fix(mount): fixing idempotency check for the mount path

Signed-off-by: Pawan <pawan@mayadata.io>
This commit is contained in:
Pawan 2020-12-15 00:02:25 +05:30 committed by Kiran Mova
parent 43553d6077
commit b42893ce47
2 changed files with 21 additions and 16 deletions

View file

@ -0,0 +1 @@
fixing idempotency check for the mount path

View file

@ -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()) 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
* This check is the famous *Wall Of North* * at more than two places. The volume should
* It will not let the volume to be mounted * be unmounted before proceeding to the mount
* at more than two places. The volume should * operation.
* be unmounted before proceeding to the mount */
* operation. currentMounts, err := mnt.GetMounts(devicePath)
*/ if err != nil {
currentMounts, err := mnt.GetMounts(devicePath) klog.Errorf("can not get mounts for volume:%s dev %s err: %v",
if err != nil { vol.Name, devicePath, err.Error())
klog.Errorf("can not get mounts for volume:%s dev %s err: %v", return false, status.Errorf(codes.Internal, "verifyMount: Getmounts failed %s", err.Error())
vol.Name, devicePath, err.Error()) } else if len(currentMounts) >= 1 {
return false, status.Errorf(codes.Internal, "verifyMount: Getmounts failed %s", err.Error()) // if device is already mounted at the mount point, return successful
} else if len(currentMounts) >= 1 { for _, mp := range currentMounts {
if currentMounts[0] == mountpath { if mp == mountpath {
return true, nil 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( klog.Errorf(
"can not mount, volume:%s already mounted dev %s mounts: %v", "can not mount, volume:%s already mounted dev %s mounts: %v",
vol.Name, devicePath, currentMounts, vol.Name, devicePath, currentMounts,