pylibmount: add debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
14104e931e
commit
b7e47ac1ac
5 changed files with 114 additions and 6 deletions
|
@ -1224,6 +1224,8 @@ void Context_AddModuleObject(PyObject *mod)
|
||||||
if (PyType_Ready(&ContextType) < 0)
|
if (PyType_Ready(&ContextType) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
DBG(CXT, pymnt_debug("add to module"));
|
||||||
|
|
||||||
Py_INCREF(&ContextType);
|
Py_INCREF(&ContextType);
|
||||||
PyModule_AddObject(mod, "Context", (PyObject *)&ContextType);
|
PyModule_AddObject(mod, "Context", (PyObject *)&ContextType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -571,9 +571,10 @@ static PyMethodDef Fs_methods[] = {
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void Fs_dealloc(FsObject *self)
|
static void Fs_destructor(FsObject *self)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "KZAK: [%p] delalocate\n", self->fs);
|
DBG(FS, pymnt_debug_h(self->fs, "destrutor py-obj: %p, py-refcnt=%d",
|
||||||
|
self, (int) ((PyObject *) self)->ob_refcnt));
|
||||||
mnt_unref_fs(self->fs);
|
mnt_unref_fs(self->fs);
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
self->ob_type->tp_free((PyObject*)self);
|
||||||
}
|
}
|
||||||
|
@ -583,8 +584,10 @@ static PyObject *Fs_new(PyTypeObject *type, PyObject *args __attribute__((unused
|
||||||
{
|
{
|
||||||
FsObject *self = (FsObject*)type->tp_alloc(type, 0);
|
FsObject *self = (FsObject*)type->tp_alloc(type, 0);
|
||||||
|
|
||||||
if (self)
|
if (self) {
|
||||||
self->fs = NULL;
|
self->fs = NULL;
|
||||||
|
DBG(FS, pymnt_debug_h(self, "new"));
|
||||||
|
}
|
||||||
return (PyObject *) self;
|
return (PyObject *) self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -606,6 +609,9 @@ static int Fs_init(FsObject *self, PyObject *args, PyObject *kwds)
|
||||||
PyErr_SetString(PyExc_TypeError, "Invalid type");
|
PyErr_SetString(PyExc_TypeError, "Invalid type");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DBG(FS, pymnt_debug_h(self, "init"));
|
||||||
|
|
||||||
if (self->fs)
|
if (self->fs)
|
||||||
mnt_unref_fs(self->fs);
|
mnt_unref_fs(self->fs);
|
||||||
|
|
||||||
|
@ -701,6 +707,8 @@ PyObject *PyObjectResultFs(struct libmnt_fs *fs)
|
||||||
result = mnt_fs_get_userdata(fs);
|
result = mnt_fs_get_userdata(fs);
|
||||||
if (result) {
|
if (result) {
|
||||||
Py_INCREF(result);
|
Py_INCREF(result);
|
||||||
|
DBG(FS, pymnt_debug_h(fs, "result py-obj %p: already exists, py-refcnt=%d",
|
||||||
|
result, (int) ((PyObject *) result)->ob_refcnt));
|
||||||
return (PyObject *) result;
|
return (PyObject *) result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -717,6 +725,8 @@ PyObject *PyObjectResultFs(struct libmnt_fs *fs)
|
||||||
Py_INCREF(result);
|
Py_INCREF(result);
|
||||||
mnt_ref_fs(fs);
|
mnt_ref_fs(fs);
|
||||||
|
|
||||||
|
DBG(FS, pymnt_debug_h(fs, "result py-obj %p new, py-refcnt=%d",
|
||||||
|
result, (int) ((PyObject *) result)->ob_refcnt));
|
||||||
result->fs = fs;
|
result->fs = fs;
|
||||||
mnt_fs_set_userdata(fs, result);
|
mnt_fs_set_userdata(fs, result);
|
||||||
return (PyObject *) result;
|
return (PyObject *) result;
|
||||||
|
@ -734,10 +744,13 @@ static PyObject *Fs_copy_fs(FsObject *self, PyObject *args, PyObject *kwds)
|
||||||
if (PyObject_TypeCheck(dest, &FsType)) { /* existing object passed as argument */
|
if (PyObject_TypeCheck(dest, &FsType)) { /* existing object passed as argument */
|
||||||
if (!mnt_copy_fs(((FsObject *)dest)->fs, self->fs))
|
if (!mnt_copy_fs(((FsObject *)dest)->fs, self->fs))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
DBG(FS, pymnt_debug_h(dest, "copy data"));
|
||||||
return (PyObject *)dest;
|
return (PyObject *)dest;
|
||||||
|
|
||||||
} else if (dest == Py_None) { /* create new object */
|
} else if (dest == Py_None) { /* create new object */
|
||||||
FsObject *result = PyObject_New(FsObject, &FsType);
|
FsObject *result = PyObject_New(FsObject, &FsType);
|
||||||
|
|
||||||
|
DBG(FS, pymnt_debug_h(result, "new copy"));
|
||||||
result->fs = mnt_copy_fs(NULL, self->fs);
|
result->fs = mnt_copy_fs(NULL, self->fs);
|
||||||
mnt_fs_set_userdata(result->fs, result); /* keep a pointer to encapsulating object */
|
mnt_fs_set_userdata(result->fs, result); /* keep a pointer to encapsulating object */
|
||||||
return (PyObject *)result;
|
return (PyObject *)result;
|
||||||
|
@ -754,7 +767,7 @@ PyTypeObject FsType = {
|
||||||
"libmount.Fs", /*tp_name*/
|
"libmount.Fs", /*tp_name*/
|
||||||
sizeof(FsObject), /*tp_basicsize*/
|
sizeof(FsObject), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
(destructor)Fs_dealloc, /*tp_dealloc*/
|
(destructor)Fs_destructor, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
0, /*tp_getattr*/
|
0, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
|
@ -795,6 +808,7 @@ void FS_AddModuleObject(PyObject *mod)
|
||||||
if (PyType_Ready(&FsType) < 0)
|
if (PyType_Ready(&FsType) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
DBG(FS, pymnt_debug("add to module"));
|
||||||
Py_INCREF(&FsType);
|
Py_INCREF(&FsType);
|
||||||
PyModule_AddObject(mod, "Fs", (PyObject *)&FsType);
|
PyModule_AddObject(mod, "Fs", (PyObject *)&FsType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
|
|
||||||
/* Libmount-specific Exception class */
|
/* Libmount-specific Exception class */
|
||||||
PyObject *LibmountError;
|
PyObject *LibmountError;
|
||||||
|
int pylibmount_debug_mask;
|
||||||
|
|
||||||
|
|
||||||
PyObject *UL_IncRef(void *killme)
|
PyObject *UL_IncRef(void *killme)
|
||||||
{
|
{
|
||||||
|
@ -130,9 +132,27 @@ PyMODINIT_FUNC initpylibmount(void)
|
||||||
|
|
||||||
if (!m)
|
if (!m)
|
||||||
return;
|
return;
|
||||||
|
/*
|
||||||
|
* init debug stuff
|
||||||
|
*/
|
||||||
|
if (!(pylibmount_debug_mask & PYMNT_DEBUG_INIT)) {
|
||||||
|
char *str = getenv("PYLIBMOUNT_DEBUG");
|
||||||
|
|
||||||
/*mnt_init_debug(0xffff);*/
|
pylibmount_debug_mask = 0;
|
||||||
|
if (str)
|
||||||
|
pylibmount_debug_mask = strtoul(str, 0, 0);
|
||||||
|
|
||||||
|
pylibmount_debug_mask |= PYMNT_DEBUG_INIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pylibmount_debug_mask && pylibmount_debug_mask != PYMNT_DEBUG_INIT)
|
||||||
|
DBG(INIT, pymnt_debug("library debug mask: 0x%04x",
|
||||||
|
pylibmount_debug_mask));
|
||||||
|
mnt_init_debug(0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add module objects
|
||||||
|
*/
|
||||||
LibmountError = PyErr_NewException("libmount.Error", NULL, NULL);
|
LibmountError = PyErr_NewException("libmount.Error", NULL, NULL);
|
||||||
Py_INCREF(LibmountError);
|
Py_INCREF(LibmountError);
|
||||||
PyModule_AddObject(m, "Error", (PyObject *)LibmountError);
|
PyModule_AddObject(m, "Error", (PyObject *)LibmountError);
|
||||||
|
|
|
@ -6,6 +6,54 @@
|
||||||
|
|
||||||
#include "libmount.h"
|
#include "libmount.h"
|
||||||
|
|
||||||
|
#define CONFIG_PYLIBMOUNT_DEBUG
|
||||||
|
|
||||||
|
#define PYMNT_DEBUG_INIT (1 << 1)
|
||||||
|
#define PYMNT_DEBUG_TAB (1 << 2)
|
||||||
|
#define PYMNT_DEBUG_FS (1 << 3)
|
||||||
|
#define PYMNT_DEBUG_CXT (1 << 4)
|
||||||
|
|
||||||
|
#ifdef CONFIG_PYLIBMOUNT_DEBUG
|
||||||
|
# include <stdio.h>
|
||||||
|
# include <stdarg.h>
|
||||||
|
|
||||||
|
# define DBG(m, x) do { \
|
||||||
|
if ((PYMNT_DEBUG_ ## m) & pylibmount_debug_mask) { \
|
||||||
|
fprintf(stderr, "%d: pylibmount: %6s: ", getpid(), # m); \
|
||||||
|
x; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
extern int pylibmount_debug_mask;
|
||||||
|
|
||||||
|
static inline void __attribute__ ((__format__ (__printf__, 1, 2)))
|
||||||
|
pymnt_debug(const char *mesg, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, mesg);
|
||||||
|
vfprintf(stderr, mesg, ap);
|
||||||
|
va_end(ap);
|
||||||
|
fputc('\n', stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void __attribute__ ((__format__ (__printf__, 2, 3)))
|
||||||
|
pymnt_debug_h(void *handler, const char *mesg, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
if (handler)
|
||||||
|
fprintf(stderr, "[%p]: ", handler);
|
||||||
|
va_start(ap, mesg);
|
||||||
|
vfprintf(stderr, mesg, ap);
|
||||||
|
va_end(ap);
|
||||||
|
fputc('\n', stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* !CONFIG_PYLIBMOUNT_DEBUG */
|
||||||
|
# define DBG(m,x) do { ; } while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define NODEL_ATTR "This attribute cannot be deleted"
|
#define NODEL_ATTR "This attribute cannot be deleted"
|
||||||
#define CONSTRUCT_ERR "Error during object construction"
|
#define CONSTRUCT_ERR "Error during object construction"
|
||||||
#define ARG_ERR "Invalid number or type of arguments"
|
#define ARG_ERR "Invalid number or type of arguments"
|
||||||
|
|
|
@ -546,19 +546,27 @@ void Table_unref(struct libmnt_table *tab)
|
||||||
if (!tab)
|
if (!tab)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
DBG(TAB, pymnt_debug_h(tab, "un-referencing filesystems"));
|
||||||
|
|
||||||
iter = mnt_new_iter(MNT_ITER_BACKWARD);
|
iter = mnt_new_iter(MNT_ITER_BACKWARD);
|
||||||
|
|
||||||
/* remove pylibmount specific references to the entries */
|
/* remove pylibmount specific references to the entries */
|
||||||
while (mnt_table_next_fs(tab, iter, &fs) == 0)
|
while (mnt_table_next_fs(tab, iter, &fs) == 0)
|
||||||
Py_XDECREF(mnt_fs_get_userdata(fs));
|
Py_XDECREF(mnt_fs_get_userdata(fs));
|
||||||
|
|
||||||
|
DBG(TAB, pymnt_debug_h(tab, "un-referencing table"));
|
||||||
|
|
||||||
mnt_unref_table(tab);
|
mnt_unref_table(tab);
|
||||||
mnt_free_iter(iter);
|
mnt_free_iter(iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Table_destructor(TableObject *self)
|
static void Table_destructor(TableObject *self)
|
||||||
{
|
{
|
||||||
|
DBG(TAB, pymnt_debug_h(self->tab, "destrutor py-obj: %p, py-refcnt=%d",
|
||||||
|
self, (int) ((PyObject *) self)->ob_refcnt));
|
||||||
Table_unref(self->tab);
|
Table_unref(self->tab);
|
||||||
|
self->tab = NULL;
|
||||||
|
|
||||||
mnt_free_iter(self->iter);
|
mnt_free_iter(self->iter);
|
||||||
Py_XDECREF(self->errcb);
|
Py_XDECREF(self->errcb);
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
self->ob_type->tp_free((PyObject*)self);
|
||||||
|
@ -571,6 +579,8 @@ static PyObject *Table_new(PyTypeObject *type,
|
||||||
TableObject *self = (TableObject*)type->tp_alloc(type, 0);
|
TableObject *self = (TableObject*)type->tp_alloc(type, 0);
|
||||||
|
|
||||||
if (self) {
|
if (self) {
|
||||||
|
DBG(TAB, pymnt_debug_h(self, "new"));
|
||||||
|
|
||||||
self->tab = NULL;
|
self->tab = NULL;
|
||||||
self->iter = NULL;
|
self->iter = NULL;
|
||||||
self->errcb = NULL;
|
self->errcb = NULL;
|
||||||
|
@ -588,12 +598,15 @@ static int Table_init(TableObject *self, PyObject *args, PyObject *kwds)
|
||||||
char *kwlist[] = {"path", "errcb", NULL};
|
char *kwlist[] = {"path", "errcb", NULL};
|
||||||
PyObject *errcb = NULL;
|
PyObject *errcb = NULL;
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
|
|
||||||
memset (&buf, 0, sizeof(struct stat));
|
memset (&buf, 0, sizeof(struct stat));
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|sO",
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|sO",
|
||||||
kwlist, &path, &errcb))
|
kwlist, &path, &errcb))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
DBG(TAB, pymnt_debug_h(self, "init"));
|
||||||
|
|
||||||
Table_unref(self->tab);
|
Table_unref(self->tab);
|
||||||
self->tab = NULL;
|
self->tab = NULL;
|
||||||
|
|
||||||
|
@ -615,6 +628,8 @@ static int Table_init(TableObject *self, PyObject *args, PyObject *kwds)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path) {
|
if (path) {
|
||||||
|
DBG(TAB, pymnt_debug_h(self, "init: path defined (%s)", path));
|
||||||
|
|
||||||
if (stat(path, &buf)) {
|
if (stat(path, &buf)) {
|
||||||
/* TODO: weird */
|
/* TODO: weird */
|
||||||
PyErr_SetFromErrno(PyExc_RuntimeError);
|
PyErr_SetFromErrno(PyExc_RuntimeError);
|
||||||
|
@ -624,8 +639,10 @@ static int Table_init(TableObject *self, PyObject *args, PyObject *kwds)
|
||||||
self->tab = mnt_new_table_from_file(path);
|
self->tab = mnt_new_table_from_file(path);
|
||||||
else if (S_ISDIR(buf.st_mode))
|
else if (S_ISDIR(buf.st_mode))
|
||||||
self->tab = mnt_new_table_from_dir(path);
|
self->tab = mnt_new_table_from_dir(path);
|
||||||
} else
|
} else {
|
||||||
|
DBG(TAB, pymnt_debug_h(self, "init: allocate empty table"));
|
||||||
self->tab = mnt_new_table();
|
self->tab = mnt_new_table();
|
||||||
|
}
|
||||||
|
|
||||||
/* Always set custom handler when using libmount from python */
|
/* Always set custom handler when using libmount from python */
|
||||||
mnt_table_set_parser_errcb(self->tab, pymnt_table_parser_errcb);
|
mnt_table_set_parser_errcb(self->tab, pymnt_table_parser_errcb);
|
||||||
|
@ -679,6 +696,8 @@ PyObject *PyObjectResultTab(struct libmnt_table *tab)
|
||||||
result = mnt_table_get_userdata(tab);
|
result = mnt_table_get_userdata(tab);
|
||||||
if (result) {
|
if (result) {
|
||||||
Py_INCREF(result);
|
Py_INCREF(result);
|
||||||
|
DBG(TAB, pymnt_debug_h(tab, "result py-obj %p: already exists, py-refcnt=%d",
|
||||||
|
result, (int) ((PyObject *) result)->ob_refcnt));
|
||||||
return (PyObject *) result;
|
return (PyObject *) result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -694,6 +713,9 @@ PyObject *PyObjectResultTab(struct libmnt_table *tab)
|
||||||
|
|
||||||
Py_INCREF(result);
|
Py_INCREF(result);
|
||||||
mnt_ref_table(tab);
|
mnt_ref_table(tab);
|
||||||
|
|
||||||
|
DBG(TAB, pymnt_debug_h(tab, "result py-obj %p new, py-refcnt=%d",
|
||||||
|
result, (int) ((PyObject *) result)->ob_refcnt));
|
||||||
result->tab = tab;
|
result->tab = tab;
|
||||||
result->iter = mnt_new_iter(MNT_ITER_FORWARD);
|
result->iter = mnt_new_iter(MNT_ITER_FORWARD);
|
||||||
mnt_table_set_userdata(result->tab, result);
|
mnt_table_set_userdata(result->tab, result);
|
||||||
|
@ -767,6 +789,8 @@ void Table_AddModuleObject(PyObject *mod)
|
||||||
if (PyType_Ready(&TableType) < 0)
|
if (PyType_Ready(&TableType) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
DBG(TAB, pymnt_debug("add to module"));
|
||||||
|
|
||||||
Py_INCREF(&TableType);
|
Py_INCREF(&TableType);
|
||||||
PyModule_AddObject(mod, "Table", (PyObject *)&TableType);
|
PyModule_AddObject(mod, "Table", (PyObject *)&TableType);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue