From 442dbf9ad8c6f107a7ffe948f60ed22395e8ffbe Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Thu, 10 Mar 2011 14:40:32 +0000 Subject: [PATCH] Refactor code for _lv_postoder Add _lv_postorder_vg() - for calling _lv_postorder() for every LV from VG. We use this in 2 places - vg_mark_partial_lvs() and vg_validate() so make it as a one function. Benefit here is - to use only one cleanup code and avoid potentially duplicate scans of same LVs. --- WHATS_NEW | 1 + lib/metadata/metadata.c | 43 +++++++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 070b45931..d60f22668 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.85 - =================================== + Add _lv_postorder_vg() to improve efficiency for all LVs in VG. Use hash tables to speedup string search in validate_vg(). Refactor allocation of VG structure, add alloc_vg(). Avoid possible endless loop in _free_vginfo when 4 or more VGs have same name. diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index b95c144ac..c61c91615 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -2039,6 +2039,29 @@ static int _lv_postorder(struct logical_volume *lv, return r; } +/* + * Calls _lv_postorder() on each LV from VG. Avoids duplicate transitivity visits. + * Clears with _lv_postorder_cleanup() when all LVs were visited by postorder. + */ +static int _lv_postorder_vg(struct volume_group *vg, + int (*fn)(struct logical_volume *lv, void *data), + void *data) +{ + struct lv_list *lvl; + int r = 1; + + dm_list_iterate_items(lvl, &vg->lvs) + if (!_lv_postorder_visit(lvl->lv, fn, data)) { + stack; + r = 0; + } + + dm_list_iterate_items(lvl, &vg->lvs) + _lv_postorder_cleanup(lvl->lv, 0); + + return r; +} + struct _lv_mark_if_partial_baton { int partial; }; @@ -2076,11 +2099,6 @@ static int _lv_mark_if_partial_single(struct logical_volume *lv, void *data) return 1; } -static int _lv_mark_if_partial(struct logical_volume *lv) -{ - return _lv_postorder(lv, _lv_mark_if_partial_single, NULL); -} - /* * Mark LVs with missing PVs using PARTIAL_LV status flag. The flag is * propagated transitively, so LVs referencing other LVs are marked @@ -2088,14 +2106,9 @@ static int _lv_mark_if_partial(struct logical_volume *lv) */ int vg_mark_partial_lvs(struct volume_group *vg) { - struct logical_volume *lv; - struct lv_list *lvl; + if (!_lv_postorder_vg(vg, _lv_mark_if_partial_single, NULL)) + return_0; - dm_list_iterate_items(lvl, &vg->lvs) { - lv = lvl->lv; - if (!_lv_mark_if_partial(lv)) - return_0; - } return 1; } @@ -2378,9 +2391,9 @@ int vg_validate(struct volume_group *vg) dm_hash_destroy(lvname_hash); dm_hash_destroy(lvid_hash); - dm_list_iterate_items(lvl, &vg->lvs) { - if (!_lv_postorder(lvl->lv, _lv_validate_references_single, NULL)) - r = 0; + if (!_lv_postorder_vg(vg, _lv_validate_references_single, NULL)) { + stack; + r = 0; } dm_list_iterate_items(lvl, &vg->lvs) {