Skip to content

Commit

Permalink
2703 add mechanism to report ZFS send progress
Browse files Browse the repository at this point in the history
Reviewed by: Matt Ahrens <[email protected]>
Reviewed by: Robert Mustacchi <[email protected]>
Reviewed by: Richard Lowe <[email protected]>
Approved by: Eric Schrock <[email protected]>
  • Loading branch information
Bill Pijewski committed May 9, 2012
1 parent b483d17 commit 4e3c9f4
Show file tree
Hide file tree
Showing 13 changed files with 316 additions and 129 deletions.
3 changes: 3 additions & 0 deletions usr/src/cmd/truss/codes.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012 by Delphix. All rights reserved.
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
*/

/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
Expand Down Expand Up @@ -1256,6 +1257,8 @@ const struct ioc {
"zfs_cmd_t" },
{ (uint_t)ZFS_IOC_POOL_REOPEN, "ZFS_IOC_POOL_REOPEN",
"zfs_cmd_t" },
{ (uint_t)ZFS_IOC_SEND_PROGRESS, "ZFS_IOC_SEND_PROGRESS",
"zfs_cmd_t" },

/* kssl ioctls */
{ (uint_t)KSSL_ADD_ENTRY, "KSSL_ADD_ENTRY",
Expand Down
2 changes: 2 additions & 0 deletions usr/src/cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Copyright 2012 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 2012 by Delphix. All rights reserved.
* Copyright 2012 Milan Jurik. All rights reserved.
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
*/

#include <assert.h>
Expand Down Expand Up @@ -3525,6 +3526,7 @@ zfs_do_send(int argc, char **argv)
if (flags.verbose)
extraverbose = B_TRUE;
flags.verbose = B_TRUE;
flags.progress = B_TRUE;
break;
case 'D':
flags.dedup = B_TRUE;
Expand Down
4 changes: 4 additions & 0 deletions usr/src/lib/libzfs/common/libzfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 2012 by Delphix. All rights reserved.
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
*/

#ifndef _LIBZFS_H
Expand Down Expand Up @@ -557,6 +558,9 @@ typedef struct sendflags {

/* parsable verbose output (ie. -P) */
boolean_t parsable;

/* show progress (ie. -v) */
boolean_t progress;
} sendflags_t;

typedef boolean_t (snapfilter_cb_t)(zfs_handle_t *, void *);
Expand Down
84 changes: 82 additions & 2 deletions usr/src/lib/libzfs/common/libzfs_sendrecv.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011 by Delphix. All rights reserved.
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
*/

#include <assert.h>
Expand All @@ -37,6 +38,7 @@
#include <sys/mount.h>
#include <pthread.h>
#include <umem.h>
#include <time.h>

#include <libzfs.h>

Expand All @@ -62,6 +64,12 @@ typedef struct dedup_arg {
libzfs_handle_t *dedup_hdl;
} dedup_arg_t;

typedef struct progress_arg {
zfs_handle_t *pa_zhp;
int pa_fd;
boolean_t pa_parsable;
} progress_arg_t;

typedef struct dataref {
uint64_t ref_guid;
uint64_t ref_object;
Expand Down Expand Up @@ -781,7 +789,7 @@ typedef struct send_dump_data {
char prevsnap[ZFS_MAXNAMELEN];
uint64_t prevsnap_obj;
boolean_t seenfrom, seento, replicate, doall, fromorigin;
boolean_t verbose, dryrun, parsable;
boolean_t verbose, dryrun, parsable, progress;
int outfd;
boolean_t err;
nvlist_t *fss;
Expand Down Expand Up @@ -973,10 +981,60 @@ hold_for_send(zfs_handle_t *zhp, send_dump_data_t *sdd)
return (error);
}

static void *
send_progress_thread(void *arg)
{
progress_arg_t *pa = arg;

zfs_cmd_t zc = { 0 };
zfs_handle_t *zhp = pa->pa_zhp;
libzfs_handle_t *hdl = zhp->zfs_hdl;
unsigned long long bytes;
char buf[16];

time_t t;
struct tm *tm;

assert(zhp->zfs_type == ZFS_TYPE_SNAPSHOT);
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));

if (!pa->pa_parsable)
(void) fprintf(stderr, "TIME SENT SNAPSHOT\n");

/*
* Print the progress from ZFS_IOC_SEND_PROGRESS every second.
*/
for (;;) {
(void) sleep(1);

zc.zc_cookie = pa->pa_fd;
if (zfs_ioctl(hdl, ZFS_IOC_SEND_PROGRESS, &zc) != 0)
return ((void *)-1);

(void) time(&t);
tm = localtime(&t);
bytes = zc.zc_cookie;

if (pa->pa_parsable) {
(void) fprintf(stderr, "%02d:%02d:%02d\t%llu\t%s\n",
tm->tm_hour, tm->tm_min, tm->tm_sec,
bytes, zhp->zfs_name);
} else {
zfs_nicenum(bytes, buf, sizeof (buf));
(void) fprintf(stderr, "%02d:%02d:%02d %5s %s\n",
tm->tm_hour, tm->tm_min, tm->tm_sec,
buf, zhp->zfs_name);
}
}
}

