X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=cmd%2Fzpool_id%2Fzpool_id;h=bf15dc99116e393e15e5637d1b82a94ca6031764;hb=5990da81a798c087d323ba9104a6696bef2d275f;hp=9d2a845497ed452ce56df3ad92f370c72caec4f6;hpb=560bcf9d14a63e2cef4dd49d61399c8a865c1348;p=zfs.git diff --git a/cmd/zpool_id/zpool_id b/cmd/zpool_id/zpool_id index 9d2a845..bf15dc9 100755 --- a/cmd/zpool_id/zpool_id +++ b/cmd/zpool_id/zpool_id @@ -1,8 +1,15 @@ -#!/bin/bash +#!/bin/sh -CONFIG=${CONFIG:-/etc/zfs/zdev.conf} -PATH_ID=${PATH_ID:-/lib/udev/path_id} -AWK=${AWK:-/usr/bin/awk} +CONFIG="${CONFIG:-/etc/zfs/zdev.conf}" + +if [ -z "${PATH_ID}" ]; then + # The path_id helper became a builtin command in udev 174. + if [ -x '/lib/udev/path_id' ]; then + PATH_ID='/lib/udev/path_id' + else + PATH_ID='udevadm test-builtin path_id' + fi +fi die() { echo "Error: $*" @@ -11,7 +18,7 @@ die() { usage() { cat << EOF -Usage: zpool_id [h] [-c configfile] +Usage: zpool_id [-h] [-c configfile] -c Alternate config file [default /etc/zfs/zdev.conf] -d Use path_id from device as the mapping key -h Show this message @@ -22,10 +29,10 @@ EOF while getopts 'c:d:h' OPTION; do case ${OPTION} in c) - CONFIG=${OPTARG} + CONFIG="${OPTARG}" ;; d) - DEVICE=${OPTARG} + DEVICE="${OPTARG}" ;; h) usage @@ -34,33 +41,43 @@ while getopts 'c:d:h' OPTION; do done # Check that a device was requested -[ -z ${DEVICE} ] && usage +[ -z "${DEVICE}" ] && usage # Check for the existence of a configuration file -[ ! -f ${CONFIG} ] && die "Missing config file: ${CONFIG}" +[ ! -f "${CONFIG}" ] && die "Missing config file: ${CONFIG}" # 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 +if [ -n "${DM_UUID}" ] && echo "${DM_UUID}" | grep -q -e '^mpath' ; then ID_PATH="dm-uuid-${DM_UUID}" else eval `${PATH_ID} ${DEVICE}` - [ -z ${ID_PATH} ] && die "Missing ID_PATH for ${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. 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}" +# and only the first match is returned. +ID_ZPOOL='' +while read CONFIG_ZPOOL CONFIG_PATH REPLY; do + if [ "${CONFIG_ZPOOL}" != "${CONFIG_ZPOOL#\#}" ]; then + # Skip comment lines. + continue + fi + if [ "${CONFIG_PATH}" = "${ID_PATH}" ]; then + ID_ZPOOL="${CONFIG_ZPOOL}" + break + fi +done <"${CONFIG}" + +[ -z "${ID_ZPOOL}" ] && die "Missing ID_ZPOOL for ID_PATH: ${ID_PATH}" -if [ ${ID_ZPOOL} ]; then +if [ -n "${ID_ZPOOL}" ]; then echo "ID_PATH=${ID_PATH}" echo "ID_ZPOOL=${ID_ZPOOL}" echo "ID_ZPOOL_PATH=disk/zpool/${ID_ZPOOL}"