mirror of
https://github.com/TECHNOFAB11/zfs-localpv.git
synced 2025-12-12 22:40:12 +01:00
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>
111 lines
3.3 KiB
Go
111 lines
3.3 KiB
Go
/*
|
|
Copyright 2020 The OpenEBS Authors
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package zfs
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"k8s.io/klog"
|
|
)
|
|
|
|
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 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))
|
|
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()
|
|
if err != nil {
|
|
klog.Errorf("xfs: failed to umount tmpdir %s error: %s", tmpdir, string(out))
|
|
return err
|
|
}
|
|
|
|
// 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 nil
|
|
}
|
|
|
|
/*
|
|
* We have to generate a new UUID for the cloned volumes with xfs filesystem
|
|
* otherwise system won't let anyone mount it if UUID is same. Here, since cloned
|
|
* volume refers to the same block because of the way ZFS clone works, it will
|
|
* also have the same UUID.
|
|
* There might be something there in the xfs log, we have to clear them
|
|
* so that filesystem is clean and we can generate the UUID for it.
|
|
*/
|
|
func xfsGenerateUUID(volume string) error {
|
|
device := ZFSDevPath + volume
|
|
|
|
// temporary mount the volume with nouuid to replay the logs
|
|
err := xfsTempMount(volume)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// for mounting the cloned volume for xfs, a new UUID has to be generated
|
|
cmd := exec.Command("xfs_admin", "-U", "generate", device)
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
klog.Errorf("xfs: uuid generate failed %s error: %s", volume, string(out))
|
|
return err
|
|
}
|
|
klog.Infof("xfs: generated UUID for the cloned volume %s \n %v", volume, string(out))
|
|
return nil
|
|
}
|