mirror of
git://sourceware.org/git/lvm2.git
synced 2025-03-10 16:58:47 +03:00
python-lvm: Add call to close/re-open C lib.
As the library handle has a dm pool associated with it for long running processes it is required to close and re-open the library to free the dm pool. Call added so python clients can reclaim memory, lvm.gc(). Note: Any python objects on the heap become invalid at the time this call is made. If referenced, a seg. fault could occur. No simple way to make this safe with the current memory management in the C library. Use with caution! Signed-off-by: Tony Asleson <tasleson@redhat.com>
This commit is contained in:
parent
357df34133
commit
1a005b40a4
@ -128,6 +128,24 @@ liblvm_library_get_version(void)
|
||||
return Py_BuildValue("s", lvm_library_get_version());
|
||||
}
|
||||
|
||||
const static char gc_doc[] = "Garbage collect the C library";
|
||||
|
||||
static PyObject *
|
||||
liblvm_lvm_gc(void)
|
||||
{
|
||||
LVM_VALID();
|
||||
|
||||
lvm_quit(libh);
|
||||
libh = lvm_init(NULL);
|
||||
|
||||
if (!libh) {
|
||||
PyErr_SetObject(LibLVMError, liblvm_get_last_error());
|
||||
return NULL;
|
||||
}
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
liblvm_lvm_list_vg_names(void)
|
||||
{
|
||||
@ -1844,6 +1862,7 @@ liblvm_lvm_pvseg_get_property(pvsegobject *self, PyObject *args)
|
||||
static PyMethodDef Liblvm_methods[] = {
|
||||
/* LVM methods */
|
||||
{ "getVersion", (PyCFunction)liblvm_library_get_version, METH_NOARGS },
|
||||
{ "gc", (PyCFunction)liblvm_lvm_gc, METH_NOARGS, gc_doc },
|
||||
{ "vgOpen", (PyCFunction)liblvm_lvm_vg_open, METH_VARARGS },
|
||||
{ "vgCreate", (PyCFunction)liblvm_lvm_vg_create, METH_VARARGS },
|
||||
{ "configFindBool", (PyCFunction)liblvm_lvm_config_find_bool, METH_VARARGS },
|
||||
@ -2024,8 +2043,10 @@ static PyTypeObject LibLVMpvsegType = {
|
||||
static void
|
||||
liblvm_cleanup(void)
|
||||
{
|
||||
lvm_quit(libh);
|
||||
libh = NULL;
|
||||
if (libh) {
|
||||
lvm_quit(libh);
|
||||
libh = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
PyMODINIT_FUNC
|
||||
|
Loading…
x
Reference in New Issue
Block a user