Add zfsDestroy & zfsGetDatasetByMountpoint functions, rename createZfsDataset to zfsCreateDataset
This commit is contained in:
parent
1b679bcd17
commit
f9f1d48023
10
cmd/fetch.go
10
cmd/fetch.go
@ -61,7 +61,7 @@ func fetchRelease(release string, proto string, arch string, datastore string, f
|
||||
}
|
||||
if false == exist {
|
||||
// Then create dataset
|
||||
if err := createZfsDataset(downloadDsName, downloadDsMountPoint, "lz4"); err != nil {
|
||||
if err := zfsCreateDataset(downloadDsName, downloadDsMountPoint, "lz4"); err != nil {
|
||||
return fmt.Errorf("Error creating dataset %s: %v\n", downloadDsName, err)
|
||||
}
|
||||
}
|
||||
@ -75,7 +75,7 @@ func fetchRelease(release string, proto string, arch string, datastore string, f
|
||||
}
|
||||
if false == exist {
|
||||
// Then create dataset
|
||||
if err := createZfsDataset(thisDownloadDsName, thisDownloadDsMountPoint, "lz4"); err != nil {
|
||||
if err := zfsCreateDataset(thisDownloadDsName, thisDownloadDsMountPoint, "lz4"); err != nil {
|
||||
return fmt.Errorf("Error creating dataset %s: %v\n", thisDownloadDsName, err)
|
||||
}
|
||||
}
|
||||
@ -147,7 +147,7 @@ func extractRelease(release string, datastore string) {
|
||||
}
|
||||
if false == exist {
|
||||
// Then create dataset
|
||||
if err := createZfsDataset(releaseDsName, releaseDsMountPoint, "lz4"); err != nil {
|
||||
if err := zfsCreateDataset(releaseDsName, releaseDsMountPoint, "lz4"); err != nil {
|
||||
fmt.Printf("Error creating dataset %s: %v\n", releaseDsName, err)
|
||||
return
|
||||
}
|
||||
@ -163,7 +163,7 @@ func extractRelease(release string, datastore string) {
|
||||
}
|
||||
if false == exist {
|
||||
// Then create dataset
|
||||
if err := createZfsDataset(thisReleaseDsName, thisReleaseDsMountPoint, "lz4"); err != nil {
|
||||
if err := zfsCreateDataset(thisReleaseDsName, thisReleaseDsMountPoint, "lz4"); err != nil {
|
||||
fmt.Printf("Error creating dataset %s: %v\n", thisReleaseDsName, err)
|
||||
return
|
||||
}
|
||||
@ -179,7 +179,7 @@ func extractRelease(release string, datastore string) {
|
||||
}
|
||||
if false == exist {
|
||||
// Then create dataset
|
||||
if err := createZfsDataset(thisReleaseRootDsName, thisReleaseRootDsMountPoint, "lz4"); err != nil {
|
||||
if err := zfsCreateDataset(thisReleaseRootDsName, thisReleaseRootDsMountPoint, "lz4"); err != nil {
|
||||
fmt.Printf("Error creating dataset %s: %v\n", thisReleaseRootDsName, err)
|
||||
return
|
||||
}
|
||||
|
22
cmd/utils.go
22
cmd/utils.go
@ -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
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user