This function ensures the argument is the mount point
(i.e. if it's not, it bind mounts it to itself).
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
| ... | ... |
@@ -48,16 +48,23 @@ func MakeRUnbindable(mountPoint string) error {
|
| 48 | 48 |
return ensureMountedAs(mountPoint, "runbindable") |
| 49 | 49 |
} |
| 50 | 50 |
|
| 51 |
-func ensureMountedAs(mountPoint, options string) error {
|
|
| 52 |
- mounted, err := Mounted(mountPoint) |
|
| 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) |
|
| 53 | 55 |
if err != nil {
|
| 54 | 56 |
return err |
| 55 | 57 |
} |
| 58 |
+ if mounted {
|
|
| 59 |
+ return nil |
|
| 60 |
+ } |
|
| 61 |
+ |
|
| 62 |
+ return Mount(mnt, mnt, "none", "bind") |
|
| 63 |
+} |
|
| 56 | 64 |
|
| 57 |
- if !mounted {
|
|
| 58 |
- if err := Mount(mountPoint, mountPoint, "none", "bind"); err != nil {
|
|
| 59 |
- return err |
|
| 60 |
- } |
|
| 65 |
+func ensureMountedAs(mountPoint, options string) error {
|
|
| 66 |
+ if err := MakeMount(mountPoint); err != nil {
|
|
| 67 |
+ return err |
|
| 61 | 68 |
} |
| 62 | 69 |
|
| 63 | 70 |
return ForceMount("", mountPoint, "none", options)
|