From 9585e50fef252ccb6a8eacba605c55f6eb466ebb Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Tue, 19 Mar 2002 16:41:44 +0000 Subject: [PATCH] Better support for LVs with hyphens in names. --- lib/activate/dev_manager.c | 32 +++++++++++++++++++------------- tools/toollib.c | 5 +++++ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c index da847feca..05906ffb4 100644 --- a/lib/activate/dev_manager.c +++ b/lib/activate/dev_manager.c @@ -1046,7 +1046,6 @@ int _create_rec(struct dev_manager *dm, struct dev_layer *dl) struct list *sh; struct dev_layer *dep; char *dlid, *newname, *suffix; - int len; int suspended = 0; list_iterate(sh, &dl->pre_create) { @@ -1076,13 +1075,11 @@ int _create_rec(struct dev_manager *dm, struct dev_layer *dl) /* Rename? */ if (dl->info.exists) { - newname = _build_name(dm->mem, dm->vg_name, dl->lv->name, NULL); - len = strlen(newname); - if (strncmp(newname, dl->name, len)) { - if ((suffix = rindex(dl->dlid, '-'))) - suffix++; - newname = _build_name(dm->mem, dm->vg_name, - dl->lv->name, suffix); + if ((suffix = rindex(dl->dlid, '-'))) + suffix++; + newname = _build_name(dm->mem, dm->vg_name, dl->lv->name, + suffix); + if (strcmp(newname, dl->name)) { if (!_rename(dm, dl, newname)) { stack; return 0; @@ -1259,12 +1256,21 @@ static int _execute(struct dev_manager *dm, struct volume_group *vg) * looking at the beginning of the device * name. */ -static int _belong_to_vg(const char *vg, const char *name) +static int _belong_to_vg(const char *vgname, const char *name) { - /* - * FIXME: broken for vg's with '-'s in. - */ - return !strncmp(vg, name, strlen(vg)); + const char *v = vgname, *n = name; + + while (*v) { + if ((*v != *n) || + (*v == '-' && *(++n) != '-')) + return 0; + v++, n++; + } + + if (*n == '-' && *(n+1) != '-') + return 1; + else + return 0; } static int _add_existing_layer(struct dev_manager *dm, const char *name) diff --git a/tools/toollib.c b/tools/toollib.c index 461450c06..a3d6fbf3c 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -221,6 +221,11 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv, int is_valid_chars(char *n) { register char c; + + /* Hyphen used as VG-LV separator - ambiguity if LV starts with it */ + if (*n == '-') + return 0; + while ((c = *n++)) if (!isalnum(c) && c != '.' && c != '_' && c != '-' && c != '+') return 0;