summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Wysochanski <dwysocha@redhat.com>2009-07-23 23:39:02 +0000
committerDave Wysochanski <dwysocha@redhat.com>2009-07-23 23:39:02 +0000
commit6c6c821445da7c4b490d62c23cf96497ecf87cdb (patch)
tree64dd8914c457baf3fb475e0f4819543849462c2c
parent357ed599ec4b3a6000cecb305192d453b92c86c7 (diff)
downloadlvm2-6c6c821445da7c4b490d62c23cf96497ecf87cdb.tar.gz
lvm2-6c6c821445da7c4b490d62c23cf96497ecf87cdb.tar.xz
lvm2-6c6c821445da7c4b490d62c23cf96497ecf87cdb.zip
Add lvm_vg_list_{pvs|lvs} - return lists of pv/lv handles for a vg.
- Use vgmem pool to allocate a list of lvm_*_list structs - Allocate a new list each call (list may have changed since last call) - Add to liblvm's exported symbols Signed-off-by: Dave Wysochanski <dwysocha@redhat.com> Acked-by: Thomas Woerner <twoerner@redhat.com>
-rw-r--r--liblvm/.exported_symbols2
-rw-r--r--liblvm/lvm.h15
-rw-r--r--liblvm/lvm_vg.c52
3 files changed, 69 insertions, 0 deletions
diff --git a/liblvm/.exported_symbols b/liblvm/.exported_symbols
index 3895c9d3..ef5e9a5b 100644
--- a/liblvm/.exported_symbols
+++ b/liblvm/.exported_symbols
@@ -10,3 +10,5 @@ lvm_vg_close
lvm_vg_remove
lvm_errno
lvm_errmsg
+lvm_vg_list_pvs
+lvm_vg_list_lvs
diff --git a/liblvm/lvm.h b/liblvm/lvm.h
index 5df80d68..bba97a48 100644
--- a/liblvm/lvm.h
+++ b/liblvm/lvm.h
@@ -44,6 +44,13 @@ typedef struct lvm_lv_list {
lv_t *lv;
} lv_list_t;
+/**
+ * Return a list of LV handles for a given VG handle.
+ *
+ * \return A list of lv_list_t structures containing lv handles for this vg.
+ * If no LVs exist on the given VG, NULL is returned.
+ */
+struct dm_list *lvm_vg_list_lvs(vg_t *vg);
struct lvm; /* internal data */
@@ -225,4 +232,12 @@ int lvm_vg_close(vg_t *vg);
vg_t *lvm_vg_open(lvm_t libh, const char *vgname, const char *mode,
uint32_t flags);
+/**
+ * Return a list of PV handles for a given VG handle.
+ *
+ * \return A list of pv_list_t structures containing pv handles for this vg.
+ * If no PVs exist on the given VG, NULL is returned.
+ */
+struct dm_list *lvm_vg_list_pvs(vg_t *vg);
+
#endif /* _LIB_LVM_H */
diff --git a/liblvm/lvm_vg.c b/liblvm/lvm_vg.c
index 99e0bbcc..30047f1d 100644
--- a/liblvm/lvm_vg.c
+++ b/liblvm/lvm_vg.c
@@ -114,3 +114,55 @@ vg_t *lvm_vg_open(lvm_t libh, const char *vgname, const char *mode,
return vg;
}
+
+struct dm_list *lvm_vg_list_pvs(vg_t *vg)
+{
+ struct dm_list *list;
+ pv_list_t *pvs;
+ struct pv_list *pvl;
+
+ if (dm_list_empty(&vg->pvs))
+ return NULL;
+
+ if (!(list = dm_pool_zalloc(vg->vgmem, sizeof(*list)))) {
+ log_error("Memory allocation fail for dm_list.\n");
+ return NULL;
+ }
+ dm_list_init(list);
+
+ dm_list_iterate_items(pvl, &vg->pvs) {
+ if (!(pvs = dm_pool_zalloc(vg->vgmem, sizeof(*pvs)))) {
+ log_error("Memory allocation fail for lvm_pv_list.\n");
+ return NULL;
+ }
+ pvs->pv = pvl->pv;
+ dm_list_add(list, &pvs->list);
+ }
+ return list;
+}
+
+struct dm_list *lvm_vg_list_lvs(vg_t *vg)
+{
+ struct dm_list *list;
+ lv_list_t *lvs;
+ struct lv_list *lvl;
+
+ if (dm_list_empty(&vg->lvs))
+ return NULL;
+
+ if (!(list = dm_pool_zalloc(vg->vgmem, sizeof(*list)))) {
+ log_error("Memory allocation fail for dm_list.\n");
+ return NULL;
+ }
+ dm_list_init(list);
+
+ dm_list_iterate_items(lvl, &vg->lvs) {
+ if (!(lvs = dm_pool_zalloc(vg->vgmem, sizeof(*lvs)))) {
+ log_error("Memory allocation fail for lvm_lv_list.\n");
+ return NULL;
+ }
+ lvs->lv = lvl->lv;
+ dm_list_add(list, &lvs->list);
+ }
+ return list;
+}