master - lvm2app: Implement lv resize (v3)
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=49d7596581be01...
Commit: 49d7596581be013ec71a1da7897f861b721eaa19
Parent: c43ce46ba796d92382b386bbeee933fc7479a9cd
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Mar 13 18:07:16 2013 -0400
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Jul 2 14:24:33 2013 -0500
lvm2app: Implement lv resize (v3)
Simplified version of lv resize.
v3: Rebase changes to make work. Needed to set sizeargs = 1
to indicate to resize that we are asking for a size based
resize.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
lib/metadata/metadata-exported.h | 1 +
liblvm/lvm2app.h | 2 --
liblvm/lvm_lv.c | 20 +++++++++++++++++---
3 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index f07e360..ee8f0c1 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -26,6 +26,7 @@
#include "vg.h"
#include "lv.h"
#include "lvm-percent.h"
+#include "errors.h"
#define MAX_STRIPES 128U
#define SECTOR_SHIFT 9L
diff --git a/liblvm/lvm2app.h b/liblvm/lvm2app.h
index 633b026..25778d1 100644
--- a/liblvm/lvm2app.h
+++ b/liblvm/lvm2app.h
@@ -1374,8 +1374,6 @@ int lvm_lv_rename(lv_t lv, const char *new_name);
*
* \memberof lv_t
*
- * NOTE: This function is currently not implemented.
- *
* \param lv
* Logical volume handle.
*
diff --git a/liblvm/lvm_lv.c b/liblvm/lvm_lv.c
index 2039126..d0f89f1 100644
--- a/liblvm/lvm_lv.c
+++ b/liblvm/lvm_lv.c
@@ -318,9 +318,23 @@ int lvm_lv_rename(lv_t lv, const char *new_name)
int lvm_lv_resize(const lv_t lv, uint64_t new_size)
{
- /* FIXME: add lv resize code here */
- log_error("NOT IMPLEMENTED YET");
- return -1;
+ struct lvresize_params lp = { 0 };
+
+ lp.vg_name = lv->vg->name;
+ lp.lv_name = lv->name;
+ lp.sign = SIGN_NONE;
+ lp.percent = PERCENT_NONE;
+ lp.resize = LV_ANY;
+ lp.size = new_size >> SECTOR_SHIFT;
+ lp.ac_force = 1; /* Assume the user has a good backup? */
+ lp.sizeargs = 1;
+
+ if (ECMD_PROCESSED != lv_resize(lv->vg->cmd, lv->vg, &lp, &lv->vg->pvs)) {
+ log_verbose("LV Re-size failed.");
+ return -1;
+ }
+
+ return 0;
}
lv_t lvm_lv_snapshot(const lv_t lv, const char *snap_name, uint64_t max_snap_size)
10 years, 10 months
master - lvm2app: Move core lv re-size code (v6)
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c43ce46ba796d9...
Commit: c43ce46ba796d92382b386bbeee933fc7479a9cd
Parent: 9d550cfc36ffb13fa0c70c077add7d8d8957180f
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Mar 13 18:00:29 2013 -0400
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Jul 2 14:24:33 2013 -0500
lvm2app: Move core lv re-size code (v6)
Moved to allow use from command line and for library use.
v3,v4,v5,v6: rebase changes
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
lib/metadata/lv_manip.c | 837 ++++++++++++++++++++++++++++++++++++
lib/metadata/metadata-exported.h | 49 +++
tools/lvresize.c | 879 +-------------------------------------
3 files changed, 887 insertions(+), 878 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 76660ae..38f5b45 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -27,6 +27,8 @@
#include "activate.h"
#include "str_list.h"
#include "defaults.h"
+#include "lvm-exec.h"
+#include "errors.h"
typedef enum {
PREFERRED,
@@ -3177,6 +3179,841 @@ int lv_rename(struct cmd_context *cmd, struct logical_volume *lv,
return lv_rename_update(cmd, lv, new_name, 1);
}
+/*
+ * Core lv resize code
+ */
+
+#define SIZE_BUF 128
+
+static int _validate_stripesize(struct cmd_context *cmd,
+ const struct volume_group *vg,
+ struct lvresize_params *lp)
+{
+
+ if ( lp->ac_stripesize_value > STRIPE_SIZE_LIMIT * 2) {
+ log_error("Stripe size cannot be larger than %s",
+ display_size(cmd, (uint64_t) STRIPE_SIZE_LIMIT));
+ return 0;
+ }
+
+ if (!(vg->fid->fmt->features & FMT_SEGMENTS))
+ log_warn("Varied stripesize not supported. Ignoring.");
+ else if (lp->ac_stripesize_value > (uint64_t) vg->extent_size * 2) {
+ log_error("Reducing stripe size %s to maximum, "
+ "physical extent size %s",
+ display_size(cmd,lp->ac_stripesize_value),
+ display_size(cmd, (uint64_t) vg->extent_size));
+ lp->stripe_size = vg->extent_size;
+ } else
+ lp->stripe_size = lp->ac_stripesize_value;
+
+ if (lp->stripe_size & (lp->stripe_size - 1)) {
+ log_error("Stripe size must be power of 2");
+ return 0;
+ }
+
+ return 1;
+}
+
+static int _request_confirmation(struct cmd_context *cmd,
+ const struct volume_group *vg,
+ const struct logical_volume *lv,
+ const struct lvresize_params *lp)
+{
+ struct lvinfo info = { 0 };
+
+ if (!lv_info(cmd, lv, 0, &info, 1, 0) && driver_version(NULL, 0)) {
+ log_error("lv_info failed: aborting");
+ return 0;
+ }
+
+ if (lp->resizefs) {
+ if (!info.exists) {
+ log_error("Logical volume %s must be activated "
+ "before resizing filesystem", lp->lv_name);
+ return 0;
+ }
+ return 1;
+ }
+
+ if (!info.exists)
+ return 1;
+
+ log_warn("WARNING: Reducing active%s logical volume to %s",
+ info.open_count ? " and open" : "",
+ display_size(cmd, (uint64_t) lp->extents * vg->extent_size));
+
+ log_warn("THIS MAY DESTROY YOUR DATA (filesystem etc.)");
+
+ if (!lp->ac_force) {
+ if (yes_no_prompt("Do you really want to reduce %s? [y/n]: ",
+ lp->lv_name) == 'n') {
+ log_error("Logical volume %s NOT reduced", lp->lv_name);
+ return 0;
+ }
+ if (sigint_caught())
+ return 0;
+ }
+
+ return 1;
+}
+
+enum fsadm_cmd_e { FSADM_CMD_CHECK, FSADM_CMD_RESIZE };
+#define FSADM_CMD "fsadm"
+#define FSADM_CMD_MAX_ARGS 6
+#define FSADM_CHECK_FAILS_FOR_MOUNTED 3 /* shell exist status code */
+
+/*
+ * FSADM_CMD --dry-run --verbose --force check lv_path
+ * FSADM_CMD --dry-run --verbose --force resize lv_path size
+ */
+static int _fsadm_cmd(struct cmd_context *cmd,
+ const struct volume_group *vg,
+ const struct lvresize_params *lp,
+ enum fsadm_cmd_e fcmd,
+ int *status)
+{
+ char lv_path[PATH_MAX];
+ char size_buf[SIZE_BUF];
+ const char *argv[FSADM_CMD_MAX_ARGS + 2];
+ unsigned i = 0;
+
+ argv[i++] = FSADM_CMD;
+
+ if (test_mode())
+ argv[i++] = "--dry-run";
+
+ if (verbose_level() >= _LOG_NOTICE)
+ argv[i++] = "--verbose";
+
+ if (lp->ac_force)
+ argv[i++] = "--force";
+
+ argv[i++] = (fcmd == FSADM_CMD_RESIZE) ? "resize" : "check";
+
+ if (status)
+ *status = -1;
+
+ if (dm_snprintf(lv_path, PATH_MAX, "%s%s/%s", cmd->dev_dir, lp->vg_name,
+ lp->lv_name) < 0) {
+ log_error("Couldn't create LV path for %s", lp->lv_name);
+ return 0;
+ }
+
+ argv[i++] = lv_path;
+
+ if (fcmd == FSADM_CMD_RESIZE) {
+ if (dm_snprintf(size_buf, SIZE_BUF, "%" PRIu64 "K",
+ (uint64_t) lp->extents * vg->extent_size / 2) < 0) {
+ log_error("Couldn't generate new LV size string");
+ return 0;
+ }
+
+ argv[i++] = size_buf;
+ }
+
+ argv[i] = NULL;
+
+ return exec_cmd(cmd, argv, status, 1);
+}
+
+static int _adjust_policy_params(struct cmd_context *cmd,
+ struct logical_volume *lv, struct lvresize_params *lp)
+{
+ percent_t percent;
+ int policy_threshold, policy_amount;
+
+ if (lv_is_thin_pool(lv)) {
+ policy_threshold =
+ find_config_tree_int(cmd, activation_thin_pool_autoextend_threshold_CFG,
+ lv_config_profile(lv)) * PERCENT_1;
+ policy_amount =
+ find_config_tree_int(cmd, activation_thin_pool_autoextend_percent_CFG,
+ lv_config_profile(lv));
+ if (!policy_amount && policy_threshold < PERCENT_100)
+ return 0;
+ } else {
+ policy_threshold =
+ find_config_tree_int(cmd, activation_snapshot_autoextend_threshold_CFG, NULL) * PERCENT_1;
+ policy_amount =
+ find_config_tree_int(cmd, activation_snapshot_autoextend_percent_CFG, NULL);
+ }
+
+ if (policy_threshold >= PERCENT_100)
+ return 1; /* nothing to do */
+
+ if (lv_is_thin_pool(lv)) {
+ if (!lv_thin_pool_percent(lv, 1, &percent))
+ return_0;
+ if ((PERCENT_0 < percent && percent <= PERCENT_100) &&
+ (percent > policy_threshold)) {
+ if (!pool_can_resize_metadata(lv)) {
+ log_error_once("Online metadata resize for %s/%s is not supported.",
+ lp->vg_name, lp->lv_name);
+ return 0;
+ }
+ lp->poolmetadatasize = (first_seg(lv)->metadata_lv->size *
+ policy_amount + 99) / 100;
+ lp->poolmetadatasign = SIGN_PLUS;
+ }
+
+ if (!lv_thin_pool_percent(lv, 0, &percent))
+ return_0;
+ if (!(PERCENT_0 < percent && percent <= PERCENT_100) ||
+ percent <= policy_threshold)
+ return 1;
+ } else {
+ if (!lv_snapshot_percent(lv, &percent))
+ return_0;
+ if (!(PERCENT_0 < percent && percent <= PERCENT_100) || percent <= policy_threshold)
+ return 1; /* nothing to do */
+ }
+
+ lp->extents = policy_amount;
+ lp->sizeargs = (lp->extents) ? 1 : 0;
+
+ return 1;
+}
+
+static uint32_t lvseg_get_stripes(struct lv_segment *seg, uint32_t *stripesize)
+{
+ uint32_t s;
+ struct lv_segment *seg_mirr;
+
+ /* If segment mirrored, check if images are striped */
+ if (seg_is_mirrored(seg))
+ for (s = 0; s < seg->area_count; s++) {
+ if (seg_type(seg, s) != AREA_LV)
+ continue;
+ seg_mirr = first_seg(seg_lv(seg, s));
+
+ if (seg_is_striped(seg_mirr)) {
+ seg = seg_mirr;
+ break;
+ }
+ }
+
+
+ if (seg_is_striped(seg)) {
+ *stripesize = seg->stripe_size;
+ return seg->area_count;
+ }
+
+ *stripesize = 0;
+ return 0;
+}
+
+static int _lvresize_poolmetadata(struct cmd_context *cmd, struct volume_group *vg,
+ struct lvresize_params *lp,
+ const struct logical_volume *pool_lv,
+ struct dm_list *pvh,
+ alloc_policy_t alloc)
+{
+ struct logical_volume *lv;
+ struct lv_segment *mseg;
+ uint32_t extents;
+ uint32_t seg_mirrors;
+
+ if (!pool_can_resize_metadata(pool_lv)) {
+ log_error("Support for online metadata resize not detected.");
+ return 0;
+ }
+
+ if (lp->poolmetadatasize % vg->extent_size) {
+ lp->poolmetadatasize += vg->extent_size -
+ (lp->poolmetadatasize % vg->extent_size);
+ log_print_unless_silent("Rounding pool metadata size to boundary between physical extents: %s",
+ display_size(cmd, lp->poolmetadatasize));
+ }
+
+ if (!(extents = extents_from_size(vg->cmd, lp->poolmetadatasize,
+ vg->extent_size)))
+ return_0;
+
+ lv = first_seg(pool_lv)->metadata_lv;
+ if (lp->poolmetadatasign == SIGN_PLUS) {
+ if (extents >= (MAX_EXTENT_COUNT - lv->le_count)) {
+ log_error("Unable to extend %s by %u extents, exceeds limit (%u).",
+ lv->name, lv->le_count, MAX_EXTENT_COUNT);
+ return 0;
+ }
+ extents += lv->le_count;
+ }
+
+ if (extents * vg->extent_size > DM_THIN_MAX_METADATA_SIZE) {
+ log_print_unless_silent("Rounding size to maximum supported size 16GiB "
+ "for metadata volume %s.", lv->name);
+ extents = (DM_THIN_MAX_METADATA_SIZE + vg->extent_size - 1) /
+ vg->extent_size;
+ }
+
+ if (extents == lv->le_count) {
+ log_print_unless_silent("Metadata volume %s has already %s.",
+ lv->name, display_size(cmd, lv->size));
+ return 2;
+ }
+
+ if (!lp->sizeargs && !archive(vg))
+ return_0;
+
+ log_print_unless_silent("Extending logical volume %s to %s.",
+ lv->name,
+ display_size(cmd, (uint64_t) extents * vg->extent_size));
+ mseg = last_seg(lv);
+ seg_mirrors = lv_mirror_count(lv);
+ if (!lv_extend(lv,
+ mseg->segtype,
+ mseg->area_count / seg_mirrors,
+ mseg->stripe_size,
+ seg_mirrors,
+ mseg->region_size,
+ extents - lv->le_count, NULL,
+ pvh, alloc))
+ return_0;
+
+ return 1;
+}
+
+int lv_resize(struct cmd_context *cmd, struct volume_group *vg,
+ struct lvresize_params *lp, struct dm_list *pvh)
+{
+ struct logical_volume *lv;
+ uint32_t stripesize_extents;
+ uint32_t seg_stripes = 0, seg_stripesize = 0, seg_size;
+ uint32_t seg_mirrors = 0;
+ uint32_t extents_used;
+ uint32_t size_rest;
+ uint32_t pv_extent_count;
+ alloc_policy_t alloc;
+ struct logical_volume *lock_lv = NULL;
+ struct lv_list *lvl;
+ struct lv_segment *seg, *uninitialized_var(mirr_seg);
+ uint32_t seg_extents;
+ uint32_t sz, str;
+ int status;
+
+ /* does LV exist? */
+ if (!(lvl = find_lv_in_vg(vg, lp->lv_name))) {
+ log_error("Logical volume %s not found in volume group %s",
+ lp->lv_name, lp->vg_name);
+ return ECMD_FAILED;
+ }
+
+ lv = lvl->lv;
+
+ if (lv_is_external_origin(lv)) {
+ /*
+ * Since external-origin can be activated read-only,
+ * there is no way to use extended areas.
+ */
+ log_error("Cannot resize external origin \"%s\".", lv->name);
+ return EINVALID_CMD_LINE;
+ }
+
+ if (lv->status & (RAID_IMAGE | RAID_META)) {
+ log_error("Cannot resize a RAID %s directly",
+ (lv->status & RAID_IMAGE) ? "image" :
+ "metadata area");
+ return ECMD_FAILED;
+ }
+
+ if (lv_is_raid_with_tracking(lv)) {
+ log_error("Cannot resize %s while it is tracking a split image",
+ lv->name);
+ return ECMD_FAILED;
+ }
+
+ if (lp->ac_stripes) {
+ if (vg->fid->fmt->features & FMT_SEGMENTS)
+ lp->stripes = lp->ac_stripes_value;
+ else
+ log_warn("Varied striping not supported. Ignoring.");
+ }
+
+ if (lp->ac_mirrors) {
+ if (vg->fid->fmt->features & FMT_SEGMENTS)
+ lp->mirrors = lp->ac_mirrors_value;
+ else
+ log_warn("Mirrors not supported. Ignoring.");
+ }
+
+ if (lp->ac_stripesize &&
+ !_validate_stripesize(cmd, vg, lp))
+ return EINVALID_CMD_LINE;
+
+ if (lp->ac_policy) {
+ if (!lv_is_cow(lv) &&
+ !lv_is_thin_pool(lv)) {
+ log_error("Policy-based resize is supported only for snapshot and thin pool volumes.");
+ return ECMD_FAILED;
+ }
+ if (!_adjust_policy_params(cmd, lv, lp))
+ return_ECMD_FAILED;
+ }
+
+ if (!lv_is_visible(lv) &&
+ !lv_is_thin_pool_metadata(lv)) {
+ log_error("Can't resize internal logical volume %s", lv->name);
+ return ECMD_FAILED;
+ }
+
+ if (lv->status & LOCKED) {
+ log_error("Can't resize locked LV %s", lv->name);
+ return ECMD_FAILED;
+ }
+
+ if (lv->status & CONVERTING) {
+ log_error("Can't resize %s while lvconvert in progress", lv->name);
+ return ECMD_FAILED;
+ }
+
+ alloc = (alloc_policy_t)(lp->ac_alloc)?lp->ac_alloc: lv->alloc;
+
+ /*
+ * First adjust to an exact multiple of extent size.
+ * When extending by a relative amount we round that amount up.
+ * When reducing by a relative amount we remove at most that amount.
+ * When changing to an absolute size, we round that size up.
+ */
+ if (lp->size) {
+ if (lp->size % vg->extent_size) {
+ if (lp->sign == SIGN_MINUS)
+ lp->size -= lp->size % vg->extent_size;
+ else
+ lp->size += vg->extent_size -
+ (lp->size % vg->extent_size);
+
+ log_print_unless_silent("Rounding size to boundary between physical extents: %s",
+ display_size(cmd, lp->size));
+ }
+
+ lp->extents = lp->size / vg->extent_size;
+ }
+
+ if (lp->sizeargs) { /* TODO: reindent or move to function */
+
+ switch(lp->percent) {
+ case PERCENT_VG:
+ lp->extents = percent_of_extents(lp->extents, vg->extent_count,
+ (lp->sign != SIGN_MINUS));
+ break;
+ case PERCENT_FREE:
+ lp->extents = percent_of_extents(lp->extents, vg->free_count,
+ (lp->sign != SIGN_MINUS));
+ break;
+ case PERCENT_LV:
+ lp->extents = percent_of_extents(lp->extents, lv->le_count,
+ (lp->sign != SIGN_MINUS));
+ break;
+ case PERCENT_PVS:
+ if (lp->argc) {
+ pv_extent_count = pv_list_extents_free(pvh);
+ lp->extents = percent_of_extents(lp->extents, pv_extent_count,
+ (lp->sign != SIGN_MINUS));
+ } else
+ lp->extents = percent_of_extents(lp->extents, vg->extent_count,
+ (lp->sign != SIGN_MINUS));
+ break;
+ case PERCENT_ORIGIN:
+ if (!lv_is_cow(lv)) {
+ log_error("Specified LV does not have an origin LV.");
+ return EINVALID_CMD_LINE;
+ }
+ lp->extents = percent_of_extents(lp->extents, origin_from_cow(lv)->le_count,
+ (lp->sign != SIGN_MINUS));
+ break;
+ case PERCENT_NONE:
+ break;
+ }
+
+ if (lp->sign == SIGN_PLUS) {
+ if (lp->extents >= (MAX_EXTENT_COUNT - lv->le_count)) {
+ log_error("Unable to extend %s by %u extents, exceeds limit (%u).",
+ lp->lv_name, lv->le_count, MAX_EXTENT_COUNT);
+ return EINVALID_CMD_LINE;
+ }
+ lp->extents += lv->le_count;
+ if (lv_is_cow(lv)) {
+ extents_used = cow_max_extents(origin_from_cow(lv), find_cow(lv)->chunk_size);
+ if (extents_used < lp->extents) {
+ log_print_unless_silent("Reached maximum COW size %s.",
+ display_size(vg->cmd, (uint64_t) vg->extent_size * extents_used));
+ lp->extents = extents_used;
+ if (lp->extents == lv->le_count)
+ return ECMD_PROCESSED;
+ }
+ }
+ } else if (lp->sign == SIGN_MINUS) {
+ if (lp->extents >= lv->le_count) {
+ log_error("Unable to reduce %s below 1 extent",
+ lp->lv_name);
+ return EINVALID_CMD_LINE;
+ }
+
+ lp->extents = lv->le_count - lp->extents;
+ }
+
+ if (!lp->extents) {
+ log_error("New size of 0 not permitted");
+ return EINVALID_CMD_LINE;
+ }
+
+ if (lp->extents == lv->le_count) {
+ /* A bit of hack - but still may resize metadata */
+ if (lp->poolmetadatasize) {
+ lp->sizeargs = 0;
+ goto metadata_resize;
+ }
+ if (lp->ac_policy)
+ return ECMD_PROCESSED; /* Nothing to do. */
+ if (!lp->resizefs) {
+ log_error("New size (%d extents) matches existing size "
+ "(%d extents)", lp->extents, lv->le_count);
+ return EINVALID_CMD_LINE;
+ }
+ lp->resize = LV_EXTEND; /* lets pretend zero size extension */
+ }
+
+ seg_size = lp->extents - lv->le_count;
+
+ /* Use segment type of last segment */
+ lp->segtype = last_seg(lv)->segtype;
+
+ /* FIXME Support LVs with mixed segment types */
+ if (lp->segtype != get_segtype_from_string(cmd, (lp->ac_type)?lp->ac_type:lp->segtype->name)) {
+ log_error("VolumeType does not match (%s)", lp->segtype->name);
+ return EINVALID_CMD_LINE;
+ }
+
+ /* If extending, find mirrors of last segment */
+ if ((lp->extents > lv->le_count)) {
+ /*
+ * Has the user specified that they would like the additional
+ * extents of a mirror not to have an initial sync?
+ */
+ if (seg_is_mirrored(first_seg(lv)) && lp->ac_no_sync)
+ lv->status |= LV_NOTSYNCED;
+
+ dm_list_iterate_back_items(mirr_seg, &lv->segments) {
+ if (seg_is_mirrored(mirr_seg))
+ seg_mirrors = lv_mirror_count(mirr_seg->lv);
+ else
+ seg_mirrors = 0;
+ break;
+ }
+
+ if (!lp->ac_mirrors && seg_mirrors) {
+ log_print_unless_silent("Extending %" PRIu32 " mirror images.",
+ seg_mirrors);
+ lp->mirrors = seg_mirrors;
+ }
+ if ((lp->ac_mirrors || seg_mirrors) &&
+ (lp->mirrors != seg_mirrors)) {
+ log_error("Cannot vary number of mirrors in LV yet.");
+ return EINVALID_CMD_LINE;
+ }
+
+ if (seg_mirrors && !strcmp(mirr_seg->segtype->name, "raid10")) {
+ lp->stripes = mirr_seg->area_count / seg_mirrors;
+ lp->stripe_size = mirr_seg->stripe_size;
+ }
+ }
+
+ /* If extending, find stripes, stripesize & size of last segment */
+ if ((lp->extents > lv->le_count) &&
+ !(lp->stripes == 1 || (lp->stripes > 1 && lp->stripe_size)) &&
+ strcmp(mirr_seg->segtype->name, "raid10")) {
+ /* FIXME Don't assume mirror seg will always be AREA_LV */
+ /* FIXME We will need to support resize for metadata LV as well,
+ * and data LV could be any type (i.e. mirror)) */
+ dm_list_iterate_items(seg, seg_mirrors ? &seg_lv(mirr_seg, 0)->segments :
+ lv_is_thin_pool(lv) ? &seg_lv(first_seg(lv), 0)->segments : &lv->segments) {
+ /* Allow through "striped" and RAID 4/5/6/10 */
+ if (!seg_is_striped(seg) &&
+ (!seg_is_raid(seg) || seg_is_mirrored(seg)) &&
+ strcmp(seg->segtype->name, "raid10"))
+ continue;
+
+ sz = seg->stripe_size;
+ str = seg->area_count - lp->segtype->parity_devs;
+
+ if ((seg_stripesize && seg_stripesize != sz &&
+ sz && !lp->stripe_size) ||
+ (seg_stripes && seg_stripes != str && !lp->stripes)) {
+ log_error("Please specify number of "
+ "stripes (-i) and stripesize (-I)");
+ return EINVALID_CMD_LINE;
+ }
+
+ seg_stripesize = sz;
+ seg_stripes = str;
+ }
+
+ if (!lp->stripes)
+ lp->stripes = seg_stripes;
+ else if (seg_is_raid(first_seg(lv)) &&
+ (lp->stripes != seg_stripes)) {
+ log_error("Unable to extend \"%s\" segment type with different number of stripes.", first_seg(lv)->segtype->ops->name(first_seg(lv)));
+ return ECMD_FAILED;
+ }
+
+ if (!lp->stripe_size && lp->stripes > 1) {
+ if (seg_stripesize) {
+ log_print_unless_silent("Using stripesize of last segment %s",
+ display_size(cmd, (uint64_t) seg_stripesize));
+ lp->stripe_size = seg_stripesize;
+ } else {
+ lp->stripe_size =
+ find_config_tree_int(cmd, metadata_stripesize_CFG, NULL) * 2;
+ log_print_unless_silent("Using default stripesize %s",
+ display_size(cmd, (uint64_t) lp->stripe_size));
+ }
+ }
+ }
+
+ /* If reducing, find stripes, stripesize & size of last segment */
+ if (lp->extents < lv->le_count) {
+ extents_used = 0;
+
+ if (lp->stripes || lp->stripe_size || lp->mirrors)
+ log_error("Ignoring stripes, stripesize and mirrors "
+ "arguments when reducing");
+
+ dm_list_iterate_items(seg, &lv->segments) {
+ seg_extents = seg->len;
+
+ /* Check for underlying stripe sizes */
+ seg_stripes = lvseg_get_stripes(seg, &seg_stripesize);
+
+ if (seg_is_mirrored(seg))
+ seg_mirrors = lv_mirror_count(seg->lv);
+ else
+ seg_mirrors = 0;
+
+ if (lp->extents <= extents_used + seg_extents)
+ break;
+
+ extents_used += seg_extents;
+ }
+
+ seg_size = lp->extents - extents_used;
+ lp->stripe_size = seg_stripesize;
+ lp->stripes = seg_stripes;
+ lp->mirrors = seg_mirrors;
+ }
+
+ if (lp->stripes > 1 && !lp->stripe_size) {
+ log_error("Stripesize for striped segment should not be 0!");
+ return EINVALID_CMD_LINE;
+ }
+
+ if (lp->stripes > 1) {
+ if (lp->stripe_size < STRIPE_SIZE_MIN) {
+ log_error("Invalid stripe size %s",
+ display_size(cmd, (uint64_t) lp->stripe_size));
+ return EINVALID_CMD_LINE;
+ }
+
+ if (!(stripesize_extents = lp->stripe_size / vg->extent_size))
+ stripesize_extents = 1;
+
+ size_rest = seg_size % (lp->stripes * stripesize_extents);
+ /* Round toward the original size. */
+ if (size_rest &&
+ ((lp->extents < lv->le_count) ||
+ !lp->percent ||
+ (vg->free_count >= (lp->extents - lv->le_count - size_rest +
+ (lp->stripes * stripesize_extents))))) {
+ log_print_unless_silent("Rounding size (%d extents) up to stripe "
+ "boundary size for segment (%d extents)",
+ lp->extents, lp->extents - size_rest +
+ (lp->stripes * stripesize_extents));
+ lp->extents = lp->extents - size_rest +
+ (lp->stripes * stripesize_extents);
+ } else if (size_rest) {
+ log_print_unless_silent("Rounding size (%d extents) down to stripe "
+ "boundary size for segment (%d extents)",
+ lp->extents, lp->extents - size_rest);
+ lp->extents = lp->extents - size_rest;
+ }
+ }
+
+ if (lp->extents < lv->le_count) {
+ if (lp->resize == LV_EXTEND) {
+ log_error("New size given (%d extents) not larger "
+ "than existing size (%d extents)",
+ lp->extents, lv->le_count);
+ return EINVALID_CMD_LINE;
+ }
+ lp->resize = LV_REDUCE;
+ } else if (lp->extents > lv->le_count) {
+ if (lp->resize == LV_REDUCE) {
+ log_error("New size given (%d extents) not less than "
+ "existing size (%d extents)", lp->extents,
+ lv->le_count);
+ return EINVALID_CMD_LINE;
+ }
+ lp->resize = LV_EXTEND;
+ } else if (lp->extents == lv->le_count) {
+ if (lp->ac_policy)
+ return ECMD_PROCESSED; /* Nothing to do. */
+ if (!lp->resizefs) {
+ log_error("New size (%d extents) matches existing size "
+ "(%d extents)", lp->extents, lv->le_count);
+ return EINVALID_CMD_LINE;
+ }
+ lp->resize = LV_EXTEND;
+ }
+
+ if (lv_is_origin(lv)) {
+ if (lp->resize == LV_REDUCE) {
+ log_error("Snapshot origin volumes cannot be reduced "
+ "in size yet.");
+ return ECMD_FAILED;
+ }
+
+ if (lv_is_active(lv)) {
+ log_error("Snapshot origin volumes can be resized "
+ "only while inactive: try lvchange -an");
+ return ECMD_FAILED;
+ }
+ }
+
+ if (lv_is_thin_pool(lv)) {
+ if (lp->resize == LV_REDUCE) {
+ log_error("Thin pool volumes cannot be reduced in size yet.");
+ return ECMD_FAILED;
+ }
+
+ if (lp->resizefs) {
+ log_warn("Thin pool volumes do not have filesystem.");
+ lp->resizefs = 0;
+ }
+ } else if (lp->poolmetadatasize) {
+ log_error("--poolmetadatasize can be used only with thin pools.");
+ return ECMD_FAILED;
+ }
+
+ if ((lp->resize == LV_REDUCE) && lp->argc)
+ log_warn("Ignoring PVs on command line when reducing");
+
+ /* Request confirmation before operations that are often mistakes. */
+ if ((lp->resizefs || (lp->resize == LV_REDUCE)) &&
+ !_request_confirmation(cmd, vg, lv, lp))
+ return_ECMD_FAILED;
+
+ if (lp->resizefs) {
+ if (!lp->nofsck &&
+ !_fsadm_cmd(cmd, vg, lp, FSADM_CMD_CHECK, &status)) {
+ if (status != FSADM_CHECK_FAILS_FOR_MOUNTED) {
+ log_error("Filesystem check failed.");
+ return ECMD_FAILED;
+ }
+ /* some filesystems supports online resize */
+ }
+
+ if ((lp->resize == LV_REDUCE) &&
+ !_fsadm_cmd(cmd, vg, lp, FSADM_CMD_RESIZE, NULL)) {
+ log_error("Filesystem resize failed.");
+ return ECMD_FAILED;
+ }
+ }
+
+ if (!archive(vg))
+ return_ECMD_FAILED;
+
+ log_print_unless_silent("%sing logical volume %s to %s",
+ (lp->resize == LV_REDUCE) ? "Reduc" : "Extend",
+ lv->name,
+ display_size(cmd, (uint64_t) lp->extents * vg->extent_size));
+
+ if (lp->resize == LV_REDUCE) {
+ if (!lv_reduce(lv, lv->le_count - lp->extents))
+ return ECMD_FAILED;
+ } else if ((lp->extents > lv->le_count) && /* Ensure we extend */
+ !lv_extend(lv, lp->segtype,
+ lp->stripes, lp->stripe_size,
+ lp->mirrors, first_seg(lv)->region_size,
+ lp->extents - lv->le_count, NULL,
+ pvh, alloc))
+ return_ECMD_FAILED;
+
+ /* If thin metadata, must suspend thin pool */
+ if (lv_is_thin_pool_metadata(lv)) {
+ if (!(lock_lv = find_pool_lv(lv)))
+ return_0;
+ /* If snapshot, must suspend all associated devices */
+ } else if (lv_is_cow(lv))
+ lock_lv = origin_from_cow(lv);
+ else
+ lock_lv = lv;
+
+ } /* lp->sizeargs */
+
+ if (lp->poolmetadatasize) {
+metadata_resize:
+ if (!(status = _lvresize_poolmetadata(cmd, vg, lp, lv, pvh, alloc)))
+ return_ECMD_FAILED;
+ else if ((status == 2) && !lp->sizeargs)
+ return ECMD_PROCESSED;
+ lock_lv = lv;
+ }
+
+ if (!lock_lv)
+ return ECMD_PROCESSED; /* Nothing to do */
+
+ /* store vg on disk(s) */
+ if (!vg_write(vg))
+ return_ECMD_FAILED;
+
+ if (!suspend_lv(cmd, lock_lv)) {
+ log_error("Failed to suspend %s", lock_lv->name);
+ vg_revert(vg);
+ backup(vg);
+ return ECMD_FAILED;
+ }
+
+ if (!vg_commit(vg)) {
+ stack;
+ if (!resume_lv(cmd, lock_lv))
+ stack;
+ backup(vg);
+ return ECMD_FAILED;
+ }
+
+ if (!resume_lv(cmd, lock_lv)) {
+ log_error("Problem reactivating %s", lock_lv->name);
+ backup(vg);
+ return ECMD_FAILED;
+ }
+
+ if (lv_is_cow_covering_origin(lv))
+ if (!monitor_dev_for_events(cmd, lv, 0, 0))
+ stack;
+
+ backup(vg);
+
+ /*
+ * Update lvm pool metadata (drop messages) if the pool has been
+ * resumed and do a pool active/deactivate in other case.
+ *
+ * Note: Active thin pool can be waiting for resize.
+ *
+ * FIXME: Activate only when thin volume is active
+ */
+ if (lv_is_thin_pool(lv) &&
+ !update_pool_lv(lv, !lv_is_active(lv)))
+ return_ECMD_FAILED;
+
+ log_print_unless_silent("Logical volume %s successfully resized", lp->lv_name);
+
+ if (lp->resizefs && (lp->resize == LV_EXTEND) &&
+ !_fsadm_cmd(cmd, vg, lp, FSADM_CMD_RESIZE, NULL))
+ return_ECMD_FAILED;
+
+ return ECMD_PROCESSED;
+}
+
char *generate_lv_name(struct volume_group *vg, const char *format,
char *buffer, size_t len)
{
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 50d9d2c..f07e360 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -429,6 +429,52 @@ struct pvcreate_params {
struct pvcreate_restorable_params rp;
};
+struct lvresize_params {
+ const char *vg_name;
+ const char *lv_name;
+
+ uint32_t stripes;
+ uint32_t stripe_size;
+ uint32_t mirrors;
+
+ const struct segment_type *segtype;
+
+ /* size */
+ uint32_t extents;
+ uint64_t size;
+ int sizeargs;
+ sign_t sign;
+ uint64_t poolmetadatasize;
+ sign_t poolmetadatasign;
+ percent_type_t percent;
+
+ enum {
+ LV_ANY = 0,
+ LV_REDUCE = 1,
+ LV_EXTEND = 2
+ } resize;
+
+ int resizefs;
+ int nofsck;
+
+ int argc;
+ char **argv;
+
+ /* Arg counts & values */
+ unsigned ac_policy;
+ unsigned ac_stripes;
+ uint32_t ac_stripes_value;
+ unsigned ac_mirrors;
+ uint32_t ac_mirrors_value;
+ unsigned ac_stripesize;
+ uint64_t ac_stripesize_value;
+ unsigned ac_alloc;
+ unsigned ac_no_sync;
+ unsigned ac_force;
+
+ const char *ac_type;
+};
+
struct physical_volume *pvcreate_single(struct cmd_context *cmd,
const char *pv_name,
struct pvcreate_params *pp,
@@ -475,6 +521,9 @@ int vgs_are_compatible(struct cmd_context *cmd,
struct volume_group *vg_to);
uint32_t vg_lock_newname(struct cmd_context *cmd, const char *vgname);
+int lv_resize(struct cmd_context *cmd, struct volume_group *vg,
+ struct lvresize_params *lp, struct dm_list *pvh);
+
/*
* Return a handle to VG metadata.
*/
diff --git a/tools/lvresize.c b/tools/lvresize.c
index f08fa91..7c73341 100644
--- a/tools/lvresize.c
+++ b/tools/lvresize.c
@@ -15,186 +15,6 @@
#include "tools.h"
-#define SIZE_BUF 128
-
-struct lvresize_params {
- const char *vg_name;
- const char *lv_name;
-
- uint32_t stripes;
- uint32_t stripe_size;
- uint32_t mirrors;
-
- const struct segment_type *segtype;
-
- /* size */
- uint32_t extents;
- uint64_t size;
- int sizeargs;
- sign_t sign;
- uint64_t poolmetadatasize;
- sign_t poolmetadatasign;
- percent_type_t percent;
-
- enum {
- LV_ANY = 0,
- LV_REDUCE = 1,
- LV_EXTEND = 2
- } resize;
-
- int resizefs;
- int nofsck;
-
- int argc;
- char **argv;
-
- /* Arg counts & values */
- unsigned ac_policy;
- unsigned ac_stripes;
- uint32_t ac_stripes_value;
- unsigned ac_mirrors;
- uint32_t ac_mirrors_value;
- unsigned ac_stripesize;
- uint64_t ac_stripesize_value;
- unsigned ac_alloc;
- unsigned ac_no_sync;
- unsigned ac_force;
-
- const char *ac_type;
-};
-
-static int _validate_stripesize(struct cmd_context *cmd,
- const struct volume_group *vg,
- struct lvresize_params *lp)
-{
-
- if ( lp->ac_stripesize_value > STRIPE_SIZE_LIMIT * 2) {
- log_error("Stripe size cannot be larger than %s",
- display_size(cmd, (uint64_t) STRIPE_SIZE_LIMIT));
- return 0;
- }
-
- if (!(vg->fid->fmt->features & FMT_SEGMENTS))
- log_warn("Varied stripesize not supported. Ignoring.");
- else if (lp->ac_stripesize_value > (uint64_t) vg->extent_size * 2) {
- log_error("Reducing stripe size %s to maximum, "
- "physical extent size %s",
- display_size(cmd,lp->ac_stripesize_value),
- display_size(cmd, (uint64_t) vg->extent_size));
- lp->stripe_size = vg->extent_size;
- } else
- lp->stripe_size = lp->ac_stripesize_value;
-
- if (lp->stripe_size & (lp->stripe_size - 1)) {
- log_error("Stripe size must be power of 2");
- return 0;
- }
-
- return 1;
-}
-
-static int _request_confirmation(struct cmd_context *cmd,
- const struct volume_group *vg,
- const struct logical_volume *lv,
- const struct lvresize_params *lp)
-{
- struct lvinfo info = { 0 };
-
- if (!lv_info(cmd, lv, 0, &info, 1, 0) && driver_version(NULL, 0)) {
- log_error("lv_info failed: aborting");
- return 0;
- }
-
- if (lp->resizefs) {
- if (!info.exists) {
- log_error("Logical volume %s must be activated "
- "before resizing filesystem", lp->lv_name);
- return 0;
- }
- return 1;
- }
-
- if (!info.exists)
- return 1;
-
- log_warn("WARNING: Reducing active%s logical volume to %s",
- info.open_count ? " and open" : "",
- display_size(cmd, (uint64_t) lp->extents * vg->extent_size));
-
- log_warn("THIS MAY DESTROY YOUR DATA (filesystem etc.)");
-
- if (!lp->ac_force) {
- if (yes_no_prompt("Do you really want to reduce %s? [y/n]: ",
- lp->lv_name) == 'n') {
- log_error("Logical volume %s NOT reduced", lp->lv_name);
- return 0;
- }
- if (sigint_caught())
- return 0;
- }
-
- return 1;
-}
-
-enum fsadm_cmd_e { FSADM_CMD_CHECK, FSADM_CMD_RESIZE };
-#define FSADM_CMD "fsadm"
-#define FSADM_CMD_MAX_ARGS 6
-#define FSADM_CHECK_FAILS_FOR_MOUNTED 3 /* shell exist status code */
-
-/*
- * FSADM_CMD --dry-run --verbose --force check lv_path
- * FSADM_CMD --dry-run --verbose --force resize lv_path size
- */
-static int _fsadm_cmd(struct cmd_context *cmd,
- const struct volume_group *vg,
- const struct lvresize_params *lp,
- enum fsadm_cmd_e fcmd,
- int *status)
-{
- char lv_path[PATH_MAX];
- char size_buf[SIZE_BUF];
- const char *argv[FSADM_CMD_MAX_ARGS + 2];
- unsigned i = 0;
-
- argv[i++] = FSADM_CMD;
-
- if (test_mode())
- argv[i++] = "--dry-run";
-
- if (verbose_level() >= _LOG_NOTICE)
- argv[i++] = "--verbose";
-
- if (lp->ac_force)
- argv[i++] = "--force";
-
- argv[i++] = (fcmd == FSADM_CMD_RESIZE) ? "resize" : "check";
-
- if (status)
- *status = -1;
-
- if (dm_snprintf(lv_path, PATH_MAX, "%s%s/%s", cmd->dev_dir, lp->vg_name,
- lp->lv_name) < 0) {
- log_error("Couldn't create LV path for %s", lp->lv_name);
- return 0;
- }
-
- argv[i++] = lv_path;
-
- if (fcmd == FSADM_CMD_RESIZE) {
- if (dm_snprintf(size_buf, SIZE_BUF, "%" PRIu64 "K",
- (uint64_t) lp->extents * vg->extent_size / 2) < 0) {
- log_error("Couldn't generate new LV size string");
- return 0;
- }
-
- argv[i++] = size_buf;
- }
-
- argv[i] = NULL;
-
- return exec_cmd(cmd, argv, status, 1);
-}
-
static int _lvresize_params(struct cmd_context *cmd, int argc, char **argv,
struct lvresize_params *lp)
{
@@ -344,703 +164,6 @@ static int _lvresize_params(struct cmd_context *cmd, int argc, char **argv,
return 1;
}
-static int _adjust_policy_params(struct cmd_context *cmd,
- struct logical_volume *lv, struct lvresize_params *lp)
-{
- percent_t percent;
- int policy_threshold, policy_amount;
-
- if (lv_is_thin_pool(lv)) {
- policy_threshold =
- find_config_tree_int(cmd, activation_thin_pool_autoextend_threshold_CFG,
- lv_config_profile(lv)) * PERCENT_1;
- policy_amount =
- find_config_tree_int(cmd, activation_thin_pool_autoextend_percent_CFG,
- lv_config_profile(lv));
- if (!policy_amount && policy_threshold < PERCENT_100)
- return 0;
- } else {
- policy_threshold =
- find_config_tree_int(cmd, activation_snapshot_autoextend_threshold_CFG, NULL) * PERCENT_1;
- policy_amount =
- find_config_tree_int(cmd, activation_snapshot_autoextend_percent_CFG, NULL);
- }
-
- if (policy_threshold >= PERCENT_100)
- return 1; /* nothing to do */
-
- if (lv_is_thin_pool(lv)) {
- if (!lv_thin_pool_percent(lv, 1, &percent))
- return_0;
- if ((PERCENT_0 < percent && percent <= PERCENT_100) &&
- (percent > policy_threshold)) {
- if (!pool_can_resize_metadata(lv)) {
- log_error_once("Online metadata resize for %s/%s is not supported.",
- lp->vg_name, lp->lv_name);
- return 0;
- }
- lp->poolmetadatasize = (first_seg(lv)->metadata_lv->size *
- policy_amount + 99) / 100;
- lp->poolmetadatasign = SIGN_PLUS;
- }
-
- if (!lv_thin_pool_percent(lv, 0, &percent))
- return_0;
- if (!(PERCENT_0 < percent && percent <= PERCENT_100) ||
- percent <= policy_threshold)
- return 1;
- } else {
- if (!lv_snapshot_percent(lv, &percent))
- return_0;
- if (!(PERCENT_0 < percent && percent <= PERCENT_100) || percent <= policy_threshold)
- return 1; /* nothing to do */
- }
-
- lp->extents = policy_amount;
- lp->sizeargs = (lp->extents) ? 1 : 0;
-
- return 1;
-}
-
-static uint32_t lvseg_get_stripes(struct lv_segment *seg, uint32_t *stripesize)
-{
- uint32_t s;
- struct lv_segment *seg_mirr;
-
- /* If segment mirrored, check if images are striped */
- if (seg_is_mirrored(seg))
- for (s = 0; s < seg->area_count; s++) {
- if (seg_type(seg, s) != AREA_LV)
- continue;
- seg_mirr = first_seg(seg_lv(seg, s));
-
- if (seg_is_striped(seg_mirr)) {
- seg = seg_mirr;
- break;
- }
- }
-
-
- if (seg_is_striped(seg)) {
- *stripesize = seg->stripe_size;
- return seg->area_count;
- }
-
- *stripesize = 0;
- return 0;
-}
-
-static int _lvresize_poolmetadata(struct cmd_context *cmd, struct volume_group *vg,
- struct lvresize_params *lp,
- const struct logical_volume *pool_lv,
- struct dm_list *pvh,
- alloc_policy_t alloc)
-{
- struct logical_volume *lv;
- struct lv_segment *mseg;
- uint32_t extents;
- uint32_t seg_mirrors;
-
- if (!pool_can_resize_metadata(pool_lv)) {
- log_error("Support for online metadata resize not detected.");
- return 0;
- }
-
- if (lp->poolmetadatasize % vg->extent_size) {
- lp->poolmetadatasize += vg->extent_size -
- (lp->poolmetadatasize % vg->extent_size);
- log_print_unless_silent("Rounding pool metadata size to boundary between physical extents: %s",
- display_size(cmd, lp->poolmetadatasize));
- }
-
- if (!(extents = extents_from_size(vg->cmd, lp->poolmetadatasize,
- vg->extent_size)))
- return_0;
-
- lv = first_seg(pool_lv)->metadata_lv;
- if (lp->poolmetadatasign == SIGN_PLUS) {
- if (extents >= (MAX_EXTENT_COUNT - lv->le_count)) {
- log_error("Unable to extend %s by %u extents, exceeds limit (%u).",
- lv->name, lv->le_count, MAX_EXTENT_COUNT);
- return 0;
- }
- extents += lv->le_count;
- }
-
- if (extents * vg->extent_size > DM_THIN_MAX_METADATA_SIZE) {
- log_print_unless_silent("Rounding size to maximum supported size 16GiB "
- "for metadata volume %s.", lv->name);
- extents = (DM_THIN_MAX_METADATA_SIZE + vg->extent_size - 1) /
- vg->extent_size;
- }
-
- if (extents == lv->le_count) {
- log_print_unless_silent("Metadata volume %s has already %s.",
- lv->name, display_size(cmd, lv->size));
- return 2;
- }
-
- if (!lp->sizeargs && !archive(vg))
- return_0;
-
- log_print_unless_silent("Extending logical volume %s to %s.",
- lv->name,
- display_size(cmd, (uint64_t) extents * vg->extent_size));
- mseg = last_seg(lv);
- seg_mirrors = lv_mirror_count(lv);
- if (!lv_extend(lv,
- mseg->segtype,
- mseg->area_count / seg_mirrors,
- mseg->stripe_size,
- seg_mirrors,
- mseg->region_size,
- extents - lv->le_count, NULL,
- pvh, alloc))
- return_0;
-
- return 1;
-}
-
-static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
- struct lvresize_params *lp, struct dm_list *pvh)
-{
- struct logical_volume *lv;
- uint32_t stripesize_extents;
- uint32_t seg_stripes = 0, seg_stripesize = 0, seg_size;
- uint32_t seg_mirrors = 0;
- uint32_t extents_used;
- uint32_t size_rest;
- uint32_t pv_extent_count;
- alloc_policy_t alloc;
- struct logical_volume *lock_lv = NULL;
- struct lv_list *lvl;
- struct lv_segment *seg, *uninitialized_var(mirr_seg);
- uint32_t seg_extents;
- uint32_t sz, str;
- int status;
-
- /* does LV exist? */
- if (!(lvl = find_lv_in_vg(vg, lp->lv_name))) {
- log_error("Logical volume %s not found in volume group %s",
- lp->lv_name, lp->vg_name);
- return ECMD_FAILED;
- }
-
- lv = lvl->lv;
-
- if (lv_is_external_origin(lv)) {
- /*
- * Since external-origin can be activated read-only,
- * there is no way to use extended areas.
- */
- log_error("Cannot resize external origin \"%s\".", lv->name);
- return EINVALID_CMD_LINE;
- }
-
- if (lv->status & (RAID_IMAGE | RAID_META)) {
- log_error("Cannot resize a RAID %s directly",
- (lv->status & RAID_IMAGE) ? "image" :
- "metadata area");
- return ECMD_FAILED;
- }
-
- if (lv_is_raid_with_tracking(lv)) {
- log_error("Cannot resize %s while it is tracking a split image",
- lv->name);
- return ECMD_FAILED;
- }
-
- if (lp->ac_stripes) {
- if (vg->fid->fmt->features & FMT_SEGMENTS)
- lp->stripes = lp->ac_stripes_value;
- else
- log_warn("Varied striping not supported. Ignoring.");
- }
-
- if (lp->ac_mirrors) {
- if (vg->fid->fmt->features & FMT_SEGMENTS)
- lp->mirrors = lp->ac_mirrors_value;
- else
- log_warn("Mirrors not supported. Ignoring.");
- }
-
- if (lp->ac_stripesize &&
- !_validate_stripesize(cmd, vg, lp))
- return EINVALID_CMD_LINE;
-
- if (lp->ac_policy) {
- if (!lv_is_cow(lv) &&
- !lv_is_thin_pool(lv)) {
- log_error("Policy-based resize is supported only for snapshot and thin pool volumes.");
- return ECMD_FAILED;
- }
- if (!_adjust_policy_params(cmd, lv, lp))
- return_ECMD_FAILED;
- }
-
- if (!lv_is_visible(lv) &&
- !lv_is_thin_pool_metadata(lv)) {
- log_error("Can't resize internal logical volume %s", lv->name);
- return ECMD_FAILED;
- }
-
- if (lv->status & LOCKED) {
- log_error("Can't resize locked LV %s", lv->name);
- return ECMD_FAILED;
- }
-
- if (lv->status & CONVERTING) {
- log_error("Can't resize %s while lvconvert in progress", lv->name);
- return ECMD_FAILED;
- }
-
- alloc = (alloc_policy_t)(lp->ac_alloc)?lp->ac_alloc: lv->alloc;
-
- /*
- * First adjust to an exact multiple of extent size.
- * When extending by a relative amount we round that amount up.
- * When reducing by a relative amount we remove at most that amount.
- * When changing to an absolute size, we round that size up.
- */
- if (lp->size) {
- if (lp->size % vg->extent_size) {
- if (lp->sign == SIGN_MINUS)
- lp->size -= lp->size % vg->extent_size;
- else
- lp->size += vg->extent_size -
- (lp->size % vg->extent_size);
-
- log_print_unless_silent("Rounding size to boundary between physical extents: %s",
- display_size(cmd, lp->size));
- }
-
- lp->extents = lp->size / vg->extent_size;
- }
-
- if (lp->sizeargs) { /* TODO: reindent or move to function */
-
- switch(lp->percent) {
- case PERCENT_VG:
- lp->extents = percent_of_extents(lp->extents, vg->extent_count,
- (lp->sign != SIGN_MINUS));
- break;
- case PERCENT_FREE:
- lp->extents = percent_of_extents(lp->extents, vg->free_count,
- (lp->sign != SIGN_MINUS));
- break;
- case PERCENT_LV:
- lp->extents = percent_of_extents(lp->extents, lv->le_count,
- (lp->sign != SIGN_MINUS));
- break;
- case PERCENT_PVS:
- if (lp->argc) {
- pv_extent_count = pv_list_extents_free(pvh);
- lp->extents = percent_of_extents(lp->extents, pv_extent_count,
- (lp->sign != SIGN_MINUS));
- } else
- lp->extents = percent_of_extents(lp->extents, vg->extent_count,
- (lp->sign != SIGN_MINUS));
- break;
- case PERCENT_ORIGIN:
- if (!lv_is_cow(lv)) {
- log_error("Specified LV does not have an origin LV.");
- return EINVALID_CMD_LINE;
- }
- lp->extents = percent_of_extents(lp->extents, origin_from_cow(lv)->le_count,
- (lp->sign != SIGN_MINUS));
- break;
- case PERCENT_NONE:
- break;
- }
-
- if (lp->sign == SIGN_PLUS) {
- if (lp->extents >= (MAX_EXTENT_COUNT - lv->le_count)) {
- log_error("Unable to extend %s by %u extents, exceeds limit (%u).",
- lp->lv_name, lv->le_count, MAX_EXTENT_COUNT);
- return EINVALID_CMD_LINE;
- }
- lp->extents += lv->le_count;
- if (lv_is_cow(lv)) {
- extents_used = cow_max_extents(origin_from_cow(lv), find_cow(lv)->chunk_size);
- if (extents_used < lp->extents) {
- log_print_unless_silent("Reached maximum COW size %s.",
- display_size(vg->cmd, (uint64_t) vg->extent_size * extents_used));
- lp->extents = extents_used;
- if (lp->extents == lv->le_count)
- return ECMD_PROCESSED;
- }
- }
- } else if (lp->sign == SIGN_MINUS) {
- if (lp->extents >= lv->le_count) {
- log_error("Unable to reduce %s below 1 extent",
- lp->lv_name);
- return EINVALID_CMD_LINE;
- }
-
- lp->extents = lv->le_count - lp->extents;
- }
-
- if (!lp->extents) {
- log_error("New size of 0 not permitted");
- return EINVALID_CMD_LINE;
- }
-
- if (lp->extents == lv->le_count) {
- /* A bit of hack - but still may resize metadata */
- if (lp->poolmetadatasize) {
- lp->sizeargs = 0;
- goto metadata_resize;
- }
- if (lp->ac_policy)
- return ECMD_PROCESSED; /* Nothing to do. */
- if (!lp->resizefs) {
- log_error("New size (%d extents) matches existing size "
- "(%d extents)", lp->extents, lv->le_count);
- return EINVALID_CMD_LINE;
- }
- lp->resize = LV_EXTEND; /* lets pretend zero size extension */
- }
-
- seg_size = lp->extents - lv->le_count;
-
- /* Use segment type of last segment */
- lp->segtype = last_seg(lv)->segtype;
-
- /* FIXME Support LVs with mixed segment types */
- if (lp->segtype != get_segtype_from_string(cmd, (lp->ac_type)?lp->ac_type:lp->segtype->name)) {
- log_error("VolumeType does not match (%s)", lp->segtype->name);
- return EINVALID_CMD_LINE;
- }
-
- /* If extending, find mirrors of last segment */
- if ((lp->extents > lv->le_count)) {
- /*
- * Has the user specified that they would like the additional
- * extents of a mirror not to have an initial sync?
- */
- if (seg_is_mirrored(first_seg(lv)) && lp->ac_no_sync)
- lv->status |= LV_NOTSYNCED;
-
- dm_list_iterate_back_items(mirr_seg, &lv->segments) {
- if (seg_is_mirrored(mirr_seg))
- seg_mirrors = lv_mirror_count(mirr_seg->lv);
- else
- seg_mirrors = 0;
- break;
- }
-
- if (!lp->ac_mirrors && seg_mirrors) {
- log_print_unless_silent("Extending %" PRIu32 " mirror images.",
- seg_mirrors);
- lp->mirrors = seg_mirrors;
- }
- if ((lp->ac_mirrors || seg_mirrors) &&
- (lp->mirrors != seg_mirrors)) {
- log_error("Cannot vary number of mirrors in LV yet.");
- return EINVALID_CMD_LINE;
- }
-
- if (seg_mirrors && !strcmp(mirr_seg->segtype->name, "raid10")) {
- lp->stripes = mirr_seg->area_count / seg_mirrors;
- lp->stripe_size = mirr_seg->stripe_size;
- }
- }
-
- /* If extending, find stripes, stripesize & size of last segment */
- if ((lp->extents > lv->le_count) &&
- !(lp->stripes == 1 || (lp->stripes > 1 && lp->stripe_size)) &&
- strcmp(mirr_seg->segtype->name, "raid10")) {
- /* FIXME Don't assume mirror seg will always be AREA_LV */
- /* FIXME We will need to support resize for metadata LV as well,
- * and data LV could be any type (i.e. mirror)) */
- dm_list_iterate_items(seg, seg_mirrors ? &seg_lv(mirr_seg, 0)->segments :
- lv_is_thin_pool(lv) ? &seg_lv(first_seg(lv), 0)->segments : &lv->segments) {
- /* Allow through "striped" and RAID 4/5/6/10 */
- if (!seg_is_striped(seg) &&
- (!seg_is_raid(seg) || seg_is_mirrored(seg)) &&
- strcmp(seg->segtype->name, "raid10"))
- continue;
-
- sz = seg->stripe_size;
- str = seg->area_count - lp->segtype->parity_devs;
-
- if ((seg_stripesize && seg_stripesize != sz &&
- sz && !lp->stripe_size) ||
- (seg_stripes && seg_stripes != str && !lp->stripes)) {
- log_error("Please specify number of "
- "stripes (-i) and stripesize (-I)");
- return EINVALID_CMD_LINE;
- }
-
- seg_stripesize = sz;
- seg_stripes = str;
- }
-
- if (!lp->stripes)
- lp->stripes = seg_stripes;
- else if (seg_is_raid(first_seg(lv)) &&
- (lp->stripes != seg_stripes)) {
- log_error("Unable to extend \"%s\" segment type with different number of stripes.", first_seg(lv)->segtype->ops->name(first_seg(lv)));
- return ECMD_FAILED;
- }
-
- if (!lp->stripe_size && lp->stripes > 1) {
- if (seg_stripesize) {
- log_print_unless_silent("Using stripesize of last segment %s",
- display_size(cmd, (uint64_t) seg_stripesize));
- lp->stripe_size = seg_stripesize;
- } else {
- lp->stripe_size =
- find_config_tree_int(cmd, metadata_stripesize_CFG, NULL) * 2;
- log_print_unless_silent("Using default stripesize %s",
- display_size(cmd, (uint64_t) lp->stripe_size));
- }
- }
- }
-
- /* If reducing, find stripes, stripesize & size of last segment */
- if (lp->extents < lv->le_count) {
- extents_used = 0;
-
- if (lp->stripes || lp->stripe_size || lp->mirrors)
- log_error("Ignoring stripes, stripesize and mirrors "
- "arguments when reducing");
-
- dm_list_iterate_items(seg, &lv->segments) {
- seg_extents = seg->len;
-
- /* Check for underlying stripe sizes */
- seg_stripes = lvseg_get_stripes(seg, &seg_stripesize);
-
- if (seg_is_mirrored(seg))
- seg_mirrors = lv_mirror_count(seg->lv);
- else
- seg_mirrors = 0;
-
- if (lp->extents <= extents_used + seg_extents)
- break;
-
- extents_used += seg_extents;
- }
-
- seg_size = lp->extents - extents_used;
- lp->stripe_size = seg_stripesize;
- lp->stripes = seg_stripes;
- lp->mirrors = seg_mirrors;
- }
-
- if (lp->stripes > 1 && !lp->stripe_size) {
- log_error("Stripesize for striped segment should not be 0!");
- return EINVALID_CMD_LINE;
- }
-
- if (lp->stripes > 1) {
- if (lp->stripe_size < STRIPE_SIZE_MIN) {
- log_error("Invalid stripe size %s",
- display_size(cmd, (uint64_t) lp->stripe_size));
- return EINVALID_CMD_LINE;
- }
-
- if (!(stripesize_extents = lp->stripe_size / vg->extent_size))
- stripesize_extents = 1;
-
- size_rest = seg_size % (lp->stripes * stripesize_extents);
- /* Round toward the original size. */
- if (size_rest &&
- ((lp->extents < lv->le_count) ||
- !lp->percent ||
- (vg->free_count >= (lp->extents - lv->le_count - size_rest +
- (lp->stripes * stripesize_extents))))) {
- log_print_unless_silent("Rounding size (%d extents) up to stripe "
- "boundary size for segment (%d extents)",
- lp->extents, lp->extents - size_rest +
- (lp->stripes * stripesize_extents));
- lp->extents = lp->extents - size_rest +
- (lp->stripes * stripesize_extents);
- } else if (size_rest) {
- log_print_unless_silent("Rounding size (%d extents) down to stripe "
- "boundary size for segment (%d extents)",
- lp->extents, lp->extents - size_rest);
- lp->extents = lp->extents - size_rest;
- }
- }
-
- if (lp->extents < lv->le_count) {
- if (lp->resize == LV_EXTEND) {
- log_error("New size given (%d extents) not larger "
- "than existing size (%d extents)",
- lp->extents, lv->le_count);
- return EINVALID_CMD_LINE;
- }
- lp->resize = LV_REDUCE;
- } else if (lp->extents > lv->le_count) {
- if (lp->resize == LV_REDUCE) {
- log_error("New size given (%d extents) not less than "
- "existing size (%d extents)", lp->extents,
- lv->le_count);
- return EINVALID_CMD_LINE;
- }
- lp->resize = LV_EXTEND;
- } else if (lp->extents == lv->le_count) {
- if (lp->ac_policy)
- return ECMD_PROCESSED; /* Nothing to do. */
- if (!lp->resizefs) {
- log_error("New size (%d extents) matches existing size "
- "(%d extents)", lp->extents, lv->le_count);
- return EINVALID_CMD_LINE;
- }
- lp->resize = LV_EXTEND;
- }
-
- if (lv_is_origin(lv)) {
- if (lp->resize == LV_REDUCE) {
- log_error("Snapshot origin volumes cannot be reduced "
- "in size yet.");
- return ECMD_FAILED;
- }
-
- if (lv_is_active(lv)) {
- log_error("Snapshot origin volumes can be resized "
- "only while inactive: try lvchange -an");
- return ECMD_FAILED;
- }
- }
-
- if (lv_is_thin_pool(lv)) {
- if (lp->resize == LV_REDUCE) {
- log_error("Thin pool volumes cannot be reduced in size yet.");
- return ECMD_FAILED;
- }
-
- if (lp->resizefs) {
- log_warn("Thin pool volumes do not have filesystem.");
- lp->resizefs = 0;
- }
- } else if (lp->poolmetadatasize) {
- log_error("--poolmetadatasize can be used only with thin pools.");
- return ECMD_FAILED;
- }
-
- if ((lp->resize == LV_REDUCE) && lp->argc)
- log_warn("Ignoring PVs on command line when reducing");
-
- /* Request confirmation before operations that are often mistakes. */
- if ((lp->resizefs || (lp->resize == LV_REDUCE)) &&
- !_request_confirmation(cmd, vg, lv, lp))
- return_ECMD_FAILED;
-
- if (lp->resizefs) {
- if (!lp->nofsck &&
- !_fsadm_cmd(cmd, vg, lp, FSADM_CMD_CHECK, &status)) {
- if (status != FSADM_CHECK_FAILS_FOR_MOUNTED) {
- log_error("Filesystem check failed.");
- return ECMD_FAILED;
- }
- /* some filesystems supports online resize */
- }
-
- if ((lp->resize == LV_REDUCE) &&
- !_fsadm_cmd(cmd, vg, lp, FSADM_CMD_RESIZE, NULL)) {
- log_error("Filesystem resize failed.");
- return ECMD_FAILED;
- }
- }
-
- if (!archive(vg))
- return_ECMD_FAILED;
-
- log_print_unless_silent("%sing logical volume %s to %s",
- (lp->resize == LV_REDUCE) ? "Reduc" : "Extend",
- lv->name,
- display_size(cmd, (uint64_t) lp->extents * vg->extent_size));
-
- if (lp->resize == LV_REDUCE) {
- if (!lv_reduce(lv, lv->le_count - lp->extents))
- return ECMD_FAILED;
- } else if ((lp->extents > lv->le_count) && /* Ensure we extend */
- !lv_extend(lv, lp->segtype,
- lp->stripes, lp->stripe_size,
- lp->mirrors, first_seg(lv)->region_size,
- lp->extents - lv->le_count, NULL,
- pvh, alloc))
- return_ECMD_FAILED;
-
- /* If thin metadata, must suspend thin pool */
- if (lv_is_thin_pool_metadata(lv)) {
- if (!(lock_lv = find_pool_lv(lv)))
- return_0;
- /* If snapshot, must suspend all associated devices */
- } else if (lv_is_cow(lv))
- lock_lv = origin_from_cow(lv);
- else
- lock_lv = lv;
-
- } /* lp->sizeargs */
-
- if (lp->poolmetadatasize) {
-metadata_resize:
- if (!(status = _lvresize_poolmetadata(cmd, vg, lp, lv, pvh, alloc)))
- return_ECMD_FAILED;
- else if ((status == 2) && !lp->sizeargs)
- return ECMD_PROCESSED;
- lock_lv = lv;
- }
-
- if (!lock_lv)
- return ECMD_PROCESSED; /* Nothing to do */
-
- /* store vg on disk(s) */
- if (!vg_write(vg))
- return_ECMD_FAILED;
-
- if (!suspend_lv(cmd, lock_lv)) {
- log_error("Failed to suspend %s", lock_lv->name);
- vg_revert(vg);
- backup(vg);
- return ECMD_FAILED;
- }
-
- if (!vg_commit(vg)) {
- stack;
- if (!resume_lv(cmd, lock_lv))
- stack;
- backup(vg);
- return ECMD_FAILED;
- }
-
- if (!resume_lv(cmd, lock_lv)) {
- log_error("Problem reactivating %s", lock_lv->name);
- backup(vg);
- return ECMD_FAILED;
- }
-
- if (lv_is_cow_covering_origin(lv))
- if (!monitor_dev_for_events(cmd, lv, 0, 0))
- stack;
-
- backup(vg);
-
- /*
- * Update lvm pool metadata (drop messages) if the pool has been
- * resumed and do a pool active/deactivate in other case.
- *
- * Note: Active thin pool can be waiting for resize.
- *
- * FIXME: Activate only when thin volume is active
- */
- if (lv_is_thin_pool(lv) &&
- !update_pool_lv(lv, !lv_is_active(lv)))
- return_ECMD_FAILED;
-
- log_print_unless_silent("Logical volume %s successfully resized", lp->lv_name);
-
- if (lp->resizefs && (lp->resize == LV_EXTEND) &&
- !_fsadm_cmd(cmd, vg, lp, FSADM_CMD_RESIZE, NULL))
- return_ECMD_FAILED;
-
- return ECMD_PROCESSED;
-}
-
int lvresize(struct cmd_context *cmd, int argc, char **argv)
{
struct lvresize_params lp = { 0 };
@@ -1064,7 +187,7 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
return_ECMD_FAILED;
}
- if (!(r = _lvresize(cmd, vg, &lp, pvh)))
+ if (!(r = lv_resize(cmd, vg, &lp, pvh)))
stack;
unlock_and_release_vg(cmd, vg, lp.vg_name);
10 years, 10 months
master - lvm2app: Rework argument handling for lv resize
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=9d550cfc36ffb1...
Commit: 9d550cfc36ffb13fa0c70c077add7d8d8957180f
Parent: 60c78e6aef9b744d6313ac0cf3ebb62b74066eb3
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Jan 8 16:39:00 2013 -0600
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Jul 2 14:24:33 2013 -0500
lvm2app: Rework argument handling for lv resize
Extend the lv resize parameter structure to contain everything
the re-size functions need so that the command line does not
need to be present for lower level calls when we call from
library functions.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
tools/lvresize.c | 116 ++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 79 insertions(+), 37 deletions(-)
diff --git a/tools/lvresize.c b/tools/lvresize.c
index 47cb6aa..f08fa91 100644
--- a/tools/lvresize.c
+++ b/tools/lvresize.c
@@ -47,18 +47,28 @@ struct lvresize_params {
int argc;
char **argv;
+
+ /* Arg counts & values */
+ unsigned ac_policy;
+ unsigned ac_stripes;
+ uint32_t ac_stripes_value;
+ unsigned ac_mirrors;
+ uint32_t ac_mirrors_value;
+ unsigned ac_stripesize;
+ uint64_t ac_stripesize_value;
+ unsigned ac_alloc;
+ unsigned ac_no_sync;
+ unsigned ac_force;
+
+ const char *ac_type;
};
static int _validate_stripesize(struct cmd_context *cmd,
const struct volume_group *vg,
struct lvresize_params *lp)
{
- if (arg_sign_value(cmd, stripesize_ARG, SIGN_NONE) == SIGN_MINUS) {
- log_error("Stripesize may not be negative.");
- return 0;
- }
- if (arg_uint64_value(cmd, stripesize_ARG, 0) > STRIPE_SIZE_LIMIT * 2) {
+ if ( lp->ac_stripesize_value > STRIPE_SIZE_LIMIT * 2) {
log_error("Stripe size cannot be larger than %s",
display_size(cmd, (uint64_t) STRIPE_SIZE_LIMIT));
return 0;
@@ -66,15 +76,14 @@ 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) > (uint64_t) vg->extent_size * 2) {
+ else if (lp->ac_stripesize_value > (uint64_t) 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)),
+ display_size(cmd,lp->ac_stripesize_value),
display_size(cmd, (uint64_t) vg->extent_size));
lp->stripe_size = vg->extent_size;
} else
- lp->stripe_size = arg_uint_value(cmd, stripesize_ARG, 0);
+ lp->stripe_size = lp->ac_stripesize_value;
if (lp->stripe_size & (lp->stripe_size - 1)) {
log_error("Stripe size must be power of 2");
@@ -114,7 +123,7 @@ static int _request_confirmation(struct cmd_context *cmd,
log_warn("THIS MAY DESTROY YOUR DATA (filesystem etc.)");
- if (!arg_count(cmd, force_ARG)) {
+ if (!lp->ac_force) {
if (yes_no_prompt("Do you really want to reduce %s? [y/n]: ",
lp->lv_name) == 'n') {
log_error("Logical volume %s NOT reduced", lp->lv_name);
@@ -155,7 +164,7 @@ static int _fsadm_cmd(struct cmd_context *cmd,
if (verbose_level() >= _LOG_NOTICE)
argv[i++] = "--verbose";
- if (arg_count(cmd, force_ARG))
+ if (lp->ac_force)
argv[i++] = "--force";
argv[i++] = (fcmd == FSADM_CMD_RESIZE) ? "resize" : "check";
@@ -295,6 +304,43 @@ static int _lvresize_params(struct cmd_context *cmd, int argc, char **argv,
lp->argc = argc;
lp->argv = argv;
+ lp->ac_policy = arg_count(cmd, use_policies_ARG);
+ lp->ac_stripes = arg_count(cmd, stripes_ARG);
+ if (lp->ac_stripes) {
+ lp->ac_stripes_value = arg_uint_value(cmd, stripes_ARG, 1);
+ } else {
+ lp->ac_stripes_value = 0;
+ }
+
+ lp->ac_mirrors = arg_count(cmd, mirrors_ARG);
+
+ if (lp->ac_mirrors) {
+ if (arg_sign_value(cmd, mirrors_ARG, SIGN_NONE) == SIGN_MINUS) {
+ log_error("Mirrors argument may not be negative");
+ return 0;
+ }
+
+ lp->ac_mirrors_value = arg_uint_value(cmd, mirrors_ARG, 1) + 1;
+ } else {
+ lp->ac_mirrors_value = 0;
+ }
+
+ lp->ac_stripesize = arg_count(cmd, stripesize_ARG);
+ if (lp->ac_stripesize) {
+ if (arg_sign_value(cmd, stripesize_ARG, SIGN_NONE) == SIGN_MINUS) {
+ log_error("Stripesize may not be negative.");
+ return 0;
+ }
+
+ lp->ac_stripesize_value = arg_uint64_value(cmd, stripesize_ARG, 0);
+ }
+
+ lp->ac_no_sync = arg_count(cmd, nosync_ARG);
+ lp->ac_alloc = arg_uint_value(cmd, alloc_ARG, 0);
+
+ lp->ac_type = arg_str_value(cmd, type_ARG, NULL);
+ lp->ac_force = arg_count(cmd, force_ARG);
+
return 1;
}
@@ -456,7 +502,7 @@ static int _lvresize_poolmetadata(struct cmd_context *cmd, struct volume_group *
}
static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
- struct lvresize_params *lp)
+ struct lvresize_params *lp, struct dm_list *pvh)
{
struct logical_volume *lv;
uint32_t stripesize_extents;
@@ -472,8 +518,6 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
uint32_t seg_extents;
uint32_t sz, str;
int status;
- struct dm_list *pvh = NULL;
- int use_policy = arg_count(cmd, use_policies_ARG);
/* does LV exist? */
if (!(lvl = find_lv_in_vg(vg, lp->lv_name))) {
@@ -506,29 +550,25 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
return ECMD_FAILED;
}
- if (arg_count(cmd, stripes_ARG)) {
+ if (lp->ac_stripes) {
if (vg->fid->fmt->features & FMT_SEGMENTS)
- lp->stripes = arg_uint_value(cmd, stripes_ARG, 1);
+ lp->stripes = lp->ac_stripes_value;
else
log_warn("Varied striping not supported. Ignoring.");
}
- if (arg_count(cmd, mirrors_ARG)) {
+ if (lp->ac_mirrors) {
if (vg->fid->fmt->features & FMT_SEGMENTS)
- lp->mirrors = arg_uint_value(cmd, mirrors_ARG, 1) + 1;
+ lp->mirrors = lp->ac_mirrors_value;
else
log_warn("Mirrors not supported. Ignoring.");
- if (arg_sign_value(cmd, mirrors_ARG, SIGN_NONE) == SIGN_MINUS) {
- log_error("Mirrors argument may not be negative");
- return EINVALID_CMD_LINE;
- }
}
- if (arg_count(cmd, stripesize_ARG) &&
+ if (lp->ac_stripesize &&
!_validate_stripesize(cmd, vg, lp))
return EINVALID_CMD_LINE;
- if (use_policy) {
+ if (lp->ac_policy) {
if (!lv_is_cow(lv) &&
!lv_is_thin_pool(lv)) {
log_error("Policy-based resize is supported only for snapshot and thin pool volumes.");
@@ -554,7 +594,7 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
return ECMD_FAILED;
}
- alloc = (alloc_policy_t) arg_uint_value(cmd, alloc_ARG, lv->alloc);
+ alloc = (alloc_policy_t)(lp->ac_alloc)?lp->ac_alloc: lv->alloc;
/*
* First adjust to an exact multiple of extent size.
@@ -577,10 +617,6 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
lp->extents = lp->size / vg->extent_size;
}
- if (!(pvh = lp->argc ? create_pv_list(cmd->mem, vg, lp->argc,
- lp->argv, 1) : &vg->pvs))
- return_ECMD_FAILED;
-
if (lp->sizeargs) { /* TODO: reindent or move to function */
switch(lp->percent) {
@@ -655,7 +691,7 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
lp->sizeargs = 0;
goto metadata_resize;
}
- if (use_policy)
+ if (lp->ac_policy)
return ECMD_PROCESSED; /* Nothing to do. */
if (!lp->resizefs) {
log_error("New size (%d extents) matches existing size "
@@ -671,8 +707,7 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
lp->segtype = last_seg(lv)->segtype;
/* FIXME Support LVs with mixed segment types */
- if (lp->segtype != get_segtype_from_string(cmd, arg_str_value(cmd, type_ARG,
- lp->segtype->name))) {
+ if (lp->segtype != get_segtype_from_string(cmd, (lp->ac_type)?lp->ac_type:lp->segtype->name)) {
log_error("VolumeType does not match (%s)", lp->segtype->name);
return EINVALID_CMD_LINE;
}
@@ -683,7 +718,7 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
* Has the user specified that they would like the additional
* extents of a mirror not to have an initial sync?
*/
- if (seg_is_mirrored(first_seg(lv)) && arg_count(cmd, nosync_ARG))
+ if (seg_is_mirrored(first_seg(lv)) && lp->ac_no_sync)
lv->status |= LV_NOTSYNCED;
dm_list_iterate_back_items(mirr_seg, &lv->segments) {
@@ -694,12 +729,12 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
break;
}
- if (!arg_count(cmd, mirrors_ARG) && seg_mirrors) {
+ if (!lp->ac_mirrors && seg_mirrors) {
log_print_unless_silent("Extending %" PRIu32 " mirror images.",
seg_mirrors);
lp->mirrors = seg_mirrors;
}
- if ((arg_count(cmd, mirrors_ARG) || seg_mirrors) &&
+ if ((lp->ac_mirrors || seg_mirrors) &&
(lp->mirrors != seg_mirrors)) {
log_error("Cannot vary number of mirrors in LV yet.");
return EINVALID_CMD_LINE;
@@ -847,7 +882,7 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
}
lp->resize = LV_EXTEND;
} else if (lp->extents == lv->le_count) {
- if (use_policy)
+ if (lp->ac_policy)
return ECMD_PROCESSED; /* Nothing to do. */
if (!lp->resizefs) {
log_error("New size (%d extents) matches existing size "
@@ -1011,6 +1046,7 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
struct lvresize_params lp = { 0 };
struct volume_group *vg;
int r;
+ struct dm_list *pvh = NULL;
if (!_lvresize_params(cmd, argc, argv, &lp))
return EINVALID_CMD_LINE;
@@ -1022,7 +1058,13 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
return_ECMD_FAILED;
}
- if (!(r = _lvresize(cmd, vg, &lp)))
+ /* How does this list get cleaned up? */
+ if (!(pvh = lp.argc ? create_pv_list(cmd->mem, vg, lp.argc,
+ lp.argv, 1) : &vg->pvs)) {
+ return_ECMD_FAILED;
+ }
+
+ if (!(r = _lvresize(cmd, vg, &lp, pvh)))
stack;
unlock_and_release_vg(cmd, vg, lp.vg_name);
10 years, 10 months
master - lvm2app: Move percent_of_extents to lvm-percent.[h|c]
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=60c78e6aef9b74...
Commit: 60c78e6aef9b744d6313ac0cf3ebb62b74066eb3
Parent: d52b6be455126e7b6a46c39127ca343982955b19
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Jan 8 14:29:56 2013 -0600
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Jul 2 14:24:33 2013 -0500
lvm2app: Move percent_of_extents to lvm-percent.[h|c]
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
lib/misc/lvm-percent.c | 5 +++++
lib/misc/lvm-percent.h | 17 +++++++++++++++++
tools/toollib.c | 6 ------
tools/tools.h | 16 ----------------
4 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/lib/misc/lvm-percent.c b/lib/misc/lvm-percent.c
index 4b73db4..1dafa57 100644
--- a/lib/misc/lvm-percent.c
+++ b/lib/misc/lvm-percent.c
@@ -38,3 +38,8 @@ percent_t make_percent(uint64_t numerator, uint64_t denominator)
}
}
+uint32_t percent_of_extents(uint32_t percents, uint32_t count, int roundup)
+{
+ return (uint32_t)(((uint64_t)percents * (uint64_t)count +
+ ((roundup) ? 99 : 0)) / 100);
+}
diff --git a/lib/misc/lvm-percent.h b/lib/misc/lvm-percent.h
index bf30a7e..ff3de42 100644
--- a/lib/misc/lvm-percent.h
+++ b/lib/misc/lvm-percent.h
@@ -31,6 +31,21 @@
typedef int32_t percent_t;
typedef enum {
+ SIGN_NONE = 0,
+ SIGN_PLUS = 1,
+ SIGN_MINUS = 2
+} sign_t;
+
+typedef enum {
+ PERCENT_NONE = 0,
+ PERCENT_VG,
+ PERCENT_FREE,
+ PERCENT_LV,
+ PERCENT_PVS,
+ PERCENT_ORIGIN
+} percent_type_t;
+
+typedef enum {
PERCENT_0 = 0,
PERCENT_1 = 1000000,
PERCENT_100 = 100 * PERCENT_1,
@@ -41,4 +56,6 @@ typedef enum {
float percent_to_float(percent_t v);
percent_t make_percent(uint64_t numerator, uint64_t denominator);
+uint32_t percent_of_extents(uint32_t percents, uint32_t count, int roundup);
+
#endif
diff --git a/tools/toollib.c b/tools/toollib.c
index 46eb864..6e23e17 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1746,9 +1746,3 @@ int change_tag(struct cmd_context *cmd, struct volume_group *vg,
return 1;
}
-/* Return percents of extents and avoid overflow, with optional roundup */
-uint32_t percent_of_extents(uint32_t percents, uint32_t count, int roundup)
-{
- return (uint32_t)(((uint64_t)percents * (uint64_t)count +
- ((roundup) ? 99 : 0)) / 100);
-}
diff --git a/tools/tools.h b/tools/tools.h
index 15d1f84..6e820bf 100644
--- a/tools/tools.h
+++ b/tools/tools.h
@@ -74,21 +74,6 @@ enum {
#undef arg
};
-typedef enum {
- SIGN_NONE = 0,
- SIGN_PLUS = 1,
- SIGN_MINUS = 2
-} sign_t;
-
-typedef enum {
- PERCENT_NONE = 0,
- PERCENT_VG,
- PERCENT_FREE,
- PERCENT_LV,
- PERCENT_PVS,
- PERCENT_ORIGIN
-} percent_type_t;
-
#define ARG_COUNTABLE 0x00000001 /* E.g. -vvvv */
#define ARG_GROUPABLE 0x00000002 /* E.g. --addtag */
@@ -189,7 +174,6 @@ int lvconvert_poll(struct cmd_context *cmd, struct logical_volume *lv, unsigned
int mirror_remove_missing(struct cmd_context *cmd,
struct logical_volume *lv, int force);
-uint32_t percent_of_extents(uint32_t percents, uint32_t count, int roundup);
int vgchange_activate(struct cmd_context *cmd, struct volume_group *vg,
activation_change_t activate);
10 years, 10 months
master - lvm2app: Implementation of pv resize (v6)
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d52b6be455126e...
Commit: d52b6be455126e7b6a46c39127ca343982955b19
Parent: 4d5de8322b3a6050def60542b167b46d97b2824d
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Mar 13 14:39:56 2013 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Jul 2 14:24:33 2013 -0500
lvm2app: Implementation of pv resize (v6)
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
liblvm/lvm2app.h | 2 --
liblvm/lvm_pv.c | 20 +++++++++++++++++---
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/liblvm/lvm2app.h b/liblvm/lvm2app.h
index b1d6abd..633b026 100644
--- a/liblvm/lvm2app.h
+++ b/liblvm/lvm2app.h
@@ -1759,8 +1759,6 @@ pv_t lvm_pv_from_uuid(vg_t vg, const char *uuid);
*
* \memberof pv_t
*
- * NOTE: This function is currently not implemented.
- *
* \param pv
* Physical volume handle.
*
diff --git a/liblvm/lvm_pv.c b/liblvm/lvm_pv.c
index 3924af4..18b1069 100644
--- a/liblvm/lvm_pv.c
+++ b/liblvm/lvm_pv.c
@@ -123,7 +123,21 @@ pv_t lvm_pv_from_uuid(vg_t vg, const char *uuid)
int lvm_pv_resize(const pv_t pv, uint64_t new_size)
{
- /* FIXME: add pv resize code here */
- log_error("NOT IMPLEMENTED YET");
- return -1;
+ uint64_t size = new_size >> SECTOR_SHIFT;
+
+ if (new_size % SECTOR_SIZE) {
+ log_errno(EINVAL, "Size not a multiple of 512");
+ return -1;
+ }
+
+ if (!vg_check_write_mode(pv->vg)) {
+ return -1;
+ }
+
+ if (!pv_resize(pv, pv->vg, size)) {
+ log_error("PV re-size failed!");
+ return -1;
+ } else {
+ return 0;
+ }
}
10 years, 10 months
master - lvm2app: Add thin and thin pool lv creation V5
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=4d5de8322b3a60...
Commit: 4d5de8322b3a6050def60542b167b46d97b2824d
Parent: fd94dd3b7e9e55029dd79274da18d8503fa12ebf
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Apr 17 11:59:21 2013 +0530
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Jul 2 14:24:33 2013 -0500
lvm2app: Add thin and thin pool lv creation V5
Add thin and thin pool lv creation support to lvm library
This is Mohan's thinp patch, re-worked to include suggestions
from Zdenek and Mohan.
V2: Remove const lvm_lv_params_create_thin
Add const lvm_lv_params_skip_zero_get
V3: Changed get/set to use generic functions like current
property
V4: Corrected macro in properties.c
V5: Fixed a bug in liblvm/lvm_lv.c function lvm_lv_create.
incorrectly used pool instead of lv_name when doing the
find_lv_in_vg call.
Based on work done by M. Mohan Kumar <mohan(a)in.ibm.com>
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
lib/report/columns.h | 2 +
lib/report/properties.c | 30 +++++++
lib/report/properties.h | 6 ++
lib/report/report.c | 1 +
lib/report/report.h | 3 +-
liblvm/lvm2app.h | 133 +++++++++++++++++++++++++++++
liblvm/lvm_lv.c | 212 ++++++++++++++++++++++++++++++++++++++++++++++-
liblvm/lvm_misc.c | 16 +++-
liblvm/lvm_misc.h | 6 +-
liblvm/lvm_pv.c | 4 +-
liblvm/lvm_vg.c | 4 +-
tools/reporter.c | 4 +
12 files changed, 410 insertions(+), 11 deletions(-)
diff --git a/lib/report/columns.h b/lib/report/columns.h
index d13d19a..4a05167 100644
--- a/lib/report/columns.h
+++ b/lib/report/columns.h
@@ -164,4 +164,6 @@ FIELD(SEGS, seg, STR, "Monitor", list, 7, segmonitor, monitor, "Dmeventd monitor
FIELD(PVSEGS, pvseg, NUM, "Start", pe, 5, uint32, pvseg_start, "Physical Extent number of start of segment.", 0)
FIELD(PVSEGS, pvseg, NUM, "SSize", len, 5, uint32, pvseg_size, "Number of extents in segment.", 0)
+
+FIELD(LV_CREATE_PARAMS, lvcreate_params, NUM, "skip_zero", zero, 2, uint32, skip_zero, "Skip zeroing on lv creation", 1)
/* *INDENT-ON* */
diff --git a/lib/report/properties.c b/lib/report/properties.c
index ad23e7c..c20868b 100644
--- a/lib/report/properties.c
+++ b/lib/report/properties.c
@@ -39,6 +39,9 @@ static int _ ## NAME ## _get (const void *obj, struct lvm_property_type *prop) \
GET_NUM_PROPERTY_FN(NAME, VALUE, lv_segment, lvseg)
#define GET_PVSEG_NUM_PROPERTY_FN(NAME, VALUE) \
GET_NUM_PROPERTY_FN(NAME, VALUE, pv_segment, pvseg)
+#define GET_LVCREATEPARAMS_NUM_PROPERTY_FN(NAME, VALUE)\
+ GET_NUM_PROPERTY_FN(NAME, VALUE, lvcreate_params, lvcp)
+
#define SET_NUM_PROPERTY_FN(NAME, SETFN, TYPE, VAR) \
static int _ ## NAME ## _set (void *obj, struct lvm_property_type *prop) \
@@ -48,6 +51,15 @@ static int _ ## NAME ## _set (void *obj, struct lvm_property_type *prop) \
SETFN(VAR, prop->value.integer); \
return 1; \
}
+
+#define SET_NUM_PROPERTY(NAME, VALUE, TYPE, VAR) \
+static int _ ## NAME ## _set (void *obj, struct lvm_property_type *prop) \
+{ \
+ struct TYPE *VAR = (struct TYPE *)obj; \
+\
+ VALUE = prop->value.integer; \
+ return 1; \
+}
#define SET_VG_NUM_PROPERTY_FN(NAME, SETFN) \
SET_NUM_PROPERTY_FN(NAME, SETFN, volume_group, vg)
#define SET_PV_NUM_PROPERTY_FN(NAME, SETFN) \
@@ -55,6 +67,9 @@ static int _ ## NAME ## _set (void *obj, struct lvm_property_type *prop) \
#define SET_LV_NUM_PROPERTY_FN(NAME, SETFN) \
SET_NUM_PROPERTY_FN(NAME, SETFN, logical_volume, lv)
+#define SET_LVCREATEPARAMS_NUM_PROPERTY_FN(NAME, VALUE) \
+ SET_NUM_PROPERTY(NAME, VALUE, lvcreate_params, lvcp)
+
#define GET_STR_PROPERTY_FN(NAME, VALUE, TYPE, VAR) \
static int _ ## NAME ## _get (const void *obj, struct lvm_property_type *prop) \
{ \
@@ -360,6 +375,9 @@ GET_PVSEG_NUM_PROPERTY_FN(pvseg_start, pvseg->pe)
GET_PVSEG_NUM_PROPERTY_FN(pvseg_size, (SECTOR_SIZE * pvseg->len))
#define _pvseg_size_set _not_implemented_set
+/* lv create parameters */
+GET_LVCREATEPARAMS_NUM_PROPERTY_FN(skip_zero, lvcp->zero)
+SET_LVCREATEPARAMS_NUM_PROPERTY_FN(skip_zero, lvcp->zero)
#define STR DM_REPORT_FIELD_TYPE_STRING
#define NUM DM_REPORT_FIELD_TYPE_NUMBER
@@ -464,6 +482,18 @@ int pvseg_get_property(const struct pv_segment *pvseg,
return _get_property(pvseg, prop, PVSEGS);
}
+int lv_create_param_get_property(const struct lvcreate_params *lvcp,
+ struct lvm_property_type *prop)
+{
+ return _get_property(lvcp, prop, LV_CREATE_PARAMS);
+}
+
+int lv_create_param_set_property(struct lvcreate_params *lvcp,
+ struct lvm_property_type *prop)
+{
+ return _set_property(lvcp, prop, LV_CREATE_PARAMS);
+}
+
int pv_get_property(const struct physical_volume *pv,
struct lvm_property_type *prop)
{
diff --git a/lib/report/properties.h b/lib/report/properties.h
index aefd3f5..1a08589 100644
--- a/lib/report/properties.h
+++ b/lib/report/properties.h
@@ -50,4 +50,10 @@ int vg_set_property(struct volume_group *vg,
int pv_set_property(struct physical_volume *pv,
struct lvm_property_type *prop);
+int lv_create_param_get_property(const struct lvcreate_params *lvcp,
+ struct lvm_property_type *prop);
+
+int lv_create_param_set_property(struct lvcreate_params *lvcp,
+ struct lvm_property_type *prop);
+
#endif
diff --git a/lib/report/report.c b/lib/report/report.c
index 8b5455b..965859d 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -1295,6 +1295,7 @@ typedef struct logical_volume type_lv;
typedef struct volume_group type_vg;
typedef struct lv_segment type_seg;
typedef struct pv_segment type_pvseg;
+typedef struct lvcreate_params type_lvcreate_params;
static const struct dm_report_field_type _fields[] = {
#include "columns.h"
diff --git a/lib/report/report.h b/lib/report/report.h
index 26cc2f7..d5bfb6a 100644
--- a/lib/report/report.h
+++ b/lib/report/report.h
@@ -24,7 +24,8 @@ typedef enum {
VGS = 4,
SEGS = 8,
PVSEGS = 16,
- LABEL = 32
+ LABEL = 32,
+ LV_CREATE_PARAMS = 64
} report_type_t;
struct field;
diff --git a/liblvm/lvm2app.h b/liblvm/lvm2app.h
index 93a78c3..b1d6abd 100644
--- a/liblvm/lvm2app.h
+++ b/liblvm/lvm2app.h
@@ -97,6 +97,7 @@ struct volume_group;
struct logical_volume;
struct lv_segment;
struct pv_segment;
+struct lvm_lv_create_params;
/**
* \class lvm_t
@@ -153,6 +154,14 @@ typedef struct lv_segment *lvseg_t;
typedef struct pv_segment *pvseg_t;
/**
+ * \class lv_create_params
+ *
+ * This lv_create_params represents the plethora of available options when
+ * creating a logical volume
+ */
+typedef struct lvm_lv_create_params *lv_create_params_t;
+
+/**
* Logical Volume object list.
*
* Lists of these structures are returned by lvm_vg_list_lvs().
@@ -1400,6 +1409,130 @@ int lvm_lv_resize(const lv_t lv, uint64_t new_size);
*/
lv_t lvm_lv_snapshot(const lv_t lv, const char *snap_name, uint64_t max_snap_size);
+/**
+ * Thin provisioning discard policies
+ */
+typedef enum {
+ LVM_THIN_DISCARDS_IGNORE,
+ LVM_THIN_DISCARDS_NO_PASSDOWN,
+ LVM_THIN_DISCARDS_PASSDOWN,
+} lvm_thin_discards_t;
+
+/**
+ * Create a thinpool parameter passing object for the specified VG
+ *
+ * \param vg
+ * Volume Group handle.
+ *
+ * \param pool_name
+ * Name of the pool.
+ *
+ * \param size
+ * size of the pool
+ *
+ * \param chunk_size
+ * data block size of the pool
+ * Default value is DEFAULT_THIN_POOL_CHUNK_SIZE * 2 when 0 passed as chunk_size
+ * DM_THIN_MIN_DATA_BLOCK_SIZE < chunk_size < DM_THIN_MAX_DATA_BLOCK_SIZE
+ *
+ * \param meta_size
+ * Size of thin pool's metadata logical volume. Allowed range is 2MB-16GB.
+ * Default value (ie if 0) pool size / pool chunk size * 64
+ *
+ * \param discard
+ * Thin discard policy
+ * Note: THIN_DISCARDS_PASSDOWN is the default.
+ *
+ * \return
+ * Valid lv_create_params pointer on success, else NULL on error.
+ * Note: Memory is associated with the vg, it will get reclaimed when vg is
+ * closed.
+ *
+ */
+lv_create_params_t lvm_lv_params_create_thin_pool(vg_t vg,
+ const char *pool_name, uint64_t size, uint32_t chunk_size,
+ uint64_t meta_size, lvm_thin_discards_t discard);
+
+#define lvm_lv_params_create_thin_pool_default(vg, pool_name, size) \
+ lvm_lv_params_create_thin_pool((vg), (pool_name), (size), 0, 0, \
+ LVM_THIN_DISCARDS_PASSDOWN)
+
+
+
+/**
+ * Get the specific value of a lv create parameter by name
+ *
+ * \param params lv create parameters
+ *
+ * \param name name of parameter
+ *
+ * \return
+ * lvm_property_value structure that will contain the current
+ * value of the property. Caller should check 'is_valid' flag before using
+ * the value. If 'is_valid' is not set, caller should check lvm_errno()
+ * for specific error.
+ */
+struct lvm_property_value lvm_lv_params_get_property(
+ const lv_create_params_t params,
+ const char *name);
+
+
+/**
+ * Set the specific value of a lv create parameter by name
+ *
+ * Note that the property must be a 'settable' property, as evidenced '
+ * by the 'is_settable' flag when querying the property.
+ *
+ * The memory allocated for a string property value is tied to the vg_t
+ * handle associated with the lv_create_params_t and will be released when
+ * lvm_vg_close() is called.
+ *
+ * \param params lv create parameters
+ *
+ * \param name name of parameter
+ *
+ * \param prop Property value to use for setting
+ *
+ * \return
+ * 0 on success, -1 on error.
+ */
+int lvm_lv_params_set_property(lv_create_params_t params,
+ const char *name,
+ struct lvm_property_value *prop);
+
+/**
+ * Create a thin LV creation parameters in a given VG & thin pool
+ *
+ * \param vg
+ * Volume Group handle.
+ *
+ * \param pool_name
+ * Name of the pool.
+ *
+ * \param lvname
+ * Name of the LV to create
+ *
+ * \param size
+ * Size of logical volume
+ *
+ * \return
+ * Valid lv_create_params pointer on success, else NULL on error.
+ * Note: Memory is associated with the vg, it will get reclaimed when vg is
+ * closed.
+ *
+ */
+lv_create_params_t lvm_lv_params_create_thin(const vg_t vg, const char *pool_name,
+ const char *lvname, uint64_t size);
+/**
+ * Create the actual logical volume.
+ *
+ * \param params The parameters object for lv creation
+ *
+ * \return
+ * Valid lv pointer on success, else NULL on error.
+ */
+lv_t lvm_lv_create(lv_create_params_t params);
+
/************************** physical volume handling ************************/
/**
diff --git a/liblvm/lvm_lv.c b/liblvm/lvm_lv.c
index 91948a6..2039126 100644
--- a/liblvm/lvm_lv.c
+++ b/liblvm/lvm_lv.c
@@ -22,6 +22,15 @@
#include "lvm_misc.h"
#include "lvm2app.h"
+struct lvm_lv_create_params
+{
+ uint32_t magic;
+ vg_t vg;
+ struct lvcreate_params lvp;
+};
+
+#define LV_CREATE_PARAMS_MAGIC 0xFEED0001
+
static int _lv_check_handle(const lv_t lv, const int vg_writeable)
{
if (!lv || !lv->vg || vg_read_error(lv->vg))
@@ -50,13 +59,13 @@ const char *lvm_lv_get_name(const lv_t lv)
struct lvm_property_value lvm_lv_get_property(const lv_t lv, const char *name)
{
- return get_property(NULL, NULL, lv, NULL, NULL, name);
+ return get_property(NULL, NULL, lv, NULL, NULL, NULL, name);
}
struct lvm_property_value lvm_lvseg_get_property(const lvseg_t lvseg,
const char *name)
{
- return get_property(NULL, NULL, NULL, lvseg, NULL, name);
+ return get_property(NULL, NULL, NULL, lvseg, NULL, NULL, name);
}
uint64_t lvm_lv_is_active(const lv_t lv)
@@ -350,3 +359,202 @@ lv_t lvm_lv_snapshot(const lv_t lv, const char *snap_name, uint64_t max_snap_siz
return NULL;
return (lv_t) lvl->lv;
}
+
+/* Set defaults for thin pool specific LV parameters */
+static void _lv_set_pool_params(struct lvcreate_params *lp,
+ vg_t vg, const char *pool,
+ uint64_t extents, uint64_t meta_size)
+{
+ _lv_set_default_params(lp, vg, NULL, extents);
+
+ lp->pool = pool;
+
+ lp->create_thin_pool = 1;
+ lp->segtype = get_segtype_from_string(vg->cmd, "thin-pool");
+ lp->stripes = 1;
+
+ if (!meta_size) {
+ lp->poolmetadatasize = extents * vg->extent_size /
+ (lp->chunk_size * (SECTOR_SIZE / 64));
+ while ((lp->poolmetadatasize >
+ (2 * DEFAULT_THIN_POOL_OPTIMAL_SIZE / SECTOR_SIZE)) &&
+ lp->chunk_size < DM_THIN_MAX_DATA_BLOCK_SIZE) {
+ lp->chunk_size <<= 1;
+ lp->poolmetadatasize >>= 1;
+ }
+ } else
+ lp->poolmetadatasize = meta_size;
+
+ if (lp->poolmetadatasize % vg->extent_size)
+ lp->poolmetadatasize +=
+ vg->extent_size - lp->poolmetadatasize % vg->extent_size;
+
+ lp->poolmetadataextents =
+ extents_from_size(vg->cmd, lp->poolmetadatasize / SECTOR_SIZE,
+ vg->extent_size);
+}
+
+lv_create_params_t lvm_lv_params_create_thin_pool(vg_t vg,
+ const char *pool_name, uint64_t size, uint32_t chunk_size,
+ uint64_t meta_size, lvm_thin_discards_t discard)
+{
+ uint64_t extents = 0;
+ struct lvm_lv_create_params *lvcp = NULL;
+
+ if (meta_size > (2 * DEFAULT_THIN_POOL_MAX_METADATA_SIZE)) {
+ log_error("Invalid metadata size");
+ return NULL;
+ }
+
+ if (meta_size &&
+ meta_size < (2 * DEFAULT_THIN_POOL_MIN_METADATA_SIZE)) {
+ log_error("Invalid metadata size");
+ return NULL;
+ }
+
+ if (vg_read_error(vg))
+ return NULL;
+
+ if (!vg_check_write_mode(vg))
+ return NULL;
+
+ if (pool_name == NULL || !strlen(pool_name)) {
+ log_error("pool_name invalid");
+ return NULL;
+ }
+
+ if (!(extents = extents_from_size(vg->cmd, size / SECTOR_SIZE,
+ vg->extent_size))) {
+ log_error("Unable to create LV thin pool without size.");
+ return NULL;
+ }
+
+ lvcp = dm_pool_zalloc(vg->vgmem, sizeof (struct lvm_lv_create_params));
+
+ if (lvcp) {
+ lvcp->vg = vg;
+ lvcp->lvp.discards = discard;
+
+ if (chunk_size)
+ lvcp->lvp.chunk_size = chunk_size;
+ else
+ lvcp->lvp.chunk_size = DEFAULT_THIN_POOL_CHUNK_SIZE * 2;
+
+ if (lvcp->lvp.chunk_size < DM_THIN_MIN_DATA_BLOCK_SIZE ||
+ lvcp->lvp.chunk_size > DM_THIN_MAX_DATA_BLOCK_SIZE) {
+ log_error("Invalid chunk_size");
+ return NULL;
+ }
+
+ _lv_set_pool_params(&lvcp->lvp, vg, pool_name, extents, meta_size);
+
+ lvcp->magic = LV_CREATE_PARAMS_MAGIC;
+ }
+ return lvcp;
+}
+
+/* Set defaults for thin LV specific parameters */
+static void _lv_set_thin_params(struct lvcreate_params *lp,
+ vg_t vg, const char *pool,
+ const char *lvname,
+ uint64_t extents)
+{
+ _lv_set_default_params(lp, vg, lvname, extents);
+
+ lp->thin = 1;
+ lp->pool = pool;
+ lp->segtype = get_segtype_from_string(vg->cmd, "thin");
+
+ lp->voriginsize = extents * vg->extent_size;
+ lp->voriginextents = extents_from_size(vg->cmd, lp->voriginsize,
+ vg->extent_size);
+
+ lp->stripes = 1;
+}
+
+lv_create_params_t lvm_lv_params_create_thin(const vg_t vg, const char *pool_name,
+ const char *lvname, uint64_t size)
+{
+ struct lvm_lv_create_params *lvcp = NULL;
+ uint64_t extents = 0;
+
+ /* precondition checks */
+ if (vg_read_error(vg))
+ return NULL;
+
+ if (!vg_check_write_mode(vg))
+ return NULL;
+
+ if (pool_name == NULL || !strlen(pool_name)) {
+ log_error("pool_name invalid");
+ return NULL;
+ }
+
+ if (lvname == NULL || !strlen(lvname)) {
+ log_error("lvname invalid");
+ return NULL;
+ }
+
+ if (!(extents = extents_from_size(vg->cmd, size / SECTOR_SIZE,
+ vg->extent_size))) {
+ log_error("Unable to create thin LV without size.");
+ return NULL;
+ }
+
+ lvcp = dm_pool_zalloc(vg->vgmem, sizeof (struct lvm_lv_create_params));
+ if (lvcp) {
+ lvcp->vg = vg;
+ _lv_set_thin_params(&lvcp->lvp, vg, pool_name, lvname, extents);
+ lvcp->magic = LV_CREATE_PARAMS_MAGIC;
+ }
+
+ return lvcp;
+}
+
+struct lvm_property_value lvm_lv_params_get_property(
+ const lv_create_params_t params,
+ const char *name)
+{
+ struct lvm_property_value rc;
+
+ rc.is_valid = 0;
+
+ if (params && params->magic == LV_CREATE_PARAMS_MAGIC) {
+ rc = get_property(NULL, NULL, NULL, NULL, NULL, ¶ms->lvp, name);
+ } else {
+ log_error("Invalid lv_create_params parameter");
+ }
+ return rc;
+}
+
+int lvm_lv_params_set_property(lv_create_params_t params, const char *name,
+ struct lvm_property_value *prop)
+{
+ int rc = -1;
+
+ if (params && params->magic == LV_CREATE_PARAMS_MAGIC) {
+ rc = set_property(NULL, NULL, NULL, ¶ms->lvp, name, prop);
+ } else {
+ log_error("Invalid lv_create_params parameter");
+ }
+ return rc;
+}
+
+lv_t lvm_lv_create(lv_create_params_t params)
+{
+ struct lv_list *lvl = NULL;
+
+ if (params && params->magic == LV_CREATE_PARAMS_MAGIC) {
+ if (!params->lvp.segtype) {
+ log_error("segtype parameter is NULL");
+ return_NULL;
+ }
+ if (!lv_create_single(params->vg, ¶ms->lvp))
+ return_NULL;
+ if (!(lvl = find_lv_in_vg(params->vg, params->lvp.lv_name)))
+ return_NULL;
+ return (lv_t) lvl->lv;
+ }
+ log_error("Invalid lv_create_params parameter");
+ return NULL;
+}
diff --git a/liblvm/lvm_misc.c b/liblvm/lvm_misc.c
index 0a0ea12..de66417 100644
--- a/liblvm/lvm_misc.c
+++ b/liblvm/lvm_misc.c
@@ -47,7 +47,8 @@ struct dm_list *tag_list_copy(struct dm_pool *p, struct dm_list *tag_list)
struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
const lv_t lv, const lvseg_t lvseg,
- const pvseg_t pvseg, const char *name)
+ const pvseg_t pvseg, const struct lvcreate_params *lvcp,
+ const char *name)
{
struct lvm_property_type prop;
struct lvm_property_value v = { 0 };
@@ -69,6 +70,9 @@ struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
} else if (pvseg) {
if (!pvseg_get_property(pvseg, &prop))
return v;
+ } else if (lvcp) {
+ if (!lv_create_param_get_property(lvcp, &prop))
+ return v;
} else {
log_errno(EINVAL, "Invalid NULL handle passed to library function.");
return v;
@@ -87,7 +91,8 @@ struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
int set_property(const pv_t pv, const vg_t vg, const lv_t lv,
- const char *name, struct lvm_property_value *v)
+ struct lvcreate_params *lvcp, const char *name,
+ struct lvm_property_value *v)
{
struct lvm_property_type prop;
@@ -111,6 +116,13 @@ int set_property(const pv_t pv, const vg_t vg, const lv_t lv,
v->is_valid = 0;
return -1;
}
+ } else if (lvcp) {
+ if (!lv_create_param_set_property(lvcp, &prop)) {
+ v->is_valid = 0;
+ return -1;
+ }
+ } else {
+ return -1;
}
return 0;
}
diff --git a/liblvm/lvm_misc.h b/liblvm/lvm_misc.h
index a0324b8..76f4e0a 100644
--- a/liblvm/lvm_misc.h
+++ b/liblvm/lvm_misc.h
@@ -20,8 +20,10 @@
struct dm_list *tag_list_copy(struct dm_pool *p, struct dm_list *tag_list);
struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
const lv_t lv, const lvseg_t lvseg,
- const pvseg_t pvseg, const char *name);
+ const pvseg_t pvseg, const struct lvcreate_params *lvcp,
+ const char *name);
int set_property(const pv_t pv, const vg_t vg, const lv_t lv,
- const char *name, struct lvm_property_value *value);
+ struct lvcreate_params *lvcp, const char *name,
+ struct lvm_property_value *value);
#endif
diff --git a/liblvm/lvm_pv.c b/liblvm/lvm_pv.c
index 90edaed..3924af4 100644
--- a/liblvm/lvm_pv.c
+++ b/liblvm/lvm_pv.c
@@ -51,13 +51,13 @@ uint64_t lvm_pv_get_free(const pv_t pv)
struct lvm_property_value lvm_pv_get_property(const pv_t pv, const char *name)
{
- return get_property(pv, NULL, NULL, NULL, NULL, name);
+ return get_property(pv, NULL, NULL, NULL, NULL, NULL, name);
}
struct lvm_property_value lvm_pvseg_get_property(const pvseg_t pvseg,
const char *name)
{
- return get_property(NULL, NULL, NULL, NULL, pvseg, name);
+ return get_property(NULL, NULL, NULL, NULL, pvseg, NULL, name);
}
struct dm_list *lvm_pv_list_pvsegs(pv_t pv)
diff --git a/liblvm/lvm_vg.c b/liblvm/lvm_vg.c
index b090b84..a707589 100644
--- a/liblvm/lvm_vg.c
+++ b/liblvm/lvm_vg.c
@@ -339,13 +339,13 @@ const char *lvm_vg_get_name(const vg_t vg)
struct lvm_property_value lvm_vg_get_property(const vg_t vg, const char *name)
{
- return get_property(NULL, vg, NULL, NULL, NULL, name);
+ return get_property(NULL, vg, NULL, NULL, NULL, NULL, name);
}
int lvm_vg_set_property(const vg_t vg, const char *name,
struct lvm_property_value *value)
{
- return set_property(NULL, vg, NULL, name, value);
+ return set_property(NULL, vg, NULL, NULL, name, value);
}
struct dm_list *lvm_list_vg_names(lvm_t libh)
diff --git a/tools/reporter.c b/tools/reporter.c
index a6941e3..ced7d56 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -271,6 +271,7 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
else
options = find_config_tree_str(cmd, report_pvsegs_cols_verbose_CFG, NULL);
break;
+ case LV_CREATE_PARAMS:
default:
log_error(INTERNAL_ERROR "Unknown report type.");
return ECMD_FAILED;
@@ -382,6 +383,9 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
r = process_each_vg(cmd, argc, argv, 0,
report_handle, &_pvsegs_in_vg);
break;
+
+ case LV_CREATE_PARAMS:
+ break;
}
dm_report_output(report_handle);
10 years, 10 months
master - WHATS_NEW: config/profile_dir
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=fd94dd3b7e9e55...
Commit: fd94dd3b7e9e55029dd79274da18d8503fa12ebf
Parent: 7ce0c6777b88f9a20aa1c4476f37fdc37d7732cd
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Jul 2 15:57:46 2013 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Jul 2 15:57:46 2013 +0200
WHATS_NEW: config/profile_dir
---
WHATS_NEW | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 37e5534..b68360f 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -7,6 +7,7 @@ Version 2.02.99 -
Support changing VG/LV profiles: vgchange/lvchange --profile/--detachprofile.
Support storing profile name in metadata for both VGs and LVs.
Add new --profile command line arg to select a configuration profile for use.
+ Add config/profile_dir to set working directory to load profiles from.
Add configure --with-default-profile-subdir to select dir to keep profiles in.
Add support for configuration profiles.
Introduce config_source wrapper for identification of configuration sources.
10 years, 10 months
master - WHATS_NEW: configuration profile support
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=7ce0c6777b88f9...
Commit: 7ce0c6777b88f9a20aa1c4476f37fdc37d7732cd
Parent: 9f6cfc9de497944b60a0b52e77ff532c489bce63
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Jul 2 15:51:21 2013 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Jul 2 15:51:21 2013 +0200
WHATS_NEW: configuration profile support
---
WHATS_NEW | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index b501121..37e5534 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,15 @@
Version 2.02.99 -
===================================
+ Add vgs/lvs -o vg_profile/lv_profile to report profiles attached to VG/LV.
+ Add default.profile configuration profile and install it on make install.
+ Create a new 'conf' subdir for configuration files including profiles.
+ Make selected thinp settings customizable by a profile.
+ Support changing VG/LV profiles: vgchange/lvchange --profile/--detachprofile.
+ Support storing profile name in metadata for both VGs and LVs.
+ Add new --profile command line arg to select a configuration profile for use.
+ Add configure --with-default-profile-subdir to select dir to keep profiles in.
+ Add support for configuration profiles.
+ Introduce config_source wrapper for identification of configuration sources.
Avoid creation of multiple archives for one command.
Use mirror_segtype_default if type not specified for linear->mirror upconvert.
Fix use of too big chunks of memory when communication with lvmetad.
10 years, 10 months
master - report: add vg_profile and lv_profile to report the profile attached to VG/LV
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=9f6cfc9de49794...
Commit: 9f6cfc9de497944b60a0b52e77ff532c489bce63
Parent: 21554ab5fe958b09eed853f3bfefa61c4c130604
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Jul 2 14:34:52 2013 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Jul 2 15:22:12 2013 +0200
report: add vg_profile and lv_profile to report the profile attached to VG/LV
vgs -o vg_profile ...
lvs -o lv_profile ...
---
lib/config/defaults.h | 4 ++--
lib/metadata/lv.c | 6 ++++++
lib/metadata/lv.h | 1 +
lib/metadata/vg.c | 6 ++++++
lib/metadata/vg.h | 1 +
lib/report/columns.h | 2 ++
lib/report/properties.c | 4 ++++
lib/report/report.c | 26 ++++++++++++++++++++++++++
8 files changed, 48 insertions(+), 2 deletions(-)
diff --git a/lib/config/defaults.h b/lib/config/defaults.h
index b8d46f1..7ee89ec 100644
--- a/lib/config/defaults.h
+++ b/lib/config/defaults.h
@@ -163,8 +163,8 @@
#define DEFAULT_SEGS_COLS "lv_name,vg_name,lv_attr,stripes,segtype,seg_size"
#define DEFAULT_PVSEGS_COLS "pv_name,vg_name,pv_fmt,pv_attr,pv_size,pv_free,pvseg_start,pvseg_size"
-#define DEFAULT_LVS_COLS_VERB "lv_name,vg_name,seg_count,lv_attr,lv_size,lv_major,lv_minor,lv_kernel_major,lv_kernel_minor,pool_lv,origin,data_percent,metadata_percent,move_pv,copy_percent,mirror_log,convert_lv,lv_uuid"
-#define DEFAULT_VGS_COLS_VERB "vg_name,vg_attr,vg_extent_size,pv_count,lv_count,snap_count,vg_size,vg_free,vg_uuid"
+#define DEFAULT_LVS_COLS_VERB "lv_name,vg_name,seg_count,lv_attr,lv_size,lv_major,lv_minor,lv_kernel_major,lv_kernel_minor,pool_lv,origin,data_percent,metadata_percent,move_pv,copy_percent,mirror_log,convert_lv,lv_uuid,lv_profile"
+#define DEFAULT_VGS_COLS_VERB "vg_name,vg_attr,vg_extent_size,pv_count,lv_count,snap_count,vg_size,vg_free,vg_uuid,vg_profile"
#define DEFAULT_PVS_COLS_VERB "pv_name,vg_name,pv_fmt,pv_attr,pv_size,pv_free,dev_size,pv_uuid"
#define DEFAULT_SEGS_COLS_VERB "lv_name,vg_name,lv_attr,seg_start,seg_size,stripes,segtype,stripesize,chunksize"
#define DEFAULT_PVSEGS_COLS_VERB "pv_name,vg_name,pv_fmt,pv_attr,pv_size,pv_free,pvseg_start,pvseg_size,lv_name,seg_start_pe,segtype,seg_pe_ranges"
diff --git a/lib/metadata/lv.c b/lib/metadata/lv.c
index 93ae92d..475a514 100644
--- a/lib/metadata/lv.c
+++ b/lib/metadata/lv.c
@@ -785,6 +785,12 @@ char *lv_active_dup(struct dm_pool *mem, const struct logical_volume *lv)
return dm_pool_strdup(mem, s);
}
+char *lv_profile_dup(struct dm_pool *mem, const struct logical_volume *lv)
+{
+ const char *profile_name = lv->profile ? lv->profile->name : "";
+ return dm_pool_strdup(mem, profile_name);
+}
+
/* For given LV find recursively the LV which holds lock for it */
const struct logical_volume *lv_lock_holder(const struct logical_volume *lv)
{
diff --git a/lib/metadata/lv.h b/lib/metadata/lv.h
index 6831f67..06f8c60 100644
--- a/lib/metadata/lv.h
+++ b/lib/metadata/lv.h
@@ -93,4 +93,5 @@ char *lv_active_dup(struct dm_pool *mem, const struct logical_volume *lv);
const struct logical_volume *lv_lock_holder(const struct logical_volume *lv);
struct logical_volume *lv_ondisk(struct logical_volume *lv);
struct profile *lv_config_profile(const struct logical_volume *lv);
+char *lv_profile_dup(struct dm_pool *mem, const struct logical_volume *lv);
#endif /* _LVM_LV_H */
diff --git a/lib/metadata/vg.c b/lib/metadata/vg.c
index 50e8328..22099e2 100644
--- a/lib/metadata/vg.c
+++ b/lib/metadata/vg.c
@@ -267,6 +267,12 @@ int vg_set_mda_copies(struct volume_group *vg, uint32_t mda_copies)
return 1;
}
+char *vg_profile_dup(const struct volume_group *vg)
+{
+ const char *profile_name = vg->profile ? vg->profile->name : "";
+ return dm_pool_strdup(vg->vgmem, profile_name);
+}
+
static int _recalc_extents(uint32_t *extents, const char *desc1,
const char *desc2, uint32_t old_size,
uint32_t new_size)
diff --git a/lib/metadata/vg.h b/lib/metadata/vg.h
index f33fe11..8db04d3 100644
--- a/lib/metadata/vg.h
+++ b/lib/metadata/vg.h
@@ -155,6 +155,7 @@ uint32_t vg_mda_count(const struct volume_group *vg);
uint32_t vg_mda_used_count(const struct volume_group *vg);
uint32_t vg_mda_copies(const struct volume_group *vg);
int vg_set_mda_copies(struct volume_group *vg, uint32_t mda_copies);
+char *vg_profile_dup(const struct volume_group *vg);
/*
* Returns visible LV count - number of LVs from user perspective
diff --git a/lib/report/columns.h b/lib/report/columns.h
index c55a685..d13d19a 100644
--- a/lib/report/columns.h
+++ b/lib/report/columns.h
@@ -96,6 +96,7 @@ FIELD(LVS, lv, STR, "LV Tags", tags, 7, tags, lv_tags, "Tags, if any.", 0)
FIELD(LVS, lv, STR, "Time", lvid, 26, lvtime, lv_time, "Creation time of the LV, if known", 0)
FIELD(LVS, lv, STR, "Host", lvid, 10, lvhost, lv_host, "Creation host of the LV, if known.", 0)
FIELD(LVS, lv, STR, "Modules", lvid, 7, modules, modules, "Kernel device-mapper modules required for this LV.", 0)
+FIELD(LVS, lv, STR, "LProfile", lvid, 8, lvprofile, lv_profile, "Configuration profile attached to this LV", 0)
FIELD(LABEL, pv, STR, "Fmt", id, 3, pvfmt, pv_fmt, "Type of metadata.", 0)
FIELD(LABEL, pv, STR, "PV UUID", id, 38, uuid, pv_uuid, "Unique identifier.", 0)
@@ -139,6 +140,7 @@ FIELD(VGS, vg, NUM, "#VMdaUse", cmd, 8, vgmdasused, vg_mda_used_count, "Number o
FIELD(VGS, vg, NUM, "VMdaFree", cmd, 9, vgmdafree, vg_mda_free, "Free metadata area space for this VG in current units.", 0)
FIELD(VGS, vg, NUM, "VMdaSize", cmd, 9, vgmdasize, vg_mda_size, "Size of smallest metadata area for this VG in current units.", 0)
FIELD(VGS, vg, NUM, "#VMdaCps", cmd, 8, vgmdacopies, vg_mda_copies, "Target number of in use metadata areas in the VG.", 1)
+FIELD(VGS, vg, STR, "VProfile", cmd, 8, vgprofile, vg_profile, "Configuration profile attached to this VG", 0)
FIELD(SEGS, seg, STR, "Type", list, 4, segtype, segtype, "Type of LV segment.", 0)
FIELD(SEGS, seg, NUM, "#Str", area_count, 4, uint32, stripes, "Number of stripes or mirror legs.", 0)
diff --git a/lib/report/properties.c b/lib/report/properties.c
index 884df2a..ad23e7c 100644
--- a/lib/report/properties.c
+++ b/lib/report/properties.c
@@ -261,6 +261,8 @@ GET_LV_STR_PROPERTY_FN(lv_host, lv_host_dup(lv->vg->vgmem, lv))
#define _lv_host_set _not_implemented_set
GET_LV_STR_PROPERTY_FN(lv_active, lv_active_dup(lv->vg->vgmem, lv))
#define _lv_active_set _not_implemented_set
+GET_LV_STR_PROPERTY_FN(lv_profile, lv_profile_dup(lv->vg->vgmem, lv))
+#define _lv_profile_set _not_implemented_set
/* VG */
GET_VG_STR_PROPERTY_FN(vg_fmt, vg_fmt_dup(vg))
@@ -307,6 +309,8 @@ GET_VG_NUM_PROPERTY_FN(vg_mda_size, (SECTOR_SIZE * vg_mda_size(vg)))
#define _vg_mda_size_set _not_implemented_set
GET_VG_NUM_PROPERTY_FN(vg_mda_copies, (vg_mda_copies(vg)))
SET_VG_NUM_PROPERTY_FN(vg_mda_copies, vg_set_mda_copies)
+GET_VG_STR_PROPERTY_FN(vg_profile, vg_profile_dup(vg))
+#define _vg_profile_set _not_implemented_set
/* LVSEG */
GET_LVSEG_STR_PROPERTY_FN(segtype, lvseg_segtype_dup(lvseg->lv->vg->vgmem, lvseg))
diff --git a/lib/report/report.c b/lib/report/report.c
index 8ff4f28..8b5455b 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -111,6 +111,19 @@ static int _modules_disp(struct dm_report *rh, struct dm_pool *mem,
return 1;
}
+static int _lvprofile_disp(struct dm_report *rh, struct dm_pool *mem,
+ struct dm_report_field *field,
+ const void *data, void *private)
+{
+ const struct logical_volume *lv = (const struct logical_volume *) data;
+
+ if (lv->profile)
+ return dm_report_field_string(rh, field, &lv->profile->name);
+
+ dm_report_field_set_value(field, "", NULL);
+ return 1;
+}
+
static int _vgfmt_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
@@ -760,6 +773,19 @@ static int _vgmdacopies_disp(struct dm_report *rh, struct dm_pool *mem,
return _uint32_disp(rh, mem, field, &count, private);
}
+static int _vgprofile_disp(struct dm_report *rh, struct dm_pool *mem,
+ struct dm_report_field *field,
+ const void *data, void *private)
+{
+ const struct volume_group *vg = (const struct volume_group *) data;
+
+ if (vg->profile)
+ return dm_report_field_string(rh, field, &vg->profile->name);
+
+ dm_report_field_set_value(field, "", NULL);
+ return 1;
+}
+
static int _pvmdafree_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
10 years, 10 months
master - profile: add default.profile and install it
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=21554ab5fe958b...
Commit: 21554ab5fe958b09eed853f3bfefa61c4c130604
Parent: 6d1ed2254ccfe2a34f1423ea2359cf6a554e8d9e
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Fri Jun 28 14:08:04 2013 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Jul 2 15:22:11 2013 +0200
profile: add default.profile and install it
The default.profile contains all settings that are customizable
by a profile. This default profile can be copied across to create
new profiles.
---
conf/Makefile.in | 13 +++++++++++--
conf/default.profile.in | 20 ++++++++++++++++++++
configure | 3 ++-
configure.in | 1 +
make.tmpl.in | 1 +
5 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/conf/Makefile.in b/conf/Makefile.in
index c63e3ce..c148ac2 100644
--- a/conf/Makefile.in
+++ b/conf/Makefile.in
@@ -18,14 +18,23 @@ top_builddir = @top_builddir@
CONFSRC=example.conf
CONFDEST=lvm.conf
+DEFAULT_PROFILE=default.profile
+PROFILES=$(DEFAULT_PROFILE)
+
include $(top_builddir)/make.tmpl
-install_lvm2: $(CONFSRC)
+install_conf: $(CONFSRC)
@if [ ! -e $(confdir)/$(CONFDEST) ]; then \
echo "$(INSTALL_WDATA) -D $< $(confdir)/$(CONFDEST)"; \
$(INSTALL_WDATA) -D $< $(confdir)/$(CONFDEST); \
fi
+install_profiles: $(PROFILES)
+ $(INSTALL) -d $(DEFAULT_PROFILE_DIR)
+ $(INSTALL_DATA) $(PROFILES) $(DEFAULT_PROFILE_DIR)/
+
+install_lvm2: install_conf install_profiles
+
install: install_lvm2
-DISTCLEAN_TARGETS += $(CONFSRC)
+DISTCLEAN_TARGETS += $(CONFSRC) $(DEFAULT_PROFILE)
diff --git a/conf/default.profile.in b/conf/default.profile.in
new file mode 100644
index 0000000..6a0b8f1
--- /dev/null
+++ b/conf/default.profile.in
@@ -0,0 +1,20 @@
+# This is a default profile for the LVM2 system.
+# It contains all configuration settings that are customizable by profiles.
+#
+# To create a new profile, select the settings you want to customize
+# and put them in a new file named <profile_name>.profile. Then put this
+# file in a directory as defined by config/profile_dir setting found in
+# @DEFAULT_SYS_DIR(a)/lvm.conf file.
+#
+# Refer to 'man lvm.conf' for further information about profiles and file layout.
+
+allocation {
+ thin_pool_chunk_size = 64
+ thin_pool_discards = "passdown"
+ thin_pool_zero = 1
+}
+
+activation {
+ thin_pool_autoextend_threshold = 100
+ thin_pool_autoextend_percent = 20
+}
diff --git a/configure b/configure
index aeb2b46..212bd80 100755
--- a/configure
+++ b/configure
@@ -10810,7 +10810,7 @@ LVM_LIBAPI=`echo "$VER" | $AWK -F '[()]' '{print $2}'`
################################################################################
-ac_config_files="$ac_config_files Makefile make.tmpl daemons/Makefile daemons/clvmd/Makefile daemons/cmirrord/Makefile daemons/dmeventd/Makefile daemons/dmeventd/libdevmapper-event.pc daemons/dmeventd/plugins/Makefile daemons/dmeventd/plugins/lvm2/Makefile daemons/dmeventd/plugins/raid/Makefile daemons/dmeventd/plugins/mirror/Makefile daemons/dmeventd/plugins/snapshot/Makefile daemons/dmeventd/plugins/thin/Makefile daemons/lvmetad/Makefile conf/Makefile conf/example.conf include/.symlinks include/Makefile lib/Makefile lib/format1/Makefile lib/format_pool/Makefile lib/locking/Makefile lib/mirror/Makefile lib/replicator/Makefile lib/misc/lvm-version.h lib/raid/Makefile lib/snapshot/Makefile lib/thin/Makefile libdaemon/Makefile libdaemon/client/Makefile libdaemon/server/Makefile libdm/Makefile libdm/libdevmapper.pc liblvm/Makefile liblvm/liblvm2app.pc man/Makefile po/Makefile python/Makefile python/setup.py scripts/blkdeactivate.sh scripts/blk_availability_init_red_hat scripts/
blk_availability_systemd_red_hat.service scripts/clvmd_init_red_hat scripts/cmirrord_init_red_hat scripts/lvm2_lvmetad_init_red_hat scripts/lvm2_lvmetad_systemd_red_hat.socket scripts/lvm2_lvmetad_systemd_red_hat.service scripts/lvm2_monitoring_init_red_hat scripts/dm_event_systemd_red_hat.socket scripts/dm_event_systemd_red_hat.service scripts/lvm2_monitoring_systemd_red_hat.service scripts/lvm2_tmpfiles_red_hat.conf scripts/Makefile test/Makefile test/api/Makefile test/unit/Makefile tools/Makefile udev/Makefile unit-tests/datastruct/Makefile unit-tests/regex/Makefile unit-tests/mm/Makefile"
+ac_config_files="$ac_config_files Makefile make.tmpl daemons/Makefile daemons/clvmd/Makefile daemons/cmirrord/Makefile daemons/dmeventd/Makefile daemons/dmeventd/libdevmapper-event.pc daemons/dmeventd/plugins/Makefile daemons/dmeventd/plugins/lvm2/Makefile daemons/dmeventd/plugins/raid/Makefile daemons/dmeventd/plugins/mirror/Makefile daemons/dmeventd/plugins/snapshot/Makefile daemons/dmeventd/plugins/thin/Makefile daemons/lvmetad/Makefile conf/Makefile conf/example.conf conf/default.profile include/.symlinks include/Makefile lib/Makefile lib/format1/Makefile lib/format_pool/Makefile lib/locking/Makefile lib/mirror/Makefile lib/replicator/Makefile lib/misc/lvm-version.h lib/raid/Makefile lib/snapshot/Makefile lib/thin/Makefile libdaemon/Makefile libdaemon/client/Makefile libdaemon/server/Makefile libdm/Makefile libdm/libdevmapper.pc liblvm/Makefile liblvm/liblvm2app.pc man/Makefile po/Makefile python/Makefile python/setup.py scripts/blkdeactivate.sh scripts/blk_availability_
init_red_hat scripts/blk_availability_systemd_red_hat.service scripts/clvmd_init_red_hat scripts/cmirrord_init_red_hat scripts/lvm2_lvmetad_init_red_hat scripts/lvm2_lvmetad_systemd_red_hat.socket scripts/lvm2_lvmetad_systemd_red_hat.service scripts/lvm2_monitoring_init_red_hat scripts/dm_event_systemd_red_hat.socket scripts/dm_event_systemd_red_hat.service scripts/lvm2_monitoring_systemd_red_hat.service scripts/lvm2_tmpfiles_red_hat.conf scripts/Makefile test/Makefile test/api/Makefile test/unit/Makefile tools/Makefile udev/Makefile unit-tests/datastruct/Makefile unit-tests/regex/Makefile unit-tests/mm/Makefile"
cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
@@ -11515,6 +11515,7 @@ do
"daemons/lvmetad/Makefile") CONFIG_FILES="$CONFIG_FILES daemons/lvmetad/Makefile" ;;
"conf/Makefile") CONFIG_FILES="$CONFIG_FILES conf/Makefile" ;;
"conf/example.conf") CONFIG_FILES="$CONFIG_FILES conf/example.conf" ;;
+ "conf/default.profile") CONFIG_FILES="$CONFIG_FILES conf/default.profile" ;;
"include/.symlinks") CONFIG_FILES="$CONFIG_FILES include/.symlinks" ;;
"include/Makefile") CONFIG_FILES="$CONFIG_FILES include/Makefile" ;;
"lib/Makefile") CONFIG_FILES="$CONFIG_FILES lib/Makefile" ;;
diff --git a/configure.in b/configure.in
index 77a0503..6d417e3 100644
--- a/configure.in
+++ b/configure.in
@@ -1642,6 +1642,7 @@ daemons/dmeventd/plugins/thin/Makefile
daemons/lvmetad/Makefile
conf/Makefile
conf/example.conf
+conf/default.profile
include/.symlinks
include/Makefile
lib/Makefile
diff --git a/make.tmpl.in b/make.tmpl.in
index df7453d..ae62182 100644
--- a/make.tmpl.in
+++ b/make.tmpl.in
@@ -81,6 +81,7 @@ DEFAULT_SYS_DIR = @DEFAULT_SYS_DIR@
DEFAULT_ARCHIVE_DIR = $(DEFAULT_SYS_DIR)/@DEFAULT_ARCHIVE_SUBDIR@
DEFAULT_BACKUP_DIR = $(DEFAULT_SYS_DIR)/@DEFAULT_BACKUP_SUBDIR@
DEFAULT_CACHE_DIR = $(DEFAULT_SYS_DIR)/@DEFAULT_CACHE_SUBDIR@
+DEFAULT_PROFILE_DIR = $(DEFAULT_SYS_DIR)/@DEFAULT_PROFILE_SUBDIR@
DEFAULT_LOCK_DIR = @DEFAULT_LOCK_DIR@
DEFAULT_RUN_DIR = @DEFAULT_RUN_DIR@
10 years, 10 months