libzfs_pool.c revision b1b8ab34de515a5e83206da22c3d7e563241b021
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
39c23413b8df94a95f67b34cfd4a4dfc3fd0b48deschrock * Copyright 2007 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
99653d4ee642c6528e88224f12409a5f23060994eschrockzpool_name_valid(libzfs_handle_t *hdl, boolean_t isopen, const char *pool)
b468a217b67dc26ce21da5d5a2ca09bb6249e4faeschrock * The rules for reserved pool names were extended at a later point.
b468a217b67dc26ce21da5d5a2ca09bb6249e4faeschrock * But we need to support users with existing pools that may now be
b468a217b67dc26ce21da5d5a2ca09bb6249e4faeschrock * invalid. So we only check for this expanded set of names during a
b468a217b67dc26ce21da5d5a2ca09bb6249e4faeschrock * create (or import), and only in userland.
b468a217b67dc26ce21da5d5a2ca09bb6249e4faeschrock if (ret != 0) {
99653d4ee642c6528e88224f12409a5f23060994eschrock "name must begin with a letter"));
99653d4ee642c6528e88224f12409a5f23060994eschrock "name is reserved"));
99653d4ee642c6528e88224f12409a5f23060994eschrock "pool name is reserved"));
5ad820458efd0fdb914baff9c1447c22b819fa23nd "leading slash in name"));
5ad820458efd0fdb914baff9c1447c22b819fa23nd "empty component in name"));
5ad820458efd0fdb914baff9c1447c22b819fa23nd "trailing slash in name"));
5ad820458efd0fdb914baff9c1447c22b819fa23nd "multiple '@' delimiters in name"));
b1b8ab34de515a5e83206da22c3d7e563241b021lling (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (-1);
b1b8ab34de515a5e83206da22c3d7e563241b021lling while (ioctl(hdl->libzfs_fd, ZFS_IOC_POOL_GET_PROPS, &zc) != 0) {
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (-1);
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (-1);
b1b8ab34de515a5e83206da22c3d7e563241b021lling if (zcmd_read_dst_nvlist(hdl, &zc, &zhp->zpool_props) != 0) {
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (-1);
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Open a handle to the given pool, even if the pool is currently in the FAULTED
99653d4ee642c6528e88224f12409a5f23060994eschrockzpool_open_canfail(libzfs_handle_t *hdl, const char *pool)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Make sure the pool name is valid.
99653d4ee642c6528e88224f12409a5f23060994eschrock if ((zhp = zfs_alloc(hdl, sizeof (zpool_handle_t))) == NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zhp->zpool_name, pool, sizeof (zhp->zpool_name));
94de1d4cf6ec0a3bf040dcc4b8df107c4ed36b51eschrock "no such pool"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Like the above, but silent on error. Used when iterating over pools (because
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the configuration cache may be out of date).
94de1d4cf6ec0a3bf040dcc4b8df107c4ed36b51eschrockzpool_open_silent(libzfs_handle_t *hdl, const char *pool, zpool_handle_t **ret)
94de1d4cf6ec0a3bf040dcc4b8df107c4ed36b51eschrock if ((zhp = zfs_alloc(hdl, sizeof (zpool_handle_t))) == NULL)
94de1d4cf6ec0a3bf040dcc4b8df107c4ed36b51eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zhp->zpool_name, pool, sizeof (zhp->zpool_name));
94de1d4cf6ec0a3bf040dcc4b8df107c4ed36b51eschrock return (-1);
94de1d4cf6ec0a3bf040dcc4b8df107c4ed36b51eschrock return (0);
94de1d4cf6ec0a3bf040dcc4b8df107c4ed36b51eschrock return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Similar to zpool_open_canfail(), but refuses to open pools in the faulted
99653d4ee642c6528e88224f12409a5f23060994eschrock dgettext(TEXT_DOMAIN, "cannot open '%s'"), zhp->zpool_name);
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,
99653d4ee642c6528e88224f12409a5f23060994eschrock * Return the version of the pool.
99653d4ee642c6528e88224f12409a5f23060994eschrock verify(nvlist_lookup_uint64(zhp->zpool_config, ZPOOL_CONFIG_VERSION,
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));
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, &zc) != 0 ||
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.
99653d4ee642c6528e88224f12409a5f23060994eschrockzpool_create(libzfs_handle_t *hdl, const char *pool, nvlist_t *nvroot,
99653d4ee642c6528e88224f12409a5f23060994eschrock const char *altroot)
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
99653d4ee642c6528e88224f12409a5f23060994eschrock dgettext(TEXT_DOMAIN, "bad alternate root '%s'"), altroot));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (zcmd_write_src_nvlist(hdl, &zc, nvroot, NULL) != 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, pool, sizeof (zc.zc_name));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(zc.zc_value, altroot, sizeof (zc.zc_value));
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(hdl->libzfs_fd, ZFS_IOC_POOL_CREATE, &zc) != 0) {
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
99653d4ee642c6528e88224f12409a5f23060994eschrock "one or more vdevs refer to the same device"));
99653d4ee642c6528e88224f12409a5f23060994eschrock * This occurs 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.
99653d4ee642c6528e88224f12409a5f23060994eschrock "one or more devices is less than the "
99653d4ee642c6528e88224f12409a5f23060994eschrock "one or more devices is out of space"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If this is an alternate root pool, then we automatically set the
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * mountpoint of the root dataset to be '/'.
99653d4ee642c6528e88224f12409a5f23060994eschrock verify((zhp = zfs_open(hdl, pool, ZFS_TYPE_ANY)) != NULL);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock verify(zfs_prop_set(zhp, zfs_prop_to_name(ZFS_PROP_MOUNTPOINT),
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock "/") == 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 return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_POOL_DESTROY, &zc) != 0) {
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
99653d4ee642c6528e88224f12409a5f23060994eschrock "one or more devices is 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.
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
99653d4ee642c6528e88224f12409a5f23060994eschrock nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
99653d4ee642c6528e88224f12409a5f23060994eschrock zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "pool must be "
99653d4ee642c6528e88224f12409a5f23060994eschrock "upgraded to add hot spares"));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (zcmd_write_src_nvlist(hdl, &zc, nvroot, NULL) != 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_VDEV_ADD, &zc) != 0) {
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
99653d4ee642c6528e88224f12409a5f23060994eschrock "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.
99653d4ee642c6528e88224f12409a5f23060994eschrock "device is less than the minimum "
99653d4ee642c6528e88224f12409a5f23060994eschrock "pool must be upgraded to add raidz2 vdevs"));
b1b8ab34de515a5e83206da22c3d7e563241b021lling "root pool can not have concatenated devices"));
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));
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_POOL_EXPORT, &zc) != 0)
ece3d9b3bacef51a5f34d993935eedbb7bb87059lling return (zpool_standard_error_fmt(zhp->zpool_hdl, errno,
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.
99653d4ee642c6528e88224f12409a5f23060994eschrockzpool_import(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,
99653d4ee642c6528e88224f12409a5f23060994eschrock const char *altroot)
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
fa9e4066f08beec538e775443c5be79dd423fcabahrens (void) strlcpy(zc.zc_name, thename, sizeof (zc.zc_name));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strlcpy(zc.zc_value, altroot, sizeof (zc.zc_value));
fa9e4066f08beec538e775443c5be79dd423fcabahrens verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (zcmd_write_src_nvlist(hdl, &zc, config, NULL) != 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(hdl->libzfs_fd, ZFS_IOC_POOL_IMPORT, &zc) != 0) {
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));
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_POOL_SCRUB, &zc) == 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens dgettext(TEXT_DOMAIN, "cannot scrub %s"), zc.zc_name);
a43d325b828008a3ab54eed57fd7c00b6470172bek * 'avail_spare' is set to TRUE if the provided guid refers to an AVAIL
a43d325b828008a3ab54eed57fd7c00b6470172bek * spare; but FALSE if its an INUSE spare.
99653d4ee642c6528e88224f12409a5f23060994eschrockvdev_to_nvlist_iter(nvlist_t *nv, const char *search, uint64_t guid,
99653d4ee642c6528e88224f12409a5f23060994eschrock verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &theguid) == 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 for (c = 0; c < children; c++)
99653d4ee642c6528e88224f12409a5f23060994eschrock if ((ret = vdev_to_nvlist_iter(child[c], search, guid,
99653d4ee642c6528e88224f12409a5f23060994eschrock if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
99653d4ee642c6528e88224f12409a5f23060994eschrock for (c = 0; c < children; c++) {
99653d4ee642c6528e88224f12409a5f23060994eschrock if ((ret = vdev_to_nvlist_iter(child[c], search, guid,
a43d325b828008a3ab54eed57fd7c00b6470172bekzpool_find_vdev(zpool_handle_t *zhp, const char *path, boolean_t *avail_spare)
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,
a43d325b828008a3ab54eed57fd7c00b6470172bek return (vdev_to_nvlist_iter(nvroot, search, guid, avail_spare));
a43d325b828008a3ab54eed57fd7c00b6470172bek * Returns TRUE if the given guid corresponds to a spare (INUSE or not).
a43d325b828008a3ab54eed57fd7c00b6470172bek verify(nvlist_lookup_nvlist(zhp->zpool_config, ZPOOL_CONFIG_VDEV_TREE,
a43d325b828008a3ab54eed57fd7c00b6470172bek if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
a43d325b828008a3ab54eed57fd7c00b6470172bek for (i = 0; i < nspares; i++) {
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));
a43d325b828008a3ab54eed57fd7c00b6470172bek if ((tgt = zpool_find_vdev(zhp, path, &avail_spare)) == NULL)
99653d4ee642c6528e88224f12409a5f23060994eschrock verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0);
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_VDEV_ONLINE, &zc) == 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock return (0);
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));
a43d325b828008a3ab54eed57fd7c00b6470172bek if ((tgt = zpool_find_vdev(zhp, path, &avail_spare)) == NULL)
99653d4ee642c6528e88224f12409a5f23060994eschrock verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0);
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_VDEV_OFFLINE, &zc) == 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * There are no other replicas of this device.
99653d4ee642c6528e88224f12409a5f23060994eschrock * Returns TRUE if the given nvlist is a vdev that was originally swapped in as
99653d4ee642c6528e88224f12409a5f23060994eschrock * a hot spare.
99653d4ee642c6528e88224f12409a5f23060994eschrockis_replacing_spare(nvlist_t *search, nvlist_t *tgt, int which)
99653d4ee642c6528e88224f12409a5f23060994eschrock if (nvlist_lookup_nvlist_array(search, ZPOOL_CONFIG_CHILDREN, &child,
99653d4ee642c6528e88224f12409a5f23060994eschrock verify(nvlist_lookup_string(search, ZPOOL_CONFIG_TYPE,
99653d4ee642c6528e88224f12409a5f23060994eschrock for (c = 0; c < children; c++)
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));
a43d325b828008a3ab54eed57fd7c00b6470172bek if ((tgt = zpool_find_vdev(zhp, old_disk, &avail_spare)) == 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0);
99653d4ee642c6528e88224f12409a5f23060994eschrock if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN,
99653d4ee642c6528e88224f12409a5f23060994eschrock "new device must be a single disk"));
99653d4ee642c6528e88224f12409a5f23060994eschrock verify(nvlist_lookup_nvlist(zpool_get_config(zhp, NULL),
99653d4ee642c6528e88224f12409a5f23060994eschrock * If the target is a hot spare that has been swapped in, we can only
99653d4ee642c6528e88224f12409a5f23060994eschrock * replace it with another hot spare.
99653d4ee642c6528e88224f12409a5f23060994eschrock nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_IS_SPARE, &val) == 0 &&
99653d4ee642c6528e88224f12409a5f23060994eschrock nvlist_lookup_string(child[0], ZPOOL_CONFIG_PATH, &path) == 0 &&
a43d325b828008a3ab54eed57fd7c00b6470172bek !avail_spare) && is_replacing_spare(config_root, tgt, 1)) {
99653d4ee642c6528e88224f12409a5f23060994eschrock "can only be replaced by another hot spare"));
99653d4ee642c6528e88224f12409a5f23060994eschrock * If we are attempting to replace a spare, it canot be applied to an
99653d4ee642c6528e88224f12409a5f23060994eschrock * already spared device.
99653d4ee642c6528e88224f12409a5f23060994eschrock nvlist_lookup_string(child[0], ZPOOL_CONFIG_PATH, &path) == 0 &&
a43d325b828008a3ab54eed57fd7c00b6470172bek zpool_find_vdev(zhp, path, &avail_spare) != NULL && avail_spare &&
99653d4ee642c6528e88224f12409a5f23060994eschrock "device has already been replaced with a spare"));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if (zcmd_write_src_nvlist(hdl, &zc, nvroot, NULL) != 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
99653d4ee642c6528e88224f12409a5f23060994eschrock ret = ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_VDEV_ATTACH, &zc);
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Can't attach to or replace this type of vdev.
99653d4ee642c6528e88224f12409a5f23060994eschrock "cannot replace a replacing device"));
99653d4ee642c6528e88224f12409a5f23060994eschrock "can only attach to mirrors and top-level "
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The new device must be a single disk.
99653d4ee642c6528e88224f12409a5f23060994eschrock "new device must be a single disk"));
99653d4ee642c6528e88224f12409a5f23060994eschrock zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "%s is busy"),
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The new device is too small.
99653d4ee642c6528e88224f12409a5f23060994eschrock "device is too small"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The new device has a different alignment requirement.
99653d4ee642c6528e88224f12409a5f23060994eschrock "devices have different sector alignment"));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The resulting top-level vdev spec won't fit in the label.
99653d4ee642c6528e88224f12409a5f23060994eschrock 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));
a43d325b828008a3ab54eed57fd7c00b6470172bek if ((tgt = zpool_find_vdev(zhp, path, &avail_spare)) == 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0);
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(hdl->libzfs_fd, ZFS_IOC_VDEV_DETACH, &zc) == 0)
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Can't detach from this type of vdev.
99653d4ee642c6528e88224f12409a5f23060994eschrock "applicable to mirror and replacing vdevs"));
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) zfs_error(zhp->zpool_hdl, EZFS_BADTARGET, msg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * There are no other replicas of this device.
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
99653d4ee642c6528e88224f12409a5f23060994eschrock * Remove the given device. Currently, this is supported only for hot spares.
99653d4ee642c6528e88224f12409a5f23060994eschrockzpool_vdev_remove(zpool_handle_t *zhp, const char *path)
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
a43d325b828008a3ab54eed57fd7c00b6470172bek if ((tgt = zpool_find_vdev(zhp, path, &avail_spare)) == 0)
39c23413b8df94a95f67b34cfd4a4dfc3fd0b48deschrock "only inactive hot spares can be removed"));
99653d4ee642c6528e88224f12409a5f23060994eschrock verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0);
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(hdl->libzfs_fd, ZFS_IOC_VDEV_REMOVE, &zc) == 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock return (0);
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));
a43d325b828008a3ab54eed57fd7c00b6470172bek if ((tgt = zpool_find_vdev(zhp, path, &avail_spare)) == 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID,
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(hdl->libzfs_fd, ZFS_IOC_CLEAR, &zc) == 0)
99653d4ee642c6528e88224f12409a5f23060994eschrock return (0);
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * Iterate over all zvols in a given pool by walking the /dev/zvol/dsk/<pool>
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * hierarchy.
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahlzpool_iter_zvol(zpool_handle_t *zhp, int (*cb)(const char *, void *),
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * Oddly this wasn't a directory -- ignore that failure since we
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * know there are no links lower in the (non-existant) hierarchy.
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl return (0);
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl if ((paths = zfs_alloc(hdl, size * sizeof (paths[0]))) == NULL) {
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl return (-1);
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl (void) strlcpy(paths[0], zhp->zpool_name, sizeof (paths[0]));
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl while (curr >= 0) {
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl if (fstatat(base, paths[curr], &st, AT_SYMLINK_NOFOLLOW) != 0)
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl return (-1);
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahltypedef struct zvol_cb {
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl/*ARGSUSED*/
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Iterate over all zvols in the pool and make any necessary minor nodes.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If the pool is unavailable, just return success.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * Iterate over all zvols in the pool and remove any minor nodes. We iterate
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * by examining the /dev links so that a corrupted pool doesn't impede this
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl * operation.
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));
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock (void) strncpy(zc.zc_value, path, sizeof (zc.zc_value));
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_VDEV_SETPATH, &zc);
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.
99653d4ee642c6528e88224f12409a5f23060994eschrockzpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv)
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);
99653d4ee642c6528e88224f12409a5f23060994eschrock * If it's a raidz device, we need to stick in the parity level.
99653d4ee642c6528e88224f12409a5f23060994eschrock verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NPARITY,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockzbookmark_compare(const void *a, const void *b)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Retrieve the persistent error log, uniquify the members, and return to the
55434c770c89aa1b84474f2559a106803511aba0ekzpool_get_errlog(zpool_handle_t *zhp, nvlist_t **nverrlistp)
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,
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock if ((zc.zc_nvlist_dst = (uintptr_t)zfs_alloc(zhp->zpool_hdl,
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_ERROR_LOG,
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
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
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * to first, and 'zc_nvlist_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.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock zb = ((zbookmark_t *)(uintptr_t)zc.zc_nvlist_dst) +
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock qsort(zb, count, sizeof (zbookmark_t), zbookmark_compare);
55434c770c89aa1b84474f2559a106803511aba0ek * Fill in the nverrlistp with nvlist's of dataset and object numbers.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock for (i = 0; i < count; i++) {
c0a81264b59ba24de8701436570c3aae5689dc89ek /* ignoring zb_blkid and zb_level for now */
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (0);
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock * Upgrade a ZFS pool to the latest on-disk version.
99653d4ee642c6528e88224f12409a5f23060994eschrock if (ioctl(hdl->libzfs_fd, ZFS_IOC_POOL_UPGRADE, &zc) != 0)
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock return (0);
06eeb2ad640ce72d394ac521094bed7681044408ek * Log command history.
06eeb2ad640ce72d394ac521094bed7681044408ek * 'pool' is B_TRUE if we are logging a command for 'zpool'; B_FALSE
06eeb2ad640ce72d394ac521094bed7681044408ek * otherwise ('zfs'). 'pool_create' is B_TRUE if we are logging the creation
06eeb2ad640ce72d394ac521094bed7681044408ek * of the pool; B_FALSE otherwise. 'path' is the pathanme containing the
06eeb2ad640ce72d394ac521094bed7681044408ek * poolname. 'argc' and 'argv' are used to construct the command string.
06eeb2ad640ce72d394ac521094bed7681044408ekzpool_log_history(libzfs_handle_t *hdl, int argc, char **argv, const char *path,
06eeb2ad640ce72d394ac521094bed7681044408ek /* construct the command string */
06eeb2ad640ce72d394ac521094bed7681044408ek for (i = 0; i < argc; i++) {
06eeb2ad640ce72d394ac521094bed7681044408ek if (strlen(cmd_buf) + 1 + strlen(argv[i]) > HIS_MAX_RECORD_LEN)
06eeb2ad640ce72d394ac521094bed7681044408ek /* figure out the poolname */
06eeb2ad640ce72d394ac521094bed7681044408ek /* overloading zc_history_offset */
06eeb2ad640ce72d394ac521094bed7681044408ek (void) ioctl(hdl->libzfs_fd, ZFS_IOC_POOL_LOG_HISTORY, &zc);
06eeb2ad640ce72d394ac521094bed7681044408ek * Perform ioctl to get some command history of a pool.
06eeb2ad640ce72d394ac521094bed7681044408ek * 'buf' is the buffer to fill up to 'len' bytes. 'off' is the
06eeb2ad640ce72d394ac521094bed7681044408ek * logical offset of the history buffer to start reading from.
06eeb2ad640ce72d394ac521094bed7681044408ek * Upon return, 'off' is the next logical offset to read from and
06eeb2ad640ce72d394ac521094bed7681044408ek * 'len' is the actual amount of bytes read into 'buf'.
06eeb2ad640ce72d394ac521094bed7681044408ekget_history(zpool_handle_t *zhp, char *buf, uint64_t *off, uint64_t *len)
06eeb2ad640ce72d394ac521094bed7681044408ek (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
06eeb2ad640ce72d394ac521094bed7681044408ek if (ioctl(hdl->libzfs_fd, ZFS_IOC_POOL_GET_HISTORY, &zc) != 0) {
06eeb2ad640ce72d394ac521094bed7681044408ek switch (errno) {
06eeb2ad640ce72d394ac521094bed7681044408ek "cannot show history for pool '%s'"),
06eeb2ad640ce72d394ac521094bed7681044408ek return (0);
06eeb2ad640ce72d394ac521094bed7681044408ek * Process the buffer of nvlists, unpacking and storing each nvlist record
06eeb2ad640ce72d394ac521094bed7681044408ek * into 'records'. 'leftover' is set to the number of bytes that weren't
06eeb2ad640ce72d394ac521094bed7681044408ek * processed as there wasn't a complete record.
06eeb2ad640ce72d394ac521094bed7681044408ekzpool_history_unpack(char *buf, uint64_t bytes_read, uint64_t *leftover,
06eeb2ad640ce72d394ac521094bed7681044408ek /* get length of packed record (stored as little endian) */
06eeb2ad640ce72d394ac521094bed7681044408ek /* unpack record */
06eeb2ad640ce72d394ac521094bed7681044408ek if (nvlist_unpack(buf + sizeof (reclen), reclen, &nv, 0) != 0)
06eeb2ad640ce72d394ac521094bed7681044408ek /* add record to nvlist array */
06eeb2ad640ce72d394ac521094bed7681044408ek return (0);
06eeb2ad640ce72d394ac521094bed7681044408ek * Retrieve the command history of a pool.
06eeb2ad640ce72d394ac521094bed7681044408ek if ((err = get_history(zhp, buf, &off, &bytes_read)) != 0)
06eeb2ad640ce72d394ac521094bed7681044408ek /* if nothing else was read in, we're at EOF, just return */
06eeb2ad640ce72d394ac521094bed7681044408ek /* CONSTCOND */
06eeb2ad640ce72d394ac521094bed7681044408ek } while (1);
06eeb2ad640ce72d394ac521094bed7681044408ek verify(nvlist_add_nvlist_array(*nvhisp, ZPOOL_HIST_RECORD,
06eeb2ad640ce72d394ac521094bed7681044408ek for (i = 0; i < numrecords; i++)
55434c770c89aa1b84474f2559a106803511aba0ekzpool_obj_to_path(zpool_handle_t *zhp, uint64_t dsobj, uint64_t obj,
55434c770c89aa1b84474f2559a106803511aba0ek if (dsobj == 0) {
55434c770c89aa1b84474f2559a106803511aba0ek /* special case for the MOS */
55434c770c89aa1b84474f2559a106803511aba0ek (void) snprintf(pathname, len, "<metadata>:<0x%llx>", obj);
55434c770c89aa1b84474f2559a106803511aba0ek /* get the dataset's name */
55434c770c89aa1b84474f2559a106803511aba0ek (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
55434c770c89aa1b84474f2559a106803511aba0ek /* just write out a path of two object numbers */
55434c770c89aa1b84474f2559a106803511aba0ek /* find out if the dataset is mounted */
55434c770c89aa1b84474f2559a106803511aba0ek /* get the corrupted object's path */
55434c770c89aa1b84474f2559a106803511aba0ek if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_OBJ_TO_PATH,
55434c770c89aa1b84474f2559a106803511aba0ek &zc) == 0) {
55434c770c89aa1b84474f2559a106803511aba0ek (void) snprintf(pathname, len, "%s:<0x%llx>", dsname, obj);
b1b8ab34de515a5e83206da22c3d7e563241b021llingzpool_set_prop(zpool_handle_t *zhp, const char *propname, const char *propval)
b1b8ab34de515a5e83206da22c3d7e563241b021lling dgettext(TEXT_DOMAIN, "cannot set property for '%s'"),
b1b8ab34de515a5e83206da22c3d7e563241b021lling "upgraded to support pool properties"));
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (zfs_error(zhp->zpool_hdl, EZFS_BADVERSION, errbuf));
b1b8ab34de515a5e83206da22c3d7e563241b021lling if (zhp->zpool_props == NULL && zpool_get_all_props(zhp))
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (zfs_error(zhp->zpool_hdl, EZFS_POOLPROPS, errbuf));
b1b8ab34de515a5e83206da22c3d7e563241b021lling if ((realprops = zfs_validate_properties(zhp->zpool_hdl, ZFS_TYPE_POOL,
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (-1);
b1b8ab34de515a5e83206da22c3d7e563241b021lling * Execute the corresponding ioctl() to set this property.
b1b8ab34de515a5e83206da22c3d7e563241b021lling (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
b1b8ab34de515a5e83206da22c3d7e563241b021lling if (zcmd_write_src_nvlist(zhp->zpool_hdl, &zc, nvl, NULL) != 0)
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (-1);
b1b8ab34de515a5e83206da22c3d7e563241b021lling ret = ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_POOL_SET_PROPS, &zc);
b1b8ab34de515a5e83206da22c3d7e563241b021lling (void) zpool_standard_error(zhp->zpool_hdl, errno, errbuf);
b1b8ab34de515a5e83206da22c3d7e563241b021llingzpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *propbuf,
b1b8ab34de515a5e83206da22c3d7e563241b021lling (void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
b1b8ab34de515a5e83206da22c3d7e563241b021lling "cannot get property '%s'"), zpool_prop_to_name(prop));
b1b8ab34de515a5e83206da22c3d7e563241b021lling "upgraded to support pool properties"));
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (zfs_error(zhp->zpool_hdl, EZFS_BADVERSION, msg));
b1b8ab34de515a5e83206da22c3d7e563241b021lling if (zhp->zpool_props == NULL && zpool_get_all_props(zhp))
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (zfs_error(zhp->zpool_hdl, EZFS_POOLPROPS, msg));
b1b8ab34de515a5e83206da22c3d7e563241b021lling * the "name" property is special cased
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (-1);
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (-1);
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (-1);
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (0);
b1b8ab34de515a5e83206da22c3d7e563241b021llingzpool_get_proplist(libzfs_handle_t *hdl, char *fields, zpool_proplist_t **listp)
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (zfs_get_proplist_common(hdl, fields, listp, ZFS_TYPE_POOL));
b1b8ab34de515a5e83206da22c3d7e563241b021llingzpool_expand_proplist(zpool_handle_t *zhp, zpool_proplist_t **plp)
b1b8ab34de515a5e83206da22c3d7e563241b021lling if (zfs_expand_proplist_common(hdl, plp, ZFS_TYPE_POOL) != 0)
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (-1);
b1b8ab34de515a5e83206da22c3d7e563241b021lling for (entry = *plp; entry != NULL; entry = entry->pl_next) {
b1b8ab34de515a5e83206da22c3d7e563241b021lling zpool_get_prop(zhp, entry->pl_prop, buf, sizeof (buf),
b1b8ab34de515a5e83206da22c3d7e563241b021lling return (0);