From 906fd7529e3f7ea3cc1ff753b3d36115be061394 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Wed, 9 May 2018 09:52:37 +0200 Subject: [PATCH] Fix iSCSI and RBD UnmountDevice with mount containers. Google's configure-helper.sh script bind-mounts /var/lib/kubelet somewhere into /home/kubernetes and thus every mount that Kubernetes does is visible twice in /proc/mounts. iSCSI and RBD should not rely on counting on entries in /proc/mounts and unmount device when Kubernetes thinks it's unusued. Kubernetes tracks the mounts by itself and most of other volume plugins rely on it safely. --- pkg/volume/iscsi/iscsi_util.go | 11 +---------- pkg/volume/rbd/attacher.go | 18 +++++++----------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/pkg/volume/iscsi/iscsi_util.go b/pkg/volume/iscsi/iscsi_util.go index ad6382f308f..d649e351729 100644 --- a/pkg/volume/iscsi/iscsi_util.go +++ b/pkg/volume/iscsi/iscsi_util.go @@ -396,25 +396,16 @@ func globalPDPathOperation(b iscsiDiskMounter) func(iscsiDiskMounter, string, *I // DetachDisk unmounts and detaches a volume from node func (util *ISCSIUtil) DetachDisk(c iscsiDiskUnmounter, mntPath string) error { - _, cnt, err := mount.GetDeviceNameFromMount(c.mounter, mntPath) - if err != nil { - glog.Errorf("iscsi detach disk: failed to get device from mnt: %s\nError: %v", mntPath, err) - return err - } if pathExists, pathErr := volumeutil.PathExists(mntPath); pathErr != nil { return fmt.Errorf("Error checking if path exists: %v", pathErr) } else if !pathExists { glog.Warningf("Warning: Unmount skipped because path does not exist: %v", mntPath) return nil } - if err = c.mounter.Unmount(mntPath); err != nil { + if err := c.mounter.Unmount(mntPath); err != nil { glog.Errorf("iscsi detach disk: failed to unmount: %s\nError: %v", mntPath, err) return err } - cnt-- - if cnt != 0 { - return nil - } // if device is no longer used, see if need to logout the target device, prefix, err := extractDeviceAndPrefix(mntPath) if err != nil { diff --git a/pkg/volume/rbd/attacher.go b/pkg/volume/rbd/attacher.go index 2e5960092e1..9a74a608c33 100644 --- a/pkg/volume/rbd/attacher.go +++ b/pkg/volume/rbd/attacher.go @@ -189,21 +189,17 @@ func (detacher *rbdDetacher) UnmountDevice(deviceMountPath string) error { glog.Warningf("Warning: Unmount skipped because path does not exist: %v", deviceMountPath) return nil } - devicePath, cnt, err := mount.GetDeviceNameFromMount(detacher.mounter, deviceMountPath) + devicePath, _, err := mount.GetDeviceNameFromMount(detacher.mounter, deviceMountPath) if err != nil { return err } - if cnt > 1 { - return fmt.Errorf("rbd: more than 1 reference counts at %s", deviceMountPath) - } - if cnt == 1 { - // Unmount the device from the device mount point. - glog.V(4).Infof("rbd: unmouting device mountpoint %s", deviceMountPath) - if err = detacher.mounter.Unmount(deviceMountPath); err != nil { - return err - } - glog.V(3).Infof("rbd: successfully umount device mountpath %s", deviceMountPath) + // Unmount the device from the device mount point. + glog.V(4).Infof("rbd: unmouting device mountpoint %s", deviceMountPath) + if err = detacher.mounter.Unmount(deviceMountPath); err != nil { + return err } + glog.V(3).Infof("rbd: successfully umount device mountpath %s", deviceMountPath) + glog.V(4).Infof("rbd: detaching device %s", devicePath) err = detacher.manager.DetachDisk(detacher.plugin, deviceMountPath, devicePath) if err != nil {