From: Petr Rockai Date: Thu, 25 Nov 2010 14:33:44 +0000 (+0000) Subject: This patch adds helpers to allow users to lookup a lv or pv handle by X-Git-Tag: v2_02_78~45 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=2ac0e8f989c430a5d7f51390c6774808521292cf;p=lvm2.git This patch adds helpers to allow users to lookup a lv or pv handle by name (given a vg_t of course). Signed-off-by: Dave Wysochanski Reviewed-by: Petr Rockai --- diff --git a/liblvm/lvm2app.h b/liblvm/lvm2app.h index d6378ac4f..4750211be 100644 --- a/liblvm/lvm2app.h +++ b/liblvm/lvm2app.h @@ -1014,6 +1014,23 @@ lv_t lvm_vg_create_lv_linear(vg_t vg, const char *name, uint64_t size); */ struct dm_list *lvm_lv_list_lvsegs(lv_t lv); +/** + * Lookup an LV handle in a VG by the LV name. + * + * \memberof lv_t + * + * \param vg + * VG handle obtained from lvm_vg_create() or lvm_vg_open(). + * + * \param name + * Name of LV to lookup. + * + * \return + * non-NULL handle to the LV 'name' attached to the VG. + * NULL is returned if the LV name is not associated with the VG handle. + */ +lv_t lvm_lv_from_name(vg_t vg, const char *name); + /** * Activate a logical volume. * @@ -1488,6 +1505,23 @@ struct lvm_property_value lvm_pvseg_get_property(const pvseg_t pvseg, */ struct dm_list *lvm_pv_list_pvsegs(pv_t pv); +/** + * Lookup an PV handle in a VG by the PV name. + * + * \memberof pv_t + * + * \param vg + * VG handle obtained from lvm_vg_create() or lvm_vg_open(). + * + * \param name + * Name of PV to lookup. + * + * \return + * non-NULL handle to the PV 'name' attached to the VG. + * NULL is returned if the PV name is not associated with the VG handle. + */ +pv_t lvm_pv_from_name(vg_t vg, const char *name); + /** * Resize physical volume to new_size bytes. * diff --git a/liblvm/lvm_lv.c b/liblvm/lvm_lv.c index 432f5b779..5e8322f16 100644 --- a/liblvm/lvm_lv.c +++ b/liblvm/lvm_lv.c @@ -249,6 +249,17 @@ struct dm_list *lvm_lv_list_lvsegs(lv_t lv) return list; } +lv_t lvm_lv_from_name(vg_t vg, const char *name) +{ + struct lv_list *lvl; + + dm_list_iterate_items(lvl, &vg->lvs) { + if (!strcmp(name, lvl->lv->name)) + return lvl->lv; + } + return NULL; +} + int lvm_lv_resize(const lv_t lv, uint64_t new_size) { /* FIXME: add lv resize code here */ diff --git a/liblvm/lvm_pv.c b/liblvm/lvm_pv.c index 9ca92d540..3372fdec0 100644 --- a/liblvm/lvm_pv.c +++ b/liblvm/lvm_pv.c @@ -87,6 +87,18 @@ struct dm_list *lvm_pv_list_pvsegs(pv_t pv) return list; } +pv_t lvm_pv_from_name(vg_t vg, const char *name) +{ + struct pv_list *pvl; + + dm_list_iterate_items(pvl, &vg->pvs) { + if (!strcmp(name, pv_dev_name(pvl->pv))) + return pvl->pv; + } + return NULL; +} + + int lvm_pv_resize(const pv_t pv, uint64_t new_size) { /* FIXME: add pv resize code here */