@@ -928,16 +928,24 @@ zfs_send_progress(zfs_handle_t *zhp, int fd, uint64_t *bytes_written,
928
928
return (0 );
929
929
}
930
930
931
+ static volatile boolean_t send_progress_thread_signal_duetotimer ;
931
932
static void
932
- signal_nop (int sig )
933
+ send_progress_thread_act (int sig , siginfo_t * info , void * ucontext )
933
934
{
934
- (void ) sig ;
935
+ (void ) sig , (void ) ucontext ;
936
+ send_progress_thread_signal_duetotimer = info -> si_code == SI_TIMER ;
935
937
}
936
938
939
+ struct timer_desirability {
940
+ timer_t timer ;
941
+ boolean_t desired ;
942
+ };
937
943
static void
938
944
timer_delete_cleanup (void * timer )
939
945
{
940
- timer_delete (timer );
946
+ struct timer_desirability * td = timer ;
947
+ if (td -> desired )
948
+ timer_delete (td -> timer );
941
949
}
942
950
943
951
#ifdef SIGINFO
@@ -967,22 +975,24 @@ send_progress_thread(void *arg)
967
975
int err ;
968
976
969
977
const struct sigaction signal_action =
970
- {.sa_handler = signal_nop };
978
+ {.sa_sigaction = send_progress_thread_act , . sa_flags = SA_SIGINFO };
971
979
struct sigevent timer_cfg =
972
980
{.sigev_notify = SIGEV_SIGNAL , .sigev_signo = SIGUSR1 };
973
981
const struct itimerspec timer_time =
974
982
{.it_value = {.tv_sec = 1 }, .it_interval = {.tv_sec = 1 }};
975
- timer_t timer ;
983
+ struct timer_desirability timer = {} ;
976
984
977
985
sigaction (SIGUSR1 , & signal_action , NULL );
978
986
#ifdef SIGINFO
979
987
sigaction (SIGINFO , & signal_action , NULL );
980
988
#endif
981
989
982
- if (timer_create (CLOCK_MONOTONIC , & timer_cfg , & timer ))
983
- return ((void * )(uintptr_t )errno );
984
- pthread_cleanup_push (timer_delete_cleanup , timer );
985
- (void ) timer_settime (timer , 0 , & timer_time , NULL );
990
+ if ((timer .desired = pa -> pa_progress || pa -> pa_astitle )) {
991
+ if (timer_create (CLOCK_MONOTONIC , & timer_cfg , & timer .timer ))
992
+ return ((void * )(uintptr_t )errno );
993
+ (void ) timer_settime (timer .timer , 0 , & timer_time , NULL );
994
+ }
995
+ pthread_cleanup_push (timer_delete_cleanup , & timer );
986
996
987
997
if (!pa -> pa_parsable && pa -> pa_progress ) {
988
998
(void ) fprintf (stderr ,
@@ -1033,7 +1043,8 @@ send_progress_thread(void *arg)
1033
1043
(void ) fprintf (stderr , "%02d:%02d:%02d\t%llu\t%s\n" ,
1034
1044
tm .tm_hour , tm .tm_min , tm .tm_sec ,
1035
1045
(u_longlong_t )bytes , zhp -> zfs_name );
1036
- } else if (pa -> pa_progress ) {
1046
+ } else if (pa -> pa_progress ||
1047
+ !send_progress_thread_signal_duetotimer ) {
1037
1048
zfs_nicebytes (bytes , buf , sizeof (buf ));
1038
1049
(void ) fprintf (stderr , "%02d:%02d:%02d %5s %s\n" ,
1039
1050
tm .tm_hour , tm .tm_min , tm .tm_sec ,
@@ -1246,7 +1257,7 @@ dump_snapshot(zfs_handle_t *zhp, void *arg)
1246
1257
* poll ZFS_IOC_SEND_PROGRESS at a regular interval.
1247
1258
*/
1248
1259
sigset_t oldmask ;
1249
- if ( sdd -> progress || sdd -> progressastitle ) {
1260
+ {
1250
1261
pa .pa_zhp = zhp ;
1251
1262
pa .pa_fd = sdd -> outfd ;
1252
1263
pa .pa_parsable = sdd -> parsable ;
@@ -1267,8 +1278,7 @@ dump_snapshot(zfs_handle_t *zhp, void *arg)
1267
1278
err = dump_ioctl (zhp , sdd -> prevsnap , sdd -> prevsnap_obj ,
1268
1279
fromorigin , sdd -> outfd , flags , sdd -> debugnv );
1269
1280
1270
- if ((sdd -> progress || sdd -> progressastitle ) &&
1271
- send_progress_thread_exit (zhp -> zfs_hdl , tid , & oldmask ))
1281
+ if (send_progress_thread_exit (zhp -> zfs_hdl , tid , & oldmask ))
1272
1282
return (-1 );
1273
1283
}
1274
1284
@@ -1612,7 +1622,7 @@ estimate_size(zfs_handle_t *zhp, const char *from, int fd, sendflags_t *flags,
1612
1622
pthread_t ptid ;
1613
1623
sigset_t oldmask ;
1614
1624
1615
- if ( flags -> progress || flags -> progressastitle ) {
1625
+ {
1616
1626
pa .pa_zhp = zhp ;
1617
1627
pa .pa_fd = fd ;
1618
1628
pa .pa_parsable = flags -> parsable ;
@@ -1634,8 +1644,7 @@ estimate_size(zfs_handle_t *zhp, const char *from, int fd, sendflags_t *flags,
1634
1644
redactbook , fd , & size );
1635
1645
* sizep = size ;
1636
1646
1637
- if ((flags -> progress || flags -> progressastitle ) &&
1638
- send_progress_thread_exit (zhp -> zfs_hdl , ptid , & oldmask ))
1647
+ if (send_progress_thread_exit (zhp -> zfs_hdl , ptid , & oldmask ))
1639
1648
return (-1 );
1640
1649
1641
1650
if (!flags -> progress && !flags -> parsable )
@@ -1931,7 +1940,7 @@ zfs_send_resume_impl_cb_impl(libzfs_handle_t *hdl, sendflags_t *flags,
1931
1940
* If progress reporting is requested, spawn a new thread to
1932
1941
* poll ZFS_IOC_SEND_PROGRESS at a regular interval.
1933
1942
*/
1934
- if ( flags -> progress || flags -> progressastitle ) {
1943
+ {
1935
1944
pa .pa_zhp = zhp ;
1936
1945
pa .pa_fd = outfd ;
1937
1946
pa .pa_parsable = flags -> parsable ;
@@ -1957,8 +1966,7 @@ zfs_send_resume_impl_cb_impl(libzfs_handle_t *hdl, sendflags_t *flags,
1957
1966
if (redact_book != NULL )
1958
1967
free (redact_book );
1959
1968
1960
- if ((flags -> progressastitle || flags -> progress ) &&
1961
- send_progress_thread_exit (hdl , tid , & oldmask )) {
1969
+ if (send_progress_thread_exit (hdl , tid , & oldmask )) {
1962
1970
zfs_close (zhp );
1963
1971
return (-1 );
1964
1972
}
@@ -2744,7 +2752,7 @@ zfs_send_one_cb_impl(zfs_handle_t *zhp, const char *from, int fd,
2744
2752
* ZFS_IOC_SEND_PROGRESS at a regular interval.
2745
2753
*/
2746
2754
sigset_t oldmask ;
2747
- if ( flags -> progress || flags -> progressastitle ) {
2755
+ {
2748
2756
pa .pa_zhp = zhp ;
2749
2757
pa .pa_fd = fd ;
2750
2758
pa .pa_parsable = flags -> parsable ;
@@ -2767,8 +2775,7 @@ zfs_send_one_cb_impl(zfs_handle_t *zhp, const char *from, int fd,
2767
2775
err = lzc_send_redacted (name , from , fd ,
2768
2776
lzc_flags_from_sendflags (flags ), redactbook );
2769
2777
2770
- if ((flags -> progress || flags -> progressastitle ) &&
2771
- send_progress_thread_exit (hdl , ptid , & oldmask ))
2778
+ if (send_progress_thread_exit (hdl , ptid , & oldmask ))
2772
2779
return (-1 );
2773
2780
2774
2781
if (err == 0 && (flags -> props || flags -> holds || flags -> backup )) {
0 commit comments