]>
Commit | Line | Data |
---|---|---|
dc01aad8 SS |
1 | --- |
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 +++++--- | |
9 | multipath/main.c | 1 + | |
10 | multipathd/main.c | 1 + | |
11 | 9 files changed, 55 insertions(+), 24 deletions(-) | |
12 | ||
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 | |
18 | } | |
19 | ||
20 | extern 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) { | |
23 | int r = 0; | |
24 | + int udev_wait_flag = (task == DM_DEVICE_RESUME || | |
25 | + task == DM_DEVICE_REMOVE); | |
26 | struct dm_task *dmt; | |
27 | ||
28 | if (!(dmt = dm_task_create(task))) | |
29 | @@ -68,6 +70,8 @@ dm_simplecmd (int task, const char *name | |
30 | if (no_flush) | |
31 | dm_task_no_flush(dmt); | |
32 | ||
33 | + if (udev_wait_flag && !dm_task_set_cookie(dmt, cookie, 0)) | |
34 | + goto out; | |
35 | r = dm_task_run(dmt); | |
36 | ||
37 | out: | |
38 | @@ -78,7 +82,7 @@ dm_simplecmd (int task, const char *name | |
39 | extern int | |
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) { | |
44 | int r = 0; | |
45 | struct dm_task *dmt; | |
46 | char *prefixed_uuid = NULL; | |
47 | @@ -113,6 +117,8 @@ dm_addmap (int task, const char *name, c | |
48 | ||
49 | dm_task_no_open_count(dmt); | |
50 | ||
51 | + if (task == DM_DEVICE_CREATE && !dm_task_set_cookie(dmt, cookie, 0)) | |
52 | + goto addout; | |
53 | r = dm_task_run (dmt); | |
54 | ||
55 | addout: | |
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); | |
62 | } | |
63 | ||
64 | -static char short_opts[] = "ladgvp:t:"; | |
65 | +static char short_opts[] = "ladgvp:t:s"; | |
66 | ||
67 | /* Used in gpt.c */ | |
68 | int force_gpt=0; | |
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"); | |
74 | return 1; | |
75 | } | |
76 | ||
77 | @@ -198,7 +199,9 @@ main(int argc, char **argv){ | |
78 | int loopro = 0; | |
79 | int hotplug = 0; | |
80 | int loopcreated = 0; | |
81 | + int sync = 0; | |
82 | struct stat buf; | |
83 | + uint32_t cookie = 0; | |
84 | ||
85 | initpts(); | |
86 | init_crc32(); | |
87 | @@ -251,11 +254,17 @@ main(int argc, char **argv){ | |
88 | case 'd': | |
89 | what = DELETE; | |
90 | break; | |
91 | + case 's': | |
92 | + sync = 1; | |
93 | + break; | |
94 | default: | |
95 | usage(); | |
96 | exit(1); | |
97 | } | |
98 | ||
99 | + if (!sync) | |
100 | + dm_udev_set_sync_support(0); | |
101 | + | |
102 | if (dm_prereq(DM_TARGET, 0, 0, 0) && (what == ADD || what == DELETE)) { | |
103 | fprintf(stderr, "device mapper prerequisites not met\n"); | |
104 | exit(1); | |
105 | @@ -413,8 +422,8 @@ main(int argc, char **argv){ | |
106 | if (!slices[j].size || !dm_map_present(partname)) | |
107 | continue; | |
108 | ||
109 | - if (!dm_simplecmd(DM_DEVICE_REMOVE, | |
110 | - partname, 0)) { | |
111 | + if (!dm_simplecmd(DM_DEVICE_REMOVE, partname, | |
112 | + 0, &cookie)) { | |
113 | r++; | |
114 | continue; | |
115 | } | |
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, | |
120 | - buf.st_gid)) { | |
121 | + buf.st_gid, &cookie)) { | |
122 | fprintf(stderr, "create/reload failed on %s\n", | |
123 | partname); | |
124 | r++; | |
125 | } | |
126 | if (op == DM_DEVICE_RELOAD && | |
127 | - !dm_simplecmd(DM_DEVICE_RESUME, | |
128 | - partname, 1)) { | |
129 | + !dm_simplecmd(DM_DEVICE_RESUME, partname, | |
130 | + 1, &cookie)) { | |
131 | fprintf(stderr, "resume failed on %s\n", | |
132 | partname); | |
133 | r++; | |
134 | @@ -557,6 +566,7 @@ main(int argc, char **argv){ | |
135 | if (n > 0) | |
136 | break; | |
137 | } | |
138 | + dm_udev_wait(cookie); | |
139 | dm_lib_release(); | |
140 | dm_lib_exit(); | |
141 | ||
142 | Index: multipath-tools/kpartx/devmapper.h | |
143 | =================================================================== | |
144 | --- multipath-tools.orig/kpartx/devmapper.h | |
145 | +++ multipath-tools/kpartx/devmapper.h | |
146 | @@ -3,9 +3,9 @@ | |
147 | #define MKDEV(ma,mi) ((mi & 0xff) | (ma << 8) | ((mi & ~0xff) << 12)) | |
148 | ||
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 | |
162 | @@ -2,6 +2,7 @@ | |
163 | #define _CONFIG_H | |
164 | ||
165 | #include <sys/types.h> | |
166 | +#include <stdint.h> | |
167 | ||
168 | #define ORIGIN_DEFAULT 0 | |
169 | #define ORIGIN_CONFIG 1 | |
170 | @@ -84,6 +85,7 @@ struct config { | |
171 | uid_t uid; | |
172 | gid_t gid; | |
173 | mode_t mode; | |
174 | + uint32_t cookie; | |
175 | ||
176 | char * dev; | |
177 | char * sysfs_dir; | |
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) | |
183 | } | |
184 | ||
185 | static int | |
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) { | |
188 | int r = 0; | |
189 | + int udev_wait_flag = (need_sync && (task == DM_DEVICE_RESUME || | |
190 | + task == DM_DEVICE_REMOVE)); | |
191 | struct dm_task *dmt; | |
192 | ||
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 */ | |
196 | #endif | |
197 | ||
198 | + if (udev_wait_flag && !dm_task_set_cookie(dmt, &conf->cookie, 0)) | |
199 | + goto out; | |
200 | r = dm_task_run (dmt); | |
201 | ||
202 | out: | |
203 | @@ -174,13 +178,13 @@ dm_simplecmd (int task, const char *name | |
204 | } | |
205 | ||
206 | extern int | |
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); | |
211 | } | |
212 | ||
213 | extern int | |
214 | dm_simplecmd_noflush (int task, const char *name) { | |
215 | - return dm_simplecmd(task, name, 1); | |
216 | + return dm_simplecmd(task, name, 1, 1); | |
217 | } | |
218 | ||
219 | extern int | |
220 | @@ -226,6 +230,9 @@ dm_addmap (int task, const char *target, | |
221 | ||
222 | dm_task_no_open_count(dmt); | |
223 | ||
224 | + if (task == DM_DEVICE_CREATE && | |
225 | + !dm_task_set_cookie(dmt, &conf->cookie, 0)) | |
226 | + goto freeout; | |
227 | r = dm_task_run (dmt); | |
228 | ||
229 | freeout: | |
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)", | |
233 | mpp->alias); | |
234 | - dm_flush_map(mpp->alias); | |
235 | + dm_flush_map_nosync(mpp->alias); | |
236 | } | |
237 | return r; | |
238 | } | |
239 | @@ -529,7 +536,7 @@ out: | |
240 | } | |
241 | ||
242 | extern int | |
243 | -dm_flush_map (const char * mapname) | |
244 | +_dm_flush_map (const char * mapname, int need_sync) | |
245 | { | |
246 | int r; | |
247 | ||
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 */ | |
251 | ||
252 | - if (dm_remove_partmaps(mapname)) | |
253 | + if (dm_remove_partmaps(mapname, need_sync)) | |
254 | return 1; | |
255 | ||
256 | if (dm_get_opencount(mapname)) { | |
257 | @@ -547,7 +554,7 @@ dm_flush_map (const char * mapname) | |
258 | return 1; | |
259 | } | |
260 | ||
261 | - r = dm_simplecmd_flush(DM_DEVICE_REMOVE, mapname); | |
262 | + r = dm_simplecmd_flush(DM_DEVICE_REMOVE, mapname, need_sync); | |
263 | ||
264 | if (r) { | |
265 | condlog(4, "multipath map %s removed", mapname); | |
266 | @@ -883,7 +890,7 @@ bad: | |
267 | } | |
268 | ||
269 | int | |
270 | -dm_remove_partmaps (const char * mapname) | |
271 | +dm_remove_partmaps (const char * mapname, int need_sync) | |
272 | { | |
273 | struct dm_task *dmt; | |
274 | struct dm_names *names; | |
275 | @@ -946,7 +953,7 @@ dm_remove_partmaps (const char * mapname | |
276 | */ | |
277 | condlog(4, "partition map %s removed", | |
278 | names->name); | |
279 | - dm_simplecmd_flush(DM_DEVICE_REMOVE, names->name); | |
280 | + dm_simplecmd_flush(DM_DEVICE_REMOVE, names->name, need_sync); | |
281 | } | |
282 | ||
283 | next = names->next; | |
284 | @@ -1102,6 +1109,8 @@ dm_rename (char * old, char * new) | |
285 | ||
286 | dm_task_no_open_count(dmt); | |
287 | ||
288 | + if (!dm_task_set_cookie(dmt, &conf->cookie, 0)) | |
289 | + goto out; | |
290 | if (!dm_task_run(dmt)) | |
291 | goto out; | |
292 | ||
293 | Index: multipath-tools/libmultipath/devmapper.h | |
294 | =================================================================== | |
295 | --- multipath-tools.orig/libmultipath/devmapper.h | |
296 | +++ multipath-tools/libmultipath/devmapper.h | |
297 | @@ -8,7 +8,7 @@ | |
298 | ||
299 | void dm_init(void); | |
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"); | |
332 | ||
333 | out: | |
334 | + dm_udev_wait(conf->cookie); | |
335 | ||
336 | sysfs_cleanup(); | |
337 | dm_lib_release(); | |
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) | |
343 | exit(1); | |
344 | } | |
345 | conf->daemon = 1; | |
346 | + dm_udev_set_sync_support(0); | |
347 | /* | |
348 | * fetch and configure both paths and multipaths | |
349 | */ | |
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) | |
355 | if (!r) | |
356 | r = dm_addmap_reload_ro(mpp); | |
357 | if (r) | |
358 | - r = dm_simplecmd_flush(DM_DEVICE_RESUME, mpp->alias); | |
359 | + r = dm_simplecmd_flush(DM_DEVICE_RESUME, mpp->alias, 1); | |
360 | break; | |
361 | ||
362 | case ACT_RENAME: |