[arch-releng] [PATCH 2/2] Use globbing and parameter expansion to get the raid slave devices

pyther at pyther.net pyther at pyther.net
Sun Jan 23 17:55:45 EST 2011


Uses bash globbing and parameter expansion to find all of the slaves for
a raid device. This is a much better method then using ls. Also, by
looking at DEVNAME in the uevent file we provide support for block
device that are not in the root of /dev.

call die_error if a block device is not passed into device_is_raid()
---
 src/core/libs/lib-blockdevices-filesystems.sh |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh
index 8451f15..f388d5b 100644
--- a/src/core/libs/lib-blockdevices-filesystems.sh
+++ b/src/core/libs/lib-blockdevices-filesystems.sh
@@ -921,7 +921,8 @@ get_blockdevice_size ()
 # $1 blockdevice (ex: /dev/md0 or /dev/sda1)
 # All MD RAID block devices have a major id of 9
 device_is_raid() {
-    [[ $1 && -f /proc/mdstat ]] || return 1
+    [[ -b "$1" ]] || die_error "device_is_raid needs a blockdevice as \$1 ($1 given)"
+    [[ -f /proc/mdstast ]] || return 1
     local devmajor=$(stat -c %t "$1")
     (( devmajor == 9 ))
 } 
@@ -942,10 +943,13 @@ mdraid_slave0 ()
 # ex: /dev/md0 has slaves: "/dev/sda1 /dev/sdb2 /dev/sdc2"
 mdraid_all_slaves ()
 {
+    shopt -s nullglob
     local slave=
-    local slaves=
-    for slave in $(ls /sys/class/block/$(basename $1)/slaves/); do
-        slaves=$slaves"/dev/"$slave" "
+    local slaves= 
+    for slave in /sys/class/block/${1##*/}/slaves/*; do
+        source "$slave/uevent"
+        slaves="$slaves/dev/$DEVNAME "
+        unset DEVNAME
     done
     echo $slaves
 }
-- 
1.7.3.5



More information about the arch-releng mailing list