Skip to contentSkip to conversation

dracut-gencmdline: use udevadm info to go from /dev/X to /sys/Y

PATCH In review Alan Jenkins 1 participant 2 messages Oct 29, 2009 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dracut-gencmdline: use udevadm info to go from /dev/X to /sys/Y

Avoid some manual spelunking in sysfs. This makes for slightly shorter and simpler code.

dracut-gencmdline +13 -11
index 625546c..a4e2c3d 100755
@@ -169,17 +169,20 @@ resolve_device_name() {
     echo "$1" 
 }
 
+finddevinsys() {
+    path=$(udevadm info --name "$1" --query=path 2>/dev/null)
+    if [ -n "$path" ]; then
+        echo "/sys/$path"
+        return 0
+    fi
+    return 1
+}
+
 finddevnoinsys() {
     majmin="$1"
     if [ -n "$majmin" ]; then
-        dev=$(for x in /sys/block/* ; do find $x/ -name dev ; done | while read device ; do \
-              echo "$majmin" | cmp -s $device && echo $device ; done)
-        if [ -n "$dev" ]; then
-            dev=${dev%%/dev}
-            dev=${dev%%/}
-            echo "$dev"
-            return 0
-        fi
+        finddevinsys "/dev/block/$majmin"
+        return $?
     fi
     return 1
 }
@@ -252,11 +255,10 @@ findstoragedriver () {
         return
     fi
 
-    local majmin=$(get_numeric_dev dec "$device")
-    local sysfs=$(finddevnoinsys "$majmin")
+    local sysfs=$(finddevinsys "$device")
 
     if [ -z "$sysfs" ]; then
-        #error "WARNING: $device major:minor $majmin not found, skipping"
+        #error "WARNING: $device not found in sysfs, skipping"
         return
     fi
 

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 3 lines · Alan Jenkins

Avoid some manual spelunking in sysfs. This makes for slightly shorter and simpler code.

Argh, please ignore this patch.

dracut-gencmdline resolve_device_name() { · line 182

Quoted 11 lines
dracut-gencmdline +1 -8
+    path=$(udevadm info --name "$1" --query=path 2>/dev/null
 
-        dev=$(for x in /sys/block/* ; do find $x/ -name dev ; done | while read device ; do \
-              echo "$majmin" | cmp -s $device && echo $device ; done)
-        if [ -n "$dev" ]; then
-            dev=${dev%%/dev}
-            dev=${dev%%/}
-            echo "$dev"
-            return 0
-        fi

Device-mapper was still creating some of it's own device nodes as of April this year. So it's not safe to rely on udev knowing about everything in /dev.