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

Dieter Plaetinck dieter at plaetinck.be
Sat Jan 29 11:50:40 EST 2011


On Sat, 29 Jan 2011 11:35:33 -0500
Matthew Gyurgyik <pyther at pyther.net> wrote:

> On 01/29/2011 11:33 AM, pyther at pyther.net 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 |   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
> >   }
> This version of the patch unsets nullglob at the end of the function

thanks, applied.
Btw, both this patch and the device_is_raid one added trailing whitespace.
I ammended both commits for now, but please make sure the patch is cleaner next time.

Dieter


More information about the arch-releng mailing list