Skip to contentSkip to conversation

Add lvm {lv|pv}seg properties for lvm2app.

PATCH New Dave Wysochanski 1 participant 8 messages Nov 10, 2010

lore
Share & tools
lore
#0 lore raw

cover Add lvm {lv|pv}seg properties for lvm2app.

This patchset adds APIs covering pv and lv segments properties. New types are added which cover lists of lvsegs and pvsegs. Functions lvm_pv_list_pvsegs() and lvm_lv_list_lvsegs() are added which return a list of lvsegs and pvsegs, and lvm_{pv|lv}seg_get_property() functions are added to query the properties. Finally, interactive tests are updated to cover lvseg and pvseg properties.

All lvseg properties are covered by this patchset, with the exception of 'seg_pe_ranges' and 'devices'. All (2) pvseg properties are covered by this patchset.

This patchset enumerates lvsegs from an lv_t and pvsegs from a pv_t. The enumeration is consistent with other enumeration APIs already in lvm2app (lvm_vg_list_lvs, lvm_vg_list_pvs, etc).

This patchset should apply cleanly on upstream and finishes the properties patchset, with the exception of a couple specific 'get' functions for lvseg_t ('seg_pe_ranges' and 'devices') and lv_t ('snap_percent' and 'copy_percent').

#1 lore raw

PATCH 1/7 Add lvseg_t to lvm2app and lvm_lv_list_lvsegs().

From: Dave Wysochanski <[email protected]>

Add a new type and function to lvm2app to enumerate lvsegs.

---
 liblvm/lvm2app.h |   31 +++++++++++++++++++++++++++++++
 liblvm/lvm_lv.c  |   27 +++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 0 deletions(-)
liblvm/lvm2app.h +31 -0
index a5f65e9..82ed383 100644
@@ -95,6 +95,7 @@ struct lvm;
 struct physical_volume;
 struct volume_group;
 struct logical_volume;
+struct lv_segment;
 
 /**
  * \class lvm_t
@@ -137,6 +138,13 @@ typedef struct logical_volume *lv_t;
 typedef struct physical_volume *pv_t;
 
 /**
+ * \class lvseg_t
+ *
+ * This lv segment object is bound to a lv_t.
+ */
+typedef struct lv_segment *lvseg_t;
+
+/**
  * Logical Volume object list.
  *
  * Lists of these structures are returned by lvm_vg_list_lvs().
@@ -147,6 +155,16 @@ typedef struct lvm_lv_list {
 } lv_list_t;
 
 /**
+ * Logical Volume Segment object list.
+ *
+ * Lists of these structures are returned by lvm_lv_list_lvsegs().
+ */
+typedef struct lvm_lvseg_list {
+	struct dm_list list;
+	lvseg_t lvseg;
+} lvseg_list_t;
+
+/**
  * Physical volume object list.
  *
  * Lists of these structures are returned by lvm_vg_list_pvs().
@@ -936,6 +954,19 @@ struct lvm_property_value lvm_vg_get_property(const vg_t vg, const char *name);
 lv_t lvm_vg_create_lv_linear(vg_t vg, const char *name, uint64_t size);
 
 /**
+ * Return a list of lvseg handles for a given LV handle.
+ *
+ * \memberof lv_t
+ *
+ * \param   lv
+ * Logical volume handle.
+ *
+ * \return
+ * A list of lvm_lvseg_list structures containing lvseg handles for this lv.
+ */
+struct dm_list *lvm_lv_list_lvsegs(lv_t lv);
+
+/**
  * Activate a logical volume.
  *
  * \memberof lv_t
liblvm/lvm_lv.c +27 -0
index cef87f5..42982f9 100644
@@ -216,6 +216,33 @@ int lvm_lv_deactivate(lv_t lv)
 	return 0;
 }
 
+struct dm_list *lvm_lv_list_lvsegs(lv_t lv)
+{
+	struct dm_list *list;
+	lvseg_list_t *lvseg;
+	struct lv_segment *lvl;
+
+	if (dm_list_empty(&lv->segments))
+		return NULL;
+
+	if (!(list = dm_pool_zalloc(lv->vg->vgmem, sizeof(*list)))) {
+		log_errno(ENOMEM, "Memory allocation fail for dm_list.");
+		return NULL;
+	}
+	dm_list_init(list);
+
+	dm_list_iterate_items(lvl, &lv->segments) {
+		if (!(lvseg = dm_pool_zalloc(lv->vg->vgmem, sizeof(*lvseg)))) {
+			log_errno(ENOMEM,
+				"Memory allocation fail for lvm_lvseg_list.");
+			return NULL;
+		}
+		lvseg->lvseg = lvl;
+		dm_list_add(list, &lvseg->list);
+	}
+	return list;
+}
+
 int lvm_lv_resize(const lv_t lv, uint64_t new_size)
 {
 	/* FIXME: add lv resize code here */
Signature · 1 line
1.7.2.2
#2 lore raw

PATCH 2/7 Add lvseg internal library 'get' functions.

In reply to Dave Wysochanski

From: Dave Wysochanski <[email protected]>

Add the macro and specific 'get' functions for lvsegs.

