1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

Add skip_dev_dir() to process command line VGs.

This commit is contained in:
Alasdair Kergon 2006-08-25 23:02:33 +00:00
parent b499b916ca
commit 08c060cf38
12 changed files with 41 additions and 59 deletions

View File

@ -1,11 +1,12 @@
Version 2.02.10 -
==================================
Add skip_dev_dir() to process command line VGs.
Stop clvmd complaining about nodes that have left the cluster.
Move lvm_snprintf(), split_words() and split_dm_name() into libdevmapper.
Add lvconvert man page.
Add mirror options to man pages.
Prevent mirror renames.
Move CMDLIB code into separate file and record whether static build.
Stop clvmd complaining about nodes that have left the cluster
Version 2.02.09 - 17th August 2006
==================================

View File

@ -94,19 +94,7 @@ static int _lvcreate_name_params(struct lvcreate_params *lp,
}
} else {
vg_name = argv[0];
/* Strip dev_dir (optional) */
if (*vg_name == '/') {
while (*vg_name == '/')
vg_name++;
vg_name--;
}
if (!strncmp(vg_name, cmd->dev_dir,
strlen(cmd->dev_dir))) {
vg_name += strlen(cmd->dev_dir);
while (*vg_name == '/')
vg_name++;
}
vg_name = skip_dev_dir(cmd, argv[0]);
if (strrchr(vg_name, '/')) {
log_error("Volume group name expected "
"(no slash)");

View File

@ -29,9 +29,7 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)
struct lv_list *lvl;
if (argc == 3) {
vg_name = argv[0];
if (!strncmp(vg_name, cmd->dev_dir, strlen(cmd->dev_dir)))
vg_name += strlen(cmd->dev_dir);
vg_name = skip_dev_dir(cmd, argv[0]);
lv_name_old = argv[1];
lv_name_new = argv[2];
if (strchr(lv_name_old, '/') &&

View File

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

View File

@ -80,6 +80,28 @@ const char *command_name(struct cmd_context *cmd)
return cmd->command->name;
}
/*
* Strip dev_dir if present
*/
char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name)
{
/* FIXME Do this properly */
if (*vg_name == '/') {
while (*vg_name == '/')
vg_name++;
vg_name--;
}
if (!strncmp(vg_name, cmd->dev_dir, strlen(cmd->dev_dir))) {
vg_name += strlen(cmd->dev_dir);
while (*vg_name == '/')
vg_name++;
}
return (char *) vg_name;
}
/*
* Metadata iteration functions
*/
@ -450,7 +472,6 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
struct list arg_vgnames, tags;
const char *vg_name, *vgid;
char *dev_dir = cmd->dev_dir;
list_init(&tags);
list_init(&arg_vgnames);
@ -475,13 +496,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
continue;
}
if (*vg_name == '/') {
while (*vg_name == '/')
vg_name++;
vg_name--;
}
if (!strncmp(vg_name, dev_dir, strlen(dev_dir)))
vg_name += strlen(dev_dir);
vg_name = skip_dev_dir(cmd, vg_name);
if (strchr(vg_name, '/')) {
log_error("Invalid volume group name: %s",
vg_name);
@ -768,21 +783,13 @@ const char *extract_vgname(struct cmd_context *cmd, const char *lv_name)
char *default_vgname(struct cmd_context *cmd)
{
char *vg_path;
char *dev_dir = cmd->dev_dir;
/* Take default VG from environment? */
vg_path = getenv("LVM_VG_NAME");
if (!vg_path)
return 0;
/* Strip dev_dir (optional) */
if (*vg_path == '/') {
while (*vg_path == '/')
vg_path++;
vg_path--;
}
if (!strncmp(vg_path, dev_dir, strlen(dev_dir)))
vg_path += strlen(dev_dir);
vg_path = skip_dev_dir(cmd, vg_path);
if (strchr(vg_path, '/')) {
log_error("Environment Volume Group in LVM_VG_NAME invalid: "

View File

@ -76,6 +76,7 @@ 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);
/*
* Builds a list of pv's from the names in argv. Used in

View File

@ -24,10 +24,7 @@ int vgcfgrestore(struct cmd_context *cmd, int argc, char **argv)
return ECMD_FAILED;
}
vg_name = argv[0];
if (!strncmp(vg_name, cmd->dev_dir, strlen(cmd->dev_dir)))
vg_name += strlen(cmd->dev_dir);
vg_name = skip_dev_dir(cmd, argv[0]);
if (!validate_name(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;
}
vg_name = argv[0];
vg_name = skip_dev_dir(cmd, argv[0]);
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);
@ -84,10 +84,6 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE;
}
/* Strip dev_dir if present */
if (!strncmp(vg_name, cmd->dev_dir, strlen(cmd->dev_dir)))
vg_name += strlen(cmd->dev_dir);
if (!validate_vg_name(cmd, vg_name)) {
log_error("New volume group name \"%s\" is invalid", vg_name);
return ECMD_FAILED;

View File

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

View File

@ -231,7 +231,7 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,
int vgmerge(struct cmd_context *cmd, int argc, char **argv)
{
char *vg_name_to;
char *vg_name_to, *vg_name_from;
int opt = 0;
int ret = 0, ret_max = 0;
@ -240,12 +240,14 @@ int vgmerge(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE;
}
vg_name_to = argv[0];
vg_name_to = skip_dev_dir(cmd, argv[0]);
argc--;
argv++;
for (; opt < argc; opt++) {
ret = _vgmerge_single(cmd, vg_name_to, argv[opt]);
vg_name_from = skip_dev_dir(cmd, argv[opt]);
ret = _vgmerge_single(cmd, vg_name_to, vg_name_from);
if (ret > ret_max)
ret_max = ret;
}

View File

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

View File

@ -35,18 +35,12 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE;
}
vg_name_old = argv[0];
vg_name_new = argv[1];
vg_name_old = skip_dev_dir(cmd, argv[0]);
vg_name_new = skip_dev_dir(cmd, argv[1]);
dev_dir = cmd->dev_dir;
length = strlen(dev_dir);
/* If present, strip dev_dir */
if (!strncmp(vg_name_old, dev_dir, length))
vg_name_old += length;
if (!strncmp(vg_name_new, dev_dir, length))
vg_name_new += length;
/* Check sanity of new name */
if (strlen(vg_name_new) > NAME_LEN - length - 2) {
log_error("New volume group path exceeds maximum length "