]> sourceware.org Git - lvm2.git/commitdiff
Add lvm_vg_get_property() generic vg property function.
authorDave Wysochanski <dwysocha@redhat.com>
Mon, 25 Oct 2010 14:08:43 +0000 (14:08 +0000)
committerDave Wysochanski <dwysocha@redhat.com>
Mon, 25 Oct 2010 14:08:43 +0000 (14:08 +0000)
Add a generic VG property function to lvm2app.  Call the internal library
vg_get_property() function.  Strings are dup'd internally.
Rework lvm_vg_get_property to return lvm_property_value and require caller
to check 'is_valid' flag.  If !is_valid, the caller can check lvm_errno()
for the specific error.

Create a 'get_property' function, local to lvm2app, that factors out
most of the common code that copies the components of lvm_property_type
into lvm_property_value.  This allows for a 1-line function for each
of the generic property functions exported by lvm2app.

liblvm/lvm2app.h
liblvm/lvm_misc.c
liblvm/lvm_misc.h
liblvm/lvm_vg.c

index 47d34176c20c8a89a8475c634418648bfc0e613a..90a7d42b413bd2115cb7d5f9206bf9028e4c6ef9 100644 (file)
@@ -139,7 +139,7 @@ typedef struct physical_volume *pv_t;
 /**
  * Logical Volume object list.
  *
- * Lists of these structures are returned by lvm_vg_list_pvs().
+ * Lists of these structures are returned by lvm_vg_list_lvs().
  */
 typedef struct lvm_lv_list {
        struct dm_list list;
@@ -168,6 +168,30 @@ typedef struct lvm_str_list {
        const char *str;
 } lvm_str_list_t;
 
+/**
+ * Property Value
+ *
+ * This structure defines a single LVM property value for an LVM object.
+ * The structures are returned by functions such as
+ * lvm_vg_get_property().
+ *
+ * is_settable: indicates whether a 'set' function exists for this property
+ * is_string: indicates whether this property is a string (1) or not (0)
+ * is_integer: indicates whether this property is an integer (1) or not (0)
+ * is_valid: indicates whether 'value' is valid (1) or not (0)
+ */
+typedef struct lvm_property_value {
+       uint32_t is_settable:1;
+       uint32_t is_string:1;
+       uint32_t is_integer:1;
+       uint32_t is_valid:1;
+       uint32_t padding:28;
+       union {
+               const char *string;
+               uint64_t integer;
+       } value;
+} lvm_property_value_t;
+
 /*************************** generic lvm handling ***************************/
 /**
  * Create a LVM handle.
@@ -848,6 +872,45 @@ uint64_t lvm_vg_get_max_lv(const vg_t vg);
  */
 struct dm_list *lvm_vg_get_tags(const vg_t vg);
 
+/**
+ * Get the value of a VG property
+ *
+ * \memberof vg_t
+ *
+ * \param   vg
+ * VG handle obtained from lvm_vg_create() or lvm_vg_open().
+ *
+ * \param   name
+ * Name of property to query.  See vgs 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 = "vg_mda_count";
+ *
+ *      v = lvm_vg_get_property(vg, prop_name);
+ *      if (!v.is_valid) {
+ *           printf("Invalid property name or unable to query"
+ *                  "'%s', errno = %d.\n", prop_name, lvm_errno(libh));
+ *           return;
+ *      }
+ *      if (v.is_string)
+ *           printf(", value = %s\n", v.value.string);
+ *     if (v.is_integer)
+ *           printf(", value = %"PRIu64"\n", v.value.integer);
+ *
+ *
+ * \return
+ * lvm_property_value structure that will contain the current
+ * value of the property.  Caller should check 'is_valid' flag before using
+ * the value.  If 'is_valid' is not set, caller should check lvm_errno()
+ * for specific error.
+ */
+struct lvm_property_value lvm_vg_get_property(const vg_t vg, const char *name);
+
 /************************** logical volume handling *************************/
 
 /**
index e339faab24fcd2d1cb2259ad050fb6c1a43bcdb1..adec2bc5780fd8fdf9170d4f54e1d36bfb10e54d 100644 (file)
@@ -15,6 +15,7 @@
 #include "lvm2app.h"
 #include "lvm_misc.h"
 #include "lib.h"
+#include "properties.h"
 
 struct dm_list *tag_list_copy(struct dm_pool *p, struct dm_list *tag_list)
 {
@@ -43,3 +44,37 @@ struct dm_list *tag_list_copy(struct dm_pool *p, struct dm_list *tag_list)
        }
        return list;
 }
+
+struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
+                                      const lv_t lv, const char *name)
+{
+       struct lvm_property_type prop;
+       struct lvm_property_value v;
+
+       prop.id = name;
+       if (pv) {
+               if (!pv_get_property(pv, &prop)) {
+                       v.is_valid = 0;
+                       return v;
+               }
+       } else if (vg) {
+               if (!vg_get_property(vg, &prop)) {
+                       v.is_valid = 0;
+                       return v;
+               }
+       } else if (lv) {
+               if (!lv_get_property(lv, &prop)) {
+                       v.is_valid = 0;
+                       return v;
+               }
+       }
+       v.is_settable = prop.is_settable;
+       v.is_string = prop.is_string;
+       v.is_integer = prop.is_integer;
+       if (v.is_string)
+               v.value.string = prop.value.string;
+       if (v.is_integer)
+               v.value.integer = prop.value.integer;
+       v.is_valid = 1;
+       return v;
+}
index ced1f0f0904b320f81c1ddde186026d5ced2984b..b4e675eb5c06ede64ebc681fdafcd8887f53b8e7 100644 (file)
@@ -17,5 +17,7 @@
 #include "libdevmapper.h"
 
 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);
 
 #endif
index a09208acb222206d58144f1a1f7e4c2db9df9974..6970910be7f2f90d9dcddb67279a56aab68a9fe8 100644 (file)
@@ -335,6 +335,12 @@ const char *lvm_vg_get_name(const vg_t vg)
        return dm_pool_strndup(vg->vgmem, (const char *)vg->name, NAME_LEN+1);
 }
 
+
+struct lvm_property_value lvm_vg_get_property(const vg_t vg, const char *name)
+{
+       return get_property(NULL, vg, NULL, name);
+}
+
 struct dm_list *lvm_list_vg_names(lvm_t libh)
 {
        return get_vgnames((struct cmd_context *)libh, 0);
This page took 0.035675 seconds and 5 git commands to generate.