From c8ca2a299362495b95511b9e0b1ded179df2fa78 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Mon, 8 Oct 2001 17:53:43 +0000 Subject: [PATCH] o get_pvs for format 1 o fix vg_read if vg doesn't exist --- lib/format1/format1.c | 54 +++++++++++++++++++++++++++++------ lib/metadata/metadata.h | 6 ++-- old-tests/format1/read_vg_t.c | 3 +- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/lib/format1/format1.c b/lib/format1/format1.c index 9a583522c..b19d38244 100644 --- a/lib/format1/format1.c +++ b/lib/format1/format1.c @@ -47,18 +47,18 @@ static int _import_vg(struct pool *mem, } } - return 1; + return first ? 1 : 0; } -static int _import_pvs(struct pool *mem, struct volume_group *vg, - struct list_head *pvs) +static int _import_pvs(struct pool *mem, struct list_head *pvs, + struct list_head *results, int *count) { struct list_head *tmp; struct disk_list *dl; struct pv_list *pvl; struct physical_volume *pv; - vg->pv_count = 0; + *count = 0; list_for_each(tmp, pvs) { dl = list_entry(tmp, struct disk_list, list); pvl = pool_alloc(mem, sizeof(*pvl)); @@ -89,8 +89,8 @@ static int _import_pvs(struct pool *mem, struct volume_group *vg, pv->pe_count = dl->pv.pe_total; pv->pe_allocated = dl->pv.pe_allocated; - list_add(&pvl->list, &vg->pvs); - vg->pv_count++; + list_add(&pvl->list, results); + (*count)++; } return 1; @@ -276,7 +276,7 @@ static struct volume_group *_build_vg(struct pool *mem, struct list_head *pvs) if (!_import_vg(mem, vg, pvs)) goto bad; - if (!_import_pvs(mem, vg, pvs)) + if (!_import_pvs(mem, pvs, &vg->pvs, &vg->pv_count)) goto bad; if (!_import_lvs(mem, vg, pvs)) @@ -362,6 +362,44 @@ static int _vg_write(struct io_space *is, struct volume_group *vg) } #endif +static struct list_head *_get_pvs(struct io_space *is) +{ + struct pool *mem = pool_create(1024 * 10); + struct list_head pvs, *results; + uint32_t count; + + if (!mem) { + stack; + return NULL; + } + + if (!(results = pool_alloc(is->mem, sizeof(*results)))) { + stack; + return NULL; + } + + INIT_LIST_HEAD(&pvs); + INIT_LIST_HEAD(results); + + if (!read_pvs_in_vg(NULL, is->filter, mem, &pvs)) { + stack; + goto bad; + } + + if (!_import_pvs(mem, &pvs, results, &count)) { + stack; + goto bad; + } + + pool_destroy(mem); + return results; + + bad: + pool_destroy(mem); + pool_free(mem, results); + return NULL; +} + void _destroy(struct io_space *ios) { dbg_free(ios->prefix); @@ -373,7 +411,7 @@ struct io_space *create_lvm1_format(const char *prefix, struct pool *mem, { struct io_space *ios = dbg_malloc(sizeof(*ios)); - ios->get_vgs = NULL; + ios->get_vgs = _get_pvs; ios->get_pvs = NULL; ios->pv_read = NULL; ios->pv_write = NULL; diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index a5c055b60..d8b532d2c 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -124,11 +124,11 @@ struct lv_list { struct io_space { /* Returns list of names of all vgs - vg component only, not full path*/ - struct name_list *(*get_vgs)(struct io_space *is); + struct list_head *(*get_vgs)(struct io_space *is); - /* Returns list of fully-populated pv + /* Returns list of fully-populated pv_list structures */ - struct pv_list *(*get_pvs)(struct io_space *is); + struct list_head *(*get_pvs)(struct io_space *is); /* Return PV with given name (may be full or relative path) */ diff --git a/old-tests/format1/read_vg_t.c b/old-tests/format1/read_vg_t.c index 45eb85c9c..80d548343 100644 --- a/old-tests/format1/read_vg_t.c +++ b/old-tests/format1/read_vg_t.c @@ -37,7 +37,8 @@ static void _dump_lv(struct logical_volume *lv, FILE *fp) for (i = 0; i < lv->le_count; i++) { struct physical_volume *pv = lv->map[i].pv; - fprintf(fp, "\t\tpv = '%s', ", pv ? pv->dev->name : "null ???"); + fprintf(fp, "\t\tpv = '%s', ", + pv ? pv->dev->name : "null ???"); fprintf(fp, "\textent = %u\n", lv->map[i].pe); } fprintf(fp, "\t}\n}\n\n");