Blame SOURCES/0159-UPBZ-1255885-udev-waits.patch

f20720
---
f20720
 kpartx/devmapper.c       |   41 ++++++++++++++++++++++++++++-------------
f20720
 kpartx/devmapper.h       |    4 ++--
f20720
 kpartx/kpartx.c          |   16 ++++++++--------
f20720
 libmultipath/config.h    |    1 -
f20720
 libmultipath/devmapper.c |   19 +++++++++++++------
f20720
 multipath/main.c         |    2 --
f20720
 6 files changed, 51 insertions(+), 32 deletions(-)
f20720
f20720
Index: multipath-tools-130222/kpartx/devmapper.c
f20720
===================================================================
f20720
--- multipath-tools-130222.orig/kpartx/devmapper.c
f20720
+++ multipath-tools-130222/kpartx/devmapper.c
f20720
@@ -14,13 +14,6 @@
f20720
 #define MAX_PREFIX_LEN 8
f20720
 #define PARAMS_SIZE 1024
f20720
 
f20720
-#ifndef LIBDM_API_COOKIE
f20720
-static inline int dm_task_set_cookie(struct dm_task *dmt, uint32_t *c, int a)
f20720
-{
f20720
-	return 1;
f20720
-}
f20720
-#endif
f20720
-
f20720
 extern int
f20720
 dm_prereq (char * str, int x, int y, int z)
