Switch to github.com/golang/dep for vendoring
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
d6ab91be27
commit
8e5b17cf13
15431 changed files with 3971413 additions and 8881 deletions
41
vendor/github.com/mistifyio/go-zfs/.travis.yml
generated
vendored
41
vendor/github.com/mistifyio/go-zfs/.travis.yml
generated
vendored
|
@ -1,41 +0,0 @@
|
|||
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="
|
37
vendor/github.com/mistifyio/go-zfs/error_test.go
generated
vendored
Normal file
37
vendor/github.com/mistifyio/go-zfs/error_test.go
generated
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
package zfs
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestError(t *testing.T) {
|
||||
var tests = []struct {
|
||||
err error
|
||||
debug string
|
||||
stderr string
|
||||
}{
|
||||
// Empty error
|
||||
{nil, "", ""},
|
||||
// Typical error
|
||||
{errors.New("exit status foo"), "/sbin/foo bar qux", "command not found"},
|
||||
// Quoted error
|
||||
{errors.New("exit status quoted"), "\"/sbin/foo\" bar qux", "\"some\" 'random' `quotes`"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
// Generate error from tests
|
||||
zErr := Error{
|
||||
Err: test.err,
|
||||
Debug: test.debug,
|
||||
Stderr: test.stderr,
|
||||
}
|
||||
|
||||
// Verify output format is consistent, so that any changes to the
|
||||
// Error method must be reflected by the test
|
||||
if str := zErr.Error(); str != fmt.Sprintf("%s: %q => %s", test.err, test.debug, test.stderr) {
|
||||
t.Fatalf("unexpected Error string: %v", str)
|
||||
}
|
||||
}
|
||||
}
|
94
vendor/github.com/mistifyio/go-zfs/utils.go
generated
vendored
94
vendor/github.com/mistifyio/go-zfs/utils.go
generated
vendored
|
@ -2,16 +2,12 @@ package zfs
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pborman/uuid"
|
||||
)
|
||||
|
||||
type command struct {
|
||||
|
@ -38,17 +34,16 @@ func (c *command) Run(arg ...string) ([][]string, error) {
|
|||
}
|
||||
cmd.Stderr = &stderr
|
||||
|
||||
id := uuid.New()
|
||||
joinedArgs := strings.Join(cmd.Args, " ")
|
||||
|
||||
logger.Log([]string{"ID:" + id, "START", joinedArgs})
|
||||
debug := strings.Join([]string{cmd.Path, strings.Join(cmd.Args, " ")}, " ")
|
||||
if logger != nil {
|
||||
logger.Log(cmd.Args)
|
||||
}
|
||||
err := cmd.Run()
|
||||
logger.Log([]string{"ID:" + id, "FINISH"})
|
||||
|
||||
if err != nil {
|
||||
return nil, &Error{
|
||||
Err: err,
|
||||
Debug: strings.Join([]string{cmd.Path, joinedArgs}, " "),
|
||||
Debug: debug,
|
||||
Stderr: stderr.String(),
|
||||
}
|
||||
}
|
||||
|
@ -93,46 +88,34 @@ func setUint(field *uint64, value string) error {
|
|||
}
|
||||
|
||||
func (ds *Dataset) parseLine(line []string) error {
|
||||
prop := line[1]
|
||||
val := line[2]
|
||||
|
||||
var err error
|
||||
|
||||
if len(line) != len(dsPropList) {
|
||||
return errors.New("Output does not match what is expected on this platform")
|
||||
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)
|
||||
}
|
||||
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 runtime.GOOS == "solaris" {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err = setUint(&ds.Written, line[9]); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = setUint(&ds.Logicalused, line[10]); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = setUint(&ds.Usedbydataset, line[11]); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -281,8 +264,7 @@ func parseInodeChanges(lines [][]string) ([]*InodeChange, error) {
|
|||
}
|
||||
|
||||
func listByType(t, filter string) ([]*Dataset, error) {
|
||||
args := []string{"list", "-rHp", "-t", t, "-o", dsPropListOptions}
|
||||
|
||||
args := []string{"get", "-rHp", "-t", t, "all"}
|
||||
if filter != "" {
|
||||
args = append(args, filter)
|
||||
}
|
||||
|
@ -325,8 +307,6 @@ 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":
|
||||
|
@ -335,18 +315,6 @@ 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
|
||||
err = setUint(&z.Fragmentation, val[:len(val)-1])
|
||||
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
17
vendor/github.com/mistifyio/go-zfs/utils_notsolaris.go
generated
vendored
|
@ -1,17 +0,0 @@
|
|||
// +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", "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
17
vendor/github.com/mistifyio/go-zfs/utils_solaris.go
generated
vendored
|
@ -1,17 +0,0 @@
|
|||
// +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"}
|
||||
|
||||
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}
|
81
vendor/github.com/mistifyio/go-zfs/zfs.go
generated
vendored
81
vendor/github.com/mistifyio/go-zfs/zfs.go
generated
vendored
|
@ -32,8 +32,8 @@ type Dataset struct {
|
|||
Type string
|
||||
Written uint64
|
||||
Volsize uint64
|
||||
Logicalused uint64
|
||||
Usedbydataset uint64
|
||||
Logicalused uint64
|
||||
Quota uint64
|
||||
}
|
||||
|
||||
|
@ -92,20 +92,12 @@ type Logger interface {
|
|||
Log(cmd []string)
|
||||
}
|
||||
|
||||
type defaultLogger struct{}
|
||||
|
||||
func (*defaultLogger) Log(cmd []string) {
|
||||
return
|
||||
}
|
||||
|
||||
var logger Logger = &defaultLogger{}
|
||||
var logger Logger
|
||||
|
||||
// SetLogger set a log handler to log all commands including arguments before
|
||||
// they are executed
|
||||
func SetLogger(l Logger) {
|
||||
if l != nil {
|
||||
logger = l
|
||||
}
|
||||
logger = l
|
||||
}
|
||||
|
||||
// zfs is a helper function to wrap typical calls to zfs.
|
||||
|
@ -145,7 +137,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("list", "-Hp", "-o", dsPropListOptions, name)
|
||||
out, err := zfs("get", "-Hp", "all", name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -180,46 +172,6 @@ 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.
|
||||
|
@ -307,7 +259,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", "-H", key, d.Name)
|
||||
out, err := zfs("get", key, d.Name)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -315,26 +267,6 @@ 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)
|
||||
|
@ -403,14 +335,13 @@ 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{"list"}
|
||||
args := []string{"get", "-t", "all", "-Hp", "all"}
|
||||
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...)
|
||||
|
|
359
vendor/github.com/mistifyio/go-zfs/zfs_test.go
generated
vendored
Normal file
359
vendor/github.com/mistifyio/go-zfs/zfs_test.go
generated
vendored
Normal file
|
@ -0,0 +1,359 @@
|
|||
package zfs_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/mistifyio/go-zfs"
|
||||
)
|
||||
|
||||
func sleep(delay int) {
|
||||
time.Sleep(time.Duration(delay) * time.Second)
|
||||
}
|
||||
|
||||
func pow2(x int) int64 {
|
||||
return int64(math.Pow(2, float64(x)))
|
||||
}
|
||||
|
||||
//https://github.com/benbjohnson/testing
|
||||
// assert fails the test if the condition is false.
|
||||
func assert(tb testing.TB, condition bool, msg string, v ...interface{}) {
|
||||
if !condition {
|
||||
_, file, line, _ := runtime.Caller(1)
|
||||
fmt.Printf("\033[31m%s:%d: "+msg+"\033[39m\n\n", append([]interface{}{filepath.Base(file), line}, v...)...)
|
||||
tb.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
// ok fails the test if an err is not nil.
|
||||
func ok(tb testing.TB, err error) {
|
||||
if err != nil {
|
||||
_, file, line, _ := runtime.Caller(1)
|
||||
fmt.Printf("\033[31m%s:%d: unexpected error: %s\033[39m\n\n", filepath.Base(file), line, err.Error())
|
||||
tb.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
// equals fails the test if exp is not equal to act.
|
||||
func equals(tb testing.TB, exp, act interface{}) {
|
||||
if !reflect.DeepEqual(exp, act) {
|
||||
_, file, line, _ := runtime.Caller(1)
|
||||
fmt.Printf("\033[31m%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", filepath.Base(file), line, exp, act)
|
||||
tb.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func zpoolTest(t *testing.T, fn func()) {
|
||||
tempfiles := make([]string, 3)
|
||||
for i := range tempfiles {
|
||||
f, _ := ioutil.TempFile("/tmp/", "zfs-")
|
||||
defer f.Close()
|
||||
err := f.Truncate(pow2(30))
|
||||
ok(t, err)
|
||||
tempfiles[i] = f.Name()
|
||||
defer os.Remove(f.Name())
|
||||
}
|
||||
|
||||
pool, err := zfs.CreateZpool("test", nil, tempfiles...)
|
||||
ok(t, err)
|
||||
defer pool.Destroy()
|
||||
ok(t, err)
|
||||
fn()
|
||||
|
||||
}
|
||||
|
||||
func TestDatasets(t *testing.T) {
|
||||
zpoolTest(t, func() {
|
||||
_, err := zfs.Datasets("")
|
||||
ok(t, err)
|
||||
|
||||
ds, err := zfs.GetDataset("test")
|
||||
ok(t, err)
|
||||
equals(t, zfs.DatasetFilesystem, ds.Type)
|
||||
equals(t, "", ds.Origin)
|
||||
assert(t, ds.Logicalused > 0, "Logicalused is not greater than 0")
|
||||
})
|
||||
}
|
||||
|
||||
func TestSnapshots(t *testing.T) {
|
||||
|
||||
zpoolTest(t, func() {
|
||||
snapshots, err := zfs.Snapshots("")
|
||||
ok(t, err)
|
||||
|
||||
for _, snapshot := range snapshots {
|
||||
equals(t, zfs.DatasetSnapshot, snapshot.Type)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestFilesystems(t *testing.T) {
|
||||
zpoolTest(t, func() {
|
||||
f, err := zfs.CreateFilesystem("test/filesystem-test", nil)
|
||||
ok(t, err)
|
||||
|
||||
filesystems, err := zfs.Filesystems("")
|
||||
ok(t, err)
|
||||
|
||||
for _, filesystem := range filesystems {
|
||||
equals(t, zfs.DatasetFilesystem, filesystem.Type)
|
||||
}
|
||||
|
||||
ok(t, f.Destroy(zfs.DestroyDefault))
|
||||
})
|
||||
}
|
||||
|
||||
func TestCreateFilesystemWithProperties(t *testing.T) {
|
||||
zpoolTest(t, func() {
|
||||
props := map[string]string{
|
||||
"compression": "lz4",
|
||||
}
|
||||
|
||||
f, err := zfs.CreateFilesystem("test/filesystem-test", props)
|
||||
ok(t, err)
|
||||
|
||||
equals(t, "lz4", f.Compression)
|
||||
|
||||
filesystems, err := zfs.Filesystems("")
|
||||
ok(t, err)
|
||||
|
||||
for _, filesystem := range filesystems {
|
||||
equals(t, zfs.DatasetFilesystem, filesystem.Type)
|
||||
}
|
||||
|
||||
ok(t, f.Destroy(zfs.DestroyDefault))
|
||||
})
|
||||
}
|
||||
|
||||
func TestVolumes(t *testing.T) {
|
||||
zpoolTest(t, func() {
|
||||
v, err := zfs.CreateVolume("test/volume-test", uint64(pow2(23)), nil)
|
||||
ok(t, err)
|
||||
|
||||
// volumes are sometimes "busy" if you try to manipulate them right away
|
||||
sleep(1)
|
||||
|
||||
equals(t, zfs.DatasetVolume, v.Type)
|
||||
volumes, err := zfs.Volumes("")
|
||||
ok(t, err)
|
||||
|
||||
for _, volume := range volumes {
|
||||
equals(t, zfs.DatasetVolume, volume.Type)
|
||||
}
|
||||
|
||||
ok(t, v.Destroy(zfs.DestroyDefault))
|
||||
})
|
||||
}
|
||||
|
||||
func TestSnapshot(t *testing.T) {
|
||||
zpoolTest(t, func() {
|
||||
f, err := zfs.CreateFilesystem("test/snapshot-test", nil)
|
||||
ok(t, err)
|
||||
|
||||
filesystems, err := zfs.Filesystems("")
|
||||
ok(t, err)
|
||||
|
||||
for _, filesystem := range filesystems {
|
||||
equals(t, zfs.DatasetFilesystem, filesystem.Type)
|
||||
}
|
||||
|
||||
s, err := f.Snapshot("test", false)
|
||||
ok(t, err)
|
||||
|
||||
equals(t, zfs.DatasetSnapshot, s.Type)
|
||||
|
||||
equals(t, "test/snapshot-test@test", s.Name)
|
||||
|
||||
ok(t, s.Destroy(zfs.DestroyDefault))
|
||||
|
||||
ok(t, f.Destroy(zfs.DestroyDefault))
|
||||
})
|
||||
}
|
||||
|
||||
func TestClone(t *testing.T) {
|
||||
zpoolTest(t, func() {
|
||||
f, err := zfs.CreateFilesystem("test/snapshot-test", nil)
|
||||
ok(t, err)
|
||||
|
||||
filesystems, err := zfs.Filesystems("")
|
||||
ok(t, err)
|
||||
|
||||
for _, filesystem := range filesystems {
|
||||
equals(t, zfs.DatasetFilesystem, filesystem.Type)
|
||||
}
|
||||
|
||||
s, err := f.Snapshot("test", false)
|
||||
ok(t, err)
|
||||
|
||||
equals(t, zfs.DatasetSnapshot, s.Type)
|
||||
equals(t, "test/snapshot-test@test", s.Name)
|
||||
|
||||
c, err := s.Clone("test/clone-test", nil)
|
||||
ok(t, err)
|
||||
|
||||
equals(t, zfs.DatasetFilesystem, c.Type)
|
||||
|
||||
ok(t, c.Destroy(zfs.DestroyDefault))
|
||||
|
||||
ok(t, s.Destroy(zfs.DestroyDefault))
|
||||
|
||||
ok(t, f.Destroy(zfs.DestroyDefault))
|
||||
})
|
||||
}
|
||||
|
||||
func TestSendSnapshot(t *testing.T) {
|
||||
zpoolTest(t, func() {
|
||||
f, err := zfs.CreateFilesystem("test/snapshot-test", nil)
|
||||
ok(t, err)
|
||||
|
||||
filesystems, err := zfs.Filesystems("")
|
||||
ok(t, err)
|
||||
|
||||
for _, filesystem := range filesystems {
|
||||
equals(t, zfs.DatasetFilesystem, filesystem.Type)
|
||||
}
|
||||
|
||||
s, err := f.Snapshot("test", false)
|
||||
ok(t, err)
|
||||
|
||||
file, _ := ioutil.TempFile("/tmp/", "zfs-")
|
||||
defer file.Close()
|
||||
err = file.Truncate(pow2(30))
|
||||
ok(t, err)
|
||||
defer os.Remove(file.Name())
|
||||
|
||||
err = s.SendSnapshot(file)
|
||||
ok(t, err)
|
||||
|
||||
ok(t, s.Destroy(zfs.DestroyDefault))
|
||||
|
||||
ok(t, f.Destroy(zfs.DestroyDefault))
|
||||
})
|
||||
}
|
||||
|
||||
func TestChildren(t *testing.T) {
|
||||
zpoolTest(t, func() {
|
||||
f, err := zfs.CreateFilesystem("test/snapshot-test", nil)
|
||||
ok(t, err)
|
||||
|
||||
s, err := f.Snapshot("test", false)
|
||||
ok(t, err)
|
||||
|
||||
equals(t, zfs.DatasetSnapshot, s.Type)
|
||||
equals(t, "test/snapshot-test@test", s.Name)
|
||||
|
||||
children, err := f.Children(0)
|
||||
ok(t, err)
|
||||
|
||||
equals(t, 1, len(children))
|
||||
equals(t, "test/snapshot-test@test", children[0].Name)
|
||||
|
||||
ok(t, s.Destroy(zfs.DestroyDefault))
|
||||
ok(t, f.Destroy(zfs.DestroyDefault))
|
||||
})
|
||||
}
|
||||
|
||||
func TestListZpool(t *testing.T) {
|
||||
zpoolTest(t, func() {
|
||||
pools, err := zfs.ListZpools()
|
||||
ok(t, err)
|
||||
equals(t, "test", pools[0].Name)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestRollback(t *testing.T) {
|
||||
zpoolTest(t, func() {
|
||||
f, err := zfs.CreateFilesystem("test/snapshot-test", nil)
|
||||
ok(t, err)
|
||||
|
||||
filesystems, err := zfs.Filesystems("")
|
||||
ok(t, err)
|
||||
|
||||
for _, filesystem := range filesystems {
|
||||
equals(t, zfs.DatasetFilesystem, filesystem.Type)
|
||||
}
|
||||
|
||||
s1, err := f.Snapshot("test", false)
|
||||
ok(t, err)
|
||||
|
||||
_, err = f.Snapshot("test2", false)
|
||||
ok(t, err)
|
||||
|
||||
s3, err := f.Snapshot("test3", false)
|
||||
ok(t, err)
|
||||
|
||||
err = s3.Rollback(false)
|
||||
ok(t, err)
|
||||
|
||||
err = s1.Rollback(false)
|
||||
assert(t, err != nil, "should error when rolling back beyond most recent without destroyMoreRecent = true")
|
||||
|
||||
err = s1.Rollback(true)
|
||||
ok(t, err)
|
||||
|
||||
ok(t, s1.Destroy(zfs.DestroyDefault))
|
||||
|
||||
ok(t, f.Destroy(zfs.DestroyDefault))
|
||||
})
|
||||
}
|
||||
|
||||
func TestDiff(t *testing.T) {
|
||||
zpoolTest(t, func() {
|
||||
fs, err := zfs.CreateFilesystem("test/origin", nil)
|
||||
ok(t, err)
|
||||
|
||||
linkedFile, err := os.Create(filepath.Join(fs.Mountpoint, "linked"))
|
||||
ok(t, err)
|
||||
|
||||
movedFile, err := os.Create(filepath.Join(fs.Mountpoint, "file"))
|
||||
ok(t, err)
|
||||
|
||||
snapshot, err := fs.Snapshot("snapshot", false)
|
||||
ok(t, err)
|
||||
|
||||
unicodeFile, err := os.Create(filepath.Join(fs.Mountpoint, "i ❤ unicode"))
|
||||
ok(t, err)
|
||||
|
||||
err = os.Rename(movedFile.Name(), movedFile.Name()+"-new")
|
||||
ok(t, err)
|
||||
|
||||
err = os.Link(linkedFile.Name(), linkedFile.Name()+"_hard")
|
||||
ok(t, err)
|
||||
|
||||
inodeChanges, err := fs.Diff(snapshot.Name)
|
||||
ok(t, err)
|
||||
equals(t, 4, len(inodeChanges))
|
||||
|
||||
equals(t, "/test/origin/", inodeChanges[0].Path)
|
||||
equals(t, zfs.Directory, inodeChanges[0].Type)
|
||||
equals(t, zfs.Modified, inodeChanges[0].Change)
|
||||
|
||||
equals(t, "/test/origin/linked", inodeChanges[1].Path)
|
||||
equals(t, zfs.File, inodeChanges[1].Type)
|
||||
equals(t, zfs.Modified, inodeChanges[1].Change)
|
||||
equals(t, 1, inodeChanges[1].ReferenceCountChange)
|
||||
|
||||
equals(t, "/test/origin/file", inodeChanges[2].Path)
|
||||
equals(t, "/test/origin/file-new", inodeChanges[2].NewPath)
|
||||
equals(t, zfs.File, inodeChanges[2].Type)
|
||||
equals(t, zfs.Renamed, inodeChanges[2].Change)
|
||||
|
||||
equals(t, "/test/origin/i ❤ unicode", inodeChanges[3].Path)
|
||||
equals(t, zfs.File, inodeChanges[3].Type)
|
||||
equals(t, zfs.Created, inodeChanges[3].Change)
|
||||
|
||||
ok(t, movedFile.Close())
|
||||
ok(t, unicodeFile.Close())
|
||||
ok(t, linkedFile.Close())
|
||||
ok(t, snapshot.Destroy(zfs.DestroyForceUmount))
|
||||
ok(t, fs.Destroy(zfs.DestroyForceUmount))
|
||||
})
|
||||
}
|
19
vendor/github.com/mistifyio/go-zfs/zpool.go
generated
vendored
19
vendor/github.com/mistifyio/go-zfs/zpool.go
generated
vendored
|
@ -15,16 +15,11 @@ 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
|
||||
Fragmentation uint64
|
||||
ReadOnly bool
|
||||
Freeing uint64
|
||||
Leaked uint64
|
||||
DedupRatio float64
|
||||
Name string
|
||||
Health string
|
||||
Allocated uint64
|
||||
Size uint64
|
||||
Free uint64
|
||||
}
|
||||
|
||||
// zpool is a helper function to wrap typical calls to zpool.
|
||||
|
@ -35,9 +30,7 @@ func zpool(arg ...string) ([][]string, error) {
|
|||
|
||||
// GetZpool retrieves a single ZFS zpool by name.
|
||||
func GetZpool(name string) (*Zpool, error) {
|
||||
args := zpoolArgs
|
||||
args = append(args, name)
|
||||
out, err := zpool(args...)
|
||||
out, err := zpool("get", "all", "-p", name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue