X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=cmd%2Fzpool_id%2Fzpool_id;h=9d2a845497ed452ce56df3ad92f370c72caec4f6;hb=de0a1c099b7dc6722eb428838e893a4d9490a21e;hp=c3637847a8387757ed34415d34ed04e4199cde7d;hpb=c9c0d073da561bcbefbdf09c87fc75b227415619;p=zfs.git diff --git a/cmd/zpool_id/zpool_id b/cmd/zpool_id/zpool_id index c363784..9d2a845 100755 --- a/cmd/zpool_id/zpool_id +++ b/cmd/zpool_id/zpool_id @@ -2,7 +2,7 @@ CONFIG=${CONFIG:-/etc/zfs/zdev.conf} PATH_ID=${PATH_ID:-/lib/udev/path_id} -AWK=${AWK:-/bin/awk} +AWK=${AWK:-/usr/bin/awk} die() { echo "Error: $*" @@ -39,16 +39,25 @@ done # Check for the existence of a configuration file [ ! -f ${CONFIG} ] && die "Missing config file: ${CONFIG}" -# Use udev's path_id to generate a unique persistent key -eval `${PATH_ID} ${DEVICE}` -[ -z ${ID_PATH} ] && die "Missing ID_PATH for ${DEVICE}" +# If we are handling a multipath device then $DM_UUID will be +# exported and we'll use its value (prefixed with dm-uuid per +# multipathd's naming convention) as our unique persistent key. +# For traditional devices we'll obtain the key from udev's +# path_id. +if [ -n "${DM_UUID}" ] && echo ${DM_UUID} | egrep -q -e '^mpath' ; then + ID_PATH="dm-uuid-${DM_UUID}" +else + eval `${PATH_ID} ${DEVICE}` + [ -z ${ID_PATH} ] && die "Missing ID_PATH for ${DEVICE}" +fi # Use the persistent key to lookup the zpool device id in the # configuration file which is of the format . # Lines starting with #'s are treated as comments and ignored. # Exact matches are required, wild cards are not supported, -# and only the first match is returned. -ID_ZPOOL=`${AWK} "/${ID_PATH}\>/ && !/^#/ { print \\$1; exit }" ${CONFIG}` +# and only the first match is returned. Also note the following +# regex pattern only appears to work with gawk, not mawk or awk. +ID_ZPOOL=`${AWK} "/\<${ID_PATH}\>/ && !/^#/ { print \\$1; exit }" ${CONFIG}` [ -z ${ID_ZPOOL} ] && die "Missing ID_ZPOOL for ID_PATH: ${ID_PATH}" if [ ${ID_ZPOOL} ]; then