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

Bug#691710: unblock: mdadm/3.2.5-4 (pre-upload)



Package: release.debian.org
Severity: normal
User: release.debian.org@packages.debian.org
Usertags: unblock

This is a "pre-upload unblock request" for mdadm/3.2.5-4.

Recently, upstream released a new version of mdadm, v3.2.6,
which contains only bugfixes or documentation improvements.

I'm cherry-picking only the most important changes from this
version.  These changes fixes a number of important bugs, each
of which is not of RC severity, but important enough to be
included into wheezy in my point of view.

Each of the bug has relatively low impact or probability, or
can be seen in only very specific configurations, but once you
hit it, it might be difficult to recover the data which was
on the raid array in question.  This is why I consider these
to be good candidates for wheezy.

This "unblock request" consists of two parts.  First, the "main"
part, which talks about several bugfixes:

Here are the list of changelog entries of this nature:

  * Fix 'enough' function for RAID10, to prevent starting of a RAID10
    array which does not have required minimum of component devices.
    (Closes: #691668).

  * fix segfaults in Detail() - mdadm --detail may segfault if a drive
    has been removed from the array (Closes: #691670)

  * super0: do not override uuid with homehost.  The bug prevented
    re-creating an array with v0.90 superblock with the specified uuid
    when homehost is also specified.  (Closes: #686703)

Each of the above 3 patches fixes specific bugs relevant to data stability,
so to say.

  * several fixes for mdmon argument processing (Closes: #691671):
    - allow --takeover when original was started with --offroot
    - fix arg parsing.
    - fix arg processing for -a

The last series - mdmon argument processing fixes - is not directly
relevant for version of the package currently in wheezy, since mdmon
utility there is not used right now.  For this reason, the fixes above
are of zero risk for configurations which are directly supported by
mdadm debian package infrastructure.  However, mdmon is required to
support raid arrays with "external" metadata, which are all the
"fakeraid" arrays (ahci and other in-chipset implementations), found
in almost all modern motherboards or PCs.  These tiny bugfixes allows
usage of such arrays in saner way.  More about mdmon is below.

While at it, I'm also fixing 2 minor issues with packaging which were
slipped in - one debian/changelog typo and an inverse logic in
`/etc/init.d/mdadm status' handling (#686100).

Debdiff between current version in wheezy (3.2.5-3) and the proposed
release attached in file named mdadm_3.2.5-4.debdiff.

Whole packaging is done in git, and each change is visible in the
git repository on git.debian.org, maybe this one is easier to review:
http://anonscm.debian.org/gitweb/?p=pkg-mdadm/mdadm.git;a=shortlog;h=master


And second, there's a second part, which talks especially about mdmon
and usage of arrays with external metadata.

There's one bugreport of RC severity, filed by Miquel van Smoorenburg,
who requested a new feature: adding support for raid arrays with
"external" metadata.  It is #684708.

First, a little explanation.

mdadm utility is used to manage raid arrays.  For native linux arrays,
only 2 components are necessary: mdadm utility to start/stop/etc, and
the kernel to handle all the rest.  However, for arrays with non-native
formats/metadata, metadata updates are handled by external program,
kernel sends events affecting metadata to userspace and expects an
external program to udpate the metadata using whatever format it is in.
This external program is mdmon.  Kernel refuses to make the device
read-write unless such external prgram is running for the array in
question.

When mdadm is asked to assemble such a non-native array, it tries to
execute mdmon automatically.  Once running, it will handle metadata
updates from kernel, and the array becomes fully operational.  No
additional actions are necessary, mdadm does it all internally.

If such non-native arrays are assembled from initramfs, mdmon should
be in the initramfs too, because else, say, ext4 journal replay
(which is done even on a read-only mount) can not be completed,
so an uncleanly umounted ext4 can't be mounted.  And we need to
just provide mdmon binary in initramfs for the whole thing to
start working.

But we also need 3 extra steps _after_ such an array is started:
first, we need to restart mdmon from real root once the system is
booted, in order to release initramfs.  Second, we need to ensure
that these mdmon processes will not be killed by sendsigs during
shutdown, because mdmon might still be needed after sendsigs is
done - when umounting filesystems etc.  And third, we need to
wait for such arrays to settle down (to sync metadata etc) at
the very end of the shutdown process (mdmon need to finish its
task there), or else at next boot the array will not be clean.

Miquel provided a patch implementing all this, and I reworked it
a bit.

In the second attached file, named mdadm_3.2.5-4+mdmon.debdiff,
there's incremental debdiff between version described above,
and the one which implements this mdmon functionality.

And one more thing -- the udeb now includes mdmon binary -- for
exactly the same reason, mere presence of this binary is enough
to start such non-native raid array from within the installer.
There's no other changes which affects udeb/d-i in this release.


Both set of changes is included into mdadm_3.2.5-4+mdmon which
I uploaded to experimental today.

I don't know which changes the release team will decide to be
okay or not okay for wheezy, -- so I'm asking first, before
uploading it to unstable.

I'll upload will be okay for the release team (and for the d-i team
as well!) to unstable, if at all.

Thank you for your time!

/mjt
diff -Nru mdadm-3.2.5/debian/changelog mdadm-3.2.5/debian/changelog
--- mdadm-3.2.5/debian/changelog	2012-08-25 23:29:05.000000000 +0400
+++ mdadm-3.2.5/debian/changelog	2012-10-28 21:12:37.000000000 +0400
@@ -1,3 +1,26 @@
+mdadm (3.2.5-4) UNRELEASED; urgency=low
+
+  * fix `/etc/init.d/mdadm-raid status' inverse logic (Closes: #686100)
+  * /etc/init.d/mdadm: change RUNDIR to /run instead of /var/run.
+    Mdadm itself uses /run internally, we properly depend on initscripts
+    version which creates /run, and the initscript itself is started
+    after local_fs is processed, so this is merely a no-op, but let's
+    do it for consistency.
+  * Fix 'enough' function for RAID10, to prevent starting of a RAID10
+    array which does not have required minimum of component devices.
+    (Closes: #691668).
+  * fix segfaults in Detail() - mdadm --detail may segfault if a drive
+    has been removed from the array (Closes: #691670)
+  * super0: do not override uuid with homehost.  The bug prevented
+    re-creating an array with v0.90 superblock with the specified uuid
+    when homehost is also specified.  (Closes: #686703)
+  * several fixes for mdmon argument processing (Closes: #691671):
+    - allow --takeover when original was started with --offroot
+    - fix arg parsing.
+    - fix arg processing for -a
+
+ -- Michael Tokarev <mjt@tls.msk.ru>  Sat, 20 Oct 2012 19:20:12 +0400
+
 mdadm (3.2.5-3) unstable; urgency=low
 
   * revert "Drop unused debconf templates" change -- the templates
@@ -21,7 +44,7 @@
   * some cleanups for checkarray:
    - change --help printing and shorten/simplify the text
    - make --quiet cumulative and stop documenting --real-quiet
-   - do not prduce help in case of incorrect usage, and exit with 1
+   - do not produce help in case of incorrect usage, and exit with 1
   * fixes for initramfs integration (Closes: #644389, #678262, #685161):
    - check INITRDSTART=none early
    - do not explicitly load raid level modules (modprobe/kmod does this)
diff -Nru mdadm-3.2.5/debian/mdadm.init mdadm-3.2.5/debian/mdadm.init
--- mdadm-3.2.5/debian/mdadm.init	2012-06-22 11:16:25.000000000 +0400
+++ mdadm-3.2.5/debian/mdadm.init	2012-10-28 21:12:37.000000000 +0400
@@ -22,7 +22,7 @@
 set -eu
 
 MDADM=/sbin/mdadm
-RUNDIR=/var/run/mdadm
+RUNDIR=/run/mdadm
 PIDFILE=$RUNDIR/monitor.pid
 DEBIANCONFIG=/etc/default/mdadm
 
diff -Nru mdadm-3.2.5/debian/mdadm-raid mdadm-3.2.5/debian/mdadm-raid
--- mdadm-3.2.5/debian/mdadm-raid	2012-06-22 11:57:47.000000000 +0400
+++ mdadm-3.2.5/debian/mdadm-raid	2012-10-20 19:20:03.000000000 +0400
@@ -249,7 +249,7 @@
     ;;
 
   status)
-    if [ -f /proc/mdstat ]; then
+    if [ ! -f /proc/mdstat ]; then
       log_problem "no MD subsystem loaded"
       exit 1
     else
diff -Nru mdadm-3.2.5/debian/patches/fix-enough-function-for-RAID10.patch mdadm-3.2.5/debian/patches/fix-enough-function-for-RAID10.patch
--- mdadm-3.2.5/debian/patches/fix-enough-function-for-RAID10.patch	1970-01-01 03:00:00.000000000 +0300
+++ mdadm-3.2.5/debian/patches/fix-enough-function-for-RAID10.patch	2012-10-28 20:34:26.000000000 +0400
@@ -0,0 +1,46 @@
+From 2117ad1dd1b79cf6d02a065d9e38076aa9f4788d Mon Sep 17 00:00:00 2001
+From: NeilBrown <neilb@suse.de>
+Date: Thu, 27 Sep 2012 16:58:44 +1000
+Subject: Fix 'enough' function for RAID10.
+Bug-Debian: http://bugs.debian.org/691668
+Comment: from stable/bugfix 3.2.6 upstream version
+
+The 'enough' function is written to work with 'near' arrays only
+in that is implicitly assumes that the offset from one 'group' of
+devices to the next is the same as the number of copies.
+In reality it is the number of 'near' copies.
+
+So change it to make this number explicit.
+
+Reported-by: Jakub Husák <jakub@gooseman.cz>
+Signed-off-by: NeilBrown <neilb@suse.de>
+---
+ util.c |    7 ++++---
+ 1 file changed, 4 insertions(+), 3 deletions(-)
+
+diff --git a/util.c b/util.c
+index 83f3187..eef0d6f 100644
+--- a/util.c
++++ b/util.c
+@@ -332,14 +332,15 @@ int enough(int level, int raid_disks, int layout, int clean, char *avail)
+ 			/* there must be one of the 'copies' form 'first' */
+ 			int n = copies;
+ 			int cnt=0;
++			int this = first;
+ 			while (n--) {
+-				if (avail[first])
++				if (avail[this])
+ 					cnt++;
+-				first = (first+1) % raid_disks;
++				this = (this+1) % raid_disks;
+ 			}
+ 			if (cnt == 0)
+ 				return 0;
+-
++			first = (first+(layout&255)) % raid_disks;
+ 		} while (first != 0);
+ 		return 1;
+ 
+-- 
+1.7.10.4
+
diff -Nru mdadm-3.2.5/debian/patches/fix-segfaults-in-detail.patch mdadm-3.2.5/debian/patches/fix-segfaults-in-detail.patch
--- mdadm-3.2.5/debian/patches/fix-segfaults-in-detail.patch	1970-01-01 03:00:00.000000000 +0300
+++ mdadm-3.2.5/debian/patches/fix-segfaults-in-detail.patch	2012-10-28 20:35:48.000000000 +0400
@@ -0,0 +1,42 @@
+From aec89f63e98322a141d146a84c67b0cc2d1cd1a4 Mon Sep 17 00:00:00 2001
+From: Lukasz Dorau <lukasz.dorau@intel.com>
+Date: Thu, 27 Sep 2012 16:58:44 +1000
+Subject: fix segfaults in Detail()
+Bug-Debian: http://bugs.debian.org/691670
+Comment: from stable/bugfix upstream 3.2.6 version
+
+If disk has been removed, 'st' and 'info' can be NULL. It causes segfault.
+'st' and 'info' should be checked against being NULL before being used.
+
+Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
+Signed-off-by: NeilBrown <neilb@suse.de>
+---
+ Detail.c |    5 +++--
+ 1 file changed, 3 insertions(+), 2 deletions(-)
+
+diff --git a/Detail.c b/Detail.c
+index 85e2b89..67ddc80 100644
+--- a/Detail.c
++++ b/Detail.c
+@@ -424,7 +424,7 @@ int Detail(char *dev, int brief, int export, int test, char *homehost, char *pre
+ 		}
+ 		free_mdstat(ms);
+ 
+-		if (st->sb && info->reshape_active) {
++		if ((st && st->sb) && (info && info->reshape_active)) {
+ #if 0
+ This is pretty boring
+ 			printf("  Reshape pos'n : %llu%s\n", (unsigned long long) info->reshape_progress<<9,
+@@ -575,7 +575,8 @@ This is pretty boring
+ 	if (spares && brief && array.raid_disks) printf(" spares=%d", spares);
+ 	if (brief && st && st->sb)
+ 		st->ss->brief_detail_super(st);
+-	st->ss->free_super(st);
++	if (st)
++		st->ss->free_super(st);
+ 
+ 	if (brief > 1 && devices) printf("\n   devices=%s", devices);
+ 	if (brief) printf("\n");
+-- 
+1.7.10.4
+
diff -Nru mdadm-3.2.5/debian/patches/mdmon-allow-takeover-when-original-was-started-with-.patch mdadm-3.2.5/debian/patches/mdmon-allow-takeover-when-original-was-started-with-.patch
--- mdadm-3.2.5/debian/patches/mdmon-allow-takeover-when-original-was-started-with-.patch	1970-01-01 03:00:00.000000000 +0300
+++ mdadm-3.2.5/debian/patches/mdmon-allow-takeover-when-original-was-started-with-.patch	2012-10-28 20:39:49.000000000 +0400
@@ -0,0 +1,37 @@
+From c4e96a305fbca4f83ae9f3a81482481524380905 Mon Sep 17 00:00:00 2001
+From: NeilBrown <neilb@suse.de>
+Date: Mon, 20 Aug 2012 10:37:21 +1000
+Subject: mdmon: allow --takeover when original was started with --offroot
+Bug-Debian: http://bugs.debian.org/691671
+Comment: from stable/bugfix upstream 3.2.6 version
+Comment: one of the 3 patches fixing mentioned issues
+
+As --offroot causes ARGV[0] to be changed, we need to be more
+lenient when checking that the mdmon we are about to kill really
+is mdmon.  i.e. allow name to be "@dmon" instead.
+
+Signed-off-by: NeilBrown <neilb@suse.de>
+---
+ mdmon.c |    6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/mdmon.c b/mdmon.c
+index 2d0503d..54e1238 100644
+--- a/mdmon.c
++++ b/mdmon.c
+@@ -184,7 +184,11 @@ static void try_kill_monitor(pid_t pid, char *devname, int sock)
+ 	buf[sizeof(buf)-1] = 0;
+ 	close(fd);
+ 
+-	if (n < 0 || !strstr(buf, "mdmon"))
++	/* Note that if started with --offroot, the name
++	 * might be "@dmon"
++	 */
++	if (n < 0 || !(strstr(buf, "mdmon") ||
++		       strstr(buf, "@dmon")))
+ 		return;
+ 
+ 	kill(pid, SIGTERM);
+-- 
+1.7.10.4
+
diff -Nru mdadm-3.2.5/debian/patches/mdmon-fix-arg-parsing.patch mdadm-3.2.5/debian/patches/mdmon-fix-arg-parsing.patch
--- mdadm-3.2.5/debian/patches/mdmon-fix-arg-parsing.patch	1970-01-01 03:00:00.000000000 +0300
+++ mdadm-3.2.5/debian/patches/mdmon-fix-arg-parsing.patch	2012-10-28 20:39:49.000000000 +0400
@@ -0,0 +1,32 @@
+From 68ad53b301b6fc722fee6d32a5267c1a4506452d Mon Sep 17 00:00:00 2001
+From: NeilBrown <neilb@suse.de>
+Date: Mon, 9 Jul 2012 16:50:22 +1000
+Subject: mdmon: fix arg parsing.
+Bug-Debian: http://bugs.debian.org/691671
+Comment: from stable/bugfix upstream 3.2.6 version
+Comment: one of the 3 patches fixing mentioned issues
+
+-t aka --takeover should not be setting container_name.
+It sets it to NULL which causes failure when you try
+  mdmon --all --takeover
+
+Signed-off-by: NeilBrown <neilb@suse.de>
+---
+ mdmon.c |    1 -
+ 1 file changed, 1 deletion(-)
+
+diff --git a/mdmon.c b/mdmon.c
+index 2093476..dee02a9 100644
+--- a/mdmon.c
++++ b/mdmon.c
+@@ -306,7 +306,6 @@ int main(int argc, char *argv[])
+ 			all = 1;
+ 			break;
+ 		case 't':
+-			container_name = optarg;
+ 			takeover = 1;
+ 			break;
+ 		case OffRootOpt:
+-- 
+1.7.10.4
+
diff -Nru mdadm-3.2.5/debian/patches/mdmon-fix-arg-processing-for-a.patch mdadm-3.2.5/debian/patches/mdmon-fix-arg-processing-for-a.patch
--- mdadm-3.2.5/debian/patches/mdmon-fix-arg-processing-for-a.patch	1970-01-01 03:00:00.000000000 +0300
+++ mdadm-3.2.5/debian/patches/mdmon-fix-arg-processing-for-a.patch	2012-10-28 20:39:49.000000000 +0400
@@ -0,0 +1,31 @@
+From 23084aaa76d9fc3121ff2ab38c04ee9893793e00 Mon Sep 17 00:00:00 2001
+From: NeilBrown <neilb@suse.de>
+Date: Mon, 20 Aug 2012 10:33:50 +1000
+Subject: mdmon: fix arg processing for -a
+Bug-Debian: http://bugs.debian.org/691671
+Comment: from stable/bugfix upstream 3.2.6 version
+Comment: one of the 3 patches fixing mentioned issues
+
+'-a' was not being recognised as an abbreviation for '--all'.
+
+Signed-off-by: NeilBrown <neilb@suse.de>
+---
+ mdmon.c |    2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/mdmon.c b/mdmon.c
+index dee02a9..2d0503d 100644
+--- a/mdmon.c
++++ b/mdmon.c
+@@ -299,7 +299,7 @@ int main(int argc, char *argv[])
+ 		{NULL, 0, NULL, 0}
+ 	};
+ 
+-	while ((opt = getopt_long(argc, argv, "th", options, NULL)) != -1) {
++	while ((opt = getopt_long(argc, argv, "tha", options, NULL)) != -1) {
+ 		switch (opt) {
+ 		case 'a':
+ 			container_name = argv[optind-1];
+-- 
+1.7.10.4
+
diff -Nru mdadm-3.2.5/debian/patches/series mdadm-3.2.5/debian/patches/series
--- mdadm-3.2.5/debian/patches/series	2012-06-22 12:04:59.000000000 +0400
+++ mdadm-3.2.5/debian/patches/series	2012-10-28 20:58:33.000000000 +0400
@@ -3,3 +3,9 @@
 debian-no-Werror.diff
 sha1-includes.diff
 spelling-and-manpages.patch
+fix-enough-function-for-RAID10.patch
+fix-segfaults-in-detail.patch
+super0-do-not-override-uuid-with-homehost.patch
+mdmon-allow-takeover-when-original-was-started-with-.patch
+mdmon-fix-arg-parsing.patch
+mdmon-fix-arg-processing-for-a.patch
diff -Nru mdadm-3.2.5/debian/patches/super0-do-not-override-uuid-with-homehost.patch mdadm-3.2.5/debian/patches/super0-do-not-override-uuid-with-homehost.patch
--- mdadm-3.2.5/debian/patches/super0-do-not-override-uuid-with-homehost.patch	1970-01-01 03:00:00.000000000 +0300
+++ mdadm-3.2.5/debian/patches/super0-do-not-override-uuid-with-homehost.patch	2012-10-28 20:41:31.000000000 +0400
@@ -0,0 +1,34 @@
+From 3713633a30349773a83bd8257cdd64b86ce32dbd Mon Sep 17 00:00:00 2001
+From: Michael Tokarev <mjt@tls.msk.ru>
+Date: Sat, 20 Oct 2012 15:40:02 +0400
+Subject: super0: do not override uuid with homehost
+Bug-Debian: http://bugs.debian.org/686703
+Comment: from stable/bugfix upstream 3.2.6 version
+
+When --uuid is specified in the command line, even for v0.90
+superblock we override last portion of uuid with data from
+--homehost, which is wrong (and disagrees with the manpage).
+Only use homehost in super0 if no uuid is specified.
+
+Signed-off-By: Michael Tokarev <mjt@tls.msk.ru>
+Signed-off-by: NeilBrown <neilb@suse.de>
+---
+ super0.c |    2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/super0.c b/super0.c
+index 1375799..ca4c082 100644
+--- a/super0.c
++++ b/super0.c
+@@ -657,7 +657,7 @@ static int init_super0(struct supertype *st, mdu_array_info_t *info,
+ 		if (rfd >= 0)
+ 			close(rfd);
+ 	}
+-	if (homehost) {
++	if (homehost && !uuid) {
+ 		char buf[20];
+ 		char *hash = sha1_buffer(homehost,
+ 					 strlen(homehost),
+-- 
+1.7.10.4
+
diff -Nru mdadm-3.2.5/debian/changelog mdadm-3.2.5/debian/changelog
--- mdadm-3.2.5/debian/changelog	2012-10-28 21:12:37.000000000 +0400
+++ mdadm-3.2.5/debian/changelog	2012-10-28 22:28:32.000000000 +0400
@@ -18,6 +18,21 @@
     - allow --takeover when original was started with --offroot
     - fix arg parsing.
     - fix arg processing for -a
+  * Changes based on a patch by Miquel van Smoorenburg (Closes: #684708):
+    - install mdmon in udeb and initramfs, so imsm arrays can work.
+      mdadm runs mdmon automatically when needed (currently for imsm
+      arrays), and mdmon is required to make such arrays read-write
+      (they're read-only by default) so merely presence of mdmon is
+      enough to be able to use imsm arrays.
+    - /etc/init.d/mdadm start: if a mdmon pidfile is found in /run/mdadm,
+      restart mdmon (--takeover --all)
+    - /etc/init.d/mdadm stop: link pidfiles of mdmon processes into
+      /run/sendsigs.omit.d, and make sure that happens before sendsigs runs.
+    - stop mdadm before sendsigs, so that the above code works
+    - add script mdadm-waitidle that runs just before reboot/halt.
+      For each array that is still running, it sets sync_action to idle,
+      and uses mdadm --wait-clean to wait for all arrays to go idle
+      (it has a short timeout).
 
  -- Michael Tokarev <mjt@tls.msk.ru>  Sat, 20 Oct 2012 19:20:12 +0400
 
diff -Nru mdadm-3.2.5/debian/initramfs/hook mdadm-3.2.5/debian/initramfs/hook
--- mdadm-3.2.5/debian/initramfs/hook	2012-10-28 21:12:37.000000000 +0400
+++ mdadm-3.2.5/debian/initramfs/hook	2012-10-28 22:28:12.000000000 +0400
@@ -50,6 +50,7 @@
 }
 
 MDADM=/sbin/mdadm
+MDMON=/sbin/mdmon
 [ -x "$MDADM" ] || exit 0
 
 [ -r /usr/share/initramfs-tools/hook-functions ] || exit 0
@@ -57,6 +58,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 -Nru mdadm-3.2.5/debian/mdadm.init mdadm-3.2.5/debian/mdadm.init
--- mdadm-3.2.5/debian/mdadm.init	2012-10-28 21:12:37.000000000 +0400
+++ mdadm-3.2.5/debian/mdadm.init	2012-10-28 22:28:12.000000000 +0400
@@ -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
@@ -22,6 +22,7 @@
 set -eu
 
 MDADM=/sbin/mdadm
+MDMON=/sbin/mdmon
 RUNDIR=/run/mdadm
 PIDFILE=$RUNDIR/monitor.pid
 DEBIANCONFIG=/etc/default/mdadm
@@ -54,6 +55,13 @@
       log_end_msg $?
       set -e
     fi
+    if [ "$(echo $RUNDIR/md[0-9]*.pid)" != "$RUNDIR/md[0-9]*.pid" ]; then
+      log_daemon_msg "Restarting MD external metadata monitor" "mdmon --takeover --all"
+      set +e
+      $MDMON --takeover --all
+      log_end_msg $?
+      set -e
+    fi
     ;;
   stop)
     if [ -f $PIDFILE ] ; then
@@ -64,6 +72,10 @@
       log_end_msg $?
       set -e
     fi
+    for file in $RUNDIR/md[0-9]*.pid ; do
+      [ ! -f "$file" ] && continue
+      ln -sf $file /run/sendsigs.omit.d/mdmon-${file##*/}
+    done
     ;;
   status)
     status_of_proc -p $PIDFILE "$MDADM" "mdadm" && exit 0 || exit $?
diff -Nru mdadm-3.2.5/debian/mdadm-waitidle mdadm-3.2.5/debian/mdadm-waitidle
--- mdadm-3.2.5/debian/mdadm-waitidle	1970-01-01 03:00:00.000000000 +0300
+++ mdadm-3.2.5/debian/mdadm-waitidle	2012-10-28 22:28:12.000000000 +0400
@@ -0,0 +1,54 @@
+#!/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:       Waits until all MD arrays are in idle and synced state
+#                    before halt/reboot.
+### END INIT INFO
+#
+set -eu
+
+MDADM=/sbin/mdadm
+test -x "$MDADM" || exit 0
+test -f /proc/mdstat || exit 0
+
+. /lib/lsb/init-functions
+
+case "${1:-}" in
+
+  start)
+    ;;
+
+  stop)
+    sync
+    wait=
+    for md in /sys/block/md*/md ; do
+      [ -d "$md" ] || continue
+      [ "$wait" ] || log_action_begin_msg "Waiting for MD arrays to become idle"
+      wait=y
+      [ -w $md/sync_action ] && echo idle > $md/sync_action
+    done
+    if [ "$wait" ]; then
+      # mdadm --wait-clean has a short internal timeout
+      if $MDADM --wait-clean --scan; then
+        log_action_end_msg 0
+      else
+        log_action_end_msg 1
+        sleep 1
+      fi
+    fi
+    ;;
+
+  *)
+    echo "Usage: ${0:-} stop" >&2
+    exit 1;;
+
+esac
+
+exit 0
diff -Nru mdadm-3.2.5/debian/rules mdadm-3.2.5/debian/rules
--- mdadm-3.2.5/debian/rules	2012-10-28 21:12:37.000000000 +0400
+++ mdadm-3.2.5/debian/rules	2012-10-28 22:28:12.000000000 +0400
@@ -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-restart-on-upgrade -- 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 to: