diff --git a/lib/config/defaults.h b/lib/config/defaults.h index 0583fd2be..131796237 100644 --- a/lib/config/defaults.h +++ b/lib/config/defaults.h @@ -60,6 +60,9 @@ #define DEFAULT_DMEVENTD_MONITOR 1 #define DEFAULT_BACKGROUND_POLLING 1 +#define DEFAULT_THIN_POOL_MAX_METADATA_SIZE (16 * 1024 * 1024) /* KB */ +#define DEFAULT_THIN_POOL_MIN_METADATA_SIZE 2048 /* KB */ + #define DEFAULT_UMASK 0077 #ifdef LVM1_FALLBACK diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index f76d1db6d..ef71f4fa3 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -810,8 +810,9 @@ static struct alloc_handle *_alloc_init(struct cmd_context *cmd, } } else if (segtype_is_thin_pool(segtype)) { ah->log_area_count = metadata_area_count; -// FIXME Calculate thin metadata area size (--metadatasize, or reuse --regionsize??) - ah->log_len = 128 * 1024 * 1024 / (512 * extent_size); /* Fixed 128MB */ + /* thin_pool uses region_size to pass metadata size in extents */ + ah->log_len = ah->region_size; + ah->region_size = 0; } else { ah->log_area_count = metadata_area_count; ah->log_len = !metadata_area_count ? 0 : @@ -4161,7 +4162,8 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg, struct l if (!lv_extend(lv, lp->segtype, lp->stripes, lp->stripe_size, - lp->mirrors, lp->region_size, + lp->mirrors, + seg_is_thin_pool(lp) ? lp->poolmetadataextents : lp->region_size, seg_is_thin_volume(lp) ? lp->voriginextents : lp->extents, seg_is_thin_volume(lp) ? lp->pool : NULL, lp->pvh, lp->alloc)) return_NULL; diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index 611fd3378..fff76318e 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -603,6 +603,8 @@ struct lvcreate_params { uint32_t extents; /* all */ uint32_t voriginextents; /* snapshot */ uint64_t voriginsize; /* snapshot */ + uint32_t poolmetadataextents; /* thin pool */ + uint64_t poolmetadatasize; /* thin pool */ struct dm_list *pvh; /* all */ uint32_t permission; /* all */ diff --git a/tools/args.h b/tools/args.h index a61729106..9f0e57940 100644 --- a/tools/args.h +++ b/tools/args.h @@ -69,6 +69,7 @@ arg(dataalignmentoffset_ARG, '\0', "dataalignmentoffset", size_kb_arg, 0) arg(virtualoriginsize_ARG, '\0', "virtualoriginsize", size_mb_arg, 0) arg(noudevsync_ARG, '\0', "noudevsync", NULL, 0) arg(poll_ARG, '\0', "poll", yes_no_arg, 0) +arg(poolmetadatasize_ARG, '\0', "poolmetadatasize", size_mb_arg, 0) arg(stripes_long_ARG, '\0', "stripes", int_arg, 0) arg(sysinit_ARG, '\0', "sysinit", NULL, 0) arg(thinpool_ARG, '\0', "thinpool", string_arg, 0) diff --git a/tools/commands.h b/tools/commands.h index bbc278546..ca6d9f48b 100644 --- a/tools/commands.h +++ b/tools/commands.h @@ -192,6 +192,7 @@ xx(lvcreate, "\t[-i|--stripes Stripes [-I|--stripesize StripeSize]]\n" "\t{-l|--extents LogicalExtentsNumber[%{VG|FREE|ORIGIN}] |\n" "\t -L|--size LogicalVolumeSize[bBsSkKmMgGtTpPeE]}\n" + "\t[--poolmetadatasize Size[bBsSkKmMgG]]\n" "\t[-M|--persistent {y|n}] [--major major] [--minor minor]\n" "\t[-n|--name LogicalVolumeName]\n" "\t[--noudevsync]\n" @@ -210,7 +211,7 @@ xx(lvcreate, noudevsync_ARG, permission_ARG, persistent_ARG, readahead_ARG, regionsize_ARG, size_ARG, snapshot_ARG, stripes_ARG, stripesize_ARG, test_ARG, thin_ARG, thinpool_ARG, type_ARG, virtualoriginsize_ARG, - virtualsize_ARG, zero_ARG) + poolmetadatasize_ARG, virtualsize_ARG, zero_ARG) xx(lvdisplay, "Display information about a logical volume", diff --git a/tools/lvcreate.c b/tools/lvcreate.c index 9b55fd063..ee5eab9cd 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -283,6 +283,17 @@ static int _update_extents_params(struct volume_group *vg, case PERCENT_NONE: break; } + + if (lp->create_thin_pool && !lp->poolmetadatasize) + /* Defaults to nr_pool_blocks * 64b */ + lp->poolmetadatasize = (uint64_t) lp->extents * vg->extent_size / + (uint64_t) lp->chunk_size * UINT64_C(64); + + if (lp->poolmetadatasize && + !(lp->poolmetadataextents = extents_from_size(vg->cmd, lp->poolmetadatasize, + vg->extent_size))) + return_0; + return 1; } @@ -323,6 +334,18 @@ static int _read_size_params(struct lvcreate_params *lp, if (lp->thin && (arg_count(cmd, size_ARG) || arg_count(cmd, extents_ARG))) lp->create_thin_pool = 1; + if (arg_count(cmd, poolmetadatasize_ARG)) { + if (!seg_is_thin(lp)) { + log_error("--poolmetadatasize may only be specified when allocating the thin pool."); + return 0; + } + if (arg_sign_value(cmd, poolmetadatasize_ARG, 0) == SIGN_MINUS) { + log_error("Negative poolmetadatasize is invalid."); + return 0; + } + lp->poolmetadatasize = arg_uint64_value(cmd, poolmetadatasize_ARG, UINT64_C(0)); + } + /* Size returned in kilobyte units; held in sectors */ if (arg_count(cmd, virtualsize_ARG)) { if (seg_is_thin_pool(lp)) { @@ -478,6 +501,33 @@ static int _read_raid_params(struct lvcreate_params *lp, return 1; } +static int _read_thin_params(struct lvcreate_params *lp, + struct cmd_context *cmd) +{ + if (!seg_is_thin(lp)) { + if (lp->poolmetadatasize) { + log_error("Pool metadata size option is only for pool creation."); + return 0; + } + return 1; + } + + if (lp->create_thin_pool) { + if (lp->poolmetadatasize > (2 * DEFAULT_THIN_POOL_MAX_METADATA_SIZE)) { + log_warn("WARNING: Maximum supported pool metadata size is 16GB."); + lp->poolmetadatasize = 2 * DEFAULT_THIN_POOL_MAX_METADATA_SIZE; + } else if (lp->poolmetadatasize < (2 * DEFAULT_THIN_POOL_MIN_METADATA_SIZE)) + lp->poolmetadatasize = 2 * DEFAULT_THIN_POOL_MIN_METADATA_SIZE; + log_verbose("Setting pool metadata size to %" PRIu64 " sectors.", + lp->poolmetadatasize); + } else if (lp->poolmetadatasize) { + log_error("Pool metadata size options is only for pool creation."); + return 0; + } + + return 1; +} + static int _read_activation_params(struct lvcreate_params *lp, struct cmd_context *cmd) { unsigned pagesize; @@ -677,7 +727,8 @@ static int _lvcreate_params(struct lvcreate_params *lp, !_read_size_params(lp, lcp, cmd) || !get_stripe_params(cmd, &lp->stripes, &lp->stripe_size) || !_read_mirror_params(lp, cmd) || - !_read_raid_params(lp, cmd)) + !_read_raid_params(lp, cmd) || + !_read_thin_params(lp, cmd)) return_0; if (lp->snapshot && lp->thin && arg_count(cmd, chunksize_ARG)) @@ -796,6 +847,11 @@ static int _check_thin_parameters(struct volume_group *vg, struct lvcreate_param return 0; } + if (arg_count(vg->cmd, poolmetadatasize_ARG)) { + log_error("--poolmetadatasize may only be specified when allocating the thin pool."); + return 0; + } + if (arg_count(vg->cmd, stripesize_ARG)) { log_error("--stripesize may only be specified when allocating the thin pool."); return 0;