Package: mdadm
Version: 3.2.5-1
Severity: serious
Tags: patch wheezy sid

The initramfs hook supplied by mdadm doesn't install mdmon. Also, mdmon
is not included in the .udeb for the installer.

This means that if you have an array with external metadata (ddf or,
more widely used, imsm - Intel Matrix Raid) that it will come up
readonly. This causes the installer to hang or the system not being
able to boot if root is on that array.

The attached patch does a couple of things:

- it makes sure mdadm is included in the initramfs and the udeb package
- it adds a mdadm-waitidle script that runs just before reboot/halt. For all
  arrays that are still running, it sets safe_mode_delay to a low version,
  sets sync_action to idle, and waits for the array(s) to go idle.
  This is needed so that the array is clean, otherwise it will start
  to resync at the next boot.
- it adds 2 lines of code to mdmon.c so that it symlinks its pidfile
  into /run/sendsigs.omit.d - mdmon should not be killed at shutdown,
  we still need it after the rootfs has been unmounted.

I have added support for installation on Intel Matrix raid (imsm)
arrays using mdadm to d-i, and I'll be sending patches to the debian-boot
list soon. Please consider this patch for inclusion in wheezy.

Mike.
Binary files orig/mdadm-3.2.5/debian/.rules.swp and mdadm-3.2.5/debian/.rules.swp differ
diff -ruN orig/mdadm-3.2.5/debian/changelog mdadm-3.2.5/debian/changelog
--- orig/mdadm-3.2.5/debian/changelog	2012-05-25 20:05:23.000000000 +0200
+++ mdadm-3.2.5/debian/changelog	2012-08-06 23:30:04.171100029 +0200
@@ -1,3 +1,14 @@
+mdadm (3.2.5-1+1) unstable; urgency=low
+
+  * also install mdmon in udeb and initramfs, so imsm arrays work
+  * mdmon now automatically makes a symlink in /run/sendsigs.omit.d to its pidfile
+  * create /run/sendsigs.omit.d/ in local-top script
+  * add script mdadm-waitidle that runs just before reboot/halt. For all
+    arrays that are still running, it sets safe_mode_delay to a low version,
+    sets sync_action to idle, and waits for the array(s) to go idle.
+
+ -- Miquel van Smoorenburg <miqu...@debian.org>  Mon, 06 Aug 2012 23:29:32 +0200
+
 mdadm (3.2.5-1) unstable; urgency=low
 
   [ Michael Tokarev ]
diff -ruN orig/mdadm-3.2.5/debian/initramfs/hook mdadm-3.2.5/debian/initramfs/hook
--- orig/mdadm-3.2.5/debian/initramfs/hook	2012-05-25 19:31:37.000000000 +0200
+++ mdadm-3.2.5/debian/initramfs/hook	2012-08-02 00:32:50.925671675 +0200
@@ -49,6 +49,7 @@
 }
 
 MDADM=/sbin/mdadm
+MDMON=/sbin/mdmon
 [ -x "$MDADM" ] || exit 0
 
 [ -r /usr/share/initramfs-tools/hook-functions ] || exit 0
@@ -56,6 +57,7 @@
 
 # copy the binary as early as possible
 copy_exec $MDADM /sbin
+copy_exec $MDMON /sbin
 
 # copy all modules into the initramfs, just for safety.
 # we copy raid456 / raid5+raid6 because the hook script just won't do
diff -ruN orig/mdadm-3.2.5/debian/initramfs/script.local-top mdadm-3.2.5/debian/initramfs/script.local-top
--- orig/mdadm-3.2.5/debian/initramfs/script.local-top	2012-05-10 22:22:16.000000000 +0200
+++ mdadm-3.2.5/debian/initramfs/script.local-top	2012-08-06 17:32:30.162720885 +0200
@@ -53,6 +53,9 @@
 # handle /dev/md/X nodes
 mkdir -p /dev/md
 
+# mdmon wants this directory to exist
+mkdir -p /run/sendsigs.omit.d
+
 CONFIG=/etc/mdadm/mdadm.conf
 # in case the hook failed to install a configuration file, this is our last
 # attempt... the "emergency procedure"... <drumroll>
