diff options
author | Turbo Fredriksson <[email protected]> | 2015-03-20 23:29:14 +0100 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2015-05-04 10:17:08 -0700 |
commit | 859735c0954e89dd329729c6959df7cbaca1fdcc (patch) | |
tree | 4d28d1be45ec1e0dc38d420c9b411d28a0d3bec1 | |
parent | 0c60cc326bdb44f7eea61e62c6183822d0bd9cf0 (diff) |
Add the '-a' option to 'zpool export'
Support exporting all imported pools in one go, using 'zpool export -a'.
This is accomplished by moving the export parts from zpool_do_export()
in to the new function zpool_export_one(). The for_each_pool() function
is used to enumerate the list of pools to be exported. Passing an argc
of 0 implies the function should be called on all pools.
Signed-off-by: Turbo Fredriksson <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Closes: #3203
-rw-r--r-- | cmd/zpool/zpool_main.c | 82 | ||||
-rw-r--r-- | man/man8/zpool.8 | 19 |
2 files changed, 67 insertions, 34 deletions
diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c index ca3737475..bf323ee08 100644 --- a/cmd/zpool/zpool_main.c +++ b/cmd/zpool/zpool_main.c @@ -222,7 +222,7 @@ get_usage(zpool_help_t idx) { case HELP_DETACH: return (gettext("\tdetach <pool> <device>\n")); case HELP_EXPORT: - return (gettext("\texport [-f] <pool> ...\n")); + return (gettext("\texport [-af] <pool> ...\n")); case HELP_HISTORY: return (gettext("\thistory [-il] [<pool>] ...\n")); case HELP_IMPORT: @@ -1212,9 +1212,39 @@ zpool_do_destroy(int argc, char **argv) return (ret); } +typedef struct export_cbdata { + boolean_t force; + boolean_t hardforce; +} export_cbdata_t; + +/* + * Export one pool + */ +int +zpool_export_one(zpool_handle_t *zhp, void *data) +{ + export_cbdata_t *cb = data; + + if (zpool_disable_datasets(zhp, cb->force) != 0) + return (1); + + /* The history must be logged as part of the export */ + log_history = B_FALSE; + + if (cb->hardforce) { + if (zpool_export_force(zhp, history_str) != 0) + return (1); + } else if (zpool_export(zhp, cb->force, history_str) != 0) { + return (1); + } + + return (0); +} + /* * zpool export [-f] <pool> ... * + * -a Export all pools * -f Forcefully unmount datasets * * Export the given pools. By default, the command will attempt to cleanly @@ -1224,16 +1254,18 @@ zpool_do_destroy(int argc, char **argv) int zpool_do_export(int argc, char **argv) { + export_cbdata_t cb; + boolean_t do_all = B_FALSE; boolean_t force = B_FALSE; boolean_t hardforce = B_FALSE; - int c; - zpool_handle_t *zhp; - int ret; - int i; + int c, ret; /* check options */ - while ((c = getopt(argc, argv, "fF")) != -1) { + while ((c = getopt(argc, argv, "afF")) != -1) { switch (c) { + case 'a': + do_all = B_TRUE; + break; case 'f': force = B_TRUE; break; @@ -1247,40 +1279,28 @@ zpool_do_export(int argc, char **argv) } } + cb.force = force; + cb.hardforce = hardforce; argc -= optind; argv += optind; + if (do_all) { + if (argc != 0) { + (void) fprintf(stderr, gettext("too many arguments\n")); + usage(B_FALSE); + } + + return (for_each_pool(argc, argv, B_TRUE, NULL, + zpool_export_one, &cb)); + } + /* check arguments */ if (argc < 1) { (void) fprintf(stderr, gettext("missing pool argument\n")); usage(B_FALSE); } - ret = 0; - for (i = 0; i < argc; i++) { - if ((zhp = zpool_open_canfail(g_zfs, argv[i])) == NULL) { - ret = 1; - continue; - } - - if (zpool_disable_datasets(zhp, force) != 0) { - ret = 1; - zpool_close(zhp); - continue; - } - - /* The history must be logged as part of the export */ - log_history = B_FALSE; - - if (hardforce) { - if (zpool_export_force(zhp, history_str) != 0) - ret = 1; - } else if (zpool_export(zhp, force, history_str) != 0) { - ret = 1; - } - - zpool_close(zhp); - } + ret = for_each_pool(argc, argv, B_TRUE, NULL, zpool_export_one, &cb); return (ret); } diff --git a/man/man8/zpool.8 b/man/man8/zpool.8 index 00c19305a..74d7461ce 100644 --- a/man/man8/zpool.8 +++ b/man/man8/zpool.8 @@ -57,7 +57,7 @@ zpool \- configures ZFS storage pools .LP .nf -\fBzpool export\fR [\fB-f\fR] \fIpool\fR ... +\fBzpool export\fR [\fB-a\fR] [\fB-f\fR] \fIpool\fR ... .fi .LP @@ -1059,11 +1059,13 @@ Forces any active datasets contained within the pool to be unmounted. Detaches \fIdevice\fR from a mirror. The operation is refused if there are no other valid replicas of the data. If \fIdevice\fR may be re-added to the pool later on then consider the "\fBzpool offline\fR" command instead. .RE +.RE + .sp .ne 2 .mk .na -\fB\fBzpool export\fR [\fB-f\fR] \fIpool\fR ...\fR +\fB\fBzpool export\fR [\fB-a\fR] [\fB-f\fR] \fIpool\fR ...\fR .ad .sp .6 .RS 4n @@ -1076,10 +1078,21 @@ For pools to be portable, you must give the \fBzpool\fR command whole disks, not .ne 2 .mk .na +\fB\fB-a\fR\fR +.ad +.RS 6n +.rt +Exports all pools imported on the system. +.RE + +.sp +.ne 2 +.mk +.na \fB\fB-f\fR\fR .ad .RS 6n -.rt +.rt Forcefully unmount all datasets, using the "\fBunmount -f\fR" command. .sp This command will forcefully export the pool even if it has a shared spare that is currently being used. This may lead to potential data corruption. |