3 CONFIG="${CONFIG:-/etc/zfs/zdev.conf}"
4 AWK="${AWK:-/usr/bin/awk}"
6 if [ -z "${PATH_ID}" ]; then
7 # The path_id helper became a builtin command in udev 174.
8 if [ -x '/lib/udev/path_id' ]; then
9 PATH_ID='/lib/udev/path_id'
11 PATH_ID='udevadm test-builtin path_id'
22 Usage: zpool_id [-h] [-c configfile] <devpath>
23 -c Alternate config file [default /etc/zfs/zdev.conf]
24 -d Use path_id from device as the mapping key
30 while getopts 'c:d:h' OPTION; do
44 # Check that a device was requested
45 [ -z "${DEVICE}" ] && usage
47 # Check for the existence of a configuration file
48 [ ! -f "${CONFIG}" ] && die "Missing config file: ${CONFIG}"
50 # If we are handling a multipath device then $DM_UUID will be
51 # exported and we'll use its value (prefixed with dm-uuid per
52 # multipathd's naming convention) as our unique persistent key.
53 # For traditional devices we'll obtain the key from udev's
55 if [ -n "${DM_UUID}" ] && echo "${DM_UUID}" | grep -q -e '^mpath' ; then
56 ID_PATH="dm-uuid-${DM_UUID}"
58 eval `${PATH_ID} ${DEVICE}`
59 [ -z "${ID_PATH}" ] && die "Missing ID_PATH for ${DEVICE}"
62 # Use the persistent key to lookup the zpool device id in the
63 # configuration file which is of the format <device id> <key>.
64 # Lines starting with #'s are treated as comments and ignored.
65 # Exact matches are required, wild cards are not supported,
66 # and only the first match is returned. Also note the following
67 # regex pattern only appears to work with gawk, not mawk or awk.
68 ID_ZPOOL=`${AWK} "/\<${ID_PATH}\>/ && !/^#/ { print \\$1; exit }" "${CONFIG}"`
69 [ -z "${ID_ZPOOL}" ] && die "Missing ID_ZPOOL for ID_PATH: ${ID_PATH}"
71 if [ -n "${ID_ZPOOL}" ]; then
72 echo "ID_PATH=${ID_PATH}"
73 echo "ID_ZPOOL=${ID_ZPOOL}"
74 echo "ID_ZPOOL_PATH=disk/zpool/${ID_ZPOOL}"