SVN: geninitrd/trunk: Makefile geninitrd mod-ide.sh

glen glen at pld-linux.org
Wed Dec 10 16:34:53 CET 2008


Author: glen
Date: Wed Dec 10 16:34:52 2008
New Revision: 10032

Added:
   geninitrd/trunk/mod-ide.sh
Modified:
   geninitrd/trunk/Makefile
   geninitrd/trunk/geninitrd
Log:
- modularize ide component

Modified: geninitrd/trunk/Makefile
==============================================================================
--- geninitrd/trunk/Makefile	(original)
+++ geninitrd/trunk/Makefile	Wed Dec 10 16:34:52 2008
@@ -1,6 +1,6 @@
 # when making release, make sure you do it as RELEASE document describes
 VERSION		:= 10000
-MODS		:= mod-luks.sh mod-multipath.sh mod-dmraid.sh
+MODS		:= mod-ide.sh mod-luks.sh mod-multipath.sh mod-dmraid.sh
 FILES		:= Makefile geninitrd.sysconfig geninitrd functions $(MODS) geninitrd.8 geninitrd.8.xml ChangeLog
 prefix		:= /usr
 mandir		:= $(prefix)/share/man

Modified: geninitrd/trunk/geninitrd
==============================================================================
--- geninitrd/trunk/geninitrd	(original)
+++ geninitrd/trunk/geninitrd	Wed Dec 10 16:34:52 2008
@@ -27,8 +27,6 @@
 USE_TUXONICE=no
 # it should be safe to remove scsi_mod from here, but I'm not sure...
 PRESCSIMODS="-scsi_mod unknown -sd_mod"
-PREIDEMODS="-ide-core unknown -ide-detect -ide-disk"
-PREIDEMODSOLD="-ide-probe -ide-probe-mod -ide-disk"
 target=""
 kernel=""
 force=""
@@ -548,106 +546,6 @@
 	findmodule "-scsi_wait_scan"
 }
 
