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) 2011, 2018 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.
28 * Copyright (c) 2013 by Prasad Joshi (sTec). All rights reserved.
29 * Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>.
30 * Copyright (c) 2017 Datto Inc.
31 * Copyright (c) 2017 Open-E, Inc. All Rights Reserved.
32 * Copyright (c) 2017, Intel Corporation.
54 #include <sys/fs/zfs.h>
56 #include <sys/systeminfo.h>
57 #include <sys/fm/fs/zfs.h>
58 #include <sys/fm/util.h>
59 #include <sys/fm/protocol.h>
60 #include <sys/zfs_ioctl.h>
61 #include <sys/mount.h>
62 #include <sys/sysmacros.h>
69 #include "zpool_util.h"
70 #include "zfs_comutil.h"
71 #include "zfeature_common.h"
73 #include "statcommon.h"
75 static int zpool_do_create(int, char **);
76 static int zpool_do_destroy(int, char **);
78 static int zpool_do_add(int, char **);
79 static int zpool_do_remove(int, char **);
80 static int zpool_do_labelclear(int, char **);
82 static int zpool_do_checkpoint(int, char **);
84 static int zpool_do_list(int, char **);
85 static int zpool_do_iostat(int, char **);
86 static int zpool_do_status(int, char **);
88 static int zpool_do_online(int, char **);
89 static int zpool_do_offline(int, char **);
90 static int zpool_do_clear(int, char **);
91 static int zpool_do_reopen(int, char **);
93 static int zpool_do_reguid(int, char **);
95 static int zpool_do_attach(int, char **);
96 static int zpool_do_detach(int, char **);
97 static int zpool_do_replace(int, char **);
98 static int zpool_do_split(int, char **);
100 static int zpool_do_initialize(int, char **);
101 static int zpool_do_scrub(int, char **);
102 static int zpool_do_resilver(int, char **);
104 static int zpool_do_import(int, char **);
105 static int zpool_do_export(int, char **);
107 static int zpool_do_upgrade(int, char **);
109 static int zpool_do_history(int, char **);
110 static int zpool_do_events(int, char **);
112 static int zpool_do_get(int, char **);
113 static int zpool_do_set(int, char **);
115 static int zpool_do_sync(int, char **);
118 * These libumem hooks provide a reasonable set of defaults for the allocator's
119 * debugging facilities.
124 _umem_debug_init(void)
126 return ("default,verbose"); /* $UMEM_DEBUG setting */
130 _umem_logging_init(void)
132 return ("fail,contents"); /* $UMEM_LOGGING setting */
170 * Flags for stats to display with "zpool iostats"
178 IOS_COUNT, /* always last element */
181 /* iostat_type entries as bitmasks */
182 #define IOS_DEFAULT_M (1ULL << IOS_DEFAULT)
183 #define IOS_LATENCY_M (1ULL << IOS_LATENCY)
184 #define IOS_QUEUES_M (1ULL << IOS_QUEUES)
185 #define IOS_L_HISTO_M (1ULL << IOS_L_HISTO)
186 #define IOS_RQ_HISTO_M (1ULL << IOS_RQ_HISTO)
188 /* Mask of all the histo bits */
189 #define IOS_ANYHISTO_M (IOS_L_HISTO_M | IOS_RQ_HISTO_M)
192 * Lookup table for iostat flags to nvlist names. Basically a list
193 * of all the nvlists a flag requires. Also specifies the order in
194 * which data gets printed in zpool iostat.
196 static const char *vsx_type_to_nvlist[IOS_COUNT][11] = {
198 ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO,
199 ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO,
200 ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO,
201 ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO,
202 ZPOOL_CONFIG_VDEV_SYNC_R_LAT_HISTO,
203 ZPOOL_CONFIG_VDEV_SYNC_W_LAT_HISTO,
204 ZPOOL_CONFIG_VDEV_ASYNC_R_LAT_HISTO,
205 ZPOOL_CONFIG_VDEV_ASYNC_W_LAT_HISTO,
206 ZPOOL_CONFIG_VDEV_SCRUB_LAT_HISTO,
209 ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO,
210 ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO,
211 ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO,
212 ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO,
215 ZPOOL_CONFIG_VDEV_SYNC_R_ACTIVE_QUEUE,
216 ZPOOL_CONFIG_VDEV_SYNC_W_ACTIVE_QUEUE,
217 ZPOOL_CONFIG_VDEV_ASYNC_R_ACTIVE_QUEUE,
218 ZPOOL_CONFIG_VDEV_ASYNC_W_ACTIVE_QUEUE,
219 ZPOOL_CONFIG_VDEV_SCRUB_ACTIVE_QUEUE,
222 ZPOOL_CONFIG_VDEV_SYNC_IND_R_HISTO,
223 ZPOOL_CONFIG_VDEV_SYNC_AGG_R_HISTO,
224 ZPOOL_CONFIG_VDEV_SYNC_IND_W_HISTO,
225 ZPOOL_CONFIG_VDEV_SYNC_AGG_W_HISTO,
226 ZPOOL_CONFIG_VDEV_ASYNC_IND_R_HISTO,
227 ZPOOL_CONFIG_VDEV_ASYNC_AGG_R_HISTO,
228 ZPOOL_CONFIG_VDEV_ASYNC_IND_W_HISTO,
229 ZPOOL_CONFIG_VDEV_ASYNC_AGG_W_HISTO,
230 ZPOOL_CONFIG_VDEV_IND_SCRUB_HISTO,
231 ZPOOL_CONFIG_VDEV_AGG_SCRUB_HISTO,
237 * Given a cb->cb_flags with a histogram bit set, return the iostat_type.
238 * Right now, only one histo bit is ever set at one time, so we can
239 * just do a highbit64(a)
241 #define IOS_HISTO_IDX(a) (highbit64(a & IOS_ANYHISTO_M) - 1)
243 typedef struct zpool_command {
245 int (*func)(int, char **);
250 * Master command table. Each ZFS command has a name, associated function, and
251 * usage message. The usage messages need to be internationalized, so we have
252 * to have a function to return the usage message based on a command index.
254 * These commands are organized according to how they are displayed in the usage
255 * message. An empty command (one with a NULL name) indicates an empty line in
256 * the generic usage message.
258 static zpool_command_t command_table[] = {
259 { "create", zpool_do_create, HELP_CREATE },
260 { "destroy", zpool_do_destroy, HELP_DESTROY },
262 { "add", zpool_do_add, HELP_ADD },
263 { "remove", zpool_do_remove, HELP_REMOVE },
265 { "labelclear", zpool_do_labelclear, HELP_LABELCLEAR },
267 { "checkpoint", zpool_do_checkpoint, HELP_CHECKPOINT },
269 { "list", zpool_do_list, HELP_LIST },
270 { "iostat", zpool_do_iostat, HELP_IOSTAT },
271 { "status", zpool_do_status, HELP_STATUS },
273 { "online", zpool_do_online, HELP_ONLINE },
274 { "offline", zpool_do_offline, HELP_OFFLINE },
275 { "clear", zpool_do_clear, HELP_CLEAR },
276 { "reopen", zpool_do_reopen, HELP_REOPEN },
278 { "attach", zpool_do_attach, HELP_ATTACH },
279 { "detach", zpool_do_detach, HELP_DETACH },
280 { "replace", zpool_do_replace, HELP_REPLACE },
281 { "split", zpool_do_split, HELP_SPLIT },
283 { "initialize", zpool_do_initialize, HELP_INITIALIZE },
284 { "scrub", zpool_do_scrub, HELP_SCRUB },
285 { "resilver", zpool_do_resilver, HELP_RESILVER },
287 { "import", zpool_do_import, HELP_IMPORT },
288 { "export", zpool_do_export, HELP_EXPORT },
289 { "upgrade", zpool_do_upgrade, HELP_UPGRADE },
290 { "reguid", zpool_do_reguid, HELP_REGUID },
292 { "history", zpool_do_history, HELP_HISTORY },
293 { "events", zpool_do_events, HELP_EVENTS },
295 { "get", zpool_do_get, HELP_GET },
296 { "set", zpool_do_set, HELP_SET },
297 { "sync", zpool_do_sync, HELP_SYNC },
300 #define NCOMMAND (ARRAY_SIZE(command_table))
302 #define VDEV_ALLOC_CLASS_LOGS "logs"
304 static zpool_command_t *current_command;
305 static char history_str[HIS_MAX_RECORD_LEN];
306 static boolean_t log_history = B_TRUE;
307 static uint_t timestamp_fmt = NODATE;
310 get_usage(zpool_help_t idx)
314 return (gettext("\tadd [-fgLnP] [-o property=value] "
315 "<pool> <vdev> ...\n"));
317 return (gettext("\tattach [-f] [-o property=value] "
318 "<pool> <device> <new-device>\n"));
320 return (gettext("\tclear [-nF] <pool> [device]\n"));
322 return (gettext("\tcreate [-fnd] [-o property=value] ... \n"
323 "\t [-O file-system-property=value] ... \n"
324 "\t [-m mountpoint] [-R root] <pool> <vdev> ...\n"));
325 case HELP_CHECKPOINT:
326 return (gettext("\tcheckpoint [--discard] <pool> ...\n"));
328 return (gettext("\tdestroy [-f] <pool>\n"));
330 return (gettext("\tdetach <pool> <device>\n"));
332 return (gettext("\texport [-af] <pool> ...\n"));
334 return (gettext("\thistory [-il] [<pool>] ...\n"));
336 return (gettext("\timport [-d dir] [-D]\n"
337 "\timport [-o mntopts] [-o property=value] ... \n"
338 "\t [-d dir | -c cachefile] [-D] [-l] [-f] [-m] [-N] "
339 "[-R root] [-F [-n]] -a\n"
340 "\timport [-o mntopts] [-o property=value] ... \n"
341 "\t [-d dir | -c cachefile] [-D] [-l] [-f] [-m] [-N] "
342 "[-R root] [-F [-n]]\n"
343 "\t [--rewind-to-checkpoint] <pool | id> [newpool]\n"));
345 return (gettext("\tiostat [[[-c [script1,script2,...]"
346 "[-lq]]|[-rw]] [-T d | u] [-ghHLpPvy]\n"
347 "\t [[pool ...]|[pool vdev ...]|[vdev ...]]"
348 " [[-n] interval [count]]\n"));
349 case HELP_LABELCLEAR:
350 return (gettext("\tlabelclear [-f] <vdev>\n"));
352 return (gettext("\tlist [-gHLpPv] [-o property[,...]] "
353 "[-T d|u] [pool] ... \n"
354 "\t [interval [count]]\n"));
356 return (gettext("\toffline [-f] [-t] <pool> <device> ...\n"));
358 return (gettext("\tonline [-e] <pool> <device> ...\n"));
360 return (gettext("\treplace [-f] [-o property=value] "
361 "<pool> <device> [new-device]\n"));
363 return (gettext("\tremove [-nps] <pool> <device> ...\n"));
365 return (gettext("\treopen [-n] <pool>\n"));
366 case HELP_INITIALIZE:
367 return (gettext("\tinitialize [-c | -s] <pool> "
368 "[<device> ...]\n"));
370 return (gettext("\tscrub [-s | -p] <pool> ...\n"));
372 return (gettext("\tresilver <pool> ...\n"));
374 return (gettext("\tstatus [-c [script1,script2,...]] "
375 "[-igLpPsvxD] [-T d|u] [pool] ... \n"
376 "\t [interval [count]]\n"));
378 return (gettext("\tupgrade\n"
380 "\tupgrade [-V version] <-a | pool ...>\n"));
382 return (gettext("\tevents [-vHf [pool] | -c]\n"));
384 return (gettext("\tget [-Hp] [-o \"all\" | field[,...]] "
385 "<\"all\" | property[,...]> <pool> ...\n"));
387 return (gettext("\tset <property=value> <pool> \n"));
389 return (gettext("\tsplit [-gLnPl] [-R altroot] [-o mntopts]\n"
390 "\t [-o property=value] <pool> <newpool> "
391 "[<device> ...]\n"));
393 return (gettext("\treguid <pool>\n"));
395 return (gettext("\tsync [pool] ...\n"));
403 zpool_collect_leaves(zpool_handle_t *zhp, nvlist_t *nvroot, nvlist_t *res)
409 (void) nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN,
413 char *path = zpool_vdev_name(g_zfs, zhp, nvroot, B_FALSE);
414 fnvlist_add_boolean(res, path);
419 for (i = 0; i < children; i++) {
420 zpool_collect_leaves(zhp, child[i], res);
425 * Callback routine that will print out a pool property value.
428 print_prop_cb(int prop, void *cb)
432 (void) fprintf(fp, "\t%-19s ", zpool_prop_to_name(prop));
434 if (zpool_prop_readonly(prop))
435 (void) fprintf(fp, " NO ");
437 (void) fprintf(fp, " YES ");
439 if (zpool_prop_values(prop) == NULL)
440 (void) fprintf(fp, "-\n");
442 (void) fprintf(fp, "%s\n", zpool_prop_values(prop));
448 * Display usage message. If we're inside a command, display only the usage for
449 * that command. Otherwise, iterate over the entire command table and display
450 * a complete usage message.
453 usage(boolean_t requested)
455 FILE *fp = requested ? stdout : stderr;
457 if (current_command == NULL) {
460 (void) fprintf(fp, gettext("usage: zpool command args ...\n"));
462 gettext("where 'command' is one of the following:\n\n"));
464 for (i = 0; i < NCOMMAND; i++) {
465 if (command_table[i].name == NULL)
466 (void) fprintf(fp, "\n");
468 (void) fprintf(fp, "%s",
469 get_usage(command_table[i].usage));
472 (void) fprintf(fp, gettext("usage:\n"));
473 (void) fprintf(fp, "%s", get_usage(current_command->usage));
476 if (current_command != NULL &&
477 ((strcmp(current_command->name, "set") == 0) ||
478 (strcmp(current_command->name, "get") == 0) ||
479 (strcmp(current_command->name, "list") == 0))) {
482 gettext("\nthe following properties are supported:\n"));
484 (void) fprintf(fp, "\n\t%-19s %s %s\n\n",
485 "PROPERTY", "EDIT", "VALUES");
487 /* Iterate over all properties */
488 (void) zprop_iter(print_prop_cb, fp, B_FALSE, B_TRUE,
491 (void) fprintf(fp, "\t%-19s ", "feature@...");
492 (void) fprintf(fp, "YES disabled | enabled | active\n");
494 (void) fprintf(fp, gettext("\nThe feature@ properties must be "
495 "appended with a feature name.\nSee zpool-features(5).\n"));
499 * See comments at end of main().
501 if (getenv("ZFS_ABORT") != NULL) {
502 (void) printf("dumping core by request\n");
506 exit(requested ? 0 : 2);
510 * zpool initialize [-c | -s] <pool> [<vdev> ...]
511 * Initialize all unused blocks in the specified vdevs, or all vdevs in the pool
514 * -c Cancel. Ends active initializing.
515 * -s Suspend. Initializing can then be restarted with no flags.
518 zpool_do_initialize(int argc, char **argv)
526 struct option long_options[] = {
527 {"cancel", no_argument, NULL, 'c'},
528 {"suspend", no_argument, NULL, 's'},
532 pool_initialize_func_t cmd_type = POOL_INITIALIZE_DO;
533 while ((c = getopt_long(argc, argv, "cs", long_options, NULL)) != -1) {
536 if (cmd_type != POOL_INITIALIZE_DO &&
537 cmd_type != POOL_INITIALIZE_CANCEL) {
538 (void) fprintf(stderr, gettext("-c cannot be "
539 "combined with other options\n"));
542 cmd_type = POOL_INITIALIZE_CANCEL;
545 if (cmd_type != POOL_INITIALIZE_DO &&
546 cmd_type != POOL_INITIALIZE_SUSPEND) {
547 (void) fprintf(stderr, gettext("-s cannot be "
548 "combined with other options\n"));
551 cmd_type = POOL_INITIALIZE_SUSPEND;
555 (void) fprintf(stderr,
556 gettext("invalid option '%c'\n"), optopt);
558 (void) fprintf(stderr,
559 gettext("invalid option '%s'\n"),
570 (void) fprintf(stderr, gettext("missing pool name argument\n"));
576 zhp = zpool_open(g_zfs, poolname);
580 vdevs = fnvlist_alloc();
582 /* no individual leaf vdevs specified, so add them all */
583 nvlist_t *config = zpool_get_config(zhp, NULL);
584 nvlist_t *nvroot = fnvlist_lookup_nvlist(config,
585 ZPOOL_CONFIG_VDEV_TREE);
586 zpool_collect_leaves(zhp, nvroot, vdevs);
589 for (i = 1; i < argc; i++) {
590 fnvlist_add_boolean(vdevs, argv[i]);
594 err = zpool_initialize(zhp, cmd_type, vdevs);
603 * print a pool vdev config for dry runs
606 print_vdev_tree(zpool_handle_t *zhp, const char *name, nvlist_t *nv, int indent,
607 const char *match, int name_flags)
612 boolean_t printed = B_FALSE;
614 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
615 &child, &children) != 0) {
617 (void) printf("\t%*s%s\n", indent, "", name);
621 for (c = 0; c < children; c++) {
622 uint64_t is_log = B_FALSE;
625 (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
628 class = VDEV_ALLOC_BIAS_LOG;
629 (void) nvlist_lookup_string(child[c],
630 ZPOOL_CONFIG_ALLOCATION_BIAS, &class);
631 if (strcmp(match, class) != 0)
634 if (!printed && name != NULL) {
635 (void) printf("\t%*s%s\n", indent, "", name);
638 vname = zpool_vdev_name(g_zfs, zhp, child[c], name_flags);
639 print_vdev_tree(zhp, vname, child[c], indent + 2, "",
646 prop_list_contains_feature(nvlist_t *proplist)
649 for (nvp = nvlist_next_nvpair(proplist, NULL); NULL != nvp;
650 nvp = nvlist_next_nvpair(proplist, nvp)) {
651 if (zpool_prop_feature(nvpair_name(nvp)))
658 * Add a property pair (name, string-value) into a property nvlist.
661 add_prop_list(const char *propname, char *propval, nvlist_t **props,
664 zpool_prop_t prop = ZPOOL_PROP_INVAL;
669 if (*props == NULL &&
670 nvlist_alloc(props, NV_UNIQUE_NAME, 0) != 0) {
671 (void) fprintf(stderr,
672 gettext("internal error: out of memory\n"));
679 const char *vname = zpool_prop_to_name(ZPOOL_PROP_VERSION);
681 if ((prop = zpool_name_to_prop(propname)) == ZPOOL_PROP_INVAL &&
682 !zpool_prop_feature(propname)) {
683 (void) fprintf(stderr, gettext("property '%s' is "
684 "not a valid pool property\n"), propname);
689 * feature@ properties and version should not be specified
692 if ((prop == ZPOOL_PROP_INVAL && zpool_prop_feature(propname) &&
693 nvlist_exists(proplist, vname)) ||
694 (prop == ZPOOL_PROP_VERSION &&
695 prop_list_contains_feature(proplist))) {
696 (void) fprintf(stderr, gettext("'feature@' and "
697 "'version' properties cannot be specified "
703 if (zpool_prop_feature(propname))
706 normnm = zpool_prop_to_name(prop);
708 zfs_prop_t fsprop = zfs_name_to_prop(propname);
710 if (zfs_prop_valid_for_type(fsprop, ZFS_TYPE_FILESYSTEM,
712 normnm = zfs_prop_to_name(fsprop);
713 } else if (zfs_prop_user(propname) ||
714 zfs_prop_userquota(propname)) {
717 (void) fprintf(stderr, gettext("property '%s' is "
718 "not a valid filesystem property\n"), propname);
723 if (nvlist_lookup_string(proplist, normnm, &strval) == 0 &&
724 prop != ZPOOL_PROP_CACHEFILE) {
725 (void) fprintf(stderr, gettext("property '%s' "
726 "specified multiple times\n"), propname);
730 if (nvlist_add_string(proplist, normnm, propval) != 0) {
731 (void) fprintf(stderr, gettext("internal "
732 "error: out of memory\n"));
740 * Set a default property pair (name, string-value) in a property nvlist
743 add_prop_list_default(const char *propname, char *propval, nvlist_t **props,
748 if (nvlist_lookup_string(*props, propname, &pval) == 0)
751 return (add_prop_list(propname, propval, props, B_TRUE));
755 * zpool add [-fgLnP] [-o property=value] <pool> <vdev> ...
757 * -f Force addition of devices, even if they appear in use
758 * -g Display guid for individual vdev name.
759 * -L Follow links when resolving vdev path name.
760 * -n Do not add the devices, but display the resulting layout if
761 * they were to be added.
762 * -o Set property=value.
763 * -P Display full path for vdev name.
765 * Adds the given vdevs to 'pool'. As with create, the bulk of this work is
766 * handled by get_vdev_spec(), which constructs the nvlist needed to pass to
770 zpool_do_add(int argc, char **argv)
772 boolean_t force = B_FALSE;
773 boolean_t dryrun = B_FALSE;
781 nvlist_t *props = NULL;
785 while ((c = getopt(argc, argv, "fgLno:P")) != -1) {
791 name_flags |= VDEV_NAME_GUID;
794 name_flags |= VDEV_NAME_FOLLOW_LINKS;
800 if ((propval = strchr(optarg, '=')) == NULL) {
801 (void) fprintf(stderr, gettext("missing "
802 "'=' for -o option\n"));
808 if ((strcmp(optarg, ZPOOL_CONFIG_ASHIFT) != 0) ||
809 (add_prop_list(optarg, propval, &props, B_TRUE)))
813 name_flags |= VDEV_NAME_PATH;
816 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
825 /* get pool name and check number of arguments */
827 (void) fprintf(stderr, gettext("missing pool name argument\n"));
831 (void) fprintf(stderr, gettext("missing vdev specification\n"));
840 if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
843 if ((config = zpool_get_config(zhp, NULL)) == NULL) {
844 (void) fprintf(stderr, gettext("pool '%s' is unavailable\n"),
850 /* unless manually specified use "ashift" pool property (if set) */
851 if (!nvlist_exists(props, ZPOOL_CONFIG_ASHIFT)) {
854 char strval[ZPOOL_MAXPROPLEN];
856 intval = zpool_get_prop_int(zhp, ZPOOL_PROP_ASHIFT, &src);
857 if (src != ZPROP_SRC_DEFAULT) {
858 (void) sprintf(strval, "%" PRId32, intval);
859 verify(add_prop_list(ZPOOL_CONFIG_ASHIFT, strval,
860 &props, B_TRUE) == 0);
864 /* pass off to get_vdev_spec for processing */
865 nvroot = make_root_vdev(zhp, props, force, !force, B_FALSE, dryrun,
867 if (nvroot == NULL) {
873 nvlist_t *poolnvroot;
875 uint_t l2children, c;
877 boolean_t hadcache = B_FALSE;
879 verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
882 (void) printf(gettext("would update '%s' to the following "
883 "configuration:\n"), zpool_get_name(zhp));
885 /* print original main pool and new tree */
886 print_vdev_tree(zhp, poolname, poolnvroot, 0, "",
887 name_flags | VDEV_NAME_TYPE_ID);
888 print_vdev_tree(zhp, NULL, nvroot, 0, "", name_flags);
890 /* print other classes: 'dedup', 'special', and 'log' */
891 print_vdev_tree(zhp, "dedup", poolnvroot, 0,
892 VDEV_ALLOC_BIAS_DEDUP, name_flags);
893 print_vdev_tree(zhp, NULL, nvroot, 0, VDEV_ALLOC_BIAS_DEDUP,
896 print_vdev_tree(zhp, "special", poolnvroot, 0,
897 VDEV_ALLOC_BIAS_SPECIAL, name_flags);
898 print_vdev_tree(zhp, NULL, nvroot, 0, VDEV_ALLOC_BIAS_SPECIAL,
901 print_vdev_tree(zhp, "logs", poolnvroot, 0, VDEV_ALLOC_BIAS_LOG,
903 print_vdev_tree(zhp, NULL, nvroot, 0, VDEV_ALLOC_BIAS_LOG,
906 /* Do the same for the caches */
907 if (nvlist_lookup_nvlist_array(poolnvroot, ZPOOL_CONFIG_L2CACHE,
908 &l2child, &l2children) == 0 && l2children) {
910 (void) printf(gettext("\tcache\n"));
911 for (c = 0; c < l2children; c++) {
912 vname = zpool_vdev_name(g_zfs, NULL,
913 l2child[c], name_flags);
914 (void) printf("\t %s\n", vname);
918 if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE,
919 &l2child, &l2children) == 0 && l2children) {
921 (void) printf(gettext("\tcache\n"));
922 for (c = 0; c < l2children; c++) {
923 vname = zpool_vdev_name(g_zfs, NULL,
924 l2child[c], name_flags);
925 (void) printf("\t %s\n", vname);
932 ret = (zpool_add(zhp, nvroot) != 0);
943 * zpool remove <pool> <vdev> ...
945 * Removes the given vdev from the pool.
948 zpool_do_remove(int argc, char **argv)
952 zpool_handle_t *zhp = NULL;
953 boolean_t stop = B_FALSE;
955 boolean_t noop = B_FALSE;
956 boolean_t parsable = B_FALSE;
959 while ((c = getopt(argc, argv, "nps")) != -1) {
971 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
980 /* get pool name and check number of arguments */
982 (void) fprintf(stderr, gettext("missing pool name argument\n"));
988 if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
992 (void) fprintf(stderr, gettext("stop request ignored\n"));
998 (void) fprintf(stderr, gettext("too many arguments\n"));
1001 if (zpool_vdev_remove_cancel(zhp) != 0)
1005 (void) fprintf(stderr, gettext("missing device\n"));
1009 for (i = 1; i < argc; i++) {
1013 if (zpool_vdev_indirect_size(zhp, argv[i],
1019 (void) printf("%s %llu\n",
1020 argv[i], (unsigned long long)size);
1023 zfs_nicenum(size, valstr,
1025 (void) printf("Memory that will be "
1026 "used after removing %s: %s\n",
1030 if (zpool_vdev_remove(zhp, argv[i]) != 0)
1041 * zpool labelclear [-f] <vdev>
1043 * -f Force clearing the label for the vdevs which are members of
1044 * the exported or foreign pools.
1046 * Verifies that the vdev is not active and zeros out the label information
1050 zpool_do_labelclear(int argc, char **argv)
1052 char vdev[MAXPATHLEN];
1055 int c, fd = -1, ret = 0;
1058 boolean_t inuse = B_FALSE;
1059 boolean_t force = B_FALSE;
1062 while ((c = getopt(argc, argv, "f")) != -1) {
1068 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
1079 (void) fprintf(stderr, gettext("missing vdev name\n"));
1083 (void) fprintf(stderr, gettext("too many arguments\n"));
1088 * Check if we were given absolute path and use it as is.
1089 * Otherwise if the provided vdev name doesn't point to a file,
1090 * try prepending expected disk paths and partition numbers.
1092 (void) strlcpy(vdev, argv[0], sizeof (vdev));
1093 if (vdev[0] != '/' && stat(vdev, &st) != 0) {
1096 error = zfs_resolve_shortname(argv[0], vdev, MAXPATHLEN);
1097 if (error == 0 && zfs_dev_is_whole_disk(vdev)) {
1098 if (zfs_append_partition(vdev, MAXPATHLEN) == -1)
1102 if (error || (stat(vdev, &st) != 0)) {
1103 (void) fprintf(stderr, gettext(
1104 "failed to find device %s, try specifying absolute "
1105 "path instead\n"), argv[0]);
1110 if ((fd = open(vdev, O_RDWR)) < 0) {
1111 (void) fprintf(stderr, gettext("failed to open %s: %s\n"),
1112 vdev, strerror(errno));
1116 if (ioctl(fd, BLKFLSBUF) != 0)
1117 (void) fprintf(stderr, gettext("failed to invalidate "
1118 "cache for %s: %s\n"), vdev, strerror(errno));
1120 if (zpool_read_label(fd, &config, NULL) != 0 || config == NULL) {
1121 (void) fprintf(stderr,
1122 gettext("failed to check state for %s\n"), vdev);
1126 nvlist_free(config);
1128 ret = zpool_in_use(g_zfs, fd, &state, &name, &inuse);
1130 (void) fprintf(stderr,
1131 gettext("failed to check state for %s\n"), vdev);
1141 case POOL_STATE_ACTIVE:
1142 case POOL_STATE_SPARE:
1143 case POOL_STATE_L2CACHE:
1144 (void) fprintf(stderr, gettext(
1145 "%s is a member (%s) of pool \"%s\"\n"),
1146 vdev, zpool_pool_state_to_name(state), name);
1150 case POOL_STATE_EXPORTED:
1153 (void) fprintf(stderr, gettext(
1154 "use '-f' to override the following error:\n"
1155 "%s is a member of exported pool \"%s\"\n"),
1160 case POOL_STATE_POTENTIALLY_ACTIVE:
1163 (void) fprintf(stderr, gettext(
1164 "use '-f' to override the following error:\n"
1165 "%s is a member of potentially active pool \"%s\"\n"),
1170 case POOL_STATE_DESTROYED:
1171 /* inuse should never be set for a destroyed pool */
1177 ret = zpool_clear_label(fd);
1179 (void) fprintf(stderr,
1180 gettext("failed to clear label for %s\n"), vdev);
1191 * zpool create [-fnd] [-o property=value] ...
1192 * [-O file-system-property=value] ...
1193 * [-R root] [-m mountpoint] <pool> <dev> ...
1195 * -f Force creation, even if devices appear in use
1196 * -n Do not create the pool, but display the resulting layout if it
1197 * were to be created.
1198 * -R Create a pool under an alternate root
1199 * -m Set default mountpoint for the root dataset. By default it's
1201 * -o Set property=value.
1202 * -o Set feature@feature=enabled|disabled.
1203 * -d Don't automatically enable all supported pool features
1204 * (individual features can be enabled with -o).
1205 * -O Set fsproperty=value in the pool's root file system
1207 * Creates the named pool according to the given vdev specification. The
1208 * bulk of the vdev processing is done in get_vdev_spec() in zpool_vdev.c. Once
1209 * we get the nvlist back from get_vdev_spec(), we either print out the contents
1210 * (if '-n' was specified), or pass it to libzfs to do the creation.
1213 zpool_do_create(int argc, char **argv)
1215 boolean_t force = B_FALSE;
1216 boolean_t dryrun = B_FALSE;
1217 boolean_t enable_all_pool_feat = B_TRUE;
1219 nvlist_t *nvroot = NULL;
1223 char *altroot = NULL;
1224 char *mountpoint = NULL;
1225 nvlist_t *fsprops = NULL;
1226 nvlist_t *props = NULL;
1230 while ((c = getopt(argc, argv, ":fndR:m:o:O:t:")) != -1) {
1239 enable_all_pool_feat = B_FALSE;
1243 if (add_prop_list(zpool_prop_to_name(
1244 ZPOOL_PROP_ALTROOT), optarg, &props, B_TRUE))
1246 if (add_prop_list_default(zpool_prop_to_name(
1247 ZPOOL_PROP_CACHEFILE), "none", &props, B_TRUE))
1251 /* Equivalent to -O mountpoint=optarg */
1252 mountpoint = optarg;
1255 if ((propval = strchr(optarg, '=')) == NULL) {
1256 (void) fprintf(stderr, gettext("missing "
1257 "'=' for -o option\n"));
1263 if (add_prop_list(optarg, propval, &props, B_TRUE))
1267 * If the user is creating a pool that doesn't support
1268 * feature flags, don't enable any features.
1270 if (zpool_name_to_prop(optarg) == ZPOOL_PROP_VERSION) {
1274 ver = strtoull(propval, &end, 10);
1276 ver < SPA_VERSION_FEATURES) {
1277 enable_all_pool_feat = B_FALSE;
1280 if (zpool_name_to_prop(optarg) == ZPOOL_PROP_ALTROOT)
1284 if ((propval = strchr(optarg, '=')) == NULL) {
1285 (void) fprintf(stderr, gettext("missing "
1286 "'=' for -O option\n"));
1293 * Mountpoints are checked and then added later.
1294 * Uniquely among properties, they can be specified
1295 * more than once, to avoid conflict with -m.
1297 if (0 == strcmp(optarg,
1298 zfs_prop_to_name(ZFS_PROP_MOUNTPOINT))) {
1299 mountpoint = propval;
1300 } else if (add_prop_list(optarg, propval, &fsprops,
1307 * Sanity check temporary pool name.
1309 if (strchr(optarg, '/') != NULL) {
1310 (void) fprintf(stderr, gettext("cannot create "
1311 "'%s': invalid character '/' in temporary "
1313 (void) fprintf(stderr, gettext("use 'zfs "
1314 "create' to create a dataset\n"));
1318 if (add_prop_list(zpool_prop_to_name(
1319 ZPOOL_PROP_TNAME), optarg, &props, B_TRUE))
1321 if (add_prop_list_default(zpool_prop_to_name(
1322 ZPOOL_PROP_CACHEFILE), "none", &props, B_TRUE))
1327 (void) fprintf(stderr, gettext("missing argument for "
1328 "'%c' option\n"), optopt);
1331 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
1340 /* get pool name and check number of arguments */
1342 (void) fprintf(stderr, gettext("missing pool name argument\n"));
1346 (void) fprintf(stderr, gettext("missing vdev specification\n"));
1353 * As a special case, check for use of '/' in the name, and direct the
1354 * user to use 'zfs create' instead.
1356 if (strchr(poolname, '/') != NULL) {
1357 (void) fprintf(stderr, gettext("cannot create '%s': invalid "
1358 "character '/' in pool name\n"), poolname);
1359 (void) fprintf(stderr, gettext("use 'zfs create' to "
1360 "create a dataset\n"));
1364 /* pass off to get_vdev_spec for bulk processing */
1365 nvroot = make_root_vdev(NULL, props, force, !force, B_FALSE, dryrun,
1366 argc - 1, argv + 1);
1370 /* make_root_vdev() allows 0 toplevel children if there are spares */
1371 if (!zfs_allocatable_devs(nvroot)) {
1372 (void) fprintf(stderr, gettext("invalid vdev "
1373 "specification: at least one toplevel vdev must be "
1378 if (altroot != NULL && altroot[0] != '/') {
1379 (void) fprintf(stderr, gettext("invalid alternate root '%s': "
1380 "must be an absolute path\n"), altroot);
1385 * Check the validity of the mountpoint and direct the user to use the
1386 * '-m' mountpoint option if it looks like its in use.
1388 if (mountpoint == NULL ||
1389 (strcmp(mountpoint, ZFS_MOUNTPOINT_LEGACY) != 0 &&
1390 strcmp(mountpoint, ZFS_MOUNTPOINT_NONE) != 0)) {
1391 char buf[MAXPATHLEN];
1394 if (mountpoint && mountpoint[0] != '/') {
1395 (void) fprintf(stderr, gettext("invalid mountpoint "
1396 "'%s': must be an absolute path, 'legacy', or "
1397 "'none'\n"), mountpoint);
1401 if (mountpoint == NULL) {
1402 if (altroot != NULL)
1403 (void) snprintf(buf, sizeof (buf), "%s/%s",
1406 (void) snprintf(buf, sizeof (buf), "/%s",
1409 if (altroot != NULL)
1410 (void) snprintf(buf, sizeof (buf), "%s%s",
1411 altroot, mountpoint);
1413 (void) snprintf(buf, sizeof (buf), "%s",
1417 if ((dirp = opendir(buf)) == NULL && errno != ENOENT) {
1418 (void) fprintf(stderr, gettext("mountpoint '%s' : "
1419 "%s\n"), buf, strerror(errno));
1420 (void) fprintf(stderr, gettext("use '-m' "
1421 "option to provide a different default\n"));
1426 while (count < 3 && readdir(dirp) != NULL)
1428 (void) closedir(dirp);
1431 (void) fprintf(stderr, gettext("mountpoint "
1432 "'%s' exists and is not empty\n"), buf);
1433 (void) fprintf(stderr, gettext("use '-m' "
1434 "option to provide a "
1435 "different default\n"));
1442 * Now that the mountpoint's validity has been checked, ensure that
1443 * the property is set appropriately prior to creating the pool.
1445 if (mountpoint != NULL) {
1446 ret = add_prop_list(zfs_prop_to_name(ZFS_PROP_MOUNTPOINT),
1447 mountpoint, &fsprops, B_FALSE);
1455 * For a dry run invocation, print out a basic message and run
1456 * through all the vdevs in the list and print out in an
1457 * appropriate hierarchy.
1459 (void) printf(gettext("would create '%s' with the "
1460 "following layout:\n\n"), poolname);
1462 print_vdev_tree(NULL, poolname, nvroot, 0, "", 0);
1463 print_vdev_tree(NULL, "dedup", nvroot, 0,
1464 VDEV_ALLOC_BIAS_DEDUP, 0);
1465 print_vdev_tree(NULL, "special", nvroot, 0,
1466 VDEV_ALLOC_BIAS_SPECIAL, 0);
1467 print_vdev_tree(NULL, "logs", nvroot, 0,
1468 VDEV_ALLOC_BIAS_LOG, 0);
1473 * Hand off to libzfs.
1476 for (i = 0; i < SPA_FEATURES; i++) {
1477 char propname[MAXPATHLEN];
1479 zfeature_info_t *feat = &spa_feature_table[i];
1481 (void) snprintf(propname, sizeof (propname),
1482 "feature@%s", feat->fi_uname);
1485 * Only features contained in props will be enabled:
1486 * remove from the nvlist every ZFS_FEATURE_DISABLED
1487 * value and add every missing ZFS_FEATURE_ENABLED if
1488 * enable_all_pool_feat is set.
1490 if (!nvlist_lookup_string(props, propname, &propval)) {
1491 if (strcmp(propval, ZFS_FEATURE_DISABLED) == 0)
1492 (void) nvlist_remove_all(props,
1494 } else if (enable_all_pool_feat) {
1495 ret = add_prop_list(propname,
1496 ZFS_FEATURE_ENABLED, &props, B_TRUE);
1503 if (zpool_create(g_zfs, poolname,
1504 nvroot, props, fsprops) == 0) {
1505 zfs_handle_t *pool = zfs_open(g_zfs,
1506 tname ? tname : poolname, ZFS_TYPE_FILESYSTEM);
1508 if (zfs_mount(pool, NULL, 0) == 0)
1509 ret = zfs_shareall(pool);
1512 } else if (libzfs_errno(g_zfs) == EZFS_INVALIDNAME) {
1513 (void) fprintf(stderr, gettext("pool name may have "
1519 nvlist_free(nvroot);
1520 nvlist_free(fsprops);
1524 nvlist_free(fsprops);
1531 * zpool destroy <pool>
1533 * -f Forcefully unmount any datasets
1535 * Destroy the given pool. Automatically unmounts any datasets in the pool.
1538 zpool_do_destroy(int argc, char **argv)
1540 boolean_t force = B_FALSE;
1543 zpool_handle_t *zhp;
1547 while ((c = getopt(argc, argv, "f")) != -1) {
1553 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
1562 /* check arguments */
1564 (void) fprintf(stderr, gettext("missing pool argument\n"));
1568 (void) fprintf(stderr, gettext("too many arguments\n"));
1574 if ((zhp = zpool_open_canfail(g_zfs, pool)) == NULL) {
1576 * As a special case, check for use of '/' in the name, and
1577 * direct the user to use 'zfs destroy' instead.
1579 if (strchr(pool, '/') != NULL)
1580 (void) fprintf(stderr, gettext("use 'zfs destroy' to "
1581 "destroy a dataset\n"));
1585 if (zpool_disable_datasets(zhp, force) != 0) {
1586 (void) fprintf(stderr, gettext("could not destroy '%s': "
1587 "could not unmount datasets\n"), zpool_get_name(zhp));
1592 /* The history must be logged as part of the export */
1593 log_history = B_FALSE;
1595 ret = (zpool_destroy(zhp, history_str) != 0);
1602 typedef struct export_cbdata {
1604 boolean_t hardforce;
1611 zpool_export_one(zpool_handle_t *zhp, void *data)
1613 export_cbdata_t *cb = data;
1615 if (zpool_disable_datasets(zhp, cb->force) != 0)
1618 /* The history must be logged as part of the export */
1619 log_history = B_FALSE;
1621 if (cb->hardforce) {
1622 if (zpool_export_force(zhp, history_str) != 0)
1624 } else if (zpool_export(zhp, cb->force, history_str) != 0) {
1632 * zpool export [-f] <pool> ...
1634 * -a Export all pools
1635 * -f Forcefully unmount datasets
1637 * Export the given pools. By default, the command will attempt to cleanly
1638 * unmount any active datasets within the pool. If the '-f' flag is specified,
1639 * then the datasets will be forcefully unmounted.
1642 zpool_do_export(int argc, char **argv)
1645 boolean_t do_all = B_FALSE;
1646 boolean_t force = B_FALSE;
1647 boolean_t hardforce = B_FALSE;
1651 while ((c = getopt(argc, argv, "afF")) != -1) {
1663 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
1670 cb.hardforce = hardforce;
1676 (void) fprintf(stderr, gettext("too many arguments\n"));
1680 return (for_each_pool(argc, argv, B_TRUE, NULL,
1681 zpool_export_one, &cb));
1684 /* check arguments */
1686 (void) fprintf(stderr, gettext("missing pool argument\n"));
1690 ret = for_each_pool(argc, argv, B_TRUE, NULL, zpool_export_one, &cb);
1696 * Given a vdev configuration, determine the maximum width needed for the device
1700 max_width(zpool_handle_t *zhp, nvlist_t *nv, int depth, int max,
1708 name = zpool_vdev_name(g_zfs, zhp, nv, name_flags);
1709 if (strlen(name) + depth > max)
1710 max = strlen(name) + depth;
1714 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
1715 &child, &children) == 0) {
1716 for (c = 0; c < children; c++)
1717 if ((ret = max_width(zhp, child[c], depth + 2,
1718 max, name_flags)) > max)
1722 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
1723 &child, &children) == 0) {
1724 for (c = 0; c < children; c++)
1725 if ((ret = max_width(zhp, child[c], depth + 2,
1726 max, name_flags)) > max)
1730 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
1731 &child, &children) == 0) {
1732 for (c = 0; c < children; c++)
1733 if ((ret = max_width(zhp, child[c], depth + 2,
1734 max, name_flags)) > max)
1741 typedef struct spare_cbdata {
1743 zpool_handle_t *cb_zhp;
1747 find_vdev(nvlist_t *nv, uint64_t search)
1753 if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) == 0 &&
1757 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
1758 &child, &children) == 0) {
1759 for (c = 0; c < children; c++)
1760 if (find_vdev(child[c], search))
1768 find_spare(zpool_handle_t *zhp, void *data)
1770 spare_cbdata_t *cbp = data;
1771 nvlist_t *config, *nvroot;
1773 config = zpool_get_config(zhp, NULL);
1774 verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
1777 if (find_vdev(nvroot, cbp->cb_guid)) {
1786 typedef struct status_cbdata {
1790 boolean_t cb_allpools;
1791 boolean_t cb_verbose;
1792 boolean_t cb_literal;
1793 boolean_t cb_explain;
1795 boolean_t cb_dedup_stats;
1796 boolean_t cb_print_status;
1797 boolean_t cb_print_slow_ios;
1798 boolean_t cb_print_vdev_init;
1799 vdev_cmd_data_list_t *vcdl;
1802 /* Return 1 if string is NULL, empty, or whitespace; return 0 otherwise. */
1804 is_blank_str(char *str)
1806 while (str != NULL && *str != '\0') {
1814 /* Print command output lines for specific vdev in a specific pool */
1816 zpool_print_cmd(vdev_cmd_data_list_t *vcdl, const char *pool, char *path)
1818 vdev_cmd_data_t *data;
1822 for (i = 0; i < vcdl->count; i++) {
1823 if ((strcmp(vcdl->data[i].path, path) != 0) ||
1824 (strcmp(vcdl->data[i].pool, pool) != 0)) {
1825 /* Not the vdev we're looking for */
1829 data = &vcdl->data[i];
1830 /* Print out all the output values for this vdev */
1831 for (j = 0; j < vcdl->uniq_cols_cnt; j++) {
1833 /* Does this vdev have values for this column? */
1834 for (int k = 0; k < data->cols_cnt; k++) {
1835 if (strcmp(data->cols[k],
1836 vcdl->uniq_cols[j]) == 0) {
1837 /* yes it does, record the value */
1838 val = data->lines[k];
1843 * Mark empty values with dashes to make output
1846 if (is_blank_str(val))
1849 printf("%*s", vcdl->uniq_cols_width[j], val);
1850 if (j < vcdl->uniq_cols_cnt - 1)
1854 /* Print out any values that aren't in a column at the end */
1855 for (j = data->cols_cnt; j < data->lines_cnt; j++) {
1856 /* Did we have any columns? If so print a spacer. */
1857 if (vcdl->uniq_cols_cnt > 0)
1860 val = data->lines[j];
1861 printf("%s", val ? val : "");
1868 * Print out configuration state as requested by status_callback.
1871 print_status_config(zpool_handle_t *zhp, status_cbdata_t *cb, const char *name,
1872 nvlist_t *nv, int depth, boolean_t isspare)
1874 nvlist_t **child, *root;
1876 pool_scan_stat_t *ps = NULL;
1878 char rbuf[6], wbuf[6], cbuf[6];
1880 uint64_t notpresent;
1881 spare_cbdata_t spare_cb;
1886 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
1887 &child, &children) != 0)
1890 verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
1891 (uint64_t **)&vs, &c) == 0);
1893 verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) == 0);
1895 if (strcmp(type, VDEV_TYPE_INDIRECT) == 0)
1898 state = zpool_state_to_name(vs->vs_state, vs->vs_aux);
1901 * For hot spares, we use the terms 'INUSE' and 'AVAILABLE' for
1904 if (vs->vs_aux == VDEV_AUX_SPARED)
1906 else if (vs->vs_state == VDEV_STATE_HEALTHY)
1910 (void) printf("\t%*s%-*s %-8s", depth, "", cb->cb_namewidth - depth,
1914 if (cb->cb_literal) {
1915 printf(" %5llu %5llu %5llu",
1916 (u_longlong_t)vs->vs_read_errors,
1917 (u_longlong_t)vs->vs_write_errors,
1918 (u_longlong_t)vs->vs_checksum_errors);
1920 zfs_nicenum(vs->vs_read_errors, rbuf, sizeof (rbuf));
1921 zfs_nicenum(vs->vs_write_errors, wbuf, sizeof (wbuf));
1922 zfs_nicenum(vs->vs_checksum_errors, cbuf,
1924 printf(" %5s %5s %5s", rbuf, wbuf, cbuf);
1927 if (cb->cb_print_slow_ios) {
1928 if (children == 0) {
1929 /* Only leafs vdevs have slow IOs */
1930 zfs_nicenum(vs->vs_slow_ios, rbuf,
1933 snprintf(rbuf, sizeof (rbuf), "-");
1937 printf(" %5llu", (u_longlong_t)vs->vs_slow_ios);
1939 printf(" %5s", rbuf);
1944 if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT,
1945 ¬present) == 0) {
1946 verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0);
1947 (void) printf(" was %s", path);
1948 } else if (vs->vs_aux != 0) {
1951 switch (vs->vs_aux) {
1952 case VDEV_AUX_OPEN_FAILED:
1953 (void) printf(gettext("cannot open"));
1956 case VDEV_AUX_BAD_GUID_SUM:
1957 (void) printf(gettext("missing device"));
1960 case VDEV_AUX_NO_REPLICAS:
1961 (void) printf(gettext("insufficient replicas"));
1964 case VDEV_AUX_VERSION_NEWER:
1965 (void) printf(gettext("newer version"));
1968 case VDEV_AUX_UNSUP_FEAT:
1969 (void) printf(gettext("unsupported feature(s)"));
1972 case VDEV_AUX_SPARED:
1973 verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID,
1974 &spare_cb.cb_guid) == 0);
1975 if (zpool_iter(g_zfs, find_spare, &spare_cb) == 1) {
1976 if (strcmp(zpool_get_name(spare_cb.cb_zhp),
1977 zpool_get_name(zhp)) == 0)
1978 (void) printf(gettext("currently in "
1981 (void) printf(gettext("in use by "
1983 zpool_get_name(spare_cb.cb_zhp));
1984 zpool_close(spare_cb.cb_zhp);
1986 (void) printf(gettext("currently in use"));
1990 case VDEV_AUX_ERR_EXCEEDED:
1991 (void) printf(gettext("too many errors"));
1994 case VDEV_AUX_IO_FAILURE:
1995 (void) printf(gettext("experienced I/O failures"));
1998 case VDEV_AUX_BAD_LOG:
1999 (void) printf(gettext("bad intent log"));
2002 case VDEV_AUX_EXTERNAL:
2003 (void) printf(gettext("external device fault"));
2006 case VDEV_AUX_SPLIT_POOL:
2007 (void) printf(gettext("split into new pool"));
2010 case VDEV_AUX_ACTIVE:
2011 (void) printf(gettext("currently in use"));
2014 case VDEV_AUX_CHILDREN_OFFLINE:
2015 (void) printf(gettext("all children offline"));
2019 (void) printf(gettext("corrupted data"));
2024 /* The root vdev has the scrub/resilver stats */
2025 root = fnvlist_lookup_nvlist(zpool_get_config(zhp, NULL),
2026 ZPOOL_CONFIG_VDEV_TREE);
2027 (void) nvlist_lookup_uint64_array(root, ZPOOL_CONFIG_SCAN_STATS,
2028 (uint64_t **)&ps, &c);
2030 if (ps != NULL && ps->pss_state == DSS_SCANNING && children == 0) {
2031 if (vs->vs_scan_processed != 0) {
2032 (void) printf(gettext(" (%s)"),
2033 (ps->pss_func == POOL_SCAN_RESILVER) ?
2034 "resilvering" : "repairing");
2035 } else if (vs->vs_resilver_deferred) {
2036 (void) printf(gettext(" (awaiting resilver)"));
2040 if (cb->vcdl != NULL) {
2041 if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0) {
2043 zpool_print_cmd(cb->vcdl, zpool_get_name(zhp), path);
2047 /* Optionally display vdev initialization status for leaves */
2048 if (cb->cb_print_vdev_init && children == 0) {
2049 if ((vs->vs_initialize_state == VDEV_INITIALIZE_ACTIVE ||
2050 vs->vs_initialize_state == VDEV_INITIALIZE_SUSPENDED ||
2051 vs->vs_initialize_state == VDEV_INITIALIZE_COMPLETE) &&
2052 !vs->vs_scan_removing) {
2055 struct tm zaction_ts;
2057 time_t t = vs->vs_initialize_action_time;
2058 int initialize_pct = 100;
2059 if (vs->vs_initialize_state !=
2060 VDEV_INITIALIZE_COMPLETE) {
2061 initialize_pct = (vs->vs_initialize_bytes_done *
2062 100 / (vs->vs_initialize_bytes_est + 1));
2065 (void) localtime_r(&t, &zaction_ts);
2066 (void) strftime(tbuf, sizeof (tbuf), "%c", &zaction_ts);
2068 switch (vs->vs_initialize_state) {
2069 case VDEV_INITIALIZE_SUSPENDED:
2070 (void) snprintf(zbuf, sizeof (zbuf),
2071 ", suspended, started at %s", tbuf);
2073 case VDEV_INITIALIZE_ACTIVE:
2074 (void) snprintf(zbuf, sizeof (zbuf),
2075 ", started at %s", tbuf);
2077 case VDEV_INITIALIZE_COMPLETE:
2078 (void) snprintf(zbuf, sizeof (zbuf),
2079 ", completed at %s", tbuf);
2083 (void) printf(gettext(" (%d%% initialized%s)"),
2084 initialize_pct, zbuf);
2086 (void) printf(gettext(" (uninitialized)"));
2089 if (vs->vs_initialize_state == VDEV_INITIALIZE_ACTIVE &&
2091 (void) printf(gettext(" (initializing)"));
2095 (void) printf("\n");
2097 for (c = 0; c < children; c++) {
2098 uint64_t islog = B_FALSE, ishole = B_FALSE;
2100 /* Don't print logs or holes here */
2101 (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
2103 (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_HOLE,
2105 if (islog || ishole)
2107 /* Only print normal classes here */
2108 if (nvlist_exists(child[c], ZPOOL_CONFIG_ALLOCATION_BIAS))
2111 vname = zpool_vdev_name(g_zfs, zhp, child[c],
2112 cb->cb_name_flags | VDEV_NAME_TYPE_ID);
2114 print_status_config(zhp, cb, vname, child[c], depth + 2,
2121 * Print the configuration of an exported pool. Iterate over all vdevs in the
2122 * pool, printing out the name and status for each one.
2125 print_import_config(status_cbdata_t *cb, const char *name, nvlist_t *nv,
2133 verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) == 0);
2134 if (strcmp(type, VDEV_TYPE_MISSING) == 0 ||
2135 strcmp(type, VDEV_TYPE_HOLE) == 0)
2138 verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
2139 (uint64_t **)&vs, &c) == 0);
2141 (void) printf("\t%*s%-*s", depth, "", cb->cb_namewidth - depth, name);
2142 (void) printf(" %s", zpool_state_to_name(vs->vs_state, vs->vs_aux));
2144 if (vs->vs_aux != 0) {
2147 switch (vs->vs_aux) {
2148 case VDEV_AUX_OPEN_FAILED:
2149 (void) printf(gettext("cannot open"));
2152 case VDEV_AUX_BAD_GUID_SUM:
2153 (void) printf(gettext("missing device"));
2156 case VDEV_AUX_NO_REPLICAS:
2157 (void) printf(gettext("insufficient replicas"));
2160 case VDEV_AUX_VERSION_NEWER:
2161 (void) printf(gettext("newer version"));
2164 case VDEV_AUX_UNSUP_FEAT:
2165 (void) printf(gettext("unsupported feature(s)"));
2168 case VDEV_AUX_ERR_EXCEEDED:
2169 (void) printf(gettext("too many errors"));
2172 case VDEV_AUX_ACTIVE:
2173 (void) printf(gettext("currently in use"));
2176 case VDEV_AUX_CHILDREN_OFFLINE:
2177 (void) printf(gettext("all children offline"));
2181 (void) printf(gettext("corrupted data"));
2185 (void) printf("\n");
2187 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
2188 &child, &children) != 0)
2191 for (c = 0; c < children; c++) {
2192 uint64_t is_log = B_FALSE;
2194 (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
2198 if (nvlist_exists(child[c], ZPOOL_CONFIG_ALLOCATION_BIAS))
2201 vname = zpool_vdev_name(g_zfs, NULL, child[c],
2202 cb->cb_name_flags | VDEV_NAME_TYPE_ID);
2203 print_import_config(cb, vname, child[c], depth + 2);
2207 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
2208 &child, &children) == 0) {
2209 (void) printf(gettext("\tcache\n"));
2210 for (c = 0; c < children; c++) {
2211 vname = zpool_vdev_name(g_zfs, NULL, child[c],
2213 (void) printf("\t %s\n", vname);
2218 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
2219 &child, &children) == 0) {
2220 (void) printf(gettext("\tspares\n"));
2221 for (c = 0; c < children; c++) {
2222 vname = zpool_vdev_name(g_zfs, NULL, child[c],
2224 (void) printf("\t %s\n", vname);
2231 * Print specialized class vdevs.
2233 * These are recorded as top level vdevs in the main pool child array
2234 * but with "is_log" set to 1 or an "alloc_bias" string. We use either
2235 * print_status_config() or print_import_config() to print the top level
2236 * class vdevs then any of their children (eg mirrored slogs) are printed
2237 * recursively - which works because only the top level vdev is marked.
2240 print_class_vdevs(zpool_handle_t *zhp, status_cbdata_t *cb, nvlist_t *nv,
2245 boolean_t printed = B_FALSE;
2247 assert(zhp != NULL || !cb->cb_verbose);
2249 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN, &child,
2253 for (c = 0; c < children; c++) {
2254 uint64_t is_log = B_FALSE;
2258 (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
2262 bias = VDEV_ALLOC_CLASS_LOGS;
2264 (void) nvlist_lookup_string(child[c],
2265 ZPOOL_CONFIG_ALLOCATION_BIAS, &bias);
2266 (void) nvlist_lookup_string(child[c],
2267 ZPOOL_CONFIG_TYPE, &type);
2270 if (bias == NULL || strcmp(bias, class) != 0)
2272 if (!is_log && strcmp(type, VDEV_TYPE_INDIRECT) == 0)
2276 (void) printf("\t%s\t\n", gettext(class));
2280 char *name = zpool_vdev_name(g_zfs, zhp, child[c],
2281 cb->cb_name_flags | VDEV_NAME_TYPE_ID);
2282 if (cb->cb_print_status)
2283 print_status_config(zhp, cb, name, child[c], 2,
2286 print_import_config(cb, name, child[c], 2);
2292 * Display the status for the given pool.
2295 show_import(nvlist_t *config)
2297 uint64_t pool_state;
2301 uint64_t hostid = 0;
2303 char *hostname = "unknown";
2304 nvlist_t *nvroot, *nvinfo;
2305 zpool_status_t reason;
2306 zpool_errata_t errata;
2310 status_cbdata_t cb = { 0 };
2312 verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
2314 verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID,
2316 verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
2318 verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
2321 verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_VDEV_STATS,
2322 (uint64_t **)&vs, &vsc) == 0);
2323 health = zpool_state_to_name(vs->vs_state, vs->vs_aux);
2325 reason = zpool_import_status(config, &msgid, &errata);
2327 (void) printf(gettext(" pool: %s\n"), name);
2328 (void) printf(gettext(" id: %llu\n"), (u_longlong_t)guid);
2329 (void) printf(gettext(" state: %s"), health);
2330 if (pool_state == POOL_STATE_DESTROYED)
2331 (void) printf(gettext(" (DESTROYED)"));
2332 (void) printf("\n");
2335 case ZPOOL_STATUS_MISSING_DEV_R:
2336 case ZPOOL_STATUS_MISSING_DEV_NR:
2337 case ZPOOL_STATUS_BAD_GUID_SUM:
2338 (void) printf(gettext(" status: One or more devices are "
2339 "missing from the system.\n"));
2342 case ZPOOL_STATUS_CORRUPT_LABEL_R:
2343 case ZPOOL_STATUS_CORRUPT_LABEL_NR:
2344 (void) printf(gettext(" status: One or more devices contains "
2345 "corrupted data.\n"));
2348 case ZPOOL_STATUS_CORRUPT_DATA:
2350 gettext(" status: The pool data is corrupted.\n"));
2353 case ZPOOL_STATUS_OFFLINE_DEV:
2354 (void) printf(gettext(" status: One or more devices "
2355 "are offlined.\n"));
2358 case ZPOOL_STATUS_CORRUPT_POOL:
2359 (void) printf(gettext(" status: The pool metadata is "
2363 case ZPOOL_STATUS_VERSION_OLDER:
2364 (void) printf(gettext(" status: The pool is formatted using a "
2365 "legacy on-disk version.\n"));
2368 case ZPOOL_STATUS_VERSION_NEWER:
2369 (void) printf(gettext(" status: The pool is formatted using an "
2370 "incompatible version.\n"));
2373 case ZPOOL_STATUS_FEAT_DISABLED:
2374 (void) printf(gettext(" status: Some supported features are "
2375 "not enabled on the pool.\n"));
2378 case ZPOOL_STATUS_UNSUP_FEAT_READ:
2379 (void) printf(gettext("status: The pool uses the following "
2380 "feature(s) not supported on this system:\n"));
2381 zpool_print_unsup_feat(config);
2384 case ZPOOL_STATUS_UNSUP_FEAT_WRITE:
2385 (void) printf(gettext("status: The pool can only be accessed "
2386 "in read-only mode on this system. It\n\tcannot be "
2387 "accessed in read-write mode because it uses the "
2388 "following\n\tfeature(s) not supported on this system:\n"));
2389 zpool_print_unsup_feat(config);
2392 case ZPOOL_STATUS_HOSTID_ACTIVE:
2393 (void) printf(gettext(" status: The pool is currently "
2394 "imported by another system.\n"));
2397 case ZPOOL_STATUS_HOSTID_REQUIRED:
2398 (void) printf(gettext(" status: The pool has the "
2399 "multihost property on. It cannot\n\tbe safely imported "
2400 "when the system hostid is not set.\n"));
2403 case ZPOOL_STATUS_HOSTID_MISMATCH:
2404 (void) printf(gettext(" status: The pool was last accessed by "
2405 "another system.\n"));
2408 case ZPOOL_STATUS_FAULTED_DEV_R:
2409 case ZPOOL_STATUS_FAULTED_DEV_NR:
2410 (void) printf(gettext(" status: One or more devices are "
2414 case ZPOOL_STATUS_BAD_LOG:
2415 (void) printf(gettext(" status: An intent log record cannot be "
2419 case ZPOOL_STATUS_RESILVERING:
2420 (void) printf(gettext(" status: One or more devices were being "
2424 case ZPOOL_STATUS_ERRATA:
2425 (void) printf(gettext(" status: Errata #%d detected.\n"),
2431 * No other status can be seen when importing pools.
2433 assert(reason == ZPOOL_STATUS_OK);
2437 * Print out an action according to the overall state of the pool.
2439 if (vs->vs_state == VDEV_STATE_HEALTHY) {
2440 if (reason == ZPOOL_STATUS_VERSION_OLDER ||
2441 reason == ZPOOL_STATUS_FEAT_DISABLED) {
2442 (void) printf(gettext(" action: The pool can be "
2443 "imported using its name or numeric identifier, "
2444 "though\n\tsome features will not be available "
2445 "without an explicit 'zpool upgrade'.\n"));
2446 } else if (reason == ZPOOL_STATUS_HOSTID_MISMATCH) {
2447 (void) printf(gettext(" action: The pool can be "
2448 "imported using its name or numeric "
2449 "identifier and\n\tthe '-f' flag.\n"));
2450 } else if (reason == ZPOOL_STATUS_ERRATA) {
2452 case ZPOOL_ERRATA_NONE:
2455 case ZPOOL_ERRATA_ZOL_2094_SCRUB:
2456 (void) printf(gettext(" action: The pool can "
2457 "be imported using its name or numeric "
2458 "identifier,\n\thowever there is a compat"
2459 "ibility issue which should be corrected"
2460 "\n\tby running 'zpool scrub'\n"));
2463 case ZPOOL_ERRATA_ZOL_2094_ASYNC_DESTROY:
2464 (void) printf(gettext(" action: The pool can"
2465 "not be imported with this version of ZFS "
2466 "due to\n\tan active asynchronous destroy. "
2467 "Revert to an earlier version\n\tand "
2468 "allow the destroy to complete before "
2472 case ZPOOL_ERRATA_ZOL_6845_ENCRYPTION:
2473 (void) printf(gettext(" action: Existing "
2474 "encrypted datasets contain an on-disk "
2475 "incompatibility, which\n\tneeds to be "
2476 "corrected. Backup these datasets to new "
2477 "encrypted datasets\n\tand destroy the "
2481 case ZPOOL_ERRATA_ZOL_8308_ENCRYPTION:
2482 (void) printf(gettext(" action: Any existing "
2483 "encrypted datasets contain an on-disk "
2484 "incompatibility\n\twhich may cause "
2485 "on-disk corruption with 'zfs recv' and "
2486 "which needs\n\tto be corrected. Enable "
2487 "the bookmark_v2 feature, backup "
2488 "these datasets\n\tto new encrypted "
2489 "datasets, and destroy the old ones. "
2490 "If this pool does\n\tnot contain any "
2491 "encrypted datasets, simply enable the "
2492 "bookmark_v2\n\tfeature.\n"));
2496 * All errata must contain an action message.
2501 (void) printf(gettext(" action: The pool can be "
2502 "imported using its name or numeric "
2505 } else if (vs->vs_state == VDEV_STATE_DEGRADED) {
2506 (void) printf(gettext(" action: The pool can be imported "
2507 "despite missing or damaged devices. The\n\tfault "
2508 "tolerance of the pool may be compromised if imported.\n"));
2511 case ZPOOL_STATUS_VERSION_NEWER:
2512 (void) printf(gettext(" action: The pool cannot be "
2513 "imported. Access the pool on a system running "
2514 "newer\n\tsoftware, or recreate the pool from "
2517 case ZPOOL_STATUS_UNSUP_FEAT_READ:
2518 (void) printf(gettext("action: The pool cannot be "
2519 "imported. Access the pool on a system that "
2520 "supports\n\tthe required feature(s), or recreate "
2521 "the pool from backup.\n"));
2523 case ZPOOL_STATUS_UNSUP_FEAT_WRITE:
2524 (void) printf(gettext("action: The pool cannot be "
2525 "imported in read-write mode. Import the pool "
2527 "\t\"-o readonly=on\", access the pool on a system "
2528 "that supports the\n\trequired feature(s), or "
2529 "recreate the pool from backup.\n"));
2531 case ZPOOL_STATUS_MISSING_DEV_R:
2532 case ZPOOL_STATUS_MISSING_DEV_NR:
2533 case ZPOOL_STATUS_BAD_GUID_SUM:
2534 (void) printf(gettext(" action: The pool cannot be "
2535 "imported. Attach the missing\n\tdevices and try "
2538 case ZPOOL_STATUS_HOSTID_ACTIVE:
2539 VERIFY0(nvlist_lookup_nvlist(config,
2540 ZPOOL_CONFIG_LOAD_INFO, &nvinfo));
2542 if (nvlist_exists(nvinfo, ZPOOL_CONFIG_MMP_HOSTNAME))
2543 hostname = fnvlist_lookup_string(nvinfo,
2544 ZPOOL_CONFIG_MMP_HOSTNAME);
2546 if (nvlist_exists(nvinfo, ZPOOL_CONFIG_MMP_HOSTID))
2547 hostid = fnvlist_lookup_uint64(nvinfo,
2548 ZPOOL_CONFIG_MMP_HOSTID);
2550 (void) printf(gettext(" action: The pool must be "
2551 "exported from %s (hostid=%lx)\n\tbefore it "
2552 "can be safely imported.\n"), hostname,
2553 (unsigned long) hostid);
2555 case ZPOOL_STATUS_HOSTID_REQUIRED:
2556 (void) printf(gettext(" action: Set a unique system "
2557 "hostid with the zgenhostid(8) command.\n"));
2560 (void) printf(gettext(" action: The pool cannot be "
2561 "imported due to damaged devices or data.\n"));
2565 /* Print the comment attached to the pool. */
2566 if (nvlist_lookup_string(config, ZPOOL_CONFIG_COMMENT, &comment) == 0)
2567 (void) printf(gettext("comment: %s\n"), comment);
2570 * If the state is "closed" or "can't open", and the aux state
2571 * is "corrupt data":
2573 if (((vs->vs_state == VDEV_STATE_CLOSED) ||
2574 (vs->vs_state == VDEV_STATE_CANT_OPEN)) &&
2575 (vs->vs_aux == VDEV_AUX_CORRUPT_DATA)) {
2576 if (pool_state == POOL_STATE_DESTROYED)
2577 (void) printf(gettext("\tThe pool was destroyed, "
2578 "but can be imported using the '-Df' flags.\n"));
2579 else if (pool_state != POOL_STATE_EXPORTED)
2580 (void) printf(gettext("\tThe pool may be active on "
2581 "another system, but can be imported using\n\t"
2582 "the '-f' flag.\n"));
2586 (void) printf(gettext(" see: http://zfsonlinux.org/msg/%s\n"),
2589 (void) printf(gettext(" config:\n\n"));
2591 cb.cb_namewidth = max_width(NULL, nvroot, 0, strlen(name),
2593 if (cb.cb_namewidth < 10)
2594 cb.cb_namewidth = 10;
2596 print_import_config(&cb, name, nvroot, 0);
2598 print_class_vdevs(NULL, &cb, nvroot, VDEV_ALLOC_BIAS_DEDUP);
2599 print_class_vdevs(NULL, &cb, nvroot, VDEV_ALLOC_BIAS_SPECIAL);
2600 print_class_vdevs(NULL, &cb, nvroot, VDEV_ALLOC_CLASS_LOGS);
2602 if (reason == ZPOOL_STATUS_BAD_GUID_SUM) {
2603 (void) printf(gettext("\n\tAdditional devices are known to "
2604 "be part of this pool, though their\n\texact "
2605 "configuration cannot be determined.\n"));
2610 zfs_force_import_required(nvlist_t *config)
2613 uint64_t hostid = 0;
2616 state = fnvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE);
2617 (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID, &hostid);
2619 if (state != POOL_STATE_EXPORTED && hostid != get_system_hostid())
2622 nvinfo = fnvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO);
2623 if (nvlist_exists(nvinfo, ZPOOL_CONFIG_MMP_STATE)) {
2624 mmp_state_t mmp_state = fnvlist_lookup_uint64(nvinfo,
2625 ZPOOL_CONFIG_MMP_STATE);
2627 if (mmp_state != MMP_STATE_INACTIVE)
2635 * Perform the import for the given configuration. This passes the heavy
2636 * lifting off to zpool_import_props(), and then mounts the datasets contained
2640 do_import(nvlist_t *config, const char *newname, const char *mntopts,
2641 nvlist_t *props, int flags)
2644 zpool_handle_t *zhp;
2648 name = fnvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME);
2649 version = fnvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION);
2651 if (!SPA_VERSION_IS_SUPPORTED(version)) {
2652 (void) fprintf(stderr, gettext("cannot import '%s': pool "
2653 "is formatted using an unsupported ZFS version\n"), name);
2655 } else if (zfs_force_import_required(config) &&
2656 !(flags & ZFS_IMPORT_ANY_HOST)) {
2657 mmp_state_t mmp_state = MMP_STATE_INACTIVE;
2660 nvinfo = fnvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO);
2661 if (nvlist_exists(nvinfo, ZPOOL_CONFIG_MMP_STATE))
2662 mmp_state = fnvlist_lookup_uint64(nvinfo,
2663 ZPOOL_CONFIG_MMP_STATE);
2665 if (mmp_state == MMP_STATE_ACTIVE) {
2666 char *hostname = "<unknown>";
2667 uint64_t hostid = 0;
2669 if (nvlist_exists(nvinfo, ZPOOL_CONFIG_MMP_HOSTNAME))
2670 hostname = fnvlist_lookup_string(nvinfo,
2671 ZPOOL_CONFIG_MMP_HOSTNAME);
2673 if (nvlist_exists(nvinfo, ZPOOL_CONFIG_MMP_HOSTID))
2674 hostid = fnvlist_lookup_uint64(nvinfo,
2675 ZPOOL_CONFIG_MMP_HOSTID);
2677 (void) fprintf(stderr, gettext("cannot import '%s': "
2678 "pool is imported on %s (hostid: "
2679 "0x%lx)\nExport the pool on the other system, "
2680 "then run 'zpool import'.\n"),
2681 name, hostname, (unsigned long) hostid);
2682 } else if (mmp_state == MMP_STATE_NO_HOSTID) {
2683 (void) fprintf(stderr, gettext("Cannot import '%s': "
2684 "pool has the multihost property on and the\n"
2685 "system's hostid is not set. Set a unique hostid "
2686 "with the zgenhostid(8) command.\n"), name);
2688 char *hostname = "<unknown>";
2689 uint64_t timestamp = 0;
2690 uint64_t hostid = 0;
2692 if (nvlist_exists(config, ZPOOL_CONFIG_HOSTNAME))
2693 hostname = fnvlist_lookup_string(config,
2694 ZPOOL_CONFIG_HOSTNAME);
2696 if (nvlist_exists(config, ZPOOL_CONFIG_TIMESTAMP))
2697 timestamp = fnvlist_lookup_uint64(config,
2698 ZPOOL_CONFIG_TIMESTAMP);
2700 if (nvlist_exists(config, ZPOOL_CONFIG_HOSTID))
2701 hostid = fnvlist_lookup_uint64(config,
2702 ZPOOL_CONFIG_HOSTID);
2704 (void) fprintf(stderr, gettext("cannot import '%s': "
2705 "pool was previously in use from another system.\n"
2706 "Last accessed by %s (hostid=%lx) at %s"
2707 "The pool can be imported, use 'zpool import -f' "
2708 "to import the pool.\n"), name, hostname,
2709 (unsigned long)hostid, ctime((time_t *)×tamp));
2715 if (zpool_import_props(g_zfs, config, newname, props, flags) != 0)
2718 if (newname != NULL)
2719 name = (char *)newname;
2721 if ((zhp = zpool_open_canfail(g_zfs, name)) == NULL)
2725 * Loading keys is best effort. We don't want to return immediately
2726 * if it fails but we do want to give the error to the caller.
2728 if (flags & ZFS_IMPORT_LOAD_KEYS) {
2729 ret = zfs_crypto_attempt_load_keys(g_zfs, name);
2734 if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL &&
2735 !(flags & ZFS_IMPORT_ONLY) &&
2736 zpool_enable_datasets(zhp, mntopts, 0) != 0) {
2745 typedef struct target_exists_args {
2746 const char *poolname;
2748 } target_exists_args_t;
2751 name_or_guid_exists(zpool_handle_t *zhp, void *data)
2753 target_exists_args_t *args = data;
2754 nvlist_t *config = zpool_get_config(zhp, NULL);
2760 if (args->poolname != NULL) {
2763 verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
2765 if (strcmp(pool_name, args->poolname) == 0)
2770 verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID,
2772 if (pool_guid == args->poolguid)
2780 * zpool checkpoint <pool>
2781 * checkpoint --discard <pool>
2783 * -d Discard the checkpoint from a checkpointed
2786 * Checkpoints the specified pool, by taking a "snapshot" of its
2787 * current state. A pool can only have one checkpoint at a time.
2790 zpool_do_checkpoint(int argc, char **argv)
2794 zpool_handle_t *zhp;
2797 struct option long_options[] = {
2798 {"discard", no_argument, NULL, 'd'},
2803 while ((c = getopt_long(argc, argv, ":d", long_options, NULL)) != -1) {
2809 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
2819 (void) fprintf(stderr, gettext("missing pool argument\n"));
2824 (void) fprintf(stderr, gettext("too many arguments\n"));
2830 if ((zhp = zpool_open(g_zfs, pool)) == NULL) {
2831 /* As a special case, check for use of '/' in the name */
2832 if (strchr(pool, '/') != NULL)
2833 (void) fprintf(stderr, gettext("'zpool checkpoint' "
2834 "doesn't work on datasets. To save the state "
2835 "of a dataset from a specific point in time "
2836 "please use 'zfs snapshot'\n"));
2841 err = (zpool_discard_checkpoint(zhp) != 0);
2843 err = (zpool_checkpoint(zhp) != 0);
2850 #define CHECKPOINT_OPT 1024
2853 * zpool import [-d dir] [-D]
2854 * import [-o mntopts] [-o prop=value] ... [-R root] [-D] [-l]
2855 * [-d dir | -c cachefile] [-f] -a
2856 * import [-o mntopts] [-o prop=value] ... [-R root] [-D] [-l]
2857 * [-d dir | -c cachefile] [-f] [-n] [-F] <pool | id> [newpool]
2859 * -c Read pool information from a cachefile instead of searching
2862 * -d Scan in a specific directory, other than /dev/. More than
2863 * one directory can be specified using multiple '-d' options.
2865 * -D Scan for previously destroyed pools or import all or only
2866 * specified destroyed pools.
2868 * -R Temporarily import the pool, with all mountpoints relative to
2869 * the given root. The pool will remain exported when the machine
2872 * -V Import even in the presence of faulted vdevs. This is an
2873 * intentionally undocumented option for testing purposes, and
2874 * treats the pool configuration as complete, leaving any bad
2875 * vdevs in the FAULTED state. In other words, it does verbatim
2878 * -f Force import, even if it appears that the pool is active.
2880 * -F Attempt rewind if necessary.
2882 * -n See if rewind would work, but don't actually rewind.
2884 * -N Import the pool but don't mount datasets.
2886 * -T Specify a starting txg to use for import. This option is
2887 * intentionally undocumented option for testing purposes.
2889 * -a Import all pools found.
2891 * -l Load encryption keys while importing.
2893 * -o Set property=value and/or temporary mount options (without '=').
2895 * -s Scan using the default search path, the libblkid cache will
2898 * --rewind-to-checkpoint
2899 * Import the pool and revert back to the checkpoint.
2901 * The import command scans for pools to import, and import pools based on pool
2902 * name and GUID. The pool can also be renamed as part of the import process.
2905 zpool_do_import(int argc, char **argv)
2907 char **searchdirs = NULL;
2908 char *env, *envdup = NULL;
2912 nvlist_t *pools = NULL;
2913 boolean_t do_all = B_FALSE;
2914 boolean_t do_destroyed = B_FALSE;
2915 char *mntopts = NULL;
2918 uint64_t searchguid = 0;
2919 char *searchname = NULL;
2921 nvlist_t *found_config;
2922 nvlist_t *policy = NULL;
2923 nvlist_t *props = NULL;
2925 int flags = ZFS_IMPORT_NORMAL;
2926 uint32_t rewind_policy = ZPOOL_NO_REWIND;
2927 boolean_t dryrun = B_FALSE;
2928 boolean_t do_rewind = B_FALSE;
2929 boolean_t xtreme_rewind = B_FALSE;
2930 boolean_t do_scan = B_FALSE;
2931 boolean_t pool_exists = B_FALSE;
2932 uint64_t pool_state, txg = -1ULL;
2933 char *cachefile = NULL;
2934 importargs_t idata = { 0 };
2937 struct option long_options[] = {
2938 {"rewind-to-checkpoint", no_argument, NULL, CHECKPOINT_OPT},
2943 while ((c = getopt_long(argc, argv, ":aCc:d:DEfFlmnNo:R:stT:VX",
2944 long_options, NULL)) != -1) {
2953 if (searchdirs == NULL) {
2954 searchdirs = safe_malloc(sizeof (char *));
2956 char **tmp = safe_malloc((nsearch + 1) *
2958 bcopy(searchdirs, tmp, nsearch *
2963 searchdirs[nsearch++] = optarg;
2966 do_destroyed = B_TRUE;
2969 flags |= ZFS_IMPORT_ANY_HOST;
2975 flags |= ZFS_IMPORT_LOAD_KEYS;
2978 flags |= ZFS_IMPORT_MISSING_LOG;
2984 flags |= ZFS_IMPORT_ONLY;
2987 if ((propval = strchr(optarg, '=')) != NULL) {
2990 if (add_prop_list(optarg, propval,
2998 if (add_prop_list(zpool_prop_to_name(
2999 ZPOOL_PROP_ALTROOT), optarg, &props, B_TRUE))
3001 if (add_prop_list_default(zpool_prop_to_name(
3002 ZPOOL_PROP_CACHEFILE), "none", &props, B_TRUE))
3009 flags |= ZFS_IMPORT_TEMP_NAME;
3010 if (add_prop_list_default(zpool_prop_to_name(
3011 ZPOOL_PROP_CACHEFILE), "none", &props, B_TRUE))
3017 txg = strtoull(optarg, &endptr, 0);
3018 if (errno != 0 || *endptr != '\0') {
3019 (void) fprintf(stderr,
3020 gettext("invalid txg value\n"));
3023 rewind_policy = ZPOOL_DO_REWIND | ZPOOL_EXTREME_REWIND;
3026 flags |= ZFS_IMPORT_VERBATIM;
3029 xtreme_rewind = B_TRUE;
3031 case CHECKPOINT_OPT:
3032 flags |= ZFS_IMPORT_CHECKPOINT;
3035 (void) fprintf(stderr, gettext("missing argument for "
3036 "'%c' option\n"), optopt);
3040 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
3049 if (cachefile && nsearch != 0) {
3050 (void) fprintf(stderr, gettext("-c is incompatible with -d\n"));
3054 if ((flags & ZFS_IMPORT_LOAD_KEYS) && (flags & ZFS_IMPORT_ONLY)) {
3055 (void) fprintf(stderr, gettext("-l is incompatible with -N\n"));
3059 if ((flags & ZFS_IMPORT_LOAD_KEYS) && !do_all && argc == 0) {
3060 (void) fprintf(stderr, gettext("-l is only meaningful during "
3065 if ((dryrun || xtreme_rewind) && !do_rewind) {
3066 (void) fprintf(stderr,
3067 gettext("-n or -X only meaningful with -F\n"));
3071 rewind_policy = ZPOOL_TRY_REWIND;
3073 rewind_policy = ZPOOL_DO_REWIND;
3075 rewind_policy |= ZPOOL_EXTREME_REWIND;
3077 /* In the future, we can capture further policy and include it here */
3078 if (nvlist_alloc(&policy, NV_UNIQUE_NAME, 0) != 0 ||
3079 nvlist_add_uint64(policy, ZPOOL_LOAD_REQUEST_TXG, txg) != 0 ||
3080 nvlist_add_uint32(policy, ZPOOL_LOAD_REWIND_POLICY,
3081 rewind_policy) != 0)
3084 /* check argument count */
3087 (void) fprintf(stderr, gettext("too many arguments\n"));
3092 (void) fprintf(stderr, gettext("too many arguments\n"));
3098 * Check for the effective uid. We do this explicitly here because
3099 * otherwise any attempt to discover pools will silently fail.
3101 if (argc == 0 && geteuid() != 0) {
3102 (void) fprintf(stderr, gettext("cannot "
3103 "discover pools: permission denied\n"));
3104 if (searchdirs != NULL)
3108 nvlist_free(policy);
3113 * Depending on the arguments given, we do one of the following:
3115 * <none> Iterate through all pools and display information about
3118 * -a Iterate through all pools and try to import each one.
3120 * <id> Find the pool that corresponds to the given GUID/pool
3121 * name and import that one.
3123 * -D Above options applies only to destroyed pools.
3129 searchguid = strtoull(argv[0], &endptr, 10);
3130 if (errno != 0 || *endptr != '\0') {
3131 searchname = argv[0];
3134 found_config = NULL;
3137 * User specified a name or guid. Ensure it's unique.
3139 target_exists_args_t search = {searchname, searchguid};
3140 pool_exists = zpool_iter(g_zfs, name_or_guid_exists, &search);
3144 * Check the environment for the preferred search path.
3146 if ((searchdirs == NULL) && (env = getenv("ZPOOL_IMPORT_PATH"))) {
3149 envdup = strdup(env);
3151 dir = strtok(envdup, ":");
3152 while (dir != NULL) {
3153 if (searchdirs == NULL) {
3154 searchdirs = safe_malloc(sizeof (char *));
3156 char **tmp = safe_malloc((nsearch + 1) *
3158 bcopy(searchdirs, tmp, nsearch *
3163 searchdirs[nsearch++] = dir;
3164 dir = strtok(NULL, ":");
3168 idata.path = searchdirs;
3169 idata.paths = nsearch;
3170 idata.poolname = searchname;
3171 idata.guid = searchguid;
3172 idata.cachefile = cachefile;
3173 idata.scan = do_scan;
3174 idata.policy = policy;
3176 pools = zpool_search_import(g_zfs, &idata, &libzfs_config_ops);
3178 if (pools != NULL && pool_exists &&
3179 (argc == 1 || strcmp(argv[0], argv[1]) == 0)) {
3180 (void) fprintf(stderr, gettext("cannot import '%s': "
3181 "a pool with that name already exists\n"),
3183 (void) fprintf(stderr, gettext("use the form '%s "
3184 "<pool | id> <newpool>' to give it a new name\n"),
3187 } else if (pools == NULL && pool_exists) {
3188 (void) fprintf(stderr, gettext("cannot import '%s': "
3189 "a pool with that name is already created/imported,\n"),
3191 (void) fprintf(stderr, gettext("and no additional pools "
3192 "with that name were found\n"));
3194 } else if (pools == NULL) {
3196 (void) fprintf(stderr, gettext("cannot import '%s': "
3197 "no such pool available\n"), argv[0]);
3203 if (searchdirs != NULL)
3207 nvlist_free(policy);
3214 * At this point we have a list of import candidate configs. Even if
3215 * we were searching by pool name or guid, we still need to
3216 * post-process the list to deal with pool state and possible
3222 while ((elem = nvlist_next_nvpair(pools, elem)) != NULL) {
3224 verify(nvpair_value_nvlist(elem, &config) == 0);
3226 verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
3228 if (!do_destroyed && pool_state == POOL_STATE_DESTROYED)
3230 if (do_destroyed && pool_state != POOL_STATE_DESTROYED)
3233 verify(nvlist_add_nvlist(config, ZPOOL_LOAD_POLICY,
3240 (void) printf("\n");
3243 err |= do_import(config, NULL, mntopts,
3246 show_import(config);
3248 } else if (searchname != NULL) {
3252 * We are searching for a pool based on name.
3254 verify(nvlist_lookup_string(config,
3255 ZPOOL_CONFIG_POOL_NAME, &name) == 0);
3257 if (strcmp(name, searchname) == 0) {
3258 if (found_config != NULL) {
3259 (void) fprintf(stderr, gettext(
3260 "cannot import '%s': more than "
3261 "one matching pool\n"), searchname);
3262 (void) fprintf(stderr, gettext(
3263 "import by numeric ID instead\n"));
3266 found_config = config;
3272 * Search for a pool by guid.
3274 verify(nvlist_lookup_uint64(config,
3275 ZPOOL_CONFIG_POOL_GUID, &guid) == 0);
3277 if (guid == searchguid)
3278 found_config = config;
3283 * If we were searching for a specific pool, verify that we found a
3284 * pool, and then do the import.
3286 if (argc != 0 && err == 0) {
3287 if (found_config == NULL) {
3288 (void) fprintf(stderr, gettext("cannot import '%s': "
3289 "no such pool available\n"), argv[0]);
3292 err |= do_import(found_config, argc == 1 ? NULL :
3293 argv[1], mntopts, props, flags);
3298 * If we were just looking for pools, report an error if none were
3301 if (argc == 0 && first)
3302 (void) fprintf(stderr,
3303 gettext("no pools available to import\n"));
3308 nvlist_free(policy);
3309 if (searchdirs != NULL)
3314 return (err ? 1 : 0);
3318 * zpool sync [-f] [pool] ...
3320 * -f (undocumented) force uberblock (and config including zpool cache file)
3323 * Sync the specified pool(s).
3324 * Without arguments "zpool sync" will sync all pools.
3325 * This command initiates TXG sync(s) and will return after the TXG(s) commit.
3329 zpool_do_sync(int argc, char **argv)
3332 boolean_t force = B_FALSE;
3335 while ((ret = getopt(argc, argv, "f")) != -1) {
3341 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
3350 /* if argc == 0 we will execute zpool_sync_one on all pools */
3351 ret = for_each_pool(argc, argv, B_FALSE, NULL, zpool_sync_one, &force);
3356 typedef struct iostat_cbdata {
3361 char **cb_vdev_names; /* Only show these vdevs */
3362 unsigned int cb_vdev_names_count;
3363 boolean_t cb_verbose;
3364 boolean_t cb_literal;
3365 boolean_t cb_scripted;
3366 zpool_list_t *cb_list;
3367 vdev_cmd_data_list_t *vcdl;
3371 typedef struct name_and_columns {
3372 const char *name; /* Column name */
3373 unsigned int columns; /* Center name to this number of columns */
3374 } name_and_columns_t;
3376 #define IOSTAT_MAX_LABELS 11 /* Max number of labels on one line */
3378 static const name_and_columns_t iostat_top_labels[][IOSTAT_MAX_LABELS] =
3380 [IOS_DEFAULT] = {{"capacity", 2}, {"operations", 2}, {"bandwidth", 2},
3382 [IOS_LATENCY] = {{"total_wait", 2}, {"disk_wait", 2}, {"syncq_wait", 2},
3383 {"asyncq_wait", 2}, {"scrub"}},
3384 [IOS_QUEUES] = {{"syncq_read", 2}, {"syncq_write", 2},
3385 {"asyncq_read", 2}, {"asyncq_write", 2}, {"scrubq_read", 2},
3387 [IOS_L_HISTO] = {{"total_wait", 2}, {"disk_wait", 2}, {"syncq_wait", 2},
3388 {"asyncq_wait", 2}, {NULL}},
3389 [IOS_RQ_HISTO] = {{"sync_read", 2}, {"sync_write", 2},
3390 {"async_read", 2}, {"async_write", 2}, {"scrub", 2}, {NULL}},
3394 /* Shorthand - if "columns" field not set, default to 1 column */
3395 static const name_and_columns_t iostat_bottom_labels[][IOSTAT_MAX_LABELS] =
3397 [IOS_DEFAULT] = {{"alloc"}, {"free"}, {"read"}, {"write"}, {"read"},
3399 [IOS_LATENCY] = {{"read"}, {"write"}, {"read"}, {"write"}, {"read"},
3400 {"write"}, {"read"}, {"write"}, {"wait"}, {NULL}},
3401 [IOS_QUEUES] = {{"pend"}, {"activ"}, {"pend"}, {"activ"}, {"pend"},
3402 {"activ"}, {"pend"}, {"activ"}, {"pend"}, {"activ"}, {NULL}},
3403 [IOS_L_HISTO] = {{"read"}, {"write"}, {"read"}, {"write"}, {"read"},
3404 {"write"}, {"read"}, {"write"}, {"scrub"}, {NULL}},
3405 [IOS_RQ_HISTO] = {{"ind"}, {"agg"}, {"ind"}, {"agg"}, {"ind"}, {"agg"},
3406 {"ind"}, {"agg"}, {"ind"}, {"agg"}, {NULL}},
3409 static const char *histo_to_title[] = {
3410 [IOS_L_HISTO] = "latency",
3411 [IOS_RQ_HISTO] = "req_size",
3415 * Return the number of labels in a null-terminated name_and_columns_t
3420 label_array_len(const name_and_columns_t *labels)
3424 while (labels[i].name)
3431 * Return the number of strings in a null-terminated string array.
3434 * const char foo[] = {"bar", "baz", NULL}
3439 str_array_len(const char *array[])
3450 * Return a default column width for default/latency/queue columns. This does
3451 * not include histograms, which have their columns autosized.
3454 default_column_width(iostat_cbdata_t *cb, enum iostat_type type)
3456 unsigned long column_width = 5; /* Normal niceprint */
3457 static unsigned long widths[] = {
3459 * Choose some sane default column sizes for printing the
3462 [IOS_DEFAULT] = 15, /* 1PB capacity */
3463 [IOS_LATENCY] = 10, /* 1B ns = 10sec */
3464 [IOS_QUEUES] = 6, /* 1M queue entries */
3468 column_width = widths[type];
3470 return (column_width);
3474 * Print the column labels, i.e:
3476 * capacity operations bandwidth
3477 * alloc free read write read write ...
3479 * If force_column_width is set, use it for the column width. If not set, use
3480 * the default column width.
3483 print_iostat_labels(iostat_cbdata_t *cb, unsigned int force_column_width,
3484 const name_and_columns_t labels[][IOSTAT_MAX_LABELS])
3487 unsigned int text_start, rw_column_width, spaces_to_end;
3488 uint64_t flags = cb->cb_flags;
3490 unsigned int column_width = force_column_width;
3492 /* For each bit set in flags */
3493 for (f = flags; f; f &= ~(1ULL << idx)) {
3494 idx = lowbit64(f) - 1;
3495 if (!force_column_width)
3496 column_width = default_column_width(cb, idx);
3497 /* Print our top labels centered over "read write" label. */
3498 for (i = 0; i < label_array_len(labels[idx]); i++) {
3499 const char *name = labels[idx][i].name;
3501 * We treat labels[][].columns == 0 as shorthand
3502 * for one column. It makes writing out the label
3503 * tables more concise.
3505 unsigned int columns = MAX(1, labels[idx][i].columns);
3506 unsigned int slen = strlen(name);
3508 rw_column_width = (column_width * columns) +
3509 (2 * (columns - 1));
3511 text_start = (int)((rw_column_width)/columns -
3514 printf(" "); /* Two spaces between columns */
3516 /* Space from beginning of column to label */
3517 for (s = 0; s < text_start; s++)
3522 /* Print space after label to end of column */
3523 spaces_to_end = rw_column_width - text_start - slen;
3524 for (s = 0; s < spaces_to_end; s++)
3533 * print_cmd_columns - Print custom column titles from -c
3535 * If the user specified the "zpool status|iostat -c" then print their custom
3536 * column titles in the header. For example, print_cmd_columns() would print
3537 * the " col1 col2" part of this:
3539 * $ zpool iostat -vc 'echo col1=val1; echo col2=val2'
3541 * capacity operations bandwidth
3542 * pool alloc free read write read write col1 col2
3543 * ---------- ----- ----- ----- ----- ----- ----- ---- ----
3544 * mypool 269K 1008M 0 0 107 946
3545 * mirror 269K 1008M 0 0 107 946
3546 * sdb - - 0 0 102 473 val1 val2
3547 * sdc - - 0 0 5 473 val1 val2
3548 * ---------- ----- ----- ----- ----- ----- ----- ---- ----
3551 print_cmd_columns(vdev_cmd_data_list_t *vcdl, int use_dashes)
3554 vdev_cmd_data_t *data = &vcdl->data[0];
3556 if (vcdl->count == 0 || data == NULL)
3560 * Each vdev cmd should have the same column names unless the user did
3561 * something weird with their cmd. Just take the column names from the
3562 * first vdev and assume it works for all of them.
3564 for (i = 0; i < vcdl->uniq_cols_cnt; i++) {
3567 for (j = 0; j < vcdl->uniq_cols_width[i]; j++)
3570 printf("%*s", vcdl->uniq_cols_width[i],
3571 vcdl->uniq_cols[i]);
3578 * Utility function to print out a line of dashes like:
3580 * -------------------------------- ----- ----- ----- ----- -----
3582 * ...or a dashed named-row line like:
3588 * @force_column_width If non-zero, use the value as the column width.
3589 * Otherwise use the default column widths.
3591 * @name: Print a dashed named-row line starting
3592 * with @name. Otherwise, print a regular
3596 print_iostat_dashes(iostat_cbdata_t *cb, unsigned int force_column_width,
3600 unsigned int namewidth;
3601 uint64_t flags = cb->cb_flags;
3604 const name_and_columns_t *labels;
3608 if (cb->cb_flags & IOS_ANYHISTO_M) {
3609 title = histo_to_title[IOS_HISTO_IDX(cb->cb_flags)];
3610 } else if (cb->cb_vdev_names_count) {
3616 namewidth = MAX(MAX(strlen(title), cb->cb_namewidth),
3617 name ? strlen(name) : 0);
3621 printf("%-*s", namewidth, name);
3623 for (i = 0; i < namewidth; i++)
3627 /* For each bit in flags */
3628 for (f = flags; f; f &= ~(1ULL << idx)) {
3629 unsigned int column_width;
3630 idx = lowbit64(f) - 1;
3631 if (force_column_width)
3632 column_width = force_column_width;
3634 column_width = default_column_width(cb, idx);
3636 labels = iostat_bottom_labels[idx];
3637 for (i = 0; i < label_array_len(labels); i++) {
3639 printf(" %*s-", column_width - 1, " ");
3641 printf(" %.*s", column_width,
3642 "--------------------");
3649 print_iostat_separator_impl(iostat_cbdata_t *cb,
3650 unsigned int force_column_width)
3652 print_iostat_dashes(cb, force_column_width, NULL);
3656 print_iostat_separator(iostat_cbdata_t *cb)
3658 print_iostat_separator_impl(cb, 0);
3662 print_iostat_header_impl(iostat_cbdata_t *cb, unsigned int force_column_width,
3663 const char *histo_vdev_name)
3665 unsigned int namewidth;
3668 if (cb->cb_flags & IOS_ANYHISTO_M) {
3669 title = histo_to_title[IOS_HISTO_IDX(cb->cb_flags)];
3670 } else if (cb->cb_vdev_names_count) {
3676 namewidth = MAX(MAX(strlen(title), cb->cb_namewidth),
3677 histo_vdev_name ? strlen(histo_vdev_name) : 0);
3679 if (histo_vdev_name)
3680 printf("%-*s", namewidth, histo_vdev_name);
3682 printf("%*s", namewidth, "");
3685 print_iostat_labels(cb, force_column_width, iostat_top_labels);
3688 printf("%-*s", namewidth, title);
3690 print_iostat_labels(cb, force_column_width, iostat_bottom_labels);
3691 if (cb->vcdl != NULL)
3692 print_cmd_columns(cb->vcdl, 0);
3696 print_iostat_separator_impl(cb, force_column_width);
3698 if (cb->vcdl != NULL)
3699 print_cmd_columns(cb->vcdl, 1);
3705 print_iostat_header(iostat_cbdata_t *cb)
3707 print_iostat_header_impl(cb, 0, NULL);
3712 * Display a single statistic.
3715 print_one_stat(uint64_t value, enum zfs_nicenum_format format,
3716 unsigned int column_size, boolean_t scripted)
3720 zfs_nicenum_format(value, buf, sizeof (buf), format);
3723 printf("\t%s", buf);
3725 printf(" %*s", column_size, buf);
3729 * Calculate the default vdev stats
3731 * Subtract oldvs from newvs, apply a scaling factor, and save the resulting
3732 * stats into calcvs.
3735 calc_default_iostats(vdev_stat_t *oldvs, vdev_stat_t *newvs,
3736 vdev_stat_t *calcvs)
3740 memcpy(calcvs, newvs, sizeof (*calcvs));
3741 for (i = 0; i < ARRAY_SIZE(calcvs->vs_ops); i++)
3742 calcvs->vs_ops[i] = (newvs->vs_ops[i] - oldvs->vs_ops[i]);
3744 for (i = 0; i < ARRAY_SIZE(calcvs->vs_bytes); i++)
3745 calcvs->vs_bytes[i] = (newvs->vs_bytes[i] - oldvs->vs_bytes[i]);
3749 * Internal representation of the extended iostats data.
3751 * The extended iostat stats are exported in nvlists as either uint64_t arrays
3752 * or single uint64_t's. We make both look like arrays to make them easier
3753 * to process. In order to make single uint64_t's look like arrays, we set
3754 * __data to the stat data, and then set *data = &__data with count = 1. Then,
3755 * we can just use *data and count.
3759 uint_t count; /* Number of entries in data[] */
3760 uint64_t __data; /* Only used when data is a single uint64_t */
3764 stat_histo_max(struct stat_array *nva, unsigned int len)
3768 for (i = 0; i < len; i++)
3769 max = MAX(max, array64_max(nva[i].data, nva[i].count));
3775 * Helper function to lookup a uint64_t array or uint64_t value and store its
3776 * data as a stat_array. If the nvpair is a single uint64_t value, then we make
3777 * it look like a one element array to make it easier to process.
3780 nvpair64_to_stat_array(nvlist_t *nvl, const char *name,
3781 struct stat_array *nva)
3786 verify(nvlist_lookup_nvpair(nvl, name, &tmp) == 0);
3787 switch (nvpair_type(tmp)) {
3788 case DATA_TYPE_UINT64_ARRAY:
3789 ret = nvpair_value_uint64_array(tmp, &nva->data, &nva->count);
3791 case DATA_TYPE_UINT64:
3792 ret = nvpair_value_uint64(tmp, &nva->__data);
3793 nva->data = &nva->__data;
3797 /* Not a uint64_t */
3806 * Given a list of nvlist names, look up the extended stats in newnv and oldnv,
3807 * subtract them, and return the results in a newly allocated stat_array.
3808 * You must free the returned array after you are done with it with
3809 * free_calc_stats().
3811 * Additionally, you can set "oldnv" to NULL if you simply want the newnv
3814 static struct stat_array *
3815 calc_and_alloc_stats_ex(const char **names, unsigned int len, nvlist_t *oldnv,
3818 nvlist_t *oldnvx = NULL, *newnvx;
3819 struct stat_array *oldnva, *newnva, *calcnva;
3821 unsigned int alloc_size = (sizeof (struct stat_array)) * len;
3823 /* Extract our extended stats nvlist from the main list */
3824 verify(nvlist_lookup_nvlist(newnv, ZPOOL_CONFIG_VDEV_STATS_EX,
3827 verify(nvlist_lookup_nvlist(oldnv, ZPOOL_CONFIG_VDEV_STATS_EX,
3831 newnva = safe_malloc(alloc_size);
3832 oldnva = safe_malloc(alloc_size);
3833 calcnva = safe_malloc(alloc_size);
3835 for (j = 0; j < len; j++) {
3836 verify(nvpair64_to_stat_array(newnvx, names[j],
3838 calcnva[j].count = newnva[j].count;
3839 alloc_size = calcnva[j].count * sizeof (calcnva[j].data[0]);
3840 calcnva[j].data = safe_malloc(alloc_size);
3841 memcpy(calcnva[j].data, newnva[j].data, alloc_size);
3844 verify(nvpair64_to_stat_array(oldnvx, names[j],
3846 for (i = 0; i < oldnva[j].count; i++)
3847 calcnva[j].data[i] -= oldnva[j].data[i];
3856 free_calc_stats(struct stat_array *nva, unsigned int len)
3859 for (i = 0; i < len; i++)
3866 print_iostat_histo(struct stat_array *nva, unsigned int len,
3867 iostat_cbdata_t *cb, unsigned int column_width, unsigned int namewidth,
3873 enum zfs_nicenum_format format;
3874 unsigned int buckets;
3875 unsigned int start_bucket;
3878 format = ZFS_NICENUM_RAW;
3880 format = ZFS_NICENUM_1024;
3882 /* All these histos are the same size, so just use nva[0].count */
3883 buckets = nva[0].count;
3885 if (cb->cb_flags & IOS_RQ_HISTO_M) {
3886 /* Start at 512 - req size should never be lower than this */
3892 for (j = start_bucket; j < buckets; j++) {
3893 /* Print histogram bucket label */
3894 if (cb->cb_flags & IOS_L_HISTO_M) {
3895 /* Ending range of this bucket */
3896 val = (1UL << (j + 1)) - 1;
3897 zfs_nicetime(val, buf, sizeof (buf));
3899 /* Request size (starting range of bucket) */
3901 zfs_nicenum(val, buf, sizeof (buf));
3904 if (cb->cb_scripted)
3905 printf("%llu", (u_longlong_t)val);
3907 printf("%-*s", namewidth, buf);
3909 /* Print the values on the line */
3910 for (i = 0; i < len; i++) {
3911 print_one_stat(nva[i].data[j] * scale, format,
3912 column_width, cb->cb_scripted);
3919 print_solid_separator(unsigned int length)
3927 print_iostat_histos(iostat_cbdata_t *cb, nvlist_t *oldnv,
3928 nvlist_t *newnv, double scale, const char *name)
3930 unsigned int column_width;
3931 unsigned int namewidth;
3932 unsigned int entire_width;
3933 enum iostat_type type;
3934 struct stat_array *nva;
3936 unsigned int names_len;
3938 /* What type of histo are we? */
3939 type = IOS_HISTO_IDX(cb->cb_flags);
3941 /* Get NULL-terminated array of nvlist names for our histo */
3942 names = vsx_type_to_nvlist[type];
3943 names_len = str_array_len(names); /* num of names */
3945 nva = calc_and_alloc_stats_ex(names, names_len, oldnv, newnv);
3947 if (cb->cb_literal) {
3948 column_width = MAX(5,
3949 (unsigned int) log10(stat_histo_max(nva, names_len)) + 1);
3954 namewidth = MAX(cb->cb_namewidth,
3955 strlen(histo_to_title[IOS_HISTO_IDX(cb->cb_flags)]));
3958 * Calculate the entire line width of what we're printing. The
3959 * +2 is for the two spaces between columns:
3963 /* |___| <---------- column_width */
3965 /* |__________| <--- entire_width */
3967 entire_width = namewidth + (column_width + 2) *
3968 label_array_len(iostat_bottom_labels[type]);
3970 if (cb->cb_scripted)
3971 printf("%s\n", name);
3973 print_iostat_header_impl(cb, column_width, name);
3975 print_iostat_histo(nva, names_len, cb, column_width,
3978 free_calc_stats(nva, names_len);
3979 if (!cb->cb_scripted)
3980 print_solid_separator(entire_width);
3984 * Calculate the average latency of a power-of-two latency histogram
3987 single_histo_average(uint64_t *histo, unsigned int buckets)
3990 uint64_t count = 0, total = 0;
3992 for (i = 0; i < buckets; i++) {
3994 * Our buckets are power-of-two latency ranges. Use the
3995 * midpoint latency of each bucket to calculate the average.
4003 if (histo[i] != 0) {
4004 total += histo[i] * (((1UL << i) + ((1UL << i)/2)));
4009 /* Prevent divide by zero */
4010 return (count == 0 ? 0 : total / count);
4014 print_iostat_queues(iostat_cbdata_t *cb, nvlist_t *oldnv,
4019 const char *names[] = {
4020 ZPOOL_CONFIG_VDEV_SYNC_R_PEND_QUEUE,
4021 ZPOOL_CONFIG_VDEV_SYNC_R_ACTIVE_QUEUE,
4022 ZPOOL_CONFIG_VDEV_SYNC_W_PEND_QUEUE,
4023 ZPOOL_CONFIG_VDEV_SYNC_W_ACTIVE_QUEUE,
4024 ZPOOL_CONFIG_VDEV_ASYNC_R_PEND_QUEUE,
4025 ZPOOL_CONFIG_VDEV_ASYNC_R_ACTIVE_QUEUE,
4026 ZPOOL_CONFIG_VDEV_ASYNC_W_PEND_QUEUE,
4027 ZPOOL_CONFIG_VDEV_ASYNC_W_ACTIVE_QUEUE,
4028 ZPOOL_CONFIG_VDEV_SCRUB_PEND_QUEUE,
4029 ZPOOL_CONFIG_VDEV_SCRUB_ACTIVE_QUEUE,
4032 struct stat_array *nva;
4034 unsigned int column_width = default_column_width(cb, IOS_QUEUES);
4035 enum zfs_nicenum_format format;
4037 nva = calc_and_alloc_stats_ex(names, ARRAY_SIZE(names), NULL, newnv);
4040 format = ZFS_NICENUM_RAW;
4042 format = ZFS_NICENUM_1024;
4044 for (i = 0; i < ARRAY_SIZE(names); i++) {
4045 val = nva[i].data[0];
4046 print_one_stat(val, format, column_width, cb->cb_scripted);
4049 free_calc_stats(nva, ARRAY_SIZE(names));
4053 print_iostat_latency(iostat_cbdata_t *cb, nvlist_t *oldnv,
4058 const char *names[] = {
4059 ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO,
4060 ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO,
4061 ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO,
4062 ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO,
4063 ZPOOL_CONFIG_VDEV_SYNC_R_LAT_HISTO,
4064 ZPOOL_CONFIG_VDEV_SYNC_W_LAT_HISTO,
4065 ZPOOL_CONFIG_VDEV_ASYNC_R_LAT_HISTO,
4066 ZPOOL_CONFIG_VDEV_ASYNC_W_LAT_HISTO,
4067 ZPOOL_CONFIG_VDEV_SCRUB_LAT_HISTO,
4069 struct stat_array *nva;
4071 unsigned int column_width = default_column_width(cb, IOS_LATENCY);
4072 enum zfs_nicenum_format format;
4074 nva = calc_and_alloc_stats_ex(names, ARRAY_SIZE(names), oldnv, newnv);
4077 format = ZFS_NICENUM_RAWTIME;
4079 format = ZFS_NICENUM_TIME;
4081 /* Print our avg latencies on the line */
4082 for (i = 0; i < ARRAY_SIZE(names); i++) {
4083 /* Compute average latency for a latency histo */
4084 val = single_histo_average(nva[i].data, nva[i].count);
4085 print_one_stat(val, format, column_width, cb->cb_scripted);
4087 free_calc_stats(nva, ARRAY_SIZE(names));
4091 * Print default statistics (capacity/operations/bandwidth)
4094 print_iostat_default(vdev_stat_t *vs, iostat_cbdata_t *cb, double scale)
4096 unsigned int column_width = default_column_width(cb, IOS_DEFAULT);
4097 enum zfs_nicenum_format format;
4098 char na; /* char to print for "not applicable" values */
4100 if (cb->cb_literal) {
4101 format = ZFS_NICENUM_RAW;
4104 format = ZFS_NICENUM_1024;
4108 /* only toplevel vdevs have capacity stats */
4109 if (vs->vs_space == 0) {
4110 if (cb->cb_scripted)
4111 printf("\t%c\t%c", na, na);
4113 printf(" %*c %*c", column_width, na, column_width,
4116 print_one_stat(vs->vs_alloc, format, column_width,
4118 print_one_stat(vs->vs_space - vs->vs_alloc, format,
4119 column_width, cb->cb_scripted);
4122 print_one_stat((uint64_t)(vs->vs_ops[ZIO_TYPE_READ] * scale),
4123 format, column_width, cb->cb_scripted);
4124 print_one_stat((uint64_t)(vs->vs_ops[ZIO_TYPE_WRITE] * scale),
4125 format, column_width, cb->cb_scripted);
4126 print_one_stat((uint64_t)(vs->vs_bytes[ZIO_TYPE_READ] * scale),
4127 format, column_width, cb->cb_scripted);
4128 print_one_stat((uint64_t)(vs->vs_bytes[ZIO_TYPE_WRITE] * scale),
4129 format, column_width, cb->cb_scripted);
4132 static const char *class_name[] = {
4133 VDEV_ALLOC_BIAS_DEDUP,
4134 VDEV_ALLOC_BIAS_SPECIAL,
4135 VDEV_ALLOC_CLASS_LOGS
4139 * Print out all the statistics for the given vdev. This can either be the
4140 * toplevel configuration, or called recursively. If 'name' is NULL, then this
4141 * is a verbose output, and we don't want to display the toplevel pool stats.
4143 * Returns the number of stat lines printed.
4146 print_vdev_stats(zpool_handle_t *zhp, const char *name, nvlist_t *oldnv,
4147 nvlist_t *newnv, iostat_cbdata_t *cb, int depth)
4149 nvlist_t **oldchild, **newchild;
4150 uint_t c, children, oldchildren;
4151 vdev_stat_t *oldvs, *newvs, *calcvs;
4152 vdev_stat_t zerovs = { 0 };
4159 calcvs = safe_malloc(sizeof (*calcvs));
4161 if (strcmp(name, VDEV_TYPE_INDIRECT) == 0)
4164 if (oldnv != NULL) {
4165 verify(nvlist_lookup_uint64_array(oldnv,
4166 ZPOOL_CONFIG_VDEV_STATS, (uint64_t **)&oldvs, &c) == 0);
4171 /* Do we only want to see a specific vdev? */
4172 for (i = 0; i < cb->cb_vdev_names_count; i++) {
4173 /* Yes we do. Is this the vdev? */
4174 if (strcmp(name, cb->cb_vdev_names[i]) == 0) {
4176 * This is our vdev. Since it is the only vdev we
4177 * will be displaying, make depth = 0 so that it
4178 * doesn't get indented.
4185 if (cb->cb_vdev_names_count && (i == cb->cb_vdev_names_count)) {
4186 /* Couldn't match the name */
4191 verify(nvlist_lookup_uint64_array(newnv, ZPOOL_CONFIG_VDEV_STATS,
4192 (uint64_t **)&newvs, &c) == 0);
4195 * Print the vdev name unless it's is a histogram. Histograms
4196 * display the vdev name in the header itself.
4198 if (!(cb->cb_flags & IOS_ANYHISTO_M)) {
4199 if (cb->cb_scripted) {
4202 if (strlen(name) + depth > cb->cb_namewidth)
4203 (void) printf("%*s%s", depth, "", name);
4205 (void) printf("%*s%s%*s", depth, "", name,
4206 (int)(cb->cb_namewidth - strlen(name) -
4211 /* Calculate our scaling factor */
4212 tdelta = newvs->vs_timestamp - oldvs->vs_timestamp;
4213 if ((oldvs->vs_timestamp == 0) && (cb->cb_flags & IOS_ANYHISTO_M)) {
4215 * If we specify printing histograms with no time interval, then
4216 * print the histogram numbers over the entire lifetime of the
4224 scale = (double)NANOSEC / tdelta;
4227 if (cb->cb_flags & IOS_DEFAULT_M) {
4228 calc_default_iostats(oldvs, newvs, calcvs);
4229 print_iostat_default(calcvs, cb, scale);
4231 if (cb->cb_flags & IOS_LATENCY_M)
4232 print_iostat_latency(cb, oldnv, newnv);
4233 if (cb->cb_flags & IOS_QUEUES_M)
4234 print_iostat_queues(cb, oldnv, newnv);
4235 if (cb->cb_flags & IOS_ANYHISTO_M) {
4237 print_iostat_histos(cb, oldnv, newnv, scale, name);
4240 if (cb->vcdl != NULL) {
4242 if (nvlist_lookup_string(newnv, ZPOOL_CONFIG_PATH,
4245 zpool_print_cmd(cb->vcdl, zpool_get_name(zhp), path);
4249 if (!(cb->cb_flags & IOS_ANYHISTO_M))
4258 if (!cb->cb_verbose)
4261 if (nvlist_lookup_nvlist_array(newnv, ZPOOL_CONFIG_CHILDREN,
4262 &newchild, &children) != 0)
4266 if (nvlist_lookup_nvlist_array(oldnv, ZPOOL_CONFIG_CHILDREN,
4267 &oldchild, &oldchildren) != 0)
4270 children = MIN(oldchildren, children);
4274 * print normal top-level devices
4276 for (c = 0; c < children; c++) {
4277 uint64_t ishole = B_FALSE, islog = B_FALSE;
4279 (void) nvlist_lookup_uint64(newchild[c], ZPOOL_CONFIG_IS_HOLE,
4282 (void) nvlist_lookup_uint64(newchild[c], ZPOOL_CONFIG_IS_LOG,
4285 if (ishole || islog)
4288 if (nvlist_exists(newchild[c], ZPOOL_CONFIG_ALLOCATION_BIAS))
4291 vname = zpool_vdev_name(g_zfs, zhp, newchild[c],
4293 ret += print_vdev_stats(zhp, vname, oldnv ? oldchild[c] : NULL,
4294 newchild[c], cb, depth + 2);
4299 * print all other top-level devices
4301 for (uint_t n = 0; n < 3; n++) {
4302 boolean_t printed = B_FALSE;
4304 for (c = 0; c < children; c++) {
4305 uint64_t islog = B_FALSE;
4309 (void) nvlist_lookup_uint64(newchild[c],
4310 ZPOOL_CONFIG_IS_LOG, &islog);
4312 bias = VDEV_ALLOC_CLASS_LOGS;
4314 (void) nvlist_lookup_string(newchild[c],
4315 ZPOOL_CONFIG_ALLOCATION_BIAS, &bias);
4316 (void) nvlist_lookup_string(newchild[c],
4317 ZPOOL_CONFIG_TYPE, &type);
4319 if (bias == NULL || strcmp(bias, class_name[n]) != 0)
4321 if (!islog && strcmp(type, VDEV_TYPE_INDIRECT) == 0)
4325 if ((!(cb->cb_flags & IOS_ANYHISTO_M)) &&
4326 !cb->cb_scripted && !cb->cb_vdev_names) {
4327 print_iostat_dashes(cb, 0,
4334 vname = zpool_vdev_name(g_zfs, zhp, newchild[c],
4336 ret += print_vdev_stats(zhp, vname, oldnv ?
4337 oldchild[c] : NULL, newchild[c], cb, depth + 2);
4343 * Include level 2 ARC devices in iostat output
4345 if (nvlist_lookup_nvlist_array(newnv, ZPOOL_CONFIG_L2CACHE,
4346 &newchild, &children) != 0)
4350 if (nvlist_lookup_nvlist_array(oldnv, ZPOOL_CONFIG_L2CACHE,
4351 &oldchild, &oldchildren) != 0)
4354 children = MIN(oldchildren, children);
4358 if ((!(cb->cb_flags & IOS_ANYHISTO_M)) && !cb->cb_scripted &&
4359 !cb->cb_vdev_names) {
4360 print_iostat_dashes(cb, 0, "cache");
4364 for (c = 0; c < children; c++) {
4365 vname = zpool_vdev_name(g_zfs, zhp, newchild[c],
4367 ret += print_vdev_stats(zhp, vname, oldnv ? oldchild[c]
4368 : NULL, newchild[c], cb, depth + 2);
4377 refresh_iostat(zpool_handle_t *zhp, void *data)
4379 iostat_cbdata_t *cb = data;
4383 * If the pool has disappeared, remove it from the list and continue.
4385 if (zpool_refresh_stats(zhp, &missing) != 0)
4389 pool_list_remove(cb->cb_list, zhp);
4395 * Callback to print out the iostats for the given pool.
4398 print_iostat(zpool_handle_t *zhp, void *data)
4400 iostat_cbdata_t *cb = data;
4401 nvlist_t *oldconfig, *newconfig;
4402 nvlist_t *oldnvroot, *newnvroot;
4405 newconfig = zpool_get_config(zhp, &oldconfig);
4407 if (cb->cb_iteration == 1)
4410 verify(nvlist_lookup_nvlist(newconfig, ZPOOL_CONFIG_VDEV_TREE,
4413 if (oldconfig == NULL)
4416 verify(nvlist_lookup_nvlist(oldconfig, ZPOOL_CONFIG_VDEV_TREE,
4419 ret = print_vdev_stats(zhp, zpool_get_name(zhp), oldnvroot, newnvroot,
4421 if ((ret != 0) && !(cb->cb_flags & IOS_ANYHISTO_M) &&
4422 !cb->cb_scripted && cb->cb_verbose && !cb->cb_vdev_names_count) {
4423 print_iostat_separator(cb);
4424 if (cb->vcdl != NULL) {
4425 print_cmd_columns(cb->vcdl, 1);
4440 if (isatty(STDOUT_FILENO)) {
4441 error = ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
4443 columns = ws.ws_col;
4452 * Return the required length of the pool/vdev name column. The minimum
4453 * allowed width and output formatting flags must be provided.
4456 get_namewidth(zpool_handle_t *zhp, int min_width, int flags, boolean_t verbose)
4458 nvlist_t *config, *nvroot;
4459 int width = min_width;
4461 if ((config = zpool_get_config(zhp, NULL)) != NULL) {
4462 verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
4464 unsigned int poolname_len = strlen(zpool_get_name(zhp));
4465 if (verbose == B_FALSE) {
4466 width = MAX(poolname_len, min_width);
4468 width = MAX(poolname_len,
4469 max_width(zhp, nvroot, 0, min_width, flags));
4477 * Parse the input string, get the 'interval' and 'count' value if there is one.
4480 get_interval_count(int *argcp, char **argv, float *iv,
4484 unsigned long count = 0;
4488 * Determine if the last argument is an integer or a pool name
4490 if (argc > 0 && isnumber(argv[argc - 1])) {
4494 interval = strtof(argv[argc - 1], &end);
4496 if (*end == '\0' && errno == 0) {
4497 if (interval == 0) {
4498 (void) fprintf(stderr, gettext("interval "
4499 "cannot be zero\n"));
4503 * Ignore the last parameter
4508 * If this is not a valid number, just plow on. The
4509 * user will get a more informative error message later
4517 * If the last argument is also an integer, then we have both a count
4520 if (argc > 0 && isnumber(argv[argc - 1])) {
4525 interval = strtof(argv[argc - 1], &end);
4527 if (*end == '\0' && errno == 0) {
4528 if (interval == 0) {
4529 (void) fprintf(stderr, gettext("interval "
4530 "cannot be zero\n"));
4535 * Ignore the last parameter
4549 get_timestamp_arg(char c)
4552 timestamp_fmt = UDATE;
4554 timestamp_fmt = DDATE;
4560 * Return stat flags that are supported by all pools by both the module and
4561 * zpool iostat. "*data" should be initialized to all 0xFFs before running.
4562 * It will get ANDed down until only the flags that are supported on all pools
4566 get_stat_flags_cb(zpool_handle_t *zhp, void *data)
4568 uint64_t *mask = data;
4569 nvlist_t *config, *nvroot, *nvx;
4573 config = zpool_get_config(zhp, NULL);
4574 verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
4577 /* Default stats are always supported, but for completeness.. */
4578 if (nvlist_exists(nvroot, ZPOOL_CONFIG_VDEV_STATS))
4579 flags |= IOS_DEFAULT_M;
4581 /* Get our extended stats nvlist from the main list */
4582 if (nvlist_lookup_nvlist(nvroot, ZPOOL_CONFIG_VDEV_STATS_EX,
4585 * No extended stats; they're probably running an older
4586 * module. No big deal, we support that too.
4591 /* For each extended stat, make sure all its nvpairs are supported */
4592 for (j = 0; j < ARRAY_SIZE(vsx_type_to_nvlist); j++) {
4593 if (!vsx_type_to_nvlist[j][0])
4596 /* Start off by assuming the flag is supported, then check */
4597 flags |= (1ULL << j);
4598 for (i = 0; vsx_type_to_nvlist[j][i]; i++) {
4599 if (!nvlist_exists(nvx, vsx_type_to_nvlist[j][i])) {
4600 /* flag isn't supported */
4601 flags = flags & ~(1ULL << j);
4607 *mask = *mask & flags;
4612 * Return a bitmask of stats that are supported on all pools by both the module
4616 get_stat_flags(zpool_list_t *list)
4621 * get_stat_flags_cb() will lop off bits from "mask" until only the
4622 * flags that are supported on all pools remain.
4624 pool_list_iter(list, B_FALSE, get_stat_flags_cb, &mask);
4629 * Return 1 if cb_data->cb_vdev_names[0] is this vdev's name, 0 otherwise.
4632 is_vdev_cb(zpool_handle_t *zhp, nvlist_t *nv, void *cb_data)
4634 iostat_cbdata_t *cb = cb_data;
4638 name = zpool_vdev_name(g_zfs, zhp, nv, cb->cb_name_flags);
4640 if (strcmp(name, cb->cb_vdev_names[0]) == 0)
4641 ret = 1; /* match */
4648 * Returns 1 if cb_data->cb_vdev_names[0] is a vdev name, 0 otherwise.
4651 is_vdev(zpool_handle_t *zhp, void *cb_data)
4653 return (for_each_vdev(zhp, is_vdev_cb, cb_data));
4657 * Check if vdevs are in a pool
4659 * Return 1 if all argv[] strings are vdev names in pool "pool_name". Otherwise
4660 * return 0. If pool_name is NULL, then search all pools.
4663 are_vdevs_in_pool(int argc, char **argv, char *pool_name,
4664 iostat_cbdata_t *cb)
4671 if ((argc == 0) || !*argv)
4677 /* Temporarily hijack cb_vdev_names for a second... */
4678 tmp_name = cb->cb_vdev_names;
4680 /* Go though our list of prospective vdev names */
4681 for (i = 0; i < argc; i++) {
4682 cb->cb_vdev_names = argv + i;
4684 /* Is this name a vdev in our pools? */
4685 ret = for_each_pool(pool_count, &pool_name, B_TRUE, NULL,
4693 cb->cb_vdev_names = tmp_name;
4699 is_pool_cb(zpool_handle_t *zhp, void *data)
4702 if (strcmp(name, zpool_get_name(zhp)) == 0)
4709 * Do we have a pool named *name? If so, return 1, otherwise 0.
4714 return (for_each_pool(0, NULL, B_TRUE, NULL, is_pool_cb, name));
4717 /* Are all our argv[] strings pool names? If so return 1, 0 otherwise. */
4719 are_all_pools(int argc, char **argv)
4721 if ((argc == 0) || !*argv)
4725 if (!is_pool(argv[argc]))
4732 * Helper function to print out vdev/pool names we can't resolve. Used for an
4736 error_list_unresolved_vdevs(int argc, char **argv, char *pool_name,
4737 iostat_cbdata_t *cb)
4742 for (i = 0; i < argc; i++) {
4746 str = gettext("pool");
4747 else if (are_vdevs_in_pool(1, &name, pool_name, cb))
4748 str = gettext("vdev in this pool");
4749 else if (are_vdevs_in_pool(1, &name, NULL, cb))
4750 str = gettext("vdev in another pool");
4752 str = gettext("unknown");
4754 fprintf(stderr, "\t%s (%s)\n", name, str);
4759 * Same as get_interval_count(), but with additional checks to not misinterpret
4760 * guids as interval/count values. Assumes VDEV_NAME_GUID is set in
4764 get_interval_count_filter_guids(int *argc, char **argv, float *interval,
4765 unsigned long *count, iostat_cbdata_t *cb)
4767 char **tmpargv = argv;
4768 int argc_for_interval = 0;
4770 /* Is the last arg an interval value? Or a guid? */
4771 if (*argc >= 1 && !are_vdevs_in_pool(1, &argv[*argc - 1], NULL, cb)) {
4773 * The last arg is not a guid, so it's probably an
4776 argc_for_interval++;
4779 !are_vdevs_in_pool(1, &argv[*argc - 2], NULL, cb)) {
4781 * The 2nd to last arg is not a guid, so it's probably
4782 * an interval value.
4784 argc_for_interval++;
4788 /* Point to our list of possible intervals */
4789 tmpargv = &argv[*argc - argc_for_interval];
4791 *argc = *argc - argc_for_interval;
4792 get_interval_count(&argc_for_interval, tmpargv,
4797 * Floating point sleep(). Allows you to pass in a floating point value for
4803 struct timespec req;
4804 req.tv_sec = floor(sec);
4805 req.tv_nsec = (sec - (float)req.tv_sec) * NANOSEC;
4806 nanosleep(&req, NULL);
4810 * Run one of the zpool status/iostat -c scripts with the help (-h) option and
4813 * name: Short name of the script ('iostat').
4814 * path: Full path to the script ('/usr/local/etc/zfs/zpool.d/iostat');
4817 print_zpool_script_help(char *name, char *path)
4819 char *argv[] = {path, "-h", NULL};
4820 char **lines = NULL;
4824 rc = libzfs_run_process_get_stdout_nopath(path, argv, NULL, &lines,
4826 if (rc != 0 || lines == NULL || lines_cnt <= 0) {
4828 libzfs_free_str_array(lines, lines_cnt);
4832 for (int i = 0; i < lines_cnt; i++)
4833 if (!is_blank_str(lines[i]))
4834 printf(" %-14s %s\n", name, lines[i]);
4836 libzfs_free_str_array(lines, lines_cnt);
4840 * Go though the zpool status/iostat -c scripts in the user's path, run their
4841 * help option (-h), and print out the results.
4844 print_zpool_dir_scripts(char *dirpath)
4848 char fullpath[MAXPATHLEN];
4849 struct stat dir_stat;
4851 if ((dir = opendir(dirpath)) != NULL) {
4852 /* print all the files and directories within directory */
4853 while ((ent = readdir(dir)) != NULL) {
4854 sprintf(fullpath, "%s/%s", dirpath, ent->d_name);
4856 /* Print the scripts */
4857 if (stat(fullpath, &dir_stat) == 0)
4858 if (dir_stat.st_mode & S_IXUSR &&
4859 S_ISREG(dir_stat.st_mode))
4860 print_zpool_script_help(ent->d_name,
4868 * Print out help text for all zpool status/iostat -c scripts.
4871 print_zpool_script_list(char *subcommand)
4875 printf(gettext("Available 'zpool %s -c' commands:\n"), subcommand);
4877 sp = zpool_get_cmd_search_path();
4881 dir = strtok(sp, ":");
4882 while (dir != NULL) {
4883 print_zpool_dir_scripts(dir);
4884 dir = strtok(NULL, ":");
4891 * Set the minimum pool/vdev name column width. The width must be at least 10,
4892 * but may be as large as the column width - 42 so it still fits on one line.
4895 get_namewidth_iostat(zpool_handle_t *zhp, void *data)
4897 iostat_cbdata_t *cb = data;
4900 width = get_namewidth(zhp, cb->cb_namewidth, cb->cb_name_flags,
4902 columns = get_columns();
4906 if (width > columns - 42)
4907 width = columns - 42;
4909 cb->cb_namewidth = width;
4915 * zpool iostat [[-c [script1,script2,...]] [-lq]|[-rw]] [-ghHLpPvy] [-n name]
4916 * [-T d|u] [[ pool ...]|[pool vdev ...]|[vdev ...]]
4917 * [interval [count]]
4919 * -c CMD For each vdev, run command CMD
4920 * -g Display guid for individual vdev name.
4921 * -L Follow links when resolving vdev path name.
4922 * -P Display full path for vdev name.
4923 * -v Display statistics for individual vdevs
4925 * -p Display values in parsable (exact) format.
4926 * -H Scripted mode. Don't display headers, and separate properties
4928 * -l Display average latency
4929 * -q Display queue depths
4930 * -w Display latency histograms
4931 * -r Display request size histogram
4932 * -T Display a timestamp in date(1) or Unix format
4933 * -n Only print headers once
4935 * This command can be tricky because we want to be able to deal with pool
4936 * creation/destruction as well as vdev configuration changes. The bulk of this
4937 * processing is handled by the pool_list_* routines in zpool_iter.c. We rely
4938 * on pool_list_update() to detect the addition of new pools. Configuration
4939 * changes are all handled within libzfs.
4942 zpool_do_iostat(int argc, char **argv)
4948 unsigned long count = 0;
4952 boolean_t verbose = B_FALSE;
4953 boolean_t latency = B_FALSE, l_histo = B_FALSE, rq_histo = B_FALSE;
4954 boolean_t queues = B_FALSE, parsable = B_FALSE, scripted = B_FALSE;
4955 boolean_t omit_since_boot = B_FALSE;
4956 boolean_t guid = B_FALSE;
4957 boolean_t follow_links = B_FALSE;
4958 boolean_t full_name = B_FALSE;
4959 boolean_t headers_once = B_FALSE;
4960 iostat_cbdata_t cb = { 0 };
4963 /* Used for printing error message */
4964 const char flag_to_arg[] = {[IOS_LATENCY] = 'l', [IOS_QUEUES] = 'q',
4965 [IOS_L_HISTO] = 'w', [IOS_RQ_HISTO] = 'r'};
4967 uint64_t unsupported_flags;
4970 while ((c = getopt(argc, argv, "c:gLPT:vyhplqrwnH")) != -1) {
4975 gettext("Can't set -c flag twice\n"));
4979 if (getenv("ZPOOL_SCRIPTS_ENABLED") != NULL &&
4980 !libzfs_envvar_is_set("ZPOOL_SCRIPTS_ENABLED")) {
4981 fprintf(stderr, gettext(
4982 "Can't run -c, disabled by "
4983 "ZPOOL_SCRIPTS_ENABLED.\n"));
4987 if ((getuid() <= 0 || geteuid() <= 0) &&
4988 !libzfs_envvar_is_set("ZPOOL_SCRIPTS_AS_ROOT")) {
4989 fprintf(stderr, gettext(
4990 "Can't run -c with root privileges "
4991 "unless ZPOOL_SCRIPTS_AS_ROOT is set.\n"));
5001 follow_links = B_TRUE;
5007 get_timestamp_arg(*optarg);
5031 omit_since_boot = B_TRUE;
5034 headers_once = B_TRUE;
5040 if (optopt == 'c') {
5041 print_zpool_script_list("iostat");
5045 gettext("invalid option '%c'\n"), optopt);
5054 cb.cb_literal = parsable;
5055 cb.cb_scripted = scripted;
5058 cb.cb_name_flags |= VDEV_NAME_GUID;
5060 cb.cb_name_flags |= VDEV_NAME_FOLLOW_LINKS;
5062 cb.cb_name_flags |= VDEV_NAME_PATH;
5063 cb.cb_iteration = 0;
5064 cb.cb_namewidth = 0;
5065 cb.cb_verbose = verbose;
5067 /* Get our interval and count values (if any) */
5069 get_interval_count_filter_guids(&argc, argv, &interval,
5072 get_interval_count(&argc, argv, &interval, &count);
5076 /* No args, so just print the defaults. */
5077 } else if (are_all_pools(argc, argv)) {
5078 /* All the args are pool names */
5079 } else if (are_vdevs_in_pool(argc, argv, NULL, &cb)) {
5080 /* All the args are vdevs */
5081 cb.cb_vdev_names = argv;
5082 cb.cb_vdev_names_count = argc;
5083 argc = 0; /* No pools to process */
5084 } else if (are_all_pools(1, argv)) {
5085 /* The first arg is a pool name */
5086 if (are_vdevs_in_pool(argc - 1, argv + 1, argv[0], &cb)) {
5087 /* ...and the rest are vdev names */
5088 cb.cb_vdev_names = argv + 1;
5089 cb.cb_vdev_names_count = argc - 1;
5090 argc = 1; /* One pool to process */
5092 fprintf(stderr, gettext("Expected either a list of "));
5093 fprintf(stderr, gettext("pools, or list of vdevs in"));
5094 fprintf(stderr, " \"%s\", ", argv[0]);
5095 fprintf(stderr, gettext("but got:\n"));
5096 error_list_unresolved_vdevs(argc - 1, argv + 1,
5098 fprintf(stderr, "\n");
5104 * The args don't make sense. The first arg isn't a pool name,
5105 * nor are all the args vdevs.
5107 fprintf(stderr, gettext("Unable to parse pools/vdevs list.\n"));
5108 fprintf(stderr, "\n");
5112 if (cb.cb_vdev_names_count != 0) {
5114 * If user specified vdevs, it implies verbose.
5116 cb.cb_verbose = B_TRUE;
5120 * Construct the list of all interesting pools.
5123 if ((list = pool_list_get(argc, argv, NULL, &ret)) == NULL)
5126 if (pool_list_count(list) == 0 && argc != 0) {
5127 pool_list_free(list);
5131 if (pool_list_count(list) == 0 && interval == 0) {
5132 pool_list_free(list);
5133 (void) fprintf(stderr, gettext("no pools available\n"));
5137 if ((l_histo || rq_histo) && (cmd != NULL || latency || queues)) {
5138 pool_list_free(list);
5139 (void) fprintf(stderr,
5140 gettext("[-r|-w] isn't allowed with [-c|-l|-q]\n"));
5145 if (l_histo && rq_histo) {
5146 pool_list_free(list);
5147 (void) fprintf(stderr,
5148 gettext("Only one of [-r|-w] can be passed at a time\n"));
5154 * Enter the main iostat loop.
5160 * Histograms tables look out of place when you try to display
5161 * them with the other stats, so make a rule that you can only
5162 * print histograms by themselves.
5164 cb.cb_flags = IOS_L_HISTO_M;
5165 } else if (rq_histo) {
5166 cb.cb_flags = IOS_RQ_HISTO_M;
5168 cb.cb_flags = IOS_DEFAULT_M;
5170 cb.cb_flags |= IOS_LATENCY_M;
5172 cb.cb_flags |= IOS_QUEUES_M;
5176 * See if the module supports all the stats we want to display.
5178 unsupported_flags = cb.cb_flags & ~get_stat_flags(list);
5179 if (unsupported_flags) {
5183 gettext("The loaded zfs module doesn't support:"));
5185 /* for each bit set in unsupported_flags */
5186 for (f = unsupported_flags; f; f &= ~(1ULL << idx)) {
5187 idx = lowbit64(f) - 1;
5188 fprintf(stderr, " -%c", flag_to_arg[idx]);
5191 fprintf(stderr, ". Try running a newer module.\n");
5192 pool_list_free(list);
5198 if ((npools = pool_list_count(list)) == 0)
5199 (void) fprintf(stderr, gettext("no pools available\n"));
5202 * If this is the first iteration and -y was supplied
5203 * we skip any printing.
5205 boolean_t skip = (omit_since_boot &&
5206 cb.cb_iteration == 0);
5209 * Refresh all statistics. This is done as an
5210 * explicit step before calculating the maximum name
5211 * width, so that any * configuration changes are
5212 * properly accounted for.
5214 (void) pool_list_iter(list, B_FALSE, refresh_iostat,
5218 * Iterate over all pools to determine the maximum width
5219 * for the pool / device name column across all pools.
5221 cb.cb_namewidth = 0;
5222 (void) pool_list_iter(list, B_FALSE,
5223 get_namewidth_iostat, &cb);
5225 if (timestamp_fmt != NODATE)
5226 print_timestamp(timestamp_fmt);
5228 if (cmd != NULL && cb.cb_verbose &&
5229 !(cb.cb_flags & IOS_ANYHISTO_M)) {
5230 cb.vcdl = all_pools_for_each_vdev_run(argc,
5231 argv, cmd, g_zfs, cb.cb_vdev_names,
5232 cb.cb_vdev_names_count, cb.cb_name_flags);
5238 * Are we connected to TTY? If not, headers_once
5239 * should be true, to avoid breaking scripts.
5241 if (isatty(fileno(stdout)) == 0)
5242 headers_once = B_TRUE;
5245 * Check terminal size so we can print headers
5246 * even when terminal window has its height
5249 if (headers_once == B_FALSE) {
5250 if (ioctl(1, TIOCGWINSZ, &win) != -1 &&
5252 winheight = win.ws_row;
5254 headers_once = B_TRUE;
5258 * If it's the first time and we're not skipping it,
5259 * or either skip or verbose mode, print the header.
5261 * The histogram code explicitly prints its header on
5262 * every vdev, so skip this for histograms.
5264 if (((++cb.cb_iteration == 1 && !skip) ||
5265 (skip != verbose) ||
5267 (cb.cb_iteration % winheight) == 0)) &&
5268 (!(cb.cb_flags & IOS_ANYHISTO_M)) &&
5270 print_iostat_header(&cb);
5273 (void) fsleep(interval);
5277 pool_list_iter(list, B_FALSE, print_iostat, &cb);
5280 * If there's more than one pool, and we're not in
5281 * verbose mode (which prints a separator for us),
5282 * then print a separator.
5284 * In addition, if we're printing specific vdevs then
5285 * we also want an ending separator.
5287 if (((npools > 1 && !verbose &&
5288 !(cb.cb_flags & IOS_ANYHISTO_M)) ||
5289 (!(cb.cb_flags & IOS_ANYHISTO_M) &&
5290 cb.cb_vdev_names_count)) &&
5292 print_iostat_separator(&cb);
5293 if (cb.vcdl != NULL)
5294 print_cmd_columns(cb.vcdl, 1);
5298 if (cb.vcdl != NULL)
5299 free_vdev_cmd_data_list(cb.vcdl);
5304 * Flush the output so that redirection to a file isn't buffered
5307 (void) fflush(stdout);
5312 if (count != 0 && --count == 0)
5315 (void) fsleep(interval);
5318 pool_list_free(list);
5323 typedef struct list_cbdata {
5324 boolean_t cb_verbose;
5327 boolean_t cb_scripted;
5328 zprop_list_t *cb_proplist;
5329 boolean_t cb_literal;
5334 * Given a list of columns to display, output appropriate headers for each one.
5337 print_header(list_cbdata_t *cb)
5339 zprop_list_t *pl = cb->cb_proplist;
5340 char headerbuf[ZPOOL_MAXPROPLEN];
5342 boolean_t first = B_TRUE;
5343 boolean_t right_justify;
5346 for (; pl != NULL; pl = pl->pl_next) {
5347 width = pl->pl_width;
5348 if (first && cb->cb_verbose) {
5350 * Reset the width to accommodate the verbose listing
5353 width = cb->cb_namewidth;
5361 right_justify = B_FALSE;
5362 if (pl->pl_prop != ZPROP_INVAL) {
5363 header = zpool_prop_column_name(pl->pl_prop);
5364 right_justify = zpool_prop_align_right(pl->pl_prop);
5368 for (i = 0; pl->pl_user_prop[i] != '\0'; i++)
5369 headerbuf[i] = toupper(pl->pl_user_prop[i]);
5370 headerbuf[i] = '\0';
5374 if (pl->pl_next == NULL && !right_justify)
5375 (void) printf("%s", header);
5376 else if (right_justify)
5377 (void) printf("%*s", (int)width, header);
5379 (void) printf("%-*s", (int)width, header);
5382 (void) printf("\n");
5386 * Given a pool and a list of properties, print out all the properties according
5387 * to the described layout. Used by zpool_do_list().
5390 print_pool(zpool_handle_t *zhp, list_cbdata_t *cb)
5392 zprop_list_t *pl = cb->cb_proplist;
5393 boolean_t first = B_TRUE;
5394 char property[ZPOOL_MAXPROPLEN];
5396 boolean_t right_justify;
5399 for (; pl != NULL; pl = pl->pl_next) {
5401 width = pl->pl_width;
5402 if (first && cb->cb_verbose) {
5404 * Reset the width to accommodate the verbose listing
5407 width = cb->cb_namewidth;
5411 if (cb->cb_scripted)
5412 (void) printf("\t");
5419 right_justify = B_FALSE;
5420 if (pl->pl_prop != ZPROP_INVAL) {
5421 if (zpool_get_prop(zhp, pl->pl_prop, property,
5422 sizeof (property), NULL, cb->cb_literal) != 0)
5427 right_justify = zpool_prop_align_right(pl->pl_prop);
5428 } else if ((zpool_prop_feature(pl->pl_user_prop) ||
5429 zpool_prop_unsupported(pl->pl_user_prop)) &&
5430 zpool_prop_get_feature(zhp, pl->pl_user_prop, property,
5431 sizeof (property)) == 0) {
5439 * If this is being called in scripted mode, or if this is the
5440 * last column and it is left-justified, don't include a width
5443 if (cb->cb_scripted || (pl->pl_next == NULL && !right_justify))
5444 (void) printf("%s", propstr);
5445 else if (right_justify)
5446 (void) printf("%*s", (int)width, propstr);
5448 (void) printf("%-*s", (int)width, propstr);
5451 (void) printf("\n");
5455 print_one_column(zpool_prop_t prop, uint64_t value, const char *str,
5456 boolean_t scripted, boolean_t valid, enum zfs_nicenum_format format)
5460 size_t width = zprop_width(prop, &fixed, ZFS_TYPE_POOL);
5463 case ZPOOL_PROP_EXPANDSZ:
5464 case ZPOOL_PROP_CHECKPOINT:
5465 case ZPOOL_PROP_DEDUPRATIO:
5467 (void) strlcpy(propval, "-", sizeof (propval));
5469 zfs_nicenum_format(value, propval, sizeof (propval),
5472 case ZPOOL_PROP_FRAGMENTATION:
5473 if (value == ZFS_FRAG_INVALID) {
5474 (void) strlcpy(propval, "-", sizeof (propval));
5475 } else if (format == ZFS_NICENUM_RAW) {
5476 (void) snprintf(propval, sizeof (propval), "%llu",
5477 (unsigned long long)value);
5479 (void) snprintf(propval, sizeof (propval), "%llu%%",
5480 (unsigned long long)value);
5483 case ZPOOL_PROP_CAPACITY:
5484 /* capacity value is in parts-per-10,000 (aka permyriad) */
5485 if (format == ZFS_NICENUM_RAW)
5486 (void) snprintf(propval, sizeof (propval), "%llu",
5487 (unsigned long long)value / 100);
5489 (void) snprintf(propval, sizeof (propval),
5490 value < 1000 ? "%1.2f%%" : value < 10000 ?
5491 "%2.1f%%" : "%3.0f%%", value / 100.0);
5493 case ZPOOL_PROP_HEALTH:
5495 snprintf(propval, sizeof (propval), "%-*s", (int)width, str);
5498 zfs_nicenum_format(value, propval, sizeof (propval), format);
5502 (void) strlcpy(propval, "-", sizeof (propval));
5505 (void) printf("\t%s", propval);
5507 (void) printf(" %*s", (int)width, propval);
5511 * print static default line per vdev
5512 * not compatible with '-o' <proplist> option
5515 print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
5516 list_cbdata_t *cb, int depth, boolean_t isspare)
5522 boolean_t scripted = cb->cb_scripted;
5523 uint64_t islog = B_FALSE;
5524 char *dashes = "%-*s - - - - "
5527 verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
5528 (uint64_t **)&vs, &c) == 0);
5531 boolean_t toplevel = (vs->vs_space != 0);
5533 enum zfs_nicenum_format format;
5537 format = ZFS_NICENUM_RAW;
5539 format = ZFS_NICENUM_1024;
5541 if (strcmp(name, VDEV_TYPE_INDIRECT) == 0)
5545 (void) printf("\t%s", name);
5546 else if (strlen(name) + depth > cb->cb_namewidth)
5547 (void) printf("%*s%s", depth, "", name);
5549 (void) printf("%*s%s%*s", depth, "", name,
5550 (int)(cb->cb_namewidth - strlen(name) - depth), "");
5553 * Print the properties for the individual vdevs. Some
5554 * properties are only applicable to toplevel vdevs. The
5555 * 'toplevel' boolean value is passed to the print_one_column()
5556 * to indicate that the value is valid.
5558 print_one_column(ZPOOL_PROP_SIZE, vs->vs_space, NULL, scripted,
5560 print_one_column(ZPOOL_PROP_ALLOCATED, vs->vs_alloc, NULL,
5561 scripted, toplevel, format);
5562 print_one_column(ZPOOL_PROP_FREE, vs->vs_space - vs->vs_alloc,
5563 NULL, scripted, toplevel, format);
5564 print_one_column(ZPOOL_PROP_CHECKPOINT,
5565 vs->vs_checkpoint_space, NULL, scripted, toplevel, format);
5566 print_one_column(ZPOOL_PROP_EXPANDSZ, vs->vs_esize, NULL,
5567 scripted, B_TRUE, format);
5568 print_one_column(ZPOOL_PROP_FRAGMENTATION,
5569 vs->vs_fragmentation, NULL, scripted,
5570 (vs->vs_fragmentation != ZFS_FRAG_INVALID && toplevel),
5572 cap = (vs->vs_space == 0) ? 0 :
5573 (vs->vs_alloc * 10000 / vs->vs_space);
5574 print_one_column(ZPOOL_PROP_CAPACITY, cap, NULL,
5575 scripted, toplevel, format);
5576 print_one_column(ZPOOL_PROP_DEDUPRATIO, 0, NULL,
5577 scripted, toplevel, format);
5578 state = zpool_state_to_name(vs->vs_state, vs->vs_aux);
5580 if (vs->vs_aux == VDEV_AUX_SPARED)
5582 else if (vs->vs_state == VDEV_STATE_HEALTHY)
5585 print_one_column(ZPOOL_PROP_HEALTH, 0, state, scripted,
5587 (void) printf("\n");
5590 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
5591 &child, &children) != 0)
5594 /* list the normal vdevs first */
5595 for (c = 0; c < children; c++) {
5596 uint64_t ishole = B_FALSE;
5598 if (nvlist_lookup_uint64(child[c],
5599 ZPOOL_CONFIG_IS_HOLE, &ishole) == 0 && ishole)
5602 if (nvlist_lookup_uint64(child[c],
5603 ZPOOL_CONFIG_IS_LOG, &islog) == 0 && islog)
5606 if (nvlist_exists(child[c], ZPOOL_CONFIG_ALLOCATION_BIAS))
5609 vname = zpool_vdev_name(g_zfs, zhp, child[c],
5611 print_list_stats(zhp, vname, child[c], cb, depth + 2, B_FALSE);
5615 /* list the classes: 'logs', 'dedup', and 'special' */
5616 for (uint_t n = 0; n < 3; n++) {
5617 boolean_t printed = B_FALSE;
5619 for (c = 0; c < children; c++) {
5623 if (nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
5624 &islog) == 0 && islog) {
5625 bias = VDEV_ALLOC_CLASS_LOGS;
5627 (void) nvlist_lookup_string(child[c],
5628 ZPOOL_CONFIG_ALLOCATION_BIAS, &bias);
5629 (void) nvlist_lookup_string(child[c],
5630 ZPOOL_CONFIG_TYPE, &type);
5632 if (bias == NULL || strcmp(bias, class_name[n]) != 0)
5634 if (!islog && strcmp(type, VDEV_TYPE_INDIRECT) == 0)
5638 /* LINTED E_SEC_PRINTF_VAR_FMT */
5639 (void) printf(dashes, cb->cb_namewidth,
5643 vname = zpool_vdev_name(g_zfs, zhp, child[c],
5645 print_list_stats(zhp, vname, child[c], cb, depth + 2,
5651 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
5652 &child, &children) == 0 && children > 0) {
5653 /* LINTED E_SEC_PRINTF_VAR_FMT */
5654 (void) printf(dashes, cb->cb_namewidth, "cache");
5655 for (c = 0; c < children; c++) {
5656 vname = zpool_vdev_name(g_zfs, zhp, child[c],
5658 print_list_stats(zhp, vname, child[c], cb, depth + 2,
5664 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES, &child,
5665 &children) == 0 && children > 0) {
5666 /* LINTED E_SEC_PRINTF_VAR_FMT */
5667 (void) printf(dashes, cb->cb_namewidth, "spare");
5668 for (c = 0; c < children; c++) {
5669 vname = zpool_vdev_name(g_zfs, zhp, child[c],
5671 print_list_stats(zhp, vname, child[c], cb, depth + 2,
5679 * Generic callback function to list a pool.
5682 list_callback(zpool_handle_t *zhp, void *data)
5684 list_cbdata_t *cbp = data;
5686 print_pool(zhp, cbp);
5688 if (cbp->cb_verbose) {
5689 nvlist_t *config, *nvroot;
5691 config = zpool_get_config(zhp, NULL);
5692 verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
5694 print_list_stats(zhp, NULL, nvroot, cbp, 0, B_FALSE);
5701 * Set the minimum pool/vdev name column width. The width must be at least 9,
5702 * but may be as large as needed.
5705 get_namewidth_list(zpool_handle_t *zhp, void *data)
5707 list_cbdata_t *cb = data;
5710 width = get_namewidth(zhp, cb->cb_namewidth, cb->cb_name_flags,
5716 cb->cb_namewidth = width;
5722 * zpool list [-gHLpP] [-o prop[,prop]*] [-T d|u] [pool] ... [interval [count]]
5724 * -g Display guid for individual vdev name.
5725 * -H Scripted mode. Don't display headers, and separate properties
5727 * -L Follow links when resolving vdev path name.
5728 * -o List of properties to display. Defaults to
5729 * "name,size,allocated,free,expandsize,fragmentation,capacity,"
5730 * "dedupratio,health,altroot"
5731 * -p Display values in parsable (exact) format.
5732 * -P Display full path for vdev name.
5733 * -T Display a timestamp in date(1) or Unix format
5735 * List all pools in the system, whether or not they're healthy. Output space
5736 * statistics for each one, as well as health status summary.
5739 zpool_do_list(int argc, char **argv)
5743 list_cbdata_t cb = { 0 };
5744 static char default_props[] =
5745 "name,size,allocated,free,checkpoint,expandsize,fragmentation,"
5746 "capacity,dedupratio,health,altroot";
5747 char *props = default_props;
5749 unsigned long count = 0;
5751 boolean_t first = B_TRUE;
5754 while ((c = getopt(argc, argv, ":gHLo:pPT:v")) != -1) {
5757 cb.cb_name_flags |= VDEV_NAME_GUID;
5760 cb.cb_scripted = B_TRUE;
5763 cb.cb_name_flags |= VDEV_NAME_FOLLOW_LINKS;
5769 cb.cb_name_flags |= VDEV_NAME_PATH;
5772 cb.cb_literal = B_TRUE;
5775 get_timestamp_arg(*optarg);
5778 cb.cb_verbose = B_TRUE;
5779 cb.cb_namewidth = 8; /* 8 until precalc is avail */
5782 (void) fprintf(stderr, gettext("missing argument for "
5783 "'%c' option\n"), optopt);
5787 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
5796 get_interval_count(&argc, argv, &interval, &count);
5798 if (zprop_get_list(g_zfs, props, &cb.cb_proplist, ZFS_TYPE_POOL) != 0)
5802 if ((list = pool_list_get(argc, argv, &cb.cb_proplist,
5806 if (pool_list_count(list) == 0)
5809 cb.cb_namewidth = 0;
5810 (void) pool_list_iter(list, B_FALSE, get_namewidth_list, &cb);
5812 if (timestamp_fmt != NODATE)
5813 print_timestamp(timestamp_fmt);
5815 if (!cb.cb_scripted && (first || cb.cb_verbose)) {
5819 ret = pool_list_iter(list, B_TRUE, list_callback, &cb);
5824 if (count != 0 && --count == 0)
5827 pool_list_free(list);
5828 (void) fsleep(interval);
5831 if (argc == 0 && !cb.cb_scripted && pool_list_count(list) == 0) {
5832 (void) printf(gettext("no pools available\n"));
5836 pool_list_free(list);
5837 zprop_free_list(cb.cb_proplist);
5842 zpool_do_attach_or_replace(int argc, char **argv, int replacing)
5844 boolean_t force = B_FALSE;
5847 char *poolname, *old_disk, *new_disk;
5848 zpool_handle_t *zhp;
5849 nvlist_t *props = NULL;
5854 while ((c = getopt(argc, argv, "fo:")) != -1) {
5860 if ((propval = strchr(optarg, '=')) == NULL) {
5861 (void) fprintf(stderr, gettext("missing "
5862 "'=' for -o option\n"));
5868 if ((strcmp(optarg, ZPOOL_CONFIG_ASHIFT) != 0) ||
5869 (add_prop_list(optarg, propval, &props, B_TRUE)))
5873 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
5882 /* get pool name and check number of arguments */
5884 (void) fprintf(stderr, gettext("missing pool name argument\n"));
5891 (void) fprintf(stderr,
5892 gettext("missing <device> specification\n"));
5900 (void) fprintf(stderr,
5901 gettext("missing <new_device> specification\n"));
5904 new_disk = old_disk;
5914 (void) fprintf(stderr, gettext("too many arguments\n"));
5918 if ((zhp = zpool_open(g_zfs, poolname)) == NULL) {
5923 if (zpool_get_config(zhp, NULL) == NULL) {
5924 (void) fprintf(stderr, gettext("pool '%s' is unavailable\n"),
5931 /* unless manually specified use "ashift" pool property (if set) */
5932 if (!nvlist_exists(props, ZPOOL_CONFIG_ASHIFT)) {
5935 char strval[ZPOOL_MAXPROPLEN];
5937 intval = zpool_get_prop_int(zhp, ZPOOL_PROP_ASHIFT, &src);
5938 if (src != ZPROP_SRC_DEFAULT) {
5939 (void) sprintf(strval, "%" PRId32, intval);
5940 verify(add_prop_list(ZPOOL_CONFIG_ASHIFT, strval,
5941 &props, B_TRUE) == 0);
5945 nvroot = make_root_vdev(zhp, props, force, B_FALSE, replacing, B_FALSE,
5947 if (nvroot == NULL) {
5953 ret = zpool_vdev_attach(zhp, old_disk, new_disk, nvroot, replacing);
5956 nvlist_free(nvroot);
5963 * zpool replace [-f] <pool> <device> <new_device>
5965 * -f Force attach, even if <new_device> appears to be in use.
5967 * Replace <device> with <new_device>.
5971 zpool_do_replace(int argc, char **argv)
5973 return (zpool_do_attach_or_replace(argc, argv, B_TRUE));
5977 * zpool attach [-f] [-o property=value] <pool> <device> <new_device>
5979 * -f Force attach, even if <new_device> appears to be in use.
5980 * -o Set property=value.
5982 * Attach <new_device> to the mirror containing <device>. If <device> is not
5983 * part of a mirror, then <device> will be transformed into a mirror of
5984 * <device> and <new_device>. In either case, <new_device> will begin life
5985 * with a DTL of [0, now], and will immediately begin to resilver itself.
5988 zpool_do_attach(int argc, char **argv)
5990 return (zpool_do_attach_or_replace(argc, argv, B_FALSE));
5994 * zpool detach [-f] <pool> <device>
5996 * -f Force detach of <device>, even if DTLs argue against it
5997 * (not supported yet)
5999 * Detach a device from a mirror. The operation will be refused if <device>
6000 * is the last device in the mirror, or if the DTLs indicate that this device
6001 * has the only valid copy of some data.
6005 zpool_do_detach(int argc, char **argv)
6008 char *poolname, *path;
6009 zpool_handle_t *zhp;
6013 while ((c = getopt(argc, argv, "f")) != -1) {
6017 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
6026 /* get pool name and check number of arguments */
6028 (void) fprintf(stderr, gettext("missing pool name argument\n"));
6033 (void) fprintf(stderr,
6034 gettext("missing <device> specification\n"));
6041 if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
6044 ret = zpool_vdev_detach(zhp, path);
6052 * zpool split [-gLnP] [-o prop=val] ...
6054 * [-R altroot] <pool> <newpool> [<device> ...]
6056 * -g Display guid for individual vdev name.
6057 * -L Follow links when resolving vdev path name.
6058 * -n Do not split the pool, but display the resulting layout if
6059 * it were to be split.
6060 * -o Set property=value, or set mount options.
6061 * -P Display full path for vdev name.
6062 * -R Mount the split-off pool under an alternate root.
6063 * -l Load encryption keys while importing.
6065 * Splits the named pool and gives it the new pool name. Devices to be split
6066 * off may be listed, provided that no more than one device is specified
6067 * per top-level vdev mirror. The newly split pool is left in an exported
6068 * state unless -R is specified.
6070 * Restrictions: the top-level of the pool pool must only be made up of
6071 * mirrors; all devices in the pool must be healthy; no device may be
6072 * undergoing a resilvering operation.
6075 zpool_do_split(int argc, char **argv)
6077 char *srcpool, *newpool, *propval;
6078 char *mntopts = NULL;
6081 boolean_t loadkeys = B_FALSE;
6082 zpool_handle_t *zhp;
6083 nvlist_t *config, *props = NULL;
6085 flags.dryrun = B_FALSE;
6086 flags.import = B_FALSE;
6087 flags.name_flags = 0;
6090 while ((c = getopt(argc, argv, ":gLR:lno:P")) != -1) {
6093 flags.name_flags |= VDEV_NAME_GUID;
6096 flags.name_flags |= VDEV_NAME_FOLLOW_LINKS;
6099 flags.import = B_TRUE;
6101 zpool_prop_to_name(ZPOOL_PROP_ALTROOT), optarg,
6102 &props, B_TRUE) != 0) {
6111 flags.dryrun = B_TRUE;
6114 if ((propval = strchr(optarg, '=')) != NULL) {
6117 if (add_prop_list(optarg, propval,
6118 &props, B_TRUE) != 0) {
6127 flags.name_flags |= VDEV_NAME_PATH;
6130 (void) fprintf(stderr, gettext("missing argument for "
6131 "'%c' option\n"), optopt);
6135 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
6142 if (!flags.import && mntopts != NULL) {
6143 (void) fprintf(stderr, gettext("setting mntopts is only "
6144 "valid when importing the pool\n"));
6148 if (!flags.import && loadkeys) {
6149 (void) fprintf(stderr, gettext("loading keys is only "
6150 "valid when importing the pool\n"));
6158 (void) fprintf(stderr, gettext("Missing pool name\n"));
6162 (void) fprintf(stderr, gettext("Missing new pool name\n"));
6172 if ((zhp = zpool_open(g_zfs, srcpool)) == NULL) {
6177 config = split_mirror_vdev(zhp, newpool, props, flags, argc, argv);
6178 if (config == NULL) {
6182 (void) printf(gettext("would create '%s' with the "
6183 "following layout:\n\n"), newpool);
6184 print_vdev_tree(NULL, newpool, config, 0, "",
6191 if (ret != 0 || flags.dryrun || !flags.import) {
6192 nvlist_free(config);
6198 * The split was successful. Now we need to open the new
6199 * pool and import it.
6201 if ((zhp = zpool_open_canfail(g_zfs, newpool)) == NULL) {
6202 nvlist_free(config);
6208 ret = zfs_crypto_attempt_load_keys(g_zfs, newpool);
6213 if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL &&
6214 zpool_enable_datasets(zhp, mntopts, 0) != 0) {
6216 (void) fprintf(stderr, gettext("Split was successful, but "
6217 "the datasets could not all be mounted\n"));
6218 (void) fprintf(stderr, gettext("Try doing '%s' with a "
6219 "different altroot\n"), "zpool import");
6222 nvlist_free(config);
6231 * zpool online <pool> <device> ...
6234 zpool_do_online(int argc, char **argv)
6238 zpool_handle_t *zhp;
6240 vdev_state_t newstate;
6244 while ((c = getopt(argc, argv, "et")) != -1) {
6247 flags |= ZFS_ONLINE_EXPAND;
6251 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
6260 /* get pool name and check number of arguments */
6262 (void) fprintf(stderr, gettext("missing pool name\n"));
6266 (void) fprintf(stderr, gettext("missing device name\n"));
6272 if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
6275 for (i = 1; i < argc; i++) {
6276 if (zpool_vdev_online(zhp, argv[i], flags, &newstate) == 0) {
6277 if (newstate != VDEV_STATE_HEALTHY) {
6278 (void) printf(gettext("warning: device '%s' "
6279 "onlined, but remains in faulted state\n"),
6281 if (newstate == VDEV_STATE_FAULTED)
6282 (void) printf(gettext("use 'zpool "
6283 "clear' to restore a faulted "
6286 (void) printf(gettext("use 'zpool "
6287 "replace' to replace devices "
6288 "that are no longer present\n"));
6301 * zpool offline [-ft] <pool> <device> ...
6303 * -f Force the device into a faulted state.
6305 * -t Only take the device off-line temporarily. The offline/faulted
6306 * state will not be persistent across reboots.
6310 zpool_do_offline(int argc, char **argv)
6314 zpool_handle_t *zhp;
6316 boolean_t istmp = B_FALSE;
6317 boolean_t fault = B_FALSE;
6320 while ((c = getopt(argc, argv, "ft")) != -1) {
6329 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
6338 /* get pool name and check number of arguments */
6340 (void) fprintf(stderr, gettext("missing pool name\n"));
6344 (void) fprintf(stderr, gettext("missing device name\n"));
6350 if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
6353 for (i = 1; i < argc; i++) {
6355 uint64_t guid = zpool_vdev_path_to_guid(zhp, argv[i]);
6357 if (istmp == B_FALSE) {
6358 /* Force the fault to persist across imports */
6359 aux = VDEV_AUX_EXTERNAL_PERSIST;
6361 aux = VDEV_AUX_EXTERNAL;
6364 if (guid == 0 || zpool_vdev_fault(zhp, guid, aux) != 0)
6367 if (zpool_vdev_offline(zhp, argv[i], istmp) != 0)
6378 * zpool clear <pool> [device]
6380 * Clear all errors associated with a pool or a particular device.
6383 zpool_do_clear(int argc, char **argv)
6387 boolean_t dryrun = B_FALSE;
6388 boolean_t do_rewind = B_FALSE;
6389 boolean_t xtreme_rewind = B_FALSE;
6390 uint32_t rewind_policy = ZPOOL_NO_REWIND;
6391 nvlist_t *policy = NULL;
6392 zpool_handle_t *zhp;
6393 char *pool, *device;
6396 while ((c = getopt(argc, argv, "FnX")) != -1) {
6405 xtreme_rewind = B_TRUE;
6408 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
6418 (void) fprintf(stderr, gettext("missing pool name\n"));
6423 (void) fprintf(stderr, gettext("too many arguments\n"));
6427 if ((dryrun || xtreme_rewind) && !do_rewind) {
6428 (void) fprintf(stderr,
6429 gettext("-n or -X only meaningful with -F\n"));
6433 rewind_policy = ZPOOL_TRY_REWIND;
6435 rewind_policy = ZPOOL_DO_REWIND;
6437 rewind_policy |= ZPOOL_EXTREME_REWIND;
6439 /* In future, further rewind policy choices can be passed along here */
6440 if (nvlist_alloc(&policy, NV_UNIQUE_NAME, 0) != 0 ||
6441 nvlist_add_uint32(policy, ZPOOL_LOAD_REWIND_POLICY,
6442 rewind_policy) != 0) {
6447 device = argc == 2 ? argv[1] : NULL;
6449 if ((zhp = zpool_open_canfail(g_zfs, pool)) == NULL) {
6450 nvlist_free(policy);
6454 if (zpool_clear(zhp, device, policy) != 0)
6459 nvlist_free(policy);
6465 * zpool reguid <pool>
6468 zpool_do_reguid(int argc, char **argv)
6472 zpool_handle_t *zhp;
6476 while ((c = getopt(argc, argv, "")) != -1) {
6479 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
6488 /* get pool name and check number of arguments */
6490 (void) fprintf(stderr, gettext("missing pool name\n"));
6495 (void) fprintf(stderr, gettext("too many arguments\n"));
6500 if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
6503 ret = zpool_reguid(zhp);
6511 * zpool reopen <pool>
6513 * Reopen the pool so that the kernel can update the sizes of all vdevs.
6516 zpool_do_reopen(int argc, char **argv)
6520 boolean_t scrub_restart = B_TRUE;
6523 while ((c = getopt(argc, argv, "n")) != -1) {
6526 scrub_restart = B_FALSE;
6529 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
6538 /* if argc == 0 we will execute zpool_reopen_one on all pools */
6539 ret = for_each_pool(argc, argv, B_TRUE, NULL, zpool_reopen_one,
6545 typedef struct scrub_cbdata {
6549 pool_scrub_cmd_t cb_scrub_cmd;
6553 zpool_has_checkpoint(zpool_handle_t *zhp)
6555 nvlist_t *config, *nvroot;
6557 config = zpool_get_config(zhp, NULL);
6559 if (config != NULL) {
6560 pool_checkpoint_stat_t *pcs = NULL;
6563 nvroot = fnvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE);
6564 (void) nvlist_lookup_uint64_array(nvroot,
6565 ZPOOL_CONFIG_CHECKPOINT_STATS, (uint64_t **)&pcs, &c);
6567 if (pcs == NULL || pcs->pcs_state == CS_NONE)
6570 assert(pcs->pcs_state == CS_CHECKPOINT_EXISTS ||
6571 pcs->pcs_state == CS_CHECKPOINT_DISCARDING);
6579 scrub_callback(zpool_handle_t *zhp, void *data)
6581 scrub_cbdata_t *cb = data;
6585 * Ignore faulted pools.
6587 if (zpool_get_state(zhp) == POOL_STATE_UNAVAIL) {
6588 (void) fprintf(stderr, gettext("cannot scan '%s': pool is "
6589 "currently unavailable\n"), zpool_get_name(zhp));
6593 err = zpool_scan(zhp, cb->cb_type, cb->cb_scrub_cmd);
6595 if (err == 0 && zpool_has_checkpoint(zhp) &&
6596 cb->cb_type == POOL_SCAN_SCRUB) {
6597 (void) printf(gettext("warning: will not scrub state that "
6598 "belongs to the checkpoint of pool '%s'\n"),
6599 zpool_get_name(zhp));
6606 * zpool scrub [-s | -p] <pool> ...
6608 * -s Stop. Stops any in-progress scrub.
6609 * -p Pause. Pause in-progress scrub.
6612 zpool_do_scrub(int argc, char **argv)
6617 cb.cb_type = POOL_SCAN_SCRUB;
6618 cb.cb_scrub_cmd = POOL_SCRUB_NORMAL;
6621 while ((c = getopt(argc, argv, "sp")) != -1) {
6624 cb.cb_type = POOL_SCAN_NONE;
6627 cb.cb_scrub_cmd = POOL_SCRUB_PAUSE;
6630 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
6636 if (cb.cb_type == POOL_SCAN_NONE &&
6637 cb.cb_scrub_cmd == POOL_SCRUB_PAUSE) {
6638 (void) fprintf(stderr, gettext("invalid option combination: "
6639 "-s and -p are mutually exclusive\n"));
6649 (void) fprintf(stderr, gettext("missing pool name argument\n"));
6653 return (for_each_pool(argc, argv, B_TRUE, NULL, scrub_callback, &cb));
6657 * zpool resilver <pool> ...
6659 * Restarts any in-progress resilver
6662 zpool_do_resilver(int argc, char **argv)
6667 cb.cb_type = POOL_SCAN_RESILVER;
6668 cb.cb_scrub_cmd = POOL_SCRUB_NORMAL;
6673 while ((c = getopt(argc, argv, "")) != -1) {
6676 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
6686 (void) fprintf(stderr, gettext("missing pool name argument\n"));
6690 return (for_each_pool(argc, argv, B_TRUE, NULL, scrub_callback, &cb));
6695 * Print out detailed scrub status.
6698 print_scan_status(pool_scan_stat_t *ps)
6700 time_t start, end, pause;
6701 uint64_t total_secs_left;
6702 uint64_t elapsed, secs_left, mins_left, hours_left, days_left;
6703 uint64_t pass_scanned, scanned, pass_issued, issued, total;
6704 uint64_t scan_rate, issue_rate;
6705 double fraction_done;
6706 char processed_buf[7], scanned_buf[7], issued_buf[7], total_buf[7];
6707 char srate_buf[7], irate_buf[7];
6709 (void) printf(gettext(" scan: "));
6711 /* If there's never been a scan, there's not much to say. */
6712 if (ps == NULL || ps->pss_func == POOL_SCAN_NONE ||
6713 ps->pss_func >= POOL_SCAN_FUNCS) {
6714 (void) printf(gettext("none requested\n"));
6718 start = ps->pss_start_time;
6719 end = ps->pss_end_time;
6720 pause = ps->pss_pass_scrub_pause;
6722 zfs_nicebytes(ps->pss_processed, processed_buf, sizeof (processed_buf));
6724 assert(ps->pss_func == POOL_SCAN_SCRUB ||
6725 ps->pss_func == POOL_SCAN_RESILVER);
6727 /* Scan is finished or canceled. */
6728 if (ps->pss_state == DSS_FINISHED) {
6729 total_secs_left = end - start;
6730 days_left = total_secs_left / 60 / 60 / 24;
6731 hours_left = (total_secs_left / 60 / 60) % 24;
6732 mins_left = (total_secs_left / 60) % 60;
6733 secs_left = (total_secs_left % 60);
6735 if (ps->pss_func == POOL_SCAN_SCRUB) {
6736 (void) printf(gettext("scrub repaired %s "
6737 "in %llu days %02llu:%02llu:%02llu "
6738 "with %llu errors on %s"), processed_buf,
6739 (u_longlong_t)days_left, (u_longlong_t)hours_left,
6740 (u_longlong_t)mins_left, (u_longlong_t)secs_left,
6741 (u_longlong_t)ps->pss_errors, ctime(&end));
6742 } else if (ps->pss_func == POOL_SCAN_RESILVER) {
6743 (void) printf(gettext("resilvered %s "
6744 "in %llu days %02llu:%02llu:%02llu "
6745 "with %llu errors on %s"), processed_buf,
6746 (u_longlong_t)days_left, (u_longlong_t)hours_left,
6747 (u_longlong_t)mins_left, (u_longlong_t)secs_left,
6748 (u_longlong_t)ps->pss_errors, ctime(&end));
6751 } else if (ps->pss_state == DSS_CANCELED) {
6752 if (ps->pss_func == POOL_SCAN_SCRUB) {
6753 (void) printf(gettext("scrub canceled on %s"),
6755 } else if (ps->pss_func == POOL_SCAN_RESILVER) {
6756 (void) printf(gettext("resilver canceled on %s"),
6762 assert(ps->pss_state == DSS_SCANNING);
6764 /* Scan is in progress. Resilvers can't be paused. */
6765 if (ps->pss_func == POOL_SCAN_SCRUB) {
6767 (void) printf(gettext("scrub in progress since %s"),
6770 (void) printf(gettext("scrub paused since %s"),
6772 (void) printf(gettext("\tscrub started on %s"),
6775 } else if (ps->pss_func == POOL_SCAN_RESILVER) {
6776 (void) printf(gettext("resilver in progress since %s"),
6780 scanned = ps->pss_examined;
6781 pass_scanned = ps->pss_pass_exam;
6782 issued = ps->pss_issued;
6783 pass_issued = ps->pss_pass_issued;
6784 total = ps->pss_to_examine;
6786 /* we are only done with a block once we have issued the IO for it */
6787 fraction_done = (double)issued / total;
6789 /* elapsed time for this pass, rounding up to 1 if it's 0 */
6790 elapsed = time(NULL) - ps->pss_pass_start;
6791 elapsed -= ps->pss_pass_scrub_spent_paused;
6792 elapsed = (elapsed != 0) ? elapsed : 1;
6794 scan_rate = pass_scanned / elapsed;
6795 issue_rate = pass_issued / elapsed;
6796 total_secs_left = (issue_rate != 0) ?
6797 ((total - issued) / issue_rate) : UINT64_MAX;
6799 days_left = total_secs_left / 60 / 60 / 24;
6800 hours_left = (total_secs_left / 60 / 60) % 24;
6801 mins_left = (total_secs_left / 60) % 60;
6802 secs_left = (total_secs_left % 60);
6804 /* format all of the numbers we will be reporting */
6805 zfs_nicebytes(scanned, scanned_buf, sizeof (scanned_buf));
6806 zfs_nicebytes(issued, issued_buf, sizeof (issued_buf));
6807 zfs_nicebytes(total, total_buf, sizeof (total_buf));
6808 zfs_nicebytes(scan_rate, srate_buf, sizeof (srate_buf));
6809 zfs_nicebytes(issue_rate, irate_buf, sizeof (irate_buf));
6811 /* do not print estimated time if we have a paused scrub */
6813 (void) printf(gettext("\t%s scanned at %s/s, "
6814 "%s issued at %s/s, %s total\n"),
6815 scanned_buf, srate_buf, issued_buf, irate_buf, total_buf);
6817 (void) printf(gettext("\t%s scanned, %s issued, %s total\n"),
6818 scanned_buf, issued_buf, total_buf);
6821 if (ps->pss_func == POOL_SCAN_RESILVER) {
6822 (void) printf(gettext("\t%s resilvered, %.2f%% done"),
6823 processed_buf, 100 * fraction_done);
6824 } else if (ps->pss_func == POOL_SCAN_SCRUB) {
6825 (void) printf(gettext("\t%s repaired, %.2f%% done"),
6826 processed_buf, 100 * fraction_done);
6830 if (issue_rate >= 10 * 1024 * 1024) {
6831 (void) printf(gettext(", %llu days "
6832 "%02llu:%02llu:%02llu to go\n"),
6833 (u_longlong_t)days_left, (u_longlong_t)hours_left,
6834 (u_longlong_t)mins_left, (u_longlong_t)secs_left);
6836 (void) printf(gettext(", no estimated "
6837 "completion time\n"));
6840 (void) printf(gettext("\n"));
6845 * As we don't scrub checkpointed blocks, we want to warn the
6846 * user that we skipped scanning some blocks if a checkpoint exists
6847 * or existed at any time during the scan.
6850 print_checkpoint_scan_warning(pool_scan_stat_t *ps, pool_checkpoint_stat_t *pcs)
6852 if (ps == NULL || pcs == NULL)
6855 if (pcs->pcs_state == CS_NONE ||
6856 pcs->pcs_state == CS_CHECKPOINT_DISCARDING)
6859 assert(pcs->pcs_state == CS_CHECKPOINT_EXISTS);
6861 if (ps->pss_state == DSS_NONE)
6864 if ((ps->pss_state == DSS_FINISHED || ps->pss_state == DSS_CANCELED) &&
6865 ps->pss_end_time < pcs->pcs_start_time)
6868 if (ps->pss_state == DSS_FINISHED || ps->pss_state == DSS_CANCELED) {
6869 (void) printf(gettext(" scan warning: skipped blocks "
6870 "that are only referenced by the checkpoint.\n"));
6872 assert(ps->pss_state == DSS_SCANNING);
6873 (void) printf(gettext(" scan warning: skipping blocks "
6874 "that are only referenced by the checkpoint.\n"));
6879 * Print out detailed removal status.
6882 print_removal_status(zpool_handle_t *zhp, pool_removal_stat_t *prs)
6884 char copied_buf[7], examined_buf[7], total_buf[7], rate_buf[7];
6886 nvlist_t *config, *nvroot;
6891 if (prs == NULL || prs->prs_state == DSS_NONE)
6895 * Determine name of vdev.
6897 config = zpool_get_config(zhp, NULL);
6898 nvroot = fnvlist_lookup_nvlist(config,
6899 ZPOOL_CONFIG_VDEV_TREE);
6900 verify(nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN,
6901 &child, &children) == 0);
6902 assert(prs->prs_removing_vdev < children);
6903 vdev_name = zpool_vdev_name(g_zfs, zhp,
6904 child[prs->prs_removing_vdev], B_TRUE);
6906 (void) printf(gettext("remove: "));
6908 start = prs->prs_start_time;
6909 end = prs->prs_end_time;
6910 zfs_nicenum(prs->prs_copied, copied_buf, sizeof (copied_buf));
6913 * Removal is finished or canceled.
6915 if (prs->prs_state == DSS_FINISHED) {
6916 uint64_t minutes_taken = (end - start) / 60;
6918 (void) printf(gettext("Removal of vdev %llu copied %s "
6919 "in %lluh%um, completed on %s"),
6920 (longlong_t)prs->prs_removing_vdev,
6922 (u_longlong_t)(minutes_taken / 60),
6923 (uint_t)(minutes_taken % 60),
6924 ctime((time_t *)&end));
6925 } else if (prs->prs_state == DSS_CANCELED) {
6926 (void) printf(gettext("Removal of %s canceled on %s"),
6927 vdev_name, ctime(&end));
6929 uint64_t copied, total, elapsed, mins_left, hours_left;
6930 double fraction_done;
6933 assert(prs->prs_state == DSS_SCANNING);
6936 * Removal is in progress.
6938 (void) printf(gettext(
6939 "Evacuation of %s in progress since %s"),
6940 vdev_name, ctime(&start));
6942 copied = prs->prs_copied > 0 ? prs->prs_copied : 1;
6943 total = prs->prs_to_copy;
6944 fraction_done = (double)copied / total;
6946 /* elapsed time for this pass */
6947 elapsed = time(NULL) - prs->prs_start_time;
6948 elapsed = elapsed > 0 ? elapsed : 1;
6949 rate = copied / elapsed;
6950 rate = rate > 0 ? rate : 1;
6951 mins_left = ((total - copied) / rate) / 60;
6952 hours_left = mins_left / 60;
6954 zfs_nicenum(copied, examined_buf, sizeof (examined_buf));
6955 zfs_nicenum(total, total_buf, sizeof (total_buf));
6956 zfs_nicenum(rate, rate_buf, sizeof (rate_buf));
6959 * do not print estimated time if hours_left is more than
6962 (void) printf(gettext(" %s copied out of %s at %s/s, "
6964 examined_buf, total_buf, rate_buf, 100 * fraction_done);
6965 if (hours_left < (30 * 24)) {
6966 (void) printf(gettext(", %lluh%um to go\n"),
6967 (u_longlong_t)hours_left, (uint_t)(mins_left % 60));
6969 (void) printf(gettext(
6970 ", (copy is slow, no estimated time)\n"));
6974 if (prs->prs_mapping_memory > 0) {
6976 zfs_nicenum(prs->prs_mapping_memory, mem_buf, sizeof (mem_buf));
6977 (void) printf(gettext(" %s memory used for "
6978 "removed device mappings\n"),
6984 print_checkpoint_status(pool_checkpoint_stat_t *pcs)
6989 if (pcs == NULL || pcs->pcs_state == CS_NONE)
6992 (void) printf(gettext("checkpoint: "));
6994 start = pcs->pcs_start_time;
6995 zfs_nicenum(pcs->pcs_space, space_buf, sizeof (space_buf));
6997 if (pcs->pcs_state == CS_CHECKPOINT_EXISTS) {
6998 char *date = ctime(&start);
7001 * ctime() adds a newline at the end of the generated
7002 * string, thus the weird format specifier and the
7003 * strlen() call used to chop it off from the output.
7005 (void) printf(gettext("created %.*s, consumes %s\n"),
7006 (int)(strlen(date) - 1), date, space_buf);
7010 assert(pcs->pcs_state == CS_CHECKPOINT_DISCARDING);
7012 (void) printf(gettext("discarding, %s remaining.\n"),
7017 print_error_log(zpool_handle_t *zhp)
7019 nvlist_t *nverrlist = NULL;
7022 size_t len = MAXPATHLEN * 2;
7024 if (zpool_get_errlog(zhp, &nverrlist) != 0)
7027 (void) printf("errors: Permanent errors have been "
7028 "detected in the following files:\n\n");
7030 pathname = safe_malloc(len);
7032 while ((elem = nvlist_next_nvpair(nverrlist, elem)) != NULL) {
7034 uint64_t dsobj, obj;
7036 verify(nvpair_value_nvlist(elem, &nv) == 0);
7037 verify(nvlist_lookup_uint64(nv, ZPOOL_ERR_DATASET,
7039 verify(nvlist_lookup_uint64(nv, ZPOOL_ERR_OBJECT,
7041 zpool_obj_to_path(zhp, dsobj, obj, pathname, len);
7042 (void) printf("%7s %s\n", "", pathname);
7045 nvlist_free(nverrlist);
7049 print_spares(zpool_handle_t *zhp, status_cbdata_t *cb, nvlist_t **spares,
7058 (void) printf(gettext("\tspares\n"));
7060 for (i = 0; i < nspares; i++) {
7061 name = zpool_vdev_name(g_zfs, zhp, spares[i],
7063 print_status_config(zhp, cb, name, spares[i], 2, B_TRUE);
7069 print_l2cache(zpool_handle_t *zhp, status_cbdata_t *cb, nvlist_t **l2cache,
7078 (void) printf(gettext("\tcache\n"));
7080 for (i = 0; i < nl2cache; i++) {
7081 name = zpool_vdev_name(g_zfs, zhp, l2cache[i],
7083 print_status_config(zhp, cb, name, l2cache[i], 2, B_FALSE);
7089 print_dedup_stats(nvlist_t *config)
7091 ddt_histogram_t *ddh;
7095 char dspace[6], mspace[6];
7098 * If the pool was faulted then we may not have been able to
7099 * obtain the config. Otherwise, if we have anything in the dedup
7100 * table continue processing the stats.
7102 if (nvlist_lookup_uint64_array(config, ZPOOL_CONFIG_DDT_OBJ_STATS,
7103 (uint64_t **)&ddo, &c) != 0)
7106 (void) printf("\n");
7107 (void) printf(gettext(" dedup: "));
7108 if (ddo->ddo_count == 0) {
7109 (void) printf(gettext("no DDT entries\n"));
7113 zfs_nicebytes(ddo->ddo_dspace, dspace, sizeof (dspace));
7114 zfs_nicebytes(ddo->ddo_mspace, mspace, sizeof (mspace));
7115 (void) printf("DDT entries %llu, size %s on disk, %s in core\n",
7116 (u_longlong_t)ddo->ddo_count,
7120 verify(nvlist_lookup_uint64_array(config, ZPOOL_CONFIG_DDT_STATS,
7121 (uint64_t **)&dds, &c) == 0);
7122 verify(nvlist_lookup_uint64_array(config, ZPOOL_CONFIG_DDT_HISTOGRAM,
7123 (uint64_t **)&ddh, &c) == 0);
7124 zpool_dump_ddt(dds, ddh);
7128 * Display a summary of pool status. Displays a summary such as:
7132 * reason: One or more devices ...
7133 * see: http://zfsonlinux.org/msg/ZFS-xxxx-01
7139 * When given the '-v' option, we print out the complete config. If the '-e'
7140 * option is specified, then we print out error rate information as well.
7143 status_callback(zpool_handle_t *zhp, void *data)
7145 status_cbdata_t *cbp = data;
7146 nvlist_t *config, *nvroot;
7148 zpool_status_t reason;
7149 zpool_errata_t errata;
7154 config = zpool_get_config(zhp, NULL);
7155 reason = zpool_get_status(zhp, &msgid, &errata);
7160 * If we were given 'zpool status -x', only report those pools with
7163 if (cbp->cb_explain &&
7164 (reason == ZPOOL_STATUS_OK ||
7165 reason == ZPOOL_STATUS_VERSION_OLDER ||
7166 reason == ZPOOL_STATUS_FEAT_DISABLED)) {
7167 if (!cbp->cb_allpools) {
7168 (void) printf(gettext("pool '%s' is healthy\n"),
7169 zpool_get_name(zhp));
7171 cbp->cb_first = B_FALSE;
7177 cbp->cb_first = B_FALSE;
7179 (void) printf("\n");
7181 nvroot = fnvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE);
7182 verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_VDEV_STATS,
7183 (uint64_t **)&vs, &c) == 0);
7185 health = zpool_get_state_str(zhp);
7187 (void) printf(gettext(" pool: %s\n"), zpool_get_name(zhp));
7188 (void) printf(gettext(" state: %s\n"), health);
7191 case ZPOOL_STATUS_MISSING_DEV_R:
7192 (void) printf(gettext("status: One or more devices could not "
7193 "be opened. Sufficient replicas exist for\n\tthe pool to "
7194 "continue functioning in a degraded state.\n"));
7195 (void) printf(gettext("action: Attach the missing device and "
7196 "online it using 'zpool online'.\n"));
7199 case ZPOOL_STATUS_MISSING_DEV_NR:
7200 (void) printf(gettext("status: One or more devices could not "
7201 "be opened. There are insufficient\n\treplicas for the "
7202 "pool to continue functioning.\n"));
7203 (void) printf(gettext("action: Attach the missing device and "
7204 "online it using 'zpool online'.\n"));
7207 case ZPOOL_STATUS_CORRUPT_LABEL_R:
7208 (void) printf(gettext("status: One or more devices could not "
7209 "be used because the label is missing or\n\tinvalid. "
7210 "Sufficient replicas exist for the pool to continue\n\t"
7211 "functioning in a degraded state.\n"));
7212 (void) printf(gettext("action: Replace the device using "
7213 "'zpool replace'.\n"));
7216 case ZPOOL_STATUS_CORRUPT_LABEL_NR:
7217 (void) printf(gettext("status: One or more devices could not "
7218 "be used because the label is missing \n\tor invalid. "
7219 "There are insufficient replicas for the pool to "
7220 "continue\n\tfunctioning.\n"));
7221 zpool_explain_recover(zpool_get_handle(zhp),
7222 zpool_get_name(zhp), reason, config);
7225 case ZPOOL_STATUS_FAILING_DEV:
7226 (void) printf(gettext("status: One or more devices has "
7227 "experienced an unrecoverable error. An\n\tattempt was "
7228 "made to correct the error. Applications are "
7230 (void) printf(gettext("action: Determine if the device needs "
7231 "to be replaced, and clear the errors\n\tusing "
7232 "'zpool clear' or replace the device with 'zpool "
7236 case ZPOOL_STATUS_OFFLINE_DEV:
7237 (void) printf(gettext("status: One or more devices has "
7238 "been taken offline by the administrator.\n\tSufficient "
7239 "replicas exist for the pool to continue functioning in "
7240 "a\n\tdegraded state.\n"));
7241 (void) printf(gettext("action: Online the device using "
7242 "'zpool online' or replace the device with\n\t'zpool "
7246 case ZPOOL_STATUS_REMOVED_DEV:
7247 (void) printf(gettext("status: One or more devices has "
7248 "been removed by the administrator.\n\tSufficient "
7249 "replicas exist for the pool to continue functioning in "
7250 "a\n\tdegraded state.\n"));
7251 (void) printf(gettext("action: Online the device using "
7252 "'zpool online' or replace the device with\n\t'zpool "
7256 case ZPOOL_STATUS_RESILVERING:
7257 (void) printf(gettext("status: One or more devices is "
7258 "currently being resilvered. The pool will\n\tcontinue "
7259 "to function, possibly in a degraded state.\n"));
7260 (void) printf(gettext("action: Wait for the resilver to "
7264 case ZPOOL_STATUS_CORRUPT_DATA:
7265 (void) printf(gettext("status: One or more devices has "
7266 "experienced an error resulting in data\n\tcorruption. "
7267 "Applications may be affected.\n"));
7268 (void) printf(gettext("action: Restore the file in question "
7269 "if possible. Otherwise restore the\n\tentire pool from "
7273 case ZPOOL_STATUS_CORRUPT_POOL:
7274 (void) printf(gettext("status: The pool metadata is corrupted "
7275 "and the pool cannot be opened.\n"));
7276 zpool_explain_recover(zpool_get_handle(zhp),
7277 zpool_get_name(zhp), reason, config);
7280 case ZPOOL_STATUS_VERSION_OLDER:
7281 (void) printf(gettext("status: The pool is formatted using a "
7282 "legacy on-disk format. The pool can\n\tstill be used, "
7283 "but some features are unavailable.\n"));
7284 (void) printf(gettext("action: Upgrade the pool using 'zpool "
7285 "upgrade'. Once this is done, the\n\tpool will no longer "
7286 "be accessible on software that does not support\n\t"
7287 "feature flags.\n"));
7290 case ZPOOL_STATUS_VERSION_NEWER:
7291 (void) printf(gettext("status: The pool has been upgraded to a "
7292 "newer, incompatible on-disk version.\n\tThe pool cannot "
7293 "be accessed on this system.\n"));
7294 (void) printf(gettext("action: Access the pool from a system "
7295 "running more recent software, or\n\trestore the pool from "
7299 case ZPOOL_STATUS_FEAT_DISABLED:
7300 (void) printf(gettext("status: Some supported features are not "
7301 "enabled on the pool. The pool can\n\tstill be used, but "
7302 "some features are unavailable.\n"));
7303 (void) printf(gettext("action: Enable all features using "
7304 "'zpool upgrade'. Once this is done,\n\tthe pool may no "
7305 "longer be accessible by software that does not support\n\t"
7306 "the features. See zpool-features(5) for details.\n"));
7309 case ZPOOL_STATUS_UNSUP_FEAT_READ:
7310 (void) printf(gettext("status: The pool cannot be accessed on "
7311 "this system because it uses the\n\tfollowing feature(s) "
7312 "not supported on this system:\n"));
7313 zpool_print_unsup_feat(config);
7314 (void) printf("\n");
7315 (void) printf(gettext("action: Access the pool from a system "
7316 "that supports the required feature(s),\n\tor restore the "
7317 "pool from backup.\n"));
7320 case ZPOOL_STATUS_UNSUP_FEAT_WRITE:
7321 (void) printf(gettext("status: The pool can only be accessed "
7322 "in read-only mode on this system. It\n\tcannot be "
7323 "accessed in read-write mode because it uses the "
7324 "following\n\tfeature(s) not supported on this system:\n"));
7325 zpool_print_unsup_feat(config);
7326 (void) printf("\n");
7327 (void) printf(gettext("action: The pool cannot be accessed in "
7328 "read-write mode. Import the pool with\n"
7329 "\t\"-o readonly=on\", access the pool from a system that "
7330 "supports the\n\trequired feature(s), or restore the "
7331 "pool from backup.\n"));
7334 case ZPOOL_STATUS_FAULTED_DEV_R:
7335 (void) printf(gettext("status: One or more devices are "
7336 "faulted in response to persistent errors.\n\tSufficient "
7337 "replicas exist for the pool to continue functioning "
7338 "in a\n\tdegraded state.\n"));
7339 (void) printf(gettext("action: Replace the faulted device, "
7340 "or use 'zpool clear' to mark the device\n\trepaired.\n"));
7343 case ZPOOL_STATUS_FAULTED_DEV_NR:
7344 (void) printf(gettext("status: One or more devices are "
7345 "faulted in response to persistent errors. There are "
7346 "insufficient replicas for the pool to\n\tcontinue "
7348 (void) printf(gettext("action: Destroy and re-create the pool "
7349 "from a backup source. Manually marking the device\n"
7350 "\trepaired using 'zpool clear' may allow some data "
7351 "to be recovered.\n"));
7354 case ZPOOL_STATUS_IO_FAILURE_MMP:
7355 (void) printf(gettext("status: The pool is suspended because "
7356 "multihost writes failed or were delayed;\n\tanother "
7357 "system could import the pool undetected.\n"));
7358 (void) printf(gettext("action: Make sure the pool's devices "
7359 "are connected, then reboot your system and\n\timport the "
7363 case ZPOOL_STATUS_IO_FAILURE_WAIT:
7364 case ZPOOL_STATUS_IO_FAILURE_CONTINUE:
7365 (void) printf(gettext("status: One or more devices are "
7366 "faulted in response to IO failures.\n"));
7367 (void) printf(gettext("action: Make sure the affected devices "
7368 "are connected, then run 'zpool clear'.\n"));
7371 case ZPOOL_STATUS_BAD_LOG:
7372 (void) printf(gettext("status: An intent log record "
7373 "could not be read.\n"
7374 "\tWaiting for administrator intervention to fix the "
7375 "faulted pool.\n"));
7376 (void) printf(gettext("action: Either restore the affected "
7377 "device(s) and run 'zpool online',\n"
7378 "\tor ignore the intent log records by running "
7379 "'zpool clear'.\n"));
7382 case ZPOOL_STATUS_HOSTID_MISMATCH:
7383 (void) printf(gettext("status: Mismatch between pool hostid "
7384 "and system hostid on imported pool.\n\tThis pool was "
7385 "previously imported into a system with a different "
7386 "hostid,\n\tand then was verbatim imported into this "
7388 (void) printf(gettext("action: Export this pool on all systems "
7389 "on which it is imported.\n"
7390 "\tThen import it to correct the mismatch.\n"));
7393 case ZPOOL_STATUS_ERRATA:
7394 (void) printf(gettext("status: Errata #%d detected.\n"),
7398 case ZPOOL_ERRATA_NONE:
7401 case ZPOOL_ERRATA_ZOL_2094_SCRUB:
7402 (void) printf(gettext("action: To correct the issue "
7403 "run 'zpool scrub'.\n"));
7406 case ZPOOL_ERRATA_ZOL_6845_ENCRYPTION:
7407 (void) printf(gettext("\tExisting encrypted datasets "
7408 "contain an on-disk incompatibility\n\twhich "
7409 "needs to be corrected.\n"));
7410 (void) printf(gettext("action: To correct the issue "
7411 "backup existing encrypted datasets to new\n\t"
7412 "encrypted datasets and destroy the old ones. "
7413 "'zfs mount -o ro' can\n\tbe used to temporarily "
7414 "mount existing encrypted datasets readonly.\n"));
7417 case ZPOOL_ERRATA_ZOL_8308_ENCRYPTION:
7418 (void) printf(gettext("\tExisting encrypted datasets "
7419 "contain an on-disk incompatibility\n\twhich "
7420 "needs to be corrected.\n"));
7421 (void) printf(gettext("action: To correct the issue "
7422 "enable the bookmark_v2 feature, backup\n\tany "
7423 "existing encrypted datasets to new encrypted "
7424 "datasets,\n\tand destroy the old ones. If this "
7425 "pool does not contain any\n\tencrypted "
7426 "datasets, simply enable the bookmark_v2 "
7432 * All errata which allow the pool to be imported
7433 * must contain an action message.
7441 * The remaining errors can't actually be generated, yet.
7443 assert(reason == ZPOOL_STATUS_OK);
7447 (void) printf(gettext(" see: http://zfsonlinux.org/msg/%s\n"),
7450 if (config != NULL) {
7452 nvlist_t **spares, **l2cache;
7453 uint_t nspares, nl2cache;
7454 pool_checkpoint_stat_t *pcs = NULL;
7455 pool_scan_stat_t *ps = NULL;
7456 pool_removal_stat_t *prs = NULL;
7458 (void) nvlist_lookup_uint64_array(nvroot,
7459 ZPOOL_CONFIG_CHECKPOINT_STATS, (uint64_t **)&pcs, &c);
7460 (void) nvlist_lookup_uint64_array(nvroot,
7461 ZPOOL_CONFIG_SCAN_STATS, (uint64_t **)&ps, &c);
7462 (void) nvlist_lookup_uint64_array(nvroot,
7463 ZPOOL_CONFIG_REMOVAL_STATS, (uint64_t **)&prs, &c);
7465 print_scan_status(ps);
7466 print_checkpoint_scan_warning(ps, pcs);
7467 print_removal_status(zhp, prs);
7468 print_checkpoint_status(pcs);
7470 cbp->cb_namewidth = max_width(zhp, nvroot, 0, 0,
7471 cbp->cb_name_flags | VDEV_NAME_TYPE_ID);
7472 if (cbp->cb_namewidth < 10)
7473 cbp->cb_namewidth = 10;
7475 (void) printf(gettext("config:\n\n"));
7476 (void) printf(gettext("\t%-*s %-8s %5s %5s %5s"),
7477 cbp->cb_namewidth, "NAME", "STATE", "READ", "WRITE",
7480 if (cbp->cb_print_slow_ios)
7481 (void) printf(" %5s", gettext("SLOW"));
7483 if (cbp->vcdl != NULL)
7484 print_cmd_columns(cbp->vcdl, 0);
7488 print_status_config(zhp, cbp, zpool_get_name(zhp), nvroot, 0,
7491 print_class_vdevs(zhp, cbp, nvroot, VDEV_ALLOC_BIAS_DEDUP);
7492 print_class_vdevs(zhp, cbp, nvroot, VDEV_ALLOC_BIAS_SPECIAL);
7493 print_class_vdevs(zhp, cbp, nvroot, VDEV_ALLOC_CLASS_LOGS);
7495 if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE,
7496 &l2cache, &nl2cache) == 0)
7497 print_l2cache(zhp, cbp, l2cache, nl2cache);
7499 if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
7500 &spares, &nspares) == 0)
7501 print_spares(zhp, cbp, spares, nspares);
7503 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_ERRCOUNT,
7505 nvlist_t *nverrlist = NULL;
7508 * If the approximate error count is small, get a
7509 * precise count by fetching the entire log and
7510 * uniquifying the results.
7512 if (nerr > 0 && nerr < 100 && !cbp->cb_verbose &&
7513 zpool_get_errlog(zhp, &nverrlist) == 0) {
7518 while ((elem = nvlist_next_nvpair(nverrlist,
7523 nvlist_free(nverrlist);
7525 (void) printf("\n");
7528 (void) printf(gettext("errors: No known data "
7530 else if (!cbp->cb_verbose)
7531 (void) printf(gettext("errors: %llu data "
7532 "errors, use '-v' for a list\n"),
7533 (u_longlong_t)nerr);
7535 print_error_log(zhp);
7538 if (cbp->cb_dedup_stats)
7539 print_dedup_stats(config);
7541 (void) printf(gettext("config: The configuration cannot be "
7549 * zpool status [-c [script1,script2,...]] [-igLpPsvx] [-T d|u] [pool] ...
7550 * [interval [count]]
7552 * -c CMD For each vdev, run command CMD
7553 * -i Display vdev initialization status.
7554 * -g Display guid for individual vdev name.
7555 * -L Follow links when resolving vdev path name.
7556 * -p Display values in parsable (exact) format.
7557 * -P Display full path for vdev name.
7558 * -s Display slow IOs column.
7559 * -v Display complete error logs
7560 * -x Display only pools with potential problems
7561 * -D Display dedup status (undocumented)
7562 * -T Display a timestamp in date(1) or Unix format
7564 * Describes the health status of all pools or some subset.
7567 zpool_do_status(int argc, char **argv)
7572 unsigned long count = 0;
7573 status_cbdata_t cb = { 0 };
7577 while ((c = getopt(argc, argv, "c:igLpPsvxDT:")) != -1) {
7582 gettext("Can't set -c flag twice\n"));
7586 if (getenv("ZPOOL_SCRIPTS_ENABLED") != NULL &&
7587 !libzfs_envvar_is_set("ZPOOL_SCRIPTS_ENABLED")) {
7588 fprintf(stderr, gettext(
7589 "Can't run -c, disabled by "
7590 "ZPOOL_SCRIPTS_ENABLED.\n"));
7594 if ((getuid() <= 0 || geteuid() <= 0) &&
7595 !libzfs_envvar_is_set("ZPOOL_SCRIPTS_AS_ROOT")) {
7596 fprintf(stderr, gettext(
7597 "Can't run -c with root privileges "
7598 "unless ZPOOL_SCRIPTS_AS_ROOT is set.\n"));
7604 cb.cb_print_vdev_init = B_TRUE;
7607 cb.cb_name_flags |= VDEV_NAME_GUID;
7610 cb.cb_name_flags |= VDEV_NAME_FOLLOW_LINKS;
7613 cb.cb_literal = B_TRUE;
7616 cb.cb_name_flags |= VDEV_NAME_PATH;
7619 cb.cb_print_slow_ios = B_TRUE;
7622 cb.cb_verbose = B_TRUE;
7625 cb.cb_explain = B_TRUE;
7628 cb.cb_dedup_stats = B_TRUE;
7631 get_timestamp_arg(*optarg);
7634 if (optopt == 'c') {
7635 print_zpool_script_list("status");
7639 gettext("invalid option '%c'\n"), optopt);
7648 get_interval_count(&argc, argv, &interval, &count);
7651 cb.cb_allpools = B_TRUE;
7653 cb.cb_first = B_TRUE;
7654 cb.cb_print_status = B_TRUE;
7657 if (timestamp_fmt != NODATE)
7658 print_timestamp(timestamp_fmt);
7661 cb.vcdl = all_pools_for_each_vdev_run(argc, argv, cmd,
7664 ret = for_each_pool(argc, argv, B_TRUE, NULL,
7665 status_callback, &cb);
7667 if (cb.vcdl != NULL)
7668 free_vdev_cmd_data_list(cb.vcdl);
7670 if (argc == 0 && cb.cb_count == 0)
7671 (void) fprintf(stderr, gettext("no pools available\n"));
7672 else if (cb.cb_explain && cb.cb_first && cb.cb_allpools)
7673 (void) printf(gettext("all pools are healthy\n"));
7681 if (count != 0 && --count == 0)
7684 (void) fsleep(interval);
7690 typedef struct upgrade_cbdata {
7693 uint64_t cb_version;
7698 check_unsupp_fs(zfs_handle_t *zhp, void *unsupp_fs)
7700 int zfs_version = (int)zfs_prop_get_int(zhp, ZFS_PROP_VERSION);
7701 int *count = (int *)unsupp_fs;
7703 if (zfs_version > ZPL_VERSION) {
7704 (void) printf(gettext("%s (v%d) is not supported by this "
7705 "implementation of ZFS.\n"),
7706 zfs_get_name(zhp), zfs_version);
7710 zfs_iter_filesystems(zhp, check_unsupp_fs, unsupp_fs);
7718 upgrade_version(zpool_handle_t *zhp, uint64_t version)
7722 uint64_t oldversion;
7725 config = zpool_get_config(zhp, NULL);
7726 verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
7729 assert(SPA_VERSION_IS_SUPPORTED(oldversion));
7730 assert(oldversion < version);
7732 ret = zfs_iter_root(zpool_get_handle(zhp), check_unsupp_fs, &unsupp_fs);
7737 (void) fprintf(stderr, gettext("Upgrade not performed due "
7738 "to %d unsupported filesystems (max v%d).\n"),
7739 unsupp_fs, (int)ZPL_VERSION);
7743 ret = zpool_upgrade(zhp, version);
7747 if (version >= SPA_VERSION_FEATURES) {
7748 (void) printf(gettext("Successfully upgraded "
7749 "'%s' from version %llu to feature flags.\n"),
7750 zpool_get_name(zhp), (u_longlong_t)oldversion);
7752 (void) printf(gettext("Successfully upgraded "
7753 "'%s' from version %llu to version %llu.\n"),
7754 zpool_get_name(zhp), (u_longlong_t)oldversion,
7755 (u_longlong_t)version);
7762 upgrade_enable_all(zpool_handle_t *zhp, int *countp)
7765 boolean_t firstff = B_TRUE;
7766 nvlist_t *enabled = zpool_get_features(zhp);
7769 for (i = 0; i < SPA_FEATURES; i++) {
7770 const char *fname = spa_feature_table[i].fi_uname;
7771 const char *fguid = spa_feature_table[i].fi_guid;
7772 if (!nvlist_exists(enabled, fguid)) {
7774 verify(-1 != asprintf(&propname, "feature@%s", fname));
7775 ret = zpool_set_prop(zhp, propname,
7776 ZFS_FEATURE_ENABLED);
7784 (void) printf(gettext("Enabled the "
7785 "following features on '%s':\n"),
7786 zpool_get_name(zhp));
7789 (void) printf(gettext(" %s\n"), fname);
7800 upgrade_cb(zpool_handle_t *zhp, void *arg)
7802 upgrade_cbdata_t *cbp = arg;
7805 boolean_t printnl = B_FALSE;
7808 config = zpool_get_config(zhp, NULL);
7809 verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
7812 assert(SPA_VERSION_IS_SUPPORTED(version));
7814 if (version < cbp->cb_version) {
7815 cbp->cb_first = B_FALSE;
7816 ret = upgrade_version(zhp, cbp->cb_version);
7822 * If they did "zpool upgrade -a", then we could
7823 * be doing ioctls to different pools. We need
7824 * to log this history once to each pool, and bypass
7825 * the normal history logging that happens in main().
7827 (void) zpool_log_history(g_zfs, history_str);
7828 log_history = B_FALSE;
7831 if (cbp->cb_version >= SPA_VERSION_FEATURES) {
7833 ret = upgrade_enable_all(zhp, &count);
7838 cbp->cb_first = B_FALSE;
7844 (void) printf(gettext("\n"));
7851 upgrade_list_older_cb(zpool_handle_t *zhp, void *arg)
7853 upgrade_cbdata_t *cbp = arg;
7857 config = zpool_get_config(zhp, NULL);
7858 verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
7861 assert(SPA_VERSION_IS_SUPPORTED(version));
7863 if (version < SPA_VERSION_FEATURES) {
7864 if (cbp->cb_first) {
7865 (void) printf(gettext("The following pools are "
7866 "formatted with legacy version numbers and can\n"
7867 "be upgraded to use feature flags. After "
7868 "being upgraded, these pools\nwill no "
7869 "longer be accessible by software that does not "
7870 "support feature\nflags.\n\n"));
7871 (void) printf(gettext("VER POOL\n"));
7872 (void) printf(gettext("--- ------------\n"));
7873 cbp->cb_first = B_FALSE;
7876 (void) printf("%2llu %s\n", (u_longlong_t)version,
7877 zpool_get_name(zhp));
7884 upgrade_list_disabled_cb(zpool_handle_t *zhp, void *arg)
7886 upgrade_cbdata_t *cbp = arg;
7890 config = zpool_get_config(zhp, NULL);
7891 verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
7894 if (version >= SPA_VERSION_FEATURES) {
7896 boolean_t poolfirst = B_TRUE;
7897 nvlist_t *enabled = zpool_get_features(zhp);
7899 for (i = 0; i < SPA_FEATURES; i++) {
7900 const char *fguid = spa_feature_table[i].fi_guid;
7901 const char *fname = spa_feature_table[i].fi_uname;
7902 if (!nvlist_exists(enabled, fguid)) {
7903 if (cbp->cb_first) {
7904 (void) printf(gettext("\nSome "
7905 "supported features are not "
7906 "enabled on the following pools. "
7907 "Once a\nfeature is enabled the "
7908 "pool may become incompatible with "
7909 "software\nthat does not support "
7911 "zpool-features(5) for "
7913 (void) printf(gettext("POOL "
7915 (void) printf(gettext("------"
7917 cbp->cb_first = B_FALSE;
7921 (void) printf(gettext("%s\n"),
7922 zpool_get_name(zhp));
7923 poolfirst = B_FALSE;
7926 (void) printf(gettext(" %s\n"), fname);
7929 * If they did "zpool upgrade -a", then we could
7930 * be doing ioctls to different pools. We need
7931 * to log this history once to each pool, and bypass
7932 * the normal history logging that happens in main().
7934 (void) zpool_log_history(g_zfs, history_str);
7935 log_history = B_FALSE;
7944 upgrade_one(zpool_handle_t *zhp, void *data)
7946 boolean_t printnl = B_FALSE;
7947 upgrade_cbdata_t *cbp = data;
7948 uint64_t cur_version;
7951 if (strcmp("log", zpool_get_name(zhp)) == 0) {
7952 (void) fprintf(stderr, gettext("'log' is now a reserved word\n"
7953 "Pool 'log' must be renamed using export and import"
7958 cur_version = zpool_get_prop_int(zhp, ZPOOL_PROP_VERSION, NULL);
7959 if (cur_version > cbp->cb_version) {
7960 (void) printf(gettext("Pool '%s' is already formatted "
7961 "using more current version '%llu'.\n\n"),
7962 zpool_get_name(zhp), (u_longlong_t)cur_version);
7966 if (cbp->cb_version != SPA_VERSION && cur_version == cbp->cb_version) {
7967 (void) printf(gettext("Pool '%s' is already formatted "
7968 "using version %llu.\n\n"), zpool_get_name(zhp),
7969 (u_longlong_t)cbp->cb_version);
7973 if (cur_version != cbp->cb_version) {
7975 ret = upgrade_version(zhp, cbp->cb_version);
7980 if (cbp->cb_version >= SPA_VERSION_FEATURES) {
7982 ret = upgrade_enable_all(zhp, &count);
7988 } else if (cur_version == SPA_VERSION) {
7989 (void) printf(gettext("Pool '%s' already has all "
7990 "supported features enabled.\n"),
7991 zpool_get_name(zhp));
7996 (void) printf(gettext("\n"));
8005 * zpool upgrade [-V version] <-a | pool ...>
8007 * With no arguments, display downrev'd ZFS pool available for upgrade.
8008 * Individual pools can be upgraded by specifying the pool, and '-a' will
8009 * upgrade all pools.
8012 zpool_do_upgrade(int argc, char **argv)
8015 upgrade_cbdata_t cb = { 0 };
8017 boolean_t showversions = B_FALSE;
8018 boolean_t upgradeall = B_FALSE;
8023 while ((c = getopt(argc, argv, ":avV:")) != -1) {
8026 upgradeall = B_TRUE;
8029 showversions = B_TRUE;
8032 cb.cb_version = strtoll(optarg, &end, 10);
8034 !SPA_VERSION_IS_SUPPORTED(cb.cb_version)) {
8035 (void) fprintf(stderr,
8036 gettext("invalid version '%s'\n"), optarg);
8041 (void) fprintf(stderr, gettext("missing argument for "
8042 "'%c' option\n"), optopt);
8046 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
8057 if (cb.cb_version == 0) {
8058 cb.cb_version = SPA_VERSION;
8059 } else if (!upgradeall && argc == 0) {
8060 (void) fprintf(stderr, gettext("-V option is "
8061 "incompatible with other arguments\n"));
8066 if (upgradeall || argc != 0) {
8067 (void) fprintf(stderr, gettext("-v option is "
8068 "incompatible with other arguments\n"));
8071 } else if (upgradeall) {
8073 (void) fprintf(stderr, gettext("-a option should not "
8074 "be used along with a pool name\n"));
8079 (void) printf(gettext("This system supports ZFS pool feature "
8084 (void) printf(gettext("The following features are "
8086 (void) printf(gettext("FEAT DESCRIPTION\n"));
8087 (void) printf("----------------------------------------------"
8088 "---------------\n");
8089 for (i = 0; i < SPA_FEATURES; i++) {
8090 zfeature_info_t *fi = &spa_feature_table[i];
8092 (fi->fi_flags & ZFEATURE_FLAG_READONLY_COMPAT) ?
8093 " (read-only compatible)" : "";
8095 (void) printf("%-37s%s\n", fi->fi_uname, ro);
8096 (void) printf(" %s\n", fi->fi_desc);
8098 (void) printf("\n");
8100 (void) printf(gettext("The following legacy versions are also "
8102 (void) printf(gettext("VER DESCRIPTION\n"));
8103 (void) printf("--- -----------------------------------------"
8104 "---------------\n");
8105 (void) printf(gettext(" 1 Initial ZFS version\n"));
8106 (void) printf(gettext(" 2 Ditto blocks "
8107 "(replicated metadata)\n"));
8108 (void) printf(gettext(" 3 Hot spares and double parity "
8110 (void) printf(gettext(" 4 zpool history\n"));
8111 (void) printf(gettext(" 5 Compression using the gzip "
8113 (void) printf(gettext(" 6 bootfs pool property\n"));
8114 (void) printf(gettext(" 7 Separate intent log devices\n"));
8115 (void) printf(gettext(" 8 Delegated administration\n"));
8116 (void) printf(gettext(" 9 refquota and refreservation "
8118 (void) printf(gettext(" 10 Cache devices\n"));
8119 (void) printf(gettext(" 11 Improved scrub performance\n"));
8120 (void) printf(gettext(" 12 Snapshot properties\n"));
8121 (void) printf(gettext(" 13 snapused property\n"));
8122 (void) printf(gettext(" 14 passthrough-x aclinherit\n"));
8123 (void) printf(gettext(" 15 user/group space accounting\n"));
8124 (void) printf(gettext(" 16 stmf property support\n"));
8125 (void) printf(gettext(" 17 Triple-parity RAID-Z\n"));
8126 (void) printf(gettext(" 18 Snapshot user holds\n"));
8127 (void) printf(gettext(" 19 Log device removal\n"));
8128 (void) printf(gettext(" 20 Compression using zle "
8129 "(zero-length encoding)\n"));
8130 (void) printf(gettext(" 21 Deduplication\n"));
8131 (void) printf(gettext(" 22 Received properties\n"));
8132 (void) printf(gettext(" 23 Slim ZIL\n"));
8133 (void) printf(gettext(" 24 System attributes\n"));
8134 (void) printf(gettext(" 25 Improved scrub stats\n"));
8135 (void) printf(gettext(" 26 Improved snapshot deletion "
8137 (void) printf(gettext(" 27 Improved snapshot creation "
8139 (void) printf(gettext(" 28 Multiple vdev replacements\n"));
8140 (void) printf(gettext("\nFor more information on a particular "
8141 "version, including supported releases,\n"));
8142 (void) printf(gettext("see the ZFS Administration Guide.\n\n"));
8143 } else if (argc == 0 && upgradeall) {
8144 cb.cb_first = B_TRUE;
8145 ret = zpool_iter(g_zfs, upgrade_cb, &cb);
8146 if (ret == 0 && cb.cb_first) {
8147 if (cb.cb_version == SPA_VERSION) {
8148 (void) printf(gettext("All pools are already "
8149 "formatted using feature flags.\n\n"));
8150 (void) printf(gettext("Every feature flags "
8151 "pool already has all supported features "
8154 (void) printf(gettext("All pools are already "
8155 "formatted with version %llu or higher.\n"),
8156 (u_longlong_t)cb.cb_version);
8159 } else if (argc == 0) {
8160 cb.cb_first = B_TRUE;
8161 ret = zpool_iter(g_zfs, upgrade_list_older_cb, &cb);
8165 (void) printf(gettext("All pools are formatted "
8166 "using feature flags.\n\n"));
8168 (void) printf(gettext("\nUse 'zpool upgrade -v' "
8169 "for a list of available legacy versions.\n"));
8172 cb.cb_first = B_TRUE;
8173 ret = zpool_iter(g_zfs, upgrade_list_disabled_cb, &cb);
8177 (void) printf(gettext("Every feature flags pool has "
8178 "all supported features enabled.\n"));
8180 (void) printf(gettext("\n"));
8183 ret = for_each_pool(argc, argv, B_FALSE, NULL,
8190 typedef struct hist_cbdata {
8197 * Print out the command history for a specific pool.
8200 get_history_one(zpool_handle_t *zhp, void *data)
8206 hist_cbdata_t *cb = (hist_cbdata_t *)data;
8208 cb->first = B_FALSE;
8210 (void) printf(gettext("History for '%s':\n"), zpool_get_name(zhp));
8212 if ((ret = zpool_get_history(zhp, &nvhis)) != 0)
8215 verify(nvlist_lookup_nvlist_array(nvhis, ZPOOL_HIST_RECORD,
8216 &records, &numrecords) == 0);
8217 for (i = 0; i < numrecords; i++) {
8218 nvlist_t *rec = records[i];
8221 if (nvlist_exists(rec, ZPOOL_HIST_TIME)) {
8225 tsec = fnvlist_lookup_uint64(records[i],
8227 (void) localtime_r(&tsec, &t);
8228 (void) strftime(tbuf, sizeof (tbuf), "%F.%T", &t);
8231 if (nvlist_exists(rec, ZPOOL_HIST_CMD)) {
8232 (void) printf("%s %s", tbuf,
8233 fnvlist_lookup_string(rec, ZPOOL_HIST_CMD));
8234 } else if (nvlist_exists(rec, ZPOOL_HIST_INT_EVENT)) {
8236 fnvlist_lookup_uint64(rec, ZPOOL_HIST_INT_EVENT);
8239 if (ievent >= ZFS_NUM_LEGACY_HISTORY_EVENTS) {
8240 (void) printf("%s unrecognized record:\n",
8242 dump_nvlist(rec, 4);
8245 (void) printf("%s [internal %s txg:%lld] %s", tbuf,
8246 zfs_history_event_names[ievent],
8247 (longlong_t)fnvlist_lookup_uint64(
8248 rec, ZPOOL_HIST_TXG),
8249 fnvlist_lookup_string(rec, ZPOOL_HIST_INT_STR));
8250 } else if (nvlist_exists(rec, ZPOOL_HIST_INT_NAME)) {
8253 (void) printf("%s [txg:%lld] %s", tbuf,
8254 (longlong_t)fnvlist_lookup_uint64(
8255 rec, ZPOOL_HIST_TXG),
8256 fnvlist_lookup_string(rec, ZPOOL_HIST_INT_NAME));
8257 if (nvlist_exists(rec, ZPOOL_HIST_DSNAME)) {
8258 (void) printf(" %s (%llu)",
8259 fnvlist_lookup_string(rec,
8261 (u_longlong_t)fnvlist_lookup_uint64(rec,
8264 (void) printf(" %s", fnvlist_lookup_string(rec,
8265 ZPOOL_HIST_INT_STR));
8266 } else if (nvlist_exists(rec, ZPOOL_HIST_IOCTL)) {
8269 (void) printf("%s ioctl %s\n", tbuf,
8270 fnvlist_lookup_string(rec, ZPOOL_HIST_IOCTL));
8271 if (nvlist_exists(rec, ZPOOL_HIST_INPUT_NVL)) {
8272 (void) printf(" input:\n");
8273 dump_nvlist(fnvlist_lookup_nvlist(rec,
8274 ZPOOL_HIST_INPUT_NVL), 8);
8276 if (nvlist_exists(rec, ZPOOL_HIST_OUTPUT_NVL)) {
8277 (void) printf(" output:\n");
8278 dump_nvlist(fnvlist_lookup_nvlist(rec,
8279 ZPOOL_HIST_OUTPUT_NVL), 8);
8281 if (nvlist_exists(rec, ZPOOL_HIST_ERRNO)) {
8282 (void) printf(" errno: %lld\n",
8283 (longlong_t)fnvlist_lookup_int64(rec,
8289 (void) printf("%s unrecognized record:\n", tbuf);
8290 dump_nvlist(rec, 4);
8294 (void) printf("\n");
8297 (void) printf(" [");
8298 if (nvlist_exists(rec, ZPOOL_HIST_WHO)) {
8299 uid_t who = fnvlist_lookup_uint64(rec, ZPOOL_HIST_WHO);
8300 struct passwd *pwd = getpwuid(who);
8301 (void) printf("user %d ", (int)who);
8303 (void) printf("(%s) ", pwd->pw_name);
8305 if (nvlist_exists(rec, ZPOOL_HIST_HOST)) {
8306 (void) printf("on %s",
8307 fnvlist_lookup_string(rec, ZPOOL_HIST_HOST));
8309 if (nvlist_exists(rec, ZPOOL_HIST_ZONE)) {
8310 (void) printf(":%s",
8311 fnvlist_lookup_string(rec, ZPOOL_HIST_ZONE));
8315 (void) printf("\n");
8317 (void) printf("\n");
8324 * zpool history <pool>
8326 * Displays the history of commands that modified pools.
8329 zpool_do_history(int argc, char **argv)
8331 hist_cbdata_t cbdata = { 0 };
8335 cbdata.first = B_TRUE;
8337 while ((c = getopt(argc, argv, "li")) != -1) {
8340 cbdata.longfmt = B_TRUE;
8343 cbdata.internal = B_TRUE;
8346 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
8354 ret = for_each_pool(argc, argv, B_FALSE, NULL, get_history_one,
8357 if (argc == 0 && cbdata.first == B_TRUE) {
8358 (void) fprintf(stderr, gettext("no pools available\n"));
8365 typedef struct ev_opts {
8370 char poolname[ZFS_MAX_DATASET_NAME_LEN];
8374 zpool_do_events_short(nvlist_t *nvl, ev_opts_t *opts)
8376 char ctime_str[26], str[32], *ptr;
8380 verify(nvlist_lookup_int64_array(nvl, FM_EREPORT_TIME, &tv, &n) == 0);
8381 memset(str, ' ', 32);
8382 (void) ctime_r((const time_t *)&tv[0], ctime_str);
8383 (void) strncpy(str, ctime_str+4, 6); /* 'Jun 30' */
8384 (void) strncpy(str+7, ctime_str+20, 4); /* '1993' */
8385 (void) strncpy(str+12, ctime_str+11, 8); /* '21:49:08' */
8386 (void) sprintf(str+20, ".%09lld", (longlong_t)tv[1]); /* '.123456789' */
8388 (void) printf(gettext("%s\t"), str);
8390 (void) printf(gettext("%s "), str);
8392 verify(nvlist_lookup_string(nvl, FM_CLASS, &ptr) == 0);
8393 (void) printf(gettext("%s\n"), ptr);
8397 zpool_do_events_nvprint(nvlist_t *nvl, int depth)
8401 for (nvp = nvlist_next_nvpair(nvl, NULL);
8402 nvp != NULL; nvp = nvlist_next_nvpair(nvl, nvp)) {
8404 data_type_t type = nvpair_type(nvp);
8405 const char *name = nvpair_name(nvp);
8415 printf(gettext("%*s%s = "), depth, "", name);
8418 case DATA_TYPE_BOOLEAN:
8419 printf(gettext("%s"), "1");
8422 case DATA_TYPE_BOOLEAN_VALUE:
8423 (void) nvpair_value_boolean_value(nvp, &b);
8424 printf(gettext("%s"), b ? "1" : "0");
8427 case DATA_TYPE_BYTE:
8428 (void) nvpair_value_byte(nvp, &i8);
8429 printf(gettext("0x%x"), i8);
8432 case DATA_TYPE_INT8:
8433 (void) nvpair_value_int8(nvp, (void *)&i8);
8434 printf(gettext("0x%x"), i8);
8437 case DATA_TYPE_UINT8:
8438 (void) nvpair_value_uint8(nvp, &i8);
8439 printf(gettext("0x%x"), i8);
8442 case DATA_TYPE_INT16:
8443 (void) nvpair_value_int16(nvp, (void *)&i16);
8444 printf(gettext("0x%x"), i16);
8447 case DATA_TYPE_UINT16:
8448 (void) nvpair_value_uint16(nvp, &i16);
8449 printf(gettext("0x%x"), i16);
8452 case DATA_TYPE_INT32:
8453 (void) nvpair_value_int32(nvp, (void *)&i32);
8454 printf(gettext("0x%x"), i32);
8457 case DATA_TYPE_UINT32:
8458 (void) nvpair_value_uint32(nvp, &i32);
8459 printf(gettext("0x%x"), i32);
8462 case DATA_TYPE_INT64:
8463 (void) nvpair_value_int64(nvp, (void *)&i64);
8464 printf(gettext("0x%llx"), (u_longlong_t)i64);
8467 case DATA_TYPE_UINT64:
8468 (void) nvpair_value_uint64(nvp, &i64);
8470 * translate vdev state values to readable
8471 * strings to aide zpool events consumers
8474 FM_EREPORT_PAYLOAD_ZFS_VDEV_STATE) == 0 ||
8476 FM_EREPORT_PAYLOAD_ZFS_VDEV_LASTSTATE) == 0) {
8477 printf(gettext("\"%s\" (0x%llx)"),
8478 zpool_state_to_name(i64, VDEV_AUX_NONE),
8481 printf(gettext("0x%llx"), (u_longlong_t)i64);
8485 case DATA_TYPE_HRTIME:
8486 (void) nvpair_value_hrtime(nvp, (void *)&i64);
8487 printf(gettext("0x%llx"), (u_longlong_t)i64);
8490 case DATA_TYPE_STRING:
8491 (void) nvpair_value_string(nvp, &str);
8492 printf(gettext("\"%s\""), str ? str : "<NULL>");
8495 case DATA_TYPE_NVLIST:
8496 printf(gettext("(embedded nvlist)\n"));
8497 (void) nvpair_value_nvlist(nvp, &cnv);
8498 zpool_do_events_nvprint(cnv, depth + 8);
8499 printf(gettext("%*s(end %s)"), depth, "", name);
8502 case DATA_TYPE_NVLIST_ARRAY: {
8506 (void) nvpair_value_nvlist_array(nvp, &val, &nelem);
8507 printf(gettext("(%d embedded nvlists)\n"), nelem);
8508 for (i = 0; i < nelem; i++) {
8509 printf(gettext("%*s%s[%d] = %s\n"),
8510 depth, "", name, i, "(embedded nvlist)");
8511 zpool_do_events_nvprint(val[i], depth + 8);
8512 printf(gettext("%*s(end %s[%i])\n"),
8513 depth, "", name, i);
8515 printf(gettext("%*s(end %s)\n"), depth, "", name);
8519 case DATA_TYPE_INT8_ARRAY: {
8523 (void) nvpair_value_int8_array(nvp, &val, &nelem);
8524 for (i = 0; i < nelem; i++)
8525 printf(gettext("0x%x "), val[i]);
8530 case DATA_TYPE_UINT8_ARRAY: {
8534 (void) nvpair_value_uint8_array(nvp, &val, &nelem);
8535 for (i = 0; i < nelem; i++)
8536 printf(gettext("0x%x "), val[i]);
8541 case DATA_TYPE_INT16_ARRAY: {
8545 (void) nvpair_value_int16_array(nvp, &val, &nelem);
8546 for (i = 0; i < nelem; i++)
8547 printf(gettext("0x%x "), val[i]);
8552 case DATA_TYPE_UINT16_ARRAY: {
8556 (void) nvpair_value_uint16_array(nvp, &val, &nelem);
8557 for (i = 0; i < nelem; i++)
8558 printf(gettext("0x%x "), val[i]);
8563 case DATA_TYPE_INT32_ARRAY: {
8567 (void) nvpair_value_int32_array(nvp, &val, &nelem);
8568 for (i = 0; i < nelem; i++)
8569 printf(gettext("0x%x "), val[i]);
8574 case DATA_TYPE_UINT32_ARRAY: {
8578 (void) nvpair_value_uint32_array(nvp, &val, &nelem);
8579 for (i = 0; i < nelem; i++)
8580 printf(gettext("0x%x "), val[i]);
8585 case DATA_TYPE_INT64_ARRAY: {
8589 (void) nvpair_value_int64_array(nvp, &val, &nelem);
8590 for (i = 0; i < nelem; i++)
8591 printf(gettext("0x%llx "),
8592 (u_longlong_t)val[i]);
8597 case DATA_TYPE_UINT64_ARRAY: {
8601 (void) nvpair_value_uint64_array(nvp, &val, &nelem);
8602 for (i = 0; i < nelem; i++)
8603 printf(gettext("0x%llx "),
8604 (u_longlong_t)val[i]);
8609 case DATA_TYPE_STRING_ARRAY: {
8613 (void) nvpair_value_string_array(nvp, &str, &nelem);
8614 for (i = 0; i < nelem; i++)
8615 printf(gettext("\"%s\" "),
8616 str[i] ? str[i] : "<NULL>");
8621 case DATA_TYPE_BOOLEAN_ARRAY:
8622 case DATA_TYPE_BYTE_ARRAY:
8623 case DATA_TYPE_DOUBLE:
8624 case DATA_TYPE_DONTCARE:
8625 case DATA_TYPE_UNKNOWN:
8626 printf(gettext("<unknown>"));
8630 printf(gettext("\n"));
8635 zpool_do_events_next(ev_opts_t *opts)
8638 int zevent_fd, ret, dropped;
8641 zevent_fd = open(ZFS_DEV, O_RDWR);
8642 VERIFY(zevent_fd >= 0);
8644 if (!opts->scripted)
8645 (void) printf(gettext("%-30s %s\n"), "TIME", "CLASS");
8648 ret = zpool_events_next(g_zfs, &nvl, &dropped,
8649 (opts->follow ? ZEVENT_NONE : ZEVENT_NONBLOCK), zevent_fd);
8650 if (ret || nvl == NULL)
8654 (void) printf(gettext("dropped %d events\n"), dropped);
8656 if (strlen(opts->poolname) > 0 &&
8657 nvlist_lookup_string(nvl, FM_FMRI_ZFS_POOL, &pool) == 0 &&
8658 strcmp(opts->poolname, pool) != 0)
8661 zpool_do_events_short(nvl, opts);
8663 if (opts->verbose) {
8664 zpool_do_events_nvprint(nvl, 8);
8665 printf(gettext("\n"));
8667 (void) fflush(stdout);
8672 VERIFY(0 == close(zevent_fd));
8678 zpool_do_events_clear(ev_opts_t *opts)
8682 ret = zpool_events_clear(g_zfs, &count);
8684 (void) printf(gettext("cleared %d events\n"), count);
8690 * zpool events [-vHf [pool] | -c]
8692 * Displays events logs by ZFS.
8695 zpool_do_events(int argc, char **argv)
8697 ev_opts_t opts = { 0 };
8702 while ((c = getopt(argc, argv, "vHfc")) != -1) {
8717 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
8726 (void) fprintf(stderr, gettext("too many arguments\n"));
8728 } else if (argc == 1) {
8729 (void) strlcpy(opts.poolname, argv[0], sizeof (opts.poolname));
8730 if (!zfs_name_valid(opts.poolname, ZFS_TYPE_POOL)) {
8731 (void) fprintf(stderr,
8732 gettext("invalid pool name '%s'\n"), opts.poolname);
8737 if ((argc == 1 || opts.verbose || opts.scripted || opts.follow) &&
8739 (void) fprintf(stderr,
8740 gettext("invalid options combined with -c\n"));
8745 ret = zpool_do_events_clear(&opts);
8747 ret = zpool_do_events_next(&opts);
8753 get_callback(zpool_handle_t *zhp, void *data)
8755 zprop_get_cbdata_t *cbp = (zprop_get_cbdata_t *)data;
8756 char value[MAXNAMELEN];
8757 zprop_source_t srctype;
8760 for (pl = cbp->cb_proplist; pl != NULL; pl = pl->pl_next) {
8763 * Skip the special fake placeholder. This will also skip
8764 * over the name property when 'all' is specified.
8766 if (pl->pl_prop == ZPOOL_PROP_NAME &&
8767 pl == cbp->cb_proplist)
8770 if (pl->pl_prop == ZPROP_INVAL &&
8771 (zpool_prop_feature(pl->pl_user_prop) ||
8772 zpool_prop_unsupported(pl->pl_user_prop))) {
8773 srctype = ZPROP_SRC_LOCAL;
8775 if (zpool_prop_get_feature(zhp, pl->pl_user_prop,
8776 value, sizeof (value)) == 0) {
8777 zprop_print_one_property(zpool_get_name(zhp),
8778 cbp, pl->pl_user_prop, value, srctype,
8782 if (zpool_get_prop(zhp, pl->pl_prop, value,
8783 sizeof (value), &srctype, cbp->cb_literal) != 0)
8786 zprop_print_one_property(zpool_get_name(zhp), cbp,
8787 zpool_prop_to_name(pl->pl_prop), value, srctype,
8795 * zpool get [-Hp] [-o "all" | field[,...]] <"all" | property[,...]> <pool> ...
8797 * -H Scripted mode. Don't display headers, and separate properties
8799 * -o List of columns to display. Defaults to
8800 * "name,property,value,source".
8801 * -p Display values in parsable (exact) format.
8803 * Get properties of pools in the system. Output space statistics
8804 * for each one as well as other attributes.
8807 zpool_do_get(int argc, char **argv)
8809 zprop_get_cbdata_t cb = { 0 };
8810 zprop_list_t fake_name = { 0 };
8815 cb.cb_first = B_TRUE;
8818 * Set up default columns and sources.
8820 cb.cb_sources = ZPROP_SRC_ALL;
8821 cb.cb_columns[0] = GET_COL_NAME;
8822 cb.cb_columns[1] = GET_COL_PROPERTY;
8823 cb.cb_columns[2] = GET_COL_VALUE;
8824 cb.cb_columns[3] = GET_COL_SOURCE;
8825 cb.cb_type = ZFS_TYPE_POOL;
8828 while ((c = getopt(argc, argv, ":Hpo:")) != -1) {
8831 cb.cb_literal = B_TRUE;
8834 cb.cb_scripted = B_TRUE;
8837 bzero(&cb.cb_columns, sizeof (cb.cb_columns));
8839 while (*optarg != '\0') {
8840 static char *col_subopts[] =
8841 { "name", "property", "value", "source",
8844 if (i == ZFS_GET_NCOLS) {
8845 (void) fprintf(stderr, gettext("too "
8846 "many fields given to -o "
8851 switch (getsubopt(&optarg, col_subopts,
8854 cb.cb_columns[i++] = GET_COL_NAME;
8857 cb.cb_columns[i++] = GET_COL_PROPERTY;
8860 cb.cb_columns[i++] = GET_COL_VALUE;
8863 cb.cb_columns[i++] = GET_COL_SOURCE;
8867 (void) fprintf(stderr,
8868 gettext("\"all\" conflicts "
8869 "with specific fields "
8870 "given to -o option\n"));
8873 cb.cb_columns[0] = GET_COL_NAME;
8874 cb.cb_columns[1] = GET_COL_PROPERTY;
8875 cb.cb_columns[2] = GET_COL_VALUE;
8876 cb.cb_columns[3] = GET_COL_SOURCE;
8880 (void) fprintf(stderr,
8881 gettext("invalid column name "
8888 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
8898 (void) fprintf(stderr, gettext("missing property "
8903 if (zprop_get_list(g_zfs, argv[0], &cb.cb_proplist,
8904 ZFS_TYPE_POOL) != 0)
8910 if (cb.cb_proplist != NULL) {
8911 fake_name.pl_prop = ZPOOL_PROP_NAME;
8912 fake_name.pl_width = strlen(gettext("NAME"));
8913 fake_name.pl_next = cb.cb_proplist;
8914 cb.cb_proplist = &fake_name;
8917 ret = for_each_pool(argc, argv, B_TRUE, &cb.cb_proplist,
8920 if (cb.cb_proplist == &fake_name)
8921 zprop_free_list(fake_name.pl_next);
8923 zprop_free_list(cb.cb_proplist);
8928 typedef struct set_cbdata {
8931 boolean_t cb_any_successful;
8935 set_callback(zpool_handle_t *zhp, void *data)
8938 set_cbdata_t *cb = (set_cbdata_t *)data;
8940 error = zpool_set_prop(zhp, cb->cb_propname, cb->cb_value);
8943 cb->cb_any_successful = B_TRUE;
8949 zpool_do_set(int argc, char **argv)
8951 set_cbdata_t cb = { 0 };
8954 if (argc > 1 && argv[1][0] == '-') {
8955 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
8961 (void) fprintf(stderr, gettext("missing property=value "
8967 (void) fprintf(stderr, gettext("missing pool name\n"));
8972 (void) fprintf(stderr, gettext("too many pool names\n"));
8976 cb.cb_propname = argv[1];
8977 cb.cb_value = strchr(cb.cb_propname, '=');
8978 if (cb.cb_value == NULL) {
8979 (void) fprintf(stderr, gettext("missing value in "
8980 "property=value argument\n"));
8984 *(cb.cb_value) = '\0';
8987 error = for_each_pool(argc - 2, argv + 2, B_TRUE, NULL,
8994 find_command_idx(char *command, int *idx)
8998 for (i = 0; i < NCOMMAND; i++) {
8999 if (command_table[i].name == NULL)
9002 if (strcmp(command, command_table[i].name) == 0) {
9011 main(int argc, char **argv)
9018 (void) setlocale(LC_ALL, "");
9019 (void) textdomain(TEXT_DOMAIN);
9025 * Make sure the user has specified some command.
9028 (void) fprintf(stderr, gettext("missing command\n"));
9037 if ((strcmp(cmdname, "-?") == 0) || strcmp(cmdname, "--help") == 0)
9040 if ((g_zfs = libzfs_init()) == NULL) {
9041 (void) fprintf(stderr, "%s", libzfs_error_init(errno));
9045 libzfs_print_on_error(g_zfs, B_TRUE);
9047 zfs_save_arguments(argc, argv, history_str, sizeof (history_str));
9050 * Many commands modify input strings for string parsing reasons.
9051 * We create a copy to protect the original argv.
9053 newargv = malloc((argc + 1) * sizeof (newargv[0]));
9054 for (i = 0; i < argc; i++)
9055 newargv[i] = strdup(argv[i]);
9056 newargv[argc] = NULL;
9059 * Run the appropriate command.
9061 if (find_command_idx(cmdname, &i) == 0) {
9062 current_command = &command_table[i];
9063 ret = command_table[i].func(argc - 1, newargv + 1);
9064 } else if (strchr(cmdname, '=')) {
9065 verify(find_command_idx("set", &i) == 0);
9066 current_command = &command_table[i];
9067 ret = command_table[i].func(argc, newargv);
9068 } else if (strcmp(cmdname, "freeze") == 0 && argc == 3) {
9070 * 'freeze' is a vile debugging abomination, so we treat
9073 zfs_cmd_t zc = {"\0"};
9075 (void) strlcpy(zc.zc_name, argv[2], sizeof (zc.zc_name));
9076 ret = zfs_ioctl(g_zfs, ZFS_IOC_POOL_FREEZE, &zc);
9078 (void) fprintf(stderr,
9079 gettext("failed to freeze pool: %d\n"), errno);
9085 (void) fprintf(stderr, gettext("unrecognized "
9086 "command '%s'\n"), cmdname);
9091 for (i = 0; i < argc; i++)
9095 if (ret == 0 && log_history)
9096 (void) zpool_log_history(g_zfs, history_str);
9101 * The 'ZFS_ABORT' environment variable causes us to dump core on exit
9102 * for the purposes of running ::findleaks.
9104 if (getenv("ZFS_ABORT") != NULL) {
9105 (void) printf("dumping core by request\n");