1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

Remove snapshot_count from VG and use function instead.

This commit is contained in:
Milan Broz 2009-05-12 19:12:09 +00:00
parent 920e68d603
commit 2f9a9d1a7f
11 changed files with 36 additions and 18 deletions

View File

@ -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.

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;
}

View File

@ -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.
*/

View File

@ -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;

View File

@ -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.")

View File

@ -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)))

View File

@ -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;

View File

@ -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++;
}