aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2012-10-17 16:58:54 -0700
committerBrian Behlendorf <[email protected]>2012-10-22 08:45:58 -0700
commiteac4720465e54c86ae814667985c8a013ec45b85 (patch)
treefcb3dbf45463e84e6e8fd5bab6701d3794b76547 /cmd
parentc7dfc086297b6e7768e94d1eef3afaa58beeb5ec (diff)
Allow 'zpool replace' to use short device names
The 'zpool replace' command would fail when given a short name because unlike on other platforms the short name cannot be deterministically expanded to a single path. Multiple path prefixes must be checked and in addition the partition suffix for whole disks is determined by the prefix. To handle this complexity a zfs_strcmp_pathname() function was added which takes either a short or fully qualified device name. Short names will be expanded using the prefixes in the default import search path, or the ZPOOL_IMPORT_PATH environment variable if it's defined. All posible expansions are then compared against the comparison path. Care is taken to strip redundant slashes to ensure legitimate matches are not missed. In the context of this work the existing zfs_resolve_shortname() function was extended to consider the ZPOOL_IMPORT_PATH when set. The zfs_append_partition() interface was also simplified to take only a single buffer. The vast majority of these changes rework existing Linux specific code which was originally written to accomidate udev. However, there is some minimal cleanup which removes Illumos specific code. This was done to improve readability but the basic flow and intent of the upstream code was maintained. These changes are the logical conclusion of the previos work to adjust the 'zpool import' search behavior, see commit 44867b6a. Signed-off-by: Brian Behlendorf <[email protected]> Closes #544 Closes #976
Diffstat (limited to 'cmd')
-rw-r--r--cmd/zpool/zpool_vdev.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/cmd/zpool/zpool_vdev.c b/cmd/zpool/zpool_vdev.c
index 8c4fadebd..da121f06f 100644
--- a/cmd/zpool/zpool_vdev.c
+++ b/cmd/zpool/zpool_vdev.c
@@ -366,16 +366,18 @@ is_whole_disk(const char *path)
/*
* This may be a shorthand device path or it could be total gibberish.
- * Check to see if it's a known device in /dev/, /dev/disk/by-id,
- * /dev/disk/by-label, /dev/disk/by-path, /dev/disk/by-uuid,
- * /dev/disk/by-vdev, or /dev/disk/zpool/. As part of this check, see
- * if we've been given an entire disk (minus the slice number).
+ * Check to see if it is a known device available in zfs_vdev_paths.
+ * As part of this check, see if we've been given an entire disk
+ * (minus the slice number).
*/
static int
is_shorthand_path(const char *arg, char *path,
struct stat64 *statbuf, boolean_t *wholedisk)
{
- if (zfs_resolve_shortname(arg, path, MAXPATHLEN) == 0) {
+ int error;
+
+ error = zfs_resolve_shortname(arg, path, MAXPATHLEN);
+ if (error == 0) {
*wholedisk = is_whole_disk(path);
if (*wholedisk || (stat64(path, statbuf) == 0))
return (0);
@@ -385,7 +387,7 @@ is_shorthand_path(const char *arg, char *path,
memset(statbuf, 0, sizeof(*statbuf));
*wholedisk = B_FALSE;
- return (ENOENT);
+ return (error);
}
/*
@@ -393,9 +395,9 @@ is_shorthand_path(const char *arg, char *path,
* device, fill in the device id to make a complete nvlist. Valid forms for a
* leaf vdev are:
*
- * /dev/xxx Complete disk path
- * /xxx Full path to file
- * xxx Shorthand for /dev/disk/yyy/xxx
+ * /dev/xxx Complete disk path
+ * /xxx Full path to file
+ * xxx Shorthand for <zfs_vdev_paths>/xxx
*/
static nvlist_t *
make_leaf_vdev(nvlist_t *props, const char *arg, uint64_t is_log)
@@ -959,7 +961,9 @@ make_disks(zpool_handle_t *zhp, nvlist_t *nv)
* deletes and recreates the link during which access attempts
* will fail with ENOENT.
*/
- zfs_append_partition(path, udevpath, sizeof (udevpath));
+ strncpy(udevpath, path, MAXPATHLEN);
+ (void) zfs_append_partition(udevpath, MAXPATHLEN);
+
if ((strncmp(udevpath, UDISK_ROOT, strlen(UDISK_ROOT)) == 0) &&
(lstat64(udevpath, &statbuf) == 0) &&
S_ISLNK(statbuf.st_mode))
@@ -983,9 +987,9 @@ make_disks(zpool_handle_t *zhp, nvlist_t *nv)
}
/*
- * Update the path to refer to FIRST_SLICE. The presence of
+ * Update the path to refer to the partition. The presence of
* the 'whole_disk' field indicates to the CLI that we should
- * chop off the slice number when displaying the device in
+ * chop off the partition number when displaying the device in
* future output.
*/
verify(nvlist_add_string(nv, ZPOOL_CONFIG_PATH, udevpath) == 0);