1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-02-04 21:47:46 +03:00

macros: Use is_power_of_2.

This commit is contained in:
Alasdair G Kergon 2016-06-30 17:59:44 +01:00
parent a8e39530ef
commit aed8bc8ae7
9 changed files with 14 additions and 13 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.159 - Version 2.02.159 -
================================= =================================
Introduce and use is_power_of_2 macro.
Support conversions between striped and raid0 segment types. Support conversions between striped and raid0 segment types.
Add infrastructure for raid takeover lvconvert options. Add infrastructure for raid takeover lvconvert options.

View File

@ -181,7 +181,7 @@ static int _add_stripe_seg(struct dm_pool *mem,
unsigned j; unsigned j;
uint32_t area_len; uint32_t area_len;
if (usp->striping & (usp->striping - 1)) { if (!is_power_of_2(usp->striping)) {
log_error("Stripe size must be a power of 2"); log_error("Stripe size must be a power of 2");
return 0; return 0;
} }

View File

@ -712,7 +712,7 @@ int get_default_region_size(struct cmd_context *cmd)
{ {
int region_size = _get_default_region_size(cmd); int region_size = _get_default_region_size(cmd);
if (region_size & (region_size - 1)) { if (!is_power_of_2(region_size)) {
region_size = _round_down_pow2(region_size); region_size = _round_down_pow2(region_size);
log_verbose("Reducing region size to %u kiB (power of 2).", log_verbose("Reducing region size to %u kiB (power of 2).",
region_size / 2); region_size / 2);
@ -4329,7 +4329,7 @@ static int _validate_stripesize(const struct volume_group *vg,
lp->stripe_size = vg->extent_size; lp->stripe_size = vg->extent_size;
} }
if (lp->stripe_size & (lp->stripe_size - 1)) { if (!is_power_of_2(lp->stripe_size)) {
log_error("Stripe size must be power of 2."); log_error("Stripe size must be power of 2.");
return 0; return 0;
} }

View File

@ -588,7 +588,7 @@ int update_thin_pool_params(const struct segment_type *segtype,
*zero = find_config_tree_bool(cmd, allocation_thin_pool_zero_CFG, profile); *zero = find_config_tree_bool(cmd, allocation_thin_pool_zero_CFG, profile);
if (!(attr & THIN_FEATURE_BLOCK_SIZE) && if (!(attr & THIN_FEATURE_BLOCK_SIZE) &&
(*chunk_size & (*chunk_size - 1))) { !is_power_of_2(*chunk_size)) {
log_error("Chunk size must be a power of 2 for this thin target version."); log_error("Chunk size must be a power of 2 for this thin target version.");
return 0; return 0;
} }

View File

@ -379,7 +379,7 @@ int vg_check_new_extent_size(const struct format_type *fmt, uint32_t new_extent_
} }
if ((fmt->features & FMT_NON_POWER2_EXTENTS)) { if ((fmt->features & FMT_NON_POWER2_EXTENTS)) {
if ((new_extent_size & (new_extent_size - 1)) && if (!is_power_of_2(new_extent_size) &&
(new_extent_size % MIN_NON_POWER2_EXTENT_SIZE)) { (new_extent_size % MIN_NON_POWER2_EXTENT_SIZE)) {
log_error("Physical Extent size must be a multiple of %s when not a power of 2.", log_error("Physical Extent size must be a multiple of %s when not a power of 2.",
display_size(fmt->cmd, (uint64_t) MIN_NON_POWER2_EXTENT_SIZE)); display_size(fmt->cmd, (uint64_t) MIN_NON_POWER2_EXTENT_SIZE));
@ -389,7 +389,7 @@ int vg_check_new_extent_size(const struct format_type *fmt, uint32_t new_extent_
} }
/* Apply original format1 restrictions */ /* Apply original format1 restrictions */
if ((new_extent_size & (new_extent_size - 1))) { if (!is_power_of_2(new_extent_size)) {
log_error("Metadata format only supports Physical Extent sizes that are powers of 2."); log_error("Metadata format only supports Physical Extent sizes that are powers of 2.");
return 0; return 0;
} }

View File

@ -271,7 +271,7 @@ static int _thin_pool_add_target_line(struct dev_manager *dm,
} }
if (!(attr & THIN_FEATURE_BLOCK_SIZE) && if (!(attr & THIN_FEATURE_BLOCK_SIZE) &&
(seg->chunk_size & (seg->chunk_size - 1))) { !is_power_of_2(seg->chunk_size)) {
log_error("Thin pool target does not support %s chunk size (needs" log_error("Thin pool target does not support %s chunk size (needs"
" kernel >= 3.6).", display_size(cmd, seg->chunk_size)); " kernel >= 3.6).", display_size(cmd, seg->chunk_size));
return 0; return 0;
@ -311,7 +311,7 @@ static int _thin_pool_add_target_line(struct dev_manager *dm,
/* Use ignore for discards ignore or non-power-of-2 chunk_size and <1.5 target */ /* Use ignore for discards ignore or non-power-of-2 chunk_size and <1.5 target */
/* FIXME: Check whether underlying dev supports discards */ /* FIXME: Check whether underlying dev supports discards */
if (((!(attr & THIN_FEATURE_DISCARDS_NON_POWER_2) && if (((!(attr & THIN_FEATURE_DISCARDS_NON_POWER_2) &&
(seg->chunk_size & (seg->chunk_size - 1))) || !is_power_of_2(seg->chunk_size)) ||
(seg->discards == THIN_DISCARDS_IGNORE))) { (seg->discards == THIN_DISCARDS_IGNORE))) {
if (!dm_tree_node_set_thin_pool_discard(node, 1, 0)) if (!dm_tree_node_set_thin_pool_discard(node, 1, 0))
return_0; return_0;

View File

@ -650,7 +650,7 @@ static int _read_params(struct cmd_context *cmd, int argc, char **argv,
lp->chunk_size = arg_uint_value(cmd, chunksize_ARG, 8); lp->chunk_size = arg_uint_value(cmd, chunksize_ARG, 8);
if (lp->chunk_size < 8 || lp->chunk_size > 1024 || if (lp->chunk_size < 8 || lp->chunk_size > 1024 ||
(lp->chunk_size & (lp->chunk_size - 1))) { !is_power_of_2(lp->chunk_size)) {
log_error("Chunk size must be a power of 2 in the " log_error("Chunk size must be a power of 2 in the "
"range 4K to 512K"); "range 4K to 512K");
return 0; return 0;
@ -724,7 +724,7 @@ static int _read_params(struct cmd_context *cmd, int argc, char **argv,
return 0; return 0;
} }
if (lp->region_size & (lp->region_size - 1)) { if (!is_power_of_2(lp->region_size)) {
log_error("Region size (%" PRIu32 log_error("Region size (%" PRIu32
") must be a power of 2", lp->region_size); ") must be a power of 2", lp->region_size);
return 0; return 0;

View File

@ -555,7 +555,7 @@ static int _read_mirror_and_raid_params(struct cmd_context *cmd,
return 0; return 0;
} }
if (lp->region_size & (lp->region_size - 1)) { if (!is_power_of_2(lp->region_size)) {
log_error("Region size (%" PRIu32 ") must be a power of 2", log_error("Region size (%" PRIu32 ") must be a power of 2",
lp->region_size); lp->region_size);
return 0; return 0;
@ -1036,7 +1036,7 @@ static int _lvcreate_params(struct cmd_context *cmd,
if (lp->snapshot && (lp->extents || lcp->size)) { if (lp->snapshot && (lp->extents || lcp->size)) {
lp->chunk_size = arg_uint_value(cmd, chunksize_ARG, 8); lp->chunk_size = arg_uint_value(cmd, chunksize_ARG, 8);
if (lp->chunk_size < 8 || lp->chunk_size > 1024 || if (lp->chunk_size < 8 || lp->chunk_size > 1024 ||
(lp->chunk_size & (lp->chunk_size - 1))) { !is_power_of_2(lp->chunk_size)) {
log_error("Chunk size must be a power of 2 in the " log_error("Chunk size must be a power of 2 in the "
"range 4K to 512K."); "range 4K to 512K.");
return 0; return 0;

View File

@ -1294,7 +1294,7 @@ static int _validate_stripe_params(struct cmd_context *cmd, uint32_t *stripes,
} }
if (*stripes > 1 && (*stripe_size < STRIPE_SIZE_MIN || if (*stripes > 1 && (*stripe_size < STRIPE_SIZE_MIN ||
*stripe_size & (*stripe_size - 1))) { !is_power_of_2(*stripe_size))) {
log_error("Invalid stripe size %s.", log_error("Invalid stripe size %s.",
display_size(cmd, (uint64_t) *stripe_size)); display_size(cmd, (uint64_t) *stripe_size));
return 0; return 0;