Skip to content

Commit

Permalink
Fix 9pfs mounts of hostPath volumes
Browse files Browse the repository at this point in the history
hostPath was only working for the host paths that are mounted inside
the virtlet container.
  • Loading branch information
Ivan Shvedunov committed Feb 11, 2019
1 parent 65b0b91 commit caaee11
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
3 changes: 2 additions & 1 deletion pkg/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ type DelimitedReader interface {
// FileSystem defines a filesystem interface interface
type FileSystem interface {
// Mount mounts the specified source under the target path.
// For bind mounts, bind must be true.
// For bind mounts, bind must be true. The bind mounts will
// happen in the host mount namespace (that of PID 1).
Mount(source string, target string, fstype string, bind bool) error
// Unmount unmounts the specified target directory. If detach
// is true, MNT_DETACH option is used (disconnect the
Expand Down
22 changes: 17 additions & 5 deletions pkg/fs/fs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,27 @@ limitations under the License.

package fs

import "syscall"
import (
"fmt"
"os/exec"
"syscall"
)

// Mount inplements Mount method of FileSystem interface.
func (fs *realFileSystem) Mount(source string, target string, fstype string, bind bool) error {
flags := uintptr(0)
if bind {
flags = syscall.MS_BIND | syscall.MS_REC
if !bind {
return syscall.Mount(source, target, fstype, uintptr(0), "")
}
return syscall.Mount(source, target, fstype, flags, "")

// In case of bind mounts, we want to do it in the outer mount namespace.
// This is used for hostPath volumes, for example.
args := []string{"/usr/bin/nsenter", "-t", "1", "-m", "/bin/mount", "--bind", source, target}
if out, err := exec.Command(args[0], args[1:]...).CombinedOutput(); err != nil {
return fmt.Errorf("mount %v: %v; output: %v", args, err, string(out))
}

return nil

}

// Unmount inplements Unmount method of FileSystem interface.
Expand Down

0 comments on commit caaee11

Please sign in to comment.