2 kpartx/devmapper.c | 10 ++++++++--
3 kpartx/devmapper.h | 4 ++--
4 kpartx/kpartx.c | 22 ++++++++++++++++------
5 libmultipath/config.h | 2 ++
6 libmultipath/configure.c | 2 +-
7 libmultipath/devmapper.c | 29 +++++++++++++++++++----------
8 libmultipath/devmapper.h | 8 +++++---
10 multipathd/main.c | 1 +
11 9 files changed, 55 insertions(+), 24 deletions(-)
13 Index: multipath-tools/kpartx/devmapper.c
14 ===================================================================
15 --- multipath-tools.orig/kpartx/devmapper.c
16 +++ multipath-tools/kpartx/devmapper.c
17 @@ -52,8 +52,10 @@ dm_prereq (char * str, int x, int y, int
21 -dm_simplecmd (int task, const char *name, int no_flush) {
22 +dm_simplecmd (int task, const char *name, int no_flush, uint32_t *cookie) {
24 + int udev_wait_flag = (task == DM_DEVICE_RESUME ||
25 + task == DM_DEVICE_REMOVE);
28 if (!(dmt = dm_task_create(task)))
29 @@ -68,6 +70,8 @@ dm_simplecmd (int task, const char *name
31 dm_task_no_flush(dmt);
33 + if (udev_wait_flag && !dm_task_set_cookie(dmt, cookie, 0))
38 @@ -78,7 +82,7 @@ dm_simplecmd (int task, const char *name
40 dm_addmap (int task, const char *name, const char *target,
41 const char *params, uint64_t size, const char *uuid, int part,
42 - mode_t mode, uid_t uid, gid_t gid) {
43 + mode_t mode, uid_t uid, gid_t gid, uint32_t *cookie) {
46 char *prefixed_uuid = NULL;
47 @@ -113,6 +117,8 @@ dm_addmap (int task, const char *name, c
49 dm_task_no_open_count(dmt);
51 + if (task == DM_DEVICE_CREATE && !dm_task_set_cookie(dmt, cookie, 0))
53 r = dm_task_run (dmt);
56 Index: multipath-tools/kpartx/kpartx.c
57 ===================================================================
58 --- multipath-tools.orig/kpartx/kpartx.c
59 +++ multipath-tools/kpartx/kpartx.c
60 @@ -82,7 +82,7 @@ initpts(void)
61 addpts("sun", read_sun_pt);
64 -static char short_opts[] = "ladgvp:t:";
65 +static char short_opts[] = "ladgvp:t:s";
69 @@ -96,6 +96,7 @@ usage(void) {
70 printf("\t-p set device name-partition number delimiter\n");
71 printf("\t-g force GUID partition table (GPT)\n");
72 printf("\t-v verbose\n");
73 + printf("\t-s sync mode. Don't return until the partitions are created\n");
77 @@ -198,7 +199,9 @@ main(int argc, char **argv){
83 + uint32_t cookie = 0;
87 @@ -251,11 +254,17 @@ main(int argc, char **argv){
100 + dm_udev_set_sync_support(0);
102 if (dm_prereq(DM_TARGET, 0, 0, 0) && (what == ADD || what == DELETE)) {
103 fprintf(stderr, "device mapper prerequisites not met\n");
105 @@ -413,8 +422,8 @@ main(int argc, char **argv){
106 if (!slices[j].size || !dm_map_present(partname))
109 - if (!dm_simplecmd(DM_DEVICE_REMOVE,
111 + if (!dm_simplecmd(DM_DEVICE_REMOVE, partname,
116 @@ -463,14 +472,14 @@ main(int argc, char **argv){
117 if (!dm_addmap(op, partname, DM_TARGET, params,
118 slices[j].size, uuid, j+1,
119 buf.st_mode & 0777, buf.st_uid,
121 + buf.st_gid, &cookie)) {
122 fprintf(stderr, "create/reload failed on %s\n",
126 if (op == DM_DEVICE_RELOAD &&
127 - !dm_simplecmd(DM_DEVICE_RESUME,
129 + !dm_simplecmd(DM_DEVICE_RESUME, partname,
131 fprintf(stderr, "resume failed on %s\n",
134 @@ -557,6 +566,7 @@ main(int argc, char **argv){
138 + dm_udev_wait(cookie);
142 Index: multipath-tools/kpartx/devmapper.h
143 ===================================================================
144 --- multipath-tools.orig/kpartx/devmapper.h
145 +++ multipath-tools/kpartx/devmapper.h
147 #define MKDEV(ma,mi) ((mi & 0xff) | (ma << 8) | ((mi & ~0xff) << 12))
149 int dm_prereq (char *, int, int, int);
150 -int dm_simplecmd (int, const char *, int);
151 +int dm_simplecmd (int, const char *, int, uint32_t *);
152 int dm_addmap (int, const char *, const char *, const char *, uint64_t,
153 - const char *, int, mode_t, uid_t, gid_t);
154 + const char *, int, mode_t, uid_t, gid_t, uint32_t *);
155 int dm_map_present (char *);
156 char * dm_mapname(int major, int minor);
157 dev_t dm_get_first_dep(char *devname);
158 Index: multipath-tools/libmultipath/config.h
159 ===================================================================
160 --- multipath-tools.orig/libmultipath/config.h
161 +++ multipath-tools/libmultipath/config.h
165 #include <sys/types.h>
168 #define ORIGIN_DEFAULT 0
169 #define ORIGIN_CONFIG 1
170 @@ -84,6 +85,7 @@ struct config {
178 Index: multipath-tools/libmultipath/devmapper.c
179 ===================================================================
180 --- multipath-tools.orig/libmultipath/devmapper.c
181 +++ multipath-tools/libmultipath/devmapper.c
182 @@ -149,8 +149,10 @@ dm_prereq (void)
186 -dm_simplecmd (int task, const char *name, int no_flush) {
187 +dm_simplecmd (int task, const char *name, int no_flush, int need_sync) {
189 + int udev_wait_flag = (need_sync && (task == DM_DEVICE_RESUME ||
190 + task == DM_DEVICE_REMOVE));
193 if (!(dmt = dm_task_create (task)))
194 @@ -166,6 +168,8 @@ dm_simplecmd (int task, const char *name
195 dm_task_no_flush(dmt); /* for DM_DEVICE_SUSPEND/RESUME */
198 + if (udev_wait_flag && !dm_task_set_cookie(dmt, &conf->cookie, 0))
200 r = dm_task_run (dmt);
203 @@ -174,13 +178,13 @@ dm_simplecmd (int task, const char *name
207 -dm_simplecmd_flush (int task, const char *name) {
208 - return dm_simplecmd(task, name, 0);
209 +dm_simplecmd_flush (int task, const char *name, int needsync) {
210 + return dm_simplecmd(task, name, 0, needsync);
214 dm_simplecmd_noflush (int task, const char *name) {
215 - return dm_simplecmd(task, name, 1);
216 + return dm_simplecmd(task, name, 1, 1);
220 @@ -226,6 +230,9 @@ dm_addmap (int task, const char *target,
222 dm_task_no_open_count(dmt);
224 + if (task == DM_DEVICE_CREATE &&
225 + !dm_task_set_cookie(dmt, &conf->cookie, 0))
227 r = dm_task_run (dmt);
230 @@ -249,7 +256,7 @@ _dm_addmap_create (struct multipath *mpp
231 if (!r && dm_map_present(mpp->alias)) {
232 condlog(3, "%s: failed to load map (a path might be in use)",
234 - dm_flush_map(mpp->alias);
235 + dm_flush_map_nosync(mpp->alias);
239 @@ -529,7 +536,7 @@ out:
243 -dm_flush_map (const char * mapname)
244 +_dm_flush_map (const char * mapname, int need_sync)
248 @@ -539,7 +546,7 @@ dm_flush_map (const char * mapname)
249 if (dm_type(mapname, TGT_MPATH) <= 0)
250 return 0; /* nothing to do */
252 - if (dm_remove_partmaps(mapname))
253 + if (dm_remove_partmaps(mapname, need_sync))
256 if (dm_get_opencount(mapname)) {
257 @@ -547,7 +554,7 @@ dm_flush_map (const char * mapname)
261 - r = dm_simplecmd_flush(DM_DEVICE_REMOVE, mapname);
262 + r = dm_simplecmd_flush(DM_DEVICE_REMOVE, mapname, need_sync);
265 condlog(4, "multipath map %s removed", mapname);
266 @@ -883,7 +890,7 @@ bad:
270 -dm_remove_partmaps (const char * mapname)
271 +dm_remove_partmaps (const char * mapname, int need_sync)
274 struct dm_names *names;
275 @@ -946,7 +953,7 @@ dm_remove_partmaps (const char * mapname
277 condlog(4, "partition map %s removed",
279 - dm_simplecmd_flush(DM_DEVICE_REMOVE, names->name);
280 + dm_simplecmd_flush(DM_DEVICE_REMOVE, names->name, need_sync);
284 @@ -1102,6 +1109,8 @@ dm_rename (char * old, char * new)
286 dm_task_no_open_count(dmt);
288 + if (!dm_task_set_cookie(dmt, &conf->cookie, 0))
290 if (!dm_task_run(dmt))
293 Index: multipath-tools/libmultipath/devmapper.h
294 ===================================================================
295 --- multipath-tools.orig/libmultipath/devmapper.h
296 +++ multipath-tools/libmultipath/devmapper.h
300 int dm_prereq (void);
301 -int dm_simplecmd_flush (int, const char *);
302 +int dm_simplecmd_flush (int, const char *, int);
303 int dm_simplecmd_noflush (int, const char *);
304 int dm_addmap_create (struct multipath *mpp);
305 int dm_addmap_create_ro (struct multipath *mpp);
306 @@ -18,7 +18,9 @@ int dm_map_present (const char *);
307 int dm_get_map(char *, unsigned long long *, char *);
308 int dm_get_status(char *, char *);
309 int dm_type(const char *, char *);
310 -int dm_flush_map (const char *);
311 +int _dm_flush_map (const char *, int);
312 +#define dm_flush_map(mapname) _dm_flush_map(mapname, 1)
313 +#define dm_flush_map_nosync(mapname) _dm_flush_map(mapname, 0)
314 int dm_flush_maps (void);
315 int dm_fail_path(char * mapname, char * path);
316 int dm_reinstate_path(char * mapname, char * path);
317 @@ -31,7 +33,7 @@ int dm_get_maps (vector mp);
318 int dm_geteventnr (char *name);
319 int dm_get_minor (char *name);
320 char * dm_mapname(int major, int minor);
321 -int dm_remove_partmaps (const char * mapname);
322 +int dm_remove_partmaps (const char * mapname, int need_sync);
323 int dm_get_uuid(char *name, char *uuid);
324 int dm_get_info (char * mapname, struct dm_info ** dmi);
325 int dm_rename (char * old, char * new);
326 Index: multipath-tools/multipath/main.c
327 ===================================================================
328 --- multipath-tools.orig/multipath/main.c
329 +++ multipath-tools/multipath/main.c
330 @@ -454,6 +454,7 @@ main (int argc, char *argv[])
331 condlog(3, "restart multipath configuration process");
334 + dm_udev_wait(conf->cookie);
338 Index: multipath-tools/multipathd/main.c
339 ===================================================================
340 --- multipath-tools.orig/multipathd/main.c
341 +++ multipath-tools/multipathd/main.c
342 @@ -1396,6 +1396,7 @@ child (void * param)
346 + dm_udev_set_sync_support(0);
348 * fetch and configure both paths and multipaths
350 Index: multipath-tools/libmultipath/configure.c
351 ===================================================================
352 --- multipath-tools.orig/libmultipath/configure.c
353 +++ multipath-tools/libmultipath/configure.c
354 @@ -373,7 +373,7 @@ domap (struct multipath * mpp)
356 r = dm_addmap_reload_ro(mpp);
358 - r = dm_simplecmd_flush(DM_DEVICE_RESUME, mpp->alias);
359 + r = dm_simplecmd_flush(DM_DEVICE_RESUME, mpp->alias, 1);