Skip to contentSkip to conversation

Fix off by 512 sizes for lvm2app.

PATCH New Dave Wysochanski 2 participants 4 messages Feb 13, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Fix off by 512 sizes for lvm2app.

Internally we store sizes in sectors, but lvm2app exports sizes in bytes. We could get fancier and allow units configuration but this fix should do for now.

Fixes rhbz561422.

---
 lib/metadata/metadata-exported.h |    1 +
 lib/metadata/metadata.h          |    2 +-
 liblvm/lvm_lv.c                  |    2 +-
 liblvm/lvm_vg.c                  |    8 ++++----
 4 files changed, 7 insertions(+), 6 deletions(-)
lib/metadata/metadata-exported.h +1 -0
index f8329d5..acb7b52 100644
@@ -25,6 +25,7 @@
 
 #define MAX_STRIPES 128U
 #define SECTOR_SHIFT 9L
+#define SECTOR_SIZE ( 1L << SECTOR_SHIFT )
 #define STRIPE_SIZE_MIN ( (unsigned) lvm_getpagesize() >> SECTOR_SHIFT)	/* PAGESIZE in sectors */
 #define STRIPE_SIZE_MAX ( 512L * 1024L >> SECTOR_SHIFT)	/* 512 KB in sectors */
 #define STRIPE_SIZE_LIMIT ((UINT_MAX >> 2) + 1)
lib/metadata/metadata.h +1 -1
index 391734b..542be6e 100644
@@ -28,7 +28,7 @@
 
 //#define MAX_STRIPES 128U
 //#define SECTOR_SHIFT 9L
-#define SECTOR_SIZE ( 1L << SECTOR_SHIFT )
+//#define SECTOR_SIZE ( 1L << SECTOR_SHIFT )
 //#define STRIPE_SIZE_MIN ( (unsigned) lvm_getpagesize() >> SECTOR_SHIFT)	/* PAGESIZE in sectors */
 //#define STRIPE_SIZE_MAX ( 512L * 1024L >> SECTOR_SHIFT)	/* 512 KB in sectors */
 //#define STRIPE_SIZE_LIMIT ((UINT_MAX >> 2) + 1)
liblvm/lvm_lv.c +1 -1
index d28e6bd..74950e3 100644
@@ -26,7 +26,7 @@
 /* FIXME: have lib/report/report.c _disp function call lv_size()? */
 uint64_t lvm_lv_get_size(const lv_t lv)
 {
-	return lv_size(lv);
+	return SECTOR_SIZE*lv_size(lv);
 }
 
 char *lvm_lv_get_uuid(const lv_t lv)
liblvm/lvm_vg.c +4 -4
index 9a5c239..30c7aad 100644
@@ -86,7 +86,7 @@ int lvm_vg_set_extent_size(vg_t vg, uint32_t new_size)
 	if (!vg_check_write_mode(vg))
 		return -1;
 
-	if (!vg_set_extent_size(vg, new_size))
+	if (!vg_set_extent_size(vg, new_size/SECTOR_SIZE))
 		return -1;
 	return 0;
 }
@@ -256,17 +256,17 @@ uint64_t lvm_vg_is_partial(const vg_t vg)
 /* FIXME: invalid handle? return INTMAX? */
 uint64_t lvm_vg_get_size(const vg_t vg)
 {
-	return vg_size(vg);
+	return SECTOR_SIZE*vg_size(vg);
 }
 
 uint64_t lvm_vg_get_free_size(const vg_t vg)
 {
-	return vg_free(vg);
+	return SECTOR_SIZE*vg_free(vg);
 }
 
 uint64_t lvm_vg_get_extent_size(const vg_t vg)
 {
-	return vg_extent_size(vg);
+	return SECTOR_SIZE*vg_extent_size(vg);
 }
 
 uint64_t lvm_vg_get_extent_count(const vg_t vg)
Signature · 1 line
1.6.0.6
#1 lore raw

PATCH 2/3 Export lvm_pv_get_size(), lvm_pv_get_free(), lvm_pv_get_dev_size in lvm2app.

We add these exports to show the pv_size and pv_free and dev_size fields.
Fixes rhbz561423.

