mirror of
https://github.com/TECHNOFAB11/zfs-localpv.git
synced 2025-12-12 06:20:11 +01:00
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:
parent
e00a6b9ae2
commit
ea552beb1f
2 changed files with 31 additions and 10 deletions
1
changelogs/unreleased/183-pawanpraka1
Normal file
1
changelogs/unreleased/183-pawanpraka1
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
fixed uuid generation issue when mount fails
|
||||||
|
|
@ -19,6 +19,7 @@ package zfs
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
|
@ -29,35 +30,54 @@ func xfsTempMount(volume string) error {
|
||||||
device := ZFSDevPath + volume
|
device := ZFSDevPath + volume
|
||||||
pvol := strings.Split(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
|
// create a temporary directory to mount the xfs file system
|
||||||
tmpdir := "/tmp/" + pvol[1]
|
tmpdir := "/tmp/" + pvol[1]
|
||||||
err := os.Mkdir(tmpdir, 0755)
|
err = os.Mkdir(tmpdir, 0755)
|
||||||
if err != nil {
|
if os.IsNotExist(err) {
|
||||||
klog.Errorf("xfs: failed to create tmpdir %s error: %s", tmpdir, err.Error())
|
klog.Errorf("xfs: failed to create tmpdir %s error: %s", tmpdir, err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// mount with nouuid, so that it can play the log
|
/*
|
||||||
cmd := exec.Command("mount", "-o", "nouuid", device, tmpdir)
|
* Device might have already mounted at the tmp path but umount might have failed
|
||||||
out, err := cmd.CombinedOutput()
|
* 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 {
|
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
|
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
|
// log has been replayed, unmount the volume
|
||||||
cmd = exec.Command("umount", tmpdir)
|
cmd := exec.Command("umount", tmpdir)
|
||||||
out, err = cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("xfs: failed to umount tmpdir %s error: %s", tmpdir, string(out))
|
klog.Errorf("xfs: failed to umount tmpdir %s error: %s", tmpdir, string(out))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove the directory
|
// remove the tmp directory
|
||||||
err = os.Remove(tmpdir)
|
err = os.Remove(tmpdir)
|
||||||
if err != nil {
|
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())
|
klog.Errorf("xfs: failed to remove tmpdir %s error: %s", tmpdir, err.Error())
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue