Search
j0ke.net Open Build Service
>
Projects
>
GFS
>
multipath-tools
> multipath-tools-add-udev-callouts
Sign Up
|
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File multipath-tools-add-udev-callouts of Package multipath-tools
commit 8414f018bc75c7bfb0b59d8b184d7844c52e8e40 Author: Hannes Reinecke <hare@acerbis.suse.de> Date: Fri Feb 29 16:40:28 2008 +0100 Add kpartx_id and mpath_id for udev Helper programs for udev. Signed-off-by: Hannes Reinecke <hare@suse.de> diff --git a/Makefile.inc b/Makefile.inc index 1b07ab0..21fa557 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -22,6 +22,7 @@ endif prefix = exec_prefix = $(prefix) bindir = $(exec_prefix)/sbin +udevdir = $(prefix)/etc/udev/rules.d libudevdir = ${prefix}/lib/udev checkersdir = $(TOPDIR)/libcheckers libpriodir = $(TOPDIR)/libprio diff --git a/kpartx/Makefile b/kpartx/Makefile index d979cc5..a1284ff 100644 --- a/kpartx/Makefile +++ b/kpartx/Makefile @@ -39,6 +39,7 @@ install: $(EXEC) $(EXEC).8 install -m 755 $(EXEC) $(DESTDIR)$(bindir) install -d $(DESTDIR)$(mandir) install -m 644 $(EXEC).8 $(DESTDIR)$(mandir) + install -m 755 kpartx_id $(DESTDIR)$(bindir) uninstall: rm -f $(DESTDIR)$(bindir)/$(EXEC) diff --git a/kpartx/kpartx_id b/kpartx/kpartx_id index 81f32bf..2c9f617 100644 --- /dev/null +++ b/kpartx/kpartx_id @@ -0,0 +1,61 @@ +#!/bin/bash +# +# kpartx_id +# +# Checks whether a given dm table is a table for a partition +# on a multipathed device as created by kpartx. +# +# A table has been created by kpartx if +# 1) it is of type 'linear' +# 2) has exactly one dependency +# 3) this dependency is of type 'multipath' +# + +DMSETUP=/sbin/dmsetup + +MAJOR=$1 +MINOR=$2 + +if [ -z "$MAJOR" -o -z "$MINOR" ]; then + echo "usage: $0 major minor" + exit 1; +fi + +# 1) Check for dependencies +tbldeps=$($DMSETUP deps -j $MAJOR -m $MINOR) +if [ $? -ne 0 ] || [ -z "$tbldeps" ]; then + exit $? +fi + +numdeps=${tbldeps%dependen*} +if [ "$numdeps" -ne 1 ]; then + exit $numdeps +fi + +# 2) Check for table type +tbldef=$($DMSETUP table -j $MAJOR -m $MINOR) +if [ $? -ne 0 ] || [ -z "$tbldef" ]; then + exit $? +fi +set -- $tbldef + +if [ "$3" != "linear" ]; then + echo "Not a linear table" + exit 10 +fi + +# 3) Check if the container is a multipath table +tblmajor=${4%:*} +tblminor=${4#*:} + +tbldef=$($DMSETUP table -j $tblmajor -m $tblminor) +if [ $? -ne 0 ] || [ -z "$tbldef" ]; then + exit $? +fi +set -- $tbldef + +if [ "$3" != "multipath" ]; then + exit 20 +fi + +exit 0 diff --git a/multipathd/Makefile b/multipathd/Makefile index 7179096..42e1edd 100644 --- a/multipathd/Makefile +++ b/multipathd/Makefile @@ -56,11 +56,16 @@ install: install -m 644 71-multipath.rules $(DESTDIR)$(udevdir) install -m 644 72-multipath-compat.rules $(DESTDIR)$(udevdir) install -m 644 96-multipath-late.rules $(DESTDIR)$(udevdir) + install -m 755 mpath_id $(DESTDIR)$(bindir) uninstall: rm -f $(DESTDIR)$(bindir)/$(EXEC) rm -f $(DESTDIR)$(rcdir)/$(EXEC) rm -f $(DESTDIR)$(mandir)/$(EXEC).8 + rm -f $(DESTDIR)$(udevdir)/71-multipath.rules + rm -f $(DESTDIR)$(udevdir)/72-multipath-compat.rules + rm -f $(DESTDIR)$(udevdir)/96-multipath-late.rules + rm -f $(DESTDIR)$(udevdir)/mpath_id clean: $(MAKE) -C $(multipathdir) prepare DAEMON=1 diff --git a/multipathd/mpath_id b/multipathd/mpath_id new file mode 100644 index 0000000..38358dc --- /dev/null +++ b/multipathd/mpath_id @@ -0,0 +1,57 @@ +#!/bin/sh + +major=$1 +minor=$2 + +# Check for linear (kpartx) tables first +mptbl=$(/sbin/dmsetup table -j $major -m $minor --target linear) +if [ "$mptbl" ] ; then + set -- $mptbl + mpathmajor=${4%%:*} + mpathminor=${4##*:} + if [ "$mpathmajor" -ne "$major" ] ; then + # Not a device mapper device, exit + exit 1 + fi +else + mpathmajor=$major + mpathminor=$minor +fi + +mpstatus=$(/sbin/dmsetup status -j $mpathmajor -m $mpathminor --target multipath) +if [ "$mpstatus" ]; then + set -- $mpstatus + while [ $# -gt 0 ] ; do + : $1 + case $1 in + *:*) + devmajor=${1%%:*} + devminor=${1##*:} + line=$(sed -n "/ *$devmajor *$devminor .*/p" /proc/partitions) + devname=${line##* } + ;; + esac + [ "$devname" ] && break + shift + done + + case "$devname" in + dasd*) + echo ID_BUS=\"ccw\" ;; + *) + echo ID_BUS=\"scsi\" ;; + esac +else + # Not a multipath device, exit + exit 1 +fi + +mpid=$(/sbin/dmsetup info -c --noopencount --noheadings -o name -j $major -m $minor) + +if [ -z "$mpid" ]; then + exit 1 +fi +echo ID_MPATH=\"$mpid\" + +exit 0 +