master - python-lvm: Add method to retrieve lv attr.
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=9e0260c2e34f1b...
Commit: 9e0260c2e34f1b7150fb2fac3e780c3e75cd411e
Parent: 952605a8ea3a7c9eabeb89bb3d644b8b04b4239b
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Apr 10 14:38:18 2013 -0400
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Jul 2 14:24:34 2013 -0500
python-lvm: Add method to retrieve lv attr.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
python/liblvm.c | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/python/liblvm.c b/python/liblvm.c
index 4d35c94..381af62 100644
--- a/python/liblvm.c
+++ b/python/liblvm.c
@@ -1193,6 +1193,13 @@ liblvm_pv_dealloc(pvobject *self)
} \
} while (0)
+static PyObject *
+liblvm_lvm_lv_get_attr(lvobject *self)
+{
+ LV_VALID(self);
+
+ return Py_BuildValue("s", lvm_lv_get_attr(self->lv));
+}
static PyObject *
liblvm_lvm_lv_get_name(lvobject *self)
@@ -1749,6 +1756,7 @@ static PyMethodDef liblvm_vg_methods[] = {
static PyMethodDef liblvm_lv_methods[] = {
/* lv methods */
+ { "getAttr", (PyCFunction)liblvm_lvm_lv_get_attr, METH_NOARGS },
{ "getName", (PyCFunction)liblvm_lvm_lv_get_name, METH_NOARGS },
{ "getUuid", (PyCFunction)liblvm_lvm_lv_get_uuid, METH_NOARGS },
{ "activate", (PyCFunction)liblvm_lvm_lv_activate, METH_NOARGS },
10 years, 11 months
master - lvm2app: Add method to retrieve attr from lv.
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=952605a8ea3a7c...
Commit: 952605a8ea3a7c9eabeb89bb3d644b8b04b4239b
Parent: 588a16cadbb9000da8d5405ad69d3ed7024fd0fb
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Apr 10 14:37:56 2013 -0400
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Jul 2 14:24:34 2013 -0500
lvm2app: Add method to retrieve attr from lv.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
liblvm/lvm2app.h | 16 ++++++++++++++++
liblvm/lvm_lv.c | 5 +++++
2 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/liblvm/lvm2app.h b/liblvm/lvm2app.h
index 54a67c0..4a0844e 100644
--- a/liblvm/lvm2app.h
+++ b/liblvm/lvm2app.h
@@ -1216,6 +1216,22 @@ const char *lvm_lv_get_uuid(const lv_t lv);
const char *lvm_lv_get_name(const lv_t lv);
/**
+ * Get the attributes of a logical volume.
+ *
+ * \memberof lv_t
+ *
+ * The memory allocated for the name is tied to the vg_t handle and will be
+ * released when lvm_vg_close() is called.
+ *
+ * \param lv
+ * Logical volume handle.
+ *
+ * \return
+ * Copy of the attributes for the logical volume
+ */
+const char *lvm_lv_get_attr(const lv_t lv);
+
+/**
* Get the current size in bytes of a logical volume.
*
* \memberof lv_t
diff --git a/liblvm/lvm_lv.c b/liblvm/lvm_lv.c
index d0f89f1..6226eac 100644
--- a/liblvm/lvm_lv.c
+++ b/liblvm/lvm_lv.c
@@ -57,6 +57,11 @@ const char *lvm_lv_get_name(const lv_t lv)
NAME_LEN+1);
}
+const char *lvm_lv_get_attr(const lv_t lv)
+{
+ return lv_attr_dup(lv->vg->vgmem, lv);
+}
+
struct lvm_property_value lvm_lv_get_property(const lv_t lv, const char *name)
{
return get_property(NULL, NULL, lv, NULL, NULL, NULL, name);
10 years, 11 months
master - python-lvm: Add pvCreate python method
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=588a16cadbb900...
Commit: 588a16cadbb9000da8d5405ad69d3ed7024fd0fb
Parent: 6d6ccded3590b46f214561db38e1ce084b643c13
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Apr 3 17:54:12 2013 -0400
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Jul 2 14:24:34 2013 -0500
python-lvm: Add pvCreate python method
Added to base namespace.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
python/liblvm.c | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/python/liblvm.c b/python/liblvm.c
index 9c2e658..4d35c94 100644
--- a/python/liblvm.c
+++ b/python/liblvm.c
@@ -263,6 +263,26 @@ liblvm_lvm_pv_remove(PyObject *self, PyObject *arg)
}
static PyObject *
+liblvm_lvm_pv_create(PyObject *self, PyObject *arg)
+{
+ const char *pv_name;
+ uint64_t size;
+ LVM_VALID();
+
+ if (!PyArg_ParseTuple(arg, "sl", &pv_name, &size))
+ return NULL;
+
+ int rc = lvm_pv_create(libh, pv_name, size);
+ if (0 != rc) {
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
+ return NULL;
+ }
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyObject *
liblvm_lvm_percent_to_float(PyObject *self, PyObject *arg)
{
double converted;
@@ -1683,6 +1703,7 @@ static PyMethodDef Liblvm_methods[] = {
{ "listVgNames", (PyCFunction)liblvm_lvm_list_vg_names, METH_NOARGS },
{ "listVgUuids", (PyCFunction)liblvm_lvm_list_vg_uuids, METH_NOARGS },
{ "listPvs", (PyCFunction)liblvm_lvm_list_pvs, METH_NOARGS },
+ { "pvCreate", (PyCFunction)liblvm_lvm_pv_create, METH_VARARGS },
{ "pvRemove", (PyCFunction)liblvm_lvm_pv_remove, METH_VARARGS },
{ "percentToFloat", (PyCFunction)liblvm_lvm_percent_to_float, METH_VARARGS },
{ "vgNameFromPvid", (PyCFunction)liblvm_lvm_vgname_from_pvid, METH_VARARGS },
10 years, 11 months
master - lib2app: Added PV create. V2
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6d6ccded3590b4...
Commit: 6d6ccded3590b46f214561db38e1ce084b643c13
Parent: d079411051e8151b61c7614e791215db065c01cb
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Apr 3 17:53:21 2013 -0400
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Jul 2 14:24:34 2013 -0500
lib2app: Added PV create. V2
V2: Correct call to lock_vol
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
lib/metadata/metadata.h | 3 +++
lib/metadata/pv_manip.c | 22 ++++++++++++++++++++++
liblvm/lvm2app.h | 10 ++++++++++
liblvm/lvm_pv.c | 26 ++++++++++++++++++++++++++
tools/pvcreate.c | 11 ++---------
5 files changed, 63 insertions(+), 9 deletions(-)
diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h
index 5c0a85b..364722f 100644
--- a/lib/metadata/metadata.h
+++ b/lib/metadata/metadata.h
@@ -345,6 +345,9 @@ int pvremove_single(struct cmd_context *cmd, const char *pv_name,
void *handle __attribute__((unused)), unsigned force_count,
unsigned prompt);
+int pvcreate_locked(struct cmd_context *cmd, const char *pv_name,
+ struct pvcreate_params *pp);
+
/* Manipulate PV structures */
int pv_add(struct volume_group *vg, struct physical_volume *pv);
int pv_remove(struct volume_group *vg, struct physical_volume *pv);
diff --git a/lib/metadata/pv_manip.c b/lib/metadata/pv_manip.c
index 30ccd97..3ec20ef 100644
--- a/lib/metadata/pv_manip.c
+++ b/lib/metadata/pv_manip.c
@@ -20,6 +20,8 @@
#include "locking.h"
#include "defaults.h"
#include "lvmetad.h"
+#include "display.h"
+#include "label.h"
static struct pv_segment *_alloc_pv_segment(struct dm_pool *mem,
struct physical_volume *pv,
@@ -672,3 +674,23 @@ out:
return ret;
}
+
+int pvcreate_locked(struct cmd_context *cmd, const char *pv_name,
+ struct pvcreate_params *pp)
+{
+ int ret = ECMD_PROCESSED;
+
+ if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE, NULL)) {
+ log_error("Can't get lock for orphan PVs");
+ return ECMD_FAILED;
+ }
+
+ if (!(pvcreate_single(cmd, pv_name, pp, 1))) {
+ stack;
+ ret = ECMD_FAILED;
+ }
+
+ unlock_vg(cmd, VG_ORPHANS);
+
+ return ret;
+}
diff --git a/liblvm/lvm2app.h b/liblvm/lvm2app.h
index 695f5eb..54a67c0 100644
--- a/liblvm/lvm2app.h
+++ b/liblvm/lvm2app.h
@@ -572,6 +572,16 @@ struct dm_list *lvm_list_pvs(lvm_t libh);
int lvm_list_pvs_free(struct dm_list *pvlist);
/**
+ * Create a physical volume.
+ * \param libh Library handle
+ * \param pv_name The physical volume name
+ * \param size Size of physical volume, 0 = use all available.
+ * \return
+ * 0 on success, else -1 with library errno and text set.
+ */
+int lvm_pv_create(lvm_t libh, const char *pv_name, uint64_t size);
+
+/**
* Remove a physical volume.
* Note: You cannot remove a PV while iterating through the list of PVs as
* locks are held for the PV list.
diff --git a/liblvm/lvm_pv.c b/liblvm/lvm_pv.c
index bced4f9..9069f6f 100644
--- a/liblvm/lvm_pv.c
+++ b/liblvm/lvm_pv.c
@@ -226,3 +226,29 @@ int lvm_pv_resize(const pv_t pv, uint64_t new_size)
return 0;
}
}
+
+int lvm_pv_create(lvm_t libh, const char *pv_name, uint64_t size)
+{
+ int rc = -1;
+ struct pvcreate_params pp;
+ struct cmd_context *cmd = (struct cmd_context *)libh;
+ uint64_t size_sectors = size;
+
+ pvcreate_params_set_defaults(&pp);
+
+ if (size_sectors != 0 ) {
+ if( size_sectors % SECTOR_SIZE ) {
+ log_errno(EINVAL, "Size not a multiple of 512");
+ return -1;
+ }
+ size_sectors = size_sectors >> SECTOR_SHIFT;
+ }
+
+ pp.size = size_sectors;
+
+ if (ECMD_PROCESSED == pvcreate_locked(cmd, pv_name, &pp)) {
+ rc = 0;
+ }
+
+ return rc;
+}
diff --git a/tools/pvcreate.c b/tools/pvcreate.c
index 7570c52..d2de4d9 100644
--- a/tools/pvcreate.c
+++ b/tools/pvcreate.c
@@ -15,6 +15,7 @@
#include "tools.h"
#include "metadata-exported.h"
+#include "metadata.h"
/*
* Intial sanity checking of recovery-related command-line arguments.
@@ -96,7 +97,6 @@ int pvcreate(struct cmd_context *cmd, int argc, char **argv)
int i;
int ret = ECMD_PROCESSED;
struct pvcreate_params pp;
- struct physical_volume *pv;
pvcreate_params_set_defaults(&pp);
@@ -108,19 +108,12 @@ int pvcreate(struct cmd_context *cmd, int argc, char **argv)
}
for (i = 0; i < argc; i++) {
- if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE, NULL)) {
- log_error("Can't get lock for orphan PVs");
- return ECMD_FAILED;
- }
-
dm_unescape_colons_and_at_signs(argv[i], NULL, NULL);
- if (!(pv = pvcreate_single(cmd, argv[i], &pp, 1))) {
- stack;
+ if (ECMD_PROCESSED != pvcreate_locked(cmd, argv[i], &pp)) {
ret = ECMD_FAILED;
}
- unlock_vg(cmd, VG_ORPHANS);
if (sigint_caught())
return ret;
}
10 years, 11 months
master - lib2app: Fix warnings in lvm_list_pvs_free
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d079411051e815...
Commit: d079411051e8151b61c7614e791215db065c01cb
Parent: 8ddb1b4abfeeb39044cd26199ff8d966870c2354
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Apr 3 17:07:08 2013 -0400
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Jul 2 14:24:34 2013 -0500
lib2app: Fix warnings in lvm_list_pvs_free
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
liblvm/lvm_pv.c | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/liblvm/lvm_pv.c b/liblvm/lvm_pv.c
index 8f53352..bced4f9 100644
--- a/liblvm/lvm_pv.c
+++ b/liblvm/lvm_pv.c
@@ -116,9 +116,7 @@ int lvm_list_pvs_free(struct dm_list *pvlist)
int rc = 0;
struct lvm_list_wrapper *to_delete = NULL;
struct vg_list *vgl = NULL;
- struct vg_list *tmp_vgl = NULL;
struct pv_list *pvl = NULL;
- struct pv_list *tmp_pvl = NULL;
struct cmd_context *cmd = NULL;
if (pvlist ) {
10 years, 11 months
master - _get_pvs: Remove unused variable
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=8ddb1b4abfeeb3...
Commit: 8ddb1b4abfeeb39044cd26199ff8d966870c2354
Parent: bfa265f1985818567b1eb6f7fae0ff3ba315b152
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Apr 3 17:05:00 2013 -0400
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Jul 2 14:24:34 2013 -0500
_get_pvs: Remove unused variable
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
lib/metadata/metadata.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 0f71abc..e594f7c 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -3696,7 +3696,6 @@ static int _get_pvs(struct cmd_context *cmd, int warnings,
struct dm_list *pvslist, struct dm_list *vgslist)
{
struct str_list *strl;
- struct dm_list * uninitialized_var(results);
const char *vgname, *vgid;
struct pv_list *pvl, *pvl_copy;
struct dm_list *vgids;
10 years, 11 months
master - lvm2app: Set suppress to 1
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=bfa265f1985818...
Commit: bfa265f1985818567b1eb6f7fae0ff3ba315b152
Parent: 45a0f9e45be5999095c71382361f37f7c24d86d6
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Apr 2 17:10:02 2013 -0400
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Jul 2 14:24:34 2013 -0500
lvm2app: Set suppress to 1
Removes printing to stdout/stderr etc.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
liblvm/lvm_base.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/liblvm/lvm_base.c b/liblvm/lvm_base.c
index 53be709..67ed023 100644
--- a/liblvm/lvm_base.c
+++ b/liblvm/lvm_base.c
@@ -66,6 +66,12 @@ lvm_t lvm_init(const char *system_dir)
*/
cmd->cmd_line = "liblvm";
+ /*
+ * Turn off writing to stderr etc., not sure if there is a better way
+ * to do this?
+ */
+ log_suppress(1);
+
return (lvm_t) cmd;
}
10 years, 11 months
master - python-lvm: Add bindings for lvm_pv_remove
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=45a0f9e45be599...
Commit: 45a0f9e45be5999095c71382361f37f7c24d86d6
Parent: e33ac7b1ed962abb5ccb3d12a5401c84a188bf92
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Apr 2 16:10:57 2013 -0400
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Jul 2 14:24:34 2013 -0500
python-lvm: Add bindings for lvm_pv_remove
Method off of base lvm namespace "pvRemove".
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
python/liblvm.c | 20 ++++++++++++++++++++
1 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/python/liblvm.c b/python/liblvm.c
index 6491274..9c2e658 100644
--- a/python/liblvm.c
+++ b/python/liblvm.c
@@ -244,6 +244,25 @@ liblvm_lvm_list_pvs(void)
}
static PyObject *
+liblvm_lvm_pv_remove(PyObject *self, PyObject *arg)
+{
+ const char *pv_name;
+ LVM_VALID();
+
+ if (!PyArg_ParseTuple(arg, "s", &pv_name))
+ return NULL;
+
+ int rc = lvm_pv_remove(libh, pv_name);
+ if (0 != rc) {
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
+ return NULL;
+ }
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyObject *
liblvm_lvm_percent_to_float(PyObject *self, PyObject *arg)
{
double converted;
@@ -1664,6 +1683,7 @@ static PyMethodDef Liblvm_methods[] = {
{ "listVgNames", (PyCFunction)liblvm_lvm_list_vg_names, METH_NOARGS },
{ "listVgUuids", (PyCFunction)liblvm_lvm_list_vg_uuids, METH_NOARGS },
{ "listPvs", (PyCFunction)liblvm_lvm_list_pvs, METH_NOARGS },
+ { "pvRemove", (PyCFunction)liblvm_lvm_pv_remove, METH_VARARGS },
{ "percentToFloat", (PyCFunction)liblvm_lvm_percent_to_float, METH_VARARGS },
{ "vgNameFromPvid", (PyCFunction)liblvm_lvm_vgname_from_pvid, METH_VARARGS },
{ "vgNameFromDevice", (PyCFunction)liblvm_lvm_vgname_from_device, METH_VARARGS },
10 years, 11 months
master - lvm2app: Implement lvm_pv_remove V2
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e33ac7b1ed962a...
Commit: e33ac7b1ed962abb5ccb3d12a5401c84a188bf92
Parent: ef3ab801e8604d8f629badc1cac1d9190467033f
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Apr 2 16:10:18 2013 -0400
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Jul 2 14:24:34 2013 -0500
lvm2app: Implement lvm_pv_remove V2
Code move and changes to support calling code from
command line and from library interface.
V2 Change lock_vol call
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
lib/metadata/metadata.h | 4 ++
lib/metadata/pv_manip.c | 130 +++++++++++++++++++++++++++++++++++++++++++++
liblvm/lvm2app.h | 16 +++++-
liblvm/lvm_pv.c | 8 +++
tools/pvremove.c | 133 +++--------------------------------------------
5 files changed, 163 insertions(+), 128 deletions(-)
diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h
index bf9bd55..5c0a85b 100644
--- a/lib/metadata/metadata.h
+++ b/lib/metadata/metadata.h
@@ -341,6 +341,10 @@ int vg_validate(struct volume_group *vg);
int pv_write_orphan(struct cmd_context *cmd, struct physical_volume *pv);
+int pvremove_single(struct cmd_context *cmd, const char *pv_name,
+ void *handle __attribute__((unused)), unsigned force_count,
+ unsigned prompt);
+
/* Manipulate PV structures */
int pv_add(struct volume_group *vg, struct physical_volume *pv);
int pv_remove(struct volume_group *vg, struct physical_volume *pv);
diff --git a/lib/metadata/pv_manip.c b/lib/metadata/pv_manip.c
index 2f4f51e..30ccd97 100644
--- a/lib/metadata/pv_manip.c
+++ b/lib/metadata/pv_manip.c
@@ -19,6 +19,7 @@
#include "toolcontext.h"
#include "locking.h"
#include "defaults.h"
+#include "lvmetad.h"
static struct pv_segment *_alloc_pv_segment(struct dm_pool *mem,
struct physical_volume *pv,
@@ -542,3 +543,132 @@ int pv_resize(struct physical_volume *pv,
return 1;
}
+
+const char _really_wipe[] =
+ "Really WIPE LABELS from physical volume \"%s\" of volume group \"%s\" [y/n]? ";
+
+/*
+ * Decide whether it is "safe" to wipe the labels on this device.
+ * 0 indicates we may not.
+ */
+static int pvremove_check(struct cmd_context *cmd, const char *name,
+ unsigned force_count, unsigned prompt)
+{
+ struct physical_volume *pv;
+
+ /* FIXME Check partition type is LVM unless --force is given */
+
+ /* Is there a pv here already? */
+ /* If not, this is an error unless you used -f. */
+ if (!(pv = pv_read(cmd, name, 1, 0))) {
+ if (force_count)
+ return 1;
+ log_error("Physical Volume %s not found", name);
+ return 0;
+ }
+
+ /*
+ * If a PV has no MDAs it may appear to be an
+ * orphan until the metadata is read off
+ * another PV in the same VG. Detecting this
+ * means checking every VG by scanning every
+ * PV on the system.
+ */
+ if (is_orphan(pv) && !dm_list_size(&pv->fid->metadata_areas_in_use) &&
+ !dm_list_size(&pv->fid->metadata_areas_ignored)) {
+ if (!scan_vgs_for_pvs(cmd, 0)) {
+ log_error("Rescan for PVs without metadata areas "
+ "failed.");
+ goto bad;
+ }
+ free_pv_fid(pv);
+ if (!(pv = pv_read(cmd, name, 1, 0))) {
+ log_error("Failed to read physical volume %s", name);
+ goto bad;
+ }
+ }
+
+ /* orphan ? */
+ if (is_orphan(pv)) {
+ free_pv_fid(pv);
+ return 1;
+ }
+
+ /* Allow partial & exported VGs to be destroyed. */
+ /* we must have -ff to overwrite a non orphan */
+ if (force_count < 2) {
+ log_error("PV %s belongs to Volume Group %s so please use vgreduce first.", name, pv_vg_name(pv));
+ log_error("(If you are certain you need pvremove, then confirm by using --force twice.)");
+ goto bad;
+ }
+
+ /* prompt */
+ if (!prompt &&
+ yes_no_prompt(_really_wipe, name, pv_vg_name(pv)) == 'n') {
+ log_error("%s: physical volume label not removed", name);
+ goto bad;
+ }
+
+ if (force_count) {
+ log_warn("WARNING: Wiping physical volume label from "
+ "%s%s%s%s", name,
+ !is_orphan(pv) ? " of volume group \"" : "",
+ !is_orphan(pv) ? pv_vg_name(pv) : "",
+ !is_orphan(pv) ? "\"" : "");
+ }
+
+ free_pv_fid(pv);
+ return 1;
+
+bad:
+ free_pv_fid(pv);
+ return 0;
+}
+
+int pvremove_single(struct cmd_context *cmd, const char *pv_name,
+ void *handle __attribute__((unused)), unsigned force_count,
+ unsigned prompt)
+{
+ struct device *dev;
+ int ret = ECMD_FAILED;
+
+ if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE, NULL)) {
+ log_error("Can't get lock for orphan PVs");
+ return ECMD_FAILED;
+ }
+
+ if (!pvremove_check(cmd, pv_name, force_count, prompt))
+ goto out;
+
+ if (!(dev = dev_cache_get(pv_name, cmd->filter))) {
+ log_error("%s: Couldn't find device. Check your filters?",
+ pv_name);
+ goto out;
+ }
+
+ if (!dev_test_excl(dev)) {
+ /* FIXME Detect whether device-mapper is still using the device */
+ log_error("Can't open %s exclusively - not removing. "
+ "Mounted filesystem?", dev_name(dev));
+ goto out;
+ }
+
+ /* Wipe existing label(s) */
+ if (!label_remove(dev)) {
+ log_error("Failed to wipe existing label(s) on %s", pv_name);
+ goto out;
+ }
+
+ if (!lvmetad_pv_gone_by_dev(dev, NULL))
+ goto_out;
+
+ log_print_unless_silent("Labels on physical volume \"%s\" successfully wiped",
+ pv_name);
+
+ ret = ECMD_PROCESSED;
+
+out:
+ unlock_vg(cmd, VG_ORPHANS);
+
+ return ret;
+}
diff --git a/liblvm/lvm2app.h b/liblvm/lvm2app.h
index f70e72c..695f5eb 100644
--- a/liblvm/lvm2app.h
+++ b/liblvm/lvm2app.h
@@ -553,14 +553,15 @@ struct dm_list *lvm_vg_list_lvs(vg_t vg);
* \return
* A list of lvm_pv_list structures containing pv handles for all physical
* volumes. If no PVs exist or a global lock was unable to be obtained a
- * NULL is returned.
+ * NULL is returned. Do not attempt to remove one of the PVs until after the
+ * call to lvm_list_pvs_free has been made.
*/
struct dm_list *lvm_list_pvs(lvm_t libh);
/**
* Free the resources used by acquiring the pvlist. This should be called as
* soon as possible after processing the needed information from the pv list as
- * a global locks are held.
+ * a global lock is held.
*
* \param pvlist
* PV list to be freed
@@ -571,6 +572,17 @@ struct dm_list *lvm_list_pvs(lvm_t libh);
int lvm_list_pvs_free(struct dm_list *pvlist);
/**
+ * Remove a physical volume.
+ * Note: You cannot remove a PV while iterating through the list of PVs as
+ * locks are held for the PV list.
+ * \param libh Library handle
+ * \param pv_name The physical volume name
+ * \return
+ * 0 on success, else -1 with library errno and text set.
+ */
+int lvm_pv_remove(lvm_t libh, const char *pv_name);
+
+/**
* Return a list of PV handles for a given VG handle.
*
* \memberof vg_t
diff --git a/liblvm/lvm_pv.c b/liblvm/lvm_pv.c
index db6c39d..8f53352 100644
--- a/liblvm/lvm_pv.c
+++ b/liblvm/lvm_pv.c
@@ -75,6 +75,14 @@ struct lvm_list_wrapper
struct dm_list vgslist;
};
+int lvm_pv_remove(lvm_t libh, const char *pv_name)
+{
+ struct cmd_context *cmd = (struct cmd_context *)libh;
+ if ( 1 != pvremove_single(cmd, pv_name, NULL, 0, 0)) {
+ return -1;
+ }
+ return 0;
+}
struct dm_list *lvm_list_pvs(lvm_t libh)
{
diff --git a/tools/pvremove.c b/tools/pvremove.c
index 2c8f5c6..a99a9bd 100644
--- a/tools/pvremove.c
+++ b/tools/pvremove.c
@@ -14,146 +14,27 @@
*/
#include "tools.h"
+#include "metadata.h"
-/*
- * Decide whether it is "safe" to wipe the labels on this device.
- * 0 indicates we may not.
- */
-static int pvremove_check(struct cmd_context *cmd, const char *name)
-{
- struct physical_volume *pv;
-
- /* FIXME Check partition type is LVM unless --force is given */
-
- /* Is there a pv here already? */
- /* If not, this is an error unless you used -f. */
- if (!(pv = pv_read(cmd, name, 1, 0))) {
- if (arg_count(cmd, force_ARG))
- return 1;
- log_error("Physical Volume %s not found", name);
- return 0;
- }
-
- /*
- * If a PV has no MDAs it may appear to be an
- * orphan until the metadata is read off
- * another PV in the same VG. Detecting this
- * means checking every VG by scanning every
- * PV on the system.
- */
- if (is_orphan(pv) && !dm_list_size(&pv->fid->metadata_areas_in_use) &&
- !dm_list_size(&pv->fid->metadata_areas_ignored)) {
- if (!scan_vgs_for_pvs(cmd, 0)) {
- log_error("Rescan for PVs without metadata areas "
- "failed.");
- goto bad;
- }
- free_pv_fid(pv);
- if (!(pv = pv_read(cmd, name, 1, 0))) {
- log_error("Failed to read physical volume %s", name);
- goto bad;
- }
- }
-
- /* orphan ? */
- if (is_orphan(pv)) {
- free_pv_fid(pv);
- return 1;
- }
-
- /* Allow partial & exported VGs to be destroyed. */
- /* we must have -ff to overwrite a non orphan */
- if (arg_count(cmd, force_ARG) < 2) {
- log_error("PV %s belongs to Volume Group %s so please use vgreduce first.", name, pv_vg_name(pv));
- log_error("(If you are certain you need pvremove, then confirm by using --force twice.)");
- goto bad;
- }
-
- /* prompt */
- if (!arg_count(cmd, yes_ARG) &&
- yes_no_prompt("Really WIPE LABELS from physical volume \"%s\" "
- "of volume group \"%s\" [y/n]? ",
- name, pv_vg_name(pv)) == 'n') {
- log_error("%s: physical volume label not removed", name);
- goto bad;
- }
-
- if (arg_count(cmd, force_ARG)) {
- log_warn("WARNING: Wiping physical volume label from "
- "%s%s%s%s", name,
- !is_orphan(pv) ? " of volume group \"" : "",
- !is_orphan(pv) ? pv_vg_name(pv) : "",
- !is_orphan(pv) ? "\"" : "");
- }
-
- free_pv_fid(pv);
- return 1;
-
-bad:
- free_pv_fid(pv);
- return 0;
-}
-
-static int pvremove_single(struct cmd_context *cmd, const char *pv_name,
- void *handle __attribute__((unused)))
-{
- struct device *dev;
- int ret = ECMD_FAILED;
-
- if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE, NULL)) {
- log_error("Can't get lock for orphan PVs");
- return ECMD_FAILED;
- }
-
- if (!pvremove_check(cmd, pv_name))
- goto out;
-
- if (!(dev = dev_cache_get(pv_name, cmd->filter))) {
- log_error("%s: Couldn't find device. Check your filters?",
- pv_name);
- goto out;
- }
-
- if (!dev_test_excl(dev)) {
- /* FIXME Detect whether device-mapper is still using the device */
- log_error("Can't open %s exclusively - not removing. "
- "Mounted filesystem?", dev_name(dev));
- goto out;
- }
-
- /* Wipe existing label(s) */
- if (!label_remove(dev)) {
- log_error("Failed to wipe existing label(s) on %s", pv_name);
- goto out;
- }
-
- if (!lvmetad_pv_gone_by_dev(dev, NULL))
- goto_out;
-
- log_print_unless_silent("Labels on physical volume \"%s\" successfully wiped",
- pv_name);
-
- ret = ECMD_PROCESSED;
-
-out:
- unlock_vg(cmd, VG_ORPHANS);
-
- return ret;
-}
int pvremove(struct cmd_context *cmd, int argc, char **argv)
{
int i, r;
int ret = ECMD_PROCESSED;
+ unsigned force_count;
+ unsigned prompt;
if (!argc) {
log_error("Please enter a physical volume path");
return EINVALID_CMD_LINE;
}
+ force_count = arg_count(cmd, force_ARG);
+ prompt = arg_count(cmd, yes_ARG);
+
for (i = 0; i < argc; i++) {
dm_unescape_colons_and_at_signs(argv[i], NULL, NULL);
- r = pvremove_single(cmd, argv[i], NULL);
+ r = pvremove_single(cmd, argv[i], NULL, force_count, prompt);
if (r > ret)
ret = r;
}
10 years, 11 months
master - lvm2app: Add function to retrieve list of PVs V3
by tasleson
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=ef3ab801e8604d...
Commit: ef3ab801e8604d8f629badc1cac1d9190467033f
Parent: 49d7596581be013ec71a1da7897f861b721eaa19
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Mar 19 17:37:04 2013 -0400
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Jul 2 14:24:33 2013 -0500
lvm2app: Add function to retrieve list of PVs V3
As locks are held, you need to call the included function
to release the memory and locks when done transversing the
list of physical volumes.
V2: Rebase fix
V3: Prevent VGs from getting cached and then write protected.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
lib/metadata/metadata-exported.h | 12 +++-
lib/metadata/metadata.c | 91 +++++++++++++++++------
liblvm/lvm2app.h | 28 +++++++
liblvm/lvm_pv.c | 79 ++++++++++++++++++++
python/liblvm.c | 152 ++++++++++++++++++++++++++++++++++++--
5 files changed, 331 insertions(+), 31 deletions(-)
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index ee8f0c1..7743c47 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -403,6 +403,11 @@ struct lv_list {
struct logical_volume *lv;
};
+struct vg_list {
+ struct dm_list list;
+ struct volume_group *vg;
+};
+
#define PV_PE_START_CALC ((uint64_t) -1) /* Calculate pe_start value */
struct pvcreate_restorable_params {
@@ -493,7 +498,12 @@ struct volume_group *vg_read_internal(struct cmd_context *cmd, const char *vg_na
struct physical_volume *pv_read(struct cmd_context *cmd, const char *pv_name,
int warnings,
int scan_label_only);
-struct dm_list *get_pvs(struct cmd_context *cmd);
+
+#define get_pvs( cmd ) get_pvs_internal((cmd), NULL, NULL)
+#define get_pvs_perserve_vg( cmd, pv_list, vg_list ) get_pvs_internal((cmd), (pv_list), (vg_list))
+
+struct dm_list *get_pvs_internal(struct cmd_context *cmd,
+ struct dm_list *pvslist, struct dm_list *vgslist);
/*
* Add/remove LV to/from volume group
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index e12e1b0..0f71abc 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -3692,7 +3692,8 @@ struct dm_list *get_vgids(struct cmd_context *cmd, int include_internal)
return lvmcache_get_vgids(cmd, include_internal);
}
-static int _get_pvs(struct cmd_context *cmd, int warnings, struct dm_list **pvslist)
+static int _get_pvs(struct cmd_context *cmd, int warnings,
+ struct dm_list *pvslist, struct dm_list *vgslist)
{
struct str_list *strl;
struct dm_list * uninitialized_var(results);
@@ -3702,18 +3703,11 @@ static int _get_pvs(struct cmd_context *cmd, int warnings, struct dm_list **pvsl
struct volume_group *vg;
int consistent = 0;
int old_pvmove;
+ struct vg_list *vgl_item = NULL;
+ int have_pv = 0;
lvmcache_label_scan(cmd, 0);
- if (pvslist) {
- if (!(results = dm_pool_alloc(cmd->mem, sizeof(*results)))) {
- log_error("PV list allocation failed");
- return 0;
- }
-
- dm_list_init(results);
- }
-
/* Get list of VGs */
if (!(vgids = get_vgids(cmd, 1))) {
log_error("get_pvs: get_vgids failed");
@@ -3733,7 +3727,15 @@ static int _get_pvs(struct cmd_context *cmd, int warnings, struct dm_list **pvsl
stack;
continue;
}
- if (!(vg = vg_read_internal(cmd, vgname, vgid, warnings, &consistent))) {
+
+ /* When we are retrieving a list to return toliblvm we need
+ * that list to contain VGs that are modifiable as we are using
+ * the vgmem pool in the vg to provide allocation for liblvm.
+ * This is a hack to prevent the vg from getting cached as the
+ * vgid will be NULL. There is most definitely a better way
+ * to do this.
+ */
+ if (!(vg = vg_read_internal(cmd, vgname, (!vgslist) ? vgid : NULL, warnings, &consistent))) {
stack;
continue;
}
@@ -3749,33 +3751,78 @@ static int _get_pvs(struct cmd_context *cmd, int warnings, struct dm_list **pvsl
release_vg(vg);
return 0;
}
- dm_list_add(results, &pvl_copy->list);
+ /* If we are going to release the vg, don't store a pointer to
+ * it in the pv structure.
+ */
+ if (!vgslist) {
+ pvl_copy->pv->vg = NULL;
+ }
+ have_pv = 1;
+ dm_list_add(pvslist, &pvl_copy->list);
}
- release_vg(vg);
+
+ /* In the case of the library we want to preserve the embedded volume
+ * group as subsequent calls to retrieve data about the pv require it.
+ */
+ if (!vgslist || have_pv == 0) {
+ release_vg(vg);
+ } else {
+ /* Add vg to list of vg objects that will be returned
+ */
+ vgl_item = dm_pool_alloc(cmd->mem, sizeof(*vgl_item));
+ if (!vgl_item) {
+ log_error("VG list element allocation failed");
+ return 0;
+ }
+ vgl_item->vg = vg;
+ vg = NULL;
+ dm_list_add(vgslist, &vgl_item->list);
+ }
+ have_pv = 0;
}
init_pvmove(old_pvmove);
- if (pvslist)
- *pvslist = results;
- else
+ if (!pvslist) {
dm_pool_free(cmd->mem, vgids);
-
+ }
return 1;
}
-struct dm_list *get_pvs(struct cmd_context *cmd)
+/* Retrieve a list of all physical volumes.
+ * @param cmd Command context
+ * @param pvslist Set to NULL if you want memory for list created,
+ * else valid memory
+ * @param vgslist Set to NULL if you need the pv structures to contain
+ * valid vg pointer. This is the list of VGs
+ * @returns NULL on errors, else pvslist which will equal passes in value if
+ * supplied.
+ */
+struct dm_list *get_pvs_internal(struct cmd_context *cmd,
+ struct dm_list *pvslist, struct dm_list *vgslist)
{
- struct dm_list *results;
+ struct dm_list *results = pvslist;
- if (!_get_pvs(cmd, 1, &results))
- return NULL;
+ if (NULL == results) {
+ if (!(results = dm_pool_alloc(cmd->mem, sizeof(*results)))) {
+ log_error("PV list allocation failed");
+ return 0;
+ }
+
+ dm_list_init(results);
+ }
+ if (!_get_pvs(cmd, 1, results, vgslist)) {
+ if (NULL == pvslist) {
+ dm_pool_free(cmd->mem, results);
+ }
+ return NULL;
+ }
return results;
}
int scan_vgs_for_pvs(struct cmd_context *cmd, int warnings)
{
- return _get_pvs(cmd, warnings, NULL);
+ return _get_pvs(cmd, warnings, NULL, NULL);
}
int pv_write(struct cmd_context *cmd __attribute__((unused)),
diff --git a/liblvm/lvm2app.h b/liblvm/lvm2app.h
index 25778d1..f70e72c 100644
--- a/liblvm/lvm2app.h
+++ b/liblvm/lvm2app.h
@@ -543,6 +543,34 @@ vg_t lvm_vg_create(lvm_t libh, const char *vg_name);
struct dm_list *lvm_vg_list_lvs(vg_t vg);
/**
+ * Return a list of PV handles for all.
+ *
+ * \memberof lvm_t
+ *
+ * \param libh
+ * Library handle retrieved from lvm_init
+ *
+ * \return
+ * A list of lvm_pv_list structures containing pv handles for all physical
+ * volumes. If no PVs exist or a global lock was unable to be obtained a
+ * NULL is returned.
+ */
+struct dm_list *lvm_list_pvs(lvm_t libh);
+
+/**
+ * Free the resources used by acquiring the pvlist. This should be called as
+ * soon as possible after processing the needed information from the pv list as
+ * a global locks are held.
+ *
+ * \param pvlist
+ * PV list to be freed
+ *
+ * \return
+ * 0 on success, else -1 with library errno and text set.
+ */
+int lvm_list_pvs_free(struct dm_list *pvlist);
+
+/**
* Return a list of PV handles for a given VG handle.
*
* \memberof vg_t
diff --git a/liblvm/lvm_pv.c b/liblvm/lvm_pv.c
index 18b1069..db6c39d 100644
--- a/liblvm/lvm_pv.c
+++ b/liblvm/lvm_pv.c
@@ -12,11 +12,14 @@
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include <stddef.h>
#include "lib.h"
#include "metadata.h"
#include "lvm-string.h"
#include "lvm_misc.h"
#include "lvm2app.h"
+#include "locking.h"
+#include "toolcontext.h"
const char *lvm_pv_get_uuid(const pv_t pv)
{
@@ -60,6 +63,82 @@ struct lvm_property_value lvm_pvseg_get_property(const pvseg_t pvseg,
return get_property(NULL, NULL, NULL, NULL, pvseg, NULL, name);
}
+
+#define address_of(p, t, m) ({ \
+ const typeof( ((t *)0)->m ) *__mptr = (p); \
+ (t *)( (char *)__mptr - offsetof(t,m) );})
+
+struct lvm_list_wrapper
+{
+ unsigned long magic;
+ struct dm_list pvslist;
+ struct dm_list vgslist;
+};
+
+
+struct dm_list *lvm_list_pvs(lvm_t libh)
+{
+ struct lvm_list_wrapper *rc = NULL;
+ struct cmd_context *cmd = (struct cmd_context *)libh;
+
+
+ rc = dm_pool_zalloc(cmd->mem, sizeof(*rc));
+ if (!rc) {
+ log_errno(ENOMEM, "Memory allocation fail for pv list.");
+ return NULL;
+ }
+
+ if (!lock_vol(cmd, VG_GLOBAL, LCK_VG_WRITE, NULL)) {
+ log_errno(ENOLCK, "Unable to obtain global lock.");
+ } else {
+ dm_list_init(&rc->pvslist);
+ dm_list_init(&rc->vgslist);
+ if( !get_pvs_perserve_vg(cmd, &rc->pvslist, &rc->vgslist) ) {
+ dm_pool_free(cmd->mem, rc);
+ return NULL;
+ }
+ rc->magic = 0xF005BA11;
+ }
+
+ return &rc->pvslist;
+}
+
+int lvm_list_pvs_free(struct dm_list *pvlist)
+{
+ int rc = 0;
+ struct lvm_list_wrapper *to_delete = NULL;
+ struct vg_list *vgl = NULL;
+ struct vg_list *tmp_vgl = NULL;
+ struct pv_list *pvl = NULL;
+ struct pv_list *tmp_pvl = NULL;
+ struct cmd_context *cmd = NULL;
+
+ if (pvlist ) {
+ to_delete = address_of(pvlist, struct lvm_list_wrapper, pvslist);
+ if (to_delete->magic == 0xF005BA11) {
+
+ dm_list_iterate_items(vgl, &to_delete->vgslist) {
+ cmd = vgl->vg->cmd;
+ release_vg(vgl->vg);
+ }
+
+ dm_list_iterate_items(pvl, &to_delete->pvslist) {
+ free_pv_fid(pvl->pv);
+ }
+
+ unlock_vg(cmd, VG_GLOBAL);
+ } else {
+ log_errno(EINVAL, "Not a correct pvlist structure");
+ rc = -1;
+ }
+
+ to_delete->magic = 0xA5A5A5A5;
+ dm_pool_free(cmd->mem, to_delete);
+
+ }
+ return rc;
+}
+
struct dm_list *lvm_pv_list_pvsegs(pv_t pv)
{
struct dm_list *list;
diff --git a/python/liblvm.c b/python/liblvm.c
index 906825e..6491274 100644
--- a/python/liblvm.c
+++ b/python/liblvm.c
@@ -34,6 +34,11 @@ typedef struct {
typedef struct {
PyObject_HEAD
+ struct dm_list *pvslist;
+} pvslistobject;
+
+typedef struct {
+ PyObject_HEAD
lv_t lv; /* lv handle */
vgobject *parent_vgobj;
} lvobject;
@@ -42,6 +47,7 @@ typedef struct {
PyObject_HEAD
pv_t pv; /* pv handle */
vgobject *parent_vgobj;
+ pvslistobject *parent_pvslistobj;
} pvobject;
typedef struct {
@@ -58,6 +64,7 @@ typedef struct {
static PyTypeObject LibLVMvgType;
static PyTypeObject LibLVMlvType;
+static PyTypeObject LibLVMpvlistType;
static PyTypeObject LibLVMpvType;
static PyTypeObject LibLVMlvsegType;
static PyTypeObject LibLVMpvsegType;
@@ -153,6 +160,90 @@ liblvm_lvm_list_vg_uuids(void)
}
static PyObject *
+liblvm_lvm_pvlist_get(pvslistobject *pvsobj)
+{
+ struct lvm_pv_list *pvl;
+ PyObject * pytuple;
+ pvobject * pvobj;
+ int i = 0;
+
+ /* unlike other LVM api calls, if there are no results, we get NULL */
+ pvsobj->pvslist = lvm_list_pvs(libh);
+
+ if (!pvsobj->pvslist)
+ return Py_BuildValue("()");
+
+ pytuple = PyTuple_New(dm_list_size(pvsobj->pvslist));
+ if (!pytuple)
+ return NULL;
+
+ dm_list_iterate_items(pvl, pvsobj->pvslist) {
+ /* Create and initialize the object */
+ pvobj = PyObject_New(pvobject, &LibLVMpvType);
+ if (!pvobj) {
+ Py_DECREF(pytuple);
+ return NULL;
+ }
+
+ /* We don't have a parent vg object to be concerned about */
+ pvobj->parent_vgobj = NULL;
+ pvobj->parent_pvslistobj = pvsobj;
+ Py_INCREF(pvobj->parent_pvslistobj);
+
+ pvobj->pv = pvl->pv;
+ PyTuple_SET_ITEM(pytuple, i, (PyObject *) pvobj);
+ i++;
+ }
+
+ return pytuple;
+}
+
+static PyObject *
+liblvm_lvm_pvlist_put(pvslistobject *self)
+{
+ int rc = 0;
+ if (self->pvslist) {
+ rc = lvm_list_pvs_free(self->pvslist);
+
+ if ( 0 != rc ) {
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
+ return NULL;
+ }
+
+ self->pvslist = NULL;
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ return NULL;
+}
+
+static PyObject *
+liblvm_pvlist_dealloc(pvslistobject *self)
+{
+ if (self->pvslist) {
+ liblvm_lvm_pvlist_put(self);
+ }
+
+ PyObject_Del(self);
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyObject *
+liblvm_lvm_list_pvs(void)
+{
+ pvslistobject *pvslistobj;
+
+ LVM_VALID();
+
+ if ((pvslistobj = PyObject_New(pvslistobject, &LibLVMpvlistType)) == NULL)
+ return NULL;
+
+ pvslistobj->pvslist = NULL;
+ return (PyObject *)pvslistobj;
+}
+
+static PyObject *
liblvm_lvm_percent_to_float(PyObject *self, PyObject *arg)
{
double converted;
@@ -360,6 +451,15 @@ liblvm_vg_dealloc(vgobject *self)
} \
} while (0)
+#define PVSLIST_VALID(pvslistobject) \
+ do { \
+ LVM_VALID(); \
+ if (!pvslistobject->pvslist) { \
+ PyErr_SetString(PyExc_UnboundLocalError, "PVS object invalid"); \
+ return NULL; \
+ } \
+ } while (0)
+
static PyObject *
liblvm_lvm_vg_close(vgobject *self)
{
@@ -1030,7 +1130,16 @@ liblvm_lvm_pv_from_uuid(vgobject *self, PyObject *arg)
static void
liblvm_pv_dealloc(pvobject *self)
{
- Py_DECREF(self->parent_vgobj);
+ if (self->parent_vgobj) {
+ Py_DECREF(self->parent_vgobj);
+ }
+
+ if (self->parent_pvslistobj) {
+ Py_DECREF(self->parent_pvslistobj);
+ }
+
+ self->parent_vgobj = NULL;
+ self->parent_pvslistobj = NULL;
PyObject_Del(self);
}
@@ -1337,19 +1446,23 @@ liblvm_lvm_lv_snapshot(lvobject *self, PyObject *args)
lvobj->parent_vgobj = self->parent_vgobj;
Py_INCREF(lvobj->parent_vgobj);
-
return (PyObject *)lvobj;
}
/* PV Methods */
-#define PV_VALID(pvobject) \
- do { \
- VG_VALID(pvobject->parent_vgobj); \
- if (!pvobject->pv) { \
+#define PV_VALID(pvobject) \
+ do { \
+ if (pvobject->parent_vgobj) { \
+ VG_VALID(pvobject->parent_vgobj); \
+ } \
+ if (pvobject->parent_pvslistobj) { \
+ PVSLIST_VALID(pvobject->parent_pvslistobj); \
+ } \
+ if (!pvobject->pv) { \
PyErr_SetString(PyExc_UnboundLocalError, "PV object invalid"); \
- return NULL; \
- } \
+ return NULL; \
+ } \
} while (0)
static PyObject *
@@ -1550,6 +1663,7 @@ static PyMethodDef Liblvm_methods[] = {
{ "scan", (PyCFunction)liblvm_lvm_scan, METH_NOARGS },
{ "listVgNames", (PyCFunction)liblvm_lvm_list_vg_names, METH_NOARGS },
{ "listVgUuids", (PyCFunction)liblvm_lvm_list_vg_uuids, METH_NOARGS },
+ { "listPvs", (PyCFunction)liblvm_lvm_list_pvs, METH_NOARGS },
{ "percentToFloat", (PyCFunction)liblvm_lvm_percent_to_float, METH_VARARGS },
{ "vgNameFromPvid", (PyCFunction)liblvm_lvm_vgname_from_pvid, METH_VARARGS },
{ "vgNameFromDevice", (PyCFunction)liblvm_lvm_vgname_from_device, METH_VARARGS },
@@ -1613,6 +1727,15 @@ static PyMethodDef liblvm_lv_methods[] = {
{ NULL, NULL } /* sentinel */
};
+static PyMethodDef liblvm_pv_list_methods[] = {
+ /* pv list methods */
+ { "__enter__", (PyCFunction)liblvm_lvm_pvlist_get, METH_VARARGS },
+ { "__exit__", (PyCFunction)liblvm_lvm_pvlist_put, METH_VARARGS },
+ { "open", (PyCFunction)liblvm_lvm_pvlist_get, METH_VARARGS },
+ { "close", (PyCFunction)liblvm_lvm_pvlist_put, METH_VARARGS },
+ { NULL, NULL }
+};
+
static PyMethodDef liblvm_pv_methods[] = {
/* pv methods */
{ "getName", (PyCFunction)liblvm_lvm_pv_get_name, METH_NOARGS },
@@ -1659,6 +1782,17 @@ static PyTypeObject LibLVMlvType = {
.tp_methods = liblvm_lv_methods,
};
+static PyTypeObject LibLVMpvlistType = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ .tp_name = "liblvm.Liblvm_pvlist",
+ .tp_basicsize = sizeof(pvslistobject),
+ .tp_new = PyType_GenericNew,
+ .tp_dealloc = (destructor)liblvm_pvlist_dealloc,
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+ .tp_doc = "LVM Physical Volume list object",
+ .tp_methods = liblvm_pv_list_methods,
+};
+
static PyTypeObject LibLVMpvType = {
PyObject_HEAD_INIT(&PyType_Type)
.tp_name = "liblvm.Liblvm_pv",
@@ -1716,6 +1850,8 @@ initlvm(void)
return;
if (PyType_Ready(&LibLVMpvsegType) < 0)
return;
+ if (PyType_Ready(&LibLVMpvlistType) < 0)
+ return;
m = Py_InitModule3("lvm", Liblvm_methods, "Liblvm module");
if (m == NULL)
10 years, 11 months