summaryrefslogtreecommitdiffstats
path: root/cmd/zpool_id
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2010-08-26 11:22:58 -0700
committerBrian Behlendorf <[email protected]>2010-08-31 13:41:27 -0700
commitc9c0d073da561bcbefbdf09c87fc75b227415619 (patch)
tree7daee55ae61526107f421de48171573fa5a15d28 /cmd/zpool_id
parent40b84e7aec6392187722e61e5a4a853b530bf60f (diff)
Add build system
Add autoconf style build infrastructure to the ZFS tree. This includes autogen.sh, configure.ac, m4 macros, some scripts/*, and makefiles for all the core ZFS components.
Diffstat (limited to 'cmd/zpool_id')
-rw-r--r--cmd/zpool_id/Makefile.am1
-rwxr-xr-xcmd/zpool_id/zpool_id60
2 files changed, 61 insertions, 0 deletions
diff --git a/cmd/zpool_id/Makefile.am b/cmd/zpool_id/Makefile.am
new file mode 100644
index 000000000..023e1ab59
--- /dev/null
+++ b/cmd/zpool_id/Makefile.am
@@ -0,0 +1 @@
+dist_bin_SCRIPTS = zpool_id
diff --git a/cmd/zpool_id/zpool_id b/cmd/zpool_id/zpool_id
new file mode 100755
index 000000000..c3637847a
--- /dev/null
+++ b/cmd/zpool_id/zpool_id
@@ -0,0 +1,60 @@
+#!/bin/bash
+
+CONFIG=${CONFIG:-/etc/zfs/zdev.conf}
+PATH_ID=${PATH_ID:-/lib/udev/path_id}
+AWK=${AWK:-/bin/awk}
+
+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}"
+
+# Use udev's path_id to generate a unique persistent key
+eval `${PATH_ID} ${DEVICE}`
+[ -z ${ID_PATH} ] && die "Missing ID_PATH for ${DEVICE}"
+
+# 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=`${AWK} "/${ID_PATH}\>/ && !/^#/ { print \\$1; exit }" ${CONFIG}`
+[ -z ${ID_ZPOOL} ] && die "Missing ID_ZPOOL for ID_PATH: ${ID_PATH}"
+
+if [ ${ID_ZPOOL} ]; then
+ echo "ID_PATH=${ID_PATH}"
+ echo "ID_ZPOOL=${ID_ZPOOL}"
+ echo "ID_ZPOOL_PATH=disk/zpool/${ID_ZPOOL}"
+fi
+
+exit 0