3 CONFIG=${CONFIG:-/etc/zfs/zdev.conf}
4 PATH_ID=${PATH_ID:-/lib/udev/path_id}
5 AWK=${AWK:-/usr/bin/awk}
14 Usage: zpool_id [h] [-c configfile] <devpath>
15 -c Alternate config file [default /etc/zfs/zdev.conf]
16 -d Use path_id from device as the mapping key
22 while getopts 'c:d:h' OPTION; do
36 # Check that a device was requested
37 [ -z ${DEVICE} ] && usage
39 # Check for the existence of a configuration file
40 [ ! -f ${CONFIG} ] && die "Missing config file: ${CONFIG}"
42 # If we are handling a multipath device then $DM_UUID will be
43 # exported and we'll use its value (prefixed with dm-uuid per
44 # multipathd's naming convention) as our unique persistent key.
45 # For traditional devices we'll obtain the key from udev's
47 if [ -n "${DM_UUID}" ] && echo ${DM_UUID} | egrep -q -e '^mpath' ; then
48 ID_PATH="dm-uuid-${DM_UUID}"
50 eval `${PATH_ID} ${DEVICE}`
51 [ -z ${ID_PATH} ] && die "Missing ID_PATH for ${DEVICE}"
54 # Use the persistent key to lookup the zpool device id in the
55 # configuration file which is of the format <device id> <key>.
56 # Lines starting with #'s are treated as comments and ignored.
57 # Exact matches are required, wild cards are not supported,
58 # and only the first match is returned. Also note the following
59 # regex pattern only appears to work with gawk, not mawk or awk.
60 ID_ZPOOL=`${AWK} "/\<${ID_PATH}\>/ && !/^#/ { print \\$1; exit }" ${CONFIG}`
61 [ -z ${ID_ZPOOL} ] && die "Missing ID_ZPOOL for ID_PATH: ${ID_PATH}"
63 if [ ${ID_ZPOOL} ]; then
64 echo "ID_PATH=${ID_PATH}"
65 echo "ID_ZPOOL=${ID_ZPOOL}"
66 echo "ID_ZPOOL_PATH=disk/zpool/${ID_ZPOOL}"