From 064c620fb0bd51353d607c1a5a4036119eca7094 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Fri, 5 Oct 2001 13:59:44 +0000 Subject: [PATCH] o finished writing extent reading code --- lib/format1/format1.c | 58 ++++++++++++++++++++++++++++++++++++------- lib/format1/format1.h | 15 +++++++++++ 2 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 lib/format1/format1.h diff --git a/lib/format1/format1.c b/lib/format1/format1.c index c28906caa..7eedf920d 100644 --- a/lib/format1/format1.c +++ b/lib/format1/format1.c @@ -92,7 +92,7 @@ static int _import_pvs(struct pool *mem, struct volume_group *vg, return 1; } -static struct logical_volume *_find_lv(struct volume_group *vg, +static struct logical_volume *_find_lv(struct volume_group *vg, const char *name) { struct list_head *tmp; @@ -142,6 +142,7 @@ static int _import_lvs(struct pool *mem, struct volume_group *vg, { struct list_head *tmp, tmp2; struct disk_list *dl; + struct lv_list *ll; struct lv_disk *lvd; struct logical_volume *lv; int i; @@ -149,7 +150,9 @@ static int _import_lvs(struct pool *mem, struct volume_group *vg, list_for_each(tmp, pvs) { dl = list_entry(tmp, struct disk_list, list); list_for_each(tmp2, &dl->lvs) { - lvd = list_entry(tmp2, struct lv_disk, list); + ll = list_entry(tmp2, struct lv_list, list); + lvd = &ll->lv; + if (!_find_lv(vg, lvd->lvname) && !_add_lv(vg, lvd)) { stack; return 0; @@ -160,29 +163,66 @@ static int _import_lvs(struct pool *mem, struct volume_group *vg, return 1; } +static int _fill_lv_array(struct logical_volume *lvs, + struct volume_group *vg, struct disk_list *dl) +{ + struct list_head *tmp; + struct pv_disk *pvd = &dl->pv; + struct logical_volume *lv; + int i = 0; + + list_for_each(tmp, &dl->lvs) { + struct lv_list *ll = list_entry(tmp, struct lv_disk, list); + + if (!(lv = _find_lv(vg, ll->lv.name))) { + stack; + return 0; + } + + lvs[i] = lv; + i++; + } + + return 1; +} + static int _import_extents(struct pool *mem, struct volume_group *vg, struct list_head *pvs) { struct list_head *tmp; struct disk_list *dl; - struct logical_volume *lv; + struct logical_volume *lv, lvs[MAX_LV]; struct physical_volume *pv; struct pe_disk *e; int i, le; + uint32_t lv_num, le_num; list_for_each(tmp, pvs) { dl = list_entry(tmp, struct disk_list, list); pv = _find_pv(vg, dl->pv.pv_name); e = dl->extents; - for (i = 0; i < dl->pv.pe_total; i++) { - if (e[i].lv_num) { - if (!(lv = _find_lv_num(vg, e[i].lv_num))) { - stack; - return 0; - } + /* build an array of lv's for this pv */ + if (!_fill_lv_array(lvs, vg, dl)) { + stack; + return 0; + } + for (i = 0; i < dl->pv.pe_total; i++) { + lv_num = e[i].lv_num; + le_num = e[i].le_num; + + if (lv_num == UNMAPPED_EXTENT) + lv->map[le].pv = NULL; + + else if(lv_num >= dl->pv.lv_cur) { + log_err("invalid lv in extent map\n"); + return 0; + + else { + lv = lvs[e[i].lv_num]; le = e[i].le_num; + lv->map[le].pv = pv; lv->map[le].pe = i; } diff --git a/lib/format1/format1.h b/lib/format1/format1.h new file mode 100644 index 000000000..44a3f87a9 --- /dev/null +++ b/lib/format1/format1.h @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2001 Sistina Software (UK) Limited. + * + * This file is released under the GPL. + * + */ + +#ifndef LVM_FORMAT1_H +#define LVM_FORMAT1_H + +#include "metadata.h" + +struct io_space *create_lvm_v1_format(struct dev_filter *filter); + +#endif