master - python-lvm: Implement proper refcounting for parent objects
by Andy Grover
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=0e47639a44e163...
Commit: 0e47639a44e1630250ea10643f5a440281edfdce
Parent: bf2741376d47411994d4065863acab8e405ff5c7
Author: Andy Grover <agrover(a)redhat.com>
AuthorDate: Wed Oct 17 12:55:25 2012 -0700
Committer: Andy Grover <agrover(a)redhat.com>
CommitterDate: Wed Oct 17 12:55:25 2012 -0700
python-lvm: Implement proper refcounting for parent objects
Our object nesting:
lib -> VG -> LV -> lvseg
-> PV -> pvseg
Implement refcounting and checks to ensure parent objects are not
dealloced before their children. Also ensure calls to self or child's
methods are handled cleanly for objects that have been closed or removed.
Ensure all functions that are object methods have a first parameter named
'self', for consistency
Rename local vars that reference a Python object to '*obj', in order to
differentiate from liblvm handles
Fix a misspelled pv method name
Signed-off-by: Andy Grover <agrover(a)redhat.com>
---
python/liblvm.c | 152 ++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 106 insertions(+), 46 deletions(-)
diff --git a/python/liblvm.c b/python/liblvm.c
index 8a73ced..024d769 100644
--- a/python/liblvm.c
+++ b/python/liblvm.c
@@ -35,21 +35,25 @@ typedef struct {
typedef struct {
PyObject_HEAD
lv_t lv; /* lv handle */
+ vgobject *parent_vgobj;
} lvobject;
typedef struct {
PyObject_HEAD
pv_t pv; /* pv handle */
+ vgobject *parent_vgobj;
} pvobject;
typedef struct {
PyObject_HEAD
lvseg_t lv_seg; /* lv segment handle */
+ lvobject *parent_lvobj;
} lvsegobject;
typedef struct {
PyObject_HEAD
pvseg_t pv_seg; /* pv segment handle */
+ pvobject *parent_pvobj;
} pvsegobject;
static PyTypeObject LibLVMvgType;
@@ -347,6 +351,7 @@ liblvm_vg_dealloc(vgobject *self)
#define VG_VALID(vgobject) \
do { \
+ LVM_VALID(); \
if (!vgobject->vg) { \
PyErr_SetString(PyExc_UnboundLocalError, "VG object invalid"); \
return NULL; \
@@ -785,18 +790,18 @@ liblvm_lvm_vg_set_extent_size(vgobject *self, PyObject *args)
}
static PyObject *
-liblvm_lvm_vg_list_lvs(vgobject *vg)
+liblvm_lvm_vg_list_lvs(vgobject *self)
{
struct dm_list *lvs;
struct lvm_lv_list *lvl;
PyObject * pytuple;
- lvobject * self;
+ lvobject * lvobj;
int i = 0;
- VG_VALID(vg);
+ VG_VALID(self);
/* unlike other LVM api calls, if there are no results, we get NULL */
- lvs = lvm_vg_list_lvs(vg->vg);
+ lvs = lvm_vg_list_lvs(self->vg);
if (!lvs)
return Py_BuildValue("()");
@@ -806,14 +811,17 @@ liblvm_lvm_vg_list_lvs(vgobject *vg)
dm_list_iterate_items(lvl, lvs) {
/* Create and initialize the object */
- self = PyObject_New(lvobject, &LibLVMlvType);
- if (!self) {
+ lvobj = PyObject_New(lvobject, &LibLVMlvType);
+ if (!lvobj) {
Py_DECREF(pytuple);
return NULL;
}
- self->lv = lvl->lv;
- PyTuple_SET_ITEM(pytuple, i, (PyObject *) self);
+ lvobj->parent_vgobj = self;
+ Py_INCREF(lvobj->parent_vgobj);
+
+ lvobj->lv = lvl->lv;
+ PyTuple_SET_ITEM(pytuple, i, (PyObject *) lvobj);
i++;
}
@@ -849,49 +857,53 @@ liblvm_lvm_vg_get_tags(vgobject *self)
}
static PyObject *
-liblvm_lvm_vg_create_lv_linear(vgobject *vg, PyObject *args)
+liblvm_lvm_vg_create_lv_linear(vgobject *self, PyObject *args)
{
const char *vgname;
uint64_t size;
- lvobject *self;
+ lvobject *lvobj;
- VG_VALID(vg);
+ VG_VALID(self);
if (!PyArg_ParseTuple(args, "sl", &vgname, &size)) {
return NULL;
}
- if ((self = PyObject_New(lvobject, &LibLVMlvType)) == NULL)
+ if ((lvobj = PyObject_New(lvobject, &LibLVMlvType)) == NULL)
return NULL;
- if ((self->lv = lvm_vg_create_lv_linear(vg->vg, vgname, size))== NULL) {
+ if ((lvobj->lv = lvm_vg_create_lv_linear(self->vg, vgname, size)) == NULL) {
PyErr_SetObject(LibLVMError, liblvm_get_last_error());
- Py_DECREF(self);
+ Py_DECREF(lvobj);
return NULL;
}
- return (PyObject *)self;
+ lvobj->parent_vgobj = self;
+ Py_INCREF(lvobj->parent_vgobj);
+
+ return (PyObject *)lvobj;
}
static void
liblvm_lv_dealloc(lvobject *self)
{
+ Py_DECREF(self->parent_vgobj);
PyObject_Del(self);
}
static PyObject *
-liblvm_lvm_vg_list_pvs(vgobject *vg)
+liblvm_lvm_vg_list_pvs(vgobject *self)
{
struct dm_list *pvs;
struct lvm_pv_list *pvl;
PyObject * pytuple;
- pvobject * self;
+ pvobject * pvobj;
int i = 0;
- VG_VALID(vg);
+ VG_VALID(self);
/* unlike other LVM api calls, if there are no results, we get NULL */
- pvs = lvm_vg_list_pvs(vg->vg);
+ pvs = lvm_vg_list_pvs(self->vg);
if (!pvs)
return Py_BuildValue("()");
@@ -901,14 +913,17 @@ liblvm_lvm_vg_list_pvs(vgobject *vg)
dm_list_iterate_items(pvl, pvs) {
/* Create and initialize the object */
- self = PyObject_New(pvobject, &LibLVMpvType);
- if (!self) {
+ pvobj = PyObject_New(pvobject, &LibLVMpvType);
+ if (!pvobj) {
Py_DECREF(pytuple);
return NULL;
}
- self->pv = pvl->pv;
- PyTuple_SET_ITEM(pytuple, i, (PyObject *) self);
+ pvobj->parent_vgobj = self;
+ Py_INCREF(pvobj->parent_vgobj);
+
+ pvobj->pv = pvl->pv;
+ PyTuple_SET_ITEM(pytuple, i, (PyObject *) pvobj);
i++;
}
@@ -922,7 +937,7 @@ static PyObject *
liblvm_lvm_lv_from_N(vgobject *self, PyObject *arg, lv_fetch_by_N method)
{
const char *id;
- lvobject *rc;
+ lvobject *lvobj;
lv_t lv = NULL;
VG_VALID(self);
@@ -936,13 +951,16 @@ liblvm_lvm_lv_from_N(vgobject *self, PyObject *arg, lv_fetch_by_N method)
return NULL;
}
- rc = PyObject_New(lvobject, &LibLVMlvType);
- if (!rc) {
+ lvobj = PyObject_New(lvobject, &LibLVMlvType);
+ if (!lvobj) {
return NULL;
}
- rc->lv = lv;
- return (PyObject *)rc;
+ lvobj->parent_vgobj = self;
+ Py_INCREF(lvobj->parent_vgobj);
+
+ lvobj->lv = lv;
+ return (PyObject *)lvobj;
}
static PyObject *
@@ -980,6 +998,7 @@ liblvm_lvm_pv_from_N(vgobject *self, PyObject *arg, pv_fetch_by_N method)
return NULL;
}
+ Py_INCREF(self);
rc->pv = pv;
return (PyObject *)rc;
}
@@ -999,6 +1018,7 @@ liblvm_lvm_pv_from_uuid(vgobject *self, PyObject *arg)
static void
liblvm_pv_dealloc(pvobject *self)
{
+ Py_DECREF(self->parent_vgobj);
PyObject_Del(self);
}
@@ -1006,6 +1026,7 @@ liblvm_pv_dealloc(pvobject *self)
#define LV_VALID(lvobject) \
do { \
+ VG_VALID(lvobject->parent_vgobj); \
if (!lvobject->lv) { \
PyErr_SetString(PyExc_UnboundLocalError, "LV object invalid"); \
return NULL; \
@@ -1242,17 +1263,17 @@ liblvm_lvm_lv_resize(lvobject *self, PyObject *args)
}
static PyObject *
-liblvm_lvm_lv_list_lvsegs(lvobject *lv)
+liblvm_lvm_lv_list_lvsegs(lvobject *self)
{
struct dm_list *lvsegs;
lvseg_list_t *lvsegl;
PyObject * pytuple;
- lvsegobject *self;
+ lvsegobject *lvsegobj;
int i = 0;
- LV_VALID(lv);
+ LV_VALID(self);
- lvsegs = lvm_lv_list_lvsegs(lv->lv);
+ lvsegs = lvm_lv_list_lvsegs(self->lv);
if (!lvsegs) {
return Py_BuildValue("()");
}
@@ -1263,14 +1284,17 @@ liblvm_lvm_lv_list_lvsegs(lvobject *lv)
dm_list_iterate_items(lvsegl, lvsegs) {
/* Create and initialize the object */
- self = PyObject_New(lvsegobject, &LibLVMlvsegType);
- if (!self) {
+ lvsegobj = PyObject_New(lvsegobject, &LibLVMlvsegType);
+ if (!lvsegobj) {
Py_DECREF(pytuple);
return NULL;
}
- self->lv_seg = lvsegl->lvseg;
- PyTuple_SET_ITEM(pytuple, i, (PyObject *) self);
+ lvsegobj->parent_lvobj = self;
+ Py_INCREF(lvsegobj->parent_lvobj);
+
+ lvsegobj->lv_seg = lvsegl->lvseg;
+ PyTuple_SET_ITEM(pytuple, i, (PyObject *) lvsegobj);
i++;
}
@@ -1281,7 +1305,8 @@ liblvm_lvm_lv_list_lvsegs(lvobject *lv)
#define PV_VALID(pvobject) \
do { \
- if (!pvobject->pv || !libh) { \
+ VG_VALID(pvobject->parent_vgobj); \
+ if (!pvobject->pv) { \
PyErr_SetString(PyExc_UnboundLocalError, "PV object invalid"); \
return NULL; \
} \
@@ -1290,18 +1315,24 @@ liblvm_lvm_lv_list_lvsegs(lvobject *lv)
static PyObject *
liblvm_lvm_pv_get_name(pvobject *self)
{
+ PV_VALID(self);
+
return Py_BuildValue("s", lvm_pv_get_name(self->pv));
}
static PyObject *
liblvm_lvm_pv_get_uuid(pvobject *self)
{
+ PV_VALID(self);
+
return Py_BuildValue("s", lvm_pv_get_uuid(self->pv));
}
static PyObject *
liblvm_lvm_pv_get_mda_count(pvobject *self)
{
+ PV_VALID(self);
+
return Py_BuildValue("l", lvm_pv_get_mda_count(self->pv));
}
@@ -1323,18 +1354,24 @@ liblvm_lvm_pv_get_property(pvobject *self, PyObject *args)
static PyObject *
liblvm_lvm_pv_get_dev_size(pvobject *self)
{
+ PV_VALID(self);
+
return Py_BuildValue("l", lvm_pv_get_dev_size(self->pv));
}
static PyObject *
liblvm_lvm_pv_get_size(pvobject *self)
{
+ PV_VALID(self);
+
return Py_BuildValue("l", lvm_pv_get_size(self->pv));
}
static PyObject *
liblvm_lvm_pv_get_free(pvobject *self)
{
+ PV_VALID(self);
+
return Py_BuildValue("l", lvm_pv_get_free(self->pv));
}
@@ -1344,6 +1381,8 @@ liblvm_lvm_pv_resize(pvobject *self, PyObject *args)
uint64_t new_size;
int rval;
+ PV_VALID(self);
+
if (!PyArg_ParseTuple(args, "l", &new_size)) {
return NULL;
}
@@ -1358,17 +1397,17 @@ liblvm_lvm_pv_resize(pvobject *self, PyObject *args)
}
static PyObject *
-liblvm_lvm_lv_list_pvsegs(pvobject *pv)
+liblvm_lvm_pv_list_pvsegs(pvobject *self)
{
struct dm_list *pvsegs;
pvseg_list_t *pvsegl;
PyObject *pytuple;
- pvsegobject *self;
+ pvsegobject *pvsegobj;
int i = 0;
- PV_VALID(pv);
+ PV_VALID(self);
- pvsegs = lvm_pv_list_pvsegs(pv->pv);
+ pvsegs = lvm_pv_list_pvsegs(self->pv);
if (!pvsegs) {
return Py_BuildValue("()");
}
@@ -1379,14 +1418,17 @@ liblvm_lvm_lv_list_pvsegs(pvobject *pv)
dm_list_iterate_items(pvsegl, pvsegs) {
/* Create and initialize the object */
- self = PyObject_New(pvsegobject, &LibLVMpvsegType);
- if (!self) {
+ pvsegobj = PyObject_New(pvsegobject, &LibLVMpvsegType);
+ if (!pvsegobj) {
Py_DECREF(pytuple);
return NULL;
}
- self->pv_seg = pvsegl->pvseg;
- PyTuple_SET_ITEM(pytuple, i, (PyObject *) self);
+ pvsegobj->parent_pvobj = self;
+ Py_INCREF(pvsegobj->parent_pvobj);
+
+ pvsegobj->pv_seg = pvsegl->pvseg;
+ PyTuple_SET_ITEM(pytuple, i, (PyObject *) pvsegobj);
i++;
}
@@ -1395,9 +1437,16 @@ liblvm_lvm_lv_list_pvsegs(pvobject *pv)
/* LV seg methods */
+/*
+ * No way to close/destroy an lvseg, just need to make sure parents are
+ * still good
+ */
+#define LVSEG_VALID(lvsegobject) LV_VALID(lvsegobject->parent_lvobj)
+
static void
liblvm_lvseg_dealloc(lvsegobject *self)
{
+ Py_DECREF(self->parent_lvobj);
PyObject_Del(self);
}
@@ -1407,6 +1456,8 @@ liblvm_lvm_lvseg_get_property(lvsegobject *self, PyObject *args)
const char *name;
struct lvm_property_value prop_value;
+ LVSEG_VALID(self);
+
if (!PyArg_ParseTuple(args, "s", &name))
return NULL;
@@ -1416,9 +1467,16 @@ liblvm_lvm_lvseg_get_property(lvsegobject *self, PyObject *args)
/* PV seg methods */
+/*
+ * No way to close/destroy a pvseg, just need to make sure parents are
+ * still good
+ */
+#define PVSEG_VALID(pvsegobject) PV_VALID(pvsegobject->parent_pvobj)
+
static void
liblvm_pvseg_dealloc(pvsegobject *self)
{
+ Py_DECREF(self->parent_pvobj);
PyObject_Del(self);
}
@@ -1428,6 +1486,8 @@ liblvm_lvm_pvseg_get_property(pvsegobject *self, PyObject *args)
const char *name;
struct lvm_property_value prop_value;
+ PVSEG_VALID(self);
+
if (!PyArg_ParseTuple(args, "s", &name))
return NULL;
@@ -1522,7 +1582,7 @@ static PyMethodDef liblvm_pv_methods[] = {
{ "getDevSize", (PyCFunction)liblvm_lvm_pv_get_dev_size, METH_NOARGS },
{ "getFree", (PyCFunction)liblvm_lvm_pv_get_free, METH_NOARGS },
{ "resize", (PyCFunction)liblvm_lvm_pv_resize, METH_VARARGS },
- { "listPVsegs", (PyCFunction)liblvm_lvm_lv_list_pvsegs, METH_NOARGS },
+ { "listPVsegs", (PyCFunction)liblvm_lvm_pv_list_pvsegs, METH_NOARGS },
{ NULL, NULL} /* sentinel */
};
11 years, 5 months
master - Use lv_is_active instead of lv_info()
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=bf2741376d4741...
Commit: bf2741376d47411994d4065863acab8e405ff5c7
Parent: e431b19bac29cf8fc21530118eb283b6ae703cbb
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Jan 31 23:42:53 2012 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed Oct 17 15:42:31 2012 +0200
Use lv_is_active instead of lv_info()
Usage of lv_is_active makes it more obvious what is being checked.
---
WHATS_NEW | 1 +
lib/metadata/lv_manip.c | 5 ++---
lib/metadata/mirror.c | 9 +++------
lib/report/report.c | 3 +--
4 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 370c7e5..8ba9f2d 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.99 -
===================================
+ Use lv_is_active() instead of lv_info() call.
Cleanup some log_error message and use log_warn instead.
Version 2.02.98 - 15th October 2012
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index d2aca00..32a207d 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -4218,7 +4218,6 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg, struct l
struct logical_volume *pool_lv;
struct lv_list *lvl;
int origin_active = 0;
- struct lvinfo info;
if (new_lv_name && find_lv_in_vg(vg, new_lv_name)) {
log_error("Logical volume \"%s\" already exists in "
@@ -4350,12 +4349,12 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg, struct l
log_warn("WARNING: See global/mirror_segtype_default in lvm.conf.");
}
- if (!lv_info(cmd, org, 0, &info, 0, 0)) {
+ if (!lv_is_active(org)) {
log_error("Check for existence of active snapshot "
"origin '%s' failed.", org->name);
return NULL;
}
- origin_active = info.exists;
+ origin_active = 1;
if (vg_is_clustered(vg) &&
!lv_is_active_exclusive_locally(org)) {
diff --git a/lib/metadata/mirror.c b/lib/metadata/mirror.c
index c4683df..084c93a 100644
--- a/lib/metadata/mirror.c
+++ b/lib/metadata/mirror.c
@@ -282,7 +282,6 @@ static int _init_mirror_log(struct cmd_context *cmd,
struct dm_list *tags, int remove_on_failure)
{
struct str_list *sl;
- struct lvinfo info;
uint64_t orig_status = log_lv->status;
int was_active = 0;
@@ -298,14 +297,13 @@ static int _init_mirror_log(struct cmd_context *cmd,
}
/* If the LV is active, deactivate it first. */
- if (lv_info(cmd, log_lv, 0, &info, 0, 0) && info.exists) {
- (void)deactivate_lv(cmd, log_lv);
+ if (lv_is_active(log_lv)) {
/*
* FIXME: workaround to fail early
* Ensure that log is really deactivated because deactivate_lv
* on cluster do not fail if there is log_lv with different UUID.
*/
- if (lv_info(cmd, log_lv, 0, &info, 0, 0) && info.exists) {
+ if (!deactivate_lv(cmd, log_lv)) {
log_error("Aborting. Unable to deactivate mirror log.");
goto revert_new_lv;
}
@@ -1714,7 +1712,6 @@ int remove_mirror_log(struct cmd_context *cmd,
int force)
{
percent_t sync_percent;
- struct lvinfo info;
struct volume_group *vg = lv->vg;
/* Unimplemented features */
@@ -1724,7 +1721,7 @@ int remove_mirror_log(struct cmd_context *cmd,
}
/* Had disk log, switch to core. */
- if (lv_info(cmd, lv, 0, &info, 0, 0) && info.exists) {
+ if (lv_is_active(lv)) {
if (!lv_mirror_percent(cmd, lv, 0, &sync_percent,
NULL)) {
log_error("Unable to determine mirror sync status.");
diff --git a/lib/report/report.c b/lib/report/report.c
index eeca282..b1e2bc1 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -830,7 +830,6 @@ static int _snpercent_disp(struct dm_report *rh __attribute__((unused)), struct
const void *data, void *private __attribute__((unused)))
{
const struct logical_volume *lv = (const struct logical_volume *) data;
- struct lvinfo info;
percent_t snap_percent;
uint64_t *sortval;
char *repstr;
@@ -847,7 +846,7 @@ static int _snpercent_disp(struct dm_report *rh __attribute__((unused)), struct
}
if ((!lv_is_cow(lv) && !lv_is_merging_origin(lv)) ||
- !lv_info(lv->vg->cmd, lv, 0, &info, 0, 0) || !info.exists) {
+ !lv_is_active(lv)) {
*sortval = UINT64_C(0);
dm_report_field_set_value(field, "", sortval);
return 1;
11 years, 5 months
master - cleanup: move log_error upward in code stack
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e431b19bac29cf...
Commit: e431b19bac29cf8fc21530118eb283b6ae703cbb
Parent: f260f99d5791791f0aef2172b199fa5cdb7f6102
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Oct 16 10:20:02 2012 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed Oct 17 15:41:44 2012 +0200
cleanup: move log_error upward in code stack
Report log_error earlier.
---
lib/metadata/metadata.c | 21 +++++++++------------
1 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 0b3158a..549a356 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -450,8 +450,11 @@ static int validate_new_vg_name(struct cmd_context *cmd, const char *vg_name)
{
static char vg_path[PATH_MAX];
- if (!validate_name(vg_name))
- return_0;
+ if (!validate_name(vg_name)) {
+ log_error("New volume group name \"%s\" is invalid.",
+ vg_name);
+ return 0;
+ }
snprintf(vg_path, sizeof(vg_path), "%s%s", cmd->dev_dir, vg_name);
if (path_exists(vg_path)) {
@@ -479,11 +482,8 @@ int validate_vg_rename_params(struct cmd_context *cmd,
return 0;
}
- if (!validate_new_vg_name(cmd, vg_name_new)) {
- log_error("New volume group name \"%s\" is invalid",
- vg_name_new);
- return 0;
- }
+ if (!validate_new_vg_name(cmd, vg_name_new))
+ return_0;
if (!strcmp(vg_name_old, vg_name_new)) {
log_error("Old and new volume group names must differ");
@@ -819,11 +819,8 @@ const char *strip_dir(const char *vg_name, const char *dev_dir)
int vgcreate_params_validate(struct cmd_context *cmd,
struct vgcreate_params *vp)
{
- if (!validate_new_vg_name(cmd, vp->vg_name)) {
- log_error("New volume group name \"%s\" is invalid",
- vp->vg_name);
- return 0;
- }
+ if (!validate_new_vg_name(cmd, vp->vg_name))
+ return_0;
if (vp->alloc == ALLOC_INHERIT) {
log_error("Volume Group allocation policy cannot inherit "
11 years, 5 months
master - cleanup: switch log_error to log_warn
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=f260f99d579179...
Commit: f260f99d5791791f0aef2172b199fa5cdb7f6102
Parent: b89963a7c3aea97ff11083a13dff718b5895ccc9
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Oct 16 10:14:41 2012 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed Oct 17 15:41:35 2012 +0200
cleanup: switch log_error to log_warn
Use log_warn to print non-fatal warning messages.
Use of log_error would confuse checker for testing
whether proper error has been reported for some real error.
---
WHATS_NEW | 4 ++++
lib/device/dev-cache.c | 14 +++++++-------
lib/format_text/flags.c | 4 ++--
lib/metadata/lv_manip.c | 4 ++--
lib/metadata/raid_manip.c | 4 ++--
libdm/libdm-report.c | 4 ++--
tools/lvconvert.c | 11 +++++------
tools/pvchange.c | 8 ++++----
tools/toollib.c | 6 +++---
tools/vgchange.c | 16 ++++++++--------
10 files changed, 39 insertions(+), 36 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index c0ae3df..370c7e5 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,3 +1,7 @@
+Version 2.02.99 -
+===================================
+ Cleanup some log_error message and use log_warn instead.
+
Version 2.02.98 - 15th October 2012
===================================
Switch from DEBUG() to DEBUGLOG() in lvmetad as -DDEBUG is already used.
diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c
index d08b07f..2b2d32b 100644
--- a/lib/device/dev-cache.c
+++ b/lib/device/dev-cache.c
@@ -800,13 +800,13 @@ int dev_cache_add_dir(const char *path)
struct stat st;
if (stat(path, &st)) {
- log_error("Ignoring %s: %s", path, strerror(errno));
+ log_warn("Ignoring %s: %s.", path, strerror(errno));
/* But don't fail */
return 1;
}
if (!S_ISDIR(st.st_mode)) {
- log_error("Ignoring %s: Not a directory", path);
+ log_warn("Ignoring %s: Not a directory.", path);
return 1;
}
@@ -826,13 +826,13 @@ int dev_cache_add_loopfile(const char *path)
struct stat st;
if (stat(path, &st)) {
- log_error("Ignoring %s: %s", path, strerror(errno));
+ log_warn("Ignoring %s: %s.", path, strerror(errno));
/* But don't fail */
return 1;
}
if (!S_ISREG(st.st_mode)) {
- log_error("Ignoring %s: Not a regular file", path);
+ log_warn("Ignoring %s: Not a regular file.", path);
return 1;
}
@@ -873,9 +873,9 @@ const char *dev_name_confirmed(struct device *dev, int quiet)
name, (int) MAJOR(dev->dev),
(int) MINOR(dev->dev));
else
- log_error("Path %s no longer valid for device(%d,%d)",
- name, (int) MAJOR(dev->dev),
- (int) MINOR(dev->dev));
+ log_warn("Path %s no longer valid for device(%d,%d)",
+ name, (int) MAJOR(dev->dev),
+ (int) MINOR(dev->dev));
/* Remove the incorrect hash entry */
dm_hash_remove(_cache.names, name);
diff --git a/lib/format_text/flags.c b/lib/format_text/flags.c
index dbca8c9..a3a3d0e 100644
--- a/lib/format_text/flags.c
+++ b/lib/format_text/flags.c
@@ -140,8 +140,8 @@ int print_flags(uint64_t status, int type, char *buffer, size_t size)
return 0;
if (status)
- log_error("Metadata inconsistency: Not all flags successfully "
- "exported.");
+ log_warn("Metadata inconsistency: Not all flags successfully "
+ "exported.");
return 1;
}
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 5f006ab..d2aca00 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -1104,7 +1104,7 @@ static int _alloc_parallel_area(struct alloc_handle *ah, uint32_t max_to_allocat
total_area_count = ah->area_count + alloc_state->log_area_count_still_needed;
total_area_count += ah->parity_count;
if (!total_area_count) {
- log_error(INTERNAL_ERROR "_alloc_parallel_area called without any allocation to do.");
+ log_warn(INTERNAL_ERROR "_alloc_parallel_area called without any allocation to do.");
return 1;
}
@@ -2024,7 +2024,7 @@ static int _allocate(struct alloc_handle *ah,
alloc_state.allocated = lv ? lv->le_count : 0;
if (alloc_state.allocated >= ah->new_extents && !ah->log_area_count) {
- log_error("_allocate called with no work to do!");
+ log_warn("_allocate called with no work to do!");
return 1;
}
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index c7910e8..b9f75ff 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -1122,8 +1122,8 @@ int lv_raid_change_image_count(struct logical_volume *lv,
uint32_t old_count = lv_raid_image_count(lv);
if (old_count == new_count) {
- log_error("%s/%s already has image count of %d",
- lv->vg->name, lv->name, new_count);
+ log_warn("%s/%s already has image count of %d.",
+ lv->vg->name, lv->name, new_count);
return 1;
}
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index 0bafa86..0984416 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -461,8 +461,8 @@ static int _add_sort_key(struct dm_report *rh, uint32_t field_num,
return 1;
if (found->flags & FLD_SORT_KEY) {
- log_error("dm_report: Ignoring duplicate sort field: %s",
- rh->fields[field_num].id);
+ log_warn("dm_report: Ignoring duplicate sort field: %s.",
+ rh->fields[field_num].id);
return 1;
}
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 132a69d..f23fc4b 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -1171,8 +1171,8 @@ static int _lvconvert_mirrors_aux(struct cmd_context *cmd,
uint32_t old_log_count = _get_log_count(lv);
if ((lp->mirrors == 1) && !(lv->status & MIRRORED)) {
- log_error("Logical volume %s is already not mirrored.",
- lv->name);
+ log_warn("Logical volume %s is already not mirrored.",
+ lv->name);
return 1;
}
@@ -1403,7 +1403,7 @@ static int _lvconvert_mirrors_repair(struct cmd_context *cmd,
lv_check_transient(lv); /* TODO check this in lib for all commands? */
if (!(lv->status & PARTIAL_LV)) {
- log_error("%s is consistent. Nothing to repair.", lv->name);
+ log_warn("%s is consistent. Nothing to repair.", lv->name);
return 1;
}
@@ -1663,9 +1663,8 @@ static int lvconvert_raid(struct logical_volume *lv, struct lvconvert_params *lp
/* "warn" if policy not set to replace */
if (arg_count(cmd, use_policies_ARG))
- log_error("Use 'lvconvert --repair %s/%s' to "
- "replace failed device",
- lv->vg->name, lv->name);
+ log_warn("Use 'lvconvert --repair %s/%s' to replace "
+ "failed device.", lv->vg->name, lv->name);
return 1;
}
diff --git a/tools/pvchange.c b/tools/pvchange.c
index 70f1e62..c282ec0 100644
--- a/tools/pvchange.c
+++ b/tools/pvchange.c
@@ -73,14 +73,14 @@ static int _pvchange_single(struct cmd_context *cmd, struct volume_group *vg,
/* change allocatability for a PV */
if (allocatable && (pv_status(pv) & ALLOCATABLE_PV)) {
- log_error("Physical volume \"%s\" is already "
- "allocatable", pv_name);
+ log_warn("Physical volume \"%s\" is already "
+ "allocatable.", pv_name);
return 1;
}
if (!allocatable && !(pv_status(pv) & ALLOCATABLE_PV)) {
- log_error("Physical volume \"%s\" is already "
- "unallocatable", pv_name);
+ log_warn("Physical volume \"%s\" is already "
+ "unallocatable.", pv_name);
return 1;
}
diff --git a/tools/toollib.c b/tools/toollib.c
index 48b9a86..62f59d8 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1076,18 +1076,18 @@ static int _create_pv_entry(struct dm_pool *mem, struct pv_list *pvl,
pvname = pv_dev_name(pvl->pv);
if (allocatable_only && !(pvl->pv->status & ALLOCATABLE_PV)) {
- log_error("Physical volume %s not allocatable", pvname);
+ log_warn("Physical volume %s not allocatable.", pvname);
return 1;
}
if (allocatable_only && is_missing_pv(pvl->pv)) {
- log_error("Physical volume %s is missing", pvname);
+ log_warn("Physical volume %s is missing.", pvname);
return 1;
}
if (allocatable_only &&
(pvl->pv->pe_count == pvl->pv->pe_alloc_count)) {
- log_error("No free extents on physical volume \"%s\"", pvname);
+ log_warn("No free extents on physical volume \"%s\".", pvname);
return 1;
}
diff --git a/tools/vgchange.c b/tools/vgchange.c
index a897a85..ccf31da 100644
--- a/tools/vgchange.c
+++ b/tools/vgchange.c
@@ -368,16 +368,16 @@ static int _vgchange_pesize(struct cmd_context *cmd, struct volume_group *vg)
uint32_t extent_size;
if (arg_uint64_value(cmd, physicalextentsize_ARG, 0) > MAX_EXTENT_SIZE) {
- log_error("Physical extent size cannot be larger than %s",
- display_size(cmd, (uint64_t) MAX_EXTENT_SIZE));
+ log_warn("Physical extent size cannot be larger than %s.",
+ display_size(cmd, (uint64_t) MAX_EXTENT_SIZE));
return 1;
}
extent_size = arg_uint_value(cmd, physicalextentsize_ARG, 0);
/* FIXME: remove check - redundant with vg_change_pesize */
if (extent_size == vg->extent_size) {
- log_error("Physical extent size of VG %s is already %s",
- vg->name, display_size(cmd, (uint64_t) extent_size));
+ log_warn("Physical extent size of VG %s is already %s.",
+ vg->name, display_size(cmd, (uint64_t) extent_size));
return 1;
}
@@ -427,11 +427,11 @@ static int _vgchange_metadata_copies(struct cmd_context *cmd,
if (mda_copies == vg_mda_copies(vg)) {
if (vg_mda_copies(vg) == VGMETADATACOPIES_UNMANAGED)
- log_error("Number of metadata copies for VG %s is already unmanaged.",
- vg->name);
+ log_warn("Number of metadata copies for VG %s is already unmanaged.",
+ vg->name);
else
- log_error("Number of metadata copies for VG %s is already %" PRIu32,
- vg->name, mda_copies);
+ log_warn("Number of metadata copies for VG %s is already %u.",
+ vg->name, mda_copies);
return 1;
}
11 years, 5 months
master - cleanup: swap return values
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b89963a7c3aea9...
Commit: b89963a7c3aea97ff11083a13dff718b5895ccc9
Parent: 10ba799ab08001d5435425e65f039f20cadd306e
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Oct 16 10:07:27 2012 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed Oct 17 15:37:26 2012 +0200
cleanup: swap return values
Use lvm standard return code for success/fail 1/0.
---
lib/config/config.c | 4 ++--
lib/metadata/metadata.c | 10 +++++-----
liblvm/lvm_base.c | 2 +-
tools/lvmcmdline.c | 2 +-
tools/toollib.c | 10 +++++-----
tools/vgcreate.c | 4 ++--
tools/vgsplit.c | 4 ++--
7 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/lib/config/config.c b/lib/config/config.c
index 00bfcab..0820594 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -177,12 +177,12 @@ int override_config_tree_from_string(struct cmd_context *cmd,
if (!(cft_new = dm_config_from_string(config_settings))) {
log_error("Failed to set overridden configuration entries.");
- return 1;
+ return 0;
}
cmd->cft = dm_config_insert_cascaded_tree(cft_new, cmd->cft);
- return 0;
+ return 1;
}
int config_file_read_fd(struct dm_config_tree *cft, struct device *dev,
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index c210a63..0b3158a 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -822,18 +822,18 @@ int vgcreate_params_validate(struct cmd_context *cmd,
if (!validate_new_vg_name(cmd, vp->vg_name)) {
log_error("New volume group name \"%s\" is invalid",
vp->vg_name);
- return 1;
+ return 0;
}
if (vp->alloc == ALLOC_INHERIT) {
log_error("Volume Group allocation policy cannot inherit "
"from anything");
- return 1;
+ return 0;
}
if (!vp->extent_size) {
log_error("Physical extent size may not be zero");
- return 1;
+ return 0;
}
if (!(cmd->fmt->features & FMT_UNLIMITED_VOLS)) {
@@ -843,11 +843,11 @@ int vgcreate_params_validate(struct cmd_context *cmd,
vp->max_pv = 255;
if (vp->max_lv > 255 || vp->max_pv > 255) {
log_error("Number of volumes may not exceed 255");
- return 1;
+ return 0;
}
}
- return 0;
+ return 1;
}
/*
diff --git a/liblvm/lvm_base.c b/liblvm/lvm_base.c
index 01ea0d7..b4911df 100644
--- a/liblvm/lvm_base.c
+++ b/liblvm/lvm_base.c
@@ -89,7 +89,7 @@ int lvm_config_reload(lvm_t libh)
int lvm_config_override(lvm_t libh, const char *config_settings)
{
struct cmd_context *cmd = (struct cmd_context *)libh;
- if (override_config_tree_from_string(cmd, config_settings))
+ if (!override_config_tree_from_string(cmd, config_settings))
return -1;
return 0;
}
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 39a8c58..3720d7f 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -1066,7 +1066,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
set_cmd_name(cmd->command->name);
if (arg_count(cmd, config_ARG))
- if (override_config_tree_from_string(cmd, arg_str_value(cmd, config_ARG, ""))) {
+ if (!override_config_tree_from_string(cmd, arg_str_value(cmd, config_ARG, ""))) {
ret = EINVALID_CMD_LINE;
goto_out;
}
diff --git a/tools/toollib.c b/tools/toollib.c
index 3fe1c14..48b9a86 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1264,23 +1264,23 @@ int vgcreate_params_set_from_args(struct cmd_context *cmd,
if (arg_sign_value(cmd, physicalextentsize_ARG, SIGN_NONE) == SIGN_MINUS) {
log_error("Physical extent size may not be negative");
- return 1;
+ return 0;
}
if (arg_uint64_value(cmd, physicalextentsize_ARG, 0) > MAX_EXTENT_SIZE) {
log_error("Physical extent size cannot be larger than %s",
display_size(cmd, (uint64_t) MAX_EXTENT_SIZE));
- return 1;
+ return 0;
}
if (arg_sign_value(cmd, maxlogicalvolumes_ARG, SIGN_NONE) == SIGN_MINUS) {
log_error("Max Logical Volumes may not be negative");
- return 1;
+ return 0;
}
if (arg_sign_value(cmd, maxphysicalvolumes_ARG, SIGN_NONE) == SIGN_MINUS) {
log_error("Max Physical Volumes may not be negative");
- return 1;
+ return 0;
}
if (arg_count(cmd, metadatacopies_ARG)) {
@@ -1295,7 +1295,7 @@ int vgcreate_params_set_from_args(struct cmd_context *cmd,
DEFAULT_VGMETADATACOPIES);
}
- return 0;
+ return 1;
}
int lv_refresh(struct cmd_context *cmd, struct logical_volume *lv)
diff --git a/tools/vgcreate.c b/tools/vgcreate.c
index 2b9fb2f..8ce7803 100644
--- a/tools/vgcreate.c
+++ b/tools/vgcreate.c
@@ -43,10 +43,10 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
vgcreate_params_set_defaults(&vp_def, NULL);
vp_def.vg_name = vg_name;
- if (vgcreate_params_set_from_args(cmd, &vp_new, &vp_def))
+ if (!vgcreate_params_set_from_args(cmd, &vp_new, &vp_def))
return EINVALID_CMD_LINE;
- if (vgcreate_params_validate(cmd, &vp_new))
+ if (!vgcreate_params_validate(cmd, &vp_new))
return EINVALID_CMD_LINE;
lvmcache_seed_infos_from_lvmetad(cmd);
diff --git a/tools/vgsplit.c b/tools/vgsplit.c
index 3bbb9fa..b52c2f8 100644
--- a/tools/vgsplit.c
+++ b/tools/vgsplit.c
@@ -383,12 +383,12 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv)
} else {
vgcreate_params_set_defaults(&vp_def, vg_from);
vp_def.vg_name = vg_name_to;
- if (vgcreate_params_set_from_args(cmd, &vp_new, &vp_def)) {
+ if (!vgcreate_params_set_from_args(cmd, &vp_new, &vp_def)) {
r = EINVALID_CMD_LINE;
goto_bad;
}
- if (vgcreate_params_validate(cmd, &vp_new)) {
+ if (!vgcreate_params_validate(cmd, &vp_new)) {
r = EINVALID_CMD_LINE;
goto_bad;
}
11 years, 5 months
master - python-lvm: Update example to work with lvm object removal.
by Andy Grover
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=10ba799ab08001...
Commit: 10ba799ab08001d5435425e65f039f20cadd306e
Parent: 12b631a6768e6f2a2005ef8ea91c0afbc2455c54
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Mon Oct 15 13:54:19 2012 -0700
Committer: Andy Grover <agrover(a)redhat.com>
CommitterDate: Mon Oct 15 14:11:10 2012 -0700
python-lvm: Update example to work with lvm object removal.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
Signed-off-by: Andy Grover <agrover(a)redhat.com>
---
python/example.py | 35 +++++++++++++++--------------------
1 files changed, 15 insertions(+), 20 deletions(-)
diff --git a/python/example.py b/python/example.py
index 67bb7e4..5c14ee1 100644
--- a/python/example.py
+++ b/python/example.py
@@ -31,9 +31,9 @@ def print_pv(pv):
#Dump some information about a specific volume group
-def print_vg(h, vg_name):
+def print_vg(vg_name):
#Open read only
- vg = h.vgOpen(vg_name, 'r')
+ vg = lvm.vgOpen(vg_name, 'r')
print 'Volume group:', vg_name, 'Size: ', vg.getSize()
@@ -55,13 +55,13 @@ def print_vg(h, vg_name):
vg.close()
#Returns the name of a vg with space available
-def find_vg_with_free_space(h):
+def find_vg_with_free_space():
free_space = 0
rc = None
- vg_names = l.listVgNames()
+ vg_names = lvm.listVgNames()
for v in vg_names:
- vg = h.vgOpen(v, 'r')
+ vg = lvm.vgOpen(v, 'r')
c_free = vg.getFreeSize()
if c_free > free_space:
free_space = c_free
@@ -72,13 +72,13 @@ def find_vg_with_free_space(h):
#Walk through the volume groups and fine one with space in which we can
#create a new logical volume
-def create_delete_logical_volume(h):
- vg_name = find_vg_with_free_space(h)
+def create_delete_logical_volume():
+ vg_name = find_vg_with_free_space()
print 'Using volume group ', vg_name, ' for example'
if vg_name:
- vg = h.vgOpen(vg_name, 'w')
+ vg = lvm.vgOpen(vg_name, 'w')
lv = vg.createLvLinear('python_lvm_ok_to_delete', vg.getFreeSize())
if lv:
@@ -93,11 +93,11 @@ def create_delete_logical_volume(h):
#Remove tag
lv.removeTag(t)
+ lv.deactivate()
+
#Try to rename
- lv.rename("python_lvm_ok_to_be_removed_shortly")
+ lv.rename("python_lvm_renamed")
print 'LV name= ', lv.getName()
-
- lv.deactivate()
lv.remove()
vg.close()
@@ -105,21 +105,16 @@ def create_delete_logical_volume(h):
print 'No free space available to create demo lv!'
if __name__ == '__main__':
- #Create a new LVM instance
- l = lvm.Liblvm()
-
#What version
- print 'lvm version=', l.getVersion()
+ print 'lvm version=', lvm.getVersion()
#Get a list of volume group names
- vg_names = l.listVgNames()
+ vg_names = lvm.listVgNames()
#For each volume group display some information about each of them
for vg_i in vg_names:
- print_vg(l, vg_i)
+ print_vg(vg_i)
#Demo creating a logical volume
- create_delete_logical_volume(l)
+ create_delete_logical_volume()
- #Close
- l.close()
11 years, 5 months
master - python-lvm: whitespace and Yoda conditionals
by Andy Grover
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=12b631a6768e6f...
Commit: 12b631a6768e6f2a2005ef8ea91c0afbc2455c54
Parent: 84a4d4b970bb9aaf540ad5fa82276b1caf5aa9bd
Author: Andy Grover <agrover(a)redhat.com>
AuthorDate: Mon Oct 15 13:34:43 2012 -0700
Committer: Andy Grover <agrover(a)redhat.com>
CommitterDate: Mon Oct 15 14:11:10 2012 -0700
python-lvm: whitespace and Yoda conditionals
Signed-off-by: Andy Grover <agrover(a)redhat.com>
---
python/liblvm.c | 50 ++++++++++++++++++++++++--------------------------
1 files changed, 24 insertions(+), 26 deletions(-)
diff --git a/python/liblvm.c b/python/liblvm.c
index 4518cf4..8a73ced 100644
--- a/python/liblvm.c
+++ b/python/liblvm.c
@@ -75,7 +75,7 @@ liblvm_get_last_error(void)
LVM_VALID();
- if((info = PyTuple_New(2)) == NULL)
+ if ((info = PyTuple_New(2)) == NULL)
return NULL;
PyTuple_SetItem(info, 0, PyInt_FromLong((long) lvm_errno(libh)));
@@ -174,7 +174,7 @@ liblvm_lvm_vgname_from_pvid(PyObject *self, PyObject *arg)
if (!PyArg_ParseTuple(arg, "s", &pvid))
return NULL;
- if((vgname = lvm_vgname_from_pvid(libh, pvid)) == NULL) {
+ if ((vgname = lvm_vgname_from_pvid(libh, pvid)) == NULL) {
PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -193,7 +193,7 @@ liblvm_lvm_vgname_from_device(PyObject *self, PyObject *arg)
if (!PyArg_ParseTuple(arg, "s", &device))
return NULL;
- if((vgname = lvm_vgname_from_device(libh, device)) == NULL) {
+ if ((vgname = lvm_vgname_from_device(libh, device)) == NULL) {
PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -233,7 +233,7 @@ liblvm_lvm_config_reload(void)
LVM_VALID();
- if((rval = lvm_config_reload(libh)) == -1) {
+ if ((rval = lvm_config_reload(libh)) == -1) {
PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -250,7 +250,7 @@ liblvm_lvm_scan(void)
LVM_VALID();
- if((rval = lvm_scan(libh)) == -1) {
+ if ((rval = lvm_scan(libh)) == -1) {
PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -603,7 +603,7 @@ get_property(struct lvm_property_value *prop)
PyObject *pytuple;
PyObject *setable;
- if( !prop->is_valid ) {
+ if (!prop->is_valid) {
PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -612,7 +612,7 @@ get_property(struct lvm_property_value *prop)
if (!pytuple)
return NULL;
- if( prop->is_integer ) {
+ if (prop->is_integer) {
PyTuple_SET_ITEM(pytuple, 0, Py_BuildValue("K", prop->value.integer));
} else {
PyTuple_SET_ITEM(pytuple, 0, PyString_FromString(prop->value.string));
@@ -661,11 +661,11 @@ liblvm_lvm_vg_set_property(vgobject *self, PyObject *args)
lvm_property = lvm_vg_get_property(self->vg, property_name);
- if( !lvm_property.is_valid ) {
+ if (!lvm_property.is_valid ) {
goto lvmerror;
}
- if(PyObject_IsInstance(variant_type_arg, (PyObject*)&PyString_Type)) {
+ if (PyObject_IsInstance(variant_type_arg, (PyObject*)&PyString_Type)) {
if (!lvm_property.is_string) {
PyErr_Format(PyExc_ValueError, "Property requires string value");
@@ -676,7 +676,7 @@ liblvm_lvm_vg_set_property(vgobject *self, PyObject *args)
leak when calling into set_property, need to verify*/
string_value = strdup(PyString_AsString(variant_type_arg));
lvm_property.value.string = string_value;
- if(!lvm_property.value.string) {
+ if (!lvm_property.value.string) {
PyErr_NoMemory();
goto bail;
}
@@ -688,14 +688,12 @@ liblvm_lvm_vg_set_property(vgobject *self, PyObject *args)
goto bail;
}
- if(PyObject_IsInstance(variant_type_arg, (PyObject*)&PyInt_Type)) {
+ if (PyObject_IsInstance(variant_type_arg, (PyObject*)&PyInt_Type)) {
int temp_py_int = PyInt_AsLong(variant_type_arg);
/* -1 could be valid, need to see if an exception was gen. */
- if( -1 == temp_py_int ) {
- if( PyErr_Occurred() ) {
- goto bail;
- }
+ if (temp_py_int == -1 && PyErr_Occurred()) {
+ goto bail;
}
if (temp_py_int < 0) {
@@ -704,10 +702,10 @@ liblvm_lvm_vg_set_property(vgobject *self, PyObject *args)
}
lvm_property.value.integer = temp_py_int;
- } else if(PyObject_IsInstance(variant_type_arg, (PyObject*)&PyLong_Type)){
+ } else if (PyObject_IsInstance(variant_type_arg, (PyObject*)&PyLong_Type)){
/* This will fail on negative numbers */
unsigned long long temp_py_long = PyLong_AsUnsignedLongLong(variant_type_arg);
- if( (unsigned long long)-1 == temp_py_long ) {
+ if (temp_py_long == (unsigned long long)-1) {
goto bail;
}
@@ -718,11 +716,11 @@ liblvm_lvm_vg_set_property(vgobject *self, PyObject *args)
}
}
- if( -1 == lvm_vg_set_property(self->vg, property_name, &lvm_property) ) {
+ if (lvm_vg_set_property(self->vg, property_name, &lvm_property) == -1) {
goto lvmerror;
}
- if( -1 == lvm_vg_write(self->vg)) {
+ if (lvm_vg_write(self->vg) == -1) {
goto lvmerror;
}
@@ -734,7 +732,7 @@ lvmerror:
PyErr_SetObject(LibLVMError, liblvm_get_last_error());
bail:
free(string_value);
- if( variant_type_arg ) {
+ if (variant_type_arg) {
Py_DECREF(variant_type_arg);
variant_type_arg = NULL;
}
@@ -933,13 +931,13 @@ liblvm_lvm_lv_from_N(vgobject *self, PyObject *arg, lv_fetch_by_N method)
return NULL;
lv = method(self->vg, id);
- if( !lv ) {
+ if (!lv) {
PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
rc = PyObject_New(lvobject, &LibLVMlvType);
- if( !rc ) {
+ if (!rc) {
return NULL;
}
@@ -972,13 +970,13 @@ liblvm_lvm_pv_from_N(vgobject *self, PyObject *arg, pv_fetch_by_N method)
return NULL;
pv = method(self->vg, id);
- if( !pv ) {
+ if (!pv) {
PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
rc = PyObject_New(pvobject, &LibLVMpvType);
- if( !rc ) {
+ if (!rc) {
return NULL;
}
@@ -1255,7 +1253,7 @@ liblvm_lvm_lv_list_lvsegs(lvobject *lv)
LV_VALID(lv);
lvsegs = lvm_lv_list_lvsegs(lv->lv);
- if(!lvsegs) {
+ if (!lvsegs) {
return Py_BuildValue("()");
}
@@ -1371,7 +1369,7 @@ liblvm_lvm_lv_list_pvsegs(pvobject *pv)
PV_VALID(pv);
pvsegs = lvm_pv_list_pvsegs(pv->pv);
- if(!pvsegs) {
+ if (!pvsegs) {
return Py_BuildValue("()");
}
11 years, 5 months
master - python-lvm: Remove liblvm object
by Andy Grover
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=84a4d4b970bb9a...
Commit: 84a4d4b970bb9aaf540ad5fa82276b1caf5aa9bd
Parent: 831ce3cda941f02556dd8c4a407754397df17997
Author: Andy Grover <agrover(a)redhat.com>
AuthorDate: Mon Oct 15 13:26:01 2012 -0700
Committer: Andy Grover <agrover(a)redhat.com>
CommitterDate: Mon Oct 15 14:11:10 2012 -0700
python-lvm: Remove liblvm object
Instead of requiring users to create a liblvm object, and then calling
methods on it, the module acquires a liblvm handle as part of
initialization. This makes it impossible to instantiate a liblvm object
with a different systemdir, but there is an alternate envvar method for
that obscure use case.
Signed-off-by: Andy Grover <agrover(a)redhat.com>
---
python/liblvm.c | 269 ++++++++++++++++++++-----------------------------------
1 files changed, 97 insertions(+), 172 deletions(-)
diff --git a/python/liblvm.c b/python/liblvm.c
index cbfa170..4518cf4 100644
--- a/python/liblvm.c
+++ b/python/liblvm.c
@@ -24,39 +24,32 @@
#include <Python.h>
#include "lvm2app.h"
-typedef struct {
- PyObject_HEAD
- lvm_t libh; /* lvm lib handle */
-} lvmobject;
+static lvm_t libh;
+
typedef struct {
PyObject_HEAD
vg_t vg; /* vg handle */
- lvmobject *lvm_obj;
} vgobject;
typedef struct {
PyObject_HEAD
lv_t lv; /* lv handle */
- lvmobject *lvm_obj;
} lvobject;
typedef struct {
PyObject_HEAD
pv_t pv; /* pv handle */
- lvmobject *lvm_obj;
} pvobject;
typedef struct {
PyObject_HEAD
lvseg_t lv_seg; /* lv segment handle */
- lvmobject *lvm_obj;
} lvsegobject;
typedef struct {
PyObject_HEAD
pvseg_t pv_seg; /* pv segment handle */
- lvmobject *lvm_obj;
} pvsegobject;
static PyTypeObject LibLVMvgType;
@@ -67,100 +60,51 @@ static PyTypeObject LibLVMpvsegType;
static PyObject *LibLVMError;
-
-/* ----------------------------------------------------------------------
- * LVM object initialization/deallocation
- */
-
-static int
-liblvm_init(lvmobject *self, PyObject *arg)
-{
- char *systemdir = NULL;
-
- if (!PyArg_ParseTuple(arg, "|s", &systemdir))
- return -1;
-
- self->libh = lvm_init(systemdir);
- if (lvm_errno(self->libh)) {
- PyErr_SetFromErrno(PyExc_OSError);
- return -1;
- }
-
- return 0;
-}
-
-static void
-liblvm_dealloc(lvmobject *self)
-{
- /* if already closed, don't reclose it */
- if (self->libh != NULL){
- lvm_quit(self->libh);
- }
-
- PyObject_Del(self);
-}
-
-#define LVM_VALID(lvmobject) \
+#define LVM_VALID() \
do { \
- if (!lvmobject->libh) { \
- PyErr_SetString(PyExc_UnboundLocalError, "LVM object invalid"); \
+ if (!libh) { \
+ PyErr_SetString(PyExc_UnboundLocalError, "LVM handle invalid"); \
return NULL; \
} \
} while (0)
static PyObject *
-liblvm_get_last_error(lvmobject *self)
+liblvm_get_last_error(void)
{
PyObject *info;
- LVM_VALID(self);
+ LVM_VALID();
if((info = PyTuple_New(2)) == NULL)
return NULL;
- PyTuple_SetItem(info, 0, PyInt_FromLong((long) lvm_errno(self->libh)));
- PyTuple_SetItem(info, 1, PyString_FromString(lvm_errmsg(self->libh)));
+ PyTuple_SetItem(info, 0, PyInt_FromLong((long) lvm_errno(libh)));
+ PyTuple_SetItem(info, 1, PyString_FromString(lvm_errmsg(libh)));
return info;
}
static PyObject *
-liblvm_library_get_version(lvmobject *self)
+liblvm_library_get_version(void)
{
- LVM_VALID(self);
+ LVM_VALID();
return Py_BuildValue("s", lvm_library_get_version());
}
-
-static PyObject *
-liblvm_close(lvmobject *self)
-{
- LVM_VALID(self);
-
- /* if already closed, don't reclose it */
- if (self->libh != NULL)
- lvm_quit(self->libh);
-
- self->libh = NULL;
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
static PyObject *
-liblvm_lvm_list_vg_names(lvmobject *self)
+liblvm_lvm_list_vg_names(void)
{
struct dm_list *vgnames;
struct lvm_str_list *strl;
PyObject * pytuple;
int i = 0;
- LVM_VALID(self);
+ LVM_VALID();
- vgnames = lvm_list_vg_names(self->libh);
+ vgnames = lvm_list_vg_names(libh);
if (!vgnames) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -177,18 +121,18 @@ liblvm_lvm_list_vg_names(lvmobject *self)
}
static PyObject *
-liblvm_lvm_list_vg_uuids(lvmobject *self)
+liblvm_lvm_list_vg_uuids(void)
{
struct dm_list *uuids;
struct lvm_str_list *strl;
PyObject * pytuple;
int i = 0;
- LVM_VALID(self);
+ LVM_VALID();
- uuids = lvm_list_vg_uuids(self->libh);
+ uuids = lvm_list_vg_uuids(libh);
if (!uuids) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -205,12 +149,12 @@ liblvm_lvm_list_vg_uuids(lvmobject *self)
}
static PyObject *
-liblvm_lvm_percent_to_float(lvmobject *self, PyObject *arg)
+liblvm_lvm_percent_to_float(PyObject *arg)
{
double converted;
int percent;
- LVM_VALID(self);
+ LVM_VALID();
if (!PyArg_ParseTuple(arg, "i", &percent))
return NULL;
@@ -220,18 +164,18 @@ liblvm_lvm_percent_to_float(lvmobject *self, PyObject *arg)
}
static PyObject *
-liblvm_lvm_vgname_from_pvid(lvmobject *self, PyObject *arg)
+liblvm_lvm_vgname_from_pvid(PyObject *self, PyObject *arg)
{
const char *pvid;
const char *vgname;
- LVM_VALID(self);
+ LVM_VALID();
if (!PyArg_ParseTuple(arg, "s", &pvid))
return NULL;
- if((vgname = lvm_vgname_from_pvid(self->libh, pvid)) == NULL) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self));
+ if((vgname = lvm_vgname_from_pvid(libh, pvid)) == NULL) {
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -239,18 +183,18 @@ liblvm_lvm_vgname_from_pvid(lvmobject *self, PyObject *arg)
}
static PyObject *
-liblvm_lvm_vgname_from_device(lvmobject *self, PyObject *arg)
+liblvm_lvm_vgname_from_device(PyObject *self, PyObject *arg)
{
const char *device;
const char *vgname;
- LVM_VALID(self);
+ LVM_VALID();
if (!PyArg_ParseTuple(arg, "s", &device))
return NULL;
- if((vgname = lvm_vgname_from_device(self->libh, device)) == NULL) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self));
+ if((vgname = lvm_vgname_from_device(libh, device)) == NULL) {
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -259,18 +203,18 @@ liblvm_lvm_vgname_from_device(lvmobject *self, PyObject *arg)
static PyObject *
-liblvm_lvm_config_find_bool(lvmobject *self, PyObject *arg)
+liblvm_lvm_config_find_bool(PyObject *self, PyObject *arg)
{
const char *config;
int rval;
PyObject *rc;
- LVM_VALID(self);
+ LVM_VALID();
if (!PyArg_ParseTuple(arg, "s", &config))
return NULL;
- if ((rval = lvm_config_find_bool(self->libh, config, -10)) == -10) {
+ if ((rval = lvm_config_find_bool(libh, config, -10)) == -10) {
/* Retrieving error information yields no error in this case */
PyErr_Format(PyExc_ValueError, "config path not found");
return NULL;
@@ -283,14 +227,14 @@ liblvm_lvm_config_find_bool(lvmobject *self, PyObject *arg)
}
static PyObject *
-liblvm_lvm_config_reload(lvmobject *self)
+liblvm_lvm_config_reload(void)
{
int rval;
- LVM_VALID(self);
+ LVM_VALID();
- if((rval = lvm_config_reload(self->libh)) == -1) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self));
+ if((rval = lvm_config_reload(libh)) == -1) {
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -300,14 +244,14 @@ liblvm_lvm_config_reload(lvmobject *self)
static PyObject *
-liblvm_lvm_scan(lvmobject *self)
+liblvm_lvm_scan(void)
{
int rval;
- LVM_VALID(self);
+ LVM_VALID();
- if((rval = lvm_scan(self->libh)) == -1) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self));
+ if((rval = lvm_scan(libh)) == -1) {
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -316,18 +260,18 @@ liblvm_lvm_scan(lvmobject *self)
}
static PyObject *
-liblvm_lvm_config_override(lvmobject *self, PyObject *arg)
+liblvm_lvm_config_override(PyObject *self, PyObject *arg)
{
const char *config;
int rval;
- LVM_VALID(self);
+ LVM_VALID();
if (!PyArg_ParseTuple(arg, "s", &config))
return NULL;
- if ((rval = lvm_config_override(self->libh, config)) == -1) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self));
+ if ((rval = lvm_config_override(libh, config)) == -1) {
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -340,14 +284,14 @@ liblvm_lvm_config_override(lvmobject *self, PyObject *arg)
static PyObject *
-liblvm_lvm_vg_open(lvmobject *lvm, PyObject *args)
+liblvm_lvm_vg_open(PyObject *self, PyObject *args)
{
const char *vgname;
const char *mode = NULL;
- vgobject *self;
+ vgobject *vgobj;
- LVM_VALID(lvm);
+ LVM_VALID();
if (!PyArg_ParseTuple(args, "s|s", &vgname, &mode)) {
return NULL;
@@ -356,42 +300,38 @@ liblvm_lvm_vg_open(lvmobject *lvm, PyObject *args)
if (mode == NULL)
mode = "r";
- if ((self = PyObject_New(vgobject, &LibLVMvgType)) == NULL)
+ if ((vgobj = PyObject_New(vgobject, &LibLVMvgType)) == NULL)
return NULL;
- if ((self->vg = lvm_vg_open(lvm->libh, vgname, mode, 0))== NULL) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(lvm));
- Py_DECREF(self);
+ if ((vgobj->vg = lvm_vg_open(libh, vgname, mode, 0))== NULL) {
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
- self->lvm_obj = lvm;
- return (PyObject *)self;
+ return (PyObject *)vgobj;
}
static PyObject *
-liblvm_lvm_vg_create(lvmobject *lvm, PyObject *args)
+liblvm_lvm_vg_create(PyObject *self, PyObject *args)
{
const char *vgname;
- vgobject *self;
+ vgobject *vgobj;
- LVM_VALID(lvm);
+ LVM_VALID();
if (!PyArg_ParseTuple(args, "s", &vgname)) {
return NULL;
}
- if ((self = PyObject_New(vgobject, &LibLVMvgType)) == NULL)
+ if ((vgobj = PyObject_New(vgobject, &LibLVMvgType)) == NULL)
return NULL;
- if ((self->vg = lvm_vg_create(lvm->libh, vgname))== NULL) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(lvm));
- Py_DECREF(self);
+ if ((vgobj->vg = lvm_vg_create(libh, vgname))== NULL) {
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
- self->lvm_obj = lvm;
- return (PyObject *)self;
+ return (PyObject *)vgobj;
}
static void
@@ -462,7 +402,7 @@ liblvm_lvm_vg_remove(vgobject *self)
return Py_None;
error:
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -488,7 +428,7 @@ liblvm_lvm_vg_extend(vgobject *self, PyObject *args)
return Py_None;
error:
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -514,7 +454,7 @@ liblvm_lvm_vg_reduce(vgobject *self, PyObject *args)
return Py_None;
error:
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -538,7 +478,7 @@ liblvm_lvm_vg_add_tag(vgobject *self, PyObject *args)
return Py_BuildValue("i", rval);
error:
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -564,7 +504,7 @@ liblvm_lvm_vg_remove_tag(vgobject *self, PyObject *args)
return Py_None;
error:
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -658,13 +598,13 @@ liblvm_lvm_vg_get_free_extent_count(vgobject *self)
/* Builds a python tuple ([string|number], bool) from a struct lvm_property_value */
static PyObject *
-get_property(lvmobject *h, struct lvm_property_value *prop)
+get_property(struct lvm_property_value *prop)
{
PyObject *pytuple;
PyObject *setable;
if( !prop->is_valid ) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(h));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -703,7 +643,7 @@ liblvm_lvm_vg_get_property(vgobject *self, PyObject *args)
return NULL;
prop_value = lvm_vg_get_property(self->vg, name);
- return get_property(self->lvm_obj, &prop_value);
+ return get_property(&prop_value);
}
static PyObject *
@@ -791,7 +731,7 @@ liblvm_lvm_vg_set_property(vgobject *self, PyObject *args)
return Py_None;
lvmerror:
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
bail:
free(string_value);
if( variant_type_arg ) {
@@ -838,7 +778,7 @@ liblvm_lvm_vg_set_extent_size(vgobject *self, PyObject *args)
}
if ((rval = lvm_vg_set_extent_size(self->vg, new_size)) == -1) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -875,7 +815,6 @@ liblvm_lvm_vg_list_lvs(vgobject *vg)
}
self->lv = lvl->lv;
- self->lvm_obj = vg->lvm_obj;
PyTuple_SET_ITEM(pytuple, i, (PyObject *) self);
i++;
}
@@ -895,7 +834,7 @@ liblvm_lvm_vg_get_tags(vgobject *self)
tags = lvm_vg_get_tags(self->vg);
if (!tags) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -928,11 +867,10 @@ liblvm_lvm_vg_create_lv_linear(vgobject *vg, PyObject *args)
return NULL;
if ((self->lv = lvm_vg_create_lv_linear(vg->vg, vgname, size))== NULL) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(vg->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
Py_DECREF(self);
return NULL;
}
- self->lvm_obj = vg->lvm_obj;
return (PyObject *)self;
}
@@ -972,7 +910,6 @@ liblvm_lvm_vg_list_pvs(vgobject *vg)
}
self->pv = pvl->pv;
- self->lvm_obj = vg->lvm_obj;
PyTuple_SET_ITEM(pytuple, i, (PyObject *) self);
i++;
}
@@ -997,7 +934,7 @@ liblvm_lvm_lv_from_N(vgobject *self, PyObject *arg, lv_fetch_by_N method)
lv = method(self->vg, id);
if( !lv ) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -1007,7 +944,6 @@ liblvm_lvm_lv_from_N(vgobject *self, PyObject *arg, lv_fetch_by_N method)
}
rc->lv = lv;
- rc->lvm_obj = self->lvm_obj;
return (PyObject *)rc;
}
@@ -1037,7 +973,7 @@ liblvm_lvm_pv_from_N(vgobject *self, PyObject *arg, pv_fetch_by_N method)
pv = method(self->vg, id);
if( !pv ) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -1047,7 +983,6 @@ liblvm_lvm_pv_from_N(vgobject *self, PyObject *arg, pv_fetch_by_N method)
}
rc->pv = pv;
- rc->lvm_obj = self->lvm_obj;
return (PyObject *)rc;
}
@@ -1104,7 +1039,7 @@ liblvm_lvm_lv_activate(lvobject *self)
LV_VALID(self);
if ((rval = lvm_lv_activate(self->lv)) == -1) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -1120,7 +1055,7 @@ liblvm_lvm_lv_deactivate(lvobject *self)
LV_VALID(self);
if ((rval = lvm_lv_deactivate(self->lv)) == -1) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -1136,7 +1071,7 @@ liblvm_lvm_vg_remove_lv(lvobject *self)
LV_VALID(self);
if ((rval = lvm_vg_remove_lv(self->lv)) == -1) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -1149,7 +1084,7 @@ liblvm_lvm_vg_remove_lv(lvobject *self)
/* This will return a tuple of (value, bool) with the value being a string or
integer and bool indicating if property is settable */
static PyObject *
-liblvm_lvm_lv_get_property(lvobject *self, PyObject *args)
+liblvm_lvm_lv_get_property(lvobject *self, PyObject *args)
{
const char *name;
struct lvm_property_value prop_value;
@@ -1160,7 +1095,7 @@ liblvm_lvm_lv_get_property(lvobject *self, PyObject *args)
return NULL;
prop_value = lvm_lv_get_property(self->lv, name);
- return get_property(self->lvm_obj, &prop_value);
+ return get_property(&prop_value);
}
static PyObject *
@@ -1210,7 +1145,7 @@ liblvm_lvm_lv_add_tag(lvobject *self, PyObject *args)
}
if ((rval = lvm_lv_add_tag(self->lv, tag)) == -1) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -1231,7 +1166,7 @@ liblvm_lvm_lv_remove_tag(lvobject *self, PyObject *args)
}
if ((rval = lvm_lv_remove_tag(self->lv, tag)) == -1) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -1251,7 +1186,7 @@ liblvm_lvm_lv_get_tags(lvobject *self)
tags = lvm_lv_get_tags(self->lv);
if (!tags) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -1279,7 +1214,7 @@ liblvm_lvm_lv_rename(lvobject *self, PyObject *args)
return NULL;
if ((rval = lvm_lv_rename(self->lv, new_name)) == -1) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -1300,7 +1235,7 @@ liblvm_lvm_lv_resize(lvobject *self, PyObject *args)
}
if ((rval = lvm_lv_resize(self->lv, new_size)) == -1) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -1337,7 +1272,6 @@ liblvm_lvm_lv_list_lvsegs(lvobject *lv)
}
self->lv_seg = lvsegl->lvseg;
- self->lvm_obj = lv->lvm_obj;
PyTuple_SET_ITEM(pytuple, i, (PyObject *) self);
i++;
}
@@ -1349,7 +1283,7 @@ liblvm_lvm_lv_list_lvsegs(lvobject *lv)
#define PV_VALID(pvobject) \
do { \
- if (!pvobject->pv || !pvobject->lvm_obj) { \
+ if (!pvobject->pv || !libh) { \
PyErr_SetString(PyExc_UnboundLocalError, "PV object invalid"); \
return NULL; \
} \
@@ -1385,7 +1319,7 @@ liblvm_lvm_pv_get_property(pvobject *self, PyObject *args)
return NULL;
prop_value = lvm_pv_get_property(self->pv, name);
- return get_property(self->lvm_obj, &prop_value);
+ return get_property(&prop_value);
}
static PyObject *
@@ -1417,7 +1351,7 @@ liblvm_lvm_pv_resize(pvobject *self, PyObject *args)
}
if ((rval = lvm_pv_resize(self->pv, new_size)) == -1) {
- PyErr_SetObject(LibLVMError, liblvm_get_last_error(self->lvm_obj));
+ PyErr_SetObject(LibLVMError, liblvm_get_last_error());
return NULL;
}
@@ -1454,7 +1388,6 @@ liblvm_lvm_lv_list_pvsegs(pvobject *pv)
}
self->pv_seg = pvsegl->pvseg;
- self->lvm_obj = pv->lvm_obj;
PyTuple_SET_ITEM(pytuple, i, (PyObject *) self);
i++;
}
@@ -1480,7 +1413,7 @@ liblvm_lvm_lvseg_get_property(lvsegobject *self, PyObject *args)
return NULL;
prop_value = lvm_lvseg_get_property(self->lv_seg, name);
- return get_property(self->lvm_obj, &prop_value);
+ return get_property(&prop_value);
}
/* PV seg methods */
@@ -1501,7 +1434,7 @@ liblvm_lvm_pvseg_get_property(pvsegobject *self, PyObject *args)
return NULL;
prop_value = lvm_pvseg_get_property(self->pv_seg, name);
- return get_property(self->lvm_obj, &prop_value);
+ return get_property(&prop_value);
}
/* ----------------------------------------------------------------------
@@ -1513,7 +1446,6 @@ static PyMethodDef Liblvm_methods[] = {
{ "getVersion", (PyCFunction)liblvm_library_get_version, METH_NOARGS },
{ "vgOpen", (PyCFunction)liblvm_lvm_vg_open, METH_VARARGS },
{ "vgCreate", (PyCFunction)liblvm_lvm_vg_create, METH_VARARGS },
- { "close", (PyCFunction)liblvm_close, METH_NOARGS },
{ "configFindBool", (PyCFunction)liblvm_lvm_config_find_bool, METH_VARARGS },
{ "configReload", (PyCFunction)liblvm_lvm_config_reload, METH_NOARGS },
{ "configOverride", (PyCFunction)liblvm_lvm_config_override, METH_VARARGS },
@@ -1606,18 +1538,6 @@ static PyMethodDef liblvm_pvseg_methods[] = {
{ NULL, NULL} /* sentinel */
};
-static PyTypeObject LiblvmType = {
- PyObject_HEAD_INIT(&PyType_Type)
- .tp_name = "liblvm.Liblvm",
- .tp_basicsize = sizeof(lvmobject),
- .tp_new = PyType_GenericNew,
- .tp_dealloc = (destructor)liblvm_dealloc,
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- .tp_doc = "Liblvm objects",
- .tp_methods = Liblvm_methods,
- .tp_init = (initproc)liblvm_init,
-};
-
static PyTypeObject LibLVMvgType = {
PyObject_HEAD_INIT(&PyType_Type)
.tp_name = "liblvm.Liblvm_vg",
@@ -1673,13 +1593,20 @@ static PyTypeObject LibLVMpvsegType = {
.tp_methods = liblvm_pvseg_methods,
};
+static void
+liblvm_cleanup(void)
+{
+ lvm_quit(libh);
+ libh = NULL;
+}
+
PyMODINIT_FUNC
initlvm(void)
{
PyObject *m;
- if (PyType_Ready(&LiblvmType) < 0)
- return;
+ libh = lvm_init(NULL);
+
if (PyType_Ready(&LibLVMvgType) < 0)
return;
if (PyType_Ready(&LibLVMlvType) < 0)
@@ -1695,9 +1622,6 @@ initlvm(void)
if (m == NULL)
return;
- Py_INCREF(&LiblvmType);
- PyModule_AddObject(m, "Liblvm", (PyObject *)&LiblvmType);
-
LibLVMError = PyErr_NewException("Liblvm.LibLVMError",
NULL, NULL);
if (LibLVMError) {
@@ -1708,4 +1632,5 @@ initlvm(void)
PyModule_AddObject(m, "LibLVMError", LibLVMError);
}
+ Py_AtExit(liblvm_cleanup);
}
11 years, 5 months
master - TEST: Re-add testing of lvconvert-raid for kernels < 3.2
by Jonathan Brassow
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=831ce3cda941f0...
Commit: 831ce3cda941f02556dd8c4a407754397df17997
Parent: 67379a3ffdafa69a2830a1155fe9b4689bbf71cb
Author: Jonathan Brassow <jbrassow(a)redhat.com>
AuthorDate: Mon Oct 15 15:43:15 2012 -0500
Committer: Jonathan Brassow <jbrassow(a)redhat.com>
CommitterDate: Mon Oct 15 15:43:15 2012 -0500
TEST: Re-add testing of lvconvert-raid for kernels < 3.2
I'm not sure what 'BUG's were being encountered when the restriction
to limit lvconvert-raid.sh tests to kernels > 3.2 was added. I do know
that there were BUG's that could be triggered when testing snapshots and
some of the earliest DM RAID available in the kernel. I've taken out
the 3.2 kernel restriction and added a dm-raid >= 1.2 restriction instead.
This will allow the test to run on patched production kernels.
---
test/shell/lvconvert-raid.sh | 18 +++---------------
1 files changed, 3 insertions(+), 15 deletions(-)
diff --git a/test/shell/lvconvert-raid.sh b/test/shell/lvconvert-raid.sh
index 4fa766d..59c8bdb 100644
--- a/test/shell/lvconvert-raid.sh
+++ b/test/shell/lvconvert-raid.sh
@@ -22,8 +22,7 @@ get_image_pvs() {
########################################################
# MAIN
########################################################
-aux target_at_least dm-raid 1 1 0 || skip
-aux kernel_at_least 3 2 0 || skip
+aux target_at_least dm-raid 1 2 0 || skip
# 9 PVs needed for RAID10 testing (3-stripes/2-mirror - replacing 3 devs)
aux prepare_pvs 9 80
@@ -33,8 +32,8 @@ vgcreate -c n -s 256k $vg $(cat DEVICES)
# RAID1 convert tests
###########################################
for under_snap in false true; do
-for i in 1 2 3 4; do
- for j in 1 2 3 4; do
+for i in 1 2 3; do
+ for j in 1 2 3; do
if [ $i -eq 1 ]; then
from="linear"
else
@@ -121,17 +120,6 @@ check linear $vg $lv2
# FIXME: ensure no residual devices
lvremove -ff $vg
-# 3-way to linear/2-way
-lvcreate --type raid1 -m 2 -l 2 -n $lv1 $vg
-aux wait_for_sync $vg $lv1
-# FIXME: Can't split off a RAID1 from a RAID1 yet
-# 'should' results in "warnings"
-should lvconvert --splitmirrors 2 -n $lv2 $vg/$lv1
-#check linear $vg $lv1
-#check lv_exists $vg $lv2
-# FIXME: ensure no residual devices
-lvremove -ff $vg
-
###########################################
# RAID1 split + trackchanges / merge
###########################################
11 years, 5 months
master - RAID: Add "raid10" to lvcreate man page.
by Jonathan Brassow
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=67379a3ffdafa6...
Commit: 67379a3ffdafa69a2830a1155fe9b4689bbf71cb
Parent: 7519d881ef07c4a515716099a4bf9566b7f71b1a
Author: Jonathan Brassow <jbrassow(a)redhat.com>
AuthorDate: Mon Oct 15 15:41:14 2012 -0500
Committer: Jonathan Brassow <jbrassow(a)redhat.com>
CommitterDate: Mon Oct 15 15:41:14 2012 -0500
RAID: Add "raid10" to lvcreate man page.
In addition to reference to raid10 under the '--type' argument, an
example creating a RAID10 LV has been added.
---
man/lvcreate.8.in | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/man/lvcreate.8.in b/man/lvcreate.8.in
index fb54cc6..f374950 100644
--- a/man/lvcreate.8.in
+++ b/man/lvcreate.8.in
@@ -298,7 +298,7 @@ commandline switch alias that will enable their use
However, this argument must be used when no existing
commandline switch alias is available for the desired type,
as is the case with
-.IR error ", " zero ", " raid1 ", " raid4 ", " raid5 " or " raid6 .
+.IR error ", " zero ", " raid1 ", " raid10 ", " raid4 ", " raid5 " or " raid6 .
.TP
.BR \-V ", " \-\-virtualsize " " \fIVirtualSize [ \fIbBsSkKmMgGtTpPeE ]
Create a sparse device of the given size (in MB by default) using a snapshot
@@ -363,6 +363,14 @@ a parity drive for a total of 4 devices) and a stripesize of 64KiB:
.sp
.B lvcreate \-\-type raid5 \-L 5G \-i 3 \-I 64 \-n my_lv vg00
+Creates a 5GiB RAID10 logical volume "vg00/my_lv", with 2 stripes on
+2 2-way mirrors. Note that the '-i' and '-m' arguments behave differently.
+The '-i' specifies the number of stripes. The '-m' specifies the number of
+.B additional
+copies.
+.sp
+.B lvcreate \-\-type raid10 \-L 5G \-i 2 \-m 1 \-n my_lv vg00
+
Creates 100MiB pool logical volume for thin provisioning
build with 2 stripes 64KiB and chunk size 128KiB together with
1TiB thin provisioned logical volume "vg00/thin_lv":
11 years, 5 months