Skip to content

Commit

Permalink
fix(mount): fixing idempotency check for the mount path
Browse files Browse the repository at this point in the history
Signed-off-by: Pawan <pawan@mayadata.io>
  • Loading branch information
pawanpraka1 committed Dec 15, 2020
1 parent 0409fca commit f2eb524
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/259-pawanpraka1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fixing idempotency check for the mount path
36 changes: 20 additions & 16 deletions pkg/zfs/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 is 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,
Expand Down

0 comments on commit f2eb524

Please sign in to comment.