File manage-rebuild-map-for-kpartx of Package mdadm

Manage: rebuild map for 'kpartx -d' at stop

From: Dan Williams <dan.j.williams@intel.com>

mdadm needs the 'map' file to run 'kpartx -d' at array shutdown.
Rebuild it if it does not exist.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---

 Manage.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)


diff --git a/Manage.c b/Manage.c
index 85bb2c8..603e838 100644
--- a/Manage.c
+++ b/Manage.c
@@ -222,11 +222,23 @@ int Manage_runstop(char *devname, int fd, int runstop, int quiet)
 		    mdi->array.level > 0 &&
 		    is_subarray(mdi->text_version)) {
 			struct map_ent *me = map_by_devnum(&map, devnum);
+
+			if (!me) {
+				RebuildMap();
+				me = map_by_devnum(&map, devnum);
+			}
+
+			if (!me) {
+				fprintf(stderr, Name ": failed to map device %d\n",
+					devnum);
+				return 1;
+			} else
+				run_kpartx('d', me->path);
+
 			/* This is mdmon managed. */
 			close(fd);
 			
 			/* Delete any kpartx partitions */
-			run_kpartx('d', me->path);
 			if (sysfs_set_str(mdi, NULL,
 					  "array_state", "inactive") < 0) {
 				if (quiet == 0)
openSUSE Build Service is sponsored by