Remove shelling out to mount
Also remove the target from the Mount struct because it should not be used at all. The target can be variable and set by a caller, not by the snapshot drivers. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
39
mount.go
39
mount.go
@@ -1,8 +1,6 @@
|
||||
package containerd
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
@@ -12,48 +10,23 @@ import (
|
||||
type Mount struct {
|
||||
// Type specifies the host-specific of the mount.
|
||||
Type string
|
||||
|
||||
// Source specifies where to mount from. Depending on the host system, this
|
||||
// can be a source path or device.
|
||||
Source string
|
||||
|
||||
// Target is the filesystem mount location.
|
||||
Target string
|
||||
|
||||
// Options contains zero or more fstab-style mount options. Typically,
|
||||
// these are platform specific.
|
||||
Options []string
|
||||
}
|
||||
|
||||
// MountCommand converts the provided mount into a CLI arguments that can be used to mount the
|
||||
func MountCommand(m Mount) []string {
|
||||
return []string{
|
||||
"mount",
|
||||
"-t", strings.ToLower(m.Type),
|
||||
m.Source,
|
||||
m.Target,
|
||||
"-o", strings.Join(m.Options, ","),
|
||||
}
|
||||
func (m *Mount) Mount(target string) error {
|
||||
flags, data := parseMountOptions(m.Options)
|
||||
return syscall.Mount(m.Source, target, m.Type, uintptr(flags), data)
|
||||
}
|
||||
|
||||
func MountAll(mounts ...Mount) error {
|
||||
for _, mount := range mounts {
|
||||
cmd := exec.Command("mount", MountCommand(mount)[1:]...)
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdout = os.Stdout
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func MountFS(mounts []Mount, target string) error {
|
||||
// MountAll mounts all the provided mounts to the provided target
|
||||
func MountAll(mounts []Mount, target string) error {
|
||||
for _, m := range mounts {
|
||||
flags, data := parseMountOptions(m.Options)
|
||||
if err := syscall.Mount(m.Source, target, m.Type, uintptr(flags), data); err != nil {
|
||||
if err := m.Mount(target); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user