Skip to content

Commit

Permalink
- Option to resume interrupted send
Browse files Browse the repository at this point in the history
  • Loading branch information
Asmir Selimovic authored and Faruk Kasumovic committed Dec 20, 2019
1 parent a21bc23 commit 9901e4a
Showing 1 changed file with 52 additions and 18 deletions.
70 changes: 52 additions & 18 deletions sendrecv.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,30 @@ import (
)

type SendFlags struct {
Verbose bool
Replicate bool
DoAll bool
FromOrigin bool
Dedup bool
Props bool
DryRun bool
Parsable bool
Verbose bool // -v
Replicate bool // -R
DoAll bool // -I
FromOrigin bool // -o
Dedup bool // -D
Props bool // -p
DryRun bool // -n
Parsable bool // -P
LargeBlock bool // -L
EmbedData bool // -e
Compress bool // -c
Progress bool
LargeBlock bool
EmbedData bool
Compress bool
}

type RecvFlags struct {
Verbose bool
IsPrefix bool
IsTail bool
DryRun bool
Force bool
Verbose bool // -v
IsPrefix bool // -d
IsTail bool // -e
DryRun bool // -n
Force bool // -r
Resumable bool // -s
NoMount bool // -u
CanmountOff bool
Resumable bool
ByteSwap bool
NoMount bool
}

func to_boolean_t(a bool) C.boolean_t {
Expand Down Expand Up @@ -170,6 +170,40 @@ func (d *Dataset) SendOne(FromName string, outf *os.File, flags *SendFlags) (err
return
}

func (d *Dataset) SendResume(outf *os.File, flags *SendFlags, receiveResumeToken string) (err error) {
if d.Type != DatasetTypeSnapshot {
err = fmt.Errorf("Unsupported method on filesystem or bookmark. Use func SendOne() for that purpose.")
return
}

var dpath string
var pd Dataset

cflags := to_sendflags_t(flags)
defer C.free(unsafe.Pointer(cflags))
if dpath, err = d.Path(); err != nil {
return
}
sendparams := strings.Split(dpath, "@")
parent := sendparams[0]

if pd, err = DatasetOpen(parent); err != nil {
return
}
defer pd.Close()

cReceiveResumeToken := C.CString(receiveResumeToken)
defer C.free(unsafe.Pointer(cReceiveResumeToken))

clerr := C.zfs_send_resume(C.libzfsHandle, cflags, C.int(outf.Fd()), cReceiveResumeToken)
if clerr != 0 {
err = LastError()
fmt.Println(err.Error())
}

return
}

func (d *Dataset) Send(outf *os.File, flags SendFlags) (err error) {
if flags.Replicate {
flags.DoAll = true
Expand Down

0 comments on commit 9901e4a

Please sign in to comment.