1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

Support the /dev/mapper prefix on most command lines.

This commit is contained in:
Alasdair Kergon 2007-03-09 20:47:41 +00:00
parent 13e5d2420d
commit 9397354a33
12 changed files with 54 additions and 30 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.24 - Version 2.02.24 -
==================================== ====================================
Support the /dev/mapper prefix on most command lines.
Version 2.02.23 - 8th March 2007 Version 2.02.23 - 8th March 2007
================================ ================================

View File

@ -95,7 +95,7 @@ static int _lvcreate_name_params(struct lvcreate_params *lp,
} }
} else { } else {
vg_name = skip_dev_dir(cmd, argv[0]); vg_name = skip_dev_dir(cmd, argv[0], NULL);
if (strrchr(vg_name, '/')) { if (strrchr(vg_name, '/')) {
log_error("Volume group name expected " log_error("Volume group name expected "
"(no slash)"); "(no slash)");

View File

@ -29,7 +29,7 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)
struct lv_list *lvl; struct lv_list *lvl;
if (argc == 3) { 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_old = argv[1];
lv_name_new = argv[2]; lv_name_new = argv[2];
if (strchr(lv_name_old, '/') && if (strchr(lv_name_old, '/') &&

View File

@ -27,7 +27,7 @@ static const char *_extract_lvname(struct cmd_context *cmd, const char *vgname,
if (!strchr(arg, '/')) if (!strchr(arg, '/'))
return arg; return arg;
lvname = skip_dev_dir(cmd, arg); lvname = skip_dev_dir(cmd, arg, NULL);
while (*lvname == '/') while (*lvname == '/')
lvname++; lvname++;
if (!strchr(lvname, '/')) { if (!strchr(lvname, '/')) {

View File

@ -88,21 +88,53 @@ const char *command_name(struct cmd_context *cmd)
/* /*
* Strip dev_dir if present * 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 == '/') { if (*vg_name == '/') {
while (*vg_name == '/') while (*vg_name == '/')
vg_name++; 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 (!strncmp(vg_name, cmd->dev_dir, strlen(cmd->dev_dir))) {
if (dev_dir_found)
*dev_dir_found = 1;
vg_name += strlen(cmd->dev_dir); vg_name += strlen(cmd->dev_dir);
while (*vg_name == '/') while (*vg_name == '/')
vg_name++; vg_name++;
} } else if (dev_dir_found)
*dev_dir_found = 0;
return (char *) vg_name; return (char *) vg_name;
} }
@ -222,7 +254,7 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
for (; opt < argc; opt++) { for (; opt < argc; opt++) {
const char *lv_name = argv[opt]; const char *lv_name = argv[opt];
char *vgname_def; char *vgname_def;
int dev_dir_found = 0; unsigned dev_dir_found = 0;
/* Do we have a tag or vgname or lvname? */ /* Do we have a tag or vgname or lvname? */
vgname = lv_name; vgname = lv_name;
@ -243,18 +275,8 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
} }
/* FIXME Jumbled parsing */ /* FIXME Jumbled parsing */
if (*vgname == '/') { vgname = skip_dev_dir(cmd, vgname, &dev_dir_found);
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++;
}
if (*vgname == '/') { if (*vgname == '/') {
log_error("\"%s\": Invalid path for Logical " log_error("\"%s\": Invalid path for Logical "
"Volume", argv[opt]); "Volume", argv[opt]);
@ -528,7 +550,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
continue; continue;
} }
vg_name = skip_dev_dir(cmd, vg_name); vg_name = skip_dev_dir(cmd, vg_name, NULL);
if (strchr(vg_name, '/')) { if (strchr(vg_name, '/')) {
log_error("Invalid volume group name: %s", log_error("Invalid volume group name: %s",
vg_name); vg_name);
@ -830,7 +852,7 @@ char *default_vgname(struct cmd_context *cmd)
if (!vg_path) if (!vg_path)
return 0; return 0;
vg_path = skip_dev_dir(cmd, vg_path); vg_path = skip_dev_dir(cmd, vg_path, NULL);
if (strchr(vg_path, '/')) { if (strchr(vg_path, '/')) {
log_error("Environment Volume Group in LVM_VG_NAME invalid: " log_error("Environment Volume Group in LVM_VG_NAME invalid: "

View File

@ -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); char *default_vgname(struct cmd_context *cmd);
const char *extract_vgname(struct cmd_context *cmd, const char *lv_name); 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 * Builds a list of pv's from the names in argv. Used in

View File

@ -24,7 +24,7 @@ int vgcfgrestore(struct cmd_context *cmd, int argc, char **argv)
return ECMD_FAILED; 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)) { if (!validate_name(vg_name)) {
log_error("Volume group name \"%s\" is invalid", vg_name); log_error("Volume group name \"%s\" is invalid", vg_name);

View File

@ -38,7 +38,7 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE; 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_lv = arg_uint_value(cmd, maxlogicalvolumes_ARG, 0);
max_pv = arg_uint_value(cmd, maxphysicalvolumes_ARG, 0); max_pv = arg_uint_value(cmd, maxphysicalvolumes_ARG, 0);
alloc = arg_uint_value(cmd, alloc_ARG, ALLOC_NORMAL); alloc = arg_uint_value(cmd, alloc_ARG, ALLOC_NORMAL);

View File

@ -32,7 +32,7 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE; return EINVALID_CMD_LINE;
} }
vg_name = skip_dev_dir(cmd, argv[0]); vg_name = skip_dev_dir(cmd, argv[0], NULL);
argc--; argc--;
argv++; argv++;

View File

@ -253,12 +253,12 @@ int vgmerge(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE; return EINVALID_CMD_LINE;
} }
vg_name_to = skip_dev_dir(cmd, argv[0]); vg_name_to = skip_dev_dir(cmd, argv[0], NULL);
argc--; argc--;
argv++; argv++;
for (; opt < argc; opt++) { 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); ret = _vgmerge_single(cmd, vg_name_to, vg_name_from);
if (ret > ret_max) if (ret > ret_max)

View File

@ -461,7 +461,7 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE; return EINVALID_CMD_LINE;
} }
vg_name = skip_dev_dir(cmd, argv[0]); vg_name = skip_dev_dir(cmd, argv[0], NULL);
argv++; argv++;
argc--; argc--;

View File

@ -35,8 +35,8 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE; return EINVALID_CMD_LINE;
} }
vg_name_old = skip_dev_dir(cmd, argv[0]); vg_name_old = skip_dev_dir(cmd, argv[0], NULL);
vg_name_new = skip_dev_dir(cmd, argv[1]); vg_name_new = skip_dev_dir(cmd, argv[1], NULL);
dev_dir = cmd->dev_dir; dev_dir = cmd->dev_dir;
length = strlen(dev_dir); length = strlen(dev_dir);