diff options
author | наб <[email protected]> | 2022-04-04 15:19:12 +0200 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2022-04-05 09:46:07 -0700 |
commit | e3e4c30b0a56553af643cfa5204f4dd69e3b8529 (patch) | |
tree | a8735ee49369a142a31637760606aa8d47e5ee44 | |
parent | 1217fd1ff8fc312f2167589c0e8dff969cde7ce1 (diff) |
libzfs: sendrecv: use common progress thread killer
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes #13284
-rw-r--r-- | lib/libzfs/libzfs_sendrecv.c | 71 |
1 files changed, 23 insertions, 48 deletions
diff --git a/lib/libzfs/libzfs_sendrecv.c b/lib/libzfs/libzfs_sendrecv.c index d07c45c62..6017b0e43 100644 --- a/lib/libzfs/libzfs_sendrecv.c +++ b/lib/libzfs/libzfs_sendrecv.c @@ -961,6 +961,20 @@ send_progress_thread(void *arg) } } +static boolean_t +send_progress_thread_exit(libzfs_handle_t *hdl, pthread_t ptid) +{ + void *status = NULL; + (void) pthread_cancel(ptid); + (void) pthread_join(ptid, &status); + int error = (int)(uintptr_t)status; + if (error != 0 && status != PTHREAD_CANCELED) + return (zfs_standard_error(hdl, error, + dgettext(TEXT_DOMAIN, "progress thread exited nonzero"))); + else + return (B_FALSE); +} + static void send_print_verbose(FILE *fout, const char *tosnap, const char *fromsnap, uint64_t size, boolean_t parsable) @@ -1133,17 +1147,9 @@ dump_snapshot(zfs_handle_t *zhp, void *arg) err = dump_ioctl(zhp, sdd->prevsnap, sdd->prevsnap_obj, fromorigin, sdd->outfd, flags, sdd->debugnv); - if (sdd->progress) { - void *status = NULL; - (void) pthread_cancel(tid); - (void) pthread_join(tid, &status); - int error = (int)(uintptr_t)status; - if (error != 0 && status != PTHREAD_CANCELED) { - return (zfs_standard_error(zhp->zfs_hdl, error, - dgettext(TEXT_DOMAIN, - "progress thread exited nonzero"))); - } - } + if (sdd->progress && + send_progress_thread_exit(zhp->zfs_hdl, tid)) + return (-1); } (void) strcpy(sdd->prevsnap, thissnap); @@ -1505,20 +1511,8 @@ estimate_size(zfs_handle_t *zhp, const char *from, int fd, sendflags_t *flags, lzc_flags_from_sendflags(flags), resumeobj, resumeoff, bytes, redactbook, fd, &size); - if (flags->progress) { - void *status = NULL; - (void) pthread_cancel(ptid); - (void) pthread_join(ptid, &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)); - } - } + if (flags->progress && send_progress_thread_exit(zhp->zfs_hdl, ptid)) + return (-1); if (err != 0) { zfs_error_aux(zhp->zfs_hdl, "%s", strerror(err)); @@ -1830,19 +1824,8 @@ zfs_send_resume_impl_cb_impl(libzfs_handle_t *hdl, sendflags_t *flags, if (redact_book != NULL) free(redact_book); - if (flags->progress) { - void *status = NULL; - (void) pthread_cancel(tid); - (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(hdl, error, errbuf)); - } - } + if (flags->progress && send_progress_thread_exit(hdl, tid)) + return (-1); char errbuf[1024]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, @@ -2641,16 +2624,8 @@ zfs_send_one_cb_impl(zfs_handle_t *zhp, const char *from, int fd, err = lzc_send_redacted(name, from, fd, lzc_flags_from_sendflags(flags), redactbook); - if (flags->progress) { - void *status = NULL; - (void) pthread_cancel(ptid); - (void) pthread_join(ptid, &status); - int error = (int)(uintptr_t)status; - if (error != 0 && status != PTHREAD_CANCELED) - return (zfs_standard_error_fmt(hdl, error, - dgettext(TEXT_DOMAIN, - "progress thread exited nonzero"))); - } + if (flags->progress && send_progress_thread_exit(hdl, ptid)) + return (-1); if (err == 0 && (flags->props || flags->holds || flags->backup)) { /* Write the final end record. */ |