Skip to content

Commit cb271c7

Browse files
nabijaczleweliandrewc12
authored andcommitted
libzfs: sendrecv: use common progress thread killer
Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes openzfs#13284
1 parent a468166 commit cb271c7

File tree

1 file changed

+23
-48
lines changed

1 file changed

+23
-48
lines changed

lib/libzfs/libzfs_sendrecv.c

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,20 @@ send_progress_thread(void *arg)
961961
}
962962
}
963963

964+
static boolean_t
965+
send_progress_thread_exit(libzfs_handle_t *hdl, pthread_t ptid)
966+
{
967+
void *status = NULL;
968+
(void) pthread_cancel(ptid);
969+
(void) pthread_join(ptid, &status);
970+
int error = (int)(uintptr_t)status;
971+
if (error != 0 && status != PTHREAD_CANCELED)
972+
return (zfs_standard_error(hdl, error,
973+
dgettext(TEXT_DOMAIN, "progress thread exited nonzero")));
974+
else
975+
return (B_FALSE);
976+
}
977+
964978
static void
965979
send_print_verbose(FILE *fout, const char *tosnap, const char *fromsnap,
966980
uint64_t size, boolean_t parsable)
@@ -1133,17 +1147,9 @@ dump_snapshot(zfs_handle_t *zhp, void *arg)
11331147
err = dump_ioctl(zhp, sdd->prevsnap, sdd->prevsnap_obj,
11341148
fromorigin, sdd->outfd, flags, sdd->debugnv);
11351149

1136-
if (sdd->progress) {
1137-
void *status = NULL;
1138-
(void) pthread_cancel(tid);
1139-
(void) pthread_join(tid, &status);
1140-
int error = (int)(uintptr_t)status;
1141-
if (error != 0 && status != PTHREAD_CANCELED) {
1142-
return (zfs_standard_error(zhp->zfs_hdl, error,
1143-
dgettext(TEXT_DOMAIN,
1144-
"progress thread exited nonzero")));
1145-
}
1146-
}
1150+
if (sdd->progress &&
1151+
send_progress_thread_exit(zhp->zfs_hdl, tid))
1152+
return (-1);
11471153
}
11481154

11491155
(void) strcpy(sdd->prevsnap, thissnap);
@@ -1505,20 +1511,8 @@ estimate_size(zfs_handle_t *zhp, const char *from, int fd, sendflags_t *flags,
15051511
lzc_flags_from_sendflags(flags), resumeobj, resumeoff, bytes,
15061512
redactbook, fd, &size);
15071513

1508-
if (flags->progress) {
1509-
void *status = NULL;
1510-
(void) pthread_cancel(ptid);
1511-
(void) pthread_join(ptid, &status);
1512-
int error = (int)(uintptr_t)status;
1513-
if (error != 0 && status != PTHREAD_CANCELED) {
1514-
char errbuf[1024];
1515-
(void) snprintf(errbuf, sizeof (errbuf),
1516-
dgettext(TEXT_DOMAIN, "progress thread exited "
1517-
"nonzero"));
1518-
return (zfs_standard_error(zhp->zfs_hdl, error,
1519-
errbuf));
1520-
}
1521-
}
1514+
if (flags->progress && send_progress_thread_exit(zhp->zfs_hdl, ptid))
1515+
return (-1);
15221516

15231517
if (err != 0) {
15241518
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,
18301824
if (redact_book != NULL)
18311825
free(redact_book);
18321826

1833-
if (flags->progress) {
1834-
void *status = NULL;
1835-
(void) pthread_cancel(tid);
1836-
(void) pthread_join(tid, &status);
1837-
int error = (int)(uintptr_t)status;
1838-
if (error != 0 && status != PTHREAD_CANCELED) {
1839-
char errbuf[1024];
1840-
(void) snprintf(errbuf, sizeof (errbuf),
1841-
dgettext(TEXT_DOMAIN,
1842-
"progress thread exited nonzero"));
1843-
return (zfs_standard_error(hdl, error, errbuf));
1844-
}
1845-
}
1827+
if (flags->progress && send_progress_thread_exit(hdl, tid))
1828+
return (-1);
18461829

18471830
char errbuf[1024];
18481831
(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,
26412624
err = lzc_send_redacted(name, from, fd,
26422625
lzc_flags_from_sendflags(flags), redactbook);
26432626

2644-
if (flags->progress) {
2645-
void *status = NULL;
2646-
(void) pthread_cancel(ptid);
2647-
(void) pthread_join(ptid, &status);
2648-
int error = (int)(uintptr_t)status;
2649-
if (error != 0 && status != PTHREAD_CANCELED)
2650-
return (zfs_standard_error_fmt(hdl, error,
2651-
dgettext(TEXT_DOMAIN,
2652-
"progress thread exited nonzero")));
2653-
}
2627+
if (flags->progress && send_progress_thread_exit(hdl, ptid))
2628+
return (-1);
26542629

26552630
if (err == 0 && (flags->props || flags->holds || flags->backup)) {
26562631
/* Write the final end record. */

0 commit comments

Comments
 (0)