From: Milan Broz Date: Tue, 12 May 2009 19:12:09 +0000 (+0000) Subject: Remove snapshot_count from VG and use function instead. X-Git-Tag: v2_02_91~3122 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=2f9a9d1a7f79f098593d95d308eabe18a57d200d;p=lvm2.git Remove snapshot_count from VG and use function instead. --- diff --git a/WHATS_NEW b/WHATS_NEW index 4cea7d50b..858c33fb8 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.46 - ================================ + Remove snapshot_count from VG and use function instead. Fix first_seg() call for empty segment list. Add make install_lvm2 as complement to device-mapper install. Reject missing PVs from allocation in toollib. diff --git a/lib/format1/import-export.c b/lib/format1/import-export.c index 66e2390ec..a950f9af7 100644 --- a/lib/format1/import-export.c +++ b/lib/format1/import-export.c @@ -282,7 +282,7 @@ int export_vg(struct vg_disk *vgd, struct volume_group *vg) vgd->vg_status |= VG_EXTENDABLE; vgd->lv_max = vg->max_lv; - vgd->lv_cur = vg->lv_count + vg->snapshot_count; + vgd->lv_cur = vg->lv_count + snapshot_count(vg); vgd->pv_max = vg->max_pv; vgd->pv_cur = vg->pv_count; diff --git a/lib/format_pool/format_pool.c b/lib/format_pool/format_pool.c index 9a34f94b3..114cec196 100644 --- a/lib/format_pool/format_pool.c +++ b/lib/format_pool/format_pool.c @@ -120,7 +120,6 @@ static struct volume_group *_build_vg_from_pds(struct format_instance vg->extent_count = 0; vg->pv_count = 0; vg->lv_count = 0; - vg->snapshot_count = 0; vg->seqno = 1; vg->system_id = NULL; dm_list_init(&vg->pvs); diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index 3b13e378c..9bd33894b 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -243,8 +243,7 @@ struct volume_group { * Snapshots consist of 2 instances of "struct logical_volume": * - cow (lv_name is visible to the user) * - snapshot (lv_name is 'snapshotN') - * Neither of these instances is reflected in lv_count, but we - * multiply the snapshot_count by 2. + * Neither of these instances is reflected in lv_count. * * Mirrors consist of multiple instances of "struct logical_volume": * - one for the mirror log @@ -253,7 +252,6 @@ struct volume_group { * all of the instances are reflected in lv_count. */ uint32_t lv_count; - uint32_t snapshot_count; struct dm_list lvs; struct dm_list tags; diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index af4c69c1d..a5fefd536 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -574,8 +574,6 @@ struct volume_group *vg_create(struct cmd_context *cmd, const char *vg_name, vg->lv_count = 0; dm_list_init(&vg->lvs); - vg->snapshot_count = 0; - dm_list_init(&vg->tags); if (!(vg->fid = cmd->fmt->ops->create_instance(cmd->fmt, vg_name, @@ -1155,6 +1153,18 @@ unsigned displayable_lvs_in_vg(const struct volume_group *vg) return lv_count; } +unsigned snapshot_count(const struct volume_group *vg) +{ + struct lv_list *lvl; + unsigned lv_count = 0; + + dm_list_iterate_items(lvl, &vg->lvs) + if (lv_is_cow(lvl->lv)) + lv_count++; + + return lv_count; +} + /* * Determine whether two vgs are compatible for merging. */ @@ -1445,11 +1455,11 @@ int vg_validate(struct volume_group *vg) } if ((lv_count = (uint32_t) dm_list_size(&vg->lvs)) != - vg->lv_count + 2 * vg->snapshot_count) { + vg->lv_count + 2 * snapshot_count(vg)) { log_error("Internal error: #internal LVs (%u) != #LVs (%" PRIu32 ") + 2 * #snapshots (%" PRIu32 ") in VG %s", dm_list_size(&vg->lvs), vg->lv_count, - vg->snapshot_count, vg->name); + snapshot_count(vg), vg->name); r = 0; } diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index eff2380c2..aca57f4c0 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -344,6 +344,11 @@ struct lv_segment *get_only_segment_using_this_lv(struct logical_volume *lv); */ unsigned displayable_lvs_in_vg(const struct volume_group *vg); +/* + * Count snapshot LVs. + */ +unsigned snapshot_count(const struct volume_group *vg); + /* * For internal metadata caching. */ diff --git a/lib/metadata/snapshot_manip.c b/lib/metadata/snapshot_manip.c index 1189dbdb3..6aa29a00e 100644 --- a/lib/metadata/snapshot_manip.c +++ b/lib/metadata/snapshot_manip.c @@ -106,7 +106,6 @@ int vg_add_snapshot(const char *name, struct logical_volume *origin, seg->lv->status |= SNAPSHOT; origin->origin_count++; - origin->vg->snapshot_count++; cow->snapshot = seg; cow->status &= ~VISIBLE_LV; @@ -133,7 +132,6 @@ int vg_remove_snapshot(struct logical_volume *cow) cow->snapshot = NULL; - cow->vg->snapshot_count--; cow->vg->lv_count++; cow->status |= VISIBLE_LV; diff --git a/lib/report/columns.h b/lib/report/columns.h index d1dbc1c60..04a377384 100644 --- a/lib/report/columns.h +++ b/lib/report/columns.h @@ -108,7 +108,7 @@ FIELD(VGS, vg, NUM, "MaxLV", max_lv, 5, uint32, "max_lv", "Maximum number of LVs FIELD(VGS, vg, NUM, "MaxPV", max_pv, 5, uint32, "max_pv", "Maximum number of PVs allowed in VG or 0 if unlimited.") FIELD(VGS, vg, NUM, "#PV", pv_count, 3, uint32, "pv_count", "Number of PVs.") FIELD(VGS, vg, NUM, "#LV", cmd, 3, lvcount, "lv_count", "Number of LVs.") -FIELD(VGS, vg, NUM, "#SN", snapshot_count, 3, uint32, "snap_count", "Number of snapshots.") +FIELD(VGS, vg, NUM, "#SN", cmd, 3, snapcount, "snap_count", "Number of snapshots.") FIELD(VGS, vg, NUM, "Seq", seqno, 3, uint32, "vg_seqno", "Revision number of internal metadata. Incremented whenever it changes.") FIELD(VGS, vg, STR, "VG Tags", tags, 7, tags, "vg_tags", "Tags, if any.") FIELD(VGS, vg, NUM, "#VMda", cmd, 5, vgmdas, "vg_mda_count", "Number of metadata areas in use by this VG.") diff --git a/lib/report/report.c b/lib/report/report.c index 91e2b98ac..d8f7961de 100644 --- a/lib/report/report.c +++ b/lib/report/report.c @@ -991,6 +991,18 @@ static int _lvsegcount_disp(struct dm_report *rh, struct dm_pool *mem, return _uint32_disp(rh, mem, field, &count, private); } +static int _snapcount_disp(struct dm_report *rh, struct dm_pool *mem, + struct dm_report_field *field, + const void *data, void *private) +{ + const struct volume_group *vg = (const struct volume_group *) data; + uint32_t count; + + count = snapshot_count(vg); + + return _uint32_disp(rh, mem, field, &count, private); +} + static int _snpercent_disp(struct dm_report *rh __attribute((unused)), struct dm_pool *mem, struct dm_report_field *field, const void *data, void *private __attribute((unused))) diff --git a/tools/vgmerge.c b/tools/vgmerge.c index c847c7ef9..82c34561d 100644 --- a/tools/vgmerge.c +++ b/tools/vgmerge.c @@ -102,8 +102,6 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to, } vg_to->lv_count += vg_from->lv_count; - vg_to->snapshot_count += vg_from->snapshot_count; - vg_to->extent_count += vg_from->extent_count; vg_to->free_count += vg_from->free_count; diff --git a/tools/vgsplit.c b/tools/vgsplit.c index 87e74a4a8..c4b583afd 100644 --- a/tools/vgsplit.c +++ b/tools/vgsplit.c @@ -106,10 +106,7 @@ static int _move_one_lv(struct volume_group *vg_from, return 0; } - if (lv->status & SNAPSHOT) { - vg_from->snapshot_count--; - vg_to->snapshot_count++; - } else if (!lv_is_cow(lv)) { + if (!(lv->status & SNAPSHOT) && !lv_is_cow(lv)) { vg_from->lv_count--; vg_to->lv_count++; }