summaryrefslogtreecommitdiff
path: root/vendor/github.com/mistifyio/go-zfs/zfs.go
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2021-03-17 14:43:10 +0100
committerGiuseppe Scrivano <gscrivan@redhat.com>2021-03-18 20:27:25 +0100
commitec1651fbf11c4d3d1c792e7f46139ebd96f7ffb2 (patch)
tree61606abbce5e8efbf0c1f0c0ff6fe1c785c8a203 /vendor/github.com/mistifyio/go-zfs/zfs.go
parent77b3a2df645f2548f7bd2da85bbdb17e4de98310 (diff)
downloadpodman-ec1651fbf11c4d3d1c792e7f46139ebd96f7ffb2.tar.gz
podman-ec1651fbf11c4d3d1c792e7f46139ebd96f7ffb2.tar.bz2
podman-ec1651fbf11c4d3d1c792e7f46139ebd96f7ffb2.zip
Bump github.com/containers/storage from 1.25.0 to 1.28.0
Bumps [github.com/containers/storage](https://github.com/containers/storage) from 1.25.0 to 1.28.0. - [Release notes](https://github.com/containers/storage/releases) - [Changelog](https://github.com/containers/storage/blob/master/docs/containers-storage-changes.md) - [Commits](https://github.com/containers/storage/compare/v1.25.0...v1.28.0) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'vendor/github.com/mistifyio/go-zfs/zfs.go')
-rw-r--r--vendor/github.com/mistifyio/go-zfs/zfs.go82
1 files changed, 76 insertions, 6 deletions
diff --git a/vendor/github.com/mistifyio/go-zfs/zfs.go b/vendor/github.com/mistifyio/go-zfs/zfs.go
index a1d740e07..4e5087ffe 100644
--- a/vendor/github.com/mistifyio/go-zfs/zfs.go
+++ b/vendor/github.com/mistifyio/go-zfs/zfs.go
@@ -32,9 +32,10 @@ type Dataset struct {
Type string
Written uint64
Volsize uint64
- Usedbydataset uint64
Logicalused uint64
+ Usedbydataset uint64
Quota uint64
+ Referenced uint64
}
// InodeType is the type of inode as reported by Diff
@@ -92,12 +93,20 @@ type Logger interface {
Log(cmd []string)
}
-var logger Logger
+type defaultLogger struct{}
+
+func (*defaultLogger) Log(cmd []string) {
+ return
+}
+
+var logger Logger = &defaultLogger{}
// SetLogger set a log handler to log all commands including arguments before
// they are executed
func SetLogger(l Logger) {
- logger = l
+ if l != nil {
+ logger = l
+ }
}
// zfs is a helper function to wrap typical calls to zfs.
@@ -137,7 +146,7 @@ func Volumes(filter string) ([]*Dataset, error) {
// GetDataset retrieves a single ZFS dataset by name. This dataset could be
// any valid ZFS dataset type, such as a clone, filesystem, snapshot, or volume.
func GetDataset(name string) (*Dataset, error) {
- out, err := zfs("get", "-Hp", "all", name)
+ out, err := zfs("list", "-Hp", "-o", dsPropListOptions, name)
if err != nil {
return nil, err
}
@@ -172,6 +181,46 @@ func (d *Dataset) Clone(dest string, properties map[string]string) (*Dataset, er
return GetDataset(dest)
}
+// Unmount unmounts currently mounted ZFS file systems.
+func (d *Dataset) Unmount(force bool) (*Dataset, error) {
+ if d.Type == DatasetSnapshot {
+ return nil, errors.New("cannot unmount snapshots")
+ }
+ args := make([]string, 1, 3)
+ args[0] = "umount"
+ if force {
+ args = append(args, "-f")
+ }
+ args = append(args, d.Name)
+ _, err := zfs(args...)
+ if err != nil {
+ return nil, err
+ }
+ return GetDataset(d.Name)
+}
+
+// Mount mounts ZFS file systems.
+func (d *Dataset) Mount(overlay bool, options []string) (*Dataset, error) {
+ if d.Type == DatasetSnapshot {
+ return nil, errors.New("cannot mount snapshots")
+ }
+ args := make([]string, 1, 5)
+ args[0] = "mount"
+ if overlay {
+ args = append(args, "-O")
+ }
+ if options != nil {
+ args = append(args, "-o")
+ args = append(args, strings.Join(options, ","))
+ }
+ args = append(args, d.Name)
+ _, err := zfs(args...)
+ if err != nil {
+ return nil, err
+ }
+ return GetDataset(d.Name)
+}
+
// ReceiveSnapshot receives a ZFS stream from the input io.Reader, creates a
// new snapshot with the specified name, and streams the input data into the
// newly-created snapshot.
@@ -259,7 +308,7 @@ func (d *Dataset) SetProperty(key, val string) error {
// A full list of available ZFS properties may be found here:
// https://www.freebsd.org/cgi/man.cgi?zfs(8).
func (d *Dataset) GetProperty(key string) (string, error) {
- out, err := zfs("get", key, d.Name)
+ out, err := zfs("get", "-H", key, d.Name)
if err != nil {
return "", err
}
@@ -267,6 +316,26 @@ func (d *Dataset) GetProperty(key string) (string, error) {
return out[0][2], nil
}
+// Rename renames a dataset.
+func (d *Dataset) Rename(name string, createParent bool, recursiveRenameSnapshots bool) (*Dataset, error) {
+ args := make([]string, 3, 5)
+ args[0] = "rename"
+ args[1] = d.Name
+ args[2] = name
+ if createParent {
+ args = append(args, "-p")
+ }
+ if recursiveRenameSnapshots {
+ args = append(args, "-r")
+ }
+ _, err := zfs(args...)
+ if err != nil {
+ return d, err
+ }
+
+ return GetDataset(name)
+}
+
// Snapshots returns a slice of all ZFS snapshots of a given dataset.
func (d *Dataset) Snapshots() ([]*Dataset, error) {
return Snapshots(d.Name)
@@ -335,13 +404,14 @@ func (d *Dataset) Rollback(destroyMoreRecent bool) error {
// A recursion depth may be specified, or a depth of 0 allows unlimited
// recursion.
func (d *Dataset) Children(depth uint64) ([]*Dataset, error) {
- args := []string{"get", "-t", "all", "-Hp", "all"}
+ args := []string{"list"}
if depth > 0 {
args = append(args, "-d")
args = append(args, strconv.FormatUint(depth, 10))
} else {
args = append(args, "-r")
}
+ args = append(args, "-t", "all", "-Hp", "-o", dsPropListOptions)
args = append(args, d.Name)
out, err := zfs(args...)