Permalink
Browse files

wait for device creation; minor fixes

 * use the udev sync foo to make sure that nodes appear before
   continuing. This is particularly important when trying to create
   stacked volumes for the cascaded ciphers.

 * add a newline char to the "All Ok" printf.

 * don't mistakenly return that everything went ok in dm_setup when the
   only thing that went ok was the unrolling of changes after an error.
  • Loading branch information...
1 parent 793b877 commit ff87b18e058d08f2cbaf821a063421fd82e556a7 @bwalex committed Jul 20, 2011
Showing with 20 additions and 4 deletions.
  1. +20 −4 tcplay.c
View
@@ -794,7 +794,7 @@ map_volume(const char *map_name, const char *device, int sflag,
}
if (interactive)
- printf("All ok!");
+ printf("All ok!\n");
return 0;
}
@@ -836,11 +836,14 @@ dm_setup(const char *mapname, struct tcplay_info *info)
#if defined(__DragonFly__)
uint32_t status;
#endif
- int ret = 0;
+ int r, ret = 0;
int j;
off_t start, offset;
char dev[PATH_MAX];
char map[PATH_MAX];
+ uint32_t cookie;
+
+ dm_udev_set_sync_support(1);
if ((params = alloc_safe_mem(512)) == NULL) {
tc_log(1, "could not allocate safe parameters memory");
@@ -859,6 +862,9 @@ dm_setup(const char *mapname, struct tcplay_info *info)
for (j= 0; cipher_chain != NULL;
cipher_chain = cipher_chain->prev, j++) {
+
+ cookie = 0;
+
/* aes-cbc-essiv:sha256 7997f8af... 0 /dev/ad0s0a 8 */
/* iv off---^ block off--^ */
snprintf(params, 512, "%s %s %"PRIu64 " %s %"PRIu64,
@@ -928,26 +934,36 @@ dm_setup(const char *mapname, struct tcplay_info *info)
goto out;
}
+ if ((dm_task_set_cookie(dmt, &cookie, 0)) == 0) {
+ tc_log(1, "dm_task_set_cookie failed\n");
+ ret = -1;
+ goto out;
+ }
+
if ((dm_task_run(dmt)) == 0) {
+ dm_udev_wait(cookie);
tc_log(1, "dm_task_task_run failed\n");
ret = -1;
goto out;
}
if ((dm_task_get_info(dmt, &dmi)) == 0) {
+ dm_udev_wait(cookie);
tc_log(1, "dm_task_get info failed\n");
- /* XXX: probably do more than just erroring out... */
ret = -1;
goto out;
}
+ dm_udev_wait(cookie);
+
asprintf(&uu_stack[uu_stack_idx++], "%s", map);
offset = 0;
start = 0;
sprintf(dev, "/dev/mapper/%s.%d", mapname, j);
dm_task_destroy(dmt);
+ dm_task_update_nodes();
}
out:
@@ -962,7 +978,7 @@ dm_setup(const char *mapname, struct tcplay_info *info)
printf("Unrolling dm changes! j = %d (%s)\n", j-1,
uu_stack[j-1]);
#endif
- if ((ret = dm_remove_device(uu_stack[--j])) != 0) {
+ if ((r = dm_remove_device(uu_stack[--j])) != 0) {
tc_log(1, "Tried to unroll dm changes, "
"giving up.\n");
break;

0 comments on commit ff87b18

Please sign in to comment.