zfs: support destroy

This commit is contained in:
Christian Schwarz 2017-07-01 18:21:18 +02:00
parent c22190e981
commit c7f140a00f
2 changed files with 41 additions and 0 deletions

View File

@ -112,3 +112,22 @@ func ZFSListFilesystemVersions(fs DatasetPath, filter FilesystemVersionFilter) (
}
return
}
func ZFSDestroyFilesystemVersion(filesystem DatasetPath, version FilesystemVersion) (err error) {
datasetPath := version.ToAbsPath(filesystem)
// Sanity check...
if strings.IndexAny(datasetPath, "@#") == -1 {
return fmt.Errorf("sanity check failed: no @ character found in dataset path: %s", datasetPath)
}
err = ZFSDestroy(datasetPath)
if err == nil {
return
}
// Check for EBUSY, special meaning to us
return
}

View File

@ -182,3 +182,25 @@ func ZFSSet(fs DatasetPath, prop, val string) (err error) {
return
}
func ZFSDestroy(dataset string) (err error) {
cmd := exec.Command(ZFS_BINARY, "destroy", dataset)
stderr := bytes.NewBuffer(make([]byte, 0, 1024))
cmd.Stderr = stderr
if err = cmd.Start(); err != nil {
return err
}
if err = cmd.Wait(); err != nil {
err = ZFSError{
Stderr: stderr.Bytes(),
WaitErr: err,
}
}
return
}