diff options
author | LOLi <[email protected]> | 2017-09-09 00:24:31 +0200 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2017-09-08 15:24:31 -0700 |
commit | 835db58592d7d947e5818eb7281882e2a46073e0 (patch) | |
tree | 5f99c47d3fa3ab2d18aeafb4b7be90975984f747 /lib | |
parent | 57858fb5ca4b1d0f28b054cb5e15aaf3bc54c99e (diff) |
Add -vnP support to 'zfs send' for bookmarks
This leverages the functionality introduced in cf7684b to expose
verbose, dry-run and parsable 'zfs send' options for bookmarks.
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: loli10K <[email protected]>
Closes #3666
Closes #6601
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libzfs/libzfs_sendrecv.c | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/lib/libzfs/libzfs_sendrecv.c b/lib/libzfs/libzfs_sendrecv.c index fddcd9c02..857abda3d 100644 --- a/lib/libzfs/libzfs_sendrecv.c +++ b/lib/libzfs/libzfs_sendrecv.c @@ -1242,16 +1242,14 @@ send_print_verbose(FILE *fout, const char *tosnap, const char *fromsnap, } } - if (size != 0) { - if (parsable) { - (void) fprintf(fout, "\t%llu", - (longlong_t)size); - } else { - char buf[16]; - zfs_nicebytes(size, buf, sizeof (buf)); - (void) fprintf(fout, dgettext(TEXT_DOMAIN, - " estimated size is %s"), buf); - } + if (parsable) { + (void) fprintf(fout, "\t%llu", + (longlong_t)size); + } else if (size != 0) { + char buf[16]; + zfs_nicebytes(size, buf, sizeof (buf)); + (void) fprintf(fout, dgettext(TEXT_DOMAIN, + " estimated size is %s"), buf); } (void) fprintf(fout, "\n"); } @@ -2113,17 +2111,42 @@ err_out: } int -zfs_send_one(zfs_handle_t *zhp, const char *from, int fd, - enum lzc_send_flags flags) +zfs_send_one(zfs_handle_t *zhp, const char *from, int fd, sendflags_t flags) { - int err; + int err = 0; libzfs_handle_t *hdl = zhp->zfs_hdl; - + enum lzc_send_flags lzc_flags = 0; + FILE *fout = (flags.verbose && flags.dryrun) ? stdout : stderr; char errbuf[1024]; + + if (flags.largeblock) + lzc_flags |= LZC_SEND_FLAG_LARGE_BLOCK; + if (flags.embed_data) + lzc_flags |= LZC_SEND_FLAG_EMBED_DATA; + if (flags.compress) + lzc_flags |= LZC_SEND_FLAG_COMPRESS; + if (flags.raw) + lzc_flags |= LZC_SEND_FLAG_RAW; + + if (flags.verbose) { + uint64_t size = 0; + err = lzc_send_space(zhp->zfs_name, from, lzc_flags, &size); + if (err == 0) { + send_print_verbose(fout, zhp->zfs_name, from, size, + flags.parsable); + } else { + (void) fprintf(stderr, "Cannot estimate send size: " + "%s\n", strerror(errno)); + } + } + + if (flags.dryrun) + return (err); + (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "warning: cannot send '%s'"), zhp->zfs_name); - err = lzc_send(zhp->zfs_name, from, fd, flags); + err = lzc_send(zhp->zfs_name, from, fd, lzc_flags); if (err != 0) { switch (errno) { case EXDEV: |