github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/pkg/mount/sharedsubtree_linux.go (about)

     1  // +build linux
     2  
     3  package mount
     4  
     5  // MakeShared ensures a mounted filesystem has the SHARED mount option enabled.
     6  // See the supported options in flags.go for further reference.
     7  func MakeShared(mountPoint string) error {
     8  	return ensureMountedAs(mountPoint, "shared")
     9  }
    10  
    11  // MakeRShared ensures a mounted filesystem has the RSHARED mount option enabled.
    12  // See the supported options in flags.go for further reference.
    13  func MakeRShared(mountPoint string) error {
    14  	return ensureMountedAs(mountPoint, "rshared")
    15  }
    16  
    17  // MakePrivate ensures a mounted filesystem has the PRIVATE mount option enabled.
    18  // See the supported options in flags.go for further reference.
    19  func MakePrivate(mountPoint string) error {
    20  	return ensureMountedAs(mountPoint, "private")
    21  }
    22  
    23  // MakeRPrivate ensures a mounted filesystem has the RPRIVATE mount option
    24  // enabled. See the supported options in flags.go for further reference.
    25  func MakeRPrivate(mountPoint string) error {
    26  	return ensureMountedAs(mountPoint, "rprivate")
    27  }
    28  
    29  // MakeSlave ensures a mounted filesystem has the SLAVE mount option enabled.
    30  // See the supported options in flags.go for further reference.
    31  func MakeSlave(mountPoint string) error {
    32  	return ensureMountedAs(mountPoint, "slave")
    33  }
    34  
    35  // MakeRSlave ensures a mounted filesystem has the RSLAVE mount option enabled.
    36  // See the supported options in flags.go for further reference.
    37  func MakeRSlave(mountPoint string) error {
    38  	return ensureMountedAs(mountPoint, "rslave")
    39  }
    40  
    41  // MakeUnbindable ensures a mounted filesystem has the UNBINDABLE mount option
    42  // enabled. See the supported options in flags.go for further reference.
    43  func MakeUnbindable(mountPoint string) error {
    44  	return ensureMountedAs(mountPoint, "unbindable")
    45  }
    46  
    47  // MakeRUnbindable ensures a mounted filesystem has the RUNBINDABLE mount
    48  // option enabled. See the supported options in flags.go for further reference.
    49  func MakeRUnbindable(mountPoint string) error {
    50  	return ensureMountedAs(mountPoint, "runbindable")
    51  }
    52  
    53  func ensureMountedAs(mountPoint, options string) error {
    54  	mounted, err := Mounted(mountPoint)
    55  	if err != nil {
    56  		return err
    57  	}
    58  
    59  	if !mounted {
    60  		if err := Mount(mountPoint, mountPoint, "none", "bind,rw"); err != nil {
    61  			return err
    62  		}
    63  	}
    64  	if _, err = Mounted(mountPoint); err != nil {
    65  		return err
    66  	}
    67  
    68  	return ForceMount("", mountPoint, "none", options)
    69  }