diff --git a/VERSION b/VERSION index dcd226abe..1ab0063fe 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.02.05-cvs (2006-04-21) +2.02.06-cvs (2006-04-21) diff --git a/WHATS_NEW b/WHATS_NEW index 6c88198de..79a096684 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,3 +1,7 @@ +Version 2.02.06 - +================================= + Invalidate cache if composition of VG changed externally. + Version 2.02.05 - 21st April 2006 ================================= Fix vgid string termination in recent cache code. diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c index 83a34375c..b2c0696b8 100644 --- a/lib/cache/lvmcache.c +++ b/lib/cache/lvmcache.c @@ -306,6 +306,32 @@ struct list *lvmcache_get_vgnames(struct cmd_context *cmd, int full_scan) return vgnames; } +struct list *lvmcache_get_pvids(struct cmd_context *cmd, const char *vgname, + const char *vgid) +{ + struct list *pvids; + struct lvmcache_vginfo *vginfo; + struct lvmcache_info *info; + + if (!(pvids = str_list_create(cmd->mem))) { + log_error("pvids list allocation failed"); + return NULL; + } + + if (!(vginfo = vginfo_from_vgname(vgname, vgid))) + return pvids; + + list_iterate_items(info, &vginfo->infos) { + if (!str_list_add(cmd->mem, pvids, + dm_pool_strdup(cmd->mem, info->dev->pvid))) { + log_error("strlist allocation failed"); + return NULL; + } + } + + return pvids; +} + struct device *device_from_pvid(struct cmd_context *cmd, struct id *pvid) { struct label *label; diff --git a/lib/cache/lvmcache.h b/lib/cache/lvmcache.h index 5ee00f5e2..fbf4fd1e2 100644 --- a/lib/cache/lvmcache.h +++ b/lib/cache/lvmcache.h @@ -101,4 +101,8 @@ struct list *lvmcache_get_vgnames(struct cmd_context *cmd, int full_scan); /* Set full_scan to 1 to reread every filtered device label */ struct list *lvmcache_get_vgids(struct cmd_context *cmd, int full_scan); +/* Returns list of struct str_lists containing pool-allocated copy of pvids */ +struct list *lvmcache_get_pvids(struct cmd_context *cmd, const char *vgname, + const char *vgid); + #endif diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index c3f321181..db707fc64 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -919,6 +919,8 @@ static struct volume_group *_vg_read(struct cmd_context *cmd, struct metadata_area *mda; int inconsistent = 0; int use_precommitted = precommitted; + struct list *pvids; + struct pv_list *pvl; if (!*vgname) { if (use_precommitted) { @@ -950,6 +952,12 @@ static struct volume_group *_vg_read(struct cmd_context *cmd, if (use_precommitted && !(fmt->features & FMT_PRECOMMIT)) use_precommitted = 0; + /* Store pvids for later so we can check if any are missing */ + if (!(pvids = lvmcache_get_pvids(cmd, vgname, vgid))) { + stack; + return NULL; + } + /* create format instance with appropriate metadata area */ if (!(fid = fmt->ops->create_instance(fmt, vgname, vgid, NULL))) { log_error("Failed to create format instance"); @@ -977,6 +985,22 @@ static struct volume_group *_vg_read(struct cmd_context *cmd, } } + /* Ensure every PV in the VG was in the cache */ + if (correct_vg) { + if (list_size(&correct_vg->pvs) != list_size(pvids)) { + log_debug("Cached VG %s had incorrect PV list", + vg->name); + correct_vg = NULL; + } else list_iterate_items(pvl, &correct_vg->pvs) { + if (!str_list_match_item(pvids, pvl->pv->dev->pvid)) { + log_debug("Cached VG %s had incorrect PV list", + vg->name); + correct_vg = NULL; + break; + } + } + } + /* Failed to find VG where we expected it - full scan and retry */ if (!correct_vg) { inconsistent = 0;