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

pyther at pyther.net pyther at pyther.net
Sat Jan 29 11:33:53 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.
---
 src/core/libs/lib-blockdevices-filesystems.sh |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh
index 021f41b..7731d9f 100644
--- a/src/core/libs/lib-blockdevices-filesystems.sh
+++ b/src/core/libs/lib-blockdevices-filesystems.sh
@@ -943,10 +943,14 @@ 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
+    shopt -u nullglob
     echo $slaves
 }
-- 
1.7.3.5



More information about the arch-releng mailing list