diff options
Diffstat (limited to 'Documentation/filesystems/sharedsubtree.txt')
| -rw-r--r-- | Documentation/filesystems/sharedsubtree.txt | 220 |
1 files changed, 42 insertions, 178 deletions
diff --git a/Documentation/filesystems/sharedsubtree.txt b/Documentation/filesystems/sharedsubtree.txt index 736540045dc7..23a181074f94 100644 --- a/Documentation/filesystems/sharedsubtree.txt +++ b/Documentation/filesystems/sharedsubtree.txt | |||
| @@ -4,7 +4,7 @@ Shared Subtrees | |||
| 4 | Contents: | 4 | Contents: |
| 5 | 1) Overview | 5 | 1) Overview |
| 6 | 2) Features | 6 | 2) Features |
| 7 | 3) smount command | 7 | 3) Setting mount states |
| 8 | 4) Use-case | 8 | 4) Use-case |
| 9 | 5) Detailed semantics | 9 | 5) Detailed semantics |
| 10 | 6) Quiz | 10 | 6) Quiz |
| @@ -41,14 +41,14 @@ replicas continue to be exactly same. | |||
| 41 | 41 | ||
| 42 | Here is an example: | 42 | Here is an example: |
| 43 | 43 | ||
| 44 | Lets say /mnt has a mount that is shared. | 44 | Let's say /mnt has a mount that is shared. |
| 45 | mount --make-shared /mnt | 45 | mount --make-shared /mnt |
| 46 | 46 | ||
| 47 | note: mount command does not yet support the --make-shared flag. | 47 | Note: mount(8) command now supports the --make-shared flag, |
| 48 | I have included a small C program which does the same by executing | 48 | so the sample 'smount' program is no longer needed and has been |
| 49 | 'smount /mnt shared' | 49 | removed. |
| 50 | 50 | ||
| 51 | #mount --bind /mnt /tmp | 51 | # mount --bind /mnt /tmp |
| 52 | The above command replicates the mount at /mnt to the mountpoint /tmp | 52 | The above command replicates the mount at /mnt to the mountpoint /tmp |
| 53 | and the contents of both the mounts remain identical. | 53 | and the contents of both the mounts remain identical. |
| 54 | 54 | ||
| @@ -58,8 +58,8 @@ replicas continue to be exactly same. | |||
| 58 | #ls /tmp | 58 | #ls /tmp |
| 59 | a b c | 59 | a b c |
| 60 | 60 | ||
| 61 | Now lets say we mount a device at /tmp/a | 61 | Now let's say we mount a device at /tmp/a |
| 62 | #mount /dev/sd0 /tmp/a | 62 | # mount /dev/sd0 /tmp/a |
| 63 | 63 | ||
| 64 | #ls /tmp/a | 64 | #ls /tmp/a |
| 65 | t1 t2 t2 | 65 | t1 t2 t2 |
| @@ -80,21 +80,20 @@ replicas continue to be exactly same. | |||
| 80 | 80 | ||
| 81 | Here is an example: | 81 | Here is an example: |
| 82 | 82 | ||
| 83 | Lets say /mnt has a mount which is shared. | 83 | Let's say /mnt has a mount which is shared. |
| 84 | #mount --make-shared /mnt | 84 | # mount --make-shared /mnt |
| 85 | 85 | ||
| 86 | Lets bind mount /mnt to /tmp | 86 | Let's bind mount /mnt to /tmp |
| 87 | #mount --bind /mnt /tmp | 87 | # mount --bind /mnt /tmp |
| 88 | 88 | ||
| 89 | the new mount at /tmp becomes a shared mount and it is a replica of | 89 | the new mount at /tmp becomes a shared mount and it is a replica of |
| 90 | the mount at /mnt. | 90 | the mount at /mnt. |
| 91 | 91 | ||
| 92 | Now lets make the mount at /tmp; a slave of /mnt | 92 | Now let's make the mount at /tmp; a slave of /mnt |
| 93 | #mount --make-slave /tmp | 93 | # mount --make-slave /tmp |
| 94 | [or smount /tmp slave] | ||
| 95 | 94 | ||
| 96 | lets mount /dev/sd0 on /mnt/a | 95 | let's mount /dev/sd0 on /mnt/a |
| 97 | #mount /dev/sd0 /mnt/a | 96 | # mount /dev/sd0 /mnt/a |
| 98 | 97 | ||
| 99 | #ls /mnt/a | 98 | #ls /mnt/a |
| 100 | t1 t2 t3 | 99 | t1 t2 t3 |
| @@ -104,9 +103,9 @@ replicas continue to be exactly same. | |||
| 104 | 103 | ||
| 105 | Note the mount event has propagated to the mount at /tmp | 104 | Note the mount event has propagated to the mount at /tmp |
| 106 | 105 | ||
| 107 | However lets see what happens if we mount something on the mount at /tmp | 106 | However let's see what happens if we mount something on the mount at /tmp |
| 108 | 107 | ||
| 109 | #mount /dev/sd1 /tmp/b | 108 | # mount /dev/sd1 /tmp/b |
| 110 | 109 | ||
| 111 | #ls /tmp/b | 110 | #ls /tmp/b |
| 112 | s1 s2 s3 | 111 | s1 s2 s3 |
| @@ -124,12 +123,11 @@ replicas continue to be exactly same. | |||
| 124 | 123 | ||
| 125 | 2d) A unbindable mount is a unbindable private mount | 124 | 2d) A unbindable mount is a unbindable private mount |
| 126 | 125 | ||
| 127 | lets say we have a mount at /mnt and we make is unbindable | 126 | let's say we have a mount at /mnt and we make is unbindable |
| 128 | 127 | ||
| 129 | #mount --make-unbindable /mnt | 128 | # mount --make-unbindable /mnt |
| 130 | [ smount /mnt unbindable ] | ||
| 131 | 129 | ||
| 132 | Lets try to bind mount this mount somewhere else. | 130 | Let's try to bind mount this mount somewhere else. |
| 133 | # mount --bind /mnt /tmp | 131 | # mount --bind /mnt /tmp |
| 134 | mount: wrong fs type, bad option, bad superblock on /mnt, | 132 | mount: wrong fs type, bad option, bad superblock on /mnt, |
| 135 | or too many mounted file systems | 133 | or too many mounted file systems |
| @@ -137,149 +135,15 @@ replicas continue to be exactly same. | |||
| 137 | Binding a unbindable mount is a invalid operation. | 135 | Binding a unbindable mount is a invalid operation. |
| 138 | 136 | ||
| 139 | 137 | ||
| 140 | 3) smount command | 138 | 3) Setting mount states |
| 141 | 139 | ||
| 142 | Currently the mount command is not aware of shared subtree features. | 140 | The mount command (util-linux package) can be used to set mount |
| 143 | Work is in progress to add the support in mount ( util-linux package ). | 141 | states: |
| 144 | Till then use the following program. | ||
| 145 | 142 | ||
| 146 | ------------------------------------------------------------------------ | 143 | mount --make-shared mountpoint |
| 147 | // | 144 | mount --make-slave mountpoint |
| 148 | //this code was developed my Miklos Szeredi <miklos@szeredi.hu> | 145 | mount --make-private mountpoint |
| 149 | //and modified by Ram Pai <linuxram@us.ibm.com> | 146 | mount --make-unbindable mountpoint |
| 150 | // sample usage: | ||
| 151 | // smount /tmp shared | ||
| 152 | // | ||
| 153 | #include <stdio.h> | ||
| 154 | #include <stdlib.h> | ||
| 155 | #include <unistd.h> | ||
| 156 | #include <string.h> | ||
| 157 | #include <sys/mount.h> | ||
| 158 | #include <sys/fsuid.h> | ||
| 159 | |||
| 160 | #ifndef MS_REC | ||
| 161 | #define MS_REC 0x4000 /* 16384: Recursive loopback */ | ||
| 162 | #endif | ||
| 163 | |||
| 164 | #ifndef MS_SHARED | ||
| 165 | #define MS_SHARED 1<<20 /* Shared */ | ||
| 166 | #endif | ||
| 167 | |||
| 168 | #ifndef MS_PRIVATE | ||
| 169 | #define MS_PRIVATE 1<<18 /* Private */ | ||
| 170 | #endif | ||
| 171 | |||
| 172 | #ifndef MS_SLAVE | ||
| 173 | #define MS_SLAVE 1<<19 /* Slave */ | ||
| 174 | #endif | ||
| 175 | |||
| 176 | #ifndef MS_UNBINDABLE | ||
| 177 | #define MS_UNBINDABLE 1<<17 /* Unbindable */ | ||
| 178 | #endif | ||
| 179 | |||
| 180 | int main(int argc, char *argv[]) | ||
| 181 | { | ||
| 182 | int type; | ||
| 183 | if(argc != 3) { | ||
| 184 | fprintf(stderr, "usage: %s dir " | ||
| 185 | "<rshared|rslave|rprivate|runbindable|shared|slave" | ||
| 186 | "|private|unbindable>\n" , argv[0]); | ||
| 187 | return 1; | ||
| 188 | } | ||
| 189 | |||
| 190 | fprintf(stdout, "%s %s %s\n", argv[0], argv[1], argv[2]); | ||
| 191 | |||
| 192 | if (strcmp(argv[2],"rshared")==0) | ||
| 193 | type=(MS_SHARED|MS_REC); | ||
| 194 | else if (strcmp(argv[2],"rslave")==0) | ||
| 195 | type=(MS_SLAVE|MS_REC); | ||
| 196 | else if (strcmp(argv[2],"rprivate")==0) | ||
| 197 | type=(MS_PRIVATE|MS_REC); | ||
| 198 | else if (strcmp(argv[2],"runbindable")==0) | ||
| 199 | type=(MS_UNBINDABLE|MS_REC); | ||
| 200 | else if (strcmp(argv[2],"shared")==0) | ||
| 201 | type=MS_SHARED; | ||
| 202 | else if (strcmp(argv[2],"slave")==0) | ||
| 203 | type=MS_SLAVE; | ||
| 204 | else if (strcmp(argv[2],"private")==0) | ||
| 205 | type=MS_PRIVATE; | ||
| 206 | else if (strcmp(argv[2],"unbindable")==0) | ||
| 207 | type=MS_UNBINDABLE; | ||
| 208 | else { | ||
| 209 | fprintf(stderr, "invalid operation: %s\n", argv[2]); | ||
| 210 | return 1; | ||
| 211 | } | ||
| 212 | setfsuid(getuid()); | ||
| 213 | |||
| 214 | if(mount("", argv[1], "dontcare", type, "") == -1) { | ||
| 215 | perror("mount"); | ||
| 216 | return 1; | ||
| 217 | } | ||
| 218 | return 0; | ||
| 219 | } | ||
| 220 | ----------------------------------------------------------------------- | ||
| 221 | |||
| 222 | Copy the above code snippet into smount.c | ||
| 223 | gcc -o smount smount.c | ||
| 224 | |||
| 225 | |||
| 226 | (i) To mark all the mounts under /mnt as shared execute the following | ||
| 227 | command: | ||
| 228 | |||
| 229 | smount /mnt rshared | ||
| 230 | the corresponding syntax planned for mount command is | ||
| 231 | mount --make-rshared /mnt | ||
| 232 | |||
| 233 | just to mark a mount /mnt as shared, execute the following | ||
| 234 | command: | ||
| 235 | smount /mnt shared | ||
| 236 | the corresponding syntax planned for mount command is | ||
| 237 | mount --make-shared /mnt | ||
| 238 | |||
| 239 | (ii) To mark all the shared mounts under /mnt as slave execute the | ||
| 240 | following | ||
| 241 | |||
| 242 | command: | ||
| 243 | smount /mnt rslave | ||
| 244 | the corresponding syntax planned for mount command is | ||
| 245 | mount --make-rslave /mnt | ||
| 246 | |||
| 247 | just to mark a mount /mnt as slave, execute the following | ||
| 248 | command: | ||
| 249 | smount /mnt slave | ||
| 250 | the corresponding syntax planned for mount command is | ||
| 251 | mount --make-slave /mnt | ||
| 252 | |||
| 253 | (iii) To mark all the mounts under /mnt as private execute the | ||
| 254 | following command: | ||
| 255 | |||
| 256 | smount /mnt rprivate | ||
| 257 | the corresponding syntax planned for mount command is | ||
| 258 | mount --make-rprivate /mnt | ||
| 259 | |||
| 260 | just to mark a mount /mnt as private, execute the following | ||
| 261 | command: | ||
| 262 | smount /mnt private | ||
| 263 | the corresponding syntax planned for mount command is | ||
| 264 | mount --make-private /mnt | ||
| 265 | |||
| 266 | NOTE: by default all the mounts are created as private. But if | ||
| 267 | you want to change some shared/slave/unbindable mount as | ||
| 268 | private at a later point in time, this command can help. | ||
| 269 | |||
| 270 | (iv) To mark all the mounts under /mnt as unbindable execute the | ||
| 271 | following | ||
| 272 | |||
| 273 | command: | ||
| 274 | smount /mnt runbindable | ||
| 275 | the corresponding syntax planned for mount command is | ||
| 276 | mount --make-runbindable /mnt | ||
| 277 | |||
| 278 | just to mark a mount /mnt as unbindable, execute the following | ||
| 279 | command: | ||
| 280 | smount /mnt unbindable | ||
| 281 | the corresponding syntax planned for mount command is | ||
| 282 | mount --make-unbindable /mnt | ||
| 283 | 147 | ||
| 284 | 148 | ||
| 285 | 4) Use cases | 149 | 4) Use cases |
| @@ -350,7 +214,7 @@ replicas continue to be exactly same. | |||
| 350 | mount --rbind / /view/v3 | 214 | mount --rbind / /view/v3 |
| 351 | mount --rbind / /view/v4 | 215 | mount --rbind / /view/v4 |
| 352 | 216 | ||
| 353 | and if /usr has a versioning filesystem mounted, than that | 217 | and if /usr has a versioning filesystem mounted, then that |
| 354 | mount appears at /view/v1/usr, /view/v2/usr, /view/v3/usr and | 218 | mount appears at /view/v1/usr, /view/v2/usr, /view/v3/usr and |
| 355 | /view/v4/usr too | 219 | /view/v4/usr too |
| 356 | 220 | ||
| @@ -390,7 +254,7 @@ replicas continue to be exactly same. | |||
| 390 | 254 | ||
| 391 | For example: | 255 | For example: |
| 392 | mount --make-shared /mnt | 256 | mount --make-shared /mnt |
| 393 | mount --bin /mnt /tmp | 257 | mount --bind /mnt /tmp |
| 394 | 258 | ||
| 395 | The mount at /mnt and that at /tmp are both shared and belong | 259 | The mount at /mnt and that at /tmp are both shared and belong |
| 396 | to the same peer group. Anything mounted or unmounted under | 260 | to the same peer group. Anything mounted or unmounted under |
| @@ -558,7 +422,7 @@ replicas continue to be exactly same. | |||
| 558 | then the subtree under the unbindable mount is pruned in the new | 422 | then the subtree under the unbindable mount is pruned in the new |
| 559 | location. | 423 | location. |
| 560 | 424 | ||
| 561 | eg: lets say we have the following mount tree. | 425 | eg: let's say we have the following mount tree. |
| 562 | 426 | ||
| 563 | A | 427 | A |
| 564 | / \ | 428 | / \ |
| @@ -566,7 +430,7 @@ replicas continue to be exactly same. | |||
| 566 | / \ / \ | 430 | / \ / \ |
| 567 | D E F G | 431 | D E F G |
| 568 | 432 | ||
| 569 | Lets say all the mount except the mount C in the tree are | 433 | Let's say all the mount except the mount C in the tree are |
| 570 | of a type other than unbindable. | 434 | of a type other than unbindable. |
| 571 | 435 | ||
| 572 | If this tree is rbound to say Z | 436 | If this tree is rbound to say Z |
| @@ -683,13 +547,13 @@ replicas continue to be exactly same. | |||
| 683 | 'b' on mounts that receive propagation from mount 'B' and does not have | 547 | 'b' on mounts that receive propagation from mount 'B' and does not have |
| 684 | sub-mounts within them are unmounted. | 548 | sub-mounts within them are unmounted. |
| 685 | 549 | ||
| 686 | Example: Lets say 'B1', 'B2', 'B3' are shared mounts that propagate to | 550 | Example: Let's say 'B1', 'B2', 'B3' are shared mounts that propagate to |
| 687 | each other. | 551 | each other. |
| 688 | 552 | ||
| 689 | lets say 'A1', 'A2', 'A3' are first mounted at dentry 'b' on mount | 553 | let's say 'A1', 'A2', 'A3' are first mounted at dentry 'b' on mount |
| 690 | 'B1', 'B2' and 'B3' respectively. | 554 | 'B1', 'B2' and 'B3' respectively. |
| 691 | 555 | ||
| 692 | lets say 'C1', 'C2', 'C3' are next mounted at the same dentry 'b' on | 556 | let's say 'C1', 'C2', 'C3' are next mounted at the same dentry 'b' on |
| 693 | mount 'B1', 'B2' and 'B3' respectively. | 557 | mount 'B1', 'B2' and 'B3' respectively. |
| 694 | 558 | ||
| 695 | if 'C1' is unmounted, all the mounts that are most-recently-mounted on | 559 | if 'C1' is unmounted, all the mounts that are most-recently-mounted on |
| @@ -710,7 +574,7 @@ replicas continue to be exactly same. | |||
| 710 | A cloned namespace contains all the mounts as that of the parent | 574 | A cloned namespace contains all the mounts as that of the parent |
| 711 | namespace. | 575 | namespace. |
| 712 | 576 | ||
| 713 | Lets say 'A' and 'B' are the corresponding mounts in the parent and the | 577 | Let's say 'A' and 'B' are the corresponding mounts in the parent and the |
| 714 | child namespace. | 578 | child namespace. |
| 715 | 579 | ||
| 716 | If 'A' is shared, then 'B' is also shared and 'A' and 'B' propagate to | 580 | If 'A' is shared, then 'B' is also shared and 'A' and 'B' propagate to |
| @@ -759,11 +623,11 @@ replicas continue to be exactly same. | |||
| 759 | mount --make-slave /mnt | 623 | mount --make-slave /mnt |
| 760 | 624 | ||
| 761 | At this point we have the first mount at /tmp and | 625 | At this point we have the first mount at /tmp and |
| 762 | its root dentry is 1. Lets call this mount 'A' | 626 | its root dentry is 1. Let's call this mount 'A' |
| 763 | And then we have a second mount at /tmp1 with root | 627 | And then we have a second mount at /tmp1 with root |
| 764 | dentry 2. Lets call this mount 'B' | 628 | dentry 2. Let's call this mount 'B' |
| 765 | Next we have a third mount at /mnt with root dentry | 629 | Next we have a third mount at /mnt with root dentry |
| 766 | mnt. Lets call this mount 'C' | 630 | mnt. Let's call this mount 'C' |
| 767 | 631 | ||
| 768 | 'B' is the slave of 'A' and 'C' is a slave of 'B' | 632 | 'B' is the slave of 'A' and 'C' is a slave of 'B' |
| 769 | A -> B -> C | 633 | A -> B -> C |
| @@ -794,7 +658,7 @@ replicas continue to be exactly same. | |||
| 794 | 658 | ||
| 795 | Q3 Why is unbindable mount needed? | 659 | Q3 Why is unbindable mount needed? |
| 796 | 660 | ||
| 797 | Lets say we want to replicate the mount tree at multiple | 661 | Let's say we want to replicate the mount tree at multiple |
| 798 | locations within the same subtree. | 662 | locations within the same subtree. |
| 799 | 663 | ||
| 800 | if one rbind mounts a tree within the same subtree 'n' times | 664 | if one rbind mounts a tree within the same subtree 'n' times |
| @@ -803,7 +667,7 @@ replicas continue to be exactly same. | |||
| 803 | mounts. Here is a example. | 667 | mounts. Here is a example. |
| 804 | 668 | ||
| 805 | step 1: | 669 | step 1: |
| 806 | lets say the root tree has just two directories with | 670 | let's say the root tree has just two directories with |
| 807 | one vfsmount. | 671 | one vfsmount. |
| 808 | root | 672 | root |
| 809 | / \ | 673 | / \ |
| @@ -875,7 +739,7 @@ replicas continue to be exactly same. | |||
| 875 | Unclonable mounts come in handy here. | 739 | Unclonable mounts come in handy here. |
| 876 | 740 | ||
| 877 | step 1: | 741 | step 1: |
| 878 | lets say the root tree has just two directories with | 742 | let's say the root tree has just two directories with |
| 879 | one vfsmount. | 743 | one vfsmount. |
| 880 | root | 744 | root |
| 881 | / \ | 745 | / \ |
