summaryrefslogtreecommitdiff
path: root/tools/lvreduce.c
diff options
context:
space:
mode:
authorAlasdair Kergon <agk@redhat.com>2001-11-09 22:01:04 +0000
committerAlasdair Kergon <agk@redhat.com>2001-11-09 22:01:04 +0000
commit7858f6fb16b9b2373efa92103e81b46fce897799 (patch)
tree12cc418aac3ba47a42528418eee9f5079086d7c6 /tools/lvreduce.c
parent4f0a4a6a7a13e3c24360a54813208397fbb6c218 (diff)
downloadlvm2-7858f6fb16b9b2373efa92103e81b46fce897799.tar.gz
o Added lvextend
o Full signed arguments to lvreduce/lvextend o Consistent lv_number/pe map use o Populate pv->pe_allocated o Fixes for allocation/writing of multiple LVs
Diffstat (limited to 'tools/lvreduce.c')
-rw-r--r--tools/lvreduce.c49
1 files changed, 33 insertions, 16 deletions
diff --git a/tools/lvreduce.c b/tools/lvreduce.c
index e9163e5bc..48aaf3f26 100644
--- a/tools/lvreduce.c
+++ b/tools/lvreduce.c
@@ -25,22 +25,32 @@ int lvreduce(int argc, char **argv)
struct volume_group *vg;
struct logical_volume *lv;
struct list *lvh;
- int32_t extents = 0;
- int32_t size = 0;
+ uint32_t extents = 0;
+ uint32_t size = 0;
+ sign_t sign = SIGN_NONE;
char *lv_name, *vg_name;
char *st;
+ int i;
if (arg_count(extents_ARG) + arg_count(size_ARG) != 1) {
log_error("Please specify either size or extents (not both)");
return EINVALID_CMD_LINE;
}
- /* FIXME signed use throughout halves the maximum... */
- if (arg_count(extents_ARG))
+ if (arg_count(extents_ARG)) {
extents = arg_int_value(extents_ARG, 0);
+ sign = arg_sign_value(extents_ARG, SIGN_NONE);
+ }
- if (arg_count(size_ARG))
+ if (arg_count(size_ARG)) {
size = arg_int_value(size_ARG, 0);
+ sign = arg_sign_value(extents_ARG, SIGN_NONE);
+ }
+
+ if (sign == SIGN_PLUS) {
+ log_error("Positive sign not permitted - use lvextend");
+ return EINVALID_CMD_LINE;
+ }
if (!argc) {
log_error("Please provide the logical volume name");
@@ -94,15 +104,18 @@ int lvreduce(int argc, char **argv)
if (extents % vg->extent_size) {
char *s1;
- extents += (signed) vg->extent_size -
- (signed) (extents % vg->extent_size);
+ if (sign == SIGN_NONE)
+ extents += vg->extent_size -
+ (extents % vg->extent_size);
+ else
+ extents -= extents % vg->extent_size;
+
log_print("Rounding up size to full physical extent %s",
- (s1 =
- display_size(abs(extents) / 2, SIZE_SHORT)));
+ (s1 = display_size(extents / 2, SIZE_SHORT)));
dbg_free(s1);
}
- extents /= (signed) vg->extent_size;
+ extents /= vg->extent_size;
}
if (!extents) {
@@ -110,14 +123,14 @@ int lvreduce(int argc, char **argv)
return EINVALID_CMD_LINE;
}
- if (extents < 0) {
- if (1 - extents > lv->le_count) {
+ if (sign == SIGN_MINUS) {
+ if (extents >= lv->le_count) {
log_error("Unable to reduce %s below 1 extent",
lv_name);
return EINVALID_CMD_LINE;
}
- lv->le_count += extents;
+ extents = lv->le_count - extents;
} else {
if (extents >= lv->le_count) {
log_error("New size given (%d extents) not less than "
@@ -125,7 +138,6 @@ int lvreduce(int argc, char **argv)
lv->le_count);
return EINVALID_CMD_LINE;
}
- lv->le_count = extents;
}
/************ FIXME Stripes
@@ -144,7 +156,7 @@ int lvreduce(int argc, char **argv)
log_print("WARNING: Reducing active%s logical volume to %s",
(lv_open_count(lv) > 0) ? " and open" : "",
(dummy =
- display_size(lv->le_count * vg->extent_size / 2,
+ display_size(extents * vg->extent_size / 2,
SIZE_SHORT)));
log_print("THIS MAY DESTROY YOUR DATA (filesystem etc.)");
dbg_free(dummy);
@@ -159,6 +171,12 @@ int lvreduce(int argc, char **argv)
}
}
+ for (i = extents; i < lv->le_count; i++) {
+ lv->map[i].pv->pe_allocated--;
+ }
+
+ lv->le_count = extents;
+
/********* FIXME Suspend lv ***********/
/* store vg on disk(s) */
@@ -180,4 +198,3 @@ int lvreduce(int argc, char **argv)
return 0;
}
-