summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--WHATS_NEW1
-rw-r--r--lib/format1/import-export.c2
-rw-r--r--lib/format_pool/format_pool.c1
-rw-r--r--lib/metadata/metadata-exported.h4
-rw-r--r--lib/metadata/metadata.c18
-rw-r--r--lib/metadata/metadata.h5
-rw-r--r--lib/metadata/snapshot_manip.c2
-rw-r--r--lib/report/columns.h2
-rw-r--r--lib/report/report.c12
-rw-r--r--tools/vgmerge.c2
-rw-r--r--tools/vgsplit.c5
11 files changed, 36 insertions, 18 deletions
diff --git a/WHATS_NEW b/WHATS_NEW
index 4cea7d50..858c33fb 100644
--- 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.
diff --git a/lib/format1/import-export.c b/lib/format1/import-export.c
index 66e2390e..a950f9af 100644
--- a/lib/format1/import-export.c
+++ b/lib/format1/import-export.c
@@ -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;
diff --git a/lib/format_pool/format_pool.c b/lib/format_pool/format_pool.c
index 9a34f94b..114cec19 100644
--- a/lib/format_pool/format_pool.c
+++ b/lib/format_pool/format_pool.c
@@ -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);
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 3b13e378..9bd33894 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -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;
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index af4c69c1..a5fefd53 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -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;
}
diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h
index eff2380c..aca57f4c 100644
--- a/lib/metadata/metadata.h
+++ b/lib/metadata/metadata.h
@@ -345,6 +345,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.
*/
int export_vg_to_buffer(struct volume_group *vg, char **buf);
diff --git a/lib/metadata/snapshot_manip.c b/lib/metadata/snapshot_manip.c
index 1189dbdb..6aa29a00 100644
--- a/lib/metadata/snapshot_manip.c
+++ b/lib/metadata/snapshot_manip.c
@@ -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;
diff --git a/lib/report/columns.h b/lib/report/columns.h
index d1dbc1c6..04a37738 100644
--- a/lib/report/columns.h
+++ b/lib/report/columns.h
@@ -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.")
diff --git a/lib/report/report.c b/lib/report/report.c
index 91e2b98a..d8f7961d 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -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)))
diff --git a/tools/vgmerge.c b/tools/vgmerge.c
index c847c7ef..82c34561 100644
--- a/tools/vgmerge.c
+++ b/tools/vgmerge.c
@@ -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;
diff --git a/tools/vgsplit.c b/tools/vgsplit.c
index 87e74a4a..c4b583af 100644
--- a/tools/vgsplit.c
+++ b/tools/vgsplit.c
@@ -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++;
}