3 CONFIG=${CONFIG:-/etc/zfs/zdev.conf}
4 PATH_ID=${PATH_ID:-/lib/udev/path_id}
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 # Use udev's path_id to generate a unique persistent key
43 eval `${PATH_ID} ${DEVICE}`
44 [ -z ${ID_PATH} ] && die "Missing ID_PATH for ${DEVICE}"
46 # Use the persistent key to lookup the zpool device id in the
47 # configuration file which is of the format <device id> <key>.
48 # Lines starting with #'s are treated as comments and ignored.
49 # Exact matches are required, wild cards are not supported,
50 # and only the first match is returned.
51 ID_ZPOOL=`${AWK} "/${ID_PATH}\>/ && !/^#/ { print \\$1; exit }" ${CONFIG}`
52 [ -z ${ID_ZPOOL} ] && die "Missing ID_ZPOOL for ID_PATH: ${ID_PATH}"
54 if [ ${ID_ZPOOL} ]; then
55 echo "ID_PATH=${ID_PATH}"
56 echo "ID_ZPOOL=${ID_ZPOOL}"
57 echo "ID_ZPOOL_PATH=disk/zpool/${ID_ZPOOL}"