mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
o pe_start wasn't being set properly when exporting to disk
o added a check for lv's with null lv_name o setup pv->lv_cur correctly o test program for vg_write
This commit is contained in:
parent
161720b500
commit
491ae26f6c
@ -102,8 +102,8 @@ static int _munge_formats(struct pv_disk *pvd)
|
||||
|
||||
switch (pvd->version) {
|
||||
case 1:
|
||||
pe_start = (pvd->pe_on_disk.base + pvd->pe_on_disk.size) /
|
||||
SECTOR_SIZE;
|
||||
pvd->pe_start = ((pvd->pe_on_disk.base +
|
||||
pvd->pe_on_disk.size) / SECTOR_SIZE);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
@ -179,6 +179,17 @@ static int _read_uuids(struct disk_list *data)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _check_lv(struct lv_disk *lvd)
|
||||
{
|
||||
/* FIXME: add more checks */
|
||||
if (lvd->lv_name[0] == '\0') {
|
||||
log_debug("lv has no name");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _read_lvs(struct disk_list *data)
|
||||
{
|
||||
int i;
|
||||
@ -195,6 +206,9 @@ static int _read_lvs(struct disk_list *data)
|
||||
if (!_read_lv(data->dev, pos, &ll->lv))
|
||||
fail;
|
||||
|
||||
if (!_check_lv(&ll->lv))
|
||||
fail;
|
||||
|
||||
list_add(&ll->list, &data->lvs);
|
||||
}
|
||||
|
||||
@ -240,7 +254,7 @@ struct disk_list *read_pv(struct device *dev, struct pool *mem,
|
||||
}
|
||||
|
||||
if (!_munge_formats(&data->pv)) {
|
||||
log_very_verbose("Unknown metadata version %d found on %s",
|
||||
log_very_verbose("Unknown metadata version %d found on %s",
|
||||
data->pv.version, dev->name);
|
||||
goto bad;
|
||||
}
|
||||
@ -380,9 +394,10 @@ static int _write_extents(struct disk_list *data)
|
||||
{
|
||||
size_t len = sizeof(struct pe_disk) * data->pv.pe_total;
|
||||
struct pe_disk *extents = data->extents;
|
||||
unsigned long pos = data->pv.pe_on_disk.base;
|
||||
|
||||
_xlate_extents(extents, data->pv.pe_total);
|
||||
if (dev_write(data->dev, 0, len, extents) != len)
|
||||
if (dev_write(data->dev, pos, len, extents) != len)
|
||||
fail;
|
||||
|
||||
_xlate_extents(extents, data->pv.pe_total);
|
||||
|
@ -22,7 +22,13 @@ static int _check_vg_name(const char *name)
|
||||
*/
|
||||
static char *_create_lv_name(struct pool *mem, const char *full_name)
|
||||
{
|
||||
const char *ptr = strrchr(full_name, '/') + 1;
|
||||
const char *ptr = strrchr(full_name, '/');
|
||||
|
||||
if (!ptr)
|
||||
ptr = full_name;
|
||||
else
|
||||
ptr++;
|
||||
|
||||
return pool_strdup(mem, ptr);
|
||||
}
|
||||
|
||||
@ -87,7 +93,7 @@ int import_pv(struct pool *mem, struct device *dev,
|
||||
struct physical_volume *pv, struct pv_disk *pvd)
|
||||
{
|
||||
memset(pv, 0, sizeof(*pv));
|
||||
memcpy(&pv->id, &pvd->pv_uuid, ID_LEN);
|
||||
memcpy(&pv->id, pvd->pv_uuid, ID_LEN);
|
||||
|
||||
pv->dev = dev;
|
||||
if (!(pv->vg_name = pool_strdup(mem, pvd->vg_name))) {
|
||||
@ -117,7 +123,7 @@ int export_pv(struct pv_disk *pvd, struct physical_volume *pv)
|
||||
pvd->id[1] = 'M';
|
||||
pvd->version = 1;
|
||||
|
||||
memcpy(&pvd->pv_uuid, &pv->id.uuid, ID_LEN);
|
||||
memcpy(pvd->pv_uuid, pv->id.uuid, ID_LEN);
|
||||
|
||||
if (!_check_vg_name(pv->vg_name)) {
|
||||
stack;
|
||||
@ -151,7 +157,7 @@ int import_vg(struct pool *mem,
|
||||
struct volume_group *vg, struct disk_list *dl)
|
||||
{
|
||||
struct vg_disk *vgd = &dl->vg;
|
||||
memcpy(&vg->id.uuid, &vgd->vg_uuid, ID_LEN);
|
||||
memcpy(vg->id.uuid, vgd->vg_uuid, ID_LEN);
|
||||
|
||||
if (!_check_vg_name(dl->pv.vg_name)) {
|
||||
stack;
|
||||
@ -195,7 +201,7 @@ int import_vg(struct pool *mem,
|
||||
int export_vg(struct vg_disk *vgd, struct volume_group *vg)
|
||||
{
|
||||
memset(vgd, 0, sizeof(*vgd));
|
||||
memcpy(&vgd->vg_uuid, &vg->id.uuid, ID_LEN);
|
||||
memcpy(vgd->vg_uuid, vg->id.uuid, ID_LEN);
|
||||
//vgd->vg_number = ??;
|
||||
|
||||
if (vg->status &= LVM_READ)
|
||||
@ -236,7 +242,7 @@ int export_vg(struct vg_disk *vgd, struct volume_group *vg)
|
||||
int import_lv(struct pool *mem, struct logical_volume *lv, struct lv_disk *lvd)
|
||||
{
|
||||
int len;
|
||||
memset(&lv->id.uuid, 0, sizeof(lv->id));
|
||||
memset(&lv->id, 0, sizeof(lv->id));
|
||||
if (!(lv->name = _create_lv_name(mem, lvd->lv_name))) {
|
||||
stack;
|
||||
return 0;
|
||||
@ -478,10 +484,10 @@ int export_lvs(struct disk_list *dl, struct volume_group *vg,
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
memset(&dl->extents, 0, len);
|
||||
memset(dl->extents, 0, len);
|
||||
|
||||
|
||||
list_for_each(tmp, &dl->lvs) {
|
||||
list_for_each(tmp, &vg->lvs) {
|
||||
ll = list_entry(tmp, struct lv_list, list);
|
||||
if (!(lvdl = pool_alloc(dl->mem, sizeof(*lvdl)))) {
|
||||
stack;
|
||||
@ -495,6 +501,7 @@ int export_lvs(struct disk_list *dl, struct volume_group *vg,
|
||||
}
|
||||
|
||||
list_add(&lvdl->list, &dl->lvs);
|
||||
dl->pv.lv_cur++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -512,8 +519,8 @@ int export_uuids(struct disk_list *dl, struct volume_group *vg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(&ul->uuid, 0, sizeof(ul->uuid));
|
||||
memcpy(&ul->uuid, &pvl->pv.id.uuid, ID_LEN);
|
||||
memset(ul->uuid, 0, sizeof(ul->uuid));
|
||||
memcpy(ul->uuid, pvl->pv.id.uuid, ID_LEN);
|
||||
|
||||
list_add(&ul->list, &dl->uuids);
|
||||
}
|
||||
|
@ -55,10 +55,10 @@ static void _calc_simple_layout(struct pv_disk *pvd)
|
||||
pvd->vg_on_disk.size = VG_SIZE;
|
||||
|
||||
pvd->pv_uuidlist_on_disk.base = _next_base(&pvd->vg_on_disk);
|
||||
pvd->pv_uuidlist_on_disk.size = (MAX_PV + 1) * NAME_LEN;
|
||||
pvd->pv_uuidlist_on_disk.size = MAX_PV * NAME_LEN;
|
||||
|
||||
pvd->lv_on_disk.base = _next_base(&pvd->pv_uuidlist_on_disk);
|
||||
pvd->lv_on_disk.size = (MAX_LV + 1) * sizeof(struct lv_disk);
|
||||
pvd->lv_on_disk.size = MAX_LV * sizeof(struct lv_disk);
|
||||
|
||||
pvd->pe_on_disk.base = _next_base(&pvd->lv_on_disk);
|
||||
pvd->pe_on_disk.size = pvd->pe_total * sizeof(struct pe_disk);
|
||||
|
@ -10,6 +10,7 @@ VPATH = @srcdir@
|
||||
|
||||
SOURCES=\
|
||||
read_vg_t.c \
|
||||
write_vg_t.c \
|
||||
pretty_print.c \
|
||||
get_pvs_t.c \
|
||||
read_pv_t.c \
|
||||
@ -17,6 +18,7 @@ SOURCES=\
|
||||
|
||||
TARGETS=\
|
||||
read_vg_t \
|
||||
write_vg_t \
|
||||
get_pvs_t \
|
||||
read_pv_t \
|
||||
get_vgs_t
|
||||
@ -26,6 +28,10 @@ include ../../make.tmpl
|
||||
read_vg_t: read_vg_t.o pretty_print.o $(top_srcdir)/lib/liblvm.a
|
||||
$(CC) -o read_vg_t read_vg_t.o pretty_print.o -L$(top_srcdir)/lib -llvm
|
||||
|
||||
write_vg_t: write_vg_t.o pretty_print.o $(top_srcdir)/lib/liblvm.a
|
||||
$(CC) -o write_vg_t write_vg_t.o pretty_print.o \
|
||||
-L$(top_srcdir)/lib -llvm
|
||||
|
||||
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
|
||||
|
||||
|
70
old-tests/format1/write_vg_t.c
Normal file
70
old-tests/format1/write_vg_t.c
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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 <stdio.h>
|
||||
|
||||
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 <vg_name>\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);
|
||||
}
|
||||
|
||||
vg = ios->vg_read(ios, argv[1]);
|
||||
|
||||
if (!vg) {
|
||||
fprintf(stderr, "couldn't read vg %s\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!ios->vg_write(ios, vg)) {
|
||||
fprintf(stderr, "couldn't write vg\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ios->destroy(ios);
|
||||
|
||||
pool_destroy(mem);
|
||||
dev_cache_exit();
|
||||
dump_memory();
|
||||
fin_log();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user