Skip to contentSkip to conversation

Add most all liblvm 'get' functions needed for anaconda.

PATCH New Dave Wysochanski 1 participant 2 messages Jul 26, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add most all liblvm 'get' functions needed for anaconda.

Add the most straightforward 'get' functions required for anaconda. These are the ones that return simple uint64_t values.
The other more complex ones involve the lv_attr bits. These will come in a separate patch series since each lv_attr bit will be returned in a separate API instred of returning the string and requiring the user to parse it.

---
 liblvm/lvm.h    |   15 +++++++++++++++
 liblvm/lvm_lv.c |    3 +++
 liblvm/lvm_pv.c |   11 +++++++++++
 liblvm/lvm_vg.c |   20 ++++++++++++++++++++
 4 files changed, 49 insertions(+), 0 deletions(-)
liblvm/lvm.h +15 -0
index f2080f7..a39f198 100644
@@ -243,6 +243,21 @@ char *lvm_vg_get_name(const vg_t *vg);
 char *lvm_lv_get_name(const lv_t *lv);
 
 /**
+ * Get various pv, vg, or lv properties.
+ * For full description of each property, consult the man pages for pvs,
+ * vgs, and lvs.
+ * FIXME: What value to return for invalid handle or other errors?
+ */
+uint64_t lvm_pv_get_mda_count(const pv_t *pv);
+uint64_t lvm_vg_get_size(const vg_t *vg);
+uint64_t lvm_vg_get_free(const vg_t *vg);
+uint64_t lvm_vg_get_extent_size(const vg_t *vg);
+uint64_t lvm_vg_get_extent_count(const vg_t *vg);
+uint64_t lvm_vg_get_free_count(const vg_t *vg);
+uint64_t lvm_vg_get_pv_count(const vg_t *vg);
+uint64_t lvm_lv_get_size(const lv_t *lv);
+
+/**
  * Close a VG opened with lvm_vg_create
  *
  * This API releases a VG handle and any resources associated with the handle.
liblvm/lvm_lv.c +3 -0
index e914d6c..5b1b213 100644
@@ -20,6 +20,9 @@
 #include "segtype.h"
 #include <string.h>
 
+inline uint64_t lvm_lv_get_size(const lv_t *lv)
+{ return (uint64_t) lv->size; }
+
 char *lvm_lv_get_uuid(const lv_t *lv)
 {
 	char uuid[64] __attribute((aligned(8)));
liblvm/lvm_pv.c +11 -0
index 0618a84..19d0ce6 100644
@@ -16,6 +16,8 @@
 #include "lvm.h"
 #include "metadata-exported.h"
 #include "lvm-string.h"
+#include "uuid.h"
+#include "lvmcache.h"
 
 char *lvm_pv_get_uuid(const pv_t *pv)
 {
@@ -38,3 +40,12 @@ char *lvm_pv_get_name(const pv_t *pv)
 	return name;
 }
 
+/* FIXME: have pvmdas_disp call this function */
+uint64_t lvm_pv_get_mda_count(const pv_t *pv)
+{
+	struct lvmcache_info *info;
+	const char *pvid = (const char *)pv->id.uuid;
+
+	info = info_from_pvid(pvid, 0);
+	return info ? dm_list_size(&info->mdas) : UINT64_C(0);
+}
liblvm/lvm_vg.c +20 -0
index bd6b36d..e64e3f9 100644
@@ -194,6 +194,26 @@ struct dm_list *lvm_vg_list_lvs(vg_t *vg)
 	return list;
 }
 
+/* FIXME: have *_disp functions from report.c call these functions */
+/* FIXME: invalid handle? return INTMAX? */
+inline uint64_t lvm_vg_get_size(const vg_t *vg)
+{ return (uint64_t) vg->extent_count * vg->extent_size; }
+
+inline uint64_t lvm_vg_get_free(const vg_t *vg)
+{ return (uint64_t) vg->free_count * vg->extent_size; }
+
+inline uint64_t lvm_vg_get_extent_size(const vg_t *vg)
+{ return (uint64_t) vg->extent_size; }
+
+inline uint64_t lvm_vg_get_extent_count(const vg_t *vg)
+{ return (uint64_t) vg->extent_count; }
+
+inline uint64_t lvm_vg_get_free_count(const vg_t *vg)
+{ return (uint64_t) vg->free_count; }
+
+inline uint64_t lvm_vg_get_pv_count(const vg_t *vg)
+{ return (uint64_t) vg->pv_count; }
+
 char *lvm_vg_get_uuid(const vg_t *vg)
 {
 	char uuid[64] __attribute((aligned(8)));
Signature · 1 line
1.6.0.6
#1 lore raw

PATCH 1/1 Add lvm_vg_remove_lv liblvm function.

Add a very simple version of lvm_vg_remove_lv.
Since we currently can only create linear LVs, this simple remove function is adequate. We must refactor lvremove_single a bit.

---
 liblvm/.exported_symbols |    1 +
 liblvm/lvm.h             |   11 +++++++++++
 liblvm/lvm_lv.c          |    6 ++++++
 3 files changed, 18 insertions(+), 0 deletions(-)
liblvm/.exported_symbols +1 -0
index 3d42cc7..eb3aee9 100644
@@ -22,3 +22,4 @@ lvm_vg_list_lvs
 lvm_list_vg_names
 lvm_list_vg_ids
 lvm_vg_create_lv_linear
+lvm_vg_remove_lv
liblvm/lvm.h +11 -0
index a39f198..2bb36ee 100644
@@ -117,6 +117,17 @@ int lvm_reload_config(lvm_t libh);
 lv_t *lvm_vg_create_lv_linear(vg_t *vg, const char *name, uint64_t size);
 
 /**
+ * Remove a logical volume from a volume group.
+ * This API commits the change to disk and does _not_ require calling
+ * lvm_vg_write.
+ * Currently only removing linear LVs are possible.
+ *
+ * FIXME: This API should probably not commit to disk but require calling
+ * lvm_vg_write.
+ */
+int lvm_vg_remove_lv(lv_t *lv);
+
+/**
  * Return stored error no describing last LVM API error.
  *
  * Users of liblvm should use lvm_errno to determine success or failure
liblvm/lvm_lv.c +6 -0
index 5b1b213..a0ee136 100644
@@ -93,3 +93,9 @@ lv_t *lvm_vg_create_lv_linear(vg_t *vg, const char *name, uint64_t size)
 	return lvl->lv;
 }
 
+int lvm_vg_remove_lv(lv_t *lv)
+{
+	if (!lv || !lv->vg || vg_read_error(lv->vg))
+		return 0;
+	return lv_remove_single(lv->vg->cmd, lv, DONT_PROMPT);
+}
Signature · 1 line
1.6.0.6