---
 lib/metadata/lv.c       |   35 +++++++++++++++++++++++++++++++++++
 lib/metadata/lv.h       |    5 +++++
 lib/report/properties.c |   34 ++++++++++++++++++++++------------
 lib/report/properties.h |    2 ++
 lib/report/report.c     |   18 ++++++------------
 5 files changed, 70 insertions(+), 24 deletions(-)
lib/metadata/lv.c +35 -0
index 744b7b0..df132fe 100644
@@ -21,6 +21,41 @@
 #include "segtype.h"
 #include "str_list.h"
 
+char *lvseg_tags_dup(const struct lv_segment *seg)
+{
+	return tags_format_and_copy(seg->lv->vg->vgmem, &seg->tags);
+}
+
+char *lvseg_segtype_dup(const struct lv_segment *seg)
+{
+	if (seg->area_count == 1) {
+		return (char *)"linear";
+	}
+
+	return dm_pool_strdup(seg->lv->vg->vgmem, seg->segtype->ops->name(seg));
+}
+
+uint64_t lvseg_chunksize(const struct lv_segment *seg)
+{
+	uint64_t size;
+
+	if (lv_is_cow(seg->lv))
+		size = (uint64_t) find_cow(seg->lv)->chunk_size;
+	else
+		size = UINT64_C(0);
+	return size;
+}
+
+uint64_t lvseg_start(const struct lv_segment *seg)
+{
+	return (uint64_t) seg->le * seg->lv->vg->extent_size;
+}
+
+uint64_t lvseg_size(const struct lv_segment *seg)
+{
+	return (uint64_t) seg->len * seg->lv->vg->extent_size;
+}
+
 uint32_t lv_kernel_read_ahead(const struct logical_volume *lv)
 {
 	struct lvinfo info;
lib/metadata/lv.h +5 -0
index 48d5293..bff36d2 100644
@@ -63,5 +63,10 @@ char *lv_modules_dup(struct dm_pool *mem, const struct logical_volume *lv);
 char *lv_name_dup(struct dm_pool *mem, const struct logical_volume *lv);
 char *lv_origin_dup(struct dm_pool *mem, const struct logical_volume *lv);
 uint32_t lv_kernel_read_ahead(const struct logical_volume *lv);
+uint64_t lvseg_start(const struct lv_segment *seg);
+uint64_t lvseg_size(const struct lv_segment *seg);
+uint64_t lvseg_chunksize(const struct lv_segment *seg);
+char *lvseg_segtype_dup(const struct lv_segment *seg);
+char *lvseg_tags_dup(const struct lv_segment *seg);
 
 #endif /* _LVM_LV_H */
lib/report/properties.c +22 -12
index 339fd84..cb0beec 100644
@@ -34,6 +34,8 @@ static int _ ## NAME ## _get (const void *obj, struct lvm_property_type *prop) \
 	GET_NUM_PROPERTY_FN(NAME, VALUE, physical_volume, pv)
 #define GET_LV_NUM_PROPERTY_FN(NAME, VALUE) \
 	GET_NUM_PROPERTY_FN(NAME, VALUE, logical_volume, lv)
+#define GET_LVSEG_NUM_PROPERTY_FN(NAME, VALUE) \
+	GET_NUM_PROPERTY_FN(NAME, VALUE, lv_segment, lvseg)
 
 #define GET_STR_PROPERTY_FN(NAME, VALUE, TYPE, VAR)			\
 static int _ ## NAME ## _get (const void *obj, struct lvm_property_type *prop) \
@@ -49,6 +51,8 @@ static int _ ## NAME ## _get (const void *obj, struct lvm_property_type *prop) \
 	GET_STR_PROPERTY_FN(NAME, VALUE, physical_volume, pv)
 #define GET_LV_STR_PROPERTY_FN(NAME, VALUE) \
 	GET_STR_PROPERTY_FN(NAME, VALUE, logical_volume, lv)
+#define GET_LVSEG_STR_PROPERTY_FN(NAME, VALUE) \
+	GET_STR_PROPERTY_FN(NAME, VALUE, lv_segment, lvseg)
 
 static int _not_implemented_get(const void *obj, struct lvm_property_type *prop)
 {
@@ -187,29 +191,29 @@ GET_VG_NUM_PROPERTY_FN(vg_mda_copies, (vg_mda_copies(vg)))
 #define _vg_mda_copies_set _not_implemented_set
 
 /* LVSEG */
-#define _segtype_get _not_implemented_get
+GET_LVSEG_STR_PROPERTY_FN(segtype, lvseg_segtype_dup(lvseg))
 #define _segtype_set _not_implemented_set
-#define _stripes_get _not_implemented_get
+GET_LVSEG_NUM_PROPERTY_FN(stripes, lvseg->area_count)
 #define _stripes_set _not_implemented_set
-#define _stripesize_get _not_implemented_get
+GET_LVSEG_NUM_PROPERTY_FN(stripesize, lvseg->stripe_size)
 #define _stripesize_set _not_implemented_set
-#define _stripe_size_get _not_implemented_get
+GET_LVSEG_NUM_PROPERTY_FN(stripe_size, lvseg->stripe_size)
 #define _stripe_size_set _not_implemented_set
-#define _regionsize_get _not_implemented_get
+GET_LVSEG_NUM_PROPERTY_FN(regionsize, lvseg->region_size)
 #define _regionsize_set _not_implemented_set
-#define _region_size_get _not_implemented_get
+GET_LVSEG_NUM_PROPERTY_FN(region_size, lvseg->region_size)
 #define _region_size_set _not_implemented_set
-#define _chunksize_get _not_implemented_get
+GET_LVSEG_NUM_PROPERTY_FN(chunksize, lvseg_chunksize(lvseg))
 #define _chunksize_set _not_implemented_set
-#define _chunk_size_get _not_implemented_get
+GET_LVSEG_NUM_PROPERTY_FN(chunk_size, lvseg_chunksize(lvseg))
 #define _chunk_size_set _not_implemented_set
-#define _seg_start_get _not_implemented_get
+GET_LVSEG_NUM_PROPERTY_FN(seg_start, lvseg_start(lvseg))
 #define _seg_start_set _not_implemented_set
-#define _seg_start_pe_get _not_implemented_get
+GET_LVSEG_NUM_PROPERTY_FN(seg_start_pe, lvseg->le)
 #define _seg_start_pe_set _not_implemented_set
-#define _seg_size_get _not_implemented_get
+GET_LVSEG_NUM_PROPERTY_FN(seg_size, lvseg_size(lvseg))
 #define _seg_size_set _not_implemented_set
-#define _seg_tags_get _not_implemented_get
+GET_LVSEG_STR_PROPERTY_FN(seg_tags, lvseg_tags_dup(lvseg))
 #define _seg_tags_set _not_implemented_set
 #define _seg_pe_ranges_get _not_implemented_get
 #define _seg_pe_ranges_set _not_implemented_set
@@ -267,6 +271,12 @@ static int _get_property(const void *obj, struct lvm_property_type *prop,
 	return 1;
 }
 
+int lvseg_get_property(const struct lv_segment *lvseg,
+		       struct lvm_property_type *prop)
+{
+	return _get_property(lvseg, prop, SEGS);
+}
+
 int lv_get_property(const struct logical_volume *lv,
 		    struct lvm_property_type *prop)
 {
lib/report/properties.h +2 -0
index 054f400..361750f 100644
@@ -33,6 +33,8 @@ struct lvm_property_type {
 	int (*set) (void *obj, struct lvm_property_type *prop);
 };
 
+int lvseg_get_property(const struct lv_segment *lvseg,
+		       struct lvm_property_type *prop);
 int lv_get_property(const struct logical_volume *lv,
 		    struct lvm_property_type *prop);
 int vg_get_property(const struct volume_group *vg,
lib/report/report.c +6 -12
index 7a90b4d..837ef0b 100644
@@ -279,12 +279,9 @@ static int _segtype_disp(struct dm_report *rh __attribute__((unused)),
 {
 	const struct lv_segment *seg = (const struct lv_segment *) data;
 
-	if (seg->area_count == 1) {
-		dm_report_field_set_value(field, "linear", NULL);
-		return 1;
-	}
-
-	dm_report_field_set_value(field, seg->segtype->ops->name(seg), NULL);
+	char *name;
+	name = lvseg_segtype_dup(seg);
+	dm_report_field_set_value(field, name, NULL);
 	return 1;
 }
 
@@ -496,7 +493,7 @@ static int _segstart_disp(struct dm_report *rh, struct dm_pool *mem,
 	const struct lv_segment *seg = (const struct lv_segment *) data;
 	uint64_t start;
 
-	start = (uint64_t) seg->le * seg->lv->vg->extent_size;
+	start = lvseg_start(seg);
 
 	return _size64_disp(rh, mem, field, &start, private);
 }
@@ -519,7 +516,7 @@ static int _segsize_disp(struct dm_report *rh, struct dm_pool *mem,
 	const struct lv_segment *seg = (const struct lv_segment *) data;
 	uint64_t size;
 
-	size = (uint64_t) seg->len * seg->lv->vg->extent_size;
+	size = lvseg_size(seg);
 
 	return _size64_disp(rh, mem, field, &size, private);
 }
@@ -531,10 +528,7 @@ static int _chunksize_disp(struct dm_report *rh, struct dm_pool *mem,
 	const struct lv_segment *seg = (const struct lv_segment *) data;
 	uint64_t size;
 
-	if (lv_is_cow(seg->lv))
-		size = (uint64_t) find_cow(seg->lv)->chunk_size;
-	else
-		size = UINT64_C(0);
+	size = lvseg_chunksize(seg);
 
 	return _size64_disp(rh, mem, field, &size, private);
 }
Signature · 1 line
1.7.2.2
#3 lore raw

PATCH 3/7 Add lvm_lvseg_get_property() function.

In reply to Dave Wysochanski

From: Dave Wysochanski <[email protected]>

Add lvm2app function to query lvseg properties.

---
 liblvm/lvm2app.h  |   39 +++++++++++++++++++++++++++++++++++++++
 liblvm/lvm_lv.c   |    8 +++++++-
 liblvm/lvm_misc.c |    8 +++++++-
 liblvm/lvm_misc.h |    3 ++-
 liblvm/lvm_pv.c   |    2 +-
 liblvm/lvm_vg.c   |    2 +-
 6 files changed, 57 insertions(+), 5 deletions(-)
liblvm/lvm2app.h +39 -0
index 82ed383..744d343 100644
@@ -1102,6 +1102,45 @@ uint64_t lvm_lv_get_size(const lv_t lv);
 struct lvm_property_value lvm_lv_get_property(const lv_t lv, const char *name);
 
 /**
+ * Get the value of a LV segment property
+ *
+ * \memberof lv_t
+ *
+ * \param   lvseg
+ * Logical volume segment handle.
+ *
+ * \param   name
+ * Name of property to query.  See lvs man page for full list of properties
+ * that may be queried.
+ *
+ * The memory allocated for a string property value is tied to the vg_t
+ * handle and will be released when lvm_vg_close() is called.
+ *
+ * Example:
+ *      lvm_property_value v;
+ *      char *prop_name = "seg_start_pe";
+ *
+ *      v = lvm_lvseg_get_property(lvseg, prop_name);
+ *      if (lvm_errno(libh) || !v.is_valid) {
+ *           // handle error
+ *           printf("Invalid property name or unable to query"
+ *                  "'%s'.\n", prop_name);
+ *           return;
+ *      }
+ *      if (v.is_string)
+ *           printf(", value = %s\n", v.value.string);
+ *	else
+ *           printf(", value = %"PRIu64"\n", v.value.integer);
+ *
+ * \return
+ * lvm_property_value structure that will contain the current
+ * value of the property.  Caller should check lvm_errno() as well
+ * as 'is_valid' flag before using the value.
+ */
+struct lvm_property_value lvm_lvseg_get_property(const lvseg_t lvseg,
+						 const char *name);
+
+/**
  * Get the current activation state of a logical volume.
  *
  * \memberof lv_t
liblvm/lvm_lv.c +7 -1
index 42982f9..5d6f110 100644
@@ -50,7 +50,13 @@ const char *lvm_lv_get_name(const lv_t lv)
 
 struct lvm_property_value lvm_lv_get_property(const lv_t lv, const char *name)
 {
-	return get_property(NULL, NULL, lv, name);
+	return get_property(NULL, NULL, lv, NULL, name);
+}
+
+struct lvm_property_value lvm_lvseg_get_property(const lvseg_t lvseg,
+						 const char *name)
+{
+	return get_property(NULL, NULL, NULL, lvseg, name);
 }
 
 uint64_t lvm_lv_is_active(const lv_t lv)
liblvm/lvm_misc.c +7 -1
index adec2bc..f19efb2 100644
@@ -46,7 +46,8 @@ struct dm_list *tag_list_copy(struct dm_pool *p, struct dm_list *tag_list)
 }
 
 struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
-				       const lv_t lv, const char *name)
+				       const lv_t lv, const lvseg_t lvseg,
+				       const char *name)
 {
 	struct lvm_property_type prop;
 	struct lvm_property_value v;
@@ -67,6 +68,11 @@ struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
 			v.is_valid = 0;
 			return v;
 		}
+	} else if (lvseg) {
+		if (!lvseg_get_property(lvseg, &prop)) {
+			v.is_valid = 0;
+			return v;
+		}
 	}
 	v.is_settable = prop.is_settable;
 	v.is_string = prop.is_string;
liblvm/lvm_misc.h +2 -1
index b4e675e..918482e 100644
@@ -18,6 +18,7 @@
 
 struct dm_list *tag_list_copy(struct dm_pool *p, struct dm_list *tag_list);
 struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
-				       const lv_t lv, const char *name);
+				       const lv_t lv, const lvseg_t lvseg,
+				       const char *name);
 
 #endif
liblvm/lvm_pv.c +1 -1
index efdccb5..6705dd8 100644
@@ -51,7 +51,7 @@ uint64_t lvm_pv_get_free(const pv_t pv)
 
 struct lvm_property_value lvm_pv_get_property(const pv_t pv, const char *name)
 {
-	return get_property(pv, NULL, NULL, name);
+	return get_property(pv, NULL, NULL, NULL, name);
 }
 
 int lvm_pv_resize(const pv_t pv, uint64_t new_size)
liblvm/lvm_vg.c +1 -1
index 6970910..bc92ca2 100644
@@ -338,7 +338,7 @@ const char *lvm_vg_get_name(const vg_t vg)
 
 struct lvm_property_value lvm_vg_get_property(const vg_t vg, const char *name)
 {
-	return get_property(NULL, vg, NULL, name);
+	return get_property(NULL, vg, NULL, NULL, name);
 }
 
 struct dm_list *lvm_list_vg_names(lvm_t libh)
Signature · 1 line
1.7.2.2
#4 lore raw

PATCH 4/7 Add pvseg_t to lvm2app and lvm_pv_list_pvsegs().

In reply to Dave Wysochanski

Add a new type and function to lvm2app to enumerate pvsegs.

---
 liblvm/lvm2app.h |   31 +++++++++++++++++++++++++++++++
 liblvm/lvm_pv.c  |   27 +++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 0 deletions(-)
liblvm/lvm2app.h +31 -0
index 744d343..de6e8a3 100644
@@ -96,6 +96,7 @@ struct physical_volume;
 struct volume_group;
 struct logical_volume;
 struct lv_segment;
+struct pv_segment;
 
 /**
  * \class lvm_t
@@ -145,6 +146,13 @@ typedef struct physical_volume *pv_t;
 typedef struct lv_segment *lvseg_t;
 
 /**
+ * \class pvseg_t
+ *
+ * This pv segment object is bound to a pv_t.
+ */
+typedef struct pv_segment *pvseg_t;
+
+/**
  * Logical Volume object list.
  *
  * Lists of these structures are returned by lvm_vg_list_lvs().
@@ -175,6 +183,16 @@ typedef struct lvm_pv_list {
 } pv_list_t;
 
 /**
+ * Physical Volume Segment object list.
+ *
+ * Lists of these structures are returned by lvm_pv_list_pvsegs().
+ */
+typedef struct lvm_pvseg_list {
+	struct dm_list list;
+	pvseg_t pvseg;
+} pvseg_list_t;
+
+/**
  * String list.
  *
  * This string list contains read-only strings.
@@ -1389,6 +1407,19 @@ uint64_t lvm_pv_get_free(const pv_t pv);
 struct lvm_property_value lvm_pv_get_property(const pv_t pv, const char *name);
 
 /**
+ * Return a list of pvseg handles for a given PV handle.
+ *
+ * \memberof pv_t
+ *
+ * \param   pv
+ * Physical volume handle.
+ *
+ * \return
+ * A list of lvm_pvseg_list structures containing pvseg handles for this pv.
+ */
+struct dm_list *lvm_pv_list_pvsegs(pv_t pv);
+
+/**
  * Resize physical volume to new_size bytes.
  *
  * \memberof pv_t
liblvm/lvm_pv.c +27 -0
index 6705dd8..aaaca92 100644
@@ -54,6 +54,33 @@ struct lvm_property_value lvm_pv_get_property(const pv_t pv, const char *name)
 	return get_property(pv, NULL, NULL, NULL, name);
 }
 
+struct dm_list *lvm_pv_list_pvsegs(pv_t pv)
+{
+	struct dm_list *list;
+	pvseg_list_t *pvseg;
+	struct pv_segment *pvl;
+
+	if (dm_list_empty(&pv->segments))
+		return NULL;
+
+	if (!(list = dm_pool_zalloc(pv->vg->vgmem, sizeof(*list)))) {
+		log_errno(ENOMEM, "Memory allocation fail for dm_list.");
+		return NULL;
+	}
+	dm_list_init(list);
+
+	dm_list_iterate_items(pvl, &pv->segments) {
+		if (!(pvseg = dm_pool_zalloc(pv->vg->vgmem, sizeof(*pvseg)))) {
+			log_errno(ENOMEM,
+				"Memory allocation fail for lvm_pvseg_list.");
+			return NULL;
+		}
+		pvseg->pvseg = pvl;
+		dm_list_add(list, &pvseg->list);
+	}
+	return list;
+}
+
 int lvm_pv_resize(const pv_t pv, uint64_t new_size)
 {
 	/* FIXME: add pv resize code here */
Signature · 1 line
1.7.2.2
#5 lore raw

PATCH 5/7 Add pvseg internal library 'get' functions.

In reply to Dave Wysochanski

Add the macro and specific 'get' functions for pvsegs.

---
 lib/report/properties.c |   14 ++++++++++++--
 lib/report/properties.h |    2 ++
 2 files changed, 14 insertions(+), 2 deletions(-)
lib/report/properties.c +12 -2
index cb0beec..71f54bf 100644
@@ -36,6 +36,8 @@ static int _ ## NAME ## _get (const void *obj, struct lvm_property_type *prop) \
 	GET_NUM_PROPERTY_FN(NAME, VALUE, logical_volume, lv)
 #define GET_LVSEG_NUM_PROPERTY_FN(NAME, VALUE) \
 	GET_NUM_PROPERTY_FN(NAME, VALUE, lv_segment, lvseg)
+#define GET_PVSEG_NUM_PROPERTY_FN(NAME, VALUE) \
+	GET_NUM_PROPERTY_FN(NAME, VALUE, pv_segment, pvseg)
 
 #define GET_STR_PROPERTY_FN(NAME, VALUE, TYPE, VAR)			\
 static int _ ## NAME ## _get (const void *obj, struct lvm_property_type *prop) \
@@ -53,6 +55,8 @@ static int _ ## NAME ## _get (const void *obj, struct lvm_property_type *prop) \
 	GET_STR_PROPERTY_FN(NAME, VALUE, logical_volume, lv)
 #define GET_LVSEG_STR_PROPERTY_FN(NAME, VALUE) \
 	GET_STR_PROPERTY_FN(NAME, VALUE, lv_segment, lvseg)
+#define GET_PVSEG_STR_PROPERTY_FN(NAME, VALUE) \
+	GET_STR_PROPERTY_FN(NAME, VALUE, pv_segment, pvseg)
 
 static int _not_implemented_get(const void *obj, struct lvm_property_type *prop)
 {
@@ -222,9 +226,9 @@ GET_LVSEG_STR_PROPERTY_FN(seg_tags, lvseg_tags_dup(lvseg))
 
 
 /* PVSEG */
-#define _pvseg_start_get _not_implemented_get
+GET_PVSEG_NUM_PROPERTY_FN(pvseg_start, pvseg->pe)
 #define _pvseg_start_set _not_implemented_set
-#define _pvseg_size_get _not_implemented_get
+GET_PVSEG_NUM_PROPERTY_FN(pvseg_size, pvseg->len)
 #define _pvseg_size_set _not_implemented_set
 
 
@@ -289,6 +293,12 @@ int vg_get_property(const struct volume_group *vg,
 	return _get_property(vg, prop, VGS);
 }
 
+int pvseg_get_property(const struct pv_segment *pvseg,
+		       struct lvm_property_type *prop)
+{
+	return _get_property(pvseg, prop, PVSEGS);
+}
+
 int pv_get_property(const struct physical_volume *pv,
 		    struct lvm_property_type *prop)
 {
lib/report/properties.h +2 -0
index 361750f..20123b3 100644
@@ -39,6 +39,8 @@ int lv_get_property(const struct logical_volume *lv,
 		    struct lvm_property_type *prop);
 int vg_get_property(const struct volume_group *vg,
 		    struct lvm_property_type *prop);
+int pvseg_get_property(const struct pv_segment *pvseg,
+		       struct lvm_property_type *prop);
 int pv_get_property(const struct physical_volume *pv,
 		    struct lvm_property_type *prop);
 
Signature · 1 line
1.7.2.2
#6 lore raw

PATCH 6/7 Add lvm_pvseg_get_property() function.

In reply to Dave Wysochanski

Add lvm2app function to query pvseg properties.

---
 liblvm/lvm2app.h  |   39 +++++++++++++++++++++++++++++++++++++++
 liblvm/lvm_lv.c   |    4 ++--
 liblvm/lvm_misc.c |    7 ++++++-
 liblvm/lvm_misc.h |    2 +-
 liblvm/lvm_pv.c   |    8 +++++++-
 liblvm/lvm_vg.c   |    2 +-
 6 files changed, 56 insertions(+), 6 deletions(-)
liblvm/lvm2app.h +39 -0
index de6e8a3..90a89f5 100644
@@ -1407,6 +1407,45 @@ uint64_t lvm_pv_get_free(const pv_t pv);
 struct lvm_property_value lvm_pv_get_property(const pv_t pv, const char *name);
 
 /**
+ * Get the value of a PV segment property
+ *
+ * \memberof pv_t
+ *
+ * \param   pvseg
+ * Physical volume segment handle.
+ *
+ * \param   name
+ * Name of property to query.  See pvs man page for full list of properties
+ * that may be queried.
+ *
+ * The memory allocated for a string property value is tied to the vg_t
+ * handle and will be released when lvm_vg_close() is called.
+ *
+ * Example:
+ *      lvm_property_value v;
+ *      char *prop_name = "pvseg_start";
+ *
+ *      v = lvm_pvseg_get_property(pvseg, prop_name);
+ *      if (lvm_errno(libh) || !v.is_valid) {
+ *           // handle error
+ *           printf("Invalid property name or unable to query"
+ *                  "'%s'.\n", prop_name);
+ *           return;
+ *      }
+ *      if (v.is_string)
+ *           printf(", value = %s\n", v.value.string);
+ *	else
+ *           printf(", value = %"PRIu64"\n", v.value.integer);
+ *
+ * \return
+ * lvm_property_value structure that will contain the current
+ * value of the property.  Caller should check lvm_errno() as well
+ * as 'is_valid' flag before using the value.
+ */
+struct lvm_property_value lvm_pvseg_get_property(const pvseg_t pvseg,
+						 const char *name);
+
+/**
  * Return a list of pvseg handles for a given PV handle.
  *
  * \memberof pv_t
liblvm/lvm_lv.c +2 -2
index 5d6f110..ec5fec0 100644
@@ -50,13 +50,13 @@ const char *lvm_lv_get_name(const lv_t lv)
 
 struct lvm_property_value lvm_lv_get_property(const lv_t lv, const char *name)
 {
-	return get_property(NULL, NULL, lv, NULL, name);
+	return get_property(NULL, NULL, lv, NULL, NULL, name);
 }
 
 struct lvm_property_value lvm_lvseg_get_property(const lvseg_t lvseg,
 						 const char *name)
 {
-	return get_property(NULL, NULL, NULL, lvseg, name);
+	return get_property(NULL, NULL, NULL, lvseg, NULL, name);
 }
 
 uint64_t lvm_lv_is_active(const lv_t lv)
liblvm/lvm_misc.c +6 -1
index f19efb2..e3d9a5f 100644
@@ -47,7 +47,7 @@ struct dm_list *tag_list_copy(struct dm_pool *p, struct dm_list *tag_list)
 
 struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
 				       const lv_t lv, const lvseg_t lvseg,
-				       const char *name)
+				       const pvseg_t pvseg, const char *name)
 {
 	struct lvm_property_type prop;
 	struct lvm_property_value v;
@@ -73,6 +73,11 @@ struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
 			v.is_valid = 0;
 			return v;
 		}
+	} else if (pvseg) {
+		if (!pvseg_get_property(pvseg, &prop)) {
+			v.is_valid = 0;
+			return v;
+		}
 	}
 	v.is_settable = prop.is_settable;
 	v.is_string = prop.is_string;
liblvm/lvm_misc.h +1 -1
index 918482e..55775b0 100644
@@ -19,6 +19,6 @@
 struct dm_list *tag_list_copy(struct dm_pool *p, struct dm_list *tag_list);
 struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
 				       const lv_t lv, const lvseg_t lvseg,
-				       const char *name);
+				       const pvseg_t pvseg, const char *name);
 
 #endif
liblvm/lvm_pv.c +7 -1
index aaaca92..9ca92d5 100644
@@ -51,7 +51,13 @@ uint64_t lvm_pv_get_free(const pv_t pv)
 
 struct lvm_property_value lvm_pv_get_property(const pv_t pv, const char *name)
 {
-	return get_property(pv, NULL, NULL, NULL, name);
+	return get_property(pv, NULL, NULL, NULL, NULL, name);
+}
+
+struct lvm_property_value lvm_pvseg_get_property(const pvseg_t pvseg,
+						 const char *name)
+{
+	return get_property(NULL, NULL, NULL, NULL, pvseg, name);
 }
 
 struct dm_list *lvm_pv_list_pvsegs(pv_t pv)
liblvm/lvm_vg.c +1 -1
index bc92ca2..e9fb959 100644
@@ -338,7 +338,7 @@ const char *lvm_vg_get_name(const vg_t vg)
 
 struct lvm_property_value lvm_vg_get_property(const vg_t vg, const char *name)
 {
-	return get_property(NULL, vg, NULL, NULL, name);
+	return get_property(NULL, vg, NULL, NULL, NULL, name);
 }
 
 struct dm_list *lvm_list_vg_names(lvm_t libh)
Signature · 1 line
1.7.2.2
#7 lore raw

PATCH 7/7 Update tests for lvseg and pvseg apis.

In reply to Dave Wysochanski

From: Dave Wysochanski <[email protected]>

Update interactive tests for lvm2app lvseg and pvseg apis.

---
 test/api/test.c |  124 +++++++++++++++++++++++++++++++++----------------------
 1 files changed, 75 insertions(+), 49 deletions(-)
test/api/test.c +75 -49
index fea3d0d..bfe32b7 100644
@@ -67,8 +67,12 @@ static void _show_help(void)
 	       "List the uuids of the VGs that exist in the system\n");
 	printf("'vg_list_pvs vgname': "
 	       "List the PVs that exist in VG vgname\n");
+	printf("'pv_list_pvsegs pvname': "
+	       "List the PV segments that exist in PV pvname\n");
 	printf("'vg_list_lvs vgname': "
 	       "List the LVs that exist in VG vgname\n");
+	printf("'lv_list_lvsegs vgname lvname': "
+	       "List the LV segments that exist in LV vgname/lvname\n");
 	printf("'vgs_open': "
 	       "List the VGs that are currently open\n");
 	printf("'vgs': "
@@ -187,17 +191,13 @@ static vg_t _lookup_vg_by_name(char **argv, int argc)
 	return vg;
 }
 
-static pv_t _lookup_pv_by_name(char **argv, int argc)
+static pv_t _lookup_pv_by_name(const char *name)
 {
 	pv_t pv;
 
-	if (argc < 2) {
-		printf ("Please enter vg_name\n");
-		return NULL;
-	}
-	if (!(pv = dm_hash_lookup(_pvname_hash, argv[1]))) {
+	if (!(pv = dm_hash_lookup(_pvname_hash, name))) {
 		printf ("Can't find %s in open PVs - run vg_open first\n",
-			argv[1]);
+			name);
 		return NULL;
 	}
 	return pv;
@@ -236,6 +236,7 @@ static void _add_device_to_pvname_hash(struct dm_list *pvs, const char *name)
 			dm_hash_insert(_pvname_hash, name, pvl->pv);
 	}
 }
+
 static void _vg_reduce(char **argv, int argc, lvm_t libh)
 {
 	vg_t vg;
@@ -494,6 +495,40 @@ static void _pvs_in_vg(char **argv, int argc)
 	}
 }
 
+static void _print_property_value(const char *name,
+				  struct lvm_property_value v)
+{
+	if (!v.is_valid)
+		printf("%s = INVALID\n", name);
+	else if (v.is_string)
+		printf("%s = %s\n", name, v.value.string);
+	else
+		printf("%s = %"PRIu64"\n", name, v.value.integer);
+}
+
+static void _pvsegs_in_pv(char **argv, int argc)
+{
+	struct dm_list *pvsegs;
+	struct lvm_pvseg_list *pvl;
+	pv_t pv;
+
+	if (!(pv = _lookup_pv_by_name(argv[1])))
+		return;
+	pvsegs = lvm_pv_list_pvsegs(pv);
+	if (!pvsegs || dm_list_empty(pvsegs)) {
+		printf("No PV segments in pv %s\n", argv[1]);
+		return;
+	}
+	printf("PV segments in pv %s:\n", argv[1]);
+	dm_list_iterate_items(pvl, pvsegs) {
+		struct lvm_property_value v;
+		v = lvm_pvseg_get_property(pvl->pvseg, "pvseg_start");
+		_print_property_value("pvseg_start", v);
+		v = lvm_pvseg_get_property(pvl->pvseg, "pvseg_size");
+		_print_property_value("pvseg_size", v);
+	}
+}
+
 static void _scan_vgs(lvm_t libh)
 {
 	lvm_scan(libh);
@@ -569,14 +604,6 @@ static void _vg_tag(char **argv, int argc, int add)
 	       add ? "adding":"removing", argv[2], argv[1]);
 }
 
-static void _print_property_value(struct lvm_property_value value)
-{
-	if (value.is_string)
-		printf(", value = %s\n", value.value.string);
-	else
-		printf(", value = %"PRIu64"\n", value.value.integer);
-}
-
 static void _pv_get_property(char **argv, int argc)
 {
 	pv_t pv;
@@ -586,20 +613,10 @@ static void _pv_get_property(char **argv, int argc)
 		printf("Please enter pvname, field_id\n");
 		return;
 	}
-	if (!(pv = _lookup_pv_by_name(argv, argc)))
+	if (!(pv = _lookup_pv_by_name(argv[1])))
 		return;
 	v = lvm_pv_get_property(pv, argv[2]);
-	if (!v.is_valid)
-		printf("Error ");
-	else
-		printf("Success ");
-	printf("obtaining value of property %s in PV %s",
-	       argv[2], argv[1]);
-	if (!v.is_valid) {
-		printf("\n");
-		return;
-	}
-	_print_property_value(v);
+	_print_property_value(argv[2], v);
 }
 
 static void _vg_get_property(char **argv, int argc)
@@ -614,17 +631,7 @@ static void _vg_get_property(char **argv, int argc)
 	if (!(vg = _lookup_vg_by_name(argv, argc)))
 		return;
 	v =  lvm_vg_get_property(vg, argv[2]);
-	if (!v.is_valid)
-		printf("Error ");
-	else
-		printf("Success ");
-	printf("obtaining value of property %s in VG %s",
-	       argv[2], argv[1]);
-	if (!v.is_valid) {
-		printf("\n");
-		return;
-	}
-	_print_property_value(v);
+	_print_property_value(argv[2], v);
 }
 
 static void _lv_get_property(char **argv, int argc)
@@ -639,17 +646,7 @@ static void _lv_get_property(char **argv, int argc)
 	if (!(lv = _lookup_lv_by_name(argv[2])))
 		return;
 	v = lvm_lv_get_property(lv, argv[3]);
-	if (!v.is_valid)
-		printf("Error ");
-	else
-		printf("Success ");
-	printf("obtaining value of property %s in LV %s",
-	       argv[3], argv[2]);
-	if (!v.is_valid) {
-		printf("\n");
-		return;
-	}
-	_print_property_value(v);
+	_print_property_value(argv[3], v);
 }
 
 static void _lv_get_tags(char **argv, int argc)
@@ -742,6 +739,31 @@ static void _lvs_in_vg(char **argv, int argc)
 	}
 }
 
+static void _lvsegs_in_lv(char **argv, int argc)
+{
+	struct dm_list *lvsegs;
+	struct lvm_lvseg_list *lvl;
+	lv_t lv;
+
+	if (!(lv = _lookup_lv_by_name(argv[2])))
+		return;
+	lvsegs = lvm_lv_list_lvsegs(lv);
+	if (!lvsegs || dm_list_empty(lvsegs)) {
+		printf("No LV segments in lv %s\n", lvm_lv_get_name(lv));
+		return;
+	}
+	printf("LV segments in lv %s:\n", lvm_lv_get_name(lv));
+	dm_list_iterate_items(lvl, lvsegs) {
+		struct lvm_property_value v;
+		v = lvm_lvseg_get_property(lvl->lvseg, "segtype");
+		_print_property_value("segtype", v);
+		v = lvm_lvseg_get_property(lvl->lvseg, "seg_start_pe");
+		_print_property_value("seg_start_pe", v);
+		v = lvm_lvseg_get_property(lvl->lvseg, "seg_size");
+		_print_property_value("seg_size", v);
+	}
+}
+
 static void _lv_deactivate(char **argv, int argc)
 {
 	lv_t lv;
@@ -886,8 +908,12 @@ static int lvmapi_test_shell(lvm_t libh)
 			_list_open_vgs();
 		} else if (!strcmp(argv[0], "vg_list_pvs")) {
 			_pvs_in_vg(argv, argc);
+		} else if (!strcmp(argv[0], "pv_list_pvsegs")) {
+			_pvsegs_in_pv(argv, argc);
 		} else if (!strcmp(argv[0], "vg_list_lvs")) {
 			_lvs_in_vg(argv, argc);
+		} else if (!strcmp(argv[0], "lv_list_lvsegs")) {
+			_lvsegs_in_lv(argv, argc);
 		} else if (!strcmp(argv[0], "list_vg_names")) {
 			_list_vg_names(libh);
 		} else if (!strcmp(argv[0], "list_vg_ids")) {
Signature · 1 line
1.7.2.2