summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAlasdair Kergon <agk@redhat.com>2005-06-03 14:49:51 +0000
committerAlasdair Kergon <agk@redhat.com>2005-06-03 14:49:51 +0000
commit8211a13ce0180979257689175d2fe2d700389c1e (patch)
tree98681540e30645c3bf91186c8e50d18d5c369c8b /tools
parent60f13f01d2af1cb1b05c20b11285c7c6c15acd6b (diff)
downloadlvm2-8211a13ce0180979257689175d2fe2d700389c1e.tar.gz
lvm2-8211a13ce0180979257689175d2fe2d700389c1e.tar.xz
lvm2-8211a13ce0180979257689175d2fe2d700389c1e.zip
Always insert an intermediate layer for mirrors.
Suppress hidden LVs from reports unless --all is given. Use square brackets for hidden LVs in reports. Centralise restrictions on LV names.
Diffstat (limited to 'tools')
-rw-r--r--tools/commands.h23
-rw-r--r--tools/lvchange.c13
-rw-r--r--tools/lvcreate.c54
-rw-r--r--tools/lvdisplay.c3
-rw-r--r--tools/lvremove.c6
-rw-r--r--tools/lvrename.c6
-rw-r--r--tools/pvmove.c2
-rw-r--r--tools/reporter.c6
-rw-r--r--tools/toollib.c30
-rw-r--r--tools/toollib.h2
10 files changed, 119 insertions, 26 deletions
diff --git a/tools/commands.h b/tools/commands.h
index 46ac265e..6b224649 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -131,6 +131,7 @@ xx(lvcreate,
xx(lvdisplay,
"Display information about a logical volume",
"lvdisplay\n"
+ "\t[-a|--all]\n"
"\t[-c|--colon]\n"
"\t[-d|--debug]\n"
"\t[-h|--help]\n"
@@ -145,6 +146,7 @@ xx(lvdisplay,
"\n"
"lvdisplay --columns|-C\n"
"\t[--aligned]\n"
+ "\t[-a|--all]\n"
"\t[-d|--debug]\n"
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
@@ -161,9 +163,10 @@ xx(lvdisplay,
"\t[--version]" "\n"
"\t[LogicalVolume[Path] [LogicalVolume[Path]...]]\n",
- aligned_ARG, colon_ARG, columns_ARG, disk_ARG, ignorelockingfailure_ARG,
- maps_ARG, noheadings_ARG, nosuffix_ARG, options_ARG, sort_ARG,
- partial_ARG, segments_ARG, separator_ARG, unbuffered_ARG, units_ARG)
+ aligned_ARG, all_ARG, colon_ARG, columns_ARG, disk_ARG,
+ ignorelockingfailure_ARG, maps_ARG, noheadings_ARG, nosuffix_ARG,
+ options_ARG, sort_ARG, partial_ARG, segments_ARG, separator_ARG,
+ unbuffered_ARG, units_ARG)
xx(lvextend,
"Add space to a logical volume",
@@ -300,6 +303,7 @@ xx(lvresize,
xx(lvs,
"Display information about logical volumes",
"lvs" "\n"
+ "\t[-a|--all]\n"
"\t[--aligned]\n"
"\t[-d|--debug]\n"
"\t[-h|--help]\n"
@@ -317,9 +321,9 @@ xx(lvs,
"\t[--version]" "\n"
"\t[LogicalVolume[Path] [LogicalVolume[Path]...]]\n",
- aligned_ARG, ignorelockingfailure_ARG, noheadings_ARG, nolocking_ARG,
- nosuffix_ARG, options_ARG, partial_ARG, segments_ARG, separator_ARG,
- sort_ARG, unbuffered_ARG, units_ARG)
+ aligned_ARG, all_ARG, ignorelockingfailure_ARG, noheadings_ARG,
+ nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, segments_ARG,
+ separator_ARG, sort_ARG, unbuffered_ARG, units_ARG)
xx(lvscan,
"List all logical volumes in all volume groups",
@@ -775,6 +779,7 @@ xx(vgs,
"Display information about volume groups",
"vgs" "\n"
"\t[--aligned]\n"
+ "\t[-a|--all]\n"
"\t[-d|--debug]\n"
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
@@ -790,9 +795,9 @@ xx(vgs,
"\t[--version]\n"
"\t[VolumeGroupName [VolumeGroupName...]]\n",
- aligned_ARG, ignorelockingfailure_ARG, noheadings_ARG, nolocking_ARG,
- nosuffix_ARG, options_ARG, partial_ARG, separator_ARG, sort_ARG,
- unbuffered_ARG, units_ARG)
+ aligned_ARG, all_ARG, ignorelockingfailure_ARG, noheadings_ARG,
+ nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, separator_ARG,
+ sort_ARG, unbuffered_ARG, units_ARG)
xx(vgscan,
"Search for all volume groups",
diff --git a/tools/lvchange.c b/tools/lvchange.c
index 75251be2..036ba609 100644
--- a/tools/lvchange.c
+++ b/tools/lvchange.c
@@ -405,12 +405,23 @@ static int lvchange_single(struct cmd_context *cmd, struct logical_volume *lv,
return ECMD_FAILED;
}
- /* FIXME Test for VISIBLE instead? */
if (lv->status & MIRROR_LOG) {
log_error("Unable to change mirror log LV %s directly", lv->name);
return ECMD_FAILED;
}
+ if (lv->status & MIRROR_IMAGE) {
+ log_error("Unable to change mirror image LV %s directly",
+ lv->name);
+ return ECMD_FAILED;
+ }
+
+ if (!(lv->status & VISIBLE_LV)) {
+ log_error("Unable to change internal LV %s directly",
+ lv->name);
+ return ECMD_FAILED;
+ }
+
/* access permission change */
if (arg_count(cmd, permission_ARG)) {
if (!archive(lv->vg))
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
index 7bd36111..b495060b 100644
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -137,10 +137,8 @@ static int _read_name_params(struct lvcreate_params *lp,
if ((ptr = strrchr(lp->lv_name, '/')))
lp->lv_name = ptr + 1;
- /* FIXME Remove this restriction eventually */
- if (!strncmp(lp->lv_name, "snapshot", 8)) {
- log_error("Names starting \"snapshot\" are reserved. "
- "Please choose a different LV name.");
+ if (!apply_lvname_restrictions(lp->lv_name)) {
+ stack;
return 0;
}
@@ -469,6 +467,9 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
const char *tag;
int consistent = 1;
struct alloc_handle *ah = NULL;
+ char *log_name, lv_name_buf[128];
+ const char *lv_name;
+ size_t len;
status |= lp->permission | VISIBLE_LV;
@@ -597,6 +598,16 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
if (!archive(vg))
return 0;
+ if (lp->lv_name)
+ lv_name = lp->lv_name;
+ else {
+ if (!generate_lv_name(vg, "lvol%d", lv_name_buf, sizeof(lv_name_buf))) {
+ log_error("Failed to generate LV name.");
+ return 0;
+ }
+ lv_name = &lv_name_buf[0];
+ }
+
if (lp->mirrors > 1) {
/* FIXME Adjust lp->region_size if necessary */
region_max = (1 << (ffs(lp->extents) - 1)) * vg->extent_size;
@@ -609,7 +620,29 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
/* FIXME Calculate how many extents needed for the log */
- if (!(log_lv = lv_create_empty(vg->fid, NULL, "mirrorlog%d", NULL,
+ len = strlen(lv_name) + 32;
+ if (!(log_name = alloca(len))) {
+ log_error("log_name allocation failed. "
+ "Remove new LV and retry.");
+ return 0;
+ }
+
+ if (lvm_snprintf(log_name, len, "%s_mlog", lv_name) < 0) {
+ log_error("log_name allocation failed. "
+ "Remove new LV and retry.");
+ return 0;
+ }
+
+ if (find_lv_in_vg(vg, log_name)) {
+ if (lvm_snprintf(log_name, len, "%s_mlog_%%d",
+ lv_name) < 0) {
+ log_error("log_name allocation failed. "
+ "Remove new LV and retry.");
+ return 0;
+ }
+ }
+
+ if (!(log_lv = lv_create_empty(vg->fid, log_name, NULL,
VISIBLE_LV | LVM_READ | LVM_WRITE,
lp->alloc, 0, vg))) {
stack;
@@ -662,7 +695,7 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
log_lv->status &= ~VISIBLE_LV;
}
- if (!(lv = lv_create_empty(vg->fid, lp->lv_name, "lvol%d", NULL,
+ if (!(lv = lv_create_empty(vg->fid, lv_name ? lv_name : "lvol%d", NULL,
status, lp->alloc, 0, vg))) {
stack;
goto error;
@@ -701,11 +734,10 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
}
if (lp->mirrors > 1) {
- if (!lv_add_segment(ah, 0, lp->mirrors, lv, lp->segtype,
- lp->stripe_size, NULL, 0, 0,
- lp->region_size, log_lv)) {
- log_error("Aborting. Failed to add mirror segment. "
- "Remove new LV and retry.");
+ if (!create_mirror_layers(ah, 0, lp->mirrors, lv,
+ lp->segtype, 0,
+ lp->region_size, log_lv)) {
+ stack;
goto error;
}
diff --git a/tools/lvdisplay.c b/tools/lvdisplay.c
index c6dbfa71..2b8c8a11 100644
--- a/tools/lvdisplay.c
+++ b/tools/lvdisplay.c
@@ -18,6 +18,9 @@
static int _lvdisplay_single(struct cmd_context *cmd, struct logical_volume *lv,
void *handle)
{
+ if (!arg_count(cmd, all_ARG) && !(lv->status & VISIBLE_LV))
+ return ECMD_PROCESSED;
+
if (arg_count(cmd, colon_ARG))
lvdisplay_colons(lv);
else {
diff --git a/tools/lvremove.c b/tools/lvremove.c
index e5069a1f..18cac809 100644
--- a/tools/lvremove.c
+++ b/tools/lvremove.c
@@ -34,6 +34,12 @@ static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv,
return ECMD_FAILED;
}
+ if (lv->status & MIRROR_IMAGE) {
+ log_error("Can't remove logical volume %s used by a mirror",
+ lv->name);
+ return ECMD_FAILED;
+ }
+
if (lv->status & MIRROR_LOG) {
log_error("Can't remove logical volume %s used as mirror log",
lv->name);
diff --git a/tools/lvrename.c b/tools/lvrename.c
index 34b44258..bc042acb 100644
--- a/tools/lvrename.c
+++ b/tools/lvrename.c
@@ -83,10 +83,8 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)
return ECMD_FAILED;
}
- /* FIXME Remove this restriction eventually */
- if (!strncmp(lv_name_new, "snapshot", 8)) {
- log_error("Names starting \"snapshot\" are reserved. "
- "Please choose a different LV name.");
+ if (!apply_lvname_restrictions(lv_name_new)) {
+ stack;
return ECMD_FAILED;
}
diff --git a/tools/pvmove.c b/tools/pvmove.c
index a23bd8c0..d8e18e78 100644
--- a/tools/pvmove.c
+++ b/tools/pvmove.c
@@ -140,7 +140,7 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,
struct lv_list *lvl;
/* FIXME Cope with non-contiguous => splitting existing segments */
- if (!(lv_mirr = lv_create_empty(vg->fid, NULL, "pvmove%d", NULL,
+ if (!(lv_mirr = lv_create_empty(vg->fid, "pvmove%d", NULL,
LVM_READ | LVM_WRITE,
ALLOC_CONTIGUOUS, 0, vg))) {
log_error("Creation of temporary pvmove LV failed");
diff --git a/tools/reporter.c b/tools/reporter.c
index a3e633e9..2cc172ac 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -35,6 +35,9 @@ static int _vgs_single(struct cmd_context *cmd, const char *vg_name,
static int _lvs_single(struct cmd_context *cmd, struct logical_volume *lv,
void *handle)
{
+ if (!arg_count(cmd, all_ARG) && !(lv->status & VISIBLE_LV))
+ return ECMD_PROCESSED;
+
if (!report_object(handle, lv->vg, lv, NULL, NULL, NULL))
return ECMD_FAILED;
@@ -78,6 +81,9 @@ static int _pvsegs_sub_single(struct cmd_context *cmd, struct volume_group *vg,
static int _lvsegs_single(struct cmd_context *cmd, struct logical_volume *lv,
void *handle)
{
+ if (!arg_count(cmd, all_ARG) && !(lv->status & VISIBLE_LV))
+ return ECMD_PROCESSED;
+
return process_each_segment_in_lv(cmd, lv, handle, _segs_single);
}
diff --git a/tools/toollib.c b/tools/toollib.c
index 4c7cf160..a3098ac3 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1012,3 +1012,33 @@ int exec_cmd(const char *command, const char *fscmd, const char *lv_path,
return 1;
}
+
+int apply_lvname_restrictions(const char *name)
+{
+ if (!strncmp(name, "snapshot", 8)) {
+ log_error("Names starting \"snapshot\" are reserved. "
+ "Please choose a different LV name.");
+ return 0;
+ }
+
+ if (!strncmp(name, "pvmove", 6)) {
+ log_error("Names starting \"pvmove\" are reserved. "
+ "Please choose a different LV name.");
+ return 0;
+ }
+
+ if (strstr(name, "_mlog")) {
+ log_error("Names including \"_mlog\" are reserved. "
+ "Please choose a different LV name.");
+ return 0;
+ }
+
+ if (strstr(name, "_mimage")) {
+ log_error("Names including \"_mimage\" are reserved. "
+ "Please choose a different LV name.");
+ return 0;
+ }
+
+ return 1;
+}
+
diff --git a/tools/toollib.h b/tools/toollib.h
index b0536baa..b4714748 100644
--- a/tools/toollib.h
+++ b/tools/toollib.h
@@ -90,4 +90,6 @@ struct list *clone_pv_list(struct pool *mem, struct list *pvs);
int exec_cmd(const char *command, const char *fscmd, const char *lv_path,
const char *size);
+int apply_lvname_restrictions(const char *name);
+
#endif