On 13.08.2012 14:10, Miquel van Smoorenburg wrote:
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 time with patch attached, oops.]

Here is a revised patch. I proposed the patch to mdmon.c (to symlink the pidfile into /run/sendsigs.omit.d/) on the linux-raid mailinglist, and Neil Brown remarked "why not do that in an init script just before sendsigs runs". Which is ofcourse a good idea, no changes to mdmon.c required, just 3 lines added to /etc/init.d/mdadm.

I was careful to ensure that if you do not have a raid device with external metadata, this patch does exactly nothing. And on systems with a raid device with external metadata it will enhance data integrity due to /etc/init.d/mdadm-waitidle.

Thanks,

Mike.

Binary files x/mdadm-3.2.5/debian/.rules.swp and mdadm-3.2.5/debian/.rules.swp 
differ
diff -ruN x/mdadm-3.2.5/debian/changelog mdadm-3.2.5/debian/changelog
--- x/mdadm-3.2.5/debian/changelog      2012-05-25 18:05:23.000000000 +0000
+++ mdadm-3.2.5/debian/changelog        2012-09-03 17:54:14.582811602 +0000
@@ -1,3 +1,14 @@
+mdadm (3.2.5-1+1) unstable; urgency=low
+
+  * also install mdmon in udeb and initramfs, so imsm arrays work
+  * link pidfiles of mdmons into /run/sendsigs.omit.d in the stop section
+    of /etc/init.d/mdadm, and make sure that script runs before sendsigs.
+  * 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 x/mdadm-3.2.5/debian/initramfs/hook mdadm-3.2.5/debian/initramfs/hook
--- x/mdadm-3.2.5/debian/initramfs/hook 2012-05-25 17:31:37.000000000 +0000
+++ mdadm-3.2.5/debian/initramfs/hook   2012-08-01 22:32:50.925671675 +0000
@@ -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 x/mdadm-3.2.5/debian/mdadm-waitidle mdadm-3.2.5/debian/mdadm-waitidle
--- x/mdadm-3.2.5/debian/mdadm-waitidle 1970-01-01 00:00:00.000000000 +0000
+++ mdadm-3.2.5/debian/mdadm-waitidle   2012-08-06 21:49:22.138176669 +0000
@@ -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 x/mdadm-3.2.5/debian/mdadm.init mdadm-3.2.5/debian/mdadm.init
--- x/mdadm-3.2.5/debian/mdadm.init     2012-05-10 20:22:16.000000000 +0000
+++ mdadm-3.2.5/debian/mdadm.init       2012-09-03 17:52:37.545176785 +0000
@@ -9,7 +9,7 @@
 ### BEGIN INIT INFO
 # Provides:          mdadm
 # Required-Start:    $local_fs $syslog mdadm-raid
-# Required-Stop:     $local_fs $syslog mdadm-raid
+# Required-Stop:     $local_fs $syslog sendsigs mdadm-raid
 # Default-Start:     2 3 4 5
 # Default-Stop:      0 1 6
 # Short-Description: MD monitoring daemon
@@ -64,6 +64,10 @@
       log_end_msg $?
       set -e
     fi
+    for file in /run/mdadm/md*.pid
+    do
+      [ ! -f "$file" ] || ln -sf $file /run/sendsigs.omit.d/mdmon-${file##*/}
+    done
     ;;
   status)
     status_of_proc -p $PIDFILE "$MDADM" "mdadm" && exit 0 || exit $?
diff -ruN x/mdadm-3.2.5/debian/rules mdadm-3.2.5/debian/rules
--- x/mdadm-3.2.5/debian/rules  2012-05-25 17:31:37.000000000 +0000
+++ mdadm-3.2.5/debian/rules    2012-08-06 21:26:11.195263083 +0000
@@ -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