]> sourceware.org Git - lvm2.git/commitdiff
Remove vg->lv_count and use counter function.
authorMilan Broz <mbroz@redhat.com>
Wed, 13 May 2009 21:22:57 +0000 (21:22 +0000)
committerMilan Broz <mbroz@redhat.com>
Wed, 13 May 2009 21:22:57 +0000 (21:22 +0000)
This should not cause problems but simplifies code a lot.

(the volumes_count is merged and renamed with lvs_visible
function by following patch.)

12 files changed:
WHATS_NEW
lib/format1/import-export.c
lib/format_pool/format_pool.c
lib/format_pool/import_export.c
lib/format_text/import_vsn1.c
lib/metadata/lv_manip.c
lib/metadata/metadata-exported.h
lib/metadata/metadata.c
lib/metadata/snapshot_manip.c
tools/vgchange.c
tools/vgmerge.c
tools/vgsplit.c

index 15c1b167ec21fc90f93db6ed41b9b5896e42b26b..523858eec33a09392ef6f1647006fa531728d806 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -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.
index 5d2e86ade8e2ef3119b7cd12055ec5b2695633f3..56800a2683baf5a2f399a253b5311f2e42803caa 100644 (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;
 }
index 114cec196744c39da9eac36064c179372482bc16..3f31bba3b33b2590e573694df8dc4ea34bb54206 100644 (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);
index 4d2163d371f68621e323dfb3b2a3c9679652073c..25d53e71470f6950a11fb86c1b5cce586f421c6f 100644 (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;
 }
index a9748aa94e5b649e651e05a84e070995e069801b..8f0d07c1197673c82c6facec16596668f86c68c0 100644 (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;
index 7214b27c9de145c50c06d97d7fa7aef17f0b2296..64419d1a53320c5afc0d3f6a16600f0413b3f066 100644 (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;
index 6c32ab42a8d3cb713f6c5581992cfd032301bf68..2970b9c4294518060bc766aecbe8ddb5754ba649 100644 (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
 */
index 7cd416664d0a943a4527422557bfe99205fc45c4..97b9ebbdc5469f69685b1a33f552598bcc099222 100644 (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;
        }
 
index 9364b4f95a1e9e31e53a2b1d84ac7af33c0ef26b..e186dffb9d2e05dadef06cc0bad7e7a4a2b90a82 100644 (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;
index eb2b81661bc7a8f651cca7942557115a8c672b40..d01bc0114bb00bc166b0a8d4caa5f0bfd1104ce7 100644 (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;
        }
index 8b85c7af3186e02da5c6686f6eda137d8ac15bba..57a700e134f820f17ac56abb3025fccfe919f214 100644 (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;
 
index e4c7620eedfea6200e8d5340c1e3794830ed7910..317aac112b1ec61b331e7c569a3934b0b8e573b2 100644 (file)
@@ -106,12 +106,8 @@ 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;
-}      
+}
 
 static int _move_lvs(struct volume_group *vg_from, struct volume_group *vg_to)
 {
This page took 0.061692 seconds and 5 git commands to generate.