---
 lib/metadata/metadata-exported.h |    3 +++
 lib/metadata/metadata.c          |   32 ++++++++++++++++++++++++++++++++
 lib/report/columns.h             |    2 +-
 lib/report/report.c              |   16 +++++-----------
 liblvm/.exported_symbols         |    3 +++
 liblvm/lvm2app.h                 |   34 ++++++++++++++++++++++++++++++++++
 liblvm/lvm_pv.c                  |   15 +++++++++++++++
 7 files changed, 93 insertions(+), 12 deletions(-)
lib/metadata/metadata-exported.h +3 -0
index acb7b52..164ce36 100644
@@ -726,6 +726,9 @@ struct device *pv_dev(const struct physical_volume *pv);
 const char *pv_vg_name(const struct physical_volume *pv);
 const char *pv_dev_name(const struct physical_volume *pv);
 uint64_t pv_size(const struct physical_volume *pv);
+uint64_t pv_size_field(const struct physical_volume *pv);
+uint64_t pv_dev_size(const struct physical_volume *pv);
+uint64_t pv_free(const struct physical_volume *pv);
 uint64_t pv_status(const struct physical_volume *pv);
 uint32_t pv_pe_size(const struct physical_volume *pv);
 uint64_t pv_pe_start(const struct physical_volume *pv);
lib/metadata/metadata.c +32 -0
index 28c7c47..b3b3778 100644
@@ -3603,6 +3603,38 @@ uint64_t pv_size(const struct physical_volume *pv)
 	return pv_field(pv, size);
 }
 
