summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZdenek Kabelac <zkabelac@redhat.com>2019-01-21 12:20:07 +0100
committerZdenek Kabelac <zkabelac@redhat.com>2019-01-21 12:53:16 +0100
commitf1ad4b067962c36e6f8199a8c6d10496bd9fb3b7 (patch)
tree6d46b5f36ab0a1e7461afbb84928c9c943a254a5
parentca72d19691683266f14dac7ae2eac755eeda6586 (diff)
downloadlvm2-f1ad4b067962c36e6f8199a8c6d10496bd9fb3b7.tar.gz
vdo: discard reduced area
Implement sending discard to reduced LV area.
-rw-r--r--lib/metadata/lv_manip.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 9ef568c64..1825abe5f 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -5570,6 +5570,8 @@ int lv_resize(struct logical_volume *lv,
int activated = 0;
int ret = 0;
int status;
+ struct device *dev;
+ char name[PATH_MAX];
if (lv_is_writecache(lv)) {
log_error("Resize not yet allowed on LVs with writecache attached.");
@@ -5695,6 +5697,41 @@ int lv_resize(struct logical_volume *lv,
activated = 1;
}
+ /* Send DISCARD/TRIM to reduced area of VDO volumes
+ * TODO: enable thin and provide
+ * TODO2: we need polling method */
+ if ((lp->resize == LV_REDUCE) && lv_is_vdo(lv)) {
+ if (dm_snprintf(name, sizeof(name), "%s%s/%s", lv->vg->cmd->dev_dir,
+ lv->vg->name, lv->name) < 0) {
+ log_error("Name too long - device not discarded (%s)", lv->name);
+ return 0;
+ }
+
+ if (!(dev = dev_cache_get(lv->vg->cmd, name, NULL))) {
+ log_error("%s: not found: device not discarded.", name);
+ return 0;
+ }
+
+ if (!dev_discard_max_bytes(cmd->dev_types, dev) ||
+ !dev_discard_granularity(cmd->dev_types, dev)) {
+ log_error("%s: max bytes and granularity query fails.", name);
+ dev_destroy_file(dev);
+ return 0;
+ }
+
+ log_warn("WARNING: %s: Discarding %s at offset " FMTu64 ", please wait...",
+ name, display_size(cmd, (uint64_t)(lv->le_count - lp->extents) * vg->extent_size),
+ ((uint64_t)lp->extents * vg->extent_size) << SECTOR_SHIFT);
+
+ if (!dev_discard_blocks(dev, ((uint64_t)lp->extents * vg->extent_size) << SECTOR_SHIFT,
+ ((uint64_t)(lv->le_count - lp->extents) * vg->extent_size) << SECTOR_SHIFT)) {
+ log_error("%s: discarding failed.", name);
+ dev_destroy_file(dev);
+ return 0;
+ }
+
+ dev_destroy_file(dev);
+ }
/*
* If the LV is locked from activation, this lock call is a no-op.
* Otherwise, this acquires a transient lock on the lv (not PERSISTENT).