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"
156 IOS_COUNT
, /* always last element */
159 /* iostat_type entries as bitmasks */
160 #define IOS_DEFAULT_M (1ULL << IOS_DEFAULT)
161 #define IOS_LATENCY_M (1ULL << IOS_LATENCY)
162 #define IOS_QUEUES_M (1ULL << IOS_QUEUES)
163 #define IOS_L_HISTO_M (1ULL << IOS_L_HISTO)
165 typedef struct zpool_command
{
167 int (*func
)(int, char **);
172 * Master command table. Each ZFS command has a name, associated function, and
173 * usage message. The usage messages need to be internationalized, so we have
174 * to have a function to return the usage message based on a command index.
176 * These commands are organized according to how they are displayed in the usage
177 * message. An empty command (one with a NULL name) indicates an empty line in
178 * the generic usage message.
180 static zpool_command_t command_table
[] = {
181 { "create", zpool_do_create
, HELP_CREATE
},
182 { "destroy", zpool_do_destroy
, HELP_DESTROY
},
184 { "add", zpool_do_add
, HELP_ADD
},
185 { "remove", zpool_do_remove
, HELP_REMOVE
},
187 { "labelclear", zpool_do_labelclear
, HELP_LABELCLEAR
},
189 { "list", zpool_do_list
, HELP_LIST
},
190 { "iostat", zpool_do_iostat
, HELP_IOSTAT
},
191 { "status", zpool_do_status
, HELP_STATUS
},
193 { "online", zpool_do_online
, HELP_ONLINE
},
194 { "offline", zpool_do_offline
, HELP_OFFLINE
},
195 { "clear", zpool_do_clear
, HELP_CLEAR
},
196 { "reopen", zpool_do_reopen
, HELP_REOPEN
},
198 { "attach", zpool_do_attach
, HELP_ATTACH
},
199 { "detach", zpool_do_detach
, HELP_DETACH
},
200 { "replace", zpool_do_replace
, HELP_REPLACE
},
201 { "split", zpool_do_split
, HELP_SPLIT
},
203 { "scrub", zpool_do_scrub
, HELP_SCRUB
},
205 { "import", zpool_do_import
, HELP_IMPORT
},
206 { "export", zpool_do_export
, HELP_EXPORT
},
207 { "upgrade", zpool_do_upgrade
, HELP_UPGRADE
},
208 { "reguid", zpool_do_reguid
, HELP_REGUID
},
210 { "history", zpool_do_history
, HELP_HISTORY
},
211 { "events", zpool_do_events
, HELP_EVENTS
},
213 { "get", zpool_do_get
, HELP_GET
},
214 { "set", zpool_do_set
, HELP_SET
},
217 #define NCOMMAND (ARRAY_SIZE(command_table))
219 static zpool_command_t
*current_command
;
220 static char history_str
[HIS_MAX_RECORD_LEN
];
221 static boolean_t log_history
= B_TRUE
;
222 static uint_t timestamp_fmt
= NODATE
;
225 get_usage(zpool_help_t idx
) {
228 return (gettext("\tadd [-fgLnP] [-o property=value] "
229 "<pool> <vdev> ...\n"));
231 return (gettext("\tattach [-f] [-o property=value] "
232 "<pool> <device> <new-device>\n"));
234 return (gettext("\tclear [-nF] <pool> [device]\n"));
236 return (gettext("\tcreate [-fnd] [-o property=value] ... \n"
237 "\t [-O file-system-property=value] ... \n"
238 "\t [-m mountpoint] [-R root] <pool> <vdev> ...\n"));
240 return (gettext("\tdestroy [-f] <pool>\n"));
242 return (gettext("\tdetach <pool> <device>\n"));
244 return (gettext("\texport [-af] <pool> ...\n"));
246 return (gettext("\thistory [-il] [<pool>] ...\n"));
248 return (gettext("\timport [-d dir] [-D]\n"
249 "\timport [-d dir | -c cachefile] [-F [-n]] <pool | id>\n"
250 "\timport [-o mntopts] [-o property=value] ... \n"
251 "\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
252 "[-R root] [-F [-n]] -a\n"
253 "\timport [-o mntopts] [-o property=value] ... \n"
254 "\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
255 "[-R root] [-F [-n]]\n"
256 "\t <pool | id> [newpool]\n"));
258 return (gettext("\tiostat [-T d | u] [-ghHLpPvy] [[-lq]|-w]\n"
259 "\t [[pool ...]|[pool vdev ...]|[vdev ...]] "
260 "[interval [count]]\n"));
261 case HELP_LABELCLEAR
:
262 return (gettext("\tlabelclear [-f] <vdev>\n"));
264 return (gettext("\tlist [-gHLpPv] [-o property[,...]] "
265 "[-T d|u] [pool] ... [interval [count]]\n"));
267 return (gettext("\toffline [-t] <pool> <device> ...\n"));
269 return (gettext("\tonline <pool> <device> ...\n"));
271 return (gettext("\treplace [-f] [-o property=value] "
272 "<pool> <device> [new-device]\n"));
274 return (gettext("\tremove <pool> <device> ...\n"));
276 return (gettext("\treopen <pool>\n"));
278 return (gettext("\tscrub [-s] <pool> ...\n"));
280 return (gettext("\tstatus [-gLPvxD] [-T d|u] [pool] ... "
281 "[interval [count]]\n"));
283 return (gettext("\tupgrade\n"
285 "\tupgrade [-V version] <-a | pool ...>\n"));
287 return (gettext("\tevents [-vHfc]\n"));
289 return (gettext("\tget [-Hp] [-o \"all\" | field[,...]] "
290 "<\"all\" | property[,...]> <pool> ...\n"));
292 return (gettext("\tset <property=value> <pool> \n"));
294 return (gettext("\tsplit [-gLnP] [-R altroot] [-o mntopts]\n"
295 "\t [-o property=value] <pool> <newpool> "
296 "[<device> ...]\n"));
298 return (gettext("\treguid <pool>\n"));
307 * Callback routine that will print out a pool property value.
310 print_prop_cb(int prop
, void *cb
)
314 (void) fprintf(fp
, "\t%-15s ", zpool_prop_to_name(prop
));
316 if (zpool_prop_readonly(prop
))
317 (void) fprintf(fp
, " NO ");
319 (void) fprintf(fp
, " YES ");
321 if (zpool_prop_values(prop
) == NULL
)
322 (void) fprintf(fp
, "-\n");
324 (void) fprintf(fp
, "%s\n", zpool_prop_values(prop
));
330 * Display usage message. If we're inside a command, display only the usage for
331 * that command. Otherwise, iterate over the entire command table and display
332 * a complete usage message.
335 usage(boolean_t requested
)
337 FILE *fp
= requested
? stdout
: stderr
;
339 if (current_command
== NULL
) {
342 (void) fprintf(fp
, gettext("usage: zpool command args ...\n"));
344 gettext("where 'command' is one of the following:\n\n"));
346 for (i
= 0; i
< NCOMMAND
; i
++) {
347 if (command_table
[i
].name
== NULL
)
348 (void) fprintf(fp
, "\n");
350 (void) fprintf(fp
, "%s",
351 get_usage(command_table
[i
].usage
));
354 (void) fprintf(fp
, gettext("usage:\n"));
355 (void) fprintf(fp
, "%s", get_usage(current_command
->usage
));
358 if (current_command
!= NULL
&&
359 ((strcmp(current_command
->name
, "set") == 0) ||
360 (strcmp(current_command
->name
, "get") == 0) ||
361 (strcmp(current_command
->name
, "list") == 0))) {
364 gettext("\nthe following properties are supported:\n"));
366 (void) fprintf(fp
, "\n\t%-15s %s %s\n\n",
367 "PROPERTY", "EDIT", "VALUES");
369 /* Iterate over all properties */
370 (void) zprop_iter(print_prop_cb
, fp
, B_FALSE
, B_TRUE
,
373 (void) fprintf(fp
, "\t%-15s ", "feature@...");
374 (void) fprintf(fp
, "YES disabled | enabled | active\n");
376 (void) fprintf(fp
, gettext("\nThe feature@ properties must be "
377 "appended with a feature name.\nSee zpool-features(5).\n"));
381 * See comments at end of main().
383 if (getenv("ZFS_ABORT") != NULL
) {
384 (void) printf("dumping core by request\n");
388 exit(requested
? 0 : 2);
392 print_vdev_tree(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
, int indent
,
393 boolean_t print_logs
, int name_flags
)
400 (void) printf("\t%*s%s\n", indent
, "", name
);
402 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
403 &child
, &children
) != 0)
406 for (c
= 0; c
< children
; c
++) {
407 uint64_t is_log
= B_FALSE
;
409 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
411 if ((is_log
&& !print_logs
) || (!is_log
&& print_logs
))
414 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], name_flags
);
415 print_vdev_tree(zhp
, vname
, child
[c
], indent
+ 2,
416 B_FALSE
, name_flags
);
422 prop_list_contains_feature(nvlist_t
*proplist
)
425 for (nvp
= nvlist_next_nvpair(proplist
, NULL
); NULL
!= nvp
;
426 nvp
= nvlist_next_nvpair(proplist
, nvp
)) {
427 if (zpool_prop_feature(nvpair_name(nvp
)))
434 * Add a property pair (name, string-value) into a property nvlist.
437 add_prop_list(const char *propname
, char *propval
, nvlist_t
**props
,
440 zpool_prop_t prop
= ZPROP_INVAL
;
446 if (*props
== NULL
&&
447 nvlist_alloc(props
, NV_UNIQUE_NAME
, 0) != 0) {
448 (void) fprintf(stderr
,
449 gettext("internal error: out of memory\n"));
456 const char *vname
= zpool_prop_to_name(ZPOOL_PROP_VERSION
);
458 if ((prop
= zpool_name_to_prop(propname
)) == ZPROP_INVAL
&&
459 !zpool_prop_feature(propname
)) {
460 (void) fprintf(stderr
, gettext("property '%s' is "
461 "not a valid pool property\n"), propname
);
466 * feature@ properties and version should not be specified
469 if ((prop
== ZPROP_INVAL
&& zpool_prop_feature(propname
) &&
470 nvlist_exists(proplist
, vname
)) ||
471 (prop
== ZPOOL_PROP_VERSION
&&
472 prop_list_contains_feature(proplist
))) {
473 (void) fprintf(stderr
, gettext("'feature@' and "
474 "'version' properties cannot be specified "
480 if (zpool_prop_feature(propname
))
483 normnm
= zpool_prop_to_name(prop
);
485 if ((fprop
= zfs_name_to_prop(propname
)) != ZPROP_INVAL
) {
486 normnm
= zfs_prop_to_name(fprop
);
492 if (nvlist_lookup_string(proplist
, normnm
, &strval
) == 0 &&
493 prop
!= ZPOOL_PROP_CACHEFILE
) {
494 (void) fprintf(stderr
, gettext("property '%s' "
495 "specified multiple times\n"), propname
);
499 if (nvlist_add_string(proplist
, normnm
, propval
) != 0) {
500 (void) fprintf(stderr
, gettext("internal "
501 "error: out of memory\n"));
509 * Set a default property pair (name, string-value) in a property nvlist
512 add_prop_list_default(const char *propname
, char *propval
, nvlist_t
**props
,
517 if (nvlist_lookup_string(*props
, propname
, &pval
) == 0)
520 return (add_prop_list(propname
, propval
, props
, B_TRUE
));
524 * zpool add [-fgLnP] [-o property=value] <pool> <vdev> ...
526 * -f Force addition of devices, even if they appear in use
527 * -g Display guid for individual vdev name.
528 * -L Follow links when resolving vdev path name.
529 * -n Do not add the devices, but display the resulting layout if
530 * they were to be added.
531 * -o Set property=value.
532 * -P Display full path for vdev name.
534 * Adds the given vdevs to 'pool'. As with create, the bulk of this work is
535 * handled by get_vdev_spec(), which constructs the nvlist needed to pass to
539 zpool_do_add(int argc
, char **argv
)
541 boolean_t force
= B_FALSE
;
542 boolean_t dryrun
= B_FALSE
;
550 nvlist_t
*props
= NULL
;
554 while ((c
= getopt(argc
, argv
, "fgLno:P")) != -1) {
560 name_flags
|= VDEV_NAME_GUID
;
563 name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
569 if ((propval
= strchr(optarg
, '=')) == NULL
) {
570 (void) fprintf(stderr
, gettext("missing "
571 "'=' for -o option\n"));
577 if ((strcmp(optarg
, ZPOOL_CONFIG_ASHIFT
) != 0) ||
578 (add_prop_list(optarg
, propval
, &props
, B_TRUE
)))
582 name_flags
|= VDEV_NAME_PATH
;
585 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
594 /* get pool name and check number of arguments */
596 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
600 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
609 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
612 if ((config
= zpool_get_config(zhp
, NULL
)) == NULL
) {
613 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
619 /* pass off to get_vdev_spec for processing */
620 nvroot
= make_root_vdev(zhp
, props
, force
, !force
, B_FALSE
, dryrun
,
622 if (nvroot
== NULL
) {
628 nvlist_t
*poolnvroot
;
630 uint_t l2children
, c
;
632 boolean_t hadcache
= B_FALSE
;
634 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
637 (void) printf(gettext("would update '%s' to the following "
638 "configuration:\n"), zpool_get_name(zhp
));
640 /* print original main pool and new tree */
641 print_vdev_tree(zhp
, poolname
, poolnvroot
, 0, B_FALSE
,
643 print_vdev_tree(zhp
, NULL
, nvroot
, 0, B_FALSE
, name_flags
);
645 /* Do the same for the logs */
646 if (num_logs(poolnvroot
) > 0) {
647 print_vdev_tree(zhp
, "logs", poolnvroot
, 0, B_TRUE
,
649 print_vdev_tree(zhp
, NULL
, nvroot
, 0, B_TRUE
,
651 } else if (num_logs(nvroot
) > 0) {
652 print_vdev_tree(zhp
, "logs", nvroot
, 0, B_TRUE
,
656 /* Do the same for the caches */
657 if (nvlist_lookup_nvlist_array(poolnvroot
, ZPOOL_CONFIG_L2CACHE
,
658 &l2child
, &l2children
) == 0 && l2children
) {
660 (void) printf(gettext("\tcache\n"));
661 for (c
= 0; c
< l2children
; c
++) {
662 vname
= zpool_vdev_name(g_zfs
, NULL
,
663 l2child
[c
], name_flags
);
664 (void) printf("\t %s\n", vname
);
668 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_L2CACHE
,
669 &l2child
, &l2children
) == 0 && l2children
) {
671 (void) printf(gettext("\tcache\n"));
672 for (c
= 0; c
< l2children
; c
++) {
673 vname
= zpool_vdev_name(g_zfs
, NULL
,
674 l2child
[c
], name_flags
);
675 (void) printf("\t %s\n", vname
);
682 ret
= (zpool_add(zhp
, nvroot
) != 0);
693 * zpool remove <pool> <vdev> ...
695 * Removes the given vdev from the pool. Currently, this supports removing
696 * spares, cache, and log devices from the pool.
699 zpool_do_remove(int argc
, char **argv
)
708 /* get pool name and check number of arguments */
710 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
714 (void) fprintf(stderr
, gettext("missing device\n"));
720 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
723 for (i
= 1; i
< argc
; i
++) {
724 if (zpool_vdev_remove(zhp
, argv
[i
]) != 0)
732 * zpool labelclear <vdev>
734 * Verifies that the vdev is not active and zeros out the label information
738 zpool_do_labelclear(int argc
, char **argv
)
741 int c
, fd
= -1, ret
= 0;
743 boolean_t inuse
= B_FALSE
;
744 boolean_t force
= B_FALSE
;
747 while ((c
= getopt(argc
, argv
, "f")) != -1) {
753 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
764 (void) fprintf(stderr
, gettext("missing vdev device name\n"));
769 if ((fd
= open(vdev
, O_RDWR
)) < 0) {
770 (void) fprintf(stderr
, gettext("Unable to open %s\n"), vdev
);
775 if (zpool_in_use(g_zfs
, fd
, &state
, &name
, &inuse
) != 0) {
779 (void) fprintf(stderr
,
780 gettext("Unable to determine pool state for %s\n"
781 "Use -f to force the clearing any label data\n"), vdev
);
789 case POOL_STATE_ACTIVE
:
790 case POOL_STATE_SPARE
:
791 case POOL_STATE_L2CACHE
:
792 (void) fprintf(stderr
,
793 gettext("labelclear operation failed.\n"
794 "\tVdev %s is a member (%s), of pool \"%s\".\n"
795 "\tTo remove label information from this device, "
796 "export or destroy\n\tthe pool, or remove %s from "
797 "the configuration of this pool\n\tand retry the "
798 "labelclear operation.\n"),
799 vdev
, zpool_pool_state_to_name(state
), name
, vdev
);
803 case POOL_STATE_EXPORTED
:
807 (void) fprintf(stderr
,
808 gettext("labelclear operation failed.\n\tVdev "
809 "%s is a member of the exported pool \"%s\".\n"
810 "\tUse \"zpool labelclear -f %s\" to force the "
811 "removal of label\n\tinformation.\n"),
816 case POOL_STATE_POTENTIALLY_ACTIVE
:
820 (void) fprintf(stderr
,
821 gettext("labelclear operation failed.\n"
822 "\tVdev %s is a member of the pool \"%s\".\n"
823 "\tThis pool is unknown to this system, but may "
824 "be active on\n\tanother system. Use "
825 "\'zpool labelclear -f %s\' to force the\n"
826 "\tremoval of label information.\n"),
831 case POOL_STATE_DESTROYED
:
832 /* inuse should never be set for a destroyed pool... */
838 if (zpool_clear_label(fd
) != 0) {
839 (void) fprintf(stderr
,
840 gettext("Label clear failed on vdev %s\n"), vdev
);
853 * zpool create [-fnd] [-o property=value] ...
854 * [-O file-system-property=value] ...
855 * [-R root] [-m mountpoint] <pool> <dev> ...
857 * -f Force creation, even if devices appear in use
858 * -n Do not create the pool, but display the resulting layout if it
859 * were to be created.
860 * -R Create a pool under an alternate root
861 * -m Set default mountpoint for the root dataset. By default it's
863 * -o Set property=value.
864 * -d Don't automatically enable all supported pool features
865 * (individual features can be enabled with -o).
866 * -O Set fsproperty=value in the pool's root file system
868 * Creates the named pool according to the given vdev specification. The
869 * bulk of the vdev processing is done in get_vdev_spec() in zpool_vdev.c. Once
870 * we get the nvlist back from get_vdev_spec(), we either print out the contents
871 * (if '-n' was specified), or pass it to libzfs to do the creation.
874 zpool_do_create(int argc
, char **argv
)
876 boolean_t force
= B_FALSE
;
877 boolean_t dryrun
= B_FALSE
;
878 boolean_t enable_all_pool_feat
= B_TRUE
;
880 nvlist_t
*nvroot
= NULL
;
884 char *altroot
= NULL
;
885 char *mountpoint
= NULL
;
886 nvlist_t
*fsprops
= NULL
;
887 nvlist_t
*props
= NULL
;
891 while ((c
= getopt(argc
, argv
, ":fndR:m:o:O:t:")) != -1) {
900 enable_all_pool_feat
= B_FALSE
;
904 if (add_prop_list(zpool_prop_to_name(
905 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
907 if (add_prop_list_default(zpool_prop_to_name(
908 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
912 /* Equivalent to -O mountpoint=optarg */
916 if ((propval
= strchr(optarg
, '=')) == NULL
) {
917 (void) fprintf(stderr
, gettext("missing "
918 "'=' for -o option\n"));
924 if (add_prop_list(optarg
, propval
, &props
, B_TRUE
))
928 * If the user is creating a pool that doesn't support
929 * feature flags, don't enable any features.
931 if (zpool_name_to_prop(optarg
) == ZPOOL_PROP_VERSION
) {
935 ver
= strtoull(propval
, &end
, 10);
937 ver
< SPA_VERSION_FEATURES
) {
938 enable_all_pool_feat
= B_FALSE
;
941 if (zpool_name_to_prop(optarg
) == ZPOOL_PROP_ALTROOT
)
945 if ((propval
= strchr(optarg
, '=')) == NULL
) {
946 (void) fprintf(stderr
, gettext("missing "
947 "'=' for -O option\n"));
954 * Mountpoints are checked and then added later.
955 * Uniquely among properties, they can be specified
956 * more than once, to avoid conflict with -m.
958 if (0 == strcmp(optarg
,
959 zfs_prop_to_name(ZFS_PROP_MOUNTPOINT
))) {
960 mountpoint
= propval
;
961 } else if (add_prop_list(optarg
, propval
, &fsprops
,
968 * Sanity check temporary pool name.
970 if (strchr(optarg
, '/') != NULL
) {
971 (void) fprintf(stderr
, gettext("cannot create "
972 "'%s': invalid character '/' in temporary "
974 (void) fprintf(stderr
, gettext("use 'zfs "
975 "create' to create a dataset\n"));
979 if (add_prop_list(zpool_prop_to_name(
980 ZPOOL_PROP_TNAME
), optarg
, &props
, B_TRUE
))
982 if (add_prop_list_default(zpool_prop_to_name(
983 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
988 (void) fprintf(stderr
, gettext("missing argument for "
989 "'%c' option\n"), optopt
);
992 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1001 /* get pool name and check number of arguments */
1003 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
1007 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
1014 * As a special case, check for use of '/' in the name, and direct the
1015 * user to use 'zfs create' instead.
1017 if (strchr(poolname
, '/') != NULL
) {
1018 (void) fprintf(stderr
, gettext("cannot create '%s': invalid "
1019 "character '/' in pool name\n"), poolname
);
1020 (void) fprintf(stderr
, gettext("use 'zfs create' to "
1021 "create a dataset\n"));
1025 /* pass off to get_vdev_spec for bulk processing */
1026 nvroot
= make_root_vdev(NULL
, props
, force
, !force
, B_FALSE
, dryrun
,
1027 argc
- 1, argv
+ 1);
1031 /* make_root_vdev() allows 0 toplevel children if there are spares */
1032 if (!zfs_allocatable_devs(nvroot
)) {
1033 (void) fprintf(stderr
, gettext("invalid vdev "
1034 "specification: at least one toplevel vdev must be "
1039 if (altroot
!= NULL
&& altroot
[0] != '/') {
1040 (void) fprintf(stderr
, gettext("invalid alternate root '%s': "
1041 "must be an absolute path\n"), altroot
);
1046 * Check the validity of the mountpoint and direct the user to use the
1047 * '-m' mountpoint option if it looks like its in use.
1049 if (mountpoint
== NULL
||
1050 (strcmp(mountpoint
, ZFS_MOUNTPOINT_LEGACY
) != 0 &&
1051 strcmp(mountpoint
, ZFS_MOUNTPOINT_NONE
) != 0)) {
1052 char buf
[MAXPATHLEN
];
1055 if (mountpoint
&& mountpoint
[0] != '/') {
1056 (void) fprintf(stderr
, gettext("invalid mountpoint "
1057 "'%s': must be an absolute path, 'legacy', or "
1058 "'none'\n"), mountpoint
);
1062 if (mountpoint
== NULL
) {
1063 if (altroot
!= NULL
)
1064 (void) snprintf(buf
, sizeof (buf
), "%s/%s",
1067 (void) snprintf(buf
, sizeof (buf
), "/%s",
1070 if (altroot
!= NULL
)
1071 (void) snprintf(buf
, sizeof (buf
), "%s%s",
1072 altroot
, mountpoint
);
1074 (void) snprintf(buf
, sizeof (buf
), "%s",
1078 if ((dirp
= opendir(buf
)) == NULL
&& errno
!= ENOENT
) {
1079 (void) fprintf(stderr
, gettext("mountpoint '%s' : "
1080 "%s\n"), buf
, strerror(errno
));
1081 (void) fprintf(stderr
, gettext("use '-m' "
1082 "option to provide a different default\n"));
1087 while (count
< 3 && readdir(dirp
) != NULL
)
1089 (void) closedir(dirp
);
1092 (void) fprintf(stderr
, gettext("mountpoint "
1093 "'%s' exists and is not empty\n"), buf
);
1094 (void) fprintf(stderr
, gettext("use '-m' "
1095 "option to provide a "
1096 "different default\n"));
1103 * Now that the mountpoint's validity has been checked, ensure that
1104 * the property is set appropriately prior to creating the pool.
1106 if (mountpoint
!= NULL
) {
1107 ret
= add_prop_list(zfs_prop_to_name(ZFS_PROP_MOUNTPOINT
),
1108 mountpoint
, &fsprops
, B_FALSE
);
1116 * For a dry run invocation, print out a basic message and run
1117 * through all the vdevs in the list and print out in an
1118 * appropriate hierarchy.
1120 (void) printf(gettext("would create '%s' with the "
1121 "following layout:\n\n"), poolname
);
1123 print_vdev_tree(NULL
, poolname
, nvroot
, 0, B_FALSE
, 0);
1124 if (num_logs(nvroot
) > 0)
1125 print_vdev_tree(NULL
, "logs", nvroot
, 0, B_TRUE
, 0);
1130 * Hand off to libzfs.
1132 if (enable_all_pool_feat
) {
1134 for (i
= 0; i
< SPA_FEATURES
; i
++) {
1135 char propname
[MAXPATHLEN
];
1136 zfeature_info_t
*feat
= &spa_feature_table
[i
];
1138 (void) snprintf(propname
, sizeof (propname
),
1139 "feature@%s", feat
->fi_uname
);
1142 * Skip feature if user specified it manually
1143 * on the command line.
1145 if (nvlist_exists(props
, propname
))
1148 ret
= add_prop_list(propname
,
1149 ZFS_FEATURE_ENABLED
, &props
, B_TRUE
);
1156 if (zpool_create(g_zfs
, poolname
,
1157 nvroot
, props
, fsprops
) == 0) {
1158 zfs_handle_t
*pool
= zfs_open(g_zfs
,
1159 tname
? tname
: poolname
, ZFS_TYPE_FILESYSTEM
);
1161 if (zfs_mount(pool
, NULL
, 0) == 0)
1162 ret
= zfs_shareall(pool
);
1165 } else if (libzfs_errno(g_zfs
) == EZFS_INVALIDNAME
) {
1166 (void) fprintf(stderr
, gettext("pool name may have "
1172 nvlist_free(nvroot
);
1173 nvlist_free(fsprops
);
1177 nvlist_free(fsprops
);
1184 * zpool destroy <pool>
1186 * -f Forcefully unmount any datasets
1188 * Destroy the given pool. Automatically unmounts any datasets in the pool.
1191 zpool_do_destroy(int argc
, char **argv
)
1193 boolean_t force
= B_FALSE
;
1196 zpool_handle_t
*zhp
;
1200 while ((c
= getopt(argc
, argv
, "f")) != -1) {
1206 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1215 /* check arguments */
1217 (void) fprintf(stderr
, gettext("missing pool argument\n"));
1221 (void) fprintf(stderr
, gettext("too many arguments\n"));
1227 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
) {
1229 * As a special case, check for use of '/' in the name, and
1230 * direct the user to use 'zfs destroy' instead.
1232 if (strchr(pool
, '/') != NULL
)
1233 (void) fprintf(stderr
, gettext("use 'zfs destroy' to "
1234 "destroy a dataset\n"));
1238 if (zpool_disable_datasets(zhp
, force
) != 0) {
1239 (void) fprintf(stderr
, gettext("could not destroy '%s': "
1240 "could not unmount datasets\n"), zpool_get_name(zhp
));
1244 /* The history must be logged as part of the export */
1245 log_history
= B_FALSE
;
1247 ret
= (zpool_destroy(zhp
, history_str
) != 0);
1254 typedef struct export_cbdata
{
1256 boolean_t hardforce
;
1263 zpool_export_one(zpool_handle_t
*zhp
, void *data
)
1265 export_cbdata_t
*cb
= data
;
1267 if (zpool_disable_datasets(zhp
, cb
->force
) != 0)
1270 /* The history must be logged as part of the export */
1271 log_history
= B_FALSE
;
1273 if (cb
->hardforce
) {
1274 if (zpool_export_force(zhp
, history_str
) != 0)
1276 } else if (zpool_export(zhp
, cb
->force
, history_str
) != 0) {
1284 * zpool export [-f] <pool> ...
1286 * -a Export all pools
1287 * -f Forcefully unmount datasets
1289 * Export the given pools. By default, the command will attempt to cleanly
1290 * unmount any active datasets within the pool. If the '-f' flag is specified,
1291 * then the datasets will be forcefully unmounted.
1294 zpool_do_export(int argc
, char **argv
)
1297 boolean_t do_all
= B_FALSE
;
1298 boolean_t force
= B_FALSE
;
1299 boolean_t hardforce
= B_FALSE
;
1303 while ((c
= getopt(argc
, argv
, "afF")) != -1) {
1315 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1322 cb
.hardforce
= hardforce
;
1328 (void) fprintf(stderr
, gettext("too many arguments\n"));
1332 return (for_each_pool(argc
, argv
, B_TRUE
, NULL
,
1333 zpool_export_one
, &cb
));
1336 /* check arguments */
1338 (void) fprintf(stderr
, gettext("missing pool argument\n"));
1342 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
, zpool_export_one
, &cb
);
1348 * Given a vdev configuration, determine the maximum width needed for the device
1352 max_width(zpool_handle_t
*zhp
, nvlist_t
*nv
, int depth
, int max
,
1360 name
= zpool_vdev_name(g_zfs
, zhp
, nv
, name_flags
| VDEV_NAME_TYPE_ID
);
1361 if (strlen(name
) + depth
> max
)
1362 max
= strlen(name
) + depth
;
1366 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
1367 &child
, &children
) == 0) {
1368 for (c
= 0; c
< children
; c
++)
1369 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1370 max
, name_flags
)) > max
)
1374 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
1375 &child
, &children
) == 0) {
1376 for (c
= 0; c
< children
; c
++)
1377 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1378 max
, name_flags
)) > max
)
1382 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1383 &child
, &children
) == 0) {
1384 for (c
= 0; c
< children
; c
++)
1385 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1386 max
, name_flags
)) > max
)
1393 typedef struct spare_cbdata
{
1395 zpool_handle_t
*cb_zhp
;
1399 find_vdev(nvlist_t
*nv
, uint64_t search
)
1405 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
, &guid
) == 0 &&
1409 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1410 &child
, &children
) == 0) {
1411 for (c
= 0; c
< children
; c
++)
1412 if (find_vdev(child
[c
], search
))
1420 find_spare(zpool_handle_t
*zhp
, void *data
)
1422 spare_cbdata_t
*cbp
= data
;
1423 nvlist_t
*config
, *nvroot
;
1425 config
= zpool_get_config(zhp
, NULL
);
1426 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
1429 if (find_vdev(nvroot
, cbp
->cb_guid
)) {
1439 * Print out configuration state as requested by status_callback.
1442 print_status_config(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
,
1443 int namewidth
, int depth
, boolean_t isspare
, int name_flags
)
1447 pool_scan_stat_t
*ps
= NULL
;
1449 char rbuf
[6], wbuf
[6], cbuf
[6];
1451 uint64_t notpresent
;
1455 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1456 &child
, &children
) != 0)
1459 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
1460 (uint64_t **)&vs
, &c
) == 0);
1462 state
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
1465 * For hot spares, we use the terms 'INUSE' and 'AVAILABLE' for
1468 if (vs
->vs_aux
== VDEV_AUX_SPARED
)
1470 else if (vs
->vs_state
== VDEV_STATE_HEALTHY
)
1474 (void) printf("\t%*s%-*s %-8s", depth
, "", namewidth
- depth
,
1478 zfs_nicenum(vs
->vs_read_errors
, rbuf
, sizeof (rbuf
));
1479 zfs_nicenum(vs
->vs_write_errors
, wbuf
, sizeof (wbuf
));
1480 zfs_nicenum(vs
->vs_checksum_errors
, cbuf
, sizeof (cbuf
));
1481 (void) printf(" %5s %5s %5s", rbuf
, wbuf
, cbuf
);
1484 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_NOT_PRESENT
,
1485 ¬present
) == 0) {
1487 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_PATH
, &path
) == 0);
1488 (void) printf(" was %s", path
);
1489 } else if (vs
->vs_aux
!= 0) {
1492 switch (vs
->vs_aux
) {
1493 case VDEV_AUX_OPEN_FAILED
:
1494 (void) printf(gettext("cannot open"));
1497 case VDEV_AUX_BAD_GUID_SUM
:
1498 (void) printf(gettext("missing device"));
1501 case VDEV_AUX_NO_REPLICAS
:
1502 (void) printf(gettext("insufficient replicas"));
1505 case VDEV_AUX_VERSION_NEWER
:
1506 (void) printf(gettext("newer version"));
1509 case VDEV_AUX_UNSUP_FEAT
:
1510 (void) printf(gettext("unsupported feature(s)"));
1513 case VDEV_AUX_SPARED
:
1514 verify(nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
,
1516 if (zpool_iter(g_zfs
, find_spare
, &cb
) == 1) {
1517 if (strcmp(zpool_get_name(cb
.cb_zhp
),
1518 zpool_get_name(zhp
)) == 0)
1519 (void) printf(gettext("currently in "
1522 (void) printf(gettext("in use by "
1524 zpool_get_name(cb
.cb_zhp
));
1525 zpool_close(cb
.cb_zhp
);
1527 (void) printf(gettext("currently in use"));
1531 case VDEV_AUX_ERR_EXCEEDED
:
1532 (void) printf(gettext("too many errors"));
1535 case VDEV_AUX_IO_FAILURE
:
1536 (void) printf(gettext("experienced I/O failures"));
1539 case VDEV_AUX_BAD_LOG
:
1540 (void) printf(gettext("bad intent log"));
1543 case VDEV_AUX_EXTERNAL
:
1544 (void) printf(gettext("external device fault"));
1547 case VDEV_AUX_SPLIT_POOL
:
1548 (void) printf(gettext("split into new pool"));
1552 (void) printf(gettext("corrupted data"));
1557 (void) nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_SCAN_STATS
,
1558 (uint64_t **)&ps
, &c
);
1560 if (ps
&& ps
->pss_state
== DSS_SCANNING
&&
1561 vs
->vs_scan_processed
!= 0 && children
== 0) {
1562 (void) printf(gettext(" (%s)"),
1563 (ps
->pss_func
== POOL_SCAN_RESILVER
) ?
1564 "resilvering" : "repairing");
1567 (void) printf("\n");
1569 for (c
= 0; c
< children
; c
++) {
1570 uint64_t islog
= B_FALSE
, ishole
= B_FALSE
;
1572 /* Don't print logs or holes here */
1573 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1575 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_HOLE
,
1577 if (islog
|| ishole
)
1579 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
1580 name_flags
| VDEV_NAME_TYPE_ID
);
1581 print_status_config(zhp
, vname
, child
[c
],
1582 namewidth
, depth
+ 2, isspare
, name_flags
);
1588 * Print the configuration of an exported pool. Iterate over all vdevs in the
1589 * pool, printing out the name and status for each one.
1592 print_import_config(const char *name
, nvlist_t
*nv
, int namewidth
, int depth
,
1600 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_TYPE
, &type
) == 0);
1601 if (strcmp(type
, VDEV_TYPE_MISSING
) == 0 ||
1602 strcmp(type
, VDEV_TYPE_HOLE
) == 0)
1605 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
1606 (uint64_t **)&vs
, &c
) == 0);
1608 (void) printf("\t%*s%-*s", depth
, "", namewidth
- depth
, name
);
1609 (void) printf(" %s", zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
));
1611 if (vs
->vs_aux
!= 0) {
1614 switch (vs
->vs_aux
) {
1615 case VDEV_AUX_OPEN_FAILED
:
1616 (void) printf(gettext("cannot open"));
1619 case VDEV_AUX_BAD_GUID_SUM
:
1620 (void) printf(gettext("missing device"));
1623 case VDEV_AUX_NO_REPLICAS
:
1624 (void) printf(gettext("insufficient replicas"));
1627 case VDEV_AUX_VERSION_NEWER
:
1628 (void) printf(gettext("newer version"));
1631 case VDEV_AUX_UNSUP_FEAT
:
1632 (void) printf(gettext("unsupported feature(s)"));
1635 case VDEV_AUX_ERR_EXCEEDED
:
1636 (void) printf(gettext("too many errors"));
1640 (void) printf(gettext("corrupted data"));
1644 (void) printf("\n");
1646 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1647 &child
, &children
) != 0)
1650 for (c
= 0; c
< children
; c
++) {
1651 uint64_t is_log
= B_FALSE
;
1653 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1658 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
],
1659 name_flags
| VDEV_NAME_TYPE_ID
);
1660 print_import_config(vname
, child
[c
], namewidth
, depth
+ 2,
1665 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
1666 &child
, &children
) == 0) {
1667 (void) printf(gettext("\tcache\n"));
1668 for (c
= 0; c
< children
; c
++) {
1669 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
],
1671 (void) printf("\t %s\n", vname
);
1676 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
1677 &child
, &children
) == 0) {
1678 (void) printf(gettext("\tspares\n"));
1679 for (c
= 0; c
< children
; c
++) {
1680 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
],
1682 (void) printf("\t %s\n", vname
);
1690 * Logs are recorded as top level vdevs in the main pool child array
1691 * but with "is_log" set to 1. We use either print_status_config() or
1692 * print_import_config() to print the top level logs then any log
1693 * children (eg mirrored slogs) are printed recursively - which
1694 * works because only the top level vdev is marked "is_log"
1697 print_logs(zpool_handle_t
*zhp
, nvlist_t
*nv
, int namewidth
, boolean_t verbose
,
1703 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
, &child
,
1707 (void) printf(gettext("\tlogs\n"));
1709 for (c
= 0; c
< children
; c
++) {
1710 uint64_t is_log
= B_FALSE
;
1713 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1717 name
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
1718 name_flags
| VDEV_NAME_TYPE_ID
);
1720 print_status_config(zhp
, name
, child
[c
], namewidth
,
1721 2, B_FALSE
, name_flags
);
1723 print_import_config(name
, child
[c
], namewidth
, 2,
1730 * Display the status for the given pool.
1733 show_import(nvlist_t
*config
)
1735 uint64_t pool_state
;
1741 zpool_status_t reason
;
1742 zpool_errata_t errata
;
1748 verify(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
1750 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
,
1752 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
1754 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
1757 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_VDEV_STATS
,
1758 (uint64_t **)&vs
, &vsc
) == 0);
1759 health
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
1761 reason
= zpool_import_status(config
, &msgid
, &errata
);
1763 (void) printf(gettext(" pool: %s\n"), name
);
1764 (void) printf(gettext(" id: %llu\n"), (u_longlong_t
)guid
);
1765 (void) printf(gettext(" state: %s"), health
);
1766 if (pool_state
== POOL_STATE_DESTROYED
)
1767 (void) printf(gettext(" (DESTROYED)"));
1768 (void) printf("\n");
1771 case ZPOOL_STATUS_MISSING_DEV_R
:
1772 case ZPOOL_STATUS_MISSING_DEV_NR
:
1773 case ZPOOL_STATUS_BAD_GUID_SUM
:
1774 (void) printf(gettext(" status: One or more devices are "
1775 "missing from the system.\n"));
1778 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
1779 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
1780 (void) printf(gettext(" status: One or more devices contains "
1781 "corrupted data.\n"));
1784 case ZPOOL_STATUS_CORRUPT_DATA
:
1786 gettext(" status: The pool data is corrupted.\n"));
1789 case ZPOOL_STATUS_OFFLINE_DEV
:
1790 (void) printf(gettext(" status: One or more devices "
1791 "are offlined.\n"));
1794 case ZPOOL_STATUS_CORRUPT_POOL
:
1795 (void) printf(gettext(" status: The pool metadata is "
1799 case ZPOOL_STATUS_VERSION_OLDER
:
1800 (void) printf(gettext(" status: The pool is formatted using a "
1801 "legacy on-disk version.\n"));
1804 case ZPOOL_STATUS_VERSION_NEWER
:
1805 (void) printf(gettext(" status: The pool is formatted using an "
1806 "incompatible version.\n"));
1809 case ZPOOL_STATUS_FEAT_DISABLED
:
1810 (void) printf(gettext(" status: Some supported features are "
1811 "not enabled on the pool.\n"));
1814 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
1815 (void) printf(gettext("status: The pool uses the following "
1816 "feature(s) not supported on this sytem:\n"));
1817 zpool_print_unsup_feat(config
);
1820 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
1821 (void) printf(gettext("status: The pool can only be accessed "
1822 "in read-only mode on this system. It\n\tcannot be "
1823 "accessed in read-write mode because it uses the "
1824 "following\n\tfeature(s) not supported on this system:\n"));
1825 zpool_print_unsup_feat(config
);
1828 case ZPOOL_STATUS_HOSTID_MISMATCH
:
1829 (void) printf(gettext(" status: The pool was last accessed by "
1830 "another system.\n"));
1833 case ZPOOL_STATUS_FAULTED_DEV_R
:
1834 case ZPOOL_STATUS_FAULTED_DEV_NR
:
1835 (void) printf(gettext(" status: One or more devices are "
1839 case ZPOOL_STATUS_BAD_LOG
:
1840 (void) printf(gettext(" status: An intent log record cannot be "
1844 case ZPOOL_STATUS_RESILVERING
:
1845 (void) printf(gettext(" status: One or more devices were being "
1849 case ZPOOL_STATUS_ERRATA
:
1850 (void) printf(gettext(" status: Errata #%d detected.\n"),
1856 * No other status can be seen when importing pools.
1858 assert(reason
== ZPOOL_STATUS_OK
);
1862 * Print out an action according to the overall state of the pool.
1864 if (vs
->vs_state
== VDEV_STATE_HEALTHY
) {
1865 if (reason
== ZPOOL_STATUS_VERSION_OLDER
||
1866 reason
== ZPOOL_STATUS_FEAT_DISABLED
) {
1867 (void) printf(gettext(" action: The pool can be "
1868 "imported using its name or numeric identifier, "
1869 "though\n\tsome features will not be available "
1870 "without an explicit 'zpool upgrade'.\n"));
1871 } else if (reason
== ZPOOL_STATUS_HOSTID_MISMATCH
) {
1872 (void) printf(gettext(" action: The pool can be "
1873 "imported using its name or numeric "
1874 "identifier and\n\tthe '-f' flag.\n"));
1875 } else if (reason
== ZPOOL_STATUS_ERRATA
) {
1877 case ZPOOL_ERRATA_NONE
:
1880 case ZPOOL_ERRATA_ZOL_2094_SCRUB
:
1881 (void) printf(gettext(" action: The pool can "
1882 "be imported using its name or numeric "
1883 "identifier,\n\thowever there is a compat"
1884 "ibility issue which should be corrected"
1885 "\n\tby running 'zpool scrub'\n"));
1888 case ZPOOL_ERRATA_ZOL_2094_ASYNC_DESTROY
:
1889 (void) printf(gettext(" action: The pool can"
1890 "not be imported with this version of ZFS "
1891 "due to\n\tan active asynchronous destroy. "
1892 "Revert to an earlier version\n\tand "
1893 "allow the destroy to complete before "
1899 * All errata must contain an action message.
1904 (void) printf(gettext(" action: The pool can be "
1905 "imported using its name or numeric "
1908 } else if (vs
->vs_state
== VDEV_STATE_DEGRADED
) {
1909 (void) printf(gettext(" action: The pool can be imported "
1910 "despite missing or damaged devices. The\n\tfault "
1911 "tolerance of the pool may be compromised if imported.\n"));
1914 case ZPOOL_STATUS_VERSION_NEWER
:
1915 (void) printf(gettext(" action: The pool cannot be "
1916 "imported. Access the pool on a system running "
1917 "newer\n\tsoftware, or recreate the pool from "
1920 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
1921 (void) printf(gettext("action: The pool cannot be "
1922 "imported. Access the pool on a system that "
1923 "supports\n\tthe required feature(s), or recreate "
1924 "the pool from backup.\n"));
1926 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
1927 (void) printf(gettext("action: The pool cannot be "
1928 "imported in read-write mode. Import the pool "
1930 "\t\"-o readonly=on\", access the pool on a system "
1931 "that supports the\n\trequired feature(s), or "
1932 "recreate the pool from backup.\n"));
1934 case ZPOOL_STATUS_MISSING_DEV_R
:
1935 case ZPOOL_STATUS_MISSING_DEV_NR
:
1936 case ZPOOL_STATUS_BAD_GUID_SUM
:
1937 (void) printf(gettext(" action: The pool cannot be "
1938 "imported. Attach the missing\n\tdevices and try "
1942 (void) printf(gettext(" action: The pool cannot be "
1943 "imported due to damaged devices or data.\n"));
1947 /* Print the comment attached to the pool. */
1948 if (nvlist_lookup_string(config
, ZPOOL_CONFIG_COMMENT
, &comment
) == 0)
1949 (void) printf(gettext("comment: %s\n"), comment
);
1952 * If the state is "closed" or "can't open", and the aux state
1953 * is "corrupt data":
1955 if (((vs
->vs_state
== VDEV_STATE_CLOSED
) ||
1956 (vs
->vs_state
== VDEV_STATE_CANT_OPEN
)) &&
1957 (vs
->vs_aux
== VDEV_AUX_CORRUPT_DATA
)) {
1958 if (pool_state
== POOL_STATE_DESTROYED
)
1959 (void) printf(gettext("\tThe pool was destroyed, "
1960 "but can be imported using the '-Df' flags.\n"));
1961 else if (pool_state
!= POOL_STATE_EXPORTED
)
1962 (void) printf(gettext("\tThe pool may be active on "
1963 "another system, but can be imported using\n\t"
1964 "the '-f' flag.\n"));
1968 (void) printf(gettext(" see: http://zfsonlinux.org/msg/%s\n"),
1971 (void) printf(gettext(" config:\n\n"));
1973 namewidth
= max_width(NULL
, nvroot
, 0, 0, 0);
1977 print_import_config(name
, nvroot
, namewidth
, 0, 0);
1978 if (num_logs(nvroot
) > 0)
1979 print_logs(NULL
, nvroot
, namewidth
, B_FALSE
, 0);
1981 if (reason
== ZPOOL_STATUS_BAD_GUID_SUM
) {
1982 (void) printf(gettext("\n\tAdditional devices are known to "
1983 "be part of this pool, though their\n\texact "
1984 "configuration cannot be determined.\n"));
1989 * Perform the import for the given configuration. This passes the heavy
1990 * lifting off to zpool_import_props(), and then mounts the datasets contained
1994 do_import(nvlist_t
*config
, const char *newname
, const char *mntopts
,
1995 nvlist_t
*props
, int flags
)
1997 zpool_handle_t
*zhp
;
2002 verify(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
2005 verify(nvlist_lookup_uint64(config
,
2006 ZPOOL_CONFIG_POOL_STATE
, &state
) == 0);
2007 verify(nvlist_lookup_uint64(config
,
2008 ZPOOL_CONFIG_VERSION
, &version
) == 0);
2009 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
2010 (void) fprintf(stderr
, gettext("cannot import '%s': pool "
2011 "is formatted using an unsupported ZFS version\n"), name
);
2013 } else if (state
!= POOL_STATE_EXPORTED
&&
2014 !(flags
& ZFS_IMPORT_ANY_HOST
)) {
2015 uint64_t hostid
= 0;
2016 unsigned long system_hostid
= get_system_hostid();
2018 (void) nvlist_lookup_uint64(config
, ZPOOL_CONFIG_HOSTID
,
2021 if (hostid
!= 0 && (unsigned long)hostid
!= system_hostid
) {
2026 verify(nvlist_lookup_string(config
,
2027 ZPOOL_CONFIG_HOSTNAME
, &hostname
) == 0);
2028 verify(nvlist_lookup_uint64(config
,
2029 ZPOOL_CONFIG_TIMESTAMP
, ×tamp
) == 0);
2031 (void) fprintf(stderr
, gettext("cannot import "
2032 "'%s': pool may be in use from other "
2033 "system, it was last accessed by %s "
2034 "(hostid: 0x%lx) on %s"), name
, hostname
,
2035 (unsigned long)hostid
,
2036 asctime(localtime(&t
)));
2037 (void) fprintf(stderr
, gettext("use '-f' to "
2038 "import anyway\n"));
2043 if (zpool_import_props(g_zfs
, config
, newname
, props
, flags
) != 0)
2046 if (newname
!= NULL
)
2047 name
= (char *)newname
;
2049 if ((zhp
= zpool_open_canfail(g_zfs
, name
)) == NULL
)
2052 if (zpool_get_state(zhp
) != POOL_STATE_UNAVAIL
&&
2053 !(flags
& ZFS_IMPORT_ONLY
) &&
2054 zpool_enable_datasets(zhp
, mntopts
, 0) != 0) {
2064 * zpool import [-d dir] [-D]
2065 * import [-o mntopts] [-o prop=value] ... [-R root] [-D]
2066 * [-d dir | -c cachefile] [-f] -a
2067 * import [-o mntopts] [-o prop=value] ... [-R root] [-D]
2068 * [-d dir | -c cachefile] [-f] [-n] [-F] <pool | id> [newpool]
2070 * -c Read pool information from a cachefile instead of searching
2073 * -d Scan in a specific directory, other than /dev/. More than
2074 * one directory can be specified using multiple '-d' options.
2076 * -D Scan for previously destroyed pools or import all or only
2077 * specified destroyed pools.
2079 * -R Temporarily import the pool, with all mountpoints relative to
2080 * the given root. The pool will remain exported when the machine
2083 * -V Import even in the presence of faulted vdevs. This is an
2084 * intentionally undocumented option for testing purposes, and
2085 * treats the pool configuration as complete, leaving any bad
2086 * vdevs in the FAULTED state. In other words, it does verbatim
2089 * -f Force import, even if it appears that the pool is active.
2091 * -F Attempt rewind if necessary.
2093 * -n See if rewind would work, but don't actually rewind.
2095 * -N Import the pool but don't mount datasets.
2097 * -T Specify a starting txg to use for import. This option is
2098 * intentionally undocumented option for testing purposes.
2100 * -a Import all pools found.
2102 * -o Set property=value and/or temporary mount options (without '=').
2104 * -s Scan using the default search path, the libblkid cache will
2107 * The import command scans for pools to import, and import pools based on pool
2108 * name and GUID. The pool can also be renamed as part of the import process.
2111 zpool_do_import(int argc
, char **argv
)
2113 char **searchdirs
= NULL
;
2114 char *env
, *envdup
= NULL
;
2118 nvlist_t
*pools
= NULL
;
2119 boolean_t do_all
= B_FALSE
;
2120 boolean_t do_destroyed
= B_FALSE
;
2121 char *mntopts
= NULL
;
2124 uint64_t searchguid
= 0;
2125 char *searchname
= NULL
;
2127 nvlist_t
*found_config
;
2128 nvlist_t
*policy
= NULL
;
2129 nvlist_t
*props
= NULL
;
2131 int flags
= ZFS_IMPORT_NORMAL
;
2132 uint32_t rewind_policy
= ZPOOL_NO_REWIND
;
2133 boolean_t dryrun
= B_FALSE
;
2134 boolean_t do_rewind
= B_FALSE
;
2135 boolean_t xtreme_rewind
= B_FALSE
;
2136 boolean_t do_scan
= B_FALSE
;
2137 uint64_t pool_state
, txg
= -1ULL;
2138 char *cachefile
= NULL
;
2139 importargs_t idata
= { 0 };
2143 while ((c
= getopt(argc
, argv
, ":aCc:d:DEfFmnNo:R:stT:VX")) != -1) {
2152 if (searchdirs
== NULL
) {
2153 searchdirs
= safe_malloc(sizeof (char *));
2155 char **tmp
= safe_malloc((nsearch
+ 1) *
2157 bcopy(searchdirs
, tmp
, nsearch
*
2162 searchdirs
[nsearch
++] = optarg
;
2165 do_destroyed
= B_TRUE
;
2168 flags
|= ZFS_IMPORT_ANY_HOST
;
2174 flags
|= ZFS_IMPORT_MISSING_LOG
;
2180 flags
|= ZFS_IMPORT_ONLY
;
2183 if ((propval
= strchr(optarg
, '=')) != NULL
) {
2186 if (add_prop_list(optarg
, propval
,
2194 if (add_prop_list(zpool_prop_to_name(
2195 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
2197 if (add_prop_list_default(zpool_prop_to_name(
2198 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
2205 flags
|= ZFS_IMPORT_TEMP_NAME
;
2206 if (add_prop_list_default(zpool_prop_to_name(
2207 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
2213 txg
= strtoull(optarg
, &endptr
, 0);
2214 if (errno
!= 0 || *endptr
!= '\0') {
2215 (void) fprintf(stderr
,
2216 gettext("invalid txg value\n"));
2219 rewind_policy
= ZPOOL_DO_REWIND
| ZPOOL_EXTREME_REWIND
;
2222 flags
|= ZFS_IMPORT_VERBATIM
;
2225 xtreme_rewind
= B_TRUE
;
2228 (void) fprintf(stderr
, gettext("missing argument for "
2229 "'%c' option\n"), optopt
);
2233 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2242 if (cachefile
&& nsearch
!= 0) {
2243 (void) fprintf(stderr
, gettext("-c is incompatible with -d\n"));
2247 if ((dryrun
|| xtreme_rewind
) && !do_rewind
) {
2248 (void) fprintf(stderr
,
2249 gettext("-n or -X only meaningful with -F\n"));
2253 rewind_policy
= ZPOOL_TRY_REWIND
;
2255 rewind_policy
= ZPOOL_DO_REWIND
;
2257 rewind_policy
|= ZPOOL_EXTREME_REWIND
;
2259 /* In the future, we can capture further policy and include it here */
2260 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME
, 0) != 0 ||
2261 nvlist_add_uint64(policy
, ZPOOL_REWIND_REQUEST_TXG
, txg
) != 0 ||
2262 nvlist_add_uint32(policy
, ZPOOL_REWIND_REQUEST
, rewind_policy
) != 0)
2265 /* check argument count */
2268 (void) fprintf(stderr
, gettext("too many arguments\n"));
2273 (void) fprintf(stderr
, gettext("too many arguments\n"));
2278 * Check for the SYS_CONFIG privilege. We do this explicitly
2279 * here because otherwise any attempt to discover pools will
2282 if (argc
== 0 && !priv_ineffect(PRIV_SYS_CONFIG
)) {
2283 (void) fprintf(stderr
, gettext("cannot "
2284 "discover pools: permission denied\n"));
2285 if (searchdirs
!= NULL
)
2288 nvlist_free(policy
);
2294 * Depending on the arguments given, we do one of the following:
2296 * <none> Iterate through all pools and display information about
2299 * -a Iterate through all pools and try to import each one.
2301 * <id> Find the pool that corresponds to the given GUID/pool
2302 * name and import that one.
2304 * -D Above options applies only to destroyed pools.
2310 searchguid
= strtoull(argv
[0], &endptr
, 10);
2311 if (errno
!= 0 || *endptr
!= '\0') {
2312 searchname
= argv
[0];
2315 found_config
= NULL
;
2318 * User specified a name or guid. Ensure it's unique.
2320 idata
.unique
= B_TRUE
;
2324 * Check the environment for the preferred search path.
2326 if ((searchdirs
== NULL
) && (env
= getenv("ZPOOL_IMPORT_PATH"))) {
2329 envdup
= strdup(env
);
2331 dir
= strtok(envdup
, ":");
2332 while (dir
!= NULL
) {
2333 if (searchdirs
== NULL
) {
2334 searchdirs
= safe_malloc(sizeof (char *));
2336 char **tmp
= safe_malloc((nsearch
+ 1) *
2338 bcopy(searchdirs
, tmp
, nsearch
*
2343 searchdirs
[nsearch
++] = dir
;
2344 dir
= strtok(NULL
, ":");
2348 idata
.path
= searchdirs
;
2349 idata
.paths
= nsearch
;
2350 idata
.poolname
= searchname
;
2351 idata
.guid
= searchguid
;
2352 idata
.cachefile
= cachefile
;
2353 idata
.scan
= do_scan
;
2356 * Under Linux the zpool_find_import_impl() function leverages the
2357 * taskq implementation to parallelize device scanning. It is
2358 * therefore necessary to initialize this functionality for the
2359 * duration of the zpool_search_import() function.
2362 pools
= zpool_search_import(g_zfs
, &idata
);
2365 if (pools
!= NULL
&& idata
.exists
&&
2366 (argc
== 1 || strcmp(argv
[0], argv
[1]) == 0)) {
2367 (void) fprintf(stderr
, gettext("cannot import '%s': "
2368 "a pool with that name already exists\n"),
2370 (void) fprintf(stderr
, gettext("use the form '%s "
2371 "<pool | id> <newpool>' to give it a new name\n"),
2374 } else if (pools
== NULL
&& idata
.exists
) {
2375 (void) fprintf(stderr
, gettext("cannot import '%s': "
2376 "a pool with that name is already created/imported,\n"),
2378 (void) fprintf(stderr
, gettext("and no additional pools "
2379 "with that name were found\n"));
2381 } else if (pools
== NULL
) {
2383 (void) fprintf(stderr
, gettext("cannot import '%s': "
2384 "no such pool available\n"), argv
[0]);
2390 if (searchdirs
!= NULL
)
2394 nvlist_free(policy
);
2399 * At this point we have a list of import candidate configs. Even if
2400 * we were searching by pool name or guid, we still need to
2401 * post-process the list to deal with pool state and possible
2407 while ((elem
= nvlist_next_nvpair(pools
, elem
)) != NULL
) {
2409 verify(nvpair_value_nvlist(elem
, &config
) == 0);
2411 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
2413 if (!do_destroyed
&& pool_state
== POOL_STATE_DESTROYED
)
2415 if (do_destroyed
&& pool_state
!= POOL_STATE_DESTROYED
)
2418 verify(nvlist_add_nvlist(config
, ZPOOL_REWIND_POLICY
,
2425 (void) printf("\n");
2428 err
|= do_import(config
, NULL
, mntopts
,
2431 show_import(config
);
2433 } else if (searchname
!= NULL
) {
2437 * We are searching for a pool based on name.
2439 verify(nvlist_lookup_string(config
,
2440 ZPOOL_CONFIG_POOL_NAME
, &name
) == 0);
2442 if (strcmp(name
, searchname
) == 0) {
2443 if (found_config
!= NULL
) {
2444 (void) fprintf(stderr
, gettext(
2445 "cannot import '%s': more than "
2446 "one matching pool\n"), searchname
);
2447 (void) fprintf(stderr
, gettext(
2448 "import by numeric ID instead\n"));
2451 found_config
= config
;
2457 * Search for a pool by guid.
2459 verify(nvlist_lookup_uint64(config
,
2460 ZPOOL_CONFIG_POOL_GUID
, &guid
) == 0);
2462 if (guid
== searchguid
)
2463 found_config
= config
;
2468 * If we were searching for a specific pool, verify that we found a
2469 * pool, and then do the import.
2471 if (argc
!= 0 && err
== 0) {
2472 if (found_config
== NULL
) {
2473 (void) fprintf(stderr
, gettext("cannot import '%s': "
2474 "no such pool available\n"), argv
[0]);
2477 err
|= do_import(found_config
, argc
== 1 ? NULL
:
2478 argv
[1], mntopts
, props
, flags
);
2483 * If we were just looking for pools, report an error if none were
2486 if (argc
== 0 && first
)
2487 (void) fprintf(stderr
,
2488 gettext("no pools available to import\n"));
2493 nvlist_free(policy
);
2494 if (searchdirs
!= NULL
)
2499 return (err
? 1 : 0);
2502 typedef struct iostat_cbdata
{
2507 char **cb_vdev_names
; /* Only show these vdevs */
2508 unsigned int cb_vdev_names_count
;
2509 boolean_t cb_verbose
;
2510 boolean_t cb_literal
;
2511 boolean_t cb_scripted
;
2512 zpool_list_t
*cb_list
;
2516 typedef struct name_and_columns
{
2517 const char *name
; /* Column name */
2518 unsigned int columns
; /* Center name to this number of columns */
2519 } name_and_columns_t
;
2521 #define IOSTAT_MAX_LABELS 11 /* Max number of labels on one line */
2523 static const name_and_columns_t iostat_top_labels
[][IOSTAT_MAX_LABELS
] =
2525 [IOS_DEFAULT
] = {{"capacity", 2}, {"operations", 2}, {"bandwidth", 2},
2527 [IOS_LATENCY
] = {{"total_wait", 2}, {"disk_wait", 2}, {"syncq_wait", 2},
2528 {"asyncq_wait", 2}, {"scrub"}},
2529 [IOS_QUEUES
] = {{"syncq_read", 2}, {"syncq_write", 2},
2530 {"asyncq_read", 2}, {"asyncq_write", 2}, {"scrubq_read", 2},
2532 [IOS_L_HISTO
] = {{"total_wait", 2}, {"disk_wait", 2},
2533 {"sync_queue", 2}, {"async_queue", 2}, {NULL
}},
2536 /* Shorthand - if "columns" field not set, default to 1 column */
2537 static const name_and_columns_t iostat_bottom_labels
[][IOSTAT_MAX_LABELS
] =
2539 [IOS_DEFAULT
] = {{"alloc"}, {"free"}, {"read"}, {"write"}, {"read"},
2541 [IOS_LATENCY
] = {{"read"}, {"write"}, {"read"}, {"write"}, {"read"},
2542 {"write"}, {"read"}, {"write"}, {"wait"}, {NULL
}},
2543 [IOS_QUEUES
] = {{"pend"}, {"activ"}, {"pend"}, {"activ"}, {"pend"},
2544 {"activ"}, {"pend"}, {"activ"}, {"pend"}, {"activ"}, {NULL
}},
2545 [IOS_L_HISTO
] = {{"read"}, {"write"}, {"read"}, {"write"}, {"read"},
2546 {"write"}, {"read"}, {"write"}, {"scrub"}, {NULL
}},
2550 * Return the number of labels in a null-terminated name_and_columns_t
2555 label_array_len(const name_and_columns_t
*labels
)
2559 while (labels
[i
].name
)
2566 * Return a default column width for default/latency/queue columns. This does
2567 * not include histograms, which have their columns autosized.
2570 default_column_width(iostat_cbdata_t
*cb
, enum iostat_type type
)
2572 unsigned long column_width
= 5; /* Normal niceprint */
2573 static unsigned long widths
[] = {
2575 * Choose some sane default column sizes for printing the
2578 [IOS_DEFAULT
] = 15, /* 1PB capacity */
2579 [IOS_LATENCY
] = 10, /* 1B ns = 10sec */
2580 [IOS_QUEUES
] = 6, /* 1M queue entries */
2584 column_width
= widths
[type
];
2586 return (column_width
);
2590 * Print the column labels, i.e:
2592 * capacity operations bandwidth
2593 * alloc free read write read write ...
2595 * If force_column_width is set, use it for the column width. If not set, use
2596 * the default column width.
2599 print_iostat_labels(iostat_cbdata_t
*cb
, unsigned int force_column_width
,
2600 const name_and_columns_t labels
[][IOSTAT_MAX_LABELS
])
2603 unsigned int text_start
, rw_column_width
, spaces_to_end
;
2604 uint64_t flags
= cb
->cb_flags
;
2606 unsigned int column_width
= force_column_width
;
2608 /* For each bit set in flags */
2609 for (f
= flags
; f
; f
&= ~(1ULL << idx
)) {
2610 idx
= lowbit64(f
) - 1;
2611 if (!force_column_width
)
2612 column_width
= default_column_width(cb
, idx
);
2613 /* Print our top labels centered over "read write" label. */
2614 for (i
= 0; i
< label_array_len(labels
[idx
]); i
++) {
2615 const char *name
= labels
[idx
][i
].name
;
2617 * We treat labels[][].columns == 0 as shorthand
2618 * for one column. It makes writing out the label
2619 * tables more concise.
2621 unsigned int columns
= MAX(1, labels
[idx
][i
].columns
);
2622 unsigned int slen
= strlen(name
);
2624 rw_column_width
= (column_width
* columns
) +
2625 (2 * (columns
- 1));
2627 text_start
= (int) ((rw_column_width
)/columns
-
2630 printf(" "); /* Two spaces between columns */
2632 /* Space from beginning of column to label */
2633 for (s
= 0; s
< text_start
; s
++)
2638 /* Print space after label to end of column */
2639 spaces_to_end
= rw_column_width
- text_start
- slen
;
2640 for (s
= 0; s
< spaces_to_end
; s
++)
2649 * Utility function to print out a line of dashes like:
2651 * -------------------------------- ----- ----- ----- ----- -----
2653 * ...or a dashed named-row line like:
2659 * @force_column_width If non-zero, use the value as the column width.
2660 * Otherwise use the default column widths.
2662 * @name: Print a dashed named-row line starting
2663 * with @name. Otherwise, print a regular
2667 print_iostat_dashes(iostat_cbdata_t
*cb
, unsigned int force_column_width
,
2671 unsigned int namewidth
;
2672 uint64_t flags
= cb
->cb_flags
;
2675 const name_and_columns_t
*labels
;
2677 if (cb
->cb_flags
& IOS_L_HISTO_M
)
2678 namewidth
= MAX(cb
->cb_namewidth
, strlen("latency"));
2680 namewidth
= cb
->cb_namewidth
;
2683 namewidth
= MAX(cb
->cb_namewidth
, strlen(name
));
2684 printf("%-*s", namewidth
, name
);
2686 for (i
= 0; i
< namewidth
; i
++)
2690 /* For each bit in flags */
2691 for (f
= flags
; f
; f
&= ~(1ULL << idx
)) {
2692 unsigned int column_width
;
2693 idx
= lowbit64(f
) - 1;
2694 if (force_column_width
)
2695 column_width
= force_column_width
;
2697 column_width
= default_column_width(cb
, idx
);
2699 labels
= iostat_bottom_labels
[idx
];
2700 for (i
= 0; i
< label_array_len(labels
); i
++) {
2702 printf(" %*s-", column_width
- 1, " ");
2704 printf(" %.*s", column_width
,
2705 "--------------------");
2713 print_iostat_separator_impl(iostat_cbdata_t
*cb
,
2714 unsigned int force_column_width
)
2716 print_iostat_dashes(cb
, force_column_width
, NULL
);
2720 print_iostat_separator(iostat_cbdata_t
*cb
)
2722 print_iostat_separator_impl(cb
, 0);
2726 print_iostat_header_impl(iostat_cbdata_t
*cb
, unsigned int force_column_width
,
2727 const char *histo_vdev_name
)
2729 unsigned int namewidth
;
2730 uint64_t flags
= cb
->cb_flags
;
2732 if (flags
& IOS_L_HISTO_M
)
2733 namewidth
= MAX(cb
->cb_namewidth
, strlen("latency"));
2735 namewidth
= cb
->cb_namewidth
;
2737 if (flags
& IOS_L_HISTO_M
)
2738 printf("%-*s", namewidth
, histo_vdev_name
);
2740 printf("%*s", namewidth
, "");
2742 print_iostat_labels(cb
, force_column_width
, iostat_top_labels
);
2744 printf("%-*s", namewidth
, flags
& IOS_L_HISTO_M
? "latency" :
2745 cb
->cb_vdev_names_count
? "vdev" : "pool");
2747 print_iostat_labels(cb
, force_column_width
, iostat_bottom_labels
);
2749 print_iostat_separator_impl(cb
, force_column_width
);
2753 print_iostat_header(iostat_cbdata_t
*cb
)
2755 print_iostat_header_impl(cb
, 0, NULL
);
2760 * Display a single statistic.
2763 print_one_stat(uint64_t value
, enum zfs_nicenum_format format
,
2764 unsigned int column_size
, boolean_t scripted
)
2768 zfs_nicenum_format(value
, buf
, sizeof (buf
), format
);
2771 printf("\t%s", buf
);
2773 printf(" %*s", column_size
, buf
);
2777 * Calculate the default vdev stats
2779 * Subtract oldvs from newvs, apply a scaling factor, and save the resulting
2780 * stats into calcvs.
2783 calc_default_iostats(vdev_stat_t
*oldvs
, vdev_stat_t
*newvs
,
2784 vdev_stat_t
*calcvs
)
2788 memcpy(calcvs
, newvs
, sizeof (*calcvs
));
2789 for (i
= 0; i
< ARRAY_SIZE(calcvs
->vs_ops
); i
++)
2790 calcvs
->vs_ops
[i
] = (newvs
->vs_ops
[i
] - oldvs
->vs_ops
[i
]);
2792 for (i
= 0; i
< ARRAY_SIZE(calcvs
->vs_bytes
); i
++)
2793 calcvs
->vs_bytes
[i
] = (newvs
->vs_bytes
[i
] - oldvs
->vs_bytes
[i
]);
2797 * Internal representation of the extended iostats data.
2799 * The extended iostat stats are exported in nvlists as either uint64_t arrays
2800 * or single uint64_t's. We make both look like arrays to make them easier
2801 * to process. In order to make single uint64_t's look like arrays, we set
2802 * __data to the stat data, and then set *data = &__data with count = 1. Then,
2803 * we can just use *data and count.
2807 uint_t count
; /* Number of entries in data[] */
2808 uint64_t __data
; /* Only used when data is a single uint64_t */
2812 stat_histo_max(struct stat_array
*nva
, unsigned int len
) {
2815 for (i
= 0; i
< len
; i
++)
2816 max
= MAX(max
, array64_max(nva
[i
].data
, nva
[i
].count
));
2822 * Helper function to lookup a uint64_t array or uint64_t value and store its
2823 * data as a stat_array. If the nvpair is a single uint64_t value, then we make
2824 * it look like a one element array to make it easier to process.
2827 nvpair64_to_stat_array(nvlist_t
*nvl
, const char *name
,
2828 struct stat_array
*nva
) {
2832 verify(nvlist_lookup_nvpair(nvl
, name
, &tmp
) == 0);
2833 switch (nvpair_type(tmp
)) {
2834 case DATA_TYPE_UINT64_ARRAY
:
2835 ret
= nvpair_value_uint64_array(tmp
, &nva
->data
, &nva
->count
);
2837 case DATA_TYPE_UINT64
:
2838 ret
= nvpair_value_uint64(tmp
, &nva
->__data
);
2839 nva
->data
= &nva
->__data
;
2843 /* Not a uint64_t */
2852 * Given a list of nvlist names, look up the extended stats in newnv and oldnv,
2853 * subtract them, and return the results in a newly allocated stat_array.
2854 * You must free the returned array after you are done with it with
2855 * free_calc_stats().
2857 * Additionally, you can set "oldnv" to NULL if you simply want the newnv
2860 static struct stat_array
*
2861 calc_and_alloc_stats_ex(const char **names
, unsigned int len
, nvlist_t
*oldnv
,
2864 nvlist_t
*oldnvx
= NULL
, *newnvx
;
2865 struct stat_array
*oldnva
, *newnva
, *calcnva
;
2867 unsigned int alloc_size
= (sizeof (struct stat_array
)) * len
;
2869 /* Extract our extended stats nvlist from the main list */
2870 verify(nvlist_lookup_nvlist(newnv
, ZPOOL_CONFIG_VDEV_STATS_EX
,
2873 verify(nvlist_lookup_nvlist(oldnv
, ZPOOL_CONFIG_VDEV_STATS_EX
,
2877 newnva
= safe_malloc(alloc_size
);
2878 oldnva
= safe_malloc(alloc_size
);
2879 calcnva
= safe_malloc(alloc_size
);
2881 for (j
= 0; j
< len
; j
++) {
2882 verify(nvpair64_to_stat_array(newnvx
, names
[j
],
2884 calcnva
[j
].count
= newnva
[j
].count
;
2885 alloc_size
= calcnva
[j
].count
* sizeof (calcnva
[j
].data
[0]);
2886 calcnva
[j
].data
= safe_malloc(alloc_size
);
2887 memcpy(calcnva
[j
].data
, newnva
[j
].data
, alloc_size
);
2890 verify(nvpair64_to_stat_array(oldnvx
, names
[j
],
2892 for (i
= 0; i
< oldnva
[j
].count
; i
++)
2893 calcnva
[j
].data
[i
] -= oldnva
[j
].data
[i
];
2902 free_calc_stats(struct stat_array
*nva
, unsigned int len
)
2905 for (i
= 0; i
< len
; i
++)
2912 print_iostat_histo(struct stat_array
*nva
, unsigned int len
,
2913 iostat_cbdata_t
*cb
, unsigned int column_width
, unsigned int namewidth
,
2919 enum zfs_nicenum_format format
;
2920 unsigned int buckets
;
2923 format
= ZFS_NICENUM_RAW
;
2925 format
= ZFS_NICENUM_1024
;
2927 /* All these histos are the same size, so just use nva[0].count */
2928 buckets
= nva
[0].count
;
2930 for (j
= 0; j
< buckets
; j
++) {
2931 /* Ending range of this bucket */
2932 val
= (1UL << (j
+ 1)) - 1;
2934 /* Print histogram bucket label */
2935 zfs_nicetime(val
, buf
, sizeof (buf
));
2936 if (cb
->cb_scripted
)
2937 printf("%llu", (u_longlong_t
) val
);
2939 printf("%-*s", namewidth
, buf
);
2941 /* Print the values on the line */
2942 for (i
= 0; i
< len
; i
++) {
2943 print_one_stat(nva
[i
].data
[j
] * scale
, format
,
2944 column_width
, cb
->cb_scripted
);
2951 print_solid_separator(unsigned int length
)
2959 print_iostat_histos(iostat_cbdata_t
*cb
, nvlist_t
*oldnv
,
2960 nvlist_t
*newnv
, double scale
, const char *name
)
2962 unsigned int column_width
;
2963 unsigned int namewidth
;
2964 unsigned int entire_width
;
2966 const char *names
[] = {
2967 ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO
,
2968 ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO
,
2969 ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO
,
2970 ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO
,
2971 ZPOOL_CONFIG_VDEV_SYNC_R_LAT_HISTO
,
2972 ZPOOL_CONFIG_VDEV_SYNC_W_LAT_HISTO
,
2973 ZPOOL_CONFIG_VDEV_ASYNC_R_LAT_HISTO
,
2974 ZPOOL_CONFIG_VDEV_ASYNC_W_LAT_HISTO
,
2975 ZPOOL_CONFIG_VDEV_SCRUB_LAT_HISTO
,
2977 struct stat_array
*nva
;
2978 nva
= calc_and_alloc_stats_ex(names
, ARRAY_SIZE(names
), oldnv
, newnv
);
2980 if (cb
->cb_literal
) {
2981 column_width
= MAX(5,
2982 (unsigned int) log10(stat_histo_max(nva
,
2983 ARRAY_SIZE(names
))) + 1);
2988 namewidth
= MAX(cb
->cb_namewidth
, strlen("latency"));
2991 * Calculate the entire line width of what we're printing. The
2992 * +2 is for the two spaces between columns:
2996 /* |___| <---------- column_width */
2998 /* |__________| <--- entire_width */
3000 entire_width
= namewidth
+ (column_width
+ 2) *
3001 label_array_len(iostat_bottom_labels
[IOS_L_HISTO
]);
3003 if (cb
->cb_scripted
)
3004 printf("%s\n", name
);
3006 print_iostat_header_impl(cb
, column_width
, name
);
3008 print_iostat_histo(nva
, ARRAY_SIZE(names
), cb
, column_width
,
3011 free_calc_stats(nva
, ARRAY_SIZE(names
));
3012 if (!cb
->cb_scripted
)
3013 print_solid_separator(entire_width
);
3017 * Calculate the average latency of a power-of-two latency histogram
3020 single_histo_average(uint64_t *histo
, unsigned int buckets
)
3023 uint64_t count
= 0, total
= 0;
3025 for (i
= 0; i
< buckets
; i
++) {
3027 * Our buckets are power-of-two latency ranges. Use the
3028 * midpoint latency of each bucket to calculate the average.
3036 if (histo
[i
] != 0) {
3037 total
+= histo
[i
] * (((1UL << i
) + ((1UL << i
)/2)));
3042 /* Prevent divide by zero */
3043 return (count
== 0 ? 0 : total
/ count
);
3047 print_iostat_queues(iostat_cbdata_t
*cb
, nvlist_t
*oldnv
,
3048 nvlist_t
*newnv
, double scale
)
3052 const char *names
[] = {
3053 ZPOOL_CONFIG_VDEV_SYNC_R_PEND_QUEUE
,
3054 ZPOOL_CONFIG_VDEV_SYNC_R_ACTIVE_QUEUE
,
3055 ZPOOL_CONFIG_VDEV_SYNC_W_PEND_QUEUE
,
3056 ZPOOL_CONFIG_VDEV_SYNC_W_ACTIVE_QUEUE
,
3057 ZPOOL_CONFIG_VDEV_ASYNC_R_PEND_QUEUE
,
3058 ZPOOL_CONFIG_VDEV_ASYNC_R_ACTIVE_QUEUE
,
3059 ZPOOL_CONFIG_VDEV_ASYNC_W_PEND_QUEUE
,
3060 ZPOOL_CONFIG_VDEV_ASYNC_W_ACTIVE_QUEUE
,
3061 ZPOOL_CONFIG_VDEV_SCRUB_PEND_QUEUE
,
3062 ZPOOL_CONFIG_VDEV_SCRUB_ACTIVE_QUEUE
,
3065 struct stat_array
*nva
;
3067 unsigned int column_width
= default_column_width(cb
, IOS_QUEUES
);
3068 enum zfs_nicenum_format format
;
3070 nva
= calc_and_alloc_stats_ex(names
, ARRAY_SIZE(names
), NULL
, newnv
);
3073 format
= ZFS_NICENUM_RAW
;
3075 format
= ZFS_NICENUM_1024
;
3077 for (i
= 0; i
< ARRAY_SIZE(names
); i
++) {
3078 val
= nva
[i
].data
[0] * scale
;
3079 print_one_stat(val
, format
, column_width
, cb
->cb_scripted
);
3082 free_calc_stats(nva
, ARRAY_SIZE(names
));
3086 print_iostat_latency(iostat_cbdata_t
*cb
, nvlist_t
*oldnv
,
3087 nvlist_t
*newnv
, double scale
)
3091 const char *names
[] = {
3092 ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO
,
3093 ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO
,
3094 ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO
,
3095 ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO
,
3096 ZPOOL_CONFIG_VDEV_SYNC_R_LAT_HISTO
,
3097 ZPOOL_CONFIG_VDEV_SYNC_W_LAT_HISTO
,
3098 ZPOOL_CONFIG_VDEV_ASYNC_R_LAT_HISTO
,
3099 ZPOOL_CONFIG_VDEV_ASYNC_W_LAT_HISTO
,
3100 ZPOOL_CONFIG_VDEV_SCRUB_LAT_HISTO
,
3102 struct stat_array
*nva
;
3104 unsigned int column_width
= default_column_width(cb
, IOS_LATENCY
);
3105 enum zfs_nicenum_format format
;
3107 nva
= calc_and_alloc_stats_ex(names
, ARRAY_SIZE(names
), oldnv
, newnv
);
3110 format
= ZFS_NICENUM_RAW
;
3112 format
= ZFS_NICENUM_TIME
;
3114 /* Print our avg latencies on the line */
3115 for (i
= 0; i
< ARRAY_SIZE(names
); i
++) {
3116 /* Compute average latency for a latency histo */
3117 val
= single_histo_average(nva
[i
].data
, nva
[i
].count
) * scale
;
3118 print_one_stat(val
, format
, column_width
, cb
->cb_scripted
);
3120 free_calc_stats(nva
, ARRAY_SIZE(names
));
3124 * Print default statistics (capacity/operations/bandwidth)
3127 print_iostat_default(vdev_stat_t
*vs
, iostat_cbdata_t
*cb
, double scale
)
3129 unsigned int column_width
= default_column_width(cb
, IOS_DEFAULT
);
3130 enum zfs_nicenum_format format
;
3131 char na
; /* char to print for "not applicable" values */
3133 if (cb
->cb_literal
) {
3134 format
= ZFS_NICENUM_RAW
;
3137 format
= ZFS_NICENUM_1024
;
3141 /* only toplevel vdevs have capacity stats */
3142 if (vs
->vs_space
== 0) {
3143 if (cb
->cb_scripted
)
3144 printf("\t%c\t%c", na
, na
);
3146 printf(" %*c %*c", column_width
, na
, column_width
,
3149 print_one_stat(vs
->vs_alloc
, format
, column_width
,
3151 print_one_stat(vs
->vs_space
- vs
->vs_alloc
, format
,
3152 column_width
, cb
->cb_scripted
);
3155 print_one_stat((uint64_t)(vs
->vs_ops
[ZIO_TYPE_READ
] * scale
),
3156 format
, column_width
, cb
->cb_scripted
);
3157 print_one_stat((uint64_t)(vs
->vs_ops
[ZIO_TYPE_WRITE
] * scale
),
3158 format
, column_width
, cb
->cb_scripted
);
3159 print_one_stat((uint64_t)(vs
->vs_bytes
[ZIO_TYPE_READ
] * scale
),
3160 format
, column_width
, cb
->cb_scripted
);
3161 print_one_stat((uint64_t)(vs
->vs_bytes
[ZIO_TYPE_WRITE
] * scale
),
3162 format
, column_width
, cb
->cb_scripted
);
3166 * Print out all the statistics for the given vdev. This can either be the
3167 * toplevel configuration, or called recursively. If 'name' is NULL, then this
3168 * is a verbose output, and we don't want to display the toplevel pool stats.
3170 * Returns the number of stat lines printed.
3173 print_vdev_stats(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*oldnv
,
3174 nvlist_t
*newnv
, iostat_cbdata_t
*cb
, int depth
)
3176 nvlist_t
**oldchild
, **newchild
;
3178 vdev_stat_t
*oldvs
, *newvs
, *calcvs
;
3179 vdev_stat_t zerovs
= { 0 };
3186 calcvs
= safe_malloc(sizeof (*calcvs
));
3188 if (oldnv
!= NULL
) {
3189 verify(nvlist_lookup_uint64_array(oldnv
,
3190 ZPOOL_CONFIG_VDEV_STATS
, (uint64_t **)&oldvs
, &c
) == 0);
3195 /* Do we only want to see a specific vdev? */
3196 for (i
= 0; i
< cb
->cb_vdev_names_count
; i
++) {
3197 /* Yes we do. Is this the vdev? */
3198 if (strcmp(name
, cb
->cb_vdev_names
[i
]) == 0) {
3200 * This is our vdev. Since it is the only vdev we
3201 * will be displaying, make depth = 0 so that it
3202 * doesn't get indented.
3209 if (cb
->cb_vdev_names_count
&& (i
== cb
->cb_vdev_names_count
)) {
3210 /* Couldn't match the name */
3215 verify(nvlist_lookup_uint64_array(newnv
, ZPOOL_CONFIG_VDEV_STATS
,
3216 (uint64_t **)&newvs
, &c
) == 0);
3219 * Print the vdev name unless it's is a histogram. Histograms
3220 * display the vdev name in the header itself.
3222 if (!(cb
->cb_flags
& IOS_L_HISTO_M
)) {
3223 if (cb
->cb_scripted
) {
3226 if (strlen(name
) + depth
> cb
->cb_namewidth
)
3227 (void) printf("%*s%s", depth
, "", name
);
3229 (void) printf("%*s%s%*s", depth
, "", name
,
3230 (int)(cb
->cb_namewidth
- strlen(name
) -
3235 /* Calculate our scaling factor */
3236 tdelta
= newvs
->vs_timestamp
- oldvs
->vs_timestamp
;
3237 if ((oldvs
->vs_timestamp
== 0) && (cb
->cb_flags
& IOS_L_HISTO_M
)) {
3239 * If we specify printing histograms with no time interval, then
3240 * print the histogram numbers over the entire lifetime of the
3248 scale
= (double)NANOSEC
/ tdelta
;
3251 if (cb
->cb_flags
& IOS_DEFAULT_M
) {
3252 calc_default_iostats(oldvs
, newvs
, calcvs
);
3253 print_iostat_default(calcvs
, cb
, scale
);
3255 if (cb
->cb_flags
& IOS_LATENCY_M
)
3256 print_iostat_latency(cb
, oldnv
, newnv
, scale
);
3257 if (cb
->cb_flags
& IOS_QUEUES_M
)
3258 print_iostat_queues(cb
, oldnv
, newnv
, scale
);
3259 if (cb
->cb_flags
& IOS_L_HISTO_M
) {
3261 print_iostat_histos(cb
, oldnv
, newnv
, scale
, name
);
3264 if (!(cb
->cb_flags
& IOS_L_HISTO_M
))
3271 if (!cb
->cb_verbose
)
3274 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_CHILDREN
,
3275 &newchild
, &children
) != 0)
3278 if (oldnv
&& nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_CHILDREN
,
3279 &oldchild
, &c
) != 0)
3282 for (c
= 0; c
< children
; c
++) {
3283 uint64_t ishole
= B_FALSE
, islog
= B_FALSE
;
3285 (void) nvlist_lookup_uint64(newchild
[c
], ZPOOL_CONFIG_IS_HOLE
,
3288 (void) nvlist_lookup_uint64(newchild
[c
], ZPOOL_CONFIG_IS_LOG
,
3291 if (ishole
|| islog
)
3294 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
3296 ret
+= print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
] : NULL
,
3297 newchild
[c
], cb
, depth
+ 2);
3302 * Log device section
3305 if (num_logs(newnv
) > 0) {
3306 if ((!(cb
->cb_flags
& IOS_L_HISTO_M
)) && !cb
->cb_scripted
&&
3307 !cb
->cb_vdev_names
) {
3308 print_iostat_dashes(cb
, 0, "logs");
3311 for (c
= 0; c
< children
; c
++) {
3312 uint64_t islog
= B_FALSE
;
3313 (void) nvlist_lookup_uint64(newchild
[c
],
3314 ZPOOL_CONFIG_IS_LOG
, &islog
);
3317 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
3319 ret
+= print_vdev_stats(zhp
, vname
, oldnv
?
3320 oldchild
[c
] : NULL
, newchild
[c
],
3329 * Include level 2 ARC devices in iostat output
3331 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_L2CACHE
,
3332 &newchild
, &children
) != 0)
3335 if (oldnv
&& nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_L2CACHE
,
3336 &oldchild
, &c
) != 0)
3340 if ((!(cb
->cb_flags
& IOS_L_HISTO_M
)) && !cb
->cb_scripted
&&
3341 !cb
->cb_vdev_names
) {
3342 print_iostat_dashes(cb
, 0, "cache");
3345 for (c
= 0; c
< children
; c
++) {
3346 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
3348 ret
+= print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
]
3349 : NULL
, newchild
[c
], cb
, depth
+ 2);
3358 refresh_iostat(zpool_handle_t
*zhp
, void *data
)
3360 iostat_cbdata_t
*cb
= data
;
3364 * If the pool has disappeared, remove it from the list and continue.
3366 if (zpool_refresh_stats(zhp
, &missing
) != 0)
3370 pool_list_remove(cb
->cb_list
, zhp
);
3376 * Callback to print out the iostats for the given pool.
3379 print_iostat(zpool_handle_t
*zhp
, void *data
)
3381 iostat_cbdata_t
*cb
= data
;
3382 nvlist_t
*oldconfig
, *newconfig
;
3383 nvlist_t
*oldnvroot
, *newnvroot
;
3386 newconfig
= zpool_get_config(zhp
, &oldconfig
);
3388 if (cb
->cb_iteration
== 1)
3391 verify(nvlist_lookup_nvlist(newconfig
, ZPOOL_CONFIG_VDEV_TREE
,
3394 if (oldconfig
== NULL
)
3397 verify(nvlist_lookup_nvlist(oldconfig
, ZPOOL_CONFIG_VDEV_TREE
,
3400 ret
= print_vdev_stats(zhp
, zpool_get_name(zhp
), oldnvroot
, newnvroot
,
3402 if ((ret
!= 0) && !(cb
->cb_flags
& IOS_L_HISTO_M
) && !cb
->cb_scripted
&&
3403 cb
->cb_verbose
&& !cb
->cb_vdev_names_count
)
3404 print_iostat_separator(cb
);
3416 if (isatty(STDOUT_FILENO
)) {
3417 error
= ioctl(STDOUT_FILENO
, TIOCGWINSZ
, &ws
);
3419 columns
= ws
.ws_col
;
3428 get_namewidth(zpool_handle_t
*zhp
, void *data
)
3430 iostat_cbdata_t
*cb
= data
;
3431 nvlist_t
*config
, *nvroot
;
3434 if ((config
= zpool_get_config(zhp
, NULL
)) != NULL
) {
3435 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
3437 unsigned int poolname_len
= strlen(zpool_get_name(zhp
));
3438 if (!cb
->cb_verbose
)
3439 cb
->cb_namewidth
= poolname_len
;
3441 cb
->cb_namewidth
= MAX(poolname_len
,
3442 max_width(zhp
, nvroot
, 0, cb
->cb_namewidth
,
3443 cb
->cb_name_flags
));
3446 * The width must be at least 10, but may be as large as the
3447 * column width - 42 so that we can still fit in one line.
3449 columns
= get_columns();
3451 if (cb
->cb_namewidth
< 10)
3452 cb
->cb_namewidth
= 10;
3453 if (cb
->cb_namewidth
> columns
- 42)
3454 cb
->cb_namewidth
= columns
- 42;
3460 * Parse the input string, get the 'interval' and 'count' value if there is one.
3463 get_interval_count(int *argcp
, char **argv
, float *iv
,
3467 unsigned long count
= 0;
3471 * Determine if the last argument is an integer or a pool name
3473 if (argc
> 0 && isnumber(argv
[argc
- 1])) {
3477 interval
= strtof(argv
[argc
- 1], &end
);
3479 if (*end
== '\0' && errno
== 0) {
3480 if (interval
== 0) {
3481 (void) fprintf(stderr
, gettext("interval "
3482 "cannot be zero\n"));
3486 * Ignore the last parameter
3491 * If this is not a valid number, just plow on. The
3492 * user will get a more informative error message later
3500 * If the last argument is also an integer, then we have both a count
3503 if (argc
> 0 && isnumber(argv
[argc
- 1])) {
3508 interval
= strtof(argv
[argc
- 1], &end
);
3510 if (*end
== '\0' && errno
== 0) {
3511 if (interval
== 0) {
3512 (void) fprintf(stderr
, gettext("interval "
3513 "cannot be zero\n"));
3518 * Ignore the last parameter
3532 get_timestamp_arg(char c
)
3535 timestamp_fmt
= UDATE
;
3537 timestamp_fmt
= DDATE
;
3543 * Return stat flags that are supported by all pools by both the module and
3544 * zpool iostat. "*data" should be initialized to all 0xFFs before running.
3545 * It will get ANDed down until only the flags that are supported on all pools
3549 get_stat_flags_cb(zpool_handle_t
*zhp
, void *data
)
3551 uint64_t *mask
= data
;
3552 nvlist_t
*config
, *nvroot
, *nvx
;
3557 * Lookup table for extended iostat flags to nvlist names.
3558 * Basically a list of all the nvpairs a flag requires.
3560 static const char *vsx_type_to_nvlist
[IOS_COUNT
][10] = {
3562 ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO
,
3563 ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO
,
3564 ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO
,
3565 ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO
,
3566 ZPOOL_CONFIG_VDEV_SYNC_R_LAT_HISTO
,
3567 ZPOOL_CONFIG_VDEV_SYNC_W_LAT_HISTO
,
3568 ZPOOL_CONFIG_VDEV_ASYNC_R_LAT_HISTO
,
3569 ZPOOL_CONFIG_VDEV_ASYNC_W_LAT_HISTO
,
3570 ZPOOL_CONFIG_VDEV_SCRUB_LAT_HISTO
,
3573 ZPOOL_CONFIG_VDEV_TOT_R_LAT_HISTO
,
3574 ZPOOL_CONFIG_VDEV_TOT_W_LAT_HISTO
,
3575 ZPOOL_CONFIG_VDEV_DISK_R_LAT_HISTO
,
3576 ZPOOL_CONFIG_VDEV_DISK_W_LAT_HISTO
,
3579 ZPOOL_CONFIG_VDEV_SYNC_R_ACTIVE_QUEUE
,
3580 ZPOOL_CONFIG_VDEV_SYNC_W_ACTIVE_QUEUE
,
3581 ZPOOL_CONFIG_VDEV_ASYNC_R_ACTIVE_QUEUE
,
3582 ZPOOL_CONFIG_VDEV_ASYNC_W_ACTIVE_QUEUE
,
3583 ZPOOL_CONFIG_VDEV_SCRUB_ACTIVE_QUEUE
,
3587 config
= zpool_get_config(zhp
, NULL
);
3588 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
3591 /* Default stats are always supported, but for completeness.. */
3592 if (nvlist_exists(nvroot
, ZPOOL_CONFIG_VDEV_STATS
))
3593 flags
|= IOS_DEFAULT_M
;
3595 /* Get our extended stats nvlist from the main list */
3596 if (nvlist_lookup_nvlist(nvroot
, ZPOOL_CONFIG_VDEV_STATS_EX
,
3599 * No extended stats; they're probably running an older
3600 * module. No big deal, we support that too.
3605 /* For each extended stat, make sure all its nvpairs are supported */
3606 for (j
= 0; j
< ARRAY_SIZE(vsx_type_to_nvlist
); j
++) {
3607 if (!vsx_type_to_nvlist
[j
][0])
3610 /* Start off by assuming the flag is supported, then check */
3611 flags
|= (1ULL << j
);
3612 for (i
= 0; vsx_type_to_nvlist
[j
][i
]; i
++) {
3613 if (!nvlist_exists(nvx
, vsx_type_to_nvlist
[j
][i
])) {
3614 /* flag isn't supported */
3615 flags
= flags
& ~(1ULL << j
);
3621 *mask
= *mask
& flags
;
3626 * Return a bitmask of stats that are supported on all pools by both the module
3630 get_stat_flags(zpool_list_t
*list
)
3635 * get_stat_flags_cb() will lop off bits from "mask" until only the
3636 * flags that are supported on all pools remain.
3638 pool_list_iter(list
, B_FALSE
, get_stat_flags_cb
, &mask
);
3643 * Return 1 if cb_data->cb_vdev_names[0] is this vdev's name, 0 otherwise.
3646 is_vdev_cb(zpool_handle_t
*zhp
, nvlist_t
*nv
, void *cb_data
)
3648 iostat_cbdata_t
*cb
= cb_data
;
3651 name
= zpool_vdev_name(g_zfs
, zhp
, nv
, cb
->cb_name_flags
);
3653 if (strcmp(name
, cb
->cb_vdev_names
[0]) == 0)
3654 return (1); /* match */
3660 * Returns 1 if cb_data->cb_vdev_names[0] is a vdev name, 0 otherwise.
3663 is_vdev(zpool_handle_t
*zhp
, void *cb_data
)
3665 return (for_each_vdev(zhp
, is_vdev_cb
, cb_data
));
3669 * Check if vdevs are in a pool
3671 * Return 1 if all argv[] strings are vdev names in pool "pool_name". Otherwise
3672 * return 0. If pool_name is NULL, then search all pools.
3675 are_vdevs_in_pool(int argc
, char **argv
, char *pool_name
,
3676 iostat_cbdata_t
*cb
)
3683 if ((argc
== 0) || !*argv
)
3689 /* Temporarily hijack cb_vdev_names for a second... */
3690 tmp_name
= cb
->cb_vdev_names
;
3692 /* Go though our list of prospective vdev names */
3693 for (i
= 0; i
< argc
; i
++) {
3694 cb
->cb_vdev_names
= argv
+ i
;
3696 /* Is this name a vdev in our pools? */
3697 ret
= for_each_pool(pool_count
, &pool_name
, B_TRUE
, NULL
,
3705 cb
->cb_vdev_names
= tmp_name
;
3711 is_pool_cb(zpool_handle_t
*zhp
, void *data
)
3714 if (strcmp(name
, zpool_get_name(zhp
)) == 0)
3721 * Do we have a pool named *name? If so, return 1, otherwise 0.
3726 return (for_each_pool(0, NULL
, B_TRUE
, NULL
, is_pool_cb
, name
));
3729 /* Are all our argv[] strings pool names? If so return 1, 0 otherwise. */
3731 are_all_pools(int argc
, char **argv
) {
3732 if ((argc
== 0) || !*argv
)
3736 if (!is_pool(argv
[argc
]))
3743 * Helper function to print out vdev/pool names we can't resolve. Used for an
3747 error_list_unresolved_vdevs(int argc
, char **argv
, char *pool_name
,
3748 iostat_cbdata_t
*cb
)
3753 for (i
= 0; i
< argc
; i
++) {
3757 str
= gettext("pool");
3758 else if (are_vdevs_in_pool(1, &name
, pool_name
, cb
))
3759 str
= gettext("vdev in this pool");
3760 else if (are_vdevs_in_pool(1, &name
, NULL
, cb
))
3761 str
= gettext("vdev in another pool");
3763 str
= gettext("unknown");
3765 fprintf(stderr
, "\t%s (%s)\n", name
, str
);
3770 * Same as get_interval_count(), but with additional checks to not misinterpret
3771 * guids as interval/count values. Assumes VDEV_NAME_GUID is set in
3775 get_interval_count_filter_guids(int *argc
, char **argv
, float *interval
,
3776 unsigned long *count
, iostat_cbdata_t
*cb
)
3778 char **tmpargv
= argv
;
3779 int argc_for_interval
= 0;
3781 /* Is the last arg an interval value? Or a guid? */
3782 if (*argc
>= 1 && !are_vdevs_in_pool(1, &argv
[*argc
- 1], NULL
, cb
)) {
3784 * The last arg is not a guid, so it's probably an
3787 argc_for_interval
++;
3790 !are_vdevs_in_pool(1, &argv
[*argc
- 2], NULL
, cb
)) {
3792 * The 2nd to last arg is not a guid, so it's probably
3793 * an interval value.
3795 argc_for_interval
++;
3799 /* Point to our list of possible intervals */
3800 tmpargv
= &argv
[*argc
- argc_for_interval
];
3802 *argc
= *argc
- argc_for_interval
;
3803 get_interval_count(&argc_for_interval
, tmpargv
,
3808 * Floating point sleep(). Allows you to pass in a floating point value for
3813 struct timespec req
;
3814 req
.tv_sec
= floor(sec
);
3815 req
.tv_nsec
= (sec
- (float)req
.tv_sec
) * NANOSEC
;
3816 nanosleep(&req
, NULL
);
3821 * zpool iostat [-ghHLpPvy] [[-lq]-w] [-n name] [-T d|u]
3822 * [[ pool ...]|[pool vdev ...]|[vdev ...]]
3823 * [interval [count]]
3825 * -g Display guid for individual vdev name.
3826 * -L Follow links when resolving vdev path name.
3827 * -P Display full path for vdev name.
3828 * -v Display statistics for individual vdevs
3830 * -p Display values in parsable (exact) format.
3831 * -H Scripted mode. Don't display headers, and separate properties
3833 * -l Display average latency
3834 * -q Display queue depths
3835 * -w Display histograms
3836 * -T Display a timestamp in date(1) or Unix format
3838 * This command can be tricky because we want to be able to deal with pool
3839 * creation/destruction as well as vdev configuration changes. The bulk of this
3840 * processing is handled by the pool_list_* routines in zpool_iter.c. We rely
3841 * on pool_list_update() to detect the addition of new pools. Configuration
3842 * changes are all handled within libzfs.
3845 zpool_do_iostat(int argc
, char **argv
)
3851 unsigned long count
= 0;
3853 boolean_t verbose
= B_FALSE
;
3854 boolean_t latency
= B_FALSE
, histo
= B_FALSE
;
3855 boolean_t queues
= B_FALSE
, parseable
= B_FALSE
, scripted
= B_FALSE
;
3856 boolean_t omit_since_boot
= B_FALSE
;
3857 boolean_t guid
= B_FALSE
;
3858 boolean_t follow_links
= B_FALSE
;
3859 boolean_t full_name
= B_FALSE
;
3860 iostat_cbdata_t cb
= { 0 };
3862 /* Used for printing error message */
3863 const char flag_to_arg
[] = {[IOS_LATENCY
] = 'l', [IOS_QUEUES
] = 'q',
3864 [IOS_L_HISTO
] = 'w'};
3866 uint64_t unsupported_flags
;
3869 while ((c
= getopt(argc
, argv
, "gLPT:vyhplqwH")) != -1) {
3875 follow_links
= B_TRUE
;
3881 get_timestamp_arg(*optarg
);
3902 omit_since_boot
= B_TRUE
;
3908 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3917 cb
.cb_literal
= parseable
;
3918 cb
.cb_scripted
= scripted
;
3921 cb
.cb_name_flags
|= VDEV_NAME_GUID
;
3923 cb
.cb_name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
3925 cb
.cb_name_flags
|= VDEV_NAME_PATH
;
3926 cb
.cb_iteration
= 0;
3927 cb
.cb_namewidth
= 0;
3928 cb
.cb_verbose
= verbose
;
3930 /* Get our interval and count values (if any) */
3932 get_interval_count_filter_guids(&argc
, argv
, &interval
,
3935 get_interval_count(&argc
, argv
, &interval
, &count
);
3939 /* No args, so just print the defaults. */
3940 } else if (are_all_pools(argc
, argv
)) {
3941 /* All the args are pool names */
3942 } else if (are_vdevs_in_pool(argc
, argv
, NULL
, &cb
)) {
3943 /* All the args are vdevs */
3944 cb
.cb_vdev_names
= argv
;
3945 cb
.cb_vdev_names_count
= argc
;
3946 argc
= 0; /* No pools to process */
3947 } else if (are_all_pools(1, argv
)) {
3948 /* The first arg is a pool name */
3949 if (are_vdevs_in_pool(argc
- 1, argv
+ 1, argv
[0], &cb
)) {
3950 /* ...and the rest are vdev names */
3951 cb
.cb_vdev_names
= argv
+ 1;
3952 cb
.cb_vdev_names_count
= argc
- 1;
3953 argc
= 1; /* One pool to process */
3955 fprintf(stderr
, gettext("Expected either a list of "));
3956 fprintf(stderr
, gettext("pools, or list of vdevs in"));
3957 fprintf(stderr
, " \"%s\", ", argv
[0]);
3958 fprintf(stderr
, gettext("but got:\n"));
3959 error_list_unresolved_vdevs(argc
- 1, argv
+ 1,
3961 fprintf(stderr
, "\n");
3967 * The args don't make sense. The first arg isn't a pool name,
3968 * nor are all the args vdevs.
3970 fprintf(stderr
, gettext("Unable to parse pools/vdevs list.\n"));
3971 fprintf(stderr
, "\n");
3975 if (cb
.cb_vdev_names_count
!= 0) {
3977 * If user specified vdevs, it implies verbose.
3979 cb
.cb_verbose
= B_TRUE
;
3983 * Construct the list of all interesting pools.
3986 if ((list
= pool_list_get(argc
, argv
, NULL
, &ret
)) == NULL
)
3989 if (pool_list_count(list
) == 0 && argc
!= 0) {
3990 pool_list_free(list
);
3994 if (pool_list_count(list
) == 0 && interval
== 0) {
3995 pool_list_free(list
);
3996 (void) fprintf(stderr
, gettext("no pools available\n"));
4000 if (histo
&& (queues
|| latency
)) {
4001 pool_list_free(list
);
4002 (void) fprintf(stderr
,
4003 gettext("-w isn't allowed with [-q|-l]\n"));
4009 * Enter the main iostat loop.
4015 * Histograms tables look out of place when you try to display
4016 * them with the other stats, so make a rule that you can only
4017 * print histograms by themselves.
4019 cb
.cb_flags
= IOS_L_HISTO_M
;
4021 cb
.cb_flags
= IOS_DEFAULT_M
;
4023 cb
.cb_flags
|= IOS_LATENCY_M
;
4025 cb
.cb_flags
|= IOS_QUEUES_M
;
4029 * See if the module supports all the stats we want to display.
4031 unsupported_flags
= cb
.cb_flags
& ~get_stat_flags(list
);
4032 if (unsupported_flags
) {
4036 gettext("The loaded zfs module doesn't support:"));
4038 /* for each bit set in unsupported_flags */
4039 for (f
= unsupported_flags
; f
; f
&= ~(1ULL << idx
)) {
4040 idx
= lowbit64(f
) - 1;
4041 fprintf(stderr
, " -%c", flag_to_arg
[idx
]);
4044 fprintf(stderr
, ". Try running a newer module.\n"),
4045 pool_list_free(list
);
4052 if ((npools
= pool_list_count(list
)) == 0)
4053 (void) fprintf(stderr
, gettext("no pools available\n"));
4056 * If this is the first iteration and -y was supplied
4057 * we skip any printing.
4059 boolean_t skip
= (omit_since_boot
&&
4060 cb
.cb_iteration
== 0);
4063 * Refresh all statistics. This is done as an
4064 * explicit step before calculating the maximum name
4065 * width, so that any * configuration changes are
4066 * properly accounted for.
4068 (void) pool_list_iter(list
, B_FALSE
, refresh_iostat
,
4072 * Iterate over all pools to determine the maximum width
4073 * for the pool / device name column across all pools.
4075 cb
.cb_namewidth
= 0;
4076 (void) pool_list_iter(list
, B_FALSE
, get_namewidth
,
4079 if (timestamp_fmt
!= NODATE
)
4080 print_timestamp(timestamp_fmt
);
4083 * If it's the first time and we're not skipping it,
4084 * or either skip or verbose mode, print the header.
4086 * The histogram code explicitly prints its header on
4087 * every vdev, so skip this for histograms.
4089 if (((++cb
.cb_iteration
== 1 && !skip
) ||
4090 (skip
!= verbose
)) &&
4091 (!(cb
.cb_flags
& IOS_L_HISTO_M
)) &&
4093 print_iostat_header(&cb
);
4096 (void) fsleep(interval
);
4100 pool_list_iter(list
, B_FALSE
, print_iostat
, &cb
);
4103 * If there's more than one pool, and we're not in
4104 * verbose mode (which prints a separator for us),
4105 * then print a separator.
4107 * In addition, if we're printing specific vdevs then
4108 * we also want an ending separator.
4110 if (((npools
> 1 && !verbose
&&
4111 !(cb
.cb_flags
& IOS_L_HISTO_M
)) ||
4112 (!(cb
.cb_flags
& IOS_L_HISTO_M
) &&
4113 cb
.cb_vdev_names_count
)) &&
4115 print_iostat_separator(&cb
);
4120 * Flush the output so that redirection to a file isn't buffered
4123 (void) fflush(stdout
);
4128 if (count
!= 0 && --count
== 0)
4131 (void) fsleep(interval
);
4134 pool_list_free(list
);
4139 typedef struct list_cbdata
{
4140 boolean_t cb_verbose
;
4143 boolean_t cb_scripted
;
4144 zprop_list_t
*cb_proplist
;
4145 boolean_t cb_literal
;
4149 * Given a list of columns to display, output appropriate headers for each one.
4152 print_header(list_cbdata_t
*cb
)
4154 zprop_list_t
*pl
= cb
->cb_proplist
;
4155 char headerbuf
[ZPOOL_MAXPROPLEN
];
4157 boolean_t first
= B_TRUE
;
4158 boolean_t right_justify
;
4161 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
4162 width
= pl
->pl_width
;
4163 if (first
&& cb
->cb_verbose
) {
4165 * Reset the width to accommodate the verbose listing
4168 width
= cb
->cb_namewidth
;
4176 right_justify
= B_FALSE
;
4177 if (pl
->pl_prop
!= ZPROP_INVAL
) {
4178 header
= zpool_prop_column_name(pl
->pl_prop
);
4179 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
4183 for (i
= 0; pl
->pl_user_prop
[i
] != '\0'; i
++)
4184 headerbuf
[i
] = toupper(pl
->pl_user_prop
[i
]);
4185 headerbuf
[i
] = '\0';
4189 if (pl
->pl_next
== NULL
&& !right_justify
)
4190 (void) printf("%s", header
);
4191 else if (right_justify
)
4192 (void) printf("%*s", (int)width
, header
);
4194 (void) printf("%-*s", (int)width
, header
);
4197 (void) printf("\n");
4201 * Given a pool and a list of properties, print out all the properties according
4202 * to the described layout.
4205 print_pool(zpool_handle_t
*zhp
, list_cbdata_t
*cb
)
4207 zprop_list_t
*pl
= cb
->cb_proplist
;
4208 boolean_t first
= B_TRUE
;
4209 char property
[ZPOOL_MAXPROPLEN
];
4211 boolean_t right_justify
;
4214 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
4216 width
= pl
->pl_width
;
4217 if (first
&& cb
->cb_verbose
) {
4219 * Reset the width to accommodate the verbose listing
4222 width
= cb
->cb_namewidth
;
4226 if (cb
->cb_scripted
)
4227 (void) printf("\t");
4234 right_justify
= B_FALSE
;
4235 if (pl
->pl_prop
!= ZPROP_INVAL
) {
4236 if (zpool_get_prop(zhp
, pl
->pl_prop
, property
,
4237 sizeof (property
), NULL
, cb
->cb_literal
) != 0)
4242 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
4243 } else if ((zpool_prop_feature(pl
->pl_user_prop
) ||
4244 zpool_prop_unsupported(pl
->pl_user_prop
)) &&
4245 zpool_prop_get_feature(zhp
, pl
->pl_user_prop
, property
,
4246 sizeof (property
)) == 0) {
4254 * If this is being called in scripted mode, or if this is the
4255 * last column and it is left-justified, don't include a width
4258 if (cb
->cb_scripted
|| (pl
->pl_next
== NULL
&& !right_justify
))
4259 (void) printf("%s", propstr
);
4260 else if (right_justify
)
4261 (void) printf("%*s", (int)width
, propstr
);
4263 (void) printf("%-*s", (int)width
, propstr
);
4266 (void) printf("\n");
4270 print_one_column(zpool_prop_t prop
, uint64_t value
, boolean_t scripted
,
4275 size_t width
= zprop_width(prop
, &fixed
, ZFS_TYPE_POOL
);
4278 case ZPOOL_PROP_EXPANDSZ
:
4280 (void) strlcpy(propval
, "-", sizeof (propval
));
4282 zfs_nicenum(value
, propval
, sizeof (propval
));
4284 case ZPOOL_PROP_FRAGMENTATION
:
4285 if (value
== ZFS_FRAG_INVALID
) {
4286 (void) strlcpy(propval
, "-", sizeof (propval
));
4288 (void) snprintf(propval
, sizeof (propval
), "%llu%%",
4289 (unsigned long long)value
);
4292 case ZPOOL_PROP_CAPACITY
:
4293 (void) snprintf(propval
, sizeof (propval
), "%llu%%",
4294 (unsigned long long)value
);
4297 zfs_nicenum(value
, propval
, sizeof (propval
));
4301 (void) strlcpy(propval
, "-", sizeof (propval
));
4304 (void) printf("\t%s", propval
);
4306 (void) printf(" %*s", (int)width
, propval
);
4310 print_list_stats(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
,
4311 list_cbdata_t
*cb
, int depth
)
4317 boolean_t scripted
= cb
->cb_scripted
;
4318 uint64_t islog
= B_FALSE
;
4319 boolean_t haslog
= B_FALSE
;
4320 char *dashes
= "%-*s - - - - - -\n";
4322 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
4323 (uint64_t **)&vs
, &c
) == 0);
4326 boolean_t toplevel
= (vs
->vs_space
!= 0);
4330 (void) printf("\t%s", name
);
4331 else if (strlen(name
) + depth
> cb
->cb_namewidth
)
4332 (void) printf("%*s%s", depth
, "", name
);
4334 (void) printf("%*s%s%*s", depth
, "", name
,
4335 (int)(cb
->cb_namewidth
- strlen(name
) - depth
), "");
4338 * Print the properties for the individual vdevs. Some
4339 * properties are only applicable to toplevel vdevs. The
4340 * 'toplevel' boolean value is passed to the print_one_column()
4341 * to indicate that the value is valid.
4343 print_one_column(ZPOOL_PROP_SIZE
, vs
->vs_space
, scripted
,
4345 print_one_column(ZPOOL_PROP_ALLOCATED
, vs
->vs_alloc
, scripted
,
4347 print_one_column(ZPOOL_PROP_FREE
, vs
->vs_space
- vs
->vs_alloc
,
4348 scripted
, toplevel
);
4349 print_one_column(ZPOOL_PROP_EXPANDSZ
, vs
->vs_esize
, scripted
,
4351 print_one_column(ZPOOL_PROP_FRAGMENTATION
,
4352 vs
->vs_fragmentation
, scripted
,
4353 (vs
->vs_fragmentation
!= ZFS_FRAG_INVALID
&& toplevel
));
4354 cap
= (vs
->vs_space
== 0) ? 0 :
4355 (vs
->vs_alloc
* 100 / vs
->vs_space
);
4356 print_one_column(ZPOOL_PROP_CAPACITY
, cap
, scripted
, toplevel
);
4357 (void) printf("\n");
4360 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
4361 &child
, &children
) != 0)
4364 for (c
= 0; c
< children
; c
++) {
4365 uint64_t ishole
= B_FALSE
;
4367 if (nvlist_lookup_uint64(child
[c
],
4368 ZPOOL_CONFIG_IS_HOLE
, &ishole
) == 0 && ishole
)
4371 if (nvlist_lookup_uint64(child
[c
],
4372 ZPOOL_CONFIG_IS_LOG
, &islog
) == 0 && islog
) {
4377 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
4379 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
4383 if (haslog
== B_TRUE
) {
4384 /* LINTED E_SEC_PRINTF_VAR_FMT */
4385 (void) printf(dashes
, cb
->cb_namewidth
, "log");
4386 for (c
= 0; c
< children
; c
++) {
4387 if (nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
4388 &islog
) != 0 || !islog
)
4390 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
4392 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
4397 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
4398 &child
, &children
) == 0 && children
> 0) {
4399 /* LINTED E_SEC_PRINTF_VAR_FMT */
4400 (void) printf(dashes
, cb
->cb_namewidth
, "cache");
4401 for (c
= 0; c
< children
; c
++) {
4402 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
4404 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
4409 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
, &child
,
4410 &children
) == 0 && children
> 0) {
4411 /* LINTED E_SEC_PRINTF_VAR_FMT */
4412 (void) printf(dashes
, cb
->cb_namewidth
, "spare");
4413 for (c
= 0; c
< children
; c
++) {
4414 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
4416 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
4424 * Generic callback function to list a pool.
4427 list_callback(zpool_handle_t
*zhp
, void *data
)
4429 list_cbdata_t
*cbp
= data
;
4433 config
= zpool_get_config(zhp
, NULL
);
4435 print_pool(zhp
, cbp
);
4436 if (!cbp
->cb_verbose
)
4439 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
4441 print_list_stats(zhp
, NULL
, nvroot
, cbp
, 0);
4447 * zpool list [-gHLpP] [-o prop[,prop]*] [-T d|u] [pool] ... [interval [count]]
4449 * -g Display guid for individual vdev name.
4450 * -H Scripted mode. Don't display headers, and separate properties
4452 * -L Follow links when resolving vdev path name.
4453 * -o List of properties to display. Defaults to
4454 * "name,size,allocated,free,expandsize,fragmentation,capacity,"
4455 * "dedupratio,health,altroot"
4456 * -p Display values in parsable (exact) format.
4457 * -P Display full path for vdev name.
4458 * -T Display a timestamp in date(1) or Unix format
4460 * List all pools in the system, whether or not they're healthy. Output space
4461 * statistics for each one, as well as health status summary.
4464 zpool_do_list(int argc
, char **argv
)
4468 list_cbdata_t cb
= { 0 };
4469 static char default_props
[] =
4470 "name,size,allocated,free,expandsize,fragmentation,capacity,"
4471 "dedupratio,health,altroot";
4472 char *props
= default_props
;
4474 unsigned long count
= 0;
4476 boolean_t first
= B_TRUE
;
4479 while ((c
= getopt(argc
, argv
, ":gHLo:pPT:v")) != -1) {
4482 cb
.cb_name_flags
|= VDEV_NAME_GUID
;
4485 cb
.cb_scripted
= B_TRUE
;
4488 cb
.cb_name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
4494 cb
.cb_name_flags
|= VDEV_NAME_PATH
;
4497 cb
.cb_literal
= B_TRUE
;
4500 get_timestamp_arg(*optarg
);
4503 cb
.cb_verbose
= B_TRUE
;
4506 (void) fprintf(stderr
, gettext("missing argument for "
4507 "'%c' option\n"), optopt
);
4511 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4520 get_interval_count(&argc
, argv
, &interval
, &count
);
4522 if (zprop_get_list(g_zfs
, props
, &cb
.cb_proplist
, ZFS_TYPE_POOL
) != 0)
4526 if ((list
= pool_list_get(argc
, argv
, &cb
.cb_proplist
,
4530 if (pool_list_count(list
) == 0)
4533 if (timestamp_fmt
!= NODATE
)
4534 print_timestamp(timestamp_fmt
);
4536 if (!cb
.cb_scripted
&& (first
|| cb
.cb_verbose
)) {
4540 ret
= pool_list_iter(list
, B_TRUE
, list_callback
, &cb
);
4545 if (count
!= 0 && --count
== 0)
4548 pool_list_free(list
);
4549 (void) fsleep(interval
);
4552 if (argc
== 0 && !cb
.cb_scripted
&& pool_list_count(list
) == 0) {
4553 (void) printf(gettext("no pools available\n"));
4557 pool_list_free(list
);
4558 zprop_free_list(cb
.cb_proplist
);
4563 zpool_do_attach_or_replace(int argc
, char **argv
, int replacing
)
4565 boolean_t force
= B_FALSE
;
4568 char *poolname
, *old_disk
, *new_disk
;
4569 zpool_handle_t
*zhp
;
4570 nvlist_t
*props
= NULL
;
4575 while ((c
= getopt(argc
, argv
, "fo:")) != -1) {
4581 if ((propval
= strchr(optarg
, '=')) == NULL
) {
4582 (void) fprintf(stderr
, gettext("missing "
4583 "'=' for -o option\n"));
4589 if ((strcmp(optarg
, ZPOOL_CONFIG_ASHIFT
) != 0) ||
4590 (add_prop_list(optarg
, propval
, &props
, B_TRUE
)))
4594 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4603 /* get pool name and check number of arguments */
4605 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
4612 (void) fprintf(stderr
,
4613 gettext("missing <device> specification\n"));
4621 (void) fprintf(stderr
,
4622 gettext("missing <new_device> specification\n"));
4625 new_disk
= old_disk
;
4635 (void) fprintf(stderr
, gettext("too many arguments\n"));
4639 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
4642 if (zpool_get_config(zhp
, NULL
) == NULL
) {
4643 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
4649 nvroot
= make_root_vdev(zhp
, props
, force
, B_FALSE
, replacing
, B_FALSE
,
4651 if (nvroot
== NULL
) {
4656 ret
= zpool_vdev_attach(zhp
, old_disk
, new_disk
, nvroot
, replacing
);
4658 nvlist_free(nvroot
);
4665 * zpool replace [-f] <pool> <device> <new_device>
4667 * -f Force attach, even if <new_device> appears to be in use.
4669 * Replace <device> with <new_device>.
4673 zpool_do_replace(int argc
, char **argv
)
4675 return (zpool_do_attach_or_replace(argc
, argv
, B_TRUE
));
4679 * zpool attach [-f] [-o property=value] <pool> <device> <new_device>
4681 * -f Force attach, even if <new_device> appears to be in use.
4682 * -o Set property=value.
4684 * Attach <new_device> to the mirror containing <device>. If <device> is not
4685 * part of a mirror, then <device> will be transformed into a mirror of
4686 * <device> and <new_device>. In either case, <new_device> will begin life
4687 * with a DTL of [0, now], and will immediately begin to resilver itself.
4690 zpool_do_attach(int argc
, char **argv
)
4692 return (zpool_do_attach_or_replace(argc
, argv
, B_FALSE
));
4696 * zpool detach [-f] <pool> <device>
4698 * -f Force detach of <device>, even if DTLs argue against it
4699 * (not supported yet)
4701 * Detach a device from a mirror. The operation will be refused if <device>
4702 * is the last device in the mirror, or if the DTLs indicate that this device
4703 * has the only valid copy of some data.
4707 zpool_do_detach(int argc
, char **argv
)
4710 char *poolname
, *path
;
4711 zpool_handle_t
*zhp
;
4715 while ((c
= getopt(argc
, argv
, "f")) != -1) {
4719 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4728 /* get pool name and check number of arguments */
4730 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
4735 (void) fprintf(stderr
,
4736 gettext("missing <device> specification\n"));
4743 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
4746 ret
= zpool_vdev_detach(zhp
, path
);
4754 * zpool split [-gLnP] [-o prop=val] ...
4756 * [-R altroot] <pool> <newpool> [<device> ...]
4758 * -g Display guid for individual vdev name.
4759 * -L Follow links when resolving vdev path name.
4760 * -n Do not split the pool, but display the resulting layout if
4761 * it were to be split.
4762 * -o Set property=value, or set mount options.
4763 * -P Display full path for vdev name.
4764 * -R Mount the split-off pool under an alternate root.
4766 * Splits the named pool and gives it the new pool name. Devices to be split
4767 * off may be listed, provided that no more than one device is specified
4768 * per top-level vdev mirror. The newly split pool is left in an exported
4769 * state unless -R is specified.
4771 * Restrictions: the top-level of the pool pool must only be made up of
4772 * mirrors; all devices in the pool must be healthy; no device may be
4773 * undergoing a resilvering operation.
4776 zpool_do_split(int argc
, char **argv
)
4778 char *srcpool
, *newpool
, *propval
;
4779 char *mntopts
= NULL
;
4782 zpool_handle_t
*zhp
;
4783 nvlist_t
*config
, *props
= NULL
;
4785 flags
.dryrun
= B_FALSE
;
4786 flags
.import
= B_FALSE
;
4787 flags
.name_flags
= 0;
4790 while ((c
= getopt(argc
, argv
, ":gLR:no:P")) != -1) {
4793 flags
.name_flags
|= VDEV_NAME_GUID
;
4796 flags
.name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
4799 flags
.import
= B_TRUE
;
4801 zpool_prop_to_name(ZPOOL_PROP_ALTROOT
), optarg
,
4802 &props
, B_TRUE
) != 0) {
4808 flags
.dryrun
= B_TRUE
;
4811 if ((propval
= strchr(optarg
, '=')) != NULL
) {
4814 if (add_prop_list(optarg
, propval
,
4815 &props
, B_TRUE
) != 0) {
4824 flags
.name_flags
|= VDEV_NAME_PATH
;
4827 (void) fprintf(stderr
, gettext("missing argument for "
4828 "'%c' option\n"), optopt
);
4832 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4839 if (!flags
.import
&& mntopts
!= NULL
) {
4840 (void) fprintf(stderr
, gettext("setting mntopts is only "
4841 "valid when importing the pool\n"));
4849 (void) fprintf(stderr
, gettext("Missing pool name\n"));
4853 (void) fprintf(stderr
, gettext("Missing new pool name\n"));
4863 if ((zhp
= zpool_open(g_zfs
, srcpool
)) == NULL
)
4866 config
= split_mirror_vdev(zhp
, newpool
, props
, flags
, argc
, argv
);
4867 if (config
== NULL
) {
4871 (void) printf(gettext("would create '%s' with the "
4872 "following layout:\n\n"), newpool
);
4873 print_vdev_tree(NULL
, newpool
, config
, 0, B_FALSE
,
4876 nvlist_free(config
);
4881 if (ret
!= 0 || flags
.dryrun
|| !flags
.import
)
4885 * The split was successful. Now we need to open the new
4886 * pool and import it.
4888 if ((zhp
= zpool_open_canfail(g_zfs
, newpool
)) == NULL
)
4890 if (zpool_get_state(zhp
) != POOL_STATE_UNAVAIL
&&
4891 zpool_enable_datasets(zhp
, mntopts
, 0) != 0) {
4893 (void) fprintf(stderr
, gettext("Split was successful, but "
4894 "the datasets could not all be mounted\n"));
4895 (void) fprintf(stderr
, gettext("Try doing '%s' with a "
4896 "different altroot\n"), "zpool import");
4906 * zpool online <pool> <device> ...
4909 zpool_do_online(int argc
, char **argv
)
4913 zpool_handle_t
*zhp
;
4915 vdev_state_t newstate
;
4919 while ((c
= getopt(argc
, argv
, "et")) != -1) {
4922 flags
|= ZFS_ONLINE_EXPAND
;
4926 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4935 /* get pool name and check number of arguments */
4937 (void) fprintf(stderr
, gettext("missing pool name\n"));
4941 (void) fprintf(stderr
, gettext("missing device name\n"));
4947 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
4950 for (i
= 1; i
< argc
; i
++) {
4951 if (zpool_vdev_online(zhp
, argv
[i
], flags
, &newstate
) == 0) {
4952 if (newstate
!= VDEV_STATE_HEALTHY
) {
4953 (void) printf(gettext("warning: device '%s' "
4954 "onlined, but remains in faulted state\n"),
4956 if (newstate
== VDEV_STATE_FAULTED
)
4957 (void) printf(gettext("use 'zpool "
4958 "clear' to restore a faulted "
4961 (void) printf(gettext("use 'zpool "
4962 "replace' to replace devices "
4963 "that are no longer present\n"));
4976 * zpool offline [-ft] <pool> <device> ...
4978 * -f Force the device into the offline state, even if doing
4979 * so would appear to compromise pool availability.
4980 * (not supported yet)
4982 * -t Only take the device off-line temporarily. The offline
4983 * state will not be persistent across reboots.
4987 zpool_do_offline(int argc
, char **argv
)
4991 zpool_handle_t
*zhp
;
4993 boolean_t istmp
= B_FALSE
;
4996 while ((c
= getopt(argc
, argv
, "ft")) != -1) {
5003 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5012 /* get pool name and check number of arguments */
5014 (void) fprintf(stderr
, gettext("missing pool name\n"));
5018 (void) fprintf(stderr
, gettext("missing device name\n"));
5024 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
5027 for (i
= 1; i
< argc
; i
++) {
5028 if (zpool_vdev_offline(zhp
, argv
[i
], istmp
) != 0)
5038 * zpool clear <pool> [device]
5040 * Clear all errors associated with a pool or a particular device.
5043 zpool_do_clear(int argc
, char **argv
)
5047 boolean_t dryrun
= B_FALSE
;
5048 boolean_t do_rewind
= B_FALSE
;
5049 boolean_t xtreme_rewind
= B_FALSE
;
5050 uint32_t rewind_policy
= ZPOOL_NO_REWIND
;
5051 nvlist_t
*policy
= NULL
;
5052 zpool_handle_t
*zhp
;
5053 char *pool
, *device
;
5056 while ((c
= getopt(argc
, argv
, "FnX")) != -1) {
5065 xtreme_rewind
= B_TRUE
;
5068 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5078 (void) fprintf(stderr
, gettext("missing pool name\n"));
5083 (void) fprintf(stderr
, gettext("too many arguments\n"));
5087 if ((dryrun
|| xtreme_rewind
) && !do_rewind
) {
5088 (void) fprintf(stderr
,
5089 gettext("-n or -X only meaningful with -F\n"));
5093 rewind_policy
= ZPOOL_TRY_REWIND
;
5095 rewind_policy
= ZPOOL_DO_REWIND
;
5097 rewind_policy
|= ZPOOL_EXTREME_REWIND
;
5099 /* In future, further rewind policy choices can be passed along here */
5100 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME
, 0) != 0 ||
5101 nvlist_add_uint32(policy
, ZPOOL_REWIND_REQUEST
, rewind_policy
) != 0)
5105 device
= argc
== 2 ? argv
[1] : NULL
;
5107 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
) {
5108 nvlist_free(policy
);
5112 if (zpool_clear(zhp
, device
, policy
) != 0)
5117 nvlist_free(policy
);
5123 * zpool reguid <pool>
5126 zpool_do_reguid(int argc
, char **argv
)
5130 zpool_handle_t
*zhp
;
5134 while ((c
= getopt(argc
, argv
, "")) != -1) {
5137 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5146 /* get pool name and check number of arguments */
5148 (void) fprintf(stderr
, gettext("missing pool name\n"));
5153 (void) fprintf(stderr
, gettext("too many arguments\n"));
5158 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
5161 ret
= zpool_reguid(zhp
);
5169 * zpool reopen <pool>
5171 * Reopen the pool so that the kernel can update the sizes of all vdevs.
5174 zpool_do_reopen(int argc
, char **argv
)
5178 zpool_handle_t
*zhp
;
5182 while ((c
= getopt(argc
, argv
, "")) != -1) {
5185 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5195 (void) fprintf(stderr
, gettext("missing pool name\n"));
5200 (void) fprintf(stderr
, gettext("too many arguments\n"));
5205 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
)
5208 ret
= zpool_reopen(zhp
);
5213 typedef struct scrub_cbdata
{
5220 scrub_callback(zpool_handle_t
*zhp
, void *data
)
5222 scrub_cbdata_t
*cb
= data
;
5226 * Ignore faulted pools.
5228 if (zpool_get_state(zhp
) == POOL_STATE_UNAVAIL
) {
5229 (void) fprintf(stderr
, gettext("cannot scrub '%s': pool is "
5230 "currently unavailable\n"), zpool_get_name(zhp
));
5234 err
= zpool_scan(zhp
, cb
->cb_type
);
5240 * zpool scrub [-s] <pool> ...
5242 * -s Stop. Stops any in-progress scrub.
5245 zpool_do_scrub(int argc
, char **argv
)
5250 cb
.cb_type
= POOL_SCAN_SCRUB
;
5253 while ((c
= getopt(argc
, argv
, "s")) != -1) {
5256 cb
.cb_type
= POOL_SCAN_NONE
;
5259 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5271 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
5275 return (for_each_pool(argc
, argv
, B_TRUE
, NULL
, scrub_callback
, &cb
));
5278 typedef struct status_cbdata
{
5281 boolean_t cb_allpools
;
5282 boolean_t cb_verbose
;
5283 boolean_t cb_explain
;
5285 boolean_t cb_dedup_stats
;
5289 * Print out detailed scrub status.
5292 print_scan_status(pool_scan_stat_t
*ps
)
5295 uint64_t elapsed
, mins_left
, hours_left
;
5296 uint64_t pass_exam
, examined
, total
;
5298 double fraction_done
;
5299 char processed_buf
[7], examined_buf
[7], total_buf
[7], rate_buf
[7];
5301 (void) printf(gettext(" scan: "));
5303 /* If there's never been a scan, there's not much to say. */
5304 if (ps
== NULL
|| ps
->pss_func
== POOL_SCAN_NONE
||
5305 ps
->pss_func
>= POOL_SCAN_FUNCS
) {
5306 (void) printf(gettext("none requested\n"));
5310 start
= ps
->pss_start_time
;
5311 end
= ps
->pss_end_time
;
5312 zfs_nicenum(ps
->pss_processed
, processed_buf
, sizeof (processed_buf
));
5314 assert(ps
->pss_func
== POOL_SCAN_SCRUB
||
5315 ps
->pss_func
== POOL_SCAN_RESILVER
);
5317 * Scan is finished or canceled.
5319 if (ps
->pss_state
== DSS_FINISHED
) {
5320 uint64_t minutes_taken
= (end
- start
) / 60;
5323 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
5324 fmt
= gettext("scrub repaired %s in %lluh%um with "
5325 "%llu errors on %s");
5326 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
5327 fmt
= gettext("resilvered %s in %lluh%um with "
5328 "%llu errors on %s");
5331 (void) printf(fmt
, processed_buf
,
5332 (u_longlong_t
)(minutes_taken
/ 60),
5333 (uint_t
)(minutes_taken
% 60),
5334 (u_longlong_t
)ps
->pss_errors
,
5335 ctime((time_t *)&end
));
5337 } else if (ps
->pss_state
== DSS_CANCELED
) {
5338 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
5339 (void) printf(gettext("scrub canceled on %s"),
5341 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
5342 (void) printf(gettext("resilver canceled on %s"),
5348 assert(ps
->pss_state
== DSS_SCANNING
);
5351 * Scan is in progress.
5353 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
5354 (void) printf(gettext("scrub in progress since %s"),
5356 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
5357 (void) printf(gettext("resilver in progress since %s"),
5361 examined
= ps
->pss_examined
? ps
->pss_examined
: 1;
5362 total
= ps
->pss_to_examine
;
5363 fraction_done
= (double)examined
/ total
;
5365 /* elapsed time for this pass */
5366 elapsed
= time(NULL
) - ps
->pss_pass_start
;
5367 elapsed
= elapsed
? elapsed
: 1;
5368 pass_exam
= ps
->pss_pass_exam
? ps
->pss_pass_exam
: 1;
5369 rate
= pass_exam
/ elapsed
;
5370 rate
= rate
? rate
: 1;
5371 mins_left
= ((total
- examined
) / rate
) / 60;
5372 hours_left
= mins_left
/ 60;
5374 zfs_nicenum(examined
, examined_buf
, sizeof (examined_buf
));
5375 zfs_nicenum(total
, total_buf
, sizeof (total_buf
));
5376 zfs_nicenum(rate
, rate_buf
, sizeof (rate_buf
));
5379 * do not print estimated time if hours_left is more than 30 days
5381 (void) printf(gettext("\t%s scanned out of %s at %s/s"),
5382 examined_buf
, total_buf
, rate_buf
);
5383 if (hours_left
< (30 * 24)) {
5384 (void) printf(gettext(", %lluh%um to go\n"),
5385 (u_longlong_t
)hours_left
, (uint_t
)(mins_left
% 60));
5387 (void) printf(gettext(
5388 ", (scan is slow, no estimated time)\n"));
5391 if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
5392 (void) printf(gettext("\t%s resilvered, %.2f%% done\n"),
5393 processed_buf
, 100 * fraction_done
);
5394 } else if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
5395 (void) printf(gettext("\t%s repaired, %.2f%% done\n"),
5396 processed_buf
, 100 * fraction_done
);
5401 print_error_log(zpool_handle_t
*zhp
)
5403 nvlist_t
*nverrlist
= NULL
;
5406 size_t len
= MAXPATHLEN
* 2;
5408 if (zpool_get_errlog(zhp
, &nverrlist
) != 0) {
5409 (void) printf("errors: List of errors unavailable "
5410 "(insufficient privileges)\n");
5414 (void) printf("errors: Permanent errors have been "
5415 "detected in the following files:\n\n");
5417 pathname
= safe_malloc(len
);
5419 while ((elem
= nvlist_next_nvpair(nverrlist
, elem
)) != NULL
) {
5421 uint64_t dsobj
, obj
;
5423 verify(nvpair_value_nvlist(elem
, &nv
) == 0);
5424 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_DATASET
,
5426 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_OBJECT
,
5428 zpool_obj_to_path(zhp
, dsobj
, obj
, pathname
, len
);
5429 (void) printf("%7s %s\n", "", pathname
);
5432 nvlist_free(nverrlist
);
5436 print_spares(zpool_handle_t
*zhp
, nvlist_t
**spares
, uint_t nspares
,
5437 int namewidth
, int name_flags
)
5445 (void) printf(gettext("\tspares\n"));
5447 for (i
= 0; i
< nspares
; i
++) {
5448 name
= zpool_vdev_name(g_zfs
, zhp
, spares
[i
], name_flags
);
5449 print_status_config(zhp
, name
, spares
[i
],
5450 namewidth
, 2, B_TRUE
, name_flags
);
5456 print_l2cache(zpool_handle_t
*zhp
, nvlist_t
**l2cache
, uint_t nl2cache
,
5457 int namewidth
, int name_flags
)
5465 (void) printf(gettext("\tcache\n"));
5467 for (i
= 0; i
< nl2cache
; i
++) {
5468 name
= zpool_vdev_name(g_zfs
, zhp
, l2cache
[i
], name_flags
);
5469 print_status_config(zhp
, name
, l2cache
[i
],
5470 namewidth
, 2, B_FALSE
, name_flags
);
5476 print_dedup_stats(nvlist_t
*config
)
5478 ddt_histogram_t
*ddh
;
5484 * If the pool was faulted then we may not have been able to
5485 * obtain the config. Otherwise, if we have anything in the dedup
5486 * table continue processing the stats.
5488 if (nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_OBJ_STATS
,
5489 (uint64_t **)&ddo
, &c
) != 0)
5492 (void) printf("\n");
5493 (void) printf(gettext(" dedup: "));
5494 if (ddo
->ddo_count
== 0) {
5495 (void) printf(gettext("no DDT entries\n"));
5499 (void) printf("DDT entries %llu, size %llu on disk, %llu in core\n",
5500 (u_longlong_t
)ddo
->ddo_count
,
5501 (u_longlong_t
)ddo
->ddo_dspace
,
5502 (u_longlong_t
)ddo
->ddo_mspace
);
5504 verify(nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_STATS
,
5505 (uint64_t **)&dds
, &c
) == 0);
5506 verify(nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_HISTOGRAM
,
5507 (uint64_t **)&ddh
, &c
) == 0);
5508 zpool_dump_ddt(dds
, ddh
);
5512 * Display a summary of pool status. Displays a summary such as:
5516 * reason: One or more devices ...
5517 * see: http://zfsonlinux.org/msg/ZFS-xxxx-01
5523 * When given the '-v' option, we print out the complete config. If the '-e'
5524 * option is specified, then we print out error rate information as well.
5527 status_callback(zpool_handle_t
*zhp
, void *data
)
5529 status_cbdata_t
*cbp
= data
;
5530 nvlist_t
*config
, *nvroot
;
5532 zpool_status_t reason
;
5533 zpool_errata_t errata
;
5538 config
= zpool_get_config(zhp
, NULL
);
5539 reason
= zpool_get_status(zhp
, &msgid
, &errata
);
5544 * If we were given 'zpool status -x', only report those pools with
5547 if (cbp
->cb_explain
&&
5548 (reason
== ZPOOL_STATUS_OK
||
5549 reason
== ZPOOL_STATUS_VERSION_OLDER
||
5550 reason
== ZPOOL_STATUS_FEAT_DISABLED
)) {
5551 if (!cbp
->cb_allpools
) {
5552 (void) printf(gettext("pool '%s' is healthy\n"),
5553 zpool_get_name(zhp
));
5555 cbp
->cb_first
= B_FALSE
;
5561 cbp
->cb_first
= B_FALSE
;
5563 (void) printf("\n");
5565 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
5567 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_VDEV_STATS
,
5568 (uint64_t **)&vs
, &c
) == 0);
5569 health
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
5571 (void) printf(gettext(" pool: %s\n"), zpool_get_name(zhp
));
5572 (void) printf(gettext(" state: %s\n"), health
);
5575 case ZPOOL_STATUS_MISSING_DEV_R
:
5576 (void) printf(gettext("status: One or more devices could not "
5577 "be opened. Sufficient replicas exist for\n\tthe pool to "
5578 "continue functioning in a degraded state.\n"));
5579 (void) printf(gettext("action: Attach the missing device and "
5580 "online it using 'zpool online'.\n"));
5583 case ZPOOL_STATUS_MISSING_DEV_NR
:
5584 (void) printf(gettext("status: One or more devices could not "
5585 "be opened. There are insufficient\n\treplicas for the "
5586 "pool to continue functioning.\n"));
5587 (void) printf(gettext("action: Attach the missing device and "
5588 "online it using 'zpool online'.\n"));
5591 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
5592 (void) printf(gettext("status: One or more devices could not "
5593 "be used because the label is missing or\n\tinvalid. "
5594 "Sufficient replicas exist for the pool to continue\n\t"
5595 "functioning in a degraded state.\n"));
5596 (void) printf(gettext("action: Replace the device using "
5597 "'zpool replace'.\n"));
5600 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
5601 (void) printf(gettext("status: One or more devices could not "
5602 "be used because the label is missing \n\tor invalid. "
5603 "There are insufficient replicas for the pool to "
5604 "continue\n\tfunctioning.\n"));
5605 zpool_explain_recover(zpool_get_handle(zhp
),
5606 zpool_get_name(zhp
), reason
, config
);
5609 case ZPOOL_STATUS_FAILING_DEV
:
5610 (void) printf(gettext("status: One or more devices has "
5611 "experienced an unrecoverable error. An\n\tattempt was "
5612 "made to correct the error. Applications are "
5614 (void) printf(gettext("action: Determine if the device needs "
5615 "to be replaced, and clear the errors\n\tusing "
5616 "'zpool clear' or replace the device with 'zpool "
5620 case ZPOOL_STATUS_OFFLINE_DEV
:
5621 (void) printf(gettext("status: One or more devices has "
5622 "been taken offline by the administrator.\n\tSufficient "
5623 "replicas exist for the pool to continue functioning in "
5624 "a\n\tdegraded state.\n"));
5625 (void) printf(gettext("action: Online the device using "
5626 "'zpool online' or replace the device with\n\t'zpool "
5630 case ZPOOL_STATUS_REMOVED_DEV
:
5631 (void) printf(gettext("status: One or more devices has "
5632 "been removed by the administrator.\n\tSufficient "
5633 "replicas exist for the pool to continue functioning in "
5634 "a\n\tdegraded state.\n"));
5635 (void) printf(gettext("action: Online the device using "
5636 "'zpool online' or replace the device with\n\t'zpool "
5640 case ZPOOL_STATUS_RESILVERING
:
5641 (void) printf(gettext("status: One or more devices is "
5642 "currently being resilvered. The pool will\n\tcontinue "
5643 "to function, possibly in a degraded state.\n"));
5644 (void) printf(gettext("action: Wait for the resilver to "
5648 case ZPOOL_STATUS_CORRUPT_DATA
:
5649 (void) printf(gettext("status: One or more devices has "
5650 "experienced an error resulting in data\n\tcorruption. "
5651 "Applications may be affected.\n"));
5652 (void) printf(gettext("action: Restore the file in question "
5653 "if possible. Otherwise restore the\n\tentire pool from "
5657 case ZPOOL_STATUS_CORRUPT_POOL
:
5658 (void) printf(gettext("status: The pool metadata is corrupted "
5659 "and the pool cannot be opened.\n"));
5660 zpool_explain_recover(zpool_get_handle(zhp
),
5661 zpool_get_name(zhp
), reason
, config
);
5664 case ZPOOL_STATUS_VERSION_OLDER
:
5665 (void) printf(gettext("status: The pool is formatted using a "
5666 "legacy on-disk format. The pool can\n\tstill be used, "
5667 "but some features are unavailable.\n"));
5668 (void) printf(gettext("action: Upgrade the pool using 'zpool "
5669 "upgrade'. Once this is done, the\n\tpool will no longer "
5670 "be accessible on software that does not support\n\t"
5671 "feature flags.\n"));
5674 case ZPOOL_STATUS_VERSION_NEWER
:
5675 (void) printf(gettext("status: The pool has been upgraded to a "
5676 "newer, incompatible on-disk version.\n\tThe pool cannot "
5677 "be accessed on this system.\n"));
5678 (void) printf(gettext("action: Access the pool from a system "
5679 "running more recent software, or\n\trestore the pool from "
5683 case ZPOOL_STATUS_FEAT_DISABLED
:
5684 (void) printf(gettext("status: Some supported features are not "
5685 "enabled on the pool. The pool can\n\tstill be used, but "
5686 "some features are unavailable.\n"));
5687 (void) printf(gettext("action: Enable all features using "
5688 "'zpool upgrade'. Once this is done,\n\tthe pool may no "
5689 "longer be accessible by software that does not support\n\t"
5690 "the features. See zpool-features(5) for details.\n"));
5693 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
5694 (void) printf(gettext("status: The pool cannot be accessed on "
5695 "this system because it uses the\n\tfollowing feature(s) "
5696 "not supported on this system:\n"));
5697 zpool_print_unsup_feat(config
);
5698 (void) printf("\n");
5699 (void) printf(gettext("action: Access the pool from a system "
5700 "that supports the required feature(s),\n\tor restore the "
5701 "pool from backup.\n"));
5704 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
5705 (void) printf(gettext("status: The pool can only be accessed "
5706 "in read-only mode on this system. It\n\tcannot be "
5707 "accessed in read-write mode because it uses the "
5708 "following\n\tfeature(s) not supported on this system:\n"));
5709 zpool_print_unsup_feat(config
);
5710 (void) printf("\n");
5711 (void) printf(gettext("action: The pool cannot be accessed in "
5712 "read-write mode. Import the pool with\n"
5713 "\t\"-o readonly=on\", access the pool from a system that "
5714 "supports the\n\trequired feature(s), or restore the "
5715 "pool from backup.\n"));
5718 case ZPOOL_STATUS_FAULTED_DEV_R
:
5719 (void) printf(gettext("status: One or more devices are "
5720 "faulted in response to persistent errors.\n\tSufficient "
5721 "replicas exist for the pool to continue functioning "
5722 "in a\n\tdegraded state.\n"));
5723 (void) printf(gettext("action: Replace the faulted device, "
5724 "or use 'zpool clear' to mark the device\n\trepaired.\n"));
5727 case ZPOOL_STATUS_FAULTED_DEV_NR
:
5728 (void) printf(gettext("status: One or more devices are "
5729 "faulted in response to persistent errors. There are "
5730 "insufficient replicas for the pool to\n\tcontinue "
5732 (void) printf(gettext("action: Destroy and re-create the pool "
5733 "from a backup source. Manually marking the device\n"
5734 "\trepaired using 'zpool clear' may allow some data "
5735 "to be recovered.\n"));
5738 case ZPOOL_STATUS_IO_FAILURE_WAIT
:
5739 case ZPOOL_STATUS_IO_FAILURE_CONTINUE
:
5740 (void) printf(gettext("status: One or more devices are "
5741 "faulted in response to IO failures.\n"));
5742 (void) printf(gettext("action: Make sure the affected devices "
5743 "are connected, then run 'zpool clear'.\n"));
5746 case ZPOOL_STATUS_BAD_LOG
:
5747 (void) printf(gettext("status: An intent log record "
5748 "could not be read.\n"
5749 "\tWaiting for adminstrator intervention to fix the "
5750 "faulted pool.\n"));
5751 (void) printf(gettext("action: Either restore the affected "
5752 "device(s) and run 'zpool online',\n"
5753 "\tor ignore the intent log records by running "
5754 "'zpool clear'.\n"));
5757 case ZPOOL_STATUS_HOSTID_MISMATCH
:
5758 (void) printf(gettext("status: Mismatch between pool hostid "
5759 "and system hostid on imported pool.\n\tThis pool was "
5760 "previously imported into a system with a different "
5761 "hostid,\n\tand then was verbatim imported into this "
5763 (void) printf(gettext("action: Export this pool on all systems "
5764 "on which it is imported.\n"
5765 "\tThen import it to correct the mismatch.\n"));
5768 case ZPOOL_STATUS_ERRATA
:
5769 (void) printf(gettext("status: Errata #%d detected.\n"),
5773 case ZPOOL_ERRATA_NONE
:
5776 case ZPOOL_ERRATA_ZOL_2094_SCRUB
:
5777 (void) printf(gettext("action: To correct the issue "
5778 "run 'zpool scrub'.\n"));
5783 * All errata which allow the pool to be imported
5784 * must contain an action message.
5792 * The remaining errors can't actually be generated, yet.
5794 assert(reason
== ZPOOL_STATUS_OK
);
5798 (void) printf(gettext(" see: http://zfsonlinux.org/msg/%s\n"),
5801 if (config
!= NULL
) {
5804 nvlist_t
**spares
, **l2cache
;
5805 uint_t nspares
, nl2cache
;
5806 pool_scan_stat_t
*ps
= NULL
;
5808 (void) nvlist_lookup_uint64_array(nvroot
,
5809 ZPOOL_CONFIG_SCAN_STATS
, (uint64_t **)&ps
, &c
);
5810 print_scan_status(ps
);
5812 namewidth
= max_width(zhp
, nvroot
, 0, 0, cbp
->cb_name_flags
);
5816 (void) printf(gettext("config:\n\n"));
5817 (void) printf(gettext("\t%-*s %-8s %5s %5s %5s\n"), namewidth
,
5818 "NAME", "STATE", "READ", "WRITE", "CKSUM");
5819 print_status_config(zhp
, zpool_get_name(zhp
), nvroot
,
5820 namewidth
, 0, B_FALSE
, cbp
->cb_name_flags
);
5822 if (num_logs(nvroot
) > 0)
5823 print_logs(zhp
, nvroot
, namewidth
, B_TRUE
,
5824 cbp
->cb_name_flags
);
5825 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_L2CACHE
,
5826 &l2cache
, &nl2cache
) == 0)
5827 print_l2cache(zhp
, l2cache
, nl2cache
, namewidth
,
5828 cbp
->cb_name_flags
);
5830 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_SPARES
,
5831 &spares
, &nspares
) == 0)
5832 print_spares(zhp
, spares
, nspares
, namewidth
,
5833 cbp
->cb_name_flags
);
5835 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_ERRCOUNT
,
5837 nvlist_t
*nverrlist
= NULL
;
5840 * If the approximate error count is small, get a
5841 * precise count by fetching the entire log and
5842 * uniquifying the results.
5844 if (nerr
> 0 && nerr
< 100 && !cbp
->cb_verbose
&&
5845 zpool_get_errlog(zhp
, &nverrlist
) == 0) {
5850 while ((elem
= nvlist_next_nvpair(nverrlist
,
5855 nvlist_free(nverrlist
);
5857 (void) printf("\n");
5860 (void) printf(gettext("errors: No known data "
5862 else if (!cbp
->cb_verbose
)
5863 (void) printf(gettext("errors: %llu data "
5864 "errors, use '-v' for a list\n"),
5865 (u_longlong_t
)nerr
);
5867 print_error_log(zhp
);
5870 if (cbp
->cb_dedup_stats
)
5871 print_dedup_stats(config
);
5873 (void) printf(gettext("config: The configuration cannot be "
5881 * zpool status [-gLPvx] [-T d|u] [pool] ... [interval [count]]
5883 * -g Display guid for individual vdev name.
5884 * -L Follow links when resolving vdev path name.
5885 * -P Display full path for vdev name.
5886 * -v Display complete error logs
5887 * -x Display only pools with potential problems
5888 * -D Display dedup status (undocumented)
5889 * -T Display a timestamp in date(1) or Unix format
5891 * Describes the health status of all pools or some subset.
5894 zpool_do_status(int argc
, char **argv
)
5899 unsigned long count
= 0;
5900 status_cbdata_t cb
= { 0 };
5903 while ((c
= getopt(argc
, argv
, "gLPvxDT:")) != -1) {
5906 cb
.cb_name_flags
|= VDEV_NAME_GUID
;
5909 cb
.cb_name_flags
|= VDEV_NAME_FOLLOW_LINKS
;
5912 cb
.cb_name_flags
|= VDEV_NAME_PATH
;
5915 cb
.cb_verbose
= B_TRUE
;
5918 cb
.cb_explain
= B_TRUE
;
5921 cb
.cb_dedup_stats
= B_TRUE
;
5924 get_timestamp_arg(*optarg
);
5927 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5936 get_interval_count(&argc
, argv
, &interval
, &count
);
5939 cb
.cb_allpools
= B_TRUE
;
5941 cb
.cb_first
= B_TRUE
;
5944 if (timestamp_fmt
!= NODATE
)
5945 print_timestamp(timestamp_fmt
);
5947 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
,
5948 status_callback
, &cb
);
5950 if (argc
== 0 && cb
.cb_count
== 0)
5951 (void) fprintf(stderr
, gettext("no pools available\n"));
5952 else if (cb
.cb_explain
&& cb
.cb_first
&& cb
.cb_allpools
)
5953 (void) printf(gettext("all pools are healthy\n"));
5961 if (count
!= 0 && --count
== 0)
5964 (void) fsleep(interval
);
5970 typedef struct upgrade_cbdata
{
5973 uint64_t cb_version
;
5978 check_unsupp_fs(zfs_handle_t
*zhp
, void *unsupp_fs
)
5980 int zfs_version
= (int) zfs_prop_get_int(zhp
, ZFS_PROP_VERSION
);
5981 int *count
= (int *)unsupp_fs
;
5983 if (zfs_version
> ZPL_VERSION
) {
5984 (void) printf(gettext("%s (v%d) is not supported by this "
5985 "implementation of ZFS.\n"),
5986 zfs_get_name(zhp
), zfs_version
);
5990 zfs_iter_filesystems(zhp
, check_unsupp_fs
, unsupp_fs
);
5998 upgrade_version(zpool_handle_t
*zhp
, uint64_t version
)
6002 uint64_t oldversion
;
6005 config
= zpool_get_config(zhp
, NULL
);
6006 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
6009 assert(SPA_VERSION_IS_SUPPORTED(oldversion
));
6010 assert(oldversion
< version
);
6012 ret
= zfs_iter_root(zpool_get_handle(zhp
), check_unsupp_fs
, &unsupp_fs
);
6017 (void) fprintf(stderr
, gettext("Upgrade not performed due "
6018 "to %d unsupported filesystems (max v%d).\n"),
6019 unsupp_fs
, (int) ZPL_VERSION
);
6023 ret
= zpool_upgrade(zhp
, version
);
6027 if (version
>= SPA_VERSION_FEATURES
) {
6028 (void) printf(gettext("Successfully upgraded "
6029 "'%s' from version %llu to feature flags.\n"),
6030 zpool_get_name(zhp
), (u_longlong_t
) oldversion
);
6032 (void) printf(gettext("Successfully upgraded "
6033 "'%s' from version %llu to version %llu.\n"),
6034 zpool_get_name(zhp
), (u_longlong_t
) oldversion
,
6035 (u_longlong_t
) version
);
6042 upgrade_enable_all(zpool_handle_t
*zhp
, int *countp
)
6045 boolean_t firstff
= B_TRUE
;
6046 nvlist_t
*enabled
= zpool_get_features(zhp
);
6049 for (i
= 0; i
< SPA_FEATURES
; i
++) {
6050 const char *fname
= spa_feature_table
[i
].fi_uname
;
6051 const char *fguid
= spa_feature_table
[i
].fi_guid
;
6052 if (!nvlist_exists(enabled
, fguid
)) {
6054 verify(-1 != asprintf(&propname
, "feature@%s", fname
));
6055 ret
= zpool_set_prop(zhp
, propname
,
6056 ZFS_FEATURE_ENABLED
);
6064 (void) printf(gettext("Enabled the "
6065 "following features on '%s':\n"),
6066 zpool_get_name(zhp
));
6069 (void) printf(gettext(" %s\n"), fname
);
6080 upgrade_cb(zpool_handle_t
*zhp
, void *arg
)
6082 upgrade_cbdata_t
*cbp
= arg
;
6085 boolean_t printnl
= B_FALSE
;
6088 config
= zpool_get_config(zhp
, NULL
);
6089 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
6092 assert(SPA_VERSION_IS_SUPPORTED(version
));
6094 if (version
< cbp
->cb_version
) {
6095 cbp
->cb_first
= B_FALSE
;
6096 ret
= upgrade_version(zhp
, cbp
->cb_version
);
6102 * If they did "zpool upgrade -a", then we could
6103 * be doing ioctls to different pools. We need
6104 * to log this history once to each pool, and bypass
6105 * the normal history logging that happens in main().
6107 (void) zpool_log_history(g_zfs
, history_str
);
6108 log_history
= B_FALSE
;
6111 if (cbp
->cb_version
>= SPA_VERSION_FEATURES
) {
6113 ret
= upgrade_enable_all(zhp
, &count
);
6118 cbp
->cb_first
= B_FALSE
;
6124 (void) printf(gettext("\n"));
6131 upgrade_list_older_cb(zpool_handle_t
*zhp
, void *arg
)
6133 upgrade_cbdata_t
*cbp
= arg
;
6137 config
= zpool_get_config(zhp
, NULL
);
6138 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
6141 assert(SPA_VERSION_IS_SUPPORTED(version
));
6143 if (version
< SPA_VERSION_FEATURES
) {
6144 if (cbp
->cb_first
) {
6145 (void) printf(gettext("The following pools are "
6146 "formatted with legacy version numbers and can\n"
6147 "be upgraded to use feature flags. After "
6148 "being upgraded, these pools\nwill no "
6149 "longer be accessible by software that does not "
6150 "support feature\nflags.\n\n"));
6151 (void) printf(gettext("VER POOL\n"));
6152 (void) printf(gettext("--- ------------\n"));
6153 cbp
->cb_first
= B_FALSE
;
6156 (void) printf("%2llu %s\n", (u_longlong_t
)version
,
6157 zpool_get_name(zhp
));
6164 upgrade_list_disabled_cb(zpool_handle_t
*zhp
, void *arg
)
6166 upgrade_cbdata_t
*cbp
= arg
;
6170 config
= zpool_get_config(zhp
, NULL
);
6171 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
6174 if (version
>= SPA_VERSION_FEATURES
) {
6176 boolean_t poolfirst
= B_TRUE
;
6177 nvlist_t
*enabled
= zpool_get_features(zhp
);
6179 for (i
= 0; i
< SPA_FEATURES
; i
++) {
6180 const char *fguid
= spa_feature_table
[i
].fi_guid
;
6181 const char *fname
= spa_feature_table
[i
].fi_uname
;
6182 if (!nvlist_exists(enabled
, fguid
)) {
6183 if (cbp
->cb_first
) {
6184 (void) printf(gettext("\nSome "
6185 "supported features are not "
6186 "enabled on the following pools. "
6187 "Once a\nfeature is enabled the "
6188 "pool may become incompatible with "
6189 "software\nthat does not support "
6191 "zpool-features(5) for "
6193 (void) printf(gettext("POOL "
6195 (void) printf(gettext("------"
6197 cbp
->cb_first
= B_FALSE
;
6201 (void) printf(gettext("%s\n"),
6202 zpool_get_name(zhp
));
6203 poolfirst
= B_FALSE
;
6206 (void) printf(gettext(" %s\n"), fname
);
6209 * If they did "zpool upgrade -a", then we could
6210 * be doing ioctls to different pools. We need
6211 * to log this history once to each pool, and bypass
6212 * the normal history logging that happens in main().
6214 (void) zpool_log_history(g_zfs
, history_str
);
6215 log_history
= B_FALSE
;
6224 upgrade_one(zpool_handle_t
*zhp
, void *data
)
6226 boolean_t printnl
= B_FALSE
;
6227 upgrade_cbdata_t
*cbp
= data
;
6228 uint64_t cur_version
;
6231 if (strcmp("log", zpool_get_name(zhp
)) == 0) {
6232 (void) fprintf(stderr
, gettext("'log' is now a reserved word\n"
6233 "Pool 'log' must be renamed using export and import"
6238 cur_version
= zpool_get_prop_int(zhp
, ZPOOL_PROP_VERSION
, NULL
);
6239 if (cur_version
> cbp
->cb_version
) {
6240 (void) printf(gettext("Pool '%s' is already formatted "
6241 "using more current version '%llu'.\n\n"),
6242 zpool_get_name(zhp
), (u_longlong_t
) cur_version
);
6246 if (cbp
->cb_version
!= SPA_VERSION
&& cur_version
== cbp
->cb_version
) {
6247 (void) printf(gettext("Pool '%s' is already formatted "
6248 "using version %llu.\n\n"), zpool_get_name(zhp
),
6249 (u_longlong_t
) cbp
->cb_version
);
6253 if (cur_version
!= cbp
->cb_version
) {
6255 ret
= upgrade_version(zhp
, cbp
->cb_version
);
6260 if (cbp
->cb_version
>= SPA_VERSION_FEATURES
) {
6262 ret
= upgrade_enable_all(zhp
, &count
);
6268 } else if (cur_version
== SPA_VERSION
) {
6269 (void) printf(gettext("Pool '%s' already has all "
6270 "supported features enabled.\n"),
6271 zpool_get_name(zhp
));
6276 (void) printf(gettext("\n"));
6285 * zpool upgrade [-V version] <-a | pool ...>
6287 * With no arguments, display downrev'd ZFS pool available for upgrade.
6288 * Individual pools can be upgraded by specifying the pool, and '-a' will
6289 * upgrade all pools.
6292 zpool_do_upgrade(int argc
, char **argv
)
6295 upgrade_cbdata_t cb
= { 0 };
6297 boolean_t showversions
= B_FALSE
;
6298 boolean_t upgradeall
= B_FALSE
;
6303 while ((c
= getopt(argc
, argv
, ":avV:")) != -1) {
6306 upgradeall
= B_TRUE
;
6309 showversions
= B_TRUE
;
6312 cb
.cb_version
= strtoll(optarg
, &end
, 10);
6314 !SPA_VERSION_IS_SUPPORTED(cb
.cb_version
)) {
6315 (void) fprintf(stderr
,
6316 gettext("invalid version '%s'\n"), optarg
);
6321 (void) fprintf(stderr
, gettext("missing argument for "
6322 "'%c' option\n"), optopt
);
6326 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
6337 if (cb
.cb_version
== 0) {
6338 cb
.cb_version
= SPA_VERSION
;
6339 } else if (!upgradeall
&& argc
== 0) {
6340 (void) fprintf(stderr
, gettext("-V option is "
6341 "incompatible with other arguments\n"));
6346 if (upgradeall
|| argc
!= 0) {
6347 (void) fprintf(stderr
, gettext("-v option is "
6348 "incompatible with other arguments\n"));
6351 } else if (upgradeall
) {
6353 (void) fprintf(stderr
, gettext("-a option should not "
6354 "be used along with a pool name\n"));
6359 (void) printf(gettext("This system supports ZFS pool feature "
6364 (void) printf(gettext("The following features are "
6366 (void) printf(gettext("FEAT DESCRIPTION\n"));
6367 (void) printf("----------------------------------------------"
6368 "---------------\n");
6369 for (i
= 0; i
< SPA_FEATURES
; i
++) {
6370 zfeature_info_t
*fi
= &spa_feature_table
[i
];
6372 (fi
->fi_flags
& ZFEATURE_FLAG_READONLY_COMPAT
) ?
6373 " (read-only compatible)" : "";
6375 (void) printf("%-37s%s\n", fi
->fi_uname
, ro
);
6376 (void) printf(" %s\n", fi
->fi_desc
);
6378 (void) printf("\n");
6380 (void) printf(gettext("The following legacy versions are also "
6382 (void) printf(gettext("VER DESCRIPTION\n"));
6383 (void) printf("--- -----------------------------------------"
6384 "---------------\n");
6385 (void) printf(gettext(" 1 Initial ZFS version\n"));
6386 (void) printf(gettext(" 2 Ditto blocks "
6387 "(replicated metadata)\n"));
6388 (void) printf(gettext(" 3 Hot spares and double parity "
6390 (void) printf(gettext(" 4 zpool history\n"));
6391 (void) printf(gettext(" 5 Compression using the gzip "
6393 (void) printf(gettext(" 6 bootfs pool property\n"));
6394 (void) printf(gettext(" 7 Separate intent log devices\n"));
6395 (void) printf(gettext(" 8 Delegated administration\n"));
6396 (void) printf(gettext(" 9 refquota and refreservation "
6398 (void) printf(gettext(" 10 Cache devices\n"));
6399 (void) printf(gettext(" 11 Improved scrub performance\n"));
6400 (void) printf(gettext(" 12 Snapshot properties\n"));
6401 (void) printf(gettext(" 13 snapused property\n"));
6402 (void) printf(gettext(" 14 passthrough-x aclinherit\n"));
6403 (void) printf(gettext(" 15 user/group space accounting\n"));
6404 (void) printf(gettext(" 16 stmf property support\n"));
6405 (void) printf(gettext(" 17 Triple-parity RAID-Z\n"));
6406 (void) printf(gettext(" 18 Snapshot user holds\n"));
6407 (void) printf(gettext(" 19 Log device removal\n"));
6408 (void) printf(gettext(" 20 Compression using zle "
6409 "(zero-length encoding)\n"));
6410 (void) printf(gettext(" 21 Deduplication\n"));
6411 (void) printf(gettext(" 22 Received properties\n"));
6412 (void) printf(gettext(" 23 Slim ZIL\n"));
6413 (void) printf(gettext(" 24 System attributes\n"));
6414 (void) printf(gettext(" 25 Improved scrub stats\n"));
6415 (void) printf(gettext(" 26 Improved snapshot deletion "
6417 (void) printf(gettext(" 27 Improved snapshot creation "
6419 (void) printf(gettext(" 28 Multiple vdev replacements\n"));
6420 (void) printf(gettext("\nFor more information on a particular "
6421 "version, including supported releases,\n"));
6422 (void) printf(gettext("see the ZFS Administration Guide.\n\n"));
6423 } else if (argc
== 0 && upgradeall
) {
6424 cb
.cb_first
= B_TRUE
;
6425 ret
= zpool_iter(g_zfs
, upgrade_cb
, &cb
);
6426 if (ret
== 0 && cb
.cb_first
) {
6427 if (cb
.cb_version
== SPA_VERSION
) {
6428 (void) printf(gettext("All pools are already "
6429 "formatted using feature flags.\n\n"));
6430 (void) printf(gettext("Every feature flags "
6431 "pool already has all supported features "
6434 (void) printf(gettext("All pools are already "
6435 "formatted with version %llu or higher.\n"),
6436 (u_longlong_t
) cb
.cb_version
);
6439 } else if (argc
== 0) {
6440 cb
.cb_first
= B_TRUE
;
6441 ret
= zpool_iter(g_zfs
, upgrade_list_older_cb
, &cb
);
6445 (void) printf(gettext("All pools are formatted "
6446 "using feature flags.\n\n"));
6448 (void) printf(gettext("\nUse 'zpool upgrade -v' "
6449 "for a list of available legacy versions.\n"));
6452 cb
.cb_first
= B_TRUE
;
6453 ret
= zpool_iter(g_zfs
, upgrade_list_disabled_cb
, &cb
);
6457 (void) printf(gettext("Every feature flags pool has "
6458 "all supported features enabled.\n"));
6460 (void) printf(gettext("\n"));
6463 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
,
6470 typedef struct hist_cbdata
{
6477 * Print out the command history for a specific pool.
6480 get_history_one(zpool_handle_t
*zhp
, void *data
)
6486 hist_cbdata_t
*cb
= (hist_cbdata_t
*)data
;
6488 cb
->first
= B_FALSE
;
6490 (void) printf(gettext("History for '%s':\n"), zpool_get_name(zhp
));
6492 if ((ret
= zpool_get_history(zhp
, &nvhis
)) != 0)
6495 verify(nvlist_lookup_nvlist_array(nvhis
, ZPOOL_HIST_RECORD
,
6496 &records
, &numrecords
) == 0);
6497 for (i
= 0; i
< numrecords
; i
++) {
6498 nvlist_t
*rec
= records
[i
];
6501 if (nvlist_exists(rec
, ZPOOL_HIST_TIME
)) {
6505 tsec
= fnvlist_lookup_uint64(records
[i
],
6507 (void) localtime_r(&tsec
, &t
);
6508 (void) strftime(tbuf
, sizeof (tbuf
), "%F.%T", &t
);
6511 if (nvlist_exists(rec
, ZPOOL_HIST_CMD
)) {
6512 (void) printf("%s %s", tbuf
,
6513 fnvlist_lookup_string(rec
, ZPOOL_HIST_CMD
));
6514 } else if (nvlist_exists(rec
, ZPOOL_HIST_INT_EVENT
)) {
6516 fnvlist_lookup_uint64(rec
, ZPOOL_HIST_INT_EVENT
);
6519 if (ievent
>= ZFS_NUM_LEGACY_HISTORY_EVENTS
) {
6520 (void) printf("%s unrecognized record:\n",
6522 dump_nvlist(rec
, 4);
6525 (void) printf("%s [internal %s txg:%lld] %s", tbuf
,
6526 zfs_history_event_names
[ievent
],
6527 (longlong_t
) fnvlist_lookup_uint64(
6528 rec
, ZPOOL_HIST_TXG
),
6529 fnvlist_lookup_string(rec
, ZPOOL_HIST_INT_STR
));
6530 } else if (nvlist_exists(rec
, ZPOOL_HIST_INT_NAME
)) {
6533 (void) printf("%s [txg:%lld] %s", tbuf
,
6534 (longlong_t
) fnvlist_lookup_uint64(
6535 rec
, ZPOOL_HIST_TXG
),
6536 fnvlist_lookup_string(rec
, ZPOOL_HIST_INT_NAME
));
6537 if (nvlist_exists(rec
, ZPOOL_HIST_DSNAME
)) {
6538 (void) printf(" %s (%llu)",
6539 fnvlist_lookup_string(rec
,
6541 (u_longlong_t
)fnvlist_lookup_uint64(rec
,
6544 (void) printf(" %s", fnvlist_lookup_string(rec
,
6545 ZPOOL_HIST_INT_STR
));
6546 } else if (nvlist_exists(rec
, ZPOOL_HIST_IOCTL
)) {
6549 (void) printf("%s ioctl %s\n", tbuf
,
6550 fnvlist_lookup_string(rec
, ZPOOL_HIST_IOCTL
));
6551 if (nvlist_exists(rec
, ZPOOL_HIST_INPUT_NVL
)) {
6552 (void) printf(" input:\n");
6553 dump_nvlist(fnvlist_lookup_nvlist(rec
,
6554 ZPOOL_HIST_INPUT_NVL
), 8);
6556 if (nvlist_exists(rec
, ZPOOL_HIST_OUTPUT_NVL
)) {
6557 (void) printf(" output:\n");
6558 dump_nvlist(fnvlist_lookup_nvlist(rec
,
6559 ZPOOL_HIST_OUTPUT_NVL
), 8);
6564 (void) printf("%s unrecognized record:\n", tbuf
);
6565 dump_nvlist(rec
, 4);
6569 (void) printf("\n");
6572 (void) printf(" [");
6573 if (nvlist_exists(rec
, ZPOOL_HIST_WHO
)) {
6574 uid_t who
= fnvlist_lookup_uint64(rec
, ZPOOL_HIST_WHO
);
6575 struct passwd
*pwd
= getpwuid(who
);
6576 (void) printf("user %d ", (int)who
);
6578 (void) printf("(%s) ", pwd
->pw_name
);
6580 if (nvlist_exists(rec
, ZPOOL_HIST_HOST
)) {
6581 (void) printf("on %s",
6582 fnvlist_lookup_string(rec
, ZPOOL_HIST_HOST
));
6584 if (nvlist_exists(rec
, ZPOOL_HIST_ZONE
)) {
6585 (void) printf(":%s",
6586 fnvlist_lookup_string(rec
, ZPOOL_HIST_ZONE
));
6590 (void) printf("\n");
6592 (void) printf("\n");
6599 * zpool history <pool>
6601 * Displays the history of commands that modified pools.
6604 zpool_do_history(int argc
, char **argv
)
6606 hist_cbdata_t cbdata
= { 0 };
6610 cbdata
.first
= B_TRUE
;
6612 while ((c
= getopt(argc
, argv
, "li")) != -1) {
6615 cbdata
.longfmt
= B_TRUE
;
6618 cbdata
.internal
= B_TRUE
;
6621 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
6629 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
, get_history_one
,
6632 if (argc
== 0 && cbdata
.first
== B_TRUE
) {
6633 (void) fprintf(stderr
, gettext("no pools available\n"));
6640 typedef struct ev_opts
{
6648 zpool_do_events_short(nvlist_t
*nvl
)
6650 char ctime_str
[26], str
[32], *ptr
;
6654 verify(nvlist_lookup_int64_array(nvl
, FM_EREPORT_TIME
, &tv
, &n
) == 0);
6655 memset(str
, ' ', 32);
6656 (void) ctime_r((const time_t *)&tv
[0], ctime_str
);
6657 (void) strncpy(str
, ctime_str
+4, 6); /* 'Jun 30' */
6658 (void) strncpy(str
+7, ctime_str
+20, 4); /* '1993' */
6659 (void) strncpy(str
+12, ctime_str
+11, 8); /* '21:49:08' */
6660 (void) sprintf(str
+20, ".%09lld", (longlong_t
)tv
[1]); /* '.123456789' */
6661 (void) printf(gettext("%s "), str
);
6663 verify(nvlist_lookup_string(nvl
, FM_CLASS
, &ptr
) == 0);
6664 (void) printf(gettext("%s\n"), ptr
);
6668 zpool_do_events_nvprint(nvlist_t
*nvl
, int depth
)
6672 for (nvp
= nvlist_next_nvpair(nvl
, NULL
);
6673 nvp
!= NULL
; nvp
= nvlist_next_nvpair(nvl
, nvp
)) {
6675 data_type_t type
= nvpair_type(nvp
);
6676 const char *name
= nvpair_name(nvp
);
6686 printf(gettext("%*s%s = "), depth
, "", name
);
6689 case DATA_TYPE_BOOLEAN
:
6690 printf(gettext("%s"), "1");
6693 case DATA_TYPE_BOOLEAN_VALUE
:
6694 (void) nvpair_value_boolean_value(nvp
, &b
);
6695 printf(gettext("%s"), b
? "1" : "0");
6698 case DATA_TYPE_BYTE
:
6699 (void) nvpair_value_byte(nvp
, &i8
);
6700 printf(gettext("0x%x"), i8
);
6703 case DATA_TYPE_INT8
:
6704 (void) nvpair_value_int8(nvp
, (void *)&i8
);
6705 printf(gettext("0x%x"), i8
);
6708 case DATA_TYPE_UINT8
:
6709 (void) nvpair_value_uint8(nvp
, &i8
);
6710 printf(gettext("0x%x"), i8
);
6713 case DATA_TYPE_INT16
:
6714 (void) nvpair_value_int16(nvp
, (void *)&i16
);
6715 printf(gettext("0x%x"), i16
);
6718 case DATA_TYPE_UINT16
:
6719 (void) nvpair_value_uint16(nvp
, &i16
);
6720 printf(gettext("0x%x"), i16
);
6723 case DATA_TYPE_INT32
:
6724 (void) nvpair_value_int32(nvp
, (void *)&i32
);
6725 printf(gettext("0x%x"), i32
);
6728 case DATA_TYPE_UINT32
:
6729 (void) nvpair_value_uint32(nvp
, &i32
);
6730 printf(gettext("0x%x"), i32
);
6733 case DATA_TYPE_INT64
:
6734 (void) nvpair_value_int64(nvp
, (void *)&i64
);
6735 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
6738 case DATA_TYPE_UINT64
:
6739 (void) nvpair_value_uint64(nvp
, &i64
);
6740 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
6743 case DATA_TYPE_HRTIME
:
6744 (void) nvpair_value_hrtime(nvp
, (void *)&i64
);
6745 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
6748 case DATA_TYPE_STRING
:
6749 (void) nvpair_value_string(nvp
, &str
);
6750 printf(gettext("\"%s\""), str
? str
: "<NULL>");
6753 case DATA_TYPE_NVLIST
:
6754 printf(gettext("(embedded nvlist)\n"));
6755 (void) nvpair_value_nvlist(nvp
, &cnv
);
6756 zpool_do_events_nvprint(cnv
, depth
+ 8);
6757 printf(gettext("%*s(end %s)"), depth
, "", name
);
6760 case DATA_TYPE_NVLIST_ARRAY
: {
6764 (void) nvpair_value_nvlist_array(nvp
, &val
, &nelem
);
6765 printf(gettext("(%d embedded nvlists)\n"), nelem
);
6766 for (i
= 0; i
< nelem
; i
++) {
6767 printf(gettext("%*s%s[%d] = %s\n"),
6768 depth
, "", name
, i
, "(embedded nvlist)");
6769 zpool_do_events_nvprint(val
[i
], depth
+ 8);
6770 printf(gettext("%*s(end %s[%i])\n"),
6771 depth
, "", name
, i
);
6773 printf(gettext("%*s(end %s)\n"), depth
, "", name
);
6777 case DATA_TYPE_INT8_ARRAY
: {
6781 (void) nvpair_value_int8_array(nvp
, &val
, &nelem
);
6782 for (i
= 0; i
< nelem
; i
++)
6783 printf(gettext("0x%x "), val
[i
]);
6788 case DATA_TYPE_UINT8_ARRAY
: {
6792 (void) nvpair_value_uint8_array(nvp
, &val
, &nelem
);
6793 for (i
= 0; i
< nelem
; i
++)
6794 printf(gettext("0x%x "), val
[i
]);
6799 case DATA_TYPE_INT16_ARRAY
: {
6803 (void) nvpair_value_int16_array(nvp
, &val
, &nelem
);
6804 for (i
= 0; i
< nelem
; i
++)
6805 printf(gettext("0x%x "), val
[i
]);
6810 case DATA_TYPE_UINT16_ARRAY
: {
6814 (void) nvpair_value_uint16_array(nvp
, &val
, &nelem
);
6815 for (i
= 0; i
< nelem
; i
++)
6816 printf(gettext("0x%x "), val
[i
]);
6821 case DATA_TYPE_INT32_ARRAY
: {
6825 (void) nvpair_value_int32_array(nvp
, &val
, &nelem
);
6826 for (i
= 0; i
< nelem
; i
++)
6827 printf(gettext("0x%x "), val
[i
]);
6832 case DATA_TYPE_UINT32_ARRAY
: {
6836 (void) nvpair_value_uint32_array(nvp
, &val
, &nelem
);
6837 for (i
= 0; i
< nelem
; i
++)
6838 printf(gettext("0x%x "), val
[i
]);
6843 case DATA_TYPE_INT64_ARRAY
: {
6847 (void) nvpair_value_int64_array(nvp
, &val
, &nelem
);
6848 for (i
= 0; i
< nelem
; i
++)
6849 printf(gettext("0x%llx "),
6850 (u_longlong_t
)val
[i
]);
6855 case DATA_TYPE_UINT64_ARRAY
: {
6859 (void) nvpair_value_uint64_array(nvp
, &val
, &nelem
);
6860 for (i
= 0; i
< nelem
; i
++)
6861 printf(gettext("0x%llx "),
6862 (u_longlong_t
)val
[i
]);
6867 case DATA_TYPE_STRING_ARRAY
: {
6871 (void) nvpair_value_string_array(nvp
, &str
, &nelem
);
6872 for (i
= 0; i
< nelem
; i
++)
6873 printf(gettext("\"%s\" "),
6874 str
[i
] ? str
[i
] : "<NULL>");
6879 case DATA_TYPE_BOOLEAN_ARRAY
:
6880 case DATA_TYPE_BYTE_ARRAY
:
6881 case DATA_TYPE_DOUBLE
:
6882 case DATA_TYPE_UNKNOWN
:
6883 printf(gettext("<unknown>"));
6887 printf(gettext("\n"));
6892 zpool_do_events_next(ev_opts_t
*opts
)
6895 int zevent_fd
, ret
, dropped
;
6897 zevent_fd
= open(ZFS_DEV
, O_RDWR
);
6898 VERIFY(zevent_fd
>= 0);
6900 if (!opts
->scripted
)
6901 (void) printf(gettext("%-30s %s\n"), "TIME", "CLASS");
6904 ret
= zpool_events_next(g_zfs
, &nvl
, &dropped
,
6905 (opts
->follow
? ZEVENT_NONE
: ZEVENT_NONBLOCK
), zevent_fd
);
6906 if (ret
|| nvl
== NULL
)
6910 (void) printf(gettext("dropped %d events\n"), dropped
);
6912 zpool_do_events_short(nvl
);
6914 if (opts
->verbose
) {
6915 zpool_do_events_nvprint(nvl
, 8);
6916 printf(gettext("\n"));
6918 (void) fflush(stdout
);
6923 VERIFY(0 == close(zevent_fd
));
6929 zpool_do_events_clear(ev_opts_t
*opts
)
6933 ret
= zpool_events_clear(g_zfs
, &count
);
6935 (void) printf(gettext("cleared %d events\n"), count
);
6941 * zpool events [-vfc]
6943 * Displays events logs by ZFS.
6946 zpool_do_events(int argc
, char **argv
)
6948 ev_opts_t opts
= { 0 };
6953 while ((c
= getopt(argc
, argv
, "vHfc")) != -1) {
6968 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
6977 ret
= zpool_do_events_clear(&opts
);
6979 ret
= zpool_do_events_next(&opts
);
6985 get_callback(zpool_handle_t
*zhp
, void *data
)
6987 zprop_get_cbdata_t
*cbp
= (zprop_get_cbdata_t
*)data
;
6988 char value
[MAXNAMELEN
];
6989 zprop_source_t srctype
;
6992 for (pl
= cbp
->cb_proplist
; pl
!= NULL
; pl
= pl
->pl_next
) {
6995 * Skip the special fake placeholder. This will also skip
6996 * over the name property when 'all' is specified.
6998 if (pl
->pl_prop
== ZPOOL_PROP_NAME
&&
6999 pl
== cbp
->cb_proplist
)
7002 if (pl
->pl_prop
== ZPROP_INVAL
&&
7003 (zpool_prop_feature(pl
->pl_user_prop
) ||
7004 zpool_prop_unsupported(pl
->pl_user_prop
))) {
7005 srctype
= ZPROP_SRC_LOCAL
;
7007 if (zpool_prop_get_feature(zhp
, pl
->pl_user_prop
,
7008 value
, sizeof (value
)) == 0) {
7009 zprop_print_one_property(zpool_get_name(zhp
),
7010 cbp
, pl
->pl_user_prop
, value
, srctype
,
7014 if (zpool_get_prop(zhp
, pl
->pl_prop
, value
,
7015 sizeof (value
), &srctype
, cbp
->cb_literal
) != 0)
7018 zprop_print_one_property(zpool_get_name(zhp
), cbp
,
7019 zpool_prop_to_name(pl
->pl_prop
), value
, srctype
,
7027 * zpool get [-Hp] [-o "all" | field[,...]] <"all" | property[,...]> <pool> ...
7029 * -H Scripted mode. Don't display headers, and separate properties
7031 * -o List of columns to display. Defaults to
7032 * "name,property,value,source".
7033 * -p Diplay values in parsable (exact) format.
7035 * Get properties of pools in the system. Output space statistics
7036 * for each one as well as other attributes.
7039 zpool_do_get(int argc
, char **argv
)
7041 zprop_get_cbdata_t cb
= { 0 };
7042 zprop_list_t fake_name
= { 0 };
7047 cb
.cb_first
= B_TRUE
;
7050 * Set up default columns and sources.
7052 cb
.cb_sources
= ZPROP_SRC_ALL
;
7053 cb
.cb_columns
[0] = GET_COL_NAME
;
7054 cb
.cb_columns
[1] = GET_COL_PROPERTY
;
7055 cb
.cb_columns
[2] = GET_COL_VALUE
;
7056 cb
.cb_columns
[3] = GET_COL_SOURCE
;
7057 cb
.cb_type
= ZFS_TYPE_POOL
;
7060 while ((c
= getopt(argc
, argv
, ":Hpo:")) != -1) {
7063 cb
.cb_literal
= B_TRUE
;
7066 cb
.cb_scripted
= B_TRUE
;
7069 bzero(&cb
.cb_columns
, sizeof (cb
.cb_columns
));
7071 while (*optarg
!= '\0') {
7072 static char *col_subopts
[] =
7073 { "name", "property", "value", "source",
7076 if (i
== ZFS_GET_NCOLS
) {
7077 (void) fprintf(stderr
, gettext("too "
7078 "many fields given to -o "
7083 switch (getsubopt(&optarg
, col_subopts
,
7086 cb
.cb_columns
[i
++] = GET_COL_NAME
;
7089 cb
.cb_columns
[i
++] = GET_COL_PROPERTY
;
7092 cb
.cb_columns
[i
++] = GET_COL_VALUE
;
7095 cb
.cb_columns
[i
++] = GET_COL_SOURCE
;
7099 (void) fprintf(stderr
,
7100 gettext("\"all\" conflicts "
7101 "with specific fields "
7102 "given to -o option\n"));
7105 cb
.cb_columns
[0] = GET_COL_NAME
;
7106 cb
.cb_columns
[1] = GET_COL_PROPERTY
;
7107 cb
.cb_columns
[2] = GET_COL_VALUE
;
7108 cb
.cb_columns
[3] = GET_COL_SOURCE
;
7112 (void) fprintf(stderr
,
7113 gettext("invalid column name "
7120 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
7130 (void) fprintf(stderr
, gettext("missing property "
7135 if (zprop_get_list(g_zfs
, argv
[0], &cb
.cb_proplist
,
7136 ZFS_TYPE_POOL
) != 0)
7142 if (cb
.cb_proplist
!= NULL
) {
7143 fake_name
.pl_prop
= ZPOOL_PROP_NAME
;
7144 fake_name
.pl_width
= strlen(gettext("NAME"));
7145 fake_name
.pl_next
= cb
.cb_proplist
;
7146 cb
.cb_proplist
= &fake_name
;
7149 ret
= for_each_pool(argc
, argv
, B_TRUE
, &cb
.cb_proplist
,
7152 if (cb
.cb_proplist
== &fake_name
)
7153 zprop_free_list(fake_name
.pl_next
);
7155 zprop_free_list(cb
.cb_proplist
);
7160 typedef struct set_cbdata
{
7163 boolean_t cb_any_successful
;
7167 set_callback(zpool_handle_t
*zhp
, void *data
)
7170 set_cbdata_t
*cb
= (set_cbdata_t
*)data
;
7172 error
= zpool_set_prop(zhp
, cb
->cb_propname
, cb
->cb_value
);
7175 cb
->cb_any_successful
= B_TRUE
;
7181 zpool_do_set(int argc
, char **argv
)
7183 set_cbdata_t cb
= { 0 };
7186 if (argc
> 1 && argv
[1][0] == '-') {
7187 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
7193 (void) fprintf(stderr
, gettext("missing property=value "
7199 (void) fprintf(stderr
, gettext("missing pool name\n"));
7204 (void) fprintf(stderr
, gettext("too many pool names\n"));
7208 cb
.cb_propname
= argv
[1];
7209 cb
.cb_value
= strchr(cb
.cb_propname
, '=');
7210 if (cb
.cb_value
== NULL
) {
7211 (void) fprintf(stderr
, gettext("missing value in "
7212 "property=value argument\n"));
7216 *(cb
.cb_value
) = '\0';
7219 error
= for_each_pool(argc
- 2, argv
+ 2, B_TRUE
, NULL
,
7226 find_command_idx(char *command
, int *idx
)
7230 for (i
= 0; i
< NCOMMAND
; i
++) {
7231 if (command_table
[i
].name
== NULL
)
7234 if (strcmp(command
, command_table
[i
].name
) == 0) {
7243 main(int argc
, char **argv
)
7249 (void) setlocale(LC_ALL
, "");
7250 (void) textdomain(TEXT_DOMAIN
);
7253 dprintf_setup(&argc
, argv
);
7258 * Make sure the user has specified some command.
7261 (void) fprintf(stderr
, gettext("missing command\n"));
7270 if ((strcmp(cmdname
, "-?") == 0) || strcmp(cmdname
, "--help") == 0)
7273 if ((g_zfs
= libzfs_init()) == NULL
) {
7274 (void) fprintf(stderr
, "%s", libzfs_error_init(errno
));
7278 libzfs_print_on_error(g_zfs
, B_TRUE
);
7280 zfs_save_arguments(argc
, argv
, history_str
, sizeof (history_str
));
7283 * Run the appropriate command.
7285 if (find_command_idx(cmdname
, &i
) == 0) {
7286 current_command
= &command_table
[i
];
7287 ret
= command_table
[i
].func(argc
- 1, argv
+ 1);
7288 } else if (strchr(cmdname
, '=')) {
7289 verify(find_command_idx("set", &i
) == 0);
7290 current_command
= &command_table
[i
];
7291 ret
= command_table
[i
].func(argc
, argv
);
7292 } else if (strcmp(cmdname
, "freeze") == 0 && argc
== 3) {
7294 * 'freeze' is a vile debugging abomination, so we treat
7298 int fd
= open(ZFS_DEV
, O_RDWR
);
7299 (void) strcpy((void *)buf
, argv
[2]);
7300 return (!!ioctl(fd
, ZFS_IOC_POOL_FREEZE
, buf
));
7302 (void) fprintf(stderr
, gettext("unrecognized "
7303 "command '%s'\n"), cmdname
);
7308 if (ret
== 0 && log_history
)
7309 (void) zpool_log_history(g_zfs
, history_str
);
7314 * The 'ZFS_ABORT' environment variable causes us to dump core on exit
7315 * for the purposes of running ::findleaks.
7317 if (getenv("ZFS_ABORT") != NULL
) {
7318 (void) printf("dumping core by request\n");