diff --git a/WHATS_NEW b/WHATS_NEW index dddc5fa65..0a8df6daa 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.24 - ==================================== + Support the /dev/mapper prefix on most command lines. Version 2.02.23 - 8th March 2007 ================================ diff --git a/tools/lvcreate.c b/tools/lvcreate.c index 20ffba4d5..71af12aaa 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -95,7 +95,7 @@ static int _lvcreate_name_params(struct lvcreate_params *lp, } } else { - vg_name = skip_dev_dir(cmd, argv[0]); + vg_name = skip_dev_dir(cmd, argv[0], NULL); if (strrchr(vg_name, '/')) { log_error("Volume group name expected " "(no slash)"); diff --git a/tools/lvrename.c b/tools/lvrename.c index 67c8d1e34..a63f3a561 100644 --- a/tools/lvrename.c +++ b/tools/lvrename.c @@ -29,7 +29,7 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv) struct lv_list *lvl; if (argc == 3) { - vg_name = skip_dev_dir(cmd, argv[0]); + vg_name = skip_dev_dir(cmd, argv[0], NULL); lv_name_old = argv[1]; lv_name_new = argv[2]; if (strchr(lv_name_old, '/') && diff --git a/tools/pvmove.c b/tools/pvmove.c index 7c3d94375..b98014ef9 100644 --- a/tools/pvmove.c +++ b/tools/pvmove.c @@ -27,7 +27,7 @@ static const char *_extract_lvname(struct cmd_context *cmd, const char *vgname, if (!strchr(arg, '/')) return arg; - lvname = skip_dev_dir(cmd, arg); + lvname = skip_dev_dir(cmd, arg, NULL); while (*lvname == '/') lvname++; if (!strchr(lvname, '/')) { diff --git a/tools/toollib.c b/tools/toollib.c index fb2a70136..d3909ecc3 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -88,21 +88,53 @@ const char *command_name(struct cmd_context *cmd) /* * Strip dev_dir if present */ -char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name) +char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name, + unsigned *dev_dir_found) { - /* FIXME Do this properly */ + const char *dmdir = dm_dir(); + size_t dmdir_len = strlen(dmdir), vglv_sz; + char *vgname, *lvname, *layer, *vglv; + /* FIXME Do this properly */ if (*vg_name == '/') { while (*vg_name == '/') vg_name++; vg_name--; } + /* Reformat string if /dev/mapper found */ + if (!strncmp(vg_name, dmdir, dmdir_len) && vg_name[dmdir_len] == '/') { + if (dev_dir_found) + *dev_dir_found = 1; + vg_name += dmdir_len; + while (*vg_name == '/') + vg_name++; + + if (!dm_split_lvm_name(cmd->mem, vg_name, &vgname, &lvname, &layer) || + *layer) { + log_error("skip_dev_dir: Couldn't split up device name %s", + vg_name); + return (char *) vg_name; + } + vglv_sz = strlen(vgname) + strlen(lvname) + 2; + if (!(vglv = dm_pool_alloc(cmd->mem, vglv_sz)) || + dm_snprintf(vglv, vglv_sz, "%s%s%s", vgname, + *lvname ? "/" : "", + lvname) < 0) { + log_error("vg/lv string alloc failed"); + return (char *) vg_name; + } + return vglv; + } + if (!strncmp(vg_name, cmd->dev_dir, strlen(cmd->dev_dir))) { + if (dev_dir_found) + *dev_dir_found = 1; vg_name += strlen(cmd->dev_dir); while (*vg_name == '/') vg_name++; - } + } else if (dev_dir_found) + *dev_dir_found = 0; return (char *) vg_name; } @@ -222,7 +254,7 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv, for (; opt < argc; opt++) { const char *lv_name = argv[opt]; char *vgname_def; - int dev_dir_found = 0; + unsigned dev_dir_found = 0; /* Do we have a tag or vgname or lvname? */ vgname = lv_name; @@ -243,18 +275,8 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv, } /* FIXME Jumbled parsing */ - if (*vgname == '/') { - while (*vgname == '/') - vgname++; - vgname--; - } - if (!strncmp(vgname, cmd->dev_dir, - strlen(cmd->dev_dir))) { - vgname += strlen(cmd->dev_dir); - dev_dir_found = 1; - while (*vgname == '/') - vgname++; - } + vgname = skip_dev_dir(cmd, vgname, &dev_dir_found); + if (*vgname == '/') { log_error("\"%s\": Invalid path for Logical " "Volume", argv[opt]); @@ -528,7 +550,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv, continue; } - vg_name = skip_dev_dir(cmd, vg_name); + vg_name = skip_dev_dir(cmd, vg_name, NULL); if (strchr(vg_name, '/')) { log_error("Invalid volume group name: %s", vg_name); @@ -830,7 +852,7 @@ char *default_vgname(struct cmd_context *cmd) if (!vg_path) return 0; - vg_path = skip_dev_dir(cmd, vg_path); + vg_path = skip_dev_dir(cmd, vg_path, NULL); if (strchr(vg_path, '/')) { log_error("Environment Volume Group in LVM_VG_NAME invalid: " diff --git a/tools/toollib.h b/tools/toollib.h index d4b1089e6..af0db95f8 100644 --- a/tools/toollib.h +++ b/tools/toollib.h @@ -76,7 +76,8 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg, char *default_vgname(struct cmd_context *cmd); const char *extract_vgname(struct cmd_context *cmd, const char *lv_name); -char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name); +char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name, + unsigned *dev_dir_found); /* * Builds a list of pv's from the names in argv. Used in diff --git a/tools/vgcfgrestore.c b/tools/vgcfgrestore.c index 303982575..3dd1c676b 100644 --- a/tools/vgcfgrestore.c +++ b/tools/vgcfgrestore.c @@ -24,7 +24,7 @@ int vgcfgrestore(struct cmd_context *cmd, int argc, char **argv) return ECMD_FAILED; } - vg_name = skip_dev_dir(cmd, argv[0]); + vg_name = skip_dev_dir(cmd, argv[0], NULL); if (!validate_name(vg_name)) { log_error("Volume group name \"%s\" is invalid", vg_name); diff --git a/tools/vgcreate.c b/tools/vgcreate.c index 1b67401f2..5ae6f9c2e 100644 --- a/tools/vgcreate.c +++ b/tools/vgcreate.c @@ -38,7 +38,7 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv) return EINVALID_CMD_LINE; } - vg_name = skip_dev_dir(cmd, argv[0]); + vg_name = skip_dev_dir(cmd, argv[0], NULL); max_lv = arg_uint_value(cmd, maxlogicalvolumes_ARG, 0); max_pv = arg_uint_value(cmd, maxphysicalvolumes_ARG, 0); alloc = arg_uint_value(cmd, alloc_ARG, ALLOC_NORMAL); diff --git a/tools/vgextend.c b/tools/vgextend.c index 7ec7008ba..e1a768fd8 100644 --- a/tools/vgextend.c +++ b/tools/vgextend.c @@ -32,7 +32,7 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv) return EINVALID_CMD_LINE; } - vg_name = skip_dev_dir(cmd, argv[0]); + vg_name = skip_dev_dir(cmd, argv[0], NULL); argc--; argv++; diff --git a/tools/vgmerge.c b/tools/vgmerge.c index 80c6bdc12..e7361e44f 100644 --- a/tools/vgmerge.c +++ b/tools/vgmerge.c @@ -253,12 +253,12 @@ int vgmerge(struct cmd_context *cmd, int argc, char **argv) return EINVALID_CMD_LINE; } - vg_name_to = skip_dev_dir(cmd, argv[0]); + vg_name_to = skip_dev_dir(cmd, argv[0], NULL); argc--; argv++; for (; opt < argc; opt++) { - vg_name_from = skip_dev_dir(cmd, argv[opt]); + vg_name_from = skip_dev_dir(cmd, argv[opt], NULL); ret = _vgmerge_single(cmd, vg_name_to, vg_name_from); if (ret > ret_max) diff --git a/tools/vgreduce.c b/tools/vgreduce.c index d2a1af635..fc6e390c1 100644 --- a/tools/vgreduce.c +++ b/tools/vgreduce.c @@ -461,7 +461,7 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv) return EINVALID_CMD_LINE; } - vg_name = skip_dev_dir(cmd, argv[0]); + vg_name = skip_dev_dir(cmd, argv[0], NULL); argv++; argc--; diff --git a/tools/vgrename.c b/tools/vgrename.c index 0da8be663..2adf71796 100644 --- a/tools/vgrename.c +++ b/tools/vgrename.c @@ -35,8 +35,8 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv) return EINVALID_CMD_LINE; } - vg_name_old = skip_dev_dir(cmd, argv[0]); - vg_name_new = skip_dev_dir(cmd, argv[1]); + vg_name_old = skip_dev_dir(cmd, argv[0], NULL); + vg_name_new = skip_dev_dir(cmd, argv[1], NULL); dev_dir = cmd->dev_dir; length = strlen(dev_dir);