From b42893ce470b15ab1d70da558f838e97837bb21e Mon Sep 17 00:00:00 2001 From: Pawan Date: Tue, 15 Dec 2020 00:02:25 +0530 Subject: [PATCH] fix(mount): fixing idempotency check for the mount path Signed-off-by: Pawan --- changelogs/unreleased/260-pawanpraka1 | 1 + pkg/zfs/mount.go | 36 +++++++++++++++------------ 2 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 changelogs/unreleased/260-pawanpraka1 diff --git a/changelogs/unreleased/260-pawanpraka1 b/changelogs/unreleased/260-pawanpraka1 new file mode 100644 index 0000000..e089e9e --- /dev/null +++ b/changelogs/unreleased/260-pawanpraka1 @@ -0,0 +1 @@ +fixing idempotency check for the mount path diff --git a/pkg/zfs/mount.go b/pkg/zfs/mount.go index 9662e57..a98709d 100644 --- a/pkg/zfs/mount.go +++ b/pkg/zfs/mount.go @@ -144,24 +144,28 @@ func verifyMountRequest(vol *apis.ZFSVolume, mountpath string) (bool, error) { return false, status.Errorf(codes.Internal, "verifyMount: GetVolumePath failed %s", err.Error()) } - // if it is not a shared volume, then make sure it is not mounted to more than one path - if vol.Spec.Shared != "yes" { - /* - * This check is the famous *Wall Of North* - * It will not let the volume to be mounted - * at more than two places. The volume should - * be unmounted before proceeding to the mount - * operation. - */ - currentMounts, err := mnt.GetMounts(devicePath) - if err != nil { - klog.Errorf("can not get mounts for volume:%s dev %s err: %v", - vol.Name, devicePath, err.Error()) - return false, status.Errorf(codes.Internal, "verifyMount: Getmounts failed %s", err.Error()) - } else if len(currentMounts) >= 1 { - if currentMounts[0] == mountpath { + /* + * This check is the famous *Wall Of North* + * It will not let the volume to be mounted + * at more than two places. The volume should + * be unmounted before proceeding to the mount + * operation. + */ + currentMounts, err := mnt.GetMounts(devicePath) + if err != nil { + klog.Errorf("can not get mounts for volume:%s dev %s err: %v", + vol.Name, devicePath, err.Error()) + return false, status.Errorf(codes.Internal, "verifyMount: Getmounts failed %s", err.Error()) + } else if len(currentMounts) >= 1 { + // if device is already mounted at the mount point, return successful + for _, mp := range currentMounts { + if mp == mountpath { return true, nil } + } + + // if it is not a shared volume, then it should not mounted to more than one path + if vol.Spec.Shared != "yes" { klog.Errorf( "can not mount, volume:%s already mounted dev %s mounts: %v", vol.Name, devicePath, currentMounts,