4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25 * Copyright (c) 2011, 2020 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>
58 #include <sys/fs/zfs.h>
60 #include <sys/systeminfo.h>
61 #include <sys/fm/fs/zfs.h>
62 #include <sys/fm/util.h>
63 #include <sys/fm/protocol.h>
64 #include <sys/zfs_ioctl.h>
65 #include <sys/mount.h>
66 #include <sys/sysmacros.h>
73 #include "zpool_util.h"
74 #include "zfs_comutil.h"
75 #include "zfeature_common.h"
77 #include "statcommon.h"
79 libzfs_handle_t
*g_zfs
;
81 static int zpool_do_create(int, char **);
82 static int zpool_do_destroy(int, char **);
84 static int zpool_do_add(int, char **);
85 static int zpool_do_remove(int, char **);
86 static int zpool_do_labelclear(int, char **);
88 static int zpool_do_checkpoint(int, char **);
90 static int zpool_do_list(int, char **);
91 static int zpool_do_iostat(int, char **);
92 static int zpool_do_status(int, char **);
94 static int zpool_do_online(int, char **);
95 static int zpool_do_offline(int, char **);
96 static int zpool_do_clear(int, char **);
97 static int zpool_do_reopen(int, char **);
99 static int zpool_do_reguid(int, char **);
101 static int zpool_do_attach(int, char **);
102 static int zpool_do_detach(int, char **);
103 static int zpool_do_replace(int, char **);
104 static int zpool_do_split(int, char **);
106 static int zpool_do_initialize(int, char **);
107 static int zpool_do_scrub(int, char **);
108 static int zpool_do_resilver(int, char **);
109 static int zpool_do_trim(int, char **);
111 static int zpool_do_import(int, char **);
112 static int zpool_do_export(int, char **);
114 static int zpool_do_upgrade(int, char **);
116 static int zpool_do_history(int, char **);
117 static int zpool_do_events(int, char **);
119 static int zpool_do_get(int, char **);
120 static int zpool_do_set(int, char **);
122 static int zpool_do_sync(int, char **);
124 static int zpool_do_version(int, char **);
126 static int zpool_do_wait(int, char **);
128 static zpool_compat_status_t
zpool_do_load_compat(
129 const char *, boolean_t
*);
132 * These libumem hooks provide a reasonable set of defaults for the allocator's
133 * debugging facilities.
138 _umem_debug_init(void)
140 return ("default,verbose"); /* $UMEM_DEBUG setting */
144 _umem_logging_init(void)
146 return ("fail,contents"); /* $UMEM_LOGGING setting */
187 * Flags for stats to display with "zpool iostats"
195 IOS_COUNT
, /* always last element */
198 /* iostat_type entries as bitmasks */
199 #define IOS_DEFAULT_M (1ULL << IOS_DEFAULT)
200 #define IOS_LATENCY_M (1ULL << IOS_LATENCY)
201 #define IOS_QUEUES_M (1ULL << IOS_QUEUES)
202 #define IOS_L_HISTO_M (1ULL << IOS_L_HISTO)
203 #define IOS_RQ_HISTO_M (1ULL << IOS_RQ_HISTO)
205 /* Mask of all the histo bits */
206 #define IOS_ANYHISTO_M (IOS_L_HISTO_M | IOS_RQ_HISTO_M)
209 * Lookup table for iostat flags to nvlist names. Basically a list
210 * of all the nvlists a flag requires. Also specifies the order in
211 * which data gets printed in zpool iostat.
213 static const char *vsx_type_to_nvlist
[IOS_COUNT
][13] = {
215 ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO
,
216 ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO
,
217 ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO
,
218 ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO
,
219 ZPOOL_CONFIG_VDEV_SYNC_R_LAT_HISTO
,
220 ZPOOL_CONFIG_VDEV_SYNC_W_LAT_HISTO
,
221 ZPOOL_CONFIG_VDEV_ASYNC_R_LAT_HISTO
,
222 ZPOOL_CONFIG_VDEV_ASYNC_W_LAT_HISTO
,
223 ZPOOL_CONFIG_VDEV_SCRUB_LAT_HISTO
,
224 ZPOOL_CONFIG_VDEV_TRIM_LAT_HISTO
,
227 ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO
,
228 ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO
,
229 ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO
,
230 ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO
,
231 ZPOOL_CONFIG_VDEV_TRIM_LAT_HISTO
,
234 ZPOOL_CONFIG_VDEV_SYNC_R_ACTIVE_QUEUE
,
235 ZPOOL_CONFIG_VDEV_SYNC_W_ACTIVE_QUEUE
,
236 ZPOOL_CONFIG_VDEV_ASYNC_R_ACTIVE_QUEUE
,
237 ZPOOL_CONFIG_VDEV_ASYNC_W_ACTIVE_QUEUE
,
238 ZPOOL_CONFIG_VDEV_SCRUB_ACTIVE_QUEUE
,
239 ZPOOL_CONFIG_VDEV_TRIM_ACTIVE_QUEUE
,
242 ZPOOL_CONFIG_VDEV_SYNC_IND_R_HISTO
,
243 ZPOOL_CONFIG_VDEV_SYNC_AGG_R_HISTO
,
244 ZPOOL_CONFIG_VDEV_SYNC_IND_W_HISTO
,
245 ZPOOL_CONFIG_VDEV_SYNC_AGG_W_HISTO
,
246 ZPOOL_CONFIG_VDEV_ASYNC_IND_R_HISTO
,
247 ZPOOL_CONFIG_VDEV_ASYNC_AGG_R_HISTO
,
248 ZPOOL_CONFIG_VDEV_ASYNC_IND_W_HISTO
,
249 ZPOOL_CONFIG_VDEV_ASYNC_AGG_W_HISTO
,
250 ZPOOL_CONFIG_VDEV_IND_SCRUB_HISTO
,
251 ZPOOL_CONFIG_VDEV_AGG_SCRUB_HISTO
,
252 ZPOOL_CONFIG_VDEV_IND_TRIM_HISTO
,
253 ZPOOL_CONFIG_VDEV_AGG_TRIM_HISTO
,
259 * Given a cb->cb_flags with a histogram bit set, return the iostat_type.
260 * Right now, only one histo bit is ever set at one time, so we can
261 * just do a highbit64(a)
263 #define IOS_HISTO_IDX(a) (highbit64(a & IOS_ANYHISTO_M) - 1)
265 typedef struct zpool_command
{
267 int (*func
)(int, char **);
272 * Master command table. Each ZFS command has a name, associated function, and
273 * usage message. The usage messages need to be internationalized, so we have
274 * to have a function to return the usage message based on a command index.
276 * These commands are organized according to how they are displayed in the usage
277 * message. An empty command (one with a NULL name) indicates an empty line in
278 * the generic usage message.
280 static zpool_command_t command_table
[] = {
281 { "version", zpool_do_version
, HELP_VERSION
},
283 { "create", zpool_do_create
, HELP_CREATE
},
284 { "destroy", zpool_do_destroy
, HELP_DESTROY
},
286 { "add", zpool_do_add
, HELP_ADD
},
287 { "remove", zpool_do_remove
, HELP_REMOVE
},
289 { "labelclear", zpool_do_labelclear
, HELP_LABELCLEAR
},
291 { "checkpoint", zpool_do_checkpoint
, HELP_CHECKPOINT
},
293 { "list", zpool_do_list
, HELP_LIST
},
294 { "iostat", zpool_do_iostat
, HELP_IOSTAT
},
295 { "status", zpool_do_status
, HELP_STATUS
},
297 { "online", zpool_do_online
, HELP_ONLINE
},
298 { "offline", zpool_do_offline
, HELP_OFFLINE
},
299 { "clear", zpool_do_clear
, HELP_CLEAR
},
300 { "reopen", zpool_do_reopen
, HELP_REOPEN
},
302 { "attach", zpool_do_attach
, HELP_ATTACH
},
303 { "detach", zpool_do_detach
, HELP_DETACH
},
304 { "replace", zpool_do_replace
, HELP_REPLACE
},
305 { "split", zpool_do_split
, HELP_SPLIT
},
307 { "initialize", zpool_do_initialize
, HELP_INITIALIZE
},
308 { "resilver", zpool_do_resilver
, HELP_RESILVER
},
309 { "scrub", zpool_do_scrub
, HELP_SCRUB
},
310 { "trim", zpool_do_trim
, HELP_TRIM
},
312 { "import", zpool_do_import
, HELP_IMPORT
},
313 { "export", zpool_do_export
, HELP_EXPORT
},
314 { "upgrade", zpool_do_upgrade
, HELP_UPGRADE
},
315 { "reguid", zpool_do_reguid
, HELP_REGUID
},
317 { "history", zpool_do_history
, HELP_HISTORY
},
318 { "events", zpool_do_events
, HELP_EVENTS
},
320 { "get", zpool_do_get
, HELP_GET
},
321 { "set", zpool_do_set
, HELP_SET
},
322 { "sync", zpool_do_sync
, HELP_SYNC
},
324 { "wait", zpool_do_wait
, HELP_WAIT
},
327 #define NCOMMAND (ARRAY_SIZE(command_table))
329 #define VDEV_ALLOC_CLASS_LOGS "logs"
331 static zpool_command_t
*current_command
;
332 static char history_str
[HIS_MAX_RECORD_LEN
];
333 static boolean_t log_history
= B_TRUE
;
334 static uint_t timestamp_fmt
= NODATE
;
337 get_usage(zpool_help_t idx
)
341 return (gettext("\tadd [-fgLnP] [-o property=value] "
342 "<pool> <vdev> ...\n"));
344 return (gettext("\tattach [-fsw] [-o property=value] "
345 "<pool> <device> <new-device>\n"));
347 return (gettext("\tclear [-nF] <pool> [device]\n"));
349 return (gettext("\tcreate [-fnd] [-o property=value] ... \n"
350 "\t [-O file-system-property=value] ... \n"
351 "\t [-m mountpoint] [-R root] <pool> <vdev> ...\n"));
352 case HELP_CHECKPOINT
:
353 return (gettext("\tcheckpoint [-d [-w]] <pool> ...\n"));
355 return (gettext("\tdestroy [-f] <pool>\n"));
357 return (gettext("\tdetach <pool> <device>\n"));
359 return (gettext("\texport [-af] <pool> ...\n"));
361 return (gettext("\thistory [-il] [<pool>] ...\n"));
363 return (gettext("\timport [-d dir] [-D]\n"
364 "\timport [-o mntopts] [-o property=value] ... \n"
365 "\t [-d dir | -c cachefile] [-D] [-l] [-f] [-m] [-N] "
366 "[-R root] [-F [-n]] -a\n"
367 "\timport [-o mntopts] [-o property=value] ... \n"
368 "\t [-d dir | -c cachefile] [-D] [-l] [-f] [-m] [-N] "
369 "[-R root] [-F [-n]]\n"
370 "\t [--rewind-to-checkpoint] <pool | id> [newpool]\n"));
372 return (gettext("\tiostat [[[-c [script1,script2,...]"
373 "[-lq]]|[-rw]] [-T d | u] [-ghHLpPvy]\n"
374 "\t [[pool ...]|[pool vdev ...]|[vdev ...]]"
375 " [[-n] interval [count]]\n"));
376 case HELP_LABELCLEAR
:
377 return (gettext("\tlabelclear [-f] <vdev>\n"));
379 return (gettext("\tlist [-gHLpPv] [-o property[,...]] "
380 "[-T d|u] [pool] ... \n"
381 "\t [interval [count]]\n"));
383 return (gettext("\toffline [-f] [-t] <pool> <device> ...\n"));
385 return (gettext("\tonline [-e] <pool> <device> ...\n"));
387 return (gettext("\treplace [-fsw] [-o property=value] "
388 "<pool> <device> [new-device]\n"));
390 return (gettext("\tremove [-npsw] <pool> <device> ...\n"));
392 return (gettext("\treopen [-n] <pool>\n"));
393 case HELP_INITIALIZE
:
394 return (gettext("\tinitialize [-c | -s] [-w] <pool> "
395 "[<device> ...]\n"));
397 return (gettext("\tscrub [-s | -p] [-w] <pool> ...\n"));
399 return (gettext("\tresilver <pool> ...\n"));
401 return (gettext("\ttrim [-dw] [-r <rate>] [-c | -s] <pool> "
402 "[<device> ...]\n"));
404 return (gettext("\tstatus [-c [script1,script2,...]] "
405 "[-igLpPstvxD] [-T d|u] [pool] ... \n"
406 "\t [interval [count]]\n"));
408 return (gettext("\tupgrade\n"
410 "\tupgrade [-V version] <-a | pool ...>\n"));
412 return (gettext("\tevents [-vHf [pool] | -c]\n"));
414 return (gettext("\tget [-Hp] [-o \"all\" | field[,...]] "
415 "<\"all\" | property[,...]> <pool> ...\n"));
417 return (gettext("\tset <property=value> <pool> \n"));
419 return (gettext("\tsplit [-gLnPl] [-R altroot] [-o mntopts]\n"
420 "\t [-o property=value] <pool> <newpool> "
421 "[<device> ...]\n"));
423 return (gettext("\treguid <pool>\n"));
425 return (gettext("\tsync [pool] ...\n"));
427 return (gettext("\tversion\n"));
429 return (gettext("\twait [-Hp] [-T d|u] [-t <activity>[,...]] "
430 "<pool> [interval]\n"));
438 zpool_collect_leaves(zpool_handle_t
*zhp
, nvlist_t
*nvroot
, nvlist_t
*res
)
444 (void) nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_CHILDREN
,
448 char *path
= zpool_vdev_name(g_zfs
, zhp
, nvroot
,
451 if (strcmp(path
, VDEV_TYPE_INDIRECT
) != 0 &&
452 strcmp(path
, VDEV_TYPE_HOLE
) != 0)
453 fnvlist_add_boolean(res
, path
);
459 for (i
= 0; i
< children
; i
++) {
460 zpool_collect_leaves(zhp
, child
[i
], res
);
465 * Callback routine that will print out a pool property value.
468 print_prop_cb(int prop
, void *cb
)
472 (void) fprintf(fp
, "\t%-19s ", zpool_prop_to_name(prop
));
474 if (zpool_prop_readonly(prop
))
475 (void) fprintf(fp
, " NO ");
477 (void) fprintf(fp
, " YES ");
479 if (zpool_prop_values(prop
) == NULL
)
480 (void) fprintf(fp
, "-\n");
482 (void) fprintf(fp
, "%s\n", zpool_prop_values(prop
));
488 * Display usage message. If we're inside a command, display only the usage for
489 * that command. Otherwise, iterate over the entire command table and display
490 * a complete usage message.
493 usage(boolean_t requested
)
495 FILE *fp
= requested
? stdout
: stderr
;
497 if (current_command
== NULL
) {
500 (void) fprintf(fp
, gettext("usage: zpool command args ...\n"));
502 gettext("where 'command' is one of the following:\n\n"));
504 for (i
= 0; i
< NCOMMAND
; i
++) {
505 if (command_table
[i
].name
== NULL
)
506 (void) fprintf(fp
, "\n");
508 (void) fprintf(fp
, "%s",
509 get_usage(command_table
[i
].usage
));
512 (void) fprintf(fp
, gettext("usage:\n"));
513 (void) fprintf(fp
, "%s", get_usage(current_command
->usage
));
516 if (current_command
!= NULL
&&
517 ((strcmp(current_command
->name
, "set") == 0) ||
518 (strcmp(current_command
->name
, "get") == 0) ||
519 (strcmp(current_command
->name
, "list") == 0))) {
522 gettext("\nthe following properties are supported:\n"));
524 (void) fprintf(fp
, "\n\t%-19s %s %s\n\n",
525 "PROPERTY", "EDIT", "VALUES");
527 /* Iterate over all properties */
528 (void) zprop_iter(print_prop_cb
, fp
, B_FALSE
, B_TRUE
,
531 (void) fprintf(fp
, "\t%-19s ", "feature@...");
532 (void) fprintf(fp
, "YES disabled | enabled | active\n");
534 (void) fprintf(fp
, gettext("\nThe feature@ properties must be "
535 "appended with a feature name.\nSee zpool-features(5).\n"));
539 * See comments at end of main().
541 if (getenv("ZFS_ABORT") != NULL
) {
542 (void) printf("dumping core by request\n");
546 exit(requested
? 0 : 2);
550 * zpool initialize [-c | -s] [-w] <pool> [<vdev> ...]
551 * Initialize all unused blocks in the specified vdevs, or all vdevs in the pool
554 * -c Cancel. Ends active initializing.
555 * -s Suspend. Initializing can then be restarted with no flags.
556 * -w Wait. Blocks until initializing has completed.
559 zpool_do_initialize(int argc
, char **argv
)
566 boolean_t wait
= B_FALSE
;
568 struct option long_options
[] = {
569 {"cancel", no_argument
, NULL
, 'c'},
570 {"suspend", no_argument
, NULL
, 's'},
571 {"wait", no_argument
, NULL
, 'w'},
575 pool_initialize_func_t cmd_type
= POOL_INITIALIZE_START
;
576 while ((c
= getopt_long(argc
, argv
, "csw", long_options
, NULL
)) != -1) {
579 if (cmd_type
!= POOL_INITIALIZE_START
&&
580 cmd_type
!= POOL_INITIALIZE_CANCEL
) {
581 (void) fprintf(stderr
, gettext("-c cannot be "
582 "combined with other options\n"));
585 cmd_type
= POOL_INITIALIZE_CANCEL
;
588 if (cmd_type
!= POOL_INITIALIZE_START
&&
589 cmd_type
!= POOL_INITIALIZE_SUSPEND
) {
590 (void) fprintf(stderr
, gettext("-s cannot be "
591 "combined with other options\n"));
594 cmd_type
= POOL_INITIALIZE_SUSPEND
;
601 (void) fprintf(stderr
,
602 gettext("invalid option '%c'\n"), optopt
);
604 (void) fprintf(stderr
,
605 gettext("invalid option '%s'\n"),
616 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
621 if (wait
&& (cmd_type
!= POOL_INITIALIZE_START
)) {
622 (void) fprintf(stderr
, gettext("-w cannot be used with -c or "
628 zhp
= zpool_open(g_zfs
, poolname
);
632 vdevs
= fnvlist_alloc();
634 /* no individual leaf vdevs specified, so add them all */
635 nvlist_t
*config
= zpool_get_config(zhp
, NULL
);
636 nvlist_t
*nvroot
= fnvlist_lookup_nvlist(config
,
637 ZPOOL_CONFIG_VDEV_TREE
);
638 zpool_collect_leaves(zhp
, nvroot
, vdevs
);
640 for (int i
= 1; i
< argc
; i
++) {
641 fnvlist_add_boolean(vdevs
, argv
[i
]);
646 err
= zpool_initialize_wait(zhp
, cmd_type
, vdevs
);
648 err
= zpool_initialize(zhp
, cmd_type
, vdevs
);
657 * print a pool vdev config for dry runs
660 print_vdev_tree(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
, int indent
,
661 const char *match
, int name_flags
)
666 boolean_t printed
= B_FALSE
;
668 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
669 &child
, &children
) != 0) {
671 (void) printf("\t%*s%s\n", indent
, "", name
);
675 for (c
= 0; c
< children
; c
++) {
676 uint64_t is_log
= B_FALSE
, is_hole
= B_FALSE
;
679 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_HOLE
,
682 if (is_hole
== B_TRUE
) {
686 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
689 class = VDEV_ALLOC_BIAS_LOG
;
690 (void) nvlist_lookup_string(child
[c
],
691 ZPOOL_CONFIG_ALLOCATION_BIAS
, &class);
692 if (strcmp(match
, class) != 0)
695 if (!printed
&& name
!= NULL
) {
696 (void) printf("\t%*s%s\n", indent
, "", name
);
699 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], name_flags
);
700 print_vdev_tree(zhp
, vname
, child
[c
], indent
+ 2, "",
707 * Print the list of l2cache devices for dry runs.
710 print_cache_list(nvlist_t
*nv
, int indent
)
715 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
716 &child
, &children
) == 0 && children
> 0) {
717 (void) printf("\t%*s%s\n", indent
, "", "cache");
721 for (c
= 0; c
< children
; c
++) {
724 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
], 0);
725 (void) printf("\t%*s%s\n", indent
+ 2, "", vname
);
731 * Print the list of spares for dry runs.
734 print_spare_list(nvlist_t
*nv
, int indent
)
739 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
740 &child
, &children
) == 0 && children
> 0) {
741 (void) printf("\t%*s%s\n", indent
, "", "spares");
745 for (c
= 0; c
< children
; c
++) {
748 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
], 0);
749 (void) printf("\t%*s%s\n", indent
+ 2, "", vname
);
755 prop_list_contains_feature(nvlist_t
*proplist
)
758 for (nvp
= nvlist_next_nvpair(proplist
, NULL
); NULL
!= nvp
;
759 nvp
= nvlist_next_nvpair(proplist
, nvp
)) {
760 if (zpool_prop_feature(nvpair_name(nvp
)))
767 * Add a property pair (name, string-value) into a property nvlist.
770 add_prop_list(const char *propname
, char *propval
, nvlist_t
**props
,
773 zpool_prop_t prop
= ZPOOL_PROP_INVAL
;
778 if (*props
== NULL
&&
779 nvlist_alloc(props
, NV_UNIQUE_NAME
, 0) != 0) {
780 (void) fprintf(stderr
,
781 gettext("internal error: out of memory\n"));
788 const char *vname
= zpool_prop_to_name(ZPOOL_PROP_VERSION
);
790 zpool_prop_to_name(ZPOOL_PROP_COMPATIBILITY
);
792 if ((prop
= zpool_name_to_prop(propname
)) == ZPOOL_PROP_INVAL
&&
793 !zpool_prop_feature(propname
)) {
794 (void) fprintf(stderr
, gettext("property '%s' is "
795 "not a valid pool property\n"), propname
);
800 * feature@ properties and version should not be specified
803 if ((prop
== ZPOOL_PROP_INVAL
&& zpool_prop_feature(propname
) &&
804 nvlist_exists(proplist
, vname
)) ||
805 (prop
== ZPOOL_PROP_VERSION
&&
806 prop_list_contains_feature(proplist
))) {
807 (void) fprintf(stderr
, gettext("'feature@' and "
808 "'version' properties cannot be specified "
814 * compatibility property and version should not be specified
817 if ((prop
== ZPOOL_PROP_COMPATIBILITY
&&
818 nvlist_exists(proplist
, vname
)) ||
819 (prop
== ZPOOL_PROP_VERSION
&&
820 nvlist_exists(proplist
, fname
))) {
821 (void) fprintf(stderr
, gettext("'compatibility' and "
822 "'version' properties cannot be specified "
827 if (zpool_prop_feature(propname
))
830 normnm
= zpool_prop_to_name(prop
);
832 zfs_prop_t fsprop
= zfs_name_to_prop(propname
);
834 if (zfs_prop_valid_for_type(fsprop
, ZFS_TYPE_FILESYSTEM
,
836 normnm
= zfs_prop_to_name(fsprop
);
837 } else if (zfs_prop_user(propname
) ||
838 zfs_prop_userquota(propname
)) {
841 (void) fprintf(stderr
, gettext("property '%s' is "
842 "not a valid filesystem property\n"), propname
);
847 if (nvlist_lookup_string(proplist
, normnm
, &strval
) == 0 &&
848 prop
!= ZPOOL_PROP_CACHEFILE
) {
849 (void) fprintf(stderr
, gettext("property '%s' "
850 "specified multiple times\n"), propname
);
854 if (nvlist_add_string(proplist
, normnm
, propval
) != 0) {
855 (void) fprintf(stderr
, gettext("internal "
856 "error: out of memory\n"));
864 * Set a default property pair (name, string-value) in a property nvlist
867 add_prop_list_default(const char *propname
, char *propval
, nvlist_t
**props
,
872 if (nvlist_lookup_string(*props
, propname
, &pval
) == 0)
875 return (add_prop_list(propname
, propval
, props
, B_TRUE
));
879 * zpool add [-fgLnP] [-o property=value] <pool> <vdev> ...
881 * -f Force addition of devices, even if they appear in use
882 * -g Display guid for individual vdev name.
883 * -L Follow links when resolving vdev path name.
884 * -n Do not add the devices, but display the resulting layout if
885 * they were to be added.
886 * -o Set property=value.
887 * -P Display full path for vdev name.
889 * Adds the given vdevs to 'pool'. As with create, the bulk of this work is
890 * handled by make_root_vdev(), which constructs the nvlist needed to pass to
894 zpool_do_add(int argc
, char **argv
)
896 boolean_t force
= B_FALSE
;
897 boolean_t dryrun
= B_FALSE
;
905 nvlist_t
*props
= NULL
;
909 while ((c
= getopt(argc
, argv
, "fgLno:P")) != -1) {
915 name_flags
|= VDEV_NAME_GUID
;
918 name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
924 if ((propval
= strchr(optarg
, '=')) == NULL
) {
925 (void) fprintf(stderr
, gettext("missing "
926 "'=' for -o option\n"));
932 if ((strcmp(optarg
, ZPOOL_CONFIG_ASHIFT
) != 0) ||
933 (add_prop_list(optarg
, propval
, &props
, B_TRUE
)))
937 name_flags
|= VDEV_NAME_PATH
;
940 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
949 /* get pool name and check number of arguments */
951 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
955 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
964 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
967 if ((config
= zpool_get_config(zhp
, NULL
)) == NULL
) {
968 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
974 /* unless manually specified use "ashift" pool property (if set) */
975 if (!nvlist_exists(props
, ZPOOL_CONFIG_ASHIFT
)) {
978 char strval
[ZPOOL_MAXPROPLEN
];
980 intval
= zpool_get_prop_int(zhp
, ZPOOL_PROP_ASHIFT
, &src
);
981 if (src
!= ZPROP_SRC_DEFAULT
) {
982 (void) sprintf(strval
, "%" PRId32
, intval
);
983 verify(add_prop_list(ZPOOL_CONFIG_ASHIFT
, strval
,
984 &props
, B_TRUE
) == 0);
988 /* pass off to make_root_vdev for processing */
989 nvroot
= make_root_vdev(zhp
, props
, force
, !force
, B_FALSE
, dryrun
,
991 if (nvroot
== NULL
) {
997 nvlist_t
*poolnvroot
;
998 nvlist_t
**l2child
, **sparechild
;
999 uint_t l2children
, sparechildren
, c
;
1001 boolean_t hadcache
= B_FALSE
, hadspare
= B_FALSE
;
1003 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
1006 (void) printf(gettext("would update '%s' to the following "
1007 "configuration:\n\n"), zpool_get_name(zhp
));
1009 /* print original main pool and new tree */
1010 print_vdev_tree(zhp
, poolname
, poolnvroot
, 0, "",
1011 name_flags
| VDEV_NAME_TYPE_ID
);
1012 print_vdev_tree(zhp
, NULL
, nvroot
, 0, "", name_flags
);
1014 /* print other classes: 'dedup', 'special', and 'log' */
1015 if (zfs_special_devs(poolnvroot
, VDEV_ALLOC_BIAS_DEDUP
)) {
1016 print_vdev_tree(zhp
, "dedup", poolnvroot
, 0,
1017 VDEV_ALLOC_BIAS_DEDUP
, name_flags
);
1018 print_vdev_tree(zhp
, NULL
, nvroot
, 0,
1019 VDEV_ALLOC_BIAS_DEDUP
, name_flags
);
1020 } else if (zfs_special_devs(nvroot
, VDEV_ALLOC_BIAS_DEDUP
)) {
1021 print_vdev_tree(zhp
, "dedup", nvroot
, 0,
1022 VDEV_ALLOC_BIAS_DEDUP
, name_flags
);
1025 if (zfs_special_devs(poolnvroot
, VDEV_ALLOC_BIAS_SPECIAL
)) {
1026 print_vdev_tree(zhp
, "special", poolnvroot
, 0,
1027 VDEV_ALLOC_BIAS_SPECIAL
, name_flags
);
1028 print_vdev_tree(zhp
, NULL
, nvroot
, 0,
1029 VDEV_ALLOC_BIAS_SPECIAL
, name_flags
);
1030 } else if (zfs_special_devs(nvroot
, VDEV_ALLOC_BIAS_SPECIAL
)) {
1031 print_vdev_tree(zhp
, "special", nvroot
, 0,
1032 VDEV_ALLOC_BIAS_SPECIAL
, name_flags
);
1035 if (num_logs(poolnvroot
) > 0) {
1036 print_vdev_tree(zhp
, "logs", poolnvroot
, 0,
1037 VDEV_ALLOC_BIAS_LOG
, name_flags
);
1038 print_vdev_tree(zhp
, NULL
, nvroot
, 0,
1039 VDEV_ALLOC_BIAS_LOG
, name_flags
);
1040 } else if (num_logs(nvroot
) > 0) {
1041 print_vdev_tree(zhp
, "logs", nvroot
, 0,
1042 VDEV_ALLOC_BIAS_LOG
, name_flags
);
1045 /* Do the same for the caches */
1046 if (nvlist_lookup_nvlist_array(poolnvroot
, ZPOOL_CONFIG_L2CACHE
,
1047 &l2child
, &l2children
) == 0 && l2children
) {
1049 (void) printf(gettext("\tcache\n"));
1050 for (c
= 0; c
< l2children
; c
++) {
1051 vname
= zpool_vdev_name(g_zfs
, NULL
,
1052 l2child
[c
], name_flags
);
1053 (void) printf("\t %s\n", vname
);
1057 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_L2CACHE
,
1058 &l2child
, &l2children
) == 0 && l2children
) {
1060 (void) printf(gettext("\tcache\n"));
1061 for (c
= 0; c
< l2children
; c
++) {
1062 vname
= zpool_vdev_name(g_zfs
, NULL
,
1063 l2child
[c
], name_flags
);
1064 (void) printf("\t %s\n", vname
);
1068 /* And finaly the spares */
1069 if (nvlist_lookup_nvlist_array(poolnvroot
, ZPOOL_CONFIG_SPARES
,
1070 &sparechild
, &sparechildren
) == 0 && sparechildren
> 0) {
1072 (void) printf(gettext("\tspares\n"));
1073 for (c
= 0; c
< sparechildren
; c
++) {
1074 vname
= zpool_vdev_name(g_zfs
, NULL
,
1075 sparechild
[c
], name_flags
);
1076 (void) printf("\t %s\n", vname
);
1080 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_SPARES
,
1081 &sparechild
, &sparechildren
) == 0 && sparechildren
> 0) {
1083 (void) printf(gettext("\tspares\n"));
1084 for (c
= 0; c
< sparechildren
; c
++) {
1085 vname
= zpool_vdev_name(g_zfs
, NULL
,
1086 sparechild
[c
], name_flags
);
1087 (void) printf("\t %s\n", vname
);
1094 ret
= (zpool_add(zhp
, nvroot
) != 0);
1098 nvlist_free(nvroot
);
1105 * zpool remove [-npsw] <pool> <vdev> ...
1107 * Removes the given vdev from the pool.
1110 zpool_do_remove(int argc
, char **argv
)
1114 zpool_handle_t
*zhp
= NULL
;
1115 boolean_t stop
= B_FALSE
;
1117 boolean_t noop
= B_FALSE
;
1118 boolean_t parsable
= B_FALSE
;
1119 boolean_t wait
= B_FALSE
;
1122 while ((c
= getopt(argc
, argv
, "npsw")) != -1) {
1137 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1146 /* get pool name and check number of arguments */
1148 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
1154 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
1158 (void) fprintf(stderr
, gettext("stop request ignored\n"));
1164 (void) fprintf(stderr
, gettext("too many arguments\n"));
1167 if (zpool_vdev_remove_cancel(zhp
) != 0)
1170 (void) fprintf(stderr
, gettext("invalid option "
1171 "combination: -w cannot be used with -s\n"));
1176 (void) fprintf(stderr
, gettext("missing device\n"));
1180 for (i
= 1; i
< argc
; i
++) {
1184 if (zpool_vdev_indirect_size(zhp
, argv
[i
],
1190 (void) printf("%s %llu\n",
1191 argv
[i
], (unsigned long long)size
);
1194 zfs_nicenum(size
, valstr
,
1196 (void) printf("Memory that will be "
1197 "used after removing %s: %s\n",
1201 if (zpool_vdev_remove(zhp
, argv
[i
]) != 0)
1206 if (ret
== 0 && wait
)
1207 ret
= zpool_wait(zhp
, ZPOOL_WAIT_REMOVE
);
1215 * zpool labelclear [-f] <vdev>
1217 * -f Force clearing the label for the vdevs which are members of
1218 * the exported or foreign pools.
1220 * Verifies that the vdev is not active and zeros out the label information
1224 zpool_do_labelclear(int argc
, char **argv
)
1226 char vdev
[MAXPATHLEN
];
1229 int c
, fd
= -1, ret
= 0;
1232 boolean_t inuse
= B_FALSE
;
1233 boolean_t force
= B_FALSE
;
1236 while ((c
= getopt(argc
, argv
, "f")) != -1) {
1242 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1253 (void) fprintf(stderr
, gettext("missing vdev name\n"));
1257 (void) fprintf(stderr
, gettext("too many arguments\n"));
1262 * Check if we were given absolute path and use it as is.
1263 * Otherwise if the provided vdev name doesn't point to a file,
1264 * try prepending expected disk paths and partition numbers.
1266 (void) strlcpy(vdev
, argv
[0], sizeof (vdev
));
1267 if (vdev
[0] != '/' && stat(vdev
, &st
) != 0) {
1270 error
= zfs_resolve_shortname(argv
[0], vdev
, MAXPATHLEN
);
1271 if (error
== 0 && zfs_dev_is_whole_disk(vdev
)) {
1272 if (zfs_append_partition(vdev
, MAXPATHLEN
) == -1)
1276 if (error
|| (stat(vdev
, &st
) != 0)) {
1277 (void) fprintf(stderr
, gettext(
1278 "failed to find device %s, try specifying absolute "
1279 "path instead\n"), argv
[0]);
1284 if ((fd
= open(vdev
, O_RDWR
)) < 0) {
1285 (void) fprintf(stderr
, gettext("failed to open %s: %s\n"),
1286 vdev
, strerror(errno
));
1291 * Flush all dirty pages for the block device. This should not be
1292 * fatal when the device does not support BLKFLSBUF as would be the
1293 * case for a file vdev.
1295 if ((zfs_dev_flush(fd
) != 0) && (errno
!= ENOTTY
))
1296 (void) fprintf(stderr
, gettext("failed to invalidate "
1297 "cache for %s: %s\n"), vdev
, strerror(errno
));
1299 if (zpool_read_label(fd
, &config
, NULL
) != 0) {
1300 (void) fprintf(stderr
,
1301 gettext("failed to read label from %s\n"), vdev
);
1305 nvlist_free(config
);
1307 ret
= zpool_in_use(g_zfs
, fd
, &state
, &name
, &inuse
);
1309 (void) fprintf(stderr
,
1310 gettext("failed to check state for %s\n"), vdev
);
1320 case POOL_STATE_ACTIVE
:
1321 case POOL_STATE_SPARE
:
1322 case POOL_STATE_L2CACHE
:
1323 (void) fprintf(stderr
, gettext(
1324 "%s is a member (%s) of pool \"%s\"\n"),
1325 vdev
, zpool_pool_state_to_name(state
), name
);
1329 case POOL_STATE_EXPORTED
:
1332 (void) fprintf(stderr
, gettext(
1333 "use '-f' to override the following error:\n"
1334 "%s is a member of exported pool \"%s\"\n"),
1339 case POOL_STATE_POTENTIALLY_ACTIVE
:
1342 (void) fprintf(stderr
, gettext(
1343 "use '-f' to override the following error:\n"
1344 "%s is a member of potentially active pool \"%s\"\n"),
1349 case POOL_STATE_DESTROYED
:
1350 /* inuse should never be set for a destroyed pool */
1356 ret
= zpool_clear_label(fd
);
1358 (void) fprintf(stderr
,
1359 gettext("failed to clear label for %s\n"), vdev
);
1370 * zpool create [-fnd] [-o property=value] ...
1371 * [-O file-system-property=value] ...
1372 * [-R root] [-m mountpoint] <pool> <dev> ...
1374 * -f Force creation, even if devices appear in use
1375 * -n Do not create the pool, but display the resulting layout if it
1376 * were to be created.
1377 * -R Create a pool under an alternate root
1378 * -m Set default mountpoint for the root dataset. By default it's
1380 * -o Set property=value.
1381 * -o Set feature@feature=enabled|disabled.
1382 * -d Don't automatically enable all supported pool features
1383 * (individual features can be enabled with -o).
1384 * -O Set fsproperty=value in the pool's root file system
1386 * Creates the named pool according to the given vdev specification. The
1387 * bulk of the vdev processing is done in make_root_vdev() in zpool_vdev.c.
1388 * Once we get the nvlist back from make_root_vdev(), we either print out the
1389 * contents (if '-n' was specified), or pass it to libzfs to do the creation.
1392 zpool_do_create(int argc
, char **argv
)
1394 boolean_t force
= B_FALSE
;
1395 boolean_t dryrun
= B_FALSE
;
1396 boolean_t enable_pool_features
= B_TRUE
;
1399 nvlist_t
*nvroot
= NULL
;
1403 char *altroot
= NULL
;
1404 char *compat
= NULL
;
1405 char *mountpoint
= NULL
;
1406 nvlist_t
*fsprops
= NULL
;
1407 nvlist_t
*props
= NULL
;
1411 while ((c
= getopt(argc
, argv
, ":fndR:m:o:O:t:")) != -1) {
1420 enable_pool_features
= B_FALSE
;
1424 if (add_prop_list(zpool_prop_to_name(
1425 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
1427 if (add_prop_list_default(zpool_prop_to_name(
1428 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
1432 /* Equivalent to -O mountpoint=optarg */
1433 mountpoint
= optarg
;
1436 if ((propval
= strchr(optarg
, '=')) == NULL
) {
1437 (void) fprintf(stderr
, gettext("missing "
1438 "'=' for -o option\n"));
1444 if (add_prop_list(optarg
, propval
, &props
, B_TRUE
))
1448 * If the user is creating a pool that doesn't support
1449 * feature flags, don't enable any features.
1451 if (zpool_name_to_prop(optarg
) == ZPOOL_PROP_VERSION
) {
1455 ver
= strtoull(propval
, &end
, 10);
1457 ver
< SPA_VERSION_FEATURES
) {
1458 enable_pool_features
= B_FALSE
;
1461 if (zpool_name_to_prop(optarg
) == ZPOOL_PROP_ALTROOT
)
1463 if (zpool_name_to_prop(optarg
) ==
1464 ZPOOL_PROP_COMPATIBILITY
)
1468 if ((propval
= strchr(optarg
, '=')) == NULL
) {
1469 (void) fprintf(stderr
, gettext("missing "
1470 "'=' for -O option\n"));
1477 * Mountpoints are checked and then added later.
1478 * Uniquely among properties, they can be specified
1479 * more than once, to avoid conflict with -m.
1481 if (0 == strcmp(optarg
,
1482 zfs_prop_to_name(ZFS_PROP_MOUNTPOINT
))) {
1483 mountpoint
= propval
;
1484 } else if (add_prop_list(optarg
, propval
, &fsprops
,
1491 * Sanity check temporary pool name.
1493 if (strchr(optarg
, '/') != NULL
) {
1494 (void) fprintf(stderr
, gettext("cannot create "
1495 "'%s': invalid character '/' in temporary "
1497 (void) fprintf(stderr
, gettext("use 'zfs "
1498 "create' to create a dataset\n"));
1502 if (add_prop_list(zpool_prop_to_name(
1503 ZPOOL_PROP_TNAME
), optarg
, &props
, B_TRUE
))
1505 if (add_prop_list_default(zpool_prop_to_name(
1506 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
1511 (void) fprintf(stderr
, gettext("missing argument for "
1512 "'%c' option\n"), optopt
);
1515 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1524 /* get pool name and check number of arguments */
1526 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
1530 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
1537 * As a special case, check for use of '/' in the name, and direct the
1538 * user to use 'zfs create' instead.
1540 if (strchr(poolname
, '/') != NULL
) {
1541 (void) fprintf(stderr
, gettext("cannot create '%s': invalid "
1542 "character '/' in pool name\n"), poolname
);
1543 (void) fprintf(stderr
, gettext("use 'zfs create' to "
1544 "create a dataset\n"));
1548 /* pass off to make_root_vdev for bulk processing */
1549 nvroot
= make_root_vdev(NULL
, props
, force
, !force
, B_FALSE
, dryrun
,
1550 argc
- 1, argv
+ 1);
1554 /* make_root_vdev() allows 0 toplevel children if there are spares */
1555 if (!zfs_allocatable_devs(nvroot
)) {
1556 (void) fprintf(stderr
, gettext("invalid vdev "
1557 "specification: at least one toplevel vdev must be "
1562 if (altroot
!= NULL
&& altroot
[0] != '/') {
1563 (void) fprintf(stderr
, gettext("invalid alternate root '%s': "
1564 "must be an absolute path\n"), altroot
);
1569 * Check the validity of the mountpoint and direct the user to use the
1570 * '-m' mountpoint option if it looks like its in use.
1572 if (mountpoint
== NULL
||
1573 (strcmp(mountpoint
, ZFS_MOUNTPOINT_LEGACY
) != 0 &&
1574 strcmp(mountpoint
, ZFS_MOUNTPOINT_NONE
) != 0)) {
1575 char buf
[MAXPATHLEN
];
1578 if (mountpoint
&& mountpoint
[0] != '/') {
1579 (void) fprintf(stderr
, gettext("invalid mountpoint "
1580 "'%s': must be an absolute path, 'legacy', or "
1581 "'none'\n"), mountpoint
);
1585 if (mountpoint
== NULL
) {
1586 if (altroot
!= NULL
)
1587 (void) snprintf(buf
, sizeof (buf
), "%s/%s",
1590 (void) snprintf(buf
, sizeof (buf
), "/%s",
1593 if (altroot
!= NULL
)
1594 (void) snprintf(buf
, sizeof (buf
), "%s%s",
1595 altroot
, mountpoint
);
1597 (void) snprintf(buf
, sizeof (buf
), "%s",
1601 if ((dirp
= opendir(buf
)) == NULL
&& errno
!= ENOENT
) {
1602 (void) fprintf(stderr
, gettext("mountpoint '%s' : "
1603 "%s\n"), buf
, strerror(errno
));
1604 (void) fprintf(stderr
, gettext("use '-m' "
1605 "option to provide a different default\n"));
1610 while (count
< 3 && readdir(dirp
) != NULL
)
1612 (void) closedir(dirp
);
1615 (void) fprintf(stderr
, gettext("mountpoint "
1616 "'%s' exists and is not empty\n"), buf
);
1617 (void) fprintf(stderr
, gettext("use '-m' "
1618 "option to provide a "
1619 "different default\n"));
1626 * Now that the mountpoint's validity has been checked, ensure that
1627 * the property is set appropriately prior to creating the pool.
1629 if (mountpoint
!= NULL
) {
1630 ret
= add_prop_list(zfs_prop_to_name(ZFS_PROP_MOUNTPOINT
),
1631 mountpoint
, &fsprops
, B_FALSE
);
1639 * For a dry run invocation, print out a basic message and run
1640 * through all the vdevs in the list and print out in an
1641 * appropriate hierarchy.
1643 (void) printf(gettext("would create '%s' with the "
1644 "following layout:\n\n"), poolname
);
1646 print_vdev_tree(NULL
, poolname
, nvroot
, 0, "", 0);
1647 print_vdev_tree(NULL
, "dedup", nvroot
, 0,
1648 VDEV_ALLOC_BIAS_DEDUP
, 0);
1649 print_vdev_tree(NULL
, "special", nvroot
, 0,
1650 VDEV_ALLOC_BIAS_SPECIAL
, 0);
1651 print_vdev_tree(NULL
, "logs", nvroot
, 0,
1652 VDEV_ALLOC_BIAS_LOG
, 0);
1653 print_cache_list(nvroot
, 0);
1654 print_spare_list(nvroot
, 0);
1659 * Load in feature set.
1660 * Note: if compatibility property not given, we'll have
1661 * NULL, which means 'all features'.
1663 boolean_t requested_features
[SPA_FEATURES
];
1664 if (zpool_do_load_compat(compat
, requested_features
) !=
1665 ZPOOL_COMPATIBILITY_OK
)
1669 * props contains list of features to enable.
1671 * - remove it if feature@name=disabled
1672 * - leave it there if feature@name=enabled
1674 * - enable_pool_features (ie: no '-d' or '-o version')
1675 * - it's supported by the kernel module
1676 * - it's in the requested feature set
1678 for (spa_feature_t i
= 0; i
< SPA_FEATURES
; i
++) {
1679 char propname
[MAXPATHLEN
];
1681 zfeature_info_t
*feat
= &spa_feature_table
[i
];
1683 (void) snprintf(propname
, sizeof (propname
),
1684 "feature@%s", feat
->fi_uname
);
1686 if (!nvlist_lookup_string(props
, propname
, &propval
)) {
1687 if (strcmp(propval
, ZFS_FEATURE_DISABLED
) == 0)
1688 (void) nvlist_remove_all(props
,
1691 enable_pool_features
&&
1692 feat
->fi_zfs_mod_supported
&&
1693 requested_features
[i
]) {
1694 ret
= add_prop_list(propname
,
1695 ZFS_FEATURE_ENABLED
, &props
, B_TRUE
);
1702 if (zpool_create(g_zfs
, poolname
,
1703 nvroot
, props
, fsprops
) == 0) {
1704 zfs_handle_t
*pool
= zfs_open(g_zfs
,
1705 tname
? tname
: poolname
, ZFS_TYPE_FILESYSTEM
);
1707 if (zfs_mount(pool
, NULL
, 0) == 0) {
1708 ret
= zfs_shareall(pool
);
1709 zfs_commit_all_shares();
1713 } else if (libzfs_errno(g_zfs
) == EZFS_INVALIDNAME
) {
1714 (void) fprintf(stderr
, gettext("pool name may have "
1720 nvlist_free(nvroot
);
1721 nvlist_free(fsprops
);
1725 nvlist_free(fsprops
);
1732 * zpool destroy <pool>
1734 * -f Forcefully unmount any datasets
1736 * Destroy the given pool. Automatically unmounts any datasets in the pool.
1739 zpool_do_destroy(int argc
, char **argv
)
1741 boolean_t force
= B_FALSE
;
1744 zpool_handle_t
*zhp
;
1748 while ((c
= getopt(argc
, argv
, "f")) != -1) {
1754 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1763 /* check arguments */
1765 (void) fprintf(stderr
, gettext("missing pool argument\n"));
1769 (void) fprintf(stderr
, gettext("too many arguments\n"));
1775 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
) {
1777 * As a special case, check for use of '/' in the name, and
1778 * direct the user to use 'zfs destroy' instead.
1780 if (strchr(pool
, '/') != NULL
)
1781 (void) fprintf(stderr
, gettext("use 'zfs destroy' to "
1782 "destroy a dataset\n"));
1786 if (zpool_disable_datasets(zhp
, force
) != 0) {
1787 (void) fprintf(stderr
, gettext("could not destroy '%s': "
1788 "could not unmount datasets\n"), zpool_get_name(zhp
));
1793 /* The history must be logged as part of the export */
1794 log_history
= B_FALSE
;
1796 ret
= (zpool_destroy(zhp
, history_str
) != 0);
1803 typedef struct export_cbdata
{
1805 boolean_t hardforce
;
1812 zpool_export_one(zpool_handle_t
*zhp
, void *data
)
1814 export_cbdata_t
*cb
= data
;
1816 if (zpool_disable_datasets(zhp
, cb
->force
) != 0)
1819 /* The history must be logged as part of the export */
1820 log_history
= B_FALSE
;
1822 if (cb
->hardforce
) {
1823 if (zpool_export_force(zhp
, history_str
) != 0)
1825 } else if (zpool_export(zhp
, cb
->force
, history_str
) != 0) {
1833 * zpool export [-f] <pool> ...
1835 * -a Export all pools
1836 * -f Forcefully unmount datasets
1838 * Export the given pools. By default, the command will attempt to cleanly
1839 * unmount any active datasets within the pool. If the '-f' flag is specified,
1840 * then the datasets will be forcefully unmounted.
1843 zpool_do_export(int argc
, char **argv
)
1846 boolean_t do_all
= B_FALSE
;
1847 boolean_t force
= B_FALSE
;
1848 boolean_t hardforce
= B_FALSE
;
1852 while ((c
= getopt(argc
, argv
, "afF")) != -1) {
1864 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1871 cb
.hardforce
= hardforce
;
1877 (void) fprintf(stderr
, gettext("too many arguments\n"));
1881 return (for_each_pool(argc
, argv
, B_TRUE
, NULL
,
1882 B_FALSE
, zpool_export_one
, &cb
));
1885 /* check arguments */
1887 (void) fprintf(stderr
, gettext("missing pool argument\n"));
1891 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
, B_FALSE
, zpool_export_one
,
1898 * Given a vdev configuration, determine the maximum width needed for the device
1902 max_width(zpool_handle_t
*zhp
, nvlist_t
*nv
, int depth
, int max
,
1910 name
= zpool_vdev_name(g_zfs
, zhp
, nv
, name_flags
);
1911 if (strlen(name
) + depth
> max
)
1912 max
= strlen(name
) + depth
;
1916 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
1917 &child
, &children
) == 0) {
1918 for (c
= 0; c
< children
; c
++)
1919 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1920 max
, name_flags
)) > max
)
1924 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
1925 &child
, &children
) == 0) {
1926 for (c
= 0; c
< children
; c
++)
1927 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1928 max
, name_flags
)) > max
)
1932 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1933 &child
, &children
) == 0) {
1934 for (c
= 0; c
< children
; c
++)
1935 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1936 max
, name_flags
)) > max
)
1943 typedef struct spare_cbdata
{
1945 zpool_handle_t
*cb_zhp
;
1949 find_vdev(nvlist_t
*nv
, uint64_t search
)
1955 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
, &guid
) == 0 &&
1959 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1960 &child
, &children
) == 0) {
1961 for (c
= 0; c
< children
; c
++)
1962 if (find_vdev(child
[c
], search
))
1970 find_spare(zpool_handle_t
*zhp
, void *data
)
1972 spare_cbdata_t
*cbp
= data
;
1973 nvlist_t
*config
, *nvroot
;
1975 config
= zpool_get_config(zhp
, NULL
);
1976 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
1979 if (find_vdev(nvroot
, cbp
->cb_guid
)) {
1988 typedef struct status_cbdata
{
1992 boolean_t cb_allpools
;
1993 boolean_t cb_verbose
;
1994 boolean_t cb_literal
;
1995 boolean_t cb_explain
;
1997 boolean_t cb_dedup_stats
;
1998 boolean_t cb_print_status
;
1999 boolean_t cb_print_slow_ios
;
2000 boolean_t cb_print_vdev_init
;
2001 boolean_t cb_print_vdev_trim
;
2002 vdev_cmd_data_list_t
*vcdl
;
2005 /* Return 1 if string is NULL, empty, or whitespace; return 0 otherwise. */
2007 is_blank_str(char *str
)
2009 while (str
!= NULL
&& *str
!= '\0') {
2017 /* Print command output lines for specific vdev in a specific pool */
2019 zpool_print_cmd(vdev_cmd_data_list_t
*vcdl
, const char *pool
, char *path
)
2021 vdev_cmd_data_t
*data
;
2025 for (i
= 0; i
< vcdl
->count
; i
++) {
2026 if ((strcmp(vcdl
->data
[i
].path
, path
) != 0) ||
2027 (strcmp(vcdl
->data
[i
].pool
, pool
) != 0)) {
2028 /* Not the vdev we're looking for */
2032 data
= &vcdl
->data
[i
];
2033 /* Print out all the output values for this vdev */
2034 for (j
= 0; j
< vcdl
->uniq_cols_cnt
; j
++) {
2036 /* Does this vdev have values for this column? */
2037 for (int k
= 0; k
< data
->cols_cnt
; k
++) {
2038 if (strcmp(data
->cols
[k
],
2039 vcdl
->uniq_cols
[j
]) == 0) {
2040 /* yes it does, record the value */
2041 val
= data
->lines
[k
];
2046 * Mark empty values with dashes to make output
2049 if (val
== NULL
|| is_blank_str(val
))
2052 printf("%*s", vcdl
->uniq_cols_width
[j
], val
);
2053 if (j
< vcdl
->uniq_cols_cnt
- 1)
2057 /* Print out any values that aren't in a column at the end */
2058 for (j
= data
->cols_cnt
; j
< data
->lines_cnt
; j
++) {
2059 /* Did we have any columns? If so print a spacer. */
2060 if (vcdl
->uniq_cols_cnt
> 0)
2063 val
= data
->lines
[j
];
2064 printf("%s", val
? val
: "");
2071 * Print vdev initialization status for leaves
2074 print_status_initialize(vdev_stat_t
*vs
, boolean_t verbose
)
2077 if ((vs
->vs_initialize_state
== VDEV_INITIALIZE_ACTIVE
||
2078 vs
->vs_initialize_state
== VDEV_INITIALIZE_SUSPENDED
||
2079 vs
->vs_initialize_state
== VDEV_INITIALIZE_COMPLETE
) &&
2080 !vs
->vs_scan_removing
) {
2083 struct tm zaction_ts
;
2085 time_t t
= vs
->vs_initialize_action_time
;
2086 int initialize_pct
= 100;
2087 if (vs
->vs_initialize_state
!=
2088 VDEV_INITIALIZE_COMPLETE
) {
2089 initialize_pct
= (vs
->vs_initialize_bytes_done
*
2090 100 / (vs
->vs_initialize_bytes_est
+ 1));
2093 (void) localtime_r(&t
, &zaction_ts
);
2094 (void) strftime(tbuf
, sizeof (tbuf
), "%c", &zaction_ts
);
2096 switch (vs
->vs_initialize_state
) {
2097 case VDEV_INITIALIZE_SUSPENDED
:
2098 (void) snprintf(zbuf
, sizeof (zbuf
), ", %s %s",
2099 gettext("suspended, started at"), tbuf
);
2101 case VDEV_INITIALIZE_ACTIVE
:
2102 (void) snprintf(zbuf
, sizeof (zbuf
), ", %s %s",
2103 gettext("started at"), tbuf
);
2105 case VDEV_INITIALIZE_COMPLETE
:
2106 (void) snprintf(zbuf
, sizeof (zbuf
), ", %s %s",
2107 gettext("completed at"), tbuf
);
2111 (void) printf(gettext(" (%d%% initialized%s)"),
2112 initialize_pct
, zbuf
);
2114 (void) printf(gettext(" (uninitialized)"));
2116 } else if (vs
->vs_initialize_state
== VDEV_INITIALIZE_ACTIVE
) {
2117 (void) printf(gettext(" (initializing)"));
2122 * Print vdev TRIM status for leaves
2125 print_status_trim(vdev_stat_t
*vs
, boolean_t verbose
)
2128 if ((vs
->vs_trim_state
== VDEV_TRIM_ACTIVE
||
2129 vs
->vs_trim_state
== VDEV_TRIM_SUSPENDED
||
2130 vs
->vs_trim_state
== VDEV_TRIM_COMPLETE
) &&
2131 !vs
->vs_scan_removing
) {
2134 struct tm zaction_ts
;
2136 time_t t
= vs
->vs_trim_action_time
;
2138 if (vs
->vs_trim_state
!= VDEV_TRIM_COMPLETE
) {
2139 trim_pct
= (vs
->vs_trim_bytes_done
*
2140 100 / (vs
->vs_trim_bytes_est
+ 1));
2143 (void) localtime_r(&t
, &zaction_ts
);
2144 (void) strftime(tbuf
, sizeof (tbuf
), "%c", &zaction_ts
);
2146 switch (vs
->vs_trim_state
) {
2147 case VDEV_TRIM_SUSPENDED
:
2148 (void) snprintf(zbuf
, sizeof (zbuf
), ", %s %s",
2149 gettext("suspended, started at"), tbuf
);
2151 case VDEV_TRIM_ACTIVE
:
2152 (void) snprintf(zbuf
, sizeof (zbuf
), ", %s %s",
2153 gettext("started at"), tbuf
);
2155 case VDEV_TRIM_COMPLETE
:
2156 (void) snprintf(zbuf
, sizeof (zbuf
), ", %s %s",
2157 gettext("completed at"), tbuf
);
2161 (void) printf(gettext(" (%d%% trimmed%s)"),
2163 } else if (vs
->vs_trim_notsup
) {
2164 (void) printf(gettext(" (trim unsupported)"));
2166 (void) printf(gettext(" (untrimmed)"));
2168 } else if (vs
->vs_trim_state
== VDEV_TRIM_ACTIVE
) {
2169 (void) printf(gettext(" (trimming)"));
2174 * Return the color associated with a health string. This includes returning
2175 * NULL for no color change.
2178 health_str_to_color(const char *health
)
2180 if (strcmp(health
, gettext("FAULTED")) == 0 ||
2181 strcmp(health
, gettext("SUSPENDED")) == 0 ||
2182 strcmp(health
, gettext("UNAVAIL")) == 0) {
2186 if (strcmp(health
, gettext("OFFLINE")) == 0 ||
2187 strcmp(health
, gettext("DEGRADED")) == 0 ||
2188 strcmp(health
, gettext("REMOVED")) == 0) {
2189 return (ANSI_YELLOW
);
2196 * Print out configuration state as requested by status_callback.
2199 print_status_config(zpool_handle_t
*zhp
, status_cbdata_t
*cb
, const char *name
,
2200 nvlist_t
*nv
, int depth
, boolean_t isspare
, vdev_rebuild_stat_t
*vrs
)
2202 nvlist_t
**child
, *root
;
2203 uint_t c
, i
, vsc
, children
;
2204 pool_scan_stat_t
*ps
= NULL
;
2206 char rbuf
[6], wbuf
[6], cbuf
[6];
2208 uint64_t notpresent
;
2209 spare_cbdata_t spare_cb
;
2213 char *rcolor
= NULL
, *wcolor
= NULL
, *ccolor
= NULL
;
2215 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
2216 &child
, &children
) != 0)
2219 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
2220 (uint64_t **)&vs
, &vsc
) == 0);
2222 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_TYPE
, &type
) == 0);
2224 if (strcmp(type
, VDEV_TYPE_INDIRECT
) == 0)
2227 state
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
2231 * For hot spares, we use the terms 'INUSE' and 'AVAILABLE' for
2234 if (vs
->vs_aux
== VDEV_AUX_SPARED
)
2235 state
= gettext("INUSE");
2236 else if (vs
->vs_state
== VDEV_STATE_HEALTHY
)
2237 state
= gettext("AVAIL");
2240 printf_color(health_str_to_color(state
),
2241 "\t%*s%-*s %-8s", depth
, "", cb
->cb_namewidth
- depth
,
2245 if (vs
->vs_read_errors
)
2248 if (vs
->vs_write_errors
)
2251 if (vs
->vs_checksum_errors
)
2254 if (cb
->cb_literal
) {
2256 printf_color(rcolor
, "%5llu",
2257 (u_longlong_t
)vs
->vs_read_errors
);
2259 printf_color(wcolor
, "%5llu",
2260 (u_longlong_t
)vs
->vs_write_errors
);
2262 printf_color(ccolor
, "%5llu",
2263 (u_longlong_t
)vs
->vs_checksum_errors
);
2265 zfs_nicenum(vs
->vs_read_errors
, rbuf
, sizeof (rbuf
));
2266 zfs_nicenum(vs
->vs_write_errors
, wbuf
, sizeof (wbuf
));
2267 zfs_nicenum(vs
->vs_checksum_errors
, cbuf
,
2270 printf_color(rcolor
, "%5s", rbuf
);
2272 printf_color(wcolor
, "%5s", wbuf
);
2274 printf_color(ccolor
, "%5s", cbuf
);
2276 if (cb
->cb_print_slow_ios
) {
2277 if (children
== 0) {
2278 /* Only leafs vdevs have slow IOs */
2279 zfs_nicenum(vs
->vs_slow_ios
, rbuf
,
2282 snprintf(rbuf
, sizeof (rbuf
), "-");
2286 printf(" %5llu", (u_longlong_t
)vs
->vs_slow_ios
);
2288 printf(" %5s", rbuf
);
2292 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_NOT_PRESENT
,
2293 ¬present
) == 0) {
2294 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_PATH
, &path
) == 0);
2295 (void) printf(" %s %s", gettext("was"), path
);
2296 } else if (vs
->vs_aux
!= 0) {
2298 color_start(ANSI_RED
);
2299 switch (vs
->vs_aux
) {
2300 case VDEV_AUX_OPEN_FAILED
:
2301 (void) printf(gettext("cannot open"));
2304 case VDEV_AUX_BAD_GUID_SUM
:
2305 (void) printf(gettext("missing device"));
2308 case VDEV_AUX_NO_REPLICAS
:
2309 (void) printf(gettext("insufficient replicas"));
2312 case VDEV_AUX_VERSION_NEWER
:
2313 (void) printf(gettext("newer version"));
2316 case VDEV_AUX_UNSUP_FEAT
:
2317 (void) printf(gettext("unsupported feature(s)"));
2320 case VDEV_AUX_ASHIFT_TOO_BIG
:
2321 (void) printf(gettext("unsupported minimum blocksize"));
2324 case VDEV_AUX_SPARED
:
2325 verify(nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
,
2326 &spare_cb
.cb_guid
) == 0);
2327 if (zpool_iter(g_zfs
, find_spare
, &spare_cb
) == 1) {
2328 if (strcmp(zpool_get_name(spare_cb
.cb_zhp
),
2329 zpool_get_name(zhp
)) == 0)
2330 (void) printf(gettext("currently in "
2333 (void) printf(gettext("in use by "
2335 zpool_get_name(spare_cb
.cb_zhp
));
2336 zpool_close(spare_cb
.cb_zhp
);
2338 (void) printf(gettext("currently in use"));
2342 case VDEV_AUX_ERR_EXCEEDED
:
2343 (void) printf(gettext("too many errors"));
2346 case VDEV_AUX_IO_FAILURE
:
2347 (void) printf(gettext("experienced I/O failures"));
2350 case VDEV_AUX_BAD_LOG
:
2351 (void) printf(gettext("bad intent log"));
2354 case VDEV_AUX_EXTERNAL
:
2355 (void) printf(gettext("external device fault"));
2358 case VDEV_AUX_SPLIT_POOL
:
2359 (void) printf(gettext("split into new pool"));
2362 case VDEV_AUX_ACTIVE
:
2363 (void) printf(gettext("currently in use"));
2366 case VDEV_AUX_CHILDREN_OFFLINE
:
2367 (void) printf(gettext("all children offline"));
2371 (void) printf(gettext("corrupted data"));
2375 } else if (children
== 0 && !isspare
&&
2376 getenv("ZPOOL_STATUS_NON_NATIVE_ASHIFT_IGNORE") == NULL
&&
2377 VDEV_STAT_VALID(vs_physical_ashift
, vsc
) &&
2378 vs
->vs_configured_ashift
< vs
->vs_physical_ashift
) {
2380 gettext(" block size: %dB configured, %dB native"),
2381 1 << vs
->vs_configured_ashift
, 1 << vs
->vs_physical_ashift
);
2384 /* The root vdev has the scrub/resilver stats */
2385 root
= fnvlist_lookup_nvlist(zpool_get_config(zhp
, NULL
),
2386 ZPOOL_CONFIG_VDEV_TREE
);
2387 (void) nvlist_lookup_uint64_array(root
, ZPOOL_CONFIG_SCAN_STATS
,
2388 (uint64_t **)&ps
, &c
);
2390 if (ps
!= NULL
&& ps
->pss_state
== DSS_SCANNING
&& children
== 0) {
2391 if (vs
->vs_scan_processed
!= 0) {
2392 (void) printf(gettext(" (%s)"),
2393 (ps
->pss_func
== POOL_SCAN_RESILVER
) ?
2394 "resilvering" : "repairing");
2395 } else if (vs
->vs_resilver_deferred
) {
2396 (void) printf(gettext(" (awaiting resilver)"));
2400 /* The top-level vdevs have the rebuild stats */
2401 if (vrs
!= NULL
&& vrs
->vrs_state
== VDEV_REBUILD_ACTIVE
&&
2403 if (vs
->vs_rebuild_processed
!= 0) {
2404 (void) printf(gettext(" (resilvering)"));
2408 if (cb
->vcdl
!= NULL
) {
2409 if (nvlist_lookup_string(nv
, ZPOOL_CONFIG_PATH
, &path
) == 0) {
2411 zpool_print_cmd(cb
->vcdl
, zpool_get_name(zhp
), path
);
2415 /* Display vdev initialization and trim status for leaves. */
2416 if (children
== 0) {
2417 print_status_initialize(vs
, cb
->cb_print_vdev_init
);
2418 print_status_trim(vs
, cb
->cb_print_vdev_trim
);
2421 (void) printf("\n");
2423 for (c
= 0; c
< children
; c
++) {
2424 uint64_t islog
= B_FALSE
, ishole
= B_FALSE
;
2426 /* Don't print logs or holes here */
2427 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
2429 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_HOLE
,
2431 if (islog
|| ishole
)
2433 /* Only print normal classes here */
2434 if (nvlist_exists(child
[c
], ZPOOL_CONFIG_ALLOCATION_BIAS
))
2437 /* Provide vdev_rebuild_stats to children if available */
2439 (void) nvlist_lookup_uint64_array(nv
,
2440 ZPOOL_CONFIG_REBUILD_STATS
,
2441 (uint64_t **)&vrs
, &i
);
2444 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
2445 cb
->cb_name_flags
| VDEV_NAME_TYPE_ID
);
2446 print_status_config(zhp
, cb
, vname
, child
[c
], depth
+ 2,
2453 * Print the configuration of an exported pool. Iterate over all vdevs in the
2454 * pool, printing out the name and status for each one.
2457 print_import_config(status_cbdata_t
*cb
, const char *name
, nvlist_t
*nv
,
2465 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_TYPE
, &type
) == 0);
2466 if (strcmp(type
, VDEV_TYPE_MISSING
) == 0 ||
2467 strcmp(type
, VDEV_TYPE_HOLE
) == 0)
2470 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
2471 (uint64_t **)&vs
, &c
) == 0);
2473 (void) printf("\t%*s%-*s", depth
, "", cb
->cb_namewidth
- depth
, name
);
2474 (void) printf(" %s", zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
));
2476 if (vs
->vs_aux
!= 0) {
2479 switch (vs
->vs_aux
) {
2480 case VDEV_AUX_OPEN_FAILED
:
2481 (void) printf(gettext("cannot open"));
2484 case VDEV_AUX_BAD_GUID_SUM
:
2485 (void) printf(gettext("missing device"));
2488 case VDEV_AUX_NO_REPLICAS
:
2489 (void) printf(gettext("insufficient replicas"));
2492 case VDEV_AUX_VERSION_NEWER
:
2493 (void) printf(gettext("newer version"));
2496 case VDEV_AUX_UNSUP_FEAT
:
2497 (void) printf(gettext("unsupported feature(s)"));
2500 case VDEV_AUX_ERR_EXCEEDED
:
2501 (void) printf(gettext("too many errors"));
2504 case VDEV_AUX_ACTIVE
:
2505 (void) printf(gettext("currently in use"));
2508 case VDEV_AUX_CHILDREN_OFFLINE
:
2509 (void) printf(gettext("all children offline"));
2513 (void) printf(gettext("corrupted data"));
2517 (void) printf("\n");
2519 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
2520 &child
, &children
) != 0)
2523 for (c
= 0; c
< children
; c
++) {
2524 uint64_t is_log
= B_FALSE
;
2526 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
2530 if (nvlist_exists(child
[c
], ZPOOL_CONFIG_ALLOCATION_BIAS
))
2533 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
],
2534 cb
->cb_name_flags
| VDEV_NAME_TYPE_ID
);
2535 print_import_config(cb
, vname
, child
[c
], depth
+ 2);
2539 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
2540 &child
, &children
) == 0) {
2541 (void) printf(gettext("\tcache\n"));
2542 for (c
= 0; c
< children
; c
++) {
2543 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
],
2545 (void) printf("\t %s\n", vname
);
2550 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
2551 &child
, &children
) == 0) {
2552 (void) printf(gettext("\tspares\n"));
2553 for (c
= 0; c
< children
; c
++) {
2554 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
],
2556 (void) printf("\t %s\n", vname
);
2563 * Print specialized class vdevs.
2565 * These are recorded as top level vdevs in the main pool child array
2566 * but with "is_log" set to 1 or an "alloc_bias" string. We use either
2567 * print_status_config() or print_import_config() to print the top level
2568 * class vdevs then any of their children (eg mirrored slogs) are printed
2569 * recursively - which works because only the top level vdev is marked.
2572 print_class_vdevs(zpool_handle_t
*zhp
, status_cbdata_t
*cb
, nvlist_t
*nv
,
2577 boolean_t printed
= B_FALSE
;
2579 assert(zhp
!= NULL
|| !cb
->cb_verbose
);
2581 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
, &child
,
2585 for (c
= 0; c
< children
; c
++) {
2586 uint64_t is_log
= B_FALSE
;
2590 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
2594 bias
= VDEV_ALLOC_CLASS_LOGS
;
2596 (void) nvlist_lookup_string(child
[c
],
2597 ZPOOL_CONFIG_ALLOCATION_BIAS
, &bias
);
2598 (void) nvlist_lookup_string(child
[c
],
2599 ZPOOL_CONFIG_TYPE
, &type
);
2602 if (bias
== NULL
|| strcmp(bias
, class) != 0)
2604 if (!is_log
&& strcmp(type
, VDEV_TYPE_INDIRECT
) == 0)
2608 (void) printf("\t%s\t\n", gettext(class));
2612 char *name
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
2613 cb
->cb_name_flags
| VDEV_NAME_TYPE_ID
);
2614 if (cb
->cb_print_status
)
2615 print_status_config(zhp
, cb
, name
, child
[c
], 2,
2618 print_import_config(cb
, name
, child
[c
], 2);
2624 * Display the status for the given pool.
2627 show_import(nvlist_t
*config
, boolean_t report_error
)
2629 uint64_t pool_state
;
2633 uint64_t hostid
= 0;
2635 char *hostname
= "unknown";
2636 nvlist_t
*nvroot
, *nvinfo
;
2637 zpool_status_t reason
;
2638 zpool_errata_t errata
;
2642 status_cbdata_t cb
= { 0 };
2644 verify(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
2646 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
,
2648 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
2650 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
2653 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_VDEV_STATS
,
2654 (uint64_t **)&vs
, &vsc
) == 0);
2655 health
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
2657 reason
= zpool_import_status(config
, &msgid
, &errata
);
2660 * If we're importing using a cachefile, then we won't report any
2661 * errors unless we are in the scan phase of the import.
2663 if (reason
!= ZPOOL_STATUS_OK
&& !report_error
)
2666 (void) printf(gettext(" pool: %s\n"), name
);
2667 (void) printf(gettext(" id: %llu\n"), (u_longlong_t
)guid
);
2668 (void) printf(gettext(" state: %s"), health
);
2669 if (pool_state
== POOL_STATE_DESTROYED
)
2670 (void) printf(gettext(" (DESTROYED)"));
2671 (void) printf("\n");
2674 case ZPOOL_STATUS_MISSING_DEV_R
:
2675 case ZPOOL_STATUS_MISSING_DEV_NR
:
2676 case ZPOOL_STATUS_BAD_GUID_SUM
:
2677 printf_color(ANSI_BOLD
, gettext("status: "));
2678 printf_color(ANSI_YELLOW
, gettext("One or more devices are "
2679 "missing from the system.\n"));
2682 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
2683 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
2684 printf_color(ANSI_BOLD
, gettext("status: "));
2685 printf_color(ANSI_YELLOW
, gettext("One or more devices contains"
2686 " corrupted data.\n"));
2689 case ZPOOL_STATUS_CORRUPT_DATA
:
2691 gettext(" status: The pool data is corrupted.\n"));
2694 case ZPOOL_STATUS_OFFLINE_DEV
:
2695 printf_color(ANSI_BOLD
, gettext("status: "));
2696 printf_color(ANSI_YELLOW
, gettext("One or more devices "
2697 "are offlined.\n"));
2700 case ZPOOL_STATUS_CORRUPT_POOL
:
2701 printf_color(ANSI_BOLD
, gettext("status: "));
2702 printf_color(ANSI_YELLOW
, gettext("The pool metadata is "
2706 case ZPOOL_STATUS_VERSION_OLDER
:
2707 printf_color(ANSI_BOLD
, gettext("status: "));
2708 printf_color(ANSI_YELLOW
, gettext("The pool is formatted using "
2709 "a legacy on-disk version.\n"));
2712 case ZPOOL_STATUS_VERSION_NEWER
:
2713 printf_color(ANSI_BOLD
, gettext("status: "));
2714 printf_color(ANSI_YELLOW
, gettext("The pool is formatted using "
2715 "an incompatible version.\n"));
2718 case ZPOOL_STATUS_FEAT_DISABLED
:
2719 printf_color(ANSI_BOLD
, gettext("status: "));
2720 printf_color(ANSI_YELLOW
, gettext("Some supported and "
2721 "requested features are not enabled on the pool.\n"));
2724 case ZPOOL_STATUS_COMPATIBILITY_ERR
:
2725 printf_color(ANSI_BOLD
, gettext("status: "));
2726 printf_color(ANSI_YELLOW
, gettext("Error reading or parsing "
2727 "the file(s) indicated by the 'compatibility'\n"
2731 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
2732 printf_color(ANSI_BOLD
, gettext("status: "));
2733 printf_color(ANSI_YELLOW
, gettext("The pool uses the following "
2734 "feature(s) not supported on this system:\n"));
2735 color_start(ANSI_YELLOW
);
2736 zpool_print_unsup_feat(config
);
2740 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
2741 printf_color(ANSI_BOLD
, gettext("status: "));
2742 printf_color(ANSI_YELLOW
, gettext("The pool can only be "
2743 "accessed in read-only mode on this system. It\n\tcannot be"
2744 " accessed in read-write mode because it uses the "
2745 "following\n\tfeature(s) not supported on this system:\n"));
2746 color_start(ANSI_YELLOW
);
2747 zpool_print_unsup_feat(config
);
2751 case ZPOOL_STATUS_HOSTID_ACTIVE
:
2752 printf_color(ANSI_BOLD
, gettext("status: "));
2753 printf_color(ANSI_YELLOW
, gettext("The pool is currently "
2754 "imported by another system.\n"));
2757 case ZPOOL_STATUS_HOSTID_REQUIRED
:
2758 printf_color(ANSI_BOLD
, gettext("status: "));
2759 printf_color(ANSI_YELLOW
, gettext("The pool has the "
2760 "multihost property on. It cannot\n\tbe safely imported "
2761 "when the system hostid is not set.\n"));
2764 case ZPOOL_STATUS_HOSTID_MISMATCH
:
2765 printf_color(ANSI_BOLD
, gettext("status: "));
2766 printf_color(ANSI_YELLOW
, gettext("The pool was last accessed "
2767 "by another system.\n"));
2770 case ZPOOL_STATUS_FAULTED_DEV_R
:
2771 case ZPOOL_STATUS_FAULTED_DEV_NR
:
2772 printf_color(ANSI_BOLD
, gettext("status: "));
2773 printf_color(ANSI_YELLOW
, gettext("One or more devices are "
2777 case ZPOOL_STATUS_BAD_LOG
:
2778 printf_color(ANSI_BOLD
, gettext("status: "));
2779 printf_color(ANSI_YELLOW
, gettext("An intent log record cannot "
2783 case ZPOOL_STATUS_RESILVERING
:
2784 case ZPOOL_STATUS_REBUILDING
:
2785 printf_color(ANSI_BOLD
, gettext("status: "));
2786 printf_color(ANSI_YELLOW
, gettext("One or more devices were "
2787 "being resilvered.\n"));
2790 case ZPOOL_STATUS_ERRATA
:
2791 printf_color(ANSI_BOLD
, gettext("status: "));
2792 printf_color(ANSI_YELLOW
, gettext("Errata #%d detected.\n"),
2796 case ZPOOL_STATUS_NON_NATIVE_ASHIFT
:
2797 printf_color(ANSI_BOLD
, gettext("status: "));
2798 printf_color(ANSI_YELLOW
, gettext("One or more devices are "
2799 "configured to use a non-native block size.\n"
2800 "\tExpect reduced performance.\n"));
2805 * No other status can be seen when importing pools.
2807 assert(reason
== ZPOOL_STATUS_OK
);
2811 * Print out an action according to the overall state of the pool.
2813 if (vs
->vs_state
== VDEV_STATE_HEALTHY
) {
2814 if (reason
== ZPOOL_STATUS_VERSION_OLDER
||
2815 reason
== ZPOOL_STATUS_FEAT_DISABLED
) {
2816 (void) printf(gettext(" action: The pool can be "
2817 "imported using its name or numeric identifier, "
2818 "though\n\tsome features will not be available "
2819 "without an explicit 'zpool upgrade'.\n"));
2820 } else if (reason
== ZPOOL_STATUS_COMPATIBILITY_ERR
) {
2821 (void) printf(gettext(" action: The pool can be "
2822 "imported using its name or numeric\n\tidentifier, "
2823 "though the file(s) indicated by its "
2824 "'compatibility'\n\tproperty cannot be parsed at "
2826 } else if (reason
== ZPOOL_STATUS_HOSTID_MISMATCH
) {
2827 (void) printf(gettext(" action: The pool can be "
2828 "imported using its name or numeric "
2829 "identifier and\n\tthe '-f' flag.\n"));
2830 } else if (reason
== ZPOOL_STATUS_ERRATA
) {
2832 case ZPOOL_ERRATA_NONE
:
2835 case ZPOOL_ERRATA_ZOL_2094_SCRUB
:
2836 (void) printf(gettext(" action: The pool can "
2837 "be imported using its name or numeric "
2838 "identifier,\n\thowever there is a compat"
2839 "ibility issue which should be corrected"
2840 "\n\tby running 'zpool scrub'\n"));
2843 case ZPOOL_ERRATA_ZOL_2094_ASYNC_DESTROY
:
2844 (void) printf(gettext(" action: The pool can"
2845 "not be imported with this version of ZFS "
2846 "due to\n\tan active asynchronous destroy. "
2847 "Revert to an earlier version\n\tand "
2848 "allow the destroy to complete before "
2852 case ZPOOL_ERRATA_ZOL_6845_ENCRYPTION
:
2853 (void) printf(gettext(" action: Existing "
2854 "encrypted datasets contain an on-disk "
2855 "incompatibility, which\n\tneeds to be "
2856 "corrected. Backup these datasets to new "
2857 "encrypted datasets\n\tand destroy the "
2861 case ZPOOL_ERRATA_ZOL_8308_ENCRYPTION
:
2862 (void) printf(gettext(" action: Existing "
2863 "encrypted snapshots and bookmarks contain "
2864 "an on-disk\n\tincompatibility. This may "
2865 "cause on-disk corruption if they are used"
2866 "\n\twith 'zfs recv'. To correct the "
2867 "issue, enable the bookmark_v2 feature.\n\t"
2868 "No additional action is needed if there "
2869 "are no encrypted snapshots or\n\t"
2870 "bookmarks. If preserving the encrypted "
2871 "snapshots and bookmarks is\n\trequired, "
2872 "use a non-raw send to backup and restore "
2873 "them. Alternately,\n\tthey may be removed"
2874 " to resolve the incompatibility.\n"));
2878 * All errata must contain an action message.
2883 (void) printf(gettext(" action: The pool can be "
2884 "imported using its name or numeric "
2887 } else if (vs
->vs_state
== VDEV_STATE_DEGRADED
) {
2888 (void) printf(gettext(" action: The pool can be imported "
2889 "despite missing or damaged devices. The\n\tfault "
2890 "tolerance of the pool may be compromised if imported.\n"));
2893 case ZPOOL_STATUS_VERSION_NEWER
:
2894 (void) printf(gettext(" action: The pool cannot be "
2895 "imported. Access the pool on a system running "
2896 "newer\n\tsoftware, or recreate the pool from "
2899 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
2900 printf_color(ANSI_BOLD
, gettext("action: "));
2901 printf_color(ANSI_YELLOW
, gettext("The pool cannot be "
2902 "imported. Access the pool on a system that "
2903 "supports\n\tthe required feature(s), or recreate "
2904 "the pool from backup.\n"));
2906 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
2907 printf_color(ANSI_BOLD
, gettext("action: "));
2908 printf_color(ANSI_YELLOW
, gettext("The pool cannot be "
2909 "imported in read-write mode. Import the pool "
2911 "\t\"-o readonly=on\", access the pool on a system "
2912 "that supports the\n\trequired feature(s), or "
2913 "recreate the pool from backup.\n"));
2915 case ZPOOL_STATUS_MISSING_DEV_R
:
2916 case ZPOOL_STATUS_MISSING_DEV_NR
:
2917 case ZPOOL_STATUS_BAD_GUID_SUM
:
2918 (void) printf(gettext(" action: The pool cannot be "
2919 "imported. Attach the missing\n\tdevices and try "
2922 case ZPOOL_STATUS_HOSTID_ACTIVE
:
2923 VERIFY0(nvlist_lookup_nvlist(config
,
2924 ZPOOL_CONFIG_LOAD_INFO
, &nvinfo
));
2926 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_MMP_HOSTNAME
))
2927 hostname
= fnvlist_lookup_string(nvinfo
,
2928 ZPOOL_CONFIG_MMP_HOSTNAME
);
2930 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_MMP_HOSTID
))
2931 hostid
= fnvlist_lookup_uint64(nvinfo
,
2932 ZPOOL_CONFIG_MMP_HOSTID
);
2934 (void) printf(gettext(" action: The pool must be "
2935 "exported from %s (hostid=%lx)\n\tbefore it "
2936 "can be safely imported.\n"), hostname
,
2937 (unsigned long) hostid
);
2939 case ZPOOL_STATUS_HOSTID_REQUIRED
:
2940 (void) printf(gettext(" action: Set a unique system "
2941 "hostid with the zgenhostid(8) command.\n"));
2944 (void) printf(gettext(" action: The pool cannot be "
2945 "imported due to damaged devices or data.\n"));
2949 /* Print the comment attached to the pool. */
2950 if (nvlist_lookup_string(config
, ZPOOL_CONFIG_COMMENT
, &comment
) == 0)
2951 (void) printf(gettext("comment: %s\n"), comment
);
2954 * If the state is "closed" or "can't open", and the aux state
2955 * is "corrupt data":
2957 if (((vs
->vs_state
== VDEV_STATE_CLOSED
) ||
2958 (vs
->vs_state
== VDEV_STATE_CANT_OPEN
)) &&
2959 (vs
->vs_aux
== VDEV_AUX_CORRUPT_DATA
)) {
2960 if (pool_state
== POOL_STATE_DESTROYED
)
2961 (void) printf(gettext("\tThe pool was destroyed, "
2962 "but can be imported using the '-Df' flags.\n"));
2963 else if (pool_state
!= POOL_STATE_EXPORTED
)
2964 (void) printf(gettext("\tThe pool may be active on "
2965 "another system, but can be imported using\n\t"
2966 "the '-f' flag.\n"));
2969 if (msgid
!= NULL
) {
2970 (void) printf(gettext(
2971 " see: https://openzfs.github.io/openzfs-docs/msg/%s\n"),
2975 (void) printf(gettext(" config:\n\n"));
2977 cb
.cb_namewidth
= max_width(NULL
, nvroot
, 0, strlen(name
),
2979 if (cb
.cb_namewidth
< 10)
2980 cb
.cb_namewidth
= 10;
2982 print_import_config(&cb
, name
, nvroot
, 0);
2984 print_class_vdevs(NULL
, &cb
, nvroot
, VDEV_ALLOC_BIAS_DEDUP
);
2985 print_class_vdevs(NULL
, &cb
, nvroot
, VDEV_ALLOC_BIAS_SPECIAL
);
2986 print_class_vdevs(NULL
, &cb
, nvroot
, VDEV_ALLOC_CLASS_LOGS
);
2988 if (reason
== ZPOOL_STATUS_BAD_GUID_SUM
) {
2989 (void) printf(gettext("\n\tAdditional devices are known to "
2990 "be part of this pool, though their\n\texact "
2991 "configuration cannot be determined.\n"));
2997 zfs_force_import_required(nvlist_t
*config
)
3000 uint64_t hostid
= 0;
3003 state
= fnvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
);
3004 (void) nvlist_lookup_uint64(config
, ZPOOL_CONFIG_HOSTID
, &hostid
);
3006 if (state
!= POOL_STATE_EXPORTED
&& hostid
!= get_system_hostid())
3009 nvinfo
= fnvlist_lookup_nvlist(config
, ZPOOL_CONFIG_LOAD_INFO
);
3010 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_MMP_STATE
)) {
3011 mmp_state_t mmp_state
= fnvlist_lookup_uint64(nvinfo
,
3012 ZPOOL_CONFIG_MMP_STATE
);
3014 if (mmp_state
!= MMP_STATE_INACTIVE
)
3022 * Perform the import for the given configuration. This passes the heavy
3023 * lifting off to zpool_import_props(), and then mounts the datasets contained
3027 do_import(nvlist_t
*config
, const char *newname
, const char *mntopts
,
3028 nvlist_t
*props
, int flags
)
3031 zpool_handle_t
*zhp
;
3035 name
= fnvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
);
3036 version
= fnvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
);
3038 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
3039 (void) fprintf(stderr
, gettext("cannot import '%s': pool "
3040 "is formatted using an unsupported ZFS version\n"), name
);
3042 } else if (zfs_force_import_required(config
) &&
3043 !(flags
& ZFS_IMPORT_ANY_HOST
)) {
3044 mmp_state_t mmp_state
= MMP_STATE_INACTIVE
;
3047 nvinfo
= fnvlist_lookup_nvlist(config
, ZPOOL_CONFIG_LOAD_INFO
);
3048 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_MMP_STATE
))
3049 mmp_state
= fnvlist_lookup_uint64(nvinfo
,
3050 ZPOOL_CONFIG_MMP_STATE
);
3052 if (mmp_state
== MMP_STATE_ACTIVE
) {
3053 char *hostname
= "<unknown>";
3054 uint64_t hostid
= 0;
3056 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_MMP_HOSTNAME
))
3057 hostname
= fnvlist_lookup_string(nvinfo
,
3058 ZPOOL_CONFIG_MMP_HOSTNAME
);
3060 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_MMP_HOSTID
))
3061 hostid
= fnvlist_lookup_uint64(nvinfo
,
3062 ZPOOL_CONFIG_MMP_HOSTID
);
3064 (void) fprintf(stderr
, gettext("cannot import '%s': "
3065 "pool is imported on %s (hostid: "
3066 "0x%lx)\nExport the pool on the other system, "
3067 "then run 'zpool import'.\n"),
3068 name
, hostname
, (unsigned long) hostid
);
3069 } else if (mmp_state
== MMP_STATE_NO_HOSTID
) {
3070 (void) fprintf(stderr
, gettext("Cannot import '%s': "
3071 "pool has the multihost property on and the\n"
3072 "system's hostid is not set. Set a unique hostid "
3073 "with the zgenhostid(8) command.\n"), name
);
3075 char *hostname
= "<unknown>";
3076 uint64_t timestamp
= 0;
3077 uint64_t hostid
= 0;
3079 if (nvlist_exists(config
, ZPOOL_CONFIG_HOSTNAME
))
3080 hostname
= fnvlist_lookup_string(config
,
3081 ZPOOL_CONFIG_HOSTNAME
);
3083 if (nvlist_exists(config
, ZPOOL_CONFIG_TIMESTAMP
))
3084 timestamp
= fnvlist_lookup_uint64(config
,
3085 ZPOOL_CONFIG_TIMESTAMP
);
3087 if (nvlist_exists(config
, ZPOOL_CONFIG_HOSTID
))
3088 hostid
= fnvlist_lookup_uint64(config
,
3089 ZPOOL_CONFIG_HOSTID
);
3091 (void) fprintf(stderr
, gettext("cannot import '%s': "
3092 "pool was previously in use from another system.\n"
3093 "Last accessed by %s (hostid=%lx) at %s"
3094 "The pool can be imported, use 'zpool import -f' "
3095 "to import the pool.\n"), name
, hostname
,
3096 (unsigned long)hostid
, ctime((time_t *)×tamp
));
3102 if (zpool_import_props(g_zfs
, config
, newname
, props
, flags
) != 0)
3105 if (newname
!= NULL
)
3106 name
= (char *)newname
;
3108 if ((zhp
= zpool_open_canfail(g_zfs
, name
)) == NULL
)
3112 * Loading keys is best effort. We don't want to return immediately
3113 * if it fails but we do want to give the error to the caller.
3115 if (flags
& ZFS_IMPORT_LOAD_KEYS
) {
3116 ret
= zfs_crypto_attempt_load_keys(g_zfs
, name
);
3121 if (zpool_get_state(zhp
) != POOL_STATE_UNAVAIL
&&
3122 !(flags
& ZFS_IMPORT_ONLY
) &&
3123 zpool_enable_datasets(zhp
, mntopts
, 0) != 0) {
3133 import_pools(nvlist_t
*pools
, nvlist_t
*props
, char *mntopts
, int flags
,
3134 char *orig_name
, char *new_name
,
3135 boolean_t do_destroyed
, boolean_t pool_specified
, boolean_t do_all
,
3136 importargs_t
*import
)
3138 nvlist_t
*config
= NULL
;
3139 nvlist_t
*found_config
= NULL
;
3140 uint64_t pool_state
;
3143 * At this point we have a list of import candidate configs. Even if
3144 * we were searching by pool name or guid, we still need to
3145 * post-process the list to deal with pool state and possible
3149 nvpair_t
*elem
= NULL
;
3150 boolean_t first
= B_TRUE
;
3151 while ((elem
= nvlist_next_nvpair(pools
, elem
)) != NULL
) {
3153 verify(nvpair_value_nvlist(elem
, &config
) == 0);
3155 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
3157 if (!do_destroyed
&& pool_state
== POOL_STATE_DESTROYED
)
3159 if (do_destroyed
&& pool_state
!= POOL_STATE_DESTROYED
)
3162 verify(nvlist_add_nvlist(config
, ZPOOL_LOAD_POLICY
,
3163 import
->policy
) == 0);
3165 if (!pool_specified
) {
3169 (void) printf("\n");
3172 err
|= do_import(config
, NULL
, mntopts
,
3176 * If we're importing from cachefile, then
3177 * we don't want to report errors until we
3178 * are in the scan phase of the import. If
3179 * we get an error, then we return that error
3180 * to invoke the scan phase.
3182 if (import
->cachefile
&& !import
->scan
)
3183 err
= show_import(config
, B_FALSE
);
3185 (void) show_import(config
, B_TRUE
);
3187 } else if (import
->poolname
!= NULL
) {
3191 * We are searching for a pool based on name.
3193 verify(nvlist_lookup_string(config
,
3194 ZPOOL_CONFIG_POOL_NAME
, &name
) == 0);
3196 if (strcmp(name
, import
->poolname
) == 0) {
3197 if (found_config
!= NULL
) {
3198 (void) fprintf(stderr
, gettext(
3199 "cannot import '%s': more than "
3200 "one matching pool\n"),
3202 (void) fprintf(stderr
, gettext(
3203 "import by numeric ID instead\n"));
3206 found_config
= config
;
3212 * Search for a pool by guid.
3214 verify(nvlist_lookup_uint64(config
,
3215 ZPOOL_CONFIG_POOL_GUID
, &guid
) == 0);
3217 if (guid
== import
->guid
)
3218 found_config
= config
;
3223 * If we were searching for a specific pool, verify that we found a
3224 * pool, and then do the import.
3226 if (pool_specified
&& err
== 0) {
3227 if (found_config
== NULL
) {
3228 (void) fprintf(stderr
, gettext("cannot import '%s': "
3229 "no such pool available\n"), orig_name
);
3232 err
|= do_import(found_config
, new_name
,
3233 mntopts
, props
, flags
);
3238 * If we were just looking for pools, report an error if none were
3241 if (!pool_specified
&& first
)
3242 (void) fprintf(stderr
,
3243 gettext("no pools available to import\n"));
3247 typedef struct target_exists_args
{
3248 const char *poolname
;
3250 } target_exists_args_t
;
3253 name_or_guid_exists(zpool_handle_t
*zhp
, void *data
)
3255 target_exists_args_t
*args
= data
;
3256 nvlist_t
*config
= zpool_get_config(zhp
, NULL
);
3262 if (args
->poolname
!= NULL
) {
3265 verify(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
3267 if (strcmp(pool_name
, args
->poolname
) == 0)
3272 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
,
3274 if (pool_guid
== args
->poolguid
)
3282 * zpool checkpoint <pool>
3283 * checkpoint --discard <pool>
3285 * -d Discard the checkpoint from a checkpointed
3288 * -w Wait for discarding a checkpoint to complete.
3291 * Checkpoints the specified pool, by taking a "snapshot" of its
3292 * current state. A pool can only have one checkpoint at a time.
3295 zpool_do_checkpoint(int argc
, char **argv
)
3297 boolean_t discard
, wait
;
3299 zpool_handle_t
*zhp
;
3302 struct option long_options
[] = {
3303 {"discard", no_argument
, NULL
, 'd'},
3304 {"wait", no_argument
, NULL
, 'w'},
3310 while ((c
= getopt_long(argc
, argv
, ":dw", long_options
, NULL
)) != -1) {
3319 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3325 if (wait
&& !discard
) {
3326 (void) fprintf(stderr
, gettext("--wait only valid when "
3327 "--discard also specified\n"));
3335 (void) fprintf(stderr
, gettext("missing pool argument\n"));
3340 (void) fprintf(stderr
, gettext("too many arguments\n"));
3346 if ((zhp
= zpool_open(g_zfs
, pool
)) == NULL
) {
3347 /* As a special case, check for use of '/' in the name */
3348 if (strchr(pool
, '/') != NULL
)
3349 (void) fprintf(stderr
, gettext("'zpool checkpoint' "
3350 "doesn't work on datasets. To save the state "
3351 "of a dataset from a specific point in time "
3352 "please use 'zfs snapshot'\n"));
3357 err
= (zpool_discard_checkpoint(zhp
) != 0);
3358 if (err
== 0 && wait
)
3359 err
= zpool_wait(zhp
, ZPOOL_WAIT_CKPT_DISCARD
);
3361 err
= (zpool_checkpoint(zhp
) != 0);
3369 #define CHECKPOINT_OPT 1024
3372 * zpool import [-d dir] [-D]
3373 * import [-o mntopts] [-o prop=value] ... [-R root] [-D] [-l]
3374 * [-d dir | -c cachefile | -s] [-f] -a
3375 * import [-o mntopts] [-o prop=value] ... [-R root] [-D] [-l]
3376 * [-d dir | -c cachefile | -s] [-f] [-n] [-F] <pool | id>
3379 * -c Read pool information from a cachefile instead of searching
3380 * devices. If importing from a cachefile config fails, then
3381 * fallback to searching for devices only in the directories that
3382 * exist in the cachefile.
3384 * -d Scan in a specific directory, other than /dev/. More than
3385 * one directory can be specified using multiple '-d' options.
3387 * -D Scan for previously destroyed pools or import all or only
3388 * specified destroyed pools.
3390 * -R Temporarily import the pool, with all mountpoints relative to
3391 * the given root. The pool will remain exported when the machine
3394 * -V Import even in the presence of faulted vdevs. This is an
3395 * intentionally undocumented option for testing purposes, and
3396 * treats the pool configuration as complete, leaving any bad
3397 * vdevs in the FAULTED state. In other words, it does verbatim
3400 * -f Force import, even if it appears that the pool is active.
3402 * -F Attempt rewind if necessary.
3404 * -n See if rewind would work, but don't actually rewind.
3406 * -N Import the pool but don't mount datasets.
3408 * -T Specify a starting txg to use for import. This option is
3409 * intentionally undocumented option for testing purposes.
3411 * -a Import all pools found.
3413 * -l Load encryption keys while importing.
3415 * -o Set property=value and/or temporary mount options (without '=').
3417 * -s Scan using the default search path, the libblkid cache will
3420 * --rewind-to-checkpoint
3421 * Import the pool and revert back to the checkpoint.
3423 * The import command scans for pools to import, and import pools based on pool
3424 * name and GUID. The pool can also be renamed as part of the import process.
3427 zpool_do_import(int argc
, char **argv
)
3429 char **searchdirs
= NULL
;
3430 char *env
, *envdup
= NULL
;
3434 nvlist_t
*pools
= NULL
;
3435 boolean_t do_all
= B_FALSE
;
3436 boolean_t do_destroyed
= B_FALSE
;
3437 char *mntopts
= NULL
;
3438 uint64_t searchguid
= 0;
3439 char *searchname
= NULL
;
3441 nvlist_t
*policy
= NULL
;
3442 nvlist_t
*props
= NULL
;
3443 int flags
= ZFS_IMPORT_NORMAL
;
3444 uint32_t rewind_policy
= ZPOOL_NO_REWIND
;
3445 boolean_t dryrun
= B_FALSE
;
3446 boolean_t do_rewind
= B_FALSE
;
3447 boolean_t xtreme_rewind
= B_FALSE
;
3448 boolean_t do_scan
= B_FALSE
;
3449 boolean_t pool_exists
= B_FALSE
;
3450 boolean_t pool_specified
= B_FALSE
;
3451 uint64_t txg
= -1ULL;
3452 char *cachefile
= NULL
;
3453 importargs_t idata
= { 0 };
3456 struct option long_options
[] = {
3457 {"rewind-to-checkpoint", no_argument
, NULL
, CHECKPOINT_OPT
},
3462 while ((c
= getopt_long(argc
, argv
, ":aCc:d:DEfFlmnNo:R:stT:VX",
3463 long_options
, NULL
)) != -1) {
3472 if (searchdirs
== NULL
) {
3473 searchdirs
= safe_malloc(sizeof (char *));
3475 char **tmp
= safe_malloc((nsearch
+ 1) *
3477 bcopy(searchdirs
, tmp
, nsearch
*
3482 searchdirs
[nsearch
++] = optarg
;
3485 do_destroyed
= B_TRUE
;
3488 flags
|= ZFS_IMPORT_ANY_HOST
;
3494 flags
|= ZFS_IMPORT_LOAD_KEYS
;
3497 flags
|= ZFS_IMPORT_MISSING_LOG
;
3503 flags
|= ZFS_IMPORT_ONLY
;
3506 if ((propval
= strchr(optarg
, '=')) != NULL
) {
3509 if (add_prop_list(optarg
, propval
,
3517 if (add_prop_list(zpool_prop_to_name(
3518 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
3520 if (add_prop_list_default(zpool_prop_to_name(
3521 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
3528 flags
|= ZFS_IMPORT_TEMP_NAME
;
3529 if (add_prop_list_default(zpool_prop_to_name(
3530 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
3536 txg
= strtoull(optarg
, &endptr
, 0);
3537 if (errno
!= 0 || *endptr
!= '\0') {
3538 (void) fprintf(stderr
,
3539 gettext("invalid txg value\n"));
3542 rewind_policy
= ZPOOL_DO_REWIND
| ZPOOL_EXTREME_REWIND
;
3545 flags
|= ZFS_IMPORT_VERBATIM
;
3548 xtreme_rewind
= B_TRUE
;
3550 case CHECKPOINT_OPT
:
3551 flags
|= ZFS_IMPORT_CHECKPOINT
;
3554 (void) fprintf(stderr
, gettext("missing argument for "
3555 "'%c' option\n"), optopt
);
3559 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3568 if (cachefile
&& nsearch
!= 0) {
3569 (void) fprintf(stderr
, gettext("-c is incompatible with -d\n"));
3573 if (cachefile
&& do_scan
) {
3574 (void) fprintf(stderr
, gettext("-c is incompatible with -s\n"));
3578 if ((flags
& ZFS_IMPORT_LOAD_KEYS
) && (flags
& ZFS_IMPORT_ONLY
)) {
3579 (void) fprintf(stderr
, gettext("-l is incompatible with -N\n"));
3583 if ((flags
& ZFS_IMPORT_LOAD_KEYS
) && !do_all
&& argc
== 0) {
3584 (void) fprintf(stderr
, gettext("-l is only meaningful during "
3589 if ((dryrun
|| xtreme_rewind
) && !do_rewind
) {
3590 (void) fprintf(stderr
,
3591 gettext("-n or -X only meaningful with -F\n"));
3595 rewind_policy
= ZPOOL_TRY_REWIND
;
3597 rewind_policy
= ZPOOL_DO_REWIND
;
3599 rewind_policy
|= ZPOOL_EXTREME_REWIND
;
3601 /* In the future, we can capture further policy and include it here */
3602 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME
, 0) != 0 ||
3603 nvlist_add_uint64(policy
, ZPOOL_LOAD_REQUEST_TXG
, txg
) != 0 ||
3604 nvlist_add_uint32(policy
, ZPOOL_LOAD_REWIND_POLICY
,
3605 rewind_policy
) != 0)
3608 /* check argument count */
3611 (void) fprintf(stderr
, gettext("too many arguments\n"));
3616 (void) fprintf(stderr
, gettext("too many arguments\n"));
3622 * Check for the effective uid. We do this explicitly here because
3623 * otherwise any attempt to discover pools will silently fail.
3625 if (argc
== 0 && geteuid() != 0) {
3626 (void) fprintf(stderr
, gettext("cannot "
3627 "discover pools: permission denied\n"));
3628 if (searchdirs
!= NULL
)
3632 nvlist_free(policy
);
3637 * Depending on the arguments given, we do one of the following:
3639 * <none> Iterate through all pools and display information about
3642 * -a Iterate through all pools and try to import each one.
3644 * <id> Find the pool that corresponds to the given GUID/pool
3645 * name and import that one.
3647 * -D Above options applies only to destroyed pools.
3653 searchguid
= strtoull(argv
[0], &endptr
, 10);
3654 if (errno
!= 0 || *endptr
!= '\0') {
3655 searchname
= argv
[0];
3658 pool_specified
= B_TRUE
;
3661 * User specified a name or guid. Ensure it's unique.
3663 target_exists_args_t search
= {searchname
, searchguid
};
3664 pool_exists
= zpool_iter(g_zfs
, name_or_guid_exists
, &search
);
3668 * Check the environment for the preferred search path.
3670 if ((searchdirs
== NULL
) && (env
= getenv("ZPOOL_IMPORT_PATH"))) {
3673 envdup
= strdup(env
);
3675 dir
= strtok(envdup
, ":");
3676 while (dir
!= NULL
) {
3677 if (searchdirs
== NULL
) {
3678 searchdirs
= safe_malloc(sizeof (char *));
3680 char **tmp
= safe_malloc((nsearch
+ 1) *
3682 bcopy(searchdirs
, tmp
, nsearch
*
3687 searchdirs
[nsearch
++] = dir
;
3688 dir
= strtok(NULL
, ":");
3692 idata
.path
= searchdirs
;
3693 idata
.paths
= nsearch
;
3694 idata
.poolname
= searchname
;
3695 idata
.guid
= searchguid
;
3696 idata
.cachefile
= cachefile
;
3697 idata
.scan
= do_scan
;
3698 idata
.policy
= policy
;
3700 pools
= zpool_search_import(g_zfs
, &idata
, &libzfs_config_ops
);
3702 if (pools
!= NULL
&& pool_exists
&&
3703 (argc
== 1 || strcmp(argv
[0], argv
[1]) == 0)) {
3704 (void) fprintf(stderr
, gettext("cannot import '%s': "
3705 "a pool with that name already exists\n"),
3707 (void) fprintf(stderr
, gettext("use the form '%s "
3708 "<pool | id> <newpool>' to give it a new name\n"),
3711 } else if (pools
== NULL
&& pool_exists
) {
3712 (void) fprintf(stderr
, gettext("cannot import '%s': "
3713 "a pool with that name is already created/imported,\n"),
3715 (void) fprintf(stderr
, gettext("and no additional pools "
3716 "with that name were found\n"));
3718 } else if (pools
== NULL
) {
3720 (void) fprintf(stderr
, gettext("cannot import '%s': "
3721 "no such pool available\n"), argv
[0]);
3727 if (searchdirs
!= NULL
)
3731 nvlist_free(policy
);
3737 err
= import_pools(pools
, props
, mntopts
, flags
, argv
[0],
3738 argc
== 1 ? NULL
: argv
[1], do_destroyed
, pool_specified
,
3742 * If we're using the cachefile and we failed to import, then
3743 * fallback to scanning the directory for pools that match
3744 * those in the cachefile.
3746 if (err
!= 0 && cachefile
!= NULL
) {
3747 (void) printf(gettext("cachefile import failed, retrying\n"));
3750 * We use the scan flag to gather the directories that exist
3751 * in the cachefile. If we need to fallback to searching for
3752 * the pool config, we will only search devices in these
3755 idata
.scan
= B_TRUE
;
3757 pools
= zpool_search_import(g_zfs
, &idata
, &libzfs_config_ops
);
3759 err
= import_pools(pools
, props
, mntopts
, flags
, argv
[0],
3760 argc
== 1 ? NULL
: argv
[1], do_destroyed
, pool_specified
,
3767 nvlist_free(policy
);
3768 if (searchdirs
!= NULL
)
3773 return (err
? 1 : 0);
3777 * zpool sync [-f] [pool] ...
3779 * -f (undocumented) force uberblock (and config including zpool cache file)
3782 * Sync the specified pool(s).
3783 * Without arguments "zpool sync" will sync all pools.
3784 * This command initiates TXG sync(s) and will return after the TXG(s) commit.
3788 zpool_do_sync(int argc
, char **argv
)
3791 boolean_t force
= B_FALSE
;
3794 while ((ret
= getopt(argc
, argv
, "f")) != -1) {
3800 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3809 /* if argc == 0 we will execute zpool_sync_one on all pools */
3810 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
, B_FALSE
, zpool_sync_one
,
3816 typedef struct iostat_cbdata
{
3821 char **cb_vdev_names
; /* Only show these vdevs */
3822 unsigned int cb_vdev_names_count
;
3823 boolean_t cb_verbose
;
3824 boolean_t cb_literal
;
3825 boolean_t cb_scripted
;
3826 zpool_list_t
*cb_list
;
3827 vdev_cmd_data_list_t
*vcdl
;
3831 typedef struct name_and_columns
{
3832 const char *name
; /* Column name */
3833 unsigned int columns
; /* Center name to this number of columns */
3834 } name_and_columns_t
;
3836 #define IOSTAT_MAX_LABELS 13 /* Max number of labels on one line */
3838 static const name_and_columns_t iostat_top_labels
[][IOSTAT_MAX_LABELS
] =
3840 [IOS_DEFAULT
] = {{"capacity", 2}, {"operations", 2}, {"bandwidth", 2},
3842 [IOS_LATENCY
] = {{"total_wait", 2}, {"disk_wait", 2}, {"syncq_wait", 2},
3843 {"asyncq_wait", 2}, {"scrub", 1}, {"trim", 1}, {NULL
}},
3844 [IOS_QUEUES
] = {{"syncq_read", 2}, {"syncq_write", 2},
3845 {"asyncq_read", 2}, {"asyncq_write", 2}, {"scrubq_read", 2},
3846 {"trimq_write", 2}, {NULL
}},
3847 [IOS_L_HISTO
] = {{"total_wait", 2}, {"disk_wait", 2}, {"syncq_wait", 2},
3848 {"asyncq_wait", 2}, {NULL
}},
3849 [IOS_RQ_HISTO
] = {{"sync_read", 2}, {"sync_write", 2},
3850 {"async_read", 2}, {"async_write", 2}, {"scrub", 2},
3851 {"trim", 2}, {NULL
}},
3854 /* Shorthand - if "columns" field not set, default to 1 column */
3855 static const name_and_columns_t iostat_bottom_labels
[][IOSTAT_MAX_LABELS
] =
3857 [IOS_DEFAULT
] = {{"alloc"}, {"free"}, {"read"}, {"write"}, {"read"},
3859 [IOS_LATENCY
] = {{"read"}, {"write"}, {"read"}, {"write"}, {"read"},
3860 {"write"}, {"read"}, {"write"}, {"wait"}, {"wait"}, {NULL
}},
3861 [IOS_QUEUES
] = {{"pend"}, {"activ"}, {"pend"}, {"activ"}, {"pend"},
3862 {"activ"}, {"pend"}, {"activ"}, {"pend"}, {"activ"},
3863 {"pend"}, {"activ"}, {NULL
}},
3864 [IOS_L_HISTO
] = {{"read"}, {"write"}, {"read"}, {"write"}, {"read"},
3865 {"write"}, {"read"}, {"write"}, {"scrub"}, {"trim"}, {NULL
}},
3866 [IOS_RQ_HISTO
] = {{"ind"}, {"agg"}, {"ind"}, {"agg"}, {"ind"}, {"agg"},
3867 {"ind"}, {"agg"}, {"ind"}, {"agg"}, {"ind"}, {"agg"}, {NULL
}},
3870 static const char *histo_to_title
[] = {
3871 [IOS_L_HISTO
] = "latency",
3872 [IOS_RQ_HISTO
] = "req_size",
3876 * Return the number of labels in a null-terminated name_and_columns_t
3881 label_array_len(const name_and_columns_t
*labels
)
3885 while (labels
[i
].name
)
3892 * Return the number of strings in a null-terminated string array.
3895 * const char foo[] = {"bar", "baz", NULL}
3900 str_array_len(const char *array
[])
3911 * Return a default column width for default/latency/queue columns. This does
3912 * not include histograms, which have their columns autosized.
3915 default_column_width(iostat_cbdata_t
*cb
, enum iostat_type type
)
3917 unsigned long column_width
= 5; /* Normal niceprint */
3918 static unsigned long widths
[] = {
3920 * Choose some sane default column sizes for printing the
3923 [IOS_DEFAULT
] = 15, /* 1PB capacity */
3924 [IOS_LATENCY
] = 10, /* 1B ns = 10sec */
3925 [IOS_QUEUES
] = 6, /* 1M queue entries */
3926 [IOS_L_HISTO
] = 10, /* 1B ns = 10sec */
3927 [IOS_RQ_HISTO
] = 6, /* 1M queue entries */
3931 column_width
= widths
[type
];
3933 return (column_width
);
3937 * Print the column labels, i.e:
3939 * capacity operations bandwidth
3940 * alloc free read write read write ...
3942 * If force_column_width is set, use it for the column width. If not set, use
3943 * the default column width.
3946 print_iostat_labels(iostat_cbdata_t
*cb
, unsigned int force_column_width
,
3947 const name_and_columns_t labels
[][IOSTAT_MAX_LABELS
])
3950 int text_start
, rw_column_width
, spaces_to_end
;
3951 uint64_t flags
= cb
->cb_flags
;
3953 unsigned int column_width
= force_column_width
;
3955 /* For each bit set in flags */
3956 for (f
= flags
; f
; f
&= ~(1ULL << idx
)) {
3957 idx
= lowbit64(f
) - 1;
3958 if (!force_column_width
)
3959 column_width
= default_column_width(cb
, idx
);
3960 /* Print our top labels centered over "read write" label. */
3961 for (i
= 0; i
< label_array_len(labels
[idx
]); i
++) {
3962 const char *name
= labels
[idx
][i
].name
;
3964 * We treat labels[][].columns == 0 as shorthand
3965 * for one column. It makes writing out the label
3966 * tables more concise.
3968 unsigned int columns
= MAX(1, labels
[idx
][i
].columns
);
3969 unsigned int slen
= strlen(name
);
3971 rw_column_width
= (column_width
* columns
) +
3972 (2 * (columns
- 1));
3974 text_start
= (int)((rw_column_width
) / columns
-
3979 printf(" "); /* Two spaces between columns */
3981 /* Space from beginning of column to label */
3982 for (s
= 0; s
< text_start
; s
++)
3987 /* Print space after label to end of column */
3988 spaces_to_end
= rw_column_width
- text_start
- slen
;
3989 if (spaces_to_end
< 0)
3992 for (s
= 0; s
< spaces_to_end
; s
++)
4000 * print_cmd_columns - Print custom column titles from -c
4002 * If the user specified the "zpool status|iostat -c" then print their custom
4003 * column titles in the header. For example, print_cmd_columns() would print
4004 * the " col1 col2" part of this:
4006 * $ zpool iostat -vc 'echo col1=val1; echo col2=val2'
4008 * capacity operations bandwidth
4009 * pool alloc free read write read write col1 col2
4010 * ---------- ----- ----- ----- ----- ----- ----- ---- ----
4011 * mypool 269K 1008M 0 0 107 946
4012 * mirror 269K 1008M 0 0 107 946
4013 * sdb - - 0 0 102 473 val1 val2
4014 * sdc - - 0 0 5 473 val1 val2
4015 * ---------- ----- ----- ----- ----- ----- ----- ---- ----
4018 print_cmd_columns(vdev_cmd_data_list_t
*vcdl
, int use_dashes
)
4021 vdev_cmd_data_t
*data
= &vcdl
->data
[0];
4023 if (vcdl
->count
== 0 || data
== NULL
)
4027 * Each vdev cmd should have the same column names unless the user did
4028 * something weird with their cmd. Just take the column names from the
4029 * first vdev and assume it works for all of them.
4031 for (i
= 0; i
< vcdl
->uniq_cols_cnt
; i
++) {
4034 for (j
= 0; j
< vcdl
->uniq_cols_width
[i
]; j
++)
4037 printf_color(ANSI_BOLD
, "%*s", vcdl
->uniq_cols_width
[i
],
4038 vcdl
->uniq_cols
[i
]);
4045 * Utility function to print out a line of dashes like:
4047 * -------------------------------- ----- ----- ----- ----- -----
4049 * ...or a dashed named-row line like:
4055 * @force_column_width If non-zero, use the value as the column width.
4056 * Otherwise use the default column widths.
4058 * @name: Print a dashed named-row line starting
4059 * with @name. Otherwise, print a regular
4063 print_iostat_dashes(iostat_cbdata_t
*cb
, unsigned int force_column_width
,
4067 unsigned int namewidth
;
4068 uint64_t flags
= cb
->cb_flags
;
4071 const name_and_columns_t
*labels
;
4075 if (cb
->cb_flags
& IOS_ANYHISTO_M
) {
4076 title
= histo_to_title
[IOS_HISTO_IDX(cb
->cb_flags
)];
4077 } else if (cb
->cb_vdev_names_count
) {
4083 namewidth
= MAX(MAX(strlen(title
), cb
->cb_namewidth
),
4084 name
? strlen(name
) : 0);
4088 printf("%-*s", namewidth
, name
);
4090 for (i
= 0; i
< namewidth
; i
++)
4094 /* For each bit in flags */
4095 for (f
= flags
; f
; f
&= ~(1ULL << idx
)) {
4096 unsigned int column_width
;
4097 idx
= lowbit64(f
) - 1;
4098 if (force_column_width
)
4099 column_width
= force_column_width
;
4101 column_width
= default_column_width(cb
, idx
);
4103 labels
= iostat_bottom_labels
[idx
];
4104 for (i
= 0; i
< label_array_len(labels
); i
++) {
4106 printf(" %*s-", column_width
- 1, " ");
4108 printf(" %.*s", column_width
,
4109 "--------------------");
4116 print_iostat_separator_impl(iostat_cbdata_t
*cb
,
4117 unsigned int force_column_width
)
4119 print_iostat_dashes(cb
, force_column_width
, NULL
);
4123 print_iostat_separator(iostat_cbdata_t
*cb
)
4125 print_iostat_separator_impl(cb
, 0);
4129 print_iostat_header_impl(iostat_cbdata_t
*cb
, unsigned int force_column_width
,
4130 const char *histo_vdev_name
)
4132 unsigned int namewidth
;
4135 if (cb
->cb_flags
& IOS_ANYHISTO_M
) {
4136 title
= histo_to_title
[IOS_HISTO_IDX(cb
->cb_flags
)];
4137 } else if (cb
->cb_vdev_names_count
) {
4143 namewidth
= MAX(MAX(strlen(title
), cb
->cb_namewidth
),
4144 histo_vdev_name
? strlen(histo_vdev_name
) : 0);
4146 if (histo_vdev_name
)
4147 printf("%-*s", namewidth
, histo_vdev_name
);
4149 printf("%*s", namewidth
, "");
4152 print_iostat_labels(cb
, force_column_width
, iostat_top_labels
);
4155 printf("%-*s", namewidth
, title
);
4157 print_iostat_labels(cb
, force_column_width
, iostat_bottom_labels
);
4158 if (cb
->vcdl
!= NULL
)
4159 print_cmd_columns(cb
->vcdl
, 0);
4163 print_iostat_separator_impl(cb
, force_column_width
);
4165 if (cb
->vcdl
!= NULL
)
4166 print_cmd_columns(cb
->vcdl
, 1);
4172 print_iostat_header(iostat_cbdata_t
*cb
)
4174 print_iostat_header_impl(cb
, 0, NULL
);
4179 * Display a single statistic.
4182 print_one_stat(uint64_t value
, enum zfs_nicenum_format format
,
4183 unsigned int column_size
, boolean_t scripted
)
4187 zfs_nicenum_format(value
, buf
, sizeof (buf
), format
);
4190 printf("\t%s", buf
);
4192 printf(" %*s", column_size
, buf
);
4196 * Calculate the default vdev stats
4198 * Subtract oldvs from newvs, apply a scaling factor, and save the resulting
4199 * stats into calcvs.
4202 calc_default_iostats(vdev_stat_t
*oldvs
, vdev_stat_t
*newvs
,
4203 vdev_stat_t
*calcvs
)
4207 memcpy(calcvs
, newvs
, sizeof (*calcvs
));
4208 for (i
= 0; i
< ARRAY_SIZE(calcvs
->vs_ops
); i
++)
4209 calcvs
->vs_ops
[i
] = (newvs
->vs_ops
[i
] - oldvs
->vs_ops
[i
]);
4211 for (i
= 0; i
< ARRAY_SIZE(calcvs
->vs_bytes
); i
++)
4212 calcvs
->vs_bytes
[i
] = (newvs
->vs_bytes
[i
] - oldvs
->vs_bytes
[i
]);
4216 * Internal representation of the extended iostats data.
4218 * The extended iostat stats are exported in nvlists as either uint64_t arrays
4219 * or single uint64_t's. We make both look like arrays to make them easier
4220 * to process. In order to make single uint64_t's look like arrays, we set
4221 * __data to the stat data, and then set *data = &__data with count = 1. Then,
4222 * we can just use *data and count.
4226 uint_t count
; /* Number of entries in data[] */
4227 uint64_t __data
; /* Only used when data is a single uint64_t */
4231 stat_histo_max(struct stat_array
*nva
, unsigned int len
)
4235 for (i
= 0; i
< len
; i
++)
4236 max
= MAX(max
, array64_max(nva
[i
].data
, nva
[i
].count
));
4242 * Helper function to lookup a uint64_t array or uint64_t value and store its
4243 * data as a stat_array. If the nvpair is a single uint64_t value, then we make
4244 * it look like a one element array to make it easier to process.
4247 nvpair64_to_stat_array(nvlist_t
*nvl
, const char *name
,
4248 struct stat_array
*nva
)
4253 verify(nvlist_lookup_nvpair(nvl
, name
, &tmp
) == 0);
4254 switch (nvpair_type(tmp
)) {
4255 case DATA_TYPE_UINT64_ARRAY
:
4256 ret
= nvpair_value_uint64_array(tmp
, &nva
->data
, &nva
->count
);
4258 case DATA_TYPE_UINT64
:
4259 ret
= nvpair_value_uint64(tmp
, &nva
->__data
);
4260 nva
->data
= &nva
->__data
;
4264 /* Not a uint64_t */
4273 * Given a list of nvlist names, look up the extended stats in newnv and oldnv,
4274 * subtract them, and return the results in a newly allocated stat_array.
4275 * You must free the returned array after you are done with it with
4276 * free_calc_stats().
4278 * Additionally, you can set "oldnv" to NULL if you simply want the newnv
4281 static struct stat_array
*
4282 calc_and_alloc_stats_ex(const char **names
, unsigned int len
, nvlist_t
*oldnv
,
4285 nvlist_t
*oldnvx
= NULL
, *newnvx
;
4286 struct stat_array
*oldnva
, *newnva
, *calcnva
;
4288 unsigned int alloc_size
= (sizeof (struct stat_array
)) * len
;
4290 /* Extract our extended stats nvlist from the main list */
4291 verify(nvlist_lookup_nvlist(newnv
, ZPOOL_CONFIG_VDEV_STATS_EX
,
4294 verify(nvlist_lookup_nvlist(oldnv
, ZPOOL_CONFIG_VDEV_STATS_EX
,
4298 newnva
= safe_malloc(alloc_size
);
4299 oldnva
= safe_malloc(alloc_size
);
4300 calcnva
= safe_malloc(alloc_size
);
4302 for (j
= 0; j
< len
; j
++) {
4303 verify(nvpair64_to_stat_array(newnvx
, names
[j
],
4305 calcnva
[j
].count
= newnva
[j
].count
;
4306 alloc_size
= calcnva
[j
].count
* sizeof (calcnva
[j
].data
[0]);
4307 calcnva
[j
].data
= safe_malloc(alloc_size
);
4308 memcpy(calcnva
[j
].data
, newnva
[j
].data
, alloc_size
);
4311 verify(nvpair64_to_stat_array(oldnvx
, names
[j
],
4313 for (i
= 0; i
< oldnva
[j
].count
; i
++)
4314 calcnva
[j
].data
[i
] -= oldnva
[j
].data
[i
];
4323 free_calc_stats(struct stat_array
*nva
, unsigned int len
)
4326 for (i
= 0; i
< len
; i
++)
4333 print_iostat_histo(struct stat_array
*nva
, unsigned int len
,
4334 iostat_cbdata_t
*cb
, unsigned int column_width
, unsigned int namewidth
,
4340 enum zfs_nicenum_format format
;
4341 unsigned int buckets
;
4342 unsigned int start_bucket
;
4345 format
= ZFS_NICENUM_RAW
;
4347 format
= ZFS_NICENUM_1024
;
4349 /* All these histos are the same size, so just use nva[0].count */
4350 buckets
= nva
[0].count
;
4352 if (cb
->cb_flags
& IOS_RQ_HISTO_M
) {
4353 /* Start at 512 - req size should never be lower than this */
4359 for (j
= start_bucket
; j
< buckets
; j
++) {
4360 /* Print histogram bucket label */
4361 if (cb
->cb_flags
& IOS_L_HISTO_M
) {
4362 /* Ending range of this bucket */
4363 val
= (1UL << (j
+ 1)) - 1;
4364 zfs_nicetime(val
, buf
, sizeof (buf
));
4366 /* Request size (starting range of bucket) */
4368 zfs_nicenum(val
, buf
, sizeof (buf
));
4371 if (cb
->cb_scripted
)
4372 printf("%llu", (u_longlong_t
)val
);
4374 printf("%-*s", namewidth
, buf
);
4376 /* Print the values on the line */
4377 for (i
= 0; i
< len
; i
++) {
4378 print_one_stat(nva
[i
].data
[j
] * scale
, format
,
4379 column_width
, cb
->cb_scripted
);
4386 print_solid_separator(unsigned int length
)
4394 print_iostat_histos(iostat_cbdata_t
*cb
, nvlist_t
*oldnv
,
4395 nvlist_t
*newnv
, double scale
, const char *name
)
4397 unsigned int column_width
;
4398 unsigned int namewidth
;
4399 unsigned int entire_width
;
4400 enum iostat_type type
;
4401 struct stat_array
*nva
;
4403 unsigned int names_len
;
4405 /* What type of histo are we? */
4406 type
= IOS_HISTO_IDX(cb
->cb_flags
);
4408 /* Get NULL-terminated array of nvlist names for our histo */
4409 names
= vsx_type_to_nvlist
[type
];
4410 names_len
= str_array_len(names
); /* num of names */
4412 nva
= calc_and_alloc_stats_ex(names
, names_len
, oldnv
, newnv
);
4414 if (cb
->cb_literal
) {
4415 column_width
= MAX(5,
4416 (unsigned int) log10(stat_histo_max(nva
, names_len
)) + 1);
4421 namewidth
= MAX(cb
->cb_namewidth
,
4422 strlen(histo_to_title
[IOS_HISTO_IDX(cb
->cb_flags
)]));
4425 * Calculate the entire line width of what we're printing. The
4426 * +2 is for the two spaces between columns:
4430 /* |___| <---------- column_width */
4432 /* |__________| <--- entire_width */
4434 entire_width
= namewidth
+ (column_width
+ 2) *
4435 label_array_len(iostat_bottom_labels
[type
]);
4437 if (cb
->cb_scripted
)
4438 printf("%s\n", name
);
4440 print_iostat_header_impl(cb
, column_width
, name
);
4442 print_iostat_histo(nva
, names_len
, cb
, column_width
,
4445 free_calc_stats(nva
, names_len
);
4446 if (!cb
->cb_scripted
)
4447 print_solid_separator(entire_width
);
4451 * Calculate the average latency of a power-of-two latency histogram
4454 single_histo_average(uint64_t *histo
, unsigned int buckets
)
4457 uint64_t count
= 0, total
= 0;
4459 for (i
= 0; i
< buckets
; i
++) {
4461 * Our buckets are power-of-two latency ranges. Use the
4462 * midpoint latency of each bucket to calculate the average.
4470 if (histo
[i
] != 0) {
4471 total
+= histo
[i
] * (((1UL << i
) + ((1UL << i
)/2)));
4476 /* Prevent divide by zero */
4477 return (count
== 0 ? 0 : total
/ count
);
4481 print_iostat_queues(iostat_cbdata_t
*cb
, nvlist_t
*oldnv
,
4486 const char *names
[] = {
4487 ZPOOL_CONFIG_VDEV_SYNC_R_PEND_QUEUE
,
4488 ZPOOL_CONFIG_VDEV_SYNC_R_ACTIVE_QUEUE
,
4489 ZPOOL_CONFIG_VDEV_SYNC_W_PEND_QUEUE
,
4490 ZPOOL_CONFIG_VDEV_SYNC_W_ACTIVE_QUEUE
,
4491 ZPOOL_CONFIG_VDEV_ASYNC_R_PEND_QUEUE
,
4492 ZPOOL_CONFIG_VDEV_ASYNC_R_ACTIVE_QUEUE
,
4493 ZPOOL_CONFIG_VDEV_ASYNC_W_PEND_QUEUE
,
4494 ZPOOL_CONFIG_VDEV_ASYNC_W_ACTIVE_QUEUE
,
4495 ZPOOL_CONFIG_VDEV_SCRUB_PEND_QUEUE
,
4496 ZPOOL_CONFIG_VDEV_SCRUB_ACTIVE_QUEUE
,
4497 ZPOOL_CONFIG_VDEV_TRIM_PEND_QUEUE
,
4498 ZPOOL_CONFIG_VDEV_TRIM_ACTIVE_QUEUE
,
4501 struct stat_array
*nva
;
4503 unsigned int column_width
= default_column_width(cb
, IOS_QUEUES
);
4504 enum zfs_nicenum_format format
;
4506 nva
= calc_and_alloc_stats_ex(names
, ARRAY_SIZE(names
), NULL
, newnv
);
4509 format
= ZFS_NICENUM_RAW
;
4511 format
= ZFS_NICENUM_1024
;
4513 for (i
= 0; i
< ARRAY_SIZE(names
); i
++) {
4514 val
= nva
[i
].data
[0];
4515 print_one_stat(val
, format
, column_width
, cb
->cb_scripted
);
4518 free_calc_stats(nva
, ARRAY_SIZE(names
));
4522 print_iostat_latency(iostat_cbdata_t
*cb
, nvlist_t
*oldnv
,
4527 const char *names
[] = {
4528 ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO
,
4529 ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO
,
4530 ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO
,
4531 ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO
,
4532 ZPOOL_CONFIG_VDEV_SYNC_R_LAT_HISTO
,
4533 ZPOOL_CONFIG_VDEV_SYNC_W_LAT_HISTO
,
4534 ZPOOL_CONFIG_VDEV_ASYNC_R_LAT_HISTO
,
4535 ZPOOL_CONFIG_VDEV_ASYNC_W_LAT_HISTO
,
4536 ZPOOL_CONFIG_VDEV_SCRUB_LAT_HISTO
,
4537 ZPOOL_CONFIG_VDEV_TRIM_LAT_HISTO
,
4539 struct stat_array
*nva
;
4541 unsigned int column_width
= default_column_width(cb
, IOS_LATENCY
);
4542 enum zfs_nicenum_format format
;
4544 nva
= calc_and_alloc_stats_ex(names
, ARRAY_SIZE(names
), oldnv
, newnv
);
4547 format
= ZFS_NICENUM_RAWTIME
;
4549 format
= ZFS_NICENUM_TIME
;
4551 /* Print our avg latencies on the line */
4552 for (i
= 0; i
< ARRAY_SIZE(names
); i
++) {
4553 /* Compute average latency for a latency histo */
4554 val
= single_histo_average(nva
[i
].data
, nva
[i
].count
);
4555 print_one_stat(val
, format
, column_width
, cb
->cb_scripted
);
4557 free_calc_stats(nva
, ARRAY_SIZE(names
));
4561 * Print default statistics (capacity/operations/bandwidth)
4564 print_iostat_default(vdev_stat_t
*vs
, iostat_cbdata_t
*cb
, double scale
)
4566 unsigned int column_width
= default_column_width(cb
, IOS_DEFAULT
);
4567 enum zfs_nicenum_format format
;
4568 char na
; /* char to print for "not applicable" values */
4570 if (cb
->cb_literal
) {
4571 format
= ZFS_NICENUM_RAW
;
4574 format
= ZFS_NICENUM_1024
;
4578 /* only toplevel vdevs have capacity stats */
4579 if (vs
->vs_space
== 0) {
4580 if (cb
->cb_scripted
)
4581 printf("\t%c\t%c", na
, na
);
4583 printf(" %*c %*c", column_width
, na
, column_width
,
4586 print_one_stat(vs
->vs_alloc
, format
, column_width
,
4588 print_one_stat(vs
->vs_space
- vs
->vs_alloc
, format
,
4589 column_width
, cb
->cb_scripted
);
4592 print_one_stat((uint64_t)(vs
->vs_ops
[ZIO_TYPE_READ
] * scale
),
4593 format
, column_width
, cb
->cb_scripted
);
4594 print_one_stat((uint64_t)(vs
->vs_ops
[ZIO_TYPE_WRITE
] * scale
),
4595 format
, column_width
, cb
->cb_scripted
);
4596 print_one_stat((uint64_t)(vs
->vs_bytes
[ZIO_TYPE_READ
] * scale
),
4597 format
, column_width
, cb
->cb_scripted
);
4598 print_one_stat((uint64_t)(vs
->vs_bytes
[ZIO_TYPE_WRITE
] * scale
),
4599 format
, column_width
, cb
->cb_scripted
);
4602 static const char *class_name
[] = {
4603 VDEV_ALLOC_BIAS_DEDUP
,
4604 VDEV_ALLOC_BIAS_SPECIAL
,
4605 VDEV_ALLOC_CLASS_LOGS
4609 * Print out all the statistics for the given vdev. This can either be the
4610 * toplevel configuration, or called recursively. If 'name' is NULL, then this
4611 * is a verbose output, and we don't want to display the toplevel pool stats.
4613 * Returns the number of stat lines printed.
4616 print_vdev_stats(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*oldnv
,
4617 nvlist_t
*newnv
, iostat_cbdata_t
*cb
, int depth
)
4619 nvlist_t
**oldchild
, **newchild
;
4620 uint_t c
, children
, oldchildren
;
4621 vdev_stat_t
*oldvs
, *newvs
, *calcvs
;
4622 vdev_stat_t zerovs
= { 0 };
4629 if (strcmp(name
, VDEV_TYPE_INDIRECT
) == 0)
4632 calcvs
= safe_malloc(sizeof (*calcvs
));
4634 if (oldnv
!= NULL
) {
4635 verify(nvlist_lookup_uint64_array(oldnv
,
4636 ZPOOL_CONFIG_VDEV_STATS
, (uint64_t **)&oldvs
, &c
) == 0);
4641 /* Do we only want to see a specific vdev? */
4642 for (i
= 0; i
< cb
->cb_vdev_names_count
; i
++) {
4643 /* Yes we do. Is this the vdev? */
4644 if (strcmp(name
, cb
->cb_vdev_names
[i
]) == 0) {
4646 * This is our vdev. Since it is the only vdev we
4647 * will be displaying, make depth = 0 so that it
4648 * doesn't get indented.
4655 if (cb
->cb_vdev_names_count
&& (i
== cb
->cb_vdev_names_count
)) {
4656 /* Couldn't match the name */
4661 verify(nvlist_lookup_uint64_array(newnv
, ZPOOL_CONFIG_VDEV_STATS
,
4662 (uint64_t **)&newvs
, &c
) == 0);
4665 * Print the vdev name unless it's is a histogram. Histograms
4666 * display the vdev name in the header itself.
4668 if (!(cb
->cb_flags
& IOS_ANYHISTO_M
)) {
4669 if (cb
->cb_scripted
) {
4672 if (strlen(name
) + depth
> cb
->cb_namewidth
)
4673 (void) printf("%*s%s", depth
, "", name
);
4675 (void) printf("%*s%s%*s", depth
, "", name
,
4676 (int)(cb
->cb_namewidth
- strlen(name
) -
4681 /* Calculate our scaling factor */
4682 tdelta
= newvs
->vs_timestamp
- oldvs
->vs_timestamp
;
4683 if ((oldvs
->vs_timestamp
== 0) && (cb
->cb_flags
& IOS_ANYHISTO_M
)) {
4685 * If we specify printing histograms with no time interval, then
4686 * print the histogram numbers over the entire lifetime of the
4694 scale
= (double)NANOSEC
/ tdelta
;
4697 if (cb
->cb_flags
& IOS_DEFAULT_M
) {
4698 calc_default_iostats(oldvs
, newvs
, calcvs
);
4699 print_iostat_default(calcvs
, cb
, scale
);
4701 if (cb
->cb_flags
& IOS_LATENCY_M
)
4702 print_iostat_latency(cb
, oldnv
, newnv
);
4703 if (cb
->cb_flags
& IOS_QUEUES_M
)
4704 print_iostat_queues(cb
, oldnv
, newnv
);
4705 if (cb
->cb_flags
& IOS_ANYHISTO_M
) {
4707 print_iostat_histos(cb
, oldnv
, newnv
, scale
, name
);
4710 if (cb
->vcdl
!= NULL
) {
4712 if (nvlist_lookup_string(newnv
, ZPOOL_CONFIG_PATH
,
4715 zpool_print_cmd(cb
->vcdl
, zpool_get_name(zhp
), path
);
4719 if (!(cb
->cb_flags
& IOS_ANYHISTO_M
))
4728 if (!cb
->cb_verbose
)
4731 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_CHILDREN
,
4732 &newchild
, &children
) != 0)
4736 if (nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_CHILDREN
,
4737 &oldchild
, &oldchildren
) != 0)
4740 children
= MIN(oldchildren
, children
);
4744 * print normal top-level devices
4746 for (c
= 0; c
< children
; c
++) {
4747 uint64_t ishole
= B_FALSE
, islog
= B_FALSE
;
4749 (void) nvlist_lookup_uint64(newchild
[c
], ZPOOL_CONFIG_IS_HOLE
,
4752 (void) nvlist_lookup_uint64(newchild
[c
], ZPOOL_CONFIG_IS_LOG
,
4755 if (ishole
|| islog
)
4758 if (nvlist_exists(newchild
[c
], ZPOOL_CONFIG_ALLOCATION_BIAS
))
4761 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
4763 ret
+= print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
] : NULL
,
4764 newchild
[c
], cb
, depth
+ 2);
4769 * print all other top-level devices
4771 for (uint_t n
= 0; n
< 3; n
++) {
4772 boolean_t printed
= B_FALSE
;
4774 for (c
= 0; c
< children
; c
++) {
4775 uint64_t islog
= B_FALSE
;
4779 (void) nvlist_lookup_uint64(newchild
[c
],
4780 ZPOOL_CONFIG_IS_LOG
, &islog
);
4782 bias
= VDEV_ALLOC_CLASS_LOGS
;
4784 (void) nvlist_lookup_string(newchild
[c
],
4785 ZPOOL_CONFIG_ALLOCATION_BIAS
, &bias
);
4786 (void) nvlist_lookup_string(newchild
[c
],
4787 ZPOOL_CONFIG_TYPE
, &type
);
4789 if (bias
== NULL
|| strcmp(bias
, class_name
[n
]) != 0)
4791 if (!islog
&& strcmp(type
, VDEV_TYPE_INDIRECT
) == 0)
4795 if ((!(cb
->cb_flags
& IOS_ANYHISTO_M
)) &&
4796 !cb
->cb_scripted
&& !cb
->cb_vdev_names
) {
4797 print_iostat_dashes(cb
, 0,
4804 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
4806 ret
+= print_vdev_stats(zhp
, vname
, oldnv
?
4807 oldchild
[c
] : NULL
, newchild
[c
], cb
, depth
+ 2);
4813 * Include level 2 ARC devices in iostat output
4815 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_L2CACHE
,
4816 &newchild
, &children
) != 0)
4820 if (nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_L2CACHE
,
4821 &oldchild
, &oldchildren
) != 0)
4824 children
= MIN(oldchildren
, children
);
4828 if ((!(cb
->cb_flags
& IOS_ANYHISTO_M
)) && !cb
->cb_scripted
&&
4829 !cb
->cb_vdev_names
) {
4830 print_iostat_dashes(cb
, 0, "cache");
4834 for (c
= 0; c
< children
; c
++) {
4835 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
4837 ret
+= print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
]
4838 : NULL
, newchild
[c
], cb
, depth
+ 2);
4847 refresh_iostat(zpool_handle_t
*zhp
, void *data
)
4849 iostat_cbdata_t
*cb
= data
;
4853 * If the pool has disappeared, remove it from the list and continue.
4855 if (zpool_refresh_stats(zhp
, &missing
) != 0)
4859 pool_list_remove(cb
->cb_list
, zhp
);
4865 * Callback to print out the iostats for the given pool.
4868 print_iostat(zpool_handle_t
*zhp
, void *data
)
4870 iostat_cbdata_t
*cb
= data
;
4871 nvlist_t
*oldconfig
, *newconfig
;
4872 nvlist_t
*oldnvroot
, *newnvroot
;
4875 newconfig
= zpool_get_config(zhp
, &oldconfig
);
4877 if (cb
->cb_iteration
== 1)
4880 verify(nvlist_lookup_nvlist(newconfig
, ZPOOL_CONFIG_VDEV_TREE
,
4883 if (oldconfig
== NULL
)
4886 verify(nvlist_lookup_nvlist(oldconfig
, ZPOOL_CONFIG_VDEV_TREE
,
4889 ret
= print_vdev_stats(zhp
, zpool_get_name(zhp
), oldnvroot
, newnvroot
,
4891 if ((ret
!= 0) && !(cb
->cb_flags
& IOS_ANYHISTO_M
) &&
4892 !cb
->cb_scripted
&& cb
->cb_verbose
&& !cb
->cb_vdev_names_count
) {
4893 print_iostat_separator(cb
);
4894 if (cb
->vcdl
!= NULL
) {
4895 print_cmd_columns(cb
->vcdl
, 1);
4910 if (isatty(STDOUT_FILENO
)) {
4911 error
= ioctl(STDOUT_FILENO
, TIOCGWINSZ
, &ws
);
4913 columns
= ws
.ws_col
;
4922 * Return the required length of the pool/vdev name column. The minimum
4923 * allowed width and output formatting flags must be provided.
4926 get_namewidth(zpool_handle_t
*zhp
, int min_width
, int flags
, boolean_t verbose
)
4928 nvlist_t
*config
, *nvroot
;
4929 int width
= min_width
;
4931 if ((config
= zpool_get_config(zhp
, NULL
)) != NULL
) {
4932 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
4934 unsigned int poolname_len
= strlen(zpool_get_name(zhp
));
4935 if (verbose
== B_FALSE
) {
4936 width
= MAX(poolname_len
, min_width
);
4938 width
= MAX(poolname_len
,
4939 max_width(zhp
, nvroot
, 0, min_width
, flags
));
4947 * Parse the input string, get the 'interval' and 'count' value if there is one.
4950 get_interval_count(int *argcp
, char **argv
, float *iv
,
4954 unsigned long count
= 0;
4958 * Determine if the last argument is an integer or a pool name
4960 if (argc
> 0 && zfs_isnumber(argv
[argc
- 1])) {
4964 interval
= strtof(argv
[argc
- 1], &end
);
4966 if (*end
== '\0' && errno
== 0) {
4967 if (interval
== 0) {
4968 (void) fprintf(stderr
, gettext("interval "
4969 "cannot be zero\n"));
4973 * Ignore the last parameter
4978 * If this is not a valid number, just plow on. The
4979 * user will get a more informative error message later
4987 * If the last argument is also an integer, then we have both a count
4990 if (argc
> 0 && zfs_isnumber(argv
[argc
- 1])) {
4995 interval
= strtof(argv
[argc
- 1], &end
);
4997 if (*end
== '\0' && errno
== 0) {
4998 if (interval
== 0) {
4999 (void) fprintf(stderr
, gettext("interval "
5000 "cannot be zero\n"));
5005 * Ignore the last parameter
5019 get_timestamp_arg(char c
)
5022 timestamp_fmt
= UDATE
;
5024 timestamp_fmt
= DDATE
;
5030 * Return stat flags that are supported by all pools by both the module and
5031 * zpool iostat. "*data" should be initialized to all 0xFFs before running.
5032 * It will get ANDed down until only the flags that are supported on all pools
5036 get_stat_flags_cb(zpool_handle_t
*zhp
, void *data
)
5038 uint64_t *mask
= data
;
5039 nvlist_t
*config
, *nvroot
, *nvx
;
5043 config
= zpool_get_config(zhp
, NULL
);
5044 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
5047 /* Default stats are always supported, but for completeness.. */
5048 if (nvlist_exists(nvroot
, ZPOOL_CONFIG_VDEV_STATS
))
5049 flags
|= IOS_DEFAULT_M
;
5051 /* Get our extended stats nvlist from the main list */
5052 if (nvlist_lookup_nvlist(nvroot
, ZPOOL_CONFIG_VDEV_STATS_EX
,
5055 * No extended stats; they're probably running an older
5056 * module. No big deal, we support that too.
5061 /* For each extended stat, make sure all its nvpairs are supported */
5062 for (j
= 0; j
< ARRAY_SIZE(vsx_type_to_nvlist
); j
++) {
5063 if (!vsx_type_to_nvlist
[j
][0])
5066 /* Start off by assuming the flag is supported, then check */
5067 flags
|= (1ULL << j
);
5068 for (i
= 0; vsx_type_to_nvlist
[j
][i
]; i
++) {
5069 if (!nvlist_exists(nvx
, vsx_type_to_nvlist
[j
][i
])) {
5070 /* flag isn't supported */
5071 flags
= flags
& ~(1ULL << j
);
5077 *mask
= *mask
& flags
;
5082 * Return a bitmask of stats that are supported on all pools by both the module
5086 get_stat_flags(zpool_list_t
*list
)
5091 * get_stat_flags_cb() will lop off bits from "mask" until only the
5092 * flags that are supported on all pools remain.
5094 pool_list_iter(list
, B_FALSE
, get_stat_flags_cb
, &mask
);
5099 * Return 1 if cb_data->cb_vdev_names[0] is this vdev's name, 0 otherwise.
5102 is_vdev_cb(zpool_handle_t
*zhp
, nvlist_t
*nv
, void *cb_data
)
5104 iostat_cbdata_t
*cb
= cb_data
;
5108 name
= zpool_vdev_name(g_zfs
, zhp
, nv
, cb
->cb_name_flags
);
5110 if (strcmp(name
, cb
->cb_vdev_names
[0]) == 0)
5111 ret
= 1; /* match */
5118 * Returns 1 if cb_data->cb_vdev_names[0] is a vdev name, 0 otherwise.
5121 is_vdev(zpool_handle_t
*zhp
, void *cb_data
)
5123 return (for_each_vdev(zhp
, is_vdev_cb
, cb_data
));
5127 * Check if vdevs are in a pool
5129 * Return 1 if all argv[] strings are vdev names in pool "pool_name". Otherwise
5130 * return 0. If pool_name is NULL, then search all pools.
5133 are_vdevs_in_pool(int argc
, char **argv
, char *pool_name
,
5134 iostat_cbdata_t
*cb
)
5141 if ((argc
== 0) || !*argv
)
5147 /* Temporarily hijack cb_vdev_names for a second... */
5148 tmp_name
= cb
->cb_vdev_names
;
5150 /* Go though our list of prospective vdev names */
5151 for (i
= 0; i
< argc
; i
++) {
5152 cb
->cb_vdev_names
= argv
+ i
;
5154 /* Is this name a vdev in our pools? */
5155 ret
= for_each_pool(pool_count
, &pool_name
, B_TRUE
, NULL
,
5156 B_FALSE
, is_vdev
, cb
);
5163 cb
->cb_vdev_names
= tmp_name
;
5169 is_pool_cb(zpool_handle_t
*zhp
, void *data
)
5172 if (strcmp(name
, zpool_get_name(zhp
)) == 0)
5179 * Do we have a pool named *name? If so, return 1, otherwise 0.
5184 return (for_each_pool(0, NULL
, B_TRUE
, NULL
, B_FALSE
, is_pool_cb
,
5188 /* Are all our argv[] strings pool names? If so return 1, 0 otherwise. */
5190 are_all_pools(int argc
, char **argv
)
5192 if ((argc
== 0) || !*argv
)
5196 if (!is_pool(argv
[argc
]))
5203 * Helper function to print out vdev/pool names we can't resolve. Used for an
5207 error_list_unresolved_vdevs(int argc
, char **argv
, char *pool_name
,
5208 iostat_cbdata_t
*cb
)
5213 for (i
= 0; i
< argc
; i
++) {
5217 str
= gettext("pool");
5218 else if (are_vdevs_in_pool(1, &name
, pool_name
, cb
))
5219 str
= gettext("vdev in this pool");
5220 else if (are_vdevs_in_pool(1, &name
, NULL
, cb
))
5221 str
= gettext("vdev in another pool");
5223 str
= gettext("unknown");
5225 fprintf(stderr
, "\t%s (%s)\n", name
, str
);
5230 * Same as get_interval_count(), but with additional checks to not misinterpret
5231 * guids as interval/count values. Assumes VDEV_NAME_GUID is set in
5235 get_interval_count_filter_guids(int *argc
, char **argv
, float *interval
,
5236 unsigned long *count
, iostat_cbdata_t
*cb
)
5238 char **tmpargv
= argv
;
5239 int argc_for_interval
= 0;
5241 /* Is the last arg an interval value? Or a guid? */
5242 if (*argc
>= 1 && !are_vdevs_in_pool(1, &argv
[*argc
- 1], NULL
, cb
)) {
5244 * The last arg is not a guid, so it's probably an
5247 argc_for_interval
++;
5250 !are_vdevs_in_pool(1, &argv
[*argc
- 2], NULL
, cb
)) {
5252 * The 2nd to last arg is not a guid, so it's probably
5253 * an interval value.
5255 argc_for_interval
++;
5259 /* Point to our list of possible intervals */
5260 tmpargv
= &argv
[*argc
- argc_for_interval
];
5262 *argc
= *argc
- argc_for_interval
;
5263 get_interval_count(&argc_for_interval
, tmpargv
,
5268 * Floating point sleep(). Allows you to pass in a floating point value for
5274 struct timespec req
;
5275 req
.tv_sec
= floor(sec
);
5276 req
.tv_nsec
= (sec
- (float)req
.tv_sec
) * NANOSEC
;
5277 nanosleep(&req
, NULL
);
5281 * Terminal height, in rows. Returns -1 if stdout is not connected to a TTY or
5282 * if we were unable to determine its size.
5285 terminal_height(void)
5289 if (isatty(STDOUT_FILENO
) == 0)
5292 if (ioctl(STDOUT_FILENO
, TIOCGWINSZ
, &win
) != -1 && win
.ws_row
> 0)
5293 return (win
.ws_row
);
5299 * Run one of the zpool status/iostat -c scripts with the help (-h) option and
5302 * name: Short name of the script ('iostat').
5303 * path: Full path to the script ('/usr/local/etc/zfs/zpool.d/iostat');
5306 print_zpool_script_help(char *name
, char *path
)
5308 char *argv
[] = {path
, "-h", NULL
};
5309 char **lines
= NULL
;
5313 rc
= libzfs_run_process_get_stdout_nopath(path
, argv
, NULL
, &lines
,
5315 if (rc
!= 0 || lines
== NULL
|| lines_cnt
<= 0) {
5317 libzfs_free_str_array(lines
, lines_cnt
);
5321 for (int i
= 0; i
< lines_cnt
; i
++)
5322 if (!is_blank_str(lines
[i
]))
5323 printf(" %-14s %s\n", name
, lines
[i
]);
5325 libzfs_free_str_array(lines
, lines_cnt
);
5329 * Go though the zpool status/iostat -c scripts in the user's path, run their
5330 * help option (-h), and print out the results.
5333 print_zpool_dir_scripts(char *dirpath
)
5337 char fullpath
[MAXPATHLEN
];
5338 struct stat dir_stat
;
5340 if ((dir
= opendir(dirpath
)) != NULL
) {
5341 /* print all the files and directories within directory */
5342 while ((ent
= readdir(dir
)) != NULL
) {
5343 sprintf(fullpath
, "%s/%s", dirpath
, ent
->d_name
);
5345 /* Print the scripts */
5346 if (stat(fullpath
, &dir_stat
) == 0)
5347 if (dir_stat
.st_mode
& S_IXUSR
&&
5348 S_ISREG(dir_stat
.st_mode
))
5349 print_zpool_script_help(ent
->d_name
,
5357 * Print out help text for all zpool status/iostat -c scripts.
5360 print_zpool_script_list(char *subcommand
)
5364 printf(gettext("Available 'zpool %s -c' commands:\n"), subcommand
);
5366 sp
= zpool_get_cmd_search_path();
5370 dir
= strtok(sp
, ":");
5371 while (dir
!= NULL
) {
5372 print_zpool_dir_scripts(dir
);
5373 dir
= strtok(NULL
, ":");
5380 * Set the minimum pool/vdev name column width. The width must be at least 10,
5381 * but may be as large as the column width - 42 so it still fits on one line.
5382 * NOTE: 42 is the width of the default capacity/operations/bandwidth output
5385 get_namewidth_iostat(zpool_handle_t
*zhp
, void *data
)
5387 iostat_cbdata_t
*cb
= data
;
5388 int width
, available_width
;
5391 * get_namewidth() returns the maximum width of any name in that column
5392 * for any pool/vdev/device line that will be output.
5394 width
= get_namewidth(zhp
, cb
->cb_namewidth
, cb
->cb_name_flags
,
5398 * The width we are calculating is the width of the header and also the
5399 * padding width for names that are less than maximum width. The stats
5400 * take up 42 characters, so the width available for names is:
5402 available_width
= get_columns() - 42;
5405 * If the maximum width fits on a screen, then great! Make everything
5406 * line up by justifying all lines to the same width. If that max
5407 * width is larger than what's available, the name plus stats won't fit
5408 * on one line, and justifying to that width would cause every line to
5409 * wrap on the screen. We only want lines with long names to wrap.
5410 * Limit the padding to what won't wrap.
5412 if (width
> available_width
)
5413 width
= available_width
;
5416 * And regardless of whatever the screen width is (get_columns can
5417 * return 0 if the width is not known or less than 42 for a narrow
5418 * terminal) have the width be a minimum of 10.
5423 /* Save the calculated width */
5424 cb
->cb_namewidth
= width
;
5430 * zpool iostat [[-c [script1,script2,...]] [-lq]|[-rw]] [-ghHLpPvy] [-n name]
5431 * [-T d|u] [[ pool ...]|[pool vdev ...]|[vdev ...]]
5432 * [interval [count]]
5434 * -c CMD For each vdev, run command CMD
5435 * -g Display guid for individual vdev name.
5436 * -L Follow links when resolving vdev path name.
5437 * -P Display full path for vdev name.
5438 * -v Display statistics for individual vdevs
5440 * -p Display values in parsable (exact) format.
5441 * -H Scripted mode. Don't display headers, and separate properties
5443 * -l Display average latency
5444 * -q Display queue depths
5445 * -w Display latency histograms
5446 * -r Display request size histogram
5447 * -T Display a timestamp in date(1) or Unix format
5448 * -n Only print headers once
5450 * This command can be tricky because we want to be able to deal with pool
5451 * creation/destruction as well as vdev configuration changes. The bulk of this
5452 * processing is handled by the pool_list_* routines in zpool_iter.c. We rely
5453 * on pool_list_update() to detect the addition of new pools. Configuration
5454 * changes are all handled within libzfs.
5457 zpool_do_iostat(int argc
, char **argv
)
5463 unsigned long count
= 0;
5466 boolean_t verbose
= B_FALSE
;
5467 boolean_t latency
= B_FALSE
, l_histo
= B_FALSE
, rq_histo
= B_FALSE
;
5468 boolean_t queues
= B_FALSE
, parsable
= B_FALSE
, scripted
= B_FALSE
;
5469 boolean_t omit_since_boot
= B_FALSE
;
5470 boolean_t guid
= B_FALSE
;
5471 boolean_t follow_links
= B_FALSE
;
5472 boolean_t full_name
= B_FALSE
;
5473 boolean_t headers_once
= B_FALSE
;
5474 iostat_cbdata_t cb
= { 0 };
5477 /* Used for printing error message */
5478 const char flag_to_arg
[] = {[IOS_LATENCY
] = 'l', [IOS_QUEUES
] = 'q',
5479 [IOS_L_HISTO
] = 'w', [IOS_RQ_HISTO
] = 'r'};
5481 uint64_t unsupported_flags
;
5484 while ((c
= getopt(argc
, argv
, "c:gLPT:vyhplqrwnH")) != -1) {
5489 gettext("Can't set -c flag twice\n"));
5493 if (getenv("ZPOOL_SCRIPTS_ENABLED") != NULL
&&
5494 !libzfs_envvar_is_set("ZPOOL_SCRIPTS_ENABLED")) {
5495 fprintf(stderr
, gettext(
5496 "Can't run -c, disabled by "
5497 "ZPOOL_SCRIPTS_ENABLED.\n"));
5501 if ((getuid() <= 0 || geteuid() <= 0) &&
5502 !libzfs_envvar_is_set("ZPOOL_SCRIPTS_AS_ROOT")) {
5503 fprintf(stderr
, gettext(
5504 "Can't run -c with root privileges "
5505 "unless ZPOOL_SCRIPTS_AS_ROOT is set.\n"));
5515 follow_links
= B_TRUE
;
5521 get_timestamp_arg(*optarg
);
5545 omit_since_boot
= B_TRUE
;
5548 headers_once
= B_TRUE
;
5554 if (optopt
== 'c') {
5555 print_zpool_script_list("iostat");
5559 gettext("invalid option '%c'\n"), optopt
);
5568 cb
.cb_literal
= parsable
;
5569 cb
.cb_scripted
= scripted
;
5572 cb
.cb_name_flags
|= VDEV_NAME_GUID
;
5574 cb
.cb_name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
5576 cb
.cb_name_flags
|= VDEV_NAME_PATH
;
5577 cb
.cb_iteration
= 0;
5578 cb
.cb_namewidth
= 0;
5579 cb
.cb_verbose
= verbose
;
5581 /* Get our interval and count values (if any) */
5583 get_interval_count_filter_guids(&argc
, argv
, &interval
,
5586 get_interval_count(&argc
, argv
, &interval
, &count
);
5590 /* No args, so just print the defaults. */
5591 } else if (are_all_pools(argc
, argv
)) {
5592 /* All the args are pool names */
5593 } else if (are_vdevs_in_pool(argc
, argv
, NULL
, &cb
)) {
5594 /* All the args are vdevs */
5595 cb
.cb_vdev_names
= argv
;
5596 cb
.cb_vdev_names_count
= argc
;
5597 argc
= 0; /* No pools to process */
5598 } else if (are_all_pools(1, argv
)) {
5599 /* The first arg is a pool name */
5600 if (are_vdevs_in_pool(argc
- 1, argv
+ 1, argv
[0], &cb
)) {
5601 /* ...and the rest are vdev names */
5602 cb
.cb_vdev_names
= argv
+ 1;
5603 cb
.cb_vdev_names_count
= argc
- 1;
5604 argc
= 1; /* One pool to process */
5606 fprintf(stderr
, gettext("Expected either a list of "));
5607 fprintf(stderr
, gettext("pools, or list of vdevs in"));
5608 fprintf(stderr
, " \"%s\", ", argv
[0]);
5609 fprintf(stderr
, gettext("but got:\n"));
5610 error_list_unresolved_vdevs(argc
- 1, argv
+ 1,
5612 fprintf(stderr
, "\n");
5618 * The args don't make sense. The first arg isn't a pool name,
5619 * nor are all the args vdevs.
5621 fprintf(stderr
, gettext("Unable to parse pools/vdevs list.\n"));
5622 fprintf(stderr
, "\n");
5626 if (cb
.cb_vdev_names_count
!= 0) {
5628 * If user specified vdevs, it implies verbose.
5630 cb
.cb_verbose
= B_TRUE
;
5634 * Construct the list of all interesting pools.
5637 if ((list
= pool_list_get(argc
, argv
, NULL
, parsable
, &ret
)) == NULL
)
5640 if (pool_list_count(list
) == 0 && argc
!= 0) {
5641 pool_list_free(list
);
5645 if (pool_list_count(list
) == 0 && interval
== 0) {
5646 pool_list_free(list
);
5647 (void) fprintf(stderr
, gettext("no pools available\n"));
5651 if ((l_histo
|| rq_histo
) && (cmd
!= NULL
|| latency
|| queues
)) {
5652 pool_list_free(list
);
5653 (void) fprintf(stderr
,
5654 gettext("[-r|-w] isn't allowed with [-c|-l|-q]\n"));
5659 if (l_histo
&& rq_histo
) {
5660 pool_list_free(list
);
5661 (void) fprintf(stderr
,
5662 gettext("Only one of [-r|-w] can be passed at a time\n"));
5668 * Enter the main iostat loop.
5674 * Histograms tables look out of place when you try to display
5675 * them with the other stats, so make a rule that you can only
5676 * print histograms by themselves.
5678 cb
.cb_flags
= IOS_L_HISTO_M
;
5679 } else if (rq_histo
) {
5680 cb
.cb_flags
= IOS_RQ_HISTO_M
;
5682 cb
.cb_flags
= IOS_DEFAULT_M
;
5684 cb
.cb_flags
|= IOS_LATENCY_M
;
5686 cb
.cb_flags
|= IOS_QUEUES_M
;
5690 * See if the module supports all the stats we want to display.
5692 unsupported_flags
= cb
.cb_flags
& ~get_stat_flags(list
);
5693 if (unsupported_flags
) {
5697 gettext("The loaded zfs module doesn't support:"));
5699 /* for each bit set in unsupported_flags */
5700 for (f
= unsupported_flags
; f
; f
&= ~(1ULL << idx
)) {
5701 idx
= lowbit64(f
) - 1;
5702 fprintf(stderr
, " -%c", flag_to_arg
[idx
]);
5705 fprintf(stderr
, ". Try running a newer module.\n");
5706 pool_list_free(list
);
5712 if ((npools
= pool_list_count(list
)) == 0)
5713 (void) fprintf(stderr
, gettext("no pools available\n"));
5716 * If this is the first iteration and -y was supplied
5717 * we skip any printing.
5719 boolean_t skip
= (omit_since_boot
&&
5720 cb
.cb_iteration
== 0);
5723 * Refresh all statistics. This is done as an
5724 * explicit step before calculating the maximum name
5725 * width, so that any * configuration changes are
5726 * properly accounted for.
5728 (void) pool_list_iter(list
, B_FALSE
, refresh_iostat
,
5732 * Iterate over all pools to determine the maximum width
5733 * for the pool / device name column across all pools.
5735 cb
.cb_namewidth
= 0;
5736 (void) pool_list_iter(list
, B_FALSE
,
5737 get_namewidth_iostat
, &cb
);
5739 if (timestamp_fmt
!= NODATE
)
5740 print_timestamp(timestamp_fmt
);
5742 if (cmd
!= NULL
&& cb
.cb_verbose
&&
5743 !(cb
.cb_flags
& IOS_ANYHISTO_M
)) {
5744 cb
.vcdl
= all_pools_for_each_vdev_run(argc
,
5745 argv
, cmd
, g_zfs
, cb
.cb_vdev_names
,
5746 cb
.cb_vdev_names_count
, cb
.cb_name_flags
);
5753 * Check terminal size so we can print headers
5754 * even when terminal window has its height
5757 winheight
= terminal_height();
5759 * Are we connected to TTY? If not, headers_once
5760 * should be true, to avoid breaking scripts.
5763 headers_once
= B_TRUE
;
5766 * If it's the first time and we're not skipping it,
5767 * or either skip or verbose mode, print the header.
5769 * The histogram code explicitly prints its header on
5770 * every vdev, so skip this for histograms.
5772 if (((++cb
.cb_iteration
== 1 && !skip
) ||
5773 (skip
!= verbose
) ||
5775 (cb
.cb_iteration
% winheight
) == 0)) &&
5776 (!(cb
.cb_flags
& IOS_ANYHISTO_M
)) &&
5778 print_iostat_header(&cb
);
5781 (void) fsleep(interval
);
5785 pool_list_iter(list
, B_FALSE
, print_iostat
, &cb
);
5788 * If there's more than one pool, and we're not in
5789 * verbose mode (which prints a separator for us),
5790 * then print a separator.
5792 * In addition, if we're printing specific vdevs then
5793 * we also want an ending separator.
5795 if (((npools
> 1 && !verbose
&&
5796 !(cb
.cb_flags
& IOS_ANYHISTO_M
)) ||
5797 (!(cb
.cb_flags
& IOS_ANYHISTO_M
) &&
5798 cb
.cb_vdev_names_count
)) &&
5800 print_iostat_separator(&cb
);
5801 if (cb
.vcdl
!= NULL
)
5802 print_cmd_columns(cb
.vcdl
, 1);
5806 if (cb
.vcdl
!= NULL
)
5807 free_vdev_cmd_data_list(cb
.vcdl
);
5812 * Flush the output so that redirection to a file isn't buffered
5815 (void) fflush(stdout
);
5820 if (count
!= 0 && --count
== 0)
5823 (void) fsleep(interval
);
5826 pool_list_free(list
);
5831 typedef struct list_cbdata
{
5832 boolean_t cb_verbose
;
5835 boolean_t cb_scripted
;
5836 zprop_list_t
*cb_proplist
;
5837 boolean_t cb_literal
;
5842 * Given a list of columns to display, output appropriate headers for each one.
5845 print_header(list_cbdata_t
*cb
)
5847 zprop_list_t
*pl
= cb
->cb_proplist
;
5848 char headerbuf
[ZPOOL_MAXPROPLEN
];
5850 boolean_t first
= B_TRUE
;
5851 boolean_t right_justify
;
5854 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
5855 width
= pl
->pl_width
;
5856 if (first
&& cb
->cb_verbose
) {
5858 * Reset the width to accommodate the verbose listing
5861 width
= cb
->cb_namewidth
;
5869 right_justify
= B_FALSE
;
5870 if (pl
->pl_prop
!= ZPROP_INVAL
) {
5871 header
= zpool_prop_column_name(pl
->pl_prop
);
5872 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
5876 for (i
= 0; pl
->pl_user_prop
[i
] != '\0'; i
++)
5877 headerbuf
[i
] = toupper(pl
->pl_user_prop
[i
]);
5878 headerbuf
[i
] = '\0';
5882 if (pl
->pl_next
== NULL
&& !right_justify
)
5883 (void) printf("%s", header
);
5884 else if (right_justify
)
5885 (void) printf("%*s", (int)width
, header
);
5887 (void) printf("%-*s", (int)width
, header
);
5890 (void) printf("\n");
5894 * Given a pool and a list of properties, print out all the properties according
5895 * to the described layout. Used by zpool_do_list().
5898 print_pool(zpool_handle_t
*zhp
, list_cbdata_t
*cb
)
5900 zprop_list_t
*pl
= cb
->cb_proplist
;
5901 boolean_t first
= B_TRUE
;
5902 char property
[ZPOOL_MAXPROPLEN
];
5904 boolean_t right_justify
;
5907 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
5909 width
= pl
->pl_width
;
5910 if (first
&& cb
->cb_verbose
) {
5912 * Reset the width to accommodate the verbose listing
5915 width
= cb
->cb_namewidth
;
5919 if (cb
->cb_scripted
)
5920 (void) printf("\t");
5927 right_justify
= B_FALSE
;
5928 if (pl
->pl_prop
!= ZPROP_INVAL
) {
5929 if (zpool_get_prop(zhp
, pl
->pl_prop
, property
,
5930 sizeof (property
), NULL
, cb
->cb_literal
) != 0)
5935 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
5936 } else if ((zpool_prop_feature(pl
->pl_user_prop
) ||
5937 zpool_prop_unsupported(pl
->pl_user_prop
)) &&
5938 zpool_prop_get_feature(zhp
, pl
->pl_user_prop
, property
,
5939 sizeof (property
)) == 0) {
5947 * If this is being called in scripted mode, or if this is the
5948 * last column and it is left-justified, don't include a width
5951 if (cb
->cb_scripted
|| (pl
->pl_next
== NULL
&& !right_justify
))
5952 (void) printf("%s", propstr
);
5953 else if (right_justify
)
5954 (void) printf("%*s", (int)width
, propstr
);
5956 (void) printf("%-*s", (int)width
, propstr
);
5959 (void) printf("\n");
5963 print_one_column(zpool_prop_t prop
, uint64_t value
, const char *str
,
5964 boolean_t scripted
, boolean_t valid
, enum zfs_nicenum_format format
)
5968 size_t width
= zprop_width(prop
, &fixed
, ZFS_TYPE_POOL
);
5971 case ZPOOL_PROP_EXPANDSZ
:
5972 case ZPOOL_PROP_CHECKPOINT
:
5973 case ZPOOL_PROP_DEDUPRATIO
:
5975 (void) strlcpy(propval
, "-", sizeof (propval
));
5977 zfs_nicenum_format(value
, propval
, sizeof (propval
),
5980 case ZPOOL_PROP_FRAGMENTATION
:
5981 if (value
== ZFS_FRAG_INVALID
) {
5982 (void) strlcpy(propval
, "-", sizeof (propval
));
5983 } else if (format
== ZFS_NICENUM_RAW
) {
5984 (void) snprintf(propval
, sizeof (propval
), "%llu",
5985 (unsigned long long)value
);
5987 (void) snprintf(propval
, sizeof (propval
), "%llu%%",
5988 (unsigned long long)value
);
5991 case ZPOOL_PROP_CAPACITY
:
5992 /* capacity value is in parts-per-10,000 (aka permyriad) */
5993 if (format
== ZFS_NICENUM_RAW
)
5994 (void) snprintf(propval
, sizeof (propval
), "%llu",
5995 (unsigned long long)value
/ 100);
5997 (void) snprintf(propval
, sizeof (propval
),
5998 value
< 1000 ? "%1.2f%%" : value
< 10000 ?
5999 "%2.1f%%" : "%3.0f%%", value
/ 100.0);
6001 case ZPOOL_PROP_HEALTH
:
6003 snprintf(propval
, sizeof (propval
), "%-*s", (int)width
, str
);
6006 zfs_nicenum_format(value
, propval
, sizeof (propval
), format
);
6010 (void) strlcpy(propval
, "-", sizeof (propval
));
6013 (void) printf("\t%s", propval
);
6015 (void) printf(" %*s", (int)width
, propval
);
6019 * print static default line per vdev
6020 * not compatible with '-o' <proplist> option
6023 print_list_stats(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
,
6024 list_cbdata_t
*cb
, int depth
, boolean_t isspare
)
6030 boolean_t scripted
= cb
->cb_scripted
;
6031 uint64_t islog
= B_FALSE
;
6032 char *dashes
= "%-*s - - - - "
6035 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
6036 (uint64_t **)&vs
, &c
) == 0);
6039 boolean_t toplevel
= (vs
->vs_space
!= 0);
6041 enum zfs_nicenum_format format
;
6045 format
= ZFS_NICENUM_RAW
;
6047 format
= ZFS_NICENUM_1024
;
6049 if (strcmp(name
, VDEV_TYPE_INDIRECT
) == 0)
6053 (void) printf("\t%s", name
);
6054 else if (strlen(name
) + depth
> cb
->cb_namewidth
)
6055 (void) printf("%*s%s", depth
, "", name
);
6057 (void) printf("%*s%s%*s", depth
, "", name
,
6058 (int)(cb
->cb_namewidth
- strlen(name
) - depth
), "");
6061 * Print the properties for the individual vdevs. Some
6062 * properties are only applicable to toplevel vdevs. The
6063 * 'toplevel' boolean value is passed to the print_one_column()
6064 * to indicate that the value is valid.
6066 print_one_column(ZPOOL_PROP_SIZE
, vs
->vs_space
, NULL
, scripted
,
6068 print_one_column(ZPOOL_PROP_ALLOCATED
, vs
->vs_alloc
, NULL
,
6069 scripted
, toplevel
, format
);
6070 print_one_column(ZPOOL_PROP_FREE
, vs
->vs_space
- vs
->vs_alloc
,
6071 NULL
, scripted
, toplevel
, format
);
6072 print_one_column(ZPOOL_PROP_CHECKPOINT
,
6073 vs
->vs_checkpoint_space
, NULL
, scripted
, toplevel
, format
);
6074 print_one_column(ZPOOL_PROP_EXPANDSZ
, vs
->vs_esize
, NULL
,
6075 scripted
, B_TRUE
, format
);
6076 print_one_column(ZPOOL_PROP_FRAGMENTATION
,
6077 vs
->vs_fragmentation
, NULL
, scripted
,
6078 (vs
->vs_fragmentation
!= ZFS_FRAG_INVALID
&& toplevel
),
6080 cap
= (vs
->vs_space
== 0) ? 0 :
6081 (vs
->vs_alloc
* 10000 / vs
->vs_space
);
6082 print_one_column(ZPOOL_PROP_CAPACITY
, cap
, NULL
,
6083 scripted
, toplevel
, format
);
6084 print_one_column(ZPOOL_PROP_DEDUPRATIO
, 0, NULL
,
6085 scripted
, toplevel
, format
);
6086 state
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
6088 if (vs
->vs_aux
== VDEV_AUX_SPARED
)
6090 else if (vs
->vs_state
== VDEV_STATE_HEALTHY
)
6093 print_one_column(ZPOOL_PROP_HEALTH
, 0, state
, scripted
,
6095 (void) printf("\n");
6098 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
6099 &child
, &children
) != 0)
6102 /* list the normal vdevs first */
6103 for (c
= 0; c
< children
; c
++) {
6104 uint64_t ishole
= B_FALSE
;
6106 if (nvlist_lookup_uint64(child
[c
],
6107 ZPOOL_CONFIG_IS_HOLE
, &ishole
) == 0 && ishole
)
6110 if (nvlist_lookup_uint64(child
[c
],
6111 ZPOOL_CONFIG_IS_LOG
, &islog
) == 0 && islog
)
6114 if (nvlist_exists(child
[c
], ZPOOL_CONFIG_ALLOCATION_BIAS
))
6117 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
6119 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2, B_FALSE
);
6123 /* list the classes: 'logs', 'dedup', and 'special' */
6124 for (uint_t n
= 0; n
< 3; n
++) {
6125 boolean_t printed
= B_FALSE
;
6127 for (c
= 0; c
< children
; c
++) {
6131 if (nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
6132 &islog
) == 0 && islog
) {
6133 bias
= VDEV_ALLOC_CLASS_LOGS
;
6135 (void) nvlist_lookup_string(child
[c
],
6136 ZPOOL_CONFIG_ALLOCATION_BIAS
, &bias
);
6137 (void) nvlist_lookup_string(child
[c
],
6138 ZPOOL_CONFIG_TYPE
, &type
);
6140 if (bias
== NULL
|| strcmp(bias
, class_name
[n
]) != 0)
6142 if (!islog
&& strcmp(type
, VDEV_TYPE_INDIRECT
) == 0)
6146 /* LINTED E_SEC_PRINTF_VAR_FMT */
6147 (void) printf(dashes
, cb
->cb_namewidth
,
6151 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
6153 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2,
6159 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
6160 &child
, &children
) == 0 && children
> 0) {
6161 /* LINTED E_SEC_PRINTF_VAR_FMT */
6162 (void) printf(dashes
, cb
->cb_namewidth
, "cache");
6163 for (c
= 0; c
< children
; c
++) {
6164 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
6166 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2,
6172 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
, &child
,
6173 &children
) == 0 && children
> 0) {
6174 /* LINTED E_SEC_PRINTF_VAR_FMT */
6175 (void) printf(dashes
, cb
->cb_namewidth
, "spare");
6176 for (c
= 0; c
< children
; c
++) {
6177 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
6179 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2,
6187 * Generic callback function to list a pool.
6190 list_callback(zpool_handle_t
*zhp
, void *data
)
6192 list_cbdata_t
*cbp
= data
;
6194 print_pool(zhp
, cbp
);
6196 if (cbp
->cb_verbose
) {
6197 nvlist_t
*config
, *nvroot
;
6199 config
= zpool_get_config(zhp
, NULL
);
6200 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
6202 print_list_stats(zhp
, NULL
, nvroot
, cbp
, 0, B_FALSE
);
6209 * Set the minimum pool/vdev name column width. The width must be at least 9,
6210 * but may be as large as needed.
6213 get_namewidth_list(zpool_handle_t
*zhp
, void *data
)
6215 list_cbdata_t
*cb
= data
;
6218 width
= get_namewidth(zhp
, cb
->cb_namewidth
, cb
->cb_name_flags
,
6224 cb
->cb_namewidth
= width
;
6230 * zpool list [-gHLpP] [-o prop[,prop]*] [-T d|u] [pool] ... [interval [count]]
6232 * -g Display guid for individual vdev name.
6233 * -H Scripted mode. Don't display headers, and separate properties
6235 * -L Follow links when resolving vdev path name.
6236 * -o List of properties to display. Defaults to
6237 * "name,size,allocated,free,expandsize,fragmentation,capacity,"
6238 * "dedupratio,health,altroot"
6239 * -p Display values in parsable (exact) format.
6240 * -P Display full path for vdev name.
6241 * -T Display a timestamp in date(1) or Unix format
6243 * List all pools in the system, whether or not they're healthy. Output space
6244 * statistics for each one, as well as health status summary.
6247 zpool_do_list(int argc
, char **argv
)
6251 list_cbdata_t cb
= { 0 };
6252 static char default_props
[] =
6253 "name,size,allocated,free,checkpoint,expandsize,fragmentation,"
6254 "capacity,dedupratio,health,altroot";
6255 char *props
= default_props
;
6257 unsigned long count
= 0;
6259 boolean_t first
= B_TRUE
;
6262 while ((c
= getopt(argc
, argv
, ":gHLo:pPT:v")) != -1) {
6265 cb
.cb_name_flags
|= VDEV_NAME_GUID
;
6268 cb
.cb_scripted
= B_TRUE
;
6271 cb
.cb_name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
6277 cb
.cb_name_flags
|= VDEV_NAME_PATH
;
6280 cb
.cb_literal
= B_TRUE
;
6283 get_timestamp_arg(*optarg
);
6286 cb
.cb_verbose
= B_TRUE
;
6287 cb
.cb_namewidth
= 8; /* 8 until precalc is avail */
6290 (void) fprintf(stderr
, gettext("missing argument for "
6291 "'%c' option\n"), optopt
);
6295 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
6304 get_interval_count(&argc
, argv
, &interval
, &count
);
6306 if (zprop_get_list(g_zfs
, props
, &cb
.cb_proplist
, ZFS_TYPE_POOL
) != 0)
6310 if ((list
= pool_list_get(argc
, argv
, &cb
.cb_proplist
,
6311 cb
.cb_literal
, &ret
)) == NULL
)
6314 if (pool_list_count(list
) == 0)
6317 cb
.cb_namewidth
= 0;
6318 (void) pool_list_iter(list
, B_FALSE
, get_namewidth_list
, &cb
);
6320 if (timestamp_fmt
!= NODATE
)
6321 print_timestamp(timestamp_fmt
);
6323 if (!cb
.cb_scripted
&& (first
|| cb
.cb_verbose
)) {
6327 ret
= pool_list_iter(list
, B_TRUE
, list_callback
, &cb
);
6332 if (count
!= 0 && --count
== 0)
6335 pool_list_free(list
);
6336 (void) fsleep(interval
);
6339 if (argc
== 0 && !cb
.cb_scripted
&& pool_list_count(list
) == 0) {
6340 (void) printf(gettext("no pools available\n"));
6344 pool_list_free(list
);
6345 zprop_free_list(cb
.cb_proplist
);
6350 zpool_do_attach_or_replace(int argc
, char **argv
, int replacing
)
6352 boolean_t force
= B_FALSE
;
6353 boolean_t rebuild
= B_FALSE
;
6354 boolean_t wait
= B_FALSE
;
6357 char *poolname
, *old_disk
, *new_disk
;
6358 zpool_handle_t
*zhp
;
6359 nvlist_t
*props
= NULL
;
6364 while ((c
= getopt(argc
, argv
, "fo:sw")) != -1) {
6370 if ((propval
= strchr(optarg
, '=')) == NULL
) {
6371 (void) fprintf(stderr
, gettext("missing "
6372 "'=' for -o option\n"));
6378 if ((strcmp(optarg
, ZPOOL_CONFIG_ASHIFT
) != 0) ||
6379 (add_prop_list(optarg
, propval
, &props
, B_TRUE
)))
6389 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
6398 /* get pool name and check number of arguments */
6400 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
6407 (void) fprintf(stderr
,
6408 gettext("missing <device> specification\n"));
6416 (void) fprintf(stderr
,
6417 gettext("missing <new_device> specification\n"));
6420 new_disk
= old_disk
;
6430 (void) fprintf(stderr
, gettext("too many arguments\n"));
6434 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
) {
6439 if (zpool_get_config(zhp
, NULL
) == NULL
) {
6440 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
6447 /* unless manually specified use "ashift" pool property (if set) */
6448 if (!nvlist_exists(props
, ZPOOL_CONFIG_ASHIFT
)) {
6451 char strval
[ZPOOL_MAXPROPLEN
];
6453 intval
= zpool_get_prop_int(zhp
, ZPOOL_PROP_ASHIFT
, &src
);
6454 if (src
!= ZPROP_SRC_DEFAULT
) {
6455 (void) sprintf(strval
, "%" PRId32
, intval
);
6456 verify(add_prop_list(ZPOOL_CONFIG_ASHIFT
, strval
,
6457 &props
, B_TRUE
) == 0);
6461 nvroot
= make_root_vdev(zhp
, props
, force
, B_FALSE
, replacing
, B_FALSE
,
6463 if (nvroot
== NULL
) {
6469 ret
= zpool_vdev_attach(zhp
, old_disk
, new_disk
, nvroot
, replacing
,
6472 if (ret
== 0 && wait
)
6473 ret
= zpool_wait(zhp
,
6474 replacing
? ZPOOL_WAIT_REPLACE
: ZPOOL_WAIT_RESILVER
);
6477 nvlist_free(nvroot
);
6484 * zpool replace [-fsw] [-o property=value] <pool> <device> <new_device>
6486 * -f Force attach, even if <new_device> appears to be in use.
6487 * -s Use sequential instead of healing reconstruction for resilver.
6488 * -o Set property=value.
6489 * -w Wait for replacing to complete before returning
6491 * Replace <device> with <new_device>.
6495 zpool_do_replace(int argc
, char **argv
)
6497 return (zpool_do_attach_or_replace(argc
, argv
, B_TRUE
));
6501 * zpool attach [-fsw] [-o property=value] <pool> <device> <new_device>
6503 * -f Force attach, even if <new_device> appears to be in use.
6504 * -s Use sequential instead of healing reconstruction for resilver.
6505 * -o Set property=value.
6506 * -w Wait for resilvering to complete before returning
6508 * Attach <new_device> to the mirror containing <device>. If <device> is not
6509 * part of a mirror, then <device> will be transformed into a mirror of
6510 * <device> and <new_device>. In either case, <new_device> will begin life
6511 * with a DTL of [0, now], and will immediately begin to resilver itself.
6514 zpool_do_attach(int argc
, char **argv
)
6516 return (zpool_do_attach_or_replace(argc
, argv
, B_FALSE
));
6520 * zpool detach [-f] <pool> <device>
6522 * -f Force detach of <device>, even if DTLs argue against it
6523 * (not supported yet)
6525 * Detach a device from a mirror. The operation will be refused if <device>
6526 * is the last device in the mirror, or if the DTLs indicate that this device
6527 * has the only valid copy of some data.
6531 zpool_do_detach(int argc
, char **argv
)
6534 char *poolname
, *path
;
6535 zpool_handle_t
*zhp
;
6539 while ((c
= getopt(argc
, argv
, "")) != -1) {
6542 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
6551 /* get pool name and check number of arguments */
6553 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
6558 (void) fprintf(stderr
,
6559 gettext("missing <device> specification\n"));
6566 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
6569 ret
= zpool_vdev_detach(zhp
, path
);
6577 * zpool split [-gLnP] [-o prop=val] ...
6579 * [-R altroot] <pool> <newpool> [<device> ...]
6581 * -g Display guid for individual vdev name.
6582 * -L Follow links when resolving vdev path name.
6583 * -n Do not split the pool, but display the resulting layout if
6584 * it were to be split.
6585 * -o Set property=value, or set mount options.
6586 * -P Display full path for vdev name.
6587 * -R Mount the split-off pool under an alternate root.
6588 * -l Load encryption keys while importing.
6590 * Splits the named pool and gives it the new pool name. Devices to be split
6591 * off may be listed, provided that no more than one device is specified
6592 * per top-level vdev mirror. The newly split pool is left in an exported
6593 * state unless -R is specified.
6595 * Restrictions: the top-level of the pool pool must only be made up of
6596 * mirrors; all devices in the pool must be healthy; no device may be
6597 * undergoing a resilvering operation.
6600 zpool_do_split(int argc
, char **argv
)
6602 char *srcpool
, *newpool
, *propval
;
6603 char *mntopts
= NULL
;
6606 boolean_t loadkeys
= B_FALSE
;
6607 zpool_handle_t
*zhp
;
6608 nvlist_t
*config
, *props
= NULL
;
6610 flags
.dryrun
= B_FALSE
;
6611 flags
.import
= B_FALSE
;
6612 flags
.name_flags
= 0;
6615 while ((c
= getopt(argc
, argv
, ":gLR:lno:P")) != -1) {
6618 flags
.name_flags
|= VDEV_NAME_GUID
;
6621 flags
.name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
6624 flags
.import
= B_TRUE
;
6626 zpool_prop_to_name(ZPOOL_PROP_ALTROOT
), optarg
,
6627 &props
, B_TRUE
) != 0) {
6636 flags
.dryrun
= B_TRUE
;
6639 if ((propval
= strchr(optarg
, '=')) != NULL
) {
6642 if (add_prop_list(optarg
, propval
,
6643 &props
, B_TRUE
) != 0) {
6652 flags
.name_flags
|= VDEV_NAME_PATH
;
6655 (void) fprintf(stderr
, gettext("missing argument for "
6656 "'%c' option\n"), optopt
);
6660 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
6667 if (!flags
.import
&& mntopts
!= NULL
) {
6668 (void) fprintf(stderr
, gettext("setting mntopts is only "
6669 "valid when importing the pool\n"));
6673 if (!flags
.import
&& loadkeys
) {
6674 (void) fprintf(stderr
, gettext("loading keys is only "
6675 "valid when importing the pool\n"));
6683 (void) fprintf(stderr
, gettext("Missing pool name\n"));
6687 (void) fprintf(stderr
, gettext("Missing new pool name\n"));
6697 if ((zhp
= zpool_open(g_zfs
, srcpool
)) == NULL
) {
6702 config
= split_mirror_vdev(zhp
, newpool
, props
, flags
, argc
, argv
);
6703 if (config
== NULL
) {
6707 (void) printf(gettext("would create '%s' with the "
6708 "following layout:\n\n"), newpool
);
6709 print_vdev_tree(NULL
, newpool
, config
, 0, "",
6711 print_vdev_tree(NULL
, "dedup", config
, 0,
6712 VDEV_ALLOC_BIAS_DEDUP
, 0);
6713 print_vdev_tree(NULL
, "special", config
, 0,
6714 VDEV_ALLOC_BIAS_SPECIAL
, 0);
6720 if (ret
!= 0 || flags
.dryrun
|| !flags
.import
) {
6721 nvlist_free(config
);
6727 * The split was successful. Now we need to open the new
6728 * pool and import it.
6730 if ((zhp
= zpool_open_canfail(g_zfs
, newpool
)) == NULL
) {
6731 nvlist_free(config
);
6737 ret
= zfs_crypto_attempt_load_keys(g_zfs
, newpool
);
6742 if (zpool_get_state(zhp
) != POOL_STATE_UNAVAIL
&&
6743 zpool_enable_datasets(zhp
, mntopts
, 0) != 0) {
6745 (void) fprintf(stderr
, gettext("Split was successful, but "
6746 "the datasets could not all be mounted\n"));
6747 (void) fprintf(stderr
, gettext("Try doing '%s' with a "
6748 "different altroot\n"), "zpool import");
6751 nvlist_free(config
);
6760 * zpool online <pool> <device> ...
6763 zpool_do_online(int argc
, char **argv
)
6767 zpool_handle_t
*zhp
;
6769 vdev_state_t newstate
;
6773 while ((c
= getopt(argc
, argv
, "e")) != -1) {
6776 flags
|= ZFS_ONLINE_EXPAND
;
6779 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
6788 /* get pool name and check number of arguments */
6790 (void) fprintf(stderr
, gettext("missing pool name\n"));
6794 (void) fprintf(stderr
, gettext("missing device name\n"));
6800 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
6803 for (i
= 1; i
< argc
; i
++) {
6804 if (zpool_vdev_online(zhp
, argv
[i
], flags
, &newstate
) == 0) {
6805 if (newstate
!= VDEV_STATE_HEALTHY
) {
6806 (void) printf(gettext("warning: device '%s' "
6807 "onlined, but remains in faulted state\n"),
6809 if (newstate
== VDEV_STATE_FAULTED
)
6810 (void) printf(gettext("use 'zpool "
6811 "clear' to restore a faulted "
6814 (void) printf(gettext("use 'zpool "
6815 "replace' to replace devices "
6816 "that are no longer present\n"));
6829 * zpool offline [-ft] <pool> <device> ...
6831 * -f Force the device into a faulted state.
6833 * -t Only take the device off-line temporarily. The offline/faulted
6834 * state will not be persistent across reboots.
6838 zpool_do_offline(int argc
, char **argv
)
6842 zpool_handle_t
*zhp
;
6844 boolean_t istmp
= B_FALSE
;
6845 boolean_t fault
= B_FALSE
;
6848 while ((c
= getopt(argc
, argv
, "ft")) != -1) {
6857 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
6866 /* get pool name and check number of arguments */
6868 (void) fprintf(stderr
, gettext("missing pool name\n"));
6872 (void) fprintf(stderr
, gettext("missing device name\n"));
6878 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
6881 for (i
= 1; i
< argc
; i
++) {
6883 uint64_t guid
= zpool_vdev_path_to_guid(zhp
, argv
[i
]);
6885 if (istmp
== B_FALSE
) {
6886 /* Force the fault to persist across imports */
6887 aux
= VDEV_AUX_EXTERNAL_PERSIST
;
6889 aux
= VDEV_AUX_EXTERNAL
;
6892 if (guid
== 0 || zpool_vdev_fault(zhp
, guid
, aux
) != 0)
6895 if (zpool_vdev_offline(zhp
, argv
[i
], istmp
) != 0)
6906 * zpool clear <pool> [device]
6908 * Clear all errors associated with a pool or a particular device.
6911 zpool_do_clear(int argc
, char **argv
)
6915 boolean_t dryrun
= B_FALSE
;
6916 boolean_t do_rewind
= B_FALSE
;
6917 boolean_t xtreme_rewind
= B_FALSE
;
6918 uint32_t rewind_policy
= ZPOOL_NO_REWIND
;
6919 nvlist_t
*policy
= NULL
;
6920 zpool_handle_t
*zhp
;
6921 char *pool
, *device
;
6924 while ((c
= getopt(argc
, argv
, "FnX")) != -1) {
6933 xtreme_rewind
= B_TRUE
;
6936 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
6946 (void) fprintf(stderr
, gettext("missing pool name\n"));
6951 (void) fprintf(stderr
, gettext("too many arguments\n"));
6955 if ((dryrun
|| xtreme_rewind
) && !do_rewind
) {
6956 (void) fprintf(stderr
,
6957 gettext("-n or -X only meaningful with -F\n"));
6961 rewind_policy
= ZPOOL_TRY_REWIND
;
6963 rewind_policy
= ZPOOL_DO_REWIND
;
6965 rewind_policy
|= ZPOOL_EXTREME_REWIND
;
6967 /* In future, further rewind policy choices can be passed along here */
6968 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME
, 0) != 0 ||
6969 nvlist_add_uint32(policy
, ZPOOL_LOAD_REWIND_POLICY
,
6970 rewind_policy
) != 0) {
6975 device
= argc
== 2 ? argv
[1] : NULL
;
6977 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
) {
6978 nvlist_free(policy
);
6982 if (zpool_clear(zhp
, device
, policy
) != 0)
6987 nvlist_free(policy
);
6993 * zpool reguid <pool>
6996 zpool_do_reguid(int argc
, char **argv
)
7000 zpool_handle_t
*zhp
;
7004 while ((c
= getopt(argc
, argv
, "")) != -1) {
7007 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
7016 /* get pool name and check number of arguments */
7018 (void) fprintf(stderr
, gettext("missing pool name\n"));
7023 (void) fprintf(stderr
, gettext("too many arguments\n"));
7028 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
7031 ret
= zpool_reguid(zhp
);
7039 * zpool reopen <pool>
7041 * Reopen the pool so that the kernel can update the sizes of all vdevs.
7044 zpool_do_reopen(int argc
, char **argv
)
7048 boolean_t scrub_restart
= B_TRUE
;
7051 while ((c
= getopt(argc
, argv
, "n")) != -1) {
7054 scrub_restart
= B_FALSE
;
7057 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
7066 /* if argc == 0 we will execute zpool_reopen_one on all pools */
7067 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
, B_FALSE
, zpool_reopen_one
,
7073 typedef struct scrub_cbdata
{
7075 pool_scrub_cmd_t cb_scrub_cmd
;
7079 zpool_has_checkpoint(zpool_handle_t
*zhp
)
7081 nvlist_t
*config
, *nvroot
;
7083 config
= zpool_get_config(zhp
, NULL
);
7085 if (config
!= NULL
) {
7086 pool_checkpoint_stat_t
*pcs
= NULL
;
7089 nvroot
= fnvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
);
7090 (void) nvlist_lookup_uint64_array(nvroot
,
7091 ZPOOL_CONFIG_CHECKPOINT_STATS
, (uint64_t **)&pcs
, &c
);
7093 if (pcs
== NULL
|| pcs
->pcs_state
== CS_NONE
)
7096 assert(pcs
->pcs_state
== CS_CHECKPOINT_EXISTS
||
7097 pcs
->pcs_state
== CS_CHECKPOINT_DISCARDING
);
7105 scrub_callback(zpool_handle_t
*zhp
, void *data
)
7107 scrub_cbdata_t
*cb
= data
;
7111 * Ignore faulted pools.
7113 if (zpool_get_state(zhp
) == POOL_STATE_UNAVAIL
) {
7114 (void) fprintf(stderr
, gettext("cannot scan '%s': pool is "
7115 "currently unavailable\n"), zpool_get_name(zhp
));
7119 err
= zpool_scan(zhp
, cb
->cb_type
, cb
->cb_scrub_cmd
);
7121 if (err
== 0 && zpool_has_checkpoint(zhp
) &&
7122 cb
->cb_type
== POOL_SCAN_SCRUB
) {
7123 (void) printf(gettext("warning: will not scrub state that "
7124 "belongs to the checkpoint of pool '%s'\n"),
7125 zpool_get_name(zhp
));
7132 wait_callback(zpool_handle_t
*zhp
, void *data
)
7134 zpool_wait_activity_t
*act
= data
;
7135 return (zpool_wait(zhp
, *act
));
7139 * zpool scrub [-s | -p] [-w] <pool> ...
7141 * -s Stop. Stops any in-progress scrub.
7142 * -p Pause. Pause in-progress scrub.
7143 * -w Wait. Blocks until scrub has completed.
7146 zpool_do_scrub(int argc
, char **argv
)
7150 boolean_t wait
= B_FALSE
;
7153 cb
.cb_type
= POOL_SCAN_SCRUB
;
7154 cb
.cb_scrub_cmd
= POOL_SCRUB_NORMAL
;
7157 while ((c
= getopt(argc
, argv
, "spw")) != -1) {
7160 cb
.cb_type
= POOL_SCAN_NONE
;
7163 cb
.cb_scrub_cmd
= POOL_SCRUB_PAUSE
;
7169 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
7175 if (cb
.cb_type
== POOL_SCAN_NONE
&&
7176 cb
.cb_scrub_cmd
== POOL_SCRUB_PAUSE
) {
7177 (void) fprintf(stderr
, gettext("invalid option combination: "
7178 "-s and -p are mutually exclusive\n"));
7182 if (wait
&& (cb
.cb_type
== POOL_SCAN_NONE
||
7183 cb
.cb_scrub_cmd
== POOL_SCRUB_PAUSE
)) {
7184 (void) fprintf(stderr
, gettext("invalid option combination: "
7185 "-w cannot be used with -p or -s\n"));
7193 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
7197 error
= for_each_pool(argc
, argv
, B_TRUE
, NULL
, B_FALSE
,
7198 scrub_callback
, &cb
);
7200 if (wait
&& !error
) {
7201 zpool_wait_activity_t act
= ZPOOL_WAIT_SCRUB
;
7202 error
= for_each_pool(argc
, argv
, B_TRUE
, NULL
, B_FALSE
,
7203 wait_callback
, &act
);
7210 * zpool resilver <pool> ...
7212 * Restarts any in-progress resilver
7215 zpool_do_resilver(int argc
, char **argv
)
7220 cb
.cb_type
= POOL_SCAN_RESILVER
;
7221 cb
.cb_scrub_cmd
= POOL_SCRUB_NORMAL
;
7224 while ((c
= getopt(argc
, argv
, "")) != -1) {
7227 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
7237 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
7241 return (for_each_pool(argc
, argv
, B_TRUE
, NULL
, B_FALSE
,
7242 scrub_callback
, &cb
));
7246 * zpool trim [-d] [-r <rate>] [-c | -s] <pool> [<device> ...]
7248 * -c Cancel. Ends any in-progress trim.
7249 * -d Secure trim. Requires kernel and device support.
7250 * -r <rate> Sets the TRIM rate in bytes (per second). Supports
7251 * adding a multiplier suffix such as 'k' or 'm'.
7252 * -s Suspend. TRIM can then be restarted with no flags.
7253 * -w Wait. Blocks until trimming has completed.
7256 zpool_do_trim(int argc
, char **argv
)
7258 struct option long_options
[] = {
7259 {"cancel", no_argument
, NULL
, 'c'},
7260 {"secure", no_argument
, NULL
, 'd'},
7261 {"rate", required_argument
, NULL
, 'r'},
7262 {"suspend", no_argument
, NULL
, 's'},
7263 {"wait", no_argument
, NULL
, 'w'},
7267 pool_trim_func_t cmd_type
= POOL_TRIM_START
;
7269 boolean_t secure
= B_FALSE
;
7270 boolean_t wait
= B_FALSE
;
7273 while ((c
= getopt_long(argc
, argv
, "cdr:sw", long_options
, NULL
))
7277 if (cmd_type
!= POOL_TRIM_START
&&
7278 cmd_type
!= POOL_TRIM_CANCEL
) {
7279 (void) fprintf(stderr
, gettext("-c cannot be "
7280 "combined with other options\n"));
7283 cmd_type
= POOL_TRIM_CANCEL
;
7286 if (cmd_type
!= POOL_TRIM_START
) {
7287 (void) fprintf(stderr
, gettext("-d cannot be "
7288 "combined with the -c or -s options\n"));
7294 if (cmd_type
!= POOL_TRIM_START
) {
7295 (void) fprintf(stderr
, gettext("-r cannot be "
7296 "combined with the -c or -s options\n"));
7299 if (zfs_nicestrtonum(NULL
, optarg
, &rate
) == -1) {
7300 (void) fprintf(stderr
,
7301 gettext("invalid value for rate\n"));
7306 if (cmd_type
!= POOL_TRIM_START
&&
7307 cmd_type
!= POOL_TRIM_SUSPEND
) {
7308 (void) fprintf(stderr
, gettext("-s cannot be "
7309 "combined with other options\n"));
7312 cmd_type
= POOL_TRIM_SUSPEND
;
7319 (void) fprintf(stderr
,
7320 gettext("invalid option '%c'\n"), optopt
);
7322 (void) fprintf(stderr
,
7323 gettext("invalid option '%s'\n"),
7334 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
7339 if (wait
&& (cmd_type
!= POOL_TRIM_START
)) {
7340 (void) fprintf(stderr
, gettext("-w cannot be used with -c or "
7345 char *poolname
= argv
[0];
7346 zpool_handle_t
*zhp
= zpool_open(g_zfs
, poolname
);
7350 trimflags_t trim_flags
= {
7356 nvlist_t
*vdevs
= fnvlist_alloc();
7358 /* no individual leaf vdevs specified, so add them all */
7359 nvlist_t
*config
= zpool_get_config(zhp
, NULL
);
7360 nvlist_t
*nvroot
= fnvlist_lookup_nvlist(config
,
7361 ZPOOL_CONFIG_VDEV_TREE
);
7362 zpool_collect_leaves(zhp
, nvroot
, vdevs
);
7363 trim_flags
.fullpool
= B_TRUE
;
7365 trim_flags
.fullpool
= B_FALSE
;
7366 for (int i
= 1; i
< argc
; i
++) {
7367 fnvlist_add_boolean(vdevs
, argv
[i
]);
7371 int error
= zpool_trim(zhp
, cmd_type
, vdevs
, &trim_flags
);
7373 fnvlist_free(vdevs
);
7380 * Converts a total number of seconds to a human readable string broken
7381 * down in to days/hours/minutes/seconds.
7384 secs_to_dhms(uint64_t total
, char *buf
)
7386 uint64_t days
= total
/ 60 / 60 / 24;
7387 uint64_t hours
= (total
/ 60 / 60) % 24;
7388 uint64_t mins
= (total
/ 60) % 60;
7389 uint64_t secs
= (total
% 60);
7392 (void) sprintf(buf
, "%llu days %02llu:%02llu:%02llu",
7393 (u_longlong_t
)days
, (u_longlong_t
)hours
,
7394 (u_longlong_t
)mins
, (u_longlong_t
)secs
);
7396 (void) sprintf(buf
, "%02llu:%02llu:%02llu",
7397 (u_longlong_t
)hours
, (u_longlong_t
)mins
,
7398 (u_longlong_t
)secs
);
7403 * Print out detailed scrub status.
7406 print_scan_scrub_resilver_status(pool_scan_stat_t
*ps
)
7408 time_t start
, end
, pause
;
7409 uint64_t pass_scanned
, scanned
, pass_issued
, issued
, total
;
7410 uint64_t elapsed
, scan_rate
, issue_rate
;
7411 double fraction_done
;
7412 char processed_buf
[7], scanned_buf
[7], issued_buf
[7], total_buf
[7];
7413 char srate_buf
[7], irate_buf
[7], time_buf
[32];
7416 printf_color(ANSI_BOLD
, gettext("scan:"));
7419 /* If there's never been a scan, there's not much to say. */
7420 if (ps
== NULL
|| ps
->pss_func
== POOL_SCAN_NONE
||
7421 ps
->pss_func
>= POOL_SCAN_FUNCS
) {
7422 (void) printf(gettext("none requested\n"));
7426 start
= ps
->pss_start_time
;
7427 end
= ps
->pss_end_time
;
7428 pause
= ps
->pss_pass_scrub_pause
;
7430 zfs_nicebytes(ps
->pss_processed
, processed_buf
, sizeof (processed_buf
));
7432 assert(ps
->pss_func
== POOL_SCAN_SCRUB
||
7433 ps
->pss_func
== POOL_SCAN_RESILVER
);
7435 /* Scan is finished or canceled. */
7436 if (ps
->pss_state
== DSS_FINISHED
) {
7437 secs_to_dhms(end
- start
, time_buf
);
7439 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
7440 (void) printf(gettext("scrub repaired %s "
7441 "in %s with %llu errors on %s"), processed_buf
,
7442 time_buf
, (u_longlong_t
)ps
->pss_errors
,
7444 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
7445 (void) printf(gettext("resilvered %s "
7446 "in %s with %llu errors on %s"), processed_buf
,
7447 time_buf
, (u_longlong_t
)ps
->pss_errors
,
7451 } else if (ps
->pss_state
== DSS_CANCELED
) {
7452 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
7453 (void) printf(gettext("scrub canceled on %s"),
7455 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
7456 (void) printf(gettext("resilver canceled on %s"),
7462 assert(ps
->pss_state
== DSS_SCANNING
);
7464 /* Scan is in progress. Resilvers can't be paused. */
7465 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
7467 (void) printf(gettext("scrub in progress since %s"),
7470 (void) printf(gettext("scrub paused since %s"),
7472 (void) printf(gettext("\tscrub started on %s"),
7475 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
7476 (void) printf(gettext("resilver in progress since %s"),
7480 scanned
= ps
->pss_examined
;
7481 pass_scanned
= ps
->pss_pass_exam
;
7482 issued
= ps
->pss_issued
;
7483 pass_issued
= ps
->pss_pass_issued
;
7484 total
= ps
->pss_to_examine
;
7486 /* we are only done with a block once we have issued the IO for it */
7487 fraction_done
= (double)issued
/ total
;
7489 /* elapsed time for this pass, rounding up to 1 if it's 0 */
7490 elapsed
= time(NULL
) - ps
->pss_pass_start
;
7491 elapsed
-= ps
->pss_pass_scrub_spent_paused
;
7492 elapsed
= (elapsed
!= 0) ? elapsed
: 1;
7494 scan_rate
= pass_scanned
/ elapsed
;
7495 issue_rate
= pass_issued
/ elapsed
;
7496 uint64_t total_secs_left
= (issue_rate
!= 0 && total
>= issued
) ?
7497 ((total
- issued
) / issue_rate
) : UINT64_MAX
;
7498 secs_to_dhms(total_secs_left
, time_buf
);
7500 /* format all of the numbers we will be reporting */
7501 zfs_nicebytes(scanned
, scanned_buf
, sizeof (scanned_buf
));
7502 zfs_nicebytes(issued
, issued_buf
, sizeof (issued_buf
));
7503 zfs_nicebytes(total
, total_buf
, sizeof (total_buf
));
7504 zfs_nicebytes(scan_rate
, srate_buf
, sizeof (srate_buf
));
7505 zfs_nicebytes(issue_rate
, irate_buf
, sizeof (irate_buf
));
7507 /* do not print estimated time if we have a paused scrub */
7509 (void) printf(gettext("\t%s scanned at %s/s, "
7510 "%s issued at %s/s, %s total\n"),
7511 scanned_buf
, srate_buf
, issued_buf
, irate_buf
, total_buf
);
7513 (void) printf(gettext("\t%s scanned, %s issued, %s total\n"),
7514 scanned_buf
, issued_buf
, total_buf
);
7517 if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
7518 (void) printf(gettext("\t%s resilvered, %.2f%% done"),
7519 processed_buf
, 100 * fraction_done
);
7520 } else if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
7521 (void) printf(gettext("\t%s repaired, %.2f%% done"),
7522 processed_buf
, 100 * fraction_done
);
7526 if (total_secs_left
!= UINT64_MAX
&&
7527 issue_rate
>= 10 * 1024 * 1024) {
7528 (void) printf(gettext(", %s to go\n"), time_buf
);
7530 (void) printf(gettext(", no estimated "
7531 "completion time\n"));
7534 (void) printf(gettext("\n"));
7539 print_rebuild_status_impl(vdev_rebuild_stat_t
*vrs
, char *vdev_name
)
7541 if (vrs
== NULL
|| vrs
->vrs_state
== VDEV_REBUILD_NONE
)
7545 printf_color(ANSI_BOLD
, gettext("scan:"));
7548 uint64_t bytes_scanned
= vrs
->vrs_bytes_scanned
;
7549 uint64_t bytes_issued
= vrs
->vrs_bytes_issued
;
7550 uint64_t bytes_rebuilt
= vrs
->vrs_bytes_rebuilt
;
7551 uint64_t bytes_est
= vrs
->vrs_bytes_est
;
7552 uint64_t scan_rate
= (vrs
->vrs_pass_bytes_scanned
/
7553 (vrs
->vrs_pass_time_ms
+ 1)) * 1000;
7554 uint64_t issue_rate
= (vrs
->vrs_pass_bytes_issued
/
7555 (vrs
->vrs_pass_time_ms
+ 1)) * 1000;
7556 double scan_pct
= MIN((double)bytes_scanned
* 100 /
7557 (bytes_est
+ 1), 100);
7559 /* Format all of the numbers we will be reporting */
7560 char bytes_scanned_buf
[7], bytes_issued_buf
[7];
7561 char bytes_rebuilt_buf
[7], bytes_est_buf
[7];
7562 char scan_rate_buf
[7], issue_rate_buf
[7], time_buf
[32];
7563 zfs_nicebytes(bytes_scanned
, bytes_scanned_buf
,
7564 sizeof (bytes_scanned_buf
));
7565 zfs_nicebytes(bytes_issued
, bytes_issued_buf
,
7566 sizeof (bytes_issued_buf
));
7567 zfs_nicebytes(bytes_rebuilt
, bytes_rebuilt_buf
,
7568 sizeof (bytes_rebuilt_buf
));
7569 zfs_nicebytes(bytes_est
, bytes_est_buf
, sizeof (bytes_est_buf
));
7570 zfs_nicebytes(scan_rate
, scan_rate_buf
, sizeof (scan_rate_buf
));
7571 zfs_nicebytes(issue_rate
, issue_rate_buf
, sizeof (issue_rate_buf
));
7573 time_t start
= vrs
->vrs_start_time
;
7574 time_t end
= vrs
->vrs_end_time
;
7576 /* Rebuild is finished or canceled. */
7577 if (vrs
->vrs_state
== VDEV_REBUILD_COMPLETE
) {
7578 secs_to_dhms(vrs
->vrs_scan_time_ms
/ 1000, time_buf
);
7579 (void) printf(gettext("resilvered (%s) %s in %s "
7580 "with %llu errors on %s"), vdev_name
, bytes_rebuilt_buf
,
7581 time_buf
, (u_longlong_t
)vrs
->vrs_errors
, ctime(&end
));
7583 } else if (vrs
->vrs_state
== VDEV_REBUILD_CANCELED
) {
7584 (void) printf(gettext("resilver (%s) canceled on %s"),
7585 vdev_name
, ctime(&end
));
7587 } else if (vrs
->vrs_state
== VDEV_REBUILD_ACTIVE
) {
7588 (void) printf(gettext("resilver (%s) in progress since %s"),
7589 vdev_name
, ctime(&start
));
7592 assert(vrs
->vrs_state
== VDEV_REBUILD_ACTIVE
);
7594 secs_to_dhms(MAX((int64_t)bytes_est
- (int64_t)bytes_scanned
, 0) /
7595 MAX(scan_rate
, 1), time_buf
);
7597 (void) printf(gettext("\t%s scanned at %s/s, %s issued %s/s, "
7598 "%s total\n"), bytes_scanned_buf
, scan_rate_buf
,
7599 bytes_issued_buf
, issue_rate_buf
, bytes_est_buf
);
7600 (void) printf(gettext("\t%s resilvered, %.2f%% done"),
7601 bytes_rebuilt_buf
, scan_pct
);
7603 if (vrs
->vrs_state
== VDEV_REBUILD_ACTIVE
) {
7604 if (scan_rate
>= 10 * 1024 * 1024) {
7605 (void) printf(gettext(", %s to go\n"), time_buf
);
7607 (void) printf(gettext(", no estimated "
7608 "completion time\n"));
7611 (void) printf(gettext("\n"));
7616 * Print rebuild status for top-level vdevs.
7619 print_rebuild_status(zpool_handle_t
*zhp
, nvlist_t
*nvroot
)
7624 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_CHILDREN
,
7625 &child
, &children
) != 0)
7628 for (uint_t c
= 0; c
< children
; c
++) {
7629 vdev_rebuild_stat_t
*vrs
;
7632 if (nvlist_lookup_uint64_array(child
[c
],
7633 ZPOOL_CONFIG_REBUILD_STATS
, (uint64_t **)&vrs
, &i
) == 0) {
7634 char *name
= zpool_vdev_name(g_zfs
, zhp
,
7635 child
[c
], VDEV_NAME_TYPE_ID
);
7636 print_rebuild_status_impl(vrs
, name
);
7643 * As we don't scrub checkpointed blocks, we want to warn the user that we
7644 * skipped scanning some blocks if a checkpoint exists or existed at any
7645 * time during the scan. If a sequential instead of healing reconstruction
7646 * was performed then the blocks were reconstructed. However, their checksums
7647 * have not been verified so we still print the warning.
7650 print_checkpoint_scan_warning(pool_scan_stat_t
*ps
, pool_checkpoint_stat_t
*pcs
)
7652 if (ps
== NULL
|| pcs
== NULL
)
7655 if (pcs
->pcs_state
== CS_NONE
||
7656 pcs
->pcs_state
== CS_CHECKPOINT_DISCARDING
)
7659 assert(pcs
->pcs_state
== CS_CHECKPOINT_EXISTS
);
7661 if (ps
->pss_state
== DSS_NONE
)
7664 if ((ps
->pss_state
== DSS_FINISHED
|| ps
->pss_state
== DSS_CANCELED
) &&
7665 ps
->pss_end_time
< pcs
->pcs_start_time
)
7668 if (ps
->pss_state
== DSS_FINISHED
|| ps
->pss_state
== DSS_CANCELED
) {
7669 (void) printf(gettext(" scan warning: skipped blocks "
7670 "that are only referenced by the checkpoint.\n"));
7672 assert(ps
->pss_state
== DSS_SCANNING
);
7673 (void) printf(gettext(" scan warning: skipping blocks "
7674 "that are only referenced by the checkpoint.\n"));
7679 * Returns B_TRUE if there is an active rebuild in progress. Otherwise,
7680 * B_FALSE is returned and 'rebuild_end_time' is set to the end time for
7681 * the last completed (or cancelled) rebuild.
7684 check_rebuilding(nvlist_t
*nvroot
, uint64_t *rebuild_end_time
)
7688 boolean_t rebuilding
= B_FALSE
;
7689 uint64_t end_time
= 0;
7691 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_CHILDREN
,
7692 &child
, &children
) != 0)
7695 for (uint_t c
= 0; c
< children
; c
++) {
7696 vdev_rebuild_stat_t
*vrs
;
7699 if (nvlist_lookup_uint64_array(child
[c
],
7700 ZPOOL_CONFIG_REBUILD_STATS
, (uint64_t **)&vrs
, &i
) == 0) {
7702 if (vrs
->vrs_end_time
> end_time
)
7703 end_time
= vrs
->vrs_end_time
;
7705 if (vrs
->vrs_state
== VDEV_REBUILD_ACTIVE
) {
7706 rebuilding
= B_TRUE
;
7713 if (rebuild_end_time
!= NULL
)
7714 *rebuild_end_time
= end_time
;
7716 return (rebuilding
);
7720 * Print the scan status.
7723 print_scan_status(zpool_handle_t
*zhp
, nvlist_t
*nvroot
)
7725 uint64_t rebuild_end_time
= 0, resilver_end_time
= 0;
7726 boolean_t have_resilver
= B_FALSE
, have_scrub
= B_FALSE
;
7727 boolean_t active_resilver
= B_FALSE
;
7728 pool_checkpoint_stat_t
*pcs
= NULL
;
7729 pool_scan_stat_t
*ps
= NULL
;
7732 if (nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_SCAN_STATS
,
7733 (uint64_t **)&ps
, &c
) == 0) {
7734 if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
7735 resilver_end_time
= ps
->pss_end_time
;
7736 active_resilver
= (ps
->pss_state
== DSS_SCANNING
);
7739 have_resilver
= (ps
->pss_func
== POOL_SCAN_RESILVER
);
7740 have_scrub
= (ps
->pss_func
== POOL_SCAN_SCRUB
);
7743 boolean_t active_rebuild
= check_rebuilding(nvroot
, &rebuild_end_time
);
7744 boolean_t have_rebuild
= (active_rebuild
|| (rebuild_end_time
> 0));
7746 /* Always print the scrub status when available. */
7748 print_scan_scrub_resilver_status(ps
);
7751 * When there is an active resilver or rebuild print its status.
7752 * Otherwise print the status of the last resilver or rebuild.
7754 if (active_resilver
|| (!active_rebuild
&& have_resilver
&&
7755 resilver_end_time
&& resilver_end_time
> rebuild_end_time
)) {
7756 print_scan_scrub_resilver_status(ps
);
7757 } else if (active_rebuild
|| (!active_resilver
&& have_rebuild
&&
7758 rebuild_end_time
&& rebuild_end_time
> resilver_end_time
)) {
7759 print_rebuild_status(zhp
, nvroot
);
7762 (void) nvlist_lookup_uint64_array(nvroot
,
7763 ZPOOL_CONFIG_CHECKPOINT_STATS
, (uint64_t **)&pcs
, &c
);
7764 print_checkpoint_scan_warning(ps
, pcs
);
7768 * Print out detailed removal status.
7771 print_removal_status(zpool_handle_t
*zhp
, pool_removal_stat_t
*prs
)
7773 char copied_buf
[7], examined_buf
[7], total_buf
[7], rate_buf
[7];
7775 nvlist_t
*config
, *nvroot
;
7780 if (prs
== NULL
|| prs
->prs_state
== DSS_NONE
)
7784 * Determine name of vdev.
7786 config
= zpool_get_config(zhp
, NULL
);
7787 nvroot
= fnvlist_lookup_nvlist(config
,
7788 ZPOOL_CONFIG_VDEV_TREE
);
7789 verify(nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_CHILDREN
,
7790 &child
, &children
) == 0);
7791 assert(prs
->prs_removing_vdev
< children
);
7792 vdev_name
= zpool_vdev_name(g_zfs
, zhp
,
7793 child
[prs
->prs_removing_vdev
], B_TRUE
);
7795 printf_color(ANSI_BOLD
, gettext("remove: "));
7797 start
= prs
->prs_start_time
;
7798 end
= prs
->prs_end_time
;
7799 zfs_nicenum(prs
->prs_copied
, copied_buf
, sizeof (copied_buf
));
7802 * Removal is finished or canceled.
7804 if (prs
->prs_state
== DSS_FINISHED
) {
7805 uint64_t minutes_taken
= (end
- start
) / 60;
7807 (void) printf(gettext("Removal of vdev %llu copied %s "
7808 "in %lluh%um, completed on %s"),
7809 (longlong_t
)prs
->prs_removing_vdev
,
7811 (u_longlong_t
)(minutes_taken
/ 60),
7812 (uint_t
)(minutes_taken
% 60),
7813 ctime((time_t *)&end
));
7814 } else if (prs
->prs_state
== DSS_CANCELED
) {
7815 (void) printf(gettext("Removal of %s canceled on %s"),
7816 vdev_name
, ctime(&end
));
7818 uint64_t copied
, total
, elapsed
, mins_left
, hours_left
;
7819 double fraction_done
;
7822 assert(prs
->prs_state
== DSS_SCANNING
);
7825 * Removal is in progress.
7827 (void) printf(gettext(
7828 "Evacuation of %s in progress since %s"),
7829 vdev_name
, ctime(&start
));
7831 copied
= prs
->prs_copied
> 0 ? prs
->prs_copied
: 1;
7832 total
= prs
->prs_to_copy
;
7833 fraction_done
= (double)copied
/ total
;
7835 /* elapsed time for this pass */
7836 elapsed
= time(NULL
) - prs
->prs_start_time
;
7837 elapsed
= elapsed
> 0 ? elapsed
: 1;
7838 rate
= copied
/ elapsed
;
7839 rate
= rate
> 0 ? rate
: 1;
7840 mins_left
= ((total
- copied
) / rate
) / 60;
7841 hours_left
= mins_left
/ 60;
7843 zfs_nicenum(copied
, examined_buf
, sizeof (examined_buf
));
7844 zfs_nicenum(total
, total_buf
, sizeof (total_buf
));
7845 zfs_nicenum(rate
, rate_buf
, sizeof (rate_buf
));
7848 * do not print estimated time if hours_left is more than
7851 (void) printf(gettext(
7852 "\t%s copied out of %s at %s/s, %.2f%% done"),
7853 examined_buf
, total_buf
, rate_buf
, 100 * fraction_done
);
7854 if (hours_left
< (30 * 24)) {
7855 (void) printf(gettext(", %lluh%um to go\n"),
7856 (u_longlong_t
)hours_left
, (uint_t
)(mins_left
% 60));
7858 (void) printf(gettext(
7859 ", (copy is slow, no estimated time)\n"));
7864 if (prs
->prs_mapping_memory
> 0) {
7866 zfs_nicenum(prs
->prs_mapping_memory
, mem_buf
, sizeof (mem_buf
));
7867 (void) printf(gettext(
7868 "\t%s memory used for removed device mappings\n"),
7874 print_checkpoint_status(pool_checkpoint_stat_t
*pcs
)
7879 if (pcs
== NULL
|| pcs
->pcs_state
== CS_NONE
)
7882 (void) printf(gettext("checkpoint: "));
7884 start
= pcs
->pcs_start_time
;
7885 zfs_nicenum(pcs
->pcs_space
, space_buf
, sizeof (space_buf
));
7887 if (pcs
->pcs_state
== CS_CHECKPOINT_EXISTS
) {
7888 char *date
= ctime(&start
);
7891 * ctime() adds a newline at the end of the generated
7892 * string, thus the weird format specifier and the
7893 * strlen() call used to chop it off from the output.
7895 (void) printf(gettext("created %.*s, consumes %s\n"),
7896 (int)(strlen(date
) - 1), date
, space_buf
);
7900 assert(pcs
->pcs_state
== CS_CHECKPOINT_DISCARDING
);
7902 (void) printf(gettext("discarding, %s remaining.\n"),
7907 print_error_log(zpool_handle_t
*zhp
)
7909 nvlist_t
*nverrlist
= NULL
;
7912 size_t len
= MAXPATHLEN
* 2;
7914 if (zpool_get_errlog(zhp
, &nverrlist
) != 0)
7917 (void) printf("errors: Permanent errors have been "
7918 "detected in the following files:\n\n");
7920 pathname
= safe_malloc(len
);
7922 while ((elem
= nvlist_next_nvpair(nverrlist
, elem
)) != NULL
) {
7924 uint64_t dsobj
, obj
;
7926 verify(nvpair_value_nvlist(elem
, &nv
) == 0);
7927 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_DATASET
,
7929 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_OBJECT
,
7931 zpool_obj_to_path(zhp
, dsobj
, obj
, pathname
, len
);
7932 (void) printf("%7s %s\n", "", pathname
);
7935 nvlist_free(nverrlist
);
7939 print_spares(zpool_handle_t
*zhp
, status_cbdata_t
*cb
, nvlist_t
**spares
,
7948 (void) printf(gettext("\tspares\n"));
7950 for (i
= 0; i
< nspares
; i
++) {
7951 name
= zpool_vdev_name(g_zfs
, zhp
, spares
[i
],
7953 print_status_config(zhp
, cb
, name
, spares
[i
], 2, B_TRUE
, NULL
);
7959 print_l2cache(zpool_handle_t
*zhp
, status_cbdata_t
*cb
, nvlist_t
**l2cache
,
7968 (void) printf(gettext("\tcache\n"));
7970 for (i
= 0; i
< nl2cache
; i
++) {
7971 name
= zpool_vdev_name(g_zfs
, zhp
, l2cache
[i
],
7973 print_status_config(zhp
, cb
, name
, l2cache
[i
], 2,
7980 print_dedup_stats(nvlist_t
*config
)
7982 ddt_histogram_t
*ddh
;
7986 char dspace
[6], mspace
[6];
7989 * If the pool was faulted then we may not have been able to
7990 * obtain the config. Otherwise, if we have anything in the dedup
7991 * table continue processing the stats.
7993 if (nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_OBJ_STATS
,
7994 (uint64_t **)&ddo
, &c
) != 0)
7997 (void) printf("\n");
7998 (void) printf(gettext(" dedup: "));
7999 if (ddo
->ddo_count
== 0) {
8000 (void) printf(gettext("no DDT entries\n"));
8004 zfs_nicebytes(ddo
->ddo_dspace
, dspace
, sizeof (dspace
));
8005 zfs_nicebytes(ddo
->ddo_mspace
, mspace
, sizeof (mspace
));
8006 (void) printf("DDT entries %llu, size %s on disk, %s in core\n",
8007 (u_longlong_t
)ddo
->ddo_count
,
8011 verify(nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_STATS
,
8012 (uint64_t **)&dds
, &c
) == 0);
8013 verify(nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_HISTOGRAM
,
8014 (uint64_t **)&ddh
, &c
) == 0);
8015 zpool_dump_ddt(dds
, ddh
);
8019 * Display a summary of pool status. Displays a summary such as:
8023 * reason: One or more devices ...
8024 * see: https://openzfs.github.io/openzfs-docs/msg/ZFS-xxxx-01
8030 * When given the '-v' option, we print out the complete config. If the '-e'
8031 * option is specified, then we print out error rate information as well.
8034 status_callback(zpool_handle_t
*zhp
, void *data
)
8036 status_cbdata_t
*cbp
= data
;
8037 nvlist_t
*config
, *nvroot
;
8039 zpool_status_t reason
;
8040 zpool_errata_t errata
;
8045 config
= zpool_get_config(zhp
, NULL
);
8046 reason
= zpool_get_status(zhp
, &msgid
, &errata
);
8051 * If we were given 'zpool status -x', only report those pools with
8054 if (cbp
->cb_explain
&&
8055 (reason
== ZPOOL_STATUS_OK
||
8056 reason
== ZPOOL_STATUS_VERSION_OLDER
||
8057 reason
== ZPOOL_STATUS_FEAT_DISABLED
||
8058 reason
== ZPOOL_STATUS_COMPATIBILITY_ERR
)) {
8059 if (!cbp
->cb_allpools
) {
8060 (void) printf(gettext("pool '%s' is healthy\n"),
8061 zpool_get_name(zhp
));
8063 cbp
->cb_first
= B_FALSE
;
8069 cbp
->cb_first
= B_FALSE
;
8071 (void) printf("\n");
8073 nvroot
= fnvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
);
8074 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_VDEV_STATS
,
8075 (uint64_t **)&vs
, &c
) == 0);
8077 health
= zpool_get_state_str(zhp
);
8080 printf_color(ANSI_BOLD
, gettext("pool:"));
8081 printf(" %s\n", zpool_get_name(zhp
));
8083 printf_color(ANSI_BOLD
, gettext("state: "));
8085 printf_color(health_str_to_color(health
), "%s", health
);
8090 case ZPOOL_STATUS_MISSING_DEV_R
:
8091 printf_color(ANSI_BOLD
, gettext("status: "));
8092 printf_color(ANSI_YELLOW
, gettext("One or more devices could "
8093 "not be opened. Sufficient replicas exist for\n\tthe pool "
8094 "to continue functioning in a degraded state.\n"));
8095 printf_color(ANSI_BOLD
, gettext("action: "));
8096 printf_color(ANSI_YELLOW
, gettext("Attach the missing device "
8097 "and online it using 'zpool online'.\n"));
8100 case ZPOOL_STATUS_MISSING_DEV_NR
:
8101 printf_color(ANSI_BOLD
, gettext("status: "));
8102 printf_color(ANSI_YELLOW
, gettext("One or more devices could "
8103 "not be opened. There are insufficient\n\treplicas for the"
8104 " pool to continue functioning.\n"));
8105 printf_color(ANSI_BOLD
, gettext("action: "));
8106 printf_color(ANSI_YELLOW
, gettext("Attach the missing device "
8107 "and online it using 'zpool online'.\n"));
8110 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
8111 printf_color(ANSI_BOLD
, gettext("status: "));
8112 printf_color(ANSI_YELLOW
, gettext("One or more devices could "
8113 "not be used because the label is missing or\n\tinvalid. "
8114 "Sufficient replicas exist for the pool to continue\n\t"
8115 "functioning in a degraded state.\n"));
8116 printf_color(ANSI_BOLD
, gettext("action: "));
8117 printf_color(ANSI_YELLOW
, gettext("Replace the device using "
8118 "'zpool replace'.\n"));
8121 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
8122 printf_color(ANSI_BOLD
, gettext("status: "));
8123 printf_color(ANSI_YELLOW
, gettext("One or more devices could "
8124 "not be used because the label is missing \n\tor invalid. "
8125 "There are insufficient replicas for the pool to "
8126 "continue\n\tfunctioning.\n"));
8127 zpool_explain_recover(zpool_get_handle(zhp
),
8128 zpool_get_name(zhp
), reason
, config
);
8131 case ZPOOL_STATUS_FAILING_DEV
:
8132 printf_color(ANSI_BOLD
, gettext("status: "));
8133 printf_color(ANSI_YELLOW
, gettext("One or more devices has "
8134 "experienced an unrecoverable error. An\n\tattempt was "
8135 "made to correct the error. Applications are "
8137 printf_color(ANSI_BOLD
, gettext("action: "));
8138 printf_color(ANSI_YELLOW
, gettext("Determine if the "
8139 "device needs to be replaced, and clear the errors\n\tusing"
8140 " 'zpool clear' or replace the device with 'zpool "
8144 case ZPOOL_STATUS_OFFLINE_DEV
:
8145 printf_color(ANSI_BOLD
, gettext("status: "));
8146 printf_color(ANSI_YELLOW
, gettext("One or more devices has "
8147 "been taken offline by the administrator.\n\tSufficient "
8148 "replicas exist for the pool to continue functioning in "
8149 "a\n\tdegraded state.\n"));
8150 printf_color(ANSI_BOLD
, gettext("action: "));
8151 printf_color(ANSI_YELLOW
, gettext("Online the device "
8152 "using 'zpool online' or replace the device with\n\t'zpool "
8156 case ZPOOL_STATUS_REMOVED_DEV
:
8157 printf_color(ANSI_BOLD
, gettext("status: "));
8158 printf_color(ANSI_YELLOW
, gettext("One or more devices has "
8159 "been removed by the administrator.\n\tSufficient "
8160 "replicas exist for the pool to continue functioning in "
8161 "a\n\tdegraded state.\n"));
8162 printf_color(ANSI_BOLD
, gettext("action: "));
8163 printf_color(ANSI_YELLOW
, gettext("Online the device "
8164 "using zpool online' or replace the device with\n\t'zpool "
8168 case ZPOOL_STATUS_RESILVERING
:
8169 case ZPOOL_STATUS_REBUILDING
:
8170 printf_color(ANSI_BOLD
, gettext("status: "));
8171 printf_color(ANSI_YELLOW
, gettext("One or more devices is "
8172 "currently being resilvered. The pool will\n\tcontinue "
8173 "to function, possibly in a degraded state.\n"));
8174 printf_color(ANSI_BOLD
, gettext("action: "));
8175 printf_color(ANSI_YELLOW
, gettext("Wait for the resilver to "
8179 case ZPOOL_STATUS_REBUILD_SCRUB
:
8180 printf_color(ANSI_BOLD
, gettext("status: "));
8181 printf_color(ANSI_YELLOW
, gettext("One or more devices have "
8182 "been sequentially resilvered, scrubbing\n\tthe pool "
8183 "is recommended.\n"));
8184 printf_color(ANSI_BOLD
, gettext("action: "));
8185 printf_color(ANSI_YELLOW
, gettext("Use 'zpool scrub' to "
8186 "verify all data checksums.\n"));
8189 case ZPOOL_STATUS_CORRUPT_DATA
:
8190 printf_color(ANSI_BOLD
, gettext("status: "));
8191 printf_color(ANSI_YELLOW
, gettext("One or more devices has "
8192 "experienced an error resulting in data\n\tcorruption. "
8193 "Applications may be affected.\n"));
8194 printf_color(ANSI_BOLD
, gettext("action: "));
8195 printf_color(ANSI_YELLOW
, gettext("Restore the file in question"
8196 " if possible. Otherwise restore the\n\tentire pool from "
8200 case ZPOOL_STATUS_CORRUPT_POOL
:
8201 printf_color(ANSI_BOLD
, gettext("status: "));
8202 printf_color(ANSI_YELLOW
, gettext("The pool metadata is "
8203 "corrupted and the pool cannot be opened.\n"));
8204 zpool_explain_recover(zpool_get_handle(zhp
),
8205 zpool_get_name(zhp
), reason
, config
);
8208 case ZPOOL_STATUS_VERSION_OLDER
:
8209 printf_color(ANSI_BOLD
, gettext("status: "));
8210 printf_color(ANSI_YELLOW
, gettext("The pool is formatted using "
8211 "a legacy on-disk format. The pool can\n\tstill be used, "
8212 "but some features are unavailable.\n"));
8213 printf_color(ANSI_BOLD
, gettext("action: "));
8214 printf_color(ANSI_YELLOW
, gettext("Upgrade the pool using "
8215 "'zpool upgrade'. Once this is done, the\n\tpool will no "
8216 "longer be accessible on software that does not support\n\t"
8217 "feature flags.\n"));
8220 case ZPOOL_STATUS_VERSION_NEWER
:
8221 printf_color(ANSI_BOLD
, gettext("status: "));
8222 printf_color(ANSI_YELLOW
, gettext("The pool has been upgraded "
8223 "to a newer, incompatible on-disk version.\n\tThe pool "
8224 "cannot be accessed on this system.\n"));
8225 printf_color(ANSI_BOLD
, gettext("action: "));
8226 printf_color(ANSI_YELLOW
, gettext("Access the pool from a "
8227 "system running more recent software, or\n\trestore the "
8228 "pool from backup.\n"));
8231 case ZPOOL_STATUS_FEAT_DISABLED
:
8232 printf_color(ANSI_BOLD
, gettext("status: "));
8233 printf_color(ANSI_YELLOW
, gettext("Some supported and "
8234 "requested features are not enabled on the pool.\n\t"
8235 "The pool can still be used, but some features are "
8237 printf_color(ANSI_BOLD
, gettext("action: "));
8238 printf_color(ANSI_YELLOW
, gettext("Enable all features using "
8239 "'zpool upgrade'. Once this is done,\n\tthe pool may no "
8240 "longer be accessible by software that does not support\n\t"
8241 "the features. See zpool-features(5) for details.\n"));
8244 case ZPOOL_STATUS_COMPATIBILITY_ERR
:
8245 printf_color(ANSI_BOLD
, gettext("status: "));
8246 printf_color(ANSI_YELLOW
, gettext("This pool has a "
8247 "compatibility list specified, but it could not be\n\t"
8248 "read/parsed at this time. The pool can still be used, "
8249 "but this\n\tshould be investigated.\n"));
8250 printf_color(ANSI_BOLD
, gettext("action: "));
8251 printf_color(ANSI_YELLOW
, gettext("Check the value of the "
8252 "'compatibility' property against the\n\t"
8253 "appropriate file in " ZPOOL_SYSCONF_COMPAT_D
" or "
8254 ZPOOL_DATA_COMPAT_D
".\n"));
8257 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
8258 printf_color(ANSI_BOLD
, gettext("status: "));
8259 printf_color(ANSI_YELLOW
, gettext("The pool cannot be accessed "
8260 "on this system because it uses the\n\tfollowing feature(s)"
8261 " not supported on this system:\n"));
8262 zpool_print_unsup_feat(config
);
8263 (void) printf("\n");
8264 printf_color(ANSI_BOLD
, gettext("action: "));
8265 printf_color(ANSI_YELLOW
, gettext("Access the pool from a "
8266 "system that supports the required feature(s),\n\tor "
8267 "restore the pool from backup.\n"));
8270 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
8271 printf_color(ANSI_BOLD
, gettext("status: "));
8272 printf_color(ANSI_YELLOW
, gettext("The pool can only be "
8273 "accessed in read-only mode on this system. It\n\tcannot be"
8274 " accessed in read-write mode because it uses the "
8275 "following\n\tfeature(s) not supported on this system:\n"));
8276 zpool_print_unsup_feat(config
);
8277 (void) printf("\n");
8278 printf_color(ANSI_BOLD
, gettext("action: "));
8279 printf_color(ANSI_YELLOW
, gettext("The pool cannot be accessed "
8280 "in read-write mode. Import the pool with\n"
8281 "\t\"-o readonly=on\", access the pool from a system that "
8282 "supports the\n\trequired feature(s), or restore the "
8283 "pool from backup.\n"));
8286 case ZPOOL_STATUS_FAULTED_DEV_R
:
8287 printf_color(ANSI_BOLD
, gettext("status: "));
8288 printf_color(ANSI_YELLOW
, gettext("One or more devices are "
8289 "faulted in response to persistent errors.\n\tSufficient "
8290 "replicas exist for the pool to continue functioning "
8291 "in a\n\tdegraded state.\n"));
8292 printf_color(ANSI_BOLD
, gettext("action: "));
8293 printf_color(ANSI_YELLOW
, gettext("Replace the faulted device, "
8294 "or use 'zpool clear' to mark the device\n\trepaired.\n"));
8297 case ZPOOL_STATUS_FAULTED_DEV_NR
:
8298 printf_color(ANSI_BOLD
, gettext("status: "));
8299 printf_color(ANSI_YELLOW
, gettext("One or more devices are "
8300 "faulted in response to persistent errors. There are "
8301 "insufficient replicas for the pool to\n\tcontinue "
8303 printf_color(ANSI_BOLD
, gettext("action: "));
8304 printf_color(ANSI_YELLOW
, gettext("Destroy and re-create the "
8305 "pool from a backup source. Manually marking the device\n"
8306 "\trepaired using 'zpool clear' may allow some data "
8307 "to be recovered.\n"));
8310 case ZPOOL_STATUS_IO_FAILURE_MMP
:
8311 printf_color(ANSI_BOLD
, gettext("status: "));
8312 printf_color(ANSI_YELLOW
, gettext("The pool is suspended "
8313 "because multihost writes failed or were delayed;\n\t"
8314 "another system could import the pool undetected.\n"));
8315 printf_color(ANSI_BOLD
, gettext("action: "));
8316 printf_color(ANSI_YELLOW
, gettext("Make sure the pool's devices"
8317 " are connected, then reboot your system and\n\timport the "
8321 case ZPOOL_STATUS_IO_FAILURE_WAIT
:
8322 case ZPOOL_STATUS_IO_FAILURE_CONTINUE
:
8323 printf_color(ANSI_BOLD
, gettext("status: "));
8324 printf_color(ANSI_YELLOW
, gettext("One or more devices are "
8325 "faulted in response to IO failures.\n"));
8326 printf_color(ANSI_BOLD
, gettext("action: "));
8327 printf_color(ANSI_YELLOW
, gettext("Make sure the affected "
8328 "devices are connected, then run 'zpool clear'.\n"));
8331 case ZPOOL_STATUS_BAD_LOG
:
8332 printf_color(ANSI_BOLD
, gettext("status: "));
8333 printf_color(ANSI_YELLOW
, gettext("An intent log record "
8334 "could not be read.\n"
8335 "\tWaiting for administrator intervention to fix the "
8336 "faulted pool.\n"));
8337 printf_color(ANSI_BOLD
, gettext("action: "));
8338 printf_color(ANSI_YELLOW
, gettext("Either restore the affected "
8339 "device(s) and run 'zpool online',\n"
8340 "\tor ignore the intent log records by running "
8341 "'zpool clear'.\n"));
8344 case ZPOOL_STATUS_NON_NATIVE_ASHIFT
:
8345 (void) printf(gettext("status: One or more devices are "
8346 "configured to use a non-native block size.\n"
8347 "\tExpect reduced performance.\n"));
8348 (void) printf(gettext("action: Replace affected devices with "
8349 "devices that support the\n\tconfigured block size, or "
8350 "migrate data to a properly configured\n\tpool.\n"));
8353 case ZPOOL_STATUS_HOSTID_MISMATCH
:
8354 printf_color(ANSI_BOLD
, gettext("status: "));
8355 printf_color(ANSI_YELLOW
, gettext("Mismatch between pool hostid"
8356 " and system hostid on imported pool.\n\tThis pool was "
8357 "previously imported into a system with a different "
8358 "hostid,\n\tand then was verbatim imported into this "
8360 printf_color(ANSI_BOLD
, gettext("action: "));
8361 printf_color(ANSI_YELLOW
, gettext("Export this pool on all "
8362 "systems on which it is imported.\n"
8363 "\tThen import it to correct the mismatch.\n"));
8366 case ZPOOL_STATUS_ERRATA
:
8367 printf_color(ANSI_BOLD
, gettext("status: "));
8368 printf_color(ANSI_YELLOW
, gettext("Errata #%d detected.\n"),
8372 case ZPOOL_ERRATA_NONE
:
8375 case ZPOOL_ERRATA_ZOL_2094_SCRUB
:
8376 printf_color(ANSI_BOLD
, gettext("action: "));
8377 printf_color(ANSI_YELLOW
, gettext("To correct the issue"
8378 " run 'zpool scrub'.\n"));
8381 case ZPOOL_ERRATA_ZOL_6845_ENCRYPTION
:
8382 (void) printf(gettext("\tExisting encrypted datasets "
8383 "contain an on-disk incompatibility\n\twhich "
8384 "needs to be corrected.\n"));
8385 printf_color(ANSI_BOLD
, gettext("action: "));
8386 printf_color(ANSI_YELLOW
, gettext("To correct the issue"
8387 " backup existing encrypted datasets to new\n\t"
8388 "encrypted datasets and destroy the old ones. "
8389 "'zfs mount -o ro' can\n\tbe used to temporarily "
8390 "mount existing encrypted datasets readonly.\n"));
8393 case ZPOOL_ERRATA_ZOL_8308_ENCRYPTION
:
8394 (void) printf(gettext("\tExisting encrypted snapshots "
8395 "and bookmarks contain an on-disk\n\tincompat"
8396 "ibility. This may cause on-disk corruption if "
8397 "they are used\n\twith 'zfs recv'.\n"));
8398 printf_color(ANSI_BOLD
, gettext("action: "));
8399 printf_color(ANSI_YELLOW
, gettext("To correct the"
8400 "issue, enable the bookmark_v2 feature. No "
8401 "additional\n\taction is needed if there are no "
8402 "encrypted snapshots or bookmarks.\n\tIf preserving"
8403 "the encrypted snapshots and bookmarks is required,"
8404 " use\n\ta non-raw send to backup and restore them."
8405 " Alternately, they may be\n\tremoved to resolve "
8406 "the incompatibility.\n"));
8411 * All errata which allow the pool to be imported
8412 * must contain an action message.
8420 * The remaining errors can't actually be generated, yet.
8422 assert(reason
== ZPOOL_STATUS_OK
);
8425 if (msgid
!= NULL
) {
8427 printf_color(ANSI_BOLD
, gettext("see:"));
8429 " https://openzfs.github.io/openzfs-docs/msg/%s\n"),
8433 if (config
!= NULL
) {
8435 nvlist_t
**spares
, **l2cache
;
8436 uint_t nspares
, nl2cache
;
8437 pool_checkpoint_stat_t
*pcs
= NULL
;
8438 pool_removal_stat_t
*prs
= NULL
;
8440 print_scan_status(zhp
, nvroot
);
8442 (void) nvlist_lookup_uint64_array(nvroot
,
8443 ZPOOL_CONFIG_REMOVAL_STATS
, (uint64_t **)&prs
, &c
);
8444 print_removal_status(zhp
, prs
);
8446 (void) nvlist_lookup_uint64_array(nvroot
,
8447 ZPOOL_CONFIG_CHECKPOINT_STATS
, (uint64_t **)&pcs
, &c
);
8448 print_checkpoint_status(pcs
);
8450 cbp
->cb_namewidth
= max_width(zhp
, nvroot
, 0, 0,
8451 cbp
->cb_name_flags
| VDEV_NAME_TYPE_ID
);
8452 if (cbp
->cb_namewidth
< 10)
8453 cbp
->cb_namewidth
= 10;
8455 color_start(ANSI_BOLD
);
8456 (void) printf(gettext("config:\n\n"));
8457 (void) printf(gettext("\t%-*s %-8s %5s %5s %5s"),
8458 cbp
->cb_namewidth
, "NAME", "STATE", "READ", "WRITE",
8462 if (cbp
->cb_print_slow_ios
) {
8463 printf_color(ANSI_BOLD
, " %5s", gettext("SLOW"));
8466 if (cbp
->vcdl
!= NULL
)
8467 print_cmd_columns(cbp
->vcdl
, 0);
8471 print_status_config(zhp
, cbp
, zpool_get_name(zhp
), nvroot
, 0,
8474 print_class_vdevs(zhp
, cbp
, nvroot
, VDEV_ALLOC_BIAS_DEDUP
);
8475 print_class_vdevs(zhp
, cbp
, nvroot
, VDEV_ALLOC_BIAS_SPECIAL
);
8476 print_class_vdevs(zhp
, cbp
, nvroot
, VDEV_ALLOC_CLASS_LOGS
);
8478 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_L2CACHE
,
8479 &l2cache
, &nl2cache
) == 0)
8480 print_l2cache(zhp
, cbp
, l2cache
, nl2cache
);
8482 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_SPARES
,
8483 &spares
, &nspares
) == 0)
8484 print_spares(zhp
, cbp
, spares
, nspares
);
8486 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_ERRCOUNT
,
8488 nvlist_t
*nverrlist
= NULL
;
8491 * If the approximate error count is small, get a
8492 * precise count by fetching the entire log and
8493 * uniquifying the results.
8495 if (nerr
> 0 && nerr
< 100 && !cbp
->cb_verbose
&&
8496 zpool_get_errlog(zhp
, &nverrlist
) == 0) {
8501 while ((elem
= nvlist_next_nvpair(nverrlist
,
8506 nvlist_free(nverrlist
);
8508 (void) printf("\n");
8511 (void) printf(gettext("errors: No known data "
8513 else if (!cbp
->cb_verbose
)
8514 (void) printf(gettext("errors: %llu data "
8515 "errors, use '-v' for a list\n"),
8516 (u_longlong_t
)nerr
);
8518 print_error_log(zhp
);
8521 if (cbp
->cb_dedup_stats
)
8522 print_dedup_stats(config
);
8524 (void) printf(gettext("config: The configuration cannot be "
8532 * zpool status [-c [script1,script2,...]] [-igLpPstvx] [-T d|u] [pool] ...
8533 * [interval [count]]
8535 * -c CMD For each vdev, run command CMD
8536 * -i Display vdev initialization status.
8537 * -g Display guid for individual vdev name.
8538 * -L Follow links when resolving vdev path name.
8539 * -p Display values in parsable (exact) format.
8540 * -P Display full path for vdev name.
8541 * -s Display slow IOs column.
8542 * -v Display complete error logs
8543 * -x Display only pools with potential problems
8544 * -D Display dedup status (undocumented)
8545 * -t Display vdev TRIM status.
8546 * -T Display a timestamp in date(1) or Unix format
8548 * Describes the health status of all pools or some subset.
8551 zpool_do_status(int argc
, char **argv
)
8556 unsigned long count
= 0;
8557 status_cbdata_t cb
= { 0 };
8561 while ((c
= getopt(argc
, argv
, "c:igLpPsvxDtT:")) != -1) {
8566 gettext("Can't set -c flag twice\n"));
8570 if (getenv("ZPOOL_SCRIPTS_ENABLED") != NULL
&&
8571 !libzfs_envvar_is_set("ZPOOL_SCRIPTS_ENABLED")) {
8572 fprintf(stderr
, gettext(
8573 "Can't run -c, disabled by "
8574 "ZPOOL_SCRIPTS_ENABLED.\n"));
8578 if ((getuid() <= 0 || geteuid() <= 0) &&
8579 !libzfs_envvar_is_set("ZPOOL_SCRIPTS_AS_ROOT")) {
8580 fprintf(stderr
, gettext(
8581 "Can't run -c with root privileges "
8582 "unless ZPOOL_SCRIPTS_AS_ROOT is set.\n"));
8588 cb
.cb_print_vdev_init
= B_TRUE
;
8591 cb
.cb_name_flags
|= VDEV_NAME_GUID
;
8594 cb
.cb_name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
8597 cb
.cb_literal
= B_TRUE
;
8600 cb
.cb_name_flags
|= VDEV_NAME_PATH
;
8603 cb
.cb_print_slow_ios
= B_TRUE
;
8606 cb
.cb_verbose
= B_TRUE
;
8609 cb
.cb_explain
= B_TRUE
;
8612 cb
.cb_dedup_stats
= B_TRUE
;
8615 cb
.cb_print_vdev_trim
= B_TRUE
;
8618 get_timestamp_arg(*optarg
);
8621 if (optopt
== 'c') {
8622 print_zpool_script_list("status");
8626 gettext("invalid option '%c'\n"), optopt
);
8635 get_interval_count(&argc
, argv
, &interval
, &count
);
8638 cb
.cb_allpools
= B_TRUE
;
8640 cb
.cb_first
= B_TRUE
;
8641 cb
.cb_print_status
= B_TRUE
;
8644 if (timestamp_fmt
!= NODATE
)
8645 print_timestamp(timestamp_fmt
);
8648 cb
.vcdl
= all_pools_for_each_vdev_run(argc
, argv
, cmd
,
8651 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
, cb
.cb_literal
,
8652 status_callback
, &cb
);
8654 if (cb
.vcdl
!= NULL
)
8655 free_vdev_cmd_data_list(cb
.vcdl
);
8657 if (argc
== 0 && cb
.cb_count
== 0)
8658 (void) fprintf(stderr
, gettext("no pools available\n"));
8659 else if (cb
.cb_explain
&& cb
.cb_first
&& cb
.cb_allpools
)
8660 (void) printf(gettext("all pools are healthy\n"));
8668 if (count
!= 0 && --count
== 0)
8671 (void) fsleep(interval
);
8677 typedef struct upgrade_cbdata
{
8680 uint64_t cb_version
;
8685 check_unsupp_fs(zfs_handle_t
*zhp
, void *unsupp_fs
)
8687 int zfs_version
= (int)zfs_prop_get_int(zhp
, ZFS_PROP_VERSION
);
8688 int *count
= (int *)unsupp_fs
;
8690 if (zfs_version
> ZPL_VERSION
) {
8691 (void) printf(gettext("%s (v%d) is not supported by this "
8692 "implementation of ZFS.\n"),
8693 zfs_get_name(zhp
), zfs_version
);
8697 zfs_iter_filesystems(zhp
, check_unsupp_fs
, unsupp_fs
);
8705 upgrade_version(zpool_handle_t
*zhp
, uint64_t version
)
8709 uint64_t oldversion
;
8712 config
= zpool_get_config(zhp
, NULL
);
8713 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
8716 assert(SPA_VERSION_IS_SUPPORTED(oldversion
));
8717 assert(oldversion
< version
);
8719 ret
= zfs_iter_root(zpool_get_handle(zhp
), check_unsupp_fs
, &unsupp_fs
);
8724 (void) fprintf(stderr
, gettext("Upgrade not performed due "
8725 "to %d unsupported filesystems (max v%d).\n"),
8726 unsupp_fs
, (int)ZPL_VERSION
);
8730 ret
= zpool_upgrade(zhp
, version
);
8734 if (version
>= SPA_VERSION_FEATURES
) {
8735 (void) printf(gettext("Successfully upgraded "
8736 "'%s' from version %llu to feature flags.\n"),
8737 zpool_get_name(zhp
), (u_longlong_t
)oldversion
);
8739 (void) printf(gettext("Successfully upgraded "
8740 "'%s' from version %llu to version %llu.\n"),
8741 zpool_get_name(zhp
), (u_longlong_t
)oldversion
,
8742 (u_longlong_t
)version
);
8749 upgrade_enable_all(zpool_handle_t
*zhp
, int *countp
)
8752 boolean_t firstff
= B_TRUE
;
8753 nvlist_t
*enabled
= zpool_get_features(zhp
);
8755 char compat
[ZFS_MAXPROPLEN
];
8756 if (zpool_get_prop(zhp
, ZPOOL_PROP_COMPATIBILITY
, compat
,
8757 ZFS_MAXPROPLEN
, NULL
, B_FALSE
) != 0)
8760 boolean_t requested_features
[SPA_FEATURES
];
8761 if (zpool_do_load_compat(compat
, requested_features
) !=
8762 ZPOOL_COMPATIBILITY_OK
)
8766 for (i
= 0; i
< SPA_FEATURES
; i
++) {
8767 const char *fname
= spa_feature_table
[i
].fi_uname
;
8768 const char *fguid
= spa_feature_table
[i
].fi_guid
;
8770 if (!spa_feature_table
[i
].fi_zfs_mod_supported
)
8773 if (!nvlist_exists(enabled
, fguid
) && requested_features
[i
]) {
8775 verify(-1 != asprintf(&propname
, "feature@%s", fname
));
8776 ret
= zpool_set_prop(zhp
, propname
,
8777 ZFS_FEATURE_ENABLED
);
8785 (void) printf(gettext("Enabled the "
8786 "following features on '%s':\n"),
8787 zpool_get_name(zhp
));
8790 (void) printf(gettext(" %s\n"), fname
);
8801 upgrade_cb(zpool_handle_t
*zhp
, void *arg
)
8803 upgrade_cbdata_t
*cbp
= arg
;
8806 boolean_t printnl
= B_FALSE
;
8809 config
= zpool_get_config(zhp
, NULL
);
8810 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
8813 assert(SPA_VERSION_IS_SUPPORTED(version
));
8815 if (version
< cbp
->cb_version
) {
8816 cbp
->cb_first
= B_FALSE
;
8817 ret
= upgrade_version(zhp
, cbp
->cb_version
);
8823 * If they did "zpool upgrade -a", then we could
8824 * be doing ioctls to different pools. We need
8825 * to log this history once to each pool, and bypass
8826 * the normal history logging that happens in main().
8828 (void) zpool_log_history(g_zfs
, history_str
);
8829 log_history
= B_FALSE
;
8832 if (cbp
->cb_version
>= SPA_VERSION_FEATURES
) {
8834 ret
= upgrade_enable_all(zhp
, &count
);
8839 cbp
->cb_first
= B_FALSE
;
8845 (void) printf(gettext("\n"));
8852 upgrade_list_older_cb(zpool_handle_t
*zhp
, void *arg
)
8854 upgrade_cbdata_t
*cbp
= arg
;
8858 config
= zpool_get_config(zhp
, NULL
);
8859 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
8862 assert(SPA_VERSION_IS_SUPPORTED(version
));
8864 if (version
< SPA_VERSION_FEATURES
) {
8865 if (cbp
->cb_first
) {
8866 (void) printf(gettext("The following pools are "
8867 "formatted with legacy version numbers and can\n"
8868 "be upgraded to use feature flags. After "
8869 "being upgraded, these pools\nwill no "
8870 "longer be accessible by software that does not "
8871 "support feature\nflags.\n\n"));
8872 (void) printf(gettext("VER POOL\n"));
8873 (void) printf(gettext("--- ------------\n"));
8874 cbp
->cb_first
= B_FALSE
;
8877 (void) printf("%2llu %s\n", (u_longlong_t
)version
,
8878 zpool_get_name(zhp
));
8885 upgrade_list_disabled_cb(zpool_handle_t
*zhp
, void *arg
)
8887 upgrade_cbdata_t
*cbp
= arg
;
8891 config
= zpool_get_config(zhp
, NULL
);
8892 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
8895 if (version
>= SPA_VERSION_FEATURES
) {
8897 boolean_t poolfirst
= B_TRUE
;
8898 nvlist_t
*enabled
= zpool_get_features(zhp
);
8900 for (i
= 0; i
< SPA_FEATURES
; i
++) {
8901 const char *fguid
= spa_feature_table
[i
].fi_guid
;
8902 const char *fname
= spa_feature_table
[i
].fi_uname
;
8904 if (!spa_feature_table
[i
].fi_zfs_mod_supported
)
8907 if (!nvlist_exists(enabled
, fguid
)) {
8908 if (cbp
->cb_first
) {
8909 (void) printf(gettext("\nSome "
8910 "supported features are not "
8911 "enabled on the following pools. "
8912 "Once a\nfeature is enabled the "
8913 "pool may become incompatible with "
8914 "software\nthat does not support "
8916 "zpool-features(5) for "
8918 (void) printf(gettext("POOL "
8920 (void) printf(gettext("------"
8922 cbp
->cb_first
= B_FALSE
;
8926 (void) printf(gettext("%s\n"),
8927 zpool_get_name(zhp
));
8928 poolfirst
= B_FALSE
;
8931 (void) printf(gettext(" %s\n"), fname
);
8934 * If they did "zpool upgrade -a", then we could
8935 * be doing ioctls to different pools. We need
8936 * to log this history once to each pool, and bypass
8937 * the normal history logging that happens in main().
8939 (void) zpool_log_history(g_zfs
, history_str
);
8940 log_history
= B_FALSE
;
8949 upgrade_one(zpool_handle_t
*zhp
, void *data
)
8951 boolean_t printnl
= B_FALSE
;
8952 upgrade_cbdata_t
*cbp
= data
;
8953 uint64_t cur_version
;
8956 if (strcmp("log", zpool_get_name(zhp
)) == 0) {
8957 (void) fprintf(stderr
, gettext("'log' is now a reserved word\n"
8958 "Pool 'log' must be renamed using export and import"
8963 cur_version
= zpool_get_prop_int(zhp
, ZPOOL_PROP_VERSION
, NULL
);
8964 if (cur_version
> cbp
->cb_version
) {
8965 (void) printf(gettext("Pool '%s' is already formatted "
8966 "using more current version '%llu'.\n\n"),
8967 zpool_get_name(zhp
), (u_longlong_t
)cur_version
);
8971 if (cbp
->cb_version
!= SPA_VERSION
&& cur_version
== cbp
->cb_version
) {
8972 (void) printf(gettext("Pool '%s' is already formatted "
8973 "using version %llu.\n\n"), zpool_get_name(zhp
),
8974 (u_longlong_t
)cbp
->cb_version
);
8978 if (cur_version
!= cbp
->cb_version
) {
8980 ret
= upgrade_version(zhp
, cbp
->cb_version
);
8985 if (cbp
->cb_version
>= SPA_VERSION_FEATURES
) {
8987 ret
= upgrade_enable_all(zhp
, &count
);
8993 } else if (cur_version
== SPA_VERSION
) {
8994 (void) printf(gettext("Pool '%s' already has all "
8995 "supported and requested features enabled.\n"),
8996 zpool_get_name(zhp
));
9001 (void) printf(gettext("\n"));
9010 * zpool upgrade [-V version] <-a | pool ...>
9012 * With no arguments, display downrev'd ZFS pool available for upgrade.
9013 * Individual pools can be upgraded by specifying the pool, and '-a' will
9014 * upgrade all pools.
9017 zpool_do_upgrade(int argc
, char **argv
)
9020 upgrade_cbdata_t cb
= { 0 };
9022 boolean_t showversions
= B_FALSE
;
9023 boolean_t upgradeall
= B_FALSE
;
9028 while ((c
= getopt(argc
, argv
, ":avV:")) != -1) {
9031 upgradeall
= B_TRUE
;
9034 showversions
= B_TRUE
;
9037 cb
.cb_version
= strtoll(optarg
, &end
, 10);
9039 !SPA_VERSION_IS_SUPPORTED(cb
.cb_version
)) {
9040 (void) fprintf(stderr
,
9041 gettext("invalid version '%s'\n"), optarg
);
9046 (void) fprintf(stderr
, gettext("missing argument for "
9047 "'%c' option\n"), optopt
);
9051 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
9062 if (cb
.cb_version
== 0) {
9063 cb
.cb_version
= SPA_VERSION
;
9064 } else if (!upgradeall
&& argc
== 0) {
9065 (void) fprintf(stderr
, gettext("-V option is "
9066 "incompatible with other arguments\n"));
9071 if (upgradeall
|| argc
!= 0) {
9072 (void) fprintf(stderr
, gettext("-v option is "
9073 "incompatible with other arguments\n"));
9076 } else if (upgradeall
) {
9078 (void) fprintf(stderr
, gettext("-a option should not "
9079 "be used along with a pool name\n"));
9084 (void) printf(gettext("This system supports ZFS pool feature "
9089 (void) printf(gettext("The following features are "
9091 (void) printf(gettext("FEAT DESCRIPTION\n"));
9092 (void) printf("----------------------------------------------"
9093 "---------------\n");
9094 for (i
= 0; i
< SPA_FEATURES
; i
++) {
9095 zfeature_info_t
*fi
= &spa_feature_table
[i
];
9096 if (!fi
->fi_zfs_mod_supported
)
9099 (fi
->fi_flags
& ZFEATURE_FLAG_READONLY_COMPAT
) ?
9100 " (read-only compatible)" : "";
9102 (void) printf("%-37s%s\n", fi
->fi_uname
, ro
);
9103 (void) printf(" %s\n", fi
->fi_desc
);
9105 (void) printf("\n");
9107 (void) printf(gettext("The following legacy versions are also "
9109 (void) printf(gettext("VER DESCRIPTION\n"));
9110 (void) printf("--- -----------------------------------------"
9111 "---------------\n");
9112 (void) printf(gettext(" 1 Initial ZFS version\n"));
9113 (void) printf(gettext(" 2 Ditto blocks "
9114 "(replicated metadata)\n"));
9115 (void) printf(gettext(" 3 Hot spares and double parity "
9117 (void) printf(gettext(" 4 zpool history\n"));
9118 (void) printf(gettext(" 5 Compression using the gzip "
9120 (void) printf(gettext(" 6 bootfs pool property\n"));
9121 (void) printf(gettext(" 7 Separate intent log devices\n"));
9122 (void) printf(gettext(" 8 Delegated administration\n"));
9123 (void) printf(gettext(" 9 refquota and refreservation "
9125 (void) printf(gettext(" 10 Cache devices\n"));
9126 (void) printf(gettext(" 11 Improved scrub performance\n"));
9127 (void) printf(gettext(" 12 Snapshot properties\n"));
9128 (void) printf(gettext(" 13 snapused property\n"));
9129 (void) printf(gettext(" 14 passthrough-x aclinherit\n"));
9130 (void) printf(gettext(" 15 user/group space accounting\n"));
9131 (void) printf(gettext(" 16 stmf property support\n"));
9132 (void) printf(gettext(" 17 Triple-parity RAID-Z\n"));
9133 (void) printf(gettext(" 18 Snapshot user holds\n"));
9134 (void) printf(gettext(" 19 Log device removal\n"));
9135 (void) printf(gettext(" 20 Compression using zle "
9136 "(zero-length encoding)\n"));
9137 (void) printf(gettext(" 21 Deduplication\n"));
9138 (void) printf(gettext(" 22 Received properties\n"));
9139 (void) printf(gettext(" 23 Slim ZIL\n"));
9140 (void) printf(gettext(" 24 System attributes\n"));
9141 (void) printf(gettext(" 25 Improved scrub stats\n"));
9142 (void) printf(gettext(" 26 Improved snapshot deletion "
9144 (void) printf(gettext(" 27 Improved snapshot creation "
9146 (void) printf(gettext(" 28 Multiple vdev replacements\n"));
9147 (void) printf(gettext("\nFor more information on a particular "
9148 "version, including supported releases,\n"));
9149 (void) printf(gettext("see the ZFS Administration Guide.\n\n"));
9150 } else if (argc
== 0 && upgradeall
) {
9151 cb
.cb_first
= B_TRUE
;
9152 ret
= zpool_iter(g_zfs
, upgrade_cb
, &cb
);
9153 if (ret
== 0 && cb
.cb_first
) {
9154 if (cb
.cb_version
== SPA_VERSION
) {
9155 (void) printf(gettext("All pools are already "
9156 "formatted using feature flags.\n\n"));
9157 (void) printf(gettext("Every feature flags "
9158 "pool already has all supported and "
9159 "requested features enabled.\n"));
9161 (void) printf(gettext("All pools are already "
9162 "formatted with version %llu or higher.\n"),
9163 (u_longlong_t
)cb
.cb_version
);
9166 } else if (argc
== 0) {
9167 cb
.cb_first
= B_TRUE
;
9168 ret
= zpool_iter(g_zfs
, upgrade_list_older_cb
, &cb
);
9172 (void) printf(gettext("All pools are formatted "
9173 "using feature flags.\n\n"));
9175 (void) printf(gettext("\nUse 'zpool upgrade -v' "
9176 "for a list of available legacy versions.\n"));
9179 cb
.cb_first
= B_TRUE
;
9180 ret
= zpool_iter(g_zfs
, upgrade_list_disabled_cb
, &cb
);
9184 (void) printf(gettext("Every feature flags pool has "
9185 "all supported and requested features enabled.\n"));
9187 (void) printf(gettext("\n"));
9190 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
, B_FALSE
,
9197 typedef struct hist_cbdata
{
9204 print_history_records(nvlist_t
*nvhis
, hist_cbdata_t
*cb
)
9210 verify(nvlist_lookup_nvlist_array(nvhis
, ZPOOL_HIST_RECORD
,
9211 &records
, &numrecords
) == 0);
9212 for (i
= 0; i
< numrecords
; i
++) {
9213 nvlist_t
*rec
= records
[i
];
9216 if (nvlist_exists(rec
, ZPOOL_HIST_TIME
)) {
9220 tsec
= fnvlist_lookup_uint64(records
[i
],
9222 (void) localtime_r(&tsec
, &t
);
9223 (void) strftime(tbuf
, sizeof (tbuf
), "%F.%T", &t
);
9226 if (nvlist_exists(rec
, ZPOOL_HIST_ELAPSED_NS
)) {
9227 uint64_t elapsed_ns
= fnvlist_lookup_int64(records
[i
],
9228 ZPOOL_HIST_ELAPSED_NS
);
9229 (void) snprintf(tbuf
+ strlen(tbuf
),
9230 sizeof (tbuf
) - strlen(tbuf
),
9231 " (%lldms)", (long long)elapsed_ns
/ 1000 / 1000);
9234 if (nvlist_exists(rec
, ZPOOL_HIST_CMD
)) {
9235 (void) printf("%s %s", tbuf
,
9236 fnvlist_lookup_string(rec
, ZPOOL_HIST_CMD
));
9237 } else if (nvlist_exists(rec
, ZPOOL_HIST_INT_EVENT
)) {
9239 fnvlist_lookup_uint64(rec
, ZPOOL_HIST_INT_EVENT
);
9242 if (ievent
>= ZFS_NUM_LEGACY_HISTORY_EVENTS
) {
9243 (void) printf("%s unrecognized record:\n",
9245 dump_nvlist(rec
, 4);
9248 (void) printf("%s [internal %s txg:%lld] %s", tbuf
,
9249 zfs_history_event_names
[ievent
],
9250 (longlong_t
)fnvlist_lookup_uint64(
9251 rec
, ZPOOL_HIST_TXG
),
9252 fnvlist_lookup_string(rec
, ZPOOL_HIST_INT_STR
));
9253 } else if (nvlist_exists(rec
, ZPOOL_HIST_INT_NAME
)) {
9256 (void) printf("%s [txg:%lld] %s", tbuf
,
9257 (longlong_t
)fnvlist_lookup_uint64(
9258 rec
, ZPOOL_HIST_TXG
),
9259 fnvlist_lookup_string(rec
, ZPOOL_HIST_INT_NAME
));
9260 if (nvlist_exists(rec
, ZPOOL_HIST_DSNAME
)) {
9261 (void) printf(" %s (%llu)",
9262 fnvlist_lookup_string(rec
,
9264 (u_longlong_t
)fnvlist_lookup_uint64(rec
,
9267 (void) printf(" %s", fnvlist_lookup_string(rec
,
9268 ZPOOL_HIST_INT_STR
));
9269 } else if (nvlist_exists(rec
, ZPOOL_HIST_IOCTL
)) {
9272 (void) printf("%s ioctl %s\n", tbuf
,
9273 fnvlist_lookup_string(rec
, ZPOOL_HIST_IOCTL
));
9274 if (nvlist_exists(rec
, ZPOOL_HIST_INPUT_NVL
)) {
9275 (void) printf(" input:\n");
9276 dump_nvlist(fnvlist_lookup_nvlist(rec
,
9277 ZPOOL_HIST_INPUT_NVL
), 8);
9279 if (nvlist_exists(rec
, ZPOOL_HIST_OUTPUT_NVL
)) {
9280 (void) printf(" output:\n");
9281 dump_nvlist(fnvlist_lookup_nvlist(rec
,
9282 ZPOOL_HIST_OUTPUT_NVL
), 8);
9284 if (nvlist_exists(rec
, ZPOOL_HIST_OUTPUT_SIZE
)) {
9285 (void) printf(" output nvlist omitted; "
9286 "original size: %lldKB\n",
9287 (longlong_t
)fnvlist_lookup_int64(rec
,
9288 ZPOOL_HIST_OUTPUT_SIZE
) / 1024);
9290 if (nvlist_exists(rec
, ZPOOL_HIST_ERRNO
)) {
9291 (void) printf(" errno: %lld\n",
9292 (longlong_t
)fnvlist_lookup_int64(rec
,
9298 (void) printf("%s unrecognized record:\n", tbuf
);
9299 dump_nvlist(rec
, 4);
9303 (void) printf("\n");
9306 (void) printf(" [");
9307 if (nvlist_exists(rec
, ZPOOL_HIST_WHO
)) {
9308 uid_t who
= fnvlist_lookup_uint64(rec
, ZPOOL_HIST_WHO
);
9309 struct passwd
*pwd
= getpwuid(who
);
9310 (void) printf("user %d ", (int)who
);
9312 (void) printf("(%s) ", pwd
->pw_name
);
9314 if (nvlist_exists(rec
, ZPOOL_HIST_HOST
)) {
9315 (void) printf("on %s",
9316 fnvlist_lookup_string(rec
, ZPOOL_HIST_HOST
));
9318 if (nvlist_exists(rec
, ZPOOL_HIST_ZONE
)) {
9319 (void) printf(":%s",
9320 fnvlist_lookup_string(rec
, ZPOOL_HIST_ZONE
));
9324 (void) printf("\n");
9329 * Print out the command history for a specific pool.
9332 get_history_one(zpool_handle_t
*zhp
, void *data
)
9336 hist_cbdata_t
*cb
= (hist_cbdata_t
*)data
;
9338 boolean_t eof
= B_FALSE
;
9340 cb
->first
= B_FALSE
;
9342 (void) printf(gettext("History for '%s':\n"), zpool_get_name(zhp
));
9345 if ((ret
= zpool_get_history(zhp
, &nvhis
, &off
, &eof
)) != 0)
9348 print_history_records(nvhis
, cb
);
9351 (void) printf("\n");
9357 * zpool history <pool>
9359 * Displays the history of commands that modified pools.
9362 zpool_do_history(int argc
, char **argv
)
9364 hist_cbdata_t cbdata
= { 0 };
9368 cbdata
.first
= B_TRUE
;
9370 while ((c
= getopt(argc
, argv
, "li")) != -1) {
9373 cbdata
.longfmt
= B_TRUE
;
9376 cbdata
.internal
= B_TRUE
;
9379 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
9387 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
, B_FALSE
, get_history_one
,
9390 if (argc
== 0 && cbdata
.first
== B_TRUE
) {
9391 (void) fprintf(stderr
, gettext("no pools available\n"));
9398 typedef struct ev_opts
{
9403 char poolname
[ZFS_MAX_DATASET_NAME_LEN
];
9407 zpool_do_events_short(nvlist_t
*nvl
, ev_opts_t
*opts
)
9409 char ctime_str
[26], str
[32], *ptr
;
9413 verify(nvlist_lookup_int64_array(nvl
, FM_EREPORT_TIME
, &tv
, &n
) == 0);
9414 memset(str
, ' ', 32);
9415 (void) ctime_r((const time_t *)&tv
[0], ctime_str
);
9416 (void) memcpy(str
, ctime_str
+4, 6); /* 'Jun 30' */
9417 (void) memcpy(str
+7, ctime_str
+20, 4); /* '1993' */
9418 (void) memcpy(str
+12, ctime_str
+11, 8); /* '21:49:08' */
9419 (void) sprintf(str
+20, ".%09lld", (longlong_t
)tv
[1]); /* '.123456789' */
9421 (void) printf(gettext("%s\t"), str
);
9423 (void) printf(gettext("%s "), str
);
9425 verify(nvlist_lookup_string(nvl
, FM_CLASS
, &ptr
) == 0);
9426 (void) printf(gettext("%s\n"), ptr
);
9430 zpool_do_events_nvprint(nvlist_t
*nvl
, int depth
)
9434 for (nvp
= nvlist_next_nvpair(nvl
, NULL
);
9435 nvp
!= NULL
; nvp
= nvlist_next_nvpair(nvl
, nvp
)) {
9437 data_type_t type
= nvpair_type(nvp
);
9438 const char *name
= nvpair_name(nvp
);
9448 printf(gettext("%*s%s = "), depth
, "", name
);
9451 case DATA_TYPE_BOOLEAN
:
9452 printf(gettext("%s"), "1");
9455 case DATA_TYPE_BOOLEAN_VALUE
:
9456 (void) nvpair_value_boolean_value(nvp
, &b
);
9457 printf(gettext("%s"), b
? "1" : "0");
9460 case DATA_TYPE_BYTE
:
9461 (void) nvpair_value_byte(nvp
, &i8
);
9462 printf(gettext("0x%x"), i8
);
9465 case DATA_TYPE_INT8
:
9466 (void) nvpair_value_int8(nvp
, (void *)&i8
);
9467 printf(gettext("0x%x"), i8
);
9470 case DATA_TYPE_UINT8
:
9471 (void) nvpair_value_uint8(nvp
, &i8
);
9472 printf(gettext("0x%x"), i8
);
9475 case DATA_TYPE_INT16
:
9476 (void) nvpair_value_int16(nvp
, (void *)&i16
);
9477 printf(gettext("0x%x"), i16
);
9480 case DATA_TYPE_UINT16
:
9481 (void) nvpair_value_uint16(nvp
, &i16
);
9482 printf(gettext("0x%x"), i16
);
9485 case DATA_TYPE_INT32
:
9486 (void) nvpair_value_int32(nvp
, (void *)&i32
);
9487 printf(gettext("0x%x"), i32
);
9490 case DATA_TYPE_UINT32
:
9491 (void) nvpair_value_uint32(nvp
, &i32
);
9492 printf(gettext("0x%x"), i32
);
9495 case DATA_TYPE_INT64
:
9496 (void) nvpair_value_int64(nvp
, (void *)&i64
);
9497 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
9500 case DATA_TYPE_UINT64
:
9501 (void) nvpair_value_uint64(nvp
, &i64
);
9503 * translate vdev state values to readable
9504 * strings to aide zpool events consumers
9507 FM_EREPORT_PAYLOAD_ZFS_VDEV_STATE
) == 0 ||
9509 FM_EREPORT_PAYLOAD_ZFS_VDEV_LASTSTATE
) == 0) {
9510 printf(gettext("\"%s\" (0x%llx)"),
9511 zpool_state_to_name(i64
, VDEV_AUX_NONE
),
9514 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
9518 case DATA_TYPE_HRTIME
:
9519 (void) nvpair_value_hrtime(nvp
, (void *)&i64
);
9520 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
9523 case DATA_TYPE_STRING
:
9524 (void) nvpair_value_string(nvp
, &str
);
9525 printf(gettext("\"%s\""), str
? str
: "<NULL>");
9528 case DATA_TYPE_NVLIST
:
9529 printf(gettext("(embedded nvlist)\n"));
9530 (void) nvpair_value_nvlist(nvp
, &cnv
);
9531 zpool_do_events_nvprint(cnv
, depth
+ 8);
9532 printf(gettext("%*s(end %s)"), depth
, "", name
);
9535 case DATA_TYPE_NVLIST_ARRAY
: {
9539 (void) nvpair_value_nvlist_array(nvp
, &val
, &nelem
);
9540 printf(gettext("(%d embedded nvlists)\n"), nelem
);
9541 for (i
= 0; i
< nelem
; i
++) {
9542 printf(gettext("%*s%s[%d] = %s\n"),
9543 depth
, "", name
, i
, "(embedded nvlist)");
9544 zpool_do_events_nvprint(val
[i
], depth
+ 8);
9545 printf(gettext("%*s(end %s[%i])\n"),
9546 depth
, "", name
, i
);
9548 printf(gettext("%*s(end %s)\n"), depth
, "", name
);
9552 case DATA_TYPE_INT8_ARRAY
: {
9556 (void) nvpair_value_int8_array(nvp
, &val
, &nelem
);
9557 for (i
= 0; i
< nelem
; i
++)
9558 printf(gettext("0x%x "), val
[i
]);
9563 case DATA_TYPE_UINT8_ARRAY
: {
9567 (void) nvpair_value_uint8_array(nvp
, &val
, &nelem
);
9568 for (i
= 0; i
< nelem
; i
++)
9569 printf(gettext("0x%x "), val
[i
]);
9574 case DATA_TYPE_INT16_ARRAY
: {
9578 (void) nvpair_value_int16_array(nvp
, &val
, &nelem
);
9579 for (i
= 0; i
< nelem
; i
++)
9580 printf(gettext("0x%x "), val
[i
]);
9585 case DATA_TYPE_UINT16_ARRAY
: {
9589 (void) nvpair_value_uint16_array(nvp
, &val
, &nelem
);
9590 for (i
= 0; i
< nelem
; i
++)
9591 printf(gettext("0x%x "), val
[i
]);
9596 case DATA_TYPE_INT32_ARRAY
: {
9600 (void) nvpair_value_int32_array(nvp
, &val
, &nelem
);
9601 for (i
= 0; i
< nelem
; i
++)
9602 printf(gettext("0x%x "), val
[i
]);
9607 case DATA_TYPE_UINT32_ARRAY
: {
9611 (void) nvpair_value_uint32_array(nvp
, &val
, &nelem
);
9612 for (i
= 0; i
< nelem
; i
++)
9613 printf(gettext("0x%x "), val
[i
]);
9618 case DATA_TYPE_INT64_ARRAY
: {
9622 (void) nvpair_value_int64_array(nvp
, &val
, &nelem
);
9623 for (i
= 0; i
< nelem
; i
++)
9624 printf(gettext("0x%llx "),
9625 (u_longlong_t
)val
[i
]);
9630 case DATA_TYPE_UINT64_ARRAY
: {
9634 (void) nvpair_value_uint64_array(nvp
, &val
, &nelem
);
9635 for (i
= 0; i
< nelem
; i
++)
9636 printf(gettext("0x%llx "),
9637 (u_longlong_t
)val
[i
]);
9642 case DATA_TYPE_STRING_ARRAY
: {
9646 (void) nvpair_value_string_array(nvp
, &str
, &nelem
);
9647 for (i
= 0; i
< nelem
; i
++)
9648 printf(gettext("\"%s\" "),
9649 str
[i
] ? str
[i
] : "<NULL>");
9654 case DATA_TYPE_BOOLEAN_ARRAY
:
9655 case DATA_TYPE_BYTE_ARRAY
:
9656 case DATA_TYPE_DOUBLE
:
9657 case DATA_TYPE_DONTCARE
:
9658 case DATA_TYPE_UNKNOWN
:
9659 printf(gettext("<unknown>"));
9663 printf(gettext("\n"));
9668 zpool_do_events_next(ev_opts_t
*opts
)
9671 int zevent_fd
, ret
, dropped
;
9674 zevent_fd
= open(ZFS_DEV
, O_RDWR
);
9675 VERIFY(zevent_fd
>= 0);
9677 if (!opts
->scripted
)
9678 (void) printf(gettext("%-30s %s\n"), "TIME", "CLASS");
9681 ret
= zpool_events_next(g_zfs
, &nvl
, &dropped
,
9682 (opts
->follow
? ZEVENT_NONE
: ZEVENT_NONBLOCK
), zevent_fd
);
9683 if (ret
|| nvl
== NULL
)
9687 (void) printf(gettext("dropped %d events\n"), dropped
);
9689 if (strlen(opts
->poolname
) > 0 &&
9690 nvlist_lookup_string(nvl
, FM_FMRI_ZFS_POOL
, &pool
) == 0 &&
9691 strcmp(opts
->poolname
, pool
) != 0)
9694 zpool_do_events_short(nvl
, opts
);
9696 if (opts
->verbose
) {
9697 zpool_do_events_nvprint(nvl
, 8);
9698 printf(gettext("\n"));
9700 (void) fflush(stdout
);
9705 VERIFY(0 == close(zevent_fd
));
9711 zpool_do_events_clear(ev_opts_t
*opts
)
9715 ret
= zpool_events_clear(g_zfs
, &count
);
9717 (void) printf(gettext("cleared %d events\n"), count
);
9723 * zpool events [-vHf [pool] | -c]
9725 * Displays events logs by ZFS.
9728 zpool_do_events(int argc
, char **argv
)
9730 ev_opts_t opts
= { 0 };
9735 while ((c
= getopt(argc
, argv
, "vHfc")) != -1) {
9750 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
9759 (void) fprintf(stderr
, gettext("too many arguments\n"));
9761 } else if (argc
== 1) {
9762 (void) strlcpy(opts
.poolname
, argv
[0], sizeof (opts
.poolname
));
9763 if (!zfs_name_valid(opts
.poolname
, ZFS_TYPE_POOL
)) {
9764 (void) fprintf(stderr
,
9765 gettext("invalid pool name '%s'\n"), opts
.poolname
);
9770 if ((argc
== 1 || opts
.verbose
|| opts
.scripted
|| opts
.follow
) &&
9772 (void) fprintf(stderr
,
9773 gettext("invalid options combined with -c\n"));
9778 ret
= zpool_do_events_clear(&opts
);
9780 ret
= zpool_do_events_next(&opts
);
9786 get_callback(zpool_handle_t
*zhp
, void *data
)
9788 zprop_get_cbdata_t
*cbp
= (zprop_get_cbdata_t
*)data
;
9789 char value
[MAXNAMELEN
];
9790 zprop_source_t srctype
;
9793 for (pl
= cbp
->cb_proplist
; pl
!= NULL
; pl
= pl
->pl_next
) {
9796 * Skip the special fake placeholder. This will also skip
9797 * over the name property when 'all' is specified.
9799 if (pl
->pl_prop
== ZPOOL_PROP_NAME
&&
9800 pl
== cbp
->cb_proplist
)
9803 if (pl
->pl_prop
== ZPROP_INVAL
&&
9804 (zpool_prop_feature(pl
->pl_user_prop
) ||
9805 zpool_prop_unsupported(pl
->pl_user_prop
))) {
9806 srctype
= ZPROP_SRC_LOCAL
;
9808 if (zpool_prop_get_feature(zhp
, pl
->pl_user_prop
,
9809 value
, sizeof (value
)) == 0) {
9810 zprop_print_one_property(zpool_get_name(zhp
),
9811 cbp
, pl
->pl_user_prop
, value
, srctype
,
9815 if (zpool_get_prop(zhp
, pl
->pl_prop
, value
,
9816 sizeof (value
), &srctype
, cbp
->cb_literal
) != 0)
9819 zprop_print_one_property(zpool_get_name(zhp
), cbp
,
9820 zpool_prop_to_name(pl
->pl_prop
), value
, srctype
,
9828 * zpool get [-Hp] [-o "all" | field[,...]] <"all" | property[,...]> <pool> ...
9830 * -H Scripted mode. Don't display headers, and separate properties
9832 * -o List of columns to display. Defaults to
9833 * "name,property,value,source".
9834 * -p Display values in parsable (exact) format.
9836 * Get properties of pools in the system. Output space statistics
9837 * for each one as well as other attributes.
9840 zpool_do_get(int argc
, char **argv
)
9842 zprop_get_cbdata_t cb
= { 0 };
9843 zprop_list_t fake_name
= { 0 };
9848 cb
.cb_first
= B_TRUE
;
9851 * Set up default columns and sources.
9853 cb
.cb_sources
= ZPROP_SRC_ALL
;
9854 cb
.cb_columns
[0] = GET_COL_NAME
;
9855 cb
.cb_columns
[1] = GET_COL_PROPERTY
;
9856 cb
.cb_columns
[2] = GET_COL_VALUE
;
9857 cb
.cb_columns
[3] = GET_COL_SOURCE
;
9858 cb
.cb_type
= ZFS_TYPE_POOL
;
9861 while ((c
= getopt(argc
, argv
, ":Hpo:")) != -1) {
9864 cb
.cb_literal
= B_TRUE
;
9867 cb
.cb_scripted
= B_TRUE
;
9870 bzero(&cb
.cb_columns
, sizeof (cb
.cb_columns
));
9872 while (*optarg
!= '\0') {
9873 static char *col_subopts
[] =
9874 { "name", "property", "value", "source",
9877 if (i
== ZFS_GET_NCOLS
) {
9878 (void) fprintf(stderr
, gettext("too "
9879 "many fields given to -o "
9884 switch (getsubopt(&optarg
, col_subopts
,
9887 cb
.cb_columns
[i
++] = GET_COL_NAME
;
9890 cb
.cb_columns
[i
++] = GET_COL_PROPERTY
;
9893 cb
.cb_columns
[i
++] = GET_COL_VALUE
;
9896 cb
.cb_columns
[i
++] = GET_COL_SOURCE
;
9900 (void) fprintf(stderr
,
9901 gettext("\"all\" conflicts "
9902 "with specific fields "
9903 "given to -o option\n"));
9906 cb
.cb_columns
[0] = GET_COL_NAME
;
9907 cb
.cb_columns
[1] = GET_COL_PROPERTY
;
9908 cb
.cb_columns
[2] = GET_COL_VALUE
;
9909 cb
.cb_columns
[3] = GET_COL_SOURCE
;
9913 (void) fprintf(stderr
,
9914 gettext("invalid column name "
9921 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
9931 (void) fprintf(stderr
, gettext("missing property "
9936 if (zprop_get_list(g_zfs
, argv
[0], &cb
.cb_proplist
,
9937 ZFS_TYPE_POOL
) != 0)
9943 if (cb
.cb_proplist
!= NULL
) {
9944 fake_name
.pl_prop
= ZPOOL_PROP_NAME
;
9945 fake_name
.pl_width
= strlen(gettext("NAME"));
9946 fake_name
.pl_next
= cb
.cb_proplist
;
9947 cb
.cb_proplist
= &fake_name
;
9950 ret
= for_each_pool(argc
, argv
, B_TRUE
, &cb
.cb_proplist
, cb
.cb_literal
,
9953 if (cb
.cb_proplist
== &fake_name
)
9954 zprop_free_list(fake_name
.pl_next
);
9956 zprop_free_list(cb
.cb_proplist
);
9961 typedef struct set_cbdata
{
9964 boolean_t cb_any_successful
;
9968 set_callback(zpool_handle_t
*zhp
, void *data
)
9971 set_cbdata_t
*cb
= (set_cbdata_t
*)data
;
9973 error
= zpool_set_prop(zhp
, cb
->cb_propname
, cb
->cb_value
);
9976 cb
->cb_any_successful
= B_TRUE
;
9982 zpool_do_set(int argc
, char **argv
)
9984 set_cbdata_t cb
= { 0 };
9987 if (argc
> 1 && argv
[1][0] == '-') {
9988 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
9994 (void) fprintf(stderr
, gettext("missing property=value "
10000 (void) fprintf(stderr
, gettext("missing pool name\n"));
10005 (void) fprintf(stderr
, gettext("too many pool names\n"));
10009 cb
.cb_propname
= argv
[1];
10010 cb
.cb_value
= strchr(cb
.cb_propname
, '=');
10011 if (cb
.cb_value
== NULL
) {
10012 (void) fprintf(stderr
, gettext("missing value in "
10013 "property=value argument\n"));
10017 *(cb
.cb_value
) = '\0';
10020 error
= for_each_pool(argc
- 2, argv
+ 2, B_TRUE
, NULL
, B_FALSE
,
10021 set_callback
, &cb
);
10026 /* Add up the total number of bytes left to initialize/trim across all vdevs */
10028 vdev_activity_remaining(nvlist_t
*nv
, zpool_wait_activity_t activity
)
10030 uint64_t bytes_remaining
;
10032 uint_t c
, children
;
10035 assert(activity
== ZPOOL_WAIT_INITIALIZE
||
10036 activity
== ZPOOL_WAIT_TRIM
);
10038 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
10039 (uint64_t **)&vs
, &c
) == 0);
10041 if (activity
== ZPOOL_WAIT_INITIALIZE
&&
10042 vs
->vs_initialize_state
== VDEV_INITIALIZE_ACTIVE
)
10043 bytes_remaining
= vs
->vs_initialize_bytes_est
-
10044 vs
->vs_initialize_bytes_done
;
10045 else if (activity
== ZPOOL_WAIT_TRIM
&&
10046 vs
->vs_trim_state
== VDEV_TRIM_ACTIVE
)
10047 bytes_remaining
= vs
->vs_trim_bytes_est
-
10048 vs
->vs_trim_bytes_done
;
10050 bytes_remaining
= 0;
10052 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
10053 &child
, &children
) != 0)
10056 for (c
= 0; c
< children
; c
++)
10057 bytes_remaining
+= vdev_activity_remaining(child
[c
], activity
);
10059 return (bytes_remaining
);
10062 /* Add up the total number of bytes left to rebuild across top-level vdevs */
10064 vdev_activity_top_remaining(nvlist_t
*nv
)
10066 uint64_t bytes_remaining
= 0;
10071 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
10072 &child
, &children
) != 0)
10075 for (uint_t c
= 0; c
< children
; c
++) {
10076 vdev_rebuild_stat_t
*vrs
;
10079 error
= nvlist_lookup_uint64_array(child
[c
],
10080 ZPOOL_CONFIG_REBUILD_STATS
, (uint64_t **)&vrs
, &i
);
10082 if (vrs
->vrs_state
== VDEV_REBUILD_ACTIVE
) {
10083 bytes_remaining
+= (vrs
->vrs_bytes_est
-
10084 vrs
->vrs_bytes_rebuilt
);
10089 return (bytes_remaining
);
10092 /* Whether any vdevs are 'spare' or 'replacing' vdevs */
10094 vdev_any_spare_replacing(nvlist_t
*nv
)
10097 uint_t c
, children
;
10100 (void) nvlist_lookup_string(nv
, ZPOOL_CONFIG_TYPE
, &vdev_type
);
10102 if (strcmp(vdev_type
, VDEV_TYPE_REPLACING
) == 0 ||
10103 strcmp(vdev_type
, VDEV_TYPE_SPARE
) == 0 ||
10104 strcmp(vdev_type
, VDEV_TYPE_DRAID_SPARE
) == 0) {
10108 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
10109 &child
, &children
) != 0)
10112 for (c
= 0; c
< children
; c
++) {
10113 if (vdev_any_spare_replacing(child
[c
]))
10120 typedef struct wait_data
{
10122 boolean_t wd_scripted
;
10123 boolean_t wd_exact
;
10124 boolean_t wd_headers_once
;
10125 boolean_t wd_should_exit
;
10126 /* Which activities to wait for */
10127 boolean_t wd_enabled
[ZPOOL_WAIT_NUM_ACTIVITIES
];
10129 pthread_cond_t wd_cv
;
10130 pthread_mutex_t wd_mutex
;
10134 * Print to stdout a single line, containing one column for each activity that
10135 * we are waiting for specifying how many bytes of work are left for that
10139 print_wait_status_row(wait_data_t
*wd
, zpool_handle_t
*zhp
, int row
)
10141 nvlist_t
*config
, *nvroot
;
10144 pool_checkpoint_stat_t
*pcs
= NULL
;
10145 pool_scan_stat_t
*pss
= NULL
;
10146 pool_removal_stat_t
*prs
= NULL
;
10147 char *headers
[] = {"DISCARD", "FREE", "INITIALIZE", "REPLACE",
10148 "REMOVE", "RESILVER", "SCRUB", "TRIM"};
10149 int col_widths
[ZPOOL_WAIT_NUM_ACTIVITIES
];
10151 /* Calculate the width of each column */
10152 for (i
= 0; i
< ZPOOL_WAIT_NUM_ACTIVITIES
; i
++) {
10154 * Make sure we have enough space in the col for pretty-printed
10155 * numbers and for the column header, and then leave a couple
10156 * spaces between cols for readability.
10158 col_widths
[i
] = MAX(strlen(headers
[i
]), 6) + 2;
10161 /* Print header if appropriate */
10162 int term_height
= terminal_height();
10163 boolean_t reprint_header
= (!wd
->wd_headers_once
&& term_height
> 0 &&
10164 row
% (term_height
-1) == 0);
10165 if (!wd
->wd_scripted
&& (row
== 0 || reprint_header
)) {
10166 for (i
= 0; i
< ZPOOL_WAIT_NUM_ACTIVITIES
; i
++) {
10167 if (wd
->wd_enabled
[i
])
10168 (void) printf("%*s", col_widths
[i
], headers
[i
]);
10170 (void) printf("\n");
10173 /* Bytes of work remaining in each activity */
10174 int64_t bytes_rem
[ZPOOL_WAIT_NUM_ACTIVITIES
] = {0};
10176 bytes_rem
[ZPOOL_WAIT_FREE
] =
10177 zpool_get_prop_int(zhp
, ZPOOL_PROP_FREEING
, NULL
);
10179 config
= zpool_get_config(zhp
, NULL
);
10180 nvroot
= fnvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
);
10182 (void) nvlist_lookup_uint64_array(nvroot
,
10183 ZPOOL_CONFIG_CHECKPOINT_STATS
, (uint64_t **)&pcs
, &c
);
10184 if (pcs
!= NULL
&& pcs
->pcs_state
== CS_CHECKPOINT_DISCARDING
)
10185 bytes_rem
[ZPOOL_WAIT_CKPT_DISCARD
] = pcs
->pcs_space
;
10187 (void) nvlist_lookup_uint64_array(nvroot
,
10188 ZPOOL_CONFIG_REMOVAL_STATS
, (uint64_t **)&prs
, &c
);
10189 if (prs
!= NULL
&& prs
->prs_state
== DSS_SCANNING
)
10190 bytes_rem
[ZPOOL_WAIT_REMOVE
] = prs
->prs_to_copy
-
10193 (void) nvlist_lookup_uint64_array(nvroot
,
10194 ZPOOL_CONFIG_SCAN_STATS
, (uint64_t **)&pss
, &c
);
10195 if (pss
!= NULL
&& pss
->pss_state
== DSS_SCANNING
&&
10196 pss
->pss_pass_scrub_pause
== 0) {
10197 int64_t rem
= pss
->pss_to_examine
- pss
->pss_issued
;
10198 if (pss
->pss_func
== POOL_SCAN_SCRUB
)
10199 bytes_rem
[ZPOOL_WAIT_SCRUB
] = rem
;
10201 bytes_rem
[ZPOOL_WAIT_RESILVER
] = rem
;
10202 } else if (check_rebuilding(nvroot
, NULL
)) {
10203 bytes_rem
[ZPOOL_WAIT_RESILVER
] =
10204 vdev_activity_top_remaining(nvroot
);
10207 bytes_rem
[ZPOOL_WAIT_INITIALIZE
] =
10208 vdev_activity_remaining(nvroot
, ZPOOL_WAIT_INITIALIZE
);
10209 bytes_rem
[ZPOOL_WAIT_TRIM
] =
10210 vdev_activity_remaining(nvroot
, ZPOOL_WAIT_TRIM
);
10213 * A replace finishes after resilvering finishes, so the amount of work
10214 * left for a replace is the same as for resilvering.
10216 * It isn't quite correct to say that if we have any 'spare' or
10217 * 'replacing' vdevs and a resilver is happening, then a replace is in
10218 * progress, like we do here. When a hot spare is used, the faulted vdev
10219 * is not removed after the hot spare is resilvered, so parent 'spare'
10220 * vdev is not removed either. So we could have a 'spare' vdev, but be
10221 * resilvering for a different reason. However, we use it as a heuristic
10222 * because we don't have access to the DTLs, which could tell us whether
10223 * or not we have really finished resilvering a hot spare.
10225 if (vdev_any_spare_replacing(nvroot
))
10226 bytes_rem
[ZPOOL_WAIT_REPLACE
] = bytes_rem
[ZPOOL_WAIT_RESILVER
];
10228 if (timestamp_fmt
!= NODATE
)
10229 print_timestamp(timestamp_fmt
);
10231 for (i
= 0; i
< ZPOOL_WAIT_NUM_ACTIVITIES
; i
++) {
10233 if (!wd
->wd_enabled
[i
])
10237 (void) snprintf(buf
, sizeof (buf
), "%" PRIi64
,
10240 zfs_nicenum(bytes_rem
[i
], buf
, sizeof (buf
));
10242 if (wd
->wd_scripted
)
10243 (void) printf(i
== 0 ? "%s" : "\t%s", buf
);
10245 (void) printf(" %*s", col_widths
[i
] - 1, buf
);
10247 (void) printf("\n");
10248 (void) fflush(stdout
);
10252 wait_status_thread(void *arg
)
10254 wait_data_t
*wd
= (wait_data_t
*)arg
;
10255 zpool_handle_t
*zhp
;
10257 if ((zhp
= zpool_open(g_zfs
, wd
->wd_poolname
)) == NULL
)
10258 return (void *)(1);
10260 for (int row
= 0; ; row
++) {
10262 struct timespec timeout
;
10264 (void) clock_gettime(CLOCK_REALTIME
, &timeout
);
10266 if (zpool_refresh_stats(zhp
, &missing
) != 0 || missing
||
10267 zpool_props_refresh(zhp
) != 0) {
10269 return (void *)(uintptr_t)(missing
? 0 : 1);
10272 print_wait_status_row(wd
, zhp
, row
);
10274 timeout
.tv_sec
+= floor(wd
->wd_interval
);
10275 long nanos
= timeout
.tv_nsec
+
10276 (wd
->wd_interval
- floor(wd
->wd_interval
)) * NANOSEC
;
10277 if (nanos
>= NANOSEC
) {
10279 timeout
.tv_nsec
= nanos
- NANOSEC
;
10281 timeout
.tv_nsec
= nanos
;
10283 pthread_mutex_lock(&wd
->wd_mutex
);
10284 if (!wd
->wd_should_exit
)
10285 ret
= pthread_cond_timedwait(&wd
->wd_cv
, &wd
->wd_mutex
,
10287 pthread_mutex_unlock(&wd
->wd_mutex
);
10289 break; /* signaled by main thread */
10290 } else if (ret
!= ETIMEDOUT
) {
10291 (void) fprintf(stderr
, gettext("pthread_cond_timedwait "
10292 "failed: %s\n"), strerror(ret
));
10294 return (void *)(uintptr_t)(1);
10299 return (void *)(0);
10303 zpool_do_wait(int argc
, char **argv
)
10305 boolean_t verbose
= B_FALSE
;
10309 unsigned long count
;
10310 pthread_t status_thr
;
10312 zpool_handle_t
*zhp
;
10315 wd
.wd_scripted
= B_FALSE
;
10316 wd
.wd_exact
= B_FALSE
;
10317 wd
.wd_headers_once
= B_FALSE
;
10318 wd
.wd_should_exit
= B_FALSE
;
10320 pthread_mutex_init(&wd
.wd_mutex
, NULL
);
10321 pthread_cond_init(&wd
.wd_cv
, NULL
);
10323 /* By default, wait for all types of activity. */
10324 for (i
= 0; i
< ZPOOL_WAIT_NUM_ACTIVITIES
; i
++)
10325 wd
.wd_enabled
[i
] = B_TRUE
;
10327 while ((c
= getopt(argc
, argv
, "HpT:t:")) != -1) {
10330 wd
.wd_scripted
= B_TRUE
;
10333 wd
.wd_headers_once
= B_TRUE
;
10336 wd
.wd_exact
= B_TRUE
;
10339 get_timestamp_arg(*optarg
);
10343 static char *col_subopts
[] = { "discard", "free",
10344 "initialize", "replace", "remove", "resilver",
10345 "scrub", "trim", NULL
};
10347 /* Reset activities array */
10348 bzero(&wd
.wd_enabled
, sizeof (wd
.wd_enabled
));
10349 while (*optarg
!= '\0') {
10350 int activity
= getsubopt(&optarg
, col_subopts
,
10353 if (activity
< 0) {
10354 (void) fprintf(stderr
,
10355 gettext("invalid activity '%s'\n"),
10360 wd
.wd_enabled
[activity
] = B_TRUE
;
10365 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
10374 get_interval_count(&argc
, argv
, &wd
.wd_interval
, &count
);
10376 /* This subcmd only accepts an interval, not a count */
10377 (void) fprintf(stderr
, gettext("too many arguments\n"));
10381 if (wd
.wd_interval
!= 0)
10385 (void) fprintf(stderr
, gettext("missing 'pool' argument\n"));
10389 (void) fprintf(stderr
, gettext("too many arguments\n"));
10393 wd
.wd_poolname
= argv
[0];
10395 if ((zhp
= zpool_open(g_zfs
, wd
.wd_poolname
)) == NULL
)
10400 * We use a separate thread for printing status updates because
10401 * the main thread will call lzc_wait(), which blocks as long
10402 * as an activity is in progress, which can be a long time.
10404 if (pthread_create(&status_thr
, NULL
, wait_status_thread
, &wd
)
10406 (void) fprintf(stderr
, gettext("failed to create status"
10407 "thread: %s\n"), strerror(errno
));
10414 * Loop over all activities that we are supposed to wait for until none
10415 * of them are in progress. Note that this means we can end up waiting
10416 * for more activities to complete than just those that were in progress
10417 * when we began waiting; if an activity we are interested in begins
10418 * while we are waiting for another activity, we will wait for both to
10419 * complete before exiting.
10422 boolean_t missing
= B_FALSE
;
10423 boolean_t any_waited
= B_FALSE
;
10425 for (i
= 0; i
< ZPOOL_WAIT_NUM_ACTIVITIES
; i
++) {
10428 if (!wd
.wd_enabled
[i
])
10431 error
= zpool_wait_status(zhp
, i
, &missing
, &waited
);
10432 if (error
!= 0 || missing
)
10435 any_waited
= (any_waited
|| waited
);
10438 if (error
!= 0 || missing
|| !any_waited
)
10446 pthread_mutex_lock(&wd
.wd_mutex
);
10447 wd
.wd_should_exit
= B_TRUE
;
10448 pthread_cond_signal(&wd
.wd_cv
);
10449 pthread_mutex_unlock(&wd
.wd_mutex
);
10450 (void) pthread_join(status_thr
, (void *)&status
);
10455 pthread_mutex_destroy(&wd
.wd_mutex
);
10456 pthread_cond_destroy(&wd
.wd_cv
);
10461 find_command_idx(char *command
, int *idx
)
10465 for (i
= 0; i
< NCOMMAND
; i
++) {
10466 if (command_table
[i
].name
== NULL
)
10469 if (strcmp(command
, command_table
[i
].name
) == 0) {
10478 * Display version message
10481 zpool_do_version(int argc
, char **argv
)
10483 if (zfs_version_print() == -1)
10490 * Do zpool_load_compat() and print error message on failure
10492 static zpool_compat_status_t
10493 zpool_do_load_compat(const char *compat
, boolean_t
*list
)
10495 char badword
[ZFS_MAXPROPLEN
];
10496 char badfile
[MAXPATHLEN
];
10497 zpool_compat_status_t ret
;
10499 switch (ret
= zpool_load_compat(compat
, list
, badword
, badfile
)) {
10500 case ZPOOL_COMPATIBILITY_OK
:
10502 case ZPOOL_COMPATIBILITY_READERR
:
10503 (void) fprintf(stderr
, gettext("error reading compatibility "
10504 "file '%s'\n"), badfile
);
10506 case ZPOOL_COMPATIBILITY_BADFILE
:
10507 (void) fprintf(stderr
, gettext("compatibility file '%s' "
10508 "too large or not newline-terminated\n"), badfile
);
10510 case ZPOOL_COMPATIBILITY_BADWORD
:
10511 (void) fprintf(stderr
, gettext("unknown feature '%s' in "
10512 "compatibility file '%s'\n"), badword
, badfile
);
10514 case ZPOOL_COMPATIBILITY_NOFILES
:
10515 (void) fprintf(stderr
, gettext("no compatibility files "
10523 main(int argc
, char **argv
)
10530 (void) setlocale(LC_ALL
, "");
10531 (void) setlocale(LC_NUMERIC
, "C");
10532 (void) textdomain(TEXT_DOMAIN
);
10538 * Make sure the user has specified some command.
10541 (void) fprintf(stderr
, gettext("missing command\n"));
10548 * Special case '-?'
10550 if ((strcmp(cmdname
, "-?") == 0) || strcmp(cmdname
, "--help") == 0)
10554 * Special case '-V|--version'
10556 if ((strcmp(cmdname
, "-V") == 0) || (strcmp(cmdname
, "--version") == 0))
10557 return (zpool_do_version(argc
, argv
));
10559 if ((g_zfs
= libzfs_init()) == NULL
) {
10560 (void) fprintf(stderr
, "%s\n", libzfs_error_init(errno
));
10564 libzfs_print_on_error(g_zfs
, B_TRUE
);
10566 zfs_save_arguments(argc
, argv
, history_str
, sizeof (history_str
));
10569 * Many commands modify input strings for string parsing reasons.
10570 * We create a copy to protect the original argv.
10572 newargv
= malloc((argc
+ 1) * sizeof (newargv
[0]));
10573 for (i
= 0; i
< argc
; i
++)
10574 newargv
[i
] = strdup(argv
[i
]);
10575 newargv
[argc
] = NULL
;
10578 * Run the appropriate command.
10580 if (find_command_idx(cmdname
, &i
) == 0) {
10581 current_command
= &command_table
[i
];
10582 ret
= command_table
[i
].func(argc
- 1, newargv
+ 1);
10583 } else if (strchr(cmdname
, '=')) {
10584 verify(find_command_idx("set", &i
) == 0);
10585 current_command
= &command_table
[i
];
10586 ret
= command_table
[i
].func(argc
, newargv
);
10587 } else if (strcmp(cmdname
, "freeze") == 0 && argc
== 3) {
10589 * 'freeze' is a vile debugging abomination, so we treat
10592 zfs_cmd_t zc
= {"\0"};
10594 (void) strlcpy(zc
.zc_name
, argv
[2], sizeof (zc
.zc_name
));
10595 ret
= zfs_ioctl(g_zfs
, ZFS_IOC_POOL_FREEZE
, &zc
);
10597 (void) fprintf(stderr
,
10598 gettext("failed to freeze pool: %d\n"), errno
);
10604 (void) fprintf(stderr
, gettext("unrecognized "
10605 "command '%s'\n"), cmdname
);
10610 for (i
= 0; i
< argc
; i
++)
10614 if (ret
== 0 && log_history
)
10615 (void) zpool_log_history(g_zfs
, history_str
);
10617 libzfs_fini(g_zfs
);
10620 * The 'ZFS_ABORT' environment variable causes us to dump core on exit
10621 * for the purposes of running ::findleaks.
10623 if (getenv("ZFS_ABORT") != NULL
) {
10624 (void) printf("dumping core by request\n");