static int
dump_snapshot(zfs_handle_t *zhp, void *arg)
{
send_dump_data_t *sdd = arg;
progress_arg_t pa = { 0 };
pthread_t tid;

char *thissnap;
int err;
boolean_t isfromsnap, istosnap, fromorigin;
Expand Down Expand Up @@ -1094,8 +1152,29 @@ dump_snapshot(zfs_handle_t *zhp, void *arg)
}

if (!sdd->dryrun) {
/*
* If progress reporting is requested, spawn a new thread to
* poll ZFS_IOC_SEND_PROGRESS at a regular interval.
*/
if (sdd->progress) {
pa.pa_zhp = zhp;
pa.pa_fd = sdd->outfd;
pa.pa_parsable = sdd->parsable;

if (err = pthread_create(&tid, NULL,
send_progress_thread, &pa)) {
zfs_close(zhp);
return (err);
}
}

err = dump_ioctl(zhp, sdd->prevsnap, sdd->prevsnap_obj,
fromorigin, sdd->outfd, sdd->debugnv);

if (sdd->progress) {
(void) pthread_cancel(tid);
(void) pthread_join(tid, NULL);
}
}

(void) strcpy(sdd->prevsnap, thissnap);
Expand Down Expand Up @@ -1445,12 +1524,13 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap,
sdd.fsavl = fsavl;
sdd.verbose = flags->verbose;
sdd.parsable = flags->parsable;
sdd.progress = flags->progress;
sdd.dryrun = flags->dryrun;
sdd.filter_cb = filter_func;
sdd.filter_cb_arg = cb_arg;
if (debugnvp)
sdd.debugnv = *debugnvp;
if (holdsnaps) {
if (holdsnaps || flags->progress) {
++holdseq;
(void) snprintf(sdd.holdtag, sizeof (sdd.holdtag),
".send-%d-%llu", getpid(), (u_longlong_t)holdseq);
Expand Down
2 changes: 2 additions & 0 deletions usr/src/lib/libzpool/common/sys/zfs_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 2012 by Delphix. All rights reserved.
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
*/

#ifndef _SYS_ZFS_CONTEXT_H
Expand Down Expand Up @@ -214,6 +215,7 @@ struct proc {
};

extern struct proc p0;
#define curproc (&p0)

#define PS_NONE -1

Expand Down
4 changes: 3 additions & 1 deletion usr/src/man/man1m/zfs.1m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.\" Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
.\" Copyright (c) 2012 by Delphix. All rights reserved.
.\" Copyright (c) 2012 Nexenta Systems, Inc. All Rights Reserved.
.\" Copyright (c) 2012, Joyent, Inc. All rights reserved.
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
.\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with
.\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
Expand Down Expand Up @@ -2845,7 +2846,8 @@ Print machine-parsable verbose information about the stream package generated.
.ad
.sp .6
.RS 4n
Print verbose information about the stream package generated.
Print verbose information about the stream package generated. This information
includes a per-second report of how much data has been sent.
.RE

The format of the stream is committed. You will be able to receive your streams
Expand Down
Loading

0 comments on commit 4e3c9f4

Please sign in to comment.