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 <pawan@mayadata.io>
This commit is contained in:
Pawan 2020-07-15 19:14:24 +05:30 committed by Kiran Mova
parent e00a6b9ae2
commit ea552beb1f
2 changed files with 31 additions and 10 deletions

View file

@ -0,0 +1 @@
fixed uuid generation issue when mount fails

View file

@ -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
}
/*
* 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: 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))
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
}