Merge pull request #1755 from bakins/update-zfs
Update go-zfs dependency
This commit is contained in:
commit
eaa3532918
4
Godeps/Godeps.json
generated
4
Godeps/Godeps.json
generated
@ -416,8 +416,8 @@
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/mistifyio/go-zfs",
|
||||
"Comment": "v2.1.1-5-g1b4ae6f",
|
||||
"Rev": "1b4ae6fb4e77b095934d4430860ff202060169f8"
|
||||
"Comment": "v2.1.1-31-g166dd29",
|
||||
"Rev": "166dd29edf054bff262cdaa5ffcaddb50ced9e31"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/mrunalp/fileutils",
|
||||
|
41
vendor/github.com/mistifyio/go-zfs/.travis.yml
generated
vendored
Normal file
41
vendor/github.com/mistifyio/go-zfs/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
language: go
|
||||
sudo: required
|
||||
dist: trusty
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
||||
env:
|
||||
- rel=0.6.4.2
|
||||
- rel=0.6.5.4
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- env: rel=0.6.5.4
|
||||
|
||||
go:
|
||||
- 1.7
|
||||
|
||||
before_install:
|
||||
- go get github.com/alecthomas/gometalinter
|
||||
- gometalinter --install --update
|
||||
- MAKEFLAGS=-j$(($(grep -c '^processor' /proc/cpuinfo) * 2 + 1))
|
||||
- sudo apt-get update -y && sudo apt-get install -y linux-headers-$(uname -r) uuid-dev tree
|
||||
- cd /tmp
|
||||
- curl -L https://github.com/zfsonlinux/zfs/releases/download/zfs-$rel/spl-$rel.tar.gz | tar xz
|
||||
- curl -L https://github.com/zfsonlinux/zfs/releases/download/zfs-$rel/zfs-$rel.tar.gz | tar xz
|
||||
- (cd spl-$rel && ./configure --prefix=/usr && make && sudo make install)
|
||||
- (cd zfs-$rel && ./configure --prefix=/usr && make && sudo make install)
|
||||
- sudo modprobe zfs
|
||||
- cd $TRAVIS_BUILD_DIR
|
||||
|
||||
script:
|
||||
- sudo -E $(which go) test -v ./...
|
||||
- gometalinter --disable=golint --disable=vetshadow --enable=gofmt ./... || true
|
||||
- gometalinter --disable-all --enable=golint --enable=vetshadow ./... || true
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
slack:
|
||||
secure: "AbDJNjWyf/z+neX0HtoIUynjBcdvbhrsuyzoeaImZaanUtyo3cWNpA1M+5CApDQneaKbLqcehDBTjaLQD1fjXXtWrNvq+FgCRDJ1gvZasq13iJfYe3qtLz7n0YGHqEGzZ1lsheWtle/Sg32RlPAUZrHKWPciu7/Fg1k1ca8FsB4="
|
2
vendor/github.com/mistifyio/go-zfs/README.md
generated
vendored
2
vendor/github.com/mistifyio/go-zfs/README.md
generated
vendored
@ -29,7 +29,7 @@ The tests have decent examples for most functions.
|
||||
|
||||
```go
|
||||
//assuming a zpool named test
|
||||
//error handling ommitted
|
||||
//error handling omitted
|
||||
|
||||
|
||||
f, err := zfs.CreateFilesystem("test/snapshot-test", nil)
|
||||
|
89
vendor/github.com/mistifyio/go-zfs/utils.go
generated
vendored
89
vendor/github.com/mistifyio/go-zfs/utils.go
generated
vendored
@ -2,10 +2,12 @@ package zfs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -91,34 +93,50 @@ func setUint(field *uint64, value string) error {
|
||||
}
|
||||
|
||||
func (ds *Dataset) parseLine(line []string) error {
|
||||
prop := line[1]
|
||||
val := line[2]
|
||||
|
||||
var err error
|
||||
|
||||
switch prop {
|
||||
case "available":
|
||||
err = setUint(&ds.Avail, val)
|
||||
case "compression":
|
||||
setString(&ds.Compression, val)
|
||||
case "mountpoint":
|
||||
setString(&ds.Mountpoint, val)
|
||||
case "quota":
|
||||
err = setUint(&ds.Quota, val)
|
||||
case "type":
|
||||
setString(&ds.Type, val)
|
||||
case "origin":
|
||||
setString(&ds.Origin, val)
|
||||
case "used":
|
||||
err = setUint(&ds.Used, val)
|
||||
case "volsize":
|
||||
err = setUint(&ds.Volsize, val)
|
||||
case "written":
|
||||
err = setUint(&ds.Written, val)
|
||||
case "logicalused":
|
||||
err = setUint(&ds.Logicalused, val)
|
||||
if len(line) != len(dsPropList) {
|
||||
return errors.New("Output does not match what is expected on this platform")
|
||||
}
|
||||
return err
|
||||
setString(&ds.Name, line[0])
|
||||
setString(&ds.Origin, line[1])
|
||||
|
||||
if err = setUint(&ds.Used, line[2]); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = setUint(&ds.Avail, line[3]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
setString(&ds.Mountpoint, line[4])
|
||||
setString(&ds.Compression, line[5])
|
||||
setString(&ds.Type, line[6])
|
||||
|
||||
if err = setUint(&ds.Volsize, line[7]); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = setUint(&ds.Quota, line[8]); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = setUint(&ds.Referenced, line[9]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if runtime.GOOS == "solaris" {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err = setUint(&ds.Written, line[10]); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = setUint(&ds.Logicalused, line[11]); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = setUint(&ds.Usedbydataset, line[12]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
@ -267,7 +285,8 @@ func parseInodeChanges(lines [][]string) ([]*InodeChange, error) {
|
||||
}
|
||||
|
||||
func listByType(t, filter string) ([]*Dataset, error) {
|
||||
args := []string{"get", "-rHp", "-t", t, "all"}
|
||||
args := []string{"list", "-rHp", "-t", t, "-o", dsPropListOptions}
|
||||
|
||||
if filter != "" {
|
||||
args = append(args, filter)
|
||||
}
|
||||
@ -310,6 +329,8 @@ func (z *Zpool) parseLine(line []string) error {
|
||||
var err error
|
||||
|
||||
switch prop {
|
||||
case "name":
|
||||
setString(&z.Name, val)
|
||||
case "health":
|
||||
setString(&z.Health, val)
|
||||
case "allocated":
|
||||
@ -318,6 +339,22 @@ func (z *Zpool) parseLine(line []string) error {
|
||||
err = setUint(&z.Size, val)
|
||||
case "free":
|
||||
err = setUint(&z.Free, val)
|
||||
case "fragmentation":
|
||||
// Trim trailing "%" before parsing uint
|
||||
i := strings.Index(val, "%")
|
||||
if i < 0 {
|
||||
i = len(val)
|
||||
}
|
||||
err = setUint(&z.Fragmentation, val[:i])
|
||||
case "readonly":
|
||||
z.ReadOnly = val == "on"
|
||||
case "freeing":
|
||||
err = setUint(&z.Freeing, val)
|
||||
case "leaked":
|
||||
err = setUint(&z.Leaked, val)
|
||||
case "dedupratio":
|
||||
// Trim trailing "x" before parsing float64
|
||||
z.DedupRatio, err = strconv.ParseFloat(val[:len(val)-1], 64)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
17
vendor/github.com/mistifyio/go-zfs/utils_notsolaris.go
generated
vendored
Normal file
17
vendor/github.com/mistifyio/go-zfs/utils_notsolaris.go
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// +build !solaris
|
||||
|
||||
package zfs
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// List of ZFS properties to retrieve from zfs list command on a non-Solaris platform
|
||||
var dsPropList = []string{"name", "origin", "used", "available", "mountpoint", "compression", "type", "volsize", "quota", "referenced", "written", "logicalused", "usedbydataset"}
|
||||
|
||||
var dsPropListOptions = strings.Join(dsPropList, ",")
|
||||
|
||||
// List of Zpool properties to retrieve from zpool list command on a non-Solaris platform
|
||||
var zpoolPropList = []string{"name", "health", "allocated", "size", "free", "readonly", "dedupratio", "fragmentation", "freeing", "leaked"}
|
||||
var zpoolPropListOptions = strings.Join(zpoolPropList, ",")
|
||||
var zpoolArgs = []string{"get", "-p", zpoolPropListOptions}
|
17
vendor/github.com/mistifyio/go-zfs/utils_solaris.go
generated
vendored
Normal file
17
vendor/github.com/mistifyio/go-zfs/utils_solaris.go
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// +build solaris
|
||||
|
||||
package zfs
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// List of ZFS properties to retrieve from zfs list command on a Solaris platform
|
||||
var dsPropList = []string{"name", "origin", "used", "available", "mountpoint", "compression", "type", "volsize", "quota", "referenced"}
|
||||
|
||||
var dsPropListOptions = strings.Join(dsPropList, ",")
|
||||
|
||||
// List of Zpool properties to retrieve from zpool list command on a non-Solaris platform
|
||||
var zpoolPropList = []string{"name", "health", "allocated", "size", "free", "readonly", "dedupratio"}
|
||||
var zpoolPropListOptions = strings.Join(zpoolPropList, ",")
|
||||
var zpoolArgs = []string{"get", "-p", zpoolPropListOptions}
|
70
vendor/github.com/mistifyio/go-zfs/zfs.go
generated
vendored
70
vendor/github.com/mistifyio/go-zfs/zfs.go
generated
vendored
@ -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
|
||||
@ -145,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
|
||||
}
|
||||
@ -180,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.
|
||||
@ -267,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
|
||||
}
|
||||
@ -275,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)
|
||||
@ -343,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...)
|
||||
|
19
vendor/github.com/mistifyio/go-zfs/zpool.go
generated
vendored
19
vendor/github.com/mistifyio/go-zfs/zpool.go
generated
vendored
@ -15,11 +15,16 @@ const (
|
||||
// Zpool is a ZFS zpool. A pool is a top-level structure in ZFS, and can
|
||||
// contain many descendent datasets.
|
||||
type Zpool struct {
|
||||
Name string
|
||||
Health string
|
||||
Allocated uint64
|
||||
Size uint64
|
||||
Free uint64
|
||||
Name string
|
||||
Health string
|
||||
Allocated uint64
|
||||
Size uint64
|
||||
Free uint64
|
||||
Fragmentation uint64
|
||||
ReadOnly bool
|
||||
Freeing uint64
|
||||
Leaked uint64
|
||||
DedupRatio float64
|
||||
}
|
||||
|
||||
// zpool is a helper function to wrap typical calls to zpool.
|
||||
@ -30,7 +35,9 @@ func zpool(arg ...string) ([][]string, error) {
|
||||
|
||||
// GetZpool retrieves a single ZFS zpool by name.
|
||||
func GetZpool(name string) (*Zpool, error) {
|
||||
out, err := zpool("get", "all", "-p", name)
|
||||
args := zpoolArgs
|
||||
args = append(args, name)
|
||||
out, err := zpool(args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user