45d01a
---
45d01a
 libmultipath/configure.c |   18 +++------------
45d01a
 libmultipath/devmapper.c |   55 +++++++++++++++++++++++++++++++++++++++++------
45d01a
 libmultipath/devmapper.h |    3 +-
45d01a
 3 files changed, 55 insertions(+), 21 deletions(-)
45d01a
45d01a
Index: multipath-tools-130222/libmultipath/configure.c
45d01a
===================================================================
45d01a
--- multipath-tools-130222.orig/libmultipath/configure.c
45d01a
+++ multipath-tools-130222/libmultipath/configure.c
45d01a
@@ -616,7 +616,6 @@ extern int
45d01a
 domap (struct multipath * mpp, char * params)
45d01a
 {
45d01a
 	int r = 0;
45d01a
-	uint16_t udev_flags = ((mpp->force_udev_reload)? 0 : MPATH_UDEV_RELOAD_FLAG) | ((mpp->skip_kpartx == SKIP_KPARTX_ON)? MPATH_UDEV_NO_KPARTX_FLAG : 0) | ((mpp->nr_active)? 0 : MPATH_UDEV_NO_PATHS_FLAG);
45d01a
 
45d01a
 	/*
45d01a
 	 * last chance to quit before touching the devmaps
45d01a
@@ -660,17 +659,11 @@ domap (struct multipath * mpp, char * pa
45d01a
 		break;
45d01a
 
45d01a
 	case ACT_RELOAD:
45d01a
-		r = dm_addmap_reload(mpp, params);
45d01a
-		if (r)
45d01a
-			r = dm_simplecmd_noflush(DM_DEVICE_RESUME, mpp->alias,
45d01a
-						 udev_flags);
45d01a
+		r = dm_addmap_reload(mpp, params, 0);
45d01a
 		break;
45d01a
 
45d01a
 	case ACT_RESIZE:
45d01a
-		r = dm_addmap_reload(mpp, params);
45d01a
-		if (r)
45d01a
-			r = dm_simplecmd_flush(DM_DEVICE_RESUME, mpp->alias, 1,
45d01a
-					       udev_flags);
45d01a
+		r = dm_addmap_reload(mpp, params, 1);
45d01a
 		break;
45d01a
 
45d01a
 	case ACT_RENAME:
45d01a
@@ -679,11 +672,8 @@ domap (struct multipath * mpp, char * pa
45d01a
 
45d01a
 	case ACT_RENAME2:
45d01a
 		r = dm_rename(mpp->alias_old, mpp->alias, mpp->skip_kpartx);
45d01a
-		if (r) {
45d01a
-			r = dm_addmap_reload(mpp, params);
45d01a
-			if (r)
45d01a
-				r = dm_simplecmd_noflush(DM_DEVICE_RESUME, mpp->alias, udev_flags);
45d01a
-		}
45d01a
+		if (r)
45d01a
+			r = dm_addmap_reload(mpp, params, 0);
45d01a
 		break;
45d01a
 
45d01a
 	default:
45d01a
Index: multipath-tools-130222/libmultipath/devmapper.c
45d01a
===================================================================
45d01a
--- multipath-tools-130222.orig/libmultipath/devmapper.c
45d01a
+++ multipath-tools-130222/libmultipath/devmapper.c
45d01a
@@ -356,15 +356,33 @@ dm_addmap_create (struct multipath *mpp,
45d01a
 #define ADDMAP_RO 1
45d01a
 
45d01a
 extern int
45d01a
-dm_addmap_reload (struct multipath *mpp, char *params) {
45d01a
+dm_addmap_reload (struct multipath *mpp, char *params, int flush) {
45d01a
+	int r = 0;
45d01a
+	uint16_t udev_flags = ((mpp->force_udev_reload)?
45d01a
+			       0 : MPATH_UDEV_RELOAD_FLAG) |
45d01a
+			      ((mpp->skip_kpartx == SKIP_KPARTX_ON)?
45d01a
+			       MPATH_UDEV_NO_KPARTX_FLAG : 0) |
45d01a
+			      ((mpp->nr_active)? 0 : MPATH_UDEV_NO_PATHS_FLAG);
45d01a
+
45d01a
 	sysfs_set_max_sectors_kb(mpp, 1);
45d01a
-	if (!mpp->force_readonly) {
45d01a
-		if (dm_addmap(DM_DEVICE_RELOAD, TGT_MPATH, mpp, params, 0, ADDMAP_RW, SKIP_KPARTX_OFF))
45d01a
-			return 1;
45d01a
-		if (errno != EROFS)
45d01a
+	if (!mpp->force_readonly)
45d01a
+		r = dm_addmap(DM_DEVICE_RELOAD, TGT_MPATH, mpp, params, 0,
45d01a
+			      ADDMAP_RW, SKIP_KPARTX_OFF);
45d01a
+	if (!r) {
45d01a
+		if (!mpp->force_readonly && errno != EROFS)
45d01a
 			return 0;
45d01a
+		r = dm_addmap(DM_DEVICE_RELOAD, TGT_MPATH, mpp, params, 0,
45d01a
+			      ADDMAP_RO, SKIP_KPARTX_OFF);
45d01a
 	}
45d01a
-	return dm_addmap(DM_DEVICE_RELOAD, TGT_MPATH, mpp, params, 0, ADDMAP_RO, SKIP_KPARTX_OFF);
45d01a
+	if (r)
45d01a
+		r = dm_simplecmd(DM_DEVICE_RESUME, mpp->alias, !flush,
45d01a
+				 1, udev_flags, 0);
45d01a
+	if (r)
45d01a
+		return r;
45d01a
+	if (dm_is_suspended(mpp->alias))
45d01a
+		dm_simplecmd(DM_DEVICE_RESUME, mpp->alias, !flush, 1,
45d01a
+			     udev_flags, 0);
45d01a
+	return 0;
45d01a
 }
45d01a
 
45d01a
 extern int
45d01a
@@ -613,6 +631,31 @@ dm_is_mpath(const char * name)
45d01a
 out:
45d01a
 	dm_task_destroy(dmt);
45d01a
 	return r;
45d01a
+}
45d01a
+
45d01a
+int
45d01a
+dm_is_suspended(const char *mapname)
45d01a
+{
45d01a
+	int r = -1;
45d01a
+	struct dm_task *dmt;
45d01a
+	struct dm_info info;
45d01a
+
45d01a
+	if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
45d01a
+		return r;
45d01a
+
45d01a
+	if (!dm_task_set_name(dmt, mapname))
45d01a
+		goto out;
45d01a
+
45d01a
+	if (!dm_task_run(dmt))
45d01a
+		goto out;
45d01a
+
45d01a
+	if (!dm_task_get_info(dmt, &info) || !info.exists)
45d01a
+		goto out;
45d01a
+
45d01a
+	r = info.suspended;
45d01a
+out:
45d01a
+	dm_task_destroy(dmt);
45d01a
+	return r;
45d01a
 }
45d01a
 
45d01a
 static int
45d01a
Index: multipath-tools-130222/libmultipath/devmapper.h
45d01a
===================================================================
45d01a
--- multipath-tools-130222.orig/libmultipath/devmapper.h
45d01a
+++ multipath-tools-130222/libmultipath/devmapper.h
45d01a
@@ -30,7 +30,7 @@ int dm_drv_version (unsigned int * versi
45d01a
 int dm_simplecmd_flush (int, const char *, int, uint16_t);
45d01a
 int dm_simplecmd_noflush (int, const char *, uint16_t);
45d01a
 int dm_addmap_create (struct multipath *mpp, char *params);
45d01a
-int dm_addmap_reload (struct multipath *mpp, char *params);
45d01a
+int dm_addmap_reload (struct multipath *mpp, char *params, int flush);
45d01a
 int dm_map_present (const char *);
45d01a
 int dm_get_map(const char *, unsigned long long *, char *);
45d01a
 int dm_get_status(char *, char *);
45d01a
@@ -51,6 +51,7 @@ int dm_switchgroup(char * mapname, int i
45d01a
 int dm_enablegroup(char * mapname, int index);
45d01a
 int dm_disablegroup(char * mapname, int index);
45d01a
 int dm_get_maps (vector mp);
45d01a
+int dm_is_suspended(const char *mapname);
45d01a
 int dm_geteventnr (char *name);
45d01a
 int dm_get_major (char *name);
45d01a
 int dm_get_minor (char *name);