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) 2012 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>
55 #include "zpool_util.h"
56 #include "zfs_comutil.h"
57 #include "zfeature_common.h"
59 #include "statcommon.h"
61 static int zpool_do_create(int, char **);
62 static int zpool_do_destroy(int, char **);
64 static int zpool_do_add(int, char **);
65 static int zpool_do_remove(int, char **);
66 static int zpool_do_labelclear(int, char **);
68 static int zpool_do_list(int, char **);
69 static int zpool_do_iostat(int, char **);
70 static int zpool_do_status(int, char **);
72 static int zpool_do_online(int, char **);
73 static int zpool_do_offline(int, char **);
74 static int zpool_do_clear(int, char **);
75 static int zpool_do_reopen(int, char **);
77 static int zpool_do_reguid(int, char **);
79 static int zpool_do_attach(int, char **);
80 static int zpool_do_detach(int, char **);
81 static int zpool_do_replace(int, char **);
82 static int zpool_do_split(int, char **);
84 static int zpool_do_scrub(int, char **);
86 static int zpool_do_import(int, char **);
87 static int zpool_do_export(int, char **);
89 static int zpool_do_upgrade(int, char **);
91 static int zpool_do_history(int, char **);
92 static int zpool_do_events(int, char **);
94 static int zpool_do_get(int, char **);
95 static int zpool_do_set(int, char **);
98 * These libumem hooks provide a reasonable set of defaults for the allocator's
99 * debugging facilities.
104 _umem_debug_init(void)
106 return ("default,verbose"); /* $UMEM_DEBUG setting */
110 _umem_logging_init(void)
112 return ("fail,contents"); /* $UMEM_LOGGING setting */
145 typedef struct zpool_command
{
147 int (*func
)(int, char **);
152 * Master command table. Each ZFS command has a name, associated function, and
153 * usage message. The usage messages need to be internationalized, so we have
154 * to have a function to return the usage message based on a command index.
156 * These commands are organized according to how they are displayed in the usage
157 * message. An empty command (one with a NULL name) indicates an empty line in
158 * the generic usage message.
160 static zpool_command_t command_table
[] = {
161 { "create", zpool_do_create
, HELP_CREATE
},
162 { "destroy", zpool_do_destroy
, HELP_DESTROY
},
164 { "add", zpool_do_add
, HELP_ADD
},
165 { "remove", zpool_do_remove
, HELP_REMOVE
},
167 { "labelclear", zpool_do_labelclear
, HELP_LABELCLEAR
},
169 { "list", zpool_do_list
, HELP_LIST
},
170 { "iostat", zpool_do_iostat
, HELP_IOSTAT
},
171 { "status", zpool_do_status
, HELP_STATUS
},
173 { "online", zpool_do_online
, HELP_ONLINE
},
174 { "offline", zpool_do_offline
, HELP_OFFLINE
},
175 { "clear", zpool_do_clear
, HELP_CLEAR
},
176 { "reopen", zpool_do_reopen
, HELP_REOPEN
},
178 { "attach", zpool_do_attach
, HELP_ATTACH
},
179 { "detach", zpool_do_detach
, HELP_DETACH
},
180 { "replace", zpool_do_replace
, HELP_REPLACE
},
181 { "split", zpool_do_split
, HELP_SPLIT
},
183 { "scrub", zpool_do_scrub
, HELP_SCRUB
},
185 { "import", zpool_do_import
, HELP_IMPORT
},
186 { "export", zpool_do_export
, HELP_EXPORT
},
187 { "upgrade", zpool_do_upgrade
, HELP_UPGRADE
},
188 { "reguid", zpool_do_reguid
, HELP_REGUID
},
190 { "history", zpool_do_history
, HELP_HISTORY
},
191 { "events", zpool_do_events
, HELP_EVENTS
},
193 { "get", zpool_do_get
, HELP_GET
},
194 { "set", zpool_do_set
, HELP_SET
},
197 #define NCOMMAND (sizeof (command_table) / sizeof (command_table[0]))
199 zpool_command_t
*current_command
;
200 static char history_str
[HIS_MAX_RECORD_LEN
];
202 static uint_t timestamp_fmt
= NODATE
;
205 get_usage(zpool_help_t idx
) {
208 return (gettext("\tadd [-fn] [-o property=value] "
209 "<pool> <vdev> ...\n"));
211 return (gettext("\tattach [-f] [-o property=value] "
212 "<pool> <device> <new-device>\n"));
214 return (gettext("\tclear [-nF] <pool> [device]\n"));
216 return (gettext("\tcreate [-fnd] [-o property=value] ... \n"
217 "\t [-O file-system-property=value] ... \n"
218 "\t [-m mountpoint] [-R root] <pool> <vdev> ...\n"));
220 return (gettext("\tdestroy [-f] <pool>\n"));
222 return (gettext("\tdetach <pool> <device>\n"));
224 return (gettext("\texport [-f] <pool> ...\n"));
226 return (gettext("\thistory [-il] [<pool>] ...\n"));
228 return (gettext("\timport [-d dir] [-D]\n"
229 "\timport [-d dir | -c cachefile] [-F [-n]] <pool | id>\n"
230 "\timport [-o mntopts] [-o property=value] ... \n"
231 "\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
232 "[-R root] [-F [-n]] -a\n"
233 "\timport [-o mntopts] [-o property=value] ... \n"
234 "\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
235 "[-R root] [-F [-n]]\n"
236 "\t <pool | id> [newpool]\n"));
238 return (gettext("\tiostat [-v] [-T d|u] [pool] ... [interval "
240 case HELP_LABELCLEAR
:
241 return (gettext("\tlabelclear [-f] <vdev>\n"));
243 return (gettext("\tlist [-H] [-o property[,...]] "
244 "[-T d|u] [pool] ... [interval [count]]\n"));
246 return (gettext("\toffline [-t] <pool> <device> ...\n"));
248 return (gettext("\tonline <pool> <device> ...\n"));
250 return (gettext("\treplace [-f] <pool> <device> "
253 return (gettext("\tremove <pool> <device> ...\n"));
255 return (gettext("\treopen <pool>\n"));
257 return (gettext("\tscrub [-s] <pool> ...\n"));
259 return (gettext("\tstatus [-vx] [-T d|u] [pool] ... [interval "
262 return (gettext("\tupgrade\n"
264 "\tupgrade [-V version] <-a | pool ...>\n"));
266 return (gettext("\tevents [-vHfc]\n"));
268 return (gettext("\tget <\"all\" | property[,...]> "
271 return (gettext("\tset <property=value> <pool> \n"));
273 return (gettext("\tsplit [-n] [-R altroot] [-o mntopts]\n"
274 "\t [-o property=value] <pool> <newpool> "
275 "[<device> ...]\n"));
277 return (gettext("\treguid <pool>\n"));
286 * Callback routine that will print out a pool property value.
289 print_prop_cb(int prop
, void *cb
)
293 (void) fprintf(fp
, "\t%-15s ", zpool_prop_to_name(prop
));
295 if (zpool_prop_readonly(prop
))
296 (void) fprintf(fp
, " NO ");
298 (void) fprintf(fp
, " YES ");
300 if (zpool_prop_values(prop
) == NULL
)
301 (void) fprintf(fp
, "-\n");
303 (void) fprintf(fp
, "%s\n", zpool_prop_values(prop
));
309 * Display usage message. If we're inside a command, display only the usage for
310 * that command. Otherwise, iterate over the entire command table and display
311 * a complete usage message.
314 usage(boolean_t requested
)
316 FILE *fp
= requested
? stdout
: stderr
;
318 if (current_command
== NULL
) {
321 (void) fprintf(fp
, gettext("usage: zpool command args ...\n"));
323 gettext("where 'command' is one of the following:\n\n"));
325 for (i
= 0; i
< NCOMMAND
; i
++) {
326 if (command_table
[i
].name
== NULL
)
327 (void) fprintf(fp
, "\n");
329 (void) fprintf(fp
, "%s",
330 get_usage(command_table
[i
].usage
));
333 (void) fprintf(fp
, gettext("usage:\n"));
334 (void) fprintf(fp
, "%s", get_usage(current_command
->usage
));
337 if (current_command
!= NULL
&&
338 ((strcmp(current_command
->name
, "set") == 0) ||
339 (strcmp(current_command
->name
, "get") == 0) ||
340 (strcmp(current_command
->name
, "list") == 0))) {
343 gettext("\nthe following properties are supported:\n"));
345 (void) fprintf(fp
, "\n\t%-15s %s %s\n\n",
346 "PROPERTY", "EDIT", "VALUES");
348 /* Iterate over all properties */
349 (void) zprop_iter(print_prop_cb
, fp
, B_FALSE
, B_TRUE
,
352 (void) fprintf(fp
, "\t%-15s ", "feature@...");
353 (void) fprintf(fp
, "YES disabled | enabled | active\n");
355 (void) fprintf(fp
, gettext("\nThe feature@ properties must be "
356 "appended with a feature name.\nSee zpool-features(5).\n"));
360 * See comments at end of main().
362 if (getenv("ZFS_ABORT") != NULL
) {
363 (void) printf("dumping core by request\n");
367 exit(requested
? 0 : 2);
371 print_vdev_tree(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
, int indent
,
372 boolean_t print_logs
)
379 (void) printf("\t%*s%s\n", indent
, "", name
);
381 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
382 &child
, &children
) != 0)
385 for (c
= 0; c
< children
; c
++) {
386 uint64_t is_log
= B_FALSE
;
388 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
390 if ((is_log
&& !print_logs
) || (!is_log
&& print_logs
))
393 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], B_FALSE
);
394 print_vdev_tree(zhp
, vname
, child
[c
], indent
+ 2,
401 prop_list_contains_feature(nvlist_t
*proplist
)
404 for (nvp
= nvlist_next_nvpair(proplist
, NULL
); NULL
!= nvp
;
405 nvp
= nvlist_next_nvpair(proplist
, nvp
)) {
406 if (zpool_prop_feature(nvpair_name(nvp
)))
413 * Add a property pair (name, string-value) into a property nvlist.
416 add_prop_list(const char *propname
, char *propval
, nvlist_t
**props
,
419 zpool_prop_t prop
= ZPROP_INVAL
;
425 if (*props
== NULL
&&
426 nvlist_alloc(props
, NV_UNIQUE_NAME
, 0) != 0) {
427 (void) fprintf(stderr
,
428 gettext("internal error: out of memory\n"));
435 const char *vname
= zpool_prop_to_name(ZPOOL_PROP_VERSION
);
437 if ((prop
= zpool_name_to_prop(propname
)) == ZPROP_INVAL
&&
438 !zpool_prop_feature(propname
)) {
439 (void) fprintf(stderr
, gettext("property '%s' is "
440 "not a valid pool property\n"), propname
);
445 * feature@ properties and version should not be specified
448 if ((prop
== ZPROP_INVAL
&& zpool_prop_feature(propname
) &&
449 nvlist_exists(proplist
, vname
)) ||
450 (prop
== ZPOOL_PROP_VERSION
&&
451 prop_list_contains_feature(proplist
))) {
452 (void) fprintf(stderr
, gettext("'feature@' and "
453 "'version' properties cannot be specified "
459 if (zpool_prop_feature(propname
))
462 normnm
= zpool_prop_to_name(prop
);
464 if ((fprop
= zfs_name_to_prop(propname
)) != ZPROP_INVAL
) {
465 normnm
= zfs_prop_to_name(fprop
);
471 if (nvlist_lookup_string(proplist
, normnm
, &strval
) == 0 &&
472 prop
!= ZPOOL_PROP_CACHEFILE
) {
473 (void) fprintf(stderr
, gettext("property '%s' "
474 "specified multiple times\n"), propname
);
478 if (nvlist_add_string(proplist
, normnm
, propval
) != 0) {
479 (void) fprintf(stderr
, gettext("internal "
480 "error: out of memory\n"));
488 * zpool add [-fn] [-o property=value] <pool> <vdev> ...
490 * -f Force addition of devices, even if they appear in use
491 * -n Do not add the devices, but display the resulting layout if
492 * they were to be added.
493 * -o Set property=value.
495 * Adds the given vdevs to 'pool'. As with create, the bulk of this work is
496 * handled by get_vdev_spec(), which constructs the nvlist needed to pass to
500 zpool_do_add(int argc
, char **argv
)
502 boolean_t force
= B_FALSE
;
503 boolean_t dryrun
= B_FALSE
;
510 nvlist_t
*props
= NULL
;
514 while ((c
= getopt(argc
, argv
, "fno:")) != -1) {
523 if ((propval
= strchr(optarg
, '=')) == NULL
) {
524 (void) fprintf(stderr
, gettext("missing "
525 "'=' for -o option\n"));
531 if ((strcmp(optarg
, ZPOOL_CONFIG_ASHIFT
) != 0) ||
532 (add_prop_list(optarg
, propval
, &props
, B_TRUE
)))
536 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
545 /* get pool name and check number of arguments */
547 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
551 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
560 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
563 if ((config
= zpool_get_config(zhp
, NULL
)) == NULL
) {
564 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
570 /* pass off to get_vdev_spec for processing */
571 nvroot
= make_root_vdev(zhp
, props
, force
, !force
, B_FALSE
, dryrun
,
573 if (nvroot
== NULL
) {
579 nvlist_t
*poolnvroot
;
581 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
584 (void) printf(gettext("would update '%s' to the following "
585 "configuration:\n"), zpool_get_name(zhp
));
587 /* print original main pool and new tree */
588 print_vdev_tree(zhp
, poolname
, poolnvroot
, 0, B_FALSE
);
589 print_vdev_tree(zhp
, NULL
, nvroot
, 0, B_FALSE
);
591 /* Do the same for the logs */
592 if (num_logs(poolnvroot
) > 0) {
593 print_vdev_tree(zhp
, "logs", poolnvroot
, 0, B_TRUE
);
594 print_vdev_tree(zhp
, NULL
, nvroot
, 0, B_TRUE
);
595 } else if (num_logs(nvroot
) > 0) {
596 print_vdev_tree(zhp
, "logs", nvroot
, 0, B_TRUE
);
601 ret
= (zpool_add(zhp
, nvroot
) != 0);
612 * zpool remove <pool> <vdev> ...
614 * Removes the given vdev from the pool. Currently, this supports removing
615 * spares, cache, and log devices from the pool.
618 zpool_do_remove(int argc
, char **argv
)
627 /* get pool name and check number of arguments */
629 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
633 (void) fprintf(stderr
, gettext("missing device\n"));
639 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
642 for (i
= 1; i
< argc
; i
++) {
643 if (zpool_vdev_remove(zhp
, argv
[i
]) != 0)
651 * zpool labelclear <vdev>
653 * Verifies that the vdev is not active and zeros out the label information
657 zpool_do_labelclear(int argc
, char **argv
)
660 int c
, fd
= -1, ret
= 0;
662 boolean_t inuse
= B_FALSE
;
663 boolean_t force
= B_FALSE
;
666 while ((c
= getopt(argc
, argv
, "f")) != -1) {
672 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
683 (void) fprintf(stderr
, gettext("missing vdev device name\n"));
688 if ((fd
= open(vdev
, O_RDWR
)) < 0) {
689 (void) fprintf(stderr
, gettext("Unable to open %s\n"), vdev
);
694 if (zpool_in_use(g_zfs
, fd
, &state
, &name
, &inuse
) != 0) {
698 (void) fprintf(stderr
,
699 gettext("Unable to determine pool state for %s\n"
700 "Use -f to force the clearing any label data\n"), vdev
);
708 case POOL_STATE_ACTIVE
:
709 case POOL_STATE_SPARE
:
710 case POOL_STATE_L2CACHE
:
711 (void) fprintf(stderr
,
712 gettext("labelclear operation failed.\n"
713 "\tVdev %s is a member (%s), of pool \"%s\".\n"
714 "\tTo remove label information from this device, "
715 "export or destroy\n\tthe pool, or remove %s from "
716 "the configuration of this pool\n\tand retry the "
717 "labelclear operation.\n"),
718 vdev
, zpool_pool_state_to_name(state
), name
, vdev
);
722 case POOL_STATE_EXPORTED
:
726 (void) fprintf(stderr
,
727 gettext("labelclear operation failed.\n\tVdev "
728 "%s is a member of the exported pool \"%s\".\n"
729 "\tUse \"zpool labelclear -f %s\" to force the "
730 "removal of label\n\tinformation.\n"),
735 case POOL_STATE_POTENTIALLY_ACTIVE
:
739 (void) fprintf(stderr
,
740 gettext("labelclear operation failed.\n"
741 "\tVdev %s is a member of the pool \"%s\".\n"
742 "\tThis pool is unknown to this system, but may "
743 "be active on\n\tanother system. Use "
744 "\'zpool labelclear -f %s\' to force the\n"
745 "\tremoval of label information.\n"),
750 case POOL_STATE_DESTROYED
:
751 /* inuse should never be set for a destroyed pool... */
757 if (zpool_clear_label(fd
) != 0) {
758 (void) fprintf(stderr
,
759 gettext("Label clear failed on vdev %s\n"), vdev
);
772 * zpool create [-fnd] [-o property=value] ...
773 * [-O file-system-property=value] ...
774 * [-R root] [-m mountpoint] <pool> <dev> ...
776 * -f Force creation, even if devices appear in use
777 * -n Do not create the pool, but display the resulting layout if it
778 * were to be created.
779 * -R Create a pool under an alternate root
780 * -m Set default mountpoint for the root dataset. By default it's
782 * -o Set property=value.
783 * -d Don't automatically enable all supported pool features
784 * (individual features can be enabled with -o).
785 * -O Set fsproperty=value in the pool's root file system
787 * Creates the named pool according to the given vdev specification. The
788 * bulk of the vdev processing is done in get_vdev_spec() in zpool_vdev.c. Once
789 * we get the nvlist back from get_vdev_spec(), we either print out the contents
790 * (if '-n' was specified), or pass it to libzfs to do the creation.
793 zpool_do_create(int argc
, char **argv
)
795 boolean_t force
= B_FALSE
;
796 boolean_t dryrun
= B_FALSE
;
797 boolean_t enable_all_pool_feat
= B_TRUE
;
799 nvlist_t
*nvroot
= NULL
;
802 char *altroot
= NULL
;
803 char *mountpoint
= NULL
;
804 nvlist_t
*fsprops
= NULL
;
805 nvlist_t
*props
= NULL
;
809 while ((c
= getopt(argc
, argv
, ":fndR:m:o:O:")) != -1) {
818 enable_all_pool_feat
= B_FALSE
;
822 if (add_prop_list(zpool_prop_to_name(
823 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
825 if (nvlist_lookup_string(props
,
826 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
),
829 if (add_prop_list(zpool_prop_to_name(
830 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
837 if ((propval
= strchr(optarg
, '=')) == NULL
) {
838 (void) fprintf(stderr
, gettext("missing "
839 "'=' for -o option\n"));
845 if (add_prop_list(optarg
, propval
, &props
, B_TRUE
))
849 * If the user is creating a pool that doesn't support
850 * feature flags, don't enable any features.
852 if (zpool_name_to_prop(optarg
) == ZPOOL_PROP_VERSION
) {
856 ver
= strtoull(propval
, &end
, 10);
858 ver
< SPA_VERSION_FEATURES
) {
859 enable_all_pool_feat
= B_FALSE
;
864 if ((propval
= strchr(optarg
, '=')) == NULL
) {
865 (void) fprintf(stderr
, gettext("missing "
866 "'=' for -O option\n"));
872 if (add_prop_list(optarg
, propval
, &fsprops
, B_FALSE
))
876 (void) fprintf(stderr
, gettext("missing argument for "
877 "'%c' option\n"), optopt
);
880 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
889 /* get pool name and check number of arguments */
891 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
895 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
902 * As a special case, check for use of '/' in the name, and direct the
903 * user to use 'zfs create' instead.
905 if (strchr(poolname
, '/') != NULL
) {
906 (void) fprintf(stderr
, gettext("cannot create '%s': invalid "
907 "character '/' in pool name\n"), poolname
);
908 (void) fprintf(stderr
, gettext("use 'zfs create' to "
909 "create a dataset\n"));
913 /* pass off to get_vdev_spec for bulk processing */
914 nvroot
= make_root_vdev(NULL
, props
, force
, !force
, B_FALSE
, dryrun
,
919 /* make_root_vdev() allows 0 toplevel children if there are spares */
920 if (!zfs_allocatable_devs(nvroot
)) {
921 (void) fprintf(stderr
, gettext("invalid vdev "
922 "specification: at least one toplevel vdev must be "
927 if (altroot
!= NULL
&& altroot
[0] != '/') {
928 (void) fprintf(stderr
, gettext("invalid alternate root '%s': "
929 "must be an absolute path\n"), altroot
);
934 * Check the validity of the mountpoint and direct the user to use the
935 * '-m' mountpoint option if it looks like its in use.
937 if (mountpoint
== NULL
||
938 (strcmp(mountpoint
, ZFS_MOUNTPOINT_LEGACY
) != 0 &&
939 strcmp(mountpoint
, ZFS_MOUNTPOINT_NONE
) != 0)) {
940 char buf
[MAXPATHLEN
];
943 if (mountpoint
&& mountpoint
[0] != '/') {
944 (void) fprintf(stderr
, gettext("invalid mountpoint "
945 "'%s': must be an absolute path, 'legacy', or "
946 "'none'\n"), mountpoint
);
950 if (mountpoint
== NULL
) {
952 (void) snprintf(buf
, sizeof (buf
), "%s/%s",
955 (void) snprintf(buf
, sizeof (buf
), "/%s",
959 (void) snprintf(buf
, sizeof (buf
), "%s%s",
960 altroot
, mountpoint
);
962 (void) snprintf(buf
, sizeof (buf
), "%s",
966 if ((dirp
= opendir(buf
)) == NULL
&& errno
!= ENOENT
) {
967 (void) fprintf(stderr
, gettext("mountpoint '%s' : "
968 "%s\n"), buf
, strerror(errno
));
969 (void) fprintf(stderr
, gettext("use '-m' "
970 "option to provide a different default\n"));
975 while (count
< 3 && readdir(dirp
) != NULL
)
977 (void) closedir(dirp
);
980 (void) fprintf(stderr
, gettext("mountpoint "
981 "'%s' exists and is not empty\n"), buf
);
982 (void) fprintf(stderr
, gettext("use '-m' "
983 "option to provide a "
984 "different default\n"));
992 * For a dry run invocation, print out a basic message and run
993 * through all the vdevs in the list and print out in an
994 * appropriate hierarchy.
996 (void) printf(gettext("would create '%s' with the "
997 "following layout:\n\n"), poolname
);
999 print_vdev_tree(NULL
, poolname
, nvroot
, 0, B_FALSE
);
1000 if (num_logs(nvroot
) > 0)
1001 print_vdev_tree(NULL
, "logs", nvroot
, 0, B_TRUE
);
1006 * Hand off to libzfs.
1008 if (enable_all_pool_feat
) {
1010 for (i
= 0; i
< SPA_FEATURES
; i
++) {
1011 char propname
[MAXPATHLEN
];
1012 zfeature_info_t
*feat
= &spa_feature_table
[i
];
1014 (void) snprintf(propname
, sizeof (propname
),
1015 "feature@%s", feat
->fi_uname
);
1018 * Skip feature if user specified it manually
1019 * on the command line.
1021 if (nvlist_exists(props
, propname
))
1024 if (add_prop_list(propname
, ZFS_FEATURE_ENABLED
,
1025 &props
, B_TRUE
) != 0)
1029 if (zpool_create(g_zfs
, poolname
,
1030 nvroot
, props
, fsprops
) == 0) {
1031 zfs_handle_t
*pool
= zfs_open(g_zfs
, poolname
,
1032 ZFS_TYPE_FILESYSTEM
);
1034 if (mountpoint
!= NULL
)
1035 verify(zfs_prop_set(pool
,
1037 ZFS_PROP_MOUNTPOINT
),
1039 if (zfs_mount(pool
, NULL
, 0) == 0)
1040 ret
= zfs_shareall(pool
);
1043 } else if (libzfs_errno(g_zfs
) == EZFS_INVALIDNAME
) {
1044 (void) fprintf(stderr
, gettext("pool name may have "
1050 nvlist_free(nvroot
);
1051 nvlist_free(fsprops
);
1055 nvlist_free(fsprops
);
1062 * zpool destroy <pool>
1064 * -f Forcefully unmount any datasets
1066 * Destroy the given pool. Automatically unmounts any datasets in the pool.
1069 zpool_do_destroy(int argc
, char **argv
)
1071 boolean_t force
= B_FALSE
;
1074 zpool_handle_t
*zhp
;
1078 while ((c
= getopt(argc
, argv
, "f")) != -1) {
1084 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1093 /* check arguments */
1095 (void) fprintf(stderr
, gettext("missing pool argument\n"));
1099 (void) fprintf(stderr
, gettext("too many arguments\n"));
1105 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
) {
1107 * As a special case, check for use of '/' in the name, and
1108 * direct the user to use 'zfs destroy' instead.
1110 if (strchr(pool
, '/') != NULL
)
1111 (void) fprintf(stderr
, gettext("use 'zfs destroy' to "
1112 "destroy a dataset\n"));
1116 if (zpool_disable_datasets(zhp
, force
) != 0) {
1117 (void) fprintf(stderr
, gettext("could not destroy '%s': "
1118 "could not unmount datasets\n"), zpool_get_name(zhp
));
1122 ret
= (zpool_destroy(zhp
) != 0);
1130 * zpool export [-f] <pool> ...
1132 * -f Forcefully unmount datasets
1134 * Export the given pools. By default, the command will attempt to cleanly
1135 * unmount any active datasets within the pool. If the '-f' flag is specified,
1136 * then the datasets will be forcefully unmounted.
1139 zpool_do_export(int argc
, char **argv
)
1141 boolean_t force
= B_FALSE
;
1142 boolean_t hardforce
= B_FALSE
;
1144 zpool_handle_t
*zhp
;
1149 while ((c
= getopt(argc
, argv
, "fF")) != -1) {
1158 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1167 /* check arguments */
1169 (void) fprintf(stderr
, gettext("missing pool argument\n"));
1174 for (i
= 0; i
< argc
; i
++) {
1175 if ((zhp
= zpool_open_canfail(g_zfs
, argv
[i
])) == NULL
) {
1180 if (zpool_disable_datasets(zhp
, force
) != 0) {
1187 if (zpool_export_force(zhp
) != 0)
1189 } else if (zpool_export(zhp
, force
) != 0) {
1200 * Given a vdev configuration, determine the maximum width needed for the device
1204 max_width(zpool_handle_t
*zhp
, nvlist_t
*nv
, int depth
, int max
)
1206 char *name
= zpool_vdev_name(g_zfs
, zhp
, nv
, B_TRUE
);
1211 if (strlen(name
) + depth
> max
)
1212 max
= strlen(name
) + depth
;
1216 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
1217 &child
, &children
) == 0) {
1218 for (c
= 0; c
< children
; c
++)
1219 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1224 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
1225 &child
, &children
) == 0) {
1226 for (c
= 0; c
< children
; c
++)
1227 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1232 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1233 &child
, &children
) == 0) {
1234 for (c
= 0; c
< children
; c
++)
1235 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1244 typedef struct spare_cbdata
{
1246 zpool_handle_t
*cb_zhp
;
1250 find_vdev(nvlist_t
*nv
, uint64_t search
)
1256 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
, &guid
) == 0 &&
1260 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1261 &child
, &children
) == 0) {
1262 for (c
= 0; c
< children
; c
++)
1263 if (find_vdev(child
[c
], search
))
1271 find_spare(zpool_handle_t
*zhp
, void *data
)
1273 spare_cbdata_t
*cbp
= data
;
1274 nvlist_t
*config
, *nvroot
;
1276 config
= zpool_get_config(zhp
, NULL
);
1277 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
1280 if (find_vdev(nvroot
, cbp
->cb_guid
)) {
1290 * Print out configuration state as requested by status_callback.
1293 print_status_config(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
,
1294 int namewidth
, int depth
, boolean_t isspare
)
1298 pool_scan_stat_t
*ps
= NULL
;
1300 char rbuf
[6], wbuf
[6], cbuf
[6];
1302 uint64_t notpresent
;
1306 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1307 &child
, &children
) != 0)
1310 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
1311 (uint64_t **)&vs
, &c
) == 0);
1313 state
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
1316 * For hot spares, we use the terms 'INUSE' and 'AVAILABLE' for
1319 if (vs
->vs_aux
== VDEV_AUX_SPARED
)
1321 else if (vs
->vs_state
== VDEV_STATE_HEALTHY
)
1325 (void) printf("\t%*s%-*s %-8s", depth
, "", namewidth
- depth
,
1329 zfs_nicenum(vs
->vs_read_errors
, rbuf
, sizeof (rbuf
));
1330 zfs_nicenum(vs
->vs_write_errors
, wbuf
, sizeof (wbuf
));
1331 zfs_nicenum(vs
->vs_checksum_errors
, cbuf
, sizeof (cbuf
));
1332 (void) printf(" %5s %5s %5s", rbuf
, wbuf
, cbuf
);
1335 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_NOT_PRESENT
,
1336 ¬present
) == 0) {
1338 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_PATH
, &path
) == 0);
1339 (void) printf(" was %s", path
);
1340 } else if (vs
->vs_aux
!= 0) {
1343 switch (vs
->vs_aux
) {
1344 case VDEV_AUX_OPEN_FAILED
:
1345 (void) printf(gettext("cannot open"));
1348 case VDEV_AUX_BAD_GUID_SUM
:
1349 (void) printf(gettext("missing device"));
1352 case VDEV_AUX_NO_REPLICAS
:
1353 (void) printf(gettext("insufficient replicas"));
1356 case VDEV_AUX_VERSION_NEWER
:
1357 (void) printf(gettext("newer version"));
1360 case VDEV_AUX_UNSUP_FEAT
:
1361 (void) printf(gettext("unsupported feature(s)"));
1364 case VDEV_AUX_SPARED
:
1365 verify(nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
,
1367 if (zpool_iter(g_zfs
, find_spare
, &cb
) == 1) {
1368 if (strcmp(zpool_get_name(cb
.cb_zhp
),
1369 zpool_get_name(zhp
)) == 0)
1370 (void) printf(gettext("currently in "
1373 (void) printf(gettext("in use by "
1375 zpool_get_name(cb
.cb_zhp
));
1376 zpool_close(cb
.cb_zhp
);
1378 (void) printf(gettext("currently in use"));
1382 case VDEV_AUX_ERR_EXCEEDED
:
1383 (void) printf(gettext("too many errors"));
1386 case VDEV_AUX_IO_FAILURE
:
1387 (void) printf(gettext("experienced I/O failures"));
1390 case VDEV_AUX_BAD_LOG
:
1391 (void) printf(gettext("bad intent log"));
1394 case VDEV_AUX_EXTERNAL
:
1395 (void) printf(gettext("external device fault"));
1398 case VDEV_AUX_SPLIT_POOL
:
1399 (void) printf(gettext("split into new pool"));
1403 (void) printf(gettext("corrupted data"));
1408 (void) nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_SCAN_STATS
,
1409 (uint64_t **)&ps
, &c
);
1411 if (ps
&& ps
->pss_state
== DSS_SCANNING
&&
1412 vs
->vs_scan_processed
!= 0 && children
== 0) {
1413 (void) printf(gettext(" (%s)"),
1414 (ps
->pss_func
== POOL_SCAN_RESILVER
) ?
1415 "resilvering" : "repairing");
1418 (void) printf("\n");
1420 for (c
= 0; c
< children
; c
++) {
1421 uint64_t islog
= B_FALSE
, ishole
= B_FALSE
;
1423 /* Don't print logs or holes here */
1424 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1426 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_HOLE
,
1428 if (islog
|| ishole
)
1430 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], B_TRUE
);
1431 print_status_config(zhp
, vname
, child
[c
],
1432 namewidth
, depth
+ 2, isspare
);
1439 * Print the configuration of an exported pool. Iterate over all vdevs in the
1440 * pool, printing out the name and status for each one.
1443 print_import_config(const char *name
, nvlist_t
*nv
, int namewidth
, int depth
)
1450 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_TYPE
, &type
) == 0);
1451 if (strcmp(type
, VDEV_TYPE_MISSING
) == 0 ||
1452 strcmp(type
, VDEV_TYPE_HOLE
) == 0)
1455 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
1456 (uint64_t **)&vs
, &c
) == 0);
1458 (void) printf("\t%*s%-*s", depth
, "", namewidth
- depth
, name
);
1459 (void) printf(" %s", zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
));
1461 if (vs
->vs_aux
!= 0) {
1464 switch (vs
->vs_aux
) {
1465 case VDEV_AUX_OPEN_FAILED
:
1466 (void) printf(gettext("cannot open"));
1469 case VDEV_AUX_BAD_GUID_SUM
:
1470 (void) printf(gettext("missing device"));
1473 case VDEV_AUX_NO_REPLICAS
:
1474 (void) printf(gettext("insufficient replicas"));
1477 case VDEV_AUX_VERSION_NEWER
:
1478 (void) printf(gettext("newer version"));
1481 case VDEV_AUX_UNSUP_FEAT
:
1482 (void) printf(gettext("unsupported feature(s)"));
1485 case VDEV_AUX_ERR_EXCEEDED
:
1486 (void) printf(gettext("too many errors"));
1490 (void) printf(gettext("corrupted data"));
1494 (void) printf("\n");
1496 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1497 &child
, &children
) != 0)
1500 for (c
= 0; c
< children
; c
++) {
1501 uint64_t is_log
= B_FALSE
;
1503 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1508 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
], B_TRUE
);
1509 print_import_config(vname
, child
[c
], namewidth
, depth
+ 2);
1513 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
1514 &child
, &children
) == 0) {
1515 (void) printf(gettext("\tcache\n"));
1516 for (c
= 0; c
< children
; c
++) {
1517 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
], B_FALSE
);
1518 (void) printf("\t %s\n", vname
);
1523 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
1524 &child
, &children
) == 0) {
1525 (void) printf(gettext("\tspares\n"));
1526 for (c
= 0; c
< children
; c
++) {
1527 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
], B_FALSE
);
1528 (void) printf("\t %s\n", vname
);
1536 * Logs are recorded as top level vdevs in the main pool child array
1537 * but with "is_log" set to 1. We use either print_status_config() or
1538 * print_import_config() to print the top level logs then any log
1539 * children (eg mirrored slogs) are printed recursively - which
1540 * works because only the top level vdev is marked "is_log"
1543 print_logs(zpool_handle_t
*zhp
, nvlist_t
*nv
, int namewidth
, boolean_t verbose
)
1548 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
, &child
,
1552 (void) printf(gettext("\tlogs\n"));
1554 for (c
= 0; c
< children
; c
++) {
1555 uint64_t is_log
= B_FALSE
;
1558 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1562 name
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], B_TRUE
);
1564 print_status_config(zhp
, name
, child
[c
], namewidth
,
1567 print_import_config(name
, child
[c
], namewidth
, 2);
1573 * Display the status for the given pool.
1576 show_import(nvlist_t
*config
)
1578 uint64_t pool_state
;
1590 verify(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
1592 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
,
1594 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
1596 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
1599 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_VDEV_STATS
,
1600 (uint64_t **)&vs
, &vsc
) == 0);
1601 health
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
1603 reason
= zpool_import_status(config
, &msgid
);
1605 (void) printf(gettext(" pool: %s\n"), name
);
1606 (void) printf(gettext(" id: %llu\n"), (u_longlong_t
)guid
);
1607 (void) printf(gettext(" state: %s"), health
);
1608 if (pool_state
== POOL_STATE_DESTROYED
)
1609 (void) printf(gettext(" (DESTROYED)"));
1610 (void) printf("\n");
1613 case ZPOOL_STATUS_MISSING_DEV_R
:
1614 case ZPOOL_STATUS_MISSING_DEV_NR
:
1615 case ZPOOL_STATUS_BAD_GUID_SUM
:
1616 (void) printf(gettext(" status: One or more devices are "
1617 "missing from the system.\n"));
1620 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
1621 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
1622 (void) printf(gettext(" status: One or more devices contains "
1623 "corrupted data.\n"));
1626 case ZPOOL_STATUS_CORRUPT_DATA
:
1628 gettext(" status: The pool data is corrupted.\n"));
1631 case ZPOOL_STATUS_OFFLINE_DEV
:
1632 (void) printf(gettext(" status: One or more devices "
1633 "are offlined.\n"));
1636 case ZPOOL_STATUS_CORRUPT_POOL
:
1637 (void) printf(gettext(" status: The pool metadata is "
1641 case ZPOOL_STATUS_VERSION_OLDER
:
1642 (void) printf(gettext(" status: The pool is formatted using a "
1643 "legacy on-disk version.\n"));
1646 case ZPOOL_STATUS_VERSION_NEWER
:
1647 (void) printf(gettext(" status: The pool is formatted using an "
1648 "incompatible version.\n"));
1651 case ZPOOL_STATUS_FEAT_DISABLED
:
1652 (void) printf(gettext(" status: Some supported features are "
1653 "not enabled on the pool.\n"));
1656 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
1657 (void) printf(gettext("status: The pool uses the following "
1658 "feature(s) not supported on this sytem:\n"));
1659 zpool_print_unsup_feat(config
);
1662 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
1663 (void) printf(gettext("status: The pool can only be accessed "
1664 "in read-only mode on this system. It\n\tcannot be "
1665 "accessed in read-write mode because it uses the "
1666 "following\n\tfeature(s) not supported on this system:\n"));
1667 zpool_print_unsup_feat(config
);
1670 case ZPOOL_STATUS_HOSTID_MISMATCH
:
1671 (void) printf(gettext(" status: The pool was last accessed by "
1672 "another system.\n"));
1675 case ZPOOL_STATUS_FAULTED_DEV_R
:
1676 case ZPOOL_STATUS_FAULTED_DEV_NR
:
1677 (void) printf(gettext(" status: One or more devices are "
1681 case ZPOOL_STATUS_BAD_LOG
:
1682 (void) printf(gettext(" status: An intent log record cannot be "
1686 case ZPOOL_STATUS_RESILVERING
:
1687 (void) printf(gettext(" status: One or more devices were being "
1693 * No other status can be seen when importing pools.
1695 assert(reason
== ZPOOL_STATUS_OK
);
1699 * Print out an action according to the overall state of the pool.
1701 if (vs
->vs_state
== VDEV_STATE_HEALTHY
) {
1702 if (reason
== ZPOOL_STATUS_VERSION_OLDER
||
1703 reason
== ZPOOL_STATUS_FEAT_DISABLED
) {
1704 (void) printf(gettext(" action: The pool can be "
1705 "imported using its name or numeric identifier, "
1706 "though\n\tsome features will not be available "
1707 "without an explicit 'zpool upgrade'.\n"));
1708 } else if (reason
== ZPOOL_STATUS_HOSTID_MISMATCH
) {
1709 (void) printf(gettext(" action: The pool can be "
1710 "imported using its name or numeric "
1711 "identifier and\n\tthe '-f' flag.\n"));
1713 (void) printf(gettext(" action: The pool can be "
1714 "imported using its name or numeric "
1717 } else if (vs
->vs_state
== VDEV_STATE_DEGRADED
) {
1718 (void) printf(gettext(" action: The pool can be imported "
1719 "despite missing or damaged devices. The\n\tfault "
1720 "tolerance of the pool may be compromised if imported.\n"));
1723 case ZPOOL_STATUS_VERSION_NEWER
:
1724 (void) printf(gettext(" action: The pool cannot be "
1725 "imported. Access the pool on a system running "
1726 "newer\n\tsoftware, or recreate the pool from "
1729 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
1730 (void) printf(gettext("action: The pool cannot be "
1731 "imported. Access the pool on a system that "
1732 "supports\n\tthe required feature(s), or recreate "
1733 "the pool from backup.\n"));
1735 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
1736 (void) printf(gettext("action: The pool cannot be "
1737 "imported in read-write mode. Import the pool "
1739 "\t\"-o readonly=on\", access the pool on a system "
1740 "that supports the\n\trequired feature(s), or "
1741 "recreate the pool from backup.\n"));
1743 case ZPOOL_STATUS_MISSING_DEV_R
:
1744 case ZPOOL_STATUS_MISSING_DEV_NR
:
1745 case ZPOOL_STATUS_BAD_GUID_SUM
:
1746 (void) printf(gettext(" action: The pool cannot be "
1747 "imported. Attach the missing\n\tdevices and try "
1751 (void) printf(gettext(" action: The pool cannot be "
1752 "imported due to damaged devices or data.\n"));
1756 /* Print the comment attached to the pool. */
1757 if (nvlist_lookup_string(config
, ZPOOL_CONFIG_COMMENT
, &comment
) == 0)
1758 (void) printf(gettext("comment: %s\n"), comment
);
1761 * If the state is "closed" or "can't open", and the aux state
1762 * is "corrupt data":
1764 if (((vs
->vs_state
== VDEV_STATE_CLOSED
) ||
1765 (vs
->vs_state
== VDEV_STATE_CANT_OPEN
)) &&
1766 (vs
->vs_aux
== VDEV_AUX_CORRUPT_DATA
)) {
1767 if (pool_state
== POOL_STATE_DESTROYED
)
1768 (void) printf(gettext("\tThe pool was destroyed, "
1769 "but can be imported using the '-Df' flags.\n"));
1770 else if (pool_state
!= POOL_STATE_EXPORTED
)
1771 (void) printf(gettext("\tThe pool may be active on "
1772 "another system, but can be imported using\n\t"
1773 "the '-f' flag.\n"));
1777 (void) printf(gettext(" see: http://zfsonlinux.org/msg/%s\n"),
1780 (void) printf(gettext(" config:\n\n"));
1782 namewidth
= max_width(NULL
, nvroot
, 0, 0);
1786 print_import_config(name
, nvroot
, namewidth
, 0);
1787 if (num_logs(nvroot
) > 0)
1788 print_logs(NULL
, nvroot
, namewidth
, B_FALSE
);
1790 if (reason
== ZPOOL_STATUS_BAD_GUID_SUM
) {
1791 (void) printf(gettext("\n\tAdditional devices are known to "
1792 "be part of this pool, though their\n\texact "
1793 "configuration cannot be determined.\n"));
1798 * Perform the import for the given configuration. This passes the heavy
1799 * lifting off to zpool_import_props(), and then mounts the datasets contained
1803 do_import(nvlist_t
*config
, const char *newname
, const char *mntopts
,
1804 nvlist_t
*props
, int flags
)
1806 zpool_handle_t
*zhp
;
1811 verify(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
1814 verify(nvlist_lookup_uint64(config
,
1815 ZPOOL_CONFIG_POOL_STATE
, &state
) == 0);
1816 verify(nvlist_lookup_uint64(config
,
1817 ZPOOL_CONFIG_VERSION
, &version
) == 0);
1818 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
1819 (void) fprintf(stderr
, gettext("cannot import '%s': pool "
1820 "is formatted using an unsupported ZFS version\n"), name
);
1822 } else if (state
!= POOL_STATE_EXPORTED
&&
1823 !(flags
& ZFS_IMPORT_ANY_HOST
)) {
1826 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_HOSTID
,
1828 unsigned long system_hostid
= gethostid() & 0xffffffff;
1830 if ((unsigned long)hostid
!= system_hostid
) {
1835 verify(nvlist_lookup_string(config
,
1836 ZPOOL_CONFIG_HOSTNAME
, &hostname
) == 0);
1837 verify(nvlist_lookup_uint64(config
,
1838 ZPOOL_CONFIG_TIMESTAMP
, ×tamp
) == 0);
1840 (void) fprintf(stderr
, gettext("cannot import "
1841 "'%s': pool may be in use from other "
1842 "system, it was last accessed by %s "
1843 "(hostid: 0x%lx) on %s"), name
, hostname
,
1844 (unsigned long)hostid
,
1845 asctime(localtime(&t
)));
1846 (void) fprintf(stderr
, gettext("use '-f' to "
1847 "import anyway\n"));
1851 (void) fprintf(stderr
, gettext("cannot import '%s': "
1852 "pool may be in use from other system\n"), name
);
1853 (void) fprintf(stderr
, gettext("use '-f' to import "
1859 if (zpool_import_props(g_zfs
, config
, newname
, props
, flags
) != 0)
1862 if (newname
!= NULL
)
1863 name
= (char *)newname
;
1865 if ((zhp
= zpool_open_canfail(g_zfs
, name
)) == NULL
)
1868 if (zpool_get_state(zhp
) != POOL_STATE_UNAVAIL
&&
1869 !(flags
& ZFS_IMPORT_ONLY
) &&
1870 zpool_enable_datasets(zhp
, mntopts
, 0) != 0) {
1880 * zpool import [-d dir] [-D]
1881 * import [-o mntopts] [-o prop=value] ... [-R root] [-D]
1882 * [-d dir | -c cachefile] [-f] -a
1883 * import [-o mntopts] [-o prop=value] ... [-R root] [-D]
1884 * [-d dir | -c cachefile] [-f] [-n] [-F] <pool | id> [newpool]
1886 * -c Read pool information from a cachefile instead of searching
1889 * -d Scan in a specific directory, other than /dev/. More than
1890 * one directory can be specified using multiple '-d' options.
1892 * -D Scan for previously destroyed pools or import all or only
1893 * specified destroyed pools.
1895 * -R Temporarily import the pool, with all mountpoints relative to
1896 * the given root. The pool will remain exported when the machine
1899 * -V Import even in the presence of faulted vdevs. This is an
1900 * intentionally undocumented option for testing purposes, and
1901 * treats the pool configuration as complete, leaving any bad
1902 * vdevs in the FAULTED state. In other words, it does verbatim
1905 * -f Force import, even if it appears that the pool is active.
1907 * -F Attempt rewind if necessary.
1909 * -n See if rewind would work, but don't actually rewind.
1911 * -N Import the pool but don't mount datasets.
1913 * -T Specify a starting txg to use for import. This option is
1914 * intentionally undocumented option for testing purposes.
1916 * -a Import all pools found.
1918 * -o Set property=value and/or temporary mount options (without '=').
1920 * The import command scans for pools to import, and import pools based on pool
1921 * name and GUID. The pool can also be renamed as part of the import process.
1924 zpool_do_import(int argc
, char **argv
)
1926 char **searchdirs
= NULL
;
1927 char *env
, *envdup
= NULL
;
1931 nvlist_t
*pools
= NULL
;
1932 boolean_t do_all
= B_FALSE
;
1933 boolean_t do_destroyed
= B_FALSE
;
1934 char *mntopts
= NULL
;
1937 uint64_t searchguid
= 0;
1938 char *searchname
= NULL
;
1940 nvlist_t
*found_config
;
1941 nvlist_t
*policy
= NULL
;
1942 nvlist_t
*props
= NULL
;
1944 int flags
= ZFS_IMPORT_NORMAL
;
1945 uint32_t rewind_policy
= ZPOOL_NO_REWIND
;
1946 boolean_t dryrun
= B_FALSE
;
1947 boolean_t do_rewind
= B_FALSE
;
1948 boolean_t xtreme_rewind
= B_FALSE
;
1949 uint64_t pool_state
, txg
= -1ULL;
1950 char *cachefile
= NULL
;
1951 importargs_t idata
= { 0 };
1955 while ((c
= getopt(argc
, argv
, ":aCc:d:DEfFmnNo:rR:T:VX")) != -1) {
1964 if (searchdirs
== NULL
) {
1965 searchdirs
= safe_malloc(sizeof (char *));
1967 char **tmp
= safe_malloc((nsearch
+ 1) *
1969 bcopy(searchdirs
, tmp
, nsearch
*
1974 searchdirs
[nsearch
++] = optarg
;
1977 do_destroyed
= B_TRUE
;
1980 flags
|= ZFS_IMPORT_ANY_HOST
;
1986 flags
|= ZFS_IMPORT_MISSING_LOG
;
1992 flags
|= ZFS_IMPORT_ONLY
;
1995 if ((propval
= strchr(optarg
, '=')) != NULL
) {
1998 if (add_prop_list(optarg
, propval
,
2006 if (add_prop_list(zpool_prop_to_name(
2007 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
2009 if (nvlist_lookup_string(props
,
2010 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
),
2013 if (add_prop_list(zpool_prop_to_name(
2014 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
2019 txg
= strtoull(optarg
, &endptr
, 10);
2020 if (errno
!= 0 || *endptr
!= '\0') {
2021 (void) fprintf(stderr
,
2022 gettext("invalid txg value\n"));
2025 rewind_policy
= ZPOOL_DO_REWIND
| ZPOOL_EXTREME_REWIND
;
2028 flags
|= ZFS_IMPORT_VERBATIM
;
2031 xtreme_rewind
= B_TRUE
;
2034 (void) fprintf(stderr
, gettext("missing argument for "
2035 "'%c' option\n"), optopt
);
2039 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2048 if (cachefile
&& nsearch
!= 0) {
2049 (void) fprintf(stderr
, gettext("-c is incompatible with -d\n"));
2053 if ((dryrun
|| xtreme_rewind
) && !do_rewind
) {
2054 (void) fprintf(stderr
,
2055 gettext("-n or -X only meaningful with -F\n"));
2059 rewind_policy
= ZPOOL_TRY_REWIND
;
2061 rewind_policy
= ZPOOL_DO_REWIND
;
2063 rewind_policy
|= ZPOOL_EXTREME_REWIND
;
2065 /* In the future, we can capture further policy and include it here */
2066 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME
, 0) != 0 ||
2067 nvlist_add_uint64(policy
, ZPOOL_REWIND_REQUEST_TXG
, txg
) != 0 ||
2068 nvlist_add_uint32(policy
, ZPOOL_REWIND_REQUEST
, rewind_policy
) != 0)
2071 /* check argument count */
2074 (void) fprintf(stderr
, gettext("too many arguments\n"));
2079 (void) fprintf(stderr
, gettext("too many arguments\n"));
2084 * Check for the SYS_CONFIG privilege. We do this explicitly
2085 * here because otherwise any attempt to discover pools will
2088 if (argc
== 0 && !priv_ineffect(PRIV_SYS_CONFIG
)) {
2089 (void) fprintf(stderr
, gettext("cannot "
2090 "discover pools: permission denied\n"));
2091 if (searchdirs
!= NULL
)
2094 nvlist_free(policy
);
2100 * Depending on the arguments given, we do one of the following:
2102 * <none> Iterate through all pools and display information about
2105 * -a Iterate through all pools and try to import each one.
2107 * <id> Find the pool that corresponds to the given GUID/pool
2108 * name and import that one.
2110 * -D Above options applies only to destroyed pools.
2116 searchguid
= strtoull(argv
[0], &endptr
, 10);
2117 if (errno
!= 0 || *endptr
!= '\0')
2118 searchname
= argv
[0];
2119 found_config
= NULL
;
2122 * User specified a name or guid. Ensure it's unique.
2124 idata
.unique
= B_TRUE
;
2128 * Check the environment for the preferred search path.
2130 if ((searchdirs
== NULL
) && (env
= getenv("ZPOOL_IMPORT_PATH"))) {
2133 envdup
= strdup(env
);
2135 dir
= strtok(envdup
, ":");
2136 while (dir
!= NULL
) {
2137 if (searchdirs
== NULL
) {
2138 searchdirs
= safe_malloc(sizeof (char *));
2140 char **tmp
= safe_malloc((nsearch
+ 1) *
2142 bcopy(searchdirs
, tmp
, nsearch
*
2147 searchdirs
[nsearch
++] = dir
;
2148 dir
= strtok(NULL
, ":");
2152 idata
.path
= searchdirs
;
2153 idata
.paths
= nsearch
;
2154 idata
.poolname
= searchname
;
2155 idata
.guid
= searchguid
;
2156 idata
.cachefile
= cachefile
;
2158 pools
= zpool_search_import(g_zfs
, &idata
);
2160 if (pools
!= NULL
&& idata
.exists
&&
2161 (argc
== 1 || strcmp(argv
[0], argv
[1]) == 0)) {
2162 (void) fprintf(stderr
, gettext("cannot import '%s': "
2163 "a pool with that name already exists\n"),
2165 (void) fprintf(stderr
, gettext("use the form '%s "
2166 "<pool | id> <newpool>' to give it a new name\n"),
2169 } else if (pools
== NULL
&& idata
.exists
) {
2170 (void) fprintf(stderr
, gettext("cannot import '%s': "
2171 "a pool with that name is already created/imported,\n"),
2173 (void) fprintf(stderr
, gettext("and no additional pools "
2174 "with that name were found\n"));
2176 } else if (pools
== NULL
) {
2178 (void) fprintf(stderr
, gettext("cannot import '%s': "
2179 "no such pool available\n"), argv
[0]);
2185 if (searchdirs
!= NULL
)
2189 nvlist_free(policy
);
2194 * At this point we have a list of import candidate configs. Even if
2195 * we were searching by pool name or guid, we still need to
2196 * post-process the list to deal with pool state and possible
2202 while ((elem
= nvlist_next_nvpair(pools
, elem
)) != NULL
) {
2204 verify(nvpair_value_nvlist(elem
, &config
) == 0);
2206 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
2208 if (!do_destroyed
&& pool_state
== POOL_STATE_DESTROYED
)
2210 if (do_destroyed
&& pool_state
!= POOL_STATE_DESTROYED
)
2213 verify(nvlist_add_nvlist(config
, ZPOOL_REWIND_POLICY
,
2220 (void) printf("\n");
2223 err
|= do_import(config
, NULL
, mntopts
,
2226 show_import(config
);
2228 } else if (searchname
!= NULL
) {
2232 * We are searching for a pool based on name.
2234 verify(nvlist_lookup_string(config
,
2235 ZPOOL_CONFIG_POOL_NAME
, &name
) == 0);
2237 if (strcmp(name
, searchname
) == 0) {
2238 if (found_config
!= NULL
) {
2239 (void) fprintf(stderr
, gettext(
2240 "cannot import '%s': more than "
2241 "one matching pool\n"), searchname
);
2242 (void) fprintf(stderr
, gettext(
2243 "import by numeric ID instead\n"));
2246 found_config
= config
;
2252 * Search for a pool by guid.
2254 verify(nvlist_lookup_uint64(config
,
2255 ZPOOL_CONFIG_POOL_GUID
, &guid
) == 0);
2257 if (guid
== searchguid
)
2258 found_config
= config
;
2263 * If we were searching for a specific pool, verify that we found a
2264 * pool, and then do the import.
2266 if (argc
!= 0 && err
== 0) {
2267 if (found_config
== NULL
) {
2268 (void) fprintf(stderr
, gettext("cannot import '%s': "
2269 "no such pool available\n"), argv
[0]);
2272 err
|= do_import(found_config
, argc
== 1 ? NULL
:
2273 argv
[1], mntopts
, props
, flags
);
2278 * If we were just looking for pools, report an error if none were
2281 if (argc
== 0 && first
)
2282 (void) fprintf(stderr
,
2283 gettext("no pools available to import\n"));
2288 nvlist_free(policy
);
2289 if (searchdirs
!= NULL
)
2294 return (err
? 1 : 0);
2297 typedef struct iostat_cbdata
{
2298 boolean_t cb_verbose
;
2301 zpool_list_t
*cb_list
;
2305 print_iostat_separator(iostat_cbdata_t
*cb
)
2309 for (i
= 0; i
< cb
->cb_namewidth
; i
++)
2311 (void) printf(" ----- ----- ----- ----- ----- -----\n");
2315 print_iostat_header(iostat_cbdata_t
*cb
)
2317 (void) printf("%*s capacity operations bandwidth\n",
2318 cb
->cb_namewidth
, "");
2319 (void) printf("%-*s alloc free read write read write\n",
2320 cb
->cb_namewidth
, "pool");
2321 print_iostat_separator(cb
);
2325 * Display a single statistic.
2328 print_one_stat(uint64_t value
)
2332 zfs_nicenum(value
, buf
, sizeof (buf
));
2333 (void) printf(" %5s", buf
);
2337 * Print out all the statistics for the given vdev. This can either be the
2338 * toplevel configuration, or called recursively. If 'name' is NULL, then this
2339 * is a verbose output, and we don't want to display the toplevel pool stats.
2342 print_vdev_stats(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*oldnv
,
2343 nvlist_t
*newnv
, iostat_cbdata_t
*cb
, int depth
)
2345 nvlist_t
**oldchild
, **newchild
;
2347 vdev_stat_t
*oldvs
, *newvs
;
2348 vdev_stat_t zerovs
= { 0 };
2353 if (oldnv
!= NULL
) {
2354 verify(nvlist_lookup_uint64_array(oldnv
,
2355 ZPOOL_CONFIG_VDEV_STATS
, (uint64_t **)&oldvs
, &c
) == 0);
2360 verify(nvlist_lookup_uint64_array(newnv
, ZPOOL_CONFIG_VDEV_STATS
,
2361 (uint64_t **)&newvs
, &c
) == 0);
2363 if (strlen(name
) + depth
> cb
->cb_namewidth
)
2364 (void) printf("%*s%s", depth
, "", name
);
2366 (void) printf("%*s%s%*s", depth
, "", name
,
2367 (int)(cb
->cb_namewidth
- strlen(name
) - depth
), "");
2369 tdelta
= newvs
->vs_timestamp
- oldvs
->vs_timestamp
;
2374 scale
= (double)NANOSEC
/ tdelta
;
2376 /* only toplevel vdevs have capacity stats */
2377 if (newvs
->vs_space
== 0) {
2378 (void) printf(" - -");
2380 print_one_stat(newvs
->vs_alloc
);
2381 print_one_stat(newvs
->vs_space
- newvs
->vs_alloc
);
2384 print_one_stat((uint64_t)(scale
* (newvs
->vs_ops
[ZIO_TYPE_READ
] -
2385 oldvs
->vs_ops
[ZIO_TYPE_READ
])));
2387 print_one_stat((uint64_t)(scale
* (newvs
->vs_ops
[ZIO_TYPE_WRITE
] -
2388 oldvs
->vs_ops
[ZIO_TYPE_WRITE
])));
2390 print_one_stat((uint64_t)(scale
* (newvs
->vs_bytes
[ZIO_TYPE_READ
] -
2391 oldvs
->vs_bytes
[ZIO_TYPE_READ
])));
2393 print_one_stat((uint64_t)(scale
* (newvs
->vs_bytes
[ZIO_TYPE_WRITE
] -
2394 oldvs
->vs_bytes
[ZIO_TYPE_WRITE
])));
2396 (void) printf("\n");
2398 if (!cb
->cb_verbose
)
2401 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_CHILDREN
,
2402 &newchild
, &children
) != 0)
2405 if (oldnv
&& nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_CHILDREN
,
2406 &oldchild
, &c
) != 0)
2409 for (c
= 0; c
< children
; c
++) {
2410 uint64_t ishole
= B_FALSE
, islog
= B_FALSE
;
2412 (void) nvlist_lookup_uint64(newchild
[c
], ZPOOL_CONFIG_IS_HOLE
,
2415 (void) nvlist_lookup_uint64(newchild
[c
], ZPOOL_CONFIG_IS_LOG
,
2418 if (ishole
|| islog
)
2421 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
], B_FALSE
);
2422 print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
] : NULL
,
2423 newchild
[c
], cb
, depth
+ 2);
2428 * Log device section
2431 if (num_logs(newnv
) > 0) {
2432 (void) printf("%-*s - - - - - "
2433 "-\n", cb
->cb_namewidth
, "logs");
2435 for (c
= 0; c
< children
; c
++) {
2436 uint64_t islog
= B_FALSE
;
2437 (void) nvlist_lookup_uint64(newchild
[c
],
2438 ZPOOL_CONFIG_IS_LOG
, &islog
);
2441 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
2443 print_vdev_stats(zhp
, vname
, oldnv
?
2444 oldchild
[c
] : NULL
, newchild
[c
],
2453 * Include level 2 ARC devices in iostat output
2455 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_L2CACHE
,
2456 &newchild
, &children
) != 0)
2459 if (oldnv
&& nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_L2CACHE
,
2460 &oldchild
, &c
) != 0)
2464 (void) printf("%-*s - - - - - "
2465 "-\n", cb
->cb_namewidth
, "cache");
2466 for (c
= 0; c
< children
; c
++) {
2467 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
2469 print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
] : NULL
,
2470 newchild
[c
], cb
, depth
+ 2);
2477 refresh_iostat(zpool_handle_t
*zhp
, void *data
)
2479 iostat_cbdata_t
*cb
= data
;
2483 * If the pool has disappeared, remove it from the list and continue.
2485 if (zpool_refresh_stats(zhp
, &missing
) != 0)
2489 pool_list_remove(cb
->cb_list
, zhp
);
2495 * Callback to print out the iostats for the given pool.
2498 print_iostat(zpool_handle_t
*zhp
, void *data
)
2500 iostat_cbdata_t
*cb
= data
;
2501 nvlist_t
*oldconfig
, *newconfig
;
2502 nvlist_t
*oldnvroot
, *newnvroot
;
2504 newconfig
= zpool_get_config(zhp
, &oldconfig
);
2506 if (cb
->cb_iteration
== 1)
2509 verify(nvlist_lookup_nvlist(newconfig
, ZPOOL_CONFIG_VDEV_TREE
,
2512 if (oldconfig
== NULL
)
2515 verify(nvlist_lookup_nvlist(oldconfig
, ZPOOL_CONFIG_VDEV_TREE
,
2519 * Print out the statistics for the pool.
2521 print_vdev_stats(zhp
, zpool_get_name(zhp
), oldnvroot
, newnvroot
, cb
, 0);
2524 print_iostat_separator(cb
);
2536 if (isatty(STDOUT_FILENO
)) {
2537 error
= ioctl(STDOUT_FILENO
, TIOCGWINSZ
, &ws
);
2539 columns
= ws
.ws_col
;
2548 get_namewidth(zpool_handle_t
*zhp
, void *data
)
2550 iostat_cbdata_t
*cb
= data
;
2551 nvlist_t
*config
, *nvroot
;
2554 if ((config
= zpool_get_config(zhp
, NULL
)) != NULL
) {
2555 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
2557 if (!cb
->cb_verbose
)
2558 cb
->cb_namewidth
= strlen(zpool_get_name(zhp
));
2560 cb
->cb_namewidth
= max_width(zhp
, nvroot
, 0,
2565 * The width must be at least 10, but may be as large as the
2566 * column width - 42 so that we can still fit in one line.
2568 columns
= get_columns();
2570 if (cb
->cb_namewidth
< 10)
2571 cb
->cb_namewidth
= 10;
2572 if (cb
->cb_namewidth
> columns
- 42)
2573 cb
->cb_namewidth
= columns
- 42;
2579 * Parse the input string, get the 'interval' and 'count' value if there is one.
2582 get_interval_count(int *argcp
, char **argv
, unsigned long *iv
,
2585 unsigned long interval
= 0, count
= 0;
2589 * Determine if the last argument is an integer or a pool name
2591 if (argc
> 0 && isdigit(argv
[argc
- 1][0])) {
2595 interval
= strtoul(argv
[argc
- 1], &end
, 10);
2597 if (*end
== '\0' && errno
== 0) {
2598 if (interval
== 0) {
2599 (void) fprintf(stderr
, gettext("interval "
2600 "cannot be zero\n"));
2604 * Ignore the last parameter
2609 * If this is not a valid number, just plow on. The
2610 * user will get a more informative error message later
2618 * If the last argument is also an integer, then we have both a count
2621 if (argc
> 0 && isdigit(argv
[argc
- 1][0])) {
2626 interval
= strtoul(argv
[argc
- 1], &end
, 10);
2628 if (*end
== '\0' && errno
== 0) {
2629 if (interval
== 0) {
2630 (void) fprintf(stderr
, gettext("interval "
2631 "cannot be zero\n"));
2636 * Ignore the last parameter
2650 get_timestamp_arg(char c
)
2653 timestamp_fmt
= UDATE
;
2655 timestamp_fmt
= DDATE
;
2661 * zpool iostat [-v] [-T d|u] [pool] ... [interval [count]]
2663 * -v Display statistics for individual vdevs
2664 * -T Display a timestamp in date(1) or Unix format
2666 * This command can be tricky because we want to be able to deal with pool
2667 * creation/destruction as well as vdev configuration changes. The bulk of this
2668 * processing is handled by the pool_list_* routines in zpool_iter.c. We rely
2669 * on pool_list_update() to detect the addition of new pools. Configuration
2670 * changes are all handled within libzfs.
2673 zpool_do_iostat(int argc
, char **argv
)
2678 unsigned long interval
= 0, count
= 0;
2680 boolean_t verbose
= B_FALSE
;
2684 while ((c
= getopt(argc
, argv
, "T:v")) != -1) {
2687 get_timestamp_arg(*optarg
);
2693 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2702 get_interval_count(&argc
, argv
, &interval
, &count
);
2705 * Construct the list of all interesting pools.
2708 if ((list
= pool_list_get(argc
, argv
, NULL
, &ret
)) == NULL
)
2711 if (pool_list_count(list
) == 0 && argc
!= 0) {
2712 pool_list_free(list
);
2716 if (pool_list_count(list
) == 0 && interval
== 0) {
2717 pool_list_free(list
);
2718 (void) fprintf(stderr
, gettext("no pools available\n"));
2723 * Enter the main iostat loop.
2726 cb
.cb_verbose
= verbose
;
2727 cb
.cb_iteration
= 0;
2728 cb
.cb_namewidth
= 0;
2731 pool_list_update(list
);
2733 if ((npools
= pool_list_count(list
)) == 0)
2734 (void) fprintf(stderr
, gettext("no pools available\n"));
2737 * Refresh all statistics. This is done as an
2738 * explicit step before calculating the maximum name
2739 * width, so that any * configuration changes are
2740 * properly accounted for.
2742 (void) pool_list_iter(list
, B_FALSE
, refresh_iostat
,
2746 * Iterate over all pools to determine the maximum width
2747 * for the pool / device name column across all pools.
2749 cb
.cb_namewidth
= 0;
2750 (void) pool_list_iter(list
, B_FALSE
, get_namewidth
,
2753 if (timestamp_fmt
!= NODATE
)
2754 print_timestamp(timestamp_fmt
);
2757 * If it's the first time, or verbose mode, print the
2760 if (++cb
.cb_iteration
== 1 || verbose
)
2761 print_iostat_header(&cb
);
2763 (void) pool_list_iter(list
, B_FALSE
, print_iostat
, &cb
);
2766 * If there's more than one pool, and we're not in
2767 * verbose mode (which prints a separator for us),
2768 * then print a separator.
2770 if (npools
> 1 && !verbose
)
2771 print_iostat_separator(&cb
);
2774 (void) printf("\n");
2778 * Flush the output so that redirection to a file isn't buffered
2781 (void) fflush(stdout
);
2786 if (count
!= 0 && --count
== 0)
2789 (void) sleep(interval
);
2792 pool_list_free(list
);
2797 typedef struct list_cbdata
{
2798 boolean_t cb_verbose
;
2800 boolean_t cb_scripted
;
2801 zprop_list_t
*cb_proplist
;
2805 * Given a list of columns to display, output appropriate headers for each one.
2808 print_header(list_cbdata_t
*cb
)
2810 zprop_list_t
*pl
= cb
->cb_proplist
;
2811 char headerbuf
[ZPOOL_MAXPROPLEN
];
2813 boolean_t first
= B_TRUE
;
2814 boolean_t right_justify
;
2817 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
2818 width
= pl
->pl_width
;
2819 if (first
&& cb
->cb_verbose
) {
2821 * Reset the width to accommodate the verbose listing
2824 width
= cb
->cb_namewidth
;
2832 right_justify
= B_FALSE
;
2833 if (pl
->pl_prop
!= ZPROP_INVAL
) {
2834 header
= zpool_prop_column_name(pl
->pl_prop
);
2835 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
2839 for (i
= 0; pl
->pl_user_prop
[i
] != '\0'; i
++)
2840 headerbuf
[i
] = toupper(pl
->pl_user_prop
[i
]);
2841 headerbuf
[i
] = '\0';
2845 if (pl
->pl_next
== NULL
&& !right_justify
)
2846 (void) printf("%s", header
);
2847 else if (right_justify
)
2848 (void) printf("%*s", (int)width
, header
);
2850 (void) printf("%-*s", (int)width
, header
);
2853 (void) printf("\n");
2857 * Given a pool and a list of properties, print out all the properties according
2858 * to the described layout.
2861 print_pool(zpool_handle_t
*zhp
, list_cbdata_t
*cb
)
2863 zprop_list_t
*pl
= cb
->cb_proplist
;
2864 boolean_t first
= B_TRUE
;
2865 char property
[ZPOOL_MAXPROPLEN
];
2867 boolean_t right_justify
;
2870 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
2872 width
= pl
->pl_width
;
2873 if (first
&& cb
->cb_verbose
) {
2875 * Reset the width to accommodate the verbose listing
2878 width
= cb
->cb_namewidth
;
2882 if (cb
->cb_scripted
)
2883 (void) printf("\t");
2890 right_justify
= B_FALSE
;
2891 if (pl
->pl_prop
!= ZPROP_INVAL
) {
2892 if (pl
->pl_prop
== ZPOOL_PROP_EXPANDSZ
&&
2893 zpool_get_prop_int(zhp
, pl
->pl_prop
, NULL
) == 0)
2895 else if (zpool_get_prop(zhp
, pl
->pl_prop
, property
,
2896 sizeof (property
), NULL
) != 0)
2901 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
2902 } else if ((zpool_prop_feature(pl
->pl_user_prop
) ||
2903 zpool_prop_unsupported(pl
->pl_user_prop
)) &&
2904 zpool_prop_get_feature(zhp
, pl
->pl_user_prop
, property
,
2905 sizeof (property
)) == 0) {
2913 * If this is being called in scripted mode, or if this is the
2914 * last column and it is left-justified, don't include a width
2917 if (cb
->cb_scripted
|| (pl
->pl_next
== NULL
&& !right_justify
))
2918 (void) printf("%s", propstr
);
2919 else if (right_justify
)
2920 (void) printf("%*s", (int)width
, propstr
);
2922 (void) printf("%-*s", (int)width
, propstr
);
2925 (void) printf("\n");
2929 print_one_column(zpool_prop_t prop
, uint64_t value
, boolean_t scripted
)
2933 size_t width
= zprop_width(prop
, &fixed
, ZFS_TYPE_POOL
);
2935 zfs_nicenum(value
, propval
, sizeof (propval
));
2937 if (prop
== ZPOOL_PROP_EXPANDSZ
&& value
== 0)
2938 (void) strlcpy(propval
, "-", sizeof (propval
));
2941 (void) printf("\t%s", propval
);
2943 (void) printf(" %*s", (int)width
, propval
);
2947 print_list_stats(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
,
2948 list_cbdata_t
*cb
, int depth
)
2954 boolean_t scripted
= cb
->cb_scripted
;
2956 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
2957 (uint64_t **)&vs
, &c
) == 0);
2961 (void) printf("\t%s", name
);
2962 else if (strlen(name
) + depth
> cb
->cb_namewidth
)
2963 (void) printf("%*s%s", depth
, "", name
);
2965 (void) printf("%*s%s%*s", depth
, "", name
,
2966 (int)(cb
->cb_namewidth
- strlen(name
) - depth
), "");
2968 /* only toplevel vdevs have capacity stats */
2969 if (vs
->vs_space
== 0) {
2971 (void) printf("\t-\t-\t-");
2973 (void) printf(" - - -");
2975 print_one_column(ZPOOL_PROP_SIZE
, vs
->vs_space
,
2977 print_one_column(ZPOOL_PROP_CAPACITY
, vs
->vs_alloc
,
2979 print_one_column(ZPOOL_PROP_FREE
,
2980 vs
->vs_space
- vs
->vs_alloc
, scripted
);
2982 print_one_column(ZPOOL_PROP_EXPANDSZ
, vs
->vs_esize
,
2984 (void) printf("\n");
2987 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
2988 &child
, &children
) != 0)
2991 for (c
= 0; c
< children
; c
++) {
2992 uint64_t ishole
= B_FALSE
;
2994 if (nvlist_lookup_uint64(child
[c
],
2995 ZPOOL_CONFIG_IS_HOLE
, &ishole
) == 0 && ishole
)
2998 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], B_FALSE
);
2999 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
3004 * Include level 2 ARC devices in iostat output
3006 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
3007 &child
, &children
) != 0)
3011 (void) printf("%-*s - - - - - "
3012 "-\n", cb
->cb_namewidth
, "cache");
3013 for (c
= 0; c
< children
; c
++) {
3014 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
3016 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
3024 * Generic callback function to list a pool.
3027 list_callback(zpool_handle_t
*zhp
, void *data
)
3029 list_cbdata_t
*cbp
= data
;
3033 config
= zpool_get_config(zhp
, NULL
);
3035 print_pool(zhp
, cbp
);
3036 if (!cbp
->cb_verbose
)
3039 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
3041 print_list_stats(zhp
, NULL
, nvroot
, cbp
, 0);
3047 * zpool list [-H] [-o prop[,prop]*] [-T d|u] [pool] ... [interval [count]]
3049 * -H Scripted mode. Don't display headers, and separate properties
3051 * -o List of properties to display. Defaults to
3052 * "name,size,allocated,free,capacity,health,altroot"
3053 * -T Display a timestamp in date(1) or Unix format
3055 * List all pools in the system, whether or not they're healthy. Output space
3056 * statistics for each one, as well as health status summary.
3059 zpool_do_list(int argc
, char **argv
)
3063 list_cbdata_t cb
= { 0 };
3064 static char default_props
[] =
3065 "name,size,allocated,free,capacity,dedupratio,"
3067 char *props
= default_props
;
3068 unsigned long interval
= 0, count
= 0;
3070 boolean_t first
= B_TRUE
;
3073 while ((c
= getopt(argc
, argv
, ":Ho:T:v")) != -1) {
3076 cb
.cb_scripted
= B_TRUE
;
3082 get_timestamp_arg(*optarg
);
3085 cb
.cb_verbose
= B_TRUE
;
3088 (void) fprintf(stderr
, gettext("missing argument for "
3089 "'%c' option\n"), optopt
);
3093 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3102 get_interval_count(&argc
, argv
, &interval
, &count
);
3104 if (zprop_get_list(g_zfs
, props
, &cb
.cb_proplist
, ZFS_TYPE_POOL
) != 0)
3107 if ((list
= pool_list_get(argc
, argv
, &cb
.cb_proplist
, &ret
)) == NULL
)
3110 if (argc
== 0 && !cb
.cb_scripted
&& pool_list_count(list
) == 0) {
3111 (void) printf(gettext("no pools available\n"));
3112 zprop_free_list(cb
.cb_proplist
);
3117 pool_list_update(list
);
3119 if (pool_list_count(list
) == 0)
3122 if (timestamp_fmt
!= NODATE
)
3123 print_timestamp(timestamp_fmt
);
3125 if (!cb
.cb_scripted
&& (first
|| cb
.cb_verbose
)) {
3129 ret
= pool_list_iter(list
, B_TRUE
, list_callback
, &cb
);
3134 if (count
!= 0 && --count
== 0)
3137 (void) sleep(interval
);
3140 zprop_free_list(cb
.cb_proplist
);
3145 zpool_do_attach_or_replace(int argc
, char **argv
, int replacing
)
3147 boolean_t force
= B_FALSE
;
3150 char *poolname
, *old_disk
, *new_disk
;
3151 zpool_handle_t
*zhp
;
3152 nvlist_t
*props
= NULL
;
3157 while ((c
= getopt(argc
, argv
, "fo:")) != -1) {
3163 if ((propval
= strchr(optarg
, '=')) == NULL
) {
3164 (void) fprintf(stderr
, gettext("missing "
3165 "'=' for -o option\n"));
3171 if ((strcmp(optarg
, ZPOOL_CONFIG_ASHIFT
) != 0) ||
3172 (add_prop_list(optarg
, propval
, &props
, B_TRUE
)))
3176 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3185 /* get pool name and check number of arguments */
3187 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
3194 (void) fprintf(stderr
,
3195 gettext("missing <device> specification\n"));
3203 (void) fprintf(stderr
,
3204 gettext("missing <new_device> specification\n"));
3207 new_disk
= old_disk
;
3217 (void) fprintf(stderr
, gettext("too many arguments\n"));
3221 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
3224 if (zpool_get_config(zhp
, NULL
) == NULL
) {
3225 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
3231 nvroot
= make_root_vdev(zhp
, props
, force
, B_FALSE
, replacing
, B_FALSE
,
3233 if (nvroot
== NULL
) {
3238 ret
= zpool_vdev_attach(zhp
, old_disk
, new_disk
, nvroot
, replacing
);
3240 nvlist_free(nvroot
);
3247 * zpool replace [-f] <pool> <device> <new_device>
3249 * -f Force attach, even if <new_device> appears to be in use.
3251 * Replace <device> with <new_device>.
3255 zpool_do_replace(int argc
, char **argv
)
3257 return (zpool_do_attach_or_replace(argc
, argv
, B_TRUE
));
3261 * zpool attach [-f] [-o property=value] <pool> <device> <new_device>
3263 * -f Force attach, even if <new_device> appears to be in use.
3264 * -o Set property=value.
3266 * Attach <new_device> to the mirror containing <device>. If <device> is not
3267 * part of a mirror, then <device> will be transformed into a mirror of
3268 * <device> and <new_device>. In either case, <new_device> will begin life
3269 * with a DTL of [0, now], and will immediately begin to resilver itself.
3272 zpool_do_attach(int argc
, char **argv
)
3274 return (zpool_do_attach_or_replace(argc
, argv
, B_FALSE
));
3278 * zpool detach [-f] <pool> <device>
3280 * -f Force detach of <device>, even if DTLs argue against it
3281 * (not supported yet)
3283 * Detach a device from a mirror. The operation will be refused if <device>
3284 * is the last device in the mirror, or if the DTLs indicate that this device
3285 * has the only valid copy of some data.
3289 zpool_do_detach(int argc
, char **argv
)
3292 char *poolname
, *path
;
3293 zpool_handle_t
*zhp
;
3297 while ((c
= getopt(argc
, argv
, "f")) != -1) {
3301 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3310 /* get pool name and check number of arguments */
3312 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
3317 (void) fprintf(stderr
,
3318 gettext("missing <device> specification\n"));
3325 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
3328 ret
= zpool_vdev_detach(zhp
, path
);
3336 * zpool split [-n] [-o prop=val] ...
3338 * [-R altroot] <pool> <newpool> [<device> ...]
3340 * -n Do not split the pool, but display the resulting layout if
3341 * it were to be split.
3342 * -o Set property=value, or set mount options.
3343 * -R Mount the split-off pool under an alternate root.
3345 * Splits the named pool and gives it the new pool name. Devices to be split
3346 * off may be listed, provided that no more than one device is specified
3347 * per top-level vdev mirror. The newly split pool is left in an exported
3348 * state unless -R is specified.
3350 * Restrictions: the top-level of the pool pool must only be made up of
3351 * mirrors; all devices in the pool must be healthy; no device may be
3352 * undergoing a resilvering operation.
3355 zpool_do_split(int argc
, char **argv
)
3357 char *srcpool
, *newpool
, *propval
;
3358 char *mntopts
= NULL
;
3361 zpool_handle_t
*zhp
;
3362 nvlist_t
*config
, *props
= NULL
;
3364 flags
.dryrun
= B_FALSE
;
3365 flags
.import
= B_FALSE
;
3368 while ((c
= getopt(argc
, argv
, ":R:no:")) != -1) {
3371 flags
.import
= B_TRUE
;
3373 zpool_prop_to_name(ZPOOL_PROP_ALTROOT
), optarg
,
3374 &props
, B_TRUE
) != 0) {
3381 flags
.dryrun
= B_TRUE
;
3384 if ((propval
= strchr(optarg
, '=')) != NULL
) {
3387 if (add_prop_list(optarg
, propval
,
3388 &props
, B_TRUE
) != 0) {
3398 (void) fprintf(stderr
, gettext("missing argument for "
3399 "'%c' option\n"), optopt
);
3403 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3410 if (!flags
.import
&& mntopts
!= NULL
) {
3411 (void) fprintf(stderr
, gettext("setting mntopts is only "
3412 "valid when importing the pool\n"));
3420 (void) fprintf(stderr
, gettext("Missing pool name\n"));
3424 (void) fprintf(stderr
, gettext("Missing new pool name\n"));
3434 if ((zhp
= zpool_open(g_zfs
, srcpool
)) == NULL
)
3437 config
= split_mirror_vdev(zhp
, newpool
, props
, flags
, argc
, argv
);
3438 if (config
== NULL
) {
3442 (void) printf(gettext("would create '%s' with the "
3443 "following layout:\n\n"), newpool
);
3444 print_vdev_tree(NULL
, newpool
, config
, 0, B_FALSE
);
3446 nvlist_free(config
);
3451 if (ret
!= 0 || flags
.dryrun
|| !flags
.import
)
3455 * The split was successful. Now we need to open the new
3456 * pool and import it.
3458 if ((zhp
= zpool_open_canfail(g_zfs
, newpool
)) == NULL
)
3460 if (zpool_get_state(zhp
) != POOL_STATE_UNAVAIL
&&
3461 zpool_enable_datasets(zhp
, mntopts
, 0) != 0) {
3463 (void) fprintf(stderr
, gettext("Split was successful, but "
3464 "the datasets could not all be mounted\n"));
3465 (void) fprintf(stderr
, gettext("Try doing '%s' with a "
3466 "different altroot\n"), "zpool import");
3476 * zpool online <pool> <device> ...
3479 zpool_do_online(int argc
, char **argv
)
3483 zpool_handle_t
*zhp
;
3485 vdev_state_t newstate
;
3489 while ((c
= getopt(argc
, argv
, "et")) != -1) {
3492 flags
|= ZFS_ONLINE_EXPAND
;
3496 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3505 /* get pool name and check number of arguments */
3507 (void) fprintf(stderr
, gettext("missing pool name\n"));
3511 (void) fprintf(stderr
, gettext("missing device name\n"));
3517 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
3520 for (i
= 1; i
< argc
; i
++) {
3521 if (zpool_vdev_online(zhp
, argv
[i
], flags
, &newstate
) == 0) {
3522 if (newstate
!= VDEV_STATE_HEALTHY
) {
3523 (void) printf(gettext("warning: device '%s' "
3524 "onlined, but remains in faulted state\n"),
3526 if (newstate
== VDEV_STATE_FAULTED
)
3527 (void) printf(gettext("use 'zpool "
3528 "clear' to restore a faulted "
3531 (void) printf(gettext("use 'zpool "
3532 "replace' to replace devices "
3533 "that are no longer present\n"));
3546 * zpool offline [-ft] <pool> <device> ...
3548 * -f Force the device into the offline state, even if doing
3549 * so would appear to compromise pool availability.
3550 * (not supported yet)
3552 * -t Only take the device off-line temporarily. The offline
3553 * state will not be persistent across reboots.
3557 zpool_do_offline(int argc
, char **argv
)
3561 zpool_handle_t
*zhp
;
3563 boolean_t istmp
= B_FALSE
;
3566 while ((c
= getopt(argc
, argv
, "ft")) != -1) {
3573 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3582 /* get pool name and check number of arguments */
3584 (void) fprintf(stderr
, gettext("missing pool name\n"));
3588 (void) fprintf(stderr
, gettext("missing device name\n"));
3594 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
3597 for (i
= 1; i
< argc
; i
++) {
3598 if (zpool_vdev_offline(zhp
, argv
[i
], istmp
) != 0)
3608 * zpool clear <pool> [device]
3610 * Clear all errors associated with a pool or a particular device.
3613 zpool_do_clear(int argc
, char **argv
)
3617 boolean_t dryrun
= B_FALSE
;
3618 boolean_t do_rewind
= B_FALSE
;
3619 boolean_t xtreme_rewind
= B_FALSE
;
3620 uint32_t rewind_policy
= ZPOOL_NO_REWIND
;
3621 nvlist_t
*policy
= NULL
;
3622 zpool_handle_t
*zhp
;
3623 char *pool
, *device
;
3626 while ((c
= getopt(argc
, argv
, "FnX")) != -1) {
3635 xtreme_rewind
= B_TRUE
;
3638 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3648 (void) fprintf(stderr
, gettext("missing pool name\n"));
3653 (void) fprintf(stderr
, gettext("too many arguments\n"));
3657 if ((dryrun
|| xtreme_rewind
) && !do_rewind
) {
3658 (void) fprintf(stderr
,
3659 gettext("-n or -X only meaningful with -F\n"));
3663 rewind_policy
= ZPOOL_TRY_REWIND
;
3665 rewind_policy
= ZPOOL_DO_REWIND
;
3667 rewind_policy
|= ZPOOL_EXTREME_REWIND
;
3669 /* In future, further rewind policy choices can be passed along here */
3670 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME
, 0) != 0 ||
3671 nvlist_add_uint32(policy
, ZPOOL_REWIND_REQUEST
, rewind_policy
) != 0)
3675 device
= argc
== 2 ? argv
[1] : NULL
;
3677 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
) {
3678 nvlist_free(policy
);
3682 if (zpool_clear(zhp
, device
, policy
) != 0)
3687 nvlist_free(policy
);
3693 * zpool reguid <pool>
3696 zpool_do_reguid(int argc
, char **argv
)
3700 zpool_handle_t
*zhp
;
3704 while ((c
= getopt(argc
, argv
, "")) != -1) {
3707 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3716 /* get pool name and check number of arguments */
3718 (void) fprintf(stderr
, gettext("missing pool name\n"));
3723 (void) fprintf(stderr
, gettext("too many arguments\n"));
3728 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
3731 ret
= zpool_reguid(zhp
);
3739 * zpool reopen <pool>
3741 * Reopen the pool so that the kernel can update the sizes of all vdevs.
3744 zpool_do_reopen(int argc
, char **argv
)
3748 zpool_handle_t
*zhp
;
3752 while ((c
= getopt(argc
, argv
, "")) != -1) {
3755 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3765 (void) fprintf(stderr
, gettext("missing pool name\n"));
3770 (void) fprintf(stderr
, gettext("too many arguments\n"));
3775 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
)
3778 ret
= zpool_reopen(zhp
);
3783 typedef struct scrub_cbdata
{
3790 scrub_callback(zpool_handle_t
*zhp
, void *data
)
3792 scrub_cbdata_t
*cb
= data
;
3796 * Ignore faulted pools.
3798 if (zpool_get_state(zhp
) == POOL_STATE_UNAVAIL
) {
3799 (void) fprintf(stderr
, gettext("cannot scrub '%s': pool is "
3800 "currently unavailable\n"), zpool_get_name(zhp
));
3804 err
= zpool_scan(zhp
, cb
->cb_type
);
3810 * zpool scrub [-s] <pool> ...
3812 * -s Stop. Stops any in-progress scrub.
3815 zpool_do_scrub(int argc
, char **argv
)
3820 cb
.cb_type
= POOL_SCAN_SCRUB
;
3823 while ((c
= getopt(argc
, argv
, "s")) != -1) {
3826 cb
.cb_type
= POOL_SCAN_NONE
;
3829 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3841 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
3845 return (for_each_pool(argc
, argv
, B_TRUE
, NULL
, scrub_callback
, &cb
));
3848 typedef struct status_cbdata
{
3850 boolean_t cb_allpools
;
3851 boolean_t cb_verbose
;
3852 boolean_t cb_explain
;
3854 boolean_t cb_dedup_stats
;
3858 * Print out detailed scrub status.
3861 print_scan_status(pool_scan_stat_t
*ps
)
3864 uint64_t elapsed
, mins_left
, hours_left
;
3865 uint64_t pass_exam
, examined
, total
;
3867 double fraction_done
;
3868 char processed_buf
[7], examined_buf
[7], total_buf
[7], rate_buf
[7];
3870 (void) printf(gettext(" scan: "));
3872 /* If there's never been a scan, there's not much to say. */
3873 if (ps
== NULL
|| ps
->pss_func
== POOL_SCAN_NONE
||
3874 ps
->pss_func
>= POOL_SCAN_FUNCS
) {
3875 (void) printf(gettext("none requested\n"));
3879 start
= ps
->pss_start_time
;
3880 end
= ps
->pss_end_time
;
3881 zfs_nicenum(ps
->pss_processed
, processed_buf
, sizeof (processed_buf
));
3883 assert(ps
->pss_func
== POOL_SCAN_SCRUB
||
3884 ps
->pss_func
== POOL_SCAN_RESILVER
);
3886 * Scan is finished or canceled.
3888 if (ps
->pss_state
== DSS_FINISHED
) {
3889 uint64_t minutes_taken
= (end
- start
) / 60;
3892 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
3893 fmt
= gettext("scrub repaired %s in %lluh%um with "
3894 "%llu errors on %s");
3895 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
3896 fmt
= gettext("resilvered %s in %lluh%um with "
3897 "%llu errors on %s");
3900 (void) printf(fmt
, processed_buf
,
3901 (u_longlong_t
)(minutes_taken
/ 60),
3902 (uint_t
)(minutes_taken
% 60),
3903 (u_longlong_t
)ps
->pss_errors
,
3904 ctime((time_t *)&end
));
3906 } else if (ps
->pss_state
== DSS_CANCELED
) {
3907 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
3908 (void) printf(gettext("scrub canceled on %s"),
3910 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
3911 (void) printf(gettext("resilver canceled on %s"),
3917 assert(ps
->pss_state
== DSS_SCANNING
);
3920 * Scan is in progress.
3922 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
3923 (void) printf(gettext("scrub in progress since %s"),
3925 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
3926 (void) printf(gettext("resilver in progress since %s"),
3930 examined
= ps
->pss_examined
? ps
->pss_examined
: 1;
3931 total
= ps
->pss_to_examine
;
3932 fraction_done
= (double)examined
/ total
;
3934 /* elapsed time for this pass */
3935 elapsed
= time(NULL
) - ps
->pss_pass_start
;
3936 elapsed
= elapsed
? elapsed
: 1;
3937 pass_exam
= ps
->pss_pass_exam
? ps
->pss_pass_exam
: 1;
3938 rate
= pass_exam
/ elapsed
;
3939 rate
= rate
? rate
: 1;
3940 mins_left
= ((total
- examined
) / rate
) / 60;
3941 hours_left
= mins_left
/ 60;
3943 zfs_nicenum(examined
, examined_buf
, sizeof (examined_buf
));
3944 zfs_nicenum(total
, total_buf
, sizeof (total_buf
));
3945 zfs_nicenum(rate
, rate_buf
, sizeof (rate_buf
));
3948 * do not print estimated time if hours_left is more than 30 days
3950 (void) printf(gettext(" %s scanned out of %s at %s/s"),
3951 examined_buf
, total_buf
, rate_buf
);
3952 if (hours_left
< (30 * 24)) {
3953 (void) printf(gettext(", %lluh%um to go\n"),
3954 (u_longlong_t
)hours_left
, (uint_t
)(mins_left
% 60));
3956 (void) printf(gettext(
3957 ", (scan is slow, no estimated time)\n"));
3960 if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
3961 (void) printf(gettext(" %s resilvered, %.2f%% done\n"),
3962 processed_buf
, 100 * fraction_done
);
3963 } else if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
3964 (void) printf(gettext(" %s repaired, %.2f%% done\n"),
3965 processed_buf
, 100 * fraction_done
);
3970 print_error_log(zpool_handle_t
*zhp
)
3972 nvlist_t
*nverrlist
= NULL
;
3975 size_t len
= MAXPATHLEN
* 2;
3977 if (zpool_get_errlog(zhp
, &nverrlist
) != 0) {
3978 (void) printf("errors: List of errors unavailable "
3979 "(insufficient privileges)\n");
3983 (void) printf("errors: Permanent errors have been "
3984 "detected in the following files:\n\n");
3986 pathname
= safe_malloc(len
);
3988 while ((elem
= nvlist_next_nvpair(nverrlist
, elem
)) != NULL
) {
3990 uint64_t dsobj
, obj
;
3992 verify(nvpair_value_nvlist(elem
, &nv
) == 0);
3993 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_DATASET
,
3995 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_OBJECT
,
3997 zpool_obj_to_path(zhp
, dsobj
, obj
, pathname
, len
);
3998 (void) printf("%7s %s\n", "", pathname
);
4001 nvlist_free(nverrlist
);
4005 print_spares(zpool_handle_t
*zhp
, nvlist_t
**spares
, uint_t nspares
,
4014 (void) printf(gettext("\tspares\n"));
4016 for (i
= 0; i
< nspares
; i
++) {
4017 name
= zpool_vdev_name(g_zfs
, zhp
, spares
[i
], B_FALSE
);
4018 print_status_config(zhp
, name
, spares
[i
],
4019 namewidth
, 2, B_TRUE
);
4025 print_l2cache(zpool_handle_t
*zhp
, nvlist_t
**l2cache
, uint_t nl2cache
,
4034 (void) printf(gettext("\tcache\n"));
4036 for (i
= 0; i
< nl2cache
; i
++) {
4037 name
= zpool_vdev_name(g_zfs
, zhp
, l2cache
[i
], B_FALSE
);
4038 print_status_config(zhp
, name
, l2cache
[i
],
4039 namewidth
, 2, B_FALSE
);
4045 print_dedup_stats(nvlist_t
*config
)
4047 ddt_histogram_t
*ddh
;
4053 * If the pool was faulted then we may not have been able to
4054 * obtain the config. Otherwise, if we have anything in the dedup
4055 * table continue processing the stats.
4057 if (nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_OBJ_STATS
,
4058 (uint64_t **)&ddo
, &c
) != 0)
4061 (void) printf("\n");
4062 (void) printf(gettext(" dedup: "));
4063 if (ddo
->ddo_count
== 0) {
4064 (void) printf(gettext("no DDT entries\n"));
4068 (void) printf("DDT entries %llu, size %llu on disk, %llu in core\n",
4069 (u_longlong_t
)ddo
->ddo_count
,
4070 (u_longlong_t
)ddo
->ddo_dspace
,
4071 (u_longlong_t
)ddo
->ddo_mspace
);
4073 verify(nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_STATS
,
4074 (uint64_t **)&dds
, &c
) == 0);
4075 verify(nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_HISTOGRAM
,
4076 (uint64_t **)&ddh
, &c
) == 0);
4077 zpool_dump_ddt(dds
, ddh
);
4081 * Display a summary of pool status. Displays a summary such as:
4085 * reason: One or more devices ...
4086 * see: http://zfsonlinux.org/msg/ZFS-xxxx-01
4092 * When given the '-v' option, we print out the complete config. If the '-e'
4093 * option is specified, then we print out error rate information as well.
4096 status_callback(zpool_handle_t
*zhp
, void *data
)
4098 status_cbdata_t
*cbp
= data
;
4099 nvlist_t
*config
, *nvroot
;
4106 config
= zpool_get_config(zhp
, NULL
);
4107 reason
= zpool_get_status(zhp
, &msgid
);
4112 * If we were given 'zpool status -x', only report those pools with
4115 if (cbp
->cb_explain
&&
4116 (reason
== ZPOOL_STATUS_OK
||
4117 reason
== ZPOOL_STATUS_VERSION_OLDER
||
4118 reason
== ZPOOL_STATUS_FEAT_DISABLED
)) {
4119 if (!cbp
->cb_allpools
) {
4120 (void) printf(gettext("pool '%s' is healthy\n"),
4121 zpool_get_name(zhp
));
4123 cbp
->cb_first
= B_FALSE
;
4129 cbp
->cb_first
= B_FALSE
;
4131 (void) printf("\n");
4133 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
4135 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_VDEV_STATS
,
4136 (uint64_t **)&vs
, &c
) == 0);
4137 health
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
4139 (void) printf(gettext(" pool: %s\n"), zpool_get_name(zhp
));
4140 (void) printf(gettext(" state: %s\n"), health
);
4143 case ZPOOL_STATUS_MISSING_DEV_R
:
4144 (void) printf(gettext("status: One or more devices could not "
4145 "be opened. Sufficient replicas exist for\n\tthe pool to "
4146 "continue functioning in a degraded state.\n"));
4147 (void) printf(gettext("action: Attach the missing device and "
4148 "online it using 'zpool online'.\n"));
4151 case ZPOOL_STATUS_MISSING_DEV_NR
:
4152 (void) printf(gettext("status: One or more devices could not "
4153 "be opened. There are insufficient\n\treplicas for the "
4154 "pool to continue functioning.\n"));
4155 (void) printf(gettext("action: Attach the missing device and "
4156 "online it using 'zpool online'.\n"));
4159 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
4160 (void) printf(gettext("status: One or more devices could not "
4161 "be used because the label is missing or\n\tinvalid. "
4162 "Sufficient replicas exist for the pool to continue\n\t"
4163 "functioning in a degraded state.\n"));
4164 (void) printf(gettext("action: Replace the device using "
4165 "'zpool replace'.\n"));
4168 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
4169 (void) printf(gettext("status: One or more devices could not "
4170 "be used because the label is missing \n\tor invalid. "
4171 "There are insufficient replicas for the pool to "
4172 "continue\n\tfunctioning.\n"));
4173 zpool_explain_recover(zpool_get_handle(zhp
),
4174 zpool_get_name(zhp
), reason
, config
);
4177 case ZPOOL_STATUS_FAILING_DEV
:
4178 (void) printf(gettext("status: One or more devices has "
4179 "experienced an unrecoverable error. An\n\tattempt was "
4180 "made to correct the error. Applications are "
4182 (void) printf(gettext("action: Determine if the device needs "
4183 "to be replaced, and clear the errors\n\tusing "
4184 "'zpool clear' or replace the device with 'zpool "
4188 case ZPOOL_STATUS_OFFLINE_DEV
:
4189 (void) printf(gettext("status: One or more devices has "
4190 "been taken offline by the administrator.\n\tSufficient "
4191 "replicas exist for the pool to continue functioning in "
4192 "a\n\tdegraded state.\n"));
4193 (void) printf(gettext("action: Online the device using "
4194 "'zpool online' or replace the device with\n\t'zpool "
4198 case ZPOOL_STATUS_REMOVED_DEV
:
4199 (void) printf(gettext("status: One or more devices has "
4200 "been removed by the administrator.\n\tSufficient "
4201 "replicas exist for the pool to continue functioning in "
4202 "a\n\tdegraded state.\n"));
4203 (void) printf(gettext("action: Online the device using "
4204 "'zpool online' or replace the device with\n\t'zpool "
4208 case ZPOOL_STATUS_RESILVERING
:
4209 (void) printf(gettext("status: One or more devices is "
4210 "currently being resilvered. The pool will\n\tcontinue "
4211 "to function, possibly in a degraded state.\n"));
4212 (void) printf(gettext("action: Wait for the resilver to "
4216 case ZPOOL_STATUS_CORRUPT_DATA
:
4217 (void) printf(gettext("status: One or more devices has "
4218 "experienced an error resulting in data\n\tcorruption. "
4219 "Applications may be affected.\n"));
4220 (void) printf(gettext("action: Restore the file in question "
4221 "if possible. Otherwise restore the\n\tentire pool from "
4225 case ZPOOL_STATUS_CORRUPT_POOL
:
4226 (void) printf(gettext("status: The pool metadata is corrupted "
4227 "and the pool cannot be opened.\n"));
4228 zpool_explain_recover(zpool_get_handle(zhp
),
4229 zpool_get_name(zhp
), reason
, config
);
4232 case ZPOOL_STATUS_VERSION_OLDER
:
4233 (void) printf(gettext("status: The pool is formatted using a "
4234 "legacy on-disk format. The pool can\n\tstill be used, "
4235 "but some features are unavailable.\n"));
4236 (void) printf(gettext("action: Upgrade the pool using 'zpool "
4237 "upgrade'. Once this is done, the\n\tpool will no longer "
4238 "be accessible on software that does not support\n\t"
4239 "feature flags.\n"));
4242 case ZPOOL_STATUS_VERSION_NEWER
:
4243 (void) printf(gettext("status: The pool has been upgraded to a "
4244 "newer, incompatible on-disk version.\n\tThe pool cannot "
4245 "be accessed on this system.\n"));
4246 (void) printf(gettext("action: Access the pool from a system "
4247 "running more recent software, or\n\trestore the pool from "
4251 case ZPOOL_STATUS_FEAT_DISABLED
:
4252 (void) printf(gettext("status: Some supported features are not "
4253 "enabled on the pool. The pool can\n\tstill be used, but "
4254 "some features are unavailable.\n"));
4255 (void) printf(gettext("action: Enable all features using "
4256 "'zpool upgrade'. Once this is done,\n\tthe pool may no "
4257 "longer be accessible by software that does not support\n\t"
4258 "the features. See zpool-features(5) for details.\n"));
4261 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
4262 (void) printf(gettext("status: The pool cannot be accessed on "
4263 "this system because it uses the\n\tfollowing feature(s) "
4264 "not supported on this system:\n"));
4265 zpool_print_unsup_feat(config
);
4266 (void) printf("\n");
4267 (void) printf(gettext("action: Access the pool from a system "
4268 "that supports the required feature(s),\n\tor restore the "
4269 "pool from backup.\n"));
4272 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
4273 (void) printf(gettext("status: The pool can only be accessed "
4274 "in read-only mode on this system. It\n\tcannot be "
4275 "accessed in read-write mode because it uses the "
4276 "following\n\tfeature(s) not supported on this system:\n"));
4277 zpool_print_unsup_feat(config
);
4278 (void) printf("\n");
4279 (void) printf(gettext("action: The pool cannot be accessed in "
4280 "read-write mode. Import the pool with\n"
4281 "\t\"-o readonly=on\", access the pool from a system that "
4282 "supports the\n\trequired feature(s), or restore the "
4283 "pool from backup.\n"));
4286 case ZPOOL_STATUS_FAULTED_DEV_R
:
4287 (void) printf(gettext("status: One or more devices are "
4288 "faulted in response to persistent errors.\n\tSufficient "
4289 "replicas exist for the pool to continue functioning "
4290 "in a\n\tdegraded state.\n"));
4291 (void) printf(gettext("action: Replace the faulted device, "
4292 "or use 'zpool clear' to mark the device\n\trepaired.\n"));
4295 case ZPOOL_STATUS_FAULTED_DEV_NR
:
4296 (void) printf(gettext("status: One or more devices are "
4297 "faulted in response to persistent errors. There are "
4298 "insufficient replicas for the pool to\n\tcontinue "
4300 (void) printf(gettext("action: Destroy and re-create the pool "
4301 "from a backup source. Manually marking the device\n"
4302 "\trepaired using 'zpool clear' may allow some data "
4303 "to be recovered.\n"));
4306 case ZPOOL_STATUS_IO_FAILURE_WAIT
:
4307 case ZPOOL_STATUS_IO_FAILURE_CONTINUE
:
4308 (void) printf(gettext("status: One or more devices are "
4309 "faulted in response to IO failures.\n"));
4310 (void) printf(gettext("action: Make sure the affected devices "
4311 "are connected, then run 'zpool clear'.\n"));
4314 case ZPOOL_STATUS_BAD_LOG
:
4315 (void) printf(gettext("status: An intent log record "
4316 "could not be read.\n"
4317 "\tWaiting for adminstrator intervention to fix the "
4318 "faulted pool.\n"));
4319 (void) printf(gettext("action: Either restore the affected "
4320 "device(s) and run 'zpool online',\n"
4321 "\tor ignore the intent log records by running "
4322 "'zpool clear'.\n"));
4327 * The remaining errors can't actually be generated, yet.
4329 assert(reason
== ZPOOL_STATUS_OK
);
4333 (void) printf(gettext(" see: http://zfsonlinux.org/msg/%s\n"),
4336 if (config
!= NULL
) {
4339 nvlist_t
**spares
, **l2cache
;
4340 uint_t nspares
, nl2cache
;
4341 pool_scan_stat_t
*ps
= NULL
;
4343 (void) nvlist_lookup_uint64_array(nvroot
,
4344 ZPOOL_CONFIG_SCAN_STATS
, (uint64_t **)&ps
, &c
);
4345 print_scan_status(ps
);
4347 namewidth
= max_width(zhp
, nvroot
, 0, 0);
4351 (void) printf(gettext("config:\n\n"));
4352 (void) printf(gettext("\t%-*s %-8s %5s %5s %5s\n"), namewidth
,
4353 "NAME", "STATE", "READ", "WRITE", "CKSUM");
4354 print_status_config(zhp
, zpool_get_name(zhp
), nvroot
,
4355 namewidth
, 0, B_FALSE
);
4357 if (num_logs(nvroot
) > 0)
4358 print_logs(zhp
, nvroot
, namewidth
, B_TRUE
);
4359 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_L2CACHE
,
4360 &l2cache
, &nl2cache
) == 0)
4361 print_l2cache(zhp
, l2cache
, nl2cache
, namewidth
);
4363 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_SPARES
,
4364 &spares
, &nspares
) == 0)
4365 print_spares(zhp
, spares
, nspares
, namewidth
);
4367 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_ERRCOUNT
,
4369 nvlist_t
*nverrlist
= NULL
;
4372 * If the approximate error count is small, get a
4373 * precise count by fetching the entire log and
4374 * uniquifying the results.
4376 if (nerr
> 0 && nerr
< 100 && !cbp
->cb_verbose
&&
4377 zpool_get_errlog(zhp
, &nverrlist
) == 0) {
4382 while ((elem
= nvlist_next_nvpair(nverrlist
,
4387 nvlist_free(nverrlist
);
4389 (void) printf("\n");
4392 (void) printf(gettext("errors: No known data "
4394 else if (!cbp
->cb_verbose
)
4395 (void) printf(gettext("errors: %llu data "
4396 "errors, use '-v' for a list\n"),
4397 (u_longlong_t
)nerr
);
4399 print_error_log(zhp
);
4402 if (cbp
->cb_dedup_stats
)
4403 print_dedup_stats(config
);
4405 (void) printf(gettext("config: The configuration cannot be "
4413 * zpool status [-vx] [-T d|u] [pool] ... [interval [count]]
4415 * -v Display complete error logs
4416 * -x Display only pools with potential problems
4417 * -D Display dedup status (undocumented)
4418 * -T Display a timestamp in date(1) or Unix format
4420 * Describes the health status of all pools or some subset.
4423 zpool_do_status(int argc
, char **argv
)
4427 unsigned long interval
= 0, count
= 0;
4428 status_cbdata_t cb
= { 0 };
4431 while ((c
= getopt(argc
, argv
, "vxDT:")) != -1) {
4434 cb
.cb_verbose
= B_TRUE
;
4437 cb
.cb_explain
= B_TRUE
;
4440 cb
.cb_dedup_stats
= B_TRUE
;
4443 get_timestamp_arg(*optarg
);
4446 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4455 get_interval_count(&argc
, argv
, &interval
, &count
);
4458 cb
.cb_allpools
= B_TRUE
;
4460 cb
.cb_first
= B_TRUE
;
4463 if (timestamp_fmt
!= NODATE
)
4464 print_timestamp(timestamp_fmt
);
4466 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
,
4467 status_callback
, &cb
);
4469 if (argc
== 0 && cb
.cb_count
== 0)
4470 (void) fprintf(stderr
, gettext("no pools available\n"));
4471 else if (cb
.cb_explain
&& cb
.cb_first
&& cb
.cb_allpools
)
4472 (void) printf(gettext("all pools are healthy\n"));
4480 if (count
!= 0 && --count
== 0)
4483 (void) sleep(interval
);
4489 typedef struct upgrade_cbdata
{
4492 uint64_t cb_version
;
4497 upgrade_version(zpool_handle_t
*zhp
, uint64_t version
)
4501 uint64_t oldversion
;
4503 config
= zpool_get_config(zhp
, NULL
);
4504 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
4507 assert(SPA_VERSION_IS_SUPPORTED(oldversion
));
4508 assert(oldversion
< version
);
4510 ret
= zpool_upgrade(zhp
, version
);
4514 if (version
>= SPA_VERSION_FEATURES
) {
4515 (void) printf(gettext("Successfully upgraded "
4516 "'%s' from version %llu to feature flags.\n"),
4517 zpool_get_name(zhp
), (u_longlong_t
) oldversion
);
4519 (void) printf(gettext("Successfully upgraded "
4520 "'%s' from version %llu to version %llu.\n"),
4521 zpool_get_name(zhp
), (u_longlong_t
) oldversion
,
4522 (u_longlong_t
) version
);
4529 upgrade_enable_all(zpool_handle_t
*zhp
, int *countp
)
4532 boolean_t firstff
= B_TRUE
;
4533 nvlist_t
*enabled
= zpool_get_features(zhp
);
4536 for (i
= 0; i
< SPA_FEATURES
; i
++) {
4537 const char *fname
= spa_feature_table
[i
].fi_uname
;
4538 const char *fguid
= spa_feature_table
[i
].fi_guid
;
4539 if (!nvlist_exists(enabled
, fguid
)) {
4541 verify(-1 != asprintf(&propname
, "feature@%s", fname
));
4542 ret
= zpool_set_prop(zhp
, propname
,
4543 ZFS_FEATURE_ENABLED
);
4551 (void) printf(gettext("Enabled the "
4552 "following features on '%s':\n"),
4553 zpool_get_name(zhp
));
4556 (void) printf(gettext(" %s\n"), fname
);
4567 upgrade_cb(zpool_handle_t
*zhp
, void *arg
)
4569 upgrade_cbdata_t
*cbp
= arg
;
4572 boolean_t printnl
= B_FALSE
;
4575 config
= zpool_get_config(zhp
, NULL
);
4576 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
4579 assert(SPA_VERSION_IS_SUPPORTED(version
));
4581 if (version
< cbp
->cb_version
) {
4582 cbp
->cb_first
= B_FALSE
;
4583 ret
= upgrade_version(zhp
, cbp
->cb_version
);
4590 * XXX: This code can be enabled when Illumos commit
4591 * 4445fffbbb1ea25fd0e9ea68b9380dd7a6709025 is merged.
4592 * It reworks the history logging among other things.
4596 * If they did "zpool upgrade -a", then we could
4597 * be doing ioctls to different pools. We need
4598 * to log this history once to each pool, and bypass
4599 * the normal history logging that happens in main().
4601 (void) zpool_log_history(g_zfs
, history_str
);
4602 log_history
= B_FALSE
;
4606 if (cbp
->cb_version
>= SPA_VERSION_FEATURES
) {
4608 ret
= upgrade_enable_all(zhp
, &count
);
4613 cbp
->cb_first
= B_FALSE
;
4619 (void) printf(gettext("\n"));
4626 upgrade_list_older_cb(zpool_handle_t
*zhp
, void *arg
)
4628 upgrade_cbdata_t
*cbp
= arg
;
4632 config
= zpool_get_config(zhp
, NULL
);
4633 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
4636 assert(SPA_VERSION_IS_SUPPORTED(version
));
4638 if (version
< SPA_VERSION_FEATURES
) {
4639 if (cbp
->cb_first
) {
4640 (void) printf(gettext("The following pools are "
4641 "formatted with legacy version numbers and can\n"
4642 "be upgraded to use feature flags. After "
4643 "being upgraded, these pools\nwill no "
4644 "longer be accessible by software that does not "
4645 "support feature\nflags.\n\n"));
4646 (void) printf(gettext("VER POOL\n"));
4647 (void) printf(gettext("--- ------------\n"));
4648 cbp
->cb_first
= B_FALSE
;
4651 (void) printf("%2llu %s\n", (u_longlong_t
)version
,
4652 zpool_get_name(zhp
));
4659 upgrade_list_disabled_cb(zpool_handle_t
*zhp
, void *arg
)
4661 upgrade_cbdata_t
*cbp
= arg
;
4665 config
= zpool_get_config(zhp
, NULL
);
4666 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
4669 if (version
>= SPA_VERSION_FEATURES
) {
4671 boolean_t poolfirst
= B_TRUE
;
4672 nvlist_t
*enabled
= zpool_get_features(zhp
);
4674 for (i
= 0; i
< SPA_FEATURES
; i
++) {
4675 const char *fguid
= spa_feature_table
[i
].fi_guid
;
4676 const char *fname
= spa_feature_table
[i
].fi_uname
;
4677 if (!nvlist_exists(enabled
, fguid
)) {
4678 if (cbp
->cb_first
) {
4679 (void) printf(gettext("\nSome "
4680 "supported features are not "
4681 "enabled on the following pools. "
4682 "Once a\nfeature is enabled the "
4683 "pool may become incompatible with "
4684 "software\nthat does not support "
4686 "zpool-features(5) for "
4688 (void) printf(gettext("POOL "
4690 (void) printf(gettext("------"
4692 cbp
->cb_first
= B_FALSE
;
4696 (void) printf(gettext("%s\n"),
4697 zpool_get_name(zhp
));
4698 poolfirst
= B_FALSE
;
4701 (void) printf(gettext(" %s\n"), fname
);
4711 upgrade_one(zpool_handle_t
*zhp
, void *data
)
4713 boolean_t printnl
= B_FALSE
;
4714 upgrade_cbdata_t
*cbp
= data
;
4715 uint64_t cur_version
;
4718 if (strcmp("log", zpool_get_name(zhp
)) == 0) {
4719 (void) printf(gettext("'log' is now a reserved word\n"
4720 "Pool 'log' must be renamed using export and import"
4725 cur_version
= zpool_get_prop_int(zhp
, ZPOOL_PROP_VERSION
, NULL
);
4726 if (cur_version
> cbp
->cb_version
) {
4727 (void) printf(gettext("Pool '%s' is already formatted "
4728 "using more current version '%llu'.\n\n"),
4729 zpool_get_name(zhp
), (u_longlong_t
) cur_version
);
4733 if (cbp
->cb_version
!= SPA_VERSION
&& cur_version
== cbp
->cb_version
) {
4734 (void) printf(gettext("Pool '%s' is already formatted "
4735 "using version %llu.\n\n"), zpool_get_name(zhp
),
4736 (u_longlong_t
) cbp
->cb_version
);
4740 if (cur_version
!= cbp
->cb_version
) {
4742 ret
= upgrade_version(zhp
, cbp
->cb_version
);
4747 if (cbp
->cb_version
>= SPA_VERSION_FEATURES
) {
4749 ret
= upgrade_enable_all(zhp
, &count
);
4755 } else if (cur_version
== SPA_VERSION
) {
4756 (void) printf(gettext("Pool '%s' already has all "
4757 "supported features enabled.\n"),
4758 zpool_get_name(zhp
));
4763 (void) printf(gettext("\n"));
4772 * zpool upgrade [-V version] <-a | pool ...>
4774 * With no arguments, display downrev'd ZFS pool available for upgrade.
4775 * Individual pools can be upgraded by specifying the pool, and '-a' will
4776 * upgrade all pools.
4779 zpool_do_upgrade(int argc
, char **argv
)
4782 upgrade_cbdata_t cb
= { 0 };
4784 boolean_t showversions
= B_FALSE
;
4785 boolean_t upgradeall
= B_FALSE
;
4790 while ((c
= getopt(argc
, argv
, ":avV:")) != -1) {
4793 upgradeall
= B_TRUE
;
4796 showversions
= B_TRUE
;
4799 cb
.cb_version
= strtoll(optarg
, &end
, 10);
4801 !SPA_VERSION_IS_SUPPORTED(cb
.cb_version
)) {
4802 (void) fprintf(stderr
,
4803 gettext("invalid version '%s'\n"), optarg
);
4808 (void) fprintf(stderr
, gettext("missing argument for "
4809 "'%c' option\n"), optopt
);
4813 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4824 if (cb
.cb_version
== 0) {
4825 cb
.cb_version
= SPA_VERSION
;
4826 } else if (!upgradeall
&& argc
== 0) {
4827 (void) fprintf(stderr
, gettext("-V option is "
4828 "incompatible with other arguments\n"));
4833 if (upgradeall
|| argc
!= 0) {
4834 (void) fprintf(stderr
, gettext("-v option is "
4835 "incompatible with other arguments\n"));
4838 } else if (upgradeall
) {
4840 (void) fprintf(stderr
, gettext("-a option should not "
4841 "be used along with a pool name\n"));
4846 (void) printf(gettext("This system supports ZFS pool feature "
4851 (void) printf(gettext("The following features are "
4853 (void) printf(gettext("FEAT DESCRIPTION\n"));
4854 (void) printf("----------------------------------------------"
4855 "---------------\n");
4856 for (i
= 0; i
< SPA_FEATURES
; i
++) {
4857 zfeature_info_t
*fi
= &spa_feature_table
[i
];
4858 const char *ro
= fi
->fi_can_readonly
?
4859 " (read-only compatible)" : "";
4861 (void) printf("%-37s%s\n", fi
->fi_uname
, ro
);
4862 (void) printf(" %s\n", fi
->fi_desc
);
4864 (void) printf("\n");
4866 (void) printf(gettext("The following legacy versions are also "
4868 (void) printf(gettext("VER DESCRIPTION\n"));
4869 (void) printf("--- -----------------------------------------"
4870 "---------------\n");
4871 (void) printf(gettext(" 1 Initial ZFS version\n"));
4872 (void) printf(gettext(" 2 Ditto blocks "
4873 "(replicated metadata)\n"));
4874 (void) printf(gettext(" 3 Hot spares and double parity "
4876 (void) printf(gettext(" 4 zpool history\n"));
4877 (void) printf(gettext(" 5 Compression using the gzip "
4879 (void) printf(gettext(" 6 bootfs pool property\n"));
4880 (void) printf(gettext(" 7 Separate intent log devices\n"));
4881 (void) printf(gettext(" 8 Delegated administration\n"));
4882 (void) printf(gettext(" 9 refquota and refreservation "
4884 (void) printf(gettext(" 10 Cache devices\n"));
4885 (void) printf(gettext(" 11 Improved scrub performance\n"));
4886 (void) printf(gettext(" 12 Snapshot properties\n"));
4887 (void) printf(gettext(" 13 snapused property\n"));
4888 (void) printf(gettext(" 14 passthrough-x aclinherit\n"));
4889 (void) printf(gettext(" 15 user/group space accounting\n"));
4890 (void) printf(gettext(" 16 stmf property support\n"));
4891 (void) printf(gettext(" 17 Triple-parity RAID-Z\n"));
4892 (void) printf(gettext(" 18 Snapshot user holds\n"));
4893 (void) printf(gettext(" 19 Log device removal\n"));
4894 (void) printf(gettext(" 20 Compression using zle "
4895 "(zero-length encoding)\n"));
4896 (void) printf(gettext(" 21 Deduplication\n"));
4897 (void) printf(gettext(" 22 Received properties\n"));
4898 (void) printf(gettext(" 23 Slim ZIL\n"));
4899 (void) printf(gettext(" 24 System attributes\n"));
4900 (void) printf(gettext(" 25 Improved scrub stats\n"));
4901 (void) printf(gettext(" 26 Improved snapshot deletion "
4903 (void) printf(gettext(" 27 Improved snapshot creation "
4905 (void) printf(gettext(" 28 Multiple vdev replacements\n"));
4906 (void) printf(gettext("\nFor more information on a particular "
4907 "version, including supported releases,\n"));
4908 (void) printf(gettext("see the ZFS Administration Guide.\n\n"));
4909 } else if (argc
== 0 && upgradeall
) {
4910 cb
.cb_first
= B_TRUE
;
4911 ret
= zpool_iter(g_zfs
, upgrade_cb
, &cb
);
4912 if (ret
== 0 && cb
.cb_first
) {
4913 if (cb
.cb_version
== SPA_VERSION
) {
4914 (void) printf(gettext("All pools are already "
4915 "formatted using feature flags.\n\n"));
4916 (void) printf(gettext("Every feature flags "
4917 "pool already has all supported features "
4920 (void) printf(gettext("All pools are already "
4921 "formatted with version %llu or higher.\n"),
4922 (u_longlong_t
) cb
.cb_version
);
4925 } else if (argc
== 0) {
4926 cb
.cb_first
= B_TRUE
;
4927 ret
= zpool_iter(g_zfs
, upgrade_list_older_cb
, &cb
);
4931 (void) printf(gettext("All pools are formatted "
4932 "using feature flags.\n\n"));
4934 (void) printf(gettext("\nUse 'zpool upgrade -v' "
4935 "for a list of available legacy versions.\n"));
4938 cb
.cb_first
= B_TRUE
;
4939 ret
= zpool_iter(g_zfs
, upgrade_list_disabled_cb
, &cb
);
4943 (void) printf(gettext("Every feature flags pool has "
4944 "all supported features enabled.\n"));
4946 (void) printf(gettext("\n"));
4949 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
,
4956 typedef struct hist_cbdata
{
4963 * Print out the command history for a specific pool.
4966 get_history_one(zpool_handle_t
*zhp
, void *data
)
4982 char internalstr
[MAXPATHLEN
];
4983 hist_cbdata_t
*cb
= (hist_cbdata_t
*)data
;
4987 cb
->first
= B_FALSE
;
4989 (void) printf(gettext("History for '%s':\n"), zpool_get_name(zhp
));
4991 if ((ret
= zpool_get_history(zhp
, &nvhis
)) != 0)
4994 verify(nvlist_lookup_nvlist_array(nvhis
, ZPOOL_HIST_RECORD
,
4995 &records
, &numrecords
) == 0);
4996 for (i
= 0; i
< numrecords
; i
++) {
4997 if (nvlist_lookup_uint64(records
[i
], ZPOOL_HIST_TIME
,
5001 /* is it an internal event or a standard event? */
5002 if (nvlist_lookup_string(records
[i
], ZPOOL_HIST_CMD
,
5004 if (cb
->internal
== 0)
5007 if (nvlist_lookup_uint64(records
[i
],
5008 ZPOOL_HIST_INT_EVENT
, &ievent
) != 0)
5010 verify(nvlist_lookup_uint64(records
[i
],
5011 ZPOOL_HIST_TXG
, &txg
) == 0);
5012 verify(nvlist_lookup_string(records
[i
],
5013 ZPOOL_HIST_INT_STR
, &pathstr
) == 0);
5014 if (ievent
>= LOG_END
)
5016 (void) snprintf(internalstr
,
5017 sizeof (internalstr
),
5018 "[internal %s txg:%llu] %s",
5019 zfs_history_event_names
[ievent
], (u_longlong_t
)txg
,
5021 cmdstr
= internalstr
;
5024 (void) localtime_r(&tsec
, &t
);
5025 (void) strftime(tbuf
, sizeof (tbuf
), "%F.%T", &t
);
5026 (void) printf("%s %s", tbuf
, cmdstr
);
5029 (void) printf("\n");
5032 (void) printf(" [");
5033 if (nvlist_lookup_uint64(records
[i
],
5034 ZPOOL_HIST_WHO
, &who
) == 0) {
5035 pwd
= getpwuid((uid_t
)who
);
5037 (void) printf("user %s on",
5040 (void) printf("user %d on",
5043 (void) printf(gettext("no info]\n"));
5046 if (nvlist_lookup_string(records
[i
],
5047 ZPOOL_HIST_HOST
, &hostname
) == 0) {
5048 (void) printf(" %s", hostname
);
5050 if (nvlist_lookup_string(records
[i
],
5051 ZPOOL_HIST_ZONE
, &zonename
) == 0) {
5052 (void) printf(":%s", zonename
);
5056 (void) printf("\n");
5058 (void) printf("\n");
5065 * zpool history <pool>
5067 * Displays the history of commands that modified pools.
5072 zpool_do_history(int argc
, char **argv
)
5074 hist_cbdata_t cbdata
= { 0 };
5078 cbdata
.first
= B_TRUE
;
5080 while ((c
= getopt(argc
, argv
, "li")) != -1) {
5086 cbdata
.internal
= 1;
5089 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5097 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
, get_history_one
,
5100 if (argc
== 0 && cbdata
.first
== B_TRUE
) {
5101 (void) fprintf(stderr
, gettext("no pools available\n"));
5108 typedef struct ev_opts
{
5116 zpool_do_events_short(nvlist_t
*nvl
)
5118 char ctime_str
[26], str
[32], *ptr
;
5122 verify(nvlist_lookup_int64_array(nvl
, FM_EREPORT_TIME
, &tv
, &n
) == 0);
5123 memset(str
, ' ', 32);
5124 (void) ctime_r((const time_t *)&tv
[0], ctime_str
);
5125 (void) strncpy(str
, ctime_str
+4, 6); /* 'Jun 30' */
5126 (void) strncpy(str
+7, ctime_str
+20, 4); /* '1993' */
5127 (void) strncpy(str
+12, ctime_str
+11, 8); /* '21:49:08' */
5128 (void) sprintf(str
+20, ".%09lld", (longlong_t
)tv
[1]);/* '.123456789' */
5129 (void) printf(gettext("%s "), str
);
5131 verify(nvlist_lookup_string(nvl
, FM_CLASS
, &ptr
) == 0);
5132 (void) printf(gettext("%s\n"), ptr
);
5136 zpool_do_events_nvprint(nvlist_t
*nvl
, int depth
)
5140 for (nvp
= nvlist_next_nvpair(nvl
, NULL
);
5141 nvp
!= NULL
; nvp
= nvlist_next_nvpair(nvl
, nvp
)) {
5143 data_type_t type
= nvpair_type(nvp
);
5144 const char *name
= nvpair_name(nvp
);
5154 printf(gettext("%*s%s = "), depth
, "", name
);
5157 case DATA_TYPE_BOOLEAN
:
5158 printf(gettext("%s"), "1");
5161 case DATA_TYPE_BOOLEAN_VALUE
:
5162 (void) nvpair_value_boolean_value(nvp
, &b
);
5163 printf(gettext("%s"), b
? "1" : "0");
5166 case DATA_TYPE_BYTE
:
5167 (void) nvpair_value_byte(nvp
, &i8
);
5168 printf(gettext("0x%x"), i8
);
5171 case DATA_TYPE_INT8
:
5172 (void) nvpair_value_int8(nvp
, (void *)&i8
);
5173 printf(gettext("0x%x"), i8
);
5176 case DATA_TYPE_UINT8
:
5177 (void) nvpair_value_uint8(nvp
, &i8
);
5178 printf(gettext("0x%x"), i8
);
5181 case DATA_TYPE_INT16
:
5182 (void) nvpair_value_int16(nvp
, (void *)&i16
);
5183 printf(gettext("0x%x"), i16
);
5186 case DATA_TYPE_UINT16
:
5187 (void) nvpair_value_uint16(nvp
, &i16
);
5188 printf(gettext("0x%x"), i16
);
5191 case DATA_TYPE_INT32
:
5192 (void) nvpair_value_int32(nvp
, (void *)&i32
);
5193 printf(gettext("0x%x"), i32
);
5196 case DATA_TYPE_UINT32
:
5197 (void) nvpair_value_uint32(nvp
, &i32
);
5198 printf(gettext("0x%x"), i32
);
5201 case DATA_TYPE_INT64
:
5202 (void) nvpair_value_int64(nvp
, (void *)&i64
);
5203 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
5206 case DATA_TYPE_UINT64
:
5207 (void) nvpair_value_uint64(nvp
, &i64
);
5208 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
5211 case DATA_TYPE_HRTIME
:
5212 (void) nvpair_value_hrtime(nvp
, (void *)&i64
);
5213 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
5216 case DATA_TYPE_STRING
:
5217 (void) nvpair_value_string(nvp
, &str
);
5218 printf(gettext("\"%s\""), str
? str
: "<NULL>");
5221 case DATA_TYPE_NVLIST
:
5222 printf(gettext("(embedded nvlist)\n"));
5223 (void) nvpair_value_nvlist(nvp
, &cnv
);
5224 zpool_do_events_nvprint(cnv
, depth
+ 8);
5225 printf(gettext("%*s(end %s)"), depth
, "", name
);
5228 case DATA_TYPE_NVLIST_ARRAY
: {
5232 (void) nvpair_value_nvlist_array(nvp
, &val
, &nelem
);
5233 printf(gettext("(%d embedded nvlists)\n"), nelem
);
5234 for (i
= 0; i
< nelem
; i
++) {
5235 printf(gettext("%*s%s[%d] = %s\n"),
5236 depth
, "", name
, i
, "(embedded nvlist)");
5237 zpool_do_events_nvprint(val
[i
], depth
+ 8);
5238 printf(gettext("%*s(end %s[%i])\n"),
5239 depth
, "", name
, i
);
5241 printf(gettext("%*s(end %s)\n"), depth
, "", name
);
5245 case DATA_TYPE_INT8_ARRAY
: {
5249 (void) nvpair_value_int8_array(nvp
, &val
, &nelem
);
5250 for (i
= 0; i
< nelem
; i
++)
5251 printf(gettext("0x%x "), val
[i
]);
5256 case DATA_TYPE_UINT8_ARRAY
: {
5260 (void) nvpair_value_uint8_array(nvp
, &val
, &nelem
);
5261 for (i
= 0; i
< nelem
; i
++)
5262 printf(gettext("0x%x "), val
[i
]);
5267 case DATA_TYPE_INT16_ARRAY
: {
5271 (void) nvpair_value_int16_array(nvp
, &val
, &nelem
);
5272 for (i
= 0; i
< nelem
; i
++)
5273 printf(gettext("0x%x "), val
[i
]);
5278 case DATA_TYPE_UINT16_ARRAY
: {
5282 (void) nvpair_value_uint16_array(nvp
, &val
, &nelem
);
5283 for (i
= 0; i
< nelem
; i
++)
5284 printf(gettext("0x%x "), val
[i
]);
5289 case DATA_TYPE_INT32_ARRAY
: {
5293 (void) nvpair_value_int32_array(nvp
, &val
, &nelem
);
5294 for (i
= 0; i
< nelem
; i
++)
5295 printf(gettext("0x%x "), val
[i
]);
5300 case DATA_TYPE_UINT32_ARRAY
: {
5304 (void) nvpair_value_uint32_array(nvp
, &val
, &nelem
);
5305 for (i
= 0; i
< nelem
; i
++)
5306 printf(gettext("0x%x "), val
[i
]);
5311 case DATA_TYPE_INT64_ARRAY
: {
5315 (void) nvpair_value_int64_array(nvp
, &val
, &nelem
);
5316 for (i
= 0; i
< nelem
; i
++)
5317 printf(gettext("0x%llx "), (u_longlong_t
)val
[i
]);
5322 case DATA_TYPE_UINT64_ARRAY
: {
5326 (void) nvpair_value_uint64_array(nvp
, &val
, &nelem
);
5327 for (i
= 0; i
< nelem
; i
++)
5328 printf(gettext("0x%llx "), (u_longlong_t
)val
[i
]);
5333 case DATA_TYPE_STRING_ARRAY
:
5334 case DATA_TYPE_BOOLEAN_ARRAY
:
5335 case DATA_TYPE_BYTE_ARRAY
:
5336 case DATA_TYPE_DOUBLE
:
5337 case DATA_TYPE_UNKNOWN
:
5338 printf(gettext("<unknown>"));
5342 printf(gettext("\n"));
5347 zpool_do_events_next(ev_opts_t
*opts
)
5350 int cleanup_fd
, ret
, dropped
;
5352 cleanup_fd
= open(ZFS_DEV
, O_RDWR
);
5353 VERIFY(cleanup_fd
>= 0);
5355 if (!opts
->scripted
)
5356 (void) printf(gettext("%-30s %s\n"), "TIME", "CLASS");
5359 ret
= zpool_events_next(g_zfs
, &nvl
, &dropped
,
5360 !!opts
->follow
, cleanup_fd
);
5361 if (ret
|| nvl
== NULL
)
5365 (void) printf(gettext("dropped %d events\n"), dropped
);
5367 zpool_do_events_short(nvl
);
5369 if (opts
->verbose
) {
5370 zpool_do_events_nvprint(nvl
, 8);
5371 printf(gettext("\n"));
5373 (void) fflush(stdout
);
5378 VERIFY(0 == close(cleanup_fd
));
5384 zpool_do_events_clear(ev_opts_t
*opts
)
5388 ret
= zpool_events_clear(g_zfs
, &count
);
5390 (void) printf(gettext("cleared %d events\n"), count
);
5396 * zpool events [-vfc]
5398 * Displays events logs by ZFS.
5401 zpool_do_events(int argc
, char **argv
)
5403 ev_opts_t opts
= { 0 };
5408 while ((c
= getopt(argc
, argv
, "vHfc")) != -1) {
5423 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5432 ret
= zpool_do_events_clear(&opts
);
5434 ret
= zpool_do_events_next(&opts
);
5440 get_callback(zpool_handle_t
*zhp
, void *data
)
5442 zprop_get_cbdata_t
*cbp
= (zprop_get_cbdata_t
*)data
;
5443 char value
[MAXNAMELEN
];
5444 zprop_source_t srctype
;
5447 for (pl
= cbp
->cb_proplist
; pl
!= NULL
; pl
= pl
->pl_next
) {
5450 * Skip the special fake placeholder. This will also skip
5451 * over the name property when 'all' is specified.
5453 if (pl
->pl_prop
== ZPOOL_PROP_NAME
&&
5454 pl
== cbp
->cb_proplist
)
5457 if (pl
->pl_prop
== ZPROP_INVAL
&&
5458 (zpool_prop_feature(pl
->pl_user_prop
) ||
5459 zpool_prop_unsupported(pl
->pl_user_prop
))) {
5460 srctype
= ZPROP_SRC_LOCAL
;
5462 if (zpool_prop_get_feature(zhp
, pl
->pl_user_prop
,
5463 value
, sizeof (value
)) == 0) {
5464 zprop_print_one_property(zpool_get_name(zhp
),
5465 cbp
, pl
->pl_user_prop
, value
, srctype
,
5469 if (zpool_get_prop(zhp
, pl
->pl_prop
, value
,
5470 sizeof (value
), &srctype
) != 0)
5473 zprop_print_one_property(zpool_get_name(zhp
), cbp
,
5474 zpool_prop_to_name(pl
->pl_prop
), value
, srctype
,
5482 zpool_do_get(int argc
, char **argv
)
5484 zprop_get_cbdata_t cb
= { 0 };
5485 zprop_list_t fake_name
= { 0 };
5489 (void) fprintf(stderr
, gettext("missing property "
5494 cb
.cb_first
= B_TRUE
;
5495 cb
.cb_sources
= ZPROP_SRC_ALL
;
5496 cb
.cb_columns
[0] = GET_COL_NAME
;
5497 cb
.cb_columns
[1] = GET_COL_PROPERTY
;
5498 cb
.cb_columns
[2] = GET_COL_VALUE
;
5499 cb
.cb_columns
[3] = GET_COL_SOURCE
;
5500 cb
.cb_type
= ZFS_TYPE_POOL
;
5502 if (zprop_get_list(g_zfs
, argv
[1], &cb
.cb_proplist
,
5503 ZFS_TYPE_POOL
) != 0)
5506 if (cb
.cb_proplist
!= NULL
) {
5507 fake_name
.pl_prop
= ZPOOL_PROP_NAME
;
5508 fake_name
.pl_width
= strlen(gettext("NAME"));
5509 fake_name
.pl_next
= cb
.cb_proplist
;
5510 cb
.cb_proplist
= &fake_name
;
5513 ret
= for_each_pool(argc
- 2, argv
+ 2, B_TRUE
, &cb
.cb_proplist
,
5516 if (cb
.cb_proplist
== &fake_name
)
5517 zprop_free_list(fake_name
.pl_next
);
5519 zprop_free_list(cb
.cb_proplist
);
5524 typedef struct set_cbdata
{
5527 boolean_t cb_any_successful
;
5531 set_callback(zpool_handle_t
*zhp
, void *data
)
5534 set_cbdata_t
*cb
= (set_cbdata_t
*)data
;
5536 error
= zpool_set_prop(zhp
, cb
->cb_propname
, cb
->cb_value
);
5539 cb
->cb_any_successful
= B_TRUE
;
5545 zpool_do_set(int argc
, char **argv
)
5547 set_cbdata_t cb
= { 0 };
5550 if (argc
> 1 && argv
[1][0] == '-') {
5551 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5557 (void) fprintf(stderr
, gettext("missing property=value "
5563 (void) fprintf(stderr
, gettext("missing pool name\n"));
5568 (void) fprintf(stderr
, gettext("too many pool names\n"));
5572 cb
.cb_propname
= argv
[1];
5573 cb
.cb_value
= strchr(cb
.cb_propname
, '=');
5574 if (cb
.cb_value
== NULL
) {
5575 (void) fprintf(stderr
, gettext("missing value in "
5576 "property=value argument\n"));
5580 *(cb
.cb_value
) = '\0';
5583 error
= for_each_pool(argc
- 2, argv
+ 2, B_TRUE
, NULL
,
5590 find_command_idx(char *command
, int *idx
)
5594 for (i
= 0; i
< NCOMMAND
; i
++) {
5595 if (command_table
[i
].name
== NULL
)
5598 if (strcmp(command
, command_table
[i
].name
) == 0) {
5607 main(int argc
, char **argv
)
5613 (void) setlocale(LC_ALL
, "");
5614 (void) textdomain(TEXT_DOMAIN
);
5619 * Make sure the user has specified some command.
5622 (void) fprintf(stderr
, gettext("missing command\n"));
5631 if ((strcmp(cmdname
, "-?") == 0) ||
5632 strcmp(cmdname
, "--help") == 0)
5635 if ((g_zfs
= libzfs_init()) == NULL
)
5638 libzfs_print_on_error(g_zfs
, B_TRUE
);
5640 zpool_set_history_str("zpool", argc
, argv
, history_str
);
5641 verify(zpool_stage_history(g_zfs
, history_str
) == 0);
5644 * Run the appropriate command.
5646 if (find_command_idx(cmdname
, &i
) == 0) {
5647 current_command
= &command_table
[i
];
5648 ret
= command_table
[i
].func(argc
- 1, argv
+ 1);
5649 } else if (strchr(cmdname
, '=')) {
5650 verify(find_command_idx("set", &i
) == 0);
5651 current_command
= &command_table
[i
];
5652 ret
= command_table
[i
].func(argc
, argv
);
5653 } else if (strcmp(cmdname
, "freeze") == 0 && argc
== 3) {
5655 * 'freeze' is a vile debugging abomination, so we treat
5659 int fd
= open(ZFS_DEV
, O_RDWR
);
5660 (void) strcpy((void *)buf
, argv
[2]);
5661 return (!!ioctl(fd
, ZFS_IOC_POOL_FREEZE
, buf
));
5663 (void) fprintf(stderr
, gettext("unrecognized "
5664 "command '%s'\n"), cmdname
);
5672 * The 'ZFS_ABORT' environment variable causes us to dump core on exit
5673 * for the purposes of running ::findleaks.
5675 if (getenv("ZFS_ABORT") != NULL
) {
5676 (void) printf("dumping core by request\n");