SVN: geninitrd/trunk/geninitrd

glen glen at pld-linux.org
Fri Feb 27 17:58:18 CET 2009


Author: glen
Date: Fri Feb 27 17:58:17 2009
New Revision: 10152

Modified:
   geninitrd/trunk/geninitrd
Log:
- handle LVM PV consisting colon in path: /dev/block/104:2

Modified: geninitrd/trunk/geninitrd
==============================================================================
--- geninitrd/trunk/geninitrd	(original)
+++ geninitrd/trunk/geninitrd	Fri Feb 27 17:58:17 2009
@@ -350,7 +350,7 @@
 			[ $m = $mod ] && have=1
 		done
 		if [ $have = 0 ]; then
-			MODULES="$MODULES $mod" 
+			MODULES="$MODULES $mod"
 
 			# if we are adding uvesafb, we need v86d as well
 			if [ "$modName" = "uvesafb" ]; then
@@ -550,7 +550,7 @@
 is_lvm_node() {
 	local node="$1"
 	if [ ! -e "$node" ]; then
-		warn "check_lvm(): node $node doesn't exist!"
+		die "check_lvm(): node $node doesn't exist!"
 		return 1
 	fi
 
@@ -559,13 +559,11 @@
 	rc=$?
 
 	if [ $rc = 0 ]; then
-		debug "LVM check: $node is LVM v1 node"
 		# is lvm1
 		return 0
 	fi
 
 	if [ ! -x /sbin/lvm ]; then
-		debug "LVM check: no lvm2 tools present to check"
 		return 0
 	fi
 
@@ -576,14 +574,24 @@
 		die "Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?"
 	fi
 
-	if [ $rc = 0 ]; then
-		debug "LVM check: $node is LVM v2 node"
-	else
-		debug "LVM check: $node is not any LVM node"
-	fi
 	return $rc
 }
 
+# find PV names from given VG name
+find_lvm_pv() {
+	local vg="$1"
+
+	local pv=$(/sbin/vgdisplay -C --noheadings -o pv_name "$vg")
+	echo $pv
+}
+
+# find VG name from given devnode
+find_lvm_vg() {
+	local devnode="$1"
+
+	local vg=$(/sbin/lvdisplay -C --noheadings -o vg_name "$devnode")
+	echo $vg
+}
 
 # return dependencies MAJOR:MINOR [MAJOR:MINOR] for DM_NAME
 # TODO: patch `dmsetup export`
@@ -627,12 +635,17 @@
 		die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?"
 	fi
 
-	# /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
-	case "$devpath" in
-	/dev/dm-*)
+	if [[ "$devpath" = /dev/dm-* ]]; then
+		# /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
 		devpath=$(dm_longname "$devpath")
-		;;
-	esac
+	fi
+
+	if [ -L "$devpath" ] && ! is_lvm_node "$devpath"; then
+		# sanitize things like:
+		# /dev/block/104:2 -> /dev/cciss/c0d0p2
+		devpath=$(readlink -f "$devpath")
+	fi
+
 	debug "Finding modules for device path $devpath"
 
 	if is_luks "$devpath"; then
@@ -749,6 +762,8 @@
 	fi
 
 	if is_lvm_node "$devpath"; then
+		debug "LVM: $devpath is LVM node"
+
 		node="$devpath"
 
 		if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ]; then
@@ -761,9 +776,12 @@
 			fi
 		fi
 
-		local vg=$(/sbin/lvdisplay -c "$node" 2> /dev/null | awk -F":" ' { print $2 } ')
+		local vg=$(find_lvm_vg "$node")
+		debug "LVM VG for $node: $vg"
 		VGVOLUMES=$(echo $VGVOLUMES $vg | tr ' ' '\n' | sort -u)
-		local pv=$(/sbin/pvdisplay -c 2>/dev/null | awk -F":" -v vg="$vg" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
+
+		local pv=$(find_lvm_pv "$vg")
+		debug "LVM PV for $vg: $pv"
 		PVDEVICES=$(echo $PVDEVICES $pv | tr ' ' '\n' | sort -u)
 
 		if [ -n "$PVDEVICES" ]; then
@@ -773,6 +791,7 @@
 		else
 			die "I wasn't able to find PV (via lvdisplay and pvdisplay). You can try to set PVDEVICES in /etc/sysconfig/geninitrd."
 		fi
+
 		if [ "$LVMTOOLSVERSION" = "2" ]; then
 			findmodule "-dm-mod"
 		elif [ "$LVMTOOLSVERSION" = "1" ]; then
@@ -781,6 +800,7 @@
 		else
 			die "LVM version $LVMTOOLSVERSION is not supported yet."
 		fi
+
 		debug "LVM v$LVMTOOLSVERSION enabled"
 		have_lvm=yes
 		return


More information about the pld-cvs-commit mailing list