Skip to contentSkip to conversation

Use 'mpatha' for user_friendly_names option

PATCH In review Hannes Reinecke 3 participants 5 messages Apr 30, 2008 – May 7, 2008 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use 'mpatha' for user_friendly_names option

We really should use 'mpatha' instead of 'mpath0' for the generated names with the user_friendly_names option. Otherwise we can't distinguish them from EVMS names.

---
 libmultipath/alias.c |   61 +++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 53 insertions(+), 8 deletions(-)
libmultipath/alias.c +53 -8
index ca434fe..517b055 100644
@@ -179,6 +179,46 @@ fail:
 	return -1;
 }
 
+static int
+format_devname(char *name, int id, int len)
+{
+	int pos;
+
+	memset(name,0, len);
+	strcpy(name,"mpath");
+	for (pos = len - 1; pos >= 5; pos--) {
+		name[pos] = 'a' + id % 26;
+		if (id < 26)
+			break;
+		id /= 26;
+		id--;
+	}
+	memmove(name + 5, name + pos, len - pos);
+	name[5 + len - pos] = '\0';
+	return (5 + len - pos);
+}
+
+static int
+scan_devname(char *alias)
+{
+	char *c;
+	int i, n = 0;
+
+	if (strncmp(alias, "mpath", 5))
+		return -1;
+
+	c = alias + 5;
+	while (*c != '\0' && *c != ' ' && *c != '\t') {
+		i = *c - 'a';
+		n = ( n * 26 ) + i;
+		c++;
+		if (*c < 'a' || *c > 'z')
+			break;
+		n++;
+	}
+
+	return n;
+}
 
 static int
 lookup_binding(FILE *f, char *map_wwid, char **map_alias)
@@ -200,7 +240,8 @@ lookup_binding(FILE *f, char *map_wwid, char **map_alias)
 		alias = strtok(buf, " \t");
 		if (!alias) /* blank line */
 			continue;
-		if (sscanf(alias, "mpath%d", &curr_id) == 1 && curr_id >= id)
+		curr_id = scan_devname(alias);
+		if (curr_id >= id)
 			id = curr_id + 1;
 		wwid = strtok(NULL, " \t");
 		if (!wwid){
@@ -221,7 +262,7 @@ lookup_binding(FILE *f, char *map_wwid, char **map_alias)
 	}
 	condlog(3, "No matching wwid [%s] in bindings file.", map_wwid);
 	return id;
-}	
+}
 
 static int
 rlookup_binding(FILE *f, char **map_wwid, char *map_alias)
@@ -243,7 +284,8 @@ rlookup_binding(FILE *f, char **map_wwid, char *map_alias)
 		alias = strtok(buf, " \t");
 		if (!alias) /* blank line */
 			continue;
-		if (sscanf(alias, "mpath%d", &curr_id) == 1 && curr_id >= id)
+		curr_id = scan_devname(alias);
+		if (curr_id >= id)
 			id = curr_id + 1;
 		wwid = strtok(NULL, " \t");
 		if (!wwid){
@@ -264,7 +306,7 @@ rlookup_binding(FILE *f, char **map_wwid, char *map_alias)
 	}
 	condlog(3, "No matching alias [%s] in bindings file.", map_alias);
 	return id;
-}	
+}
 
 static char *
 allocate_binding(int fd, char *wwid, int id)
@@ -272,13 +314,16 @@ allocate_binding(int fd, char *wwid, int id)
 	char buf[LINE_MAX];
 	off_t offset;
 	char *alias, *c;
-	
+	int i;
+
 	if (id < 0) {
 		condlog(0, "Bindings file full. Cannot allocate new binding");
 		return NULL;
 	}
-	
-	snprintf(buf, LINE_MAX, "mpath%d %s\n", id, wwid);
+
+	i = format_devname(buf, id, LINE_MAX);
+	c = buf + i;
+	snprintf(c,LINE_MAX - i, " %s\n", wwid);
 	buf[LINE_MAX - 1] = '\0';
 
 	offset = lseek(fd, 0, SEEK_END);
@@ -304,7 +349,7 @@ allocate_binding(int fd, char *wwid, int id)
 		condlog(3, "Created new binding [%s] for WWID [%s]", alias,
 			wwid);
 	return alias;
-}		
+}
 
 char *
 get_user_friendly_alias(char *wwid, char *file)
Signature · 1 line
1.5.2.4
#1 lore raw
Quoted 4 lines · Hannes Reinecke

We really should use 'mpatha' instead of 'mpath0' for the generated names with the user_friendly_names option. Otherwise we can't distinguish them from EVMS names.

Is this really such a good idea? We shipped at least two upstream versions with this user friendly names default. Changing this causes problems and at least debian installer uses this during the installation phase.
Wouldn't it be nicer to make the user_friendly_names_prefix configurable so people can choose mpath, npath, mp or whatever they want leaving mpath as the default? I can cook up a patch in that case. Cheers,
-- Guido

#2 lore raw

Hi Guido,

Quoted 5 lines · Guido Günther
Quoted 3 lines · Hannes Reinecke

We really should use 'mpatha' instead of 'mpath0' for the generated names with the user_friendly_names option. Otherwise we can't distinguish them from EVMS names.

Quoted 10 lines

Is this really such a good idea? We shipped at least two upstream versions with this user friendly names default. Changing this causes problems and at least debian installer uses this during the installation phase.
Wouldn't it be nicer to make the user_friendly_names_prefix configurable so people can choose mpath, npath, mp or whatever they want leaving mpath as the default? I can cook up a patch in that case. Cheers,
-- Guido

(I knew someone would choke about this one ...)
Yeah, you're right. It would be nice to have that configurable. Preferred would be to select a prefix and a naming scheme, ie either numerical or characters.
Was just to lazy for this ...

Normally I don't use this option much; in fact, I discourage everyone on using it :-)
I really loath to have external configuration files to get your filesystem up.

But that's just me. Feel free to do so.

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		      zSeries & Storage
[email protected]			      +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Markus Rex, HRB 16746 (AG Nürnberg)
#3 lore raw
Quoted 4 lines · Hannes Reinecke

Normally I don't use this option much; in fact, I discourage everyone on using it :-) I really loath to have external configuration files to get your filesystem up.

In fact, I remember the nasty problem at boot time with bindings file residing under /var/lib/multipath when this is a filesystem different from /:
http://kbase.redhat.com/faq/FAQ_96_12017.shtm

--
Domenico Viggiani

#4 lore raw

Hi Domenico,

Quoted 8 lines · Domenico Viggiani
Quoted 1 line · Hannes Reinecke

Normally I don't use this option much; in fact, I discourage everyone on using it :-) I really loath to have external configuration files to get your filesystem up.

In fact, I remember the nasty problem at boot time with bindings file residing under /var/lib/multipath when this is a filesystem different from /:
http://kbase.redhat.com/faq/FAQ_96_12017.shtm

Which is exactly why I don't like it.
And most users normally won't touch the device names anyway, so I don't have a problem with /dev/disk/by-id/scsi-XXXXX-partY. Plus it breaks my brilliant seamless-switch-to-multipath scheme :-)

Hmm. Maybe I should write an NAA/IEEE naming decoder to translate the hex number into something readable :-)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		      zSeries & Storage
[email protected]			      +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Markus Rex, HRB 16746 (AG Nürnberg)