From 1970dc30a0f2a69e7e0f978b686334253c7e0930 Mon Sep 17 00:00:00 2001 From: Ryan Moeller Date: Wed, 18 Aug 2021 17:04:46 +0000 Subject: [PATCH] libzfs_sendrecv: Style pass on dump_snapshot * Add a high level comment. * Avoid unnecessary line wrapping. * Simplify size accounting logic. * Eliminate unnecessary buffer on the stack. Reviewed-by: Brian Behlendorf Signed-off-by: Ryan Moeller Closes #12967 --- lib/libzfs/libzfs_sendrecv.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/libzfs/libzfs_sendrecv.c b/lib/libzfs/libzfs_sendrecv.c index d3b2b56ad2ba..7d4cd1475253 100644 --- a/lib/libzfs/libzfs_sendrecv.c +++ b/lib/libzfs/libzfs_sendrecv.c @@ -995,6 +995,10 @@ send_print_verbose(FILE *fout, const char *tosnap, const char *fromsnap, (void) fprintf(fout, "\n"); } +/* + * Send a single filesystem snapshot, updating the send dump data. + * This interface is intended for use as a zfs_iter_snapshots_sorted visitor. + */ static int dump_snapshot(zfs_handle_t *zhp, void *arg) { @@ -1016,8 +1020,7 @@ dump_snapshot(zfs_handle_t *zhp, void *arg) if (!sdd->seenfrom && isfromsnap) { gather_holds(zhp, sdd); sdd->seenfrom = B_TRUE; - (void) strlcpy(sdd->prevsnap, thissnap, - sizeof (sdd->prevsnap)); + (void) strlcpy(sdd->prevsnap, thissnap, sizeof (sdd->prevsnap)); sdd->prevsnap_obj = zfs_prop_get_int(zhp, ZFS_PROP_OBJSETID); zfs_close(zhp); return (0); @@ -1097,14 +1100,12 @@ dump_snapshot(zfs_handle_t *zhp, void *arg) (void) strlcat(fromds, sdd->prevsnap, sizeof (fromds)); } if (zfs_send_space(zhp, zhp->zfs_name, - sdd->prevsnap[0] ? fromds : NULL, flags, &size) != 0) { - size = 0; /* cannot estimate send space */ - } else { + sdd->prevsnap[0] ? fromds : NULL, flags, &size) == 0) { send_print_verbose(fout, zhp->zfs_name, sdd->prevsnap[0] ? sdd->prevsnap : NULL, size, sdd->parsable); + sdd->size += size; } - sdd->size += size; } if (!sdd->dryrun) { @@ -1135,12 +1136,9 @@ dump_snapshot(zfs_handle_t *zhp, void *arg) (void) pthread_join(tid, &status); int error = (int)(uintptr_t)status; if (error != 0 && status != PTHREAD_CANCELED) { - char errbuf[1024]; - (void) snprintf(errbuf, sizeof (errbuf), - dgettext(TEXT_DOMAIN, - "progress thread exited nonzero")); return (zfs_standard_error(zhp->zfs_hdl, error, - errbuf)); + dgettext(TEXT_DOMAIN, + "progress thread exited nonzero"))); } } }