libzfs_pool.c revision b81d61a68b235e0529ebadc18e14d9d1dd52a258
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Common Development and Distribution License, Version 1.0 only
fa9e4066f08beec538e775443c5be79dd423fcabahrens * (the "License"). You may not use this file except in compliance
fa9e4066f08beec538e775443c5be79dd423fcabahrens * 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
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Copyright 2005 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
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "cannot open ' %s': pool is "
fa9e4066f08beec538e775443c5be79dd423fcabahrens zfs_error(dgettext(TEXT_DOMAIN, "run 'zpool status -v %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 (void) strlcpy(buf, zc.zc_objset_stats.dds_altroot, buflen);
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"),
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);
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));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) snprintf(zc.zc_prop_value, sizeof (zc.zc_prop_value),
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens dgettext(TEXT_DOMAIN, "cannot online %s"), zc.zc_prop_value);
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
fa9e4066f08beec538e775443c5be79dd423fcabahrenszpool_vdev_offline(zpool_handle_t *zhp, const char *path)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) snprintf(zc.zc_prop_value, sizeof (zc.zc_prop_value),
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens dgettext(TEXT_DOMAIN, "cannot offline %s"), zc.zc_prop_value);
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)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) snprintf(zc.zc_prop_value, sizeof (zc.zc_prop_value),
fa9e4066f08beec538e775443c5be79dd423fcabahrens "%s%s", old_disk[0] == '/' ? "" : "/dev/dsk/", old_disk);
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 (void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
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));
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) snprintf(zc.zc_prop_value, sizeof (zc.zc_prop_value),
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens dgettext(TEXT_DOMAIN, "cannot detach %s"), zc.zc_prop_value);
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);
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);