From f7ff4d005f10f88bf1357d8765ed5543e2b1764d Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Tue, 29 Jan 2002 15:52:11 +0000 Subject: [PATCH] Zero gap after PV structure on write to disk in order to make non LVM tools happier (AED's idea and patch for LVM1) --- lib/format1/disk-rep.c | 43 +++++++++++++++++++++++++++++++----------- lib/format1/format1.c | 5 +++++ 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/lib/format1/disk-rep.c b/lib/format1/disk-rep.c index 8f1539331..8e3fd75d0 100644 --- a/lib/format1/disk-rep.c +++ b/lib/format1/disk-rep.c @@ -5,6 +5,7 @@ */ #include "disk-rep.h" +#include "dbg_malloc.h" #include "pool.h" #include "xlate.h" #include "log.h" @@ -169,7 +170,7 @@ static int _read_lvd(struct device *dev, ulong pos, struct lv_disk *disk) static int _read_vgd(struct disk_list *data) { struct vg_disk *vgd = &data->vgd; - unsigned long pos = data->pvd.vg_on_disk.base; + ulong pos = data->pvd.vg_on_disk.base; if (dev_read(data->dev, pos, sizeof(*vgd), vgd) != sizeof(*vgd)) fail; @@ -214,7 +215,7 @@ static inline int _check_lvd(struct lv_disk *lvd) static int _read_lvs(struct disk_list *data) { int i, read = 0; - unsigned long pos; + ulong pos; struct lvd_list *ll; struct vg_disk *vgd = &data->vgd; @@ -242,7 +243,7 @@ static int _read_extents(struct disk_list *data) { size_t len = sizeof(struct pe_disk) * data->pvd.pe_total; struct pe_disk *extents = pool_alloc(data->mem, len); - unsigned long pos = data->pvd.pe_on_disk.base; + ulong pos = data->pvd.pe_on_disk.base; if (!extents) fail; @@ -421,7 +422,7 @@ int read_pvs_in_vg(const char *vg_name, struct dev_filter *filter, static int _write_vgd(struct disk_list *data) { struct vg_disk *vgd = &data->vgd; - unsigned long pos = data->pvd.vg_on_disk.base; + ulong pos = data->pvd.vg_on_disk.base; _xlate_vgd(vgd); if (dev_write(data->dev, pos, sizeof(*vgd), vgd) != sizeof(*vgd)) @@ -470,7 +471,7 @@ static int _write_lvd(struct device *dev, ulong pos, struct lv_disk *disk) static int _write_lvs(struct disk_list *data) { struct list *lvh; - unsigned long pos; + ulong pos; pos = data->pvd.lv_on_disk.base; @@ -496,7 +497,7 @@ static int _write_extents(struct disk_list *data) { size_t len = sizeof(struct pe_disk) * data->pvd.pe_total; struct pe_disk *extents = data->extents; - unsigned long pos = data->pvd.pe_on_disk.base; + ulong pos = data->pvd.pe_on_disk.base; _xlate_extents(extents, data->pvd.pe_total); if (dev_write(data->dev, pos, len, extents) != len) @@ -509,14 +510,34 @@ static int _write_extents(struct disk_list *data) static int _write_pvd(struct disk_list *data) { - struct pv_disk *disk = &data->pvd; + char *buf; + ulong pos = data->pvd.pv_on_disk.base; + ulong size = data->pvd.pv_on_disk.size; - _xlate_pvd(disk); - if (dev_write(data->dev, 0, sizeof(*disk), disk) != sizeof(*disk)) + if(size < sizeof(struct pv_disk)) { + log_err("Invalid PV size."); + return 0; + } + + /* Make sure that the gap between the PV structure and + the next one is zeroed in order to make non LVM tools + happy (idea from AED) */ + buf = dbg_malloc(size); + if(!buf) { + log_err("Couldn't allocate temporary PV buffer."); + return 0; + } + + memset(buf, 0, size); + memcpy(buf, &data->pvd, sizeof(struct pv_disk)); + + _xlate_pvd((struct pv_disk *)buf); + if (dev_write(data->dev, pos, size, buf) != size) { + dbg_free(buf); fail; + } - _xlate_pvd(disk); - + dbg_free(buf); return 1; } diff --git a/lib/format1/format1.c b/lib/format1/format1.c index f65be783c..7e538a9fb 100644 --- a/lib/format1/format1.c +++ b/lib/format1/format1.c @@ -401,6 +401,11 @@ static int _pv_write(struct format_instance *fi, struct physical_volume *pv) goto bad; } + /* must be set to be able to zero gap after PV structure in + dev_write in order to make other disk tools happy */ + dl->pvd.pv_on_disk.base = METADATA_BASE; + dl->pvd.pv_on_disk.size = PV_SIZE; + list_add(&pvs, &dl->list); if (!write_disks(&pvs)) { stack;