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