zpool_main.c revision c08432ebe688ed6410b302771a9afd8e23e2a7cc
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
441d80aa4f613b6298fc8bd3151f4be02dbf84fclling * Common Development and Distribution License (the "License").
441d80aa4f613b6298fc8bd3151f4be02dbf84fclling * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Use is subject to license terms.
fa9e4066f08beec538e775443c5be79dd423fcabahrens#pragma ident "%Z%%M% %I% %E% SMI"
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int zpool_do_create(int, char **);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int zpool_do_destroy(int, char **);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int zpool_do_add(int, char **);
99653d4ee642c6528e88224f12409a5f23060994eschrockstatic int zpool_do_remove(int, char **);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int zpool_do_list(int, char **);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int zpool_do_iostat(int, char **);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int zpool_do_status(int, char **);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int zpool_do_online(int, char **);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int zpool_do_offline(int, char **);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockstatic int zpool_do_clear(int, char **);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int zpool_do_attach(int, char **);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int zpool_do_detach(int, char **);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int zpool_do_replace(int, char **);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int zpool_do_scrub(int, char **);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int zpool_do_import(int, char **);
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic int zpool_do_export(int, char **);
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrockstatic int zpool_do_upgrade(int, char **);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * These libumem hooks provide a reasonable set of defaults for the allocator's
fa9e4066f08beec538e775443c5be79dd423fcabahrens * debugging facilities.
fa9e4066f08beec538e775443c5be79dd423fcabahrensconst char *
fa9e4066f08beec538e775443c5be79dd423fcabahrens return ("default,verbose"); /* $UMEM_DEBUG setting */
fa9e4066f08beec538e775443c5be79dd423fcabahrensconst char *
fa9e4066f08beec538e775443c5be79dd423fcabahrens return ("fail,contents"); /* $UMEM_LOGGING setting */
65cd9f2809a015b46790a9c5c2ef992d56177624eschrocktypedef enum {
fa9e4066f08beec538e775443c5be79dd423fcabahrenstypedef struct zpool_command {
fa9e4066f08beec538e775443c5be79dd423fcabahrens const char *name;
fa9e4066f08beec538e775443c5be79dd423fcabahrens int (*func)(int, char **);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Master command table. Each ZFS command has a name, associated function, and
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * usage message. The usage messages need to be internationalized, so we have
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * to have a function to return the usage message based on a command index.
65cd9f2809a015b46790a9c5c2ef992d56177624eschrock * These commands are organized according to how they are displayed in the usage
65cd9f2809a015b46790a9c5c2ef992d56177624eschrock * message. An empty command (one with a NULL name) indicates an empty line in
65cd9f2809a015b46790a9c5c2ef992d56177624eschrock * the generic usage message.
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define NCOMMAND (sizeof (command_table) / sizeof (command_table[0]))
65cd9f2809a015b46790a9c5c2ef992d56177624eschrockstatic const char *
65cd9f2809a015b46790a9c5c2ef992d56177624eschrock return (gettext("\tadd [-fn] <pool> <vdev> ...\n"));
65cd9f2809a015b46790a9c5c2ef992d56177624eschrock "<new_device>\n"));
65cd9f2809a015b46790a9c5c2ef992d56177624eschrock return (gettext("\tcreate [-fn] [-R root] [-m mountpoint] "
65cd9f2809a015b46790a9c5c2ef992d56177624eschrock "<pool> <vdev> ...\n"));
4c58d71403cebfaa40a572ff12b17668ebd56987darrenm "\timport [-d dir] [-D] [-f] [-o opts] [-R root] -a\n"
4c58d71403cebfaa40a572ff12b17668ebd56987darrenm "\timport [-d dir] [-D] [-f] [-o opts] [-R root ]"
4c58d71403cebfaa40a572ff12b17668ebd56987darrenm " <pool | id> [newpool]\n"));
65cd9f2809a015b46790a9c5c2ef992d56177624eschrock return (gettext("\tiostat [-v] [pool] ... [interval "
65cd9f2809a015b46790a9c5c2ef992d56177624eschrock "[count]]\n"));
65cd9f2809a015b46790a9c5c2ef992d56177624eschrock "[pool] ...\n"));
441d80aa4f613b6298fc8bd3151f4be02dbf84fclling return (gettext("\toffline [-t] <pool> <device> ...\n"));
65cd9f2809a015b46790a9c5c2ef992d56177624eschrock "[new_device]\n"));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "\tupgrade -v\n"
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "\tupgrade <-a | pool>\n"));
65cd9f2809a015b46790a9c5c2ef992d56177624eschrock /* NOTREACHED */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Fields available for 'zpool list'.
fa9e4066f08beec538e775443c5be79dd423fcabahrenstypedef enum {
fa9e4066f08beec538e775443c5be79dd423fcabahrenstypedef struct column_def {
fa9e4066f08beec538e775443c5be79dd423fcabahrens const char *cd_title;
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic char *column_subopts[] = {
fa9e4066f08beec538e775443c5be79dd423fcabahrens "available",
fa9e4066f08beec538e775443c5be79dd423fcabahrens "capacity",
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Display usage message. If we're inside a command, display only the usage for
fa9e4066f08beec538e775443c5be79dd423fcabahrens * that command. Otherwise, iterate over the entire command table and display
fa9e4066f08beec538e775443c5be79dd423fcabahrens * a complete usage message.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(fp, gettext("usage: zpool command args ...\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens gettext("where 'command' is one of the following:\n\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (i = 0; i < NCOMMAND; i++) {
65cd9f2809a015b46790a9c5c2ef992d56177624eschrock (void) fprintf(fp, "%s", get_usage(current_command->usage));
fa9e4066f08beec538e775443c5be79dd423fcabahrens "of the following:\n\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrensconst char *
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrockprint_vdev_tree(zpool_handle_t *zhp, const char *name, nvlist_t *nv, int indent)
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
afefbcddfd8caf5f3b2da510d9439471ab225040eschrock for (c = 0; c < children; c++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zpool add [-fn] <pool> <vdev> ...
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -f Force addition of devices, even if they appear in use
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -n Do not add the devices, but display the resulting layout if
fa9e4066f08beec538e775443c5be79dd423fcabahrens * they were to be added.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Adds the given vdevs to 'pool'. As with create, the bulk of this work is
fa9e4066f08beec538e775443c5be79dd423fcabahrens * handled by get_vdev_spec(), which constructs the nvlist needed to pass to
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check options */
fa9e4066f08beec538e775443c5be79dd423fcabahrens switch (c) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("invalid option '%c'\n"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* get pool name and check number of arguments */
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("missing pool name argument\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("missing vdev specification\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
088e9d477eee66081e407fbc5a33c4da25f66f6aeschrock if ((config = zpool_get_config(zhp, NULL)) == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("pool '%s' is unavailable\n"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* pass off to get_vdev_spec for processing */
99653d4ee642c6528e88224f12409a5f23060994eschrock nvroot = make_root_vdev(config, force, !force, B_FALSE, argc, argv);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("would update '%s' to the following "
99653d4ee642c6528e88224f12409a5f23060994eschrock * zpool remove <pool> <vdev>
99653d4ee642c6528e88224f12409a5f23060994eschrock * Removes the given vdev from the pool. Currently, this only supports removing
99653d4ee642c6528e88224f12409a5f23060994eschrock * spares from the pool. Eventually, we'll want to support removing leaf vdevs
99653d4ee642c6528e88224f12409a5f23060994eschrock * (as an alias for 'detach') as well as toplevel vdevs.
99653d4ee642c6528e88224f12409a5f23060994eschrock /* get pool name and check number of arguments */
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) fprintf(stderr, gettext("missing pool name argument\n"));
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) fprintf(stderr, gettext("missing device\n"));
99653d4ee642c6528e88224f12409a5f23060994eschrock return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zpool create [-fn] [-R root] [-m mountpoint] <pool> <dev> ...
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -f Force creation, even if devices appear in use
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -n Do not create the pool, but display the resulting layout if it
fa9e4066f08beec538e775443c5be79dd423fcabahrens * were to be created.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -R Create a pool under an alternate root
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -m Set default mountpoint for the root dataset. By default it's
fa9e4066f08beec538e775443c5be79dd423fcabahrens * '/<pool>'
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Creates the the named pool according to the given vdev specification. The
fa9e4066f08beec538e775443c5be79dd423fcabahrens * bulk of the vdev processing is done in get_vdev_spec() in zpool_vdev.c. Once
fa9e4066f08beec538e775443c5be79dd423fcabahrens * we get the nvlist back from get_vdev_spec(), we either print out the contents
fa9e4066f08beec538e775443c5be79dd423fcabahrens * (if '-n' was specified), or pass it to libzfs to do the creation.
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check options */
fa9e4066f08beec538e775443c5be79dd423fcabahrens switch (c) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("missing argument for "
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("invalid option '%c'\n"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* get pool name and check number of arguments */
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("missing pool name argument\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("missing vdev specification\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * As a special case, check for use of '/' in the name, and direct the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * user to use 'zfs create' instead.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("cannot create '%s': invalid "
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("use 'zfs create' to "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "create a dataset\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* pass off to get_vdev_spec for bulk processing */
99653d4ee642c6528e88224f12409a5f23060994eschrock nvroot = make_root_vdev(NULL, force, !force, B_FALSE, argc - 1,
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
99653d4ee642c6528e88224f12409a5f23060994eschrock /* make_root_vdev() allows 0 toplevel children if there are spares */
99653d4ee642c6528e88224f12409a5f23060994eschrock verify(nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN,
99653d4ee642c6528e88224f12409a5f23060994eschrock "specification: at least one toplevel vdev must be "
99653d4ee642c6528e88224f12409a5f23060994eschrock "specified\n"));
99653d4ee642c6528e88224f12409a5f23060994eschrock return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("invalid alternate root '%s': "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "must be an absolute path\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Check the validity of the mountpoint and direct the user to use the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * '-m' mountpoint option if it looks like its in use.
fa9e4066f08beec538e775443c5be79dd423fcabahrens "'%s': must be an absolute path, 'legacy', or "
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens "mountpoint '%s' exists and is not "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "option to provide a different default\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * For a dry run invocation, print out a basic message and run
fa9e4066f08beec538e775443c5be79dd423fcabahrens * through all the vdevs in the list and print out in an
fa9e4066f08beec538e775443c5be79dd423fcabahrens * appropriate hierarchy.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Hand off to libzfs.
99653d4ee642c6528e88224f12409a5f23060994eschrock if (zpool_create(g_zfs, poolname, nvroot, altroot) == 0) {
99653d4ee642c6528e88224f12409a5f23060994eschrock } else if (libzfs_errno(g_zfs) == EZFS_INVALIDNAME) {
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) fprintf(stderr, gettext("pool name may have "
99653d4ee642c6528e88224f12409a5f23060994eschrock "been omitted\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zpool destroy <pool>
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -f Forcefully unmount any datasets
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Destroy the given pool. Automatically unmounts any datasets in the pool.
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check options */
fa9e4066f08beec538e775443c5be79dd423fcabahrens switch (c) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("invalid option '%c'\n"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check arguments */
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("missing pool argument\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("too many arguments\n"));
99653d4ee642c6528e88224f12409a5f23060994eschrock if ((zhp = zpool_open_canfail(g_zfs, pool)) == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * As a special case, check for use of '/' in the name, and
fa9e4066f08beec538e775443c5be79dd423fcabahrens * direct the user to use 'zfs destroy' instead.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("use 'zfs destroy' to "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "destroy a dataset\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("could not destroy '%s': "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "could not unmount datasets\n"), zpool_get_name(zhp));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zpool export [-f] <pool> ...
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -f Forcefully unmount datasets
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Export the the given pools. By default, the command will attempt to cleanly
fa9e4066f08beec538e775443c5be79dd423fcabahrens * unmount any active datasets within the pool. If the '-f' flag is specified,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * then the datasets will be forcefully unmounted.
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check options */
fa9e4066f08beec538e775443c5be79dd423fcabahrens switch (c) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("invalid option '%c'\n"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check arguments */
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("missing pool argument\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (i = 0; i < argc; i++) {
99653d4ee642c6528e88224f12409a5f23060994eschrock if ((zhp = zpool_open_canfail(g_zfs, argv[i])) == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Given a vdev configuration, determine the maximum width needed for the device
fa9e4066f08beec538e775443c5be79dd423fcabahrens * name column.
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrockmax_width(zpool_handle_t *zhp, nvlist_t *nv, int depth, int max)
99653d4ee642c6528e88224f12409a5f23060994eschrock if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
99653d4ee642c6528e88224f12409a5f23060994eschrock for (c = 0; c < children; c++)
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
99653d4ee642c6528e88224f12409a5f23060994eschrock for (c = 0; c < children; c++)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Print the configuration of an exported pool. Iterate over all vdevs in the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * pool, printing out the name and status for each one.
fa9e4066f08beec538e775443c5be79dd423fcabahrensprint_import_config(const char *name, nvlist_t *nv, int namewidth, int depth)
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) == 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_STATS,
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf("\t%*s%-*s", depth, "", namewidth - depth, name);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
afefbcddfd8caf5f3b2da510d9439471ab225040eschrock for (c = 0; c < children; c++) {
99653d4ee642c6528e88224f12409a5f23060994eschrock if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
99653d4ee642c6528e88224f12409a5f23060994eschrock for (c = 0; c < children; c++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Display the status for the given pool.
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID,
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_HEALTH,
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_STATS,
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("status: One or more devices are missing "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "from the system.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("status: One or more devices contains "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "corrupted data.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("status: The pool data is corrupted.\n"));
441d80aa4f613b6298fc8bd3151f4be02dbf84fclling "are offlined.\n"));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) printf(gettext("status: The pool metadata is "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock "corrupted.\n"));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock (void) printf(gettext("status: The pool is formatted using an "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "older on-disk version.\n"));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock (void) printf(gettext("status: The pool is formatted using an "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "incompatible version.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * No other status can be seen when importing pools.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Print out an action according to the overall state of the pool.
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "imported using its name or numeric identifier, "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "though\n\tsome features will not be available "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "without an explicit 'zpool upgrade'.\n"));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "imported using its name or numeric "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "identifier.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else if (strcmp(health, gettext("DEGRADED")) == 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("action: The pool can be imported "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "despite missing or damaged devices. The\n\tfault "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "tolerance of the pool may be compromised if imported.\n"));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock (void) printf(gettext("action: The pool cannot be "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "imported. Access the pool on a system running "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "newer\n\tsoftware, or recreate the pool from "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "backup.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens "imported. Attach the missing\n\tdevices and try "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "again.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens "imported due to damaged devices or data.\n"));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "but can be imported using the '-Df' flags.\n"));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock (void) printf(gettext("\tThe pool may be active on "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "on another system, but can be imported using\n\t"
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "the '-f' flag.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext(" see: http://www.sun.com/msg/%s\n"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens "be part of this pool, though their\n\texact "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "configuration cannot be determined.\n");
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Perform the import for the given configuration. This passes the heavy
fa9e4066f08beec538e775443c5be79dd423fcabahrens * lifting off to zpool_import(), and then mounts the datasets contained within
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the pool.
fa9e4066f08beec538e775443c5be79dd423fcabahrensdo_import(nvlist_t *config, const char *newname, const char *mntopts,
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock (void) fprintf(stderr, gettext("cannot import '%s': pool "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "is formatted using a newer ZFS version\n"), name);
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock return (1);
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock } else if (state != POOL_STATE_EXPORTED && !force) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("cannot import '%s': pool "
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("use '-f' to import anyway\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
99653d4ee642c6528e88224f12409a5f23060994eschrock if (zpool_import(g_zfs, config, newname, altroot) != 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
4c58d71403cebfaa40a572ff12b17668ebd56987darrenm * zpool import [-d dir] [-D]
4c58d71403cebfaa40a572ff12b17668ebd56987darrenm * import [-R root] [-D] [-d dir] [-f] -a
4c58d71403cebfaa40a572ff12b17668ebd56987darrenm * import [-R root] [-D] [-d dir] [-f] <pool | id> [newpool]
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -d Scan in a specific directory, other than /dev/dsk. More than
fa9e4066f08beec538e775443c5be79dd423fcabahrens * one directory can be specified using multiple '-d' options.
4c58d71403cebfaa40a572ff12b17668ebd56987darrenm * -D Scan for previously destroyed pools or import all or only
4c58d71403cebfaa40a572ff12b17668ebd56987darrenm * specified destroyed pools.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -R Temporarily import the pool, with all mountpoints relative to
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the given root. The pool will remain exported when the machine
fa9e4066f08beec538e775443c5be79dd423fcabahrens * is rebooted.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -f Force import, even if it appears that the pool is active.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -a Import all pools found.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The import command scans for pools to import, and import pools based on pool
fa9e4066f08beec538e775443c5be79dd423fcabahrens * name and GUID. The pool can also be renamed as part of the import process.
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check options */
4c58d71403cebfaa40a572ff12b17668ebd56987darrenm while ((c = getopt(argc, argv, ":Dfd:R:ao:")) != -1) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens switch (c) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens sizeof (char *));
fa9e4066f08beec538e775443c5be79dd423fcabahrens sizeof (char *));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("missing argument for "
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("invalid option '%c'\n"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check argument count */
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (argc != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("too many arguments\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("too many arguments\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Check for the SYS_CONFIG privilege. We do this explicitly
fa9e4066f08beec538e775443c5be79dd423fcabahrens * here because otherwise any attempt to discover pools will
fa9e4066f08beec538e775443c5be79dd423fcabahrens * silently fail.
fa9e4066f08beec538e775443c5be79dd423fcabahrens "discover pools: permission denied\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
99653d4ee642c6528e88224f12409a5f23060994eschrock if ((pools = zpool_find_import(g_zfs, nsearch, searchdirs)) == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We now have a list of all available pools in the given directories.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Depending on the arguments given, we do one of the following:
fa9e4066f08beec538e775443c5be79dd423fcabahrens * <none> Iterate through all pools and display information about
fa9e4066f08beec538e775443c5be79dd423fcabahrens * each one.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -a Iterate through all pools and try to import each one.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * <id> Find the pool that corresponds to the given GUID/pool
fa9e4066f08beec538e775443c5be79dd423fcabahrens * name and import that one.
4c58d71403cebfaa40a572ff12b17668ebd56987darrenm * -D Above options applies only to destroyed pools.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (argc != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens while ((elem = nvlist_next_nvpair(pools, elem)) != NULL) {
4c58d71403cebfaa40a572ff12b17668ebd56987darrenm verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
4c58d71403cebfaa40a572ff12b17668ebd56987darrenm if (!do_destroyed && pool_state == POOL_STATE_DESTROYED)
4c58d71403cebfaa40a572ff12b17668ebd56987darrenm if (do_destroyed && pool_state != POOL_STATE_DESTROYED)
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (argc == 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We are searching for a pool based on name.
fa9e4066f08beec538e775443c5be79dd423fcabahrens "cannot import '%s': more than "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "import by numeric ID instead\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Search for a pool by guid.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If we were searching for a specific pool, verify that we found a
fa9e4066f08beec538e775443c5be79dd423fcabahrens * pool, and then do the import.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("cannot import '%s': "
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If we were just looking for pools, report an error if none were
fa9e4066f08beec538e775443c5be79dd423fcabahrenstypedef struct iostat_cbdata {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(" ----- ----- ----- ----- ----- -----\n");
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf("%-*s used avail read write read write\n",
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Display a single statistic.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Print out all the statistics for the given vdev. This can either be the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * toplevel configuration, or called recursively. If 'name' is NULL, then this
fa9e4066f08beec538e775443c5be79dd423fcabahrens * is a verbose output, and we don't want to display the toplevel pool stats.
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrockprint_vdev_stats(zpool_handle_t *zhp, const char *name, nvlist_t *oldnv,
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_uint64_array(oldnv, ZPOOL_CONFIG_STATS,
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_uint64_array(newnv, ZPOOL_CONFIG_STATS,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* only toplevel vdevs have capacity stats */
fa9e4066f08beec538e775443c5be79dd423fcabahrens print_one_stat((uint64_t)(scale * (newvs->vs_ops[ZIO_TYPE_READ] -
fa9e4066f08beec538e775443c5be79dd423fcabahrens print_one_stat((uint64_t)(scale * (newvs->vs_ops[ZIO_TYPE_WRITE] -
fa9e4066f08beec538e775443c5be79dd423fcabahrens print_one_stat((uint64_t)(scale * (newvs->vs_bytes[ZIO_TYPE_READ] -
fa9e4066f08beec538e775443c5be79dd423fcabahrens print_one_stat((uint64_t)(scale * (newvs->vs_bytes[ZIO_TYPE_WRITE] -
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (nvlist_lookup_nvlist_array(newnv, ZPOOL_CONFIG_CHILDREN,
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (oldnv && nvlist_lookup_nvlist_array(oldnv, ZPOOL_CONFIG_CHILDREN,
afefbcddfd8caf5f3b2da510d9439471ab225040eschrock for (c = 0; c < children; c++) {
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock print_vdev_stats(zhp, vname, oldnv ? oldchild[c] : NULL,
088e9d477eee66081e407fbc5a33c4da25f66f6aeschrock * If the pool has disappeared, remove it from the list and continue.
94de1d4cf6ec0a3bf040dcc4b8df107c4ed36b51eschrock return (-1);
088e9d477eee66081e407fbc5a33c4da25f66f6aeschrock return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Callback to print out the iostats for the given pool.
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_nvlist(newconfig, ZPOOL_CONFIG_VDEV_TREE,
088e9d477eee66081e407fbc5a33c4da25f66f6aeschrock verify(nvlist_lookup_nvlist(oldconfig, ZPOOL_CONFIG_VDEV_TREE,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Print out the statistics for the pool.
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock print_vdev_stats(zhp, zpool_get_name(zhp), oldnvroot, newnvroot, cb, 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
088e9d477eee66081e407fbc5a33c4da25f66f6aeschrock if ((config = zpool_get_config(zhp, NULL)) != NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The width must fall into the range [10,38]. The upper limit is the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * maximum we can have and still fit in 80 columns.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zpool iostat [-v] [pool] ... [interval [count]]
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -v Display statistics for individual vdevs
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This command can be tricky because we want to be able to deal with pool
fa9e4066f08beec538e775443c5be79dd423fcabahrens * creation/destruction as well as vdev configuration changes. The bulk of this
fa9e4066f08beec538e775443c5be79dd423fcabahrens * processing is handled by the pool_list_* routines in zpool_iter.c. We rely
fa9e4066f08beec538e775443c5be79dd423fcabahrens * on pool_list_update() to detect the addition of new pools. Configuration
fa9e4066f08beec538e775443c5be79dd423fcabahrens * changes are all handled within libzfs.
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check options */
fa9e4066f08beec538e775443c5be79dd423fcabahrens switch (c) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("invalid option '%c'\n"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Determine if the last argument is an integer or a pool name
fa9e4066f08beec538e775443c5be79dd423fcabahrens "cannot be zero\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Ignore the last parameter
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If this is not a valid number, just plow on. The
fa9e4066f08beec538e775443c5be79dd423fcabahrens * user will get a more informative error message later
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If the last argument is also an integer, then we have both a count
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and an integer.
fa9e4066f08beec538e775443c5be79dd423fcabahrens "cannot be zero\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Ignore the last parameter
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Construct the list of all interesting pools.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if ((list = pool_list_get(argc, argv, &ret)) == NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("no pools available\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Enter the main iostat loop.
088e9d477eee66081e407fbc5a33c4da25f66f6aeschrock * Refresh all statistics. This is done as an explicit step
088e9d477eee66081e407fbc5a33c4da25f66f6aeschrock * before calculating the maximum name width, so that any
088e9d477eee66081e407fbc5a33c4da25f66f6aeschrock * configuration changes are properly accounted for.
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) pool_list_iter(list, B_FALSE, refresh_iostat, &cb);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Iterate over all pools to determine the maximum width
fa9e4066f08beec538e775443c5be79dd423fcabahrens * for the pool / device name column across all pools.
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) pool_list_iter(list, B_FALSE, get_namewidth, &cb);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If it's the first time, or verbose mode, print the header.
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) pool_list_iter(list, B_FALSE, print_iostat, &cb);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If there's more than one pool, and we're not in verbose mode
fa9e4066f08beec538e775443c5be79dd423fcabahrens * (which prints a separator for us), then print a separator.
fa9e4066f08beec538e775443c5be79dd423fcabahrenstypedef struct list_cbdata {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Given a list of columns to display, output appropriate headers for each one.
fa9e4066f08beec538e775443c5be79dd423fcabahrens const char *fmt;
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (i = 0; i < count; i++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (i != 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(fmt, i == count - 1 ? strlen(col->cd_title) :
fa9e4066f08beec538e775443c5be79dd423fcabahrens const char *fmt;
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (i != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(buf, zpool_get_name(zhp), sizeof (buf));
fa9e4066f08beec538e775443c5be79dd423fcabahrens else if (zpool_get_root(zhp, buf, sizeof (buf)) != 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zpool list [-H] [-o field[,field]*] [pool] ...
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -H Scripted mode. Don't display headers, and separate fields by
fa9e4066f08beec538e775443c5be79dd423fcabahrens * a single tab.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -o List of fields to display. Defaults to all fields, or
fa9e4066f08beec538e775443c5be79dd423fcabahrens * "name,size,used,available,capacity,health,root"
fa9e4066f08beec538e775443c5be79dd423fcabahrens * List all pools in the system, whether or not they're healthy. Output space
fa9e4066f08beec538e775443c5be79dd423fcabahrens * statistics for each one, as well as health status summary.
fa9e4066f08beec538e775443c5be79dd423fcabahrens static char default_fields[] =
fa9e4066f08beec538e775443c5be79dd423fcabahrens "name,size,used,available,capacity,health,root";
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check options */
fa9e4066f08beec538e775443c5be79dd423fcabahrens switch (c) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("missing argument for "
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("invalid option '%c'\n"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens "properties given to -o option\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens if ((cb.cb_fields[cb.cb_fieldcount] = getsubopt(&fields,
99653d4ee642c6528e88224f12409a5f23060994eschrock ret = for_each_pool(argc, argv, B_TRUE, list_callback, &cb);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (c = 0; c < children; c++)
fa9e4066f08beec538e775443c5be79dd423fcabahrens if ((match = zpool_get_vdev_by_name(child[c], name)) != NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrenszpool_do_attach_or_replace(int argc, char **argv, int replacing)
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check options */
fa9e4066f08beec538e775443c5be79dd423fcabahrens switch (c) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("invalid option '%c'\n"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* get pool name and check number of arguments */
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("missing pool name argument\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("too many arguments\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
088e9d477eee66081e407fbc5a33c4da25f66f6aeschrock if ((config = zpool_get_config(zhp, NULL)) == NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("pool '%s' is unavailable\n"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
99653d4ee642c6528e88224f12409a5f23060994eschrock nvroot = make_root_vdev(config, force, B_FALSE, replacing, argc, argv);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
99653d4ee642c6528e88224f12409a5f23060994eschrock ret = zpool_vdev_attach(zhp, old_disk, new_disk, nvroot, replacing);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zpool replace [-f] <pool> <device> <new_device>
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -f Force attach, even if <new_device> appears to be in use.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Replace <device> with <new_device>.
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* ARGSUSED */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (zpool_do_attach_or_replace(argc, argv, B_TRUE));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zpool attach [-f] <pool> <device> <new_device>
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -f Force attach, even if <new_device> appears to be in use.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Attach <new_device> to the mirror containing <device>. If <device> is not
fa9e4066f08beec538e775443c5be79dd423fcabahrens * part of a mirror, then <device> will be transformed into a mirror of
fa9e4066f08beec538e775443c5be79dd423fcabahrens * <device> and <new_device>. In either case, <new_device> will begin life
fa9e4066f08beec538e775443c5be79dd423fcabahrens * with a DTL of [0, now], and will immediately begin to resilver itself.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (zpool_do_attach_or_replace(argc, argv, B_FALSE));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zpool detach [-f] <pool> <device>
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -f Force detach of <device>, even if DTLs argue against it
fa9e4066f08beec538e775443c5be79dd423fcabahrens * (not supported yet)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Detach a device from a mirror. The operation will be refused if <device>
fa9e4066f08beec538e775443c5be79dd423fcabahrens * is the last device in the mirror, or if the DTLs indicate that this device
fa9e4066f08beec538e775443c5be79dd423fcabahrens * has the only valid copy of some data.
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* ARGSUSED */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check options */
fa9e4066f08beec538e775443c5be79dd423fcabahrens switch (c) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("invalid option '%c'\n"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* get pool name and check number of arguments */
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("missing pool name argument\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
441d80aa4f613b6298fc8bd3151f4be02dbf84fclling * zpool online <pool> <device> ...
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* ARGSUSED */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check options */
fa9e4066f08beec538e775443c5be79dd423fcabahrens switch (c) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("invalid option '%c'\n"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* get pool name and check number of arguments */
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("missing pool name\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("missing device name\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("Bringing device %s online\n"),
441d80aa4f613b6298fc8bd3151f4be02dbf84fclling * zpool offline [-ft] <pool> <device> ...
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -f Force the device into the offline state, even if doing
fa9e4066f08beec538e775443c5be79dd423fcabahrens * so would appear to compromise pool availability.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * (not supported yet)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -t Only take the device off-line temporarily. The offline
fa9e4066f08beec538e775443c5be79dd423fcabahrens * state will not be persistent across reboots.
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* ARGSUSED */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check options */
fa9e4066f08beec538e775443c5be79dd423fcabahrens switch (c) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("invalid option '%c'\n"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* get pool name and check number of arguments */
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("missing pool name\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("missing device name\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("Bringing device %s offline\n"),
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * zpool clear <pool> [device]
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Clear all errors associated with a pool or a particular device.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) fprintf(stderr, gettext("missing pool name\n"));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) fprintf(stderr, gettext("too many arguments\n"));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrenstypedef struct scrub_cbdata {
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Ignore faulted pools.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) fprintf(stderr, gettext("cannot scrub '%s': pool is "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zpool scrub [-s] <pool> ...
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -s Stop. Stops any in-progress scrub.
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check options */
fa9e4066f08beec538e775443c5be79dd423fcabahrens switch (c) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("invalid option '%c'\n"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("missing pool name argument\n"));
99653d4ee642c6528e88224f12409a5f23060994eschrock return (for_each_pool(argc, argv, B_TRUE, scrub_callback, &cb));
fa9e4066f08beec538e775443c5be79dd423fcabahrenstypedef struct status_cbdata {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Print out detailed scrub status.
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_STATS,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If there's never been a scrub, there's not much to say.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (vs->vs_scrub_end == 0 && vs->vs_scrub_type == POOL_SCRUB_NONE) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens scrub_type = (vs->vs_scrub_type == POOL_SCRUB_RESILVER) ?
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (end != 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("%s %s with %llu errors on %s"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens scrub_type, vs->vs_scrub_complete ? "completed" : "stopped",
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("%s in progress, %.2f%% done, %lluh%um to go\n"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens (u_longlong_t)(minutes_left / 60), (uint_t)(minutes_left % 60));
99653d4ee642c6528e88224f12409a5f23060994eschrocktypedef struct spare_cbdata {
99653d4ee642c6528e88224f12409a5f23060994eschrock if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) == 0 &&
99653d4ee642c6528e88224f12409a5f23060994eschrock if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
99653d4ee642c6528e88224f12409a5f23060994eschrock for (c = 0; c < children; c++)
99653d4ee642c6528e88224f12409a5f23060994eschrock verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
99653d4ee642c6528e88224f12409a5f23060994eschrock return (1);
99653d4ee642c6528e88224f12409a5f23060994eschrock return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Print out configuration state as requested by status_callback.
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrockprint_status_config(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
99653d4ee642c6528e88224f12409a5f23060994eschrock const char *state;
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_STATS,
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
99653d4ee642c6528e88224f12409a5f23060994eschrock * For hot spares, we use the terms 'INUSE' and 'AVAILABLE' for
99653d4ee642c6528e88224f12409a5f23060994eschrock * online drives.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf("\t%*s%-*s %-8s", depth, "", namewidth - depth,
99653d4ee642c6528e88224f12409a5f23060994eschrock zfs_nicenum(vs->vs_read_errors, rbuf, sizeof (rbuf));
99653d4ee642c6528e88224f12409a5f23060994eschrock zfs_nicenum(vs->vs_write_errors, wbuf, sizeof (wbuf));
99653d4ee642c6528e88224f12409a5f23060994eschrock zfs_nicenum(vs->vs_checksum_errors, cbuf, sizeof (cbuf));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0);
99653d4ee642c6528e88224f12409a5f23060994eschrock "pool '%s'"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else if (vs->vs_scrub_repaired != 0 && children == 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Report bytes resilvered/repaired on leaf devices.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_nicenum(vs->vs_scrub_repaired, repaired, sizeof (repaired));
afefbcddfd8caf5f3b2da510d9439471ab225040eschrock for (c = 0; c < children; c++) {
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) printf("errors: List of errors unavailable "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock "(insufficient privileges)\n");
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock for (i = 0; i < nelem; i++) {
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) printf("errors: The following persistent errors have been "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock "detected:\n\n");
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) printf("%8s %-*s %-*s %s\n", "", maxdsname, "DATASET",
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock for (i = 0; i < nelem; i++) {
99653d4ee642c6528e88224f12409a5f23060994eschrockprint_spares(zpool_handle_t *zhp, nvlist_t **spares, uint_t nspares,
99653d4ee642c6528e88224f12409a5f23060994eschrock for (i = 0; i < nspares; i++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Display a summary of pool status. Displays a summary such as:
fa9e4066f08beec538e775443c5be79dd423fcabahrens * pool: tank
fa9e4066f08beec538e775443c5be79dd423fcabahrens * status: DEGRADED
fa9e4066f08beec538e775443c5be79dd423fcabahrens * reason: One or more devices ...
fa9e4066f08beec538e775443c5be79dd423fcabahrens * mirror DEGRADED
fa9e4066f08beec538e775443c5be79dd423fcabahrens * c1t0d0 OK
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * c2t0d0 UNAVAIL
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When given the '-v' option, we print out the complete config. If the '-e'
fa9e4066f08beec538e775443c5be79dd423fcabahrens * option is specified, then we print out error rate information as well.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If we were given 'zpool status -x', only report those pools with
fa9e4066f08beec538e775443c5be79dd423fcabahrens * problems.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_HEALTH,
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext(" pool: %s\n"), zpool_get_name(zhp));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("status: One or more devices could not "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "be opened. Sufficient replicas exist for\n\tthe pool to "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "continue functioning in a degraded state.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("action: Attach the missing device and "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "online it using 'zpool online'.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("status: One or more devices could not "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "be opened. There are insufficient\n\treplicas for the "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "pool to continue functioning.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("action: Attach the missing device and "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "online it using 'zpool online'.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("status: One or more devices could not "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "be used because the label is missing or\n\tinvalid. "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "Sufficient replicas exist for the pool to continue\n\t"
fa9e4066f08beec538e775443c5be79dd423fcabahrens "functioning in a degraded state.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("action: Replace the device using "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "'zpool replace'.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("status: One or more devices could not "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "be used because the the label is missing \n\tor invalid. "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "There are insufficient replicas for the pool to "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "continue\n\tfunctioning.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("action: Destroy and re-create the pool "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "from a backup source.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("status: One or more devices has "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "experienced an unrecoverable error. An\n\tattempt was "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "made to correct the error. Applications are "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "unaffected.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("action: Determine if the device needs "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "to be replaced, and clear the errors\n\tusing "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock "'zpool clear' or replace the device with 'zpool "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "replace'.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("status: One or more devices has "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "been taken offline by the adminstrator.\n\tSufficient "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "replicas exist for the pool to continue functioning in "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "a\n\tdegraded state.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("action: Online the device using "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "'zpool online' or replace the device with\n\t'zpool "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "replace'.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("status: One or more devices is "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "currently being resilvered. The pool will\n\tcontinue "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "to function, possibly in a degraded state.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("action: Wait for the resilver to "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "complete.\n"));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) printf(gettext("status: One or more devices has "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock "experienced an error resulting in data\n\tcorruption. "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock "Applications may be affected.\n"));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) printf(gettext("action: Restore the file in question "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock "if possible. Otherwise restore the\n\tentire pool from "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock "backup.\n"));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) printf(gettext("status: The pool metadata is corrupted "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock "and the pool cannot be opened.\n"));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) printf(gettext("action: Destroy and re-create the pool "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock "from a backup source.\n"));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock (void) printf(gettext("status: The pool is formatted using an "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "older on-disk format. The pool can\n\tstill be used, but "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "some features are unavailable.\n"));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock (void) printf(gettext("action: Upgrade the pool using 'zpool "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "upgrade'. Once this is done, the\n\tpool will no longer "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "be accessible on older software versions.\n"));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock (void) printf(gettext("status: The pool has been upgraded to a "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "newer, incompatible on-disk version.\n\tThe pool cannot "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "be accessed on this system.\n"));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock (void) printf(gettext("action: Access the pool from a system "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "running more recent software, or\n\trestore the pool from "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "backup.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The remaining errors can't actually be generated, yet.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext(" see: http://www.sun.com/msg/%s\n"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("\t%-*s %-8s %5s %5s %5s\n"), namewidth,
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock print_status_config(zhp, zpool_get_name(zhp), nvroot,
99653d4ee642c6528e88224f12409a5f23060994eschrock if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_ERRCOUNT,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * If the approximate error count is small, get a
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * precise count by fetching the entire log and
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * uniquifying the results.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock "errors\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) printf(gettext("config: The configuration cannot be "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "determined.\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * zpool status [-vx] [pool] ...
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -v Display complete error logs
fa9e4066f08beec538e775443c5be79dd423fcabahrens * -x Display only pools with potential problems
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Describes the health status of all pools or some subset.
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check options */
fa9e4066f08beec538e775443c5be79dd423fcabahrens switch (c) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("invalid option '%c'\n"),
99653d4ee642c6528e88224f12409a5f23060994eschrock ret = for_each_pool(argc, argv, B_TRUE, status_callback, &cb);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (argc == 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (i = 0; i < argc; i++)
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrocktypedef struct upgrade_cbdata {
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "out of date, and can be upgraded. After "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "being\nupgraded, these pools will no "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "longer be accessible by older software "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "versions.\n\n"));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock } else if (cbp->cb_newer && version > ZFS_VERSION) {
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "formatted using a newer software version and\n"
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "cannot be accessed on the current system.\n\n"));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock/* ARGSUSED */
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock (void) printf(gettext("Pool '%s' is already formatted "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "using the current version.\n"), zpool_get_name(zhp));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock return (0);
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm "from version %llu to version %llu\n"), zpool_get_name(zhp),
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock return (ret != 0);
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock * zpool upgrade
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock * zpool upgrade -v
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock * zpool upgrade <-a | pool>
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock * With no arguments, display downrev'd ZFS pool available for upgrade.
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock * Individual pools can be upgraded by specifying the pool, and '-a' will
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock * upgrade all pools.
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock /* check options */
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock switch (c) {
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock (void) fprintf(stderr, gettext("invalid option '%c'\n"),
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "incompatible with other arguments\n"));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock if (argc != 0) {
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "incompatible with other arguments\n"));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock (void) printf(gettext("This system is currently running ZFS version "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock (void) printf(gettext("The following versions are "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "suppored:\n\n"));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock (void) printf("--- -----------------------------------------"
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "---------------\n");
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) printf(gettext(" 1 Initial ZFS version\n"));
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm "(replicated metadata)\n"));
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) printf(gettext(" 3 Hot spares and double parity "
99653d4ee642c6528e88224f12409a5f23060994eschrock "RAID-Z\n"));
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm (void) printf(gettext("\nFor more information on a particular "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "version, including supported releases, see:\n\n"));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock (void) printf("http://www.opensolaris.org/os/community/zfs/"
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "version/N\n\n");
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock (void) printf(gettext("Where 'N' is the version number.\n"));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock } else if (argc == 0) {
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock if (ret == 0) {
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "using this version.\n"));
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "for a list of available versions and "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock "their associated\nfeatures.\n"));
99653d4ee642c6528e88224f12409a5f23060994eschrock ret = for_each_pool(argc, argv, B_FALSE, upgrade_one, NULL);
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) fprintf(stderr, gettext("internal error: failed to "
99653d4ee642c6528e88224f12409a5f23060994eschrock "initialize ZFS library"));
99653d4ee642c6528e88224f12409a5f23060994eschrock return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Make sure the user has specified some command.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) fprintf(stderr, gettext("missing command\n"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Special case '-?'
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Run the appropriate command.
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (i = 0; i < NCOMMAND; i++) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * 'freeze' is a vile debugging abomination, so we treat it as such.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The 'ZFS_ABORT' environment variable causes us to dump core on exit
fa9e4066f08beec538e775443c5be79dd423fcabahrens * for the purposes of running ::findleaks.