summaryrefslogtreecommitdiffstats
path: root/lib/format1
diff options
context:
space:
mode:
Diffstat (limited to 'lib/format1')
-rw-r--r--lib/format1/disk-rep.c70
-rw-r--r--lib/format1/format1.c6
-rw-r--r--lib/format1/lvm1-label.c9
3 files changed, 53 insertions, 32 deletions
diff --git a/lib/format1/disk-rep.c b/lib/format1/disk-rep.c
index c3aeac65..d7c3f7d7 100644
--- a/lib/format1/disk-rep.c
+++ b/lib/format1/disk-rep.c
@@ -335,9 +335,9 @@ static void __update_lvmcache(const struct format_type *fmt,
return;
}
- info->device_size = xlate32(dl->pvd.pv_size) << SECTOR_SHIFT;
- dm_list_init(&info->mdas);
- info->status &= ~CACHE_INVALID;
+ lvmcache_set_device_size(info, xlate32(dl->pvd.pv_size) << SECTOR_SHIFT);
+ lvmcache_del_mdas(info);
+ lvmcache_make_valid(info);
}
static struct disk_list *__read_disk(const struct format_type *fmt,
@@ -451,6 +451,28 @@ static void _add_pv_to_list(struct dm_list *head, struct disk_list *data)
dm_list_add(head, &data->list);
}
+struct _read_pvs_in_vg_baton {
+ const char *vg_name;
+ struct dm_list *head;
+ struct disk_list *data;
+ struct dm_pool *mem;
+ int empty;
+};
+
+static int _read_pv_in_vg(struct lvmcache_info *info, void *baton)
+{
+ struct _read_pvs_in_vg_baton *b = baton;
+
+ b->empty = 0;
+
+ if (!lvmcache_device(info) ||
+ !(b->data = read_disk(lvmcache_fmt(info), lvmcache_device(info), b->mem, b->vg_name)))
+ return 0; /* stop here */
+
+ _add_pv_to_list(b->head, b->data);
+ return 1;
+}
+
/*
* Build a list of pv_d's structures, allocated from mem.
* We keep track of the first object allocated from the pool
@@ -462,29 +484,31 @@ int read_pvs_in_vg(const struct format_type *fmt, const char *vg_name,
{
struct dev_iter *iter;
struct device *dev;
- struct disk_list *data = NULL;
struct lvmcache_vginfo *vginfo;
- struct lvmcache_info *info;
+ struct _read_pvs_in_vg_baton baton;
+
+ baton.head = head;
+ baton.empty = 1;
+ baton.data = NULL;
+ baton.mem = mem;
+ baton.vg_name = vg_name;
/* Fast path if we already saw this VG and cached the list of PVs */
- if (vg_name && (vginfo = vginfo_from_vgname(vg_name, NULL)) &&
- vginfo->infos.n) {
- dm_list_iterate_items(info, &vginfo->infos) {
- dev = info->dev;
- if (!dev || !(data = read_disk(fmt, dev, mem, vg_name)))
- break;
- _add_pv_to_list(head, data);
- }
+ if (vg_name && (vginfo = lvmcache_vginfo_from_vgname(vg_name, NULL))) {
+
+ lvmcache_foreach_pv(vginfo, _read_pv_in_vg, &baton);
- /* Did we find the whole VG? */
- if (!vg_name || is_orphan_vg(vg_name) ||
- (data && *data->pvd.vg_name &&
- dm_list_size(head) == data->vgd.pv_cur))
- return 1;
+ if (!baton.empty) {
+ /* Did we find the whole VG? */
+ if (!vg_name || is_orphan_vg(vg_name) ||
+ (baton.data && *baton.data->pvd.vg_name &&
+ dm_list_size(head) == baton.data->vgd.pv_cur))
+ return 1;
- /* Failed */
- dm_list_init(head);
- /* vgcache_del(vg_name); */
+ /* Failed */
+ dm_list_init(head);
+ /* vgcache_del(vg_name); */
+ }
}
if (!(iter = dev_iter_create(filter, 1))) {
@@ -494,8 +518,8 @@ int read_pvs_in_vg(const struct format_type *fmt, const char *vg_name,
/* Otherwise do a complete scan */
for (dev = dev_iter_get(iter); dev; dev = dev_iter_get(iter)) {
- if ((data = read_disk(fmt, dev, mem, vg_name))) {
- _add_pv_to_list(head, data);
+ if ((baton.data = read_disk(fmt, dev, mem, vg_name))) {
+ _add_pv_to_list(head, baton.data);
}
}
dev_iter_destroy(iter);
diff --git a/lib/format1/format1.c b/lib/format1/format1.c
index 629bb839..6b5bdb95 100644
--- a/lib/format1/format1.c
+++ b/lib/format1/format1.c
@@ -413,10 +413,8 @@ static int _format1_pv_write(const struct format_type *fmt, struct physical_volu
pv->vg_name, NULL, 0)))
return_0;
- info->device_size = pv->size << SECTOR_SHIFT;
- info->fmt = fmt;
-
- dm_list_init(&info->mdas);
+ lvmcache_update_pv(info, pv, fmt);
+ lvmcache_del_mdas(info);
dm_list_init(&pvs);
diff --git a/lib/format1/lvm1-label.c b/lib/format1/lvm1-label.c
index 07596a54..4c157ac5 100644
--- a/lib/format1/lvm1-label.c
+++ b/lib/format1/lvm1-label.c
@@ -77,12 +77,11 @@ static int _lvm1_read(struct labeller *l, struct device *dev, void *buf,
if (!(info = lvmcache_add(l, (char *)pvd->pv_uuid, dev, vgname, vgid,
exported)))
return_0;
- *label = info->label;
+ *label = lvmcache_get_label(info);
- info->device_size = xlate32(pvd->pv_size) << SECTOR_SHIFT;
- dm_list_init(&info->mdas);
-
- info->status &= ~CACHE_INVALID;
+ lvmcache_set_device_size(info, xlate32(pvd->pv_size) << SECTOR_SHIFT);
+ lvmcache_del_mdas(info);
+ lvmcache_make_valid(info);
return 1;
}