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 https://opensource.org/licenses/CDDL-1.0.
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, 2024 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.
33 * Copyright (c) 2019, loli10K <ezomori.nozomu@gmail.com>
34 * Copyright (c) 2021, Colm Buckley <colm@tuatha.org>
35 * Copyright (c) 2021, 2023, Klara Inc.
36 * Copyright [2021] Hewlett Packard Enterprise Development LP
53 #include <thread_pool.h>
60 #include <sys/fs/zfs.h>
62 #include <sys/systeminfo.h>
63 #include <sys/fm/fs/zfs.h>
64 #include <sys/fm/util.h>
65 #include <sys/fm/protocol.h>
66 #include <sys/zfs_ioctl.h>
67 #include <sys/mount.h>
68 #include <sys/sysmacros.h>
75 #include "zpool_util.h"
76 #include "zfs_comutil.h"
77 #include "zfeature_common.h"
78 #include "zfs_valstr.h"
80 #include "statcommon.h"
82 libzfs_handle_t
*g_zfs
;
84 static int mount_tp_nthr
= 512; /* tpool threads for multi-threaded mounting */
86 static int zpool_do_create(int, char **);
87 static int zpool_do_destroy(int, char **);
89 static int zpool_do_add(int, char **);
90 static int zpool_do_remove(int, char **);
91 static int zpool_do_labelclear(int, char **);
93 static int zpool_do_checkpoint(int, char **);
94 static int zpool_do_prefetch(int, char **);
96 static int zpool_do_list(int, char **);
97 static int zpool_do_iostat(int, char **);
98 static int zpool_do_status(int, char **);
100 static int zpool_do_online(int, char **);
101 static int zpool_do_offline(int, char **);
102 static int zpool_do_clear(int, char **);
103 static int zpool_do_reopen(int, char **);
105 static int zpool_do_reguid(int, char **);
107 static int zpool_do_attach(int, char **);
108 static int zpool_do_detach(int, char **);
109 static int zpool_do_replace(int, char **);
110 static int zpool_do_split(int, char **);
112 static int zpool_do_initialize(int, char **);
113 static int zpool_do_scrub(int, char **);
114 static int zpool_do_resilver(int, char **);
115 static int zpool_do_trim(int, char **);
117 static int zpool_do_import(int, char **);
118 static int zpool_do_export(int, char **);
120 static int zpool_do_upgrade(int, char **);
122 static int zpool_do_history(int, char **);
123 static int zpool_do_events(int, char **);
125 static int zpool_do_get(int, char **);
126 static int zpool_do_set(int, char **);
128 static int zpool_do_sync(int, char **);
130 static int zpool_do_version(int, char **);
132 static int zpool_do_wait(int, char **);
134 static int zpool_do_ddt_prune(int, char **);
136 static int zpool_do_help(int argc
, char **argv
);
138 static zpool_compat_status_t
zpool_do_load_compat(
139 const char *, boolean_t
*);
142 ZPOOL_OPTION_POWER
= 1024,
143 ZPOOL_OPTION_ALLOW_INUSE
,
144 ZPOOL_OPTION_ALLOW_REPLICATION_MISMATCH
,
145 ZPOOL_OPTION_ALLOW_ASHIFT_MISMATCH
,
146 ZPOOL_OPTION_POOL_KEY_GUID
,
147 ZPOOL_OPTION_JSON_NUMS_AS_INT
,
148 ZPOOL_OPTION_JSON_FLAT_VDEVS
152 * These libumem hooks provide a reasonable set of defaults for the allocator's
153 * debugging facilities.
158 _umem_debug_init(void)
160 return ("default,verbose"); /* $UMEM_DEBUG setting */
164 _umem_logging_init(void)
166 return ("fail,contents"); /* $UMEM_LOGGING setting */
209 * Flags for stats to display with "zpool iostats"
217 IOS_COUNT
, /* always last element */
220 /* iostat_type entries as bitmasks */
221 #define IOS_DEFAULT_M (1ULL << IOS_DEFAULT)
222 #define IOS_LATENCY_M (1ULL << IOS_LATENCY)
223 #define IOS_QUEUES_M (1ULL << IOS_QUEUES)
224 #define IOS_L_HISTO_M (1ULL << IOS_L_HISTO)
225 #define IOS_RQ_HISTO_M (1ULL << IOS_RQ_HISTO)
227 /* Mask of all the histo bits */
228 #define IOS_ANYHISTO_M (IOS_L_HISTO_M | IOS_RQ_HISTO_M)
231 * Lookup table for iostat flags to nvlist names. Basically a list
232 * of all the nvlists a flag requires. Also specifies the order in
233 * which data gets printed in zpool iostat.
235 static const char *vsx_type_to_nvlist
[IOS_COUNT
][15] = {
237 ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO
,
238 ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO
,
239 ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO
,
240 ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO
,
241 ZPOOL_CONFIG_VDEV_SYNC_R_LAT_HISTO
,
242 ZPOOL_CONFIG_VDEV_SYNC_W_LAT_HISTO
,
243 ZPOOL_CONFIG_VDEV_ASYNC_R_LAT_HISTO
,
244 ZPOOL_CONFIG_VDEV_ASYNC_W_LAT_HISTO
,
245 ZPOOL_CONFIG_VDEV_SCRUB_LAT_HISTO
,
246 ZPOOL_CONFIG_VDEV_TRIM_LAT_HISTO
,
247 ZPOOL_CONFIG_VDEV_REBUILD_LAT_HISTO
,
250 ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO
,
251 ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO
,
252 ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO
,
253 ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO
,
254 ZPOOL_CONFIG_VDEV_TRIM_LAT_HISTO
,
255 ZPOOL_CONFIG_VDEV_REBUILD_LAT_HISTO
,
258 ZPOOL_CONFIG_VDEV_SYNC_R_ACTIVE_QUEUE
,
259 ZPOOL_CONFIG_VDEV_SYNC_W_ACTIVE_QUEUE
,
260 ZPOOL_CONFIG_VDEV_ASYNC_R_ACTIVE_QUEUE
,
261 ZPOOL_CONFIG_VDEV_ASYNC_W_ACTIVE_QUEUE
,
262 ZPOOL_CONFIG_VDEV_SCRUB_ACTIVE_QUEUE
,
263 ZPOOL_CONFIG_VDEV_TRIM_ACTIVE_QUEUE
,
264 ZPOOL_CONFIG_VDEV_REBUILD_ACTIVE_QUEUE
,
267 ZPOOL_CONFIG_VDEV_SYNC_IND_R_HISTO
,
268 ZPOOL_CONFIG_VDEV_SYNC_AGG_R_HISTO
,
269 ZPOOL_CONFIG_VDEV_SYNC_IND_W_HISTO
,
270 ZPOOL_CONFIG_VDEV_SYNC_AGG_W_HISTO
,
271 ZPOOL_CONFIG_VDEV_ASYNC_IND_R_HISTO
,
272 ZPOOL_CONFIG_VDEV_ASYNC_AGG_R_HISTO
,
273 ZPOOL_CONFIG_VDEV_ASYNC_IND_W_HISTO
,
274 ZPOOL_CONFIG_VDEV_ASYNC_AGG_W_HISTO
,
275 ZPOOL_CONFIG_VDEV_IND_SCRUB_HISTO
,
276 ZPOOL_CONFIG_VDEV_AGG_SCRUB_HISTO
,
277 ZPOOL_CONFIG_VDEV_IND_TRIM_HISTO
,
278 ZPOOL_CONFIG_VDEV_AGG_TRIM_HISTO
,
279 ZPOOL_CONFIG_VDEV_IND_REBUILD_HISTO
,
280 ZPOOL_CONFIG_VDEV_AGG_REBUILD_HISTO
,
284 static const char *pool_scan_func_str
[] = {
291 static const char *pool_scan_state_str
[] = {
299 static const char *vdev_rebuild_state_str
[] = {
306 static const char *checkpoint_state_str
[] = {
312 static const char *vdev_state_str
[] = {
323 static const char *vdev_aux_str
[] = {
347 static const char *vdev_init_state_str
[] = {
355 static const char *vdev_trim_state_str
[] = {
363 #define ZFS_NICE_TIMESTAMP 100
366 * Given a cb->cb_flags with a histogram bit set, return the iostat_type.
367 * Right now, only one histo bit is ever set at one time, so we can
368 * just do a highbit64(a)
370 #define IOS_HISTO_IDX(a) (highbit64(a & IOS_ANYHISTO_M) - 1)
372 typedef struct zpool_command
{
374 int (*func
)(int, char **);
379 * Master command table. Each ZFS command has a name, associated function, and
380 * usage message. The usage messages need to be internationalized, so we have
381 * to have a function to return the usage message based on a command index.
383 * These commands are organized according to how they are displayed in the usage
384 * message. An empty command (one with a NULL name) indicates an empty line in
385 * the generic usage message.
387 static zpool_command_t command_table
[] = {
388 { "version", zpool_do_version
, HELP_VERSION
},
390 { "create", zpool_do_create
, HELP_CREATE
},
391 { "destroy", zpool_do_destroy
, HELP_DESTROY
},
393 { "add", zpool_do_add
, HELP_ADD
},
394 { "remove", zpool_do_remove
, HELP_REMOVE
},
396 { "labelclear", zpool_do_labelclear
, HELP_LABELCLEAR
},
398 { "checkpoint", zpool_do_checkpoint
, HELP_CHECKPOINT
},
399 { "prefetch", zpool_do_prefetch
, HELP_PREFETCH
},
401 { "list", zpool_do_list
, HELP_LIST
},
402 { "iostat", zpool_do_iostat
, HELP_IOSTAT
},
403 { "status", zpool_do_status
, HELP_STATUS
},
405 { "online", zpool_do_online
, HELP_ONLINE
},
406 { "offline", zpool_do_offline
, HELP_OFFLINE
},
407 { "clear", zpool_do_clear
, HELP_CLEAR
},
408 { "reopen", zpool_do_reopen
, HELP_REOPEN
},
410 { "attach", zpool_do_attach
, HELP_ATTACH
},
411 { "detach", zpool_do_detach
, HELP_DETACH
},
412 { "replace", zpool_do_replace
, HELP_REPLACE
},
413 { "split", zpool_do_split
, HELP_SPLIT
},
415 { "initialize", zpool_do_initialize
, HELP_INITIALIZE
},
416 { "resilver", zpool_do_resilver
, HELP_RESILVER
},
417 { "scrub", zpool_do_scrub
, HELP_SCRUB
},
418 { "trim", zpool_do_trim
, HELP_TRIM
},
420 { "import", zpool_do_import
, HELP_IMPORT
},
421 { "export", zpool_do_export
, HELP_EXPORT
},
422 { "upgrade", zpool_do_upgrade
, HELP_UPGRADE
},
423 { "reguid", zpool_do_reguid
, HELP_REGUID
},
425 { "history", zpool_do_history
, HELP_HISTORY
},
426 { "events", zpool_do_events
, HELP_EVENTS
},
428 { "get", zpool_do_get
, HELP_GET
},
429 { "set", zpool_do_set
, HELP_SET
},
430 { "sync", zpool_do_sync
, HELP_SYNC
},
432 { "wait", zpool_do_wait
, HELP_WAIT
},
434 { "ddtprune", zpool_do_ddt_prune
, HELP_DDT_PRUNE
},
437 #define NCOMMAND (ARRAY_SIZE(command_table))
439 #define VDEV_ALLOC_CLASS_LOGS "logs"
441 #define MAX_CMD_LEN 256
443 static zpool_command_t
*current_command
;
444 static zfs_type_t current_prop_type
= (ZFS_TYPE_POOL
| ZFS_TYPE_VDEV
);
445 static char history_str
[HIS_MAX_RECORD_LEN
];
446 static boolean_t log_history
= B_TRUE
;
447 static uint_t timestamp_fmt
= NODATE
;
450 get_usage(zpool_help_t idx
)
454 return (gettext("\tadd [-afgLnP] [-o property=value] "
455 "<pool> <vdev> ...\n"));
457 return (gettext("\tattach [-fsw] [-o property=value] "
458 "<pool> <device> <new-device>\n"));
460 return (gettext("\tclear [[--power]|[-nF]] <pool> [device]\n"));
462 return (gettext("\tcreate [-fnd] [-o property=value] ... \n"
463 "\t [-O file-system-property=value] ... \n"
464 "\t [-m mountpoint] [-R root] <pool> <vdev> ...\n"));
465 case HELP_CHECKPOINT
:
466 return (gettext("\tcheckpoint [-d [-w]] <pool> ...\n"));
468 return (gettext("\tdestroy [-f] <pool>\n"));
470 return (gettext("\tdetach <pool> <device>\n"));
472 return (gettext("\texport [-af] <pool> ...\n"));
474 return (gettext("\thistory [-il] [<pool>] ...\n"));
476 return (gettext("\timport [-d dir] [-D]\n"
477 "\timport [-o mntopts] [-o property=value] ... \n"
478 "\t [-d dir | -c cachefile] [-D] [-l] [-f] [-m] [-N] "
479 "[-R root] [-F [-n]] -a\n"
480 "\timport [-o mntopts] [-o property=value] ... \n"
481 "\t [-d dir | -c cachefile] [-D] [-l] [-f] [-m] [-N] "
482 "[-R root] [-F [-n]]\n"
483 "\t [--rewind-to-checkpoint] <pool | id> [newpool]\n"));
485 return (gettext("\tiostat [[[-c [script1,script2,...]"
486 "[-lq]]|[-rw]] [-T d | u] [-ghHLpPvy]\n"
487 "\t [[pool ...]|[pool vdev ...]|[vdev ...]]"
488 " [[-n] interval [count]]\n"));
489 case HELP_LABELCLEAR
:
490 return (gettext("\tlabelclear [-f] <vdev>\n"));
492 return (gettext("\tlist [-gHLpPv] [-o property[,...]] [-j "
493 "[--json-int, --json-pool-key-guid]] ...\n"
494 "\t [-T d|u] [pool] [interval [count]]\n"));
496 return (gettext("\tprefetch -t <type> [<type opts>] <pool>\n"
497 "\t -t ddt <pool>\n"));
499 return (gettext("\toffline [--power]|[[-f][-t]] <pool> "
502 return (gettext("\tonline [--power][-e] <pool> <device> "
505 return (gettext("\treplace [-fsw] [-o property=value] "
506 "<pool> <device> [new-device]\n"));
508 return (gettext("\tremove [-npsw] <pool> <device> ...\n"));
510 return (gettext("\treopen [-n] <pool>\n"));
511 case HELP_INITIALIZE
:
512 return (gettext("\tinitialize [-c | -s | -u] [-w] <pool> "
513 "[<device> ...]\n"));
515 return (gettext("\tscrub [-e | -s | -p | -C] [-w] "
518 return (gettext("\tresilver <pool> ...\n"));
520 return (gettext("\ttrim [-dw] [-r <rate>] [-c | -s] <pool> "
521 "[<device> ...]\n"));
523 return (gettext("\tstatus [--power] [-j [--json-int, "
524 "--json-flat-vdevs, ...\n"
525 "\t --json-pool-key-guid]] [-c [script1,script2,...]] "
526 "[-dDegiLpPstvx] ...\n"
527 "\t [-T d|u] [pool] [interval [count]]\n"));
529 return (gettext("\tupgrade\n"
531 "\tupgrade [-V version] <-a | pool ...>\n"));
533 return (gettext("\tevents [-vHf [pool] | -c]\n"));
535 return (gettext("\tget [-Hp] [-j [--json-int, "
536 "--json-pool-key-guid]] ...\n"
537 "\t [-o \"all\" | field[,...]] "
538 "<\"all\" | property[,...]> <pool> ...\n"));
540 return (gettext("\tset <property=value> <pool>\n"
541 "\tset <vdev_property=value> <pool> <vdev>\n"));
543 return (gettext("\tsplit [-gLnPl] [-R altroot] [-o mntopts]\n"
544 "\t [-o property=value] <pool> <newpool> "
545 "[<device> ...]\n"));
547 return (gettext("\treguid [-g guid] <pool>\n"));
549 return (gettext("\tsync [pool] ...\n"));
551 return (gettext("\tversion [-j]\n"));
553 return (gettext("\twait [-Hp] [-T d|u] [-t <activity>[,...]] "
554 "<pool> [interval]\n"));
556 return (gettext("\tddtprune -d|-p <amount> <pool>\n"));
558 __builtin_unreachable();
563 zpool_collect_leaves(zpool_handle_t
*zhp
, nvlist_t
*nvroot
, nvlist_t
*res
)
569 (void) nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_CHILDREN
,
573 char *path
= zpool_vdev_name(g_zfs
, zhp
, nvroot
,
576 if (strcmp(path
, VDEV_TYPE_INDIRECT
) != 0 &&
577 strcmp(path
, VDEV_TYPE_HOLE
) != 0)
578 fnvlist_add_boolean(res
, path
);
584 for (i
= 0; i
< children
; i
++) {
585 zpool_collect_leaves(zhp
, child
[i
], res
);
590 * Callback routine that will print out a pool property value.
593 print_pool_prop_cb(int prop
, void *cb
)
597 (void) fprintf(fp
, "\t%-19s ", zpool_prop_to_name(prop
));
599 if (zpool_prop_readonly(prop
))
600 (void) fprintf(fp
, " NO ");
602 (void) fprintf(fp
, " YES ");
604 if (zpool_prop_values(prop
) == NULL
)
605 (void) fprintf(fp
, "-\n");
607 (void) fprintf(fp
, "%s\n", zpool_prop_values(prop
));
613 * Callback routine that will print out a vdev property value.
616 print_vdev_prop_cb(int prop
, void *cb
)
620 (void) fprintf(fp
, "\t%-19s ", vdev_prop_to_name(prop
));
622 if (vdev_prop_readonly(prop
))
623 (void) fprintf(fp
, " NO ");
625 (void) fprintf(fp
, " YES ");
627 if (vdev_prop_values(prop
) == NULL
)
628 (void) fprintf(fp
, "-\n");
630 (void) fprintf(fp
, "%s\n", vdev_prop_values(prop
));
636 * Given a leaf vdev name like 'L5' return its VDEV_CONFIG_PATH like
637 * '/dev/disk/by-vdev/L5'.
640 vdev_name_to_path(zpool_handle_t
*zhp
, char *vdev
)
642 nvlist_t
*vdev_nv
= zpool_find_vdev(zhp
, vdev
, NULL
, NULL
, NULL
);
643 if (vdev_nv
== NULL
) {
646 return (fnvlist_lookup_string(vdev_nv
, ZPOOL_CONFIG_PATH
));
650 zpool_power_on(zpool_handle_t
*zhp
, char *vdev
)
652 return (zpool_power(zhp
, vdev
, B_TRUE
));
656 zpool_power_on_and_disk_wait(zpool_handle_t
*zhp
, char *vdev
)
660 rc
= zpool_power_on(zhp
, vdev
);
664 zpool_disk_wait(vdev_name_to_path(zhp
, vdev
));
670 zpool_power_on_pool_and_wait_for_devices(zpool_handle_t
*zhp
)
673 const char *path
= NULL
;
676 /* Power up all the devices first */
677 FOR_EACH_REAL_LEAF_VDEV(zhp
, nv
) {
678 path
= fnvlist_lookup_string(nv
, ZPOOL_CONFIG_PATH
);
680 rc
= zpool_power_on(zhp
, (char *)path
);
688 * Wait for their devices to show up. Since we powered them on
689 * at roughly the same time, they should all come online around
692 FOR_EACH_REAL_LEAF_VDEV(zhp
, nv
) {
693 path
= fnvlist_lookup_string(nv
, ZPOOL_CONFIG_PATH
);
694 zpool_disk_wait(path
);
701 zpool_power_off(zpool_handle_t
*zhp
, char *vdev
)
703 return (zpool_power(zhp
, vdev
, B_FALSE
));
707 * Display usage message. If we're inside a command, display only the usage for
708 * that command. Otherwise, iterate over the entire command table and display
709 * a complete usage message.
711 static __attribute__((noreturn
)) void
712 usage(boolean_t requested
)
714 FILE *fp
= requested
? stdout
: stderr
;
716 if (current_command
== NULL
) {
719 (void) fprintf(fp
, gettext("usage: zpool command args ...\n"));
721 gettext("where 'command' is one of the following:\n\n"));
723 for (i
= 0; i
< NCOMMAND
; i
++) {
724 if (command_table
[i
].name
== NULL
)
725 (void) fprintf(fp
, "\n");
727 (void) fprintf(fp
, "%s",
728 get_usage(command_table
[i
].usage
));
732 gettext("\nFor further help on a command or topic, "
733 "run: %s\n"), "zpool help [<topic>]");
735 (void) fprintf(fp
, gettext("usage:\n"));
736 (void) fprintf(fp
, "%s", get_usage(current_command
->usage
));
739 if (current_command
!= NULL
&&
740 current_prop_type
!= (ZFS_TYPE_POOL
| ZFS_TYPE_VDEV
) &&
741 ((strcmp(current_command
->name
, "set") == 0) ||
742 (strcmp(current_command
->name
, "get") == 0) ||
743 (strcmp(current_command
->name
, "list") == 0))) {
745 (void) fprintf(fp
, "%s",
746 gettext("\nthe following properties are supported:\n"));
748 (void) fprintf(fp
, "\n\t%-19s %s %s\n\n",
749 "PROPERTY", "EDIT", "VALUES");
751 /* Iterate over all properties */
752 if (current_prop_type
== ZFS_TYPE_POOL
) {
753 (void) zprop_iter(print_pool_prop_cb
, fp
, B_FALSE
,
754 B_TRUE
, current_prop_type
);
756 (void) fprintf(fp
, "\t%-19s ", "feature@...");
757 (void) fprintf(fp
, "YES "
758 "disabled | enabled | active\n");
760 (void) fprintf(fp
, gettext("\nThe feature@ properties "
761 "must be appended with a feature name.\n"
762 "See zpool-features(7).\n"));
763 } else if (current_prop_type
== ZFS_TYPE_VDEV
) {
764 (void) zprop_iter(print_vdev_prop_cb
, fp
, B_FALSE
,
765 B_TRUE
, current_prop_type
);
770 * See comments at end of main().
772 if (getenv("ZFS_ABORT") != NULL
) {
773 (void) printf("dumping core by request\n");
777 exit(requested
? 0 : 2);
781 * zpool initialize [-c | -s | -u] [-w] <pool> [<vdev> ...]
782 * Initialize all unused blocks in the specified vdevs, or all vdevs in the pool
785 * -c Cancel. Ends active initializing.
786 * -s Suspend. Initializing can then be restarted with no flags.
787 * -u Uninitialize. Clears initialization state.
788 * -w Wait. Blocks until initializing has completed.
791 zpool_do_initialize(int argc
, char **argv
)
798 boolean_t wait
= B_FALSE
;
800 struct option long_options
[] = {
801 {"cancel", no_argument
, NULL
, 'c'},
802 {"suspend", no_argument
, NULL
, 's'},
803 {"uninit", no_argument
, NULL
, 'u'},
804 {"wait", no_argument
, NULL
, 'w'},
808 pool_initialize_func_t cmd_type
= POOL_INITIALIZE_START
;
809 while ((c
= getopt_long(argc
, argv
, "csuw", long_options
,
813 if (cmd_type
!= POOL_INITIALIZE_START
&&
814 cmd_type
!= POOL_INITIALIZE_CANCEL
) {
815 (void) fprintf(stderr
, gettext("-c cannot be "
816 "combined with other options\n"));
819 cmd_type
= POOL_INITIALIZE_CANCEL
;
822 if (cmd_type
!= POOL_INITIALIZE_START
&&
823 cmd_type
!= POOL_INITIALIZE_SUSPEND
) {
824 (void) fprintf(stderr
, gettext("-s cannot be "
825 "combined with other options\n"));
828 cmd_type
= POOL_INITIALIZE_SUSPEND
;
831 if (cmd_type
!= POOL_INITIALIZE_START
&&
832 cmd_type
!= POOL_INITIALIZE_UNINIT
) {
833 (void) fprintf(stderr
, gettext("-u cannot be "
834 "combined with other options\n"));
837 cmd_type
= POOL_INITIALIZE_UNINIT
;
844 (void) fprintf(stderr
,
845 gettext("invalid option '%c'\n"), optopt
);
847 (void) fprintf(stderr
,
848 gettext("invalid option '%s'\n"),
859 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
864 if (wait
&& (cmd_type
!= POOL_INITIALIZE_START
)) {
865 (void) fprintf(stderr
, gettext("-w cannot be used with -c, -s"
871 zhp
= zpool_open(g_zfs
, poolname
);
875 vdevs
= fnvlist_alloc();
877 /* no individual leaf vdevs specified, so add them all */
878 nvlist_t
*config
= zpool_get_config(zhp
, NULL
);
879 nvlist_t
*nvroot
= fnvlist_lookup_nvlist(config
,
880 ZPOOL_CONFIG_VDEV_TREE
);
881 zpool_collect_leaves(zhp
, nvroot
, vdevs
);
883 for (int i
= 1; i
< argc
; i
++) {
884 fnvlist_add_boolean(vdevs
, argv
[i
]);
889 err
= zpool_initialize_wait(zhp
, cmd_type
, vdevs
);
891 err
= zpool_initialize(zhp
, cmd_type
, vdevs
);
900 * print a pool vdev config for dry runs
903 print_vdev_tree(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
, int indent
,
904 const char *match
, int name_flags
)
909 boolean_t printed
= B_FALSE
;
911 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
912 &child
, &children
) != 0) {
914 (void) printf("\t%*s%s\n", indent
, "", name
);
918 for (c
= 0; c
< children
; c
++) {
919 uint64_t is_log
= B_FALSE
, is_hole
= B_FALSE
;
920 const char *class = "";
922 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_HOLE
,
925 if (is_hole
== B_TRUE
) {
929 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
932 class = VDEV_ALLOC_BIAS_LOG
;
933 (void) nvlist_lookup_string(child
[c
],
934 ZPOOL_CONFIG_ALLOCATION_BIAS
, &class);
935 if (strcmp(match
, class) != 0)
938 if (!printed
&& name
!= NULL
) {
939 (void) printf("\t%*s%s\n", indent
, "", name
);
942 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], name_flags
);
943 print_vdev_tree(zhp
, vname
, child
[c
], indent
+ 2, "",
950 * Print the list of l2cache devices for dry runs.
953 print_cache_list(nvlist_t
*nv
, int indent
)
958 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
959 &child
, &children
) == 0 && children
> 0) {
960 (void) printf("\t%*s%s\n", indent
, "", "cache");
964 for (c
= 0; c
< children
; c
++) {
967 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
], 0);
968 (void) printf("\t%*s%s\n", indent
+ 2, "", vname
);
974 * Print the list of spares for dry runs.
977 print_spare_list(nvlist_t
*nv
, int indent
)
982 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
983 &child
, &children
) == 0 && children
> 0) {
984 (void) printf("\t%*s%s\n", indent
, "", "spares");
988 for (c
= 0; c
< children
; c
++) {
991 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
], 0);
992 (void) printf("\t%*s%s\n", indent
+ 2, "", vname
);
997 typedef struct spare_cbdata
{
999 zpool_handle_t
*cb_zhp
;
1003 find_vdev(nvlist_t
*nv
, uint64_t search
)
1009 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
, &guid
) == 0 &&
1013 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1014 &child
, &children
) == 0) {
1015 for (c
= 0; c
< children
; c
++)
1016 if (find_vdev(child
[c
], search
))
1024 find_spare(zpool_handle_t
*zhp
, void *data
)
1026 spare_cbdata_t
*cbp
= data
;
1027 nvlist_t
*config
, *nvroot
;
1029 config
= zpool_get_config(zhp
, NULL
);
1030 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
1033 if (find_vdev(nvroot
, cbp
->cb_guid
)) {
1043 nice_num_str_nvlist(nvlist_t
*item
, const char *key
, uint64_t value
,
1044 boolean_t literal
, boolean_t as_int
, int format
)
1049 snprintf(buf
, 256, "%llu", (u_longlong_t
)value
);
1052 case ZFS_NICENUM_1024
:
1053 zfs_nicenum_format(value
, buf
, 256, ZFS_NICENUM_1024
);
1055 case ZFS_NICENUM_BYTES
:
1056 zfs_nicenum_format(value
, buf
, 256, ZFS_NICENUM_BYTES
);
1058 case ZFS_NICENUM_TIME
:
1059 zfs_nicenum_format(value
, buf
, 256, ZFS_NICENUM_TIME
);
1061 case ZFS_NICE_TIMESTAMP
:
1062 format_timestamp(value
, buf
, 256);
1065 fprintf(stderr
, "Invalid number format");
1070 fnvlist_add_uint64(item
, key
, value
);
1072 fnvlist_add_string(item
, key
, buf
);
1076 * Generates an nvlist with output version for every command based on params.
1077 * Purpose of this is to add a version of JSON output, considering the schema
1078 * format might be updated for each command in future.
1082 * "output_version": {
1083 * "command": string,
1084 * "vers_major": integer,
1085 * "vers_minor": integer,
1089 zpool_json_schema(int maj_v
, int min_v
)
1091 char cmd
[MAX_CMD_LEN
];
1092 nvlist_t
*sch
= fnvlist_alloc();
1093 nvlist_t
*ov
= fnvlist_alloc();
1095 snprintf(cmd
, MAX_CMD_LEN
, "zpool %s", current_command
->name
);
1096 fnvlist_add_string(ov
, "command", cmd
);
1097 fnvlist_add_uint32(ov
, "vers_major", maj_v
);
1098 fnvlist_add_uint32(ov
, "vers_minor", min_v
);
1099 fnvlist_add_nvlist(sch
, "output_version", ov
);
1105 fill_pool_info(nvlist_t
*list
, zpool_handle_t
*zhp
, boolean_t addtype
,
1108 nvlist_t
*config
= zpool_get_config(zhp
, NULL
);
1109 uint64_t guid
= fnvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
);
1110 uint64_t txg
= fnvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_TXG
);
1112 fnvlist_add_string(list
, "name", zpool_get_name(zhp
));
1114 fnvlist_add_string(list
, "type", "POOL");
1115 fnvlist_add_string(list
, "state", zpool_get_state_str(zhp
));
1118 fnvlist_add_uint64(list
, ZPOOL_CONFIG_POOL_GUID
, guid
);
1120 fnvlist_add_uint64(list
, ZPOOL_CONFIG_POOL_TXG
, txg
);
1121 fnvlist_add_uint64(list
, "spa_version", SPA_VERSION
);
1122 fnvlist_add_uint64(list
, "zpl_version", ZPL_VERSION
);
1124 char value
[ZFS_MAXPROPLEN
];
1126 snprintf(value
, ZFS_MAXPROPLEN
, "%llu",
1127 (u_longlong_t
)guid
);
1128 fnvlist_add_string(list
, ZPOOL_CONFIG_POOL_GUID
, value
);
1131 snprintf(value
, ZFS_MAXPROPLEN
, "%llu",
1133 fnvlist_add_string(list
, ZPOOL_CONFIG_POOL_TXG
, value
);
1135 fnvlist_add_string(list
, "spa_version", SPA_VERSION_STRING
);
1136 fnvlist_add_string(list
, "zpl_version", ZPL_VERSION_STRING
);
1141 used_by_other(zpool_handle_t
*zhp
, nvlist_t
*nvdev
, nvlist_t
*list
)
1143 spare_cbdata_t spare_cb
;
1144 verify(nvlist_lookup_uint64(nvdev
, ZPOOL_CONFIG_GUID
,
1145 &spare_cb
.cb_guid
) == 0);
1146 if (zpool_iter(g_zfs
, find_spare
, &spare_cb
) == 1) {
1147 if (strcmp(zpool_get_name(spare_cb
.cb_zhp
),
1148 zpool_get_name(zhp
)) != 0) {
1149 fnvlist_add_string(list
, "used_by",
1150 zpool_get_name(spare_cb
.cb_zhp
));
1152 zpool_close(spare_cb
.cb_zhp
);
1157 fill_vdev_info(nvlist_t
*list
, zpool_handle_t
*zhp
, char *name
,
1158 boolean_t addtype
, boolean_t as_int
)
1160 boolean_t l2c
= B_FALSE
;
1161 const char *path
, *phys
, *devid
, *bias
= NULL
;
1162 uint64_t hole
= 0, log
= 0, spare
= 0;
1166 nvlist_t
*nvdev_parent
= NULL
;
1169 if (strcmp(name
, zpool_get_name(zhp
)) != 0)
1172 _name
= (char *)"root-0";
1174 nvdev
= zpool_find_vdev(zhp
, _name
, NULL
, &l2c
, NULL
);
1176 fnvlist_add_string(list
, "name", name
);
1178 fnvlist_add_string(list
, "type", "VDEV");
1180 const char *type
= fnvlist_lookup_string(nvdev
,
1183 fnvlist_add_string(list
, "vdev_type", type
);
1184 uint64_t guid
= fnvlist_lookup_uint64(nvdev
, ZPOOL_CONFIG_GUID
);
1187 fnvlist_add_uint64(list
, "guid", guid
);
1189 char buf
[ZFS_MAXPROPLEN
];
1190 snprintf(buf
, ZFS_MAXPROPLEN
, "%llu",
1191 (u_longlong_t
)guid
);
1192 fnvlist_add_string(list
, "guid", buf
);
1195 if (nvlist_lookup_string(nvdev
, ZPOOL_CONFIG_PATH
, &path
) == 0)
1196 fnvlist_add_string(list
, "path", path
);
1197 if (nvlist_lookup_string(nvdev
, ZPOOL_CONFIG_PHYS_PATH
,
1199 fnvlist_add_string(list
, "phys_path", phys
);
1200 if (nvlist_lookup_string(nvdev
, ZPOOL_CONFIG_DEVID
,
1202 fnvlist_add_string(list
, "devid", devid
);
1203 (void) nvlist_lookup_uint64(nvdev
, ZPOOL_CONFIG_IS_LOG
, &log
);
1204 (void) nvlist_lookup_uint64(nvdev
, ZPOOL_CONFIG_IS_SPARE
,
1206 (void) nvlist_lookup_uint64(nvdev
, ZPOOL_CONFIG_IS_HOLE
, &hole
);
1208 fnvlist_add_string(list
, "class", VDEV_TYPE_HOLE
);
1210 fnvlist_add_string(list
, "class", VDEV_TYPE_L2CACHE
);
1212 fnvlist_add_string(list
, "class", VDEV_TYPE_SPARE
);
1214 fnvlist_add_string(list
, "class", VDEV_TYPE_LOG
);
1216 (void) nvlist_lookup_string(nvdev
,
1217 ZPOOL_CONFIG_ALLOCATION_BIAS
, &bias
);
1219 fnvlist_add_string(list
, "class", bias
);
1221 nvdev_parent
= NULL
;
1222 nvdev_parent
= zpool_find_parent_vdev(zhp
,
1223 _name
, NULL
, NULL
, NULL
);
1226 * With a mirrored special device, the parent
1227 * "mirror" vdev will have
1228 * ZPOOL_CONFIG_ALLOCATION_BIAS set to "special"
1229 * not the leaf vdevs. If we're a leaf vdev
1230 * in that case we need to look at our parent
1231 * to see if they're "special" to know if we
1232 * are "special" too.
1235 (void) nvlist_lookup_string(
1237 ZPOOL_CONFIG_ALLOCATION_BIAS
,
1241 fnvlist_add_string(list
, "class", bias
);
1243 fnvlist_add_string(list
, "class",
1247 if (nvlist_lookup_uint64_array(nvdev
, ZPOOL_CONFIG_VDEV_STATS
,
1248 (uint64_t **)&vs
, &c
) == 0) {
1249 fnvlist_add_string(list
, "state",
1250 vdev_state_str
[vs
->vs_state
]);
1256 prop_list_contains_feature(nvlist_t
*proplist
)
1259 for (nvp
= nvlist_next_nvpair(proplist
, NULL
); NULL
!= nvp
;
1260 nvp
= nvlist_next_nvpair(proplist
, nvp
)) {
1261 if (zpool_prop_feature(nvpair_name(nvp
)))
1268 * Add a property pair (name, string-value) into a property nvlist.
1271 add_prop_list(const char *propname
, const char *propval
, nvlist_t
**props
,
1274 zpool_prop_t prop
= ZPOOL_PROP_INVAL
;
1279 if (*props
== NULL
&&
1280 nvlist_alloc(props
, NV_UNIQUE_NAME
, 0) != 0) {
1281 (void) fprintf(stderr
,
1282 gettext("internal error: out of memory\n"));
1289 const char *vname
= zpool_prop_to_name(ZPOOL_PROP_VERSION
);
1291 zpool_prop_to_name(ZPOOL_PROP_COMPATIBILITY
);
1293 if ((prop
= zpool_name_to_prop(propname
)) == ZPOOL_PROP_INVAL
&&
1294 (!zpool_prop_feature(propname
) &&
1295 !zpool_prop_vdev(propname
))) {
1296 (void) fprintf(stderr
, gettext("property '%s' is "
1297 "not a valid pool or vdev property\n"), propname
);
1302 * feature@ properties and version should not be specified
1305 if ((prop
== ZPOOL_PROP_INVAL
&& zpool_prop_feature(propname
) &&
1306 nvlist_exists(proplist
, vname
)) ||
1307 (prop
== ZPOOL_PROP_VERSION
&&
1308 prop_list_contains_feature(proplist
))) {
1309 (void) fprintf(stderr
, gettext("'feature@' and "
1310 "'version' properties cannot be specified "
1316 * if version is specified, only "legacy" compatibility
1319 if ((prop
== ZPOOL_PROP_COMPATIBILITY
&&
1320 strcmp(propval
, ZPOOL_COMPAT_LEGACY
) != 0 &&
1321 nvlist_exists(proplist
, vname
)) ||
1322 (prop
== ZPOOL_PROP_VERSION
&&
1323 nvlist_exists(proplist
, cname
) &&
1324 strcmp(fnvlist_lookup_string(proplist
, cname
),
1325 ZPOOL_COMPAT_LEGACY
) != 0)) {
1326 (void) fprintf(stderr
, gettext("when 'version' is "
1327 "specified, the 'compatibility' feature may only "
1328 "be set to '" ZPOOL_COMPAT_LEGACY
"'\n"));
1332 if (zpool_prop_feature(propname
) || zpool_prop_vdev(propname
))
1335 normnm
= zpool_prop_to_name(prop
);
1337 zfs_prop_t fsprop
= zfs_name_to_prop(propname
);
1339 if (zfs_prop_valid_for_type(fsprop
, ZFS_TYPE_FILESYSTEM
,
1341 normnm
= zfs_prop_to_name(fsprop
);
1342 } else if (zfs_prop_user(propname
) ||
1343 zfs_prop_userquota(propname
)) {
1346 (void) fprintf(stderr
, gettext("property '%s' is "
1347 "not a valid filesystem property\n"), propname
);
1352 if (nvlist_lookup_string(proplist
, normnm
, &strval
) == 0 &&
1353 prop
!= ZPOOL_PROP_CACHEFILE
) {
1354 (void) fprintf(stderr
, gettext("property '%s' "
1355 "specified multiple times\n"), propname
);
1359 if (nvlist_add_string(proplist
, normnm
, propval
) != 0) {
1360 (void) fprintf(stderr
, gettext("internal "
1361 "error: out of memory\n"));
1369 * Set a default property pair (name, string-value) in a property nvlist
1372 add_prop_list_default(const char *propname
, const char *propval
,
1377 if (nvlist_lookup_string(*props
, propname
, &pval
) == 0)
1380 return (add_prop_list(propname
, propval
, props
, B_TRUE
));
1384 * zpool add [-afgLnP] [-o property=value] <pool> <vdev> ...
1386 * -a Disable the ashift validation checks
1387 * -f Force addition of devices, even if they appear in use
1388 * -g Display guid for individual vdev name.
1389 * -L Follow links when resolving vdev path name.
1390 * -n Do not add the devices, but display the resulting layout if
1391 * they were to be added.
1392 * -o Set property=value.
1393 * -P Display full path for vdev name.
1395 * Adds the given vdevs to 'pool'. As with create, the bulk of this work is
1396 * handled by make_root_vdev(), which constructs the nvlist needed to pass to
1400 zpool_do_add(int argc
, char **argv
)
1402 boolean_t check_replication
= B_TRUE
;
1403 boolean_t check_inuse
= B_TRUE
;
1404 boolean_t dryrun
= B_FALSE
;
1405 boolean_t check_ashift
= B_TRUE
;
1406 boolean_t force
= B_FALSE
;
1412 zpool_handle_t
*zhp
;
1414 nvlist_t
*props
= NULL
;
1417 struct option long_options
[] = {
1418 {"allow-in-use", no_argument
, NULL
, ZPOOL_OPTION_ALLOW_INUSE
},
1419 {"allow-replication-mismatch", no_argument
, NULL
,
1420 ZPOOL_OPTION_ALLOW_REPLICATION_MISMATCH
},
1421 {"allow-ashift-mismatch", no_argument
, NULL
,
1422 ZPOOL_OPTION_ALLOW_ASHIFT_MISMATCH
},
1427 while ((c
= getopt_long(argc
, argv
, "fgLno:P", long_options
, NULL
))
1434 name_flags
|= VDEV_NAME_GUID
;
1437 name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
1443 if ((propval
= strchr(optarg
, '=')) == NULL
) {
1444 (void) fprintf(stderr
, gettext("missing "
1445 "'=' for -o option\n"));
1451 if ((strcmp(optarg
, ZPOOL_CONFIG_ASHIFT
) != 0) ||
1452 (add_prop_list(optarg
, propval
, &props
, B_TRUE
)))
1456 name_flags
|= VDEV_NAME_PATH
;
1458 case ZPOOL_OPTION_ALLOW_INUSE
:
1459 check_inuse
= B_FALSE
;
1461 case ZPOOL_OPTION_ALLOW_REPLICATION_MISMATCH
:
1462 check_replication
= B_FALSE
;
1464 case ZPOOL_OPTION_ALLOW_ASHIFT_MISMATCH
:
1465 check_ashift
= B_FALSE
;
1468 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1477 /* get pool name and check number of arguments */
1479 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
1483 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
1488 if (!check_inuse
|| !check_replication
|| !check_ashift
) {
1489 (void) fprintf(stderr
, gettext("'-f' option is not "
1490 "allowed with '--allow-replication-mismatch', "
1491 "'--allow-ashift-mismatch', or "
1492 "'--allow-in-use'\n"));
1495 check_inuse
= B_FALSE
;
1496 check_replication
= B_FALSE
;
1497 check_ashift
= B_FALSE
;
1505 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
1508 if ((config
= zpool_get_config(zhp
, NULL
)) == NULL
) {
1509 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
1515 /* unless manually specified use "ashift" pool property (if set) */
1516 if (!nvlist_exists(props
, ZPOOL_CONFIG_ASHIFT
)) {
1519 char strval
[ZPOOL_MAXPROPLEN
];
1521 intval
= zpool_get_prop_int(zhp
, ZPOOL_PROP_ASHIFT
, &src
);
1522 if (src
!= ZPROP_SRC_DEFAULT
) {
1523 (void) sprintf(strval
, "%" PRId32
, intval
);
1524 verify(add_prop_list(ZPOOL_CONFIG_ASHIFT
, strval
,
1525 &props
, B_TRUE
) == 0);
1529 /* pass off to make_root_vdev for processing */
1530 nvroot
= make_root_vdev(zhp
, props
, !check_inuse
,
1531 check_replication
, B_FALSE
, dryrun
, argc
, argv
);
1532 if (nvroot
== NULL
) {
1538 nvlist_t
*poolnvroot
;
1539 nvlist_t
**l2child
, **sparechild
;
1540 uint_t l2children
, sparechildren
, c
;
1542 boolean_t hadcache
= B_FALSE
, hadspare
= B_FALSE
;
1544 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
1547 (void) printf(gettext("would update '%s' to the following "
1548 "configuration:\n\n"), zpool_get_name(zhp
));
1550 /* print original main pool and new tree */
1551 print_vdev_tree(zhp
, poolname
, poolnvroot
, 0, "",
1552 name_flags
| VDEV_NAME_TYPE_ID
);
1553 print_vdev_tree(zhp
, NULL
, nvroot
, 0, "", name_flags
);
1555 /* print other classes: 'dedup', 'special', and 'log' */
1556 if (zfs_special_devs(poolnvroot
, VDEV_ALLOC_BIAS_DEDUP
)) {
1557 print_vdev_tree(zhp
, "dedup", poolnvroot
, 0,
1558 VDEV_ALLOC_BIAS_DEDUP
, name_flags
);
1559 print_vdev_tree(zhp
, NULL
, nvroot
, 0,
1560 VDEV_ALLOC_BIAS_DEDUP
, name_flags
);
1561 } else if (zfs_special_devs(nvroot
, VDEV_ALLOC_BIAS_DEDUP
)) {
1562 print_vdev_tree(zhp
, "dedup", nvroot
, 0,
1563 VDEV_ALLOC_BIAS_DEDUP
, name_flags
);
1566 if (zfs_special_devs(poolnvroot
, VDEV_ALLOC_BIAS_SPECIAL
)) {
1567 print_vdev_tree(zhp
, "special", poolnvroot
, 0,
1568 VDEV_ALLOC_BIAS_SPECIAL
, name_flags
);
1569 print_vdev_tree(zhp
, NULL
, nvroot
, 0,
1570 VDEV_ALLOC_BIAS_SPECIAL
, name_flags
);
1571 } else if (zfs_special_devs(nvroot
, VDEV_ALLOC_BIAS_SPECIAL
)) {
1572 print_vdev_tree(zhp
, "special", nvroot
, 0,
1573 VDEV_ALLOC_BIAS_SPECIAL
, name_flags
);
1576 if (num_logs(poolnvroot
) > 0) {
1577 print_vdev_tree(zhp
, "logs", poolnvroot
, 0,
1578 VDEV_ALLOC_BIAS_LOG
, name_flags
);
1579 print_vdev_tree(zhp
, NULL
, nvroot
, 0,
1580 VDEV_ALLOC_BIAS_LOG
, name_flags
);
1581 } else if (num_logs(nvroot
) > 0) {
1582 print_vdev_tree(zhp
, "logs", nvroot
, 0,
1583 VDEV_ALLOC_BIAS_LOG
, name_flags
);
1586 /* Do the same for the caches */
1587 if (nvlist_lookup_nvlist_array(poolnvroot
, ZPOOL_CONFIG_L2CACHE
,
1588 &l2child
, &l2children
) == 0 && l2children
) {
1590 (void) printf(gettext("\tcache\n"));
1591 for (c
= 0; c
< l2children
; c
++) {
1592 vname
= zpool_vdev_name(g_zfs
, NULL
,
1593 l2child
[c
], name_flags
);
1594 (void) printf("\t %s\n", vname
);
1598 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_L2CACHE
,
1599 &l2child
, &l2children
) == 0 && l2children
) {
1601 (void) printf(gettext("\tcache\n"));
1602 for (c
= 0; c
< l2children
; c
++) {
1603 vname
= zpool_vdev_name(g_zfs
, NULL
,
1604 l2child
[c
], name_flags
);
1605 (void) printf("\t %s\n", vname
);
1609 /* And finally the spares */
1610 if (nvlist_lookup_nvlist_array(poolnvroot
, ZPOOL_CONFIG_SPARES
,
1611 &sparechild
, &sparechildren
) == 0 && sparechildren
> 0) {
1613 (void) printf(gettext("\tspares\n"));
1614 for (c
= 0; c
< sparechildren
; c
++) {
1615 vname
= zpool_vdev_name(g_zfs
, NULL
,
1616 sparechild
[c
], name_flags
);
1617 (void) printf("\t %s\n", vname
);
1621 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_SPARES
,
1622 &sparechild
, &sparechildren
) == 0 && sparechildren
> 0) {
1624 (void) printf(gettext("\tspares\n"));
1625 for (c
= 0; c
< sparechildren
; c
++) {
1626 vname
= zpool_vdev_name(g_zfs
, NULL
,
1627 sparechild
[c
], name_flags
);
1628 (void) printf("\t %s\n", vname
);
1635 ret
= (zpool_add(zhp
, nvroot
, check_ashift
) != 0);
1639 nvlist_free(nvroot
);
1646 * zpool remove [-npsw] <pool> <vdev> ...
1648 * Removes the given vdev from the pool.
1651 zpool_do_remove(int argc
, char **argv
)
1655 zpool_handle_t
*zhp
= NULL
;
1656 boolean_t stop
= B_FALSE
;
1658 boolean_t noop
= B_FALSE
;
1659 boolean_t parsable
= B_FALSE
;
1660 boolean_t wait
= B_FALSE
;
1663 while ((c
= getopt(argc
, argv
, "npsw")) != -1) {
1678 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1687 /* get pool name and check number of arguments */
1689 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
1695 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
1700 (void) fprintf(stderr
, gettext("stop request ignored\n"));
1706 (void) fprintf(stderr
, gettext("too many arguments\n"));
1709 if (zpool_vdev_remove_cancel(zhp
) != 0)
1712 (void) fprintf(stderr
, gettext("invalid option "
1713 "combination: -w cannot be used with -s\n"));
1718 (void) fprintf(stderr
, gettext("missing device\n"));
1722 for (i
= 1; i
< argc
; i
++) {
1726 if (zpool_vdev_indirect_size(zhp
, argv
[i
],
1732 (void) printf("%s %llu\n",
1733 argv
[i
], (unsigned long long)size
);
1736 zfs_nicenum(size
, valstr
,
1738 (void) printf("Memory that will be "
1739 "used after removing %s: %s\n",
1743 if (zpool_vdev_remove(zhp
, argv
[i
]) != 0)
1748 if (ret
== 0 && wait
)
1749 ret
= zpool_wait(zhp
, ZPOOL_WAIT_REMOVE
);
1757 * Return 1 if a vdev is active (being used in a pool)
1758 * Return 0 if a vdev is inactive (offlined or faulted, or not in active pool)
1760 * This is useful for checking if a disk in an active pool is offlined or
1764 vdev_is_active(char *vdev_path
)
1767 fd
= open(vdev_path
, O_EXCL
);
1769 return (1); /* cant open O_EXCL - disk is active */
1773 return (0); /* disk is inactive in the pool */
1777 * zpool labelclear [-f] <vdev>
1779 * -f Force clearing the label for the vdevs which are members of
1780 * the exported or foreign pools.
1782 * Verifies that the vdev is not active and zeros out the label information
1786 zpool_do_labelclear(int argc
, char **argv
)
1788 char vdev
[MAXPATHLEN
];
1790 int c
, fd
= -1, ret
= 0;
1793 boolean_t inuse
= B_FALSE
;
1794 boolean_t force
= B_FALSE
;
1797 while ((c
= getopt(argc
, argv
, "f")) != -1) {
1803 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1814 (void) fprintf(stderr
, gettext("missing vdev name\n"));
1818 (void) fprintf(stderr
, gettext("too many arguments\n"));
1822 (void) strlcpy(vdev
, argv
[0], sizeof (vdev
));
1825 * If we cannot open an absolute path, we quit.
1826 * Otherwise if the provided vdev name doesn't point to a file,
1827 * try prepending expected disk paths and partition numbers.
1829 if ((fd
= open(vdev
, O_RDWR
)) < 0) {
1831 if (vdev
[0] == '/') {
1832 (void) fprintf(stderr
, gettext("failed to open "
1833 "%s: %s\n"), vdev
, strerror(errno
));
1837 error
= zfs_resolve_shortname(argv
[0], vdev
, MAXPATHLEN
);
1838 if (error
== 0 && zfs_dev_is_whole_disk(vdev
)) {
1839 if (zfs_append_partition(vdev
, MAXPATHLEN
) == -1)
1843 if (error
|| ((fd
= open(vdev
, O_RDWR
)) < 0)) {
1844 if (errno
== ENOENT
) {
1845 (void) fprintf(stderr
, gettext(
1846 "failed to find device %s, try "
1847 "specifying absolute path instead\n"),
1852 (void) fprintf(stderr
, gettext("failed to open %s:"
1853 " %s\n"), vdev
, strerror(errno
));
1859 * Flush all dirty pages for the block device. This should not be
1860 * fatal when the device does not support BLKFLSBUF as would be the
1861 * case for a file vdev.
1863 if ((zfs_dev_flush(fd
) != 0) && (errno
!= ENOTTY
))
1864 (void) fprintf(stderr
, gettext("failed to invalidate "
1865 "cache for %s: %s\n"), vdev
, strerror(errno
));
1867 if (zpool_read_label(fd
, &config
, NULL
) != 0) {
1868 (void) fprintf(stderr
,
1869 gettext("failed to read label from %s\n"), vdev
);
1873 nvlist_free(config
);
1875 ret
= zpool_in_use(g_zfs
, fd
, &state
, &name
, &inuse
);
1877 (void) fprintf(stderr
,
1878 gettext("failed to check state for %s\n"), vdev
);
1888 case POOL_STATE_ACTIVE
:
1889 case POOL_STATE_SPARE
:
1890 case POOL_STATE_L2CACHE
:
1892 * We allow the user to call 'zpool offline -f'
1893 * on an offlined disk in an active pool. We can check if
1894 * the disk is online by calling vdev_is_active().
1896 if (force
&& !vdev_is_active(vdev
))
1899 (void) fprintf(stderr
, gettext(
1900 "%s is a member (%s) of pool \"%s\""),
1901 vdev
, zpool_pool_state_to_name(state
), name
);
1904 (void) fprintf(stderr
, gettext(
1905 ". Offline the disk first to clear its label."));
1911 case POOL_STATE_EXPORTED
:
1914 (void) fprintf(stderr
, gettext(
1915 "use '-f' to override the following error:\n"
1916 "%s is a member of exported pool \"%s\"\n"),
1921 case POOL_STATE_POTENTIALLY_ACTIVE
:
1924 (void) fprintf(stderr
, gettext(
1925 "use '-f' to override the following error:\n"
1926 "%s is a member of potentially active pool \"%s\"\n"),
1931 case POOL_STATE_DESTROYED
:
1932 /* inuse should never be set for a destroyed pool */
1938 ret
= zpool_clear_label(fd
);
1940 (void) fprintf(stderr
,
1941 gettext("failed to clear label for %s\n"), vdev
);
1952 * zpool create [-fnd] [-o property=value] ...
1953 * [-O file-system-property=value] ...
1954 * [-R root] [-m mountpoint] <pool> <dev> ...
1956 * -f Force creation, even if devices appear in use
1957 * -n Do not create the pool, but display the resulting layout if it
1958 * were to be created.
1959 * -R Create a pool under an alternate root
1960 * -m Set default mountpoint for the root dataset. By default it's
1962 * -o Set property=value.
1963 * -o Set feature@feature=enabled|disabled.
1964 * -d Don't automatically enable all supported pool features
1965 * (individual features can be enabled with -o).
1966 * -O Set fsproperty=value in the pool's root file system
1968 * Creates the named pool according to the given vdev specification. The
1969 * bulk of the vdev processing is done in make_root_vdev() in zpool_vdev.c.
1970 * Once we get the nvlist back from make_root_vdev(), we either print out the
1971 * contents (if '-n' was specified), or pass it to libzfs to do the creation.
1974 zpool_do_create(int argc
, char **argv
)
1976 boolean_t force
= B_FALSE
;
1977 boolean_t dryrun
= B_FALSE
;
1978 boolean_t enable_pool_features
= B_TRUE
;
1981 nvlist_t
*nvroot
= NULL
;
1985 char *altroot
= NULL
;
1986 char *compat
= NULL
;
1987 char *mountpoint
= NULL
;
1988 nvlist_t
*fsprops
= NULL
;
1989 nvlist_t
*props
= NULL
;
1993 while ((c
= getopt(argc
, argv
, ":fndR:m:o:O:t:")) != -1) {
2002 enable_pool_features
= B_FALSE
;
2006 if (add_prop_list(zpool_prop_to_name(
2007 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
2009 if (add_prop_list_default(zpool_prop_to_name(
2010 ZPOOL_PROP_CACHEFILE
), "none", &props
))
2014 /* Equivalent to -O mountpoint=optarg */
2015 mountpoint
= optarg
;
2018 if ((propval
= strchr(optarg
, '=')) == NULL
) {
2019 (void) fprintf(stderr
, gettext("missing "
2020 "'=' for -o option\n"));
2026 if (add_prop_list(optarg
, propval
, &props
, B_TRUE
))
2030 * If the user is creating a pool that doesn't support
2031 * feature flags, don't enable any features.
2033 if (zpool_name_to_prop(optarg
) == ZPOOL_PROP_VERSION
) {
2037 ver
= strtoull(propval
, &end
, 0);
2039 ver
< SPA_VERSION_FEATURES
) {
2040 enable_pool_features
= B_FALSE
;
2043 if (zpool_name_to_prop(optarg
) == ZPOOL_PROP_ALTROOT
)
2045 if (zpool_name_to_prop(optarg
) ==
2046 ZPOOL_PROP_COMPATIBILITY
)
2050 if ((propval
= strchr(optarg
, '=')) == NULL
) {
2051 (void) fprintf(stderr
, gettext("missing "
2052 "'=' for -O option\n"));
2059 * Mountpoints are checked and then added later.
2060 * Uniquely among properties, they can be specified
2061 * more than once, to avoid conflict with -m.
2063 if (0 == strcmp(optarg
,
2064 zfs_prop_to_name(ZFS_PROP_MOUNTPOINT
))) {
2065 mountpoint
= propval
;
2066 } else if (add_prop_list(optarg
, propval
, &fsprops
,
2073 * Sanity check temporary pool name.
2075 if (strchr(optarg
, '/') != NULL
) {
2076 (void) fprintf(stderr
, gettext("cannot create "
2077 "'%s': invalid character '/' in temporary "
2079 (void) fprintf(stderr
, gettext("use 'zfs "
2080 "create' to create a dataset\n"));
2084 if (add_prop_list(zpool_prop_to_name(
2085 ZPOOL_PROP_TNAME
), optarg
, &props
, B_TRUE
))
2087 if (add_prop_list_default(zpool_prop_to_name(
2088 ZPOOL_PROP_CACHEFILE
), "none", &props
))
2093 (void) fprintf(stderr
, gettext("missing argument for "
2094 "'%c' option\n"), optopt
);
2097 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2106 /* get pool name and check number of arguments */
2108 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
2112 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
2119 * As a special case, check for use of '/' in the name, and direct the
2120 * user to use 'zfs create' instead.
2122 if (strchr(poolname
, '/') != NULL
) {
2123 (void) fprintf(stderr
, gettext("cannot create '%s': invalid "
2124 "character '/' in pool name\n"), poolname
);
2125 (void) fprintf(stderr
, gettext("use 'zfs create' to "
2126 "create a dataset\n"));
2130 /* pass off to make_root_vdev for bulk processing */
2131 nvroot
= make_root_vdev(NULL
, props
, force
, !force
, B_FALSE
, dryrun
,
2132 argc
- 1, argv
+ 1);
2136 /* make_root_vdev() allows 0 toplevel children if there are spares */
2137 if (!zfs_allocatable_devs(nvroot
)) {
2138 (void) fprintf(stderr
, gettext("invalid vdev "
2139 "specification: at least one toplevel vdev must be "
2144 if (altroot
!= NULL
&& altroot
[0] != '/') {
2145 (void) fprintf(stderr
, gettext("invalid alternate root '%s': "
2146 "must be an absolute path\n"), altroot
);
2151 * Check the validity of the mountpoint and direct the user to use the
2152 * '-m' mountpoint option if it looks like its in use.
2154 if (mountpoint
== NULL
||
2155 (strcmp(mountpoint
, ZFS_MOUNTPOINT_LEGACY
) != 0 &&
2156 strcmp(mountpoint
, ZFS_MOUNTPOINT_NONE
) != 0)) {
2157 char buf
[MAXPATHLEN
];
2160 if (mountpoint
&& mountpoint
[0] != '/') {
2161 (void) fprintf(stderr
, gettext("invalid mountpoint "
2162 "'%s': must be an absolute path, 'legacy', or "
2163 "'none'\n"), mountpoint
);
2167 if (mountpoint
== NULL
) {
2168 if (altroot
!= NULL
)
2169 (void) snprintf(buf
, sizeof (buf
), "%s/%s",
2172 (void) snprintf(buf
, sizeof (buf
), "/%s",
2175 if (altroot
!= NULL
)
2176 (void) snprintf(buf
, sizeof (buf
), "%s%s",
2177 altroot
, mountpoint
);
2179 (void) snprintf(buf
, sizeof (buf
), "%s",
2183 if ((dirp
= opendir(buf
)) == NULL
&& errno
!= ENOENT
) {
2184 (void) fprintf(stderr
, gettext("mountpoint '%s' : "
2185 "%s\n"), buf
, strerror(errno
));
2186 (void) fprintf(stderr
, gettext("use '-m' "
2187 "option to provide a different default\n"));
2192 while (count
< 3 && readdir(dirp
) != NULL
)
2194 (void) closedir(dirp
);
2197 (void) fprintf(stderr
, gettext("mountpoint "
2198 "'%s' exists and is not empty\n"), buf
);
2199 (void) fprintf(stderr
, gettext("use '-m' "
2200 "option to provide a "
2201 "different default\n"));
2208 * Now that the mountpoint's validity has been checked, ensure that
2209 * the property is set appropriately prior to creating the pool.
2211 if (mountpoint
!= NULL
) {
2212 ret
= add_prop_list(zfs_prop_to_name(ZFS_PROP_MOUNTPOINT
),
2213 mountpoint
, &fsprops
, B_FALSE
);
2221 * For a dry run invocation, print out a basic message and run
2222 * through all the vdevs in the list and print out in an
2223 * appropriate hierarchy.
2225 (void) printf(gettext("would create '%s' with the "
2226 "following layout:\n\n"), poolname
);
2228 print_vdev_tree(NULL
, poolname
, nvroot
, 0, "", 0);
2229 print_vdev_tree(NULL
, "dedup", nvroot
, 0,
2230 VDEV_ALLOC_BIAS_DEDUP
, 0);
2231 print_vdev_tree(NULL
, "special", nvroot
, 0,
2232 VDEV_ALLOC_BIAS_SPECIAL
, 0);
2233 print_vdev_tree(NULL
, "logs", nvroot
, 0,
2234 VDEV_ALLOC_BIAS_LOG
, 0);
2235 print_cache_list(nvroot
, 0);
2236 print_spare_list(nvroot
, 0);
2241 * Load in feature set.
2242 * Note: if compatibility property not given, we'll have
2243 * NULL, which means 'all features'.
2245 boolean_t requested_features
[SPA_FEATURES
];
2246 if (zpool_do_load_compat(compat
, requested_features
) !=
2247 ZPOOL_COMPATIBILITY_OK
)
2251 * props contains list of features to enable.
2253 * - remove it if feature@name=disabled
2254 * - leave it there if feature@name=enabled
2256 * - enable_pool_features (ie: no '-d' or '-o version')
2257 * - it's supported by the kernel module
2258 * - it's in the requested feature set
2259 * - warn if it's enabled but not in compat
2261 for (spa_feature_t i
= 0; i
< SPA_FEATURES
; i
++) {
2262 char propname
[MAXPATHLEN
];
2263 const char *propval
;
2264 zfeature_info_t
*feat
= &spa_feature_table
[i
];
2266 (void) snprintf(propname
, sizeof (propname
),
2267 "feature@%s", feat
->fi_uname
);
2269 if (!nvlist_lookup_string(props
, propname
, &propval
)) {
2271 ZFS_FEATURE_DISABLED
) == 0) {
2272 (void) nvlist_remove_all(props
,
2274 } else if (strcmp(propval
,
2275 ZFS_FEATURE_ENABLED
) == 0 &&
2276 !requested_features
[i
]) {
2277 (void) fprintf(stderr
, gettext(
2278 "Warning: feature \"%s\" enabled "
2279 "but is not in specified "
2280 "'compatibility' feature set.\n"),
2284 enable_pool_features
&&
2285 feat
->fi_zfs_mod_supported
&&
2286 requested_features
[i
]) {
2287 ret
= add_prop_list(propname
,
2288 ZFS_FEATURE_ENABLED
, &props
, B_TRUE
);
2295 if (zpool_create(g_zfs
, poolname
,
2296 nvroot
, props
, fsprops
) == 0) {
2297 zfs_handle_t
*pool
= zfs_open(g_zfs
,
2298 tname
? tname
: poolname
, ZFS_TYPE_FILESYSTEM
);
2300 if (zfs_mount(pool
, NULL
, 0) == 0) {
2301 ret
= zfs_share(pool
, NULL
);
2302 zfs_commit_shares(NULL
);
2306 } else if (libzfs_errno(g_zfs
) == EZFS_INVALIDNAME
) {
2307 (void) fprintf(stderr
, gettext("pool name may have "
2313 nvlist_free(nvroot
);
2314 nvlist_free(fsprops
);
2318 nvlist_free(fsprops
);
2325 * zpool destroy <pool>
2327 * -f Forcefully unmount any datasets
2329 * Destroy the given pool. Automatically unmounts any datasets in the pool.
2332 zpool_do_destroy(int argc
, char **argv
)
2334 boolean_t force
= B_FALSE
;
2337 zpool_handle_t
*zhp
;
2341 while ((c
= getopt(argc
, argv
, "f")) != -1) {
2347 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2356 /* check arguments */
2358 (void) fprintf(stderr
, gettext("missing pool argument\n"));
2362 (void) fprintf(stderr
, gettext("too many arguments\n"));
2368 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
) {
2370 * As a special case, check for use of '/' in the name, and
2371 * direct the user to use 'zfs destroy' instead.
2373 if (strchr(pool
, '/') != NULL
)
2374 (void) fprintf(stderr
, gettext("use 'zfs destroy' to "
2375 "destroy a dataset\n"));
2379 if (zpool_disable_datasets(zhp
, force
) != 0) {
2380 (void) fprintf(stderr
, gettext("could not destroy '%s': "
2381 "could not unmount datasets\n"), zpool_get_name(zhp
));
2386 /* The history must be logged as part of the export */
2387 log_history
= B_FALSE
;
2389 ret
= (zpool_destroy(zhp
, history_str
) != 0);
2396 typedef struct export_cbdata
{
2398 pthread_mutex_t mnttab_lock
;
2400 boolean_t hardforce
;
2407 export_cbdata_t
*aea_cbdata
;
2408 } async_export_args_t
;
2414 zpool_export_one(zpool_handle_t
*zhp
, void *data
)
2416 export_cbdata_t
*cb
= data
;
2419 * zpool_disable_datasets() is not thread-safe for mnttab access.
2420 * So we serialize access here for 'zpool export -a' parallel case.
2422 if (cb
->tpool
!= NULL
)
2423 pthread_mutex_lock(&cb
->mnttab_lock
);
2425 int retval
= zpool_disable_datasets(zhp
, cb
->force
);
2427 if (cb
->tpool
!= NULL
)
2428 pthread_mutex_unlock(&cb
->mnttab_lock
);
2433 if (cb
->hardforce
) {
2434 if (zpool_export_force(zhp
, history_str
) != 0)
2436 } else if (zpool_export(zhp
, cb
->force
, history_str
) != 0) {
2444 * Asynchronous export request
2447 zpool_export_task(void *arg
)
2449 async_export_args_t
*aea
= arg
;
2451 zpool_handle_t
*zhp
= zpool_open(g_zfs
, aea
->aea_poolname
);
2453 int ret
= zpool_export_one(zhp
, aea
->aea_cbdata
);
2455 aea
->aea_cbdata
->retval
= ret
;
2458 aea
->aea_cbdata
->retval
= 1;
2461 free(aea
->aea_poolname
);
2466 * Process an export request in parallel
2469 zpool_export_one_async(zpool_handle_t
*zhp
, void *data
)
2471 tpool_t
*tpool
= ((export_cbdata_t
*)data
)->tpool
;
2472 async_export_args_t
*aea
= safe_malloc(sizeof (async_export_args_t
));
2474 /* save pool name since zhp will go out of scope */
2475 aea
->aea_poolname
= strdup(zpool_get_name(zhp
));
2476 aea
->aea_cbdata
= data
;
2478 /* ship off actual export to another thread */
2479 if (tpool_dispatch(tpool
, zpool_export_task
, (void *)aea
) != 0)
2480 return (errno
); /* unlikely */
2486 * zpool export [-f] <pool> ...
2488 * -a Export all pools
2489 * -f Forcefully unmount datasets
2491 * Export the given pools. By default, the command will attempt to cleanly
2492 * unmount any active datasets within the pool. If the '-f' flag is specified,
2493 * then the datasets will be forcefully unmounted.
2496 zpool_do_export(int argc
, char **argv
)
2499 boolean_t do_all
= B_FALSE
;
2500 boolean_t force
= B_FALSE
;
2501 boolean_t hardforce
= B_FALSE
;
2505 while ((c
= getopt(argc
, argv
, "afF")) != -1) {
2517 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2524 cb
.hardforce
= hardforce
;
2530 /* The history will be logged as part of the export itself */
2531 log_history
= B_FALSE
;
2535 (void) fprintf(stderr
, gettext("too many arguments\n"));
2539 cb
.tpool
= tpool_create(1, 5 * sysconf(_SC_NPROCESSORS_ONLN
),
2541 pthread_mutex_init(&cb
.mnttab_lock
, NULL
);
2543 /* Asynchronously call zpool_export_one using thread pool */
2544 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
, ZFS_TYPE_POOL
,
2545 B_FALSE
, zpool_export_one_async
, &cb
);
2547 tpool_wait(cb
.tpool
);
2548 tpool_destroy(cb
.tpool
);
2549 (void) pthread_mutex_destroy(&cb
.mnttab_lock
);
2551 return (ret
| cb
.retval
);
2554 /* check arguments */
2556 (void) fprintf(stderr
, gettext("missing pool argument\n"));
2560 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
, ZFS_TYPE_POOL
,
2561 B_FALSE
, zpool_export_one
, &cb
);
2567 * Given a vdev configuration, determine the maximum width needed for the device
2571 max_width(zpool_handle_t
*zhp
, nvlist_t
*nv
, int depth
, int max
,
2574 static const char *const subtypes
[] =
2575 {ZPOOL_CONFIG_SPARES
, ZPOOL_CONFIG_L2CACHE
, ZPOOL_CONFIG_CHILDREN
};
2577 char *name
= zpool_vdev_name(g_zfs
, zhp
, nv
, name_flags
);
2578 max
= MAX(strlen(name
) + depth
, max
);
2583 for (size_t i
= 0; i
< ARRAY_SIZE(subtypes
); ++i
)
2584 if (nvlist_lookup_nvlist_array(nv
, subtypes
[i
],
2585 &child
, &children
) == 0)
2586 for (uint_t c
= 0; c
< children
; ++c
)
2587 max
= MAX(max_width(zhp
, child
[c
], depth
+ 2,
2588 max
, name_flags
), max
);
2593 typedef struct status_cbdata
{
2597 boolean_t cb_allpools
;
2598 boolean_t cb_verbose
;
2599 boolean_t cb_literal
;
2600 boolean_t cb_explain
;
2602 boolean_t cb_dedup_stats
;
2603 boolean_t cb_print_unhealthy
;
2604 boolean_t cb_print_status
;
2605 boolean_t cb_print_slow_ios
;
2606 boolean_t cb_print_dio_verify
;
2607 boolean_t cb_print_vdev_init
;
2608 boolean_t cb_print_vdev_trim
;
2609 vdev_cmd_data_list_t
*vcdl
;
2610 boolean_t cb_print_power
;
2612 boolean_t cb_flat_vdevs
;
2614 boolean_t cb_json_as_int
;
2615 boolean_t cb_json_pool_key_guid
;
2618 /* Return 1 if string is NULL, empty, or whitespace; return 0 otherwise. */
2620 is_blank_str(const char *str
)
2622 for (; str
!= NULL
&& *str
!= '\0'; ++str
)
2629 zpool_nvlist_cmd(vdev_cmd_data_list_t
*vcdl
, const char *pool
, const char *path
,
2632 vdev_cmd_data_t
*data
;
2637 for (i
= 0; i
< vcdl
->count
; i
++) {
2638 if ((strcmp(vcdl
->data
[i
].path
, path
) != 0) ||
2639 (strcmp(vcdl
->data
[i
].pool
, pool
) != 0))
2642 data
= &vcdl
->data
[i
];
2643 for (j
= 0; j
< vcdl
->uniq_cols_cnt
; j
++) {
2645 for (int k
= 0; k
< data
->cols_cnt
; k
++) {
2646 if (strcmp(data
->cols
[k
],
2647 vcdl
->uniq_cols
[j
]) == 0) {
2648 val
= data
->lines
[k
];
2652 if (val
== NULL
|| is_blank_str(val
))
2654 fnvlist_add_string(item
, vcdl
->uniq_cols
[j
], val
);
2657 for (j
= data
->cols_cnt
; j
< data
->lines_cnt
; j
++) {
2658 if (data
->lines
[j
]) {
2659 snprintf(tmp
, 256, "extra_%d", k
++);
2660 fnvlist_add_string(item
, tmp
,
2668 /* Print command output lines for specific vdev in a specific pool */
2670 zpool_print_cmd(vdev_cmd_data_list_t
*vcdl
, const char *pool
, const char *path
)
2672 vdev_cmd_data_t
*data
;
2676 for (i
= 0; i
< vcdl
->count
; i
++) {
2677 if ((strcmp(vcdl
->data
[i
].path
, path
) != 0) ||
2678 (strcmp(vcdl
->data
[i
].pool
, pool
) != 0)) {
2679 /* Not the vdev we're looking for */
2683 data
= &vcdl
->data
[i
];
2684 /* Print out all the output values for this vdev */
2685 for (j
= 0; j
< vcdl
->uniq_cols_cnt
; j
++) {
2687 /* Does this vdev have values for this column? */
2688 for (int k
= 0; k
< data
->cols_cnt
; k
++) {
2689 if (strcmp(data
->cols
[k
],
2690 vcdl
->uniq_cols
[j
]) == 0) {
2691 /* yes it does, record the value */
2692 val
= data
->lines
[k
];
2697 * Mark empty values with dashes to make output
2700 if (val
== NULL
|| is_blank_str(val
))
2703 printf("%*s", vcdl
->uniq_cols_width
[j
], val
);
2704 if (j
< vcdl
->uniq_cols_cnt
- 1)
2708 /* Print out any values that aren't in a column at the end */
2709 for (j
= data
->cols_cnt
; j
< data
->lines_cnt
; j
++) {
2710 /* Did we have any columns? If so print a spacer. */
2711 if (vcdl
->uniq_cols_cnt
> 0)
2714 val
= data
->lines
[j
];
2715 fputs(val
?: "", stdout
);
2722 * Print vdev initialization status for leaves
2725 print_status_initialize(vdev_stat_t
*vs
, boolean_t verbose
)
2728 if ((vs
->vs_initialize_state
== VDEV_INITIALIZE_ACTIVE
||
2729 vs
->vs_initialize_state
== VDEV_INITIALIZE_SUSPENDED
||
2730 vs
->vs_initialize_state
== VDEV_INITIALIZE_COMPLETE
) &&
2731 !vs
->vs_scan_removing
) {
2735 time_t t
= vs
->vs_initialize_action_time
;
2736 int initialize_pct
= 100;
2737 if (vs
->vs_initialize_state
!=
2738 VDEV_INITIALIZE_COMPLETE
) {
2739 initialize_pct
= (vs
->vs_initialize_bytes_done
*
2740 100 / (vs
->vs_initialize_bytes_est
+ 1));
2743 (void) ctime_r(&t
, tbuf
);
2746 switch (vs
->vs_initialize_state
) {
2747 case VDEV_INITIALIZE_SUSPENDED
:
2748 (void) snprintf(zbuf
, sizeof (zbuf
), ", %s %s",
2749 gettext("suspended, started at"), tbuf
);
2751 case VDEV_INITIALIZE_ACTIVE
:
2752 (void) snprintf(zbuf
, sizeof (zbuf
), ", %s %s",
2753 gettext("started at"), tbuf
);
2755 case VDEV_INITIALIZE_COMPLETE
:
2756 (void) snprintf(zbuf
, sizeof (zbuf
), ", %s %s",
2757 gettext("completed at"), tbuf
);
2761 (void) printf(gettext(" (%d%% initialized%s)"),
2762 initialize_pct
, zbuf
);
2764 (void) printf(gettext(" (uninitialized)"));
2766 } else if (vs
->vs_initialize_state
== VDEV_INITIALIZE_ACTIVE
) {
2767 (void) printf(gettext(" (initializing)"));
2772 * Print vdev TRIM status for leaves
2775 print_status_trim(vdev_stat_t
*vs
, boolean_t verbose
)
2778 if ((vs
->vs_trim_state
== VDEV_TRIM_ACTIVE
||
2779 vs
->vs_trim_state
== VDEV_TRIM_SUSPENDED
||
2780 vs
->vs_trim_state
== VDEV_TRIM_COMPLETE
) &&
2781 !vs
->vs_scan_removing
) {
2785 time_t t
= vs
->vs_trim_action_time
;
2787 if (vs
->vs_trim_state
!= VDEV_TRIM_COMPLETE
) {
2788 trim_pct
= (vs
->vs_trim_bytes_done
*
2789 100 / (vs
->vs_trim_bytes_est
+ 1));
2792 (void) ctime_r(&t
, tbuf
);
2795 switch (vs
->vs_trim_state
) {
2796 case VDEV_TRIM_SUSPENDED
:
2797 (void) snprintf(zbuf
, sizeof (zbuf
), ", %s %s",
2798 gettext("suspended, started at"), tbuf
);
2800 case VDEV_TRIM_ACTIVE
:
2801 (void) snprintf(zbuf
, sizeof (zbuf
), ", %s %s",
2802 gettext("started at"), tbuf
);
2804 case VDEV_TRIM_COMPLETE
:
2805 (void) snprintf(zbuf
, sizeof (zbuf
), ", %s %s",
2806 gettext("completed at"), tbuf
);
2810 (void) printf(gettext(" (%d%% trimmed%s)"),
2812 } else if (vs
->vs_trim_notsup
) {
2813 (void) printf(gettext(" (trim unsupported)"));
2815 (void) printf(gettext(" (untrimmed)"));
2817 } else if (vs
->vs_trim_state
== VDEV_TRIM_ACTIVE
) {
2818 (void) printf(gettext(" (trimming)"));
2823 * Return the color associated with a health string. This includes returning
2824 * NULL for no color change.
2827 health_str_to_color(const char *health
)
2829 if (strcmp(health
, gettext("FAULTED")) == 0 ||
2830 strcmp(health
, gettext("SUSPENDED")) == 0 ||
2831 strcmp(health
, gettext("UNAVAIL")) == 0) {
2835 if (strcmp(health
, gettext("OFFLINE")) == 0 ||
2836 strcmp(health
, gettext("DEGRADED")) == 0 ||
2837 strcmp(health
, gettext("REMOVED")) == 0) {
2838 return (ANSI_YELLOW
);
2845 * Called for each leaf vdev. Returns 0 if the vdev is healthy.
2846 * A vdev is unhealthy if any of the following are true:
2847 * 1) there are read, write, or checksum errors,
2848 * 2) its state is not ONLINE, or
2849 * 3) slow IO reporting was requested (-s) and there are slow IOs.
2852 vdev_health_check_cb(void *hdl_data
, nvlist_t
*nv
, void *data
)
2854 status_cbdata_t
*cb
= data
;
2859 if (nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
2860 (uint64_t **)&vs
, &vsc
) != 0)
2863 if (vs
->vs_checksum_errors
|| vs
->vs_read_errors
||
2864 vs
->vs_write_errors
|| vs
->vs_state
!= VDEV_STATE_HEALTHY
)
2867 if (cb
->cb_print_slow_ios
&& vs
->vs_slow_ios
)
2874 * Print out configuration state as requested by status_callback.
2877 print_status_config(zpool_handle_t
*zhp
, status_cbdata_t
*cb
, const char *name
,
2878 nvlist_t
*nv
, int depth
, boolean_t isspare
, vdev_rebuild_stat_t
*vrs
)
2880 nvlist_t
**child
, *root
;
2881 uint_t c
, i
, vsc
, children
;
2882 pool_scan_stat_t
*ps
= NULL
;
2884 char rbuf
[6], wbuf
[6], cbuf
[6], dbuf
[6];
2886 uint64_t notpresent
;
2887 spare_cbdata_t spare_cb
;
2890 const char *path
= NULL
;
2891 const char *rcolor
= NULL
, *wcolor
= NULL
, *ccolor
= NULL
,
2894 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
2895 &child
, &children
) != 0)
2898 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
2899 (uint64_t **)&vs
, &vsc
) == 0);
2901 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_TYPE
, &type
) == 0);
2903 if (strcmp(type
, VDEV_TYPE_INDIRECT
) == 0)
2906 state
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
2910 * For hot spares, we use the terms 'INUSE' and 'AVAILABLE' for
2913 if (vs
->vs_aux
== VDEV_AUX_SPARED
)
2914 state
= gettext("INUSE");
2915 else if (vs
->vs_state
== VDEV_STATE_HEALTHY
)
2916 state
= gettext("AVAIL");
2920 * If '-e' is specified then top-level vdevs and their children
2921 * can be pruned if all of their leaves are healthy.
2923 if (cb
->cb_print_unhealthy
&& depth
> 0 &&
2924 for_each_vdev_in_nvlist(nv
, vdev_health_check_cb
, cb
) == 0) {
2928 printf_color(health_str_to_color(state
),
2929 "\t%*s%-*s %-8s", depth
, "", cb
->cb_namewidth
- depth
,
2933 if (vs
->vs_read_errors
)
2936 if (vs
->vs_write_errors
)
2939 if (vs
->vs_checksum_errors
)
2942 if (vs
->vs_slow_ios
)
2945 if (cb
->cb_literal
) {
2947 printf_color(rcolor
, "%5llu",
2948 (u_longlong_t
)vs
->vs_read_errors
);
2950 printf_color(wcolor
, "%5llu",
2951 (u_longlong_t
)vs
->vs_write_errors
);
2953 printf_color(ccolor
, "%5llu",
2954 (u_longlong_t
)vs
->vs_checksum_errors
);
2956 zfs_nicenum(vs
->vs_read_errors
, rbuf
, sizeof (rbuf
));
2957 zfs_nicenum(vs
->vs_write_errors
, wbuf
, sizeof (wbuf
));
2958 zfs_nicenum(vs
->vs_checksum_errors
, cbuf
,
2961 printf_color(rcolor
, "%5s", rbuf
);
2963 printf_color(wcolor
, "%5s", wbuf
);
2965 printf_color(ccolor
, "%5s", cbuf
);
2967 if (cb
->cb_print_slow_ios
) {
2968 if (children
== 0) {
2969 /* Only leafs vdevs have slow IOs */
2970 zfs_nicenum(vs
->vs_slow_ios
, rbuf
,
2973 snprintf(rbuf
, sizeof (rbuf
), "-");
2977 printf_color(scolor
, " %5llu",
2978 (u_longlong_t
)vs
->vs_slow_ios
);
2980 printf_color(scolor
, " %5s", rbuf
);
2982 if (cb
->cb_print_power
) {
2983 if (children
== 0) {
2984 /* Only leaf vdevs have physical slots */
2985 switch (zpool_power_current_state(zhp
, (char *)
2986 fnvlist_lookup_string(nv
,
2987 ZPOOL_CONFIG_PATH
))) {
2989 printf_color(ANSI_RED
, " %5s",
2993 printf(" %5s", gettext("on"));
2996 printf(" %5s", "-");
2999 printf(" %5s", "-");
3002 if (VDEV_STAT_VALID(vs_dio_verify_errors
, vsc
) &&
3003 cb
->cb_print_dio_verify
) {
3004 zfs_nicenum(vs
->vs_dio_verify_errors
, dbuf
,
3009 (u_longlong_t
)vs
->vs_dio_verify_errors
);
3011 printf(" %5s", dbuf
);
3015 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_NOT_PRESENT
,
3016 ¬present
) == 0) {
3017 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_PATH
, &path
) == 0);
3018 (void) printf(" %s %s", gettext("was"), path
);
3019 } else if (vs
->vs_aux
!= 0) {
3021 color_start(ANSI_RED
);
3022 switch (vs
->vs_aux
) {
3023 case VDEV_AUX_OPEN_FAILED
:
3024 (void) printf(gettext("cannot open"));
3027 case VDEV_AUX_BAD_GUID_SUM
:
3028 (void) printf(gettext("missing device"));
3031 case VDEV_AUX_NO_REPLICAS
:
3032 (void) printf(gettext("insufficient replicas"));
3035 case VDEV_AUX_VERSION_NEWER
:
3036 (void) printf(gettext("newer version"));
3039 case VDEV_AUX_UNSUP_FEAT
:
3040 (void) printf(gettext("unsupported feature(s)"));
3043 case VDEV_AUX_ASHIFT_TOO_BIG
:
3044 (void) printf(gettext("unsupported minimum blocksize"));
3047 case VDEV_AUX_SPARED
:
3048 verify(nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
,
3049 &spare_cb
.cb_guid
) == 0);
3050 if (zpool_iter(g_zfs
, find_spare
, &spare_cb
) == 1) {
3051 if (strcmp(zpool_get_name(spare_cb
.cb_zhp
),
3052 zpool_get_name(zhp
)) == 0)
3053 (void) printf(gettext("currently in "
3056 (void) printf(gettext("in use by "
3058 zpool_get_name(spare_cb
.cb_zhp
));
3059 zpool_close(spare_cb
.cb_zhp
);
3061 (void) printf(gettext("currently in use"));
3065 case VDEV_AUX_ERR_EXCEEDED
:
3066 if (vs
->vs_read_errors
+ vs
->vs_write_errors
+
3067 vs
->vs_checksum_errors
== 0 && children
== 0 &&
3068 vs
->vs_slow_ios
> 0) {
3069 (void) printf(gettext("too many slow I/Os"));
3071 (void) printf(gettext("too many errors"));
3075 case VDEV_AUX_IO_FAILURE
:
3076 (void) printf(gettext("experienced I/O failures"));
3079 case VDEV_AUX_BAD_LOG
:
3080 (void) printf(gettext("bad intent log"));
3083 case VDEV_AUX_EXTERNAL
:
3084 (void) printf(gettext("external device fault"));
3087 case VDEV_AUX_SPLIT_POOL
:
3088 (void) printf(gettext("split into new pool"));
3091 case VDEV_AUX_ACTIVE
:
3092 (void) printf(gettext("currently in use"));
3095 case VDEV_AUX_CHILDREN_OFFLINE
:
3096 (void) printf(gettext("all children offline"));
3099 case VDEV_AUX_BAD_LABEL
:
3100 (void) printf(gettext("invalid label"));
3104 (void) printf(gettext("corrupted data"));
3108 } else if (children
== 0 && !isspare
&&
3109 getenv("ZPOOL_STATUS_NON_NATIVE_ASHIFT_IGNORE") == NULL
&&
3110 VDEV_STAT_VALID(vs_physical_ashift
, vsc
) &&
3111 vs
->vs_configured_ashift
< vs
->vs_physical_ashift
) {
3113 gettext(" block size: %dB configured, %dB native"),
3114 1 << vs
->vs_configured_ashift
, 1 << vs
->vs_physical_ashift
);
3117 if (vs
->vs_scan_removing
!= 0) {
3118 (void) printf(gettext(" (removing)"));
3119 } else if (VDEV_STAT_VALID(vs_noalloc
, vsc
) && vs
->vs_noalloc
!= 0) {
3120 (void) printf(gettext(" (non-allocating)"));
3123 /* The root vdev has the scrub/resilver stats */
3124 root
= fnvlist_lookup_nvlist(zpool_get_config(zhp
, NULL
),
3125 ZPOOL_CONFIG_VDEV_TREE
);
3126 (void) nvlist_lookup_uint64_array(root
, ZPOOL_CONFIG_SCAN_STATS
,
3127 (uint64_t **)&ps
, &c
);
3130 * If you force fault a drive that's resilvering, its scan stats can
3131 * get frozen in time, giving the false impression that it's
3132 * being resilvered. That's why we check the state to see if the vdev
3133 * is healthy before reporting "resilvering" or "repairing".
3135 if (ps
!= NULL
&& ps
->pss_state
== DSS_SCANNING
&& children
== 0 &&
3136 vs
->vs_state
== VDEV_STATE_HEALTHY
) {
3137 if (vs
->vs_scan_processed
!= 0) {
3138 (void) printf(gettext(" (%s)"),
3139 (ps
->pss_func
== POOL_SCAN_RESILVER
) ?
3140 "resilvering" : "repairing");
3141 } else if (vs
->vs_resilver_deferred
) {
3142 (void) printf(gettext(" (awaiting resilver)"));
3146 /* The top-level vdevs have the rebuild stats */
3147 if (vrs
!= NULL
&& vrs
->vrs_state
== VDEV_REBUILD_ACTIVE
&&
3148 children
== 0 && vs
->vs_state
== VDEV_STATE_HEALTHY
) {
3149 if (vs
->vs_rebuild_processed
!= 0) {
3150 (void) printf(gettext(" (resilvering)"));
3154 if (cb
->vcdl
!= NULL
) {
3155 if (nvlist_lookup_string(nv
, ZPOOL_CONFIG_PATH
, &path
) == 0) {
3157 zpool_print_cmd(cb
->vcdl
, zpool_get_name(zhp
), path
);
3161 /* Display vdev initialization and trim status for leaves. */
3162 if (children
== 0) {
3163 print_status_initialize(vs
, cb
->cb_print_vdev_init
);
3164 print_status_trim(vs
, cb
->cb_print_vdev_trim
);
3167 (void) printf("\n");
3169 for (c
= 0; c
< children
; c
++) {
3170 uint64_t islog
= B_FALSE
, ishole
= B_FALSE
;
3172 /* Don't print logs or holes here */
3173 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
3175 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_HOLE
,
3177 if (islog
|| ishole
)
3179 /* Only print normal classes here */
3180 if (nvlist_exists(child
[c
], ZPOOL_CONFIG_ALLOCATION_BIAS
))
3183 /* Provide vdev_rebuild_stats to children if available */
3185 (void) nvlist_lookup_uint64_array(nv
,
3186 ZPOOL_CONFIG_REBUILD_STATS
,
3187 (uint64_t **)&vrs
, &i
);
3190 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
3191 cb
->cb_name_flags
| VDEV_NAME_TYPE_ID
);
3192 print_status_config(zhp
, cb
, vname
, child
[c
], depth
+ 2,
3199 * Print the configuration of an exported pool. Iterate over all vdevs in the
3200 * pool, printing out the name and status for each one.
3203 print_import_config(status_cbdata_t
*cb
, const char *name
, nvlist_t
*nv
,
3212 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_TYPE
, &type
) == 0);
3213 if (strcmp(type
, VDEV_TYPE_MISSING
) == 0 ||
3214 strcmp(type
, VDEV_TYPE_HOLE
) == 0)
3217 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
3218 (uint64_t **)&vs
, &c
) == 0);
3220 (void) printf("\t%*s%-*s", depth
, "", cb
->cb_namewidth
- depth
, name
);
3221 (void) printf(" %s", zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
));
3223 if (vs
->vs_aux
!= 0) {
3226 switch (vs
->vs_aux
) {
3227 case VDEV_AUX_OPEN_FAILED
:
3228 (void) printf(gettext("cannot open"));
3231 case VDEV_AUX_BAD_GUID_SUM
:
3232 (void) printf(gettext("missing device"));
3235 case VDEV_AUX_NO_REPLICAS
:
3236 (void) printf(gettext("insufficient replicas"));
3239 case VDEV_AUX_VERSION_NEWER
:
3240 (void) printf(gettext("newer version"));
3243 case VDEV_AUX_UNSUP_FEAT
:
3244 (void) printf(gettext("unsupported feature(s)"));
3247 case VDEV_AUX_ERR_EXCEEDED
:
3248 (void) printf(gettext("too many errors"));
3251 case VDEV_AUX_ACTIVE
:
3252 (void) printf(gettext("currently in use"));
3255 case VDEV_AUX_CHILDREN_OFFLINE
:
3256 (void) printf(gettext("all children offline"));
3259 case VDEV_AUX_BAD_LABEL
:
3260 (void) printf(gettext("invalid label"));
3264 (void) printf(gettext("corrupted data"));
3268 (void) printf("\n");
3270 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
3271 &child
, &children
) != 0)
3274 for (c
= 0; c
< children
; c
++) {
3275 uint64_t is_log
= B_FALSE
;
3277 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
3281 if (nvlist_exists(child
[c
], ZPOOL_CONFIG_ALLOCATION_BIAS
))
3284 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
],
3285 cb
->cb_name_flags
| VDEV_NAME_TYPE_ID
);
3286 print_import_config(cb
, vname
, child
[c
], depth
+ 2);
3290 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
3291 &child
, &children
) == 0) {
3292 (void) printf(gettext("\tcache\n"));
3293 for (c
= 0; c
< children
; c
++) {
3294 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
],
3296 (void) printf("\t %s\n", vname
);
3301 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
3302 &child
, &children
) == 0) {
3303 (void) printf(gettext("\tspares\n"));
3304 for (c
= 0; c
< children
; c
++) {
3305 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
],
3307 (void) printf("\t %s\n", vname
);
3314 * Print specialized class vdevs.
3316 * These are recorded as top level vdevs in the main pool child array
3317 * but with "is_log" set to 1 or an "alloc_bias" string. We use either
3318 * print_status_config() or print_import_config() to print the top level
3319 * class vdevs then any of their children (eg mirrored slogs) are printed
3320 * recursively - which works because only the top level vdev is marked.
3323 print_class_vdevs(zpool_handle_t
*zhp
, status_cbdata_t
*cb
, nvlist_t
*nv
,
3328 boolean_t printed
= B_FALSE
;
3330 assert(zhp
!= NULL
|| !cb
->cb_verbose
);
3332 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
, &child
,
3336 for (c
= 0; c
< children
; c
++) {
3337 uint64_t is_log
= B_FALSE
;
3338 const char *bias
= NULL
;
3339 const char *type
= NULL
;
3341 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
3345 bias
= (char *)VDEV_ALLOC_CLASS_LOGS
;
3347 (void) nvlist_lookup_string(child
[c
],
3348 ZPOOL_CONFIG_ALLOCATION_BIAS
, &bias
);
3349 (void) nvlist_lookup_string(child
[c
],
3350 ZPOOL_CONFIG_TYPE
, &type
);
3353 if (bias
== NULL
|| strcmp(bias
, class) != 0)
3355 if (!is_log
&& strcmp(type
, VDEV_TYPE_INDIRECT
) == 0)
3359 (void) printf("\t%s\t\n", gettext(class));
3363 char *name
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
3364 cb
->cb_name_flags
| VDEV_NAME_TYPE_ID
);
3365 if (cb
->cb_print_status
)
3366 print_status_config(zhp
, cb
, name
, child
[c
], 2,
3369 print_import_config(cb
, name
, child
[c
], 2);
3375 * Display the status for the given pool.
3378 show_import(nvlist_t
*config
, boolean_t report_error
)
3380 uint64_t pool_state
;
3384 uint64_t hostid
= 0;
3386 const char *hostname
= "unknown";
3387 nvlist_t
*nvroot
, *nvinfo
;
3388 zpool_status_t reason
;
3389 zpool_errata_t errata
;
3392 const char *comment
;
3395 status_cbdata_t cb
= { 0 };
3397 verify(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
3399 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
,
3401 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
3403 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
3406 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_VDEV_STATS
,
3407 (uint64_t **)&vs
, &vsc
) == 0);
3408 health
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
3410 reason
= zpool_import_status(config
, &msgid
, &errata
);
3413 * If we're importing using a cachefile, then we won't report any
3414 * errors unless we are in the scan phase of the import.
3416 if (reason
!= ZPOOL_STATUS_OK
&& !report_error
)
3419 if (nvlist_lookup_string(config
, ZPOOL_CONFIG_COMMENT
, &comment
) == 0) {
3426 (void) printf(gettext("%s pool: %s\n"), indent
, name
);
3427 (void) printf(gettext("%s id: %llu\n"), indent
, (u_longlong_t
)guid
);
3428 (void) printf(gettext("%s state: %s"), indent
, health
);
3429 if (pool_state
== POOL_STATE_DESTROYED
)
3430 (void) printf(gettext(" (DESTROYED)"));
3431 (void) printf("\n");
3433 if (reason
!= ZPOOL_STATUS_OK
) {
3434 (void) printf("%s", indent
);
3435 printf_color(ANSI_BOLD
, gettext("status: "));
3438 case ZPOOL_STATUS_MISSING_DEV_R
:
3439 case ZPOOL_STATUS_MISSING_DEV_NR
:
3440 case ZPOOL_STATUS_BAD_GUID_SUM
:
3441 printf_color(ANSI_YELLOW
, gettext("One or more devices are "
3442 "missing from the system.\n"));
3445 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
3446 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
3447 printf_color(ANSI_YELLOW
, gettext("One or more devices "
3448 "contains corrupted data.\n"));
3451 case ZPOOL_STATUS_CORRUPT_DATA
:
3452 printf_color(ANSI_YELLOW
, gettext("The pool data is "
3456 case ZPOOL_STATUS_OFFLINE_DEV
:
3457 printf_color(ANSI_YELLOW
, gettext("One or more devices "
3458 "are offlined.\n"));
3461 case ZPOOL_STATUS_CORRUPT_POOL
:
3462 printf_color(ANSI_YELLOW
, gettext("The pool metadata is "
3466 case ZPOOL_STATUS_VERSION_OLDER
:
3467 printf_color(ANSI_YELLOW
, gettext("The pool is formatted using "
3468 "a legacy on-disk version.\n"));
3471 case ZPOOL_STATUS_VERSION_NEWER
:
3472 printf_color(ANSI_YELLOW
, gettext("The pool is formatted using "
3473 "an incompatible version.\n"));
3476 case ZPOOL_STATUS_FEAT_DISABLED
:
3477 printf_color(ANSI_YELLOW
, gettext("Some supported "
3478 "features are not enabled on the pool.\n"
3479 "\t%s(Note that they may be intentionally disabled if the\n"
3480 "\t%s'compatibility' property is set.)\n"), indent
, indent
);
3483 case ZPOOL_STATUS_COMPATIBILITY_ERR
:
3484 printf_color(ANSI_YELLOW
, gettext("Error reading or parsing "
3485 "the file(s) indicated by the 'compatibility'\n"
3486 "\t%sproperty.\n"), indent
);
3489 case ZPOOL_STATUS_INCOMPATIBLE_FEAT
:
3490 printf_color(ANSI_YELLOW
, gettext("One or more features "
3491 "are enabled on the pool despite not being\n"
3492 "\t%srequested by the 'compatibility' property.\n"),
3496 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
3497 printf_color(ANSI_YELLOW
, gettext("The pool uses the following "
3498 "feature(s) not supported on this system:\n"));
3499 color_start(ANSI_YELLOW
);
3500 zpool_collect_unsup_feat(config
, buf
, 2048);
3501 (void) printf("%s", buf
);
3505 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
3506 printf_color(ANSI_YELLOW
, gettext("The pool can only be "
3507 "accessed in read-only mode on this system. It\n"
3508 "\t%scannot be accessed in read-write mode because it uses "
3510 "\t%sfeature(s) not supported on this system:\n"),
3512 color_start(ANSI_YELLOW
);
3513 zpool_collect_unsup_feat(config
, buf
, 2048);
3514 (void) printf("%s", buf
);
3518 case ZPOOL_STATUS_HOSTID_ACTIVE
:
3519 printf_color(ANSI_YELLOW
, gettext("The pool is currently "
3520 "imported by another system.\n"));
3523 case ZPOOL_STATUS_HOSTID_REQUIRED
:
3524 printf_color(ANSI_YELLOW
, gettext("The pool has the "
3525 "multihost property on. It cannot\n"
3526 "\t%sbe safely imported when the system hostid is not "
3530 case ZPOOL_STATUS_HOSTID_MISMATCH
:
3531 printf_color(ANSI_YELLOW
, gettext("The pool was last accessed "
3532 "by another system.\n"));
3535 case ZPOOL_STATUS_FAULTED_DEV_R
:
3536 case ZPOOL_STATUS_FAULTED_DEV_NR
:
3537 printf_color(ANSI_YELLOW
, gettext("One or more devices are "
3541 case ZPOOL_STATUS_BAD_LOG
:
3542 printf_color(ANSI_YELLOW
, gettext("An intent log record cannot "
3546 case ZPOOL_STATUS_RESILVERING
:
3547 case ZPOOL_STATUS_REBUILDING
:
3548 printf_color(ANSI_YELLOW
, gettext("One or more devices were "
3549 "being resilvered.\n"));
3552 case ZPOOL_STATUS_ERRATA
:
3553 printf_color(ANSI_YELLOW
, gettext("Errata #%d detected.\n"),
3557 case ZPOOL_STATUS_NON_NATIVE_ASHIFT
:
3558 printf_color(ANSI_YELLOW
, gettext("One or more devices are "
3559 "configured to use a non-native block size.\n"
3560 "\t%sExpect reduced performance.\n"), indent
);
3565 * No other status can be seen when importing pools.
3567 assert(reason
== ZPOOL_STATUS_OK
);
3571 * Print out an action according to the overall state of the pool.
3573 if (vs
->vs_state
!= VDEV_STATE_HEALTHY
||
3574 reason
!= ZPOOL_STATUS_ERRATA
|| errata
!= ZPOOL_ERRATA_NONE
) {
3575 (void) printf("%s", indent
);
3576 (void) printf(gettext("action: "));
3578 if (vs
->vs_state
== VDEV_STATE_HEALTHY
) {
3579 if (reason
== ZPOOL_STATUS_VERSION_OLDER
||
3580 reason
== ZPOOL_STATUS_FEAT_DISABLED
) {
3581 (void) printf(gettext("The pool can be imported using "
3582 "its name or numeric identifier, though\n"
3583 "\t%ssome features will not be available without "
3584 "an explicit 'zpool upgrade'.\n"), indent
);
3585 } else if (reason
== ZPOOL_STATUS_COMPATIBILITY_ERR
) {
3586 (void) printf(gettext("The pool can be imported using "
3587 "its name or numeric\n"
3588 "\t%sidentifier, though the file(s) indicated by "
3589 "its 'compatibility'\n"
3590 "\t%sproperty cannot be parsed at this time.\n"),
3592 } else if (reason
== ZPOOL_STATUS_HOSTID_MISMATCH
) {
3593 (void) printf(gettext("The pool can be imported using "
3594 "its name or numeric identifier and\n"
3595 "\t%sthe '-f' flag.\n"), indent
);
3596 } else if (reason
== ZPOOL_STATUS_ERRATA
) {
3598 case ZPOOL_ERRATA_ZOL_2094_SCRUB
:
3599 (void) printf(gettext("The pool can be "
3600 "imported using its name or numeric "
3602 "\t%showever there is a compatibility "
3603 "issue which should be corrected\n"
3604 "\t%sby running 'zpool scrub'\n"),
3608 case ZPOOL_ERRATA_ZOL_2094_ASYNC_DESTROY
:
3609 (void) printf(gettext("The pool cannot be "
3610 "imported with this version of ZFS due to\n"
3611 "\t%san active asynchronous destroy. "
3612 "Revert to an earlier version\n"
3613 "\t%sand allow the destroy to complete "
3614 "before updating.\n"), indent
, indent
);
3617 case ZPOOL_ERRATA_ZOL_6845_ENCRYPTION
:
3618 (void) printf(gettext("Existing encrypted "
3619 "datasets contain an on-disk "
3620 "incompatibility, which\n"
3621 "\t%sneeds to be corrected. Backup these "
3622 "datasets to new encrypted datasets\n"
3623 "\t%sand destroy the old ones.\n"),
3627 case ZPOOL_ERRATA_ZOL_8308_ENCRYPTION
:
3628 (void) printf(gettext("Existing encrypted "
3629 "snapshots and bookmarks contain an "
3631 "\t%sincompatibility. This may cause "
3632 "on-disk corruption if they are used\n"
3633 "\t%swith 'zfs recv'. To correct the "
3634 "issue, enable the bookmark_v2 feature.\n"
3635 "\t%sNo additional action is needed if "
3636 "there are no encrypted snapshots or\n"
3637 "\t%sbookmarks. If preserving the "
3638 "encrypted snapshots and bookmarks is\n"
3639 "\t%srequired, use a non-raw send to "
3640 "backup and restore them. Alternately,\n"
3641 "\t%sthey may be removed to resolve the "
3642 "incompatibility.\n"), indent
, indent
,
3643 indent
, indent
, indent
, indent
);
3647 * All errata must contain an action message.
3649 assert(errata
== ZPOOL_ERRATA_NONE
);
3652 (void) printf(gettext("The pool can be imported using "
3653 "its name or numeric identifier.\n"));
3655 } else if (vs
->vs_state
== VDEV_STATE_DEGRADED
) {
3656 (void) printf(gettext("The pool can be imported despite "
3657 "missing or damaged devices. The\n"
3658 "\t%sfault tolerance of the pool may be compromised if "
3659 "imported.\n"), indent
);
3662 case ZPOOL_STATUS_VERSION_NEWER
:
3663 (void) printf(gettext("The pool cannot be imported. "
3664 "Access the pool on a system running newer\n"
3665 "\t%ssoftware, or recreate the pool from "
3666 "backup.\n"), indent
);
3668 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
3669 (void) printf(gettext("The pool cannot be imported. "
3670 "Access the pool on a system that supports\n"
3671 "\t%sthe required feature(s), or recreate the pool "
3672 "from backup.\n"), indent
);
3674 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
3675 (void) printf(gettext("The pool cannot be imported in "
3676 "read-write mode. Import the pool with\n"
3677 "\t%s'-o readonly=on', access the pool on a system "
3678 "that supports the\n"
3679 "\t%srequired feature(s), or recreate the pool "
3680 "from backup.\n"), indent
, indent
);
3682 case ZPOOL_STATUS_MISSING_DEV_R
:
3683 case ZPOOL_STATUS_MISSING_DEV_NR
:
3684 case ZPOOL_STATUS_BAD_GUID_SUM
:
3685 (void) printf(gettext("The pool cannot be imported. "
3686 "Attach the missing\n"
3687 "\t%sdevices and try again.\n"), indent
);
3689 case ZPOOL_STATUS_HOSTID_ACTIVE
:
3690 VERIFY0(nvlist_lookup_nvlist(config
,
3691 ZPOOL_CONFIG_LOAD_INFO
, &nvinfo
));
3693 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_MMP_HOSTNAME
))
3694 hostname
= fnvlist_lookup_string(nvinfo
,
3695 ZPOOL_CONFIG_MMP_HOSTNAME
);
3697 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_MMP_HOSTID
))
3698 hostid
= fnvlist_lookup_uint64(nvinfo
,
3699 ZPOOL_CONFIG_MMP_HOSTID
);
3701 (void) printf(gettext("The pool must be exported from "
3702 "%s (hostid=%"PRIx64
")\n"
3703 "\t%sbefore it can be safely imported.\n"),
3704 hostname
, hostid
, indent
);
3706 case ZPOOL_STATUS_HOSTID_REQUIRED
:
3707 (void) printf(gettext("Set a unique system hostid with "
3708 "the zgenhostid(8) command.\n"));
3711 (void) printf(gettext("The pool cannot be imported due "
3712 "to damaged devices or data.\n"));
3716 /* Print the comment attached to the pool. */
3717 if (comment
!= NULL
)
3718 (void) printf(gettext("comment: %s\n"), comment
);
3721 * If the state is "closed" or "can't open", and the aux state
3722 * is "corrupt data":
3724 if ((vs
->vs_state
== VDEV_STATE_CLOSED
||
3725 vs
->vs_state
== VDEV_STATE_CANT_OPEN
) &&
3726 vs
->vs_aux
== VDEV_AUX_CORRUPT_DATA
) {
3727 if (pool_state
== POOL_STATE_DESTROYED
)
3728 (void) printf(gettext("\t%sThe pool was destroyed, "
3729 "but can be imported using the '-Df' flags.\n"),
3731 else if (pool_state
!= POOL_STATE_EXPORTED
)
3732 (void) printf(gettext("\t%sThe pool may be active on "
3733 "another system, but can be imported using\n"
3734 "\t%sthe '-f' flag.\n"), indent
, indent
);
3737 if (msgid
!= NULL
) {
3738 (void) printf(gettext("%s see: "
3739 "https://openzfs.github.io/openzfs-docs/msg/%s\n"),
3743 (void) printf(gettext("%sconfig:\n\n"), indent
);
3745 cb
.cb_namewidth
= max_width(NULL
, nvroot
, 0, strlen(name
),
3747 if (cb
.cb_namewidth
< 10)
3748 cb
.cb_namewidth
= 10;
3750 print_import_config(&cb
, name
, nvroot
, 0);
3752 print_class_vdevs(NULL
, &cb
, nvroot
, VDEV_ALLOC_BIAS_DEDUP
);
3753 print_class_vdevs(NULL
, &cb
, nvroot
, VDEV_ALLOC_BIAS_SPECIAL
);
3754 print_class_vdevs(NULL
, &cb
, nvroot
, VDEV_ALLOC_CLASS_LOGS
);
3756 if (reason
== ZPOOL_STATUS_BAD_GUID_SUM
) {
3757 (void) printf(gettext("\n\t%sAdditional devices are known to "
3758 "be part of this pool, though their\n"
3759 "\t%sexact configuration cannot be determined.\n"),
3766 zfs_force_import_required(nvlist_t
*config
)
3769 uint64_t hostid
= 0;
3772 state
= fnvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
);
3773 nvinfo
= fnvlist_lookup_nvlist(config
, ZPOOL_CONFIG_LOAD_INFO
);
3776 * The hostid on LOAD_INFO comes from the MOS label via
3777 * spa_tryimport(). If its not there then we're likely talking to an
3778 * older kernel, so use the top one, which will be from the label
3779 * discovered in zpool_find_import(), or if a cachefile is in use, the
3782 if (nvlist_lookup_uint64(nvinfo
, ZPOOL_CONFIG_HOSTID
, &hostid
) != 0)
3783 (void) nvlist_lookup_uint64(config
, ZPOOL_CONFIG_HOSTID
,
3786 if (state
!= POOL_STATE_EXPORTED
&& hostid
!= get_system_hostid())
3789 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_MMP_STATE
)) {
3790 mmp_state_t mmp_state
= fnvlist_lookup_uint64(nvinfo
,
3791 ZPOOL_CONFIG_MMP_STATE
);
3793 if (mmp_state
!= MMP_STATE_INACTIVE
)
3801 * Perform the import for the given configuration. This passes the heavy
3802 * lifting off to zpool_import_props(), and then mounts the datasets contained
3806 do_import(nvlist_t
*config
, const char *newname
, const char *mntopts
,
3807 nvlist_t
*props
, int flags
, uint_t mntthreads
)
3811 zpool_handle_t
*zhp
;
3815 name
= fnvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
);
3816 version
= fnvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
);
3818 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
3819 (void) fprintf(stderr
, gettext("cannot import '%s': pool "
3820 "is formatted using an unsupported ZFS version\n"), name
);
3822 } else if (zfs_force_import_required(config
) &&
3823 !(flags
& ZFS_IMPORT_ANY_HOST
)) {
3824 mmp_state_t mmp_state
= MMP_STATE_INACTIVE
;
3827 nvinfo
= fnvlist_lookup_nvlist(config
, ZPOOL_CONFIG_LOAD_INFO
);
3828 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_MMP_STATE
))
3829 mmp_state
= fnvlist_lookup_uint64(nvinfo
,
3830 ZPOOL_CONFIG_MMP_STATE
);
3832 if (mmp_state
== MMP_STATE_ACTIVE
) {
3833 const char *hostname
= "<unknown>";
3834 uint64_t hostid
= 0;
3836 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_MMP_HOSTNAME
))
3837 hostname
= fnvlist_lookup_string(nvinfo
,
3838 ZPOOL_CONFIG_MMP_HOSTNAME
);
3840 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_MMP_HOSTID
))
3841 hostid
= fnvlist_lookup_uint64(nvinfo
,
3842 ZPOOL_CONFIG_MMP_HOSTID
);
3844 (void) fprintf(stderr
, gettext("cannot import '%s': "
3845 "pool is imported on %s (hostid: "
3846 "0x%"PRIx64
")\nExport the pool on the other "
3847 "system, then run 'zpool import'.\n"),
3848 name
, hostname
, hostid
);
3849 } else if (mmp_state
== MMP_STATE_NO_HOSTID
) {
3850 (void) fprintf(stderr
, gettext("Cannot import '%s': "
3851 "pool has the multihost property on and the\n"
3852 "system's hostid is not set. Set a unique hostid "
3853 "with the zgenhostid(8) command.\n"), name
);
3855 const char *hostname
= "<unknown>";
3856 time_t timestamp
= 0;
3857 uint64_t hostid
= 0;
3859 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_HOSTNAME
))
3860 hostname
= fnvlist_lookup_string(nvinfo
,
3861 ZPOOL_CONFIG_HOSTNAME
);
3862 else if (nvlist_exists(config
, ZPOOL_CONFIG_HOSTNAME
))
3863 hostname
= fnvlist_lookup_string(config
,
3864 ZPOOL_CONFIG_HOSTNAME
);
3866 if (nvlist_exists(config
, ZPOOL_CONFIG_TIMESTAMP
))
3867 timestamp
= fnvlist_lookup_uint64(config
,
3868 ZPOOL_CONFIG_TIMESTAMP
);
3870 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_HOSTID
))
3871 hostid
= fnvlist_lookup_uint64(nvinfo
,
3872 ZPOOL_CONFIG_HOSTID
);
3873 else if (nvlist_exists(config
, ZPOOL_CONFIG_HOSTID
))
3874 hostid
= fnvlist_lookup_uint64(config
,
3875 ZPOOL_CONFIG_HOSTID
);
3877 (void) fprintf(stderr
, gettext("cannot import '%s': "
3878 "pool was previously in use from another system.\n"
3879 "Last accessed by %s (hostid=%"PRIx64
") at %s"
3880 "The pool can be imported, use 'zpool import -f' "
3881 "to import the pool.\n"), name
, hostname
,
3882 hostid
, ctime(×tamp
));
3888 if (zpool_import_props(g_zfs
, config
, newname
, props
, flags
) != 0)
3891 if (newname
!= NULL
)
3894 if ((zhp
= zpool_open_canfail(g_zfs
, name
)) == NULL
)
3898 * Loading keys is best effort. We don't want to return immediately
3899 * if it fails but we do want to give the error to the caller.
3901 if (flags
& ZFS_IMPORT_LOAD_KEYS
&&
3902 zfs_crypto_attempt_load_keys(g_zfs
, name
) != 0)
3905 if (zpool_get_state(zhp
) != POOL_STATE_UNAVAIL
&&
3906 !(flags
& ZFS_IMPORT_ONLY
)) {
3907 ms_status
= zpool_enable_datasets(zhp
, mntopts
, 0, mntthreads
);
3908 if (ms_status
== EZFS_SHAREFAILED
) {
3909 (void) fprintf(stderr
, gettext("Import was "
3910 "successful, but unable to share some datasets\n"));
3911 } else if (ms_status
== EZFS_MOUNTFAILED
) {
3912 (void) fprintf(stderr
, gettext("Import was "
3913 "successful, but unable to mount some datasets\n"));
3921 typedef struct import_parameters
{
3922 nvlist_t
*ip_config
;
3923 const char *ip_mntopts
;
3926 uint_t ip_mntthreads
;
3928 } import_parameters_t
;
3931 do_import_task(void *arg
)
3933 import_parameters_t
*ip
= arg
;
3934 *ip
->ip_err
|= do_import(ip
->ip_config
, NULL
, ip
->ip_mntopts
,
3935 ip
->ip_props
, ip
->ip_flags
, ip
->ip_mntthreads
);
3941 import_pools(nvlist_t
*pools
, nvlist_t
*props
, char *mntopts
, int flags
,
3942 char *orig_name
, char *new_name
, importargs_t
*import
)
3944 nvlist_t
*config
= NULL
;
3945 nvlist_t
*found_config
= NULL
;
3946 uint64_t pool_state
;
3947 boolean_t pool_specified
= (import
->poolname
!= NULL
||
3953 if (import
->do_all
) {
3954 tp
= tpool_create(1, 5 * sysconf(_SC_NPROCESSORS_ONLN
),
3959 * At this point we have a list of import candidate configs. Even if
3960 * we were searching by pool name or guid, we still need to
3961 * post-process the list to deal with pool state and possible
3965 nvpair_t
*elem
= NULL
;
3966 boolean_t first
= B_TRUE
;
3967 if (!pool_specified
&& import
->do_all
) {
3968 while ((elem
= nvlist_next_nvpair(pools
, elem
)) != NULL
)
3971 while ((elem
= nvlist_next_nvpair(pools
, elem
)) != NULL
) {
3973 verify(nvpair_value_nvlist(elem
, &config
) == 0);
3975 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
3977 if (!import
->do_destroyed
&&
3978 pool_state
== POOL_STATE_DESTROYED
)
3980 if (import
->do_destroyed
&&
3981 pool_state
!= POOL_STATE_DESTROYED
)
3984 verify(nvlist_add_nvlist(config
, ZPOOL_LOAD_POLICY
,
3985 import
->policy
) == 0);
3987 if (!pool_specified
) {
3990 else if (!import
->do_all
)
3991 (void) fputc('\n', stdout
);
3993 if (import
->do_all
) {
3994 import_parameters_t
*ip
= safe_malloc(
3995 sizeof (import_parameters_t
));
3997 ip
->ip_config
= config
;
3998 ip
->ip_mntopts
= mntopts
;
3999 ip
->ip_props
= props
;
4000 ip
->ip_flags
= flags
;
4001 ip
->ip_mntthreads
= mount_tp_nthr
/ npools
;
4004 (void) tpool_dispatch(tp
, do_import_task
,
4008 * If we're importing from cachefile, then
4009 * we don't want to report errors until we
4010 * are in the scan phase of the import. If
4011 * we get an error, then we return that error
4012 * to invoke the scan phase.
4014 if (import
->cachefile
&& !import
->scan
)
4015 err
= show_import(config
, B_FALSE
);
4017 (void) show_import(config
, B_TRUE
);
4019 } else if (import
->poolname
!= NULL
) {
4023 * We are searching for a pool based on name.
4025 verify(nvlist_lookup_string(config
,
4026 ZPOOL_CONFIG_POOL_NAME
, &name
) == 0);
4028 if (strcmp(name
, import
->poolname
) == 0) {
4029 if (found_config
!= NULL
) {
4030 (void) fprintf(stderr
, gettext(
4031 "cannot import '%s': more than "
4032 "one matching pool\n"),
4034 (void) fprintf(stderr
, gettext(
4035 "import by numeric ID instead\n"));
4038 found_config
= config
;
4044 * Search for a pool by guid.
4046 verify(nvlist_lookup_uint64(config
,
4047 ZPOOL_CONFIG_POOL_GUID
, &guid
) == 0);
4049 if (guid
== import
->guid
)
4050 found_config
= config
;
4053 if (import
->do_all
) {
4059 * If we were searching for a specific pool, verify that we found a
4060 * pool, and then do the import.
4062 if (pool_specified
&& err
== 0) {
4063 if (found_config
== NULL
) {
4064 (void) fprintf(stderr
, gettext("cannot import '%s': "
4065 "no such pool available\n"), orig_name
);
4068 err
|= do_import(found_config
, new_name
,
4069 mntopts
, props
, flags
, mount_tp_nthr
);
4074 * If we were just looking for pools, report an error if none were
4077 if (!pool_specified
&& first
)
4078 (void) fprintf(stderr
,
4079 gettext("no pools available to import\n"));
4083 typedef struct target_exists_args
{
4084 const char *poolname
;
4086 } target_exists_args_t
;
4089 name_or_guid_exists(zpool_handle_t
*zhp
, void *data
)
4091 target_exists_args_t
*args
= data
;
4092 nvlist_t
*config
= zpool_get_config(zhp
, NULL
);
4098 if (args
->poolname
!= NULL
) {
4099 const char *pool_name
;
4101 verify(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
4103 if (strcmp(pool_name
, args
->poolname
) == 0)
4108 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
,
4110 if (pool_guid
== args
->poolguid
)
4118 * zpool checkpoint <pool>
4119 * checkpoint --discard <pool>
4121 * -d Discard the checkpoint from a checkpointed
4124 * -w Wait for discarding a checkpoint to complete.
4127 * Checkpoints the specified pool, by taking a "snapshot" of its
4128 * current state. A pool can only have one checkpoint at a time.
4131 zpool_do_checkpoint(int argc
, char **argv
)
4133 boolean_t discard
, wait
;
4135 zpool_handle_t
*zhp
;
4138 struct option long_options
[] = {
4139 {"discard", no_argument
, NULL
, 'd'},
4140 {"wait", no_argument
, NULL
, 'w'},
4146 while ((c
= getopt_long(argc
, argv
, ":dw", long_options
, NULL
)) != -1) {
4155 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4161 if (wait
&& !discard
) {
4162 (void) fprintf(stderr
, gettext("--wait only valid when "
4163 "--discard also specified\n"));
4171 (void) fprintf(stderr
, gettext("missing pool argument\n"));
4176 (void) fprintf(stderr
, gettext("too many arguments\n"));
4182 if ((zhp
= zpool_open(g_zfs
, pool
)) == NULL
) {
4183 /* As a special case, check for use of '/' in the name */
4184 if (strchr(pool
, '/') != NULL
)
4185 (void) fprintf(stderr
, gettext("'zpool checkpoint' "
4186 "doesn't work on datasets. To save the state "
4187 "of a dataset from a specific point in time "
4188 "please use 'zfs snapshot'\n"));
4193 err
= (zpool_discard_checkpoint(zhp
) != 0);
4194 if (err
== 0 && wait
)
4195 err
= zpool_wait(zhp
, ZPOOL_WAIT_CKPT_DISCARD
);
4197 err
= (zpool_checkpoint(zhp
) != 0);
4205 #define CHECKPOINT_OPT 1024
4208 * zpool prefetch <type> [<type opts>] <pool>
4210 * Prefetchs a particular type of data in the specified pool.
4213 zpool_do_prefetch(int argc
, char **argv
)
4217 char *typestr
= NULL
;
4218 zpool_prefetch_type_t type
;
4219 zpool_handle_t
*zhp
;
4222 while ((c
= getopt(argc
, argv
, "t:")) != -1) {
4228 (void) fprintf(stderr
, gettext("missing argument for "
4229 "'%c' option\n"), optopt
);
4233 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4242 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
4247 (void) fprintf(stderr
, gettext("too many arguments\n"));
4256 if (strcmp(typestr
, "ddt") == 0) {
4257 type
= ZPOOL_PREFETCH_DDT
;
4259 (void) fprintf(stderr
, gettext("unsupported prefetch type\n"));
4263 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
4266 err
= zpool_prefetch(zhp
, type
);
4274 * zpool import [-d dir] [-D]
4275 * import [-o mntopts] [-o prop=value] ... [-R root] [-D] [-l]
4276 * [-d dir | -c cachefile | -s] [-f] -a
4277 * import [-o mntopts] [-o prop=value] ... [-R root] [-D] [-l]
4278 * [-d dir | -c cachefile | -s] [-f] [-n] [-F] <pool | id>
4281 * -c Read pool information from a cachefile instead of searching
4282 * devices. If importing from a cachefile config fails, then
4283 * fallback to searching for devices only in the directories that
4284 * exist in the cachefile.
4286 * -d Scan in a specific directory, other than /dev/. More than
4287 * one directory can be specified using multiple '-d' options.
4289 * -D Scan for previously destroyed pools or import all or only
4290 * specified destroyed pools.
4292 * -R Temporarily import the pool, with all mountpoints relative to
4293 * the given root. The pool will remain exported when the machine
4296 * -V Import even in the presence of faulted vdevs. This is an
4297 * intentionally undocumented option for testing purposes, and
4298 * treats the pool configuration as complete, leaving any bad
4299 * vdevs in the FAULTED state. In other words, it does verbatim
4302 * -f Force import, even if it appears that the pool is active.
4304 * -F Attempt rewind if necessary.
4306 * -n See if rewind would work, but don't actually rewind.
4308 * -N Import the pool but don't mount datasets.
4310 * -T Specify a starting txg to use for import. This option is
4311 * intentionally undocumented option for testing purposes.
4313 * -a Import all pools found.
4315 * -l Load encryption keys while importing.
4317 * -o Set property=value and/or temporary mount options (without '=').
4319 * -s Scan using the default search path, the libblkid cache will
4322 * --rewind-to-checkpoint
4323 * Import the pool and revert back to the checkpoint.
4325 * The import command scans for pools to import, and import pools based on pool
4326 * name and GUID. The pool can also be renamed as part of the import process.
4329 zpool_do_import(int argc
, char **argv
)
4331 char **searchdirs
= NULL
;
4332 char *env
, *envdup
= NULL
;
4336 nvlist_t
*pools
= NULL
;
4337 boolean_t do_all
= B_FALSE
;
4338 boolean_t do_destroyed
= B_FALSE
;
4339 char *mntopts
= NULL
;
4340 uint64_t searchguid
= 0;
4341 char *searchname
= NULL
;
4343 nvlist_t
*policy
= NULL
;
4344 nvlist_t
*props
= NULL
;
4345 int flags
= ZFS_IMPORT_NORMAL
;
4346 uint32_t rewind_policy
= ZPOOL_NO_REWIND
;
4347 boolean_t dryrun
= B_FALSE
;
4348 boolean_t do_rewind
= B_FALSE
;
4349 boolean_t xtreme_rewind
= B_FALSE
;
4350 boolean_t do_scan
= B_FALSE
;
4351 boolean_t pool_exists
= B_FALSE
;
4352 uint64_t txg
= -1ULL;
4353 char *cachefile
= NULL
;
4354 importargs_t idata
= { 0 };
4357 struct option long_options
[] = {
4358 {"rewind-to-checkpoint", no_argument
, NULL
, CHECKPOINT_OPT
},
4363 while ((c
= getopt_long(argc
, argv
, ":aCc:d:DEfFlmnNo:R:stT:VX",
4364 long_options
, NULL
)) != -1) {
4373 searchdirs
= safe_realloc(searchdirs
,
4374 (nsearch
+ 1) * sizeof (char *));
4375 searchdirs
[nsearch
++] = optarg
;
4378 do_destroyed
= B_TRUE
;
4381 flags
|= ZFS_IMPORT_ANY_HOST
;
4387 flags
|= ZFS_IMPORT_LOAD_KEYS
;
4390 flags
|= ZFS_IMPORT_MISSING_LOG
;
4396 flags
|= ZFS_IMPORT_ONLY
;
4399 if ((propval
= strchr(optarg
, '=')) != NULL
) {
4402 if (add_prop_list(optarg
, propval
,
4410 if (add_prop_list(zpool_prop_to_name(
4411 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
4413 if (add_prop_list_default(zpool_prop_to_name(
4414 ZPOOL_PROP_CACHEFILE
), "none", &props
))
4421 flags
|= ZFS_IMPORT_TEMP_NAME
;
4422 if (add_prop_list_default(zpool_prop_to_name(
4423 ZPOOL_PROP_CACHEFILE
), "none", &props
))
4429 txg
= strtoull(optarg
, &endptr
, 0);
4430 if (errno
!= 0 || *endptr
!= '\0') {
4431 (void) fprintf(stderr
,
4432 gettext("invalid txg value\n"));
4435 rewind_policy
= ZPOOL_DO_REWIND
| ZPOOL_EXTREME_REWIND
;
4438 flags
|= ZFS_IMPORT_VERBATIM
;
4441 xtreme_rewind
= B_TRUE
;
4443 case CHECKPOINT_OPT
:
4444 flags
|= ZFS_IMPORT_CHECKPOINT
;
4447 (void) fprintf(stderr
, gettext("missing argument for "
4448 "'%c' option\n"), optopt
);
4452 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4461 if (cachefile
&& nsearch
!= 0) {
4462 (void) fprintf(stderr
, gettext("-c is incompatible with -d\n"));
4466 if (cachefile
&& do_scan
) {
4467 (void) fprintf(stderr
, gettext("-c is incompatible with -s\n"));
4471 if ((flags
& ZFS_IMPORT_LOAD_KEYS
) && (flags
& ZFS_IMPORT_ONLY
)) {
4472 (void) fprintf(stderr
, gettext("-l is incompatible with -N\n"));
4476 if ((flags
& ZFS_IMPORT_LOAD_KEYS
) && !do_all
&& argc
== 0) {
4477 (void) fprintf(stderr
, gettext("-l is only meaningful during "
4482 if ((dryrun
|| xtreme_rewind
) && !do_rewind
) {
4483 (void) fprintf(stderr
,
4484 gettext("-n or -X only meaningful with -F\n"));
4488 rewind_policy
= ZPOOL_TRY_REWIND
;
4490 rewind_policy
= ZPOOL_DO_REWIND
;
4492 rewind_policy
|= ZPOOL_EXTREME_REWIND
;
4494 /* In the future, we can capture further policy and include it here */
4495 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME
, 0) != 0 ||
4496 nvlist_add_uint64(policy
, ZPOOL_LOAD_REQUEST_TXG
, txg
) != 0 ||
4497 nvlist_add_uint32(policy
, ZPOOL_LOAD_REWIND_POLICY
,
4498 rewind_policy
) != 0)
4501 /* check argument count */
4504 (void) fprintf(stderr
, gettext("too many arguments\n"));
4509 (void) fprintf(stderr
, gettext("too many arguments\n"));
4515 * Check for the effective uid. We do this explicitly here because
4516 * otherwise any attempt to discover pools will silently fail.
4518 if (argc
== 0 && geteuid() != 0) {
4519 (void) fprintf(stderr
, gettext("cannot "
4520 "discover pools: permission denied\n"));
4524 nvlist_free(policy
);
4529 * Depending on the arguments given, we do one of the following:
4531 * <none> Iterate through all pools and display information about
4534 * -a Iterate through all pools and try to import each one.
4536 * <id> Find the pool that corresponds to the given GUID/pool
4537 * name and import that one.
4539 * -D Above options applies only to destroyed pools.
4545 searchguid
= strtoull(argv
[0], &endptr
, 10);
4546 if (errno
!= 0 || *endptr
!= '\0') {
4547 searchname
= argv
[0];
4552 * User specified a name or guid. Ensure it's unique.
4554 target_exists_args_t search
= {searchname
, searchguid
};
4555 pool_exists
= zpool_iter(g_zfs
, name_or_guid_exists
, &search
);
4559 * Check the environment for the preferred search path.
4561 if ((searchdirs
== NULL
) && (env
= getenv("ZPOOL_IMPORT_PATH"))) {
4562 char *dir
, *tmp
= NULL
;
4564 envdup
= strdup(env
);
4566 for (dir
= strtok_r(envdup
, ":", &tmp
);
4568 dir
= strtok_r(NULL
, ":", &tmp
)) {
4569 searchdirs
= safe_realloc(searchdirs
,
4570 (nsearch
+ 1) * sizeof (char *));
4571 searchdirs
[nsearch
++] = dir
;
4575 idata
.path
= searchdirs
;
4576 idata
.paths
= nsearch
;
4577 idata
.poolname
= searchname
;
4578 idata
.guid
= searchguid
;
4579 idata
.cachefile
= cachefile
;
4580 idata
.scan
= do_scan
;
4581 idata
.policy
= policy
;
4582 idata
.do_destroyed
= do_destroyed
;
4583 idata
.do_all
= do_all
;
4585 libpc_handle_t lpch
= {
4586 .lpc_lib_handle
= g_zfs
,
4587 .lpc_ops
= &libzfs_config_ops
,
4588 .lpc_printerr
= B_TRUE
4590 pools
= zpool_search_import(&lpch
, &idata
);
4592 if (pools
!= NULL
&& pool_exists
&&
4593 (argc
== 1 || strcmp(argv
[0], argv
[1]) == 0)) {
4594 (void) fprintf(stderr
, gettext("cannot import '%s': "
4595 "a pool with that name already exists\n"),
4597 (void) fprintf(stderr
, gettext("use the form '%s "
4598 "<pool | id> <newpool>' to give it a new name\n"),
4601 } else if (pools
== NULL
&& pool_exists
) {
4602 (void) fprintf(stderr
, gettext("cannot import '%s': "
4603 "a pool with that name is already created/imported,\n"),
4605 (void) fprintf(stderr
, gettext("and no additional pools "
4606 "with that name were found\n"));
4608 } else if (pools
== NULL
) {
4610 (void) fprintf(stderr
, gettext("cannot import '%s': "
4611 "no such pool available\n"), argv
[0]);
4619 nvlist_free(policy
);
4625 err
= import_pools(pools
, props
, mntopts
, flags
,
4626 argc
>= 1 ? argv
[0] : NULL
, argc
>= 2 ? argv
[1] : NULL
, &idata
);
4629 * If we're using the cachefile and we failed to import, then
4630 * fallback to scanning the directory for pools that match
4631 * those in the cachefile.
4633 if (err
!= 0 && cachefile
!= NULL
) {
4634 (void) printf(gettext("cachefile import failed, retrying\n"));
4637 * We use the scan flag to gather the directories that exist
4638 * in the cachefile. If we need to fallback to searching for
4639 * the pool config, we will only search devices in these
4642 idata
.scan
= B_TRUE
;
4644 pools
= zpool_search_import(&lpch
, &idata
);
4646 err
= import_pools(pools
, props
, mntopts
, flags
,
4647 argc
>= 1 ? argv
[0] : NULL
, argc
>= 2 ? argv
[1] : NULL
,
4654 nvlist_free(policy
);
4658 return (err
? 1 : 0);
4662 * zpool sync [-f] [pool] ...
4664 * -f (undocumented) force uberblock (and config including zpool cache file)
4667 * Sync the specified pool(s).
4668 * Without arguments "zpool sync" will sync all pools.
4669 * This command initiates TXG sync(s) and will return after the TXG(s) commit.
4673 zpool_do_sync(int argc
, char **argv
)
4676 boolean_t force
= B_FALSE
;
4679 while ((ret
= getopt(argc
, argv
, "f")) != -1) {
4685 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4694 /* if argc == 0 we will execute zpool_sync_one on all pools */
4695 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
, ZFS_TYPE_POOL
,
4696 B_FALSE
, zpool_sync_one
, &force
);
4701 typedef struct iostat_cbdata
{
4705 boolean_t cb_verbose
;
4706 boolean_t cb_literal
;
4707 boolean_t cb_scripted
;
4708 zpool_list_t
*cb_list
;
4709 vdev_cmd_data_list_t
*vcdl
;
4710 vdev_cbdata_t cb_vdevs
;
4714 typedef struct name_and_columns
{
4715 const char *name
; /* Column name */
4716 unsigned int columns
; /* Center name to this number of columns */
4717 } name_and_columns_t
;
4719 #define IOSTAT_MAX_LABELS 15 /* Max number of labels on one line */
4721 static const name_and_columns_t iostat_top_labels
[][IOSTAT_MAX_LABELS
] =
4723 [IOS_DEFAULT
] = {{"capacity", 2}, {"operations", 2}, {"bandwidth", 2},
4725 [IOS_LATENCY
] = {{"total_wait", 2}, {"disk_wait", 2}, {"syncq_wait", 2},
4726 {"asyncq_wait", 2}, {"scrub", 1}, {"trim", 1}, {"rebuild", 1},
4728 [IOS_QUEUES
] = {{"syncq_read", 2}, {"syncq_write", 2},
4729 {"asyncq_read", 2}, {"asyncq_write", 2}, {"scrubq_read", 2},
4730 {"trimq_write", 2}, {"rebuildq_write", 2}, {NULL
}},
4731 [IOS_L_HISTO
] = {{"total_wait", 2}, {"disk_wait", 2}, {"syncq_wait", 2},
4732 {"asyncq_wait", 2}, {NULL
}},
4733 [IOS_RQ_HISTO
] = {{"sync_read", 2}, {"sync_write", 2},
4734 {"async_read", 2}, {"async_write", 2}, {"scrub", 2},
4735 {"trim", 2}, {"rebuild", 2}, {NULL
}},
4738 /* Shorthand - if "columns" field not set, default to 1 column */
4739 static const name_and_columns_t iostat_bottom_labels
[][IOSTAT_MAX_LABELS
] =
4741 [IOS_DEFAULT
] = {{"alloc"}, {"free"}, {"read"}, {"write"}, {"read"},
4743 [IOS_LATENCY
] = {{"read"}, {"write"}, {"read"}, {"write"}, {"read"},
4744 {"write"}, {"read"}, {"write"}, {"wait"}, {"wait"}, {"wait"},
4746 [IOS_QUEUES
] = {{"pend"}, {"activ"}, {"pend"}, {"activ"}, {"pend"},
4747 {"activ"}, {"pend"}, {"activ"}, {"pend"}, {"activ"},
4748 {"pend"}, {"activ"}, {"pend"}, {"activ"}, {NULL
}},
4749 [IOS_L_HISTO
] = {{"read"}, {"write"}, {"read"}, {"write"}, {"read"},
4750 {"write"}, {"read"}, {"write"}, {"scrub"}, {"trim"}, {"rebuild"},
4752 [IOS_RQ_HISTO
] = {{"ind"}, {"agg"}, {"ind"}, {"agg"}, {"ind"}, {"agg"},
4753 {"ind"}, {"agg"}, {"ind"}, {"agg"}, {"ind"}, {"agg"},
4754 {"ind"}, {"agg"}, {NULL
}},
4757 static const char *histo_to_title
[] = {
4758 [IOS_L_HISTO
] = "latency",
4759 [IOS_RQ_HISTO
] = "req_size",
4763 * Return the number of labels in a null-terminated name_and_columns_t
4768 label_array_len(const name_and_columns_t
*labels
)
4772 while (labels
[i
].name
)
4779 * Return the number of strings in a null-terminated string array.
4782 * const char foo[] = {"bar", "baz", NULL}
4787 str_array_len(const char *array
[])
4798 * Return a default column width for default/latency/queue columns. This does
4799 * not include histograms, which have their columns autosized.
4802 default_column_width(iostat_cbdata_t
*cb
, enum iostat_type type
)
4804 unsigned long column_width
= 5; /* Normal niceprint */
4805 static unsigned long widths
[] = {
4807 * Choose some sane default column sizes for printing the
4810 [IOS_DEFAULT
] = 15, /* 1PB capacity */
4811 [IOS_LATENCY
] = 10, /* 1B ns = 10sec */
4812 [IOS_QUEUES
] = 6, /* 1M queue entries */
4813 [IOS_L_HISTO
] = 10, /* 1B ns = 10sec */
4814 [IOS_RQ_HISTO
] = 6, /* 1M queue entries */
4818 column_width
= widths
[type
];
4820 return (column_width
);
4824 * Print the column labels, i.e:
4826 * capacity operations bandwidth
4827 * alloc free read write read write ...
4829 * If force_column_width is set, use it for the column width. If not set, use
4830 * the default column width.
4833 print_iostat_labels(iostat_cbdata_t
*cb
, unsigned int force_column_width
,
4834 const name_and_columns_t labels
[][IOSTAT_MAX_LABELS
])
4837 int text_start
, rw_column_width
, spaces_to_end
;
4838 uint64_t flags
= cb
->cb_flags
;
4840 unsigned int column_width
= force_column_width
;
4842 /* For each bit set in flags */
4843 for (f
= flags
; f
; f
&= ~(1ULL << idx
)) {
4844 idx
= lowbit64(f
) - 1;
4845 if (!force_column_width
)
4846 column_width
= default_column_width(cb
, idx
);
4847 /* Print our top labels centered over "read write" label. */
4848 for (i
= 0; i
< label_array_len(labels
[idx
]); i
++) {
4849 const char *name
= labels
[idx
][i
].name
;
4851 * We treat labels[][].columns == 0 as shorthand
4852 * for one column. It makes writing out the label
4853 * tables more concise.
4855 unsigned int columns
= MAX(1, labels
[idx
][i
].columns
);
4856 unsigned int slen
= strlen(name
);
4858 rw_column_width
= (column_width
* columns
) +
4859 (2 * (columns
- 1));
4861 text_start
= (int)((rw_column_width
) / columns
-
4866 printf(" "); /* Two spaces between columns */
4868 /* Space from beginning of column to label */
4869 for (s
= 0; s
< text_start
; s
++)
4874 /* Print space after label to end of column */
4875 spaces_to_end
= rw_column_width
- text_start
- slen
;
4876 if (spaces_to_end
< 0)
4879 for (s
= 0; s
< spaces_to_end
; s
++)
4887 * print_cmd_columns - Print custom column titles from -c
4889 * If the user specified the "zpool status|iostat -c" then print their custom
4890 * column titles in the header. For example, print_cmd_columns() would print
4891 * the " col1 col2" part of this:
4893 * $ zpool iostat -vc 'echo col1=val1; echo col2=val2'
4895 * capacity operations bandwidth
4896 * pool alloc free read write read write col1 col2
4897 * ---------- ----- ----- ----- ----- ----- ----- ---- ----
4898 * mypool 269K 1008M 0 0 107 946
4899 * mirror 269K 1008M 0 0 107 946
4900 * sdb - - 0 0 102 473 val1 val2
4901 * sdc - - 0 0 5 473 val1 val2
4902 * ---------- ----- ----- ----- ----- ----- ----- ---- ----
4905 print_cmd_columns(vdev_cmd_data_list_t
*vcdl
, int use_dashes
)
4908 vdev_cmd_data_t
*data
= &vcdl
->data
[0];
4910 if (vcdl
->count
== 0 || data
== NULL
)
4914 * Each vdev cmd should have the same column names unless the user did
4915 * something weird with their cmd. Just take the column names from the
4916 * first vdev and assume it works for all of them.
4918 for (i
= 0; i
< vcdl
->uniq_cols_cnt
; i
++) {
4921 for (j
= 0; j
< vcdl
->uniq_cols_width
[i
]; j
++)
4924 printf_color(ANSI_BOLD
, "%*s", vcdl
->uniq_cols_width
[i
],
4925 vcdl
->uniq_cols
[i
]);
4932 * Utility function to print out a line of dashes like:
4934 * -------------------------------- ----- ----- ----- ----- -----
4936 * ...or a dashed named-row line like:
4942 * @force_column_width If non-zero, use the value as the column width.
4943 * Otherwise use the default column widths.
4945 * @name: Print a dashed named-row line starting
4946 * with @name. Otherwise, print a regular
4950 print_iostat_dashes(iostat_cbdata_t
*cb
, unsigned int force_column_width
,
4954 unsigned int namewidth
;
4955 uint64_t flags
= cb
->cb_flags
;
4958 const name_and_columns_t
*labels
;
4962 if (cb
->cb_flags
& IOS_ANYHISTO_M
) {
4963 title
= histo_to_title
[IOS_HISTO_IDX(cb
->cb_flags
)];
4964 } else if (cb
->cb_vdevs
.cb_names_count
) {
4970 namewidth
= MAX(MAX(strlen(title
), cb
->cb_namewidth
),
4971 name
? strlen(name
) : 0);
4975 printf("%-*s", namewidth
, name
);
4977 for (i
= 0; i
< namewidth
; i
++)
4981 /* For each bit in flags */
4982 for (f
= flags
; f
; f
&= ~(1ULL << idx
)) {
4983 unsigned int column_width
;
4984 idx
= lowbit64(f
) - 1;
4985 if (force_column_width
)
4986 column_width
= force_column_width
;
4988 column_width
= default_column_width(cb
, idx
);
4990 labels
= iostat_bottom_labels
[idx
];
4991 for (i
= 0; i
< label_array_len(labels
); i
++) {
4993 printf(" %*s-", column_width
- 1, " ");
4995 printf(" %.*s", column_width
,
4996 "--------------------");
5003 print_iostat_separator_impl(iostat_cbdata_t
*cb
,
5004 unsigned int force_column_width
)
5006 print_iostat_dashes(cb
, force_column_width
, NULL
);
5010 print_iostat_separator(iostat_cbdata_t
*cb
)
5012 print_iostat_separator_impl(cb
, 0);
5016 print_iostat_header_impl(iostat_cbdata_t
*cb
, unsigned int force_column_width
,
5017 const char *histo_vdev_name
)
5019 unsigned int namewidth
;
5022 color_start(ANSI_BOLD
);
5024 if (cb
->cb_flags
& IOS_ANYHISTO_M
) {
5025 title
= histo_to_title
[IOS_HISTO_IDX(cb
->cb_flags
)];
5026 } else if (cb
->cb_vdevs
.cb_names_count
) {
5032 namewidth
= MAX(MAX(strlen(title
), cb
->cb_namewidth
),
5033 histo_vdev_name
? strlen(histo_vdev_name
) : 0);
5035 if (histo_vdev_name
)
5036 printf("%-*s", namewidth
, histo_vdev_name
);
5038 printf("%*s", namewidth
, "");
5041 print_iostat_labels(cb
, force_column_width
, iostat_top_labels
);
5044 printf("%-*s", namewidth
, title
);
5046 print_iostat_labels(cb
, force_column_width
, iostat_bottom_labels
);
5047 if (cb
->vcdl
!= NULL
)
5048 print_cmd_columns(cb
->vcdl
, 0);
5052 print_iostat_separator_impl(cb
, force_column_width
);
5054 if (cb
->vcdl
!= NULL
)
5055 print_cmd_columns(cb
->vcdl
, 1);
5063 print_iostat_header(iostat_cbdata_t
*cb
)
5065 print_iostat_header_impl(cb
, 0, NULL
);
5069 * Prints a size string (i.e. 120M) with the suffix ("M") colored
5070 * by order of magnitude. Uses column_size to add padding.
5073 print_stat_color(const char *statbuf
, unsigned int column_size
)
5076 size_t len
= strlen(statbuf
);
5077 while (len
< column_size
) {
5081 if (*statbuf
== '0') {
5082 color_start(ANSI_GRAY
);
5085 for (; *statbuf
; statbuf
++) {
5086 if (*statbuf
== 'K') color_start(ANSI_GREEN
);
5087 else if (*statbuf
== 'M') color_start(ANSI_YELLOW
);
5088 else if (*statbuf
== 'G') color_start(ANSI_RED
);
5089 else if (*statbuf
== 'T') color_start(ANSI_BOLD_BLUE
);
5090 else if (*statbuf
== 'P') color_start(ANSI_MAGENTA
);
5091 else if (*statbuf
== 'E') color_start(ANSI_CYAN
);
5092 fputc(*statbuf
, stdout
);
5093 if (--column_size
<= 0)
5101 * Display a single statistic.
5104 print_one_stat(uint64_t value
, enum zfs_nicenum_format format
,
5105 unsigned int column_size
, boolean_t scripted
)
5109 zfs_nicenum_format(value
, buf
, sizeof (buf
), format
);
5112 printf("\t%s", buf
);
5114 print_stat_color(buf
, column_size
);
5118 * Calculate the default vdev stats
5120 * Subtract oldvs from newvs, apply a scaling factor, and save the resulting
5121 * stats into calcvs.
5124 calc_default_iostats(vdev_stat_t
*oldvs
, vdev_stat_t
*newvs
,
5125 vdev_stat_t
*calcvs
)
5129 memcpy(calcvs
, newvs
, sizeof (*calcvs
));
5130 for (i
= 0; i
< ARRAY_SIZE(calcvs
->vs_ops
); i
++)
5131 calcvs
->vs_ops
[i
] = (newvs
->vs_ops
[i
] - oldvs
->vs_ops
[i
]);
5133 for (i
= 0; i
< ARRAY_SIZE(calcvs
->vs_bytes
); i
++)
5134 calcvs
->vs_bytes
[i
] = (newvs
->vs_bytes
[i
] - oldvs
->vs_bytes
[i
]);
5138 * Internal representation of the extended iostats data.
5140 * The extended iostat stats are exported in nvlists as either uint64_t arrays
5141 * or single uint64_t's. We make both look like arrays to make them easier
5142 * to process. In order to make single uint64_t's look like arrays, we set
5143 * __data to the stat data, and then set *data = &__data with count = 1. Then,
5144 * we can just use *data and count.
5148 uint_t count
; /* Number of entries in data[] */
5149 uint64_t __data
; /* Only used when data is a single uint64_t */
5153 stat_histo_max(struct stat_array
*nva
, unsigned int len
)
5157 for (i
= 0; i
< len
; i
++)
5158 max
= MAX(max
, array64_max(nva
[i
].data
, nva
[i
].count
));
5164 * Helper function to lookup a uint64_t array or uint64_t value and store its
5165 * data as a stat_array. If the nvpair is a single uint64_t value, then we make
5166 * it look like a one element array to make it easier to process.
5169 nvpair64_to_stat_array(nvlist_t
*nvl
, const char *name
,
5170 struct stat_array
*nva
)
5175 verify(nvlist_lookup_nvpair(nvl
, name
, &tmp
) == 0);
5176 switch (nvpair_type(tmp
)) {
5177 case DATA_TYPE_UINT64_ARRAY
:
5178 ret
= nvpair_value_uint64_array(tmp
, &nva
->data
, &nva
->count
);
5180 case DATA_TYPE_UINT64
:
5181 ret
= nvpair_value_uint64(tmp
, &nva
->__data
);
5182 nva
->data
= &nva
->__data
;
5186 /* Not a uint64_t */
5195 * Given a list of nvlist names, look up the extended stats in newnv and oldnv,
5196 * subtract them, and return the results in a newly allocated stat_array.
5197 * You must free the returned array after you are done with it with
5198 * free_calc_stats().
5200 * Additionally, you can set "oldnv" to NULL if you simply want the newnv
5203 static struct stat_array
*
5204 calc_and_alloc_stats_ex(const char **names
, unsigned int len
, nvlist_t
*oldnv
,
5207 nvlist_t
*oldnvx
= NULL
, *newnvx
;
5208 struct stat_array
*oldnva
, *newnva
, *calcnva
;
5210 unsigned int alloc_size
= (sizeof (struct stat_array
)) * len
;
5212 /* Extract our extended stats nvlist from the main list */
5213 verify(nvlist_lookup_nvlist(newnv
, ZPOOL_CONFIG_VDEV_STATS_EX
,
5216 verify(nvlist_lookup_nvlist(oldnv
, ZPOOL_CONFIG_VDEV_STATS_EX
,
5220 newnva
= safe_malloc(alloc_size
);
5221 oldnva
= safe_malloc(alloc_size
);
5222 calcnva
= safe_malloc(alloc_size
);
5224 for (j
= 0; j
< len
; j
++) {
5225 verify(nvpair64_to_stat_array(newnvx
, names
[j
],
5227 calcnva
[j
].count
= newnva
[j
].count
;
5228 alloc_size
= calcnva
[j
].count
* sizeof (calcnva
[j
].data
[0]);
5229 calcnva
[j
].data
= safe_malloc(alloc_size
);
5230 memcpy(calcnva
[j
].data
, newnva
[j
].data
, alloc_size
);
5233 verify(nvpair64_to_stat_array(oldnvx
, names
[j
],
5235 for (i
= 0; i
< oldnva
[j
].count
; i
++)
5236 calcnva
[j
].data
[i
] -= oldnva
[j
].data
[i
];
5245 free_calc_stats(struct stat_array
*nva
, unsigned int len
)
5248 for (i
= 0; i
< len
; i
++)
5255 print_iostat_histo(struct stat_array
*nva
, unsigned int len
,
5256 iostat_cbdata_t
*cb
, unsigned int column_width
, unsigned int namewidth
,
5262 enum zfs_nicenum_format format
;
5263 unsigned int buckets
;
5264 unsigned int start_bucket
;
5267 format
= ZFS_NICENUM_RAW
;
5269 format
= ZFS_NICENUM_1024
;
5271 /* All these histos are the same size, so just use nva[0].count */
5272 buckets
= nva
[0].count
;
5274 if (cb
->cb_flags
& IOS_RQ_HISTO_M
) {
5275 /* Start at 512 - req size should never be lower than this */
5281 for (j
= start_bucket
; j
< buckets
; j
++) {
5282 /* Print histogram bucket label */
5283 if (cb
->cb_flags
& IOS_L_HISTO_M
) {
5284 /* Ending range of this bucket */
5285 val
= (1UL << (j
+ 1)) - 1;
5286 zfs_nicetime(val
, buf
, sizeof (buf
));
5288 /* Request size (starting range of bucket) */
5290 zfs_nicenum(val
, buf
, sizeof (buf
));
5293 if (cb
->cb_scripted
)
5294 printf("%llu", (u_longlong_t
)val
);
5296 printf("%-*s", namewidth
, buf
);
5298 /* Print the values on the line */
5299 for (i
= 0; i
< len
; i
++) {
5300 print_one_stat(nva
[i
].data
[j
] * scale
, format
,
5301 column_width
, cb
->cb_scripted
);
5308 print_solid_separator(unsigned int length
)
5316 print_iostat_histos(iostat_cbdata_t
*cb
, nvlist_t
*oldnv
,
5317 nvlist_t
*newnv
, double scale
, const char *name
)
5319 unsigned int column_width
;
5320 unsigned int namewidth
;
5321 unsigned int entire_width
;
5322 enum iostat_type type
;
5323 struct stat_array
*nva
;
5325 unsigned int names_len
;
5327 /* What type of histo are we? */
5328 type
= IOS_HISTO_IDX(cb
->cb_flags
);
5330 /* Get NULL-terminated array of nvlist names for our histo */
5331 names
= vsx_type_to_nvlist
[type
];
5332 names_len
= str_array_len(names
); /* num of names */
5334 nva
= calc_and_alloc_stats_ex(names
, names_len
, oldnv
, newnv
);
5336 if (cb
->cb_literal
) {
5337 column_width
= MAX(5,
5338 (unsigned int) log10(stat_histo_max(nva
, names_len
)) + 1);
5343 namewidth
= MAX(cb
->cb_namewidth
,
5344 strlen(histo_to_title
[IOS_HISTO_IDX(cb
->cb_flags
)]));
5347 * Calculate the entire line width of what we're printing. The
5348 * +2 is for the two spaces between columns:
5352 /* |___| <---------- column_width */
5354 /* |__________| <--- entire_width */
5356 entire_width
= namewidth
+ (column_width
+ 2) *
5357 label_array_len(iostat_bottom_labels
[type
]);
5359 if (cb
->cb_scripted
)
5360 printf("%s\n", name
);
5362 print_iostat_header_impl(cb
, column_width
, name
);
5364 print_iostat_histo(nva
, names_len
, cb
, column_width
,
5367 free_calc_stats(nva
, names_len
);
5368 if (!cb
->cb_scripted
)
5369 print_solid_separator(entire_width
);
5373 * Calculate the average latency of a power-of-two latency histogram
5376 single_histo_average(uint64_t *histo
, unsigned int buckets
)
5379 uint64_t count
= 0, total
= 0;
5381 for (i
= 0; i
< buckets
; i
++) {
5383 * Our buckets are power-of-two latency ranges. Use the
5384 * midpoint latency of each bucket to calculate the average.
5392 if (histo
[i
] != 0) {
5393 total
+= histo
[i
] * (((1UL << i
) + ((1UL << i
)/2)));
5398 /* Prevent divide by zero */
5399 return (count
== 0 ? 0 : total
/ count
);
5403 print_iostat_queues(iostat_cbdata_t
*cb
, nvlist_t
*newnv
)
5405 const char *names
[] = {
5406 ZPOOL_CONFIG_VDEV_SYNC_R_PEND_QUEUE
,
5407 ZPOOL_CONFIG_VDEV_SYNC_R_ACTIVE_QUEUE
,
5408 ZPOOL_CONFIG_VDEV_SYNC_W_PEND_QUEUE
,
5409 ZPOOL_CONFIG_VDEV_SYNC_W_ACTIVE_QUEUE
,
5410 ZPOOL_CONFIG_VDEV_ASYNC_R_PEND_QUEUE
,
5411 ZPOOL_CONFIG_VDEV_ASYNC_R_ACTIVE_QUEUE
,
5412 ZPOOL_CONFIG_VDEV_ASYNC_W_PEND_QUEUE
,
5413 ZPOOL_CONFIG_VDEV_ASYNC_W_ACTIVE_QUEUE
,
5414 ZPOOL_CONFIG_VDEV_SCRUB_PEND_QUEUE
,
5415 ZPOOL_CONFIG_VDEV_SCRUB_ACTIVE_QUEUE
,
5416 ZPOOL_CONFIG_VDEV_TRIM_PEND_QUEUE
,
5417 ZPOOL_CONFIG_VDEV_TRIM_ACTIVE_QUEUE
,
5418 ZPOOL_CONFIG_VDEV_REBUILD_PEND_QUEUE
,
5419 ZPOOL_CONFIG_VDEV_REBUILD_ACTIVE_QUEUE
,
5422 struct stat_array
*nva
;
5424 unsigned int column_width
= default_column_width(cb
, IOS_QUEUES
);
5425 enum zfs_nicenum_format format
;
5427 nva
= calc_and_alloc_stats_ex(names
, ARRAY_SIZE(names
), NULL
, newnv
);
5430 format
= ZFS_NICENUM_RAW
;
5432 format
= ZFS_NICENUM_1024
;
5434 for (int i
= 0; i
< ARRAY_SIZE(names
); i
++) {
5435 uint64_t val
= nva
[i
].data
[0];
5436 print_one_stat(val
, format
, column_width
, cb
->cb_scripted
);
5439 free_calc_stats(nva
, ARRAY_SIZE(names
));
5443 print_iostat_latency(iostat_cbdata_t
*cb
, nvlist_t
*oldnv
,
5448 const char *names
[] = {
5449 ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO
,
5450 ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO
,
5451 ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO
,
5452 ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO
,
5453 ZPOOL_CONFIG_VDEV_SYNC_R_LAT_HISTO
,
5454 ZPOOL_CONFIG_VDEV_SYNC_W_LAT_HISTO
,
5455 ZPOOL_CONFIG_VDEV_ASYNC_R_LAT_HISTO
,
5456 ZPOOL_CONFIG_VDEV_ASYNC_W_LAT_HISTO
,
5457 ZPOOL_CONFIG_VDEV_SCRUB_LAT_HISTO
,
5458 ZPOOL_CONFIG_VDEV_TRIM_LAT_HISTO
,
5459 ZPOOL_CONFIG_VDEV_REBUILD_LAT_HISTO
,
5461 struct stat_array
*nva
;
5463 unsigned int column_width
= default_column_width(cb
, IOS_LATENCY
);
5464 enum zfs_nicenum_format format
;
5466 nva
= calc_and_alloc_stats_ex(names
, ARRAY_SIZE(names
), oldnv
, newnv
);
5469 format
= ZFS_NICENUM_RAWTIME
;
5471 format
= ZFS_NICENUM_TIME
;
5473 /* Print our avg latencies on the line */
5474 for (i
= 0; i
< ARRAY_SIZE(names
); i
++) {
5475 /* Compute average latency for a latency histo */
5476 val
= single_histo_average(nva
[i
].data
, nva
[i
].count
);
5477 print_one_stat(val
, format
, column_width
, cb
->cb_scripted
);
5479 free_calc_stats(nva
, ARRAY_SIZE(names
));
5483 * Print default statistics (capacity/operations/bandwidth)
5486 print_iostat_default(vdev_stat_t
*vs
, iostat_cbdata_t
*cb
, double scale
)
5488 unsigned int column_width
= default_column_width(cb
, IOS_DEFAULT
);
5489 enum zfs_nicenum_format format
;
5490 char na
; /* char to print for "not applicable" values */
5492 if (cb
->cb_literal
) {
5493 format
= ZFS_NICENUM_RAW
;
5496 format
= ZFS_NICENUM_1024
;
5500 /* only toplevel vdevs have capacity stats */
5501 if (vs
->vs_space
== 0) {
5502 if (cb
->cb_scripted
)
5503 printf("\t%c\t%c", na
, na
);
5505 printf(" %*c %*c", column_width
, na
, column_width
,
5508 print_one_stat(vs
->vs_alloc
, format
, column_width
,
5510 print_one_stat(vs
->vs_space
- vs
->vs_alloc
, format
,
5511 column_width
, cb
->cb_scripted
);
5514 print_one_stat((uint64_t)(vs
->vs_ops
[ZIO_TYPE_READ
] * scale
),
5515 format
, column_width
, cb
->cb_scripted
);
5516 print_one_stat((uint64_t)(vs
->vs_ops
[ZIO_TYPE_WRITE
] * scale
),
5517 format
, column_width
, cb
->cb_scripted
);
5518 print_one_stat((uint64_t)(vs
->vs_bytes
[ZIO_TYPE_READ
] * scale
),
5519 format
, column_width
, cb
->cb_scripted
);
5520 print_one_stat((uint64_t)(vs
->vs_bytes
[ZIO_TYPE_WRITE
] * scale
),
5521 format
, column_width
, cb
->cb_scripted
);
5524 static const char *const class_name
[] = {
5525 VDEV_ALLOC_BIAS_DEDUP
,
5526 VDEV_ALLOC_BIAS_SPECIAL
,
5527 VDEV_ALLOC_CLASS_LOGS
5531 * Print out all the statistics for the given vdev. This can either be the
5532 * toplevel configuration, or called recursively. If 'name' is NULL, then this
5533 * is a verbose output, and we don't want to display the toplevel pool stats.
5535 * Returns the number of stat lines printed.
5538 print_vdev_stats(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*oldnv
,
5539 nvlist_t
*newnv
, iostat_cbdata_t
*cb
, int depth
)
5541 nvlist_t
**oldchild
, **newchild
;
5542 uint_t c
, children
, oldchildren
;
5543 vdev_stat_t
*oldvs
, *newvs
, *calcvs
;
5544 vdev_stat_t zerovs
= { 0 };
5551 if (strcmp(name
, VDEV_TYPE_INDIRECT
) == 0)
5554 calcvs
= safe_malloc(sizeof (*calcvs
));
5556 if (oldnv
!= NULL
) {
5557 verify(nvlist_lookup_uint64_array(oldnv
,
5558 ZPOOL_CONFIG_VDEV_STATS
, (uint64_t **)&oldvs
, &c
) == 0);
5563 /* Do we only want to see a specific vdev? */
5564 for (i
= 0; i
< cb
->cb_vdevs
.cb_names_count
; i
++) {
5565 /* Yes we do. Is this the vdev? */
5566 if (strcmp(name
, cb
->cb_vdevs
.cb_names
[i
]) == 0) {
5568 * This is our vdev. Since it is the only vdev we
5569 * will be displaying, make depth = 0 so that it
5570 * doesn't get indented.
5577 if (cb
->cb_vdevs
.cb_names_count
&& (i
== cb
->cb_vdevs
.cb_names_count
)) {
5578 /* Couldn't match the name */
5583 verify(nvlist_lookup_uint64_array(newnv
, ZPOOL_CONFIG_VDEV_STATS
,
5584 (uint64_t **)&newvs
, &c
) == 0);
5587 * Print the vdev name unless it's is a histogram. Histograms
5588 * display the vdev name in the header itself.
5590 if (!(cb
->cb_flags
& IOS_ANYHISTO_M
)) {
5591 if (cb
->cb_scripted
) {
5594 if (strlen(name
) + depth
> cb
->cb_namewidth
)
5595 (void) printf("%*s%s", depth
, "", name
);
5597 (void) printf("%*s%s%*s", depth
, "", name
,
5598 (int)(cb
->cb_namewidth
- strlen(name
) -
5603 /* Calculate our scaling factor */
5604 tdelta
= newvs
->vs_timestamp
- oldvs
->vs_timestamp
;
5605 if ((oldvs
->vs_timestamp
== 0) && (cb
->cb_flags
& IOS_ANYHISTO_M
)) {
5607 * If we specify printing histograms with no time interval, then
5608 * print the histogram numbers over the entire lifetime of the
5616 scale
= (double)NANOSEC
/ tdelta
;
5619 if (cb
->cb_flags
& IOS_DEFAULT_M
) {
5620 calc_default_iostats(oldvs
, newvs
, calcvs
);
5621 print_iostat_default(calcvs
, cb
, scale
);
5623 if (cb
->cb_flags
& IOS_LATENCY_M
)
5624 print_iostat_latency(cb
, oldnv
, newnv
);
5625 if (cb
->cb_flags
& IOS_QUEUES_M
)
5626 print_iostat_queues(cb
, newnv
);
5627 if (cb
->cb_flags
& IOS_ANYHISTO_M
) {
5629 print_iostat_histos(cb
, oldnv
, newnv
, scale
, name
);
5632 if (cb
->vcdl
!= NULL
) {
5634 if (nvlist_lookup_string(newnv
, ZPOOL_CONFIG_PATH
,
5637 zpool_print_cmd(cb
->vcdl
, zpool_get_name(zhp
), path
);
5641 if (!(cb
->cb_flags
& IOS_ANYHISTO_M
))
5650 if (!cb
->cb_verbose
)
5653 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_CHILDREN
,
5654 &newchild
, &children
) != 0)
5658 if (nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_CHILDREN
,
5659 &oldchild
, &oldchildren
) != 0)
5662 children
= MIN(oldchildren
, children
);
5666 * print normal top-level devices
5668 for (c
= 0; c
< children
; c
++) {
5669 uint64_t ishole
= B_FALSE
, islog
= B_FALSE
;
5671 (void) nvlist_lookup_uint64(newchild
[c
], ZPOOL_CONFIG_IS_HOLE
,
5674 (void) nvlist_lookup_uint64(newchild
[c
], ZPOOL_CONFIG_IS_LOG
,
5677 if (ishole
|| islog
)
5680 if (nvlist_exists(newchild
[c
], ZPOOL_CONFIG_ALLOCATION_BIAS
))
5683 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
5684 cb
->cb_vdevs
.cb_name_flags
| VDEV_NAME_TYPE_ID
);
5685 ret
+= print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
] : NULL
,
5686 newchild
[c
], cb
, depth
+ 2);
5691 * print all other top-level devices
5693 for (uint_t n
= 0; n
< ARRAY_SIZE(class_name
); n
++) {
5694 boolean_t printed
= B_FALSE
;
5696 for (c
= 0; c
< children
; c
++) {
5697 uint64_t islog
= B_FALSE
;
5698 const char *bias
= NULL
;
5699 const char *type
= NULL
;
5701 (void) nvlist_lookup_uint64(newchild
[c
],
5702 ZPOOL_CONFIG_IS_LOG
, &islog
);
5704 bias
= VDEV_ALLOC_CLASS_LOGS
;
5706 (void) nvlist_lookup_string(newchild
[c
],
5707 ZPOOL_CONFIG_ALLOCATION_BIAS
, &bias
);
5708 (void) nvlist_lookup_string(newchild
[c
],
5709 ZPOOL_CONFIG_TYPE
, &type
);
5711 if (bias
== NULL
|| strcmp(bias
, class_name
[n
]) != 0)
5713 if (!islog
&& strcmp(type
, VDEV_TYPE_INDIRECT
) == 0)
5717 if ((!(cb
->cb_flags
& IOS_ANYHISTO_M
)) &&
5719 !cb
->cb_vdevs
.cb_names
) {
5720 print_iostat_dashes(cb
, 0,
5727 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
5728 cb
->cb_vdevs
.cb_name_flags
| VDEV_NAME_TYPE_ID
);
5729 ret
+= print_vdev_stats(zhp
, vname
, oldnv
?
5730 oldchild
[c
] : NULL
, newchild
[c
], cb
, depth
+ 2);
5736 * Include level 2 ARC devices in iostat output
5738 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_L2CACHE
,
5739 &newchild
, &children
) != 0)
5743 if (nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_L2CACHE
,
5744 &oldchild
, &oldchildren
) != 0)
5747 children
= MIN(oldchildren
, children
);
5751 if ((!(cb
->cb_flags
& IOS_ANYHISTO_M
)) && !cb
->cb_scripted
&&
5752 !cb
->cb_vdevs
.cb_names
) {
5753 print_iostat_dashes(cb
, 0, "cache");
5757 for (c
= 0; c
< children
; c
++) {
5758 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
5759 cb
->cb_vdevs
.cb_name_flags
);
5760 ret
+= print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
]
5761 : NULL
, newchild
[c
], cb
, depth
+ 2);
5770 refresh_iostat(zpool_handle_t
*zhp
, void *data
)
5772 iostat_cbdata_t
*cb
= data
;
5776 * If the pool has disappeared, remove it from the list and continue.
5778 if (zpool_refresh_stats(zhp
, &missing
) != 0)
5782 pool_list_remove(cb
->cb_list
, zhp
);
5788 * Callback to print out the iostats for the given pool.
5791 print_iostat(zpool_handle_t
*zhp
, void *data
)
5793 iostat_cbdata_t
*cb
= data
;
5794 nvlist_t
*oldconfig
, *newconfig
;
5795 nvlist_t
*oldnvroot
, *newnvroot
;
5798 newconfig
= zpool_get_config(zhp
, &oldconfig
);
5800 if (cb
->cb_iteration
== 1)
5803 verify(nvlist_lookup_nvlist(newconfig
, ZPOOL_CONFIG_VDEV_TREE
,
5806 if (oldconfig
== NULL
)
5809 verify(nvlist_lookup_nvlist(oldconfig
, ZPOOL_CONFIG_VDEV_TREE
,
5812 ret
= print_vdev_stats(zhp
, zpool_get_name(zhp
), oldnvroot
, newnvroot
,
5814 if ((ret
!= 0) && !(cb
->cb_flags
& IOS_ANYHISTO_M
) &&
5815 !cb
->cb_scripted
&& cb
->cb_verbose
&&
5816 !cb
->cb_vdevs
.cb_names_count
) {
5817 print_iostat_separator(cb
);
5818 if (cb
->vcdl
!= NULL
) {
5819 print_cmd_columns(cb
->vcdl
, 1);
5834 if (isatty(STDOUT_FILENO
)) {
5835 error
= ioctl(STDOUT_FILENO
, TIOCGWINSZ
, &ws
);
5837 columns
= ws
.ws_col
;
5846 * Return the required length of the pool/vdev name column. The minimum
5847 * allowed width and output formatting flags must be provided.
5850 get_namewidth(zpool_handle_t
*zhp
, int min_width
, int flags
, boolean_t verbose
)
5852 nvlist_t
*config
, *nvroot
;
5853 int width
= min_width
;
5855 if ((config
= zpool_get_config(zhp
, NULL
)) != NULL
) {
5856 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
5858 size_t poolname_len
= strlen(zpool_get_name(zhp
));
5859 if (verbose
== B_FALSE
) {
5860 width
= MAX(poolname_len
, min_width
);
5862 width
= MAX(poolname_len
,
5863 max_width(zhp
, nvroot
, 0, min_width
, flags
));
5871 * Parse the input string, get the 'interval' and 'count' value if there is one.
5874 get_interval_count(int *argcp
, char **argv
, float *iv
,
5878 unsigned long count
= 0;
5882 * Determine if the last argument is an integer or a pool name
5884 if (argc
> 0 && zfs_isnumber(argv
[argc
- 1])) {
5888 interval
= strtof(argv
[argc
- 1], &end
);
5890 if (*end
== '\0' && errno
== 0) {
5891 if (interval
== 0) {
5892 (void) fprintf(stderr
, gettext(
5893 "interval cannot be zero\n"));
5897 * Ignore the last parameter
5902 * If this is not a valid number, just plow on. The
5903 * user will get a more informative error message later
5911 * If the last argument is also an integer, then we have both a count
5914 if (argc
> 0 && zfs_isnumber(argv
[argc
- 1])) {
5919 interval
= strtof(argv
[argc
- 1], &end
);
5921 if (*end
== '\0' && errno
== 0) {
5922 if (interval
== 0) {
5923 (void) fprintf(stderr
, gettext(
5924 "interval cannot be zero\n"));
5929 * Ignore the last parameter
5943 get_timestamp_arg(char c
)
5946 timestamp_fmt
= UDATE
;
5948 timestamp_fmt
= DDATE
;
5954 * Return stat flags that are supported by all pools by both the module and
5955 * zpool iostat. "*data" should be initialized to all 0xFFs before running.
5956 * It will get ANDed down until only the flags that are supported on all pools
5960 get_stat_flags_cb(zpool_handle_t
*zhp
, void *data
)
5962 uint64_t *mask
= data
;
5963 nvlist_t
*config
, *nvroot
, *nvx
;
5967 config
= zpool_get_config(zhp
, NULL
);
5968 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
5971 /* Default stats are always supported, but for completeness.. */
5972 if (nvlist_exists(nvroot
, ZPOOL_CONFIG_VDEV_STATS
))
5973 flags
|= IOS_DEFAULT_M
;
5975 /* Get our extended stats nvlist from the main list */
5976 if (nvlist_lookup_nvlist(nvroot
, ZPOOL_CONFIG_VDEV_STATS_EX
,
5979 * No extended stats; they're probably running an older
5980 * module. No big deal, we support that too.
5985 /* For each extended stat, make sure all its nvpairs are supported */
5986 for (j
= 0; j
< ARRAY_SIZE(vsx_type_to_nvlist
); j
++) {
5987 if (!vsx_type_to_nvlist
[j
][0])
5990 /* Start off by assuming the flag is supported, then check */
5991 flags
|= (1ULL << j
);
5992 for (i
= 0; vsx_type_to_nvlist
[j
][i
]; i
++) {
5993 if (!nvlist_exists(nvx
, vsx_type_to_nvlist
[j
][i
])) {
5994 /* flag isn't supported */
5995 flags
= flags
& ~(1ULL << j
);
6001 *mask
= *mask
& flags
;
6006 * Return a bitmask of stats that are supported on all pools by both the module
6010 get_stat_flags(zpool_list_t
*list
)
6015 * get_stat_flags_cb() will lop off bits from "mask" until only the
6016 * flags that are supported on all pools remain.
6018 pool_list_iter(list
, B_FALSE
, get_stat_flags_cb
, &mask
);
6023 * Return 1 if cb_data->cb_names[0] is this vdev's name, 0 otherwise.
6026 is_vdev_cb(void *zhp_data
, nvlist_t
*nv
, void *cb_data
)
6029 vdev_cbdata_t
*cb
= cb_data
;
6030 zpool_handle_t
*zhp
= zhp_data
;
6032 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
, &guid
) != 0)
6035 return (guid
== zpool_vdev_path_to_guid(zhp
, cb
->cb_names
[0]));
6039 * Returns 1 if cb_data->cb_names[0] is a vdev name, 0 otherwise.
6042 is_vdev(zpool_handle_t
*zhp
, void *cb_data
)
6044 return (for_each_vdev(zhp
, is_vdev_cb
, cb_data
));
6048 * Check if vdevs are in a pool
6050 * Return 1 if all argv[] strings are vdev names in pool "pool_name". Otherwise
6051 * return 0. If pool_name is NULL, then search all pools.
6054 are_vdevs_in_pool(int argc
, char **argv
, char *pool_name
,
6062 if ((argc
== 0) || !*argv
)
6068 /* Temporarily hijack cb_names for a second... */
6069 tmp_name
= cb
->cb_names
;
6071 /* Go though our list of prospective vdev names */
6072 for (i
= 0; i
< argc
; i
++) {
6073 cb
->cb_names
= argv
+ i
;
6075 /* Is this name a vdev in our pools? */
6076 ret
= for_each_pool(pool_count
, &pool_name
, B_TRUE
, NULL
,
6077 ZFS_TYPE_POOL
, B_FALSE
, is_vdev
, cb
);
6084 cb
->cb_names
= tmp_name
;
6090 is_pool_cb(zpool_handle_t
*zhp
, void *data
)
6093 if (strcmp(name
, zpool_get_name(zhp
)) == 0)
6100 * Do we have a pool named *name? If so, return 1, otherwise 0.
6105 return (for_each_pool(0, NULL
, B_TRUE
, NULL
, ZFS_TYPE_POOL
, B_FALSE
,
6109 /* Are all our argv[] strings pool names? If so return 1, 0 otherwise. */
6111 are_all_pools(int argc
, char **argv
)
6113 if ((argc
== 0) || !*argv
)
6117 if (!is_pool(argv
[argc
]))
6124 * Helper function to print out vdev/pool names we can't resolve. Used for an
6128 error_list_unresolved_vdevs(int argc
, char **argv
, char *pool_name
,
6134 for (i
= 0; i
< argc
; i
++) {
6138 str
= gettext("pool");
6139 else if (are_vdevs_in_pool(1, &name
, pool_name
, cb
))
6140 str
= gettext("vdev in this pool");
6141 else if (are_vdevs_in_pool(1, &name
, NULL
, cb
))
6142 str
= gettext("vdev in another pool");
6144 str
= gettext("unknown");
6146 fprintf(stderr
, "\t%s (%s)\n", name
, str
);
6151 * Same as get_interval_count(), but with additional checks to not misinterpret
6152 * guids as interval/count values. Assumes VDEV_NAME_GUID is set in
6153 * cb.cb_vdevs.cb_name_flags.
6156 get_interval_count_filter_guids(int *argc
, char **argv
, float *interval
,
6157 unsigned long *count
, iostat_cbdata_t
*cb
)
6159 char **tmpargv
= argv
;
6160 int argc_for_interval
= 0;
6162 /* Is the last arg an interval value? Or a guid? */
6163 if (*argc
>= 1 && !are_vdevs_in_pool(1, &argv
[*argc
- 1], NULL
,
6166 * The last arg is not a guid, so it's probably an
6169 argc_for_interval
++;
6172 !are_vdevs_in_pool(1, &argv
[*argc
- 2], NULL
,
6175 * The 2nd to last arg is not a guid, so it's probably
6176 * an interval value.
6178 argc_for_interval
++;
6182 /* Point to our list of possible intervals */
6183 tmpargv
= &argv
[*argc
- argc_for_interval
];
6185 *argc
= *argc
- argc_for_interval
;
6186 get_interval_count(&argc_for_interval
, tmpargv
,
6191 * Terminal height, in rows. Returns -1 if stdout is not connected to a TTY or
6192 * if we were unable to determine its size.
6195 terminal_height(void)
6199 if (isatty(STDOUT_FILENO
) == 0)
6202 if (ioctl(STDOUT_FILENO
, TIOCGWINSZ
, &win
) != -1 && win
.ws_row
> 0)
6203 return (win
.ws_row
);
6209 * Run one of the zpool status/iostat -c scripts with the help (-h) option and
6212 * name: Short name of the script ('iostat').
6213 * path: Full path to the script ('/usr/local/etc/zfs/zpool.d/iostat');
6216 print_zpool_script_help(char *name
, char *path
)
6218 char *argv
[] = {path
, (char *)"-h", NULL
};
6219 char **lines
= NULL
;
6223 rc
= libzfs_run_process_get_stdout_nopath(path
, argv
, NULL
, &lines
,
6225 if (rc
!= 0 || lines
== NULL
|| lines_cnt
<= 0) {
6227 libzfs_free_str_array(lines
, lines_cnt
);
6231 for (int i
= 0; i
< lines_cnt
; i
++)
6232 if (!is_blank_str(lines
[i
]))
6233 printf(" %-14s %s\n", name
, lines
[i
]);
6235 libzfs_free_str_array(lines
, lines_cnt
);
6239 * Go though the zpool status/iostat -c scripts in the user's path, run their
6240 * help option (-h), and print out the results.
6243 print_zpool_dir_scripts(char *dirpath
)
6247 char fullpath
[MAXPATHLEN
];
6248 struct stat dir_stat
;
6250 if ((dir
= opendir(dirpath
)) != NULL
) {
6251 /* print all the files and directories within directory */
6252 while ((ent
= readdir(dir
)) != NULL
) {
6253 if (snprintf(fullpath
, sizeof (fullpath
), "%s/%s",
6254 dirpath
, ent
->d_name
) >= sizeof (fullpath
)) {
6255 (void) fprintf(stderr
,
6256 gettext("internal error: "
6257 "ZPOOL_SCRIPTS_PATH too large.\n"));
6261 /* Print the scripts */
6262 if (stat(fullpath
, &dir_stat
) == 0)
6263 if (dir_stat
.st_mode
& S_IXUSR
&&
6264 S_ISREG(dir_stat
.st_mode
))
6265 print_zpool_script_help(ent
->d_name
,
6273 * Print out help text for all zpool status/iostat -c scripts.
6276 print_zpool_script_list(const char *subcommand
)
6278 char *dir
, *sp
, *tmp
;
6280 printf(gettext("Available 'zpool %s -c' commands:\n"), subcommand
);
6282 sp
= zpool_get_cmd_search_path();
6286 for (dir
= strtok_r(sp
, ":", &tmp
);
6288 dir
= strtok_r(NULL
, ":", &tmp
))
6289 print_zpool_dir_scripts(dir
);
6295 * Set the minimum pool/vdev name column width. The width must be at least 10,
6296 * but may be as large as the column width - 42 so it still fits on one line.
6297 * NOTE: 42 is the width of the default capacity/operations/bandwidth output
6300 get_namewidth_iostat(zpool_handle_t
*zhp
, void *data
)
6302 iostat_cbdata_t
*cb
= data
;
6303 int width
, available_width
;
6306 * get_namewidth() returns the maximum width of any name in that column
6307 * for any pool/vdev/device line that will be output.
6309 width
= get_namewidth(zhp
, cb
->cb_namewidth
,
6310 cb
->cb_vdevs
.cb_name_flags
| VDEV_NAME_TYPE_ID
, cb
->cb_verbose
);
6313 * The width we are calculating is the width of the header and also the
6314 * padding width for names that are less than maximum width. The stats
6315 * take up 42 characters, so the width available for names is:
6317 available_width
= get_columns() - 42;
6320 * If the maximum width fits on a screen, then great! Make everything
6321 * line up by justifying all lines to the same width. If that max
6322 * width is larger than what's available, the name plus stats won't fit
6323 * on one line, and justifying to that width would cause every line to
6324 * wrap on the screen. We only want lines with long names to wrap.
6325 * Limit the padding to what won't wrap.
6327 if (width
> available_width
)
6328 width
= available_width
;
6331 * And regardless of whatever the screen width is (get_columns can
6332 * return 0 if the width is not known or less than 42 for a narrow
6333 * terminal) have the width be a minimum of 10.
6338 /* Save the calculated width */
6339 cb
->cb_namewidth
= width
;
6345 * zpool iostat [[-c [script1,script2,...]] [-lq]|[-rw]] [-ghHLpPvy] [-n name]
6346 * [-T d|u] [[ pool ...]|[pool vdev ...]|[vdev ...]]
6347 * [interval [count]]
6349 * -c CMD For each vdev, run command CMD
6350 * -g Display guid for individual vdev name.
6351 * -L Follow links when resolving vdev path name.
6352 * -P Display full path for vdev name.
6353 * -v Display statistics for individual vdevs
6355 * -p Display values in parsable (exact) format.
6356 * -H Scripted mode. Don't display headers, and separate properties
6358 * -l Display average latency
6359 * -q Display queue depths
6360 * -w Display latency histograms
6361 * -r Display request size histogram
6362 * -T Display a timestamp in date(1) or Unix format
6363 * -n Only print headers once
6365 * This command can be tricky because we want to be able to deal with pool
6366 * creation/destruction as well as vdev configuration changes. The bulk of this
6367 * processing is handled by the pool_list_* routines in zpool_iter.c. We rely
6368 * on pool_list_update() to detect the addition of new pools. Configuration
6369 * changes are all handled within libzfs.
6372 zpool_do_iostat(int argc
, char **argv
)
6378 unsigned long count
= 0;
6381 boolean_t verbose
= B_FALSE
;
6382 boolean_t latency
= B_FALSE
, l_histo
= B_FALSE
, rq_histo
= B_FALSE
;
6383 boolean_t queues
= B_FALSE
, parsable
= B_FALSE
, scripted
= B_FALSE
;
6384 boolean_t omit_since_boot
= B_FALSE
;
6385 boolean_t guid
= B_FALSE
;
6386 boolean_t follow_links
= B_FALSE
;
6387 boolean_t full_name
= B_FALSE
;
6388 boolean_t headers_once
= B_FALSE
;
6389 iostat_cbdata_t cb
= { 0 };
6392 /* Used for printing error message */
6393 const char flag_to_arg
[] = {[IOS_LATENCY
] = 'l', [IOS_QUEUES
] = 'q',
6394 [IOS_L_HISTO
] = 'w', [IOS_RQ_HISTO
] = 'r'};
6396 uint64_t unsupported_flags
;
6399 while ((c
= getopt(argc
, argv
, "c:gLPT:vyhplqrwnH")) != -1) {
6404 gettext("Can't set -c flag twice\n"));
6408 if (getenv("ZPOOL_SCRIPTS_ENABLED") != NULL
&&
6409 !libzfs_envvar_is_set("ZPOOL_SCRIPTS_ENABLED")) {
6410 fprintf(stderr
, gettext(
6411 "Can't run -c, disabled by "
6412 "ZPOOL_SCRIPTS_ENABLED.\n"));
6416 if ((getuid() <= 0 || geteuid() <= 0) &&
6417 !libzfs_envvar_is_set("ZPOOL_SCRIPTS_AS_ROOT")) {
6418 fprintf(stderr
, gettext(
6419 "Can't run -c with root privileges "
6420 "unless ZPOOL_SCRIPTS_AS_ROOT is set.\n"));
6430 follow_links
= B_TRUE
;
6436 get_timestamp_arg(*optarg
);
6460 omit_since_boot
= B_TRUE
;
6463 headers_once
= B_TRUE
;
6469 if (optopt
== 'c') {
6470 print_zpool_script_list("iostat");
6474 gettext("invalid option '%c'\n"), optopt
);
6483 cb
.cb_literal
= parsable
;
6484 cb
.cb_scripted
= scripted
;
6487 cb
.cb_vdevs
.cb_name_flags
|= VDEV_NAME_GUID
;
6489 cb
.cb_vdevs
.cb_name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
6491 cb
.cb_vdevs
.cb_name_flags
|= VDEV_NAME_PATH
;
6492 cb
.cb_iteration
= 0;
6493 cb
.cb_namewidth
= 0;
6494 cb
.cb_verbose
= verbose
;
6496 /* Get our interval and count values (if any) */
6498 get_interval_count_filter_guids(&argc
, argv
, &interval
,
6501 get_interval_count(&argc
, argv
, &interval
, &count
);
6505 /* No args, so just print the defaults. */
6506 } else if (are_all_pools(argc
, argv
)) {
6507 /* All the args are pool names */
6508 } else if (are_vdevs_in_pool(argc
, argv
, NULL
, &cb
.cb_vdevs
)) {
6509 /* All the args are vdevs */
6510 cb
.cb_vdevs
.cb_names
= argv
;
6511 cb
.cb_vdevs
.cb_names_count
= argc
;
6512 argc
= 0; /* No pools to process */
6513 } else if (are_all_pools(1, argv
)) {
6514 /* The first arg is a pool name */
6515 if (are_vdevs_in_pool(argc
- 1, argv
+ 1, argv
[0],
6517 /* ...and the rest are vdev names */
6518 cb
.cb_vdevs
.cb_names
= argv
+ 1;
6519 cb
.cb_vdevs
.cb_names_count
= argc
- 1;
6520 argc
= 1; /* One pool to process */
6522 fprintf(stderr
, gettext("Expected either a list of "));
6523 fprintf(stderr
, gettext("pools, or list of vdevs in"));
6524 fprintf(stderr
, " \"%s\", ", argv
[0]);
6525 fprintf(stderr
, gettext("but got:\n"));
6526 error_list_unresolved_vdevs(argc
- 1, argv
+ 1,
6527 argv
[0], &cb
.cb_vdevs
);
6528 fprintf(stderr
, "\n");
6534 * The args don't make sense. The first arg isn't a pool name,
6535 * nor are all the args vdevs.
6537 fprintf(stderr
, gettext("Unable to parse pools/vdevs list.\n"));
6538 fprintf(stderr
, "\n");
6542 if (cb
.cb_vdevs
.cb_names_count
!= 0) {
6544 * If user specified vdevs, it implies verbose.
6546 cb
.cb_verbose
= B_TRUE
;
6550 * Construct the list of all interesting pools.
6553 if ((list
= pool_list_get(argc
, argv
, NULL
, ZFS_TYPE_POOL
, parsable
,
6557 if (pool_list_count(list
) == 0 && argc
!= 0) {
6558 pool_list_free(list
);
6562 if (pool_list_count(list
) == 0 && interval
== 0) {
6563 pool_list_free(list
);
6564 (void) fprintf(stderr
, gettext("no pools available\n"));
6568 if ((l_histo
|| rq_histo
) && (cmd
!= NULL
|| latency
|| queues
)) {
6569 pool_list_free(list
);
6570 (void) fprintf(stderr
,
6571 gettext("[-r|-w] isn't allowed with [-c|-l|-q]\n"));
6576 if (l_histo
&& rq_histo
) {
6577 pool_list_free(list
);
6578 (void) fprintf(stderr
,
6579 gettext("Only one of [-r|-w] can be passed at a time\n"));
6585 * Enter the main iostat loop.
6591 * Histograms tables look out of place when you try to display
6592 * them with the other stats, so make a rule that you can only
6593 * print histograms by themselves.
6595 cb
.cb_flags
= IOS_L_HISTO_M
;
6596 } else if (rq_histo
) {
6597 cb
.cb_flags
= IOS_RQ_HISTO_M
;
6599 cb
.cb_flags
= IOS_DEFAULT_M
;
6601 cb
.cb_flags
|= IOS_LATENCY_M
;
6603 cb
.cb_flags
|= IOS_QUEUES_M
;
6607 * See if the module supports all the stats we want to display.
6609 unsupported_flags
= cb
.cb_flags
& ~get_stat_flags(list
);
6610 if (unsupported_flags
) {
6614 gettext("The loaded zfs module doesn't support:"));
6616 /* for each bit set in unsupported_flags */
6617 for (f
= unsupported_flags
; f
; f
&= ~(1ULL << idx
)) {
6618 idx
= lowbit64(f
) - 1;
6619 fprintf(stderr
, " -%c", flag_to_arg
[idx
]);
6622 fprintf(stderr
, ". Try running a newer module.\n");
6623 pool_list_free(list
);
6629 if ((npools
= pool_list_count(list
)) == 0)
6630 (void) fprintf(stderr
, gettext("no pools available\n"));
6633 * If this is the first iteration and -y was supplied
6634 * we skip any printing.
6636 boolean_t skip
= (omit_since_boot
&&
6637 cb
.cb_iteration
== 0);
6640 * Refresh all statistics. This is done as an
6641 * explicit step before calculating the maximum name
6642 * width, so that any * configuration changes are
6643 * properly accounted for.
6645 (void) pool_list_iter(list
, B_FALSE
, refresh_iostat
,
6649 * Iterate over all pools to determine the maximum width
6650 * for the pool / device name column across all pools.
6652 cb
.cb_namewidth
= 0;
6653 (void) pool_list_iter(list
, B_FALSE
,
6654 get_namewidth_iostat
, &cb
);
6656 if (timestamp_fmt
!= NODATE
)
6657 print_timestamp(timestamp_fmt
);
6659 if (cmd
!= NULL
&& cb
.cb_verbose
&&
6660 !(cb
.cb_flags
& IOS_ANYHISTO_M
)) {
6661 cb
.vcdl
= all_pools_for_each_vdev_run(argc
,
6662 argv
, cmd
, g_zfs
, cb
.cb_vdevs
.cb_names
,
6663 cb
.cb_vdevs
.cb_names_count
,
6664 cb
.cb_vdevs
.cb_name_flags
);
6671 * Check terminal size so we can print headers
6672 * even when terminal window has its height
6675 winheight
= terminal_height();
6677 * Are we connected to TTY? If not, headers_once
6678 * should be true, to avoid breaking scripts.
6681 headers_once
= B_TRUE
;
6684 * If it's the first time and we're not skipping it,
6685 * or either skip or verbose mode, print the header.
6687 * The histogram code explicitly prints its header on
6688 * every vdev, so skip this for histograms.
6690 if (((++cb
.cb_iteration
== 1 && !skip
) ||
6691 (skip
!= verbose
) ||
6693 (cb
.cb_iteration
% winheight
) == 0)) &&
6694 (!(cb
.cb_flags
& IOS_ANYHISTO_M
)) &&
6696 print_iostat_header(&cb
);
6699 (void) fflush(stdout
);
6700 (void) fsleep(interval
);
6704 pool_list_iter(list
, B_FALSE
, print_iostat
, &cb
);
6707 * If there's more than one pool, and we're not in
6708 * verbose mode (which prints a separator for us),
6709 * then print a separator.
6711 * In addition, if we're printing specific vdevs then
6712 * we also want an ending separator.
6714 if (((npools
> 1 && !verbose
&&
6715 !(cb
.cb_flags
& IOS_ANYHISTO_M
)) ||
6716 (!(cb
.cb_flags
& IOS_ANYHISTO_M
) &&
6717 cb
.cb_vdevs
.cb_names_count
)) &&
6719 print_iostat_separator(&cb
);
6720 if (cb
.vcdl
!= NULL
)
6721 print_cmd_columns(cb
.vcdl
, 1);
6725 if (cb
.vcdl
!= NULL
)
6726 free_vdev_cmd_data_list(cb
.vcdl
);
6733 if (count
!= 0 && --count
== 0)
6736 (void) fflush(stdout
);
6737 (void) fsleep(interval
);
6740 pool_list_free(list
);
6745 typedef struct list_cbdata
{
6746 boolean_t cb_verbose
;
6750 boolean_t cb_scripted
;
6751 zprop_list_t
*cb_proplist
;
6752 boolean_t cb_literal
;
6754 boolean_t cb_json_as_int
;
6755 boolean_t cb_json_pool_key_guid
;
6760 * Given a list of columns to display, output appropriate headers for each one.
6763 print_header(list_cbdata_t
*cb
)
6765 zprop_list_t
*pl
= cb
->cb_proplist
;
6766 char headerbuf
[ZPOOL_MAXPROPLEN
];
6768 boolean_t first
= B_TRUE
;
6769 boolean_t right_justify
;
6772 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
6773 width
= pl
->pl_width
;
6774 if (first
&& cb
->cb_verbose
) {
6776 * Reset the width to accommodate the verbose listing
6779 width
= cb
->cb_namewidth
;
6783 (void) fputs(" ", stdout
);
6787 right_justify
= B_FALSE
;
6788 if (pl
->pl_prop
!= ZPROP_USERPROP
) {
6789 header
= zpool_prop_column_name(pl
->pl_prop
);
6790 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
6794 for (i
= 0; pl
->pl_user_prop
[i
] != '\0'; i
++)
6795 headerbuf
[i
] = toupper(pl
->pl_user_prop
[i
]);
6796 headerbuf
[i
] = '\0';
6800 if (pl
->pl_next
== NULL
&& !right_justify
)
6801 (void) fputs(header
, stdout
);
6802 else if (right_justify
)
6803 (void) printf("%*s", (int)width
, header
);
6805 (void) printf("%-*s", (int)width
, header
);
6808 (void) fputc('\n', stdout
);
6812 * Given a pool and a list of properties, print out all the properties according
6813 * to the described layout. Used by zpool_do_list().
6816 collect_pool(zpool_handle_t
*zhp
, list_cbdata_t
*cb
)
6818 zprop_list_t
*pl
= cb
->cb_proplist
;
6819 boolean_t first
= B_TRUE
;
6820 char property
[ZPOOL_MAXPROPLEN
];
6821 const char *propstr
;
6822 boolean_t right_justify
;
6824 zprop_source_t sourcetype
= ZPROP_SRC_NONE
;
6825 nvlist_t
*item
, *d
, *props
;
6826 item
= d
= props
= NULL
;
6829 item
= fnvlist_alloc();
6830 props
= fnvlist_alloc();
6831 d
= fnvlist_lookup_nvlist(cb
->cb_jsobj
, "pools");
6833 fprintf(stderr
, "pools obj not found.\n");
6836 fill_pool_info(item
, zhp
, B_TRUE
, cb
->cb_json_as_int
);
6839 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
6841 width
= pl
->pl_width
;
6842 if (first
&& cb
->cb_verbose
) {
6844 * Reset the width to accommodate the verbose listing
6847 width
= cb
->cb_namewidth
;
6850 if (!cb
->cb_json
&& !first
) {
6851 if (cb
->cb_scripted
)
6852 (void) fputc('\t', stdout
);
6854 (void) fputs(" ", stdout
);
6859 right_justify
= B_FALSE
;
6860 if (pl
->pl_prop
!= ZPROP_USERPROP
) {
6861 if (zpool_get_prop(zhp
, pl
->pl_prop
, property
,
6862 sizeof (property
), &sourcetype
,
6863 cb
->cb_literal
) != 0)
6868 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
6869 } else if ((zpool_prop_feature(pl
->pl_user_prop
) ||
6870 zpool_prop_unsupported(pl
->pl_user_prop
)) &&
6871 zpool_prop_get_feature(zhp
, pl
->pl_user_prop
, property
,
6872 sizeof (property
)) == 0) {
6874 sourcetype
= ZPROP_SRC_LOCAL
;
6875 } else if (zfs_prop_user(pl
->pl_user_prop
) &&
6876 zpool_get_userprop(zhp
, pl
->pl_user_prop
, property
,
6877 sizeof (property
), &sourcetype
) == 0) {
6884 if (pl
->pl_prop
== ZPOOL_PROP_NAME
)
6886 const char *prop_name
;
6887 if (pl
->pl_prop
!= ZPROP_USERPROP
)
6888 prop_name
= zpool_prop_to_name(pl
->pl_prop
);
6890 prop_name
= pl
->pl_user_prop
;
6891 (void) zprop_nvlist_one_property(
6893 sourcetype
, NULL
, NULL
, props
, cb
->cb_json_as_int
);
6896 * If this is being called in scripted mode, or if this
6897 * is the last column and it is left-justified, don't
6898 * include a width format specifier.
6900 if (cb
->cb_scripted
|| (pl
->pl_next
== NULL
&&
6902 (void) fputs(propstr
, stdout
);
6903 else if (right_justify
)
6904 (void) printf("%*s", (int)width
, propstr
);
6906 (void) printf("%-*s", (int)width
, propstr
);
6911 fnvlist_add_nvlist(item
, "properties", props
);
6912 if (cb
->cb_json_pool_key_guid
) {
6913 char pool_guid
[256];
6914 uint64_t guid
= fnvlist_lookup_uint64(
6915 zpool_get_config(zhp
, NULL
),
6916 ZPOOL_CONFIG_POOL_GUID
);
6917 snprintf(pool_guid
, 256, "%llu",
6918 (u_longlong_t
)guid
);
6919 fnvlist_add_nvlist(d
, pool_guid
, item
);
6921 fnvlist_add_nvlist(d
, zpool_get_name(zhp
),
6924 fnvlist_free(props
);
6927 (void) fputc('\n', stdout
);
6931 collect_vdev_prop(zpool_prop_t prop
, uint64_t value
, const char *str
,
6932 boolean_t scripted
, boolean_t valid
, enum zfs_nicenum_format format
,
6933 boolean_t json
, nvlist_t
*nvl
, boolean_t as_int
)
6937 size_t width
= zprop_width(prop
, &fixed
, ZFS_TYPE_POOL
);
6940 case ZPOOL_PROP_SIZE
:
6941 case ZPOOL_PROP_EXPANDSZ
:
6942 case ZPOOL_PROP_CHECKPOINT
:
6943 case ZPOOL_PROP_DEDUPRATIO
:
6944 case ZPOOL_PROP_DEDUPCACHED
:
6946 (void) strlcpy(propval
, "-", sizeof (propval
));
6948 zfs_nicenum_format(value
, propval
, sizeof (propval
),
6951 case ZPOOL_PROP_FRAGMENTATION
:
6952 if (value
== ZFS_FRAG_INVALID
) {
6953 (void) strlcpy(propval
, "-", sizeof (propval
));
6954 } else if (format
== ZFS_NICENUM_RAW
) {
6955 (void) snprintf(propval
, sizeof (propval
), "%llu",
6956 (unsigned long long)value
);
6958 (void) snprintf(propval
, sizeof (propval
), "%llu%%",
6959 (unsigned long long)value
);
6962 case ZPOOL_PROP_CAPACITY
:
6963 /* capacity value is in parts-per-10,000 (aka permyriad) */
6964 if (format
== ZFS_NICENUM_RAW
)
6965 (void) snprintf(propval
, sizeof (propval
), "%llu",
6966 (unsigned long long)value
/ 100);
6968 (void) snprintf(propval
, sizeof (propval
),
6969 value
< 1000 ? "%1.2f%%" : value
< 10000 ?
6970 "%2.1f%%" : "%3.0f%%", value
/ 100.0);
6972 case ZPOOL_PROP_HEALTH
:
6974 (void) strlcpy(propval
, str
, sizeof (propval
));
6977 zfs_nicenum_format(value
, propval
, sizeof (propval
), format
);
6981 (void) strlcpy(propval
, "-", sizeof (propval
));
6984 zprop_nvlist_one_property(zpool_prop_to_name(prop
), propval
,
6985 ZPROP_SRC_NONE
, NULL
, NULL
, nvl
, as_int
);
6988 (void) printf("\t%s", propval
);
6990 (void) printf(" %*s", (int)width
, propval
);
6995 * print static default line per vdev
6996 * not compatible with '-o' <proplist> option
6999 collect_list_stats(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
,
7000 list_cbdata_t
*cb
, int depth
, boolean_t isspare
, nvlist_t
*item
)
7004 uint_t c
, children
= 0;
7006 boolean_t scripted
= cb
->cb_scripted
;
7007 uint64_t islog
= B_FALSE
;
7008 nvlist_t
*props
, *ent
, *ch
, *obj
, *l2c
, *sp
;
7009 props
= ent
= ch
= obj
= sp
= l2c
= NULL
;
7010 const char *dashes
= "%-*s - - - - "
7013 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
7014 (uint64_t **)&vs
, &c
) == 0);
7017 boolean_t toplevel
= (vs
->vs_space
!= 0);
7019 enum zfs_nicenum_format format
;
7023 format
= ZFS_NICENUM_RAW
;
7025 format
= ZFS_NICENUM_1024
;
7027 if (strcmp(name
, VDEV_TYPE_INDIRECT
) == 0)
7031 props
= fnvlist_alloc();
7032 ent
= fnvlist_alloc();
7033 fill_vdev_info(ent
, zhp
, (char *)name
, B_FALSE
,
7034 cb
->cb_json_as_int
);
7037 (void) printf("\t%s", name
);
7038 else if (strlen(name
) + depth
> cb
->cb_namewidth
)
7039 (void) printf("%*s%s", depth
, "", name
);
7041 (void) printf("%*s%s%*s", depth
, "", name
,
7042 (int)(cb
->cb_namewidth
- strlen(name
) -
7047 * Print the properties for the individual vdevs. Some
7048 * properties are only applicable to toplevel vdevs. The
7049 * 'toplevel' boolean value is passed to the print_one_column()
7050 * to indicate that the value is valid.
7052 if (VDEV_STAT_VALID(vs_pspace
, c
) && vs
->vs_pspace
) {
7053 collect_vdev_prop(ZPOOL_PROP_SIZE
, vs
->vs_pspace
, NULL
,
7054 scripted
, B_TRUE
, format
, cb
->cb_json
, props
,
7055 cb
->cb_json_as_int
);
7057 collect_vdev_prop(ZPOOL_PROP_SIZE
, vs
->vs_space
, NULL
,
7058 scripted
, toplevel
, format
, cb
->cb_json
, props
,
7059 cb
->cb_json_as_int
);
7061 collect_vdev_prop(ZPOOL_PROP_ALLOCATED
, vs
->vs_alloc
, NULL
,
7062 scripted
, toplevel
, format
, cb
->cb_json
, props
,
7063 cb
->cb_json_as_int
);
7064 collect_vdev_prop(ZPOOL_PROP_FREE
, vs
->vs_space
- vs
->vs_alloc
,
7065 NULL
, scripted
, toplevel
, format
, cb
->cb_json
, props
,
7066 cb
->cb_json_as_int
);
7067 collect_vdev_prop(ZPOOL_PROP_CHECKPOINT
,
7068 vs
->vs_checkpoint_space
, NULL
, scripted
, toplevel
, format
,
7069 cb
->cb_json
, props
, cb
->cb_json_as_int
);
7070 collect_vdev_prop(ZPOOL_PROP_EXPANDSZ
, vs
->vs_esize
, NULL
,
7071 scripted
, B_TRUE
, format
, cb
->cb_json
, props
,
7072 cb
->cb_json_as_int
);
7073 collect_vdev_prop(ZPOOL_PROP_FRAGMENTATION
,
7074 vs
->vs_fragmentation
, NULL
, scripted
,
7075 (vs
->vs_fragmentation
!= ZFS_FRAG_INVALID
&& toplevel
),
7076 format
, cb
->cb_json
, props
, cb
->cb_json_as_int
);
7077 cap
= (vs
->vs_space
== 0) ? 0 :
7078 (vs
->vs_alloc
* 10000 / vs
->vs_space
);
7079 collect_vdev_prop(ZPOOL_PROP_CAPACITY
, cap
, NULL
,
7080 scripted
, toplevel
, format
, cb
->cb_json
, props
,
7081 cb
->cb_json_as_int
);
7082 collect_vdev_prop(ZPOOL_PROP_DEDUPRATIO
, 0, NULL
,
7083 scripted
, toplevel
, format
, cb
->cb_json
, props
,
7084 cb
->cb_json_as_int
);
7085 state
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
7087 if (vs
->vs_aux
== VDEV_AUX_SPARED
)
7089 else if (vs
->vs_state
== VDEV_STATE_HEALTHY
)
7092 collect_vdev_prop(ZPOOL_PROP_HEALTH
, 0, state
, scripted
,
7093 B_TRUE
, format
, cb
->cb_json
, props
, cb
->cb_json_as_int
);
7096 fnvlist_add_nvlist(ent
, "properties", props
);
7097 fnvlist_free(props
);
7099 (void) fputc('\n', stdout
);
7102 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
7103 &child
, &children
) != 0) {
7105 fnvlist_add_nvlist(item
, name
, ent
);
7112 ch
= fnvlist_alloc();
7115 /* list the normal vdevs first */
7116 for (c
= 0; c
< children
; c
++) {
7117 uint64_t ishole
= B_FALSE
;
7119 if (nvlist_lookup_uint64(child
[c
],
7120 ZPOOL_CONFIG_IS_HOLE
, &ishole
) == 0 && ishole
)
7123 if (nvlist_lookup_uint64(child
[c
],
7124 ZPOOL_CONFIG_IS_LOG
, &islog
) == 0 && islog
)
7127 if (nvlist_exists(child
[c
], ZPOOL_CONFIG_ALLOCATION_BIAS
))
7130 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
7131 cb
->cb_name_flags
| VDEV_NAME_TYPE_ID
);
7133 if (name
== NULL
|| cb
->cb_json
!= B_TRUE
)
7134 collect_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2,
7136 else if (cb
->cb_json
) {
7137 collect_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2,
7144 if (!nvlist_empty(ch
))
7145 fnvlist_add_nvlist(ent
, "vdevs", ch
);
7149 /* list the classes: 'logs', 'dedup', and 'special' */
7150 for (uint_t n
= 0; n
< ARRAY_SIZE(class_name
); n
++) {
7151 boolean_t printed
= B_FALSE
;
7153 obj
= fnvlist_alloc();
7154 for (c
= 0; c
< children
; c
++) {
7155 const char *bias
= NULL
;
7156 const char *type
= NULL
;
7158 if (nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
7159 &islog
) == 0 && islog
) {
7160 bias
= VDEV_ALLOC_CLASS_LOGS
;
7162 (void) nvlist_lookup_string(child
[c
],
7163 ZPOOL_CONFIG_ALLOCATION_BIAS
, &bias
);
7164 (void) nvlist_lookup_string(child
[c
],
7165 ZPOOL_CONFIG_TYPE
, &type
);
7167 if (bias
== NULL
|| strcmp(bias
, class_name
[n
]) != 0)
7169 if (!islog
&& strcmp(type
, VDEV_TYPE_INDIRECT
) == 0)
7172 if (!printed
&& !cb
->cb_json
) {
7173 /* LINTED E_SEC_PRINTF_VAR_FMT */
7174 (void) printf(dashes
, cb
->cb_namewidth
,
7178 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
7179 cb
->cb_name_flags
| VDEV_NAME_TYPE_ID
);
7180 collect_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2,
7185 if (!nvlist_empty(obj
))
7186 fnvlist_add_nvlist(item
, class_name
[n
], obj
);
7191 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
7192 &child
, &children
) == 0 && children
> 0) {
7194 l2c
= fnvlist_alloc();
7196 /* LINTED E_SEC_PRINTF_VAR_FMT */
7197 (void) printf(dashes
, cb
->cb_namewidth
, "cache");
7199 for (c
= 0; c
< children
; c
++) {
7200 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
7202 collect_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2,
7207 if (!nvlist_empty(l2c
))
7208 fnvlist_add_nvlist(item
, "l2cache", l2c
);
7213 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
, &child
,
7214 &children
) == 0 && children
> 0) {
7216 sp
= fnvlist_alloc();
7218 /* LINTED E_SEC_PRINTF_VAR_FMT */
7219 (void) printf(dashes
, cb
->cb_namewidth
, "spare");
7221 for (c
= 0; c
< children
; c
++) {
7222 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
7224 collect_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2,
7229 if (!nvlist_empty(sp
))
7230 fnvlist_add_nvlist(item
, "spares", sp
);
7235 if (name
!= NULL
&& cb
->cb_json
) {
7236 fnvlist_add_nvlist(item
, name
, ent
);
7242 * Generic callback function to list a pool.
7245 list_callback(zpool_handle_t
*zhp
, void *data
)
7247 nvlist_t
*p
, *d
, *nvdevs
;
7249 char pool_guid
[256];
7250 const char *pool_name
= zpool_get_name(zhp
);
7251 list_cbdata_t
*cbp
= data
;
7252 p
= d
= nvdevs
= NULL
;
7254 collect_pool(zhp
, cbp
);
7256 if (cbp
->cb_verbose
) {
7257 nvlist_t
*config
, *nvroot
;
7258 config
= zpool_get_config(zhp
, NULL
);
7259 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
7262 d
= fnvlist_lookup_nvlist(cbp
->cb_jsobj
,
7264 if (cbp
->cb_json_pool_key_guid
) {
7265 guid
= fnvlist_lookup_uint64(config
,
7266 ZPOOL_CONFIG_POOL_GUID
);
7267 snprintf(pool_guid
, 256, "%llu",
7268 (u_longlong_t
)guid
);
7269 p
= fnvlist_lookup_nvlist(d
, pool_guid
);
7271 p
= fnvlist_lookup_nvlist(d
, pool_name
);
7273 nvdevs
= fnvlist_alloc();
7275 collect_list_stats(zhp
, NULL
, nvroot
, cbp
, 0, B_FALSE
, nvdevs
);
7277 fnvlist_add_nvlist(p
, "vdevs", nvdevs
);
7278 if (cbp
->cb_json_pool_key_guid
)
7279 fnvlist_add_nvlist(d
, pool_guid
, p
);
7281 fnvlist_add_nvlist(d
, pool_name
, p
);
7282 fnvlist_add_nvlist(cbp
->cb_jsobj
, "pools", d
);
7283 fnvlist_free(nvdevs
);
7291 * Set the minimum pool/vdev name column width. The width must be at least 9,
7292 * but may be as large as needed.
7295 get_namewidth_list(zpool_handle_t
*zhp
, void *data
)
7297 list_cbdata_t
*cb
= data
;
7300 width
= get_namewidth(zhp
, cb
->cb_namewidth
,
7301 cb
->cb_name_flags
| VDEV_NAME_TYPE_ID
, cb
->cb_verbose
);
7306 cb
->cb_namewidth
= width
;
7312 * zpool list [-gHLpP] [-o prop[,prop]*] [-T d|u] [pool] ... [interval [count]]
7314 * -g Display guid for individual vdev name.
7315 * -H Scripted mode. Don't display headers, and separate properties
7317 * -L Follow links when resolving vdev path name.
7318 * -o List of properties to display. Defaults to
7319 * "name,size,allocated,free,expandsize,fragmentation,capacity,"
7320 * "dedupratio,health,altroot"
7321 * -p Display values in parsable (exact) format.
7322 * -P Display full path for vdev name.
7323 * -T Display a timestamp in date(1) or Unix format
7324 * -j Display the output in JSON format
7325 * --json-int Display the numbers as integer instead of strings.
7326 * --json-pool-key-guid Set pool GUID as key for pool objects.
7328 * List all pools in the system, whether or not they're healthy. Output space
7329 * statistics for each one, as well as health status summary.
7332 zpool_do_list(int argc
, char **argv
)
7336 list_cbdata_t cb
= { 0 };
7337 static char default_props
[] =
7338 "name,size,allocated,free,checkpoint,expandsize,fragmentation,"
7339 "capacity,dedupratio,health,altroot";
7340 char *props
= default_props
;
7342 unsigned long count
= 0;
7344 boolean_t first
= B_TRUE
;
7345 nvlist_t
*data
= NULL
;
7346 current_prop_type
= ZFS_TYPE_POOL
;
7348 struct option long_options
[] = {
7349 {"json", no_argument
, NULL
, 'j'},
7350 {"json-int", no_argument
, NULL
, ZPOOL_OPTION_JSON_NUMS_AS_INT
},
7351 {"json-pool-key-guid", no_argument
, NULL
,
7352 ZPOOL_OPTION_POOL_KEY_GUID
},
7357 while ((c
= getopt_long(argc
, argv
, ":gjHLo:pPT:v", long_options
,
7361 cb
.cb_name_flags
|= VDEV_NAME_GUID
;
7364 cb
.cb_scripted
= B_TRUE
;
7367 cb
.cb_name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
7373 cb
.cb_name_flags
|= VDEV_NAME_PATH
;
7376 cb
.cb_literal
= B_TRUE
;
7379 cb
.cb_json
= B_TRUE
;
7381 case ZPOOL_OPTION_JSON_NUMS_AS_INT
:
7382 cb
.cb_json_as_int
= B_TRUE
;
7383 cb
.cb_literal
= B_TRUE
;
7385 case ZPOOL_OPTION_POOL_KEY_GUID
:
7386 cb
.cb_json_pool_key_guid
= B_TRUE
;
7389 get_timestamp_arg(*optarg
);
7392 cb
.cb_verbose
= B_TRUE
;
7393 cb
.cb_namewidth
= 8; /* 8 until precalc is avail */
7396 (void) fprintf(stderr
, gettext("missing argument for "
7397 "'%c' option\n"), optopt
);
7401 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
7410 if (!cb
.cb_json
&& cb
.cb_json_as_int
) {
7411 (void) fprintf(stderr
, gettext("'--json-int' only works with"
7416 if (!cb
.cb_json
&& cb
.cb_json_pool_key_guid
) {
7417 (void) fprintf(stderr
, gettext("'json-pool-key-guid' only"
7418 " works with '-j' option\n"));
7422 get_interval_count(&argc
, argv
, &interval
, &count
);
7424 if (zprop_get_list(g_zfs
, props
, &cb
.cb_proplist
, ZFS_TYPE_POOL
) != 0)
7428 if ((list
= pool_list_get(argc
, argv
, &cb
.cb_proplist
,
7429 ZFS_TYPE_POOL
, cb
.cb_literal
, &ret
)) == NULL
)
7432 if (pool_list_count(list
) == 0)
7436 cb
.cb_jsobj
= zpool_json_schema(0, 1);
7437 data
= fnvlist_alloc();
7438 fnvlist_add_nvlist(cb
.cb_jsobj
, "pools", data
);
7442 cb
.cb_namewidth
= 0;
7443 (void) pool_list_iter(list
, B_FALSE
, get_namewidth_list
, &cb
);
7445 if (timestamp_fmt
!= NODATE
) {
7447 if (cb
.cb_json_as_int
) {
7448 fnvlist_add_uint64(cb
.cb_jsobj
, "time",
7452 get_timestamp(timestamp_fmt
, ts
, 128);
7453 fnvlist_add_string(cb
.cb_jsobj
, "time",
7457 print_timestamp(timestamp_fmt
);
7460 if (!cb
.cb_scripted
&& (first
|| cb
.cb_verbose
) &&
7465 ret
= pool_list_iter(list
, B_TRUE
, list_callback
, &cb
);
7467 if (ret
== 0 && cb
.cb_json
)
7468 zcmd_print_json(cb
.cb_jsobj
);
7469 else if (ret
!= 0 && cb
.cb_json
)
7470 nvlist_free(cb
.cb_jsobj
);
7475 if (count
!= 0 && --count
== 0)
7478 pool_list_free(list
);
7480 (void) fflush(stdout
);
7481 (void) fsleep(interval
);
7484 if (argc
== 0 && !cb
.cb_scripted
&& !cb
.cb_json
&&
7485 pool_list_count(list
) == 0) {
7486 (void) printf(gettext("no pools available\n"));
7490 pool_list_free(list
);
7491 zprop_free_list(cb
.cb_proplist
);
7496 zpool_do_attach_or_replace(int argc
, char **argv
, int replacing
)
7498 boolean_t force
= B_FALSE
;
7499 boolean_t rebuild
= B_FALSE
;
7500 boolean_t wait
= B_FALSE
;
7503 char *poolname
, *old_disk
, *new_disk
;
7504 zpool_handle_t
*zhp
;
7505 nvlist_t
*props
= NULL
;
7510 while ((c
= getopt(argc
, argv
, "fo:sw")) != -1) {
7516 if ((propval
= strchr(optarg
, '=')) == NULL
) {
7517 (void) fprintf(stderr
, gettext("missing "
7518 "'=' for -o option\n"));
7524 if ((strcmp(optarg
, ZPOOL_CONFIG_ASHIFT
) != 0) ||
7525 (add_prop_list(optarg
, propval
, &props
, B_TRUE
)))
7535 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
7544 /* get pool name and check number of arguments */
7546 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
7553 (void) fprintf(stderr
,
7554 gettext("missing <device> specification\n"));
7562 (void) fprintf(stderr
,
7563 gettext("missing <new_device> specification\n"));
7566 new_disk
= old_disk
;
7576 (void) fprintf(stderr
, gettext("too many arguments\n"));
7580 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
) {
7585 if (zpool_get_config(zhp
, NULL
) == NULL
) {
7586 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
7593 /* unless manually specified use "ashift" pool property (if set) */
7594 if (!nvlist_exists(props
, ZPOOL_CONFIG_ASHIFT
)) {
7597 char strval
[ZPOOL_MAXPROPLEN
];
7599 intval
= zpool_get_prop_int(zhp
, ZPOOL_PROP_ASHIFT
, &src
);
7600 if (src
!= ZPROP_SRC_DEFAULT
) {
7601 (void) sprintf(strval
, "%" PRId32
, intval
);
7602 verify(add_prop_list(ZPOOL_CONFIG_ASHIFT
, strval
,
7603 &props
, B_TRUE
) == 0);
7607 nvroot
= make_root_vdev(zhp
, props
, force
, B_FALSE
, replacing
, B_FALSE
,
7609 if (nvroot
== NULL
) {
7615 ret
= zpool_vdev_attach(zhp
, old_disk
, new_disk
, nvroot
, replacing
,
7618 if (ret
== 0 && wait
) {
7619 zpool_wait_activity_t activity
= ZPOOL_WAIT_RESILVER
;
7620 char raidz_prefix
[] = "raidz";
7622 activity
= ZPOOL_WAIT_REPLACE
;
7623 } else if (strncmp(old_disk
,
7624 raidz_prefix
, strlen(raidz_prefix
)) == 0) {
7625 activity
= ZPOOL_WAIT_RAIDZ_EXPAND
;
7627 ret
= zpool_wait(zhp
, activity
);
7631 nvlist_free(nvroot
);
7638 * zpool replace [-fsw] [-o property=value] <pool> <device> <new_device>
7640 * -f Force attach, even if <new_device> appears to be in use.
7641 * -s Use sequential instead of healing reconstruction for resilver.
7642 * -o Set property=value.
7643 * -w Wait for replacing to complete before returning
7645 * Replace <device> with <new_device>.
7648 zpool_do_replace(int argc
, char **argv
)
7650 return (zpool_do_attach_or_replace(argc
, argv
, B_TRUE
));
7654 * zpool attach [-fsw] [-o property=value] <pool> <device>|<vdev> <new_device>
7656 * -f Force attach, even if <new_device> appears to be in use.
7657 * -s Use sequential instead of healing reconstruction for resilver.
7658 * -o Set property=value.
7659 * -w Wait for resilvering (mirror) or expansion (raidz) to complete
7662 * Attach <new_device> to a <device> or <vdev>, where the vdev can be of type
7663 * mirror or raidz. If <device> is not part of a mirror, then <device> will
7664 * be transformed into a mirror of <device> and <new_device>. When a mirror
7665 * is involved, <new_device> will begin life with a DTL of [0, now], and will
7666 * immediately begin to resilver itself. For the raidz case, a expansion will
7667 * commence and reflow the raidz data across all the disks including the
7671 zpool_do_attach(int argc
, char **argv
)
7673 return (zpool_do_attach_or_replace(argc
, argv
, B_FALSE
));
7677 * zpool detach [-f] <pool> <device>
7679 * -f Force detach of <device>, even if DTLs argue against it
7680 * (not supported yet)
7682 * Detach a device from a mirror. The operation will be refused if <device>
7683 * is the last device in the mirror, or if the DTLs indicate that this device
7684 * has the only valid copy of some data.
7687 zpool_do_detach(int argc
, char **argv
)
7690 char *poolname
, *path
;
7691 zpool_handle_t
*zhp
;
7695 while ((c
= getopt(argc
, argv
, "")) != -1) {
7698 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
7707 /* get pool name and check number of arguments */
7709 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
7714 (void) fprintf(stderr
,
7715 gettext("missing <device> specification\n"));
7722 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
7725 ret
= zpool_vdev_detach(zhp
, path
);
7733 * zpool split [-gLnP] [-o prop=val] ...
7735 * [-R altroot] <pool> <newpool> [<device> ...]
7737 * -g Display guid for individual vdev name.
7738 * -L Follow links when resolving vdev path name.
7739 * -n Do not split the pool, but display the resulting layout if
7740 * it were to be split.
7741 * -o Set property=value, or set mount options.
7742 * -P Display full path for vdev name.
7743 * -R Mount the split-off pool under an alternate root.
7744 * -l Load encryption keys while importing.
7746 * Splits the named pool and gives it the new pool name. Devices to be split
7747 * off may be listed, provided that no more than one device is specified
7748 * per top-level vdev mirror. The newly split pool is left in an exported
7749 * state unless -R is specified.
7751 * Restrictions: the top-level of the pool pool must only be made up of
7752 * mirrors; all devices in the pool must be healthy; no device may be
7753 * undergoing a resilvering operation.
7756 zpool_do_split(int argc
, char **argv
)
7758 char *srcpool
, *newpool
, *propval
;
7759 char *mntopts
= NULL
;
7763 boolean_t loadkeys
= B_FALSE
;
7764 zpool_handle_t
*zhp
;
7765 nvlist_t
*config
, *props
= NULL
;
7767 flags
.dryrun
= B_FALSE
;
7768 flags
.import
= B_FALSE
;
7769 flags
.name_flags
= 0;
7772 while ((c
= getopt(argc
, argv
, ":gLR:lno:P")) != -1) {
7775 flags
.name_flags
|= VDEV_NAME_GUID
;
7778 flags
.name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
7781 flags
.import
= B_TRUE
;
7783 zpool_prop_to_name(ZPOOL_PROP_ALTROOT
), optarg
,
7784 &props
, B_TRUE
) != 0) {
7793 flags
.dryrun
= B_TRUE
;
7796 if ((propval
= strchr(optarg
, '=')) != NULL
) {
7799 if (add_prop_list(optarg
, propval
,
7800 &props
, B_TRUE
) != 0) {
7809 flags
.name_flags
|= VDEV_NAME_PATH
;
7812 (void) fprintf(stderr
, gettext("missing argument for "
7813 "'%c' option\n"), optopt
);
7817 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
7824 if (!flags
.import
&& mntopts
!= NULL
) {
7825 (void) fprintf(stderr
, gettext("setting mntopts is only "
7826 "valid when importing the pool\n"));
7830 if (!flags
.import
&& loadkeys
) {
7831 (void) fprintf(stderr
, gettext("loading keys is only "
7832 "valid when importing the pool\n"));
7840 (void) fprintf(stderr
, gettext("Missing pool name\n"));
7844 (void) fprintf(stderr
, gettext("Missing new pool name\n"));
7854 if ((zhp
= zpool_open(g_zfs
, srcpool
)) == NULL
) {
7859 config
= split_mirror_vdev(zhp
, newpool
, props
, flags
, argc
, argv
);
7860 if (config
== NULL
) {
7864 (void) printf(gettext("would create '%s' with the "
7865 "following layout:\n\n"), newpool
);
7866 print_vdev_tree(NULL
, newpool
, config
, 0, "",
7868 print_vdev_tree(NULL
, "dedup", config
, 0,
7869 VDEV_ALLOC_BIAS_DEDUP
, 0);
7870 print_vdev_tree(NULL
, "special", config
, 0,
7871 VDEV_ALLOC_BIAS_SPECIAL
, 0);
7877 if (ret
!= 0 || flags
.dryrun
|| !flags
.import
) {
7878 nvlist_free(config
);
7884 * The split was successful. Now we need to open the new
7885 * pool and import it.
7887 if ((zhp
= zpool_open_canfail(g_zfs
, newpool
)) == NULL
) {
7888 nvlist_free(config
);
7894 ret
= zfs_crypto_attempt_load_keys(g_zfs
, newpool
);
7899 if (zpool_get_state(zhp
) != POOL_STATE_UNAVAIL
) {
7900 ms_status
= zpool_enable_datasets(zhp
, mntopts
, 0,
7902 if (ms_status
== EZFS_SHAREFAILED
) {
7903 (void) fprintf(stderr
, gettext("Split was successful, "
7904 "datasets are mounted but sharing of some datasets "
7906 } else if (ms_status
== EZFS_MOUNTFAILED
) {
7907 (void) fprintf(stderr
, gettext("Split was successful"
7908 ", but some datasets could not be mounted\n"));
7909 (void) fprintf(stderr
, gettext("Try doing '%s' with a "
7910 "different altroot\n"), "zpool import");
7914 nvlist_free(config
);
7922 * zpool online [--power] <pool> <device> ...
7924 * --power: Power on the enclosure slot to the drive (if possible)
7927 zpool_do_online(int argc
, char **argv
)
7931 zpool_handle_t
*zhp
;
7933 vdev_state_t newstate
;
7935 boolean_t is_power_on
= B_FALSE
;
7936 struct option long_options
[] = {
7937 {"power", no_argument
, NULL
, ZPOOL_OPTION_POWER
},
7942 while ((c
= getopt_long(argc
, argv
, "e", long_options
, NULL
)) != -1) {
7945 flags
|= ZFS_ONLINE_EXPAND
;
7947 case ZPOOL_OPTION_POWER
:
7948 is_power_on
= B_TRUE
;
7951 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
7957 if (libzfs_envvar_is_set("ZPOOL_AUTO_POWER_ON_SLOT"))
7958 is_power_on
= B_TRUE
;
7963 /* get pool name and check number of arguments */
7965 (void) fprintf(stderr
, gettext("missing pool name\n"));
7969 (void) fprintf(stderr
, gettext("missing device name\n"));
7975 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
) {
7976 (void) fprintf(stderr
, gettext("failed to open pool "
7977 "\"%s\""), poolname
);
7981 for (i
= 1; i
< argc
; i
++) {
7982 vdev_state_t oldstate
;
7983 boolean_t avail_spare
, l2cache
;
7987 rc
= zpool_power_on_and_disk_wait(zhp
, argv
[i
]);
7988 if (rc
== ENOTSUP
) {
7989 (void) fprintf(stderr
,
7990 gettext("Power control not supported\n"));
7996 nvlist_t
*tgt
= zpool_find_vdev(zhp
, argv
[i
], &avail_spare
,
8000 (void) fprintf(stderr
, gettext("couldn't find device "
8001 "\"%s\" in pool \"%s\"\n"), argv
[i
], poolname
);
8005 oldstate
= ((vdev_stat_t
*)fnvlist_lookup_uint64_array(tgt
,
8006 ZPOOL_CONFIG_VDEV_STATS
, &vsc
))->vs_state
;
8007 if ((rc
= zpool_vdev_online(zhp
, argv
[i
], flags
,
8009 if (newstate
!= VDEV_STATE_HEALTHY
) {
8010 (void) printf(gettext("warning: device '%s' "
8011 "onlined, but remains in faulted state\n"),
8013 if (newstate
== VDEV_STATE_FAULTED
)
8014 (void) printf(gettext("use 'zpool "
8015 "clear' to restore a faulted "
8018 (void) printf(gettext("use 'zpool "
8019 "replace' to replace devices "
8020 "that are no longer present\n"));
8021 if ((flags
& ZFS_ONLINE_EXPAND
)) {
8022 (void) printf(gettext("%s: failed "
8023 "to expand usable space on "
8024 "unhealthy device '%s'\n"),
8025 (oldstate
>= VDEV_STATE_DEGRADED
?
8026 "error" : "warning"), argv
[i
]);
8027 if (oldstate
>= VDEV_STATE_DEGRADED
) {
8034 (void) fprintf(stderr
, gettext("Failed to online "
8035 "\"%s\" in pool \"%s\": %d\n"),
8036 argv
[i
], poolname
, rc
);
8047 * zpool offline [-ft]|[--power] <pool> <device> ...
8050 * -f Force the device into a faulted state.
8052 * -t Only take the device off-line temporarily. The offline/faulted
8053 * state will not be persistent across reboots.
8055 * --power Power off the enclosure slot to the drive (if possible)
8058 zpool_do_offline(int argc
, char **argv
)
8062 zpool_handle_t
*zhp
;
8064 boolean_t istmp
= B_FALSE
;
8065 boolean_t fault
= B_FALSE
;
8066 boolean_t is_power_off
= B_FALSE
;
8068 struct option long_options
[] = {
8069 {"power", no_argument
, NULL
, ZPOOL_OPTION_POWER
},
8074 while ((c
= getopt_long(argc
, argv
, "ft", long_options
, NULL
)) != -1) {
8082 case ZPOOL_OPTION_POWER
:
8083 is_power_off
= B_TRUE
;
8086 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
8092 if (is_power_off
&& fault
) {
8093 (void) fprintf(stderr
,
8094 gettext("-0 and -f cannot be used together\n"));
8099 if (is_power_off
&& istmp
) {
8100 (void) fprintf(stderr
,
8101 gettext("-0 and -t cannot be used together\n"));
8109 /* get pool name and check number of arguments */
8111 (void) fprintf(stderr
, gettext("missing pool name\n"));
8115 (void) fprintf(stderr
, gettext("missing device name\n"));
8121 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
) {
8122 (void) fprintf(stderr
, gettext("failed to open pool "
8123 "\"%s\""), poolname
);
8127 for (i
= 1; i
< argc
; i
++) {
8128 uint64_t guid
= zpool_vdev_path_to_guid(zhp
, argv
[i
]);
8131 * Note: we have to power off first, then set REMOVED,
8132 * or else zpool_vdev_set_removed_state() returns
8135 ret
= zpool_power_off(zhp
, argv
[i
]);
8137 (void) fprintf(stderr
, "%s %s %d\n",
8138 gettext("unable to power off slot for"),
8141 zpool_vdev_set_removed_state(zhp
, guid
, VDEV_AUX_NONE
);
8145 if (istmp
== B_FALSE
) {
8146 /* Force the fault to persist across imports */
8147 aux
= VDEV_AUX_EXTERNAL_PERSIST
;
8149 aux
= VDEV_AUX_EXTERNAL
;
8152 if (guid
== 0 || zpool_vdev_fault(zhp
, guid
, aux
) != 0)
8155 if (zpool_vdev_offline(zhp
, argv
[i
], istmp
) != 0)
8166 * zpool clear [-nF]|[--power] <pool> [device]
8168 * Clear all errors associated with a pool or a particular device.
8171 zpool_do_clear(int argc
, char **argv
)
8175 boolean_t dryrun
= B_FALSE
;
8176 boolean_t do_rewind
= B_FALSE
;
8177 boolean_t xtreme_rewind
= B_FALSE
;
8178 boolean_t is_power_on
= B_FALSE
;
8179 uint32_t rewind_policy
= ZPOOL_NO_REWIND
;
8180 nvlist_t
*policy
= NULL
;
8181 zpool_handle_t
*zhp
;
8182 char *pool
, *device
;
8184 struct option long_options
[] = {
8185 {"power", no_argument
, NULL
, ZPOOL_OPTION_POWER
},
8190 while ((c
= getopt_long(argc
, argv
, "FnX", long_options
,
8200 xtreme_rewind
= B_TRUE
;
8202 case ZPOOL_OPTION_POWER
:
8203 is_power_on
= B_TRUE
;
8206 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
8212 if (libzfs_envvar_is_set("ZPOOL_AUTO_POWER_ON_SLOT"))
8213 is_power_on
= B_TRUE
;
8219 (void) fprintf(stderr
, gettext("missing pool name\n"));
8224 (void) fprintf(stderr
, gettext("too many arguments\n"));
8228 if ((dryrun
|| xtreme_rewind
) && !do_rewind
) {
8229 (void) fprintf(stderr
,
8230 gettext("-n or -X only meaningful with -F\n"));
8234 rewind_policy
= ZPOOL_TRY_REWIND
;
8236 rewind_policy
= ZPOOL_DO_REWIND
;
8238 rewind_policy
|= ZPOOL_EXTREME_REWIND
;
8240 /* In future, further rewind policy choices can be passed along here */
8241 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME
, 0) != 0 ||
8242 nvlist_add_uint32(policy
, ZPOOL_LOAD_REWIND_POLICY
,
8243 rewind_policy
) != 0) {
8248 device
= argc
== 2 ? argv
[1] : NULL
;
8250 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
) {
8251 nvlist_free(policy
);
8256 if (device
== NULL
) {
8257 zpool_power_on_pool_and_wait_for_devices(zhp
);
8259 zpool_power_on_and_disk_wait(zhp
, device
);
8263 if (zpool_clear(zhp
, device
, policy
) != 0)
8268 nvlist_free(policy
);
8274 * zpool reguid [-g <guid>] <pool>
8277 zpool_do_reguid(int argc
, char **argv
)
8280 uint64_t *guidp
= NULL
;
8284 zpool_handle_t
*zhp
;
8288 while ((c
= getopt(argc
, argv
, "g:")) != -1) {
8292 guid
= strtoull(optarg
, &endptr
, 10);
8293 if (errno
!= 0 || *endptr
!= '\0') {
8294 (void) fprintf(stderr
,
8295 gettext("invalid GUID: %s\n"), optarg
);
8301 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
8310 /* get pool name and check number of arguments */
8312 (void) fprintf(stderr
, gettext("missing pool name\n"));
8317 (void) fprintf(stderr
, gettext("too many arguments\n"));
8322 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
8325 ret
= zpool_set_guid(zhp
, guidp
);
8333 * zpool reopen <pool>
8335 * Reopen the pool so that the kernel can update the sizes of all vdevs.
8338 zpool_do_reopen(int argc
, char **argv
)
8342 boolean_t scrub_restart
= B_TRUE
;
8345 while ((c
= getopt(argc
, argv
, "n")) != -1) {
8348 scrub_restart
= B_FALSE
;
8351 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
8360 /* if argc == 0 we will execute zpool_reopen_one on all pools */
8361 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
, ZFS_TYPE_POOL
,
8362 B_FALSE
, zpool_reopen_one
, &scrub_restart
);
8367 typedef struct scrub_cbdata
{
8369 pool_scrub_cmd_t cb_scrub_cmd
;
8373 zpool_has_checkpoint(zpool_handle_t
*zhp
)
8375 nvlist_t
*config
, *nvroot
;
8377 config
= zpool_get_config(zhp
, NULL
);
8379 if (config
!= NULL
) {
8380 pool_checkpoint_stat_t
*pcs
= NULL
;
8383 nvroot
= fnvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
);
8384 (void) nvlist_lookup_uint64_array(nvroot
,
8385 ZPOOL_CONFIG_CHECKPOINT_STATS
, (uint64_t **)&pcs
, &c
);
8387 if (pcs
== NULL
|| pcs
->pcs_state
== CS_NONE
)
8390 assert(pcs
->pcs_state
== CS_CHECKPOINT_EXISTS
||
8391 pcs
->pcs_state
== CS_CHECKPOINT_DISCARDING
);
8399 scrub_callback(zpool_handle_t
*zhp
, void *data
)
8401 scrub_cbdata_t
*cb
= data
;
8405 * Ignore faulted pools.
8407 if (zpool_get_state(zhp
) == POOL_STATE_UNAVAIL
) {
8408 (void) fprintf(stderr
, gettext("cannot scan '%s': pool is "
8409 "currently unavailable\n"), zpool_get_name(zhp
));
8413 err
= zpool_scan(zhp
, cb
->cb_type
, cb
->cb_scrub_cmd
);
8415 if (err
== 0 && zpool_has_checkpoint(zhp
) &&
8416 cb
->cb_type
== POOL_SCAN_SCRUB
) {
8417 (void) printf(gettext("warning: will not scrub state that "
8418 "belongs to the checkpoint of pool '%s'\n"),
8419 zpool_get_name(zhp
));
8426 wait_callback(zpool_handle_t
*zhp
, void *data
)
8428 zpool_wait_activity_t
*act
= data
;
8429 return (zpool_wait(zhp
, *act
));
8433 * zpool scrub [-e | -s | -p | -C] [-w] <pool> ...
8435 * -e Only scrub blocks in the error log.
8436 * -s Stop. Stops any in-progress scrub.
8437 * -p Pause. Pause in-progress scrub.
8438 * -w Wait. Blocks until scrub has completed.
8439 * -C Scrub from last saved txg.
8442 zpool_do_scrub(int argc
, char **argv
)
8446 boolean_t wait
= B_FALSE
;
8449 cb
.cb_type
= POOL_SCAN_SCRUB
;
8450 cb
.cb_scrub_cmd
= POOL_SCRUB_NORMAL
;
8452 boolean_t is_error_scrub
= B_FALSE
;
8453 boolean_t is_pause
= B_FALSE
;
8454 boolean_t is_stop
= B_FALSE
;
8455 boolean_t is_txg_continue
= B_FALSE
;
8458 while ((c
= getopt(argc
, argv
, "spweC")) != -1) {
8461 is_error_scrub
= B_TRUE
;
8473 is_txg_continue
= B_TRUE
;
8476 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
8482 if (is_pause
&& is_stop
) {
8483 (void) fprintf(stderr
, gettext("invalid option "
8484 "combination :-s and -p are mutually exclusive\n"));
8486 } else if (is_pause
&& is_txg_continue
) {
8487 (void) fprintf(stderr
, gettext("invalid option "
8488 "combination :-p and -C are mutually exclusive\n"));
8490 } else if (is_stop
&& is_txg_continue
) {
8491 (void) fprintf(stderr
, gettext("invalid option "
8492 "combination :-s and -C are mutually exclusive\n"));
8494 } else if (is_error_scrub
&& is_txg_continue
) {
8495 (void) fprintf(stderr
, gettext("invalid option "
8496 "combination :-e and -C are mutually exclusive\n"));
8500 cb
.cb_type
= POOL_SCAN_ERRORSCRUB
;
8503 cb
.cb_scrub_cmd
= POOL_SCRUB_PAUSE
;
8504 } else if (is_stop
) {
8505 cb
.cb_type
= POOL_SCAN_NONE
;
8506 } else if (is_txg_continue
) {
8507 cb
.cb_scrub_cmd
= POOL_SCRUB_FROM_LAST_TXG
;
8509 cb
.cb_scrub_cmd
= POOL_SCRUB_NORMAL
;
8513 if (wait
&& (cb
.cb_type
== POOL_SCAN_NONE
||
8514 cb
.cb_scrub_cmd
== POOL_SCRUB_PAUSE
)) {
8515 (void) fprintf(stderr
, gettext("invalid option combination: "
8516 "-w cannot be used with -p or -s\n"));
8524 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
8528 error
= for_each_pool(argc
, argv
, B_TRUE
, NULL
, ZFS_TYPE_POOL
,
8529 B_FALSE
, scrub_callback
, &cb
);
8531 if (wait
&& !error
) {
8532 zpool_wait_activity_t act
= ZPOOL_WAIT_SCRUB
;
8533 error
= for_each_pool(argc
, argv
, B_TRUE
, NULL
, ZFS_TYPE_POOL
,
8534 B_FALSE
, wait_callback
, &act
);
8541 * zpool resilver <pool> ...
8543 * Restarts any in-progress resilver
8546 zpool_do_resilver(int argc
, char **argv
)
8551 cb
.cb_type
= POOL_SCAN_RESILVER
;
8552 cb
.cb_scrub_cmd
= POOL_SCRUB_NORMAL
;
8555 while ((c
= getopt(argc
, argv
, "")) != -1) {
8558 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
8568 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
8572 return (for_each_pool(argc
, argv
, B_TRUE
, NULL
, ZFS_TYPE_POOL
,
8573 B_FALSE
, scrub_callback
, &cb
));
8577 * zpool trim [-d] [-r <rate>] [-c | -s] <pool> [<device> ...]
8579 * -c Cancel. Ends any in-progress trim.
8580 * -d Secure trim. Requires kernel and device support.
8581 * -r <rate> Sets the TRIM rate in bytes (per second). Supports
8582 * adding a multiplier suffix such as 'k' or 'm'.
8583 * -s Suspend. TRIM can then be restarted with no flags.
8584 * -w Wait. Blocks until trimming has completed.
8587 zpool_do_trim(int argc
, char **argv
)
8589 struct option long_options
[] = {
8590 {"cancel", no_argument
, NULL
, 'c'},
8591 {"secure", no_argument
, NULL
, 'd'},
8592 {"rate", required_argument
, NULL
, 'r'},
8593 {"suspend", no_argument
, NULL
, 's'},
8594 {"wait", no_argument
, NULL
, 'w'},
8598 pool_trim_func_t cmd_type
= POOL_TRIM_START
;
8600 boolean_t secure
= B_FALSE
;
8601 boolean_t wait
= B_FALSE
;
8604 while ((c
= getopt_long(argc
, argv
, "cdr:sw", long_options
, NULL
))
8608 if (cmd_type
!= POOL_TRIM_START
&&
8609 cmd_type
!= POOL_TRIM_CANCEL
) {
8610 (void) fprintf(stderr
, gettext("-c cannot be "
8611 "combined with other options\n"));
8614 cmd_type
= POOL_TRIM_CANCEL
;
8617 if (cmd_type
!= POOL_TRIM_START
) {
8618 (void) fprintf(stderr
, gettext("-d cannot be "
8619 "combined with the -c or -s options\n"));
8625 if (cmd_type
!= POOL_TRIM_START
) {
8626 (void) fprintf(stderr
, gettext("-r cannot be "
8627 "combined with the -c or -s options\n"));
8630 if (zfs_nicestrtonum(g_zfs
, optarg
, &rate
) == -1) {
8631 (void) fprintf(stderr
, "%s: %s\n",
8632 gettext("invalid value for rate"),
8633 libzfs_error_description(g_zfs
));
8638 if (cmd_type
!= POOL_TRIM_START
&&
8639 cmd_type
!= POOL_TRIM_SUSPEND
) {
8640 (void) fprintf(stderr
, gettext("-s cannot be "
8641 "combined with other options\n"));
8644 cmd_type
= POOL_TRIM_SUSPEND
;
8651 (void) fprintf(stderr
,
8652 gettext("invalid option '%c'\n"), optopt
);
8654 (void) fprintf(stderr
,
8655 gettext("invalid option '%s'\n"),
8666 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
8671 if (wait
&& (cmd_type
!= POOL_TRIM_START
)) {
8672 (void) fprintf(stderr
, gettext("-w cannot be used with -c or "
8677 char *poolname
= argv
[0];
8678 zpool_handle_t
*zhp
= zpool_open(g_zfs
, poolname
);
8682 trimflags_t trim_flags
= {
8688 nvlist_t
*vdevs
= fnvlist_alloc();
8690 /* no individual leaf vdevs specified, so add them all */
8691 nvlist_t
*config
= zpool_get_config(zhp
, NULL
);
8692 nvlist_t
*nvroot
= fnvlist_lookup_nvlist(config
,
8693 ZPOOL_CONFIG_VDEV_TREE
);
8694 zpool_collect_leaves(zhp
, nvroot
, vdevs
);
8695 trim_flags
.fullpool
= B_TRUE
;
8697 trim_flags
.fullpool
= B_FALSE
;
8698 for (int i
= 1; i
< argc
; i
++) {
8699 fnvlist_add_boolean(vdevs
, argv
[i
]);
8703 int error
= zpool_trim(zhp
, cmd_type
, vdevs
, &trim_flags
);
8705 fnvlist_free(vdevs
);
8712 * Converts a total number of seconds to a human readable string broken
8713 * down in to days/hours/minutes/seconds.
8716 secs_to_dhms(uint64_t total
, char *buf
)
8718 uint64_t days
= total
/ 60 / 60 / 24;
8719 uint64_t hours
= (total
/ 60 / 60) % 24;
8720 uint64_t mins
= (total
/ 60) % 60;
8721 uint64_t secs
= (total
% 60);
8724 (void) sprintf(buf
, "%llu days %02llu:%02llu:%02llu",
8725 (u_longlong_t
)days
, (u_longlong_t
)hours
,
8726 (u_longlong_t
)mins
, (u_longlong_t
)secs
);
8728 (void) sprintf(buf
, "%02llu:%02llu:%02llu",
8729 (u_longlong_t
)hours
, (u_longlong_t
)mins
,
8730 (u_longlong_t
)secs
);
8735 * Print out detailed error scrub status.
8738 print_err_scrub_status(pool_scan_stat_t
*ps
)
8740 time_t start
, end
, pause
;
8741 uint64_t total_secs_left
;
8742 uint64_t secs_left
, mins_left
, hours_left
, days_left
;
8743 uint64_t examined
, to_be_examined
;
8745 if (ps
== NULL
|| ps
->pss_error_scrub_func
!= POOL_SCAN_ERRORSCRUB
) {
8749 (void) printf(gettext(" scrub: "));
8751 start
= ps
->pss_error_scrub_start
;
8752 end
= ps
->pss_error_scrub_end
;
8753 pause
= ps
->pss_pass_error_scrub_pause
;
8754 examined
= ps
->pss_error_scrub_examined
;
8755 to_be_examined
= ps
->pss_error_scrub_to_be_examined
;
8757 assert(ps
->pss_error_scrub_func
== POOL_SCAN_ERRORSCRUB
);
8759 if (ps
->pss_error_scrub_state
== DSS_FINISHED
) {
8760 total_secs_left
= end
- start
;
8761 days_left
= total_secs_left
/ 60 / 60 / 24;
8762 hours_left
= (total_secs_left
/ 60 / 60) % 24;
8763 mins_left
= (total_secs_left
/ 60) % 60;
8764 secs_left
= (total_secs_left
% 60);
8766 (void) printf(gettext("scrubbed %llu error blocks in %llu days "
8767 "%02llu:%02llu:%02llu on %s"), (u_longlong_t
)examined
,
8768 (u_longlong_t
)days_left
, (u_longlong_t
)hours_left
,
8769 (u_longlong_t
)mins_left
, (u_longlong_t
)secs_left
,
8773 } else if (ps
->pss_error_scrub_state
== DSS_CANCELED
) {
8774 (void) printf(gettext("error scrub canceled on %s"),
8778 assert(ps
->pss_error_scrub_state
== DSS_ERRORSCRUBBING
);
8780 /* Error scrub is in progress. */
8782 (void) printf(gettext("error scrub in progress since %s"),
8785 (void) printf(gettext("error scrub paused since %s"),
8787 (void) printf(gettext("\terror scrub started on %s"),
8791 double fraction_done
= (double)examined
/ (to_be_examined
+ examined
);
8792 (void) printf(gettext("\t%.2f%% done, issued I/O for %llu error"
8793 " blocks"), 100 * fraction_done
, (u_longlong_t
)examined
);
8795 (void) printf("\n");
8799 * Print out detailed scrub status.
8802 print_scan_scrub_resilver_status(pool_scan_stat_t
*ps
)
8804 time_t start
, end
, pause
;
8805 uint64_t pass_scanned
, scanned
, pass_issued
, issued
, total_s
, total_i
;
8806 uint64_t elapsed
, scan_rate
, issue_rate
;
8807 double fraction_done
;
8808 char processed_buf
[7], scanned_buf
[7], issued_buf
[7], total_s_buf
[7];
8809 char total_i_buf
[7], srate_buf
[7], irate_buf
[7], time_buf
[32];
8812 printf_color(ANSI_BOLD
, gettext("scan:"));
8815 /* If there's never been a scan, there's not much to say. */
8816 if (ps
== NULL
|| ps
->pss_func
== POOL_SCAN_NONE
||
8817 ps
->pss_func
>= POOL_SCAN_FUNCS
) {
8818 (void) printf(gettext("none requested\n"));
8822 start
= ps
->pss_start_time
;
8823 end
= ps
->pss_end_time
;
8824 pause
= ps
->pss_pass_scrub_pause
;
8826 zfs_nicebytes(ps
->pss_processed
, processed_buf
, sizeof (processed_buf
));
8828 int is_resilver
= ps
->pss_func
== POOL_SCAN_RESILVER
;
8829 int is_scrub
= ps
->pss_func
== POOL_SCAN_SCRUB
;
8830 assert(is_resilver
|| is_scrub
);
8832 /* Scan is finished or canceled. */
8833 if (ps
->pss_state
== DSS_FINISHED
) {
8834 secs_to_dhms(end
- start
, time_buf
);
8837 (void) printf(gettext("scrub repaired %s "
8838 "in %s with %llu errors on %s"), processed_buf
,
8839 time_buf
, (u_longlong_t
)ps
->pss_errors
,
8841 } else if (is_resilver
) {
8842 (void) printf(gettext("resilvered %s "
8843 "in %s with %llu errors on %s"), processed_buf
,
8844 time_buf
, (u_longlong_t
)ps
->pss_errors
,
8848 } else if (ps
->pss_state
== DSS_CANCELED
) {
8850 (void) printf(gettext("scrub canceled on %s"),
8852 } else if (is_resilver
) {
8853 (void) printf(gettext("resilver canceled on %s"),
8859 assert(ps
->pss_state
== DSS_SCANNING
);
8861 /* Scan is in progress. Resilvers can't be paused. */
8864 (void) printf(gettext("scrub in progress since %s"),
8867 (void) printf(gettext("scrub paused since %s"),
8869 (void) printf(gettext("\tscrub started on %s"),
8872 } else if (is_resilver
) {
8873 (void) printf(gettext("resilver in progress since %s"),
8877 scanned
= ps
->pss_examined
;
8878 pass_scanned
= ps
->pss_pass_exam
;
8879 issued
= ps
->pss_issued
;
8880 pass_issued
= ps
->pss_pass_issued
;
8881 total_s
= ps
->pss_to_examine
;
8882 total_i
= ps
->pss_to_examine
- ps
->pss_skipped
;
8884 /* we are only done with a block once we have issued the IO for it */
8885 fraction_done
= (double)issued
/ total_i
;
8887 /* elapsed time for this pass, rounding up to 1 if it's 0 */
8888 elapsed
= time(NULL
) - ps
->pss_pass_start
;
8889 elapsed
-= ps
->pss_pass_scrub_spent_paused
;
8890 elapsed
= (elapsed
!= 0) ? elapsed
: 1;
8892 scan_rate
= pass_scanned
/ elapsed
;
8893 issue_rate
= pass_issued
/ elapsed
;
8895 /* format all of the numbers we will be reporting */
8896 zfs_nicebytes(scanned
, scanned_buf
, sizeof (scanned_buf
));
8897 zfs_nicebytes(issued
, issued_buf
, sizeof (issued_buf
));
8898 zfs_nicebytes(total_s
, total_s_buf
, sizeof (total_s_buf
));
8899 zfs_nicebytes(total_i
, total_i_buf
, sizeof (total_i_buf
));
8901 /* do not print estimated time if we have a paused scrub */
8902 (void) printf(gettext("\t%s / %s scanned"), scanned_buf
, total_s_buf
);
8903 if (pause
== 0 && scan_rate
> 0) {
8904 zfs_nicebytes(scan_rate
, srate_buf
, sizeof (srate_buf
));
8905 (void) printf(gettext(" at %s/s"), srate_buf
);
8907 (void) printf(gettext(", %s / %s issued"), issued_buf
, total_i_buf
);
8908 if (pause
== 0 && issue_rate
> 0) {
8909 zfs_nicebytes(issue_rate
, irate_buf
, sizeof (irate_buf
));
8910 (void) printf(gettext(" at %s/s"), irate_buf
);
8912 (void) printf(gettext("\n"));
8915 (void) printf(gettext("\t%s resilvered, %.2f%% done"),
8916 processed_buf
, 100 * fraction_done
);
8917 } else if (is_scrub
) {
8918 (void) printf(gettext("\t%s repaired, %.2f%% done"),
8919 processed_buf
, 100 * fraction_done
);
8924 * Only provide an estimate iff:
8925 * 1) we haven't yet issued all we expected, and
8926 * 2) the issue rate exceeds 10 MB/s, and
8928 * a) a resilver which has started repairs, or
8929 * b) a scrub which has entered the issue phase.
8931 if (total_i
>= issued
&& issue_rate
>= 10 * 1024 * 1024 &&
8932 ((is_resilver
&& ps
->pss_processed
> 0) ||
8933 (is_scrub
&& issued
> 0))) {
8934 secs_to_dhms((total_i
- issued
) / issue_rate
, time_buf
);
8935 (void) printf(gettext(", %s to go\n"), time_buf
);
8937 (void) printf(gettext(", no estimated "
8938 "completion time\n"));
8941 (void) printf(gettext("\n"));
8946 print_rebuild_status_impl(vdev_rebuild_stat_t
*vrs
, uint_t c
, char *vdev_name
)
8948 if (vrs
== NULL
|| vrs
->vrs_state
== VDEV_REBUILD_NONE
)
8952 printf_color(ANSI_BOLD
, gettext("scan:"));
8955 uint64_t bytes_scanned
= vrs
->vrs_bytes_scanned
;
8956 uint64_t bytes_issued
= vrs
->vrs_bytes_issued
;
8957 uint64_t bytes_rebuilt
= vrs
->vrs_bytes_rebuilt
;
8958 uint64_t bytes_est_s
= vrs
->vrs_bytes_est
;
8959 uint64_t bytes_est_i
= vrs
->vrs_bytes_est
;
8960 if (c
> offsetof(vdev_rebuild_stat_t
, vrs_pass_bytes_skipped
) / 8)
8961 bytes_est_i
-= vrs
->vrs_pass_bytes_skipped
;
8962 uint64_t scan_rate
= (vrs
->vrs_pass_bytes_scanned
/
8963 (vrs
->vrs_pass_time_ms
+ 1)) * 1000;
8964 uint64_t issue_rate
= (vrs
->vrs_pass_bytes_issued
/
8965 (vrs
->vrs_pass_time_ms
+ 1)) * 1000;
8966 double scan_pct
= MIN((double)bytes_scanned
* 100 /
8967 (bytes_est_s
+ 1), 100);
8969 /* Format all of the numbers we will be reporting */
8970 char bytes_scanned_buf
[7], bytes_issued_buf
[7];
8971 char bytes_rebuilt_buf
[7], bytes_est_s_buf
[7], bytes_est_i_buf
[7];
8972 char scan_rate_buf
[7], issue_rate_buf
[7], time_buf
[32];
8973 zfs_nicebytes(bytes_scanned
, bytes_scanned_buf
,
8974 sizeof (bytes_scanned_buf
));
8975 zfs_nicebytes(bytes_issued
, bytes_issued_buf
,
8976 sizeof (bytes_issued_buf
));
8977 zfs_nicebytes(bytes_rebuilt
, bytes_rebuilt_buf
,
8978 sizeof (bytes_rebuilt_buf
));
8979 zfs_nicebytes(bytes_est_s
, bytes_est_s_buf
, sizeof (bytes_est_s_buf
));
8980 zfs_nicebytes(bytes_est_i
, bytes_est_i_buf
, sizeof (bytes_est_i_buf
));
8982 time_t start
= vrs
->vrs_start_time
;
8983 time_t end
= vrs
->vrs_end_time
;
8985 /* Rebuild is finished or canceled. */
8986 if (vrs
->vrs_state
== VDEV_REBUILD_COMPLETE
) {
8987 secs_to_dhms(vrs
->vrs_scan_time_ms
/ 1000, time_buf
);
8988 (void) printf(gettext("resilvered (%s) %s in %s "
8989 "with %llu errors on %s"), vdev_name
, bytes_rebuilt_buf
,
8990 time_buf
, (u_longlong_t
)vrs
->vrs_errors
, ctime(&end
));
8992 } else if (vrs
->vrs_state
== VDEV_REBUILD_CANCELED
) {
8993 (void) printf(gettext("resilver (%s) canceled on %s"),
8994 vdev_name
, ctime(&end
));
8996 } else if (vrs
->vrs_state
== VDEV_REBUILD_ACTIVE
) {
8997 (void) printf(gettext("resilver (%s) in progress since %s"),
8998 vdev_name
, ctime(&start
));
9001 assert(vrs
->vrs_state
== VDEV_REBUILD_ACTIVE
);
9003 (void) printf(gettext("\t%s / %s scanned"), bytes_scanned_buf
,
9005 if (scan_rate
> 0) {
9006 zfs_nicebytes(scan_rate
, scan_rate_buf
, sizeof (scan_rate_buf
));
9007 (void) printf(gettext(" at %s/s"), scan_rate_buf
);
9009 (void) printf(gettext(", %s / %s issued"), bytes_issued_buf
,
9011 if (issue_rate
> 0) {
9012 zfs_nicebytes(issue_rate
, issue_rate_buf
,
9013 sizeof (issue_rate_buf
));
9014 (void) printf(gettext(" at %s/s"), issue_rate_buf
);
9016 (void) printf(gettext("\n"));
9018 (void) printf(gettext("\t%s resilvered, %.2f%% done"),
9019 bytes_rebuilt_buf
, scan_pct
);
9021 if (vrs
->vrs_state
== VDEV_REBUILD_ACTIVE
) {
9022 if (bytes_est_s
>= bytes_scanned
&&
9023 scan_rate
>= 10 * 1024 * 1024) {
9024 secs_to_dhms((bytes_est_s
- bytes_scanned
) / scan_rate
,
9026 (void) printf(gettext(", %s to go\n"), time_buf
);
9028 (void) printf(gettext(", no estimated "
9029 "completion time\n"));
9032 (void) printf(gettext("\n"));
9037 * Print rebuild status for top-level vdevs.
9040 print_rebuild_status(zpool_handle_t
*zhp
, nvlist_t
*nvroot
)
9045 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_CHILDREN
,
9046 &child
, &children
) != 0)
9049 for (uint_t c
= 0; c
< children
; c
++) {
9050 vdev_rebuild_stat_t
*vrs
;
9053 if (nvlist_lookup_uint64_array(child
[c
],
9054 ZPOOL_CONFIG_REBUILD_STATS
, (uint64_t **)&vrs
, &i
) == 0) {
9055 char *name
= zpool_vdev_name(g_zfs
, zhp
,
9056 child
[c
], VDEV_NAME_TYPE_ID
);
9057 print_rebuild_status_impl(vrs
, i
, name
);
9064 * As we don't scrub checkpointed blocks, we want to warn the user that we
9065 * skipped scanning some blocks if a checkpoint exists or existed at any
9066 * time during the scan. If a sequential instead of healing reconstruction
9067 * was performed then the blocks were reconstructed. However, their checksums
9068 * have not been verified so we still print the warning.
9071 print_checkpoint_scan_warning(pool_scan_stat_t
*ps
, pool_checkpoint_stat_t
*pcs
)
9073 if (ps
== NULL
|| pcs
== NULL
)
9076 if (pcs
->pcs_state
== CS_NONE
||
9077 pcs
->pcs_state
== CS_CHECKPOINT_DISCARDING
)
9080 assert(pcs
->pcs_state
== CS_CHECKPOINT_EXISTS
);
9082 if (ps
->pss_state
== DSS_NONE
)
9085 if ((ps
->pss_state
== DSS_FINISHED
|| ps
->pss_state
== DSS_CANCELED
) &&
9086 ps
->pss_end_time
< pcs
->pcs_start_time
)
9089 if (ps
->pss_state
== DSS_FINISHED
|| ps
->pss_state
== DSS_CANCELED
) {
9090 (void) printf(gettext(" scan warning: skipped blocks "
9091 "that are only referenced by the checkpoint.\n"));
9093 assert(ps
->pss_state
== DSS_SCANNING
);
9094 (void) printf(gettext(" scan warning: skipping blocks "
9095 "that are only referenced by the checkpoint.\n"));
9100 * Returns B_TRUE if there is an active rebuild in progress. Otherwise,
9101 * B_FALSE is returned and 'rebuild_end_time' is set to the end time for
9102 * the last completed (or cancelled) rebuild.
9105 check_rebuilding(nvlist_t
*nvroot
, uint64_t *rebuild_end_time
)
9109 boolean_t rebuilding
= B_FALSE
;
9110 uint64_t end_time
= 0;
9112 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_CHILDREN
,
9113 &child
, &children
) != 0)
9116 for (uint_t c
= 0; c
< children
; c
++) {
9117 vdev_rebuild_stat_t
*vrs
;
9120 if (nvlist_lookup_uint64_array(child
[c
],
9121 ZPOOL_CONFIG_REBUILD_STATS
, (uint64_t **)&vrs
, &i
) == 0) {
9123 if (vrs
->vrs_end_time
> end_time
)
9124 end_time
= vrs
->vrs_end_time
;
9126 if (vrs
->vrs_state
== VDEV_REBUILD_ACTIVE
) {
9127 rebuilding
= B_TRUE
;
9134 if (rebuild_end_time
!= NULL
)
9135 *rebuild_end_time
= end_time
;
9137 return (rebuilding
);
9141 vdev_stats_nvlist(zpool_handle_t
*zhp
, status_cbdata_t
*cb
, nvlist_t
*nv
,
9142 int depth
, boolean_t isspare
, char *parent
, nvlist_t
*item
)
9144 nvlist_t
*vds
, **child
, *ch
= NULL
;
9145 uint_t vsc
, children
;
9148 uint64_t notpresent
;
9149 const char *type
, *path
;
9151 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
9152 &child
, &children
) != 0)
9154 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
9155 (uint64_t **)&vs
, &vsc
) == 0);
9156 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_TYPE
, &type
) == 0);
9157 if (strcmp(type
, VDEV_TYPE_INDIRECT
) == 0)
9160 if (cb
->cb_print_unhealthy
&& depth
> 0 &&
9161 for_each_vdev_in_nvlist(nv
, vdev_health_check_cb
, cb
) == 0) {
9164 vname
= zpool_vdev_name(g_zfs
, zhp
, nv
,
9165 cb
->cb_name_flags
| VDEV_NAME_TYPE_ID
);
9166 vds
= fnvlist_alloc();
9167 fill_vdev_info(vds
, zhp
, vname
, B_FALSE
, cb
->cb_json_as_int
);
9168 if (cb
->cb_flat_vdevs
&& parent
!= NULL
) {
9169 fnvlist_add_string(vds
, "parent", parent
);
9173 if (vs
->vs_aux
== VDEV_AUX_SPARED
) {
9174 fnvlist_add_string(vds
, "state", "INUSE");
9175 used_by_other(zhp
, nv
, vds
);
9176 } else if (vs
->vs_state
== VDEV_STATE_HEALTHY
)
9177 fnvlist_add_string(vds
, "state", "AVAIL");
9180 nice_num_str_nvlist(vds
, "alloc_space", vs
->vs_alloc
,
9181 cb
->cb_literal
, cb
->cb_json_as_int
,
9185 nice_num_str_nvlist(vds
, "total_space", vs
->vs_space
,
9186 cb
->cb_literal
, cb
->cb_json_as_int
,
9189 if (vs
->vs_dspace
) {
9190 nice_num_str_nvlist(vds
, "def_space", vs
->vs_dspace
,
9191 cb
->cb_literal
, cb
->cb_json_as_int
,
9195 nice_num_str_nvlist(vds
, "rep_dev_size", vs
->vs_rsize
,
9196 cb
->cb_literal
, cb
->cb_json_as_int
,
9200 nice_num_str_nvlist(vds
, "ex_dev_size", vs
->vs_esize
,
9201 cb
->cb_literal
, cb
->cb_json_as_int
,
9204 if (vs
->vs_self_healed
) {
9205 nice_num_str_nvlist(vds
, "self_healed",
9206 vs
->vs_self_healed
, cb
->cb_literal
,
9207 cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9209 if (vs
->vs_pspace
) {
9210 nice_num_str_nvlist(vds
, "phys_space", vs
->vs_pspace
,
9211 cb
->cb_literal
, cb
->cb_json_as_int
,
9214 nice_num_str_nvlist(vds
, "read_errors", vs
->vs_read_errors
,
9215 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_1024
);
9216 nice_num_str_nvlist(vds
, "write_errors", vs
->vs_write_errors
,
9217 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_1024
);
9218 nice_num_str_nvlist(vds
, "checksum_errors",
9219 vs
->vs_checksum_errors
, cb
->cb_literal
,
9220 cb
->cb_json_as_int
, ZFS_NICENUM_1024
);
9221 if (vs
->vs_scan_processed
) {
9222 nice_num_str_nvlist(vds
, "scan_processed",
9223 vs
->vs_scan_processed
, cb
->cb_literal
,
9224 cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9226 if (vs
->vs_checkpoint_space
) {
9227 nice_num_str_nvlist(vds
, "checkpoint_space",
9228 vs
->vs_checkpoint_space
, cb
->cb_literal
,
9229 cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9231 if (vs
->vs_resilver_deferred
) {
9232 nice_num_str_nvlist(vds
, "resilver_deferred",
9233 vs
->vs_resilver_deferred
, B_TRUE
,
9234 cb
->cb_json_as_int
, ZFS_NICENUM_1024
);
9236 if (children
== 0) {
9237 nice_num_str_nvlist(vds
, "slow_ios", vs
->vs_slow_ios
,
9238 cb
->cb_literal
, cb
->cb_json_as_int
,
9241 if (cb
->cb_print_power
) {
9242 if (children
== 0) {
9243 /* Only leaf vdevs have physical slots */
9244 switch (zpool_power_current_state(zhp
, (char *)
9245 fnvlist_lookup_string(nv
,
9246 ZPOOL_CONFIG_PATH
))) {
9248 fnvlist_add_string(vds
, "power_state",
9252 fnvlist_add_string(vds
, "power_state",
9256 fnvlist_add_string(vds
, "power_state",
9260 fnvlist_add_string(vds
, "power_state", "-");
9265 if (cb
->cb_print_dio_verify
) {
9266 nice_num_str_nvlist(vds
, "dio_verify_errors",
9267 vs
->vs_dio_verify_errors
, cb
->cb_literal
,
9268 cb
->cb_json_as_int
, ZFS_NICENUM_1024
);
9271 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_NOT_PRESENT
,
9272 ¬present
) == 0) {
9273 nice_num_str_nvlist(vds
, ZPOOL_CONFIG_NOT_PRESENT
,
9274 1, B_TRUE
, cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9275 fnvlist_add_string(vds
, "was",
9276 fnvlist_lookup_string(nv
, ZPOOL_CONFIG_PATH
));
9277 } else if (vs
->vs_aux
!= VDEV_AUX_NONE
) {
9278 fnvlist_add_string(vds
, "aux", vdev_aux_str
[vs
->vs_aux
]);
9279 } else if (children
== 0 && !isspare
&&
9280 getenv("ZPOOL_STATUS_NON_NATIVE_ASHIFT_IGNORE") == NULL
&&
9281 VDEV_STAT_VALID(vs_physical_ashift
, vsc
) &&
9282 vs
->vs_configured_ashift
< vs
->vs_physical_ashift
) {
9283 nice_num_str_nvlist(vds
, "configured_ashift",
9284 vs
->vs_configured_ashift
, B_TRUE
, cb
->cb_json_as_int
,
9286 nice_num_str_nvlist(vds
, "physical_ashift",
9287 vs
->vs_physical_ashift
, B_TRUE
, cb
->cb_json_as_int
,
9290 if (vs
->vs_scan_removing
!= 0) {
9291 nice_num_str_nvlist(vds
, "removing", vs
->vs_scan_removing
,
9292 B_TRUE
, cb
->cb_json_as_int
, ZFS_NICENUM_1024
);
9293 } else if (VDEV_STAT_VALID(vs_noalloc
, vsc
) && vs
->vs_noalloc
!= 0) {
9294 nice_num_str_nvlist(vds
, "noalloc", vs
->vs_noalloc
,
9295 B_TRUE
, cb
->cb_json_as_int
, ZFS_NICENUM_1024
);
9298 if (cb
->vcdl
!= NULL
) {
9299 if (nvlist_lookup_string(nv
, ZPOOL_CONFIG_PATH
, &path
) == 0) {
9300 zpool_nvlist_cmd(cb
->vcdl
, zpool_get_name(zhp
),
9305 if (children
== 0) {
9306 if (cb
->cb_print_vdev_init
) {
9307 if (vs
->vs_initialize_state
!= 0) {
9308 uint64_t st
= vs
->vs_initialize_state
;
9309 fnvlist_add_string(vds
, "init_state",
9310 vdev_init_state_str
[st
]);
9311 nice_num_str_nvlist(vds
, "initialized",
9312 vs
->vs_initialize_bytes_done
,
9313 cb
->cb_literal
, cb
->cb_json_as_int
,
9315 nice_num_str_nvlist(vds
, "to_initialize",
9316 vs
->vs_initialize_bytes_est
,
9317 cb
->cb_literal
, cb
->cb_json_as_int
,
9319 nice_num_str_nvlist(vds
, "init_time",
9320 vs
->vs_initialize_action_time
,
9321 cb
->cb_literal
, cb
->cb_json_as_int
,
9322 ZFS_NICE_TIMESTAMP
);
9323 nice_num_str_nvlist(vds
, "init_errors",
9324 vs
->vs_initialize_errors
,
9325 cb
->cb_literal
, cb
->cb_json_as_int
,
9328 fnvlist_add_string(vds
, "init_state",
9332 if (cb
->cb_print_vdev_trim
) {
9333 if (vs
->vs_trim_notsup
== 0) {
9334 if (vs
->vs_trim_state
!= 0) {
9335 uint64_t st
= vs
->vs_trim_state
;
9336 fnvlist_add_string(vds
, "trim_state",
9337 vdev_trim_state_str
[st
]);
9338 nice_num_str_nvlist(vds
, "trimmed",
9339 vs
->vs_trim_bytes_done
,
9340 cb
->cb_literal
, cb
->cb_json_as_int
,
9342 nice_num_str_nvlist(vds
, "to_trim",
9343 vs
->vs_trim_bytes_est
,
9344 cb
->cb_literal
, cb
->cb_json_as_int
,
9346 nice_num_str_nvlist(vds
, "trim_time",
9347 vs
->vs_trim_action_time
,
9348 cb
->cb_literal
, cb
->cb_json_as_int
,
9349 ZFS_NICE_TIMESTAMP
);
9350 nice_num_str_nvlist(vds
, "trim_errors",
9352 cb
->cb_literal
, cb
->cb_json_as_int
,
9355 fnvlist_add_string(vds
, "trim_state",
9358 nice_num_str_nvlist(vds
, "trim_notsup",
9359 vs
->vs_trim_notsup
, B_TRUE
,
9360 cb
->cb_json_as_int
, ZFS_NICENUM_1024
);
9363 ch
= fnvlist_alloc();
9366 if (cb
->cb_flat_vdevs
&& children
== 0) {
9367 fnvlist_add_nvlist(item
, vname
, vds
);
9370 for (int c
= 0; c
< children
; c
++) {
9371 uint64_t islog
= B_FALSE
, ishole
= B_FALSE
;
9372 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
9374 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_HOLE
,
9376 if (islog
|| ishole
)
9378 if (nvlist_exists(child
[c
], ZPOOL_CONFIG_ALLOCATION_BIAS
))
9380 if (cb
->cb_flat_vdevs
) {
9381 vdev_stats_nvlist(zhp
, cb
, child
[c
], depth
+ 2, isspare
,
9384 vdev_stats_nvlist(zhp
, cb
, child
[c
], depth
+ 2, isspare
,
9389 if (!nvlist_empty(ch
))
9390 fnvlist_add_nvlist(vds
, "vdevs", ch
);
9393 fnvlist_add_nvlist(item
, vname
, vds
);
9399 class_vdevs_nvlist(zpool_handle_t
*zhp
, status_cbdata_t
*cb
, nvlist_t
*nv
,
9400 const char *class, nvlist_t
*item
)
9404 nvlist_t
*class_obj
= NULL
;
9406 if (!cb
->cb_flat_vdevs
)
9407 class_obj
= fnvlist_alloc();
9409 assert(zhp
!= NULL
|| !cb
->cb_verbose
);
9411 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
, &child
,
9415 for (c
= 0; c
< children
; c
++) {
9416 uint64_t is_log
= B_FALSE
;
9417 const char *bias
= NULL
;
9418 const char *type
= NULL
;
9419 char *name
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
9420 cb
->cb_name_flags
| VDEV_NAME_TYPE_ID
);
9422 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
9426 bias
= (char *)VDEV_ALLOC_CLASS_LOGS
;
9428 (void) nvlist_lookup_string(child
[c
],
9429 ZPOOL_CONFIG_ALLOCATION_BIAS
, &bias
);
9430 (void) nvlist_lookup_string(child
[c
],
9431 ZPOOL_CONFIG_TYPE
, &type
);
9434 if (bias
== NULL
|| strcmp(bias
, class) != 0)
9436 if (!is_log
&& strcmp(type
, VDEV_TYPE_INDIRECT
) == 0)
9439 if (cb
->cb_flat_vdevs
) {
9440 vdev_stats_nvlist(zhp
, cb
, child
[c
], 2, B_FALSE
,
9443 vdev_stats_nvlist(zhp
, cb
, child
[c
], 2, B_FALSE
,
9448 if (!cb
->cb_flat_vdevs
) {
9449 if (!nvlist_empty(class_obj
))
9450 fnvlist_add_nvlist(item
, class, class_obj
);
9451 fnvlist_free(class_obj
);
9456 l2cache_nvlist(zpool_handle_t
*zhp
, status_cbdata_t
*cb
, nvlist_t
*nv
,
9459 nvlist_t
*l2c
= NULL
, **l2cache
;
9461 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
9462 &l2cache
, &nl2cache
) == 0) {
9465 if (!cb
->cb_flat_vdevs
)
9466 l2c
= fnvlist_alloc();
9467 for (int i
= 0; i
< nl2cache
; i
++) {
9468 if (cb
->cb_flat_vdevs
) {
9469 vdev_stats_nvlist(zhp
, cb
, l2cache
[i
], 2,
9470 B_FALSE
, NULL
, item
);
9472 vdev_stats_nvlist(zhp
, cb
, l2cache
[i
], 2,
9473 B_FALSE
, NULL
, l2c
);
9477 if (!cb
->cb_flat_vdevs
) {
9478 if (!nvlist_empty(l2c
))
9479 fnvlist_add_nvlist(item
, "l2cache", l2c
);
9485 spares_nvlist(zpool_handle_t
*zhp
, status_cbdata_t
*cb
, nvlist_t
*nv
,
9488 nvlist_t
*sp
= NULL
, **spares
;
9490 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
9491 &spares
, &nspares
) == 0) {
9494 if (!cb
->cb_flat_vdevs
)
9495 sp
= fnvlist_alloc();
9496 for (int i
= 0; i
< nspares
; i
++) {
9497 if (cb
->cb_flat_vdevs
) {
9498 vdev_stats_nvlist(zhp
, cb
, spares
[i
], 2, B_TRUE
,
9501 vdev_stats_nvlist(zhp
, cb
, spares
[i
], 2, B_TRUE
,
9506 if (!cb
->cb_flat_vdevs
) {
9507 if (!nvlist_empty(sp
))
9508 fnvlist_add_nvlist(item
, "spares", sp
);
9514 errors_nvlist(zpool_handle_t
*zhp
, status_cbdata_t
*cb
, nvlist_t
*item
)
9517 nvlist_t
*config
= zpool_get_config(zhp
, NULL
);
9518 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_ERRCOUNT
,
9520 nice_num_str_nvlist(item
, ZPOOL_CONFIG_ERRCOUNT
, nerr
,
9521 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_1024
);
9522 if (nerr
!= 0 && cb
->cb_verbose
) {
9523 nvlist_t
*nverrlist
= NULL
;
9524 if (zpool_get_errlog(zhp
, &nverrlist
) == 0) {
9527 size_t len
= MAXPATHLEN
* 2;
9528 nvpair_t
*elem
= NULL
;
9530 for (nvpair_t
*pair
=
9531 nvlist_next_nvpair(nverrlist
, NULL
);
9533 pair
= nvlist_next_nvpair(nverrlist
, pair
))
9535 char **errl
= (char **)malloc(
9536 count
* sizeof (char *));
9538 while ((elem
= nvlist_next_nvpair(nverrlist
,
9541 uint64_t dsobj
, obj
;
9543 verify(nvpair_value_nvlist(elem
,
9545 verify(nvlist_lookup_uint64(nv
,
9546 ZPOOL_ERR_DATASET
, &dsobj
) == 0);
9547 verify(nvlist_lookup_uint64(nv
,
9548 ZPOOL_ERR_OBJECT
, &obj
) == 0);
9549 errl
[i
] = safe_malloc(len
);
9550 zpool_obj_to_path(zhp
, dsobj
, obj
,
9553 nvlist_free(nverrlist
);
9554 fnvlist_add_string_array(item
, "errlist",
9555 (const char **)errl
, count
);
9556 for (int i
= 0; i
< count
; ++i
)
9560 fnvlist_add_string(item
, "errlist",
9567 ddt_stats_nvlist(ddt_stat_t
*dds
, status_cbdata_t
*cb
, nvlist_t
*item
)
9569 nice_num_str_nvlist(item
, "blocks", dds
->dds_blocks
,
9570 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_1024
);
9571 nice_num_str_nvlist(item
, "logical_size", dds
->dds_lsize
,
9572 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9573 nice_num_str_nvlist(item
, "physical_size", dds
->dds_psize
,
9574 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9575 nice_num_str_nvlist(item
, "deflated_size", dds
->dds_dsize
,
9576 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9577 nice_num_str_nvlist(item
, "ref_blocks", dds
->dds_ref_blocks
,
9578 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_1024
);
9579 nice_num_str_nvlist(item
, "ref_lsize", dds
->dds_ref_lsize
,
9580 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9581 nice_num_str_nvlist(item
, "ref_psize", dds
->dds_ref_psize
,
9582 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9583 nice_num_str_nvlist(item
, "ref_dsize", dds
->dds_ref_dsize
,
9584 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9588 dedup_stats_nvlist(zpool_handle_t
*zhp
, status_cbdata_t
*cb
, nvlist_t
*item
)
9591 if (cb
->cb_dedup_stats
) {
9592 ddt_histogram_t
*ddh
;
9595 nvlist_t
*ddt_stat
, *ddt_obj
, *dedup
;
9597 uint64_t cspace_prop
;
9599 config
= zpool_get_config(zhp
, NULL
);
9600 if (nvlist_lookup_uint64_array(config
,
9601 ZPOOL_CONFIG_DDT_OBJ_STATS
, (uint64_t **)&ddo
, &c
) != 0)
9604 dedup
= fnvlist_alloc();
9605 ddt_obj
= fnvlist_alloc();
9606 nice_num_str_nvlist(dedup
, "obj_count", ddo
->ddo_count
,
9607 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_1024
);
9608 if (ddo
->ddo_count
== 0) {
9609 fnvlist_add_nvlist(dedup
, ZPOOL_CONFIG_DDT_OBJ_STATS
,
9611 fnvlist_add_nvlist(item
, "dedup_stats", dedup
);
9612 fnvlist_free(ddt_obj
);
9613 fnvlist_free(dedup
);
9616 nice_num_str_nvlist(dedup
, "dspace", ddo
->ddo_dspace
,
9617 cb
->cb_literal
, cb
->cb_json_as_int
,
9619 nice_num_str_nvlist(dedup
, "mspace", ddo
->ddo_mspace
,
9620 cb
->cb_literal
, cb
->cb_json_as_int
,
9623 * Squash cached size into in-core size to handle race.
9624 * Only include cached size if it is available.
9626 cspace_prop
= zpool_get_prop_int(zhp
,
9627 ZPOOL_PROP_DEDUPCACHED
, NULL
);
9628 cspace_prop
= MIN(cspace_prop
, ddo
->ddo_mspace
);
9629 nice_num_str_nvlist(dedup
, "cspace", cspace_prop
,
9630 cb
->cb_literal
, cb
->cb_json_as_int
,
9634 ddt_stat
= fnvlist_alloc();
9635 if (nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_STATS
,
9636 (uint64_t **)&dds
, &c
) == 0) {
9637 nvlist_t
*total
= fnvlist_alloc();
9638 if (dds
->dds_blocks
== 0)
9639 fnvlist_add_string(total
, "blocks", "0");
9641 ddt_stats_nvlist(dds
, cb
, total
);
9642 fnvlist_add_nvlist(ddt_stat
, "total", total
);
9643 fnvlist_free(total
);
9645 if (nvlist_lookup_uint64_array(config
,
9646 ZPOOL_CONFIG_DDT_HISTOGRAM
, (uint64_t **)&ddh
, &c
) == 0) {
9647 nvlist_t
*hist
= fnvlist_alloc();
9648 nvlist_t
*entry
= NULL
;
9650 for (int h
= 0; h
< 64; h
++) {
9651 if (ddh
->ddh_stat
[h
].dds_blocks
!= 0) {
9652 entry
= fnvlist_alloc();
9653 ddt_stats_nvlist(&ddh
->ddh_stat
[h
], cb
,
9655 snprintf(buf
, 16, "%d", h
);
9656 fnvlist_add_nvlist(hist
, buf
, entry
);
9657 fnvlist_free(entry
);
9660 if (!nvlist_empty(hist
))
9661 fnvlist_add_nvlist(ddt_stat
, "histogram", hist
);
9665 if (!nvlist_empty(ddt_obj
)) {
9666 fnvlist_add_nvlist(dedup
, ZPOOL_CONFIG_DDT_OBJ_STATS
,
9669 fnvlist_free(ddt_obj
);
9670 if (!nvlist_empty(ddt_stat
)) {
9671 fnvlist_add_nvlist(dedup
, ZPOOL_CONFIG_DDT_STATS
,
9674 fnvlist_free(ddt_stat
);
9675 if (!nvlist_empty(dedup
))
9676 fnvlist_add_nvlist(item
, "dedup_stats", dedup
);
9677 fnvlist_free(dedup
);
9682 raidz_expand_status_nvlist(zpool_handle_t
*zhp
, status_cbdata_t
*cb
,
9683 nvlist_t
*nvroot
, nvlist_t
*item
)
9686 pool_raidz_expand_stat_t
*pres
= NULL
;
9687 if (nvlist_lookup_uint64_array(nvroot
,
9688 ZPOOL_CONFIG_RAIDZ_EXPAND_STATS
, (uint64_t **)&pres
, &c
) == 0) {
9691 nvlist_t
*nv
= fnvlist_alloc();
9692 verify(nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_CHILDREN
,
9693 &child
, &children
) == 0);
9694 assert(pres
->pres_expanding_vdev
< children
);
9696 zpool_vdev_name(g_zfs
, zhp
,
9697 child
[pres
->pres_expanding_vdev
], 0);
9698 fill_vdev_info(nv
, zhp
, name
, B_FALSE
, cb
->cb_json_as_int
);
9699 fnvlist_add_string(nv
, "state",
9700 pool_scan_state_str
[pres
->pres_state
]);
9701 nice_num_str_nvlist(nv
, "expanding_vdev",
9702 pres
->pres_expanding_vdev
, B_TRUE
, cb
->cb_json_as_int
,
9704 nice_num_str_nvlist(nv
, "start_time", pres
->pres_start_time
,
9705 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICE_TIMESTAMP
);
9706 nice_num_str_nvlist(nv
, "end_time", pres
->pres_end_time
,
9707 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICE_TIMESTAMP
);
9708 nice_num_str_nvlist(nv
, "to_reflow", pres
->pres_to_reflow
,
9709 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9710 nice_num_str_nvlist(nv
, "reflowed", pres
->pres_reflowed
,
9711 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9712 nice_num_str_nvlist(nv
, "waiting_for_resilver",
9713 pres
->pres_waiting_for_resilver
, B_TRUE
,
9714 cb
->cb_json_as_int
, ZFS_NICENUM_1024
);
9715 fnvlist_add_nvlist(item
, ZPOOL_CONFIG_RAIDZ_EXPAND_STATS
, nv
);
9722 checkpoint_status_nvlist(nvlist_t
*nvroot
, status_cbdata_t
*cb
,
9726 pool_checkpoint_stat_t
*pcs
= NULL
;
9727 if (nvlist_lookup_uint64_array(nvroot
,
9728 ZPOOL_CONFIG_CHECKPOINT_STATS
, (uint64_t **)&pcs
, &c
) == 0) {
9729 nvlist_t
*nv
= fnvlist_alloc();
9730 fnvlist_add_string(nv
, "state",
9731 checkpoint_state_str
[pcs
->pcs_state
]);
9732 nice_num_str_nvlist(nv
, "start_time",
9733 pcs
->pcs_start_time
, cb
->cb_literal
, cb
->cb_json_as_int
,
9734 ZFS_NICE_TIMESTAMP
);
9735 nice_num_str_nvlist(nv
, "space",
9736 pcs
->pcs_space
, cb
->cb_literal
, cb
->cb_json_as_int
,
9738 fnvlist_add_nvlist(item
, ZPOOL_CONFIG_CHECKPOINT_STATS
, nv
);
9744 removal_status_nvlist(zpool_handle_t
*zhp
, status_cbdata_t
*cb
,
9745 nvlist_t
*nvroot
, nvlist_t
*item
)
9748 pool_removal_stat_t
*prs
= NULL
;
9749 if (nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_REMOVAL_STATS
,
9750 (uint64_t **)&prs
, &c
) == 0) {
9751 if (prs
->prs_state
!= DSS_NONE
) {
9754 verify(nvlist_lookup_nvlist_array(nvroot
,
9755 ZPOOL_CONFIG_CHILDREN
, &child
, &children
) == 0);
9756 assert(prs
->prs_removing_vdev
< children
);
9757 char *vdev_name
= zpool_vdev_name(g_zfs
, zhp
,
9758 child
[prs
->prs_removing_vdev
], B_TRUE
);
9759 nvlist_t
*nv
= fnvlist_alloc();
9760 fill_vdev_info(nv
, zhp
, vdev_name
, B_FALSE
,
9761 cb
->cb_json_as_int
);
9762 fnvlist_add_string(nv
, "state",
9763 pool_scan_state_str
[prs
->prs_state
]);
9764 nice_num_str_nvlist(nv
, "removing_vdev",
9765 prs
->prs_removing_vdev
, B_TRUE
, cb
->cb_json_as_int
,
9767 nice_num_str_nvlist(nv
, "start_time",
9768 prs
->prs_start_time
, cb
->cb_literal
,
9769 cb
->cb_json_as_int
, ZFS_NICE_TIMESTAMP
);
9770 nice_num_str_nvlist(nv
, "end_time", prs
->prs_end_time
,
9771 cb
->cb_literal
, cb
->cb_json_as_int
,
9772 ZFS_NICE_TIMESTAMP
);
9773 nice_num_str_nvlist(nv
, "to_copy", prs
->prs_to_copy
,
9774 cb
->cb_literal
, cb
->cb_json_as_int
,
9776 nice_num_str_nvlist(nv
, "copied", prs
->prs_copied
,
9777 cb
->cb_literal
, cb
->cb_json_as_int
,
9779 nice_num_str_nvlist(nv
, "mapping_memory",
9780 prs
->prs_mapping_memory
, cb
->cb_literal
,
9781 cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9782 fnvlist_add_nvlist(item
,
9783 ZPOOL_CONFIG_REMOVAL_STATS
, nv
);
9791 scan_status_nvlist(zpool_handle_t
*zhp
, status_cbdata_t
*cb
,
9792 nvlist_t
*nvroot
, nvlist_t
*item
)
9794 pool_scan_stat_t
*ps
= NULL
;
9796 nvlist_t
*scan
= fnvlist_alloc();
9800 if (nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_SCAN_STATS
,
9801 (uint64_t **)&ps
, &c
) == 0) {
9802 fnvlist_add_string(scan
, "function",
9803 pool_scan_func_str
[ps
->pss_func
]);
9804 fnvlist_add_string(scan
, "state",
9805 pool_scan_state_str
[ps
->pss_state
]);
9806 nice_num_str_nvlist(scan
, "start_time", ps
->pss_start_time
,
9807 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICE_TIMESTAMP
);
9808 nice_num_str_nvlist(scan
, "end_time", ps
->pss_end_time
,
9809 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICE_TIMESTAMP
);
9810 nice_num_str_nvlist(scan
, "to_examine", ps
->pss_to_examine
,
9811 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9812 nice_num_str_nvlist(scan
, "examined", ps
->pss_examined
,
9813 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9814 nice_num_str_nvlist(scan
, "skipped", ps
->pss_skipped
,
9815 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9816 nice_num_str_nvlist(scan
, "processed", ps
->pss_processed
,
9817 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9818 nice_num_str_nvlist(scan
, "errors", ps
->pss_errors
,
9819 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_1024
);
9820 nice_num_str_nvlist(scan
, "bytes_per_scan", ps
->pss_pass_exam
,
9821 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9822 nice_num_str_nvlist(scan
, "pass_start", ps
->pss_pass_start
,
9823 B_TRUE
, cb
->cb_json_as_int
, ZFS_NICENUM_1024
);
9824 nice_num_str_nvlist(scan
, "scrub_pause",
9825 ps
->pss_pass_scrub_pause
, cb
->cb_literal
,
9826 cb
->cb_json_as_int
, ZFS_NICE_TIMESTAMP
);
9827 nice_num_str_nvlist(scan
, "scrub_spent_paused",
9828 ps
->pss_pass_scrub_spent_paused
,
9829 B_TRUE
, cb
->cb_json_as_int
, ZFS_NICENUM_1024
);
9830 nice_num_str_nvlist(scan
, "issued_bytes_per_scan",
9831 ps
->pss_pass_issued
, cb
->cb_literal
,
9832 cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9833 nice_num_str_nvlist(scan
, "issued", ps
->pss_issued
,
9834 cb
->cb_literal
, cb
->cb_json_as_int
, ZFS_NICENUM_BYTES
);
9835 if (ps
->pss_error_scrub_func
== POOL_SCAN_ERRORSCRUB
&&
9836 ps
->pss_error_scrub_start
> ps
->pss_start_time
) {
9837 fnvlist_add_string(scan
, "err_scrub_func",
9838 pool_scan_func_str
[ps
->pss_error_scrub_func
]);
9839 fnvlist_add_string(scan
, "err_scrub_state",
9840 pool_scan_state_str
[ps
->pss_error_scrub_state
]);
9841 nice_num_str_nvlist(scan
, "err_scrub_start_time",
9842 ps
->pss_error_scrub_start
,
9843 cb
->cb_literal
, cb
->cb_json_as_int
,
9844 ZFS_NICE_TIMESTAMP
);
9845 nice_num_str_nvlist(scan
, "err_scrub_end_time",
9846 ps
->pss_error_scrub_end
,
9847 cb
->cb_literal
, cb
->cb_json_as_int
,
9848 ZFS_NICE_TIMESTAMP
);
9849 nice_num_str_nvlist(scan
, "err_scrub_examined",
9850 ps
->pss_error_scrub_examined
,
9851 cb
->cb_literal
, cb
->cb_json_as_int
,
9853 nice_num_str_nvlist(scan
, "err_scrub_to_examine",
9854 ps
->pss_error_scrub_to_be_examined
,
9855 cb
->cb_literal
, cb
->cb_json_as_int
,
9857 nice_num_str_nvlist(scan
, "err_scrub_pause",
9858 ps
->pss_pass_error_scrub_pause
,
9859 B_TRUE
, cb
->cb_json_as_int
, ZFS_NICENUM_1024
);
9863 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_CHILDREN
,
9864 &child
, &children
) == 0) {
9865 vdev_rebuild_stat_t
*vrs
;
9869 nvlist_t
*rebuild
= fnvlist_alloc();
9871 for (uint_t c
= 0; c
< children
; c
++) {
9872 if (nvlist_lookup_uint64_array(child
[c
],
9873 ZPOOL_CONFIG_REBUILD_STATS
, (uint64_t **)&vrs
,
9875 if (vrs
->vrs_state
!= VDEV_REBUILD_NONE
) {
9876 nv
= fnvlist_alloc();
9877 name
= zpool_vdev_name(g_zfs
, zhp
,
9878 child
[c
], VDEV_NAME_TYPE_ID
);
9879 fill_vdev_info(nv
, zhp
, name
, B_FALSE
,
9880 cb
->cb_json_as_int
);
9881 st
= vrs
->vrs_state
;
9882 fnvlist_add_string(nv
, "state",
9883 vdev_rebuild_state_str
[st
]);
9884 nice_num_str_nvlist(nv
, "start_time",
9885 vrs
->vrs_start_time
, cb
->cb_literal
,
9887 ZFS_NICE_TIMESTAMP
);
9888 nice_num_str_nvlist(nv
, "end_time",
9889 vrs
->vrs_end_time
, cb
->cb_literal
,
9891 ZFS_NICE_TIMESTAMP
);
9892 nice_num_str_nvlist(nv
, "scan_time",
9893 vrs
->vrs_scan_time_ms
* 1000000,
9894 cb
->cb_literal
, cb
->cb_json_as_int
,
9896 nice_num_str_nvlist(nv
, "scanned",
9897 vrs
->vrs_bytes_scanned
,
9898 cb
->cb_literal
, cb
->cb_json_as_int
,
9900 nice_num_str_nvlist(nv
, "issued",
9901 vrs
->vrs_bytes_issued
,
9902 cb
->cb_literal
, cb
->cb_json_as_int
,
9904 nice_num_str_nvlist(nv
, "rebuilt",
9905 vrs
->vrs_bytes_rebuilt
,
9906 cb
->cb_literal
, cb
->cb_json_as_int
,
9908 nice_num_str_nvlist(nv
, "to_scan",
9909 vrs
->vrs_bytes_est
, cb
->cb_literal
,
9912 nice_num_str_nvlist(nv
, "errors",
9913 vrs
->vrs_errors
, cb
->cb_literal
,
9916 nice_num_str_nvlist(nv
, "pass_time",
9917 vrs
->vrs_pass_time_ms
* 1000000,
9918 cb
->cb_literal
, cb
->cb_json_as_int
,
9920 nice_num_str_nvlist(nv
, "pass_scanned",
9921 vrs
->vrs_pass_bytes_scanned
,
9922 cb
->cb_literal
, cb
->cb_json_as_int
,
9924 nice_num_str_nvlist(nv
, "pass_issued",
9925 vrs
->vrs_pass_bytes_issued
,
9926 cb
->cb_literal
, cb
->cb_json_as_int
,
9928 nice_num_str_nvlist(nv
, "pass_skipped",
9929 vrs
->vrs_pass_bytes_skipped
,
9930 cb
->cb_literal
, cb
->cb_json_as_int
,
9932 fnvlist_add_nvlist(rebuild
, name
, nv
);
9937 if (!nvlist_empty(rebuild
))
9938 fnvlist_add_nvlist(scan
, "rebuild_stats", rebuild
);
9939 fnvlist_free(rebuild
);
9942 if (!nvlist_empty(scan
))
9943 fnvlist_add_nvlist(item
, ZPOOL_CONFIG_SCAN_STATS
, scan
);
9948 * Print the scan status.
9951 print_scan_status(zpool_handle_t
*zhp
, nvlist_t
*nvroot
)
9953 uint64_t rebuild_end_time
= 0, resilver_end_time
= 0;
9954 boolean_t have_resilver
= B_FALSE
, have_scrub
= B_FALSE
;
9955 boolean_t have_errorscrub
= B_FALSE
;
9956 boolean_t active_resilver
= B_FALSE
;
9957 pool_checkpoint_stat_t
*pcs
= NULL
;
9958 pool_scan_stat_t
*ps
= NULL
;
9960 time_t scrub_start
= 0, errorscrub_start
= 0;
9962 if (nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_SCAN_STATS
,
9963 (uint64_t **)&ps
, &c
) == 0) {
9964 if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
9965 resilver_end_time
= ps
->pss_end_time
;
9966 active_resilver
= (ps
->pss_state
== DSS_SCANNING
);
9969 have_resilver
= (ps
->pss_func
== POOL_SCAN_RESILVER
);
9970 have_scrub
= (ps
->pss_func
== POOL_SCAN_SCRUB
);
9971 scrub_start
= ps
->pss_start_time
;
9972 if (c
> offsetof(pool_scan_stat_t
,
9973 pss_pass_error_scrub_pause
) / 8) {
9974 have_errorscrub
= (ps
->pss_error_scrub_func
==
9975 POOL_SCAN_ERRORSCRUB
);
9976 errorscrub_start
= ps
->pss_error_scrub_start
;
9980 boolean_t active_rebuild
= check_rebuilding(nvroot
, &rebuild_end_time
);
9981 boolean_t have_rebuild
= (active_rebuild
|| (rebuild_end_time
> 0));
9983 /* Always print the scrub status when available. */
9984 if (have_scrub
&& scrub_start
> errorscrub_start
)
9985 print_scan_scrub_resilver_status(ps
);
9986 else if (have_errorscrub
&& errorscrub_start
>= scrub_start
)
9987 print_err_scrub_status(ps
);
9990 * When there is an active resilver or rebuild print its status.
9991 * Otherwise print the status of the last resilver or rebuild.
9993 if (active_resilver
|| (!active_rebuild
&& have_resilver
&&
9994 resilver_end_time
&& resilver_end_time
> rebuild_end_time
)) {
9995 print_scan_scrub_resilver_status(ps
);
9996 } else if (active_rebuild
|| (!active_resilver
&& have_rebuild
&&
9997 rebuild_end_time
&& rebuild_end_time
> resilver_end_time
)) {
9998 print_rebuild_status(zhp
, nvroot
);
10001 (void) nvlist_lookup_uint64_array(nvroot
,
10002 ZPOOL_CONFIG_CHECKPOINT_STATS
, (uint64_t **)&pcs
, &c
);
10003 print_checkpoint_scan_warning(ps
, pcs
);
10007 * Print out detailed removal status.
10010 print_removal_status(zpool_handle_t
*zhp
, pool_removal_stat_t
*prs
)
10012 char copied_buf
[7], examined_buf
[7], total_buf
[7], rate_buf
[7];
10014 nvlist_t
*config
, *nvroot
;
10019 if (prs
== NULL
|| prs
->prs_state
== DSS_NONE
)
10023 * Determine name of vdev.
10025 config
= zpool_get_config(zhp
, NULL
);
10026 nvroot
= fnvlist_lookup_nvlist(config
,
10027 ZPOOL_CONFIG_VDEV_TREE
);
10028 verify(nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_CHILDREN
,
10029 &child
, &children
) == 0);
10030 assert(prs
->prs_removing_vdev
< children
);
10031 vdev_name
= zpool_vdev_name(g_zfs
, zhp
,
10032 child
[prs
->prs_removing_vdev
], B_TRUE
);
10034 printf_color(ANSI_BOLD
, gettext("remove: "));
10036 start
= prs
->prs_start_time
;
10037 end
= prs
->prs_end_time
;
10038 zfs_nicenum(prs
->prs_copied
, copied_buf
, sizeof (copied_buf
));
10041 * Removal is finished or canceled.
10043 if (prs
->prs_state
== DSS_FINISHED
) {
10044 uint64_t minutes_taken
= (end
- start
) / 60;
10046 (void) printf(gettext("Removal of vdev %llu copied %s "
10047 "in %lluh%um, completed on %s"),
10048 (longlong_t
)prs
->prs_removing_vdev
,
10050 (u_longlong_t
)(minutes_taken
/ 60),
10051 (uint_t
)(minutes_taken
% 60),
10052 ctime((time_t *)&end
));
10053 } else if (prs
->prs_state
== DSS_CANCELED
) {
10054 (void) printf(gettext("Removal of %s canceled on %s"),
10055 vdev_name
, ctime(&end
));
10057 uint64_t copied
, total
, elapsed
, rate
, mins_left
, hours_left
;
10058 double fraction_done
;
10060 assert(prs
->prs_state
== DSS_SCANNING
);
10063 * Removal is in progress.
10065 (void) printf(gettext(
10066 "Evacuation of %s in progress since %s"),
10067 vdev_name
, ctime(&start
));
10069 copied
= prs
->prs_copied
> 0 ? prs
->prs_copied
: 1;
10070 total
= prs
->prs_to_copy
;
10071 fraction_done
= (double)copied
/ total
;
10073 /* elapsed time for this pass */
10074 elapsed
= time(NULL
) - prs
->prs_start_time
;
10075 elapsed
= elapsed
> 0 ? elapsed
: 1;
10076 rate
= copied
/ elapsed
;
10077 rate
= rate
> 0 ? rate
: 1;
10078 mins_left
= ((total
- copied
) / rate
) / 60;
10079 hours_left
= mins_left
/ 60;
10081 zfs_nicenum(copied
, examined_buf
, sizeof (examined_buf
));
10082 zfs_nicenum(total
, total_buf
, sizeof (total_buf
));
10083 zfs_nicenum(rate
, rate_buf
, sizeof (rate_buf
));
10086 * do not print estimated time if hours_left is more than
10089 (void) printf(gettext(
10090 "\t%s copied out of %s at %s/s, %.2f%% done"),
10091 examined_buf
, total_buf
, rate_buf
, 100 * fraction_done
);
10092 if (hours_left
< (30 * 24)) {
10093 (void) printf(gettext(", %lluh%um to go\n"),
10094 (u_longlong_t
)hours_left
, (uint_t
)(mins_left
% 60));
10096 (void) printf(gettext(
10097 ", (copy is slow, no estimated time)\n"));
10102 if (prs
->prs_mapping_memory
> 0) {
10104 zfs_nicenum(prs
->prs_mapping_memory
, mem_buf
, sizeof (mem_buf
));
10105 (void) printf(gettext(
10106 "\t%s memory used for removed device mappings\n"),
10112 * Print out detailed raidz expansion status.
10115 print_raidz_expand_status(zpool_handle_t
*zhp
, pool_raidz_expand_stat_t
*pres
)
10117 char copied_buf
[7];
10119 if (pres
== NULL
|| pres
->pres_state
== DSS_NONE
)
10123 * Determine name of vdev.
10125 nvlist_t
*config
= zpool_get_config(zhp
, NULL
);
10126 nvlist_t
*nvroot
= fnvlist_lookup_nvlist(config
,
10127 ZPOOL_CONFIG_VDEV_TREE
);
10130 verify(nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_CHILDREN
,
10131 &child
, &children
) == 0);
10132 assert(pres
->pres_expanding_vdev
< children
);
10134 printf_color(ANSI_BOLD
, gettext("expand: "));
10136 time_t start
= pres
->pres_start_time
;
10137 time_t end
= pres
->pres_end_time
;
10139 zpool_vdev_name(g_zfs
, zhp
, child
[pres
->pres_expanding_vdev
], 0);
10140 zfs_nicenum(pres
->pres_reflowed
, copied_buf
, sizeof (copied_buf
));
10143 * Expansion is finished or canceled.
10145 if (pres
->pres_state
== DSS_FINISHED
) {
10147 secs_to_dhms(end
- start
, time_buf
);
10149 (void) printf(gettext("expanded %s-%u copied %s in %s, "
10150 "on %s"), vname
, (int)pres
->pres_expanding_vdev
,
10151 copied_buf
, time_buf
, ctime((time_t *)&end
));
10153 char examined_buf
[7], total_buf
[7], rate_buf
[7];
10154 uint64_t copied
, total
, elapsed
, rate
, secs_left
;
10155 double fraction_done
;
10157 assert(pres
->pres_state
== DSS_SCANNING
);
10160 * Expansion is in progress.
10162 (void) printf(gettext(
10163 "expansion of %s-%u in progress since %s"),
10164 vname
, (int)pres
->pres_expanding_vdev
, ctime(&start
));
10166 copied
= pres
->pres_reflowed
> 0 ? pres
->pres_reflowed
: 1;
10167 total
= pres
->pres_to_reflow
;
10168 fraction_done
= (double)copied
/ total
;
10170 /* elapsed time for this pass */
10171 elapsed
= time(NULL
) - pres
->pres_start_time
;
10172 elapsed
= elapsed
> 0 ? elapsed
: 1;
10173 rate
= copied
/ elapsed
;
10174 rate
= rate
> 0 ? rate
: 1;
10175 secs_left
= (total
- copied
) / rate
;
10177 zfs_nicenum(copied
, examined_buf
, sizeof (examined_buf
));
10178 zfs_nicenum(total
, total_buf
, sizeof (total_buf
));
10179 zfs_nicenum(rate
, rate_buf
, sizeof (rate_buf
));
10182 * do not print estimated time if hours_left is more than
10185 (void) printf(gettext("\t%s / %s copied at %s/s, %.2f%% done"),
10186 examined_buf
, total_buf
, rate_buf
, 100 * fraction_done
);
10187 if (pres
->pres_waiting_for_resilver
) {
10188 (void) printf(gettext(", paused for resilver or "
10190 } else if (secs_left
< (30 * 24 * 3600)) {
10192 secs_to_dhms(secs_left
, time_buf
);
10193 (void) printf(gettext(", %s to go\n"), time_buf
);
10195 (void) printf(gettext(
10196 ", (copy is slow, no estimated time)\n"));
10202 print_checkpoint_status(pool_checkpoint_stat_t
*pcs
)
10207 if (pcs
== NULL
|| pcs
->pcs_state
== CS_NONE
)
10210 (void) printf(gettext("checkpoint: "));
10212 start
= pcs
->pcs_start_time
;
10213 zfs_nicenum(pcs
->pcs_space
, space_buf
, sizeof (space_buf
));
10215 if (pcs
->pcs_state
== CS_CHECKPOINT_EXISTS
) {
10216 char *date
= ctime(&start
);
10219 * ctime() adds a newline at the end of the generated
10220 * string, thus the weird format specifier and the
10221 * strlen() call used to chop it off from the output.
10223 (void) printf(gettext("created %.*s, consumes %s\n"),
10224 (int)(strlen(date
) - 1), date
, space_buf
);
10228 assert(pcs
->pcs_state
== CS_CHECKPOINT_DISCARDING
);
10230 (void) printf(gettext("discarding, %s remaining.\n"),
10235 print_error_log(zpool_handle_t
*zhp
)
10237 nvlist_t
*nverrlist
= NULL
;
10240 size_t len
= MAXPATHLEN
* 2;
10242 if (zpool_get_errlog(zhp
, &nverrlist
) != 0)
10245 (void) printf("errors: Permanent errors have been "
10246 "detected in the following files:\n\n");
10248 pathname
= safe_malloc(len
);
10250 while ((elem
= nvlist_next_nvpair(nverrlist
, elem
)) != NULL
) {
10252 uint64_t dsobj
, obj
;
10254 verify(nvpair_value_nvlist(elem
, &nv
) == 0);
10255 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_DATASET
,
10257 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_OBJECT
,
10259 zpool_obj_to_path(zhp
, dsobj
, obj
, pathname
, len
);
10260 (void) printf("%7s %s\n", "", pathname
);
10263 nvlist_free(nverrlist
);
10267 print_spares(zpool_handle_t
*zhp
, status_cbdata_t
*cb
, nvlist_t
**spares
,
10276 (void) printf(gettext("\tspares\n"));
10278 for (i
= 0; i
< nspares
; i
++) {
10279 name
= zpool_vdev_name(g_zfs
, zhp
, spares
[i
],
10280 cb
->cb_name_flags
);
10281 print_status_config(zhp
, cb
, name
, spares
[i
], 2, B_TRUE
, NULL
);
10287 print_l2cache(zpool_handle_t
*zhp
, status_cbdata_t
*cb
, nvlist_t
**l2cache
,
10296 (void) printf(gettext("\tcache\n"));
10298 for (i
= 0; i
< nl2cache
; i
++) {
10299 name
= zpool_vdev_name(g_zfs
, zhp
, l2cache
[i
],
10300 cb
->cb_name_flags
);
10301 print_status_config(zhp
, cb
, name
, l2cache
[i
], 2,
10308 print_dedup_stats(zpool_handle_t
*zhp
, nvlist_t
*config
, boolean_t literal
)
10310 ddt_histogram_t
*ddh
;
10314 /* Extra space provided for literal display */
10315 char dspace
[32], mspace
[32], cspace
[32];
10316 uint64_t cspace_prop
;
10317 enum zfs_nicenum_format format
;
10318 zprop_source_t src
;
10321 * If the pool was faulted then we may not have been able to
10322 * obtain the config. Otherwise, if we have anything in the dedup
10323 * table continue processing the stats.
10325 if (nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_OBJ_STATS
,
10326 (uint64_t **)&ddo
, &c
) != 0)
10329 (void) printf("\n");
10330 (void) printf(gettext(" dedup: "));
10331 if (ddo
->ddo_count
== 0) {
10332 (void) printf(gettext("no DDT entries\n"));
10337 * Squash cached size into in-core size to handle race.
10338 * Only include cached size if it is available.
10340 cspace_prop
= zpool_get_prop_int(zhp
, ZPOOL_PROP_DEDUPCACHED
, &src
);
10341 cspace_prop
= MIN(cspace_prop
, ddo
->ddo_mspace
);
10342 format
= literal
? ZFS_NICENUM_RAW
: ZFS_NICENUM_1024
;
10343 zfs_nicenum_format(cspace_prop
, cspace
, sizeof (cspace
), format
);
10344 zfs_nicenum_format(ddo
->ddo_dspace
, dspace
, sizeof (dspace
), format
);
10345 zfs_nicenum_format(ddo
->ddo_mspace
, mspace
, sizeof (mspace
), format
);
10346 (void) printf("DDT entries %llu, size %s on disk, %s in core",
10347 (u_longlong_t
)ddo
->ddo_count
,
10350 if (src
!= ZPROP_SRC_DEFAULT
) {
10351 (void) printf(", %s cached (%.02f%%)",
10353 (double)cspace_prop
/ (double)ddo
->ddo_mspace
* 100.0);
10355 (void) printf("\n");
10357 verify(nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_STATS
,
10358 (uint64_t **)&dds
, &c
) == 0);
10359 verify(nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_HISTOGRAM
,
10360 (uint64_t **)&ddh
, &c
) == 0);
10361 zpool_dump_ddt(dds
, ddh
);
10364 #define ST_SIZE 4096
10365 #define AC_SIZE 2048
10368 print_status_reason(zpool_handle_t
*zhp
, status_cbdata_t
*cbp
,
10369 zpool_status_t reason
, zpool_errata_t errata
, nvlist_t
*item
)
10371 char status
[ST_SIZE
];
10372 char action
[AC_SIZE
];
10373 memset(status
, 0, ST_SIZE
);
10374 memset(action
, 0, AC_SIZE
);
10377 case ZPOOL_STATUS_MISSING_DEV_R
:
10378 snprintf(status
, ST_SIZE
, gettext("One or more devices could "
10379 "not be opened. Sufficient replicas exist for\n\tthe pool "
10380 "to continue functioning in a degraded state.\n"));
10381 snprintf(action
, AC_SIZE
, gettext("Attach the missing device "
10382 "and online it using 'zpool online'.\n"));
10385 case ZPOOL_STATUS_MISSING_DEV_NR
:
10386 snprintf(status
, ST_SIZE
, gettext("One or more devices could "
10387 "not be opened. There are insufficient\n\treplicas for the"
10388 " pool to continue functioning.\n"));
10389 snprintf(action
, AC_SIZE
, gettext("Attach the missing device "
10390 "and online it using 'zpool online'.\n"));
10393 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
10394 snprintf(status
, ST_SIZE
, gettext("One or more devices could "
10395 "not be used because the label is missing or\n\tinvalid. "
10396 "Sufficient replicas exist for the pool to continue\n\t"
10397 "functioning in a degraded state.\n"));
10398 snprintf(action
, AC_SIZE
, gettext("Replace the device using "
10399 "'zpool replace'.\n"));
10402 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
10403 snprintf(status
, ST_SIZE
, gettext("One or more devices could "
10404 "not be used because the label is missing \n\tor invalid. "
10405 "There are insufficient replicas for the pool to "
10406 "continue\n\tfunctioning.\n"));
10407 zpool_explain_recover(zpool_get_handle(zhp
),
10408 zpool_get_name(zhp
), reason
, zpool_get_config(zhp
, NULL
),
10412 case ZPOOL_STATUS_FAILING_DEV
:
10413 snprintf(status
, ST_SIZE
, gettext("One or more devices has "
10414 "experienced an unrecoverable error. An\n\tattempt was "
10415 "made to correct the error. Applications are "
10417 snprintf(action
, AC_SIZE
, gettext("Determine if the "
10418 "device needs to be replaced, and clear the errors\n\tusing"
10419 " 'zpool clear' or replace the device with 'zpool "
10423 case ZPOOL_STATUS_OFFLINE_DEV
:
10424 snprintf(status
, ST_SIZE
, gettext("One or more devices has "
10425 "been taken offline by the administrator.\n\tSufficient "
10426 "replicas exist for the pool to continue functioning in "
10427 "a\n\tdegraded state.\n"));
10428 snprintf(action
, AC_SIZE
, gettext("Online the device "
10429 "using 'zpool online' or replace the device with\n\t'zpool "
10433 case ZPOOL_STATUS_REMOVED_DEV
:
10434 snprintf(status
, ST_SIZE
, gettext("One or more devices has "
10435 "been removed by the administrator.\n\tSufficient "
10436 "replicas exist for the pool to continue functioning in "
10437 "a\n\tdegraded state.\n"));
10438 snprintf(action
, AC_SIZE
, gettext("Online the device "
10439 "using zpool online' or replace the device with\n\t'zpool "
10443 case ZPOOL_STATUS_RESILVERING
:
10444 case ZPOOL_STATUS_REBUILDING
:
10445 snprintf(status
, ST_SIZE
, gettext("One or more devices is "
10446 "currently being resilvered. The pool will\n\tcontinue "
10447 "to function, possibly in a degraded state.\n"));
10448 snprintf(action
, AC_SIZE
, gettext("Wait for the resilver to "
10452 case ZPOOL_STATUS_REBUILD_SCRUB
:
10453 snprintf(status
, ST_SIZE
, gettext("One or more devices have "
10454 "been sequentially resilvered, scrubbing\n\tthe pool "
10455 "is recommended.\n"));
10456 snprintf(action
, AC_SIZE
, gettext("Use 'zpool scrub' to "
10457 "verify all data checksums.\n"));
10460 case ZPOOL_STATUS_CORRUPT_DATA
:
10461 snprintf(status
, ST_SIZE
, gettext("One or more devices has "
10462 "experienced an error resulting in data\n\tcorruption. "
10463 "Applications may be affected.\n"));
10464 snprintf(action
, AC_SIZE
, gettext("Restore the file in question"
10465 " if possible. Otherwise restore the\n\tentire pool from "
10469 case ZPOOL_STATUS_CORRUPT_POOL
:
10470 snprintf(status
, ST_SIZE
, gettext("The pool metadata is "
10471 "corrupted and the pool cannot be opened.\n"));
10472 zpool_explain_recover(zpool_get_handle(zhp
),
10473 zpool_get_name(zhp
), reason
, zpool_get_config(zhp
, NULL
),
10477 case ZPOOL_STATUS_VERSION_OLDER
:
10478 snprintf(status
, ST_SIZE
, gettext("The pool is formatted using "
10479 "a legacy on-disk format. The pool can\n\tstill be used, "
10480 "but some features are unavailable.\n"));
10481 snprintf(action
, AC_SIZE
, gettext("Upgrade the pool using "
10482 "'zpool upgrade'. Once this is done, the\n\tpool will no "
10483 "longer be accessible on software that does not support\n\t"
10484 "feature flags.\n"));
10487 case ZPOOL_STATUS_VERSION_NEWER
:
10488 snprintf(status
, ST_SIZE
, gettext("The pool has been upgraded "
10489 "to a newer, incompatible on-disk version.\n\tThe pool "
10490 "cannot be accessed on this system.\n"));
10491 snprintf(action
, AC_SIZE
, gettext("Access the pool from a "
10492 "system running more recent software, or\n\trestore the "
10493 "pool from backup.\n"));
10496 case ZPOOL_STATUS_FEAT_DISABLED
:
10497 snprintf(status
, ST_SIZE
, gettext("Some supported and "
10498 "requested features are not enabled on the pool.\n\t"
10499 "The pool can still be used, but some features are "
10500 "unavailable.\n"));
10501 snprintf(action
, AC_SIZE
, gettext("Enable all features using "
10502 "'zpool upgrade'. Once this is done,\n\tthe pool may no "
10503 "longer be accessible by software that does not support\n\t"
10504 "the features. See zpool-features(7) for details.\n"));
10507 case ZPOOL_STATUS_COMPATIBILITY_ERR
:
10508 snprintf(status
, ST_SIZE
, gettext("This pool has a "
10509 "compatibility list specified, but it could not be\n\t"
10510 "read/parsed at this time. The pool can still be used, "
10511 "but this\n\tshould be investigated.\n"));
10512 snprintf(action
, AC_SIZE
, gettext("Check the value of the "
10513 "'compatibility' property against the\n\t"
10514 "appropriate file in " ZPOOL_SYSCONF_COMPAT_D
" or "
10515 ZPOOL_DATA_COMPAT_D
".\n"));
10518 case ZPOOL_STATUS_INCOMPATIBLE_FEAT
:
10519 snprintf(status
, ST_SIZE
, gettext("One or more features "
10520 "are enabled on the pool despite not being\n\t"
10521 "requested by the 'compatibility' property.\n"));
10522 snprintf(action
, AC_SIZE
, gettext("Consider setting "
10523 "'compatibility' to an appropriate value, or\n\t"
10524 "adding needed features to the relevant file in\n\t"
10525 ZPOOL_SYSCONF_COMPAT_D
" or " ZPOOL_DATA_COMPAT_D
".\n"));
10528 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
10529 snprintf(status
, ST_SIZE
, gettext("The pool cannot be accessed "
10530 "on this system because it uses the\n\tfollowing feature(s)"
10531 " not supported on this system:\n"));
10532 zpool_collect_unsup_feat(zpool_get_config(zhp
, NULL
), status
,
10534 snprintf(action
, AC_SIZE
, gettext("Access the pool from a "
10535 "system that supports the required feature(s),\n\tor "
10536 "restore the pool from backup.\n"));
10539 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
10540 snprintf(status
, ST_SIZE
, gettext("The pool can only be "
10541 "accessed in read-only mode on this system. It\n\tcannot be"
10542 " accessed in read-write mode because it uses the "
10543 "following\n\tfeature(s) not supported on this system:\n"));
10544 zpool_collect_unsup_feat(zpool_get_config(zhp
, NULL
), status
,
10546 snprintf(action
, AC_SIZE
, gettext("The pool cannot be accessed "
10547 "in read-write mode. Import the pool with\n"
10548 "\t\"-o readonly=on\", access the pool from a system that "
10549 "supports the\n\trequired feature(s), or restore the "
10550 "pool from backup.\n"));
10553 case ZPOOL_STATUS_FAULTED_DEV_R
:
10554 snprintf(status
, ST_SIZE
, gettext("One or more devices are "
10555 "faulted in response to persistent errors.\n\tSufficient "
10556 "replicas exist for the pool to continue functioning "
10557 "in a\n\tdegraded state.\n"));
10558 snprintf(action
, AC_SIZE
, gettext("Replace the faulted device, "
10559 "or use 'zpool clear' to mark the device\n\trepaired.\n"));
10562 case ZPOOL_STATUS_FAULTED_DEV_NR
:
10563 snprintf(status
, ST_SIZE
, gettext("One or more devices are "
10564 "faulted in response to persistent errors. There are "
10565 "insufficient replicas for the pool to\n\tcontinue "
10566 "functioning.\n"));
10567 snprintf(action
, AC_SIZE
, gettext("Destroy and re-create the "
10568 "pool from a backup source. Manually marking the device\n"
10569 "\trepaired using 'zpool clear' may allow some data "
10570 "to be recovered.\n"));
10573 case ZPOOL_STATUS_IO_FAILURE_MMP
:
10574 snprintf(status
, ST_SIZE
, gettext("The pool is suspended "
10575 "because multihost writes failed or were delayed;\n\t"
10576 "another system could import the pool undetected.\n"));
10577 snprintf(action
, AC_SIZE
, gettext("Make sure the pool's devices"
10578 " are connected, then reboot your system and\n\timport the "
10579 "pool or run 'zpool clear' to resume the pool.\n"));
10582 case ZPOOL_STATUS_IO_FAILURE_WAIT
:
10583 case ZPOOL_STATUS_IO_FAILURE_CONTINUE
:
10584 snprintf(status
, ST_SIZE
, gettext("One or more devices are "
10585 "faulted in response to IO failures.\n"));
10586 snprintf(action
, AC_SIZE
, gettext("Make sure the affected "
10587 "devices are connected, then run 'zpool clear'.\n"));
10590 case ZPOOL_STATUS_BAD_LOG
:
10591 snprintf(status
, ST_SIZE
, gettext("An intent log record "
10592 "could not be read.\n"
10593 "\tWaiting for administrator intervention to fix the "
10594 "faulted pool.\n"));
10595 snprintf(action
, AC_SIZE
, gettext("Either restore the affected "
10596 "device(s) and run 'zpool online',\n"
10597 "\tor ignore the intent log records by running "
10598 "'zpool clear'.\n"));
10601 case ZPOOL_STATUS_NON_NATIVE_ASHIFT
:
10602 snprintf(status
, ST_SIZE
, gettext("One or more devices are "
10603 "configured to use a non-native block size.\n"
10604 "\tExpect reduced performance.\n"));
10605 snprintf(action
, AC_SIZE
, gettext("Replace affected devices "
10606 "with devices that support the\n\tconfigured block size, "
10607 "or migrate data to a properly configured\n\tpool.\n"));
10610 case ZPOOL_STATUS_HOSTID_MISMATCH
:
10611 snprintf(status
, ST_SIZE
, gettext("Mismatch between pool hostid"
10612 " and system hostid on imported pool.\n\tThis pool was "
10613 "previously imported into a system with a different "
10614 "hostid,\n\tand then was verbatim imported into this "
10616 snprintf(action
, AC_SIZE
, gettext("Export this pool on all "
10617 "systems on which it is imported.\n"
10618 "\tThen import it to correct the mismatch.\n"));
10621 case ZPOOL_STATUS_ERRATA
:
10622 snprintf(status
, ST_SIZE
, gettext("Errata #%d detected.\n"),
10625 case ZPOOL_ERRATA_NONE
:
10628 case ZPOOL_ERRATA_ZOL_2094_SCRUB
:
10629 snprintf(action
, AC_SIZE
, gettext("To correct the issue"
10630 " run 'zpool scrub'.\n"));
10633 case ZPOOL_ERRATA_ZOL_6845_ENCRYPTION
:
10634 (void) strlcat(status
, gettext("\tExisting encrypted "
10635 "datasets contain an on-disk incompatibility\n\t "
10636 "which needs to be corrected.\n"), ST_SIZE
);
10637 snprintf(action
, AC_SIZE
, gettext("To correct the issue"
10638 " backup existing encrypted datasets to new\n\t"
10639 "encrypted datasets and destroy the old ones. "
10640 "'zfs mount -o ro' can\n\tbe used to temporarily "
10641 "mount existing encrypted datasets readonly.\n"));
10644 case ZPOOL_ERRATA_ZOL_8308_ENCRYPTION
:
10645 (void) strlcat(status
, gettext("\tExisting encrypted "
10646 "snapshots and bookmarks contain an on-disk\n\t"
10647 "incompatibility. This may cause on-disk "
10648 "corruption if they are used\n\twith "
10649 "'zfs recv'.\n"), ST_SIZE
);
10650 snprintf(action
, AC_SIZE
, gettext("To correct the"
10651 "issue, enable the bookmark_v2 feature. No "
10652 "additional\n\taction is needed if there are no "
10653 "encrypted snapshots or bookmarks.\n\tIf preserving"
10654 "the encrypted snapshots and bookmarks is required,"
10655 " use\n\ta non-raw send to backup and restore them."
10656 " Alternately, they may be\n\tremoved to resolve "
10657 "the incompatibility.\n"));
10662 * All errata which allow the pool to be imported
10663 * must contain an action message.
10671 * The remaining errors can't actually be generated, yet.
10673 assert(reason
== ZPOOL_STATUS_OK
);
10676 if (status
[0] != 0) {
10678 fnvlist_add_string(item
, "status", status
);
10680 printf_color(ANSI_BOLD
, gettext("status: "));
10681 printf_color(ANSI_YELLOW
, status
);
10685 if (action
[0] != 0) {
10687 fnvlist_add_string(item
, "action", action
);
10689 printf_color(ANSI_BOLD
, gettext("action: "));
10690 printf_color(ANSI_YELLOW
, action
);
10696 status_callback_json(zpool_handle_t
*zhp
, void *data
)
10698 status_cbdata_t
*cbp
= data
;
10699 nvlist_t
*config
, *nvroot
;
10701 char pool_guid
[256];
10704 zpool_status_t reason
;
10705 zpool_errata_t errata
;
10708 nvlist_t
*item
, *d
, *load_info
, *vds
;
10711 /* If dedup stats were requested, also fetch dedupcached. */
10712 if (cbp
->cb_dedup_stats
> 1)
10713 zpool_add_propname(zhp
, ZPOOL_DEDUPCACHED_PROP_NAME
);
10714 reason
= zpool_get_status(zhp
, &msgid
, &errata
);
10716 * If we were given 'zpool status -x', only report those pools with
10719 if (cbp
->cb_explain
&&
10720 (reason
== ZPOOL_STATUS_OK
||
10721 reason
== ZPOOL_STATUS_VERSION_OLDER
||
10722 reason
== ZPOOL_STATUS_FEAT_DISABLED
||
10723 reason
== ZPOOL_STATUS_COMPATIBILITY_ERR
||
10724 reason
== ZPOOL_STATUS_INCOMPATIBLE_FEAT
)) {
10728 d
= fnvlist_lookup_nvlist(cbp
->cb_jsobj
, "pools");
10729 item
= fnvlist_alloc();
10730 vds
= fnvlist_alloc();
10731 fill_pool_info(item
, zhp
, B_FALSE
, cbp
->cb_json_as_int
);
10732 config
= zpool_get_config(zhp
, NULL
);
10734 if (config
!= NULL
) {
10735 nvroot
= fnvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
);
10736 verify(nvlist_lookup_uint64_array(nvroot
,
10737 ZPOOL_CONFIG_VDEV_STATS
, (uint64_t **)&vs
, &c
) == 0);
10738 if (cbp
->cb_json_pool_key_guid
) {
10739 guid
= fnvlist_lookup_uint64(config
,
10740 ZPOOL_CONFIG_POOL_GUID
);
10741 snprintf(pool_guid
, 256, "%llu", (u_longlong_t
)guid
);
10745 print_status_reason(zhp
, cbp
, reason
, errata
, item
);
10746 if (msgid
!= NULL
) {
10747 snprintf(msgbuf
, 256,
10748 "https://openzfs.github.io/openzfs-docs/msg/%s",
10750 fnvlist_add_string(item
, "msgid", msgid
);
10751 fnvlist_add_string(item
, "moreinfo", msgbuf
);
10754 if (nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_LOAD_INFO
,
10755 &load_info
) == 0) {
10756 fnvlist_add_nvlist(item
, ZPOOL_CONFIG_LOAD_INFO
,
10760 scan_status_nvlist(zhp
, cbp
, nvroot
, item
);
10761 removal_status_nvlist(zhp
, cbp
, nvroot
, item
);
10762 checkpoint_status_nvlist(nvroot
, cbp
, item
);
10763 raidz_expand_status_nvlist(zhp
, cbp
, nvroot
, item
);
10764 vdev_stats_nvlist(zhp
, cbp
, nvroot
, 0, B_FALSE
, NULL
, vds
);
10765 if (cbp
->cb_flat_vdevs
) {
10766 class_vdevs_nvlist(zhp
, cbp
, nvroot
,
10767 VDEV_ALLOC_BIAS_DEDUP
, vds
);
10768 class_vdevs_nvlist(zhp
, cbp
, nvroot
,
10769 VDEV_ALLOC_BIAS_SPECIAL
, vds
);
10770 class_vdevs_nvlist(zhp
, cbp
, nvroot
,
10771 VDEV_ALLOC_CLASS_LOGS
, vds
);
10772 l2cache_nvlist(zhp
, cbp
, nvroot
, vds
);
10773 spares_nvlist(zhp
, cbp
, nvroot
, vds
);
10775 fnvlist_add_nvlist(item
, "vdevs", vds
);
10778 fnvlist_add_nvlist(item
, "vdevs", vds
);
10781 class_vdevs_nvlist(zhp
, cbp
, nvroot
,
10782 VDEV_ALLOC_BIAS_DEDUP
, item
);
10783 class_vdevs_nvlist(zhp
, cbp
, nvroot
,
10784 VDEV_ALLOC_BIAS_SPECIAL
, item
);
10785 class_vdevs_nvlist(zhp
, cbp
, nvroot
,
10786 VDEV_ALLOC_CLASS_LOGS
, item
);
10787 l2cache_nvlist(zhp
, cbp
, nvroot
, item
);
10788 spares_nvlist(zhp
, cbp
, nvroot
, item
);
10790 dedup_stats_nvlist(zhp
, cbp
, item
);
10791 errors_nvlist(zhp
, cbp
, item
);
10793 if (cbp
->cb_json_pool_key_guid
) {
10794 fnvlist_add_nvlist(d
, pool_guid
, item
);
10796 fnvlist_add_nvlist(d
, zpool_get_name(zhp
),
10799 fnvlist_free(item
);
10804 * Display a summary of pool status. Displays a summary such as:
10808 * reason: One or more devices ...
10809 * see: https://openzfs.github.io/openzfs-docs/msg/ZFS-xxxx-01
10815 * When given the '-v' option, we print out the complete config. If the '-e'
10816 * option is specified, then we print out error rate information as well.
10819 status_callback(zpool_handle_t
*zhp
, void *data
)
10821 status_cbdata_t
*cbp
= data
;
10822 nvlist_t
*config
, *nvroot
;
10824 zpool_status_t reason
;
10825 zpool_errata_t errata
;
10826 const char *health
;
10830 /* If dedup stats were requested, also fetch dedupcached. */
10831 if (cbp
->cb_dedup_stats
> 1)
10832 zpool_add_propname(zhp
, ZPOOL_DEDUPCACHED_PROP_NAME
);
10834 config
= zpool_get_config(zhp
, NULL
);
10835 reason
= zpool_get_status(zhp
, &msgid
, &errata
);
10840 * If we were given 'zpool status -x', only report those pools with
10843 if (cbp
->cb_explain
&&
10844 (reason
== ZPOOL_STATUS_OK
||
10845 reason
== ZPOOL_STATUS_VERSION_OLDER
||
10846 reason
== ZPOOL_STATUS_FEAT_DISABLED
||
10847 reason
== ZPOOL_STATUS_COMPATIBILITY_ERR
||
10848 reason
== ZPOOL_STATUS_INCOMPATIBLE_FEAT
)) {
10849 if (!cbp
->cb_allpools
) {
10850 (void) printf(gettext("pool '%s' is healthy\n"),
10851 zpool_get_name(zhp
));
10853 cbp
->cb_first
= B_FALSE
;
10859 cbp
->cb_first
= B_FALSE
;
10861 (void) printf("\n");
10863 nvroot
= fnvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
);
10864 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_VDEV_STATS
,
10865 (uint64_t **)&vs
, &c
) == 0);
10867 health
= zpool_get_state_str(zhp
);
10870 printf_color(ANSI_BOLD
, gettext("pool:"));
10871 printf(" %s\n", zpool_get_name(zhp
));
10872 fputc(' ', stdout
);
10873 printf_color(ANSI_BOLD
, gettext("state: "));
10875 printf_color(health_str_to_color(health
), "%s", health
);
10877 fputc('\n', stdout
);
10878 print_status_reason(zhp
, cbp
, reason
, errata
, NULL
);
10880 if (msgid
!= NULL
) {
10882 printf_color(ANSI_BOLD
, gettext("see:"));
10884 " https://openzfs.github.io/openzfs-docs/msg/%s\n"),
10888 if (config
!= NULL
) {
10890 nvlist_t
**spares
, **l2cache
;
10891 uint_t nspares
, nl2cache
;
10893 print_scan_status(zhp
, nvroot
);
10895 pool_removal_stat_t
*prs
= NULL
;
10896 (void) nvlist_lookup_uint64_array(nvroot
,
10897 ZPOOL_CONFIG_REMOVAL_STATS
, (uint64_t **)&prs
, &c
);
10898 print_removal_status(zhp
, prs
);
10900 pool_checkpoint_stat_t
*pcs
= NULL
;
10901 (void) nvlist_lookup_uint64_array(nvroot
,
10902 ZPOOL_CONFIG_CHECKPOINT_STATS
, (uint64_t **)&pcs
, &c
);
10903 print_checkpoint_status(pcs
);
10905 pool_raidz_expand_stat_t
*pres
= NULL
;
10906 (void) nvlist_lookup_uint64_array(nvroot
,
10907 ZPOOL_CONFIG_RAIDZ_EXPAND_STATS
, (uint64_t **)&pres
, &c
);
10908 print_raidz_expand_status(zhp
, pres
);
10910 cbp
->cb_namewidth
= max_width(zhp
, nvroot
, 0, 0,
10911 cbp
->cb_name_flags
| VDEV_NAME_TYPE_ID
);
10912 if (cbp
->cb_namewidth
< 10)
10913 cbp
->cb_namewidth
= 10;
10915 color_start(ANSI_BOLD
);
10916 (void) printf(gettext("config:\n\n"));
10917 (void) printf(gettext("\t%-*s %-8s %5s %5s %5s"),
10918 cbp
->cb_namewidth
, "NAME", "STATE", "READ", "WRITE",
10922 if (cbp
->cb_print_slow_ios
) {
10923 printf_color(ANSI_BOLD
, " %5s", gettext("SLOW"));
10926 if (cbp
->cb_print_power
) {
10927 printf_color(ANSI_BOLD
, " %5s", gettext("POWER"));
10930 if (cbp
->cb_print_dio_verify
) {
10931 printf_color(ANSI_BOLD
, " %5s", gettext("DIO"));
10934 if (cbp
->vcdl
!= NULL
)
10935 print_cmd_columns(cbp
->vcdl
, 0);
10939 print_status_config(zhp
, cbp
, zpool_get_name(zhp
), nvroot
, 0,
10942 print_class_vdevs(zhp
, cbp
, nvroot
, VDEV_ALLOC_BIAS_DEDUP
);
10943 print_class_vdevs(zhp
, cbp
, nvroot
, VDEV_ALLOC_BIAS_SPECIAL
);
10944 print_class_vdevs(zhp
, cbp
, nvroot
, VDEV_ALLOC_CLASS_LOGS
);
10946 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_L2CACHE
,
10947 &l2cache
, &nl2cache
) == 0)
10948 print_l2cache(zhp
, cbp
, l2cache
, nl2cache
);
10950 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_SPARES
,
10951 &spares
, &nspares
) == 0)
10952 print_spares(zhp
, cbp
, spares
, nspares
);
10954 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_ERRCOUNT
,
10956 (void) printf("\n");
10958 (void) printf(gettext(
10959 "errors: No known data errors\n"));
10960 } else if (!cbp
->cb_verbose
) {
10961 color_start(ANSI_RED
);
10962 (void) printf(gettext("errors: %llu data "
10963 "errors, use '-v' for a list\n"),
10964 (u_longlong_t
)nerr
);
10967 print_error_log(zhp
);
10971 if (cbp
->cb_dedup_stats
)
10972 print_dedup_stats(zhp
, config
, cbp
->cb_literal
);
10974 (void) printf(gettext("config: The configuration cannot be "
10982 * zpool status [-c [script1,script2,...]] [-dDegiLpPstvx] [--power] ...
10983 * [-T d|u] [pool] [interval [count]]
10985 * -c CMD For each vdev, run command CMD
10986 * -d Display Direct I/O write verify errors
10987 * -D Display dedup status (undocumented)
10988 * -e Display only unhealthy vdevs
10989 * -g Display guid for individual vdev name.
10990 * -i Display vdev initialization status.
10991 * -L Follow links when resolving vdev path name.
10992 * -p Display values in parsable (exact) format.
10993 * -P Display full path for vdev name.
10994 * -s Display slow IOs column.
10995 * -t Display vdev TRIM status.
10996 * -T Display a timestamp in date(1) or Unix format
10997 * -v Display complete error logs
10998 * -x Display only pools with potential problems
10999 * -j Display output in JSON format
11000 * --power Display vdev enclosure slot power status
11001 * --json-int Display numbers in inteeger format instead of string
11002 * --json-flat-vdevs Display vdevs in flat hierarchy
11003 * --json-pool-key-guid Use pool GUID as key for pool objects
11005 * Describes the health status of all pools or some subset.
11008 zpool_do_status(int argc
, char **argv
)
11012 float interval
= 0;
11013 unsigned long count
= 0;
11014 status_cbdata_t cb
= { 0 };
11018 struct option long_options
[] = {
11019 {"power", no_argument
, NULL
, ZPOOL_OPTION_POWER
},
11020 {"json", no_argument
, NULL
, 'j'},
11021 {"json-int", no_argument
, NULL
, ZPOOL_OPTION_JSON_NUMS_AS_INT
},
11022 {"json-flat-vdevs", no_argument
, NULL
,
11023 ZPOOL_OPTION_JSON_FLAT_VDEVS
},
11024 {"json-pool-key-guid", no_argument
, NULL
,
11025 ZPOOL_OPTION_POOL_KEY_GUID
},
11029 /* check options */
11030 while ((c
= getopt_long(argc
, argv
, "c:jdDegiLpPstT:vx", long_options
,
11036 gettext("Can't set -c flag twice\n"));
11040 if (getenv("ZPOOL_SCRIPTS_ENABLED") != NULL
&&
11041 !libzfs_envvar_is_set("ZPOOL_SCRIPTS_ENABLED")) {
11042 fprintf(stderr
, gettext(
11043 "Can't run -c, disabled by "
11044 "ZPOOL_SCRIPTS_ENABLED.\n"));
11048 if ((getuid() <= 0 || geteuid() <= 0) &&
11049 !libzfs_envvar_is_set("ZPOOL_SCRIPTS_AS_ROOT")) {
11050 fprintf(stderr
, gettext(
11051 "Can't run -c with root privileges "
11052 "unless ZPOOL_SCRIPTS_AS_ROOT is set.\n"));
11058 cb
.cb_print_dio_verify
= B_TRUE
;
11061 if (++cb
.cb_dedup_stats
> 2)
11062 cb
.cb_dedup_stats
= 2;
11065 cb
.cb_print_unhealthy
= B_TRUE
;
11068 cb
.cb_name_flags
|= VDEV_NAME_GUID
;
11071 cb
.cb_print_vdev_init
= B_TRUE
;
11074 cb
.cb_name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
11077 cb
.cb_literal
= B_TRUE
;
11080 cb
.cb_name_flags
|= VDEV_NAME_PATH
;
11083 cb
.cb_print_slow_ios
= B_TRUE
;
11086 cb
.cb_print_vdev_trim
= B_TRUE
;
11089 get_timestamp_arg(*optarg
);
11092 cb
.cb_verbose
= B_TRUE
;
11095 cb
.cb_json
= B_TRUE
;
11098 cb
.cb_explain
= B_TRUE
;
11100 case ZPOOL_OPTION_POWER
:
11101 cb
.cb_print_power
= B_TRUE
;
11103 case ZPOOL_OPTION_JSON_FLAT_VDEVS
:
11104 cb
.cb_flat_vdevs
= B_TRUE
;
11106 case ZPOOL_OPTION_JSON_NUMS_AS_INT
:
11107 cb
.cb_json_as_int
= B_TRUE
;
11108 cb
.cb_literal
= B_TRUE
;
11110 case ZPOOL_OPTION_POOL_KEY_GUID
:
11111 cb
.cb_json_pool_key_guid
= B_TRUE
;
11114 if (optopt
== 'c') {
11115 print_zpool_script_list("status");
11119 gettext("invalid option '%c'\n"), optopt
);
11128 get_interval_count(&argc
, argv
, &interval
, &count
);
11131 cb
.cb_allpools
= B_TRUE
;
11133 cb
.cb_first
= B_TRUE
;
11134 cb
.cb_print_status
= B_TRUE
;
11136 if (cb
.cb_flat_vdevs
&& !cb
.cb_json
) {
11137 fprintf(stderr
, gettext("'--json-flat-vdevs' only works with"
11138 " '-j' option\n"));
11142 if (cb
.cb_json_as_int
&& !cb
.cb_json
) {
11143 (void) fprintf(stderr
, gettext("'--json-int' only works with"
11144 " '-j' option\n"));
11148 if (!cb
.cb_json
&& cb
.cb_json_pool_key_guid
) {
11149 (void) fprintf(stderr
, gettext("'json-pool-key-guid' only"
11150 " works with '-j' option\n"));
11156 cb
.cb_jsobj
= zpool_json_schema(0, 1);
11157 data
= fnvlist_alloc();
11158 fnvlist_add_nvlist(cb
.cb_jsobj
, "pools", data
);
11159 fnvlist_free(data
);
11162 if (timestamp_fmt
!= NODATE
) {
11164 if (cb
.cb_json_as_int
) {
11165 fnvlist_add_uint64(cb
.cb_jsobj
, "time",
11169 get_timestamp(timestamp_fmt
, ts
, 128);
11170 fnvlist_add_string(cb
.cb_jsobj
, "time",
11174 print_timestamp(timestamp_fmt
);
11178 cb
.vcdl
= all_pools_for_each_vdev_run(argc
, argv
, cmd
,
11182 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
,
11183 ZFS_TYPE_POOL
, cb
.cb_literal
,
11184 status_callback_json
, &cb
);
11186 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
,
11187 ZFS_TYPE_POOL
, cb
.cb_literal
,
11188 status_callback
, &cb
);
11191 if (cb
.vcdl
!= NULL
)
11192 free_vdev_cmd_data_list(cb
.vcdl
);
11196 zcmd_print_json(cb
.cb_jsobj
);
11198 nvlist_free(cb
.cb_jsobj
);
11200 if (argc
== 0 && cb
.cb_count
== 0) {
11201 (void) fprintf(stderr
, "%s",
11202 gettext("no pools available\n"));
11203 } else if (cb
.cb_explain
&& cb
.cb_first
&&
11205 (void) printf("%s",
11206 gettext("all pools are healthy\n"));
11216 if (count
!= 0 && --count
== 0)
11219 (void) fflush(stdout
);
11220 (void) fsleep(interval
);
11226 typedef struct upgrade_cbdata
{
11229 uint64_t cb_version
;
11231 } upgrade_cbdata_t
;
11234 check_unsupp_fs(zfs_handle_t
*zhp
, void *unsupp_fs
)
11236 int zfs_version
= (int)zfs_prop_get_int(zhp
, ZFS_PROP_VERSION
);
11237 int *count
= (int *)unsupp_fs
;
11239 if (zfs_version
> ZPL_VERSION
) {
11240 (void) printf(gettext("%s (v%d) is not supported by this "
11241 "implementation of ZFS.\n"),
11242 zfs_get_name(zhp
), zfs_version
);
11246 zfs_iter_filesystems_v2(zhp
, 0, check_unsupp_fs
, unsupp_fs
);
11254 upgrade_version(zpool_handle_t
*zhp
, uint64_t version
)
11258 uint64_t oldversion
;
11261 config
= zpool_get_config(zhp
, NULL
);
11262 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
11263 &oldversion
) == 0);
11265 char compat
[ZFS_MAXPROPLEN
];
11266 if (zpool_get_prop(zhp
, ZPOOL_PROP_COMPATIBILITY
, compat
,
11267 ZFS_MAXPROPLEN
, NULL
, B_FALSE
) != 0)
11270 assert(SPA_VERSION_IS_SUPPORTED(oldversion
));
11271 assert(oldversion
< version
);
11273 ret
= zfs_iter_root(zpool_get_handle(zhp
), check_unsupp_fs
, &unsupp_fs
);
11278 (void) fprintf(stderr
, gettext("Upgrade not performed due "
11279 "to %d unsupported filesystems (max v%d).\n"),
11280 unsupp_fs
, (int)ZPL_VERSION
);
11284 if (strcmp(compat
, ZPOOL_COMPAT_LEGACY
) == 0) {
11285 (void) fprintf(stderr
, gettext("Upgrade not performed because "
11286 "'compatibility' property set to '"
11287 ZPOOL_COMPAT_LEGACY
"'.\n"));
11291 ret
= zpool_upgrade(zhp
, version
);
11295 if (version
>= SPA_VERSION_FEATURES
) {
11296 (void) printf(gettext("Successfully upgraded "
11297 "'%s' from version %llu to feature flags.\n"),
11298 zpool_get_name(zhp
), (u_longlong_t
)oldversion
);
11300 (void) printf(gettext("Successfully upgraded "
11301 "'%s' from version %llu to version %llu.\n"),
11302 zpool_get_name(zhp
), (u_longlong_t
)oldversion
,
11303 (u_longlong_t
)version
);
11310 upgrade_enable_all(zpool_handle_t
*zhp
, int *countp
)
11313 boolean_t firstff
= B_TRUE
;
11314 nvlist_t
*enabled
= zpool_get_features(zhp
);
11316 char compat
[ZFS_MAXPROPLEN
];
11317 if (zpool_get_prop(zhp
, ZPOOL_PROP_COMPATIBILITY
, compat
,
11318 ZFS_MAXPROPLEN
, NULL
, B_FALSE
) != 0)
11321 boolean_t requested_features
[SPA_FEATURES
];
11322 if (zpool_do_load_compat(compat
, requested_features
) !=
11323 ZPOOL_COMPATIBILITY_OK
)
11327 for (i
= 0; i
< SPA_FEATURES
; i
++) {
11328 const char *fname
= spa_feature_table
[i
].fi_uname
;
11329 const char *fguid
= spa_feature_table
[i
].fi_guid
;
11331 if (!spa_feature_table
[i
].fi_zfs_mod_supported
)
11334 if (!nvlist_exists(enabled
, fguid
) && requested_features
[i
]) {
11336 verify(-1 != asprintf(&propname
, "feature@%s", fname
));
11337 ret
= zpool_set_prop(zhp
, propname
,
11338 ZFS_FEATURE_ENABLED
);
11346 (void) printf(gettext("Enabled the "
11347 "following features on '%s':\n"),
11348 zpool_get_name(zhp
));
11351 (void) printf(gettext(" %s\n"), fname
);
11356 if (countp
!= NULL
)
11362 upgrade_cb(zpool_handle_t
*zhp
, void *arg
)
11364 upgrade_cbdata_t
*cbp
= arg
;
11367 boolean_t modified_pool
= B_FALSE
;
11370 config
= zpool_get_config(zhp
, NULL
);
11371 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
11374 assert(SPA_VERSION_IS_SUPPORTED(version
));
11376 if (version
< cbp
->cb_version
) {
11377 cbp
->cb_first
= B_FALSE
;
11378 ret
= upgrade_version(zhp
, cbp
->cb_version
);
11381 modified_pool
= B_TRUE
;
11384 * If they did "zpool upgrade -a", then we could
11385 * be doing ioctls to different pools. We need
11386 * to log this history once to each pool, and bypass
11387 * the normal history logging that happens in main().
11389 (void) zpool_log_history(g_zfs
, history_str
);
11390 log_history
= B_FALSE
;
11393 if (cbp
->cb_version
>= SPA_VERSION_FEATURES
) {
11395 ret
= upgrade_enable_all(zhp
, &count
);
11400 cbp
->cb_first
= B_FALSE
;
11401 modified_pool
= B_TRUE
;
11405 if (modified_pool
) {
11406 (void) printf("\n");
11407 (void) after_zpool_upgrade(zhp
);
11414 upgrade_list_older_cb(zpool_handle_t
*zhp
, void *arg
)
11416 upgrade_cbdata_t
*cbp
= arg
;
11420 config
= zpool_get_config(zhp
, NULL
);
11421 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
11424 assert(SPA_VERSION_IS_SUPPORTED(version
));
11426 if (version
< SPA_VERSION_FEATURES
) {
11427 if (cbp
->cb_first
) {
11428 (void) printf(gettext("The following pools are "
11429 "formatted with legacy version numbers and can\n"
11430 "be upgraded to use feature flags. After "
11431 "being upgraded, these pools\nwill no "
11432 "longer be accessible by software that does not "
11433 "support feature\nflags.\n\n"
11434 "Note that setting a pool's 'compatibility' "
11435 "feature to '" ZPOOL_COMPAT_LEGACY
"' will\n"
11436 "inhibit upgrades.\n\n"));
11437 (void) printf(gettext("VER POOL\n"));
11438 (void) printf(gettext("--- ------------\n"));
11439 cbp
->cb_first
= B_FALSE
;
11442 (void) printf("%2llu %s\n", (u_longlong_t
)version
,
11443 zpool_get_name(zhp
));
11450 upgrade_list_disabled_cb(zpool_handle_t
*zhp
, void *arg
)
11452 upgrade_cbdata_t
*cbp
= arg
;
11456 config
= zpool_get_config(zhp
, NULL
);
11457 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
11460 if (version
>= SPA_VERSION_FEATURES
) {
11462 boolean_t poolfirst
= B_TRUE
;
11463 nvlist_t
*enabled
= zpool_get_features(zhp
);
11465 for (i
= 0; i
< SPA_FEATURES
; i
++) {
11466 const char *fguid
= spa_feature_table
[i
].fi_guid
;
11467 const char *fname
= spa_feature_table
[i
].fi_uname
;
11469 if (!spa_feature_table
[i
].fi_zfs_mod_supported
)
11472 if (!nvlist_exists(enabled
, fguid
)) {
11473 if (cbp
->cb_first
) {
11474 (void) printf(gettext("\nSome "
11475 "supported features are not "
11476 "enabled on the following pools. "
11477 "Once a\nfeature is enabled the "
11478 "pool may become incompatible with "
11479 "software\nthat does not support "
11480 "the feature. See "
11481 "zpool-features(7) for "
11483 "Note that the pool "
11484 "'compatibility' feature can be "
11485 "used to inhibit\nfeature "
11487 (void) printf(gettext("POOL "
11489 (void) printf(gettext("------"
11491 cbp
->cb_first
= B_FALSE
;
11495 (void) printf(gettext("%s\n"),
11496 zpool_get_name(zhp
));
11497 poolfirst
= B_FALSE
;
11500 (void) printf(gettext(" %s\n"), fname
);
11503 * If they did "zpool upgrade -a", then we could
11504 * be doing ioctls to different pools. We need
11505 * to log this history once to each pool, and bypass
11506 * the normal history logging that happens in main().
11508 (void) zpool_log_history(g_zfs
, history_str
);
11509 log_history
= B_FALSE
;
11517 upgrade_one(zpool_handle_t
*zhp
, void *data
)
11519 boolean_t modified_pool
= B_FALSE
;
11520 upgrade_cbdata_t
*cbp
= data
;
11521 uint64_t cur_version
;
11524 if (strcmp("log", zpool_get_name(zhp
)) == 0) {
11525 (void) fprintf(stderr
, gettext("'log' is now a reserved word\n"
11526 "Pool 'log' must be renamed using export and import"
11527 " to upgrade.\n"));
11531 cur_version
= zpool_get_prop_int(zhp
, ZPOOL_PROP_VERSION
, NULL
);
11532 if (cur_version
> cbp
->cb_version
) {
11533 (void) printf(gettext("Pool '%s' is already formatted "
11534 "using more current version '%llu'.\n\n"),
11535 zpool_get_name(zhp
), (u_longlong_t
)cur_version
);
11539 if (cbp
->cb_version
!= SPA_VERSION
&& cur_version
== cbp
->cb_version
) {
11540 (void) printf(gettext("Pool '%s' is already formatted "
11541 "using version %llu.\n\n"), zpool_get_name(zhp
),
11542 (u_longlong_t
)cbp
->cb_version
);
11546 if (cur_version
!= cbp
->cb_version
) {
11547 modified_pool
= B_TRUE
;
11548 ret
= upgrade_version(zhp
, cbp
->cb_version
);
11553 if (cbp
->cb_version
>= SPA_VERSION_FEATURES
) {
11555 ret
= upgrade_enable_all(zhp
, &count
);
11560 modified_pool
= B_TRUE
;
11561 } else if (cur_version
== SPA_VERSION
) {
11562 (void) printf(gettext("Pool '%s' already has all "
11563 "supported and requested features enabled.\n"),
11564 zpool_get_name(zhp
));
11568 if (modified_pool
) {
11569 (void) printf("\n");
11570 (void) after_zpool_upgrade(zhp
);
11579 * zpool upgrade [-V version] <-a | pool ...>
11581 * With no arguments, display downrev'd ZFS pool available for upgrade.
11582 * Individual pools can be upgraded by specifying the pool, and '-a' will
11583 * upgrade all pools.
11586 zpool_do_upgrade(int argc
, char **argv
)
11589 upgrade_cbdata_t cb
= { 0 };
11591 boolean_t showversions
= B_FALSE
;
11592 boolean_t upgradeall
= B_FALSE
;
11596 /* check options */
11597 while ((c
= getopt(argc
, argv
, ":avV:")) != -1) {
11600 upgradeall
= B_TRUE
;
11603 showversions
= B_TRUE
;
11606 cb
.cb_version
= strtoll(optarg
, &end
, 10);
11607 if (*end
!= '\0' ||
11608 !SPA_VERSION_IS_SUPPORTED(cb
.cb_version
)) {
11609 (void) fprintf(stderr
,
11610 gettext("invalid version '%s'\n"), optarg
);
11615 (void) fprintf(stderr
, gettext("missing argument for "
11616 "'%c' option\n"), optopt
);
11620 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
11631 if (cb
.cb_version
== 0) {
11632 cb
.cb_version
= SPA_VERSION
;
11633 } else if (!upgradeall
&& argc
== 0) {
11634 (void) fprintf(stderr
, gettext("-V option is "
11635 "incompatible with other arguments\n"));
11639 if (showversions
) {
11640 if (upgradeall
|| argc
!= 0) {
11641 (void) fprintf(stderr
, gettext("-v option is "
11642 "incompatible with other arguments\n"));
11645 } else if (upgradeall
) {
11647 (void) fprintf(stderr
, gettext("-a option should not "
11648 "be used along with a pool name\n"));
11653 (void) printf("%s", gettext("This system supports ZFS pool feature "
11655 if (showversions
) {
11658 (void) printf(gettext("The following features are "
11659 "supported:\n\n"));
11660 (void) printf(gettext("FEAT DESCRIPTION\n"));
11661 (void) printf("----------------------------------------------"
11662 "---------------\n");
11663 for (i
= 0; i
< SPA_FEATURES
; i
++) {
11664 zfeature_info_t
*fi
= &spa_feature_table
[i
];
11665 if (!fi
->fi_zfs_mod_supported
)
11668 (fi
->fi_flags
& ZFEATURE_FLAG_READONLY_COMPAT
) ?
11669 " (read-only compatible)" : "";
11671 (void) printf("%-37s%s\n", fi
->fi_uname
, ro
);
11672 (void) printf(" %s\n", fi
->fi_desc
);
11674 (void) printf("\n");
11676 (void) printf(gettext("The following legacy versions are also "
11677 "supported:\n\n"));
11678 (void) printf(gettext("VER DESCRIPTION\n"));
11679 (void) printf("--- -----------------------------------------"
11680 "---------------\n");
11681 (void) printf(gettext(" 1 Initial ZFS version\n"));
11682 (void) printf(gettext(" 2 Ditto blocks "
11683 "(replicated metadata)\n"));
11684 (void) printf(gettext(" 3 Hot spares and double parity "
11686 (void) printf(gettext(" 4 zpool history\n"));
11687 (void) printf(gettext(" 5 Compression using the gzip "
11689 (void) printf(gettext(" 6 bootfs pool property\n"));
11690 (void) printf(gettext(" 7 Separate intent log devices\n"));
11691 (void) printf(gettext(" 8 Delegated administration\n"));
11692 (void) printf(gettext(" 9 refquota and refreservation "
11694 (void) printf(gettext(" 10 Cache devices\n"));
11695 (void) printf(gettext(" 11 Improved scrub performance\n"));
11696 (void) printf(gettext(" 12 Snapshot properties\n"));
11697 (void) printf(gettext(" 13 snapused property\n"));
11698 (void) printf(gettext(" 14 passthrough-x aclinherit\n"));
11699 (void) printf(gettext(" 15 user/group space accounting\n"));
11700 (void) printf(gettext(" 16 stmf property support\n"));
11701 (void) printf(gettext(" 17 Triple-parity RAID-Z\n"));
11702 (void) printf(gettext(" 18 Snapshot user holds\n"));
11703 (void) printf(gettext(" 19 Log device removal\n"));
11704 (void) printf(gettext(" 20 Compression using zle "
11705 "(zero-length encoding)\n"));
11706 (void) printf(gettext(" 21 Deduplication\n"));
11707 (void) printf(gettext(" 22 Received properties\n"));
11708 (void) printf(gettext(" 23 Slim ZIL\n"));
11709 (void) printf(gettext(" 24 System attributes\n"));
11710 (void) printf(gettext(" 25 Improved scrub stats\n"));
11711 (void) printf(gettext(" 26 Improved snapshot deletion "
11713 (void) printf(gettext(" 27 Improved snapshot creation "
11715 (void) printf(gettext(" 28 Multiple vdev replacements\n"));
11716 (void) printf(gettext("\nFor more information on a particular "
11717 "version, including supported releases,\n"));
11718 (void) printf(gettext("see the ZFS Administration Guide.\n\n"));
11719 } else if (argc
== 0 && upgradeall
) {
11720 cb
.cb_first
= B_TRUE
;
11721 ret
= zpool_iter(g_zfs
, upgrade_cb
, &cb
);
11722 if (ret
== 0 && cb
.cb_first
) {
11723 if (cb
.cb_version
== SPA_VERSION
) {
11724 (void) printf(gettext("All pools are already "
11725 "formatted using feature flags.\n\n"));
11726 (void) printf(gettext("Every feature flags "
11727 "pool already has all supported and "
11728 "requested features enabled.\n"));
11730 (void) printf(gettext("All pools are already "
11731 "formatted with version %llu or higher.\n"),
11732 (u_longlong_t
)cb
.cb_version
);
11735 } else if (argc
== 0) {
11736 cb
.cb_first
= B_TRUE
;
11737 ret
= zpool_iter(g_zfs
, upgrade_list_older_cb
, &cb
);
11741 (void) printf(gettext("All pools are formatted "
11742 "using feature flags.\n\n"));
11744 (void) printf(gettext("\nUse 'zpool upgrade -v' "
11745 "for a list of available legacy versions.\n"));
11748 cb
.cb_first
= B_TRUE
;
11749 ret
= zpool_iter(g_zfs
, upgrade_list_disabled_cb
, &cb
);
11753 (void) printf(gettext("Every feature flags pool has "
11754 "all supported and requested features enabled.\n"));
11756 (void) printf(gettext("\n"));
11759 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
, ZFS_TYPE_POOL
,
11760 B_FALSE
, upgrade_one
, &cb
);
11766 typedef struct hist_cbdata
{
11769 boolean_t internal
;
11773 print_history_records(nvlist_t
*nvhis
, hist_cbdata_t
*cb
)
11775 nvlist_t
**records
;
11779 verify(nvlist_lookup_nvlist_array(nvhis
, ZPOOL_HIST_RECORD
,
11780 &records
, &numrecords
) == 0);
11781 for (i
= 0; i
< numrecords
; i
++) {
11782 nvlist_t
*rec
= records
[i
];
11783 char tbuf
[64] = "";
11785 if (nvlist_exists(rec
, ZPOOL_HIST_TIME
)) {
11789 tsec
= fnvlist_lookup_uint64(records
[i
],
11791 (void) localtime_r(&tsec
, &t
);
11792 (void) strftime(tbuf
, sizeof (tbuf
), "%F.%T", &t
);
11795 if (nvlist_exists(rec
, ZPOOL_HIST_ELAPSED_NS
)) {
11796 uint64_t elapsed_ns
= fnvlist_lookup_int64(records
[i
],
11797 ZPOOL_HIST_ELAPSED_NS
);
11798 (void) snprintf(tbuf
+ strlen(tbuf
),
11799 sizeof (tbuf
) - strlen(tbuf
),
11800 " (%lldms)", (long long)elapsed_ns
/ 1000 / 1000);
11803 if (nvlist_exists(rec
, ZPOOL_HIST_CMD
)) {
11804 (void) printf("%s %s", tbuf
,
11805 fnvlist_lookup_string(rec
, ZPOOL_HIST_CMD
));
11806 } else if (nvlist_exists(rec
, ZPOOL_HIST_INT_EVENT
)) {
11808 fnvlist_lookup_uint64(rec
, ZPOOL_HIST_INT_EVENT
);
11811 if (ievent
>= ZFS_NUM_LEGACY_HISTORY_EVENTS
) {
11812 (void) printf("%s unrecognized record:\n",
11814 dump_nvlist(rec
, 4);
11817 (void) printf("%s [internal %s txg:%lld] %s", tbuf
,
11818 zfs_history_event_names
[ievent
],
11819 (longlong_t
)fnvlist_lookup_uint64(
11820 rec
, ZPOOL_HIST_TXG
),
11821 fnvlist_lookup_string(rec
, ZPOOL_HIST_INT_STR
));
11822 } else if (nvlist_exists(rec
, ZPOOL_HIST_INT_NAME
)) {
11825 (void) printf("%s [txg:%lld] %s", tbuf
,
11826 (longlong_t
)fnvlist_lookup_uint64(
11827 rec
, ZPOOL_HIST_TXG
),
11828 fnvlist_lookup_string(rec
, ZPOOL_HIST_INT_NAME
));
11829 if (nvlist_exists(rec
, ZPOOL_HIST_DSNAME
)) {
11830 (void) printf(" %s (%llu)",
11831 fnvlist_lookup_string(rec
,
11832 ZPOOL_HIST_DSNAME
),
11833 (u_longlong_t
)fnvlist_lookup_uint64(rec
,
11836 (void) printf(" %s", fnvlist_lookup_string(rec
,
11837 ZPOOL_HIST_INT_STR
));
11838 } else if (nvlist_exists(rec
, ZPOOL_HIST_IOCTL
)) {
11841 (void) printf("%s ioctl %s\n", tbuf
,
11842 fnvlist_lookup_string(rec
, ZPOOL_HIST_IOCTL
));
11843 if (nvlist_exists(rec
, ZPOOL_HIST_INPUT_NVL
)) {
11844 (void) printf(" input:\n");
11845 dump_nvlist(fnvlist_lookup_nvlist(rec
,
11846 ZPOOL_HIST_INPUT_NVL
), 8);
11848 if (nvlist_exists(rec
, ZPOOL_HIST_OUTPUT_NVL
)) {
11849 (void) printf(" output:\n");
11850 dump_nvlist(fnvlist_lookup_nvlist(rec
,
11851 ZPOOL_HIST_OUTPUT_NVL
), 8);
11853 if (nvlist_exists(rec
, ZPOOL_HIST_OUTPUT_SIZE
)) {
11854 (void) printf(" output nvlist omitted; "
11855 "original size: %lldKB\n",
11856 (longlong_t
)fnvlist_lookup_int64(rec
,
11857 ZPOOL_HIST_OUTPUT_SIZE
) / 1024);
11859 if (nvlist_exists(rec
, ZPOOL_HIST_ERRNO
)) {
11860 (void) printf(" errno: %lld\n",
11861 (longlong_t
)fnvlist_lookup_int64(rec
,
11862 ZPOOL_HIST_ERRNO
));
11867 (void) printf("%s unrecognized record:\n", tbuf
);
11868 dump_nvlist(rec
, 4);
11871 if (!cb
->longfmt
) {
11872 (void) printf("\n");
11875 (void) printf(" [");
11876 if (nvlist_exists(rec
, ZPOOL_HIST_WHO
)) {
11877 uid_t who
= fnvlist_lookup_uint64(rec
, ZPOOL_HIST_WHO
);
11878 struct passwd
*pwd
= getpwuid(who
);
11879 (void) printf("user %d ", (int)who
);
11881 (void) printf("(%s) ", pwd
->pw_name
);
11883 if (nvlist_exists(rec
, ZPOOL_HIST_HOST
)) {
11884 (void) printf("on %s",
11885 fnvlist_lookup_string(rec
, ZPOOL_HIST_HOST
));
11887 if (nvlist_exists(rec
, ZPOOL_HIST_ZONE
)) {
11888 (void) printf(":%s",
11889 fnvlist_lookup_string(rec
, ZPOOL_HIST_ZONE
));
11892 (void) printf("]");
11893 (void) printf("\n");
11898 * Print out the command history for a specific pool.
11901 get_history_one(zpool_handle_t
*zhp
, void *data
)
11905 hist_cbdata_t
*cb
= (hist_cbdata_t
*)data
;
11907 boolean_t eof
= B_FALSE
;
11909 cb
->first
= B_FALSE
;
11911 (void) printf(gettext("History for '%s':\n"), zpool_get_name(zhp
));
11914 if ((ret
= zpool_get_history(zhp
, &nvhis
, &off
, &eof
)) != 0)
11917 print_history_records(nvhis
, cb
);
11918 nvlist_free(nvhis
);
11920 (void) printf("\n");
11926 * zpool history <pool>
11928 * Displays the history of commands that modified pools.
11931 zpool_do_history(int argc
, char **argv
)
11933 hist_cbdata_t cbdata
= { 0 };
11937 cbdata
.first
= B_TRUE
;
11938 /* check options */
11939 while ((c
= getopt(argc
, argv
, "li")) != -1) {
11942 cbdata
.longfmt
= B_TRUE
;
11945 cbdata
.internal
= B_TRUE
;
11948 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
11956 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
, ZFS_TYPE_POOL
,
11957 B_FALSE
, get_history_one
, &cbdata
);
11959 if (argc
== 0 && cbdata
.first
== B_TRUE
) {
11960 (void) fprintf(stderr
, gettext("no pools available\n"));
11967 typedef struct ev_opts
{
11972 char poolname
[ZFS_MAX_DATASET_NAME_LEN
];
11976 zpool_do_events_short(nvlist_t
*nvl
, ev_opts_t
*opts
)
11978 char ctime_str
[26], str
[32];
11983 verify(nvlist_lookup_int64_array(nvl
, FM_EREPORT_TIME
, &tv
, &n
) == 0);
11984 memset(str
, ' ', 32);
11985 (void) ctime_r((const time_t *)&tv
[0], ctime_str
);
11986 (void) memcpy(str
, ctime_str
+4, 6); /* 'Jun 30' */
11987 (void) memcpy(str
+7, ctime_str
+20, 4); /* '1993' */
11988 (void) memcpy(str
+12, ctime_str
+11, 8); /* '21:49:08' */
11989 (void) sprintf(str
+20, ".%09lld", (longlong_t
)tv
[1]); /* '.123456789' */
11990 if (opts
->scripted
)
11991 (void) printf(gettext("%s\t"), str
);
11993 (void) printf(gettext("%s "), str
);
11995 verify(nvlist_lookup_string(nvl
, FM_CLASS
, &ptr
) == 0);
11996 (void) printf(gettext("%s\n"), ptr
);
12000 zpool_do_events_nvprint(nvlist_t
*nvl
, int depth
)
12003 static char flagstr
[256];
12005 for (nvp
= nvlist_next_nvpair(nvl
, NULL
);
12006 nvp
!= NULL
; nvp
= nvlist_next_nvpair(nvl
, nvp
)) {
12008 data_type_t type
= nvpair_type(nvp
);
12009 const char *name
= nvpair_name(nvp
);
12019 printf(gettext("%*s%s = "), depth
, "", name
);
12022 case DATA_TYPE_BOOLEAN
:
12023 printf(gettext("%s"), "1");
12026 case DATA_TYPE_BOOLEAN_VALUE
:
12027 (void) nvpair_value_boolean_value(nvp
, &b
);
12028 printf(gettext("%s"), b
? "1" : "0");
12031 case DATA_TYPE_BYTE
:
12032 (void) nvpair_value_byte(nvp
, &i8
);
12033 printf(gettext("0x%x"), i8
);
12036 case DATA_TYPE_INT8
:
12037 (void) nvpair_value_int8(nvp
, (void *)&i8
);
12038 printf(gettext("0x%x"), i8
);
12041 case DATA_TYPE_UINT8
:
12042 (void) nvpair_value_uint8(nvp
, &i8
);
12043 printf(gettext("0x%x"), i8
);
12046 case DATA_TYPE_INT16
:
12047 (void) nvpair_value_int16(nvp
, (void *)&i16
);
12048 printf(gettext("0x%x"), i16
);
12051 case DATA_TYPE_UINT16
:
12052 (void) nvpair_value_uint16(nvp
, &i16
);
12053 printf(gettext("0x%x"), i16
);
12056 case DATA_TYPE_INT32
:
12057 (void) nvpair_value_int32(nvp
, (void *)&i32
);
12058 printf(gettext("0x%x"), i32
);
12061 case DATA_TYPE_UINT32
:
12062 (void) nvpair_value_uint32(nvp
, &i32
);
12064 FM_EREPORT_PAYLOAD_ZFS_ZIO_STAGE
) == 0 ||
12066 FM_EREPORT_PAYLOAD_ZFS_ZIO_PIPELINE
) == 0) {
12067 zfs_valstr_zio_stage(i32
, flagstr
,
12069 printf(gettext("0x%x [%s]"), i32
, flagstr
);
12070 } else if (strcmp(name
,
12071 FM_EREPORT_PAYLOAD_ZFS_ZIO_PRIORITY
) == 0) {
12072 zfs_valstr_zio_priority(i32
, flagstr
,
12074 printf(gettext("0x%x [%s]"), i32
, flagstr
);
12076 printf(gettext("0x%x"), i32
);
12080 case DATA_TYPE_INT64
:
12081 (void) nvpair_value_int64(nvp
, (void *)&i64
);
12082 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
12085 case DATA_TYPE_UINT64
:
12086 (void) nvpair_value_uint64(nvp
, &i64
);
12088 * translate vdev state values to readable
12089 * strings to aide zpool events consumers
12092 FM_EREPORT_PAYLOAD_ZFS_VDEV_STATE
) == 0 ||
12094 FM_EREPORT_PAYLOAD_ZFS_VDEV_LASTSTATE
) == 0) {
12095 printf(gettext("\"%s\" (0x%llx)"),
12096 zpool_state_to_name(i64
, VDEV_AUX_NONE
),
12097 (u_longlong_t
)i64
);
12098 } else if (strcmp(name
,
12099 FM_EREPORT_PAYLOAD_ZFS_ZIO_FLAGS
) == 0) {
12100 zfs_valstr_zio_flag(i64
, flagstr
,
12102 printf(gettext("0x%llx [%s]"),
12103 (u_longlong_t
)i64
, flagstr
);
12105 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
12109 case DATA_TYPE_HRTIME
:
12110 (void) nvpair_value_hrtime(nvp
, (void *)&i64
);
12111 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
12114 case DATA_TYPE_STRING
:
12115 (void) nvpair_value_string(nvp
, &str
);
12116 printf(gettext("\"%s\""), str
? str
: "<NULL>");
12119 case DATA_TYPE_NVLIST
:
12120 printf(gettext("(embedded nvlist)\n"));
12121 (void) nvpair_value_nvlist(nvp
, &cnv
);
12122 zpool_do_events_nvprint(cnv
, depth
+ 8);
12123 printf(gettext("%*s(end %s)"), depth
, "", name
);
12126 case DATA_TYPE_NVLIST_ARRAY
: {
12130 (void) nvpair_value_nvlist_array(nvp
, &val
, &nelem
);
12131 printf(gettext("(%d embedded nvlists)\n"), nelem
);
12132 for (i
= 0; i
< nelem
; i
++) {
12133 printf(gettext("%*s%s[%d] = %s\n"),
12134 depth
, "", name
, i
, "(embedded nvlist)");
12135 zpool_do_events_nvprint(val
[i
], depth
+ 8);
12136 printf(gettext("%*s(end %s[%i])\n"),
12137 depth
, "", name
, i
);
12139 printf(gettext("%*s(end %s)\n"), depth
, "", name
);
12143 case DATA_TYPE_INT8_ARRAY
: {
12147 (void) nvpair_value_int8_array(nvp
, &val
, &nelem
);
12148 for (i
= 0; i
< nelem
; i
++)
12149 printf(gettext("0x%x "), val
[i
]);
12154 case DATA_TYPE_UINT8_ARRAY
: {
12158 (void) nvpair_value_uint8_array(nvp
, &val
, &nelem
);
12159 for (i
= 0; i
< nelem
; i
++)
12160 printf(gettext("0x%x "), val
[i
]);
12165 case DATA_TYPE_INT16_ARRAY
: {
12169 (void) nvpair_value_int16_array(nvp
, &val
, &nelem
);
12170 for (i
= 0; i
< nelem
; i
++)
12171 printf(gettext("0x%x "), val
[i
]);
12176 case DATA_TYPE_UINT16_ARRAY
: {
12180 (void) nvpair_value_uint16_array(nvp
, &val
, &nelem
);
12181 for (i
= 0; i
< nelem
; i
++)
12182 printf(gettext("0x%x "), val
[i
]);
12187 case DATA_TYPE_INT32_ARRAY
: {
12191 (void) nvpair_value_int32_array(nvp
, &val
, &nelem
);
12192 for (i
= 0; i
< nelem
; i
++)
12193 printf(gettext("0x%x "), val
[i
]);
12198 case DATA_TYPE_UINT32_ARRAY
: {
12202 (void) nvpair_value_uint32_array(nvp
, &val
, &nelem
);
12203 for (i
= 0; i
< nelem
; i
++)
12204 printf(gettext("0x%x "), val
[i
]);
12209 case DATA_TYPE_INT64_ARRAY
: {
12213 (void) nvpair_value_int64_array(nvp
, &val
, &nelem
);
12214 for (i
= 0; i
< nelem
; i
++)
12215 printf(gettext("0x%llx "),
12216 (u_longlong_t
)val
[i
]);
12221 case DATA_TYPE_UINT64_ARRAY
: {
12225 (void) nvpair_value_uint64_array(nvp
, &val
, &nelem
);
12226 for (i
= 0; i
< nelem
; i
++)
12227 printf(gettext("0x%llx "),
12228 (u_longlong_t
)val
[i
]);
12233 case DATA_TYPE_STRING_ARRAY
: {
12237 (void) nvpair_value_string_array(nvp
, &str
, &nelem
);
12238 for (i
= 0; i
< nelem
; i
++)
12239 printf(gettext("\"%s\" "),
12240 str
[i
] ? str
[i
] : "<NULL>");
12245 case DATA_TYPE_BOOLEAN_ARRAY
:
12246 case DATA_TYPE_BYTE_ARRAY
:
12247 case DATA_TYPE_DOUBLE
:
12248 case DATA_TYPE_DONTCARE
:
12249 case DATA_TYPE_UNKNOWN
:
12250 printf(gettext("<unknown>"));
12254 printf(gettext("\n"));
12259 zpool_do_events_next(ev_opts_t
*opts
)
12262 int zevent_fd
, ret
, dropped
;
12265 zevent_fd
= open(ZFS_DEV
, O_RDWR
);
12266 VERIFY(zevent_fd
>= 0);
12268 if (!opts
->scripted
)
12269 (void) printf(gettext("%-30s %s\n"), "TIME", "CLASS");
12272 ret
= zpool_events_next(g_zfs
, &nvl
, &dropped
,
12273 (opts
->follow
? ZEVENT_NONE
: ZEVENT_NONBLOCK
), zevent_fd
);
12274 if (ret
|| nvl
== NULL
)
12278 (void) printf(gettext("dropped %d events\n"), dropped
);
12280 if (strlen(opts
->poolname
) > 0 &&
12281 nvlist_lookup_string(nvl
, FM_FMRI_ZFS_POOL
, &pool
) == 0 &&
12282 strcmp(opts
->poolname
, pool
) != 0)
12285 zpool_do_events_short(nvl
, opts
);
12287 if (opts
->verbose
) {
12288 zpool_do_events_nvprint(nvl
, 8);
12289 printf(gettext("\n"));
12291 (void) fflush(stdout
);
12296 VERIFY(0 == close(zevent_fd
));
12302 zpool_do_events_clear(void)
12306 ret
= zpool_events_clear(g_zfs
, &count
);
12308 (void) printf(gettext("cleared %d events\n"), count
);
12314 * zpool events [-vHf [pool] | -c]
12316 * Displays events logs by ZFS.
12319 zpool_do_events(int argc
, char **argv
)
12321 ev_opts_t opts
= { 0 };
12325 /* check options */
12326 while ((c
= getopt(argc
, argv
, "vHfc")) != -1) {
12341 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
12350 (void) fprintf(stderr
, gettext("too many arguments\n"));
12352 } else if (argc
== 1) {
12353 (void) strlcpy(opts
.poolname
, argv
[0], sizeof (opts
.poolname
));
12354 if (!zfs_name_valid(opts
.poolname
, ZFS_TYPE_POOL
)) {
12355 (void) fprintf(stderr
,
12356 gettext("invalid pool name '%s'\n"), opts
.poolname
);
12361 if ((argc
== 1 || opts
.verbose
|| opts
.scripted
|| opts
.follow
) &&
12363 (void) fprintf(stderr
,
12364 gettext("invalid options combined with -c\n"));
12369 ret
= zpool_do_events_clear();
12371 ret
= zpool_do_events_next(&opts
);
12377 get_callback_vdev(zpool_handle_t
*zhp
, char *vdevname
, void *data
)
12379 zprop_get_cbdata_t
*cbp
= (zprop_get_cbdata_t
*)data
;
12380 char value
[ZFS_MAXPROPLEN
];
12381 zprop_source_t srctype
;
12382 nvlist_t
*props
, *item
, *d
;
12383 props
= item
= d
= NULL
;
12385 if (cbp
->cb_json
) {
12386 d
= fnvlist_lookup_nvlist(cbp
->cb_jsobj
, "vdevs");
12388 fprintf(stderr
, "vdevs obj not found.\n");
12391 props
= fnvlist_alloc();
12394 for (zprop_list_t
*pl
= cbp
->cb_proplist
; pl
!= NULL
;
12395 pl
= pl
->pl_next
) {
12398 * If the first property is pool name, it is a special
12399 * placeholder that we can skip. This will also skip
12400 * over the name property when 'all' is specified.
12402 if (pl
->pl_prop
== ZPOOL_PROP_NAME
&&
12403 pl
== cbp
->cb_proplist
)
12406 if (pl
->pl_prop
== ZPROP_INVAL
) {
12407 prop_name
= pl
->pl_user_prop
;
12409 prop_name
= (char *)vdev_prop_to_name(pl
->pl_prop
);
12411 if (zpool_get_vdev_prop(zhp
, vdevname
, pl
->pl_prop
,
12412 prop_name
, value
, sizeof (value
), &srctype
,
12413 cbp
->cb_literal
) == 0) {
12414 zprop_collect_property(vdevname
, cbp
, prop_name
,
12415 value
, srctype
, NULL
, NULL
, props
);
12419 if (cbp
->cb_json
) {
12420 if (!nvlist_empty(props
)) {
12421 item
= fnvlist_alloc();
12422 fill_vdev_info(item
, zhp
, vdevname
, B_TRUE
,
12423 cbp
->cb_json_as_int
);
12424 fnvlist_add_nvlist(item
, "properties", props
);
12425 fnvlist_add_nvlist(d
, vdevname
, item
);
12426 fnvlist_add_nvlist(cbp
->cb_jsobj
, "vdevs", d
);
12427 fnvlist_free(item
);
12429 fnvlist_free(props
);
12436 get_callback_vdev_cb(void *zhp_data
, nvlist_t
*nv
, void *data
)
12438 zpool_handle_t
*zhp
= zhp_data
;
12439 zprop_get_cbdata_t
*cbp
= (zprop_get_cbdata_t
*)data
;
12445 * zpool_vdev_name() transforms the root vdev name (i.e., root-0) to the
12446 * pool name for display purposes, which is not desired. Fallback to
12447 * zpool_vdev_name() when not dealing with the root vdev.
12449 type
= fnvlist_lookup_string(nv
, ZPOOL_CONFIG_TYPE
);
12450 if (zhp
!= NULL
&& strcmp(type
, "root") == 0)
12451 vdevname
= strdup("root-0");
12453 vdevname
= zpool_vdev_name(g_zfs
, zhp
, nv
,
12454 cbp
->cb_vdevs
.cb_name_flags
);
12456 (void) vdev_expand_proplist(zhp
, vdevname
, &cbp
->cb_proplist
);
12458 ret
= get_callback_vdev(zhp
, vdevname
, data
);
12466 get_callback(zpool_handle_t
*zhp
, void *data
)
12468 zprop_get_cbdata_t
*cbp
= (zprop_get_cbdata_t
*)data
;
12469 char value
[ZFS_MAXPROPLEN
];
12470 zprop_source_t srctype
;
12474 nvlist_t
*props
, *item
, *d
;
12475 props
= item
= d
= NULL
;
12477 if (cbp
->cb_type
== ZFS_TYPE_VDEV
) {
12478 if (cbp
->cb_json
) {
12479 nvlist_t
*pool
= fnvlist_alloc();
12480 fill_pool_info(pool
, zhp
, B_FALSE
, cbp
->cb_json_as_int
);
12481 fnvlist_add_nvlist(cbp
->cb_jsobj
, "pool", pool
);
12482 fnvlist_free(pool
);
12485 if (strcmp(cbp
->cb_vdevs
.cb_names
[0], "all-vdevs") == 0) {
12486 for_each_vdev(zhp
, get_callback_vdev_cb
, data
);
12488 /* Adjust column widths for vdev properties */
12489 for (vid
= 0; vid
< cbp
->cb_vdevs
.cb_names_count
;
12491 vdev_expand_proplist(zhp
,
12492 cbp
->cb_vdevs
.cb_names
[vid
],
12493 &cbp
->cb_proplist
);
12495 /* Display the properties */
12496 for (vid
= 0; vid
< cbp
->cb_vdevs
.cb_names_count
;
12498 get_callback_vdev(zhp
,
12499 cbp
->cb_vdevs
.cb_names
[vid
], data
);
12503 assert(cbp
->cb_type
== ZFS_TYPE_POOL
);
12504 if (cbp
->cb_json
) {
12505 d
= fnvlist_lookup_nvlist(cbp
->cb_jsobj
, "pools");
12507 fprintf(stderr
, "pools obj not found.\n");
12510 props
= fnvlist_alloc();
12512 for (pl
= cbp
->cb_proplist
; pl
!= NULL
; pl
= pl
->pl_next
) {
12514 * Skip the special fake placeholder. This will also
12515 * skip over the name property when 'all' is specified.
12517 if (pl
->pl_prop
== ZPOOL_PROP_NAME
&&
12518 pl
== cbp
->cb_proplist
)
12521 if (pl
->pl_prop
== ZPROP_INVAL
&&
12522 zfs_prop_user(pl
->pl_user_prop
)) {
12523 srctype
= ZPROP_SRC_LOCAL
;
12525 if (zpool_get_userprop(zhp
, pl
->pl_user_prop
,
12526 value
, sizeof (value
), &srctype
) != 0)
12529 err
= zprop_collect_property(
12530 zpool_get_name(zhp
), cbp
, pl
->pl_user_prop
,
12531 value
, srctype
, NULL
, NULL
, props
);
12532 } else if (pl
->pl_prop
== ZPROP_INVAL
&&
12533 (zpool_prop_feature(pl
->pl_user_prop
) ||
12534 zpool_prop_unsupported(pl
->pl_user_prop
))) {
12535 srctype
= ZPROP_SRC_LOCAL
;
12537 if (zpool_prop_get_feature(zhp
,
12538 pl
->pl_user_prop
, value
,
12539 sizeof (value
)) == 0) {
12540 err
= zprop_collect_property(
12541 zpool_get_name(zhp
), cbp
,
12542 pl
->pl_user_prop
, value
, srctype
,
12543 NULL
, NULL
, props
);
12546 if (zpool_get_prop(zhp
, pl
->pl_prop
, value
,
12547 sizeof (value
), &srctype
,
12548 cbp
->cb_literal
) != 0)
12551 err
= zprop_collect_property(
12552 zpool_get_name(zhp
), cbp
,
12553 zpool_prop_to_name(pl
->pl_prop
),
12554 value
, srctype
, NULL
, NULL
, props
);
12560 if (cbp
->cb_json
) {
12561 if (!nvlist_empty(props
)) {
12562 item
= fnvlist_alloc();
12563 fill_pool_info(item
, zhp
, B_TRUE
,
12564 cbp
->cb_json_as_int
);
12565 fnvlist_add_nvlist(item
, "properties", props
);
12566 if (cbp
->cb_json_pool_key_guid
) {
12568 uint64_t guid
= fnvlist_lookup_uint64(
12569 zpool_get_config(zhp
, NULL
),
12570 ZPOOL_CONFIG_POOL_GUID
);
12571 snprintf(buf
, 256, "%llu",
12572 (u_longlong_t
)guid
);
12573 fnvlist_add_nvlist(d
, buf
, item
);
12575 const char *name
= zpool_get_name(zhp
);
12576 fnvlist_add_nvlist(d
, name
, item
);
12578 fnvlist_add_nvlist(cbp
->cb_jsobj
, "pools", d
);
12579 fnvlist_free(item
);
12581 fnvlist_free(props
);
12589 * zpool get [-Hp] [-o "all" | field[,...]] <"all" | property[,...]> <pool> ...
12591 * -H Scripted mode. Don't display headers, and separate properties
12593 * -o List of columns to display. Defaults to
12594 * "name,property,value,source".
12595 * -p Display values in parsable (exact) format.
12596 * -j Display output in JSON format.
12597 * --json-int Display numbers as integers instead of strings.
12598 * --json-pool-key-guid Set pool GUID as key for pool objects.
12600 * Get properties of pools in the system. Output space statistics
12601 * for each one as well as other attributes.
12604 zpool_do_get(int argc
, char **argv
)
12606 zprop_get_cbdata_t cb
= { 0 };
12607 zprop_list_t fake_name
= { 0 };
12610 char *propstr
= NULL
;
12612 nvlist_t
*data
= NULL
;
12614 cb
.cb_first
= B_TRUE
;
12617 * Set up default columns and sources.
12619 cb
.cb_sources
= ZPROP_SRC_ALL
;
12620 cb
.cb_columns
[0] = GET_COL_NAME
;
12621 cb
.cb_columns
[1] = GET_COL_PROPERTY
;
12622 cb
.cb_columns
[2] = GET_COL_VALUE
;
12623 cb
.cb_columns
[3] = GET_COL_SOURCE
;
12624 cb
.cb_type
= ZFS_TYPE_POOL
;
12625 cb
.cb_vdevs
.cb_name_flags
|= VDEV_NAME_TYPE_ID
;
12626 current_prop_type
= cb
.cb_type
;
12628 struct option long_options
[] = {
12629 {"json", no_argument
, NULL
, 'j'},
12630 {"json-int", no_argument
, NULL
, ZPOOL_OPTION_JSON_NUMS_AS_INT
},
12631 {"json-pool-key-guid", no_argument
, NULL
,
12632 ZPOOL_OPTION_POOL_KEY_GUID
},
12636 /* check options */
12637 while ((c
= getopt_long(argc
, argv
, ":jHpo:", long_options
,
12641 cb
.cb_literal
= B_TRUE
;
12644 cb
.cb_scripted
= B_TRUE
;
12647 cb
.cb_json
= B_TRUE
;
12648 cb
.cb_jsobj
= zpool_json_schema(0, 1);
12649 data
= fnvlist_alloc();
12651 case ZPOOL_OPTION_POOL_KEY_GUID
:
12652 cb
.cb_json_pool_key_guid
= B_TRUE
;
12654 case ZPOOL_OPTION_JSON_NUMS_AS_INT
:
12655 cb
.cb_json_as_int
= B_TRUE
;
12656 cb
.cb_literal
= B_TRUE
;
12659 memset(&cb
.cb_columns
, 0, sizeof (cb
.cb_columns
));
12662 for (char *tok
; (tok
= strsep(&optarg
, ",")); ) {
12663 static const char *const col_opts
[] =
12664 { "name", "property", "value", "source",
12666 static const zfs_get_column_t col_cols
[] =
12667 { GET_COL_NAME
, GET_COL_PROPERTY
, GET_COL_VALUE
,
12670 if (i
== ZFS_GET_NCOLS
- 1) {
12671 (void) fprintf(stderr
, gettext("too "
12672 "many fields given to -o "
12677 for (c
= 0; c
< ARRAY_SIZE(col_opts
); ++c
)
12678 if (strcmp(tok
, col_opts
[c
]) == 0)
12681 (void) fprintf(stderr
,
12682 gettext("invalid column name '%s'\n"), tok
);
12688 (void) fprintf(stderr
,
12689 gettext("\"all\" conflicts "
12690 "with specific fields "
12691 "given to -o option\n"));
12695 memcpy(cb
.cb_columns
, col_cols
,
12696 sizeof (col_cols
));
12697 i
= ZFS_GET_NCOLS
- 1;
12699 cb
.cb_columns
[i
++] = col_cols
[c
];
12703 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
12712 if (!cb
.cb_json
&& cb
.cb_json_as_int
) {
12713 (void) fprintf(stderr
, gettext("'--json-int' only works with"
12714 " '-j' option\n"));
12718 if (!cb
.cb_json
&& cb
.cb_json_pool_key_guid
) {
12719 (void) fprintf(stderr
, gettext("'json-pool-key-guid' only"
12720 " works with '-j' option\n"));
12725 (void) fprintf(stderr
, gettext("missing property "
12730 /* Properties list is needed later by zprop_get_list() */
12737 /* No args, so just print the defaults. */
12738 } else if (are_all_pools(argc
, argv
)) {
12739 /* All the args are pool names */
12740 } else if (are_all_pools(1, argv
)) {
12741 /* The first arg is a pool name */
12742 if ((argc
== 2 && strcmp(argv
[1], "all-vdevs") == 0) ||
12743 (argc
== 2 && strcmp(argv
[1], "root") == 0) ||
12744 are_vdevs_in_pool(argc
- 1, argv
+ 1, argv
[0],
12747 if (strcmp(argv
[1], "root") == 0)
12748 vdev
= strdup("root-0");
12750 vdev
= strdup(argv
[1]);
12752 /* ... and the rest are vdev names */
12753 cb
.cb_vdevs
.cb_names
= &vdev
;
12754 cb
.cb_vdevs
.cb_names_count
= argc
- 1;
12755 cb
.cb_type
= ZFS_TYPE_VDEV
;
12756 argc
= 1; /* One pool to process */
12759 nvlist_free(cb
.cb_jsobj
);
12762 fprintf(stderr
, gettext("Expected a list of vdevs in"
12763 " \"%s\", but got:\n"), argv
[0]);
12764 error_list_unresolved_vdevs(argc
- 1, argv
+ 1,
12765 argv
[0], &cb
.cb_vdevs
);
12766 fprintf(stderr
, "\n");
12772 nvlist_free(cb
.cb_jsobj
);
12776 * The first arg isn't the name of a valid pool.
12778 fprintf(stderr
, gettext("Cannot get properties of %s: "
12779 "no such pool available.\n"), argv
[0]);
12783 if (zprop_get_list(g_zfs
, propstr
, &cb
.cb_proplist
,
12784 cb
.cb_type
) != 0) {
12785 /* Use correct list of valid properties (pool or vdev) */
12786 current_prop_type
= cb
.cb_type
;
12790 if (cb
.cb_proplist
!= NULL
) {
12791 fake_name
.pl_prop
= ZPOOL_PROP_NAME
;
12792 fake_name
.pl_width
= strlen(gettext("NAME"));
12793 fake_name
.pl_next
= cb
.cb_proplist
;
12794 cb
.cb_proplist
= &fake_name
;
12798 if (cb
.cb_type
== ZFS_TYPE_VDEV
)
12799 fnvlist_add_nvlist(cb
.cb_jsobj
, "vdevs", data
);
12801 fnvlist_add_nvlist(cb
.cb_jsobj
, "pools", data
);
12802 fnvlist_free(data
);
12805 ret
= for_each_pool(argc
, argv
, B_TRUE
, &cb
.cb_proplist
, cb
.cb_type
,
12806 cb
.cb_literal
, get_callback
, &cb
);
12808 if (ret
== 0 && cb
.cb_json
)
12809 zcmd_print_json(cb
.cb_jsobj
);
12810 else if (ret
!= 0 && cb
.cb_json
)
12811 nvlist_free(cb
.cb_jsobj
);
12813 if (cb
.cb_proplist
== &fake_name
)
12814 zprop_free_list(fake_name
.pl_next
);
12816 zprop_free_list(cb
.cb_proplist
);
12824 typedef struct set_cbdata
{
12827 zfs_type_t cb_type
;
12828 vdev_cbdata_t cb_vdevs
;
12829 boolean_t cb_any_successful
;
12833 set_pool_callback(zpool_handle_t
*zhp
, set_cbdata_t
*cb
)
12837 /* Check if we have out-of-bounds features */
12838 if (strcmp(cb
->cb_propname
, ZPOOL_CONFIG_COMPATIBILITY
) == 0) {
12839 boolean_t features
[SPA_FEATURES
];
12840 if (zpool_do_load_compat(cb
->cb_value
, features
) !=
12841 ZPOOL_COMPATIBILITY_OK
)
12844 nvlist_t
*enabled
= zpool_get_features(zhp
);
12846 for (i
= 0; i
< SPA_FEATURES
; i
++) {
12847 const char *fguid
= spa_feature_table
[i
].fi_guid
;
12848 if (nvlist_exists(enabled
, fguid
) && !features
[i
])
12851 if (i
< SPA_FEATURES
)
12852 (void) fprintf(stderr
, gettext("Warning: one or "
12853 "more features already enabled on pool '%s'\n"
12854 "are not present in this compatibility set.\n"),
12855 zpool_get_name(zhp
));
12858 /* if we're setting a feature, check it's in compatibility set */
12859 if (zpool_prop_feature(cb
->cb_propname
) &&
12860 strcmp(cb
->cb_value
, ZFS_FEATURE_ENABLED
) == 0) {
12861 char *fname
= strchr(cb
->cb_propname
, '@') + 1;
12864 if (zfeature_lookup_name(fname
, &f
) == 0) {
12865 char compat
[ZFS_MAXPROPLEN
];
12866 if (zpool_get_prop(zhp
, ZPOOL_PROP_COMPATIBILITY
,
12867 compat
, ZFS_MAXPROPLEN
, NULL
, B_FALSE
) != 0)
12870 boolean_t features
[SPA_FEATURES
];
12871 if (zpool_do_load_compat(compat
, features
) !=
12872 ZPOOL_COMPATIBILITY_OK
) {
12873 (void) fprintf(stderr
, gettext("Error: "
12874 "cannot enable feature '%s' on pool '%s'\n"
12875 "because the pool's 'compatibility' "
12876 "property cannot be parsed.\n"),
12877 fname
, zpool_get_name(zhp
));
12881 if (!features
[f
]) {
12882 (void) fprintf(stderr
, gettext("Error: "
12883 "cannot enable feature '%s' on pool '%s'\n"
12884 "as it is not specified in this pool's "
12885 "current compatibility set.\n"
12886 "Consider setting 'compatibility' to a "
12887 "less restrictive set, or to 'off'.\n"),
12888 fname
, zpool_get_name(zhp
));
12894 error
= zpool_set_prop(zhp
, cb
->cb_propname
, cb
->cb_value
);
12900 set_callback(zpool_handle_t
*zhp
, void *data
)
12903 set_cbdata_t
*cb
= (set_cbdata_t
*)data
;
12905 if (cb
->cb_type
== ZFS_TYPE_VDEV
) {
12906 error
= zpool_set_vdev_prop(zhp
, *cb
->cb_vdevs
.cb_names
,
12907 cb
->cb_propname
, cb
->cb_value
);
12909 assert(cb
->cb_type
== ZFS_TYPE_POOL
);
12910 error
= set_pool_callback(zhp
, cb
);
12913 cb
->cb_any_successful
= !error
;
12918 zpool_do_set(int argc
, char **argv
)
12920 set_cbdata_t cb
= { 0 };
12924 current_prop_type
= ZFS_TYPE_POOL
;
12925 if (argc
> 1 && argv
[1][0] == '-') {
12926 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
12932 (void) fprintf(stderr
, gettext("missing property=value "
12938 (void) fprintf(stderr
, gettext("missing pool name\n"));
12943 (void) fprintf(stderr
, gettext("too many pool names\n"));
12947 cb
.cb_propname
= argv
[1];
12948 cb
.cb_type
= ZFS_TYPE_POOL
;
12949 cb
.cb_vdevs
.cb_name_flags
|= VDEV_NAME_TYPE_ID
;
12950 cb
.cb_value
= strchr(cb
.cb_propname
, '=');
12951 if (cb
.cb_value
== NULL
) {
12952 (void) fprintf(stderr
, gettext("missing value in "
12953 "property=value argument\n"));
12957 *(cb
.cb_value
) = '\0';
12962 /* argv[0] is pool name */
12963 if (!is_pool(argv
[0])) {
12964 (void) fprintf(stderr
,
12965 gettext("cannot open '%s': is not a pool\n"), argv
[0]);
12969 /* argv[1], when supplied, is vdev name */
12972 if (strcmp(argv
[1], "root") == 0)
12973 vdev
= strdup("root-0");
12975 vdev
= strdup(argv
[1]);
12977 if (!are_vdevs_in_pool(1, &vdev
, argv
[0], &cb
.cb_vdevs
)) {
12978 (void) fprintf(stderr
, gettext(
12979 "cannot find '%s' in '%s': device not in pool\n"),
12984 cb
.cb_vdevs
.cb_names
= &vdev
;
12985 cb
.cb_vdevs
.cb_names_count
= 1;
12986 cb
.cb_type
= ZFS_TYPE_VDEV
;
12989 error
= for_each_pool(1, argv
, B_TRUE
, NULL
, ZFS_TYPE_POOL
,
12990 B_FALSE
, set_callback
, &cb
);
12998 /* Add up the total number of bytes left to initialize/trim across all vdevs */
13000 vdev_activity_remaining(nvlist_t
*nv
, zpool_wait_activity_t activity
)
13002 uint64_t bytes_remaining
;
13004 uint_t c
, children
;
13007 assert(activity
== ZPOOL_WAIT_INITIALIZE
||
13008 activity
== ZPOOL_WAIT_TRIM
);
13010 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
13011 (uint64_t **)&vs
, &c
) == 0);
13013 if (activity
== ZPOOL_WAIT_INITIALIZE
&&
13014 vs
->vs_initialize_state
== VDEV_INITIALIZE_ACTIVE
)
13015 bytes_remaining
= vs
->vs_initialize_bytes_est
-
13016 vs
->vs_initialize_bytes_done
;
13017 else if (activity
== ZPOOL_WAIT_TRIM
&&
13018 vs
->vs_trim_state
== VDEV_TRIM_ACTIVE
)
13019 bytes_remaining
= vs
->vs_trim_bytes_est
-
13020 vs
->vs_trim_bytes_done
;
13022 bytes_remaining
= 0;
13024 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
13025 &child
, &children
) != 0)
13028 for (c
= 0; c
< children
; c
++)
13029 bytes_remaining
+= vdev_activity_remaining(child
[c
], activity
);
13031 return (bytes_remaining
);
13034 /* Add up the total number of bytes left to rebuild across top-level vdevs */
13036 vdev_activity_top_remaining(nvlist_t
*nv
)
13038 uint64_t bytes_remaining
= 0;
13043 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
13044 &child
, &children
) != 0)
13047 for (uint_t c
= 0; c
< children
; c
++) {
13048 vdev_rebuild_stat_t
*vrs
;
13051 error
= nvlist_lookup_uint64_array(child
[c
],
13052 ZPOOL_CONFIG_REBUILD_STATS
, (uint64_t **)&vrs
, &i
);
13054 if (vrs
->vrs_state
== VDEV_REBUILD_ACTIVE
) {
13055 bytes_remaining
+= (vrs
->vrs_bytes_est
-
13056 vrs
->vrs_bytes_rebuilt
);
13061 return (bytes_remaining
);
13064 /* Whether any vdevs are 'spare' or 'replacing' vdevs */
13066 vdev_any_spare_replacing(nvlist_t
*nv
)
13069 uint_t c
, children
;
13070 const char *vdev_type
;
13072 (void) nvlist_lookup_string(nv
, ZPOOL_CONFIG_TYPE
, &vdev_type
);
13074 if (strcmp(vdev_type
, VDEV_TYPE_REPLACING
) == 0 ||
13075 strcmp(vdev_type
, VDEV_TYPE_SPARE
) == 0 ||
13076 strcmp(vdev_type
, VDEV_TYPE_DRAID_SPARE
) == 0) {
13080 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
13081 &child
, &children
) != 0)
13084 for (c
= 0; c
< children
; c
++) {
13085 if (vdev_any_spare_replacing(child
[c
]))
13092 typedef struct wait_data
{
13094 boolean_t wd_scripted
;
13095 boolean_t wd_exact
;
13096 boolean_t wd_headers_once
;
13097 boolean_t wd_should_exit
;
13098 /* Which activities to wait for */
13099 boolean_t wd_enabled
[ZPOOL_WAIT_NUM_ACTIVITIES
];
13101 pthread_cond_t wd_cv
;
13102 pthread_mutex_t wd_mutex
;
13106 * Print to stdout a single line, containing one column for each activity that
13107 * we are waiting for specifying how many bytes of work are left for that
13111 print_wait_status_row(wait_data_t
*wd
, zpool_handle_t
*zhp
, int row
)
13113 nvlist_t
*config
, *nvroot
;
13116 pool_checkpoint_stat_t
*pcs
= NULL
;
13117 pool_scan_stat_t
*pss
= NULL
;
13118 pool_removal_stat_t
*prs
= NULL
;
13119 pool_raidz_expand_stat_t
*pres
= NULL
;
13120 const char *const headers
[] = {"DISCARD", "FREE", "INITIALIZE",
13121 "REPLACE", "REMOVE", "RESILVER", "SCRUB", "TRIM", "RAIDZ_EXPAND"};
13122 int col_widths
[ZPOOL_WAIT_NUM_ACTIVITIES
];
13124 /* Calculate the width of each column */
13125 for (i
= 0; i
< ZPOOL_WAIT_NUM_ACTIVITIES
; i
++) {
13127 * Make sure we have enough space in the col for pretty-printed
13128 * numbers and for the column header, and then leave a couple
13129 * spaces between cols for readability.
13131 col_widths
[i
] = MAX(strlen(headers
[i
]), 6) + 2;
13134 if (timestamp_fmt
!= NODATE
)
13135 print_timestamp(timestamp_fmt
);
13137 /* Print header if appropriate */
13138 int term_height
= terminal_height();
13139 boolean_t reprint_header
= (!wd
->wd_headers_once
&& term_height
> 0 &&
13140 row
% (term_height
-1) == 0);
13141 if (!wd
->wd_scripted
&& (row
== 0 || reprint_header
)) {
13142 for (i
= 0; i
< ZPOOL_WAIT_NUM_ACTIVITIES
; i
++) {
13143 if (wd
->wd_enabled
[i
])
13144 (void) printf("%*s", col_widths
[i
], headers
[i
]);
13146 (void) fputc('\n', stdout
);
13149 /* Bytes of work remaining in each activity */
13150 int64_t bytes_rem
[ZPOOL_WAIT_NUM_ACTIVITIES
] = {0};
13152 bytes_rem
[ZPOOL_WAIT_FREE
] =
13153 zpool_get_prop_int(zhp
, ZPOOL_PROP_FREEING
, NULL
);
13155 config
= zpool_get_config(zhp
, NULL
);
13156 nvroot
= fnvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
);
13158 (void) nvlist_lookup_uint64_array(nvroot
,
13159 ZPOOL_CONFIG_CHECKPOINT_STATS
, (uint64_t **)&pcs
, &c
);
13160 if (pcs
!= NULL
&& pcs
->pcs_state
== CS_CHECKPOINT_DISCARDING
)
13161 bytes_rem
[ZPOOL_WAIT_CKPT_DISCARD
] = pcs
->pcs_space
;
13163 (void) nvlist_lookup_uint64_array(nvroot
,
13164 ZPOOL_CONFIG_REMOVAL_STATS
, (uint64_t **)&prs
, &c
);
13165 if (prs
!= NULL
&& prs
->prs_state
== DSS_SCANNING
)
13166 bytes_rem
[ZPOOL_WAIT_REMOVE
] = prs
->prs_to_copy
-
13169 (void) nvlist_lookup_uint64_array(nvroot
,
13170 ZPOOL_CONFIG_SCAN_STATS
, (uint64_t **)&pss
, &c
);
13171 if (pss
!= NULL
&& pss
->pss_state
== DSS_SCANNING
&&
13172 pss
->pss_pass_scrub_pause
== 0) {
13173 int64_t rem
= pss
->pss_to_examine
- pss
->pss_issued
;
13174 if (pss
->pss_func
== POOL_SCAN_SCRUB
)
13175 bytes_rem
[ZPOOL_WAIT_SCRUB
] = rem
;
13177 bytes_rem
[ZPOOL_WAIT_RESILVER
] = rem
;
13178 } else if (check_rebuilding(nvroot
, NULL
)) {
13179 bytes_rem
[ZPOOL_WAIT_RESILVER
] =
13180 vdev_activity_top_remaining(nvroot
);
13183 (void) nvlist_lookup_uint64_array(nvroot
,
13184 ZPOOL_CONFIG_RAIDZ_EXPAND_STATS
, (uint64_t **)&pres
, &c
);
13185 if (pres
!= NULL
&& pres
->pres_state
== DSS_SCANNING
) {
13186 int64_t rem
= pres
->pres_to_reflow
- pres
->pres_reflowed
;
13187 bytes_rem
[ZPOOL_WAIT_RAIDZ_EXPAND
] = rem
;
13190 bytes_rem
[ZPOOL_WAIT_INITIALIZE
] =
13191 vdev_activity_remaining(nvroot
, ZPOOL_WAIT_INITIALIZE
);
13192 bytes_rem
[ZPOOL_WAIT_TRIM
] =
13193 vdev_activity_remaining(nvroot
, ZPOOL_WAIT_TRIM
);
13196 * A replace finishes after resilvering finishes, so the amount of work
13197 * left for a replace is the same as for resilvering.
13199 * It isn't quite correct to say that if we have any 'spare' or
13200 * 'replacing' vdevs and a resilver is happening, then a replace is in
13201 * progress, like we do here. When a hot spare is used, the faulted vdev
13202 * is not removed after the hot spare is resilvered, so parent 'spare'
13203 * vdev is not removed either. So we could have a 'spare' vdev, but be
13204 * resilvering for a different reason. However, we use it as a heuristic
13205 * because we don't have access to the DTLs, which could tell us whether
13206 * or not we have really finished resilvering a hot spare.
13208 if (vdev_any_spare_replacing(nvroot
))
13209 bytes_rem
[ZPOOL_WAIT_REPLACE
] = bytes_rem
[ZPOOL_WAIT_RESILVER
];
13211 for (i
= 0; i
< ZPOOL_WAIT_NUM_ACTIVITIES
; i
++) {
13213 if (!wd
->wd_enabled
[i
])
13216 if (wd
->wd_exact
) {
13217 (void) snprintf(buf
, sizeof (buf
), "%" PRIi64
,
13220 zfs_nicenum(bytes_rem
[i
], buf
, sizeof (buf
));
13223 if (wd
->wd_scripted
)
13224 (void) printf(i
== 0 ? "%s" : "\t%s", buf
);
13226 (void) printf(" %*s", col_widths
[i
] - 1, buf
);
13228 (void) printf("\n");
13229 (void) fflush(stdout
);
13233 wait_status_thread(void *arg
)
13235 wait_data_t
*wd
= (wait_data_t
*)arg
;
13236 zpool_handle_t
*zhp
;
13238 if ((zhp
= zpool_open(g_zfs
, wd
->wd_poolname
)) == NULL
)
13239 return (void *)(1);
13241 for (int row
= 0; ; row
++) {
13243 struct timespec timeout
;
13245 (void) clock_gettime(CLOCK_REALTIME
, &timeout
);
13247 if (zpool_refresh_stats(zhp
, &missing
) != 0 || missing
||
13248 zpool_props_refresh(zhp
) != 0) {
13250 return (void *)(uintptr_t)(missing
? 0 : 1);
13253 print_wait_status_row(wd
, zhp
, row
);
13255 timeout
.tv_sec
+= floor(wd
->wd_interval
);
13256 long nanos
= timeout
.tv_nsec
+
13257 (wd
->wd_interval
- floor(wd
->wd_interval
)) * NANOSEC
;
13258 if (nanos
>= NANOSEC
) {
13260 timeout
.tv_nsec
= nanos
- NANOSEC
;
13262 timeout
.tv_nsec
= nanos
;
13264 pthread_mutex_lock(&wd
->wd_mutex
);
13265 if (!wd
->wd_should_exit
)
13266 ret
= pthread_cond_timedwait(&wd
->wd_cv
, &wd
->wd_mutex
,
13268 pthread_mutex_unlock(&wd
->wd_mutex
);
13270 break; /* signaled by main thread */
13271 } else if (ret
!= ETIMEDOUT
) {
13272 (void) fprintf(stderr
, gettext("pthread_cond_timedwait "
13273 "failed: %s\n"), strerror(ret
));
13275 return (void *)(uintptr_t)(1);
13280 return (void *)(0);
13284 zpool_do_wait(int argc
, char **argv
)
13286 boolean_t verbose
= B_FALSE
;
13288 unsigned long count
;
13289 pthread_t status_thr
;
13291 zpool_handle_t
*zhp
;
13294 wd
.wd_scripted
= B_FALSE
;
13295 wd
.wd_exact
= B_FALSE
;
13296 wd
.wd_headers_once
= B_FALSE
;
13297 wd
.wd_should_exit
= B_FALSE
;
13299 pthread_mutex_init(&wd
.wd_mutex
, NULL
);
13300 pthread_cond_init(&wd
.wd_cv
, NULL
);
13302 /* By default, wait for all types of activity. */
13303 for (i
= 0; i
< ZPOOL_WAIT_NUM_ACTIVITIES
; i
++)
13304 wd
.wd_enabled
[i
] = B_TRUE
;
13306 while ((c
= getopt(argc
, argv
, "HpT:t:")) != -1) {
13309 wd
.wd_scripted
= B_TRUE
;
13312 wd
.wd_headers_once
= B_TRUE
;
13315 wd
.wd_exact
= B_TRUE
;
13318 get_timestamp_arg(*optarg
);
13321 /* Reset activities array */
13322 memset(&wd
.wd_enabled
, 0, sizeof (wd
.wd_enabled
));
13324 for (char *tok
; (tok
= strsep(&optarg
, ",")); ) {
13325 static const char *const col_opts
[] = {
13326 "discard", "free", "initialize", "replace",
13327 "remove", "resilver", "scrub", "trim",
13330 for (i
= 0; i
< ARRAY_SIZE(col_opts
); ++i
)
13331 if (strcmp(tok
, col_opts
[i
]) == 0) {
13332 wd
.wd_enabled
[i
] = B_TRUE
;
13336 (void) fprintf(stderr
,
13337 gettext("invalid activity '%s'\n"), tok
);
13343 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
13352 get_interval_count(&argc
, argv
, &wd
.wd_interval
, &count
);
13354 /* This subcmd only accepts an interval, not a count */
13355 (void) fprintf(stderr
, gettext("too many arguments\n"));
13359 if (wd
.wd_interval
!= 0)
13363 (void) fprintf(stderr
, gettext("missing 'pool' argument\n"));
13367 (void) fprintf(stderr
, gettext("too many arguments\n"));
13371 wd
.wd_poolname
= argv
[0];
13373 if ((zhp
= zpool_open(g_zfs
, wd
.wd_poolname
)) == NULL
)
13378 * We use a separate thread for printing status updates because
13379 * the main thread will call lzc_wait(), which blocks as long
13380 * as an activity is in progress, which can be a long time.
13382 if (pthread_create(&status_thr
, NULL
, wait_status_thread
, &wd
)
13384 (void) fprintf(stderr
, gettext("failed to create status"
13385 "thread: %s\n"), strerror(errno
));
13392 * Loop over all activities that we are supposed to wait for until none
13393 * of them are in progress. Note that this means we can end up waiting
13394 * for more activities to complete than just those that were in progress
13395 * when we began waiting; if an activity we are interested in begins
13396 * while we are waiting for another activity, we will wait for both to
13397 * complete before exiting.
13400 boolean_t missing
= B_FALSE
;
13401 boolean_t any_waited
= B_FALSE
;
13403 for (i
= 0; i
< ZPOOL_WAIT_NUM_ACTIVITIES
; i
++) {
13406 if (!wd
.wd_enabled
[i
])
13409 error
= zpool_wait_status(zhp
, i
, &missing
, &waited
);
13410 if (error
!= 0 || missing
)
13413 any_waited
= (any_waited
|| waited
);
13416 if (error
!= 0 || missing
|| !any_waited
)
13424 pthread_mutex_lock(&wd
.wd_mutex
);
13425 wd
.wd_should_exit
= B_TRUE
;
13426 pthread_cond_signal(&wd
.wd_cv
);
13427 pthread_mutex_unlock(&wd
.wd_mutex
);
13428 (void) pthread_join(status_thr
, (void *)&status
);
13433 pthread_mutex_destroy(&wd
.wd_mutex
);
13434 pthread_cond_destroy(&wd
.wd_cv
);
13439 * zpool ddtprune -d|-p <amount> <pool>
13441 * -d <days> Prune entries <days> old and older
13442 * -p <percent> Prune <percent> amount of entries
13444 * Prune single reference entries from DDT to satisfy the amount specified.
13447 zpool_do_ddt_prune(int argc
, char **argv
)
13449 zpool_ddt_prune_unit_t unit
= ZPOOL_DDT_PRUNE_NONE
;
13450 uint64_t amount
= 0;
13451 zpool_handle_t
*zhp
;
13455 while ((c
= getopt(argc
, argv
, "d:p:")) != -1) {
13458 if (unit
== ZPOOL_DDT_PRUNE_PERCENTAGE
) {
13459 (void) fprintf(stderr
, gettext("-d cannot be "
13460 "combined with -p option\n"));
13464 amount
= strtoull(optarg
, &endptr
, 0);
13465 if (errno
!= 0 || *endptr
!= '\0' || amount
== 0) {
13466 (void) fprintf(stderr
,
13467 gettext("invalid days value\n"));
13470 amount
*= 86400; /* convert days to seconds */
13471 unit
= ZPOOL_DDT_PRUNE_AGE
;
13474 if (unit
== ZPOOL_DDT_PRUNE_AGE
) {
13475 (void) fprintf(stderr
, gettext("-p cannot be "
13476 "combined with -d option\n"));
13480 amount
= strtoull(optarg
, &endptr
, 0);
13481 if (errno
!= 0 || *endptr
!= '\0' ||
13482 amount
== 0 || amount
> 100) {
13483 (void) fprintf(stderr
,
13484 gettext("invalid percentage value\n"));
13487 unit
= ZPOOL_DDT_PRUNE_PERCENTAGE
;
13490 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
13498 if (unit
== ZPOOL_DDT_PRUNE_NONE
) {
13499 (void) fprintf(stderr
,
13500 gettext("missing amount option (-d|-p <value>)\n"));
13502 } else if (argc
< 1) {
13503 (void) fprintf(stderr
, gettext("missing pool argument\n"));
13505 } else if (argc
> 1) {
13506 (void) fprintf(stderr
, gettext("too many arguments\n"));
13509 zhp
= zpool_open(g_zfs
, argv
[0]);
13513 int error
= zpool_ddt_prune(zhp
, unit
, amount
);
13521 find_command_idx(const char *command
, int *idx
)
13523 for (int i
= 0; i
< NCOMMAND
; ++i
) {
13524 if (command_table
[i
].name
== NULL
)
13527 if (strcmp(command
, command_table
[i
].name
) == 0) {
13536 * Display version message
13539 zpool_do_version(int argc
, char **argv
)
13542 nvlist_t
*jsobj
= NULL
, *zfs_ver
= NULL
;
13543 boolean_t json
= B_FALSE
;
13545 struct option long_options
[] = {
13546 {"json", no_argument
, NULL
, 'j'},
13549 while ((c
= getopt_long(argc
, argv
, "j", long_options
, NULL
)) != -1) {
13553 jsobj
= zpool_json_schema(0, 1);
13556 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
13564 (void) fprintf(stderr
, "too many arguments\n");
13569 zfs_ver
= zfs_version_nvlist();
13571 fnvlist_add_nvlist(jsobj
, "zfs_version", zfs_ver
);
13572 zcmd_print_json(jsobj
);
13573 fnvlist_free(zfs_ver
);
13578 return (zfs_version_print() != 0);
13581 /* Display documentation */
13583 zpool_do_help(int argc
, char **argv
)
13585 char page
[MAXNAMELEN
];
13586 if (argc
< 3 || strcmp(argv
[2], "zpool") == 0)
13587 strcpy(page
, "zpool");
13588 else if (strcmp(argv
[2], "concepts") == 0 ||
13589 strcmp(argv
[2], "props") == 0)
13590 snprintf(page
, sizeof (page
), "zpool%s", argv
[2]);
13592 snprintf(page
, sizeof (page
), "zpool-%s", argv
[2]);
13594 execlp("man", "man", page
, NULL
);
13596 fprintf(stderr
, "couldn't run man program: %s", strerror(errno
));
13601 * Do zpool_load_compat() and print error message on failure
13603 static zpool_compat_status_t
13604 zpool_do_load_compat(const char *compat
, boolean_t
*list
)
13608 zpool_compat_status_t ret
;
13610 ret
= zpool_load_compat(compat
, list
, report
, 1024);
13613 case ZPOOL_COMPATIBILITY_OK
:
13616 case ZPOOL_COMPATIBILITY_NOFILES
:
13617 case ZPOOL_COMPATIBILITY_BADFILE
:
13618 case ZPOOL_COMPATIBILITY_BADTOKEN
:
13619 (void) fprintf(stderr
, "Error: %s\n", report
);
13622 case ZPOOL_COMPATIBILITY_WARNTOKEN
:
13623 (void) fprintf(stderr
, "Warning: %s\n", report
);
13624 ret
= ZPOOL_COMPATIBILITY_OK
;
13631 main(int argc
, char **argv
)
13638 (void) setlocale(LC_ALL
, "");
13639 (void) setlocale(LC_NUMERIC
, "C");
13640 (void) textdomain(TEXT_DOMAIN
);
13646 * Make sure the user has specified some command.
13649 (void) fprintf(stderr
, gettext("missing command\n"));
13656 * Special case '-?'
13658 if ((strcmp(cmdname
, "-?") == 0) || strcmp(cmdname
, "--help") == 0)
13662 * Special case '-V|--version'
13664 if ((strcmp(cmdname
, "-V") == 0) || (strcmp(cmdname
, "--version") == 0))
13665 return (zfs_version_print() != 0);
13668 * Special case 'help'
13670 if (strcmp(cmdname
, "help") == 0)
13671 return (zpool_do_help(argc
, argv
));
13673 if ((g_zfs
= libzfs_init()) == NULL
) {
13674 (void) fprintf(stderr
, "%s\n", libzfs_error_init(errno
));
13678 libzfs_print_on_error(g_zfs
, B_TRUE
);
13680 zfs_save_arguments(argc
, argv
, history_str
, sizeof (history_str
));
13683 * Many commands modify input strings for string parsing reasons.
13684 * We create a copy to protect the original argv.
13686 newargv
= safe_malloc((argc
+ 1) * sizeof (newargv
[0]));
13687 for (i
= 0; i
< argc
; i
++)
13688 newargv
[i
] = strdup(argv
[i
]);
13689 newargv
[argc
] = NULL
;
13692 * Run the appropriate command.
13694 if (find_command_idx(cmdname
, &i
) == 0) {
13695 current_command
= &command_table
[i
];
13696 ret
= command_table
[i
].func(argc
- 1, newargv
+ 1);
13697 } else if (strchr(cmdname
, '=')) {
13698 verify(find_command_idx("set", &i
) == 0);
13699 current_command
= &command_table
[i
];
13700 ret
= command_table
[i
].func(argc
, newargv
);
13701 } else if (strcmp(cmdname
, "freeze") == 0 && argc
== 3) {
13703 * 'freeze' is a vile debugging abomination, so we treat
13706 zfs_cmd_t zc
= {"\0"};
13708 (void) strlcpy(zc
.zc_name
, argv
[2], sizeof (zc
.zc_name
));
13709 ret
= zfs_ioctl(g_zfs
, ZFS_IOC_POOL_FREEZE
, &zc
);
13711 (void) fprintf(stderr
,
13712 gettext("failed to freeze pool: %d\n"), errno
);
13718 (void) fprintf(stderr
, gettext("unrecognized "
13719 "command '%s'\n"), cmdname
);
13724 for (i
= 0; i
< argc
; i
++)
13728 if (ret
== 0 && log_history
)
13729 (void) zpool_log_history(g_zfs
, history_str
);
13731 libzfs_fini(g_zfs
);
13734 * The 'ZFS_ABORT' environment variable causes us to dump core on exit
13735 * for the purposes of running ::findleaks.
13737 if (getenv("ZFS_ABORT") != NULL
) {
13738 (void) printf("dumping core by request\n");