|
|
4ae388 |
---
|
|
|
4ae388 |
kpartx/devmapper.c | 17 +++++++++++++--
|
|
|
4ae388 |
kpartx/devmapper.h | 2 -
|
|
|
4ae388 |
kpartx/kpartx.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++---
|
|
|
4ae388 |
3 files changed, 69 insertions(+), 7 deletions(-)
|
|
|
4ae388 |
|
|
|
4ae388 |
Index: multipath-tools-130222/kpartx/devmapper.c
|
|
|
4ae388 |
===================================================================
|
|
|
4ae388 |
--- multipath-tools-130222.orig/kpartx/devmapper.c
|
|
|
4ae388 |
+++ multipath-tools-130222/kpartx/devmapper.c
|
|
|
4ae388 |
@@ -140,12 +140,16 @@ addout:
|
|
|
4ae388 |
}
|
|
|
4ae388 |
|
|
|
4ae388 |
extern int
|
|
|
4ae388 |
-dm_map_present (char * str)
|
|
|
4ae388 |
+dm_map_present (char * str, char **uuid)
|
|
|
4ae388 |
{
|
|
|
4ae388 |
int r = 0;
|
|
|
4ae388 |
struct dm_task *dmt;
|
|
|
4ae388 |
+ const char *uuidtmp;
|
|
|
4ae388 |
struct dm_info info;
|
|
|
4ae388 |
|
|
|
4ae388 |
+ if (uuid)
|
|
|
4ae388 |
+ *uuid = NULL;
|
|
|
4ae388 |
+
|
|
|
4ae388 |
if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
|
|
|
4ae388 |
return 0;
|
|
|
4ae388 |
|
|
|
4ae388 |
@@ -160,8 +164,15 @@ dm_map_present (char * str)
|
|
|
4ae388 |
if (!dm_task_get_info(dmt, &info))
|
|
|
4ae388 |
goto out;
|
|
|
4ae388 |
|
|
|
4ae388 |
- if (info.exists)
|
|
|
4ae388 |
- r = 1;
|
|
|
4ae388 |
+ if (!info.exists)
|
|
|
4ae388 |
+ goto out;
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+ r = 1;
|
|
|
4ae388 |
+ if (uuid) {
|
|
|
4ae388 |
+ uuidtmp = dm_task_get_uuid(dmt);
|
|
|
4ae388 |
+ if (uuidtmp && strlen(uuidtmp))
|
|
|
4ae388 |
+ *uuid = strdup(uuidtmp);
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
out:
|
|
|
4ae388 |
dm_task_destroy(dmt);
|
|
|
4ae388 |
return r;
|
|
|
4ae388 |
Index: multipath-tools-130222/kpartx/devmapper.h
|
|
|
4ae388 |
===================================================================
|
|
|
4ae388 |
--- multipath-tools-130222.orig/kpartx/devmapper.h
|
|
|
4ae388 |
+++ multipath-tools-130222/kpartx/devmapper.h
|
|
|
4ae388 |
@@ -14,7 +14,7 @@ int dm_prereq (char *, int, int, int);
|
|
|
4ae388 |
int dm_simplecmd (int, const char *, int, uint32_t *, uint16_t);
|
|
|
4ae388 |
int dm_addmap (int, const char *, const char *, const char *, uint64_t,
|
|
|
4ae388 |
int, const char *, int, mode_t, uid_t, gid_t, uint32_t *);
|
|
|
4ae388 |
-int dm_map_present (char *);
|
|
|
4ae388 |
+int dm_map_present (char *, char **);
|
|
|
4ae388 |
char * dm_mapname(int major, int minor);
|
|
|
4ae388 |
dev_t dm_get_first_dep(char *devname);
|
|
|
4ae388 |
char * dm_mapuuid(int major, int minor);
|
|
|
4ae388 |
Index: multipath-tools-130222/kpartx/kpartx.c
|
|
|
4ae388 |
===================================================================
|
|
|
4ae388 |
--- multipath-tools-130222.orig/kpartx/kpartx.c
|
|
|
4ae388 |
+++ multipath-tools-130222/kpartx/kpartx.c
|
|
|
4ae388 |
@@ -191,6 +191,21 @@ get_hotplug_device(void)
|
|
|
4ae388 |
return device;
|
|
|
4ae388 |
}
|
|
|
4ae388 |
|
|
|
4ae388 |
+static int
|
|
|
4ae388 |
+check_uuid(char *uuid, char *part_uuid, char **err_msg) {
|
|
|
4ae388 |
+ char *map_uuid = strchr(part_uuid, '-');
|
|
|
4ae388 |
+ if (!map_uuid || strncmp(part_uuid, "part", 4) != 0) {
|
|
|
4ae388 |
+ *err_msg = "not a kpartx partition";
|
|
|
4ae388 |
+ return -1;
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+ map_uuid++;
|
|
|
4ae388 |
+ if (strcmp(uuid, map_uuid) != 0) {
|
|
|
4ae388 |
+ *err_msg = "a partition of a different device";
|
|
|
4ae388 |
+ return -1;
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+ return 0;
|
|
|
4ae388 |
+}
|
|
|
4ae388 |
+
|
|
|
4ae388 |
int
|
|
|
4ae388 |
main(int argc, char **argv){
|
|
|
4ae388 |
int i, j, m, n, op, off, arg, ro=0;
|
|
|
4ae388 |
@@ -410,6 +425,8 @@ main(int argc, char **argv){
|
|
|
4ae388 |
|
|
|
4ae388 |
case DELETE:
|
|
|
4ae388 |
for (j = MAXSLICES-1; j >= 0; j--) {
|
|
|
4ae388 |
+ char *part_uuid, *reason;
|
|
|
4ae388 |
+
|
|
|
4ae388 |
if (safe_sprintf(partname, "%s%s%d",
|
|
|
4ae388 |
mapname, delim, j+1)) {
|
|
|
4ae388 |
fprintf(stderr, "partname too small\n");
|
|
|
4ae388 |
@@ -417,9 +434,18 @@ main(int argc, char **argv){
|
|
|
4ae388 |
}
|
|
|
4ae388 |
strip_slash(partname);
|
|
|
4ae388 |
|
|
|
4ae388 |
- if (!dm_map_present(partname))
|
|
|
4ae388 |
+ if (!dm_map_present(partname, &part_uuid))
|
|
|
4ae388 |
continue;
|
|
|
4ae388 |
|
|
|
4ae388 |
+ if (part_uuid && uuid) {
|
|
|
4ae388 |
+ if (check_uuid(uuid, part_uuid, &reason) != 0) {
|
|
|
4ae388 |
+ fprintf(stderr, "%s is %s. Not removing\n", partname, reason);
|
|
|
4ae388 |
+ free(part_uuid);
|
|
|
4ae388 |
+ continue;
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+ free(part_uuid);
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+
|
|
|
4ae388 |
if (!dm_simplecmd(DM_DEVICE_REMOVE, partname,
|
|
|
4ae388 |
0, &cookie, 0)) {
|
|
|
4ae388 |
r++;
|
|
|
4ae388 |
@@ -444,6 +470,8 @@ main(int argc, char **argv){
|
|
|
4ae388 |
case UPDATE:
|
|
|
4ae388 |
/* ADD and UPDATE share the same code that adds new partitions. */
|
|
|
4ae388 |
for (j = 0; j < n; j++) {
|
|
|
4ae388 |
+ char *part_uuid, *reason;
|
|
|
4ae388 |
+
|
|
|
4ae388 |
if (slices[j].size == 0)
|
|
|
4ae388 |
continue;
|
|
|
4ae388 |
|
|
|
4ae388 |
@@ -460,9 +488,19 @@ main(int argc, char **argv){
|
|
|
4ae388 |
exit(1);
|
|
|
4ae388 |
}
|
|
|
4ae388 |
|
|
|
4ae388 |
- op = (dm_map_present(partname) ?
|
|
|
4ae388 |
+ op = (dm_map_present(partname, &part_uuid) ?
|
|
|
4ae388 |
DM_DEVICE_RELOAD : DM_DEVICE_CREATE);
|
|
|
4ae388 |
|
|
|
4ae388 |
+ if (part_uuid && uuid) {
|
|
|
4ae388 |
+ if (check_uuid(uuid, part_uuid, &reason) != 0) {
|
|
|
4ae388 |
+ fprintf(stderr, "%s is already in use, and %s\n", partname, reason);
|
|
|
4ae388 |
+ r++;
|
|
|
4ae388 |
+ free(part_uuid);
|
|
|
4ae388 |
+ continue;
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+ free(part_uuid);
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+
|
|
|
4ae388 |
if (!dm_addmap(op, partname, DM_TARGET, params,
|
|
|
4ae388 |
slices[j].size, ro, uuid, j+1,
|
|
|
4ae388 |
buf.st_mode & 0777, buf.st_uid,
|
|
|
4ae388 |
@@ -470,6 +508,7 @@ main(int argc, char **argv){
|
|
|
4ae388 |
fprintf(stderr, "create/reload failed on %s\n",
|
|
|
4ae388 |
partname);
|
|
|
4ae388 |
r++;
|
|
|
4ae388 |
+ continue;
|
|
|
4ae388 |
}
|
|
|
4ae388 |
if (op == DM_DEVICE_RELOAD &&
|
|
|
4ae388 |
!dm_simplecmd(DM_DEVICE_RESUME, partname,
|
|
|
4ae388 |
@@ -477,6 +516,7 @@ main(int argc, char **argv){
|
|
|
4ae388 |
fprintf(stderr, "resume failed on %s\n",
|
|
|
4ae388 |
partname);
|
|
|
4ae388 |
r++;
|
|
|
4ae388 |
+ continue;
|
|
|
4ae388 |
}
|
|
|
4ae388 |
dm_devn(partname, &slices[j].major,
|
|
|
4ae388 |
&slices[j].minor);
|
|
|
4ae388 |
@@ -494,6 +534,7 @@ main(int argc, char **argv){
|
|
|
4ae388 |
}
|
|
|
4ae388 |
|
|
|
4ae388 |
for (j = MAXSLICES-1; j >= 0; j--) {
|
|
|
4ae388 |
+ char *part_uuid, *reason;
|
|
|
4ae388 |
if (safe_sprintf(partname, "%s%s%d",
|
|
|
4ae388 |
mapname, delim, j+1)) {
|
|
|
4ae388 |
fprintf(stderr, "partname too small\n");
|
|
|
4ae388 |
@@ -501,9 +542,19 @@ main(int argc, char **argv){
|
|
|
4ae388 |
}
|
|
|
4ae388 |
strip_slash(partname);
|
|
|
4ae388 |
|
|
|
4ae388 |
- if (slices[j].size || !dm_map_present(partname))
|
|
|
4ae388 |
+ if (slices[j].size ||
|
|
|
4ae388 |
+ !dm_map_present(partname, &part_uuid))
|
|
|
4ae388 |
continue;
|
|
|
4ae388 |
|
|
|
4ae388 |
+ if (part_uuid && uuid) {
|
|
|
4ae388 |
+ if (check_uuid(uuid, part_uuid, &reason) != 0) {
|
|
|
4ae388 |
+ fprintf(stderr, "%s is %s. Not removing\n", partname, reason);
|
|
|
4ae388 |
+ free(part_uuid);
|
|
|
4ae388 |
+ continue;
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+ free(part_uuid);
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+
|
|
|
4ae388 |
if (!dm_simplecmd(DM_DEVICE_REMOVE,
|
|
|
4ae388 |
partname, 1, &cookie, 0)) {
|
|
|
4ae388 |
r++;
|