From 721128e86d8a5e36ff62aececf01ec8a91d5e434 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Mon, 8 Oct 2001 12:11:33 +0000 Subject: [PATCH] o sync --- lib/device/dev-cache.c | 6 ++++++ lib/format1/format1.c | 37 +++++++++++++++++++++++++++++++---- lib/format1/format1.h | 3 ++- lib/metadata/metadata.h | 1 - old-tests/format1/Makefile.in | 2 +- old-tests/format1/read_vg_t.c | 15 +++++++++++++- 6 files changed, 56 insertions(+), 8 deletions(-) diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c index fecc54a15..0e73bceea 100644 --- a/lib/device/dev-cache.c +++ b/lib/device/dev-cache.c @@ -194,6 +194,8 @@ int dev_cache_init(void) return 0; } + INIT_LIST_HEAD(&_cache.dirs); + return 1; } @@ -227,6 +229,10 @@ struct device *_insert_new(const char *name) struct device *dev_cache_get(const char *name, struct dev_filter *f) { struct device *d = (struct device *) hash_lookup(_cache.devices, name); + + if (!d && (d = _create_dev(name))) + hash_insert(_cache.devices, name, d); + return (d && (!f || f->passes_filter(f, d))) ? d : NULL; } diff --git a/lib/format1/format1.c b/lib/format1/format1.c index 477b5cdca..dc6c6b41b 100644 --- a/lib/format1/format1.c +++ b/lib/format1/format1.c @@ -107,7 +107,7 @@ static struct logical_volume *_find_lv(struct volume_group *vg, return NULL; } -static struct physical_volume *_find_pv(struct volume_group *vg, +static struct physical_volume *_find_pv(struct volume_group *vg, struct device *dev) { struct list_head *tmp; @@ -307,7 +307,7 @@ static struct volume_group *_vg_read(struct io_space *is, const char *vg_name) static struct disk_list *_flatten_pv(struct pool *mem, struct volume_group *vg, struct physical_volume *pv) { - + } static int _flatten_vg(struct pool *mem, struct volume_group *vg, @@ -347,9 +347,38 @@ static int _vg_write(struct io_space *is, struct volume_group *vg) } #endif -struct io_space *create_lvm1_format(void) +void _destroy(struct io_space *ios) { - return NULL; + dbg_free(ios->prefix); + dbg_free(ios); +} + +struct io_space *create_lvm1_format(const char *prefix, struct pool *mem, + struct dev_filter *filter) +{ + struct io_space *ios = dbg_malloc(sizeof(*ios)); + + ios->get_vgs = NULL; + ios->get_pvs = NULL; + ios->pv_read = NULL; + ios->pv_write = NULL; + ios->vg_read = _vg_read; + ios->vg_write = NULL; + ios->destroy = _destroy; + + ios->prefix = dbg_malloc(strlen(prefix) + 1); + if (!ios->prefix) { + stack; + dbg_free(ios); + return 0; + } + strcpy(ios->prefix, prefix); + + ios->mem = mem; + ios->filter = filter; + ios->private = NULL; + + return ios; } diff --git a/lib/format1/format1.h b/lib/format1/format1.h index 78ade8d44..cac9f68ea 100644 --- a/lib/format1/format1.h +++ b/lib/format1/format1.h @@ -9,6 +9,7 @@ #include "metadata.h" -struct io_space *create_lvm1_format(struct dev_filter *filter); +struct io_space *create_lvm1_format(const char *prefix, struct pool *mem, + struct dev_filter *filter); #endif diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index 91f9212f4..412e1c477 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -162,7 +162,6 @@ struct io_space { /* Current volume group prefix. */ /* Default to "/dev/" */ char *prefix; - struct pool *mem; struct dev_filter *filter; void *private; diff --git a/old-tests/format1/Makefile.in b/old-tests/format1/Makefile.in index 1f80e9eb5..57fb29817 100644 --- a/old-tests/format1/Makefile.in +++ b/old-tests/format1/Makefile.in @@ -15,6 +15,6 @@ TARGETS=read_vg_t include ../../make.tmpl -read_vg_t: read_vg_t.o +read_vg_t: read_vg_t.o $(top_srcdir)/lib/liblvm.a $(CC) -o read_vg_t read_vg_t.o -L$(top_srcdir)/lib -llvm diff --git a/old-tests/format1/read_vg_t.c b/old-tests/format1/read_vg_t.c index 4290df859..3ff667894 100644 --- a/old-tests/format1/read_vg_t.c +++ b/old-tests/format1/read_vg_t.c @@ -7,6 +7,7 @@ #include "log.h" #include "format1.h" #include "dbg_malloc.h" +#include "pool.h" #include @@ -14,6 +15,7 @@ int main(int argc, char **argv) { struct io_space *ios; struct volume_group *vg; + struct pool *mem; if (argc != 2) { fprintf(stderr, "usage: read_vg_t \n"); @@ -33,7 +35,18 @@ int main(int argc, char **argv) exit(1); } - ios = create_lvm1_format(NULL); + 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); + } + vg = ios->vg_read(ios, argv[1]); if (!vg) {