Add zfsDestroy & zfsGetDatasetByMountpoint functions, rename createZfsDataset to zfsCreateDataset

This commit is contained in:
yo
2023-07-09 13:40:40 +02:00
parent 1b679bcd17
commit f9f1d48023
2 changed files with 26 additions and 6 deletions

View File

@ -568,7 +568,7 @@ func doZfsDatasetExist(dataset string) (bool, error) {
}
// Create ZFS dataset. mountpoint can be "none", then the dataset won't be mounted
func createZfsDataset(dataset, mountpoint, compression string) error {
func zfsCreateDataset(dataset, mountpoint, compression string) error {
cmd := fmt.Sprintf("zfs create -o mountpoint=%s -o compression=%s %s", mountpoint, compression, dataset)
out, err := executeCommand(cmd)
if err != nil {
@ -576,6 +576,26 @@ func createZfsDataset(dataset, mountpoint, compression string) error {
}
return nil
}
// Return dataset name for a given mountpoint
func zfsGetDatasetByMountpoint(mountpoint string) (string, error) {
cmd := fmt.Sprintf("zfs list -p -r -H -o name %s", mountpoint)
out, err := executeCommand(cmd)
if err != nil {
return "", errors.New(fmt.Sprintf("%v; command returned \"%s\"", err, out))
}
return strings.TrimSuffix(out, "\n"), nil
}
// Delete a ZFS Dataset by name
func zfsDestroy(dataset string) error {
cmd := fmt.Sprintf("zfs destroy -r %s", dataset)
out, err := executeCommand(cmd)
if err != nil {
return errors.New(fmt.Sprintf("%v; command returned \"%s\"", err, out))
}
return nil
}
/*****************************************************************************
*