Skip to content

Commit

Permalink
Allow an option to set the process title during a zfs send.
Browse files Browse the repository at this point in the history
This code is modified from iXsystem's implementation.
  • Loading branch information
Sean Eric Fagan committed Feb 16, 2019
1 parent ac10f17 commit b6703f8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
12 changes: 12 additions & 0 deletions config/user-setproctitle.m4
@@ -0,0 +1,12 @@
dnl #
dnl # Check for setproctitle
dnl # In BSD, this is in libc; in Linux, it tends to be in -lbsd
dnl #
AC_DEFUN([ZFS_AC_CONFIG_USER_SETPROCTITLE], [
AC_SEARCH_LIBS([setproctitle], [bsd], [
AC_DEFINE(HAVE_PROCTITLE, 1,
[Define if the system has setproctitle])
]
)
])
1 change: 1 addition & 0 deletions config/user.m4
Expand Up @@ -8,6 +8,7 @@ AC_DEFUN([ZFS_AC_CONFIG_USER], [
ZFS_AC_CONFIG_USER_SYSVINIT
ZFS_AC_CONFIG_USER_DRACUT
ZFS_AC_CONFIG_USER_ZLIB
ZFS_AC_CONFIG_USER_SETPROCTITLE
ZFS_AC_CONFIG_USER_LIBUUID
ZFS_AC_CONFIG_USER_LIBTIRPC
ZFS_AC_CONFIG_USER_LIBBLKID
Expand Down
2 changes: 1 addition & 1 deletion lib/libzfs/Makefile.am
Expand Up @@ -61,7 +61,7 @@ libzfs_la_LIBADD = \
$(top_builddir)/lib/libzfs_core/libzfs_core.la \
$(top_builddir)/lib/libzutil/libzutil.la

libzfs_la_LIBADD += -lm $(LIBSSL)
libzfs_la_LIBADD += -lm ${BSDLIB} $(LIBSSL)
libzfs_la_LDFLAGS = -version-info 2:0:0

EXTRA_DIST = $(libzfs_pc_DATA) $(USER_C)
Expand Down
17 changes: 11 additions & 6 deletions lib/libzfs/libzfs_sendrecv.c
Expand Up @@ -1223,8 +1223,10 @@ send_progress_thread(void *arg)
if (pct > 100)
pct = 100;

#ifdef HAVE_PROCTITLE
setproctitle("sending %s (%d%%: %llu/%llu)",
zhp->zfs_name, pct, bytes, pa->pa_size);
#endif /* HAVE_PROCTITLE */
} else {
if (pa->pa_parsable) {
(void) fprintf(stderr, "%02d:%02d:%02d\t%llu\t%s\n",
Expand Down Expand Up @@ -1295,6 +1297,7 @@ dump_snapshot(zfs_handle_t *zhp, void *arg)
boolean_t isfromsnap, istosnap, fromorigin;
boolean_t exclude = B_FALSE;
FILE *fout = sdd->std_out ? stdout : stderr;
uint64_t size = 0;

err = 0;
thissnap = strchr(zhp->zfs_name, '@') + 1;
Expand Down Expand Up @@ -1372,8 +1375,7 @@ dump_snapshot(zfs_handle_t *zhp, void *arg)
fromorigin = sdd->prevsnap[0] == '\0' &&
(sdd->fromorigin || sdd->replicate);

if (sdd->verbose) {
uint64_t size = 0;
if (sdd->progress && sdd->dryrun) {
char fromds[ZFS_MAX_DATASET_NAME_LEN];

if (sdd->prevsnap[0] != '\0') {
Expand All @@ -1384,13 +1386,15 @@ dump_snapshot(zfs_handle_t *zhp, void *arg)
if (zfs_send_space(zhp, zhp->zfs_name,
sdd->prevsnap[0] ? fromds : NULL, flags, &size) != 0) {
size = 0; /* cannot estimate send space */
} else {
send_print_verbose(fout, zhp->zfs_name,
sdd->prevsnap[0] ? sdd->prevsnap : NULL,
size, sdd->parsable);
}
sdd->size += size;
}

if (sdd->verbose) {
send_print_verbose(fout, zhp->zfs_name,
sdd->prevsnap[0] ? sdd->prevsnap : NULL,
size, sdd->parsable);
}

if (!sdd->dryrun) {
/*
Expand Down Expand Up @@ -1776,6 +1780,7 @@ zfs_send_resume(libzfs_handle_t *hdl, sendflags_t *flags, int outfd,
pa.pa_zhp = zhp;
pa.pa_fd = outfd;
pa.pa_parsable = flags->parsable;
pa.pa_astitle = flags->progressastitle;

error = pthread_create(&tid, NULL,
send_progress_thread, &pa);
Expand Down
13 changes: 9 additions & 4 deletions man/man8/zfs.8
Expand Up @@ -30,7 +30,7 @@
.\" Copyright 2018 Nexenta Systems, Inc.
.\" Copyright 2018 Joyent, Inc.
.\"
.Dd Jan 05, 2019
.Dd Feb 15, 2019
.Dt ZFS 8 SMM
.Os Linux
.Sh NAME
Expand Down Expand Up @@ -195,17 +195,17 @@
.Ar snapshot bookmark
.Nm
.Cm send
.Op Fl DLPRbcenpvw
.Op Fl DLPRVbcenpvw
.Op Oo Fl I Ns | Ns Fl i Oc Ar snapshot
.Ar snapshot
.Nm
.Cm send
.Op Fl LPcenvw
.Op Fl LPVcenvw
.Op Fl i Ar snapshot Ns | Ns Ar bookmark
.Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot
.Nm
.Cm send
.Op Fl Penv
.Op Fl PVenv
.Fl t Ar receive_resume_token
.Nm
.Cm receive
Expand Down Expand Up @@ -3724,6 +3724,11 @@ and the verbose output goes to standard error
.It Fl v, -verbose
Print verbose information about the stream package generated.
This information includes a per-second report of how much data has been sent.
.It Fl V
Set the process title to a per-second report of how much data has been sent.
(On systems without
.Fn setproctitle
support, this option succeeds, but does not change the process title.)
.El
.It Xo
.Nm
Expand Down

0 comments on commit b6703f8

Please sign in to comment.