master - debug: missing trace
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9969361b51d0b69fa04...
Commit: 9969361b51d0b69fa04a6a7cd87ca74208b2437a
Parent: a255385e3a5e3668eb0a4772cd867a3a7394285b
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Oct 17 12:40:13 2019 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Oct 17 13:03:50 2019 +0200
debug: missing trace
---
lib/metadata/lv_manip.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index e6524f3..b3a749d 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -6360,7 +6360,7 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,
return_0;
if (!archive(vg))
- return 0;
+ return_0;
/* Special case removing a striped raid LV with allocated reshape space */
if (seg && seg->reshape_len) {
4 years, 7 months
master - cachevol: move cvol rename
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a255385e3a5e3668eb0...
Commit: a255385e3a5e3668eb0a4772cd867a3a7394285b
Parent: dab4a2c893ef48636809b75b2ee225e195073fe0
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Oct 16 12:10:47 2019 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Oct 17 13:03:50 2019 +0200
cachevol: move cvol rename
Move rename of CVOL after archive().
---
tools/lvconvert.c | 26 +++++++++++++-------------
1 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 48ff8e1..a21f965 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -3453,6 +3453,7 @@ static int _cache_vol_attach(struct cmd_context *cmd,
struct logical_volume *lv,
struct logical_volume *lv_fast)
{
+ char cvol_name[NAME_LEN];
struct volume_group *vg = lv->vg;
struct logical_volume *cache_lv;
uint32_t chunk_size = 0;
@@ -3475,6 +3476,18 @@ static int _cache_vol_attach(struct cmd_context *cmd,
if (!archive(vg))
goto_out;
+ /*
+ * The lvm tradition is to rename an LV with a special role-specific
+ * suffix when it becomes hidden. Here the _cvol suffix is added to
+ * the fast LV name. When the cache is detached, it's renamed back.
+ */
+ if (dm_snprintf(cvol_name, sizeof(cvol_name), "%s_cvol", lv_fast->name) < 0) {
+ log_error("Can't prepare new cachevol name for %s.", display_lvname(lv_fast));
+ goto out;
+ }
+ if (!lv_rename_update(cmd, lv_fast, cvol_name, 0))
+ goto_out;
+
lv_fast->status |= LV_CACHE_VOL; /* Mark as cachevol LV */
/*
@@ -4216,7 +4229,6 @@ static int _lvconvert_cachevol_attach_single(struct cmd_context *cmd,
struct volume_group *vg = lv->vg;
struct logical_volume *cachevol_lv;
const char *cachevol_name;
- char cvol_name[NAME_LEN];
if (!(cachevol_name = arg_str_value(cmd, cachevol_ARG, NULL)))
goto_out;
@@ -4261,18 +4273,6 @@ static int _lvconvert_cachevol_attach_single(struct cmd_context *cmd,
if (_raid_split_image_conversion(lv))
goto_out;
- /*
- * The lvm tradition is to rename an LV with a special role-specific
- * suffix when it becomes hidden. Here the _cvol suffix is added to
- * the fast LV name. When the cache is detached, it's renamed back.
- */
- if (dm_snprintf(cvol_name, sizeof(cvol_name), "%s_cvol", cachevol_lv->name) < 0) {
- log_error("Can't prepare new metadata name for %s.", display_lvname(cachevol_lv));
- return 0;
- }
- if (!lv_rename_update(cmd, cachevol_lv, cvol_name, 0))
- return_0;
-
/* Attach the cache to the main LV. */
if (!_cache_vol_attach(cmd, lv, cachevol_lv))
4 years, 7 months
master - cachevol: move flag setting after taking archive
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=dab4a2c893ef4863680...
Commit: dab4a2c893ef48636809b75b2ee225e195073fe0
Parent: f63e20ebcc0488a574fcfb65ea015fb2f988212a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Oct 16 21:22:20 2019 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Oct 17 13:03:50 2019 +0200
cachevol: move flag setting after taking archive
Before 'archive()' is called, lvm2 must not touch/modify metadata.
So move setting CACHE_VOL related flags past this point.
Also make sure reading of cache segtype always restores this
flag properly (even if compatible flag would be lost).
---
lib/cache_segtype/cache.c | 7 ++++---
lib/metadata/pool_manip.c | 16 ++++++++++++++--
tools/lvconvert.c | 13 ++-----------
3 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/lib/cache_segtype/cache.c b/lib/cache_segtype/cache.c
index 4699070..69b46a5 100644
--- a/lib/cache_segtype/cache.c
+++ b/lib/cache_segtype/cache.c
@@ -504,9 +504,6 @@ static int _cache_text_import(struct lv_segment *seg,
seg->lv->status |= strstr(seg->lv->name, "_corig") ? LV_PENDING_DELETE : 0;
- if (!attach_pool_lv(seg, pool_lv, NULL, NULL, NULL))
- return_0;
-
if (!_settings_text_import(seg, sn))
return_0;
@@ -547,6 +544,7 @@ static int _cache_text_import(struct lv_segment *seg,
if (!id_read_format(seg->data_id, uuid))
return SEG_LOG_ERROR("Couldn't format data_id in");
}
+ pool_lv->status |= LV_CACHE_VOL; /* Mark as cachevol LV */
} else {
/* Do not call this when LV is cache_vol. */
/* load order is unknown, could be cache origin or pool LV, so check for both */
@@ -554,6 +552,9 @@ static int _cache_text_import(struct lv_segment *seg,
_fix_missing_defaults(first_seg(pool_lv));
}
+ if (!attach_pool_lv(seg, pool_lv, NULL, NULL, NULL))
+ return_0;
+
return 1;
}
diff --git a/lib/metadata/pool_manip.c b/lib/metadata/pool_manip.c
index 8d0aa83..bed51f1 100644
--- a/lib/metadata/pool_manip.c
+++ b/lib/metadata/pool_manip.c
@@ -106,8 +106,20 @@ int attach_pool_lv(struct lv_segment *seg,
seg->origin = origin;
seg->lv->status |= seg_is_cache(seg) ? CACHE : THIN_VOLUME;
- if (seg_is_cache(seg))
- lv_set_hidden(pool_lv); /* Used cache-pool is hidden */
+ if (seg_is_cache(seg)) {
+ lv_set_hidden(pool_lv); /* Used cache-pool/cachevol is hidden */
+
+ if (lv_is_cache_vol(pool_lv))
+ /*
+ * This flag is added to the segtype name so that old versions of lvm
+ * (if they happen to be used with new metadata with a cache LV using a
+ * cachevol) will report an error when they see the unknown
+ * cache+CACHE_USES_CACHEVOL segment type. Otherwise the old version
+ * would expect to find a cache pool and fail.
+ */
+ seg->lv->status |= LV_CACHE_USES_CACHEVOL;
+ }
+
if (origin && !add_seg_to_segs_using_this_lv(origin, seg))
return_0;
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 5a3c1c4..48ff8e1 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -3475,6 +3475,8 @@ static int _cache_vol_attach(struct cmd_context *cmd,
if (!archive(vg))
goto_out;
+ lv_fast->status |= LV_CACHE_VOL; /* Mark as cachevol LV */
+
/*
* Changes the vg struct to match the desired state.
*
@@ -4271,17 +4273,6 @@ static int _lvconvert_cachevol_attach_single(struct cmd_context *cmd,
if (!lv_rename_update(cmd, cachevol_lv, cvol_name, 0))
return_0;
- /*
- * This flag is added to the segtype name so that old versions of lvm
- * (if they happen to be used with new metadata with a cache LV using a
- * cachevol) will report an error when they see the unknown
- * cache+CACHE_USES_CACHEVOL segment type. Otherwise the old version
- * would expect to find a cache pool and fail.
- */
- lv->status |= LV_CACHE_USES_CACHEVOL;
-
- cachevol_lv->status |= LV_CACHE_VOL;
-
/* Attach the cache to the main LV. */
if (!_cache_vol_attach(cmd, lv, cachevol_lv))
4 years, 7 months
master - cache: drop validation check
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=f63e20ebcc0488a574f...
Commit: f63e20ebcc0488a574fcfb65ea015fb2f988212a
Parent: af8cfa90d9c4cdcb14c1cf69715405e22ac68432
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Oct 16 18:47:20 2019 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Oct 17 13:03:49 2019 +0200
cache: drop validation check
Since now we can cache either with cache-pool LV or
any other LV (being used as cachevol LV) drop the
validation condition.
---
lib/metadata/cache_manip.c | 6 ------
1 files changed, 0 insertions(+), 6 deletions(-)
diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c
index febd82a..5275d24 100644
--- a/lib/metadata/cache_manip.c
+++ b/lib/metadata/cache_manip.c
@@ -341,12 +341,6 @@ int validate_lv_cache_create_pool(const struct logical_volume *pool_lv)
{
struct lv_segment *seg;
- if (!lv_is_cache_pool(pool_lv) && !lv_is_cache_vol(pool_lv)) {
- log_error("Logical volume %s is not a cache pool.",
- display_lvname(pool_lv));
- return 0;
- }
-
if (lv_is_locked(pool_lv)) {
log_error("Cannot use locked cache pool %s.",
display_lvname(pool_lv));
4 years, 7 months
master - cachevol: use CVOL UUID for cdata and cmeta layered devices
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=2a08d6d1d4945024be5...
Commit: 2a08d6d1d4945024be5e686de0df02fc66ad8d8d
Parent: 55bf692bff777e3beefed5b89a28c1fb1ebe1d32
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Oct 16 16:05:51 2019 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Oct 17 13:03:49 2019 +0200
cachevol: use CVOL UUID for cdata and cmeta layered devices
Since code is using -cdata and -cmeta UUID suffixes, it does not need
any new 'extra' ID to be generated and stored in metadata.
Since introduce of new 'segtype' cache+CACHE_USES_CACHEVOL we can
safely assume 'new' cache with cachevol will now be created
without extra metadata_id and data_id in metadata.
For backward compatibility, code still reads them in case older
version of metadata have them - so it still should be able
to activate such volumes.
Bonus is lowered size of lv structure used to store info about LV
(noticable with big volume groups).
---
WHATS_NEW | 1 +
lib/activate/dev_manager.c | 10 ++++---
lib/cache_segtype/cache.c | 48 +++++++++++++++++++++++--------------
lib/metadata/cache_manip.c | 14 +++++-----
lib/metadata/metadata-exported.h | 4 +-
5 files changed, 46 insertions(+), 31 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index e4106c1..d6e4c9a 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.03.06 -
================================
+ No longer store extra UUID for cmeta and cdata cachevol layer.
Enhance activation of cache devices with cachevols.
Add _cvol in list of protected suffixes and start use it with DM UUID.
Rename LV converted to cachevol to use _cvol suffix.
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index 38a397b..9e4dba4 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -2374,9 +2374,11 @@ static int _add_cvol_subdev_to_dtree(struct dev_manager *dm, struct dm_tree *dtr
char *name ,*dlid;
union lvid lvid = { 0 };
- /* TODO: Convert to use just CVOL UUID with suffix */
memcpy(&lvid.id[0], &lv->vg->id, sizeof(struct id));
- memcpy(&lvid.id[1], (meta_or_data) ? &lvseg->metadata_id : &lvseg->data_id, sizeof(struct id));
+ /* When ID is provided in form of metadata_id or data_id, otherwise use CVOL ID */
+ memcpy(&lvid.id[1],
+ (meta_or_data && lvseg->metadata_id) ? lvseg->metadata_id :
+ (lvseg->data_id) ? lvseg->data_id : &pool_lv->lvid.id[1], sizeof(struct id));
if (!(dlid = dm_build_dm_uuid(mem, UUID_PREFIX, (const char *)&lvid.s, layer)))
return_0;
@@ -3159,9 +3161,9 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
memset(&lvid_meta, 0, sizeof(lvid_meta));
memset(&lvid_data, 0, sizeof(lvid_meta));
memcpy(&lvid_meta.id[0], &vg->id, sizeof(struct id));
- memcpy(&lvid_meta.id[1], &lvseg->metadata_id, sizeof(struct id));
+ memcpy(&lvid_meta.id[1], lvseg->metadata_id ? : &pool_lv->lvid.id[1], sizeof(struct id));
memcpy(&lvid_data.id[0], &vg->id, sizeof(struct id));
- memcpy(&lvid_data.id[1], &lvseg->data_id, sizeof(struct id));
+ memcpy(&lvid_data.id[1], lvseg->data_id ? : &pool_lv->lvid.id[1], sizeof(struct id));
if (!(dlid_meta = dm_build_dm_uuid(dm->mem, UUID_PREFIX, (const char *)&lvid_meta.s, "cmeta")))
return_0;
diff --git a/lib/cache_segtype/cache.c b/lib/cache_segtype/cache.c
index 798b157..4699070 100644
--- a/lib/cache_segtype/cache.c
+++ b/lib/cache_segtype/cache.c
@@ -528,17 +528,25 @@ static int _cache_text_import(struct lv_segment *seg,
if (!dm_config_get_uint64(sn, "data_len", &seg->data_len))
return SEG_LOG_ERROR("Couldn't read data_len in");
- if (!dm_config_get_str(sn, "metadata_id", &uuid))
- return SEG_LOG_ERROR("Couldn't read metadata_id in");
-
- if (!id_read_format(&seg->metadata_id, uuid))
- return SEG_LOG_ERROR("Couldn't format metadata_id in");
-
- if (!dm_config_get_str(sn, "data_id", &uuid))
- return SEG_LOG_ERROR("Couldn't read data_id in");
+ /* Will use CVOL ID, when metadata_id is not provided */
+ if (dm_config_has_node(sn, "metadata_id")) {
+ if (!(seg->metadata_id = dm_pool_alloc(seg->lv->vg->vgmem, sizeof(*seg->metadata_id))))
+ return SEG_LOG_ERROR("Couldn't allocate metadata_id in");
+ if (!dm_config_get_str(sn, "metadata_id", &uuid))
+ return SEG_LOG_ERROR("Couldn't read metadata_id in");
+ if (!id_read_format(seg->metadata_id, uuid))
+ return SEG_LOG_ERROR("Couldn't format metadata_id in");
+ }
- if (!id_read_format(&seg->data_id, uuid))
- return SEG_LOG_ERROR("Couldn't format data_id in");
+ /* Will use CVOL ID, when data_id is not provided */
+ if (dm_config_has_node(sn, "data_id")) {
+ if (!(seg->data_id = dm_pool_alloc(seg->lv->vg->vgmem, sizeof(*seg->data_id))))
+ return SEG_LOG_ERROR("Couldn't allocate data_id in");
+ if (!dm_config_get_str(sn, "data_id", &uuid))
+ return SEG_LOG_ERROR("Couldn't read data_id in");
+ if (!id_read_format(seg->data_id, uuid))
+ return SEG_LOG_ERROR("Couldn't format data_id in");
+ }
} else {
/* Do not call this when LV is cache_vol. */
/* load order is unknown, could be cache origin or pool LV, so check for both */
@@ -581,13 +589,17 @@ static int _cache_text_export(const struct lv_segment *seg, struct formatter *f)
outf(f, "data_start = " FMTu64, seg->data_start);
outf(f, "data_len = " FMTu64, seg->data_len);
- if (!id_write_format(&seg->metadata_id, buffer, sizeof(buffer)))
- return_0;
- outf(f, "metadata_id = \"%s\"", buffer);
+ if (seg->metadata_id) {
+ if (!id_write_format(seg->metadata_id, buffer, sizeof(buffer)))
+ return_0;
+ outf(f, "metadata_id = \"%s\"", buffer);
+ }
- if (!id_write_format(&seg->data_id, buffer, sizeof(buffer)))
- return_0;
- outf(f, "data_id = \"%s\"", buffer);
+ if (seg->data_id) {
+ if (!id_write_format(seg->data_id, buffer, sizeof(buffer)))
+ return_0;
+ outf(f, "data_id = \"%s\"", buffer);
+ }
}
return 1;
@@ -695,9 +707,9 @@ static int _cache_add_target_line(struct dev_manager *dm,
memset(&metadata_lvid, 0, sizeof(metadata_lvid));
memset(&data_lvid, 0, sizeof(data_lvid));
memcpy(&metadata_lvid.id[0], &seg->lv->vg->id, sizeof(struct id));
- memcpy(&metadata_lvid.id[1], &seg->metadata_id, sizeof(struct id));
+ memcpy(&metadata_lvid.id[1], (seg->metadata_id) ? : &seg->pool_lv->lvid.id[1], sizeof(struct id));
memcpy(&data_lvid.id[0], &seg->lv->vg->id, sizeof(struct id));
- memcpy(&data_lvid.id[1], &seg->data_id, sizeof(struct id));
+ memcpy(&data_lvid.id[1], (seg->data_id) ? : &seg->pool_lv->lvid.id[1], sizeof(struct id));
if (!(metadata_uuid = dm_build_dm_uuid(mem, UUID_PREFIX, (const char *)&metadata_lvid.s, "cmeta")))
return_0;
diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c
index 53600d9..3b51ea0 100644
--- a/lib/metadata/cache_manip.c
+++ b/lib/metadata/cache_manip.c
@@ -578,7 +578,7 @@ int lv_cache_remove(struct logical_volume *cache_lv)
struct lv_segment *cache_seg = first_seg(cache_lv);
struct logical_volume *corigin_lv;
struct logical_volume *cache_pool_lv;
- const struct id *data_id, *metadata_id;
+ struct id *data_id, *metadata_id;
uint64_t data_len, metadata_len;
cache_mode_t cache_mode;
int is_clear;
@@ -668,9 +668,9 @@ int lv_cache_remove(struct logical_volume *cache_lv)
/* Preserve currently imortant data from original cache segment.
* TODO: can it be done without this ? */
- data_id = &cache_seg->data_id;
+ data_id = cache_seg->data_id;
data_len = cache_seg->data_len;
- metadata_id = &cache_seg->metadata_id;
+ metadata_id = cache_seg->metadata_id;
metadata_len = cache_seg->metadata_len;
/* Replace 'error' with 'cache' segtype */
@@ -691,8 +691,8 @@ int lv_cache_remove(struct logical_volume *cache_lv)
/* Restore preserved data into a new cache segment that is going to be removed. */
if ((cache_seg->data_len = data_len)) {
cache_seg->metadata_len = metadata_len;
- memcpy(&cache_seg->data_id, data_id, sizeof(struct id));
- memcpy(&cache_seg->metadata_id, metadata_id, sizeof(struct id));
+ cache_seg->data_id = data_id;
+ cache_seg->metadata_id = metadata_id;
cache_pool_lv->status |= LV_CACHE_VOL;
/* Unused settings set only for passing metadata validation. */
cache_seg->cache_mode = CACHE_MODE_WRITETHROUGH;
@@ -1215,8 +1215,8 @@ int cache_vol_set_params(struct cmd_context *cmd,
cache_seg->cache_metadata_format = format;
cache_seg->policy_name = policy_name;
cache_seg->policy_settings = policy_settings;
- id_create(&cache_seg->metadata_id);
- id_create(&cache_seg->data_id);
+ /* Since we add -cdata and -cmeta to UUID we use CacheVol LV UUID */
+ cache_seg->data_id = cache_seg->metadata_id = NULL;
return 1;
}
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 66d8579..f340093 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -506,8 +506,8 @@ struct lv_segment {
uint64_t metadata_len; /* For cache */
uint64_t data_start; /* For cache */
uint64_t data_len; /* For cache */
- struct id metadata_id; /* For cache */
- struct id data_id; /* For cache */
+ struct id *metadata_id; /* For cache, when NULL uses CVOL id */
+ struct id *data_id; /* For cache, when NULL uses CVOL id */
cache_metadata_format_t cache_metadata_format;/* For cache_pool */
cache_mode_t cache_mode; /* For cache_pool */
4 years, 7 months
master - cache: add more comments for min meta size
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=af8cfa90d9c4cdcb14c...
Commit: af8cfa90d9c4cdcb14c1cf69715405e22ac68432
Parent: 2a08d6d1d4945024be5e686de0df02fc66ad8d8d
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Oct 16 18:46:03 2019 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Oct 17 13:03:49 2019 +0200
cache: add more comments for min meta size
Enhance source code with better explanation how the minimal
metadata size is evaluated from data size and chunk size.
---
lib/metadata/cache_manip.c | 22 +++++++++++++---------
1 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c
index 3b51ea0..febd82a 100644
--- a/lib/metadata/cache_manip.c
+++ b/lib/metadata/cache_manip.c
@@ -178,18 +178,22 @@ void cache_check_for_warns(const struct lv_segment *seg)
}
/*
- * Returns minimum size of cache metadata volume for give data and chunk size
- * (all values in sector)
- * Default meta size is: (Overhead + mapping size + hint size)
+ * Returns the minimum size of cache metadata volume for given cache data size and
+ * and cache chunk size (all in/out values in sectors)
+ * Default metadata size is: (Overhead + mapping size + hint size)
*/
static uint64_t _cache_min_metadata_size(uint64_t data_size, uint32_t chunk_size)
{
- uint64_t min_meta_size;
-
- min_meta_size = data_size / chunk_size; /* nr_chunks */
- min_meta_size *= (DM_BYTES_PER_BLOCK + DM_MAX_HINT_WIDTH + DM_HINT_OVERHEAD_PER_BLOCK);
- min_meta_size = (min_meta_size + (SECTOR_SIZE - 1)) >> SECTOR_SHIFT; /* in sectors */
- min_meta_size += DM_TRANSACTION_OVERHEAD * (1024 >> SECTOR_SHIFT);
+ /* Used space for mapping and hints for each cached chunk in bytes
+ * (matching thin-tools cache_metadata_size.cc) */
+ const uint64_t chunk_overhead = (DM_BYTES_PER_BLOCK + DM_MAX_HINT_WIDTH + DM_HINT_OVERHEAD_PER_BLOCK);
+ const uint64_t transaction_overhead = DM_TRANSACTION_OVERHEAD * 1024; /* 4MiB */
+
+ /* Number of cache chunks we have in caching volume */
+ uint64_t nr_chunks = data_size / chunk_size;
+ /* Minimal size of metadata volume converted back to sectors */
+ uint64_t min_meta_size = (transaction_overhead + nr_chunks * chunk_overhead +
+ (SECTOR_SIZE - 1)) >> SECTOR_SHIFT;
return min_meta_size;
}
4 years, 7 months
stable-2.02 - devs: check for no dev when dropping aliases
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=f50af80199f723f7b19...
Commit: f50af80199f723f7b1970ee33ddf959ea79fcbef
Parent: 219c4c2ce2c605960ad760ac99be27b2665a8c43
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Oct 16 13:32:28 2019 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Oct 16 13:32:28 2019 -0500
devs: check for no dev when dropping aliases
When scanning fails to find a device path and
looks for device aliases, check if the device
itself still exists to avoid a potential segfault.
---
lib/label/label.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/lib/label/label.c b/lib/label/label.c
index 8107e33..e4a1068 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -734,6 +734,11 @@ static int _scan_list(struct cmd_context *cmd, struct dev_filter *f,
retried_open = 1;
dm_list_iterate_items_safe(devl, devl2, &reopen_devs) {
+ if (!devl->dev) {
+ dm_list_del(&devl->list);
+ continue;
+ }
+
_drop_bad_aliases(devl->dev);
if (dm_list_empty(&devl->dev->aliases)) {
4 years, 7 months
master - tests: metadata-zero-space long vgnames
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=55bf692bff777e3beef...
Commit: 55bf692bff777e3beefed5b89a28c1fb1ebe1d32
Parent: 998e7b107513697b3ea966ba49aeef3fe115d908
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Oct 16 09:46:48 2019 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Oct 16 09:46:48 2019 -0500
tests: metadata-zero-space long vgnames
In the hex dump output, grep for the vgname
followed by one space. This allows for test pids
with up to seven digits, which are used to contruct
the variable vgname used by the test. Otherwise
the long vgname wraps to the next line and fails to
match in grep.
---
test/shell/metadata-zero-space.sh | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/test/shell/metadata-zero-space.sh b/test/shell/metadata-zero-space.sh
index d037ab2..f04de48 100644
--- a/test/shell/metadata-zero-space.sh
+++ b/test/shell/metadata-zero-space.sh
@@ -39,9 +39,9 @@ xxd meta.raw > meta.txt
# to help debug if the next grep fails
ls -l meta.txt
head -n 100 meta.txt
-grep -A4 -B4 1200 meta.txt
+grep -A4 -B4 '01200:' meta.txt
-grep -B1 "$vg {" meta.txt > meta.vg
+grep -B1 "$vg " meta.txt > meta.vg
cat meta.vg
@@ -73,7 +73,7 @@ dd if="$dev1" of=meta.raw bs=1M seek=15 count=1
xxd meta.raw > meta.txt
-grep -B1 "$vg {" meta.txt > meta.vg
+grep -B1 "$vg " meta.txt > meta.vg
cat meta.vg
4 years, 7 months
master - writecache: add cvol suffix to attached cachevol
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=998e7b107513697b3ea...
Commit: 998e7b107513697b3ea966ba49aeef3fe115d908
Parent: 81fe0457141d74e20a7fda45a69164405fc9f151
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Oct 15 16:03:34 2019 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Oct 15 16:03:34 2019 -0500
writecache: add cvol suffix to attached cachevol
When an LV is used as a writecache cachevol, give
it the LV name a _cvol suffix. Remove the suffix
when the cachevol is detached, restoring the
original LV name.
---
test/shell/writecache.sh | 4 ++--
tools/lvconvert.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/test/shell/writecache.sh b/test/shell/writecache.sh
index 94fa459..6cd4665 100644
--- a/test/shell/writecache.sh
+++ b/test/shell/writecache.sh
@@ -52,7 +52,7 @@ lvconvert --yes --type writecache --cachevol $lv2 $vg/$lv1
check lv_field $vg/$lv1 segtype writecache
-lvs -a $vg/$lv2 --noheadings -o segtype >out
+lvs -a $vg/${lv2}_cvol --noheadings -o segtype >out
grep linear out
lvchange -ay $vg/$lv1
@@ -94,7 +94,7 @@ lvconvert --yes --type writecache --cachevol $lv2 $vg/$lv1
check lv_field $vg/$lv1 segtype writecache
-lvs -a $vg/$lv2 --noheadings -o segtype >out
+lvs -a $vg/${lv2}_cvol --noheadings -o segtype >out
grep linear out
lvchange -ay $vg/$lv1
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 9ab362b..5a3c1c4 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -4259,7 +4259,11 @@ static int _lvconvert_cachevol_attach_single(struct cmd_context *cmd,
if (_raid_split_image_conversion(lv))
goto_out;
- /* Attach the cache to the main LV. */
+ /*
+ * The lvm tradition is to rename an LV with a special role-specific
+ * suffix when it becomes hidden. Here the _cvol suffix is added to
+ * the fast LV name. When the cache is detached, it's renamed back.
+ */
if (dm_snprintf(cvol_name, sizeof(cvol_name), "%s_cvol", cachevol_lv->name) < 0) {
log_error("Can't prepare new metadata name for %s.", display_lvname(cachevol_lv));
return 0;
@@ -4278,6 +4282,8 @@ static int _lvconvert_cachevol_attach_single(struct cmd_context *cmd,
cachevol_lv->status |= LV_CACHE_VOL;
+ /* Attach the cache to the main LV. */
+
if (!_cache_vol_attach(cmd, lv, cachevol_lv))
goto_out;
@@ -5278,6 +5284,8 @@ static int _lvconvert_detach_writecache(struct cmd_context *cmd,
struct logical_volume *lv,
struct logical_volume *lv_fast)
{
+ char cvol_name[NAME_LEN];
+ char *c;
int noflush = 0;
/*
@@ -5315,6 +5323,27 @@ static int _lvconvert_detach_writecache(struct cmd_context *cmd,
if (!lv_detach_writecache_cachevol(lv, noflush))
return_0;
+ /*
+ * Rename lv_fast back to its original name, without the _cvol
+ * suffix that was added when lv_fast was attached for caching.
+ */
+ if (!dm_strncpy(cvol_name, lv_fast->name, sizeof(cvol_name)) ||
+ !(c = strstr(cvol_name, "_cvol"))) {
+ log_debug("LV %s has no suffix for cachevol (skipping rename).",
+ display_lvname(lv_fast));
+ } else {
+ *c = 0;
+ /* If the name is in use, generate new lvol%d */
+ if (lv_name_is_used_in_vg(lv->vg, cvol_name, NULL) &&
+ !generate_lv_name(lv->vg, "lvol%d", cvol_name, sizeof(cvol_name))) {
+ log_error("Failed to generate unique name for unused logical volume.");
+ return 0;
+ }
+
+ if (!lv_rename_update(cmd, lv_fast, cvol_name, 0))
+ return_0;
+ }
+
if (!vg_write(lv->vg) || !vg_commit(lv->vg))
return_0;
@@ -5546,6 +5575,7 @@ static int _lvconvert_writecache_attach_single(struct cmd_context *cmd,
char *lockd_fast_args = NULL;
char *lockd_fast_name = NULL;
struct id lockd_fast_id;
+ char cvol_name[NAME_LEN];
fast_name = arg_str_value(cmd, cachevol_ARG, "");
@@ -5602,6 +5632,18 @@ static int _lvconvert_writecache_attach_single(struct cmd_context *cmd,
return ECMD_FAILED;
}
+ /*
+ * The lvm tradition is to rename an LV with a special role-specific
+ * suffix when it becomes hidden. Here the _cvol suffix is added to
+ * the fast LV name. When the cache is detached, it's renamed back.
+ */
+ if (dm_snprintf(cvol_name, sizeof(cvol_name), "%s_cvol", lv_fast->name) < 0) {
+ log_error("Can't prepare new metadata name for %s.", display_lvname(lv_fast));
+ return ECMD_FAILED;
+ }
+ if (!lv_rename_update(cmd, lv_fast, cvol_name, 0))
+ return_ECMD_FAILED;
+
lv_fast->status |= LV_CACHE_VOL;
/*
4 years, 7 months
master - cache: change default cachevol metadata sizes
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=81fe0457141d74e20a7...
Commit: 81fe0457141d74e20a7fda45a69164405fc9f151
Parent: 0443d00ff1efdb5af05def774a4961563377dbd0
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Oct 15 14:16:14 2019 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Oct 15 14:36:03 2019 -0500
cache: change default cachevol metadata sizes
The first part of a cachevol LV is used for metadata,
and the rest of the space is used for data. The
division of space between metadata and data depends
on the total size of the cachevol.
The previous division gave more space than needed to
metadata, it was:
cachevol size 8M to 128M -> metadata size 16M *
cachevol size 128M to 1G -> metadata size 32M
cachevol size 1G and up -> metadata size 64M
(* if this resulted in over half the LV used as
metadata, then half the cachevol would be used
for metadata, and the other half for data.)
The division of space now gives less space to
metadata, it is:
cachevol size 8M to 16M -> metadata size 4M
cachevol size 16M to 4G -> metadata size 8M
cachevol size 4G to 16G -> metadata size 16M
cachevol size 16G to 32G -> metadata size 32M
cachevol size 32G and up -> metadata size 64M
---
lib/metadata/cache_manip.c | 34 ++++++++++++++++++++++++----------
1 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c
index 6eb68d5..53600d9 100644
--- a/lib/metadata/cache_manip.c
+++ b/lib/metadata/cache_manip.c
@@ -969,8 +969,8 @@ int cache_set_metadata_format(struct lv_segment *seg, cache_metadata_format_t fo
return 1;
}
-#define ONE_MB_S 2048 /* 1MB in sectors */
-#define ONE_GB_S 2097152 /* 1GB in sectors */
+#define ONE_MB_IN_SECTORS 2048 /* 1MB in sectors */
+#define ONE_GB_IN_SECTORS 2097152 /* 1GB in sectors */
int cache_vol_set_params(struct cmd_context *cmd,
struct logical_volume *cache_lv,
@@ -1082,18 +1082,32 @@ int cache_vol_set_params(struct cmd_context *cmd,
}
}
+ /*
+ * cachevol size 8M to 16M -> metadata size 4M
+ *
+ * cachevol size 16M to 4G -> metadata size 8M
+ *
+ * cachevol size 4G to 16G -> metadata size 16M
+ *
+ * cachevol size 16G to 32G -> metadata size 32M
+ *
+ * cachevol size 32G and up -> metadata size 64M
+ */
if (!meta_size) {
- if (pool_lv->size < (128 * ONE_MB_S))
- meta_size = 16 * ONE_MB_S;
+ if (pool_lv->size <= (16 * ONE_MB_IN_SECTORS))
+ meta_size = 4 * ONE_MB_IN_SECTORS;
+
+ else if (pool_lv->size <= (4 * ONE_GB_IN_SECTORS))
+ meta_size = 8 * ONE_MB_IN_SECTORS;
- else if (pool_lv->size < ONE_GB_S)
- meta_size = 32 * ONE_MB_S;
+ else if (pool_lv->size <= (16 * ONE_GB_IN_SECTORS))
+ meta_size = 16 * ONE_MB_IN_SECTORS;
- else if (pool_lv->size < (128 * ONE_GB_S))
- meta_size = 64 * ONE_MB_S;
+ else if (pool_lv->size <= (32 * ONE_GB_IN_SECTORS))
+ meta_size = 32 * ONE_MB_IN_SECTORS;
- if (meta_size > (pool_lv->size / 2))
- meta_size = pool_lv->size / 2;
+ else
+ meta_size = 64 * ONE_MB_IN_SECTORS;
if (meta_size < min_meta_size)
meta_size = min_meta_size;
4 years, 7 months