|
|
38852f |
---
|
|
|
38852f |
libmultipath/alias.c | 64 ++++++++++++++++++++++++++++++++++++++++++---
|
|
|
38852f |
libmultipath/alias.h | 2 +
|
|
|
38852f |
libmultipath/propsel.c | 32 +++++++++++++++-------
|
|
|
38852f |
libmultipath/structs_vec.c | 15 ++++++++++
|
|
|
38852f |
4 files changed, 100 insertions(+), 13 deletions(-)
|
|
|
38852f |
|
|
|
38852f |
Index: multipath-tools-130222/libmultipath/alias.c
|
|
|
38852f |
===================================================================
|
|
|
38852f |
--- multipath-tools-130222.orig/libmultipath/alias.c
|
|
|
38852f |
+++ multipath-tools-130222/libmultipath/alias.c
|
|
|
38852f |
@@ -145,7 +145,7 @@ lookup_binding(FILE *f, char *map_wwid,
|
|
|
38852f |
}
|
|
|
38852f |
|
|
|
38852f |
static int
|
|
|
38852f |
-rlookup_binding(FILE *f, char *buff, char *map_alias)
|
|
|
38852f |
+rlookup_binding(FILE *f, char *buff, char *map_alias, char *prefix)
|
|
|
38852f |
{
|
|
|
38852f |
char line[LINE_MAX];
|
|
|
38852f |
unsigned int line_nr = 0;
|
|
|
38852f |
@@ -164,7 +164,7 @@ rlookup_binding(FILE *f, char *buff, cha
|
|
|
38852f |
alias = strtok(line, " \t");
|
|
|
38852f |
if (!alias) /* blank line */
|
|
|
38852f |
continue;
|
|
|
38852f |
- curr_id = scan_devname(alias, NULL); /* TBD: Why this call? */
|
|
|
38852f |
+ curr_id = scan_devname(alias, prefix);
|
|
|
38852f |
if (curr_id >= id)
|
|
|
38852f |
id = curr_id + 1;
|
|
|
38852f |
wwid = strtok(NULL, " \t");
|
|
|
38852f |
@@ -188,6 +188,11 @@ rlookup_binding(FILE *f, char *buff, cha
|
|
|
38852f |
}
|
|
|
38852f |
}
|
|
|
38852f |
condlog(3, "No matching alias [%s] in bindings file.", map_alias);
|
|
|
38852f |
+
|
|
|
38852f |
+ /* Get the theoretical id for this map alias.
|
|
|
38852f |
+ * Used by use_existing_alias
|
|
|
38852f |
+ */
|
|
|
38852f |
+ id = scan_devname(map_alias, prefix);
|
|
|
38852f |
return id;
|
|
|
38852f |
}
|
|
|
38852f |
|
|
|
38852f |
@@ -237,6 +242,59 @@ allocate_binding(int fd, char *wwid, int
|
|
|
38852f |
}
|
|
|
38852f |
|
|
|
38852f |
char *
|
|
|
38852f |
+use_existing_alias (char *wwid, char *file, char *alias_old,
|
|
|
38852f |
+ char *prefix, int bindings_read_only)
|
|
|
38852f |
+{
|
|
|
38852f |
+ char *alias = NULL;
|
|
|
38852f |
+ int id = 0;
|
|
|
38852f |
+ int fd, can_write;
|
|
|
38852f |
+ char buff[WWID_SIZE];
|
|
|
38852f |
+ FILE *f;
|
|
|
38852f |
+
|
|
|
38852f |
+ fd = open_file(file, &can_write, BINDINGS_FILE_HEADER);
|
|
|
38852f |
+ if (fd < 0)
|
|
|
38852f |
+ return NULL;
|
|
|
38852f |
+
|
|
|
38852f |
+ f = fdopen(fd, "r");
|
|
|
38852f |
+ if (!f) {
|
|
|
38852f |
+ condlog(0, "cannot fdopen on bindings file descriptor");
|
|
|
38852f |
+ close(fd);
|
|
|
38852f |
+ return NULL;
|
|
|
38852f |
+ }
|
|
|
38852f |
+ /* lookup the binding. if it exsists, the wwid will be in buff
|
|
|
38852f |
+ * either way, id contains the id for the alias
|
|
|
38852f |
+ */
|
|
|
38852f |
+ id = rlookup_binding(f , buff, alias_old, prefix);
|
|
|
38852f |
+ if (id < 0)
|
|
|
38852f |
+ goto out;
|
|
|
38852f |
+
|
|
|
38852f |
+ if (strlen(buff) > 0) {
|
|
|
38852f |
+ /* if buff is our wwid, it's already
|
|
|
38852f |
+ * allocated correctly
|
|
|
38852f |
+ */
|
|
|
38852f |
+ if (strcmp(buff, wwid) == 0)
|
|
|
38852f |
+ alias = STRDUP(alias_old);
|
|
|
38852f |
+ else {
|
|
|
38852f |
+ alias = NULL;
|
|
|
38852f |
+ condlog(0, "alias %s already bound to wwid %s, cannot reuse",
|
|
|
38852f |
+ alias_old, buff);
|
|
|
38852f |
+ }
|
|
|
38852f |
+ goto out;
|
|
|
38852f |
+ }
|
|
|
38852f |
+
|
|
|
38852f |
+ /* allocate the existing alias in the bindings file */
|
|
|
38852f |
+ if (can_write && id && !bindings_read_only) {
|
|
|
38852f |
+ alias = allocate_binding(fd, wwid, id, prefix);
|
|
|
38852f |
+ condlog(0, "Allocated existing binding [%s] for WWID [%s]",
|
|
|
38852f |
+ alias, wwid);
|
|
|
38852f |
+ }
|
|
|
38852f |
+
|
|
|
38852f |
+out:
|
|
|
38852f |
+ fclose(f);
|
|
|
38852f |
+ return alias;
|
|
|
38852f |
+}
|
|
|
38852f |
+
|
|
|
38852f |
+char *
|
|
|
38852f |
get_user_friendly_alias(char *wwid, char *file, char *prefix,
|
|
|
38852f |
int bindings_read_only)
|
|
|
38852f |
{
|
|
|
38852f |
@@ -305,7 +363,7 @@ get_user_friendly_wwid(char *alias, char
|
|
|
38852f |
return -1;
|
|
|
38852f |
}
|
|
|
38852f |
|
|
|
38852f |
- rlookup_binding(f, buff, alias);
|
|
|
38852f |
+ rlookup_binding(f, buff, alias, NULL);
|
|
|
38852f |
if (!strlen(buff)) {
|
|
|
38852f |
fclose(f);
|
|
|
38852f |
return -1;
|
|
|
38852f |
Index: multipath-tools-130222/libmultipath/alias.h
|
|
|
38852f |
===================================================================
|
|
|
38852f |
--- multipath-tools-130222.orig/libmultipath/alias.h
|
|
|
38852f |
+++ multipath-tools-130222/libmultipath/alias.h
|
|
|
38852f |
@@ -10,3 +10,5 @@
|
|
|
38852f |
char *get_user_friendly_alias(char *wwid, char *file, char *prefix,
|
|
|
38852f |
int bindings_readonly);
|
|
|
38852f |
int get_user_friendly_wwid(char *alias, char *buff, char *file);
|
|
|
38852f |
+char *use_existing_alias (char *wwid, char *file, char *alias_old,
|
|
|
38852f |
+ char *prefix, int bindings_read_only);
|
|
|
38852f |
Index: multipath-tools-130222/libmultipath/propsel.c
|
|
|
38852f |
===================================================================
|
|
|
38852f |
--- multipath-tools-130222.orig/libmultipath/propsel.c
|
|
|
38852f |
+++ multipath-tools-130222/libmultipath/propsel.c
|
|
|
38852f |
@@ -253,19 +253,31 @@ want_user_friendly_names(struct multipat
|
|
|
38852f |
extern int
|
|
|
38852f |
select_alias (struct multipath * mp)
|
|
|
38852f |
{
|
|
|
38852f |
- if (mp->mpe && mp->mpe->alias)
|
|
|
38852f |
+ if (mp->mpe && mp->mpe->alias) {
|
|
|
38852f |
mp->alias = STRDUP(mp->mpe->alias);
|
|
|
38852f |
- else {
|
|
|
38852f |
- mp->alias = NULL;
|
|
|
38852f |
- if (want_user_friendly_names(mp)) {
|
|
|
38852f |
- select_alias_prefix(mp);
|
|
|
38852f |
- mp->alias = get_user_friendly_alias(mp->wwid,
|
|
|
38852f |
- conf->bindings_file, mp->alias_prefix, conf->bindings_read_only);
|
|
|
38852f |
- }
|
|
|
38852f |
- if (mp->alias == NULL)
|
|
|
38852f |
- mp->alias = STRDUP(mp->wwid);
|
|
|
38852f |
+ goto out;
|
|
|
38852f |
}
|
|
|
38852f |
|
|
|
38852f |
+ mp->alias = NULL;
|
|
|
38852f |
+ if (!want_user_friendly_names(mp))
|
|
|
38852f |
+ goto out;
|
|
|
38852f |
+
|
|
|
38852f |
+ select_alias_prefix(mp);
|
|
|
38852f |
+
|
|
|
38852f |
+ if (strlen(mp->alias_old) > 0) {
|
|
|
38852f |
+ mp->alias = use_existing_alias(mp->wwid, conf->bindings_file,
|
|
|
38852f |
+ mp->alias_old, mp->alias_prefix,
|
|
|
38852f |
+ conf->bindings_read_only);
|
|
|
38852f |
+ memset (mp->alias_old, 0, WWID_SIZE);
|
|
|
38852f |
+ }
|
|
|
38852f |
+
|
|
|
38852f |
+ if (mp->alias == NULL)
|
|
|
38852f |
+ mp->alias = get_user_friendly_alias(mp->wwid,
|
|
|
38852f |
+ conf->bindings_file, mp->alias_prefix, conf->bindings_read_only);
|
|
|
38852f |
+out:
|
|
|
38852f |
+ if (mp->alias == NULL)
|
|
|
38852f |
+ mp->alias = STRDUP(mp->wwid);
|
|
|
38852f |
+
|
|
|
38852f |
return mp->alias ? 0 : 1;
|
|
|
38852f |
}
|
|
|
38852f |
|
|
|
38852f |
Index: multipath-tools-130222/libmultipath/structs_vec.c
|
|
|
38852f |
===================================================================
|
|
|
38852f |
--- multipath-tools-130222.orig/libmultipath/structs_vec.c
|
|
|
38852f |
+++ multipath-tools-130222/libmultipath/structs_vec.c
|
|
|
38852f |
@@ -430,6 +430,20 @@ out:
|
|
|
38852f |
return NULL;
|
|
|
38852f |
}
|
|
|
38852f |
|
|
|
38852f |
+static void
|
|
|
38852f |
+find_existing_alias (struct multipath * mpp,
|
|
|
38852f |
+ struct vectors *vecs)
|
|
|
38852f |
+{
|
|
|
38852f |
+ struct multipath * mp;
|
|
|
38852f |
+ int i;
|
|
|
38852f |
+
|
|
|
38852f |
+ vector_foreach_slot (vecs->mpvec, mp, i)
|
|
|
38852f |
+ if (strcmp(mp->wwid, mpp->wwid) == 0) {
|
|
|
38852f |
+ strncpy(mpp->alias_old, mp->alias, WWID_SIZE);
|
|
|
38852f |
+ return;
|
|
|
38852f |
+ }
|
|
|
38852f |
+}
|
|
|
38852f |
+
|
|
|
38852f |
extern struct multipath *
|
|
|
38852f |
add_map_with_path (struct vectors * vecs,
|
|
|
38852f |
struct path * pp, int add_vec)
|
|
|
38852f |
@@ -443,6 +457,7 @@ add_map_with_path (struct vectors * vecs
|
|
|
38852f |
mpp->hwe = pp->hwe;
|
|
|
38852f |
|
|
|
38852f |
strcpy(mpp->wwid, pp->wwid);
|
|
|
38852f |
+ find_existing_alias(mpp, vecs);
|
|
|
38852f |
if (select_alias(mpp))
|
|
|
38852f |
goto out;
|
|
|
38852f |
mpp->size = pp->size;
|