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, 2015 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.
49 #include <sys/fs/zfs.h>
51 #include <sys/fm/util.h>
52 #include <sys/fm/protocol.h>
53 #include <sys/zfs_ioctl.h>
58 #include "zpool_util.h"
59 #include "zfs_comutil.h"
60 #include "zfeature_common.h"
62 #include "statcommon.h"
64 static int zpool_do_create(int, char **);
65 static int zpool_do_destroy(int, char **);
67 static int zpool_do_add(int, char **);
68 static int zpool_do_remove(int, char **);
69 static int zpool_do_labelclear(int, char **);
71 static int zpool_do_list(int, char **);
72 static int zpool_do_iostat(int, char **);
73 static int zpool_do_status(int, char **);
75 static int zpool_do_online(int, char **);
76 static int zpool_do_offline(int, char **);
77 static int zpool_do_clear(int, char **);
78 static int zpool_do_reopen(int, char **);
80 static int zpool_do_reguid(int, char **);
82 static int zpool_do_attach(int, char **);
83 static int zpool_do_detach(int, char **);
84 static int zpool_do_replace(int, char **);
85 static int zpool_do_split(int, char **);
87 static int zpool_do_scrub(int, char **);
89 static int zpool_do_import(int, char **);
90 static int zpool_do_export(int, char **);
92 static int zpool_do_upgrade(int, char **);
94 static int zpool_do_history(int, char **);
95 static int zpool_do_events(int, char **);
97 static int zpool_do_get(int, char **);
98 static int zpool_do_set(int, char **);
101 * These libumem hooks provide a reasonable set of defaults for the allocator's
102 * debugging facilities.
107 _umem_debug_init(void)
109 return ("default,verbose"); /* $UMEM_DEBUG setting */
113 _umem_logging_init(void)
115 return ("fail,contents"); /* $UMEM_LOGGING setting */
149 * Flags for stats to display with "zpool iostats"
157 IOS_COUNT
, /* always last element */
160 /* iostat_type entries as bitmasks */
161 #define IOS_DEFAULT_M (1ULL << IOS_DEFAULT)
162 #define IOS_LATENCY_M (1ULL << IOS_LATENCY)
163 #define IOS_QUEUES_M (1ULL << IOS_QUEUES)
164 #define IOS_L_HISTO_M (1ULL << IOS_L_HISTO)
165 #define IOS_RQ_HISTO_M (1ULL << IOS_RQ_HISTO)
167 /* Mask of all the histo bits */
168 #define IOS_ANYHISTO_M (IOS_L_HISTO_M | IOS_RQ_HISTO_M)
171 * Lookup table for iostat flags to nvlist names. Basically a list
172 * of all the nvlists a flag requires. Also specifies the order in
173 * which data gets printed in zpool iostat.
175 static const char *vsx_type_to_nvlist
[IOS_COUNT
][11] = {
177 ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO
,
178 ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO
,
179 ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO
,
180 ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO
,
181 ZPOOL_CONFIG_VDEV_SYNC_R_LAT_HISTO
,
182 ZPOOL_CONFIG_VDEV_SYNC_W_LAT_HISTO
,
183 ZPOOL_CONFIG_VDEV_ASYNC_R_LAT_HISTO
,
184 ZPOOL_CONFIG_VDEV_ASYNC_W_LAT_HISTO
,
185 ZPOOL_CONFIG_VDEV_SCRUB_LAT_HISTO
,
188 ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO
,
189 ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO
,
190 ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO
,
191 ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO
,
194 ZPOOL_CONFIG_VDEV_SYNC_R_ACTIVE_QUEUE
,
195 ZPOOL_CONFIG_VDEV_SYNC_W_ACTIVE_QUEUE
,
196 ZPOOL_CONFIG_VDEV_ASYNC_R_ACTIVE_QUEUE
,
197 ZPOOL_CONFIG_VDEV_ASYNC_W_ACTIVE_QUEUE
,
198 ZPOOL_CONFIG_VDEV_SCRUB_ACTIVE_QUEUE
,
201 ZPOOL_CONFIG_VDEV_SYNC_IND_R_HISTO
,
202 ZPOOL_CONFIG_VDEV_SYNC_AGG_R_HISTO
,
203 ZPOOL_CONFIG_VDEV_SYNC_IND_W_HISTO
,
204 ZPOOL_CONFIG_VDEV_SYNC_AGG_W_HISTO
,
205 ZPOOL_CONFIG_VDEV_ASYNC_IND_R_HISTO
,
206 ZPOOL_CONFIG_VDEV_ASYNC_AGG_R_HISTO
,
207 ZPOOL_CONFIG_VDEV_ASYNC_IND_W_HISTO
,
208 ZPOOL_CONFIG_VDEV_ASYNC_AGG_W_HISTO
,
209 ZPOOL_CONFIG_VDEV_IND_SCRUB_HISTO
,
210 ZPOOL_CONFIG_VDEV_AGG_SCRUB_HISTO
,
216 * Given a cb->cb_flags with a histogram bit set, return the iostat_type.
217 * Right now, only one histo bit is ever set at one time, so we can
218 * just do a highbit64(a)
220 #define IOS_HISTO_IDX(a) (highbit64(a & IOS_ANYHISTO_M) - 1)
222 typedef struct zpool_command
{
224 int (*func
)(int, char **);
229 * Master command table. Each ZFS command has a name, associated function, and
230 * usage message. The usage messages need to be internationalized, so we have
231 * to have a function to return the usage message based on a command index.
233 * These commands are organized according to how they are displayed in the usage
234 * message. An empty command (one with a NULL name) indicates an empty line in
235 * the generic usage message.
237 static zpool_command_t command_table
[] = {
238 { "create", zpool_do_create
, HELP_CREATE
},
239 { "destroy", zpool_do_destroy
, HELP_DESTROY
},
241 { "add", zpool_do_add
, HELP_ADD
},
242 { "remove", zpool_do_remove
, HELP_REMOVE
},
244 { "labelclear", zpool_do_labelclear
, HELP_LABELCLEAR
},
246 { "list", zpool_do_list
, HELP_LIST
},
247 { "iostat", zpool_do_iostat
, HELP_IOSTAT
},
248 { "status", zpool_do_status
, HELP_STATUS
},
250 { "online", zpool_do_online
, HELP_ONLINE
},
251 { "offline", zpool_do_offline
, HELP_OFFLINE
},
252 { "clear", zpool_do_clear
, HELP_CLEAR
},
253 { "reopen", zpool_do_reopen
, HELP_REOPEN
},
255 { "attach", zpool_do_attach
, HELP_ATTACH
},
256 { "detach", zpool_do_detach
, HELP_DETACH
},
257 { "replace", zpool_do_replace
, HELP_REPLACE
},
258 { "split", zpool_do_split
, HELP_SPLIT
},
260 { "scrub", zpool_do_scrub
, HELP_SCRUB
},
262 { "import", zpool_do_import
, HELP_IMPORT
},
263 { "export", zpool_do_export
, HELP_EXPORT
},
264 { "upgrade", zpool_do_upgrade
, HELP_UPGRADE
},
265 { "reguid", zpool_do_reguid
, HELP_REGUID
},
267 { "history", zpool_do_history
, HELP_HISTORY
},
268 { "events", zpool_do_events
, HELP_EVENTS
},
270 { "get", zpool_do_get
, HELP_GET
},
271 { "set", zpool_do_set
, HELP_SET
},
274 #define NCOMMAND (ARRAY_SIZE(command_table))
276 static zpool_command_t
*current_command
;
277 static char history_str
[HIS_MAX_RECORD_LEN
];
278 static boolean_t log_history
= B_TRUE
;
279 static uint_t timestamp_fmt
= NODATE
;
282 get_usage(zpool_help_t idx
) {
285 return (gettext("\tadd [-fgLnP] [-o property=value] "
286 "<pool> <vdev> ...\n"));
288 return (gettext("\tattach [-f] [-o property=value] "
289 "<pool> <device> <new-device>\n"));
291 return (gettext("\tclear [-nF] <pool> [device]\n"));
293 return (gettext("\tcreate [-fnd] [-o property=value] ... \n"
294 "\t [-O file-system-property=value] ... \n"
295 "\t [-m mountpoint] [-R root] <pool> <vdev> ...\n"));
297 return (gettext("\tdestroy [-f] <pool>\n"));
299 return (gettext("\tdetach <pool> <device>\n"));
301 return (gettext("\texport [-af] <pool> ...\n"));
303 return (gettext("\thistory [-il] [<pool>] ...\n"));
305 return (gettext("\timport [-d dir] [-D]\n"
306 "\timport [-d dir | -c cachefile] [-F [-n]] <pool | id>\n"
307 "\timport [-o mntopts] [-o property=value] ... \n"
308 "\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
309 "[-R root] [-F [-n]] -a\n"
310 "\timport [-o mntopts] [-o property=value] ... \n"
311 "\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
312 "[-R root] [-F [-n]]\n"
313 "\t <pool | id> [newpool]\n"));
315 return (gettext("\tiostat [-T d | u] [-ghHLpPvy] "
317 "\t [[pool ...]|[pool vdev ...]|[vdev ...]] "
318 "[interval [count]]\n"));
319 case HELP_LABELCLEAR
:
320 return (gettext("\tlabelclear [-f] <vdev>\n"));
322 return (gettext("\tlist [-gHLpPv] [-o property[,...]] "
323 "[-T d|u] [pool] ... [interval [count]]\n"));
325 return (gettext("\toffline [-t] <pool> <device> ...\n"));
327 return (gettext("\tonline <pool> <device> ...\n"));
329 return (gettext("\treplace [-f] [-o property=value] "
330 "<pool> <device> [new-device]\n"));
332 return (gettext("\tremove <pool> <device> ...\n"));
334 return (gettext("\treopen <pool>\n"));
336 return (gettext("\tscrub [-s] <pool> ...\n"));
338 return (gettext("\tstatus [-gLPvxD] [-T d|u] [pool] ... "
339 "[interval [count]]\n"));
341 return (gettext("\tupgrade\n"
343 "\tupgrade [-V version] <-a | pool ...>\n"));
345 return (gettext("\tevents [-vHfc]\n"));
347 return (gettext("\tget [-Hp] [-o \"all\" | field[,...]] "
348 "<\"all\" | property[,...]> <pool> ...\n"));
350 return (gettext("\tset <property=value> <pool> \n"));
352 return (gettext("\tsplit [-gLnP] [-R altroot] [-o mntopts]\n"
353 "\t [-o property=value] <pool> <newpool> "
354 "[<device> ...]\n"));
356 return (gettext("\treguid <pool>\n"));
365 * Callback routine that will print out a pool property value.
368 print_prop_cb(int prop
, void *cb
)
372 (void) fprintf(fp
, "\t%-15s ", zpool_prop_to_name(prop
));
374 if (zpool_prop_readonly(prop
))
375 (void) fprintf(fp
, " NO ");
377 (void) fprintf(fp
, " YES ");
379 if (zpool_prop_values(prop
) == NULL
)
380 (void) fprintf(fp
, "-\n");
382 (void) fprintf(fp
, "%s\n", zpool_prop_values(prop
));
388 * Display usage message. If we're inside a command, display only the usage for
389 * that command. Otherwise, iterate over the entire command table and display
390 * a complete usage message.
393 usage(boolean_t requested
)
395 FILE *fp
= requested
? stdout
: stderr
;
397 if (current_command
== NULL
) {
400 (void) fprintf(fp
, gettext("usage: zpool command args ...\n"));
402 gettext("where 'command' is one of the following:\n\n"));
404 for (i
= 0; i
< NCOMMAND
; i
++) {
405 if (command_table
[i
].name
== NULL
)
406 (void) fprintf(fp
, "\n");
408 (void) fprintf(fp
, "%s",
409 get_usage(command_table
[i
].usage
));
412 (void) fprintf(fp
, gettext("usage:\n"));
413 (void) fprintf(fp
, "%s", get_usage(current_command
->usage
));
416 if (current_command
!= NULL
&&
417 ((strcmp(current_command
->name
, "set") == 0) ||
418 (strcmp(current_command
->name
, "get") == 0) ||
419 (strcmp(current_command
->name
, "list") == 0))) {
422 gettext("\nthe following properties are supported:\n"));
424 (void) fprintf(fp
, "\n\t%-15s %s %s\n\n",
425 "PROPERTY", "EDIT", "VALUES");
427 /* Iterate over all properties */
428 (void) zprop_iter(print_prop_cb
, fp
, B_FALSE
, B_TRUE
,
431 (void) fprintf(fp
, "\t%-15s ", "feature@...");
432 (void) fprintf(fp
, "YES disabled | enabled | active\n");
434 (void) fprintf(fp
, gettext("\nThe feature@ properties must be "
435 "appended with a feature name.\nSee zpool-features(5).\n"));
439 * See comments at end of main().
441 if (getenv("ZFS_ABORT") != NULL
) {
442 (void) printf("dumping core by request\n");
446 exit(requested
? 0 : 2);
450 print_vdev_tree(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
, int indent
,
451 boolean_t print_logs
, int name_flags
)
458 (void) printf("\t%*s%s\n", indent
, "", name
);
460 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
461 &child
, &children
) != 0)
464 for (c
= 0; c
< children
; c
++) {
465 uint64_t is_log
= B_FALSE
;
467 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
469 if ((is_log
&& !print_logs
) || (!is_log
&& print_logs
))
472 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], name_flags
);
473 print_vdev_tree(zhp
, vname
, child
[c
], indent
+ 2,
474 B_FALSE
, name_flags
);
480 prop_list_contains_feature(nvlist_t
*proplist
)
483 for (nvp
= nvlist_next_nvpair(proplist
, NULL
); NULL
!= nvp
;
484 nvp
= nvlist_next_nvpair(proplist
, nvp
)) {
485 if (zpool_prop_feature(nvpair_name(nvp
)))
492 * Add a property pair (name, string-value) into a property nvlist.
495 add_prop_list(const char *propname
, char *propval
, nvlist_t
**props
,
498 zpool_prop_t prop
= ZPROP_INVAL
;
504 if (*props
== NULL
&&
505 nvlist_alloc(props
, NV_UNIQUE_NAME
, 0) != 0) {
506 (void) fprintf(stderr
,
507 gettext("internal error: out of memory\n"));
514 const char *vname
= zpool_prop_to_name(ZPOOL_PROP_VERSION
);
516 if ((prop
= zpool_name_to_prop(propname
)) == ZPROP_INVAL
&&
517 !zpool_prop_feature(propname
)) {
518 (void) fprintf(stderr
, gettext("property '%s' is "
519 "not a valid pool property\n"), propname
);
524 * feature@ properties and version should not be specified
527 if ((prop
== ZPROP_INVAL
&& zpool_prop_feature(propname
) &&
528 nvlist_exists(proplist
, vname
)) ||
529 (prop
== ZPOOL_PROP_VERSION
&&
530 prop_list_contains_feature(proplist
))) {
531 (void) fprintf(stderr
, gettext("'feature@' and "
532 "'version' properties cannot be specified "
538 if (zpool_prop_feature(propname
))
541 normnm
= zpool_prop_to_name(prop
);
543 if ((fprop
= zfs_name_to_prop(propname
)) != ZPROP_INVAL
) {
544 normnm
= zfs_prop_to_name(fprop
);
550 if (nvlist_lookup_string(proplist
, normnm
, &strval
) == 0 &&
551 prop
!= ZPOOL_PROP_CACHEFILE
) {
552 (void) fprintf(stderr
, gettext("property '%s' "
553 "specified multiple times\n"), propname
);
557 if (nvlist_add_string(proplist
, normnm
, propval
) != 0) {
558 (void) fprintf(stderr
, gettext("internal "
559 "error: out of memory\n"));
567 * Set a default property pair (name, string-value) in a property nvlist
570 add_prop_list_default(const char *propname
, char *propval
, nvlist_t
**props
,
575 if (nvlist_lookup_string(*props
, propname
, &pval
) == 0)
578 return (add_prop_list(propname
, propval
, props
, B_TRUE
));
582 * zpool add [-fgLnP] [-o property=value] <pool> <vdev> ...
584 * -f Force addition of devices, even if they appear in use
585 * -g Display guid for individual vdev name.
586 * -L Follow links when resolving vdev path name.
587 * -n Do not add the devices, but display the resulting layout if
588 * they were to be added.
589 * -o Set property=value.
590 * -P Display full path for vdev name.
592 * Adds the given vdevs to 'pool'. As with create, the bulk of this work is
593 * handled by get_vdev_spec(), which constructs the nvlist needed to pass to
597 zpool_do_add(int argc
, char **argv
)
599 boolean_t force
= B_FALSE
;
600 boolean_t dryrun
= B_FALSE
;
608 nvlist_t
*props
= NULL
;
612 while ((c
= getopt(argc
, argv
, "fgLno:P")) != -1) {
618 name_flags
|= VDEV_NAME_GUID
;
621 name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
627 if ((propval
= strchr(optarg
, '=')) == NULL
) {
628 (void) fprintf(stderr
, gettext("missing "
629 "'=' for -o option\n"));
635 if ((strcmp(optarg
, ZPOOL_CONFIG_ASHIFT
) != 0) ||
636 (add_prop_list(optarg
, propval
, &props
, B_TRUE
)))
640 name_flags
|= VDEV_NAME_PATH
;
643 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
652 /* get pool name and check number of arguments */
654 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
658 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
667 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
670 if ((config
= zpool_get_config(zhp
, NULL
)) == NULL
) {
671 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
677 /* pass off to get_vdev_spec for processing */
678 nvroot
= make_root_vdev(zhp
, props
, force
, !force
, B_FALSE
, dryrun
,
680 if (nvroot
== NULL
) {
686 nvlist_t
*poolnvroot
;
688 uint_t l2children
, c
;
690 boolean_t hadcache
= B_FALSE
;
692 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
695 (void) printf(gettext("would update '%s' to the following "
696 "configuration:\n"), zpool_get_name(zhp
));
698 /* print original main pool and new tree */
699 print_vdev_tree(zhp
, poolname
, poolnvroot
, 0, B_FALSE
,
701 print_vdev_tree(zhp
, NULL
, nvroot
, 0, B_FALSE
, name_flags
);
703 /* Do the same for the logs */
704 if (num_logs(poolnvroot
) > 0) {
705 print_vdev_tree(zhp
, "logs", poolnvroot
, 0, B_TRUE
,
707 print_vdev_tree(zhp
, NULL
, nvroot
, 0, B_TRUE
,
709 } else if (num_logs(nvroot
) > 0) {
710 print_vdev_tree(zhp
, "logs", nvroot
, 0, B_TRUE
,
714 /* Do the same for the caches */
715 if (nvlist_lookup_nvlist_array(poolnvroot
, ZPOOL_CONFIG_L2CACHE
,
716 &l2child
, &l2children
) == 0 && l2children
) {
718 (void) printf(gettext("\tcache\n"));
719 for (c
= 0; c
< l2children
; c
++) {
720 vname
= zpool_vdev_name(g_zfs
, NULL
,
721 l2child
[c
], name_flags
);
722 (void) printf("\t %s\n", vname
);
726 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_L2CACHE
,
727 &l2child
, &l2children
) == 0 && l2children
) {
729 (void) printf(gettext("\tcache\n"));
730 for (c
= 0; c
< l2children
; c
++) {
731 vname
= zpool_vdev_name(g_zfs
, NULL
,
732 l2child
[c
], name_flags
);
733 (void) printf("\t %s\n", vname
);
740 ret
= (zpool_add(zhp
, nvroot
) != 0);
751 * zpool remove <pool> <vdev> ...
753 * Removes the given vdev from the pool. Currently, this supports removing
754 * spares, cache, and log devices from the pool.
757 zpool_do_remove(int argc
, char **argv
)
766 /* get pool name and check number of arguments */
768 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
772 (void) fprintf(stderr
, gettext("missing device\n"));
778 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
781 for (i
= 1; i
< argc
; i
++) {
782 if (zpool_vdev_remove(zhp
, argv
[i
]) != 0)
790 * zpool labelclear <vdev>
792 * Verifies that the vdev is not active and zeros out the label information
796 zpool_do_labelclear(int argc
, char **argv
)
799 int c
, fd
= -1, ret
= 0;
801 boolean_t inuse
= B_FALSE
;
802 boolean_t force
= B_FALSE
;
805 while ((c
= getopt(argc
, argv
, "f")) != -1) {
811 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
822 (void) fprintf(stderr
, gettext("missing vdev device name\n"));
827 if ((fd
= open(vdev
, O_RDWR
)) < 0) {
828 (void) fprintf(stderr
, gettext("Unable to open %s\n"), vdev
);
833 if (zpool_in_use(g_zfs
, fd
, &state
, &name
, &inuse
) != 0) {
837 (void) fprintf(stderr
,
838 gettext("Unable to determine pool state for %s\n"
839 "Use -f to force the clearing any label data\n"), vdev
);
847 case POOL_STATE_ACTIVE
:
848 case POOL_STATE_SPARE
:
849 case POOL_STATE_L2CACHE
:
850 (void) fprintf(stderr
,
851 gettext("labelclear operation failed.\n"
852 "\tVdev %s is a member (%s), of pool \"%s\".\n"
853 "\tTo remove label information from this device, "
854 "export or destroy\n\tthe pool, or remove %s from "
855 "the configuration of this pool\n\tand retry the "
856 "labelclear operation.\n"),
857 vdev
, zpool_pool_state_to_name(state
), name
, vdev
);
861 case POOL_STATE_EXPORTED
:
865 (void) fprintf(stderr
,
866 gettext("labelclear operation failed.\n\tVdev "
867 "%s is a member of the exported pool \"%s\".\n"
868 "\tUse \"zpool labelclear -f %s\" to force the "
869 "removal of label\n\tinformation.\n"),
874 case POOL_STATE_POTENTIALLY_ACTIVE
:
878 (void) fprintf(stderr
,
879 gettext("labelclear operation failed.\n"
880 "\tVdev %s is a member of the pool \"%s\".\n"
881 "\tThis pool is unknown to this system, but may "
882 "be active on\n\tanother system. Use "
883 "\'zpool labelclear -f %s\' to force the\n"
884 "\tremoval of label information.\n"),
889 case POOL_STATE_DESTROYED
:
890 /* inuse should never be set for a destroyed pool... */
896 if (zpool_clear_label(fd
) != 0) {
897 (void) fprintf(stderr
,
898 gettext("Label clear failed on vdev %s\n"), vdev
);
911 * zpool create [-fnd] [-o property=value] ...
912 * [-O file-system-property=value] ...
913 * [-R root] [-m mountpoint] <pool> <dev> ...
915 * -f Force creation, even if devices appear in use
916 * -n Do not create the pool, but display the resulting layout if it
917 * were to be created.
918 * -R Create a pool under an alternate root
919 * -m Set default mountpoint for the root dataset. By default it's
921 * -o Set property=value.
922 * -d Don't automatically enable all supported pool features
923 * (individual features can be enabled with -o).
924 * -O Set fsproperty=value in the pool's root file system
926 * Creates the named pool according to the given vdev specification. The
927 * bulk of the vdev processing is done in get_vdev_spec() in zpool_vdev.c. Once
928 * we get the nvlist back from get_vdev_spec(), we either print out the contents
929 * (if '-n' was specified), or pass it to libzfs to do the creation.
932 zpool_do_create(int argc
, char **argv
)
934 boolean_t force
= B_FALSE
;
935 boolean_t dryrun
= B_FALSE
;
936 boolean_t enable_all_pool_feat
= B_TRUE
;
938 nvlist_t
*nvroot
= NULL
;
942 char *altroot
= NULL
;
943 char *mountpoint
= NULL
;
944 nvlist_t
*fsprops
= NULL
;
945 nvlist_t
*props
= NULL
;
949 while ((c
= getopt(argc
, argv
, ":fndR:m:o:O:t:")) != -1) {
958 enable_all_pool_feat
= B_FALSE
;
962 if (add_prop_list(zpool_prop_to_name(
963 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
965 if (add_prop_list_default(zpool_prop_to_name(
966 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
970 /* Equivalent to -O mountpoint=optarg */
974 if ((propval
= strchr(optarg
, '=')) == NULL
) {
975 (void) fprintf(stderr
, gettext("missing "
976 "'=' for -o option\n"));
982 if (add_prop_list(optarg
, propval
, &props
, B_TRUE
))
986 * If the user is creating a pool that doesn't support
987 * feature flags, don't enable any features.
989 if (zpool_name_to_prop(optarg
) == ZPOOL_PROP_VERSION
) {
993 ver
= strtoull(propval
, &end
, 10);
995 ver
< SPA_VERSION_FEATURES
) {
996 enable_all_pool_feat
= B_FALSE
;
999 if (zpool_name_to_prop(optarg
) == ZPOOL_PROP_ALTROOT
)
1003 if ((propval
= strchr(optarg
, '=')) == NULL
) {
1004 (void) fprintf(stderr
, gettext("missing "
1005 "'=' for -O option\n"));
1012 * Mountpoints are checked and then added later.
1013 * Uniquely among properties, they can be specified
1014 * more than once, to avoid conflict with -m.
1016 if (0 == strcmp(optarg
,
1017 zfs_prop_to_name(ZFS_PROP_MOUNTPOINT
))) {
1018 mountpoint
= propval
;
1019 } else if (add_prop_list(optarg
, propval
, &fsprops
,
1026 * Sanity check temporary pool name.
1028 if (strchr(optarg
, '/') != NULL
) {
1029 (void) fprintf(stderr
, gettext("cannot create "
1030 "'%s': invalid character '/' in temporary "
1032 (void) fprintf(stderr
, gettext("use 'zfs "
1033 "create' to create a dataset\n"));
1037 if (add_prop_list(zpool_prop_to_name(
1038 ZPOOL_PROP_TNAME
), optarg
, &props
, B_TRUE
))
1040 if (add_prop_list_default(zpool_prop_to_name(
1041 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
1046 (void) fprintf(stderr
, gettext("missing argument for "
1047 "'%c' option\n"), optopt
);
1050 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1059 /* get pool name and check number of arguments */
1061 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
1065 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
1072 * As a special case, check for use of '/' in the name, and direct the
1073 * user to use 'zfs create' instead.
1075 if (strchr(poolname
, '/') != NULL
) {
1076 (void) fprintf(stderr
, gettext("cannot create '%s': invalid "
1077 "character '/' in pool name\n"), poolname
);
1078 (void) fprintf(stderr
, gettext("use 'zfs create' to "
1079 "create a dataset\n"));
1083 /* pass off to get_vdev_spec for bulk processing */
1084 nvroot
= make_root_vdev(NULL
, props
, force
, !force
, B_FALSE
, dryrun
,
1085 argc
- 1, argv
+ 1);
1089 /* make_root_vdev() allows 0 toplevel children if there are spares */
1090 if (!zfs_allocatable_devs(nvroot
)) {
1091 (void) fprintf(stderr
, gettext("invalid vdev "
1092 "specification: at least one toplevel vdev must be "
1097 if (altroot
!= NULL
&& altroot
[0] != '/') {
1098 (void) fprintf(stderr
, gettext("invalid alternate root '%s': "
1099 "must be an absolute path\n"), altroot
);
1104 * Check the validity of the mountpoint and direct the user to use the
1105 * '-m' mountpoint option if it looks like its in use.
1107 if (mountpoint
== NULL
||
1108 (strcmp(mountpoint
, ZFS_MOUNTPOINT_LEGACY
) != 0 &&
1109 strcmp(mountpoint
, ZFS_MOUNTPOINT_NONE
) != 0)) {
1110 char buf
[MAXPATHLEN
];
1113 if (mountpoint
&& mountpoint
[0] != '/') {
1114 (void) fprintf(stderr
, gettext("invalid mountpoint "
1115 "'%s': must be an absolute path, 'legacy', or "
1116 "'none'\n"), mountpoint
);
1120 if (mountpoint
== NULL
) {
1121 if (altroot
!= NULL
)
1122 (void) snprintf(buf
, sizeof (buf
), "%s/%s",
1125 (void) snprintf(buf
, sizeof (buf
), "/%s",
1128 if (altroot
!= NULL
)
1129 (void) snprintf(buf
, sizeof (buf
), "%s%s",
1130 altroot
, mountpoint
);
1132 (void) snprintf(buf
, sizeof (buf
), "%s",
1136 if ((dirp
= opendir(buf
)) == NULL
&& errno
!= ENOENT
) {
1137 (void) fprintf(stderr
, gettext("mountpoint '%s' : "
1138 "%s\n"), buf
, strerror(errno
));
1139 (void) fprintf(stderr
, gettext("use '-m' "
1140 "option to provide a different default\n"));
1145 while (count
< 3 && readdir(dirp
) != NULL
)
1147 (void) closedir(dirp
);
1150 (void) fprintf(stderr
, gettext("mountpoint "
1151 "'%s' exists and is not empty\n"), buf
);
1152 (void) fprintf(stderr
, gettext("use '-m' "
1153 "option to provide a "
1154 "different default\n"));
1161 * Now that the mountpoint's validity has been checked, ensure that
1162 * the property is set appropriately prior to creating the pool.
1164 if (mountpoint
!= NULL
) {
1165 ret
= add_prop_list(zfs_prop_to_name(ZFS_PROP_MOUNTPOINT
),
1166 mountpoint
, &fsprops
, B_FALSE
);
1174 * For a dry run invocation, print out a basic message and run
1175 * through all the vdevs in the list and print out in an
1176 * appropriate hierarchy.
1178 (void) printf(gettext("would create '%s' with the "
1179 "following layout:\n\n"), poolname
);
1181 print_vdev_tree(NULL
, poolname
, nvroot
, 0, B_FALSE
, 0);
1182 if (num_logs(nvroot
) > 0)
1183 print_vdev_tree(NULL
, "logs", nvroot
, 0, B_TRUE
, 0);
1188 * Hand off to libzfs.
1190 if (enable_all_pool_feat
) {
1192 for (i
= 0; i
< SPA_FEATURES
; i
++) {
1193 char propname
[MAXPATHLEN
];
1194 zfeature_info_t
*feat
= &spa_feature_table
[i
];
1196 (void) snprintf(propname
, sizeof (propname
),
1197 "feature@%s", feat
->fi_uname
);
1200 * Skip feature if user specified it manually
1201 * on the command line.
1203 if (nvlist_exists(props
, propname
))
1206 ret
= add_prop_list(propname
,
1207 ZFS_FEATURE_ENABLED
, &props
, B_TRUE
);
1214 if (zpool_create(g_zfs
, poolname
,
1215 nvroot
, props
, fsprops
) == 0) {
1216 zfs_handle_t
*pool
= zfs_open(g_zfs
,
1217 tname
? tname
: poolname
, ZFS_TYPE_FILESYSTEM
);
1219 if (zfs_mount(pool
, NULL
, 0) == 0)
1220 ret
= zfs_shareall(pool
);
1223 } else if (libzfs_errno(g_zfs
) == EZFS_INVALIDNAME
) {
1224 (void) fprintf(stderr
, gettext("pool name may have "
1230 nvlist_free(nvroot
);
1231 nvlist_free(fsprops
);
1235 nvlist_free(fsprops
);
1242 * zpool destroy <pool>
1244 * -f Forcefully unmount any datasets
1246 * Destroy the given pool. Automatically unmounts any datasets in the pool.
1249 zpool_do_destroy(int argc
, char **argv
)
1251 boolean_t force
= B_FALSE
;
1254 zpool_handle_t
*zhp
;
1258 while ((c
= getopt(argc
, argv
, "f")) != -1) {
1264 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1273 /* check arguments */
1275 (void) fprintf(stderr
, gettext("missing pool argument\n"));
1279 (void) fprintf(stderr
, gettext("too many arguments\n"));
1285 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
) {
1287 * As a special case, check for use of '/' in the name, and
1288 * direct the user to use 'zfs destroy' instead.
1290 if (strchr(pool
, '/') != NULL
)
1291 (void) fprintf(stderr
, gettext("use 'zfs destroy' to "
1292 "destroy a dataset\n"));
1296 if (zpool_disable_datasets(zhp
, force
) != 0) {
1297 (void) fprintf(stderr
, gettext("could not destroy '%s': "
1298 "could not unmount datasets\n"), zpool_get_name(zhp
));
1302 /* The history must be logged as part of the export */
1303 log_history
= B_FALSE
;
1305 ret
= (zpool_destroy(zhp
, history_str
) != 0);
1312 typedef struct export_cbdata
{
1314 boolean_t hardforce
;
1321 zpool_export_one(zpool_handle_t
*zhp
, void *data
)
1323 export_cbdata_t
*cb
= data
;
1325 if (zpool_disable_datasets(zhp
, cb
->force
) != 0)
1328 /* The history must be logged as part of the export */
1329 log_history
= B_FALSE
;
1331 if (cb
->hardforce
) {
1332 if (zpool_export_force(zhp
, history_str
) != 0)
1334 } else if (zpool_export(zhp
, cb
->force
, history_str
) != 0) {
1342 * zpool export [-f] <pool> ...
1344 * -a Export all pools
1345 * -f Forcefully unmount datasets
1347 * Export the given pools. By default, the command will attempt to cleanly
1348 * unmount any active datasets within the pool. If the '-f' flag is specified,
1349 * then the datasets will be forcefully unmounted.
1352 zpool_do_export(int argc
, char **argv
)
1355 boolean_t do_all
= B_FALSE
;
1356 boolean_t force
= B_FALSE
;
1357 boolean_t hardforce
= B_FALSE
;
1361 while ((c
= getopt(argc
, argv
, "afF")) != -1) {
1373 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1380 cb
.hardforce
= hardforce
;
1386 (void) fprintf(stderr
, gettext("too many arguments\n"));
1390 return (for_each_pool(argc
, argv
, B_TRUE
, NULL
,
1391 zpool_export_one
, &cb
));
1394 /* check arguments */
1396 (void) fprintf(stderr
, gettext("missing pool argument\n"));
1400 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
, zpool_export_one
, &cb
);
1406 * Given a vdev configuration, determine the maximum width needed for the device
1410 max_width(zpool_handle_t
*zhp
, nvlist_t
*nv
, int depth
, int max
,
1418 name
= zpool_vdev_name(g_zfs
, zhp
, nv
, name_flags
| VDEV_NAME_TYPE_ID
);
1419 if (strlen(name
) + depth
> max
)
1420 max
= strlen(name
) + depth
;
1424 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
1425 &child
, &children
) == 0) {
1426 for (c
= 0; c
< children
; c
++)
1427 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1428 max
, name_flags
)) > max
)
1432 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
1433 &child
, &children
) == 0) {
1434 for (c
= 0; c
< children
; c
++)
1435 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1436 max
, name_flags
)) > max
)
1440 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1441 &child
, &children
) == 0) {
1442 for (c
= 0; c
< children
; c
++)
1443 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1444 max
, name_flags
)) > max
)
1451 typedef struct spare_cbdata
{
1453 zpool_handle_t
*cb_zhp
;
1457 find_vdev(nvlist_t
*nv
, uint64_t search
)
1463 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
, &guid
) == 0 &&
1467 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1468 &child
, &children
) == 0) {
1469 for (c
= 0; c
< children
; c
++)
1470 if (find_vdev(child
[c
], search
))
1478 find_spare(zpool_handle_t
*zhp
, void *data
)
1480 spare_cbdata_t
*cbp
= data
;
1481 nvlist_t
*config
, *nvroot
;
1483 config
= zpool_get_config(zhp
, NULL
);
1484 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
1487 if (find_vdev(nvroot
, cbp
->cb_guid
)) {
1497 * Print out configuration state as requested by status_callback.
1500 print_status_config(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
,
1501 int namewidth
, int depth
, boolean_t isspare
, int name_flags
)
1505 pool_scan_stat_t
*ps
= NULL
;
1507 char rbuf
[6], wbuf
[6], cbuf
[6];
1509 uint64_t notpresent
;
1513 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1514 &child
, &children
) != 0)
1517 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
1518 (uint64_t **)&vs
, &c
) == 0);
1520 state
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
1523 * For hot spares, we use the terms 'INUSE' and 'AVAILABLE' for
1526 if (vs
->vs_aux
== VDEV_AUX_SPARED
)
1528 else if (vs
->vs_state
== VDEV_STATE_HEALTHY
)
1532 (void) printf("\t%*s%-*s %-8s", depth
, "", namewidth
- depth
,
1536 zfs_nicenum(vs
->vs_read_errors
, rbuf
, sizeof (rbuf
));
1537 zfs_nicenum(vs
->vs_write_errors
, wbuf
, sizeof (wbuf
));
1538 zfs_nicenum(vs
->vs_checksum_errors
, cbuf
, sizeof (cbuf
));
1539 (void) printf(" %5s %5s %5s", rbuf
, wbuf
, cbuf
);
1542 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_NOT_PRESENT
,
1543 ¬present
) == 0) {
1545 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_PATH
, &path
) == 0);
1546 (void) printf(" was %s", path
);
1547 } else if (vs
->vs_aux
!= 0) {
1550 switch (vs
->vs_aux
) {
1551 case VDEV_AUX_OPEN_FAILED
:
1552 (void) printf(gettext("cannot open"));
1555 case VDEV_AUX_BAD_GUID_SUM
:
1556 (void) printf(gettext("missing device"));
1559 case VDEV_AUX_NO_REPLICAS
:
1560 (void) printf(gettext("insufficient replicas"));
1563 case VDEV_AUX_VERSION_NEWER
:
1564 (void) printf(gettext("newer version"));
1567 case VDEV_AUX_UNSUP_FEAT
:
1568 (void) printf(gettext("unsupported feature(s)"));
1571 case VDEV_AUX_SPARED
:
1572 verify(nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
,
1574 if (zpool_iter(g_zfs
, find_spare
, &cb
) == 1) {
1575 if (strcmp(zpool_get_name(cb
.cb_zhp
),
1576 zpool_get_name(zhp
)) == 0)
1577 (void) printf(gettext("currently in "
1580 (void) printf(gettext("in use by "
1582 zpool_get_name(cb
.cb_zhp
));
1583 zpool_close(cb
.cb_zhp
);
1585 (void) printf(gettext("currently in use"));
1589 case VDEV_AUX_ERR_EXCEEDED
:
1590 (void) printf(gettext("too many errors"));
1593 case VDEV_AUX_IO_FAILURE
:
1594 (void) printf(gettext("experienced I/O failures"));
1597 case VDEV_AUX_BAD_LOG
:
1598 (void) printf(gettext("bad intent log"));
1601 case VDEV_AUX_EXTERNAL
:
1602 (void) printf(gettext("external device fault"));
1605 case VDEV_AUX_SPLIT_POOL
:
1606 (void) printf(gettext("split into new pool"));
1610 (void) printf(gettext("corrupted data"));
1615 (void) nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_SCAN_STATS
,
1616 (uint64_t **)&ps
, &c
);
1618 if (ps
&& ps
->pss_state
== DSS_SCANNING
&&
1619 vs
->vs_scan_processed
!= 0 && children
== 0) {
1620 (void) printf(gettext(" (%s)"),
1621 (ps
->pss_func
== POOL_SCAN_RESILVER
) ?
1622 "resilvering" : "repairing");
1625 (void) printf("\n");
1627 for (c
= 0; c
< children
; c
++) {
1628 uint64_t islog
= B_FALSE
, ishole
= B_FALSE
;
1630 /* Don't print logs or holes here */
1631 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1633 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_HOLE
,
1635 if (islog
|| ishole
)
1637 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
1638 name_flags
| VDEV_NAME_TYPE_ID
);
1639 print_status_config(zhp
, vname
, child
[c
],
1640 namewidth
, depth
+ 2, isspare
, name_flags
);
1646 * Print the configuration of an exported pool. Iterate over all vdevs in the
1647 * pool, printing out the name and status for each one.
1650 print_import_config(const char *name
, nvlist_t
*nv
, int namewidth
, int depth
,
1658 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_TYPE
, &type
) == 0);
1659 if (strcmp(type
, VDEV_TYPE_MISSING
) == 0 ||
1660 strcmp(type
, VDEV_TYPE_HOLE
) == 0)
1663 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
1664 (uint64_t **)&vs
, &c
) == 0);
1666 (void) printf("\t%*s%-*s", depth
, "", namewidth
- depth
, name
);
1667 (void) printf(" %s", zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
));
1669 if (vs
->vs_aux
!= 0) {
1672 switch (vs
->vs_aux
) {
1673 case VDEV_AUX_OPEN_FAILED
:
1674 (void) printf(gettext("cannot open"));
1677 case VDEV_AUX_BAD_GUID_SUM
:
1678 (void) printf(gettext("missing device"));
1681 case VDEV_AUX_NO_REPLICAS
:
1682 (void) printf(gettext("insufficient replicas"));
1685 case VDEV_AUX_VERSION_NEWER
:
1686 (void) printf(gettext("newer version"));
1689 case VDEV_AUX_UNSUP_FEAT
:
1690 (void) printf(gettext("unsupported feature(s)"));
1693 case VDEV_AUX_ERR_EXCEEDED
:
1694 (void) printf(gettext("too many errors"));
1698 (void) printf(gettext("corrupted data"));
1702 (void) printf("\n");
1704 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1705 &child
, &children
) != 0)
1708 for (c
= 0; c
< children
; c
++) {
1709 uint64_t is_log
= B_FALSE
;
1711 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1716 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
],
1717 name_flags
| VDEV_NAME_TYPE_ID
);
1718 print_import_config(vname
, child
[c
], namewidth
, depth
+ 2,
1723 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
1724 &child
, &children
) == 0) {
1725 (void) printf(gettext("\tcache\n"));
1726 for (c
= 0; c
< children
; c
++) {
1727 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
],
1729 (void) printf("\t %s\n", vname
);
1734 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
1735 &child
, &children
) == 0) {
1736 (void) printf(gettext("\tspares\n"));
1737 for (c
= 0; c
< children
; c
++) {
1738 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
],
1740 (void) printf("\t %s\n", vname
);
1748 * Logs are recorded as top level vdevs in the main pool child array
1749 * but with "is_log" set to 1. We use either print_status_config() or
1750 * print_import_config() to print the top level logs then any log
1751 * children (eg mirrored slogs) are printed recursively - which
1752 * works because only the top level vdev is marked "is_log"
1755 print_logs(zpool_handle_t
*zhp
, nvlist_t
*nv
, int namewidth
, boolean_t verbose
,
1761 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
, &child
,
1765 (void) printf(gettext("\tlogs\n"));
1767 for (c
= 0; c
< children
; c
++) {
1768 uint64_t is_log
= B_FALSE
;
1771 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1775 name
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
1776 name_flags
| VDEV_NAME_TYPE_ID
);
1778 print_status_config(zhp
, name
, child
[c
], namewidth
,
1779 2, B_FALSE
, name_flags
);
1781 print_import_config(name
, child
[c
], namewidth
, 2,
1788 * Display the status for the given pool.
1791 show_import(nvlist_t
*config
)
1793 uint64_t pool_state
;
1799 zpool_status_t reason
;
1800 zpool_errata_t errata
;
1806 verify(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
1808 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
,
1810 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
1812 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
1815 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_VDEV_STATS
,
1816 (uint64_t **)&vs
, &vsc
) == 0);
1817 health
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
1819 reason
= zpool_import_status(config
, &msgid
, &errata
);
1821 (void) printf(gettext(" pool: %s\n"), name
);
1822 (void) printf(gettext(" id: %llu\n"), (u_longlong_t
)guid
);
1823 (void) printf(gettext(" state: %s"), health
);
1824 if (pool_state
== POOL_STATE_DESTROYED
)
1825 (void) printf(gettext(" (DESTROYED)"));
1826 (void) printf("\n");
1829 case ZPOOL_STATUS_MISSING_DEV_R
:
1830 case ZPOOL_STATUS_MISSING_DEV_NR
:
1831 case ZPOOL_STATUS_BAD_GUID_SUM
:
1832 (void) printf(gettext(" status: One or more devices are "
1833 "missing from the system.\n"));
1836 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
1837 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
1838 (void) printf(gettext(" status: One or more devices contains "
1839 "corrupted data.\n"));
1842 case ZPOOL_STATUS_CORRUPT_DATA
:
1844 gettext(" status: The pool data is corrupted.\n"));
1847 case ZPOOL_STATUS_OFFLINE_DEV
:
1848 (void) printf(gettext(" status: One or more devices "
1849 "are offlined.\n"));
1852 case ZPOOL_STATUS_CORRUPT_POOL
:
1853 (void) printf(gettext(" status: The pool metadata is "
1857 case ZPOOL_STATUS_VERSION_OLDER
:
1858 (void) printf(gettext(" status: The pool is formatted using a "
1859 "legacy on-disk version.\n"));
1862 case ZPOOL_STATUS_VERSION_NEWER
:
1863 (void) printf(gettext(" status: The pool is formatted using an "
1864 "incompatible version.\n"));
1867 case ZPOOL_STATUS_FEAT_DISABLED
:
1868 (void) printf(gettext(" status: Some supported features are "
1869 "not enabled on the pool.\n"));
1872 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
1873 (void) printf(gettext("status: The pool uses the following "
1874 "feature(s) not supported on this sytem:\n"));
1875 zpool_print_unsup_feat(config
);
1878 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
1879 (void) printf(gettext("status: The pool can only be accessed "
1880 "in read-only mode on this system. It\n\tcannot be "
1881 "accessed in read-write mode because it uses the "
1882 "following\n\tfeature(s) not supported on this system:\n"));
1883 zpool_print_unsup_feat(config
);
1886 case ZPOOL_STATUS_HOSTID_MISMATCH
:
1887 (void) printf(gettext(" status: The pool was last accessed by "
1888 "another system.\n"));
1891 case ZPOOL_STATUS_FAULTED_DEV_R
:
1892 case ZPOOL_STATUS_FAULTED_DEV_NR
:
1893 (void) printf(gettext(" status: One or more devices are "
1897 case ZPOOL_STATUS_BAD_LOG
:
1898 (void) printf(gettext(" status: An intent log record cannot be "
1902 case ZPOOL_STATUS_RESILVERING
:
1903 (void) printf(gettext(" status: One or more devices were being "
1907 case ZPOOL_STATUS_ERRATA
:
1908 (void) printf(gettext(" status: Errata #%d detected.\n"),
1914 * No other status can be seen when importing pools.
1916 assert(reason
== ZPOOL_STATUS_OK
);
1920 * Print out an action according to the overall state of the pool.
1922 if (vs
->vs_state
== VDEV_STATE_HEALTHY
) {
1923 if (reason
== ZPOOL_STATUS_VERSION_OLDER
||
1924 reason
== ZPOOL_STATUS_FEAT_DISABLED
) {
1925 (void) printf(gettext(" action: The pool can be "
1926 "imported using its name or numeric identifier, "
1927 "though\n\tsome features will not be available "
1928 "without an explicit 'zpool upgrade'.\n"));
1929 } else if (reason
== ZPOOL_STATUS_HOSTID_MISMATCH
) {
1930 (void) printf(gettext(" action: The pool can be "
1931 "imported using its name or numeric "
1932 "identifier and\n\tthe '-f' flag.\n"));
1933 } else if (reason
== ZPOOL_STATUS_ERRATA
) {
1935 case ZPOOL_ERRATA_NONE
:
1938 case ZPOOL_ERRATA_ZOL_2094_SCRUB
:
1939 (void) printf(gettext(" action: The pool can "
1940 "be imported using its name or numeric "
1941 "identifier,\n\thowever there is a compat"
1942 "ibility issue which should be corrected"
1943 "\n\tby running 'zpool scrub'\n"));
1946 case ZPOOL_ERRATA_ZOL_2094_ASYNC_DESTROY
:
1947 (void) printf(gettext(" action: The pool can"
1948 "not be imported with this version of ZFS "
1949 "due to\n\tan active asynchronous destroy. "
1950 "Revert to an earlier version\n\tand "
1951 "allow the destroy to complete before "
1957 * All errata must contain an action message.
1962 (void) printf(gettext(" action: The pool can be "
1963 "imported using its name or numeric "
1966 } else if (vs
->vs_state
== VDEV_STATE_DEGRADED
) {
1967 (void) printf(gettext(" action: The pool can be imported "
1968 "despite missing or damaged devices. The\n\tfault "
1969 "tolerance of the pool may be compromised if imported.\n"));
1972 case ZPOOL_STATUS_VERSION_NEWER
:
1973 (void) printf(gettext(" action: The pool cannot be "
1974 "imported. Access the pool on a system running "
1975 "newer\n\tsoftware, or recreate the pool from "
1978 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
1979 (void) printf(gettext("action: The pool cannot be "
1980 "imported. Access the pool on a system that "
1981 "supports\n\tthe required feature(s), or recreate "
1982 "the pool from backup.\n"));
1984 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
1985 (void) printf(gettext("action: The pool cannot be "
1986 "imported in read-write mode. Import the pool "
1988 "\t\"-o readonly=on\", access the pool on a system "
1989 "that supports the\n\trequired feature(s), or "
1990 "recreate the pool from backup.\n"));
1992 case ZPOOL_STATUS_MISSING_DEV_R
:
1993 case ZPOOL_STATUS_MISSING_DEV_NR
:
1994 case ZPOOL_STATUS_BAD_GUID_SUM
:
1995 (void) printf(gettext(" action: The pool cannot be "
1996 "imported. Attach the missing\n\tdevices and try "
2000 (void) printf(gettext(" action: The pool cannot be "
2001 "imported due to damaged devices or data.\n"));
2005 /* Print the comment attached to the pool. */
2006 if (nvlist_lookup_string(config
, ZPOOL_CONFIG_COMMENT
, &comment
) == 0)
2007 (void) printf(gettext("comment: %s\n"), comment
);
2010 * If the state is "closed" or "can't open", and the aux state
2011 * is "corrupt data":
2013 if (((vs
->vs_state
== VDEV_STATE_CLOSED
) ||
2014 (vs
->vs_state
== VDEV_STATE_CANT_OPEN
)) &&
2015 (vs
->vs_aux
== VDEV_AUX_CORRUPT_DATA
)) {
2016 if (pool_state
== POOL_STATE_DESTROYED
)
2017 (void) printf(gettext("\tThe pool was destroyed, "
2018 "but can be imported using the '-Df' flags.\n"));
2019 else if (pool_state
!= POOL_STATE_EXPORTED
)
2020 (void) printf(gettext("\tThe pool may be active on "
2021 "another system, but can be imported using\n\t"
2022 "the '-f' flag.\n"));
2026 (void) printf(gettext(" see: http://zfsonlinux.org/msg/%s\n"),
2029 (void) printf(gettext(" config:\n\n"));
2031 namewidth
= max_width(NULL
, nvroot
, 0, 0, 0);
2035 print_import_config(name
, nvroot
, namewidth
, 0, 0);
2036 if (num_logs(nvroot
) > 0)
2037 print_logs(NULL
, nvroot
, namewidth
, B_FALSE
, 0);
2039 if (reason
== ZPOOL_STATUS_BAD_GUID_SUM
) {
2040 (void) printf(gettext("\n\tAdditional devices are known to "
2041 "be part of this pool, though their\n\texact "
2042 "configuration cannot be determined.\n"));
2047 * Perform the import for the given configuration. This passes the heavy
2048 * lifting off to zpool_import_props(), and then mounts the datasets contained
2052 do_import(nvlist_t
*config
, const char *newname
, const char *mntopts
,
2053 nvlist_t
*props
, int flags
)
2055 zpool_handle_t
*zhp
;
2060 verify(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
2063 verify(nvlist_lookup_uint64(config
,
2064 ZPOOL_CONFIG_POOL_STATE
, &state
) == 0);
2065 verify(nvlist_lookup_uint64(config
,
2066 ZPOOL_CONFIG_VERSION
, &version
) == 0);
2067 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
2068 (void) fprintf(stderr
, gettext("cannot import '%s': pool "
2069 "is formatted using an unsupported ZFS version\n"), name
);
2071 } else if (state
!= POOL_STATE_EXPORTED
&&
2072 !(flags
& ZFS_IMPORT_ANY_HOST
)) {
2073 uint64_t hostid
= 0;
2074 unsigned long system_hostid
= get_system_hostid();
2076 (void) nvlist_lookup_uint64(config
, ZPOOL_CONFIG_HOSTID
,
2079 if (hostid
!= 0 && (unsigned long)hostid
!= system_hostid
) {
2084 verify(nvlist_lookup_string(config
,
2085 ZPOOL_CONFIG_HOSTNAME
, &hostname
) == 0);
2086 verify(nvlist_lookup_uint64(config
,
2087 ZPOOL_CONFIG_TIMESTAMP
, ×tamp
) == 0);
2089 (void) fprintf(stderr
, gettext("cannot import "
2090 "'%s': pool may be in use from other "
2091 "system, it was last accessed by %s "
2092 "(hostid: 0x%lx) on %s"), name
, hostname
,
2093 (unsigned long)hostid
,
2094 asctime(localtime(&t
)));
2095 (void) fprintf(stderr
, gettext("use '-f' to "
2096 "import anyway\n"));
2101 if (zpool_import_props(g_zfs
, config
, newname
, props
, flags
) != 0)
2104 if (newname
!= NULL
)
2105 name
= (char *)newname
;
2107 if ((zhp
= zpool_open_canfail(g_zfs
, name
)) == NULL
)
2110 if (zpool_get_state(zhp
) != POOL_STATE_UNAVAIL
&&
2111 !(flags
& ZFS_IMPORT_ONLY
) &&
2112 zpool_enable_datasets(zhp
, mntopts
, 0) != 0) {
2122 * zpool import [-d dir] [-D]
2123 * import [-o mntopts] [-o prop=value] ... [-R root] [-D]
2124 * [-d dir | -c cachefile] [-f] -a
2125 * import [-o mntopts] [-o prop=value] ... [-R root] [-D]
2126 * [-d dir | -c cachefile] [-f] [-n] [-F] <pool | id> [newpool]
2128 * -c Read pool information from a cachefile instead of searching
2131 * -d Scan in a specific directory, other than /dev/. More than
2132 * one directory can be specified using multiple '-d' options.
2134 * -D Scan for previously destroyed pools or import all or only
2135 * specified destroyed pools.
2137 * -R Temporarily import the pool, with all mountpoints relative to
2138 * the given root. The pool will remain exported when the machine
2141 * -V Import even in the presence of faulted vdevs. This is an
2142 * intentionally undocumented option for testing purposes, and
2143 * treats the pool configuration as complete, leaving any bad
2144 * vdevs in the FAULTED state. In other words, it does verbatim
2147 * -f Force import, even if it appears that the pool is active.
2149 * -F Attempt rewind if necessary.
2151 * -n See if rewind would work, but don't actually rewind.
2153 * -N Import the pool but don't mount datasets.
2155 * -T Specify a starting txg to use for import. This option is
2156 * intentionally undocumented option for testing purposes.
2158 * -a Import all pools found.
2160 * -o Set property=value and/or temporary mount options (without '=').
2162 * -s Scan using the default search path, the libblkid cache will
2165 * The import command scans for pools to import, and import pools based on pool
2166 * name and GUID. The pool can also be renamed as part of the import process.
2169 zpool_do_import(int argc
, char **argv
)
2171 char **searchdirs
= NULL
;
2172 char *env
, *envdup
= NULL
;
2176 nvlist_t
*pools
= NULL
;
2177 boolean_t do_all
= B_FALSE
;
2178 boolean_t do_destroyed
= B_FALSE
;
2179 char *mntopts
= NULL
;
2182 uint64_t searchguid
= 0;
2183 char *searchname
= NULL
;
2185 nvlist_t
*found_config
;
2186 nvlist_t
*policy
= NULL
;
2187 nvlist_t
*props
= NULL
;
2189 int flags
= ZFS_IMPORT_NORMAL
;
2190 uint32_t rewind_policy
= ZPOOL_NO_REWIND
;
2191 boolean_t dryrun
= B_FALSE
;
2192 boolean_t do_rewind
= B_FALSE
;
2193 boolean_t xtreme_rewind
= B_FALSE
;
2194 boolean_t do_scan
= B_FALSE
;
2195 uint64_t pool_state
, txg
= -1ULL;
2196 char *cachefile
= NULL
;
2197 importargs_t idata
= { 0 };
2201 while ((c
= getopt(argc
, argv
, ":aCc:d:DEfFmnNo:R:stT:VX")) != -1) {
2210 if (searchdirs
== NULL
) {
2211 searchdirs
= safe_malloc(sizeof (char *));
2213 char **tmp
= safe_malloc((nsearch
+ 1) *
2215 bcopy(searchdirs
, tmp
, nsearch
*
2220 searchdirs
[nsearch
++] = optarg
;
2223 do_destroyed
= B_TRUE
;
2226 flags
|= ZFS_IMPORT_ANY_HOST
;
2232 flags
|= ZFS_IMPORT_MISSING_LOG
;
2238 flags
|= ZFS_IMPORT_ONLY
;
2241 if ((propval
= strchr(optarg
, '=')) != NULL
) {
2244 if (add_prop_list(optarg
, propval
,
2252 if (add_prop_list(zpool_prop_to_name(
2253 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
2255 if (add_prop_list_default(zpool_prop_to_name(
2256 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
2263 flags
|= ZFS_IMPORT_TEMP_NAME
;
2264 if (add_prop_list_default(zpool_prop_to_name(
2265 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
2271 txg
= strtoull(optarg
, &endptr
, 0);
2272 if (errno
!= 0 || *endptr
!= '\0') {
2273 (void) fprintf(stderr
,
2274 gettext("invalid txg value\n"));
2277 rewind_policy
= ZPOOL_DO_REWIND
| ZPOOL_EXTREME_REWIND
;
2280 flags
|= ZFS_IMPORT_VERBATIM
;
2283 xtreme_rewind
= B_TRUE
;
2286 (void) fprintf(stderr
, gettext("missing argument for "
2287 "'%c' option\n"), optopt
);
2291 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2300 if (cachefile
&& nsearch
!= 0) {
2301 (void) fprintf(stderr
, gettext("-c is incompatible with -d\n"));
2305 if ((dryrun
|| xtreme_rewind
) && !do_rewind
) {
2306 (void) fprintf(stderr
,
2307 gettext("-n or -X only meaningful with -F\n"));
2311 rewind_policy
= ZPOOL_TRY_REWIND
;
2313 rewind_policy
= ZPOOL_DO_REWIND
;
2315 rewind_policy
|= ZPOOL_EXTREME_REWIND
;
2317 /* In the future, we can capture further policy and include it here */
2318 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME
, 0) != 0 ||
2319 nvlist_add_uint64(policy
, ZPOOL_REWIND_REQUEST_TXG
, txg
) != 0 ||
2320 nvlist_add_uint32(policy
, ZPOOL_REWIND_REQUEST
, rewind_policy
) != 0)
2323 /* check argument count */
2326 (void) fprintf(stderr
, gettext("too many arguments\n"));
2331 (void) fprintf(stderr
, gettext("too many arguments\n"));
2336 * Check for the SYS_CONFIG privilege. We do this explicitly
2337 * here because otherwise any attempt to discover pools will
2340 if (argc
== 0 && !priv_ineffect(PRIV_SYS_CONFIG
)) {
2341 (void) fprintf(stderr
, gettext("cannot "
2342 "discover pools: permission denied\n"));
2343 if (searchdirs
!= NULL
)
2346 nvlist_free(policy
);
2352 * Depending on the arguments given, we do one of the following:
2354 * <none> Iterate through all pools and display information about
2357 * -a Iterate through all pools and try to import each one.
2359 * <id> Find the pool that corresponds to the given GUID/pool
2360 * name and import that one.
2362 * -D Above options applies only to destroyed pools.
2368 searchguid
= strtoull(argv
[0], &endptr
, 10);
2369 if (errno
!= 0 || *endptr
!= '\0') {
2370 searchname
= argv
[0];
2373 found_config
= NULL
;
2376 * User specified a name or guid. Ensure it's unique.
2378 idata
.unique
= B_TRUE
;
2382 * Check the environment for the preferred search path.
2384 if ((searchdirs
== NULL
) && (env
= getenv("ZPOOL_IMPORT_PATH"))) {
2387 envdup
= strdup(env
);
2389 dir
= strtok(envdup
, ":");
2390 while (dir
!= NULL
) {
2391 if (searchdirs
== NULL
) {
2392 searchdirs
= safe_malloc(sizeof (char *));
2394 char **tmp
= safe_malloc((nsearch
+ 1) *
2396 bcopy(searchdirs
, tmp
, nsearch
*
2401 searchdirs
[nsearch
++] = dir
;
2402 dir
= strtok(NULL
, ":");
2406 idata
.path
= searchdirs
;
2407 idata
.paths
= nsearch
;
2408 idata
.poolname
= searchname
;
2409 idata
.guid
= searchguid
;
2410 idata
.cachefile
= cachefile
;
2411 idata
.scan
= do_scan
;
2414 * Under Linux the zpool_find_import_impl() function leverages the
2415 * taskq implementation to parallelize device scanning. It is
2416 * therefore necessary to initialize this functionality for the
2417 * duration of the zpool_search_import() function.
2420 pools
= zpool_search_import(g_zfs
, &idata
);
2423 if (pools
!= NULL
&& idata
.exists
&&
2424 (argc
== 1 || strcmp(argv
[0], argv
[1]) == 0)) {
2425 (void) fprintf(stderr
, gettext("cannot import '%s': "
2426 "a pool with that name already exists\n"),
2428 (void) fprintf(stderr
, gettext("use the form '%s "
2429 "<pool | id> <newpool>' to give it a new name\n"),
2432 } else if (pools
== NULL
&& idata
.exists
) {
2433 (void) fprintf(stderr
, gettext("cannot import '%s': "
2434 "a pool with that name is already created/imported,\n"),
2436 (void) fprintf(stderr
, gettext("and no additional pools "
2437 "with that name were found\n"));
2439 } else if (pools
== NULL
) {
2441 (void) fprintf(stderr
, gettext("cannot import '%s': "
2442 "no such pool available\n"), argv
[0]);
2448 if (searchdirs
!= NULL
)
2452 nvlist_free(policy
);
2457 * At this point we have a list of import candidate configs. Even if
2458 * we were searching by pool name or guid, we still need to
2459 * post-process the list to deal with pool state and possible
2465 while ((elem
= nvlist_next_nvpair(pools
, elem
)) != NULL
) {
2467 verify(nvpair_value_nvlist(elem
, &config
) == 0);
2469 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
2471 if (!do_destroyed
&& pool_state
== POOL_STATE_DESTROYED
)
2473 if (do_destroyed
&& pool_state
!= POOL_STATE_DESTROYED
)
2476 verify(nvlist_add_nvlist(config
, ZPOOL_REWIND_POLICY
,
2483 (void) printf("\n");
2486 err
|= do_import(config
, NULL
, mntopts
,
2489 show_import(config
);
2491 } else if (searchname
!= NULL
) {
2495 * We are searching for a pool based on name.
2497 verify(nvlist_lookup_string(config
,
2498 ZPOOL_CONFIG_POOL_NAME
, &name
) == 0);
2500 if (strcmp(name
, searchname
) == 0) {
2501 if (found_config
!= NULL
) {
2502 (void) fprintf(stderr
, gettext(
2503 "cannot import '%s': more than "
2504 "one matching pool\n"), searchname
);
2505 (void) fprintf(stderr
, gettext(
2506 "import by numeric ID instead\n"));
2509 found_config
= config
;
2515 * Search for a pool by guid.
2517 verify(nvlist_lookup_uint64(config
,
2518 ZPOOL_CONFIG_POOL_GUID
, &guid
) == 0);
2520 if (guid
== searchguid
)
2521 found_config
= config
;
2526 * If we were searching for a specific pool, verify that we found a
2527 * pool, and then do the import.
2529 if (argc
!= 0 && err
== 0) {
2530 if (found_config
== NULL
) {
2531 (void) fprintf(stderr
, gettext("cannot import '%s': "
2532 "no such pool available\n"), argv
[0]);
2535 err
|= do_import(found_config
, argc
== 1 ? NULL
:
2536 argv
[1], mntopts
, props
, flags
);
2541 * If we were just looking for pools, report an error if none were
2544 if (argc
== 0 && first
)
2545 (void) fprintf(stderr
,
2546 gettext("no pools available to import\n"));
2551 nvlist_free(policy
);
2552 if (searchdirs
!= NULL
)
2557 return (err
? 1 : 0);
2560 typedef struct iostat_cbdata
{
2565 char **cb_vdev_names
; /* Only show these vdevs */
2566 unsigned int cb_vdev_names_count
;
2567 boolean_t cb_verbose
;
2568 boolean_t cb_literal
;
2569 boolean_t cb_scripted
;
2570 zpool_list_t
*cb_list
;
2574 typedef struct name_and_columns
{
2575 const char *name
; /* Column name */
2576 unsigned int columns
; /* Center name to this number of columns */
2577 } name_and_columns_t
;
2579 #define IOSTAT_MAX_LABELS 11 /* Max number of labels on one line */
2581 static const name_and_columns_t iostat_top_labels
[][IOSTAT_MAX_LABELS
] =
2583 [IOS_DEFAULT
] = {{"capacity", 2}, {"operations", 2}, {"bandwidth", 2},
2585 [IOS_LATENCY
] = {{"total_wait", 2}, {"disk_wait", 2}, {"syncq_wait", 2},
2586 {"asyncq_wait", 2}, {"scrub"}},
2587 [IOS_QUEUES
] = {{"syncq_read", 2}, {"syncq_write", 2},
2588 {"asyncq_read", 2}, {"asyncq_write", 2}, {"scrubq_read", 2},
2590 [IOS_L_HISTO
] = {{"total_wait", 2}, {"disk_wait", 2},
2591 {"sync_queue", 2}, {"async_queue", 2}, {NULL
}},
2592 [IOS_RQ_HISTO
] = {{"sync_read", 2}, {"sync_write", 2},
2593 {"async_read", 2}, {"async_write", 2}, {"scrub", 2}, {NULL
}},
2597 /* Shorthand - if "columns" field not set, default to 1 column */
2598 static const name_and_columns_t iostat_bottom_labels
[][IOSTAT_MAX_LABELS
] =
2600 [IOS_DEFAULT
] = {{"alloc"}, {"free"}, {"read"}, {"write"}, {"read"},
2602 [IOS_LATENCY
] = {{"read"}, {"write"}, {"read"}, {"write"}, {"read"},
2603 {"write"}, {"read"}, {"write"}, {"wait"}, {NULL
}},
2604 [IOS_QUEUES
] = {{"pend"}, {"activ"}, {"pend"}, {"activ"}, {"pend"},
2605 {"activ"}, {"pend"}, {"activ"}, {"pend"}, {"activ"}, {NULL
}},
2606 [IOS_L_HISTO
] = {{"read"}, {"write"}, {"read"}, {"write"}, {"read"},
2607 {"write"}, {"read"}, {"write"}, {"scrub"}, {NULL
}},
2608 [IOS_RQ_HISTO
] = {{"ind"}, {"agg"}, {"ind"}, {"agg"}, {"ind"}, {"agg"},
2609 {"ind"}, {"agg"}, {"ind"}, {"agg"}, {NULL
}},
2612 static const char *histo_to_title
[] = {
2613 [IOS_L_HISTO
] = "latency",
2614 [IOS_RQ_HISTO
] = "req_size",
2618 * Return the number of labels in a null-terminated name_and_columns_t
2623 label_array_len(const name_and_columns_t
*labels
)
2627 while (labels
[i
].name
)
2634 * Return the number of strings in a null-terminated string array.
2637 * const char foo[] = {"bar", "baz", NULL}
2642 str_array_len(const char *array
[])
2653 * Return a default column width for default/latency/queue columns. This does
2654 * not include histograms, which have their columns autosized.
2657 default_column_width(iostat_cbdata_t
*cb
, enum iostat_type type
)
2659 unsigned long column_width
= 5; /* Normal niceprint */
2660 static unsigned long widths
[] = {
2662 * Choose some sane default column sizes for printing the
2665 [IOS_DEFAULT
] = 15, /* 1PB capacity */
2666 [IOS_LATENCY
] = 10, /* 1B ns = 10sec */
2667 [IOS_QUEUES
] = 6, /* 1M queue entries */
2671 column_width
= widths
[type
];
2673 return (column_width
);
2677 * Print the column labels, i.e:
2679 * capacity operations bandwidth
2680 * alloc free read write read write ...
2682 * If force_column_width is set, use it for the column width. If not set, use
2683 * the default column width.
2686 print_iostat_labels(iostat_cbdata_t
*cb
, unsigned int force_column_width
,
2687 const name_and_columns_t labels
[][IOSTAT_MAX_LABELS
])
2690 unsigned int text_start
, rw_column_width
, spaces_to_end
;
2691 uint64_t flags
= cb
->cb_flags
;
2693 unsigned int column_width
= force_column_width
;
2695 /* For each bit set in flags */
2696 for (f
= flags
; f
; f
&= ~(1ULL << idx
)) {
2697 idx
= lowbit64(f
) - 1;
2698 if (!force_column_width
)
2699 column_width
= default_column_width(cb
, idx
);
2700 /* Print our top labels centered over "read write" label. */
2701 for (i
= 0; i
< label_array_len(labels
[idx
]); i
++) {
2702 const char *name
= labels
[idx
][i
].name
;
2704 * We treat labels[][].columns == 0 as shorthand
2705 * for one column. It makes writing out the label
2706 * tables more concise.
2708 unsigned int columns
= MAX(1, labels
[idx
][i
].columns
);
2709 unsigned int slen
= strlen(name
);
2711 rw_column_width
= (column_width
* columns
) +
2712 (2 * (columns
- 1));
2714 text_start
= (int) ((rw_column_width
)/columns
-
2717 printf(" "); /* Two spaces between columns */
2719 /* Space from beginning of column to label */
2720 for (s
= 0; s
< text_start
; s
++)
2725 /* Print space after label to end of column */
2726 spaces_to_end
= rw_column_width
- text_start
- slen
;
2727 for (s
= 0; s
< spaces_to_end
; s
++)
2736 * Utility function to print out a line of dashes like:
2738 * -------------------------------- ----- ----- ----- ----- -----
2740 * ...or a dashed named-row line like:
2746 * @force_column_width If non-zero, use the value as the column width.
2747 * Otherwise use the default column widths.
2749 * @name: Print a dashed named-row line starting
2750 * with @name. Otherwise, print a regular
2754 print_iostat_dashes(iostat_cbdata_t
*cb
, unsigned int force_column_width
,
2758 unsigned int namewidth
;
2759 uint64_t flags
= cb
->cb_flags
;
2762 const name_and_columns_t
*labels
;
2766 if (cb
->cb_flags
& IOS_ANYHISTO_M
) {
2767 title
= histo_to_title
[IOS_HISTO_IDX(cb
->cb_flags
)];
2768 } else if (cb
->cb_vdev_names_count
) {
2774 namewidth
= MAX(MAX(strlen(title
), cb
->cb_namewidth
),
2775 name
? strlen(name
) : 0);
2779 printf("%-*s", namewidth
, name
);
2781 for (i
= 0; i
< namewidth
; i
++)
2785 /* For each bit in flags */
2786 for (f
= flags
; f
; f
&= ~(1ULL << idx
)) {
2787 unsigned int column_width
;
2788 idx
= lowbit64(f
) - 1;
2789 if (force_column_width
)
2790 column_width
= force_column_width
;
2792 column_width
= default_column_width(cb
, idx
);
2794 labels
= iostat_bottom_labels
[idx
];
2795 for (i
= 0; i
< label_array_len(labels
); i
++) {
2797 printf(" %*s-", column_width
- 1, " ");
2799 printf(" %.*s", column_width
,
2800 "--------------------");
2808 print_iostat_separator_impl(iostat_cbdata_t
*cb
,
2809 unsigned int force_column_width
)
2811 print_iostat_dashes(cb
, force_column_width
, NULL
);
2815 print_iostat_separator(iostat_cbdata_t
*cb
)
2817 print_iostat_separator_impl(cb
, 0);
2821 print_iostat_header_impl(iostat_cbdata_t
*cb
, unsigned int force_column_width
,
2822 const char *histo_vdev_name
)
2824 unsigned int namewidth
;
2827 if (cb
->cb_flags
& IOS_ANYHISTO_M
) {
2828 title
= histo_to_title
[IOS_HISTO_IDX(cb
->cb_flags
)];
2829 } else if (cb
->cb_vdev_names_count
) {
2835 namewidth
= MAX(MAX(strlen(title
), cb
->cb_namewidth
),
2836 histo_vdev_name
? strlen(histo_vdev_name
) : 0);
2838 if (histo_vdev_name
)
2839 printf("%-*s", namewidth
, histo_vdev_name
);
2841 printf("%*s", namewidth
, "");
2844 print_iostat_labels(cb
, force_column_width
, iostat_top_labels
);
2846 printf("%-*s", namewidth
, title
);
2848 print_iostat_labels(cb
, force_column_width
, iostat_bottom_labels
);
2850 print_iostat_separator_impl(cb
, force_column_width
);
2854 print_iostat_header(iostat_cbdata_t
*cb
)
2856 print_iostat_header_impl(cb
, 0, NULL
);
2861 * Display a single statistic.
2864 print_one_stat(uint64_t value
, enum zfs_nicenum_format format
,
2865 unsigned int column_size
, boolean_t scripted
)
2869 zfs_nicenum_format(value
, buf
, sizeof (buf
), format
);
2872 printf("\t%s", buf
);
2874 printf(" %*s", column_size
, buf
);
2878 * Calculate the default vdev stats
2880 * Subtract oldvs from newvs, apply a scaling factor, and save the resulting
2881 * stats into calcvs.
2884 calc_default_iostats(vdev_stat_t
*oldvs
, vdev_stat_t
*newvs
,
2885 vdev_stat_t
*calcvs
)
2889 memcpy(calcvs
, newvs
, sizeof (*calcvs
));
2890 for (i
= 0; i
< ARRAY_SIZE(calcvs
->vs_ops
); i
++)
2891 calcvs
->vs_ops
[i
] = (newvs
->vs_ops
[i
] - oldvs
->vs_ops
[i
]);
2893 for (i
= 0; i
< ARRAY_SIZE(calcvs
->vs_bytes
); i
++)
2894 calcvs
->vs_bytes
[i
] = (newvs
->vs_bytes
[i
] - oldvs
->vs_bytes
[i
]);
2898 * Internal representation of the extended iostats data.
2900 * The extended iostat stats are exported in nvlists as either uint64_t arrays
2901 * or single uint64_t's. We make both look like arrays to make them easier
2902 * to process. In order to make single uint64_t's look like arrays, we set
2903 * __data to the stat data, and then set *data = &__data with count = 1. Then,
2904 * we can just use *data and count.
2908 uint_t count
; /* Number of entries in data[] */
2909 uint64_t __data
; /* Only used when data is a single uint64_t */
2913 stat_histo_max(struct stat_array
*nva
, unsigned int len
) {
2916 for (i
= 0; i
< len
; i
++)
2917 max
= MAX(max
, array64_max(nva
[i
].data
, nva
[i
].count
));
2923 * Helper function to lookup a uint64_t array or uint64_t value and store its
2924 * data as a stat_array. If the nvpair is a single uint64_t value, then we make
2925 * it look like a one element array to make it easier to process.
2928 nvpair64_to_stat_array(nvlist_t
*nvl
, const char *name
,
2929 struct stat_array
*nva
) {
2933 verify(nvlist_lookup_nvpair(nvl
, name
, &tmp
) == 0);
2934 switch (nvpair_type(tmp
)) {
2935 case DATA_TYPE_UINT64_ARRAY
:
2936 ret
= nvpair_value_uint64_array(tmp
, &nva
->data
, &nva
->count
);
2938 case DATA_TYPE_UINT64
:
2939 ret
= nvpair_value_uint64(tmp
, &nva
->__data
);
2940 nva
->data
= &nva
->__data
;
2944 /* Not a uint64_t */
2953 * Given a list of nvlist names, look up the extended stats in newnv and oldnv,
2954 * subtract them, and return the results in a newly allocated stat_array.
2955 * You must free the returned array after you are done with it with
2956 * free_calc_stats().
2958 * Additionally, you can set "oldnv" to NULL if you simply want the newnv
2961 static struct stat_array
*
2962 calc_and_alloc_stats_ex(const char **names
, unsigned int len
, nvlist_t
*oldnv
,
2965 nvlist_t
*oldnvx
= NULL
, *newnvx
;
2966 struct stat_array
*oldnva
, *newnva
, *calcnva
;
2968 unsigned int alloc_size
= (sizeof (struct stat_array
)) * len
;
2970 /* Extract our extended stats nvlist from the main list */
2971 verify(nvlist_lookup_nvlist(newnv
, ZPOOL_CONFIG_VDEV_STATS_EX
,
2974 verify(nvlist_lookup_nvlist(oldnv
, ZPOOL_CONFIG_VDEV_STATS_EX
,
2978 newnva
= safe_malloc(alloc_size
);
2979 oldnva
= safe_malloc(alloc_size
);
2980 calcnva
= safe_malloc(alloc_size
);
2982 for (j
= 0; j
< len
; j
++) {
2983 verify(nvpair64_to_stat_array(newnvx
, names
[j
],
2985 calcnva
[j
].count
= newnva
[j
].count
;
2986 alloc_size
= calcnva
[j
].count
* sizeof (calcnva
[j
].data
[0]);
2987 calcnva
[j
].data
= safe_malloc(alloc_size
);
2988 memcpy(calcnva
[j
].data
, newnva
[j
].data
, alloc_size
);
2991 verify(nvpair64_to_stat_array(oldnvx
, names
[j
],
2993 for (i
= 0; i
< oldnva
[j
].count
; i
++)
2994 calcnva
[j
].data
[i
] -= oldnva
[j
].data
[i
];
3003 free_calc_stats(struct stat_array
*nva
, unsigned int len
)
3006 for (i
= 0; i
< len
; i
++)
3013 print_iostat_histo(struct stat_array
*nva
, unsigned int len
,
3014 iostat_cbdata_t
*cb
, unsigned int column_width
, unsigned int namewidth
,
3020 enum zfs_nicenum_format format
;
3021 unsigned int buckets
;
3022 unsigned int start_bucket
;
3025 format
= ZFS_NICENUM_RAW
;
3027 format
= ZFS_NICENUM_1024
;
3029 /* All these histos are the same size, so just use nva[0].count */
3030 buckets
= nva
[0].count
;
3032 if (cb
->cb_flags
& IOS_RQ_HISTO_M
) {
3033 /* Start at 512 - req size should never be lower than this */
3039 for (j
= start_bucket
; j
< buckets
; j
++) {
3040 /* Print histogram bucket label */
3041 if (cb
->cb_flags
& IOS_L_HISTO_M
) {
3042 /* Ending range of this bucket */
3043 val
= (1UL << (j
+ 1)) - 1;
3044 zfs_nicetime(val
, buf
, sizeof (buf
));
3046 /* Request size (starting range of bucket) */
3048 zfs_nicenum(val
, buf
, sizeof (buf
));
3051 if (cb
->cb_scripted
)
3052 printf("%llu", (u_longlong_t
) val
);
3054 printf("%-*s", namewidth
, buf
);
3056 /* Print the values on the line */
3057 for (i
= 0; i
< len
; i
++) {
3058 print_one_stat(nva
[i
].data
[j
] * scale
, format
,
3059 column_width
, cb
->cb_scripted
);
3066 print_solid_separator(unsigned int length
)
3074 print_iostat_histos(iostat_cbdata_t
*cb
, nvlist_t
*oldnv
,
3075 nvlist_t
*newnv
, double scale
, const char *name
)
3077 unsigned int column_width
;
3078 unsigned int namewidth
;
3079 unsigned int entire_width
;
3080 enum iostat_type type
;
3081 struct stat_array
*nva
;
3083 unsigned int names_len
;
3085 /* What type of histo are we? */
3086 type
= IOS_HISTO_IDX(cb
->cb_flags
);
3088 /* Get NULL-terminated array of nvlist names for our histo */
3089 names
= vsx_type_to_nvlist
[type
];
3090 names_len
= str_array_len(names
); /* num of names */
3092 nva
= calc_and_alloc_stats_ex(names
, names_len
, oldnv
, newnv
);
3094 if (cb
->cb_literal
) {
3095 column_width
= MAX(5,
3096 (unsigned int) log10(stat_histo_max(nva
, names_len
)) + 1);
3101 namewidth
= MAX(cb
->cb_namewidth
,
3102 strlen(histo_to_title
[IOS_HISTO_IDX(cb
->cb_flags
)]));
3105 * Calculate the entire line width of what we're printing. The
3106 * +2 is for the two spaces between columns:
3110 /* |___| <---------- column_width */
3112 /* |__________| <--- entire_width */
3114 entire_width
= namewidth
+ (column_width
+ 2) *
3115 label_array_len(iostat_bottom_labels
[type
]);
3117 if (cb
->cb_scripted
)
3118 printf("%s\n", name
);
3120 print_iostat_header_impl(cb
, column_width
, name
);
3122 print_iostat_histo(nva
, names_len
, cb
, column_width
,
3125 free_calc_stats(nva
, names_len
);
3126 if (!cb
->cb_scripted
)
3127 print_solid_separator(entire_width
);
3131 * Calculate the average latency of a power-of-two latency histogram
3134 single_histo_average(uint64_t *histo
, unsigned int buckets
)
3137 uint64_t count
= 0, total
= 0;
3139 for (i
= 0; i
< buckets
; i
++) {
3141 * Our buckets are power-of-two latency ranges. Use the
3142 * midpoint latency of each bucket to calculate the average.
3150 if (histo
[i
] != 0) {
3151 total
+= histo
[i
] * (((1UL << i
) + ((1UL << i
)/2)));
3156 /* Prevent divide by zero */
3157 return (count
== 0 ? 0 : total
/ count
);
3161 print_iostat_queues(iostat_cbdata_t
*cb
, nvlist_t
*oldnv
,
3162 nvlist_t
*newnv
, double scale
)
3166 const char *names
[] = {
3167 ZPOOL_CONFIG_VDEV_SYNC_R_PEND_QUEUE
,
3168 ZPOOL_CONFIG_VDEV_SYNC_R_ACTIVE_QUEUE
,
3169 ZPOOL_CONFIG_VDEV_SYNC_W_PEND_QUEUE
,
3170 ZPOOL_CONFIG_VDEV_SYNC_W_ACTIVE_QUEUE
,
3171 ZPOOL_CONFIG_VDEV_ASYNC_R_PEND_QUEUE
,
3172 ZPOOL_CONFIG_VDEV_ASYNC_R_ACTIVE_QUEUE
,
3173 ZPOOL_CONFIG_VDEV_ASYNC_W_PEND_QUEUE
,
3174 ZPOOL_CONFIG_VDEV_ASYNC_W_ACTIVE_QUEUE
,
3175 ZPOOL_CONFIG_VDEV_SCRUB_PEND_QUEUE
,
3176 ZPOOL_CONFIG_VDEV_SCRUB_ACTIVE_QUEUE
,
3179 struct stat_array
*nva
;
3181 unsigned int column_width
= default_column_width(cb
, IOS_QUEUES
);
3182 enum zfs_nicenum_format format
;
3184 nva
= calc_and_alloc_stats_ex(names
, ARRAY_SIZE(names
), NULL
, newnv
);
3187 format
= ZFS_NICENUM_RAW
;
3189 format
= ZFS_NICENUM_1024
;
3191 for (i
= 0; i
< ARRAY_SIZE(names
); i
++) {
3192 val
= nva
[i
].data
[0] * scale
;
3193 print_one_stat(val
, format
, column_width
, cb
->cb_scripted
);
3196 free_calc_stats(nva
, ARRAY_SIZE(names
));
3200 print_iostat_latency(iostat_cbdata_t
*cb
, nvlist_t
*oldnv
,
3201 nvlist_t
*newnv
, double scale
)
3205 const char *names
[] = {
3206 ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO
,
3207 ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO
,
3208 ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO
,
3209 ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO
,
3210 ZPOOL_CONFIG_VDEV_SYNC_R_LAT_HISTO
,
3211 ZPOOL_CONFIG_VDEV_SYNC_W_LAT_HISTO
,
3212 ZPOOL_CONFIG_VDEV_ASYNC_R_LAT_HISTO
,
3213 ZPOOL_CONFIG_VDEV_ASYNC_W_LAT_HISTO
,
3214 ZPOOL_CONFIG_VDEV_SCRUB_LAT_HISTO
,
3216 struct stat_array
*nva
;
3218 unsigned int column_width
= default_column_width(cb
, IOS_LATENCY
);
3219 enum zfs_nicenum_format format
;
3221 nva
= calc_and_alloc_stats_ex(names
, ARRAY_SIZE(names
), oldnv
, newnv
);
3224 format
= ZFS_NICENUM_RAW
;
3226 format
= ZFS_NICENUM_TIME
;
3228 /* Print our avg latencies on the line */
3229 for (i
= 0; i
< ARRAY_SIZE(names
); i
++) {
3230 /* Compute average latency for a latency histo */
3231 val
= single_histo_average(nva
[i
].data
, nva
[i
].count
) * scale
;
3232 print_one_stat(val
, format
, column_width
, cb
->cb_scripted
);
3234 free_calc_stats(nva
, ARRAY_SIZE(names
));
3238 * Print default statistics (capacity/operations/bandwidth)
3241 print_iostat_default(vdev_stat_t
*vs
, iostat_cbdata_t
*cb
, double scale
)
3243 unsigned int column_width
= default_column_width(cb
, IOS_DEFAULT
);
3244 enum zfs_nicenum_format format
;
3245 char na
; /* char to print for "not applicable" values */
3247 if (cb
->cb_literal
) {
3248 format
= ZFS_NICENUM_RAW
;
3251 format
= ZFS_NICENUM_1024
;
3255 /* only toplevel vdevs have capacity stats */
3256 if (vs
->vs_space
== 0) {
3257 if (cb
->cb_scripted
)
3258 printf("\t%c\t%c", na
, na
);
3260 printf(" %*c %*c", column_width
, na
, column_width
,
3263 print_one_stat(vs
->vs_alloc
, format
, column_width
,
3265 print_one_stat(vs
->vs_space
- vs
->vs_alloc
, format
,
3266 column_width
, cb
->cb_scripted
);
3269 print_one_stat((uint64_t)(vs
->vs_ops
[ZIO_TYPE_READ
] * scale
),
3270 format
, column_width
, cb
->cb_scripted
);
3271 print_one_stat((uint64_t)(vs
->vs_ops
[ZIO_TYPE_WRITE
] * scale
),
3272 format
, column_width
, cb
->cb_scripted
);
3273 print_one_stat((uint64_t)(vs
->vs_bytes
[ZIO_TYPE_READ
] * scale
),
3274 format
, column_width
, cb
->cb_scripted
);
3275 print_one_stat((uint64_t)(vs
->vs_bytes
[ZIO_TYPE_WRITE
] * scale
),
3276 format
, column_width
, cb
->cb_scripted
);
3280 * Print out all the statistics for the given vdev. This can either be the
3281 * toplevel configuration, or called recursively. If 'name' is NULL, then this
3282 * is a verbose output, and we don't want to display the toplevel pool stats.
3284 * Returns the number of stat lines printed.
3287 print_vdev_stats(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*oldnv
,
3288 nvlist_t
*newnv
, iostat_cbdata_t
*cb
, int depth
)
3290 nvlist_t
**oldchild
, **newchild
;
3292 vdev_stat_t
*oldvs
, *newvs
, *calcvs
;
3293 vdev_stat_t zerovs
= { 0 };
3300 calcvs
= safe_malloc(sizeof (*calcvs
));
3302 if (oldnv
!= NULL
) {
3303 verify(nvlist_lookup_uint64_array(oldnv
,
3304 ZPOOL_CONFIG_VDEV_STATS
, (uint64_t **)&oldvs
, &c
) == 0);
3309 /* Do we only want to see a specific vdev? */
3310 for (i
= 0; i
< cb
->cb_vdev_names_count
; i
++) {
3311 /* Yes we do. Is this the vdev? */
3312 if (strcmp(name
, cb
->cb_vdev_names
[i
]) == 0) {
3314 * This is our vdev. Since it is the only vdev we
3315 * will be displaying, make depth = 0 so that it
3316 * doesn't get indented.
3323 if (cb
->cb_vdev_names_count
&& (i
== cb
->cb_vdev_names_count
)) {
3324 /* Couldn't match the name */
3329 verify(nvlist_lookup_uint64_array(newnv
, ZPOOL_CONFIG_VDEV_STATS
,
3330 (uint64_t **)&newvs
, &c
) == 0);
3333 * Print the vdev name unless it's is a histogram. Histograms
3334 * display the vdev name in the header itself.
3336 if (!(cb
->cb_flags
& IOS_ANYHISTO_M
)) {
3337 if (cb
->cb_scripted
) {
3340 if (strlen(name
) + depth
> cb
->cb_namewidth
)
3341 (void) printf("%*s%s", depth
, "", name
);
3343 (void) printf("%*s%s%*s", depth
, "", name
,
3344 (int)(cb
->cb_namewidth
- strlen(name
) -
3349 /* Calculate our scaling factor */
3350 tdelta
= newvs
->vs_timestamp
- oldvs
->vs_timestamp
;
3351 if ((oldvs
->vs_timestamp
== 0) && (cb
->cb_flags
& IOS_ANYHISTO_M
)) {
3353 * If we specify printing histograms with no time interval, then
3354 * print the histogram numbers over the entire lifetime of the
3362 scale
= (double)NANOSEC
/ tdelta
;
3365 if (cb
->cb_flags
& IOS_DEFAULT_M
) {
3366 calc_default_iostats(oldvs
, newvs
, calcvs
);
3367 print_iostat_default(calcvs
, cb
, scale
);
3369 if (cb
->cb_flags
& IOS_LATENCY_M
)
3370 print_iostat_latency(cb
, oldnv
, newnv
, scale
);
3371 if (cb
->cb_flags
& IOS_QUEUES_M
)
3372 print_iostat_queues(cb
, oldnv
, newnv
, scale
);
3373 if (cb
->cb_flags
& IOS_ANYHISTO_M
) {
3375 print_iostat_histos(cb
, oldnv
, newnv
, scale
, name
);
3378 if (!(cb
->cb_flags
& IOS_ANYHISTO_M
))
3385 if (!cb
->cb_verbose
)
3388 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_CHILDREN
,
3389 &newchild
, &children
) != 0)
3392 if (oldnv
&& nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_CHILDREN
,
3393 &oldchild
, &c
) != 0)
3396 for (c
= 0; c
< children
; c
++) {
3397 uint64_t ishole
= B_FALSE
, islog
= B_FALSE
;
3399 (void) nvlist_lookup_uint64(newchild
[c
], ZPOOL_CONFIG_IS_HOLE
,
3402 (void) nvlist_lookup_uint64(newchild
[c
], ZPOOL_CONFIG_IS_LOG
,
3405 if (ishole
|| islog
)
3408 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
3410 ret
+= print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
] : NULL
,
3411 newchild
[c
], cb
, depth
+ 2);
3416 * Log device section
3419 if (num_logs(newnv
) > 0) {
3420 if ((!(cb
->cb_flags
& IOS_ANYHISTO_M
)) && !cb
->cb_scripted
&&
3421 !cb
->cb_vdev_names
) {
3422 print_iostat_dashes(cb
, 0, "logs");
3425 for (c
= 0; c
< children
; c
++) {
3426 uint64_t islog
= B_FALSE
;
3427 (void) nvlist_lookup_uint64(newchild
[c
],
3428 ZPOOL_CONFIG_IS_LOG
, &islog
);
3431 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
3433 ret
+= print_vdev_stats(zhp
, vname
, oldnv
?
3434 oldchild
[c
] : NULL
, newchild
[c
],
3443 * Include level 2 ARC devices in iostat output
3445 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_L2CACHE
,
3446 &newchild
, &children
) != 0)
3449 if (oldnv
&& nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_L2CACHE
,
3450 &oldchild
, &c
) != 0)
3454 if ((!(cb
->cb_flags
& IOS_ANYHISTO_M
)) && !cb
->cb_scripted
&&
3455 !cb
->cb_vdev_names
) {
3456 print_iostat_dashes(cb
, 0, "cache");
3459 for (c
= 0; c
< children
; c
++) {
3460 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
3462 ret
+= print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
]
3463 : NULL
, newchild
[c
], cb
, depth
+ 2);
3472 refresh_iostat(zpool_handle_t
*zhp
, void *data
)
3474 iostat_cbdata_t
*cb
= data
;
3478 * If the pool has disappeared, remove it from the list and continue.
3480 if (zpool_refresh_stats(zhp
, &missing
) != 0)
3484 pool_list_remove(cb
->cb_list
, zhp
);
3490 * Callback to print out the iostats for the given pool.
3493 print_iostat(zpool_handle_t
*zhp
, void *data
)
3495 iostat_cbdata_t
*cb
= data
;
3496 nvlist_t
*oldconfig
, *newconfig
;
3497 nvlist_t
*oldnvroot
, *newnvroot
;
3500 newconfig
= zpool_get_config(zhp
, &oldconfig
);
3502 if (cb
->cb_iteration
== 1)
3505 verify(nvlist_lookup_nvlist(newconfig
, ZPOOL_CONFIG_VDEV_TREE
,
3508 if (oldconfig
== NULL
)
3511 verify(nvlist_lookup_nvlist(oldconfig
, ZPOOL_CONFIG_VDEV_TREE
,
3514 ret
= print_vdev_stats(zhp
, zpool_get_name(zhp
), oldnvroot
, newnvroot
,
3516 if ((ret
!= 0) && !(cb
->cb_flags
& IOS_ANYHISTO_M
) &&
3517 !cb
->cb_scripted
&& cb
->cb_verbose
&& !cb
->cb_vdev_names_count
) {
3518 print_iostat_separator(cb
);
3531 if (isatty(STDOUT_FILENO
)) {
3532 error
= ioctl(STDOUT_FILENO
, TIOCGWINSZ
, &ws
);
3534 columns
= ws
.ws_col
;
3543 get_namewidth(zpool_handle_t
*zhp
, void *data
)
3545 iostat_cbdata_t
*cb
= data
;
3546 nvlist_t
*config
, *nvroot
;
3549 if ((config
= zpool_get_config(zhp
, NULL
)) != NULL
) {
3550 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
3552 unsigned int poolname_len
= strlen(zpool_get_name(zhp
));
3553 if (!cb
->cb_verbose
)
3554 cb
->cb_namewidth
= poolname_len
;
3556 cb
->cb_namewidth
= MAX(poolname_len
,
3557 max_width(zhp
, nvroot
, 0, cb
->cb_namewidth
,
3558 cb
->cb_name_flags
));
3561 * The width must be at least 10, but may be as large as the
3562 * column width - 42 so that we can still fit in one line.
3564 columns
= get_columns();
3566 if (cb
->cb_namewidth
< 10)
3567 cb
->cb_namewidth
= 10;
3568 if (cb
->cb_namewidth
> columns
- 42)
3569 cb
->cb_namewidth
= columns
- 42;
3575 * Parse the input string, get the 'interval' and 'count' value if there is one.
3578 get_interval_count(int *argcp
, char **argv
, float *iv
,
3582 unsigned long count
= 0;
3586 * Determine if the last argument is an integer or a pool name
3588 if (argc
> 0 && isnumber(argv
[argc
- 1])) {
3592 interval
= strtof(argv
[argc
- 1], &end
);
3594 if (*end
== '\0' && errno
== 0) {
3595 if (interval
== 0) {
3596 (void) fprintf(stderr
, gettext("interval "
3597 "cannot be zero\n"));
3601 * Ignore the last parameter
3606 * If this is not a valid number, just plow on. The
3607 * user will get a more informative error message later
3615 * If the last argument is also an integer, then we have both a count
3618 if (argc
> 0 && isnumber(argv
[argc
- 1])) {
3623 interval
= strtof(argv
[argc
- 1], &end
);
3625 if (*end
== '\0' && errno
== 0) {
3626 if (interval
== 0) {
3627 (void) fprintf(stderr
, gettext("interval "
3628 "cannot be zero\n"));
3633 * Ignore the last parameter
3647 get_timestamp_arg(char c
)
3650 timestamp_fmt
= UDATE
;
3652 timestamp_fmt
= DDATE
;
3658 * Return stat flags that are supported by all pools by both the module and
3659 * zpool iostat. "*data" should be initialized to all 0xFFs before running.
3660 * It will get ANDed down until only the flags that are supported on all pools
3664 get_stat_flags_cb(zpool_handle_t
*zhp
, void *data
)
3666 uint64_t *mask
= data
;
3667 nvlist_t
*config
, *nvroot
, *nvx
;
3671 config
= zpool_get_config(zhp
, NULL
);
3672 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
3675 /* Default stats are always supported, but for completeness.. */
3676 if (nvlist_exists(nvroot
, ZPOOL_CONFIG_VDEV_STATS
))
3677 flags
|= IOS_DEFAULT_M
;
3679 /* Get our extended stats nvlist from the main list */
3680 if (nvlist_lookup_nvlist(nvroot
, ZPOOL_CONFIG_VDEV_STATS_EX
,
3683 * No extended stats; they're probably running an older
3684 * module. No big deal, we support that too.
3689 /* For each extended stat, make sure all its nvpairs are supported */
3690 for (j
= 0; j
< ARRAY_SIZE(vsx_type_to_nvlist
); j
++) {
3691 if (!vsx_type_to_nvlist
[j
][0])
3694 /* Start off by assuming the flag is supported, then check */
3695 flags
|= (1ULL << j
);
3696 for (i
= 0; vsx_type_to_nvlist
[j
][i
]; i
++) {
3697 if (!nvlist_exists(nvx
, vsx_type_to_nvlist
[j
][i
])) {
3698 /* flag isn't supported */
3699 flags
= flags
& ~(1ULL << j
);
3705 *mask
= *mask
& flags
;
3710 * Return a bitmask of stats that are supported on all pools by both the module
3714 get_stat_flags(zpool_list_t
*list
)
3719 * get_stat_flags_cb() will lop off bits from "mask" until only the
3720 * flags that are supported on all pools remain.
3722 pool_list_iter(list
, B_FALSE
, get_stat_flags_cb
, &mask
);
3727 * Return 1 if cb_data->cb_vdev_names[0] is this vdev's name, 0 otherwise.
3730 is_vdev_cb(zpool_handle_t
*zhp
, nvlist_t
*nv
, void *cb_data
)
3732 iostat_cbdata_t
*cb
= cb_data
;
3735 name
= zpool_vdev_name(g_zfs
, zhp
, nv
, cb
->cb_name_flags
);
3737 if (strcmp(name
, cb
->cb_vdev_names
[0]) == 0)
3738 return (1); /* match */
3744 * Returns 1 if cb_data->cb_vdev_names[0] is a vdev name, 0 otherwise.
3747 is_vdev(zpool_handle_t
*zhp
, void *cb_data
)
3749 return (for_each_vdev(zhp
, is_vdev_cb
, cb_data
));
3753 * Check if vdevs are in a pool
3755 * Return 1 if all argv[] strings are vdev names in pool "pool_name". Otherwise
3756 * return 0. If pool_name is NULL, then search all pools.
3759 are_vdevs_in_pool(int argc
, char **argv
, char *pool_name
,
3760 iostat_cbdata_t
*cb
)
3767 if ((argc
== 0) || !*argv
)
3773 /* Temporarily hijack cb_vdev_names for a second... */
3774 tmp_name
= cb
->cb_vdev_names
;
3776 /* Go though our list of prospective vdev names */
3777 for (i
= 0; i
< argc
; i
++) {
3778 cb
->cb_vdev_names
= argv
+ i
;
3780 /* Is this name a vdev in our pools? */
3781 ret
= for_each_pool(pool_count
, &pool_name
, B_TRUE
, NULL
,
3789 cb
->cb_vdev_names
= tmp_name
;
3795 is_pool_cb(zpool_handle_t
*zhp
, void *data
)
3798 if (strcmp(name
, zpool_get_name(zhp
)) == 0)
3805 * Do we have a pool named *name? If so, return 1, otherwise 0.
3810 return (for_each_pool(0, NULL
, B_TRUE
, NULL
, is_pool_cb
, name
));
3813 /* Are all our argv[] strings pool names? If so return 1, 0 otherwise. */
3815 are_all_pools(int argc
, char **argv
) {
3816 if ((argc
== 0) || !*argv
)
3820 if (!is_pool(argv
[argc
]))
3827 * Helper function to print out vdev/pool names we can't resolve. Used for an
3831 error_list_unresolved_vdevs(int argc
, char **argv
, char *pool_name
,
3832 iostat_cbdata_t
*cb
)
3837 for (i
= 0; i
< argc
; i
++) {
3841 str
= gettext("pool");
3842 else if (are_vdevs_in_pool(1, &name
, pool_name
, cb
))
3843 str
= gettext("vdev in this pool");
3844 else if (are_vdevs_in_pool(1, &name
, NULL
, cb
))
3845 str
= gettext("vdev in another pool");
3847 str
= gettext("unknown");
3849 fprintf(stderr
, "\t%s (%s)\n", name
, str
);
3854 * Same as get_interval_count(), but with additional checks to not misinterpret
3855 * guids as interval/count values. Assumes VDEV_NAME_GUID is set in
3859 get_interval_count_filter_guids(int *argc
, char **argv
, float *interval
,
3860 unsigned long *count
, iostat_cbdata_t
*cb
)
3862 char **tmpargv
= argv
;
3863 int argc_for_interval
= 0;
3865 /* Is the last arg an interval value? Or a guid? */
3866 if (*argc
>= 1 && !are_vdevs_in_pool(1, &argv
[*argc
- 1], NULL
, cb
)) {
3868 * The last arg is not a guid, so it's probably an
3871 argc_for_interval
++;
3874 !are_vdevs_in_pool(1, &argv
[*argc
- 2], NULL
, cb
)) {
3876 * The 2nd to last arg is not a guid, so it's probably
3877 * an interval value.
3879 argc_for_interval
++;
3883 /* Point to our list of possible intervals */
3884 tmpargv
= &argv
[*argc
- argc_for_interval
];
3886 *argc
= *argc
- argc_for_interval
;
3887 get_interval_count(&argc_for_interval
, tmpargv
,
3892 * Floating point sleep(). Allows you to pass in a floating point value for
3897 struct timespec req
;
3898 req
.tv_sec
= floor(sec
);
3899 req
.tv_nsec
= (sec
- (float)req
.tv_sec
) * NANOSEC
;
3900 nanosleep(&req
, NULL
);
3905 * zpool iostat [-ghHLpPvy] [[-lq]|[-r|-w]] [-n name] [-T d|u]
3906 * [[ pool ...]|[pool vdev ...]|[vdev ...]]
3907 * [interval [count]]
3909 * -g Display guid for individual vdev name.
3910 * -L Follow links when resolving vdev path name.
3911 * -P Display full path for vdev name.
3912 * -v Display statistics for individual vdevs
3914 * -p Display values in parsable (exact) format.
3915 * -H Scripted mode. Don't display headers, and separate properties
3917 * -l Display average latency
3918 * -q Display queue depths
3919 * -w Display latency histograms
3920 * -r Display request size histogram
3921 * -T Display a timestamp in date(1) or Unix format
3923 * This command can be tricky because we want to be able to deal with pool
3924 * creation/destruction as well as vdev configuration changes. The bulk of this
3925 * processing is handled by the pool_list_* routines in zpool_iter.c. We rely
3926 * on pool_list_update() to detect the addition of new pools. Configuration
3927 * changes are all handled within libzfs.
3930 zpool_do_iostat(int argc
, char **argv
)
3936 unsigned long count
= 0;
3938 boolean_t verbose
= B_FALSE
;
3939 boolean_t latency
= B_FALSE
, l_histo
= B_FALSE
, rq_histo
= B_FALSE
;
3940 boolean_t queues
= B_FALSE
, parsable
= B_FALSE
, scripted
= B_FALSE
;
3941 boolean_t omit_since_boot
= B_FALSE
;
3942 boolean_t guid
= B_FALSE
;
3943 boolean_t follow_links
= B_FALSE
;
3944 boolean_t full_name
= B_FALSE
;
3945 iostat_cbdata_t cb
= { 0 };
3947 /* Used for printing error message */
3948 const char flag_to_arg
[] = {[IOS_LATENCY
] = 'l', [IOS_QUEUES
] = 'q',
3949 [IOS_L_HISTO
] = 'w', [IOS_RQ_HISTO
] = 'r'};
3951 uint64_t unsupported_flags
;
3954 while ((c
= getopt(argc
, argv
, "gLPT:vyhplqrwH")) != -1) {
3960 follow_links
= B_TRUE
;
3966 get_timestamp_arg(*optarg
);
3990 omit_since_boot
= B_TRUE
;
3996 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4005 cb
.cb_literal
= parsable
;
4006 cb
.cb_scripted
= scripted
;
4009 cb
.cb_name_flags
|= VDEV_NAME_GUID
;
4011 cb
.cb_name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
4013 cb
.cb_name_flags
|= VDEV_NAME_PATH
;
4014 cb
.cb_iteration
= 0;
4015 cb
.cb_namewidth
= 0;
4016 cb
.cb_verbose
= verbose
;
4018 /* Get our interval and count values (if any) */
4020 get_interval_count_filter_guids(&argc
, argv
, &interval
,
4023 get_interval_count(&argc
, argv
, &interval
, &count
);
4027 /* No args, so just print the defaults. */
4028 } else if (are_all_pools(argc
, argv
)) {
4029 /* All the args are pool names */
4030 } else if (are_vdevs_in_pool(argc
, argv
, NULL
, &cb
)) {
4031 /* All the args are vdevs */
4032 cb
.cb_vdev_names
= argv
;
4033 cb
.cb_vdev_names_count
= argc
;
4034 argc
= 0; /* No pools to process */
4035 } else if (are_all_pools(1, argv
)) {
4036 /* The first arg is a pool name */
4037 if (are_vdevs_in_pool(argc
- 1, argv
+ 1, argv
[0], &cb
)) {
4038 /* ...and the rest are vdev names */
4039 cb
.cb_vdev_names
= argv
+ 1;
4040 cb
.cb_vdev_names_count
= argc
- 1;
4041 argc
= 1; /* One pool to process */
4043 fprintf(stderr
, gettext("Expected either a list of "));
4044 fprintf(stderr
, gettext("pools, or list of vdevs in"));
4045 fprintf(stderr
, " \"%s\", ", argv
[0]);
4046 fprintf(stderr
, gettext("but got:\n"));
4047 error_list_unresolved_vdevs(argc
- 1, argv
+ 1,
4049 fprintf(stderr
, "\n");
4055 * The args don't make sense. The first arg isn't a pool name,
4056 * nor are all the args vdevs.
4058 fprintf(stderr
, gettext("Unable to parse pools/vdevs list.\n"));
4059 fprintf(stderr
, "\n");
4063 if (cb
.cb_vdev_names_count
!= 0) {
4065 * If user specified vdevs, it implies verbose.
4067 cb
.cb_verbose
= B_TRUE
;
4071 * Construct the list of all interesting pools.
4074 if ((list
= pool_list_get(argc
, argv
, NULL
, &ret
)) == NULL
)
4077 if (pool_list_count(list
) == 0 && argc
!= 0) {
4078 pool_list_free(list
);
4082 if (pool_list_count(list
) == 0 && interval
== 0) {
4083 pool_list_free(list
);
4084 (void) fprintf(stderr
, gettext("no pools available\n"));
4088 if ((l_histo
|| rq_histo
) && (queues
|| latency
)) {
4089 pool_list_free(list
);
4090 (void) fprintf(stderr
,
4091 gettext("[-r|-w] isn't allowed with [-q|-l]\n"));
4096 if (l_histo
&& rq_histo
) {
4097 pool_list_free(list
);
4098 (void) fprintf(stderr
,
4099 gettext("Only one of [-r|-w] can be passed at a time\n"));
4105 * Enter the main iostat loop.
4111 * Histograms tables look out of place when you try to display
4112 * them with the other stats, so make a rule that you can only
4113 * print histograms by themselves.
4115 cb
.cb_flags
= IOS_L_HISTO_M
;
4116 } else if (rq_histo
) {
4117 cb
.cb_flags
= IOS_RQ_HISTO_M
;
4119 cb
.cb_flags
= IOS_DEFAULT_M
;
4121 cb
.cb_flags
|= IOS_LATENCY_M
;
4123 cb
.cb_flags
|= IOS_QUEUES_M
;
4127 * See if the module supports all the stats we want to display.
4129 unsupported_flags
= cb
.cb_flags
& ~get_stat_flags(list
);
4130 if (unsupported_flags
) {
4134 gettext("The loaded zfs module doesn't support:"));
4136 /* for each bit set in unsupported_flags */
4137 for (f
= unsupported_flags
; f
; f
&= ~(1ULL << idx
)) {
4138 idx
= lowbit64(f
) - 1;
4139 fprintf(stderr
, " -%c", flag_to_arg
[idx
]);
4142 fprintf(stderr
, ". Try running a newer module.\n"),
4143 pool_list_free(list
);
4150 if ((npools
= pool_list_count(list
)) == 0)
4151 (void) fprintf(stderr
, gettext("no pools available\n"));
4154 * If this is the first iteration and -y was supplied
4155 * we skip any printing.
4157 boolean_t skip
= (omit_since_boot
&&
4158 cb
.cb_iteration
== 0);
4161 * Refresh all statistics. This is done as an
4162 * explicit step before calculating the maximum name
4163 * width, so that any * configuration changes are
4164 * properly accounted for.
4166 (void) pool_list_iter(list
, B_FALSE
, refresh_iostat
,
4170 * Iterate over all pools to determine the maximum width
4171 * for the pool / device name column across all pools.
4173 cb
.cb_namewidth
= 0;
4174 (void) pool_list_iter(list
, B_FALSE
, get_namewidth
,
4177 if (timestamp_fmt
!= NODATE
)
4178 print_timestamp(timestamp_fmt
);
4181 * If it's the first time and we're not skipping it,
4182 * or either skip or verbose mode, print the header.
4184 * The histogram code explicitly prints its header on
4185 * every vdev, so skip this for histograms.
4187 if (((++cb
.cb_iteration
== 1 && !skip
) ||
4188 (skip
!= verbose
)) &&
4189 (!(cb
.cb_flags
& IOS_ANYHISTO_M
)) &&
4191 print_iostat_header(&cb
);
4194 (void) fsleep(interval
);
4198 pool_list_iter(list
, B_FALSE
, print_iostat
, &cb
);
4201 * If there's more than one pool, and we're not in
4202 * verbose mode (which prints a separator for us),
4203 * then print a separator.
4205 * In addition, if we're printing specific vdevs then
4206 * we also want an ending separator.
4208 if (((npools
> 1 && !verbose
&&
4209 !(cb
.cb_flags
& IOS_ANYHISTO_M
)) ||
4210 (!(cb
.cb_flags
& IOS_ANYHISTO_M
) &&
4211 cb
.cb_vdev_names_count
)) &&
4213 print_iostat_separator(&cb
);
4218 * Flush the output so that redirection to a file isn't buffered
4221 (void) fflush(stdout
);
4226 if (count
!= 0 && --count
== 0)
4229 (void) fsleep(interval
);
4232 pool_list_free(list
);
4237 typedef struct list_cbdata
{
4238 boolean_t cb_verbose
;
4241 boolean_t cb_scripted
;
4242 zprop_list_t
*cb_proplist
;
4243 boolean_t cb_literal
;
4247 * Given a list of columns to display, output appropriate headers for each one.
4250 print_header(list_cbdata_t
*cb
)
4252 zprop_list_t
*pl
= cb
->cb_proplist
;
4253 char headerbuf
[ZPOOL_MAXPROPLEN
];
4255 boolean_t first
= B_TRUE
;
4256 boolean_t right_justify
;
4259 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
4260 width
= pl
->pl_width
;
4261 if (first
&& cb
->cb_verbose
) {
4263 * Reset the width to accommodate the verbose listing
4266 width
= cb
->cb_namewidth
;
4274 right_justify
= B_FALSE
;
4275 if (pl
->pl_prop
!= ZPROP_INVAL
) {
4276 header
= zpool_prop_column_name(pl
->pl_prop
);
4277 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
4281 for (i
= 0; pl
->pl_user_prop
[i
] != '\0'; i
++)
4282 headerbuf
[i
] = toupper(pl
->pl_user_prop
[i
]);
4283 headerbuf
[i
] = '\0';
4287 if (pl
->pl_next
== NULL
&& !right_justify
)
4288 (void) printf("%s", header
);
4289 else if (right_justify
)
4290 (void) printf("%*s", (int)width
, header
);
4292 (void) printf("%-*s", (int)width
, header
);
4295 (void) printf("\n");
4299 * Given a pool and a list of properties, print out all the properties according
4300 * to the described layout.
4303 print_pool(zpool_handle_t
*zhp
, list_cbdata_t
*cb
)
4305 zprop_list_t
*pl
= cb
->cb_proplist
;
4306 boolean_t first
= B_TRUE
;
4307 char property
[ZPOOL_MAXPROPLEN
];
4309 boolean_t right_justify
;
4312 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
4314 width
= pl
->pl_width
;
4315 if (first
&& cb
->cb_verbose
) {
4317 * Reset the width to accommodate the verbose listing
4320 width
= cb
->cb_namewidth
;
4324 if (cb
->cb_scripted
)
4325 (void) printf("\t");
4332 right_justify
= B_FALSE
;
4333 if (pl
->pl_prop
!= ZPROP_INVAL
) {
4334 if (zpool_get_prop(zhp
, pl
->pl_prop
, property
,
4335 sizeof (property
), NULL
, cb
->cb_literal
) != 0)
4340 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
4341 } else if ((zpool_prop_feature(pl
->pl_user_prop
) ||
4342 zpool_prop_unsupported(pl
->pl_user_prop
)) &&
4343 zpool_prop_get_feature(zhp
, pl
->pl_user_prop
, property
,
4344 sizeof (property
)) == 0) {
4352 * If this is being called in scripted mode, or if this is the
4353 * last column and it is left-justified, don't include a width
4356 if (cb
->cb_scripted
|| (pl
->pl_next
== NULL
&& !right_justify
))
4357 (void) printf("%s", propstr
);
4358 else if (right_justify
)
4359 (void) printf("%*s", (int)width
, propstr
);
4361 (void) printf("%-*s", (int)width
, propstr
);
4364 (void) printf("\n");
4368 print_one_column(zpool_prop_t prop
, uint64_t value
, boolean_t scripted
,
4369 boolean_t valid
, enum zfs_nicenum_format format
)
4373 size_t width
= zprop_width(prop
, &fixed
, ZFS_TYPE_POOL
);
4376 case ZPOOL_PROP_EXPANDSZ
:
4378 (void) strlcpy(propval
, "-", sizeof (propval
));
4380 zfs_nicenum_format(value
, propval
, sizeof (propval
),
4383 case ZPOOL_PROP_FRAGMENTATION
:
4384 if (value
== ZFS_FRAG_INVALID
) {
4385 (void) strlcpy(propval
, "-", sizeof (propval
));
4386 } else if (format
== ZFS_NICENUM_RAW
) {
4387 (void) snprintf(propval
, sizeof (propval
), "%llu",
4388 (unsigned long long)value
);
4390 (void) snprintf(propval
, sizeof (propval
), "%llu%%",
4391 (unsigned long long)value
);
4394 case ZPOOL_PROP_CAPACITY
:
4395 if (format
== ZFS_NICENUM_RAW
)
4396 (void) snprintf(propval
, sizeof (propval
), "%llu",
4397 (unsigned long long)value
);
4399 (void) snprintf(propval
, sizeof (propval
), "%llu%%",
4400 (unsigned long long)value
);
4403 zfs_nicenum_format(value
, propval
, sizeof (propval
), format
);
4407 (void) strlcpy(propval
, "-", sizeof (propval
));
4410 (void) printf("\t%s", propval
);
4412 (void) printf(" %*s", (int)width
, propval
);
4416 print_list_stats(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
,
4417 list_cbdata_t
*cb
, int depth
)
4423 boolean_t scripted
= cb
->cb_scripted
;
4424 uint64_t islog
= B_FALSE
;
4425 boolean_t haslog
= B_FALSE
;
4426 char *dashes
= "%-*s - - - - - -\n";
4428 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
4429 (uint64_t **)&vs
, &c
) == 0);
4432 boolean_t toplevel
= (vs
->vs_space
!= 0);
4434 enum zfs_nicenum_format format
;
4437 format
= ZFS_NICENUM_RAW
;
4439 format
= ZFS_NICENUM_1024
;
4442 (void) printf("\t%s", name
);
4443 else if (strlen(name
) + depth
> cb
->cb_namewidth
)
4444 (void) printf("%*s%s", depth
, "", name
);
4446 (void) printf("%*s%s%*s", depth
, "", name
,
4447 (int)(cb
->cb_namewidth
- strlen(name
) - depth
), "");
4450 * Print the properties for the individual vdevs. Some
4451 * properties are only applicable to toplevel vdevs. The
4452 * 'toplevel' boolean value is passed to the print_one_column()
4453 * to indicate that the value is valid.
4455 print_one_column(ZPOOL_PROP_SIZE
, vs
->vs_space
, scripted
,
4457 print_one_column(ZPOOL_PROP_ALLOCATED
, vs
->vs_alloc
, scripted
,
4459 print_one_column(ZPOOL_PROP_FREE
, vs
->vs_space
- vs
->vs_alloc
,
4460 scripted
, toplevel
, format
);
4461 print_one_column(ZPOOL_PROP_EXPANDSZ
, vs
->vs_esize
, scripted
,
4463 print_one_column(ZPOOL_PROP_FRAGMENTATION
,
4464 vs
->vs_fragmentation
, scripted
,
4465 (vs
->vs_fragmentation
!= ZFS_FRAG_INVALID
&& toplevel
),
4467 cap
= (vs
->vs_space
== 0) ? 0 :
4468 (vs
->vs_alloc
* 100 / vs
->vs_space
);
4469 print_one_column(ZPOOL_PROP_CAPACITY
, cap
, scripted
, toplevel
,
4471 (void) printf("\n");
4474 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
4475 &child
, &children
) != 0)
4478 for (c
= 0; c
< children
; c
++) {
4479 uint64_t ishole
= B_FALSE
;
4481 if (nvlist_lookup_uint64(child
[c
],
4482 ZPOOL_CONFIG_IS_HOLE
, &ishole
) == 0 && ishole
)
4485 if (nvlist_lookup_uint64(child
[c
],
4486 ZPOOL_CONFIG_IS_LOG
, &islog
) == 0 && islog
) {
4491 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
4493 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
4497 if (haslog
== B_TRUE
) {
4498 /* LINTED E_SEC_PRINTF_VAR_FMT */
4499 (void) printf(dashes
, cb
->cb_namewidth
, "log");
4500 for (c
= 0; c
< children
; c
++) {
4501 if (nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
4502 &islog
) != 0 || !islog
)
4504 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
4506 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
4511 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
4512 &child
, &children
) == 0 && children
> 0) {
4513 /* LINTED E_SEC_PRINTF_VAR_FMT */
4514 (void) printf(dashes
, cb
->cb_namewidth
, "cache");
4515 for (c
= 0; c
< children
; c
++) {
4516 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
4518 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
4523 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
, &child
,
4524 &children
) == 0 && children
> 0) {
4525 /* LINTED E_SEC_PRINTF_VAR_FMT */
4526 (void) printf(dashes
, cb
->cb_namewidth
, "spare");
4527 for (c
= 0; c
< children
; c
++) {
4528 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
4530 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
4538 * Generic callback function to list a pool.
4541 list_callback(zpool_handle_t
*zhp
, void *data
)
4543 list_cbdata_t
*cbp
= data
;
4547 config
= zpool_get_config(zhp
, NULL
);
4549 print_pool(zhp
, cbp
);
4550 if (!cbp
->cb_verbose
)
4553 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
4555 print_list_stats(zhp
, NULL
, nvroot
, cbp
, 0);
4561 * zpool list [-gHLpP] [-o prop[,prop]*] [-T d|u] [pool] ... [interval [count]]
4563 * -g Display guid for individual vdev name.
4564 * -H Scripted mode. Don't display headers, and separate properties
4566 * -L Follow links when resolving vdev path name.
4567 * -o List of properties to display. Defaults to
4568 * "name,size,allocated,free,expandsize,fragmentation,capacity,"
4569 * "dedupratio,health,altroot"
4570 * -p Display values in parsable (exact) format.
4571 * -P Display full path for vdev name.
4572 * -T Display a timestamp in date(1) or Unix format
4574 * List all pools in the system, whether or not they're healthy. Output space
4575 * statistics for each one, as well as health status summary.
4578 zpool_do_list(int argc
, char **argv
)
4582 list_cbdata_t cb
= { 0 };
4583 static char default_props
[] =
4584 "name,size,allocated,free,expandsize,fragmentation,capacity,"
4585 "dedupratio,health,altroot";
4586 char *props
= default_props
;
4588 unsigned long count
= 0;
4590 boolean_t first
= B_TRUE
;
4593 while ((c
= getopt(argc
, argv
, ":gHLo:pPT:v")) != -1) {
4596 cb
.cb_name_flags
|= VDEV_NAME_GUID
;
4599 cb
.cb_scripted
= B_TRUE
;
4602 cb
.cb_name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
4608 cb
.cb_name_flags
|= VDEV_NAME_PATH
;
4611 cb
.cb_literal
= B_TRUE
;
4614 get_timestamp_arg(*optarg
);
4617 cb
.cb_verbose
= B_TRUE
;
4620 (void) fprintf(stderr
, gettext("missing argument for "
4621 "'%c' option\n"), optopt
);
4625 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4634 get_interval_count(&argc
, argv
, &interval
, &count
);
4636 if (zprop_get_list(g_zfs
, props
, &cb
.cb_proplist
, ZFS_TYPE_POOL
) != 0)
4640 if ((list
= pool_list_get(argc
, argv
, &cb
.cb_proplist
,
4644 if (pool_list_count(list
) == 0)
4647 if (timestamp_fmt
!= NODATE
)
4648 print_timestamp(timestamp_fmt
);
4650 if (!cb
.cb_scripted
&& (first
|| cb
.cb_verbose
)) {
4654 ret
= pool_list_iter(list
, B_TRUE
, list_callback
, &cb
);
4659 if (count
!= 0 && --count
== 0)
4662 pool_list_free(list
);
4663 (void) fsleep(interval
);
4666 if (argc
== 0 && !cb
.cb_scripted
&& pool_list_count(list
) == 0) {
4667 (void) printf(gettext("no pools available\n"));
4671 pool_list_free(list
);
4672 zprop_free_list(cb
.cb_proplist
);
4677 zpool_do_attach_or_replace(int argc
, char **argv
, int replacing
)
4679 boolean_t force
= B_FALSE
;
4682 char *poolname
, *old_disk
, *new_disk
;
4683 zpool_handle_t
*zhp
;
4684 nvlist_t
*props
= NULL
;
4689 while ((c
= getopt(argc
, argv
, "fo:")) != -1) {
4695 if ((propval
= strchr(optarg
, '=')) == NULL
) {
4696 (void) fprintf(stderr
, gettext("missing "
4697 "'=' for -o option\n"));
4703 if ((strcmp(optarg
, ZPOOL_CONFIG_ASHIFT
) != 0) ||
4704 (add_prop_list(optarg
, propval
, &props
, B_TRUE
)))
4708 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4717 /* get pool name and check number of arguments */
4719 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
4726 (void) fprintf(stderr
,
4727 gettext("missing <device> specification\n"));
4735 (void) fprintf(stderr
,
4736 gettext("missing <new_device> specification\n"));
4739 new_disk
= old_disk
;
4749 (void) fprintf(stderr
, gettext("too many arguments\n"));
4753 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
4756 if (zpool_get_config(zhp
, NULL
) == NULL
) {
4757 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
4763 nvroot
= make_root_vdev(zhp
, props
, force
, B_FALSE
, replacing
, B_FALSE
,
4765 if (nvroot
== NULL
) {
4770 ret
= zpool_vdev_attach(zhp
, old_disk
, new_disk
, nvroot
, replacing
);
4772 nvlist_free(nvroot
);
4779 * zpool replace [-f] <pool> <device> <new_device>
4781 * -f Force attach, even if <new_device> appears to be in use.
4783 * Replace <device> with <new_device>.
4787 zpool_do_replace(int argc
, char **argv
)
4789 return (zpool_do_attach_or_replace(argc
, argv
, B_TRUE
));
4793 * zpool attach [-f] [-o property=value] <pool> <device> <new_device>
4795 * -f Force attach, even if <new_device> appears to be in use.
4796 * -o Set property=value.
4798 * Attach <new_device> to the mirror containing <device>. If <device> is not
4799 * part of a mirror, then <device> will be transformed into a mirror of
4800 * <device> and <new_device>. In either case, <new_device> will begin life
4801 * with a DTL of [0, now], and will immediately begin to resilver itself.
4804 zpool_do_attach(int argc
, char **argv
)
4806 return (zpool_do_attach_or_replace(argc
, argv
, B_FALSE
));
4810 * zpool detach [-f] <pool> <device>
4812 * -f Force detach of <device>, even if DTLs argue against it
4813 * (not supported yet)
4815 * Detach a device from a mirror. The operation will be refused if <device>
4816 * is the last device in the mirror, or if the DTLs indicate that this device
4817 * has the only valid copy of some data.
4821 zpool_do_detach(int argc
, char **argv
)
4824 char *poolname
, *path
;
4825 zpool_handle_t
*zhp
;
4829 while ((c
= getopt(argc
, argv
, "f")) != -1) {
4833 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4842 /* get pool name and check number of arguments */
4844 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
4849 (void) fprintf(stderr
,
4850 gettext("missing <device> specification\n"));
4857 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
4860 ret
= zpool_vdev_detach(zhp
, path
);
4868 * zpool split [-gLnP] [-o prop=val] ...
4870 * [-R altroot] <pool> <newpool> [<device> ...]
4872 * -g Display guid for individual vdev name.
4873 * -L Follow links when resolving vdev path name.
4874 * -n Do not split the pool, but display the resulting layout if
4875 * it were to be split.
4876 * -o Set property=value, or set mount options.
4877 * -P Display full path for vdev name.
4878 * -R Mount the split-off pool under an alternate root.
4880 * Splits the named pool and gives it the new pool name. Devices to be split
4881 * off may be listed, provided that no more than one device is specified
4882 * per top-level vdev mirror. The newly split pool is left in an exported
4883 * state unless -R is specified.
4885 * Restrictions: the top-level of the pool pool must only be made up of
4886 * mirrors; all devices in the pool must be healthy; no device may be
4887 * undergoing a resilvering operation.
4890 zpool_do_split(int argc
, char **argv
)
4892 char *srcpool
, *newpool
, *propval
;
4893 char *mntopts
= NULL
;
4896 zpool_handle_t
*zhp
;
4897 nvlist_t
*config
, *props
= NULL
;
4899 flags
.dryrun
= B_FALSE
;
4900 flags
.import
= B_FALSE
;
4901 flags
.name_flags
= 0;
4904 while ((c
= getopt(argc
, argv
, ":gLR:no:P")) != -1) {
4907 flags
.name_flags
|= VDEV_NAME_GUID
;
4910 flags
.name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
4913 flags
.import
= B_TRUE
;
4915 zpool_prop_to_name(ZPOOL_PROP_ALTROOT
), optarg
,
4916 &props
, B_TRUE
) != 0) {
4922 flags
.dryrun
= B_TRUE
;
4925 if ((propval
= strchr(optarg
, '=')) != NULL
) {
4928 if (add_prop_list(optarg
, propval
,
4929 &props
, B_TRUE
) != 0) {
4938 flags
.name_flags
|= VDEV_NAME_PATH
;
4941 (void) fprintf(stderr
, gettext("missing argument for "
4942 "'%c' option\n"), optopt
);
4946 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4953 if (!flags
.import
&& mntopts
!= NULL
) {
4954 (void) fprintf(stderr
, gettext("setting mntopts is only "
4955 "valid when importing the pool\n"));
4963 (void) fprintf(stderr
, gettext("Missing pool name\n"));
4967 (void) fprintf(stderr
, gettext("Missing new pool name\n"));
4977 if ((zhp
= zpool_open(g_zfs
, srcpool
)) == NULL
)
4980 config
= split_mirror_vdev(zhp
, newpool
, props
, flags
, argc
, argv
);
4981 if (config
== NULL
) {
4985 (void) printf(gettext("would create '%s' with the "
4986 "following layout:\n\n"), newpool
);
4987 print_vdev_tree(NULL
, newpool
, config
, 0, B_FALSE
,
4990 nvlist_free(config
);
4995 if (ret
!= 0 || flags
.dryrun
|| !flags
.import
)
4999 * The split was successful. Now we need to open the new
5000 * pool and import it.
5002 if ((zhp
= zpool_open_canfail(g_zfs
, newpool
)) == NULL
)
5004 if (zpool_get_state(zhp
) != POOL_STATE_UNAVAIL
&&
5005 zpool_enable_datasets(zhp
, mntopts
, 0) != 0) {
5007 (void) fprintf(stderr
, gettext("Split was successful, but "
5008 "the datasets could not all be mounted\n"));
5009 (void) fprintf(stderr
, gettext("Try doing '%s' with a "
5010 "different altroot\n"), "zpool import");
5020 * zpool online <pool> <device> ...
5023 zpool_do_online(int argc
, char **argv
)
5027 zpool_handle_t
*zhp
;
5029 vdev_state_t newstate
;
5033 while ((c
= getopt(argc
, argv
, "et")) != -1) {
5036 flags
|= ZFS_ONLINE_EXPAND
;
5040 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5049 /* get pool name and check number of arguments */
5051 (void) fprintf(stderr
, gettext("missing pool name\n"));
5055 (void) fprintf(stderr
, gettext("missing device name\n"));
5061 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
5064 for (i
= 1; i
< argc
; i
++) {
5065 if (zpool_vdev_online(zhp
, argv
[i
], flags
, &newstate
) == 0) {
5066 if (newstate
!= VDEV_STATE_HEALTHY
) {
5067 (void) printf(gettext("warning: device '%s' "
5068 "onlined, but remains in faulted state\n"),
5070 if (newstate
== VDEV_STATE_FAULTED
)
5071 (void) printf(gettext("use 'zpool "
5072 "clear' to restore a faulted "
5075 (void) printf(gettext("use 'zpool "
5076 "replace' to replace devices "
5077 "that are no longer present\n"));
5090 * zpool offline [-ft] <pool> <device> ...
5092 * -f Force the device into the offline state, even if doing
5093 * so would appear to compromise pool availability.
5094 * (not supported yet)
5096 * -t Only take the device off-line temporarily. The offline
5097 * state will not be persistent across reboots.
5101 zpool_do_offline(int argc
, char **argv
)
5105 zpool_handle_t
*zhp
;
5107 boolean_t istmp
= B_FALSE
;
5110 while ((c
= getopt(argc
, argv
, "ft")) != -1) {
5117 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5126 /* get pool name and check number of arguments */
5128 (void) fprintf(stderr
, gettext("missing pool name\n"));
5132 (void) fprintf(stderr
, gettext("missing device name\n"));
5138 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
5141 for (i
= 1; i
< argc
; i
++) {
5142 if (zpool_vdev_offline(zhp
, argv
[i
], istmp
) != 0)
5152 * zpool clear <pool> [device]
5154 * Clear all errors associated with a pool or a particular device.
5157 zpool_do_clear(int argc
, char **argv
)
5161 boolean_t dryrun
= B_FALSE
;
5162 boolean_t do_rewind
= B_FALSE
;
5163 boolean_t xtreme_rewind
= B_FALSE
;
5164 uint32_t rewind_policy
= ZPOOL_NO_REWIND
;
5165 nvlist_t
*policy
= NULL
;
5166 zpool_handle_t
*zhp
;
5167 char *pool
, *device
;
5170 while ((c
= getopt(argc
, argv
, "FnX")) != -1) {
5179 xtreme_rewind
= B_TRUE
;
5182 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5192 (void) fprintf(stderr
, gettext("missing pool name\n"));
5197 (void) fprintf(stderr
, gettext("too many arguments\n"));
5201 if ((dryrun
|| xtreme_rewind
) && !do_rewind
) {
5202 (void) fprintf(stderr
,
5203 gettext("-n or -X only meaningful with -F\n"));
5207 rewind_policy
= ZPOOL_TRY_REWIND
;
5209 rewind_policy
= ZPOOL_DO_REWIND
;
5211 rewind_policy
|= ZPOOL_EXTREME_REWIND
;
5213 /* In future, further rewind policy choices can be passed along here */
5214 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME
, 0) != 0 ||
5215 nvlist_add_uint32(policy
, ZPOOL_REWIND_REQUEST
, rewind_policy
) != 0)
5219 device
= argc
== 2 ? argv
[1] : NULL
;
5221 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
) {
5222 nvlist_free(policy
);
5226 if (zpool_clear(zhp
, device
, policy
) != 0)
5231 nvlist_free(policy
);
5237 * zpool reguid <pool>
5240 zpool_do_reguid(int argc
, char **argv
)
5244 zpool_handle_t
*zhp
;
5248 while ((c
= getopt(argc
, argv
, "")) != -1) {
5251 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5260 /* get pool name and check number of arguments */
5262 (void) fprintf(stderr
, gettext("missing pool name\n"));
5267 (void) fprintf(stderr
, gettext("too many arguments\n"));
5272 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
5275 ret
= zpool_reguid(zhp
);
5283 * zpool reopen <pool>
5285 * Reopen the pool so that the kernel can update the sizes of all vdevs.
5288 zpool_do_reopen(int argc
, char **argv
)
5292 zpool_handle_t
*zhp
;
5296 while ((c
= getopt(argc
, argv
, "")) != -1) {
5299 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5309 (void) fprintf(stderr
, gettext("missing pool name\n"));
5314 (void) fprintf(stderr
, gettext("too many arguments\n"));
5319 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
)
5322 ret
= zpool_reopen(zhp
);
5327 typedef struct scrub_cbdata
{
5334 scrub_callback(zpool_handle_t
*zhp
, void *data
)
5336 scrub_cbdata_t
*cb
= data
;
5340 * Ignore faulted pools.
5342 if (zpool_get_state(zhp
) == POOL_STATE_UNAVAIL
) {
5343 (void) fprintf(stderr
, gettext("cannot scrub '%s': pool is "
5344 "currently unavailable\n"), zpool_get_name(zhp
));
5348 err
= zpool_scan(zhp
, cb
->cb_type
);
5354 * zpool scrub [-s] <pool> ...
5356 * -s Stop. Stops any in-progress scrub.
5359 zpool_do_scrub(int argc
, char **argv
)
5364 cb
.cb_type
= POOL_SCAN_SCRUB
;
5367 while ((c
= getopt(argc
, argv
, "s")) != -1) {
5370 cb
.cb_type
= POOL_SCAN_NONE
;
5373 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5385 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
5389 return (for_each_pool(argc
, argv
, B_TRUE
, NULL
, scrub_callback
, &cb
));
5392 typedef struct status_cbdata
{
5395 boolean_t cb_allpools
;
5396 boolean_t cb_verbose
;
5397 boolean_t cb_explain
;
5399 boolean_t cb_dedup_stats
;
5403 * Print out detailed scrub status.
5406 print_scan_status(pool_scan_stat_t
*ps
)
5409 uint64_t elapsed
, mins_left
, hours_left
;
5410 uint64_t pass_exam
, examined
, total
;
5412 double fraction_done
;
5413 char processed_buf
[7], examined_buf
[7], total_buf
[7], rate_buf
[7];
5415 (void) printf(gettext(" scan: "));
5417 /* If there's never been a scan, there's not much to say. */
5418 if (ps
== NULL
|| ps
->pss_func
== POOL_SCAN_NONE
||
5419 ps
->pss_func
>= POOL_SCAN_FUNCS
) {
5420 (void) printf(gettext("none requested\n"));
5424 start
= ps
->pss_start_time
;
5425 end
= ps
->pss_end_time
;
5426 zfs_nicenum(ps
->pss_processed
, processed_buf
, sizeof (processed_buf
));
5428 assert(ps
->pss_func
== POOL_SCAN_SCRUB
||
5429 ps
->pss_func
== POOL_SCAN_RESILVER
);
5431 * Scan is finished or canceled.
5433 if (ps
->pss_state
== DSS_FINISHED
) {
5434 uint64_t minutes_taken
= (end
- start
) / 60;
5437 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
5438 fmt
= gettext("scrub repaired %s in %lluh%um with "
5439 "%llu errors on %s");
5440 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
5441 fmt
= gettext("resilvered %s in %lluh%um with "
5442 "%llu errors on %s");
5445 (void) printf(fmt
, processed_buf
,
5446 (u_longlong_t
)(minutes_taken
/ 60),
5447 (uint_t
)(minutes_taken
% 60),
5448 (u_longlong_t
)ps
->pss_errors
,
5449 ctime((time_t *)&end
));
5451 } else if (ps
->pss_state
== DSS_CANCELED
) {
5452 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
5453 (void) printf(gettext("scrub canceled on %s"),
5455 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
5456 (void) printf(gettext("resilver canceled on %s"),
5462 assert(ps
->pss_state
== DSS_SCANNING
);
5465 * Scan is in progress.
5467 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
5468 (void) printf(gettext("scrub in progress since %s"),
5470 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
5471 (void) printf(gettext("resilver in progress since %s"),
5475 examined
= ps
->pss_examined
? ps
->pss_examined
: 1;
5476 total
= ps
->pss_to_examine
;
5477 fraction_done
= (double)examined
/ total
;
5479 /* elapsed time for this pass */
5480 elapsed
= time(NULL
) - ps
->pss_pass_start
;
5481 elapsed
= elapsed
? elapsed
: 1;
5482 pass_exam
= ps
->pss_pass_exam
? ps
->pss_pass_exam
: 1;
5483 rate
= pass_exam
/ elapsed
;
5484 rate
= rate
? rate
: 1;
5485 mins_left
= ((total
- examined
) / rate
) / 60;
5486 hours_left
= mins_left
/ 60;
5488 zfs_nicenum(examined
, examined_buf
, sizeof (examined_buf
));
5489 zfs_nicenum(total
, total_buf
, sizeof (total_buf
));
5490 zfs_nicenum(rate
, rate_buf
, sizeof (rate_buf
));
5493 * do not print estimated time if hours_left is more than 30 days
5495 (void) printf(gettext("\t%s scanned out of %s at %s/s"),
5496 examined_buf
, total_buf
, rate_buf
);
5497 if (hours_left
< (30 * 24)) {
5498 (void) printf(gettext(", %lluh%um to go\n"),
5499 (u_longlong_t
)hours_left
, (uint_t
)(mins_left
% 60));
5501 (void) printf(gettext(
5502 ", (scan is slow, no estimated time)\n"));
5505 if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
5506 (void) printf(gettext("\t%s resilvered, %.2f%% done\n"),
5507 processed_buf
, 100 * fraction_done
);
5508 } else if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
5509 (void) printf(gettext("\t%s repaired, %.2f%% done\n"),
5510 processed_buf
, 100 * fraction_done
);
5515 print_error_log(zpool_handle_t
*zhp
)
5517 nvlist_t
*nverrlist
= NULL
;
5520 size_t len
= MAXPATHLEN
* 2;
5522 if (zpool_get_errlog(zhp
, &nverrlist
) != 0) {
5523 (void) printf("errors: List of errors unavailable "
5524 "(insufficient privileges)\n");
5528 (void) printf("errors: Permanent errors have been "
5529 "detected in the following files:\n\n");
5531 pathname
= safe_malloc(len
);
5533 while ((elem
= nvlist_next_nvpair(nverrlist
, elem
)) != NULL
) {
5535 uint64_t dsobj
, obj
;
5537 verify(nvpair_value_nvlist(elem
, &nv
) == 0);
5538 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_DATASET
,
5540 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_OBJECT
,
5542 zpool_obj_to_path(zhp
, dsobj
, obj
, pathname
, len
);
5543 (void) printf("%7s %s\n", "", pathname
);
5546 nvlist_free(nverrlist
);
5550 print_spares(zpool_handle_t
*zhp
, nvlist_t
**spares
, uint_t nspares
,
5551 int namewidth
, int name_flags
)
5559 (void) printf(gettext("\tspares\n"));
5561 for (i
= 0; i
< nspares
; i
++) {
5562 name
= zpool_vdev_name(g_zfs
, zhp
, spares
[i
], name_flags
);
5563 print_status_config(zhp
, name
, spares
[i
],
5564 namewidth
, 2, B_TRUE
, name_flags
);
5570 print_l2cache(zpool_handle_t
*zhp
, nvlist_t
**l2cache
, uint_t nl2cache
,
5571 int namewidth
, int name_flags
)
5579 (void) printf(gettext("\tcache\n"));
5581 for (i
= 0; i
< nl2cache
; i
++) {
5582 name
= zpool_vdev_name(g_zfs
, zhp
, l2cache
[i
], name_flags
);
5583 print_status_config(zhp
, name
, l2cache
[i
],
5584 namewidth
, 2, B_FALSE
, name_flags
);
5590 print_dedup_stats(nvlist_t
*config
)
5592 ddt_histogram_t
*ddh
;
5598 * If the pool was faulted then we may not have been able to
5599 * obtain the config. Otherwise, if we have anything in the dedup
5600 * table continue processing the stats.
5602 if (nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_OBJ_STATS
,
5603 (uint64_t **)&ddo
, &c
) != 0)
5606 (void) printf("\n");
5607 (void) printf(gettext(" dedup: "));
5608 if (ddo
->ddo_count
== 0) {
5609 (void) printf(gettext("no DDT entries\n"));
5613 (void) printf("DDT entries %llu, size %llu on disk, %llu in core\n",
5614 (u_longlong_t
)ddo
->ddo_count
,
5615 (u_longlong_t
)ddo
->ddo_dspace
,
5616 (u_longlong_t
)ddo
->ddo_mspace
);
5618 verify(nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_STATS
,
5619 (uint64_t **)&dds
, &c
) == 0);
5620 verify(nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_HISTOGRAM
,
5621 (uint64_t **)&ddh
, &c
) == 0);
5622 zpool_dump_ddt(dds
, ddh
);
5626 * Display a summary of pool status. Displays a summary such as:
5630 * reason: One or more devices ...
5631 * see: http://zfsonlinux.org/msg/ZFS-xxxx-01
5637 * When given the '-v' option, we print out the complete config. If the '-e'
5638 * option is specified, then we print out error rate information as well.
5641 status_callback(zpool_handle_t
*zhp
, void *data
)
5643 status_cbdata_t
*cbp
= data
;
5644 nvlist_t
*config
, *nvroot
;
5646 zpool_status_t reason
;
5647 zpool_errata_t errata
;
5652 config
= zpool_get_config(zhp
, NULL
);
5653 reason
= zpool_get_status(zhp
, &msgid
, &errata
);
5658 * If we were given 'zpool status -x', only report those pools with
5661 if (cbp
->cb_explain
&&
5662 (reason
== ZPOOL_STATUS_OK
||
5663 reason
== ZPOOL_STATUS_VERSION_OLDER
||
5664 reason
== ZPOOL_STATUS_FEAT_DISABLED
)) {
5665 if (!cbp
->cb_allpools
) {
5666 (void) printf(gettext("pool '%s' is healthy\n"),
5667 zpool_get_name(zhp
));
5669 cbp
->cb_first
= B_FALSE
;
5675 cbp
->cb_first
= B_FALSE
;
5677 (void) printf("\n");
5679 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
5681 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_VDEV_STATS
,
5682 (uint64_t **)&vs
, &c
) == 0);
5683 health
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
5685 (void) printf(gettext(" pool: %s\n"), zpool_get_name(zhp
));
5686 (void) printf(gettext(" state: %s\n"), health
);
5689 case ZPOOL_STATUS_MISSING_DEV_R
:
5690 (void) printf(gettext("status: One or more devices could not "
5691 "be opened. Sufficient replicas exist for\n\tthe pool to "
5692 "continue functioning in a degraded state.\n"));
5693 (void) printf(gettext("action: Attach the missing device and "
5694 "online it using 'zpool online'.\n"));
5697 case ZPOOL_STATUS_MISSING_DEV_NR
:
5698 (void) printf(gettext("status: One or more devices could not "
5699 "be opened. There are insufficient\n\treplicas for the "
5700 "pool to continue functioning.\n"));
5701 (void) printf(gettext("action: Attach the missing device and "
5702 "online it using 'zpool online'.\n"));
5705 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
5706 (void) printf(gettext("status: One or more devices could not "
5707 "be used because the label is missing or\n\tinvalid. "
5708 "Sufficient replicas exist for the pool to continue\n\t"
5709 "functioning in a degraded state.\n"));
5710 (void) printf(gettext("action: Replace the device using "
5711 "'zpool replace'.\n"));
5714 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
5715 (void) printf(gettext("status: One or more devices could not "
5716 "be used because the label is missing \n\tor invalid. "
5717 "There are insufficient replicas for the pool to "
5718 "continue\n\tfunctioning.\n"));
5719 zpool_explain_recover(zpool_get_handle(zhp
),
5720 zpool_get_name(zhp
), reason
, config
);
5723 case ZPOOL_STATUS_FAILING_DEV
:
5724 (void) printf(gettext("status: One or more devices has "
5725 "experienced an unrecoverable error. An\n\tattempt was "
5726 "made to correct the error. Applications are "
5728 (void) printf(gettext("action: Determine if the device needs "
5729 "to be replaced, and clear the errors\n\tusing "
5730 "'zpool clear' or replace the device with 'zpool "
5734 case ZPOOL_STATUS_OFFLINE_DEV
:
5735 (void) printf(gettext("status: One or more devices has "
5736 "been taken offline by the administrator.\n\tSufficient "
5737 "replicas exist for the pool to continue functioning in "
5738 "a\n\tdegraded state.\n"));
5739 (void) printf(gettext("action: Online the device using "
5740 "'zpool online' or replace the device with\n\t'zpool "
5744 case ZPOOL_STATUS_REMOVED_DEV
:
5745 (void) printf(gettext("status: One or more devices has "
5746 "been removed by the administrator.\n\tSufficient "
5747 "replicas exist for the pool to continue functioning in "
5748 "a\n\tdegraded state.\n"));
5749 (void) printf(gettext("action: Online the device using "
5750 "'zpool online' or replace the device with\n\t'zpool "
5754 case ZPOOL_STATUS_RESILVERING
:
5755 (void) printf(gettext("status: One or more devices is "
5756 "currently being resilvered. The pool will\n\tcontinue "
5757 "to function, possibly in a degraded state.\n"));
5758 (void) printf(gettext("action: Wait for the resilver to "
5762 case ZPOOL_STATUS_CORRUPT_DATA
:
5763 (void) printf(gettext("status: One or more devices has "
5764 "experienced an error resulting in data\n\tcorruption. "
5765 "Applications may be affected.\n"));
5766 (void) printf(gettext("action: Restore the file in question "
5767 "if possible. Otherwise restore the\n\tentire pool from "
5771 case ZPOOL_STATUS_CORRUPT_POOL
:
5772 (void) printf(gettext("status: The pool metadata is corrupted "
5773 "and the pool cannot be opened.\n"));
5774 zpool_explain_recover(zpool_get_handle(zhp
),
5775 zpool_get_name(zhp
), reason
, config
);
5778 case ZPOOL_STATUS_VERSION_OLDER
:
5779 (void) printf(gettext("status: The pool is formatted using a "
5780 "legacy on-disk format. The pool can\n\tstill be used, "
5781 "but some features are unavailable.\n"));
5782 (void) printf(gettext("action: Upgrade the pool using 'zpool "
5783 "upgrade'. Once this is done, the\n\tpool will no longer "
5784 "be accessible on software that does not support\n\t"
5785 "feature flags.\n"));
5788 case ZPOOL_STATUS_VERSION_NEWER
:
5789 (void) printf(gettext("status: The pool has been upgraded to a "
5790 "newer, incompatible on-disk version.\n\tThe pool cannot "
5791 "be accessed on this system.\n"));
5792 (void) printf(gettext("action: Access the pool from a system "
5793 "running more recent software, or\n\trestore the pool from "
5797 case ZPOOL_STATUS_FEAT_DISABLED
:
5798 (void) printf(gettext("status: Some supported features are not "
5799 "enabled on the pool. The pool can\n\tstill be used, but "
5800 "some features are unavailable.\n"));
5801 (void) printf(gettext("action: Enable all features using "
5802 "'zpool upgrade'. Once this is done,\n\tthe pool may no "
5803 "longer be accessible by software that does not support\n\t"
5804 "the features. See zpool-features(5) for details.\n"));
5807 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
5808 (void) printf(gettext("status: The pool cannot be accessed on "
5809 "this system because it uses the\n\tfollowing feature(s) "
5810 "not supported on this system:\n"));
5811 zpool_print_unsup_feat(config
);
5812 (void) printf("\n");
5813 (void) printf(gettext("action: Access the pool from a system "
5814 "that supports the required feature(s),\n\tor restore the "
5815 "pool from backup.\n"));
5818 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
5819 (void) printf(gettext("status: The pool can only be accessed "
5820 "in read-only mode on this system. It\n\tcannot be "
5821 "accessed in read-write mode because it uses the "
5822 "following\n\tfeature(s) not supported on this system:\n"));
5823 zpool_print_unsup_feat(config
);
5824 (void) printf("\n");
5825 (void) printf(gettext("action: The pool cannot be accessed in "
5826 "read-write mode. Import the pool with\n"
5827 "\t\"-o readonly=on\", access the pool from a system that "
5828 "supports the\n\trequired feature(s), or restore the "
5829 "pool from backup.\n"));
5832 case ZPOOL_STATUS_FAULTED_DEV_R
:
5833 (void) printf(gettext("status: One or more devices are "
5834 "faulted in response to persistent errors.\n\tSufficient "
5835 "replicas exist for the pool to continue functioning "
5836 "in a\n\tdegraded state.\n"));
5837 (void) printf(gettext("action: Replace the faulted device, "
5838 "or use 'zpool clear' to mark the device\n\trepaired.\n"));
5841 case ZPOOL_STATUS_FAULTED_DEV_NR
:
5842 (void) printf(gettext("status: One or more devices are "
5843 "faulted in response to persistent errors. There are "
5844 "insufficient replicas for the pool to\n\tcontinue "
5846 (void) printf(gettext("action: Destroy and re-create the pool "
5847 "from a backup source. Manually marking the device\n"
5848 "\trepaired using 'zpool clear' may allow some data "
5849 "to be recovered.\n"));
5852 case ZPOOL_STATUS_IO_FAILURE_WAIT
:
5853 case ZPOOL_STATUS_IO_FAILURE_CONTINUE
:
5854 (void) printf(gettext("status: One or more devices are "
5855 "faulted in response to IO failures.\n"));
5856 (void) printf(gettext("action: Make sure the affected devices "
5857 "are connected, then run 'zpool clear'.\n"));
5860 case ZPOOL_STATUS_BAD_LOG
:
5861 (void) printf(gettext("status: An intent log record "
5862 "could not be read.\n"
5863 "\tWaiting for adminstrator intervention to fix the "
5864 "faulted pool.\n"));
5865 (void) printf(gettext("action: Either restore the affected "
5866 "device(s) and run 'zpool online',\n"
5867 "\tor ignore the intent log records by running "
5868 "'zpool clear'.\n"));
5871 case ZPOOL_STATUS_HOSTID_MISMATCH
:
5872 (void) printf(gettext("status: Mismatch between pool hostid "
5873 "and system hostid on imported pool.\n\tThis pool was "
5874 "previously imported into a system with a different "
5875 "hostid,\n\tand then was verbatim imported into this "
5877 (void) printf(gettext("action: Export this pool on all systems "
5878 "on which it is imported.\n"
5879 "\tThen import it to correct the mismatch.\n"));
5882 case ZPOOL_STATUS_ERRATA
:
5883 (void) printf(gettext("status: Errata #%d detected.\n"),
5887 case ZPOOL_ERRATA_NONE
:
5890 case ZPOOL_ERRATA_ZOL_2094_SCRUB
:
5891 (void) printf(gettext("action: To correct the issue "
5892 "run 'zpool scrub'.\n"));
5897 * All errata which allow the pool to be imported
5898 * must contain an action message.
5906 * The remaining errors can't actually be generated, yet.
5908 assert(reason
== ZPOOL_STATUS_OK
);
5912 (void) printf(gettext(" see: http://zfsonlinux.org/msg/%s\n"),
5915 if (config
!= NULL
) {
5918 nvlist_t
**spares
, **l2cache
;
5919 uint_t nspares
, nl2cache
;
5920 pool_scan_stat_t
*ps
= NULL
;
5922 (void) nvlist_lookup_uint64_array(nvroot
,
5923 ZPOOL_CONFIG_SCAN_STATS
, (uint64_t **)&ps
, &c
);
5924 print_scan_status(ps
);
5926 namewidth
= max_width(zhp
, nvroot
, 0, 0, cbp
->cb_name_flags
);
5930 (void) printf(gettext("config:\n\n"));
5931 (void) printf(gettext("\t%-*s %-8s %5s %5s %5s\n"), namewidth
,
5932 "NAME", "STATE", "READ", "WRITE", "CKSUM");
5933 print_status_config(zhp
, zpool_get_name(zhp
), nvroot
,
5934 namewidth
, 0, B_FALSE
, cbp
->cb_name_flags
);
5936 if (num_logs(nvroot
) > 0)
5937 print_logs(zhp
, nvroot
, namewidth
, B_TRUE
,
5938 cbp
->cb_name_flags
);
5939 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_L2CACHE
,
5940 &l2cache
, &nl2cache
) == 0)
5941 print_l2cache(zhp
, l2cache
, nl2cache
, namewidth
,
5942 cbp
->cb_name_flags
);
5944 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_SPARES
,
5945 &spares
, &nspares
) == 0)
5946 print_spares(zhp
, spares
, nspares
, namewidth
,
5947 cbp
->cb_name_flags
);
5949 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_ERRCOUNT
,
5951 nvlist_t
*nverrlist
= NULL
;
5954 * If the approximate error count is small, get a
5955 * precise count by fetching the entire log and
5956 * uniquifying the results.
5958 if (nerr
> 0 && nerr
< 100 && !cbp
->cb_verbose
&&
5959 zpool_get_errlog(zhp
, &nverrlist
) == 0) {
5964 while ((elem
= nvlist_next_nvpair(nverrlist
,
5969 nvlist_free(nverrlist
);
5971 (void) printf("\n");
5974 (void) printf(gettext("errors: No known data "
5976 else if (!cbp
->cb_verbose
)
5977 (void) printf(gettext("errors: %llu data "
5978 "errors, use '-v' for a list\n"),
5979 (u_longlong_t
)nerr
);
5981 print_error_log(zhp
);
5984 if (cbp
->cb_dedup_stats
)
5985 print_dedup_stats(config
);
5987 (void) printf(gettext("config: The configuration cannot be "
5995 * zpool status [-gLPvx] [-T d|u] [pool] ... [interval [count]]
5997 * -g Display guid for individual vdev name.
5998 * -L Follow links when resolving vdev path name.
5999 * -P Display full path for vdev name.
6000 * -v Display complete error logs
6001 * -x Display only pools with potential problems
6002 * -D Display dedup status (undocumented)
6003 * -T Display a timestamp in date(1) or Unix format
6005 * Describes the health status of all pools or some subset.
6008 zpool_do_status(int argc
, char **argv
)
6013 unsigned long count
= 0;
6014 status_cbdata_t cb
= { 0 };
6017 while ((c
= getopt(argc
, argv
, "gLPvxDT:")) != -1) {
6020 cb
.cb_name_flags
|= VDEV_NAME_GUID
;
6023 cb
.cb_name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
6026 cb
.cb_name_flags
|= VDEV_NAME_PATH
;
6029 cb
.cb_verbose
= B_TRUE
;
6032 cb
.cb_explain
= B_TRUE
;
6035 cb
.cb_dedup_stats
= B_TRUE
;
6038 get_timestamp_arg(*optarg
);
6041 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
6050 get_interval_count(&argc
, argv
, &interval
, &count
);
6053 cb
.cb_allpools
= B_TRUE
;
6055 cb
.cb_first
= B_TRUE
;
6058 if (timestamp_fmt
!= NODATE
)
6059 print_timestamp(timestamp_fmt
);
6061 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
,
6062 status_callback
, &cb
);
6064 if (argc
== 0 && cb
.cb_count
== 0)
6065 (void) fprintf(stderr
, gettext("no pools available\n"));
6066 else if (cb
.cb_explain
&& cb
.cb_first
&& cb
.cb_allpools
)
6067 (void) printf(gettext("all pools are healthy\n"));
6075 if (count
!= 0 && --count
== 0)
6078 (void) fsleep(interval
);
6084 typedef struct upgrade_cbdata
{
6087 uint64_t cb_version
;
6092 check_unsupp_fs(zfs_handle_t
*zhp
, void *unsupp_fs
)
6094 int zfs_version
= (int) zfs_prop_get_int(zhp
, ZFS_PROP_VERSION
);
6095 int *count
= (int *)unsupp_fs
;
6097 if (zfs_version
> ZPL_VERSION
) {
6098 (void) printf(gettext("%s (v%d) is not supported by this "
6099 "implementation of ZFS.\n"),
6100 zfs_get_name(zhp
), zfs_version
);
6104 zfs_iter_filesystems(zhp
, check_unsupp_fs
, unsupp_fs
);
6112 upgrade_version(zpool_handle_t
*zhp
, uint64_t version
)
6116 uint64_t oldversion
;
6119 config
= zpool_get_config(zhp
, NULL
);
6120 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
6123 assert(SPA_VERSION_IS_SUPPORTED(oldversion
));
6124 assert(oldversion
< version
);
6126 ret
= zfs_iter_root(zpool_get_handle(zhp
), check_unsupp_fs
, &unsupp_fs
);
6131 (void) fprintf(stderr
, gettext("Upgrade not performed due "
6132 "to %d unsupported filesystems (max v%d).\n"),
6133 unsupp_fs
, (int) ZPL_VERSION
);
6137 ret
= zpool_upgrade(zhp
, version
);
6141 if (version
>= SPA_VERSION_FEATURES
) {
6142 (void) printf(gettext("Successfully upgraded "
6143 "'%s' from version %llu to feature flags.\n"),
6144 zpool_get_name(zhp
), (u_longlong_t
) oldversion
);
6146 (void) printf(gettext("Successfully upgraded "
6147 "'%s' from version %llu to version %llu.\n"),
6148 zpool_get_name(zhp
), (u_longlong_t
) oldversion
,
6149 (u_longlong_t
) version
);
6156 upgrade_enable_all(zpool_handle_t
*zhp
, int *countp
)
6159 boolean_t firstff
= B_TRUE
;
6160 nvlist_t
*enabled
= zpool_get_features(zhp
);
6163 for (i
= 0; i
< SPA_FEATURES
; i
++) {
6164 const char *fname
= spa_feature_table
[i
].fi_uname
;
6165 const char *fguid
= spa_feature_table
[i
].fi_guid
;
6166 if (!nvlist_exists(enabled
, fguid
)) {
6168 verify(-1 != asprintf(&propname
, "feature@%s", fname
));
6169 ret
= zpool_set_prop(zhp
, propname
,
6170 ZFS_FEATURE_ENABLED
);
6178 (void) printf(gettext("Enabled the "
6179 "following features on '%s':\n"),
6180 zpool_get_name(zhp
));
6183 (void) printf(gettext(" %s\n"), fname
);
6194 upgrade_cb(zpool_handle_t
*zhp
, void *arg
)
6196 upgrade_cbdata_t
*cbp
= arg
;
6199 boolean_t printnl
= B_FALSE
;
6202 config
= zpool_get_config(zhp
, NULL
);
6203 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
6206 assert(SPA_VERSION_IS_SUPPORTED(version
));
6208 if (version
< cbp
->cb_version
) {
6209 cbp
->cb_first
= B_FALSE
;
6210 ret
= upgrade_version(zhp
, cbp
->cb_version
);
6216 * If they did "zpool upgrade -a", then we could
6217 * be doing ioctls to different pools. We need
6218 * to log this history once to each pool, and bypass
6219 * the normal history logging that happens in main().
6221 (void) zpool_log_history(g_zfs
, history_str
);
6222 log_history
= B_FALSE
;
6225 if (cbp
->cb_version
>= SPA_VERSION_FEATURES
) {
6227 ret
= upgrade_enable_all(zhp
, &count
);
6232 cbp
->cb_first
= B_FALSE
;
6238 (void) printf(gettext("\n"));
6245 upgrade_list_older_cb(zpool_handle_t
*zhp
, void *arg
)
6247 upgrade_cbdata_t
*cbp
= arg
;
6251 config
= zpool_get_config(zhp
, NULL
);
6252 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
6255 assert(SPA_VERSION_IS_SUPPORTED(version
));
6257 if (version
< SPA_VERSION_FEATURES
) {
6258 if (cbp
->cb_first
) {
6259 (void) printf(gettext("The following pools are "
6260 "formatted with legacy version numbers and can\n"
6261 "be upgraded to use feature flags. After "
6262 "being upgraded, these pools\nwill no "
6263 "longer be accessible by software that does not "
6264 "support feature\nflags.\n\n"));
6265 (void) printf(gettext("VER POOL\n"));
6266 (void) printf(gettext("--- ------------\n"));
6267 cbp
->cb_first
= B_FALSE
;
6270 (void) printf("%2llu %s\n", (u_longlong_t
)version
,
6271 zpool_get_name(zhp
));
6278 upgrade_list_disabled_cb(zpool_handle_t
*zhp
, void *arg
)
6280 upgrade_cbdata_t
*cbp
= arg
;
6284 config
= zpool_get_config(zhp
, NULL
);
6285 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
6288 if (version
>= SPA_VERSION_FEATURES
) {
6290 boolean_t poolfirst
= B_TRUE
;
6291 nvlist_t
*enabled
= zpool_get_features(zhp
);
6293 for (i
= 0; i
< SPA_FEATURES
; i
++) {
6294 const char *fguid
= spa_feature_table
[i
].fi_guid
;
6295 const char *fname
= spa_feature_table
[i
].fi_uname
;
6296 if (!nvlist_exists(enabled
, fguid
)) {
6297 if (cbp
->cb_first
) {
6298 (void) printf(gettext("\nSome "
6299 "supported features are not "
6300 "enabled on the following pools. "
6301 "Once a\nfeature is enabled the "
6302 "pool may become incompatible with "
6303 "software\nthat does not support "
6305 "zpool-features(5) for "
6307 (void) printf(gettext("POOL "
6309 (void) printf(gettext("------"
6311 cbp
->cb_first
= B_FALSE
;
6315 (void) printf(gettext("%s\n"),
6316 zpool_get_name(zhp
));
6317 poolfirst
= B_FALSE
;
6320 (void) printf(gettext(" %s\n"), fname
);
6323 * If they did "zpool upgrade -a", then we could
6324 * be doing ioctls to different pools. We need
6325 * to log this history once to each pool, and bypass
6326 * the normal history logging that happens in main().
6328 (void) zpool_log_history(g_zfs
, history_str
);
6329 log_history
= B_FALSE
;
6338 upgrade_one(zpool_handle_t
*zhp
, void *data
)
6340 boolean_t printnl
= B_FALSE
;
6341 upgrade_cbdata_t
*cbp
= data
;
6342 uint64_t cur_version
;
6345 if (strcmp("log", zpool_get_name(zhp
)) == 0) {
6346 (void) fprintf(stderr
, gettext("'log' is now a reserved word\n"
6347 "Pool 'log' must be renamed using export and import"
6352 cur_version
= zpool_get_prop_int(zhp
, ZPOOL_PROP_VERSION
, NULL
);
6353 if (cur_version
> cbp
->cb_version
) {
6354 (void) printf(gettext("Pool '%s' is already formatted "
6355 "using more current version '%llu'.\n\n"),
6356 zpool_get_name(zhp
), (u_longlong_t
) cur_version
);
6360 if (cbp
->cb_version
!= SPA_VERSION
&& cur_version
== cbp
->cb_version
) {
6361 (void) printf(gettext("Pool '%s' is already formatted "
6362 "using version %llu.\n\n"), zpool_get_name(zhp
),
6363 (u_longlong_t
) cbp
->cb_version
);
6367 if (cur_version
!= cbp
->cb_version
) {
6369 ret
= upgrade_version(zhp
, cbp
->cb_version
);
6374 if (cbp
->cb_version
>= SPA_VERSION_FEATURES
) {
6376 ret
= upgrade_enable_all(zhp
, &count
);
6382 } else if (cur_version
== SPA_VERSION
) {
6383 (void) printf(gettext("Pool '%s' already has all "
6384 "supported features enabled.\n"),
6385 zpool_get_name(zhp
));
6390 (void) printf(gettext("\n"));
6399 * zpool upgrade [-V version] <-a | pool ...>
6401 * With no arguments, display downrev'd ZFS pool available for upgrade.
6402 * Individual pools can be upgraded by specifying the pool, and '-a' will
6403 * upgrade all pools.
6406 zpool_do_upgrade(int argc
, char **argv
)
6409 upgrade_cbdata_t cb
= { 0 };
6411 boolean_t showversions
= B_FALSE
;
6412 boolean_t upgradeall
= B_FALSE
;
6417 while ((c
= getopt(argc
, argv
, ":avV:")) != -1) {
6420 upgradeall
= B_TRUE
;
6423 showversions
= B_TRUE
;
6426 cb
.cb_version
= strtoll(optarg
, &end
, 10);
6428 !SPA_VERSION_IS_SUPPORTED(cb
.cb_version
)) {
6429 (void) fprintf(stderr
,
6430 gettext("invalid version '%s'\n"), optarg
);
6435 (void) fprintf(stderr
, gettext("missing argument for "
6436 "'%c' option\n"), optopt
);
6440 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
6451 if (cb
.cb_version
== 0) {
6452 cb
.cb_version
= SPA_VERSION
;
6453 } else if (!upgradeall
&& argc
== 0) {
6454 (void) fprintf(stderr
, gettext("-V option is "
6455 "incompatible with other arguments\n"));
6460 if (upgradeall
|| argc
!= 0) {
6461 (void) fprintf(stderr
, gettext("-v option is "
6462 "incompatible with other arguments\n"));
6465 } else if (upgradeall
) {
6467 (void) fprintf(stderr
, gettext("-a option should not "
6468 "be used along with a pool name\n"));
6473 (void) printf(gettext("This system supports ZFS pool feature "
6478 (void) printf(gettext("The following features are "
6480 (void) printf(gettext("FEAT DESCRIPTION\n"));
6481 (void) printf("----------------------------------------------"
6482 "---------------\n");
6483 for (i
= 0; i
< SPA_FEATURES
; i
++) {
6484 zfeature_info_t
*fi
= &spa_feature_table
[i
];
6486 (fi
->fi_flags
& ZFEATURE_FLAG_READONLY_COMPAT
) ?
6487 " (read-only compatible)" : "";
6489 (void) printf("%-37s%s\n", fi
->fi_uname
, ro
);
6490 (void) printf(" %s\n", fi
->fi_desc
);
6492 (void) printf("\n");
6494 (void) printf(gettext("The following legacy versions are also "
6496 (void) printf(gettext("VER DESCRIPTION\n"));
6497 (void) printf("--- -----------------------------------------"
6498 "---------------\n");
6499 (void) printf(gettext(" 1 Initial ZFS version\n"));
6500 (void) printf(gettext(" 2 Ditto blocks "
6501 "(replicated metadata)\n"));
6502 (void) printf(gettext(" 3 Hot spares and double parity "
6504 (void) printf(gettext(" 4 zpool history\n"));
6505 (void) printf(gettext(" 5 Compression using the gzip "
6507 (void) printf(gettext(" 6 bootfs pool property\n"));
6508 (void) printf(gettext(" 7 Separate intent log devices\n"));
6509 (void) printf(gettext(" 8 Delegated administration\n"));
6510 (void) printf(gettext(" 9 refquota and refreservation "
6512 (void) printf(gettext(" 10 Cache devices\n"));
6513 (void) printf(gettext(" 11 Improved scrub performance\n"));
6514 (void) printf(gettext(" 12 Snapshot properties\n"));
6515 (void) printf(gettext(" 13 snapused property\n"));
6516 (void) printf(gettext(" 14 passthrough-x aclinherit\n"));
6517 (void) printf(gettext(" 15 user/group space accounting\n"));
6518 (void) printf(gettext(" 16 stmf property support\n"));
6519 (void) printf(gettext(" 17 Triple-parity RAID-Z\n"));
6520 (void) printf(gettext(" 18 Snapshot user holds\n"));
6521 (void) printf(gettext(" 19 Log device removal\n"));
6522 (void) printf(gettext(" 20 Compression using zle "
6523 "(zero-length encoding)\n"));
6524 (void) printf(gettext(" 21 Deduplication\n"));
6525 (void) printf(gettext(" 22 Received properties\n"));
6526 (void) printf(gettext(" 23 Slim ZIL\n"));
6527 (void) printf(gettext(" 24 System attributes\n"));
6528 (void) printf(gettext(" 25 Improved scrub stats\n"));
6529 (void) printf(gettext(" 26 Improved snapshot deletion "
6531 (void) printf(gettext(" 27 Improved snapshot creation "
6533 (void) printf(gettext(" 28 Multiple vdev replacements\n"));
6534 (void) printf(gettext("\nFor more information on a particular "
6535 "version, including supported releases,\n"));
6536 (void) printf(gettext("see the ZFS Administration Guide.\n\n"));
6537 } else if (argc
== 0 && upgradeall
) {
6538 cb
.cb_first
= B_TRUE
;
6539 ret
= zpool_iter(g_zfs
, upgrade_cb
, &cb
);
6540 if (ret
== 0 && cb
.cb_first
) {
6541 if (cb
.cb_version
== SPA_VERSION
) {
6542 (void) printf(gettext("All pools are already "
6543 "formatted using feature flags.\n\n"));
6544 (void) printf(gettext("Every feature flags "
6545 "pool already has all supported features "
6548 (void) printf(gettext("All pools are already "
6549 "formatted with version %llu or higher.\n"),
6550 (u_longlong_t
) cb
.cb_version
);
6553 } else if (argc
== 0) {
6554 cb
.cb_first
= B_TRUE
;
6555 ret
= zpool_iter(g_zfs
, upgrade_list_older_cb
, &cb
);
6559 (void) printf(gettext("All pools are formatted "
6560 "using feature flags.\n\n"));
6562 (void) printf(gettext("\nUse 'zpool upgrade -v' "
6563 "for a list of available legacy versions.\n"));
6566 cb
.cb_first
= B_TRUE
;
6567 ret
= zpool_iter(g_zfs
, upgrade_list_disabled_cb
, &cb
);
6571 (void) printf(gettext("Every feature flags pool has "
6572 "all supported features enabled.\n"));
6574 (void) printf(gettext("\n"));
6577 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
,
6584 typedef struct hist_cbdata
{
6591 * Print out the command history for a specific pool.
6594 get_history_one(zpool_handle_t
*zhp
, void *data
)
6600 hist_cbdata_t
*cb
= (hist_cbdata_t
*)data
;
6602 cb
->first
= B_FALSE
;
6604 (void) printf(gettext("History for '%s':\n"), zpool_get_name(zhp
));
6606 if ((ret
= zpool_get_history(zhp
, &nvhis
)) != 0)
6609 verify(nvlist_lookup_nvlist_array(nvhis
, ZPOOL_HIST_RECORD
,
6610 &records
, &numrecords
) == 0);
6611 for (i
= 0; i
< numrecords
; i
++) {
6612 nvlist_t
*rec
= records
[i
];
6615 if (nvlist_exists(rec
, ZPOOL_HIST_TIME
)) {
6619 tsec
= fnvlist_lookup_uint64(records
[i
],
6621 (void) localtime_r(&tsec
, &t
);
6622 (void) strftime(tbuf
, sizeof (tbuf
), "%F.%T", &t
);
6625 if (nvlist_exists(rec
, ZPOOL_HIST_CMD
)) {
6626 (void) printf("%s %s", tbuf
,
6627 fnvlist_lookup_string(rec
, ZPOOL_HIST_CMD
));
6628 } else if (nvlist_exists(rec
, ZPOOL_HIST_INT_EVENT
)) {
6630 fnvlist_lookup_uint64(rec
, ZPOOL_HIST_INT_EVENT
);
6633 if (ievent
>= ZFS_NUM_LEGACY_HISTORY_EVENTS
) {
6634 (void) printf("%s unrecognized record:\n",
6636 dump_nvlist(rec
, 4);
6639 (void) printf("%s [internal %s txg:%lld] %s", tbuf
,
6640 zfs_history_event_names
[ievent
],
6641 (longlong_t
) fnvlist_lookup_uint64(
6642 rec
, ZPOOL_HIST_TXG
),
6643 fnvlist_lookup_string(rec
, ZPOOL_HIST_INT_STR
));
6644 } else if (nvlist_exists(rec
, ZPOOL_HIST_INT_NAME
)) {
6647 (void) printf("%s [txg:%lld] %s", tbuf
,
6648 (longlong_t
) fnvlist_lookup_uint64(
6649 rec
, ZPOOL_HIST_TXG
),
6650 fnvlist_lookup_string(rec
, ZPOOL_HIST_INT_NAME
));
6651 if (nvlist_exists(rec
, ZPOOL_HIST_DSNAME
)) {
6652 (void) printf(" %s (%llu)",
6653 fnvlist_lookup_string(rec
,
6655 (u_longlong_t
)fnvlist_lookup_uint64(rec
,
6658 (void) printf(" %s", fnvlist_lookup_string(rec
,
6659 ZPOOL_HIST_INT_STR
));
6660 } else if (nvlist_exists(rec
, ZPOOL_HIST_IOCTL
)) {
6663 (void) printf("%s ioctl %s\n", tbuf
,
6664 fnvlist_lookup_string(rec
, ZPOOL_HIST_IOCTL
));
6665 if (nvlist_exists(rec
, ZPOOL_HIST_INPUT_NVL
)) {
6666 (void) printf(" input:\n");
6667 dump_nvlist(fnvlist_lookup_nvlist(rec
,
6668 ZPOOL_HIST_INPUT_NVL
), 8);
6670 if (nvlist_exists(rec
, ZPOOL_HIST_OUTPUT_NVL
)) {
6671 (void) printf(" output:\n");
6672 dump_nvlist(fnvlist_lookup_nvlist(rec
,
6673 ZPOOL_HIST_OUTPUT_NVL
), 8);
6678 (void) printf("%s unrecognized record:\n", tbuf
);
6679 dump_nvlist(rec
, 4);
6683 (void) printf("\n");
6686 (void) printf(" [");
6687 if (nvlist_exists(rec
, ZPOOL_HIST_WHO
)) {
6688 uid_t who
= fnvlist_lookup_uint64(rec
, ZPOOL_HIST_WHO
);
6689 struct passwd
*pwd
= getpwuid(who
);
6690 (void) printf("user %d ", (int)who
);
6692 (void) printf("(%s) ", pwd
->pw_name
);
6694 if (nvlist_exists(rec
, ZPOOL_HIST_HOST
)) {
6695 (void) printf("on %s",
6696 fnvlist_lookup_string(rec
, ZPOOL_HIST_HOST
));
6698 if (nvlist_exists(rec
, ZPOOL_HIST_ZONE
)) {
6699 (void) printf(":%s",
6700 fnvlist_lookup_string(rec
, ZPOOL_HIST_ZONE
));
6704 (void) printf("\n");
6706 (void) printf("\n");
6713 * zpool history <pool>
6715 * Displays the history of commands that modified pools.
6718 zpool_do_history(int argc
, char **argv
)
6720 hist_cbdata_t cbdata
= { 0 };
6724 cbdata
.first
= B_TRUE
;
6726 while ((c
= getopt(argc
, argv
, "li")) != -1) {
6729 cbdata
.longfmt
= B_TRUE
;
6732 cbdata
.internal
= B_TRUE
;
6735 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
6743 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
, get_history_one
,
6746 if (argc
== 0 && cbdata
.first
== B_TRUE
) {
6747 (void) fprintf(stderr
, gettext("no pools available\n"));
6754 typedef struct ev_opts
{
6762 zpool_do_events_short(nvlist_t
*nvl
)
6764 char ctime_str
[26], str
[32], *ptr
;
6768 verify(nvlist_lookup_int64_array(nvl
, FM_EREPORT_TIME
, &tv
, &n
) == 0);
6769 memset(str
, ' ', 32);
6770 (void) ctime_r((const time_t *)&tv
[0], ctime_str
);
6771 (void) strncpy(str
, ctime_str
+4, 6); /* 'Jun 30' */
6772 (void) strncpy(str
+7, ctime_str
+20, 4); /* '1993' */
6773 (void) strncpy(str
+12, ctime_str
+11, 8); /* '21:49:08' */
6774 (void) sprintf(str
+20, ".%09lld", (longlong_t
)tv
[1]); /* '.123456789' */
6775 (void) printf(gettext("%s "), str
);
6777 verify(nvlist_lookup_string(nvl
, FM_CLASS
, &ptr
) == 0);
6778 (void) printf(gettext("%s\n"), ptr
);
6782 zpool_do_events_nvprint(nvlist_t
*nvl
, int depth
)
6786 for (nvp
= nvlist_next_nvpair(nvl
, NULL
);
6787 nvp
!= NULL
; nvp
= nvlist_next_nvpair(nvl
, nvp
)) {
6789 data_type_t type
= nvpair_type(nvp
);
6790 const char *name
= nvpair_name(nvp
);
6800 printf(gettext("%*s%s = "), depth
, "", name
);
6803 case DATA_TYPE_BOOLEAN
:
6804 printf(gettext("%s"), "1");
6807 case DATA_TYPE_BOOLEAN_VALUE
:
6808 (void) nvpair_value_boolean_value(nvp
, &b
);
6809 printf(gettext("%s"), b
? "1" : "0");
6812 case DATA_TYPE_BYTE
:
6813 (void) nvpair_value_byte(nvp
, &i8
);
6814 printf(gettext("0x%x"), i8
);
6817 case DATA_TYPE_INT8
:
6818 (void) nvpair_value_int8(nvp
, (void *)&i8
);
6819 printf(gettext("0x%x"), i8
);
6822 case DATA_TYPE_UINT8
:
6823 (void) nvpair_value_uint8(nvp
, &i8
);
6824 printf(gettext("0x%x"), i8
);
6827 case DATA_TYPE_INT16
:
6828 (void) nvpair_value_int16(nvp
, (void *)&i16
);
6829 printf(gettext("0x%x"), i16
);
6832 case DATA_TYPE_UINT16
:
6833 (void) nvpair_value_uint16(nvp
, &i16
);
6834 printf(gettext("0x%x"), i16
);
6837 case DATA_TYPE_INT32
:
6838 (void) nvpair_value_int32(nvp
, (void *)&i32
);
6839 printf(gettext("0x%x"), i32
);
6842 case DATA_TYPE_UINT32
:
6843 (void) nvpair_value_uint32(nvp
, &i32
);
6844 printf(gettext("0x%x"), i32
);
6847 case DATA_TYPE_INT64
:
6848 (void) nvpair_value_int64(nvp
, (void *)&i64
);
6849 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
6852 case DATA_TYPE_UINT64
:
6853 (void) nvpair_value_uint64(nvp
, &i64
);
6854 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
6857 case DATA_TYPE_HRTIME
:
6858 (void) nvpair_value_hrtime(nvp
, (void *)&i64
);
6859 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
6862 case DATA_TYPE_STRING
:
6863 (void) nvpair_value_string(nvp
, &str
);
6864 printf(gettext("\"%s\""), str
? str
: "<NULL>");
6867 case DATA_TYPE_NVLIST
:
6868 printf(gettext("(embedded nvlist)\n"));
6869 (void) nvpair_value_nvlist(nvp
, &cnv
);
6870 zpool_do_events_nvprint(cnv
, depth
+ 8);
6871 printf(gettext("%*s(end %s)"), depth
, "", name
);
6874 case DATA_TYPE_NVLIST_ARRAY
: {
6878 (void) nvpair_value_nvlist_array(nvp
, &val
, &nelem
);
6879 printf(gettext("(%d embedded nvlists)\n"), nelem
);
6880 for (i
= 0; i
< nelem
; i
++) {
6881 printf(gettext("%*s%s[%d] = %s\n"),
6882 depth
, "", name
, i
, "(embedded nvlist)");
6883 zpool_do_events_nvprint(val
[i
], depth
+ 8);
6884 printf(gettext("%*s(end %s[%i])\n"),
6885 depth
, "", name
, i
);
6887 printf(gettext("%*s(end %s)\n"), depth
, "", name
);
6891 case DATA_TYPE_INT8_ARRAY
: {
6895 (void) nvpair_value_int8_array(nvp
, &val
, &nelem
);
6896 for (i
= 0; i
< nelem
; i
++)
6897 printf(gettext("0x%x "), val
[i
]);
6902 case DATA_TYPE_UINT8_ARRAY
: {
6906 (void) nvpair_value_uint8_array(nvp
, &val
, &nelem
);
6907 for (i
= 0; i
< nelem
; i
++)
6908 printf(gettext("0x%x "), val
[i
]);
6913 case DATA_TYPE_INT16_ARRAY
: {
6917 (void) nvpair_value_int16_array(nvp
, &val
, &nelem
);
6918 for (i
= 0; i
< nelem
; i
++)
6919 printf(gettext("0x%x "), val
[i
]);
6924 case DATA_TYPE_UINT16_ARRAY
: {
6928 (void) nvpair_value_uint16_array(nvp
, &val
, &nelem
);
6929 for (i
= 0; i
< nelem
; i
++)
6930 printf(gettext("0x%x "), val
[i
]);
6935 case DATA_TYPE_INT32_ARRAY
: {
6939 (void) nvpair_value_int32_array(nvp
, &val
, &nelem
);
6940 for (i
= 0; i
< nelem
; i
++)
6941 printf(gettext("0x%x "), val
[i
]);
6946 case DATA_TYPE_UINT32_ARRAY
: {
6950 (void) nvpair_value_uint32_array(nvp
, &val
, &nelem
);
6951 for (i
= 0; i
< nelem
; i
++)
6952 printf(gettext("0x%x "), val
[i
]);
6957 case DATA_TYPE_INT64_ARRAY
: {
6961 (void) nvpair_value_int64_array(nvp
, &val
, &nelem
);
6962 for (i
= 0; i
< nelem
; i
++)
6963 printf(gettext("0x%llx "),
6964 (u_longlong_t
)val
[i
]);
6969 case DATA_TYPE_UINT64_ARRAY
: {
6973 (void) nvpair_value_uint64_array(nvp
, &val
, &nelem
);
6974 for (i
= 0; i
< nelem
; i
++)
6975 printf(gettext("0x%llx "),
6976 (u_longlong_t
)val
[i
]);
6981 case DATA_TYPE_STRING_ARRAY
: {
6985 (void) nvpair_value_string_array(nvp
, &str
, &nelem
);
6986 for (i
= 0; i
< nelem
; i
++)
6987 printf(gettext("\"%s\" "),
6988 str
[i
] ? str
[i
] : "<NULL>");
6993 case DATA_TYPE_BOOLEAN_ARRAY
:
6994 case DATA_TYPE_BYTE_ARRAY
:
6995 case DATA_TYPE_DOUBLE
:
6996 case DATA_TYPE_UNKNOWN
:
6997 printf(gettext("<unknown>"));
7001 printf(gettext("\n"));
7006 zpool_do_events_next(ev_opts_t
*opts
)
7009 int zevent_fd
, ret
, dropped
;
7011 zevent_fd
= open(ZFS_DEV
, O_RDWR
);
7012 VERIFY(zevent_fd
>= 0);
7014 if (!opts
->scripted
)
7015 (void) printf(gettext("%-30s %s\n"), "TIME", "CLASS");
7018 ret
= zpool_events_next(g_zfs
, &nvl
, &dropped
,
7019 (opts
->follow
? ZEVENT_NONE
: ZEVENT_NONBLOCK
), zevent_fd
);
7020 if (ret
|| nvl
== NULL
)
7024 (void) printf(gettext("dropped %d events\n"), dropped
);
7026 zpool_do_events_short(nvl
);
7028 if (opts
->verbose
) {
7029 zpool_do_events_nvprint(nvl
, 8);
7030 printf(gettext("\n"));
7032 (void) fflush(stdout
);
7037 VERIFY(0 == close(zevent_fd
));
7043 zpool_do_events_clear(ev_opts_t
*opts
)
7047 ret
= zpool_events_clear(g_zfs
, &count
);
7049 (void) printf(gettext("cleared %d events\n"), count
);
7055 * zpool events [-vfc]
7057 * Displays events logs by ZFS.
7060 zpool_do_events(int argc
, char **argv
)
7062 ev_opts_t opts
= { 0 };
7067 while ((c
= getopt(argc
, argv
, "vHfc")) != -1) {
7082 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
7091 ret
= zpool_do_events_clear(&opts
);
7093 ret
= zpool_do_events_next(&opts
);
7099 get_callback(zpool_handle_t
*zhp
, void *data
)
7101 zprop_get_cbdata_t
*cbp
= (zprop_get_cbdata_t
*)data
;
7102 char value
[MAXNAMELEN
];
7103 zprop_source_t srctype
;
7106 for (pl
= cbp
->cb_proplist
; pl
!= NULL
; pl
= pl
->pl_next
) {
7109 * Skip the special fake placeholder. This will also skip
7110 * over the name property when 'all' is specified.
7112 if (pl
->pl_prop
== ZPOOL_PROP_NAME
&&
7113 pl
== cbp
->cb_proplist
)
7116 if (pl
->pl_prop
== ZPROP_INVAL
&&
7117 (zpool_prop_feature(pl
->pl_user_prop
) ||
7118 zpool_prop_unsupported(pl
->pl_user_prop
))) {
7119 srctype
= ZPROP_SRC_LOCAL
;
7121 if (zpool_prop_get_feature(zhp
, pl
->pl_user_prop
,
7122 value
, sizeof (value
)) == 0) {
7123 zprop_print_one_property(zpool_get_name(zhp
),
7124 cbp
, pl
->pl_user_prop
, value
, srctype
,
7128 if (zpool_get_prop(zhp
, pl
->pl_prop
, value
,
7129 sizeof (value
), &srctype
, cbp
->cb_literal
) != 0)
7132 zprop_print_one_property(zpool_get_name(zhp
), cbp
,
7133 zpool_prop_to_name(pl
->pl_prop
), value
, srctype
,
7141 * zpool get [-Hp] [-o "all" | field[,...]] <"all" | property[,...]> <pool> ...
7143 * -H Scripted mode. Don't display headers, and separate properties
7145 * -o List of columns to display. Defaults to
7146 * "name,property,value,source".
7147 * -p Diplay values in parsable (exact) format.
7149 * Get properties of pools in the system. Output space statistics
7150 * for each one as well as other attributes.
7153 zpool_do_get(int argc
, char **argv
)
7155 zprop_get_cbdata_t cb
= { 0 };
7156 zprop_list_t fake_name
= { 0 };
7161 cb
.cb_first
= B_TRUE
;
7164 * Set up default columns and sources.
7166 cb
.cb_sources
= ZPROP_SRC_ALL
;
7167 cb
.cb_columns
[0] = GET_COL_NAME
;
7168 cb
.cb_columns
[1] = GET_COL_PROPERTY
;
7169 cb
.cb_columns
[2] = GET_COL_VALUE
;
7170 cb
.cb_columns
[3] = GET_COL_SOURCE
;
7171 cb
.cb_type
= ZFS_TYPE_POOL
;
7174 while ((c
= getopt(argc
, argv
, ":Hpo:")) != -1) {
7177 cb
.cb_literal
= B_TRUE
;
7180 cb
.cb_scripted
= B_TRUE
;
7183 bzero(&cb
.cb_columns
, sizeof (cb
.cb_columns
));
7185 while (*optarg
!= '\0') {
7186 static char *col_subopts
[] =
7187 { "name", "property", "value", "source",
7190 if (i
== ZFS_GET_NCOLS
) {
7191 (void) fprintf(stderr
, gettext("too "
7192 "many fields given to -o "
7197 switch (getsubopt(&optarg
, col_subopts
,
7200 cb
.cb_columns
[i
++] = GET_COL_NAME
;
7203 cb
.cb_columns
[i
++] = GET_COL_PROPERTY
;
7206 cb
.cb_columns
[i
++] = GET_COL_VALUE
;
7209 cb
.cb_columns
[i
++] = GET_COL_SOURCE
;
7213 (void) fprintf(stderr
,
7214 gettext("\"all\" conflicts "
7215 "with specific fields "
7216 "given to -o option\n"));
7219 cb
.cb_columns
[0] = GET_COL_NAME
;
7220 cb
.cb_columns
[1] = GET_COL_PROPERTY
;
7221 cb
.cb_columns
[2] = GET_COL_VALUE
;
7222 cb
.cb_columns
[3] = GET_COL_SOURCE
;
7226 (void) fprintf(stderr
,
7227 gettext("invalid column name "
7234 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
7244 (void) fprintf(stderr
, gettext("missing property "
7249 if (zprop_get_list(g_zfs
, argv
[0], &cb
.cb_proplist
,
7250 ZFS_TYPE_POOL
) != 0)
7256 if (cb
.cb_proplist
!= NULL
) {
7257 fake_name
.pl_prop
= ZPOOL_PROP_NAME
;
7258 fake_name
.pl_width
= strlen(gettext("NAME"));
7259 fake_name
.pl_next
= cb
.cb_proplist
;
7260 cb
.cb_proplist
= &fake_name
;
7263 ret
= for_each_pool(argc
, argv
, B_TRUE
, &cb
.cb_proplist
,
7266 if (cb
.cb_proplist
== &fake_name
)
7267 zprop_free_list(fake_name
.pl_next
);
7269 zprop_free_list(cb
.cb_proplist
);
7274 typedef struct set_cbdata
{
7277 boolean_t cb_any_successful
;
7281 set_callback(zpool_handle_t
*zhp
, void *data
)
7284 set_cbdata_t
*cb
= (set_cbdata_t
*)data
;
7286 error
= zpool_set_prop(zhp
, cb
->cb_propname
, cb
->cb_value
);
7289 cb
->cb_any_successful
= B_TRUE
;
7295 zpool_do_set(int argc
, char **argv
)
7297 set_cbdata_t cb
= { 0 };
7300 if (argc
> 1 && argv
[1][0] == '-') {
7301 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
7307 (void) fprintf(stderr
, gettext("missing property=value "
7313 (void) fprintf(stderr
, gettext("missing pool name\n"));
7318 (void) fprintf(stderr
, gettext("too many pool names\n"));
7322 cb
.cb_propname
= argv
[1];
7323 cb
.cb_value
= strchr(cb
.cb_propname
, '=');
7324 if (cb
.cb_value
== NULL
) {
7325 (void) fprintf(stderr
, gettext("missing value in "
7326 "property=value argument\n"));
7330 *(cb
.cb_value
) = '\0';
7333 error
= for_each_pool(argc
- 2, argv
+ 2, B_TRUE
, NULL
,
7340 find_command_idx(char *command
, int *idx
)
7344 for (i
= 0; i
< NCOMMAND
; i
++) {
7345 if (command_table
[i
].name
== NULL
)
7348 if (strcmp(command
, command_table
[i
].name
) == 0) {
7357 main(int argc
, char **argv
)
7363 (void) setlocale(LC_ALL
, "");
7364 (void) textdomain(TEXT_DOMAIN
);
7367 dprintf_setup(&argc
, argv
);
7372 * Make sure the user has specified some command.
7375 (void) fprintf(stderr
, gettext("missing command\n"));
7384 if ((strcmp(cmdname
, "-?") == 0) || strcmp(cmdname
, "--help") == 0)
7387 if ((g_zfs
= libzfs_init()) == NULL
) {
7388 (void) fprintf(stderr
, "%s", libzfs_error_init(errno
));
7392 libzfs_print_on_error(g_zfs
, B_TRUE
);
7394 zfs_save_arguments(argc
, argv
, history_str
, sizeof (history_str
));
7397 * Run the appropriate command.
7399 if (find_command_idx(cmdname
, &i
) == 0) {
7400 current_command
= &command_table
[i
];
7401 ret
= command_table
[i
].func(argc
- 1, argv
+ 1);
7402 } else if (strchr(cmdname
, '=')) {
7403 verify(find_command_idx("set", &i
) == 0);
7404 current_command
= &command_table
[i
];
7405 ret
= command_table
[i
].func(argc
, argv
);
7406 } else if (strcmp(cmdname
, "freeze") == 0 && argc
== 3) {
7408 * 'freeze' is a vile debugging abomination, so we treat
7412 int fd
= open(ZFS_DEV
, O_RDWR
);
7413 (void) strcpy((void *)buf
, argv
[2]);
7414 return (!!ioctl(fd
, ZFS_IOC_POOL_FREEZE
, buf
));
7416 (void) fprintf(stderr
, gettext("unrecognized "
7417 "command '%s'\n"), cmdname
);
7422 if (ret
== 0 && log_history
)
7423 (void) zpool_log_history(g_zfs
, history_str
);
7428 * The 'ZFS_ABORT' environment variable causes us to dump core on exit
7429 * for the purposes of running ::findleaks.
7431 if (getenv("ZFS_ABORT") != NULL
) {
7432 (void) printf("dumping core by request\n");