+uint64_t pv_dev_size(const struct physical_volume *pv)
+{
+	uint64_t size;
+
+	if (!dev_get_size(pv->dev, &size))
+		size = 0;
+	return size;
+}
+
+uint64_t pv_size_field(const struct physical_volume *pv)
+{
+	uint64_t size;
+
+	if (!pv->pe_count)
+		size = pv->size;
+	else
+		size = (uint64_t) pv->pe_count * pv->pe_size;
+	return size;
+}
+
+uint64_t pv_free(const struct physical_volume *pv)
+{
+	uint64_t freespace;
+
+	if (!pv->pe_count)
+		freespace = pv->size;
+	else
+		freespace = (uint64_t)
+			(pv->pe_count - pv->pe_alloc_count) * pv->pe_size;
+	return freespace;
+}
+
 uint64_t pv_status(const struct physical_volume *pv)
 {
 	return pv_field(pv, status);
lib/report/columns.h +1 -1
index 49ebab4..1414971 100644
@@ -78,7 +78,7 @@ FIELD(LVS, lv, STR, "Modules", lvid, 7, modules, "modules", "Kernel device-mappe
 
 FIELD(LABEL, pv, STR, "Fmt", id, 3, pvfmt, "pv_fmt", "Type of metadata.")
 FIELD(LABEL, pv, STR, "PV UUID", id, 38, uuid, "pv_uuid", "Unique identifier.")
-FIELD(LABEL, pv, NUM, "DevSize", dev, 7, devsize, "dev_size", "Size of underlying device in current units.")
+FIELD(LABEL, pv, NUM, "DevSize", id, 7, devsize, "dev_size", "Size of underlying device in current units.")
 FIELD(LABEL, pv, STR, "PV", dev, 10, dev_name, "pv_name", "Name.")
 FIELD(LABEL, pv, NUM, "PMdaFree", id, 9, pvmdafree, "pv_mda_free", "Free metadata area space on this device in current units.")
 FIELD(LABEL, pv, NUM, "PMdaSize", id, 9, pvmdasize, "pv_mda_size", "Size of smallest metadata area on this device in current units.")
lib/report/report.c +5 -11
index 2cceedd..6bcab55 100644
@@ -767,10 +767,7 @@ static int _pvfree_disp(struct dm_report *rh, struct dm_pool *mem,
 	    (const struct physical_volume *) data;
 	uint64_t freespace;
 
-	if (!pv->pe_count)
-		freespace = pv->size;
-	else
-		freespace = (uint64_t) (pv->pe_count - pv->pe_alloc_count) * pv->pe_size;
+	freespace = pv_free(pv);
 
 	return _size64_disp(rh, mem, field, &freespace, private);
 }
@@ -783,10 +780,7 @@ static int _pvsize_disp(struct dm_report *rh, struct dm_pool *mem,
 	    (const struct physical_volume *) data;
 	uint64_t size;
 
-	if (!pv->pe_count)
-		size = pv->size;
-	else
-		size = (uint64_t) pv->pe_count * pv->pe_size;
+	size = pv_size_field(pv);
 
 	return _size64_disp(rh, mem, field, &size, private);
 }
@@ -795,11 +789,11 @@ static int _devsize_disp(struct dm_report *rh, struct dm_pool *mem,
 			 struct dm_report_field *field,
 			 const void *data, void *private)
 {
-	const struct device *dev = *(const struct device **) data;
+	const struct physical_volume *pv =
+	    (const struct physical_volume *) data;
 	uint64_t size;
 
-	if (!dev_get_size(dev, &size))
-		size = 0;
+	size = pv_dev_size(pv);
 
 	return _size64_disp(rh, mem, field, &size, private);
 }
liblvm/.exported_symbols +3 -0
index 1e6d4c4..c184a88 100644
@@ -3,6 +3,9 @@ lvm_init
 lvm_quit
 lvm_config_reload
 lvm_config_override
+lvm_pv_get_dev_size
+lvm_pv_get_size
+lvm_pv_get_free
 lvm_pv_get_name
 lvm_pv_get_uuid
 lvm_pv_get_mda_count
liblvm/lvm2app.h +34 -0
index aeadd74..442a591 100644
@@ -868,6 +868,40 @@ char *lvm_pv_get_name(const pv_t pv);
 uint64_t lvm_pv_get_mda_count(const pv_t pv);
 
 /**
+ * Get the current size in bytes of a device underlying a
+ * physical volume.
+ *
+ * \param   pv
+ * Physical volume handle.
+ *
+ * \return
+ * Size in bytes.
+ */
+uint64_t lvm_pv_get_dev_size(const pv_t pv);
+
+/**
+ * Get the current size in bytes of a physical volume.
+ *
+ * \param   pv
+ * Physical volume handle.
+ *
+ * \return
+ * Size in bytes.
+ */
+uint64_t lvm_pv_get_size(const pv_t pv);
+
+/**
+ * Get the current unallocated space in bytes of a physical volume.
+ *
+ * \param   pv
+ * Physical volume handle.
+ *
+ * \return
+ * Free size in bytes.
+ */
+uint64_t lvm_pv_get_free(const pv_t pv);
+
+/**
  * Resize physical volume to new_size bytes.
  *
  * NOTE: This function is currently not implemented.
liblvm/lvm_pv.c +15 -0
index 8548597..a97f26f 100644
@@ -43,6 +43,21 @@ uint64_t lvm_pv_get_mda_count(const pv_t pv)
 	return (uint64_t) pv_mda_count(pv);
 }
 
+uint64_t lvm_pv_get_dev_size(const pv_t pv)
+{
+	return (uint64_t) SECTOR_SIZE*pv_dev_size(pv);
+}
+
+uint64_t lvm_pv_get_size(const pv_t pv)
+{
+	return (uint64_t) SECTOR_SIZE*pv_size_field(pv);
+}
+
+uint64_t lvm_pv_get_free(const pv_t pv)
+{
+	return (uint64_t) SECTOR_SIZE*pv_free(pv);
+}
+
 int lvm_pv_resize(const pv_t pv, uint64_t new_size)
 {
 	/* FIXME: add pv resize code here */
Signature · 1 line
1.6.0.6
#2 lore raw

PATCH 3/3 Update simple lvm2app unit test for new size apis.

---
 test/api/test.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
test/api/test.c +5 -2
index 308c867..6e222da 100644
@@ -450,8 +450,11 @@ static void _pvs_in_vg(char **argv, int argc)
 	}
 	printf("PVs in VG %s:\n", lvm_vg_get_name(vg));
 	dm_list_iterate_items(pvl, pvs) {
-		printf("%s (%s): mda_count=%"PRIu64"\n",
-		       lvm_pv_get_name(pvl->pv), lvm_pv_get_uuid(pvl->pv),
+		printf("%s (%s): size=%"PRIu64", free=%"PRIu64
+			", dev_size=%"PRIu64", mda_count=%"PRIu64"\n",
+			lvm_pv_get_name(pvl->pv), lvm_pv_get_uuid(pvl->pv),
+			lvm_pv_get_size(pvl->pv), lvm_pv_get_free(pvl->pv),
+			lvm_pv_get_dev_size(pvl->pv),
 			lvm_pv_get_mda_count(pvl->pv));
 	}
 }
Signature · 1 line
1.6.0.6