^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) .. SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) ===============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) Shared Subtrees
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) ===============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) .. Contents:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) 1) Overview
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) 2) Features
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) 3) Setting mount states
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 4) Use-case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) 5) Detailed semantics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 6) Quiz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 7) FAQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 8) Implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 1) Overview
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) -----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) Consider the following situation:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) A process wants to clone its own namespace, but still wants to access the CD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) that got mounted recently. Shared subtree semantics provide the necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) mechanism to accomplish the above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) It provides the necessary building blocks for features like per-user-namespace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) and versioned filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 2) Features
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) -----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) Shared subtree provides four different flavors of mounts; struct vfsmount to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) precise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) a. shared mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) b. slave mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) c. private mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) d. unbindable mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 2a) A shared mount can be replicated to as many mountpoints and all the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) replicas continue to be exactly same.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) Here is an example:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) Let's say /mnt has a mount that is shared::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) mount --make-shared /mnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) Note: mount(8) command now supports the --make-shared flag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) so the sample 'smount' program is no longer needed and has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) removed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) # mount --bind /mnt /tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) The above command replicates the mount at /mnt to the mountpoint /tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) and the contents of both the mounts remain identical.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #ls /mnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) a b c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #ls /tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) a b c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) Now let's say we mount a device at /tmp/a::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) # mount /dev/sd0 /tmp/a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #ls /tmp/a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) t1 t2 t3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #ls /mnt/a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) t1 t2 t3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) Note that the mount has propagated to the mount at /mnt as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) And the same is true even when /dev/sd0 is mounted on /mnt/a. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) contents will be visible under /tmp/a too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 2b) A slave mount is like a shared mount except that mount and umount events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) only propagate towards it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) All slave mounts have a master mount which is a shared.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) Here is an example:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) Let's say /mnt has a mount which is shared.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) # mount --make-shared /mnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) Let's bind mount /mnt to /tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) # mount --bind /mnt /tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) the new mount at /tmp becomes a shared mount and it is a replica of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) the mount at /mnt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) Now let's make the mount at /tmp; a slave of /mnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) # mount --make-slave /tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) let's mount /dev/sd0 on /mnt/a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) # mount /dev/sd0 /mnt/a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #ls /mnt/a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) t1 t2 t3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #ls /tmp/a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) t1 t2 t3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) Note the mount event has propagated to the mount at /tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) However let's see what happens if we mount something on the mount at /tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) # mount /dev/sd1 /tmp/b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #ls /tmp/b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) s1 s2 s3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #ls /mnt/b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) Note how the mount event has not propagated to the mount at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /mnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 2c) A private mount does not forward or receive propagation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) This is the mount we are familiar with. Its the default type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 2d) A unbindable mount is a unbindable private mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) let's say we have a mount at /mnt and we make it unbindable::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) # mount --make-unbindable /mnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) Let's try to bind mount this mount somewhere else::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) # mount --bind /mnt /tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) mount: wrong fs type, bad option, bad superblock on /mnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) or too many mounted file systems
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) Binding a unbindable mount is a invalid operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 3) Setting mount states
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) The mount command (util-linux package) can be used to set mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) states::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) mount --make-shared mountpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) mount --make-slave mountpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) mount --make-private mountpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) mount --make-unbindable mountpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 4) Use cases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) ------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) A) A process wants to clone its own namespace, but still wants to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) access the CD that got mounted recently.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) Solution:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) The system administrator can make the mount at /cdrom shared::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) mount --bind /cdrom /cdrom
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) mount --make-shared /cdrom
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) Now any process that clones off a new namespace will have a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) mount at /cdrom which is a replica of the same mount in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) parent namespace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) So when a CD is inserted and mounted at /cdrom that mount gets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) propagated to the other mount at /cdrom in all the other clone
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) namespaces.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) B) A process wants its mounts invisible to any other process, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) still be able to see the other system mounts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) Solution:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) To begin with, the administrator can mark the entire mount tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) as shareable::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) mount --make-rshared /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) A new process can clone off a new namespace. And mark some part
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) of its namespace as slave::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) mount --make-rslave /myprivatetree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) Hence forth any mounts within the /myprivatetree done by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) process will not show up in any other namespace. However mounts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) done in the parent namespace under /myprivatetree still shows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) up in the process's namespace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) Apart from the above semantics this feature provides the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) building blocks to solve the following problems:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) C) Per-user namespace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) The above semantics allows a way to share mounts across
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) namespaces. But namespaces are associated with processes. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) namespaces are made first class objects with user API to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) associate/disassociate a namespace with userid, then each user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) could have his/her own namespace and tailor it to his/her
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) requirements. This needs to be supported in PAM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) D) Versioned files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) If the entire mount tree is visible at multiple locations, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) an underlying versioning file system can return different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) versions of the file depending on the path used to access that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) An example is::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) mount --make-shared /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) mount --rbind / /view/v1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) mount --rbind / /view/v2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) mount --rbind / /view/v3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) mount --rbind / /view/v4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) and if /usr has a versioning filesystem mounted, then that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) mount appears at /view/v1/usr, /view/v2/usr, /view/v3/usr and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) /view/v4/usr too
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) A user can request v3 version of the file /usr/fs/namespace.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) by accessing /view/v3/usr/fs/namespace.c . The underlying
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) versioning filesystem can then decipher that v3 version of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) filesystem is being requested and return the corresponding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 5) Detailed semantics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) ---------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) The section below explains the detailed semantics of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) bind, rbind, move, mount, umount and clone-namespace operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) Note: the word 'vfsmount' and the noun 'mount' have been used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) to mean the same thing, throughout this document.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 5a) Mount states
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) A given mount can be in one of the following states
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 1) shared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 2) slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 3) shared and slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 4) private
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 5) unbindable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) A 'propagation event' is defined as event generated on a vfsmount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) that leads to mount or unmount actions in other vfsmounts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) A 'peer group' is defined as a group of vfsmounts that propagate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) events to each other.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) (1) Shared mounts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) A 'shared mount' is defined as a vfsmount that belongs to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 'peer group'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) For example::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) mount --make-shared /mnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) mount --bind /mnt /tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) The mount at /mnt and that at /tmp are both shared and belong
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) to the same peer group. Anything mounted or unmounted under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) /mnt or /tmp reflect in all the other mounts of its peer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) (2) Slave mounts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) A 'slave mount' is defined as a vfsmount that receives
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) propagation events and does not forward propagation events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) A slave mount as the name implies has a master mount from which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) mount/unmount events are received. Events do not propagate from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) the slave mount to the master. Only a shared mount can be made
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) a slave by executing the following command::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) mount --make-slave mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) A shared mount that is made as a slave is no more shared unless
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) modified to become shared.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) (3) Shared and Slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) A vfsmount can be both shared as well as slave. This state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) indicates that the mount is a slave of some vfsmount, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) has its own peer group too. This vfsmount receives propagation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) events from its master vfsmount, and also forwards propagation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) events to its 'peer group' and to its slave vfsmounts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) Strictly speaking, the vfsmount is shared having its own
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) peer group, and this peer-group is a slave of some other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) peer group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) Only a slave vfsmount can be made as 'shared and slave' by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) either executing the following command::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) mount --make-shared mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) or by moving the slave vfsmount under a shared vfsmount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) (4) Private mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) A 'private mount' is defined as vfsmount that does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) receive or forward any propagation events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) (5) Unbindable mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) A 'unbindable mount' is defined as vfsmount that does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) receive or forward any propagation events and cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) be bind mounted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) State diagram:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) The state diagram below explains the state transition of a mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) in response to various commands::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) -----------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) | |make-shared | make-slave | make-private |make-unbindab|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) --------------|------------|--------------|--------------|-------------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) |shared |shared |*slave/private| private | unbindable |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) | | | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) |-------------|------------|--------------|--------------|-------------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) |slave |shared | **slave | private | unbindable |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) | |and slave | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) |-------------|------------|--------------|--------------|-------------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) |shared |shared | slave | private | unbindable |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) |and slave |and slave | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) |-------------|------------|--------------|--------------|-------------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) |private |shared | **private | private | unbindable |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) |-------------|------------|--------------|--------------|-------------|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) |unbindable |shared |**unbindable | private | unbindable |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) ------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) * if the shared mount is the only mount in its peer group, making it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) slave, makes it private automatically. Note that there is no master to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) which it can be slaved to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) ** slaving a non-shared mount has no effect on the mount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) Apart from the commands listed below, the 'move' operation also changes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) the state of a mount depending on type of the destination mount. Its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) explained in section 5d.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 5b) Bind semantics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) Consider the following command::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) mount --bind A/a B/b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) where 'A' is the source mount, 'a' is the dentry in the mount 'A', 'B'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) is the destination mount and 'b' is the dentry in the destination mount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) The outcome depends on the type of mount of 'A' and 'B'. The table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) below contains quick reference::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) --------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) | BIND MOUNT OPERATION |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) |************************************************************************|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) |source(A)->| shared | private | slave | unbindable |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) | dest(B) | | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) | | | | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) | v | | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) |************************************************************************|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) | shared | shared | shared | shared & slave | invalid |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) | | | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) |non-shared| shared | private | slave | invalid |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) **************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) Details:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 1. 'A' is a shared mount and 'B' is a shared mount. A new mount 'C'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) which is clone of 'A', is created. Its root dentry is 'a' . 'C' is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) mounted on mount 'B' at dentry 'b'. Also new mount 'C1', 'C2', 'C3' ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) are created and mounted at the dentry 'b' on all mounts where 'B'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) propagates to. A new propagation tree containing 'C1',..,'Cn' is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) created. This propagation tree is identical to the propagation tree of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 'B'. And finally the peer-group of 'C' is merged with the peer group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) of 'A'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 2. 'A' is a private mount and 'B' is a shared mount. A new mount 'C'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) which is clone of 'A', is created. Its root dentry is 'a'. 'C' is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) mounted on mount 'B' at dentry 'b'. Also new mount 'C1', 'C2', 'C3' ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) are created and mounted at the dentry 'b' on all mounts where 'B'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) propagates to. A new propagation tree is set containing all new mounts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 'C', 'C1', .., 'Cn' with exactly the same configuration as the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) propagation tree for 'B'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 3. 'A' is a slave mount of mount 'Z' and 'B' is a shared mount. A new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) mount 'C' which is clone of 'A', is created. Its root dentry is 'a' .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 'C' is mounted on mount 'B' at dentry 'b'. Also new mounts 'C1', 'C2',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 'C3' ... are created and mounted at the dentry 'b' on all mounts where
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 'B' propagates to. A new propagation tree containing the new mounts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 'C','C1',.. 'Cn' is created. This propagation tree is identical to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) propagation tree for 'B'. And finally the mount 'C' and its peer group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) is made the slave of mount 'Z'. In other words, mount 'C' is in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) state 'slave and shared'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 4. 'A' is a unbindable mount and 'B' is a shared mount. This is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) invalid operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 5. 'A' is a private mount and 'B' is a non-shared(private or slave or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) unbindable) mount. A new mount 'C' which is clone of 'A', is created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) Its root dentry is 'a'. 'C' is mounted on mount 'B' at dentry 'b'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 6. 'A' is a shared mount and 'B' is a non-shared mount. A new mount 'C'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) which is a clone of 'A' is created. Its root dentry is 'a'. 'C' is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) mounted on mount 'B' at dentry 'b'. 'C' is made a member of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) peer-group of 'A'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 7. 'A' is a slave mount of mount 'Z' and 'B' is a non-shared mount. A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) new mount 'C' which is a clone of 'A' is created. Its root dentry is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 'a'. 'C' is mounted on mount 'B' at dentry 'b'. Also 'C' is set as a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) slave mount of 'Z'. In other words 'A' and 'C' are both slave mounts of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 'Z'. All mount/unmount events on 'Z' propagates to 'A' and 'C'. But
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) mount/unmount on 'A' do not propagate anywhere else. Similarly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) mount/unmount on 'C' do not propagate anywhere else.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 8. 'A' is a unbindable mount and 'B' is a non-shared mount. This is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) invalid operation. A unbindable mount cannot be bind mounted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 5c) Rbind semantics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) rbind is same as bind. Bind replicates the specified mount. Rbind
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) replicates all the mounts in the tree belonging to the specified mount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) Rbind mount is bind mount applied to all the mounts in the tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) If the source tree that is rbind has some unbindable mounts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) then the subtree under the unbindable mount is pruned in the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) location.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) eg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) let's say we have the following mount tree::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) B C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) / \ / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) D E F G
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) Let's say all the mount except the mount C in the tree are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) of a type other than unbindable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) If this tree is rbound to say Z
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) We will have the following tree at the new location::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) Z
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) A'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) B' Note how the tree under C is pruned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) / \ in the new location.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) D' E'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 5d) Move semantics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) Consider the following command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) mount --move A B/b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) where 'A' is the source mount, 'B' is the destination mount and 'b' is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) the dentry in the destination mount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) The outcome depends on the type of the mount of 'A' and 'B'. The table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) below is a quick reference::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) ---------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) | MOVE MOUNT OPERATION |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) |**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) | source(A)->| shared | private | slave | unbindable |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) | dest(B) | | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) | | | | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) | v | | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) |**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) | shared | shared | shared |shared and slave| invalid |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) | | | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) |non-shared| shared | private | slave | unbindable |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) ***************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) .. Note:: moving a mount residing under a shared mount is invalid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) Details follow:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 1. 'A' is a shared mount and 'B' is a shared mount. The mount 'A' is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) mounted on mount 'B' at dentry 'b'. Also new mounts 'A1', 'A2'...'An'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) are created and mounted at dentry 'b' on all mounts that receive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) propagation from mount 'B'. A new propagation tree is created in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) exact same configuration as that of 'B'. This new propagation tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) contains all the new mounts 'A1', 'A2'... 'An'. And this new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) propagation tree is appended to the already existing propagation tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) of 'A'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 2. 'A' is a private mount and 'B' is a shared mount. The mount 'A' is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) mounted on mount 'B' at dentry 'b'. Also new mount 'A1', 'A2'... 'An'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) are created and mounted at dentry 'b' on all mounts that receive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) propagation from mount 'B'. The mount 'A' becomes a shared mount and a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) propagation tree is created which is identical to that of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 'B'. This new propagation tree contains all the new mounts 'A1',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 'A2'... 'An'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 3. 'A' is a slave mount of mount 'Z' and 'B' is a shared mount. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) mount 'A' is mounted on mount 'B' at dentry 'b'. Also new mounts 'A1',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 'A2'... 'An' are created and mounted at dentry 'b' on all mounts that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) receive propagation from mount 'B'. A new propagation tree is created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) in the exact same configuration as that of 'B'. This new propagation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) tree contains all the new mounts 'A1', 'A2'... 'An'. And this new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) propagation tree is appended to the already existing propagation tree of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 'A'. Mount 'A' continues to be the slave mount of 'Z' but it also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) becomes 'shared'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 4. 'A' is a unbindable mount and 'B' is a shared mount. The operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) is invalid. Because mounting anything on the shared mount 'B' can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) create new mounts that get mounted on the mounts that receive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) propagation from 'B'. And since the mount 'A' is unbindable, cloning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) it to mount at other mountpoints is not possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 5. 'A' is a private mount and 'B' is a non-shared(private or slave or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) unbindable) mount. The mount 'A' is mounted on mount 'B' at dentry 'b'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 6. 'A' is a shared mount and 'B' is a non-shared mount. The mount 'A'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) is mounted on mount 'B' at dentry 'b'. Mount 'A' continues to be a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) shared mount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 7. 'A' is a slave mount of mount 'Z' and 'B' is a non-shared mount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) The mount 'A' is mounted on mount 'B' at dentry 'b'. Mount 'A'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) continues to be a slave mount of mount 'Z'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 8. 'A' is a unbindable mount and 'B' is a non-shared mount. The mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 'A' is mounted on mount 'B' at dentry 'b'. Mount 'A' continues to be a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) unbindable mount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 5e) Mount semantics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) Consider the following command::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) mount device B/b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 'B' is the destination mount and 'b' is the dentry in the destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) mount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) The above operation is the same as bind operation with the exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) that the source mount is always a private mount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 5f) Unmount semantics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) Consider the following command::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) umount A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) where 'A' is a mount mounted on mount 'B' at dentry 'b'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) If mount 'B' is shared, then all most-recently-mounted mounts at dentry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 'b' on mounts that receive propagation from mount 'B' and does not have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) sub-mounts within them are unmounted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) Example: Let's say 'B1', 'B2', 'B3' are shared mounts that propagate to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) each other.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) let's say 'A1', 'A2', 'A3' are first mounted at dentry 'b' on mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 'B1', 'B2' and 'B3' respectively.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) let's say 'C1', 'C2', 'C3' are next mounted at the same dentry 'b' on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) mount 'B1', 'B2' and 'B3' respectively.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) if 'C1' is unmounted, all the mounts that are most-recently-mounted on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 'B1' and on the mounts that 'B1' propagates-to are unmounted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 'B1' propagates to 'B2' and 'B3'. And the most recently mounted mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) on 'B2' at dentry 'b' is 'C2', and that of mount 'B3' is 'C3'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) So all 'C1', 'C2' and 'C3' should be unmounted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) If any of 'C2' or 'C3' has some child mounts, then that mount is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) unmounted, but all other mounts are unmounted. However if 'C1' is told
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) to be unmounted and 'C1' has some sub-mounts, the umount operation is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) failed entirely.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 5g) Clone Namespace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) A cloned namespace contains all the mounts as that of the parent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) namespace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) Let's say 'A' and 'B' are the corresponding mounts in the parent and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) child namespace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) If 'A' is shared, then 'B' is also shared and 'A' and 'B' propagate to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) each other.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) If 'A' is a slave mount of 'Z', then 'B' is also the slave mount of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 'Z'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) If 'A' is a private mount, then 'B' is a private mount too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) If 'A' is unbindable mount, then 'B' is a unbindable mount too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 6) Quiz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) A. What is the result of the following command sequence?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) mount --bind /mnt /mnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) mount --make-shared /mnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) mount --bind /mnt /tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) mount --move /tmp /mnt/1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) what should be the contents of /mnt /mnt/1 /mnt/1/1 should be?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) Should they all be identical? or should /mnt and /mnt/1 be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) identical only?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) B. What is the result of the following command sequence?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) mount --make-rshared /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) mkdir -p /v/1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) mount --rbind / /v/1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) what should be the content of /v/1/v/1 be?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) C. What is the result of the following command sequence?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) mount --bind /mnt /mnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) mount --make-shared /mnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) mkdir -p /mnt/1/2/3 /mnt/1/test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) mount --bind /mnt/1 /tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) mount --make-slave /mnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) mount --make-shared /mnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) mount --bind /mnt/1/2 /tmp1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) mount --make-slave /mnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) At this point we have the first mount at /tmp and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) its root dentry is 1. Let's call this mount 'A'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) And then we have a second mount at /tmp1 with root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) dentry 2. Let's call this mount 'B'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) Next we have a third mount at /mnt with root dentry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) mnt. Let's call this mount 'C'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 'B' is the slave of 'A' and 'C' is a slave of 'B'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) A -> B -> C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) at this point if we execute the following command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) mount --bind /bin /tmp/test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) The mount is attempted on 'A'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) will the mount propagate to 'B' and 'C' ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) what would be the contents of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) /mnt/1/test be?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 7) FAQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) Q1. Why is bind mount needed? How is it different from symbolic links?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) symbolic links can get stale if the destination mount gets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) unmounted or moved. Bind mounts continue to exist even if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) other mount is unmounted or moved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) Q2. Why can't the shared subtree be implemented using exportfs?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) exportfs is a heavyweight way of accomplishing part of what
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) shared subtree can do. I cannot imagine a way to implement the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) semantics of slave mount using exportfs?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) Q3 Why is unbindable mount needed?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) Let's say we want to replicate the mount tree at multiple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) locations within the same subtree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) if one rbind mounts a tree within the same subtree 'n' times
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) the number of mounts created is an exponential function of 'n'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) Having unbindable mount can help prune the unneeded bind
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) mounts. Here is an example.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) step 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) let's say the root tree has just two directories with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) one vfsmount::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) tmp usr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) And we want to replicate the tree at multiple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) mountpoints under /root/tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) step 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) mount --make-shared /root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) mkdir -p /tmp/m1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) mount --rbind /root /tmp/m1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) the new tree now looks like this::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) tmp usr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) m1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) tmp usr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) m1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) it has two vfsmounts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) step 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) mkdir -p /tmp/m2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) mount --rbind /root /tmp/m2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) the new tree now looks like this::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) tmp usr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) m1 m2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) / \ / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) tmp usr tmp usr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) / \ /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) m1 m2 m1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) / \ / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) tmp usr tmp usr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) / / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) m1 m1 m2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) tmp usr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) m1 m2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) it has 6 vfsmounts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) step 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) mkdir -p /tmp/m3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) mount --rbind /root /tmp/m3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) I won't draw the tree..but it has 24 vfsmounts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) at step i the number of vfsmounts is V[i] = i*V[i-1].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) This is an exponential function. And this tree has way more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) mounts than what we really needed in the first place.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) One could use a series of umount at each step to prune
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) out the unneeded mounts. But there is a better solution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) Unclonable mounts come in handy here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) step 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) let's say the root tree has just two directories with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) one vfsmount::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) tmp usr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) How do we set up the same tree at multiple locations under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) /root/tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) step 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) mount --bind /root/tmp /root/tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) mount --make-rshared /root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) mount --make-unbindable /root/tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) mkdir -p /tmp/m1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) mount --rbind /root /tmp/m1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) the new tree now looks like this::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) tmp usr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) m1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) tmp usr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) step 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) mkdir -p /tmp/m2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) mount --rbind /root /tmp/m2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) the new tree now looks like this::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) tmp usr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) m1 m2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) / \ / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) tmp usr tmp usr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) step 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) mkdir -p /tmp/m3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) mount --rbind /root /tmp/m3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) the new tree now looks like this::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) tmp usr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) / \ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) m1 m2 m3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) / \ / \ / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) tmp usr tmp usr tmp usr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 8) Implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 8A) Datastructure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 4 new fields are introduced to struct vfsmount:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) * ->mnt_share
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) * ->mnt_slave_list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) * ->mnt_slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) * ->mnt_master
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) ->mnt_share
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) links together all the mount to/from which this vfsmount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) send/receives propagation events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) ->mnt_slave_list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) links all the mounts to which this vfsmount propagates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) ->mnt_slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) links together all the slaves that its master vfsmount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) propagates to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) ->mnt_master
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) points to the master vfsmount from which this vfsmount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) receives propagation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) ->mnt_flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) takes two more flags to indicate the propagation status of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) the vfsmount. MNT_SHARE indicates that the vfsmount is a shared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) vfsmount. MNT_UNCLONABLE indicates that the vfsmount cannot be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) replicated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) All the shared vfsmounts in a peer group form a cyclic list through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) ->mnt_share.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) All vfsmounts with the same ->mnt_master form on a cyclic list anchored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) in ->mnt_master->mnt_slave_list and going through ->mnt_slave.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) ->mnt_master can point to arbitrary (and possibly different) members
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) of master peer group. To find all immediate slaves of a peer group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) you need to go through _all_ ->mnt_slave_list of its members.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) Conceptually it's just a single set - distribution among the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) individual lists does not affect propagation or the way propagation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) tree is modified by operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) All vfsmounts in a peer group have the same ->mnt_master. If it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) non-NULL, they form a contiguous (ordered) segment of slave list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) A example propagation tree looks as shown in the figure below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) [ NOTE: Though it looks like a forest, if we consider all the shared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) mounts as a conceptual entity called 'pnode', it becomes a tree]::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) A <--> B <--> C <---> D
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) /|\ /| |\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) / F G J K H I
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) E<-->K
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) /|\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) M L N
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) In the above figure A,B,C and D all are shared and propagate to each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) other. 'A' has got 3 slave mounts 'E' 'F' and 'G' 'C' has got 2 slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) mounts 'J' and 'K' and 'D' has got two slave mounts 'H' and 'I'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) 'E' is also shared with 'K' and they propagate to each other. And
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) 'K' has 3 slaves 'M', 'L' and 'N'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) A's ->mnt_share links with the ->mnt_share of 'B' 'C' and 'D'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) A's ->mnt_slave_list links with ->mnt_slave of 'E', 'K', 'F' and 'G'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) E's ->mnt_share links with ->mnt_share of K
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) 'E', 'K', 'F', 'G' have their ->mnt_master point to struct vfsmount of 'A'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) 'M', 'L', 'N' have their ->mnt_master point to struct vfsmount of 'K'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) K's ->mnt_slave_list links with ->mnt_slave of 'M', 'L' and 'N'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) C's ->mnt_slave_list links with ->mnt_slave of 'J' and 'K'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) J and K's ->mnt_master points to struct vfsmount of C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) and finally D's ->mnt_slave_list links with ->mnt_slave of 'H' and 'I'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) 'H' and 'I' have their ->mnt_master pointing to struct vfsmount of 'D'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) NOTE: The propagation tree is orthogonal to the mount tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) 8B Locking:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) ->mnt_share, ->mnt_slave, ->mnt_slave_list, ->mnt_master are protected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) by namespace_sem (exclusive for modifications, shared for reading).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) Normally we have ->mnt_flags modifications serialized by vfsmount_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) There are two exceptions: do_add_mount() and clone_mnt().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) The former modifies a vfsmount that has not been visible in any shared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) data structures yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) The latter holds namespace_sem and the only references to vfsmount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) are in lists that can't be traversed without namespace_sem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) 8C Algorithm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) The crux of the implementation resides in rbind/move operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) The overall algorithm breaks the operation into 3 phases: (look at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) attach_recursive_mnt() and propagate_mnt())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) 1. prepare phase.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) 2. commit phases.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) 3. abort phases.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) Prepare phase:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) for each mount in the source tree:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) a) Create the necessary number of mount trees to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) be attached to each of the mounts that receive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) propagation from the destination mount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) b) Do not attach any of the trees to its destination.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) However note down its ->mnt_parent and ->mnt_mountpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) c) Link all the new mounts to form a propagation tree that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) is identical to the propagation tree of the destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) mount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) If this phase is successful, there should be 'n' new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) propagation trees; where 'n' is the number of mounts in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) source tree. Go to the commit phase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) Also there should be 'm' new mount trees, where 'm' is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) the number of mounts to which the destination mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) propagates to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) if any memory allocations fail, go to the abort phase.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) Commit phase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) attach each of the mount trees to their corresponding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) destination mounts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) Abort phase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) delete all the newly created trees.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) .. Note::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) all the propagation related functionality resides in the file pnode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) ------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) version 0.1 (created the initial document, Ram Pai linuxram@us.ibm.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) version 0.2 (Incorporated comments from Al Viro)