From d11ba0046d74b61f14c79c0793e53a99e51395cb Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 11 Feb 2012 13:53:49 -0500 Subject: autodetect: refactor raid device detection FS#10061 still isn't dead, its just resting: https://bbs.archlinux.org/viewtopic.php?pid=1056003 An strace from a helpful user shows that our mdadm call is trying to open a block device and the call never returns: open("/dev/sdb", O_RDONLY|O_DIRECT|O_LARGEFILE Fix this by only scanning explicitly the block devices we're interested in, found via sysfs. This is an all around win for everyone, especially users who have mdadm installed without any need for it. This changes some of our assumptions about the environment: - the mdadm binary exists when we find md devices in /sys - the user running mkinitcpio isn't any specific UID or part of any particular group, but merely has read access to the block devices we're about to scan. Signed-off-by: Dave Reisner --- install/autodetect | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'install/autodetect') diff --git a/install/autodetect b/install/autodetect index 3fb87ce..5cc908c 100644 --- a/install/autodetect +++ b/install/autodetect @@ -1,6 +1,9 @@ #!/bin/bash build() { + local -a md_devs + local dev insufficient_perms + MODULE_FILE=$workdir/autodetect_modules add_if_avail() { @@ -29,15 +32,28 @@ build() { add_if_avail "$usrfstype" fi - if (( UID == 0 )) || in_array 'disk' $(groups); then - if [[ -x $(type -P mdadm) ]]; then - mdadm -Esv /dev/[hrsv]d* /dev/{ida,cciss,ataraid,mapper}/* | + # look for raid devices + shopt -s nullglob + for dev in /sys/class/block/*/md/dev-*; do + dev=/dev/${dev#*/dev-} + + [[ -r $dev ]] || insufficient_perms=1 + + md_devs+=("$dev") + done + shopt -u nullglob + + # scan members of raid devices if found + if (( ${#md_devs[*]} )); then + (( !QUIET )) && plain "found %d raid members to scan" "${#md_devs[*]}" + if (( ! insufficient_perms )); then + mdadm -Esv "${md_devs[@]}" | sed -n 's/.*level=\([^ ]\+\) .*/\1/p' | sed 's/\/raid456/g' | sort -u >>"$MODULE_FILE" + else + warning "Insufficient permission to perform autodetection for mdadm devices" + raid_autodetect_failed=1 fi - else - error "Insufficient permission to perform autodetection for mdadm devices" - raid_autodetect_failed=1 fi if (( !QUIET )) && [[ -s $MODULE_FILE ]]; then -- cgit v1.2.3-24-g4f1b