From 59743245b4ceacb82e7a1d4ef916452f839458af Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Fri, 27 Jun 2008 15:18:31 +0000 Subject: [PATCH] Fix up cache for PVs without mdas after consistent VG metadata is processed. --- WHATS_NEW | 1 + lib/cache/lvmcache.c | 22 ++++++++++++++++------ lib/metadata/metadata.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index b93ef0d4f..7c9ad933f 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.39 - ================================ + Fix up cache for PVs without mdas after consistent VG metadata is processed. Update validation of safe mirror log type conversions in lvconvert. Fix lvconvert to disallow snapshot and mirror combinations. Fix reporting of LV fields alongside unallocated PV segments. diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c index a25ccde41..139425ff7 100644 --- a/lib/cache/lvmcache.c +++ b/lib/cache/lvmcache.c @@ -845,6 +845,7 @@ static int _lvmcache_update_vgname(struct lvmcache_info *info, { struct lvmcache_vginfo *vginfo, *primary_vginfo, *orphan_vginfo; struct lvmcache_info *info2, *info3; + char mdabuf[32]; // struct lvmcache_vginfo *old_vginfo, *next; if (!vgname || (info && info->vginfo && !strcmp(info->vginfo->vgname, vgname))) @@ -914,11 +915,16 @@ static int _lvmcache_update_vgname(struct lvmcache_info *info, orphan_vginfo = vginfo_from_vgname(primary_vginfo->fmt->orphan_vg_name, NULL); _drop_vginfo(info2, primary_vginfo); _vginfo_attach_info(orphan_vginfo, info2); - log_debug("lvmcache: %s: now in VG %s%s%s%s", + if (info2->mdas.n) + sprintf(mdabuf, " with %u mdas", + list_size(&info2->mdas)); + else + mdabuf[0] = '\0'; + log_debug("lvmcache: %s: now in VG %s%s%s%s%s", dev_name(info2->dev), vgname, orphan_vginfo->vgid[0] ? " (" : "", orphan_vginfo->vgid[0] ? orphan_vginfo->vgid : "", - orphan_vginfo->vgid[0] ? ")" : ""); + orphan_vginfo->vgid[0] ? ")" : "", mdabuf); } if (!_insert_vginfo(vginfo, vgid, vgstatus, creation_host, @@ -947,13 +953,17 @@ static int _lvmcache_update_vgname(struct lvmcache_info *info, /* FIXME Check consistency of list! */ vginfo->fmt = fmt; - if (info) - log_debug("lvmcache: %s: now in VG %s%s%s%s", + if (info) { + if (info->mdas.n) + sprintf(mdabuf, " with %u mdas", list_size(&info->mdas)); + else + mdabuf[0] = '\0'; + log_debug("lvmcache: %s: now in VG %s%s%s%s%s", dev_name(info->dev), vgname, vginfo->vgid[0] ? " (" : "", vginfo->vgid[0] ? vginfo->vgid : "", - vginfo->vgid[0] ? ")" : ""); - else + vginfo->vgid[0] ? ")" : "", mdabuf); + } else log_debug("lvmcache: initialised VG %s", vgname); return 1; diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index a82242417..6a1b250d5 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -1488,8 +1488,10 @@ static struct volume_group *_vg_read(struct cmd_context *cmd, const struct format_type *fmt; struct volume_group *vg, *correct_vg = NULL; struct metadata_area *mda; + struct lvmcache_info *info; int inconsistent = 0; int inconsistent_vgid = 0; + int inconsistent_pvs = 0; unsigned use_precommitted = precommitted; struct list *pvids; struct pv_list *pvl, *pvl2; @@ -1564,6 +1566,44 @@ static struct volume_group *_vg_read(struct cmd_context *cmd, /* Ensure every PV in the VG was in the cache */ if (correct_vg) { + /* + * If the VG has PVs without mdas, they may still be + * orphans in the cache: update the cache state here. + */ + if (!inconsistent && + list_size(&correct_vg->pvs) > list_size(pvids)) { + list_iterate_items(pvl, &correct_vg->pvs) { + if (!pvl->pv->dev) { + inconsistent_pvs = 1; + break; + } + + if (str_list_match_item(pvids, pvl->pv->dev->pvid)) + continue; + + /* + * PV not marked as belonging to this VG in cache. + * Check it's an orphan without metadata area. + */ + if (!(info = info_from_pvid(pvl->pv->dev->pvid, 1)) || + !info->vginfo || !is_orphan_vg(info->vginfo->vgname) || + list_size(&info->mdas)) { + inconsistent_pvs = 1; + break; + } + } + + /* If the check passed, let's update VG and recalculate pvids */ + if (!inconsistent_pvs) { + log_debug("Updating cache for PVs without mdas " + "in VG %s.", vgname); + lvmcache_update_vg(correct_vg, use_precommitted); + + if (!(pvids = lvmcache_get_pvids(cmd, vgname, vgid))) + return_NULL; + } + } + if (list_size(&correct_vg->pvs) != list_size(pvids)) { log_debug("Cached VG %s had incorrect PV list", vgname); -- 2.43.5