func rename(name, newName string, recursive bool) (string, error) { m := map[string]interface{}{ "cmd": "zfs_rename", "version": uint64(0), "innvl": map[string]interface{}{ "newname": newName, "recursive": recursive, }, } encoded := &bytes.Buffer{} err := nv.NewNativeEncoder(encoded).Encode(m) if err != nil { return "", err } out := make([]byte, 1024) err = ioctl(zfs, name, encoded.Bytes(), out) var failedName string if err != nil && recursive { _ = nv.NewNativeDecoder(bytes.NewReader(out)).Decode(&failedName) } return failedName, err }
func holds(name string) ([]string, error) { m := map[string]interface{}{ "cmd": "zfs_get_holds", "version": uint64(0), } encoded := &bytes.Buffer{} err := nv.NewNativeEncoder(encoded).Encode(m) if err != nil { return nil, err } out := make([]byte, 1024) copy(out, emptyList) err = ioctl(zfs, name, encoded.Bytes(), out) if err != nil { return nil, err } m = map[string]interface{}{} if err = nv.NewNativeDecoder(bytes.NewReader(out)).Decode(&m); err != nil { return nil, err } names := make([]string, 0, len(m)) for name := range m { names = append(names, name) } return names, nil }
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 }
func rollback(name string) (string, error) { m := map[string]interface{}{ "cmd": "zfs_rollback", "version": uint64(0), } encoded := &bytes.Buffer{} err := nv.NewNativeEncoder(encoded).Encode(m) if err != nil { return "", err } out := make([]byte, 1024) err = ioctl(zfs, name, encoded.Bytes(), out) var snapName string if err == nil { var results map[string]string if err = nv.NewNativeDecoder(bytes.NewReader(out)).Decode(&results); err == nil { snapName = results["target"] } } return snapName, err }