diff --git a/lib/format1/format1.c b/lib/format1/format1.c index bd95226a1..9a583522c 100644 --- a/lib/format1/format1.c +++ b/lib/format1/format1.c @@ -12,7 +12,8 @@ #include "log.h" -static int _import_vg(struct volume_group *vg, struct list_head *pvs) +static int _import_vg(struct pool *mem, + struct volume_group *vg, struct list_head *pvs) { struct list_head *tmp; struct disk_list *dl; @@ -26,7 +27,10 @@ static int _import_vg(struct volume_group *vg, struct list_head *pvs) first = &dl->vg; memcpy(&vg->id.uuid, &first->vg_uuid, ID_LEN); - vg->name = NULL; + if (!(vg->name = pool_strdup(mem, dl->pv.vg_name))) { + stack; + return 0; + } // FIXME: encode flags //vg->status = first->vg_status; @@ -157,6 +161,7 @@ static struct logical_volume *_add_lv(struct pool *mem, } list_add(&ll->list, &vg->lvs); + vg->lv_count++; return lv; } @@ -268,7 +273,7 @@ static struct volume_group *_build_vg(struct pool *mem, struct list_head *pvs) INIT_LIST_HEAD(&vg->pvs); INIT_LIST_HEAD(&vg->lvs); - if (!_import_vg(vg, pvs)) + if (!_import_vg(mem, vg, pvs)) goto bad; if (!_import_pvs(mem, vg, pvs)) diff --git a/old-tests/format1/read_vg_t.c b/old-tests/format1/read_vg_t.c index eeeb2ed48..45eb85c9c 100644 --- a/old-tests/format1/read_vg_t.c +++ b/old-tests/format1/read_vg_t.c @@ -11,6 +11,64 @@ #include +static void _dump_pv(struct physical_volume *pv, FILE *fp) +{ + fprintf(fp, "physical_volume {\n"); + fprintf(fp, "\tname = '%s'\n", pv->dev->name); + fprintf(fp, "\tvg_name = '%s'\n", pv->vg_name); + fprintf(fp, "\tsize = %llu\n", pv->size); + fprintf(fp, "\tpe_size = %llu\n", pv->pe_size); + fprintf(fp, "\tpe_start = %llu\n", pv->pe_start); + fprintf(fp, "\tpe_count = %u\n", pv->pe_count); + fprintf(fp, "\tpe_allocated = %u\n", pv->pe_allocated); + fprintf(fp, "}\n\n"); +} + +static void _dump_lv(struct logical_volume *lv, FILE *fp) +{ + int i; + + fprintf(fp, "logical_volume {\n"); + fprintf(fp, "\tname = '%s'\n", lv->name); + fprintf(fp, "\tsize = %llu\n", lv->size); + fprintf(fp, "\tle_count = %u\n", lv->le_count); + + fprintf(fp, "\tmap {\n"); + 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, "\textent = %u\n", lv->map[i].pe); + } + fprintf(fp, "\t}\n}\n\n"); +} + +static void _dump_vg(struct volume_group *vg, FILE *fp) +{ + struct list_head *tmp; + + fprintf(fp, "volume_group {\n"); + fprintf(fp, "\tname = '%s'\n", vg->name); + fprintf(fp, "\textent_size = %llu\n", vg->extent_size); + fprintf(fp, "\textent_count = %d\n", vg->extent_count); + fprintf(fp, "\tfree_count = %d\n", vg->free_count); + fprintf(fp, "\tmax_lv = %d\n", vg->max_lv); + fprintf(fp, "\tmax_pv = %d\n", vg->max_pv); + fprintf(fp, "\tpv_count = %d\n", vg->pv_count); + fprintf(fp, "\tlv_count = %d\n", vg->lv_count); + fprintf(fp, "}\n\n"); + + list_for_each(tmp, &vg->pvs) { + struct pv_list *pvl = list_entry(tmp, struct pv_list, list); + _dump_pv(&pvl->pv, fp); + } + + list_for_each(tmp, &vg->lvs) { + struct lv_list *lvl = list_entry(tmp, struct lv_list, list); + _dump_lv(&lvl->lv, fp); + } +} + int main(int argc, char **argv) { struct io_space *ios; @@ -54,6 +112,8 @@ int main(int argc, char **argv) exit(1); } + _dump_vg(vg, stdout); + ios->destroy(ios); pool_destroy(mem);