[dm-devel] [PATCH 2/2] Mark reloads with udev flag

Benjamin Marzinski bmarzins at redhat.com
Wed Feb 12 17:15:17 UTC 2014


In order for the udev rules to be able to distinguish uevents generated by
reloads instead of creates, multipath now tags all the reload resumes with
MPATH_UDEV_RELOAD_FLAG, which is defined as the first multipath
dm subsystem udev flag.  11-dm-mpath.rules watches for multipath events
tag.

Signed-off-by: Peter Rajnoha <prajnoha at redhat.com>
Signed-off-by: Benjamin Marzinski <bmarzins at redhat.com>
---
 kpartx/devmapper.c        |  4 ++--
 kpartx/devmapper.h        |  8 +++++++-
 kpartx/kpartx.c           |  8 ++++----
 libmultipath/configure.c  |  4 ++--
 libmultipath/devmapper.c  | 26 ++++++++++++++------------
 libmultipath/devmapper.h  | 10 ++++++++--
 multipathd/cli_handlers.c |  4 ++--
 7 files changed, 39 insertions(+), 25 deletions(-)

diff --git a/kpartx/devmapper.c b/kpartx/devmapper.c
index 24a43ee..7879a09 100644
--- a/kpartx/devmapper.c
+++ b/kpartx/devmapper.c
@@ -60,7 +60,7 @@ dm_prereq (char * str, int x, int y, int z)
 }
 
 extern int
