summaryrefslogtreecommitdiffstats
path: root/liblvm
diff options
context:
space:
mode:
authorPetr Rockai <prockai@redhat.com>2010-11-25 14:34:51 +0000
committerPetr Rockai <prockai@redhat.com>2010-11-25 14:34:51 +0000
commit5219fe3ca853348b588aff9666c83d15acb66b65 (patch)
treed84f2d15a9409467b0944d1c83473d3b362ed099 /liblvm
parent14b0c96bc72cfd08daf00cb1395fd04446c22d71 (diff)
downloadlvm2-5219fe3ca853348b588aff9666c83d15acb66b65.tar.gz
lvm2-5219fe3ca853348b588aff9666c83d15acb66b65.tar.xz
lvm2-5219fe3ca853348b588aff9666c83d15acb66b65.zip
This patch adds helpers to allow users to lookup a lv or pv handle by
uuid (given a vg_t of course). Signed-off-by: Dave Wysochanski <wysochanski@pobox.com> Reviewed-by: Petr Rockai <prockai@redhat.com>
Diffstat (limited to 'liblvm')
-rw-r--r--liblvm/lvm2app.h38
-rw-r--r--liblvm/lvm_lv.c22
-rw-r--r--liblvm/lvm_pv.c22
3 files changed, 82 insertions, 0 deletions
diff --git a/liblvm/lvm2app.h b/liblvm/lvm2app.h
index 4750211b..1fff08ad 100644
--- a/liblvm/lvm2app.h
+++ b/liblvm/lvm2app.h
@@ -1032,6 +1032,25 @@ struct dm_list *lvm_lv_list_lvsegs(lv_t lv);
lv_t lvm_lv_from_name(vg_t vg, const char *name);
/**
+ * Lookup an LV handle in a VG by the LV uuid.
+ * The form of the uuid may be either the formatted, human-readable form,
+ * or the non-formatted form.
+ *
+ * \memberof lv_t
+ *
+ * \param vg
+ * VG handle obtained from lvm_vg_create() or lvm_vg_open().
+ *
+ * \param uuid
+ * UUID of LV to lookup.
+ *
+ * \return
+ * non-NULL handle to the LV with 'uuid' attached to the VG.
+ * NULL is returned if the LV uuid is not associated with the VG handle.
+ */
+lv_t lvm_lv_from_uuid(vg_t vg, const char *uuid);
+
+/**
* Activate a logical volume.
*
* \memberof lv_t
@@ -1523,6 +1542,25 @@ struct dm_list *lvm_pv_list_pvsegs(pv_t pv);
pv_t lvm_pv_from_name(vg_t vg, const char *name);
/**
+ * Lookup an PV handle in a VG by the PV uuid.
+ * The form of the uuid may be either the formatted, human-readable form,
+ * or the non-formatted form.
+ *
+ * \memberof pv_t
+ *
+ * \param vg
+ * VG handle obtained from lvm_vg_create() or lvm_vg_open().
+ *
+ * \param uuid
+ * UUID of PV to lookup.
+ *
+ * \return
+ * non-NULL handle to the PV with 'uuid' attached to the VG.
+ * NULL is returned if the PV uuid is not associated with the VG handle.
+ */
+pv_t lvm_pv_from_uuid(vg_t vg, const char *uuid);
+
+/**
* Resize physical volume to new_size bytes.
*
* \memberof pv_t
diff --git a/liblvm/lvm_lv.c b/liblvm/lvm_lv.c
index 5e8322f1..85d536cf 100644
--- a/liblvm/lvm_lv.c
+++ b/liblvm/lvm_lv.c
@@ -260,6 +260,28 @@ lv_t lvm_lv_from_name(vg_t vg, const char *name)
return NULL;
}
+lv_t lvm_lv_from_uuid(vg_t vg, const char *uuid)
+{
+ struct lv_list *lvl;
+ struct id id;
+
+ if (strlen(uuid) < ID_LEN) {
+ log_errno (EINVAL, "Invalid UUID string length");
+ return NULL;
+ }
+ if (strlen(uuid) >= ID_LEN) {
+ if (!id_read_format(&id, uuid)) {
+ log_errno(EINVAL, "Invalid UUID format");
+ return NULL;
+ }
+ }
+ dm_list_iterate_items(lvl, &vg->lvs) {
+ if (id_equal(&vg->id, &lvl->lv->lvid.id[0]) &&
+ id_equal(&id, &lvl->lv->lvid.id[1]))
+ 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 3372fdec..5f2014d1 100644
--- a/liblvm/lvm_pv.c
+++ b/liblvm/lvm_pv.c
@@ -98,6 +98,28 @@ pv_t lvm_pv_from_name(vg_t vg, const char *name)
return NULL;
}
+pv_t lvm_pv_from_uuid(vg_t vg, const char *uuid)
+{
+ struct pv_list *pvl;
+ struct id id;
+
+ if (strlen(uuid) < ID_LEN) {
+ log_errno (EINVAL, "Invalid UUID string length");
+ return NULL;
+ }
+ if (strlen(uuid) >= ID_LEN) {
+ if (!id_read_format(&id, uuid)) {
+ log_errno(EINVAL, "Invalid UUID format");
+ return NULL;
+ }
+ }
+ dm_list_iterate_items(pvl, &vg->pvs) {
+ if (id_equal(&id, &pvl->pv->id))
+ return pvl->pv;
+ }
+ return NULL;
+}
+
int lvm_pv_resize(const pv_t pv, uint64_t new_size)
{