4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25 * Copyright (c) 2012 by Delphix. All rights reserved.
26 * Copyright (c) 2012 by Frederik Wessels. All rights reserved.
27 * Copyright (c) 2012 by Cyril Plisko. All rights reserved.
48 #include <sys/fs/zfs.h>
50 #include <sys/fm/util.h>
51 #include <sys/fm/protocol.h>
55 #include "zpool_util.h"
56 #include "zfs_comutil.h"
57 #include "zfeature_common.h"
59 #include "statcommon.h"
61 static int zpool_do_create(int, char **);
62 static int zpool_do_destroy(int, char **);
64 static int zpool_do_add(int, char **);
65 static int zpool_do_remove(int, char **);
67 static int zpool_do_list(int, char **);
68 static int zpool_do_iostat(int, char **);
69 static int zpool_do_status(int, char **);
71 static int zpool_do_online(int, char **);
72 static int zpool_do_offline(int, char **);
73 static int zpool_do_clear(int, char **);
74 static int zpool_do_reopen(int, char **);
76 static int zpool_do_reguid(int, char **);
78 static int zpool_do_attach(int, char **);
79 static int zpool_do_detach(int, char **);
80 static int zpool_do_replace(int, char **);
81 static int zpool_do_split(int, char **);
83 static int zpool_do_scrub(int, char **);
85 static int zpool_do_import(int, char **);
86 static int zpool_do_export(int, char **);
88 static int zpool_do_upgrade(int, char **);
90 static int zpool_do_history(int, char **);
91 static int zpool_do_events(int, char **);
93 static int zpool_do_get(int, char **);
94 static int zpool_do_set(int, char **);
97 * These libumem hooks provide a reasonable set of defaults for the allocator's
98 * debugging facilities.
103 _umem_debug_init(void)
105 return ("default,verbose"); /* $UMEM_DEBUG setting */
109 _umem_logging_init(void)
111 return ("fail,contents"); /* $UMEM_LOGGING setting */
143 typedef struct zpool_command
{
145 int (*func
)(int, char **);
150 * Master command table. Each ZFS command has a name, associated function, and
151 * usage message. The usage messages need to be internationalized, so we have
152 * to have a function to return the usage message based on a command index.
154 * These commands are organized according to how they are displayed in the usage
155 * message. An empty command (one with a NULL name) indicates an empty line in
156 * the generic usage message.
158 static zpool_command_t command_table
[] = {
159 { "create", zpool_do_create
, HELP_CREATE
},
160 { "destroy", zpool_do_destroy
, HELP_DESTROY
},
162 { "add", zpool_do_add
, HELP_ADD
},
163 { "remove", zpool_do_remove
, HELP_REMOVE
},
165 { "list", zpool_do_list
, HELP_LIST
},
166 { "iostat", zpool_do_iostat
, HELP_IOSTAT
},
167 { "status", zpool_do_status
, HELP_STATUS
},
169 { "online", zpool_do_online
, HELP_ONLINE
},
170 { "offline", zpool_do_offline
, HELP_OFFLINE
},
171 { "clear", zpool_do_clear
, HELP_CLEAR
},
172 { "reopen", zpool_do_reopen
, HELP_REOPEN
},
174 { "attach", zpool_do_attach
, HELP_ATTACH
},
175 { "detach", zpool_do_detach
, HELP_DETACH
},
176 { "replace", zpool_do_replace
, HELP_REPLACE
},
177 { "split", zpool_do_split
, HELP_SPLIT
},
179 { "scrub", zpool_do_scrub
, HELP_SCRUB
},
181 { "import", zpool_do_import
, HELP_IMPORT
},
182 { "export", zpool_do_export
, HELP_EXPORT
},
183 { "upgrade", zpool_do_upgrade
, HELP_UPGRADE
},
184 { "reguid", zpool_do_reguid
, HELP_REGUID
},
186 { "history", zpool_do_history
, HELP_HISTORY
},
187 { "events", zpool_do_events
, HELP_EVENTS
},
189 { "get", zpool_do_get
, HELP_GET
},
190 { "set", zpool_do_set
, HELP_SET
},
193 #define NCOMMAND (sizeof (command_table) / sizeof (command_table[0]))
195 zpool_command_t
*current_command
;
196 static char history_str
[HIS_MAX_RECORD_LEN
];
198 static uint_t timestamp_fmt
= NODATE
;
201 get_usage(zpool_help_t idx
) {
204 return (gettext("\tadd [-fn] [-o property=value] "
205 "<pool> <vdev> ...\n"));
207 return (gettext("\tattach [-f] [-o property=value] "
208 "<pool> <device> <new-device>\n"));
210 return (gettext("\tclear [-nF] <pool> [device]\n"));
212 return (gettext("\tcreate [-fnd] [-o property=value] ... \n"
213 "\t [-O file-system-property=value] ... \n"
214 "\t [-m mountpoint] [-R root] <pool> <vdev> ...\n"));
216 return (gettext("\tdestroy [-f] <pool>\n"));
218 return (gettext("\tdetach <pool> <device>\n"));
220 return (gettext("\texport [-f] <pool> ...\n"));
222 return (gettext("\thistory [-il] [<pool>] ...\n"));
224 return (gettext("\timport [-d dir] [-D]\n"
225 "\timport [-d dir | -c cachefile] [-F [-n]] <pool | id>\n"
226 "\timport [-o mntopts] [-o property=value] ... \n"
227 "\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
228 "[-R root] [-F [-n]] -a\n"
229 "\timport [-o mntopts] [-o property=value] ... \n"
230 "\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
231 "[-R root] [-F [-n]]\n"
232 "\t <pool | id> [newpool]\n"));
234 return (gettext("\tiostat [-v] [-T d|u] [pool] ... [interval "
237 return (gettext("\tlist [-H] [-o property[,...]] "
238 "[-T d|u] [pool] ... [interval [count]]\n"));
240 return (gettext("\toffline [-t] <pool> <device> ...\n"));
242 return (gettext("\tonline <pool> <device> ...\n"));
244 return (gettext("\treplace [-f] <pool> <device> "
247 return (gettext("\tremove <pool> <device> ...\n"));
249 return (""); /* Undocumented command */
251 return (gettext("\tscrub [-s] <pool> ...\n"));
253 return (gettext("\tstatus [-vx] [-T d|u] [pool] ... [interval "
256 return (gettext("\tupgrade\n"
258 "\tupgrade [-V version] <-a | pool ...>\n"));
260 return (gettext("\tevents [-vHfc]\n"));
262 return (gettext("\tget <\"all\" | property[,...]> "
265 return (gettext("\tset <property=value> <pool> \n"));
267 return (gettext("\tsplit [-n] [-R altroot] [-o mntopts]\n"
268 "\t [-o property=value] <pool> <newpool> "
269 "[<device> ...]\n"));
271 return (gettext("\treguid <pool>\n"));
280 * Callback routine that will print out a pool property value.
283 print_prop_cb(int prop
, void *cb
)
287 (void) fprintf(fp
, "\t%-15s ", zpool_prop_to_name(prop
));
289 if (zpool_prop_readonly(prop
))
290 (void) fprintf(fp
, " NO ");
292 (void) fprintf(fp
, " YES ");
294 if (zpool_prop_values(prop
) == NULL
)
295 (void) fprintf(fp
, "-\n");
297 (void) fprintf(fp
, "%s\n", zpool_prop_values(prop
));
303 * Display usage message. If we're inside a command, display only the usage for
304 * that command. Otherwise, iterate over the entire command table and display
305 * a complete usage message.
308 usage(boolean_t requested
)
310 FILE *fp
= requested
? stdout
: stderr
;
312 if (current_command
== NULL
) {
315 (void) fprintf(fp
, gettext("usage: zpool command args ...\n"));
317 gettext("where 'command' is one of the following:\n\n"));
319 for (i
= 0; i
< NCOMMAND
; i
++) {
320 if (command_table
[i
].name
== NULL
)
321 (void) fprintf(fp
, "\n");
323 (void) fprintf(fp
, "%s",
324 get_usage(command_table
[i
].usage
));
327 (void) fprintf(fp
, gettext("usage:\n"));
328 (void) fprintf(fp
, "%s", get_usage(current_command
->usage
));
331 if (current_command
!= NULL
&&
332 ((strcmp(current_command
->name
, "set") == 0) ||
333 (strcmp(current_command
->name
, "get") == 0) ||
334 (strcmp(current_command
->name
, "list") == 0))) {
337 gettext("\nthe following properties are supported:\n"));
339 (void) fprintf(fp
, "\n\t%-15s %s %s\n\n",
340 "PROPERTY", "EDIT", "VALUES");
342 /* Iterate over all properties */
343 (void) zprop_iter(print_prop_cb
, fp
, B_FALSE
, B_TRUE
,
346 (void) fprintf(fp
, "\t%-15s ", "feature@...");
347 (void) fprintf(fp
, "YES disabled | enabled | active\n");
349 (void) fprintf(fp
, gettext("\nThe feature@ properties must be "
350 "appended with a feature name.\nSee zpool-features(5).\n"));
354 * See comments at end of main().
356 if (getenv("ZFS_ABORT") != NULL
) {
357 (void) printf("dumping core by request\n");
361 exit(requested
? 0 : 2);
365 print_vdev_tree(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
, int indent
,
366 boolean_t print_logs
)
373 (void) printf("\t%*s%s\n", indent
, "", name
);
375 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
376 &child
, &children
) != 0)
379 for (c
= 0; c
< children
; c
++) {
380 uint64_t is_log
= B_FALSE
;
382 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
384 if ((is_log
&& !print_logs
) || (!is_log
&& print_logs
))
387 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], B_FALSE
);
388 print_vdev_tree(zhp
, vname
, child
[c
], indent
+ 2,
395 prop_list_contains_feature(nvlist_t
*proplist
)
398 for (nvp
= nvlist_next_nvpair(proplist
, NULL
); NULL
!= nvp
;
399 nvp
= nvlist_next_nvpair(proplist
, nvp
)) {
400 if (zpool_prop_feature(nvpair_name(nvp
)))
407 * Add a property pair (name, string-value) into a property nvlist.
410 add_prop_list(const char *propname
, char *propval
, nvlist_t
**props
,
413 zpool_prop_t prop
= ZPROP_INVAL
;
419 if (*props
== NULL
&&
420 nvlist_alloc(props
, NV_UNIQUE_NAME
, 0) != 0) {
421 (void) fprintf(stderr
,
422 gettext("internal error: out of memory\n"));
429 const char *vname
= zpool_prop_to_name(ZPOOL_PROP_VERSION
);
431 if ((prop
= zpool_name_to_prop(propname
)) == ZPROP_INVAL
&&
432 !zpool_prop_feature(propname
)) {
433 (void) fprintf(stderr
, gettext("property '%s' is "
434 "not a valid pool property\n"), propname
);
439 * feature@ properties and version should not be specified
442 if ((prop
== ZPROP_INVAL
&& zpool_prop_feature(propname
) &&
443 nvlist_exists(proplist
, vname
)) ||
444 (prop
== ZPOOL_PROP_VERSION
&&
445 prop_list_contains_feature(proplist
))) {
446 (void) fprintf(stderr
, gettext("'feature@' and "
447 "'version' properties cannot be specified "
453 if (zpool_prop_feature(propname
))
456 normnm
= zpool_prop_to_name(prop
);
458 if ((fprop
= zfs_name_to_prop(propname
)) != ZPROP_INVAL
) {
459 normnm
= zfs_prop_to_name(fprop
);
465 if (nvlist_lookup_string(proplist
, normnm
, &strval
) == 0 &&
466 prop
!= ZPOOL_PROP_CACHEFILE
) {
467 (void) fprintf(stderr
, gettext("property '%s' "
468 "specified multiple times\n"), propname
);
472 if (nvlist_add_string(proplist
, normnm
, propval
) != 0) {
473 (void) fprintf(stderr
, gettext("internal "
474 "error: out of memory\n"));
482 * zpool add [-fn] [-o property=value] <pool> <vdev> ...
484 * -f Force addition of devices, even if they appear in use
485 * -n Do not add the devices, but display the resulting layout if
486 * they were to be added.
487 * -o Set property=value.
489 * Adds the given vdevs to 'pool'. As with create, the bulk of this work is
490 * handled by get_vdev_spec(), which constructs the nvlist needed to pass to
494 zpool_do_add(int argc
, char **argv
)
496 boolean_t force
= B_FALSE
;
497 boolean_t dryrun
= B_FALSE
;
504 nvlist_t
*props
= NULL
;
508 while ((c
= getopt(argc
, argv
, "fno:")) != -1) {
517 if ((propval
= strchr(optarg
, '=')) == NULL
) {
518 (void) fprintf(stderr
, gettext("missing "
519 "'=' for -o option\n"));
525 if ((strcmp(optarg
, ZPOOL_CONFIG_ASHIFT
) != 0) ||
526 (add_prop_list(optarg
, propval
, &props
, B_TRUE
)))
530 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
539 /* get pool name and check number of arguments */
541 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
545 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
554 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
557 if ((config
= zpool_get_config(zhp
, NULL
)) == NULL
) {
558 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
564 /* pass off to get_vdev_spec for processing */
565 nvroot
= make_root_vdev(zhp
, props
, force
, !force
, B_FALSE
, dryrun
,
567 if (nvroot
== NULL
) {
573 nvlist_t
*poolnvroot
;
575 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
578 (void) printf(gettext("would update '%s' to the following "
579 "configuration:\n"), zpool_get_name(zhp
));
581 /* print original main pool and new tree */
582 print_vdev_tree(zhp
, poolname
, poolnvroot
, 0, B_FALSE
);
583 print_vdev_tree(zhp
, NULL
, nvroot
, 0, B_FALSE
);
585 /* Do the same for the logs */
586 if (num_logs(poolnvroot
) > 0) {
587 print_vdev_tree(zhp
, "logs", poolnvroot
, 0, B_TRUE
);
588 print_vdev_tree(zhp
, NULL
, nvroot
, 0, B_TRUE
);
589 } else if (num_logs(nvroot
) > 0) {
590 print_vdev_tree(zhp
, "logs", nvroot
, 0, B_TRUE
);
595 ret
= (zpool_add(zhp
, nvroot
) != 0);
606 * zpool remove <pool> <vdev> ...
608 * Removes the given vdev from the pool. Currently, this supports removing
609 * spares, cache, and log devices from the pool.
612 zpool_do_remove(int argc
, char **argv
)
621 /* get pool name and check number of arguments */
623 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
627 (void) fprintf(stderr
, gettext("missing device\n"));
633 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
636 for (i
= 1; i
< argc
; i
++) {
637 if (zpool_vdev_remove(zhp
, argv
[i
]) != 0)
645 * zpool create [-fnd] [-o property=value] ...
646 * [-O file-system-property=value] ...
647 * [-R root] [-m mountpoint] <pool> <dev> ...
649 * -f Force creation, even if devices appear in use
650 * -n Do not create the pool, but display the resulting layout if it
651 * were to be created.
652 * -R Create a pool under an alternate root
653 * -m Set default mountpoint for the root dataset. By default it's
655 * -o Set property=value.
656 * -d Don't automatically enable all supported pool features
657 * (individual features can be enabled with -o).
658 * -O Set fsproperty=value in the pool's root file system
660 * Creates the named pool according to the given vdev specification. The
661 * bulk of the vdev processing is done in get_vdev_spec() in zpool_vdev.c. Once
662 * we get the nvlist back from get_vdev_spec(), we either print out the contents
663 * (if '-n' was specified), or pass it to libzfs to do the creation.
666 zpool_do_create(int argc
, char **argv
)
668 boolean_t force
= B_FALSE
;
669 boolean_t dryrun
= B_FALSE
;
670 boolean_t enable_all_pool_feat
= B_TRUE
;
672 nvlist_t
*nvroot
= NULL
;
675 char *altroot
= NULL
;
676 char *mountpoint
= NULL
;
677 nvlist_t
*fsprops
= NULL
;
678 nvlist_t
*props
= NULL
;
682 while ((c
= getopt(argc
, argv
, ":fndR:m:o:O:")) != -1) {
691 enable_all_pool_feat
= B_FALSE
;
695 if (add_prop_list(zpool_prop_to_name(
696 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
698 if (nvlist_lookup_string(props
,
699 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
),
702 if (add_prop_list(zpool_prop_to_name(
703 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
710 if ((propval
= strchr(optarg
, '=')) == NULL
) {
711 (void) fprintf(stderr
, gettext("missing "
712 "'=' for -o option\n"));
718 if (add_prop_list(optarg
, propval
, &props
, B_TRUE
))
722 * If the user is creating a pool that doesn't support
723 * feature flags, don't enable any features.
725 if (zpool_name_to_prop(optarg
) == ZPOOL_PROP_VERSION
) {
729 ver
= strtoull(propval
, &end
, 10);
731 ver
< SPA_VERSION_FEATURES
) {
732 enable_all_pool_feat
= B_FALSE
;
737 if ((propval
= strchr(optarg
, '=')) == NULL
) {
738 (void) fprintf(stderr
, gettext("missing "
739 "'=' for -O option\n"));
745 if (add_prop_list(optarg
, propval
, &fsprops
, B_FALSE
))
749 (void) fprintf(stderr
, gettext("missing argument for "
750 "'%c' option\n"), optopt
);
753 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
762 /* get pool name and check number of arguments */
764 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
768 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
775 * As a special case, check for use of '/' in the name, and direct the
776 * user to use 'zfs create' instead.
778 if (strchr(poolname
, '/') != NULL
) {
779 (void) fprintf(stderr
, gettext("cannot create '%s': invalid "
780 "character '/' in pool name\n"), poolname
);
781 (void) fprintf(stderr
, gettext("use 'zfs create' to "
782 "create a dataset\n"));
786 /* pass off to get_vdev_spec for bulk processing */
787 nvroot
= make_root_vdev(NULL
, props
, force
, !force
, B_FALSE
, dryrun
,
792 /* make_root_vdev() allows 0 toplevel children if there are spares */
793 if (!zfs_allocatable_devs(nvroot
)) {
794 (void) fprintf(stderr
, gettext("invalid vdev "
795 "specification: at least one toplevel vdev must be "
800 if (altroot
!= NULL
&& altroot
[0] != '/') {
801 (void) fprintf(stderr
, gettext("invalid alternate root '%s': "
802 "must be an absolute path\n"), altroot
);
807 * Check the validity of the mountpoint and direct the user to use the
808 * '-m' mountpoint option if it looks like its in use.
810 if (mountpoint
== NULL
||
811 (strcmp(mountpoint
, ZFS_MOUNTPOINT_LEGACY
) != 0 &&
812 strcmp(mountpoint
, ZFS_MOUNTPOINT_NONE
) != 0)) {
813 char buf
[MAXPATHLEN
];
816 if (mountpoint
&& mountpoint
[0] != '/') {
817 (void) fprintf(stderr
, gettext("invalid mountpoint "
818 "'%s': must be an absolute path, 'legacy', or "
819 "'none'\n"), mountpoint
);
823 if (mountpoint
== NULL
) {
825 (void) snprintf(buf
, sizeof (buf
), "%s/%s",
828 (void) snprintf(buf
, sizeof (buf
), "/%s",
832 (void) snprintf(buf
, sizeof (buf
), "%s%s",
833 altroot
, mountpoint
);
835 (void) snprintf(buf
, sizeof (buf
), "%s",
839 if ((dirp
= opendir(buf
)) == NULL
&& errno
!= ENOENT
) {
840 (void) fprintf(stderr
, gettext("mountpoint '%s' : "
841 "%s\n"), buf
, strerror(errno
));
842 (void) fprintf(stderr
, gettext("use '-m' "
843 "option to provide a different default\n"));
848 while (count
< 3 && readdir(dirp
) != NULL
)
850 (void) closedir(dirp
);
853 (void) fprintf(stderr
, gettext("mountpoint "
854 "'%s' exists and is not empty\n"), buf
);
855 (void) fprintf(stderr
, gettext("use '-m' "
856 "option to provide a "
857 "different default\n"));
865 * For a dry run invocation, print out a basic message and run
866 * through all the vdevs in the list and print out in an
867 * appropriate hierarchy.
869 (void) printf(gettext("would create '%s' with the "
870 "following layout:\n\n"), poolname
);
872 print_vdev_tree(NULL
, poolname
, nvroot
, 0, B_FALSE
);
873 if (num_logs(nvroot
) > 0)
874 print_vdev_tree(NULL
, "logs", nvroot
, 0, B_TRUE
);
879 * Hand off to libzfs.
881 if (enable_all_pool_feat
) {
883 for (i
= 0; i
< SPA_FEATURES
; i
++) {
884 char propname
[MAXPATHLEN
];
885 zfeature_info_t
*feat
= &spa_feature_table
[i
];
887 (void) snprintf(propname
, sizeof (propname
),
888 "feature@%s", feat
->fi_uname
);
891 * Skip feature if user specified it manually
892 * on the command line.
894 if (nvlist_exists(props
, propname
))
897 if (add_prop_list(propname
, ZFS_FEATURE_ENABLED
,
898 &props
, B_TRUE
) != 0)
902 if (zpool_create(g_zfs
, poolname
,
903 nvroot
, props
, fsprops
) == 0) {
904 zfs_handle_t
*pool
= zfs_open(g_zfs
, poolname
,
905 ZFS_TYPE_FILESYSTEM
);
907 if (mountpoint
!= NULL
)
908 verify(zfs_prop_set(pool
,
910 ZFS_PROP_MOUNTPOINT
),
912 if (zfs_mount(pool
, NULL
, 0) == 0)
913 ret
= zfs_shareall(pool
);
916 } else if (libzfs_errno(g_zfs
) == EZFS_INVALIDNAME
) {
917 (void) fprintf(stderr
, gettext("pool name may have "
924 nvlist_free(fsprops
);
928 nvlist_free(fsprops
);
935 * zpool destroy <pool>
937 * -f Forcefully unmount any datasets
939 * Destroy the given pool. Automatically unmounts any datasets in the pool.
942 zpool_do_destroy(int argc
, char **argv
)
944 boolean_t force
= B_FALSE
;
951 while ((c
= getopt(argc
, argv
, "f")) != -1) {
957 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
966 /* check arguments */
968 (void) fprintf(stderr
, gettext("missing pool argument\n"));
972 (void) fprintf(stderr
, gettext("too many arguments\n"));
978 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
) {
980 * As a special case, check for use of '/' in the name, and
981 * direct the user to use 'zfs destroy' instead.
983 if (strchr(pool
, '/') != NULL
)
984 (void) fprintf(stderr
, gettext("use 'zfs destroy' to "
985 "destroy a dataset\n"));
989 if (zpool_disable_datasets(zhp
, force
) != 0) {
990 (void) fprintf(stderr
, gettext("could not destroy '%s': "
991 "could not unmount datasets\n"), zpool_get_name(zhp
));
995 ret
= (zpool_destroy(zhp
) != 0);
1003 * zpool export [-f] <pool> ...
1005 * -f Forcefully unmount datasets
1007 * Export the given pools. By default, the command will attempt to cleanly
1008 * unmount any active datasets within the pool. If the '-f' flag is specified,
1009 * then the datasets will be forcefully unmounted.
1012 zpool_do_export(int argc
, char **argv
)
1014 boolean_t force
= B_FALSE
;
1015 boolean_t hardforce
= B_FALSE
;
1017 zpool_handle_t
*zhp
;
1022 while ((c
= getopt(argc
, argv
, "fF")) != -1) {
1031 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1040 /* check arguments */
1042 (void) fprintf(stderr
, gettext("missing pool argument\n"));
1047 for (i
= 0; i
< argc
; i
++) {
1048 if ((zhp
= zpool_open_canfail(g_zfs
, argv
[i
])) == NULL
) {
1053 if (zpool_disable_datasets(zhp
, force
) != 0) {
1060 if (zpool_export_force(zhp
) != 0)
1062 } else if (zpool_export(zhp
, force
) != 0) {
1073 * Given a vdev configuration, determine the maximum width needed for the device
1077 max_width(zpool_handle_t
*zhp
, nvlist_t
*nv
, int depth
, int max
)
1079 char *name
= zpool_vdev_name(g_zfs
, zhp
, nv
, B_TRUE
);
1084 if (strlen(name
) + depth
> max
)
1085 max
= strlen(name
) + depth
;
1089 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
1090 &child
, &children
) == 0) {
1091 for (c
= 0; c
< children
; c
++)
1092 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1097 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
1098 &child
, &children
) == 0) {
1099 for (c
= 0; c
< children
; c
++)
1100 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1105 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1106 &child
, &children
) == 0) {
1107 for (c
= 0; c
< children
; c
++)
1108 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1117 typedef struct spare_cbdata
{
1119 zpool_handle_t
*cb_zhp
;
1123 find_vdev(nvlist_t
*nv
, uint64_t search
)
1129 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
, &guid
) == 0 &&
1133 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1134 &child
, &children
) == 0) {
1135 for (c
= 0; c
< children
; c
++)
1136 if (find_vdev(child
[c
], search
))
1144 find_spare(zpool_handle_t
*zhp
, void *data
)
1146 spare_cbdata_t
*cbp
= data
;
1147 nvlist_t
*config
, *nvroot
;
1149 config
= zpool_get_config(zhp
, NULL
);
1150 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
1153 if (find_vdev(nvroot
, cbp
->cb_guid
)) {
1163 * Print out configuration state as requested by status_callback.
1166 print_status_config(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
,
1167 int namewidth
, int depth
, boolean_t isspare
)
1171 pool_scan_stat_t
*ps
= NULL
;
1173 char rbuf
[6], wbuf
[6], cbuf
[6];
1175 uint64_t notpresent
;
1179 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1180 &child
, &children
) != 0)
1183 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
1184 (uint64_t **)&vs
, &c
) == 0);
1186 state
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
1189 * For hot spares, we use the terms 'INUSE' and 'AVAILABLE' for
1192 if (vs
->vs_aux
== VDEV_AUX_SPARED
)
1194 else if (vs
->vs_state
== VDEV_STATE_HEALTHY
)
1198 (void) printf("\t%*s%-*s %-8s", depth
, "", namewidth
- depth
,
1202 zfs_nicenum(vs
->vs_read_errors
, rbuf
, sizeof (rbuf
));
1203 zfs_nicenum(vs
->vs_write_errors
, wbuf
, sizeof (wbuf
));
1204 zfs_nicenum(vs
->vs_checksum_errors
, cbuf
, sizeof (cbuf
));
1205 (void) printf(" %5s %5s %5s", rbuf
, wbuf
, cbuf
);
1208 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_NOT_PRESENT
,
1209 ¬present
) == 0) {
1211 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_PATH
, &path
) == 0);
1212 (void) printf(" was %s", path
);
1213 } else if (vs
->vs_aux
!= 0) {
1216 switch (vs
->vs_aux
) {
1217 case VDEV_AUX_OPEN_FAILED
:
1218 (void) printf(gettext("cannot open"));
1221 case VDEV_AUX_BAD_GUID_SUM
:
1222 (void) printf(gettext("missing device"));
1225 case VDEV_AUX_NO_REPLICAS
:
1226 (void) printf(gettext("insufficient replicas"));
1229 case VDEV_AUX_VERSION_NEWER
:
1230 (void) printf(gettext("newer version"));
1233 case VDEV_AUX_UNSUP_FEAT
:
1234 (void) printf(gettext("unsupported feature(s)"));
1237 case VDEV_AUX_SPARED
:
1238 verify(nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
,
1240 if (zpool_iter(g_zfs
, find_spare
, &cb
) == 1) {
1241 if (strcmp(zpool_get_name(cb
.cb_zhp
),
1242 zpool_get_name(zhp
)) == 0)
1243 (void) printf(gettext("currently in "
1246 (void) printf(gettext("in use by "
1248 zpool_get_name(cb
.cb_zhp
));
1249 zpool_close(cb
.cb_zhp
);
1251 (void) printf(gettext("currently in use"));
1255 case VDEV_AUX_ERR_EXCEEDED
:
1256 (void) printf(gettext("too many errors"));
1259 case VDEV_AUX_IO_FAILURE
:
1260 (void) printf(gettext("experienced I/O failures"));
1263 case VDEV_AUX_BAD_LOG
:
1264 (void) printf(gettext("bad intent log"));
1267 case VDEV_AUX_EXTERNAL
:
1268 (void) printf(gettext("external device fault"));
1271 case VDEV_AUX_SPLIT_POOL
:
1272 (void) printf(gettext("split into new pool"));
1276 (void) printf(gettext("corrupted data"));
1281 (void) nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_SCAN_STATS
,
1282 (uint64_t **)&ps
, &c
);
1284 if (ps
&& ps
->pss_state
== DSS_SCANNING
&&
1285 vs
->vs_scan_processed
!= 0 && children
== 0) {
1286 (void) printf(gettext(" (%s)"),
1287 (ps
->pss_func
== POOL_SCAN_RESILVER
) ?
1288 "resilvering" : "repairing");
1291 (void) printf("\n");
1293 for (c
= 0; c
< children
; c
++) {
1294 uint64_t islog
= B_FALSE
, ishole
= B_FALSE
;
1296 /* Don't print logs or holes here */
1297 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1299 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_HOLE
,
1301 if (islog
|| ishole
)
1303 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], B_TRUE
);
1304 print_status_config(zhp
, vname
, child
[c
],
1305 namewidth
, depth
+ 2, isspare
);
1312 * Print the configuration of an exported pool. Iterate over all vdevs in the
1313 * pool, printing out the name and status for each one.
1316 print_import_config(const char *name
, nvlist_t
*nv
, int namewidth
, int depth
)
1323 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_TYPE
, &type
) == 0);
1324 if (strcmp(type
, VDEV_TYPE_MISSING
) == 0 ||
1325 strcmp(type
, VDEV_TYPE_HOLE
) == 0)
1328 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
1329 (uint64_t **)&vs
, &c
) == 0);
1331 (void) printf("\t%*s%-*s", depth
, "", namewidth
- depth
, name
);
1332 (void) printf(" %s", zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
));
1334 if (vs
->vs_aux
!= 0) {
1337 switch (vs
->vs_aux
) {
1338 case VDEV_AUX_OPEN_FAILED
:
1339 (void) printf(gettext("cannot open"));
1342 case VDEV_AUX_BAD_GUID_SUM
:
1343 (void) printf(gettext("missing device"));
1346 case VDEV_AUX_NO_REPLICAS
:
1347 (void) printf(gettext("insufficient replicas"));
1350 case VDEV_AUX_VERSION_NEWER
:
1351 (void) printf(gettext("newer version"));
1354 case VDEV_AUX_UNSUP_FEAT
:
1355 (void) printf(gettext("unsupported feature(s)"));
1358 case VDEV_AUX_ERR_EXCEEDED
:
1359 (void) printf(gettext("too many errors"));
1363 (void) printf(gettext("corrupted data"));
1367 (void) printf("\n");
1369 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1370 &child
, &children
) != 0)
1373 for (c
= 0; c
< children
; c
++) {
1374 uint64_t is_log
= B_FALSE
;
1376 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1381 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
], B_TRUE
);
1382 print_import_config(vname
, child
[c
], namewidth
, depth
+ 2);
1386 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
1387 &child
, &children
) == 0) {
1388 (void) printf(gettext("\tcache\n"));
1389 for (c
= 0; c
< children
; c
++) {
1390 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
], B_FALSE
);
1391 (void) printf("\t %s\n", vname
);
1396 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
1397 &child
, &children
) == 0) {
1398 (void) printf(gettext("\tspares\n"));
1399 for (c
= 0; c
< children
; c
++) {
1400 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
], B_FALSE
);
1401 (void) printf("\t %s\n", vname
);
1409 * Logs are recorded as top level vdevs in the main pool child array
1410 * but with "is_log" set to 1. We use either print_status_config() or
1411 * print_import_config() to print the top level logs then any log
1412 * children (eg mirrored slogs) are printed recursively - which
1413 * works because only the top level vdev is marked "is_log"
1416 print_logs(zpool_handle_t
*zhp
, nvlist_t
*nv
, int namewidth
, boolean_t verbose
)
1421 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
, &child
,
1425 (void) printf(gettext("\tlogs\n"));
1427 for (c
= 0; c
< children
; c
++) {
1428 uint64_t is_log
= B_FALSE
;
1431 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1435 name
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], B_TRUE
);
1437 print_status_config(zhp
, name
, child
[c
], namewidth
,
1440 print_import_config(name
, child
[c
], namewidth
, 2);
1446 * Display the status for the given pool.
1449 show_import(nvlist_t
*config
)
1451 uint64_t pool_state
;
1463 verify(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
1465 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
,
1467 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
1469 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
1472 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_VDEV_STATS
,
1473 (uint64_t **)&vs
, &vsc
) == 0);
1474 health
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
1476 reason
= zpool_import_status(config
, &msgid
);
1478 (void) printf(gettext(" pool: %s\n"), name
);
1479 (void) printf(gettext(" id: %llu\n"), (u_longlong_t
)guid
);
1480 (void) printf(gettext(" state: %s"), health
);
1481 if (pool_state
== POOL_STATE_DESTROYED
)
1482 (void) printf(gettext(" (DESTROYED)"));
1483 (void) printf("\n");
1486 case ZPOOL_STATUS_MISSING_DEV_R
:
1487 case ZPOOL_STATUS_MISSING_DEV_NR
:
1488 case ZPOOL_STATUS_BAD_GUID_SUM
:
1489 (void) printf(gettext(" status: One or more devices are "
1490 "missing from the system.\n"));
1493 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
1494 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
1495 (void) printf(gettext(" status: One or more devices contains "
1496 "corrupted data.\n"));
1499 case ZPOOL_STATUS_CORRUPT_DATA
:
1501 gettext(" status: The pool data is corrupted.\n"));
1504 case ZPOOL_STATUS_OFFLINE_DEV
:
1505 (void) printf(gettext(" status: One or more devices "
1506 "are offlined.\n"));
1509 case ZPOOL_STATUS_CORRUPT_POOL
:
1510 (void) printf(gettext(" status: The pool metadata is "
1514 case ZPOOL_STATUS_VERSION_OLDER
:
1515 (void) printf(gettext(" status: The pool is formatted using a "
1516 "legacy on-disk version.\n"));
1519 case ZPOOL_STATUS_VERSION_NEWER
:
1520 (void) printf(gettext(" status: The pool is formatted using an "
1521 "incompatible version.\n"));
1524 case ZPOOL_STATUS_FEAT_DISABLED
:
1525 (void) printf(gettext(" status: Some supported features are "
1526 "not enabled on the pool.\n"));
1529 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
1530 (void) printf(gettext("status: The pool uses the following "
1531 "feature(s) not supported on this sytem:\n"));
1532 zpool_print_unsup_feat(config
);
1535 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
1536 (void) printf(gettext("status: The pool can only be accessed "
1537 "in read-only mode on this system. It\n\tcannot be "
1538 "accessed in read-write mode because it uses the "
1539 "following\n\tfeature(s) not supported on this system:\n"));
1540 zpool_print_unsup_feat(config
);
1543 case ZPOOL_STATUS_HOSTID_MISMATCH
:
1544 (void) printf(gettext(" status: The pool was last accessed by "
1545 "another system.\n"));
1548 case ZPOOL_STATUS_FAULTED_DEV_R
:
1549 case ZPOOL_STATUS_FAULTED_DEV_NR
:
1550 (void) printf(gettext(" status: One or more devices are "
1554 case ZPOOL_STATUS_BAD_LOG
:
1555 (void) printf(gettext(" status: An intent log record cannot be "
1559 case ZPOOL_STATUS_RESILVERING
:
1560 (void) printf(gettext(" status: One or more devices were being "
1566 * No other status can be seen when importing pools.
1568 assert(reason
== ZPOOL_STATUS_OK
);
1572 * Print out an action according to the overall state of the pool.
1574 if (vs
->vs_state
== VDEV_STATE_HEALTHY
) {
1575 if (reason
== ZPOOL_STATUS_VERSION_OLDER
||
1576 reason
== ZPOOL_STATUS_FEAT_DISABLED
) {
1577 (void) printf(gettext(" action: The pool can be "
1578 "imported using its name or numeric identifier, "
1579 "though\n\tsome features will not be available "
1580 "without an explicit 'zpool upgrade'.\n"));
1581 } else if (reason
== ZPOOL_STATUS_HOSTID_MISMATCH
) {
1582 (void) printf(gettext(" action: The pool can be "
1583 "imported using its name or numeric "
1584 "identifier and\n\tthe '-f' flag.\n"));
1586 (void) printf(gettext(" action: The pool can be "
1587 "imported using its name or numeric "
1590 } else if (vs
->vs_state
== VDEV_STATE_DEGRADED
) {
1591 (void) printf(gettext(" action: The pool can be imported "
1592 "despite missing or damaged devices. The\n\tfault "
1593 "tolerance of the pool may be compromised if imported.\n"));
1596 case ZPOOL_STATUS_VERSION_NEWER
:
1597 (void) printf(gettext(" action: The pool cannot be "
1598 "imported. Access the pool on a system running "
1599 "newer\n\tsoftware, or recreate the pool from "
1602 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
1603 (void) printf(gettext("action: The pool cannot be "
1604 "imported. Access the pool on a system that "
1605 "supports\n\tthe required feature(s), or recreate "
1606 "the pool from backup.\n"));
1608 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
1609 (void) printf(gettext("action: The pool cannot be "
1610 "imported in read-write mode. Import the pool "
1612 "\t\"-o readonly=on\", access the pool on a system "
1613 "that supports the\n\trequired feature(s), or "
1614 "recreate the pool from backup.\n"));
1616 case ZPOOL_STATUS_MISSING_DEV_R
:
1617 case ZPOOL_STATUS_MISSING_DEV_NR
:
1618 case ZPOOL_STATUS_BAD_GUID_SUM
:
1619 (void) printf(gettext(" action: The pool cannot be "
1620 "imported. Attach the missing\n\tdevices and try "
1624 (void) printf(gettext(" action: The pool cannot be "
1625 "imported due to damaged devices or data.\n"));
1629 /* Print the comment attached to the pool. */
1630 if (nvlist_lookup_string(config
, ZPOOL_CONFIG_COMMENT
, &comment
) == 0)
1631 (void) printf(gettext("comment: %s\n"), comment
);
1634 * If the state is "closed" or "can't open", and the aux state
1635 * is "corrupt data":
1637 if (((vs
->vs_state
== VDEV_STATE_CLOSED
) ||
1638 (vs
->vs_state
== VDEV_STATE_CANT_OPEN
)) &&
1639 (vs
->vs_aux
== VDEV_AUX_CORRUPT_DATA
)) {
1640 if (pool_state
== POOL_STATE_DESTROYED
)
1641 (void) printf(gettext("\tThe pool was destroyed, "
1642 "but can be imported using the '-Df' flags.\n"));
1643 else if (pool_state
!= POOL_STATE_EXPORTED
)
1644 (void) printf(gettext("\tThe pool may be active on "
1645 "another system, but can be imported using\n\t"
1646 "the '-f' flag.\n"));
1650 (void) printf(gettext(" see: http://zfsonlinux.org/msg/%s\n"),
1653 (void) printf(gettext(" config:\n\n"));
1655 namewidth
= max_width(NULL
, nvroot
, 0, 0);
1659 print_import_config(name
, nvroot
, namewidth
, 0);
1660 if (num_logs(nvroot
) > 0)
1661 print_logs(NULL
, nvroot
, namewidth
, B_FALSE
);
1663 if (reason
== ZPOOL_STATUS_BAD_GUID_SUM
) {
1664 (void) printf(gettext("\n\tAdditional devices are known to "
1665 "be part of this pool, though their\n\texact "
1666 "configuration cannot be determined.\n"));
1671 * Perform the import for the given configuration. This passes the heavy
1672 * lifting off to zpool_import_props(), and then mounts the datasets contained
1676 do_import(nvlist_t
*config
, const char *newname
, const char *mntopts
,
1677 nvlist_t
*props
, int flags
)
1679 zpool_handle_t
*zhp
;
1684 verify(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
1687 verify(nvlist_lookup_uint64(config
,
1688 ZPOOL_CONFIG_POOL_STATE
, &state
) == 0);
1689 verify(nvlist_lookup_uint64(config
,
1690 ZPOOL_CONFIG_VERSION
, &version
) == 0);
1691 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
1692 (void) fprintf(stderr
, gettext("cannot import '%s': pool "
1693 "is formatted using an unsupported ZFS version\n"), name
);
1695 } else if (state
!= POOL_STATE_EXPORTED
&&
1696 !(flags
& ZFS_IMPORT_ANY_HOST
)) {
1699 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_HOSTID
,
1701 unsigned long system_hostid
= gethostid() & 0xffffffff;
1703 if ((unsigned long)hostid
!= system_hostid
) {
1708 verify(nvlist_lookup_string(config
,
1709 ZPOOL_CONFIG_HOSTNAME
, &hostname
) == 0);
1710 verify(nvlist_lookup_uint64(config
,
1711 ZPOOL_CONFIG_TIMESTAMP
, ×tamp
) == 0);
1713 (void) fprintf(stderr
, gettext("cannot import "
1714 "'%s': pool may be in use from other "
1715 "system, it was last accessed by %s "
1716 "(hostid: 0x%lx) on %s"), name
, hostname
,
1717 (unsigned long)hostid
,
1718 asctime(localtime(&t
)));
1719 (void) fprintf(stderr
, gettext("use '-f' to "
1720 "import anyway\n"));
1724 (void) fprintf(stderr
, gettext("cannot import '%s': "
1725 "pool may be in use from other system\n"), name
);
1726 (void) fprintf(stderr
, gettext("use '-f' to import "
1732 if (zpool_import_props(g_zfs
, config
, newname
, props
, flags
) != 0)
1735 if (newname
!= NULL
)
1736 name
= (char *)newname
;
1738 if ((zhp
= zpool_open_canfail(g_zfs
, name
)) == NULL
)
1741 if (zpool_get_state(zhp
) != POOL_STATE_UNAVAIL
&&
1742 !(flags
& ZFS_IMPORT_ONLY
) &&
1743 zpool_enable_datasets(zhp
, mntopts
, 0) != 0) {
1753 * zpool import [-d dir] [-D]
1754 * import [-o mntopts] [-o prop=value] ... [-R root] [-D]
1755 * [-d dir | -c cachefile] [-f] -a
1756 * import [-o mntopts] [-o prop=value] ... [-R root] [-D]
1757 * [-d dir | -c cachefile] [-f] [-n] [-F] <pool | id> [newpool]
1759 * -c Read pool information from a cachefile instead of searching
1762 * -d Scan in a specific directory, other than /dev/. More than
1763 * one directory can be specified using multiple '-d' options.
1765 * -D Scan for previously destroyed pools or import all or only
1766 * specified destroyed pools.
1768 * -R Temporarily import the pool, with all mountpoints relative to
1769 * the given root. The pool will remain exported when the machine
1772 * -V Import even in the presence of faulted vdevs. This is an
1773 * intentionally undocumented option for testing purposes, and
1774 * treats the pool configuration as complete, leaving any bad
1775 * vdevs in the FAULTED state. In other words, it does verbatim
1778 * -f Force import, even if it appears that the pool is active.
1780 * -F Attempt rewind if necessary.
1782 * -n See if rewind would work, but don't actually rewind.
1784 * -N Import the pool but don't mount datasets.
1786 * -T Specify a starting txg to use for import. This option is
1787 * intentionally undocumented option for testing purposes.
1789 * -a Import all pools found.
1791 * -o Set property=value and/or temporary mount options (without '=').
1793 * The import command scans for pools to import, and import pools based on pool
1794 * name and GUID. The pool can also be renamed as part of the import process.
1797 zpool_do_import(int argc
, char **argv
)
1799 char **searchdirs
= NULL
;
1800 char *env
, *envdup
= NULL
;
1804 nvlist_t
*pools
= NULL
;
1805 boolean_t do_all
= B_FALSE
;
1806 boolean_t do_destroyed
= B_FALSE
;
1807 char *mntopts
= NULL
;
1810 uint64_t searchguid
= 0;
1811 char *searchname
= NULL
;
1813 nvlist_t
*found_config
;
1814 nvlist_t
*policy
= NULL
;
1815 nvlist_t
*props
= NULL
;
1817 int flags
= ZFS_IMPORT_NORMAL
;
1818 uint32_t rewind_policy
= ZPOOL_NO_REWIND
;
1819 boolean_t dryrun
= B_FALSE
;
1820 boolean_t do_rewind
= B_FALSE
;
1821 boolean_t xtreme_rewind
= B_FALSE
;
1822 uint64_t pool_state
, txg
= -1ULL;
1823 char *cachefile
= NULL
;
1824 importargs_t idata
= { 0 };
1828 while ((c
= getopt(argc
, argv
, ":aCc:d:DEfFmnNo:rR:T:VX")) != -1) {
1837 if (searchdirs
== NULL
) {
1838 searchdirs
= safe_malloc(sizeof (char *));
1840 char **tmp
= safe_malloc((nsearch
+ 1) *
1842 bcopy(searchdirs
, tmp
, nsearch
*
1847 searchdirs
[nsearch
++] = optarg
;
1850 do_destroyed
= B_TRUE
;
1853 flags
|= ZFS_IMPORT_ANY_HOST
;
1859 flags
|= ZFS_IMPORT_MISSING_LOG
;
1865 flags
|= ZFS_IMPORT_ONLY
;
1868 if ((propval
= strchr(optarg
, '=')) != NULL
) {
1871 if (add_prop_list(optarg
, propval
,
1879 if (add_prop_list(zpool_prop_to_name(
1880 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
1882 if (nvlist_lookup_string(props
,
1883 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
),
1886 if (add_prop_list(zpool_prop_to_name(
1887 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
1892 txg
= strtoull(optarg
, &endptr
, 10);
1893 if (errno
!= 0 || *endptr
!= '\0') {
1894 (void) fprintf(stderr
,
1895 gettext("invalid txg value\n"));
1898 rewind_policy
= ZPOOL_DO_REWIND
| ZPOOL_EXTREME_REWIND
;
1901 flags
|= ZFS_IMPORT_VERBATIM
;
1904 xtreme_rewind
= B_TRUE
;
1907 (void) fprintf(stderr
, gettext("missing argument for "
1908 "'%c' option\n"), optopt
);
1912 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1921 if (cachefile
&& nsearch
!= 0) {
1922 (void) fprintf(stderr
, gettext("-c is incompatible with -d\n"));
1926 if ((dryrun
|| xtreme_rewind
) && !do_rewind
) {
1927 (void) fprintf(stderr
,
1928 gettext("-n or -X only meaningful with -F\n"));
1932 rewind_policy
= ZPOOL_TRY_REWIND
;
1934 rewind_policy
= ZPOOL_DO_REWIND
;
1936 rewind_policy
|= ZPOOL_EXTREME_REWIND
;
1938 /* In the future, we can capture further policy and include it here */
1939 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME
, 0) != 0 ||
1940 nvlist_add_uint64(policy
, ZPOOL_REWIND_REQUEST_TXG
, txg
) != 0 ||
1941 nvlist_add_uint32(policy
, ZPOOL_REWIND_REQUEST
, rewind_policy
) != 0)
1944 /* check argument count */
1947 (void) fprintf(stderr
, gettext("too many arguments\n"));
1952 (void) fprintf(stderr
, gettext("too many arguments\n"));
1957 * Check for the SYS_CONFIG privilege. We do this explicitly
1958 * here because otherwise any attempt to discover pools will
1961 if (argc
== 0 && !priv_ineffect(PRIV_SYS_CONFIG
)) {
1962 (void) fprintf(stderr
, gettext("cannot "
1963 "discover pools: permission denied\n"));
1964 if (searchdirs
!= NULL
)
1967 nvlist_free(policy
);
1973 * Depending on the arguments given, we do one of the following:
1975 * <none> Iterate through all pools and display information about
1978 * -a Iterate through all pools and try to import each one.
1980 * <id> Find the pool that corresponds to the given GUID/pool
1981 * name and import that one.
1983 * -D Above options applies only to destroyed pools.
1989 searchguid
= strtoull(argv
[0], &endptr
, 10);
1990 if (errno
!= 0 || *endptr
!= '\0')
1991 searchname
= argv
[0];
1992 found_config
= NULL
;
1995 * User specified a name or guid. Ensure it's unique.
1997 idata
.unique
= B_TRUE
;
2001 * Check the environment for the preferred search path.
2003 if ((searchdirs
== NULL
) && (env
= getenv("ZPOOL_IMPORT_PATH"))) {
2006 envdup
= strdup(env
);
2008 dir
= strtok(envdup
, ":");
2009 while (dir
!= NULL
) {
2010 if (searchdirs
== NULL
) {
2011 searchdirs
= safe_malloc(sizeof (char *));
2013 char **tmp
= safe_malloc((nsearch
+ 1) *
2015 bcopy(searchdirs
, tmp
, nsearch
*
2020 searchdirs
[nsearch
++] = dir
;
2021 dir
= strtok(NULL
, ":");
2025 idata
.path
= searchdirs
;
2026 idata
.paths
= nsearch
;
2027 idata
.poolname
= searchname
;
2028 idata
.guid
= searchguid
;
2029 idata
.cachefile
= cachefile
;
2031 pools
= zpool_search_import(g_zfs
, &idata
);
2033 if (pools
!= NULL
&& idata
.exists
&&
2034 (argc
== 1 || strcmp(argv
[0], argv
[1]) == 0)) {
2035 (void) fprintf(stderr
, gettext("cannot import '%s': "
2036 "a pool with that name already exists\n"),
2038 (void) fprintf(stderr
, gettext("use the form '%s "
2039 "<pool | id> <newpool>' to give it a new name\n"),
2042 } else if (pools
== NULL
&& idata
.exists
) {
2043 (void) fprintf(stderr
, gettext("cannot import '%s': "
2044 "a pool with that name is already created/imported,\n"),
2046 (void) fprintf(stderr
, gettext("and no additional pools "
2047 "with that name were found\n"));
2049 } else if (pools
== NULL
) {
2051 (void) fprintf(stderr
, gettext("cannot import '%s': "
2052 "no such pool available\n"), argv
[0]);
2058 if (searchdirs
!= NULL
)
2062 nvlist_free(policy
);
2067 * At this point we have a list of import candidate configs. Even if
2068 * we were searching by pool name or guid, we still need to
2069 * post-process the list to deal with pool state and possible
2075 while ((elem
= nvlist_next_nvpair(pools
, elem
)) != NULL
) {
2077 verify(nvpair_value_nvlist(elem
, &config
) == 0);
2079 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
2081 if (!do_destroyed
&& pool_state
== POOL_STATE_DESTROYED
)
2083 if (do_destroyed
&& pool_state
!= POOL_STATE_DESTROYED
)
2086 verify(nvlist_add_nvlist(config
, ZPOOL_REWIND_POLICY
,
2093 (void) printf("\n");
2096 err
|= do_import(config
, NULL
, mntopts
,
2099 show_import(config
);
2101 } else if (searchname
!= NULL
) {
2105 * We are searching for a pool based on name.
2107 verify(nvlist_lookup_string(config
,
2108 ZPOOL_CONFIG_POOL_NAME
, &name
) == 0);
2110 if (strcmp(name
, searchname
) == 0) {
2111 if (found_config
!= NULL
) {
2112 (void) fprintf(stderr
, gettext(
2113 "cannot import '%s': more than "
2114 "one matching pool\n"), searchname
);
2115 (void) fprintf(stderr
, gettext(
2116 "import by numeric ID instead\n"));
2119 found_config
= config
;
2125 * Search for a pool by guid.
2127 verify(nvlist_lookup_uint64(config
,
2128 ZPOOL_CONFIG_POOL_GUID
, &guid
) == 0);
2130 if (guid
== searchguid
)
2131 found_config
= config
;
2136 * If we were searching for a specific pool, verify that we found a
2137 * pool, and then do the import.
2139 if (argc
!= 0 && err
== 0) {
2140 if (found_config
== NULL
) {
2141 (void) fprintf(stderr
, gettext("cannot import '%s': "
2142 "no such pool available\n"), argv
[0]);
2145 err
|= do_import(found_config
, argc
== 1 ? NULL
:
2146 argv
[1], mntopts
, props
, flags
);
2151 * If we were just looking for pools, report an error if none were
2154 if (argc
== 0 && first
)
2155 (void) fprintf(stderr
,
2156 gettext("no pools available to import\n"));
2161 nvlist_free(policy
);
2162 if (searchdirs
!= NULL
)
2167 return (err
? 1 : 0);
2170 typedef struct iostat_cbdata
{
2171 boolean_t cb_verbose
;
2174 zpool_list_t
*cb_list
;
2178 print_iostat_separator(iostat_cbdata_t
*cb
)
2182 for (i
= 0; i
< cb
->cb_namewidth
; i
++)
2184 (void) printf(" ----- ----- ----- ----- ----- -----\n");
2188 print_iostat_header(iostat_cbdata_t
*cb
)
2190 (void) printf("%*s capacity operations bandwidth\n",
2191 cb
->cb_namewidth
, "");
2192 (void) printf("%-*s alloc free read write read write\n",
2193 cb
->cb_namewidth
, "pool");
2194 print_iostat_separator(cb
);
2198 * Display a single statistic.
2201 print_one_stat(uint64_t value
)
2205 zfs_nicenum(value
, buf
, sizeof (buf
));
2206 (void) printf(" %5s", buf
);
2210 * Print out all the statistics for the given vdev. This can either be the
2211 * toplevel configuration, or called recursively. If 'name' is NULL, then this
2212 * is a verbose output, and we don't want to display the toplevel pool stats.
2215 print_vdev_stats(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*oldnv
,
2216 nvlist_t
*newnv
, iostat_cbdata_t
*cb
, int depth
)
2218 nvlist_t
**oldchild
, **newchild
;
2220 vdev_stat_t
*oldvs
, *newvs
;
2221 vdev_stat_t zerovs
= { 0 };
2226 if (oldnv
!= NULL
) {
2227 verify(nvlist_lookup_uint64_array(oldnv
,
2228 ZPOOL_CONFIG_VDEV_STATS
, (uint64_t **)&oldvs
, &c
) == 0);
2233 verify(nvlist_lookup_uint64_array(newnv
, ZPOOL_CONFIG_VDEV_STATS
,
2234 (uint64_t **)&newvs
, &c
) == 0);
2236 if (strlen(name
) + depth
> cb
->cb_namewidth
)
2237 (void) printf("%*s%s", depth
, "", name
);
2239 (void) printf("%*s%s%*s", depth
, "", name
,
2240 (int)(cb
->cb_namewidth
- strlen(name
) - depth
), "");
2242 tdelta
= newvs
->vs_timestamp
- oldvs
->vs_timestamp
;
2247 scale
= (double)NANOSEC
/ tdelta
;
2249 /* only toplevel vdevs have capacity stats */
2250 if (newvs
->vs_space
== 0) {
2251 (void) printf(" - -");
2253 print_one_stat(newvs
->vs_alloc
);
2254 print_one_stat(newvs
->vs_space
- newvs
->vs_alloc
);
2257 print_one_stat((uint64_t)(scale
* (newvs
->vs_ops
[ZIO_TYPE_READ
] -
2258 oldvs
->vs_ops
[ZIO_TYPE_READ
])));
2260 print_one_stat((uint64_t)(scale
* (newvs
->vs_ops
[ZIO_TYPE_WRITE
] -
2261 oldvs
->vs_ops
[ZIO_TYPE_WRITE
])));
2263 print_one_stat((uint64_t)(scale
* (newvs
->vs_bytes
[ZIO_TYPE_READ
] -
2264 oldvs
->vs_bytes
[ZIO_TYPE_READ
])));
2266 print_one_stat((uint64_t)(scale
* (newvs
->vs_bytes
[ZIO_TYPE_WRITE
] -
2267 oldvs
->vs_bytes
[ZIO_TYPE_WRITE
])));
2269 (void) printf("\n");
2271 if (!cb
->cb_verbose
)
2274 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_CHILDREN
,
2275 &newchild
, &children
) != 0)
2278 if (oldnv
&& nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_CHILDREN
,
2279 &oldchild
, &c
) != 0)
2282 for (c
= 0; c
< children
; c
++) {
2283 uint64_t ishole
= B_FALSE
, islog
= B_FALSE
;
2285 (void) nvlist_lookup_uint64(newchild
[c
], ZPOOL_CONFIG_IS_HOLE
,
2288 (void) nvlist_lookup_uint64(newchild
[c
], ZPOOL_CONFIG_IS_LOG
,
2291 if (ishole
|| islog
)
2294 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
], B_FALSE
);
2295 print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
] : NULL
,
2296 newchild
[c
], cb
, depth
+ 2);
2301 * Log device section
2304 if (num_logs(newnv
) > 0) {
2305 (void) printf("%-*s - - - - - "
2306 "-\n", cb
->cb_namewidth
, "logs");
2308 for (c
= 0; c
< children
; c
++) {
2309 uint64_t islog
= B_FALSE
;
2310 (void) nvlist_lookup_uint64(newchild
[c
],
2311 ZPOOL_CONFIG_IS_LOG
, &islog
);
2314 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
2316 print_vdev_stats(zhp
, vname
, oldnv
?
2317 oldchild
[c
] : NULL
, newchild
[c
],
2326 * Include level 2 ARC devices in iostat output
2328 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_L2CACHE
,
2329 &newchild
, &children
) != 0)
2332 if (oldnv
&& nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_L2CACHE
,
2333 &oldchild
, &c
) != 0)
2337 (void) printf("%-*s - - - - - "
2338 "-\n", cb
->cb_namewidth
, "cache");
2339 for (c
= 0; c
< children
; c
++) {
2340 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
2342 print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
] : NULL
,
2343 newchild
[c
], cb
, depth
+ 2);
2350 refresh_iostat(zpool_handle_t
*zhp
, void *data
)
2352 iostat_cbdata_t
*cb
= data
;
2356 * If the pool has disappeared, remove it from the list and continue.
2358 if (zpool_refresh_stats(zhp
, &missing
) != 0)
2362 pool_list_remove(cb
->cb_list
, zhp
);
2368 * Callback to print out the iostats for the given pool.
2371 print_iostat(zpool_handle_t
*zhp
, void *data
)
2373 iostat_cbdata_t
*cb
= data
;
2374 nvlist_t
*oldconfig
, *newconfig
;
2375 nvlist_t
*oldnvroot
, *newnvroot
;
2377 newconfig
= zpool_get_config(zhp
, &oldconfig
);
2379 if (cb
->cb_iteration
== 1)
2382 verify(nvlist_lookup_nvlist(newconfig
, ZPOOL_CONFIG_VDEV_TREE
,
2385 if (oldconfig
== NULL
)
2388 verify(nvlist_lookup_nvlist(oldconfig
, ZPOOL_CONFIG_VDEV_TREE
,
2392 * Print out the statistics for the pool.
2394 print_vdev_stats(zhp
, zpool_get_name(zhp
), oldnvroot
, newnvroot
, cb
, 0);
2397 print_iostat_separator(cb
);
2409 if (isatty(STDOUT_FILENO
)) {
2410 error
= ioctl(STDOUT_FILENO
, TIOCGWINSZ
, &ws
);
2412 columns
= ws
.ws_col
;
2421 get_namewidth(zpool_handle_t
*zhp
, void *data
)
2423 iostat_cbdata_t
*cb
= data
;
2424 nvlist_t
*config
, *nvroot
;
2427 if ((config
= zpool_get_config(zhp
, NULL
)) != NULL
) {
2428 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
2430 if (!cb
->cb_verbose
)
2431 cb
->cb_namewidth
= strlen(zpool_get_name(zhp
));
2433 cb
->cb_namewidth
= max_width(zhp
, nvroot
, 0,
2438 * The width must be at least 10, but may be as large as the
2439 * column width - 42 so that we can still fit in one line.
2441 columns
= get_columns();
2443 if (cb
->cb_namewidth
< 10)
2444 cb
->cb_namewidth
= 10;
2445 if (cb
->cb_namewidth
> columns
- 42)
2446 cb
->cb_namewidth
= columns
- 42;
2452 * Parse the input string, get the 'interval' and 'count' value if there is one.
2455 get_interval_count(int *argcp
, char **argv
, unsigned long *iv
,
2458 unsigned long interval
= 0, count
= 0;
2462 * Determine if the last argument is an integer or a pool name
2464 if (argc
> 0 && isdigit(argv
[argc
- 1][0])) {
2468 interval
= strtoul(argv
[argc
- 1], &end
, 10);
2470 if (*end
== '\0' && errno
== 0) {
2471 if (interval
== 0) {
2472 (void) fprintf(stderr
, gettext("interval "
2473 "cannot be zero\n"));
2477 * Ignore the last parameter
2482 * If this is not a valid number, just plow on. The
2483 * user will get a more informative error message later
2491 * If the last argument is also an integer, then we have both a count
2494 if (argc
> 0 && isdigit(argv
[argc
- 1][0])) {
2499 interval
= strtoul(argv
[argc
- 1], &end
, 10);
2501 if (*end
== '\0' && errno
== 0) {
2502 if (interval
== 0) {
2503 (void) fprintf(stderr
, gettext("interval "
2504 "cannot be zero\n"));
2509 * Ignore the last parameter
2523 get_timestamp_arg(char c
)
2526 timestamp_fmt
= UDATE
;
2528 timestamp_fmt
= DDATE
;
2534 * zpool iostat [-v] [-T d|u] [pool] ... [interval [count]]
2536 * -v Display statistics for individual vdevs
2537 * -T Display a timestamp in date(1) or Unix format
2539 * This command can be tricky because we want to be able to deal with pool
2540 * creation/destruction as well as vdev configuration changes. The bulk of this
2541 * processing is handled by the pool_list_* routines in zpool_iter.c. We rely
2542 * on pool_list_update() to detect the addition of new pools. Configuration
2543 * changes are all handled within libzfs.
2546 zpool_do_iostat(int argc
, char **argv
)
2551 unsigned long interval
= 0, count
= 0;
2553 boolean_t verbose
= B_FALSE
;
2557 while ((c
= getopt(argc
, argv
, "T:v")) != -1) {
2560 get_timestamp_arg(*optarg
);
2566 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2575 get_interval_count(&argc
, argv
, &interval
, &count
);
2578 * Construct the list of all interesting pools.
2581 if ((list
= pool_list_get(argc
, argv
, NULL
, &ret
)) == NULL
)
2584 if (pool_list_count(list
) == 0 && argc
!= 0) {
2585 pool_list_free(list
);
2589 if (pool_list_count(list
) == 0 && interval
== 0) {
2590 pool_list_free(list
);
2591 (void) fprintf(stderr
, gettext("no pools available\n"));
2596 * Enter the main iostat loop.
2599 cb
.cb_verbose
= verbose
;
2600 cb
.cb_iteration
= 0;
2601 cb
.cb_namewidth
= 0;
2604 pool_list_update(list
);
2606 if ((npools
= pool_list_count(list
)) == 0)
2607 (void) fprintf(stderr
, gettext("no pools available\n"));
2610 * Refresh all statistics. This is done as an
2611 * explicit step before calculating the maximum name
2612 * width, so that any * configuration changes are
2613 * properly accounted for.
2615 (void) pool_list_iter(list
, B_FALSE
, refresh_iostat
,
2619 * Iterate over all pools to determine the maximum width
2620 * for the pool / device name column across all pools.
2622 cb
.cb_namewidth
= 0;
2623 (void) pool_list_iter(list
, B_FALSE
, get_namewidth
,
2626 if (timestamp_fmt
!= NODATE
)
2627 print_timestamp(timestamp_fmt
);
2630 * If it's the first time, or verbose mode, print the
2633 if (++cb
.cb_iteration
== 1 || verbose
)
2634 print_iostat_header(&cb
);
2636 (void) pool_list_iter(list
, B_FALSE
, print_iostat
, &cb
);
2639 * If there's more than one pool, and we're not in
2640 * verbose mode (which prints a separator for us),
2641 * then print a separator.
2643 if (npools
> 1 && !verbose
)
2644 print_iostat_separator(&cb
);
2647 (void) printf("\n");
2651 * Flush the output so that redirection to a file isn't buffered
2654 (void) fflush(stdout
);
2659 if (count
!= 0 && --count
== 0)
2662 (void) sleep(interval
);
2665 pool_list_free(list
);
2670 typedef struct list_cbdata
{
2671 boolean_t cb_verbose
;
2673 boolean_t cb_scripted
;
2674 zprop_list_t
*cb_proplist
;
2678 * Given a list of columns to display, output appropriate headers for each one.
2681 print_header(list_cbdata_t
*cb
)
2683 zprop_list_t
*pl
= cb
->cb_proplist
;
2684 char headerbuf
[ZPOOL_MAXPROPLEN
];
2686 boolean_t first
= B_TRUE
;
2687 boolean_t right_justify
;
2690 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
2691 width
= pl
->pl_width
;
2692 if (first
&& cb
->cb_verbose
) {
2694 * Reset the width to accommodate the verbose listing
2697 width
= cb
->cb_namewidth
;
2705 right_justify
= B_FALSE
;
2706 if (pl
->pl_prop
!= ZPROP_INVAL
) {
2707 header
= zpool_prop_column_name(pl
->pl_prop
);
2708 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
2712 for (i
= 0; pl
->pl_user_prop
[i
] != '\0'; i
++)
2713 headerbuf
[i
] = toupper(pl
->pl_user_prop
[i
]);
2714 headerbuf
[i
] = '\0';
2718 if (pl
->pl_next
== NULL
&& !right_justify
)
2719 (void) printf("%s", header
);
2720 else if (right_justify
)
2721 (void) printf("%*s", (int)width
, header
);
2723 (void) printf("%-*s", (int)width
, header
);
2726 (void) printf("\n");
2730 * Given a pool and a list of properties, print out all the properties according
2731 * to the described layout.
2734 print_pool(zpool_handle_t
*zhp
, list_cbdata_t
*cb
)
2736 zprop_list_t
*pl
= cb
->cb_proplist
;
2737 boolean_t first
= B_TRUE
;
2738 char property
[ZPOOL_MAXPROPLEN
];
2740 boolean_t right_justify
;
2743 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
2745 width
= pl
->pl_width
;
2746 if (first
&& cb
->cb_verbose
) {
2748 * Reset the width to accommodate the verbose listing
2751 width
= cb
->cb_namewidth
;
2755 if (cb
->cb_scripted
)
2756 (void) printf("\t");
2763 right_justify
= B_FALSE
;
2764 if (pl
->pl_prop
!= ZPROP_INVAL
) {
2765 if (pl
->pl_prop
== ZPOOL_PROP_EXPANDSZ
&&
2766 zpool_get_prop_int(zhp
, pl
->pl_prop
, NULL
) == 0)
2768 else if (zpool_get_prop(zhp
, pl
->pl_prop
, property
,
2769 sizeof (property
), NULL
) != 0)
2774 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
2775 } else if ((zpool_prop_feature(pl
->pl_user_prop
) ||
2776 zpool_prop_unsupported(pl
->pl_user_prop
)) &&
2777 zpool_prop_get_feature(zhp
, pl
->pl_user_prop
, property
,
2778 sizeof (property
)) == 0) {
2786 * If this is being called in scripted mode, or if this is the
2787 * last column and it is left-justified, don't include a width
2790 if (cb
->cb_scripted
|| (pl
->pl_next
== NULL
&& !right_justify
))
2791 (void) printf("%s", propstr
);
2792 else if (right_justify
)
2793 (void) printf("%*s", (int)width
, propstr
);
2795 (void) printf("%-*s", (int)width
, propstr
);
2798 (void) printf("\n");
2802 print_one_column(zpool_prop_t prop
, uint64_t value
, boolean_t scripted
)
2806 size_t width
= zprop_width(prop
, &fixed
, ZFS_TYPE_POOL
);
2808 zfs_nicenum(value
, propval
, sizeof (propval
));
2810 if (prop
== ZPOOL_PROP_EXPANDSZ
&& value
== 0)
2811 (void) strlcpy(propval
, "-", sizeof (propval
));
2814 (void) printf("\t%s", propval
);
2816 (void) printf(" %*s", (int)width
, propval
);
2820 print_list_stats(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
,
2821 list_cbdata_t
*cb
, int depth
)
2827 boolean_t scripted
= cb
->cb_scripted
;
2829 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
2830 (uint64_t **)&vs
, &c
) == 0);
2834 (void) printf("\t%s", name
);
2835 else if (strlen(name
) + depth
> cb
->cb_namewidth
)
2836 (void) printf("%*s%s", depth
, "", name
);
2838 (void) printf("%*s%s%*s", depth
, "", name
,
2839 (int)(cb
->cb_namewidth
- strlen(name
) - depth
), "");
2841 /* only toplevel vdevs have capacity stats */
2842 if (vs
->vs_space
== 0) {
2844 (void) printf("\t-\t-\t-");
2846 (void) printf(" - - -");
2848 print_one_column(ZPOOL_PROP_SIZE
, vs
->vs_space
,
2850 print_one_column(ZPOOL_PROP_CAPACITY
, vs
->vs_alloc
,
2852 print_one_column(ZPOOL_PROP_FREE
,
2853 vs
->vs_space
- vs
->vs_alloc
, scripted
);
2855 print_one_column(ZPOOL_PROP_EXPANDSZ
, vs
->vs_esize
,
2857 (void) printf("\n");
2860 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
2861 &child
, &children
) != 0)
2864 for (c
= 0; c
< children
; c
++) {
2865 uint64_t ishole
= B_FALSE
;
2867 if (nvlist_lookup_uint64(child
[c
],
2868 ZPOOL_CONFIG_IS_HOLE
, &ishole
) == 0 && ishole
)
2871 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], B_FALSE
);
2872 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
2877 * Include level 2 ARC devices in iostat output
2879 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
2880 &child
, &children
) != 0)
2884 (void) printf("%-*s - - - - - "
2885 "-\n", cb
->cb_namewidth
, "cache");
2886 for (c
= 0; c
< children
; c
++) {
2887 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
2889 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
2897 * Generic callback function to list a pool.
2900 list_callback(zpool_handle_t
*zhp
, void *data
)
2902 list_cbdata_t
*cbp
= data
;
2906 config
= zpool_get_config(zhp
, NULL
);
2908 print_pool(zhp
, cbp
);
2909 if (!cbp
->cb_verbose
)
2912 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
2914 print_list_stats(zhp
, NULL
, nvroot
, cbp
, 0);
2920 * zpool list [-H] [-o prop[,prop]*] [-T d|u] [pool] ... [interval [count]]
2922 * -H Scripted mode. Don't display headers, and separate properties
2924 * -o List of properties to display. Defaults to
2925 * "name,size,allocated,free,capacity,health,altroot"
2926 * -T Display a timestamp in date(1) or Unix format
2928 * List all pools in the system, whether or not they're healthy. Output space
2929 * statistics for each one, as well as health status summary.
2932 zpool_do_list(int argc
, char **argv
)
2936 list_cbdata_t cb
= { 0 };
2937 static char default_props
[] =
2938 "name,size,allocated,free,capacity,dedupratio,"
2940 char *props
= default_props
;
2941 unsigned long interval
= 0, count
= 0;
2943 boolean_t first
= B_TRUE
;
2946 while ((c
= getopt(argc
, argv
, ":Ho:T:v")) != -1) {
2949 cb
.cb_scripted
= B_TRUE
;
2955 get_timestamp_arg(*optarg
);
2958 cb
.cb_verbose
= B_TRUE
;
2961 (void) fprintf(stderr
, gettext("missing argument for "
2962 "'%c' option\n"), optopt
);
2966 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2975 get_interval_count(&argc
, argv
, &interval
, &count
);
2977 if (zprop_get_list(g_zfs
, props
, &cb
.cb_proplist
, ZFS_TYPE_POOL
) != 0)
2980 if ((list
= pool_list_get(argc
, argv
, &cb
.cb_proplist
, &ret
)) == NULL
)
2983 if (argc
== 0 && !cb
.cb_scripted
&& pool_list_count(list
) == 0) {
2984 (void) printf(gettext("no pools available\n"));
2985 zprop_free_list(cb
.cb_proplist
);
2990 pool_list_update(list
);
2992 if (pool_list_count(list
) == 0)
2995 if (timestamp_fmt
!= NODATE
)
2996 print_timestamp(timestamp_fmt
);
2998 if (!cb
.cb_scripted
&& (first
|| cb
.cb_verbose
)) {
3002 ret
= pool_list_iter(list
, B_TRUE
, list_callback
, &cb
);
3007 if (count
!= 0 && --count
== 0)
3010 (void) sleep(interval
);
3013 zprop_free_list(cb
.cb_proplist
);
3018 zpool_do_attach_or_replace(int argc
, char **argv
, int replacing
)
3020 boolean_t force
= B_FALSE
;
3023 char *poolname
, *old_disk
, *new_disk
;
3024 zpool_handle_t
*zhp
;
3025 nvlist_t
*props
= NULL
;
3030 while ((c
= getopt(argc
, argv
, "fo:")) != -1) {
3036 if ((propval
= strchr(optarg
, '=')) == NULL
) {
3037 (void) fprintf(stderr
, gettext("missing "
3038 "'=' for -o option\n"));
3044 if ((strcmp(optarg
, ZPOOL_CONFIG_ASHIFT
) != 0) ||
3045 (add_prop_list(optarg
, propval
, &props
, B_TRUE
)))
3049 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3058 /* get pool name and check number of arguments */
3060 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
3067 (void) fprintf(stderr
,
3068 gettext("missing <device> specification\n"));
3076 (void) fprintf(stderr
,
3077 gettext("missing <new_device> specification\n"));
3080 new_disk
= old_disk
;
3090 (void) fprintf(stderr
, gettext("too many arguments\n"));
3094 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
3097 if (zpool_get_config(zhp
, NULL
) == NULL
) {
3098 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
3104 nvroot
= make_root_vdev(zhp
, props
, force
, B_FALSE
, replacing
, B_FALSE
,
3106 if (nvroot
== NULL
) {
3111 ret
= zpool_vdev_attach(zhp
, old_disk
, new_disk
, nvroot
, replacing
);
3113 nvlist_free(nvroot
);
3120 * zpool replace [-f] <pool> <device> <new_device>
3122 * -f Force attach, even if <new_device> appears to be in use.
3124 * Replace <device> with <new_device>.
3128 zpool_do_replace(int argc
, char **argv
)
3130 return (zpool_do_attach_or_replace(argc
, argv
, B_TRUE
));
3134 * zpool attach [-f] [-o property=value] <pool> <device> <new_device>
3136 * -f Force attach, even if <new_device> appears to be in use.
3137 * -o Set property=value.
3139 * Attach <new_device> to the mirror containing <device>. If <device> is not
3140 * part of a mirror, then <device> will be transformed into a mirror of
3141 * <device> and <new_device>. In either case, <new_device> will begin life
3142 * with a DTL of [0, now], and will immediately begin to resilver itself.
3145 zpool_do_attach(int argc
, char **argv
)
3147 return (zpool_do_attach_or_replace(argc
, argv
, B_FALSE
));
3151 * zpool detach [-f] <pool> <device>
3153 * -f Force detach of <device>, even if DTLs argue against it
3154 * (not supported yet)
3156 * Detach a device from a mirror. The operation will be refused if <device>
3157 * is the last device in the mirror, or if the DTLs indicate that this device
3158 * has the only valid copy of some data.
3162 zpool_do_detach(int argc
, char **argv
)
3165 char *poolname
, *path
;
3166 zpool_handle_t
*zhp
;
3170 while ((c
= getopt(argc
, argv
, "f")) != -1) {
3174 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3183 /* get pool name and check number of arguments */
3185 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
3190 (void) fprintf(stderr
,
3191 gettext("missing <device> specification\n"));
3198 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
3201 ret
= zpool_vdev_detach(zhp
, path
);
3209 * zpool split [-n] [-o prop=val] ...
3211 * [-R altroot] <pool> <newpool> [<device> ...]
3213 * -n Do not split the pool, but display the resulting layout if
3214 * it were to be split.
3215 * -o Set property=value, or set mount options.
3216 * -R Mount the split-off pool under an alternate root.
3218 * Splits the named pool and gives it the new pool name. Devices to be split
3219 * off may be listed, provided that no more than one device is specified
3220 * per top-level vdev mirror. The newly split pool is left in an exported
3221 * state unless -R is specified.
3223 * Restrictions: the top-level of the pool pool must only be made up of
3224 * mirrors; all devices in the pool must be healthy; no device may be
3225 * undergoing a resilvering operation.
3228 zpool_do_split(int argc
, char **argv
)
3230 char *srcpool
, *newpool
, *propval
;
3231 char *mntopts
= NULL
;
3234 zpool_handle_t
*zhp
;
3235 nvlist_t
*config
, *props
= NULL
;
3237 flags
.dryrun
= B_FALSE
;
3238 flags
.import
= B_FALSE
;
3241 while ((c
= getopt(argc
, argv
, ":R:no:")) != -1) {
3244 flags
.import
= B_TRUE
;
3246 zpool_prop_to_name(ZPOOL_PROP_ALTROOT
), optarg
,
3247 &props
, B_TRUE
) != 0) {
3254 flags
.dryrun
= B_TRUE
;
3257 if ((propval
= strchr(optarg
, '=')) != NULL
) {
3260 if (add_prop_list(optarg
, propval
,
3261 &props
, B_TRUE
) != 0) {
3271 (void) fprintf(stderr
, gettext("missing argument for "
3272 "'%c' option\n"), optopt
);
3276 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3283 if (!flags
.import
&& mntopts
!= NULL
) {
3284 (void) fprintf(stderr
, gettext("setting mntopts is only "
3285 "valid when importing the pool\n"));
3293 (void) fprintf(stderr
, gettext("Missing pool name\n"));
3297 (void) fprintf(stderr
, gettext("Missing new pool name\n"));
3307 if ((zhp
= zpool_open(g_zfs
, srcpool
)) == NULL
)
3310 config
= split_mirror_vdev(zhp
, newpool
, props
, flags
, argc
, argv
);
3311 if (config
== NULL
) {
3315 (void) printf(gettext("would create '%s' with the "
3316 "following layout:\n\n"), newpool
);
3317 print_vdev_tree(NULL
, newpool
, config
, 0, B_FALSE
);
3319 nvlist_free(config
);
3324 if (ret
!= 0 || flags
.dryrun
|| !flags
.import
)
3328 * The split was successful. Now we need to open the new
3329 * pool and import it.
3331 if ((zhp
= zpool_open_canfail(g_zfs
, newpool
)) == NULL
)
3333 if (zpool_get_state(zhp
) != POOL_STATE_UNAVAIL
&&
3334 zpool_enable_datasets(zhp
, mntopts
, 0) != 0) {
3336 (void) fprintf(stderr
, gettext("Split was successful, but "
3337 "the datasets could not all be mounted\n"));
3338 (void) fprintf(stderr
, gettext("Try doing '%s' with a "
3339 "different altroot\n"), "zpool import");
3349 * zpool online <pool> <device> ...
3352 zpool_do_online(int argc
, char **argv
)
3356 zpool_handle_t
*zhp
;
3358 vdev_state_t newstate
;
3362 while ((c
= getopt(argc
, argv
, "et")) != -1) {
3365 flags
|= ZFS_ONLINE_EXPAND
;
3369 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3378 /* get pool name and check number of arguments */
3380 (void) fprintf(stderr
, gettext("missing pool name\n"));
3384 (void) fprintf(stderr
, gettext("missing device name\n"));
3390 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
3393 for (i
= 1; i
< argc
; i
++) {
3394 if (zpool_vdev_online(zhp
, argv
[i
], flags
, &newstate
) == 0) {
3395 if (newstate
!= VDEV_STATE_HEALTHY
) {
3396 (void) printf(gettext("warning: device '%s' "
3397 "onlined, but remains in faulted state\n"),
3399 if (newstate
== VDEV_STATE_FAULTED
)
3400 (void) printf(gettext("use 'zpool "
3401 "clear' to restore a faulted "
3404 (void) printf(gettext("use 'zpool "
3405 "replace' to replace devices "
3406 "that are no longer present\n"));
3419 * zpool offline [-ft] <pool> <device> ...
3421 * -f Force the device into the offline state, even if doing
3422 * so would appear to compromise pool availability.
3423 * (not supported yet)
3425 * -t Only take the device off-line temporarily. The offline
3426 * state will not be persistent across reboots.
3430 zpool_do_offline(int argc
, char **argv
)
3434 zpool_handle_t
*zhp
;
3436 boolean_t istmp
= B_FALSE
;
3439 while ((c
= getopt(argc
, argv
, "ft")) != -1) {
3446 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3455 /* get pool name and check number of arguments */
3457 (void) fprintf(stderr
, gettext("missing pool name\n"));
3461 (void) fprintf(stderr
, gettext("missing device name\n"));
3467 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
3470 for (i
= 1; i
< argc
; i
++) {
3471 if (zpool_vdev_offline(zhp
, argv
[i
], istmp
) != 0)
3481 * zpool clear <pool> [device]
3483 * Clear all errors associated with a pool or a particular device.
3486 zpool_do_clear(int argc
, char **argv
)
3490 boolean_t dryrun
= B_FALSE
;
3491 boolean_t do_rewind
= B_FALSE
;
3492 boolean_t xtreme_rewind
= B_FALSE
;
3493 uint32_t rewind_policy
= ZPOOL_NO_REWIND
;
3494 nvlist_t
*policy
= NULL
;
3495 zpool_handle_t
*zhp
;
3496 char *pool
, *device
;
3499 while ((c
= getopt(argc
, argv
, "FnX")) != -1) {
3508 xtreme_rewind
= B_TRUE
;
3511 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3521 (void) fprintf(stderr
, gettext("missing pool name\n"));
3526 (void) fprintf(stderr
, gettext("too many arguments\n"));
3530 if ((dryrun
|| xtreme_rewind
) && !do_rewind
) {
3531 (void) fprintf(stderr
,
3532 gettext("-n or -X only meaningful with -F\n"));
3536 rewind_policy
= ZPOOL_TRY_REWIND
;
3538 rewind_policy
= ZPOOL_DO_REWIND
;
3540 rewind_policy
|= ZPOOL_EXTREME_REWIND
;
3542 /* In future, further rewind policy choices can be passed along here */
3543 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME
, 0) != 0 ||
3544 nvlist_add_uint32(policy
, ZPOOL_REWIND_REQUEST
, rewind_policy
) != 0)
3548 device
= argc
== 2 ? argv
[1] : NULL
;
3550 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
) {
3551 nvlist_free(policy
);
3555 if (zpool_clear(zhp
, device
, policy
) != 0)
3560 nvlist_free(policy
);
3566 * zpool reguid <pool>
3569 zpool_do_reguid(int argc
, char **argv
)
3573 zpool_handle_t
*zhp
;
3577 while ((c
= getopt(argc
, argv
, "")) != -1) {
3580 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3589 /* get pool name and check number of arguments */
3591 (void) fprintf(stderr
, gettext("missing pool name\n"));
3596 (void) fprintf(stderr
, gettext("too many arguments\n"));
3601 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
3604 ret
= zpool_reguid(zhp
);
3612 * zpool reopen <pool>
3614 * Reopen the pool so that the kernel can update the sizes of all vdevs.
3616 * NOTE: This command is currently undocumented. If the command is ever
3617 * exposed then the appropriate usage() messages will need to be made.
3620 zpool_do_reopen(int argc
, char **argv
)
3623 zpool_handle_t
*zhp
;
3633 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
)
3636 ret
= zpool_reopen(zhp
);
3641 typedef struct scrub_cbdata
{
3648 scrub_callback(zpool_handle_t
*zhp
, void *data
)
3650 scrub_cbdata_t
*cb
= data
;
3654 * Ignore faulted pools.
3656 if (zpool_get_state(zhp
) == POOL_STATE_UNAVAIL
) {
3657 (void) fprintf(stderr
, gettext("cannot scrub '%s': pool is "
3658 "currently unavailable\n"), zpool_get_name(zhp
));
3662 err
= zpool_scan(zhp
, cb
->cb_type
);
3668 * zpool scrub [-s] <pool> ...
3670 * -s Stop. Stops any in-progress scrub.
3673 zpool_do_scrub(int argc
, char **argv
)
3678 cb
.cb_type
= POOL_SCAN_SCRUB
;
3681 while ((c
= getopt(argc
, argv
, "s")) != -1) {
3684 cb
.cb_type
= POOL_SCAN_NONE
;
3687 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3699 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
3703 return (for_each_pool(argc
, argv
, B_TRUE
, NULL
, scrub_callback
, &cb
));
3706 typedef struct status_cbdata
{
3708 boolean_t cb_allpools
;
3709 boolean_t cb_verbose
;
3710 boolean_t cb_explain
;
3712 boolean_t cb_dedup_stats
;
3716 * Print out detailed scrub status.
3719 print_scan_status(pool_scan_stat_t
*ps
)
3722 uint64_t elapsed
, mins_left
, hours_left
;
3723 uint64_t pass_exam
, examined
, total
;
3725 double fraction_done
;
3726 char processed_buf
[7], examined_buf
[7], total_buf
[7], rate_buf
[7];
3728 (void) printf(gettext(" scan: "));
3730 /* If there's never been a scan, there's not much to say. */
3731 if (ps
== NULL
|| ps
->pss_func
== POOL_SCAN_NONE
||
3732 ps
->pss_func
>= POOL_SCAN_FUNCS
) {
3733 (void) printf(gettext("none requested\n"));
3737 start
= ps
->pss_start_time
;
3738 end
= ps
->pss_end_time
;
3739 zfs_nicenum(ps
->pss_processed
, processed_buf
, sizeof (processed_buf
));
3741 assert(ps
->pss_func
== POOL_SCAN_SCRUB
||
3742 ps
->pss_func
== POOL_SCAN_RESILVER
);
3744 * Scan is finished or canceled.
3746 if (ps
->pss_state
== DSS_FINISHED
) {
3747 uint64_t minutes_taken
= (end
- start
) / 60;
3750 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
3751 fmt
= gettext("scrub repaired %s in %lluh%um with "
3752 "%llu errors on %s");
3753 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
3754 fmt
= gettext("resilvered %s in %lluh%um with "
3755 "%llu errors on %s");
3758 (void) printf(fmt
, processed_buf
,
3759 (u_longlong_t
)(minutes_taken
/ 60),
3760 (uint_t
)(minutes_taken
% 60),
3761 (u_longlong_t
)ps
->pss_errors
,
3762 ctime((time_t *)&end
));
3764 } else if (ps
->pss_state
== DSS_CANCELED
) {
3765 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
3766 (void) printf(gettext("scrub canceled on %s"),
3768 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
3769 (void) printf(gettext("resilver canceled on %s"),
3775 assert(ps
->pss_state
== DSS_SCANNING
);
3778 * Scan is in progress.
3780 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
3781 (void) printf(gettext("scrub in progress since %s"),
3783 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
3784 (void) printf(gettext("resilver in progress since %s"),
3788 examined
= ps
->pss_examined
? ps
->pss_examined
: 1;
3789 total
= ps
->pss_to_examine
;
3790 fraction_done
= (double)examined
/ total
;
3792 /* elapsed time for this pass */
3793 elapsed
= time(NULL
) - ps
->pss_pass_start
;
3794 elapsed
= elapsed
? elapsed
: 1;
3795 pass_exam
= ps
->pss_pass_exam
? ps
->pss_pass_exam
: 1;
3796 rate
= pass_exam
/ elapsed
;
3797 rate
= rate
? rate
: 1;
3798 mins_left
= ((total
- examined
) / rate
) / 60;
3799 hours_left
= mins_left
/ 60;
3801 zfs_nicenum(examined
, examined_buf
, sizeof (examined_buf
));
3802 zfs_nicenum(total
, total_buf
, sizeof (total_buf
));
3803 zfs_nicenum(rate
, rate_buf
, sizeof (rate_buf
));
3806 * do not print estimated time if hours_left is more than 30 days
3808 (void) printf(gettext(" %s scanned out of %s at %s/s"),
3809 examined_buf
, total_buf
, rate_buf
);
3810 if (hours_left
< (30 * 24)) {
3811 (void) printf(gettext(", %lluh%um to go\n"),
3812 (u_longlong_t
)hours_left
, (uint_t
)(mins_left
% 60));
3814 (void) printf(gettext(
3815 ", (scan is slow, no estimated time)\n"));
3818 if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
3819 (void) printf(gettext(" %s resilvered, %.2f%% done\n"),
3820 processed_buf
, 100 * fraction_done
);
3821 } else if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
3822 (void) printf(gettext(" %s repaired, %.2f%% done\n"),
3823 processed_buf
, 100 * fraction_done
);
3828 print_error_log(zpool_handle_t
*zhp
)
3830 nvlist_t
*nverrlist
= NULL
;
3833 size_t len
= MAXPATHLEN
* 2;
3835 if (zpool_get_errlog(zhp
, &nverrlist
) != 0) {
3836 (void) printf("errors: List of errors unavailable "
3837 "(insufficient privileges)\n");
3841 (void) printf("errors: Permanent errors have been "
3842 "detected in the following files:\n\n");
3844 pathname
= safe_malloc(len
);
3846 while ((elem
= nvlist_next_nvpair(nverrlist
, elem
)) != NULL
) {
3848 uint64_t dsobj
, obj
;
3850 verify(nvpair_value_nvlist(elem
, &nv
) == 0);
3851 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_DATASET
,
3853 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_OBJECT
,
3855 zpool_obj_to_path(zhp
, dsobj
, obj
, pathname
, len
);
3856 (void) printf("%7s %s\n", "", pathname
);
3859 nvlist_free(nverrlist
);
3863 print_spares(zpool_handle_t
*zhp
, nvlist_t
**spares
, uint_t nspares
,
3872 (void) printf(gettext("\tspares\n"));
3874 for (i
= 0; i
< nspares
; i
++) {
3875 name
= zpool_vdev_name(g_zfs
, zhp
, spares
[i
], B_FALSE
);
3876 print_status_config(zhp
, name
, spares
[i
],
3877 namewidth
, 2, B_TRUE
);
3883 print_l2cache(zpool_handle_t
*zhp
, nvlist_t
**l2cache
, uint_t nl2cache
,
3892 (void) printf(gettext("\tcache\n"));
3894 for (i
= 0; i
< nl2cache
; i
++) {
3895 name
= zpool_vdev_name(g_zfs
, zhp
, l2cache
[i
], B_FALSE
);
3896 print_status_config(zhp
, name
, l2cache
[i
],
3897 namewidth
, 2, B_FALSE
);
3903 print_dedup_stats(nvlist_t
*config
)
3905 ddt_histogram_t
*ddh
;
3911 * If the pool was faulted then we may not have been able to
3912 * obtain the config. Otherwise, if we have anything in the dedup
3913 * table continue processing the stats.
3915 if (nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_OBJ_STATS
,
3916 (uint64_t **)&ddo
, &c
) != 0 || ddo
->ddo_count
== 0)
3919 (void) printf("\n");
3920 (void) printf("DDT entries %llu, size %llu on disk, %llu in core\n",
3921 (u_longlong_t
)ddo
->ddo_count
,
3922 (u_longlong_t
)ddo
->ddo_dspace
,
3923 (u_longlong_t
)ddo
->ddo_mspace
);
3925 verify(nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_STATS
,
3926 (uint64_t **)&dds
, &c
) == 0);
3927 verify(nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_HISTOGRAM
,
3928 (uint64_t **)&ddh
, &c
) == 0);
3929 zpool_dump_ddt(dds
, ddh
);
3933 * Display a summary of pool status. Displays a summary such as:
3937 * reason: One or more devices ...
3938 * see: http://zfsonlinux.org/msg/ZFS-xxxx-01
3944 * When given the '-v' option, we print out the complete config. If the '-e'
3945 * option is specified, then we print out error rate information as well.
3948 status_callback(zpool_handle_t
*zhp
, void *data
)
3950 status_cbdata_t
*cbp
= data
;
3951 nvlist_t
*config
, *nvroot
;
3958 config
= zpool_get_config(zhp
, NULL
);
3959 reason
= zpool_get_status(zhp
, &msgid
);
3964 * If we were given 'zpool status -x', only report those pools with
3967 if (reason
== ZPOOL_STATUS_OK
&& cbp
->cb_explain
) {
3968 if (!cbp
->cb_allpools
) {
3969 (void) printf(gettext("pool '%s' is healthy\n"),
3970 zpool_get_name(zhp
));
3972 cbp
->cb_first
= B_FALSE
;
3978 cbp
->cb_first
= B_FALSE
;
3980 (void) printf("\n");
3982 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
3984 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_VDEV_STATS
,
3985 (uint64_t **)&vs
, &c
) == 0);
3986 health
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
3988 (void) printf(gettext(" pool: %s\n"), zpool_get_name(zhp
));
3989 (void) printf(gettext(" state: %s\n"), health
);
3992 case ZPOOL_STATUS_MISSING_DEV_R
:
3993 (void) printf(gettext("status: One or more devices could not "
3994 "be opened. Sufficient replicas exist for\n\tthe pool to "
3995 "continue functioning in a degraded state.\n"));
3996 (void) printf(gettext("action: Attach the missing device and "
3997 "online it using 'zpool online'.\n"));
4000 case ZPOOL_STATUS_MISSING_DEV_NR
:
4001 (void) printf(gettext("status: One or more devices could not "
4002 "be opened. There are insufficient\n\treplicas for the "
4003 "pool to continue functioning.\n"));
4004 (void) printf(gettext("action: Attach the missing device and "
4005 "online it using 'zpool online'.\n"));
4008 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
4009 (void) printf(gettext("status: One or more devices could not "
4010 "be used because the label is missing or\n\tinvalid. "
4011 "Sufficient replicas exist for the pool to continue\n\t"
4012 "functioning in a degraded state.\n"));
4013 (void) printf(gettext("action: Replace the device using "
4014 "'zpool replace'.\n"));
4017 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
4018 (void) printf(gettext("status: One or more devices could not "
4019 "be used because the label is missing \n\tor invalid. "
4020 "There are insufficient replicas for the pool to "
4021 "continue\n\tfunctioning.\n"));
4022 zpool_explain_recover(zpool_get_handle(zhp
),
4023 zpool_get_name(zhp
), reason
, config
);
4026 case ZPOOL_STATUS_FAILING_DEV
:
4027 (void) printf(gettext("status: One or more devices has "
4028 "experienced an unrecoverable error. An\n\tattempt was "
4029 "made to correct the error. Applications are "
4031 (void) printf(gettext("action: Determine if the device needs "
4032 "to be replaced, and clear the errors\n\tusing "
4033 "'zpool clear' or replace the device with 'zpool "
4037 case ZPOOL_STATUS_OFFLINE_DEV
:
4038 (void) printf(gettext("status: One or more devices has "
4039 "been taken offline by the administrator.\n\tSufficient "
4040 "replicas exist for the pool to continue functioning in "
4041 "a\n\tdegraded state.\n"));
4042 (void) printf(gettext("action: Online the device using "
4043 "'zpool online' or replace the device with\n\t'zpool "
4047 case ZPOOL_STATUS_REMOVED_DEV
:
4048 (void) printf(gettext("status: One or more devices has "
4049 "been removed by the administrator.\n\tSufficient "
4050 "replicas exist for the pool to continue functioning in "
4051 "a\n\tdegraded state.\n"));
4052 (void) printf(gettext("action: Online the device using "
4053 "'zpool online' or replace the device with\n\t'zpool "
4057 case ZPOOL_STATUS_RESILVERING
:
4058 (void) printf(gettext("status: One or more devices is "
4059 "currently being resilvered. The pool will\n\tcontinue "
4060 "to function, possibly in a degraded state.\n"));
4061 (void) printf(gettext("action: Wait for the resilver to "
4065 case ZPOOL_STATUS_CORRUPT_DATA
:
4066 (void) printf(gettext("status: One or more devices has "
4067 "experienced an error resulting in data\n\tcorruption. "
4068 "Applications may be affected.\n"));
4069 (void) printf(gettext("action: Restore the file in question "
4070 "if possible. Otherwise restore the\n\tentire pool from "
4074 case ZPOOL_STATUS_CORRUPT_POOL
:
4075 (void) printf(gettext("status: The pool metadata is corrupted "
4076 "and the pool cannot be opened.\n"));
4077 zpool_explain_recover(zpool_get_handle(zhp
),
4078 zpool_get_name(zhp
), reason
, config
);
4081 case ZPOOL_STATUS_VERSION_OLDER
:
4082 (void) printf(gettext("status: The pool is formatted using a "
4083 "legacy on-disk format. The pool can\n\tstill be used, "
4084 "but some features are unavailable.\n"));
4085 (void) printf(gettext("action: Upgrade the pool using 'zpool "
4086 "upgrade'. Once this is done, the\n\tpool will no longer "
4087 "be accessible on software that does not support feature\n"
4091 case ZPOOL_STATUS_VERSION_NEWER
:
4092 (void) printf(gettext("status: The pool has been upgraded to a "
4093 "newer, incompatible on-disk version.\n\tThe pool cannot "
4094 "be accessed on this system.\n"));
4095 (void) printf(gettext("action: Access the pool from a system "
4096 "running more recent software, or\n\trestore the pool from "
4100 case ZPOOL_STATUS_FEAT_DISABLED
:
4101 (void) printf(gettext("status: Some supported features are not "
4102 "enabled on the pool. The pool can\n\tstill be used, but "
4103 "some features are unavailable.\n"));
4104 (void) printf(gettext("action: Enable all features using "
4105 "'zpool upgrade'. Once this is done,\n\tthe pool may no "
4106 "longer be accessible by software that does not support\n\t"
4107 "the features. See zpool-features(5) for details.\n"));
4110 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
4111 (void) printf(gettext("status: The pool cannot be accessed on "
4112 "this system because it uses the\n\tfollowing feature(s) "
4113 "not supported on this system:\n"));
4114 zpool_print_unsup_feat(config
);
4115 (void) printf("\n");
4116 (void) printf(gettext("action: Access the pool from a system "
4117 "that supports the required feature(s),\n\tor restore the "
4118 "pool from backup.\n"));
4121 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
4122 (void) printf(gettext("status: The pool can only be accessed "
4123 "in read-only mode on this system. It\n\tcannot be "
4124 "accessed in read-write mode because it uses the "
4125 "following\n\tfeature(s) not supported on this system:\n"));
4126 zpool_print_unsup_feat(config
);
4127 (void) printf("\n");
4128 (void) printf(gettext("action: The pool cannot be accessed in "
4129 "read-write mode. Import the pool with\n"
4130 "\t\"-o readonly=on\", access the pool from a system that "
4131 "supports the\n\trequired feature(s), or restore the "
4132 "pool from backup.\n"));
4135 case ZPOOL_STATUS_FAULTED_DEV_R
:
4136 (void) printf(gettext("status: One or more devices are "
4137 "faulted in response to persistent errors.\n\tSufficient "
4138 "replicas exist for the pool to continue functioning "
4139 "in a\n\tdegraded state.\n"));
4140 (void) printf(gettext("action: Replace the faulted device, "
4141 "or use 'zpool clear' to mark the device\n\trepaired.\n"));
4144 case ZPOOL_STATUS_FAULTED_DEV_NR
:
4145 (void) printf(gettext("status: One or more devices are "
4146 "faulted in response to persistent errors. There are "
4147 "insufficient replicas for the pool to\n\tcontinue "
4149 (void) printf(gettext("action: Destroy and re-create the pool "
4150 "from a backup source. Manually marking the device\n"
4151 "\trepaired using 'zpool clear' may allow some data "
4152 "to be recovered.\n"));
4155 case ZPOOL_STATUS_IO_FAILURE_WAIT
:
4156 case ZPOOL_STATUS_IO_FAILURE_CONTINUE
:
4157 (void) printf(gettext("status: One or more devices are "
4158 "faulted in response to IO failures.\n"));
4159 (void) printf(gettext("action: Make sure the affected devices "
4160 "are connected, then run 'zpool clear'.\n"));
4163 case ZPOOL_STATUS_BAD_LOG
:
4164 (void) printf(gettext("status: An intent log record "
4165 "could not be read.\n"
4166 "\tWaiting for adminstrator intervention to fix the "
4167 "faulted pool.\n"));
4168 (void) printf(gettext("action: Either restore the affected "
4169 "device(s) and run 'zpool online',\n"
4170 "\tor ignore the intent log records by running "
4171 "'zpool clear'.\n"));
4176 * The remaining errors can't actually be generated, yet.
4178 assert(reason
== ZPOOL_STATUS_OK
);
4182 (void) printf(gettext(" see: http://zfsonlinux.org/msg/%s\n"),
4185 if (config
!= NULL
) {
4188 nvlist_t
**spares
, **l2cache
;
4189 uint_t nspares
, nl2cache
;
4190 pool_scan_stat_t
*ps
= NULL
;
4192 (void) nvlist_lookup_uint64_array(nvroot
,
4193 ZPOOL_CONFIG_SCAN_STATS
, (uint64_t **)&ps
, &c
);
4194 print_scan_status(ps
);
4196 namewidth
= max_width(zhp
, nvroot
, 0, 0);
4200 (void) printf(gettext("config:\n\n"));
4201 (void) printf(gettext("\t%-*s %-8s %5s %5s %5s\n"), namewidth
,
4202 "NAME", "STATE", "READ", "WRITE", "CKSUM");
4203 print_status_config(zhp
, zpool_get_name(zhp
), nvroot
,
4204 namewidth
, 0, B_FALSE
);
4206 if (num_logs(nvroot
) > 0)
4207 print_logs(zhp
, nvroot
, namewidth
, B_TRUE
);
4208 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_L2CACHE
,
4209 &l2cache
, &nl2cache
) == 0)
4210 print_l2cache(zhp
, l2cache
, nl2cache
, namewidth
);
4212 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_SPARES
,
4213 &spares
, &nspares
) == 0)
4214 print_spares(zhp
, spares
, nspares
, namewidth
);
4216 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_ERRCOUNT
,
4218 nvlist_t
*nverrlist
= NULL
;
4221 * If the approximate error count is small, get a
4222 * precise count by fetching the entire log and
4223 * uniquifying the results.
4225 if (nerr
> 0 && nerr
< 100 && !cbp
->cb_verbose
&&
4226 zpool_get_errlog(zhp
, &nverrlist
) == 0) {
4231 while ((elem
= nvlist_next_nvpair(nverrlist
,
4236 nvlist_free(nverrlist
);
4238 (void) printf("\n");
4241 (void) printf(gettext("errors: No known data "
4243 else if (!cbp
->cb_verbose
)
4244 (void) printf(gettext("errors: %llu data "
4245 "errors, use '-v' for a list\n"),
4246 (u_longlong_t
)nerr
);
4248 print_error_log(zhp
);
4251 if (cbp
->cb_dedup_stats
)
4252 print_dedup_stats(config
);
4254 (void) printf(gettext("config: The configuration cannot be "
4262 * zpool status [-vx] [-T d|u] [pool] ... [interval [count]]
4264 * -v Display complete error logs
4265 * -x Display only pools with potential problems
4266 * -D Display dedup status (undocumented)
4267 * -T Display a timestamp in date(1) or Unix format
4269 * Describes the health status of all pools or some subset.
4272 zpool_do_status(int argc
, char **argv
)
4276 unsigned long interval
= 0, count
= 0;
4277 status_cbdata_t cb
= { 0 };
4280 while ((c
= getopt(argc
, argv
, "vxDT:")) != -1) {
4283 cb
.cb_verbose
= B_TRUE
;
4286 cb
.cb_explain
= B_TRUE
;
4289 cb
.cb_dedup_stats
= B_TRUE
;
4292 get_timestamp_arg(*optarg
);
4295 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4304 get_interval_count(&argc
, argv
, &interval
, &count
);
4307 cb
.cb_allpools
= B_TRUE
;
4309 cb
.cb_first
= B_TRUE
;
4312 if (timestamp_fmt
!= NODATE
)
4313 print_timestamp(timestamp_fmt
);
4315 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
,
4316 status_callback
, &cb
);
4318 if (argc
== 0 && cb
.cb_count
== 0)
4319 (void) fprintf(stderr
, gettext("no pools available\n"));
4320 else if (cb
.cb_explain
&& cb
.cb_first
&& cb
.cb_allpools
)
4321 (void) printf(gettext("all pools are healthy\n"));
4329 if (count
!= 0 && --count
== 0)
4332 (void) sleep(interval
);
4338 typedef struct upgrade_cbdata
{
4341 uint64_t cb_version
;
4346 upgrade_version(zpool_handle_t
*zhp
, uint64_t version
)
4350 uint64_t oldversion
;
4352 config
= zpool_get_config(zhp
, NULL
);
4353 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
4356 assert(SPA_VERSION_IS_SUPPORTED(oldversion
));
4357 assert(oldversion
< version
);
4359 ret
= zpool_upgrade(zhp
, version
);
4363 if (version
>= SPA_VERSION_FEATURES
) {
4364 (void) printf(gettext("Successfully upgraded "
4365 "'%s' from version %llu to feature flags.\n"),
4366 zpool_get_name(zhp
), (u_longlong_t
) oldversion
);
4368 (void) printf(gettext("Successfully upgraded "
4369 "'%s' from version %llu to version %llu.\n"),
4370 zpool_get_name(zhp
), (u_longlong_t
) oldversion
,
4371 (u_longlong_t
) version
);
4378 upgrade_enable_all(zpool_handle_t
*zhp
, int *countp
)
4381 boolean_t firstff
= B_TRUE
;
4382 nvlist_t
*enabled
= zpool_get_features(zhp
);
4385 for (i
= 0; i
< SPA_FEATURES
; i
++) {
4386 const char *fname
= spa_feature_table
[i
].fi_uname
;
4387 const char *fguid
= spa_feature_table
[i
].fi_guid
;
4388 if (!nvlist_exists(enabled
, fguid
)) {
4390 verify(-1 != asprintf(&propname
, "feature@%s", fname
));
4391 ret
= zpool_set_prop(zhp
, propname
,
4392 ZFS_FEATURE_ENABLED
);
4400 (void) printf(gettext("Enabled the "
4401 "following features on '%s':\n"),
4402 zpool_get_name(zhp
));
4405 (void) printf(gettext(" %s\n"), fname
);
4416 upgrade_cb(zpool_handle_t
*zhp
, void *arg
)
4418 upgrade_cbdata_t
*cbp
= arg
;
4421 boolean_t printnl
= B_FALSE
;
4424 config
= zpool_get_config(zhp
, NULL
);
4425 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
4428 assert(SPA_VERSION_IS_SUPPORTED(version
));
4430 if (version
< cbp
->cb_version
) {
4431 cbp
->cb_first
= B_FALSE
;
4432 ret
= upgrade_version(zhp
, cbp
->cb_version
);
4439 * XXX: This code can be enabled when Illumos commit
4440 * 4445fffbbb1ea25fd0e9ea68b9380dd7a6709025 is merged.
4441 * It reworks the history logging among other things.
4445 * If they did "zpool upgrade -a", then we could
4446 * be doing ioctls to different pools. We need
4447 * to log this history once to each pool, and bypass
4448 * the normal history logging that happens in main().
4450 (void) zpool_log_history(g_zfs
, history_str
);
4451 log_history
= B_FALSE
;
4455 if (cbp
->cb_version
>= SPA_VERSION_FEATURES
) {
4457 ret
= upgrade_enable_all(zhp
, &count
);
4462 cbp
->cb_first
= B_FALSE
;
4468 (void) printf(gettext("\n"));
4475 upgrade_list_older_cb(zpool_handle_t
*zhp
, void *arg
)
4477 upgrade_cbdata_t
*cbp
= arg
;
4481 config
= zpool_get_config(zhp
, NULL
);
4482 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
4485 assert(SPA_VERSION_IS_SUPPORTED(version
));
4487 if (version
< SPA_VERSION_FEATURES
) {
4488 if (cbp
->cb_first
) {
4489 (void) printf(gettext("The following pools are "
4490 "formatted with legacy version numbers and can\n"
4491 "be upgraded to use feature flags. After "
4492 "being upgraded, these pools\nwill no "
4493 "longer be accessible by software that does not "
4494 "support feature\nflags.\n\n"));
4495 (void) printf(gettext("VER POOL\n"));
4496 (void) printf(gettext("--- ------------\n"));
4497 cbp
->cb_first
= B_FALSE
;
4500 (void) printf("%2llu %s\n", (u_longlong_t
)version
,
4501 zpool_get_name(zhp
));
4508 upgrade_list_disabled_cb(zpool_handle_t
*zhp
, void *arg
)
4510 upgrade_cbdata_t
*cbp
= arg
;
4514 config
= zpool_get_config(zhp
, NULL
);
4515 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
4518 if (version
>= SPA_VERSION_FEATURES
) {
4520 boolean_t poolfirst
= B_TRUE
;
4521 nvlist_t
*enabled
= zpool_get_features(zhp
);
4523 for (i
= 0; i
< SPA_FEATURES
; i
++) {
4524 const char *fguid
= spa_feature_table
[i
].fi_guid
;
4525 const char *fname
= spa_feature_table
[i
].fi_uname
;
4526 if (!nvlist_exists(enabled
, fguid
)) {
4527 if (cbp
->cb_first
) {
4528 (void) printf(gettext("\nSome "
4529 "supported features are not "
4530 "enabled on the following pools. "
4531 "Once a\nfeature is enabled the "
4532 "pool may become incompatible with "
4533 "software\nthat does not support "
4535 "zpool-features(5) for "
4537 (void) printf(gettext("POOL "
4539 (void) printf(gettext("------"
4541 cbp
->cb_first
= B_FALSE
;
4545 (void) printf(gettext("%s\n"),
4546 zpool_get_name(zhp
));
4547 poolfirst
= B_FALSE
;
4550 (void) printf(gettext(" %s\n"), fname
);
4560 upgrade_one(zpool_handle_t
*zhp
, void *data
)
4562 boolean_t printnl
= B_FALSE
;
4563 upgrade_cbdata_t
*cbp
= data
;
4564 uint64_t cur_version
;
4567 if (strcmp("log", zpool_get_name(zhp
)) == 0) {
4568 (void) printf(gettext("'log' is now a reserved word\n"
4569 "Pool 'log' must be renamed using export and import"
4574 cur_version
= zpool_get_prop_int(zhp
, ZPOOL_PROP_VERSION
, NULL
);
4575 if (cur_version
> cbp
->cb_version
) {
4576 (void) printf(gettext("Pool '%s' is already formatted "
4577 "using more current version '%llu'.\n\n"),
4578 zpool_get_name(zhp
), (u_longlong_t
) cur_version
);
4582 if (cbp
->cb_version
!= SPA_VERSION
&& cur_version
== cbp
->cb_version
) {
4583 (void) printf(gettext("Pool '%s' is already formatted "
4584 "using version %llu.\n\n"), zpool_get_name(zhp
),
4585 (u_longlong_t
) cbp
->cb_version
);
4589 if (cur_version
!= cbp
->cb_version
) {
4591 ret
= upgrade_version(zhp
, cbp
->cb_version
);
4596 if (cbp
->cb_version
>= SPA_VERSION_FEATURES
) {
4598 ret
= upgrade_enable_all(zhp
, &count
);
4604 } else if (cur_version
== SPA_VERSION
) {
4605 (void) printf(gettext("Pool '%s' already has all "
4606 "supported features enabled.\n"),
4607 zpool_get_name(zhp
));
4612 (void) printf(gettext("\n"));
4621 * zpool upgrade [-V version] <-a | pool ...>
4623 * With no arguments, display downrev'd ZFS pool available for upgrade.
4624 * Individual pools can be upgraded by specifying the pool, and '-a' will
4625 * upgrade all pools.
4628 zpool_do_upgrade(int argc
, char **argv
)
4631 upgrade_cbdata_t cb
= { 0 };
4633 boolean_t showversions
= B_FALSE
;
4634 boolean_t upgradeall
= B_FALSE
;
4639 while ((c
= getopt(argc
, argv
, ":avV:")) != -1) {
4642 upgradeall
= B_TRUE
;
4645 showversions
= B_TRUE
;
4648 cb
.cb_version
= strtoll(optarg
, &end
, 10);
4650 !SPA_VERSION_IS_SUPPORTED(cb
.cb_version
)) {
4651 (void) fprintf(stderr
,
4652 gettext("invalid version '%s'\n"), optarg
);
4657 (void) fprintf(stderr
, gettext("missing argument for "
4658 "'%c' option\n"), optopt
);
4662 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4673 if (cb
.cb_version
== 0) {
4674 cb
.cb_version
= SPA_VERSION
;
4675 } else if (!upgradeall
&& argc
== 0) {
4676 (void) fprintf(stderr
, gettext("-V option is "
4677 "incompatible with other arguments\n"));
4682 if (upgradeall
|| argc
!= 0) {
4683 (void) fprintf(stderr
, gettext("-v option is "
4684 "incompatible with other arguments\n"));
4687 } else if (upgradeall
) {
4689 (void) fprintf(stderr
, gettext("-a option should not "
4690 "be used along with a pool name\n"));
4695 (void) printf(gettext("This system supports ZFS pool feature "
4700 (void) printf(gettext("The following features are "
4702 (void) printf(gettext("FEAT DESCRIPTION\n"));
4703 (void) printf("----------------------------------------------"
4704 "---------------\n");
4705 for (i
= 0; i
< SPA_FEATURES
; i
++) {
4706 zfeature_info_t
*fi
= &spa_feature_table
[i
];
4707 const char *ro
= fi
->fi_can_readonly
?
4708 " (read-only compatible)" : "";
4710 (void) printf("%-37s%s\n", fi
->fi_uname
, ro
);
4711 (void) printf(" %s\n", fi
->fi_desc
);
4713 (void) printf("\n");
4715 (void) printf(gettext("The following legacy versions are also "
4717 (void) printf(gettext("VER DESCRIPTION\n"));
4718 (void) printf("--- -----------------------------------------"
4719 "---------------\n");
4720 (void) printf(gettext(" 1 Initial ZFS version\n"));
4721 (void) printf(gettext(" 2 Ditto blocks "
4722 "(replicated metadata)\n"));
4723 (void) printf(gettext(" 3 Hot spares and double parity "
4725 (void) printf(gettext(" 4 zpool history\n"));
4726 (void) printf(gettext(" 5 Compression using the gzip "
4728 (void) printf(gettext(" 6 bootfs pool property\n"));
4729 (void) printf(gettext(" 7 Separate intent log devices\n"));
4730 (void) printf(gettext(" 8 Delegated administration\n"));
4731 (void) printf(gettext(" 9 refquota and refreservation "
4733 (void) printf(gettext(" 10 Cache devices\n"));
4734 (void) printf(gettext(" 11 Improved scrub performance\n"));
4735 (void) printf(gettext(" 12 Snapshot properties\n"));
4736 (void) printf(gettext(" 13 snapused property\n"));
4737 (void) printf(gettext(" 14 passthrough-x aclinherit\n"));
4738 (void) printf(gettext(" 15 user/group space accounting\n"));
4739 (void) printf(gettext(" 16 stmf property support\n"));
4740 (void) printf(gettext(" 17 Triple-parity RAID-Z\n"));
4741 (void) printf(gettext(" 18 Snapshot user holds\n"));
4742 (void) printf(gettext(" 19 Log device removal\n"));
4743 (void) printf(gettext(" 20 Compression using zle "
4744 "(zero-length encoding)\n"));
4745 (void) printf(gettext(" 21 Deduplication\n"));
4746 (void) printf(gettext(" 22 Received properties\n"));
4747 (void) printf(gettext(" 23 Slim ZIL\n"));
4748 (void) printf(gettext(" 24 System attributes\n"));
4749 (void) printf(gettext(" 25 Improved scrub stats\n"));
4750 (void) printf(gettext(" 26 Improved snapshot deletion "
4752 (void) printf(gettext(" 27 Improved snapshot creation "
4754 (void) printf(gettext(" 28 Multiple vdev replacements\n"));
4755 (void) printf(gettext("\nFor more information on a particular "
4756 "version, including supported releases,\n"));
4757 (void) printf(gettext("see the ZFS Administration Guide.\n\n"));
4758 } else if (argc
== 0 && upgradeall
) {
4759 cb
.cb_first
= B_TRUE
;
4760 ret
= zpool_iter(g_zfs
, upgrade_cb
, &cb
);
4761 if (ret
== 0 && cb
.cb_first
) {
4762 if (cb
.cb_version
== SPA_VERSION
) {
4763 (void) printf(gettext("All pools are already "
4764 "formatted using feature flags.\n\n"));
4765 (void) printf(gettext("Every feature flags "
4766 "pool already has all supported features "
4769 (void) printf(gettext("All pools are already "
4770 "formatted with version %llu or higher.\n"),
4771 (u_longlong_t
) cb
.cb_version
);
4774 } else if (argc
== 0) {
4775 cb
.cb_first
= B_TRUE
;
4776 ret
= zpool_iter(g_zfs
, upgrade_list_older_cb
, &cb
);
4780 (void) printf(gettext("All pools are formatted "
4781 "using feature flags.\n\n"));
4783 (void) printf(gettext("\nUse 'zpool upgrade -v' "
4784 "for a list of available legacy versions.\n"));
4787 cb
.cb_first
= B_TRUE
;
4788 ret
= zpool_iter(g_zfs
, upgrade_list_disabled_cb
, &cb
);
4792 (void) printf(gettext("Every feature flags pool has "
4793 "all supported features enabled.\n"));
4795 (void) printf(gettext("\n"));
4798 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
,
4805 typedef struct hist_cbdata
{
4812 * Print out the command history for a specific pool.
4815 get_history_one(zpool_handle_t
*zhp
, void *data
)
4831 char internalstr
[MAXPATHLEN
];
4832 hist_cbdata_t
*cb
= (hist_cbdata_t
*)data
;
4836 cb
->first
= B_FALSE
;
4838 (void) printf(gettext("History for '%s':\n"), zpool_get_name(zhp
));
4840 if ((ret
= zpool_get_history(zhp
, &nvhis
)) != 0)
4843 verify(nvlist_lookup_nvlist_array(nvhis
, ZPOOL_HIST_RECORD
,
4844 &records
, &numrecords
) == 0);
4845 for (i
= 0; i
< numrecords
; i
++) {
4846 if (nvlist_lookup_uint64(records
[i
], ZPOOL_HIST_TIME
,
4850 /* is it an internal event or a standard event? */
4851 if (nvlist_lookup_string(records
[i
], ZPOOL_HIST_CMD
,
4853 if (cb
->internal
== 0)
4856 if (nvlist_lookup_uint64(records
[i
],
4857 ZPOOL_HIST_INT_EVENT
, &ievent
) != 0)
4859 verify(nvlist_lookup_uint64(records
[i
],
4860 ZPOOL_HIST_TXG
, &txg
) == 0);
4861 verify(nvlist_lookup_string(records
[i
],
4862 ZPOOL_HIST_INT_STR
, &pathstr
) == 0);
4863 if (ievent
>= LOG_END
)
4865 (void) snprintf(internalstr
,
4866 sizeof (internalstr
),
4867 "[internal %s txg:%llu] %s",
4868 zfs_history_event_names
[ievent
], (u_longlong_t
)txg
,
4870 cmdstr
= internalstr
;
4873 (void) localtime_r(&tsec
, &t
);
4874 (void) strftime(tbuf
, sizeof (tbuf
), "%F.%T", &t
);
4875 (void) printf("%s %s", tbuf
, cmdstr
);
4878 (void) printf("\n");
4881 (void) printf(" [");
4882 if (nvlist_lookup_uint64(records
[i
],
4883 ZPOOL_HIST_WHO
, &who
) == 0) {
4884 pwd
= getpwuid((uid_t
)who
);
4886 (void) printf("user %s on",
4889 (void) printf("user %d on",
4892 (void) printf(gettext("no info]\n"));
4895 if (nvlist_lookup_string(records
[i
],
4896 ZPOOL_HIST_HOST
, &hostname
) == 0) {
4897 (void) printf(" %s", hostname
);
4899 if (nvlist_lookup_string(records
[i
],
4900 ZPOOL_HIST_ZONE
, &zonename
) == 0) {
4901 (void) printf(":%s", zonename
);
4905 (void) printf("\n");
4907 (void) printf("\n");
4914 * zpool history <pool>
4916 * Displays the history of commands that modified pools.
4921 zpool_do_history(int argc
, char **argv
)
4923 hist_cbdata_t cbdata
= { 0 };
4927 cbdata
.first
= B_TRUE
;
4929 while ((c
= getopt(argc
, argv
, "li")) != -1) {
4935 cbdata
.internal
= 1;
4938 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4946 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
, get_history_one
,
4949 if (argc
== 0 && cbdata
.first
== B_TRUE
) {
4950 (void) fprintf(stderr
, gettext("no pools available\n"));
4957 typedef struct ev_opts
{
4965 zpool_do_events_short(nvlist_t
*nvl
)
4967 char ctime_str
[26], str
[32], *ptr
;
4971 verify(nvlist_lookup_int64_array(nvl
, FM_EREPORT_TIME
, &tv
, &n
) == 0);
4972 memset(str
, ' ', 32);
4973 (void) ctime_r((const time_t *)&tv
[0], ctime_str
);
4974 (void) strncpy(str
, ctime_str
+4, 6); /* 'Jun 30' */
4975 (void) strncpy(str
+7, ctime_str
+20, 4); /* '1993' */
4976 (void) strncpy(str
+12, ctime_str
+11, 8); /* '21:49:08' */
4977 (void) sprintf(str
+20, ".%09lld", (longlong_t
)tv
[1]);/* '.123456789' */
4978 (void) printf(gettext("%s "), str
);
4980 verify(nvlist_lookup_string(nvl
, FM_CLASS
, &ptr
) == 0);
4981 (void) printf(gettext("%s\n"), ptr
);
4985 zpool_do_events_nvprint(nvlist_t
*nvl
, int depth
)
4989 for (nvp
= nvlist_next_nvpair(nvl
, NULL
);
4990 nvp
!= NULL
; nvp
= nvlist_next_nvpair(nvl
, nvp
)) {
4992 data_type_t type
= nvpair_type(nvp
);
4993 const char *name
= nvpair_name(nvp
);
5003 printf(gettext("%*s%s = "), depth
, "", name
);
5006 case DATA_TYPE_BOOLEAN
:
5007 printf(gettext("%s"), "1");
5010 case DATA_TYPE_BOOLEAN_VALUE
:
5011 (void) nvpair_value_boolean_value(nvp
, &b
);
5012 printf(gettext("%s"), b
? "1" : "0");
5015 case DATA_TYPE_BYTE
:
5016 (void) nvpair_value_byte(nvp
, &i8
);
5017 printf(gettext("0x%x"), i8
);
5020 case DATA_TYPE_INT8
:
5021 (void) nvpair_value_int8(nvp
, (void *)&i8
);
5022 printf(gettext("0x%x"), i8
);
5025 case DATA_TYPE_UINT8
:
5026 (void) nvpair_value_uint8(nvp
, &i8
);
5027 printf(gettext("0x%x"), i8
);
5030 case DATA_TYPE_INT16
:
5031 (void) nvpair_value_int16(nvp
, (void *)&i16
);
5032 printf(gettext("0x%x"), i16
);
5035 case DATA_TYPE_UINT16
:
5036 (void) nvpair_value_uint16(nvp
, &i16
);
5037 printf(gettext("0x%x"), i16
);
5040 case DATA_TYPE_INT32
:
5041 (void) nvpair_value_int32(nvp
, (void *)&i32
);
5042 printf(gettext("0x%x"), i32
);
5045 case DATA_TYPE_UINT32
:
5046 (void) nvpair_value_uint32(nvp
, &i32
);
5047 printf(gettext("0x%x"), i32
);
5050 case DATA_TYPE_INT64
:
5051 (void) nvpair_value_int64(nvp
, (void *)&i64
);
5052 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
5055 case DATA_TYPE_UINT64
:
5056 (void) nvpair_value_uint64(nvp
, &i64
);
5057 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
5060 case DATA_TYPE_HRTIME
:
5061 (void) nvpair_value_hrtime(nvp
, (void *)&i64
);
5062 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
5065 case DATA_TYPE_STRING
:
5066 (void) nvpair_value_string(nvp
, &str
);
5067 printf(gettext("\"%s\""), str
? str
: "<NULL>");
5070 case DATA_TYPE_NVLIST
:
5071 printf(gettext("(embedded nvlist)\n"));
5072 (void) nvpair_value_nvlist(nvp
, &cnv
);
5073 zpool_do_events_nvprint(cnv
, depth
+ 8);
5074 printf(gettext("%*s(end %s)"), depth
, "", name
);
5077 case DATA_TYPE_NVLIST_ARRAY
: {
5081 (void) nvpair_value_nvlist_array(nvp
, &val
, &nelem
);
5082 printf(gettext("(%d embedded nvlists)\n"), nelem
);
5083 for (i
= 0; i
< nelem
; i
++) {
5084 printf(gettext("%*s%s[%d] = %s\n"),
5085 depth
, "", name
, i
, "(embedded nvlist)");
5086 zpool_do_events_nvprint(val
[i
], depth
+ 8);
5087 printf(gettext("%*s(end %s[%i])\n"),
5088 depth
, "", name
, i
);
5090 printf(gettext("%*s(end %s)\n"), depth
, "", name
);
5094 case DATA_TYPE_INT8_ARRAY
: {
5098 (void) nvpair_value_int8_array(nvp
, &val
, &nelem
);
5099 for (i
= 0; i
< nelem
; i
++)
5100 printf(gettext("0x%x "), val
[i
]);
5105 case DATA_TYPE_UINT8_ARRAY
: {
5109 (void) nvpair_value_uint8_array(nvp
, &val
, &nelem
);
5110 for (i
= 0; i
< nelem
; i
++)
5111 printf(gettext("0x%x "), val
[i
]);
5116 case DATA_TYPE_INT16_ARRAY
: {
5120 (void) nvpair_value_int16_array(nvp
, &val
, &nelem
);
5121 for (i
= 0; i
< nelem
; i
++)
5122 printf(gettext("0x%x "), val
[i
]);
5127 case DATA_TYPE_UINT16_ARRAY
: {
5131 (void) nvpair_value_uint16_array(nvp
, &val
, &nelem
);
5132 for (i
= 0; i
< nelem
; i
++)
5133 printf(gettext("0x%x "), val
[i
]);
5138 case DATA_TYPE_INT32_ARRAY
: {
5142 (void) nvpair_value_int32_array(nvp
, &val
, &nelem
);
5143 for (i
= 0; i
< nelem
; i
++)
5144 printf(gettext("0x%x "), val
[i
]);
5149 case DATA_TYPE_UINT32_ARRAY
: {
5153 (void) nvpair_value_uint32_array(nvp
, &val
, &nelem
);
5154 for (i
= 0; i
< nelem
; i
++)
5155 printf(gettext("0x%x "), val
[i
]);
5160 case DATA_TYPE_INT64_ARRAY
: {
5164 (void) nvpair_value_int64_array(nvp
, &val
, &nelem
);
5165 for (i
= 0; i
< nelem
; i
++)
5166 printf(gettext("0x%llx "), (u_longlong_t
)val
[i
]);
5171 case DATA_TYPE_UINT64_ARRAY
: {
5175 (void) nvpair_value_uint64_array(nvp
, &val
, &nelem
);
5176 for (i
= 0; i
< nelem
; i
++)
5177 printf(gettext("0x%llx "), (u_longlong_t
)val
[i
]);
5182 case DATA_TYPE_STRING_ARRAY
:
5183 case DATA_TYPE_BOOLEAN_ARRAY
:
5184 case DATA_TYPE_BYTE_ARRAY
:
5185 case DATA_TYPE_DOUBLE
:
5186 case DATA_TYPE_UNKNOWN
:
5187 printf(gettext("<unknown>"));
5191 printf(gettext("\n"));
5196 zpool_do_events_next(ev_opts_t
*opts
)
5199 int cleanup_fd
, ret
, dropped
;
5201 cleanup_fd
= open(ZFS_DEV
, O_RDWR
);
5202 VERIFY(cleanup_fd
>= 0);
5204 if (!opts
->scripted
)
5205 (void) printf(gettext("%-30s %s\n"), "TIME", "CLASS");
5208 ret
= zpool_events_next(g_zfs
, &nvl
, &dropped
,
5209 !!opts
->follow
, cleanup_fd
);
5210 if (ret
|| nvl
== NULL
)
5214 (void) printf(gettext("dropped %d events\n"), dropped
);
5216 zpool_do_events_short(nvl
);
5218 if (opts
->verbose
) {
5219 zpool_do_events_nvprint(nvl
, 8);
5220 printf(gettext("\n"));
5226 VERIFY(0 == close(cleanup_fd
));
5232 zpool_do_events_clear(ev_opts_t
*opts
)
5236 ret
= zpool_events_clear(g_zfs
, &count
);
5238 (void) printf(gettext("cleared %d events\n"), count
);
5244 * zpool events [-vfc]
5246 * Displays events logs by ZFS.
5249 zpool_do_events(int argc
, char **argv
)
5251 ev_opts_t opts
= { 0 };
5256 while ((c
= getopt(argc
, argv
, "vHfc")) != -1) {
5271 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5280 ret
= zpool_do_events_clear(&opts
);
5282 ret
= zpool_do_events_next(&opts
);
5288 get_callback(zpool_handle_t
*zhp
, void *data
)
5290 zprop_get_cbdata_t
*cbp
= (zprop_get_cbdata_t
*)data
;
5291 char value
[MAXNAMELEN
];
5292 zprop_source_t srctype
;
5295 for (pl
= cbp
->cb_proplist
; pl
!= NULL
; pl
= pl
->pl_next
) {
5298 * Skip the special fake placeholder. This will also skip
5299 * over the name property when 'all' is specified.
5301 if (pl
->pl_prop
== ZPOOL_PROP_NAME
&&
5302 pl
== cbp
->cb_proplist
)
5305 if (pl
->pl_prop
== ZPROP_INVAL
&&
5306 (zpool_prop_feature(pl
->pl_user_prop
) ||
5307 zpool_prop_unsupported(pl
->pl_user_prop
))) {
5308 srctype
= ZPROP_SRC_LOCAL
;
5310 if (zpool_prop_get_feature(zhp
, pl
->pl_user_prop
,
5311 value
, sizeof (value
)) == 0) {
5312 zprop_print_one_property(zpool_get_name(zhp
),
5313 cbp
, pl
->pl_user_prop
, value
, srctype
,
5317 if (zpool_get_prop(zhp
, pl
->pl_prop
, value
,
5318 sizeof (value
), &srctype
) != 0)
5321 zprop_print_one_property(zpool_get_name(zhp
), cbp
,
5322 zpool_prop_to_name(pl
->pl_prop
), value
, srctype
,
5330 zpool_do_get(int argc
, char **argv
)
5332 zprop_get_cbdata_t cb
= { 0 };
5333 zprop_list_t fake_name
= { 0 };
5337 (void) fprintf(stderr
, gettext("missing property "
5342 cb
.cb_first
= B_TRUE
;
5343 cb
.cb_sources
= ZPROP_SRC_ALL
;
5344 cb
.cb_columns
[0] = GET_COL_NAME
;
5345 cb
.cb_columns
[1] = GET_COL_PROPERTY
;
5346 cb
.cb_columns
[2] = GET_COL_VALUE
;
5347 cb
.cb_columns
[3] = GET_COL_SOURCE
;
5348 cb
.cb_type
= ZFS_TYPE_POOL
;
5350 if (zprop_get_list(g_zfs
, argv
[1], &cb
.cb_proplist
,
5351 ZFS_TYPE_POOL
) != 0)
5354 if (cb
.cb_proplist
!= NULL
) {
5355 fake_name
.pl_prop
= ZPOOL_PROP_NAME
;
5356 fake_name
.pl_width
= strlen(gettext("NAME"));
5357 fake_name
.pl_next
= cb
.cb_proplist
;
5358 cb
.cb_proplist
= &fake_name
;
5361 ret
= for_each_pool(argc
- 2, argv
+ 2, B_TRUE
, &cb
.cb_proplist
,
5364 if (cb
.cb_proplist
== &fake_name
)
5365 zprop_free_list(fake_name
.pl_next
);
5367 zprop_free_list(cb
.cb_proplist
);
5372 typedef struct set_cbdata
{
5375 boolean_t cb_any_successful
;
5379 set_callback(zpool_handle_t
*zhp
, void *data
)
5382 set_cbdata_t
*cb
= (set_cbdata_t
*)data
;
5384 error
= zpool_set_prop(zhp
, cb
->cb_propname
, cb
->cb_value
);
5387 cb
->cb_any_successful
= B_TRUE
;
5393 zpool_do_set(int argc
, char **argv
)
5395 set_cbdata_t cb
= { 0 };
5398 if (argc
> 1 && argv
[1][0] == '-') {
5399 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5405 (void) fprintf(stderr
, gettext("missing property=value "
5411 (void) fprintf(stderr
, gettext("missing pool name\n"));
5416 (void) fprintf(stderr
, gettext("too many pool names\n"));
5420 cb
.cb_propname
= argv
[1];
5421 cb
.cb_value
= strchr(cb
.cb_propname
, '=');
5422 if (cb
.cb_value
== NULL
) {
5423 (void) fprintf(stderr
, gettext("missing value in "
5424 "property=value argument\n"));
5428 *(cb
.cb_value
) = '\0';
5431 error
= for_each_pool(argc
- 2, argv
+ 2, B_TRUE
, NULL
,
5438 find_command_idx(char *command
, int *idx
)
5442 for (i
= 0; i
< NCOMMAND
; i
++) {
5443 if (command_table
[i
].name
== NULL
)
5446 if (strcmp(command
, command_table
[i
].name
) == 0) {
5455 main(int argc
, char **argv
)
5461 (void) setlocale(LC_ALL
, "");
5462 (void) textdomain(TEXT_DOMAIN
);
5467 * Make sure the user has specified some command.
5470 (void) fprintf(stderr
, gettext("missing command\n"));
5479 if ((strcmp(cmdname
, "-?") == 0) ||
5480 strcmp(cmdname
, "--help") == 0)
5483 if ((g_zfs
= libzfs_init()) == NULL
)
5486 libzfs_print_on_error(g_zfs
, B_TRUE
);
5488 zpool_set_history_str("zpool", argc
, argv
, history_str
);
5489 verify(zpool_stage_history(g_zfs
, history_str
) == 0);
5492 * Run the appropriate command.
5494 if (find_command_idx(cmdname
, &i
) == 0) {
5495 current_command
= &command_table
[i
];
5496 ret
= command_table
[i
].func(argc
- 1, argv
+ 1);
5497 } else if (strchr(cmdname
, '=')) {
5498 verify(find_command_idx("set", &i
) == 0);
5499 current_command
= &command_table
[i
];
5500 ret
= command_table
[i
].func(argc
, argv
);
5501 } else if (strcmp(cmdname
, "freeze") == 0 && argc
== 3) {
5503 * 'freeze' is a vile debugging abomination, so we treat
5507 int fd
= open(ZFS_DEV
, O_RDWR
);
5508 (void) strcpy((void *)buf
, argv
[2]);
5509 return (!!ioctl(fd
, ZFS_IOC_POOL_FREEZE
, buf
));
5511 (void) fprintf(stderr
, gettext("unrecognized "
5512 "command '%s'\n"), cmdname
);
5520 * The 'ZFS_ABORT' environment variable causes us to dump core on exit
5521 * for the purposes of running ::findleaks.
5523 if (getenv("ZFS_ABORT") != NULL
) {
5524 (void) printf("dumping core by request\n");