Re: PATCH: Streamline mkinitrd storage device dedection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hans de Goede wrote:

mkinitrd | 189 ++++++++++++++++++++++++--------------------------------------
 1 files changed, 72 insertions(+), 117 deletions(-)

diff --git a/mkinitrd b/mkinitrd
index fb1cf3f..6f4847f 100755
--- a/mkinitrd
+++ b/mkinitrd
@@ -283,7 +283,7 @@ access() {
 finddevnoinsys() {
     majmin="$1"
     if [ -n "$majmin" ]; then
- dev=$(for x in /sys/block/* ; do findall $x/ -name dev ; done | while read device ; do \ + dev=$(for x in /sys/block/* ; do findall $x -name dev ; done | while read device ; do \
               echo "$majmin" | cmp -s $device && echo $device ; done)
         if [ -n "$dev" ]; then
             dev=${dev%%/dev}
@@ -295,60 +295,7 @@ finddevnoinsys() {
     return 1
 }

This bit is obviated by the fix in the other thread.

-findblockdevinsys() {
-    devname=$(resolve_device_name "$1")
-    if [[ "$devname" =~ ^/sys/block/ ]]; then
-        echo "$devname"
-    fi
- # check if it's a dm-crypt device. if so, just return the /dev/mapper path
-    if [[ "$devname" =~ ^/dev/mapper/ ]]; then
- type=$(/sbin/dmsetup table $(basename $devname) | awk '{print $3}')
-        if [ "$type" == "crypt" ]; then
-            echo "$devname"
-            return 0
-        fi
-    fi
-    majmin=$(get_numeric_dev dec $devname)
-    finddevnoinsys "$majmin"
-}
-
-slavestried=""
-handledsysfspaths=""
-
-findstoragedriverinsys () {
-    while [ ! -L device ]; do
-        for slave in $(ls -d slaves/* 2>/dev/null) ; do
-            [ -e $slave ] || continue
-            slavename=${slave##*/}
-            case " $slavestried " in
-                *" $slavename "*)
-                    continue
-                    ;;
-                *)
-                    slavestried="$slavestried $slavename"
-                    if [ -L $slave ]; then
-                        slave=$(readlink $slave)
-                    fi
-                    qpushd $slave
-                    findstoragedriverinsys
-                    qpopd
-                    ;;
-            esac
-        done
-        [ "$PWD" = "/sys" ] && return
-        cd ..
-    done
-
-    cd $(readlink ./device)
-    case " $handledsysfspaths " in
-        *" $PWD "*)
-            return
-            ;;
-        *)
-            handledsysfspaths="$handledsysfspaths $PWD"
-            ;;
-    esac
-
+finddevicedriverinsys () {
     if is_iscsi $PWD; then
         handleiscsi "$PWD"
         return
@@ -376,40 +323,69 @@ findstoragedriverinsys () {
     done
 }

-findstoragedriver () {
-    for device in $@ ; do
-        case " $handleddevices " in
-            *" $device "*)
-                continue ;;
-            *) handleddevices="$handleddevices $device" ;;
-        esac
-        if [[ "$device" =~ "^md[0-9]+" ]]; then
-            vecho "Found RAID component $device"
-            handleraid "$device"
-            continue
-        fi
-        vecho "Looking for driver for device $device"
-        if [[ "$device" =~ ^/sys ]]; then
-            device=${device##*/}
-        fi
-        if [[ "$device" =~ ^(dm-|mapper/) ]]; then
-            majmin=$(get_numeric_dev dec "/dev/$device")
-            sysfs=$(finddevnoinsys $majmin)
- handledm $(echo "$majmin" |cut -d : -f 1) $(echo "$majmin" |cut -d : -f 2)
-        else
-            sysfs=""
-            device=$(echo "$device" | sed 's,/,!,g')
-            if [ -d /sys/block/$device/ ]; then
-                sysfs="/sys/block/$device"
-            else
- sysfs=$(for x in /sys/block/* ; do findone -type d $x/ -name $device; done)
-            fi
-        fi
-        [ -z "$sysfs" -o ! -e "$sysfs" ] && continue
-        qpushd $sysfs
-        findstoragedriverinsys
-        qpopd
+findstoragedriverinsys () {
+    local sysfs=$(readlink "$1")
+
+    # if its a partition look at the device holding the partition
+    if [ -f "$sysfs/partition" ]; then
+        sysfs=$(readlink ${sysfs%/*})
+    fi
+
+    if [[ ! "$sysfs" =~ '^/sys/devices/.*/block/.*$' ]]; then
+        error "WARNING: $sysfs is a not a block sysfs path, skipping"
+        return
+    fi
+
+    if [ ! -e "$sysfs" ]; then
+        error "WARNING: sysfspath $sysfs does not exist, skipping"
+        return
+    fi

If we hit this test, isn't the kernel totally broken?

+
+    case " $handleddevices " in
+        *" $sysfs "*)
+            return ;;
+        *) handleddevices="$handleddevices $sysfs" ;;
+    esac
+
+    if [[ "$sysfs" =~ '^/sys/devices/virtual/block/md[0-9]+$' ]]; then
+        local raid=${sysfs##*/}
+        vecho "Found MDRAID component $raid"
+        handleraid $raid
+    fi
+    if [[ "$sysfs" =~ '^/sys/devices/virtual/block/dm-[0-9]+$' ]]; then
+        vecho "Found DeviceMapper component ${sysfs##*/}"
+ handledm $(cat $sysfs/dev |cut -d : -f 1) $(cat $sysfs/dev |cut -d : -f 2)
+    fi

cut isn't allowed because it's in /usr/bin ; use sed for this.

Basically I think this patch should work, but I'm not entirely sure cciss won't break.

--
        Peter

Power corrupts.  Absolute power is kind of neat.
		-- John Lehman, Secretary of the Navy, 1981-1987

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux