]> sourceware.org Git - lvm2.git/commitdiff
Add lvm_vg_list_{pvs|lvs} - return lists of pv/lv handles for a vg.
authorDave Wysochanski <dwysocha@redhat.com>
Thu, 23 Jul 2009 23:39:02 +0000 (23:39 +0000)
committerDave Wysochanski <dwysocha@redhat.com>
Thu, 23 Jul 2009 23:39:02 +0000 (23:39 +0000)
- 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>
liblvm/.exported_symbols
liblvm/lvm.h
liblvm/lvm_vg.c

index 3895c9d349bdd6d1ba88ef65319f91383b3939fd..ef5e9a5b0aa989861175ac7b145c6b9e47ae4186 100644 (file)
@@ -10,3 +10,5 @@ lvm_vg_close
 lvm_vg_remove
 lvm_errno
 lvm_errmsg
+lvm_vg_list_pvs
+lvm_vg_list_lvs
index 5df80d685697b1137223e775a212c490a2e2c0fd..bba97a48d6121fbd4661db8932d4e40c32cfbfbb 100644 (file)
@@ -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 */
index 99e0bbcc8cdb0356c4968d130fa5bb92a15ae4d4..30047f1de8a0c5fb3b65586c68ea26823704810b 100644 (file)
@@ -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;
+}
This page took 0.043432 seconds and 5 git commands to generate.