Shared Subtrees

1) Overview

Consider the following situation:

A process wants to clone its own namespace, but still wants to access the CDthat got mounted recently. Shared subtree semantics provide the necessarymechanism to accomplish the above.

It provides the necessary building blocks for features like per-user-namespaceand versioned filesystem.

2) Features

Shared subtree provides four different flavors of mounts;structvfsmount to beprecise:

  1. Ashared mount can be replicated to as many mountpoints and all thereplicas continue to be exactly same.

    Here is an example:

    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 beenremoved.

    # mount --bind /mnt /tmp

    The above command replicates the mount at /mnt to the mountpoint /tmpand the contents of both the mounts remain identical.

    #ls /mnta b c#ls /tmpa b c

    Now let’s say we mount a device at /tmp/a:

    # mount /dev/sd0  /tmp/a# ls /tmp/at1 t2 t3# ls /mnt/at1 t2 t3

    Note that the mount has propagated to the mount at /mnt as well.

    And the same is true even when /dev/sd0 is mounted on /mnt/a. Thecontents will be visible under /tmp/a too.

  2. Aslave mount is like a shared mount except that mount and umount eventsonly propagate towards it.

    All slave mounts have a master mount which is a shared.

    Here is an example:

    Let’s say /mnt has a mount which is shared:

    # mount --make-shared /mnt

    Let’s bind mount /mnt to /tmp:

    # mount --bind /mnt /tmp

    the new mount at /tmp becomes a shared mount and it is a replica ofthe mount at /mnt.

    Now let’s make the mount at /tmp; a slave of /mnt:

    # mount --make-slave /tmp

    let’s mount /dev/sd0 on /mnt/a:

    # mount /dev/sd0 /mnt/a# ls /mnt/at1 t2 t3# ls /tmp/at1 t2 t3

    Note the mount event has propagated to the mount at /tmp

    However let’s see what happens if we mount something on the mount at/tmp:

    # mount /dev/sd1 /tmp/b# ls /tmp/bs1 s2 s3# ls /mnt/b

    Note how the mount event has not propagated to the mount at/mnt

  3. Aprivate mount does not forward or receive propagation.

    This is the mount we are familiar with. Its the default type.

  4. Anunbindable mount is, as the name suggests, an unbindable privatemount.

    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:

    # mount --bind /mnt /tmp mount: wrong fs type, bad option, badsuperblock on /mnt, or too many mounted file systems

    Binding a unbindable mount is a invalid operation.

3) Setting mount states

The mount command (util-linux package) can be used to set mountstates:

mount --make-shared mountpointmount --make-slave mountpointmount --make-private mountpointmount --make-unbindable mountpoint

4) Use cases

  1. A process wants to clone its own namespace, but still wants toaccess the CD that got mounted recently.

    Solution:

    The system administrator can make the mount at /cdrom shared:

    mount --bind /cdrom /cdrommount --make-shared /cdrom

    Now any process that clones off a new namespace will have amount at /cdrom which is a replica of the same mount in theparent namespace.

    So when a CD is inserted and mounted at /cdrom that mount getspropagated to the other mount at /cdrom in all the other clonenamespaces.

  2. A process wants its mounts invisible to any other process, butstill be able to see the other system mounts.

    Solution:

    To begin with, the administrator can mark the entire mount treeas shareable:

    mount --make-rshared /

    A new process can clone off a new namespace. And mark some partof its namespace as slave:

    mount --make-rslave /myprivatetree

    Hence forth any mounts within the /myprivatetree done by theprocess will not show up in any other namespace. However mountsdone in the parent namespace under /myprivatetree still showsup in the process’s namespace.

Apart from the above semantics this feature provides thebuilding blocks to solve the following problems:

  1. Per-user namespace

    The above semantics allows a way to share mounts acrossnamespaces. But namespaces are associated with processes. Ifnamespaces are made first class objects with user API toassociate/disassociate a namespace with userid, then each usercould have his/her own namespace and tailor it to his/herrequirements. This needs to be supported in PAM.

  2. Versioned files

    If the entire mount tree is visible at multiple locations, thenan underlying versioning file system can return differentversions of the file depending on the path used to access thatfile.

    An example is:

    mount --make-shared /mount --rbind / /view/v1mount --rbind / /view/v2mount --rbind / /view/v3mount --rbind / /view/v4

    and if /usr has a versioning filesystem mounted, then thatmount appears at /view/v1/usr, /view/v2/usr, /view/v3/usr and/view/v4/usr too

    A user can request v3 version of the file /usr/fs/namespace.cby accessing /view/v3/usr/fs/namespace.c . The underlyingversioning filesystem can then decipher that v3 version of thefilesystem is being requested and return the correspondinginode.

