Allow 'zpool replace' to use short device names
authorBrian Behlendorf <behlendorf1@llnl.gov>
Wed, 17 Oct 2012 23:58:54 +0000 (16:58 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 22 Oct 2012 15:45:58 +0000 (08:45 -0700)
commiteac4720465e54c86ae814667985c8a013ec45b85
treefcb3dbf45463e84e6e8fd5bab6701d3794b76547
parentc7dfc086297b6e7768e94d1eef3afaa58beeb5ec
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 <behlendorf1@llnl.gov>
Closes #544
Closes #976
cmd/zpool/zpool_vdev.c
include/libzfs.h
lib/libzfs/libzfs_import.c
lib/libzfs/libzfs_pool.c
lib/libzfs/libzfs_util.c