4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25 * Copyright (c) 2011, 2018 by Delphix. All rights reserved.
26 * Copyright (c) 2012 by Frederik Wessels. All rights reserved.
27 * Copyright (c) 2012 by Cyril Plisko. All rights reserved.
28 * Copyright (c) 2013 by Prasad Joshi (sTec). All rights reserved.
29 * Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>.
30 * Copyright (c) 2017 Datto Inc.
31 * Copyright (c) 2017 Open-E, Inc. All Rights Reserved.
32 * Copyright (c) 2017, Intel Corporation.
54 #include <sys/fs/zfs.h>
56 #include <sys/systeminfo.h>
57 #include <sys/fm/fs/zfs.h>
58 #include <sys/fm/util.h>
59 #include <sys/fm/protocol.h>
60 #include <sys/zfs_ioctl.h>
61 #include <sys/mount.h>
62 #include <sys/sysmacros.h>
68 #include "zpool_util.h"
69 #include "zfs_comutil.h"
70 #include "zfeature_common.h"
72 #include "statcommon.h"
74 static int zpool_do_create(int, char **);
75 static int zpool_do_destroy(int, char **);
77 static int zpool_do_add(int, char **);
78 static int zpool_do_remove(int, char **);
79 static int zpool_do_labelclear(int, char **);
81 static int zpool_do_checkpoint(int, char **);
83 static int zpool_do_list(int, char **);
84 static int zpool_do_iostat(int, char **);
85 static int zpool_do_status(int, char **);
87 static int zpool_do_online(int, char **);
88 static int zpool_do_offline(int, char **);
89 static int zpool_do_clear(int, char **);
90 static int zpool_do_reopen(int, char **);
92 static int zpool_do_reguid(int, char **);
94 static int zpool_do_attach(int, char **);
95 static int zpool_do_detach(int, char **);
96 static int zpool_do_replace(int, char **);
97 static int zpool_do_split(int, char **);
99 static int zpool_do_scrub(int, char **);
101 static int zpool_do_import(int, char **);
102 static int zpool_do_export(int, char **);
104 static int zpool_do_upgrade(int, char **);
106 static int zpool_do_history(int, char **);
107 static int zpool_do_events(int, char **);
109 static int zpool_do_get(int, char **);
110 static int zpool_do_set(int, char **);
112 static int zpool_do_sync(int, char **);
115 * These libumem hooks provide a reasonable set of defaults for the allocator's
116 * debugging facilities.
121 _umem_debug_init(void)
123 return ("default,verbose"); /* $UMEM_DEBUG setting */
127 _umem_logging_init(void)
129 return ("fail,contents"); /* $UMEM_LOGGING setting */
165 * Flags for stats to display with "zpool iostats"
173 IOS_COUNT
, /* always last element */
176 /* iostat_type entries as bitmasks */
177 #define IOS_DEFAULT_M (1ULL << IOS_DEFAULT)
178 #define IOS_LATENCY_M (1ULL << IOS_LATENCY)
179 #define IOS_QUEUES_M (1ULL << IOS_QUEUES)
180 #define IOS_L_HISTO_M (1ULL << IOS_L_HISTO)
181 #define IOS_RQ_HISTO_M (1ULL << IOS_RQ_HISTO)
183 /* Mask of all the histo bits */
184 #define IOS_ANYHISTO_M (IOS_L_HISTO_M | IOS_RQ_HISTO_M)
187 * Lookup table for iostat flags to nvlist names. Basically a list
188 * of all the nvlists a flag requires. Also specifies the order in
189 * which data gets printed in zpool iostat.
191 static const char *vsx_type_to_nvlist
[IOS_COUNT
][11] = {
193 ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO
,
194 ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO
,
195 ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO
,
196 ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO
,
197 ZPOOL_CONFIG_VDEV_SYNC_R_LAT_HISTO
,
198 ZPOOL_CONFIG_VDEV_SYNC_W_LAT_HISTO
,
199 ZPOOL_CONFIG_VDEV_ASYNC_R_LAT_HISTO
,
200 ZPOOL_CONFIG_VDEV_ASYNC_W_LAT_HISTO
,
201 ZPOOL_CONFIG_VDEV_SCRUB_LAT_HISTO
,
204 ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO
,
205 ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO
,
206 ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO
,
207 ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO
,
210 ZPOOL_CONFIG_VDEV_SYNC_R_ACTIVE_QUEUE
,
211 ZPOOL_CONFIG_VDEV_SYNC_W_ACTIVE_QUEUE
,
212 ZPOOL_CONFIG_VDEV_ASYNC_R_ACTIVE_QUEUE
,
213 ZPOOL_CONFIG_VDEV_ASYNC_W_ACTIVE_QUEUE
,
214 ZPOOL_CONFIG_VDEV_SCRUB_ACTIVE_QUEUE
,
217 ZPOOL_CONFIG_VDEV_SYNC_IND_R_HISTO
,
218 ZPOOL_CONFIG_VDEV_SYNC_AGG_R_HISTO
,
219 ZPOOL_CONFIG_VDEV_SYNC_IND_W_HISTO
,
220 ZPOOL_CONFIG_VDEV_SYNC_AGG_W_HISTO
,
221 ZPOOL_CONFIG_VDEV_ASYNC_IND_R_HISTO
,
222 ZPOOL_CONFIG_VDEV_ASYNC_AGG_R_HISTO
,
223 ZPOOL_CONFIG_VDEV_ASYNC_IND_W_HISTO
,
224 ZPOOL_CONFIG_VDEV_ASYNC_AGG_W_HISTO
,
225 ZPOOL_CONFIG_VDEV_IND_SCRUB_HISTO
,
226 ZPOOL_CONFIG_VDEV_AGG_SCRUB_HISTO
,
232 * Given a cb->cb_flags with a histogram bit set, return the iostat_type.
233 * Right now, only one histo bit is ever set at one time, so we can
234 * just do a highbit64(a)
236 #define IOS_HISTO_IDX(a) (highbit64(a & IOS_ANYHISTO_M) - 1)
238 typedef struct zpool_command
{
240 int (*func
)(int, char **);
245 * Master command table. Each ZFS command has a name, associated function, and
246 * usage message. The usage messages need to be internationalized, so we have
247 * to have a function to return the usage message based on a command index.
249 * These commands are organized according to how they are displayed in the usage
250 * message. An empty command (one with a NULL name) indicates an empty line in
251 * the generic usage message.
253 static zpool_command_t command_table
[] = {
254 { "create", zpool_do_create
, HELP_CREATE
},
255 { "destroy", zpool_do_destroy
, HELP_DESTROY
},
257 { "add", zpool_do_add
, HELP_ADD
},
258 { "remove", zpool_do_remove
, HELP_REMOVE
},
260 { "labelclear", zpool_do_labelclear
, HELP_LABELCLEAR
},
262 { "checkpoint", zpool_do_checkpoint
, HELP_CHECKPOINT
},
264 { "list", zpool_do_list
, HELP_LIST
},
265 { "iostat", zpool_do_iostat
, HELP_IOSTAT
},
266 { "status", zpool_do_status
, HELP_STATUS
},
268 { "online", zpool_do_online
, HELP_ONLINE
},
269 { "offline", zpool_do_offline
, HELP_OFFLINE
},
270 { "clear", zpool_do_clear
, HELP_CLEAR
},
271 { "reopen", zpool_do_reopen
, HELP_REOPEN
},
273 { "attach", zpool_do_attach
, HELP_ATTACH
},
274 { "detach", zpool_do_detach
, HELP_DETACH
},
275 { "replace", zpool_do_replace
, HELP_REPLACE
},
276 { "split", zpool_do_split
, HELP_SPLIT
},
278 { "scrub", zpool_do_scrub
, HELP_SCRUB
},
280 { "import", zpool_do_import
, HELP_IMPORT
},
281 { "export", zpool_do_export
, HELP_EXPORT
},
282 { "upgrade", zpool_do_upgrade
, HELP_UPGRADE
},
283 { "reguid", zpool_do_reguid
, HELP_REGUID
},
285 { "history", zpool_do_history
, HELP_HISTORY
},
286 { "events", zpool_do_events
, HELP_EVENTS
},
288 { "get", zpool_do_get
, HELP_GET
},
289 { "set", zpool_do_set
, HELP_SET
},
290 { "sync", zpool_do_sync
, HELP_SYNC
},
293 #define NCOMMAND (ARRAY_SIZE(command_table))
295 #define VDEV_ALLOC_CLASS_LOGS "logs"
297 static zpool_command_t
*current_command
;
298 static char history_str
[HIS_MAX_RECORD_LEN
];
299 static boolean_t log_history
= B_TRUE
;
300 static uint_t timestamp_fmt
= NODATE
;
303 get_usage(zpool_help_t idx
)
307 return (gettext("\tadd [-fgLnP] [-o property=value] "
308 "<pool> <vdev> ...\n"));
310 return (gettext("\tattach [-f] [-o property=value] "
311 "<pool> <device> <new-device>\n"));
313 return (gettext("\tclear [-nF] <pool> [device]\n"));
315 return (gettext("\tcreate [-fnd] [-o property=value] ... \n"
316 "\t [-O file-system-property=value] ... \n"
317 "\t [-m mountpoint] [-R root] <pool> <vdev> ...\n"));
318 case HELP_CHECKPOINT
:
319 return (gettext("\tcheckpoint [--discard] <pool> ...\n"));
321 return (gettext("\tdestroy [-f] <pool>\n"));
323 return (gettext("\tdetach <pool> <device>\n"));
325 return (gettext("\texport [-af] <pool> ...\n"));
327 return (gettext("\thistory [-il] [<pool>] ...\n"));
329 return (gettext("\timport [-d dir] [-D]\n"
330 "\timport [-o mntopts] [-o property=value] ... \n"
331 "\t [-d dir | -c cachefile] [-D] [-l] [-f] [-m] [-N] "
332 "[-R root] [-F [-n]] -a\n"
333 "\timport [-o mntopts] [-o property=value] ... \n"
334 "\t [-d dir | -c cachefile] [-D] [-l] [-f] [-m] [-N] "
335 "[-R root] [-F [-n]]\n"
336 "\t [--rewind-to-checkpoint] <pool | id> [newpool]\n"));
338 return (gettext("\tiostat [[[-c [script1,script2,...]"
339 "[-lq]]|[-rw]] [-T d | u] [-ghHLpPvy]\n"
340 "\t [[pool ...]|[pool vdev ...]|[vdev ...]]"
341 " [interval [count]]\n"));
342 case HELP_LABELCLEAR
:
343 return (gettext("\tlabelclear [-f] <vdev>\n"));
345 return (gettext("\tlist [-gHLpPv] [-o property[,...]] "
346 "[-T d|u] [pool] ... \n"
347 "\t [interval [count]]\n"));
349 return (gettext("\toffline [-f] [-t] <pool> <device> ...\n"));
351 return (gettext("\tonline [-e] <pool> <device> ...\n"));
353 return (gettext("\treplace [-f] [-o property=value] "
354 "<pool> <device> [new-device]\n"));
356 return (gettext("\tremove [-nps] <pool> <device> ...\n"));
358 return (gettext("\treopen [-n] <pool>\n"));
360 return (gettext("\tscrub [-s | -p] <pool> ...\n"));
362 return (gettext("\tstatus [-c [script1,script2,...]] [-gLPvxD]"
363 "[-T d|u] [pool] ... \n"
364 "\t [interval [count]]\n"));
366 return (gettext("\tupgrade\n"
368 "\tupgrade [-V version] <-a | pool ...>\n"));
370 return (gettext("\tevents [-vHf [pool] | -c]\n"));
372 return (gettext("\tget [-Hp] [-o \"all\" | field[,...]] "
373 "<\"all\" | property[,...]> <pool> ...\n"));
375 return (gettext("\tset <property=value> <pool> \n"));
377 return (gettext("\tsplit [-gLnPl] [-R altroot] [-o mntopts]\n"
378 "\t [-o property=value] <pool> <newpool> "
379 "[<device> ...]\n"));
381 return (gettext("\treguid <pool>\n"));
383 return (gettext("\tsync [pool] ...\n"));
392 * Callback routine that will print out a pool property value.
395 print_prop_cb(int prop
, void *cb
)
399 (void) fprintf(fp
, "\t%-19s ", zpool_prop_to_name(prop
));
401 if (zpool_prop_readonly(prop
))
402 (void) fprintf(fp
, " NO ");
404 (void) fprintf(fp
, " YES ");
406 if (zpool_prop_values(prop
) == NULL
)
407 (void) fprintf(fp
, "-\n");
409 (void) fprintf(fp
, "%s\n", zpool_prop_values(prop
));
415 * Display usage message. If we're inside a command, display only the usage for
416 * that command. Otherwise, iterate over the entire command table and display
417 * a complete usage message.
420 usage(boolean_t requested
)
422 FILE *fp
= requested
? stdout
: stderr
;
424 if (current_command
== NULL
) {
427 (void) fprintf(fp
, gettext("usage: zpool command args ...\n"));
429 gettext("where 'command' is one of the following:\n\n"));
431 for (i
= 0; i
< NCOMMAND
; i
++) {
432 if (command_table
[i
].name
== NULL
)
433 (void) fprintf(fp
, "\n");
435 (void) fprintf(fp
, "%s",
436 get_usage(command_table
[i
].usage
));
439 (void) fprintf(fp
, gettext("usage:\n"));
440 (void) fprintf(fp
, "%s", get_usage(current_command
->usage
));
443 if (current_command
!= NULL
&&
444 ((strcmp(current_command
->name
, "set") == 0) ||
445 (strcmp(current_command
->name
, "get") == 0) ||
446 (strcmp(current_command
->name
, "list") == 0))) {
449 gettext("\nthe following properties are supported:\n"));
451 (void) fprintf(fp
, "\n\t%-19s %s %s\n\n",
452 "PROPERTY", "EDIT", "VALUES");
454 /* Iterate over all properties */
455 (void) zprop_iter(print_prop_cb
, fp
, B_FALSE
, B_TRUE
,
458 (void) fprintf(fp
, "\t%-19s ", "feature@...");
459 (void) fprintf(fp
, "YES disabled | enabled | active\n");
461 (void) fprintf(fp
, gettext("\nThe feature@ properties must be "
462 "appended with a feature name.\nSee zpool-features(5).\n"));
466 * See comments at end of main().
468 if (getenv("ZFS_ABORT") != NULL
) {
469 (void) printf("dumping core by request\n");
473 exit(requested
? 0 : 2);
477 * print a pool vdev config for dry runs
480 print_vdev_tree(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
, int indent
,
481 const char *match
, int name_flags
)
486 boolean_t printed
= B_FALSE
;
488 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
489 &child
, &children
) != 0) {
491 (void) printf("\t%*s%s\n", indent
, "", name
);
495 for (c
= 0; c
< children
; c
++) {
496 uint64_t is_log
= B_FALSE
;
499 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
502 class = VDEV_ALLOC_BIAS_LOG
;
503 (void) nvlist_lookup_string(child
[c
],
504 ZPOOL_CONFIG_ALLOCATION_BIAS
, &class);
505 if (strcmp(match
, class) != 0)
508 if (!printed
&& name
!= NULL
) {
509 (void) printf("\t%*s%s\n", indent
, "", name
);
512 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], name_flags
);
513 print_vdev_tree(zhp
, vname
, child
[c
], indent
+ 2, "",
520 prop_list_contains_feature(nvlist_t
*proplist
)
523 for (nvp
= nvlist_next_nvpair(proplist
, NULL
); NULL
!= nvp
;
524 nvp
= nvlist_next_nvpair(proplist
, nvp
)) {
525 if (zpool_prop_feature(nvpair_name(nvp
)))
532 * Add a property pair (name, string-value) into a property nvlist.
535 add_prop_list(const char *propname
, char *propval
, nvlist_t
**props
,
538 zpool_prop_t prop
= ZPOOL_PROP_INVAL
;
544 if (*props
== NULL
&&
545 nvlist_alloc(props
, NV_UNIQUE_NAME
, 0) != 0) {
546 (void) fprintf(stderr
,
547 gettext("internal error: out of memory\n"));
554 const char *vname
= zpool_prop_to_name(ZPOOL_PROP_VERSION
);
556 if ((prop
= zpool_name_to_prop(propname
)) == ZPOOL_PROP_INVAL
&&
557 !zpool_prop_feature(propname
)) {
558 (void) fprintf(stderr
, gettext("property '%s' is "
559 "not a valid pool property\n"), propname
);
564 * feature@ properties and version should not be specified
567 if ((prop
== ZPOOL_PROP_INVAL
&& zpool_prop_feature(propname
) &&
568 nvlist_exists(proplist
, vname
)) ||
569 (prop
== ZPOOL_PROP_VERSION
&&
570 prop_list_contains_feature(proplist
))) {
571 (void) fprintf(stderr
, gettext("'feature@' and "
572 "'version' properties cannot be specified "
578 if (zpool_prop_feature(propname
))
581 normnm
= zpool_prop_to_name(prop
);
583 if ((fprop
= zfs_name_to_prop(propname
)) != ZPROP_INVAL
) {
584 normnm
= zfs_prop_to_name(fprop
);
590 if (nvlist_lookup_string(proplist
, normnm
, &strval
) == 0 &&
591 prop
!= ZPOOL_PROP_CACHEFILE
) {
592 (void) fprintf(stderr
, gettext("property '%s' "
593 "specified multiple times\n"), propname
);
597 if (nvlist_add_string(proplist
, normnm
, propval
) != 0) {
598 (void) fprintf(stderr
, gettext("internal "
599 "error: out of memory\n"));
607 * Set a default property pair (name, string-value) in a property nvlist
610 add_prop_list_default(const char *propname
, char *propval
, nvlist_t
**props
,
615 if (nvlist_lookup_string(*props
, propname
, &pval
) == 0)
618 return (add_prop_list(propname
, propval
, props
, B_TRUE
));
622 * zpool add [-fgLnP] [-o property=value] <pool> <vdev> ...
624 * -f Force addition of devices, even if they appear in use
625 * -g Display guid for individual vdev name.
626 * -L Follow links when resolving vdev path name.
627 * -n Do not add the devices, but display the resulting layout if
628 * they were to be added.
629 * -o Set property=value.
630 * -P Display full path for vdev name.
632 * Adds the given vdevs to 'pool'. As with create, the bulk of this work is
633 * handled by get_vdev_spec(), which constructs the nvlist needed to pass to
637 zpool_do_add(int argc
, char **argv
)
639 boolean_t force
= B_FALSE
;
640 boolean_t dryrun
= B_FALSE
;
648 nvlist_t
*props
= NULL
;
652 while ((c
= getopt(argc
, argv
, "fgLno:P")) != -1) {
658 name_flags
|= VDEV_NAME_GUID
;
661 name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
667 if ((propval
= strchr(optarg
, '=')) == NULL
) {
668 (void) fprintf(stderr
, gettext("missing "
669 "'=' for -o option\n"));
675 if ((strcmp(optarg
, ZPOOL_CONFIG_ASHIFT
) != 0) ||
676 (add_prop_list(optarg
, propval
, &props
, B_TRUE
)))
680 name_flags
|= VDEV_NAME_PATH
;
683 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
692 /* get pool name and check number of arguments */
694 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
698 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
707 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
710 if ((config
= zpool_get_config(zhp
, NULL
)) == NULL
) {
711 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
717 /* unless manually specified use "ashift" pool property (if set) */
718 if (!nvlist_exists(props
, ZPOOL_CONFIG_ASHIFT
)) {
721 char strval
[ZPOOL_MAXPROPLEN
];
723 intval
= zpool_get_prop_int(zhp
, ZPOOL_PROP_ASHIFT
, &src
);
724 if (src
!= ZPROP_SRC_DEFAULT
) {
725 (void) sprintf(strval
, "%" PRId32
, intval
);
726 verify(add_prop_list(ZPOOL_CONFIG_ASHIFT
, strval
,
727 &props
, B_TRUE
) == 0);
731 /* pass off to get_vdev_spec for processing */
732 nvroot
= make_root_vdev(zhp
, props
, force
, !force
, B_FALSE
, dryrun
,
734 if (nvroot
== NULL
) {
740 nvlist_t
*poolnvroot
;
742 uint_t l2children
, c
;
744 boolean_t hadcache
= B_FALSE
;
746 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
749 (void) printf(gettext("would update '%s' to the following "
750 "configuration:\n"), zpool_get_name(zhp
));
752 /* print original main pool and new tree */
753 print_vdev_tree(zhp
, poolname
, poolnvroot
, 0, "",
754 name_flags
| VDEV_NAME_TYPE_ID
);
755 print_vdev_tree(zhp
, NULL
, nvroot
, 0, "", name_flags
);
757 /* print other classes: 'dedup', 'special', and 'log' */
758 print_vdev_tree(zhp
, "dedup", poolnvroot
, 0,
759 VDEV_ALLOC_BIAS_DEDUP
, name_flags
);
760 print_vdev_tree(zhp
, NULL
, nvroot
, 0, VDEV_ALLOC_BIAS_DEDUP
,
763 print_vdev_tree(zhp
, "special", poolnvroot
, 0,
764 VDEV_ALLOC_BIAS_SPECIAL
, name_flags
);
765 print_vdev_tree(zhp
, NULL
, nvroot
, 0, VDEV_ALLOC_BIAS_SPECIAL
,
768 print_vdev_tree(zhp
, "logs", poolnvroot
, 0, VDEV_ALLOC_BIAS_LOG
,
770 print_vdev_tree(zhp
, NULL
, nvroot
, 0, VDEV_ALLOC_BIAS_LOG
,
773 /* Do the same for the caches */
774 if (nvlist_lookup_nvlist_array(poolnvroot
, ZPOOL_CONFIG_L2CACHE
,
775 &l2child
, &l2children
) == 0 && l2children
) {
777 (void) printf(gettext("\tcache\n"));
778 for (c
= 0; c
< l2children
; c
++) {
779 vname
= zpool_vdev_name(g_zfs
, NULL
,
780 l2child
[c
], name_flags
);
781 (void) printf("\t %s\n", vname
);
785 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_L2CACHE
,
786 &l2child
, &l2children
) == 0 && l2children
) {
788 (void) printf(gettext("\tcache\n"));
789 for (c
= 0; c
< l2children
; c
++) {
790 vname
= zpool_vdev_name(g_zfs
, NULL
,
791 l2child
[c
], name_flags
);
792 (void) printf("\t %s\n", vname
);
799 ret
= (zpool_add(zhp
, nvroot
) != 0);
810 * zpool remove <pool> <vdev> ...
812 * Removes the given vdev from the pool.
815 zpool_do_remove(int argc
, char **argv
)
819 zpool_handle_t
*zhp
= NULL
;
820 boolean_t stop
= B_FALSE
;
822 boolean_t noop
= B_FALSE
;
823 boolean_t parsable
= B_FALSE
;
826 while ((c
= getopt(argc
, argv
, "nps")) != -1) {
838 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
847 /* get pool name and check number of arguments */
849 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
855 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
859 (void) fprintf(stderr
, gettext("stop request ignored\n"));
865 (void) fprintf(stderr
, gettext("too many arguments\n"));
868 if (zpool_vdev_remove_cancel(zhp
) != 0)
872 (void) fprintf(stderr
, gettext("missing device\n"));
876 for (i
= 1; i
< argc
; i
++) {
880 if (zpool_vdev_indirect_size(zhp
, argv
[i
],
886 (void) printf("%s %llu\n",
887 argv
[i
], (unsigned long long)size
);
890 zfs_nicenum(size
, valstr
,
892 (void) printf("Memory that will be "
893 "used after removing %s: %s\n",
897 if (zpool_vdev_remove(zhp
, argv
[i
]) != 0)
908 * zpool labelclear [-f] <vdev>
910 * -f Force clearing the label for the vdevs which are members of
911 * the exported or foreign pools.
913 * Verifies that the vdev is not active and zeros out the label information
917 zpool_do_labelclear(int argc
, char **argv
)
919 char vdev
[MAXPATHLEN
];
922 int c
, fd
= -1, ret
= 0;
925 boolean_t inuse
= B_FALSE
;
926 boolean_t force
= B_FALSE
;
929 while ((c
= getopt(argc
, argv
, "f")) != -1) {
935 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
946 (void) fprintf(stderr
, gettext("missing vdev name\n"));
950 (void) fprintf(stderr
, gettext("too many arguments\n"));
955 * Check if we were given absolute path and use it as is.
956 * Otherwise if the provided vdev name doesn't point to a file,
957 * try prepending expected disk paths and partition numbers.
959 (void) strlcpy(vdev
, argv
[0], sizeof (vdev
));
960 if (vdev
[0] != '/' && stat(vdev
, &st
) != 0) {
963 error
= zfs_resolve_shortname(argv
[0], vdev
, MAXPATHLEN
);
964 if (error
== 0 && zfs_dev_is_whole_disk(vdev
)) {
965 if (zfs_append_partition(vdev
, MAXPATHLEN
) == -1)
969 if (error
|| (stat(vdev
, &st
) != 0)) {
970 (void) fprintf(stderr
, gettext(
971 "failed to find device %s, try specifying absolute "
972 "path instead\n"), argv
[0]);
977 if ((fd
= open(vdev
, O_RDWR
)) < 0) {
978 (void) fprintf(stderr
, gettext("failed to open %s: %s\n"),
979 vdev
, strerror(errno
));
983 if (ioctl(fd
, BLKFLSBUF
) != 0)
984 (void) fprintf(stderr
, gettext("failed to invalidate "
985 "cache for %s: %s\n"), vdev
, strerror(errno
));
987 if (zpool_read_label(fd
, &config
, NULL
) != 0 || config
== NULL
) {
988 (void) fprintf(stderr
,
989 gettext("failed to check state for %s\n"), vdev
);
995 ret
= zpool_in_use(g_zfs
, fd
, &state
, &name
, &inuse
);
997 (void) fprintf(stderr
,
998 gettext("failed to check state for %s\n"), vdev
);
1008 case POOL_STATE_ACTIVE
:
1009 case POOL_STATE_SPARE
:
1010 case POOL_STATE_L2CACHE
:
1011 (void) fprintf(stderr
, gettext(
1012 "%s is a member (%s) of pool \"%s\"\n"),
1013 vdev
, zpool_pool_state_to_name(state
), name
);
1017 case POOL_STATE_EXPORTED
:
1020 (void) fprintf(stderr
, gettext(
1021 "use '-f' to override the following error:\n"
1022 "%s is a member of exported pool \"%s\"\n"),
1027 case POOL_STATE_POTENTIALLY_ACTIVE
:
1030 (void) fprintf(stderr
, gettext(
1031 "use '-f' to override the following error:\n"
1032 "%s is a member of potentially active pool \"%s\"\n"),
1037 case POOL_STATE_DESTROYED
:
1038 /* inuse should never be set for a destroyed pool */
1044 ret
= zpool_clear_label(fd
);
1046 (void) fprintf(stderr
,
1047 gettext("failed to clear label for %s\n"), vdev
);
1058 * zpool create [-fnd] [-o property=value] ...
1059 * [-O file-system-property=value] ...
1060 * [-R root] [-m mountpoint] <pool> <dev> ...
1062 * -f Force creation, even if devices appear in use
1063 * -n Do not create the pool, but display the resulting layout if it
1064 * were to be created.
1065 * -R Create a pool under an alternate root
1066 * -m Set default mountpoint for the root dataset. By default it's
1068 * -o Set property=value.
1069 * -o Set feature@feature=enabled|disabled.
1070 * -d Don't automatically enable all supported pool features
1071 * (individual features can be enabled with -o).
1072 * -O Set fsproperty=value in the pool's root file system
1074 * Creates the named pool according to the given vdev specification. The
1075 * bulk of the vdev processing is done in get_vdev_spec() in zpool_vdev.c. Once
1076 * we get the nvlist back from get_vdev_spec(), we either print out the contents
1077 * (if '-n' was specified), or pass it to libzfs to do the creation.
1080 zpool_do_create(int argc
, char **argv
)
1082 boolean_t force
= B_FALSE
;
1083 boolean_t dryrun
= B_FALSE
;
1084 boolean_t enable_all_pool_feat
= B_TRUE
;
1086 nvlist_t
*nvroot
= NULL
;
1090 char *altroot
= NULL
;
1091 char *mountpoint
= NULL
;
1092 nvlist_t
*fsprops
= NULL
;
1093 nvlist_t
*props
= NULL
;
1097 while ((c
= getopt(argc
, argv
, ":fndR:m:o:O:t:")) != -1) {
1106 enable_all_pool_feat
= B_FALSE
;
1110 if (add_prop_list(zpool_prop_to_name(
1111 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
1113 if (add_prop_list_default(zpool_prop_to_name(
1114 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
1118 /* Equivalent to -O mountpoint=optarg */
1119 mountpoint
= optarg
;
1122 if ((propval
= strchr(optarg
, '=')) == NULL
) {
1123 (void) fprintf(stderr
, gettext("missing "
1124 "'=' for -o option\n"));
1130 if (add_prop_list(optarg
, propval
, &props
, B_TRUE
))
1134 * If the user is creating a pool that doesn't support
1135 * feature flags, don't enable any features.
1137 if (zpool_name_to_prop(optarg
) == ZPOOL_PROP_VERSION
) {
1141 ver
= strtoull(propval
, &end
, 10);
1143 ver
< SPA_VERSION_FEATURES
) {
1144 enable_all_pool_feat
= B_FALSE
;
1147 if (zpool_name_to_prop(optarg
) == ZPOOL_PROP_ALTROOT
)
1151 if ((propval
= strchr(optarg
, '=')) == NULL
) {
1152 (void) fprintf(stderr
, gettext("missing "
1153 "'=' for -O option\n"));
1160 * Mountpoints are checked and then added later.
1161 * Uniquely among properties, they can be specified
1162 * more than once, to avoid conflict with -m.
1164 if (0 == strcmp(optarg
,
1165 zfs_prop_to_name(ZFS_PROP_MOUNTPOINT
))) {
1166 mountpoint
= propval
;
1167 } else if (add_prop_list(optarg
, propval
, &fsprops
,
1174 * Sanity check temporary pool name.
1176 if (strchr(optarg
, '/') != NULL
) {
1177 (void) fprintf(stderr
, gettext("cannot create "
1178 "'%s': invalid character '/' in temporary "
1180 (void) fprintf(stderr
, gettext("use 'zfs "
1181 "create' to create a dataset\n"));
1185 if (add_prop_list(zpool_prop_to_name(
1186 ZPOOL_PROP_TNAME
), optarg
, &props
, B_TRUE
))
1188 if (add_prop_list_default(zpool_prop_to_name(
1189 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
1194 (void) fprintf(stderr
, gettext("missing argument for "
1195 "'%c' option\n"), optopt
);
1198 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1207 /* get pool name and check number of arguments */
1209 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
1213 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
1220 * As a special case, check for use of '/' in the name, and direct the
1221 * user to use 'zfs create' instead.
1223 if (strchr(poolname
, '/') != NULL
) {
1224 (void) fprintf(stderr
, gettext("cannot create '%s': invalid "
1225 "character '/' in pool name\n"), poolname
);
1226 (void) fprintf(stderr
, gettext("use 'zfs create' to "
1227 "create a dataset\n"));
1231 /* pass off to get_vdev_spec for bulk processing */
1232 nvroot
= make_root_vdev(NULL
, props
, force
, !force
, B_FALSE
, dryrun
,
1233 argc
- 1, argv
+ 1);
1237 /* make_root_vdev() allows 0 toplevel children if there are spares */
1238 if (!zfs_allocatable_devs(nvroot
)) {
1239 (void) fprintf(stderr
, gettext("invalid vdev "
1240 "specification: at least one toplevel vdev must be "
1245 if (altroot
!= NULL
&& altroot
[0] != '/') {
1246 (void) fprintf(stderr
, gettext("invalid alternate root '%s': "
1247 "must be an absolute path\n"), altroot
);
1252 * Check the validity of the mountpoint and direct the user to use the
1253 * '-m' mountpoint option if it looks like its in use.
1255 if (mountpoint
== NULL
||
1256 (strcmp(mountpoint
, ZFS_MOUNTPOINT_LEGACY
) != 0 &&
1257 strcmp(mountpoint
, ZFS_MOUNTPOINT_NONE
) != 0)) {
1258 char buf
[MAXPATHLEN
];
1261 if (mountpoint
&& mountpoint
[0] != '/') {
1262 (void) fprintf(stderr
, gettext("invalid mountpoint "
1263 "'%s': must be an absolute path, 'legacy', or "
1264 "'none'\n"), mountpoint
);
1268 if (mountpoint
== NULL
) {
1269 if (altroot
!= NULL
)
1270 (void) snprintf(buf
, sizeof (buf
), "%s/%s",
1273 (void) snprintf(buf
, sizeof (buf
), "/%s",
1276 if (altroot
!= NULL
)
1277 (void) snprintf(buf
, sizeof (buf
), "%s%s",
1278 altroot
, mountpoint
);
1280 (void) snprintf(buf
, sizeof (buf
), "%s",
1284 if ((dirp
= opendir(buf
)) == NULL
&& errno
!= ENOENT
) {
1285 (void) fprintf(stderr
, gettext("mountpoint '%s' : "
1286 "%s\n"), buf
, strerror(errno
));
1287 (void) fprintf(stderr
, gettext("use '-m' "
1288 "option to provide a different default\n"));
1293 while (count
< 3 && readdir(dirp
) != NULL
)
1295 (void) closedir(dirp
);
1298 (void) fprintf(stderr
, gettext("mountpoint "
1299 "'%s' exists and is not empty\n"), buf
);
1300 (void) fprintf(stderr
, gettext("use '-m' "
1301 "option to provide a "
1302 "different default\n"));
1309 * Now that the mountpoint's validity has been checked, ensure that
1310 * the property is set appropriately prior to creating the pool.
1312 if (mountpoint
!= NULL
) {
1313 ret
= add_prop_list(zfs_prop_to_name(ZFS_PROP_MOUNTPOINT
),
1314 mountpoint
, &fsprops
, B_FALSE
);
1322 * For a dry run invocation, print out a basic message and run
1323 * through all the vdevs in the list and print out in an
1324 * appropriate hierarchy.
1326 (void) printf(gettext("would create '%s' with the "
1327 "following layout:\n\n"), poolname
);
1329 print_vdev_tree(NULL
, poolname
, nvroot
, 0, "", 0);
1330 print_vdev_tree(NULL
, "dedup", nvroot
, 0,
1331 VDEV_ALLOC_BIAS_DEDUP
, 0);
1332 print_vdev_tree(NULL
, "special", nvroot
, 0,
1333 VDEV_ALLOC_BIAS_SPECIAL
, 0);
1334 print_vdev_tree(NULL
, "logs", nvroot
, 0,
1335 VDEV_ALLOC_BIAS_LOG
, 0);
1340 * Hand off to libzfs.
1343 for (i
= 0; i
< SPA_FEATURES
; i
++) {
1344 char propname
[MAXPATHLEN
];
1346 zfeature_info_t
*feat
= &spa_feature_table
[i
];
1348 (void) snprintf(propname
, sizeof (propname
),
1349 "feature@%s", feat
->fi_uname
);
1352 * Only features contained in props will be enabled:
1353 * remove from the nvlist every ZFS_FEATURE_DISABLED
1354 * value and add every missing ZFS_FEATURE_ENABLED if
1355 * enable_all_pool_feat is set.
1357 if (!nvlist_lookup_string(props
, propname
, &propval
)) {
1358 if (strcmp(propval
, ZFS_FEATURE_DISABLED
) == 0)
1359 (void) nvlist_remove_all(props
,
1361 } else if (enable_all_pool_feat
) {
1362 ret
= add_prop_list(propname
,
1363 ZFS_FEATURE_ENABLED
, &props
, B_TRUE
);
1370 if (zpool_create(g_zfs
, poolname
,
1371 nvroot
, props
, fsprops
) == 0) {
1372 zfs_handle_t
*pool
= zfs_open(g_zfs
,
1373 tname
? tname
: poolname
, ZFS_TYPE_FILESYSTEM
);
1375 if (zfs_mount(pool
, NULL
, 0) == 0)
1376 ret
= zfs_shareall(pool
);
1379 } else if (libzfs_errno(g_zfs
) == EZFS_INVALIDNAME
) {
1380 (void) fprintf(stderr
, gettext("pool name may have "
1386 nvlist_free(nvroot
);
1387 nvlist_free(fsprops
);
1391 nvlist_free(fsprops
);
1398 * zpool destroy <pool>
1400 * -f Forcefully unmount any datasets
1402 * Destroy the given pool. Automatically unmounts any datasets in the pool.
1405 zpool_do_destroy(int argc
, char **argv
)
1407 boolean_t force
= B_FALSE
;
1410 zpool_handle_t
*zhp
;
1414 while ((c
= getopt(argc
, argv
, "f")) != -1) {
1420 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1429 /* check arguments */
1431 (void) fprintf(stderr
, gettext("missing pool argument\n"));
1435 (void) fprintf(stderr
, gettext("too many arguments\n"));
1441 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
) {
1443 * As a special case, check for use of '/' in the name, and
1444 * direct the user to use 'zfs destroy' instead.
1446 if (strchr(pool
, '/') != NULL
)
1447 (void) fprintf(stderr
, gettext("use 'zfs destroy' to "
1448 "destroy a dataset\n"));
1452 if (zpool_disable_datasets(zhp
, force
) != 0) {
1453 (void) fprintf(stderr
, gettext("could not destroy '%s': "
1454 "could not unmount datasets\n"), zpool_get_name(zhp
));
1459 /* The history must be logged as part of the export */
1460 log_history
= B_FALSE
;
1462 ret
= (zpool_destroy(zhp
, history_str
) != 0);
1469 typedef struct export_cbdata
{
1471 boolean_t hardforce
;
1478 zpool_export_one(zpool_handle_t
*zhp
, void *data
)
1480 export_cbdata_t
*cb
= data
;
1482 if (zpool_disable_datasets(zhp
, cb
->force
) != 0)
1485 /* The history must be logged as part of the export */
1486 log_history
= B_FALSE
;
1488 if (cb
->hardforce
) {
1489 if (zpool_export_force(zhp
, history_str
) != 0)
1491 } else if (zpool_export(zhp
, cb
->force
, history_str
) != 0) {
1499 * zpool export [-f] <pool> ...
1501 * -a Export all pools
1502 * -f Forcefully unmount datasets
1504 * Export the given pools. By default, the command will attempt to cleanly
1505 * unmount any active datasets within the pool. If the '-f' flag is specified,
1506 * then the datasets will be forcefully unmounted.
1509 zpool_do_export(int argc
, char **argv
)
1512 boolean_t do_all
= B_FALSE
;
1513 boolean_t force
= B_FALSE
;
1514 boolean_t hardforce
= B_FALSE
;
1518 while ((c
= getopt(argc
, argv
, "afF")) != -1) {
1530 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1537 cb
.hardforce
= hardforce
;
1543 (void) fprintf(stderr
, gettext("too many arguments\n"));
1547 return (for_each_pool(argc
, argv
, B_TRUE
, NULL
,
1548 zpool_export_one
, &cb
));
1551 /* check arguments */
1553 (void) fprintf(stderr
, gettext("missing pool argument\n"));
1557 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
, zpool_export_one
, &cb
);
1563 * Given a vdev configuration, determine the maximum width needed for the device
1567 max_width(zpool_handle_t
*zhp
, nvlist_t
*nv
, int depth
, int max
,
1575 name
= zpool_vdev_name(g_zfs
, zhp
, nv
, name_flags
);
1576 if (strlen(name
) + depth
> max
)
1577 max
= strlen(name
) + depth
;
1581 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
1582 &child
, &children
) == 0) {
1583 for (c
= 0; c
< children
; c
++)
1584 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1585 max
, name_flags
)) > max
)
1589 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
1590 &child
, &children
) == 0) {
1591 for (c
= 0; c
< children
; c
++)
1592 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1593 max
, name_flags
)) > max
)
1597 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1598 &child
, &children
) == 0) {
1599 for (c
= 0; c
< children
; c
++)
1600 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1601 max
, name_flags
)) > max
)
1608 typedef struct spare_cbdata
{
1610 zpool_handle_t
*cb_zhp
;
1614 find_vdev(nvlist_t
*nv
, uint64_t search
)
1620 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
, &guid
) == 0 &&
1624 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1625 &child
, &children
) == 0) {
1626 for (c
= 0; c
< children
; c
++)
1627 if (find_vdev(child
[c
], search
))
1635 find_spare(zpool_handle_t
*zhp
, void *data
)
1637 spare_cbdata_t
*cbp
= data
;
1638 nvlist_t
*config
, *nvroot
;
1640 config
= zpool_get_config(zhp
, NULL
);
1641 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
1644 if (find_vdev(nvroot
, cbp
->cb_guid
)) {
1653 typedef struct status_cbdata
{
1657 boolean_t cb_allpools
;
1658 boolean_t cb_verbose
;
1659 boolean_t cb_explain
;
1661 boolean_t cb_dedup_stats
;
1662 boolean_t cb_print_status
;
1663 vdev_cmd_data_list_t
*vcdl
;
1666 /* Return 1 if string is NULL, empty, or whitespace; return 0 otherwise. */
1668 is_blank_str(char *str
)
1670 while (str
!= NULL
&& *str
!= '\0') {
1678 /* Print command output lines for specific vdev in a specific pool */
1680 zpool_print_cmd(vdev_cmd_data_list_t
*vcdl
, const char *pool
, char *path
)
1682 vdev_cmd_data_t
*data
;
1686 for (i
= 0; i
< vcdl
->count
; i
++) {
1687 if ((strcmp(vcdl
->data
[i
].path
, path
) != 0) ||
1688 (strcmp(vcdl
->data
[i
].pool
, pool
) != 0)) {
1689 /* Not the vdev we're looking for */
1693 data
= &vcdl
->data
[i
];
1694 /* Print out all the output values for this vdev */
1695 for (j
= 0; j
< vcdl
->uniq_cols_cnt
; j
++) {
1697 /* Does this vdev have values for this column? */
1698 for (int k
= 0; k
< data
->cols_cnt
; k
++) {
1699 if (strcmp(data
->cols
[k
],
1700 vcdl
->uniq_cols
[j
]) == 0) {
1701 /* yes it does, record the value */
1702 val
= data
->lines
[k
];
1707 * Mark empty values with dashes to make output
1710 if (is_blank_str(val
))
1713 printf("%*s", vcdl
->uniq_cols_width
[j
], val
);
1714 if (j
< vcdl
->uniq_cols_cnt
- 1)
1718 /* Print out any values that aren't in a column at the end */
1719 for (j
= data
->cols_cnt
; j
< data
->lines_cnt
; j
++) {
1720 /* Did we have any columns? If so print a spacer. */
1721 if (vcdl
->uniq_cols_cnt
> 0)
1724 val
= data
->lines
[j
];
1725 printf("%s", val
? val
: "");
1732 * Print out configuration state as requested by status_callback.
1735 print_status_config(zpool_handle_t
*zhp
, status_cbdata_t
*cb
, const char *name
,
1736 nvlist_t
*nv
, int depth
, boolean_t isspare
)
1740 pool_scan_stat_t
*ps
= NULL
;
1742 char rbuf
[6], wbuf
[6], cbuf
[6];
1744 uint64_t notpresent
;
1745 spare_cbdata_t spare_cb
;
1750 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1751 &child
, &children
) != 0)
1754 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
1755 (uint64_t **)&vs
, &c
) == 0);
1757 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_TYPE
, &type
) == 0);
1759 if (strcmp(type
, VDEV_TYPE_INDIRECT
) == 0)
1762 state
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
1765 * For hot spares, we use the terms 'INUSE' and 'AVAILABLE' for
1768 if (vs
->vs_aux
== VDEV_AUX_SPARED
)
1770 else if (vs
->vs_state
== VDEV_STATE_HEALTHY
)
1774 (void) printf("\t%*s%-*s %-8s", depth
, "", cb
->cb_namewidth
- depth
,
1778 zfs_nicenum(vs
->vs_read_errors
, rbuf
, sizeof (rbuf
));
1779 zfs_nicenum(vs
->vs_write_errors
, wbuf
, sizeof (wbuf
));
1780 zfs_nicenum(vs
->vs_checksum_errors
, cbuf
, sizeof (cbuf
));
1781 (void) printf(" %5s %5s %5s", rbuf
, wbuf
, cbuf
);
1784 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_NOT_PRESENT
,
1785 ¬present
) == 0) {
1786 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_PATH
, &path
) == 0);
1787 (void) printf(" was %s", path
);
1788 } else if (vs
->vs_aux
!= 0) {
1791 switch (vs
->vs_aux
) {
1792 case VDEV_AUX_OPEN_FAILED
:
1793 (void) printf(gettext("cannot open"));
1796 case VDEV_AUX_BAD_GUID_SUM
:
1797 (void) printf(gettext("missing device"));
1800 case VDEV_AUX_NO_REPLICAS
:
1801 (void) printf(gettext("insufficient replicas"));
1804 case VDEV_AUX_VERSION_NEWER
:
1805 (void) printf(gettext("newer version"));
1808 case VDEV_AUX_UNSUP_FEAT
:
1809 (void) printf(gettext("unsupported feature(s)"));
1812 case VDEV_AUX_SPARED
:
1813 verify(nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
,
1814 &spare_cb
.cb_guid
) == 0);
1815 if (zpool_iter(g_zfs
, find_spare
, &spare_cb
) == 1) {
1816 if (strcmp(zpool_get_name(spare_cb
.cb_zhp
),
1817 zpool_get_name(zhp
)) == 0)
1818 (void) printf(gettext("currently in "
1821 (void) printf(gettext("in use by "
1823 zpool_get_name(spare_cb
.cb_zhp
));
1824 zpool_close(spare_cb
.cb_zhp
);
1826 (void) printf(gettext("currently in use"));
1830 case VDEV_AUX_ERR_EXCEEDED
:
1831 (void) printf(gettext("too many errors"));
1834 case VDEV_AUX_IO_FAILURE
:
1835 (void) printf(gettext("experienced I/O failures"));
1838 case VDEV_AUX_BAD_LOG
:
1839 (void) printf(gettext("bad intent log"));
1842 case VDEV_AUX_EXTERNAL
:
1843 (void) printf(gettext("external device fault"));
1846 case VDEV_AUX_SPLIT_POOL
:
1847 (void) printf(gettext("split into new pool"));
1850 case VDEV_AUX_ACTIVE
:
1851 (void) printf(gettext("currently in use"));
1854 case VDEV_AUX_CHILDREN_OFFLINE
:
1855 (void) printf(gettext("all children offline"));
1859 (void) printf(gettext("corrupted data"));
1864 (void) nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_SCAN_STATS
,
1865 (uint64_t **)&ps
, &c
);
1867 if (ps
!= NULL
&& ps
->pss_state
== DSS_SCANNING
&&
1868 vs
->vs_scan_processed
!= 0 && children
== 0) {
1869 (void) printf(gettext(" (%s)"),
1870 (ps
->pss_func
== POOL_SCAN_RESILVER
) ?
1871 "resilvering" : "repairing");
1874 if (cb
->vcdl
!= NULL
) {
1875 if (nvlist_lookup_string(nv
, ZPOOL_CONFIG_PATH
, &path
) == 0) {
1877 zpool_print_cmd(cb
->vcdl
, zpool_get_name(zhp
), path
);
1881 (void) printf("\n");
1883 for (c
= 0; c
< children
; c
++) {
1884 uint64_t islog
= B_FALSE
, ishole
= B_FALSE
;
1886 /* Don't print logs or holes here */
1887 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1889 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_HOLE
,
1891 if (islog
|| ishole
)
1893 /* Only print normal classes here */
1894 if (nvlist_exists(child
[c
], ZPOOL_CONFIG_ALLOCATION_BIAS
))
1897 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
1898 cb
->cb_name_flags
| VDEV_NAME_TYPE_ID
);
1899 print_status_config(zhp
, cb
, vname
, child
[c
], depth
+ 2,
1906 * Print the configuration of an exported pool. Iterate over all vdevs in the
1907 * pool, printing out the name and status for each one.
1910 print_import_config(status_cbdata_t
*cb
, const char *name
, nvlist_t
*nv
,
1918 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_TYPE
, &type
) == 0);
1919 if (strcmp(type
, VDEV_TYPE_MISSING
) == 0 ||
1920 strcmp(type
, VDEV_TYPE_HOLE
) == 0)
1923 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
1924 (uint64_t **)&vs
, &c
) == 0);
1926 (void) printf("\t%*s%-*s", depth
, "", cb
->cb_namewidth
- depth
, name
);
1927 (void) printf(" %s", zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
));
1929 if (vs
->vs_aux
!= 0) {
1932 switch (vs
->vs_aux
) {
1933 case VDEV_AUX_OPEN_FAILED
:
1934 (void) printf(gettext("cannot open"));
1937 case VDEV_AUX_BAD_GUID_SUM
:
1938 (void) printf(gettext("missing device"));
1941 case VDEV_AUX_NO_REPLICAS
:
1942 (void) printf(gettext("insufficient replicas"));
1945 case VDEV_AUX_VERSION_NEWER
:
1946 (void) printf(gettext("newer version"));
1949 case VDEV_AUX_UNSUP_FEAT
:
1950 (void) printf(gettext("unsupported feature(s)"));
1953 case VDEV_AUX_ERR_EXCEEDED
:
1954 (void) printf(gettext("too many errors"));
1957 case VDEV_AUX_ACTIVE
:
1958 (void) printf(gettext("currently in use"));
1961 case VDEV_AUX_CHILDREN_OFFLINE
:
1962 (void) printf(gettext("all children offline"));
1966 (void) printf(gettext("corrupted data"));
1970 (void) printf("\n");
1972 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1973 &child
, &children
) != 0)
1976 for (c
= 0; c
< children
; c
++) {
1977 uint64_t is_log
= B_FALSE
;
1979 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1983 if (nvlist_exists(child
[c
], ZPOOL_CONFIG_ALLOCATION_BIAS
))
1986 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
],
1987 cb
->cb_name_flags
| VDEV_NAME_TYPE_ID
);
1988 print_import_config(cb
, vname
, child
[c
], depth
+ 2);
1992 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
1993 &child
, &children
) == 0) {
1994 (void) printf(gettext("\tcache\n"));
1995 for (c
= 0; c
< children
; c
++) {
1996 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
],
1998 (void) printf("\t %s\n", vname
);
2003 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
2004 &child
, &children
) == 0) {
2005 (void) printf(gettext("\tspares\n"));
2006 for (c
= 0; c
< children
; c
++) {
2007 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
],
2009 (void) printf("\t %s\n", vname
);
2016 * Print specialized class vdevs.
2018 * These are recorded as top level vdevs in the main pool child array
2019 * but with "is_log" set to 1 or an "alloc_bias" string. We use either
2020 * print_status_config() or print_import_config() to print the top level
2021 * class vdevs then any of their children (eg mirrored slogs) are printed
2022 * recursively - which works because only the top level vdev is marked.
2025 print_class_vdevs(zpool_handle_t
*zhp
, status_cbdata_t
*cb
, nvlist_t
*nv
,
2030 boolean_t printed
= B_FALSE
;
2032 assert(zhp
!= NULL
|| !cb
->cb_verbose
);
2034 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
, &child
,
2038 for (c
= 0; c
< children
; c
++) {
2039 uint64_t is_log
= B_FALSE
;
2043 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
2047 bias
= VDEV_ALLOC_CLASS_LOGS
;
2049 (void) nvlist_lookup_string(child
[c
],
2050 ZPOOL_CONFIG_ALLOCATION_BIAS
, &bias
);
2051 (void) nvlist_lookup_string(child
[c
],
2052 ZPOOL_CONFIG_TYPE
, &type
);
2055 if (bias
== NULL
|| strcmp(bias
, class) != 0)
2057 if (!is_log
&& strcmp(type
, VDEV_TYPE_INDIRECT
) == 0)
2061 (void) printf("\t%s\t\n", gettext(class));
2065 char *name
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
2066 cb
->cb_name_flags
| VDEV_NAME_TYPE_ID
);
2067 if (cb
->cb_print_status
)
2068 print_status_config(zhp
, cb
, name
, child
[c
], 2,
2071 print_import_config(cb
, name
, child
[c
], 2);
2077 * Display the status for the given pool.
2080 show_import(nvlist_t
*config
)
2082 uint64_t pool_state
;
2086 uint64_t hostid
= 0;
2088 char *hostname
= "unknown";
2089 nvlist_t
*nvroot
, *nvinfo
;
2090 zpool_status_t reason
;
2091 zpool_errata_t errata
;
2095 status_cbdata_t cb
= { 0 };
2097 verify(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
2099 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
,
2101 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
2103 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
2106 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_VDEV_STATS
,
2107 (uint64_t **)&vs
, &vsc
) == 0);
2108 health
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
2110 reason
= zpool_import_status(config
, &msgid
, &errata
);
2112 (void) printf(gettext(" pool: %s\n"), name
);
2113 (void) printf(gettext(" id: %llu\n"), (u_longlong_t
)guid
);
2114 (void) printf(gettext(" state: %s"), health
);
2115 if (pool_state
== POOL_STATE_DESTROYED
)
2116 (void) printf(gettext(" (DESTROYED)"));
2117 (void) printf("\n");
2120 case ZPOOL_STATUS_MISSING_DEV_R
:
2121 case ZPOOL_STATUS_MISSING_DEV_NR
:
2122 case ZPOOL_STATUS_BAD_GUID_SUM
:
2123 (void) printf(gettext(" status: One or more devices are "
2124 "missing from the system.\n"));
2127 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
2128 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
2129 (void) printf(gettext(" status: One or more devices contains "
2130 "corrupted data.\n"));
2133 case ZPOOL_STATUS_CORRUPT_DATA
:
2135 gettext(" status: The pool data is corrupted.\n"));
2138 case ZPOOL_STATUS_OFFLINE_DEV
:
2139 (void) printf(gettext(" status: One or more devices "
2140 "are offlined.\n"));
2143 case ZPOOL_STATUS_CORRUPT_POOL
:
2144 (void) printf(gettext(" status: The pool metadata is "
2148 case ZPOOL_STATUS_VERSION_OLDER
:
2149 (void) printf(gettext(" status: The pool is formatted using a "
2150 "legacy on-disk version.\n"));
2153 case ZPOOL_STATUS_VERSION_NEWER
:
2154 (void) printf(gettext(" status: The pool is formatted using an "
2155 "incompatible version.\n"));
2158 case ZPOOL_STATUS_FEAT_DISABLED
:
2159 (void) printf(gettext(" status: Some supported features are "
2160 "not enabled on the pool.\n"));
2163 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
2164 (void) printf(gettext("status: The pool uses the following "
2165 "feature(s) not supported on this system:\n"));
2166 zpool_print_unsup_feat(config
);
2169 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
2170 (void) printf(gettext("status: The pool can only be accessed "
2171 "in read-only mode on this system. It\n\tcannot be "
2172 "accessed in read-write mode because it uses the "
2173 "following\n\tfeature(s) not supported on this system:\n"));
2174 zpool_print_unsup_feat(config
);
2177 case ZPOOL_STATUS_HOSTID_ACTIVE
:
2178 (void) printf(gettext(" status: The pool is currently "
2179 "imported by another system.\n"));
2182 case ZPOOL_STATUS_HOSTID_REQUIRED
:
2183 (void) printf(gettext(" status: The pool has the "
2184 "multihost property on. It cannot\n\tbe safely imported "
2185 "when the system hostid is not set.\n"));
2188 case ZPOOL_STATUS_HOSTID_MISMATCH
:
2189 (void) printf(gettext(" status: The pool was last accessed by "
2190 "another system.\n"));
2193 case ZPOOL_STATUS_FAULTED_DEV_R
:
2194 case ZPOOL_STATUS_FAULTED_DEV_NR
:
2195 (void) printf(gettext(" status: One or more devices are "
2199 case ZPOOL_STATUS_BAD_LOG
:
2200 (void) printf(gettext(" status: An intent log record cannot be "
2204 case ZPOOL_STATUS_RESILVERING
:
2205 (void) printf(gettext(" status: One or more devices were being "
2209 case ZPOOL_STATUS_ERRATA
:
2210 (void) printf(gettext(" status: Errata #%d detected.\n"),
2216 * No other status can be seen when importing pools.
2218 assert(reason
== ZPOOL_STATUS_OK
);
2222 * Print out an action according to the overall state of the pool.
2224 if (vs
->vs_state
== VDEV_STATE_HEALTHY
) {
2225 if (reason
== ZPOOL_STATUS_VERSION_OLDER
||
2226 reason
== ZPOOL_STATUS_FEAT_DISABLED
) {
2227 (void) printf(gettext(" action: The pool can be "
2228 "imported using its name or numeric identifier, "
2229 "though\n\tsome features will not be available "
2230 "without an explicit 'zpool upgrade'.\n"));
2231 } else if (reason
== ZPOOL_STATUS_HOSTID_MISMATCH
) {
2232 (void) printf(gettext(" action: The pool can be "
2233 "imported using its name or numeric "
2234 "identifier and\n\tthe '-f' flag.\n"));
2235 } else if (reason
== ZPOOL_STATUS_ERRATA
) {
2237 case ZPOOL_ERRATA_NONE
:
2240 case ZPOOL_ERRATA_ZOL_2094_SCRUB
:
2241 (void) printf(gettext(" action: The pool can "
2242 "be imported using its name or numeric "
2243 "identifier,\n\thowever there is a compat"
2244 "ibility issue which should be corrected"
2245 "\n\tby running 'zpool scrub'\n"));
2248 case ZPOOL_ERRATA_ZOL_2094_ASYNC_DESTROY
:
2249 (void) printf(gettext(" action: The pool can"
2250 "not be imported with this version of ZFS "
2251 "due to\n\tan active asynchronous destroy. "
2252 "Revert to an earlier version\n\tand "
2253 "allow the destroy to complete before "
2257 case ZPOOL_ERRATA_ZOL_6845_ENCRYPTION
:
2258 (void) printf(gettext(" action: Existing "
2259 "encrypted datasets contain an on-disk "
2260 "incompatibility, which\n\tneeds to be "
2261 "corrected. Backup these datasets to new "
2262 "encrypted datasets\n\tand destroy the "
2268 * All errata must contain an action message.
2273 (void) printf(gettext(" action: The pool can be "
2274 "imported using its name or numeric "
2277 } else if (vs
->vs_state
== VDEV_STATE_DEGRADED
) {
2278 (void) printf(gettext(" action: The pool can be imported "
2279 "despite missing or damaged devices. The\n\tfault "
2280 "tolerance of the pool may be compromised if imported.\n"));
2283 case ZPOOL_STATUS_VERSION_NEWER
:
2284 (void) printf(gettext(" action: The pool cannot be "
2285 "imported. Access the pool on a system running "
2286 "newer\n\tsoftware, or recreate the pool from "
2289 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
2290 (void) printf(gettext("action: The pool cannot be "
2291 "imported. Access the pool on a system that "
2292 "supports\n\tthe required feature(s), or recreate "
2293 "the pool from backup.\n"));
2295 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
2296 (void) printf(gettext("action: The pool cannot be "
2297 "imported in read-write mode. Import the pool "
2299 "\t\"-o readonly=on\", access the pool on a system "
2300 "that supports the\n\trequired feature(s), or "
2301 "recreate the pool from backup.\n"));
2303 case ZPOOL_STATUS_MISSING_DEV_R
:
2304 case ZPOOL_STATUS_MISSING_DEV_NR
:
2305 case ZPOOL_STATUS_BAD_GUID_SUM
:
2306 (void) printf(gettext(" action: The pool cannot be "
2307 "imported. Attach the missing\n\tdevices and try "
2310 case ZPOOL_STATUS_HOSTID_ACTIVE
:
2311 VERIFY0(nvlist_lookup_nvlist(config
,
2312 ZPOOL_CONFIG_LOAD_INFO
, &nvinfo
));
2314 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_MMP_HOSTNAME
))
2315 hostname
= fnvlist_lookup_string(nvinfo
,
2316 ZPOOL_CONFIG_MMP_HOSTNAME
);
2318 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_MMP_HOSTID
))
2319 hostid
= fnvlist_lookup_uint64(nvinfo
,
2320 ZPOOL_CONFIG_MMP_HOSTID
);
2322 (void) printf(gettext(" action: The pool must be "
2323 "exported from %s (hostid=%lx)\n\tbefore it "
2324 "can be safely imported.\n"), hostname
,
2325 (unsigned long) hostid
);
2327 case ZPOOL_STATUS_HOSTID_REQUIRED
:
2328 (void) printf(gettext(" action: Set a unique system "
2329 "hostid with the zgenhostid(8) command.\n"));
2332 (void) printf(gettext(" action: The pool cannot be "
2333 "imported due to damaged devices or data.\n"));
2337 /* Print the comment attached to the pool. */
2338 if (nvlist_lookup_string(config
, ZPOOL_CONFIG_COMMENT
, &comment
) == 0)
2339 (void) printf(gettext("comment: %s\n"), comment
);
2342 * If the state is "closed" or "can't open", and the aux state
2343 * is "corrupt data":
2345 if (((vs
->vs_state
== VDEV_STATE_CLOSED
) ||
2346 (vs
->vs_state
== VDEV_STATE_CANT_OPEN
)) &&
2347 (vs
->vs_aux
== VDEV_AUX_CORRUPT_DATA
)) {
2348 if (pool_state
== POOL_STATE_DESTROYED
)
2349 (void) printf(gettext("\tThe pool was destroyed, "
2350 "but can be imported using the '-Df' flags.\n"));
2351 else if (pool_state
!= POOL_STATE_EXPORTED
)
2352 (void) printf(gettext("\tThe pool may be active on "
2353 "another system, but can be imported using\n\t"
2354 "the '-f' flag.\n"));
2358 (void) printf(gettext(" see: http://zfsonlinux.org/msg/%s\n"),
2361 (void) printf(gettext(" config:\n\n"));
2363 cb
.cb_namewidth
= max_width(NULL
, nvroot
, 0, strlen(name
),
2365 if (cb
.cb_namewidth
< 10)
2366 cb
.cb_namewidth
= 10;
2368 print_import_config(&cb
, name
, nvroot
, 0);
2370 print_class_vdevs(NULL
, &cb
, nvroot
, VDEV_ALLOC_BIAS_DEDUP
);
2371 print_class_vdevs(NULL
, &cb
, nvroot
, VDEV_ALLOC_BIAS_SPECIAL
);
2372 print_class_vdevs(NULL
, &cb
, nvroot
, VDEV_ALLOC_CLASS_LOGS
);
2374 if (reason
== ZPOOL_STATUS_BAD_GUID_SUM
) {
2375 (void) printf(gettext("\n\tAdditional devices are known to "
2376 "be part of this pool, though their\n\texact "
2377 "configuration cannot be determined.\n"));
2382 zfs_force_import_required(nvlist_t
*config
)
2385 uint64_t hostid
= 0;
2388 state
= fnvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
);
2389 (void) nvlist_lookup_uint64(config
, ZPOOL_CONFIG_HOSTID
, &hostid
);
2391 if (state
!= POOL_STATE_EXPORTED
&& hostid
!= get_system_hostid())
2394 nvinfo
= fnvlist_lookup_nvlist(config
, ZPOOL_CONFIG_LOAD_INFO
);
2395 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_MMP_STATE
)) {
2396 mmp_state_t mmp_state
= fnvlist_lookup_uint64(nvinfo
,
2397 ZPOOL_CONFIG_MMP_STATE
);
2399 if (mmp_state
!= MMP_STATE_INACTIVE
)
2407 * Perform the import for the given configuration. This passes the heavy
2408 * lifting off to zpool_import_props(), and then mounts the datasets contained
2412 do_import(nvlist_t
*config
, const char *newname
, const char *mntopts
,
2413 nvlist_t
*props
, int flags
)
2416 zpool_handle_t
*zhp
;
2420 name
= fnvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
);
2421 version
= fnvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
);
2423 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
2424 (void) fprintf(stderr
, gettext("cannot import '%s': pool "
2425 "is formatted using an unsupported ZFS version\n"), name
);
2427 } else if (zfs_force_import_required(config
) &&
2428 !(flags
& ZFS_IMPORT_ANY_HOST
)) {
2429 mmp_state_t mmp_state
= MMP_STATE_INACTIVE
;
2432 nvinfo
= fnvlist_lookup_nvlist(config
, ZPOOL_CONFIG_LOAD_INFO
);
2433 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_MMP_STATE
))
2434 mmp_state
= fnvlist_lookup_uint64(nvinfo
,
2435 ZPOOL_CONFIG_MMP_STATE
);
2437 if (mmp_state
== MMP_STATE_ACTIVE
) {
2438 char *hostname
= "<unknown>";
2439 uint64_t hostid
= 0;
2441 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_MMP_HOSTNAME
))
2442 hostname
= fnvlist_lookup_string(nvinfo
,
2443 ZPOOL_CONFIG_MMP_HOSTNAME
);
2445 if (nvlist_exists(nvinfo
, ZPOOL_CONFIG_MMP_HOSTID
))
2446 hostid
= fnvlist_lookup_uint64(nvinfo
,
2447 ZPOOL_CONFIG_MMP_HOSTID
);
2449 (void) fprintf(stderr
, gettext("cannot import '%s': "
2450 "pool is imported on %s (hostid: "
2451 "0x%lx)\nExport the pool on the other system, "
2452 "then run 'zpool import'.\n"),
2453 name
, hostname
, (unsigned long) hostid
);
2454 } else if (mmp_state
== MMP_STATE_NO_HOSTID
) {
2455 (void) fprintf(stderr
, gettext("Cannot import '%s': "
2456 "pool has the multihost property on and the\n"
2457 "system's hostid is not set. Set a unique hostid "
2458 "with the zgenhostid(8) command.\n"), name
);
2460 char *hostname
= "<unknown>";
2461 uint64_t timestamp
= 0;
2462 uint64_t hostid
= 0;
2464 if (nvlist_exists(config
, ZPOOL_CONFIG_HOSTNAME
))
2465 hostname
= fnvlist_lookup_string(config
,
2466 ZPOOL_CONFIG_HOSTNAME
);
2468 if (nvlist_exists(config
, ZPOOL_CONFIG_TIMESTAMP
))
2469 timestamp
= fnvlist_lookup_uint64(config
,
2470 ZPOOL_CONFIG_TIMESTAMP
);
2472 if (nvlist_exists(config
, ZPOOL_CONFIG_HOSTID
))
2473 hostid
= fnvlist_lookup_uint64(config
,
2474 ZPOOL_CONFIG_HOSTID
);
2476 (void) fprintf(stderr
, gettext("cannot import '%s': "
2477 "pool was previously in use from another system.\n"
2478 "Last accessed by %s (hostid=%lx) at %s"
2479 "The pool can be imported, use 'zpool import -f' "
2480 "to import the pool.\n"), name
, hostname
,
2481 (unsigned long)hostid
, ctime((time_t *)×tamp
));
2487 if (zpool_import_props(g_zfs
, config
, newname
, props
, flags
) != 0)
2490 if (newname
!= NULL
)
2491 name
= (char *)newname
;
2493 if ((zhp
= zpool_open_canfail(g_zfs
, name
)) == NULL
)
2497 * Loading keys is best effort. We don't want to return immediately
2498 * if it fails but we do want to give the error to the caller.
2500 if (flags
& ZFS_IMPORT_LOAD_KEYS
) {
2501 ret
= zfs_crypto_attempt_load_keys(g_zfs
, name
);
2506 if (zpool_get_state(zhp
) != POOL_STATE_UNAVAIL
&&
2507 !(flags
& ZFS_IMPORT_ONLY
) &&
2508 zpool_enable_datasets(zhp
, mntopts
, 0) != 0) {
2518 * zpool checkpoint <pool>
2519 * checkpoint --discard <pool>
2521 * -d Discard the checkpoint from a checkpointed
2524 * Checkpoints the specified pool, by taking a "snapshot" of its
2525 * current state. A pool can only have one checkpoint at a time.
2528 zpool_do_checkpoint(int argc
, char **argv
)
2532 zpool_handle_t
*zhp
;
2535 struct option long_options
[] = {
2536 {"discard", no_argument
, NULL
, 'd'},
2541 while ((c
= getopt_long(argc
, argv
, ":d", long_options
, NULL
)) != -1) {
2547 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2557 (void) fprintf(stderr
, gettext("missing pool argument\n"));
2562 (void) fprintf(stderr
, gettext("too many arguments\n"));
2568 if ((zhp
= zpool_open(g_zfs
, pool
)) == NULL
) {
2569 /* As a special case, check for use of '/' in the name */
2570 if (strchr(pool
, '/') != NULL
)
2571 (void) fprintf(stderr
, gettext("'zpool checkpoint' "
2572 "doesn't work on datasets. To save the state "
2573 "of a dataset from a specific point in time "
2574 "please use 'zfs snapshot'\n"));
2579 err
= (zpool_discard_checkpoint(zhp
) != 0);
2581 err
= (zpool_checkpoint(zhp
) != 0);
2588 #define CHECKPOINT_OPT 1024
2591 * zpool import [-d dir] [-D]
2592 * import [-o mntopts] [-o prop=value] ... [-R root] [-D] [-l]
2593 * [-d dir | -c cachefile] [-f] -a
2594 * import [-o mntopts] [-o prop=value] ... [-R root] [-D] [-l]
2595 * [-d dir | -c cachefile] [-f] [-n] [-F] <pool | id> [newpool]
2597 * -c Read pool information from a cachefile instead of searching
2600 * -d Scan in a specific directory, other than /dev/. More than
2601 * one directory can be specified using multiple '-d' options.
2603 * -D Scan for previously destroyed pools or import all or only
2604 * specified destroyed pools.
2606 * -R Temporarily import the pool, with all mountpoints relative to
2607 * the given root. The pool will remain exported when the machine
2610 * -V Import even in the presence of faulted vdevs. This is an
2611 * intentionally undocumented option for testing purposes, and
2612 * treats the pool configuration as complete, leaving any bad
2613 * vdevs in the FAULTED state. In other words, it does verbatim
2616 * -f Force import, even if it appears that the pool is active.
2618 * -F Attempt rewind if necessary.
2620 * -n See if rewind would work, but don't actually rewind.
2622 * -N Import the pool but don't mount datasets.
2624 * -T Specify a starting txg to use for import. This option is
2625 * intentionally undocumented option for testing purposes.
2627 * -a Import all pools found.
2629 * -l Load encryption keys while importing.
2631 * -o Set property=value and/or temporary mount options (without '=').
2633 * -s Scan using the default search path, the libblkid cache will
2636 * --rewind-to-checkpoint
2637 * Import the pool and revert back to the checkpoint.
2639 * The import command scans for pools to import, and import pools based on pool
2640 * name and GUID. The pool can also be renamed as part of the import process.
2643 zpool_do_import(int argc
, char **argv
)
2645 char **searchdirs
= NULL
;
2646 char *env
, *envdup
= NULL
;
2650 nvlist_t
*pools
= NULL
;
2651 boolean_t do_all
= B_FALSE
;
2652 boolean_t do_destroyed
= B_FALSE
;
2653 char *mntopts
= NULL
;
2656 uint64_t searchguid
= 0;
2657 char *searchname
= NULL
;
2659 nvlist_t
*found_config
;
2660 nvlist_t
*policy
= NULL
;
2661 nvlist_t
*props
= NULL
;
2663 int flags
= ZFS_IMPORT_NORMAL
;
2664 uint32_t rewind_policy
= ZPOOL_NO_REWIND
;
2665 boolean_t dryrun
= B_FALSE
;
2666 boolean_t do_rewind
= B_FALSE
;
2667 boolean_t xtreme_rewind
= B_FALSE
;
2668 boolean_t do_scan
= B_FALSE
;
2669 uint64_t pool_state
, txg
= -1ULL;
2670 char *cachefile
= NULL
;
2671 importargs_t idata
= { 0 };
2674 struct option long_options
[] = {
2675 {"rewind-to-checkpoint", no_argument
, NULL
, CHECKPOINT_OPT
},
2680 while ((c
= getopt_long(argc
, argv
, ":aCc:d:DEfFlmnNo:R:stT:VX",
2681 long_options
, NULL
)) != -1) {
2690 if (searchdirs
== NULL
) {
2691 searchdirs
= safe_malloc(sizeof (char *));
2693 char **tmp
= safe_malloc((nsearch
+ 1) *
2695 bcopy(searchdirs
, tmp
, nsearch
*
2700 searchdirs
[nsearch
++] = optarg
;
2703 do_destroyed
= B_TRUE
;
2706 flags
|= ZFS_IMPORT_ANY_HOST
;
2712 flags
|= ZFS_IMPORT_LOAD_KEYS
;
2715 flags
|= ZFS_IMPORT_MISSING_LOG
;
2721 flags
|= ZFS_IMPORT_ONLY
;
2724 if ((propval
= strchr(optarg
, '=')) != NULL
) {
2727 if (add_prop_list(optarg
, propval
,
2735 if (add_prop_list(zpool_prop_to_name(
2736 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
2738 if (add_prop_list_default(zpool_prop_to_name(
2739 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
2746 flags
|= ZFS_IMPORT_TEMP_NAME
;
2747 if (add_prop_list_default(zpool_prop_to_name(
2748 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
2754 txg
= strtoull(optarg
, &endptr
, 0);
2755 if (errno
!= 0 || *endptr
!= '\0') {
2756 (void) fprintf(stderr
,
2757 gettext("invalid txg value\n"));
2760 rewind_policy
= ZPOOL_DO_REWIND
| ZPOOL_EXTREME_REWIND
;
2763 flags
|= ZFS_IMPORT_VERBATIM
;
2766 xtreme_rewind
= B_TRUE
;
2768 case CHECKPOINT_OPT
:
2769 flags
|= ZFS_IMPORT_CHECKPOINT
;
2772 (void) fprintf(stderr
, gettext("missing argument for "
2773 "'%c' option\n"), optopt
);
2777 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2786 if (cachefile
&& nsearch
!= 0) {
2787 (void) fprintf(stderr
, gettext("-c is incompatible with -d\n"));
2791 if ((flags
& ZFS_IMPORT_LOAD_KEYS
) && (flags
& ZFS_IMPORT_ONLY
)) {
2792 (void) fprintf(stderr
, gettext("-l is incompatible with -N\n"));
2796 if ((flags
& ZFS_IMPORT_LOAD_KEYS
) && !do_all
&& argc
== 0) {
2797 (void) fprintf(stderr
, gettext("-l is only meaningful during "
2802 if ((dryrun
|| xtreme_rewind
) && !do_rewind
) {
2803 (void) fprintf(stderr
,
2804 gettext("-n or -X only meaningful with -F\n"));
2808 rewind_policy
= ZPOOL_TRY_REWIND
;
2810 rewind_policy
= ZPOOL_DO_REWIND
;
2812 rewind_policy
|= ZPOOL_EXTREME_REWIND
;
2814 /* In the future, we can capture further policy and include it here */
2815 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME
, 0) != 0 ||
2816 nvlist_add_uint64(policy
, ZPOOL_LOAD_REQUEST_TXG
, txg
) != 0 ||
2817 nvlist_add_uint32(policy
, ZPOOL_LOAD_REWIND_POLICY
,
2818 rewind_policy
) != 0)
2821 /* check argument count */
2824 (void) fprintf(stderr
, gettext("too many arguments\n"));
2829 (void) fprintf(stderr
, gettext("too many arguments\n"));
2835 * Check for the effective uid. We do this explicitly here because
2836 * otherwise any attempt to discover pools will silently fail.
2838 if (argc
== 0 && geteuid() != 0) {
2839 (void) fprintf(stderr
, gettext("cannot "
2840 "discover pools: permission denied\n"));
2841 if (searchdirs
!= NULL
)
2845 nvlist_free(policy
);
2850 * Depending on the arguments given, we do one of the following:
2852 * <none> Iterate through all pools and display information about
2855 * -a Iterate through all pools and try to import each one.
2857 * <id> Find the pool that corresponds to the given GUID/pool
2858 * name and import that one.
2860 * -D Above options applies only to destroyed pools.
2866 searchguid
= strtoull(argv
[0], &endptr
, 10);
2867 if (errno
!= 0 || *endptr
!= '\0') {
2868 searchname
= argv
[0];
2871 found_config
= NULL
;
2874 * User specified a name or guid. Ensure it's unique.
2876 idata
.unique
= B_TRUE
;
2880 * Check the environment for the preferred search path.
2882 if ((searchdirs
== NULL
) && (env
= getenv("ZPOOL_IMPORT_PATH"))) {
2885 envdup
= strdup(env
);
2887 dir
= strtok(envdup
, ":");
2888 while (dir
!= NULL
) {
2889 if (searchdirs
== NULL
) {
2890 searchdirs
= safe_malloc(sizeof (char *));
2892 char **tmp
= safe_malloc((nsearch
+ 1) *
2894 bcopy(searchdirs
, tmp
, nsearch
*
2899 searchdirs
[nsearch
++] = dir
;
2900 dir
= strtok(NULL
, ":");
2904 idata
.path
= searchdirs
;
2905 idata
.paths
= nsearch
;
2906 idata
.poolname
= searchname
;
2907 idata
.guid
= searchguid
;
2908 idata
.cachefile
= cachefile
;
2909 idata
.scan
= do_scan
;
2910 idata
.policy
= policy
;
2912 pools
= zpool_search_import(g_zfs
, &idata
);
2914 if (pools
!= NULL
&& idata
.exists
&&
2915 (argc
== 1 || strcmp(argv
[0], argv
[1]) == 0)) {
2916 (void) fprintf(stderr
, gettext("cannot import '%s': "
2917 "a pool with that name already exists\n"),
2919 (void) fprintf(stderr
, gettext("use the form '%s "
2920 "<pool | id> <newpool>' to give it a new name\n"),
2923 } else if (pools
== NULL
&& idata
.exists
) {
2924 (void) fprintf(stderr
, gettext("cannot import '%s': "
2925 "a pool with that name is already created/imported,\n"),
2927 (void) fprintf(stderr
, gettext("and no additional pools "
2928 "with that name were found\n"));
2930 } else if (pools
== NULL
) {
2932 (void) fprintf(stderr
, gettext("cannot import '%s': "
2933 "no such pool available\n"), argv
[0]);
2939 if (searchdirs
!= NULL
)
2943 nvlist_free(policy
);
2950 * At this point we have a list of import candidate configs. Even if
2951 * we were searching by pool name or guid, we still need to
2952 * post-process the list to deal with pool state and possible
2958 while ((elem
= nvlist_next_nvpair(pools
, elem
)) != NULL
) {
2960 verify(nvpair_value_nvlist(elem
, &config
) == 0);
2962 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
2964 if (!do_destroyed
&& pool_state
== POOL_STATE_DESTROYED
)
2966 if (do_destroyed
&& pool_state
!= POOL_STATE_DESTROYED
)
2969 verify(nvlist_add_nvlist(config
, ZPOOL_LOAD_POLICY
,
2976 (void) printf("\n");
2979 err
|= do_import(config
, NULL
, mntopts
,
2982 show_import(config
);
2984 } else if (searchname
!= NULL
) {
2988 * We are searching for a pool based on name.
2990 verify(nvlist_lookup_string(config
,
2991 ZPOOL_CONFIG_POOL_NAME
, &name
) == 0);
2993 if (strcmp(name
, searchname
) == 0) {
2994 if (found_config
!= NULL
) {
2995 (void) fprintf(stderr
, gettext(
2996 "cannot import '%s': more than "
2997 "one matching pool\n"), searchname
);
2998 (void) fprintf(stderr
, gettext(
2999 "import by numeric ID instead\n"));
3002 found_config
= config
;
3008 * Search for a pool by guid.
3010 verify(nvlist_lookup_uint64(config
,
3011 ZPOOL_CONFIG_POOL_GUID
, &guid
) == 0);
3013 if (guid
== searchguid
)
3014 found_config
= config
;
3019 * If we were searching for a specific pool, verify that we found a
3020 * pool, and then do the import.
3022 if (argc
!= 0 && err
== 0) {
3023 if (found_config
== NULL
) {
3024 (void) fprintf(stderr
, gettext("cannot import '%s': "
3025 "no such pool available\n"), argv
[0]);
3028 err
|= do_import(found_config
, argc
== 1 ? NULL
:
3029 argv
[1], mntopts
, props
, flags
);
3034 * If we were just looking for pools, report an error if none were
3037 if (argc
== 0 && first
)
3038 (void) fprintf(stderr
,
3039 gettext("no pools available to import\n"));
3044 nvlist_free(policy
);
3045 if (searchdirs
!= NULL
)
3050 return (err
? 1 : 0);
3054 * zpool sync [-f] [pool] ...
3056 * -f (undocumented) force uberblock (and config including zpool cache file)
3059 * Sync the specified pool(s).
3060 * Without arguments "zpool sync" will sync all pools.
3061 * This command initiates TXG sync(s) and will return after the TXG(s) commit.
3065 zpool_do_sync(int argc
, char **argv
)
3068 boolean_t force
= B_FALSE
;
3071 while ((ret
= getopt(argc
, argv
, "f")) != -1) {
3077 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3086 /* if argc == 0 we will execute zpool_sync_one on all pools */
3087 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
, zpool_sync_one
, &force
);
3092 typedef struct iostat_cbdata
{
3097 char **cb_vdev_names
; /* Only show these vdevs */
3098 unsigned int cb_vdev_names_count
;
3099 boolean_t cb_verbose
;
3100 boolean_t cb_literal
;
3101 boolean_t cb_scripted
;
3102 zpool_list_t
*cb_list
;
3103 vdev_cmd_data_list_t
*vcdl
;
3107 typedef struct name_and_columns
{
3108 const char *name
; /* Column name */
3109 unsigned int columns
; /* Center name to this number of columns */
3110 } name_and_columns_t
;
3112 #define IOSTAT_MAX_LABELS 11 /* Max number of labels on one line */
3114 static const name_and_columns_t iostat_top_labels
[][IOSTAT_MAX_LABELS
] =
3116 [IOS_DEFAULT
] = {{"capacity", 2}, {"operations", 2}, {"bandwidth", 2},
3118 [IOS_LATENCY
] = {{"total_wait", 2}, {"disk_wait", 2}, {"syncq_wait", 2},
3119 {"asyncq_wait", 2}, {"scrub"}},
3120 [IOS_QUEUES
] = {{"syncq_read", 2}, {"syncq_write", 2},
3121 {"asyncq_read", 2}, {"asyncq_write", 2}, {"scrubq_read", 2},
3123 [IOS_L_HISTO
] = {{"total_wait", 2}, {"disk_wait", 2},
3124 {"sync_queue", 2}, {"async_queue", 2}, {NULL
}},
3125 [IOS_RQ_HISTO
] = {{"sync_read", 2}, {"sync_write", 2},
3126 {"async_read", 2}, {"async_write", 2}, {"scrub", 2}, {NULL
}},
3130 /* Shorthand - if "columns" field not set, default to 1 column */
3131 static const name_and_columns_t iostat_bottom_labels
[][IOSTAT_MAX_LABELS
] =
3133 [IOS_DEFAULT
] = {{"alloc"}, {"free"}, {"read"}, {"write"}, {"read"},
3135 [IOS_LATENCY
] = {{"read"}, {"write"}, {"read"}, {"write"}, {"read"},
3136 {"write"}, {"read"}, {"write"}, {"wait"}, {NULL
}},
3137 [IOS_QUEUES
] = {{"pend"}, {"activ"}, {"pend"}, {"activ"}, {"pend"},
3138 {"activ"}, {"pend"}, {"activ"}, {"pend"}, {"activ"}, {NULL
}},
3139 [IOS_L_HISTO
] = {{"read"}, {"write"}, {"read"}, {"write"}, {"read"},
3140 {"write"}, {"read"}, {"write"}, {"scrub"}, {NULL
}},
3141 [IOS_RQ_HISTO
] = {{"ind"}, {"agg"}, {"ind"}, {"agg"}, {"ind"}, {"agg"},
3142 {"ind"}, {"agg"}, {"ind"}, {"agg"}, {NULL
}},
3145 static const char *histo_to_title
[] = {
3146 [IOS_L_HISTO
] = "latency",
3147 [IOS_RQ_HISTO
] = "req_size",
3151 * Return the number of labels in a null-terminated name_and_columns_t
3156 label_array_len(const name_and_columns_t
*labels
)
3160 while (labels
[i
].name
)
3167 * Return the number of strings in a null-terminated string array.
3170 * const char foo[] = {"bar", "baz", NULL}
3175 str_array_len(const char *array
[])
3186 * Return a default column width for default/latency/queue columns. This does
3187 * not include histograms, which have their columns autosized.
3190 default_column_width(iostat_cbdata_t
*cb
, enum iostat_type type
)
3192 unsigned long column_width
= 5; /* Normal niceprint */
3193 static unsigned long widths
[] = {
3195 * Choose some sane default column sizes for printing the
3198 [IOS_DEFAULT
] = 15, /* 1PB capacity */
3199 [IOS_LATENCY
] = 10, /* 1B ns = 10sec */
3200 [IOS_QUEUES
] = 6, /* 1M queue entries */
3204 column_width
= widths
[type
];
3206 return (column_width
);
3210 * Print the column labels, i.e:
3212 * capacity operations bandwidth
3213 * alloc free read write read write ...
3215 * If force_column_width is set, use it for the column width. If not set, use
3216 * the default column width.
3219 print_iostat_labels(iostat_cbdata_t
*cb
, unsigned int force_column_width
,
3220 const name_and_columns_t labels
[][IOSTAT_MAX_LABELS
])
3223 unsigned int text_start
, rw_column_width
, spaces_to_end
;
3224 uint64_t flags
= cb
->cb_flags
;
3226 unsigned int column_width
= force_column_width
;
3228 /* For each bit set in flags */
3229 for (f
= flags
; f
; f
&= ~(1ULL << idx
)) {
3230 idx
= lowbit64(f
) - 1;
3231 if (!force_column_width
)
3232 column_width
= default_column_width(cb
, idx
);
3233 /* Print our top labels centered over "read write" label. */
3234 for (i
= 0; i
< label_array_len(labels
[idx
]); i
++) {
3235 const char *name
= labels
[idx
][i
].name
;
3237 * We treat labels[][].columns == 0 as shorthand
3238 * for one column. It makes writing out the label
3239 * tables more concise.
3241 unsigned int columns
= MAX(1, labels
[idx
][i
].columns
);
3242 unsigned int slen
= strlen(name
);
3244 rw_column_width
= (column_width
* columns
) +
3245 (2 * (columns
- 1));
3247 text_start
= (int)((rw_column_width
)/columns
-
3250 printf(" "); /* Two spaces between columns */
3252 /* Space from beginning of column to label */
3253 for (s
= 0; s
< text_start
; s
++)
3258 /* Print space after label to end of column */
3259 spaces_to_end
= rw_column_width
- text_start
- slen
;
3260 for (s
= 0; s
< spaces_to_end
; s
++)
3269 * print_cmd_columns - Print custom column titles from -c
3271 * If the user specified the "zpool status|iostat -c" then print their custom
3272 * column titles in the header. For example, print_cmd_columns() would print
3273 * the " col1 col2" part of this:
3275 * $ zpool iostat -vc 'echo col1=val1; echo col2=val2'
3277 * capacity operations bandwidth
3278 * pool alloc free read write read write col1 col2
3279 * ---------- ----- ----- ----- ----- ----- ----- ---- ----
3280 * mypool 269K 1008M 0 0 107 946
3281 * mirror 269K 1008M 0 0 107 946
3282 * sdb - - 0 0 102 473 val1 val2
3283 * sdc - - 0 0 5 473 val1 val2
3284 * ---------- ----- ----- ----- ----- ----- ----- ---- ----
3287 print_cmd_columns(vdev_cmd_data_list_t
*vcdl
, int use_dashes
)
3290 vdev_cmd_data_t
*data
= &vcdl
->data
[0];
3292 if (vcdl
->count
== 0 || data
== NULL
)
3296 * Each vdev cmd should have the same column names unless the user did
3297 * something weird with their cmd. Just take the column names from the
3298 * first vdev and assume it works for all of them.
3300 for (i
= 0; i
< vcdl
->uniq_cols_cnt
; i
++) {
3303 for (j
= 0; j
< vcdl
->uniq_cols_width
[i
]; j
++)
3306 printf("%*s", vcdl
->uniq_cols_width
[i
],
3307 vcdl
->uniq_cols
[i
]);
3314 * Utility function to print out a line of dashes like:
3316 * -------------------------------- ----- ----- ----- ----- -----
3318 * ...or a dashed named-row line like:
3324 * @force_column_width If non-zero, use the value as the column width.
3325 * Otherwise use the default column widths.
3327 * @name: Print a dashed named-row line starting
3328 * with @name. Otherwise, print a regular
3332 print_iostat_dashes(iostat_cbdata_t
*cb
, unsigned int force_column_width
,
3336 unsigned int namewidth
;
3337 uint64_t flags
= cb
->cb_flags
;
3340 const name_and_columns_t
*labels
;
3344 if (cb
->cb_flags
& IOS_ANYHISTO_M
) {
3345 title
= histo_to_title
[IOS_HISTO_IDX(cb
->cb_flags
)];
3346 } else if (cb
->cb_vdev_names_count
) {
3352 namewidth
= MAX(MAX(strlen(title
), cb
->cb_namewidth
),
3353 name
? strlen(name
) : 0);
3357 printf("%-*s", namewidth
, name
);
3359 for (i
= 0; i
< namewidth
; i
++)
3363 /* For each bit in flags */
3364 for (f
= flags
; f
; f
&= ~(1ULL << idx
)) {
3365 unsigned int column_width
;
3366 idx
= lowbit64(f
) - 1;
3367 if (force_column_width
)
3368 column_width
= force_column_width
;
3370 column_width
= default_column_width(cb
, idx
);
3372 labels
= iostat_bottom_labels
[idx
];
3373 for (i
= 0; i
< label_array_len(labels
); i
++) {
3375 printf(" %*s-", column_width
- 1, " ");
3377 printf(" %.*s", column_width
,
3378 "--------------------");
3385 print_iostat_separator_impl(iostat_cbdata_t
*cb
,
3386 unsigned int force_column_width
)
3388 print_iostat_dashes(cb
, force_column_width
, NULL
);
3392 print_iostat_separator(iostat_cbdata_t
*cb
)
3394 print_iostat_separator_impl(cb
, 0);
3398 print_iostat_header_impl(iostat_cbdata_t
*cb
, unsigned int force_column_width
,
3399 const char *histo_vdev_name
)
3401 unsigned int namewidth
;
3404 if (cb
->cb_flags
& IOS_ANYHISTO_M
) {
3405 title
= histo_to_title
[IOS_HISTO_IDX(cb
->cb_flags
)];
3406 } else if (cb
->cb_vdev_names_count
) {
3412 namewidth
= MAX(MAX(strlen(title
), cb
->cb_namewidth
),
3413 histo_vdev_name
? strlen(histo_vdev_name
) : 0);
3415 if (histo_vdev_name
)
3416 printf("%-*s", namewidth
, histo_vdev_name
);
3418 printf("%*s", namewidth
, "");
3421 print_iostat_labels(cb
, force_column_width
, iostat_top_labels
);
3424 printf("%-*s", namewidth
, title
);
3426 print_iostat_labels(cb
, force_column_width
, iostat_bottom_labels
);
3427 if (cb
->vcdl
!= NULL
)
3428 print_cmd_columns(cb
->vcdl
, 0);
3432 print_iostat_separator_impl(cb
, force_column_width
);
3434 if (cb
->vcdl
!= NULL
)
3435 print_cmd_columns(cb
->vcdl
, 1);
3441 print_iostat_header(iostat_cbdata_t
*cb
)
3443 print_iostat_header_impl(cb
, 0, NULL
);
3448 * Display a single statistic.
3451 print_one_stat(uint64_t value
, enum zfs_nicenum_format format
,
3452 unsigned int column_size
, boolean_t scripted
)
3456 zfs_nicenum_format(value
, buf
, sizeof (buf
), format
);
3459 printf("\t%s", buf
);
3461 printf(" %*s", column_size
, buf
);
3465 * Calculate the default vdev stats
3467 * Subtract oldvs from newvs, apply a scaling factor, and save the resulting
3468 * stats into calcvs.
3471 calc_default_iostats(vdev_stat_t
*oldvs
, vdev_stat_t
*newvs
,
3472 vdev_stat_t
*calcvs
)
3476 memcpy(calcvs
, newvs
, sizeof (*calcvs
));
3477 for (i
= 0; i
< ARRAY_SIZE(calcvs
->vs_ops
); i
++)
3478 calcvs
->vs_ops
[i
] = (newvs
->vs_ops
[i
] - oldvs
->vs_ops
[i
]);
3480 for (i
= 0; i
< ARRAY_SIZE(calcvs
->vs_bytes
); i
++)
3481 calcvs
->vs_bytes
[i
] = (newvs
->vs_bytes
[i
] - oldvs
->vs_bytes
[i
]);
3485 * Internal representation of the extended iostats data.
3487 * The extended iostat stats are exported in nvlists as either uint64_t arrays
3488 * or single uint64_t's. We make both look like arrays to make them easier
3489 * to process. In order to make single uint64_t's look like arrays, we set
3490 * __data to the stat data, and then set *data = &__data with count = 1. Then,
3491 * we can just use *data and count.
3495 uint_t count
; /* Number of entries in data[] */
3496 uint64_t __data
; /* Only used when data is a single uint64_t */
3500 stat_histo_max(struct stat_array
*nva
, unsigned int len
)
3504 for (i
= 0; i
< len
; i
++)
3505 max
= MAX(max
, array64_max(nva
[i
].data
, nva
[i
].count
));
3511 * Helper function to lookup a uint64_t array or uint64_t value and store its
3512 * data as a stat_array. If the nvpair is a single uint64_t value, then we make
3513 * it look like a one element array to make it easier to process.
3516 nvpair64_to_stat_array(nvlist_t
*nvl
, const char *name
,
3517 struct stat_array
*nva
)
3522 verify(nvlist_lookup_nvpair(nvl
, name
, &tmp
) == 0);
3523 switch (nvpair_type(tmp
)) {
3524 case DATA_TYPE_UINT64_ARRAY
:
3525 ret
= nvpair_value_uint64_array(tmp
, &nva
->data
, &nva
->count
);
3527 case DATA_TYPE_UINT64
:
3528 ret
= nvpair_value_uint64(tmp
, &nva
->__data
);
3529 nva
->data
= &nva
->__data
;
3533 /* Not a uint64_t */
3542 * Given a list of nvlist names, look up the extended stats in newnv and oldnv,
3543 * subtract them, and return the results in a newly allocated stat_array.
3544 * You must free the returned array after you are done with it with
3545 * free_calc_stats().
3547 * Additionally, you can set "oldnv" to NULL if you simply want the newnv
3550 static struct stat_array
*
3551 calc_and_alloc_stats_ex(const char **names
, unsigned int len
, nvlist_t
*oldnv
,
3554 nvlist_t
*oldnvx
= NULL
, *newnvx
;
3555 struct stat_array
*oldnva
, *newnva
, *calcnva
;
3557 unsigned int alloc_size
= (sizeof (struct stat_array
)) * len
;
3559 /* Extract our extended stats nvlist from the main list */
3560 verify(nvlist_lookup_nvlist(newnv
, ZPOOL_CONFIG_VDEV_STATS_EX
,
3563 verify(nvlist_lookup_nvlist(oldnv
, ZPOOL_CONFIG_VDEV_STATS_EX
,
3567 newnva
= safe_malloc(alloc_size
);
3568 oldnva
= safe_malloc(alloc_size
);
3569 calcnva
= safe_malloc(alloc_size
);
3571 for (j
= 0; j
< len
; j
++) {
3572 verify(nvpair64_to_stat_array(newnvx
, names
[j
],
3574 calcnva
[j
].count
= newnva
[j
].count
;
3575 alloc_size
= calcnva
[j
].count
* sizeof (calcnva
[j
].data
[0]);
3576 calcnva
[j
].data
= safe_malloc(alloc_size
);
3577 memcpy(calcnva
[j
].data
, newnva
[j
].data
, alloc_size
);
3580 verify(nvpair64_to_stat_array(oldnvx
, names
[j
],
3582 for (i
= 0; i
< oldnva
[j
].count
; i
++)
3583 calcnva
[j
].data
[i
] -= oldnva
[j
].data
[i
];
3592 free_calc_stats(struct stat_array
*nva
, unsigned int len
)
3595 for (i
= 0; i
< len
; i
++)
3602 print_iostat_histo(struct stat_array
*nva
, unsigned int len
,
3603 iostat_cbdata_t
*cb
, unsigned int column_width
, unsigned int namewidth
,
3609 enum zfs_nicenum_format format
;
3610 unsigned int buckets
;
3611 unsigned int start_bucket
;
3614 format
= ZFS_NICENUM_RAW
;
3616 format
= ZFS_NICENUM_1024
;
3618 /* All these histos are the same size, so just use nva[0].count */
3619 buckets
= nva
[0].count
;
3621 if (cb
->cb_flags
& IOS_RQ_HISTO_M
) {
3622 /* Start at 512 - req size should never be lower than this */
3628 for (j
= start_bucket
; j
< buckets
; j
++) {
3629 /* Print histogram bucket label */
3630 if (cb
->cb_flags
& IOS_L_HISTO_M
) {
3631 /* Ending range of this bucket */
3632 val
= (1UL << (j
+ 1)) - 1;
3633 zfs_nicetime(val
, buf
, sizeof (buf
));
3635 /* Request size (starting range of bucket) */
3637 zfs_nicenum(val
, buf
, sizeof (buf
));
3640 if (cb
->cb_scripted
)
3641 printf("%llu", (u_longlong_t
)val
);
3643 printf("%-*s", namewidth
, buf
);
3645 /* Print the values on the line */
3646 for (i
= 0; i
< len
; i
++) {
3647 print_one_stat(nva
[i
].data
[j
] * scale
, format
,
3648 column_width
, cb
->cb_scripted
);
3655 print_solid_separator(unsigned int length
)
3663 print_iostat_histos(iostat_cbdata_t
*cb
, nvlist_t
*oldnv
,
3664 nvlist_t
*newnv
, double scale
, const char *name
)
3666 unsigned int column_width
;
3667 unsigned int namewidth
;
3668 unsigned int entire_width
;
3669 enum iostat_type type
;
3670 struct stat_array
*nva
;
3672 unsigned int names_len
;
3674 /* What type of histo are we? */
3675 type
= IOS_HISTO_IDX(cb
->cb_flags
);
3677 /* Get NULL-terminated array of nvlist names for our histo */
3678 names
= vsx_type_to_nvlist
[type
];
3679 names_len
= str_array_len(names
); /* num of names */
3681 nva
= calc_and_alloc_stats_ex(names
, names_len
, oldnv
, newnv
);
3683 if (cb
->cb_literal
) {
3684 column_width
= MAX(5,
3685 (unsigned int) log10(stat_histo_max(nva
, names_len
)) + 1);
3690 namewidth
= MAX(cb
->cb_namewidth
,
3691 strlen(histo_to_title
[IOS_HISTO_IDX(cb
->cb_flags
)]));
3694 * Calculate the entire line width of what we're printing. The
3695 * +2 is for the two spaces between columns:
3699 /* |___| <---------- column_width */
3701 /* |__________| <--- entire_width */
3703 entire_width
= namewidth
+ (column_width
+ 2) *
3704 label_array_len(iostat_bottom_labels
[type
]);
3706 if (cb
->cb_scripted
)
3707 printf("%s\n", name
);
3709 print_iostat_header_impl(cb
, column_width
, name
);
3711 print_iostat_histo(nva
, names_len
, cb
, column_width
,
3714 free_calc_stats(nva
, names_len
);
3715 if (!cb
->cb_scripted
)
3716 print_solid_separator(entire_width
);
3720 * Calculate the average latency of a power-of-two latency histogram
3723 single_histo_average(uint64_t *histo
, unsigned int buckets
)
3726 uint64_t count
= 0, total
= 0;
3728 for (i
= 0; i
< buckets
; i
++) {
3730 * Our buckets are power-of-two latency ranges. Use the
3731 * midpoint latency of each bucket to calculate the average.
3739 if (histo
[i
] != 0) {
3740 total
+= histo
[i
] * (((1UL << i
) + ((1UL << i
)/2)));
3745 /* Prevent divide by zero */
3746 return (count
== 0 ? 0 : total
/ count
);
3750 print_iostat_queues(iostat_cbdata_t
*cb
, nvlist_t
*oldnv
,
3751 nvlist_t
*newnv
, double scale
)
3755 const char *names
[] = {
3756 ZPOOL_CONFIG_VDEV_SYNC_R_PEND_QUEUE
,
3757 ZPOOL_CONFIG_VDEV_SYNC_R_ACTIVE_QUEUE
,
3758 ZPOOL_CONFIG_VDEV_SYNC_W_PEND_QUEUE
,
3759 ZPOOL_CONFIG_VDEV_SYNC_W_ACTIVE_QUEUE
,
3760 ZPOOL_CONFIG_VDEV_ASYNC_R_PEND_QUEUE
,
3761 ZPOOL_CONFIG_VDEV_ASYNC_R_ACTIVE_QUEUE
,
3762 ZPOOL_CONFIG_VDEV_ASYNC_W_PEND_QUEUE
,
3763 ZPOOL_CONFIG_VDEV_ASYNC_W_ACTIVE_QUEUE
,
3764 ZPOOL_CONFIG_VDEV_SCRUB_PEND_QUEUE
,
3765 ZPOOL_CONFIG_VDEV_SCRUB_ACTIVE_QUEUE
,
3768 struct stat_array
*nva
;
3770 unsigned int column_width
= default_column_width(cb
, IOS_QUEUES
);
3771 enum zfs_nicenum_format format
;
3773 nva
= calc_and_alloc_stats_ex(names
, ARRAY_SIZE(names
), NULL
, newnv
);
3776 format
= ZFS_NICENUM_RAW
;
3778 format
= ZFS_NICENUM_1024
;
3780 for (i
= 0; i
< ARRAY_SIZE(names
); i
++) {
3781 val
= nva
[i
].data
[0] * scale
;
3782 print_one_stat(val
, format
, column_width
, cb
->cb_scripted
);
3785 free_calc_stats(nva
, ARRAY_SIZE(names
));
3789 print_iostat_latency(iostat_cbdata_t
*cb
, nvlist_t
*oldnv
,
3790 nvlist_t
*newnv
, double scale
)
3794 const char *names
[] = {
3795 ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO
,
3796 ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO
,
3797 ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO
,
3798 ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO
,
3799 ZPOOL_CONFIG_VDEV_SYNC_R_LAT_HISTO
,
3800 ZPOOL_CONFIG_VDEV_SYNC_W_LAT_HISTO
,
3801 ZPOOL_CONFIG_VDEV_ASYNC_R_LAT_HISTO
,
3802 ZPOOL_CONFIG_VDEV_ASYNC_W_LAT_HISTO
,
3803 ZPOOL_CONFIG_VDEV_SCRUB_LAT_HISTO
,
3805 struct stat_array
*nva
;
3807 unsigned int column_width
= default_column_width(cb
, IOS_LATENCY
);
3808 enum zfs_nicenum_format format
;
3810 nva
= calc_and_alloc_stats_ex(names
, ARRAY_SIZE(names
), oldnv
, newnv
);
3813 format
= ZFS_NICENUM_RAWTIME
;
3815 format
= ZFS_NICENUM_TIME
;
3817 /* Print our avg latencies on the line */
3818 for (i
= 0; i
< ARRAY_SIZE(names
); i
++) {
3819 /* Compute average latency for a latency histo */
3820 val
= single_histo_average(nva
[i
].data
, nva
[i
].count
) * scale
;
3821 print_one_stat(val
, format
, column_width
, cb
->cb_scripted
);
3823 free_calc_stats(nva
, ARRAY_SIZE(names
));
3827 * Print default statistics (capacity/operations/bandwidth)
3830 print_iostat_default(vdev_stat_t
*vs
, iostat_cbdata_t
*cb
, double scale
)
3832 unsigned int column_width
= default_column_width(cb
, IOS_DEFAULT
);
3833 enum zfs_nicenum_format format
;
3834 char na
; /* char to print for "not applicable" values */
3836 if (cb
->cb_literal
) {
3837 format
= ZFS_NICENUM_RAW
;
3840 format
= ZFS_NICENUM_1024
;
3844 /* only toplevel vdevs have capacity stats */
3845 if (vs
->vs_space
== 0) {
3846 if (cb
->cb_scripted
)
3847 printf("\t%c\t%c", na
, na
);
3849 printf(" %*c %*c", column_width
, na
, column_width
,
3852 print_one_stat(vs
->vs_alloc
, format
, column_width
,
3854 print_one_stat(vs
->vs_space
- vs
->vs_alloc
, format
,
3855 column_width
, cb
->cb_scripted
);
3858 print_one_stat((uint64_t)(vs
->vs_ops
[ZIO_TYPE_READ
] * scale
),
3859 format
, column_width
, cb
->cb_scripted
);
3860 print_one_stat((uint64_t)(vs
->vs_ops
[ZIO_TYPE_WRITE
] * scale
),
3861 format
, column_width
, cb
->cb_scripted
);
3862 print_one_stat((uint64_t)(vs
->vs_bytes
[ZIO_TYPE_READ
] * scale
),
3863 format
, column_width
, cb
->cb_scripted
);
3864 print_one_stat((uint64_t)(vs
->vs_bytes
[ZIO_TYPE_WRITE
] * scale
),
3865 format
, column_width
, cb
->cb_scripted
);
3868 static const char *class_name
[] = {
3869 VDEV_ALLOC_BIAS_DEDUP
,
3870 VDEV_ALLOC_BIAS_SPECIAL
,
3871 VDEV_ALLOC_CLASS_LOGS
3875 * Print out all the statistics for the given vdev. This can either be the
3876 * toplevel configuration, or called recursively. If 'name' is NULL, then this
3877 * is a verbose output, and we don't want to display the toplevel pool stats.
3879 * Returns the number of stat lines printed.
3882 print_vdev_stats(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*oldnv
,
3883 nvlist_t
*newnv
, iostat_cbdata_t
*cb
, int depth
)
3885 nvlist_t
**oldchild
, **newchild
;
3886 uint_t c
, children
, oldchildren
;
3887 vdev_stat_t
*oldvs
, *newvs
, *calcvs
;
3888 vdev_stat_t zerovs
= { 0 };
3895 calcvs
= safe_malloc(sizeof (*calcvs
));
3897 if (strcmp(name
, VDEV_TYPE_INDIRECT
) == 0)
3900 if (oldnv
!= NULL
) {
3901 verify(nvlist_lookup_uint64_array(oldnv
,
3902 ZPOOL_CONFIG_VDEV_STATS
, (uint64_t **)&oldvs
, &c
) == 0);
3907 /* Do we only want to see a specific vdev? */
3908 for (i
= 0; i
< cb
->cb_vdev_names_count
; i
++) {
3909 /* Yes we do. Is this the vdev? */
3910 if (strcmp(name
, cb
->cb_vdev_names
[i
]) == 0) {
3912 * This is our vdev. Since it is the only vdev we
3913 * will be displaying, make depth = 0 so that it
3914 * doesn't get indented.
3921 if (cb
->cb_vdev_names_count
&& (i
== cb
->cb_vdev_names_count
)) {
3922 /* Couldn't match the name */
3927 verify(nvlist_lookup_uint64_array(newnv
, ZPOOL_CONFIG_VDEV_STATS
,
3928 (uint64_t **)&newvs
, &c
) == 0);
3931 * Print the vdev name unless it's is a histogram. Histograms
3932 * display the vdev name in the header itself.
3934 if (!(cb
->cb_flags
& IOS_ANYHISTO_M
)) {
3935 if (cb
->cb_scripted
) {
3938 if (strlen(name
) + depth
> cb
->cb_namewidth
)
3939 (void) printf("%*s%s", depth
, "", name
);
3941 (void) printf("%*s%s%*s", depth
, "", name
,
3942 (int)(cb
->cb_namewidth
- strlen(name
) -
3947 /* Calculate our scaling factor */
3948 tdelta
= newvs
->vs_timestamp
- oldvs
->vs_timestamp
;
3949 if ((oldvs
->vs_timestamp
== 0) && (cb
->cb_flags
& IOS_ANYHISTO_M
)) {
3951 * If we specify printing histograms with no time interval, then
3952 * print the histogram numbers over the entire lifetime of the
3960 scale
= (double)NANOSEC
/ tdelta
;
3963 if (cb
->cb_flags
& IOS_DEFAULT_M
) {
3964 calc_default_iostats(oldvs
, newvs
, calcvs
);
3965 print_iostat_default(calcvs
, cb
, scale
);
3967 if (cb
->cb_flags
& IOS_LATENCY_M
)
3968 print_iostat_latency(cb
, oldnv
, newnv
, scale
);
3969 if (cb
->cb_flags
& IOS_QUEUES_M
)
3970 print_iostat_queues(cb
, oldnv
, newnv
, scale
);
3971 if (cb
->cb_flags
& IOS_ANYHISTO_M
) {
3973 print_iostat_histos(cb
, oldnv
, newnv
, scale
, name
);
3976 if (cb
->vcdl
!= NULL
) {
3978 if (nvlist_lookup_string(newnv
, ZPOOL_CONFIG_PATH
,
3981 zpool_print_cmd(cb
->vcdl
, zpool_get_name(zhp
), path
);
3985 if (!(cb
->cb_flags
& IOS_ANYHISTO_M
))
3994 if (!cb
->cb_verbose
)
3997 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_CHILDREN
,
3998 &newchild
, &children
) != 0)
4002 if (nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_CHILDREN
,
4003 &oldchild
, &oldchildren
) != 0)
4006 children
= MIN(oldchildren
, children
);
4010 * print normal top-level devices
4012 for (c
= 0; c
< children
; c
++) {
4013 uint64_t ishole
= B_FALSE
, islog
= B_FALSE
;
4015 (void) nvlist_lookup_uint64(newchild
[c
], ZPOOL_CONFIG_IS_HOLE
,
4018 (void) nvlist_lookup_uint64(newchild
[c
], ZPOOL_CONFIG_IS_LOG
,
4021 if (ishole
|| islog
)
4024 if (nvlist_exists(newchild
[c
], ZPOOL_CONFIG_ALLOCATION_BIAS
))
4027 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
4029 ret
+= print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
] : NULL
,
4030 newchild
[c
], cb
, depth
+ 2);
4035 * print all other top-level devices
4037 for (uint_t n
= 0; n
< 3; n
++) {
4038 boolean_t printed
= B_FALSE
;
4040 for (c
= 0; c
< children
; c
++) {
4041 uint64_t islog
= B_FALSE
;
4045 (void) nvlist_lookup_uint64(newchild
[c
],
4046 ZPOOL_CONFIG_IS_LOG
, &islog
);
4048 bias
= VDEV_ALLOC_CLASS_LOGS
;
4050 (void) nvlist_lookup_string(newchild
[c
],
4051 ZPOOL_CONFIG_ALLOCATION_BIAS
, &bias
);
4052 (void) nvlist_lookup_string(newchild
[c
],
4053 ZPOOL_CONFIG_TYPE
, &type
);
4055 if (bias
== NULL
|| strcmp(bias
, class_name
[n
]) != 0)
4057 if (!islog
&& strcmp(type
, VDEV_TYPE_INDIRECT
) == 0)
4061 if ((!(cb
->cb_flags
& IOS_ANYHISTO_M
)) &&
4062 !cb
->cb_scripted
&& !cb
->cb_vdev_names
) {
4063 print_iostat_dashes(cb
, 0,
4070 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
4072 ret
+= print_vdev_stats(zhp
, vname
, oldnv
?
4073 oldchild
[c
] : NULL
, newchild
[c
], cb
, depth
+ 2);
4079 * Include level 2 ARC devices in iostat output
4081 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_L2CACHE
,
4082 &newchild
, &children
) != 0)
4086 if (nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_L2CACHE
,
4087 &oldchild
, &oldchildren
) != 0)
4090 children
= MIN(oldchildren
, children
);
4094 if ((!(cb
->cb_flags
& IOS_ANYHISTO_M
)) && !cb
->cb_scripted
&&
4095 !cb
->cb_vdev_names
) {
4096 print_iostat_dashes(cb
, 0, "cache");
4100 for (c
= 0; c
< children
; c
++) {
4101 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
4103 ret
+= print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
]
4104 : NULL
, newchild
[c
], cb
, depth
+ 2);
4113 refresh_iostat(zpool_handle_t
*zhp
, void *data
)
4115 iostat_cbdata_t
*cb
= data
;
4119 * If the pool has disappeared, remove it from the list and continue.
4121 if (zpool_refresh_stats(zhp
, &missing
) != 0)
4125 pool_list_remove(cb
->cb_list
, zhp
);
4131 * Callback to print out the iostats for the given pool.
4134 print_iostat(zpool_handle_t
*zhp
, void *data
)
4136 iostat_cbdata_t
*cb
= data
;
4137 nvlist_t
*oldconfig
, *newconfig
;
4138 nvlist_t
*oldnvroot
, *newnvroot
;
4141 newconfig
= zpool_get_config(zhp
, &oldconfig
);
4143 if (cb
->cb_iteration
== 1)
4146 verify(nvlist_lookup_nvlist(newconfig
, ZPOOL_CONFIG_VDEV_TREE
,
4149 if (oldconfig
== NULL
)
4152 verify(nvlist_lookup_nvlist(oldconfig
, ZPOOL_CONFIG_VDEV_TREE
,
4155 ret
= print_vdev_stats(zhp
, zpool_get_name(zhp
), oldnvroot
, newnvroot
,
4157 if ((ret
!= 0) && !(cb
->cb_flags
& IOS_ANYHISTO_M
) &&
4158 !cb
->cb_scripted
&& cb
->cb_verbose
&& !cb
->cb_vdev_names_count
) {
4159 print_iostat_separator(cb
);
4160 if (cb
->vcdl
!= NULL
) {
4161 print_cmd_columns(cb
->vcdl
, 1);
4176 if (isatty(STDOUT_FILENO
)) {
4177 error
= ioctl(STDOUT_FILENO
, TIOCGWINSZ
, &ws
);
4179 columns
= ws
.ws_col
;
4188 get_namewidth(zpool_handle_t
*zhp
, void *data
)
4190 iostat_cbdata_t
*cb
= data
;
4191 nvlist_t
*config
, *nvroot
;
4194 if ((config
= zpool_get_config(zhp
, NULL
)) != NULL
) {
4195 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
4197 unsigned int poolname_len
= strlen(zpool_get_name(zhp
));
4198 if (!cb
->cb_verbose
)
4199 cb
->cb_namewidth
= MAX(poolname_len
, cb
->cb_namewidth
);
4201 cb
->cb_namewidth
= MAX(poolname_len
,
4202 max_width(zhp
, nvroot
, 0, cb
->cb_namewidth
,
4203 cb
->cb_name_flags
));
4206 * The width must be at least 10, but may be as large as the
4207 * column width - 42 so that we can still fit in one line.
4209 columns
= get_columns();
4211 if (cb
->cb_namewidth
< 10)
4212 cb
->cb_namewidth
= 10;
4213 if (cb
->cb_namewidth
> columns
- 42)
4214 cb
->cb_namewidth
= columns
- 42;
4220 * Parse the input string, get the 'interval' and 'count' value if there is one.
4223 get_interval_count(int *argcp
, char **argv
, float *iv
,
4227 unsigned long count
= 0;
4231 * Determine if the last argument is an integer or a pool name
4233 if (argc
> 0 && isnumber(argv
[argc
- 1])) {
4237 interval
= strtof(argv
[argc
- 1], &end
);
4239 if (*end
== '\0' && errno
== 0) {
4240 if (interval
== 0) {
4241 (void) fprintf(stderr
, gettext("interval "
4242 "cannot be zero\n"));
4246 * Ignore the last parameter
4251 * If this is not a valid number, just plow on. The
4252 * user will get a more informative error message later
4260 * If the last argument is also an integer, then we have both a count
4263 if (argc
> 0 && isnumber(argv
[argc
- 1])) {
4268 interval
= strtof(argv
[argc
- 1], &end
);
4270 if (*end
== '\0' && errno
== 0) {
4271 if (interval
== 0) {
4272 (void) fprintf(stderr
, gettext("interval "
4273 "cannot be zero\n"));
4278 * Ignore the last parameter
4292 get_timestamp_arg(char c
)
4295 timestamp_fmt
= UDATE
;
4297 timestamp_fmt
= DDATE
;
4303 * Return stat flags that are supported by all pools by both the module and
4304 * zpool iostat. "*data" should be initialized to all 0xFFs before running.
4305 * It will get ANDed down until only the flags that are supported on all pools
4309 get_stat_flags_cb(zpool_handle_t
*zhp
, void *data
)
4311 uint64_t *mask
= data
;
4312 nvlist_t
*config
, *nvroot
, *nvx
;
4316 config
= zpool_get_config(zhp
, NULL
);
4317 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
4320 /* Default stats are always supported, but for completeness.. */
4321 if (nvlist_exists(nvroot
, ZPOOL_CONFIG_VDEV_STATS
))
4322 flags
|= IOS_DEFAULT_M
;
4324 /* Get our extended stats nvlist from the main list */
4325 if (nvlist_lookup_nvlist(nvroot
, ZPOOL_CONFIG_VDEV_STATS_EX
,
4328 * No extended stats; they're probably running an older
4329 * module. No big deal, we support that too.
4334 /* For each extended stat, make sure all its nvpairs are supported */
4335 for (j
= 0; j
< ARRAY_SIZE(vsx_type_to_nvlist
); j
++) {
4336 if (!vsx_type_to_nvlist
[j
][0])
4339 /* Start off by assuming the flag is supported, then check */
4340 flags
|= (1ULL << j
);
4341 for (i
= 0; vsx_type_to_nvlist
[j
][i
]; i
++) {
4342 if (!nvlist_exists(nvx
, vsx_type_to_nvlist
[j
][i
])) {
4343 /* flag isn't supported */
4344 flags
= flags
& ~(1ULL << j
);
4350 *mask
= *mask
& flags
;
4355 * Return a bitmask of stats that are supported on all pools by both the module
4359 get_stat_flags(zpool_list_t
*list
)
4364 * get_stat_flags_cb() will lop off bits from "mask" until only the
4365 * flags that are supported on all pools remain.
4367 pool_list_iter(list
, B_FALSE
, get_stat_flags_cb
, &mask
);
4372 * Return 1 if cb_data->cb_vdev_names[0] is this vdev's name, 0 otherwise.
4375 is_vdev_cb(zpool_handle_t
*zhp
, nvlist_t
*nv
, void *cb_data
)
4377 iostat_cbdata_t
*cb
= cb_data
;
4381 name
= zpool_vdev_name(g_zfs
, zhp
, nv
, cb
->cb_name_flags
);
4383 if (strcmp(name
, cb
->cb_vdev_names
[0]) == 0)
4384 ret
= 1; /* match */
4391 * Returns 1 if cb_data->cb_vdev_names[0] is a vdev name, 0 otherwise.
4394 is_vdev(zpool_handle_t
*zhp
, void *cb_data
)
4396 return (for_each_vdev(zhp
, is_vdev_cb
, cb_data
));
4400 * Check if vdevs are in a pool
4402 * Return 1 if all argv[] strings are vdev names in pool "pool_name". Otherwise
4403 * return 0. If pool_name is NULL, then search all pools.
4406 are_vdevs_in_pool(int argc
, char **argv
, char *pool_name
,
4407 iostat_cbdata_t
*cb
)
4414 if ((argc
== 0) || !*argv
)
4420 /* Temporarily hijack cb_vdev_names for a second... */
4421 tmp_name
= cb
->cb_vdev_names
;
4423 /* Go though our list of prospective vdev names */
4424 for (i
= 0; i
< argc
; i
++) {
4425 cb
->cb_vdev_names
= argv
+ i
;
4427 /* Is this name a vdev in our pools? */
4428 ret
= for_each_pool(pool_count
, &pool_name
, B_TRUE
, NULL
,
4436 cb
->cb_vdev_names
= tmp_name
;
4442 is_pool_cb(zpool_handle_t
*zhp
, void *data
)
4445 if (strcmp(name
, zpool_get_name(zhp
)) == 0)
4452 * Do we have a pool named *name? If so, return 1, otherwise 0.
4457 return (for_each_pool(0, NULL
, B_TRUE
, NULL
, is_pool_cb
, name
));
4460 /* Are all our argv[] strings pool names? If so return 1, 0 otherwise. */
4462 are_all_pools(int argc
, char **argv
)
4464 if ((argc
== 0) || !*argv
)
4468 if (!is_pool(argv
[argc
]))
4475 * Helper function to print out vdev/pool names we can't resolve. Used for an
4479 error_list_unresolved_vdevs(int argc
, char **argv
, char *pool_name
,
4480 iostat_cbdata_t
*cb
)
4485 for (i
= 0; i
< argc
; i
++) {
4489 str
= gettext("pool");
4490 else if (are_vdevs_in_pool(1, &name
, pool_name
, cb
))
4491 str
= gettext("vdev in this pool");
4492 else if (are_vdevs_in_pool(1, &name
, NULL
, cb
))
4493 str
= gettext("vdev in another pool");
4495 str
= gettext("unknown");
4497 fprintf(stderr
, "\t%s (%s)\n", name
, str
);
4502 * Same as get_interval_count(), but with additional checks to not misinterpret
4503 * guids as interval/count values. Assumes VDEV_NAME_GUID is set in
4507 get_interval_count_filter_guids(int *argc
, char **argv
, float *interval
,
4508 unsigned long *count
, iostat_cbdata_t
*cb
)
4510 char **tmpargv
= argv
;
4511 int argc_for_interval
= 0;
4513 /* Is the last arg an interval value? Or a guid? */
4514 if (*argc
>= 1 && !are_vdevs_in_pool(1, &argv
[*argc
- 1], NULL
, cb
)) {
4516 * The last arg is not a guid, so it's probably an
4519 argc_for_interval
++;
4522 !are_vdevs_in_pool(1, &argv
[*argc
- 2], NULL
, cb
)) {
4524 * The 2nd to last arg is not a guid, so it's probably
4525 * an interval value.
4527 argc_for_interval
++;
4531 /* Point to our list of possible intervals */
4532 tmpargv
= &argv
[*argc
- argc_for_interval
];
4534 *argc
= *argc
- argc_for_interval
;
4535 get_interval_count(&argc_for_interval
, tmpargv
,
4540 * Floating point sleep(). Allows you to pass in a floating point value for
4546 struct timespec req
;
4547 req
.tv_sec
= floor(sec
);
4548 req
.tv_nsec
= (sec
- (float)req
.tv_sec
) * NANOSEC
;
4549 nanosleep(&req
, NULL
);
4553 * Run one of the zpool status/iostat -c scripts with the help (-h) option and
4556 * name: Short name of the script ('iostat').
4557 * path: Full path to the script ('/usr/local/etc/zfs/zpool.d/iostat');
4560 print_zpool_script_help(char *name
, char *path
)
4562 char *argv
[] = {path
, "-h", NULL
};
4563 char **lines
= NULL
;
4567 rc
= libzfs_run_process_get_stdout_nopath(path
, argv
, NULL
, &lines
,
4569 if (rc
!= 0 || lines
== NULL
|| lines_cnt
<= 0) {
4571 libzfs_free_str_array(lines
, lines_cnt
);
4575 for (int i
= 0; i
< lines_cnt
; i
++)
4576 if (!is_blank_str(lines
[i
]))
4577 printf(" %-14s %s\n", name
, lines
[i
]);
4579 libzfs_free_str_array(lines
, lines_cnt
);
4583 * Go though the zpool status/iostat -c scripts in the user's path, run their
4584 * help option (-h), and print out the results.
4587 print_zpool_dir_scripts(char *dirpath
)
4591 char fullpath
[MAXPATHLEN
];
4592 struct stat dir_stat
;
4594 if ((dir
= opendir(dirpath
)) != NULL
) {
4595 /* print all the files and directories within directory */
4596 while ((ent
= readdir(dir
)) != NULL
) {
4597 sprintf(fullpath
, "%s/%s", dirpath
, ent
->d_name
);
4599 /* Print the scripts */
4600 if (stat(fullpath
, &dir_stat
) == 0)
4601 if (dir_stat
.st_mode
& S_IXUSR
&&
4602 S_ISREG(dir_stat
.st_mode
))
4603 print_zpool_script_help(ent
->d_name
,
4611 * Print out help text for all zpool status/iostat -c scripts.
4614 print_zpool_script_list(char *subcommand
)
4618 printf(gettext("Available 'zpool %s -c' commands:\n"), subcommand
);
4620 sp
= zpool_get_cmd_search_path();
4624 dir
= strtok(sp
, ":");
4625 while (dir
!= NULL
) {
4626 print_zpool_dir_scripts(dir
);
4627 dir
= strtok(NULL
, ":");
4634 * zpool iostat [[-c [script1,script2,...]] [-lq]|[-rw]] [-ghHLpPvy] [-n name]
4635 * [-T d|u] [[ pool ...]|[pool vdev ...]|[vdev ...]]
4636 * [interval [count]]
4638 * -c CMD For each vdev, run command CMD
4639 * -g Display guid for individual vdev name.
4640 * -L Follow links when resolving vdev path name.
4641 * -P Display full path for vdev name.
4642 * -v Display statistics for individual vdevs
4644 * -p Display values in parsable (exact) format.
4645 * -H Scripted mode. Don't display headers, and separate properties
4647 * -l Display average latency
4648 * -q Display queue depths
4649 * -w Display latency histograms
4650 * -r Display request size histogram
4651 * -T Display a timestamp in date(1) or Unix format
4653 * This command can be tricky because we want to be able to deal with pool
4654 * creation/destruction as well as vdev configuration changes. The bulk of this
4655 * processing is handled by the pool_list_* routines in zpool_iter.c. We rely
4656 * on pool_list_update() to detect the addition of new pools. Configuration
4657 * changes are all handled within libzfs.
4660 zpool_do_iostat(int argc
, char **argv
)
4666 unsigned long count
= 0;
4668 boolean_t verbose
= B_FALSE
;
4669 boolean_t latency
= B_FALSE
, l_histo
= B_FALSE
, rq_histo
= B_FALSE
;
4670 boolean_t queues
= B_FALSE
, parsable
= B_FALSE
, scripted
= B_FALSE
;
4671 boolean_t omit_since_boot
= B_FALSE
;
4672 boolean_t guid
= B_FALSE
;
4673 boolean_t follow_links
= B_FALSE
;
4674 boolean_t full_name
= B_FALSE
;
4675 iostat_cbdata_t cb
= { 0 };
4678 /* Used for printing error message */
4679 const char flag_to_arg
[] = {[IOS_LATENCY
] = 'l', [IOS_QUEUES
] = 'q',
4680 [IOS_L_HISTO
] = 'w', [IOS_RQ_HISTO
] = 'r'};
4682 uint64_t unsupported_flags
;
4685 while ((c
= getopt(argc
, argv
, "c:gLPT:vyhplqrwH")) != -1) {
4690 gettext("Can't set -c flag twice\n"));
4694 if (getenv("ZPOOL_SCRIPTS_ENABLED") != NULL
&&
4695 !libzfs_envvar_is_set("ZPOOL_SCRIPTS_ENABLED")) {
4696 fprintf(stderr
, gettext(
4697 "Can't run -c, disabled by "
4698 "ZPOOL_SCRIPTS_ENABLED.\n"));
4702 if ((getuid() <= 0 || geteuid() <= 0) &&
4703 !libzfs_envvar_is_set("ZPOOL_SCRIPTS_AS_ROOT")) {
4704 fprintf(stderr
, gettext(
4705 "Can't run -c with root privileges "
4706 "unless ZPOOL_SCRIPTS_AS_ROOT is set.\n"));
4716 follow_links
= B_TRUE
;
4722 get_timestamp_arg(*optarg
);
4746 omit_since_boot
= B_TRUE
;
4752 if (optopt
== 'c') {
4753 print_zpool_script_list("iostat");
4757 gettext("invalid option '%c'\n"), optopt
);
4766 cb
.cb_literal
= parsable
;
4767 cb
.cb_scripted
= scripted
;
4770 cb
.cb_name_flags
|= VDEV_NAME_GUID
;
4772 cb
.cb_name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
4774 cb
.cb_name_flags
|= VDEV_NAME_PATH
;
4775 cb
.cb_iteration
= 0;
4776 cb
.cb_namewidth
= 0;
4777 cb
.cb_verbose
= verbose
;
4779 /* Get our interval and count values (if any) */
4781 get_interval_count_filter_guids(&argc
, argv
, &interval
,
4784 get_interval_count(&argc
, argv
, &interval
, &count
);
4788 /* No args, so just print the defaults. */
4789 } else if (are_all_pools(argc
, argv
)) {
4790 /* All the args are pool names */
4791 } else if (are_vdevs_in_pool(argc
, argv
, NULL
, &cb
)) {
4792 /* All the args are vdevs */
4793 cb
.cb_vdev_names
= argv
;
4794 cb
.cb_vdev_names_count
= argc
;
4795 argc
= 0; /* No pools to process */
4796 } else if (are_all_pools(1, argv
)) {
4797 /* The first arg is a pool name */
4798 if (are_vdevs_in_pool(argc
- 1, argv
+ 1, argv
[0], &cb
)) {
4799 /* ...and the rest are vdev names */
4800 cb
.cb_vdev_names
= argv
+ 1;
4801 cb
.cb_vdev_names_count
= argc
- 1;
4802 argc
= 1; /* One pool to process */
4804 fprintf(stderr
, gettext("Expected either a list of "));
4805 fprintf(stderr
, gettext("pools, or list of vdevs in"));
4806 fprintf(stderr
, " \"%s\", ", argv
[0]);
4807 fprintf(stderr
, gettext("but got:\n"));
4808 error_list_unresolved_vdevs(argc
- 1, argv
+ 1,
4810 fprintf(stderr
, "\n");
4816 * The args don't make sense. The first arg isn't a pool name,
4817 * nor are all the args vdevs.
4819 fprintf(stderr
, gettext("Unable to parse pools/vdevs list.\n"));
4820 fprintf(stderr
, "\n");
4824 if (cb
.cb_vdev_names_count
!= 0) {
4826 * If user specified vdevs, it implies verbose.
4828 cb
.cb_verbose
= B_TRUE
;
4832 * Construct the list of all interesting pools.
4835 if ((list
= pool_list_get(argc
, argv
, NULL
, &ret
)) == NULL
)
4838 if (pool_list_count(list
) == 0 && argc
!= 0) {
4839 pool_list_free(list
);
4843 if (pool_list_count(list
) == 0 && interval
== 0) {
4844 pool_list_free(list
);
4845 (void) fprintf(stderr
, gettext("no pools available\n"));
4849 if ((l_histo
|| rq_histo
) && (cmd
!= NULL
|| latency
|| queues
)) {
4850 pool_list_free(list
);
4851 (void) fprintf(stderr
,
4852 gettext("[-r|-w] isn't allowed with [-c|-l|-q]\n"));
4857 if (l_histo
&& rq_histo
) {
4858 pool_list_free(list
);
4859 (void) fprintf(stderr
,
4860 gettext("Only one of [-r|-w] can be passed at a time\n"));
4866 * Enter the main iostat loop.
4872 * Histograms tables look out of place when you try to display
4873 * them with the other stats, so make a rule that you can only
4874 * print histograms by themselves.
4876 cb
.cb_flags
= IOS_L_HISTO_M
;
4877 } else if (rq_histo
) {
4878 cb
.cb_flags
= IOS_RQ_HISTO_M
;
4880 cb
.cb_flags
= IOS_DEFAULT_M
;
4882 cb
.cb_flags
|= IOS_LATENCY_M
;
4884 cb
.cb_flags
|= IOS_QUEUES_M
;
4888 * See if the module supports all the stats we want to display.
4890 unsupported_flags
= cb
.cb_flags
& ~get_stat_flags(list
);
4891 if (unsupported_flags
) {
4895 gettext("The loaded zfs module doesn't support:"));
4897 /* for each bit set in unsupported_flags */
4898 for (f
= unsupported_flags
; f
; f
&= ~(1ULL << idx
)) {
4899 idx
= lowbit64(f
) - 1;
4900 fprintf(stderr
, " -%c", flag_to_arg
[idx
]);
4903 fprintf(stderr
, ". Try running a newer module.\n");
4904 pool_list_free(list
);
4910 if ((npools
= pool_list_count(list
)) == 0)
4911 (void) fprintf(stderr
, gettext("no pools available\n"));
4914 * If this is the first iteration and -y was supplied
4915 * we skip any printing.
4917 boolean_t skip
= (omit_since_boot
&&
4918 cb
.cb_iteration
== 0);
4921 * Refresh all statistics. This is done as an
4922 * explicit step before calculating the maximum name
4923 * width, so that any * configuration changes are
4924 * properly accounted for.
4926 (void) pool_list_iter(list
, B_FALSE
, refresh_iostat
,
4930 * Iterate over all pools to determine the maximum width
4931 * for the pool / device name column across all pools.
4933 cb
.cb_namewidth
= 0;
4934 (void) pool_list_iter(list
, B_FALSE
, get_namewidth
,
4937 if (timestamp_fmt
!= NODATE
)
4938 print_timestamp(timestamp_fmt
);
4940 if (cmd
!= NULL
&& cb
.cb_verbose
&&
4941 !(cb
.cb_flags
& IOS_ANYHISTO_M
)) {
4942 cb
.vcdl
= all_pools_for_each_vdev_run(argc
,
4943 argv
, cmd
, g_zfs
, cb
.cb_vdev_names
,
4944 cb
.cb_vdev_names_count
, cb
.cb_name_flags
);
4950 * If it's the first time and we're not skipping it,
4951 * or either skip or verbose mode, print the header.
4953 * The histogram code explicitly prints its header on
4954 * every vdev, so skip this for histograms.
4956 if (((++cb
.cb_iteration
== 1 && !skip
) ||
4957 (skip
!= verbose
)) &&
4958 (!(cb
.cb_flags
& IOS_ANYHISTO_M
)) &&
4960 print_iostat_header(&cb
);
4963 (void) fsleep(interval
);
4968 pool_list_iter(list
, B_FALSE
, print_iostat
, &cb
);
4971 * If there's more than one pool, and we're not in
4972 * verbose mode (which prints a separator for us),
4973 * then print a separator.
4975 * In addition, if we're printing specific vdevs then
4976 * we also want an ending separator.
4978 if (((npools
> 1 && !verbose
&&
4979 !(cb
.cb_flags
& IOS_ANYHISTO_M
)) ||
4980 (!(cb
.cb_flags
& IOS_ANYHISTO_M
) &&
4981 cb
.cb_vdev_names_count
)) &&
4983 print_iostat_separator(&cb
);
4984 if (cb
.vcdl
!= NULL
)
4985 print_cmd_columns(cb
.vcdl
, 1);
4989 if (cb
.vcdl
!= NULL
)
4990 free_vdev_cmd_data_list(cb
.vcdl
);
4995 * Flush the output so that redirection to a file isn't buffered
4998 (void) fflush(stdout
);
5003 if (count
!= 0 && --count
== 0)
5006 (void) fsleep(interval
);
5009 pool_list_free(list
);
5014 typedef struct list_cbdata
{
5015 boolean_t cb_verbose
;
5018 boolean_t cb_scripted
;
5019 zprop_list_t
*cb_proplist
;
5020 boolean_t cb_literal
;
5025 * Given a list of columns to display, output appropriate headers for each one.
5028 print_header(list_cbdata_t
*cb
)
5030 zprop_list_t
*pl
= cb
->cb_proplist
;
5031 char headerbuf
[ZPOOL_MAXPROPLEN
];
5033 boolean_t first
= B_TRUE
;
5034 boolean_t right_justify
;
5037 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
5038 width
= pl
->pl_width
;
5039 if (first
&& cb
->cb_verbose
) {
5041 * Reset the width to accommodate the verbose listing
5044 width
= cb
->cb_namewidth
;
5052 right_justify
= B_FALSE
;
5053 if (pl
->pl_prop
!= ZPROP_INVAL
) {
5054 header
= zpool_prop_column_name(pl
->pl_prop
);
5055 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
5059 for (i
= 0; pl
->pl_user_prop
[i
] != '\0'; i
++)
5060 headerbuf
[i
] = toupper(pl
->pl_user_prop
[i
]);
5061 headerbuf
[i
] = '\0';
5065 if (pl
->pl_next
== NULL
&& !right_justify
)
5066 (void) printf("%s", header
);
5067 else if (right_justify
)
5068 (void) printf("%*s", (int)width
, header
);
5070 (void) printf("%-*s", (int)width
, header
);
5073 (void) printf("\n");
5077 * Given a pool and a list of properties, print out all the properties according
5078 * to the described layout. Used by zpool_do_list().
5081 print_pool(zpool_handle_t
*zhp
, list_cbdata_t
*cb
)
5083 zprop_list_t
*pl
= cb
->cb_proplist
;
5084 boolean_t first
= B_TRUE
;
5085 char property
[ZPOOL_MAXPROPLEN
];
5087 boolean_t right_justify
;
5090 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
5092 width
= pl
->pl_width
;
5093 if (first
&& cb
->cb_verbose
) {
5095 * Reset the width to accommodate the verbose listing
5098 width
= cb
->cb_namewidth
;
5102 if (cb
->cb_scripted
)
5103 (void) printf("\t");
5110 right_justify
= B_FALSE
;
5111 if (pl
->pl_prop
!= ZPROP_INVAL
) {
5112 if (zpool_get_prop(zhp
, pl
->pl_prop
, property
,
5113 sizeof (property
), NULL
, cb
->cb_literal
) != 0)
5118 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
5119 } else if ((zpool_prop_feature(pl
->pl_user_prop
) ||
5120 zpool_prop_unsupported(pl
->pl_user_prop
)) &&
5121 zpool_prop_get_feature(zhp
, pl
->pl_user_prop
, property
,
5122 sizeof (property
)) == 0) {
5130 * If this is being called in scripted mode, or if this is the
5131 * last column and it is left-justified, don't include a width
5134 if (cb
->cb_scripted
|| (pl
->pl_next
== NULL
&& !right_justify
))
5135 (void) printf("%s", propstr
);
5136 else if (right_justify
)
5137 (void) printf("%*s", (int)width
, propstr
);
5139 (void) printf("%-*s", (int)width
, propstr
);
5142 (void) printf("\n");
5146 print_one_column(zpool_prop_t prop
, uint64_t value
, boolean_t scripted
,
5147 boolean_t valid
, enum zfs_nicenum_format format
)
5151 size_t width
= zprop_width(prop
, &fixed
, ZFS_TYPE_POOL
);
5154 case ZPOOL_PROP_EXPANDSZ
:
5155 case ZPOOL_PROP_CHECKPOINT
:
5157 (void) strlcpy(propval
, "-", sizeof (propval
));
5159 zfs_nicenum_format(value
, propval
, sizeof (propval
),
5162 case ZPOOL_PROP_FRAGMENTATION
:
5163 if (value
== ZFS_FRAG_INVALID
) {
5164 (void) strlcpy(propval
, "-", sizeof (propval
));
5165 } else if (format
== ZFS_NICENUM_RAW
) {
5166 (void) snprintf(propval
, sizeof (propval
), "%llu",
5167 (unsigned long long)value
);
5169 (void) snprintf(propval
, sizeof (propval
), "%llu%%",
5170 (unsigned long long)value
);
5173 case ZPOOL_PROP_CAPACITY
:
5174 /* capacity value is in parts-per-10,000 (aka permyriad) */
5175 if (format
== ZFS_NICENUM_RAW
)
5176 (void) snprintf(propval
, sizeof (propval
), "%llu",
5177 (unsigned long long)value
/ 100);
5179 (void) snprintf(propval
, sizeof (propval
),
5180 value
< 1000 ? "%1.2f%%" : value
< 10000 ?
5181 "%2.1f%%" : "%3.0f%%", value
/ 100.0);
5184 zfs_nicenum_format(value
, propval
, sizeof (propval
), format
);
5188 (void) strlcpy(propval
, "-", sizeof (propval
));
5191 (void) printf("\t%s", propval
);
5193 (void) printf(" %*s", (int)width
, propval
);
5197 * print static default line per vdev
5198 * not compatible with '-o' <proplist> option
5201 print_list_stats(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
,
5202 list_cbdata_t
*cb
, int depth
)
5208 boolean_t scripted
= cb
->cb_scripted
;
5209 uint64_t islog
= B_FALSE
;
5210 char *dashes
= "%-*s - - - - - -\n";
5212 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
5213 (uint64_t **)&vs
, &c
) == 0);
5216 boolean_t toplevel
= (vs
->vs_space
!= 0);
5218 enum zfs_nicenum_format format
;
5221 format
= ZFS_NICENUM_RAW
;
5223 format
= ZFS_NICENUM_1024
;
5225 if (strcmp(name
, VDEV_TYPE_INDIRECT
) == 0)
5229 (void) printf("\t%s", name
);
5230 else if (strlen(name
) + depth
> cb
->cb_namewidth
)
5231 (void) printf("%*s%s", depth
, "", name
);
5233 (void) printf("%*s%s%*s", depth
, "", name
,
5234 (int)(cb
->cb_namewidth
- strlen(name
) - depth
), "");
5237 * Print the properties for the individual vdevs. Some
5238 * properties are only applicable to toplevel vdevs. The
5239 * 'toplevel' boolean value is passed to the print_one_column()
5240 * to indicate that the value is valid.
5242 print_one_column(ZPOOL_PROP_SIZE
, vs
->vs_space
, scripted
,
5244 print_one_column(ZPOOL_PROP_ALLOCATED
, vs
->vs_alloc
, scripted
,
5246 print_one_column(ZPOOL_PROP_FREE
, vs
->vs_space
- vs
->vs_alloc
,
5247 scripted
, toplevel
, format
);
5248 print_one_column(ZPOOL_PROP_CHECKPOINT
,
5249 vs
->vs_checkpoint_space
, scripted
, toplevel
, format
);
5250 print_one_column(ZPOOL_PROP_EXPANDSZ
, vs
->vs_esize
, scripted
,
5252 print_one_column(ZPOOL_PROP_FRAGMENTATION
,
5253 vs
->vs_fragmentation
, scripted
,
5254 (vs
->vs_fragmentation
!= ZFS_FRAG_INVALID
&& toplevel
),
5256 cap
= (vs
->vs_space
== 0) ? 0 :
5257 (vs
->vs_alloc
* 10000 / vs
->vs_space
);
5258 print_one_column(ZPOOL_PROP_CAPACITY
, cap
, scripted
, toplevel
,
5260 (void) printf("\n");
5263 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
5264 &child
, &children
) != 0)
5267 /* list the normal vdevs first */
5268 for (c
= 0; c
< children
; c
++) {
5269 uint64_t ishole
= B_FALSE
;
5271 if (nvlist_lookup_uint64(child
[c
],
5272 ZPOOL_CONFIG_IS_HOLE
, &ishole
) == 0 && ishole
)
5275 if (nvlist_lookup_uint64(child
[c
],
5276 ZPOOL_CONFIG_IS_LOG
, &islog
) == 0 && islog
)
5279 if (nvlist_exists(child
[c
], ZPOOL_CONFIG_ALLOCATION_BIAS
))
5282 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
5284 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
5288 /* list the classes: 'logs', 'dedup', and 'special' */
5289 for (uint_t n
= 0; n
< 3; n
++) {
5290 boolean_t printed
= B_FALSE
;
5292 for (c
= 0; c
< children
; c
++) {
5296 if (nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
5297 &islog
) == 0 && islog
) {
5298 bias
= VDEV_ALLOC_CLASS_LOGS
;
5300 (void) nvlist_lookup_string(child
[c
],
5301 ZPOOL_CONFIG_ALLOCATION_BIAS
, &bias
);
5302 (void) nvlist_lookup_string(child
[c
],
5303 ZPOOL_CONFIG_TYPE
, &type
);
5305 if (bias
== NULL
|| strcmp(bias
, class_name
[n
]) != 0)
5307 if (!islog
&& strcmp(type
, VDEV_TYPE_INDIRECT
) == 0)
5311 /* LINTED E_SEC_PRINTF_VAR_FMT */
5312 (void) printf(dashes
, cb
->cb_namewidth
,
5316 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
5318 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
5323 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
5324 &child
, &children
) == 0 && children
> 0) {
5325 /* LINTED E_SEC_PRINTF_VAR_FMT */
5326 (void) printf(dashes
, cb
->cb_namewidth
, "cache");
5327 for (c
= 0; c
< children
; c
++) {
5328 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
5330 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
5335 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
, &child
,
5336 &children
) == 0 && children
> 0) {
5337 /* LINTED E_SEC_PRINTF_VAR_FMT */
5338 (void) printf(dashes
, cb
->cb_namewidth
, "spare");
5339 for (c
= 0; c
< children
; c
++) {
5340 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
5342 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
5349 * Generic callback function to list a pool.
5352 list_callback(zpool_handle_t
*zhp
, void *data
)
5354 list_cbdata_t
*cbp
= data
;
5358 config
= zpool_get_config(zhp
, NULL
);
5360 if (cbp
->cb_verbose
) {
5361 config
= zpool_get_config(zhp
, NULL
);
5363 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
5367 if (cbp
->cb_verbose
)
5368 cbp
->cb_namewidth
= max_width(zhp
, nvroot
, 0, 0,
5369 cbp
->cb_name_flags
);
5371 print_pool(zhp
, cbp
);
5373 if (cbp
->cb_verbose
)
5374 print_list_stats(zhp
, NULL
, nvroot
, cbp
, 0);
5380 * zpool list [-gHLpP] [-o prop[,prop]*] [-T d|u] [pool] ... [interval [count]]
5382 * -g Display guid for individual vdev name.
5383 * -H Scripted mode. Don't display headers, and separate properties
5385 * -L Follow links when resolving vdev path name.
5386 * -o List of properties to display. Defaults to
5387 * "name,size,allocated,free,expandsize,fragmentation,capacity,"
5388 * "dedupratio,health,altroot"
5389 * -p Display values in parsable (exact) format.
5390 * -P Display full path for vdev name.
5391 * -T Display a timestamp in date(1) or Unix format
5393 * List all pools in the system, whether or not they're healthy. Output space
5394 * statistics for each one, as well as health status summary.
5397 zpool_do_list(int argc
, char **argv
)
5401 list_cbdata_t cb
= { 0 };
5402 static char default_props
[] =
5403 "name,size,allocated,free,checkpoint,expandsize,fragmentation,"
5404 "capacity,dedupratio,health,altroot";
5405 char *props
= default_props
;
5407 unsigned long count
= 0;
5409 boolean_t first
= B_TRUE
;
5412 while ((c
= getopt(argc
, argv
, ":gHLo:pPT:v")) != -1) {
5415 cb
.cb_name_flags
|= VDEV_NAME_GUID
;
5418 cb
.cb_scripted
= B_TRUE
;
5421 cb
.cb_name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
5427 cb
.cb_name_flags
|= VDEV_NAME_PATH
;
5430 cb
.cb_literal
= B_TRUE
;
5433 get_timestamp_arg(*optarg
);
5436 cb
.cb_verbose
= B_TRUE
;
5437 cb
.cb_namewidth
= 8; /* 8 until precalc is avail */
5440 (void) fprintf(stderr
, gettext("missing argument for "
5441 "'%c' option\n"), optopt
);
5445 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5454 get_interval_count(&argc
, argv
, &interval
, &count
);
5456 if (zprop_get_list(g_zfs
, props
, &cb
.cb_proplist
, ZFS_TYPE_POOL
) != 0)
5460 if ((list
= pool_list_get(argc
, argv
, &cb
.cb_proplist
,
5464 if (pool_list_count(list
) == 0)
5467 if (timestamp_fmt
!= NODATE
)
5468 print_timestamp(timestamp_fmt
);
5470 if (!cb
.cb_scripted
&& (first
|| cb
.cb_verbose
)) {
5474 ret
= pool_list_iter(list
, B_TRUE
, list_callback
, &cb
);
5479 if (count
!= 0 && --count
== 0)
5482 pool_list_free(list
);
5483 (void) fsleep(interval
);
5486 if (argc
== 0 && !cb
.cb_scripted
&& pool_list_count(list
) == 0) {
5487 (void) printf(gettext("no pools available\n"));
5491 pool_list_free(list
);
5492 zprop_free_list(cb
.cb_proplist
);
5497 zpool_do_attach_or_replace(int argc
, char **argv
, int replacing
)
5499 boolean_t force
= B_FALSE
;
5502 char *poolname
, *old_disk
, *new_disk
;
5503 zpool_handle_t
*zhp
;
5504 nvlist_t
*props
= NULL
;
5509 while ((c
= getopt(argc
, argv
, "fo:")) != -1) {
5515 if ((propval
= strchr(optarg
, '=')) == NULL
) {
5516 (void) fprintf(stderr
, gettext("missing "
5517 "'=' for -o option\n"));
5523 if ((strcmp(optarg
, ZPOOL_CONFIG_ASHIFT
) != 0) ||
5524 (add_prop_list(optarg
, propval
, &props
, B_TRUE
)))
5528 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5537 /* get pool name and check number of arguments */
5539 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
5546 (void) fprintf(stderr
,
5547 gettext("missing <device> specification\n"));
5555 (void) fprintf(stderr
,
5556 gettext("missing <new_device> specification\n"));
5559 new_disk
= old_disk
;
5569 (void) fprintf(stderr
, gettext("too many arguments\n"));
5573 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
) {
5578 if (zpool_get_config(zhp
, NULL
) == NULL
) {
5579 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
5586 /* unless manually specified use "ashift" pool property (if set) */
5587 if (!nvlist_exists(props
, ZPOOL_CONFIG_ASHIFT
)) {
5590 char strval
[ZPOOL_MAXPROPLEN
];
5592 intval
= zpool_get_prop_int(zhp
, ZPOOL_PROP_ASHIFT
, &src
);
5593 if (src
!= ZPROP_SRC_DEFAULT
) {
5594 (void) sprintf(strval
, "%" PRId32
, intval
);
5595 verify(add_prop_list(ZPOOL_CONFIG_ASHIFT
, strval
,
5596 &props
, B_TRUE
) == 0);
5600 nvroot
= make_root_vdev(zhp
, props
, force
, B_FALSE
, replacing
, B_FALSE
,
5602 if (nvroot
== NULL
) {
5608 ret
= zpool_vdev_attach(zhp
, old_disk
, new_disk
, nvroot
, replacing
);
5611 nvlist_free(nvroot
);
5618 * zpool replace [-f] <pool> <device> <new_device>
5620 * -f Force attach, even if <new_device> appears to be in use.
5622 * Replace <device> with <new_device>.
5626 zpool_do_replace(int argc
, char **argv
)
5628 return (zpool_do_attach_or_replace(argc
, argv
, B_TRUE
));
5632 * zpool attach [-f] [-o property=value] <pool> <device> <new_device>
5634 * -f Force attach, even if <new_device> appears to be in use.
5635 * -o Set property=value.
5637 * Attach <new_device> to the mirror containing <device>. If <device> is not
5638 * part of a mirror, then <device> will be transformed into a mirror of
5639 * <device> and <new_device>. In either case, <new_device> will begin life
5640 * with a DTL of [0, now], and will immediately begin to resilver itself.
5643 zpool_do_attach(int argc
, char **argv
)
5645 return (zpool_do_attach_or_replace(argc
, argv
, B_FALSE
));
5649 * zpool detach [-f] <pool> <device>
5651 * -f Force detach of <device>, even if DTLs argue against it
5652 * (not supported yet)
5654 * Detach a device from a mirror. The operation will be refused if <device>
5655 * is the last device in the mirror, or if the DTLs indicate that this device
5656 * has the only valid copy of some data.
5660 zpool_do_detach(int argc
, char **argv
)
5663 char *poolname
, *path
;
5664 zpool_handle_t
*zhp
;
5668 while ((c
= getopt(argc
, argv
, "f")) != -1) {
5672 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5681 /* get pool name and check number of arguments */
5683 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
5688 (void) fprintf(stderr
,
5689 gettext("missing <device> specification\n"));
5696 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
5699 ret
= zpool_vdev_detach(zhp
, path
);
5707 * zpool split [-gLnP] [-o prop=val] ...
5709 * [-R altroot] <pool> <newpool> [<device> ...]
5711 * -g Display guid for individual vdev name.
5712 * -L Follow links when resolving vdev path name.
5713 * -n Do not split the pool, but display the resulting layout if
5714 * it were to be split.
5715 * -o Set property=value, or set mount options.
5716 * -P Display full path for vdev name.
5717 * -R Mount the split-off pool under an alternate root.
5718 * -l Load encryption keys while importing.
5720 * Splits the named pool and gives it the new pool name. Devices to be split
5721 * off may be listed, provided that no more than one device is specified
5722 * per top-level vdev mirror. The newly split pool is left in an exported
5723 * state unless -R is specified.
5725 * Restrictions: the top-level of the pool pool must only be made up of
5726 * mirrors; all devices in the pool must be healthy; no device may be
5727 * undergoing a resilvering operation.
5730 zpool_do_split(int argc
, char **argv
)
5732 char *srcpool
, *newpool
, *propval
;
5733 char *mntopts
= NULL
;
5736 boolean_t loadkeys
= B_FALSE
;
5737 zpool_handle_t
*zhp
;
5738 nvlist_t
*config
, *props
= NULL
;
5740 flags
.dryrun
= B_FALSE
;
5741 flags
.import
= B_FALSE
;
5742 flags
.name_flags
= 0;
5745 while ((c
= getopt(argc
, argv
, ":gLR:lno:P")) != -1) {
5748 flags
.name_flags
|= VDEV_NAME_GUID
;
5751 flags
.name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
5754 flags
.import
= B_TRUE
;
5756 zpool_prop_to_name(ZPOOL_PROP_ALTROOT
), optarg
,
5757 &props
, B_TRUE
) != 0) {
5766 flags
.dryrun
= B_TRUE
;
5769 if ((propval
= strchr(optarg
, '=')) != NULL
) {
5772 if (add_prop_list(optarg
, propval
,
5773 &props
, B_TRUE
) != 0) {
5782 flags
.name_flags
|= VDEV_NAME_PATH
;
5785 (void) fprintf(stderr
, gettext("missing argument for "
5786 "'%c' option\n"), optopt
);
5790 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5797 if (!flags
.import
&& mntopts
!= NULL
) {
5798 (void) fprintf(stderr
, gettext("setting mntopts is only "
5799 "valid when importing the pool\n"));
5803 if (!flags
.import
&& loadkeys
) {
5804 (void) fprintf(stderr
, gettext("loading keys is only "
5805 "valid when importing the pool\n"));
5813 (void) fprintf(stderr
, gettext("Missing pool name\n"));
5817 (void) fprintf(stderr
, gettext("Missing new pool name\n"));
5827 if ((zhp
= zpool_open(g_zfs
, srcpool
)) == NULL
) {
5832 config
= split_mirror_vdev(zhp
, newpool
, props
, flags
, argc
, argv
);
5833 if (config
== NULL
) {
5837 (void) printf(gettext("would create '%s' with the "
5838 "following layout:\n\n"), newpool
);
5839 print_vdev_tree(NULL
, newpool
, config
, 0, "",
5846 if (ret
!= 0 || flags
.dryrun
|| !flags
.import
) {
5847 nvlist_free(config
);
5853 * The split was successful. Now we need to open the new
5854 * pool and import it.
5856 if ((zhp
= zpool_open_canfail(g_zfs
, newpool
)) == NULL
) {
5857 nvlist_free(config
);
5863 ret
= zfs_crypto_attempt_load_keys(g_zfs
, newpool
);
5868 if (zpool_get_state(zhp
) != POOL_STATE_UNAVAIL
&&
5869 zpool_enable_datasets(zhp
, mntopts
, 0) != 0) {
5871 (void) fprintf(stderr
, gettext("Split was successful, but "
5872 "the datasets could not all be mounted\n"));
5873 (void) fprintf(stderr
, gettext("Try doing '%s' with a "
5874 "different altroot\n"), "zpool import");
5877 nvlist_free(config
);
5886 * zpool online <pool> <device> ...
5889 zpool_do_online(int argc
, char **argv
)
5893 zpool_handle_t
*zhp
;
5895 vdev_state_t newstate
;
5899 while ((c
= getopt(argc
, argv
, "et")) != -1) {
5902 flags
|= ZFS_ONLINE_EXPAND
;
5906 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5915 /* get pool name and check number of arguments */
5917 (void) fprintf(stderr
, gettext("missing pool name\n"));
5921 (void) fprintf(stderr
, gettext("missing device name\n"));
5927 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
5930 for (i
= 1; i
< argc
; i
++) {
5931 if (zpool_vdev_online(zhp
, argv
[i
], flags
, &newstate
) == 0) {
5932 if (newstate
!= VDEV_STATE_HEALTHY
) {
5933 (void) printf(gettext("warning: device '%s' "
5934 "onlined, but remains in faulted state\n"),
5936 if (newstate
== VDEV_STATE_FAULTED
)
5937 (void) printf(gettext("use 'zpool "
5938 "clear' to restore a faulted "
5941 (void) printf(gettext("use 'zpool "
5942 "replace' to replace devices "
5943 "that are no longer present\n"));
5956 * zpool offline [-ft] <pool> <device> ...
5958 * -f Force the device into a faulted state.
5960 * -t Only take the device off-line temporarily. The offline/faulted
5961 * state will not be persistent across reboots.
5965 zpool_do_offline(int argc
, char **argv
)
5969 zpool_handle_t
*zhp
;
5971 boolean_t istmp
= B_FALSE
;
5972 boolean_t fault
= B_FALSE
;
5975 while ((c
= getopt(argc
, argv
, "ft")) != -1) {
5984 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5993 /* get pool name and check number of arguments */
5995 (void) fprintf(stderr
, gettext("missing pool name\n"));
5999 (void) fprintf(stderr
, gettext("missing device name\n"));
6005 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
6008 for (i
= 1; i
< argc
; i
++) {
6010 uint64_t guid
= zpool_vdev_path_to_guid(zhp
, argv
[i
]);
6012 if (istmp
== B_FALSE
) {
6013 /* Force the fault to persist across imports */
6014 aux
= VDEV_AUX_EXTERNAL_PERSIST
;
6016 aux
= VDEV_AUX_EXTERNAL
;
6019 if (guid
== 0 || zpool_vdev_fault(zhp
, guid
, aux
) != 0)
6022 if (zpool_vdev_offline(zhp
, argv
[i
], istmp
) != 0)
6033 * zpool clear <pool> [device]
6035 * Clear all errors associated with a pool or a particular device.
6038 zpool_do_clear(int argc
, char **argv
)
6042 boolean_t dryrun
= B_FALSE
;
6043 boolean_t do_rewind
= B_FALSE
;
6044 boolean_t xtreme_rewind
= B_FALSE
;
6045 uint32_t rewind_policy
= ZPOOL_NO_REWIND
;
6046 nvlist_t
*policy
= NULL
;
6047 zpool_handle_t
*zhp
;
6048 char *pool
, *device
;
6051 while ((c
= getopt(argc
, argv
, "FnX")) != -1) {
6060 xtreme_rewind
= B_TRUE
;
6063 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
6073 (void) fprintf(stderr
, gettext("missing pool name\n"));
6078 (void) fprintf(stderr
, gettext("too many arguments\n"));
6082 if ((dryrun
|| xtreme_rewind
) && !do_rewind
) {
6083 (void) fprintf(stderr
,
6084 gettext("-n or -X only meaningful with -F\n"));
6088 rewind_policy
= ZPOOL_TRY_REWIND
;
6090 rewind_policy
= ZPOOL_DO_REWIND
;
6092 rewind_policy
|= ZPOOL_EXTREME_REWIND
;
6094 /* In future, further rewind policy choices can be passed along here */
6095 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME
, 0) != 0 ||
6096 nvlist_add_uint32(policy
, ZPOOL_LOAD_REWIND_POLICY
,
6097 rewind_policy
) != 0) {
6102 device
= argc
== 2 ? argv
[1] : NULL
;
6104 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
) {
6105 nvlist_free(policy
);
6109 if (zpool_clear(zhp
, device
, policy
) != 0)
6114 nvlist_free(policy
);
6120 * zpool reguid <pool>
6123 zpool_do_reguid(int argc
, char **argv
)
6127 zpool_handle_t
*zhp
;
6131 while ((c
= getopt(argc
, argv
, "")) != -1) {
6134 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
6143 /* get pool name and check number of arguments */
6145 (void) fprintf(stderr
, gettext("missing pool name\n"));
6150 (void) fprintf(stderr
, gettext("too many arguments\n"));
6155 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
6158 ret
= zpool_reguid(zhp
);
6166 * zpool reopen <pool>
6168 * Reopen the pool so that the kernel can update the sizes of all vdevs.
6171 zpool_do_reopen(int argc
, char **argv
)
6175 boolean_t scrub_restart
= B_TRUE
;
6178 while ((c
= getopt(argc
, argv
, "n")) != -1) {
6181 scrub_restart
= B_FALSE
;
6184 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
6193 /* if argc == 0 we will execute zpool_reopen_one on all pools */
6194 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
, zpool_reopen_one
,
6200 typedef struct scrub_cbdata
{
6204 pool_scrub_cmd_t cb_scrub_cmd
;
6208 zpool_has_checkpoint(zpool_handle_t
*zhp
)
6210 nvlist_t
*config
, *nvroot
;
6212 config
= zpool_get_config(zhp
, NULL
);
6214 if (config
!= NULL
) {
6215 pool_checkpoint_stat_t
*pcs
= NULL
;
6218 nvroot
= fnvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
);
6219 (void) nvlist_lookup_uint64_array(nvroot
,
6220 ZPOOL_CONFIG_CHECKPOINT_STATS
, (uint64_t **)&pcs
, &c
);
6222 if (pcs
== NULL
|| pcs
->pcs_state
== CS_NONE
)
6225 assert(pcs
->pcs_state
== CS_CHECKPOINT_EXISTS
||
6226 pcs
->pcs_state
== CS_CHECKPOINT_DISCARDING
);
6234 scrub_callback(zpool_handle_t
*zhp
, void *data
)
6236 scrub_cbdata_t
*cb
= data
;
6240 * Ignore faulted pools.
6242 if (zpool_get_state(zhp
) == POOL_STATE_UNAVAIL
) {
6243 (void) fprintf(stderr
, gettext("cannot scrub '%s': pool is "
6244 "currently unavailable\n"), zpool_get_name(zhp
));
6248 err
= zpool_scan(zhp
, cb
->cb_type
, cb
->cb_scrub_cmd
);
6250 if (err
== 0 && zpool_has_checkpoint(zhp
) &&
6251 cb
->cb_type
== POOL_SCAN_SCRUB
) {
6252 (void) printf(gettext("warning: will not scrub state that "
6253 "belongs to the checkpoint of pool '%s'\n"),
6254 zpool_get_name(zhp
));
6261 * zpool scrub [-s | -p] <pool> ...
6263 * -s Stop. Stops any in-progress scrub.
6264 * -p Pause. Pause in-progress scrub.
6267 zpool_do_scrub(int argc
, char **argv
)
6272 cb
.cb_type
= POOL_SCAN_SCRUB
;
6273 cb
.cb_scrub_cmd
= POOL_SCRUB_NORMAL
;
6276 while ((c
= getopt(argc
, argv
, "sp")) != -1) {
6279 cb
.cb_type
= POOL_SCAN_NONE
;
6282 cb
.cb_scrub_cmd
= POOL_SCRUB_PAUSE
;
6285 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
6291 if (cb
.cb_type
== POOL_SCAN_NONE
&&
6292 cb
.cb_scrub_cmd
== POOL_SCRUB_PAUSE
) {
6293 (void) fprintf(stderr
, gettext("invalid option combination: "
6294 "-s and -p are mutually exclusive\n"));
6304 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
6308 return (for_each_pool(argc
, argv
, B_TRUE
, NULL
, scrub_callback
, &cb
));
6312 * Print out detailed scrub status.
6315 print_scan_status(pool_scan_stat_t
*ps
)
6317 time_t start
, end
, pause
;
6318 uint64_t total_secs_left
;
6319 uint64_t elapsed
, secs_left
, mins_left
, hours_left
, days_left
;
6320 uint64_t pass_scanned
, scanned
, pass_issued
, issued
, total
;
6321 uint64_t scan_rate
, issue_rate
;
6322 double fraction_done
;
6323 char processed_buf
[7], scanned_buf
[7], issued_buf
[7], total_buf
[7];
6324 char srate_buf
[7], irate_buf
[7];
6326 (void) printf(gettext(" scan: "));
6328 /* If there's never been a scan, there's not much to say. */
6329 if (ps
== NULL
|| ps
->pss_func
== POOL_SCAN_NONE
||
6330 ps
->pss_func
>= POOL_SCAN_FUNCS
) {
6331 (void) printf(gettext("none requested\n"));
6335 start
= ps
->pss_start_time
;
6336 end
= ps
->pss_end_time
;
6337 pause
= ps
->pss_pass_scrub_pause
;
6339 zfs_nicebytes(ps
->pss_processed
, processed_buf
, sizeof (processed_buf
));
6341 assert(ps
->pss_func
== POOL_SCAN_SCRUB
||
6342 ps
->pss_func
== POOL_SCAN_RESILVER
);
6344 /* Scan is finished or canceled. */
6345 if (ps
->pss_state
== DSS_FINISHED
) {
6346 total_secs_left
= end
- start
;
6347 days_left
= total_secs_left
/ 60 / 60 / 24;
6348 hours_left
= (total_secs_left
/ 60 / 60) % 24;
6349 mins_left
= (total_secs_left
/ 60) % 60;
6350 secs_left
= (total_secs_left
% 60);
6352 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
6353 (void) printf(gettext("scrub repaired %s "
6354 "in %llu days %02llu:%02llu:%02llu "
6355 "with %llu errors on %s"), processed_buf
,
6356 (u_longlong_t
)days_left
, (u_longlong_t
)hours_left
,
6357 (u_longlong_t
)mins_left
, (u_longlong_t
)secs_left
,
6358 (u_longlong_t
)ps
->pss_errors
, ctime(&end
));
6359 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
6360 (void) printf(gettext("resilvered %s "
6361 "in %llu days %02llu:%02llu:%02llu "
6362 "with %llu errors on %s"), processed_buf
,
6363 (u_longlong_t
)days_left
, (u_longlong_t
)hours_left
,
6364 (u_longlong_t
)mins_left
, (u_longlong_t
)secs_left
,
6365 (u_longlong_t
)ps
->pss_errors
, ctime(&end
));
6368 } else if (ps
->pss_state
== DSS_CANCELED
) {
6369 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
6370 (void) printf(gettext("scrub canceled on %s"),
6372 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
6373 (void) printf(gettext("resilver canceled on %s"),
6379 assert(ps
->pss_state
== DSS_SCANNING
);
6381 /* Scan is in progress. Resilvers can't be paused. */
6382 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
6384 (void) printf(gettext("scrub in progress since %s"),
6387 (void) printf(gettext("scrub paused since %s"),
6389 (void) printf(gettext("\tscrub started on %s"),
6392 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
6393 (void) printf(gettext("resilver in progress since %s"),
6397 scanned
= ps
->pss_examined
;
6398 pass_scanned
= ps
->pss_pass_exam
;
6399 issued
= ps
->pss_issued
;
6400 pass_issued
= ps
->pss_pass_issued
;
6401 total
= ps
->pss_to_examine
;
6403 /* we are only done with a block once we have issued the IO for it */
6404 fraction_done
= (double)issued
/ total
;
6406 /* elapsed time for this pass, rounding up to 1 if it's 0 */
6407 elapsed
= time(NULL
) - ps
->pss_pass_start
;
6408 elapsed
-= ps
->pss_pass_scrub_spent_paused
;
6409 elapsed
= (elapsed
!= 0) ? elapsed
: 1;
6411 scan_rate
= pass_scanned
/ elapsed
;
6412 issue_rate
= pass_issued
/ elapsed
;
6413 total_secs_left
= (issue_rate
!= 0) ?
6414 ((total
- issued
) / issue_rate
) : UINT64_MAX
;
6416 days_left
= total_secs_left
/ 60 / 60 / 24;
6417 hours_left
= (total_secs_left
/ 60 / 60) % 24;
6418 mins_left
= (total_secs_left
/ 60) % 60;
6419 secs_left
= (total_secs_left
% 60);
6421 /* format all of the numbers we will be reporting */
6422 zfs_nicebytes(scanned
, scanned_buf
, sizeof (scanned_buf
));
6423 zfs_nicebytes(issued
, issued_buf
, sizeof (issued_buf
));
6424 zfs_nicebytes(total
, total_buf
, sizeof (total_buf
));
6425 zfs_nicebytes(scan_rate
, srate_buf
, sizeof (srate_buf
));
6426 zfs_nicebytes(issue_rate
, irate_buf
, sizeof (irate_buf
));
6428 /* do not print estimated time if we have a paused scrub */
6430 (void) printf(gettext("\t%s scanned at %s/s, "
6431 "%s issued at %s/s, %s total\n"),
6432 scanned_buf
, srate_buf
, issued_buf
, irate_buf
, total_buf
);
6434 (void) printf(gettext("\t%s scanned, %s issued, %s total\n"),
6435 scanned_buf
, issued_buf
, total_buf
);
6438 if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
6439 (void) printf(gettext("\t%s resilvered, %.2f%% done"),
6440 processed_buf
, 100 * fraction_done
);
6441 } else if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
6442 (void) printf(gettext("\t%s repaired, %.2f%% done"),
6443 processed_buf
, 100 * fraction_done
);
6447 if (issue_rate
>= 10 * 1024 * 1024) {
6448 (void) printf(gettext(", %llu days "
6449 "%02llu:%02llu:%02llu to go\n"),
6450 (u_longlong_t
)days_left
, (u_longlong_t
)hours_left
,
6451 (u_longlong_t
)mins_left
, (u_longlong_t
)secs_left
);
6453 (void) printf(gettext(", no estimated "
6454 "completion time\n"));
6457 (void) printf(gettext("\n"));
6462 * As we don't scrub checkpointed blocks, we want to warn the
6463 * user that we skipped scanning some blocks if a checkpoint exists
6464 * or existed at any time during the scan.
6467 print_checkpoint_scan_warning(pool_scan_stat_t
*ps
, pool_checkpoint_stat_t
*pcs
)
6469 if (ps
== NULL
|| pcs
== NULL
)
6472 if (pcs
->pcs_state
== CS_NONE
||
6473 pcs
->pcs_state
== CS_CHECKPOINT_DISCARDING
)
6476 assert(pcs
->pcs_state
== CS_CHECKPOINT_EXISTS
);
6478 if (ps
->pss_state
== DSS_NONE
)
6481 if ((ps
->pss_state
== DSS_FINISHED
|| ps
->pss_state
== DSS_CANCELED
) &&
6482 ps
->pss_end_time
< pcs
->pcs_start_time
)
6485 if (ps
->pss_state
== DSS_FINISHED
|| ps
->pss_state
== DSS_CANCELED
) {
6486 (void) printf(gettext(" scan warning: skipped blocks "
6487 "that are only referenced by the checkpoint.\n"));
6489 assert(ps
->pss_state
== DSS_SCANNING
);
6490 (void) printf(gettext(" scan warning: skipping blocks "
6491 "that are only referenced by the checkpoint.\n"));
6496 * Print out detailed removal status.
6499 print_removal_status(zpool_handle_t
*zhp
, pool_removal_stat_t
*prs
)
6501 char copied_buf
[7], examined_buf
[7], total_buf
[7], rate_buf
[7];
6503 nvlist_t
*config
, *nvroot
;
6508 if (prs
== NULL
|| prs
->prs_state
== DSS_NONE
)
6512 * Determine name of vdev.
6514 config
= zpool_get_config(zhp
, NULL
);
6515 nvroot
= fnvlist_lookup_nvlist(config
,
6516 ZPOOL_CONFIG_VDEV_TREE
);
6517 verify(nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_CHILDREN
,
6518 &child
, &children
) == 0);
6519 assert(prs
->prs_removing_vdev
< children
);
6520 vdev_name
= zpool_vdev_name(g_zfs
, zhp
,
6521 child
[prs
->prs_removing_vdev
], B_TRUE
);
6523 (void) printf(gettext("remove: "));
6525 start
= prs
->prs_start_time
;
6526 end
= prs
->prs_end_time
;
6527 zfs_nicenum(prs
->prs_copied
, copied_buf
, sizeof (copied_buf
));
6530 * Removal is finished or canceled.
6532 if (prs
->prs_state
== DSS_FINISHED
) {
6533 uint64_t minutes_taken
= (end
- start
) / 60;
6535 (void) printf(gettext("Removal of vdev %llu copied %s "
6536 "in %lluh%um, completed on %s"),
6537 (longlong_t
)prs
->prs_removing_vdev
,
6539 (u_longlong_t
)(minutes_taken
/ 60),
6540 (uint_t
)(minutes_taken
% 60),
6541 ctime((time_t *)&end
));
6542 } else if (prs
->prs_state
== DSS_CANCELED
) {
6543 (void) printf(gettext("Removal of %s canceled on %s"),
6544 vdev_name
, ctime(&end
));
6546 uint64_t copied
, total
, elapsed
, mins_left
, hours_left
;
6547 double fraction_done
;
6550 assert(prs
->prs_state
== DSS_SCANNING
);
6553 * Removal is in progress.
6555 (void) printf(gettext(
6556 "Evacuation of %s in progress since %s"),
6557 vdev_name
, ctime(&start
));
6559 copied
= prs
->prs_copied
> 0 ? prs
->prs_copied
: 1;
6560 total
= prs
->prs_to_copy
;
6561 fraction_done
= (double)copied
/ total
;
6563 /* elapsed time for this pass */
6564 elapsed
= time(NULL
) - prs
->prs_start_time
;
6565 elapsed
= elapsed
> 0 ? elapsed
: 1;
6566 rate
= copied
/ elapsed
;
6567 rate
= rate
> 0 ? rate
: 1;
6568 mins_left
= ((total
- copied
) / rate
) / 60;
6569 hours_left
= mins_left
/ 60;
6571 zfs_nicenum(copied
, examined_buf
, sizeof (examined_buf
));
6572 zfs_nicenum(total
, total_buf
, sizeof (total_buf
));
6573 zfs_nicenum(rate
, rate_buf
, sizeof (rate_buf
));
6576 * do not print estimated time if hours_left is more than
6579 (void) printf(gettext(" %s copied out of %s at %s/s, "
6581 examined_buf
, total_buf
, rate_buf
, 100 * fraction_done
);
6582 if (hours_left
< (30 * 24)) {
6583 (void) printf(gettext(", %lluh%um to go\n"),
6584 (u_longlong_t
)hours_left
, (uint_t
)(mins_left
% 60));
6586 (void) printf(gettext(
6587 ", (copy is slow, no estimated time)\n"));
6591 if (prs
->prs_mapping_memory
> 0) {
6593 zfs_nicenum(prs
->prs_mapping_memory
, mem_buf
, sizeof (mem_buf
));
6594 (void) printf(gettext(" %s memory used for "
6595 "removed device mappings\n"),
6601 print_checkpoint_status(pool_checkpoint_stat_t
*pcs
)
6606 if (pcs
== NULL
|| pcs
->pcs_state
== CS_NONE
)
6609 (void) printf(gettext("checkpoint: "));
6611 start
= pcs
->pcs_start_time
;
6612 zfs_nicenum(pcs
->pcs_space
, space_buf
, sizeof (space_buf
));
6614 if (pcs
->pcs_state
== CS_CHECKPOINT_EXISTS
) {
6615 char *date
= ctime(&start
);
6618 * ctime() adds a newline at the end of the generated
6619 * string, thus the weird format specifier and the
6620 * strlen() call used to chop it off from the output.
6622 (void) printf(gettext("created %.*s, consumes %s\n"),
6623 (int)(strlen(date
) - 1), date
, space_buf
);
6627 assert(pcs
->pcs_state
== CS_CHECKPOINT_DISCARDING
);
6629 (void) printf(gettext("discarding, %s remaining.\n"),
6634 print_error_log(zpool_handle_t
*zhp
)
6636 nvlist_t
*nverrlist
= NULL
;
6639 size_t len
= MAXPATHLEN
* 2;
6641 if (zpool_get_errlog(zhp
, &nverrlist
) != 0)
6644 (void) printf("errors: Permanent errors have been "
6645 "detected in the following files:\n\n");
6647 pathname
= safe_malloc(len
);
6649 while ((elem
= nvlist_next_nvpair(nverrlist
, elem
)) != NULL
) {
6651 uint64_t dsobj
, obj
;
6653 verify(nvpair_value_nvlist(elem
, &nv
) == 0);
6654 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_DATASET
,
6656 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_OBJECT
,
6658 zpool_obj_to_path(zhp
, dsobj
, obj
, pathname
, len
);
6659 (void) printf("%7s %s\n", "", pathname
);
6662 nvlist_free(nverrlist
);
6666 print_spares(zpool_handle_t
*zhp
, status_cbdata_t
*cb
, nvlist_t
**spares
,
6675 (void) printf(gettext("\tspares\n"));
6677 for (i
= 0; i
< nspares
; i
++) {
6678 name
= zpool_vdev_name(g_zfs
, zhp
, spares
[i
],
6680 print_status_config(zhp
, cb
, name
, spares
[i
], 2, B_TRUE
);
6686 print_l2cache(zpool_handle_t
*zhp
, status_cbdata_t
*cb
, nvlist_t
**l2cache
,
6695 (void) printf(gettext("\tcache\n"));
6697 for (i
= 0; i
< nl2cache
; i
++) {
6698 name
= zpool_vdev_name(g_zfs
, zhp
, l2cache
[i
],
6700 print_status_config(zhp
, cb
, name
, l2cache
[i
], 2, B_FALSE
);
6706 print_dedup_stats(nvlist_t
*config
)
6708 ddt_histogram_t
*ddh
;
6712 char dspace
[6], mspace
[6];
6715 * If the pool was faulted then we may not have been able to
6716 * obtain the config. Otherwise, if we have anything in the dedup
6717 * table continue processing the stats.
6719 if (nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_OBJ_STATS
,
6720 (uint64_t **)&ddo
, &c
) != 0)
6723 (void) printf("\n");
6724 (void) printf(gettext(" dedup: "));
6725 if (ddo
->ddo_count
== 0) {
6726 (void) printf(gettext("no DDT entries\n"));
6730 zfs_nicebytes(ddo
->ddo_dspace
, dspace
, sizeof (dspace
));
6731 zfs_nicebytes(ddo
->ddo_mspace
, mspace
, sizeof (mspace
));
6732 (void) printf("DDT entries %llu, size %s on disk, %s in core\n",
6733 (u_longlong_t
)ddo
->ddo_count
,
6737 verify(nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_STATS
,
6738 (uint64_t **)&dds
, &c
) == 0);
6739 verify(nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_HISTOGRAM
,
6740 (uint64_t **)&ddh
, &c
) == 0);
6741 zpool_dump_ddt(dds
, ddh
);
6745 * Display a summary of pool status. Displays a summary such as:
6749 * reason: One or more devices ...
6750 * see: http://zfsonlinux.org/msg/ZFS-xxxx-01
6756 * When given the '-v' option, we print out the complete config. If the '-e'
6757 * option is specified, then we print out error rate information as well.
6760 status_callback(zpool_handle_t
*zhp
, void *data
)
6762 status_cbdata_t
*cbp
= data
;
6763 nvlist_t
*config
, *nvroot
;
6765 zpool_status_t reason
;
6766 zpool_errata_t errata
;
6771 config
= zpool_get_config(zhp
, NULL
);
6772 reason
= zpool_get_status(zhp
, &msgid
, &errata
);
6777 * If we were given 'zpool status -x', only report those pools with
6780 if (cbp
->cb_explain
&&
6781 (reason
== ZPOOL_STATUS_OK
||
6782 reason
== ZPOOL_STATUS_VERSION_OLDER
||
6783 reason
== ZPOOL_STATUS_FEAT_DISABLED
)) {
6784 if (!cbp
->cb_allpools
) {
6785 (void) printf(gettext("pool '%s' is healthy\n"),
6786 zpool_get_name(zhp
));
6788 cbp
->cb_first
= B_FALSE
;
6794 cbp
->cb_first
= B_FALSE
;
6796 (void) printf("\n");
6798 nvroot
= fnvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
);
6799 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_VDEV_STATS
,
6800 (uint64_t **)&vs
, &c
) == 0);
6802 health
= zpool_get_state_str(zhp
);
6804 (void) printf(gettext(" pool: %s\n"), zpool_get_name(zhp
));
6805 (void) printf(gettext(" state: %s\n"), health
);
6808 case ZPOOL_STATUS_MISSING_DEV_R
:
6809 (void) printf(gettext("status: One or more devices could not "
6810 "be opened. Sufficient replicas exist for\n\tthe pool to "
6811 "continue functioning in a degraded state.\n"));
6812 (void) printf(gettext("action: Attach the missing device and "
6813 "online it using 'zpool online'.\n"));
6816 case ZPOOL_STATUS_MISSING_DEV_NR
:
6817 (void) printf(gettext("status: One or more devices could not "
6818 "be opened. There are insufficient\n\treplicas for the "
6819 "pool to continue functioning.\n"));
6820 (void) printf(gettext("action: Attach the missing device and "
6821 "online it using 'zpool online'.\n"));
6824 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
6825 (void) printf(gettext("status: One or more devices could not "
6826 "be used because the label is missing or\n\tinvalid. "
6827 "Sufficient replicas exist for the pool to continue\n\t"
6828 "functioning in a degraded state.\n"));
6829 (void) printf(gettext("action: Replace the device using "
6830 "'zpool replace'.\n"));
6833 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
6834 (void) printf(gettext("status: One or more devices could not "
6835 "be used because the label is missing \n\tor invalid. "
6836 "There are insufficient replicas for the pool to "
6837 "continue\n\tfunctioning.\n"));
6838 zpool_explain_recover(zpool_get_handle(zhp
),
6839 zpool_get_name(zhp
), reason
, config
);
6842 case ZPOOL_STATUS_FAILING_DEV
:
6843 (void) printf(gettext("status: One or more devices has "
6844 "experienced an unrecoverable error. An\n\tattempt was "
6845 "made to correct the error. Applications are "
6847 (void) printf(gettext("action: Determine if the device needs "
6848 "to be replaced, and clear the errors\n\tusing "
6849 "'zpool clear' or replace the device with 'zpool "
6853 case ZPOOL_STATUS_OFFLINE_DEV
:
6854 (void) printf(gettext("status: One or more devices has "
6855 "been taken offline by the administrator.\n\tSufficient "
6856 "replicas exist for the pool to continue functioning in "
6857 "a\n\tdegraded state.\n"));
6858 (void) printf(gettext("action: Online the device using "
6859 "'zpool online' or replace the device with\n\t'zpool "
6863 case ZPOOL_STATUS_REMOVED_DEV
:
6864 (void) printf(gettext("status: One or more devices has "
6865 "been removed by the administrator.\n\tSufficient "
6866 "replicas exist for the pool to continue functioning in "
6867 "a\n\tdegraded state.\n"));
6868 (void) printf(gettext("action: Online the device using "
6869 "'zpool online' or replace the device with\n\t'zpool "
6873 case ZPOOL_STATUS_RESILVERING
:
6874 (void) printf(gettext("status: One or more devices is "
6875 "currently being resilvered. The pool will\n\tcontinue "
6876 "to function, possibly in a degraded state.\n"));
6877 (void) printf(gettext("action: Wait for the resilver to "
6881 case ZPOOL_STATUS_CORRUPT_DATA
:
6882 (void) printf(gettext("status: One or more devices has "
6883 "experienced an error resulting in data\n\tcorruption. "
6884 "Applications may be affected.\n"));
6885 (void) printf(gettext("action: Restore the file in question "
6886 "if possible. Otherwise restore the\n\tentire pool from "
6890 case ZPOOL_STATUS_CORRUPT_POOL
:
6891 (void) printf(gettext("status: The pool metadata is corrupted "
6892 "and the pool cannot be opened.\n"));
6893 zpool_explain_recover(zpool_get_handle(zhp
),
6894 zpool_get_name(zhp
), reason
, config
);
6897 case ZPOOL_STATUS_VERSION_OLDER
:
6898 (void) printf(gettext("status: The pool is formatted using a "
6899 "legacy on-disk format. The pool can\n\tstill be used, "
6900 "but some features are unavailable.\n"));
6901 (void) printf(gettext("action: Upgrade the pool using 'zpool "
6902 "upgrade'. Once this is done, the\n\tpool will no longer "
6903 "be accessible on software that does not support\n\t"
6904 "feature flags.\n"));
6907 case ZPOOL_STATUS_VERSION_NEWER
:
6908 (void) printf(gettext("status: The pool has been upgraded to a "
6909 "newer, incompatible on-disk version.\n\tThe pool cannot "
6910 "be accessed on this system.\n"));
6911 (void) printf(gettext("action: Access the pool from a system "
6912 "running more recent software, or\n\trestore the pool from "
6916 case ZPOOL_STATUS_FEAT_DISABLED
:
6917 (void) printf(gettext("status: Some supported features are not "
6918 "enabled on the pool. The pool can\n\tstill be used, but "
6919 "some features are unavailable.\n"));
6920 (void) printf(gettext("action: Enable all features using "
6921 "'zpool upgrade'. Once this is done,\n\tthe pool may no "
6922 "longer be accessible by software that does not support\n\t"
6923 "the features. See zpool-features(5) for details.\n"));
6926 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
6927 (void) printf(gettext("status: The pool cannot be accessed on "
6928 "this system because it uses the\n\tfollowing feature(s) "
6929 "not supported on this system:\n"));
6930 zpool_print_unsup_feat(config
);
6931 (void) printf("\n");
6932 (void) printf(gettext("action: Access the pool from a system "
6933 "that supports the required feature(s),\n\tor restore the "
6934 "pool from backup.\n"));
6937 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
6938 (void) printf(gettext("status: The pool can only be accessed "
6939 "in read-only mode on this system. It\n\tcannot be "
6940 "accessed in read-write mode because it uses the "
6941 "following\n\tfeature(s) not supported on this system:\n"));
6942 zpool_print_unsup_feat(config
);
6943 (void) printf("\n");
6944 (void) printf(gettext("action: The pool cannot be accessed in "
6945 "read-write mode. Import the pool with\n"
6946 "\t\"-o readonly=on\", access the pool from a system that "
6947 "supports the\n\trequired feature(s), or restore the "
6948 "pool from backup.\n"));
6951 case ZPOOL_STATUS_FAULTED_DEV_R
:
6952 (void) printf(gettext("status: One or more devices are "
6953 "faulted in response to persistent errors.\n\tSufficient "
6954 "replicas exist for the pool to continue functioning "
6955 "in a\n\tdegraded state.\n"));
6956 (void) printf(gettext("action: Replace the faulted device, "
6957 "or use 'zpool clear' to mark the device\n\trepaired.\n"));
6960 case ZPOOL_STATUS_FAULTED_DEV_NR
:
6961 (void) printf(gettext("status: One or more devices are "
6962 "faulted in response to persistent errors. There are "
6963 "insufficient replicas for the pool to\n\tcontinue "
6965 (void) printf(gettext("action: Destroy and re-create the pool "
6966 "from a backup source. Manually marking the device\n"
6967 "\trepaired using 'zpool clear' may allow some data "
6968 "to be recovered.\n"));
6971 case ZPOOL_STATUS_IO_FAILURE_MMP
:
6972 (void) printf(gettext("status: The pool is suspended because "
6973 "multihost writes failed or were delayed;\n\tanother "
6974 "system could import the pool undetected.\n"));
6975 (void) printf(gettext("action: Make sure the pool's devices "
6976 "are connected, then reboot your system and\n\timport the "
6980 case ZPOOL_STATUS_IO_FAILURE_WAIT
:
6981 case ZPOOL_STATUS_IO_FAILURE_CONTINUE
:
6982 (void) printf(gettext("status: One or more devices are "
6983 "faulted in response to IO failures.\n"));
6984 (void) printf(gettext("action: Make sure the affected devices "
6985 "are connected, then run 'zpool clear'.\n"));
6988 case ZPOOL_STATUS_BAD_LOG
:
6989 (void) printf(gettext("status: An intent log record "
6990 "could not be read.\n"
6991 "\tWaiting for administrator intervention to fix the "
6992 "faulted pool.\n"));
6993 (void) printf(gettext("action: Either restore the affected "
6994 "device(s) and run 'zpool online',\n"
6995 "\tor ignore the intent log records by running "
6996 "'zpool clear'.\n"));
6999 case ZPOOL_STATUS_HOSTID_MISMATCH
:
7000 (void) printf(gettext("status: Mismatch between pool hostid "
7001 "and system hostid on imported pool.\n\tThis pool was "
7002 "previously imported into a system with a different "
7003 "hostid,\n\tand then was verbatim imported into this "
7005 (void) printf(gettext("action: Export this pool on all systems "
7006 "on which it is imported.\n"
7007 "\tThen import it to correct the mismatch.\n"));
7010 case ZPOOL_STATUS_ERRATA
:
7011 (void) printf(gettext("status: Errata #%d detected.\n"),
7015 case ZPOOL_ERRATA_NONE
:
7018 case ZPOOL_ERRATA_ZOL_2094_SCRUB
:
7019 (void) printf(gettext("action: To correct the issue "
7020 "run 'zpool scrub'.\n"));
7023 case ZPOOL_ERRATA_ZOL_6845_ENCRYPTION
:
7024 (void) printf(gettext("\tExisting encrypted datasets "
7025 "contain an on-disk incompatibility\n\twhich "
7026 "needs to be corrected.\n"));
7027 (void) printf(gettext("action: To correct the issue "
7028 "backup existing encrypted datasets to new\n\t"
7029 "encrypted datasets and destroy the old ones. "
7030 "'zfs mount -o ro' can\n\tbe used to temporarily "
7031 "mount existing encrypted datasets readonly.\n"));
7036 * All errata which allow the pool to be imported
7037 * must contain an action message.
7045 * The remaining errors can't actually be generated, yet.
7047 assert(reason
== ZPOOL_STATUS_OK
);
7051 (void) printf(gettext(" see: http://zfsonlinux.org/msg/%s\n"),
7054 if (config
!= NULL
) {
7056 nvlist_t
**spares
, **l2cache
;
7057 uint_t nspares
, nl2cache
;
7058 pool_checkpoint_stat_t
*pcs
= NULL
;
7059 pool_scan_stat_t
*ps
= NULL
;
7060 pool_removal_stat_t
*prs
= NULL
;
7062 (void) nvlist_lookup_uint64_array(nvroot
,
7063 ZPOOL_CONFIG_CHECKPOINT_STATS
, (uint64_t **)&pcs
, &c
);
7064 (void) nvlist_lookup_uint64_array(nvroot
,
7065 ZPOOL_CONFIG_SCAN_STATS
, (uint64_t **)&ps
, &c
);
7066 (void) nvlist_lookup_uint64_array(nvroot
,
7067 ZPOOL_CONFIG_REMOVAL_STATS
, (uint64_t **)&prs
, &c
);
7069 print_scan_status(ps
);
7070 print_checkpoint_scan_warning(ps
, pcs
);
7071 print_removal_status(zhp
, prs
);
7072 print_checkpoint_status(pcs
);
7074 cbp
->cb_namewidth
= max_width(zhp
, nvroot
, 0, 0,
7075 cbp
->cb_name_flags
| VDEV_NAME_TYPE_ID
);
7076 if (cbp
->cb_namewidth
< 10)
7077 cbp
->cb_namewidth
= 10;
7079 (void) printf(gettext("config:\n\n"));
7080 (void) printf(gettext("\t%-*s %-8s %5s %5s %5s"),
7081 cbp
->cb_namewidth
, "NAME", "STATE", "READ", "WRITE",
7084 if (cbp
->vcdl
!= NULL
)
7085 print_cmd_columns(cbp
->vcdl
, 0);
7089 print_status_config(zhp
, cbp
, zpool_get_name(zhp
), nvroot
, 0,
7092 print_class_vdevs(zhp
, cbp
, nvroot
, VDEV_ALLOC_BIAS_DEDUP
);
7093 print_class_vdevs(zhp
, cbp
, nvroot
, VDEV_ALLOC_BIAS_SPECIAL
);
7094 print_class_vdevs(zhp
, cbp
, nvroot
, VDEV_ALLOC_CLASS_LOGS
);
7096 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_L2CACHE
,
7097 &l2cache
, &nl2cache
) == 0)
7098 print_l2cache(zhp
, cbp
, l2cache
, nl2cache
);
7100 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_SPARES
,
7101 &spares
, &nspares
) == 0)
7102 print_spares(zhp
, cbp
, spares
, nspares
);
7104 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_ERRCOUNT
,
7106 nvlist_t
*nverrlist
= NULL
;
7109 * If the approximate error count is small, get a
7110 * precise count by fetching the entire log and
7111 * uniquifying the results.
7113 if (nerr
> 0 && nerr
< 100 && !cbp
->cb_verbose
&&
7114 zpool_get_errlog(zhp
, &nverrlist
) == 0) {
7119 while ((elem
= nvlist_next_nvpair(nverrlist
,
7124 nvlist_free(nverrlist
);
7126 (void) printf("\n");
7129 (void) printf(gettext("errors: No known data "
7131 else if (!cbp
->cb_verbose
)
7132 (void) printf(gettext("errors: %llu data "
7133 "errors, use '-v' for a list\n"),
7134 (u_longlong_t
)nerr
);
7136 print_error_log(zhp
);
7139 if (cbp
->cb_dedup_stats
)
7140 print_dedup_stats(config
);
7142 (void) printf(gettext("config: The configuration cannot be "
7150 * zpool status [-c [script1,script2,...]] [-gLPvx] [-T d|u] [pool] ...
7151 * [interval [count]]
7153 * -c CMD For each vdev, run command CMD
7154 * -g Display guid for individual vdev name.
7155 * -L Follow links when resolving vdev path name.
7156 * -P Display full path for vdev name.
7157 * -v Display complete error logs
7158 * -x Display only pools with potential problems
7159 * -D Display dedup status (undocumented)
7160 * -T Display a timestamp in date(1) or Unix format
7162 * Describes the health status of all pools or some subset.
7165 zpool_do_status(int argc
, char **argv
)
7170 unsigned long count
= 0;
7171 status_cbdata_t cb
= { 0 };
7175 while ((c
= getopt(argc
, argv
, "c:gLPvxDT:")) != -1) {
7180 gettext("Can't set -c flag twice\n"));
7184 if (getenv("ZPOOL_SCRIPTS_ENABLED") != NULL
&&
7185 !libzfs_envvar_is_set("ZPOOL_SCRIPTS_ENABLED")) {
7186 fprintf(stderr
, gettext(
7187 "Can't run -c, disabled by "
7188 "ZPOOL_SCRIPTS_ENABLED.\n"));
7192 if ((getuid() <= 0 || geteuid() <= 0) &&
7193 !libzfs_envvar_is_set("ZPOOL_SCRIPTS_AS_ROOT")) {
7194 fprintf(stderr
, gettext(
7195 "Can't run -c with root privileges "
7196 "unless ZPOOL_SCRIPTS_AS_ROOT is set.\n"));
7202 cb
.cb_name_flags
|= VDEV_NAME_GUID
;
7205 cb
.cb_name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
7208 cb
.cb_name_flags
|= VDEV_NAME_PATH
;
7211 cb
.cb_verbose
= B_TRUE
;
7214 cb
.cb_explain
= B_TRUE
;
7217 cb
.cb_dedup_stats
= B_TRUE
;
7220 get_timestamp_arg(*optarg
);
7223 if (optopt
== 'c') {
7224 print_zpool_script_list("status");
7228 gettext("invalid option '%c'\n"), optopt
);
7237 get_interval_count(&argc
, argv
, &interval
, &count
);
7240 cb
.cb_allpools
= B_TRUE
;
7242 cb
.cb_first
= B_TRUE
;
7243 cb
.cb_print_status
= B_TRUE
;
7246 if (timestamp_fmt
!= NODATE
)
7247 print_timestamp(timestamp_fmt
);
7250 cb
.vcdl
= all_pools_for_each_vdev_run(argc
, argv
, cmd
,
7253 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
,
7254 status_callback
, &cb
);
7256 if (cb
.vcdl
!= NULL
)
7257 free_vdev_cmd_data_list(cb
.vcdl
);
7259 if (argc
== 0 && cb
.cb_count
== 0)
7260 (void) fprintf(stderr
, gettext("no pools available\n"));
7261 else if (cb
.cb_explain
&& cb
.cb_first
&& cb
.cb_allpools
)
7262 (void) printf(gettext("all pools are healthy\n"));
7270 if (count
!= 0 && --count
== 0)
7273 (void) fsleep(interval
);
7279 typedef struct upgrade_cbdata
{
7282 uint64_t cb_version
;
7287 check_unsupp_fs(zfs_handle_t
*zhp
, void *unsupp_fs
)
7289 int zfs_version
= (int)zfs_prop_get_int(zhp
, ZFS_PROP_VERSION
);
7290 int *count
= (int *)unsupp_fs
;
7292 if (zfs_version
> ZPL_VERSION
) {
7293 (void) printf(gettext("%s (v%d) is not supported by this "
7294 "implementation of ZFS.\n"),
7295 zfs_get_name(zhp
), zfs_version
);
7299 zfs_iter_filesystems(zhp
, check_unsupp_fs
, unsupp_fs
);
7307 upgrade_version(zpool_handle_t
*zhp
, uint64_t version
)
7311 uint64_t oldversion
;
7314 config
= zpool_get_config(zhp
, NULL
);
7315 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
7318 assert(SPA_VERSION_IS_SUPPORTED(oldversion
));
7319 assert(oldversion
< version
);
7321 ret
= zfs_iter_root(zpool_get_handle(zhp
), check_unsupp_fs
, &unsupp_fs
);
7326 (void) fprintf(stderr
, gettext("Upgrade not performed due "
7327 "to %d unsupported filesystems (max v%d).\n"),
7328 unsupp_fs
, (int)ZPL_VERSION
);
7332 ret
= zpool_upgrade(zhp
, version
);
7336 if (version
>= SPA_VERSION_FEATURES
) {
7337 (void) printf(gettext("Successfully upgraded "
7338 "'%s' from version %llu to feature flags.\n"),
7339 zpool_get_name(zhp
), (u_longlong_t
)oldversion
);
7341 (void) printf(gettext("Successfully upgraded "
7342 "'%s' from version %llu to version %llu.\n"),
7343 zpool_get_name(zhp
), (u_longlong_t
)oldversion
,
7344 (u_longlong_t
)version
);
7351 upgrade_enable_all(zpool_handle_t
*zhp
, int *countp
)
7354 boolean_t firstff
= B_TRUE
;
7355 nvlist_t
*enabled
= zpool_get_features(zhp
);
7358 for (i
= 0; i
< SPA_FEATURES
; i
++) {
7359 const char *fname
= spa_feature_table
[i
].fi_uname
;
7360 const char *fguid
= spa_feature_table
[i
].fi_guid
;
7361 if (!nvlist_exists(enabled
, fguid
)) {
7363 verify(-1 != asprintf(&propname
, "feature@%s", fname
));
7364 ret
= zpool_set_prop(zhp
, propname
,
7365 ZFS_FEATURE_ENABLED
);
7373 (void) printf(gettext("Enabled the "
7374 "following features on '%s':\n"),
7375 zpool_get_name(zhp
));
7378 (void) printf(gettext(" %s\n"), fname
);
7389 upgrade_cb(zpool_handle_t
*zhp
, void *arg
)
7391 upgrade_cbdata_t
*cbp
= arg
;
7394 boolean_t printnl
= B_FALSE
;
7397 config
= zpool_get_config(zhp
, NULL
);
7398 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
7401 assert(SPA_VERSION_IS_SUPPORTED(version
));
7403 if (version
< cbp
->cb_version
) {
7404 cbp
->cb_first
= B_FALSE
;
7405 ret
= upgrade_version(zhp
, cbp
->cb_version
);
7411 * If they did "zpool upgrade -a", then we could
7412 * be doing ioctls to different pools. We need
7413 * to log this history once to each pool, and bypass
7414 * the normal history logging that happens in main().
7416 (void) zpool_log_history(g_zfs
, history_str
);
7417 log_history
= B_FALSE
;
7420 if (cbp
->cb_version
>= SPA_VERSION_FEATURES
) {
7422 ret
= upgrade_enable_all(zhp
, &count
);
7427 cbp
->cb_first
= B_FALSE
;
7433 (void) printf(gettext("\n"));
7440 upgrade_list_older_cb(zpool_handle_t
*zhp
, void *arg
)
7442 upgrade_cbdata_t
*cbp
= arg
;
7446 config
= zpool_get_config(zhp
, NULL
);
7447 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
7450 assert(SPA_VERSION_IS_SUPPORTED(version
));
7452 if (version
< SPA_VERSION_FEATURES
) {
7453 if (cbp
->cb_first
) {
7454 (void) printf(gettext("The following pools are "
7455 "formatted with legacy version numbers and can\n"
7456 "be upgraded to use feature flags. After "
7457 "being upgraded, these pools\nwill no "
7458 "longer be accessible by software that does not "
7459 "support feature\nflags.\n\n"));
7460 (void) printf(gettext("VER POOL\n"));
7461 (void) printf(gettext("--- ------------\n"));
7462 cbp
->cb_first
= B_FALSE
;
7465 (void) printf("%2llu %s\n", (u_longlong_t
)version
,
7466 zpool_get_name(zhp
));
7473 upgrade_list_disabled_cb(zpool_handle_t
*zhp
, void *arg
)
7475 upgrade_cbdata_t
*cbp
= arg
;
7479 config
= zpool_get_config(zhp
, NULL
);
7480 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
7483 if (version
>= SPA_VERSION_FEATURES
) {
7485 boolean_t poolfirst
= B_TRUE
;
7486 nvlist_t
*enabled
= zpool_get_features(zhp
);
7488 for (i
= 0; i
< SPA_FEATURES
; i
++) {
7489 const char *fguid
= spa_feature_table
[i
].fi_guid
;
7490 const char *fname
= spa_feature_table
[i
].fi_uname
;
7491 if (!nvlist_exists(enabled
, fguid
)) {
7492 if (cbp
->cb_first
) {
7493 (void) printf(gettext("\nSome "
7494 "supported features are not "
7495 "enabled on the following pools. "
7496 "Once a\nfeature is enabled the "
7497 "pool may become incompatible with "
7498 "software\nthat does not support "
7500 "zpool-features(5) for "
7502 (void) printf(gettext("POOL "
7504 (void) printf(gettext("------"
7506 cbp
->cb_first
= B_FALSE
;
7510 (void) printf(gettext("%s\n"),
7511 zpool_get_name(zhp
));
7512 poolfirst
= B_FALSE
;
7515 (void) printf(gettext(" %s\n"), fname
);
7518 * If they did "zpool upgrade -a", then we could
7519 * be doing ioctls to different pools. We need
7520 * to log this history once to each pool, and bypass
7521 * the normal history logging that happens in main().
7523 (void) zpool_log_history(g_zfs
, history_str
);
7524 log_history
= B_FALSE
;
7533 upgrade_one(zpool_handle_t
*zhp
, void *data
)
7535 boolean_t printnl
= B_FALSE
;
7536 upgrade_cbdata_t
*cbp
= data
;
7537 uint64_t cur_version
;
7540 if (strcmp("log", zpool_get_name(zhp
)) == 0) {
7541 (void) fprintf(stderr
, gettext("'log' is now a reserved word\n"
7542 "Pool 'log' must be renamed using export and import"
7547 cur_version
= zpool_get_prop_int(zhp
, ZPOOL_PROP_VERSION
, NULL
);
7548 if (cur_version
> cbp
->cb_version
) {
7549 (void) printf(gettext("Pool '%s' is already formatted "
7550 "using more current version '%llu'.\n\n"),
7551 zpool_get_name(zhp
), (u_longlong_t
)cur_version
);
7555 if (cbp
->cb_version
!= SPA_VERSION
&& cur_version
== cbp
->cb_version
) {
7556 (void) printf(gettext("Pool '%s' is already formatted "
7557 "using version %llu.\n\n"), zpool_get_name(zhp
),
7558 (u_longlong_t
)cbp
->cb_version
);
7562 if (cur_version
!= cbp
->cb_version
) {
7564 ret
= upgrade_version(zhp
, cbp
->cb_version
);
7569 if (cbp
->cb_version
>= SPA_VERSION_FEATURES
) {
7571 ret
= upgrade_enable_all(zhp
, &count
);
7577 } else if (cur_version
== SPA_VERSION
) {
7578 (void) printf(gettext("Pool '%s' already has all "
7579 "supported features enabled.\n"),
7580 zpool_get_name(zhp
));
7585 (void) printf(gettext("\n"));
7594 * zpool upgrade [-V version] <-a | pool ...>
7596 * With no arguments, display downrev'd ZFS pool available for upgrade.
7597 * Individual pools can be upgraded by specifying the pool, and '-a' will
7598 * upgrade all pools.
7601 zpool_do_upgrade(int argc
, char **argv
)
7604 upgrade_cbdata_t cb
= { 0 };
7606 boolean_t showversions
= B_FALSE
;
7607 boolean_t upgradeall
= B_FALSE
;
7612 while ((c
= getopt(argc
, argv
, ":avV:")) != -1) {
7615 upgradeall
= B_TRUE
;
7618 showversions
= B_TRUE
;
7621 cb
.cb_version
= strtoll(optarg
, &end
, 10);
7623 !SPA_VERSION_IS_SUPPORTED(cb
.cb_version
)) {
7624 (void) fprintf(stderr
,
7625 gettext("invalid version '%s'\n"), optarg
);
7630 (void) fprintf(stderr
, gettext("missing argument for "
7631 "'%c' option\n"), optopt
);
7635 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
7646 if (cb
.cb_version
== 0) {
7647 cb
.cb_version
= SPA_VERSION
;
7648 } else if (!upgradeall
&& argc
== 0) {
7649 (void) fprintf(stderr
, gettext("-V option is "
7650 "incompatible with other arguments\n"));
7655 if (upgradeall
|| argc
!= 0) {
7656 (void) fprintf(stderr
, gettext("-v option is "
7657 "incompatible with other arguments\n"));
7660 } else if (upgradeall
) {
7662 (void) fprintf(stderr
, gettext("-a option should not "
7663 "be used along with a pool name\n"));
7668 (void) printf(gettext("This system supports ZFS pool feature "
7673 (void) printf(gettext("The following features are "
7675 (void) printf(gettext("FEAT DESCRIPTION\n"));
7676 (void) printf("----------------------------------------------"
7677 "---------------\n");
7678 for (i
= 0; i
< SPA_FEATURES
; i
++) {
7679 zfeature_info_t
*fi
= &spa_feature_table
[i
];
7681 (fi
->fi_flags
& ZFEATURE_FLAG_READONLY_COMPAT
) ?
7682 " (read-only compatible)" : "";
7684 (void) printf("%-37s%s\n", fi
->fi_uname
, ro
);
7685 (void) printf(" %s\n", fi
->fi_desc
);
7687 (void) printf("\n");
7689 (void) printf(gettext("The following legacy versions are also "
7691 (void) printf(gettext("VER DESCRIPTION\n"));
7692 (void) printf("--- -----------------------------------------"
7693 "---------------\n");
7694 (void) printf(gettext(" 1 Initial ZFS version\n"));
7695 (void) printf(gettext(" 2 Ditto blocks "
7696 "(replicated metadata)\n"));
7697 (void) printf(gettext(" 3 Hot spares and double parity "
7699 (void) printf(gettext(" 4 zpool history\n"));
7700 (void) printf(gettext(" 5 Compression using the gzip "
7702 (void) printf(gettext(" 6 bootfs pool property\n"));
7703 (void) printf(gettext(" 7 Separate intent log devices\n"));
7704 (void) printf(gettext(" 8 Delegated administration\n"));
7705 (void) printf(gettext(" 9 refquota and refreservation "
7707 (void) printf(gettext(" 10 Cache devices\n"));
7708 (void) printf(gettext(" 11 Improved scrub performance\n"));
7709 (void) printf(gettext(" 12 Snapshot properties\n"));
7710 (void) printf(gettext(" 13 snapused property\n"));
7711 (void) printf(gettext(" 14 passthrough-x aclinherit\n"));
7712 (void) printf(gettext(" 15 user/group space accounting\n"));
7713 (void) printf(gettext(" 16 stmf property support\n"));
7714 (void) printf(gettext(" 17 Triple-parity RAID-Z\n"));
7715 (void) printf(gettext(" 18 Snapshot user holds\n"));
7716 (void) printf(gettext(" 19 Log device removal\n"));
7717 (void) printf(gettext(" 20 Compression using zle "
7718 "(zero-length encoding)\n"));
7719 (void) printf(gettext(" 21 Deduplication\n"));
7720 (void) printf(gettext(" 22 Received properties\n"));
7721 (void) printf(gettext(" 23 Slim ZIL\n"));
7722 (void) printf(gettext(" 24 System attributes\n"));
7723 (void) printf(gettext(" 25 Improved scrub stats\n"));
7724 (void) printf(gettext(" 26 Improved snapshot deletion "
7726 (void) printf(gettext(" 27 Improved snapshot creation "
7728 (void) printf(gettext(" 28 Multiple vdev replacements\n"));
7729 (void) printf(gettext("\nFor more information on a particular "
7730 "version, including supported releases,\n"));
7731 (void) printf(gettext("see the ZFS Administration Guide.\n\n"));
7732 } else if (argc
== 0 && upgradeall
) {
7733 cb
.cb_first
= B_TRUE
;
7734 ret
= zpool_iter(g_zfs
, upgrade_cb
, &cb
);
7735 if (ret
== 0 && cb
.cb_first
) {
7736 if (cb
.cb_version
== SPA_VERSION
) {
7737 (void) printf(gettext("All pools are already "
7738 "formatted using feature flags.\n\n"));
7739 (void) printf(gettext("Every feature flags "
7740 "pool already has all supported features "
7743 (void) printf(gettext("All pools are already "
7744 "formatted with version %llu or higher.\n"),
7745 (u_longlong_t
)cb
.cb_version
);
7748 } else if (argc
== 0) {
7749 cb
.cb_first
= B_TRUE
;
7750 ret
= zpool_iter(g_zfs
, upgrade_list_older_cb
, &cb
);
7754 (void) printf(gettext("All pools are formatted "
7755 "using feature flags.\n\n"));
7757 (void) printf(gettext("\nUse 'zpool upgrade -v' "
7758 "for a list of available legacy versions.\n"));
7761 cb
.cb_first
= B_TRUE
;
7762 ret
= zpool_iter(g_zfs
, upgrade_list_disabled_cb
, &cb
);
7766 (void) printf(gettext("Every feature flags pool has "
7767 "all supported features enabled.\n"));
7769 (void) printf(gettext("\n"));
7772 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
,
7779 typedef struct hist_cbdata
{
7786 * Print out the command history for a specific pool.
7789 get_history_one(zpool_handle_t
*zhp
, void *data
)
7795 hist_cbdata_t
*cb
= (hist_cbdata_t
*)data
;
7797 cb
->first
= B_FALSE
;
7799 (void) printf(gettext("History for '%s':\n"), zpool_get_name(zhp
));
7801 if ((ret
= zpool_get_history(zhp
, &nvhis
)) != 0)
7804 verify(nvlist_lookup_nvlist_array(nvhis
, ZPOOL_HIST_RECORD
,
7805 &records
, &numrecords
) == 0);
7806 for (i
= 0; i
< numrecords
; i
++) {
7807 nvlist_t
*rec
= records
[i
];
7810 if (nvlist_exists(rec
, ZPOOL_HIST_TIME
)) {
7814 tsec
= fnvlist_lookup_uint64(records
[i
],
7816 (void) localtime_r(&tsec
, &t
);
7817 (void) strftime(tbuf
, sizeof (tbuf
), "%F.%T", &t
);
7820 if (nvlist_exists(rec
, ZPOOL_HIST_CMD
)) {
7821 (void) printf("%s %s", tbuf
,
7822 fnvlist_lookup_string(rec
, ZPOOL_HIST_CMD
));
7823 } else if (nvlist_exists(rec
, ZPOOL_HIST_INT_EVENT
)) {
7825 fnvlist_lookup_uint64(rec
, ZPOOL_HIST_INT_EVENT
);
7828 if (ievent
>= ZFS_NUM_LEGACY_HISTORY_EVENTS
) {
7829 (void) printf("%s unrecognized record:\n",
7831 dump_nvlist(rec
, 4);
7834 (void) printf("%s [internal %s txg:%lld] %s", tbuf
,
7835 zfs_history_event_names
[ievent
],
7836 (longlong_t
)fnvlist_lookup_uint64(
7837 rec
, ZPOOL_HIST_TXG
),
7838 fnvlist_lookup_string(rec
, ZPOOL_HIST_INT_STR
));
7839 } else if (nvlist_exists(rec
, ZPOOL_HIST_INT_NAME
)) {
7842 (void) printf("%s [txg:%lld] %s", tbuf
,
7843 (longlong_t
)fnvlist_lookup_uint64(
7844 rec
, ZPOOL_HIST_TXG
),
7845 fnvlist_lookup_string(rec
, ZPOOL_HIST_INT_NAME
));
7846 if (nvlist_exists(rec
, ZPOOL_HIST_DSNAME
)) {
7847 (void) printf(" %s (%llu)",
7848 fnvlist_lookup_string(rec
,
7850 (u_longlong_t
)fnvlist_lookup_uint64(rec
,
7853 (void) printf(" %s", fnvlist_lookup_string(rec
,
7854 ZPOOL_HIST_INT_STR
));
7855 } else if (nvlist_exists(rec
, ZPOOL_HIST_IOCTL
)) {
7858 (void) printf("%s ioctl %s\n", tbuf
,
7859 fnvlist_lookup_string(rec
, ZPOOL_HIST_IOCTL
));
7860 if (nvlist_exists(rec
, ZPOOL_HIST_INPUT_NVL
)) {
7861 (void) printf(" input:\n");
7862 dump_nvlist(fnvlist_lookup_nvlist(rec
,
7863 ZPOOL_HIST_INPUT_NVL
), 8);
7865 if (nvlist_exists(rec
, ZPOOL_HIST_OUTPUT_NVL
)) {
7866 (void) printf(" output:\n");
7867 dump_nvlist(fnvlist_lookup_nvlist(rec
,
7868 ZPOOL_HIST_OUTPUT_NVL
), 8);
7870 if (nvlist_exists(rec
, ZPOOL_HIST_ERRNO
)) {
7871 (void) printf(" errno: %lld\n",
7872 (longlong_t
)fnvlist_lookup_int64(rec
,
7878 (void) printf("%s unrecognized record:\n", tbuf
);
7879 dump_nvlist(rec
, 4);
7883 (void) printf("\n");
7886 (void) printf(" [");
7887 if (nvlist_exists(rec
, ZPOOL_HIST_WHO
)) {
7888 uid_t who
= fnvlist_lookup_uint64(rec
, ZPOOL_HIST_WHO
);
7889 struct passwd
*pwd
= getpwuid(who
);
7890 (void) printf("user %d ", (int)who
);
7892 (void) printf("(%s) ", pwd
->pw_name
);
7894 if (nvlist_exists(rec
, ZPOOL_HIST_HOST
)) {
7895 (void) printf("on %s",
7896 fnvlist_lookup_string(rec
, ZPOOL_HIST_HOST
));
7898 if (nvlist_exists(rec
, ZPOOL_HIST_ZONE
)) {
7899 (void) printf(":%s",
7900 fnvlist_lookup_string(rec
, ZPOOL_HIST_ZONE
));
7904 (void) printf("\n");
7906 (void) printf("\n");
7913 * zpool history <pool>
7915 * Displays the history of commands that modified pools.
7918 zpool_do_history(int argc
, char **argv
)
7920 hist_cbdata_t cbdata
= { 0 };
7924 cbdata
.first
= B_TRUE
;
7926 while ((c
= getopt(argc
, argv
, "li")) != -1) {
7929 cbdata
.longfmt
= B_TRUE
;
7932 cbdata
.internal
= B_TRUE
;
7935 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
7943 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
, get_history_one
,
7946 if (argc
== 0 && cbdata
.first
== B_TRUE
) {
7947 (void) fprintf(stderr
, gettext("no pools available\n"));
7954 typedef struct ev_opts
{
7959 char poolname
[ZFS_MAX_DATASET_NAME_LEN
];
7963 zpool_do_events_short(nvlist_t
*nvl
, ev_opts_t
*opts
)
7965 char ctime_str
[26], str
[32], *ptr
;
7969 verify(nvlist_lookup_int64_array(nvl
, FM_EREPORT_TIME
, &tv
, &n
) == 0);
7970 memset(str
, ' ', 32);
7971 (void) ctime_r((const time_t *)&tv
[0], ctime_str
);
7972 (void) strncpy(str
, ctime_str
+4, 6); /* 'Jun 30' */
7973 (void) strncpy(str
+7, ctime_str
+20, 4); /* '1993' */
7974 (void) strncpy(str
+12, ctime_str
+11, 8); /* '21:49:08' */
7975 (void) sprintf(str
+20, ".%09lld", (longlong_t
)tv
[1]); /* '.123456789' */
7977 (void) printf(gettext("%s\t"), str
);
7979 (void) printf(gettext("%s "), str
);
7981 verify(nvlist_lookup_string(nvl
, FM_CLASS
, &ptr
) == 0);
7982 (void) printf(gettext("%s\n"), ptr
);
7986 zpool_do_events_nvprint(nvlist_t
*nvl
, int depth
)
7990 for (nvp
= nvlist_next_nvpair(nvl
, NULL
);
7991 nvp
!= NULL
; nvp
= nvlist_next_nvpair(nvl
, nvp
)) {
7993 data_type_t type
= nvpair_type(nvp
);
7994 const char *name
= nvpair_name(nvp
);
8004 printf(gettext("%*s%s = "), depth
, "", name
);
8007 case DATA_TYPE_BOOLEAN
:
8008 printf(gettext("%s"), "1");
8011 case DATA_TYPE_BOOLEAN_VALUE
:
8012 (void) nvpair_value_boolean_value(nvp
, &b
);
8013 printf(gettext("%s"), b
? "1" : "0");
8016 case DATA_TYPE_BYTE
:
8017 (void) nvpair_value_byte(nvp
, &i8
);
8018 printf(gettext("0x%x"), i8
);
8021 case DATA_TYPE_INT8
:
8022 (void) nvpair_value_int8(nvp
, (void *)&i8
);
8023 printf(gettext("0x%x"), i8
);
8026 case DATA_TYPE_UINT8
:
8027 (void) nvpair_value_uint8(nvp
, &i8
);
8028 printf(gettext("0x%x"), i8
);
8031 case DATA_TYPE_INT16
:
8032 (void) nvpair_value_int16(nvp
, (void *)&i16
);
8033 printf(gettext("0x%x"), i16
);
8036 case DATA_TYPE_UINT16
:
8037 (void) nvpair_value_uint16(nvp
, &i16
);
8038 printf(gettext("0x%x"), i16
);
8041 case DATA_TYPE_INT32
:
8042 (void) nvpair_value_int32(nvp
, (void *)&i32
);
8043 printf(gettext("0x%x"), i32
);
8046 case DATA_TYPE_UINT32
:
8047 (void) nvpair_value_uint32(nvp
, &i32
);
8048 printf(gettext("0x%x"), i32
);
8051 case DATA_TYPE_INT64
:
8052 (void) nvpair_value_int64(nvp
, (void *)&i64
);
8053 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
8056 case DATA_TYPE_UINT64
:
8057 (void) nvpair_value_uint64(nvp
, &i64
);
8059 * translate vdev state values to readable
8060 * strings to aide zpool events consumers
8063 FM_EREPORT_PAYLOAD_ZFS_VDEV_STATE
) == 0 ||
8065 FM_EREPORT_PAYLOAD_ZFS_VDEV_LASTSTATE
) == 0) {
8066 printf(gettext("\"%s\" (0x%llx)"),
8067 zpool_state_to_name(i64
, VDEV_AUX_NONE
),
8070 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
8074 case DATA_TYPE_HRTIME
:
8075 (void) nvpair_value_hrtime(nvp
, (void *)&i64
);
8076 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
8079 case DATA_TYPE_STRING
:
8080 (void) nvpair_value_string(nvp
, &str
);
8081 printf(gettext("\"%s\""), str
? str
: "<NULL>");
8084 case DATA_TYPE_NVLIST
:
8085 printf(gettext("(embedded nvlist)\n"));
8086 (void) nvpair_value_nvlist(nvp
, &cnv
);
8087 zpool_do_events_nvprint(cnv
, depth
+ 8);
8088 printf(gettext("%*s(end %s)"), depth
, "", name
);
8091 case DATA_TYPE_NVLIST_ARRAY
: {
8095 (void) nvpair_value_nvlist_array(nvp
, &val
, &nelem
);
8096 printf(gettext("(%d embedded nvlists)\n"), nelem
);
8097 for (i
= 0; i
< nelem
; i
++) {
8098 printf(gettext("%*s%s[%d] = %s\n"),
8099 depth
, "", name
, i
, "(embedded nvlist)");
8100 zpool_do_events_nvprint(val
[i
], depth
+ 8);
8101 printf(gettext("%*s(end %s[%i])\n"),
8102 depth
, "", name
, i
);
8104 printf(gettext("%*s(end %s)\n"), depth
, "", name
);
8108 case DATA_TYPE_INT8_ARRAY
: {
8112 (void) nvpair_value_int8_array(nvp
, &val
, &nelem
);
8113 for (i
= 0; i
< nelem
; i
++)
8114 printf(gettext("0x%x "), val
[i
]);
8119 case DATA_TYPE_UINT8_ARRAY
: {
8123 (void) nvpair_value_uint8_array(nvp
, &val
, &nelem
);
8124 for (i
= 0; i
< nelem
; i
++)
8125 printf(gettext("0x%x "), val
[i
]);
8130 case DATA_TYPE_INT16_ARRAY
: {
8134 (void) nvpair_value_int16_array(nvp
, &val
, &nelem
);
8135 for (i
= 0; i
< nelem
; i
++)
8136 printf(gettext("0x%x "), val
[i
]);
8141 case DATA_TYPE_UINT16_ARRAY
: {
8145 (void) nvpair_value_uint16_array(nvp
, &val
, &nelem
);
8146 for (i
= 0; i
< nelem
; i
++)
8147 printf(gettext("0x%x "), val
[i
]);
8152 case DATA_TYPE_INT32_ARRAY
: {
8156 (void) nvpair_value_int32_array(nvp
, &val
, &nelem
);
8157 for (i
= 0; i
< nelem
; i
++)
8158 printf(gettext("0x%x "), val
[i
]);
8163 case DATA_TYPE_UINT32_ARRAY
: {
8167 (void) nvpair_value_uint32_array(nvp
, &val
, &nelem
);
8168 for (i
= 0; i
< nelem
; i
++)
8169 printf(gettext("0x%x "), val
[i
]);
8174 case DATA_TYPE_INT64_ARRAY
: {
8178 (void) nvpair_value_int64_array(nvp
, &val
, &nelem
);
8179 for (i
= 0; i
< nelem
; i
++)
8180 printf(gettext("0x%llx "),
8181 (u_longlong_t
)val
[i
]);
8186 case DATA_TYPE_UINT64_ARRAY
: {
8190 (void) nvpair_value_uint64_array(nvp
, &val
, &nelem
);
8191 for (i
= 0; i
< nelem
; i
++)
8192 printf(gettext("0x%llx "),
8193 (u_longlong_t
)val
[i
]);
8198 case DATA_TYPE_STRING_ARRAY
: {
8202 (void) nvpair_value_string_array(nvp
, &str
, &nelem
);
8203 for (i
= 0; i
< nelem
; i
++)
8204 printf(gettext("\"%s\" "),
8205 str
[i
] ? str
[i
] : "<NULL>");
8210 case DATA_TYPE_BOOLEAN_ARRAY
:
8211 case DATA_TYPE_BYTE_ARRAY
:
8212 case DATA_TYPE_DOUBLE
:
8213 case DATA_TYPE_DONTCARE
:
8214 case DATA_TYPE_UNKNOWN
:
8215 printf(gettext("<unknown>"));
8219 printf(gettext("\n"));
8224 zpool_do_events_next(ev_opts_t
*opts
)
8227 int zevent_fd
, ret
, dropped
;
8230 zevent_fd
= open(ZFS_DEV
, O_RDWR
);
8231 VERIFY(zevent_fd
>= 0);
8233 if (!opts
->scripted
)
8234 (void) printf(gettext("%-30s %s\n"), "TIME", "CLASS");
8237 ret
= zpool_events_next(g_zfs
, &nvl
, &dropped
,
8238 (opts
->follow
? ZEVENT_NONE
: ZEVENT_NONBLOCK
), zevent_fd
);
8239 if (ret
|| nvl
== NULL
)
8243 (void) printf(gettext("dropped %d events\n"), dropped
);
8245 if (strlen(opts
->poolname
) > 0 &&
8246 nvlist_lookup_string(nvl
, FM_FMRI_ZFS_POOL
, &pool
) == 0 &&
8247 strcmp(opts
->poolname
, pool
) != 0)
8250 zpool_do_events_short(nvl
, opts
);
8252 if (opts
->verbose
) {
8253 zpool_do_events_nvprint(nvl
, 8);
8254 printf(gettext("\n"));
8256 (void) fflush(stdout
);
8261 VERIFY(0 == close(zevent_fd
));
8267 zpool_do_events_clear(ev_opts_t
*opts
)
8271 ret
= zpool_events_clear(g_zfs
, &count
);
8273 (void) printf(gettext("cleared %d events\n"), count
);
8279 * zpool events [-vHf [pool] | -c]
8281 * Displays events logs by ZFS.
8284 zpool_do_events(int argc
, char **argv
)
8286 ev_opts_t opts
= { 0 };
8291 while ((c
= getopt(argc
, argv
, "vHfc")) != -1) {
8306 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
8315 (void) fprintf(stderr
, gettext("too many arguments\n"));
8317 } else if (argc
== 1) {
8318 (void) strlcpy(opts
.poolname
, argv
[0], sizeof (opts
.poolname
));
8319 if (!zfs_name_valid(opts
.poolname
, ZFS_TYPE_POOL
)) {
8320 (void) fprintf(stderr
,
8321 gettext("invalid pool name '%s'\n"), opts
.poolname
);
8326 if ((argc
== 1 || opts
.verbose
|| opts
.scripted
|| opts
.follow
) &&
8328 (void) fprintf(stderr
,
8329 gettext("invalid options combined with -c\n"));
8334 ret
= zpool_do_events_clear(&opts
);
8336 ret
= zpool_do_events_next(&opts
);
8342 get_callback(zpool_handle_t
*zhp
, void *data
)
8344 zprop_get_cbdata_t
*cbp
= (zprop_get_cbdata_t
*)data
;
8345 char value
[MAXNAMELEN
];
8346 zprop_source_t srctype
;
8349 for (pl
= cbp
->cb_proplist
; pl
!= NULL
; pl
= pl
->pl_next
) {
8352 * Skip the special fake placeholder. This will also skip
8353 * over the name property when 'all' is specified.
8355 if (pl
->pl_prop
== ZPOOL_PROP_NAME
&&
8356 pl
== cbp
->cb_proplist
)
8359 if (pl
->pl_prop
== ZPROP_INVAL
&&
8360 (zpool_prop_feature(pl
->pl_user_prop
) ||
8361 zpool_prop_unsupported(pl
->pl_user_prop
))) {
8362 srctype
= ZPROP_SRC_LOCAL
;
8364 if (zpool_prop_get_feature(zhp
, pl
->pl_user_prop
,
8365 value
, sizeof (value
)) == 0) {
8366 zprop_print_one_property(zpool_get_name(zhp
),
8367 cbp
, pl
->pl_user_prop
, value
, srctype
,
8371 if (zpool_get_prop(zhp
, pl
->pl_prop
, value
,
8372 sizeof (value
), &srctype
, cbp
->cb_literal
) != 0)
8375 zprop_print_one_property(zpool_get_name(zhp
), cbp
,
8376 zpool_prop_to_name(pl
->pl_prop
), value
, srctype
,
8384 * zpool get [-Hp] [-o "all" | field[,...]] <"all" | property[,...]> <pool> ...
8386 * -H Scripted mode. Don't display headers, and separate properties
8388 * -o List of columns to display. Defaults to
8389 * "name,property,value,source".
8390 * -p Display values in parsable (exact) format.
8392 * Get properties of pools in the system. Output space statistics
8393 * for each one as well as other attributes.
8396 zpool_do_get(int argc
, char **argv
)
8398 zprop_get_cbdata_t cb
= { 0 };
8399 zprop_list_t fake_name
= { 0 };
8404 cb
.cb_first
= B_TRUE
;
8407 * Set up default columns and sources.
8409 cb
.cb_sources
= ZPROP_SRC_ALL
;
8410 cb
.cb_columns
[0] = GET_COL_NAME
;
8411 cb
.cb_columns
[1] = GET_COL_PROPERTY
;
8412 cb
.cb_columns
[2] = GET_COL_VALUE
;
8413 cb
.cb_columns
[3] = GET_COL_SOURCE
;
8414 cb
.cb_type
= ZFS_TYPE_POOL
;
8417 while ((c
= getopt(argc
, argv
, ":Hpo:")) != -1) {
8420 cb
.cb_literal
= B_TRUE
;
8423 cb
.cb_scripted
= B_TRUE
;
8426 bzero(&cb
.cb_columns
, sizeof (cb
.cb_columns
));
8428 while (*optarg
!= '\0') {
8429 static char *col_subopts
[] =
8430 { "name", "property", "value", "source",
8433 if (i
== ZFS_GET_NCOLS
) {
8434 (void) fprintf(stderr
, gettext("too "
8435 "many fields given to -o "
8440 switch (getsubopt(&optarg
, col_subopts
,
8443 cb
.cb_columns
[i
++] = GET_COL_NAME
;
8446 cb
.cb_columns
[i
++] = GET_COL_PROPERTY
;
8449 cb
.cb_columns
[i
++] = GET_COL_VALUE
;
8452 cb
.cb_columns
[i
++] = GET_COL_SOURCE
;
8456 (void) fprintf(stderr
,
8457 gettext("\"all\" conflicts "
8458 "with specific fields "
8459 "given to -o option\n"));
8462 cb
.cb_columns
[0] = GET_COL_NAME
;
8463 cb
.cb_columns
[1] = GET_COL_PROPERTY
;
8464 cb
.cb_columns
[2] = GET_COL_VALUE
;
8465 cb
.cb_columns
[3] = GET_COL_SOURCE
;
8469 (void) fprintf(stderr
,
8470 gettext("invalid column name "
8477 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
8487 (void) fprintf(stderr
, gettext("missing property "
8492 if (zprop_get_list(g_zfs
, argv
[0], &cb
.cb_proplist
,
8493 ZFS_TYPE_POOL
) != 0)
8499 if (cb
.cb_proplist
!= NULL
) {
8500 fake_name
.pl_prop
= ZPOOL_PROP_NAME
;
8501 fake_name
.pl_width
= strlen(gettext("NAME"));
8502 fake_name
.pl_next
= cb
.cb_proplist
;
8503 cb
.cb_proplist
= &fake_name
;
8506 ret
= for_each_pool(argc
, argv
, B_TRUE
, &cb
.cb_proplist
,
8509 if (cb
.cb_proplist
== &fake_name
)
8510 zprop_free_list(fake_name
.pl_next
);
8512 zprop_free_list(cb
.cb_proplist
);
8517 typedef struct set_cbdata
{
8520 boolean_t cb_any_successful
;
8524 set_callback(zpool_handle_t
*zhp
, void *data
)
8527 set_cbdata_t
*cb
= (set_cbdata_t
*)data
;
8529 error
= zpool_set_prop(zhp
, cb
->cb_propname
, cb
->cb_value
);
8532 cb
->cb_any_successful
= B_TRUE
;
8538 zpool_do_set(int argc
, char **argv
)
8540 set_cbdata_t cb
= { 0 };
8543 if (argc
> 1 && argv
[1][0] == '-') {
8544 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
8550 (void) fprintf(stderr
, gettext("missing property=value "
8556 (void) fprintf(stderr
, gettext("missing pool name\n"));
8561 (void) fprintf(stderr
, gettext("too many pool names\n"));
8565 cb
.cb_propname
= argv
[1];
8566 cb
.cb_value
= strchr(cb
.cb_propname
, '=');
8567 if (cb
.cb_value
== NULL
) {
8568 (void) fprintf(stderr
, gettext("missing value in "
8569 "property=value argument\n"));
8573 *(cb
.cb_value
) = '\0';
8576 error
= for_each_pool(argc
- 2, argv
+ 2, B_TRUE
, NULL
,
8583 find_command_idx(char *command
, int *idx
)
8587 for (i
= 0; i
< NCOMMAND
; i
++) {
8588 if (command_table
[i
].name
== NULL
)
8591 if (strcmp(command
, command_table
[i
].name
) == 0) {
8600 main(int argc
, char **argv
)
8607 (void) setlocale(LC_ALL
, "");
8608 (void) textdomain(TEXT_DOMAIN
);
8614 * Make sure the user has specified some command.
8617 (void) fprintf(stderr
, gettext("missing command\n"));
8626 if ((strcmp(cmdname
, "-?") == 0) || strcmp(cmdname
, "--help") == 0)
8629 if ((g_zfs
= libzfs_init()) == NULL
) {
8630 (void) fprintf(stderr
, "%s", libzfs_error_init(errno
));
8634 libzfs_print_on_error(g_zfs
, B_TRUE
);
8636 zfs_save_arguments(argc
, argv
, history_str
, sizeof (history_str
));
8639 * Many commands modify input strings for string parsing reasons.
8640 * We create a copy to protect the original argv.
8642 newargv
= malloc((argc
+ 1) * sizeof (newargv
[0]));
8643 for (i
= 0; i
< argc
; i
++)
8644 newargv
[i
] = strdup(argv
[i
]);
8645 newargv
[argc
] = NULL
;
8648 * Run the appropriate command.
8650 if (find_command_idx(cmdname
, &i
) == 0) {
8651 current_command
= &command_table
[i
];
8652 ret
= command_table
[i
].func(argc
- 1, newargv
+ 1);
8653 } else if (strchr(cmdname
, '=')) {
8654 verify(find_command_idx("set", &i
) == 0);
8655 current_command
= &command_table
[i
];
8656 ret
= command_table
[i
].func(argc
, newargv
);
8657 } else if (strcmp(cmdname
, "freeze") == 0 && argc
== 3) {
8659 * 'freeze' is a vile debugging abomination, so we treat
8662 zfs_cmd_t zc
= {"\0"};
8664 (void) strlcpy(zc
.zc_name
, argv
[2], sizeof (zc
.zc_name
));
8665 ret
= zfs_ioctl(g_zfs
, ZFS_IOC_POOL_FREEZE
, &zc
);
8667 (void) fprintf(stderr
,
8668 gettext("failed to freeze pool: %d\n"), errno
);
8674 (void) fprintf(stderr
, gettext("unrecognized "
8675 "command '%s'\n"), cmdname
);
8680 for (i
= 0; i
< argc
; i
++)
8684 if (ret
== 0 && log_history
)
8685 (void) zpool_log_history(g_zfs
, history_str
);
8690 * The 'ZFS_ABORT' environment variable causes us to dump core on exit
8691 * for the purposes of running ::findleaks.
8693 if (getenv("ZFS_ABORT") != NULL
) {
8694 (void) printf("dumping core by request\n");