diff -ruN orig/mdadm-3.2.5/debian/mdadm-waitidle mdadm-3.2.5/debian/mdadm-waitidle
--- orig/mdadm-3.2.5/debian/mdadm-waitidle	1970-01-01 01:00:00.000000000 +0100
+++ mdadm-3.2.5/debian/mdadm-waitidle	2012-08-06 23:49:22.138176669 +0200
@@ -0,0 +1,76 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides:          mdadm-waitidle
+# Required-Start:
+# Required-Stop:
+# Should-Stop:       halt reboot kexec
+# X-Stop-After:      umountroot
+# Default-Start:
+# Default-Stop:      0 6
+# Short-Description: Wait for MD arrays to become idle
+# Description:       This script waits until all MD arrays are
+#                    in idle and synced state before halt/reboot.
+### END INIT INFO
+#
+set -eu
+
+. /lib/lsb/init-functions
+
+case "${1:-}" in
+  start)
+    ;;
+  stop)
+    cd /sys/block
+    for md in md*
+    do
+      if [ -d "$md/md/" ]
+      then
+        if [ -w $md/md/safe_mode_delay ]; then
+          echo 0.05 > $md/md/safe_mode_delay ||:
+        fi
+        if [ -w $md/md/sync_action ]; then
+          echo idle > $md/md/sync_action ||:
+        fi
+        array_found=1
+      fi
+    done
+    [ -z "$array_found" ] && exit 0
+
+    log_action_begin_msg "Waiting for MD arrays to become idle"
+    sync
+    start=`date +%s`
+    secs=0
+    while [ $secs -lt 10 ]
+    do
+      secs=$((`date +%s` - $start))
+      active=
+      for md in md*
+      do
+        # We wait for normal writes, but not too long for resyncs/rebuilds.
+        state="`cat $md/md/array_state 2>/dev/null || echo unknown`"
+        sync="`cat $md/md/sync_action 2>/dev/null || echo idle`"
+        if [ "$state" = active ] && ([ "$sync" = idle ] || [ $secs -lt 3 ])
+        then
+          active=1
+        fi
+      done
+      [ -n "$active" ] || break
+      sleep 0.2
+    done
+
+    if [ -n "$active" ]
+    then
+      log_action_end_msg 1
+      sleep 1
+    else
+      log_action_end_msg 0
+    fi
+    ;;
+
+  *)
+    echo "Usage: ${0:-} {stop}" >&2
+    exit 1;;
+
+esac
+
+exit 0
diff -ruN orig/mdadm-3.2.5/debian/patches/debian-sendsigs-omit.patch mdadm-3.2.5/debian/patches/debian-sendsigs-omit.patch
--- orig/mdadm-3.2.5/debian/patches/debian-sendsigs-omit.patch	1970-01-01 01:00:00.000000000 +0100
+++ mdadm-3.2.5/debian/patches/debian-sendsigs-omit.patch	2012-08-06 16:59:45.205515235 +0200
@@ -0,0 +1,24 @@
+Index: mdadm-3.2.5/mdmon.c
+===================================================================
+--- mdadm-3.2.5.orig/mdmon.c	2012-05-18 07:10:03.000000000 +0000
++++ mdadm-3.2.5/mdmon.c	2012-08-06 14:59:28.881239759 +0000
+@@ -143,6 +143,7 @@
+ static int make_pidfile(char *devname)
+ {
+ 	char path[100];
++	char sendsigs_omit_path[100];
+ 	char pid[10];
+ 	int fd;
+ 	int n;
+@@ -160,6 +161,11 @@
+ 	close(fd);
+ 	if (n < 0)
+ 		return -errno;
++
++	/* debian: automatically symlink to sendsigs.omit.d/. ignore result. */
++	sprintf(sendsigs_omit_path, "/run/sendsigs.omit.d/%s.pid", devname);
++	symlink(path, sendsigs_omit_path);
++
+ 	return 0;
+ }
+ 
diff -ruN orig/mdadm-3.2.5/debian/patches/series mdadm-3.2.5/debian/patches/series
--- orig/mdadm-3.2.5/debian/patches/series	2012-05-25 18:49:06.000000000 +0200
+++ mdadm-3.2.5/debian/patches/series	2012-08-13 11:47:29.765991155 +0200
@@ -2,3 +2,4 @@
 debian-disable-udev-incr-assembly.diff
 debian-no-Werror.diff
 sha1-includes.diff
+debian-sendsigs-omit.patch
diff -ruN orig/mdadm-3.2.5/debian/rules mdadm-3.2.5/debian/rules
--- orig/mdadm-3.2.5/debian/rules	2012-05-25 19:31:37.000000000 +0200
+++ mdadm-3.2.5/debian/rules	2012-08-06 23:26:11.195263083 +0200
@@ -35,7 +35,8 @@
 	dh_testdir
 	$(MAKE) $(FLAGS) all
 	mv mdadm mdadm.udeb
-.PHONY: mdadm.udeb
+	mv mdmon mdmon.udeb
+.PHONY: mdadm.udeb mdmon.udeb
 
 mdadm: FLAGS = CXFLAGS="$(CXFLAGS)" CONFFILE=/etc/mdadm/mdadm.conf CONFFILE2=/etc/mdadm.conf
 mdadm: configure
@@ -50,7 +51,7 @@
 	rm -f $(INTERPOLATED_FILES)
 	rm -f build-stamp
 	[ ! -f Makefile ] || $(MAKE) clean
-	rm -f mdadm.udeb mdadm debian/mdadm-startall.8
+	rm -f mdadm.udeb mdmon.udeb mdadm debian/mdadm-startall.8
 	dh_clean
 	debconf-updatepo
 
@@ -80,6 +81,7 @@
 	install -m0755 debian/mdadm-startall $(DESTDIR)/sbin
 
 	install -m0755 mdadm.udeb $(DESTDIR_UDEB)/sbin/mdadm
+	install -m0755 mdmon.udeb $(DESTDIR_UDEB)/sbin/mdmon
 	install -m0644 udev-md-raid.rules $(DESTDIR_UDEB)/lib/udev/rules.d/64-md-raid.rules
 
 binary-indep: build install
@@ -92,6 +94,7 @@
 	dh_installdocs
 	dh_installexamples debian/mdadd.sh
 	dh_installinit --init-script=mdadm-raid --no-start -- start 25 S . start 60 0 6 .
+	dh_installinit --init-script=mdadm-waitidle --no-start -- stop 98 0 6 .
 	dh_installinit -- defaults 25
 	dh_installman
 	dh_installcron

Reply via email to