239
static int _read_vg_pds(const struct format_type *fmt, struct dm_pool *mem,
240
struct lvmcache_vginfo *vginfo, struct dm_list *head,
238
struct _read_pool_pv_baton {
239
const struct format_type *fmt;
240
struct dm_pool *mem, *tmpmem;
241
struct pool_list *pl;
242
struct dm_list *head;
250
static int _read_pool_pv(struct lvmcache_info *info, void *baton)
252
struct _read_pool_pv_baton *b = baton;
256
if (lvmcache_device(info) &&
257
!(b->pl = read_pool_disk(b->fmt, lvmcache_device(info), b->mem, b->vgname)))
261
* We need to keep track of the total expected number
262
* of devices per subpool
265
/* FIXME pl left uninitialised if !info->dev */
267
log_error(INTERNAL_ERROR "device is missing");
268
dm_pool_destroy(b->tmpmem);
272
b->sp_count = b->pl->pd.pl_subpools;
274
dm_pool_zalloc(b->tmpmem,
275
sizeof(uint32_t) * b->sp_count))) {
276
log_error("Unable to allocate %d 32-bit uints",
278
dm_pool_destroy(b->tmpmem);
285
* watch out for a pool label with a different subpool
286
* count than the original - give up if it does
288
if (b->sp_count != b->pl->pd.pl_subpools)
291
_add_pl_to_list(b->head, b->pl);
293
if (b->sp_count > b->pl->pd.pl_sp_id && b->sp_devs[b->pl->pd.pl_sp_id] == 0)
294
b->sp_devs[b->pl->pd.pl_sp_id] = b->pl->pd.pl_sp_devs;
299
static int _read_vg_pds(struct _read_pool_pv_baton *b,
300
struct lvmcache_vginfo *vginfo,
241
301
uint32_t *devcount)
243
struct lvmcache_info *info;
244
struct pool_list *pl = NULL;
245
struct dm_pool *tmpmem;
247
uint32_t sp_count = 0;
248
uint32_t *sp_devs = NULL;
251
310
/* FIXME: maybe should return a different error in memory
252
311
* allocation failure */
253
if (!(tmpmem = dm_pool_create("pool read_vg", 512)))
312
if (!(b->tmpmem = dm_pool_create("pool read_vg", 512)))
256
dm_list_iterate_items(info, &vginfo->infos) {
258
!(pl = read_pool_disk(fmt, info->dev, mem, vginfo->vgname)))
261
* We need to keep track of the total expected number
262
* of devices per subpool
265
/* FIXME pl left uninitialised if !info->dev */
267
log_error(INTERNAL_ERROR "device is missing");
268
dm_pool_destroy(tmpmem);
271
sp_count = pl->pd.pl_subpools;
273
dm_pool_zalloc(tmpmem,
274
sizeof(uint32_t) * sp_count))) {
275
log_error("Unable to allocate %d 32-bit uints",
277
dm_pool_destroy(tmpmem);
282
* watch out for a pool label with a different subpool
283
* count than the original - give up if it does
285
if (sp_count != pl->pd.pl_subpools)
288
_add_pl_to_list(head, pl);
290
if (sp_count > pl->pd.pl_sp_id && sp_devs[pl->pd.pl_sp_id] == 0)
291
sp_devs[pl->pd.pl_sp_id] = pl->pd.pl_sp_devs;
315
lvmcache_foreach_pv(vginfo, _read_pool_pv, b);
295
for (i = 0; i < sp_count; i++)
296
*devcount += sp_devs[i];
298
dm_pool_destroy(tmpmem);
300
if (pl && *pl->pd.pl_pool_name)
318
for (i = 0; i < b->sp_count; i++)
319
*devcount += b->sp_devs[i];
321
dm_pool_destroy(b->tmpmem);
323
if (b->pl && *b->pl->pd.pl_pool_name)
311
334
uint32_t totaldevs;
312
335
int full_scan = -1;
337
struct _read_pool_pv_baton baton;
339
baton.vgname = vg_name;
316
347
* If the cache scanning doesn't work, this will never work
318
if (vg_name && (vginfo = vginfo_from_vgname(vg_name, NULL)) &&
321
if (_read_vg_pds(fmt, mem, vginfo, pdhead, &totaldevs)) {
323
* If we found all the devices we were
324
* expecting, return success
326
if (dm_list_size(pdhead) == totaldevs)
330
* accept partial pool if we've done a full
331
* rescan of the cache
349
if (vg_name && (vginfo = lvmcache_vginfo_from_vgname(vg_name, NULL)) &&
350
_read_vg_pds(&baton, vginfo, &totaldevs) && !baton.empty)
353
* If we found all the devices we were expecting, return
356
if (dm_list_size(pdhead) == totaldevs)
360
* accept partial pool if we've done a full rescan of
338
368
dm_list_init(pdhead);