3 CONFIG="${CONFIG:-/etc/zfs/zdev.conf}"
5 if [ -z "${PATH_ID}" ]; then
6 # The path_id helper became a builtin command in udev 174.
7 if [ -x '/lib/udev/path_id' ]; then
8 PATH_ID='/lib/udev/path_id'
10 PATH_ID='udevadm test-builtin path_id'
21 Usage: zpool_id [-h] [-c configfile] <devpath>
22 -c Alternate config file [default /etc/zfs/zdev.conf]
23 -d Use path_id from device as the mapping key
29 while getopts 'c:d:h' OPTION; do
43 # Check that a device was requested
44 [ -z "${DEVICE}" ] && usage
46 # Check for the existence of a configuration file
47 [ ! -f "${CONFIG}" ] && die "Missing config file: ${CONFIG}"
49 # If we are handling a multipath device then $DM_UUID will be
50 # exported and we'll use its value (prefixed with dm-uuid per
51 # multipathd's naming convention) as our unique persistent key.
52 # For traditional devices we'll obtain the key from udev's
54 if [ -n "${DM_UUID}" ] && echo "${DM_UUID}" | grep -q -e '^mpath' ; then
55 ID_PATH="dm-uuid-${DM_UUID}"
57 eval `${PATH_ID} ${DEVICE}`
58 [ -z "${ID_PATH}" ] && die "Missing ID_PATH for ${DEVICE}"
61 # Use the persistent key to lookup the zpool device id in the
62 # configuration file which is of the format <device id> <key>.
63 # Lines starting with #'s are treated as comments and ignored.
64 # Exact matches are required, wild cards are not supported,
65 # and only the first match is returned.
67 while read CONFIG_ZPOOL CONFIG_PATH REPLY; do
68 if [ "${CONFIG_ZPOOL}" != "${CONFIG_ZPOOL#\#}" ]; then
72 if [ "${CONFIG_PATH}" = "${ID_PATH}" ]; then
73 ID_ZPOOL="${CONFIG_ZPOOL}"
78 [ -z "${ID_ZPOOL}" ] && die "Missing ID_ZPOOL for ID_PATH: ${ID_PATH}"
80 if [ -n "${ID_ZPOOL}" ]; then
81 echo "ID_PATH=${ID_PATH}"
82 echo "ID_ZPOOL=${ID_ZPOOL}"
83 echo "ID_ZPOOL_PATH=disk/zpool/${ID_ZPOOL}"