Skip to content

Commit

Permalink
Merge pull request kata-containers#99 from sameo/topic/mount
Browse files Browse the repository at this point in the history
mount: Fixes for both 9pfs and virtio-blk/scsi
  • Loading branch information
bergwolf authored Jan 17, 2018
2 parents 3221222 + 4f73ac9 commit 6ea4f02
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,22 @@ var flagList = map[string]int{
"runbindable": unix.MS_UNBINDABLE | unix.MS_REC,
}

func createDestinationDir(dest string) error {
targetPath, _ := filepath.Split(dest)

return os.MkdirAll(targetPath, mountPerm)
}

// mount mounts a source in to a destination. This will do some bookkeeping:
// * evaluate all symlinks
// * ensure the source exists
func mount(source, destination, fsType string, flags int, options string) error {
var absSource string

if fsType != type9pFs {
absSource, err := filepath.EvalSymlinks(source)
var err error

absSource, err = filepath.EvalSymlinks(source)
if err != nil {
return fmt.Errorf("Could not resolve symlink for source %v", source)
}
Expand All @@ -74,6 +82,9 @@ func mount(source, destination, fsType string, flags int, options string) error
destination, err)
}
} else {
if err := createDestinationDir(destination); err != nil {
return err
}
absSource = source
}

Expand All @@ -95,10 +106,9 @@ func ensureDestinationExists(source, destination string, fsType string) error {
source)
}

targetPathParent, _ := filepath.Split(destination)
if err := os.MkdirAll(targetPathParent, mountPerm); err != nil {
if err := createDestinationDir(destination); err != nil {
return fmt.Errorf("could not create parent directory: %v",
targetPathParent)
destination)
}

if fsType != "bind" || fileInfo.IsDir() {
Expand Down

0 comments on commit 6ea4f02

Please sign in to comment.