From ea552beb1f53f0ad472a6dc09631508f8baedfc9 Mon Sep 17 00:00:00 2001 From: Pawan Date: Wed, 15 Jul 2020 19:14:24 +0530 Subject: [PATCH] fix(xfs, uuid): fixed uuid generation issue when mount fails This issue is specific to xfs only, when we create a clone volume and system is taking time in creating the device. When we create a clone volume from a xfs filesystem, ZFS-LocalPV will go ahead and generate a new UUID for the clone volumes as we need a new UUID to mount the new clone filesystem. To generate a new UUID for the clone volume, ZFS-LocalPV first replays the xfs log by mounting the device to a tmp localtion. Here, what is happening is since device creation is slow, so we went ahead and created the tmp location to mount the clone volume but since device has not created yet, the mount failed. In the next try since the tmp location is present, it will keep failing there only at every reconciliation time. Signed-off-by: Pawan --- changelogs/unreleased/183-pawanpraka1 | 1 + pkg/zfs/xfs_util.go | 40 ++++++++++++++++++++------- 2 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 changelogs/unreleased/183-pawanpraka1 diff --git a/changelogs/unreleased/183-pawanpraka1 b/changelogs/unreleased/183-pawanpraka1 new file mode 100644 index 0000000..298eeab --- /dev/null +++ b/changelogs/unreleased/183-pawanpraka1 @@ -0,0 +1 @@ +fixed uuid generation issue when mount fails diff --git a/pkg/zfs/xfs_util.go b/pkg/zfs/xfs_util.go index 679fa08..e55fb44 100644 --- a/pkg/zfs/xfs_util.go +++ b/pkg/zfs/xfs_util.go @@ -19,6 +19,7 @@ package zfs import ( "os" "os/exec" + "path/filepath" "strings" @@ -29,35 +30,54 @@ func xfsTempMount(volume string) error { device := ZFSDevPath + volume pvol := strings.Split(volume, "/") + // evaluate the symlink to get the dev path for volume + dev, err := filepath.EvalSymlinks(device) + if err != nil { + return err + } + // create a temporary directory to mount the xfs file system tmpdir := "/tmp/" + pvol[1] - err := os.Mkdir(tmpdir, 0755) - if err != nil { + err = os.Mkdir(tmpdir, 0755) + if os.IsNotExist(err) { klog.Errorf("xfs: failed to create tmpdir %s error: %s", tmpdir, err.Error()) return err } - // mount with nouuid, so that it can play the log - cmd := exec.Command("mount", "-o", "nouuid", device, tmpdir) - out, err := cmd.CombinedOutput() + /* + * Device might have already mounted at the tmp path but umount might have failed + * in previous attempt. Checking here if device is not mounted then only attempt + * to mount it, otherwise proceed with the umount. + */ + curMounts, err := GetMounts(dev) if err != nil { - klog.Errorf("xfs: failed to mount volume %s=>%s error: %s", device, tmpdir, string(out)) + klog.Errorf("xfs: get mounts failed dev: %s err: %v", device, err.Error()) return err + } else if len(curMounts) == 0 { + // mount with nouuid, so that it can play the log + cmd := exec.Command("mount", "-o", "nouuid", device, tmpdir) + out, err := cmd.CombinedOutput() + if err != nil { + klog.Errorf("xfs: failed to mount volume %s => %s error: %s", device, tmpdir, string(out)) + return err + } + } else { + klog.Infof("xfs: device already mounted %s => [%v]", device, curMounts) } // log has been replayed, unmount the volume - cmd = exec.Command("umount", tmpdir) - out, err = cmd.CombinedOutput() + cmd := exec.Command("umount", tmpdir) + out, err := cmd.CombinedOutput() if err != nil { klog.Errorf("xfs: failed to umount tmpdir %s error: %s", tmpdir, string(out)) return err } - // remove the directory + // remove the tmp directory err = os.Remove(tmpdir) if err != nil { + // don't return error, reconciliation is not needed as umount is done klog.Errorf("xfs: failed to remove tmpdir %s error: %s", tmpdir, err.Error()) - return err } return nil }