mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
args: use arg parsing function for region size
Consolidate the validation of the region size arg in a new arg parsing function.
This commit is contained in:
parent
a1386dcca0
commit
13a6368522
@ -1223,12 +1223,13 @@ cfg_array(activation_read_only_volume_list_CFG, "read_only_volume_list", activat
|
|||||||
|
|
||||||
cfg(activation_mirror_region_size_CFG, "mirror_region_size", activation_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_RAID_REGION_SIZE, vsn(1, 0, 0), NULL, vsn(2, 2, 99),
|
cfg(activation_mirror_region_size_CFG, "mirror_region_size", activation_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_RAID_REGION_SIZE, vsn(1, 0, 0), NULL, vsn(2, 2, 99),
|
||||||
"This has been replaced by the activation/raid_region_size setting.\n",
|
"This has been replaced by the activation/raid_region_size setting.\n",
|
||||||
"Size in KiB of each copy operation when mirroring.\n")
|
"Size in KiB of each raid or mirror synchronization region.\n")
|
||||||
|
|
||||||
cfg(activation_raid_region_size_CFG, "raid_region_size", activation_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_RAID_REGION_SIZE, vsn(2, 2, 99), NULL, 0, NULL,
|
cfg(activation_raid_region_size_CFG, "raid_region_size", activation_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_RAID_REGION_SIZE, vsn(2, 2, 99), NULL, 0, NULL,
|
||||||
"Size in KiB of each raid or mirror synchronization region.\n"
|
"Size in KiB of each raid or mirror synchronization region.\n"
|
||||||
"For raid or mirror segment types, this is the amount of data that is\n"
|
"The clean/dirty state of data is tracked for each region.\n"
|
||||||
"copied at once when initializing, or moved at once by pvmove.\n")
|
"The value is rounded down to a power of two if necessary, and\n"
|
||||||
|
"is ignored if it is not a multiple of the machine memory page size.\n")
|
||||||
|
|
||||||
cfg(activation_error_when_full_CFG, "error_when_full", activation_CFG_SECTION, CFG_DEFAULT_COMMENTED, CFG_TYPE_BOOL, DEFAULT_ERROR_WHEN_FULL, vsn(2, 2, 115), NULL, 0, NULL,
|
cfg(activation_error_when_full_CFG, "error_when_full", activation_CFG_SECTION, CFG_DEFAULT_COMMENTED, CFG_TYPE_BOOL, DEFAULT_ERROR_WHEN_FULL, vsn(2, 2, 115), NULL, 0, NULL,
|
||||||
"Return errors if a thin pool runs out of space.\n"
|
"Return errors if a thin pool runs out of space.\n"
|
||||||
|
@ -712,6 +712,7 @@ static int _round_down_pow2(int r)
|
|||||||
|
|
||||||
int get_default_region_size(struct cmd_context *cmd)
|
int get_default_region_size(struct cmd_context *cmd)
|
||||||
{
|
{
|
||||||
|
int pagesize = lvm_getpagesize();
|
||||||
int region_size = _get_default_region_size(cmd);
|
int region_size = _get_default_region_size(cmd);
|
||||||
|
|
||||||
if (!is_power_of_2(region_size)) {
|
if (!is_power_of_2(region_size)) {
|
||||||
@ -720,6 +721,12 @@ int get_default_region_size(struct cmd_context *cmd)
|
|||||||
region_size / 2);
|
region_size / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (region_size % (pagesize >> SECTOR_SHIFT)) {
|
||||||
|
region_size = DEFAULT_RAID_REGION_SIZE * 2;
|
||||||
|
log_verbose("Using default region size %u kiB (multiple of page size).",
|
||||||
|
region_size / 2);
|
||||||
|
}
|
||||||
|
|
||||||
return region_size;
|
return region_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1212,10 +1212,8 @@ arg(resizefs_ARG, 'r', "resizefs", 0, 0, 0,
|
|||||||
/* Not used */
|
/* Not used */
|
||||||
arg(reset_ARG, 'R', "reset", 0, 0, 0, NULL)
|
arg(reset_ARG, 'R', "reset", 0, 0, 0, NULL)
|
||||||
|
|
||||||
arg(regionsize_ARG, 'R', "regionsize", sizemb_VAL, 0, 0,
|
arg(regionsize_ARG, 'R', "regionsize", regionsize_VAL, 0, 0,
|
||||||
"A mirror is divided into regions of this size, and the mirror log\n"
|
"Size of each raid or mirror synchronization region.\n")
|
||||||
"uses this granularity to track which regions are in sync.\n"
|
|
||||||
"(This can be used with the \"mirror\" type, not the \"raid1\" type.)\n")
|
|
||||||
|
|
||||||
arg(physicalextentsize_ARG, 's', "physicalextentsize", sizemb_VAL, 0, 0,
|
arg(physicalextentsize_ARG, 's', "physicalextentsize", sizemb_VAL, 0, 0,
|
||||||
"#vgcreate\n"
|
"#vgcreate\n"
|
||||||
|
@ -317,7 +317,7 @@ RULE: all not LV_thinpool LV_cachepool
|
|||||||
---
|
---
|
||||||
|
|
||||||
OO_LVCONVERT_RAID: --mirrors SNumber, --stripes_long Number,
|
OO_LVCONVERT_RAID: --mirrors SNumber, --stripes_long Number,
|
||||||
--stripesize SizeKB, --regionsize SizeMB, --interval Number
|
--stripesize SizeKB, --regionsize RegionSize, --interval Number
|
||||||
|
|
||||||
OO_LVCONVERT_POOL: --poolmetadata LV, --poolmetadatasize SizeMB,
|
OO_LVCONVERT_POOL: --poolmetadata LV, --poolmetadatasize SizeMB,
|
||||||
--poolmetadataspare Bool, --readahead Readahead, --chunksize SizeKB
|
--poolmetadataspare Bool, --readahead Readahead, --chunksize SizeKB
|
||||||
@ -364,7 +364,7 @@ ID: lvconvert_raid_types
|
|||||||
DESC: Convert LV to raid1 or mirror, or change number of mirror images.
|
DESC: Convert LV to raid1 or mirror, or change number of mirror images.
|
||||||
RULE: all not lv_is_locked lv_is_pvmove
|
RULE: all not lv_is_locked lv_is_pvmove
|
||||||
|
|
||||||
lvconvert --regionsize SizeMB LV_raid
|
lvconvert --regionsize RegionSize LV_raid
|
||||||
OO: OO_LVCONVERT
|
OO: OO_LVCONVERT
|
||||||
ID: lvconvert_change_region_size
|
ID: lvconvert_change_region_size
|
||||||
DESC: Change the region size of an LV.
|
DESC: Change the region size of an LV.
|
||||||
@ -655,7 +655,7 @@ OO_LVCREATE_POOL: --poolmetadatasize SizeMB, --poolmetadataspare Bool, --chunksi
|
|||||||
OO_LVCREATE_THIN: --discards Discards, --errorwhenfull Bool
|
OO_LVCREATE_THIN: --discards Discards, --errorwhenfull Bool
|
||||||
|
|
||||||
OO_LVCREATE_RAID: --mirrors SNumber, --stripes Number, --stripesize SizeKB,
|
OO_LVCREATE_RAID: --mirrors SNumber, --stripes Number, --stripesize SizeKB,
|
||||||
--regionsize SizeMB, --minrecoveryrate SizeKB, --maxrecoveryrate SizeKB
|
--regionsize RegionSize, --minrecoveryrate SizeKB, --maxrecoveryrate SizeKB
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -712,7 +712,7 @@ DESC: Create a striped LV (infers --type striped).
|
|||||||
---
|
---
|
||||||
|
|
||||||
lvcreate --type mirror --size SizeMB VG
|
lvcreate --type mirror --size SizeMB VG
|
||||||
OO: --mirrors SNumber, --mirrorlog MirrorLog, --regionsize SizeMB, --stripes Number, OO_LVCREATE
|
OO: --mirrors SNumber, --mirrorlog MirrorLog, --regionsize RegionSize, --stripes Number, OO_LVCREATE
|
||||||
OP: PV ...
|
OP: PV ...
|
||||||
ID: lvcreate_mirror
|
ID: lvcreate_mirror
|
||||||
DESC: Create a mirror LV (also see --type raid1).
|
DESC: Create a mirror LV (also see --type raid1).
|
||||||
|
@ -75,6 +75,7 @@ static inline int segtype_arg(struct cmd_context *cmd, struct arg_values *av) {
|
|||||||
static inline int alloc_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
|
static inline int alloc_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
|
||||||
static inline int locktype_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
|
static inline int locktype_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
|
||||||
static inline int readahead_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
|
static inline int readahead_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
|
||||||
|
static inline int regionsize_arg(struct cmd_context *cmd, struct arg_values *av) { return 0; }
|
||||||
static inline int vgmetadatacopies_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av) { return 0; }
|
static inline int vgmetadatacopies_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av) { return 0; }
|
||||||
static inline int pvmetadatacopies_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av) { return 0; }
|
static inline int pvmetadatacopies_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av) { return 0; }
|
||||||
static inline int metadatacopies_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av) { return 0; }
|
static inline int metadatacopies_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av) { return 0; }
|
||||||
|
@ -146,8 +146,6 @@ static int _read_conversion_type(struct cmd_context *cmd,
|
|||||||
static int _read_params(struct cmd_context *cmd, struct lvconvert_params *lp)
|
static int _read_params(struct cmd_context *cmd, struct lvconvert_params *lp)
|
||||||
{
|
{
|
||||||
const char *vg_name = NULL;
|
const char *vg_name = NULL;
|
||||||
int region_size;
|
|
||||||
int pagesize = lvm_getpagesize();
|
|
||||||
|
|
||||||
if (!_read_conversion_type(cmd, lp))
|
if (!_read_conversion_type(cmd, lp))
|
||||||
return_0;
|
return_0;
|
||||||
@ -249,45 +247,10 @@ static int _read_params(struct cmd_context *cmd, struct lvconvert_params *lp)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (arg_is_set(cmd, regionsize_ARG))
|
||||||
* --regionsize is only valid if converting an LV into a mirror.
|
|
||||||
* Checked when we know the state of the LV being converted.
|
|
||||||
*/
|
|
||||||
if (arg_is_set(cmd, regionsize_ARG)) {
|
|
||||||
if (arg_sign_value(cmd, regionsize_ARG, SIGN_NONE) ==
|
|
||||||
SIGN_MINUS) {
|
|
||||||
log_error("Negative regionsize is invalid.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
lp->region_size = arg_uint_value(cmd, regionsize_ARG, 0);
|
lp->region_size = arg_uint_value(cmd, regionsize_ARG, 0);
|
||||||
} else {
|
else
|
||||||
region_size = get_default_region_size(cmd);
|
lp->region_size = get_default_region_size(cmd);
|
||||||
if (region_size < 0) {
|
|
||||||
log_error("Negative regionsize in "
|
|
||||||
"configuration file is invalid.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
lp->region_size = region_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lp->region_size % (pagesize >> SECTOR_SHIFT)) {
|
|
||||||
log_error("Region size (%" PRIu32 ") must be "
|
|
||||||
"a multiple of machine memory "
|
|
||||||
"page size (%d).",
|
|
||||||
lp->region_size, pagesize >> SECTOR_SHIFT);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_power_of_2(lp->region_size)) {
|
|
||||||
log_error("Region size (%" PRIu32
|
|
||||||
") must be a power of 2.", lp->region_size);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!lp->region_size) {
|
|
||||||
log_error("Non-zero region size must be supplied.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FIXME man page says in one place that --type and --mirrors can't be mixed */
|
/* FIXME man page says in one place that --type and --mirrors can't be mixed */
|
||||||
if (lp->mirrors_supplied && !lp->mirrors)
|
if (lp->mirrors_supplied && !lp->mirrors)
|
||||||
|
@ -545,7 +545,6 @@ static int _read_raid_params(struct cmd_context *cmd,
|
|||||||
static int _read_mirror_and_raid_params(struct cmd_context *cmd,
|
static int _read_mirror_and_raid_params(struct cmd_context *cmd,
|
||||||
struct lvcreate_params *lp)
|
struct lvcreate_params *lp)
|
||||||
{
|
{
|
||||||
int pagesize = lvm_getpagesize();
|
|
||||||
unsigned max_images;
|
unsigned max_images;
|
||||||
|
|
||||||
if (seg_is_raid(lp)) {
|
if (seg_is_raid(lp)) {
|
||||||
@ -616,19 +615,6 @@ static int _read_mirror_and_raid_params(struct cmd_context *cmd,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_power_of_2(lp->region_size)) {
|
|
||||||
log_error("Region size (%" PRIu32 ") must be a power of 2",
|
|
||||||
lp->region_size);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lp->region_size % (pagesize >> SECTOR_SHIFT)) {
|
|
||||||
log_error("Region size (%" PRIu32 ") must be a multiple of "
|
|
||||||
"machine memory page size (%d)",
|
|
||||||
lp->region_size, pagesize >> SECTOR_SHIFT);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (seg_is_mirror(lp) && !_read_mirror_params(cmd, lp))
|
if (seg_is_mirror(lp) && !_read_mirror_params(cmd, lp))
|
||||||
return_0;
|
return_0;
|
||||||
|
|
||||||
|
@ -797,6 +797,45 @@ int readahead_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_va
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int regionsize_arg(struct cmd_context *cmd, struct arg_values *av)
|
||||||
|
{
|
||||||
|
int pagesize = lvm_getpagesize();
|
||||||
|
uint32_t num;
|
||||||
|
|
||||||
|
if (!_size_arg(cmd, av, 2048, 0))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (av->sign == SIGN_MINUS) {
|
||||||
|
log_error("Region size may not be negative.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (av->ui64_value > UINT32_MAX) {
|
||||||
|
log_error("Region size is too big (max %u).", UINT32_MAX);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
num = av->ui_value;
|
||||||
|
|
||||||
|
if (!num) {
|
||||||
|
log_error("Region size may not be zero.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (num % (pagesize >> SECTOR_SHIFT)) {
|
||||||
|
log_error("Region size must be a multiple of machine memory page size (%d bytes).",
|
||||||
|
pagesize);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_power_of_2(num)) {
|
||||||
|
log_error("Region size must be a power of 2.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Non-zero, positive integer, "all", or "unmanaged"
|
* Non-zero, positive integer, "all", or "unmanaged"
|
||||||
*/
|
*/
|
||||||
|
@ -200,6 +200,7 @@ int segtype_arg(struct cmd_context *cmd, struct arg_values *av);
|
|||||||
int alloc_arg(struct cmd_context *cmd, struct arg_values *av);
|
int alloc_arg(struct cmd_context *cmd, struct arg_values *av);
|
||||||
int locktype_arg(struct cmd_context *cmd, struct arg_values *av);
|
int locktype_arg(struct cmd_context *cmd, struct arg_values *av);
|
||||||
int readahead_arg(struct cmd_context *cmd, struct arg_values *av);
|
int readahead_arg(struct cmd_context *cmd, struct arg_values *av);
|
||||||
|
int regionsize_arg(struct cmd_context *cmd, struct arg_values *av);
|
||||||
int vgmetadatacopies_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av);
|
int vgmetadatacopies_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av);
|
||||||
int pvmetadatacopies_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av);
|
int pvmetadatacopies_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av);
|
||||||
int metadatacopies_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av);
|
int metadatacopies_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av);
|
||||||
|
@ -92,6 +92,10 @@
|
|||||||
* --size and other option args treat upper/lower letters
|
* --size and other option args treat upper/lower letters
|
||||||
* the same, all as 1024 SI base. For this reason, we
|
* the same, all as 1024 SI base. For this reason, we
|
||||||
* should avoid suggesting the upper case letters.
|
* should avoid suggesting the upper case letters.
|
||||||
|
*
|
||||||
|
* FIXME: negative numbers should be automatically rejected
|
||||||
|
* for anything but int_arg_with_sign(), e.g.
|
||||||
|
* size_mb_arg() should reject a negative number.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
val(none_VAL, NULL, "None", "ERR") /* unused, for enum value 0 */
|
val(none_VAL, NULL, "None", "ERR") /* unused, for enum value 0 */
|
||||||
@ -113,6 +117,7 @@ val(discards_VAL, discards_arg, "Discards", "passdown|nopassdown|ignore")
|
|||||||
val(mirrorlog_VAL, mirrorlog_arg, "MirrorLog", "core|disk")
|
val(mirrorlog_VAL, mirrorlog_arg, "MirrorLog", "core|disk")
|
||||||
val(sizekb_VAL, size_kb_arg, "SizeKB", "Number[k|unit]")
|
val(sizekb_VAL, size_kb_arg, "SizeKB", "Number[k|unit]")
|
||||||
val(sizemb_VAL, size_mb_arg, "SizeMB", "Number[m|unit]")
|
val(sizemb_VAL, size_mb_arg, "SizeMB", "Number[m|unit]")
|
||||||
|
val(regionsize_VAL, regionsize_arg, "RegionSize", "Number[m|unit]")
|
||||||
val(numsigned_VAL, int_arg_with_sign, "SNumber", "[+|-]Number")
|
val(numsigned_VAL, int_arg_with_sign, "SNumber", "[+|-]Number")
|
||||||
val(numsignedper_VAL, int_arg_with_sign_and_percent, "SNumberP", "[+|-]Number[%VG|%PVS|%FREE]")
|
val(numsignedper_VAL, int_arg_with_sign_and_percent, "SNumberP", "[+|-]Number[%VG|%PVS|%FREE]")
|
||||||
val(permission_VAL, permission_arg, "Permission", "rw|r")
|
val(permission_VAL, permission_arg, "Permission", "rw|r")
|
||||||
|
Loading…
Reference in New Issue
Block a user