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 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
44 #include <sys/fs/zfs.h>
50 #include "zpool_util.h"
51 #include "zfs_comutil.h"
53 static int zpool_do_create(int, char **);
54 static int zpool_do_destroy(int, char **);
56 static int zpool_do_add(int, char **);
57 static int zpool_do_remove(int, char **);
59 static int zpool_do_list(int, char **);
60 static int zpool_do_iostat(int, char **);
61 static int zpool_do_status(int, char **);
63 static int zpool_do_online(int, char **);
64 static int zpool_do_offline(int, char **);
65 static int zpool_do_clear(int, char **);
67 static int zpool_do_attach(int, char **);
68 static int zpool_do_detach(int, char **);
69 static int zpool_do_replace(int, char **);
71 static int zpool_do_scrub(int, char **);
73 static int zpool_do_import(int, char **);
74 static int zpool_do_export(int, char **);
76 static int zpool_do_upgrade(int, char **);
78 static int zpool_do_history(int, char **);
80 static int zpool_do_get(int, char **);
81 static int zpool_do_set(int, char **);
84 * These libumem hooks provide a reasonable set of defaults for the allocator's
85 * debugging facilities.
90 _umem_debug_init(void)
92 return ("default,verbose"); /* $UMEM_DEBUG setting */
96 _umem_logging_init(void)
98 return ("fail,contents"); /* $UMEM_LOGGING setting */
126 typedef struct zpool_command
{
128 int (*func
)(int, char **);
133 * Master command table. Each ZFS command has a name, associated function, and
134 * usage message. The usage messages need to be internationalized, so we have
135 * to have a function to return the usage message based on a command index.
137 * These commands are organized according to how they are displayed in the usage
138 * message. An empty command (one with a NULL name) indicates an empty line in
139 * the generic usage message.
141 static zpool_command_t command_table
[] = {
142 { "create", zpool_do_create
, HELP_CREATE
},
143 { "destroy", zpool_do_destroy
, HELP_DESTROY
},
145 { "add", zpool_do_add
, HELP_ADD
},
146 { "remove", zpool_do_remove
, HELP_REMOVE
},
148 { "list", zpool_do_list
, HELP_LIST
},
149 { "iostat", zpool_do_iostat
, HELP_IOSTAT
},
150 { "status", zpool_do_status
, HELP_STATUS
},
152 { "online", zpool_do_online
, HELP_ONLINE
},
153 { "offline", zpool_do_offline
, HELP_OFFLINE
},
154 { "clear", zpool_do_clear
, HELP_CLEAR
},
156 { "attach", zpool_do_attach
, HELP_ATTACH
},
157 { "detach", zpool_do_detach
, HELP_DETACH
},
158 { "replace", zpool_do_replace
, HELP_REPLACE
},
160 { "scrub", zpool_do_scrub
, HELP_SCRUB
},
162 { "import", zpool_do_import
, HELP_IMPORT
},
163 { "export", zpool_do_export
, HELP_EXPORT
},
164 { "upgrade", zpool_do_upgrade
, HELP_UPGRADE
},
166 { "history", zpool_do_history
, HELP_HISTORY
},
167 { "get", zpool_do_get
, HELP_GET
},
168 { "set", zpool_do_set
, HELP_SET
},
171 #define NCOMMAND (sizeof (command_table) / sizeof (command_table[0]))
173 zpool_command_t
*current_command
;
174 static char history_str
[HIS_MAX_RECORD_LEN
];
177 get_usage(zpool_help_t idx
) {
180 return (gettext("\tadd [-fn] <pool> <vdev> ...\n"));
182 return (gettext("\tattach [-f] <pool> <device> "
185 return (gettext("\tclear <pool> [device]\n"));
187 return (gettext("\tcreate [-fn] [-o property=value] ... \n"
188 "\t [-O file-system-property=value] ... \n"
189 "\t [-m mountpoint] [-R root] <pool> <vdev> ...\n"));
191 return (gettext("\tdestroy [-f] <pool>\n"));
193 return (gettext("\tdetach <pool> <device>\n"));
195 return (gettext("\texport [-f] <pool> ...\n"));
197 return (gettext("\thistory [-il] [<pool>] ...\n"));
199 return (gettext("\timport [-d dir] [-D]\n"
200 "\timport [-o mntopts] [-o property=value] ... \n"
201 "\t [-d dir | -c cachefile] [-D] [-f] [-R root] -a\n"
202 "\timport [-o mntopts] [-o property=value] ... \n"
203 "\t [-d dir | -c cachefile] [-D] [-f] [-R root] "
204 "<pool | id> [newpool]\n"));
206 return (gettext("\tiostat [-v] [pool] ... [interval "
209 return (gettext("\tlist [-H] [-o property[,...]] "
212 return (gettext("\toffline [-t] <pool> <device> ...\n"));
214 return (gettext("\tonline <pool> <device> ...\n"));
216 return (gettext("\treplace [-f] <pool> <device> "
219 return (gettext("\tremove <pool> <device> ...\n"));
221 return (gettext("\tscrub [-s] <pool> ...\n"));
223 return (gettext("\tstatus [-vx] [pool] ...\n"));
225 return (gettext("\tupgrade\n"
227 "\tupgrade [-V version] <-a | pool ...>\n"));
229 return (gettext("\tget <\"all\" | property[,...]> "
232 return (gettext("\tset <property=value> <pool> \n"));
241 * Callback routine that will print out a pool property value.
244 print_prop_cb(int prop
, void *cb
)
248 (void) fprintf(fp
, "\t%-13s ", zpool_prop_to_name(prop
));
250 if (zpool_prop_readonly(prop
))
251 (void) fprintf(fp
, " NO ");
253 (void) fprintf(fp
, " YES ");
255 if (zpool_prop_values(prop
) == NULL
)
256 (void) fprintf(fp
, "-\n");
258 (void) fprintf(fp
, "%s\n", zpool_prop_values(prop
));
264 * Display usage message. If we're inside a command, display only the usage for
265 * that command. Otherwise, iterate over the entire command table and display
266 * a complete usage message.
269 usage(boolean_t requested
)
271 FILE *fp
= requested
? stdout
: stderr
;
273 if (current_command
== NULL
) {
276 (void) fprintf(fp
, gettext("usage: zpool command args ...\n"));
278 gettext("where 'command' is one of the following:\n\n"));
280 for (i
= 0; i
< NCOMMAND
; i
++) {
281 if (command_table
[i
].name
== NULL
)
282 (void) fprintf(fp
, "\n");
284 (void) fprintf(fp
, "%s",
285 get_usage(command_table
[i
].usage
));
288 (void) fprintf(fp
, gettext("usage:\n"));
289 (void) fprintf(fp
, "%s", get_usage(current_command
->usage
));
292 if (current_command
!= NULL
&&
293 ((strcmp(current_command
->name
, "set") == 0) ||
294 (strcmp(current_command
->name
, "get") == 0) ||
295 (strcmp(current_command
->name
, "list") == 0))) {
298 gettext("\nthe following properties are supported:\n"));
300 (void) fprintf(fp
, "\n\t%-13s %s %s\n\n",
301 "PROPERTY", "EDIT", "VALUES");
303 /* Iterate over all properties */
304 (void) zprop_iter(print_prop_cb
, fp
, B_FALSE
, B_TRUE
,
309 * See comments at end of main().
311 if (getenv("ZFS_ABORT") != NULL
) {
312 (void) printf("dumping core by request\n");
316 exit(requested
? 0 : 2);
320 print_vdev_tree(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
, int indent
,
321 boolean_t print_logs
)
328 (void) printf("\t%*s%s\n", indent
, "", name
);
330 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
331 &child
, &children
) != 0)
334 for (c
= 0; c
< children
; c
++) {
335 uint64_t is_log
= B_FALSE
;
337 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
339 if ((is_log
&& !print_logs
) || (!is_log
&& print_logs
))
342 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
]);
343 print_vdev_tree(zhp
, vname
, child
[c
], indent
+ 2,
350 * Add a property pair (name, string-value) into a property nvlist.
353 add_prop_list(const char *propname
, char *propval
, nvlist_t
**props
,
356 zpool_prop_t prop
= ZPROP_INVAL
;
362 if (*props
== NULL
&&
363 nvlist_alloc(props
, NV_UNIQUE_NAME
, 0) != 0) {
364 (void) fprintf(stderr
,
365 gettext("internal error: out of memory\n"));
372 if ((prop
= zpool_name_to_prop(propname
)) == ZPROP_INVAL
) {
373 (void) fprintf(stderr
, gettext("property '%s' is "
374 "not a valid pool property\n"), propname
);
377 normnm
= zpool_prop_to_name(prop
);
379 if ((fprop
= zfs_name_to_prop(propname
)) == ZPROP_INVAL
) {
380 (void) fprintf(stderr
, gettext("property '%s' is "
381 "not a valid file system property\n"), propname
);
384 normnm
= zfs_prop_to_name(fprop
);
387 if (nvlist_lookup_string(proplist
, normnm
, &strval
) == 0 &&
388 prop
!= ZPOOL_PROP_CACHEFILE
) {
389 (void) fprintf(stderr
, gettext("property '%s' "
390 "specified multiple times\n"), propname
);
394 if (nvlist_add_string(proplist
, normnm
, propval
) != 0) {
395 (void) fprintf(stderr
, gettext("internal "
396 "error: out of memory\n"));
404 * zpool add [-fn] <pool> <vdev> ...
406 * -f Force addition of devices, even if they appear in use
407 * -n Do not add the devices, but display the resulting layout if
408 * they were to be added.
410 * Adds the given vdevs to 'pool'. As with create, the bulk of this work is
411 * handled by get_vdev_spec(), which constructs the nvlist needed to pass to
415 zpool_do_add(int argc
, char **argv
)
417 boolean_t force
= B_FALSE
;
418 boolean_t dryrun
= B_FALSE
;
427 while ((c
= getopt(argc
, argv
, "fn")) != -1) {
436 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
445 /* get pool name and check number of arguments */
447 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
451 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
460 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
463 if ((config
= zpool_get_config(zhp
, NULL
)) == NULL
) {
464 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
470 /* pass off to get_vdev_spec for processing */
471 nvroot
= make_root_vdev(zhp
, force
, !force
, B_FALSE
, dryrun
,
473 if (nvroot
== NULL
) {
479 nvlist_t
*poolnvroot
;
481 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
484 (void) printf(gettext("would update '%s' to the following "
485 "configuration:\n"), zpool_get_name(zhp
));
487 /* print original main pool and new tree */
488 print_vdev_tree(zhp
, poolname
, poolnvroot
, 0, B_FALSE
);
489 print_vdev_tree(zhp
, NULL
, nvroot
, 0, B_FALSE
);
491 /* Do the same for the logs */
492 if (num_logs(poolnvroot
) > 0) {
493 print_vdev_tree(zhp
, "logs", poolnvroot
, 0, B_TRUE
);
494 print_vdev_tree(zhp
, NULL
, nvroot
, 0, B_TRUE
);
495 } else if (num_logs(nvroot
) > 0) {
496 print_vdev_tree(zhp
, "logs", nvroot
, 0, B_TRUE
);
501 ret
= (zpool_add(zhp
, nvroot
) != 0);
511 * zpool remove <pool> <vdev> ...
513 * Removes the given vdev from the pool. Currently, this only supports removing
514 * spares and cache devices from the pool. Eventually, we'll want to support
515 * removing leaf vdevs (as an alias for 'detach') as well as toplevel vdevs.
518 zpool_do_remove(int argc
, char **argv
)
527 /* get pool name and check number of arguments */
529 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
533 (void) fprintf(stderr
, gettext("missing device\n"));
539 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
542 for (i
= 1; i
< argc
; i
++) {
543 if (zpool_vdev_remove(zhp
, argv
[i
]) != 0)
551 * zpool create [-fn] [-o property=value] ...
552 * [-O file-system-property=value] ...
553 * [-R root] [-m mountpoint] <pool> <dev> ...
555 * -f Force creation, even if devices appear in use
556 * -n Do not create the pool, but display the resulting layout if it
557 * were to be created.
558 * -R Create a pool under an alternate root
559 * -m Set default mountpoint for the root dataset. By default it's
561 * -o Set property=value.
562 * -O Set fsproperty=value in the pool's root file system
564 * Creates the named pool according to the given vdev specification. The
565 * bulk of the vdev processing is done in get_vdev_spec() in zpool_vdev.c. Once
566 * we get the nvlist back from get_vdev_spec(), we either print out the contents
567 * (if '-n' was specified), or pass it to libzfs to do the creation.
570 zpool_do_create(int argc
, char **argv
)
572 boolean_t force
= B_FALSE
;
573 boolean_t dryrun
= B_FALSE
;
575 nvlist_t
*nvroot
= NULL
;
578 char *altroot
= NULL
;
579 char *mountpoint
= NULL
;
580 nvlist_t
*fsprops
= NULL
;
581 nvlist_t
*props
= NULL
;
585 while ((c
= getopt(argc
, argv
, ":fnR:m:o:O:")) != -1) {
595 if (add_prop_list(zpool_prop_to_name(
596 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
598 if (nvlist_lookup_string(props
,
599 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
),
602 if (add_prop_list(zpool_prop_to_name(
603 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
610 if ((propval
= strchr(optarg
, '=')) == NULL
) {
611 (void) fprintf(stderr
, gettext("missing "
612 "'=' for -o option\n"));
618 if (add_prop_list(optarg
, propval
, &props
, B_TRUE
))
622 if ((propval
= strchr(optarg
, '=')) == NULL
) {
623 (void) fprintf(stderr
, gettext("missing "
624 "'=' for -O option\n"));
630 if (add_prop_list(optarg
, propval
, &fsprops
, B_FALSE
))
634 (void) fprintf(stderr
, gettext("missing argument for "
635 "'%c' option\n"), optopt
);
638 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
647 /* get pool name and check number of arguments */
649 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
653 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
660 * As a special case, check for use of '/' in the name, and direct the
661 * user to use 'zfs create' instead.
663 if (strchr(poolname
, '/') != NULL
) {
664 (void) fprintf(stderr
, gettext("cannot create '%s': invalid "
665 "character '/' in pool name\n"), poolname
);
666 (void) fprintf(stderr
, gettext("use 'zfs create' to "
667 "create a dataset\n"));
671 /* pass off to get_vdev_spec for bulk processing */
672 nvroot
= make_root_vdev(NULL
, force
, !force
, B_FALSE
, dryrun
,
677 /* make_root_vdev() allows 0 toplevel children if there are spares */
678 if (!zfs_allocatable_devs(nvroot
)) {
679 (void) fprintf(stderr
, gettext("invalid vdev "
680 "specification: at least one toplevel vdev must be "
686 if (altroot
!= NULL
&& altroot
[0] != '/') {
687 (void) fprintf(stderr
, gettext("invalid alternate root '%s': "
688 "must be an absolute path\n"), altroot
);
693 * Check the validity of the mountpoint and direct the user to use the
694 * '-m' mountpoint option if it looks like its in use.
696 if (mountpoint
== NULL
||
697 (strcmp(mountpoint
, ZFS_MOUNTPOINT_LEGACY
) != 0 &&
698 strcmp(mountpoint
, ZFS_MOUNTPOINT_NONE
) != 0)) {
699 char buf
[MAXPATHLEN
];
702 if (mountpoint
&& mountpoint
[0] != '/') {
703 (void) fprintf(stderr
, gettext("invalid mountpoint "
704 "'%s': must be an absolute path, 'legacy', or "
705 "'none'\n"), mountpoint
);
709 if (mountpoint
== NULL
) {
711 (void) snprintf(buf
, sizeof (buf
), "%s/%s",
714 (void) snprintf(buf
, sizeof (buf
), "/%s",
718 (void) snprintf(buf
, sizeof (buf
), "%s%s",
719 altroot
, mountpoint
);
721 (void) snprintf(buf
, sizeof (buf
), "%s",
725 if ((dirp
= opendir(buf
)) == NULL
&& errno
!= ENOENT
) {
726 (void) fprintf(stderr
, gettext("mountpoint '%s' : "
727 "%s\n"), buf
, strerror(errno
));
728 (void) fprintf(stderr
, gettext("use '-m' "
729 "option to provide a different default\n"));
734 while (count
< 3 && readdir(dirp
) != NULL
)
736 (void) closedir(dirp
);
739 (void) fprintf(stderr
, gettext("mountpoint "
740 "'%s' exists and is not empty\n"), buf
);
741 (void) fprintf(stderr
, gettext("use '-m' "
742 "option to provide a "
743 "different default\n"));
751 * For a dry run invocation, print out a basic message and run
752 * through all the vdevs in the list and print out in an
753 * appropriate hierarchy.
755 (void) printf(gettext("would create '%s' with the "
756 "following layout:\n\n"), poolname
);
758 print_vdev_tree(NULL
, poolname
, nvroot
, 0, B_FALSE
);
759 if (num_logs(nvroot
) > 0)
760 print_vdev_tree(NULL
, "logs", nvroot
, 0, B_TRUE
);
765 * Hand off to libzfs.
767 if (zpool_create(g_zfs
, poolname
,
768 nvroot
, props
, fsprops
) == 0) {
769 zfs_handle_t
*pool
= zfs_open(g_zfs
, poolname
,
770 ZFS_TYPE_FILESYSTEM
);
772 if (mountpoint
!= NULL
)
773 verify(zfs_prop_set(pool
,
775 ZFS_PROP_MOUNTPOINT
),
777 if (zfs_mount(pool
, NULL
, 0) == 0)
778 ret
= zfs_shareall(pool
);
781 } else if (libzfs_errno(g_zfs
) == EZFS_INVALIDNAME
) {
782 (void) fprintf(stderr
, gettext("pool name may have "
789 nvlist_free(fsprops
);
793 nvlist_free(fsprops
);
800 * zpool destroy <pool>
802 * -f Forcefully unmount any datasets
804 * Destroy the given pool. Automatically unmounts any datasets in the pool.
807 zpool_do_destroy(int argc
, char **argv
)
809 boolean_t force
= B_FALSE
;
816 while ((c
= getopt(argc
, argv
, "f")) != -1) {
822 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
831 /* check arguments */
833 (void) fprintf(stderr
, gettext("missing pool argument\n"));
837 (void) fprintf(stderr
, gettext("too many arguments\n"));
843 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
) {
845 * As a special case, check for use of '/' in the name, and
846 * direct the user to use 'zfs destroy' instead.
848 if (strchr(pool
, '/') != NULL
)
849 (void) fprintf(stderr
, gettext("use 'zfs destroy' to "
850 "destroy a dataset\n"));
854 if (zpool_disable_datasets(zhp
, force
) != 0) {
855 (void) fprintf(stderr
, gettext("could not destroy '%s': "
856 "could not unmount datasets\n"), zpool_get_name(zhp
));
860 ret
= (zpool_destroy(zhp
) != 0);
868 * zpool export [-f] <pool> ...
870 * -f Forcefully unmount datasets
872 * Export the given pools. By default, the command will attempt to cleanly
873 * unmount any active datasets within the pool. If the '-f' flag is specified,
874 * then the datasets will be forcefully unmounted.
877 zpool_do_export(int argc
, char **argv
)
879 boolean_t force
= B_FALSE
;
886 while ((c
= getopt(argc
, argv
, "f")) != -1) {
892 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
901 /* check arguments */
903 (void) fprintf(stderr
, gettext("missing pool argument\n"));
908 for (i
= 0; i
< argc
; i
++) {
909 if ((zhp
= zpool_open_canfail(g_zfs
, argv
[i
])) == NULL
) {
914 if (zpool_disable_datasets(zhp
, force
) != 0) {
920 if (zpool_export(zhp
, force
) != 0)
930 * Given a vdev configuration, determine the maximum width needed for the device
934 max_width(zpool_handle_t
*zhp
, nvlist_t
*nv
, int depth
, int max
)
936 char *name
= zpool_vdev_name(g_zfs
, zhp
, nv
);
941 if (strlen(name
) + depth
> max
)
942 max
= strlen(name
) + depth
;
946 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
947 &child
, &children
) == 0) {
948 for (c
= 0; c
< children
; c
++)
949 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
954 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
955 &child
, &children
) == 0) {
956 for (c
= 0; c
< children
; c
++)
957 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
962 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
963 &child
, &children
) == 0) {
964 for (c
= 0; c
< children
; c
++)
965 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
976 * Print the configuration of an exported pool. Iterate over all vdevs in the
977 * pool, printing out the name and status for each one.
980 print_import_config(const char *name
, nvlist_t
*nv
, int namewidth
, int depth
,
981 boolean_t print_logs
)
988 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_TYPE
, &type
) == 0);
989 if (strcmp(type
, VDEV_TYPE_MISSING
) == 0)
992 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_STATS
,
993 (uint64_t **)&vs
, &c
) == 0);
995 (void) printf("\t%*s%-*s", depth
, "", namewidth
- depth
, name
);
996 (void) printf(" %s", zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
));
998 if (vs
->vs_aux
!= 0) {
1001 switch (vs
->vs_aux
) {
1002 case VDEV_AUX_OPEN_FAILED
:
1003 (void) printf(gettext("cannot open"));
1006 case VDEV_AUX_BAD_GUID_SUM
:
1007 (void) printf(gettext("missing device"));
1010 case VDEV_AUX_NO_REPLICAS
:
1011 (void) printf(gettext("insufficient replicas"));
1014 case VDEV_AUX_VERSION_NEWER
:
1015 (void) printf(gettext("newer version"));
1018 case VDEV_AUX_ERR_EXCEEDED
:
1019 (void) printf(gettext("too many errors"));
1023 (void) printf(gettext("corrupted data"));
1027 (void) printf("\n");
1029 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1030 &child
, &children
) != 0)
1033 for (c
= 0; c
< children
; c
++) {
1034 uint64_t is_log
= B_FALSE
;
1036 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1038 if ((is_log
&& !print_logs
) || (!is_log
&& print_logs
))
1041 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
]);
1042 print_import_config(vname
, child
[c
],
1043 namewidth
, depth
+ 2, B_FALSE
);
1047 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
1048 &child
, &children
) == 0) {
1049 (void) printf(gettext("\tcache\n"));
1050 for (c
= 0; c
< children
; c
++) {
1051 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
]);
1052 (void) printf("\t %s\n", vname
);
1057 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
1058 &child
, &children
) == 0) {
1059 (void) printf(gettext("\tspares\n"));
1060 for (c
= 0; c
< children
; c
++) {
1061 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
]);
1062 (void) printf("\t %s\n", vname
);
1069 * Display the status for the given pool.
1072 show_import(nvlist_t
*config
)
1074 uint64_t pool_state
;
1085 verify(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
1087 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
,
1089 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
1091 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
1094 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_STATS
,
1095 (uint64_t **)&vs
, &vsc
) == 0);
1096 health
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
1098 reason
= zpool_import_status(config
, &msgid
);
1100 (void) printf(gettext(" pool: %s\n"), name
);
1101 (void) printf(gettext(" id: %llu\n"), (u_longlong_t
)guid
);
1102 (void) printf(gettext(" state: %s"), health
);
1103 if (pool_state
== POOL_STATE_DESTROYED
)
1104 (void) printf(gettext(" (DESTROYED)"));
1105 (void) printf("\n");
1108 case ZPOOL_STATUS_MISSING_DEV_R
:
1109 case ZPOOL_STATUS_MISSING_DEV_NR
:
1110 case ZPOOL_STATUS_BAD_GUID_SUM
:
1111 (void) printf(gettext("status: One or more devices are missing "
1112 "from the system.\n"));
1115 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
1116 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
1117 (void) printf(gettext("status: One or more devices contains "
1118 "corrupted data.\n"));
1121 case ZPOOL_STATUS_CORRUPT_DATA
:
1122 (void) printf(gettext("status: The pool data is corrupted.\n"));
1125 case ZPOOL_STATUS_OFFLINE_DEV
:
1126 (void) printf(gettext("status: One or more devices "
1127 "are offlined.\n"));
1130 case ZPOOL_STATUS_CORRUPT_POOL
:
1131 (void) printf(gettext("status: The pool metadata is "
1135 case ZPOOL_STATUS_VERSION_OLDER
:
1136 (void) printf(gettext("status: The pool is formatted using an "
1137 "older on-disk version.\n"));
1140 case ZPOOL_STATUS_VERSION_NEWER
:
1141 (void) printf(gettext("status: The pool is formatted using an "
1142 "incompatible version.\n"));
1145 case ZPOOL_STATUS_HOSTID_MISMATCH
:
1146 (void) printf(gettext("status: The pool was last accessed by "
1147 "another system.\n"));
1150 case ZPOOL_STATUS_FAULTED_DEV_R
:
1151 case ZPOOL_STATUS_FAULTED_DEV_NR
:
1152 (void) printf(gettext("status: One or more devices are "
1156 case ZPOOL_STATUS_BAD_LOG
:
1157 (void) printf(gettext("status: An intent log record cannot be "
1163 * No other status can be seen when importing pools.
1165 assert(reason
== ZPOOL_STATUS_OK
);
1169 * Print out an action according to the overall state of the pool.
1171 if (vs
->vs_state
== VDEV_STATE_HEALTHY
) {
1172 if (reason
== ZPOOL_STATUS_VERSION_OLDER
)
1173 (void) printf(gettext("action: The pool can be "
1174 "imported using its name or numeric identifier, "
1175 "though\n\tsome features will not be available "
1176 "without an explicit 'zpool upgrade'.\n"));
1177 else if (reason
== ZPOOL_STATUS_HOSTID_MISMATCH
)
1178 (void) printf(gettext("action: The pool can be "
1179 "imported using its name or numeric "
1180 "identifier and\n\tthe '-f' flag.\n"));
1182 (void) printf(gettext("action: The pool can be "
1183 "imported using its name or numeric "
1185 } else if (vs
->vs_state
== VDEV_STATE_DEGRADED
) {
1186 (void) printf(gettext("action: The pool can be imported "
1187 "despite missing or damaged devices. The\n\tfault "
1188 "tolerance of the pool may be compromised if imported.\n"));
1191 case ZPOOL_STATUS_VERSION_NEWER
:
1192 (void) printf(gettext("action: The pool cannot be "
1193 "imported. Access the pool on a system running "
1194 "newer\n\tsoftware, or recreate the pool from "
1197 case ZPOOL_STATUS_MISSING_DEV_R
:
1198 case ZPOOL_STATUS_MISSING_DEV_NR
:
1199 case ZPOOL_STATUS_BAD_GUID_SUM
:
1200 (void) printf(gettext("action: The pool cannot be "
1201 "imported. Attach the missing\n\tdevices and try "
1205 (void) printf(gettext("action: The pool cannot be "
1206 "imported due to damaged devices or data.\n"));
1211 * If the state is "closed" or "can't open", and the aux state
1212 * is "corrupt data":
1214 if (((vs
->vs_state
== VDEV_STATE_CLOSED
) ||
1215 (vs
->vs_state
== VDEV_STATE_CANT_OPEN
)) &&
1216 (vs
->vs_aux
== VDEV_AUX_CORRUPT_DATA
)) {
1217 if (pool_state
== POOL_STATE_DESTROYED
)
1218 (void) printf(gettext("\tThe pool was destroyed, "
1219 "but can be imported using the '-Df' flags.\n"));
1220 else if (pool_state
!= POOL_STATE_EXPORTED
)
1221 (void) printf(gettext("\tThe pool may be active on "
1222 "another system, but can be imported using\n\t"
1223 "the '-f' flag.\n"));
1227 (void) printf(gettext(" see: http://www.sun.com/msg/%s\n"),
1230 (void) printf(gettext("config:\n\n"));
1232 namewidth
= max_width(NULL
, nvroot
, 0, 0);
1236 print_import_config(name
, nvroot
, namewidth
, 0, B_FALSE
);
1237 if (num_logs(nvroot
) > 0) {
1238 (void) printf(gettext("\tlogs\n"));
1239 print_import_config(name
, nvroot
, namewidth
, 0, B_TRUE
);
1242 if (reason
== ZPOOL_STATUS_BAD_GUID_SUM
) {
1243 (void) printf(gettext("\n\tAdditional devices are known to "
1244 "be part of this pool, though their\n\texact "
1245 "configuration cannot be determined.\n"));
1250 * Perform the import for the given configuration. This passes the heavy
1251 * lifting off to zpool_import_props(), and then mounts the datasets contained
1255 do_import(nvlist_t
*config
, const char *newname
, const char *mntopts
,
1256 int force
, nvlist_t
*props
, boolean_t allowfaulted
)
1258 zpool_handle_t
*zhp
;
1264 verify(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
1267 verify(nvlist_lookup_uint64(config
,
1268 ZPOOL_CONFIG_POOL_STATE
, &state
) == 0);
1269 verify(nvlist_lookup_uint64(config
,
1270 ZPOOL_CONFIG_VERSION
, &version
) == 0);
1271 if (version
> SPA_VERSION
) {
1272 (void) fprintf(stderr
, gettext("cannot import '%s': pool "
1273 "is formatted using a newer ZFS version\n"), name
);
1275 } else if (state
!= POOL_STATE_EXPORTED
&& !force
) {
1278 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_HOSTID
,
1280 if ((unsigned long)hostid
!= gethostid()) {
1285 verify(nvlist_lookup_string(config
,
1286 ZPOOL_CONFIG_HOSTNAME
, &hostname
) == 0);
1287 verify(nvlist_lookup_uint64(config
,
1288 ZPOOL_CONFIG_TIMESTAMP
, ×tamp
) == 0);
1290 (void) fprintf(stderr
, gettext("cannot import "
1291 "'%s': pool may be in use from other "
1292 "system, it was last accessed by %s "
1293 "(hostid: 0x%lx) on %s"), name
, hostname
,
1294 (unsigned long)hostid
,
1295 asctime(localtime(&t
)));
1296 (void) fprintf(stderr
, gettext("use '-f' to "
1297 "import anyway\n"));
1301 (void) fprintf(stderr
, gettext("cannot import '%s': "
1302 "pool may be in use from other system\n"), name
);
1303 (void) fprintf(stderr
, gettext("use '-f' to import "
1309 if (zpool_import_props(g_zfs
, config
, newname
, props
,
1313 if (newname
!= NULL
)
1314 name
= (char *)newname
;
1316 verify((zhp
= zpool_open_canfail(g_zfs
, name
)) != NULL
);
1318 if (zpool_enable_datasets(zhp
, mntopts
, 0) != 0) {
1328 * zpool import [-d dir] [-D]
1329 * import [-o mntopts] [-o prop=value] ... [-R root] [-D]
1330 * [-d dir | -c cachefile] [-f] -a
1331 * import [-o mntopts] [-o prop=value] ... [-R root] [-D]
1332 * [-d dir | -c cachefile] [-f] <pool | id> [newpool]
1334 * -c Read pool information from a cachefile instead of searching
1337 * -d Scan in a specific directory, other than /dev/dsk. More than
1338 * one directory can be specified using multiple '-d' options.
1340 * -D Scan for previously destroyed pools or import all or only
1341 * specified destroyed pools.
1343 * -R Temporarily import the pool, with all mountpoints relative to
1344 * the given root. The pool will remain exported when the machine
1347 * -f Force import, even if it appears that the pool is active.
1349 * -F Import even in the presence of faulted vdevs. This is an
1350 * intentionally undocumented option for testing purposes, and
1351 * treats the pool configuration as complete, leaving any bad
1352 * vdevs in the FAULTED state.
1354 * -a Import all pools found.
1356 * -o Set property=value and/or temporary mount options (without '=').
1358 * The import command scans for pools to import, and import pools based on pool
1359 * name and GUID. The pool can also be renamed as part of the import process.
1362 zpool_do_import(int argc
, char **argv
)
1364 char **searchdirs
= NULL
;
1368 nvlist_t
*pools
= NULL
;
1369 boolean_t do_all
= B_FALSE
;
1370 boolean_t do_destroyed
= B_FALSE
;
1371 char *mntopts
= NULL
;
1372 boolean_t do_force
= B_FALSE
;
1375 uint64_t searchguid
= 0;
1376 char *searchname
= NULL
;
1378 nvlist_t
*found_config
;
1379 nvlist_t
*props
= NULL
;
1381 boolean_t allow_faulted
= B_FALSE
;
1382 uint64_t pool_state
;
1383 char *cachefile
= NULL
;
1386 while ((c
= getopt(argc
, argv
, ":ac:d:DfFo:p:R:")) != -1) {
1395 if (searchdirs
== NULL
) {
1396 searchdirs
= safe_malloc(sizeof (char *));
1398 char **tmp
= safe_malloc((nsearch
+ 1) *
1400 bcopy(searchdirs
, tmp
, nsearch
*
1405 searchdirs
[nsearch
++] = optarg
;
1408 do_destroyed
= B_TRUE
;
1414 allow_faulted
= B_TRUE
;
1417 if ((propval
= strchr(optarg
, '=')) != NULL
) {
1420 if (add_prop_list(optarg
, propval
,
1428 if (add_prop_list(zpool_prop_to_name(
1429 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
1431 if (nvlist_lookup_string(props
,
1432 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
),
1435 if (add_prop_list(zpool_prop_to_name(
1436 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
1440 (void) fprintf(stderr
, gettext("missing argument for "
1441 "'%c' option\n"), optopt
);
1445 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1454 if (cachefile
&& nsearch
!= 0) {
1455 (void) fprintf(stderr
, gettext("-c is incompatible with -d\n"));
1459 if (searchdirs
== NULL
) {
1460 searchdirs
= safe_malloc(sizeof (char *));
1461 searchdirs
[0] = "/dev/dsk";
1465 /* check argument count */
1468 (void) fprintf(stderr
, gettext("too many arguments\n"));
1473 (void) fprintf(stderr
, gettext("too many arguments\n"));
1478 * Check for the SYS_CONFIG privilege. We do this explicitly
1479 * here because otherwise any attempt to discover pools will
1482 if (argc
== 0 && !priv_ineffect(PRIV_SYS_CONFIG
)) {
1483 (void) fprintf(stderr
, gettext("cannot "
1484 "discover pools: permission denied\n"));
1491 * Depending on the arguments given, we do one of the following:
1493 * <none> Iterate through all pools and display information about
1496 * -a Iterate through all pools and try to import each one.
1498 * <id> Find the pool that corresponds to the given GUID/pool
1499 * name and import that one.
1501 * -D Above options applies only to destroyed pools.
1507 searchguid
= strtoull(argv
[0], &endptr
, 10);
1508 if (errno
!= 0 || *endptr
!= '\0')
1509 searchname
= argv
[0];
1510 found_config
= NULL
;
1514 pools
= zpool_find_import_cached(g_zfs
, cachefile
, searchname
,
1516 } else if (searchname
!= NULL
) {
1517 pools
= zpool_find_import_byname(g_zfs
, nsearch
, searchdirs
,
1521 * It's OK to search by guid even if searchguid is 0.
1523 pools
= zpool_find_import_byguid(g_zfs
, nsearch
, searchdirs
,
1527 if (pools
== NULL
) {
1529 (void) fprintf(stderr
, gettext("cannot import '%s': "
1530 "no such pool available\n"), argv
[0]);
1537 * At this point we have a list of import candidate configs. Even if
1538 * we were searching by pool name or guid, we still need to
1539 * post-process the list to deal with pool state and possible
1545 while ((elem
= nvlist_next_nvpair(pools
, elem
)) != NULL
) {
1547 verify(nvpair_value_nvlist(elem
, &config
) == 0);
1549 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
1551 if (!do_destroyed
&& pool_state
== POOL_STATE_DESTROYED
)
1553 if (do_destroyed
&& pool_state
!= POOL_STATE_DESTROYED
)
1560 (void) printf("\n");
1563 err
|= do_import(config
, NULL
, mntopts
,
1564 do_force
, props
, allow_faulted
);
1566 show_import(config
);
1567 } else if (searchname
!= NULL
) {
1571 * We are searching for a pool based on name.
1573 verify(nvlist_lookup_string(config
,
1574 ZPOOL_CONFIG_POOL_NAME
, &name
) == 0);
1576 if (strcmp(name
, searchname
) == 0) {
1577 if (found_config
!= NULL
) {
1578 (void) fprintf(stderr
, gettext(
1579 "cannot import '%s': more than "
1580 "one matching pool\n"), searchname
);
1581 (void) fprintf(stderr
, gettext(
1582 "import by numeric ID instead\n"));
1585 found_config
= config
;
1591 * Search for a pool by guid.
1593 verify(nvlist_lookup_uint64(config
,
1594 ZPOOL_CONFIG_POOL_GUID
, &guid
) == 0);
1596 if (guid
== searchguid
)
1597 found_config
= config
;
1602 * If we were searching for a specific pool, verify that we found a
1603 * pool, and then do the import.
1605 if (argc
!= 0 && err
== 0) {
1606 if (found_config
== NULL
) {
1607 (void) fprintf(stderr
, gettext("cannot import '%s': "
1608 "no such pool available\n"), argv
[0]);
1611 err
|= do_import(found_config
, argc
== 1 ? NULL
:
1612 argv
[1], mntopts
, do_force
, props
, allow_faulted
);
1617 * If we were just looking for pools, report an error if none were
1620 if (argc
== 0 && first
)
1621 (void) fprintf(stderr
,
1622 gettext("no pools available to import\n"));
1629 return (err
? 1 : 0);
1632 typedef struct iostat_cbdata
{
1633 zpool_list_t
*cb_list
;
1640 print_iostat_separator(iostat_cbdata_t
*cb
)
1644 for (i
= 0; i
< cb
->cb_namewidth
; i
++)
1646 (void) printf(" ----- ----- ----- ----- ----- -----\n");
1650 print_iostat_header(iostat_cbdata_t
*cb
)
1652 (void) printf("%*s capacity operations bandwidth\n",
1653 cb
->cb_namewidth
, "");
1654 (void) printf("%-*s used avail read write read write\n",
1655 cb
->cb_namewidth
, "pool");
1656 print_iostat_separator(cb
);
1660 * Display a single statistic.
1663 print_one_stat(uint64_t value
)
1667 zfs_nicenum(value
, buf
, sizeof (buf
));
1668 (void) printf(" %5s", buf
);
1672 * Print out all the statistics for the given vdev. This can either be the
1673 * toplevel configuration, or called recursively. If 'name' is NULL, then this
1674 * is a verbose output, and we don't want to display the toplevel pool stats.
1677 print_vdev_stats(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*oldnv
,
1678 nvlist_t
*newnv
, iostat_cbdata_t
*cb
, int depth
)
1680 nvlist_t
**oldchild
, **newchild
;
1682 vdev_stat_t
*oldvs
, *newvs
;
1683 vdev_stat_t zerovs
= { 0 };
1688 if (oldnv
!= NULL
) {
1689 verify(nvlist_lookup_uint64_array(oldnv
, ZPOOL_CONFIG_STATS
,
1690 (uint64_t **)&oldvs
, &c
) == 0);
1695 verify(nvlist_lookup_uint64_array(newnv
, ZPOOL_CONFIG_STATS
,
1696 (uint64_t **)&newvs
, &c
) == 0);
1698 if (strlen(name
) + depth
> cb
->cb_namewidth
)
1699 (void) printf("%*s%s", depth
, "", name
);
1701 (void) printf("%*s%s%*s", depth
, "", name
,
1702 (int)(cb
->cb_namewidth
- strlen(name
) - depth
), "");
1704 tdelta
= newvs
->vs_timestamp
- oldvs
->vs_timestamp
;
1709 scale
= (double)NANOSEC
/ tdelta
;
1711 /* only toplevel vdevs have capacity stats */
1712 if (newvs
->vs_space
== 0) {
1713 (void) printf(" - -");
1715 print_one_stat(newvs
->vs_alloc
);
1716 print_one_stat(newvs
->vs_space
- newvs
->vs_alloc
);
1719 print_one_stat((uint64_t)(scale
* (newvs
->vs_ops
[ZIO_TYPE_READ
] -
1720 oldvs
->vs_ops
[ZIO_TYPE_READ
])));
1722 print_one_stat((uint64_t)(scale
* (newvs
->vs_ops
[ZIO_TYPE_WRITE
] -
1723 oldvs
->vs_ops
[ZIO_TYPE_WRITE
])));
1725 print_one_stat((uint64_t)(scale
* (newvs
->vs_bytes
[ZIO_TYPE_READ
] -
1726 oldvs
->vs_bytes
[ZIO_TYPE_READ
])));
1728 print_one_stat((uint64_t)(scale
* (newvs
->vs_bytes
[ZIO_TYPE_WRITE
] -
1729 oldvs
->vs_bytes
[ZIO_TYPE_WRITE
])));
1731 (void) printf("\n");
1733 if (!cb
->cb_verbose
)
1736 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_CHILDREN
,
1737 &newchild
, &children
) != 0)
1740 if (oldnv
&& nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_CHILDREN
,
1741 &oldchild
, &c
) != 0)
1744 for (c
= 0; c
< children
; c
++) {
1745 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
]);
1746 print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
] : NULL
,
1747 newchild
[c
], cb
, depth
+ 2);
1752 * Include level 2 ARC devices in iostat output
1754 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_L2CACHE
,
1755 &newchild
, &children
) != 0)
1758 if (oldnv
&& nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_L2CACHE
,
1759 &oldchild
, &c
) != 0)
1763 (void) printf("%-*s - - - - - "
1764 "-\n", cb
->cb_namewidth
, "cache");
1765 for (c
= 0; c
< children
; c
++) {
1766 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
]);
1767 print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
] : NULL
,
1768 newchild
[c
], cb
, depth
+ 2);
1775 refresh_iostat(zpool_handle_t
*zhp
, void *data
)
1777 iostat_cbdata_t
*cb
= data
;
1781 * If the pool has disappeared, remove it from the list and continue.
1783 if (zpool_refresh_stats(zhp
, &missing
) != 0)
1787 pool_list_remove(cb
->cb_list
, zhp
);
1793 * Callback to print out the iostats for the given pool.
1796 print_iostat(zpool_handle_t
*zhp
, void *data
)
1798 iostat_cbdata_t
*cb
= data
;
1799 nvlist_t
*oldconfig
, *newconfig
;
1800 nvlist_t
*oldnvroot
, *newnvroot
;
1802 newconfig
= zpool_get_config(zhp
, &oldconfig
);
1804 if (cb
->cb_iteration
== 1)
1807 verify(nvlist_lookup_nvlist(newconfig
, ZPOOL_CONFIG_VDEV_TREE
,
1810 if (oldconfig
== NULL
)
1813 verify(nvlist_lookup_nvlist(oldconfig
, ZPOOL_CONFIG_VDEV_TREE
,
1817 * Print out the statistics for the pool.
1819 print_vdev_stats(zhp
, zpool_get_name(zhp
), oldnvroot
, newnvroot
, cb
, 0);
1822 print_iostat_separator(cb
);
1828 get_namewidth(zpool_handle_t
*zhp
, void *data
)
1830 iostat_cbdata_t
*cb
= data
;
1831 nvlist_t
*config
, *nvroot
;
1833 if ((config
= zpool_get_config(zhp
, NULL
)) != NULL
) {
1834 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
1836 if (!cb
->cb_verbose
)
1837 cb
->cb_namewidth
= strlen(zpool_get_name(zhp
));
1839 cb
->cb_namewidth
= max_width(zhp
, nvroot
, 0, 0);
1843 * The width must fall into the range [10,38]. The upper limit is the
1844 * maximum we can have and still fit in 80 columns.
1846 if (cb
->cb_namewidth
< 10)
1847 cb
->cb_namewidth
= 10;
1848 if (cb
->cb_namewidth
> 38)
1849 cb
->cb_namewidth
= 38;
1855 * zpool iostat [-v] [pool] ... [interval [count]]
1857 * -v Display statistics for individual vdevs
1859 * This command can be tricky because we want to be able to deal with pool
1860 * creation/destruction as well as vdev configuration changes. The bulk of this
1861 * processing is handled by the pool_list_* routines in zpool_iter.c. We rely
1862 * on pool_list_update() to detect the addition of new pools. Configuration
1863 * changes are all handled within libzfs.
1866 zpool_do_iostat(int argc
, char **argv
)
1871 unsigned long interval
= 0, count
= 0;
1873 boolean_t verbose
= B_FALSE
;
1877 while ((c
= getopt(argc
, argv
, "v")) != -1) {
1883 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1893 * Determine if the last argument is an integer or a pool name
1895 if (argc
> 0 && isdigit(argv
[argc
- 1][0])) {
1899 interval
= strtoul(argv
[argc
- 1], &end
, 10);
1901 if (*end
== '\0' && errno
== 0) {
1902 if (interval
== 0) {
1903 (void) fprintf(stderr
, gettext("interval "
1904 "cannot be zero\n"));
1909 * Ignore the last parameter
1914 * If this is not a valid number, just plow on. The
1915 * user will get a more informative error message later
1923 * If the last argument is also an integer, then we have both a count
1926 if (argc
> 0 && isdigit(argv
[argc
- 1][0])) {
1931 interval
= strtoul(argv
[argc
- 1], &end
, 10);
1933 if (*end
== '\0' && errno
== 0) {
1934 if (interval
== 0) {
1935 (void) fprintf(stderr
, gettext("interval "
1936 "cannot be zero\n"));
1941 * Ignore the last parameter
1950 * Construct the list of all interesting pools.
1953 if ((list
= pool_list_get(argc
, argv
, NULL
, &ret
)) == NULL
)
1956 if (pool_list_count(list
) == 0 && argc
!= 0) {
1957 pool_list_free(list
);
1961 if (pool_list_count(list
) == 0 && interval
== 0) {
1962 pool_list_free(list
);
1963 (void) fprintf(stderr
, gettext("no pools available\n"));
1968 * Enter the main iostat loop.
1971 cb
.cb_verbose
= verbose
;
1972 cb
.cb_iteration
= 0;
1973 cb
.cb_namewidth
= 0;
1976 pool_list_update(list
);
1978 if ((npools
= pool_list_count(list
)) == 0)
1982 * Refresh all statistics. This is done as an explicit step
1983 * before calculating the maximum name width, so that any
1984 * configuration changes are properly accounted for.
1986 (void) pool_list_iter(list
, B_FALSE
, refresh_iostat
, &cb
);
1989 * Iterate over all pools to determine the maximum width
1990 * for the pool / device name column across all pools.
1992 cb
.cb_namewidth
= 0;
1993 (void) pool_list_iter(list
, B_FALSE
, get_namewidth
, &cb
);
1996 * If it's the first time, or verbose mode, print the header.
1998 if (++cb
.cb_iteration
== 1 || verbose
)
1999 print_iostat_header(&cb
);
2001 (void) pool_list_iter(list
, B_FALSE
, print_iostat
, &cb
);
2004 * If there's more than one pool, and we're not in verbose mode
2005 * (which prints a separator for us), then print a separator.
2007 if (npools
> 1 && !verbose
)
2008 print_iostat_separator(&cb
);
2011 (void) printf("\n");
2014 * Flush the output so that redirection to a file isn't buffered
2017 (void) fflush(stdout
);
2022 if (count
!= 0 && --count
== 0)
2025 (void) sleep(interval
);
2028 pool_list_free(list
);
2033 typedef struct list_cbdata
{
2034 boolean_t cb_scripted
;
2036 zprop_list_t
*cb_proplist
;
2040 * Given a list of columns to display, output appropriate headers for each one.
2043 print_header(zprop_list_t
*pl
)
2046 boolean_t first
= B_TRUE
;
2047 boolean_t right_justify
;
2049 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
2050 if (pl
->pl_prop
== ZPROP_INVAL
)
2058 header
= zpool_prop_column_name(pl
->pl_prop
);
2059 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
2061 if (pl
->pl_next
== NULL
&& !right_justify
)
2062 (void) printf("%s", header
);
2063 else if (right_justify
)
2064 (void) printf("%*s", pl
->pl_width
, header
);
2066 (void) printf("%-*s", pl
->pl_width
, header
);
2069 (void) printf("\n");
2073 * Given a pool and a list of properties, print out all the properties according
2074 * to the described layout.
2077 print_pool(zpool_handle_t
*zhp
, zprop_list_t
*pl
, int scripted
)
2079 boolean_t first
= B_TRUE
;
2080 char property
[ZPOOL_MAXPROPLEN
];
2082 boolean_t right_justify
;
2085 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
2088 (void) printf("\t");
2095 right_justify
= B_FALSE
;
2096 if (pl
->pl_prop
!= ZPROP_INVAL
) {
2097 if (zpool_get_prop(zhp
, pl
->pl_prop
, property
,
2098 sizeof (property
), NULL
) != 0)
2103 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
2108 width
= pl
->pl_width
;
2111 * If this is being called in scripted mode, or if this is the
2112 * last column and it is left-justified, don't include a width
2115 if (scripted
|| (pl
->pl_next
== NULL
&& !right_justify
))
2116 (void) printf("%s", propstr
);
2117 else if (right_justify
)
2118 (void) printf("%*s", width
, propstr
);
2120 (void) printf("%-*s", width
, propstr
);
2123 (void) printf("\n");
2127 * Generic callback function to list a pool.
2130 list_callback(zpool_handle_t
*zhp
, void *data
)
2132 list_cbdata_t
*cbp
= data
;
2134 if (cbp
->cb_first
) {
2135 if (!cbp
->cb_scripted
)
2136 print_header(cbp
->cb_proplist
);
2137 cbp
->cb_first
= B_FALSE
;
2140 print_pool(zhp
, cbp
->cb_proplist
, cbp
->cb_scripted
);
2146 * zpool list [-H] [-o prop[,prop]*] [pool] ...
2148 * -H Scripted mode. Don't display headers, and separate properties
2150 * -o List of properties to display. Defaults to
2151 * "name,size,used,available,capacity,health,altroot"
2153 * List all pools in the system, whether or not they're healthy. Output space
2154 * statistics for each one, as well as health status summary.
2157 zpool_do_list(int argc
, char **argv
)
2161 list_cbdata_t cb
= { 0 };
2162 static char default_props
[] =
2163 "name,size,used,available,capacity,health,altroot";
2164 char *props
= default_props
;
2167 while ((c
= getopt(argc
, argv
, ":Ho:")) != -1) {
2170 cb
.cb_scripted
= B_TRUE
;
2176 (void) fprintf(stderr
, gettext("missing argument for "
2177 "'%c' option\n"), optopt
);
2181 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2190 if (zprop_get_list(g_zfs
, props
, &cb
.cb_proplist
, ZFS_TYPE_POOL
) != 0)
2193 cb
.cb_first
= B_TRUE
;
2195 ret
= for_each_pool(argc
, argv
, B_TRUE
, &cb
.cb_proplist
,
2196 list_callback
, &cb
);
2198 zprop_free_list(cb
.cb_proplist
);
2200 if (argc
== 0 && cb
.cb_first
&& !cb
.cb_scripted
) {
2201 (void) printf(gettext("no pools available\n"));
2209 zpool_get_vdev_by_name(nvlist_t
*nv
, char *name
)
2216 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
2217 &child
, &children
) != 0) {
2218 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_PATH
, &path
) == 0);
2219 if (strncmp(name
, "/dev/dsk/", 9) == 0)
2221 if (strncmp(path
, "/dev/dsk/", 9) == 0)
2223 if (strcmp(name
, path
) == 0)
2228 for (c
= 0; c
< children
; c
++)
2229 if ((match
= zpool_get_vdev_by_name(child
[c
], name
)) != NULL
)
2236 zpool_do_attach_or_replace(int argc
, char **argv
, int replacing
)
2238 boolean_t force
= B_FALSE
;
2241 char *poolname
, *old_disk
, *new_disk
;
2242 zpool_handle_t
*zhp
;
2246 while ((c
= getopt(argc
, argv
, "f")) != -1) {
2252 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2261 /* get pool name and check number of arguments */
2263 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
2270 (void) fprintf(stderr
,
2271 gettext("missing <device> specification\n"));
2279 (void) fprintf(stderr
,
2280 gettext("missing <new_device> specification\n"));
2283 new_disk
= old_disk
;
2293 (void) fprintf(stderr
, gettext("too many arguments\n"));
2297 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
2300 if (zpool_get_config(zhp
, NULL
) == NULL
) {
2301 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
2307 nvroot
= make_root_vdev(zhp
, force
, B_FALSE
, replacing
, B_FALSE
,
2309 if (nvroot
== NULL
) {
2314 ret
= zpool_vdev_attach(zhp
, old_disk
, new_disk
, nvroot
, replacing
);
2316 nvlist_free(nvroot
);
2323 * zpool replace [-f] <pool> <device> <new_device>
2325 * -f Force attach, even if <new_device> appears to be in use.
2327 * Replace <device> with <new_device>.
2331 zpool_do_replace(int argc
, char **argv
)
2333 return (zpool_do_attach_or_replace(argc
, argv
, B_TRUE
));
2337 * zpool attach [-f] <pool> <device> <new_device>
2339 * -f Force attach, even if <new_device> appears to be in use.
2341 * Attach <new_device> to the mirror containing <device>. If <device> is not
2342 * part of a mirror, then <device> will be transformed into a mirror of
2343 * <device> and <new_device>. In either case, <new_device> will begin life
2344 * with a DTL of [0, now], and will immediately begin to resilver itself.
2347 zpool_do_attach(int argc
, char **argv
)
2349 return (zpool_do_attach_or_replace(argc
, argv
, B_FALSE
));
2353 * zpool detach [-f] <pool> <device>
2355 * -f Force detach of <device>, even if DTLs argue against it
2356 * (not supported yet)
2358 * Detach a device from a mirror. The operation will be refused if <device>
2359 * is the last device in the mirror, or if the DTLs indicate that this device
2360 * has the only valid copy of some data.
2364 zpool_do_detach(int argc
, char **argv
)
2367 char *poolname
, *path
;
2368 zpool_handle_t
*zhp
;
2372 while ((c
= getopt(argc
, argv
, "f")) != -1) {
2376 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2385 /* get pool name and check number of arguments */
2387 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
2392 (void) fprintf(stderr
,
2393 gettext("missing <device> specification\n"));
2400 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
2403 ret
= zpool_vdev_detach(zhp
, path
);
2411 * zpool online <pool> <device> ...
2414 zpool_do_online(int argc
, char **argv
)
2418 zpool_handle_t
*zhp
;
2420 vdev_state_t newstate
;
2423 while ((c
= getopt(argc
, argv
, "t")) != -1) {
2427 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2436 /* get pool name and check number of arguments */
2438 (void) fprintf(stderr
, gettext("missing pool name\n"));
2442 (void) fprintf(stderr
, gettext("missing device name\n"));
2448 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
2451 for (i
= 1; i
< argc
; i
++) {
2452 if (zpool_vdev_online(zhp
, argv
[i
], 0, &newstate
) == 0) {
2453 if (newstate
!= VDEV_STATE_HEALTHY
) {
2454 (void) printf(gettext("warning: device '%s' "
2455 "onlined, but remains in faulted state\n"),
2457 if (newstate
== VDEV_STATE_FAULTED
)
2458 (void) printf(gettext("use 'zpool "
2459 "clear' to restore a faulted "
2462 (void) printf(gettext("use 'zpool "
2463 "replace' to replace devices "
2464 "that are no longer present\n"));
2477 * zpool offline [-ft] <pool> <device> ...
2479 * -f Force the device into the offline state, even if doing
2480 * so would appear to compromise pool availability.
2481 * (not supported yet)
2483 * -t Only take the device off-line temporarily. The offline
2484 * state will not be persistent across reboots.
2488 zpool_do_offline(int argc
, char **argv
)
2492 zpool_handle_t
*zhp
;
2494 boolean_t istmp
= B_FALSE
;
2497 while ((c
= getopt(argc
, argv
, "ft")) != -1) {
2504 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2513 /* get pool name and check number of arguments */
2515 (void) fprintf(stderr
, gettext("missing pool name\n"));
2519 (void) fprintf(stderr
, gettext("missing device name\n"));
2525 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
2528 for (i
= 1; i
< argc
; i
++) {
2529 if (zpool_vdev_offline(zhp
, argv
[i
], istmp
) != 0)
2539 * zpool clear <pool> [device]
2541 * Clear all errors associated with a pool or a particular device.
2544 zpool_do_clear(int argc
, char **argv
)
2547 zpool_handle_t
*zhp
;
2548 char *pool
, *device
;
2551 (void) fprintf(stderr
, gettext("missing pool name\n"));
2556 (void) fprintf(stderr
, gettext("too many arguments\n"));
2561 device
= argc
== 3 ? argv
[2] : NULL
;
2563 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
)
2566 if (zpool_clear(zhp
, device
) != 0)
2574 typedef struct scrub_cbdata
{
2581 scrub_callback(zpool_handle_t
*zhp
, void *data
)
2583 scrub_cbdata_t
*cb
= data
;
2587 * Ignore faulted pools.
2589 if (zpool_get_state(zhp
) == POOL_STATE_UNAVAIL
) {
2590 (void) fprintf(stderr
, gettext("cannot scrub '%s': pool is "
2591 "currently unavailable\n"), zpool_get_name(zhp
));
2595 err
= zpool_scrub(zhp
, cb
->cb_type
);
2601 * zpool scrub [-s] <pool> ...
2603 * -s Stop. Stops any in-progress scrub.
2606 zpool_do_scrub(int argc
, char **argv
)
2611 cb
.cb_type
= POOL_SCRUB_EVERYTHING
;
2614 while ((c
= getopt(argc
, argv
, "s")) != -1) {
2617 cb
.cb_type
= POOL_SCRUB_NONE
;
2620 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2632 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
2636 return (for_each_pool(argc
, argv
, B_TRUE
, NULL
, scrub_callback
, &cb
));
2639 typedef struct status_cbdata
{
2641 boolean_t cb_allpools
;
2642 boolean_t cb_verbose
;
2643 boolean_t cb_explain
;
2648 * Print out detailed scrub status.
2651 print_scrub_status(nvlist_t
*nvroot
)
2655 time_t start
, end
, now
;
2656 double fraction_done
;
2657 uint64_t examined
, total
, minutes_left
, minutes_taken
;
2660 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_STATS
,
2661 (uint64_t **)&vs
, &vsc
) == 0);
2664 * If there's never been a scrub, there's not much to say.
2666 if (vs
->vs_scrub_end
== 0 && vs
->vs_scrub_type
== POOL_SCRUB_NONE
) {
2667 (void) printf(gettext("none requested\n"));
2671 scrub_type
= (vs
->vs_scrub_type
== POOL_SCRUB_RESILVER
) ?
2672 "resilver" : "scrub";
2674 start
= vs
->vs_scrub_start
;
2675 end
= vs
->vs_scrub_end
;
2677 examined
= vs
->vs_scrub_examined
;
2678 total
= vs
->vs_alloc
;
2681 minutes_taken
= (uint64_t)((end
- start
) / 60);
2683 (void) printf(gettext("%s %s after %lluh%um with %llu errors "
2685 scrub_type
, vs
->vs_scrub_complete
? "completed" : "stopped",
2686 (u_longlong_t
)(minutes_taken
/ 60),
2687 (uint_t
)(minutes_taken
% 60),
2688 (u_longlong_t
)vs
->vs_scrub_errors
, ctime(&end
));
2694 if (examined
> total
)
2697 fraction_done
= (double)examined
/ total
;
2698 minutes_left
= (uint64_t)((now
- start
) *
2699 (1 - fraction_done
) / fraction_done
/ 60);
2700 minutes_taken
= (uint64_t)((now
- start
) / 60);
2702 (void) printf(gettext("%s in progress for %lluh%um, %.2f%% done, "
2703 "%lluh%um to go\n"),
2704 scrub_type
, (u_longlong_t
)(minutes_taken
/ 60),
2705 (uint_t
)(minutes_taken
% 60), 100 * fraction_done
,
2706 (u_longlong_t
)(minutes_left
/ 60), (uint_t
)(minutes_left
% 60));
2709 typedef struct spare_cbdata
{
2711 zpool_handle_t
*cb_zhp
;
2715 find_vdev(nvlist_t
*nv
, uint64_t search
)
2721 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
, &guid
) == 0 &&
2725 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
2726 &child
, &children
) == 0) {
2727 for (c
= 0; c
< children
; c
++)
2728 if (find_vdev(child
[c
], search
))
2736 find_spare(zpool_handle_t
*zhp
, void *data
)
2738 spare_cbdata_t
*cbp
= data
;
2739 nvlist_t
*config
, *nvroot
;
2741 config
= zpool_get_config(zhp
, NULL
);
2742 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
2745 if (find_vdev(nvroot
, cbp
->cb_guid
)) {
2755 * Print out configuration state as requested by status_callback.
2758 print_status_config(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
,
2759 int namewidth
, int depth
, boolean_t isspare
, boolean_t print_logs
)
2764 char rbuf
[6], wbuf
[6], cbuf
[6], repaired
[7];
2766 uint64_t notpresent
;
2770 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_STATS
,
2771 (uint64_t **)&vs
, &c
) == 0);
2773 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
2774 &child
, &children
) != 0)
2777 state
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
2780 * For hot spares, we use the terms 'INUSE' and 'AVAILABLE' for
2783 if (vs
->vs_aux
== VDEV_AUX_SPARED
)
2785 else if (vs
->vs_state
== VDEV_STATE_HEALTHY
)
2789 (void) printf("\t%*s%-*s %-8s", depth
, "", namewidth
- depth
,
2793 zfs_nicenum(vs
->vs_read_errors
, rbuf
, sizeof (rbuf
));
2794 zfs_nicenum(vs
->vs_write_errors
, wbuf
, sizeof (wbuf
));
2795 zfs_nicenum(vs
->vs_checksum_errors
, cbuf
, sizeof (cbuf
));
2796 (void) printf(" %5s %5s %5s", rbuf
, wbuf
, cbuf
);
2799 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_NOT_PRESENT
,
2800 ¬present
) == 0) {
2802 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_PATH
, &path
) == 0);
2803 (void) printf(" was %s", path
);
2804 } else if (vs
->vs_aux
!= 0) {
2807 switch (vs
->vs_aux
) {
2808 case VDEV_AUX_OPEN_FAILED
:
2809 (void) printf(gettext("cannot open"));
2812 case VDEV_AUX_BAD_GUID_SUM
:
2813 (void) printf(gettext("missing device"));
2816 case VDEV_AUX_NO_REPLICAS
:
2817 (void) printf(gettext("insufficient replicas"));
2820 case VDEV_AUX_VERSION_NEWER
:
2821 (void) printf(gettext("newer version"));
2824 case VDEV_AUX_SPARED
:
2825 verify(nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
,
2827 if (zpool_iter(g_zfs
, find_spare
, &cb
) == 1) {
2828 if (strcmp(zpool_get_name(cb
.cb_zhp
),
2829 zpool_get_name(zhp
)) == 0)
2830 (void) printf(gettext("currently in "
2833 (void) printf(gettext("in use by "
2835 zpool_get_name(cb
.cb_zhp
));
2836 zpool_close(cb
.cb_zhp
);
2838 (void) printf(gettext("currently in use"));
2842 case VDEV_AUX_ERR_EXCEEDED
:
2843 (void) printf(gettext("too many errors"));
2846 case VDEV_AUX_IO_FAILURE
:
2847 (void) printf(gettext("experienced I/O failures"));
2850 case VDEV_AUX_BAD_LOG
:
2851 (void) printf(gettext("bad intent log"));
2855 (void) printf(gettext("corrupted data"));
2858 } else if (vs
->vs_scrub_repaired
!= 0 && children
== 0) {
2860 * Report bytes resilvered/repaired on leaf devices.
2862 zfs_nicenum(vs
->vs_scrub_repaired
, repaired
, sizeof (repaired
));
2863 (void) printf(gettext(" %s %s"), repaired
,
2864 (vs
->vs_scrub_type
== POOL_SCRUB_RESILVER
) ?
2865 "resilvered" : "repaired");
2868 (void) printf("\n");
2870 for (c
= 0; c
< children
; c
++) {
2871 uint64_t is_log
= B_FALSE
;
2873 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
2875 if ((is_log
&& !print_logs
) || (!is_log
&& print_logs
))
2877 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
]);
2878 print_status_config(zhp
, vname
, child
[c
],
2879 namewidth
, depth
+ 2, isspare
, B_FALSE
);
2885 print_error_log(zpool_handle_t
*zhp
)
2887 nvlist_t
*nverrlist
= NULL
;
2890 size_t len
= MAXPATHLEN
* 2;
2892 if (zpool_get_errlog(zhp
, &nverrlist
) != 0) {
2893 (void) printf("errors: List of errors unavailable "
2894 "(insufficient privileges)\n");
2898 (void) printf("errors: Permanent errors have been "
2899 "detected in the following files:\n\n");
2901 pathname
= safe_malloc(len
);
2903 while ((elem
= nvlist_next_nvpair(nverrlist
, elem
)) != NULL
) {
2905 uint64_t dsobj
, obj
;
2907 verify(nvpair_value_nvlist(elem
, &nv
) == 0);
2908 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_DATASET
,
2910 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_OBJECT
,
2912 zpool_obj_to_path(zhp
, dsobj
, obj
, pathname
, len
);
2913 (void) printf("%7s %s\n", "", pathname
);
2916 nvlist_free(nverrlist
);
2920 print_spares(zpool_handle_t
*zhp
, nvlist_t
**spares
, uint_t nspares
,
2929 (void) printf(gettext("\tspares\n"));
2931 for (i
= 0; i
< nspares
; i
++) {
2932 name
= zpool_vdev_name(g_zfs
, zhp
, spares
[i
]);
2933 print_status_config(zhp
, name
, spares
[i
],
2934 namewidth
, 2, B_TRUE
, B_FALSE
);
2940 print_l2cache(zpool_handle_t
*zhp
, nvlist_t
**l2cache
, uint_t nl2cache
,
2949 (void) printf(gettext("\tcache\n"));
2951 for (i
= 0; i
< nl2cache
; i
++) {
2952 name
= zpool_vdev_name(g_zfs
, zhp
, l2cache
[i
]);
2953 print_status_config(zhp
, name
, l2cache
[i
],
2954 namewidth
, 2, B_FALSE
, B_FALSE
);
2960 * Display a summary of pool status. Displays a summary such as:
2964 * reason: One or more devices ...
2965 * see: http://www.sun.com/msg/ZFS-xxxx-01
2971 * When given the '-v' option, we print out the complete config. If the '-e'
2972 * option is specified, then we print out error rate information as well.
2975 status_callback(zpool_handle_t
*zhp
, void *data
)
2977 status_cbdata_t
*cbp
= data
;
2978 nvlist_t
*config
, *nvroot
;
2985 config
= zpool_get_config(zhp
, NULL
);
2986 reason
= zpool_get_status(zhp
, &msgid
);
2991 * If we were given 'zpool status -x', only report those pools with
2994 if (reason
== ZPOOL_STATUS_OK
&& cbp
->cb_explain
) {
2995 if (!cbp
->cb_allpools
) {
2996 (void) printf(gettext("pool '%s' is healthy\n"),
2997 zpool_get_name(zhp
));
2999 cbp
->cb_first
= B_FALSE
;
3005 cbp
->cb_first
= B_FALSE
;
3007 (void) printf("\n");
3009 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
3011 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_STATS
,
3012 (uint64_t **)&vs
, &c
) == 0);
3013 health
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
3015 (void) printf(gettext(" pool: %s\n"), zpool_get_name(zhp
));
3016 (void) printf(gettext(" state: %s\n"), health
);
3019 case ZPOOL_STATUS_MISSING_DEV_R
:
3020 (void) printf(gettext("status: One or more devices could not "
3021 "be opened. Sufficient replicas exist for\n\tthe pool to "
3022 "continue functioning in a degraded state.\n"));
3023 (void) printf(gettext("action: Attach the missing device and "
3024 "online it using 'zpool online'.\n"));
3027 case ZPOOL_STATUS_MISSING_DEV_NR
:
3028 (void) printf(gettext("status: One or more devices could not "
3029 "be opened. There are insufficient\n\treplicas for the "
3030 "pool to continue functioning.\n"));
3031 (void) printf(gettext("action: Attach the missing device and "
3032 "online it using 'zpool online'.\n"));
3035 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
3036 (void) printf(gettext("status: One or more devices could not "
3037 "be used because the label is missing or\n\tinvalid. "
3038 "Sufficient replicas exist for the pool to continue\n\t"
3039 "functioning in a degraded state.\n"));
3040 (void) printf(gettext("action: Replace the device using "
3041 "'zpool replace'.\n"));
3044 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
3045 (void) printf(gettext("status: One or more devices could not "
3046 "be used because the label is missing \n\tor invalid. "
3047 "There are insufficient replicas for the pool to "
3048 "continue\n\tfunctioning.\n"));
3049 (void) printf(gettext("action: Destroy and re-create the pool "
3050 "from a backup source.\n"));
3053 case ZPOOL_STATUS_FAILING_DEV
:
3054 (void) printf(gettext("status: One or more devices has "
3055 "experienced an unrecoverable error. An\n\tattempt was "
3056 "made to correct the error. Applications are "
3058 (void) printf(gettext("action: Determine if the device needs "
3059 "to be replaced, and clear the errors\n\tusing "
3060 "'zpool clear' or replace the device with 'zpool "
3064 case ZPOOL_STATUS_OFFLINE_DEV
:
3065 (void) printf(gettext("status: One or more devices has "
3066 "been taken offline by the administrator.\n\tSufficient "
3067 "replicas exist for the pool to continue functioning in "
3068 "a\n\tdegraded state.\n"));
3069 (void) printf(gettext("action: Online the device using "
3070 "'zpool online' or replace the device with\n\t'zpool "
3074 case ZPOOL_STATUS_RESILVERING
:
3075 (void) printf(gettext("status: One or more devices is "
3076 "currently being resilvered. The pool will\n\tcontinue "
3077 "to function, possibly in a degraded state.\n"));
3078 (void) printf(gettext("action: Wait for the resilver to "
3082 case ZPOOL_STATUS_CORRUPT_DATA
:
3083 (void) printf(gettext("status: One or more devices has "
3084 "experienced an error resulting in data\n\tcorruption. "
3085 "Applications may be affected.\n"));
3086 (void) printf(gettext("action: Restore the file in question "
3087 "if possible. Otherwise restore the\n\tentire pool from "
3091 case ZPOOL_STATUS_CORRUPT_POOL
:
3092 (void) printf(gettext("status: The pool metadata is corrupted "
3093 "and the pool cannot be opened.\n"));
3094 (void) printf(gettext("action: Destroy and re-create the pool "
3095 "from a backup source.\n"));
3098 case ZPOOL_STATUS_VERSION_OLDER
:
3099 (void) printf(gettext("status: The pool is formatted using an "
3100 "older on-disk format. The pool can\n\tstill be used, but "
3101 "some features are unavailable.\n"));
3102 (void) printf(gettext("action: Upgrade the pool using 'zpool "
3103 "upgrade'. Once this is done, the\n\tpool will no longer "
3104 "be accessible on older software versions.\n"));
3107 case ZPOOL_STATUS_VERSION_NEWER
:
3108 (void) printf(gettext("status: The pool has been upgraded to a "
3109 "newer, incompatible on-disk version.\n\tThe pool cannot "
3110 "be accessed on this system.\n"));
3111 (void) printf(gettext("action: Access the pool from a system "
3112 "running more recent software, or\n\trestore the pool from "
3116 case ZPOOL_STATUS_FAULTED_DEV_R
:
3117 (void) printf(gettext("status: One or more devices are "
3118 "faulted in response to persistent errors.\n\tSufficient "
3119 "replicas exist for the pool to continue functioning "
3120 "in a\n\tdegraded state.\n"));
3121 (void) printf(gettext("action: Replace the faulted device, "
3122 "or use 'zpool clear' to mark the device\n\trepaired.\n"));
3125 case ZPOOL_STATUS_FAULTED_DEV_NR
:
3126 (void) printf(gettext("status: One or more devices are "
3127 "faulted in response to persistent errors. There are "
3128 "insufficient replicas for the pool to\n\tcontinue "
3130 (void) printf(gettext("action: Destroy and re-create the pool "
3131 "from a backup source. Manually marking the device\n"
3132 "\trepaired using 'zpool clear' may allow some data "
3133 "to be recovered.\n"));
3136 case ZPOOL_STATUS_IO_FAILURE_WAIT
:
3137 case ZPOOL_STATUS_IO_FAILURE_CONTINUE
:
3138 (void) printf(gettext("status: One or more devices are "
3139 "faulted in response to IO failures.\n"));
3140 (void) printf(gettext("action: Make sure the affected devices "
3141 "are connected, then run 'zpool clear'.\n"));
3144 case ZPOOL_STATUS_BAD_LOG
:
3145 (void) printf(gettext("status: An intent log record "
3146 "could not be read.\n"
3147 "\tWaiting for adminstrator intervention to fix the "
3148 "faulted pool.\n"));
3149 (void) printf(gettext("action: Either restore the affected "
3150 "device(s) and run 'zpool online',\n"
3151 "\tor ignore the intent log records by running "
3152 "'zpool clear'.\n"));
3157 * The remaining errors can't actually be generated, yet.
3159 assert(reason
== ZPOOL_STATUS_OK
);
3163 (void) printf(gettext(" see: http://www.sun.com/msg/%s\n"),
3166 if (config
!= NULL
) {
3169 nvlist_t
**spares
, **l2cache
;
3170 uint_t nspares
, nl2cache
;
3173 (void) printf(gettext(" scrub: "));
3174 print_scrub_status(nvroot
);
3176 namewidth
= max_width(zhp
, nvroot
, 0, 0);
3180 (void) printf(gettext("config:\n\n"));
3181 (void) printf(gettext("\t%-*s %-8s %5s %5s %5s\n"), namewidth
,
3182 "NAME", "STATE", "READ", "WRITE", "CKSUM");
3183 print_status_config(zhp
, zpool_get_name(zhp
), nvroot
,
3184 namewidth
, 0, B_FALSE
, B_FALSE
);
3185 if (num_logs(nvroot
) > 0)
3186 print_status_config(zhp
, "logs", nvroot
, namewidth
, 0,
3189 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_L2CACHE
,
3190 &l2cache
, &nl2cache
) == 0)
3191 print_l2cache(zhp
, l2cache
, nl2cache
, namewidth
);
3193 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_SPARES
,
3194 &spares
, &nspares
) == 0)
3195 print_spares(zhp
, spares
, nspares
, namewidth
);
3197 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_ERRCOUNT
,
3199 nvlist_t
*nverrlist
= NULL
;
3202 * If the approximate error count is small, get a
3203 * precise count by fetching the entire log and
3204 * uniquifying the results.
3206 if (nerr
> 0 && nerr
< 100 && !cbp
->cb_verbose
&&
3207 zpool_get_errlog(zhp
, &nverrlist
) == 0) {
3212 while ((elem
= nvlist_next_nvpair(nverrlist
,
3217 nvlist_free(nverrlist
);
3219 (void) printf("\n");
3222 (void) printf(gettext("errors: No known data "
3224 else if (!cbp
->cb_verbose
)
3225 (void) printf(gettext("errors: %llu data "
3226 "errors, use '-v' for a list\n"),
3227 (u_longlong_t
)nerr
);
3229 print_error_log(zhp
);
3232 (void) printf(gettext("config: The configuration cannot be "
3240 * zpool status [-vx] [pool] ...
3242 * -v Display complete error logs
3243 * -x Display only pools with potential problems
3245 * Describes the health status of all pools or some subset.
3248 zpool_do_status(int argc
, char **argv
)
3252 status_cbdata_t cb
= { 0 };
3255 while ((c
= getopt(argc
, argv
, "vx")) != -1) {
3258 cb
.cb_verbose
= B_TRUE
;
3261 cb
.cb_explain
= B_TRUE
;
3264 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3273 cb
.cb_first
= B_TRUE
;
3276 cb
.cb_allpools
= B_TRUE
;
3278 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
, status_callback
, &cb
);
3280 if (argc
== 0 && cb
.cb_count
== 0)
3281 (void) printf(gettext("no pools available\n"));
3282 else if (cb
.cb_explain
&& cb
.cb_first
&& cb
.cb_allpools
)
3283 (void) printf(gettext("all pools are healthy\n"));
3288 typedef struct upgrade_cbdata
{
3293 uint64_t cb_version
;
3298 upgrade_cb(zpool_handle_t
*zhp
, void *arg
)
3300 upgrade_cbdata_t
*cbp
= arg
;
3305 config
= zpool_get_config(zhp
, NULL
);
3306 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
3309 if (!cbp
->cb_newer
&& version
< SPA_VERSION
) {
3311 if (cbp
->cb_first
) {
3312 (void) printf(gettext("The following pools are "
3313 "out of date, and can be upgraded. After "
3314 "being\nupgraded, these pools will no "
3315 "longer be accessible by older software "
3317 (void) printf(gettext("VER POOL\n"));
3318 (void) printf(gettext("--- ------------\n"));
3319 cbp
->cb_first
= B_FALSE
;
3322 (void) printf("%2llu %s\n", (u_longlong_t
)version
,
3323 zpool_get_name(zhp
));
3325 cbp
->cb_first
= B_FALSE
;
3326 ret
= zpool_upgrade(zhp
, cbp
->cb_version
);
3328 (void) printf(gettext("Successfully upgraded "
3329 "'%s'\n\n"), zpool_get_name(zhp
));
3332 } else if (cbp
->cb_newer
&& version
> SPA_VERSION
) {
3333 assert(!cbp
->cb_all
);
3335 if (cbp
->cb_first
) {
3336 (void) printf(gettext("The following pools are "
3337 "formatted using a newer software version and\n"
3338 "cannot be accessed on the current system.\n\n"));
3339 (void) printf(gettext("VER POOL\n"));
3340 (void) printf(gettext("--- ------------\n"));
3341 cbp
->cb_first
= B_FALSE
;
3344 (void) printf("%2llu %s\n", (u_longlong_t
)version
,
3345 zpool_get_name(zhp
));
3354 upgrade_one(zpool_handle_t
*zhp
, void *data
)
3356 upgrade_cbdata_t
*cbp
= data
;
3357 uint64_t cur_version
;
3360 if (strcmp("log", zpool_get_name(zhp
)) == 0) {
3361 (void) printf(gettext("'log' is now a reserved word\n"
3362 "Pool 'log' must be renamed using export and import"
3367 cur_version
= zpool_get_prop_int(zhp
, ZPOOL_PROP_VERSION
, NULL
);
3368 if (cur_version
> cbp
->cb_version
) {
3369 (void) printf(gettext("Pool '%s' is already formatted "
3370 "using more current version '%llu'.\n"),
3371 zpool_get_name(zhp
), cur_version
);
3374 if (cur_version
== cbp
->cb_version
) {
3375 (void) printf(gettext("Pool '%s' is already formatted "
3376 "using the current version.\n"), zpool_get_name(zhp
));
3380 ret
= zpool_upgrade(zhp
, cbp
->cb_version
);
3383 (void) printf(gettext("Successfully upgraded '%s' "
3384 "from version %llu to version %llu\n\n"),
3385 zpool_get_name(zhp
), (u_longlong_t
)cur_version
,
3386 (u_longlong_t
)cbp
->cb_version
);
3395 * zpool upgrade [-V version] <-a | pool ...>
3397 * With no arguments, display downrev'd ZFS pool available for upgrade.
3398 * Individual pools can be upgraded by specifying the pool, and '-a' will
3399 * upgrade all pools.
3402 zpool_do_upgrade(int argc
, char **argv
)
3405 upgrade_cbdata_t cb
= { 0 };
3407 boolean_t showversions
= B_FALSE
;
3412 while ((c
= getopt(argc
, argv
, "avV:")) != -1) {
3418 showversions
= B_TRUE
;
3421 cb
.cb_version
= strtoll(optarg
, &end
, 10);
3422 if (*end
!= '\0' || cb
.cb_version
> SPA_VERSION
||
3423 cb
.cb_version
< SPA_VERSION_1
) {
3424 (void) fprintf(stderr
,
3425 gettext("invalid version '%s'\n"), optarg
);
3430 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3441 if (cb
.cb_version
== 0) {
3442 cb
.cb_version
= SPA_VERSION
;
3443 } else if (!cb
.cb_all
&& argc
== 0) {
3444 (void) fprintf(stderr
, gettext("-V option is "
3445 "incompatible with other arguments\n"));
3450 if (cb
.cb_all
|| argc
!= 0) {
3451 (void) fprintf(stderr
, gettext("-v option is "
3452 "incompatible with other arguments\n"));
3455 } else if (cb
.cb_all
) {
3457 (void) fprintf(stderr
, gettext("-a option should not "
3458 "be used along with a pool name\n"));
3463 (void) printf(gettext("This system is currently running "
3464 "ZFS pool version %llu.\n\n"), SPA_VERSION
);
3465 cb
.cb_first
= B_TRUE
;
3467 (void) printf(gettext("The following versions are "
3469 (void) printf(gettext("VER DESCRIPTION\n"));
3470 (void) printf("--- -----------------------------------------"
3471 "---------------\n");
3472 (void) printf(gettext(" 1 Initial ZFS version\n"));
3473 (void) printf(gettext(" 2 Ditto blocks "
3474 "(replicated metadata)\n"));
3475 (void) printf(gettext(" 3 Hot spares and double parity "
3477 (void) printf(gettext(" 4 zpool history\n"));
3478 (void) printf(gettext(" 5 Compression using the gzip "
3480 (void) printf(gettext(" 6 bootfs pool property\n"));
3481 (void) printf(gettext(" 7 Separate intent log devices\n"));
3482 (void) printf(gettext(" 8 Delegated administration\n"));
3483 (void) printf(gettext(" 9 refquota and refreservation "
3485 (void) printf(gettext(" 10 Cache devices\n"));
3486 (void) printf(gettext(" 11 Improved scrub performance\n"));
3487 (void) printf(gettext(" 12 Snapshot properties\n"));
3488 (void) printf(gettext(" 13 snapused property\n"));
3489 (void) printf(gettext(" 14 passthrough-x aclinherit "
3491 (void) printf(gettext("For more information on a particular "
3492 "version, including supported releases, see:\n\n"));
3493 (void) printf("http://www.opensolaris.org/os/community/zfs/"
3495 (void) printf(gettext("Where 'N' is the version number.\n"));
3496 } else if (argc
== 0) {
3499 ret
= zpool_iter(g_zfs
, upgrade_cb
, &cb
);
3500 notfound
= cb
.cb_first
;
3502 if (!cb
.cb_all
&& ret
== 0) {
3504 (void) printf("\n");
3505 cb
.cb_first
= B_TRUE
;
3506 cb
.cb_newer
= B_TRUE
;
3507 ret
= zpool_iter(g_zfs
, upgrade_cb
, &cb
);
3510 (void) printf("\n");
3516 (void) printf(gettext("All pools are formatted "
3517 "using this version.\n"));
3518 else if (!cb
.cb_all
)
3519 (void) printf(gettext("Use 'zpool upgrade -v' "
3520 "for a list of available versions and "
3521 "their associated\nfeatures.\n"));
3524 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
,
3531 typedef struct hist_cbdata
{
3537 char *hist_event_table
[LOG_END
] = {
3553 "pool property set",
3557 "destroy_begin_sync",
3561 "permission update",
3562 "permission remove",
3563 "permission who remove",
3572 "filesystem version upgrade",
3574 "refreservation set",
3579 * Print out the command history for a specific pool.
3582 get_history_one(zpool_handle_t
*zhp
, void *data
)
3598 char internalstr
[MAXPATHLEN
];
3599 hist_cbdata_t
*cb
= (hist_cbdata_t
*)data
;
3603 cb
->first
= B_FALSE
;
3605 (void) printf(gettext("History for '%s':\n"), zpool_get_name(zhp
));
3607 if ((ret
= zpool_get_history(zhp
, &nvhis
)) != 0)
3610 verify(nvlist_lookup_nvlist_array(nvhis
, ZPOOL_HIST_RECORD
,
3611 &records
, &numrecords
) == 0);
3612 for (i
= 0; i
< numrecords
; i
++) {
3613 if (nvlist_lookup_uint64(records
[i
], ZPOOL_HIST_TIME
,
3617 /* is it an internal event or a standard event? */
3618 if (nvlist_lookup_string(records
[i
], ZPOOL_HIST_CMD
,
3620 if (cb
->internal
== 0)
3623 if (nvlist_lookup_uint64(records
[i
],
3624 ZPOOL_HIST_INT_EVENT
, &ievent
) != 0)
3626 verify(nvlist_lookup_uint64(records
[i
],
3627 ZPOOL_HIST_TXG
, &txg
) == 0);
3628 verify(nvlist_lookup_string(records
[i
],
3629 ZPOOL_HIST_INT_STR
, &pathstr
) == 0);
3630 if (ievent
>= LOG_END
)
3632 (void) snprintf(internalstr
,
3633 sizeof (internalstr
),
3634 "[internal %s txg:%lld] %s",
3635 hist_event_table
[ievent
], txg
,
3637 cmdstr
= internalstr
;
3640 (void) localtime_r(&tsec
, &t
);
3641 (void) strftime(tbuf
, sizeof (tbuf
), "%F.%T", &t
);
3642 (void) printf("%s %s", tbuf
, cmdstr
);
3645 (void) printf("\n");
3648 (void) printf(" [");
3649 if (nvlist_lookup_uint64(records
[i
],
3650 ZPOOL_HIST_WHO
, &who
) == 0) {
3651 pwd
= getpwuid((uid_t
)who
);
3653 (void) printf("user %s on",
3656 (void) printf("user %d on",
3659 (void) printf(gettext("no info]\n"));
3662 if (nvlist_lookup_string(records
[i
],
3663 ZPOOL_HIST_HOST
, &hostname
) == 0) {
3664 (void) printf(" %s", hostname
);
3666 if (nvlist_lookup_string(records
[i
],
3667 ZPOOL_HIST_ZONE
, &zonename
) == 0) {
3668 (void) printf(":%s", zonename
);
3672 (void) printf("\n");
3674 (void) printf("\n");
3681 * zpool history <pool>
3683 * Displays the history of commands that modified pools.
3688 zpool_do_history(int argc
, char **argv
)
3690 hist_cbdata_t cbdata
= { 0 };
3694 cbdata
.first
= B_TRUE
;
3696 while ((c
= getopt(argc
, argv
, "li")) != -1) {
3702 cbdata
.internal
= 1;
3705 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3713 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
, get_history_one
,
3716 if (argc
== 0 && cbdata
.first
== B_TRUE
) {
3717 (void) printf(gettext("no pools available\n"));
3725 get_callback(zpool_handle_t
*zhp
, void *data
)
3727 zprop_get_cbdata_t
*cbp
= (zprop_get_cbdata_t
*)data
;
3728 char value
[MAXNAMELEN
];
3729 zprop_source_t srctype
;
3732 for (pl
= cbp
->cb_proplist
; pl
!= NULL
; pl
= pl
->pl_next
) {
3735 * Skip the special fake placeholder. This will also skip
3736 * over the name property when 'all' is specified.
3738 if (pl
->pl_prop
== ZPOOL_PROP_NAME
&&
3739 pl
== cbp
->cb_proplist
)
3742 if (zpool_get_prop(zhp
, pl
->pl_prop
,
3743 value
, sizeof (value
), &srctype
) != 0)
3746 zprop_print_one_property(zpool_get_name(zhp
), cbp
,
3747 zpool_prop_to_name(pl
->pl_prop
), value
, srctype
, NULL
);
3753 zpool_do_get(int argc
, char **argv
)
3755 zprop_get_cbdata_t cb
= { 0 };
3756 zprop_list_t fake_name
= { 0 };
3762 cb
.cb_first
= B_TRUE
;
3763 cb
.cb_sources
= ZPROP_SRC_ALL
;
3764 cb
.cb_columns
[0] = GET_COL_NAME
;
3765 cb
.cb_columns
[1] = GET_COL_PROPERTY
;
3766 cb
.cb_columns
[2] = GET_COL_VALUE
;
3767 cb
.cb_columns
[3] = GET_COL_SOURCE
;
3768 cb
.cb_type
= ZFS_TYPE_POOL
;
3770 if (zprop_get_list(g_zfs
, argv
[1], &cb
.cb_proplist
,
3771 ZFS_TYPE_POOL
) != 0)
3774 if (cb
.cb_proplist
!= NULL
) {
3775 fake_name
.pl_prop
= ZPOOL_PROP_NAME
;
3776 fake_name
.pl_width
= strlen(gettext("NAME"));
3777 fake_name
.pl_next
= cb
.cb_proplist
;
3778 cb
.cb_proplist
= &fake_name
;
3781 ret
= for_each_pool(argc
- 2, argv
+ 2, B_TRUE
, &cb
.cb_proplist
,
3784 if (cb
.cb_proplist
== &fake_name
)
3785 zprop_free_list(fake_name
.pl_next
);
3787 zprop_free_list(cb
.cb_proplist
);
3792 typedef struct set_cbdata
{
3795 boolean_t cb_any_successful
;
3799 set_callback(zpool_handle_t
*zhp
, void *data
)
3802 set_cbdata_t
*cb
= (set_cbdata_t
*)data
;
3804 error
= zpool_set_prop(zhp
, cb
->cb_propname
, cb
->cb_value
);
3807 cb
->cb_any_successful
= B_TRUE
;
3813 zpool_do_set(int argc
, char **argv
)
3815 set_cbdata_t cb
= { 0 };
3818 if (argc
> 1 && argv
[1][0] == '-') {
3819 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3825 (void) fprintf(stderr
, gettext("missing property=value "
3831 (void) fprintf(stderr
, gettext("missing pool name\n"));
3836 (void) fprintf(stderr
, gettext("too many pool names\n"));
3840 cb
.cb_propname
= argv
[1];
3841 cb
.cb_value
= strchr(cb
.cb_propname
, '=');
3842 if (cb
.cb_value
== NULL
) {
3843 (void) fprintf(stderr
, gettext("missing value in "
3844 "property=value argument\n"));
3848 *(cb
.cb_value
) = '\0';
3851 error
= for_each_pool(argc
- 2, argv
+ 2, B_TRUE
, NULL
,
3858 find_command_idx(char *command
, int *idx
)
3862 for (i
= 0; i
< NCOMMAND
; i
++) {
3863 if (command_table
[i
].name
== NULL
)
3866 if (strcmp(command
, command_table
[i
].name
) == 0) {
3875 main(int argc
, char **argv
)
3881 (void) setlocale(LC_ALL
, "");
3882 (void) textdomain(TEXT_DOMAIN
);
3884 if ((g_zfs
= libzfs_init()) == NULL
) {
3885 (void) fprintf(stderr
, gettext("internal error: failed to "
3886 "initialize ZFS library\n"));
3890 libzfs_print_on_error(g_zfs
, B_TRUE
);
3895 * Make sure the user has specified some command.
3898 (void) fprintf(stderr
, gettext("missing command\n"));
3907 if (strcmp(cmdname
, "-?") == 0)
3910 zpool_set_history_str("zpool", argc
, argv
, history_str
);
3911 verify(zpool_stage_history(g_zfs
, history_str
) == 0);
3914 * Run the appropriate command.
3916 if (find_command_idx(cmdname
, &i
) == 0) {
3917 current_command
= &command_table
[i
];
3918 ret
= command_table
[i
].func(argc
- 1, argv
+ 1);
3919 } else if (strchr(cmdname
, '=')) {
3920 verify(find_command_idx("set", &i
) == 0);
3921 current_command
= &command_table
[i
];
3922 ret
= command_table
[i
].func(argc
, argv
);
3923 } else if (strcmp(cmdname
, "freeze") == 0 && argc
== 3) {
3925 * 'freeze' is a vile debugging abomination, so we treat
3929 int fd
= open(ZFS_DEV
, O_RDWR
);
3930 (void) strcpy((void *)buf
, argv
[2]);
3931 return (!!ioctl(fd
, ZFS_IOC_POOL_FREEZE
, buf
));
3933 (void) fprintf(stderr
, gettext("unrecognized "
3934 "command '%s'\n"), cmdname
);
3941 * The 'ZFS_ABORT' environment variable causes us to dump core on exit
3942 * for the purposes of running ::findleaks.
3944 if (getenv("ZFS_ABORT") != NULL
) {
3945 (void) printf("dumping core by request\n");