Jelajahi Sumber

pkg/mount: add more sharesubtree options

Signed-off-by: Vincent Batts <vbatts@redhat.com>
Vincent Batts 10 tahun lalu
induk
melakukan
06bd66a1f8

+ 7 - 0
pkg/mount/flags.go

@@ -37,7 +37,14 @@ func parseOptions(options string) (int, string) {
 		"nodiratime":    {false, NODIRATIME},
 		"bind":          {false, BIND},
 		"rbind":         {false, RBIND},
+		"unbindable":    {false, UNBINDABLE},
+		"runbindable":   {false, RUNBINDABLE},
 		"private":       {false, PRIVATE},
+		"rprivate":      {false, RPRIVATE},
+		"shared":        {false, SHARED},
+		"rshared":       {false, RSHARED},
+		"slave":         {false, SLAVE},
+		"rslave":        {false, RSLAVE},
 		"relatime":      {false, RELATIME},
 		"norelatime":    {true, RELATIME},
 		"strictatime":   {false, STRICTATIME},

+ 7 - 0
pkg/mount/flags_freebsd.go

@@ -19,7 +19,14 @@ const (
 	MANDLOCK    = 0
 	NODEV       = 0
 	NODIRATIME  = 0
+	UNBINDABLE  = 0
+	RUNBINDABLE = 0
 	PRIVATE     = 0
+	RPRIVATE    = 0
+	SHARED      = 0
+	RSHARED     = 0
+	SLAVE       = 0
+	RSLAVE      = 0
 	RBIND       = 0
 	RELATIVE    = 0
 	RELATIME    = 0

+ 7 - 0
pkg/mount/flags_linux.go

@@ -17,7 +17,14 @@ const (
 	NODIRATIME  = syscall.MS_NODIRATIME
 	BIND        = syscall.MS_BIND
 	RBIND       = syscall.MS_BIND | syscall.MS_REC
+	UNBINDABLE  = syscall.MS_UNBINDABLE
+	RUNBINDABLE = syscall.MS_UNBINDABLE | syscall.MS_REC
 	PRIVATE     = syscall.MS_PRIVATE
+	RPRIVATE    = syscall.MS_PRIVATE | syscall.MS_REC
+	SLAVE       = syscall.MS_SLAVE
+	RSLAVE      = syscall.MS_SLAVE | syscall.MS_REC
+	SHARED      = syscall.MS_SHARED
+	RSHARED     = syscall.MS_SHARED | syscall.MS_REC
 	RELATIME    = syscall.MS_RELATIME
 	STRICTATIME = syscall.MS_STRICTATIME
 )

+ 7 - 0
pkg/mount/flags_unsupported.go

@@ -11,7 +11,14 @@ const (
 	NODIRATIME  = 0
 	NOEXEC      = 0
 	NOSUID      = 0
+	UNBINDABLE  = 0
+	RUNBINDABLE = 0
 	PRIVATE     = 0
+	RPRIVATE    = 0
+	SHARED      = 0
+	RSHARED     = 0
+	SLAVE       = 0
+	RSLAVE      = 0
 	RBIND       = 0
 	RELATIME    = 0
 	RELATIVE    = 0

+ 37 - 1
pkg/mount/sharedsubtree_linux.go

@@ -2,7 +2,39 @@
 
 package mount
 
+func MakeShared(mountPoint string) error {
+	return ensureMountedAs(mountPoint, "shared")
+}
+
+func MakeRShared(mountPoint string) error {
+	return ensureMountedAs(mountPoint, "rshared")
+}
+
 func MakePrivate(mountPoint string) error {
+	return ensureMountedAs(mountPoint, "private")
+}
+
+func MakeRPrivate(mountPoint string) error {
+	return ensureMountedAs(mountPoint, "rprivate")
+}
+
+func MakeSlave(mountPoint string) error {
+	return ensureMountedAs(mountPoint, "slave")
+}
+
+func MakeRSlave(mountPoint string) error {
+	return ensureMountedAs(mountPoint, "rslave")
+}
+
+func MakeUnbindable(mountPoint string) error {
+	return ensureMountedAs(mountPoint, "unbindable")
+}
+
+func MakeRUnbindable(mountPoint string) error {
+	return ensureMountedAs(mountPoint, "runbindable")
+}
+
+func ensureMountedAs(mountPoint, options string) error {
 	mounted, err := Mounted(mountPoint)
 	if err != nil {
 		return err
@@ -13,6 +45,10 @@ func MakePrivate(mountPoint string) error {
 			return err
 		}
 	}
+	mounted, err = Mounted(mountPoint)
+	if err != nil {
+		return err
+	}
 
-	return ForceMount("", mountPoint, "none", "private")
+	return ForceMount("", mountPoint, "none", options)
 }