#include <libdevmapper.h>
#include <ctype.h>
#include <linux/kdev_t.h>
+#include <errno.h>
+
+#define UUID_PREFIX "part%d-"
+#define MAX_PREFIX_LEN 8
extern int
dm_prereq (char * str, int x, int y, int z)
extern int
dm_addmap (int task, const char *name, const char *target,
- const char *params, unsigned long size) {
+ const char *params, unsigned long size, const char *uuid, int part) {
int r = 0;
struct dm_task *dmt;
+ char *prefixed_uuid;
if (!(dmt = dm_task_create (task)))
return 0;
if (!dm_task_add_target (dmt, 0, size, target, params))
goto addout;
+ if (task == DM_DEVICE_CREATE && uuid) {
+ prefixed_uuid = malloc(MAX_PREFIX_LEN + strlen(uuid) + 1);
+ if (!prefixed_uuid) {
+ fprintf(stderr, "cannot create prefixed uuid : %s\n",
+ strerror(errno));
+ goto addout;
+ }
+ sprintf(prefixed_uuid, UUID_PREFIX "%s", part, uuid);
+ if (!dm_task_set_uuid(dmt, prefixed_uuid))
+ goto freeout;
+ }
+
dm_task_no_open_count(dmt);
r = dm_task_run (dmt);
+ freeout:
+ if (prefixed_uuid)
+ free(prefixed_uuid);
+
addout:
dm_task_destroy (dmt);
return r;
return ret;
}
+char *
+dm_mapuuid(int major, int minor)
+{
+ struct dm_task *dmt;
+ char *tmp, *uuid = NULL;
+
+ if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
+ return NULL;
+
+ dm_task_no_open_count(dmt);
+ dm_task_set_major(dmt, major);
+ dm_task_set_minor(dmt, minor);
+
+ if (!dm_task_run(dmt))
+ goto out;
+
+ tmp = dm_task_get_uuid(dmt);
+ if (tmp[0] != '\0')
+ uuid = strdup(tmp);
+out:
+ dm_task_destroy(dmt);
+ return uuid;
+}
int dm_prereq (char *, int, int, int);
int dm_simplecmd (int, const char *);
-int dm_addmap (int, const char *, const char *, const char *, unsigned long);
+int dm_addmap (int, const char *, const char *, const char *, unsigned long,
+ char *, int);
int dm_map_present (char *);
char * dm_mapname(int major, int minor);
dev_t dm_get_first_dep(char *devname);
+char * dm_mapuuid(int major, int minor);
char partname[PARTNAME_SIZE], params[PARTNAME_SIZE + 16];
char * loopdev = NULL;
char * delim = NULL;
+ char *uuid = NULL;
int loopro = 0;
int hotplug = 0;
struct stat buf;
}
if (S_ISREG (buf.st_mode)) {
- loopdev = malloc(LO_NAME_SIZE * sizeof(char));
-
- if (!loopdev)
- exit(1);
-
/* already looped file ? */
loopdev = find_loop_by_file(device);
}
off = find_devname_offset(device);
+
+ if (!loopdev)
+ uuid = dm_mapuuid((unsigned int)MAJOR(buf.st_rdev),
+ (unsigned int)MINOR(buf.st_rdev));
+ if (!uuid)
+ uuid = device + off;
+
fd = open(device, O_RDONLY);
if (fd == -1) {
DM_DEVICE_RELOAD : DM_DEVICE_CREATE);
dm_addmap(op, partname, DM_TARGET, params,
- slices[j].size);
+ slices[j].size, uuid, j+1);
if (op == DM_DEVICE_RELOAD)
dm_simplecmd(DM_DEVICE_RESUME,
#include <ctype.h>
#include <linux/kdev_t.h>
#include <unistd.h>
+#include <errno.h>
#include <checkers.h>
#define MAX_WAIT 5
#define LOOPS_PER_SEC 5
+#define UUID_PREFIX "mpath-"
+#define UUID_PREFIX_LEN 6
+
+
static void
dm_dummy_log (int level, const char *file, int line, const char *f, ...)
{
const char *params, unsigned long long size, const char *uuid) {
int r = 0;
struct dm_task *dmt;
+ char *prefixed_uuid = NULL;
if (!(dmt = dm_task_create (task)))
return 0;
if (!dm_task_add_target (dmt, 0, size, target, params))
goto addout;
- if (uuid && !dm_task_set_uuid(dmt, uuid))
- goto addout;
+ if (uuid){
+ prefixed_uuid = MALLOC(UUID_PREFIX_LEN + strlen(uuid) + 1);
+ if (!prefixed_uuid) {
+ condlog(0, "cannot create prefixed uuid : %s\n",
+ strerror(errno));
+ goto addout;
+ }
+ sprintf(prefixed_uuid, UUID_PREFIX "%s", uuid);
+ if (!dm_task_set_uuid(dmt, prefixed_uuid))
+ goto freeout;
+ }
dm_task_no_open_count(dmt);
r = dm_task_run (dmt);
+ freeout:
+ if (prefixed_uuid)
+ free(prefixed_uuid);
+
addout:
dm_task_destroy (dmt);
return r;
goto uuidout;
uuidtmp = dm_task_get_uuid(dmt);
- if (uuidtmp)
- strcpy(uuid, uuidtmp);
+ if (uuidtmp) {
+ if (!strncmp(uuidtmp, UUID_PREFIX, UUID_PREFIX_LEN))
+ strcpy(uuid, uuidtmp + UUID_PREFIX_LEN);
+ else
+ strcpy(uuid, uuidtmp);
+ }
else
uuid[0] = '\0';