From 9d1db8278a21e46be4e22a424127c652204aec2a Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Wed, 6 Apr 2005 16:35:33 +0000 Subject: [PATCH] _vg_posn -> _find_vg_rlocn --- lib/format_text/format-text.c | 49 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c index 0676921c9..34eef5b4a 100644 --- a/lib/format_text/format-text.c +++ b/lib/format_text/format-text.c @@ -213,32 +213,41 @@ static struct raw_locn *_find_vg_rlocn(struct device_area *dev_area, return NULL; } -static struct raw_locn *_vg_posn(struct format_instance *fid, - struct device_area *dev_area, - const char *vgname) +/* + * Determine offset for uncommitted metadata + */ +static uint64_t _next_rlocn_offset(struct raw_locn *rlocn, + struct mda_header *mdah) { + if (!rlocn) + /* Find an empty slot */ + /* FIXME Assume only one VG per mdah for now */ + return MDA_HEADER_SIZE; - struct mda_header *mdah; - - if (!(mdah = _raw_read_mda_header(fid->fmt, dev_area))) { - stack; - return NULL; - } - - return _find_vg_rlocn(dev_area, mdah, vgname); + /* Start of free space - round up to next sector; circular */ + return ((rlocn->offset + rlocn->size + + (SECTOR_SIZE - rlocn->size % SECTOR_SIZE) - + MDA_HEADER_SIZE) % (mdah->size - MDA_HEADER_SIZE)) + + MDA_HEADER_SIZE; } static int _raw_holds_vgname(struct format_instance *fid, struct device_area *dev_area, const char *vgname) { int r = 0; + struct mda_header *mdah; if (!dev_open(dev_area->dev)) { stack; return 0; } - if (_vg_posn(fid, dev_area, vgname)) + if (!(mdah = _raw_read_mda_header(fid->fmt, dev_area))) { + stack; + return 0; + } + + if (_find_vg_rlocn(dev_area, mdah, vgname)) r = 1; if (!dev_close(dev_area->dev)) @@ -268,7 +277,7 @@ static struct volume_group *_vg_read_raw_area(struct format_instance *fid, goto out; } - if (!(rlocn = _vg_posn(fid, area, vgname))) { + if (!(rlocn = _find_vg_rlocn(area, mdah, vgname))) { log_debug("VG %s not found on %s", vgname, dev_name(area->dev)); goto out; } @@ -349,18 +358,8 @@ static int _vg_write_raw(struct format_instance *fid, struct volume_group *vg, goto out; } - if ((rlocn = _find_vg_rlocn(&mdac->area, mdah, vg->name))) { - /* Start of free space - round up to next sector; circular */ - mdac->rlocn.offset = - ((rlocn->offset + rlocn->size + - (SECTOR_SIZE - rlocn->size % SECTOR_SIZE) - - MDA_HEADER_SIZE) % (mdah->size - MDA_HEADER_SIZE)) - + MDA_HEADER_SIZE; - } else { - /* Find an empty slot */ - /* FIXME Assume only one VG per mdah for now */ - mdac->rlocn.offset = MDA_HEADER_SIZE; - } + rlocn = _find_vg_rlocn(&mdac->area, mdah, vg->name); + mdac->rlocn.offset = _next_rlocn_offset(rlocn, mdah); if (!(mdac->rlocn.size = text_vg_export_raw(vg, "", buf, sizeof(buf)))) { log_error("VG %s metadata writing failed", vg->name);