From ffaff4e976b67d052139c6feb4e5427a78596781 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Thu, 27 Sep 2018 10:23:54 +0200 Subject: [PATCH 1/2] Fixed panic in iSCSI.UnmountDevice Fill iscsiDetacher.plugin so iscsiDetacher.plugin.targetLocks.LockKey(iqn) does not panic. --- pkg/volume/iscsi/attacher.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/volume/iscsi/attacher.go b/pkg/volume/iscsi/attacher.go index 82eccfd3d2..26e9e52808 100644 --- a/pkg/volume/iscsi/attacher.go +++ b/pkg/volume/iscsi/attacher.go @@ -137,6 +137,7 @@ type iscsiDetacher struct { host volume.VolumeHost mounter mount.Interface manager diskManager + plugin *iscsiPlugin } var _ volume.Detacher = &iscsiDetacher{} @@ -148,6 +149,7 @@ func (plugin *iscsiPlugin) NewDetacher() (volume.Detacher, error) { host: plugin.host, mounter: plugin.host.GetMounter(iscsiPluginName), manager: &ISCSIUtil{}, + plugin: plugin, }, nil } @@ -160,7 +162,7 @@ func (detacher *iscsiDetacher) Detach(volumeName string, nodeName types.NodeName } func (detacher *iscsiDetacher) UnmountDevice(deviceMountPath string) error { - unMounter := volumeSpecToUnmounter(detacher.mounter, detacher.host) + unMounter := volumeSpecToUnmounter(detacher.mounter, detacher.host, detacher.plugin) err := detacher.manager.DetachDisk(*unMounter, deviceMountPath) if err != nil { return fmt.Errorf("iscsi: failed to detach disk: %s\nError: %v", deviceMountPath, err) @@ -225,11 +227,11 @@ func volumeSpecToMounter(spec *volume.Spec, host volume.VolumeHost, targetLocks }, nil } -func volumeSpecToUnmounter(mounter mount.Interface, host volume.VolumeHost) *iscsiDiskUnmounter { +func volumeSpecToUnmounter(mounter mount.Interface, host volume.VolumeHost, plugin *iscsiPlugin) *iscsiDiskUnmounter { exec := host.GetExec(iscsiPluginName) return &iscsiDiskUnmounter{ iscsiDisk: &iscsiDisk{ - plugin: &iscsiPlugin{}, + plugin: plugin, }, mounter: mounter, exec: exec, From e5fbb3538f9fd987dea4aeeab17e97946fe92669 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Thu, 27 Sep 2018 10:24:59 +0200 Subject: [PATCH 2/2] Unmount iSCSI device only if it's mounted. --- pkg/volume/iscsi/iscsi_util.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/volume/iscsi/iscsi_util.go b/pkg/volume/iscsi/iscsi_util.go index dda88d03c6..d16aed1645 100644 --- a/pkg/volume/iscsi/iscsi_util.go +++ b/pkg/volume/iscsi/iscsi_util.go @@ -23,6 +23,7 @@ import ( "path" "path/filepath" "regexp" + "strconv" "strings" "time" @@ -34,7 +35,6 @@ import ( "k8s.io/kubernetes/pkg/volume" volumeutil "k8s.io/kubernetes/pkg/volume/util" "k8s.io/kubernetes/pkg/volume/util/volumepathhandler" - "strconv" ) var ( @@ -553,10 +553,18 @@ func (util *ISCSIUtil) DetachDisk(c iscsiDiskUnmounter, mntPath string) error { glog.Warningf("Warning: Unmount skipped because path does not exist: %v", mntPath) return nil } - if err := c.mounter.Unmount(mntPath); err != nil { - glog.Errorf("iscsi detach disk: failed to unmount: %s\nError: %v", mntPath, err) + + notMnt, err := c.mounter.IsLikelyNotMountPoint(mntPath) + if err != nil { return err } + if !notMnt { + if err := c.mounter.Unmount(mntPath); err != nil { + glog.Errorf("iscsi detach disk: failed to unmount: %s\nError: %v", mntPath, err) + return err + } + } + // if device is no longer used, see if need to logout the target device, prefix, err := extractDeviceAndPrefix(mntPath) if err != nil {