1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

o get_vgs works

This commit is contained in:
Joe Thornber 2001-10-09 09:22:50 +00:00
parent 47bd29840d
commit 7a8c751a8f
6 changed files with 140 additions and 4 deletions

View File

@ -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 \

View File

@ -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;

View File

@ -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

View File

@ -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 <stdio.h>
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;
}

View File

@ -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);
}
}

View File

@ -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