}
extern int
-dm_simplecmd (int task, const char *name, int no_flush) {
+dm_simplecmd (int task, const char *name, int no_flush, uint32_t *cookie) {
int r = 0;
+ int udev_wait_flag = (task == DM_DEVICE_RESUME ||
+ task == DM_DEVICE_REMOVE);
struct dm_task *dmt;
if (!(dmt = dm_task_create(task)))
if (no_flush)
dm_task_no_flush(dmt);
+ if (udev_wait_flag && !dm_task_set_cookie(dmt, cookie, 0))
+ goto out;
r = dm_task_run(dmt);
out:
extern int
dm_addmap (int task, const char *name, const char *target,
const char *params, uint64_t size, const char *uuid, int part,
- mode_t mode, uid_t uid, gid_t gid) {
+ mode_t mode, uid_t uid, gid_t gid, uint32_t *cookie) {
int r = 0;
struct dm_task *dmt;
char *prefixed_uuid = NULL;
dm_task_no_open_count(dmt);
+ if (task == DM_DEVICE_CREATE && !dm_task_set_cookie(dmt, cookie, 0))
+ goto addout;
r = dm_task_run (dmt);
addout:
#define MKDEV(ma,mi) ((mi & 0xff) | (ma << 8) | ((mi & ~0xff) << 12))
int dm_prereq (char *, int, int, int);
-int dm_simplecmd (int, const char *, int);
+int dm_simplecmd (int, const char *, int, uint32_t *);
int dm_addmap (int, const char *, const char *, const char *, uint64_t,
- const char *, int, mode_t, uid_t, gid_t);
+ const char *, int, mode_t, uid_t, gid_t, uint32_t *);
int dm_map_present (char *);
char * dm_mapname(int major, int minor);
dev_t dm_get_first_dep(char *devname);
addpts("sun", read_sun_pt);
}
-static char short_opts[] = "ladgvp:t:";
+static char short_opts[] = "ladgvp:t:s";
/* Used in gpt.c */
int force_gpt=0;
printf("\t-p set device name-partition number delimiter\n");
printf("\t-g force GUID partition table (GPT)\n");
printf("\t-v verbose\n");
+ printf("\t-s sync mode. Don't return until the partitions are created\n");
return 1;
}
int loopro = 0;
int hotplug = 0;
int loopcreated = 0;
+ int sync = 0;
struct stat buf;
+ uint32_t cookie = 0;
initpts();
init_crc32();
case 'd':
what = DELETE;
break;
+ case 's':
+ sync = 1;
+ break;
default:
usage();
exit(1);
}
+ if (!sync)
+ dm_udev_set_sync_support(0);
+
if (dm_prereq(DM_TARGET, 0, 0, 0) && (what == ADD || what == DELETE)) {
fprintf(stderr, "device mapper prerequisites not met\n");
exit(1);
if (!slices[j].size || !dm_map_present(partname))
continue;
- if (!dm_simplecmd(DM_DEVICE_REMOVE,
- partname, 0)) {
+ if (!dm_simplecmd(DM_DEVICE_REMOVE, partname,
+ 0, &cookie)) {
r++;
continue;
}
if (!dm_addmap(op, partname, DM_TARGET, params,
slices[j].size, uuid, j+1,
buf.st_mode & 0777, buf.st_uid,
- buf.st_gid)) {
+ buf.st_gid, &cookie)) {
fprintf(stderr, "create/reload failed on %s\n",
partname);
r++;
}
if (op == DM_DEVICE_RELOAD &&
- !dm_simplecmd(DM_DEVICE_RESUME,
- partname, 1)) {
+ !dm_simplecmd(DM_DEVICE_RESUME, partname,
+ 1, &cookie)) {
fprintf(stderr, "resume failed on %s\n",
partname);
r++;
dm_addmap(op, partname, DM_TARGET, params,
slices[j].size, uuid, j+1,
buf.st_mode & 0777,
- buf.st_uid, buf.st_gid);
+ buf.st_uid, buf.st_gid,
+ &cookie);
if (op == DM_DEVICE_RELOAD)
dm_simplecmd(DM_DEVICE_RESUME,
- partname, 1);
+ partname, 1,
+ &cookie);
dm_devn(partname, &slices[j].major,
&slices[j].minor);
if (n > 0)
break;
}
+ dm_udev_wait(cookie);
dm_lib_release();
dm_lib_exit();
#define _CONFIG_H
#include <sys/types.h>
+#include <stdint.h>
#define ORIGIN_DEFAULT 0
#define ORIGIN_CONFIG 1
uid_t uid;
gid_t gid;
mode_t mode;
+ uint32_t cookie;
char * dev;
char * sysfs_dir;
if (!r)
r = dm_addmap_reload_ro(mpp);
if (r)
- r = dm_simplecmd_flush(DM_DEVICE_RESUME, mpp->alias);
+ r = dm_simplecmd_flush(DM_DEVICE_RESUME, mpp->alias, 1);
break;
case ACT_RENAME:
{
char version[64];
int v[3];
- int minv[3] = {1, 2, 8};
+ int minv[3] = {1, 2, 38};
dm_get_library_version(version, sizeof(version));
condlog(3, "libdevmapper version %s", version);
}
static int
-dm_simplecmd (int task, const char *name, int no_flush) {
+dm_simplecmd (int task, const char *name, int no_flush, int need_sync) {
int r = 0;
+ int udev_wait_flag = (need_sync && (task == DM_DEVICE_RESUME ||
+ task == DM_DEVICE_REMOVE));
struct dm_task *dmt;
if (!(dmt = dm_task_create (task)))
dm_task_no_flush(dmt); /* for DM_DEVICE_SUSPEND/RESUME */
#endif
+ if (udev_wait_flag && !dm_task_set_cookie(dmt, &conf->cookie, 0))
+ goto out;
r = dm_task_run (dmt);
out:
}
extern int
-dm_simplecmd_flush (int task, const char *name) {
- return dm_simplecmd(task, name, 0);
+dm_simplecmd_flush (int task, const char *name, int needsync) {
+ return dm_simplecmd(task, name, 0, needsync);
}
extern int
dm_simplecmd_noflush (int task, const char *name) {
- return dm_simplecmd(task, name, 1);
+ return dm_simplecmd(task, name, 1, 1);
}
extern int
dm_task_no_open_count(dmt);
+ if (task == DM_DEVICE_CREATE &&
+ !dm_task_set_cookie(dmt, &conf->cookie, 0))
+ goto freeout;
r = dm_task_run (dmt);
freeout:
if (!r && dm_map_present(mpp->alias)) {
condlog(3, "%s: failed to load map (a path might be in use)",
mpp->alias);
- dm_flush_map(mpp->alias);
+ dm_flush_map_nosync(mpp->alias);
}
return r;
}
}
extern int
-dm_flush_map (const char * mapname)
+_dm_flush_map (const char * mapname, int need_sync)
{
int r;
if (dm_type(mapname, TGT_MPATH) <= 0)
return 0; /* nothing to do */
- if (dm_remove_partmaps(mapname))
+ if (dm_remove_partmaps(mapname, need_sync))
return 1;
if (dm_get_opencount(mapname)) {
return 1;
}
- r = dm_simplecmd_flush(DM_DEVICE_REMOVE, mapname);
+ r = dm_simplecmd_flush(DM_DEVICE_REMOVE, mapname, need_sync);
if (r) {
condlog(4, "multipath map %s removed", mapname);
}
int
-dm_remove_partmaps (const char * mapname)
+dm_remove_partmaps (const char * mapname, int need_sync)
{
struct dm_task *dmt;
struct dm_names *names;
*/
condlog(4, "partition map %s removed",
names->name);
- dm_simplecmd_flush(DM_DEVICE_REMOVE, names->name);
+ dm_simplecmd_flush(DM_DEVICE_REMOVE, names->name, need_sync);
}
next = names->next;
dm_task_no_open_count(dmt);
+ if (!dm_task_set_cookie(dmt, &conf->cookie, 0))
+ goto out;
if (!dm_task_run(dmt))
goto out;
void dm_init(void);
int dm_prereq (void);
-int dm_simplecmd_flush (int, const char *);
+int dm_simplecmd_flush (int, const char *, int);
int dm_simplecmd_noflush (int, const char *);
int dm_addmap_create (struct multipath *mpp);
int dm_addmap_create_ro (struct multipath *mpp);
int dm_get_map(char *, unsigned long long *, char *);
int dm_get_status(char *, char *);
int dm_type(const char *, char *);
-int dm_flush_map (const char *);
+int _dm_flush_map (const char *, int);
+#define dm_flush_map(mapname) _dm_flush_map(mapname, 1)
+#define dm_flush_map_nosync(mapname) _dm_flush_map(mapname, 0)
int dm_flush_maps (void);
int dm_fail_path(char * mapname, char * path);
int dm_reinstate_path(char * mapname, char * path);
int dm_geteventnr (char *name);
int dm_get_minor (char *name);
char * dm_mapname(int major, int minor);
-int dm_remove_partmaps (const char * mapname);
+int dm_remove_partmaps (const char * mapname, int need_sync);
int dm_get_uuid(char *name, char *uuid);
int dm_get_info (char * mapname, struct dm_info ** dmi);
int dm_rename (char * old, char * new);
condlog(3, "restart multipath configuration process");
out:
+ dm_udev_wait(conf->cookie);
sysfs_cleanup();
dm_lib_release();
exit(1);
}
conf->daemon = 1;
+ dm_udev_set_sync_support(0);
/*
* fetch and configure both paths and multipaths
*/