libzfs_pool.c revision eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481
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"
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Validate the given pool name, optionally putting an extended error message in
fa9e4066f08beec538e775443c5be79dd423fcabahrenszpool_name_valid(const char *pool, char *buf, size_t buflen)
fa9e4066f08beec538e775443c5be79dd423fcabahrens "name is reserved\n"
fa9e4066f08beec538e775443c5be79dd423fcabahrens "pool name is reserved\n"
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Set the pool-wide health based on the vdev state of the root vdev.
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_STATS,
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_add_string(config, ZPOOL_CONFIG_POOL_HEALTH,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Open a handle to the given pool, even if the pool is currently in the FAULTED
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Make sure the pool name is valid.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "cannot open '%s': invalid "
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zhp->zpool_name, pool, sizeof (zhp->zpool_name));
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "cannot open '%s': no "
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Like the above, but silent on error. Used when iterating over pools (because
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the configuration cache may be out of date).
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zhp->zpool_name, pool, sizeof (zhp->zpool_name));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Similar to zpool_open_canfail(), but refuses to open pools in the faulted
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock zfs_error(dgettext(TEXT_DOMAIN, "cannot open '%s': pool is "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock zfs_error(dgettext(TEXT_DOMAIN, "run 'zpool status %s' for "
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Close the handle. Simply frees the memory associated with the handle.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Return the name of the pool.
fa9e4066f08beec538e775443c5be79dd423fcabahrensconst char *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Return the GUID of the pool.
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_uint64(zhp->zpool_config, ZPOOL_CONFIG_POOL_GUID,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Return the amount of space currently consumed by the pool.
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_nvlist(zhp->zpool_config, ZPOOL_CONFIG_VDEV_TREE,
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_STATS,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Return the total space in the pool.
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_nvlist(zhp->zpool_config, ZPOOL_CONFIG_VDEV_TREE,
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_STATS,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Return the alternate root for this pool, if any.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszpool_get_root(zpool_handle_t *zhp, char *buf, size_t buflen)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Return the state of the pool (ACTIVE or UNAVAILABLE)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Create the named pool, using the provided vdev list. It is assumed
fa9e4066f08beec538e775443c5be79dd423fcabahrens * that the consumer has already validated the contents of the nvlist, so we
fa9e4066f08beec538e775443c5be79dd423fcabahrens * don't have to worry about error semantics.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszpool_create(const char *pool, nvlist_t *nvroot, const char *altroot)
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (!zpool_name_valid(pool, reason, sizeof (reason))) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "cannot create '%s': %s"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "cannot create '%s': alternate "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "root '%s' must be a complete path"), pool, altroot);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if ((err = nvlist_size(nvroot, &len, NV_ENCODE_NATIVE)) != 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, pool, sizeof (zc.zc_name));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_root, altroot, sizeof (zc.zc_root));
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "cannot create '%s': "
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "cannot create '%s': "
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This can happen if the user has specified the same
fa9e4066f08beec538e775443c5be79dd423fcabahrens * device multiple times. We can't reliably detect this
fa9e4066f08beec538e775443c5be79dd423fcabahrens * until we try to add it and see we already have a
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "cannot create '%s': "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "one or more vdevs refer to the same device"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This occurrs when one of the devices is below
fa9e4066f08beec538e775443c5be79dd423fcabahrens * SPA_MINDEVSIZE. Unfortunately, we can't detect which
fa9e4066f08beec538e775443c5be79dd423fcabahrens * device was the problem device since there's no
fa9e4066f08beec538e775443c5be79dd423fcabahrens * reliable way to determine device size from userland.
fa9e4066f08beec538e775443c5be79dd423fcabahrens "create '%s': one or more devices is less "
fa9e4066f08beec538e775443c5be79dd423fcabahrens * One of the vdevs has exceeded VDEV_SPEC_MAX length in
fa9e4066f08beec538e775443c5be79dd423fcabahrens * its plaintext representation.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "cannot create '%s': "
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "cannot create '%s': "
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This is unlikely to happen since we've verified that
fa9e4066f08beec538e775443c5be79dd423fcabahrens * all the devices can be opened from userland, but it's
fa9e4066f08beec538e775443c5be79dd423fcabahrens * still possible in some circumstances.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "cannot create '%s': "
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This can occur if we were incapable of writing to a
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file vdev because the underlying filesystem is out of
fa9e4066f08beec538e775443c5be79dd423fcabahrens * space. This is very similar to EOVERFLOW, but we'll
fa9e4066f08beec538e775443c5be79dd423fcabahrens * produce a slightly different message.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "cannot create '%s': "
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If this is an alternate root pool, then we automatically set the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * moutnpoint of the root dataset to be '/'.
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify((zhp = zfs_open(pool, ZFS_TYPE_ANY)) != NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(zfs_prop_set(zhp, ZFS_PROP_MOUNTPOINT, "/") == 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Destroy the given pool. It is up to the caller to ensure that there are no
fa9e4066f08beec538e775443c5be79dd423fcabahrens * datasets left in the pool.
fa9e4066f08beec538e775443c5be79dd423fcabahrens (zfp = zfs_open(zhp->zpool_name, ZFS_TYPE_FILESYSTEM)) == NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
fa9e4066f08beec538e775443c5be79dd423fcabahrens "cannot destroy '%s': permission denied"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens "cannot destroy '%s': pool busy"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens "cannot destroy '%s': no such pool"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens "cannot destroy '%s': one or more devices is "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "read only, or '/' is mounted read only"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Add the given vdevs to the pool. The caller must have already performed the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * necessary verification to ensure that the vdev specification is well-formed.
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_size(nvroot, &len, NV_ENCODE_NATIVE) == 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_pack(nvroot, &packed, &len, NV_ENCODE_NATIVE, 0) == 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "cannot add to '%s': "
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This can happen if the user has specified the same
fa9e4066f08beec538e775443c5be79dd423fcabahrens * device multiple times. We can't reliably detect this
fa9e4066f08beec538e775443c5be79dd423fcabahrens * until we try to add it and see we already have a
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "cannot add to '%s': "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "one or more vdevs refer to the same device"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens * One of the vdevs has exceeded VDEV_SPEC_MAX length in
fa9e4066f08beec538e775443c5be79dd423fcabahrens * its plaintext representation.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "cannot add to '%s': "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "too many devices in a single vdev"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This is unlikely to happen since we've verified that
fa9e4066f08beec538e775443c5be79dd423fcabahrens * all the devices can be opened from userland, but it's
fa9e4066f08beec538e775443c5be79dd423fcabahrens * still possible in some circumstances.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "cannot add to '%s': "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "one or more devices is unavailable"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This occurrs when one of the devices is below
fa9e4066f08beec538e775443c5be79dd423fcabahrens * SPA_MINDEVSIZE. Unfortunately, we can't detect which
fa9e4066f08beec538e775443c5be79dd423fcabahrens * device was the problem device since there's no
fa9e4066f08beec538e775443c5be79dd423fcabahrens * reliable way to determine device size from userland.
fa9e4066f08beec538e775443c5be79dd423fcabahrens "add to '%s': one or more devices is less "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "than the minimum size (%s)"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Exports the pool from the system. The caller must ensure that there are no
fa9e4066f08beec538e775443c5be79dd423fcabahrens * mounted datasets in the pool.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
fa9e4066f08beec538e775443c5be79dd423fcabahrens "cannot export '%s': permission denied"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens "cannot export '%s': pool is in use"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens "cannot export '%s': no such pool"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Import the given pool using the known configuration. The configuration
fa9e4066f08beec538e775443c5be79dd423fcabahrens * should have come from zpool_find_import(). The 'newname' and 'altroot'
fa9e4066f08beec538e775443c5be79dd423fcabahrens * parameters control whether the pool is imported with a different name or with
fa9e4066f08beec538e775443c5be79dd423fcabahrens * an alternate root, respectively.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszpool_import(nvlist_t *config, const char *newname, const char *altroot)
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "cannot import '%s': "
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "cannot import '%s': alternate "
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, thename, sizeof (zc.zc_name));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_root, altroot, sizeof (zc.zc_root));
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID,
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_size(config, &len, NV_ENCODE_NATIVE) == 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_pack(config, &packed, &len, NV_ENCODE_NATIVE, 0) == 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * A pool with that name already exists.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The user doesn't have permission to create pools.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Device is unavailable, or vdev sum didn't match.
fa9e4066f08beec538e775443c5be79dd423fcabahrens "devices is unavailable"),
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Unsupported version.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This should never fail, but play it safe anyway.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Scrub the pool.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszpool_scrub(zpool_handle_t *zhp, pool_scrub_type_t type)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens dgettext(TEXT_DOMAIN, "cannot scrub %s"), zc.zc_name);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * No permission to scrub this pool.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "%s: permission denied"), msg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Resilver in progress.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "%s: currently resilvering"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockvdev_to_guid(nvlist_t *nv, const char *search, uint64_t guid)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &ret) == 0);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT, &present) == 0) {
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * If the device has never been present since import, the only
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * reliable way to match the vdev is by GUID.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0) {
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_WHOLE_DISK,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * For whole disks, the internal path has 's0', but the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * path passed in by the user doesn't.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (0);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock for (c = 0; c < children; c++)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if ((ret = vdev_to_guid(child[c], search, guid)) != 0)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (0);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Given a string describing a vdev, returns the matching GUID, or 0 if none.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockzpool_vdev_to_guid(zpool_handle_t *zhp, const char *path)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock const char *search;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) snprintf(buf, sizeof (buf), "%s%s", "/dev/dsk/", path);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock verify(nvlist_lookup_nvlist(zhp->zpool_config, ZPOOL_CONFIG_VDEV_TREE,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Bring the specified vdev online
fa9e4066f08beec538e775443c5be79dd423fcabahrenszpool_vdev_online(zpool_handle_t *zhp, const char *path)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if ((zc.zc_guid = zpool_vdev_to_guid(zhp, path)) == 0) {
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock zfs_error(dgettext(TEXT_DOMAIN, "%s: no such device in pool"),
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Device doesn't exist
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "%s: device not in pool"), msg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * No permission to bring this vdev online.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "%s: permission denied"), msg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Take the specified vdev offline
441d80aa4f613b6298fc8bd3151f4be02dbf84fcllingzpool_vdev_offline(zpool_handle_t *zhp, const char *path, int istmp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if ((zc.zc_guid = zpool_vdev_to_guid(zhp, path)) == 0) {
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock zfs_error(dgettext(TEXT_DOMAIN, "%s: no such device in pool"),
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Device doesn't exist
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "%s: device not in pool"), msg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * No permission to take this vdev offline.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "%s: permission denied"), msg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * There are no other replicas of this device.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "%s: no valid replicas"), msg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Attach new_disk (fully described by nvroot) to old_disk.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If 'replacing' is specified, tne new disk will replace the old one.
fa9e4066f08beec538e775443c5be79dd423fcabahrens const char *old_disk, const char *new_disk, nvlist_t *nvroot, int replacing)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if ((zc.zc_guid = zpool_vdev_to_guid(zhp, old_disk)) == 0) {
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock zfs_error(dgettext(TEXT_DOMAIN, "%s: no such device in pool"),
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_size(nvroot, &len, NV_ENCODE_NATIVE) == 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_pack(nvroot, &packed, &len, NV_ENCODE_NATIVE, 0) == 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * No permission to mess with the config.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "%s: permission denied"), msg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Device doesn't exist.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "%s: %s not in pool"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Can't attach to or replace this type of vdev.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The new device must be a single disk.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This is unlikely to happen since we've verified that
fa9e4066f08beec538e775443c5be79dd423fcabahrens * all the devices can be opened from userland, but it's
fa9e4066f08beec538e775443c5be79dd423fcabahrens * still possible in some circumstances.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "%s: %s is unavailable"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The new device is is use.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "%s: %s busy"), msg, new_disk);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The new device is too small.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "%s: %s is too small"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The new device has a different alignment requirement.
fa9e4066f08beec538e775443c5be79dd423fcabahrens "%s: devices have different sector alignment"), msg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The resulting top-level vdev spec won't fit in the label.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Detach the specified device.
fa9e4066f08beec538e775443c5be79dd423fcabahrenszpool_vdev_detach(zpool_handle_t *zhp, const char *path)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if ((zc.zc_guid = zpool_vdev_to_guid(zhp, path)) == 0) {
0373e76b3c3643df49ef3483e0f293fdea61d8c6bonwick zfs_error(dgettext(TEXT_DOMAIN, "%s: no such device in pool"),
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * No permission to mess with the config.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "%s: permission denied"), msg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Device doesn't exist.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "%s: device not in pool"), msg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Can't detach from this type of vdev.
fa9e4066f08beec538e775443c5be79dd423fcabahrens "%s: only applicable to mirror and replacing vdevs"), msg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * There are no other replicas of this device.
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "%s: no valid replicas"), msg);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (1);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Clear the errors for the pool, or the particular device if specified.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock dgettext(TEXT_DOMAIN, "cannot clear errors for %s"),
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock dgettext(TEXT_DOMAIN, "cannot clear errors for %s"),
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (path && (zc.zc_guid = zpool_vdev_to_guid(zhp, path)) == 0) {
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock zfs_error(dgettext(TEXT_DOMAIN, "%s: no such device in pool"),
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (-1);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (0);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * No permission to mess with the config.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock zfs_error(dgettext(TEXT_DOMAIN, "%s: permission denied"), msg);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Device doesn't exist.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock zfs_error(dgettext(TEXT_DOMAIN, "%s: device not in pool"), msg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We check for volblocksize intead of ZFS_TYPE_VOLUME so that we
fa9e4066f08beec538e775443c5be79dd423fcabahrens * correctly handle snapshots of volumes.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Iterate over all zvols in the pool and make any necessary minor nodes.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If the pool is unavailable, just return success.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if ((zfp = make_dataset_handle(zhp->zpool_name)) == NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Iterate over all zvols in the poool and remove any minor nodes.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If the pool is unavailable, just return success.
fa9e4066f08beec538e775443c5be79dd423fcabahrens if ((zfp = make_dataset_handle(zhp->zpool_name)) == NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens ret = zfs_iter_children(zfp, do_zvol, (void *)FALSE);
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * Convert from a devid string to a path.
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrockstatic char *
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock if (devid_str_decode(devid_str, &devid, &minor) != 0)
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock ret = devid_deviceid_to_nmlist("/dev", devid, minor, &list);
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * Convert from a path to a devid string.
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrockstatic char *
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * Issue the necessary ioctl() to update the stored path value for the vdev. We
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * ignore any failure here, since a common case is for an unprivileged user to
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * type 'zpool status', and we'll display the correct information anyway.
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrockset_path(zpool_handle_t *zhp, nvlist_t *nv, const char *path)
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock (void) strncpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock (void) strncpy(zc.zc_prop_value, path, sizeof (zc.zc_prop_value));
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * Given a vdev, return the name to display in iostat. If the vdev has a path,
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * we use that, stripping off any leading "/dev/dsk/"; if not, we use the type.
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * We also check if this is a whole disk, in which case we strip off the
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * trailing 's0' slice name.
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * This routine is also responsible for identifying when disks have been
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * reconfigured in a new location. The kernel will have opened the device by
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * devid, but the path will still refer to the old location. To catch this, we
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * first do a path -> devid translation (which is fast for the common case). If
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * the devid matches, we're done. If not, we do a reverse devid -> path
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * translation and issue the appropriate ioctl() to update the path of the vdev.
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * If 'zhp' is NULL, then this is an exported pool, and we don't need to do any
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * of these checks.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock } else if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0) {
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock nvlist_lookup_string(nv, ZPOOL_CONFIG_DEVID, &devid) == 0) {
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * Determine if the current path is correct.
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock * Update the path appropriately.
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_WHOLE_DISK,
c67d9675bbc8392fe45f3a7dfbda1ad4daa1eb07eschrock verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &path) == 0);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockzbookmark_compare(const void *a, const void *b)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Retrieve the persistent error log, uniquify the members, and return to the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockzpool_get_errlog(zpool_handle_t *zhp, nvlist_t ***list, size_t *nelem)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (0);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Retrieve the raw error list from the kernel. If the number of errors
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * has increased, allocate more space and continue until we get the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * entire list.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock verify(nvlist_lookup_uint64(zhp->zpool_config, ZPOOL_CONFIG_ERRCOUNT,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock zc.zc_config_dst = (uintptr_t)zfs_malloc(count * sizeof (zbookmark_t));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (-1);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Sort the resulting bookmarks. This is a little confusing due to the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * implementation of ZFS_IOC_ERROR_LOG. The bookmarks are copied last
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * to first, and 'zc_config_dst_size' indicates the number of boomarks
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * _not_ copied as part of the process. So we point the start of our
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * array appropriate and decrement the total number of elements.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock zb = ((zbookmark_t *)(uintptr_t)zc.zc_config_dst) +
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock qsort(zb, count, sizeof (zbookmark_t), zbookmark_compare);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Count the number of unique elements
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock for (i = 0; i < count; i++) {
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock sizeof (zbookmark_t)) == 0)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * If the user has only requested the number of items, return it now
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * without bothering with the extra work.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (0);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Allocate an array of nvlists to hold the results
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock zhp->zpool_error_log = zfs_malloc(j * sizeof (nvlist_t *));
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Fill in the results with names from the kernel.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock for (i = 0; i < count; i++) {
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock sizeof (zbookmark_t)) == 0)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) snprintf(buf, sizeof (buf), "lvl=%u blkid=%llu",
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (0);
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock * Upgrade a ZFS pool to the latest on-disk version.
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock zfs_error(dgettext(TEXT_DOMAIN, "cannot upgrade '%s': "
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock return (-1);
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock return (0);