github.com/zhouyu0/docker-note@v0.0.0-20190722021225-b8d3825084db/pkg/mount/sharedsubtree_linux.go (about) 1 package mount // import "github.com/docker/docker/pkg/mount" 2 3 // MakeShared ensures a mounted filesystem has the SHARED mount option enabled. 4 // See the supported options in flags.go for further reference. 5 func MakeShared(mountPoint string) error { 6 return ensureMountedAs(mountPoint, "shared") 7 } 8 9 // MakeRShared ensures a mounted filesystem has the RSHARED mount option enabled. 10 // See the supported options in flags.go for further reference. 11 func MakeRShared(mountPoint string) error { 12 return ensureMountedAs(mountPoint, "rshared") 13 } 14 15 // MakePrivate ensures a mounted filesystem has the PRIVATE mount option enabled. 16 // See the supported options in flags.go for further reference. 17 func MakePrivate(mountPoint string) error { 18 return ensureMountedAs(mountPoint, "private") 19 } 20 21 // MakeRPrivate ensures a mounted filesystem has the RPRIVATE mount option 22 // enabled. See the supported options in flags.go for further reference. 23 func MakeRPrivate(mountPoint string) error { 24 return ensureMountedAs(mountPoint, "rprivate") 25 } 26 27 // MakeSlave ensures a mounted filesystem has the SLAVE mount option enabled. 28 // See the supported options in flags.go for further reference. 29 func MakeSlave(mountPoint string) error { 30 return ensureMountedAs(mountPoint, "slave") 31 } 32 33 // MakeRSlave ensures a mounted filesystem has the RSLAVE mount option enabled. 34 // See the supported options in flags.go for further reference. 35 func MakeRSlave(mountPoint string) error { 36 return ensureMountedAs(mountPoint, "rslave") 37 } 38 39 // MakeUnbindable ensures a mounted filesystem has the UNBINDABLE mount option 40 // enabled. See the supported options in flags.go for further reference. 41 func MakeUnbindable(mountPoint string) error { 42 return ensureMountedAs(mountPoint, "unbindable") 43 } 44 45 // MakeRUnbindable ensures a mounted filesystem has the RUNBINDABLE mount 46 // option enabled. See the supported options in flags.go for further reference. 47 func MakeRUnbindable(mountPoint string) error { 48 return ensureMountedAs(mountPoint, "runbindable") 49 } 50 51 // MakeMount ensures that the file or directory given is a mount point, 52 // bind mounting it to itself it case it is not. 53 func MakeMount(mnt string) error { 54 mounted, err := Mounted(mnt) 55 if err != nil { 56 return err 57 } 58 if mounted { 59 return nil 60 } 61 62 return Mount(mnt, mnt, "none", "bind") 63 } 64 65 func ensureMountedAs(mountPoint, options string) error { 66 if err := MakeMount(mountPoint); err != nil { 67 return err 68 } 69 70 return ForceMount("", mountPoint, "none", options) 71 }