WHATS_NEW | 1 +
tools/lvconvert.c | 16 +++++++++++++++-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 2dfeada..5d3bb8b 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.104 -
===================================
+ Fix lvconvert swap of poolmetadata volume for active thin pool.
Add configure --enable-udev-systemd-background-jobs.
Add lvm2-pvscan@.service to run pvscan as a service for lvmetad/autoactivation.
Fix possible race during daemon worker thread creation (lvmetad).
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 1970ca3..1098642 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -2271,6 +2271,7 @@ static int _lvconvert_thinpool(struct cmd_context *cmd,
struct logical_volume *pool_metadata_lv;
struct logical_volume *external_lv = NULL;
char metadata_name[NAME_LEN], data_name[NAME_LEN];
+ int activate_pool;
if (!lv_is_visible(pool_lv)) {
log_error("Can't convert internal LV %s/%s.",
@@ -2299,6 +2300,7 @@ static int _lvconvert_thinpool(struct cmd_context *cmd,
}
if (lv_is_thin_pool(pool_lv)) {
+ activate_pool = lv_is_active(pool_lv);
r = 1; /* Already existing thin pool */
goto out;
}
@@ -2311,6 +2313,9 @@ static int _lvconvert_thinpool(struct cmd_context *cmd,
return 0;
}
+ /* Allow to have only thinpool active and restore it's active state */
+ activate_pool = lv_is_active(pool_lv);
+
/* We are changing target type, so deactivate first */
if (!deactivate_lv(cmd, pool_lv)) {
log_error("Aborting. Failed to deactivate logical volume %s/%s.",
@@ -2318,6 +2323,13 @@ static int _lvconvert_thinpool(struct cmd_context *cmd,
return 0;
}
+ if (lv_is_thin_pool(pool_lv) && pool_is_active(pool_lv)) {
+ /* If any thin volume is also active - abort here */
+ log_error("Cannot convert pool %s/%s with active thin volumes.",
+ pool_lv->vg->name, pool_lv->name);
+ return 0;
+ }
+
if ((dm_snprintf(metadata_name, sizeof(metadata_name), "%s_tmeta",
pool_lv->name) < 0) ||
(dm_snprintf(data_name, sizeof(data_name), "%s_tdata",
@@ -2419,6 +2431,7 @@ static int _lvconvert_thinpool(struct cmd_context *cmd,
goto mda_write;
}
+ metadata_lv->status |= LV_NOSCAN;
if (!lv_is_active(metadata_lv) &&
!activate_lv_local(cmd, metadata_lv)) {
log_error("Aborting. Failed to activate thin metadata lv.");
@@ -2511,7 +2524,8 @@ mda_write:
if (!vg_write(pool_lv->vg) || !vg_commit(pool_lv->vg))
return_0;
- if (!activate_lv_excl(cmd, pool_lv)) {
+ if (activate_pool &&
+ !activate_lv_excl(cmd, pool_lv)) {
log_error("Failed to activate pool logical volume %s/%s.",
pool_lv->vg->name, pool_lv->name);
/* Deactivate subvolumes */