5) Detailed semantics

The section below explains the detailed semantics ofbind, rbind, move, mount, umount and clone-namespace operations.

Note

the word ‘vfsmount’ and the noun ‘mount’ have been usedto mean the same thing, throughout this document.

  1. Mount states

    Apropagation event is defined as event generated on a vfsmountthat leads to mount or unmount actions in other vfsmounts.

    Apeer group is defined as a group of vfsmounts that propagateevents to each other.

    A given mount can be in one of the following states:

    1. Shared mounts

      Ashared mount is defined as a vfsmount that belongs to apeer group.

      For example:

      mount --make-shared /mntmount --bind /mnt /tmp

      The mount at /mnt and that at /tmp are both shared and belongto the same peer group. Anything mounted or unmounted under/mnt or /tmp reflect in all the other mounts of its peergroup.

    2. Slave mounts

      Aslave mount is defined as a vfsmount that receivespropagation events and does not forward propagation events.

      A slave mount as the name implies has a master mount from whichmount/unmount events are received. Events do not propagate fromthe slave mount to the master. Only a shared mount can be madea slave by executing the following command:

      mount --make-slave mount

      A shared mount that is made as a slave is no more shared unlessmodified to become shared.

    3. Shared and Slave

      A vfsmount can be bothshared as well asslave. This stateindicates that the mount is a slave of some vfsmount, andhas its own peer group too. This vfsmount receives propagationevents from its master vfsmount, and also forwards propagationevents to its ‘peer group’ and to its slave vfsmounts.

      Strictly speaking, the vfsmount is shared having its ownpeer group, and this peer-group is a slave of some otherpeer group.

      Only a slave vfsmount can be made as ‘shared and slave’ byeither executing the following command:

      mount --make-shared mount

      or by moving the slave vfsmount under a shared vfsmount.

    4. Private mount

      Aprivate mount is defined as vfsmount that does notreceive or forward any propagation events.

    5. Unbindable mount

      Aunbindable mount is defined as vfsmount that does notreceive or forward any propagation events and cannotbe bind mounted.

      State diagram:

      The state diagram below explains the state transition of a mount,in response to various commands:

      -----------------------------------------------------------------------|             |make-shared |  make-slave  | make-private |make-unbindab|--------------|------------|--------------|--------------|-------------||shared       |shared      |*slave/private|   private    | unbindable  ||             |            |              |              |             ||-------------|------------|--------------|--------------|-------------||slave        |shared      | **slave      |    private   | unbindable  ||             |and slave   |              |              |             ||-------------|------------|--------------|--------------|-------------||shared       |shared      | slave        |    private   | unbindable  ||and slave    |and slave   |              |              |             ||-------------|------------|--------------|--------------|-------------||private      |shared      |  **private   |    private   | unbindable  ||-------------|------------|--------------|--------------|-------------||unbindable   |shared      |**unbindable  |    private   | unbindable  |------------------------------------------------------------------------* if the shared mount is the only mount in its peer group, making itslave, makes it private automatically. Note that there is no master towhich it can be slaved to.** slaving a non-shared mount has no effect on the mount.

      Apart from the commands listed below, the ‘move’ operation also changesthe state of a mount depending on type of the destination mount. Itsexplained in section 5d.

  2. Bind semantics

    Consider the following command:

    mount --bind A/a  B/b

    where ‘A’ is the source mount, ‘a’ is the dentry in the mount ‘A’, ‘B’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 tablebelow 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:

    1. ‘A’ is a shared mount and ‘B’ is a shared mount. A new mount ‘C’which is clone of ‘A’, is created. Its root dentry is ‘a’ . ‘C’ ismounted on mount ‘B’ at dentry ‘b’. Also new mount ‘C1’, ‘C2’, ‘C3’ ...are created and mounted at the dentry ‘b’ on all mounts where ‘B’propagates to. A new propagation tree containing ‘C1’,..,’Cn’ iscreated. This propagation tree is identical to the propagation tree of‘B’. And finally the peer-group of ‘C’ is merged with the peer groupof ‘A’.

    2. ‘A’ is a private mount and ‘B’ is a shared mount. A new mount ‘C’which is clone of ‘A’, is created. Its root dentry is ‘a’. ‘C’ ismounted on mount ‘B’ at dentry ‘b’. Also new mount ‘C1’, ‘C2’, ‘C3’ ...are created and mounted at the dentry ‘b’ on all mounts where ‘B’propagates to. A new propagation tree is set containing all new mounts‘C’, ‘C1’, .., ‘Cn’ with exactly the same configuration as thepropagation tree for ‘B’.

    3. ‘A’ is a slave mount of mount ‘Z’ and ‘B’ is a shared mount. A newmount ‘C’ which is clone of ‘A’, is created. Its root dentry is ‘a’ .‘C’ is mounted on mount ‘B’ at dentry ‘b’. Also new mounts ‘C1’, ‘C2’,‘C3’ ... are created and mounted at the dentry ‘b’ on all mounts where‘B’ propagates to. A new propagation tree containing the new mounts‘C’,’C1’,.. ‘Cn’ is created. This propagation tree is identical to thepropagation tree for ‘B’. And finally the mount ‘C’ and its peer groupis made the slave of mount ‘Z’. In other words, mount ‘C’ is in thestate ‘slave and shared’.

    4. ‘A’ is a unbindable mount and ‘B’ is a shared mount. This is ainvalid operation.

    5. ‘A’ is a private mount and ‘B’ is a non-shared(private or slave orunbindable) mount. A new mount ‘C’ which is clone of ‘A’, is created.Its root dentry is ‘a’. ‘C’ is mounted on mount ‘B’ at dentry ‘b’.

    6. ‘A’ is a shared mount and ‘B’ is a non-shared mount. A new mount ‘C’which is a clone of ‘A’ is created. Its root dentry is ‘a’. ‘C’ ismounted on mount ‘B’ at dentry ‘b’. ‘C’ is made a member of thepeer-group of ‘A’.

    7. ‘A’ is a slave mount of mount ‘Z’ and ‘B’ is a non-shared mount. Anew mount ‘C’ which is a clone of ‘A’ is created. Its root dentry is‘a’. ‘C’ is mounted on mount ‘B’ at dentry ‘b’. Also ‘C’ is set as aslave mount of ‘Z’. In other words ‘A’ and ‘C’ are both slave mounts of‘Z’. All mount/unmount events on ‘Z’ propagates to ‘A’ and ‘C’. Butmount/unmount on ‘A’ do not propagate anywhere else. Similarlymount/unmount on ‘C’ do not propagate anywhere else.

    8. ‘A’ is a unbindable mount and ‘B’ is a non-shared mount. This is ainvalid operation. A unbindable mount cannot be bind mounted.

  3. Rbind semantics

    rbind is same as bind. Bind replicates the specified mount. Rbindreplicates all the mounts in the tree belonging to the specified mount.Rbind mount is bind mount applied to all the mounts in the tree.

    If the source tree that is rbind has some unbindable mounts,then the subtree under the unbindable mount is pruned in the newlocation.

    eg:

    let’s say we have the following mount tree:

       A /   \ B   C/ \ / \D E F G

    Let’s say all the mount except the mount C in the tree areof a type other than unbindable.

    If this tree is rbound to say Z

    We will have the following tree at the new location:

        Z    |    A'   /  B'                Note how the tree under C is pruned / \                in the new location.D' E'
  4. Move semantics

    Consider the following command:

    mount --move A  B/b

    where ‘A’ is the source mount, ‘B’ is the destination mount and ‘b’ isthe dentry in the destination mount.

    The outcome depends on the type of the mount of ‘A’ and ‘B’. The tablebelow is a quick reference:

    ---------------------------------------------------------------------------|                   MOVE MOUNT OPERATION                                 ||**************************************************************************| source(A)->| shared      |       private  |       slave    | unbindable || dest(B)  |               |                |                |            ||   |      |               |                |                |            ||   v      |               |                |                |            ||**************************************************************************|  shared  | shared        |     shared     |shared and slave|  invalid   ||          |               |                |                |            ||non-shared| shared        |      private   |    slave       | unbindable |***************************************************************************

    Note

    moving a mount residing under a shared mount is invalid.

    Details follow:

    1. ‘A’ is a shared mount and ‘B’ is a shared mount. The mount ‘A’ ismounted on mount ‘B’ at dentry ‘b’. Also new mounts ‘A1’, ‘A2’...’An’are created and mounted at dentry ‘b’ on all mounts that receivepropagation from mount ‘B’. A new propagation tree is created in theexact same configuration as that of ‘B’. This new propagation treecontains all the new mounts ‘A1’, ‘A2’... ‘An’. And this newpropagation tree is appended to the already existing propagation treeof ‘A’.

    2. ‘A’ is a private mount and ‘B’ is a shared mount. The mount ‘A’ ismounted on mount ‘B’ at dentry ‘b’. Also new mount ‘A1’, ‘A2’... ‘An’are created and mounted at dentry ‘b’ on all mounts that receivepropagation from mount ‘B’. The mount ‘A’ becomes a shared mount and apropagation tree is created which is identical to that of‘B’. This new propagation tree contains all the new mounts ‘A1’,‘A2’... ‘An’.

    3. ‘A’ is a slave mount of mount ‘Z’ and ‘B’ is a shared mount. Themount ‘A’ is mounted on mount ‘B’ at dentry ‘b’. Also new mounts ‘A1’,‘A2’... ‘An’ are created and mounted at dentry ‘b’ on all mounts thatreceive propagation from mount ‘B’. A new propagation tree is createdin the exact same configuration as that of ‘B’. This new propagationtree contains all the new mounts ‘A1’, ‘A2’... ‘An’. And this newpropagation tree is appended to the already existing propagation tree of‘A’. Mount ‘A’ continues to be the slave mount of ‘Z’ but it alsobecomes ‘shared’.

    4. ‘A’ is a unbindable mount and ‘B’ is a shared mount. The operationis invalid. Because mounting anything on the shared mount ‘B’ cancreate new mounts that get mounted on the mounts that receivepropagation from ‘B’. And since the mount ‘A’ is unbindable, cloningit to mount at other mountpoints is not possible.

    5. ‘A’ is a private mount and ‘B’ is a non-shared(private or slave orunbindable) mount. The mount ‘A’ is mounted on mount ‘B’ at dentry ‘b’.

    6. ‘A’ is a shared mount and ‘B’ is a non-shared mount. The mount ‘A’is mounted on mount ‘B’ at dentry ‘b’. Mount ‘A’ continues to be ashared mount.

    7. ‘A’ is a slave mount of mount ‘Z’ and ‘B’ is a non-shared mount.The mount ‘A’ is mounted on mount ‘B’ at dentry ‘b’. Mount ‘A’continues to be a slave mount of mount ‘Z’.

    8. ‘A’ is a unbindable mount and ‘B’ is a non-shared mount. The mount‘A’ is mounted on mount ‘B’ at dentry ‘b’. Mount ‘A’ continues to be aunbindable mount.

  5. Mount semantics

    Consider the following command:

    mount device  B/b

    ‘B’ is the destination mount and ‘b’ is the dentry in the destinationmount.

    The above operation is the same as bind operation with the exceptionthat the source mount is always a private mount.

  6. Unmount semantics

    Consider the following command:

    umount A

    where ‘A’ is a mount mounted on mount ‘B’ at dentry ‘b’.

    If mount ‘B’ is shared, then all most-recently-mounted mounts at dentry‘b’ on mounts that receive propagation from mount ‘B’ and does not havesub-mounts within them are unmounted.

    Example: Let’s say ‘B1’, ‘B2’, ‘B3’ are shared mounts that propagate toeach other.

    let’s say ‘A1’, ‘A2’, ‘A3’ are first mounted at dentry ‘b’ on mount‘B1’, ‘B2’ and ‘B3’ respectively.

    let’s say ‘C1’, ‘C2’, ‘C3’ are next mounted at the same dentry ‘b’ onmount ‘B1’, ‘B2’ and ‘B3’ respectively.

    if ‘C1’ is unmounted, all the mounts that are most-recently-mounted on‘B1’ and on the mounts that ‘B1’ propagates-to are unmounted.

    ‘B1’ propagates to ‘B2’ and ‘B3’. And the most recently mounted mounton ‘B2’ at dentry ‘b’ is ‘C2’, and that of mount ‘B3’ is ‘C3’.

    So all ‘C1’, ‘C2’ and ‘C3’ should be unmounted.

    If any of ‘C2’ or ‘C3’ has some child mounts, then that mount is notunmounted, but all other mounts are unmounted. However if ‘C1’ is toldto be unmounted and ‘C1’ has some sub-mounts, the umount operation isfailed entirely.

  7. Clone Namespace

    A cloned namespace contains all the mounts as that of the parentnamespace.

    Let’s say ‘A’ and ‘B’ are the corresponding mounts in the parent and thechild namespace.

    If ‘A’ is shared, then ‘B’ is also shared and ‘A’ and ‘B’ propagate toeach other.

    If ‘A’ is a slave mount of ‘Z’, then ‘B’ is also the slave mount of‘Z’.

    If ‘A’ is a private mount, then ‘B’ is a private mount too.

    If ‘A’ is unbindable mount, then ‘B’ is a unbindable mount too.

