]> sourceware.org Git - lvm2.git/commitdiff
Remove snapshot_count from VG and use function instead.
authorMilan Broz <mbroz@redhat.com>
Tue, 12 May 2009 19:12:09 +0000 (19:12 +0000)
committerMilan Broz <mbroz@redhat.com>
Tue, 12 May 2009 19:12:09 +0000 (19:12 +0000)
WHATS_NEW
lib/format1/import-export.c
lib/format_pool/format_pool.c
lib/metadata/metadata-exported.h
lib/metadata/metadata.c
lib/metadata/metadata.h
lib/metadata/snapshot_manip.c
lib/report/columns.h
lib/report/report.c
tools/vgmerge.c
tools/vgsplit.c

index 4cea7d50b838e0eac4610638e54e55e5294373d2..858c33fb87d20b02f7ca5d1cf00664b02f8a3a76 100644 (file)
--- 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.
index 66e2390ecd371e84a7d6ed56fbc674591f758cd2..a950f9af73da5a0f4820622a2ee91807839a9e91 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 + vg->snapshot_count;
+       vgd->lv_cur = vg->lv_count + snapshot_count(vg);
 
        vgd->pv_max = vg->max_pv;
        vgd->pv_cur = vg->pv_count;
index 9a34f94b3c610fe93a1bea1a7b698760af6d3385..114cec196744c39da9eac36064c179372482bc16 100644 (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);
index 3b13e378c9724ac9b39eea414412d87049b35a94..9bd33894b2e248af8bb34e4bec979edb075e0209 100644 (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;
index af4c69c1d797e767e4622a79cf94a189f380567e..a5fefd536ad96e32bdf44866e1eae79533010882 100644 (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;
        }
 
index eff2380c273d7a2c3f4d305923752f1aac198dc5..aca57f4c0df43604fa13888e8a396e92c4981f24 100644 (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.
  */
index 1189dbdb3f313f060cd1de0a1d34805b069ddd14..6aa29a00e2778d34009be69847bbec1e139f2c2e 100644 (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;
 
index d1dbc1c60778f3254b85f6dace51e30a4773c8ca..04a37738471377276184ab6846840ba5ba28bf83 100644 (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.")
index 91e2b98ac897b0de62bc419d7d1552ce96361310..d8f7961de9e38aa4325db7a4e436fc9d64c0ffb3 100644 (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)))
index c847c7ef965560c00e7467213e0ac174178336c6..82c34561dd9e9531a03209ff50aee33741edeb6b 100644 (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;
 
index 87e74a4a801cb1af33ccf17df327ff0418ac4bf0..c4b583afde183d12b9b133512030fb59e37d2b60 100644 (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++;
        }
This page took 0.053364 seconds and 5 git commands to generate.