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

Remove vg->lv_count and use counter function.

This should not cause problems but simplifies code a lot.

(the volumes_count is merged and renamed with lvs_visible
function by following patch.)
This commit is contained in:
Milan Broz 2009-05-13 21:22:57 +00:00
parent 4b13d5a823
commit d60f341d96
12 changed files with 29 additions and 34 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.46 -
================================
Remove lv_count from VG and use counter function instead.
Fix snapshot segment import to not use duplicate segments & replace.
Do not query nonexistent devices for readahead.
Remove NON_BLOCKING lock flag from tools and set a policy to auto-set.

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 + snapshot_count(vg);
vgd->lv_cur = volumes_count(vg) + snapshot_count(vg);
vgd->pv_max = vg->max_pv;
vgd->pv_cur = vg->pv_count;
@ -469,7 +469,6 @@ static struct logical_volume *_add_lv(struct dm_pool *mem,
return_NULL;
dm_list_add(&vg->lvs, &ll->list);
vg->lv_count++;
return lv;
}

View File

@ -119,7 +119,6 @@ static struct volume_group *_build_vg_from_pds(struct format_instance
vg->status = 0;
vg->extent_count = 0;
vg->pv_count = 0;
vg->lv_count = 0;
vg->seqno = 1;
vg->system_id = NULL;
dm_list_init(&vg->pvs);

View File

@ -49,7 +49,6 @@ int import_pool_vg(struct volume_group *vg, struct dm_pool *mem, struct dm_list
vg->max_lv = 1;
vg->max_pv = POOL_MAX_DEVICES;
vg->alloc = ALLOC_NORMAL;
vg->lv_count = 0;
}
return 1;
@ -117,7 +116,6 @@ int import_pool_lvs(struct volume_group *vg, struct dm_pool *mem, struct dm_list
lv->le_count = lv->size / POOL_PE_SIZE;
lvl->lv = lv;
dm_list_add(&vg->lvs, &lvl->list);
vg->lv_count++;
return 1;
}

View File

@ -562,7 +562,6 @@ static int _read_lvnames(struct format_instance *fid __attribute((unused)),
}
lv->vg = vg;
vg->lv_count++;
dm_list_add(&vg->lvs, &lvl->list);
return 1;

View File

@ -438,9 +438,6 @@ static int _lv_reduce(struct logical_volume *lv, uint32_t extents, int delete)
return_0;
dm_list_del(&lvl->list);
if (!(lv->status & SNAPSHOT))
lv->vg->lv_count--;
} else if (lv->vg->fid->fmt->ops->lv_setup &&
!lv->vg->fid->fmt->ops->lv_setup(lv->vg->fid, lv))
return_0;
@ -1827,7 +1824,7 @@ struct logical_volume *lv_create_empty(const char *name,
struct logical_volume *lv;
char dname[NAME_LEN];
if (vg->max_lv && (vg->max_lv == vg->lv_count)) {
if (vg->max_lv && (vg->max_lv == volumes_count(vg))) {
log_error("Maximum number of logical volumes (%u) reached "
"in volume group %s", vg->max_lv, vg->name);
return NULL;
@ -1883,9 +1880,6 @@ struct logical_volume *lv_create_empty(const char *name,
return_NULL;
}
if (!import)
vg->lv_count++;
dm_list_add(&vg->lvs, &ll->list);
return lv;

View File

@ -251,7 +251,6 @@ struct volume_group {
* - one for the user-visible mirror LV
* all of the instances are reflected in lv_count.
*/
uint32_t lv_count;
struct dm_list lvs;
struct dm_list tags;
@ -556,6 +555,8 @@ int vg_remove_snapshot(struct logical_volume *cow);
int vg_check_status(const struct volume_group *vg, uint32_t status);
unsigned volumes_count(const struct volume_group *vg);
/*
* Mirroring functions
*/

View File

@ -571,7 +571,6 @@ struct volume_group *vg_create(struct cmd_context *cmd, const char *vg_name,
vg->pv_count = 0;
dm_list_init(&vg->pvs);
vg->lv_count = 0;
dm_list_init(&vg->lvs);
dm_list_init(&vg->tags);
@ -1165,6 +1164,22 @@ unsigned snapshot_count(const struct volume_group *vg)
return num_snapshots;
}
unsigned volumes_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))
continue;
if (lvl->lv->status & SNAPSHOT)
continue;
lv_count++;
}
return lv_count;
}
/*
* Determine whether two vgs are compatible for merging.
*/
@ -1199,7 +1214,7 @@ int vgs_are_compatible(struct cmd_context *cmd __attribute((unused)),
}
if (vg_to->max_lv &&
(vg_to->max_lv < vg_to->lv_count + vg_from->lv_count)) {
(vg_to->max_lv < volumes_count(vg_to) + volumes_count(vg_from))) {
log_error("Maximum number of logical volumes (%d) exceeded "
" for \"%s\" and \"%s\"", vg_to->max_lv, vg_to->name,
vg_from->name);
@ -1455,10 +1470,10 @@ int vg_validate(struct volume_group *vg)
}
if ((lv_count = (uint32_t) dm_list_size(&vg->lvs)) !=
vg->lv_count + 2 * snapshot_count(vg)) {
volumes_count(vg) + 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,
dm_list_size(&vg->lvs), volumes_count(vg),
snapshot_count(vg), vg->name);
r = 0;
}
@ -1502,10 +1517,10 @@ int vg_validate(struct volume_group *vg)
r = 0;
}
if (vg->max_lv && (vg->max_lv < vg->lv_count)) {
if (vg->max_lv && (vg->max_lv < volumes_count(vg))) {
log_error("Internal error: Volume group %s contains %u volumes"
" but the limit is set to %u.",
vg->name, vg->lv_count, vg->max_lv);
vg->name, volumes_count(vg), vg->max_lv);
r = 0;
}

