Blame SOURCES/mdadm-3.2.6-systemd-various-fixes-for-boot-with-container-arrays.patch

8c8931
From 8d1d32bb33da1bd08a398d26f364b84e69ac7b41 Mon Sep 17 00:00:00 2001
8c8931
From: NeilBrown <neilb@suse.de>
8c8931
Date: Tue, 8 Apr 2014 17:22:18 +1000
8c8931
Subject: [PATCH] systemd: various fixes for boot with container-arrays.
8c8931
8c8931
1/ Add systemd shutdown script to ensure DDF and IMSM are
8c8931
   clean before we actually shutdown
8c8931
8c8931
2/ Get udev to tell systemd to run the mdmon@mdXXX.service
8c8931
   units when a member array appears.
8c8931
8c8931
   If we boot off a member array (with dracut at least),
8c8931
   the mdmon started in the initramfs will lose track of
8c8931
   /sys etc, so we need to restart it.
8c8931
   systemd will try to forget about it too (but not actually
8c8931
   kill it because we said not to do this).
8c8931
   Having udev tell it to start it will allow a new mdmon to
8c8931
   run which can see /sys, and systemd will know about it.
8c8931
8c8931
3/ Always use --offroot and --takeover when starting mdmon with
8c8931
   systemd
8c8931
   --offroot is needed else shutdown will hang.
8c8931
   --takeover is needed incase an mdmon was started earlier
8c8931
   (e.g. in initramfs).
8c8931
   Neither hurt if they aren't actually needed.
8c8931
8c8931
Signed-off-by: NeilBrown <neilb@suse.de>
8c8931
---
8c8931
 Makefile                  |  1 +
8c8931
 systemd/mdadm.shutdown    |  4 ++++
8c8931
 systemd/mdmon@.service    | 12 ++++++++++--
8c8931
 udev-md-raid-arrays.rules |  4 ++++
8c8931
 4 files changed, 19 insertions(+), 2 deletions(-)
8c8931
 create mode 100644 systemd/mdadm.shutdown
8c8931
8c8931
diff --git a/systemd/mdadm.shutdown b/systemd/mdadm.shutdown
8c8931
new file mode 100644
8c8931
index 0000000..1bbbb6f
8c8931
--- /dev/null
8c8931
+++ b/systemd/mdadm.shutdown
8c8931
@@ -0,0 +1,4 @@
8c8931
+#!/bin/sh
8c8931
+# We need to ensure all md arrays with external metadata
8c8931
+# (e.g. IMSM, DDF) are clean before completing the shutdown.
8c8931
+/sbin/mdadm --wait-clean --scan
8c8931
diff --git a/systemd/mdmon@.service b/systemd/mdmon@.service
8c8931
index 304b26e..af0a2a3 100644
8c8931
--- a/systemd/mdmon@.service
8c8931
+++ b/systemd/mdmon@.service
8c8931
@@ -12,9 +12,17 @@ Before=initrd-switch-root.target
8c8931
 
8c8931
 [Service]
8c8931
 Environment=IMSM_NO_PLATFORM=1
8c8931
-ExecStart=/sbin/mdmon %I
8c8931
+# The mdmon starting in the initramfs (with dracut at least)
8c8931
+# cannot see sysfs after root is mounted, so we will have to
8c8931
+# 'takeover'.  As the '--offroot --takeover' don't hurt when
8c8931
+# not necessary, are are useful with root-on-md in dracut,
8c8931
+# have them always present.
8c8931
+ExecStart=/sbin/mdmon --offroot --takeover %I
8c8931
 Type=forking
8c8931
-PIDFile=/run/mdadm/%I.pid
8c8931
+# Don't set the PIDFile.  It isn't necessary (systemd can work
8c8931
+# it out) and systemd will remove it when transitioning from
8c8931
+# initramfs to rootfs.
8c8931
+#PIDFile=/run/mdadm/%I.pid
8c8931
 StandardInput=null
8c8931
 StandardOutput=null
8c8931
 StandardError=null
8c8931
diff --git a/udev-md-raid-arrays.rules b/udev-md-raid-arrays.rules
8c8931
index 4abbe35..92aec36 100644
8c8931
--- mdadm-3.2.6/udev-md-raid.rules.sysd	2014-06-18 12:10:38.363633555 +0200
8c8931
+++ mdadm-3.2.6/udev-md-raid.rules	2014-06-18 12:13:17.927934585 +0200
8c8931
@@ -46,4 +46,10 @@
8c8931
 ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}"
8c8931
 ENV{ID_FS_USAGE}=="filesystem|other", ENV{ID_FS_LABEL_ENC}=="?*", SYMLINK+="disk/by-label/$env{ID_FS_LABEL_ENC}"
8c8931
 
8c8931
+ENV{MD_LEVEL}=="raid[1-9]*", ENV{SYSTEMD_WANTS}+="mdmonitor.service"
8c8931
+
8c8931
+# Tell systemd to run mdmon for our container, if we need it.
8c8931
+ENV{MD_LEVEL}=="raid[1-9]*", ENV{MD_CONTAINER}=="?*", PROGRAM="/usr/bin/readlink $env{MD_CONTAINER}", ENV{MD_MON_THIS}="%c"
8c8931
+ENV{MD_MON_THIS}=="?*", PROGRAM="/usr/bin/basename $env{MD_MON_THIS}", ENV{SYSTEMD_WANTS}+="mdmon@%c.service"
8c8931
+
8c8931
 LABEL="md_end"