docs: filesystems: convert sharedsubtree.txt to ReST

- Add a SPDX header;
- Adjust document and section titles;
- Some whitespace fixes and new line breaks;
- Mark literal blocks as such;
- Add table markups;
- Add it to filesystems/index.rst

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Link: https://lore.kernel.org/r/6692b8abc177130e9e53aace94117a2ad076cab5.1588021877.git.mchehab+huawei@kernel.org
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
This commit is contained in:
Mauro Carvalho Chehab 2020-04-27 23:17:12 +02:00 committed by Jonathan Corbet
parent 53a41d3eec
commit cf06612c65
3 changed files with 228 additions and 171 deletions

View File

@ -33,6 +33,7 @@ algorithms work.
mount_api
quota
seq_file
sharedsubtree
automount-support

View File

@ -1870,7 +1870,7 @@ unbindable mount is unbindable
For more information on mount propagation see:
Documentation/filesystems/sharedsubtree.txt
Documentation/filesystems/sharedsubtree.rst
3.6 /proc/<pid>/comm & /proc/<pid>/task/<tid>/comm

View File

@ -1,7 +1,10 @@
Shared Subtrees
---------------
.. SPDX-License-Identifier: GPL-2.0
Contents:
===============
Shared Subtrees
===============
.. Contents:
1) Overview
2) Features
3) Setting mount states
@ -41,24 +44,31 @@ replicas continue to be exactly same.
Here is an example:
Let's say /mnt has a mount that is shared.
Let's say /mnt has a mount that is shared::
mount --make-shared /mnt
Note: mount(8) command now supports the --make-shared flag,
so the sample 'smount' program is no longer needed and has been
removed.
::
# mount --bind /mnt /tmp
The above command replicates the mount at /mnt to the mountpoint /tmp
and the contents of both the mounts remain identical.
::
#ls /mnt
a b c
#ls /tmp
a b c
Now let's say we mount a device at /tmp/a
Now let's say we mount a device at /tmp/a::
# mount /dev/sd0 /tmp/a
#ls /tmp/a
@ -123,11 +133,12 @@ replicas continue to be exactly same.
2d) A unbindable mount is a unbindable private mount
let's say we have a mount at /mnt and we make it unbindable
let's say we have a mount at /mnt and we make it unbindable::
# mount --make-unbindable /mnt
Let's try to bind mount this mount somewhere else.
Let's try to bind mount this mount somewhere else::
# mount --bind /mnt /tmp
mount: wrong fs type, bad option, bad superblock on /mnt,
or too many mounted file systems
@ -138,7 +149,7 @@ replicas continue to be exactly same.
3) Setting mount states
The mount command (util-linux package) can be used to set mount
states:
states::
mount --make-shared mountpoint
mount --make-slave mountpoint
@ -154,7 +165,8 @@ replicas continue to be exactly same.
Solution:
The system administrator can make the mount at /cdrom shared
The system administrator can make the mount at /cdrom shared::
mount --bind /cdrom /cdrom
mount --make-shared /cdrom
@ -172,12 +184,12 @@ replicas continue to be exactly same.
Solution:
To begin with, the administrator can mark the entire mount tree
as shareable.
as shareable::
mount --make-rshared /
A new process can clone off a new namespace. And mark some part
of its namespace as slave
of its namespace as slave::
mount --make-rslave /myprivatetree
@ -206,7 +218,7 @@ replicas continue to be exactly same.
versions of the file depending on the path used to access that
file.
An example is:
An example is::
mount --make-shared /
mount --rbind / /view/v1
@ -224,8 +236,8 @@ replicas continue to be exactly same.
filesystem is being requested and return the corresponding
inode.
5) Detailed semantics:
-------------------
5) Detailed semantics
---------------------
The section below explains the detailed semantics of
bind, rbind, move, mount, umount and clone-namespace operations.
@ -235,6 +247,7 @@ replicas continue to be exactly same.
5a) Mount states
A given mount can be in one of the following states
1) shared
2) slave
3) shared and slave
@ -252,7 +265,8 @@ replicas continue to be exactly same.
A 'shared mount' is defined as a vfsmount that belongs to a
'peer group'.
For example:
For example::
mount --make-shared /mnt
mount --bind /mnt /tmp
@ -270,7 +284,7 @@ replicas continue to be exactly same.
A slave mount as the name implies has a master mount from which
mount/unmount events are received. Events do not propagate from
the slave mount to the master. Only a shared mount can be made
a slave by executing the following command
a slave by executing the following command::
mount --make-slave mount
@ -290,8 +304,10 @@ replicas continue to be exactly same.
peer group.
Only a slave vfsmount can be made as 'shared and slave' by
either executing the following command
either executing the following command::
mount --make-shared mount
or by moving the slave vfsmount under a shared vfsmount.
(4) Private mount
@ -307,9 +323,11 @@ replicas continue to be exactly same.
State diagram:
The state diagram below explains the state transition of a mount,
in response to various commands.
------------------------------------------------------------------------
in response to various commands::
-----------------------------------------------------------------------
| |make-shared | make-slave | make-private |make-unbindab|
--------------|------------|--------------|--------------|-------------|
|shared |shared |*slave/private| private | unbindable |
@ -338,7 +356,7 @@ replicas continue to be exactly same.
5b) Bind semantics
Consider the following command
Consider the following command::
mount --bind A/a B/b
@ -346,19 +364,20 @@ replicas continue to be exactly same.
is the destination mount and 'b' is the dentry in the destination mount.
The outcome depends on the type of mount of 'A' and 'B'. The table
below contains quick reference.
---------------------------------------------------------------------------
below contains quick reference::
--------------------------------------------------------------------------
| BIND MOUNT OPERATION |
|**************************************************************************
|************************************************************************|
|source(A)->| shared | private | slave | unbindable |
| dest(B) | | | | |
| | | | | | |
| v | | | | |
|**************************************************************************
|************************************************************************|
| shared | shared | shared | shared & slave | invalid |
| | | | | |
|non-shared| shared | private | slave | invalid |
***************************************************************************
**************************************************************************
Details:
@ -422,7 +441,9 @@ replicas continue to be exactly same.
then the subtree under the unbindable mount is pruned in the new
location.
eg: let's say we have the following mount tree.
eg:
let's say we have the following mount tree::
A
/ \
@ -435,7 +456,7 @@ replicas continue to be exactly same.
If this tree is rbound to say Z
We will have the following tree at the new location.
We will have the following tree at the new location::
Z
|
@ -457,7 +478,8 @@ replicas continue to be exactly same.
the dentry in the destination mount.
The outcome depends on the type of the mount of 'A' and 'B'. The table
below is a quick reference.
below is a quick reference::
---------------------------------------------------------------------------
| MOVE MOUNT OPERATION |
|**************************************************************************
@ -470,7 +492,8 @@ replicas continue to be exactly same.
| | | | | |
|non-shared| shared | private | slave | unbindable |
***************************************************************************
NOTE: moving a mount residing under a shared mount is invalid.
.. Note:: moving a mount residing under a shared mount is invalid.
Details follow:
@ -524,7 +547,7 @@ replicas continue to be exactly same.
5e) Mount semantics
Consider the following command
Consider the following command::
mount device B/b
@ -537,7 +560,7 @@ replicas continue to be exactly same.
5f) Unmount semantics
Consider the following command
Consider the following command::
umount A
@ -592,6 +615,8 @@ replicas continue to be exactly same.
A. What is the result of the following command sequence?
::
mount --bind /mnt /mnt
mount --make-shared /mnt
mount --bind /mnt /tmp
@ -604,6 +629,8 @@ replicas continue to be exactly same.
B. What is the result of the following command sequence?
::
mount --make-rshared /
mkdir -p /v/1
mount --rbind / /v/1
@ -613,6 +640,8 @@ replicas continue to be exactly same.
C. What is the result of the following command sequence?
::
mount --bind /mnt /mnt
mount --make-shared /mnt
mkdir -p /mnt/1/2/3 /mnt/1/test
@ -668,7 +697,8 @@ replicas continue to be exactly same.
step 1:
let's say the root tree has just two directories with
one vfsmount.
one vfsmount::
root
/ \
tmp usr
@ -676,14 +706,17 @@ replicas continue to be exactly same.
And we want to replicate the tree at multiple
mountpoints under /root/tmp
step2:
step 2:
::
mount --make-shared /root
mkdir -p /tmp/m1
mount --rbind /root /tmp/m1
the new tree now looks like this:
the new tree now looks like this::
root
/ \
@ -697,11 +730,13 @@ replicas continue to be exactly same.
it has two vfsmounts
step3:
step 3:
::
mkdir -p /tmp/m2
mount --rbind /root /tmp/m2
the new tree now looks like this:
the new tree now looks like this::
root
/ \
@ -724,6 +759,7 @@ replicas continue to be exactly same.
it has 6 vfsmounts
step 4:
::
mkdir -p /tmp/m3
mount --rbind /root /tmp/m3
@ -740,7 +776,8 @@ replicas continue to be exactly same.
step 1:
let's say the root tree has just two directories with
one vfsmount.
one vfsmount::
root
/ \
tmp usr
@ -748,7 +785,10 @@ replicas continue to be exactly same.
How do we set up the same tree at multiple locations under
/root/tmp
step2:
step 2:
::
mount --bind /root/tmp /root/tmp
mount --make-rshared /root
@ -758,7 +798,7 @@ replicas continue to be exactly same.
mount --rbind /root /tmp/m1
the new tree now looks like this:
the new tree now looks like this::
root
/ \
@ -768,11 +808,13 @@ replicas continue to be exactly same.
/ \
tmp usr
step3:
step 3:
::
mkdir -p /tmp/m2
mount --rbind /root /tmp/m2
the new tree now looks like this:
the new tree now looks like this::
root
/ \
@ -782,12 +824,13 @@ replicas continue to be exactly same.
/ \ / \
tmp usr tmp usr
step4:
step 4:
::
mkdir -p /tmp/m3
mount --rbind /root /tmp/m3
the new tree now looks like this:
the new tree now looks like this::
root
/ \
@ -801,25 +844,31 @@ replicas continue to be exactly same.
8A) Datastructure
4 new fields are introduced to struct vfsmount
->mnt_share
->mnt_slave_list
->mnt_slave
->mnt_master
4 new fields are introduced to struct vfsmount:
->mnt_share links together all the mount to/from which this vfsmount
* ->mnt_share
* ->mnt_slave_list
* ->mnt_slave
* ->mnt_master
->mnt_share
links together all the mount to/from which this vfsmount
send/receives propagation events.
->mnt_slave_list links all the mounts to which this vfsmount propagates
->mnt_slave_list
links all the mounts to which this vfsmount propagates
to.
->mnt_slave links together all the slaves that its master vfsmount
->mnt_slave
links together all the slaves that its master vfsmount
propagates to.
->mnt_master points to the master vfsmount from which this vfsmount
->mnt_master
points to the master vfsmount from which this vfsmount
receives propagation.
->mnt_flags takes two more flags to indicate the propagation status of
->mnt_flags
takes two more flags to indicate the propagation status of
the vfsmount. MNT_SHARE indicates that the vfsmount is a shared
vfsmount. MNT_UNCLONABLE indicates that the vfsmount cannot be
replicated.
@ -842,7 +891,7 @@ replicas continue to be exactly same.
A example propagation tree looks as shown in the figure below.
[ NOTE: Though it looks like a forest, if we consider all the shared
mounts as a conceptual entity called 'pnode', it becomes a tree]
mounts as a conceptual entity called 'pnode', it becomes a tree]::
A <--> B <--> C <---> D
@ -864,14 +913,19 @@ replicas continue to be exactly same.
A's ->mnt_slave_list links with ->mnt_slave of 'E', 'K', 'F' and 'G'
E's ->mnt_share links with ->mnt_share of K
'E', 'K', 'F', 'G' have their ->mnt_master point to struct
vfsmount of 'A'
'E', 'K', 'F', 'G' have their ->mnt_master point to struct vfsmount of 'A'
'M', 'L', 'N' have their ->mnt_master point to struct vfsmount of 'K'
K's ->mnt_slave_list links with ->mnt_slave of 'M', 'L' and 'N'
C's ->mnt_slave_list links with ->mnt_slave of 'J' and 'K'
J and K's ->mnt_master points to struct vfsmount of C
and finally D's ->mnt_slave_list links with ->mnt_slave of 'H' and 'I'
'H' and 'I' have their ->mnt_master pointing to struct vfsmount of 'D'.
@ -903,6 +957,7 @@ replicas continue to be exactly same.
Prepare phase:
for each mount in the source tree:
a) Create the necessary number of mount trees to
be attached to each of the mounts that receive
propagation from the destination mount.
@ -929,11 +984,12 @@ replicas continue to be exactly same.
Abort phase
delete all the newly created trees.
NOTE: all the propagation related functionality resides in the file
pnode.c
.. Note::
all the propagation related functionality resides in the file pnode.c
------------------------------------------------------------------------
version 0.1 (created the initial document, Ram Pai linuxram@us.ibm.com)
version 0.2 (Incorporated comments from Al Viro)