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 mount_api
quota quota
seq_file seq_file
sharedsubtree
automount-support automount-support

View File

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