mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-23 02:44:41 +03:00
Add 'zfs wait' command
Add a mechanism to wait for delete queue to drain. When doing redacted send/recv, many workflows involve deleting files that contain sensitive data. Because of the way zfs handles file deletions, snapshots taken quickly after a rm operation can sometimes still contain the file in question, especially if the file is very large. This can result in issues for redacted send/recv users who expect the deleted files to be redacted in the send streams, and not appear in their clones. This change duplicates much of the zpool wait related logic into a zfs wait command, which can be used to wait until the internal deleteq has been drained. Additional wait activities may be added in the future. Reviewed-by: Matthew Ahrens <mahrens@delphix.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: John Gallagher <john.gallagher@delphix.com> Signed-off-by: Paul Dagnelie <pcd@delphix.com> Closes #9707
This commit is contained in:
+90
-1
@@ -122,6 +122,7 @@ static int zfs_do_change_key(int argc, char **argv);
|
||||
static int zfs_do_project(int argc, char **argv);
|
||||
static int zfs_do_version(int argc, char **argv);
|
||||
static int zfs_do_redact(int argc, char **argv);
|
||||
static int zfs_do_wait(int argc, char **argv);
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
static int zfs_do_jail(int argc, char **argv);
|
||||
@@ -183,7 +184,8 @@ typedef enum {
|
||||
HELP_VERSION,
|
||||
HELP_REDACT,
|
||||
HELP_JAIL,
|
||||
HELP_UNJAIL
|
||||
HELP_UNJAIL,
|
||||
HELP_WAIT,
|
||||
} zfs_help_t;
|
||||
|
||||
typedef struct zfs_command {
|
||||
@@ -248,6 +250,7 @@ static zfs_command_t command_table[] = {
|
||||
{ "unload-key", zfs_do_unload_key, HELP_UNLOAD_KEY },
|
||||
{ "change-key", zfs_do_change_key, HELP_CHANGE_KEY },
|
||||
{ "redact", zfs_do_redact, HELP_REDACT },
|
||||
{ "wait", zfs_do_wait, HELP_WAIT },
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
{ "jail", zfs_do_jail, HELP_JAIL },
|
||||
@@ -410,6 +413,8 @@ get_usage(zfs_help_t idx)
|
||||
return (gettext("\tjail <jailid|jailname> <filesystem>\n"));
|
||||
case HELP_UNJAIL:
|
||||
return (gettext("\tunjail <jailid|jailname> <filesystem>\n"));
|
||||
case HELP_WAIT:
|
||||
return (gettext("\twait [-t <activity>] <filesystem>\n"));
|
||||
}
|
||||
|
||||
abort();
|
||||
@@ -8317,6 +8322,90 @@ zfs_do_project(int argc, char **argv)
|
||||
return (ret);
|
||||
}
|
||||
|
||||
static int
|
||||
zfs_do_wait(int argc, char **argv)
|
||||
{
|
||||
boolean_t enabled[ZFS_WAIT_NUM_ACTIVITIES];
|
||||
int error, i;
|
||||
char c;
|
||||
|
||||
/* By default, wait for all types of activity. */
|
||||
for (i = 0; i < ZFS_WAIT_NUM_ACTIVITIES; i++)
|
||||
enabled[i] = B_TRUE;
|
||||
|
||||
while ((c = getopt(argc, argv, "t:")) != -1) {
|
||||
switch (c) {
|
||||
case 't':
|
||||
{
|
||||
static char *col_subopts[] = { "deleteq", NULL };
|
||||
char *value;
|
||||
|
||||
/* Reset activities array */
|
||||
bzero(&enabled, sizeof (enabled));
|
||||
while (*optarg != '\0') {
|
||||
int activity = getsubopt(&optarg, col_subopts,
|
||||
&value);
|
||||
|
||||
if (activity < 0) {
|
||||
(void) fprintf(stderr,
|
||||
gettext("invalid activity '%s'\n"),
|
||||
value);
|
||||
usage(B_FALSE);
|
||||
}
|
||||
|
||||
enabled[activity] = B_TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '?':
|
||||
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
||||
optopt);
|
||||
usage(B_FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
if (argc < 1) {
|
||||
(void) fprintf(stderr, gettext("missing 'filesystem' "
|
||||
"argument\n"));
|
||||
usage(B_FALSE);
|
||||
}
|
||||
if (argc > 1) {
|
||||
(void) fprintf(stderr, gettext("too many arguments\n"));
|
||||
usage(B_FALSE);
|
||||
}
|
||||
|
||||
zfs_handle_t *zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_FILESYSTEM);
|
||||
if (zhp == NULL)
|
||||
return (1);
|
||||
|
||||
for (;;) {
|
||||
boolean_t missing = B_FALSE;
|
||||
boolean_t any_waited = B_FALSE;
|
||||
|
||||
for (int i = 0; i < ZFS_WAIT_NUM_ACTIVITIES; i++) {
|
||||
boolean_t waited;
|
||||
|
||||
if (!enabled[i])
|
||||
continue;
|
||||
|
||||
error = zfs_wait_status(zhp, i, &missing, &waited);
|
||||
if (error != 0 || missing)
|
||||
break;
|
||||
|
||||
any_waited = (any_waited || waited);
|
||||
}
|
||||
|
||||
if (error != 0 || missing || !any_waited)
|
||||
break;
|
||||
}
|
||||
|
||||
zfs_close(zhp);
|
||||
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Display version message
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user