mirror_zfs/cmd/zpool_id/zpool_id

87 lines
2.0 KiB
Plaintext
Raw Normal View History

#!/bin/sh
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: $*"
exit 1
}
usage() {
cat << EOF
Usage: zpool_id [-h] [-c configfile] <devpath>
-c Alternate config file [default /etc/zfs/zdev.conf]
-d Use path_id from device as the mapping key
-h Show this message
EOF
exit 1
}
while getopts 'c:d:h' OPTION; do
case ${OPTION} in
c)
CONFIG="${OPTARG}"
;;
d)
DEVICE="${OPTARG}"
;;
h)
usage
;;
esac
done
# Check that a device was requested
[ -z "${DEVICE}" ] && usage
# Check for the existence of a configuration file
[ ! -f "${CONFIG}" ] && die "Missing config file: ${CONFIG}"
Multipath device manageability improvements Update udev helper scripts to deal with device-mapper devices created by multipathd. These enhancements are targeted at a particular storage network topology under evaluation at LLNL consisting of two SAS switches providing redundant connectivity between multiple server nodes and disk enclosures. The key to making these systems manageable is to create shortnames for each disk that conveys its physical location in a drawer. In a direct-attached topology we infer a disk's enclosure from the PCI bus number and HBA port number in the by-path name provided by udev. In a switched topology, however, multiple drawers are accessed via a single HBA port. We therefore resort to assigning drawer identifiers based on which switch port a drive's enclosure is connected to. This information is available from sysfs. Add options to zpool_layout to generate an /etc/zfs/zdev.conf using symbolic links in /dev/disk/by-id of the form <label>-<UUID>-switch-port:<X>-slot:<Y>. <label> is a string that depends on the subsystem that created the link and defaults to "dm-uuid-mpath" (this prefix is used by multipathd). <UUID> is a unique identifier for the disk typically obtained from the scsi_id program, and <X> and <Y> denote the switch port and disk slot numbers, respectively. Add a callout script sas_switch_id for use by multipathd to help create symlinks of the form described above. Update zpool_id and the udev zpool rules file to handle both multipath devices and conventional drives.
2011-06-22 03:18:27 +04:00
# 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}" | grep -q -e '^mpath' ; then
Multipath device manageability improvements Update udev helper scripts to deal with device-mapper devices created by multipathd. These enhancements are targeted at a particular storage network topology under evaluation at LLNL consisting of two SAS switches providing redundant connectivity between multiple server nodes and disk enclosures. The key to making these systems manageable is to create shortnames for each disk that conveys its physical location in a drawer. In a direct-attached topology we infer a disk's enclosure from the PCI bus number and HBA port number in the by-path name provided by udev. In a switched topology, however, multiple drawers are accessed via a single HBA port. We therefore resort to assigning drawer identifiers based on which switch port a drive's enclosure is connected to. This information is available from sysfs. Add options to zpool_layout to generate an /etc/zfs/zdev.conf using symbolic links in /dev/disk/by-id of the form <label>-<UUID>-switch-port:<X>-slot:<Y>. <label> is a string that depends on the subsystem that created the link and defaults to "dm-uuid-mpath" (this prefix is used by multipathd). <UUID> is a unique identifier for the disk typically obtained from the scsi_id program, and <X> and <Y> denote the switch port and disk slot numbers, respectively. Add a callout script sas_switch_id for use by multipathd to help create symlinks of the form described above. Update zpool_id and the udev zpool rules file to handle both multipath devices and conventional drives.
2011-06-22 03:18:27 +04:00
ID_PATH="dm-uuid-${DM_UUID}"
else
eval `${PATH_ID} ${DEVICE}`
[ -z "${ID_PATH}" ] && die "Missing ID_PATH for ${DEVICE}"
Multipath device manageability improvements Update udev helper scripts to deal with device-mapper devices created by multipathd. These enhancements are targeted at a particular storage network topology under evaluation at LLNL consisting of two SAS switches providing redundant connectivity between multiple server nodes and disk enclosures. The key to making these systems manageable is to create shortnames for each disk that conveys its physical location in a drawer. In a direct-attached topology we infer a disk's enclosure from the PCI bus number and HBA port number in the by-path name provided by udev. In a switched topology, however, multiple drawers are accessed via a single HBA port. We therefore resort to assigning drawer identifiers based on which switch port a drive's enclosure is connected to. This information is available from sysfs. Add options to zpool_layout to generate an /etc/zfs/zdev.conf using symbolic links in /dev/disk/by-id of the form <label>-<UUID>-switch-port:<X>-slot:<Y>. <label> is a string that depends on the subsystem that created the link and defaults to "dm-uuid-mpath" (this prefix is used by multipathd). <UUID> is a unique identifier for the disk typically obtained from the scsi_id program, and <X> and <Y> denote the switch port and disk slot numbers, respectively. Add a callout script sas_switch_id for use by multipathd to help create symlinks of the form described above. Update zpool_id and the udev zpool rules file to handle both multipath devices and conventional drives.
2011-06-22 03:18:27 +04:00
fi
# Use the persistent key to lookup the zpool device id in the
# configuration file which is of the format <device id> <key>.
# 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.
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 [ -n "${ID_ZPOOL}" ]; then
echo "ID_PATH=${ID_PATH}"
echo "ID_ZPOOL=${ID_ZPOOL}"
echo "ID_ZPOOL_PATH=disk/zpool/${ID_ZPOOL}"
fi
exit 0