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

[RFC] Some love for partman-md v2



Hi!

Thanks Frans and Max for your comments. :)

Most of your remarks have been addressed in the revised patch.  I am not
making a detailed reply as I won't really be able to spend more time on
this right now.  Feel free to pick the work where it is if you feel that
I have missed something important.

On Sat, May 31, 2008 at 05:47:26PM +0200, Frans Pop wrote:
> AFAICT you are effectively also closing #475479 (which is good!). See my 
> analysis in http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=475479#17.
> Has that been explicitly tested? Probably has as I think it's the same as 
> #391479.

I just tested this, and the bug is indeed fixed by the patch.  I have
added the necessary "Closes".

> AFAICT #391483 already was solved by my recent changes (if not earlier).

Is there any harm in closing it with this patch?

> What should also be explicitly tested with these changes is:
> - LVM on RAID
> - delete a RAID device -> create new RAID device
> - delete a RAID device -> finish (is partman info updated> -> create new
>   RAID device

I have tested all these cases and they work fine.  \o/

Cheers,
-- 
Jérémy Bobbio
commit 93fcba972d6b1ecf97b932c5145399112f3778dc
Author: Jérémy Bobbio <lunar@debian.org>
Date:   Thu May 29 16:12:16 2008 +0000

    Clean up the initialization of MD devices
    
    The initialization of MD devices in partman previously diverged from what
    others partman components are doing, resulting in quite few bugs and
    really bad interactions with crypto setup.
    
     * Scanning for existing MD devices
    
       During partman initialization, the init.d/md-devices script now load
       kernel modules and scan for MD devices the first time it is started.
    
       This script has been move to be called before init.d/parted to have
       existing RAID partitions listed on the first partitioner run.
    
       Thus, existing MD devices will now be activated at the begining of
       the partionner.  (Closes: #391474)
    
       The same code snippet in mdcfg is now only called if /proc/mdstat did
       exist before.  The attempt to load the ancient "md" module has also
       been removed.
    
     * Keep configurations of RAID partitions accross partman restarts
    
       MD devices were previously skipped in init.d/parted, resulting in the
       loss of the previous configuration.  We now only skip deactivated RAID
       devices, in a similar way than sataraid and multipath devices are
       skipped.
    
       Most of the job of init.d/md and init.d/md-devices have been cleaned up
       and merged into init.d/md to cope with the previous change. The
       initialization scheme is now closer to what is done for LVM.
    
       (Closes: #391479, #391483, #393728, #398668, #475479)

diff --git a/packages/mdcfg/debian/changelog b/packages/mdcfg/debian/changelog
index 2543ba2..42e479a 100644
--- a/packages/mdcfg/debian/changelog
+++ b/packages/mdcfg/debian/changelog
@@ -1,3 +1,12 @@
+mdcfg (1.27) UNRELEASED; urgency=low
+
+  [ Jérémy Bobbio ]
+  * mdcfg now load kernel modules and scan MD devices only if /proc/mdstat did
+    not exist before.
+  * Remove the attempt to load the anciant module "md".
+
+ -- Jérémy Bobbio <lunar@debian.org>  Thu, 29 May 2008 17:46:31 +0000
+
 mdcfg (1.26) unstable; urgency=low
 
   [ Updated translations ]
diff --git a/packages/mdcfg/mdcfg.sh b/packages/mdcfg/mdcfg.sh
index 37a1f09..cbbaf17 100755
--- a/packages/mdcfg/mdcfg.sh
+++ b/packages/mdcfg/mdcfg.sh
@@ -502,31 +502,36 @@ md_mainmenu() {
 
 ### Main of script ###
 
-# Try to load the necesarry modules.
-# Supported schemes: RAID 0, RAID 1, RAID 5
-depmod -a >/dev/null 2>&1
-modprobe md >/dev/null 2>&1 || modprobe md-mod >/dev/null 2>&1
-modprobe raid0 >/dev/null 2>&1
-modprobe raid1 >/dev/null 2>&1
-# kernels >=2.6.18 have raid456
-modprobe raid456 >/dev/null 2>&1 || modprobe raid5 >/dev/null 2>&1
-
-# Try to detect MD devices, and start them
-# mdadm will fail if /dev/md does not already exist
-mkdir -p /dev/md
-
-log-output -t mdcfg --pass-stdout \
-	mdadm --examine --scan --config=partitions >/tmp/mdadm.conf
-
-log-output -t mdcfg \
-	mdadm --assemble --scan --run --config=/tmp/mdadm.conf --auto=yes
-
-# Make sure that we have md-support
-if [ ! -e /proc/mdstat ]; then
-	db_set mdcfg/nomd false
-	db_input high mdcfg/nomd
-	db_go
-	exit 0
+# Load the modules and scan for MD devices if needed
+if ! [ -e /proc/mdstat ]; then
+	# Try to load the necesarry modules.
+	# Supported schemes: RAID 0, RAID 1, RAID 5
+	depmod -a >/dev/null 2>&1
+	modprobe md-mod >/dev/null 2>&1
+
+	# Make sure that we have md-support
+	if [ ! -e /proc/mdstat ]; then
+		db_set mdcfg/nomd false
+		db_input high mdcfg/nomd
+		db_go
+		exit 0
+	fi
+
+	modprobe raid0 >/dev/null 2>&1
+	modprobe raid1 >/dev/null 2>&1
+	# kernels >=2.6.18 have raid456
+	modprobe raid456 >/dev/null 2>&1 || modprobe raid5 >/dev/null 2>&1
+
+	# Try to detect MD devices, and start them
+	# mdadm will fail if /dev/md does not already exist
+	mkdir -p /dev/md
+
+	log-output -t mdcfg --pass-stdout \
+		mdadm --examine --scan --config=partitions >/tmp/mdadm.conf
+
+	log-output -t mdcfg \
+		mdadm --assemble --scan --run \
+		--config=/tmp/mdadm.conf --auto=yes
 fi
 
 # Force mdadm to be installed on the target system
diff --git a/packages/partman/partman-base/debian/changelog b/packages/partman/partman-base/debian/changelog
index e81d2bf..bd3c85a 100644
--- a/packages/partman/partman-base/debian/changelog
+++ b/packages/partman/partman-base/debian/changelog
@@ -1,10 +1,15 @@
 partman-base (121) UNRELEASED; urgency=low
 
+  [ Frans Pop ]
   * Add divider below "Use as" in ithe partition options dialog. If the
     partition is used for encryption, "Encryption method" will also be
     above the divider. As changing these option changes defaults and what
     other options are available, this provides a useful visual separation.
 
+  [ Jérémy Bobbio ]
+  * Instead of skipping every MD devices during partman initialization, we
+    now only skip the ones that are deactivated.  (Closes: #475479)
+
  -- Frans Pop <fjp@debian.org>  Fri, 30 May 2008 17:56:28 +0200
 
 partman-base (120) unstable; urgency=high
diff --git a/packages/partman/partman-base/init.d/parted b/packages/partman/partman-base/init.d/parted
index 346170a..7c070fe 100755
--- a/packages/partman/partman-base/init.d/parted
+++ b/packages/partman/partman-base/init.d/parted
@@ -6,6 +6,15 @@ set -e
 
 ORIG_IFS="$IFS"
 
+is_unactive_md() {
+	local number
+	number=$(echo "$1" | sed -n -e 's,/dev/md/\?,,p')
+	if [ "$number" ] && ! grep -q "^md$number :" /proc/mdstat; then
+		return 0
+	fi
+	return 1
+}
+
 part_of_sataraid () {
 	local raiddev
 	for raiddev in $(dmraid -r -c); do
@@ -52,8 +61,7 @@ if [ ! -f /var/run/parted_server.pid ]; then
 
 	IFS="$NL"
 	for partdev in $(parted_devices |
-		grep -v '^/dev/md' |
-		sed 's,^/dev/\(ide\|scsi\|[hs]d\),!/dev/\1,' |
+		sed 's,^/dev/\(ide\|scsi\|[hs]d\|md/\?[0-9]\+\),!/dev/\1,' |
 		sort |
 		sed 's,^!,,' ); do
 
@@ -65,6 +73,13 @@ if [ ! -f /var/run/parted_server.pid ]; then
 		size=$2
 		model=$3
 
+		# Skip MD devices which are not active
+		if [ -e /proc/mdstat ]; then
+			if is_unactive_md $device; then
+				continue
+			fi
+		fi
+
 		# Skip devices that are part of a dmraid device
 		if type dmraid >/dev/null 2>&1; then
 			if part_of_sataraid $device; then
diff --git a/packages/partman/partman-md/debian/changelog b/packages/partman/partman-md/debian/changelog
index e93fc37..3dfc95c 100644
--- a/packages/partman/partman-md/debian/changelog
+++ b/packages/partman/partman-md/debian/changelog
@@ -1,3 +1,15 @@
+partman-md (42) UNRELEASED; urgency=low
+
+  [ Jérémy Bobbio ]
+  * Clean up the initialization of MD devices.  Together with the changes
+    introduced in partman-base (>= 121), setup of RAID devices won't be lost
+    across partman restarts anymore.
+    (Closes: #391479, #391483, #393728, #398668)
+  * Load the necessary modules and scan RAID arrays during partman
+    initialization.  (Closes: #391474)
+
+ -- Jérémy Bobbio <lunar@debian.org>  Thu, 29 May 2008 16:02:39 +0000
+
 partman-md (41) unstable; urgency=low
 
   [ Frans Pop ]
diff --git a/packages/partman/partman-md/debian/control b/packages/partman/partman-md/debian/control
index 08c74b5..f4f96d9 100644
--- a/packages/partman/partman-md/debian/control
+++ b/packages/partman/partman-md/debian/control
@@ -9,5 +9,5 @@ Vcs-Svn: svn://svn.debian.org/d-i/trunk/packages/partman/partman-md
 Package: partman-md
 XC-Package-Type: udeb
 Architecture: all
-Depends: ${misc:Depends}, mdadm-udeb, mdcfg-utils, partman-base (>= 114)
+Depends: ${misc:Depends}, mdadm-udeb, mdcfg-utils, partman-base (>= 121)
 Description: Add to partman support for MD
diff --git a/packages/partman/partman-md/init.d/_numbers b/packages/partman/partman-md/init.d/_numbers
index 75ae141..b5155f7 100644
--- a/packages/partman/partman-md/init.d/_numbers
+++ b/packages/partman/partman-md/init.d/_numbers
@@ -1,2 +1,2 @@
-31 md-devices
+25 md-devices
 51 md
diff --git a/packages/partman/partman-md/init.d/md b/packages/partman/partman-md/init.d/md
index e5024f2..fb8ddac 100755
--- a/packages/partman/partman-md/init.d/md
+++ b/packages/partman/partman-md/init.d/md
@@ -2,16 +2,25 @@
 
 . /lib/partman/lib/base.sh
 
-# Load modules
-#depmod -a 1>/dev/null 2>&1
-#modprobe md 1>/dev/null 2>&1 || modprobe md-mod 1>/dev/null 2>&1
-#
-## Load supported personalities
-#modprobe raid1 1>/dev/null 2>&1
-#
-## Detect and start MD devices
-#/sbin/mdadm --examine --scan --config=partitions >/tmp/mdadm.conf
-#/sbin/mdadm --assemble --scan --run --config=/tmp/mdadm.conf --auto=yes
+# Check if we have RAID
+if [ ! -f /proc/mdstat ]; then
+	exit 0
+fi
+
+# Obtain the size of an MD device
+get_size () {
+	while [ -z "$(echo "$line" | grep "^md$NUMBER :")" ]; do
+		read line
+		[ $? -eq 1 ] && break  # EOF
+	done
+	read line
+	size=$(echo "$line" | sed -e 's/ blocks.*//')
+	# If the sed failed, the line didn't contain the size; just
+	# return 0 in that case.
+	if [ "$size" = "$line" ]; then
+		size=0
+	fi
+}
 
 # Mark all RAID partitions as being MD
 for dev in $DEVICES/*; do
@@ -28,6 +37,7 @@ for dev in $DEVICES/*; do
 	done
 	close_dialog
 
+	# Check if device/partitions are used for software RAID
 	for id in $partitions; do
 		md=no
 		open_dialog GET_FLAGS $id
@@ -43,38 +53,57 @@ for dev in $DEVICES/*; do
 		fi
 	done
 
-	# Next, check if the device is a part of an MD setup
-#	if [ -f device ]; then
-#		DEVICE=`sed -e "s/\/dev\///" device`
-#		grep -q "${DEVICE}" /proc/mdstat
-#		if [ $? -eq 0 ]; then
-#			open_dialog NEW_LABEL loop
-#			close_dialog
-#		fi
-#	fi
-done
+	# Check if the device is a software RAID device
+	if [ -f device ]; then
+		NUMBER=$(sed -e 's,/dev/md/\?,,' device)
+		if ! grep -q "^md$NUMBER :" /proc/mdstat; then
+			continue
+		fi
 
-# Create the raid devices
-# NOTE: /dev/md/X does not necessarily exist; /dev/mdX can exist alone
-#       (see #470374 for reference)
-#for i in $(grep md /proc/mdstat | \
-#	    sed -e 's/^\(md.*\) : active \([[:alnum:]]*\).*/\1/'); do
-#	NUMBER=$(echo $i | sed -e "s/^md//")
-#	DEVICE="$DEVICES/=dev=md$NUMBER"
-#	mkdir -p $DEVICE
-#	cd $DEVICE
-#	echo "/dev/md$NUMBER" > $DEVICE/device
-#	echo Unknown > $DEVICE/model
-#	echo "0" > $DEVICE/size
-#	open_dialog OPEN "/dev/md$NUMBER"
-#	read_line response
-#	close_dialog
-#	if [ "$response" = failed ]; then
-#		rm -rf $DEVICE
-#	fi
-#
-#	open_dialog NEW_LABEL loop
-#	close_dialog
-#done
+		# Set an appropriate value for device model
+		db_metaget partman-md/text/device description
+		echo "${RET}" > model
+
+		# fix size
+		get_size < /proc/mdstat
+		sector_size=$(grep " sectors" /proc/mdstat | sed -e 's/[^0-9]\+//g')
+		if [ -z "$sector_size" ]; then
+			sector_size=1024
+		fi
+		size=$(($size * $sector_size))
+		echo "$size" > size
+
+		# create a label
+		open_dialog NEW_LABEL loop
+		close_dialog
+		# find the free space
+		open_dialog PARTITIONS
+		free_space=''
+		while { read_line num id size type fs path name; [ "$id" ]; }; do
+			if [ "$fs" = free ]; then
+				free_space=$id
+				free_size=$size
+			fi
+		done
+		close_dialog
+		# create partition in the free space
+		if [ "$free_space" ]; then
+			open_dialog NEW_PARTITION primary ext2 $free_space full $free_size
+			read_line num id size type fs path name
+			close_dialog
+			if [ "$id" ]; then
+				open_dialog GET_FILE_SYSTEM $id
+				read_line filesystem
+				close_dialog
+				if [ "$filesystem" != none ]; then
+					open_dialog CHANGE_FILE_SYSTEM $id $filesystem
+					close_dialog
+				fi
+			fi
+		fi
+		open_dialog DISK_UNCHANGED
+		close_dialog
+	fi
+done
 
 exit 0
diff --git a/packages/partman/partman-md/init.d/md-devices b/packages/partman/partman-md/init.d/md-devices
index df9c785..8a13b02 100755
--- a/packages/partman/partman-md/init.d/md-devices
+++ b/packages/partman/partman-md/init.d/md-devices
@@ -2,94 +2,28 @@
 
 . /lib/partman/lib/base.sh
 
-# Check if we have RAID
-if [ ! -f /proc/mdstat ]; then
+# Load modules and scan arrays if it was not done before
+if [ -e /proc/mdstat ]; then
 	exit 0
 fi
 
-# Obtain the size of an MD device
-get_size () {
-	while [ -z "$(echo "$line" | grep "^md$NUMBER :")" ]; do
-		read line
-		[ $? -eq 1 ] && break  # EOF
-	done
-	read line
-	size=$(echo "$line" | sed -e 's/ blocks.*//')
-	# If the sed failed, the line didn't contain the size; just
-	# return 0 in that case.
-	if [ "$size" = "$line" ]; then
-		size=0
-	fi
-}
+# Try to load the necessary modules.
+# Supported schemes: RAID 0, RAID 1, RAID 5
+depmod -a >/dev/null 2>&1
+modprobe md-mod >/dev/null 2>&1
+modprobe raid0 >/dev/null 2>&1
+modprobe raid1 >/dev/null 2>&1
+# kernels >=2.6.18 have raid456
+modprobe raid456 >/dev/null 2>&1 || modprobe raid5 >/dev/null 2>&1
 
-# Create the raid devices
-for i in $(grep ^md /proc/mdstat | grep -v inactive | \
-	   sed -e 's/^\(md.*\) : active \([[:alnum:]]*\).*/\1/'); do
-	NUMBER="${i#md}"
-	if [ -e "/dev/md/${NUMBER}" ]; then
-		DEVICE="$DEVICES/=dev=md=${NUMBER}"
-		DEVNODE="/dev/md/${NUMBER}"
-	else
-		DEVICE="$DEVICES/=dev=md${NUMBER}"
-		DEVNODE="/dev/md${NUMBER}"
-	fi
-	mkdir -p ${DEVICE}
-	cd ${DEVICE}
-	echo "$DEVNODE" > ${DEVICE}/device
+# Try to detect MD devices, and start them
+# mdadm will fail if /dev/md does not already exist
+mkdir -p /dev/md
 
-	db_metaget partman-md/text/device description
-	echo "${RET}" > ${DEVICE}/model
+log-output -t md-init --pass-stdout \
+	mdadm --examine --scan --config=partitions >/tmp/mdadm.conf
 
-	get_size < /proc/mdstat
-	sector_size=$(grep " sectors" /proc/mdstat | sed -e 's/[^0-9]\+//g')
-	if [ -z "$sector_size" ]; then
-		sector_size=1024
-	fi
-	size=$(($size * $sector_size))
-	echo "$size" > ${DEVICE}/size
-
-	open_dialog OPENED "$DEVNODE"
-	read_line response
-	close_dialog
-	if [ "$response" = no ]; then
-		open_dialog OPEN "$DEVNODE"
-		read_line response
-		close_dialog
-		if [ "$response" = failed ]; then
-			rm -rf ${DEVICE}
-		fi
-	fi
-
-	open_dialog NEW_LABEL loop
-	close_dialog
-
-	open_dialog PARTITIONS
-	free_space=''
-	while { read_line num id size type fs path name; [ "$id" ]; }; do
-		if [ "$fs" = free ]; then
-			free_space=$id
-			free_size=$size
-		fi
-	done
-	close_dialog
-
-	if [ "$free_space" ]; then
-		open_dialog NEW_PARTITION primary ext2 $free_space full $free_size
-		read_line num id size type fs path name
-		close_dialog
-		if [ "$id" ]; then
-			open_dialog GET_FILE_SYSTEM $id
-			read_line filesystem
-			close_dialog
-			if [ "$filesystem" != none ]; then
-				open_dialog CHANGE_FILE_SYSTEM $id $filesystem
-				close_dialog
-			fi
-		fi
-	fi
-
-	open_dialog DISK_UNCHANGED
-	close_dialog
-done
+log-output -t md-init \
+	mdadm --assemble --scan --run --config=/tmp/mdadm.conf --auto=yes
 
 exit 0

Attachment: signature.asc
Description: Digital signature


Reply to: