summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2016-05-11 13:42:00 -0500
committerDavid Teigland <teigland@redhat.com>2016-05-12 15:31:16 -0500
commit48674936887de102f83562bc900c981d2405a4c7 (patch)
tree52eba59b1305dc26489e35953646553010460a13
parent87d9406725b23e6c01e55014606ff047d7375951 (diff)
downloadlvm2-dev-dct-python-init-1.tar.gz
python: move lvm_initdev-dct-python-init-1
Only call lvm_init() when it's needed so that simply loading the lvm python code in another program doesn't make that program do lvm initialization. The version call doesn't need a handle. The garbage collection can just do lvm_quit to destroy the command. The next call that needs lvm_init will do it first.
-rw-r--r--python/liblvm.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/python/liblvm.c b/python/liblvm.c
index 089abb367..1b3534eb6 100644
--- a/python/liblvm.c
+++ b/python/liblvm.c
@@ -93,6 +93,9 @@ static PyObject *_LibLVMError;
#define LVM_VALID(ptr) \
do { \
+ if (!_libh) { \
+ _libh = lvm_init(NULL); \
+ } \
if (ptr && _libh) { \
if (ptr != _libh) { \
PyErr_SetString(PyExc_UnboundLocalError, "LVM handle reference stale"); \
@@ -175,8 +178,6 @@ static PyObject *_liblvm_get_last_error(void)
static PyObject *_liblvm_library_get_version(void)
{
- LVM_VALID(NULL);
-
return Py_BuildValue("s", lvm_library_get_version());
}
@@ -184,13 +185,9 @@ static const char _gc_doc[] = "Garbage collect the C library";
static PyObject *_liblvm_lvm_gc(void)
{
- LVM_VALID(NULL);
-
- lvm_quit(_libh);
-
- if (!(_libh = lvm_init(NULL))) {
- PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
- return NULL;
+ if (_libh) {
+ lvm_quit(_libh);
+ _libh = NULL;
}
Py_INCREF(Py_None);
@@ -2047,8 +2044,6 @@ PyMODINIT_FUNC initlvm(void)
{
PyObject *m;
- _libh = lvm_init(NULL);
-
if (PyType_Ready(&_LibLVMvgType) < 0)
MODINITERROR;
if (PyType_Ready(&_LibLVMlvType) < 0)