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.84/tools/lvcreate.c =================================================================== --- LVM2.2.02.84.orig/tools/lvcreate.c 2011-05-05 02:11:59.000000000 +0200 +++ LVM2.2.02.84/tools/lvcreate.c 2011-05-05 02:12:26.000000000 +0200 @@ -324,6 +324,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, @@ -378,18 +394,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.84/tools/tools.h =================================================================== --- LVM2.2.02.84.orig/tools/tools.h 2011-05-05 02:11:15.000000000 +0200 +++ LVM2.2.02.84/tools/tools.h 2011-05-05 02:12:26.000000000 +0200 @@ -183,6 +183,9 @@ const char *grouped_arg_str_value(const 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.84/tools/lvconvert.c =================================================================== --- LVM2.2.02.84.orig/tools/lvconvert.c 2011-05-05 02:12:13.000000000 +0200 +++ LVM2.2.02.84/tools/lvconvert.c 2011-05-05 02:12:27.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) ?