f20720
 {
f20720
@@ -60,10 +53,13 @@ dm_prereq (char * str, int x, int y, int
f20720
 }
f20720
 
f20720
 extern int
f20720
-dm_simplecmd (int task, const char *name, int no_flush, uint32_t *cookie, uint16_t udev_flags) {
f20720
+dm_simplecmd (int task, const char *name, int no_flush, uint16_t udev_flags) {
f20720
 	int r = 0;
f20720
 	int udev_wait_flag = (task == DM_DEVICE_RESUME ||
f20720
 			      task == DM_DEVICE_REMOVE);
f20720
+#ifdef LIBDM_API_COOKIE
f20720
+	uint32_t cookie = 0;
f20720
+#endif
f20720
 	struct dm_task *dmt;
f20720
 
f20720
 	if (!(dmt = dm_task_create(task)))
f20720
@@ -78,10 +74,17 @@ dm_simplecmd (int task, const char *name
f20720
 	if (no_flush)
f20720
 		dm_task_no_flush(dmt);
f20720
 
f20720
-	if (udev_wait_flag && !dm_task_set_cookie(dmt, cookie, ((udev_sync)? 0 : DM_UDEV_DISABLE_LIBRARY_FALLBACK) | udev_flags))
f20720
+#ifdef LIBDM_API_COOKIE
f20720
+	if (!udev_sync)
f20720
+		udev_flags |= DM_UDEV_DISABLE_LIBRARY_FALLBACK;
f20720
+	if (udev_wait_flag && !dm_task_set_cookie(dmt, &cookie, udev_flags))
f20720
 		goto out;
f20720
+#endif
f20720
 	r = dm_task_run(dmt);
f20720
-
f20720
+#ifdef LIBDM_API_COOKIE
f20720
+	if (udev_wait_flag)
f20720
+		dm_udev_wait(cookie);
f20720
+#endif
f20720
 	out:
f20720
 	dm_task_destroy(dmt);
f20720
 	return r;
f20720
@@ -90,10 +93,14 @@ dm_simplecmd (int task, const char *name
f20720
 extern int
f20720
 dm_addmap (int task, const char *name, const char *target,
f20720
 	   const char *params, uint64_t size, int ro, const char *uuid, int part,
f20720
-	   mode_t mode, uid_t uid, gid_t gid, uint32_t *cookie) {
f20720
+	   mode_t mode, uid_t uid, gid_t gid) {
f20720
 	int r = 0;
f20720
 	struct dm_task *dmt;
f20720
 	char *prefixed_uuid = NULL;
f20720
+#ifdef LIBDM_API_COOKIE
f20720
+	uint32_t cookie = 0;
f20720
+	uint16_t udev_flags = 0;
f20720
+#endif
f20720
 
f20720
 	if (!(dmt = dm_task_create (task)))
f20720
 		return 0;
f20720
@@ -128,10 +135,18 @@ dm_addmap (int task, const char *name, c
f20720
 
f20720
 	dm_task_no_open_count(dmt);
f20720
 
f20720
-	if (task == DM_DEVICE_CREATE && !dm_task_set_cookie(dmt, cookie, (udev_sync)? 0 : DM_UDEV_DISABLE_LIBRARY_FALLBACK))
f20720
+#ifdef LIBDM_API_COOKIE
f20720
+	if (!udev_sync)
f20720
+		udev_flags = DM_UDEV_DISABLE_LIBRARY_FALLBACK;
f20720
+	if (task == DM_DEVICE_CREATE &&
f20720
+	    !dm_task_set_cookie(dmt, &cookie, udev_flags))
f20720
 		goto addout;
f20720
+#endif
f20720
 	r = dm_task_run (dmt);
f20720
-
f20720
+#ifdef LIBDM_API_COOKIE
f20720
+	if (task == DM_DEVICE_CREATE)
f20720
+			dm_udev_wait(cookie);
f20720
+#endif
f20720
 addout:
f20720
 	dm_task_destroy (dmt);
f20720
 	free(prefixed_uuid);
f20720
Index: multipath-tools-130222/kpartx/devmapper.h
f20720
===================================================================
f20720
--- multipath-tools-130222.orig/kpartx/devmapper.h
f20720
+++ multipath-tools-130222/kpartx/devmapper.h
f20720
@@ -11,9 +11,9 @@
f20720
 extern int udev_sync;
f20720
 
f20720
 int dm_prereq (char *, int, int, int);
f20720
-int dm_simplecmd (int, const char *, int, uint32_t *, uint16_t);
f20720
+int dm_simplecmd (int, const char *, int, uint16_t);
f20720
 int dm_addmap (int, const char *, const char *, const char *, uint64_t,
f20720
-	       int, const char *, int, mode_t, uid_t, gid_t, uint32_t *);
f20720
+	       int, const char *, int, mode_t, uid_t, gid_t);
f20720
 int dm_map_present (char *, char **);
f20720
 char * dm_mapname(int major, int minor);
f20720
 dev_t dm_get_first_dep(char *devname);
f20720
Index: multipath-tools-130222/kpartx/kpartx.c
f20720
===================================================================
f20720
--- multipath-tools-130222.orig/kpartx/kpartx.c
f20720
+++ multipath-tools-130222/kpartx/kpartx.c
f20720
@@ -224,7 +224,6 @@ main(int argc, char **argv){
f20720
 	int hotplug = 0;
f20720
 	int loopcreated = 0;
f20720
 	struct stat buf;
f20720
-	uint32_t cookie = 0;
f20720
 
f20720
 	initpts();
f20720
 	init_crc32();
f20720
@@ -300,6 +299,8 @@ main(int argc, char **argv){
f20720
 #ifdef LIBDM_API_COOKIE
f20720
 	if (!udev_sync)
f20720
 		dm_udev_set_sync_support(0);
f20720
+	else
f20720
+		dm_udev_set_sync_support(1);
f20720
 #endif
f20720
 
f20720
 	if (dm_prereq(DM_TARGET, 0, 0, 0) && (what == ADD || what == DELETE || what == UPDATE)) {
f20720
@@ -451,7 +452,7 @@ main(int argc, char **argv){
f20720
 				}
f20720
 
f20720
 				if (!dm_simplecmd(DM_DEVICE_REMOVE, partname,
f20720
-						  0, &cookie, 0)) {
f20720
+						  0, 0)) {
f20720
 					r++;
f20720
 					continue;
f20720
 				}
f20720
@@ -508,7 +509,7 @@ main(int argc, char **argv){
f20720
 				if (!dm_addmap(op, partname, DM_TARGET, params,
f20720
 					       slices[j].size, ro, uuid, j+1,
f20720
 					       buf.st_mode & 0777, buf.st_uid,
f20720
-					       buf.st_gid, &cookie)) {
f20720
+					       buf.st_gid)) {
f20720
 					fprintf(stderr, "create/reload failed on %s\n",
f20720
 						partname);
f20720
 					r++;
f20720
@@ -516,12 +517,13 @@ main(int argc, char **argv){
f20720
 				}
f20720
 				if (op == DM_DEVICE_RELOAD &&
f20720
 				    !dm_simplecmd(DM_DEVICE_RESUME, partname,
f20720
-						  1, &cookie, MPATH_UDEV_RELOAD_FLAG)) {
f20720
+						  1, MPATH_UDEV_RELOAD_FLAG)) {
f20720
 					fprintf(stderr, "resume failed on %s\n",
f20720
 						partname);
f20720
 					r++;
f20720
 					continue;
f20720
 				}
f20720
+
f20720
 				dm_devn(partname, &slices[j].major,
f20720
 					&slices[j].minor);
f20720
 
f20720
@@ -560,7 +562,7 @@ main(int argc, char **argv){
f20720
 				}
f20720
 
f20720
 				if (!dm_simplecmd(DM_DEVICE_REMOVE,
f20720
-						  partname, 1, &cookie, 0)) {
f20720
+						  partname, 1, 0)) {
f20720
 					r++;
f20720
 					continue;
f20720
 				}
f20720
@@ -586,9 +588,7 @@ main(int argc, char **argv){
f20720
 		}
f20720
 		printf("loop deleted : %s\n", device);
f20720
 	}
f20720
-#ifdef LIBDM_API_COOKIE
f20720
-	dm_udev_wait(cookie);
f20720
-#endif
f20720
+
f20720
 	dm_lib_release();
f20720
 	dm_lib_exit();
f20720
 
f20720
Index: multipath-tools-130222/libmultipath/config.h
f20720
===================================================================
f20720
--- multipath-tools-130222.orig/libmultipath/config.h
f20720
+++ multipath-tools-130222/libmultipath/config.h
f20720
@@ -129,7 +129,6 @@ struct config {
f20720
 	uid_t uid;
f20720
 	gid_t gid;
f20720
 	mode_t mode;
f20720
-	uint32_t cookie;
f20720
 	int reassign_maps;
f20720
 	int retain_hwhandler;
f20720
 	int detect_prio;
f20720
Index: multipath-tools-130222/libmultipath/devmapper.c
f20720
===================================================================
f20720
--- multipath-tools-130222.orig/libmultipath/devmapper.c
f20720
+++ multipath-tools-130222/libmultipath/devmapper.c
f20720
@@ -215,6 +215,7 @@ dm_simplecmd (int task, const char *name
f20720
 	int r = 0;
f20720
 	int udev_wait_flag = (need_sync && (task == DM_DEVICE_RESUME ||
f20720
 					    task == DM_DEVICE_REMOVE));
f20720
+	uint32_t cookie = 0;
f20720
 	struct dm_task *dmt;
f20720
 
f20720
 	if (!(dmt = dm_task_create (task)))
f20720
@@ -233,10 +234,12 @@ dm_simplecmd (int task, const char *name
f20720
 	if (do_deferred(deferred_remove))
f20720
 		dm_task_deferred_remove(dmt);
f20720
 #endif
f20720
-	if (udev_wait_flag && !dm_task_set_cookie(dmt, &conf->cookie, ((conf->daemon)? DM_UDEV_DISABLE_LIBRARY_FALLBACK : 0) | udev_flags))
f20720
+	if (udev_wait_flag && !dm_task_set_cookie(dmt, &cookie, ((conf->daemon)? DM_UDEV_DISABLE_LIBRARY_FALLBACK : 0) | udev_flags))
f20720
 		goto out;
f20720
 	r = dm_task_run (dmt);
f20720
 
f20720
+	if (udev_wait_flag)
f20720
+			udev_wait(cookie);
f20720
 	out:
f20720
 	dm_task_destroy (dmt);
f20720
 	return r;
f20720
@@ -264,6 +267,7 @@ dm_addmap (int task, const char *target,
f20720
 	int r = 0;
f20720
 	struct dm_task *dmt;
f20720
 	char *prefixed_uuid = NULL;
f20720
+	uint32_t cookie = 0;
f20720
 
f20720
 	if (!(dmt = dm_task_create (task)))
f20720
 		return 0;
f20720
@@ -304,10 +308,12 @@ dm_addmap (int task, const char *target,
f20720
 	dm_task_no_open_count(dmt);
f20720
 
f20720
 	if (task == DM_DEVICE_CREATE &&
f20720
-	    !dm_task_set_cookie(dmt, &conf->cookie, (conf->daemon)? DM_UDEV_DISABLE_LIBRARY_FALLBACK : 0))
f20720
+	    !dm_task_set_cookie(dmt, &cookie, (conf->daemon)? DM_UDEV_DISABLE_LIBRARY_FALLBACK : 0))
f20720
 		goto freeout;
f20720
 	r = dm_task_run (dmt);
f20720
 
f20720
+	if (task == DM_DEVICE_CREATE)
f20720
+			udev_wait(cookie);
f20720
 	freeout:
f20720
 	if (prefixed_uuid)
f20720
 		FREE(prefixed_uuid);
f20720
@@ -1366,6 +1372,7 @@ dm_rename (const char * old, char * new)
f20720
 {
f20720
 	int r = 0;
f20720
 	struct dm_task *dmt;
f20720
+	uint32_t cookie;
f20720
 
f20720
 	if (dm_rename_partmaps(old, new))
f20720
 		return r;
f20720
@@ -1381,12 +1388,12 @@ dm_rename (const char * old, char * new)
f20720
 
f20720
 	dm_task_no_open_count(dmt);
f20720
 
f20720
-	if (!dm_task_set_cookie(dmt, &conf->cookie, (conf->daemon)? DM_UDEV_DISABLE_LIBRARY_FALLBACK : 0))
f20720
-		goto out;
f20720
-	if (!dm_task_run(dmt))
f20720
+	if (!dm_task_set_cookie(dmt, &cookie, (conf->daemon)? DM_UDEV_DISABLE_LIBRARY_FALLBACK : 0))
f20720
 		goto out;
f20720
+	r = dm_task_run(dmt);
f20720
+
f20720
+	udev_wait(cookie);
f20720
 
f20720
-	r = 1;
f20720
 out:
f20720
 	dm_task_destroy(dmt);
f20720
 	return r;
f20720
Index: multipath-tools-130222/multipath/main.c
f20720
===================================================================
f20720
--- multipath-tools-130222.orig/multipath/main.c
f20720
+++ multipath-tools-130222/multipath/main.c
f20720
@@ -681,8 +681,6 @@ main (int argc, char *argv[])
f20720
 		condlog(3, "restart multipath configuration process");
f20720
 
f20720
 out:
f20720
-	udev_wait(conf->cookie);
f20720
-
f20720
 	dm_lib_release();
f20720
 	dm_lib_exit();
f20720