6) Quiz

  1. What is the result of the following command sequence?

    mount --bind /mnt /mntmount --make-shared /mntmount --bind /mnt /tmpmount --move /tmp /mnt/1

    what should be the contents of /mnt /mnt/1 /mnt/1/1 should be?Should they all be identical? or should /mnt and /mnt/1 beidentical only?

  2. What is the result of the following command sequence?

    mount --make-rshared /mkdir -p /v/1mount --rbind / /v/1

    what should be the content of /v/1/v/1 be?

  3. What is the result of the following command sequence?

    mount --bind /mnt /mntmount --make-shared /mntmkdir -p /mnt/1/2/3 /mnt/1/testmount --bind /mnt/1 /tmpmount --make-slave /mntmount --make-shared /mntmount --bind /mnt/1/2 /tmp1mount --make-slave /mnt

    At this point we have the first mount at /tmp andits root dentry is 1. Let’s call this mount ‘A’And then we have a second mount at /tmp1 with rootdentry 2. Let’s call this mount ‘B’Next we have a third mount at /mnt with root dentrymnt. Let’s call this mount ‘C’

    ‘B’ is the slave of ‘A’ and ‘C’ is a slave of ‘B’A -> B -> C

    at this point if we execute the following command:

    mount --bind /bin /tmp/test

    The mount is attempted on ‘A’

    will the mount propagate to ‘B’ and ‘C’ ?

    what would be the contents of/mnt/1/test be?

