]> sourceware.org Git - lvm2.git/commitdiff
o pe_start wasn't being set properly when exporting to disk
authorJoe Thornber <thornber@redhat.com>
Thu, 11 Oct 2001 10:08:44 +0000 (10:08 +0000)
committerJoe Thornber <thornber@redhat.com>
Thu, 11 Oct 2001 10:08:44 +0000 (10:08 +0000)
o added a check for lv's with null lv_name

o setup pv->lv_cur correctly

o test program for vg_write

lib/format1/disk-rep.c
lib/format1/import-export.c
lib/format1/layout.c
old-tests/format1/Makefile.in
old-tests/format1/write_vg_t.c [new file with mode: 0644]

index 894f71deabb05cd25264c06830434f0ba966bb9c..da1429d8b992a4a899104c06655d3df36d5a3e50 100644 (file)
@@ -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);
index e36e62d341e53ee1b33bd51e1768c26768692bc2..d48655d4785deb7e5188b0020046107f1beac37e 100644 (file)
@@ -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);
        }
index 7c40bda893cca9b8fc38f6b0b4cecd0d76cdb8e0..5851a0255646bc570b3072512193d3a7d88119b9 100644 (file)
@@ -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);
index ab5d641d75e27ef0524c56cce6e896240539e35b..d4286d357a05ad2046a0abfb28c99cef6e42fa4c 100644 (file)
@@ -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
 
diff --git a/old-tests/format1/write_vg_t.c b/old-tests/format1/write_vg_t.c
new file mode 100644 (file)
index 0000000..157c4f1
--- /dev/null
@@ -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;
+}
This page took 0.045377 seconds and 5 git commands to generate.