From ab47fb661f473bfea34c9d6491cc7031de152889 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Thu, 11 Oct 2001 10:55:19 +0000 Subject: [PATCH] o calculate pv_numbers and lv_numbers for LVM1 support --- lib/format1/disk-rep.h | 2 ++ lib/format1/format1.c | 2 ++ lib/format1/import-export.c | 40 +++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/lib/format1/disk-rep.h b/lib/format1/disk-rep.h index 1f232e6aa..7882c5fa4 100644 --- a/lib/format1/disk-rep.h +++ b/lib/format1/disk-rep.h @@ -216,5 +216,7 @@ int export_lvs(struct disk_list *dl, struct volume_group *vg, int export_uuids(struct disk_list *dl, struct volume_group *vg); +void export_numbers(struct list_head *pvs, struct volume_group *vg); + #endif diff --git a/lib/format1/format1.c b/lib/format1/format1.c index b832a4784..2fccbc3c4 100644 --- a/lib/format1/format1.c +++ b/lib/format1/format1.c @@ -149,6 +149,8 @@ static int _flatten_vg(struct pool *mem, struct volume_group *vg, list_add(&data->list, pvs); } + + export_numbers(pvs, vg); return 1; } diff --git a/lib/format1/import-export.c b/lib/format1/import-export.c index d48655d47..73c520dac 100644 --- a/lib/format1/import-export.c +++ b/lib/format1/import-export.c @@ -526,3 +526,43 @@ int export_uuids(struct disk_list *dl, struct volume_group *vg) } return 1; } + +static int _get_lv_number(struct volume_group *vg, const char *name) +{ + /* FIXME: inefficient */ + struct list_head *tmp; + struct lv_list *ll; + int r = 0; + + list_for_each (tmp, &vg->lvs) { + ll = list_entry(tmp, struct lv_list, list); + if (!strcmp(ll->lv.name, name)) + break; + r++; + } + + return r; +} + +/* + * This calculates the nasty pv_number and + * lv_number fields used by LVM1. Very + * inefficient code. + */ +void export_numbers(struct list_head *pvs, struct volume_group *vg) +{ + struct list_head *tmp, *tmp2; + struct disk_list *dl; + struct lvd_list *ll; + int pv_num = 0; + + list_for_each (tmp, pvs) { + dl = list_entry(tmp, struct disk_list, list); + dl->pv.pv_number = pv_num++; + + list_for_each (tmp2, &dl->lvs) { + ll = list_entry(tmp2, struct lvd_list, list); + ll->lv.lv_number = _get_lv_number(vg, ll->lv.lv_name); + } + } +}