From 7a8c751a8fa03e06bfec553da4ad61998aed3688 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Tue, 9 Oct 2001 09:22:50 +0000 Subject: [PATCH] o get_vgs works --- lib/Makefile.in | 1 - lib/format1/format1.c | 60 ++++++++++++++++++++++++++++++- old-tests/format1/Makefile.in | 9 +++-- old-tests/format1/get_vgs_t.c | 62 ++++++++++++++++++++++++++++++++ old-tests/format1/pretty_print.c | 11 ++++++ old-tests/format1/pretty_print.h | 1 + 6 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 old-tests/format1/get_vgs_t.c diff --git a/lib/Makefile.in b/lib/Makefile.in index 18cec750e..aeff92501 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -13,7 +13,6 @@ SOURCES=\ datastruct/hash.c \ device/dev-cache.c \ device/dev-io.c \ - filters/filter.c \ format1/disk-rep.c \ format1/format1.c \ log/log.c \ diff --git a/lib/format1/format1.c b/lib/format1/format1.c index 88e00620b..42f2b1734 100644 --- a/lib/format1/format1.c +++ b/lib/format1/format1.c @@ -443,6 +443,64 @@ static struct list_head *_get_pvs(struct io_space *is) return NULL; } +static int _find_vg_name(struct list_head *names, const char *vg) +{ + struct list_head *tmp; + struct name_list *nl; + + list_for_each(tmp, names) { + nl = list_entry(tmp, struct name_list, list); + if (!strcmp(nl->name, vg)) + return 1; + } + + return 0; +} + +static struct list_head *_get_vgs(struct io_space *is) +{ + struct list_head *tmp, *pvs; + struct list_head *names = pool_alloc(is->mem, sizeof(*names)); + struct name_list *nl; + + if (!names) { + stack; + return NULL; + } + + INIT_LIST_HEAD(names); + + if (!(pvs = _get_pvs(is))) { + stack; + goto bad; + } + + list_for_each(tmp, pvs) { + struct pv_list *pvl = list_entry(tmp, struct pv_list, list); + + if (_find_vg_name(names, pvl->pv.vg_name)) + continue; + + if (!(nl = pool_alloc(is->mem, sizeof(*nl)))) { + stack; + goto bad; + } + + if (!(nl->name = pool_strdup(is->mem, pvl->pv.vg_name))) { + stack; + goto bad; + } + + list_add(&nl->list, names); + } + + return names; + + bad: + pool_free(is->mem, names); + return NULL; +} + void _destroy(struct io_space *ios) { dbg_free(ios->prefix); @@ -454,7 +512,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_vgs; ios->get_pvs = _get_pvs; ios->pv_read = _pv_read; ios->pv_write = NULL; diff --git a/old-tests/format1/Makefile.in b/old-tests/format1/Makefile.in index 9461e10d5..ab5d641d7 100644 --- a/old-tests/format1/Makefile.in +++ b/old-tests/format1/Makefile.in @@ -12,12 +12,14 @@ SOURCES=\ read_vg_t.c \ pretty_print.c \ get_pvs_t.c \ - read_pv_t.c + read_pv_t.c \ + get_vgs_t.c TARGETS=\ read_vg_t \ get_pvs_t \ - read_pv_t + read_pv_t \ + get_vgs_t include ../../make.tmpl @@ -30,3 +32,6 @@ get_pvs_t: get_pvs_t.o pretty_print.o $(top_srcdir)/lib/liblvm.a 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 +get_vgs_t: get_vgs_t.o pretty_print.o $(top_srcdir)/lib/liblvm.a + $(CC) -o get_vgs_t get_vgs_t.o pretty_print.o -L$(top_srcdir)/lib -llvm + diff --git a/old-tests/format1/get_vgs_t.c b/old-tests/format1/get_vgs_t.c new file mode 100644 index 000000000..7812f21e5 --- /dev/null +++ b/old-tests/format1/get_vgs_t.c @@ -0,0 +1,62 @@ +/* + * 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 list_head *vgs; + struct pool *mem; + + 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); + } + + vgs = ios->get_vgs(ios); + + if (!vgs) { + fprintf(stderr, "couldn't read vg names\n"); + exit(1); + } + + dump_vg_names(vgs, stdout); + ios->destroy(ios); + + pool_destroy(mem); + dev_cache_exit(); + dump_memory(); + fin_log(); + return 0; +} diff --git a/old-tests/format1/pretty_print.c b/old-tests/format1/pretty_print.c index c23eddfe9..7fb6946d4 100644 --- a/old-tests/format1/pretty_print.c +++ b/old-tests/format1/pretty_print.c @@ -64,3 +64,14 @@ void dump_vg(struct volume_group *vg, FILE *fp) dump_lv(&lvl->lv, fp); } } + +void dump_vg_names(struct list_head *vg_names, FILE *fp) +{ + struct list_head *tmp; + struct name_list *nl; + + list_for_each(tmp, vg_names) { + nl = list_entry(tmp, struct name_list, list); + fprintf(fp, "%s\n", nl->name); + } +} diff --git a/old-tests/format1/pretty_print.h b/old-tests/format1/pretty_print.h index d20607c2f..f887875d9 100644 --- a/old-tests/format1/pretty_print.h +++ b/old-tests/format1/pretty_print.h @@ -14,5 +14,6 @@ void dump_pv(struct physical_volume *pv, FILE *fp); void dump_lv(struct logical_volume *lv, FILE *fp); void dump_vg(struct volume_group *vg, FILE *fp); +void dump_vg_names(struct list_head *vg_names, FILE *fp); #endif -- 2.43.5