[arch-releng] [PATCH] Renamed mdraid_is_raid to device_is_raid; new mdraid_all_slaves function

Dieter Plaetinck dieter at plaetinck.be
Sun Jan 23 03:46:09 EST 2011


On Sat, 22 Jan 2011 19:19:20 -0500
Matthew Gyurgyik <pyther at pyther.net> wrote:

> On 01/22/2011 07:15 PM, pyther at pyther.net wrote:
> > Renamed mdraid_is_raid to device_is_raid
> >
> > falconindy rewrote the device_is_raid and mdraid_all_slaves
> > functions
> >
> > device_is_raid now uses dev major number to determine if a device
> > is a raid device. A major ID of 8 is a /dev/sd? device whereas a
> > major ID of 9 is a 'metadata' (raid) device.
> >
> > mdraid_all_slaves now uses a parameter expansion, reads the uevents
> > file to get the DEVNAME and appends /dev to DEVNAME
> > ---
> >   src/core/libs/lib-blockdevices-filesystems.sh |   31
> > +++++++++----------------
> > src/core/libs/lib-ui-interactive.sh           |    2 +- 2 files
> > changed, 12 insertions(+), 21 deletions(-)
> >
> > diff --git a/src/core/libs/lib-blockdevices-filesystems.sh
> > b/src/core/libs/lib-blockdevices-filesystems.sh index
> > 8573b19..2bb0a74 100644 ---
> > a/src/core/libs/lib-blockdevices-filesystems.sh +++
> > b/src/core/libs/lib-blockdevices-filesystems.sh @@ -920,19 +920,11
> > @@ get_blockdevice_size ()
> >
> >   # $1 blockdevice (ex: /dev/md0 or /dev/sda1)
> >   # return true when blockdevice is an md raid, otherwise return a
> > unset value -mdraid_is_raid()
> > -{
> > -    local israid
> > -    if [ -z $1 ]; then
> > -        # Don't call mdadm on empty blockdevice parameter!
> > -        israid=""
> > -    elif [ "$(mdadm --query $1 | cut -d':' -f2)" == " is not an md
> > array" ]; then
> > -        israid=""
> > -    else
> > -        israid=true
> > -    fi
> > -    echo $israid
> > -}
> > +device_is_raid() {
> > +    [[ $1&&  -f /proc/mdstat ]] || return 1
> > +    local devmajor=$(stat -c %t "$1")
> > +    (( devmajor == 9 ))
> > +}
> >
> Was looking for /proc/mdadm which didn't exist!
> >   # $1 md raid blockdevice (ex: /dev/md0)
> >   # return the array member device which is slave 0 in the given
> > array @@ -948,12 +940,11 @@ mdraid_slave0 ()
> >   # $1 md raid blockdevice (ex: /dev/md0)
> >   # return a list of array members from given md array
> >   # ex: /dev/md0 has slaves: "/dev/sda1 /dev/sdb2 /dev/sdc2"
> > -mdraid_all_slaves ()
> > -{
> > -    local slave=
> > -    local slaves=
> > -    for slave in $(ls /sys/class/block/$(basename $1)/slaves/); do
> > -        slaves=$slaves"/dev/"$slave" "
> > +mdraid_all_slaves () {
> > +    shopt -s nullglob
> > +    for slave in /sys/class/block/${1##*/}/slaves/*; do
> > +        eval $(cat $slave/uevent)
> > +        echo /dev/$DEVNAME
> > +        unset DEVNAME
> >       done
> > -    echo $slaves
> >   }
> Uses uevent to determine the device name and appends /dev. This is 
> better in case we have a device that does not reside in the root
> of /dev.
> > diff --git a/src/core/libs/lib-ui-interactive.sh
> > b/src/core/libs/lib-ui-interactive.sh index 881af90..829556a 100644
> > --- a/src/core/libs/lib-ui-interactive.sh
> > +++ b/src/core/libs/lib-ui-interactive.sh
> > @@ -878,7 +878,7 @@ interactive_grub() {
> >           bootdev=$(mount | grep $var_TARGET_DIR/boot | cut -d' '
> > -f 1) # check if bootdev or PART_ROOT is on a md raid array
> >           # This dialog is only shown when we detect / or /boot on
> > a raid device.
> > -		if [ -n "$(mdraid_is_raid $bootdev)" -o -n
> > "$(mdraid_is_raid $PART_ROOT)" ]; then
> > +		if device_is_raid $bootdev || device_is_raid
> > $PART_ROOT; then ask_yesno "Do you have your system installed on
> > software raid?\nAnswer 'YES' to install grub to another hard disk."
> > no if [ $? -eq 0 ]; then onraid=true
> Fixed this code, wasn't thinking!

so, did you test it this time?
(both a raid and non-raid case?)

Dieter


More information about the arch-releng mailing list