From 47bd29840ddc6c0a8753fd96a73ccd7da4ae7b5d Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Tue, 9 Oct 2001 08:58:52 +0000 Subject: [PATCH] o pv_Read works --- lib/format1/disk-rep.c | 1 - lib/format1/format1.c | 81 +++++++++++++++++++++++++++-------- lib/metadata/metadata.h | 2 +- old-tests/format1/Makefile.in | 9 +++- old-tests/format1/read_pv_t.c | 73 +++++++++++++++++++++++++++++++ 5 files changed, 143 insertions(+), 23 deletions(-) create mode 100644 old-tests/format1/read_pv_t.c diff --git a/lib/format1/disk-rep.c b/lib/format1/disk-rep.c index b57971dbe..173c16e70 100644 --- a/lib/format1/disk-rep.c +++ b/lib/format1/disk-rep.c @@ -2,7 +2,6 @@ * Copyright (C) 2001 Sistina Software (UK) Limited. * * This file is released under the GPL. - * */ #include "disk-rep.h" diff --git a/lib/format1/format1.c b/lib/format1/format1.c index 096c4e8a8..88e00620b 100644 --- a/lib/format1/format1.c +++ b/lib/format1/format1.c @@ -50,45 +50,53 @@ static int _import_vg(struct pool *mem, return first ? 1 : 0; } +static int _import_pv(struct pool *mem, + struct disk_list *dl, struct physical_volume *pv) +{ + memset(pv, 0, sizeof(*pv)); + memcpy(&pv->id, &dl->pv.pv_uuid, ID_LEN); + + pv->dev = dl->dev; + pv->vg_name = pool_strdup(mem, dl->pv.vg_name); + + if (!pv->vg_name) { + stack; + return 0; + } + + // FIXME: finish + //pv->exported = ??; + pv->status = dl->pv.pv_status; + pv->size = dl->pv.pv_size; + pv->pe_size = dl->pv.pv_size; + pv->pe_start = dl->pv.pe_start; + pv->pe_count = dl->pv.pe_total; + pv->pe_allocated = dl->pv.pe_allocated; + return 1; +} + 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; *count = 0; list_for_each(tmp, pvs) { dl = list_entry(tmp, struct disk_list, list); pvl = pool_alloc(mem, sizeof(*pvl)); - memset(pvl, 0, sizeof(*pvl)); if (!pvl) { stack; return 0; } - pv = &pvl->pv; - memcpy(&pv->id, &dl->pv.pv_uuid, ID_LEN); - - pv->dev = dl->dev; - pv->vg_name = pool_strdup(mem, dl->pv.vg_name); - - if (!pv->vg_name) { + if (!_import_pv(mem, dl, &pvl->pv)) { stack; return 0; } - // FIXME: finish - //pv->exported = ??; - pv->status = dl->pv.pv_status; - pv->size = dl->pv.pv_size; - pv->pe_size = dl->pv.pv_size; - pv->pe_start = dl->pv.pe_start; - pv->pe_count = dl->pv.pe_total; - pv->pe_allocated = dl->pv.pe_allocated; - list_add(&pvl->list, results); (*count)++; } @@ -362,6 +370,41 @@ static int _vg_write(struct io_space *is, struct volume_group *vg) } #endif +static struct physical_volume *_pv_read(struct io_space *is, + struct device *dev) +{ + struct pool *mem = pool_create(1024); + struct physical_volume *pv; + struct disk_list *dl; + + if (!mem) { + stack; + return NULL; + } + + if (!(dl = read_pv(dev, mem, NULL))) { + stack; + goto bad; + } + + if (!(pv = pool_alloc(is->mem, sizeof(*pv)))) { + stack; + goto bad; + } + + if (!_import_pv(is->mem, dl, pv)) { + stack; + goto bad; + } + + pool_destroy(mem); + return pv; + + bad: + pool_destroy(mem); + return NULL; +} + static struct list_head *_get_pvs(struct io_space *is) { struct pool *mem = pool_create(1024 * 10); @@ -413,7 +456,7 @@ struct io_space *create_lvm1_format(const char *prefix, struct pool *mem, ios->get_vgs = NULL; ios->get_pvs = _get_pvs; - ios->pv_read = NULL; + ios->pv_read = _pv_read; ios->pv_write = NULL; ios->vg_read = _vg_read; ios->vg_write = NULL; diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index d8b532d2c..8dc04d481 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -133,7 +133,7 @@ struct io_space { /* Return PV with given name (may be full or relative path) */ struct physical_volume *(*pv_read)(struct io_space *is, - const char *pv_name); + struct device *dev); /* Write a PV structure to disk. */ /* Fails if the PV is in a VG ie diff --git a/old-tests/format1/Makefile.in b/old-tests/format1/Makefile.in index 978f07153..9461e10d5 100644 --- a/old-tests/format1/Makefile.in +++ b/old-tests/format1/Makefile.in @@ -11,11 +11,13 @@ VPATH = @srcdir@ SOURCES=\ read_vg_t.c \ pretty_print.c \ - get_pvs_t.c + get_pvs_t.c \ + read_pv_t.c TARGETS=\ read_vg_t \ - get_pvs_t + get_pvs_t \ + read_pv_t include ../../make.tmpl @@ -25,3 +27,6 @@ read_vg_t: read_vg_t.o pretty_print.o $(top_srcdir)/lib/liblvm.a get_pvs_t: get_pvs_t.o pretty_print.o $(top_srcdir)/lib/liblvm.a $(CC) -o get_pvs_t get_pvs_t.o pretty_print.o -L$(top_srcdir)/lib -llvm +read_pv_t: read_pv_t.o pretty_print.o $(top_srcdir)/lib/liblvm.a + $(CC) -o read_pv_t read_pv_t.o pretty_print.o -L$(top_srcdir)/lib -llvm + diff --git a/old-tests/format1/read_pv_t.c b/old-tests/format1/read_pv_t.c new file mode 100644 index 000000000..991d3835c --- /dev/null +++ b/old-tests/format1/read_pv_t.c @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2001 Sistina Software (UK) Limited. + * + * This file is released under the GPL. + */ + +#include "log.h" +#include "format1.h" +#include "dbg_malloc.h" +#include "pool.h" +#include "pretty_print.h" +#include "list.h" + +#include + +int main(int argc, char **argv) +{ + struct io_space *ios; + struct physical_volume *pv; + struct pool *mem; + struct device *dev; + + if (argc != 2) { + fprintf(stderr, "usage: read_pv_t \n"); + exit(1); + } + + init_log(stderr); + init_debug(_LOG_INFO); + + if (!dev_cache_init()) { + fprintf(stderr, "init of dev-cache failed\n"); + exit(1); + } + + if (!dev_cache_add_dir("/dev/loop")) { + fprintf(stderr, "couldn't add /dev to dir-cache\n"); + exit(1); + } + + if (!(mem = pool_create(10 * 1024))) { + fprintf(stderr, "couldn't create pool\n"); + exit(1); + } + + ios = create_lvm1_format("/dev", mem, NULL); + + if (!ios) { + fprintf(stderr, "failed to create io_space for format1\n"); + exit(1); + } + + if (!(dev = dev_cache_get(argv[1], NULL))) { + fprintf(stderr, "couldn't get device %s\n", argv[1]); + exit(1); + } + + pv = ios->pv_read(ios, dev); + + if (!pv) { + fprintf(stderr, "couldn't read pv %s\n", dev->name); + exit(1); + } + + dump_pv(pv, stdout); + ios->destroy(ios); + + pool_destroy(mem); + dev_cache_exit(); + dump_memory(); + fin_log(); + return 0; +} -- 2.43.5