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

Add %VG, %LV and %FREE suffices to lvcreate/lvresize --extents arg.

e.g. lvcreate -l 100%FREE to create an LV using all available space.
     lvextend -l 50%LV to increase an LV by 50% of its existing size.
     lvcreate -l 20%VG to create an LV using 20% of the total VG size.
This commit is contained in:
Alasdair Kergon 2006-09-26 09:35:43 +00:00
parent 5095de5177
commit 34fadac485
12 changed files with 113 additions and 14 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.11 -
=====================================
Add %VG, %LV and %FREE suffices to lvcreate/lvresize --extents arg.
Fix two potential NULL pointer derefs in error cases in vg_read().
Separate --enable-cluster from locking lib options in lvmconf.sh.
Add a missing comma in lvcreate man page.

View File

@ -8,7 +8,7 @@ lvcreate \- create a logical volume in an existing volume group
[\-A/\-\-autobackup y/n] [\-C/\-\-contiguous y/n] [\-d/\-\-debug]
[\-h/\-?/\-\-help]
[\-i/\-\-stripes Stripes [\-I/\-\-stripesize StripeSize]]
{\-l/\-\-extents LogicalExtentsNumber |
{\-l/\-\-extents LogicalExtentsNumber[%{VG|FREE}] |
\-L/\-\-size LogicalVolumeSize[kKmMgGtT]}
[\-M/\-\-persistent y/n] [\-\-minor minor]
[\-m/\-\-mirrors Mirrors [\-\-nosync] [\-\-corelog]]
@ -22,7 +22,7 @@ VolumeGroupName [PhysicalVolumePath...]
.br
.B lvcreate
{\-l/\-\-extents LogicalExtentsNumber |
{\-l/\-\-extents LogicalExtentsNumber[%{VG|FREE}] |
\-L/\-\-size LogicalVolumeSize[kKmMgGtT]}
[\-c/\-\-chunksize ChunkSize]
\-s/\-\-snapshot \-n/\-\-name SnapshotLogicalVolumeName OriginalLogicalVolumePath
@ -63,9 +63,12 @@ StripeSize must be 2^n (n = 2 to 9) for metadata in LVM1 format.
For metadata in LVM2 format, the stripe size may be a larger
power of 2 but must not exceed the physical extent size.
.TP
.I \-l, \-\-extents LogicalExtentsNumber
.I \-l, \-\-extents LogicalExtentsNumber[%{VG|FREE}]
Gives the number of logical extents to allocate for the new
logical volume.
This can also be expressed as a percentage of the total space
in the Volume Group with the suffix %VG or of the remaining free space
with the suffix %FREE.
.TP
.I \-L, \-\-size LogicalVolumeSize[kKmMgGtT]
Gives the size to allocate for the new logical volume.

View File

@ -6,7 +6,7 @@ lvextend \- extend the size of a logical volume
[\-\-alloc AllocationPolicy]
[\-A/\-\-autobackup y/n] [\-d/\-\-debug] [\-h/\-?/\-\-help]
[\-i/\-\-stripes Stripes [\-I/\-\-stripesize StripeSize]]
{\-l/\-\-extents [+]LogicalExtentsNumber |
{\-l/\-\-extents [+]LogicalExtentsNumber[%{VG|LV|FREE}] |
\-L/\-\-size [+]LogicalVolumeSize[kKmMgGtT]}
[\-t/\-\-test]
[\-v/\-\-verbose] LogicalVolumePath [PhysicalVolumePath...]
@ -21,10 +21,14 @@ volume use
.SH OPTIONS
See \fBlvm\fP for common options.
.TP
.I \-l, \-\-extents [+]LogicalExtentsNumber
.I \-l, \-\-extents [+]LogicalExtentsNumber[%{VG|LV|FREE}]
Extend or set the logical volume size in units of logical extents.
With the + sign the value is added to the actual size
of the logical volume and without it, the value is taken as an absolute one.
The number can also be expressed as a percentage of the total space
in the Volume Group with the suffix %VG or relative to the existing
size of the Logical Volume with the suffix %LV or as a percentage of the remaining
free space in the Volume Group with the suffix %FREE.
.TP
.I \-L, \-\-size [+]LogicalVolumeSize[kKmMgGtT]
Extend or set the logical volume size in units in units of megabytes.

View File

@ -4,7 +4,8 @@ lvreduce \- reduce the size of a logical volume
.SH SYNOPSIS
.B lvreduce
[\-A/\-\-autobackup y/n] [\-d/\-\-debug] [\-f/\-\-force]
[\-h/\-?/\-\-help] {\-l/\-\-extents [\-]LogicalExtentsNumber |
[\-h/\-?/\-\-help]
{\-l/\-\-extents [\-]LogicalExtentsNumber[%{VG|LV|FREE}] |
\-L/\-\-size [\-]LogicalVolumeSize[kKmMgGtT]}
[\-t/\-\-test]
[\-v/\-\-verbose] LogicalVolume[Path]
@ -35,11 +36,15 @@ See \fBlvm\fP for common options.
.I \-f, \-\-force
Force size reduction without any question.
.TP
.I \-l, \-\-extents [\-]LogicalExtentsNumber
.I \-l, \-\-extents [\-]LogicalExtentsNumber[%{VG|LV|FREE}]
Reduce or set the logical volume size in units of logical extents.
With the - sign the value will be subtracted from
the logical volume's actual size and without it the will be taken as
an absolute size.
The number can also be expressed as a percentage of the total space
in the Volume Group with the suffix %VG or relative to the existing
size of the Logical Volume with the suffix %LV or as a percentage of the remaining
free space in the Volume Group with the suffix %FREE.
.TP
.I \-L, \-\-size [\-]LogicalVolumeSize[kKmMgGtT]
Reduce or set the logical volume size in units of megabyte by default.

View File

@ -6,7 +6,7 @@ lvresize \- resize a logical volume
[\-\-alloc AllocationPolicy]
[\-A/\-\-autobackup y/n] [\-d/\-\-debug] [\-h/\-?/\-\-help]
[\-i/\-\-stripes Stripes [\-I/\-\-stripesize StripeSize]]
{\-l/\-\-extents [+]LogicalExtentsNumber |
{\-l/\-\-extents [+]LogicalExtentsNumber[%{VG|LV|FREE}] |
\-L/\-\-size [+]LogicalVolumeSize[kKmMgGtT]}
[\-t/\-\-test]
[\-v/\-\-verbose] LogicalVolumePath [PhysicalVolumePath...]
@ -25,10 +25,14 @@ volume use
.SH OPTIONS
See \fBlvm\fP for common options.
.TP
.I \-l, \-\-extents [+/-]LogicalExtentsNumber
.I \-l, \-\-extents [+/-]LogicalExtentsNumber[%{VG|LV|FREE}]
Change or set the logical volume size in units of logical extents.
With the + or - sign the value is added to or subtracted from the actual size
of the logical volume and without it, the value is taken as an absolute one.
The number can also be expressed as a percentage of the total space
in the Volume Group with the suffix %VG or relative to the existing
size of the Logical Volume with the suffix %LV or as a percentage of the remaining
free space in the Volume Group with the suffix %FREE.
.TP
.I \-L, \-\-size [+/-]LogicalVolumeSize[kKmMgGtT]
Change or set the logical volume size in units of megabytes.

View File

@ -84,7 +84,7 @@ arg(interval_ARG, 'i', "interval", int_arg)
arg(iop_version_ARG, 'i', "iop_version", NULL)
arg(logicalvolume_ARG, 'l', "logicalvolume", int_arg)
arg(maxlogicalvolumes_ARG, 'l', "maxlogicalvolumes", int_arg)
arg(extents_ARG, 'l', "extents", int_arg_with_sign)
arg(extents_ARG, 'l', "extents", int_arg_with_sign_and_percent)
arg(lvmpartition_ARG, 'l', "lvmpartition", NULL)
arg(list_ARG, 'l', "list", NULL)
arg(size_ARG, 'L', "size", size_mb_arg)

View File

@ -137,7 +137,7 @@ xx(lvcreate,
"\t[-d|--debug]\n"
"\t[-h|-?|--help]\n"
"\t[-i|--stripes Stripes [-I|--stripesize StripeSize]]\n"
"\t{-l|--extents LogicalExtentsNumber |\n"
"\t{-l|--extents LogicalExtentsNumber[%{VG|LV|FREE}] |\n"
"\t -L|--size LogicalVolumeSize[kKmMgGtT]}\n"
"\t[-M|--persistent {y|n}] [--major major] [--minor minor]\n"
"\t[-n|--name LogicalVolumeName]\n"
@ -202,7 +202,7 @@ xx(lvextend,
"\t[-d|--debug]\n"
"\t[-h|--help]\n"
"\t[-i|--stripes Stripes [-I|--stripesize StripeSize]]\n"
"\t{-l|--extents [+]LogicalExtentsNumber |\n"
"\t{-l|--extents [+]LogicalExtentsNumber[%{VG|FREE}] |\n"
"\t -L|--size [+]LogicalVolumeSize[kKmMgGtT]}\n"
"\t[-m|--mirrors Mirrors]\n"
"\t[-n|--nofsck]\n"
@ -267,7 +267,7 @@ xx(lvreduce,
"\t[-d|--debug]\n"
"\t[-f|--force]\n"
"\t[-h|--help]\n"
"\t{-l|--extents [-]LogicalExtentsNumber |\n"
"\t{-l|--extents [-]LogicalExtentsNumber[%{VG|LV|FREE}] |\n"
"\t -L|--size [-]LogicalVolumeSize[kKmMgGtT]}\n"
"\t[-n|--nofsck]\n"
"\t[-r|--resizefs]\n"
@ -315,7 +315,7 @@ xx(lvresize,
"\t[-d|--debug]\n"
"\t[-h|--help]\n"
"\t[-i|--stripes Stripes [-I|--stripesize StripeSize]]\n"
"\t{-l|--extents [+|-]LogicalExtentsNumber |\n"
"\t{-l|--extents [+|-]LogicalExtentsNumber[%{VG|LV|FREE}] |\n"
"\t -L|--size [+|-]LogicalVolumeSize[kKmMgGtT]}\n"
"\t[-n|--nofsck]\n"
"\t[-r|--resizefs]\n"

View File

@ -43,6 +43,7 @@ struct lvcreate_params {
/* size */
uint32_t extents;
uint64_t size;
percent_t percent;
uint32_t permission;
uint32_t read_ahead;
@ -157,6 +158,7 @@ static int _read_size_params(struct lvcreate_params *lp,
return 0;
}
lp->extents = arg_uint_value(cmd, extents_ARG, 0);
lp->percent = arg_percent_value(cmd, extents_ARG, PERCENT_NONE);
}
/* Size returned in kilobyte units; held in sectors */
@ -166,6 +168,7 @@ static int _read_size_params(struct lvcreate_params *lp,
return 0;
}
lp->size = arg_uint64_value(cmd, size_ARG, UINT64_C(0)) * 2;
lp->percent = PERCENT_NONE;
}
return 1;
@ -556,6 +559,20 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
lp->extents = tmp_size / vg->extent_size;
}
switch(lp->percent) {
case PERCENT_VG:
lp->extents = lp->extents * vg->extent_count / 100;
break;
case PERCENT_FREE:
lp->extents = lp->extents * vg->free_count / 100;
break;
case PERCENT_LV:
log_error("Please express size as %%VG or %%FREE.");
return 0;
case PERCENT_NONE:
break;
}
if ((size_rest = lp->extents % lp->stripes)) {
log_print("Rounding size (%d extents) up to stripe boundary "
"size (%d extents)", lp->extents,

View File

@ -69,6 +69,7 @@ static int _interactive;
int yes_no_arg(struct cmd_context *cmd __attribute((unused)), struct arg *a)
{
a->sign = SIGN_NONE;
a->percent = PERCENT_NONE;
if (!strcmp(a->value, "y")) {
a->i_value = 1;
@ -90,6 +91,7 @@ int yes_no_excl_arg(struct cmd_context *cmd __attribute((unused)),
struct arg *a)
{
a->sign = SIGN_NONE;
a->percent = PERCENT_NONE;
if (!strcmp(a->value, "e") || !strcmp(a->value, "ey") ||
!strcmp(a->value, "ye")) {
@ -148,6 +150,8 @@ static int _get_int_arg(struct arg *a, char **ptr)
char *val;
long v;
a->percent = PERCENT_NONE;
val = a->value;
switch (*val) {
case '+':
@ -186,6 +190,8 @@ static int _size_arg(struct cmd_context *cmd __attribute((unused)), struct arg *
char *val;
double v;
a->percent = PERCENT_NONE;
val = a->value;
switch (*val) {
case '+':
@ -259,6 +265,33 @@ int int_arg_with_sign(struct cmd_context *cmd __attribute((unused)), struct arg
return 1;
}
int int_arg_with_sign_and_percent(struct cmd_context *cmd __attribute((unused)),
struct arg *a)
{
char *ptr;
if (!_get_int_arg(a, &ptr))
return 0;
if (!*ptr)
return 1;
if (*ptr++ != '%')
return 0;
if (!strcasecmp(ptr, "V") || !strcasecmp(ptr, "VG"))
a->percent = PERCENT_VG;
else if (!strcasecmp(ptr, "L") || !strcasecmp(ptr, "LV"))
a->percent = PERCENT_LV;
else if (!strcasecmp(ptr, "F") || !strcasecmp(ptr, "FR") ||
!strcasecmp(ptr, "FREE"))
a->percent = PERCENT_FREE;
else
return 0;
return 1;
}
int minor_arg(struct cmd_context *cmd __attribute((unused)), struct arg *a)
{
char *ptr;

View File

@ -31,6 +31,7 @@ struct lvresize_params {
uint32_t extents;
uint64_t size;
sign_t sign;
percent_t percent;
enum {
LV_ANY = 0,
@ -68,12 +69,14 @@ static int _lvresize_params(struct cmd_context *cmd, int argc, char **argv,
if (arg_count(cmd, extents_ARG)) {
lp->extents = arg_uint_value(cmd, extents_ARG, 0);
lp->sign = arg_sign_value(cmd, extents_ARG, SIGN_NONE);
lp->percent = arg_percent_value(cmd, extents_ARG, PERCENT_NONE);
}
/* Size returned in kilobyte units; held in sectors */
if (arg_count(cmd, size_ARG)) {
lp->size = arg_uint64_value(cmd, size_ARG, UINT64_C(0)) * 2;
lp->sign = arg_sign_value(cmd, size_ARG, SIGN_NONE);
lp->percent = PERCENT_NONE;
}
if (lp->resize == LV_EXTEND && lp->sign == SIGN_MINUS) {
@ -238,6 +241,20 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp)
lp->extents = lp->size / vg->extent_size;
}
switch(lp->percent) {
case PERCENT_VG:
lp->extents = lp->extents * vg->extent_count / 100;
break;
case PERCENT_FREE:
lp->extents = lp->extents * vg->free_count / 100;
break;
case PERCENT_LV:
lp->extents = lp->extents * lv->le_count / 100;
break;
case PERCENT_NONE:
break;
}
if (lp->sign == SIGN_PLUS)
lp->extents += lv->le_count;

View File

@ -70,6 +70,11 @@ sign_t arg_sign_value(struct cmd_context *cmd, int a, const sign_t def)
return arg_count(cmd, a) ? cmd->args[a].sign : def;
}
sign_t arg_percent_value(struct cmd_context *cmd, int a, const percent_t def)
{
return arg_count(cmd, a) ? cmd->args[a].percent : def;
}
int arg_count_increment(struct cmd_context *cmd, int a)
{
return cmd->args[a].count++;

View File

@ -80,6 +80,13 @@ typedef enum {
SIGN_MINUS = 2
} sign_t;
typedef enum {
PERCENT_NONE = 0,
PERCENT_VG,
PERCENT_FREE,
PERCENT_LV
} percent_t;
enum {
CHANGE_AY = 0,
CHANGE_AN = 1,
@ -103,6 +110,7 @@ struct arg {
int64_t i64_value;
uint64_t ui64_value;
sign_t sign;
percent_t percent;
void *ptr;
};
@ -126,6 +134,7 @@ int size_kb_arg(struct cmd_context *cmd, struct arg *a);
int size_mb_arg(struct cmd_context *cmd, struct arg *a);
int int_arg(struct cmd_context *cmd, struct arg *a);
int int_arg_with_sign(struct cmd_context *cmd, struct arg *a);
int int_arg_with_sign_and_percent(struct cmd_context *cmd, struct arg *a);
int major_arg(struct cmd_context *cmd, struct arg *a);
int minor_arg(struct cmd_context *cmd, struct arg *a);
int string_arg(struct cmd_context *cmd, struct arg *a);
@ -148,6 +157,7 @@ int64_t arg_int64_value(struct cmd_context *cmd, int a, const int64_t def);
uint64_t arg_uint64_value(struct cmd_context *cmd, int a, const uint64_t def);
const void *arg_ptr_value(struct cmd_context *cmd, int a, const void *def);
sign_t arg_sign_value(struct cmd_context *cmd, int a, const sign_t def);
percent_t arg_percent_value(struct cmd_context *cmd, int a, const percent_t def);
int arg_count_increment(struct cmd_context *cmd, int a);
const char *command_name(struct cmd_context *cmd);