|
|
4ae388 |
---
|
|
|
4ae388 |
libmultipath/devmapper.c | 155 ++++++++++++++++++-----------------------------
|
|
|
4ae388 |
1 file changed, 61 insertions(+), 94 deletions(-)
|
|
|
4ae388 |
|
|
|
4ae388 |
Index: multipath-tools-130222/libmultipath/devmapper.c
|
|
|
4ae388 |
===================================================================
|
|
|
4ae388 |
--- multipath-tools-130222.orig/libmultipath/devmapper.c
|
|
|
4ae388 |
+++ multipath-tools-130222/libmultipath/devmapper.c
|
|
|
4ae388 |
@@ -1006,8 +1006,9 @@ bad:
|
|
|
4ae388 |
return NULL;
|
|
|
4ae388 |
}
|
|
|
4ae388 |
|
|
|
4ae388 |
-int
|
|
|
4ae388 |
-dm_remove_partmaps (const char * mapname, int need_sync)
|
|
|
4ae388 |
+static int
|
|
|
4ae388 |
+do_foreach_partmaps (const char * mapname, int (*partmap_func)(char *, void *),
|
|
|
4ae388 |
+ void *data)
|
|
|
4ae388 |
{
|
|
|
4ae388 |
struct dm_task *dmt;
|
|
|
4ae388 |
struct dm_names *names;
|
|
|
4ae388 |
@@ -1059,26 +1060,8 @@ dm_remove_partmaps (const char * mapname
|
|
|
4ae388 |
*/
|
|
|
4ae388 |
strstr(params, dev_t)
|
|
|
4ae388 |
) {
|
|
|
4ae388 |
- /*
|
|
|
4ae388 |
- * then it's a kpartx generated partition.
|
|
|
4ae388 |
- * remove it.
|
|
|
4ae388 |
- */
|
|
|
4ae388 |
- /*
|
|
|
4ae388 |
- * if the opencount is 0 maybe some other
|
|
|
4ae388 |
- * partitions depend on it.
|
|
|
4ae388 |
- */
|
|
|
4ae388 |
- if (dm_get_opencount(names->name)) {
|
|
|
4ae388 |
- dm_remove_partmaps(names->name, need_sync);
|
|
|
4ae388 |
- if (dm_get_opencount(names->name)) {
|
|
|
4ae388 |
- condlog(2, "%s: map in use",
|
|
|
4ae388 |
- names->name);
|
|
|
4ae388 |
- goto out;
|
|
|
4ae388 |
- }
|
|
|
4ae388 |
- }
|
|
|
4ae388 |
- condlog(4, "partition map %s removed",
|
|
|
4ae388 |
- names->name);
|
|
|
4ae388 |
- dm_simplecmd_flush(DM_DEVICE_REMOVE, names->name,
|
|
|
4ae388 |
- need_sync, 0);
|
|
|
4ae388 |
+ if (partmap_func(names->name, data) != 0)
|
|
|
4ae388 |
+ goto out;
|
|
|
4ae388 |
}
|
|
|
4ae388 |
|
|
|
4ae388 |
next = names->next;
|
|
|
4ae388 |
@@ -1091,6 +1074,35 @@ out:
|
|
|
4ae388 |
return r;
|
|
|
4ae388 |
}
|
|
|
4ae388 |
|
|
|
4ae388 |
+struct remove_data {
|
|
|
4ae388 |
+ int need_sync;
|
|
|
4ae388 |
+};
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+static int
|
|
|
4ae388 |
+remove_partmap(char *name, void *data)
|
|
|
4ae388 |
+{
|
|
|
4ae388 |
+ struct remove_data *rd = (struct remove_data *)data;
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+ if (dm_get_opencount(name)) {
|
|
|
4ae388 |
+ dm_remove_partmaps(name, rd->need_sync);
|
|
|
4ae388 |
+ if (dm_get_opencount(name)) {
|
|
|
4ae388 |
+ condlog(2, "%s: map in use", name);
|
|
|
4ae388 |
+ return 1;
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+ condlog(4, "partition map %s removed", name);
|
|
|
4ae388 |
+ dm_simplecmd_flush(DM_DEVICE_REMOVE, name,
|
|
|
4ae388 |
+ rd->need_sync, 0);
|
|
|
4ae388 |
+ return 0;
|
|
|
4ae388 |
+}
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+int
|
|
|
4ae388 |
+dm_remove_partmaps (const char * mapname, int need_sync)
|
|
|
4ae388 |
+{
|
|
|
4ae388 |
+ struct remove_data rd = { need_sync };
|
|
|
4ae388 |
+ return do_foreach_partmaps(mapname, remove_partmap, &rd);
|
|
|
4ae388 |
+}
|
|
|
4ae388 |
+
|
|
|
4ae388 |
static struct dm_info *
|
|
|
4ae388 |
alloc_dminfo (void)
|
|
|
4ae388 |
{
|
|
|
4ae388 |
@@ -1140,86 +1152,41 @@ out:
|
|
|
4ae388 |
return r;
|
|
|
4ae388 |
}
|
|
|
4ae388 |
|
|
|
4ae388 |
-int
|
|
|
4ae388 |
-dm_rename_partmaps (char * old, char * new)
|
|
|
4ae388 |
+struct rename_data {
|
|
|
4ae388 |
+ char *old;
|
|
|
4ae388 |
+ char *new;
|
|
|
4ae388 |
+ char *delim;
|
|
|
4ae388 |
+};
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+static int
|
|
|
4ae388 |
+rename_partmap (char *name, void *data)
|
|
|
4ae388 |
{
|
|
|
4ae388 |
- struct dm_task *dmt;
|
|
|
4ae388 |
- struct dm_names *names;
|
|
|
4ae388 |
- unsigned next = 0;
|
|
|
4ae388 |
char buff[PARAMS_SIZE];
|
|
|
4ae388 |
- unsigned long long size;
|
|
|
4ae388 |
- char dev_t[32];
|
|
|
4ae388 |
- int r = 1;
|
|
|
4ae388 |
int offset;
|
|
|
4ae388 |
- char *delim;
|
|
|
4ae388 |
-
|
|
|
4ae388 |
- if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
|
|
|
4ae388 |
- return 1;
|
|
|
4ae388 |
+ struct rename_data *rd = (struct rename_data *)data;
|
|
|
4ae388 |
|
|
|
4ae388 |
- dm_task_no_open_count(dmt);
|
|
|
4ae388 |
-
|
|
|
4ae388 |
- if (!dm_task_run(dmt))
|
|
|
4ae388 |
- goto out;
|
|
|
4ae388 |
-
|
|
|
4ae388 |
- if (!(names = dm_task_get_names(dmt)))
|
|
|
4ae388 |
- goto out;
|
|
|
4ae388 |
-
|
|
|
4ae388 |
- if (!names->dev) {
|
|
|
4ae388 |
- r = 0; /* this is perfectly valid */
|
|
|
4ae388 |
- goto out;
|
|
|
4ae388 |
- }
|
|
|
4ae388 |
+ if (strncmp(name, rd->old, strlen(rd->old)) != 0)
|
|
|
4ae388 |
+ return 0;
|
|
|
4ae388 |
+ for (offset = strlen(rd->old); name[offset] && !(isdigit(name[offset])); offset++); /* do nothing */
|
|
|
4ae388 |
+ snprintf(buff, PARAMS_SIZE, "%s%s%s", rd->new, rd->delim,
|
|
|
4ae388 |
+ name + offset);
|
|
|
4ae388 |
+ dm_rename(name, buff);
|
|
|
4ae388 |
+ condlog(4, "partition map %s renamed", name);
|
|
|
4ae388 |
+ return 0;
|
|
|
4ae388 |
+}
|
|
|
4ae388 |
|
|
|
4ae388 |
- if (dm_dev_t(old, &dev_t[0], 32))
|
|
|
4ae388 |
- goto out;
|
|
|
4ae388 |
+int
|
|
|
4ae388 |
+dm_rename_partmaps (char * old, char * new)
|
|
|
4ae388 |
+{
|
|
|
4ae388 |
+ struct rename_data rd;
|
|
|
4ae388 |
|
|
|
4ae388 |
+ rd.old = old;
|
|
|
4ae388 |
+ rd.new = new;
|
|
|
4ae388 |
if (isdigit(new[strlen(new)-1]))
|
|
|
4ae388 |
- delim = "p";
|
|
|
4ae388 |
+ rd.delim = "p";
|
|
|
4ae388 |
else
|
|
|
4ae388 |
- delim = "";
|
|
|
4ae388 |
-
|
|
|
4ae388 |
- do {
|
|
|
4ae388 |
- if (
|
|
|
4ae388 |
- /*
|
|
|
4ae388 |
- * if devmap target is "linear"
|
|
|
4ae388 |
- */
|
|
|
4ae388 |
- (dm_type(names->name, TGT_PART) > 0) &&
|
|
|
4ae388 |
-
|
|
|
4ae388 |
- /*
|
|
|
4ae388 |
- * and the multipath mapname and the part mapname start
|
|
|
4ae388 |
- * the same
|
|
|
4ae388 |
- */
|
|
|
4ae388 |
- !strncmp(names->name, old, strlen(old)) &&
|
|
|
4ae388 |
-
|
|
|
4ae388 |
- /*
|
|
|
4ae388 |
- * and we can fetch the map table from the kernel
|
|
|
4ae388 |
- */
|
|
|
4ae388 |
- !dm_get_map(names->name, &size, &buff[0]) &&
|
|
|
4ae388 |
-
|
|
|
4ae388 |
- /*
|
|
|
4ae388 |
- * and the table maps over the multipath map
|
|
|
4ae388 |
- */
|
|
|
4ae388 |
- strstr(buff, dev_t)
|
|
|
4ae388 |
- ) {
|
|
|
4ae388 |
- /*
|
|
|
4ae388 |
- * then it's a kpartx generated partition.
|
|
|
4ae388 |
- * Rename it.
|
|
|
4ae388 |
- */
|
|
|
4ae388 |
- for (offset = strlen(old); names->name[offset] && !(isdigit(names->name[offset])); offset++); /* do nothing */
|
|
|
4ae388 |
- snprintf(buff, PARAMS_SIZE, "%s%s%s",
|
|
|
4ae388 |
- new, delim, names->name + offset);
|
|
|
4ae388 |
- dm_rename(names->name, buff);
|
|
|
4ae388 |
- condlog(4, "partition map %s renamed",
|
|
|
4ae388 |
- names->name);
|
|
|
4ae388 |
- }
|
|
|
4ae388 |
-
|
|
|
4ae388 |
- next = names->next;
|
|
|
4ae388 |
- names = (void *) names + next;
|
|
|
4ae388 |
- } while (next);
|
|
|
4ae388 |
-
|
|
|
4ae388 |
- r = 0;
|
|
|
4ae388 |
-out:
|
|
|
4ae388 |
- dm_task_destroy (dmt);
|
|
|
4ae388 |
- return r;
|
|
|
4ae388 |
+ rd.delim = "";
|
|
|
4ae388 |
+ return do_foreach_partmaps(old, rename_partmap, &rd);
|
|
|
4ae388 |
}
|
|
|
4ae388 |
|
|
|
4ae388 |
int
|