Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(xfs, uuid): fixed uuid generation issue when mount fails #183

Merged
merged 1 commit into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/unreleased/183-pawanpraka1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fixed uuid generation issue when mount fails
40 changes: 30 additions & 10 deletions pkg/zfs/xfs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package zfs
import (
"os"
"os/exec"
"path/filepath"

"strings"

Expand All @@ -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())
kmova marked this conversation as resolved.
Show resolved Hide resolved
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
}
Expand Down