7) FAQ

  1. Why is bind mount needed? How is it different from symbolic links?

    symbolic links can get stale if the destination mount getsunmounted or moved. Bind mounts continue to exist even if theother mount is unmounted or moved.

  2. Why can’t the shared subtree be implemented using exportfs?

    exportfs is a heavyweight way of accomplishing part of whatshared subtree can do. I cannot imagine a way to implement thesemantics of slave mount using exportfs?

  3. Why is unbindable mount needed?

    Let’s say we want to replicate the mount tree at multiplelocations within the same subtree.

    if one rbind mounts a tree within the same subtree ‘n’ timesthe number of mounts created is an exponential function of ‘n’.Having unbindable mount can help prune the unneeded bindmounts. Here is an example.

    step 1:

    let’s say the root tree has just two directories withone vfsmount:

      root /    \tmp    usr

    And we want to replicate the tree at multiplemountpoints under /root/tmp

    step 2:
    mount --make-shared /rootmkdir -p /tmp/m1mount --rbind /root /tmp/m1

    the new tree now looks like this:

            root       /    \     tmp    usr    /   m1  /  \ tmp  usr /m1

    it has two vfsmounts

    step 3:
    mkdir -p /tmp/m2mount --rbind /root /tmp/m2

    the new tree now looks like this:

                      root                 /    \               tmp     usr              /    \            m1       m2           / \       /  \         tmp  usr   tmp  usr         / \          /        m1  m2      m1            / \     /  \          tmp usr  tmp   usr          /        / \         m1       m1  m2        /  \      tmp   usr      /  \     m1   m2it has 6 vfsmounts
    step 4:
    mkdir -p /tmp/m3mount --rbind /root /tmp/m3

    I won’t draw the tree..but it has 24 vfsmounts

    at step i the number of vfsmounts is V[i] = i*V[i-1].This is an exponential function. And this tree has way moremounts than what we really needed in the first place.

    One could use a series of umount at each step to pruneout the unneeded mounts. But there is a better solution.Unclonable mounts come in handy here.

    step 1:

    let’s say the root tree has just two directories withone vfsmount:

                               root                          /    \                         tmp    usrHow do we set up the same tree at multiple locations under/root/tmp
    step 2:
    mount --bind /root/tmp /root/tmpmount --make-rshared /rootmount --make-unbindable /root/tmpmkdir -p /tmp/m1mount --rbind /root /tmp/m1

    the new tree now looks like this:

           root      /    \    tmp    usr   /  m1 /  \tmp  usr
    step 3:
    mkdir -p /tmp/m2mount --rbind /root /tmp/m2

    the new tree now looks like this:

           root      /    \    tmp    usr   /   \  m1     m2 /  \     / \tmp  usr tmp usr
    step 4:
    mkdir -p /tmp/m3mount --rbind /root /tmp/m3

    the new tree now looks like this:

                 root         /           \        tmp           usr    /    \    \  m1     m2     m3 /  \     / \    /  \tmp  usr tmp usr tmp usr

8) Implementation

  1. Datastructure

    Several new fields are introduced tostructvfsmount:

    ->mnt_share

    Links together all the mount to/from which this vfsmountsend/receives propagation events.

    ->mnt_slave_list

    Links all the mounts to which this vfsmount propagatesto.

    ->mnt_slave

    Links together all the slaves that its master vfsmountpropagates to.

    ->mnt_master

    Points to the master vfsmount from which this vfsmountreceives propagation.

    ->mnt_flags

    Takes two more flags to indicate the propagation status ofthe vfsmount. MNT_SHARE indicates that the vfsmount is a sharedvfsmount. MNT_UNCLONABLE indicates that the vfsmount cannot bereplicated.

    All the shared vfsmounts in a peer group form a cyclic list through->mnt_share.

    All vfsmounts with the same ->mnt_master form on a cyclic list anchoredin ->mnt_master->mnt_slave_list and going through ->mnt_slave.

    ->mnt_master can point to arbitrary (and possibly different) membersof master peer group. To find all immediate slaves of a peer groupyou need to go through _all_ ->mnt_slave_list of its members.Conceptually it’s just a single set - distribution among theindividual lists does not affect propagation or the way propagationtree is modified by operations.

    All vfsmounts in a peer group have the same ->mnt_master. If it isnon-NULL, they form a contiguous (ordered) segment of slave list.

    A example propagation tree looks as shown in the figure below.

    Note

    Though it looks like a forest, if we consider all the sharedmounts as a conceptual entity called ‘pnode’, it becomes a tree.

        A <--> B <--> C <---> D   /|\            /|      |\  / F G          J K      H I /E<-->K    /|\   M L N

    In the above figure A,B,C and D all are shared and propagate to eachother. ‘A’ has got 3 slave mounts ‘E’ ‘F’ and ‘G’ ‘C’ has got 2 slavemounts ‘J’ and ‘K’ and ‘D’ has got two slave mounts ‘H’ and ‘I’.‘E’ is also shared with ‘K’ and they propagate to each other. And‘K’ has 3 slaves ‘M’, ‘L’ and ‘N’

    A’s ->mnt_share links with the ->mnt_share of ‘B’ ‘C’ and ‘D’

    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 tostructvfsmount of ‘A’

    ‘M’, ‘L’, ‘N’ have their ->mnt_master point tostructvfsmount 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 tostructvfsmount 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 tostructvfsmount of ‘D’.

    NOTE: The propagation tree is orthogonal to the mount tree.

  2. Locking:

    ->mnt_share, ->mnt_slave, ->mnt_slave_list, ->mnt_master are protectedby namespace_sem (exclusive for modifications, shared for reading).

    Normally we have ->mnt_flags modifications serialized by vfsmount_lock.There are two exceptions:do_add_mount() andclone_mnt().The former modifies a vfsmount that has not been visible in any shareddata structures yet.The latter holds namespace_sem and the only references to vfsmountare in lists that can’t be traversed without namespace_sem.

  3. Algorithm:

    The crux of the implementation resides in rbind/move operation.

    The overall algorithm breaks the operation into 3 phases: (look atattach_recursive_mnt() andpropagate_mnt())

    1. Prepare phase.

      For each mount in the source tree:

      1. Create the necessary number of mount trees tobe attached to each of the mounts that receivepropagation from the destination mount.

      2. Do not attach any of the trees to its destination.However note down its ->mnt_parent and ->mnt_mountpoint

      3. Link all the new mounts to form a propagation tree thatis identical to the propagation tree of the destinationmount.

      If this phase is successful, there should be ‘n’ newpropagation trees; where ‘n’ is the number of mounts in thesource tree. Go to the commit phase

      Also there should be ‘m’ new mount trees, where ‘m’ isthe number of mounts to which the destination mountpropagates to.

      If any memory allocations fail, go to the abort phase.

    2. Commit phase.

      Attach each of the mount trees to their correspondingdestination mounts.

    3. Abort phase.

      Delete all the newly created trees.

    Note

    all the propagation related functionality resides in the file pnode.c


version 0.1 (created the initial document, Ram Pailinuxram@us.ibm.com)

version 0.2 (Incorporated comments from Al Viro)