summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAlasdair Kergon <agk@redhat.com>2006-08-25 23:02:33 +0000
committerAlasdair Kergon <agk@redhat.com>2006-08-25 23:02:33 +0000
commit08c060cf381b2b8ee5a54d84322cb373a5b2fa6b (patch)
tree4a5e06607b7acc950bc589844f5e7fc6e4dbb65f /tools
parentb499b916cac3d83b819e2a50709cd5588e91ae1d (diff)
downloadlvm2-08c060cf381b2b8ee5a54d84322cb373a5b2fa6b.tar.gz
lvm2-08c060cf381b2b8ee5a54d84322cb373a5b2fa6b.tar.xz
lvm2-08c060cf381b2b8ee5a54d84322cb373a5b2fa6b.zip
Add skip_dev_dir() to process command line VGs.
Diffstat (limited to 'tools')
-rw-r--r--tools/lvcreate.c14
-rw-r--r--tools/lvrename.c4
-rw-r--r--tools/pvmove.c4
-rw-r--r--tools/toollib.c41
-rw-r--r--tools/toollib.h1
-rw-r--r--tools/vgcfgrestore.c5
-rw-r--r--tools/vgcreate.c6
-rw-r--r--tools/vgextend.c2
-rw-r--r--tools/vgmerge.c8
-rw-r--r--tools/vgreduce.c2
-rw-r--r--tools/vgrename.c10
11 files changed, 39 insertions, 58 deletions
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
index 89304c00..a7e1aac0 100644
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -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)");
diff --git a/tools/lvrename.c b/tools/lvrename.c
index 4badb69c..29683d79 100644
--- a/tools/lvrename.c
+++ b/tools/lvrename.c
@@ -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, '/') &&
diff --git a/tools/pvmove.c b/tools/pvmove.c
index 5829b4c0..5e9d3cf0 100644
--- a/tools/pvmove.c
+++ b/tools/pvmove.c
@@ -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, '/')) {
diff --git a/tools/toollib.c b/tools/toollib.c
index 244a3af5..a9c924b9 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -81,6 +81,28 @@ 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)
+{
+ /* 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
*/
int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
@@ -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: "
diff --git a/tools/toollib.h b/tools/toollib.h
index ec9f7f07..b670a97f 100644
--- a/tools/toollib.h
+++ b/tools/toollib.h
@@ -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
diff --git a/tools/vgcfgrestore.c b/tools/vgcfgrestore.c
index 1693e084..30398257 100644
--- a/tools/vgcfgrestore.c
+++ b/tools/vgcfgrestore.c
@@ -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);
diff --git a/tools/vgcreate.c b/tools/vgcreate.c
index e79e85c4..1b67401f 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 = 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;
diff --git a/tools/vgextend.c b/tools/vgextend.c
index 82596498..a94c5788 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 = argv[0];
+ vg_name = skip_dev_dir(cmd, argv[0]);
argc--;
argv++;
diff --git a/tools/vgmerge.c b/tools/vgmerge.c
index 2331bb98..73b7fa81 100644
--- a/tools/vgmerge.c
+++ b/tools/vgmerge.c
@@ -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;
}
diff --git a/tools/vgreduce.c b/tools/vgreduce.c
index 0c6d8f77..86ff7fde 100644
--- a/tools/vgreduce.c
+++ b/tools/vgreduce.c
@@ -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--;
diff --git a/tools/vgrename.c b/tools/vgrename.c
index 3facaf7e..95eec951 100644
--- a/tools/vgrename.c
+++ b/tools/vgrename.c
@@ -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 "