-find_modules_ide() {
-	local devpath=$1
-	# remove partition, if any
-	local disk=${devpath%[0-9]*}
-	# set blockdev for rootfs (hda, sdc, ...)
-	local rootblkdev=${disk#/dev/}
-
-	local n
-	if [ "$pack_version_long" -lt "002004021" ]; then
-		debug "Finding IDE modules for kernels <= 2.4.20"
-		for n in $PREIDEMODSOLD; do
-			findmodule "$n"
-		done
-	else
-		local tryauto=1
-		for n in $PREIDEMODS; do
-			if [ "X$n" = "Xunknown" ]; then
-				debug "Finding IDE modules using ide_hostadapter"
-				local mod idemodules=$(modprobe_conf | awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
-				for mod in $idemodules; do
-					tryauto=0;
-					findmodule "$mod"
-				done
-
-				if [ "$tryauto" -eq 1 ]; then
-					# If tryauto {{{
-					if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then
-						debug "Finding IDE modules using PCI ID database"
-						# Finding IDE modules using PCI ID database {{{
-						if is_yes "${ide_only_root}"; then
-							if [ -f /sys/block/${rootblkdev}/device/../../vendor -a -f /sys/block/${rootblkdev}/device/../../device ]; then
-								vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../vendor)"
-								deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../device)"
-								searchpciid="${vendorid}${deviceid}"
-							elif [ -f /proc/ide/${rootblkdev}/../config ]; then
-								searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootblkdev}/../config)"
-							fi
-						fi
-
-						if [ -z "${searchpciid}" ]; then
-							searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
-						fi
-
-						idemodules=""
-
-						for nb in $searchpciid; do
-							eval `awk -v pciid="$nb" '{
-								gsub("\t"," ");
-								gsub("  +", " ");
-								gsub("^ ","");
-								if (/^[\t ]*#/)
-									next;
-								compmod = $1 "";	# make sure comparison type will be string
-											# cause pci IDs are hexadecimal numeric
-								if (compmod == pciid) {
-									module=$2;
-							#		min_kernel=$3;  # now in ide.pci $3,$4 = vendor and device name
-							#		max_kernel=$4;  #
-									exit 0;
-								}
-							}
-
-							END {
-								print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
-							}' /usr/share/pci-database/ide.pci`
-							[ -n "$module" ] && idemodules="$idemodules $module"
-						done
-						if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then
-							new_idemodules=""
-							for nc in idemodules; do
-								new_idemodules="$nc $new_idemodules"
-							done
-							idemodules="${new_idemodules}"
-						fi
-
-						if [ -z "$idemodules" ]; then
-							warn "rootfs on IDE device but no related modules found, loading ide-generic."
-							idemodules="ide-generic"
-						fi
-
-						# }}}
-						for nd in $idemodules; do
-							findmodule "-$nd"
-						done
-					# }}}
-					# else tryauto {{{
-					else
-						[ -r /usr/share/pci-database/ide.pci ] || warn "/usr/share/pci-database/ide.pci missing."
-						[ -r /proc/bus/pci/devices ] || warn "/proc/bus/pci/devices missing."
-						warn "Automatic IDE modules finding not available."
-					fi
-					# }}}
-				fi
-			else
-				findmodule "$n"
-			fi
-		done
-	fi
-}
-
 # return true if node is lvm node
 is_lvm_node() {
 	local node="$1"
@@ -789,7 +687,7 @@
 		return
 	fi
 
-	if is_yes "$(echo "$devpath" | awk '/^\/dev\/(hd[a-l]|ide\/)/ { print "yes"; }')"; then
+	if is_ide "$devpath"; then
 		find_modules_ide "$devpath"
 		return
 	fi
@@ -1557,6 +1455,8 @@
 	. /etc/udev/udev.conf
 fi
 
+# ide addon
+. /etc/geninitrd/mod-ide.sh
 # cryptsetup luks addon
 . /etc/geninitrd/mod-luks.sh
 # dm-multipath addon

Added: geninitrd/trunk/mod-ide.sh
==============================================================================
--- (empty file)
+++ geninitrd/trunk/mod-ide.sh	Wed Dec 10 16:34:52 2008
@@ -0,0 +1,140 @@
+#!/bin/sh
+#
+# geninitrd mod: ide
+
+PREIDEMODS="-ide-core unknown -ide-detect -ide-disk"
+PREIDEMODSOLD="-ide-probe -ide-probe-mod -ide-disk"
+
+# ???
+ide_only_root=${ide_only_root:-no}
+
+# allow forcing loading IDE modules, likely from sysconfig/geninitrd
+ADDIDE=${ADDIDE:-no}
+
+# return true if node is ide device
+# @param	string $node device node to be examined
+# @access	public
+is_ide() {
+	local node="$1"
+	if [ ! -e "$node" ]; then
+		warn "is_ide(): node $node doesn't exist!"
+		return 1
+	fi
+
+	# TODO: more sophisticated check, not just pathname check
+	if is_yes "$(echo "$node" | awk '/^\/dev\/(hd[a-l]|ide\/)/ { print "yes"; }')"; then
+		return 0
+	fi
+
+	return 1
+}
+
+# find modules for $devpath
+# @param	$devpath	device to be examined
+# @access	public
+find_modules_ide() {
+	local devpath=$1
+	# remove partition, if any
+	local disk=${devpath%[0-9]*}
+	# set blockdev for rootfs (hda, sdc, ...)
+	local rootblkdev=${disk#/dev/}
+
+	local n
+	if [ "$pack_version_long" -lt "002004021" ]; then
+		debug "Finding IDE modules for kernels <= 2.4.20"
+		for n in $PREIDEMODSOLD; do
+			findmodule "$n"
+		done
+	else
+		local tryauto=1
+		for n in $PREIDEMODS; do
+			if [ "X$n" = "Xunknown" ]; then
+				debug "Finding IDE modules using ide_hostadapter"
+				local mod idemodules=$(modprobe_conf | awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
+				for mod in $idemodules; do
+					tryauto=0;
+					findmodule "$mod"
+				done
+
+				if [ "$tryauto" -eq 1 ]; then
+					# If tryauto {{{
+					if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then
+						debug "Finding IDE modules using PCI ID database"
+						# Finding IDE modules using PCI ID database {{{
+						if is_yes "${ide_only_root}"; then
+							if [ -f /sys/block/${rootblkdev}/device/../../vendor -a -f /sys/block/${rootblkdev}/device/../../device ]; then
+								vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../vendor)"
+								deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../device)"
+								searchpciid="${vendorid}${deviceid}"
+							elif [ -f /proc/ide/${rootblkdev}/../config ]; then
+								searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootblkdev}/../config)"
+							fi
+						fi
+
+						if [ -z "${searchpciid}" ]; then
+							searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
+						fi
+
+						idemodules=""
+
+						for nb in $searchpciid; do
+							eval `awk -v pciid="$nb" '{
+								gsub("\t"," ");
+								gsub("  +", " ");
+								gsub("^ ","");
+								if (/^[\t ]*#/)
+									next;
+								compmod = $1 "";	# make sure comparison type will be string
+											# cause pci IDs are hexadecimal numeric
+								if (compmod == pciid) {
+									module=$2;
+							#		min_kernel=$3;  # now in ide.pci $3,$4 = vendor and device name
+							#		max_kernel=$4;  #
+									exit 0;
+								}
+							}
+
+							END {
+								print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
+							}' /usr/share/pci-database/ide.pci`
+							[ -n "$module" ] && idemodules="$idemodules $module"
+						done
+						if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then
+							new_idemodules=""
+							for nc in idemodules; do
+								new_idemodules="$nc $new_idemodules"
+							done
+							idemodules="${new_idemodules}"
+						fi
+
+						if [ -z "$idemodules" ]; then
+							warn "rootfs on IDE device but no related modules found, loading ide-generic."
+							idemodules="ide-generic"
+						fi
+
+						# }}}
+						for nd in $idemodules; do
+							findmodule "-$nd"
+						done
+					# }}}
+					# else tryauto {{{
+					else
+						[ -r /usr/share/pci-database/ide.pci ] || warn "/usr/share/pci-database/ide.pci missing."
+						[ -r /proc/bus/pci/devices ] || warn "/proc/bus/pci/devices missing."
+						warn "Automatic IDE modules finding not available."
+					fi
+					# }}}
+				fi
+			else
+				findmodule "$n"
+			fi
+		done
+	fi
+}
+
+# generate initrd fragment for ide device init
+# @access	public
+initrd_gen_ide() {
+	# nothing to do here
+	return 0
+}


More information about the pld-cvs-commit mailing list