Move chunksize validation to one place. Signed-off-by: Mikulas Patocka --- tools/lvconvert.c | 14 ++++++-------- tools/lvcreate.c | 30 ++++++++++++++++++++++-------- tools/tools.h | 3 +++ 3 files changed, 31 insertions(+), 16 deletions(-) Index: LVM2.2.02.70/tools/lvcreate.c =================================================================== --- LVM2.2.02.70.orig/tools/lvcreate.c 2010-07-10 04:08:37.000000000 +0200 +++ LVM2.2.02.70/tools/lvcreate.c 2010-07-10 04:08:41.000000000 +0200 @@ -320,6 +320,22 @@ static int _read_mirror_params(struct lv return 1; } +unsigned lvm_default_chunksize(const struct segment_type *segtype) +{ + return 8; /* 4KiB */ +} + +int lvm_validate_chunksize(const struct segment_type *segtype, uint32_t chunk_size) +{ + if (chunk_size < 8 || chunk_size > 1024 || + (chunk_size & (chunk_size - 1))) { + log_error("Chunk size must be a power of 2 in the " + "range 4K to 512K"); + return 0; + } + return 1; +} + static int _lvcreate_params(struct lvcreate_params *lp, struct lvcreate_cmdline_params *lcp, struct cmd_context *cmd, @@ -371,18 +387,16 @@ static int _lvcreate_params(struct lvcre log_error("Negative chunk size is invalid"); return 0; } - 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 " - "range 4K to 512K"); - return 0; - } - log_verbose("Setting chunksize to %d sectors.", lp->chunk_size); if (!(lp->segtype = get_segtype_from_string(cmd, !lp->shared_store ? "snapshot" : "multisnapshot"))) return_0; + + lp->chunk_size = arg_uint_value(cmd, chunksize_ARG, lvm_default_chunksize(lp->segtype)); + if (!lvm_validate_chunksize(lp->segtype, lp->chunk_size)) + return 0; + + log_verbose("Setting chunksize to %d sectors.", lp->chunk_size); } else { if (arg_count(cmd, chunksize_ARG)) { log_error("-c is only available with snapshots"); Index: LVM2.2.02.70/tools/tools.h =================================================================== --- LVM2.2.02.70.orig/tools/tools.h 2010-07-10 04:08:37.000000000 +0200 +++ LVM2.2.02.70/tools/tools.h 2010-07-10 04:08:41.000000000 +0200 @@ -170,6 +170,9 @@ int arg_count_increment(struct cmd_conte const char *command_name(struct cmd_context *cmd); +unsigned lvm_default_chunksize(const struct segment_type *segtype); +int lvm_validate_chunksize(const struct segment_type *segtype, uint32_t chunk_size); + int pvmove_poll(struct cmd_context *cmd, const char *pv, unsigned background); int lvconvert_poll(struct cmd_context *cmd, struct logical_volume *lv, unsigned background); Index: LVM2.2.02.70/tools/lvconvert.c =================================================================== --- LVM2.2.02.70.orig/tools/lvconvert.c 2010-07-10 04:08:37.000000000 +0200 +++ LVM2.2.02.70/tools/lvconvert.c 2010-07-10 04:08:41.000000000 +0200 @@ -225,18 +225,16 @@ static int _read_params(struct lvconvert log_error("Negative chunk size is invalid"); return 0; } - 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 " - "range 4K to 512K"); - return 0; - } - log_verbose("Setting chunksize to %d sectors.", lp->chunk_size); if (!(lp->segtype = get_segtype_from_string(cmd, "snapshot"))) return_0; + lp->chunk_size = arg_uint_value(cmd, chunksize_ARG, lvm_default_chunksize(lp->segtype)); + if (!lvm_validate_chunksize(lp->segtype, lp->chunk_size)) + return 0; + + log_verbose("Setting chunksize to %d sectors.", lp->chunk_size); + lp->zero = strcmp(arg_str_value(cmd, zero_ARG, (lp->segtype->flags & SEG_CANNOT_BE_ZEROED) ?