Fix ba_map regression
authorBryn M. Reeves <bmr@redhat.com>
Mon, 21 Jan 2013 14:16:37 +0000 (14:16 +0000)
committerBryn M. Reeves <bmr@redhat.com>
Mon, 21 Jan 2013 14:16:37 +0000 (14:16 +0000)
The local variable fixes introduced a regression in device mapping
preventing any aliases from being linked by udev.

Fix this by correcting local variable name usage and dmsetup
invocation.

This patch also improved debug logging in these functions to make
debugging future problems easier.

Note that the map command depends on a udev-like environment and
this must be supplied manually if testing outside of the context
of udev rule processing, for e.g.:

  [root@rhel6-vm1 ~]# ID_BUS=scsi DEVNAME=sda BA_DEBUG=yes \
     /sbin/blkdevalias map 0QEMU_QEMU_HARDDISK_drive-scsi0-0-0
  ba_map: 0QEMU_QEMU_HARDDISK_drive-scsi0-0-0 -> DSK1
  ba_get_partnum: sda
  calling /sbin/dmsetup info sda
  ba_get_partnum: non-dm device sda NUM=
  ba_map: WWID=0QEMU_QEMU_HARDDISK_drive-scsi0-0-0 PART=0 TYPE=sd
  BA_WWID=0QEMU_QEMU_HARDDISK_drive-scsi0-0-0
  BA_NAME=oracleasm/disks/DSK1
  BA_TYPE=sd
  BA_USER=oracle
  BA_GROUP=oracle
  BA_MODE=0660

  [root@rhel6-vm1 ~]# DM_NAME=mpathc DEVNAME=dm-1 \
     /sbin/blkdevalias map 0QEMU_QEMU_HARDDISK_drive-scsi0-0-2
  BA_WWID=0QEMU_QEMU_HARDDISK_drive-scsi0-0-2
  BA_NAME=oracleasm/disks/DSK3
  BA_TYPE=mpath
  BA_USER=oracle
  BA_GROUP=oracle
  BA_MODE=0660

blkdevalias

index 42c548e..0600ab2 100755 (executable)
@@ -173,15 +173,18 @@ ba_del_wwid_mapping() {
 ba_get_partnum () {
     local _DEV _NUM
     _DEV="$1"
-    if [[ $DEV == dm-* ]]; then
+    if [[ $_DEV == dm-* ]]; then
         _DEV=$DM_NAME
     fi
     _debug "ba_get_partnum: $_DEV"
+    _debug calling "$BA_DMSETUP info $_DEV"
     $BA_DMSETUP info $_DEV > /dev/null 2>&1
     if [ "$?" == "0" ]; then
         _NUM=$(echo $_DEV | sed -e 's/\/dev.*\///' -e 's/.*p\([0-9]*\).*/\1/')
+        _debug "ba_get_partnum: dm device $_DEV NUM=$_NUM"
     else
         _NUM=$(echo $_DEV | sed 's/\(\/dev\/\)*sd[a-z]*//')
+        _debug "ba_get_partnum: non-dm device $_DEV NUM=$_NUM"
     fi
     if [ "$_NUM" == "" ]; then
         _NUM="0"
@@ -210,7 +213,7 @@ ba_chown_configs () {
     _GROUP="$2"
     $BA_CHOWN -R "$_USER:$_GROUP" "$BA_CONF_PATH"
     ls -l "$BA_CONF_PATH" | while read _OUT; do
-        _debug $_OUT
+        _debug "ba_chown_configs: $_OUT"
     done
     return 0
 }
@@ -219,16 +222,17 @@ ba_chown_configs () {
 ba_refresh_device () {
     local _DEVPATH _DEVNAME _LINKDEST
     _DEVPATH="$1"
-    _debug "refreshing device at path $_DEVPATH"
+    _debug "ba_refresh_device: refreshing device at path $_DEVPATH"
     _LINKDEST=$($BA_READLINK $_DEVPATH)
     if [ "$?" != 0 ]; then
         _DEVNAME=$($BA_BASENAME $_DEVPATH | $BA_SED 's/p\+[1-9]*$//')
-        _debug "non-symlinked dev at $_DEVPATH has name $_DEVNAME"
+        _debug "ba_refresh_device: non-symlinked dev at $_DEVPATH has name $_DEVNAME"
     else
         _DEVNAME=$($BA_BASENAME $_LINKDEST)
-        _debug "symlinked dev at $_DEVPATH has name $_DEVNAME"
+        _debug "ba_refresh_device: symlinked dev at $_DEVPATH has name $_DEVNAME"
     fi
-    _debug "requesting change uevent at sysfs path /sys/block/$_DEVNAME"
+    _debug "ba_refresh_device: requesting change uevent at" \
+            "sysfs path /sys/block/$_DEVNAME"
     $BA_SUDO $BA_SH -c "echo change > /sys/block/$_DEVNAME/uevent"
 }
 
@@ -392,6 +396,7 @@ ba_scandisks () {
 ba_map () {
     local _WWID _TYPE _PART
     _WWID="$1"
+    _debug "ba_map: $_WWID -> ${WWIDMAP[$_WWID]}"
     if [ "$_WWID" == "" ] || [ "${WWIDMAP[$_WWID]}" == "" ]; then
         ba_usage "map <wwid>"
         exit 2
@@ -402,6 +407,7 @@ ba_map () {
     else
         _TYPE=mpath
     fi
+    _debug "ba_map: WWID=$_WWID PART=$_PART TYPE=$_TYPE"
     if [ "$_PART" != ${PARTMAP[$_WWID]} ] \
         || [ "$_TYPE" != ${TYPEMAP[$_WWID]} ] ; then
         exit 1