{
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)))
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,
/* 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;
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;
/* 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);