/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Functions to convert between a list of vdevs and an nvlist representing the
* configuration. Each entry in the list can be one of:
*
* Device vdevs
* disk=(path=..., devid=...)
* file=(path=...)
*
* Group vdevs
* raidz[1|2]=(...)
* mirror=(...)
*
* Hot spares
*
* While the underlying implementation supports it, group vdevs cannot contain
* other group vdevs. All userland verification of devices is contained within
* this file. If successful, the nvlist returned can be passed directly to the
* kernel; we've done as much verification as possible in userland.
*
* Hot spares are a special case, and passed down as an array of disk vdevs, at
* the same level as the root of the vdev tree.
*
* Functions exported by this file:
* 'zpool_make_root_vdev' - the function performs several passes:
*
* 1. Construct the vdev specification. Performs syntax validation and
* makes sure each device is valid.
* 2. Check for devices in use. Using libdiskmgt, makes sure that no
* devices are also in use. Some can be overridden using the 'force'
* flag, others cannot.
* 3. Check for replication errors if the 'force' flag is not specified.
* validates that the replication level is consistent across the
* entire pool.
* 4. Label any whole disks with an EFI label.
*
* 'zpool_split_root_vdev' - the function performs several passes:
*
* 1. Construct the vdev specification. Performs syntax validation and
* makes sure each device is valid.
* 2. Check target device if its eligable for splitting.
* 3. Initiate the actual split.
*/
#include <assert.h>
#include <ctype.h>
#include <devid.h>
#include <errno.h>
#include <fcntl.h>
#include <libdiskmgt.h>
#include <libdevinfo.h>
#include <libintl.h>
#include <libnvpair.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/efi_partition.h>
#include <sys/stat.h>
#include <sys/vtoc.h>
#include <sys/mntent.h>
#include <sys/paths.h>
#include <libzfs_impl.h>
#define DISK_ROOT _PATH_DEV "dsk"
#define RDISK_ROOT _PATH_DEV "rdsk"
#define BACKUP_SLICE "s2"
/*
* For any given vdev specification, we can have multiple errors. The
* vdev_error() function keeps track of whether we have seen an error yet, and
* prints out a header if its the first error we've seen.
*/
/*PRINTFLIKE4*/
static void
vdev_error(libzfs_handle_t *hdl, boolean_t force, int error,
const char *fmt, ...)
{
static boolean_t error_seen = B_FALSE;
char msg[1024];
va_list ap;
if (!error_seen) {
error_seen = B_TRUE;
if (!force) {
(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
"use -f to override the following errors:"));
} else {
(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
"the following errors must be manually repaired:"));
}
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "%s"), msg);
(void) zfs_error(hdl, error, dgettext(TEXT_DOMAIN,
"vdev verification failed"));
}
va_start(ap, fmt);
(void) vfprintf(stderr, fmt, ap);
va_end(ap);
}
static void
internal_error(libzfs_handle_t *hdl, int error)
{
/*
* ENXIO/ENODEV is a valid error message if the device doesn't live in
* /dev/dsk. Don't bother printing an error message in this case.
*/
if (error == ENXIO || error == ENODEV)
return;
(void) zfs_error_fmt(hdl, EZFS_INVALCONFIG, dgettext(TEXT_DOMAIN,
"device in use checking failed: %s\n"), strerror(error));
}
/*
* Validate a device, passing the bulk of the work off to libdiskmgt.
*/
static int
check_slice(libzfs_handle_t *hdl, const char *path, boolean_t force,
boolean_t wholedisk, boolean_t isspare)
{
char *msg;
int error = 0;
dm_who_type_t who;
if (force)
who = isspare ? DM_WHO_ZPOOL_SPARE_FORCE : DM_WHO_ZPOOL_FORCE;
else
who = isspare ? DM_WHO_ZPOOL_SPARE : DM_WHO_ZPOOL;
if (dm_inuse((char *)path, &msg, who, &error) || error) {
if (error != 0) {
internal_error(hdl, error);
return (0);
}
vdev_error(hdl, force, EZFS_DEV_INUSE, "%s", msg);
free(msg);
return (-1);
}
/*
* If we're given a whole disk, ignore overlapping slices since we're
* about to label it anyway.
*/
error = 0;
if (!wholedisk && !force &&
(dm_isoverlapping((char *)path, &msg, &error) || error)) {
if (error == 0) {
/* dm_isoverlapping returned -1 */
vdev_error(hdl, force, EZFS_DEV_INUSE,
gettext("%s overlaps with %s\n"), path, msg);
free(msg);
return (-1);
} else if (error != ENODEV) {
/* libdiskmgt's devcache only handles physical drives */
internal_error(hdl, error);
return (0);
}
}
return (0);
}
/*
* Validate a whole disk. Iterate over all slices on the disk and make sure
* that none is in use by calling check_slice().
*/
static int
check_disk(libzfs_handle_t *hdl, const char *name, dm_descriptor_t disk,
boolean_t force, int isspare)
{
dm_descriptor_t *drive, *media, *slice;
int err = 0;
int i, ret;
/*
* Get the drive associated with this disk. This should never fail,
* because we already have an alias handle open for the device.
*/
if ((drive = dm_get_associated_descriptors(disk, DM_DRIVE,
&err)) == NULL || *drive == NULL) {
if (err)
internal_error(hdl, err);
return (0);
}
if ((media = dm_get_associated_descriptors(*drive, DM_MEDIA,
&err)) == NULL) {
dm_free_descriptors(drive);
if (err)
internal_error(hdl, err);
return (0);
}
dm_free_descriptors(drive);
/*
* It is possible that the user has specified a removable media drive,
* and the media is not present.
*/
if (*media == NULL) {
dm_free_descriptors(media);
vdev_error(hdl, force, EZFS_BADDEV,
gettext("'%s' has no media in drive\n"), name);
return (-1);
}
if ((slice = dm_get_associated_descriptors(*media, DM_SLICE,
&err)) == NULL) {
dm_free_descriptors(media);
if (err)
internal_error(hdl, err);
return (0);
}
dm_free_descriptors(media);
ret = 0;
/*
* Iterate over all slices and report any errors. We don't care about
* overlapping slices because we are using the whole disk.
*/
for (i = 0; slice[i] != NULL; i++) {
char *name = dm_get_name(slice[i], &err);
if (check_slice(hdl, name, force, B_TRUE, isspare) != 0)
ret = -1;
dm_free_name(name);
}
dm_free_descriptors(slice);
return (ret);
}
/*
* Validate a device.
*/
static int
check_device(libzfs_handle_t *hdl, const char *path, boolean_t force,
boolean_t isspare)
{
dm_descriptor_t desc;
int err;
char *dev;
/*
* For whole disks, libdiskmgt does not include the leading dev path.
*/
dev = strrchr(path, '/');
assert(dev != NULL);
dev++;
if ((desc = dm_get_descriptor_by_name(DM_ALIAS, dev, &err)) != NULL) {
err = check_disk(hdl, path, desc, force, isspare);
dm_free_descriptor(desc);
return (err);
}
return (check_slice(hdl, path, force, B_FALSE, isspare));
}
/*
* Check that a file is valid. All we can do in this case is check that it's
* not in use by another pool, and not in use by swap.
*/
static int
check_file(libzfs_handle_t *hdl, const char *file, boolean_t force,
boolean_t isspare)
{
char *name;
int fd;
int ret = 0;
int err;
pool_state_t state;
boolean_t inuse;
if (dm_inuse_swap(file, &err)) {
if (err) {
internal_error(hdl, err);
} else {
vdev_error(hdl, force, EZFS_DEV_INUSE,
gettext("%s is currently used "
"by swap. Please see swap(1M).\n"), file);
}
return (-1);
}
if ((fd = open64(file, O_RDONLY)) < 0) {
(void) zfs_error_fmt(hdl, EZFS_OPENFAILED,
dgettext(TEXT_DOMAIN, "cannot open '%s': %s\n"),
file, strerror(errno));
return (-1);
}
if (zpool_in_use(hdl, fd, &state, &name, &inuse) == 0 && inuse) {
const char *desc;
switch (state) {
case POOL_STATE_ACTIVE:
desc = gettext("active");
break;
case POOL_STATE_EXPORTED:
desc = gettext("exported");
break;
case POOL_STATE_POTENTIALLY_ACTIVE:
desc = gettext("potentially active");
break;
default:
desc = gettext("unknown");
break;
}
/*
* Allow hot spares to be shared between pools.
*/
if (state == POOL_STATE_SPARE && isspare)
return (0);
if (state == POOL_STATE_ACTIVE ||
state == POOL_STATE_SPARE || !force) {
switch (state) {
case POOL_STATE_SPARE:
vdev_error(hdl, force, EZFS_DEV_INUSE,
gettext("%s is reserved as a hot spare "
"for ZFS pool '%s'. Please see "
"zpool(1M)\n"), file, name);
break;
default:
vdev_error(hdl, force, EZFS_DEV_INUSE,
gettext("%s is part of %s ZFS pool "
"'%s'. Please see zpool(1M)\n"),
file, desc, name);
break;
}
ret = -1;
}
free(name);
}
(void) close(fd);
return (ret);
}
/*
* By "whole disk" we mean an entire physical disk (something we can
* label, toggle the write cache on, etc.) as opposed to the full
* capacity of a pseudo-device such as lofi or did. We act as if we
* are labeling the disk, which should be a pretty good test of whether
* it's a viable device or not. Returns B_TRUE if it is and B_FALSE if
* it isn't.
*/
static boolean_t
is_whole_disk(const char *arg)
{
struct dk_gpt *label;
int fd;
char path[MAXPATHLEN];
(void) snprintf(path, sizeof (path), "%s%s%s",
RDISK_ROOT, strrchr(arg, '/'), BACKUP_SLICE);
if ((fd = open(path, O_RDWR | O_NDELAY)) < 0)
return (B_FALSE);
if (efi_alloc_and_init(fd, EFI_NUMPAR, &label) != 0) {
(void) close(fd);
return (B_FALSE);
}
efi_free(label);
(void) close(fd);
return (B_TRUE);
}
/*
* Create a leaf vdev. Determine if this is a file or a device. If it's a
* device, fill in the device id to make a complete nvlist. Valid forms for a
* leaf vdev are:
*
* /dev/dsk/xxx Complete disk path
* /xxx Full path to file
* xxx Shorthand for /dev/dsk/xxx
* /dev/chassis/.../disk Symlink to whole-disk (xxx shorthand)
*
* It is sufficient to only record the failure cause as we fail immediately,
* and the caller will issue the entire error message with zfs_error().
*/
static nvlist_t *
make_leaf_vdev(libzfs_handle_t *hdl, const char *arg, uint64_t is_log)
{
char *lvdev = NULL;
struct stat64 statbuf;
char *rp;
char path[MAXPATHLEN];
nvlist_t *vdev = NULL;
char *type = NULL;
boolean_t wholedisk = B_FALSE;
char *tmp;
/*
* If 'arg' is a symlink, read the link and try to convert it into
* a whole-disk ctd name. This is done to support references to
* /dev/chassis/.../disk, where the link value resolves to the
* /devices path. If the di_cro interfaces can convert the link value
* into a disk ctd name, then we proceed with that ctd name.
*
* NOTE: To insulate us from new cro fields, we use the string-based
* query interface.
*/
if (libzfs_get_cro_hdl(hdl) && (lstat64(arg, &statbuf) == 0) &&
S_ISLNK(statbuf.st_mode) &&
(rp = realpath(arg, NULL))) {
di_cro_reca_t ra;
di_cro_rec_t r;
int query_len;
char *query;
static const char *query_fmt =
DI_CRO_Q_OCCUPANT_TYPE DI_CRO_QREFMT ","
DI_CRO_Q_OCCUPANT_DEVICES DI_CRO_QREFMT;
query_len = strlen(query_fmt) +
strlen("disk") + strlen(rp) + 1;
if ((query = zfs_alloc(hdl, query_len)) == NULL)
goto noloc;
(void) snprintf(query, query_len, query_fmt, "disk", rp);
ra = di_cro_reca_create_query((di_cro_hdl_t)
libzfs_get_cro_hdl(hdl), 0, query);
r = di_cro_reca_next(ra, NULL);
lvdev = di_cro_rec_fgeti_occupant_compdev(r, 0, NULL, NULL);
di_cro_reca_destroy(ra);
free(query);
noloc: free(rp);
}
if (lvdev == NULL)
lvdev = (char *)arg;
/*
* Determine what type of vdev this is, and put the full path into
* 'path'. We detect whether this is a device of file afterwards by
* checking the st_mode of the file.
*/
if (lvdev[0] == '/') {
/*
* Complete device or file path. Exact type is determined by
* examining the file descriptor afterwards.
*/
wholedisk = is_whole_disk(lvdev);
if (!wholedisk && (stat64(lvdev, &statbuf) != 0)) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"cannot open '%s': %s"), arg, strerror(errno));
return (NULL);
}
(void) strlcpy(path, lvdev, sizeof (path));
} else {
/*
* This may be a short path for a device, or it could be total
* gibberish. Check to see if it's a known device in
* /dev/dsk/. As part of this check, see if we've been given a
* an entire disk (minus the slice number).
*/
(void) snprintf(path, sizeof (path), "%s/%s", DISK_ROOT,
lvdev);
wholedisk = is_whole_disk(path);
if (!wholedisk && (stat64(path, &statbuf) != 0)) {
/*
* If we got ENOENT, then the user gave us
* gibberish, so try to direct them with a
* reasonable error message. Otherwise,
* regurgitate strerror() since it's the best we
* can do.
*/
if (errno == ENOENT) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"cannot open '%s': no such device in %s\n"
"must be a full path or shorthand device "
"name"), arg, DISK_ROOT);
} else {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"cannot open '%s': %s"),
path, strerror(errno));
}
return (NULL);
}
}
/*
* Determine whether this is a device or a file.
*/
if (wholedisk || S_ISBLK(statbuf.st_mode)) {
type = VDEV_TYPE_DISK;
} else if (S_ISREG(statbuf.st_mode)) {
type = VDEV_TYPE_FILE;
} else {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "cannot use '%s': "
"must be a block device or regular file"), path);
return (NULL);
}
/*
* Finally, we have the complete device or file, and we know that it is
* acceptable to use. Construct the nvlist to describe this vdev. All
* vdevs have a 'path' element, and devices also have a 'devid' element.
*/
verify(nvlist_alloc(&vdev, NV_UNIQUE_NAME, 0) == 0);
verify(nvlist_add_string(vdev, ZPOOL_CONFIG_PATH, path) == 0);
verify(nvlist_add_string(vdev, ZPOOL_CONFIG_TYPE, type) == 0);
verify(nvlist_add_uint64(vdev, ZPOOL_CONFIG_IS_LOG, is_log) == 0);
if (strcmp(type, VDEV_TYPE_DISK) == 0)
verify(nvlist_add_uint64(vdev, ZPOOL_CONFIG_WHOLE_DISK,
(uint64_t)wholedisk) == 0);
/*
* Use di_cro interfaces to get /dev/chassis path.
*/
if ((tmp = zfs_alloc(hdl, strlen(path) + 1)) != NULL) {
if (strncmp(path, "/dev/dsk/", 9) == 0)
(void) strcpy(tmp, path + 9);
else
(void) strcpy(tmp, path);
if (tmp[0] == 'c' && isdigit(tmp[1])) {
di_cro_reca_t ra;
di_cro_rec_t r;
int query_len;
char *query, *slice, *dp = NULL;
static const char *query_fmt =
DI_CRO_Q_OCCUPANT_TYPE DI_CRO_QREFMT ","
DI_CRO_Q_OCCUPANT_COMPDEV DI_CRO_QREFMT;
if ((slice = strchr(tmp, 's')) != NULL)
*slice = '\0';
query_len = strlen(query_fmt) + strlen("disk") +
strlen(tmp) + 1;
if ((query = zfs_alloc(hdl, query_len)) != NULL) {
(void) snprintf(query, query_len, query_fmt,
"disk", tmp);
ra = di_cro_reca_create_query((di_cro_hdl_t)
libzfs_get_cro_hdl(hdl), 0, query);
r = di_cro_reca_next(ra, NULL);
if ((dp = di_cro_rec_fgeti_devchassis_path(r, 0,
NULL, NULL)) != NULL)
verify(nvlist_add_string(vdev,
ZPOOL_CONFIG_DEVCHASSIS, dp) == 0);
if ((dp = di_cro_rec_fgeti_chassis_id(r, 0,
NULL, NULL)) != NULL)
verify(nvlist_add_string(vdev,
ZPOOL_CONFIG_CHASSISSN, dp) == 0);
if ((dp = di_cro_rec_fgeti_receptacle_name(r, 0,
NULL, NULL)) != NULL)
verify(nvlist_add_string(vdev,
ZPOOL_CONFIG_LOCATION, dp) == 0);
di_cro_reca_destroy(ra);
free(query);
}
}
free(tmp);
}
/*
* For a whole disk, defer getting its devid until after labeling it.
*/
if (S_ISBLK(statbuf.st_mode) && !wholedisk) {
/*
* Get the devid for the device.
*/
int fd;
ddi_devid_t devid;
char *minor = NULL, *devid_str = NULL;
if ((fd = open(path, O_RDONLY)) < 0) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"cannot open '%s': %s"), path, strerror(errno));
nvlist_free(vdev);
return (NULL);
}
if (devid_get(fd, &devid) == 0) {
if (devid_get_minor_name(fd, &minor) == 0 &&
(devid_str = devid_str_encode(devid, minor)) !=
NULL) {
verify(nvlist_add_string(vdev,
ZPOOL_CONFIG_DEVID, devid_str) == 0);
}
if (devid_str != NULL)
devid_str_free(devid_str);
if (minor != NULL)
devid_str_free(minor);
devid_free(devid);
}
(void) close(fd);
}
return (vdev);
}
/*
* Go through and verify the replication level of the pool is consistent.
* Performs the following checks:
*
* For the new spec, verifies that devices in mirrors and raidz are the
* same size.
*
* If the current configuration already has inconsistent replication
* levels, ignore any other potential problems in the new spec.
*
* Otherwise, make sure that the current spec (if there is one) and the new
* spec have consistent replication levels.
*/
typedef struct replication_level {
const char *zprl_type;
uint64_t zprl_children;
uint64_t zprl_parity;
} replication_level_t;
#define ZPOOL_FUZZ (16 * 1024 * 1024)
/*
* Check one top-level vdev and its children to ensure we don't mix devices
* and files, and that the leaf vdevs are of approximately the same size.
*/
static boolean_t
check_tvdevs(libzfs_handle_t *hdl, nvlist_t **child, uint_t children,
replication_level_t *rep, boolean_t fatal, boolean_t force)
{
uint64_t vdev_size;
boolean_t reported;
const char *type;
int c;
/*
* This is a mirror or RAID-Z vdev. Go through and make
* sure the contents are all the same (files vs. disks),
* keeping track of the number of elements in the process.
*
* We also check that the size of each vdev (if it can
* be determined) is the same.
*
* The 'reported' variable indicates that we've
* already reported an error for this spec, so don't
* bother doing it again.
*/
type = NULL;
reported = B_FALSE;
vdev_size = -1ULL;
rep->zprl_children = 0;
for (c = 0; c < children; c++) {
nvlist_t *cnv = child[c];
char *path, *childtype;
struct stat64 statbuf;
uint64_t size = -1ULL;
int fd, err;
rep->zprl_children++;
verify(nvlist_lookup_string(cnv,
ZPOOL_CONFIG_TYPE, &childtype) == 0);
/*
* If this is a replacing or spare vdev, then
* get the real first child of the vdev.
*/
while (strcmp(childtype,
VDEV_TYPE_REPLACING) == 0 ||
strcmp(childtype, VDEV_TYPE_SPARE) == 0) {
nvlist_t **rchild;
uint_t rchildren;
verify(nvlist_lookup_nvlist_array(cnv,
ZPOOL_CONFIG_CHILDREN, &rchild,
&rchildren) == 0);
assert(rchildren > 1);
cnv = rchild[0];
verify(nvlist_lookup_string(cnv,
ZPOOL_CONFIG_TYPE,
&childtype) == 0);
}
verify(nvlist_lookup_string(cnv,
ZPOOL_CONFIG_PATH, &path) == 0);
/*
* If we have a raidz/mirror that combines disks
* with files, report it as an error.
*/
if (!reported && type != NULL && strcmp(type, childtype) != 0) {
if (!fatal)
return (B_FALSE);
vdev_error(hdl, force, EZFS_INVALCONFIG, gettext(
"mismatched replication level: %s contains both "
"files and devices\n"), rep->zprl_type);
reported = B_TRUE;
}
type = childtype;
/*
* According to stat(2), the value of 'st_size' is undefined
* for block devices and character devices. But there is no
* effective way to determine the real size in userland.
*
* Instead, we'll take advantage of an implementation detail of
* spec_size(). If the device is currently open, then we
* (should) return a valid size.
*
* If we still don't get a valid size (indicated by a size of 0
* or MAXOFFSET_T), then ignore this device altogether.
*/
if ((fd = open(path, O_RDONLY)) >= 0) {
err = fstat64(fd, &statbuf);
(void) close(fd);
} else {
err = stat64(path, &statbuf);
}
if (err != 0 ||
statbuf.st_size == 0 ||
statbuf.st_size == MAXOFFSET_T)
continue;
size = statbuf.st_size;
/*
* Also make sure that devices and slices have a consistent
* size. If they differ by a significant amount then report
* an error.
*/
if (!reported &&
(vdev_size != -1ULL &&
(labs(size - vdev_size) > ZPOOL_FUZZ))) {
if (!fatal)
return (B_FALSE);
vdev_error(hdl, force, EZFS_INVALCONFIG, gettext(
"%s contains devices of different sizes\n"),
rep->zprl_type);
reported = B_TRUE;
}
vdev_size = size;
}
/* success if we haven't reported an error */
return (!reported);
}
/*
* Check the replication levels in the existing pool's config and report
* an error if there is a mismatch.
*/
static boolean_t
compare_rep_levels(libzfs_handle_t *hdl, replication_level_t *lastrep,
replication_level_t *rep, boolean_t fatal, boolean_t force)
{
if (lastrep->zprl_type == NULL)
return (B_TRUE);
if (strcmp(lastrep->zprl_type, rep->zprl_type) != 0) {
if (fatal) {
vdev_error(hdl, force, EZFS_INVALCONFIG, gettext(
"mismatched replication level: both %s "
"and %s vdevs are present\n"),
lastrep->zprl_type, rep->zprl_type);
}
} else if (lastrep->zprl_parity != rep->zprl_parity) {
if (fatal) {
vdev_error(hdl, force, EZFS_INVALCONFIG, gettext(
"mismatched replication level: both %llu "
"and %llu and %llu device parity %s "
"vdevs are present\n"),
lastrep->zprl_parity,
rep->zprl_parity, rep->zprl_type);
}
} else if (lastrep->zprl_children != rep->zprl_children) {
if (fatal) {
vdev_error(hdl, force, EZFS_INVALCONFIG, gettext(
"mismatched replication level: both "
"%llu-way and %llu-way %s vdevs are "
"present\n"),
lastrep->zprl_children,
rep->zprl_children, rep->zprl_type);
}
} else {
return (B_TRUE);
}
return (B_FALSE);
}
/*
* Check the replication levels between the existing config and the
* config that the user wants to have. This differs from compare_rep_levels()
* only in the strings we output.
*/
static boolean_t
check_new_levels(libzfs_handle_t *hdl, replication_level_t *current,
replication_level_t *new, boolean_t force)
{
if (current->zprl_type == NULL || new->zprl_type == NULL)
return (B_TRUE);
if (strcmp(current->zprl_type, new->zprl_type) != 0) {
vdev_error(hdl, force, EZFS_INVALCONFIG, gettext(
"mismatched replication level: pool uses %s and new "
"vdev is %s\n"),
current->zprl_type, new->zprl_type);
} else if (current->zprl_parity != new->zprl_parity) {
vdev_error(hdl, force, EZFS_INVALCONFIG, gettext(
"mismatched replication level: pool uses %llu device "
"parity and new vdev uses %llu\n"),
current->zprl_parity, new->zprl_parity);
} else if (current->zprl_children != new->zprl_children) {
vdev_error(hdl, force, EZFS_INVALCONFIG, gettext(
"mismatched replication level: pool uses %llu-way %s "
"and new vdev uses %llu-way %s\n"),
current->zprl_children, current->zprl_type,
new->zprl_children, new->zprl_type);
} else {
return (B_TRUE);
}
return (B_FALSE);
}
/*
* Given a list of toplevel vdevs, determine if the configuration is
* self-consistent. If the config is inconsistent, return false. If 'fatal' is
* set, then an error message will be displayed for each self-inconsistent
* vdev.
*/
static boolean_t
valid_replication(libzfs_handle_t *hdl, nvlist_t *nvroot,
replication_level_t *pool, replication_level_t *slog, boolean_t fatal,
boolean_t force)
{
nvlist_t **top;
uint_t t, toplevels;
nvlist_t **child;
uint_t children;
nvlist_t *nv;
char *type;
replication_level_t *prev, rep;
boolean_t ret = B_TRUE;
pool->zprl_type = NULL;
slog->zprl_type = NULL;
verify(nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN,
&top, &toplevels) == 0);
for (t = 0; t < toplevels; t++) {
uint64_t is_log = B_FALSE;
nv = top[t];
/*
* For separate logs we ignore the top level vdev replication
* constraints.
*/
(void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_LOG, &is_log);
verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE,
&type) == 0);
rep.zprl_type = type;
rep.zprl_parity = 0;
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
&child, &children) != 0) {
/*
* This is a 'file' or 'disk' vdev.
*/
rep.zprl_children = 1;
} else {
/*
* If this is a raidz device, update the parity.
*/
if (strcmp(type, VDEV_TYPE_RAIDZ) == 0) {
verify(nvlist_lookup_uint64(nv,
ZPOOL_CONFIG_NPARITY,
&rep.zprl_parity) == 0);
assert(rep.zprl_parity != 0);
}
if (!check_tvdevs(hdl, child, children, &rep, fatal,
force)) {
if (!fatal)
return (B_FALSE);
ret = B_FALSE;
}
}
/*
* At this point, we have the replication of the last toplevel
* vdev in 'rep'. Compare it to the pool or the slog.
*/
prev = is_log ? slog : pool;
if (!compare_rep_levels(hdl, prev, &rep, fatal, force)) {
if (!fatal)
return (B_FALSE);
ret = B_FALSE;
}
*prev = rep;
}
return (ret);
}
/*
* Check the replication level of the vdev spec against the current pool. Calls
* valid_replication() to make sure the new spec is self-consistent. If the
* pool has a consistent replication level, then we ignore any errors.
* Otherwise, report any difference between the two.
*/
static int
check_replication(libzfs_handle_t *hdl, nvlist_t *config, nvlist_t *newroot,
boolean_t force)
{
nvlist_t **child;
uint_t children;
replication_level_t p_curr = {0}, p_new; /* pool info */
replication_level_t s_curr = {0}, s_new; /* slog info */
/*
* If we have a current pool configuration, check to see if it's
* self-consistent. If not, simply return success.
*/
if (config != NULL) {
nvlist_t *nvroot;
verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
&nvroot) == 0);
if (!valid_replication(hdl, nvroot, &p_curr, &s_curr, B_FALSE,
force))
return (0);
}
/*
* for spares there may be no children, and therefore no
* replication level to check
*/
if ((nvlist_lookup_nvlist_array(newroot, ZPOOL_CONFIG_CHILDREN,
&child, &children) != 0) || (children == 0))
return (0);
/*
* Get the replication level of the new vdev spec, reporting any
* inconsistencies found.
*/
if (!valid_replication(hdl, newroot, &p_new, &s_new, B_TRUE, force))
return (-1);
/*
* Check to see if the new vdev spec matches the replication level of
* the current pool.
*/
if (!check_new_levels(hdl, &p_curr, &p_new, force) ||
!check_new_levels(hdl, &s_curr, &s_new, force))
return (-1);
return (0);
}
/*
* Go through and find any whole disks in the vdev specification, labelling them
* as appropriate. When constructing the vdev spec, we were unable to open this
* device in order to provide a devid. Now that we have labelled the disk and
* know that slice 0 is valid, we can construct the devid now.
*
* If the disk was already labeled with an EFI label, we will have gotten the
* devid already (because we were able to open the whole disk). Otherwise, we
* need to get the devid after we label the disk.
*/
static int
make_disks(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv,
int create_req_part)
{
nvlist_t **child;
uint_t c, children;
char *type, *path, *diskname;
char buf[MAXPATHLEN];
uint64_t wholedisk;
int fd;
int ret;
ddi_devid_t devid;
char *minor = NULL, *devid_str = NULL;
int slicenum;
verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) == 0);
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
&child, &children) != 0) {
if (strcmp(type, VDEV_TYPE_DISK) != 0)
return (0);
/*
* We have a disk device. Get the path to the device
* and see if it's a whole disk by appending the backup
* slice and stat()ing the device.
*/
verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0);
if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_WHOLE_DISK,
&wholedisk) != 0 || !wholedisk)
return (0);
diskname = strrchr(path, '/');
assert(diskname != NULL);
diskname++;
if (zpool_label_disk(hdl, zhp, diskname, create_req_part,
&slicenum) == -1)
return (-1);
/*
* Fill in the devid, now that we've labeled the disk.
*/
(void) snprintf(buf, sizeof (buf), "%ss%d", path, slicenum);
if ((fd = open(buf, O_RDONLY)) < 0) {
(void) zfs_error_fmt(hdl, EZFS_OPENFAILED,
dgettext(TEXT_DOMAIN, "cannot open '%s': %s\n"),
buf, strerror(errno));
return (-1);
}
if (devid_get(fd, &devid) == 0) {
if (devid_get_minor_name(fd, &minor) == 0 &&
(devid_str = devid_str_encode(devid, minor)) !=
NULL) {
verify(nvlist_add_string(nv,
ZPOOL_CONFIG_DEVID, devid_str) == 0);
}
if (devid_str != NULL)
devid_str_free(devid_str);
if (minor != NULL)
devid_str_free(minor);
devid_free(devid);
}
/*
* Update the path to refer to the slice. The presence of
* the 'whole_disk' field indicates to the CLI that we should
* chop off the slice number when displaying the device in
* future output.
*/
verify(nvlist_add_string(nv, ZPOOL_CONFIG_PATH, buf) == 0);
(void) close(fd);
return (0);
}
for (c = 0; c < children; c++) {
if ((ret = make_disks(hdl, zhp, child[c],
create_req_part)) != 0)
return (ret);
}
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
&child, &children) == 0) {
for (c = 0; c < children; c++) {
if ((ret = make_disks(hdl, zhp, child[c],
create_req_part)) != 0)
return (ret);
}
}
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
&child, &children) == 0) {
for (c = 0; c < children; c++) {
if ((ret = make_disks(hdl, zhp, child[c],
create_req_part)) != 0)
return (ret);
}
}
return (0);
}
/*
* Determine if the given path is a hot spare within the given configuration.
*/
static boolean_t
is_spare(libzfs_handle_t *hdl, nvlist_t *config, const char *path)
{
int fd;
pool_state_t state;
char *name = NULL;
nvlist_t *label;
uint64_t guid, spareguid;
nvlist_t *nvroot;
nvlist_t **spares;
uint_t i, nspares;
boolean_t inuse;
if ((fd = open(path, O_RDONLY)) < 0)
return (B_FALSE);
if (zpool_in_use(hdl, fd, &state, &name, &inuse) != 0 ||
!inuse ||
state != POOL_STATE_SPARE ||
zpool_read_label(fd, &label) != 0) {
free(name);
(void) close(fd);
return (B_FALSE);
}
free(name);
(void) close(fd);
verify(nvlist_lookup_uint64(label, ZPOOL_CONFIG_GUID, &guid) == 0);
nvlist_free(label);
verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
&nvroot) == 0);
if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
&spares, &nspares) == 0) {
for (i = 0; i < nspares; i++) {
verify(nvlist_lookup_uint64(spares[i],
ZPOOL_CONFIG_GUID, &spareguid) == 0);
if (spareguid == guid)
return (B_TRUE);
}
}
return (B_FALSE);
}
/*
* Go through and find any devices that are in use. We rely on libdiskmgt for
* the majority of this task.
*/
static int
check_in_use(libzfs_handle_t *hdl, nvlist_t *config, nvlist_t *nv,
boolean_t force, boolean_t replacing, boolean_t isspare)
{
nvlist_t **child;
uint_t c, children;
int ret;
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
&child, &children) != 0) {
char buf[MAXPATHLEN];
char *type, *path;
uint64_t wholedisk;
verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) == 0);
verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0);
/*
* As a generic check, we look to see if this is a replace of a
* hot spare within the same pool. If so, we allow it
* regardless of what libdiskmgt or zpool_in_use() says.
*/
if (replacing) {
if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_WHOLE_DISK,
&wholedisk) == 0 && wholedisk) {
(void) snprintf(buf, sizeof (buf),
"%ss%d", path, 0);
if (is_spare(hdl, config, buf)) {
return (0);
} else {
(void) snprintf(buf,
sizeof (buf),
"%ss%d", path, 1);
if (is_spare(hdl, config, buf))
return (0);
}
} else {
(void) strlcpy(buf, path, sizeof (buf));
if (is_spare(hdl, config, buf))
return (0);
}
}
if (strcmp(type, VDEV_TYPE_DISK) == 0)
ret = check_device(hdl, path, force, isspare);
if (strcmp(type, VDEV_TYPE_FILE) == 0)
ret = check_file(hdl, path, force, isspare);
return (ret);
}
for (c = 0; c < children; c++) {
if ((ret = check_in_use(hdl, config, child[c], force,
replacing, B_FALSE)) != 0)
return (ret);
}
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
&child, &children) == 0) {
for (c = 0; c < children; c++) {
if ((ret = check_in_use(hdl, config, child[c], force,
replacing, B_TRUE)) != 0)
return (ret);
}
}
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
&child, &children) == 0) {
for (c = 0; c < children; c++) {
if ((ret = check_in_use(hdl, config, child[c], force,
replacing, B_FALSE)) != 0)
return (ret);
}
}
return (0);
}
static const char *
is_grouping(const char *type, int *mindev, int *maxdev)
{
if (strncmp(type, "raidz", 5) == 0) {
const char *p = type + 5;
char *end;
long nparity;
if (*p == '\0') {
nparity = 1;
} else if (*p == '0') {
return (NULL); /* no zero prefixes allowed */
} else {
errno = 0;
nparity = strtol(p, &end, 10);
if (errno != 0 || nparity < 1 || nparity >= 255 ||
*end != '\0')
return (NULL);
}
if (mindev != NULL)
*mindev = nparity + 1;
if (maxdev != NULL)
*maxdev = 255;
return (VDEV_TYPE_RAIDZ);
}
if (maxdev != NULL)
*maxdev = INT_MAX;
if (strcmp(type, "mirror") == 0) {
if (mindev != NULL)
*mindev = 2;
return (VDEV_TYPE_MIRROR);
}
if (strcmp(type, "spare") == 0) {
if (mindev != NULL)
*mindev = 1;
return (VDEV_TYPE_SPARE);
}
if (strcmp(type, "log") == 0) {
if (mindev != NULL)
*mindev = 1;
return (VDEV_TYPE_LOG);
}
if (strcmp(type, "cache") == 0) {
if (mindev != NULL)
*mindev = 1;
return (VDEV_TYPE_L2CACHE);
}
return (NULL);
}
/*
* Construct a syntactically valid vdev specification,
* and ensure that all devices and files exist and can be opened.
* It is sufficient to only record the failure cause as we fail immediately,
* and the caller will issue the entire error message with zfs_error().
*/
static nvlist_t *
construct_spec(libzfs_handle_t *hdl, int vdevcount, char **vdevlist)
{
nvlist_t *nvroot, *nv, **top, **spares, **l2cache;
int t, toplevels, mindev, maxdev, nspares, nlogs, nl2cache;
const char *type;
uint64_t is_log;
boolean_t seen_logs;
char msg[1024];
nvroot = NULL;
top = NULL;
toplevels = 0;
spares = NULL;
l2cache = NULL;
nspares = 0;
nlogs = 0;
nl2cache = 0;
is_log = B_FALSE;
seen_logs = B_FALSE;
(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
"invalid vdev specification: "));
while (vdevcount > 0) {
nv = NULL;
/*
* If it's a mirror or raidz, the subsequent arguments are
* its leaves -- until we encounter the next mirror or raidz.
*/
if ((type = is_grouping(vdevlist[0], &mindev, &maxdev))
!= NULL) {
nvlist_t **child = NULL;
int c, children = 0;
if (strcmp(type, VDEV_TYPE_SPARE) == 0) {
if (spares != NULL) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"%s'%s' can be specified only "
"once"), msg, VDEV_TYPE_SPARE);
goto errout;
}
is_log = B_FALSE;
}
if (strcmp(type, VDEV_TYPE_LOG) == 0) {
if (seen_logs) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"%s'%s' can be specified only "
"once"), msg, VDEV_TYPE_LOG);
goto errout;
}
seen_logs = B_TRUE;
is_log = B_TRUE;
vdevcount--;
vdevlist++;
/*
* A log is not a real grouping device.
* We just set is_log and continue.
*/
continue;
}
if (strcmp(type, VDEV_TYPE_L2CACHE) == 0) {
if (l2cache != NULL) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"%s'%s' can be specified only "
"once"), msg, VDEV_TYPE_L2CACHE);
goto errout;
}
is_log = B_FALSE;
}
if (is_log) {
if (strcmp(type, VDEV_TYPE_MIRROR) != 0) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"%sunsupported '%s' device: %s"),
msg, VDEV_TYPE_LOG, type);
goto errout;
}
nlogs++;
}
for (c = 1; c < vdevcount; c++) {
if (is_grouping(vdevlist[c], NULL, NULL)
!= NULL)
break;
child = zfs_realloc(hdl, child, children *
sizeof (nvlist_t *), (children + 1) *
sizeof (nvlist_t *));
if ((nv = make_leaf_vdev(hdl, vdevlist[c],
B_FALSE)) == NULL) {
for (int i = 0; i < children; i++)
nvlist_free(child[i]);
free(child);
goto errout;
}
child[children] = nv;
children++;
}
if (children < mindev) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"%s%s requires at least %d devices"),
msg, vdevlist[0], mindev);
if (child) {
for (int i = 0; i < children; i++)
nvlist_free(child[i]);
free(child);
}
goto errout;
}
if (children > maxdev) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"%s%s supports no more then %d devices"),
msg, vdevlist[0], maxdev);
if (child) {
for (int i = 0; i < children; i++)
nvlist_free(child[i]);
free(child);
}
goto errout;
}
vdevcount -= c;
vdevlist += c;
if (strcmp(type, VDEV_TYPE_SPARE) == 0) {
spares = child;
nspares = children;
continue;
} else if (strcmp(type, VDEV_TYPE_L2CACHE) == 0) {
l2cache = child;
nl2cache = children;
continue;
} else {
verify(nvlist_alloc(&nv, NV_UNIQUE_NAME,
0) == 0);
verify(nvlist_add_string(nv, ZPOOL_CONFIG_TYPE,
type) == 0);
verify(nvlist_add_uint64(nv,
ZPOOL_CONFIG_IS_LOG, is_log) == 0);
if (strcmp(type, VDEV_TYPE_RAIDZ) == 0) {
verify(nvlist_add_uint64(nv,
ZPOOL_CONFIG_NPARITY,
mindev - 1) == 0);
}
verify(nvlist_add_nvlist_array(nv,
ZPOOL_CONFIG_CHILDREN, child,
children) == 0);
for (c = 0; c < children; c++)
nvlist_free(child[c]);
free(child);
}
} else {
/*
* We have a device. Pass off to make_leaf_vdev() to
* construct the appropriate nvlist describing the vdev.
*/
if ((nv = make_leaf_vdev(hdl, vdevlist[0], is_log))
== NULL)
goto errout;
if (is_log)
nlogs++;
vdevcount--;
vdevlist++;
}
top = zfs_realloc(hdl, top, toplevels * sizeof (nvlist_t *),
(toplevels + 1) * sizeof (nvlist_t *));
top[toplevels] = nv;
toplevels++;
}
if (toplevels == 0 && nspares == 0 && nl2cache == 0) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"%sat least one toplevel vdev must be specified"), msg);
goto errout;
}
if (seen_logs && nlogs == 0) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "%s'%s' "
"requires at least 1 device"), msg, VDEV_TYPE_LOG);
goto errout;
}
/*
* Finally, create nvroot and add all top-level vdevs to it.
*/
verify(nvlist_alloc(&nvroot, NV_UNIQUE_NAME, 0) == 0);
verify(nvlist_add_string(nvroot, ZPOOL_CONFIG_TYPE,
VDEV_TYPE_ROOT) == 0);
verify(nvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN,
top, toplevels) == 0);
if (nspares != 0)
verify(nvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
spares, nspares) == 0);
if (nl2cache != 0)
verify(nvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE,
l2cache, nl2cache) == 0);
errout:
for (t = 0; t < toplevels; t++)
nvlist_free(top[t]);
for (t = 0; t < nspares; t++)
nvlist_free(spares[t]);
for (t = 0; t < nl2cache; t++)
nvlist_free(l2cache[t]);
free(spares);
free(l2cache);
free(top);
return (nvroot);
}
nvlist_t *
zpool_split_root_vdev(zpool_handle_t *zhp, char *newname, nvlist_t *props,
splitflags_t flags, int vdevcount, char **vdevlist)
{
nvlist_t *newroot = NULL;
assert(zhp != NULL);
if (vdevcount > 0) {
char msg[1024];
nvlist_t **child;
uint_t c, children;
libzfs_handle_t *hdl = zhp->zpool_hdl;
(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
"Unable to split '%s'"), zhp->zpool_name);
if ((newroot = construct_spec(hdl, vdevcount, vdevlist))
== NULL) {
(void) zfs_error(hdl, EZFS_INVALCONFIG, msg);
return (NULL);
}
if (!flags.dryrun && make_disks(hdl, zhp, newroot,
ZPOOL_LABEL_MATCH_REQ_PART) != 0) {
(void) zfs_error(hdl, EZFS_INVALCONFIG, msg);
nvlist_free(newroot);
return (NULL);
}
/* avoid any tricks in the spec */
verify(nvlist_lookup_nvlist_array(newroot,
ZPOOL_CONFIG_CHILDREN, &child, &children) == 0);
for (c = 0; c < children; c++) {
char *path;
const char *type;
int min, max;
verify(nvlist_lookup_string(child[c],
ZPOOL_CONFIG_PATH, &path) == 0);
if ((type = is_grouping(path, &min, &max)) != NULL) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"invalid vdev specification: cannot use "
"'%s' as a device for splitting"),
type);
(void) zfs_error(hdl, EZFS_BADDEV, msg);
nvlist_free(newroot);
return (NULL);
}
}
}
if (zpool_vdev_split(zhp, newname, &newroot, props, flags) != 0) {
/* zpool_vdev_split() does the error messaging here */
if (newroot != NULL)
nvlist_free(newroot);
return (NULL);
}
return (newroot);
}
/*
* Get and validate the contents of the given vdev specification. This ensures
* that the nvlist returned is well-formed, that all the devices exist, and that
* they are not currently in use by any other known consumer. The 'poolconfig'
* parameter is the current configuration of the pool when adding devices
* existing pool, and is used to perform additional checks, such as changing the
* replication level of the pool. It can be 'NULL' to indicate that this is a
* new pool. The 'force' flag controls whether devices should be forcefully
* added, even if they appear in use.
*/
nvlist_t *
zpool_make_root_vdev(libzfs_handle_t *hdl, zpool_handle_t *zhp, boolean_t force,
int check_rep, boolean_t replacing, boolean_t dryrun, int create_req_part,
int vdevcount, char **vdevlist)
{
nvlist_t *newroot;
nvlist_t *poolconfig = NULL;
char msg[1024];
(void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN,
"Unable to build pool from specified devices"));
/*
* Construct the vdev specification. If this is successful, we know
* that we have a valid specification, and that all devices can be
* opened.
*/
if ((newroot = construct_spec(hdl, vdevcount, vdevlist)) == NULL) {
(void) zfs_error(hdl, EZFS_INVALCONFIG, msg);
return (NULL);
}
if (zhp && ((poolconfig = zpool_get_config(zhp, NULL)) == NULL)) {
(void) zfs_error(hdl, EZFS_INVALCONFIG, msg);
return (NULL);
}
/*
* Validate each device to make sure that its not shared with another
* subsystem. We do this even if 'force' is set, because there are some
* uses (such as a dedicated dump device) that even '-f' cannot
* override.
*/
if (check_in_use(hdl, poolconfig, newroot, force, replacing, B_FALSE)
!= 0) {
nvlist_free(newroot);
(void) zfs_error(hdl, EZFS_DEV_INUSE, msg);
return (NULL);
}
/*
* Check the replication level of the given vdevs and report any errors
* found. We include the existing pool spec, if any, as we need to
* catch changes against the existing replication level.
*/
if (check_rep && check_replication(hdl, poolconfig, newroot, force)
!= 0) {
nvlist_free(newroot);
(void) zfs_error(hdl, EZFS_INVALCONFIG, msg);
return (NULL);
}
/*
* Run through the vdev specification and label any whole disks found.
*/
if (!dryrun && make_disks(hdl, zhp, newroot, create_req_part) != 0) {
nvlist_free(newroot);
(void) zfs_error(hdl, EZFS_INVALCONFIG, msg);
return (NULL);
}
return (newroot);
}