Commit 629718ef authored by mtanino's avatar mtanino

Refactoring and improvements for iSCSI and FC

This PR makes following changes. - Simplify volume tearDown path for iSCSI and FC using util.UnmountPath(). - Log lastErr during iscsi connection If iscsid fails to connect second portal, currently the error is ignored silently. The lastErr should be logged to find the root cause of problem. - Remove iscsi plugin directory after iscsi connection is successfully closed.
parent 00c1ec52
...@@ -89,33 +89,3 @@ func diskSetUp(manager diskManager, b fcDiskMounter, volPath string, mounter mou ...@@ -89,33 +89,3 @@ func diskSetUp(manager diskManager, b fcDiskMounter, volPath string, mounter mou
return nil return nil
} }
// utility to tear down a disk based filesystem
func diskTearDown(manager diskManager, c fcDiskUnmounter, volPath string, mounter mount.Interface) error {
noMnt, err := mounter.IsLikelyNotMountPoint(volPath)
if err != nil {
glog.Errorf("cannot validate mountpoint %s", volPath)
return err
}
if noMnt {
return os.Remove(volPath)
}
if err := mounter.Unmount(volPath); err != nil {
glog.Errorf("failed to unmount %s", volPath)
return err
}
noMnt, mntErr := mounter.IsLikelyNotMountPoint(volPath)
if mntErr != nil {
glog.Errorf("isMountpoint check failed: %v", mntErr)
return err
}
if noMnt {
if err := os.Remove(volPath); err != nil {
return err
}
}
return nil
}
...@@ -240,13 +240,7 @@ func (c *fcDiskUnmounter) TearDown() error { ...@@ -240,13 +240,7 @@ func (c *fcDiskUnmounter) TearDown() error {
} }
func (c *fcDiskUnmounter) TearDownAt(dir string) error { func (c *fcDiskUnmounter) TearDownAt(dir string) error {
if pathExists, pathErr := util.PathExists(dir); pathErr != nil { return util.UnmountPath(dir, c.mounter)
return fmt.Errorf("Error checking if path exists: %v", pathErr)
} else if !pathExists {
glog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
return nil
}
return diskTearDown(c.manager, *c, dir, c.mounter)
} }
func getVolumeSource(spec *volume.Spec) (*v1.FCVolumeSource, bool, error) { func getVolumeSource(spec *volume.Spec) (*v1.FCVolumeSource, bool, error) {
......
...@@ -147,6 +147,11 @@ func (detacher *iscsiDetacher) UnmountDevice(deviceMountPath string) error { ...@@ -147,6 +147,11 @@ func (detacher *iscsiDetacher) UnmountDevice(deviceMountPath string) error {
if err != nil { if err != nil {
return fmt.Errorf("iscsi: failed to detach disk: %s\nError: %v", deviceMountPath, err) return fmt.Errorf("iscsi: failed to detach disk: %s\nError: %v", deviceMountPath, err)
} }
glog.V(4).Infof("iscsi: %q is unmounted, deleting the directory", deviceMountPath)
err = os.RemoveAll(deviceMountPath)
if err != nil {
return fmt.Errorf("iscsi: failed to delete the directory: %s\nError: %v", deviceMountPath, err)
}
glog.V(4).Infof("iscsi: successfully detached disk: %s", deviceMountPath) glog.V(4).Infof("iscsi: successfully detached disk: %s", deviceMountPath)
return nil return nil
} }
......
...@@ -94,36 +94,3 @@ func diskSetUp(manager diskManager, b iscsiDiskMounter, volPath string, mounter ...@@ -94,36 +94,3 @@ func diskSetUp(manager diskManager, b iscsiDiskMounter, volPath string, mounter
return nil return nil
} }
// utility to tear down a disk based filesystem
func diskTearDown(manager diskManager, c iscsiDiskUnmounter, volPath string, mounter mount.Interface) error {
notMnt, err := mounter.IsLikelyNotMountPoint(volPath)
if err != nil {
glog.Errorf("cannot validate mountpoint %s", volPath)
return err
}
if notMnt {
return os.Remove(volPath)
}
_, err = mount.GetMountRefs(mounter, volPath)
if err != nil {
glog.Errorf("failed to get reference count %s", volPath)
return err
}
if err := mounter.Unmount(volPath); err != nil {
glog.Errorf("failed to unmount %s", volPath)
return err
}
notMnt, mntErr := mounter.IsLikelyNotMountPoint(volPath)
if mntErr != nil {
glog.Errorf("IsLikelyNotMountPoint check failed: %v", mntErr)
return err
}
if notMnt {
if err := os.Remove(volPath); err != nil {
return err
}
}
return nil
}
...@@ -267,13 +267,7 @@ func (c *iscsiDiskUnmounter) TearDown() error { ...@@ -267,13 +267,7 @@ func (c *iscsiDiskUnmounter) TearDown() error {
} }
func (c *iscsiDiskUnmounter) TearDownAt(dir string) error { func (c *iscsiDiskUnmounter) TearDownAt(dir string) error {
if pathExists, pathErr := ioutil.PathExists(dir); pathErr != nil { return ioutil.UnmountPath(dir, c.mounter)
return fmt.Errorf("Error checking if path exists: %v", pathErr)
} else if !pathExists {
glog.Warningf("Warning: Unmount skipped because path does not exist: %v", dir)
return nil
}
return diskTearDown(c.manager, *c, dir, c.mounter)
} }
func portalMounter(portal string) string { func portalMounter(portal string) string {
......
...@@ -293,6 +293,9 @@ func (util *ISCSIUtil) AttachDisk(b iscsiDiskMounter) (string, error) { ...@@ -293,6 +293,9 @@ func (util *ISCSIUtil) AttachDisk(b iscsiDiskMounter) (string, error) {
glog.Errorf("iscsi: failed to get any path for iscsi disk, last err seen:\n%v", lastErr) glog.Errorf("iscsi: failed to get any path for iscsi disk, last err seen:\n%v", lastErr)
return "", fmt.Errorf("failed to get any path for iscsi disk, last err seen:\n%v", lastErr) return "", fmt.Errorf("failed to get any path for iscsi disk, last err seen:\n%v", lastErr)
} }
if lastErr != nil {
glog.Errorf("iscsi: last error occurred during iscsi init:\n%v", lastErr)
}
//Make sure we use a valid devicepath to find mpio device. //Make sure we use a valid devicepath to find mpio device.
devicePath = devicePaths[0] devicePath = devicePaths[0]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment