4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25 * Copyright (c) 2011, 2014 by Delphix. All rights reserved.
26 * Copyright (c) 2012 by Frederik Wessels. All rights reserved.
27 * Copyright (c) 2012 by Cyril Plisko. All rights reserved.
48 #include <sys/fs/zfs.h>
50 #include <sys/fm/util.h>
51 #include <sys/fm/protocol.h>
52 #include <sys/zfs_ioctl.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_list(int, char **);
70 static int zpool_do_iostat(int, char **);
71 static int zpool_do_status(int, char **);
73 static int zpool_do_online(int, char **);
74 static int zpool_do_offline(int, char **);
75 static int zpool_do_clear(int, char **);
76 static int zpool_do_reopen(int, char **);
78 static int zpool_do_reguid(int, char **);
80 static int zpool_do_attach(int, char **);
81 static int zpool_do_detach(int, char **);
82 static int zpool_do_replace(int, char **);
83 static int zpool_do_split(int, char **);
85 static int zpool_do_scrub(int, char **);
87 static int zpool_do_import(int, char **);
88 static int zpool_do_export(int, char **);
90 static int zpool_do_upgrade(int, char **);
92 static int zpool_do_history(int, char **);
93 static int zpool_do_events(int, char **);
95 static int zpool_do_get(int, char **);
96 static int zpool_do_set(int, char **);
99 * These libumem hooks provide a reasonable set of defaults for the allocator's
100 * debugging facilities.
105 _umem_debug_init(void)
107 return ("default,verbose"); /* $UMEM_DEBUG setting */
111 _umem_logging_init(void)
113 return ("fail,contents"); /* $UMEM_LOGGING setting */
146 typedef struct zpool_command {
148 int (*func)(int, char **);
153 * Master command table. Each ZFS command has a name, associated function, and
154 * usage message. The usage messages need to be internationalized, so we have
155 * to have a function to return the usage message based on a command index.
157 * These commands are organized according to how they are displayed in the usage
158 * message. An empty command (one with a NULL name) indicates an empty line in
159 * the generic usage message.
161 static zpool_command_t command_table[] = {
162 { "create", zpool_do_create, HELP_CREATE },
163 { "destroy", zpool_do_destroy, HELP_DESTROY },
165 { "add", zpool_do_add, HELP_ADD },
166 { "remove", zpool_do_remove, HELP_REMOVE },
168 { "labelclear", zpool_do_labelclear, HELP_LABELCLEAR },
170 { "list", zpool_do_list, HELP_LIST },
171 { "iostat", zpool_do_iostat, HELP_IOSTAT },
172 { "status", zpool_do_status, HELP_STATUS },
174 { "online", zpool_do_online, HELP_ONLINE },
175 { "offline", zpool_do_offline, HELP_OFFLINE },
176 { "clear", zpool_do_clear, HELP_CLEAR },
177 { "reopen", zpool_do_reopen, HELP_REOPEN },
179 { "attach", zpool_do_attach, HELP_ATTACH },
180 { "detach", zpool_do_detach, HELP_DETACH },
181 { "replace", zpool_do_replace, HELP_REPLACE },
182 { "split", zpool_do_split, HELP_SPLIT },
184 { "scrub", zpool_do_scrub, HELP_SCRUB },
186 { "import", zpool_do_import, HELP_IMPORT },
187 { "export", zpool_do_export, HELP_EXPORT },
188 { "upgrade", zpool_do_upgrade, HELP_UPGRADE },
189 { "reguid", zpool_do_reguid, HELP_REGUID },
191 { "history", zpool_do_history, HELP_HISTORY },
192 { "events", zpool_do_events, HELP_EVENTS },
194 { "get", zpool_do_get, HELP_GET },
195 { "set", zpool_do_set, HELP_SET },
198 #define NCOMMAND (sizeof (command_table) / sizeof (command_table[0]))
200 static zpool_command_t *current_command;
201 static char history_str[HIS_MAX_RECORD_LEN];
202 static boolean_t log_history = B_TRUE;
203 static uint_t timestamp_fmt = NODATE;
206 get_usage(zpool_help_t idx) {
209 return (gettext("\tadd [-fn] [-o property=value] "
210 "<pool> <vdev> ...\n"));
212 return (gettext("\tattach [-f] [-o property=value] "
213 "<pool> <device> <new-device>\n"));
215 return (gettext("\tclear [-nF] <pool> [device]\n"));
217 return (gettext("\tcreate [-fnd] [-o property=value] ... \n"
218 "\t [-O file-system-property=value] ... \n"
219 "\t [-m mountpoint] [-R root] <pool> <vdev> ...\n"));
221 return (gettext("\tdestroy [-f] <pool>\n"));
223 return (gettext("\tdetach <pool> <device>\n"));
225 return (gettext("\texport [-f] <pool> ...\n"));
227 return (gettext("\thistory [-il] [<pool>] ...\n"));
229 return (gettext("\timport [-d dir] [-D]\n"
230 "\timport [-d dir | -c cachefile] [-F [-n]] <pool | id>\n"
231 "\timport [-o mntopts] [-o property=value] ... \n"
232 "\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
233 "[-R root] [-F [-n]] -a\n"
234 "\timport [-o mntopts] [-o property=value] ... \n"
235 "\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
236 "[-R root] [-F [-n]]\n"
237 "\t <pool | id> [newpool]\n"));
239 return (gettext("\tiostat [-v] [-T d|u] [pool] ... [interval "
241 case HELP_LABELCLEAR:
242 return (gettext("\tlabelclear [-f] <vdev>\n"));
244 return (gettext("\tlist [-Hv] [-o property[,...]] "
245 "[-T d|u] [pool] ... [interval [count]]\n"));
247 return (gettext("\toffline [-t] <pool> <device> ...\n"));
249 return (gettext("\tonline <pool> <device> ...\n"));
251 return (gettext("\treplace [-f] [-o property=value] "
252 "<pool> <device> [new-device]\n"));
254 return (gettext("\tremove <pool> <device> ...\n"));
256 return (gettext("\treopen <pool>\n"));
258 return (gettext("\tscrub [-s] <pool> ...\n"));
260 return (gettext("\tstatus [-vxD] [-T d|u] [pool] ... [interval "
263 return (gettext("\tupgrade\n"
265 "\tupgrade [-V version] <-a | pool ...>\n"));
267 return (gettext("\tevents [-vHfc]\n"));
269 return (gettext("\tget [-pH] <\"all\" | property[,...]> "
272 return (gettext("\tset <property=value> <pool> \n"));
274 return (gettext("\tsplit [-n] [-R altroot] [-o mntopts]\n"
275 "\t [-o property=value] <pool> <newpool> "
276 "[<device> ...]\n"));
278 return (gettext("\treguid <pool>\n"));
287 * Callback routine that will print out a pool property value.
290 print_prop_cb(int prop, void *cb)
294 (void) fprintf(fp, "\t%-15s ", zpool_prop_to_name(prop));
296 if (zpool_prop_readonly(prop))
297 (void) fprintf(fp, " NO ");
299 (void) fprintf(fp, " YES ");
301 if (zpool_prop_values(prop) == NULL)
302 (void) fprintf(fp, "-\n");
304 (void) fprintf(fp, "%s\n", zpool_prop_values(prop));
310 * Display usage message. If we're inside a command, display only the usage for
311 * that command. Otherwise, iterate over the entire command table and display
312 * a complete usage message.
315 usage(boolean_t requested)
317 FILE *fp = requested ? stdout : stderr;
319 if (current_command == NULL) {
322 (void) fprintf(fp, gettext("usage: zpool command args ...\n"));
324 gettext("where 'command' is one of the following:\n\n"));
326 for (i = 0; i < NCOMMAND; i++) {
327 if (command_table[i].name == NULL)
328 (void) fprintf(fp, "\n");
330 (void) fprintf(fp, "%s",
331 get_usage(command_table[i].usage));
334 (void) fprintf(fp, gettext("usage:\n"));
335 (void) fprintf(fp, "%s", get_usage(current_command->usage));
338 if (current_command != NULL &&
339 ((strcmp(current_command->name, "set") == 0) ||
340 (strcmp(current_command->name, "get") == 0) ||
341 (strcmp(current_command->name, "list") == 0))) {
344 gettext("\nthe following properties are supported:\n"));
346 (void) fprintf(fp, "\n\t%-15s %s %s\n\n",
347 "PROPERTY", "EDIT", "VALUES");
349 /* Iterate over all properties */
350 (void) zprop_iter(print_prop_cb, fp, B_FALSE, B_TRUE,
353 (void) fprintf(fp, "\t%-15s ", "feature@...");
354 (void) fprintf(fp, "YES disabled | enabled | active\n");
356 (void) fprintf(fp, gettext("\nThe feature@ properties must be "
357 "appended with a feature name.\nSee zpool-features(5).\n"));
361 * See comments at end of main().
363 if (getenv("ZFS_ABORT") != NULL) {
364 (void) printf("dumping core by request\n");
368 exit(requested ? 0 : 2);
372 print_vdev_tree(zpool_handle_t *zhp, const char *name, nvlist_t *nv, int indent,
373 boolean_t print_logs)
380 (void) printf("\t%*s%s\n", indent, "", name);
382 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
383 &child, &children) != 0)
386 for (c = 0; c < children; c++) {
387 uint64_t is_log = B_FALSE;
389 (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
391 if ((is_log && !print_logs) || (!is_log && print_logs))
394 vname = zpool_vdev_name(g_zfs, zhp, child[c], B_FALSE);
395 print_vdev_tree(zhp, vname, child[c], indent + 2,
402 prop_list_contains_feature(nvlist_t *proplist)
405 for (nvp = nvlist_next_nvpair(proplist, NULL); NULL != nvp;
406 nvp = nvlist_next_nvpair(proplist, nvp)) {
407 if (zpool_prop_feature(nvpair_name(nvp)))
414 * Add a property pair (name, string-value) into a property nvlist.
417 add_prop_list(const char *propname, char *propval, nvlist_t **props,
420 zpool_prop_t prop = ZPROP_INVAL;
426 if (*props == NULL &&
427 nvlist_alloc(props, NV_UNIQUE_NAME, 0) != 0) {
428 (void) fprintf(stderr,
429 gettext("internal error: out of memory\n"));
436 const char *vname = zpool_prop_to_name(ZPOOL_PROP_VERSION);
438 if ((prop = zpool_name_to_prop(propname)) == ZPROP_INVAL &&
439 !zpool_prop_feature(propname)) {
440 (void) fprintf(stderr, gettext("property '%s' is "
441 "not a valid pool property\n"), propname);
446 * feature@ properties and version should not be specified
449 if ((prop == ZPROP_INVAL && zpool_prop_feature(propname) &&
450 nvlist_exists(proplist, vname)) ||
451 (prop == ZPOOL_PROP_VERSION &&
452 prop_list_contains_feature(proplist))) {
453 (void) fprintf(stderr, gettext("'feature@' and "
454 "'version' properties cannot be specified "
460 if (zpool_prop_feature(propname))
463 normnm = zpool_prop_to_name(prop);
465 if ((fprop = zfs_name_to_prop(propname)) != ZPROP_INVAL) {
466 normnm = zfs_prop_to_name(fprop);
472 if (nvlist_lookup_string(proplist, normnm, &strval) == 0 &&
473 prop != ZPOOL_PROP_CACHEFILE) {
474 (void) fprintf(stderr, gettext("property '%s' "
475 "specified multiple times\n"), propname);
479 if (nvlist_add_string(proplist, normnm, propval) != 0) {
480 (void) fprintf(stderr, gettext("internal "
481 "error: out of memory\n"));
489 * zpool add [-fn] [-o property=value] <pool> <vdev> ...
491 * -f Force addition of devices, even if they appear in use
492 * -n Do not add the devices, but display the resulting layout if
493 * they were to be added.
494 * -o Set property=value.
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;
511 nvlist_t *props = NULL;
515 while ((c = getopt(argc, argv, "fno:")) != -1) {
524 if ((propval = strchr(optarg, '=')) == NULL) {
525 (void) fprintf(stderr, gettext("missing "
526 "'=' for -o option\n"));
532 if ((strcmp(optarg, ZPOOL_CONFIG_ASHIFT) != 0) ||
533 (add_prop_list(optarg, propval, &props, B_TRUE)))
537 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
546 /* get pool name and check number of arguments */
548 (void) fprintf(stderr, gettext("missing pool name argument\n"));
552 (void) fprintf(stderr, gettext("missing vdev specification\n"));
561 if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
564 if ((config = zpool_get_config(zhp, NULL)) == NULL) {
565 (void) fprintf(stderr, gettext("pool '%s' is unavailable\n"),
571 /* pass off to get_vdev_spec for processing */
572 nvroot = make_root_vdev(zhp, props, force, !force, B_FALSE, dryrun,
574 if (nvroot == NULL) {
580 nvlist_t *poolnvroot;
582 verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
585 (void) printf(gettext("would update '%s' to the following "
586 "configuration:\n"), zpool_get_name(zhp));
588 /* print original main pool and new tree */
589 print_vdev_tree(zhp, poolname, poolnvroot, 0, B_FALSE);
590 print_vdev_tree(zhp, NULL, nvroot, 0, B_FALSE);
592 /* Do the same for the logs */
593 if (num_logs(poolnvroot) > 0) {
594 print_vdev_tree(zhp, "logs", poolnvroot, 0, B_TRUE);
595 print_vdev_tree(zhp, NULL, nvroot, 0, B_TRUE);
596 } else if (num_logs(nvroot) > 0) {
597 print_vdev_tree(zhp, "logs", nvroot, 0, B_TRUE);
602 ret = (zpool_add(zhp, nvroot) != 0);
613 * zpool remove <pool> <vdev> ...
615 * Removes the given vdev from the pool. Currently, this supports removing
616 * spares, cache, and log devices from the pool.
619 zpool_do_remove(int argc, char **argv)
628 /* get pool name and check number of arguments */
630 (void) fprintf(stderr, gettext("missing pool name argument\n"));
634 (void) fprintf(stderr, gettext("missing device\n"));
640 if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
643 for (i = 1; i < argc; i++) {
644 if (zpool_vdev_remove(zhp, argv[i]) != 0)
652 * zpool labelclear <vdev>
654 * Verifies that the vdev is not active and zeros out the label information
658 zpool_do_labelclear(int argc, char **argv)
661 int c, fd = -1, ret = 0;
663 boolean_t inuse = B_FALSE;
664 boolean_t force = B_FALSE;
667 while ((c = getopt(argc, argv, "f")) != -1) {
673 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
684 (void) fprintf(stderr, gettext("missing vdev device name\n"));
689 if ((fd = open(vdev, O_RDWR)) < 0) {
690 (void) fprintf(stderr, gettext("Unable to open %s\n"), vdev);
695 if (zpool_in_use(g_zfs, fd, &state, &name, &inuse) != 0) {
699 (void) fprintf(stderr,
700 gettext("Unable to determine pool state for %s\n"
701 "Use -f to force the clearing any label data\n"), vdev);
709 case POOL_STATE_ACTIVE:
710 case POOL_STATE_SPARE:
711 case POOL_STATE_L2CACHE:
712 (void) fprintf(stderr,
713 gettext("labelclear operation failed.\n"
714 "\tVdev %s is a member (%s), of pool \"%s\".\n"
715 "\tTo remove label information from this device, "
716 "export or destroy\n\tthe pool, or remove %s from "
717 "the configuration of this pool\n\tand retry the "
718 "labelclear operation.\n"),
719 vdev, zpool_pool_state_to_name(state), name, vdev);
723 case POOL_STATE_EXPORTED:
727 (void) fprintf(stderr,
728 gettext("labelclear operation failed.\n\tVdev "
729 "%s is a member of the exported pool \"%s\".\n"
730 "\tUse \"zpool labelclear -f %s\" to force the "
731 "removal of label\n\tinformation.\n"),
736 case POOL_STATE_POTENTIALLY_ACTIVE:
740 (void) fprintf(stderr,
741 gettext("labelclear operation failed.\n"
742 "\tVdev %s is a member of the pool \"%s\".\n"
743 "\tThis pool is unknown to this system, but may "
744 "be active on\n\tanother system. Use "
745 "\'zpool labelclear -f %s\' to force the\n"
746 "\tremoval of label information.\n"),
751 case POOL_STATE_DESTROYED:
752 /* inuse should never be set for a destroyed pool... */
758 if (zpool_clear_label(fd) != 0) {
759 (void) fprintf(stderr,
760 gettext("Label clear failed on vdev %s\n"), vdev);
773 * zpool create [-fnd] [-o property=value] ...
774 * [-O file-system-property=value] ...
775 * [-R root] [-m mountpoint] <pool> <dev> ...
777 * -f Force creation, even if devices appear in use
778 * -n Do not create the pool, but display the resulting layout if it
779 * were to be created.
780 * -R Create a pool under an alternate root
781 * -m Set default mountpoint for the root dataset. By default it's
783 * -o Set property=value.
784 * -d Don't automatically enable all supported pool features
785 * (individual features can be enabled with -o).
786 * -O Set fsproperty=value in the pool's root file system
788 * Creates the named pool according to the given vdev specification. The
789 * bulk of the vdev processing is done in get_vdev_spec() in zpool_vdev.c. Once
790 * we get the nvlist back from get_vdev_spec(), we either print out the contents
791 * (if '-n' was specified), or pass it to libzfs to do the creation.
794 zpool_do_create(int argc, char **argv)
796 boolean_t force = B_FALSE;
797 boolean_t dryrun = B_FALSE;
798 boolean_t enable_all_pool_feat = B_TRUE;
800 nvlist_t *nvroot = NULL;
803 char *altroot = NULL;
804 char *mountpoint = NULL;
805 nvlist_t *fsprops = NULL;
806 nvlist_t *props = NULL;
810 while ((c = getopt(argc, argv, ":fndR:m:o:O:")) != -1) {
819 enable_all_pool_feat = B_FALSE;
823 if (add_prop_list(zpool_prop_to_name(
824 ZPOOL_PROP_ALTROOT), optarg, &props, B_TRUE))
826 if (nvlist_lookup_string(props,
827 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE),
830 if (add_prop_list(zpool_prop_to_name(
831 ZPOOL_PROP_CACHEFILE), "none", &props, B_TRUE))
835 /* Equivalent to -O mountpoint=optarg */
839 if ((propval = strchr(optarg, '=')) == NULL) {
840 (void) fprintf(stderr, gettext("missing "
841 "'=' for -o option\n"));
847 if (add_prop_list(optarg, propval, &props, B_TRUE))
851 * If the user is creating a pool that doesn't support
852 * feature flags, don't enable any features.
854 if (zpool_name_to_prop(optarg) == ZPOOL_PROP_VERSION) {
858 ver = strtoull(propval, &end, 10);
860 ver < SPA_VERSION_FEATURES) {
861 enable_all_pool_feat = B_FALSE;
866 if ((propval = strchr(optarg, '=')) == NULL) {
867 (void) fprintf(stderr, gettext("missing "
868 "'=' for -O option\n"));
875 * Mountpoints are checked and then added later.
876 * Uniquely among properties, they can be specified
877 * more than once, to avoid conflict with -m.
879 if (0 == strcmp(optarg,
880 zfs_prop_to_name(ZFS_PROP_MOUNTPOINT))) {
881 mountpoint = propval;
882 } else if (add_prop_list(optarg, propval, &fsprops,
888 (void) fprintf(stderr, gettext("missing argument for "
889 "'%c' option\n"), optopt);
892 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
901 /* get pool name and check number of arguments */
903 (void) fprintf(stderr, gettext("missing pool name argument\n"));
907 (void) fprintf(stderr, gettext("missing vdev specification\n"));
914 * As a special case, check for use of '/' in the name, and direct the
915 * user to use 'zfs create' instead.
917 if (strchr(poolname, '/') != NULL) {
918 (void) fprintf(stderr, gettext("cannot create '%s': invalid "
919 "character '/' in pool name\n"), poolname);
920 (void) fprintf(stderr, gettext("use 'zfs create' to "
921 "create a dataset\n"));
925 /* pass off to get_vdev_spec for bulk processing */
926 nvroot = make_root_vdev(NULL, props, force, !force, B_FALSE, dryrun,
931 /* make_root_vdev() allows 0 toplevel children if there are spares */
932 if (!zfs_allocatable_devs(nvroot)) {
933 (void) fprintf(stderr, gettext("invalid vdev "
934 "specification: at least one toplevel vdev must be "
939 if (altroot != NULL && altroot[0] != '/') {
940 (void) fprintf(stderr, gettext("invalid alternate root '%s': "
941 "must be an absolute path\n"), altroot);
946 * Check the validity of the mountpoint and direct the user to use the
947 * '-m' mountpoint option if it looks like its in use.
949 if (mountpoint == NULL ||
950 (strcmp(mountpoint, ZFS_MOUNTPOINT_LEGACY) != 0 &&
951 strcmp(mountpoint, ZFS_MOUNTPOINT_NONE) != 0)) {
952 char buf[MAXPATHLEN];
955 if (mountpoint && mountpoint[0] != '/') {
956 (void) fprintf(stderr, gettext("invalid mountpoint "
957 "'%s': must be an absolute path, 'legacy', or "
958 "'none'\n"), mountpoint);
962 if (mountpoint == NULL) {
964 (void) snprintf(buf, sizeof (buf), "%s/%s",
967 (void) snprintf(buf, sizeof (buf), "/%s",
971 (void) snprintf(buf, sizeof (buf), "%s%s",
972 altroot, mountpoint);
974 (void) snprintf(buf, sizeof (buf), "%s",
978 if ((dirp = opendir(buf)) == NULL && errno != ENOENT) {
979 (void) fprintf(stderr, gettext("mountpoint '%s' : "
980 "%s\n"), buf, strerror(errno));
981 (void) fprintf(stderr, gettext("use '-m' "
982 "option to provide a different default\n"));
987 while (count < 3 && readdir(dirp) != NULL)
989 (void) closedir(dirp);
992 (void) fprintf(stderr, gettext("mountpoint "
993 "'%s' exists and is not empty\n"), buf);
994 (void) fprintf(stderr, gettext("use '-m' "
995 "option to provide a "
996 "different default\n"));
1003 * Now that the mountpoint's validity has been checked, ensure that
1004 * the property is set appropriately prior to creating the pool.
1006 if (mountpoint != NULL) {
1007 ret = add_prop_list(zfs_prop_to_name(ZFS_PROP_MOUNTPOINT),
1008 mountpoint, &fsprops, B_FALSE);
1016 * For a dry run invocation, print out a basic message and run
1017 * through all the vdevs in the list and print out in an
1018 * appropriate hierarchy.
1020 (void) printf(gettext("would create '%s' with the "
1021 "following layout:\n\n"), poolname);
1023 print_vdev_tree(NULL, poolname, nvroot, 0, B_FALSE);
1024 if (num_logs(nvroot) > 0)
1025 print_vdev_tree(NULL, "logs", nvroot, 0, B_TRUE);
1030 * Hand off to libzfs.
1032 if (enable_all_pool_feat) {
1034 for (i = 0; i < SPA_FEATURES; i++) {
1035 char propname[MAXPATHLEN];
1036 zfeature_info_t *feat = &spa_feature_table[i];
1038 (void) snprintf(propname, sizeof (propname),
1039 "feature@%s", feat->fi_uname);
1042 * Skip feature if user specified it manually
1043 * on the command line.
1045 if (nvlist_exists(props, propname))
1048 ret = add_prop_list(propname,
1049 ZFS_FEATURE_ENABLED, &props, B_TRUE);
1056 if (zpool_create(g_zfs, poolname,
1057 nvroot, props, fsprops) == 0) {
1058 zfs_handle_t *pool = zfs_open(g_zfs, poolname,
1059 ZFS_TYPE_FILESYSTEM);
1061 if (zfs_mount(pool, NULL, 0) == 0)
1062 ret = zfs_shareall(pool);
1065 } else if (libzfs_errno(g_zfs) == EZFS_INVALIDNAME) {
1066 (void) fprintf(stderr, gettext("pool name may have "
1072 nvlist_free(nvroot);
1073 nvlist_free(fsprops);
1077 nvlist_free(fsprops);
1084 * zpool destroy <pool>
1086 * -f Forcefully unmount any datasets
1088 * Destroy the given pool. Automatically unmounts any datasets in the pool.
1091 zpool_do_destroy(int argc, char **argv)
1093 boolean_t force = B_FALSE;
1096 zpool_handle_t *zhp;
1100 while ((c = getopt(argc, argv, "f")) != -1) {
1106 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
1115 /* check arguments */
1117 (void) fprintf(stderr, gettext("missing pool argument\n"));
1121 (void) fprintf(stderr, gettext("too many arguments\n"));
1127 if ((zhp = zpool_open_canfail(g_zfs, pool)) == NULL) {
1129 * As a special case, check for use of '/' in the name, and
1130 * direct the user to use 'zfs destroy' instead.
1132 if (strchr(pool, '/') != NULL)
1133 (void) fprintf(stderr, gettext("use 'zfs destroy' to "
1134 "destroy a dataset\n"));
1138 if (zpool_disable_datasets(zhp, force) != 0) {
1139 (void) fprintf(stderr, gettext("could not destroy '%s': "
1140 "could not unmount datasets\n"), zpool_get_name(zhp));
1144 /* The history must be logged as part of the export */
1145 log_history = B_FALSE;
1147 ret = (zpool_destroy(zhp, history_str) != 0);
1155 * zpool export [-f] <pool> ...
1157 * -f Forcefully unmount datasets
1159 * Export the given pools. By default, the command will attempt to cleanly
1160 * unmount any active datasets within the pool. If the '-f' flag is specified,
1161 * then the datasets will be forcefully unmounted.
1164 zpool_do_export(int argc, char **argv)
1166 boolean_t force = B_FALSE;
1167 boolean_t hardforce = B_FALSE;
1169 zpool_handle_t *zhp;
1174 while ((c = getopt(argc, argv, "fF")) != -1) {
1183 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
1192 /* check arguments */
1194 (void) fprintf(stderr, gettext("missing pool argument\n"));
1199 for (i = 0; i < argc; i++) {
1200 if ((zhp = zpool_open_canfail(g_zfs, argv[i])) == NULL) {
1205 if (zpool_disable_datasets(zhp, force) != 0) {
1211 /* The history must be logged as part of the export */
1212 log_history = B_FALSE;
1215 if (zpool_export_force(zhp, history_str) != 0)
1217 } else if (zpool_export(zhp, force, history_str) != 0) {
1228 * Given a vdev configuration, determine the maximum width needed for the device
1232 max_width(zpool_handle_t *zhp, nvlist_t *nv, int depth, int max)
1234 char *name = zpool_vdev_name(g_zfs, zhp, nv, B_TRUE);
1239 if (strlen(name) + depth > max)
1240 max = strlen(name) + depth;
1244 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
1245 &child, &children) == 0) {
1246 for (c = 0; c < children; c++)
1247 if ((ret = max_width(zhp, child[c], depth + 2,
1252 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
1253 &child, &children) == 0) {
1254 for (c = 0; c < children; c++)
1255 if ((ret = max_width(zhp, child[c], depth + 2,
1260 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
1261 &child, &children) == 0) {
1262 for (c = 0; c < children; c++)
1263 if ((ret = max_width(zhp, child[c], depth + 2,
1272 typedef struct spare_cbdata {
1274 zpool_handle_t *cb_zhp;
1278 find_vdev(nvlist_t *nv, uint64_t search)
1284 if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) == 0 &&
1288 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
1289 &child, &children) == 0) {
1290 for (c = 0; c < children; c++)
1291 if (find_vdev(child[c], search))
1299 find_spare(zpool_handle_t *zhp, void *data)
1301 spare_cbdata_t *cbp = data;
1302 nvlist_t *config, *nvroot;
1304 config = zpool_get_config(zhp, NULL);
1305 verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
1308 if (find_vdev(nvroot, cbp->cb_guid)) {
1318 * Print out configuration state as requested by status_callback.
1321 print_status_config(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
1322 int namewidth, int depth, boolean_t isspare)
1326 pool_scan_stat_t *ps = NULL;
1328 char rbuf[6], wbuf[6], cbuf[6];
1330 uint64_t notpresent;
1334 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
1335 &child, &children) != 0)
1338 verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
1339 (uint64_t **)&vs, &c) == 0);
1341 state = zpool_state_to_name(vs->vs_state, vs->vs_aux);
1344 * For hot spares, we use the terms 'INUSE' and 'AVAILABLE' for
1347 if (vs->vs_aux == VDEV_AUX_SPARED)
1349 else if (vs->vs_state == VDEV_STATE_HEALTHY)
1353 (void) printf("\t%*s%-*s %-8s", depth, "", namewidth - depth,
1357 zfs_nicenum(vs->vs_read_errors, rbuf, sizeof (rbuf));
1358 zfs_nicenum(vs->vs_write_errors, wbuf, sizeof (wbuf));
1359 zfs_nicenum(vs->vs_checksum_errors, cbuf, sizeof (cbuf));
1360 (void) printf(" %5s %5s %5s", rbuf, wbuf, cbuf);
1363 if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT,
1364 ¬present) == 0) {
1366 verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0);
1367 (void) printf(" was %s", path);
1368 } else if (vs->vs_aux != 0) {
1371 switch (vs->vs_aux) {
1372 case VDEV_AUX_OPEN_FAILED:
1373 (void) printf(gettext("cannot open"));
1376 case VDEV_AUX_BAD_GUID_SUM:
1377 (void) printf(gettext("missing device"));
1380 case VDEV_AUX_NO_REPLICAS:
1381 (void) printf(gettext("insufficient replicas"));
1384 case VDEV_AUX_VERSION_NEWER:
1385 (void) printf(gettext("newer version"));
1388 case VDEV_AUX_UNSUP_FEAT:
1389 (void) printf(gettext("unsupported feature(s)"));
1392 case VDEV_AUX_SPARED:
1393 verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID,
1395 if (zpool_iter(g_zfs, find_spare, &cb) == 1) {
1396 if (strcmp(zpool_get_name(cb.cb_zhp),
1397 zpool_get_name(zhp)) == 0)
1398 (void) printf(gettext("currently in "
1401 (void) printf(gettext("in use by "
1403 zpool_get_name(cb.cb_zhp));
1404 zpool_close(cb.cb_zhp);
1406 (void) printf(gettext("currently in use"));
1410 case VDEV_AUX_ERR_EXCEEDED:
1411 (void) printf(gettext("too many errors"));
1414 case VDEV_AUX_IO_FAILURE:
1415 (void) printf(gettext("experienced I/O failures"));
1418 case VDEV_AUX_BAD_LOG:
1419 (void) printf(gettext("bad intent log"));
1422 case VDEV_AUX_EXTERNAL:
1423 (void) printf(gettext("external device fault"));
1426 case VDEV_AUX_SPLIT_POOL:
1427 (void) printf(gettext("split into new pool"));
1431 (void) printf(gettext("corrupted data"));
1436 (void) nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_SCAN_STATS,
1437 (uint64_t **)&ps, &c);
1439 if (ps && ps->pss_state == DSS_SCANNING &&
1440 vs->vs_scan_processed != 0 && children == 0) {
1441 (void) printf(gettext(" (%s)"),
1442 (ps->pss_func == POOL_SCAN_RESILVER) ?
1443 "resilvering" : "repairing");
1446 (void) printf("\n");
1448 for (c = 0; c < children; c++) {
1449 uint64_t islog = B_FALSE, ishole = B_FALSE;
1451 /* Don't print logs or holes here */
1452 (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
1454 (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_HOLE,
1456 if (islog || ishole)
1458 vname = zpool_vdev_name(g_zfs, zhp, child[c], B_TRUE);
1459 print_status_config(zhp, vname, child[c],
1460 namewidth, depth + 2, isspare);
1467 * Print the configuration of an exported pool. Iterate over all vdevs in the
1468 * pool, printing out the name and status for each one.
1471 print_import_config(const char *name, nvlist_t *nv, int namewidth, int depth)
1478 verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) == 0);
1479 if (strcmp(type, VDEV_TYPE_MISSING) == 0 ||
1480 strcmp(type, VDEV_TYPE_HOLE) == 0)
1483 verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
1484 (uint64_t **)&vs, &c) == 0);
1486 (void) printf("\t%*s%-*s", depth, "", namewidth - depth, name);
1487 (void) printf(" %s", zpool_state_to_name(vs->vs_state, vs->vs_aux));
1489 if (vs->vs_aux != 0) {
1492 switch (vs->vs_aux) {
1493 case VDEV_AUX_OPEN_FAILED:
1494 (void) printf(gettext("cannot open"));
1497 case VDEV_AUX_BAD_GUID_SUM:
1498 (void) printf(gettext("missing device"));
1501 case VDEV_AUX_NO_REPLICAS:
1502 (void) printf(gettext("insufficient replicas"));
1505 case VDEV_AUX_VERSION_NEWER:
1506 (void) printf(gettext("newer version"));
1509 case VDEV_AUX_UNSUP_FEAT:
1510 (void) printf(gettext("unsupported feature(s)"));
1513 case VDEV_AUX_ERR_EXCEEDED:
1514 (void) printf(gettext("too many errors"));
1518 (void) printf(gettext("corrupted data"));
1522 (void) printf("\n");
1524 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
1525 &child, &children) != 0)
1528 for (c = 0; c < children; c++) {
1529 uint64_t is_log = B_FALSE;
1531 (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
1536 vname = zpool_vdev_name(g_zfs, NULL, child[c], B_TRUE);
1537 print_import_config(vname, child[c], namewidth, depth + 2);
1541 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
1542 &child, &children) == 0) {
1543 (void) printf(gettext("\tcache\n"));
1544 for (c = 0; c < children; c++) {
1545 vname = zpool_vdev_name(g_zfs, NULL, child[c], B_FALSE);
1546 (void) printf("\t %s\n", vname);
1551 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
1552 &child, &children) == 0) {
1553 (void) printf(gettext("\tspares\n"));
1554 for (c = 0; c < children; c++) {
1555 vname = zpool_vdev_name(g_zfs, NULL, child[c], B_FALSE);
1556 (void) printf("\t %s\n", vname);
1564 * Logs are recorded as top level vdevs in the main pool child array
1565 * but with "is_log" set to 1. We use either print_status_config() or
1566 * print_import_config() to print the top level logs then any log
1567 * children (eg mirrored slogs) are printed recursively - which
1568 * works because only the top level vdev is marked "is_log"
1571 print_logs(zpool_handle_t *zhp, nvlist_t *nv, int namewidth, boolean_t verbose)
1576 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN, &child,
1580 (void) printf(gettext("\tlogs\n"));
1582 for (c = 0; c < children; c++) {
1583 uint64_t is_log = B_FALSE;
1586 (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
1590 name = zpool_vdev_name(g_zfs, zhp, child[c], B_TRUE);
1592 print_status_config(zhp, name, child[c], namewidth,
1595 print_import_config(name, child[c], namewidth, 2);
1601 * Display the status for the given pool.
1604 show_import(nvlist_t *config)
1606 uint64_t pool_state;
1612 zpool_status_t reason;
1613 zpool_errata_t errata;
1619 verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
1621 verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID,
1623 verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
1625 verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
1628 verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_VDEV_STATS,
1629 (uint64_t **)&vs, &vsc) == 0);
1630 health = zpool_state_to_name(vs->vs_state, vs->vs_aux);
1632 reason = zpool_import_status(config, &msgid, &errata);
1634 (void) printf(gettext(" pool: %s\n"), name);
1635 (void) printf(gettext(" id: %llu\n"), (u_longlong_t)guid);
1636 (void) printf(gettext(" state: %s"), health);
1637 if (pool_state == POOL_STATE_DESTROYED)
1638 (void) printf(gettext(" (DESTROYED)"));
1639 (void) printf("\n");
1642 case ZPOOL_STATUS_MISSING_DEV_R:
1643 case ZPOOL_STATUS_MISSING_DEV_NR:
1644 case ZPOOL_STATUS_BAD_GUID_SUM:
1645 (void) printf(gettext(" status: One or more devices are "
1646 "missing from the system.\n"));
1649 case ZPOOL_STATUS_CORRUPT_LABEL_R:
1650 case ZPOOL_STATUS_CORRUPT_LABEL_NR:
1651 (void) printf(gettext(" status: One or more devices contains "
1652 "corrupted data.\n"));
1655 case ZPOOL_STATUS_CORRUPT_DATA:
1657 gettext(" status: The pool data is corrupted.\n"));
1660 case ZPOOL_STATUS_OFFLINE_DEV:
1661 (void) printf(gettext(" status: One or more devices "
1662 "are offlined.\n"));
1665 case ZPOOL_STATUS_CORRUPT_POOL:
1666 (void) printf(gettext(" status: The pool metadata is "
1670 case ZPOOL_STATUS_VERSION_OLDER:
1671 (void) printf(gettext(" status: The pool is formatted using a "
1672 "legacy on-disk version.\n"));
1675 case ZPOOL_STATUS_VERSION_NEWER:
1676 (void) printf(gettext(" status: The pool is formatted using an "
1677 "incompatible version.\n"));
1680 case ZPOOL_STATUS_FEAT_DISABLED:
1681 (void) printf(gettext(" status: Some supported features are "
1682 "not enabled on the pool.\n"));
1685 case ZPOOL_STATUS_UNSUP_FEAT_READ:
1686 (void) printf(gettext("status: The pool uses the following "
1687 "feature(s) not supported on this sytem:\n"));
1688 zpool_print_unsup_feat(config);
1691 case ZPOOL_STATUS_UNSUP_FEAT_WRITE:
1692 (void) printf(gettext("status: The pool can only be accessed "
1693 "in read-only mode on this system. It\n\tcannot be "
1694 "accessed in read-write mode because it uses the "
1695 "following\n\tfeature(s) not supported on this system:\n"));
1696 zpool_print_unsup_feat(config);
1699 case ZPOOL_STATUS_HOSTID_MISMATCH:
1700 (void) printf(gettext(" status: The pool was last accessed by "
1701 "another system.\n"));
1704 case ZPOOL_STATUS_FAULTED_DEV_R:
1705 case ZPOOL_STATUS_FAULTED_DEV_NR:
1706 (void) printf(gettext(" status: One or more devices are "
1710 case ZPOOL_STATUS_BAD_LOG:
1711 (void) printf(gettext(" status: An intent log record cannot be "
1715 case ZPOOL_STATUS_RESILVERING:
1716 (void) printf(gettext(" status: One or more devices were being "
1720 case ZPOOL_STATUS_ERRATA:
1721 (void) printf(gettext(" status: Errata #%d detected.\n"),
1727 * No other status can be seen when importing pools.
1729 assert(reason == ZPOOL_STATUS_OK);
1733 * Print out an action according to the overall state of the pool.
1735 if (vs->vs_state == VDEV_STATE_HEALTHY) {
1736 if (reason == ZPOOL_STATUS_VERSION_OLDER ||
1737 reason == ZPOOL_STATUS_FEAT_DISABLED) {
1738 (void) printf(gettext(" action: The pool can be "
1739 "imported using its name or numeric identifier, "
1740 "though\n\tsome features will not be available "
1741 "without an explicit 'zpool upgrade'.\n"));
1742 } else if (reason == ZPOOL_STATUS_HOSTID_MISMATCH) {
1743 (void) printf(gettext(" action: The pool can be "
1744 "imported using its name or numeric "
1745 "identifier and\n\tthe '-f' flag.\n"));
1746 } else if (reason == ZPOOL_STATUS_ERRATA) {
1748 case ZPOOL_ERRATA_NONE:
1751 case ZPOOL_ERRATA_ZOL_2094_SCRUB:
1752 (void) printf(gettext(" action: The pool can "
1753 "be imported using its name or numeric "
1754 "identifier,\n\thowever there is a compat"
1755 "ibility issue which should be corrected"
1756 "\n\tby running 'zpool scrub'\n"));
1759 case ZPOOL_ERRATA_ZOL_2094_ASYNC_DESTROY:
1760 (void) printf(gettext(" action: The pool can"
1761 "not be imported with this version of ZFS "
1762 "due to\n\tan active asynchronous destroy. "
1763 "Revert to an earlier version\n\tand "
1764 "allow the destroy to complete before "
1770 * All errata must contain an action message.
1775 (void) printf(gettext(" action: The pool can be "
1776 "imported using its name or numeric "
1779 } else if (vs->vs_state == VDEV_STATE_DEGRADED) {
1780 (void) printf(gettext(" action: The pool can be imported "
1781 "despite missing or damaged devices. The\n\tfault "
1782 "tolerance of the pool may be compromised if imported.\n"));
1785 case ZPOOL_STATUS_VERSION_NEWER:
1786 (void) printf(gettext(" action: The pool cannot be "
1787 "imported. Access the pool on a system running "
1788 "newer\n\tsoftware, or recreate the pool from "
1791 case ZPOOL_STATUS_UNSUP_FEAT_READ:
1792 (void) printf(gettext("action: The pool cannot be "
1793 "imported. Access the pool on a system that "
1794 "supports\n\tthe required feature(s), or recreate "
1795 "the pool from backup.\n"));
1797 case ZPOOL_STATUS_UNSUP_FEAT_WRITE:
1798 (void) printf(gettext("action: The pool cannot be "
1799 "imported in read-write mode. Import the pool "
1801 "\t\"-o readonly=on\", access the pool on a system "
1802 "that supports the\n\trequired feature(s), or "
1803 "recreate the pool from backup.\n"));
1805 case ZPOOL_STATUS_MISSING_DEV_R:
1806 case ZPOOL_STATUS_MISSING_DEV_NR:
1807 case ZPOOL_STATUS_BAD_GUID_SUM:
1808 (void) printf(gettext(" action: The pool cannot be "
1809 "imported. Attach the missing\n\tdevices and try "
1813 (void) printf(gettext(" action: The pool cannot be "
1814 "imported due to damaged devices or data.\n"));
1818 /* Print the comment attached to the pool. */
1819 if (nvlist_lookup_string(config, ZPOOL_CONFIG_COMMENT, &comment) == 0)
1820 (void) printf(gettext("comment: %s\n"), comment);
1823 * If the state is "closed" or "can't open", and the aux state
1824 * is "corrupt data":
1826 if (((vs->vs_state == VDEV_STATE_CLOSED) ||
1827 (vs->vs_state == VDEV_STATE_CANT_OPEN)) &&
1828 (vs->vs_aux == VDEV_AUX_CORRUPT_DATA)) {
1829 if (pool_state == POOL_STATE_DESTROYED)
1830 (void) printf(gettext("\tThe pool was destroyed, "
1831 "but can be imported using the '-Df' flags.\n"));
1832 else if (pool_state != POOL_STATE_EXPORTED)
1833 (void) printf(gettext("\tThe pool may be active on "
1834 "another system, but can be imported using\n\t"
1835 "the '-f' flag.\n"));
1839 (void) printf(gettext(" see: http://zfsonlinux.org/msg/%s\n"),
1842 (void) printf(gettext(" config:\n\n"));
1844 namewidth = max_width(NULL, nvroot, 0, 0);
1848 print_import_config(name, nvroot, namewidth, 0);
1849 if (num_logs(nvroot) > 0)
1850 print_logs(NULL, nvroot, namewidth, B_FALSE);
1852 if (reason == ZPOOL_STATUS_BAD_GUID_SUM) {
1853 (void) printf(gettext("\n\tAdditional devices are known to "
1854 "be part of this pool, though their\n\texact "
1855 "configuration cannot be determined.\n"));
1860 * Perform the import for the given configuration. This passes the heavy
1861 * lifting off to zpool_import_props(), and then mounts the datasets contained
1865 do_import(nvlist_t *config, const char *newname, const char *mntopts,
1866 nvlist_t *props, int flags)
1868 zpool_handle_t *zhp;
1873 verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
1876 verify(nvlist_lookup_uint64(config,
1877 ZPOOL_CONFIG_POOL_STATE, &state) == 0);
1878 verify(nvlist_lookup_uint64(config,
1879 ZPOOL_CONFIG_VERSION, &version) == 0);
1880 if (!SPA_VERSION_IS_SUPPORTED(version)) {
1881 (void) fprintf(stderr, gettext("cannot import '%s': pool "
1882 "is formatted using an unsupported ZFS version\n"), name);
1884 } else if (state != POOL_STATE_EXPORTED &&
1885 !(flags & ZFS_IMPORT_ANY_HOST)) {
1888 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID,
1890 unsigned long system_hostid = gethostid() & 0xffffffff;
1892 if ((unsigned long)hostid != system_hostid) {
1897 verify(nvlist_lookup_string(config,
1898 ZPOOL_CONFIG_HOSTNAME, &hostname) == 0);
1899 verify(nvlist_lookup_uint64(config,
1900 ZPOOL_CONFIG_TIMESTAMP, ×tamp) == 0);
1902 (void) fprintf(stderr, gettext("cannot import "
1903 "'%s': pool may be in use from other "
1904 "system, it was last accessed by %s "
1905 "(hostid: 0x%lx) on %s"), name, hostname,
1906 (unsigned long)hostid,
1907 asctime(localtime(&t)));
1908 (void) fprintf(stderr, gettext("use '-f' to "
1909 "import anyway\n"));
1913 (void) fprintf(stderr, gettext("cannot import '%s': "
1914 "pool may be in use from other system\n"), name);
1915 (void) fprintf(stderr, gettext("use '-f' to import "
1921 if (zpool_import_props(g_zfs, config, newname, props, flags) != 0)
1924 if (newname != NULL)
1925 name = (char *)newname;
1927 if ((zhp = zpool_open_canfail(g_zfs, name)) == NULL)
1930 if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL &&
1931 !(flags & ZFS_IMPORT_ONLY) &&
1932 zpool_enable_datasets(zhp, mntopts, 0) != 0) {
1942 * zpool import [-d dir] [-D]
1943 * import [-o mntopts] [-o prop=value] ... [-R root] [-D]
1944 * [-d dir | -c cachefile] [-f] -a
1945 * import [-o mntopts] [-o prop=value] ... [-R root] [-D]
1946 * [-d dir | -c cachefile] [-f] [-n] [-F] <pool | id> [newpool]
1948 * -c Read pool information from a cachefile instead of searching
1951 * -d Scan in a specific directory, other than /dev/. More than
1952 * one directory can be specified using multiple '-d' options.
1954 * -D Scan for previously destroyed pools or import all or only
1955 * specified destroyed pools.
1957 * -R Temporarily import the pool, with all mountpoints relative to
1958 * the given root. The pool will remain exported when the machine
1961 * -V Import even in the presence of faulted vdevs. This is an
1962 * intentionally undocumented option for testing purposes, and
1963 * treats the pool configuration as complete, leaving any bad
1964 * vdevs in the FAULTED state. In other words, it does verbatim
1967 * -f Force import, even if it appears that the pool is active.
1969 * -F Attempt rewind if necessary.
1971 * -n See if rewind would work, but don't actually rewind.
1973 * -N Import the pool but don't mount datasets.
1975 * -T Specify a starting txg to use for import. This option is
1976 * intentionally undocumented option for testing purposes.
1978 * -a Import all pools found.
1980 * -o Set property=value and/or temporary mount options (without '=').
1982 * The import command scans for pools to import, and import pools based on pool
1983 * name and GUID. The pool can also be renamed as part of the import process.
1986 zpool_do_import(int argc, char **argv)
1988 char **searchdirs = NULL;
1989 char *env, *envdup = NULL;
1993 nvlist_t *pools = NULL;
1994 boolean_t do_all = B_FALSE;
1995 boolean_t do_destroyed = B_FALSE;
1996 char *mntopts = NULL;
1999 uint64_t searchguid = 0;
2000 char *searchname = NULL;
2002 nvlist_t *found_config;
2003 nvlist_t *policy = NULL;
2004 nvlist_t *props = NULL;
2006 int flags = ZFS_IMPORT_NORMAL;
2007 uint32_t rewind_policy = ZPOOL_NO_REWIND;
2008 boolean_t dryrun = B_FALSE;
2009 boolean_t do_rewind = B_FALSE;
2010 boolean_t xtreme_rewind = B_FALSE;
2011 uint64_t pool_state, txg = -1ULL;
2012 char *cachefile = NULL;
2013 importargs_t idata = { 0 };
2017 while ((c = getopt(argc, argv, ":aCc:d:DEfFmnNo:R:tT:VX")) != -1) {
2026 if (searchdirs == NULL) {
2027 searchdirs = safe_malloc(sizeof (char *));
2029 char **tmp = safe_malloc((nsearch + 1) *
2031 bcopy(searchdirs, tmp, nsearch *
2036 searchdirs[nsearch++] = optarg;
2039 do_destroyed = B_TRUE;
2042 flags |= ZFS_IMPORT_ANY_HOST;
2048 flags |= ZFS_IMPORT_MISSING_LOG;
2054 flags |= ZFS_IMPORT_ONLY;
2057 if ((propval = strchr(optarg, '=')) != NULL) {
2060 if (add_prop_list(optarg, propval,
2068 if (add_prop_list(zpool_prop_to_name(
2069 ZPOOL_PROP_ALTROOT), optarg, &props, B_TRUE))
2071 if (nvlist_lookup_string(props,
2072 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE),
2075 if (add_prop_list(zpool_prop_to_name(
2076 ZPOOL_PROP_CACHEFILE), "none", &props, B_TRUE))
2080 flags |= ZFS_IMPORT_TEMP_NAME;
2085 txg = strtoull(optarg, &endptr, 0);
2086 if (errno != 0 || *endptr != '\0') {
2087 (void) fprintf(stderr,
2088 gettext("invalid txg value\n"));
2091 rewind_policy = ZPOOL_DO_REWIND | ZPOOL_EXTREME_REWIND;
2094 flags |= ZFS_IMPORT_VERBATIM;
2097 xtreme_rewind = B_TRUE;
2100 (void) fprintf(stderr, gettext("missing argument for "
2101 "'%c' option\n"), optopt);
2105 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
2114 if (cachefile && nsearch != 0) {
2115 (void) fprintf(stderr, gettext("-c is incompatible with -d\n"));
2119 if ((dryrun || xtreme_rewind) && !do_rewind) {
2120 (void) fprintf(stderr,
2121 gettext("-n or -X only meaningful with -F\n"));
2125 rewind_policy = ZPOOL_TRY_REWIND;
2127 rewind_policy = ZPOOL_DO_REWIND;
2129 rewind_policy |= ZPOOL_EXTREME_REWIND;
2131 /* In the future, we can capture further policy and include it here */
2132 if (nvlist_alloc(&policy, NV_UNIQUE_NAME, 0) != 0 ||
2133 nvlist_add_uint64(policy, ZPOOL_REWIND_REQUEST_TXG, txg) != 0 ||
2134 nvlist_add_uint32(policy, ZPOOL_REWIND_REQUEST, rewind_policy) != 0)
2137 /* check argument count */
2140 (void) fprintf(stderr, gettext("too many arguments\n"));
2145 (void) fprintf(stderr, gettext("too many arguments\n"));
2150 * Check for the SYS_CONFIG privilege. We do this explicitly
2151 * here because otherwise any attempt to discover pools will
2154 if (argc == 0 && !priv_ineffect(PRIV_SYS_CONFIG)) {
2155 (void) fprintf(stderr, gettext("cannot "
2156 "discover pools: permission denied\n"));
2157 if (searchdirs != NULL)
2160 nvlist_free(policy);
2166 * Depending on the arguments given, we do one of the following:
2168 * <none> Iterate through all pools and display information about
2171 * -a Iterate through all pools and try to import each one.
2173 * <id> Find the pool that corresponds to the given GUID/pool
2174 * name and import that one.
2176 * -D Above options applies only to destroyed pools.
2182 searchguid = strtoull(argv[0], &endptr, 10);
2183 if (errno != 0 || *endptr != '\0')
2184 searchname = argv[0];
2185 found_config = NULL;
2188 * User specified a name or guid. Ensure it's unique.
2190 idata.unique = B_TRUE;
2194 * Check the environment for the preferred search path.
2196 if ((searchdirs == NULL) && (env = getenv("ZPOOL_IMPORT_PATH"))) {
2199 envdup = strdup(env);
2201 dir = strtok(envdup, ":");
2202 while (dir != NULL) {
2203 if (searchdirs == NULL) {
2204 searchdirs = safe_malloc(sizeof (char *));
2206 char **tmp = safe_malloc((nsearch + 1) *
2208 bcopy(searchdirs, tmp, nsearch *
2213 searchdirs[nsearch++] = dir;
2214 dir = strtok(NULL, ":");
2218 idata.path = searchdirs;
2219 idata.paths = nsearch;
2220 idata.poolname = searchname;
2221 idata.guid = searchguid;
2222 idata.cachefile = cachefile;
2224 pools = zpool_search_import(g_zfs, &idata);
2226 if (pools != NULL && idata.exists &&
2227 (argc == 1 || strcmp(argv[0], argv[1]) == 0)) {
2228 (void) fprintf(stderr, gettext("cannot import '%s': "
2229 "a pool with that name already exists\n"),
2231 (void) fprintf(stderr, gettext("use the form '%s "
2232 "<pool | id> <newpool>' to give it a new name\n"),
2235 } else if (pools == NULL && idata.exists) {
2236 (void) fprintf(stderr, gettext("cannot import '%s': "
2237 "a pool with that name is already created/imported,\n"),
2239 (void) fprintf(stderr, gettext("and no additional pools "
2240 "with that name were found\n"));
2242 } else if (pools == NULL) {
2244 (void) fprintf(stderr, gettext("cannot import '%s': "
2245 "no such pool available\n"), argv[0]);
2251 if (searchdirs != NULL)
2255 nvlist_free(policy);
2260 * At this point we have a list of import candidate configs. Even if
2261 * we were searching by pool name or guid, we still need to
2262 * post-process the list to deal with pool state and possible
2268 while ((elem = nvlist_next_nvpair(pools, elem)) != NULL) {
2270 verify(nvpair_value_nvlist(elem, &config) == 0);
2272 verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
2274 if (!do_destroyed && pool_state == POOL_STATE_DESTROYED)
2276 if (do_destroyed && pool_state != POOL_STATE_DESTROYED)
2279 verify(nvlist_add_nvlist(config, ZPOOL_REWIND_POLICY,
2286 (void) printf("\n");
2289 err |= do_import(config, NULL, mntopts,
2292 show_import(config);
2294 } else if (searchname != NULL) {
2298 * We are searching for a pool based on name.
2300 verify(nvlist_lookup_string(config,
2301 ZPOOL_CONFIG_POOL_NAME, &name) == 0);
2303 if (strcmp(name, searchname) == 0) {
2304 if (found_config != NULL) {
2305 (void) fprintf(stderr, gettext(
2306 "cannot import '%s': more than "
2307 "one matching pool\n"), searchname);
2308 (void) fprintf(stderr, gettext(
2309 "import by numeric ID instead\n"));
2312 found_config = config;
2318 * Search for a pool by guid.
2320 verify(nvlist_lookup_uint64(config,
2321 ZPOOL_CONFIG_POOL_GUID, &guid) == 0);
2323 if (guid == searchguid)
2324 found_config = config;
2329 * If we were searching for a specific pool, verify that we found a
2330 * pool, and then do the import.
2332 if (argc != 0 && err == 0) {
2333 if (found_config == NULL) {
2334 (void) fprintf(stderr, gettext("cannot import '%s': "
2335 "no such pool available\n"), argv[0]);
2338 err |= do_import(found_config, argc == 1 ? NULL :
2339 argv[1], mntopts, props, flags);
2344 * If we were just looking for pools, report an error if none were
2347 if (argc == 0 && first)
2348 (void) fprintf(stderr,
2349 gettext("no pools available to import\n"));
2354 nvlist_free(policy);
2355 if (searchdirs != NULL)
2360 return (err ? 1 : 0);
2363 typedef struct iostat_cbdata {
2364 boolean_t cb_verbose;
2367 zpool_list_t *cb_list;
2371 print_iostat_separator(iostat_cbdata_t *cb)
2375 for (i = 0; i < cb->cb_namewidth; i++)
2377 (void) printf(" ----- ----- ----- ----- ----- -----\n");
2381 print_iostat_header(iostat_cbdata_t *cb)
2383 (void) printf("%*s capacity operations bandwidth\n",
2384 cb->cb_namewidth, "");
2385 (void) printf("%-*s alloc free read write read write\n",
2386 cb->cb_namewidth, "pool");
2387 print_iostat_separator(cb);
2391 * Display a single statistic.
2394 print_one_stat(uint64_t value)
2398 zfs_nicenum(value, buf, sizeof (buf));
2399 (void) printf(" %5s", buf);
2403 * Print out all the statistics for the given vdev. This can either be the
2404 * toplevel configuration, or called recursively. If 'name' is NULL, then this
2405 * is a verbose output, and we don't want to display the toplevel pool stats.
2408 print_vdev_stats(zpool_handle_t *zhp, const char *name, nvlist_t *oldnv,
2409 nvlist_t *newnv, iostat_cbdata_t *cb, int depth)
2411 nvlist_t **oldchild, **newchild;
2413 vdev_stat_t *oldvs, *newvs;
2414 vdev_stat_t zerovs = { 0 };
2419 if (oldnv != NULL) {
2420 verify(nvlist_lookup_uint64_array(oldnv,
2421 ZPOOL_CONFIG_VDEV_STATS, (uint64_t **)&oldvs, &c) == 0);
2426 verify(nvlist_lookup_uint64_array(newnv, ZPOOL_CONFIG_VDEV_STATS,
2427 (uint64_t **)&newvs, &c) == 0);
2429 if (strlen(name) + depth > cb->cb_namewidth)
2430 (void) printf("%*s%s", depth, "", name);
2432 (void) printf("%*s%s%*s", depth, "", name,
2433 (int)(cb->cb_namewidth - strlen(name) - depth), "");
2435 tdelta = newvs->vs_timestamp - oldvs->vs_timestamp;
2440 scale = (double)NANOSEC / tdelta;
2442 /* only toplevel vdevs have capacity stats */
2443 if (newvs->vs_space == 0) {
2444 (void) printf(" - -");
2446 print_one_stat(newvs->vs_alloc);
2447 print_one_stat(newvs->vs_space - newvs->vs_alloc);
2450 print_one_stat((uint64_t)(scale * (newvs->vs_ops[ZIO_TYPE_READ] -
2451 oldvs->vs_ops[ZIO_TYPE_READ])));
2453 print_one_stat((uint64_t)(scale * (newvs->vs_ops[ZIO_TYPE_WRITE] -
2454 oldvs->vs_ops[ZIO_TYPE_WRITE])));
2456 print_one_stat((uint64_t)(scale * (newvs->vs_bytes[ZIO_TYPE_READ] -
2457 oldvs->vs_bytes[ZIO_TYPE_READ])));
2459 print_one_stat((uint64_t)(scale * (newvs->vs_bytes[ZIO_TYPE_WRITE] -
2460 oldvs->vs_bytes[ZIO_TYPE_WRITE])));
2462 (void) printf("\n");
2464 if (!cb->cb_verbose)
2467 if (nvlist_lookup_nvlist_array(newnv, ZPOOL_CONFIG_CHILDREN,
2468 &newchild, &children) != 0)
2471 if (oldnv && nvlist_lookup_nvlist_array(oldnv, ZPOOL_CONFIG_CHILDREN,
2472 &oldchild, &c) != 0)
2475 for (c = 0; c < children; c++) {
2476 uint64_t ishole = B_FALSE, islog = B_FALSE;
2478 (void) nvlist_lookup_uint64(newchild[c], ZPOOL_CONFIG_IS_HOLE,
2481 (void) nvlist_lookup_uint64(newchild[c], ZPOOL_CONFIG_IS_LOG,
2484 if (ishole || islog)
2487 vname = zpool_vdev_name(g_zfs, zhp, newchild[c], B_FALSE);
2488 print_vdev_stats(zhp, vname, oldnv ? oldchild[c] : NULL,
2489 newchild[c], cb, depth + 2);
2494 * Log device section
2497 if (num_logs(newnv) > 0) {
2498 (void) printf("%-*s - - - - - "
2499 "-\n", cb->cb_namewidth, "logs");
2501 for (c = 0; c < children; c++) {
2502 uint64_t islog = B_FALSE;
2503 (void) nvlist_lookup_uint64(newchild[c],
2504 ZPOOL_CONFIG_IS_LOG, &islog);
2507 vname = zpool_vdev_name(g_zfs, zhp, newchild[c],
2509 print_vdev_stats(zhp, vname, oldnv ?
2510 oldchild[c] : NULL, newchild[c],
2519 * Include level 2 ARC devices in iostat output
2521 if (nvlist_lookup_nvlist_array(newnv, ZPOOL_CONFIG_L2CACHE,
2522 &newchild, &children) != 0)
2525 if (oldnv && nvlist_lookup_nvlist_array(oldnv, ZPOOL_CONFIG_L2CACHE,
2526 &oldchild, &c) != 0)
2530 (void) printf("%-*s - - - - - "
2531 "-\n", cb->cb_namewidth, "cache");
2532 for (c = 0; c < children; c++) {
2533 vname = zpool_vdev_name(g_zfs, zhp, newchild[c],
2535 print_vdev_stats(zhp, vname, oldnv ? oldchild[c] : NULL,
2536 newchild[c], cb, depth + 2);
2543 refresh_iostat(zpool_handle_t *zhp, void *data)
2545 iostat_cbdata_t *cb = data;
2549 * If the pool has disappeared, remove it from the list and continue.
2551 if (zpool_refresh_stats(zhp, &missing) != 0)
2555 pool_list_remove(cb->cb_list, zhp);
2561 * Callback to print out the iostats for the given pool.
2564 print_iostat(zpool_handle_t *zhp, void *data)
2566 iostat_cbdata_t *cb = data;
2567 nvlist_t *oldconfig, *newconfig;
2568 nvlist_t *oldnvroot, *newnvroot;
2570 newconfig = zpool_get_config(zhp, &oldconfig);
2572 if (cb->cb_iteration == 1)
2575 verify(nvlist_lookup_nvlist(newconfig, ZPOOL_CONFIG_VDEV_TREE,
2578 if (oldconfig == NULL)
2581 verify(nvlist_lookup_nvlist(oldconfig, ZPOOL_CONFIG_VDEV_TREE,
2585 * Print out the statistics for the pool.
2587 print_vdev_stats(zhp, zpool_get_name(zhp), oldnvroot, newnvroot, cb, 0);
2590 print_iostat_separator(cb);
2602 if (isatty(STDOUT_FILENO)) {
2603 error = ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
2605 columns = ws.ws_col;
2614 get_namewidth(zpool_handle_t *zhp, void *data)
2616 iostat_cbdata_t *cb = data;
2617 nvlist_t *config, *nvroot;
2620 if ((config = zpool_get_config(zhp, NULL)) != NULL) {
2621 verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
2623 if (!cb->cb_verbose)
2624 cb->cb_namewidth = strlen(zpool_get_name(zhp));
2626 cb->cb_namewidth = max_width(zhp, nvroot, 0,
2631 * The width must be at least 10, but may be as large as the
2632 * column width - 42 so that we can still fit in one line.
2634 columns = get_columns();
2636 if (cb->cb_namewidth < 10)
2637 cb->cb_namewidth = 10;
2638 if (cb->cb_namewidth > columns - 42)
2639 cb->cb_namewidth = columns - 42;
2645 * Parse the input string, get the 'interval' and 'count' value if there is one.
2648 get_interval_count(int *argcp, char **argv, unsigned long *iv,
2651 unsigned long interval = 0, count = 0;
2655 * Determine if the last argument is an integer or a pool name
2657 if (argc > 0 && isdigit(argv[argc - 1][0])) {
2661 interval = strtoul(argv[argc - 1], &end, 10);
2663 if (*end == '\0' && errno == 0) {
2664 if (interval == 0) {
2665 (void) fprintf(stderr, gettext("interval "
2666 "cannot be zero\n"));
2670 * Ignore the last parameter
2675 * If this is not a valid number, just plow on. The
2676 * user will get a more informative error message later
2684 * If the last argument is also an integer, then we have both a count
2687 if (argc > 0 && isdigit(argv[argc - 1][0])) {
2692 interval = strtoul(argv[argc - 1], &end, 10);
2694 if (*end == '\0' && errno == 0) {
2695 if (interval == 0) {
2696 (void) fprintf(stderr, gettext("interval "
2697 "cannot be zero\n"));
2702 * Ignore the last parameter
2716 get_timestamp_arg(char c)
2719 timestamp_fmt = UDATE;
2721 timestamp_fmt = DDATE;
2727 * zpool iostat [-v] [-T d|u] [pool] ... [interval [count]]
2729 * -v Display statistics for individual vdevs
2730 * -T Display a timestamp in date(1) or Unix format
2732 * This command can be tricky because we want to be able to deal with pool
2733 * creation/destruction as well as vdev configuration changes. The bulk of this
2734 * processing is handled by the pool_list_* routines in zpool_iter.c. We rely
2735 * on pool_list_update() to detect the addition of new pools. Configuration
2736 * changes are all handled within libzfs.
2739 zpool_do_iostat(int argc, char **argv)
2744 unsigned long interval = 0, count = 0;
2746 boolean_t verbose = B_FALSE;
2750 while ((c = getopt(argc, argv, "T:v")) != -1) {
2753 get_timestamp_arg(*optarg);
2759 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
2768 get_interval_count(&argc, argv, &interval, &count);
2771 * Construct the list of all interesting pools.
2774 if ((list = pool_list_get(argc, argv, NULL, &ret)) == NULL)
2777 if (pool_list_count(list) == 0 && argc != 0) {
2778 pool_list_free(list);
2782 if (pool_list_count(list) == 0 && interval == 0) {
2783 pool_list_free(list);
2784 (void) fprintf(stderr, gettext("no pools available\n"));
2789 * Enter the main iostat loop.
2792 cb.cb_verbose = verbose;
2793 cb.cb_iteration = 0;
2794 cb.cb_namewidth = 0;
2797 pool_list_update(list);
2799 if ((npools = pool_list_count(list)) == 0)
2800 (void) fprintf(stderr, gettext("no pools available\n"));
2803 * Refresh all statistics. This is done as an
2804 * explicit step before calculating the maximum name
2805 * width, so that any * configuration changes are
2806 * properly accounted for.
2808 (void) pool_list_iter(list, B_FALSE, refresh_iostat,
2812 * Iterate over all pools to determine the maximum width
2813 * for the pool / device name column across all pools.
2815 cb.cb_namewidth = 0;
2816 (void) pool_list_iter(list, B_FALSE, get_namewidth,
2819 if (timestamp_fmt != NODATE)
2820 print_timestamp(timestamp_fmt);
2823 * If it's the first time, or verbose mode, print the
2826 if (++cb.cb_iteration == 1 || verbose)
2827 print_iostat_header(&cb);
2829 (void) pool_list_iter(list, B_FALSE, print_iostat, &cb);
2832 * If there's more than one pool, and we're not in
2833 * verbose mode (which prints a separator for us),
2834 * then print a separator.
2836 if (npools > 1 && !verbose)
2837 print_iostat_separator(&cb);
2840 (void) printf("\n");
2844 * Flush the output so that redirection to a file isn't buffered
2847 (void) fflush(stdout);
2852 if (count != 0 && --count == 0)
2855 (void) sleep(interval);
2858 pool_list_free(list);
2863 typedef struct list_cbdata {
2864 boolean_t cb_verbose;
2866 boolean_t cb_scripted;
2867 zprop_list_t *cb_proplist;
2871 * Given a list of columns to display, output appropriate headers for each one.
2874 print_header(list_cbdata_t *cb)
2876 zprop_list_t *pl = cb->cb_proplist;
2877 char headerbuf[ZPOOL_MAXPROPLEN];
2879 boolean_t first = B_TRUE;
2880 boolean_t right_justify;
2883 for (; pl != NULL; pl = pl->pl_next) {
2884 width = pl->pl_width;
2885 if (first && cb->cb_verbose) {
2887 * Reset the width to accommodate the verbose listing
2890 width = cb->cb_namewidth;
2898 right_justify = B_FALSE;
2899 if (pl->pl_prop != ZPROP_INVAL) {
2900 header = zpool_prop_column_name(pl->pl_prop);
2901 right_justify = zpool_prop_align_right(pl->pl_prop);
2905 for (i = 0; pl->pl_user_prop[i] != '\0'; i++)
2906 headerbuf[i] = toupper(pl->pl_user_prop[i]);
2907 headerbuf[i] = '\0';
2911 if (pl->pl_next == NULL && !right_justify)
2912 (void) printf("%s", header);
2913 else if (right_justify)
2914 (void) printf("%*s", (int)width, header);
2916 (void) printf("%-*s", (int)width, header);
2919 (void) printf("\n");
2923 * Given a pool and a list of properties, print out all the properties according
2924 * to the described layout.
2927 print_pool(zpool_handle_t *zhp, list_cbdata_t *cb)
2929 zprop_list_t *pl = cb->cb_proplist;
2930 boolean_t first = B_TRUE;
2931 char property[ZPOOL_MAXPROPLEN];
2933 boolean_t right_justify;
2936 for (; pl != NULL; pl = pl->pl_next) {
2938 width = pl->pl_width;
2939 if (first && cb->cb_verbose) {
2941 * Reset the width to accommodate the verbose listing
2944 width = cb->cb_namewidth;
2948 if (cb->cb_scripted)
2949 (void) printf("\t");
2956 right_justify = B_FALSE;
2957 if (pl->pl_prop != ZPROP_INVAL) {
2958 if (pl->pl_prop == ZPOOL_PROP_EXPANDSZ &&
2959 zpool_get_prop_int(zhp, pl->pl_prop, NULL) == 0)
2961 else if (zpool_get_prop(zhp, pl->pl_prop, property,
2962 sizeof (property), NULL) != 0)
2967 right_justify = zpool_prop_align_right(pl->pl_prop);
2968 } else if ((zpool_prop_feature(pl->pl_user_prop) ||
2969 zpool_prop_unsupported(pl->pl_user_prop)) &&
2970 zpool_prop_get_feature(zhp, pl->pl_user_prop, property,
2971 sizeof (property)) == 0) {
2979 * If this is being called in scripted mode, or if this is the
2980 * last column and it is left-justified, don't include a width
2983 if (cb->cb_scripted || (pl->pl_next == NULL && !right_justify))
2984 (void) printf("%s", propstr);
2985 else if (right_justify)
2986 (void) printf("%*s", (int)width, propstr);
2988 (void) printf("%-*s", (int)width, propstr);
2991 (void) printf("\n");
2995 print_one_column(zpool_prop_t prop, uint64_t value, boolean_t scripted)
2999 size_t width = zprop_width(prop, &fixed, ZFS_TYPE_POOL);
3002 if (prop == ZPOOL_PROP_EXPANDSZ && value == 0)
3003 (void) strlcpy(propval, "-", sizeof (propval));
3004 else if (prop == ZPOOL_PROP_FRAGMENTATION && value == ZFS_FRAG_INVALID)
3005 (void) strlcpy(propval, "-", sizeof (propval));
3006 else if (prop == ZPOOL_PROP_FRAGMENTATION)
3007 (void) snprintf(propval, sizeof (propval), "%llu%%",
3008 (unsigned long long)value);
3010 zfs_nicenum(value, propval, sizeof (propval));
3013 (void) printf("\t%s", propval);
3015 (void) printf(" %*s", (int)width, propval);
3019 print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
3020 list_cbdata_t *cb, int depth)
3026 boolean_t scripted = cb->cb_scripted;
3028 verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
3029 (uint64_t **)&vs, &c) == 0);
3033 (void) printf("\t%s", name);
3034 else if (strlen(name) + depth > cb->cb_namewidth)
3035 (void) printf("%*s%s", depth, "", name);
3037 (void) printf("%*s%s%*s", depth, "", name,
3038 (int)(cb->cb_namewidth - strlen(name) - depth), "");
3040 /* only toplevel vdevs have capacity stats */
3041 if (vs->vs_space == 0) {
3043 (void) printf("\t-\t-\t-\t-");
3045 (void) printf(" - - - -");
3047 print_one_column(ZPOOL_PROP_SIZE, vs->vs_space,
3049 print_one_column(ZPOOL_PROP_CAPACITY, vs->vs_alloc,
3051 print_one_column(ZPOOL_PROP_FREE,
3052 vs->vs_space - vs->vs_alloc, scripted);
3053 print_one_column(ZPOOL_PROP_FRAGMENTATION,
3054 vs->vs_fragmentation, scripted);
3056 print_one_column(ZPOOL_PROP_EXPANDSZ, vs->vs_esize,
3058 (void) printf("\n");
3061 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
3062 &child, &children) != 0)
3065 for (c = 0; c < children; c++) {
3066 uint64_t ishole = B_FALSE;
3068 if (nvlist_lookup_uint64(child[c],
3069 ZPOOL_CONFIG_IS_HOLE, &ishole) == 0 && ishole)
3072 vname = zpool_vdev_name(g_zfs, zhp, child[c], B_FALSE);
3073 print_list_stats(zhp, vname, child[c], cb, depth + 2);
3078 * Include level 2 ARC devices in iostat output
3080 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
3081 &child, &children) != 0)
3085 (void) printf("%-*s - - - - - "
3086 "-\n", cb->cb_namewidth, "cache");
3087 for (c = 0; c < children; c++) {
3088 vname = zpool_vdev_name(g_zfs, zhp, child[c],
3090 print_list_stats(zhp, vname, child[c], cb, depth + 2);
3098 * Generic callback function to list a pool.
3101 list_callback(zpool_handle_t *zhp, void *data)
3103 list_cbdata_t *cbp = data;
3107 config = zpool_get_config(zhp, NULL);
3109 print_pool(zhp, cbp);
3110 if (!cbp->cb_verbose)
3113 verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
3115 print_list_stats(zhp, NULL, nvroot, cbp, 0);
3121 * zpool list [-H] [-o prop[,prop]*] [-T d|u] [pool] ... [interval [count]]
3123 * -H Scripted mode. Don't display headers, and separate properties
3125 * -o List of properties to display. Defaults to
3126 * "name,size,allocated,free,capacity,health,altroot"
3127 * -T Display a timestamp in date(1) or Unix format
3129 * List all pools in the system, whether or not they're healthy. Output space
3130 * statistics for each one, as well as health status summary.
3133 zpool_do_list(int argc, char **argv)
3137 list_cbdata_t cb = { 0 };
3138 static char default_props[] =
3139 "name,size,allocated,free,fragmentation,capacity,"
3140 "dedupratio,health,altroot";
3141 char *props = default_props;
3142 unsigned long interval = 0, count = 0;
3144 boolean_t first = B_TRUE;
3147 while ((c = getopt(argc, argv, ":Ho:T:v")) != -1) {
3150 cb.cb_scripted = B_TRUE;
3156 get_timestamp_arg(*optarg);
3159 cb.cb_verbose = B_TRUE;
3162 (void) fprintf(stderr, gettext("missing argument for "
3163 "'%c' option\n"), optopt);
3167 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
3176 get_interval_count(&argc, argv, &interval, &count);
3178 if (zprop_get_list(g_zfs, props, &cb.cb_proplist, ZFS_TYPE_POOL) != 0)
3181 if ((list = pool_list_get(argc, argv, &cb.cb_proplist, &ret)) == NULL)
3184 if (argc == 0 && !cb.cb_scripted && pool_list_count(list) == 0) {
3185 (void) printf(gettext("no pools available\n"));
3186 zprop_free_list(cb.cb_proplist);
3191 pool_list_update(list);
3193 if (pool_list_count(list) == 0)
3196 if (timestamp_fmt != NODATE)
3197 print_timestamp(timestamp_fmt);
3199 if (!cb.cb_scripted && (first || cb.cb_verbose)) {
3203 ret = pool_list_iter(list, B_TRUE, list_callback, &cb);
3208 if (count != 0 && --count == 0)
3211 (void) sleep(interval);
3214 zprop_free_list(cb.cb_proplist);
3219 zpool_do_attach_or_replace(int argc, char **argv, int replacing)
3221 boolean_t force = B_FALSE;
3224 char *poolname, *old_disk, *new_disk;
3225 zpool_handle_t *zhp;
3226 nvlist_t *props = NULL;
3231 while ((c = getopt(argc, argv, "fo:")) != -1) {
3237 if ((propval = strchr(optarg, '=')) == NULL) {
3238 (void) fprintf(stderr, gettext("missing "
3239 "'=' for -o option\n"));
3245 if ((strcmp(optarg, ZPOOL_CONFIG_ASHIFT) != 0) ||
3246 (add_prop_list(optarg, propval, &props, B_TRUE)))
3250 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
3259 /* get pool name and check number of arguments */
3261 (void) fprintf(stderr, gettext("missing pool name argument\n"));
3268 (void) fprintf(stderr,
3269 gettext("missing <device> specification\n"));
3277 (void) fprintf(stderr,
3278 gettext("missing <new_device> specification\n"));
3281 new_disk = old_disk;
3291 (void) fprintf(stderr, gettext("too many arguments\n"));
3295 if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
3298 if (zpool_get_config(zhp, NULL) == NULL) {
3299 (void) fprintf(stderr, gettext("pool '%s' is unavailable\n"),
3305 nvroot = make_root_vdev(zhp, props, force, B_FALSE, replacing, B_FALSE,
3307 if (nvroot == NULL) {
3312 ret = zpool_vdev_attach(zhp, old_disk, new_disk, nvroot, replacing);
3314 nvlist_free(nvroot);
3321 * zpool replace [-f] <pool> <device> <new_device>
3323 * -f Force attach, even if <new_device> appears to be in use.
3325 * Replace <device> with <new_device>.
3329 zpool_do_replace(int argc, char **argv)
3331 return (zpool_do_attach_or_replace(argc, argv, B_TRUE));
3335 * zpool attach [-f] [-o property=value] <pool> <device> <new_device>
3337 * -f Force attach, even if <new_device> appears to be in use.
3338 * -o Set property=value.
3340 * Attach <new_device> to the mirror containing <device>. If <device> is not
3341 * part of a mirror, then <device> will be transformed into a mirror of
3342 * <device> and <new_device>. In either case, <new_device> will begin life
3343 * with a DTL of [0, now], and will immediately begin to resilver itself.
3346 zpool_do_attach(int argc, char **argv)
3348 return (zpool_do_attach_or_replace(argc, argv, B_FALSE));
3352 * zpool detach [-f] <pool> <device>
3354 * -f Force detach of <device>, even if DTLs argue against it
3355 * (not supported yet)
3357 * Detach a device from a mirror. The operation will be refused if <device>
3358 * is the last device in the mirror, or if the DTLs indicate that this device
3359 * has the only valid copy of some data.
3363 zpool_do_detach(int argc, char **argv)
3366 char *poolname, *path;
3367 zpool_handle_t *zhp;
3371 while ((c = getopt(argc, argv, "f")) != -1) {
3375 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
3384 /* get pool name and check number of arguments */
3386 (void) fprintf(stderr, gettext("missing pool name argument\n"));
3391 (void) fprintf(stderr,
3392 gettext("missing <device> specification\n"));
3399 if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
3402 ret = zpool_vdev_detach(zhp, path);
3410 * zpool split [-n] [-o prop=val] ...
3412 * [-R altroot] <pool> <newpool> [<device> ...]
3414 * -n Do not split the pool, but display the resulting layout if
3415 * it were to be split.
3416 * -o Set property=value, or set mount options.
3417 * -R Mount the split-off pool under an alternate root.
3419 * Splits the named pool and gives it the new pool name. Devices to be split
3420 * off may be listed, provided that no more than one device is specified
3421 * per top-level vdev mirror. The newly split pool is left in an exported
3422 * state unless -R is specified.
3424 * Restrictions: the top-level of the pool pool must only be made up of
3425 * mirrors; all devices in the pool must be healthy; no device may be
3426 * undergoing a resilvering operation.
3429 zpool_do_split(int argc, char **argv)
3431 char *srcpool, *newpool, *propval;
3432 char *mntopts = NULL;
3435 zpool_handle_t *zhp;
3436 nvlist_t *config, *props = NULL;
3438 flags.dryrun = B_FALSE;
3439 flags.import = B_FALSE;
3442 while ((c = getopt(argc, argv, ":R:no:")) != -1) {
3445 flags.import = B_TRUE;
3447 zpool_prop_to_name(ZPOOL_PROP_ALTROOT), optarg,
3448 &props, B_TRUE) != 0) {
3455 flags.dryrun = B_TRUE;
3458 if ((propval = strchr(optarg, '=')) != NULL) {
3461 if (add_prop_list(optarg, propval,
3462 &props, B_TRUE) != 0) {
3472 (void) fprintf(stderr, gettext("missing argument for "
3473 "'%c' option\n"), optopt);
3477 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
3484 if (!flags.import && mntopts != NULL) {
3485 (void) fprintf(stderr, gettext("setting mntopts is only "
3486 "valid when importing the pool\n"));
3494 (void) fprintf(stderr, gettext("Missing pool name\n"));
3498 (void) fprintf(stderr, gettext("Missing new pool name\n"));
3508 if ((zhp = zpool_open(g_zfs, srcpool)) == NULL)
3511 config = split_mirror_vdev(zhp, newpool, props, flags, argc, argv);
3512 if (config == NULL) {
3516 (void) printf(gettext("would create '%s' with the "
3517 "following layout:\n\n"), newpool);
3518 print_vdev_tree(NULL, newpool, config, 0, B_FALSE);
3520 nvlist_free(config);
3525 if (ret != 0 || flags.dryrun || !flags.import)
3529 * The split was successful. Now we need to open the new
3530 * pool and import it.
3532 if ((zhp = zpool_open_canfail(g_zfs, newpool)) == NULL)
3534 if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL &&
3535 zpool_enable_datasets(zhp, mntopts, 0) != 0) {
3537 (void) fprintf(stderr, gettext("Split was successful, but "
3538 "the datasets could not all be mounted\n"));
3539 (void) fprintf(stderr, gettext("Try doing '%s' with a "
3540 "different altroot\n"), "zpool import");
3550 * zpool online <pool> <device> ...
3553 zpool_do_online(int argc, char **argv)
3557 zpool_handle_t *zhp;
3559 vdev_state_t newstate;
3563 while ((c = getopt(argc, argv, "et")) != -1) {
3566 flags |= ZFS_ONLINE_EXPAND;
3570 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
3579 /* get pool name and check number of arguments */
3581 (void) fprintf(stderr, gettext("missing pool name\n"));
3585 (void) fprintf(stderr, gettext("missing device name\n"));
3591 if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
3594 for (i = 1; i < argc; i++) {
3595 if (zpool_vdev_online(zhp, argv[i], flags, &newstate) == 0) {
3596 if (newstate != VDEV_STATE_HEALTHY) {
3597 (void) printf(gettext("warning: device '%s' "
3598 "onlined, but remains in faulted state\n"),
3600 if (newstate == VDEV_STATE_FAULTED)
3601 (void) printf(gettext("use 'zpool "
3602 "clear' to restore a faulted "
3605 (void) printf(gettext("use 'zpool "
3606 "replace' to replace devices "
3607 "that are no longer present\n"));
3620 * zpool offline [-ft] <pool> <device> ...
3622 * -f Force the device into the offline state, even if doing
3623 * so would appear to compromise pool availability.
3624 * (not supported yet)
3626 * -t Only take the device off-line temporarily. The offline
3627 * state will not be persistent across reboots.
3631 zpool_do_offline(int argc, char **argv)
3635 zpool_handle_t *zhp;
3637 boolean_t istmp = B_FALSE;
3640 while ((c = getopt(argc, argv, "ft")) != -1) {
3647 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
3656 /* get pool name and check number of arguments */
3658 (void) fprintf(stderr, gettext("missing pool name\n"));
3662 (void) fprintf(stderr, gettext("missing device name\n"));
3668 if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
3671 for (i = 1; i < argc; i++) {
3672 if (zpool_vdev_offline(zhp, argv[i], istmp) != 0)
3682 * zpool clear <pool> [device]
3684 * Clear all errors associated with a pool or a particular device.
3687 zpool_do_clear(int argc, char **argv)
3691 boolean_t dryrun = B_FALSE;
3692 boolean_t do_rewind = B_FALSE;
3693 boolean_t xtreme_rewind = B_FALSE;
3694 uint32_t rewind_policy = ZPOOL_NO_REWIND;
3695 nvlist_t *policy = NULL;
3696 zpool_handle_t *zhp;
3697 char *pool, *device;
3700 while ((c = getopt(argc, argv, "FnX")) != -1) {
3709 xtreme_rewind = B_TRUE;
3712 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
3722 (void) fprintf(stderr, gettext("missing pool name\n"));
3727 (void) fprintf(stderr, gettext("too many arguments\n"));
3731 if ((dryrun || xtreme_rewind) && !do_rewind) {
3732 (void) fprintf(stderr,
3733 gettext("-n or -X only meaningful with -F\n"));
3737 rewind_policy = ZPOOL_TRY_REWIND;
3739 rewind_policy = ZPOOL_DO_REWIND;
3741 rewind_policy |= ZPOOL_EXTREME_REWIND;
3743 /* In future, further rewind policy choices can be passed along here */
3744 if (nvlist_alloc(&policy, NV_UNIQUE_NAME, 0) != 0 ||
3745 nvlist_add_uint32(policy, ZPOOL_REWIND_REQUEST, rewind_policy) != 0)
3749 device = argc == 2 ? argv[1] : NULL;
3751 if ((zhp = zpool_open_canfail(g_zfs, pool)) == NULL) {
3752 nvlist_free(policy);
3756 if (zpool_clear(zhp, device, policy) != 0)
3761 nvlist_free(policy);
3767 * zpool reguid <pool>
3770 zpool_do_reguid(int argc, char **argv)
3774 zpool_handle_t *zhp;
3778 while ((c = getopt(argc, argv, "")) != -1) {
3781 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
3790 /* get pool name and check number of arguments */
3792 (void) fprintf(stderr, gettext("missing pool name\n"));
3797 (void) fprintf(stderr, gettext("too many arguments\n"));
3802 if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
3805 ret = zpool_reguid(zhp);
3813 * zpool reopen <pool>
3815 * Reopen the pool so that the kernel can update the sizes of all vdevs.
3818 zpool_do_reopen(int argc, char **argv)
3822 zpool_handle_t *zhp;
3826 while ((c = getopt(argc, argv, "")) != -1) {
3829 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
3839 (void) fprintf(stderr, gettext("missing pool name\n"));
3844 (void) fprintf(stderr, gettext("too many arguments\n"));
3849 if ((zhp = zpool_open_canfail(g_zfs, pool)) == NULL)
3852 ret = zpool_reopen(zhp);
3857 typedef struct scrub_cbdata {
3864 scrub_callback(zpool_handle_t *zhp, void *data)
3866 scrub_cbdata_t *cb = data;
3870 * Ignore faulted pools.
3872 if (zpool_get_state(zhp) == POOL_STATE_UNAVAIL) {
3873 (void) fprintf(stderr, gettext("cannot scrub '%s': pool is "
3874 "currently unavailable\n"), zpool_get_name(zhp));
3878 err = zpool_scan(zhp, cb->cb_type);
3884 * zpool scrub [-s] <pool> ...
3886 * -s Stop. Stops any in-progress scrub.
3889 zpool_do_scrub(int argc, char **argv)
3894 cb.cb_type = POOL_SCAN_SCRUB;
3897 while ((c = getopt(argc, argv, "s")) != -1) {
3900 cb.cb_type = POOL_SCAN_NONE;
3903 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
3915 (void) fprintf(stderr, gettext("missing pool name argument\n"));
3919 return (for_each_pool(argc, argv, B_TRUE, NULL, scrub_callback, &cb));
3922 typedef struct status_cbdata {
3924 boolean_t cb_allpools;
3925 boolean_t cb_verbose;
3926 boolean_t cb_explain;
3928 boolean_t cb_dedup_stats;
3932 * Print out detailed scrub status.
3935 print_scan_status(pool_scan_stat_t *ps)
3938 uint64_t elapsed, mins_left, hours_left;
3939 uint64_t pass_exam, examined, total;
3941 double fraction_done;
3942 char processed_buf[7], examined_buf[7], total_buf[7], rate_buf[7];
3944 (void) printf(gettext(" scan: "));
3946 /* If there's never been a scan, there's not much to say. */
3947 if (ps == NULL || ps->pss_func == POOL_SCAN_NONE ||
3948 ps->pss_func >= POOL_SCAN_FUNCS) {
3949 (void) printf(gettext("none requested\n"));
3953 start = ps->pss_start_time;
3954 end = ps->pss_end_time;
3955 zfs_nicenum(ps->pss_processed, processed_buf, sizeof (processed_buf));
3957 assert(ps->pss_func == POOL_SCAN_SCRUB ||
3958 ps->pss_func == POOL_SCAN_RESILVER);
3960 * Scan is finished or canceled.
3962 if (ps->pss_state == DSS_FINISHED) {
3963 uint64_t minutes_taken = (end - start) / 60;
3966 if (ps->pss_func == POOL_SCAN_SCRUB) {
3967 fmt = gettext("scrub repaired %s in %lluh%um with "
3968 "%llu errors on %s");
3969 } else if (ps->pss_func == POOL_SCAN_RESILVER) {
3970 fmt = gettext("resilvered %s in %lluh%um with "
3971 "%llu errors on %s");
3974 (void) printf(fmt, processed_buf,
3975 (u_longlong_t)(minutes_taken / 60),
3976 (uint_t)(minutes_taken % 60),
3977 (u_longlong_t)ps->pss_errors,
3978 ctime((time_t *)&end));
3980 } else if (ps->pss_state == DSS_CANCELED) {
3981 if (ps->pss_func == POOL_SCAN_SCRUB) {
3982 (void) printf(gettext("scrub canceled on %s"),
3984 } else if (ps->pss_func == POOL_SCAN_RESILVER) {
3985 (void) printf(gettext("resilver canceled on %s"),
3991 assert(ps->pss_state == DSS_SCANNING);
3994 * Scan is in progress.
3996 if (ps->pss_func == POOL_SCAN_SCRUB) {
3997 (void) printf(gettext("scrub in progress since %s"),
3999 } else if (ps->pss_func == POOL_SCAN_RESILVER) {
4000 (void) printf(gettext("resilver in progress since %s"),
4004 examined = ps->pss_examined ? ps->pss_examined : 1;
4005 total = ps->pss_to_examine;
4006 fraction_done = (double)examined / total;
4008 /* elapsed time for this pass */
4009 elapsed = time(NULL) - ps->pss_pass_start;
4010 elapsed = elapsed ? elapsed : 1;
4011 pass_exam = ps->pss_pass_exam ? ps->pss_pass_exam : 1;
4012 rate = pass_exam / elapsed;
4013 rate = rate ? rate : 1;
4014 mins_left = ((total - examined) / rate) / 60;
4015 hours_left = mins_left / 60;
4017 zfs_nicenum(examined, examined_buf, sizeof (examined_buf));
4018 zfs_nicenum(total, total_buf, sizeof (total_buf));
4019 zfs_nicenum(rate, rate_buf, sizeof (rate_buf));
4022 * do not print estimated time if hours_left is more than 30 days
4024 (void) printf(gettext(" %s scanned out of %s at %s/s"),
4025 examined_buf, total_buf, rate_buf);
4026 if (hours_left < (30 * 24)) {
4027 (void) printf(gettext(", %lluh%um to go\n"),
4028 (u_longlong_t)hours_left, (uint_t)(mins_left % 60));
4030 (void) printf(gettext(
4031 ", (scan is slow, no estimated time)\n"));
4034 if (ps->pss_func == POOL_SCAN_RESILVER) {
4035 (void) printf(gettext(" %s resilvered, %.2f%% done\n"),
4036 processed_buf, 100 * fraction_done);
4037 } else if (ps->pss_func == POOL_SCAN_SCRUB) {
4038 (void) printf(gettext(" %s repaired, %.2f%% done\n"),
4039 processed_buf, 100 * fraction_done);
4044 print_error_log(zpool_handle_t *zhp)
4046 nvlist_t *nverrlist = NULL;
4049 size_t len = MAXPATHLEN * 2;
4051 if (zpool_get_errlog(zhp, &nverrlist) != 0) {
4052 (void) printf("errors: List of errors unavailable "
4053 "(insufficient privileges)\n");
4057 (void) printf("errors: Permanent errors have been "
4058 "detected in the following files:\n\n");
4060 pathname = safe_malloc(len);
4062 while ((elem = nvlist_next_nvpair(nverrlist, elem)) != NULL) {
4064 uint64_t dsobj, obj;
4066 verify(nvpair_value_nvlist(elem, &nv) == 0);
4067 verify(nvlist_lookup_uint64(nv, ZPOOL_ERR_DATASET,
4069 verify(nvlist_lookup_uint64(nv, ZPOOL_ERR_OBJECT,
4071 zpool_obj_to_path(zhp, dsobj, obj, pathname, len);
4072 (void) printf("%7s %s\n", "", pathname);
4075 nvlist_free(nverrlist);
4079 print_spares(zpool_handle_t *zhp, nvlist_t **spares, uint_t nspares,
4088 (void) printf(gettext("\tspares\n"));
4090 for (i = 0; i < nspares; i++) {
4091 name = zpool_vdev_name(g_zfs, zhp, spares[i], B_FALSE);
4092 print_status_config(zhp, name, spares[i],
4093 namewidth, 2, B_TRUE);
4099 print_l2cache(zpool_handle_t *zhp, nvlist_t **l2cache, uint_t nl2cache,
4108 (void) printf(gettext("\tcache\n"));
4110 for (i = 0; i < nl2cache; i++) {
4111 name = zpool_vdev_name(g_zfs, zhp, l2cache[i], B_FALSE);
4112 print_status_config(zhp, name, l2cache[i],
4113 namewidth, 2, B_FALSE);
4119 print_dedup_stats(nvlist_t *config)
4121 ddt_histogram_t *ddh;
4127 * If the pool was faulted then we may not have been able to
4128 * obtain the config. Otherwise, if we have anything in the dedup
4129 * table continue processing the stats.
4131 if (nvlist_lookup_uint64_array(config, ZPOOL_CONFIG_DDT_OBJ_STATS,
4132 (uint64_t **)&ddo, &c) != 0)
4135 (void) printf("\n");
4136 (void) printf(gettext(" dedup: "));
4137 if (ddo->ddo_count == 0) {
4138 (void) printf(gettext("no DDT entries\n"));
4142 (void) printf("DDT entries %llu, size %llu on disk, %llu in core\n",
4143 (u_longlong_t)ddo->ddo_count,
4144 (u_longlong_t)ddo->ddo_dspace,
4145 (u_longlong_t)ddo->ddo_mspace);
4147 verify(nvlist_lookup_uint64_array(config, ZPOOL_CONFIG_DDT_STATS,
4148 (uint64_t **)&dds, &c) == 0);
4149 verify(nvlist_lookup_uint64_array(config, ZPOOL_CONFIG_DDT_HISTOGRAM,
4150 (uint64_t **)&ddh, &c) == 0);
4151 zpool_dump_ddt(dds, ddh);
4155 * Display a summary of pool status. Displays a summary such as:
4159 * reason: One or more devices ...
4160 * see: http://zfsonlinux.org/msg/ZFS-xxxx-01
4166 * When given the '-v' option, we print out the complete config. If the '-e'
4167 * option is specified, then we print out error rate information as well.
4170 status_callback(zpool_handle_t *zhp, void *data)
4172 status_cbdata_t *cbp = data;
4173 nvlist_t *config, *nvroot;
4175 zpool_status_t reason;
4176 zpool_errata_t errata;
4181 config = zpool_get_config(zhp, NULL);
4182 reason = zpool_get_status(zhp, &msgid, &errata);
4187 * If we were given 'zpool status -x', only report those pools with
4190 if (cbp->cb_explain &&
4191 (reason == ZPOOL_STATUS_OK ||
4192 reason == ZPOOL_STATUS_VERSION_OLDER ||
4193 reason == ZPOOL_STATUS_FEAT_DISABLED)) {
4194 if (!cbp->cb_allpools) {
4195 (void) printf(gettext("pool '%s' is healthy\n"),
4196 zpool_get_name(zhp));
4198 cbp->cb_first = B_FALSE;
4204 cbp->cb_first = B_FALSE;
4206 (void) printf("\n");
4208 verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
4210 verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_VDEV_STATS,
4211 (uint64_t **)&vs, &c) == 0);
4212 health = zpool_state_to_name(vs->vs_state, vs->vs_aux);
4214 (void) printf(gettext(" pool: %s\n"), zpool_get_name(zhp));
4215 (void) printf(gettext(" state: %s\n"), health);
4218 case ZPOOL_STATUS_MISSING_DEV_R:
4219 (void) printf(gettext("status: One or more devices could not "
4220 "be opened. Sufficient replicas exist for\n\tthe pool to "
4221 "continue functioning in a degraded state.\n"));
4222 (void) printf(gettext("action: Attach the missing device and "
4223 "online it using 'zpool online'.\n"));
4226 case ZPOOL_STATUS_MISSING_DEV_NR:
4227 (void) printf(gettext("status: One or more devices could not "
4228 "be opened. There are insufficient\n\treplicas for the "
4229 "pool to continue functioning.\n"));
4230 (void) printf(gettext("action: Attach the missing device and "
4231 "online it using 'zpool online'.\n"));
4234 case ZPOOL_STATUS_CORRUPT_LABEL_R:
4235 (void) printf(gettext("status: One or more devices could not "
4236 "be used because the label is missing or\n\tinvalid. "
4237 "Sufficient replicas exist for the pool to continue\n\t"
4238 "functioning in a degraded state.\n"));
4239 (void) printf(gettext("action: Replace the device using "
4240 "'zpool replace'.\n"));
4243 case ZPOOL_STATUS_CORRUPT_LABEL_NR:
4244 (void) printf(gettext("status: One or more devices could not "
4245 "be used because the label is missing \n\tor invalid. "
4246 "There are insufficient replicas for the pool to "
4247 "continue\n\tfunctioning.\n"));
4248 zpool_explain_recover(zpool_get_handle(zhp),
4249 zpool_get_name(zhp), reason, config);
4252 case ZPOOL_STATUS_FAILING_DEV:
4253 (void) printf(gettext("status: One or more devices has "
4254 "experienced an unrecoverable error. An\n\tattempt was "
4255 "made to correct the error. Applications are "
4257 (void) printf(gettext("action: Determine if the device needs "
4258 "to be replaced, and clear the errors\n\tusing "
4259 "'zpool clear' or replace the device with 'zpool "
4263 case ZPOOL_STATUS_OFFLINE_DEV:
4264 (void) printf(gettext("status: One or more devices has "
4265 "been taken offline by the administrator.\n\tSufficient "
4266 "replicas exist for the pool to continue functioning in "
4267 "a\n\tdegraded state.\n"));
4268 (void) printf(gettext("action: Online the device using "
4269 "'zpool online' or replace the device with\n\t'zpool "
4273 case ZPOOL_STATUS_REMOVED_DEV:
4274 (void) printf(gettext("status: One or more devices has "
4275 "been removed by the administrator.\n\tSufficient "
4276 "replicas exist for the pool to continue functioning in "
4277 "a\n\tdegraded state.\n"));
4278 (void) printf(gettext("action: Online the device using "
4279 "'zpool online' or replace the device with\n\t'zpool "
4283 case ZPOOL_STATUS_RESILVERING:
4284 (void) printf(gettext("status: One or more devices is "
4285 "currently being resilvered. The pool will\n\tcontinue "
4286 "to function, possibly in a degraded state.\n"));
4287 (void) printf(gettext("action: Wait for the resilver to "
4291 case ZPOOL_STATUS_CORRUPT_DATA:
4292 (void) printf(gettext("status: One or more devices has "
4293 "experienced an error resulting in data\n\tcorruption. "
4294 "Applications may be affected.\n"));
4295 (void) printf(gettext("action: Restore the file in question "
4296 "if possible. Otherwise restore the\n\tentire pool from "
4300 case ZPOOL_STATUS_CORRUPT_POOL:
4301 (void) printf(gettext("status: The pool metadata is corrupted "
4302 "and the pool cannot be opened.\n"));
4303 zpool_explain_recover(zpool_get_handle(zhp),
4304 zpool_get_name(zhp), reason, config);
4307 case ZPOOL_STATUS_VERSION_OLDER:
4308 (void) printf(gettext("status: The pool is formatted using a "
4309 "legacy on-disk format. The pool can\n\tstill be used, "
4310 "but some features are unavailable.\n"));
4311 (void) printf(gettext("action: Upgrade the pool using 'zpool "
4312 "upgrade'. Once this is done, the\n\tpool will no longer "
4313 "be accessible on software that does not support\n\t"
4314 "feature flags.\n"));
4317 case ZPOOL_STATUS_VERSION_NEWER:
4318 (void) printf(gettext("status: The pool has been upgraded to a "
4319 "newer, incompatible on-disk version.\n\tThe pool cannot "
4320 "be accessed on this system.\n"));
4321 (void) printf(gettext("action: Access the pool from a system "
4322 "running more recent software, or\n\trestore the pool from "
4326 case ZPOOL_STATUS_FEAT_DISABLED:
4327 (void) printf(gettext("status: Some supported features are not "
4328 "enabled on the pool. The pool can\n\tstill be used, but "
4329 "some features are unavailable.\n"));
4330 (void) printf(gettext("action: Enable all features using "
4331 "'zpool upgrade'. Once this is done,\n\tthe pool may no "
4332 "longer be accessible by software that does not support\n\t"
4333 "the features. See zpool-features(5) for details.\n"));
4336 case ZPOOL_STATUS_UNSUP_FEAT_READ:
4337 (void) printf(gettext("status: The pool cannot be accessed on "
4338 "this system because it uses the\n\tfollowing feature(s) "
4339 "not supported on this system:\n"));
4340 zpool_print_unsup_feat(config);
4341 (void) printf("\n");
4342 (void) printf(gettext("action: Access the pool from a system "
4343 "that supports the required feature(s),\n\tor restore the "
4344 "pool from backup.\n"));
4347 case ZPOOL_STATUS_UNSUP_FEAT_WRITE:
4348 (void) printf(gettext("status: The pool can only be accessed "
4349 "in read-only mode on this system. It\n\tcannot be "
4350 "accessed in read-write mode because it uses the "
4351 "following\n\tfeature(s) not supported on this system:\n"));
4352 zpool_print_unsup_feat(config);
4353 (void) printf("\n");
4354 (void) printf(gettext("action: The pool cannot be accessed in "
4355 "read-write mode. Import the pool with\n"
4356 "\t\"-o readonly=on\", access the pool from a system that "
4357 "supports the\n\trequired feature(s), or restore the "
4358 "pool from backup.\n"));
4361 case ZPOOL_STATUS_FAULTED_DEV_R:
4362 (void) printf(gettext("status: One or more devices are "
4363 "faulted in response to persistent errors.\n\tSufficient "
4364 "replicas exist for the pool to continue functioning "
4365 "in a\n\tdegraded state.\n"));
4366 (void) printf(gettext("action: Replace the faulted device, "
4367 "or use 'zpool clear' to mark the device\n\trepaired.\n"));
4370 case ZPOOL_STATUS_FAULTED_DEV_NR:
4371 (void) printf(gettext("status: One or more devices are "
4372 "faulted in response to persistent errors. There are "
4373 "insufficient replicas for the pool to\n\tcontinue "
4375 (void) printf(gettext("action: Destroy and re-create the pool "
4376 "from a backup source. Manually marking the device\n"
4377 "\trepaired using 'zpool clear' may allow some data "
4378 "to be recovered.\n"));
4381 case ZPOOL_STATUS_IO_FAILURE_WAIT:
4382 case ZPOOL_STATUS_IO_FAILURE_CONTINUE:
4383 (void) printf(gettext("status: One or more devices are "
4384 "faulted in response to IO failures.\n"));
4385 (void) printf(gettext("action: Make sure the affected devices "
4386 "are connected, then run 'zpool clear'.\n"));
4389 case ZPOOL_STATUS_BAD_LOG:
4390 (void) printf(gettext("status: An intent log record "
4391 "could not be read.\n"
4392 "\tWaiting for adminstrator intervention to fix the "
4393 "faulted pool.\n"));
4394 (void) printf(gettext("action: Either restore the affected "
4395 "device(s) and run 'zpool online',\n"
4396 "\tor ignore the intent log records by running "
4397 "'zpool clear'.\n"));
4400 case ZPOOL_STATUS_HOSTID_MISMATCH:
4401 (void) printf(gettext("status: Mismatch between pool hostid "
4402 "and system hostid on imported pool.\n\tThis pool was "
4403 "previously imported into a system with a different "
4404 "hostid,\n\tand then was verbatim imported into this "
4406 (void) printf(gettext("action: Export this pool on all systems "
4407 "on which it is imported.\n"
4408 "\tThen import it to correct the mismatch.\n"));
4411 case ZPOOL_STATUS_ERRATA:
4412 (void) printf(gettext("status: Errata #%d detected.\n"),
4416 case ZPOOL_ERRATA_NONE:
4419 case ZPOOL_ERRATA_ZOL_2094_SCRUB:
4420 (void) printf(gettext("action: To correct the issue "
4421 "run 'zpool scrub'.\n"));
4426 * All errata which allow the pool to be imported
4427 * must contain an action message.
4435 * The remaining errors can't actually be generated, yet.
4437 assert(reason == ZPOOL_STATUS_OK);
4441 (void) printf(gettext(" see: http://zfsonlinux.org/msg/%s\n"),
4444 if (config != NULL) {
4447 nvlist_t **spares, **l2cache;
4448 uint_t nspares, nl2cache;
4449 pool_scan_stat_t *ps = NULL;
4451 (void) nvlist_lookup_uint64_array(nvroot,
4452 ZPOOL_CONFIG_SCAN_STATS, (uint64_t **)&ps, &c);
4453 print_scan_status(ps);
4455 namewidth = max_width(zhp, nvroot, 0, 0);
4459 (void) printf(gettext("config:\n\n"));
4460 (void) printf(gettext("\t%-*s %-8s %5s %5s %5s\n"), namewidth,
4461 "NAME", "STATE", "READ", "WRITE", "CKSUM");
4462 print_status_config(zhp, zpool_get_name(zhp), nvroot,
4463 namewidth, 0, B_FALSE);
4465 if (num_logs(nvroot) > 0)
4466 print_logs(zhp, nvroot, namewidth, B_TRUE);
4467 if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE,
4468 &l2cache, &nl2cache) == 0)
4469 print_l2cache(zhp, l2cache, nl2cache, namewidth);
4471 if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
4472 &spares, &nspares) == 0)
4473 print_spares(zhp, spares, nspares, namewidth);
4475 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_ERRCOUNT,
4477 nvlist_t *nverrlist = NULL;
4480 * If the approximate error count is small, get a
4481 * precise count by fetching the entire log and
4482 * uniquifying the results.
4484 if (nerr > 0 && nerr < 100 && !cbp->cb_verbose &&
4485 zpool_get_errlog(zhp, &nverrlist) == 0) {
4490 while ((elem = nvlist_next_nvpair(nverrlist,
4495 nvlist_free(nverrlist);
4497 (void) printf("\n");
4500 (void) printf(gettext("errors: No known data "
4502 else if (!cbp->cb_verbose)
4503 (void) printf(gettext("errors: %llu data "
4504 "errors, use '-v' for a list\n"),
4505 (u_longlong_t)nerr);
4507 print_error_log(zhp);
4510 if (cbp->cb_dedup_stats)
4511 print_dedup_stats(config);
4513 (void) printf(gettext("config: The configuration cannot be "
4521 * zpool status [-vx] [-T d|u] [pool] ... [interval [count]]
4523 * -v Display complete error logs
4524 * -x Display only pools with potential problems
4525 * -D Display dedup status (undocumented)
4526 * -T Display a timestamp in date(1) or Unix format
4528 * Describes the health status of all pools or some subset.
4531 zpool_do_status(int argc, char **argv)
4535 unsigned long interval = 0, count = 0;
4536 status_cbdata_t cb = { 0 };
4539 while ((c = getopt(argc, argv, "vxDT:")) != -1) {
4542 cb.cb_verbose = B_TRUE;
4545 cb.cb_explain = B_TRUE;
4548 cb.cb_dedup_stats = B_TRUE;
4551 get_timestamp_arg(*optarg);
4554 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
4563 get_interval_count(&argc, argv, &interval, &count);
4566 cb.cb_allpools = B_TRUE;
4568 cb.cb_first = B_TRUE;
4571 if (timestamp_fmt != NODATE)
4572 print_timestamp(timestamp_fmt);
4574 ret = for_each_pool(argc, argv, B_TRUE, NULL,
4575 status_callback, &cb);
4577 if (argc == 0 && cb.cb_count == 0)
4578 (void) fprintf(stderr, gettext("no pools available\n"));
4579 else if (cb.cb_explain && cb.cb_first && cb.cb_allpools)
4580 (void) printf(gettext("all pools are healthy\n"));
4588 if (count != 0 && --count == 0)
4591 (void) sleep(interval);
4597 typedef struct upgrade_cbdata {
4600 uint64_t cb_version;
4605 check_unsupp_fs(zfs_handle_t *zhp, void *unsupp_fs)
4607 int zfs_version = (int) zfs_prop_get_int(zhp, ZFS_PROP_VERSION);
4608 int *count = (int *)unsupp_fs;
4610 if (zfs_version > ZPL_VERSION) {
4611 (void) printf(gettext("%s (v%d) is not supported by this "
4612 "implementation of ZFS.\n"),
4613 zfs_get_name(zhp), zfs_version);
4617 zfs_iter_filesystems(zhp, check_unsupp_fs, unsupp_fs);
4625 upgrade_version(zpool_handle_t *zhp, uint64_t version)
4629 uint64_t oldversion;
4632 config = zpool_get_config(zhp, NULL);
4633 verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
4636 assert(SPA_VERSION_IS_SUPPORTED(oldversion));
4637 assert(oldversion < version);
4639 ret = zfs_iter_root(zpool_get_handle(zhp), check_unsupp_fs, &unsupp_fs);
4644 (void) printf(gettext("Upgrade not performed due to %d "
4645 "unsupported filesystems (max v%d).\n"),
4646 unsupp_fs, (int) ZPL_VERSION);
4650 ret = zpool_upgrade(zhp, version);
4654 if (version >= SPA_VERSION_FEATURES) {
4655 (void) printf(gettext("Successfully upgraded "
4656 "'%s' from version %llu to feature flags.\n"),
4657 zpool_get_name(zhp), (u_longlong_t) oldversion);
4659 (void) printf(gettext("Successfully upgraded "
4660 "'%s' from version %llu to version %llu.\n"),
4661 zpool_get_name(zhp), (u_longlong_t) oldversion,
4662 (u_longlong_t) version);
4669 upgrade_enable_all(zpool_handle_t *zhp, int *countp)
4672 boolean_t firstff = B_TRUE;
4673 nvlist_t *enabled = zpool_get_features(zhp);
4676 for (i = 0; i < SPA_FEATURES; i++) {
4677 const char *fname = spa_feature_table[i].fi_uname;
4678 const char *fguid = spa_feature_table[i].fi_guid;
4679 if (!nvlist_exists(enabled, fguid)) {
4681 verify(-1 != asprintf(&propname, "feature@%s", fname));
4682 ret = zpool_set_prop(zhp, propname,
4683 ZFS_FEATURE_ENABLED);
4691 (void) printf(gettext("Enabled the "
4692 "following features on '%s':\n"),
4693 zpool_get_name(zhp));
4696 (void) printf(gettext(" %s\n"), fname);
4707 upgrade_cb(zpool_handle_t *zhp, void *arg)
4709 upgrade_cbdata_t *cbp = arg;
4712 boolean_t printnl = B_FALSE;
4715 config = zpool_get_config(zhp, NULL);
4716 verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
4719 assert(SPA_VERSION_IS_SUPPORTED(version));
4721 if (version < cbp->cb_version) {
4722 cbp->cb_first = B_FALSE;
4723 ret = upgrade_version(zhp, cbp->cb_version);
4729 * If they did "zpool upgrade -a", then we could
4730 * be doing ioctls to different pools. We need
4731 * to log this history once to each pool, and bypass
4732 * the normal history logging that happens in main().
4734 (void) zpool_log_history(g_zfs, history_str);
4735 log_history = B_FALSE;
4738 if (cbp->cb_version >= SPA_VERSION_FEATURES) {
4740 ret = upgrade_enable_all(zhp, &count);
4745 cbp->cb_first = B_FALSE;
4751 (void) printf(gettext("\n"));
4758 upgrade_list_older_cb(zpool_handle_t *zhp, void *arg)
4760 upgrade_cbdata_t *cbp = arg;
4764 config = zpool_get_config(zhp, NULL);
4765 verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
4768 assert(SPA_VERSION_IS_SUPPORTED(version));
4770 if (version < SPA_VERSION_FEATURES) {
4771 if (cbp->cb_first) {
4772 (void) printf(gettext("The following pools are "
4773 "formatted with legacy version numbers and can\n"
4774 "be upgraded to use feature flags. After "
4775 "being upgraded, these pools\nwill no "
4776 "longer be accessible by software that does not "
4777 "support feature\nflags.\n\n"));
4778 (void) printf(gettext("VER POOL\n"));
4779 (void) printf(gettext("--- ------------\n"));
4780 cbp->cb_first = B_FALSE;
4783 (void) printf("%2llu %s\n", (u_longlong_t)version,
4784 zpool_get_name(zhp));
4791 upgrade_list_disabled_cb(zpool_handle_t *zhp, void *arg)
4793 upgrade_cbdata_t *cbp = arg;
4797 config = zpool_get_config(zhp, NULL);
4798 verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
4801 if (version >= SPA_VERSION_FEATURES) {
4803 boolean_t poolfirst = B_TRUE;
4804 nvlist_t *enabled = zpool_get_features(zhp);
4806 for (i = 0; i < SPA_FEATURES; i++) {
4807 const char *fguid = spa_feature_table[i].fi_guid;
4808 const char *fname = spa_feature_table[i].fi_uname;
4809 if (!nvlist_exists(enabled, fguid)) {
4810 if (cbp->cb_first) {
4811 (void) printf(gettext("\nSome "
4812 "supported features are not "
4813 "enabled on the following pools. "
4814 "Once a\nfeature is enabled the "
4815 "pool may become incompatible with "
4816 "software\nthat does not support "
4818 "zpool-features(5) for "
4820 (void) printf(gettext("POOL "
4822 (void) printf(gettext("------"
4824 cbp->cb_first = B_FALSE;
4828 (void) printf(gettext("%s\n"),
4829 zpool_get_name(zhp));
4830 poolfirst = B_FALSE;
4833 (void) printf(gettext(" %s\n"), fname);
4836 * If they did "zpool upgrade -a", then we could
4837 * be doing ioctls to different pools. We need
4838 * to log this history once to each pool, and bypass
4839 * the normal history logging that happens in main().
4841 (void) zpool_log_history(g_zfs, history_str);
4842 log_history = B_FALSE;
4851 upgrade_one(zpool_handle_t *zhp, void *data)
4853 boolean_t printnl = B_FALSE;
4854 upgrade_cbdata_t *cbp = data;
4855 uint64_t cur_version;
4858 if (strcmp("log", zpool_get_name(zhp)) == 0) {
4859 (void) printf(gettext("'log' is now a reserved word\n"
4860 "Pool 'log' must be renamed using export and import"
4865 cur_version = zpool_get_prop_int(zhp, ZPOOL_PROP_VERSION, NULL);
4866 if (cur_version > cbp->cb_version) {
4867 (void) printf(gettext("Pool '%s' is already formatted "
4868 "using more current version '%llu'.\n\n"),
4869 zpool_get_name(zhp), (u_longlong_t) cur_version);
4873 if (cbp->cb_version != SPA_VERSION && cur_version == cbp->cb_version) {
4874 (void) printf(gettext("Pool '%s' is already formatted "
4875 "using version %llu.\n\n"), zpool_get_name(zhp),
4876 (u_longlong_t) cbp->cb_version);
4880 if (cur_version != cbp->cb_version) {
4882 ret = upgrade_version(zhp, cbp->cb_version);
4887 if (cbp->cb_version >= SPA_VERSION_FEATURES) {
4889 ret = upgrade_enable_all(zhp, &count);
4895 } else if (cur_version == SPA_VERSION) {
4896 (void) printf(gettext("Pool '%s' already has all "
4897 "supported features enabled.\n"),
4898 zpool_get_name(zhp));
4903 (void) printf(gettext("\n"));
4912 * zpool upgrade [-V version] <-a | pool ...>
4914 * With no arguments, display downrev'd ZFS pool available for upgrade.
4915 * Individual pools can be upgraded by specifying the pool, and '-a' will
4916 * upgrade all pools.
4919 zpool_do_upgrade(int argc, char **argv)
4922 upgrade_cbdata_t cb = { 0 };
4924 boolean_t showversions = B_FALSE;
4925 boolean_t upgradeall = B_FALSE;
4930 while ((c = getopt(argc, argv, ":avV:")) != -1) {
4933 upgradeall = B_TRUE;
4936 showversions = B_TRUE;
4939 cb.cb_version = strtoll(optarg, &end, 10);
4941 !SPA_VERSION_IS_SUPPORTED(cb.cb_version)) {
4942 (void) fprintf(stderr,
4943 gettext("invalid version '%s'\n"), optarg);
4948 (void) fprintf(stderr, gettext("missing argument for "
4949 "'%c' option\n"), optopt);
4953 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
4964 if (cb.cb_version == 0) {
4965 cb.cb_version = SPA_VERSION;
4966 } else if (!upgradeall && argc == 0) {
4967 (void) fprintf(stderr, gettext("-V option is "
4968 "incompatible with other arguments\n"));
4973 if (upgradeall || argc != 0) {
4974 (void) fprintf(stderr, gettext("-v option is "
4975 "incompatible with other arguments\n"));
4978 } else if (upgradeall) {
4980 (void) fprintf(stderr, gettext("-a option should not "
4981 "be used along with a pool name\n"));
4986 (void) printf(gettext("This system supports ZFS pool feature "
4991 (void) printf(gettext("The following features are "
4993 (void) printf(gettext("FEAT DESCRIPTION\n"));
4994 (void) printf("----------------------------------------------"
4995 "---------------\n");
4996 for (i = 0; i < SPA_FEATURES; i++) {
4997 zfeature_info_t *fi = &spa_feature_table[i];
4998 const char *ro = fi->fi_can_readonly ?
4999 " (read-only compatible)" : "";
5001 (void) printf("%-37s%s\n", fi->fi_uname, ro);
5002 (void) printf(" %s\n", fi->fi_desc);
5004 (void) printf("\n");
5006 (void) printf(gettext("The following legacy versions are also "
5008 (void) printf(gettext("VER DESCRIPTION\n"));
5009 (void) printf("--- -----------------------------------------"
5010 "---------------\n");
5011 (void) printf(gettext(" 1 Initial ZFS version\n"));
5012 (void) printf(gettext(" 2 Ditto blocks "
5013 "(replicated metadata)\n"));
5014 (void) printf(gettext(" 3 Hot spares and double parity "
5016 (void) printf(gettext(" 4 zpool history\n"));
5017 (void) printf(gettext(" 5 Compression using the gzip "
5019 (void) printf(gettext(" 6 bootfs pool property\n"));
5020 (void) printf(gettext(" 7 Separate intent log devices\n"));
5021 (void) printf(gettext(" 8 Delegated administration\n"));
5022 (void) printf(gettext(" 9 refquota and refreservation "
5024 (void) printf(gettext(" 10 Cache devices\n"));
5025 (void) printf(gettext(" 11 Improved scrub performance\n"));
5026 (void) printf(gettext(" 12 Snapshot properties\n"));
5027 (void) printf(gettext(" 13 snapused property\n"));
5028 (void) printf(gettext(" 14 passthrough-x aclinherit\n"));
5029 (void) printf(gettext(" 15 user/group space accounting\n"));
5030 (void) printf(gettext(" 16 stmf property support\n"));
5031 (void) printf(gettext(" 17 Triple-parity RAID-Z\n"));
5032 (void) printf(gettext(" 18 Snapshot user holds\n"));
5033 (void) printf(gettext(" 19 Log device removal\n"));
5034 (void) printf(gettext(" 20 Compression using zle "
5035 "(zero-length encoding)\n"));
5036 (void) printf(gettext(" 21 Deduplication\n"));
5037 (void) printf(gettext(" 22 Received properties\n"));
5038 (void) printf(gettext(" 23 Slim ZIL\n"));
5039 (void) printf(gettext(" 24 System attributes\n"));
5040 (void) printf(gettext(" 25 Improved scrub stats\n"));
5041 (void) printf(gettext(" 26 Improved snapshot deletion "
5043 (void) printf(gettext(" 27 Improved snapshot creation "
5045 (void) printf(gettext(" 28 Multiple vdev replacements\n"));
5046 (void) printf(gettext("\nFor more information on a particular "
5047 "version, including supported releases,\n"));
5048 (void) printf(gettext("see the ZFS Administration Guide.\n\n"));
5049 } else if (argc == 0 && upgradeall) {
5050 cb.cb_first = B_TRUE;
5051 ret = zpool_iter(g_zfs, upgrade_cb, &cb);
5052 if (ret == 0 && cb.cb_first) {
5053 if (cb.cb_version == SPA_VERSION) {
5054 (void) printf(gettext("All pools are already "
5055 "formatted using feature flags.\n\n"));
5056 (void) printf(gettext("Every feature flags "
5057 "pool already has all supported features "
5060 (void) printf(gettext("All pools are already "
5061 "formatted with version %llu or higher.\n"),
5062 (u_longlong_t) cb.cb_version);
5065 } else if (argc == 0) {
5066 cb.cb_first = B_TRUE;
5067 ret = zpool_iter(g_zfs, upgrade_list_older_cb, &cb);
5071 (void) printf(gettext("All pools are formatted "
5072 "using feature flags.\n\n"));
5074 (void) printf(gettext("\nUse 'zpool upgrade -v' "
5075 "for a list of available legacy versions.\n"));
5078 cb.cb_first = B_TRUE;
5079 ret = zpool_iter(g_zfs, upgrade_list_disabled_cb, &cb);
5083 (void) printf(gettext("Every feature flags pool has "
5084 "all supported features enabled.\n"));
5086 (void) printf(gettext("\n"));
5089 ret = for_each_pool(argc, argv, B_FALSE, NULL,
5096 typedef struct hist_cbdata {
5103 * Print out the command history for a specific pool.
5106 get_history_one(zpool_handle_t *zhp, void *data)
5112 hist_cbdata_t *cb = (hist_cbdata_t *)data;
5114 cb->first = B_FALSE;
5116 (void) printf(gettext("History for '%s':\n"), zpool_get_name(zhp));
5118 if ((ret = zpool_get_history(zhp, &nvhis)) != 0)
5121 verify(nvlist_lookup_nvlist_array(nvhis, ZPOOL_HIST_RECORD,
5122 &records, &numrecords) == 0);
5123 for (i = 0; i < numrecords; i++) {
5124 nvlist_t *rec = records[i];
5127 if (nvlist_exists(rec, ZPOOL_HIST_TIME)) {
5131 tsec = fnvlist_lookup_uint64(records[i],
5133 (void) localtime_r(&tsec, &t);
5134 (void) strftime(tbuf, sizeof (tbuf), "%F.%T", &t);
5137 if (nvlist_exists(rec, ZPOOL_HIST_CMD)) {
5138 (void) printf("%s %s", tbuf,
5139 fnvlist_lookup_string(rec, ZPOOL_HIST_CMD));
5140 } else if (nvlist_exists(rec, ZPOOL_HIST_INT_EVENT)) {
5142 fnvlist_lookup_uint64(rec, ZPOOL_HIST_INT_EVENT);
5145 if (ievent >= ZFS_NUM_LEGACY_HISTORY_EVENTS) {
5146 (void) printf("%s unrecognized record:\n",
5148 dump_nvlist(rec, 4);
5151 (void) printf("%s [internal %s txg:%lld] %s", tbuf,
5152 zfs_history_event_names[ievent],
5153 (longlong_t) fnvlist_lookup_uint64(
5154 rec, ZPOOL_HIST_TXG),
5155 fnvlist_lookup_string(rec, ZPOOL_HIST_INT_STR));
5156 } else if (nvlist_exists(rec, ZPOOL_HIST_INT_NAME)) {
5159 (void) printf("%s [txg:%lld] %s", tbuf,
5160 (longlong_t) fnvlist_lookup_uint64(
5161 rec, ZPOOL_HIST_TXG),
5162 fnvlist_lookup_string(rec, ZPOOL_HIST_INT_NAME));
5163 if (nvlist_exists(rec, ZPOOL_HIST_DSNAME)) {
5164 (void) printf(" %s (%llu)",
5165 fnvlist_lookup_string(rec,
5167 (u_longlong_t)fnvlist_lookup_uint64(rec,
5170 (void) printf(" %s", fnvlist_lookup_string(rec,
5171 ZPOOL_HIST_INT_STR));
5172 } else if (nvlist_exists(rec, ZPOOL_HIST_IOCTL)) {
5175 (void) printf("%s ioctl %s\n", tbuf,
5176 fnvlist_lookup_string(rec, ZPOOL_HIST_IOCTL));
5177 if (nvlist_exists(rec, ZPOOL_HIST_INPUT_NVL)) {
5178 (void) printf(" input:\n");
5179 dump_nvlist(fnvlist_lookup_nvlist(rec,
5180 ZPOOL_HIST_INPUT_NVL), 8);
5182 if (nvlist_exists(rec, ZPOOL_HIST_OUTPUT_NVL)) {
5183 (void) printf(" output:\n");
5184 dump_nvlist(fnvlist_lookup_nvlist(rec,
5185 ZPOOL_HIST_OUTPUT_NVL), 8);
5190 (void) printf("%s unrecognized record:\n", tbuf);
5191 dump_nvlist(rec, 4);
5195 (void) printf("\n");
5198 (void) printf(" [");
5199 if (nvlist_exists(rec, ZPOOL_HIST_WHO)) {
5200 uid_t who = fnvlist_lookup_uint64(rec, ZPOOL_HIST_WHO);
5201 struct passwd *pwd = getpwuid(who);
5202 (void) printf("user %d ", (int)who);
5204 (void) printf("(%s) ", pwd->pw_name);
5206 if (nvlist_exists(rec, ZPOOL_HIST_HOST)) {
5207 (void) printf("on %s",
5208 fnvlist_lookup_string(rec, ZPOOL_HIST_HOST));
5210 if (nvlist_exists(rec, ZPOOL_HIST_ZONE)) {
5211 (void) printf(":%s",
5212 fnvlist_lookup_string(rec, ZPOOL_HIST_ZONE));
5216 (void) printf("\n");
5218 (void) printf("\n");
5225 * zpool history <pool>
5227 * Displays the history of commands that modified pools.
5230 zpool_do_history(int argc, char **argv)
5232 hist_cbdata_t cbdata = { 0 };
5236 cbdata.first = B_TRUE;
5238 while ((c = getopt(argc, argv, "li")) != -1) {
5241 cbdata.longfmt = B_TRUE;
5244 cbdata.internal = B_TRUE;
5247 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
5255 ret = for_each_pool(argc, argv, B_FALSE, NULL, get_history_one,
5258 if (argc == 0 && cbdata.first == B_TRUE) {
5259 (void) fprintf(stderr, gettext("no pools available\n"));
5266 typedef struct ev_opts {
5274 zpool_do_events_short(nvlist_t *nvl)
5276 char ctime_str[26], str[32], *ptr;
5280 verify(nvlist_lookup_int64_array(nvl, FM_EREPORT_TIME, &tv, &n) == 0);
5281 memset(str, ' ', 32);
5282 (void) ctime_r((const time_t *)&tv[0], ctime_str);
5283 (void) strncpy(str, ctime_str+4, 6); /* 'Jun 30' */
5284 (void) strncpy(str+7, ctime_str+20, 4); /* '1993' */
5285 (void) strncpy(str+12, ctime_str+11, 8); /* '21:49:08' */
5286 (void) sprintf(str+20, ".%09lld", (longlong_t)tv[1]); /* '.123456789' */
5287 (void) printf(gettext("%s "), str);
5289 verify(nvlist_lookup_string(nvl, FM_CLASS, &ptr) == 0);
5290 (void) printf(gettext("%s\n"), ptr);
5294 zpool_do_events_nvprint(nvlist_t *nvl, int depth)
5298 for (nvp = nvlist_next_nvpair(nvl, NULL);
5299 nvp != NULL; nvp = nvlist_next_nvpair(nvl, nvp)) {
5301 data_type_t type = nvpair_type(nvp);
5302 const char *name = nvpair_name(nvp);
5312 printf(gettext("%*s%s = "), depth, "", name);
5315 case DATA_TYPE_BOOLEAN:
5316 printf(gettext("%s"), "1");
5319 case DATA_TYPE_BOOLEAN_VALUE:
5320 (void) nvpair_value_boolean_value(nvp, &b);
5321 printf(gettext("%s"), b ? "1" : "0");
5324 case DATA_TYPE_BYTE:
5325 (void) nvpair_value_byte(nvp, &i8);
5326 printf(gettext("0x%x"), i8);
5329 case DATA_TYPE_INT8:
5330 (void) nvpair_value_int8(nvp, (void *)&i8);
5331 printf(gettext("0x%x"), i8);
5334 case DATA_TYPE_UINT8:
5335 (void) nvpair_value_uint8(nvp, &i8);
5336 printf(gettext("0x%x"), i8);
5339 case DATA_TYPE_INT16:
5340 (void) nvpair_value_int16(nvp, (void *)&i16);
5341 printf(gettext("0x%x"), i16);
5344 case DATA_TYPE_UINT16:
5345 (void) nvpair_value_uint16(nvp, &i16);
5346 printf(gettext("0x%x"), i16);
5349 case DATA_TYPE_INT32:
5350 (void) nvpair_value_int32(nvp, (void *)&i32);
5351 printf(gettext("0x%x"), i32);
5354 case DATA_TYPE_UINT32:
5355 (void) nvpair_value_uint32(nvp, &i32);
5356 printf(gettext("0x%x"), i32);
5359 case DATA_TYPE_INT64:
5360 (void) nvpair_value_int64(nvp, (void *)&i64);
5361 printf(gettext("0x%llx"), (u_longlong_t)i64);
5364 case DATA_TYPE_UINT64:
5365 (void) nvpair_value_uint64(nvp, &i64);
5366 printf(gettext("0x%llx"), (u_longlong_t)i64);
5369 case DATA_TYPE_HRTIME:
5370 (void) nvpair_value_hrtime(nvp, (void *)&i64);
5371 printf(gettext("0x%llx"), (u_longlong_t)i64);
5374 case DATA_TYPE_STRING:
5375 (void) nvpair_value_string(nvp, &str);
5376 printf(gettext("\"%s\""), str ? str : "<NULL>");
5379 case DATA_TYPE_NVLIST:
5380 printf(gettext("(embedded nvlist)\n"));
5381 (void) nvpair_value_nvlist(nvp, &cnv);
5382 zpool_do_events_nvprint(cnv, depth + 8);
5383 printf(gettext("%*s(end %s)"), depth, "", name);
5386 case DATA_TYPE_NVLIST_ARRAY: {
5390 (void) nvpair_value_nvlist_array(nvp, &val, &nelem);
5391 printf(gettext("(%d embedded nvlists)\n"), nelem);
5392 for (i = 0; i < nelem; i++) {
5393 printf(gettext("%*s%s[%d] = %s\n"),
5394 depth, "", name, i, "(embedded nvlist)");
5395 zpool_do_events_nvprint(val[i], depth + 8);
5396 printf(gettext("%*s(end %s[%i])\n"),
5397 depth, "", name, i);
5399 printf(gettext("%*s(end %s)\n"), depth, "", name);
5403 case DATA_TYPE_INT8_ARRAY: {
5407 (void) nvpair_value_int8_array(nvp, &val, &nelem);
5408 for (i = 0; i < nelem; i++)
5409 printf(gettext("0x%x "), val[i]);
5414 case DATA_TYPE_UINT8_ARRAY: {
5418 (void) nvpair_value_uint8_array(nvp, &val, &nelem);
5419 for (i = 0; i < nelem; i++)
5420 printf(gettext("0x%x "), val[i]);
5425 case DATA_TYPE_INT16_ARRAY: {
5429 (void) nvpair_value_int16_array(nvp, &val, &nelem);
5430 for (i = 0; i < nelem; i++)
5431 printf(gettext("0x%x "), val[i]);
5436 case DATA_TYPE_UINT16_ARRAY: {
5440 (void) nvpair_value_uint16_array(nvp, &val, &nelem);
5441 for (i = 0; i < nelem; i++)
5442 printf(gettext("0x%x "), val[i]);
5447 case DATA_TYPE_INT32_ARRAY: {
5451 (void) nvpair_value_int32_array(nvp, &val, &nelem);
5452 for (i = 0; i < nelem; i++)
5453 printf(gettext("0x%x "), val[i]);
5458 case DATA_TYPE_UINT32_ARRAY: {
5462 (void) nvpair_value_uint32_array(nvp, &val, &nelem);
5463 for (i = 0; i < nelem; i++)
5464 printf(gettext("0x%x "), val[i]);
5469 case DATA_TYPE_INT64_ARRAY: {
5473 (void) nvpair_value_int64_array(nvp, &val, &nelem);
5474 for (i = 0; i < nelem; i++)
5475 printf(gettext("0x%llx "),
5476 (u_longlong_t)val[i]);
5481 case DATA_TYPE_UINT64_ARRAY: {
5485 (void) nvpair_value_uint64_array(nvp, &val, &nelem);
5486 for (i = 0; i < nelem; i++)
5487 printf(gettext("0x%llx "),
5488 (u_longlong_t)val[i]);
5493 case DATA_TYPE_STRING_ARRAY: {
5497 (void) nvpair_value_string_array(nvp, &str, &nelem);
5498 for (i = 0; i < nelem; i++)
5499 printf(gettext("\"%s\" "),
5500 str[i] ? str[i] : "<NULL>");
5505 case DATA_TYPE_BOOLEAN_ARRAY:
5506 case DATA_TYPE_BYTE_ARRAY:
5507 case DATA_TYPE_DOUBLE:
5508 case DATA_TYPE_UNKNOWN:
5509 printf(gettext("<unknown>"));
5513 printf(gettext("\n"));
5518 zpool_do_events_next(ev_opts_t *opts)
5521 int zevent_fd, ret, dropped;
5523 zevent_fd = open(ZFS_DEV, O_RDWR);
5524 VERIFY(zevent_fd >= 0);
5526 if (!opts->scripted)
5527 (void) printf(gettext("%-30s %s\n"), "TIME", "CLASS");
5530 ret = zpool_events_next(g_zfs, &nvl, &dropped,
5531 (opts->follow ? ZEVENT_NONE : ZEVENT_NONBLOCK), zevent_fd);
5532 if (ret || nvl == NULL)
5536 (void) printf(gettext("dropped %d events\n"), dropped);
5538 zpool_do_events_short(nvl);
5540 if (opts->verbose) {
5541 zpool_do_events_nvprint(nvl, 8);
5542 printf(gettext("\n"));
5544 (void) fflush(stdout);
5549 VERIFY(0 == close(zevent_fd));
5555 zpool_do_events_clear(ev_opts_t *opts)
5559 ret = zpool_events_clear(g_zfs, &count);
5561 (void) printf(gettext("cleared %d events\n"), count);
5567 * zpool events [-vfc]
5569 * Displays events logs by ZFS.
5572 zpool_do_events(int argc, char **argv)
5574 ev_opts_t opts = { 0 };
5579 while ((c = getopt(argc, argv, "vHfc")) != -1) {
5594 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
5603 ret = zpool_do_events_clear(&opts);
5605 ret = zpool_do_events_next(&opts);
5611 get_callback(zpool_handle_t *zhp, void *data)
5613 zprop_get_cbdata_t *cbp = (zprop_get_cbdata_t *)data;
5614 char value[MAXNAMELEN];
5615 zprop_source_t srctype;
5618 for (pl = cbp->cb_proplist; pl != NULL; pl = pl->pl_next) {
5621 * Skip the special fake placeholder. This will also skip
5622 * over the name property when 'all' is specified.
5624 if (pl->pl_prop == ZPOOL_PROP_NAME &&
5625 pl == cbp->cb_proplist)
5628 if (pl->pl_prop == ZPROP_INVAL &&
5629 (zpool_prop_feature(pl->pl_user_prop) ||
5630 zpool_prop_unsupported(pl->pl_user_prop))) {
5631 srctype = ZPROP_SRC_LOCAL;
5633 if (zpool_prop_get_feature(zhp, pl->pl_user_prop,
5634 value, sizeof (value)) == 0) {
5635 zprop_print_one_property(zpool_get_name(zhp),
5636 cbp, pl->pl_user_prop, value, srctype,
5640 if (zpool_get_prop_literal(zhp, pl->pl_prop, value,
5641 sizeof (value), &srctype, cbp->cb_literal) != 0)
5644 zprop_print_one_property(zpool_get_name(zhp), cbp,
5645 zpool_prop_to_name(pl->pl_prop), value, srctype,
5653 zpool_do_get(int argc, char **argv)
5655 zprop_get_cbdata_t cb = { 0 };
5656 zprop_list_t fake_name = { 0 };
5660 while ((c = getopt(argc, argv, "pH")) != -1) {
5663 cb.cb_literal = B_TRUE;
5667 cb.cb_scripted = B_TRUE;
5671 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
5681 (void) fprintf(stderr, gettext("missing property "
5686 cb.cb_first = B_TRUE;
5687 cb.cb_sources = ZPROP_SRC_ALL;
5688 cb.cb_columns[0] = GET_COL_NAME;
5689 cb.cb_columns[1] = GET_COL_PROPERTY;
5690 cb.cb_columns[2] = GET_COL_VALUE;
5691 cb.cb_columns[3] = GET_COL_SOURCE;
5692 cb.cb_type = ZFS_TYPE_POOL;
5694 if (zprop_get_list(g_zfs, argv[0], &cb.cb_proplist, ZFS_TYPE_POOL) != 0)
5700 if (cb.cb_proplist != NULL) {
5701 fake_name.pl_prop = ZPOOL_PROP_NAME;
5702 fake_name.pl_width = strlen(gettext("NAME"));
5703 fake_name.pl_next = cb.cb_proplist;
5704 cb.cb_proplist = &fake_name;
5707 ret = for_each_pool(argc, argv, B_TRUE, &cb.cb_proplist,
5710 if (cb.cb_proplist == &fake_name)
5711 zprop_free_list(fake_name.pl_next);
5713 zprop_free_list(cb.cb_proplist);
5718 typedef struct set_cbdata {
5721 boolean_t cb_any_successful;
5725 set_callback(zpool_handle_t *zhp, void *data)
5728 set_cbdata_t *cb = (set_cbdata_t *)data;
5730 error = zpool_set_prop(zhp, cb->cb_propname, cb->cb_value);
5733 cb->cb_any_successful = B_TRUE;
5739 zpool_do_set(int argc, char **argv)
5741 set_cbdata_t cb = { 0 };
5744 if (argc > 1 && argv[1][0] == '-') {
5745 (void) fprintf(stderr, gettext("invalid option '%c'\n"),
5751 (void) fprintf(stderr, gettext("missing property=value "
5757 (void) fprintf(stderr, gettext("missing pool name\n"));
5762 (void) fprintf(stderr, gettext("too many pool names\n"));
5766 cb.cb_propname = argv[1];
5767 cb.cb_value = strchr(cb.cb_propname, '=');
5768 if (cb.cb_value == NULL) {
5769 (void) fprintf(stderr, gettext("missing value in "
5770 "property=value argument\n"));
5774 *(cb.cb_value) = '\0';
5777 error = for_each_pool(argc - 2, argv + 2, B_TRUE, NULL,
5784 find_command_idx(char *command, int *idx)
5788 for (i = 0; i < NCOMMAND; i++) {
5789 if (command_table[i].name == NULL)
5792 if (strcmp(command, command_table[i].name) == 0) {
5801 main(int argc, char **argv)
5807 (void) setlocale(LC_ALL, "");
5808 (void) textdomain(TEXT_DOMAIN);
5813 * Make sure the user has specified some command.
5816 (void) fprintf(stderr, gettext("missing command\n"));
5825 if ((strcmp(cmdname, "-?") == 0) || strcmp(cmdname, "--help") == 0)
5828 if ((g_zfs = libzfs_init()) == NULL)
5831 libzfs_print_on_error(g_zfs, B_TRUE);
5833 zfs_save_arguments(argc, argv, history_str, sizeof (history_str));
5836 * Run the appropriate command.
5838 if (find_command_idx(cmdname, &i) == 0) {
5839 current_command = &command_table[i];
5840 ret = command_table[i].func(argc - 1, argv + 1);
5841 } else if (strchr(cmdname, '=')) {
5842 verify(find_command_idx("set", &i) == 0);
5843 current_command = &command_table[i];
5844 ret = command_table[i].func(argc, argv);
5845 } else if (strcmp(cmdname, "freeze") == 0 && argc == 3) {
5847 * 'freeze' is a vile debugging abomination, so we treat
5851 int fd = open(ZFS_DEV, O_RDWR);
5852 (void) strcpy((void *)buf, argv[2]);
5853 return (!!ioctl(fd, ZFS_IOC_POOL_FREEZE, buf));
5855 (void) fprintf(stderr, gettext("unrecognized "
5856 "command '%s'\n"), cmdname);
5861 if (ret == 0 && log_history)
5862 (void) zpool_log_history(g_zfs, history_str);
5867 * The 'ZFS_ABORT' environment variable causes us to dump core on exit
5868 * for the purposes of running ::findleaks.
5870 if (getenv("ZFS_ABORT") != NULL) {
5871 (void) printf("dumping core by request\n");