[arch-releng] [PATCH 1/2] Renamed mdraid_is_raid to device_is_raid
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. call die_error if a block device is not passed into device_is_raid() --- src/core/libs/lib-blockdevices-filesystems.sh | 21 +++++++-------------- src/core/libs/lib-ui-interactive.sh | 2 +- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index 8573b19..021f41b 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -919,20 +919,13 @@ 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 -} +# All MD RAID block devices have a major id of 9 +device_is_raid() { + [[ -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 )) +} # $1 md raid blockdevice (ex: /dev/md0) # return the array member device which is slave 0 in the given array 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 -- 1.7.3.5
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 } -- 1.7.3.5
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
On Sun, 23 Jan 2011 18:06:22 -0500, pyther@pyther.net wrote: 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:~ $
On Sun, 23 Jan 2011 18:06:21 -0500 pyther@pyther.net wrote:
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.
call die_error if a block device is not passed into device_is_raid() --- src/core/libs/lib-blockdevices-filesystems.sh | 21 +++++++-------------- src/core/libs/lib-ui-interactive.sh | 2 +- 2 files changed, 8 insertions(+), 15 deletions(-)
diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index 8573b19..021f41b 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -919,20 +919,13 @@ 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 -} +# All MD RAID block devices have a major id of 9 +device_is_raid() { + [[ -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 )) +}
# $1 md raid blockdevice (ex: /dev/md0) # return the array member device which is slave 0 in the given array 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
I merged the first patch. For the second, I looked in both my mailbox and github and haven't found the correct version with the nullglob disabling. Dieter
participants (2)
-
Dieter Plaetinck
-
pyther@pyther.net