summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Rockai <prockai@redhat.com>2014-10-07 16:06:21 +0200
committerPetr Rockai <prockai@redhat.com>2014-10-07 16:11:56 +0200
commit88959032f7efb9229632c74a3738aae171f0c460 (patch)
treee507702056802054ae3c9e20597e63be1d8d0017
parent0cbb381e159f0606ec749697a596d2a6cc814283 (diff)
downloadlvm2-88959032f7efb9229632c74a3738aae171f0c460.tar.gz
metadata: Fix find_pv_in_vg for missing PVs/filtered devices.
-rw-r--r--lib/metadata/metadata.c35
1 files changed, 12 insertions, 23 deletions
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 3e5bd5dcb..5c154bdf4 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -1778,31 +1778,20 @@ struct pv_list *find_pv_in_vg(const struct volume_group *vg,
const char *pv_name)
{
struct pv_list *pvl;
+ struct device *dev = dev_cache_get(pv_name, vg->cmd->filter);
- dm_list_iterate_items(pvl, &vg->pvs) {
- if (!pvl->pv->dev) {
- /*
- * pv_dev can't be NULL here!
- * We have to catch this situation earlier in the
- * code if this internal error is hit. Otherwise,
- * there's a possibility that pv_dev will match
- * cached_dev in case both are NULL.
- *
- * NULL cached_dev may happen in case this device
- * is filtered and NULL pv_dev may happen if the
- * device is missing!
- *
- * If such incorrect match was hit, simply incorrect
- * PV would be processed. This really needs to be
- * handled earlier in the code in that case.
- */
- log_error(INTERNAL_ERROR "find_pv_in_vg: PV that is not "
- "bound to any existing device found.");
- return NULL;
- }
- if (pvl->pv->dev == dev_cache_get(pv_name, vg->cmd->filter))
+ /*
+ * If the device does not exist or is filtered out, don't bother trying
+ * to find it in the list. This also prevents accidentally finding a
+ * non-NULL PV which happens to be missing (i.e. its pv->dev is NULL)
+ * for such devices.
+ */
+ if (!dev)
+ return NULL;
+
+ dm_list_iterate_items(pvl, &vg->pvs)
+ if (pvl->pv->dev == dev)
return pvl;
- }
return NULL;
}