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 (c) 2011, 2018 by Delphix. All rights reserved.
25 * Copyright (c) 2012 by Frederik Wessels. All rights reserved.
26 * Copyright (c) 2013 by Prasad Joshi (sTec). All rights reserved.
27 * Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>.
28 * Copyright 2016 Nexenta Systems, Inc.
29 * Copyright (c) 2017 Datto Inc.
51 #include <sys/fs/zfs.h>
56 #include "zpool_util.h"
57 #include "zfs_comutil.h"
58 #include "zfeature_common.h"
60 #include "statcommon.h"
62 static int zpool_do_create(int, char **);
63 static int zpool_do_destroy(int, char **);
65 static int zpool_do_add(int, char **);
66 static int zpool_do_remove(int, char **);
67 static int zpool_do_labelclear(int, char **);
69 static int zpool_do_checkpoint(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 **);
96 static int zpool_do_get(int, char **);
97 static int zpool_do_set(int, char **);
100 * These libumem hooks provide a reasonable set of defaults for the allocator's
101 * debugging facilities.
106 _umem_debug_init(void)
108 return ("default,verbose"); /* $UMEM_DEBUG setting */
112 _umem_logging_init(void)
114 return ("fail,contents"); /* $UMEM_LOGGING setting */
147 typedef struct zpool_command
{
149 int (*func
)(int, char **);
154 * Master command table. Each ZFS command has a name, associated function, and
155 * usage message. The usage messages need to be internationalized, so we have
156 * to have a function to return the usage message based on a command index.
158 * These commands are organized according to how they are displayed in the usage
159 * message. An empty command (one with a NULL name) indicates an empty line in
160 * the generic usage message.
162 static zpool_command_t command_table
[] = {
163 { "create", zpool_do_create
, HELP_CREATE
},
164 { "destroy", zpool_do_destroy
, HELP_DESTROY
},
166 { "add", zpool_do_add
, HELP_ADD
},
167 { "remove", zpool_do_remove
, HELP_REMOVE
},
169 { "labelclear", zpool_do_labelclear
, HELP_LABELCLEAR
},
171 { "checkpoint", zpool_do_checkpoint
, HELP_CHECKPOINT
},
173 { "list", zpool_do_list
, HELP_LIST
},
174 { "iostat", zpool_do_iostat
, HELP_IOSTAT
},
175 { "status", zpool_do_status
, HELP_STATUS
},
177 { "online", zpool_do_online
, HELP_ONLINE
},
178 { "offline", zpool_do_offline
, HELP_OFFLINE
},
179 { "clear", zpool_do_clear
, HELP_CLEAR
},
180 { "reopen", zpool_do_reopen
, HELP_REOPEN
},
182 { "attach", zpool_do_attach
, HELP_ATTACH
},
183 { "detach", zpool_do_detach
, HELP_DETACH
},
184 { "replace", zpool_do_replace
, HELP_REPLACE
},
185 { "split", zpool_do_split
, HELP_SPLIT
},
187 { "scrub", zpool_do_scrub
, HELP_SCRUB
},
189 { "import", zpool_do_import
, HELP_IMPORT
},
190 { "export", zpool_do_export
, HELP_EXPORT
},
191 { "upgrade", zpool_do_upgrade
, HELP_UPGRADE
},
192 { "reguid", zpool_do_reguid
, HELP_REGUID
},
194 { "history", zpool_do_history
, HELP_HISTORY
},
195 { "get", zpool_do_get
, HELP_GET
},
196 { "set", zpool_do_set
, HELP_SET
},
199 #define NCOMMAND (sizeof (command_table) / sizeof (command_table[0]))
201 static zpool_command_t
*current_command
;
202 static char history_str
[HIS_MAX_RECORD_LEN
];
203 static boolean_t log_history
= B_TRUE
;
204 static uint_t timestamp_fmt
= NODATE
;
207 get_usage(zpool_help_t idx
)
211 return (gettext("\tadd [-fn] <pool> <vdev> ...\n"));
213 return (gettext("\tattach [-f] <pool> <device> "
216 return (gettext("\tclear [-nF] <pool> [device]\n"));
218 return (gettext("\tcreate [-fnd] [-B] "
219 "[-o property=value] ... \n"
220 "\t [-O file-system-property=value] ... \n"
221 "\t [-m mountpoint] [-R root] <pool> <vdev> ...\n"));
222 case HELP_CHECKPOINT
:
223 return (gettext("\tcheckpoint [--discard] <pool> ...\n"));
225 return (gettext("\tdestroy [-f] <pool>\n"));
227 return (gettext("\tdetach <pool> <device>\n"));
229 return (gettext("\texport [-f] <pool> ...\n"));
231 return (gettext("\thistory [-il] [<pool>] ...\n"));
233 return (gettext("\timport [-d dir] [-D]\n"
234 "\timport [-o mntopts] [-o property=value] ... \n"
235 "\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
236 "[-R root] [-F [-n]] -a\n"
237 "\timport [-o mntopts] [-o property=value] ... \n"
238 "\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
239 "[-R root] [-F [-n]]\n"
240 "\t [--rewind-to-checkpoint] <pool | id> [newpool]\n"));
242 return (gettext("\tiostat [-v] [-T d|u] [pool] ... [interval "
244 case HELP_LABELCLEAR
:
245 return (gettext("\tlabelclear [-f] <vdev>\n"));
247 return (gettext("\tlist [-Hp] [-o property[,...]] "
248 "[-T d|u] [pool] ... [interval [count]]\n"));
250 return (gettext("\toffline [-t] <pool> <device> ...\n"));
252 return (gettext("\tonline <pool> <device> ...\n"));
254 return (gettext("\treplace [-f] <pool> <device> "
257 return (gettext("\tremove [-nps] <pool> <device> ...\n"));
259 return (gettext("\treopen <pool>\n"));
261 return (gettext("\tscrub [-s | -p] <pool> ...\n"));
263 return (gettext("\tstatus [-vx] [-T d|u] [pool] ... [interval "
266 return (gettext("\tupgrade\n"
268 "\tupgrade [-V version] <-a | pool ...>\n"));
270 return (gettext("\tget [-Hp] [-o \"all\" | field[,...]] "
271 "<\"all\" | property[,...]> <pool> ...\n"));
273 return (gettext("\tset <property=value> <pool> \n"));
275 return (gettext("\tsplit [-n] [-R altroot] [-o mntopts]\n"
276 "\t [-o property=value] <pool> <newpool> "
277 "[<device> ...]\n"));
279 return (gettext("\treguid <pool>\n"));
288 * Callback routine that will print out a pool property value.
291 print_prop_cb(int prop
, void *cb
)
295 (void) fprintf(fp
, "\t%-15s ", zpool_prop_to_name(prop
));
297 if (zpool_prop_readonly(prop
))
298 (void) fprintf(fp
, " NO ");
300 (void) fprintf(fp
, " YES ");
302 if (zpool_prop_values(prop
) == NULL
)
303 (void) fprintf(fp
, "-\n");
305 (void) fprintf(fp
, "%s\n", zpool_prop_values(prop
));
311 * Display usage message. If we're inside a command, display only the usage for
312 * that command. Otherwise, iterate over the entire command table and display
313 * a complete usage message.
316 usage(boolean_t requested
)
318 FILE *fp
= requested
? stdout
: stderr
;
320 if (current_command
== NULL
) {
323 (void) fprintf(fp
, gettext("usage: zpool command args ...\n"));
325 gettext("where 'command' is one of the following:\n\n"));
327 for (i
= 0; i
< NCOMMAND
; i
++) {
328 if (command_table
[i
].name
== NULL
)
329 (void) fprintf(fp
, "\n");
331 (void) fprintf(fp
, "%s",
332 get_usage(command_table
[i
].usage
));
335 (void) fprintf(fp
, gettext("usage:\n"));
336 (void) fprintf(fp
, "%s", get_usage(current_command
->usage
));
339 if (current_command
!= NULL
&&
340 ((strcmp(current_command
->name
, "set") == 0) ||
341 (strcmp(current_command
->name
, "get") == 0) ||
342 (strcmp(current_command
->name
, "list") == 0))) {
345 gettext("\nthe following properties are supported:\n"));
347 (void) fprintf(fp
, "\n\t%-15s %s %s\n\n",
348 "PROPERTY", "EDIT", "VALUES");
350 /* Iterate over all properties */
351 (void) zprop_iter(print_prop_cb
, fp
, B_FALSE
, B_TRUE
,
354 (void) fprintf(fp
, "\t%-15s ", "feature@...");
355 (void) fprintf(fp
, "YES disabled | enabled | active\n");
357 (void) fprintf(fp
, gettext("\nThe feature@ properties must be "
358 "appended with a feature name.\nSee zpool-features(5).\n"));
362 * See comments at end of main().
364 if (getenv("ZFS_ABORT") != NULL
) {
365 (void) printf("dumping core by request\n");
369 exit(requested
? 0 : 2);
373 print_vdev_tree(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
, int indent
,
374 boolean_t print_logs
)
381 (void) printf("\t%*s%s\n", indent
, "", name
);
383 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
384 &child
, &children
) != 0)
387 for (c
= 0; c
< children
; c
++) {
388 uint64_t is_log
= B_FALSE
;
390 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
392 if ((is_log
&& !print_logs
) || (!is_log
&& print_logs
))
395 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], B_FALSE
);
396 print_vdev_tree(zhp
, vname
, child
[c
], indent
+ 2,
403 prop_list_contains_feature(nvlist_t
*proplist
)
406 for (nvp
= nvlist_next_nvpair(proplist
, NULL
); NULL
!= nvp
;
407 nvp
= nvlist_next_nvpair(proplist
, nvp
)) {
408 if (zpool_prop_feature(nvpair_name(nvp
)))
415 * Add a property pair (name, string-value) into a property nvlist.
418 add_prop_list(const char *propname
, char *propval
, nvlist_t
**props
,
421 zpool_prop_t prop
= ZPOOL_PROP_INVAL
;
427 if (*props
== NULL
&&
428 nvlist_alloc(props
, NV_UNIQUE_NAME
, 0) != 0) {
429 (void) fprintf(stderr
,
430 gettext("internal error: out of memory\n"));
437 const char *vname
= zpool_prop_to_name(ZPOOL_PROP_VERSION
);
439 if ((prop
= zpool_name_to_prop(propname
)) == ZPOOL_PROP_INVAL
&&
440 !zpool_prop_feature(propname
)) {
441 (void) fprintf(stderr
, gettext("property '%s' is "
442 "not a valid pool property\n"), propname
);
447 * feature@ properties and version should not be specified
450 if ((prop
== ZPOOL_PROP_INVAL
&& zpool_prop_feature(propname
) &&
451 nvlist_exists(proplist
, vname
)) ||
452 (prop
== ZPOOL_PROP_VERSION
&&
453 prop_list_contains_feature(proplist
))) {
454 (void) fprintf(stderr
, gettext("'feature@' and "
455 "'version' properties cannot be specified "
461 if (zpool_prop_feature(propname
))
464 normnm
= zpool_prop_to_name(prop
);
466 if ((fprop
= zfs_name_to_prop(propname
)) != ZPROP_INVAL
) {
467 normnm
= zfs_prop_to_name(fprop
);
473 if (nvlist_lookup_string(proplist
, normnm
, &strval
) == 0 &&
474 prop
!= ZPOOL_PROP_CACHEFILE
) {
475 (void) fprintf(stderr
, gettext("property '%s' "
476 "specified multiple times\n"), propname
);
480 if (nvlist_add_string(proplist
, normnm
, propval
) != 0) {
481 (void) fprintf(stderr
, gettext("internal "
482 "error: out of memory\n"));
490 * zpool add [-fn] <pool> <vdev> ...
492 * -f Force addition of devices, even if they appear in use
493 * -n Do not add the devices, but display the resulting layout if
494 * they were to be added.
496 * Adds the given vdevs to 'pool'. As with create, the bulk of this work is
497 * handled by get_vdev_spec(), which constructs the nvlist needed to pass to
501 zpool_do_add(int argc
, char **argv
)
503 boolean_t force
= B_FALSE
;
504 boolean_t dryrun
= B_FALSE
;
508 zpool_boot_label_t boot_type
;
515 while ((c
= getopt(argc
, argv
, "fn")) != -1) {
524 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
533 /* get pool name and check number of arguments */
535 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
539 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
548 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
551 if ((config
= zpool_get_config(zhp
, NULL
)) == NULL
) {
552 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
558 if (zpool_is_bootable(zhp
))
559 boot_type
= ZPOOL_COPY_BOOT_LABEL
;
561 boot_type
= ZPOOL_NO_BOOT_LABEL
;
563 /* pass off to get_vdev_spec for processing */
564 boot_size
= zpool_get_prop_int(zhp
, ZPOOL_PROP_BOOTSIZE
, NULL
);
565 nvroot
= make_root_vdev(zhp
, force
, !force
, B_FALSE
, dryrun
,
566 boot_type
, boot_size
, argc
, argv
);
567 if (nvroot
== NULL
) {
573 nvlist_t
*poolnvroot
;
575 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
578 (void) printf(gettext("would update '%s' to the following "
579 "configuration:\n"), zpool_get_name(zhp
));
581 /* print original main pool and new tree */
582 print_vdev_tree(zhp
, poolname
, poolnvroot
, 0, B_FALSE
);
583 print_vdev_tree(zhp
, NULL
, nvroot
, 0, B_FALSE
);
585 /* Do the same for the logs */
586 if (num_logs(poolnvroot
) > 0) {
587 print_vdev_tree(zhp
, "logs", poolnvroot
, 0, B_TRUE
);
588 print_vdev_tree(zhp
, NULL
, nvroot
, 0, B_TRUE
);
589 } else if (num_logs(nvroot
) > 0) {
590 print_vdev_tree(zhp
, "logs", nvroot
, 0, B_TRUE
);
595 ret
= (zpool_add(zhp
, nvroot
) != 0);
605 * zpool remove <pool> <vdev> ...
607 * Removes the given vdev from the pool.
610 zpool_do_remove(int argc
, char **argv
)
615 boolean_t stop
= B_FALSE
;
616 boolean_t noop
= B_FALSE
;
617 boolean_t parsable
= B_FALSE
;
621 while ((c
= getopt(argc
, argv
, "nps")) != -1) {
633 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
642 /* get pool name and check number of arguments */
644 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
650 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
654 (void) fprintf(stderr
, gettext("stop request ignored\n"));
660 (void) fprintf(stderr
, gettext("too many arguments\n"));
663 if (zpool_vdev_remove_cancel(zhp
) != 0)
667 (void) fprintf(stderr
, gettext("missing device\n"));
671 for (i
= 1; i
< argc
; i
++) {
675 if (zpool_vdev_indirect_size(zhp
, argv
[i
],
681 (void) printf("%s %llu\n",
685 zfs_nicenum(size
, valstr
,
687 (void) printf("Memory that will be "
688 "used after removing %s: %s\n",
692 if (zpool_vdev_remove(zhp
, argv
[i
]) != 0)
702 * zpool labelclear [-f] <vdev>
704 * -f Force clearing the label for the vdevs which are members of
705 * the exported or foreign pools.
707 * Verifies that the vdev is not active and zeros out the label information
711 zpool_do_labelclear(int argc
, char **argv
)
713 char vdev
[MAXPATHLEN
];
719 boolean_t inuse
= B_FALSE
;
720 boolean_t force
= B_FALSE
;
723 while ((c
= getopt(argc
, argv
, "f")) != -1) {
729 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
740 (void) fprintf(stderr
, gettext("missing vdev name\n"));
744 (void) fprintf(stderr
, gettext("too many arguments\n"));
749 * Check if we were given absolute path and use it as is.
750 * Otherwise if the provided vdev name doesn't point to a file,
751 * try prepending dsk path and appending s0.
753 (void) strlcpy(vdev
, argv
[0], sizeof (vdev
));
754 if (vdev
[0] != '/' && stat(vdev
, &st
) != 0) {
757 (void) snprintf(vdev
, sizeof (vdev
), "%s/%s",
758 ZFS_DISK_ROOT
, argv
[0]);
759 if ((s
= strrchr(argv
[0], 's')) == NULL
||
761 (void) strlcat(vdev
, "s0", sizeof (vdev
));
762 if (stat(vdev
, &st
) != 0) {
763 (void) fprintf(stderr
, gettext(
764 "failed to find device %s, try specifying absolute "
765 "path instead\n"), argv
[0]);
770 if ((fd
= open(vdev
, O_RDWR
)) < 0) {
771 (void) fprintf(stderr
, gettext("failed to open %s: %s\n"),
772 vdev
, strerror(errno
));
776 if (zpool_read_label(fd
, &config
) != 0) {
777 (void) fprintf(stderr
,
778 gettext("failed to read label from %s\n"), vdev
);
783 ret
= zpool_in_use(g_zfs
, fd
, &state
, &name
, &inuse
);
785 (void) fprintf(stderr
,
786 gettext("failed to check state for %s\n"), vdev
);
795 case POOL_STATE_ACTIVE
:
796 case POOL_STATE_SPARE
:
797 case POOL_STATE_L2CACHE
:
798 (void) fprintf(stderr
, gettext(
799 "%s is a member (%s) of pool \"%s\"\n"),
800 vdev
, zpool_pool_state_to_name(state
), name
);
804 case POOL_STATE_EXPORTED
:
807 (void) fprintf(stderr
, gettext(
808 "use '-f' to override the following error:\n"
809 "%s is a member of exported pool \"%s\"\n"),
814 case POOL_STATE_POTENTIALLY_ACTIVE
:
817 (void) fprintf(stderr
, gettext(
818 "use '-f' to override the following error:\n"
819 "%s is a member of potentially active pool \"%s\"\n"),
824 case POOL_STATE_DESTROYED
:
825 /* inuse should never be set for a destroyed pool */
831 ret
= zpool_clear_label(fd
);
833 (void) fprintf(stderr
,
834 gettext("failed to clear label for %s\n"), vdev
);
845 * zpool create [-fnd] [-B] [-o property=value] ...
846 * [-O file-system-property=value] ...
847 * [-R root] [-m mountpoint] <pool> <dev> ...
849 * -B Create boot partition.
850 * -f Force creation, even if devices appear in use
851 * -n Do not create the pool, but display the resulting layout if it
852 * were to be created.
853 * -R Create a pool under an alternate root
854 * -m Set default mountpoint for the root dataset. By default it's
856 * -o Set property=value.
857 * -d Don't automatically enable all supported pool features
858 * (individual features can be enabled with -o).
859 * -O Set fsproperty=value in the pool's root file system
861 * Creates the named pool according to the given vdev specification. The
862 * bulk of the vdev processing is done in get_vdev_spec() in zpool_vdev.c. Once
863 * we get the nvlist back from get_vdev_spec(), we either print out the contents
864 * (if '-n' was specified), or pass it to libzfs to do the creation.
867 #define SYSTEM256 (256 * 1024 * 1024)
869 zpool_do_create(int argc
, char **argv
)
871 boolean_t force
= B_FALSE
;
872 boolean_t dryrun
= B_FALSE
;
873 boolean_t enable_all_pool_feat
= B_TRUE
;
874 zpool_boot_label_t boot_type
= ZPOOL_NO_BOOT_LABEL
;
875 uint64_t boot_size
= 0;
877 nvlist_t
*nvroot
= NULL
;
880 char *altroot
= NULL
;
881 char *mountpoint
= NULL
;
882 nvlist_t
*fsprops
= NULL
;
883 nvlist_t
*props
= NULL
;
887 while ((c
= getopt(argc
, argv
, ":fndBR:m:o:O:")) != -1) {
896 enable_all_pool_feat
= B_FALSE
;
900 * We should create the system partition.
901 * Also make sure the size is set.
903 boot_type
= ZPOOL_CREATE_BOOT_LABEL
;
905 boot_size
= SYSTEM256
;
909 if (add_prop_list(zpool_prop_to_name(
910 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
912 if (nvlist_lookup_string(props
,
913 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
),
916 if (add_prop_list(zpool_prop_to_name(
917 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
921 /* Equivalent to -O mountpoint=optarg */
925 if ((propval
= strchr(optarg
, '=')) == NULL
) {
926 (void) fprintf(stderr
, gettext("missing "
927 "'=' for -o option\n"));
933 if (add_prop_list(optarg
, propval
, &props
, B_TRUE
))
937 * Get bootsize value for make_root_vdev().
939 if (zpool_name_to_prop(optarg
) == ZPOOL_PROP_BOOTSIZE
) {
940 if (zfs_nicestrtonum(g_zfs
, propval
,
941 &boot_size
) < 0 || boot_size
== 0) {
942 (void) fprintf(stderr
,
943 gettext("bad boot partition size "
944 "'%s': %s\n"), propval
,
945 libzfs_error_description(g_zfs
));
951 * If the user is creating a pool that doesn't support
952 * feature flags, don't enable any features.
954 if (zpool_name_to_prop(optarg
) == ZPOOL_PROP_VERSION
) {
958 ver
= strtoull(propval
, &end
, 10);
960 ver
< SPA_VERSION_FEATURES
) {
961 enable_all_pool_feat
= B_FALSE
;
964 if (zpool_name_to_prop(optarg
) == ZPOOL_PROP_ALTROOT
)
968 if ((propval
= strchr(optarg
, '=')) == NULL
) {
969 (void) fprintf(stderr
, gettext("missing "
970 "'=' for -O option\n"));
977 * Mountpoints are checked and then added later.
978 * Uniquely among properties, they can be specified
979 * more than once, to avoid conflict with -m.
981 if (0 == strcmp(optarg
,
982 zfs_prop_to_name(ZFS_PROP_MOUNTPOINT
))) {
983 mountpoint
= propval
;
984 } else if (add_prop_list(optarg
, propval
, &fsprops
,
990 (void) fprintf(stderr
, gettext("missing argument for "
991 "'%c' option\n"), optopt
);
994 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1003 /* get pool name and check number of arguments */
1005 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
1009 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
1016 * As a special case, check for use of '/' in the name, and direct the
1017 * user to use 'zfs create' instead.
1019 if (strchr(poolname
, '/') != NULL
) {
1020 (void) fprintf(stderr
, gettext("cannot create '%s': invalid "
1021 "character '/' in pool name\n"), poolname
);
1022 (void) fprintf(stderr
, gettext("use 'zfs create' to "
1023 "create a dataset\n"));
1028 * Make sure the bootsize is set when ZPOOL_CREATE_BOOT_LABEL is used,
1029 * and not set otherwise.
1031 if (boot_type
== ZPOOL_CREATE_BOOT_LABEL
) {
1032 const char *propname
;
1033 char *strptr
, *buf
= NULL
;
1036 propname
= zpool_prop_to_name(ZPOOL_PROP_BOOTSIZE
);
1037 if (nvlist_lookup_string(props
, propname
, &strptr
) != 0) {
1038 (void) asprintf(&buf
, "%" PRIu64
, boot_size
);
1040 (void) fprintf(stderr
,
1041 gettext("internal error: out of memory\n"));
1044 rv
= add_prop_list(propname
, buf
, &props
, B_TRUE
);
1050 const char *propname
;
1053 propname
= zpool_prop_to_name(ZPOOL_PROP_BOOTSIZE
);
1054 if (nvlist_lookup_string(props
, propname
, &strptr
) == 0) {
1055 (void) fprintf(stderr
, gettext("error: setting boot "
1056 "partition size requires option '-B'\n"));
1061 /* pass off to get_vdev_spec for bulk processing */
1062 nvroot
= make_root_vdev(NULL
, force
, !force
, B_FALSE
, dryrun
,
1063 boot_type
, boot_size
, argc
- 1, argv
+ 1);
1067 /* make_root_vdev() allows 0 toplevel children if there are spares */
1068 if (!zfs_allocatable_devs(nvroot
)) {
1069 (void) fprintf(stderr
, gettext("invalid vdev "
1070 "specification: at least one toplevel vdev must be "
1075 if (altroot
!= NULL
&& altroot
[0] != '/') {
1076 (void) fprintf(stderr
, gettext("invalid alternate root '%s': "
1077 "must be an absolute path\n"), altroot
);
1082 * Check the validity of the mountpoint and direct the user to use the
1083 * '-m' mountpoint option if it looks like its in use.
1085 if (mountpoint
== NULL
||
1086 (strcmp(mountpoint
, ZFS_MOUNTPOINT_LEGACY
) != 0 &&
1087 strcmp(mountpoint
, ZFS_MOUNTPOINT_NONE
) != 0)) {
1088 char buf
[MAXPATHLEN
];
1091 if (mountpoint
&& mountpoint
[0] != '/') {
1092 (void) fprintf(stderr
, gettext("invalid mountpoint "
1093 "'%s': must be an absolute path, 'legacy', or "
1094 "'none'\n"), mountpoint
);
1098 if (mountpoint
== NULL
) {
1099 if (altroot
!= NULL
)
1100 (void) snprintf(buf
, sizeof (buf
), "%s/%s",
1103 (void) snprintf(buf
, sizeof (buf
), "/%s",
1106 if (altroot
!= NULL
)
1107 (void) snprintf(buf
, sizeof (buf
), "%s%s",
1108 altroot
, mountpoint
);
1110 (void) snprintf(buf
, sizeof (buf
), "%s",
1114 if ((dirp
= opendir(buf
)) == NULL
&& errno
!= ENOENT
) {
1115 (void) fprintf(stderr
, gettext("mountpoint '%s' : "
1116 "%s\n"), buf
, strerror(errno
));
1117 (void) fprintf(stderr
, gettext("use '-m' "
1118 "option to provide a different default\n"));
1123 while (count
< 3 && readdir(dirp
) != NULL
)
1125 (void) closedir(dirp
);
1128 (void) fprintf(stderr
, gettext("mountpoint "
1129 "'%s' exists and is not empty\n"), buf
);
1130 (void) fprintf(stderr
, gettext("use '-m' "
1131 "option to provide a "
1132 "different default\n"));
1139 * Now that the mountpoint's validity has been checked, ensure that
1140 * the property is set appropriately prior to creating the pool.
1142 if (mountpoint
!= NULL
) {
1143 ret
= add_prop_list(zfs_prop_to_name(ZFS_PROP_MOUNTPOINT
),
1144 mountpoint
, &fsprops
, B_FALSE
);
1152 * For a dry run invocation, print out a basic message and run
1153 * through all the vdevs in the list and print out in an
1154 * appropriate hierarchy.
1156 (void) printf(gettext("would create '%s' with the "
1157 "following layout:\n\n"), poolname
);
1159 print_vdev_tree(NULL
, poolname
, nvroot
, 0, B_FALSE
);
1160 if (num_logs(nvroot
) > 0)
1161 print_vdev_tree(NULL
, "logs", nvroot
, 0, B_TRUE
);
1166 * Hand off to libzfs.
1168 if (enable_all_pool_feat
) {
1170 for (i
= 0; i
< SPA_FEATURES
; i
++) {
1171 char propname
[MAXPATHLEN
];
1172 zfeature_info_t
*feat
= &spa_feature_table
[i
];
1174 (void) snprintf(propname
, sizeof (propname
),
1175 "feature@%s", feat
->fi_uname
);
1178 * Skip feature if user specified it manually
1179 * on the command line.
1181 if (nvlist_exists(props
, propname
))
1184 ret
= add_prop_list(propname
,
1185 ZFS_FEATURE_ENABLED
, &props
, B_TRUE
);
1192 if (zpool_create(g_zfs
, poolname
,
1193 nvroot
, props
, fsprops
) == 0) {
1194 zfs_handle_t
*pool
= zfs_open(g_zfs
, poolname
,
1195 ZFS_TYPE_FILESYSTEM
);
1197 if (zfs_mount(pool
, NULL
, 0) == 0)
1198 ret
= zfs_shareall(pool
);
1201 } else if (libzfs_errno(g_zfs
) == EZFS_INVALIDNAME
) {
1202 (void) fprintf(stderr
, gettext("pool name may have "
1208 nvlist_free(nvroot
);
1209 nvlist_free(fsprops
);
1213 nvlist_free(fsprops
);
1220 * zpool destroy <pool>
1222 * -f Forcefully unmount any datasets
1224 * Destroy the given pool. Automatically unmounts any datasets in the pool.
1227 zpool_do_destroy(int argc
, char **argv
)
1229 boolean_t force
= B_FALSE
;
1232 zpool_handle_t
*zhp
;
1236 while ((c
= getopt(argc
, argv
, "f")) != -1) {
1242 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1251 /* check arguments */
1253 (void) fprintf(stderr
, gettext("missing pool argument\n"));
1257 (void) fprintf(stderr
, gettext("too many arguments\n"));
1263 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
) {
1265 * As a special case, check for use of '/' in the name, and
1266 * direct the user to use 'zfs destroy' instead.
1268 if (strchr(pool
, '/') != NULL
)
1269 (void) fprintf(stderr
, gettext("use 'zfs destroy' to "
1270 "destroy a dataset\n"));
1274 if (zpool_disable_datasets(zhp
, force
) != 0) {
1275 (void) fprintf(stderr
, gettext("could not destroy '%s': "
1276 "could not unmount datasets\n"), zpool_get_name(zhp
));
1280 /* The history must be logged as part of the export */
1281 log_history
= B_FALSE
;
1283 ret
= (zpool_destroy(zhp
, history_str
) != 0);
1291 * zpool export [-f] <pool> ...
1293 * -f Forcefully unmount datasets
1295 * Export the given pools. By default, the command will attempt to cleanly
1296 * unmount any active datasets within the pool. If the '-f' flag is specified,
1297 * then the datasets will be forcefully unmounted.
1300 zpool_do_export(int argc
, char **argv
)
1302 boolean_t force
= B_FALSE
;
1303 boolean_t hardforce
= B_FALSE
;
1305 zpool_handle_t
*zhp
;
1310 while ((c
= getopt(argc
, argv
, "fF")) != -1) {
1319 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1328 /* check arguments */
1330 (void) fprintf(stderr
, gettext("missing pool argument\n"));
1335 for (i
= 0; i
< argc
; i
++) {
1336 if ((zhp
= zpool_open_canfail(g_zfs
, argv
[i
])) == NULL
) {
1341 if (zpool_disable_datasets(zhp
, force
) != 0) {
1347 /* The history must be logged as part of the export */
1348 log_history
= B_FALSE
;
1351 if (zpool_export_force(zhp
, history_str
) != 0)
1353 } else if (zpool_export(zhp
, force
, history_str
) != 0) {
1364 * Given a vdev configuration, determine the maximum width needed for the device
1368 max_width(zpool_handle_t
*zhp
, nvlist_t
*nv
, int depth
, int max
)
1370 char *name
= zpool_vdev_name(g_zfs
, zhp
, nv
, B_TRUE
);
1375 if (strlen(name
) + depth
> max
)
1376 max
= strlen(name
) + depth
;
1380 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
1381 &child
, &children
) == 0) {
1382 for (c
= 0; c
< children
; c
++)
1383 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1388 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
1389 &child
, &children
) == 0) {
1390 for (c
= 0; c
< children
; c
++)
1391 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1396 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1397 &child
, &children
) == 0) {
1398 for (c
= 0; c
< children
; c
++)
1399 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1408 typedef struct spare_cbdata
{
1410 zpool_handle_t
*cb_zhp
;
1414 find_vdev(nvlist_t
*nv
, uint64_t search
)
1420 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
, &guid
) == 0 &&
1424 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1425 &child
, &children
) == 0) {
1426 for (c
= 0; c
< children
; c
++)
1427 if (find_vdev(child
[c
], search
))
1435 find_spare(zpool_handle_t
*zhp
, void *data
)
1437 spare_cbdata_t
*cbp
= data
;
1438 nvlist_t
*config
, *nvroot
;
1440 config
= zpool_get_config(zhp
, NULL
);
1441 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
1444 if (find_vdev(nvroot
, cbp
->cb_guid
)) {
1454 * Print out configuration state as requested by status_callback.
1457 print_status_config(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
,
1458 int namewidth
, int depth
, boolean_t isspare
)
1462 pool_scan_stat_t
*ps
= NULL
;
1464 char rbuf
[6], wbuf
[6], cbuf
[6];
1466 uint64_t notpresent
;
1471 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1472 &child
, &children
) != 0)
1475 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
1476 (uint64_t **)&vs
, &c
) == 0);
1478 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_TYPE
, &type
) == 0);
1480 if (strcmp(type
, VDEV_TYPE_INDIRECT
) == 0)
1483 state
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
1486 * For hot spares, we use the terms 'INUSE' and 'AVAILABLE' for
1489 if (vs
->vs_aux
== VDEV_AUX_SPARED
)
1491 else if (vs
->vs_state
== VDEV_STATE_HEALTHY
)
1495 (void) printf("\t%*s%-*s %-8s", depth
, "", namewidth
- depth
,
1499 zfs_nicenum(vs
->vs_read_errors
, rbuf
, sizeof (rbuf
));
1500 zfs_nicenum(vs
->vs_write_errors
, wbuf
, sizeof (wbuf
));
1501 zfs_nicenum(vs
->vs_checksum_errors
, cbuf
, sizeof (cbuf
));
1502 (void) printf(" %5s %5s %5s", rbuf
, wbuf
, cbuf
);
1505 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_NOT_PRESENT
,
1506 ¬present
) == 0) {
1508 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_PATH
, &path
) == 0);
1509 (void) printf(" was %s", path
);
1510 } else if (vs
->vs_aux
!= 0) {
1513 switch (vs
->vs_aux
) {
1514 case VDEV_AUX_OPEN_FAILED
:
1515 (void) printf(gettext("cannot open"));
1518 case VDEV_AUX_BAD_GUID_SUM
:
1519 (void) printf(gettext("missing device"));
1522 case VDEV_AUX_NO_REPLICAS
:
1523 (void) printf(gettext("insufficient replicas"));
1526 case VDEV_AUX_VERSION_NEWER
:
1527 (void) printf(gettext("newer version"));
1530 case VDEV_AUX_UNSUP_FEAT
:
1531 (void) printf(gettext("unsupported feature(s)"));
1534 case VDEV_AUX_SPARED
:
1535 verify(nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
,
1537 if (zpool_iter(g_zfs
, find_spare
, &cb
) == 1) {
1538 if (strcmp(zpool_get_name(cb
.cb_zhp
),
1539 zpool_get_name(zhp
)) == 0)
1540 (void) printf(gettext("currently in "
1543 (void) printf(gettext("in use by "
1545 zpool_get_name(cb
.cb_zhp
));
1546 zpool_close(cb
.cb_zhp
);
1548 (void) printf(gettext("currently in use"));
1552 case VDEV_AUX_ERR_EXCEEDED
:
1553 (void) printf(gettext("too many errors"));
1556 case VDEV_AUX_IO_FAILURE
:
1557 (void) printf(gettext("experienced I/O failures"));
1560 case VDEV_AUX_BAD_LOG
:
1561 (void) printf(gettext("bad intent log"));
1564 case VDEV_AUX_EXTERNAL
:
1565 (void) printf(gettext("external device fault"));
1568 case VDEV_AUX_SPLIT_POOL
:
1569 (void) printf(gettext("split into new pool"));
1572 case VDEV_AUX_CHILDREN_OFFLINE
:
1573 (void) printf(gettext("all children offline"));
1577 (void) printf(gettext("corrupted data"));
1582 (void) nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_SCAN_STATS
,
1583 (uint64_t **)&ps
, &c
);
1585 if (ps
&& ps
->pss_state
== DSS_SCANNING
&&
1586 vs
->vs_scan_processed
!= 0 && children
== 0) {
1587 (void) printf(gettext(" (%s)"),
1588 (ps
->pss_func
== POOL_SCAN_RESILVER
) ?
1589 "resilvering" : "repairing");
1592 (void) printf("\n");
1594 for (c
= 0; c
< children
; c
++) {
1595 uint64_t islog
= B_FALSE
, ishole
= B_FALSE
;
1597 /* Don't print logs or holes here */
1598 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1600 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_HOLE
,
1602 if (islog
|| ishole
)
1604 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], B_TRUE
);
1605 print_status_config(zhp
, vname
, child
[c
],
1606 namewidth
, depth
+ 2, isspare
);
1613 * Print the configuration of an exported pool. Iterate over all vdevs in the
1614 * pool, printing out the name and status for each one.
1617 print_import_config(const char *name
, nvlist_t
*nv
, int namewidth
, int depth
)
1624 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_TYPE
, &type
) == 0);
1625 if (strcmp(type
, VDEV_TYPE_MISSING
) == 0 ||
1626 strcmp(type
, VDEV_TYPE_HOLE
) == 0)
1629 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
1630 (uint64_t **)&vs
, &c
) == 0);
1632 (void) printf("\t%*s%-*s", depth
, "", namewidth
- depth
, name
);
1633 (void) printf(" %s", zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
));
1635 if (vs
->vs_aux
!= 0) {
1638 switch (vs
->vs_aux
) {
1639 case VDEV_AUX_OPEN_FAILED
:
1640 (void) printf(gettext("cannot open"));
1643 case VDEV_AUX_BAD_GUID_SUM
:
1644 (void) printf(gettext("missing device"));
1647 case VDEV_AUX_NO_REPLICAS
:
1648 (void) printf(gettext("insufficient replicas"));
1651 case VDEV_AUX_VERSION_NEWER
:
1652 (void) printf(gettext("newer version"));
1655 case VDEV_AUX_UNSUP_FEAT
:
1656 (void) printf(gettext("unsupported feature(s)"));
1659 case VDEV_AUX_ERR_EXCEEDED
:
1660 (void) printf(gettext("too many errors"));
1663 case VDEV_AUX_CHILDREN_OFFLINE
:
1664 (void) printf(gettext("all children offline"));
1668 (void) printf(gettext("corrupted data"));
1672 (void) printf("\n");
1674 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1675 &child
, &children
) != 0)
1678 for (c
= 0; c
< children
; c
++) {
1679 uint64_t is_log
= B_FALSE
;
1681 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1686 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
], B_TRUE
);
1687 print_import_config(vname
, child
[c
], namewidth
, depth
+ 2);
1691 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
1692 &child
, &children
) == 0) {
1693 (void) printf(gettext("\tcache\n"));
1694 for (c
= 0; c
< children
; c
++) {
1695 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
], B_FALSE
);
1696 (void) printf("\t %s\n", vname
);
1701 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
1702 &child
, &children
) == 0) {
1703 (void) printf(gettext("\tspares\n"));
1704 for (c
= 0; c
< children
; c
++) {
1705 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
], B_FALSE
);
1706 (void) printf("\t %s\n", vname
);
1714 * Logs are recorded as top level vdevs in the main pool child array
1715 * but with "is_log" set to 1. We use either print_status_config() or
1716 * print_import_config() to print the top level logs then any log
1717 * children (eg mirrored slogs) are printed recursively - which
1718 * works because only the top level vdev is marked "is_log"
1721 print_logs(zpool_handle_t
*zhp
, nvlist_t
*nv
, int namewidth
, boolean_t verbose
)
1726 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
, &child
,
1730 (void) printf(gettext("\tlogs\n"));
1732 for (c
= 0; c
< children
; c
++) {
1733 uint64_t is_log
= B_FALSE
;
1736 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1740 name
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], B_TRUE
);
1742 print_status_config(zhp
, name
, child
[c
], namewidth
,
1745 print_import_config(name
, child
[c
], namewidth
, 2);
1751 * Display the status for the given pool.
1754 show_import(nvlist_t
*config
)
1756 uint64_t pool_state
;
1768 verify(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
1770 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
,
1772 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
1774 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
1777 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_VDEV_STATS
,
1778 (uint64_t **)&vs
, &vsc
) == 0);
1779 health
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
1781 reason
= zpool_import_status(config
, &msgid
);
1783 (void) printf(gettext(" pool: %s\n"), name
);
1784 (void) printf(gettext(" id: %llu\n"), (u_longlong_t
)guid
);
1785 (void) printf(gettext(" state: %s"), health
);
1786 if (pool_state
== POOL_STATE_DESTROYED
)
1787 (void) printf(gettext(" (DESTROYED)"));
1788 (void) printf("\n");
1791 case ZPOOL_STATUS_MISSING_DEV_R
:
1792 case ZPOOL_STATUS_MISSING_DEV_NR
:
1793 case ZPOOL_STATUS_BAD_GUID_SUM
:
1794 (void) printf(gettext(" status: One or more devices are "
1795 "missing from the system.\n"));
1798 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
1799 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
1800 (void) printf(gettext(" status: One or more devices contains "
1801 "corrupted data.\n"));
1804 case ZPOOL_STATUS_CORRUPT_DATA
:
1806 gettext(" status: The pool data is corrupted.\n"));
1809 case ZPOOL_STATUS_OFFLINE_DEV
:
1810 (void) printf(gettext(" status: One or more devices "
1811 "are offlined.\n"));
1814 case ZPOOL_STATUS_CORRUPT_POOL
:
1815 (void) printf(gettext(" status: The pool metadata is "
1819 case ZPOOL_STATUS_VERSION_OLDER
:
1820 (void) printf(gettext(" status: The pool is formatted using a "
1821 "legacy on-disk version.\n"));
1824 case ZPOOL_STATUS_VERSION_NEWER
:
1825 (void) printf(gettext(" status: The pool is formatted using an "
1826 "incompatible version.\n"));
1829 case ZPOOL_STATUS_FEAT_DISABLED
:
1830 (void) printf(gettext(" status: Some supported features are "
1831 "not enabled on the pool.\n"));
1834 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
1835 (void) printf(gettext("status: The pool uses the following "
1836 "feature(s) not supported on this system:\n"));
1837 zpool_print_unsup_feat(config
);
1840 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
1841 (void) printf(gettext("status: The pool can only be accessed "
1842 "in read-only mode on this system. It\n\tcannot be "
1843 "accessed in read-write mode because it uses the "
1844 "following\n\tfeature(s) not supported on this system:\n"));
1845 zpool_print_unsup_feat(config
);
1848 case ZPOOL_STATUS_HOSTID_MISMATCH
:
1849 (void) printf(gettext(" status: The pool was last accessed by "
1850 "another system.\n"));
1853 case ZPOOL_STATUS_FAULTED_DEV_R
:
1854 case ZPOOL_STATUS_FAULTED_DEV_NR
:
1855 (void) printf(gettext(" status: One or more devices are "
1859 case ZPOOL_STATUS_BAD_LOG
:
1860 (void) printf(gettext(" status: An intent log record cannot be "
1864 case ZPOOL_STATUS_RESILVERING
:
1865 (void) printf(gettext(" status: One or more devices were being "
1871 * No other status can be seen when importing pools.
1873 assert(reason
== ZPOOL_STATUS_OK
);
1877 * Print out an action according to the overall state of the pool.
1879 if (vs
->vs_state
== VDEV_STATE_HEALTHY
) {
1880 if (reason
== ZPOOL_STATUS_VERSION_OLDER
||
1881 reason
== ZPOOL_STATUS_FEAT_DISABLED
) {
1882 (void) printf(gettext(" action: The pool can be "
1883 "imported using its name or numeric identifier, "
1884 "though\n\tsome features will not be available "
1885 "without an explicit 'zpool upgrade'.\n"));
1886 } else if (reason
== ZPOOL_STATUS_HOSTID_MISMATCH
) {
1887 (void) printf(gettext(" action: The pool can be "
1888 "imported using its name or numeric "
1889 "identifier and\n\tthe '-f' flag.\n"));
1891 (void) printf(gettext(" action: The pool can be "
1892 "imported using its name or numeric "
1895 } else if (vs
->vs_state
== VDEV_STATE_DEGRADED
) {
1896 (void) printf(gettext(" action: The pool can be imported "
1897 "despite missing or damaged devices. The\n\tfault "
1898 "tolerance of the pool may be compromised if imported.\n"));
1901 case ZPOOL_STATUS_VERSION_NEWER
:
1902 (void) printf(gettext(" action: The pool cannot be "
1903 "imported. Access the pool on a system running "
1904 "newer\n\tsoftware, or recreate the pool from "
1907 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
1908 (void) printf(gettext("action: The pool cannot be "
1909 "imported. Access the pool on a system that "
1910 "supports\n\tthe required feature(s), or recreate "
1911 "the pool from backup.\n"));
1913 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
1914 (void) printf(gettext("action: The pool cannot be "
1915 "imported in read-write mode. Import the pool "
1917 "\t\"-o readonly=on\", access the pool on a system "
1918 "that supports the\n\trequired feature(s), or "
1919 "recreate the pool from backup.\n"));
1921 case ZPOOL_STATUS_MISSING_DEV_R
:
1922 case ZPOOL_STATUS_MISSING_DEV_NR
:
1923 case ZPOOL_STATUS_BAD_GUID_SUM
:
1924 (void) printf(gettext(" action: The pool cannot be "
1925 "imported. Attach the missing\n\tdevices and try "
1929 (void) printf(gettext(" action: The pool cannot be "
1930 "imported due to damaged devices or data.\n"));
1934 /* Print the comment attached to the pool. */
1935 if (nvlist_lookup_string(config
, ZPOOL_CONFIG_COMMENT
, &comment
) == 0)
1936 (void) printf(gettext("comment: %s\n"), comment
);
1939 * If the state is "closed" or "can't open", and the aux state
1940 * is "corrupt data":
1942 if (((vs
->vs_state
== VDEV_STATE_CLOSED
) ||
1943 (vs
->vs_state
== VDEV_STATE_CANT_OPEN
)) &&
1944 (vs
->vs_aux
== VDEV_AUX_CORRUPT_DATA
)) {
1945 if (pool_state
== POOL_STATE_DESTROYED
)
1946 (void) printf(gettext("\tThe pool was destroyed, "
1947 "but can be imported using the '-Df' flags.\n"));
1948 else if (pool_state
!= POOL_STATE_EXPORTED
)
1949 (void) printf(gettext("\tThe pool may be active on "
1950 "another system, but can be imported using\n\t"
1951 "the '-f' flag.\n"));
1955 (void) printf(gettext(" see: http://illumos.org/msg/%s\n"),
1958 (void) printf(gettext(" config:\n\n"));
1960 namewidth
= max_width(NULL
, nvroot
, 0, 0);
1964 print_import_config(name
, nvroot
, namewidth
, 0);
1965 if (num_logs(nvroot
) > 0)
1966 print_logs(NULL
, nvroot
, namewidth
, B_FALSE
);
1968 if (reason
== ZPOOL_STATUS_BAD_GUID_SUM
) {
1969 (void) printf(gettext("\n\tAdditional devices are known to "
1970 "be part of this pool, though their\n\texact "
1971 "configuration cannot be determined.\n"));
1976 * Perform the import for the given configuration. This passes the heavy
1977 * lifting off to zpool_import_props(), and then mounts the datasets contained
1981 do_import(nvlist_t
*config
, const char *newname
, const char *mntopts
,
1982 nvlist_t
*props
, int flags
)
1984 zpool_handle_t
*zhp
;
1989 verify(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
1992 verify(nvlist_lookup_uint64(config
,
1993 ZPOOL_CONFIG_POOL_STATE
, &state
) == 0);
1994 verify(nvlist_lookup_uint64(config
,
1995 ZPOOL_CONFIG_VERSION
, &version
) == 0);
1996 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
1997 (void) fprintf(stderr
, gettext("cannot import '%s': pool "
1998 "is formatted using an unsupported ZFS version\n"), name
);
2000 } else if (state
!= POOL_STATE_EXPORTED
&&
2001 !(flags
& ZFS_IMPORT_ANY_HOST
)) {
2004 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_HOSTID
,
2006 if ((unsigned long)hostid
!= gethostid()) {
2011 verify(nvlist_lookup_string(config
,
2012 ZPOOL_CONFIG_HOSTNAME
, &hostname
) == 0);
2013 verify(nvlist_lookup_uint64(config
,
2014 ZPOOL_CONFIG_TIMESTAMP
, ×tamp
) == 0);
2016 (void) fprintf(stderr
, gettext("cannot import "
2017 "'%s': pool may be in use from other "
2018 "system, it was last accessed by %s "
2019 "(hostid: 0x%lx) on %s"), name
, hostname
,
2020 (unsigned long)hostid
,
2021 asctime(localtime(&t
)));
2022 (void) fprintf(stderr
, gettext("use '-f' to "
2023 "import anyway\n"));
2027 (void) fprintf(stderr
, gettext("cannot import '%s': "
2028 "pool may be in use from other system\n"), name
);
2029 (void) fprintf(stderr
, gettext("use '-f' to import "
2035 if (zpool_import_props(g_zfs
, config
, newname
, props
, flags
) != 0)
2038 if (newname
!= NULL
)
2039 name
= (char *)newname
;
2041 if ((zhp
= zpool_open_canfail(g_zfs
, name
)) == NULL
)
2044 if (zpool_get_state(zhp
) != POOL_STATE_UNAVAIL
&&
2045 !(flags
& ZFS_IMPORT_ONLY
) &&
2046 zpool_enable_datasets(zhp
, mntopts
, 0) != 0) {
2056 * zpool checkpoint <pool>
2057 * checkpoint --discard <pool>
2059 * -d Discard the checkpoint from a checkpointed
2062 * Checkpoints the specified pool, by taking a "snapshot" of its
2063 * current state. A pool can only have one checkpoint at a time.
2066 zpool_do_checkpoint(int argc
, char **argv
)
2070 zpool_handle_t
*zhp
;
2073 struct option long_options
[] = {
2074 {"discard", no_argument
, NULL
, 'd'},
2079 while ((c
= getopt_long(argc
, argv
, ":d", long_options
, NULL
)) != -1) {
2085 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2095 (void) fprintf(stderr
, gettext("missing pool argument\n"));
2100 (void) fprintf(stderr
, gettext("too many arguments\n"));
2106 if ((zhp
= zpool_open(g_zfs
, pool
)) == NULL
) {
2107 /* As a special case, check for use of '/' in the name */
2108 if (strchr(pool
, '/') != NULL
)
2109 (void) fprintf(stderr
, gettext("'zpool checkpoint' "
2110 "doesn't work on datasets. To save the state "
2111 "of a dataset from a specific point in time "
2112 "please use 'zfs snapshot'\n"));
2117 err
= (zpool_discard_checkpoint(zhp
) != 0);
2119 err
= (zpool_checkpoint(zhp
) != 0);
2126 #define CHECKPOINT_OPT 1024
2129 * zpool import [-d dir] [-D]
2130 * import [-o mntopts] [-o prop=value] ... [-R root] [-D]
2131 * [-d dir | -c cachefile] [-f] -a
2132 * import [-o mntopts] [-o prop=value] ... [-R root] [-D]
2133 * [-d dir | -c cachefile] [-f] [-n] [-F] <pool | id> [newpool]
2135 * -c Read pool information from a cachefile instead of searching
2138 * -d Scan in a specific directory, other than /dev/dsk. More than
2139 * one directory can be specified using multiple '-d' options.
2141 * -D Scan for previously destroyed pools or import all or only
2142 * specified destroyed pools.
2144 * -R Temporarily import the pool, with all mountpoints relative to
2145 * the given root. The pool will remain exported when the machine
2148 * -V Import even in the presence of faulted vdevs. This is an
2149 * intentionally undocumented option for testing purposes, and
2150 * treats the pool configuration as complete, leaving any bad
2151 * vdevs in the FAULTED state. In other words, it does verbatim
2154 * -f Force import, even if it appears that the pool is active.
2156 * -F Attempt rewind if necessary.
2158 * -n See if rewind would work, but don't actually rewind.
2160 * -N Import the pool but don't mount datasets.
2162 * -T Specify a starting txg to use for import. This option is
2163 * intentionally undocumented option for testing purposes.
2165 * -a Import all pools found.
2167 * -o Set property=value and/or temporary mount options (without '=').
2169 * --rewind-to-checkpoint
2170 * Import the pool and revert back to the checkpoint.
2172 * The import command scans for pools to import, and import pools based on pool
2173 * name and GUID. The pool can also be renamed as part of the import process.
2176 zpool_do_import(int argc
, char **argv
)
2178 char **searchdirs
= NULL
;
2182 nvlist_t
*pools
= NULL
;
2183 boolean_t do_all
= B_FALSE
;
2184 boolean_t do_destroyed
= B_FALSE
;
2185 char *mntopts
= NULL
;
2188 uint64_t searchguid
= 0;
2189 char *searchname
= NULL
;
2191 nvlist_t
*found_config
;
2192 nvlist_t
*policy
= NULL
;
2193 nvlist_t
*props
= NULL
;
2195 int flags
= ZFS_IMPORT_NORMAL
;
2196 uint32_t rewind_policy
= ZPOOL_NO_REWIND
;
2197 boolean_t dryrun
= B_FALSE
;
2198 boolean_t do_rewind
= B_FALSE
;
2199 boolean_t xtreme_rewind
= B_FALSE
;
2200 uint64_t pool_state
, txg
= -1ULL;
2201 char *cachefile
= NULL
;
2202 importargs_t idata
= { 0 };
2206 struct option long_options
[] = {
2207 {"rewind-to-checkpoint", no_argument
, NULL
, CHECKPOINT_OPT
},
2212 while ((c
= getopt_long(argc
, argv
, ":aCc:d:DEfFmnNo:rR:T:VX",
2213 long_options
, NULL
)) != -1) {
2222 if (searchdirs
== NULL
) {
2223 searchdirs
= safe_malloc(sizeof (char *));
2225 char **tmp
= safe_malloc((nsearch
+ 1) *
2227 bcopy(searchdirs
, tmp
, nsearch
*
2232 searchdirs
[nsearch
++] = optarg
;
2235 do_destroyed
= B_TRUE
;
2238 flags
|= ZFS_IMPORT_ANY_HOST
;
2244 flags
|= ZFS_IMPORT_MISSING_LOG
;
2250 flags
|= ZFS_IMPORT_ONLY
;
2253 if ((propval
= strchr(optarg
, '=')) != NULL
) {
2256 if (add_prop_list(optarg
, propval
,
2264 if (add_prop_list(zpool_prop_to_name(
2265 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
2267 if (nvlist_lookup_string(props
,
2268 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
),
2271 if (add_prop_list(zpool_prop_to_name(
2272 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
2277 txg
= strtoull(optarg
, &endptr
, 0);
2278 if (errno
!= 0 || *endptr
!= '\0') {
2279 (void) fprintf(stderr
,
2280 gettext("invalid txg value\n"));
2283 rewind_policy
= ZPOOL_DO_REWIND
| ZPOOL_EXTREME_REWIND
;
2286 flags
|= ZFS_IMPORT_VERBATIM
;
2289 xtreme_rewind
= B_TRUE
;
2291 case CHECKPOINT_OPT
:
2292 flags
|= ZFS_IMPORT_CHECKPOINT
;
2295 (void) fprintf(stderr
, gettext("missing argument for "
2296 "'%c' option\n"), optopt
);
2300 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2309 if (cachefile
&& nsearch
!= 0) {
2310 (void) fprintf(stderr
, gettext("-c is incompatible with -d\n"));
2314 if ((dryrun
|| xtreme_rewind
) && !do_rewind
) {
2315 (void) fprintf(stderr
,
2316 gettext("-n or -X only meaningful with -F\n"));
2320 rewind_policy
= ZPOOL_TRY_REWIND
;
2322 rewind_policy
= ZPOOL_DO_REWIND
;
2324 rewind_policy
|= ZPOOL_EXTREME_REWIND
;
2326 /* In the future, we can capture further policy and include it here */
2327 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME
, 0) != 0 ||
2328 nvlist_add_uint64(policy
, ZPOOL_REWIND_REQUEST_TXG
, txg
) != 0 ||
2329 nvlist_add_uint32(policy
, ZPOOL_REWIND_REQUEST
, rewind_policy
) != 0)
2332 if (searchdirs
== NULL
) {
2333 searchdirs
= safe_malloc(sizeof (char *));
2334 searchdirs
[0] = ZFS_DISK_ROOT
;
2338 /* check argument count */
2341 (void) fprintf(stderr
, gettext("too many arguments\n"));
2346 (void) fprintf(stderr
, gettext("too many arguments\n"));
2351 * Check for the SYS_CONFIG privilege. We do this explicitly
2352 * here because otherwise any attempt to discover pools will
2355 if (argc
== 0 && !priv_ineffect(PRIV_SYS_CONFIG
)) {
2356 (void) fprintf(stderr
, gettext("cannot "
2357 "discover pools: permission denied\n"));
2359 nvlist_free(policy
);
2365 * Depending on the arguments given, we do one of the following:
2367 * <none> Iterate through all pools and display information about
2370 * -a Iterate through all pools and try to import each one.
2372 * <id> Find the pool that corresponds to the given GUID/pool
2373 * name and import that one.
2375 * -D Above options applies only to destroyed pools.
2381 searchguid
= strtoull(argv
[0], &endptr
, 10);
2382 if (errno
!= 0 || *endptr
!= '\0') {
2383 searchname
= argv
[0];
2386 found_config
= NULL
;
2389 * User specified a name or guid. Ensure it's unique.
2391 idata
.unique
= B_TRUE
;
2395 idata
.path
= searchdirs
;
2396 idata
.paths
= nsearch
;
2397 idata
.poolname
= searchname
;
2398 idata
.guid
= searchguid
;
2399 idata
.cachefile
= cachefile
;
2400 idata
.policy
= policy
;
2402 pools
= zpool_search_import(g_zfs
, &idata
);
2404 if (pools
!= NULL
&& idata
.exists
&&
2405 (argc
== 1 || strcmp(argv
[0], argv
[1]) == 0)) {
2406 (void) fprintf(stderr
, gettext("cannot import '%s': "
2407 "a pool with that name already exists\n"),
2409 (void) fprintf(stderr
, gettext("use the form '%s "
2410 "<pool | id> <newpool>' to give it a new name\n"),
2413 } else if (pools
== NULL
&& idata
.exists
) {
2414 (void) fprintf(stderr
, gettext("cannot import '%s': "
2415 "a pool with that name is already created/imported,\n"),
2417 (void) fprintf(stderr
, gettext("and no additional pools "
2418 "with that name were found\n"));
2420 } else if (pools
== NULL
) {
2422 (void) fprintf(stderr
, gettext("cannot import '%s': "
2423 "no such pool available\n"), argv
[0]);
2430 nvlist_free(policy
);
2435 * At this point we have a list of import candidate configs. Even if
2436 * we were searching by pool name or guid, we still need to
2437 * post-process the list to deal with pool state and possible
2443 while ((elem
= nvlist_next_nvpair(pools
, elem
)) != NULL
) {
2445 verify(nvpair_value_nvlist(elem
, &config
) == 0);
2447 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
2449 if (!do_destroyed
&& pool_state
== POOL_STATE_DESTROYED
)
2451 if (do_destroyed
&& pool_state
!= POOL_STATE_DESTROYED
)
2454 verify(nvlist_add_nvlist(config
, ZPOOL_REWIND_POLICY
,
2461 (void) printf("\n");
2464 err
|= do_import(config
, NULL
, mntopts
,
2467 show_import(config
);
2469 } else if (searchname
!= NULL
) {
2473 * We are searching for a pool based on name.
2475 verify(nvlist_lookup_string(config
,
2476 ZPOOL_CONFIG_POOL_NAME
, &name
) == 0);
2478 if (strcmp(name
, searchname
) == 0) {
2479 if (found_config
!= NULL
) {
2480 (void) fprintf(stderr
, gettext(
2481 "cannot import '%s': more than "
2482 "one matching pool\n"), searchname
);
2483 (void) fprintf(stderr
, gettext(
2484 "import by numeric ID instead\n"));
2487 found_config
= config
;
2493 * Search for a pool by guid.
2495 verify(nvlist_lookup_uint64(config
,
2496 ZPOOL_CONFIG_POOL_GUID
, &guid
) == 0);
2498 if (guid
== searchguid
)
2499 found_config
= config
;
2504 * If we were searching for a specific pool, verify that we found a
2505 * pool, and then do the import.
2507 if (argc
!= 0 && err
== 0) {
2508 if (found_config
== NULL
) {
2509 (void) fprintf(stderr
, gettext("cannot import '%s': "
2510 "no such pool available\n"), argv
[0]);
2513 err
|= do_import(found_config
, argc
== 1 ? NULL
:
2514 argv
[1], mntopts
, props
, flags
);
2519 * If we were just looking for pools, report an error if none were
2522 if (argc
== 0 && first
)
2523 (void) fprintf(stderr
,
2524 gettext("no pools available to import\n"));
2529 nvlist_free(policy
);
2532 return (err
? 1 : 0);
2535 typedef struct iostat_cbdata
{
2536 boolean_t cb_verbose
;
2539 zpool_list_t
*cb_list
;
2543 print_iostat_separator(iostat_cbdata_t
*cb
)
2547 for (i
= 0; i
< cb
->cb_namewidth
; i
++)
2549 (void) printf(" ----- ----- ----- ----- ----- -----\n");
2553 print_iostat_header(iostat_cbdata_t
*cb
)
2555 (void) printf("%*s capacity operations bandwidth\n",
2556 cb
->cb_namewidth
, "");
2557 (void) printf("%-*s alloc free read write read write\n",
2558 cb
->cb_namewidth
, "pool");
2559 print_iostat_separator(cb
);
2563 * Display a single statistic.
2566 print_one_stat(uint64_t value
)
2570 zfs_nicenum(value
, buf
, sizeof (buf
));
2571 (void) printf(" %5s", buf
);
2575 * Print out all the statistics for the given vdev. This can either be the
2576 * toplevel configuration, or called recursively. If 'name' is NULL, then this
2577 * is a verbose output, and we don't want to display the toplevel pool stats.
2580 print_vdev_stats(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*oldnv
,
2581 nvlist_t
*newnv
, iostat_cbdata_t
*cb
, int depth
)
2583 nvlist_t
**oldchild
, **newchild
;
2585 vdev_stat_t
*oldvs
, *newvs
;
2586 vdev_stat_t zerovs
= { 0 };
2591 if (strcmp(name
, VDEV_TYPE_INDIRECT
) == 0)
2594 if (oldnv
!= NULL
) {
2595 verify(nvlist_lookup_uint64_array(oldnv
,
2596 ZPOOL_CONFIG_VDEV_STATS
, (uint64_t **)&oldvs
, &c
) == 0);
2601 verify(nvlist_lookup_uint64_array(newnv
, ZPOOL_CONFIG_VDEV_STATS
,
2602 (uint64_t **)&newvs
, &c
) == 0);
2604 if (strlen(name
) + depth
> cb
->cb_namewidth
)
2605 (void) printf("%*s%s", depth
, "", name
);
2607 (void) printf("%*s%s%*s", depth
, "", name
,
2608 (int)(cb
->cb_namewidth
- strlen(name
) - depth
), "");
2610 tdelta
= newvs
->vs_timestamp
- oldvs
->vs_timestamp
;
2615 scale
= (double)NANOSEC
/ tdelta
;
2617 /* only toplevel vdevs have capacity stats */
2618 if (newvs
->vs_space
== 0) {
2619 (void) printf(" - -");
2621 print_one_stat(newvs
->vs_alloc
);
2622 print_one_stat(newvs
->vs_space
- newvs
->vs_alloc
);
2625 print_one_stat((uint64_t)(scale
* (newvs
->vs_ops
[ZIO_TYPE_READ
] -
2626 oldvs
->vs_ops
[ZIO_TYPE_READ
])));
2628 print_one_stat((uint64_t)(scale
* (newvs
->vs_ops
[ZIO_TYPE_WRITE
] -
2629 oldvs
->vs_ops
[ZIO_TYPE_WRITE
])));
2631 print_one_stat((uint64_t)(scale
* (newvs
->vs_bytes
[ZIO_TYPE_READ
] -
2632 oldvs
->vs_bytes
[ZIO_TYPE_READ
])));
2634 print_one_stat((uint64_t)(scale
* (newvs
->vs_bytes
[ZIO_TYPE_WRITE
] -
2635 oldvs
->vs_bytes
[ZIO_TYPE_WRITE
])));
2637 (void) printf("\n");
2639 if (!cb
->cb_verbose
)
2642 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_CHILDREN
,
2643 &newchild
, &children
) != 0)
2646 if (oldnv
&& nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_CHILDREN
,
2647 &oldchild
, &c
) != 0)
2650 for (c
= 0; c
< children
; c
++) {
2651 uint64_t ishole
= B_FALSE
, islog
= B_FALSE
;
2653 (void) nvlist_lookup_uint64(newchild
[c
], ZPOOL_CONFIG_IS_HOLE
,
2656 (void) nvlist_lookup_uint64(newchild
[c
], ZPOOL_CONFIG_IS_LOG
,
2659 if (ishole
|| islog
)
2662 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
], B_FALSE
);
2663 print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
] : NULL
,
2664 newchild
[c
], cb
, depth
+ 2);
2669 * Log device section
2672 if (num_logs(newnv
) > 0) {
2673 (void) printf("%-*s - - - - - "
2674 "-\n", cb
->cb_namewidth
, "logs");
2676 for (c
= 0; c
< children
; c
++) {
2677 uint64_t islog
= B_FALSE
;
2678 (void) nvlist_lookup_uint64(newchild
[c
],
2679 ZPOOL_CONFIG_IS_LOG
, &islog
);
2682 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
2684 print_vdev_stats(zhp
, vname
, oldnv
?
2685 oldchild
[c
] : NULL
, newchild
[c
],
2694 * Include level 2 ARC devices in iostat output
2696 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_L2CACHE
,
2697 &newchild
, &children
) != 0)
2700 if (oldnv
&& nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_L2CACHE
,
2701 &oldchild
, &c
) != 0)
2705 (void) printf("%-*s - - - - - "
2706 "-\n", cb
->cb_namewidth
, "cache");
2707 for (c
= 0; c
< children
; c
++) {
2708 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
2710 print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
] : NULL
,
2711 newchild
[c
], cb
, depth
+ 2);
2718 refresh_iostat(zpool_handle_t
*zhp
, void *data
)
2720 iostat_cbdata_t
*cb
= data
;
2724 * If the pool has disappeared, remove it from the list and continue.
2726 if (zpool_refresh_stats(zhp
, &missing
) != 0)
2730 pool_list_remove(cb
->cb_list
, zhp
);
2736 * Callback to print out the iostats for the given pool.
2739 print_iostat(zpool_handle_t
*zhp
, void *data
)
2741 iostat_cbdata_t
*cb
= data
;
2742 nvlist_t
*oldconfig
, *newconfig
;
2743 nvlist_t
*oldnvroot
, *newnvroot
;
2745 newconfig
= zpool_get_config(zhp
, &oldconfig
);
2747 if (cb
->cb_iteration
== 1)
2750 verify(nvlist_lookup_nvlist(newconfig
, ZPOOL_CONFIG_VDEV_TREE
,
2753 if (oldconfig
== NULL
)
2756 verify(nvlist_lookup_nvlist(oldconfig
, ZPOOL_CONFIG_VDEV_TREE
,
2760 * Print out the statistics for the pool.
2762 print_vdev_stats(zhp
, zpool_get_name(zhp
), oldnvroot
, newnvroot
, cb
, 0);
2765 print_iostat_separator(cb
);
2771 get_namewidth(zpool_handle_t
*zhp
, void *data
)
2773 iostat_cbdata_t
*cb
= data
;
2774 nvlist_t
*config
, *nvroot
;
2776 if ((config
= zpool_get_config(zhp
, NULL
)) != NULL
) {
2777 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
2779 if (!cb
->cb_verbose
)
2780 cb
->cb_namewidth
= strlen(zpool_get_name(zhp
));
2782 cb
->cb_namewidth
= max_width(zhp
, nvroot
, 0,
2787 * The width must fall into the range [10,38]. The upper limit is the
2788 * maximum we can have and still fit in 80 columns.
2790 if (cb
->cb_namewidth
< 10)
2791 cb
->cb_namewidth
= 10;
2792 if (cb
->cb_namewidth
> 38)
2793 cb
->cb_namewidth
= 38;
2799 * Parse the input string, get the 'interval' and 'count' value if there is one.
2802 get_interval_count(int *argcp
, char **argv
, unsigned long *iv
,
2805 unsigned long interval
= 0, count
= 0;
2806 int argc
= *argcp
, errno
;
2809 * Determine if the last argument is an integer or a pool name
2811 if (argc
> 0 && isdigit(argv
[argc
- 1][0])) {
2815 interval
= strtoul(argv
[argc
- 1], &end
, 10);
2817 if (*end
== '\0' && errno
== 0) {
2818 if (interval
== 0) {
2819 (void) fprintf(stderr
, gettext("interval "
2820 "cannot be zero\n"));
2824 * Ignore the last parameter
2829 * If this is not a valid number, just plow on. The
2830 * user will get a more informative error message later
2838 * If the last argument is also an integer, then we have both a count
2841 if (argc
> 0 && isdigit(argv
[argc
- 1][0])) {
2846 interval
= strtoul(argv
[argc
- 1], &end
, 10);
2848 if (*end
== '\0' && errno
== 0) {
2849 if (interval
== 0) {
2850 (void) fprintf(stderr
, gettext("interval "
2851 "cannot be zero\n"));
2856 * Ignore the last parameter
2870 get_timestamp_arg(char c
)
2873 timestamp_fmt
= UDATE
;
2875 timestamp_fmt
= DDATE
;
2881 * zpool iostat [-v] [-T d|u] [pool] ... [interval [count]]
2883 * -v Display statistics for individual vdevs
2884 * -T Display a timestamp in date(1) or Unix format
2886 * This command can be tricky because we want to be able to deal with pool
2887 * creation/destruction as well as vdev configuration changes. The bulk of this
2888 * processing is handled by the pool_list_* routines in zpool_iter.c. We rely
2889 * on pool_list_update() to detect the addition of new pools. Configuration
2890 * changes are all handled within libzfs.
2893 zpool_do_iostat(int argc
, char **argv
)
2898 unsigned long interval
= 0, count
= 0;
2900 boolean_t verbose
= B_FALSE
;
2904 while ((c
= getopt(argc
, argv
, "T:v")) != -1) {
2907 get_timestamp_arg(*optarg
);
2913 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2922 get_interval_count(&argc
, argv
, &interval
, &count
);
2925 * Construct the list of all interesting pools.
2928 if ((list
= pool_list_get(argc
, argv
, NULL
, &ret
)) == NULL
)
2931 if (pool_list_count(list
) == 0 && argc
!= 0) {
2932 pool_list_free(list
);
2936 if (pool_list_count(list
) == 0 && interval
== 0) {
2937 pool_list_free(list
);
2938 (void) fprintf(stderr
, gettext("no pools available\n"));
2943 * Enter the main iostat loop.
2946 cb
.cb_verbose
= verbose
;
2947 cb
.cb_iteration
= 0;
2948 cb
.cb_namewidth
= 0;
2951 pool_list_update(list
);
2953 if ((npools
= pool_list_count(list
)) == 0)
2957 * Refresh all statistics. This is done as an explicit step
2958 * before calculating the maximum name width, so that any
2959 * configuration changes are properly accounted for.
2961 (void) pool_list_iter(list
, B_FALSE
, refresh_iostat
, &cb
);
2964 * Iterate over all pools to determine the maximum width
2965 * for the pool / device name column across all pools.
2967 cb
.cb_namewidth
= 0;
2968 (void) pool_list_iter(list
, B_FALSE
, get_namewidth
, &cb
);
2970 if (timestamp_fmt
!= NODATE
)
2971 print_timestamp(timestamp_fmt
);
2974 * If it's the first time, or verbose mode, print the header.
2976 if (++cb
.cb_iteration
== 1 || verbose
)
2977 print_iostat_header(&cb
);
2979 (void) pool_list_iter(list
, B_FALSE
, print_iostat
, &cb
);
2982 * If there's more than one pool, and we're not in verbose mode
2983 * (which prints a separator for us), then print a separator.
2985 if (npools
> 1 && !verbose
)
2986 print_iostat_separator(&cb
);
2989 (void) printf("\n");
2992 * Flush the output so that redirection to a file isn't buffered
2995 (void) fflush(stdout
);
3000 if (count
!= 0 && --count
== 0)
3003 (void) sleep(interval
);
3006 pool_list_free(list
);
3011 typedef struct list_cbdata
{
3012 boolean_t cb_verbose
;
3014 boolean_t cb_scripted
;
3015 zprop_list_t
*cb_proplist
;
3016 boolean_t cb_literal
;
3020 * Given a list of columns to display, output appropriate headers for each one.
3023 print_header(list_cbdata_t
*cb
)
3025 zprop_list_t
*pl
= cb
->cb_proplist
;
3026 char headerbuf
[ZPOOL_MAXPROPLEN
];
3028 boolean_t first
= B_TRUE
;
3029 boolean_t right_justify
;
3032 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
3033 width
= pl
->pl_width
;
3034 if (first
&& cb
->cb_verbose
) {
3036 * Reset the width to accommodate the verbose listing
3039 width
= cb
->cb_namewidth
;
3047 right_justify
= B_FALSE
;
3048 if (pl
->pl_prop
!= ZPROP_INVAL
) {
3049 header
= zpool_prop_column_name(pl
->pl_prop
);
3050 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
3054 for (i
= 0; pl
->pl_user_prop
[i
] != '\0'; i
++)
3055 headerbuf
[i
] = toupper(pl
->pl_user_prop
[i
]);
3056 headerbuf
[i
] = '\0';
3060 if (pl
->pl_next
== NULL
&& !right_justify
)
3061 (void) printf("%s", header
);
3062 else if (right_justify
)
3063 (void) printf("%*s", width
, header
);
3065 (void) printf("%-*s", width
, header
);
3069 (void) printf("\n");
3073 * Given a pool and a list of properties, print out all the properties according
3074 * to the described layout.
3077 print_pool(zpool_handle_t
*zhp
, list_cbdata_t
*cb
)
3079 zprop_list_t
*pl
= cb
->cb_proplist
;
3080 boolean_t first
= B_TRUE
;
3081 char property
[ZPOOL_MAXPROPLEN
];
3083 boolean_t right_justify
;
3086 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
3088 width
= pl
->pl_width
;
3089 if (first
&& cb
->cb_verbose
) {
3091 * Reset the width to accommodate the verbose listing
3094 width
= cb
->cb_namewidth
;
3098 if (cb
->cb_scripted
)
3099 (void) printf("\t");
3106 right_justify
= B_FALSE
;
3107 if (pl
->pl_prop
!= ZPROP_INVAL
) {
3108 if (zpool_get_prop(zhp
, pl
->pl_prop
, property
,
3109 sizeof (property
), NULL
, cb
->cb_literal
) != 0)
3114 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
3115 } else if ((zpool_prop_feature(pl
->pl_user_prop
) ||
3116 zpool_prop_unsupported(pl
->pl_user_prop
)) &&
3117 zpool_prop_get_feature(zhp
, pl
->pl_user_prop
, property
,
3118 sizeof (property
)) == 0) {
3126 * If this is being called in scripted mode, or if this is the
3127 * last column and it is left-justified, don't include a width
3130 if (cb
->cb_scripted
|| (pl
->pl_next
== NULL
&& !right_justify
))
3131 (void) printf("%s", propstr
);
3132 else if (right_justify
)
3133 (void) printf("%*s", width
, propstr
);
3135 (void) printf("%-*s", width
, propstr
);
3138 (void) printf("\n");
3142 print_one_column(zpool_prop_t prop
, uint64_t value
, boolean_t scripted
,
3147 size_t width
= zprop_width(prop
, &fixed
, ZFS_TYPE_POOL
);
3150 case ZPOOL_PROP_EXPANDSZ
:
3151 case ZPOOL_PROP_CHECKPOINT
:
3153 (void) strlcpy(propval
, "-", sizeof (propval
));
3155 zfs_nicenum(value
, propval
, sizeof (propval
));
3157 case ZPOOL_PROP_FRAGMENTATION
:
3158 if (value
== ZFS_FRAG_INVALID
) {
3159 (void) strlcpy(propval
, "-", sizeof (propval
));
3161 (void) snprintf(propval
, sizeof (propval
), "%llu%%",
3165 case ZPOOL_PROP_CAPACITY
:
3166 (void) snprintf(propval
, sizeof (propval
), "%llu%%", value
);
3169 zfs_nicenum(value
, propval
, sizeof (propval
));
3173 (void) strlcpy(propval
, "-", sizeof (propval
));
3176 (void) printf("\t%s", propval
);
3178 (void) printf(" %*s", width
, propval
);
3182 print_list_stats(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
,
3183 list_cbdata_t
*cb
, int depth
)
3189 boolean_t scripted
= cb
->cb_scripted
;
3190 uint64_t islog
= B_FALSE
;
3191 boolean_t haslog
= B_FALSE
;
3192 char *dashes
= "%-*s - - - - - -\n";
3194 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
3195 (uint64_t **)&vs
, &c
) == 0);
3198 boolean_t toplevel
= (vs
->vs_space
!= 0);
3201 if (strcmp(name
, VDEV_TYPE_INDIRECT
) == 0)
3205 (void) printf("\t%s", name
);
3206 else if (strlen(name
) + depth
> cb
->cb_namewidth
)
3207 (void) printf("%*s%s", depth
, "", name
);
3209 (void) printf("%*s%s%*s", depth
, "", name
,
3210 (int)(cb
->cb_namewidth
- strlen(name
) - depth
), "");
3213 * Print the properties for the individual vdevs. Some
3214 * properties are only applicable to toplevel vdevs. The
3215 * 'toplevel' boolean value is passed to the print_one_column()
3216 * to indicate that the value is valid.
3218 print_one_column(ZPOOL_PROP_SIZE
, vs
->vs_space
, scripted
,
3220 print_one_column(ZPOOL_PROP_ALLOCATED
, vs
->vs_alloc
, scripted
,
3222 print_one_column(ZPOOL_PROP_FREE
, vs
->vs_space
- vs
->vs_alloc
,
3223 scripted
, toplevel
);
3224 print_one_column(ZPOOL_PROP_CHECKPOINT
,
3225 vs
->vs_checkpoint_space
, scripted
, toplevel
);
3226 print_one_column(ZPOOL_PROP_EXPANDSZ
, vs
->vs_esize
, scripted
,
3228 print_one_column(ZPOOL_PROP_FRAGMENTATION
,
3229 vs
->vs_fragmentation
, scripted
,
3230 (vs
->vs_fragmentation
!= ZFS_FRAG_INVALID
&& toplevel
));
3231 cap
= (vs
->vs_space
== 0) ? 0 :
3232 (vs
->vs_alloc
* 100 / vs
->vs_space
);
3233 print_one_column(ZPOOL_PROP_CAPACITY
, cap
, scripted
, toplevel
);
3234 (void) printf("\n");
3237 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
3238 &child
, &children
) != 0)
3241 for (c
= 0; c
< children
; c
++) {
3242 uint64_t ishole
= B_FALSE
;
3244 if (nvlist_lookup_uint64(child
[c
],
3245 ZPOOL_CONFIG_IS_HOLE
, &ishole
) == 0 && ishole
)
3248 if (nvlist_lookup_uint64(child
[c
],
3249 ZPOOL_CONFIG_IS_LOG
, &islog
) == 0 && islog
) {
3254 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], B_FALSE
);
3255 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
3259 if (haslog
== B_TRUE
) {
3260 /* LINTED E_SEC_PRINTF_VAR_FMT */
3261 (void) printf(dashes
, cb
->cb_namewidth
, "log");
3262 for (c
= 0; c
< children
; c
++) {
3263 if (nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
3264 &islog
) != 0 || !islog
)
3266 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], B_FALSE
);
3267 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
3272 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
3273 &child
, &children
) == 0 && children
> 0) {
3274 /* LINTED E_SEC_PRINTF_VAR_FMT */
3275 (void) printf(dashes
, cb
->cb_namewidth
, "cache");
3276 for (c
= 0; c
< children
; c
++) {
3277 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], B_FALSE
);
3278 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
3283 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
, &child
,
3284 &children
) == 0 && children
> 0) {
3285 /* LINTED E_SEC_PRINTF_VAR_FMT */
3286 (void) printf(dashes
, cb
->cb_namewidth
, "spare");
3287 for (c
= 0; c
< children
; c
++) {
3288 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], B_FALSE
);
3289 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
3297 * Generic callback function to list a pool.
3300 list_callback(zpool_handle_t
*zhp
, void *data
)
3302 list_cbdata_t
*cbp
= data
;
3306 config
= zpool_get_config(zhp
, NULL
);
3308 print_pool(zhp
, cbp
);
3309 if (!cbp
->cb_verbose
)
3312 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
3314 print_list_stats(zhp
, NULL
, nvroot
, cbp
, 0);
3320 * zpool list [-Hp] [-o prop[,prop]*] [-T d|u] [pool] ... [interval [count]]
3322 * -H Scripted mode. Don't display headers, and separate properties
3324 * -o List of properties to display. Defaults to
3325 * "name,size,allocated,free,expandsize,fragmentation,capacity,"
3326 * "dedupratio,health,altroot"
3327 * -p Diplay values in parsable (exact) format.
3328 * -T Display a timestamp in date(1) or Unix format
3330 * List all pools in the system, whether or not they're healthy. Output space
3331 * statistics for each one, as well as health status summary.
3334 zpool_do_list(int argc
, char **argv
)
3338 list_cbdata_t cb
= { 0 };
3339 static char default_props
[] =
3340 "name,size,allocated,free,checkpoint,expandsize,fragmentation,"
3341 "capacity,dedupratio,health,altroot";
3342 char *props
= default_props
;
3343 unsigned long interval
= 0, count
= 0;
3345 boolean_t first
= B_TRUE
;
3348 while ((c
= getopt(argc
, argv
, ":Ho:pT:v")) != -1) {
3351 cb
.cb_scripted
= B_TRUE
;
3357 cb
.cb_literal
= B_TRUE
;
3360 get_timestamp_arg(*optarg
);
3363 cb
.cb_verbose
= B_TRUE
;
3366 (void) fprintf(stderr
, gettext("missing argument for "
3367 "'%c' option\n"), optopt
);
3371 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3380 get_interval_count(&argc
, argv
, &interval
, &count
);
3382 if (zprop_get_list(g_zfs
, props
, &cb
.cb_proplist
, ZFS_TYPE_POOL
) != 0)
3386 if ((list
= pool_list_get(argc
, argv
, &cb
.cb_proplist
,
3390 if (pool_list_count(list
) == 0)
3393 cb
.cb_namewidth
= 0;
3394 (void) pool_list_iter(list
, B_FALSE
, get_namewidth
, &cb
);
3396 if (timestamp_fmt
!= NODATE
)
3397 print_timestamp(timestamp_fmt
);
3399 if (!cb
.cb_scripted
&& (first
|| cb
.cb_verbose
)) {
3403 ret
= pool_list_iter(list
, B_TRUE
, list_callback
, &cb
);
3408 if (count
!= 0 && --count
== 0)
3411 pool_list_free(list
);
3412 (void) sleep(interval
);
3415 if (argc
== 0 && !cb
.cb_scripted
&& pool_list_count(list
) == 0) {
3416 (void) printf(gettext("no pools available\n"));
3420 pool_list_free(list
);
3421 zprop_free_list(cb
.cb_proplist
);
3426 zpool_do_attach_or_replace(int argc
, char **argv
, int replacing
)
3428 boolean_t force
= B_FALSE
;
3431 char *poolname
, *old_disk
, *new_disk
;
3432 zpool_handle_t
*zhp
;
3433 zpool_boot_label_t boot_type
;
3438 while ((c
= getopt(argc
, argv
, "f")) != -1) {
3444 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3453 /* get pool name and check number of arguments */
3455 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
3462 (void) fprintf(stderr
,
3463 gettext("missing <device> specification\n"));
3471 (void) fprintf(stderr
,
3472 gettext("missing <new_device> specification\n"));
3475 new_disk
= old_disk
;
3485 (void) fprintf(stderr
, gettext("too many arguments\n"));
3489 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
3492 if (zpool_get_config(zhp
, NULL
) == NULL
) {
3493 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
3499 if (zpool_is_bootable(zhp
))
3500 boot_type
= ZPOOL_COPY_BOOT_LABEL
;
3502 boot_type
= ZPOOL_NO_BOOT_LABEL
;
3504 boot_size
= zpool_get_prop_int(zhp
, ZPOOL_PROP_BOOTSIZE
, NULL
);
3505 nvroot
= make_root_vdev(zhp
, force
, B_FALSE
, replacing
, B_FALSE
,
3506 boot_type
, boot_size
, argc
, argv
);
3507 if (nvroot
== NULL
) {
3512 ret
= zpool_vdev_attach(zhp
, old_disk
, new_disk
, nvroot
, replacing
);
3514 nvlist_free(nvroot
);
3521 * zpool replace [-f] <pool> <device> <new_device>
3523 * -f Force attach, even if <new_device> appears to be in use.
3525 * Replace <device> with <new_device>.
3529 zpool_do_replace(int argc
, char **argv
)
3531 return (zpool_do_attach_or_replace(argc
, argv
, B_TRUE
));
3535 * zpool attach [-f] <pool> <device> <new_device>
3537 * -f Force attach, even if <new_device> appears to be in use.
3539 * Attach <new_device> to the mirror containing <device>. If <device> is not
3540 * part of a mirror, then <device> will be transformed into a mirror of
3541 * <device> and <new_device>. In either case, <new_device> will begin life
3542 * with a DTL of [0, now], and will immediately begin to resilver itself.
3545 zpool_do_attach(int argc
, char **argv
)
3547 return (zpool_do_attach_or_replace(argc
, argv
, B_FALSE
));
3551 * zpool detach [-f] <pool> <device>
3553 * -f Force detach of <device>, even if DTLs argue against it
3554 * (not supported yet)
3556 * Detach a device from a mirror. The operation will be refused if <device>
3557 * is the last device in the mirror, or if the DTLs indicate that this device
3558 * has the only valid copy of some data.
3562 zpool_do_detach(int argc
, char **argv
)
3565 char *poolname
, *path
;
3566 zpool_handle_t
*zhp
;
3570 while ((c
= getopt(argc
, argv
, "f")) != -1) {
3574 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3583 /* get pool name and check number of arguments */
3585 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
3590 (void) fprintf(stderr
,
3591 gettext("missing <device> specification\n"));
3598 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
3601 ret
= zpool_vdev_detach(zhp
, path
);
3609 * zpool split [-n] [-o prop=val] ...
3611 * [-R altroot] <pool> <newpool> [<device> ...]
3613 * -n Do not split the pool, but display the resulting layout if
3614 * it were to be split.
3615 * -o Set property=value, or set mount options.
3616 * -R Mount the split-off pool under an alternate root.
3618 * Splits the named pool and gives it the new pool name. Devices to be split
3619 * off may be listed, provided that no more than one device is specified
3620 * per top-level vdev mirror. The newly split pool is left in an exported
3621 * state unless -R is specified.
3623 * Restrictions: the top-level of the pool pool must only be made up of
3624 * mirrors; all devices in the pool must be healthy; no device may be
3625 * undergoing a resilvering operation.
3628 zpool_do_split(int argc
, char **argv
)
3630 char *srcpool
, *newpool
, *propval
;
3631 char *mntopts
= NULL
;
3634 zpool_handle_t
*zhp
;
3635 nvlist_t
*config
, *props
= NULL
;
3637 flags
.dryrun
= B_FALSE
;
3638 flags
.import
= B_FALSE
;
3641 while ((c
= getopt(argc
, argv
, ":R:no:")) != -1) {
3644 flags
.import
= B_TRUE
;
3646 zpool_prop_to_name(ZPOOL_PROP_ALTROOT
), optarg
,
3647 &props
, B_TRUE
) != 0) {
3653 flags
.dryrun
= B_TRUE
;
3656 if ((propval
= strchr(optarg
, '=')) != NULL
) {
3659 if (add_prop_list(optarg
, propval
,
3660 &props
, B_TRUE
) != 0) {
3669 (void) fprintf(stderr
, gettext("missing argument for "
3670 "'%c' option\n"), optopt
);
3674 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3681 if (!flags
.import
&& mntopts
!= NULL
) {
3682 (void) fprintf(stderr
, gettext("setting mntopts is only "
3683 "valid when importing the pool\n"));
3691 (void) fprintf(stderr
, gettext("Missing pool name\n"));
3695 (void) fprintf(stderr
, gettext("Missing new pool name\n"));
3705 if ((zhp
= zpool_open(g_zfs
, srcpool
)) == NULL
)
3708 config
= split_mirror_vdev(zhp
, newpool
, props
, flags
, argc
, argv
);
3709 if (config
== NULL
) {
3713 (void) printf(gettext("would create '%s' with the "
3714 "following layout:\n\n"), newpool
);
3715 print_vdev_tree(NULL
, newpool
, config
, 0, B_FALSE
);
3717 nvlist_free(config
);
3722 if (ret
!= 0 || flags
.dryrun
|| !flags
.import
)
3726 * The split was successful. Now we need to open the new
3727 * pool and import it.
3729 if ((zhp
= zpool_open_canfail(g_zfs
, newpool
)) == NULL
)
3731 if (zpool_get_state(zhp
) != POOL_STATE_UNAVAIL
&&
3732 zpool_enable_datasets(zhp
, mntopts
, 0) != 0) {
3734 (void) fprintf(stderr
, gettext("Split was successful, but "
3735 "the datasets could not all be mounted\n"));
3736 (void) fprintf(stderr
, gettext("Try doing '%s' with a "
3737 "different altroot\n"), "zpool import");
3747 * zpool online <pool> <device> ...
3750 zpool_do_online(int argc
, char **argv
)
3754 zpool_handle_t
*zhp
;
3756 vdev_state_t newstate
;
3760 while ((c
= getopt(argc
, argv
, "et")) != -1) {
3763 flags
|= ZFS_ONLINE_EXPAND
;
3767 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3776 /* get pool name and check number of arguments */
3778 (void) fprintf(stderr
, gettext("missing pool name\n"));
3782 (void) fprintf(stderr
, gettext("missing device name\n"));
3788 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
3791 for (i
= 1; i
< argc
; i
++) {
3792 if (zpool_vdev_online(zhp
, argv
[i
], flags
, &newstate
) == 0) {
3793 if (newstate
!= VDEV_STATE_HEALTHY
) {
3794 (void) printf(gettext("warning: device '%s' "
3795 "onlined, but remains in faulted state\n"),
3797 if (newstate
== VDEV_STATE_FAULTED
)
3798 (void) printf(gettext("use 'zpool "
3799 "clear' to restore a faulted "
3802 (void) printf(gettext("use 'zpool "
3803 "replace' to replace devices "
3804 "that are no longer present\n"));
3817 * zpool offline [-ft] <pool> <device> ...
3819 * -f Force the device into the offline state, even if doing
3820 * so would appear to compromise pool availability.
3821 * (not supported yet)
3823 * -t Only take the device off-line temporarily. The offline
3824 * state will not be persistent across reboots.
3828 zpool_do_offline(int argc
, char **argv
)
3832 zpool_handle_t
*zhp
;
3834 boolean_t istmp
= B_FALSE
;
3837 while ((c
= getopt(argc
, argv
, "ft")) != -1) {
3844 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3853 /* get pool name and check number of arguments */
3855 (void) fprintf(stderr
, gettext("missing pool name\n"));
3859 (void) fprintf(stderr
, gettext("missing device name\n"));
3865 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
3868 for (i
= 1; i
< argc
; i
++) {
3869 if (zpool_vdev_offline(zhp
, argv
[i
], istmp
) != 0)
3879 * zpool clear <pool> [device]
3881 * Clear all errors associated with a pool or a particular device.
3884 zpool_do_clear(int argc
, char **argv
)
3888 boolean_t dryrun
= B_FALSE
;
3889 boolean_t do_rewind
= B_FALSE
;
3890 boolean_t xtreme_rewind
= B_FALSE
;
3891 uint32_t rewind_policy
= ZPOOL_NO_REWIND
;
3892 nvlist_t
*policy
= NULL
;
3893 zpool_handle_t
*zhp
;
3894 char *pool
, *device
;
3897 while ((c
= getopt(argc
, argv
, "FnX")) != -1) {
3906 xtreme_rewind
= B_TRUE
;
3909 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3919 (void) fprintf(stderr
, gettext("missing pool name\n"));
3924 (void) fprintf(stderr
, gettext("too many arguments\n"));
3928 if ((dryrun
|| xtreme_rewind
) && !do_rewind
) {
3929 (void) fprintf(stderr
,
3930 gettext("-n or -X only meaningful with -F\n"));
3934 rewind_policy
= ZPOOL_TRY_REWIND
;
3936 rewind_policy
= ZPOOL_DO_REWIND
;
3938 rewind_policy
|= ZPOOL_EXTREME_REWIND
;
3940 /* In future, further rewind policy choices can be passed along here */
3941 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME
, 0) != 0 ||
3942 nvlist_add_uint32(policy
, ZPOOL_REWIND_REQUEST
, rewind_policy
) != 0)
3946 device
= argc
== 2 ? argv
[1] : NULL
;
3948 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
) {
3949 nvlist_free(policy
);
3953 if (zpool_clear(zhp
, device
, policy
) != 0)
3958 nvlist_free(policy
);
3964 * zpool reguid <pool>
3967 zpool_do_reguid(int argc
, char **argv
)
3971 zpool_handle_t
*zhp
;
3975 while ((c
= getopt(argc
, argv
, "")) != -1) {
3978 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3987 /* get pool name and check number of arguments */
3989 (void) fprintf(stderr
, gettext("missing pool name\n"));
3994 (void) fprintf(stderr
, gettext("too many arguments\n"));
3999 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
4002 ret
= zpool_reguid(zhp
);
4010 * zpool reopen <pool>
4012 * Reopen the pool so that the kernel can update the sizes of all vdevs.
4015 zpool_do_reopen(int argc
, char **argv
)
4019 zpool_handle_t
*zhp
;
4023 while ((c
= getopt(argc
, argv
, "")) != -1) {
4026 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4036 (void) fprintf(stderr
, gettext("missing pool name\n"));
4041 (void) fprintf(stderr
, gettext("too many arguments\n"));
4046 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
)
4049 ret
= zpool_reopen(zhp
);
4054 typedef struct scrub_cbdata
{
4058 pool_scrub_cmd_t cb_scrub_cmd
;
4062 zpool_has_checkpoint(zpool_handle_t
*zhp
)
4064 nvlist_t
*config
, *nvroot
;
4066 config
= zpool_get_config(zhp
, NULL
);
4068 if (config
!= NULL
) {
4069 pool_checkpoint_stat_t
*pcs
= NULL
;
4072 nvroot
= fnvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
);
4073 (void) nvlist_lookup_uint64_array(nvroot
,
4074 ZPOOL_CONFIG_CHECKPOINT_STATS
, (uint64_t **)&pcs
, &c
);
4076 if (pcs
== NULL
|| pcs
->pcs_state
== CS_NONE
)
4079 assert(pcs
->pcs_state
== CS_CHECKPOINT_EXISTS
||
4080 pcs
->pcs_state
== CS_CHECKPOINT_DISCARDING
);
4088 scrub_callback(zpool_handle_t
*zhp
, void *data
)
4090 scrub_cbdata_t
*cb
= data
;
4094 * Ignore faulted pools.
4096 if (zpool_get_state(zhp
) == POOL_STATE_UNAVAIL
) {
4097 (void) fprintf(stderr
, gettext("cannot scrub '%s': pool is "
4098 "currently unavailable\n"), zpool_get_name(zhp
));
4102 err
= zpool_scan(zhp
, cb
->cb_type
, cb
->cb_scrub_cmd
);
4104 if (err
== 0 && zpool_has_checkpoint(zhp
) &&
4105 cb
->cb_type
== POOL_SCAN_SCRUB
) {
4106 (void) printf(gettext("warning: will not scrub state that "
4107 "belongs to the checkpoint of pool '%s'\n"),
4108 zpool_get_name(zhp
));
4115 * zpool scrub [-s | -p] <pool> ...
4117 * -s Stop. Stops any in-progress scrub.
4118 * -p Pause. Pause in-progress scrub.
4121 zpool_do_scrub(int argc
, char **argv
)
4126 cb
.cb_type
= POOL_SCAN_SCRUB
;
4127 cb
.cb_scrub_cmd
= POOL_SCRUB_NORMAL
;
4130 while ((c
= getopt(argc
, argv
, "sp")) != -1) {
4133 cb
.cb_type
= POOL_SCAN_NONE
;
4136 cb
.cb_scrub_cmd
= POOL_SCRUB_PAUSE
;
4139 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4145 if (cb
.cb_type
== POOL_SCAN_NONE
&&
4146 cb
.cb_scrub_cmd
== POOL_SCRUB_PAUSE
) {
4147 (void) fprintf(stderr
, gettext("invalid option combination: "
4148 "-s and -p are mutually exclusive\n"));
4158 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
4162 return (for_each_pool(argc
, argv
, B_TRUE
, NULL
, scrub_callback
, &cb
));
4165 typedef struct status_cbdata
{
4167 boolean_t cb_allpools
;
4168 boolean_t cb_verbose
;
4169 boolean_t cb_explain
;
4171 boolean_t cb_dedup_stats
;
4175 * Print out detailed scrub status.
4178 print_scan_status(pool_scan_stat_t
*ps
)
4180 time_t start
, end
, pause
;
4181 uint64_t elapsed
, mins_left
, hours_left
;
4182 uint64_t pass_exam
, examined
, total
;
4184 double fraction_done
;
4185 char processed_buf
[7], examined_buf
[7], total_buf
[7], rate_buf
[7];
4187 (void) printf(gettext(" scan: "));
4189 /* If there's never been a scan, there's not much to say. */
4190 if (ps
== NULL
|| ps
->pss_func
== POOL_SCAN_NONE
||
4191 ps
->pss_func
>= POOL_SCAN_FUNCS
) {
4192 (void) printf(gettext("none requested\n"));
4196 start
= ps
->pss_start_time
;
4197 end
= ps
->pss_end_time
;
4198 pause
= ps
->pss_pass_scrub_pause
;
4199 zfs_nicenum(ps
->pss_processed
, processed_buf
, sizeof (processed_buf
));
4201 assert(ps
->pss_func
== POOL_SCAN_SCRUB
||
4202 ps
->pss_func
== POOL_SCAN_RESILVER
);
4204 * Scan is finished or canceled.
4206 if (ps
->pss_state
== DSS_FINISHED
) {
4207 uint64_t minutes_taken
= (end
- start
) / 60;
4210 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
4211 fmt
= gettext("scrub repaired %s in %lluh%um with "
4212 "%llu errors on %s");
4213 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
4214 fmt
= gettext("resilvered %s in %lluh%um with "
4215 "%llu errors on %s");
4218 (void) printf(fmt
, processed_buf
,
4219 (u_longlong_t
)(minutes_taken
/ 60),
4220 (uint_t
)(minutes_taken
% 60),
4221 (u_longlong_t
)ps
->pss_errors
,
4222 ctime((time_t *)&end
));
4224 } else if (ps
->pss_state
== DSS_CANCELED
) {
4225 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
4226 (void) printf(gettext("scrub canceled on %s"),
4228 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
4229 (void) printf(gettext("resilver canceled on %s"),
4235 assert(ps
->pss_state
== DSS_SCANNING
);
4238 * Scan is in progress.
4240 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
4242 (void) printf(gettext("scrub in progress since %s"),
4246 struct tm
*p
= localtime(&pause
);
4247 (void) strftime(buf
, sizeof (buf
), "%a %b %e %T %Y", p
);
4248 (void) printf(gettext("scrub paused since %s\n"), buf
);
4249 (void) printf(gettext("\tscrub started on %s"),
4252 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
4253 (void) printf(gettext("resilver in progress since %s"),
4257 examined
= ps
->pss_examined
? ps
->pss_examined
: 1;
4258 total
= ps
->pss_to_examine
;
4259 fraction_done
= (double)examined
/ total
;
4261 /* elapsed time for this pass */
4262 elapsed
= time(NULL
) - ps
->pss_pass_start
;
4263 elapsed
-= ps
->pss_pass_scrub_spent_paused
;
4264 elapsed
= elapsed
? elapsed
: 1;
4265 pass_exam
= ps
->pss_pass_exam
? ps
->pss_pass_exam
: 1;
4266 rate
= pass_exam
/ elapsed
;
4267 rate
= rate
? rate
: 1;
4268 mins_left
= ((total
- examined
) / rate
) / 60;
4269 hours_left
= mins_left
/ 60;
4271 zfs_nicenum(examined
, examined_buf
, sizeof (examined_buf
));
4272 zfs_nicenum(total
, total_buf
, sizeof (total_buf
));
4275 * do not print estimated time if hours_left is more than 30 days
4276 * or we have a paused scrub
4279 zfs_nicenum(rate
, rate_buf
, sizeof (rate_buf
));
4280 (void) printf(gettext("\t%s scanned out of %s at %s/s"),
4281 examined_buf
, total_buf
, rate_buf
);
4282 if (hours_left
< (30 * 24)) {
4283 (void) printf(gettext(", %lluh%um to go\n"),
4284 (u_longlong_t
)hours_left
, (uint_t
)(mins_left
% 60));
4286 (void) printf(gettext(
4287 ", (scan is slow, no estimated time)\n"));
4290 (void) printf(gettext("\t%s scanned out of %s\n"),
4291 examined_buf
, total_buf
);
4294 if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
4295 (void) printf(gettext(" %s resilvered, %.2f%% done\n"),
4296 processed_buf
, 100 * fraction_done
);
4297 } else if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
4298 (void) printf(gettext(" %s repaired, %.2f%% done\n"),
4299 processed_buf
, 100 * fraction_done
);
4304 * As we don't scrub checkpointed blocks, we want to warn the
4305 * user that we skipped scanning some blocks if a checkpoint exists
4306 * or existed at any time during the scan.
4309 print_checkpoint_scan_warning(pool_scan_stat_t
*ps
, pool_checkpoint_stat_t
*pcs
)
4311 if (ps
== NULL
|| pcs
== NULL
)
4314 if (pcs
->pcs_state
== CS_NONE
||
4315 pcs
->pcs_state
== CS_CHECKPOINT_DISCARDING
)
4318 assert(pcs
->pcs_state
== CS_CHECKPOINT_EXISTS
);
4320 if (ps
->pss_state
== DSS_NONE
)
4323 if ((ps
->pss_state
== DSS_FINISHED
|| ps
->pss_state
== DSS_CANCELED
) &&
4324 ps
->pss_end_time
< pcs
->pcs_start_time
)
4327 if (ps
->pss_state
== DSS_FINISHED
|| ps
->pss_state
== DSS_CANCELED
) {
4328 (void) printf(gettext(" scan warning: skipped blocks "
4329 "that are only referenced by the checkpoint.\n"));
4331 assert(ps
->pss_state
== DSS_SCANNING
);
4332 (void) printf(gettext(" scan warning: skipping blocks "
4333 "that are only referenced by the checkpoint.\n"));
4338 * Print out detailed removal status.
4341 print_removal_status(zpool_handle_t
*zhp
, pool_removal_stat_t
*prs
)
4343 char copied_buf
[7], examined_buf
[7], total_buf
[7], rate_buf
[7];
4345 nvlist_t
*config
, *nvroot
;
4350 if (prs
== NULL
|| prs
->prs_state
== DSS_NONE
)
4354 * Determine name of vdev.
4356 config
= zpool_get_config(zhp
, NULL
);
4357 nvroot
= fnvlist_lookup_nvlist(config
,
4358 ZPOOL_CONFIG_VDEV_TREE
);
4359 verify(nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_CHILDREN
,
4360 &child
, &children
) == 0);
4361 assert(prs
->prs_removing_vdev
< children
);
4362 vdev_name
= zpool_vdev_name(g_zfs
, zhp
,
4363 child
[prs
->prs_removing_vdev
], B_TRUE
);
4365 (void) printf(gettext("remove: "));
4367 start
= prs
->prs_start_time
;
4368 end
= prs
->prs_end_time
;
4369 zfs_nicenum(prs
->prs_copied
, copied_buf
, sizeof (copied_buf
));
4372 * Removal is finished or canceled.
4374 if (prs
->prs_state
== DSS_FINISHED
) {
4375 uint64_t minutes_taken
= (end
- start
) / 60;
4377 (void) printf(gettext("Removal of vdev %llu copied %s "
4378 "in %lluh%um, completed on %s"),
4379 (longlong_t
)prs
->prs_removing_vdev
,
4381 (u_longlong_t
)(minutes_taken
/ 60),
4382 (uint_t
)(minutes_taken
% 60),
4383 ctime((time_t *)&end
));
4384 } else if (prs
->prs_state
== DSS_CANCELED
) {
4385 (void) printf(gettext("Removal of %s canceled on %s"),
4386 vdev_name
, ctime(&end
));
4388 uint64_t copied
, total
, elapsed
, mins_left
, hours_left
;
4389 double fraction_done
;
4392 assert(prs
->prs_state
== DSS_SCANNING
);
4395 * Removal is in progress.
4397 (void) printf(gettext(
4398 "Evacuation of %s in progress since %s"),
4399 vdev_name
, ctime(&start
));
4401 copied
= prs
->prs_copied
> 0 ? prs
->prs_copied
: 1;
4402 total
= prs
->prs_to_copy
;
4403 fraction_done
= (double)copied
/ total
;
4405 /* elapsed time for this pass */
4406 elapsed
= time(NULL
) - prs
->prs_start_time
;
4407 elapsed
= elapsed
> 0 ? elapsed
: 1;
4408 rate
= copied
/ elapsed
;
4409 rate
= rate
> 0 ? rate
: 1;
4410 mins_left
= ((total
- copied
) / rate
) / 60;
4411 hours_left
= mins_left
/ 60;
4413 zfs_nicenum(copied
, examined_buf
, sizeof (examined_buf
));
4414 zfs_nicenum(total
, total_buf
, sizeof (total_buf
));
4415 zfs_nicenum(rate
, rate_buf
, sizeof (rate_buf
));
4418 * do not print estimated time if hours_left is more than
4421 (void) printf(gettext(" %s copied out of %s at %s/s, "
4423 examined_buf
, total_buf
, rate_buf
, 100 * fraction_done
);
4424 if (hours_left
< (30 * 24)) {
4425 (void) printf(gettext(", %lluh%um to go\n"),
4426 (u_longlong_t
)hours_left
, (uint_t
)(mins_left
% 60));
4428 (void) printf(gettext(
4429 ", (copy is slow, no estimated time)\n"));
4433 if (prs
->prs_mapping_memory
> 0) {
4435 zfs_nicenum(prs
->prs_mapping_memory
, mem_buf
, sizeof (mem_buf
));
4436 (void) printf(gettext(" %s memory used for "
4437 "removed device mappings\n"),
4443 print_checkpoint_status(pool_checkpoint_stat_t
*pcs
)
4448 if (pcs
== NULL
|| pcs
->pcs_state
== CS_NONE
)
4451 (void) printf(gettext("checkpoint: "));
4453 start
= pcs
->pcs_start_time
;
4454 zfs_nicenum(pcs
->pcs_space
, space_buf
, sizeof (space_buf
));
4456 if (pcs
->pcs_state
== CS_CHECKPOINT_EXISTS
) {
4457 char *date
= ctime(&start
);
4460 * ctime() adds a newline at the end of the generated
4461 * string, thus the weird format specifier and the
4462 * strlen() call used to chop it off from the output.
4464 (void) printf(gettext("created %.*s, consumes %s\n"),
4465 strlen(date
) - 1, date
, space_buf
);
4469 assert(pcs
->pcs_state
== CS_CHECKPOINT_DISCARDING
);
4471 (void) printf(gettext("discarding, %s remaining.\n"),
4476 print_error_log(zpool_handle_t
*zhp
)
4478 nvlist_t
*nverrlist
= NULL
;
4481 size_t len
= MAXPATHLEN
* 2;
4483 if (zpool_get_errlog(zhp
, &nverrlist
) != 0) {
4484 (void) printf("errors: List of errors unavailable "
4485 "(insufficient privileges)\n");
4489 (void) printf("errors: Permanent errors have been "
4490 "detected in the following files:\n\n");
4492 pathname
= safe_malloc(len
);
4494 while ((elem
= nvlist_next_nvpair(nverrlist
, elem
)) != NULL
) {
4496 uint64_t dsobj
, obj
;
4498 verify(nvpair_value_nvlist(elem
, &nv
) == 0);
4499 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_DATASET
,
4501 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_OBJECT
,
4503 zpool_obj_to_path(zhp
, dsobj
, obj
, pathname
, len
);
4504 (void) printf("%7s %s\n", "", pathname
);
4507 nvlist_free(nverrlist
);
4511 print_spares(zpool_handle_t
*zhp
, nvlist_t
**spares
, uint_t nspares
,
4520 (void) printf(gettext("\tspares\n"));
4522 for (i
= 0; i
< nspares
; i
++) {
4523 name
= zpool_vdev_name(g_zfs
, zhp
, spares
[i
], B_FALSE
);
4524 print_status_config(zhp
, name
, spares
[i
],
4525 namewidth
, 2, B_TRUE
);
4531 print_l2cache(zpool_handle_t
*zhp
, nvlist_t
**l2cache
, uint_t nl2cache
,
4540 (void) printf(gettext("\tcache\n"));
4542 for (i
= 0; i
< nl2cache
; i
++) {
4543 name
= zpool_vdev_name(g_zfs
, zhp
, l2cache
[i
], B_FALSE
);
4544 print_status_config(zhp
, name
, l2cache
[i
],
4545 namewidth
, 2, B_FALSE
);
4551 print_dedup_stats(nvlist_t
*config
)
4553 ddt_histogram_t
*ddh
;
4559 * If the pool was faulted then we may not have been able to
4560 * obtain the config. Otherwise, if we have anything in the dedup
4561 * table continue processing the stats.
4563 if (nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_OBJ_STATS
,
4564 (uint64_t **)&ddo
, &c
) != 0)
4567 (void) printf("\n");
4568 (void) printf(gettext(" dedup: "));
4569 if (ddo
->ddo_count
== 0) {
4570 (void) printf(gettext("no DDT entries\n"));
4574 (void) printf("DDT entries %llu, size %llu on disk, %llu in core\n",
4575 (u_longlong_t
)ddo
->ddo_count
,
4576 (u_longlong_t
)ddo
->ddo_dspace
,
4577 (u_longlong_t
)ddo
->ddo_mspace
);
4579 verify(nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_STATS
,
4580 (uint64_t **)&dds
, &c
) == 0);
4581 verify(nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_HISTOGRAM
,
4582 (uint64_t **)&ddh
, &c
) == 0);
4583 zpool_dump_ddt(dds
, ddh
);
4587 * Display a summary of pool status. Displays a summary such as:
4591 * reason: One or more devices ...
4592 * see: http://illumos.org/msg/ZFS-xxxx-01
4598 * When given the '-v' option, we print out the complete config. If the '-e'
4599 * option is specified, then we print out error rate information as well.
4602 status_callback(zpool_handle_t
*zhp
, void *data
)
4604 status_cbdata_t
*cbp
= data
;
4605 nvlist_t
*config
, *nvroot
;
4612 config
= zpool_get_config(zhp
, NULL
);
4613 reason
= zpool_get_status(zhp
, &msgid
);
4618 * If we were given 'zpool status -x', only report those pools with
4621 if (cbp
->cb_explain
&&
4622 (reason
== ZPOOL_STATUS_OK
||
4623 reason
== ZPOOL_STATUS_VERSION_OLDER
||
4624 reason
== ZPOOL_STATUS_FEAT_DISABLED
)) {
4625 if (!cbp
->cb_allpools
) {
4626 (void) printf(gettext("pool '%s' is healthy\n"),
4627 zpool_get_name(zhp
));
4629 cbp
->cb_first
= B_FALSE
;
4635 cbp
->cb_first
= B_FALSE
;
4637 (void) printf("\n");
4639 nvroot
= fnvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
);
4640 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_VDEV_STATS
,
4641 (uint64_t **)&vs
, &c
) == 0);
4642 health
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
4644 (void) printf(gettext(" pool: %s\n"), zpool_get_name(zhp
));
4645 (void) printf(gettext(" state: %s\n"), health
);
4648 case ZPOOL_STATUS_MISSING_DEV_R
:
4649 (void) printf(gettext("status: One or more devices could not "
4650 "be opened. Sufficient replicas exist for\n\tthe pool to "
4651 "continue functioning in a degraded state.\n"));
4652 (void) printf(gettext("action: Attach the missing device and "
4653 "online it using 'zpool online'.\n"));
4656 case ZPOOL_STATUS_MISSING_DEV_NR
:
4657 (void) printf(gettext("status: One or more devices could not "
4658 "be opened. There are insufficient\n\treplicas for the "
4659 "pool to continue functioning.\n"));
4660 (void) printf(gettext("action: Attach the missing device and "
4661 "online it using 'zpool online'.\n"));
4664 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
4665 (void) printf(gettext("status: One or more devices could not "
4666 "be used because the label is missing or\n\tinvalid. "
4667 "Sufficient replicas exist for the pool to continue\n\t"
4668 "functioning in a degraded state.\n"));
4669 (void) printf(gettext("action: Replace the device using "
4670 "'zpool replace'.\n"));
4673 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
4674 (void) printf(gettext("status: One or more devices could not "
4675 "be used because the label is missing \n\tor invalid. "
4676 "There are insufficient replicas for the pool to "
4677 "continue\n\tfunctioning.\n"));
4678 zpool_explain_recover(zpool_get_handle(zhp
),
4679 zpool_get_name(zhp
), reason
, config
);
4682 case ZPOOL_STATUS_FAILING_DEV
:
4683 (void) printf(gettext("status: One or more devices has "
4684 "experienced an unrecoverable error. An\n\tattempt was "
4685 "made to correct the error. Applications are "
4687 (void) printf(gettext("action: Determine if the device needs "
4688 "to be replaced, and clear the errors\n\tusing "
4689 "'zpool clear' or replace the device with 'zpool "
4693 case ZPOOL_STATUS_OFFLINE_DEV
:
4694 (void) printf(gettext("status: One or more devices has "
4695 "been taken offline by the administrator.\n\tSufficient "
4696 "replicas exist for the pool to continue functioning in "
4697 "a\n\tdegraded state.\n"));
4698 (void) printf(gettext("action: Online the device using "
4699 "'zpool online' or replace the device with\n\t'zpool "
4703 case ZPOOL_STATUS_REMOVED_DEV
:
4704 (void) printf(gettext("status: One or more devices has "
4705 "been removed by the administrator.\n\tSufficient "
4706 "replicas exist for the pool to continue functioning in "
4707 "a\n\tdegraded state.\n"));
4708 (void) printf(gettext("action: Online the device using "
4709 "'zpool online' or replace the device with\n\t'zpool "
4713 case ZPOOL_STATUS_RESILVERING
:
4714 (void) printf(gettext("status: One or more devices is "
4715 "currently being resilvered. The pool will\n\tcontinue "
4716 "to function, possibly in a degraded state.\n"));
4717 (void) printf(gettext("action: Wait for the resilver to "
4721 case ZPOOL_STATUS_CORRUPT_DATA
:
4722 (void) printf(gettext("status: One or more devices has "
4723 "experienced an error resulting in data\n\tcorruption. "
4724 "Applications may be affected.\n"));
4725 (void) printf(gettext("action: Restore the file in question "
4726 "if possible. Otherwise restore the\n\tentire pool from "
4730 case ZPOOL_STATUS_CORRUPT_POOL
:
4731 (void) printf(gettext("status: The pool metadata is corrupted "
4732 "and the pool cannot be opened.\n"));
4733 zpool_explain_recover(zpool_get_handle(zhp
),
4734 zpool_get_name(zhp
), reason
, config
);
4737 case ZPOOL_STATUS_VERSION_OLDER
:
4738 (void) printf(gettext("status: The pool is formatted using a "
4739 "legacy on-disk format. The pool can\n\tstill be used, "
4740 "but some features are unavailable.\n"));
4741 (void) printf(gettext("action: Upgrade the pool using 'zpool "
4742 "upgrade'. Once this is done, the\n\tpool will no longer "
4743 "be accessible on software that does not support feature\n"
4747 case ZPOOL_STATUS_VERSION_NEWER
:
4748 (void) printf(gettext("status: The pool has been upgraded to a "
4749 "newer, incompatible on-disk version.\n\tThe pool cannot "
4750 "be accessed on this system.\n"));
4751 (void) printf(gettext("action: Access the pool from a system "
4752 "running more recent software, or\n\trestore the pool from "
4756 case ZPOOL_STATUS_FEAT_DISABLED
:
4757 (void) printf(gettext("status: Some supported features are not "
4758 "enabled on the pool. The pool can\n\tstill be used, but "
4759 "some features are unavailable.\n"));
4760 (void) printf(gettext("action: Enable all features using "
4761 "'zpool upgrade'. Once this is done,\n\tthe pool may no "
4762 "longer be accessible by software that does not support\n\t"
4763 "the features. See zpool-features(5) for details.\n"));
4766 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
4767 (void) printf(gettext("status: The pool cannot be accessed on "
4768 "this system because it uses the\n\tfollowing feature(s) "
4769 "not supported on this system:\n"));
4770 zpool_print_unsup_feat(config
);
4771 (void) printf("\n");
4772 (void) printf(gettext("action: Access the pool from a system "
4773 "that supports the required feature(s),\n\tor restore the "
4774 "pool from backup.\n"));
4777 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
4778 (void) printf(gettext("status: The pool can only be accessed "
4779 "in read-only mode on this system. It\n\tcannot be "
4780 "accessed in read-write mode because it uses the "
4781 "following\n\tfeature(s) not supported on this system:\n"));
4782 zpool_print_unsup_feat(config
);
4783 (void) printf("\n");
4784 (void) printf(gettext("action: The pool cannot be accessed in "
4785 "read-write mode. Import the pool with\n"
4786 "\t\"-o readonly=on\", access the pool from a system that "
4787 "supports the\n\trequired feature(s), or restore the "
4788 "pool from backup.\n"));
4791 case ZPOOL_STATUS_FAULTED_DEV_R
:
4792 (void) printf(gettext("status: One or more devices are "
4793 "faulted in response to persistent errors.\n\tSufficient "
4794 "replicas exist for the pool to continue functioning "
4795 "in a\n\tdegraded state.\n"));
4796 (void) printf(gettext("action: Replace the faulted device, "
4797 "or use 'zpool clear' to mark the device\n\trepaired.\n"));
4800 case ZPOOL_STATUS_FAULTED_DEV_NR
:
4801 (void) printf(gettext("status: One or more devices are "
4802 "faulted in response to persistent errors. There are "
4803 "insufficient replicas for the pool to\n\tcontinue "
4805 (void) printf(gettext("action: Destroy and re-create the pool "
4806 "from a backup source. Manually marking the device\n"
4807 "\trepaired using 'zpool clear' may allow some data "
4808 "to be recovered.\n"));
4811 case ZPOOL_STATUS_IO_FAILURE_WAIT
:
4812 case ZPOOL_STATUS_IO_FAILURE_CONTINUE
:
4813 (void) printf(gettext("status: One or more devices are "
4814 "faulted in response to IO failures.\n"));
4815 (void) printf(gettext("action: Make sure the affected devices "
4816 "are connected, then run 'zpool clear'.\n"));
4819 case ZPOOL_STATUS_BAD_LOG
:
4820 (void) printf(gettext("status: An intent log record "
4821 "could not be read.\n"
4822 "\tWaiting for adminstrator intervention to fix the "
4823 "faulted pool.\n"));
4824 (void) printf(gettext("action: Either restore the affected "
4825 "device(s) and run 'zpool online',\n"
4826 "\tor ignore the intent log records by running "
4827 "'zpool clear'.\n"));
4832 * The remaining errors can't actually be generated, yet.
4834 assert(reason
== ZPOOL_STATUS_OK
);
4838 (void) printf(gettext(" see: http://illumos.org/msg/%s\n"),
4841 if (config
!= NULL
) {
4844 nvlist_t
**spares
, **l2cache
;
4845 uint_t nspares
, nl2cache
;
4846 pool_checkpoint_stat_t
*pcs
= NULL
;
4847 pool_scan_stat_t
*ps
= NULL
;
4848 pool_removal_stat_t
*prs
= NULL
;
4850 (void) nvlist_lookup_uint64_array(nvroot
,
4851 ZPOOL_CONFIG_CHECKPOINT_STATS
, (uint64_t **)&pcs
, &c
);
4852 (void) nvlist_lookup_uint64_array(nvroot
,
4853 ZPOOL_CONFIG_SCAN_STATS
, (uint64_t **)&ps
, &c
);
4854 (void) nvlist_lookup_uint64_array(nvroot
,
4855 ZPOOL_CONFIG_REMOVAL_STATS
, (uint64_t **)&prs
, &c
);
4857 print_scan_status(ps
);
4858 print_checkpoint_scan_warning(ps
, pcs
);
4859 print_removal_status(zhp
, prs
);
4860 print_checkpoint_status(pcs
);
4862 namewidth
= max_width(zhp
, nvroot
, 0, 0);
4866 (void) printf(gettext("config:\n\n"));
4867 (void) printf(gettext("\t%-*s %-8s %5s %5s %5s\n"), namewidth
,
4868 "NAME", "STATE", "READ", "WRITE", "CKSUM");
4869 print_status_config(zhp
, zpool_get_name(zhp
), nvroot
,
4870 namewidth
, 0, B_FALSE
);
4872 if (num_logs(nvroot
) > 0)
4873 print_logs(zhp
, nvroot
, namewidth
, B_TRUE
);
4874 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_L2CACHE
,
4875 &l2cache
, &nl2cache
) == 0)
4876 print_l2cache(zhp
, l2cache
, nl2cache
, namewidth
);
4878 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_SPARES
,
4879 &spares
, &nspares
) == 0)
4880 print_spares(zhp
, spares
, nspares
, namewidth
);
4882 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_ERRCOUNT
,
4884 nvlist_t
*nverrlist
= NULL
;
4887 * If the approximate error count is small, get a
4888 * precise count by fetching the entire log and
4889 * uniquifying the results.
4891 if (nerr
> 0 && nerr
< 100 && !cbp
->cb_verbose
&&
4892 zpool_get_errlog(zhp
, &nverrlist
) == 0) {
4897 while ((elem
= nvlist_next_nvpair(nverrlist
,
4902 nvlist_free(nverrlist
);
4904 (void) printf("\n");
4907 (void) printf(gettext("errors: No known data "
4909 else if (!cbp
->cb_verbose
)
4910 (void) printf(gettext("errors: %llu data "
4911 "errors, use '-v' for a list\n"),
4912 (u_longlong_t
)nerr
);
4914 print_error_log(zhp
);
4917 if (cbp
->cb_dedup_stats
)
4918 print_dedup_stats(config
);
4920 (void) printf(gettext("config: The configuration cannot be "
4928 * zpool status [-vx] [-T d|u] [pool] ... [interval [count]]
4930 * -v Display complete error logs
4931 * -x Display only pools with potential problems
4932 * -D Display dedup status (undocumented)
4933 * -T Display a timestamp in date(1) or Unix format
4935 * Describes the health status of all pools or some subset.
4938 zpool_do_status(int argc
, char **argv
)
4942 unsigned long interval
= 0, count
= 0;
4943 status_cbdata_t cb
= { 0 };
4946 while ((c
= getopt(argc
, argv
, "vxDT:")) != -1) {
4949 cb
.cb_verbose
= B_TRUE
;
4952 cb
.cb_explain
= B_TRUE
;
4955 cb
.cb_dedup_stats
= B_TRUE
;
4958 get_timestamp_arg(*optarg
);
4961 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4970 get_interval_count(&argc
, argv
, &interval
, &count
);
4973 cb
.cb_allpools
= B_TRUE
;
4975 cb
.cb_first
= B_TRUE
;
4978 if (timestamp_fmt
!= NODATE
)
4979 print_timestamp(timestamp_fmt
);
4981 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
,
4982 status_callback
, &cb
);
4984 if (argc
== 0 && cb
.cb_count
== 0)
4985 (void) printf(gettext("no pools available\n"));
4986 else if (cb
.cb_explain
&& cb
.cb_first
&& cb
.cb_allpools
)
4987 (void) printf(gettext("all pools are healthy\n"));
4995 if (count
!= 0 && --count
== 0)
4998 (void) sleep(interval
);
5004 typedef struct upgrade_cbdata
{
5007 uint64_t cb_version
;
5012 upgrade_version(zpool_handle_t
*zhp
, uint64_t version
)
5016 uint64_t oldversion
;
5018 config
= zpool_get_config(zhp
, NULL
);
5019 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
5022 assert(SPA_VERSION_IS_SUPPORTED(oldversion
));
5023 assert(oldversion
< version
);
5025 ret
= zpool_upgrade(zhp
, version
);
5029 if (version
>= SPA_VERSION_FEATURES
) {
5030 (void) printf(gettext("Successfully upgraded "
5031 "'%s' from version %llu to feature flags.\n"),
5032 zpool_get_name(zhp
), oldversion
);
5034 (void) printf(gettext("Successfully upgraded "
5035 "'%s' from version %llu to version %llu.\n"),
5036 zpool_get_name(zhp
), oldversion
, version
);
5043 upgrade_enable_all(zpool_handle_t
*zhp
, int *countp
)
5046 boolean_t firstff
= B_TRUE
;
5047 nvlist_t
*enabled
= zpool_get_features(zhp
);
5050 for (i
= 0; i
< SPA_FEATURES
; i
++) {
5051 const char *fname
= spa_feature_table
[i
].fi_uname
;
5052 const char *fguid
= spa_feature_table
[i
].fi_guid
;
5053 if (!nvlist_exists(enabled
, fguid
)) {
5055 verify(-1 != asprintf(&propname
, "feature@%s", fname
));
5056 ret
= zpool_set_prop(zhp
, propname
,
5057 ZFS_FEATURE_ENABLED
);
5065 (void) printf(gettext("Enabled the "
5066 "following features on '%s':\n"),
5067 zpool_get_name(zhp
));
5070 (void) printf(gettext(" %s\n"), fname
);
5081 upgrade_cb(zpool_handle_t
*zhp
, void *arg
)
5083 upgrade_cbdata_t
*cbp
= arg
;
5086 boolean_t printnl
= B_FALSE
;
5089 config
= zpool_get_config(zhp
, NULL
);
5090 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
5093 assert(SPA_VERSION_IS_SUPPORTED(version
));
5095 if (version
< cbp
->cb_version
) {
5096 cbp
->cb_first
= B_FALSE
;
5097 ret
= upgrade_version(zhp
, cbp
->cb_version
);
5103 * If they did "zpool upgrade -a", then we could
5104 * be doing ioctls to different pools. We need
5105 * to log this history once to each pool, and bypass
5106 * the normal history logging that happens in main().
5108 (void) zpool_log_history(g_zfs
, history_str
);
5109 log_history
= B_FALSE
;
5112 if (cbp
->cb_version
>= SPA_VERSION_FEATURES
) {
5114 ret
= upgrade_enable_all(zhp
, &count
);
5119 cbp
->cb_first
= B_FALSE
;
5125 (void) printf(gettext("\n"));
5132 upgrade_list_older_cb(zpool_handle_t
*zhp
, void *arg
)
5134 upgrade_cbdata_t
*cbp
= arg
;
5138 config
= zpool_get_config(zhp
, NULL
);
5139 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
5142 assert(SPA_VERSION_IS_SUPPORTED(version
));
5144 if (version
< SPA_VERSION_FEATURES
) {
5145 if (cbp
->cb_first
) {
5146 (void) printf(gettext("The following pools are "
5147 "formatted with legacy version numbers and can\n"
5148 "be upgraded to use feature flags. After "
5149 "being upgraded, these pools\nwill no "
5150 "longer be accessible by software that does not "
5151 "support feature\nflags.\n\n"));
5152 (void) printf(gettext("VER POOL\n"));
5153 (void) printf(gettext("--- ------------\n"));
5154 cbp
->cb_first
= B_FALSE
;
5157 (void) printf("%2llu %s\n", (u_longlong_t
)version
,
5158 zpool_get_name(zhp
));
5165 upgrade_list_disabled_cb(zpool_handle_t
*zhp
, void *arg
)
5167 upgrade_cbdata_t
*cbp
= arg
;
5171 config
= zpool_get_config(zhp
, NULL
);
5172 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
5175 if (version
>= SPA_VERSION_FEATURES
) {
5177 boolean_t poolfirst
= B_TRUE
;
5178 nvlist_t
*enabled
= zpool_get_features(zhp
);
5180 for (i
= 0; i
< SPA_FEATURES
; i
++) {
5181 const char *fguid
= spa_feature_table
[i
].fi_guid
;
5182 const char *fname
= spa_feature_table
[i
].fi_uname
;
5183 if (!nvlist_exists(enabled
, fguid
)) {
5184 if (cbp
->cb_first
) {
5185 (void) printf(gettext("\nSome "
5186 "supported features are not "
5187 "enabled on the following pools. "
5188 "Once a\nfeature is enabled the "
5189 "pool may become incompatible with "
5190 "software\nthat does not support "
5192 "zpool-features(5) for "
5194 (void) printf(gettext("POOL "
5196 (void) printf(gettext("------"
5198 cbp
->cb_first
= B_FALSE
;
5202 (void) printf(gettext("%s\n"),
5203 zpool_get_name(zhp
));
5204 poolfirst
= B_FALSE
;
5207 (void) printf(gettext(" %s\n"), fname
);
5217 upgrade_one(zpool_handle_t
*zhp
, void *data
)
5219 boolean_t printnl
= B_FALSE
;
5220 upgrade_cbdata_t
*cbp
= data
;
5221 uint64_t cur_version
;
5224 if (strcmp("log", zpool_get_name(zhp
)) == 0) {
5225 (void) printf(gettext("'log' is now a reserved word\n"
5226 "Pool 'log' must be renamed using export and import"
5231 cur_version
= zpool_get_prop_int(zhp
, ZPOOL_PROP_VERSION
, NULL
);
5232 if (cur_version
> cbp
->cb_version
) {
5233 (void) printf(gettext("Pool '%s' is already formatted "
5234 "using more current version '%llu'.\n\n"),
5235 zpool_get_name(zhp
), cur_version
);
5239 if (cbp
->cb_version
!= SPA_VERSION
&& cur_version
== cbp
->cb_version
) {
5240 (void) printf(gettext("Pool '%s' is already formatted "
5241 "using version %llu.\n\n"), zpool_get_name(zhp
),
5246 if (cur_version
!= cbp
->cb_version
) {
5248 ret
= upgrade_version(zhp
, cbp
->cb_version
);
5253 if (cbp
->cb_version
>= SPA_VERSION_FEATURES
) {
5255 ret
= upgrade_enable_all(zhp
, &count
);
5261 } else if (cur_version
== SPA_VERSION
) {
5262 (void) printf(gettext("Pool '%s' already has all "
5263 "supported features enabled.\n"),
5264 zpool_get_name(zhp
));
5269 (void) printf(gettext("\n"));
5278 * zpool upgrade [-V version] <-a | pool ...>
5280 * With no arguments, display downrev'd ZFS pool available for upgrade.
5281 * Individual pools can be upgraded by specifying the pool, and '-a' will
5282 * upgrade all pools.
5285 zpool_do_upgrade(int argc
, char **argv
)
5288 upgrade_cbdata_t cb
= { 0 };
5290 boolean_t showversions
= B_FALSE
;
5291 boolean_t upgradeall
= B_FALSE
;
5296 while ((c
= getopt(argc
, argv
, ":avV:")) != -1) {
5299 upgradeall
= B_TRUE
;
5302 showversions
= B_TRUE
;
5305 cb
.cb_version
= strtoll(optarg
, &end
, 10);
5307 !SPA_VERSION_IS_SUPPORTED(cb
.cb_version
)) {
5308 (void) fprintf(stderr
,
5309 gettext("invalid version '%s'\n"), optarg
);
5314 (void) fprintf(stderr
, gettext("missing argument for "
5315 "'%c' option\n"), optopt
);
5319 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5330 if (cb
.cb_version
== 0) {
5331 cb
.cb_version
= SPA_VERSION
;
5332 } else if (!upgradeall
&& argc
== 0) {
5333 (void) fprintf(stderr
, gettext("-V option is "
5334 "incompatible with other arguments\n"));
5339 if (upgradeall
|| argc
!= 0) {
5340 (void) fprintf(stderr
, gettext("-v option is "
5341 "incompatible with other arguments\n"));
5344 } else if (upgradeall
) {
5346 (void) fprintf(stderr
, gettext("-a option should not "
5347 "be used along with a pool name\n"));
5352 (void) printf(gettext("This system supports ZFS pool feature "
5357 (void) printf(gettext("The following features are "
5359 (void) printf(gettext("FEAT DESCRIPTION\n"));
5360 (void) printf("----------------------------------------------"
5361 "---------------\n");
5362 for (i
= 0; i
< SPA_FEATURES
; i
++) {
5363 zfeature_info_t
*fi
= &spa_feature_table
[i
];
5365 (fi
->fi_flags
& ZFEATURE_FLAG_READONLY_COMPAT
) ?
5366 " (read-only compatible)" : "";
5368 (void) printf("%-37s%s\n", fi
->fi_uname
, ro
);
5369 (void) printf(" %s\n", fi
->fi_desc
);
5371 (void) printf("\n");
5373 (void) printf(gettext("The following legacy versions are also "
5375 (void) printf(gettext("VER DESCRIPTION\n"));
5376 (void) printf("--- -----------------------------------------"
5377 "---------------\n");
5378 (void) printf(gettext(" 1 Initial ZFS version\n"));
5379 (void) printf(gettext(" 2 Ditto blocks "
5380 "(replicated metadata)\n"));
5381 (void) printf(gettext(" 3 Hot spares and double parity "
5383 (void) printf(gettext(" 4 zpool history\n"));
5384 (void) printf(gettext(" 5 Compression using the gzip "
5386 (void) printf(gettext(" 6 bootfs pool property\n"));
5387 (void) printf(gettext(" 7 Separate intent log devices\n"));
5388 (void) printf(gettext(" 8 Delegated administration\n"));
5389 (void) printf(gettext(" 9 refquota and refreservation "
5391 (void) printf(gettext(" 10 Cache devices\n"));
5392 (void) printf(gettext(" 11 Improved scrub performance\n"));
5393 (void) printf(gettext(" 12 Snapshot properties\n"));
5394 (void) printf(gettext(" 13 snapused property\n"));
5395 (void) printf(gettext(" 14 passthrough-x aclinherit\n"));
5396 (void) printf(gettext(" 15 user/group space accounting\n"));
5397 (void) printf(gettext(" 16 stmf property support\n"));
5398 (void) printf(gettext(" 17 Triple-parity RAID-Z\n"));
5399 (void) printf(gettext(" 18 Snapshot user holds\n"));
5400 (void) printf(gettext(" 19 Log device removal\n"));
5401 (void) printf(gettext(" 20 Compression using zle "
5402 "(zero-length encoding)\n"));
5403 (void) printf(gettext(" 21 Deduplication\n"));
5404 (void) printf(gettext(" 22 Received properties\n"));
5405 (void) printf(gettext(" 23 Slim ZIL\n"));
5406 (void) printf(gettext(" 24 System attributes\n"));
5407 (void) printf(gettext(" 25 Improved scrub stats\n"));
5408 (void) printf(gettext(" 26 Improved snapshot deletion "
5410 (void) printf(gettext(" 27 Improved snapshot creation "
5412 (void) printf(gettext(" 28 Multiple vdev replacements\n"));
5413 (void) printf(gettext("\nFor more information on a particular "
5414 "version, including supported releases,\n"));
5415 (void) printf(gettext("see the ZFS Administration Guide.\n\n"));
5416 } else if (argc
== 0 && upgradeall
) {
5417 cb
.cb_first
= B_TRUE
;
5418 ret
= zpool_iter(g_zfs
, upgrade_cb
, &cb
);
5419 if (ret
== 0 && cb
.cb_first
) {
5420 if (cb
.cb_version
== SPA_VERSION
) {
5421 (void) printf(gettext("All pools are already "
5422 "formatted using feature flags.\n\n"));
5423 (void) printf(gettext("Every feature flags "
5424 "pool already has all supported features "
5427 (void) printf(gettext("All pools are already "
5428 "formatted with version %llu or higher.\n"),
5432 } else if (argc
== 0) {
5433 cb
.cb_first
= B_TRUE
;
5434 ret
= zpool_iter(g_zfs
, upgrade_list_older_cb
, &cb
);
5438 (void) printf(gettext("All pools are formatted "
5439 "using feature flags.\n\n"));
5441 (void) printf(gettext("\nUse 'zpool upgrade -v' "
5442 "for a list of available legacy versions.\n"));
5445 cb
.cb_first
= B_TRUE
;
5446 ret
= zpool_iter(g_zfs
, upgrade_list_disabled_cb
, &cb
);
5450 (void) printf(gettext("Every feature flags pool has "
5451 "all supported features enabled.\n"));
5453 (void) printf(gettext("\n"));
5456 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
,
5463 typedef struct hist_cbdata
{
5470 * Print out the command history for a specific pool.
5473 get_history_one(zpool_handle_t
*zhp
, void *data
)
5479 hist_cbdata_t
*cb
= (hist_cbdata_t
*)data
;
5481 cb
->first
= B_FALSE
;
5483 (void) printf(gettext("History for '%s':\n"), zpool_get_name(zhp
));
5485 if ((ret
= zpool_get_history(zhp
, &nvhis
)) != 0)
5488 verify(nvlist_lookup_nvlist_array(nvhis
, ZPOOL_HIST_RECORD
,
5489 &records
, &numrecords
) == 0);
5490 for (i
= 0; i
< numrecords
; i
++) {
5491 nvlist_t
*rec
= records
[i
];
5494 if (nvlist_exists(rec
, ZPOOL_HIST_TIME
)) {
5498 tsec
= fnvlist_lookup_uint64(records
[i
],
5500 (void) localtime_r(&tsec
, &t
);
5501 (void) strftime(tbuf
, sizeof (tbuf
), "%F.%T", &t
);
5504 if (nvlist_exists(rec
, ZPOOL_HIST_CMD
)) {
5505 (void) printf("%s %s", tbuf
,
5506 fnvlist_lookup_string(rec
, ZPOOL_HIST_CMD
));
5507 } else if (nvlist_exists(rec
, ZPOOL_HIST_INT_EVENT
)) {
5509 fnvlist_lookup_uint64(rec
, ZPOOL_HIST_INT_EVENT
);
5512 if (ievent
>= ZFS_NUM_LEGACY_HISTORY_EVENTS
) {
5513 (void) printf("%s unrecognized record:\n",
5515 dump_nvlist(rec
, 4);
5518 (void) printf("%s [internal %s txg:%lld] %s", tbuf
,
5519 zfs_history_event_names
[ievent
],
5520 fnvlist_lookup_uint64(rec
, ZPOOL_HIST_TXG
),
5521 fnvlist_lookup_string(rec
, ZPOOL_HIST_INT_STR
));
5522 } else if (nvlist_exists(rec
, ZPOOL_HIST_INT_NAME
)) {
5525 (void) printf("%s [txg:%lld] %s", tbuf
,
5526 fnvlist_lookup_uint64(rec
, ZPOOL_HIST_TXG
),
5527 fnvlist_lookup_string(rec
, ZPOOL_HIST_INT_NAME
));
5528 if (nvlist_exists(rec
, ZPOOL_HIST_DSNAME
)) {
5529 (void) printf(" %s (%llu)",
5530 fnvlist_lookup_string(rec
,
5532 fnvlist_lookup_uint64(rec
,
5535 (void) printf(" %s", fnvlist_lookup_string(rec
,
5536 ZPOOL_HIST_INT_STR
));
5537 } else if (nvlist_exists(rec
, ZPOOL_HIST_IOCTL
)) {
5540 (void) printf("%s ioctl %s\n", tbuf
,
5541 fnvlist_lookup_string(rec
, ZPOOL_HIST_IOCTL
));
5542 if (nvlist_exists(rec
, ZPOOL_HIST_INPUT_NVL
)) {
5543 (void) printf(" input:\n");
5544 dump_nvlist(fnvlist_lookup_nvlist(rec
,
5545 ZPOOL_HIST_INPUT_NVL
), 8);
5547 if (nvlist_exists(rec
, ZPOOL_HIST_OUTPUT_NVL
)) {
5548 (void) printf(" output:\n");
5549 dump_nvlist(fnvlist_lookup_nvlist(rec
,
5550 ZPOOL_HIST_OUTPUT_NVL
), 8);
5552 if (nvlist_exists(rec
, ZPOOL_HIST_ERRNO
)) {
5553 (void) printf(" errno: %lld\n",
5554 fnvlist_lookup_int64(rec
,
5560 (void) printf("%s unrecognized record:\n", tbuf
);
5561 dump_nvlist(rec
, 4);
5565 (void) printf("\n");
5568 (void) printf(" [");
5569 if (nvlist_exists(rec
, ZPOOL_HIST_WHO
)) {
5570 uid_t who
= fnvlist_lookup_uint64(rec
, ZPOOL_HIST_WHO
);
5571 struct passwd
*pwd
= getpwuid(who
);
5572 (void) printf("user %d ", (int)who
);
5574 (void) printf("(%s) ", pwd
->pw_name
);
5576 if (nvlist_exists(rec
, ZPOOL_HIST_HOST
)) {
5577 (void) printf("on %s",
5578 fnvlist_lookup_string(rec
, ZPOOL_HIST_HOST
));
5580 if (nvlist_exists(rec
, ZPOOL_HIST_ZONE
)) {
5581 (void) printf(":%s",
5582 fnvlist_lookup_string(rec
, ZPOOL_HIST_ZONE
));
5585 (void) printf("\n");
5587 (void) printf("\n");
5594 * zpool history <pool>
5596 * Displays the history of commands that modified pools.
5599 zpool_do_history(int argc
, char **argv
)
5601 hist_cbdata_t cbdata
= { 0 };
5605 cbdata
.first
= B_TRUE
;
5607 while ((c
= getopt(argc
, argv
, "li")) != -1) {
5610 cbdata
.longfmt
= B_TRUE
;
5613 cbdata
.internal
= B_TRUE
;
5616 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5624 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
, get_history_one
,
5627 if (argc
== 0 && cbdata
.first
== B_TRUE
) {
5628 (void) printf(gettext("no pools available\n"));
5636 get_callback(zpool_handle_t
*zhp
, void *data
)
5638 zprop_get_cbdata_t
*cbp
= (zprop_get_cbdata_t
*)data
;
5639 char value
[MAXNAMELEN
];
5640 zprop_source_t srctype
;
5643 for (pl
= cbp
->cb_proplist
; pl
!= NULL
; pl
= pl
->pl_next
) {
5646 * Skip the special fake placeholder. This will also skip
5647 * over the name property when 'all' is specified.
5649 if (pl
->pl_prop
== ZPOOL_PROP_NAME
&&
5650 pl
== cbp
->cb_proplist
)
5653 if (pl
->pl_prop
== ZPROP_INVAL
&&
5654 (zpool_prop_feature(pl
->pl_user_prop
) ||
5655 zpool_prop_unsupported(pl
->pl_user_prop
))) {
5656 srctype
= ZPROP_SRC_LOCAL
;
5658 if (zpool_prop_get_feature(zhp
, pl
->pl_user_prop
,
5659 value
, sizeof (value
)) == 0) {
5660 zprop_print_one_property(zpool_get_name(zhp
),
5661 cbp
, pl
->pl_user_prop
, value
, srctype
,
5665 if (zpool_get_prop(zhp
, pl
->pl_prop
, value
,
5666 sizeof (value
), &srctype
, cbp
->cb_literal
) != 0)
5669 zprop_print_one_property(zpool_get_name(zhp
), cbp
,
5670 zpool_prop_to_name(pl
->pl_prop
), value
, srctype
,
5678 * zpool get [-Hp] [-o "all" | field[,...]] <"all" | property[,...]> <pool> ...
5680 * -H Scripted mode. Don't display headers, and separate properties
5682 * -o List of columns to display. Defaults to
5683 * "name,property,value,source".
5684 * -p Diplay values in parsable (exact) format.
5686 * Get properties of pools in the system. Output space statistics
5687 * for each one as well as other attributes.
5690 zpool_do_get(int argc
, char **argv
)
5692 zprop_get_cbdata_t cb
= { 0 };
5693 zprop_list_t fake_name
= { 0 };
5698 cb
.cb_first
= B_TRUE
;
5701 * Set up default columns and sources.
5703 cb
.cb_sources
= ZPROP_SRC_ALL
;
5704 cb
.cb_columns
[0] = GET_COL_NAME
;
5705 cb
.cb_columns
[1] = GET_COL_PROPERTY
;
5706 cb
.cb_columns
[2] = GET_COL_VALUE
;
5707 cb
.cb_columns
[3] = GET_COL_SOURCE
;
5708 cb
.cb_type
= ZFS_TYPE_POOL
;
5711 while ((c
= getopt(argc
, argv
, ":Hpo:")) != -1) {
5714 cb
.cb_literal
= B_TRUE
;
5717 cb
.cb_scripted
= B_TRUE
;
5720 bzero(&cb
.cb_columns
, sizeof (cb
.cb_columns
));
5722 while (*optarg
!= '\0') {
5723 static char *col_subopts
[] =
5724 { "name", "property", "value", "source",
5727 if (i
== ZFS_GET_NCOLS
) {
5728 (void) fprintf(stderr
, gettext("too "
5729 "many fields given to -o "
5734 switch (getsubopt(&optarg
, col_subopts
,
5737 cb
.cb_columns
[i
++] = GET_COL_NAME
;
5740 cb
.cb_columns
[i
++] = GET_COL_PROPERTY
;
5743 cb
.cb_columns
[i
++] = GET_COL_VALUE
;
5746 cb
.cb_columns
[i
++] = GET_COL_SOURCE
;
5750 (void) fprintf(stderr
,
5751 gettext("\"all\" conflicts "
5752 "with specific fields "
5753 "given to -o option\n"));
5756 cb
.cb_columns
[0] = GET_COL_NAME
;
5757 cb
.cb_columns
[1] = GET_COL_PROPERTY
;
5758 cb
.cb_columns
[2] = GET_COL_VALUE
;
5759 cb
.cb_columns
[3] = GET_COL_SOURCE
;
5763 (void) fprintf(stderr
,
5764 gettext("invalid column name "
5771 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5781 (void) fprintf(stderr
, gettext("missing property "
5786 if (zprop_get_list(g_zfs
, argv
[0], &cb
.cb_proplist
,
5787 ZFS_TYPE_POOL
) != 0)
5793 if (cb
.cb_proplist
!= NULL
) {
5794 fake_name
.pl_prop
= ZPOOL_PROP_NAME
;
5795 fake_name
.pl_width
= strlen(gettext("NAME"));
5796 fake_name
.pl_next
= cb
.cb_proplist
;
5797 cb
.cb_proplist
= &fake_name
;
5800 ret
= for_each_pool(argc
, argv
, B_TRUE
, &cb
.cb_proplist
,
5803 if (cb
.cb_proplist
== &fake_name
)
5804 zprop_free_list(fake_name
.pl_next
);
5806 zprop_free_list(cb
.cb_proplist
);
5811 typedef struct set_cbdata
{
5814 boolean_t cb_any_successful
;
5818 set_callback(zpool_handle_t
*zhp
, void *data
)
5821 set_cbdata_t
*cb
= (set_cbdata_t
*)data
;
5823 error
= zpool_set_prop(zhp
, cb
->cb_propname
, cb
->cb_value
);
5826 cb
->cb_any_successful
= B_TRUE
;
5832 zpool_do_set(int argc
, char **argv
)
5834 set_cbdata_t cb
= { 0 };
5837 if (argc
> 1 && argv
[1][0] == '-') {
5838 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5844 (void) fprintf(stderr
, gettext("missing property=value "
5850 (void) fprintf(stderr
, gettext("missing pool name\n"));
5855 (void) fprintf(stderr
, gettext("too many pool names\n"));
5859 cb
.cb_propname
= argv
[1];
5860 cb
.cb_value
= strchr(cb
.cb_propname
, '=');
5861 if (cb
.cb_value
== NULL
) {
5862 (void) fprintf(stderr
, gettext("missing value in "
5863 "property=value argument\n"));
5867 *(cb
.cb_value
) = '\0';
5870 error
= for_each_pool(argc
- 2, argv
+ 2, B_TRUE
, NULL
,
5877 find_command_idx(char *command
, int *idx
)
5881 for (i
= 0; i
< NCOMMAND
; i
++) {
5882 if (command_table
[i
].name
== NULL
)
5885 if (strcmp(command
, command_table
[i
].name
) == 0) {
5894 main(int argc
, char **argv
)
5900 (void) setlocale(LC_ALL
, "");
5901 (void) textdomain(TEXT_DOMAIN
);
5903 if ((g_zfs
= libzfs_init()) == NULL
) {
5904 (void) fprintf(stderr
, gettext("internal error: failed to "
5905 "initialize ZFS library\n"));
5909 libzfs_print_on_error(g_zfs
, B_TRUE
);
5914 * Make sure the user has specified some command.
5917 (void) fprintf(stderr
, gettext("missing command\n"));
5926 if (strcmp(cmdname
, "-?") == 0)
5929 zfs_save_arguments(argc
, argv
, history_str
, sizeof (history_str
));
5932 * Run the appropriate command.
5934 if (find_command_idx(cmdname
, &i
) == 0) {
5935 current_command
= &command_table
[i
];
5936 ret
= command_table
[i
].func(argc
- 1, argv
+ 1);
5937 } else if (strchr(cmdname
, '=')) {
5938 verify(find_command_idx("set", &i
) == 0);
5939 current_command
= &command_table
[i
];
5940 ret
= command_table
[i
].func(argc
, argv
);
5941 } else if (strcmp(cmdname
, "freeze") == 0 && argc
== 3) {
5943 * 'freeze' is a vile debugging abomination, so we treat
5947 int fd
= open(ZFS_DEV
, O_RDWR
);
5948 (void) strcpy((void *)buf
, argv
[2]);
5949 return (!!ioctl(fd
, ZFS_IOC_POOL_FREEZE
, buf
));
5951 (void) fprintf(stderr
, gettext("unrecognized "
5952 "command '%s'\n"), cmdname
);
5956 if (ret
== 0 && log_history
)
5957 (void) zpool_log_history(g_zfs
, history_str
);
5962 * The 'ZFS_ABORT' environment variable causes us to dump core on exit
5963 * for the purposes of running ::findleaks.
5965 if (getenv("ZFS_ABORT") != NULL
) {
5966 (void) printf("dumping core by request\n");