Change mount.Interface.Mount to exec('mount'), instead of syscall

This commit is contained in:
Deyuan Deng
2015-04-02 21:08:04 -04:00
committed by Deyuan Deng
parent 8fa21ebd62
commit 6897095e56
20 changed files with 188 additions and 238 deletions

View File

@@ -55,11 +55,11 @@ func diskSetUp(manager diskManager, disk iscsiDisk, volPath string, mounter moun
return err
}
// Perform a bind mount to the full path to allow duplicate mounts of the same disk.
flags := uintptr(0)
options := []string{"bind"}
if disk.readOnly {
flags = mount.FlagReadOnly
options = append(options, "ro")
}
err = mounter.Mount(globalPDPath, volPath, "", mount.FlagBind|flags, "")
err = mounter.Mount(globalPDPath, volPath, "", options)
if err != nil {
glog.Errorf("failed to bind mount:%s", globalPDPath)
return err
@@ -83,8 +83,8 @@ func diskTearDown(manager diskManager, disk iscsiDisk, volPath string, mounter m
glog.Errorf("failed to get reference count %s", volPath)
return err
}
if err := mounter.Unmount(volPath, 0); err != nil {
glog.Errorf("failed to umount %s", volPath)
if err := mounter.Unmount(volPath); err != nil {
glog.Errorf("failed to unmount %s", volPath)
return err
}
// If len(refs) is 1, then all bind mounts have been removed, and the

View File

@@ -110,6 +110,11 @@ func (plugin *ISCSIPlugin) newCleanerInternal(volName string, podUID types.UID,
}, nil
}
func (plugin *ISCSIPlugin) execCommand(command string, args []string) ([]byte, error) {
cmd := plugin.exe.Command(command, args...)
return cmd.CombinedOutput()
}
type iscsiDisk struct {
volName string
podUID types.UID
@@ -142,15 +147,13 @@ func (iscsi *iscsiDisk) SetUpAt(dir string) error {
return err
}
globalPDPath := iscsi.manager.MakeGlobalPDName(*iscsi)
// make mountpoint rw/ro work as expected
//FIXME revisit pkg/util/mount and ensure rw/ro is implemented as expected
mode := "rw"
var options []string
if iscsi.readOnly {
mode = "ro"
options = []string{"remount", "ro"}
} else {
options = []string{"remount", "rw"}
}
iscsi.plugin.execCommand("mount", []string{"-o", "remount," + mode, globalPDPath, dir})
return nil
return iscsi.mounter.Mount(globalPDPath, dir, "", options)
}
// Unmounts the bind mount, and detaches the disk only if the disk
@@ -162,8 +165,3 @@ func (iscsi *iscsiDisk) TearDown() error {
func (iscsi *iscsiDisk) TearDownAt(dir string) error {
return diskTearDown(iscsi.manager, *iscsi, dir, iscsi.mounter)
}
func (plugin *ISCSIPlugin) execCommand(command string, args []string) ([]byte, error) {
cmd := plugin.exe.Command(command, args...)
return cmd.CombinedOutput()
}

View File

@@ -55,7 +55,7 @@ func (fake *fakeDiskManager) AttachDisk(disk iscsiDisk) error {
}
// Simulate the global mount so that the fakeMounter returns the
// expected number of mounts for the attached disk.
disk.mounter.Mount(globalPath, globalPath, disk.fsType, 0, "")
disk.mounter.Mount(globalPath, globalPath, disk.fsType, nil)
fake.attachCalled = true
return nil

View File

@@ -112,7 +112,7 @@ func (util *ISCSIUtil) AttachDisk(iscsi iscsiDisk) error {
return err
}
err = iscsi.mounter.Mount(devicePath, globalPDPath, iscsi.fsType, uintptr(0), "")
err = iscsi.mounter.Mount(devicePath, globalPDPath, iscsi.fsType, nil)
if err != nil {
glog.Errorf("iscsi: failed to mount iscsi volume %s [%s] to %s, error %v", devicePath, iscsi.fsType, globalPDPath, err)
}
@@ -126,8 +126,8 @@ func (util *ISCSIUtil) DetachDisk(iscsi iscsiDisk, mntPath string) error {
glog.Errorf("iscsi detach disk: failed to get device from mnt: %s\nError: %v", mntPath, err)
return err
}
if err = iscsi.mounter.Unmount(mntPath, 0); err != nil {
glog.Errorf("iscsi detach disk: failed to umount: %s\nError: %v", mntPath, err)
if err = iscsi.mounter.Unmount(mntPath); err != nil {
glog.Errorf("iscsi detach disk: failed to unmount: %s\nError: %v", mntPath, err)
return err
}
cnt--