summaryrefslogtreecommitdiffstats
path: root/cmd/zpool
diff options
context:
space:
mode:
authorAlek P <[email protected]>2017-05-19 12:33:11 -0700
committerBrian Behlendorf <[email protected]>2017-05-19 12:33:11 -0700
commitbec1067d54a004cb52a4a6762bfa1d4a30300865 (patch)
treea464efb9e42d172cabbe66e7c2fb5296c5e6023d /cmd/zpool
parent4a283c7f77eb5065e9f03b122bf8ead4f4a1e2be (diff)
Implemented zpool sync command
This addition will enable us to sync an open TXG to the main pool on demand. The functionality is similar to 'sync(2)' but 'zpool sync' will return when data has hit the main storage instead of potentially just the ZIL as is the case with the 'sync(2)' cmd. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed by: Matthew Ahrens <[email protected]> Signed-off-by: Alek Pinchuk <[email protected]> Closes #6122
Diffstat (limited to 'cmd/zpool')
-rw-r--r--cmd/zpool/zpool_main.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c
index 0d06dcc05..f99145da9 100644
--- a/cmd/zpool/zpool_main.c
+++ b/cmd/zpool/zpool_main.c
@@ -27,6 +27,7 @@
* Copyright (c) 2012 by Cyril Plisko. All rights reserved.
* Copyright (c) 2013 by Prasad Joshi (sTec). All rights reserved.
* Copyright 2016 Igor Kozhukhov <[email protected]>.
+ * Copyright (c) 2017 Datto Inc.
*/
#include <assert.h>
@@ -100,6 +101,8 @@ static int zpool_do_events(int, char **);
static int zpool_do_get(int, char **);
static int zpool_do_set(int, char **);
+static int zpool_do_sync(int, char **);
+
/*
* These libumem hooks provide a reasonable set of defaults for the allocator's
* debugging facilities.
@@ -143,6 +146,7 @@ typedef enum {
HELP_GET,
HELP_SET,
HELP_SPLIT,
+ HELP_SYNC,
HELP_REGUID,
HELP_REOPEN
} zpool_help_t;
@@ -272,6 +276,7 @@ static zpool_command_t command_table[] = {
{ NULL },
{ "get", zpool_do_get, HELP_GET },
{ "set", zpool_do_set, HELP_SET },
+ { "sync", zpool_do_sync, HELP_SYNC },
};
#define NCOMMAND (ARRAY_SIZE(command_table))
@@ -358,6 +363,8 @@ get_usage(zpool_help_t idx)
"[<device> ...]\n"));
case HELP_REGUID:
return (gettext("\treguid <pool>\n"));
+ case HELP_SYNC:
+ return (gettext("\tsync [pool] ...\n"));
}
abort();
@@ -2693,6 +2700,45 @@ error:
return (err ? 1 : 0);
}
+/*
+ * zpool sync [-f] [pool] ...
+ *
+ * -f (undocumented) force uberblock (and config including zpool cache file)
+ * update.
+ *
+ * Sync the specified pool(s).
+ * Without arguments "zpool sync" will sync all pools.
+ * This command initiates TXG sync(s) and will return after the TXG(s) commit.
+ *
+ */
+static int
+zpool_do_sync(int argc, char **argv)
+{
+ int ret;
+ boolean_t force = B_FALSE;
+
+ /* check options */
+ while ((ret = getopt(argc, argv, "f")) != -1) {
+ switch (ret) {
+ case 'f':
+ force = B_TRUE;
+ break;
+ case '?':
+ (void) fprintf(stderr, gettext("invalid option '%c'\n"),
+ optopt);
+ usage(B_FALSE);
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ /* if argc == 0 we will execute zpool_sync_one on all pools */
+ ret = for_each_pool(argc, argv, B_FALSE, NULL, zpool_sync_one, &force);
+
+ return (ret);
+}
+
typedef struct iostat_cbdata {
uint64_t cb_flags;
int cb_name_flags;