From: hare@suse.de (Hannes Reinecke)
To: Christophe Varoqui <christophe.varoqui@free.fr>
Cc: dm-devel@redhat.com
Subject: [PATCH] Use 'mpatha' for user_friendly_names option
Date: Wed, 30 Apr 2008 11:03:29 +0200 [thread overview]
Message-ID: <20080430090329.CAC0718C6FF@pentland.suse.de> (raw)
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.
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
libmultipath/alias.c | 61 +++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 53 insertions(+), 8 deletions(-)
diff --git a/libmultipath/alias.c b/libmultipath/alias.c
index ca434fe..517b055 100644
--- a/libmultipath/alias.c
+++ b/libmultipath/alias.c
@@ -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)
--
1.5.2.4
next reply other threads:[~2008-04-30 9:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-30 9:03 Hannes Reinecke [this message]
2008-05-06 19:35 ` [PATCH] Use 'mpatha' for user_friendly_names option Guido Günther
2008-05-07 6:19 ` Hannes Reinecke
2008-05-07 6:37 ` Domenico Viggiani
2008-05-07 7:17 ` Hannes Reinecke
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080430090329.CAC0718C6FF@pentland.suse.de \
--to=hare@suse.de \
--cc=christophe.varoqui@free.fr \
--cc=dm-devel@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.