View File

@ -69,13 +69,10 @@ void init_snapshot_seg(struct lv_segment *seg, struct logical_volume *origin,
seg->origin = origin;
seg->cow = cow;
// FIXME: direct count manipulation to be removed later
cow->status &= ~VISIBLE_LV;
cow->vg->lv_count--;
cow->snapshot = seg;
origin->origin_count++;
origin->vg->lv_count--;
/* FIXME Assumes an invisible origin belongs to a sparse device */
if (!lv_is_visible(origin))
@ -116,7 +113,6 @@ int vg_add_snapshot(struct logical_volume *origin,
if (!(seg = alloc_snapshot_seg(snap, 0, 0)))
return_0;
origin->vg->lv_count++;
init_snapshot_seg(seg, origin, cow, chunk_size);
return 1;
@ -134,8 +130,6 @@ int vg_remove_snapshot(struct logical_volume *cow)
}
cow->snapshot = NULL;
cow->vg->lv_count++;
cow->status |= VISIBLE_LV;
return 1;

View File

@ -308,9 +308,9 @@ static int _vgchange_logicalvolume(struct cmd_context *cmd,
}
}
if (max_lv && max_lv < vg->lv_count) {
if (max_lv && max_lv < volumes_count(vg)) {
log_error("MaxLogicalVolume is less than the current number "
"%d of LVs for \"%s\"", vg->lv_count,
"%d of LVs for %s", volumes_count(vg),
vg->name);
return ECMD_FAILED;
}

View File

@ -101,7 +101,6 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,
dm_list_move(&vg_to->fid->metadata_areas, mdah);
}
vg_to->lv_count += vg_from->lv_count;
vg_to->extent_count += vg_from->extent_count;
vg_to->free_count += vg_from->free_count;

View File

@ -106,10 +106,6 @@ static int _move_one_lv(struct volume_group *vg_from,
return 0;
}
if (!(lv->status & SNAPSHOT) && !lv_is_cow(lv)) {
vg_from->lv_count--;
vg_to->lv_count++;
}
return 1;
}