1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

metadata: add vg_strip_outdated_historical_lvs fn and call it during VG read

The vg_strip_outdated_historical_lvs iterates over the list of historical LVs
we have and it shoots down the ones which are outdated.

Configuration hook to set the timeout will be in subsequent patch.
This commit is contained in:
Peter Rajnoha 2016-03-01 15:27:21 +01:00
parent 53b064b9ae
commit 74272e163d
2 changed files with 40 additions and 1 deletions

View File

@ -1298,4 +1298,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_historical_lvs(struct volume_group *vg);
#endif

View File

@ -3930,6 +3930,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_historical_lvs = *consistent;
unsigned use_precommitted = precommitted;
struct dm_list *pvids;
struct pv_list *pvl;
@ -3965,6 +3966,10 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
lvmetad_vg_clear_outdated_pvs(correct_vg);
}
}
if (correct_vg && strip_historical_lvs && !vg_strip_outdated_historical_lvs(correct_vg))
return_NULL;
return correct_vg;
}
@ -4405,6 +4410,10 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
}
*consistent = !inconsistent_pvs;
if (*consistent && correct_vg && strip_historical_lvs && !vg_strip_outdated_historical_lvs(correct_vg))
return_NULL;
return correct_vg;
}
@ -4451,7 +4460,6 @@ struct volume_group *vg_read_internal(struct cmd_context *cmd, const char *vgnam
goto out;
}
}
out:
if (!*consistent && (warn_flags & WARN_INCONSISTENT)) {
if (is_orphan_vg(vgname))
@ -6002,3 +6010,32 @@ int is_lockd_type(const char *lock_type)
return 0;
}
int vg_strip_outdated_historical_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->historical_lvs) {
/*
* Removal time in the future? Not likely,
* but skip this item in any case.
*/
if ((current_time) < glvl->glv->historical->timestamp_removed)
continue;
if ((current_time - glvl->glv->historical->timestamp_removed) > threshold) {
if (!historical_glv_remove(glvl->glv)) {
log_error("Failed to destroy record about historical LV %s/%s.",
vg->name, glvl->glv->historical->name);
return 0;
}
log_verbose("Outdated record for historical logical volume \"%s\" "
"automatically destroyed.", glvl->glv->historical->name);
}
}
return 1;
}