diff --git a/lvm2-2_02_99-python-implement-proper-refcounting-for-parent-objects.patch b/lvm2-2_02_99-python-implement-proper-refcounting-for-parent-objects.patch new file mode 100644 index 0000000..c498492 --- /dev/null +++ b/lvm2-2_02_99-python-implement-proper-refcounting-for-parent-objects.patch @@ -0,0 +1,470 @@ +commit 0e47639a44e1630250ea10643f5a440281edfdce +Author: Andy Grover +Date: 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 +--- + python/liblvm.c | 152 +++++++++++++++++++++++++++++++++++++++----------------- + 1 file 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 */ + }; + diff --git a/lvm2-2_02_99-python-remove-liblvm-object.patch b/lvm2-2_02_99-python-remove-liblvm-object.patch new file mode 100644 index 0000000..aef2284 --- /dev/null +++ b/lvm2-2_02_99-python-remove-liblvm-object.patch @@ -0,0 +1,793 @@ +commit 84a4d4b970bb9aaf540ad5fa82276b1caf5aa9bd +Author: Andy Grover +Date: Mon Oct 15 13:26:01 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 +--- + python/liblvm.c | 269 ++++++++++++++++++++------------------------------------ + 1 file 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 + #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); + } diff --git a/lvm2-2_02_99-python-update-example-to-work-with-lvm-object-removal.patch b/lvm2-2_02_99-python-update-example-to-work-with-lvm-object-removal.patch new file mode 100644 index 0000000..621d1df --- /dev/null +++ b/lvm2-2_02_99-python-update-example-to-work-with-lvm-object-removal.patch @@ -0,0 +1,103 @@ +commit 10ba799ab08001d5435425e65f039f20cadd306e +Author: Tony Asleson +Date: Mon Oct 15 13:54:19 2012 -0700 + + python-lvm: Update example to work with lvm object removal. + + Signed-off-by: Tony Asleson + Signed-off-by: Andy Grover +--- + python/example.py | 35 +++++++++++++++-------------------- + 1 file 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() diff --git a/lvm2-2_02_99-python-whitespace-and-conditional-cleanup.patch b/lvm2-2_02_99-python-whitespace-and-conditional-cleanup.patch new file mode 100644 index 0000000..454e7b7 --- /dev/null +++ b/lvm2-2_02_99-python-whitespace-and-conditional-cleanup.patch @@ -0,0 +1,205 @@ +commit 12b631a6768e6f2a2005ef8ea91c0afbc2455c54 +Author: Andy Grover +Date: Mon Oct 15 13:34:43 2012 -0700 + + python-lvm: whitespace and Yoda conditionals + + Signed-off-by: Andy Grover +--- + python/liblvm.c | 50 ++++++++++++++++++++++++-------------------------- + 1 file 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("()"); + } + diff --git a/lvm2.spec b/lvm2.spec index 2776625..901253d 100644 --- a/lvm2.spec +++ b/lvm2.spec @@ -37,12 +37,16 @@ Summary: Userland logical volume management tools Name: lvm2 Version: 2.02.98 -Release: 1%{?dist} +Release: 2%{?dist} License: GPLv2 Group: System Environment/Base URL: http://sources.redhat.com/lvm2 Source0: ftp://sources.redhat.com/pub/lvm2/LVM2.%{version}.tgz Patch0: lvm2-set-default-preferred_names.patch +Patch1: lvm2-2_02_99-python-remove-liblvm-object.patch +Patch2: lvm2-2_02_99-python-whitespace-and-conditional-cleanup.patch +Patch3: lvm2-2_02_99-python-update-example-to-work-with-lvm-object-removal.patch +Patch4: lvm2-2_02_99-python-implement-proper-refcounting-for-parent-objects.patch BuildRequires: libselinux-devel >= %{libselinux_version}, libsepol-devel BuildRequires: ncurses-devel @@ -55,6 +59,8 @@ BuildRequires: module-init-tools BuildRequires: pkgconfig BuildRequires: systemd-devel BuildRequires: systemd-units +BuildRequires: python2-devel +BuildRequires: python-setuptools Requires: %{name}-libs = %{version}-%{release} Requires: bash >= %{bash_version} Requires(post): systemd-units >= %{systemd_version}, systemd-sysv @@ -76,6 +82,10 @@ or more physical volumes and creating one or more logical volumes %prep %setup -q -n LVM2.%{version} %patch0 -p1 -b .preferred_names +%patch1 -p1 -b .python_liblvm_object +%patch2 -p1 -b .python_cleanup +%patch3 -p1 -b .python_fix_example +%patch4 -p1 -b .python_refcounting %build %define _default_pid_dir /run @@ -97,7 +107,7 @@ or more physical volumes and creating one or more logical volumes %define configure_lvmetad --enable-lvmetad %endif -%configure --with-default-dm-run-dir=%{_default_dm_run_dir} --with-default-run-dir=%{_default_run_dir} --with-default-pid-dir=%{_default_pid_dir} --with-default-locking-dir=%{_default_locking_dir} --with-usrlibdir=%{_libdir} --enable-lvm1_fallback --enable-fsadm --with-pool=internal --with-user= --with-group= --with-device-uid=0 --with-device-gid=6 --with-device-mode=0660 --enable-pkgconfig --enable-applib --enable-cmdlib --enable-dmeventd %{configure_cluster} %{configure_cmirror} %{?configure_udev} %{?configure_thin} %{?configure_lvmetad} +%configure --with-default-dm-run-dir=%{_default_dm_run_dir} --with-default-run-dir=%{_default_run_dir} --with-default-pid-dir=%{_default_pid_dir} --with-default-locking-dir=%{_default_locking_dir} --with-usrlibdir=%{_libdir} --enable-lvm1_fallback --enable-fsadm --with-pool=internal --with-user= --with-group= --with-device-uid=0 --with-device-gid=6 --with-device-mode=0660 --enable-pkgconfig --enable-applib --enable-cmdlib --enable-python-bindings --enable-dmeventd %{configure_cluster} %{configure_cmirror} %{?configure_udev} %{?configure_thin} %{?configure_lvmetad} make %{?_smp_mflags} @@ -317,6 +327,21 @@ This package contains shared lvm2 libraries for applications. %{_libdir}/device-mapper/libdevmapper-event-lvm2thin.so %endif +%package python-libs +Summary: Python module to access LVM +License: LGPLv2 +Group: Development/Libraries +Provides: python-lvm = %{version}-%{release} +Obsoletes: python-lvm < 2.02.98-2 +Requires: %{name}-libs = %{version}-%{release} + +%description python-libs +Python module to allow the creation and use of LVM +logical volumes, physical volumes, and volume groups. + +%files python-libs +%{python_sitearch}/* + ############################################################################## # Cluster subpackage ############################################################################## @@ -555,6 +580,9 @@ the device-mapper event library. %{_libdir}/pkgconfig/devmapper-event.pc %changelog +* Sat Oct 20 2012 Peter Rajnoha - 2.02.98-2 +- Incorporate former python-lvm package in lvm2 as lvm2-python-libs subpackage. + * Tue Oct 16 2012 Peter Rajnoha - 2.02.98-1 - Don't try to issue discards to a missing PV to avoid segfault. - Fix vgchange -aay not to activate non-matching LVs that follow a matching LV. diff --git a/lvm2_spec.patch b/lvm2_spec.patch new file mode 100644 index 0000000..d9df97e --- /dev/null +++ b/lvm2_spec.patch @@ -0,0 +1,63 @@ +diff --git a/lvm2.spec b/lvm2.spec +index 2776625..ac160f3 100644 +--- a/lvm2.spec ++++ b/lvm2.spec +@@ -37,7 +37,7 @@ + Summary: Userland logical volume management tools + Name: lvm2 + Version: 2.02.98 +-Release: 1%{?dist} ++Release: 2%{?dist} + License: GPLv2 + Group: System Environment/Base + URL: http://sources.redhat.com/lvm2 +@@ -55,6 +55,8 @@ BuildRequires: module-init-tools + BuildRequires: pkgconfig + BuildRequires: systemd-devel + BuildRequires: systemd-units ++BuildRequires: python2-devel ++BuildRequires: python-setuptools + Requires: %{name}-libs = %{version}-%{release} + Requires: bash >= %{bash_version} + Requires(post): systemd-units >= %{systemd_version}, systemd-sysv +@@ -97,7 +99,7 @@ or more physical volumes and creating one or more logical volumes + %define configure_lvmetad --enable-lvmetad + %endif + +-%configure --with-default-dm-run-dir=%{_default_dm_run_dir} --with-default-run-dir=%{_default_run_dir} --with-default-pid-dir=%{_default_pid_dir} --with-default-locking-dir=%{_default_locking_dir} --with-usrlibdir=%{_libdir} --enable-lvm1_fallback --enable-fsadm --with-pool=internal --with-user= --with-group= --with-device-uid=0 --with-device-gid=6 --with-device-mode=0660 --enable-pkgconfig --enable-applib --enable-cmdlib --enable-dmeventd %{configure_cluster} %{configure_cmirror} %{?configure_udev} %{?configure_thin} %{?configure_lvmetad} ++%configure --with-default-dm-run-dir=%{_default_dm_run_dir} --with-default-run-dir=%{_default_run_dir} --with-default-pid-dir=%{_default_pid_dir} --with-default-locking-dir=%{_default_locking_dir} --with-usrlibdir=%{_libdir} --enable-lvm1_fallback --enable-fsadm --with-pool=internal --with-user= --with-group= --with-device-uid=0 --with-device-gid=6 --with-device-mode=0660 --enable-pkgconfig --enable-applib --enable-cmdlib --enable-python-bindings --enable-dmeventd %{configure_cluster} %{configure_cmirror} %{?configure_udev} %{?configure_thin} %{?configure_lvmetad} + + make %{?_smp_mflags} + +@@ -317,6 +319,21 @@ This package contains shared lvm2 libraries for applications. + %{_libdir}/device-mapper/libdevmapper-event-lvm2thin.so + %endif + ++%package python-libs ++Summary: Python module to access LVM ++License: LGPLv2 ++Group: Development/Libraries ++Provides: python-lvm = %{version}-%{release} ++Obsoletes: python-lvm < 2.02.98-2 ++Requires: %{name}-libs = %{version}-%{release} ++ ++%description python-libs ++Python module to allow the creation and use of LVM ++logical volumes, physical volumes, and volume groups. ++ ++%files python-libs ++%{python_sitearch}/* ++ + ############################################################################## + # Cluster subpackage + ############################################################################## +@@ -555,6 +572,9 @@ the device-mapper event library. + %{_libdir}/pkgconfig/devmapper-event.pc + + %changelog ++* Thu Oct 18 2012 Peter Rajnoha - 2.02.98-2 ++- Incorporate former python-lvm package in lvm2 as lvm2-python-libs subpackage. ++ + * Tue Oct 16 2012 Peter Rajnoha - 2.02.98-1 + - Don't try to issue discards to a missing PV to avoid segfault. + - Fix vgchange -aay not to activate non-matching LVs that follow a matching LV.