This should not cause problems but simplifies code a lot.
(the volumes_count is merged and renamed with lvs_visible
function by following patch.)
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.
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;
return_NULL;
dm_list_add(&vg->lvs, &ll->list);
- vg->lv_count++;
return lv;
}
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);
vg->max_lv = 1;
vg->max_pv = POOL_MAX_DEVICES;
vg->alloc = ALLOC_NORMAL;
- vg->lv_count = 0;
}
return 1;
lv->le_count = lv->size / POOL_PE_SIZE;
lvl->lv = lv;
dm_list_add(&vg->lvs, &lvl->list);
- vg->lv_count++;
return 1;
}
}
lv->vg = vg;
- vg->lv_count++;
dm_list_add(&vg->lvs, &lvl->list);
return 1;
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;
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;
return_NULL;
}
- if (!import)
- vg->lv_count++;
-
dm_list_add(&vg->lvs, &ll->list);
return lv;
* - 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;
int vg_check_status(const struct volume_group *vg, uint32_t status);
+unsigned volumes_count(const struct volume_group *vg);
+
/*
* Mirroring functions
*/
vg->pv_count = 0;
dm_list_init(&vg->pvs);
- vg->lv_count = 0;
dm_list_init(&vg->lvs);
dm_list_init(&vg->tags);
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.
*/
}
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);
}
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;
}
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;
}
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))
if (!(seg = alloc_snapshot_seg(snap, 0, 0)))
return_0;
- origin->vg->lv_count++;
init_snapshot_seg(seg, origin, cow, chunk_size);
return 1;
}
cow->snapshot = NULL;
-
- cow->vg->lv_count++;
cow->status |= VISIBLE_LV;
return 1;
}
}
- 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;
}
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;
return 0;
}
- if (!(lv->status & SNAPSHOT) && !lv_is_cow(lv)) {
- vg_from->lv_count--;
- vg_to->lv_count++;
- }
return 1;
-}
+}
static int _move_lvs(struct volume_group *vg_from, struct volume_group *vg_to)
{