On Sun, 23 Jan 2011 18:06:22 -0500, [email protected] wrote:
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 |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/core/libs/lib-blockdevices-filesystems.sh
b/src/core/libs/lib-blockdevices-filesystems.sh
index 021f41b..f388d5b 100644
--- a/src/core/libs/lib-blockdevices-filesystems.sh
+++ b/src/core/libs/lib-blockdevices-filesystems.sh
@@ -943,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
 }
Falconindy mentioned that nullglob will apply to the current shell, just not the local function. Therefore nullglob will need be unset at the end of this function (shopt -s nullglob).

See below output:
R2D2:~ $ ls /tmp/test
R2D2:~ $ for x in /tmp/test/*; do echo $x; done
/tmp/test/*
R2D2:~ $ func() { shopt -s nullglob; for x in /tmp/test/*; do echo $x; done; }
R2D2:~ $ func
R2D2:~ $ for x in /tmp/test/*; do echo $x; done
R2D2:~ $ func() { shopt -s nullglob; for x in /tmp/test/*; do echo $x; done; shopt -u nullglob; }
R2D2:~ $ func
R2D2:~ $ for x in /tmp/test/*; do echo $x; done/tmp/test/*
/tmp/test/*
R2D2:~ $

Reply via email to