mirror of
git://sourceware.org/git/lvm2.git
synced 2025-02-28 05:57:49 +03:00
metadata: automatically remove invalid (dangling) historical LVs
Historical LV is valid as long as there is at least one live LV among its ancestors. If we find any invalid (dangling) historical LVs, remove them automatically.
This commit is contained in:
parent
1297b0c8be
commit
8a601454e1
@ -94,6 +94,8 @@ struct historical_logical_volume {
|
||||
uint64_t timestamp_removed;
|
||||
struct generic_logical_volume *indirect_origin;
|
||||
struct dm_list indirect_glvs; /* list of struct generic_logical_volume */
|
||||
int checked:1; /* set if this historical LV has been checked for validity */
|
||||
int valid:1; /* historical LV is valid if there's at least one live LV among ancestors */
|
||||
};
|
||||
|
||||
struct generic_logical_volume {
|
||||
|
@ -3319,15 +3319,45 @@ static int _check_old_pv_ext_for_vg(struct volume_group *vg)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _handle_historical_lvs(struct volume_group *vg)
|
||||
static int _check_historical_lv_is_valid(struct historical_logical_volume *hlv)
|
||||
{
|
||||
struct glv_list *glvl;
|
||||
|
||||
if (hlv->checked)
|
||||
return hlv->valid;
|
||||
|
||||
/*
|
||||
* Historical LV is valid if there is
|
||||
* at least one live LV among ancestors.
|
||||
*/
|
||||
hlv->valid = 0;
|
||||
dm_list_iterate_items(glvl, &hlv->indirect_glvs) {
|
||||
if (!glvl->glv->is_historical ||
|
||||
_check_historical_lv_is_valid(glvl->glv->historical)) {
|
||||
hlv->valid = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
hlv->checked = 1;
|
||||
return hlv->valid;
|
||||
}
|
||||
|
||||
static int _handle_historical_lvs(struct volume_group *vg)
|
||||
{
|
||||
struct glv_list *glvl, *tglvl;
|
||||
time_t current_timestamp = 0;
|
||||
struct historical_logical_volume *hlv;
|
||||
int valid = 1;
|
||||
|
||||
dm_list_iterate_items(glvl, &vg->historical_lvs)
|
||||
glvl->glv->historical->checked = 0;
|
||||
|
||||
dm_list_iterate_items(glvl, &vg->historical_lvs) {
|
||||
hlv = glvl->glv->historical;
|
||||
|
||||
valid &= _check_historical_lv_is_valid(hlv);
|
||||
|
||||
if (!hlv->timestamp_removed) {
|
||||
if (!current_timestamp)
|
||||
current_timestamp = time(NULL);
|
||||
@ -3335,6 +3365,21 @@ static int _handle_historical_lvs(struct volume_group *vg)
|
||||
}
|
||||
}
|
||||
|
||||
if (valid)
|
||||
return 1;
|
||||
|
||||
dm_list_iterate_items_safe(glvl, tglvl, &vg->historical_lvs) {
|
||||
hlv = glvl->glv->historical;
|
||||
if (hlv->checked && hlv->valid)
|
||||
continue;
|
||||
|
||||
log_print_unless_silent("Automatically removing historical "
|
||||
"logical volume %s/%s%s.",
|
||||
vg->name, HISTORICAL_LV_PREFIX, hlv->name);
|
||||
if (!historical_glv_remove(glvl->glv))
|
||||
return_0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user