-dm_simplecmd (int task, const char *name, int no_flush, uint32_t *cookie) {
+dm_simplecmd (int task, const char *name, int no_flush, uint32_t *cookie, uint16_t udev_flags) {
 	int r = 0;
 	int udev_wait_flag = (task == DM_DEVICE_RESUME ||
 			      task == DM_DEVICE_REMOVE);
@@ -78,7 +78,7 @@ dm_simplecmd (int task, const char *name, int no_flush, uint32_t *cookie) {
 	if (no_flush)
 		dm_task_no_flush(dmt);
 
-	if (udev_wait_flag && !dm_task_set_cookie(dmt, cookie, (udev_sync)? 0 : DM_UDEV_DISABLE_LIBRARY_FALLBACK))
+	if (udev_wait_flag && !dm_task_set_cookie(dmt, cookie, ((udev_sync)? 0 : DM_UDEV_DISABLE_LIBRARY_FALLBACK) | udev_flags))
 		goto out;
 	r = dm_task_run(dmt);
 
diff --git a/kpartx/devmapper.h b/kpartx/devmapper.h
index 0edc063..d962e43 100644
--- a/kpartx/devmapper.h
+++ b/kpartx/devmapper.h
@@ -2,10 +2,16 @@
 #define MINOR(dev)      ((dev & 0xff) | ((dev >> 12) & 0xfff00))
 #define MKDEV(ma,mi)    ((mi & 0xff) | (ma << 8) | ((mi & ~0xff) << 12))
 
+#ifdef DM_SUBSYSTEM_UDEV_FLAG0
+#define MPATH_UDEV_RELOAD_FLAG DM_SUBSYSTEM_UDEV_FLAG0
+#else
+#define MPATH_UDEV_RELOAD_FLAG 0
+#endif
+
 extern int udev_sync;
 
 int dm_prereq (char *, int, int, int);
-int dm_simplecmd (int, const char *, int, uint32_t *);
+int dm_simplecmd (int, const char *, int, uint32_t *, uint16_t);
 int dm_addmap (int, const char *, const char *, const char *, uint64_t,
 	       int, const char *, int, mode_t, uid_t, gid_t, uint32_t *);
 int dm_map_present (char *);
diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c
index 9a9a5eb..fac98dc 100644
--- a/kpartx/kpartx.c
+++ b/kpartx/kpartx.c
@@ -440,7 +440,7 @@ main(int argc, char **argv){
 					continue;
 
 				if (!dm_simplecmd(DM_DEVICE_REMOVE, partname,
-						  0, &cookie)) {
+						  0, &cookie, 0)) {
 					r++;
 					continue;
 				}
@@ -498,7 +498,7 @@ main(int argc, char **argv){
 				}
 				if (op == DM_DEVICE_RELOAD &&
 				    !dm_simplecmd(DM_DEVICE_RESUME, partname,
-						  1, &cookie)) {
+						  1, &cookie, MPATH_UDEV_RELOAD_FLAG)) {
 					fprintf(stderr, "resume failed on %s\n",
 						partname);
 					r++;
@@ -560,7 +560,7 @@ main(int argc, char **argv){
 					if (op == DM_DEVICE_RELOAD)
 						dm_simplecmd(DM_DEVICE_RESUME,
 							     partname, 1,
-							     &cookie);
+							     &cookie, MPATH_UDEV_RELOAD_FLAG);
 
 					dm_devn(partname, &slices[j].major,
 						&slices[j].minor);
@@ -593,7 +593,7 @@ main(int argc, char **argv){
 					continue;
 
 				if (!dm_simplecmd(DM_DEVICE_REMOVE,
-						  partname, 1, &cookie)) {
+						  partname, 1, &cookie, 0)) {
 					r++;
 					continue;
 				}
diff --git a/libmultipath/configure.c b/libmultipath/configure.c
index 8c09791..f20a2d6 100644
--- a/libmultipath/configure.c
+++ b/libmultipath/configure.c
@@ -389,13 +389,13 @@ domap (struct multipath * mpp, char * params)
 	case ACT_RELOAD:
 		r = dm_addmap_reload(mpp, params);
 		if (r)
-			r = dm_simplecmd_noflush(DM_DEVICE_RESUME, mpp->alias);
+			r = dm_simplecmd_noflush(DM_DEVICE_RESUME, mpp->alias, MPATH_UDEV_RELOAD_FLAG);
 		break;
 
 	case ACT_RESIZE:
 		r = dm_addmap_reload(mpp, params);
 		if (r)
-			r = dm_simplecmd_flush(DM_DEVICE_RESUME, mpp->alias, 1);
+			r = dm_simplecmd_flush(DM_DEVICE_RESUME, mpp->alias, 1, 0);
 		break;
 
 	case ACT_RENAME:
diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
index 6eb2d96..30e9351 100644
--- a/libmultipath/devmapper.c
+++ b/libmultipath/devmapper.c
@@ -105,7 +105,9 @@ dm_lib_prereq (void)
 {
 	char version[64];
 	int v[3];
-#ifdef LIBDM_API_COOKIE
+#if defined(DM_SUBSYSTEM_UDEV_FLAG0)
+	int minv[3] = {1, 2, 82};
+#elif defined(LIBDM_API_COOKIE)
 	int minv[3] = {1, 2, 38};
 #else
 	int minv[3] = {1, 2, 8};
@@ -202,7 +204,7 @@ dm_prereq (void)
 }
 
 static int
-dm_simplecmd (int task, const char *name, int no_flush, int need_sync) {
+dm_simplecmd (int task, const char *name, int no_flush, int need_sync, uint16_t udev_flags) {
 	int r = 0;
 	int udev_wait_flag = (need_sync && (task == DM_DEVICE_RESUME ||
 					    task == DM_DEVICE_REMOVE));
@@ -221,7 +223,7 @@ dm_simplecmd (int task, const char *name, int no_flush, int need_sync) {
 		dm_task_no_flush(dmt);		/* for DM_DEVICE_SUSPEND/RESUME */
 #endif
 
-	if (udev_wait_flag && !dm_task_set_cookie(dmt, &conf->cookie, (conf->daemon)? DM_UDEV_DISABLE_LIBRARY_FALLBACK : 0))
+	if (udev_wait_flag && !dm_task_set_cookie(dmt, &conf->cookie, ((conf->daemon)? DM_UDEV_DISABLE_LIBRARY_FALLBACK : 0) | udev_flags))
 		goto out;
 	r = dm_task_run (dmt);
 
@@ -231,13 +233,13 @@ dm_simplecmd (int task, const char *name, int no_flush, int need_sync) {
 }
 
 extern int
-dm_simplecmd_flush (int task, const char *name, int needsync) {
-	return dm_simplecmd(task, name, 0, needsync);
+dm_simplecmd_flush (int task, const char *name, int needsync, uint16_t udev_flags) {
+	return dm_simplecmd(task, name, 0, needsync, udev_flags);
 }
 
 extern int
-dm_simplecmd_noflush (int task, const char *name) {
-	return dm_simplecmd(task, name, 1, 1);
+dm_simplecmd_noflush (int task, const char *name, uint16_t udev_flags) {
+	return dm_simplecmd(task, name, 1, 1, udev_flags);
 }
 
 extern int
@@ -672,7 +674,7 @@ _dm_flush_map (const char * mapname, int need_sync)
 		return 1;
 	}
 
-	r = dm_simplecmd_flush(DM_DEVICE_REMOVE, mapname, need_sync);
+	r = dm_simplecmd_flush(DM_DEVICE_REMOVE, mapname, need_sync, 0);
 
 	if (r) {
 		condlog(4, "multipath map %s removed", mapname);
@@ -705,14 +707,14 @@ dm_suspend_and_flush_map (const char * mapname)
 	if (s)
 		queue_if_no_path = 0;
 	else
-		s = dm_simplecmd_flush(DM_DEVICE_SUSPEND, mapname, 0);
+		s = dm_simplecmd_flush(DM_DEVICE_SUSPEND, mapname, 0, 0);
 
 	if (!dm_flush_map(mapname)) {
 		condlog(4, "multipath map %s removed", mapname);
 		return 0;
 	}
 	condlog(2, "failed to remove multipath map %s", mapname);
-	dm_simplecmd_noflush(DM_DEVICE_RESUME, mapname);
+	dm_simplecmd_noflush(DM_DEVICE_RESUME, mapname, 0);
 	if (queue_if_no_path)
 		s = dm_queue_if_no_path((char *)mapname, 1);
 	return 1;
@@ -1069,7 +1071,7 @@ dm_remove_partmaps (const char * mapname, int need_sync)
 			condlog(4, "partition map %s removed",
 				names->name);
 			dm_simplecmd_flush(DM_DEVICE_REMOVE, names->name,
-					   need_sync);
+					   need_sync, 0);
 		}
 
 		next = names->next;
@@ -1297,7 +1299,7 @@ int dm_reassign_table(const char *name, char *old, char *new)
 			condlog(3, "%s: failed to reassign targets", name);
 			goto out_reload;
 		}
-		dm_simplecmd_noflush(DM_DEVICE_RESUME, name);
+		dm_simplecmd_noflush(DM_DEVICE_RESUME, name, MPATH_UDEV_RELOAD_FLAG);
 	}
 	r = 1;
 
diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h
index 58cd718..6ea816c 100644
--- a/libmultipath/devmapper.h
+++ b/libmultipath/devmapper.h
@@ -6,11 +6,17 @@
 #define TGT_MPATH	"multipath"
 #define TGT_PART	"linear"
 
+#ifdef DM_SUBSYSTEM_UDEV_FLAG0
+#define MPATH_UDEV_RELOAD_FLAG DM_SUBSYSTEM_UDEV_FLAG0
+#else
+#define MPATH_UDEV_RELOAD_FLAG 0
+#endif
+
 void dm_init(void);
 int dm_prereq (void);
 int dm_drv_version (unsigned int * version, char * str);
-int dm_simplecmd_flush (int, const char *, int);
-int dm_simplecmd_noflush (int, const char *);
+int dm_simplecmd_flush (int, const char *, int, uint16_t);
+int dm_simplecmd_noflush (int, const char *, uint16_t);
 int dm_addmap_create (struct multipath *mpp, char *params);
 int dm_addmap_reload (struct multipath *mpp, char *params);
 int dm_map_present (const char *);
diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c
index f7fc522..b086340 100644
--- a/multipathd/cli_handlers.c
+++ b/multipathd/cli_handlers.c
@@ -785,7 +785,7 @@ cli_suspend(void * v, char ** reply, int * len, void * data)
 {
 	struct vectors * vecs = (struct vectors *)data;
 	char * param = get_keyparam(v, MAP);
-	int r = dm_simplecmd_noflush(DM_DEVICE_SUSPEND, param);
+	int r = dm_simplecmd_noflush(DM_DEVICE_SUSPEND, param, 0);
 
 	param = convert_dev(param, 0);
 	condlog(2, "%s: suspend (operator)", param);
@@ -807,7 +807,7 @@ cli_resume(void * v, char ** reply, int * len, void * data)
 {
 	struct vectors * vecs = (struct vectors *)data;
 	char * param = get_keyparam(v, MAP);
-	int r = dm_simplecmd_noflush(DM_DEVICE_RESUME, param);
+	int r = dm_simplecmd_noflush(DM_DEVICE_RESUME, param, 0);
 
 	param = convert_dev(param, 0);
 	condlog(2, "%s: resume (operator)", param);
-- 
1.8.4.2




More information about the dm-devel mailing list