-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnapshot.go
47 lines (40 loc) · 1.13 KB
/
snapshot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package gozfs
import (
"bytes"
"syscall"
"github.com/mistifyio/gozfs/nv"
)
func snapshot(pool string, snapNames []string, props map[string]string) (map[string]syscall.Errno, error) {
// snaps needs to be a map with the snap name as the key and an arbitrary value
snaps := make(map[string]string)
for _, snapName := range snapNames {
snaps[snapName] = ""
}
m := map[string]interface{}{
"cmd": "zfs_snapshot",
"version": uint64(0),
"innvl": map[string]interface{}{
"snaps": snaps,
"props": props,
},
}
encoded := &bytes.Buffer{}
err := nv.NewNativeEncoder(encoded).Encode(m)
if err != nil {
return nil, err
}
out := make([]byte, 1024)
err = ioctl(zfs, pool, encoded.Bytes(), out)
var errlist map[string]syscall.Errno
if errno, ok := err.(syscall.Errno); ok && errno == syscall.EEXIST {
// Try to get errlist info, but ignore any errors in the attempt
errs := map[string]int32{}
if nv.NewNativeDecoder(bytes.NewReader(out)).Decode(&errs) == nil {
errlist = make(map[string]syscall.Errno, len(errs))
for snap, errno := range errs {
errlist[snap] = syscall.Errno(errno)
}
}
}
return errlist, err
}