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

o pv_Read works

This commit is contained in:
Joe Thornber 2001-10-09 08:58:52 +00:00
parent 4c9c080e07
commit 47bd29840d
5 changed files with 143 additions and 23 deletions

View File

@ -2,7 +2,6 @@
* Copyright (C) 2001 Sistina Software (UK) Limited.
*
* This file is released under the GPL.
*
*/
#include "disk-rep.h"

View File

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

View File

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

View File

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

View File

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