From 204a12e594426cf01422e87865069d494dbd1354 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Wed, 14 Nov 2007 00:08:25 +0000 Subject: [PATCH] Accept sizes with --readahead argument. Store size arguments as sectors internally. --- WHATS_NEW | 2 ++ lib/report/report.c | 13 +++++-------- tools/lvconvert.c | 5 ++--- tools/lvcreate.c | 12 ++++++------ tools/lvmcmdline.c | 18 ++++++++++++------ tools/lvresize.c | 11 +++++------ tools/pvcreate.c | 5 ++--- tools/pvresize.c | 2 +- tools/vgchange.c | 2 +- tools/vgconvert.c | 2 +- tools/vgcreate.c | 2 +- 11 files changed, 38 insertions(+), 36 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 46f1878ab..fdb4aaa5e 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,7 @@ Version 2.02.29 - ================================== + Accept sizes with --readahead argument. + Store size arguments as sectors internally. Attempt to remove incomplete LVs with lvcreate zeroing/activation problems. Add read_ahead activation code. Add activation/readahead configuration option and FMT_RESTRICTED_READAHEAD. diff --git a/lib/report/report.c b/lib/report/report.c index 58c230c0b..efe3f2ca1 100644 --- a/lib/report/report.c +++ b/lib/report/report.c @@ -566,30 +566,27 @@ static int _lvreadahead_disp(struct dm_report *rh, struct dm_pool *mem, const void *data, void *private __attribute((unused))) { const struct logical_volume *lv = (const struct logical_volume *) data; - uint64_t size; if (lv->read_ahead == DM_READ_AHEAD_AUTO) { dm_report_field_set_value(field, "auto", &_minusone); return 1; } - size = (uint64_t) lv->read_ahead; - - return _size64_disp(rh, mem, field, &size, private); + return _size32_disp(rh, mem, field, &lv->read_ahead, private); } static int _lvkreadahead_disp(struct dm_report *rh, struct dm_pool *mem, struct dm_report_field *field, const void *data, - void *private __attribute((unused))) + void *private) { const struct logical_volume *lv = (const struct logical_volume *) data; struct lvinfo info; - if (lv_info(lv->vg->cmd, lv, &info, 0, 1) && info.exists) - return dm_report_field_int(rh, field, &info.read_ahead); + if (!lv_info(lv->vg->cmd, lv, &info, 0, 1) || !info.exists) + return dm_report_field_uint64(rh, field, &_minusone); - return dm_report_field_uint64(rh, field, &_minusone); + return _size32_disp(rh, mem, field, &info.read_ahead, private); } static int _vgsize_disp(struct dm_report *rh, struct dm_pool *mem, diff --git a/tools/lvconvert.c b/tools/lvconvert.c index 293f49b13..e3cc34f18 100644 --- a/tools/lvconvert.c +++ b/tools/lvconvert.c @@ -135,7 +135,7 @@ static int _read_params(struct lvconvert_params *lp, struct cmd_context *cmd, log_error("Negative chunk size is invalid"); return 0; } - lp->chunk_size = 2 * 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 || (lp->chunk_size & (lp->chunk_size - 1))) { log_error("Chunk size must be a power of 2 in the " @@ -175,8 +175,7 @@ static int _read_params(struct lvconvert_params *lp, struct cmd_context *cmd, log_error("Negative regionsize is invalid"); return 0; } - lp->region_size = 2 * arg_uint_value(cmd, - regionsize_ARG, 0); + lp->region_size = arg_uint_value(cmd, regionsize_ARG, 0); } else { region_size = 2 * find_config_tree_int(cmd, "activation/mirror_region_size", diff --git a/tools/lvcreate.c b/tools/lvcreate.c index fc68d4f43..2976cadb0 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -173,7 +173,7 @@ static int _read_size_params(struct lvcreate_params *lp, log_error("Negative size is invalid"); return 0; } - lp->size = arg_uint64_value(cmd, size_ARG, UINT64_C(0)) * 2; + lp->size = arg_uint64_value(cmd, size_ARG, UINT64_C(0)); lp->percent = PERCENT_NONE; } @@ -195,7 +195,7 @@ static int _validate_stripe_params(struct cmd_context *cmd, if (lp->stripes > 1 && !lp->stripe_size) { lp->stripe_size = find_config_tree_int(cmd, "metadata/stripesize", - DEFAULT_STRIPESIZE) * 2; + DEFAULT_STRIPESIZE); log_print("Using default stripesize %s", display_size(cmd, (uint64_t) lp->stripe_size)); } @@ -230,12 +230,12 @@ static int _read_stripe_params(struct lvcreate_params *lp, return 0; } /* Check to make sure we won't overflow lp->stripe_size */ - if(arg_uint_value(cmd, stripesize_ARG, 0) > STRIPE_SIZE_LIMIT) { + if(arg_uint_value(cmd, stripesize_ARG, 0) > STRIPE_SIZE_LIMIT * 2) { log_error("Stripe size cannot be larger than %s", display_size(cmd, (uint64_t) STRIPE_SIZE_LIMIT)); return 0; } - lp->stripe_size = 2 * arg_uint_value(cmd, stripesize_ARG, 0); + lp->stripe_size = arg_uint_value(cmd, stripesize_ARG, 0); } @@ -310,7 +310,7 @@ static int _read_mirror_params(struct lvcreate_params *lp, log_error("Negative regionsize is invalid"); return 0; } - lp->region_size = 2 * arg_uint_value(cmd, regionsize_ARG, 0); + lp->region_size = arg_uint_value(cmd, regionsize_ARG, 0); } else { region_size = 2 * find_config_tree_int(cmd, "activation/mirror_region_size", @@ -375,7 +375,7 @@ static int _lvcreate_params(struct lvcreate_params *lp, struct cmd_context *cmd, log_error("Negative chunk size is invalid"); return 0; } - lp->chunk_size = 2 * 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 || (lp->chunk_size & (lp->chunk_size - 1))) { log_error("Chunk size must be a power of 2 in the " diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c index ca77e242c..9ef88b877 100644 --- a/tools/lvmcmdline.c +++ b/tools/lvmcmdline.c @@ -169,6 +169,7 @@ static int _get_int_arg(struct arg *a, char **ptr) return 1; } +/* Size stored in sectors */ static int _size_arg(struct cmd_context *cmd __attribute((unused)), struct arg *a, int factor) { char *ptr; @@ -211,6 +212,8 @@ static int _size_arg(struct cmd_context *cmd __attribute((unused)), struct arg * while (i-- > 0) v *= 1024; + + v *= 2; } else v *= factor; @@ -224,12 +227,12 @@ static int _size_arg(struct cmd_context *cmd __attribute((unused)), struct arg * int size_kb_arg(struct cmd_context *cmd, struct arg *a) { - return _size_arg(cmd, a, 1); + return _size_arg(cmd, a, 2); } int size_mb_arg(struct cmd_context *cmd, struct arg *a) { - return _size_arg(cmd, a, 1024); + return _size_arg(cmd, a, 2048); } int int_arg(struct cmd_context *cmd __attribute((unused)), struct arg *a) @@ -377,9 +380,6 @@ int segtype_arg(struct cmd_context *cmd, struct arg *a) */ int readahead_arg(struct cmd_context *cmd __attribute((unused)), struct arg *a) { - if (int_arg(cmd, a)) - return 1; - if (!strcasecmp(a->value, "auto")) { a->ui_value = DM_READ_AHEAD_AUTO; return 1; @@ -390,7 +390,13 @@ int readahead_arg(struct cmd_context *cmd __attribute((unused)), struct arg *a) return 1; } - return 0; + if (!_size_arg(cmd, a, 1)) + return 0; + + if (a->sign == SIGN_MINUS) + return 0; + + return 1; } static void __alloc(int size) diff --git a/tools/lvresize.c b/tools/lvresize.c index 3ddf4df88..5ba1706fc 100644 --- a/tools/lvresize.c +++ b/tools/lvresize.c @@ -55,7 +55,7 @@ static int validate_stripesize(struct cmd_context *cmd, return 0; } - if (arg_uint_value(cmd, stripesize_ARG, 0) > STRIPE_SIZE_LIMIT) { + if (arg_uint_value(cmd, stripesize_ARG, 0) > STRIPE_SIZE_LIMIT * 2) { log_error("Stripe size cannot be larger than %s", display_size(cmd, (uint64_t) STRIPE_SIZE_LIMIT)); return 0; @@ -63,16 +63,15 @@ static int validate_stripesize(struct cmd_context *cmd, if (!(vg->fid->fmt->features & FMT_SEGMENTS)) log_warn("Varied stripesize not supported. Ignoring."); - else if (arg_uint_value(cmd, stripesize_ARG, 0) > vg->extent_size) { + else if (arg_uint_value(cmd, stripesize_ARG, 0) > vg->extent_size * 2) { log_error("Reducing stripe size %s to maximum, " "physical extent size %s", display_size(cmd, - (uint64_t) arg_uint_value(cmd, stripesize_ARG, 0) * 2), + (uint64_t) arg_uint_value(cmd, stripesize_ARG, 0)), display_size(cmd, (uint64_t) vg->extent_size)); lp->stripe_size = vg->extent_size; } else - lp->stripe_size = 2 * arg_uint_value(cmd, - stripesize_ARG, 0); + lp->stripe_size = arg_uint_value(cmd, stripesize_ARG, 0); if (lp->mirrors) { log_error("Mirrors and striping cannot be combined yet."); @@ -208,7 +207,7 @@ static int _lvresize_params(struct cmd_context *cmd, int argc, char **argv, /* 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->size = arg_uint64_value(cmd, size_ARG, UINT64_C(0)); lp->sign = arg_sign_value(cmd, size_ARG, SIGN_NONE); lp->percent = PERCENT_NONE; } diff --git a/tools/pvcreate.c b/tools/pvcreate.c index 4220efa88..766c9d379 100644 --- a/tools/pvcreate.c +++ b/tools/pvcreate.c @@ -186,14 +186,13 @@ static int pvcreate_single(struct cmd_context *cmd, const char *pv_name, log_error("Physical volume size may not be negative"); goto error; } - size = arg_uint64_value(cmd, physicalvolumesize_ARG, UINT64_C(0)) * 2; + size = arg_uint64_value(cmd, physicalvolumesize_ARG, UINT64_C(0)); if (arg_sign_value(cmd, metadatasize_ARG, 0) == SIGN_MINUS) { log_error("Metadata size may not be negative"); goto error; } - pvmetadatasize = arg_uint64_value(cmd, metadatasize_ARG, UINT64_C(0)) - * 2; + pvmetadatasize = arg_uint64_value(cmd, metadatasize_ARG, UINT64_C(0)); if (!pvmetadatasize) pvmetadatasize = find_config_tree_int(cmd, "metadata/pvmetadatasize", diff --git a/tools/pvresize.c b/tools/pvresize.c index 2747473fc..18494a2ca 100644 --- a/tools/pvresize.c +++ b/tools/pvresize.c @@ -56,7 +56,7 @@ int pvresize(struct cmd_context *cmd, int argc, char **argv) } params.new_size = arg_uint64_value(cmd, physicalvolumesize_ARG, - UINT64_C(0)) * 2; + UINT64_C(0)); params.done = 0; params.total = 0; diff --git a/tools/vgchange.c b/tools/vgchange.c index 08e7147bb..7503c498e 100644 --- a/tools/vgchange.c +++ b/tools/vgchange.c @@ -388,7 +388,7 @@ static int _vgchange_pesize(struct cmd_context *cmd, struct volume_group *vg) return EINVALID_CMD_LINE; } - extent_size = arg_uint_value(cmd, physicalextentsize_ARG, 0) * 2; + extent_size = arg_uint_value(cmd, physicalextentsize_ARG, 0); if (!extent_size) { log_error("Physical extent size may not be zero"); return EINVALID_CMD_LINE; diff --git a/tools/vgconvert.c b/tools/vgconvert.c index a654462a0..870363234 100644 --- a/tools/vgconvert.c +++ b/tools/vgconvert.c @@ -61,7 +61,7 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name, } pvmetadatasize = arg_uint64_value(cmd, metadatasize_ARG, - UINT64_C(0)) * 2; + UINT64_C(0)); if (!pvmetadatasize) pvmetadatasize = find_config_tree_int(cmd, diff --git a/tools/vgcreate.c b/tools/vgcreate.c index 247b97813..736c87433 100644 --- a/tools/vgcreate.c +++ b/tools/vgcreate.c @@ -77,7 +77,7 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv) /* Units of 512-byte sectors */ extent_size = - arg_uint_value(cmd, physicalextentsize_ARG, DEFAULT_EXTENT) * 2; + arg_uint_value(cmd, physicalextentsize_ARG, DEFAULT_EXTENT); if (!extent_size) { log_error("Physical extent size may not be zero"); -- 2.43.5