summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Rajnoha <prajnoha@redhat.com>2015-09-02 09:12:18 +0200
committerPeter Rajnoha <prajnoha@redhat.com>2016-02-04 16:20:34 +0100
commite58d3de62bfbcb458042273ad814f1bdd214dafd (patch)
tree765cd92e50d700337183d9605c3260e5b1d5c846
parentfcf96b7c78920b8aa3cc6657b7806abc87cb5dcf (diff)
downloadlvm2-e58d3de62bfbcb458042273ad814f1bdd214dafd.tar.gz
metadata: add vg_strip_outdated_dead_lvs fn and call it during VG read
The vg_strip_outdated_dead_lvs iterates over the list of dead LVs we have and it shoots down the ones which are outdated. The configuration hook to set the timeout will be in subsequent patch.
-rw-r--r--lib/metadata/metadata-exported.h2
-rw-r--r--lib/metadata/metadata.c38
2 files changed, 39 insertions, 1 deletions
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index a974dac04..1ed55f74f 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -1262,4 +1262,6 @@ int is_lockd_type(const char *lock_type);
int is_system_id_allowed(struct cmd_context *cmd, const char *system_id);
+int vg_strip_outdated_dead_lvs(struct volume_group *vg);
+
#endif
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 054173f37..2625b55bc 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -3620,6 +3620,7 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
int inconsistent_pvs = 0;
int inconsistent_mdas = 0;
int inconsistent_mda_count = 0;
+ int strip_dead_lvs = *consistent;
unsigned use_precommitted = precommitted;
struct dm_list *pvids;
struct pv_list *pvl;
@@ -3654,6 +3655,10 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
lvmetad_vg_clear_outdated_pvs(correct_vg);
}
}
+
+ if (correct_vg && strip_dead_lvs && !vg_strip_outdated_dead_lvs(correct_vg))
+ return_NULL;
+
return correct_vg;
}
@@ -4086,6 +4091,9 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
return NULL;
}
+ if (correct_vg && strip_dead_lvs && !vg_strip_outdated_dead_lvs(correct_vg))
+ return_NULL;
+
*consistent = 1;
return correct_vg;
}
@@ -4133,7 +4141,6 @@ struct volume_group *vg_read_internal(struct cmd_context *cmd, const char *vgnam
goto out;
}
}
-
out:
if (!*consistent && (warn_flags & WARN_INCONSISTENT))
log_warn("WARNING: Volume Group %s is not consistent.", vgname);
@@ -5674,3 +5681,32 @@ int is_lockd_type(const char *lock_type)
return 0;
}
+int vg_strip_outdated_dead_lvs(struct volume_group *vg) {
+ struct glv_list *glvl, *tglvl;
+ time_t current_time = time(NULL);
+ uint64_t threshold = 0;
+
+ if (!threshold)
+ return 1;
+
+ dm_list_iterate_items_safe(glvl, tglvl, &vg->dead_lvs) {
+ /*
+ * Removal time in the future? Not likely,
+ * but skip this item in any case.
+ */
+ if ((current_time) < glvl->glv->dead->timestamp_removed)
+ continue;
+
+ if ((current_time - glvl->glv->dead->timestamp_removed) > threshold) {
+ if (!dead_glv_remove(glvl->glv)) {
+ log_error("Failed to destroy record about removed LV %s/%s.",
+ vg->name, glvl->glv->dead->dname);
+ return 0;
+ }
+ log_verbose("Outdated record for removed logical volume \"%s\" "
+ "automatically destroyed.", glvl->glv->dead->dname);
+ }
+ }
+
+ return 1;
+}