From 386778e629ac0c83a22cc68eca37794c7f3391f3 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 19 Mar 2020 13:59:18 +0100 Subject: [PATCH 001/341] breg.h: fix compile problems on old gcc versions --- core/src/lib/breg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/lib/breg.h b/core/src/lib/breg.h index 2e9f7790547..394a6fed67a 100644 --- a/core/src/lib/breg.h +++ b/core/src/lib/breg.h @@ -68,7 +68,7 @@ class BareosRegex { /* private */ POOLMEM* expr = nullptr; /**< search epression */ POOLMEM* subst = nullptr; /**< substitution */ - regex_t preg{}; /**< regex_t result of regcomp() */ + regex_t preg{0}; /**< regex_t result of regcomp() */ regmatch_t regs[BREG_NREGS]{}; /**< contains match */ char* eor = nullptr; /**< end of regexp in expr */ From 5be93ecd6edb36d11623995473a5673b1a5d7cde Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 17 Feb 2020 13:30:17 +0100 Subject: [PATCH 002/341] systemtests: fix python-dir-plugin-test --- systemtests/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 303869a80aa..8311a60ff87 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -495,6 +495,7 @@ else() # run systemtests on source and compiled files if(TARGET bareossd-gfapi) get_target_property(SD_BACKEND_DIR_TO_TEST bareossd-gfapi BINARY_DIR) endif() + if(TARGET python-dir) get_target_property(DIR_PLUGINS_DIR_TO_TEST python-dir BINARY_DIR) else() From bfb4f4f00ec6eafdb532dd93a9d2d5520e7901cd Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 17 Feb 2020 09:13:42 +0100 Subject: [PATCH 003/341] python plugins: initialize modules via PyImport_AppendInittab() This commit changes the module initialization for the python plugins in the way that the python documentation describes. Before, the modules were added AFTER Py_Initialize() was called which will not work on Python 3. Also the module initialization was adapted so that the porting to Python 3 will be easier. See http://python3porting.com/cextensions.html for details. --- core/src/plugins/dird/python-dir.cc | 22 +++---- core/src/plugins/dird/python-dir.h | 27 +++++++- core/src/plugins/filed/python-fd.cc | 99 +++------------------------- core/src/plugins/filed/python-fd.h | 75 ++++++++++++++++++++- core/src/plugins/stored/python-sd.cc | 24 +++---- core/src/plugins/stored/python-sd.h | 27 +++++++- 6 files changed, 150 insertions(+), 124 deletions(-) diff --git a/core/src/plugins/dird/python-dir.cc b/core/src/plugins/dird/python-dir.cc index 5a24df63885..32268205668 100644 --- a/core/src/plugins/dird/python-dir.cc +++ b/core/src/plugins/dird/python-dir.cc @@ -2,7 +2,7 @@ BAREOS® - Backup Archiving REcovery Open Sourced Copyright (C) 2011-2014 Planets Communications B.V. - Copyright (C) 2013-2019 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -108,7 +108,6 @@ struct plugin_ctx { char* module_name; /* Plugin Module Name */ PyThreadState* interpreter; /* Python interpreter for this instance of the plugin */ - PyObject* pInstance; /* Python Module instance */ PyObject* pModule; /* Python Module entry point */ PyObject* pDict; /* Python Dictionary */ PyObject* bpContext; /* Python representation of plugin context */ @@ -146,6 +145,11 @@ bRC loadPlugin(bDirInfo* lbinfo, /* * Setup Python */ +#if PY_MAJOR_VERSION >= 3 + PyImport_AppendInittab("bareosdir", &PyInit_bareosdir); +#else + PyImport_AppendInittab("bareosdir", Init_bareosdir); +#endif Py_InitializeEx(0); PyEval_InitThreads(); mainThreadState = PyEval_SaveThread(); @@ -183,7 +187,7 @@ static bRC newPlugin(bpContext* ctx) /* * For each plugin instance we instantiate a new Python interpreter. */ - PyEval_AcquireLock(); + PyEval_AcquireThread(mainThreadState); p_ctx->interpreter = Py_NewInterpreter(); PyEval_ReleaseThread(p_ctx->interpreter); @@ -273,7 +277,7 @@ static bRC handlePluginEvent(bpContext* ctx, bDirEvent* event, void* value) * See if we have been triggered in the previous switch if not we have to * always dispatch the event. If we already processed the event internally * we only do a dispatch to the python entry point when that internal - * processing was successfull (e.g. retval == bRC_OK). + * processing was successful (e.g. retval == bRC_OK). */ if (!event_dispatched || retval == bRC_OK) { PyEval_AcquireThread(p_ctx->interpreter); @@ -653,16 +657,6 @@ static bRC PyLoadModule(bpContext* ctx, void* value) } } - /* - * See if we already setup the module structure. - */ - if (!p_ctx->pInstance) { - /* - * Make our callback methods available for Python. - */ - p_ctx->pInstance = Py_InitModule("bareosdir", BareosDIRMethods); - } - /* * Try to load the Python module by name. */ diff --git a/core/src/plugins/dird/python-dir.h b/core/src/plugins/dird/python-dir.h index ba78bd6f828..397e86cdbbe 100644 --- a/core/src/plugins/dird/python-dir.h +++ b/core/src/plugins/dird/python-dir.h @@ -2,7 +2,7 @@ BAREOS® - Backup Archiving REcovery Open Sourced Copyright (C) 2013-2014 Planets Communications B.V. - Copyright (C) 2013-2016 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can modify it under the terms of version three of the GNU Affero General Public License as published by the @@ -75,5 +75,30 @@ static PyMethodDef BareosDIRMethods[] = { "Get number of instances of current plugin"}, {NULL, NULL, 0, NULL}}; + +#if PY_MAJOR_VERSION >= 3 +#define MOD_ERROR_VAL NULL +#define MOD_SUCCESS_VAL(val) val +#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void) +#define MOD_DEF(ob, name, doc, methods) \ + static struct PyModuleDef moduledef = { \ + PyModuleDef_HEAD_INIT, name, doc, -1, methods, \ + }; \ + ob = PyModule_Create(&moduledef); +#else +#define MOD_ERROR_VAL +#define MOD_SUCCESS_VAL(val) +#define MOD_INIT(name) void Init_##name(void) +#define MOD_DEF(ob, name, doc, methods) ob = Py_InitModule3(name, methods, doc); +#endif + + +MOD_INIT(bareosdir) +{ + PyObject* BareosDirModule; + MOD_DEF(BareosDirModule, "bareosdir", NULL, BareosDIRMethods) + return MOD_SUCCESS_VAL(BareosDirModule); +} + } /* namespace directordaemon */ #endif /* BAREOS_PLUGINS_DIRD_PYTHON_DIR_H_ */ diff --git a/core/src/plugins/filed/python-fd.cc b/core/src/plugins/filed/python-fd.cc index 2df030fe7d2..385e433f42a 100644 --- a/core/src/plugins/filed/python-fd.cc +++ b/core/src/plugins/filed/python-fd.cc @@ -141,7 +141,6 @@ struct plugin_ctx { char* object; /* Restore Object Content */ PyThreadState* interpreter; /* Python interpreter for this instance of the plugin */ - PyObject* pInstance; /* Python Module instance */ PyObject* pModule; /* Python Module entry point */ PyObject* pDict; /* Python Dictionary */ PyObject* bpContext; /* Python representation of plugin context */ @@ -172,9 +171,13 @@ bRC loadPlugin(bInfo* lbinfo, *pinfo = &pluginInfo; /* Return pointer to our info */ *pfuncs = &pluginFuncs; /* Return pointer to our functions */ - /* - * Setup Python - */ + /* Setup Python */ +#if PY_MAJOR_VERSION >= 3 + PyImport_AppendInittab("bareosfd", &PyInit_bareosfd); +#else + PyImport_AppendInittab("bareosfd", Init_bareosfd); +#endif + Py_InitializeEx(0); PyEval_InitThreads(); mainThreadState = PyEval_SaveThread(); @@ -220,7 +223,7 @@ static bRC newPlugin(bpContext* ctx) /* * For each plugin instance we instantiate a new Python interpreter. */ - PyEval_AcquireLock(); + PyEval_AcquireThread(mainThreadState); p_ctx->interpreter = Py_NewInterpreter(); PyEval_ReleaseThread(p_ctx->interpreter); @@ -1141,89 +1144,6 @@ static bRC PyLoadModule(bpContext* ctx, void* value) } } - /* - * See if we already setup the module structure. - */ - if (!p_ctx->pInstance) { - /* - * Make our callback methods available for Python. - */ - p_ctx->pInstance = Py_InitModule("bareosfd", BareosFDMethods); - - /* - * Fill in the slots of PyRestoreObject - */ - PyRestoreObjectType.tp_new = PyType_GenericNew; - if (PyType_Ready(&PyRestoreObjectType) < 0) { goto cleanup; } - - /* - * Fill in the slots of PyStatPacket - */ - PyStatPacketType.tp_new = PyType_GenericNew; - if (PyType_Ready(&PyStatPacketType) < 0) { goto cleanup; } - - /* - * Fill in the slots of PySavePacket - */ - PySavePacketType.tp_new = PyType_GenericNew; - if (PyType_Ready(&PySavePacketType) < 0) { goto cleanup; } - - /* - * Fill in the slots of PyRestorePacket - */ - PyRestorePacketType.tp_new = PyType_GenericNew; - if (PyType_Ready(&PyRestorePacketType) < 0) { goto cleanup; } - - /* - * Fill in the slots of PyIoPacketType - */ - PyIoPacketType.tp_new = PyType_GenericNew; - if (PyType_Ready(&PyIoPacketType) < 0) { goto cleanup; } - - /* - * Fill in the slots of PyAclPacketType - */ - PyAclPacketType.tp_new = PyType_GenericNew; - if (PyType_Ready(&PyAclPacketType) < 0) { goto cleanup; } - - /* - * Fill in the slots of PyXattrPacketType - */ - PyXattrPacketType.tp_new = PyType_GenericNew; - if (PyType_Ready(&PyXattrPacketType) < 0) { goto cleanup; } - - /* - * Add the types to the module - */ - Py_INCREF(&PyRestoreObjectType); - PyModule_AddObject(p_ctx->pInstance, "RestoreObject", - (PyObject*)&PyRestoreObjectType); - - Py_INCREF(&PyStatPacketType); - PyModule_AddObject(p_ctx->pInstance, "StatPacket", - (PyObject*)&PyStatPacketType); - - Py_INCREF(&PySavePacketType); - PyModule_AddObject(p_ctx->pInstance, "SavePacket", - (PyObject*)&PySavePacketType); - - Py_INCREF(&PyRestorePacketType); - PyModule_AddObject(p_ctx->pInstance, "RestorePacket", - (PyObject*)&PyRestorePacketType); - - Py_INCREF(&PyIoPacketType); - PyModule_AddObject(p_ctx->pInstance, "IoPacket", - (PyObject*)&PyIoPacketType); - - Py_INCREF(&PyAclPacketType); - PyModule_AddObject(p_ctx->pInstance, "AclPacket", - (PyObject*)&PyAclPacketType); - - Py_INCREF(&PyXattrPacketType); - PyModule_AddObject(p_ctx->pInstance, "XattrPacket", - (PyObject*)&PyXattrPacketType); - } - /* * Try to load the Python module by name. */ @@ -1289,9 +1209,6 @@ static bRC PyLoadModule(bpContext* ctx, void* value) return retval; -cleanup: - p_ctx->pInstance = NULL; - bail_out: if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } diff --git a/core/src/plugins/filed/python-fd.h b/core/src/plugins/filed/python-fd.h index 379a7d9ba2d..e02df76ff6d 100644 --- a/core/src/plugins/filed/python-fd.h +++ b/core/src/plugins/filed/python-fd.h @@ -2,7 +2,7 @@ BAREOS® - Backup Archiving REcovery Open Sourced Copyright (C) 2013-2014 Planets Communications B.V. - Copyright (C) 2013-2016 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can modify it under the terms of version three of the GNU Affero General Public License as published by the @@ -741,5 +741,78 @@ static PyMethodDef BareosFDMethods[] = { "Clear bit in the Accurate Seen bitmap"}, {NULL, NULL, 0, NULL}}; + +#if PY_MAJOR_VERSION >= 3 +#define MOD_ERROR_VAL NULL +#define MOD_SUCCESS_VAL(val) val +#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void) +#define MOD_DEF(ob, name, doc, methods) \ + static struct PyModuleDef moduledef = { \ + PyModuleDef_HEAD_INIT, name, doc, -1, methods, \ + }; \ + ob = PyModule_Create(&moduledef); +#else +#define MOD_ERROR_VAL +#define MOD_SUCCESS_VAL(val) +#define MOD_INIT(name) void Init_##name(void) +#define MOD_DEF(ob, name, doc, methods) ob = Py_InitModule3(name, methods, doc); +#endif + + +MOD_INIT(bareosfd) +{ + PyObject* BareosFdModule; + + MOD_DEF(BareosFdModule, "bareosfd", NULL, BareosFDMethods) + + PyRestoreObjectType.tp_new = PyType_GenericNew; + if (PyType_Ready(&PyRestoreObjectType) < 0) { return MOD_ERROR_VAL; } + + PyStatPacketType.tp_new = PyType_GenericNew; + if (PyType_Ready(&PyStatPacketType) < 0) { return MOD_ERROR_VAL; } + + PySavePacketType.tp_new = PyType_GenericNew; + if (PyType_Ready(&PySavePacketType) < 0) { return MOD_ERROR_VAL; } + + PyRestorePacketType.tp_new = PyType_GenericNew; + if (PyType_Ready(&PyRestorePacketType) < 0) { return MOD_ERROR_VAL; } + + PyIoPacketType.tp_new = PyType_GenericNew; + if (PyType_Ready(&PyIoPacketType) < 0) { return MOD_ERROR_VAL; } + + PyAclPacketType.tp_new = PyType_GenericNew; + if (PyType_Ready(&PyAclPacketType) < 0) { return MOD_ERROR_VAL; } + + PyXattrPacketType.tp_new = PyType_GenericNew; + if (PyType_Ready(&PyXattrPacketType) < 0) { return MOD_ERROR_VAL; } + + Py_INCREF(&PyRestoreObjectType); + PyModule_AddObject(BareosFdModule, "RestoreObject", + (PyObject*)&PyRestoreObjectType); + + Py_INCREF(&PyStatPacketType); + PyModule_AddObject(BareosFdModule, "StatPacket", + (PyObject*)&PyStatPacketType); + + Py_INCREF(&PySavePacketType); + PyModule_AddObject(BareosFdModule, "SavePacket", + (PyObject*)&PySavePacketType); + + Py_INCREF(&PyRestorePacketType); + PyModule_AddObject(BareosFdModule, "RestorePacket", + (PyObject*)&PyRestorePacketType); + + Py_INCREF(&PyIoPacketType); + PyModule_AddObject(BareosFdModule, "IoPacket", (PyObject*)&PyIoPacketType); + + Py_INCREF(&PyAclPacketType); + PyModule_AddObject(BareosFdModule, "AclPacket", (PyObject*)&PyAclPacketType); + + Py_INCREF(&PyXattrPacketType); + PyModule_AddObject(BareosFdModule, "XattrPacket", + (PyObject*)&PyXattrPacketType); + + return MOD_SUCCESS_VAL(BareosFdModule); +} } /* namespace filedaemon */ #endif /* BAREOS_PLUGINS_FILED_PYTHON_FD_H_ */ diff --git a/core/src/plugins/stored/python-sd.cc b/core/src/plugins/stored/python-sd.cc index 85f0c0280e8..f3428a8db21 100644 --- a/core/src/plugins/stored/python-sd.cc +++ b/core/src/plugins/stored/python-sd.cc @@ -2,7 +2,7 @@ BAREOS® - Backup Archiving REcovery Open Sourced Copyright (C) 2011-2014 Planets Communications B.V. - Copyright (C) 2013-2019 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -103,7 +103,6 @@ struct plugin_ctx { char* module_name; /* Plugin Module Name */ PyThreadState* interpreter; /* Python interpreter for this instance of the plugin */ - PyObject* pInstance; /* Python Module instance */ PyObject* pModule; /* Python Module entry point */ PyObject* pDict; /* Python Dictionary */ PyObject* bpContext; /* Python representation of plugin context */ @@ -141,9 +140,12 @@ bRC loadPlugin(bsdInfo* lbinfo, *pinfo = &pluginInfo; /* Return pointer to our info */ *pfuncs = &pluginFuncs; /* Return pointer to our functions */ - /* - * Setup Python - */ + /* Setup Python */ +#if PY_MAJOR_VERSION >= 3 + PyImport_AppendInittab("bareossd", &PyInit_bareossd); +#else + PyImport_AppendInittab("bareossd", Init_bareossd); +#endif Py_InitializeEx(0); PyEval_InitThreads(); mainThreadState = PyEval_SaveThread(); @@ -189,7 +191,7 @@ static bRC newPlugin(bpContext* ctx) /* * For each plugin instance we instantiate a new Python interpreter. */ - PyEval_AcquireLock(); + PyEval_AcquireThread(mainThreadState); p_ctx->interpreter = Py_NewInterpreter(); PyEval_ReleaseThread(p_ctx->interpreter); @@ -671,16 +673,6 @@ static bRC PyLoadModule(bpContext* ctx, void* value) } } - /* - * See if we already setup the module structure. - */ - if (!p_ctx->pInstance) { - /* - * Make our callback methods available for Python. - */ - p_ctx->pInstance = Py_InitModule("bareossd", BareosSDMethods); - } - /* * Try to load the Python module by name. */ diff --git a/core/src/plugins/stored/python-sd.h b/core/src/plugins/stored/python-sd.h index 4b4351dd7b5..0b3e003c26f 100644 --- a/core/src/plugins/stored/python-sd.h +++ b/core/src/plugins/stored/python-sd.h @@ -2,7 +2,7 @@ BAREOS® - Backup Archiving REcovery Open Sourced Copyright (C) 2013-2014 Planets Communications B.V. - Copyright (C) 2013-2016 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can modify it under the terms of version three of the GNU Affero General Public License as published by the @@ -73,4 +73,29 @@ static PyMethodDef BareosSDMethods[] = { "Get number of instances of current plugin"}, {NULL, NULL, 0, NULL}}; + +#if PY_MAJOR_VERSION >= 3 +#define MOD_ERROR_VAL NULL +#define MOD_SUCCESS_VAL(val) val +#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void) +#define MOD_DEF(ob, name, doc, methods) \ + static struct PyModuleDef moduledef = { \ + PyModuleDef_HEAD_INIT, name, doc, -1, methods, \ + }; \ + ob = PyModule_Create(&moduledef); +#else +#define MOD_ERROR_VAL +#define MOD_SUCCESS_VAL(val) +#define MOD_INIT(name) void Init_##name(void) +#define MOD_DEF(ob, name, doc, methods) ob = Py_InitModule3(name, methods, doc); +#endif + + +MOD_INIT(bareossd) +{ + PyObject* BareosSdModule; + MOD_DEF(BareosSdModule, "bareossd", NULL, BareosSDMethods) + return MOD_SUCCESS_VAL(BareosSdModule); +} + #endif /* BAREOS_PLUGINS_STORED_PYTHON_SD_H_ */ From 2ed18c974766b56b0d61c649039f92c67c406152 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 27 Feb 2020 17:27:38 +0100 Subject: [PATCH 004/341] python-fd.h: add ctx PyCapsule --- core/src/plugins/filed/python-fd.h | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/core/src/plugins/filed/python-fd.h b/core/src/plugins/filed/python-fd.h index e02df76ff6d..d18c75e7f64 100644 --- a/core/src/plugins/filed/python-fd.h +++ b/core/src/plugins/filed/python-fd.h @@ -761,10 +761,33 @@ static PyMethodDef BareosFDMethods[] = { MOD_INIT(bareosfd) { - PyObject* BareosFdModule; + /* ctx holds the bpContext instead of passing to Python and extracting it + * back like it was before. + * ctx needs to be set after loading the bareosfd binary python module and + * will be used for all calls. + */ + static void* ctx = NULL; + PyObject* BareosFdModule = NULL; + + /* Pointer Capsules to avoid context transfer back and forth */ + PyObject* PyFdModulePluginContext = + PyCapsule_New((void*)&bareos_plugin_context, "bareosfd.bpContext", NULL); + + if (!PyFdModulePluginContext) { + printf("python-fd.h: PyCapsule_New failed\n"); + return MOD_ERROR_VAL; + } MOD_DEF(BareosFdModule, "bareosfd", NULL, BareosFDMethods) + if (PyFdModulePluginContext) { + PyModule_AddObject(BareosFdModule, "bpContext", PyFdModulePluginContext); + } else { + printf("python-fd.h:PyModule_AddObject failed\n"); + return MOD_ERROR_VAL; + } + + PyRestoreObjectType.tp_new = PyType_GenericNew; if (PyType_Ready(&PyRestoreObjectType) < 0) { return MOD_ERROR_VAL; } From 6eb4c4b37ad992259f335d74efe8ab5bcd8d4774 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 27 Feb 2020 18:06:07 +0100 Subject: [PATCH 005/341] python-fd.cc: renamed cryptic variable names --- core/src/plugins/filed/python-fd.cc | 965 +++++++++++++++------------- 1 file changed, 531 insertions(+), 434 deletions(-) diff --git a/core/src/plugins/filed/python-fd.cc b/core/src/plugins/filed/python-fd.cc index 385e433f42a..2753b29a9b1 100644 --- a/core/src/plugins/filed/python-fd.cc +++ b/core/src/plugins/filed/python-fd.cc @@ -60,47 +60,63 @@ static const int debuglevel = 150; /** * Forward referenced functions */ -static bRC newPlugin(bpContext* ctx); -static bRC freePlugin(bpContext* ctx); -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value); -static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp); -static bRC endBackupFile(bpContext* ctx); -static bRC pluginIO(bpContext* ctx, struct io_pkt* io); -static bRC startRestoreFile(bpContext* ctx, const char* cmd); -static bRC endRestoreFile(bpContext* ctx); -static bRC createFile(bpContext* ctx, struct restore_pkt* rp); -static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp); -static bRC checkFile(bpContext* ctx, char* fname); -static bRC getAcl(bpContext* ctx, acl_pkt* ap); -static bRC setAcl(bpContext* ctx, acl_pkt* ap); -static bRC getXattr(bpContext* ctx, xattr_pkt* xp); -static bRC setXattr(bpContext* ctx, xattr_pkt* xp); -static bRC parse_plugin_definition(bpContext* ctx, +static bRC newPlugin(bpContext* bareos_plugin_ctx); +static bRC freePlugin(bpContext* bareos_plugin_ctx); +static bRC getPluginValue(bpContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC setPluginValue(bpContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, + bEvent* event, + void* value); +static bRC startBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp); +static bRC endBackupFile(bpContext* bareos_plugin_ctx); +static bRC pluginIO(bpContext* bareos_plugin_ctx, struct io_pkt* io); +static bRC startRestoreFile(bpContext* bareos_plugin_ctx, const char* cmd); +static bRC endRestoreFile(bpContext* bareos_plugin_ctx); +static bRC createFile(bpContext* bareos_plugin_ctx, struct restore_pkt* rp); +static bRC setFileAttributes(bpContext* bareos_plugin_ctx, + struct restore_pkt* rp); +static bRC checkFile(bpContext* bareos_plugin_ctx, char* fname); +static bRC getAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC setAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC getXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC setXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, void* value, PoolMem& plugin_options); -static void PyErrorHandler(bpContext* ctx, int msgtype); -static bRC PyLoadModule(bpContext* ctx, void* value); -static bRC PyParsePluginDefinition(bpContext* ctx, void* value); -static bRC PyGetPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC PySetPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC PyHandlePluginEvent(bpContext* ctx, bEvent* event, void* value); -static bRC PyStartBackupFile(bpContext* ctx, struct save_pkt* sp); -static bRC PyEndBackupFile(bpContext* ctx); -static bRC PyPluginIO(bpContext* ctx, struct io_pkt* io); -static bRC PyStartRestoreFile(bpContext* ctx, const char* cmd); -static bRC PyEndRestoreFile(bpContext* ctx); -static bRC PyCreateFile(bpContext* ctx, struct restore_pkt* rp); -static bRC PySetFileAttributes(bpContext* ctx, struct restore_pkt* rp); -static bRC PyCheckFile(bpContext* ctx, char* fname); -static bRC PyGetAcl(bpContext* ctx, acl_pkt* ap); -static bRC PySetAcl(bpContext* ctx, acl_pkt* ap); -static bRC PyGetXattr(bpContext* ctx, xattr_pkt* xp); -static bRC PySetXattr(bpContext* ctx, xattr_pkt* xp); -static bRC PyRestoreObjectData(bpContext* ctx, struct restore_object_pkt* rop); -static bRC PyHandleBackupFile(bpContext* ctx, struct save_pkt* sp); +static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype); +static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value); +static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value); +static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, + bEvent* event, + void* value); +static bRC PyStartBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp); +static bRC PyEndBackupFile(bpContext* bareos_plugin_ctx); +static bRC PyPluginIO(bpContext* bareos_plugin_ctx, struct io_pkt* io); +static bRC PyStartRestoreFile(bpContext* bareos_plugin_ctx, const char* cmd); +static bRC PyEndRestoreFile(bpContext* bareos_plugin_ctx); +static bRC PyCreateFile(bpContext* bareos_plugin_ctx, struct restore_pkt* rp); +static bRC PySetFileAttributes(bpContext* bareos_plugin_ctx, + struct restore_pkt* rp); +static bRC PyCheckFile(bpContext* bareos_plugin_ctx, char* fname); +static bRC PyGetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC PySetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC PyGetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC PySetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC PyRestoreObjectData(bpContext* bareos_plugin_ctx, + struct restore_object_pkt* rop); +static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, + struct save_pkt* sp); /** * Pointers to Bareos functions @@ -124,10 +140,7 @@ static pFuncs pluginFuncs = { endBackupFile, startRestoreFile, endRestoreFile, pluginIO, createFile, setFileAttributes, checkFile, getAcl, setAcl, getXattr, setXattr}; -/** - * Plugin private context - */ -struct plugin_ctx { +struct plugin_private_context { int32_t backup_level; /* Backup level e.g. Full/Differential/Incremental */ utime_t since; /* Since time for Differential/Incremental */ bool python_loaded; /* Plugin has python module loaded ? */ @@ -140,10 +153,10 @@ struct plugin_ctx { char* object_name; /* Restore Object Name */ char* object; /* Restore Object Content */ PyThreadState* - interpreter; /* Python interpreter for this instance of the plugin */ - PyObject* pModule; /* Python Module entry point */ - PyObject* pDict; /* Python Dictionary */ - PyObject* bpContext; /* Python representation of plugin context */ + interpreter; /* Python interpreter for this instance of the plugin */ + PyObject* pModule; /* Python Module entry point */ + PyObject* pyModuleFunctionsDict; /* Python Dictionary */ + PyObject* py_bpContext; /* Python representation of plugin context */ }; /** @@ -211,28 +224,30 @@ bRC unloadPlugin() * plugin instance must be thread safe and keep its own * local data. */ -static bRC newPlugin(bpContext* ctx) +static bRC newPlugin(bpContext* bareos_plugin_ctx) { - struct plugin_ctx* p_ctx; + struct plugin_private_context* plugin_priv_ctx; - p_ctx = (struct plugin_ctx*)malloc(sizeof(struct plugin_ctx)); - if (!p_ctx) { return bRC_Error; } - memset(p_ctx, 0, sizeof(struct plugin_ctx)); - ctx->pContext = (void*)p_ctx; /* set our context pointer */ + plugin_priv_ctx = (struct plugin_private_context*)malloc( + sizeof(struct plugin_private_context)); + if (!plugin_priv_ctx) { return bRC_Error; } + memset(plugin_priv_ctx, 0, sizeof(struct plugin_private_context)); + bareos_plugin_ctx->pContext = + (void*)plugin_priv_ctx; /* set our context pointer */ /* * For each plugin instance we instantiate a new Python interpreter. */ PyEval_AcquireThread(mainThreadState); - p_ctx->interpreter = Py_NewInterpreter(); - PyEval_ReleaseThread(p_ctx->interpreter); + plugin_priv_ctx->interpreter = Py_NewInterpreter(); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); /* * Always register some events the python plugin itself can register * any other events it is interested in. */ bfuncs->registerBareosEvents( - ctx, 9, bEventLevel, bEventSince, bEventNewPluginOptions, + bareos_plugin_ctx, 9, bEventLevel, bEventSince, bEventNewPluginOptions, bEventPluginCommand, bEventJobStart, bEventRestoreCommand, bEventEstimateCommand, bEventBackupCommand, bEventRestoreObject); @@ -243,43 +258,48 @@ static bRC newPlugin(bpContext* ctx) * Release everything concerning a particular instance of a * plugin. Normally called when the Job terminates. */ -static bRC freePlugin(bpContext* ctx) +static bRC freePlugin(bpContext* bareos_plugin_ctx) { - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; - if (!p_ctx) { return bRC_Error; } + if (!plugin_priv_ctx) { return bRC_Error; } - if (p_ctx->plugin_options) { free(p_ctx->plugin_options); } + if (plugin_priv_ctx->plugin_options) { + free(plugin_priv_ctx->plugin_options); + } - if (p_ctx->module_path) { free(p_ctx->module_path); } + if (plugin_priv_ctx->module_path) { free(plugin_priv_ctx->module_path); } - if (p_ctx->module_name) { free(p_ctx->module_name); } + if (plugin_priv_ctx->module_name) { free(plugin_priv_ctx->module_name); } - if (p_ctx->fname) { free(p_ctx->fname); } + if (plugin_priv_ctx->fname) { free(plugin_priv_ctx->fname); } - if (p_ctx->link) { free(p_ctx->link); } + if (plugin_priv_ctx->link) { free(plugin_priv_ctx->link); } - if (p_ctx->object_name) { free(p_ctx->object_name); } + if (plugin_priv_ctx->object_name) { free(plugin_priv_ctx->object_name); } - if (p_ctx->object) { free(p_ctx->object); } + if (plugin_priv_ctx->object) { free(plugin_priv_ctx->object); } /* * Stop any sub interpreter started per plugin instance. */ - PyEval_AcquireThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); /* * Do python cleanup calls. */ - if (p_ctx->bpContext) { Py_DECREF(p_ctx->bpContext); } + if (plugin_priv_ctx->py_bpContext) { + Py_DECREF(plugin_priv_ctx->py_bpContext); + } - if (p_ctx->pModule) { Py_DECREF(p_ctx->pModule); } + if (plugin_priv_ctx->pModule) { Py_DECREF(plugin_priv_ctx->pModule); } - Py_EndInterpreter(p_ctx->interpreter); + Py_EndInterpreter(plugin_priv_ctx->interpreter); PyEval_ReleaseLock(); - free(p_ctx); - ctx->pContext = NULL; + free(plugin_priv_ctx); + bareos_plugin_ctx->pContext = NULL; return bRC_OK; } @@ -288,16 +308,19 @@ static bRC freePlugin(bpContext* ctx) * Called by core code to get a variable from the plugin. * Not currently used. */ -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC getPluginValue(bpContext* bareos_plugin_ctx, + pVariable var, + void* value) { - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; bRC retval = bRC_Error; - if (!p_ctx) { goto bail_out; } + if (!plugin_priv_ctx) { goto bail_out; } - PyEval_AcquireThread(p_ctx->interpreter); - retval = PyGetPluginValue(ctx, var, value); - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyGetPluginValue(bareos_plugin_ctx, var, value); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: return retval; @@ -307,16 +330,19 @@ static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) * Called by core code to set a plugin variable. * Not currently used. */ -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC setPluginValue(bpContext* bareos_plugin_ctx, + pVariable var, + void* value) { - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; bRC retval = bRC_Error; - if (!p_ctx) { return bRC_Error; } + if (!plugin_priv_ctx) { return bRC_Error; } - PyEval_AcquireThread(p_ctx->interpreter); - retval = PySetPluginValue(ctx, var, value); - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PySetPluginValue(bareos_plugin_ctx, var, value); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); return retval; } @@ -325,14 +351,17 @@ static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) * Called by Bareos when there are certain events that the * plugin might want to know. The value depends on the event. */ -static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) +static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, + bEvent* event, + void* value) { bRC retval = bRC_Error; bool event_dispatched = false; PoolMem plugin_options(PM_FNAME); - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_private_context* plugin_priv_ctx = + (plugin_private_context*)bareos_plugin_ctx->pContext; - if (!p_ctx) { goto bail_out; } + if (!plugin_priv_ctx) { goto bail_out; } /* * First handle some events internally before calling python if it @@ -340,10 +369,10 @@ static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) */ switch (event->eventType) { case bEventLevel: - p_ctx->backup_level = (int64_t)value; + plugin_priv_ctx->backup_level = (int64_t)value; break; case bEventSince: - p_ctx->since = (int64_t)value; + plugin_priv_ctx->since = (int64_t)value; break; case bEventBackupCommand: /* @@ -359,24 +388,26 @@ static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) */ case bEventPluginCommand: event_dispatched = true; - retval = parse_plugin_definition(ctx, value, plugin_options); + retval = + parse_plugin_definition(bareos_plugin_ctx, value, plugin_options); break; case bEventNewPluginOptions: /* * Free any previous value. */ - if (p_ctx->plugin_options) { - free(p_ctx->plugin_options); - p_ctx->plugin_options = NULL; + if (plugin_priv_ctx->plugin_options) { + free(plugin_priv_ctx->plugin_options); + plugin_priv_ctx->plugin_options = NULL; } event_dispatched = true; - retval = parse_plugin_definition(ctx, value, plugin_options); + retval = + parse_plugin_definition(bareos_plugin_ctx, value, plugin_options); /* * Save that we got a plugin override. */ - p_ctx->plugin_options = strdup((char*)value); + plugin_priv_ctx->plugin_options = strdup((char*)value); break; case bEventRestoreObject: { struct restore_object_pkt* rop; @@ -387,11 +418,11 @@ static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) * Only use the plugin definition of a restore object if we * didn't get any other plugin definition from some other source before. */ - if (!p_ctx->python_loaded) { + if (!plugin_priv_ctx->python_loaded) { if (rop && *rop->plugin_name) { event_dispatched = true; - retval = - parse_plugin_definition(ctx, rop->plugin_name, plugin_options); + retval = parse_plugin_definition(bareos_plugin_ctx, rop->plugin_name, + plugin_options); } } break; @@ -407,7 +438,7 @@ static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) * processing was successfull (e.g. retval == bRC_OK). */ if (!event_dispatched || retval == bRC_OK) { - PyEval_AcquireThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); /* * Now dispatch the event to Python. @@ -434,15 +465,16 @@ static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) /* * See if we already loaded the Python modules. */ - if (!p_ctx->python_loaded) { - retval = PyLoadModule(ctx, plugin_options.c_str()); + if (!plugin_priv_ctx->python_loaded) { + retval = PyLoadModule(bareos_plugin_ctx, plugin_options.c_str()); } /* * Only try to call when the loading succeeded. */ if (retval == bRC_OK) { - retval = PyParsePluginDefinition(ctx, plugin_options.c_str()); + retval = PyParsePluginDefinition(bareos_plugin_ctx, + plugin_options.c_str()); } break; case bEventRestoreObject: { @@ -459,24 +491,27 @@ static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) /* * See if we already loaded the Python modules. */ - if (!p_ctx->python_loaded && *rop->plugin_name) { - retval = PyLoadModule(ctx, plugin_options.c_str()); + if (!plugin_priv_ctx->python_loaded && *rop->plugin_name) { + retval = PyLoadModule(bareos_plugin_ctx, plugin_options.c_str()); /* * Only try to call when the loading succeeded. */ if (retval == bRC_OK) { - retval = PyParsePluginDefinition(ctx, plugin_options.c_str()); - if (retval == bRC_OK) { retval = PyRestoreObjectData(ctx, rop); } + retval = PyParsePluginDefinition(bareos_plugin_ctx, + plugin_options.c_str()); + if (retval == bRC_OK) { + retval = PyRestoreObjectData(bareos_plugin_ctx, rop); + } } } else { - retval = PyRestoreObjectData(ctx, rop); + retval = PyRestoreObjectData(bareos_plugin_ctx, rop); } } break; } case bEventHandleBackupFile: - retval = PyHandleBackupFile(ctx, (struct save_pkt*)value); + retval = PyHandleBackupFile(bareos_plugin_ctx, (struct save_pkt*)value); break; default: /* @@ -484,15 +519,15 @@ static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) * We only try to call Python when we loaded the right module until * that time we pretend the call succeeded. */ - if (p_ctx->python_loaded) { - retval = PyHandlePluginEvent(ctx, event, value); + if (plugin_priv_ctx->python_loaded) { + retval = PyHandlePluginEvent(bareos_plugin_ctx, event, value); } else { retval = bRC_OK; } break; } - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); } bail_out: @@ -506,22 +541,23 @@ static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) * The plugin can create "Virtual" files by giving them a * name that is not normally found on the file system. */ -static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) +static bRC startBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; - if (!p_ctx) { goto bail_out; } + if (!plugin_priv_ctx) { goto bail_out; } - PyEval_AcquireThread(p_ctx->interpreter); - retval = PyStartBackupFile(ctx, sp); - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyStartBackupFile(bareos_plugin_ctx, sp); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); /* * For Incremental and Differential backups use checkChanges method to * see if we need to backup this file. */ - switch (p_ctx->backup_level) { + switch (plugin_priv_ctx->backup_level) { case L_INCREMENTAL: case L_DIFFERENTIAL: /* @@ -529,9 +565,11 @@ static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) * from the bEventSince event we use that as basis for the actual * save_time to check. */ - if (sp->save_time == 0 && p_ctx->since) { sp->save_time = p_ctx->since; } + if (sp->save_time == 0 && plugin_priv_ctx->since) { + sp->save_time = plugin_priv_ctx->since; + } - switch (bfuncs->checkChanges(ctx, sp)) { + switch (bfuncs->checkChanges(bareos_plugin_ctx, sp)) { case bRC_Seen: switch (sp->type) { case FT_DIRBEGIN: @@ -554,16 +592,17 @@ static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) /** * Done backing up a file. */ -static bRC endBackupFile(bpContext* ctx) +static bRC endBackupFile(bpContext* bareos_plugin_ctx) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; - if (!p_ctx) { goto bail_out; } + if (!plugin_priv_ctx) { goto bail_out; } - PyEval_AcquireThread(p_ctx->interpreter); - retval = PyEndBackupFile(ctx); - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyEndBackupFile(bareos_plugin_ctx); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: return retval; @@ -574,18 +613,19 @@ static bRC endBackupFile(bpContext* ctx) * or after startRestoreFile to do the actual file * input or output. */ -static bRC pluginIO(bpContext* ctx, struct io_pkt* io) +static bRC pluginIO(bpContext* bareos_plugin_ctx, struct io_pkt* io) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; - if (!p_ctx) { goto bail_out; } + if (!plugin_priv_ctx) { goto bail_out; } - if (!p_ctx->python_loaded) { goto bail_out; } + if (!plugin_priv_ctx->python_loaded) { goto bail_out; } - PyEval_AcquireThread(p_ctx->interpreter); - retval = PyPluginIO(ctx, io); - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyPluginIO(bareos_plugin_ctx, io); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: return retval; @@ -594,16 +634,17 @@ static bRC pluginIO(bpContext* ctx, struct io_pkt* io) /** * Start restore of a file. */ -static bRC startRestoreFile(bpContext* ctx, const char* cmd) +static bRC startRestoreFile(bpContext* bareos_plugin_ctx, const char* cmd) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; - if (!p_ctx) { goto bail_out; } + if (!plugin_priv_ctx) { goto bail_out; } - PyEval_AcquireThread(p_ctx->interpreter); - retval = PyStartRestoreFile(ctx, cmd); - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyStartRestoreFile(bareos_plugin_ctx, cmd); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: return retval; @@ -612,16 +653,17 @@ static bRC startRestoreFile(bpContext* ctx, const char* cmd) /** * Done restoring a file. */ -static bRC endRestoreFile(bpContext* ctx) +static bRC endRestoreFile(bpContext* bareos_plugin_ctx) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; - if (!p_ctx) { goto bail_out; } + if (!plugin_priv_ctx) { goto bail_out; } - PyEval_AcquireThread(p_ctx->interpreter); - retval = PyEndRestoreFile(ctx); - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyEndRestoreFile(bareos_plugin_ctx); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: return retval; @@ -634,16 +676,17 @@ static bRC endRestoreFile(bpContext* ctx) * This data is what is needed to create the file, but does * not contain actual file data. */ -static bRC createFile(bpContext* ctx, struct restore_pkt* rp) +static bRC createFile(bpContext* bareos_plugin_ctx, struct restore_pkt* rp) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; - if (!p_ctx) { goto bail_out; } + if (!plugin_priv_ctx) { goto bail_out; } - PyEval_AcquireThread(p_ctx->interpreter); - retval = PyCreateFile(ctx, rp); - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyCreateFile(bareos_plugin_ctx, rp); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: return retval; @@ -653,16 +696,18 @@ static bRC createFile(bpContext* ctx, struct restore_pkt* rp) * Called after the file has been restored. This can be used to * set directory permissions, ... */ -static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp) +static bRC setFileAttributes(bpContext* bareos_plugin_ctx, + struct restore_pkt* rp) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; - if (!p_ctx) { goto bail_out; } + if (!plugin_priv_ctx) { goto bail_out; } - PyEval_AcquireThread(p_ctx->interpreter); - retval = PySetFileAttributes(ctx, rp); - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PySetFileAttributes(bareos_plugin_ctx, rp); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: return retval; @@ -671,18 +716,19 @@ static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp) /** * When using Incremental dump, all previous dumps are necessary */ -static bRC checkFile(bpContext* ctx, char* fname) +static bRC checkFile(bpContext* bareos_plugin_ctx, char* fname) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; - if (!p_ctx) { goto bail_out; } + if (!plugin_priv_ctx) { goto bail_out; } - if (!p_ctx->python_loaded) { return bRC_OK; } + if (!plugin_priv_ctx->python_loaded) { return bRC_OK; } - PyEval_AcquireThread(p_ctx->interpreter); - retval = PyCheckFile(ctx, fname); - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyCheckFile(bareos_plugin_ctx, fname); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: return retval; @@ -690,16 +736,17 @@ static bRC checkFile(bpContext* ctx, char* fname) /** */ -static bRC getAcl(bpContext* ctx, acl_pkt* ap) +static bRC getAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; - if (!p_ctx) { goto bail_out; } + if (!plugin_priv_ctx) { goto bail_out; } - PyEval_AcquireThread(p_ctx->interpreter); - retval = PyGetAcl(ctx, ap); - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyGetAcl(bareos_plugin_ctx, ap); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: return retval; @@ -707,16 +754,17 @@ static bRC getAcl(bpContext* ctx, acl_pkt* ap) /** */ -static bRC setAcl(bpContext* ctx, acl_pkt* ap) +static bRC setAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; - if (!p_ctx) { goto bail_out; } + if (!plugin_priv_ctx) { goto bail_out; } - PyEval_AcquireThread(p_ctx->interpreter); - retval = PySetAcl(ctx, ap); - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PySetAcl(bareos_plugin_ctx, ap); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: return retval; @@ -724,16 +772,17 @@ static bRC setAcl(bpContext* ctx, acl_pkt* ap) /** */ -static bRC getXattr(bpContext* ctx, xattr_pkt* xp) +static bRC getXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; - if (!p_ctx) { goto bail_out; } + if (!plugin_priv_ctx) { goto bail_out; } - PyEval_AcquireThread(p_ctx->interpreter); - retval = PyGetXattr(ctx, xp); - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyGetXattr(bareos_plugin_ctx, xp); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: return retval; @@ -741,16 +790,17 @@ static bRC getXattr(bpContext* ctx, xattr_pkt* xp) /** */ -static bRC setXattr(bpContext* ctx, xattr_pkt* xp) +static bRC setXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; - if (!p_ctx) { goto bail_out; } + if (!plugin_priv_ctx) { goto bail_out; } - PyEval_AcquireThread(p_ctx->interpreter); - retval = PySetXattr(ctx, xp); - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PySetXattr(bareos_plugin_ctx, xp); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: return retval; @@ -820,7 +870,7 @@ static inline void SetString(char** destination, char* value) * * python:module_path=:module_name=:... */ -static bRC parse_plugin_definition(bpContext* ctx, +static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, void* value, PoolMem& plugin_options) { @@ -829,7 +879,8 @@ static bRC parse_plugin_definition(bpContext* ctx, bool keep_existing; PoolMem plugin_definition(PM_FNAME); char *bp, *argument, *argument_value; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_private_context* plugin_priv_ctx = + (plugin_private_context*)bareos_plugin_ctx->pContext; if (!value) { return bRC_Error; } @@ -839,19 +890,19 @@ static bRC parse_plugin_definition(bpContext* ctx, * Python Plugins enabled. */ if (bstrcmp((char*)value, "*all*")) { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: Got plugin definition %s, skipping to ignore\n", (char*)value); return bRC_Skip; } - keep_existing = (p_ctx->plugin_options) ? true : false; + keep_existing = (plugin_priv_ctx->plugin_options) ? true : false; /* * Parse the plugin definition. * Make a private copy of the whole string. */ - if (!p_ctx->python_loaded && p_ctx->plugin_options) { + if (!plugin_priv_ctx->python_loaded && plugin_priv_ctx->plugin_options) { int len; /* @@ -861,22 +912,22 @@ static bRC parse_plugin_definition(bpContext* ctx, * with the first argument being the pluginname removed as that is already * part of the other plugin option string. */ - len = strlen(p_ctx->plugin_options); - PmStrcpy(plugin_definition, p_ctx->plugin_options); + len = strlen(plugin_priv_ctx->plugin_options); + PmStrcpy(plugin_definition, plugin_priv_ctx->plugin_options); bp = strchr((char*)value, ':'); if (!bp) { - Jmsg(ctx, M_FATAL, "python-fd: Illegal plugin definition %s\n", - (char*)value); - Dmsg(ctx, debuglevel, "python-fd: Illegal plugin definition %s\n", - (char*)value); + Jmsg(bareos_plugin_ctx, M_FATAL, + "python-fd: Illegal plugin definition %s\n", (char*)value); + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Illegal plugin definition %s\n", (char*)value); goto bail_out; } /* * See if option string end with ':' */ - if (p_ctx->plugin_options[len - 1] != ':') { + if (plugin_priv_ctx->plugin_options[len - 1] != ':') { PmStrcat(plugin_definition, (char*)bp); } else { PmStrcat(plugin_definition, (char*)bp + 1); @@ -887,9 +938,11 @@ static bRC parse_plugin_definition(bpContext* ctx, bp = strchr(plugin_definition.c_str(), ':'); if (!bp) { - Jmsg(ctx, M_FATAL, "python-fd: Illegal plugin definition %s\n", + Jmsg(bareos_plugin_ctx, M_FATAL, + "python-fd: Illegal plugin definition %s\n", plugin_definition.c_str()); - Dmsg(ctx, debuglevel, "python-fd: Illegal plugin definition %s\n", + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Illegal plugin definition %s\n", plugin_definition.c_str()); goto bail_out; } @@ -913,10 +966,10 @@ static bRC parse_plugin_definition(bpContext* ctx, argument = bp; argument_value = strchr(bp, '='); if (!argument_value) { - Jmsg(ctx, M_FATAL, "python-fd: Illegal argument %s without value\n", - argument); - Dmsg(ctx, debuglevel, "python-fd: Illegal argument %s without value\n", - argument); + Jmsg(bareos_plugin_ctx, M_FATAL, + "python-fd: Illegal argument %s without value\n", argument); + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Illegal argument %s without value\n", argument); goto bail_out; } *argument_value++ = '\0'; @@ -945,10 +998,10 @@ static bRC parse_plugin_definition(bpContext* ctx, switch (plugin_arguments[i].type) { case argument_module_path: - str_destination = &p_ctx->module_path; + str_destination = &plugin_priv_ctx->module_path; break; case argument_module_name: - str_destination = &p_ctx->module_name; + str_destination = &plugin_priv_ctx->module_name; break; default: break; @@ -1017,13 +1070,13 @@ static bRC parse_plugin_definition(bpContext* ctx, /** * Python version before 2.7 and 3.0. */ -static PyObject* PyCreatebpContext(bpContext* ctx) +static PyObject* PyCreatebpContext(bpContext* bareos_plugin_ctx) { /* * Setup a new CObject which holds the bpContext structure used here * internally. */ - return PyCObject_FromVoidPtr((void*)ctx, NULL); + return PyCObject_FromVoidPtr((void*)bareos_plugin_ctx, NULL); } static bpContext* PyGetbpContext(PyObject* pyCtx) @@ -1034,13 +1087,13 @@ static bpContext* PyGetbpContext(PyObject* pyCtx) /** * Python version after 2.6 and 3.1. */ -static PyObject* PyCreatebpContext(bpContext* ctx) +static PyObject* PyCreatebpContext(bpContext* bareos_plugin_ctx) { /* * Setup a new Capsule which holds the bpContext structure used here * internally. */ - return PyCapsule_New((void*)ctx, "bareos.bpContext", NULL); + return PyCapsule_New((void*)bareos_plugin_ctx, "bareos.bpContext", NULL); } static bpContext* PyGetbpContext(PyObject* pyCtx) @@ -1074,7 +1127,7 @@ static inline PyObject* conv_retval_python(bRC retval) * return "".join(traceback.format_exception(sys.exc_type, * sys.exc_value, sys.exc_traceback)) */ -static void PyErrorHandler(bpContext* ctx, int msgtype) +static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype) { PyObject *type, *value, *traceback; PyObject* tracebackModule; @@ -1109,8 +1162,10 @@ static void PyErrorHandler(bpContext* ctx, int msgtype) Py_XDECREF(value); Py_XDECREF(traceback); - Dmsg(ctx, debuglevel, "python-fd: %s\n", error_string); - if (msgtype) { Jmsg(ctx, msgtype, "python-fd: %s\n", error_string); } + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: %s\n", error_string); + if (msgtype) { + Jmsg(bareos_plugin_ctx, msgtype, "python-fd: %s\n", error_string); + } free(error_string); } @@ -1122,62 +1177,66 @@ static void PyErrorHandler(bpContext* ctx, int msgtype) * module path and the module to load. We also load the dictionary used * for looking up the Python methods. */ -static bRC PyLoadModule(bpContext* ctx, void* value) +static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject *sysPath, *mPath, *pName, *pFunc; /* * See if we already setup the python search path. */ - if (!p_ctx->python_path_set) { + if (!plugin_priv_ctx->python_path_set) { /* * Extend the Python search path with the given module_path. */ - if (p_ctx->module_path) { + if (plugin_priv_ctx->module_path) { sysPath = PySys_GetObject((char*)"path"); - mPath = PyString_FromString(p_ctx->module_path); + mPath = PyString_FromString(plugin_priv_ctx->module_path); PyList_Append(sysPath, mPath); Py_DECREF(mPath); - p_ctx->python_path_set = true; + plugin_priv_ctx->python_path_set = true; } } /* * Try to load the Python module by name. */ - if (p_ctx->module_name) { - Dmsg(ctx, debuglevel, "python-fd: Trying to load module with name %s\n", - p_ctx->module_name); - pName = PyString_FromString(p_ctx->module_name); - p_ctx->pModule = PyImport_Import(pName); + if (plugin_priv_ctx->module_name) { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Trying to load module with name %s\n", + plugin_priv_ctx->module_name); + pName = PyString_FromString(plugin_priv_ctx->module_name); + plugin_priv_ctx->pModule = PyImport_Import(pName); Py_DECREF(pName); - if (!p_ctx->pModule) { - Dmsg(ctx, debuglevel, "python-fd: Failed to load module with name %s\n", - p_ctx->module_name); + if (!plugin_priv_ctx->pModule) { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Failed to load module with name %s\n", + plugin_priv_ctx->module_name); goto bail_out; } - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: Successfully loaded module with name %s\n", - p_ctx->module_name); + plugin_priv_ctx->module_name); /* * Get the Python dictionary for lookups in the Python namespace. */ - p_ctx->pDict = PyModule_GetDict(p_ctx->pModule); /* Borrowed reference */ + plugin_priv_ctx->pyModuleFunctionsDict = + PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ /* * Encode the bpContext so a Python method can pass it in on calling back. */ - p_ctx->bpContext = PyCreatebpContext(ctx); + plugin_priv_ctx->py_bpContext = PyCreatebpContext(bareos_plugin_ctx); /* * Lookup the load_bareos_plugin() function in the python module. */ - pFunc = PyDict_GetItemString(p_ctx->pDict, + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, "load_bareos_plugin"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyObject *pPluginDefinition, *pRetVal; @@ -1185,8 +1244,8 @@ static bRC PyLoadModule(bpContext* ctx, void* value) pPluginDefinition = PyString_FromString((char*)value); if (!pPluginDefinition) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, - pPluginDefinition, NULL); + pRetVal = PyObject_CallFunctionObjArgs( + pFunc, plugin_priv_ctx->py_bpContext, pPluginDefinition, NULL); Py_DECREF(pPluginDefinition); if (!pRetVal) { @@ -1196,7 +1255,7 @@ static bRC PyLoadModule(bpContext* ctx, void* value) Py_DECREF(pRetVal); } } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: Failed to find function named load_bareos_plugins()\n"); goto bail_out; } @@ -1204,13 +1263,13 @@ static bRC PyLoadModule(bpContext* ctx, void* value) /* * Keep track we successfully loaded. */ - p_ctx->python_loaded = true; + plugin_priv_ctx->python_loaded = true; } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } @@ -1223,24 +1282,26 @@ static bRC PyLoadModule(bpContext* ctx, void* value) * restore overrides can be passed in before the actual plugin options are * restored as part of the restore stream handling. */ -static bRC PyParsePluginDefinition(bpContext* ctx, void* value) +static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; /* * Lookup the parse_plugin_definition() function in the python module. */ - pFunc = PyDict_GetItemString( - p_ctx->pDict, "parse_plugin_definition"); /* Borrowed reference */ + pFunc = + PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "parse_plugin_definition"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyObject *pPluginDefinition, *pRetVal; pPluginDefinition = PyString_FromString((char*)value); if (!pPluginDefinition) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, + pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, pPluginDefinition, NULL); Py_DECREF(pPluginDefinition); @@ -1254,45 +1315,52 @@ static bRC PyParsePluginDefinition(bpContext* ctx, void* value) return retval; } else { Dmsg( - ctx, debuglevel, + bareos_plugin_ctx, debuglevel, "python-fd: Failed to find function named parse_plugin_definition()\n"); return bRC_Error; } bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } -static bRC PyGetPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, + pVariable var, + void* value) { return bRC_OK; } -static bRC PySetPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, + pVariable var, + void* value) { return bRC_OK; } -static bRC PyHandlePluginEvent(bpContext* ctx, bEvent* event, void* value) +static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, + bEvent* event, + void* value) { bRC retval = bRC_Error; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_private_context* plugin_priv_ctx = + (plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; /* * Lookup the handle_plugin_event() function in the python module. */ - pFunc = PyDict_GetItemString(p_ctx->pDict, + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, "handle_plugin_event"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyObject *pEventType, *pRetVal; pEventType = PyInt_FromLong(event->eventType); - pRetVal = - PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, pEventType, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, + pEventType, NULL); Py_DECREF(pEventType); if (!pRetVal) { @@ -1302,14 +1370,14 @@ static bRC PyHandlePluginEvent(bpContext* ctx, bEvent* event, void* value) Py_DECREF(pRetVal); } } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: Failed to find function named handle_plugin_event()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } @@ -1399,10 +1467,11 @@ static inline PySavePacket* NativeToPySavePacket(struct save_pkt* sp) return pSavePkt; } -static inline bool PySavePacketToNative(PySavePacket* pSavePkt, - struct save_pkt* sp, - struct plugin_ctx* p_ctx, - bool is_options_plugin) +static inline bool PySavePacketToNative( + PySavePacket* pSavePkt, + struct save_pkt* sp, + struct plugin_private_context* plugin_priv_ctx, + bool is_options_plugin) { /* * See if this is for an Options Plugin. @@ -1417,9 +1486,9 @@ static inline bool PySavePacketToNative(PySavePacket* pSavePkt, * our plugin context. */ if (PyString_Check(pSavePkt->fname)) { - if (p_ctx->fname) { free(p_ctx->fname); } - p_ctx->fname = strdup(PyString_AsString(pSavePkt->fname)); - sp->fname = p_ctx->fname; + if (plugin_priv_ctx->fname) { free(plugin_priv_ctx->fname); } + plugin_priv_ctx->fname = strdup(PyString_AsString(pSavePkt->fname)); + sp->fname = plugin_priv_ctx->fname; } } else { goto bail_out; @@ -1434,9 +1503,9 @@ static inline bool PySavePacketToNative(PySavePacket* pSavePkt, * our plugin context. */ if (PyString_Check(pSavePkt->link)) { - if (p_ctx->link) { free(p_ctx->link); } - p_ctx->link = strdup(PyString_AsString(pSavePkt->link)); - sp->link = p_ctx->link; + if (plugin_priv_ctx->link) { free(plugin_priv_ctx->link); } + plugin_priv_ctx->link = strdup(PyString_AsString(pSavePkt->link)); + sp->link = plugin_priv_ctx->link; } } @@ -1484,18 +1553,21 @@ static inline bool PySavePacketToNative(PySavePacket* pSavePkt, PyByteArray_Check(pSavePkt->object)) { char* buf; - if (p_ctx->object_name) { free(p_ctx->object_name); } - p_ctx->object_name = strdup(PyString_AsString(pSavePkt->object_name)); - sp->object_name = p_ctx->object_name; + if (plugin_priv_ctx->object_name) { + free(plugin_priv_ctx->object_name); + } + plugin_priv_ctx->object_name = + strdup(PyString_AsString(pSavePkt->object_name)); + sp->object_name = plugin_priv_ctx->object_name; sp->object_len = pSavePkt->object_len; sp->index = pSavePkt->object_index; if ((buf = PyByteArray_AsString(pSavePkt->object))) { - if (p_ctx->object) { free(p_ctx->object); } - p_ctx->object = (char*)malloc(pSavePkt->object_len); - memcpy(p_ctx->object, buf, pSavePkt->object_len); - sp->object = p_ctx->object; + if (plugin_priv_ctx->object) { free(plugin_priv_ctx->object); } + plugin_priv_ctx->object = (char*)malloc(pSavePkt->object_len); + memcpy(plugin_priv_ctx->object, buf, pSavePkt->object_len); + sp->object = plugin_priv_ctx->object; } else { goto bail_out; } @@ -1543,16 +1615,17 @@ static inline bool PySavePacketToNative(PySavePacket* pSavePkt, * The plugin can create "Virtual" files by giving them a * name that is not normally found on the file system. */ -static bRC PyStartBackupFile(bpContext* ctx, struct save_pkt* sp) +static bRC PyStartBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; /* * Lookup the start_backup_file() function in the python module. */ - pFunc = PyDict_GetItemString(p_ctx->pDict, + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, "start_backup_file"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PySavePacket* pSavePkt; @@ -1561,7 +1634,7 @@ static bRC PyStartBackupFile(bpContext* ctx, struct save_pkt* sp) pSavePkt = NativeToPySavePacket(sp); if (!pSavePkt) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, + pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, (PyObject*)pSavePkt, NULL); if (!pRetVal) { Py_DECREF((PyObject*)pSavePkt); @@ -1570,21 +1643,21 @@ static bRC PyStartBackupFile(bpContext* ctx, struct save_pkt* sp) retval = conv_python_retval(pRetVal); Py_DECREF(pRetVal); - if (!PySavePacketToNative(pSavePkt, sp, p_ctx, false)) { + if (!PySavePacketToNative(pSavePkt, sp, plugin_priv_ctx, false)) { Py_DECREF((PyObject*)pSavePkt); goto bail_out; } Py_DECREF((PyObject*)pSavePkt); } } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: Failed to find function named start_backup_file()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } @@ -1595,35 +1668,37 @@ static bRC PyStartBackupFile(bpContext* ctx, struct save_pkt* sp) * If the plugin wishes to create another file and back it up, * then it must return bRC_More (not yet implemented). */ -static bRC PyEndBackupFile(bpContext* ctx) +static bRC PyEndBackupFile(bpContext* bareos_plugin_ctx) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; /* * Lookup the end_backup_file() function in the python module. */ - pFunc = PyDict_GetItemString(p_ctx->pDict, + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, "end_backup_file"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyObject* pRetVal; - pRetVal = PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, + NULL); if (!pRetVal) { goto bail_out; } else { retval = conv_python_retval(pRetVal); } } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: Failed to find function named end_backup_file()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } @@ -1703,17 +1778,18 @@ static inline bool PyIoPacketToNative(PyIoPacket* pIoPkt, struct io_pkt* io) * or after startRestoreFile to do the actual file * input or output. */ -static bRC PyPluginIO(bpContext* ctx, struct io_pkt* io) +static bRC PyPluginIO(bpContext* bareos_plugin_ctx, struct io_pkt* io) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; /* * Lookup the plugin_io() function in the python module. */ - pFunc = - PyDict_GetItemString(p_ctx->pDict, "plugin_io"); /* Borrowed reference */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "plugin_io"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyIoPacket* pIoPkt; PyObject* pRetVal; @@ -1721,7 +1797,7 @@ static bRC PyPluginIO(bpContext* ctx, struct io_pkt* io) pIoPkt = NativeToPyIoPacket(io); if (!pIoPkt) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, + pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, (PyObject*)pIoPkt, NULL); if (!pRetVal) { Py_DECREF((PyObject*)pIoPkt); @@ -1737,14 +1813,14 @@ static bRC PyPluginIO(bpContext* ctx, struct io_pkt* io) } Py_DECREF((PyObject*)pIoPkt); } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: Failed to find function named plugin_io()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } io->status = -1; @@ -1755,16 +1831,17 @@ static bRC PyPluginIO(bpContext* ctx, struct io_pkt* io) * Called when the first record is read from the Volume that was previously * written by the command plugin. */ -static bRC PyStartRestoreFile(bpContext* ctx, const char* cmd) +static bRC PyStartRestoreFile(bpContext* bareos_plugin_ctx, const char* cmd) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; /* * Lookup the start_restore_file() function in the python module. */ - pFunc = PyDict_GetItemString(p_ctx->pDict, + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, "start_restore_file"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyObject *pCmd, *pRetVal; @@ -1772,7 +1849,8 @@ static bRC PyStartRestoreFile(bpContext* ctx, const char* cmd) pCmd = PyString_FromString(cmd); if (!pCmd) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, pCmd, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, + pCmd, NULL); Py_DECREF(pCmd); if (!pRetVal) { @@ -1782,14 +1860,14 @@ static bRC PyStartRestoreFile(bpContext* ctx, const char* cmd) Py_DECREF(pRetVal); } } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: Failed to find function named start_restore_file()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } @@ -1797,35 +1875,37 @@ static bRC PyStartRestoreFile(bpContext* ctx, const char* cmd) /** * Called when a command plugin is done restoring a file. */ -static bRC PyEndRestoreFile(bpContext* ctx) +static bRC PyEndRestoreFile(bpContext* bareos_plugin_ctx) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; /* * Lookup the end_restore_file() function in the python module. */ - pFunc = PyDict_GetItemString(p_ctx->pDict, + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, "end_restore_file"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyObject* pRetVal; - pRetVal = PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, + NULL); if (!pRetVal) { goto bail_out; } else { retval = conv_python_retval(pRetVal); } } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: Failed to find function named end_restore_file()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } @@ -1877,10 +1957,11 @@ static inline void PyRestorePacketToNative(PyRestorePacket* pRestorePacket, * CF_EXTRACT -- extract the file (i.e.call i/o routines) * CF_CREATED -- created, but no content to extract (typically directories) */ -static bRC PyCreateFile(bpContext* ctx, struct restore_pkt* rp) +static bRC PyCreateFile(bpContext* bareos_plugin_ctx, struct restore_pkt* rp) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; if (!rp) { return bRC_Error; } @@ -1888,7 +1969,7 @@ static bRC PyCreateFile(bpContext* ctx, struct restore_pkt* rp) /* * Lookup the create_file() function in the python module. */ - pFunc = PyDict_GetItemString(p_ctx->pDict, + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, "create_file"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyRestorePacket* pRestorePacket; @@ -1897,7 +1978,7 @@ static bRC PyCreateFile(bpContext* ctx, struct restore_pkt* rp) pRestorePacket = NativeToPyRestorePacket(rp); if (!pRestorePacket) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, + pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, pRestorePacket, NULL); if (!pRetVal) { Py_DECREF(pRestorePacket); @@ -1910,22 +1991,24 @@ static bRC PyCreateFile(bpContext* ctx, struct restore_pkt* rp) Py_DECREF(pRestorePacket); } } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: Failed to find function named create_file()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } -static bRC PySetFileAttributes(bpContext* ctx, struct restore_pkt* rp) +static bRC PySetFileAttributes(bpContext* bareos_plugin_ctx, + struct restore_pkt* rp) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; if (!rp) { return bRC_Error; } @@ -1933,7 +2016,7 @@ static bRC PySetFileAttributes(bpContext* ctx, struct restore_pkt* rp) /* * Lookup the set_file_attributes() function in the python module. */ - pFunc = PyDict_GetItemString(p_ctx->pDict, + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, "set_file_attributes"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyRestorePacket* pRestorePacket; @@ -1942,7 +2025,7 @@ static bRC PySetFileAttributes(bpContext* ctx, struct restore_pkt* rp) pRestorePacket = NativeToPyRestorePacket(rp); if (!pRestorePacket) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, + pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, pRestorePacket, NULL); if (!pRetVal) { Py_DECREF(pRestorePacket); @@ -1953,22 +2036,23 @@ static bRC PySetFileAttributes(bpContext* ctx, struct restore_pkt* rp) Py_DECREF(pRestorePacket); } } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: Failed to find function named set_file_attributes()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } -static bRC PyCheckFile(bpContext* ctx, char* fname) +static bRC PyCheckFile(bpContext* bareos_plugin_ctx, char* fname) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; if (!fname) { return bRC_Error; } @@ -1976,14 +2060,14 @@ static bRC PyCheckFile(bpContext* ctx, char* fname) /* * Lookup the check_file() function in the python module. */ - pFunc = - PyDict_GetItemString(p_ctx->pDict, "check_file"); /* Borrowed reference */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "check_file"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyObject *pFname, *pRetVal; pFname = PyString_FromString(fname); - pRetVal = - PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, pFname, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, + pFname, NULL); Py_DECREF(pFname); if (!pRetVal) { @@ -1993,14 +2077,14 @@ static bRC PyCheckFile(bpContext* ctx, char* fname) Py_DECREF(pRetVal); } } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: Failed to find function named check_file()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } @@ -2045,10 +2129,11 @@ static inline bool PyAclPacketToNative(PyAclPacket* pAclPacket, return true; } -static bRC PyGetAcl(bpContext* ctx, acl_pkt* ap) +static bRC PyGetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; if (!ap) { return bRC_Error; } @@ -2056,8 +2141,8 @@ static bRC PyGetAcl(bpContext* ctx, acl_pkt* ap) /* * Lookup the get_acl() function in the python module. */ - pFunc = - PyDict_GetItemString(p_ctx->pDict, "get_acl"); /* Borrowed reference */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "get_acl"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyAclPacket* pAclPkt; PyObject* pRetVal; @@ -2065,8 +2150,8 @@ static bRC PyGetAcl(bpContext* ctx, acl_pkt* ap) pAclPkt = NativeToPyAclPacket(ap); if (!pAclPkt) { goto bail_out; } - pRetVal = - PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, pAclPkt, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, + pAclPkt, NULL); if (!pRetVal) { Py_DECREF((PyObject*)pAclPkt); goto bail_out; @@ -2081,22 +2166,23 @@ static bRC PyGetAcl(bpContext* ctx, acl_pkt* ap) Py_DECREF(pAclPkt); } } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: Failed to find function named get_acl()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } -static bRC PySetAcl(bpContext* ctx, acl_pkt* ap) +static bRC PySetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; if (!ap) { return bRC_Error; } @@ -2104,8 +2190,8 @@ static bRC PySetAcl(bpContext* ctx, acl_pkt* ap) /* * Lookup the set_acl() function in the python module. */ - pFunc = - PyDict_GetItemString(p_ctx->pDict, "set_acl"); /* Borrowed reference */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "set_acl"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyAclPacket* pAclPkt; PyObject* pRetVal; @@ -2113,8 +2199,8 @@ static bRC PySetAcl(bpContext* ctx, acl_pkt* ap) pAclPkt = NativeToPyAclPacket(ap); if (!pAclPkt) { goto bail_out; } - pRetVal = - PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, pAclPkt, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, + pAclPkt, NULL); Py_DECREF(pAclPkt); if (!pRetVal) { @@ -2124,14 +2210,14 @@ static bRC PySetAcl(bpContext* ctx, acl_pkt* ap) Py_DECREF(pRetVal); } } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: Failed to find function named set_acl()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } @@ -2199,10 +2285,11 @@ static inline bool PyXattrPacketToNative(PyXattrPacket* pXattrPacket, return true; } -static bRC PyGetXattr(bpContext* ctx, xattr_pkt* xp) +static bRC PyGetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; if (!xp) { return bRC_Error; } @@ -2210,8 +2297,8 @@ static bRC PyGetXattr(bpContext* ctx, xattr_pkt* xp) /* * Lookup the get_xattr() function in the python module. */ - pFunc = - PyDict_GetItemString(p_ctx->pDict, "get_xattr"); /* Borrowed reference */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "get_xattr"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyXattrPacket* pXattrPkt; PyObject* pRetVal; @@ -2219,8 +2306,8 @@ static bRC PyGetXattr(bpContext* ctx, xattr_pkt* xp) pXattrPkt = NativeToPyXattrPacket(xp); if (!pXattrPkt) { goto bail_out; } - pRetVal = - PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, pXattrPkt, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, + pXattrPkt, NULL); if (!pRetVal) { Py_DECREF((PyObject*)pXattrPkt); goto bail_out; @@ -2235,22 +2322,23 @@ static bRC PyGetXattr(bpContext* ctx, xattr_pkt* xp) Py_DECREF(pXattrPkt); } } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: Failed to find function named get_xattr()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } -static bRC PySetXattr(bpContext* ctx, xattr_pkt* xp) +static bRC PySetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; if (!xp) { return bRC_Error; } @@ -2258,8 +2346,8 @@ static bRC PySetXattr(bpContext* ctx, xattr_pkt* xp) /* * Lookup the set_acl() function in the python module. */ - pFunc = - PyDict_GetItemString(p_ctx->pDict, "set_xattr"); /* Borrowed reference */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "set_xattr"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyXattrPacket* pXattrPkt; PyObject* pRetVal; @@ -2267,8 +2355,8 @@ static bRC PySetXattr(bpContext* ctx, xattr_pkt* xp) pXattrPkt = NativeToPyXattrPacket(xp); if (!pXattrPkt) { goto bail_out; } - pRetVal = - PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, pXattrPkt, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, + pXattrPkt, NULL); Py_DECREF(pXattrPkt); if (!pRetVal) { @@ -2278,13 +2366,13 @@ static bRC PySetXattr(bpContext* ctx, xattr_pkt* xp) Py_DECREF(pRetVal); } } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: Failed to find function named set_xattr()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } @@ -2312,10 +2400,12 @@ static inline PyRestoreObject* NativeToPyRestoreObject( return pRestoreObject; } -static bRC PyRestoreObjectData(bpContext* ctx, struct restore_object_pkt* rop) +static bRC PyRestoreObjectData(bpContext* bareos_plugin_ctx, + struct restore_object_pkt* rop) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; if (!rop) { return bRC_OK; } @@ -2323,7 +2413,7 @@ static bRC PyRestoreObjectData(bpContext* ctx, struct restore_object_pkt* rop) /* * Lookup the restore_object_data() function in the python module. */ - pFunc = PyDict_GetItemString(p_ctx->pDict, + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, "restore_object_data"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyRestoreObject* pRestoreObject; @@ -2332,7 +2422,7 @@ static bRC PyRestoreObjectData(bpContext* ctx, struct restore_object_pkt* rop) pRestoreObject = NativeToPyRestoreObject(rop); if (!pRestoreObject) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, + pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, pRestoreObject, NULL); Py_DECREF(pRestoreObject); @@ -2343,22 +2433,23 @@ static bRC PyRestoreObjectData(bpContext* ctx, struct restore_object_pkt* rop) Py_DECREF(pRetVal); } } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: Failed to find function named start_restore_file()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } -static bRC PyHandleBackupFile(bpContext* ctx, struct save_pkt* sp) +static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; if (!sp) { return bRC_Error; } @@ -2366,7 +2457,7 @@ static bRC PyHandleBackupFile(bpContext* ctx, struct save_pkt* sp) /* * Lookup the handle_backup_file() function in the python module. */ - pFunc = PyDict_GetItemString(p_ctx->pDict, + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, "handle_backup_file"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PySavePacket* pSavePkt; @@ -2375,8 +2466,8 @@ static bRC PyHandleBackupFile(bpContext* ctx, struct save_pkt* sp) pSavePkt = NativeToPySavePacket(sp); if (!pSavePkt) { goto bail_out; } - pRetVal = - PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, pSavePkt, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, + pSavePkt, NULL); if (!pRetVal) { Py_DECREF((PyObject*)pSavePkt); goto bail_out; @@ -2384,21 +2475,21 @@ static bRC PyHandleBackupFile(bpContext* ctx, struct save_pkt* sp) retval = conv_python_retval(pRetVal); Py_DECREF(pRetVal); - if (!PySavePacketToNative(pSavePkt, sp, p_ctx, true)) { + if (!PySavePacketToNative(pSavePkt, sp, plugin_priv_ctx, true)) { Py_DECREF((PyObject*)pSavePkt); goto bail_out; } Py_DECREF(pSavePkt); } } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: Failed to find function named handle_backup_file()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } @@ -2410,7 +2501,7 @@ static bRC PyHandleBackupFile(bpContext* ctx, struct save_pkt* sp) static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - bpContext* ctx = NULL; + bpContext* bareos_plugin_ctx = NULL; PyObject* pyCtx; PyObject* pRetVal = NULL; @@ -2426,7 +2517,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarDistName: { char* value = NULL; - if (bfuncs->getBareosValue(ctx, (bVariable)var, &value) == bRC_OK) { + if (bfuncs->getBareosValue(bareos_plugin_ctx, (bVariable)var, &value) == + bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } } break; @@ -2440,8 +2532,9 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarPrefixLinks: { int value = 0; - ctx = PyGetbpContext(pyCtx); - if (bfuncs->getBareosValue(ctx, (bVariable)var, &value) == bRC_OK) { + bareos_plugin_ctx = PyGetbpContext(pyCtx); + if (bfuncs->getBareosValue(bareos_plugin_ctx, (bVariable)var, &value) == + bRC_OK) { pRetVal = PyInt_FromLong(value); } break; @@ -2453,8 +2546,9 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarRegexWhere: { char* value = NULL; - ctx = PyGetbpContext(pyCtx); - if (bfuncs->getBareosValue(ctx, (bVariable)var, &value) == bRC_OK) { + bareos_plugin_ctx = PyGetbpContext(pyCtx); + if (bfuncs->getBareosValue(bareos_plugin_ctx, (bVariable)var, &value) == + bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } } break; @@ -2462,8 +2556,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarFileSeen: break; /* a write only variable, ignore read request */ default: - ctx = PyGetbpContext(pyCtx); - Dmsg(ctx, debuglevel, + bareos_plugin_ctx = PyGetbpContext(pyCtx); + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: PyBareosGetValue unknown variable requested %d\n", var); break; } @@ -2483,7 +2577,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - bpContext* ctx = NULL; + bpContext* bareos_plugin_ctx = NULL; bRC retval = bRC_Error; PyObject *pyCtx, *pyValue; @@ -2499,7 +2593,8 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) value = PyInt_AsLong(pyValue); if (value) { - retval = bfuncs->setBareosValue(ctx, (bVariable)var, &value); + retval = + bfuncs->setBareosValue(bareos_plugin_ctx, (bVariable)var, &value); } break; } @@ -2508,12 +2603,14 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) value = PyString_AsString(pyValue); if (value) { - retval = bfuncs->setBareosValue(ctx, (bVariable)var, value); + retval = + bfuncs->setBareosValue(bareos_plugin_ctx, (bVariable)var, value); } break; } default: - Dmsg(ctx, debuglevel, + bareos_plugin_ctx = PyGetbpContext(pyCtx); + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: PyBareosSetValue unknown variable requested %d\n", var); break; } @@ -2531,7 +2628,7 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - bpContext* ctx; + bpContext* bareos_plugin_ctx; PyObject* pyCtx; if (!PyArg_ParseTuple(args, "Oi|z:BareosDebugMessage", &pyCtx, &level, @@ -2540,8 +2637,8 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) } if (dbgmsg) { - ctx = PyGetbpContext(pyCtx); - Dmsg(ctx, level, "python-fd: %s", dbgmsg); + bareos_plugin_ctx = PyGetbpContext(pyCtx); + Dmsg(bareos_plugin_ctx, level, "python-fd: %s", dbgmsg); } Py_INCREF(Py_None); @@ -2557,7 +2654,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - bpContext* ctx; + bpContext* bareos_plugin_ctx; PyObject* pyCtx; if (!PyArg_ParseTuple(args, "Oi|z:BareosJobMessage", &pyCtx, &type, @@ -2566,8 +2663,8 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) } if (jobmsg) { - ctx = PyGetbpContext(pyCtx); - Jmsg(ctx, type, "python-fd: %s", jobmsg); + bareos_plugin_ctx = PyGetbpContext(pyCtx); + Jmsg(bareos_plugin_ctx, type, "python-fd: %s", jobmsg); } Py_INCREF(Py_None); @@ -2582,7 +2679,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* ctx; + bpContext* bareos_plugin_ctx; bRC retval = bRC_Error; PyObject *pyCtx, *pyEvents, *pySeq, *pyEvent; @@ -2595,15 +2692,15 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(pyCtx); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); if (event >= bEventJobStart && event <= FD_NR_EVENTS) { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: PyBareosRegisterEvents registering event %d\n", event); - retval = bfuncs->registerBareosEvents(ctx, 1, event); + retval = bfuncs->registerBareosEvents(bareos_plugin_ctx, 1, event); if (retval != bRC_OK) { break; } } @@ -2623,7 +2720,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* ctx; + bpContext* bareos_plugin_ctx; bRC retval = bRC_Error; PyObject *pyCtx, *pyEvents, *pySeq, *pyEvent; @@ -2636,15 +2733,15 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(pyCtx); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); if (event >= bEventJobStart && event <= FD_NR_EVENTS) { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "PyBareosUnRegisterEvents: unregistering event %d\n", event); - retval = bfuncs->unregisterBareosEvents(ctx, 1, event); + retval = bfuncs->unregisterBareosEvents(bareos_plugin_ctx, 1, event); } } @@ -2662,7 +2759,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - bpContext* ctx = NULL; + bpContext* bareos_plugin_ctx = NULL; PyObject* pyCtx; PyObject* pRetVal = NULL; @@ -2670,8 +2767,8 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) return NULL; } - ctx = PyGetbpContext(pyCtx); - if (bfuncs->getInstanceCount(ctx, &value) == bRC_OK) { + bareos_plugin_ctx = PyGetbpContext(pyCtx); + if (bfuncs->getInstanceCount(bareos_plugin_ctx, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } @@ -2690,7 +2787,7 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) { char* file = NULL; - bpContext* ctx; + bpContext* bareos_plugin_ctx; PyObject* pyCtx; bRC retval = bRC_Error; @@ -2699,8 +2796,8 @@ static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) } if (file) { - ctx = PyGetbpContext(pyCtx); - retval = bfuncs->AddExclude(ctx, file); + bareos_plugin_ctx = PyGetbpContext(pyCtx); + retval = bfuncs->AddExclude(bareos_plugin_ctx, file); } bail_out: @@ -2714,7 +2811,7 @@ static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) { char* file = NULL; - bpContext* ctx; + bpContext* bareos_plugin_ctx; PyObject* pyCtx; bRC retval = bRC_Error; @@ -2723,8 +2820,8 @@ static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) } if (file) { - ctx = PyGetbpContext(pyCtx); - retval = bfuncs->AddInclude(ctx, file); + bareos_plugin_ctx = PyGetbpContext(pyCtx); + retval = bfuncs->AddInclude(bareos_plugin_ctx, file); } bail_out: @@ -2738,7 +2835,7 @@ static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) { char* opts = NULL; - bpContext* ctx; + bpContext* bareos_plugin_ctx; PyObject* pyCtx; bRC retval = bRC_Error; @@ -2747,8 +2844,8 @@ static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) } if (opts) { - ctx = PyGetbpContext(pyCtx); - retval = bfuncs->AddOptions(ctx, opts); + bareos_plugin_ctx = PyGetbpContext(pyCtx); + retval = bfuncs->AddOptions(bareos_plugin_ctx, opts); } bail_out: @@ -2763,7 +2860,7 @@ static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) { int type; char* item = NULL; - bpContext* ctx; + bpContext* bareos_plugin_ctx; PyObject* pyCtx; bRC retval = bRC_Error; @@ -2772,8 +2869,8 @@ static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) } if (item) { - ctx = PyGetbpContext(pyCtx); - retval = bfuncs->AddRegex(ctx, item, type); + bareos_plugin_ctx = PyGetbpContext(pyCtx); + retval = bfuncs->AddRegex(bareos_plugin_ctx, item, type); } bail_out: @@ -2788,7 +2885,7 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) { int type; char* item = NULL; - bpContext* ctx; + bpContext* bareos_plugin_ctx; PyObject* pyCtx; bRC retval = bRC_Error; @@ -2797,8 +2894,8 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) } if (item) { - ctx = PyGetbpContext(pyCtx); - retval = bfuncs->AddWild(ctx, item, type); + bareos_plugin_ctx = PyGetbpContext(pyCtx); + retval = bfuncs->AddWild(bareos_plugin_ctx, item, type); } bail_out: @@ -2811,14 +2908,14 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) { - bpContext* ctx; + bpContext* bareos_plugin_ctx; PyObject* pyCtx; bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, "O:BareosNewOptions", &pyCtx)) { goto bail_out; } - ctx = PyGetbpContext(pyCtx); - retval = bfuncs->NewOptions(ctx); + bareos_plugin_ctx = PyGetbpContext(pyCtx); + retval = bfuncs->NewOptions(bareos_plugin_ctx); bail_out: return conv_retval_python(retval); @@ -2830,14 +2927,14 @@ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) { - bpContext* ctx; + bpContext* bareos_plugin_ctx; PyObject* pyCtx; bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, "O:BareosNewInclude", &pyCtx)) { goto bail_out; } - ctx = PyGetbpContext(pyCtx); - retval = bfuncs->NewInclude(ctx); + bareos_plugin_ctx = PyGetbpContext(pyCtx); + retval = bfuncs->NewInclude(bareos_plugin_ctx); bail_out: return conv_retval_python(retval); @@ -2849,7 +2946,7 @@ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) { - bpContext* ctx; + bpContext* bareos_plugin_ctx; PyObject* pyCtx; bRC retval = bRC_Error; @@ -2857,8 +2954,8 @@ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) goto bail_out; } - ctx = PyGetbpContext(pyCtx); - retval = bfuncs->NewPreInclude(ctx); + bareos_plugin_ctx = PyGetbpContext(pyCtx); + retval = bfuncs->NewPreInclude(bareos_plugin_ctx); bail_out: return conv_retval_python(retval); @@ -2871,7 +2968,7 @@ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) */ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) { - bpContext* ctx; + bpContext* bareos_plugin_ctx; PyObject* pyCtx; struct save_pkt sp; bRC retval = bRC_Error; @@ -2881,7 +2978,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) goto bail_out; } - ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(pyCtx); /* * CheckFile only has a need for a limited version of the PySavePacket so we @@ -2906,7 +3003,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) } sp.save_time = pSavePkt->save_time; - retval = bfuncs->checkChanges(ctx, &sp); + retval = bfuncs->checkChanges(bareos_plugin_ctx, &sp); /* * Copy back the two fields that are changed by checkChanges(). @@ -2925,7 +3022,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) */ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) { - bpContext* ctx; + bpContext* bareos_plugin_ctx; PyObject* pyCtx; struct save_pkt sp; bRC retval = bRC_Error; @@ -2935,7 +3032,7 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) goto bail_out; } - ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(pyCtx); /* * Acceptfile only needs fname and statp from PySavePacket so we handle @@ -2957,7 +3054,7 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) goto bail_out; } - retval = bfuncs->AcceptFile(ctx, &sp); + retval = bfuncs->AcceptFile(bareos_plugin_ctx, &sp); bail_out: return conv_retval_python(retval); @@ -2970,7 +3067,7 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) { bool all; - bpContext* ctx; + bpContext* bareos_plugin_ctx; char* fname = NULL; bRC retval = bRC_Error; PyObject *pyCtx, *pyBool; @@ -2980,9 +3077,9 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) goto bail_out; } - ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(pyCtx); all = PyObject_IsTrue(pyBool); - retval = bfuncs->SetSeenBitmap(ctx, all, fname); + retval = bfuncs->SetSeenBitmap(bareos_plugin_ctx, all, fname); bail_out: return conv_retval_python(retval); @@ -2995,7 +3092,7 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) { bool all; - bpContext* ctx; + bpContext* bareos_plugin_ctx; char* fname = NULL; bRC retval = bRC_Error; PyObject *pyCtx, *pyBool; @@ -3005,9 +3102,9 @@ static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) goto bail_out; } - ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(pyCtx); all = PyObject_IsTrue(pyBool); - retval = bfuncs->ClearSeenBitmap(ctx, all, fname); + retval = bfuncs->ClearSeenBitmap(bareos_plugin_ctx, all, fname); bail_out: return conv_retval_python(retval); From 96484ad9e942d948a87ed14f5e630c94eba4d25d Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 27 Feb 2020 18:38:15 +0100 Subject: [PATCH 006/341] python-fd: get Capsule from module --- core/src/plugins/filed/python-fd.cc | 2 ++ core/src/plugins/filed/python-fd.h | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/src/plugins/filed/python-fd.cc b/core/src/plugins/filed/python-fd.cc index 2753b29a9b1..a766111aba6 100644 --- a/core/src/plugins/filed/python-fd.cc +++ b/core/src/plugins/filed/python-fd.cc @@ -1233,6 +1233,8 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) */ plugin_priv_ctx->py_bpContext = PyCreatebpContext(bareos_plugin_ctx); + void* ctx_from_bareosfd_module = PyCapsule_Import("bareosfd.bpContext", 0); + /* * Lookup the load_bareos_plugin() function in the python module. */ diff --git a/core/src/plugins/filed/python-fd.h b/core/src/plugins/filed/python-fd.h index d18c75e7f64..bec96231d0c 100644 --- a/core/src/plugins/filed/python-fd.h +++ b/core/src/plugins/filed/python-fd.h @@ -761,12 +761,13 @@ static PyMethodDef BareosFDMethods[] = { MOD_INIT(bareosfd) { - /* ctx holds the bpContext instead of passing to Python and extracting it - * back like it was before. - * ctx needs to be set after loading the bareosfd binary python module and - * will be used for all calls. + /* bareos_plugin_context holds the bpContext instead of passing to Python and + * extracting it back like it was before. bareos_plugin_context needs to be + * set after loading the bareosfd binary python module and will be used for + * all calls. */ - static void* ctx = NULL; + static void* bareos_plugin_context = NULL; + PyObject* BareosFdModule = NULL; /* Pointer Capsules to avoid context transfer back and forth */ From 49b9d29d2f4afb6fa5a71a358ddd89c5e384d8d5 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 13 Aug 2020 10:52:21 +0200 Subject: [PATCH 007/341] python-fd: remove pyCtx Parameter in every python function call Also remove python 2.6 and 3.0 support --- .../plugins/dird/BareosDirPluginBaseclass.py | 55 ++-- core/src/plugins/dird/BareosDirWrapper.py | 8 +- .../plugins/dird/bareos-dir-class-plugin.py | 4 +- core/src/plugins/dird/bareos-dir.py.template | 29 +- .../plugins/filed/BareosFdPluginBaseclass.py | 162 +++++----- core/src/plugins/filed/BareosFdPluginLDAP.py | 84 +++--- .../filed/BareosFdPluginLocalFileset.py | 73 ++--- core/src/plugins/filed/BareosFdPluginOvirt.py | 256 ++++++---------- .../filed/BareosFdPluginPerconaXtraBackup.py | 79 ++--- core/src/plugins/filed/BareosFdWrapper.py | 66 ++--- core/src/plugins/filed/bareos-fd-ldap.py | 4 +- .../plugins/filed/bareos-fd-local-fileset.py | 6 +- core/src/plugins/filed/bareos-fd-mock-test.py | 8 +- core/src/plugins/filed/bareos-fd-ovirt.py | 4 +- .../filed/bareos-fd-percona-xtrabackup.py | 4 +- core/src/plugins/filed/bareos-fd.py.template | 77 +++-- core/src/plugins/filed/decontext.sh | 7 + core/src/plugins/filed/python-fd.cc | 280 +++++++----------- core/src/plugins/filed/python-fd.h | 4 +- .../plugins/stored/BareosSdPluginBaseclass.py | 28 +- core/src/plugins/stored/BareosSdWrapper.py | 8 +- .../plugins/stored/bareos-sd-class-plugin.py | 4 +- core/src/plugins/stored/bareos-sd.py.template | 25 +- ...sFdPluginLocalFilesetWithRestoreObjects.py | 60 ++-- ...os-fd-local-fileset-with-restoreobjects.py | 4 +- .../python-modules/bareos-dir-test.py | 8 +- ...sFdPluginLocalFilesetWithRestoreObjects.py | 60 ++-- ...os-fd-local-fileset-with-restoreobjects.py | 4 +- .../python-modules/bareos-sd-test.py | 8 +- 29 files changed, 577 insertions(+), 842 deletions(-) create mode 100755 core/src/plugins/filed/decontext.sh diff --git a/core/src/plugins/dird/BareosDirPluginBaseclass.py b/core/src/plugins/dird/BareosDirPluginBaseclass.py index 9c6805ec209..b46eb9b3980 100644 --- a/core/src/plugins/dird/BareosDirPluginBaseclass.py +++ b/core/src/plugins/dird/BareosDirPluginBaseclass.py @@ -33,9 +33,9 @@ class BareosDirPluginBaseclass(object): """ Bareos DIR python plugin base class """ - def __init__(self, context, plugindef): + def __init__(self, plugindef): bareosdir.DebugMessage( - context, 100, "Constructor called in module %s\n" % (__name__) + 100, "Constructor called in module %s\n" % (__name__) ) events = [] @@ -43,19 +43,18 @@ def __init__(self, context, plugindef): events.append(bDirEventType["bDirEventJobEnd"]) events.append(bDirEventType["bDirEventJobInit"]) events.append(bDirEventType["bDirEventJobRun"]) - bareosdir.RegisterEvents(context, events) + bareosdir.RegisterEvents(events) # get some static Bareos values - self.jobName = bareosdir.GetValue(context, brDirVariable["bDirVarJobName"]) - self.jobLevel = chr(bareosdir.GetValue(context, brDirVariable["bDirVarLevel"])) - self.jobType = bareosdir.GetValue(context, brDirVariable["bDirVarType"]) - self.jobId = int(bareosdir.GetValue(context, brDirVariable["bDirVarJobId"])) - self.jobClient = bareosdir.GetValue(context, brDirVariable["bDirVarClient"]) - self.jobStatus = bareosdir.GetValue(context, brDirVariable["bDirVarJobStatus"]) - self.Priority = bareosdir.GetValue(context, brDirVariable["bDirVarPriority"]) + self.jobName = bareosdir.GetValue(brDirVariable["bDirVarJobName"]) + self.jobLevel = chr(bareosdir.GetValue(brDirVariable["bDirVarLevel"])) + self.jobType = bareosdir.GetValue(brDirVariable["bDirVarType"]) + self.jobId = int(bareosdir.GetValue(brDirVariable["bDirVarJobId"])) + self.jobClient = bareosdir.GetValue(brDirVariable["bDirVarClient"]) + self.jobStatus = bareosdir.GetValue(brDirVariable["bDirVarJobStatus"]) + self.Priority = bareosdir.GetValue(brDirVariable["bDirVarPriority"]) bareosdir.DebugMessage( - context, 100, "JobName = %s - level = %s - type = %s - Id = %s - \ Client = %s - jobStatus = %s - Priority = %s - BareosDirPluginBaseclass\n" @@ -78,7 +77,7 @@ def __str__(self): self.Client, ) - def parse_plugin_definition(self, context, plugindef): + def parse_plugin_definition(self, plugindef): """ Called with the plugin options from the bareos configfiles You should overload this method with your own and do option checking @@ -87,21 +86,21 @@ def parse_plugin_definition(self, context, plugindef): make sanity check on self.options afterwards """ bareosdir.DebugMessage( - context, 100, "plugin def parser called with %s\n" % (plugindef) + 100, "plugin def parser called with %s\n" % (plugindef) ) # Parse plugin options into a dict self.options = dict() plugin_options = plugindef.split(":") for current_option in plugin_options: key, sep, val = current_option.partition("=") - bareosdir.DebugMessage(context, 100, "key:val = %s:%s" % (key, val)) + bareosdir.DebugMessage(100, "key:val = %s:%s" % (key, val)) if val == "": continue else: self.options[key] = val return bRCs["bRC_OK"] - def handle_plugin_event(self, context, event): + def handle_plugin_event(self, event): """ This method is called for each of the above registered events Overload this method to implement your actions for the events, @@ -111,10 +110,9 @@ def handle_plugin_event(self, context, event): if event == bDirEventType["bDirEventJobInit"]: self.jobInitTime = time.time() self.jobStatus = chr( - bareosdir.GetValue(context, brDirVariable["bDirVarJobStatus"]) + bareosdir.GetValue(brDirVariable["bDirVarJobStatus"]) ) bareosdir.DebugMessage( - context, 100, "bDirEventJobInit event triggered at Unix time %s\n" % (self.jobInitTime), @@ -123,10 +121,9 @@ def handle_plugin_event(self, context, event): elif event == bDirEventType["bDirEventJobStart"]: self.jobStartTime = time.time() self.jobStatus = chr( - bareosdir.GetValue(context, brDirVariable["bDirVarJobStatus"]) + bareosdir.GetValue(brDirVariable["bDirVarJobStatus"]) ) bareosdir.DebugMessage( - context, 100, "bDirEventJobStart event triggered at Unix time %s\n" % (self.jobStartTime), @@ -137,7 +134,6 @@ def handle_plugin_event(self, context, event): # e.g for other jobs to finish self.jobRunTime = time.time() bareosdir.DebugMessage( - context, 100, "bDirEventJobRun event triggered at Unix time %s\n" % (self.jobRunTime), ) @@ -145,34 +141,33 @@ def handle_plugin_event(self, context, event): elif event == bDirEventType["bDirEventJobEnd"]: self.jobEndTime = time.time() bareosdir.DebugMessage( - context, 100, "bDirEventJobEnd event triggered at Unix time %s\n" % (self.jobEndTime), ) self.jobLevel = chr( - bareosdir.GetValue(context, brDirVariable["bDirVarLevel"]) + bareosdir.GetValue(brDirVariable["bDirVarLevel"]) ) self.jobStatus = chr( - bareosdir.GetValue(context, brDirVariable["bDirVarJobStatus"]) + bareosdir.GetValue(brDirVariable["bDirVarJobStatus"]) ) self.jobErrors = int( - bareosdir.GetValue(context, brDirVariable["bDirVarJobErrors"]) + bareosdir.GetValue(brDirVariable["bDirVarJobErrors"]) ) self.jobBytes = int( - bareosdir.GetValue(context, brDirVariable["bDirVarJobBytes"]) + bareosdir.GetValue(brDirVariable["bDirVarJobBytes"]) ) self.jobFiles = int( - bareosdir.GetValue(context, brDirVariable["bDirVarJobFiles"]) + bareosdir.GetValue(brDirVariable["bDirVarJobFiles"]) ) self.jobNumVols = int( - bareosdir.GetValue(context, brDirVariable["bDirVarNumVols"]) + bareosdir.GetValue(brDirVariable["bDirVarNumVols"]) ) - self.jobPool = bareosdir.GetValue(context, brDirVariable["bDirVarPool"]) + self.jobPool = bareosdir.GetValue(brDirVariable["bDirVarPool"]) self.jobStorage = bareosdir.GetValue( - context, brDirVariable["bDirVarStorage"] + brDirVariable["bDirVarStorage"] ) self.jobMediaType = bareosdir.GetValue( - context, brDirVariable["bDirVarMediaType"] + brDirVariable["bDirVarMediaType"] ) self.jobTotalTime = self.jobEndTime - self.jobInitTime diff --git a/core/src/plugins/dird/BareosDirWrapper.py b/core/src/plugins/dird/BareosDirWrapper.py index 4620553b5cc..2bac1198154 100644 --- a/core/src/plugins/dird/BareosDirWrapper.py +++ b/core/src/plugins/dird/BareosDirWrapper.py @@ -30,12 +30,12 @@ bareos_dir_plugin_object = None -def parse_plugin_definition(context, plugindef): - return bareos_dir_plugin_object.parse_plugin_definition(context, plugindef) +def parse_plugin_definition(plugindef): + return bareos_dir_plugin_object.parse_plugin_definition(plugindef) -def handle_plugin_event(context, event): - return bareos_dir_plugin_object.handle_plugin_event(context, event) +def handle_plugin_event(event): + return bareos_dir_plugin_object.handle_plugin_event(event) # vim: ts=4 tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/core/src/plugins/dird/bareos-dir-class-plugin.py b/core/src/plugins/dird/bareos-dir-class-plugin.py index dd00078c589..e6f8cc3eed3 100644 --- a/core/src/plugins/dird/bareos-dir-class-plugin.py +++ b/core/src/plugins/dird/bareos-dir-class-plugin.py @@ -34,7 +34,7 @@ import BareosDirPluginBaseclass -def load_bareos_plugin(context, plugindef): +def load_bareos_plugin(plugindef): """ This function is called by the Bareos-Dir to load the plugin We use it to instantiate the plugin class @@ -42,7 +42,7 @@ def load_bareos_plugin(context, plugindef): # BareosDirWrapper.bareos_dir_plugin_object is the module attribute that # holds the plugin class object BareosDirWrapper.bareos_dir_plugin_object = BareosDirPluginBaseclass.BareosDirPluginBaseclass( - context, plugindef + plugindef ) return bareos_dir_consts.bRCs["bRC_OK"] diff --git a/core/src/plugins/dird/bareos-dir.py.template b/core/src/plugins/dird/bareos-dir.py.template index 6d84f8b7dd1..5572b9eba94 100644 --- a/core/src/plugins/dird/bareos-dir.py.template +++ b/core/src/plugins/dird/bareos-dir.py.template @@ -23,22 +23,22 @@ from bareosdir import * from bareos_dir_consts import * -def load_bareos_plugin(context, plugindef): +def load_bareos_plugin(plugindef): DebugMessage( - context, 100, "load_bareos_plugin called with param: " + plugindef + "\n" + 100, "load_bareos_plugin called with param: " + plugindef + "\n" ) events = [] events.append(bDirEventType["bDirEventJobStart"]) events.append(bDirEventType["bDirEventJobEnd"]) events.append(bDirEventType["bDirEventJobInit"]) events.append(bDirEventType["bDirEventJobRun"]) - RegisterEvents(context, events) + RegisterEvents(events) return bRCs["bRC_OK"] -def parse_plugin_definition(context, plugindef): +def parse_plugin_definition(plugindef): DebugMessage( - context, 100, "parse_plugin_definition called with param: " + plugindef + "\n" + 100, "parse_plugin_definition called with param: " + plugindef + "\n" ) plugin_options = plugindef.split(":") for current_option in plugin_options: @@ -57,7 +57,6 @@ def parse_plugin_definition(context, plugindef): else: DebugMessage( - context, 100, "parse_plugin_definition unknown option " + key @@ -70,21 +69,21 @@ def parse_plugin_definition(context, plugindef): return bRCs["bRC_OK"] -def handle_plugin_event(context, event): +def handle_plugin_event(event): if event == bDirEventType["bDirEventJobStart"]: - DebugMessage(context, 100, "bDirEventJobStart event triggered\n") - jobname = GetValue(context, brDirVariable["bDirVarJobName"]) - DebugMessage(context, 100, "Job " + jobname + " starting\n") + DebugMessage(100, "bDirEventJobStart event triggered\n") + jobname = GetValue(brDirVariable["bDirVarJobName"]) + DebugMessage(100, "Job " + jobname + " starting\n") elif event == bDirEventType["bDirEventJobEnd"]: - DebugMessage(context, 100, "bDirEventJobEnd event triggered\n") - jobname = GetValue(context, brDirVariable["bDirVarJobName"]) - DebugMessage(context, 100, "Job " + jobname + " stopped\n") + DebugMessage(100, "bDirEventJobEnd event triggered\n") + jobname = GetValue(brDirVariable["bDirVarJobName"]) + DebugMessage(100, "Job " + jobname + " stopped\n") elif event == bDirEventType["bDirEventJobInit"]: - DebugMessage(context, 100, "bDirEventJobInit event triggered\n") + DebugMessage(100, "bDirEventJobInit event triggered\n") elif event == bDirEventType["bDirEventJobRun"]: - DebugMessage(context, 100, "bDirEventJobRun event triggered\n") + DebugMessage(100, "bDirEventJobRun event triggered\n") return bRCs["bRC_OK"] diff --git a/core/src/plugins/filed/BareosFdPluginBaseclass.py b/core/src/plugins/filed/BareosFdPluginBaseclass.py index ad77e6c52aa..4ccca7cbcfe 100644 --- a/core/src/plugins/filed/BareosFdPluginBaseclass.py +++ b/core/src/plugins/filed/BareosFdPluginBaseclass.py @@ -36,9 +36,8 @@ class BareosFdPluginBaseclass(object): """ Bareos python plugin base class """ - def __init__(self, context, plugindef, mandatory_options=None): + def __init__(self, plugindef, mandatory_options=None): bareosfd.DebugMessage( - context, 100, "Constructor called in module %s with plugindef=%s\n" % (__name__, plugindef), @@ -50,14 +49,14 @@ def __init__(self, context, plugindef, mandatory_options=None): events.append(bEventType["bEventHandleBackupFile"]) events.append(bEventType["bEventStartBackupJob"]) events.append(bEventType["bEventStartRestoreJob"]) - bareosfd.RegisterEvents(context, events) + bareosfd.RegisterEvents(events) # get some static Bareos values - self.fdname = bareosfd.GetValue(context, bVariable["bVarFDName"]) - self.jobId = bareosfd.GetValue(context, bVariable["bVarJobId"]) - self.client = bareosfd.GetValue(context, bVariable["bVarClient"]) - self.since = bareosfd.GetValue(context, bVariable["bVarSinceTime"]) - self.level = bareosfd.GetValue(context, bVariable["bVarLevel"]) - self.jobName = bareosfd.GetValue(context, bVariable["bVarJobName"]) + self.fdname = bareosfd.GetValue(bVariable["bVarFDName"]) + self.jobId = bareosfd.GetValue(bVariable["bVarJobId"]) + self.client = bareosfd.GetValue(bVariable["bVarClient"]) + self.since = bareosfd.GetValue(bVariable["bVarSinceTime"]) + self.level = bareosfd.GetValue(bVariable["bVarLevel"]) + self.jobName = bareosfd.GetValue(bVariable["bVarJobName"]) # jobName is of format myName.2020-05-12_11.35.27_05 # short Name is everything left of the third point seen from the right self.shortName = self.jobName.rsplit(".", 3)[0] @@ -67,10 +66,10 @@ def __init__(self, context, plugindef, mandatory_options=None): self.filetype = "undef" self.file = None bareosfd.DebugMessage( - context, 100, "FDName = %s - BareosFdPluginBaseclass\n" % (self.fdname) + 100, "FDName = %s - BareosFdPluginBaseclass\n" % (self.fdname) ) bareosfd.DebugMessage( - context, 100, "WorkingDir: %s JobId: %s\n" % (self.workingdir, self.jobId) + 100, "WorkingDir: %s JobId: %s\n" % (self.workingdir, self.jobId) ) self.mandatory_options = mandatory_options @@ -89,9 +88,9 @@ def __str__(self): ) ) - def parse_plugin_definition(self, context, plugindef): + def parse_plugin_definition(self, plugindef): bareosfd.DebugMessage( - context, 100, 'plugin def parser called with "%s"\n' % (plugindef) + 100, 'plugin def parser called with "%s"\n' % (plugindef) ) # Parse plugin options into a dict if not hasattr(self, "options"): @@ -105,16 +104,16 @@ def parse_plugin_definition(self, context, plugindef): val = val[:-1] + ":" + plugin_options.pop(0) # Replace all '\\' val = val.replace("\\", "") - bareosfd.DebugMessage(context, 100, 'key:val = "%s:%s"\n' % (key, val)) + bareosfd.DebugMessage(100, 'key:val = "%s:%s"\n' % (key, val)) if val == "": continue else: if key not in self.options: self.options[key] = val # after we've parsed all arguments, we check the options for mandatory settings - return self.check_options(context, self.mandatory_options) + return self.check_options(self.mandatory_options) - def check_options(self, context, mandatory_options=None): + def check_options(self, mandatory_options=None): """ Check Plugin options Here we just verify that eventual mandatory options are set. @@ -125,29 +124,27 @@ def check_options(self, context, mandatory_options=None): for option in mandatory_options: if option not in self.options: bareosfd.DebugMessage( - context, 100, "Mandatory option '%s' not defined.\n" % option + 100, "Mandatory option '%s' not defined.\n" % option ) bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "Mandatory option '%s' not defined.\n" % (option), ) return bRCs["bRC_Error"] bareosfd.DebugMessage( - context, 100, "Using Option %s=%s\n" % (option, self.options[option]) + 100, "Using Option %s=%s\n" % (option, self.options[option]) ) return bRCs["bRC_OK"] - def plugin_io_open(self, context, IOP): + def plugin_io_open(self, IOP): self.FNAME = IOP.fname.decode("string_escape") bareosfd.DebugMessage( context, 250, "io_open: self.FNAME is set to %s\n" % (self.FNAME) ) if os.path.isdir(self.FNAME): - bareosfd.DebugMessage(context, 100, "%s is a directory\n" % (self.FNAME)) + bareosfd.DebugMessage(100, "%s is a directory\n" % (self.FNAME)) self.fileType = "FT_DIR" bareosfd.DebugMessage( - context, 100, "Did not open file %s of type %s\n" % (self.FNAME, self.fileType), ) @@ -155,7 +152,6 @@ def plugin_io_open(self, context, IOP): elif os.path.islink(self.FNAME): self.fileType = "FT_LNK" bareosfd.DebugMessage( - context, 100, "Did not open file %s of type %s\n" % (self.FNAME, self.fileType), ) @@ -171,7 +167,6 @@ def plugin_io_open(self, context, IOP): else: self.fileType = "FT_REG" bareosfd.DebugMessage( - context, 150, "file %s has type %s - trying to open it\n" % (self.FNAME, self.fileType), @@ -179,14 +174,12 @@ def plugin_io_open(self, context, IOP): try: if IOP.flags & (os.O_CREAT | os.O_WRONLY): bareosfd.DebugMessage( - context, 100, "Open file %s for writing with %s\n" % (self.FNAME, IOP), ) dirname = os.path.dirname(self.FNAME) if not os.path.exists(dirname): bareosfd.DebugMessage( - context, 100, "Directory %s does not exist, creating it now\n" % (dirname), ) @@ -194,7 +187,6 @@ def plugin_io_open(self, context, IOP): self.file = open(self.FNAME, "wb") else: bareosfd.DebugMessage( - context, 100, "Open file %s for reading with %s\n" % (self.FNAME, IOP), ) @@ -204,19 +196,19 @@ def plugin_io_open(self, context, IOP): return bRCs["bRC_Error"] return bRCs["bRC_OK"] - def plugin_io_close(self, context, IOP): - bareosfd.DebugMessage(context, 100, "Closing file " + "\n") + def plugin_io_close(self, IOP): + bareosfd.DebugMessage(100, "Closing file " + "\n") if self.fileType == "FT_REG": self.file.close() return bRCs["bRC_OK"] - def plugin_io_seek(self, context, IOP): + def plugin_io_seek(self, IOP): return bRCs["bRC_OK"] - def plugin_io_read(self, context, IOP): + def plugin_io_read(self, IOP): if self.fileType == "FT_REG": bareosfd.DebugMessage( - context, 200, "Reading %d from file %s\n" % (IOP.count, self.FNAME) + 200, "Reading %d from file %s\n" % (IOP.count, self.FNAME) ) IOP.buf = bytearray(IOP.count) try: @@ -224,7 +216,6 @@ def plugin_io_read(self, context, IOP): IOP.io_errno = 0 except Exception as e: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], 'Could net read %d bytes from file %s. "%s"' % (IOP.count, file_to_backup, e.message), @@ -233,7 +224,6 @@ def plugin_io_read(self, context, IOP): return bRCs["bRC_Error"] else: bareosfd.DebugMessage( - context, 100, "Did not read from file %s of type %s\n" % (self.FNAME, self.fileType), ) @@ -242,15 +232,14 @@ def plugin_io_read(self, context, IOP): IOP.io_errno = 0 return bRCs["bRC_OK"] - def plugin_io_write(self, context, IOP): + def plugin_io_write(self, IOP): bareosfd.DebugMessage( - context, 200, "Writing buffer to file %s\n" % (self.FNAME) + 200, "Writing buffer to file %s\n" % (self.FNAME) ) try: self.file.write(IOP.buf) except Exception as e: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], 'Could net write to file %s. "%s"' % (file_to_backup, e.message), ) @@ -261,144 +250,140 @@ def plugin_io_write(self, context, IOP): IOP.io_errno = 0 return bRCs["bRC_OK"] - def plugin_io(self, context, IOP): + def plugin_io(self, IOP): """ Basic IO operations. Some tweaks here: IOP.fname is only set on file-open We need to capture it on open and keep it for the remaining procedures Now (since 2020) separated into sub-methods to ease overloading in derived classes """ bareosfd.DebugMessage( - context, 250, "plugin_io called with function %s filename %s\n" % (IOP.func, IOP.fname), ) - bareosfd.DebugMessage(context, 250, "self.FNAME is set to %s\n" % (self.FNAME)) - if IOP.func == bIOPS["IO_OPEN"]: - return self.plugin_io_open(context, IOP) + bareosfd.DebugMessage(250, "self.FNAME is set to %s\n" % (self.FNAME)) + if IOP.func == bIOPS["O_OPEN"]: + return self.plugin_io_open(IOP) elif IOP.func == bIOPS["IO_CLOSE"]: - return self.plugin_io_close(context, IOP) + return self.plugin_io_close(IOP) elif IOP.func == bIOPS["IO_SEEK"]: - return self.plugin_io_seek(context, IOP) + return self.plugin_io_seek(IOP) elif IOP.func == bIOPS["IO_READ"]: - return self.plugin_io_read(context, IOP) + return self.plugin_io_read(IOP) elif IOP.func == bIOPS["IO_WRITE"]: - return self.plugin_io_write(context, IOP) + return self.plugin_io_write(IOP) - def handle_plugin_event(self, context, event): + def handle_plugin_event(self, event): if event == bEventType["bEventJobEnd"]: bareosfd.DebugMessage( - context, 100, "handle_plugin_event called with bEventJobEnd\n" + 100, "handle_plugin_event called with bEventJobEnd\n" ) - return self.end_job(context) + return self.end_job() elif event == bEventType["bEventEndBackupJob"]: bareosfd.DebugMessage( - context, 100, "handle_plugin_event called with bEventEndBackupJob\n" + 100, "handle_plugin_event called with bEventEndBackupJob\n" ) - return self.end_backup_job(context) + return self.end_backup_job() elif event == bEventType["bEventEndFileSet"]: bareosfd.DebugMessage( - context, 100, "handle_plugin_event called with bEventEndFileSet\n" + 100, "handle_plugin_event called with bEventEndFileSet\n" ) - return self.end_fileset(context) + return self.end_fileset() elif event == bEventType["bEventStartBackupJob"]: bareosfd.DebugMessage( - context, 100, "handle_plugin_event() called with bEventStartBackupJob\n" + 100, "handle_plugin_event() called with bEventStartBackupJob\n" ) - return self.start_backup_job(context) + return self.start_backup_job() elif event == bEventType["bEventStartRestoreJob"]: bareosfd.DebugMessage( - context, 100, "handle_plugin_event() called with bEventStartRestoreJob\n", ) - return self.start_restore_job(context) + return self.start_restore_job() else: bareosfd.DebugMessage( - context, 100, "handle_plugin_event called with event %s\n" % (event) + 100, "handle_plugin_event called with event %s\n" % (event) ) return bRCs["bRC_OK"] - def start_backup_job(self, context): + def start_backup_job(self): """ Start of Backup Job. Called just before backup job really start. Overload this to arrange whatever you have to do at this time. """ return bRCs["bRC_OK"] - def end_job(self, context): + def end_job(self: """ Called if job ends regularyly (not for cancelled jobs) Overload this to arrange whatever you have to do at this time. """ return bRCs["bRC_OK"] - def end_backup_job(self, context): + def end_backup_job(self): """ Called if backup job ends, before ClientAfterJob Overload this to arrange whatever you have to do at this time. """ return bRCs["bRC_OK"] - def start_backup_file(self, context, savepkt): + def start_backup_file(self,savepkt): """ Base method, we do not add anything, overload this method with your implementation to add files to backup fileset """ - bareosfd.DebugMessage(context, 100, "start_backup called\n") + bareosfd.DebugMessage(100, "start_backup called\n") return bRCs["bRC_Skip"] - def end_backup_file(self, context): + def end_backup_file(self): bareosfd.DebugMessage( - context, 100, "end_backup_file() entry point in Python called\n" + 100, "end_backup_file() entry point in Python called\n" ) return bRCs["bRC_OK"] - def end_fileset(self, context): + def end_fileset(self): bareosfd.DebugMessage( - context, 100, "end_fileset() entry point in Python called\n" + 100, "end_fileset() entry point in Python called\n" ) return bRCs["bRC_OK"] - def start_restore_job(self, context): + def start_restore_job(self): """ Start of Restore Job. Called , if you have Restore objects. Overload this to handle restore objects, if applicable """ return bRCs["bRC_OK"] - def start_restore_file(self, context, cmd): + def start_restore_file(self, cmd): bareosfd.DebugMessage( - context, 100, "start_restore_file() entry point in Python called with %s\n" % (cmd), ) return bRCs["bRC_OK"] - def end_restore_file(self, context): + def end_restore_file(self): bareosfd.DebugMessage( - context, 100, "end_restore_file() entry point in Python called\n" + 100, "end_restore_file() entry point in Python called\n" ) return bRCs["bRC_OK"] - def restore_object_data(self, context, ROP): + def restore_object_data(self, ROP): bareosfd.DebugMessage( - context, 100, "restore_object_data called with " + str(ROP) + "\n" + 100, "restore_object_data called with " + str(ROP) + "\n" ) return bRCs["bRC_OK"] - def create_file(self, context, restorepkt): + def create_file(self, restorepkt): """ Creates the file to be restored and directory structure, if needed. Adapt this in your derived class, if you need modifications for virtual files or similar """ bareosfd.DebugMessage( - context, 100, "create_file() entry point in Python called with %s\n" % (restorepkt), ) @@ -406,50 +391,47 @@ def create_file(self, context, restorepkt): restorepkt.create_status = bCFs["CF_CORE"] return bRCs["bRC_OK"] - def set_file_attributes(self, context, restorepkt): + def set_file_attributes(self, restorepkt): bareosfd.DebugMessage( - context, 100, "set_file_attributes() entry point in Python called with %s\n" % (str(restorepkt)), ) return bRCs["bRC_OK"] - def check_file(self, context, fname): + def check_file(self, fname): bareosfd.DebugMessage( - context, 100, "check_file() entry point in Python called with %s\n" % (fname), ) return bRCs["bRC_OK"] - def get_acl(self, context, acl): + def get_acl(self, acl): bareosfd.DebugMessage( - context, 100, "get_acl() entry point in Python called with %s\n" % (acl) + 100, "get_acl() entry point in Python called with %s\n" % (acl) ) return bRCs["bRC_OK"] - def set_acl(self, context, acl): + def set_acl(self, acl): bareosfd.DebugMessage( - context, 100, "set_acl() entry point in Python called with %s\n" % (acl) + 100, "set_acl() entry point in Python called with %s\n" % (acl) ) return bRCs["bRC_OK"] - def get_xattr(self, context, xattr): + def get_xattr(self, xattr): bareosfd.DebugMessage( - context, 100, "get_xattr() entry point in Python called with %s\n" % (xattr) + 100, "get_xattr() entry point in Python called with %s\n" % (xattr) ) return bRCs["bRC_OK"] - def set_xattr(self, context, xattr): + def set_xattr(self, xattr): bareosfd.DebugMessage( - context, 100, "set_xattr() entry point in Python called with %s\n" % (xattr) + 100, "set_xattr() entry point in Python called with %s\n" % (xattr) ) return bRCs["bRC_OK"] - def handle_backup_file(self, context, savepkt): + def handle_backup_file(self, savepkt): bareosfd.DebugMessage( - context, 100, "handle_backup_file() entry point in Python called with %s\n" % (savepkt), ) diff --git a/core/src/plugins/filed/BareosFdPluginLDAP.py b/core/src/plugins/filed/BareosFdPluginLDAP.py index 5cb6651a443..33f133bc75b 100644 --- a/core/src/plugins/filed/BareosFdPluginLDAP.py +++ b/core/src/plugins/filed/BareosFdPluginLDAP.py @@ -44,30 +44,28 @@ class BareosFdPluginLDAP(BareosFdPluginBaseclass.BareosFdPluginBaseclass): LDAP related backup and restore stuff """ - def __init__(self, context, plugindef): + def __init__(self, plugindef): bareosfd.DebugMessage( - context, 100, "Constructor called in module %s with plugindef=%s\n" % (__name__, plugindef), ) - super(BareosFdPluginLDAP, self).__init__(context, plugindef, ["uri", "basedn"]) + super(BareosFdPluginLDAP, self).__init__(plugindef, ["uri", "basedn"]) self.ldap = BareosLDAPWrapper() - def parse_plugin_definition(self, context, plugindef): + def parse_plugin_definition(self, plugindef): """ Parses the plugin arguments and validates the options. """ bareosfd.DebugMessage( - context, 100, "parse_plugin_definition() was called in module %s\n" % (__name__), ) - super(BareosFdPluginLDAP, self).parse_plugin_definition(context, plugindef) + super(BareosFdPluginLDAP, self).parse_plugin_definition(plugindef) return bRCs["bRC_OK"] - def start_backup_job(self, context): + def start_backup_job(self): """ Start of Backup Job """ @@ -75,19 +73,19 @@ def start_backup_job(self, context): if check_option_bRC != bRCs["bRC_OK"]: return check_option_bRC - return self.ldap.prepare_backup(context, self.options) + return self.ldap.prepare_backup(self.options) - def start_backup_file(self, context, savepkt): + def start_backup_file(self, savepkt): """ Defines the file to backup and creates the savepkt. """ bareosfd.DebugMessage( - context, 100, "BareosFdPluginLDAP:start_backup_file() called\n" + 100, "BareosFdPluginLDAP:start_backup_file() called\n" ) - return self.ldap.get_next_file_to_backup(context, savepkt) + return self.ldap.get_next_file_to_backup(savepkt) - def start_restore_job(self, context): + def start_restore_job(self): """ Start of Restore Job """ @@ -95,11 +93,10 @@ def start_restore_job(self, context): if check_option_bRC != bRCs["bRC_OK"]: return check_option_bRC - return self.ldap.prepare_restore(context, self.options) + return self.ldap.prepare_restore(self.options) - def start_restore_file(self, context, cmd): + def start_restore_file(self, cmd): bareosfd.DebugMessage( - context, 100, "BareosFdPluginLDAP:start_restore_file() called with %s\n" % (cmd), ) @@ -113,13 +110,12 @@ def start_restore_file(self, context, cmd): else: return bRCs["bRC_OK"] - def create_file(self, context, restorepkt): + def create_file(self, restorepkt): """ Directories are placeholders only we use the data.ldif files to get the actual DN of the LDAP record """ bareosfd.DebugMessage( - context, 100, "BareosFdPluginVMware:create_file() called with %s\n" % (restorepkt), ) @@ -130,7 +126,6 @@ def create_file(self, context, restorepkt): restorepkt.create_status = bCFs["CF_EXTRACT"] else: bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "Request to restore illegal filetype %s\n" % (restorepkt.type), ) @@ -138,9 +133,8 @@ def create_file(self, context, restorepkt): return bRCs["bRC_OK"] - def plugin_io(self, context, IOP): + def plugin_io(self, IOP): bareosfd.DebugMessage( - context, 100, "BareosFdPluginLDAP:plugin_io() called with function %s\n" % (IOP.func), ) @@ -173,16 +167,16 @@ def plugin_io(self, context, IOP): return bRCs["bRC_OK"] - def end_backup_file(self, context): + def end_backup_file(self): bareosfd.DebugMessage( - context, 100, "BareosFdPluginLDAP:end_backup_file() called\n" + 100, "BareosFdPluginLDAP:end_backup_file() called\n" ) return self.ldap.has_next_file(context) - def end_restore_file(self, context): + def end_restore_file(self): bareosfd.DebugMessage( - context, 100, "BareosFdPluginLDAP:end_restore_file() called\n" + 100, "BareosFdPluginLDAP:end_restore_file() called\n" ) return self.ldap.restore_entry(context) @@ -211,7 +205,7 @@ def __init__(self): self.unix_modify_time = None self.msg_id = None - def connect_and_bind(self, context, options, bulk=False): + def connect_and_bind(self, options, bulk=False): """ Bind to LDAP URI using the given authentication tokens """ @@ -228,7 +222,6 @@ def connect_and_bind(self, context, options, bulk=False): self.ld.simple_bind_s("", "") except ldap.INVALID_CREDENTIALS: bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "Failed to bind to LDAP uri %s\n" % (options["uri"]), ) @@ -237,34 +230,31 @@ def connect_and_bind(self, context, options, bulk=False): except ldap.LDAPError as e: if type(e.message) == dict and "desc" in e.message: bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "Failed to bind to LDAP uri %s: %s\n" % (options["uri"], e.message["desc"]), ) else: bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "Failed to bind to LDAP uri %s: %s\n" % (options["uri"], e), ) return bRCs["bRC_Error"] - bareosfd.DebugMessage(context, 100, "connected to LDAP server\n") + bareosfd.DebugMessage(100, "connected to LDAP server\n") return bRCs["bRC_OK"] - def prepare_backup(self, context, options): + def prepare_backup(self, options): """ Prepare a LDAP backup """ - connect_bRC = self.connect_and_bind(context, options, True) + connect_bRC = self.connect_and_bind(options, True) if connect_bRC != bRCs["bRC_OK"]: return connect_bRC bareosfd.DebugMessage( - context, 100, "Creating search filter and attribute filter to perform LDAP search\n", ) @@ -289,14 +279,12 @@ def prepare_backup(self, context, options): except ldap.LDAPError as e: if type(e.message) == dict and "desc" in e.message: bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "Failed to execute LDAP search on LDAP uri %s: %s\n" % (options["uri"], e.message["desc"]), ) else: bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "Failed to execute LDAP search on LDAP uri %s: %s\n" % (options["uri"], e), @@ -304,21 +292,21 @@ def prepare_backup(self, context, options): return bRCs["bRC_Error"] - bareosfd.DebugMessage(context, 100, "Successfully performed LDAP search\n") + bareosfd.DebugMessage(100, "Successfully performed LDAP search\n") return bRCs["bRC_OK"] - def prepare_restore(self, context, options): + def prepare_restore(self, options): """ Prepare a LDAP restore """ - connect_bRC = self.connect_and_bind(context, options) + connect_bRC = self.connect_and_bind(options) if connect_bRC != bRCs["bRC_OK"]: return connect_bRC return bRCs["bRC_OK"] - def to_unix_timestamp(self, context, timestamp): + def to_unix_timestamp(self, timestamp): if timestamp: unix_time = timegm( time.strptime(timestamp.replace("Z", "GMT"), "%Y%m%d%H%M%S%Z") @@ -327,7 +315,7 @@ def to_unix_timestamp(self, context, timestamp): else: return None - def get_next_file_to_backup(self, context, savepkt): + def get_next_file_to_backup(self, savepkt): """ Find out the next file that should be backed up """ @@ -393,7 +381,7 @@ def get_next_file_to_backup(self, context, savepkt): pass else: self.unix_create_time = self.to_unix_timestamp( - context, createTimestamp + createTimestamp ) self.unix_modify_time = None @@ -403,7 +391,7 @@ def get_next_file_to_backup(self, context, savepkt): pass else: self.unix_modify_time = self.to_unix_timestamp( - context, modifyTimestamp + modifyTimestamp ) # Convert the DN into a PATH e.g. reverse the elements. @@ -437,11 +425,11 @@ def set_new_dn(self, fname): # Remove the ',@LDAP,' in the DN which is an internal placeholder self.dn = new_dn.replace(",@LDAP,", "") - def has_next_file(self, context): + def has_next_file(self): # See if we are currently handling the LDIF file or # if there is still data in the result set if self.file_to_backup or self.ldap_entries: - bareosfd.DebugMessage(context, 100, "has_next_file(): returning bRC_More\n") + bareosfd.DebugMessage(100, "has_next_file(): returning bRC_More\n") return bRCs["bRC_More"] else: # See if there are more result sets. @@ -454,7 +442,7 @@ def has_next_file(self, context): # We expect something to be in the result set but better check if self.ldap_entries: bareosfd.DebugMessage( - context, 100, "has_next_file(): returning bRC_More\n" + 100, "has_next_file(): returning bRC_More\n" ) return bRCs["bRC_More"] except StopIteration: @@ -462,7 +450,7 @@ def has_next_file(self, context): return bRCs["bRC_OK"] - def restore_entry(self, context): + def restore_entry(self): # Restore the entry if self.ldif: # Parse the LDIF back to an attribute list @@ -474,7 +462,6 @@ def restore_entry(self, context): if self.dn != dn: bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], "Restoring original DN %s as %s\n" % (dn, self.dn), ) @@ -493,14 +480,12 @@ def restore_entry(self, context): except ldap.LDAPError as e: if type(e.message) == dict and "desc" in e.message: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "Failed to restore LDAP DN %s: %s\n" % (self.dn, e.message["desc"]), ) else: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "Failed to restore LDAP DN %s: %s\n" % (self.dn, e), ) @@ -508,7 +493,6 @@ def restore_entry(self, context): return bRCs["bRC_Error"] else: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "Failed to restore LDAP DN %s no writable binding to LDAP exists\n" % (self.dn), @@ -521,7 +505,7 @@ def restore_entry(self, context): return bRCs["bRC_OK"] - def cleanup(self, context): + def cleanup(self): if self.ld: self.ld.unbind_s() diff --git a/core/src/plugins/filed/BareosFdPluginLocalFileset.py b/core/src/plugins/filed/BareosFdPluginLocalFileset.py index 2618e17e368..84aa3b66b5f 100644 --- a/core/src/plugins/filed/BareosFdPluginLocalFileset.py +++ b/core/src/plugins/filed/BareosFdPluginLocalFileset.py @@ -40,9 +40,8 @@ class BareosFdPluginLocalFileset( listed there Filename is taken from plugin argument 'filename' """ - def __init__(self, context, plugindef, mandatory_options=None): + def __init__(self,plugindef, mandatory_options=None): bareosfd.DebugMessage( - context, 100, "Constructor called in module %s with plugindef=%s\n" % (__name__, plugindef), @@ -51,7 +50,7 @@ def __init__(self, context, plugindef, mandatory_options=None): mandatory_options = ["filename"] # Last argument of super constructor is a list of mandatory arguments super(BareosFdPluginLocalFileset, self).__init__( - context, plugindef, mandatory_options + plugindef, mandatory_options ) self.files_to_backup = [] self.file_to_backup = "" @@ -62,7 +61,7 @@ def __init__(self, context, plugindef, mandatory_options=None): self.allow = None self.deny = None - def filename_is_allowed(self, context, filename, allowregex, denyregex): + def filename_is_allowed(self, filename, allowregex, denyregex): """ Check, if filename is allowed. True, if matches allowreg and not denyregex. @@ -79,10 +78,9 @@ def filename_is_allowed(self, context, filename, allowregex, denyregex): denied = True if not allowed or denied: bareosfd.DebugMessage( - context, 100, "File %s denied by configuration\n" % (filename) + 100, "File %s denied by configuration\n" % (filename) ) bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "File %s denied by configuration\n" % (filename), ) @@ -90,7 +88,7 @@ def filename_is_allowed(self, context, filename, allowregex, denyregex): else: return True - def append_file_to_backup(self, context, filename): + def append_file_to_backup(self, filename): """ Basically add filename to list of files to backup in files_to_backup @@ -99,14 +97,13 @@ def append_file_to_backup(self, context, filename): """ self.files_to_backup.append(filename) - def start_backup_job(self, context): + def start_backup_job(self): """ At this point, plugin options were passed and checked already. We try to read from filename and setup the list of file to backup in self.files_to_backup """ bareosfd.DebugMessage( - context, 100, "Using %s to search for local files\n" % self.options["filename"], ) @@ -115,14 +112,13 @@ def start_backup_job(self, context): config_file = open(self.options["filename"], "rb") except: bareosfd.DebugMessage( - context, 100, "Could not open file %s\n" % (self.options["filename"]), ) return bRCs["bRC_Error"] else: bareosfd.DebugMessage( - context, 100, "File %s does not exist\n" % (self.options["filename"]) + 100, "File %s does not exist\n" % (self.options["filename"]) ) return bRCs["bRC_Error"] # Check, if we have allow or deny regular expressions defined @@ -133,34 +129,32 @@ def start_backup_job(self, context): for listItem in config_file.read().splitlines(): if os.path.isfile(listItem) and self.filename_is_allowed( - context, listItem, self.allow, self.deny + listItem, self.allow, self.deny ): - self.append_file_to_backup(context, listItem) + self.append_file_to_backup(listItem) if os.path.isdir(listItem): fullDirName = listItem # FD requires / at the end of a directory name if not fullDirName.endswith("/"): fullDirName += "/" - self.append_file_to_backup(context, fullDirName) + self.append_file_to_backup(fullDirName) for topdir, dirNames, fileNames in os.walk(listItem): for fileName in fileNames: if self.filename_is_allowed( - context, os.path.join(topdir, fileName), self.allow, self.deny, ): self.append_file_to_backup( - context, os.path.join(topdir, fileName) + os.path.join(topdir, fileName) ) for dirName in dirNames: fullDirName = os.path.join(topdir, dirName) + "/" - self.append_file_to_backup(context, fullDirName) - bareosfd.DebugMessage(context, 150, "Filelist: %s\n" % (self.files_to_backup)) + self.append_file_to_backup(fullDirName) + bareosfd.DebugMessage(150, "Filelist: %s\n" % (self.files_to_backup)) if not self.files_to_backup: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "No (allowed) files to backup found\n", ) @@ -168,18 +162,18 @@ def start_backup_job(self, context): else: return bRCs["bRC_OK"] - def start_backup_file(self, context, savepkt): + def start_backup_file(self, savepkt): """ Defines the file to backup and creates the savepkt. In this example only files (no directories) are allowed """ - bareosfd.DebugMessage(context, 100, "start_backup_file() called\n") + bareosfd.DebugMessage( 100, "start_backup_file() called\n") if not self.files_to_backup: - bareosfd.DebugMessage(context, 100, "No files to backup\n") + bareosfd.DebugMessage( 100, "No files to backup\n") return bRCs["bRC_Skip"] self.file_to_backup = self.files_to_backup.pop().decode("string_escape") - bareosfd.DebugMessage(context, 100, "file: " + self.file_to_backup + "\n") + bareosfd.DebugMessage(100, "file: " + self.file_to_backup + "\n") mystatp = bareosfd.StatPacket() try: @@ -189,7 +183,6 @@ def start_backup_file(self, context, savepkt): statp = os.stat(self.file_to_backup) except Exception as e: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], 'Could net get stat-info for file %s: "%s"' % (self.file_to_backup, e.message), @@ -220,40 +213,38 @@ def start_backup_file(self, context, savepkt): savepkt.link = os.readlink( self.file_to_backup.rstrip("/").encode("string_escape") ) - bareosfd.DebugMessage(context, 150, "file type is: FT_LNK\n") + bareosfd.DebugMessage(150, "file type is: FT_LNK\n") elif os.path.isfile(self.file_to_backup): savepkt.type = bFileType["FT_REG"] - bareosfd.DebugMessage(context, 150, "file type is: FT_REG\n") + bareosfd.DebugMessage(150, "file type is: FT_REG\n") elif os.path.isdir(self.file_to_backup): savepkt.type = bFileType["FT_DIREND"] savepkt.link = self.file_to_backup bareosfd.DebugMessage( - context, 150, "file %s type is: FT_DIREND\n" % self.file_to_backup + 150, "file %s type is: FT_DIREND\n" % self.file_to_backup ) elif stat.S_ISFIFO(os.stat(self.file_to_backup).st_mode): savepkt.type = bFileType["FT_FIFO"] - bareosfd.DebugMessage(context, 150, "file type is: FT_FIFO\n") + bareosfd.DebugMessage(150, "file type is: FT_FIFO\n") else: bareosfd.JobMessage( - context, bJobMessageType["M_WARNING"], "File %s of unknown type" % (self.file_to_backup), ) return bRCs["bRC_Skip"] savepkt.statp = mystatp - bareosfd.DebugMessage(context, 150, "file statpx " + str(savepkt.statp) + "\n") + bareosfd.DebugMessage(150, "file statpx " + str(savepkt.statp) + "\n") return bRCs["bRC_OK"] - def create_file(self, context, restorepkt): + def create_file(self, restorepkt): """ Creates the file to be restored and directory structure, if needed. Adapt this in your derived class, if you need modifications for virtual files or similar """ bareosfd.DebugMessage( - context, 100, "create_file() entry point in Python called with %s\n" % (restorepkt), ) @@ -263,7 +254,7 @@ def create_file(self, context, restorepkt): dirname = os.path.dirname(FNAME.rstrip("/")) if not os.path.exists(dirname): bareosfd.DebugMessage( - context, 200, "Directory %s does not exist, creating it now\n" % dirname + 200, "Directory %s does not exist, creating it now\n" % dirname ) os.makedirs(dirname) # open creates the file, if not yet existing, we close it again right @@ -294,20 +285,18 @@ def create_file(self, context, restorepkt): os.mkfifo(FNAME, 0o600) except Exception as e: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], 'Could net create fifo %s: "%s"' % (FNAME, e.message), ) restorepkt.create_status = bCFs["CF_CREATED"] else: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "Unknown type %s of file %s" % (restorepkt.type, FNAME), ) return bRCs["bRC_OK"] - def set_file_attributes(self, context, restorepkt): + def set_file_attributes(self, restorepkt): """ Need to verify: we set attributes here but on plugin_io close the mtime will be modified again. @@ -325,7 +314,6 @@ def set_file_attributes(self, context, restorepkt): self.statp[file_name] = file_attr bareosfd.DebugMessage( - context, 150, "Set file attributes " + file_name + " with stat " + str(file_attr) + "\n", ) @@ -335,7 +323,6 @@ def set_file_attributes(self, context, restorepkt): os.utime(file_name, (file_attr.atime, file_attr.mtime)) newStat = os.stat(file_name) bareosfd.DebugMessage( - context, 150, "Verified file attributes " + file_name @@ -346,21 +333,18 @@ def set_file_attributes(self, context, restorepkt): except Exception as e: bareosfd.JobMessage( - context, bJobMessageType["M_WARNING"], 'Could net set attributes for file %s: "%s"' % (file_name, e.message), ) return bRCs["bRC_OK"] - def end_restore_file(self, context): + def end_restore_file(self): bareosfd.DebugMessage( - context, 100, "end_restore_file() entry point in Python called FNAME: %s\n" % self.FNAME, ) bareosfd.DebugMessage( - context, 150, "end_restore_file set file attributes " + self.FNAME @@ -379,19 +363,18 @@ def end_restore_file(self, context): # del self.statp[self.FNAME] except Exception as e: bareosfd.JobMessage( - context, bJobMessageType["M_WARNING"], 'Could net set attributes for file %s: "%s"' % (self.FNAME, e.message), ) return bRCs["bRC_OK"] - def end_backup_file(self, context): + def end_backup_file(self): """ Here we return 'bRC_More' as long as our list files_to_backup is not empty and bRC_OK when we are done """ bareosfd.DebugMessage( - context, 100, "end_backup_file() entry point in Python called\n" + 100, "end_backup_file() entry point in Python called\n" ) if self.files_to_backup: return bRCs["bRC_More"] diff --git a/core/src/plugins/filed/BareosFdPluginOvirt.py b/core/src/plugins/filed/BareosFdPluginOvirt.py index 58eff9c47ea..ef626899836 100644 --- a/core/src/plugins/filed/BareosFdPluginOvirt.py +++ b/core/src/plugins/filed/BareosFdPluginOvirt.py @@ -47,14 +47,13 @@ class BareosFdPluginOvirt(BareosFdPluginBaseclass.BareosFdPluginBaseclass): Plugin for oVirt backup and restore """ - def __init__(self, context, plugindef): + def __init__(self, plugindef): bareosfd.DebugMessage( - context, 100, "Constructor called in module %s with plugindef=%s\n" % (__name__, plugindef), ) - super(BareosFdPluginOvirt, self).__init__(context, plugindef) + super(BareosFdPluginOvirt, self).__init__(plugindef) if self.mandatory_options is None: self.mandatory_options = [] @@ -63,14 +62,13 @@ def __init__(self, context, plugindef): self.ovirt = BareosOvirtWrapper() - def parse_plugin_definition(self, context, plugindef): + def parse_plugin_definition(self, plugindef): """ Parses the plugin arguments """ - super(BareosFdPluginOvirt, self).parse_plugin_definition(context, plugindef) + super(BareosFdPluginOvirt, self).parse_plugin_definition(plugindef) bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt:parse_plugin_definition() called with options '%s' \n" % str(self.options), @@ -85,7 +83,7 @@ def parse_plugin_definition(self, context, plugindef): self.ovirt.set_options(self.options) return bRCs["bRC_OK"] - def check_options(self, context, mandatory_options=None): + def check_options(self, mandatory_options=None): """ Check Plugin options Note: this is called by parent class parse_plugin_definition(). @@ -96,18 +94,17 @@ def check_options(self, context, mandatory_options=None): """ return bRCs["bRC_OK"] - def start_backup_job(self, context): + def start_backup_job(self): """ Start of Backup Job. Called just before backup job really start. Overload this to arrange whatever you have to do at this time. """ bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt:start_backup_job() called\n" + 100, "BareosFdPluginOvirt:start_backup_job() called\n" ) if chr(self.level) != "F": bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "BareosFdPluginOvirt can only perform level F (Full) backups, but level is %s\n" % (chr(self.level)), @@ -119,17 +116,17 @@ def start_backup_job(self, context): return self.ovirt.prepare_vm_backup(context) - def start_backup_file(self, context, savepkt): + def start_backup_file(self, savepkt): """ Defines the file to backup and creates the savepkt. """ bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt:start_backup_file() called\n" + 100, "BareosFdPluginOvirt:start_backup_file() called\n" ) if not self.ovirt.backup_objects: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "Nothing to backup.\n" + bJobMessageType["M_ERROR"], "Nothing to backup.\n" ) self.backup_obj = None return bRCs["bRC_Skip"] @@ -146,7 +143,6 @@ def start_backup_file(self, context, savepkt): vmfile = self.backup_obj["file"] bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt:start_backup_file() backup regular file '%s' of VM '%s'\n" % (vmfile["filename"], self.backup_obj["vmname"]), @@ -168,7 +164,6 @@ def start_backup_file(self, context, savepkt): snapshot = self.backup_obj["snapshot"] bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt:start_backup_file() backup disk file '%s'('%s'/'%s') of VM '%s'\n" % (disk.alias, disk.id, snapshot.id, self.backup_obj["vmname"]), @@ -184,10 +179,9 @@ def start_backup_file(self, context, savepkt): ) try: - self.ovirt.start_download(context, snapshot, disk) + self.ovirt.start_download(snapshot, disk) except Exception as e: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "BareosFdPluginOvirt:start_backup_file() Error: %s" % str(e), ) @@ -205,7 +199,6 @@ def start_backup_file(self, context, savepkt): ) bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt:start_backup_file() backup disk metadata '%s'('%s'/'%s') of VM '%s': %s\n" % ( @@ -232,7 +225,6 @@ def start_backup_file(self, context, savepkt): else: bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "BareosFdPluginOvirt:start_backup_file(): Invalid data in backup_obj, keys: %s\n" % (self.backup_obj.keys()), @@ -240,21 +232,19 @@ def start_backup_file(self, context, savepkt): return bRCs["bRC_Error"] bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], "Starting backup of %s\n" % savepkt.fname, ) return bRCs["bRC_OK"] - def create_file(self, context, restorepkt): + def create_file(self, restorepkt): """ Creates the file to be restored and directory structure, if needed. Adapt this in your derived class, if you need modifications for virtual files or similar """ bareosfd.DebugMessage( - context, 100, "create_file() entry point in Python called with %s\n" % (restorepkt), ) @@ -270,14 +260,14 @@ def create_file(self, context, restorepkt): and not self.options.get("local") == "yes" ): disk_alias = self.ovirt.get_ovf_disk_alias_by_basename( - context, restorepkt.ofname + restorepkt.ofname ) - if not self.ovirt.is_disk_alias_included(context, disk_alias): + if not self.ovirt.is_disk_alias_included(disk_alias): restorepkt.create_status = bCFs["CF_SKIP"] return bRCs["bRC_OK"] - if self.ovirt.is_disk_alias_excluded(context, disk_alias): + if self.ovirt.is_disk_alias_excluded(disk_alias): restorepkt.create_status = bCFs["CF_SKIP"] return bRCs["bRC_OK"] @@ -286,7 +276,6 @@ def create_file(self, context, restorepkt): dirname = os.path.dirname(FNAME) if not os.path.exists(dirname): bareosfd.DebugMessage( - context, 200, "Directory %s does not exist, creating it now\n" % dirname, ) @@ -303,33 +292,31 @@ def create_file(self, context, restorepkt): FNAME = restorepkt.ofname FNAME = FNAME.decode("utf-8") - disk = self.ovirt.get_vm_disk_by_basename(context, FNAME) + disk = self.ovirt.get_vm_disk_by_basename(FNAME) if disk is None: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "BareosFdPluginOvirt:create_file() Unable to restore disk %s.\n" % (FNAME), ) return bRCs["bRC_Error"] else: - self.ovirt.start_upload(context, disk) + self.ovirt.start_upload(disk) if restorepkt.type == bFileType["FT_REG"]: restorepkt.create_status = bCFs["CF_EXTRACT"] return bRCs["bRC_OK"] - def start_restore_job(self, context): + def start_restore_job(self): """ Start of Restore Job. Called , if you have Restore objects. Overload this to handle restore objects, if applicable """ bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt:start_restore_job() called\n" + 100, "BareosFdPluginOvirt:start_restore_job() called\n" ) if self.options.get("local") == "yes": bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt:start_restore_job(): restore to local file, skipping checks\n", ) @@ -341,25 +328,23 @@ def start_restore_job(self, context): return bRCs["bRC_OK"] - def start_restore_file(self, context, cmd): + def start_restore_file(self, cmd): bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt:start_restore_file() called with %s\n" % (cmd), ) return bRCs["bRC_OK"] - def plugin_io(self, context, IOP): + def plugin_io(self, IOP): """ Called for io operations. """ bareosfd.DebugMessage( - context, 100, "plugin_io called with function %s\n" % (IOP.func) + 100, "plugin_io called with function %s\n" % (IOP.func) ) - bareosfd.DebugMessage(context, 100, "FNAME is set to %s\n" % (self.FNAME)) - self.jobType = chr(bareosfd.GetValue(context, bVariable["bVarType"])) + bareosfd.DebugMessage(100, "FNAME is set to %s\n" % (self.FNAME)) + self.jobType = chr(bareosfd.GetValue(bVariable["bVarType"])) bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt::plugin_io() jobType: %s\n" % (self.jobType), ) @@ -368,14 +353,13 @@ def plugin_io(self, context, IOP): self.FNAME = IOP.fname bareosfd.DebugMessage( - context, 100, "self.FNAME was set to %s from IOP.fname\n" % (self.FNAME) + 100, "self.FNAME was set to %s from IOP.fname\n" % (self.FNAME) ) if self.options.get("local") == "yes": try: if IOP.flags & (os.O_CREAT | os.O_WRONLY): bareosfd.DebugMessage( - context, 100, "Open file %s for writing with %s\n" % (self.FNAME, IOP), ) @@ -383,7 +367,6 @@ def plugin_io(self, context, IOP): dirname = os.path.dirname(self.FNAME) if not os.path.exists(dirname): bareosfd.DebugMessage( - context, 100, "Directory %s does not exist, creating it now\n" % (dirname), @@ -393,7 +376,6 @@ def plugin_io(self, context, IOP): else: IOP.status = -1 bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "plugin_io: option local=yes can only be used on restore\n", ) @@ -401,13 +383,11 @@ def plugin_io(self, context, IOP): except (OSError, IOError) as io_open_error: IOP.status = -1 bareosfd.DebugMessage( - context, 100, "plugin_io: failed to open %s: %s\n" % (self.FNAME, io_open_error.strerror), ) bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "plugin_io: failed to open %s: %s\n" % (self.FNAME, io_open_error.strerror), @@ -418,14 +398,14 @@ def plugin_io(self, context, IOP): elif IOP.func == bIOPS["IO_CLOSE"]: if self.file is not None: - bareosfd.DebugMessage(context, 100, "Closing file " + "\n") + bareosfd.DebugMessage(100, "Closing file " + "\n") self.file.close() elif self.jobType == "B": if "file" in self.backup_obj: self.backup_obj["file"]["fh"].close() elif "disk" in self.backup_obj: bareosfd.DebugMessage( - context, 100, "plugin_io: calling end_transfer()\n" + 100, "plugin_io: calling end_transfer()\n" ) # Backup Job self.ovirt.end_transfer(context) @@ -443,26 +423,23 @@ def plugin_io(self, context, IOP): IOP.status = self.backup_obj["file"]["fh"].readinto(IOP.buf) IOP.io_errno = 0 bareosfd.DebugMessage( - context, 100, "plugin_io: read from file %s\n" % (self.backup_obj["file"]["filename"]), ) elif "disk" in self.backup_obj: bareosfd.DebugMessage( - context, 100, "plugin_io: read from disk %s\n" % (self.backup_obj["disk"].alias), ) try: IOP.buf = bytearray(IOP.count) - chunk = self.ovirt.process_download(context, IOP.count) + chunk = self.ovirt.process_download(IOP.count) IOP.buf[:] = chunk IOP.status = len(IOP.buf) IOP.io_errno = 0 except Exception as e: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "BareosFdPluginOvirt:plugin_io() Error: %s" % str(e), ) @@ -470,7 +447,6 @@ def plugin_io(self, context, IOP): return bRCs["bRC_Error"] else: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "BareosFdPluginOvirt:plugin_io() Unable to read data to backup.", ) @@ -480,7 +456,7 @@ def plugin_io(self, context, IOP): if self.file is not None: try: bareosfd.DebugMessage( - context, 200, "Writing buffer to file %s\n" % (self.FNAME) + 200, "Writing buffer to file %s\n" % (self.FNAME) ) self.file.write(IOP.buf) IOP.status = IOP.count @@ -488,40 +464,37 @@ def plugin_io(self, context, IOP): except IOError as msg: IOP.io_errno = -1 bareosfd.DebugMessage( - context, 100, "Error writing data: " + msg + "\n" + 100, "Error writing data: " + msg + "\n" ) return bRCs["bRC_Error"] elif self.FNAME.endswith(".ovf"): - self.ovirt.process_ovf(context, IOP.buf) + self.ovirt.process_ovf(IOP.buf) IOP.status = IOP.count IOP.io_errno = 0 else: - self.ovirt.process_upload(context, IOP.buf) + self.ovirt.process_upload(IOP.buf) IOP.status = IOP.count IOP.io_errno = 0 return bRCs["bRC_OK"] - def handle_plugin_event(self, context, event): + def handle_plugin_event(self, event): if event == bEventType["bEventEndBackupJob"]: bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt::handle_plugin_event() called with bEventEndBackupJob\n", ) - bareosfd.DebugMessage(context, 100, "removing Snapshot\n") + bareosfd.DebugMessage(100, "removing Snapshot\n") self.ovirt.end_vm_backup(context) elif event == bEventType["bEventEndFileSet"]: bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt::handle_plugin_event() called with bEventEndFileSet\n", ) elif event == bEventType["bEventStartBackupJob"]: bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt::handle_plugin_event() called with bEventStartBackupJob\n", ) @@ -530,7 +503,6 @@ def handle_plugin_event(self, context, event): elif event == bEventType["bEventStartRestoreJob"]: bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt::handle_plugin_event() called with bEventStartRestoreJob\n", ) @@ -539,15 +511,13 @@ def handle_plugin_event(self, context, event): elif event == bEventType["bEventEndRestoreJob"]: bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt::handle_plugin_event() called with bEventEndRestoreJob\n", ) - bareosfd.DebugMessage(context, 100, "removing Snapshot\n") + bareosfd.DebugMessage(100, "removing Snapshot\n") self.ovirt.end_vm_restore(context) else: bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt::handle_plugin_event() called with event %s\n" % (event), @@ -555,9 +525,8 @@ def handle_plugin_event(self, context, event): return bRCs["bRC_OK"] - def end_backup_file(self, context): + def end_backup_file(self): bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt::end_backup_file() entry point in Python called\n", ) @@ -567,7 +536,6 @@ def end_backup_file(self, context): self.ovirt.init_bytes_to_transf / 1000.0 / elapsed_seconds, 1 ) bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], " Transfer time: %s s bytes: %s rate: %s KB/s\n" % (elapsed_seconds, self.ovirt.init_bytes_to_transf, download_rate), @@ -579,9 +547,8 @@ def end_backup_file(self, context): else: return bRCs["bRC_OK"] - def end_restore_file(self, context): + def end_restore_file(self): bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt::end_restore_file() entry point in Python called\n", ) @@ -591,7 +558,6 @@ def end_restore_file(self, context): self.ovirt.init_bytes_to_transf / 1000.0 / elapsed_seconds, 1 ) bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], " Upload time: %s s bytes: %s rate: %s KB/s\n" % (elapsed_seconds, self.ovirt.init_bytes_to_transf, download_rate), @@ -599,7 +565,7 @@ def end_restore_file(self, context): self.ovirt.transfer_start_time = None return bRCs["bRC_OK"] - def restore_object_data(self, context, ROP): + def restore_object_data(self, ROP): """ Note: This is called in two cases: @@ -610,33 +576,28 @@ def restore_object_data(self, context, ROP): is "I" until the bEventStartBackupJob event """ bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt:restore_object_data() called with ROP:%s\n" % (ROP), ) bareosfd.DebugMessage( - context, 100, "ROP.object_name(%s): %s\n" % (type(ROP.object_name), ROP.object_name), ) bareosfd.DebugMessage( - context, 100, "ROP.plugin_name(%s): %s\n" % (type(ROP.plugin_name), ROP.plugin_name), ) bareosfd.DebugMessage( - context, 100, "ROP.object_len(%s): %s\n" % (type(ROP.object_len), ROP.object_len), ) bareosfd.DebugMessage( - context, 100, "ROP.object_full_len(%s): %s\n" % (type(ROP.object_full_len), ROP.object_full_len), ) bareosfd.DebugMessage( - context, 100, "ROP.object(%s): %s\n" % (type(ROP.object), ROP.object) + 100, "ROP.object(%s): %s\n" % (type(ROP.object), ROP.object) ) ro_data = json.loads(str(ROP.object)) self.ovirt.disk_metadata_by_id[ro_data["disk_metadata"]["id"]] = ro_data[ @@ -645,12 +606,11 @@ def restore_object_data(self, context, ROP): return bRCs["bRC_OK"] - def parse_config_file(self, context): + def parse_config_file(self): """ Parse the config file given in the config_file plugin option """ bareosfd.DebugMessage( - context, 100, "BareosFdPluginOvirt: parse_config_file(): parse %s\n" % (self.options["config_file"]), @@ -662,7 +622,6 @@ def parse_config_file(self, context): self.config.readfp(open(self.options["config_file"])) except IOError as err: bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "BareosFdPluginOvirt: Error reading config file %s: %s\n" % (self.options["config_file"], err.strerror), @@ -671,12 +630,12 @@ def parse_config_file(self, context): return self.check_config(context) - def check_config(self, context): + def check_config(self): """ Check the configuration and set or override options if necessary, considering mandatory: username and password in the [credentials] section """ - bareosfd.DebugMessage(context, 100, "BareosFdPluginOvirt: check_config()\n") + bareosfd.DebugMessage(100, "BareosFdPluginOvirt: check_config()\n") mandatory_sections = ["credentials"] mandatory_options = {} mandatory_options["credentials"] = ["username", "password"] @@ -684,7 +643,6 @@ def check_config(self, context): for section in mandatory_sections: if not self.config.has_section(section): bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "BareosFdPluginOvirt: Section [%s] missing in config file %s\n" % (section, self.options["config_file"]), @@ -694,7 +652,6 @@ def check_config(self, context): for option in mandatory_options[section]: if not self.config.has_option(section, option): bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "BareosFdPluginOvirt: Options %s missing in Section [%s] in config file %s\n" % (option, section, self.options["config_file"]), @@ -704,7 +661,6 @@ def check_config(self, context): plugin_option = self.options.get(option) if plugin_option: bareosfd.JobMessage( - context, bJobMessageType["M_WARNING"], "BareosFdPluginOvirt: Overriding plugin option %s from config file %s\n" % (option, self.options["config_file"]), @@ -759,7 +715,7 @@ def set_options(self, options): # make the plugin options also available in this class self.options = options - def connect_api(self, context): + def connect_api(self): # ca certificate self.ca = self.options["ca"] @@ -786,7 +742,6 @@ def connect_api(self, context): if not self.connection: bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "Cannot connect to host %s with user %s and ca file %s\n" % (self.options["server"], self.options["username"], self.ca), @@ -816,7 +771,6 @@ def connect_api(self, context): self.event_id = int(time.time()) bareosfd.DebugMessage( - context, 100, ( "Successfully connected to Ovirt Engine API on '%s' with" @@ -827,7 +781,7 @@ def connect_api(self, context): return True - def prepare_vm_backup(self, context): + def prepare_vm_backup(self): """ prepare VM backup: - get vm details @@ -835,13 +789,12 @@ def prepare_vm_backup(self, context): - get disk devices """ bareosfd.DebugMessage( - context, 100, "BareosOvirtWrapper::prepare_vm_backup: prepare VM to backup\n", ) if not self.get_vm(context): - bareosfd.DebugMessage(context, 100, "Error getting details for VM\n") + bareosfd.DebugMessage(100, "Error getting details for VM\n") return bRCs["bRC_Error"] else: @@ -852,7 +805,6 @@ def prepare_vm_backup(self, context): snaps_service = self.vm_service.snapshots_service() if len(snaps_service.list()) > 1: bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "Error '%s' already have snapshosts. This is not supported\n" % (self.vm.name), @@ -860,7 +812,7 @@ def prepare_vm_backup(self, context): return bRCs["bRC_Error"] bareosfd.DebugMessage( - context, 100, "Start the backup of VM %s\n" % (self.vm.name) + 100, "Start the backup of VM %s\n" % (self.vm.name) ) # Save the OVF to a file, so that we can use to restore the virtual @@ -886,7 +838,6 @@ def prepare_vm_backup(self, context): # get vm backup disks from snapshot if not self.all_disks_excluded and not self.get_vm_backup_disks(context): bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "Error getting Backup Disks VM %s from snapshot\n" % (self.vm.name), ) @@ -894,7 +845,7 @@ def prepare_vm_backup(self, context): return bRCs["bRC_OK"] - def get_vm(self, context): + def get_vm(self): search = None if "uuid" in self.options: search = "id=%s" % str(self.options["uuid"]) @@ -902,14 +853,14 @@ def get_vm(self, context): search = "name=%s" % str(self.options["vm_name"]) if search is not None: - bareosfd.DebugMessage(context, 100, "get_vm search vm by '%s'\n" % (search)) + bareosfd.DebugMessage(100, "get_vm search vm by '%s'\n" % (search)) res = self.vms_service.list(search=search, all_content=True) if len(res) > 0: self.vm = res[0] return True return False - def create_vm_snapshot(self, context): + def create_vm_snapshot(self): """ Creates a snapshot """ @@ -952,7 +903,6 @@ def create_vm_snapshot(self, context): ), ) bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], "Sent request to create snapshot '%s', the id is '%s'.\n" % (snap.description, snap.id), @@ -963,7 +913,6 @@ def create_vm_snapshot(self, context): self.snap_service = snaps_service.snapshot_service(snap.id) while snap.snapshot_status != types.SnapshotStatus.OK: bareosfd.DebugMessage( - context, 100, "Waiting till the snapshot is created, the status is now '%s'.\n" % snap.snapshot_status, @@ -976,10 +925,10 @@ def create_vm_snapshot(self, context): time.sleep(10) bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], "' The snapshot is now complete.\n" + bJobMessageType["M_INFO"], "' The snapshot is now complete.\n" ) - def get_vm_disks_for_snapshot(self, context): + def get_vm_disks_for_snapshot(self): # return list of disks for snapshot, process include/exclude if given disk_attachments_service = self.vm_service.disk_attachments_service() disk_attachments = disk_attachments_service.list() @@ -988,9 +937,9 @@ def get_vm_disks_for_snapshot(self, context): for disk_attachment in disk_attachments: disk = self.connection.follow_link(disk_attachment.disk) - if not self.is_disk_alias_included(context, disk.alias): + if not self.is_disk_alias_included(disk.alias): continue - if self.is_disk_alias_excluded(context, disk.alias): + if self.is_disk_alias_excluded(disk.alias): continue included_disk_ids.append(disk.id) @@ -1001,7 +950,6 @@ def get_vm_disks_for_snapshot(self, context): # included_disks = (types.DiskAttachment(),) self.all_disks_excluded = True bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], "All disks excluded, only backing up VM configuration.\n", ) @@ -1015,7 +963,7 @@ def get_vm_disks_for_snapshot(self, context): return included_disks - def get_vm_backup_disks(self, context): + def get_vm_backup_disks(self): has_disks = False @@ -1037,7 +985,6 @@ def get_vm_backup_disks(self, context): disk_id = snap_disk.id disk_alias = snap_disk.alias bareosfd.DebugMessage( - context, 200, "get_vm_backup_disks(): disk_id: '%s' disk_alias '%s'\n" % (disk_id, disk_alias), @@ -1073,14 +1020,13 @@ def get_vm_backup_disks(self, context): has_disks = True return has_disks - def is_disk_alias_included(self, context, disk_alias): + def is_disk_alias_included(self, disk_alias): if self.options.get("include_disk_aliases") is None: return True include_disk_aliases = self.options["include_disk_aliases"].split(",") if disk_alias in include_disk_aliases: bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], "Including disk with alias %s\n" % (disk_alias), ) @@ -1088,7 +1034,7 @@ def is_disk_alias_included(self, context, disk_alias): return False - def is_disk_alias_excluded(self, context, disk_alias): + def is_disk_alias_excluded(self, disk_alias): if self.options.get("exclude_disk_aliases") is None: return False @@ -1096,7 +1042,6 @@ def is_disk_alias_excluded(self, context, disk_alias): if "*" in exclude_disk_aliases or disk_alias in exclude_disk_aliases: bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], "Excluding disk with alias %s\n" % (disk_alias), ) @@ -1130,12 +1075,11 @@ def get_proxy_connection(self, proxy_url): # your CA certificate of the engine in the system, you need to pass it to HTTPSConnection. context.load_verify_locations(cafile=self.ca) - return HTTPSConnection(proxy_url.hostname, proxy_url.port, context=context) + return HTTPSConnection(proxy_url.hostname, proxy_url.port=context) - def start_download(self, context, snapshot, disk): + def start_download(self, snapshot, disk): bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], "Downloading snapshot '%s' of disk '%s'('%s')\n" % (snapshot.id, disk.alias, disk.id), @@ -1162,7 +1106,7 @@ def start_download(self, context, snapshot, disk): # Check the response status: if self.response.status >= 300: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "Error: %s" % self.response.read() + bJobMessageType["M_ERROR"], "Error: %s" % self.response.read() ) self.bytes_to_transf = int(self.response.getheader("Content-Length")) @@ -1182,7 +1126,6 @@ def start_download(self, context, snapshot, disk): ) bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], " Transfer disk snapshot of %s bytes\n" % (str(self.bytes_to_transf)), ) @@ -1190,12 +1133,11 @@ def start_download(self, context, snapshot, disk): self.init_bytes_to_transf = self.bytes_to_transf self.transfer_start_time = time.time() - def process_download(self, context, chunk_size): + def process_download(self, chunk_size): chunk = "" bareosfd.DebugMessage( - context, 100, "process_download(): transfer %s of %s (%s) \n" % ( @@ -1215,10 +1157,9 @@ def process_download(self, context, chunk_size): if chunk == "": bareosfd.DebugMessage( - context, 100, "process_download(): Socket disconnected. \n" + 100, "process_download(): Socket disconnected. \n" ) bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "process_download(): Socket disconnected.", ) @@ -1233,12 +1174,12 @@ def process_download(self, context, chunk_size): ) bareosfd.DebugMessage( - context, 100, "process_download(): Completed {:.0%}\n".format(completed) + 100, "process_download(): Completed {:.0%}\n".format(completed) ) return chunk - def prepare_vm_restore(self, context): + def prepare_vm_restore(self): restore_existing_vm = False if self.connection is None: # if not connected yet @@ -1247,7 +1188,6 @@ def prepare_vm_restore(self, context): if self.ovf_data is None: bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "Unable to restore VM. No OVF data. \n", ) @@ -1255,7 +1195,6 @@ def prepare_vm_restore(self, context): else: if "storage_domain" not in self.options: bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "No storage domain specified.\n", ) @@ -1267,7 +1206,7 @@ def prepare_vm_restore(self, context): self.ovf = Ovf(self.ovf_data) bareosfd.DebugMessage( - context, 200, "prepare_vm_restore(): %s\n" % (self.ovf) + 200, "prepare_vm_restore(): %s\n" % (self.ovf) ) # Find the name of the virtual machine within the OVF: @@ -1293,7 +1232,6 @@ def prepare_vm_restore(self, context): ) if len(res) > 1: bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "Found %s VMs with name '%s'\n" % (len(res), str(vm_name)), ) @@ -1302,7 +1240,6 @@ def prepare_vm_restore(self, context): if len(res) == 1: if not self.options.get("overwrite") == "yes": bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "If you are sure you want to overwrite the existing VM '%s', please add the plugin option 'overwrite=yes'\n" % (str(vm_name)), @@ -1310,7 +1247,6 @@ def prepare_vm_restore(self, context): return bRCs["bRC_Error"] bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], "Restore to existing VM '%s'\n" % str(vm_name), ) @@ -1318,7 +1254,6 @@ def prepare_vm_restore(self, context): if self.vm.status != types.VmStatus.DOWN: bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "VM '%s' must be down for restore, but status is %s\n" % (str(vm_name), self.vm.status), @@ -1328,7 +1263,7 @@ def prepare_vm_restore(self, context): restore_existing_vm = True else: - self.create_vm(context, vm_name, cluster_name) + self.create_vm(vm_name, cluster_name) self.add_nics_to_vm(context) # Extract disk information from OVF @@ -1362,7 +1297,6 @@ def prepare_vm_restore(self, context): self.old_new_ids[old_disk_id] = old_disk_id bareosfd.DebugMessage( - context, 200, "end of prepare_vm_restore(): self.restore_objects: %s self.old_new_ids: %s\n" % (self.restore_objects, self.old_new_ids), @@ -1370,7 +1304,7 @@ def prepare_vm_restore(self, context): return bRCs["bRC_OK"] - def create_vm(self, context, vm_name, cluster_name): + def create_vm(self, vm_name, cluster_name): vm_template = "Blank" if "vm_template" in self.options: @@ -1379,7 +1313,7 @@ def create_vm(self, context, vm_name, cluster_name): # Add the virtual machine, the transferred disks will be # attached to this virtual machine: bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], "Adding virtual machine %s\n" % vm_name + bJobMessageType["M_INFO"], "Adding virtual machine %s\n" % vm_name ) # vm type (server/desktop) @@ -1462,11 +1396,10 @@ def create_vm(self, context, vm_name, cluster_name): ), ) - def add_nics_to_vm(self, context): + def add_nics_to_vm(self): # Find the network section network_elements = self.ovf.get_elements("network_elements") bareosfd.DebugMessage( - context, 200, "add_nics_to_vm(): network_elements: %s\n" % (network_elements), ) @@ -1480,13 +1413,12 @@ def add_nics_to_vm(self, context): props[key] = value bareosfd.DebugMessage( - context, 200, "add_nics_to_vm(): props: %s\n" % (props) + 200, "add_nics_to_vm(): props: %s\n" % (props) ) network = props["Connection"] if network not in self.network_profiles: bareosfd.JobMessage( - context, bJobMessageType["M_WARNING"], "No network profile found for '%s'\n" % (network), ) @@ -1507,12 +1439,11 @@ def add_nics_to_vm(self, context): ), ) bareosfd.DebugMessage( - context, 200, "add_nics_to_vm(): added NIC with props %s\n" % (props), ) - def get_ovf_disk_alias_by_basename(self, context, fname): + def get_ovf_disk_alias_by_basename(self, fname): """ Return the disk alias name from OVF data for given fname (full path), this is used on restore by create_file() to process includes/excludes @@ -1525,7 +1456,7 @@ def get_ovf_disk_alias_by_basename(self, context, fname): return self.ovf_disks_by_alias_and_fileref[relname]["disk-alias"] - def get_vm_disk_by_basename(self, context, fname): + def get_vm_disk_by_basename(self, fname): dirpath = os.path.dirname(fname) dirname = os.path.basename(dirpath) @@ -1534,7 +1465,6 @@ def get_vm_disk_by_basename(self, context, fname): found = None bareosfd.DebugMessage( - context, 200, "get_vm_disk_by_basename(): %s %s\n" % (basename, self.restore_objects), ) @@ -1544,21 +1474,19 @@ def get_vm_disk_by_basename(self, context, fname): obj = self.restore_objects[i] key = "%s-%s" % (obj["disk-alias"], obj["fileRef"]) bareosfd.DebugMessage( - context, 200, "get_vm_disk_by_basename(): lookup %s == %s and %s == %s\n" % (repr(relname), repr(key), repr(basename), repr(obj["diskId"])), ) if relname == key and basename == obj["diskId"]: bareosfd.DebugMessage( - context, 200, "get_vm_disk_by_basename(): lookup matched\n" + 200, "get_vm_disk_by_basename(): lookup matched\n" ) old_disk_id = os.path.dirname(obj["fileRef"]) new_disk_id = None if old_disk_id in self.old_new_ids: bareosfd.DebugMessage( - context, 200, "get_vm_disk_by_basename(): disk id %s found in old_new_ids: %s\n" % (old_disk_id, self.old_new_ids), @@ -1567,7 +1495,7 @@ def get_vm_disk_by_basename(self, context, fname): # get base disks if not obj["parentRef"]: - disk = self.get_or_add_vm_disk(context, obj, new_disk_id) + disk = self.get_or_add_vm_disk(obj, new_disk_id) if disk is not None: new_disk_id = disk.id @@ -1575,25 +1503,24 @@ def get_vm_disk_by_basename(self, context, fname): found = disk else: bareosfd.JobMessage( - context, bJobMessageType["M_WARNING"], "The backup have snapshots and only base will be restored\n", ) i += 1 bareosfd.DebugMessage( - context, 200, "get_vm_disk_by_basename(): found disk %s\n" % (found) + 200, "get_vm_disk_by_basename(): found disk %s\n" % (found) ) return found - def get_or_add_vm_disk(self, context, obj, disk_id=None): + def get_or_add_vm_disk(self, obj, disk_id=None): # Create the disks: disks_service = self.system_service.disks_service() disk = None if "storage_domain" not in obj: bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "No storage domain specified.\n" + bJobMessageType["M_FATAL"], "No storage domain specified.\n" ) else: storage_domain = obj["storage_domain"] @@ -1678,19 +1605,18 @@ def get_or_add_vm_disk(self, context, obj, disk_id=None): return disk - def start_upload(self, context, disk): + def start_upload(self, disk): bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], "Uploading disk '%s'('%s')\n" % (disk.alias, disk.id), ) bareosfd.DebugMessage( - context, 100, "Uploading disk '%s'('%s')\n" % (disk.alias, disk.id) + 100, "Uploading disk '%s'('%s')\n" % (disk.alias, disk.id) ) - bareosfd.DebugMessage(context, 200, "old_new_ids: %s\n" % (self.old_new_ids)) + bareosfd.DebugMessage(200, "old_new_ids: %s\n" % (self.old_new_ids)) bareosfd.DebugMessage( - context, 200, "self.restore_objects: %s\n" % (self.restore_objects) + 200, "self.restore_objects: %s\n" % (self.restore_objects) ) self.transfer_service = self.get_transfer_service( @@ -1726,22 +1652,20 @@ def start_upload(self, context, disk): self.proxy_connection.endheaders() bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], " Upload disk of %s bytes\n" % (str(self.bytes_to_transf)), ) self.transfer_start_time = time.time() - def process_ovf(self, context, chunk): + def process_ovf(self, chunk): if self.ovf_data is None: self.ovf_data = str(chunk) else: self.ovf_data = self.ovf_data.str(chunk) - def process_upload(self, context, chunk): + def process_upload(self, chunk): bareosfd.DebugMessage( - context, 100, "process_upload(): transfer %s of %s (%s) \n" % (self.bytes_to_transf, self.init_bytes_to_transf, len(chunk)), @@ -1754,18 +1678,18 @@ def process_upload(self, context, chunk): completed = 1 - (self.bytes_to_transf / float(self.init_bytes_to_transf)) bareosfd.DebugMessage( - context, 100, "process_upload(): Completed {:.0%}\n".format(completed) + 100, "process_upload(): Completed {:.0%}\n".format(completed) ) - def end_transfer(self, context): + def end_transfer(self): - bareosfd.DebugMessage(context, 100, "end_transfer()\n") + bareosfd.DebugMessage(100, "end_transfer()\n") # Finalize the session. if self.transfer_service is not None: self.transfer_service.finalize() - def end_vm_backup(self, context): + def end_vm_backup(self): if self.snap_service: t_start = int(time.time()) @@ -1775,7 +1699,6 @@ def end_vm_backup(self, context): snapshot_deleted_success = False bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], "Sending request to remove snapshot '%s', the id is '%s'.\n" % (snap.description, snap.id), @@ -1791,7 +1714,6 @@ def end_vm_backup(self, context): elapsed = int(time.time()) - t_start if elapsed >= self.snapshot_remove_timeout: bareosfd.JobMessage( - context, bJobMessageType["M_WARNING"], "Remove snapshot timed out after %s s, reason: %s! Please remove it manually.\n" % (elapsed, e.message), @@ -1799,20 +1721,17 @@ def end_vm_backup(self, context): return bRCs["bRC_Error"] bareosfd.DebugMessage( - context, 100, "Could not remove snapshot, reason: %s, retrying until timeout (%s seconds left).\n" % (e.message, self.snapshot_remove_timeout - elapsed), ) bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], "Still waiting for snapshot removal, retrying until timeout (%s seconds left).\n" % (self.snapshot_remove_timeout - elapsed), ) else: bareosfd.JobMessage( - context, bJobMessageType["M_WARNING"], "Unexpected error removing snapshot: %s, Please remove it manually.\n" % e.message, @@ -1828,7 +1747,6 @@ def end_vm_backup(self, context): if snapshot_deleted_success: bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], "Removed the snapshot '%s'.\n" % snap.description, ) @@ -1870,7 +1788,7 @@ def wait_for_snapshot_removal(self, snapshot_id, timeout=30, delay=10): return - def end_vm_restore(self, context): + def end_vm_restore(self): # Send an external event to indicate to the administrator that the # restore of the virtual machine is completed: diff --git a/core/src/plugins/filed/BareosFdPluginPerconaXtraBackup.py b/core/src/plugins/filed/BareosFdPluginPerconaXtraBackup.py index c028bada4c8..9aa48e3a892 100644 --- a/core/src/plugins/filed/BareosFdPluginPerconaXtraBackup.py +++ b/core/src/plugins/filed/BareosFdPluginPerconaXtraBackup.py @@ -40,27 +40,27 @@ class BareosFdPercona(BareosFdPluginBaseclass): using the Percona xtrabackup tool. """ - def __init__(self, context, plugindef): - # BareosFdPluginBaseclass.__init__(self, context, plugindef) - super(BareosFdPercona, self).__init__(context, plugindef) + def __init__(self, plugindef): + # BareosFdPluginBaseclass.__init__(self, plugindef) + super(BareosFdPercona, self).__init__(plugindef) # we first create and backup the stream and after that # the lsn file as restore-object self.files_to_backup = ["lsnfile", "stream"] self.tempdir = tempfile.mkdtemp() - # self.logdir = GetValue(context, bVariable['bVarWorkingDir']) + # self.logdir = GetValue(bVariable['bVarWorkingDir']) self.logdir = "/var/log/bareos/" self.log = "bareos-plugin-percona.log" self.rop_data = {} self.max_to_lsn = 0 self.err_fd = None - def parse_plugin_definition(self, context, plugindef): + def parse_plugin_definition(self, plugindef): """ We have default options that should work out of the box in the most use cases that the mysql/mariadb is on the same host and can be accessed without user/password information, e.g. with a valid my.cnf for user root. """ - BareosFdPluginBaseclass.parse_plugin_definition(self, context, plugindef) + BareosFdPluginBaseclass.parse_plugin_definition(self, plugindef) if "dumpbinary" in self.options: self.dumpbinary = self.options["dumpbinary"] @@ -122,11 +122,10 @@ def parse_plugin_definition(self, context, plugindef): return bRCs["bRC_OK"] - def check_plugin_options(self, context, mandatory_options=None): - accurate_enabled = GetValue(context, bVariable["bVarAccurate"]) + def check_plugin_options(self, mandatory_options=None): + accurate_enabled = GetValue(bVariable["bVarAccurate"]) if accurate_enabled is not None and accurate_enabled != 0: JobMessage( - context, bJobMessageType["M_FATAL"], "start_backup_job: Accurate backup not allowed please disable in Job\n", ) @@ -134,13 +133,13 @@ def check_plugin_options(self, context, mandatory_options=None): else: return bRCs["bRC_OK"] - def create_file(self, context, restorepkt): + def create_file(self, restorepkt): """ On restore we create a subdirectory for the first base backup and each incremental backup. Because percona expects an empty directory, we create a tree starting with jobId/ of restore job """ FNAME = restorepkt.ofname - DebugMessage(context, 100, "create file with %s called\n" % FNAME) + DebugMessage(100, "create file with %s called\n" % FNAME) self.writeDir = "%s/%d/" % (os.path.dirname(FNAME), self.jobId) # FNAME contains originating jobId after last . origJobId = int(FNAME.rpartition(".")[-1]) @@ -152,7 +151,6 @@ def create_file(self, context, restorepkt): self.writeDir += "%010d" % origJobId else: JobMessage( - context, bJobMessageType["M_ERROR"], "No lsn information found in restore object for file %s from job %d\n" % (FNAME, origJobId), @@ -161,7 +159,6 @@ def create_file(self, context, restorepkt): # Create restore directory, if not existent if not os.path.exists(self.writeDir): bareosfd.DebugMessage( - context, 200, "Directory %s does not exist, creating it now\n" % self.writeDir, ) @@ -169,21 +166,19 @@ def create_file(self, context, restorepkt): # Percona requires empty directory if os.listdir(self.writeDir): JobMessage( - context, bJobMessageType["M_FATAL"], "Restore with xbstream needs empty directory: %s\n" % self.writeDir, ) return bRCs["bRC_Error"] self.restorecommand += self.writeDir DebugMessage( - context, 100, 'Restore using xbstream to extract files with "%s"\n' % self.restorecommand, ) restorepkt.create_status = bCFs["CF_EXTRACT"] return bRCs["bRC_OK"] - def start_backup_job(self, context): + def start_backup_job(self): """ We will check, if database has changed since last backup in the incremental case @@ -192,13 +187,12 @@ def start_backup_job(self, context): if check_option_bRC != bRCs["bRC_OK"]: return check_option_bRC bareosfd.DebugMessage( - context, 100, "start_backup_job, level: %s\n" % chr(self.level) + 100, "start_backup_job, level: %s\n" % chr(self.level) ) if chr(self.level) == "I": # We check, if we have a LSN received by restore object from previous job if self.max_to_lsn == 0: JobMessage( - context, bJobMessageType["M_FATAL"], "No LSN received to be used with incremental backup\n", ) @@ -209,10 +203,9 @@ def start_backup_job(self, context): import MySQLdb hasMySQLdbModule = True - bareosfd.DebugMessage(context, 100, "Imported module MySQLdb\n") + bareosfd.DebugMessage(100, "Imported module MySQLdb\n") except ImportError: bareosfd.DebugMessage( - context, 100, "Import of module MySQLdb failed. Using command pipe instead\n", ) @@ -225,7 +218,6 @@ def start_backup_job(self, context): result = cursor.fetchall() if len(result) == 0: JobMessage( - context, bJobMessageType["M_FATAL"], "Could not fetch SHOW ENGINE INNODB STATUS, unprivileged user?", ) @@ -237,7 +229,6 @@ def start_backup_job(self, context): last_lsn = int(line.split(" ")[-1]) except Exception as e: JobMessage( - context, bJobMessageType["M_FATAL"], "Could not get LSN, Error: %s" % e, ) @@ -256,7 +247,6 @@ def start_backup_job(self, context): (mysqlStdOut, mysqlStdErr) = last_lsn_proc.communicate() if returnCode != 0 or mysqlStdErr: JobMessage( - context, bJobMessageType["M_FATAL"], 'Could not get LSN with command "%s", Error: %s' % (get_lsn_command, mysqlStdErr), @@ -267,13 +257,12 @@ def start_backup_job(self, context): last_lsn = int(mysqlStdOut) except: JobMessage( - context, bJobMessageType["M_FATAL"], 'Error reading LSN: "%s" not an integer' % mysqlStdOut, ) return bRCs["bRC_Error"] JobMessage( - context, bJobMessageType["M_INFO"], "Backup until LSN: %d\n" % last_lsn + bJobMessageType["M_INFO"], "Backup until LSN: %d\n" % last_lsn ) if ( self.max_to_lsn > 0 @@ -281,7 +270,6 @@ def start_backup_job(self, context): and self.strictIncremental ): bareosfd.DebugMessage( - context, 100, "Last LSN of DB %d is not higher than LSN from previous job %d. Skipping this incremental backup\n" % (last_lsn, self.max_to_lsn), @@ -290,16 +278,16 @@ def start_backup_job(self, context): return bRCs["bRC_OK"] return bRCs["bRC_OK"] - def start_backup_file(self, context, savepkt): + def start_backup_file(self, savepkt): """ This method is called, when Bareos is ready to start backup a file """ if not self.files_to_backup: self.file_to_backup = None - DebugMessage(context, 100, "start_backup_file: None\n") + DebugMessage(100, "start_backup_file: None\n") else: self.file_to_backup = self.files_to_backup.pop() - DebugMessage(context, 100, "start_backup_file: %s\n" % self.file_to_backup) + DebugMessage(100, "start_backup_file: %s\n" % self.file_to_backup) statp = StatPacket() savepkt.statp = statp @@ -311,7 +299,7 @@ def start_backup_file(self, context, savepkt): if self.max_to_lsn > 0: self.dumpoptions += " --incremental-lsn=%d" % self.max_to_lsn self.dumpcommand = "%s %s" % (self.dumpbinary, self.dumpoptions) - DebugMessage(context, 100, "Dumper: '" + self.dumpcommand + "'\n") + DebugMessage(100, "Dumper: '" + self.dumpcommand + "'\n") elif self.file_to_backup == "lsnfile": # The restore object containing the log sequence number (lsn) # Read checkpoints and create restore object @@ -340,33 +328,30 @@ def start_backup_file(self, context, savepkt): else: # should not happen JobMessage( - context, bJobMessageType["M_FATAL"], "Unknown error. Don't know how to handle %s\n" % self.file_to_backup, ) JobMessage( - context, bJobMessageType["M_INFO"], "Starting backup of " + savepkt.fname + "\n", ) return bRCs["bRC_OK"] - def plugin_io(self, context, IOP): + def plugin_io(self, IOP): """ Called for io operations. We read from pipe into buffers or on restore send to xbstream """ - DebugMessage(context, 200, "plugin_io called with " + str(IOP.func) + "\n") + DebugMessage(200, "plugin_io called with " + str(IOP.func) + "\n") if IOP.func == bIOPS["IO_OPEN"]: - DebugMessage(context, 100, "plugin_io called with IO_OPEN\n") + DebugMessage(100, "plugin_io called with IO_OPEN\n") if self.log: try: self.err_fd = open(self.log, "a") except IOError as msg: DebugMessage( - context, 100, "Could not open log file (%s): %s\n" % (self.log, format(str(msg))), @@ -405,12 +390,12 @@ def plugin_io(self, context, IOP): except IOError as msg: IOP.io_errno = -1 DebugMessage( - context, 100, "Error writing data: " + format(str(msg)) + "\n" + 100, "Error writing data: " + format(str(msg)) + "\n" ) return bRCs["bRC_OK"] elif IOP.func == bIOPS["IO_CLOSE"]: - DebugMessage(context, 100, "plugin_io called with IO_CLOSE\n") + DebugMessage(100, "plugin_io called with IO_CLOSE\n") self.subprocess_returnCode = self.stream.poll() if self.subprocess_returnCode is None: # Subprocess is open, we wait until it finishes and get results @@ -419,7 +404,6 @@ def plugin_io(self, context, IOP): self.subprocess_returnCode = self.stream.poll() except: JobMessage( - context, bJobMessageType["M_ERROR"], "Dump / restore command not finished properly\n", ) @@ -427,7 +411,6 @@ def plugin_io(self, context, IOP): return bRCs["bRC_OK"] else: DebugMessage( - context, 100, "Subprocess has terminated with returncode: %d\n" % self.subprocess_returnCode, @@ -439,13 +422,12 @@ def plugin_io(self, context, IOP): else: DebugMessage( - context, 100, "plugin_io called with unsupported IOP:" + str(IOP.func) + "\n", ) return bRCs["bRC_OK"] - def end_backup_file(self, context): + def end_backup_file(self): """ Check if dump was successful. """ @@ -455,14 +437,12 @@ def end_backup_file(self, context): returnCode = self.subprocess_returnCode if returnCode is None: JobMessage( - context, bJobMessageType["M_ERROR"], "Dump command not finished properly for unknown reason\n", ) returnCode = -99 else: DebugMessage( - context, 100, "end_backup_file() entry point in Python called. Returncode: %d\n" % self.stream.returncode, @@ -475,7 +455,7 @@ def end_backup_file(self, context): if self.log: msg += ['log file: "%s"' % self.log] JobMessage( - context, bJobMessageType["M_FATAL"], ", ".join(msg) + "\n" + bJobMessageType["M_FATAL"], ", ".join(msg) + "\n" ) if returnCode != 0: return bRCs["bRC_Error"] @@ -492,21 +472,19 @@ def end_backup_file(self, context): else: return bRCs["bRC_OK"] - def end_restore_file(self, context): + def end_restore_file(self): """ Check if writing to restore command was successful. """ returnCode = self.subprocess_returnCode if returnCode is None: JobMessage( - context, bJobMessageType["M_ERROR"], "Restore command not finished properly for unknown reason\n", ) returnCode = -99 else: DebugMessage( - context, 100, "end_restore_file() entry point in Python called. Returncode: %d\n" % self.stream.returncode, @@ -515,7 +493,7 @@ def end_restore_file(self, context): msg = ["Restore command returned non-zero value: %d" % return_code] if self.log: msg += ['log file: "%s"' % self.log] - JobMessage(context, bJobMessageType["M_ERROR"], ", ".join(msg) + "\n") + JobMessage(bJobMessageType["M_ERROR"], ", ".join(msg) + "\n") if self.log: self.err_fd.write( "%s Restore Job %s closes stream\n" @@ -528,7 +506,7 @@ def end_restore_file(self, context): else: return bRCs["bRC_Error"] - def restore_object_data(self, context, ROP): + def restore_object_data(self, ROP): """ Called on restore and on diff/inc jobs. """ @@ -541,7 +519,6 @@ def restore_object_data(self, context, ROP): ): self.max_to_lsn = int(self.rop_data[ROP.jobid]["to_lsn"]) JobMessage( - context, bJobMessageType["M_INFO"], "Got to_lsn %d from restore object of job %d\n" % (self.max_to_lsn, ROP.jobid), diff --git a/core/src/plugins/filed/BareosFdWrapper.py b/core/src/plugins/filed/BareosFdWrapper.py index 7696864ac1f..a8832d0b3ae 100644 --- a/core/src/plugins/filed/BareosFdWrapper.py +++ b/core/src/plugins/filed/BareosFdWrapper.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # BAREOS - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2014-2014 Bareos GmbH & Co. KG +# Copyright (C) 2014-2020 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -30,65 +30,65 @@ bareos_fd_plugin_object = None -def parse_plugin_definition(context, plugindef): - return bareos_fd_plugin_object.parse_plugin_definition(context, plugindef) +def parse_plugin_definition(plugindef): + return bareos_fd_plugin_object.parse_plugin_definition(plugindef) -def handle_plugin_event(context, event): - return bareos_fd_plugin_object.handle_plugin_event(context, event) +def handle_plugin_event(event): + return bareos_fd_plugin_object.handle_plugin_event(event) -def start_backup_file(context, savepkt): - return bareos_fd_plugin_object.start_backup_file(context, savepkt) +def start_backup_file(savepkt): + return bareos_fd_plugin_object.start_backup_file(savepkt) -def end_backup_file(context): - return bareos_fd_plugin_object.end_backup_file(context) +def end_backup_file(): + return bareos_fd_plugin_object.end_backup_file() -def start_restore_file(context, cmd): - return bareos_fd_plugin_object.start_restore_file(context, cmd) +def start_restore_file(cmd): + return bareos_fd_plugin_object.start_restore_file(cmd) -def end_restore_file(context): - return bareos_fd_plugin_object.end_restore_file(context) +def end_restore_file(): + return bareos_fd_plugin_object.end_restore_file() -def restore_object_data(context, ROP): - return bareos_fd_plugin_object.restore_object_data(context, ROP) +def restore_object_data(ROP): + return bareos_fd_plugin_object.restore_object_data(ROP) -def plugin_io(context, IOP): - return bareos_fd_plugin_object.plugin_io(context, IOP) +def plugin_io(IOP): + return bareos_fd_plugin_object.plugin_io(IOP) -def create_file(context, restorepkt): - return bareos_fd_plugin_object.create_file(context, restorepkt) +def create_file(restorepkt): + return bareos_fd_plugin_object.create_file(restorepkt) -def set_file_attributes(context, restorepkt): - return bareos_fd_plugin_object.set_file_attributes(context, restorepkt) +def set_file_attributes(restorepkt): + return bareos_fd_plugin_object.set_file_attributes(restorepkt) -def check_file(context, fname): - return bareos_fd_plugin_object.check_file(context, fname) +def check_file(fname): + return bareos_fd_plugin_object.check_file(fname) -def get_acl(context, acl): - return bareos_fd_plugin_object.get_acl(context, acl) +def get_acl(acl): + return bareos_fd_plugin_object.get_acl(acl) -def set_acl(context, acl): - return bareos_fd_plugin_object.set_acl(context, acl) +def set_acl(acl): + return bareos_fd_plugin_object.set_acl(acl) -def get_xattr(context, xattr): - return bareos_fd_plugin_object.get_xattr(context, xattr) +def get_xattr(xattr): + return bareos_fd_plugin_object.get_xattr(xattr) -def set_xattr(context, xattr): - return bareos_fd_plugin_object.set_xattr(context, xattr) +def set_xattr(xattr): + return bareos_fd_plugin_object.set_xattr(xattr) -def handle_backup_file(context, savepkt): - return bareos_fd_plugin_object.handle_backup_file(context, savepkt) +def handle_backup_file(savepkt): + return bareos_fd_plugin_object.handle_backup_file(savepkt) diff --git a/core/src/plugins/filed/bareos-fd-ldap.py b/core/src/plugins/filed/bareos-fd-ldap.py index daad82680b2..249a7cee85c 100644 --- a/core/src/plugins/filed/bareos-fd-ldap.py +++ b/core/src/plugins/filed/bareos-fd-ldap.py @@ -39,13 +39,13 @@ import BareosFdPluginLDAP -def load_bareos_plugin(context, plugindef): +def load_bareos_plugin(plugindef): """ This function is called by the Bareos-FD to load the plugin We use it to intantiate the plugin class """ BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLDAP.BareosFdPluginLDAP( - context, plugindef + plugindef ) return bRCs["bRC_OK"] diff --git a/core/src/plugins/filed/bareos-fd-local-fileset.py b/core/src/plugins/filed/bareos-fd-local-fileset.py index 44d84a92d87..a8be185d9ec 100644 --- a/core/src/plugins/filed/bareos-fd-local-fileset.py +++ b/core/src/plugins/filed/bareos-fd-local-fileset.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # BAREOS - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2014-2014 Bareos GmbH & Co. KG +# Copyright (C) 2014-2020 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -40,7 +40,7 @@ import BareosFdPluginLocalFileset -def load_bareos_plugin(context, plugindef): +def load_bareos_plugin(plugindef): """ This function is called by the Bareos-FD to load the plugin We use it to instantiate the plugin class @@ -48,7 +48,7 @@ def load_bareos_plugin(context, plugindef): # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that # holds the plugin class object BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLocalFileset.BareosFdPluginLocalFileset( - context, plugindef + plugindef ) return bareos_fd_consts.bRCs["bRC_OK"] diff --git a/core/src/plugins/filed/bareos-fd-mock-test.py b/core/src/plugins/filed/bareos-fd-mock-test.py index 75ed350609d..6ce4702c079 100644 --- a/core/src/plugins/filed/bareos-fd-mock-test.py +++ b/core/src/plugins/filed/bareos-fd-mock-test.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # BAREOS - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2014-2014 Bareos GmbH & Co. KG +# Copyright (C) 2014-2020 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -34,12 +34,12 @@ import BareosFdPluginBaseclass -def load_bareos_plugin(context, plugindef): +def load_bareos_plugin(plugindef): bareosfd.DebugMessage( - context, 100, "------ Plugin loader called with " + plugindef + "\n" + 100, "------ Plugin loader called with " + plugindef + "\n" ) BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginBaseclass.BareosFdPluginBaseclass( - context, plugindef + plugindef ) return bareos_fd_consts.bRCs["bRC_OK"] diff --git a/core/src/plugins/filed/bareos-fd-ovirt.py b/core/src/plugins/filed/bareos-fd-ovirt.py index 12bcd9dc175..93a6fd4eae0 100644 --- a/core/src/plugins/filed/bareos-fd-ovirt.py +++ b/core/src/plugins/filed/bareos-fd-ovirt.py @@ -36,14 +36,14 @@ import BareosFdPluginOvirt -def load_bareos_plugin(context, plugindef): +def load_bareos_plugin(plugindef): """ This function is called by the Bareos-FD to load the plugin We use it to intantiate the plugin class """ # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that holds the plugin class object BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginOvirt.BareosFdPluginOvirt( - context, plugindef + plugindef ) return bRCs["bRC_OK"] diff --git a/core/src/plugins/filed/bareos-fd-percona-xtrabackup.py b/core/src/plugins/filed/bareos-fd-percona-xtrabackup.py index 6f5713b2e2f..9aa494f363e 100644 --- a/core/src/plugins/filed/bareos-fd-percona-xtrabackup.py +++ b/core/src/plugins/filed/bareos-fd-percona-xtrabackup.py @@ -30,13 +30,13 @@ from BareosFdPluginPerconaXtraBackup import * -def load_bareos_plugin(context, plugindef): +def load_bareos_plugin(plugindef): """ This function is called by the Bareos-FD to load the plugin We use it to instantiate the plugin class """ # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that holds the plugin class object - BareosFdWrapper.bareos_fd_plugin_object = BareosFdPercona(context, plugindef) + BareosFdWrapper.bareos_fd_plugin_object = BareosFdPercona(plugindef) return bRCs["bRC_OK"] diff --git a/core/src/plugins/filed/bareos-fd.py.template b/core/src/plugins/filed/bareos-fd.py.template index 5c1f2fdb5f3..37801d6576a 100644 --- a/core/src/plugins/filed/bareos-fd.py.template +++ b/core/src/plugins/filed/bareos-fd.py.template @@ -25,29 +25,29 @@ from io import open from os import O_WRONLY, O_CREAT -def load_bareos_plugin(context, plugindef): +def load_bareos_plugin(plugindef): DebugMessage( - context, 100, "load_bareos_plugin called with param: " + plugindef + "\n" + 100, "load_bareos_plugin called with param: " + plugindef + "\n" ) events = [] events.append(bEventType["bEventJobEnd"]) events.append(bEventType["bEventEndBackupJob"]) events.append(bEventType["bEventEndFileSet"]) events.append(bEventType["bEventHandleBackupFile"]) - RegisterEvents(context, events) - fdname = GetValue(context, bVariable["bVarFDName"]) - DebugMessage(context, 100, "FDName = " + fdname + "\n") - workingdir = GetValue(context, bVariable["bVarWorkingDir"]) - DebugMessage(context, 100, "WorkingDir = " + workingdir + "\n") + RegisterEvents(events) + fdname = GetValue(bVariable["bVarFDName"]) + DebugMessage(100, "FDName = " + fdname + "\n") + workingdir = GetValue(bVariable["bVarWorkingDir"]) + DebugMessage(100, "WorkingDir = " + workingdir + "\n") return bRCs["bRC_OK"] -def parse_plugin_definition(context, plugindef): +def parse_plugin_definition(plugindef): global file_to_backup DebugMessage( - context, 100, "parse_plugin_definition called with param: " + plugindef + "\n" + 100, "parse_plugin_definition called with param: " + plugindef + "\n" ) file_to_backup = "Unknown" plugin_options = plugindef.split(":") @@ -68,7 +68,6 @@ def parse_plugin_definition(context, plugindef): else: DebugMessage( - context, 100, "parse_plugin_definition unknown option " + key @@ -81,31 +80,30 @@ def parse_plugin_definition(context, plugindef): return bRCs["bRC_OK"] -def handle_plugin_event(context, event): +def handle_plugin_event(event): if event == bEventType["bEventJobEnd"]: - DebugMessage(context, 100, "handle_plugin_event called with bEventJobEnd\n") + DebugMessage(100, "handle_plugin_event called with bEventJobEnd\n") elif event == bEventType["bEventEndBackupJob"]: DebugMessage( - context, 100, "handle_plugin_event called with bEventEndBackupJob\n" + 100, "handle_plugin_event called with bEventEndBackupJob\n" ) elif event == bEventType["bEventEndFileSet"]: - DebugMessage(context, 100, "handle_plugin_event called with bEventEndFileSet\n") + DebugMessage(100, "handle_plugin_event called with bEventEndFileSet\n") else: DebugMessage( - context, 100, "handle_plugin_event called with event " + str(event) + "\n" + 100, "handle_plugin_event called with event " + str(event) + "\n" ) return bRCs["bRC_OK"] -def start_backup_file(context, savepkt): - DebugMessage(context, 100, "start_backup called\n") +def start_backup_file(savepkt): + DebugMessage(100, "start_backup called\n") if file_to_backup == "Unknown": JobMessage( - context, bJobMessageType["M_FATAL"], "No filename specified in plugin definition to backup\n", ) @@ -117,7 +115,6 @@ def start_backup_file(context, savepkt): savepkt.type = bFileType["FT_REG"] JobMessage( - context, bJobMessageType["M_INFO"], "Starting backup of " + file_to_backup + "\n", ) @@ -126,14 +123,14 @@ def start_backup_file(context, savepkt): def end_backup_file(context): - DebugMessage(context, 100, "end_backup_file() entry point in Python called\n") + DebugMessage(100, "end_backup_file() entry point in Python called\n") return bRCs["bRC_OK"] -def plugin_io(context, IOP): +def plugin_io(IOP): global file - DebugMessage(context, 100, "plugin_io called with " + str(IOP) + "\n") + DebugMessage(100, "plugin_io called with " + str(IOP) + "\n") FNAME = IOP.fname if IOP.func == bIOPS["IO_OPEN"]: @@ -167,9 +164,8 @@ def plugin_io(context, IOP): return bRCs["bRC_OK"] -def start_restore_file(context, cmd): +def start_restore_file(cmd): DebugMessage( - context, 100, "start_restore_file() entry point in Python called with " + str(cmd) + "\n", ) @@ -177,13 +173,12 @@ def start_restore_file(context, cmd): def end_restore_file(context): - DebugMessage(context, 100, "end_restore_file() entry point in Python called\n") + DebugMessage(100, "end_restore_file() entry point in Python called\n") return bRCs["bRC_OK"] -def create_file(context, restorepkt): +def create_file(restorepkt): DebugMessage( - context, 100, "create_file() entry point in Python called with " + str(restorepkt) + "\n", ) @@ -191,9 +186,8 @@ def create_file(context, restorepkt): return bRCs["bRC_OK"] -def set_file_attributes(context, restorepkt): +def set_file_attributes(restorepkt): DebugMessage( - context, 100, "set_file_attributes() entry point in Python called with " + str(restorepkt) @@ -202,54 +196,51 @@ def set_file_attributes(context, restorepkt): return bRCs["bRC_OK"] -def check_file(context, fname): +def check_file(fname): DebugMessage( - context, 100, "check_file() entry point in Python called with " + str(fname) + "\n", ) return bRCs["bRC_OK"] -def get_acl(context, acl): +def get_acl(acl): DebugMessage( - context, 100, "get_acl() entry point in Python called with " + str(acl) + "\n" + 100, "get_acl() entry point in Python called with " + str(acl) + "\n" ) return bRCs["bRC_OK"] -def set_acl(context, acl): +def set_acl(acl): DebugMessage( - context, 100, "set_acl() entry point in Python called with " + str(acl) + "\n" + 100, "set_acl() entry point in Python called with " + str(acl) + "\n" ) return bRCs["bRC_OK"] -def get_xattr(context, xattr): +def get_xattr(xattr): DebugMessage( - context, 100, "get_xattr() entry point in Python called with " + str(xattr) + "\n", ) return bRCs["bRC_OK"] -def set_xattr(context, xattr): +def set_xattr(xattr): DebugMessage( - context, 100, "set_xattr() entry point in Python called with " + str(xattr) + "\n", ) return bRCs["bRC_OK"] -def restore_object_data(context, restoreobject): +def restore_object_data(restoreobject): DebugMessage( - context, 100, "restore_object_data called with " + str(restoreobject) + "\n" + 100, "restore_object_data called with " + str(restoreobject) + "\n" ) return bRCs["bRC_OK"] -def handle_backup_file(context, savepkt): - DebugMessage(context, 100, "handle_backup_file called with " + str(savepkt) + "\n") +def handle_backup_file(savepkt): + DebugMessage(100, "handle_backup_file called with " + str(savepkt) + "\n") return bRCs["bRC_OK"] diff --git a/core/src/plugins/filed/decontext.sh b/core/src/plugins/filed/decontext.sh new file mode 100755 index 00000000000..0ba5de5edb1 --- /dev/null +++ b/core/src/plugins/filed/decontext.sh @@ -0,0 +1,7 @@ +#!/bin/bash +#remove all context calls from py files + +for i in *py*; do + #sed -i 's#context, ##g;s#, context##g;s#context,$##g' "$i"; + perl -i -p0e 's#context, ##g;s#, context##g;s#\n *context,##g' "$i"; +done diff --git a/core/src/plugins/filed/python-fd.cc b/core/src/plugins/filed/python-fd.cc index a766111aba6..33504d09bdc 100644 --- a/core/src/plugins/filed/python-fd.cc +++ b/core/src/plugins/filed/python-fd.cc @@ -226,26 +226,24 @@ bRC unloadPlugin() */ static bRC newPlugin(bpContext* bareos_plugin_ctx) { - struct plugin_private_context* plugin_priv_ctx; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)malloc( + sizeof(struct plugin_private_context)); - plugin_priv_ctx = (struct plugin_private_context*)malloc( - sizeof(struct plugin_private_context)); if (!plugin_priv_ctx) { return bRC_Error; } + memset(plugin_priv_ctx, 0, sizeof(struct plugin_private_context)); + bareos_plugin_ctx->pContext = (void*)plugin_priv_ctx; /* set our context pointer */ - /* - * For each plugin instance we instantiate a new Python interpreter. - */ + /* For each plugin instance we instantiate a new Python interpreter. */ PyEval_AcquireThread(mainThreadState); plugin_priv_ctx->interpreter = Py_NewInterpreter(); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - /* - * Always register some events the python plugin itself can register - * any other events it is interested in. - */ + /* Always register some events the python plugin itself can register + any other events it is interested in. */ bfuncs->registerBareosEvents( bareos_plugin_ctx, 9, bEventLevel, bEventSince, bEventNewPluginOptions, bEventPluginCommand, bEventJobStart, bEventRestoreCommand, @@ -1058,49 +1056,29 @@ static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, return bRC_Error; } -/** - * Work around API changes in Python versions. - * These function abstract the storage and retrieval of the bpContext - * which is passed to the Python methods and which the method can pass - * back and which allow the callback function to understand what bpContext - * its talking about. - */ -#if ((PY_VERSION_HEX < 0x02070000) || \ - ((PY_VERSION_HEX >= 0x03000000) && (PY_VERSION_HEX < 0x03010000))) -/** - * Python version before 2.7 and 3.0. - */ -static PyObject* PyCreatebpContext(bpContext* bareos_plugin_ctx) -{ - /* - * Setup a new CObject which holds the bpContext structure used here - * internally. - */ - return PyCObject_FromVoidPtr((void*)bareos_plugin_ctx, NULL); -} - -static bpContext* PyGetbpContext(PyObject* pyCtx) -{ - return (bpContext*)PyCObject_AsVoidPtr(pyCtx); -} -#else -/** - * Python version after 2.6 and 3.1. - */ static PyObject* PyCreatebpContext(bpContext* bareos_plugin_ctx) { /* * Setup a new Capsule which holds the bpContext structure used here * internally. */ + /* printf("PyCreatebpContext: bpContext is: %p\n", bareos_plugin_ctx); */ + /* Dmsg(bareos_plugin_ctx, 10, "PyGetbpContext: bpContext is: %p", */ + /* bareos_plugin_ctx); */ + /* Jmsg(bareos_plugin_ctx, M_INFO, "PyGetbpContext: bpContext is: %p", */ + /* bareos_plugin_ctx); */ return PyCapsule_New((void*)bareos_plugin_ctx, "bareos.bpContext", NULL); } -static bpContext* PyGetbpContext(PyObject* pyCtx) +static bpContext* PyGetbpContext() { - return (bpContext*)PyCapsule_GetPointer(pyCtx, "bareos.bpContext"); + bpContext** retval = (bpContext**)PyCapsule_Import("bareosfd.bpContext", 0); + + /* (bpContext*)PyCapsule_GetPointer(pyCtx, "bareos.bpContext"); */ + /* Dmsg(*retval, 10, "PyGetbpContext: bpContext is: %p\n", retval); */ + /* Jmsg(*retval, M_INFO, "PyGetbpContext: bpContext is: %p\n", retval); */ + return *retval; } -#endif /** * Convert a return value into a bRC enum value. @@ -1173,7 +1151,7 @@ static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype) /** * Initial load of the Python module. * - * Based on the parsed plugin options we set some prerequisits like the + * Based on the parsed plugin options we set some prerequisites like the * module path and the module to load. We also load the dictionary used * for looking up the Python methods. */ @@ -1184,13 +1162,9 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject *sysPath, *mPath, *pName, *pFunc; - /* - * See if we already setup the python search path. - */ + /* See if we already setup the python search path. */ if (!plugin_priv_ctx->python_path_set) { - /* - * Extend the Python search path with the given module_path. - */ + /* Extend the Python search path with the given module_path. */ if (plugin_priv_ctx->module_path) { sysPath = PySys_GetObject((char*)"path"); mPath = PyString_FromString(plugin_priv_ctx->module_path); @@ -1200,9 +1174,7 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) } } - /* - * Try to load the Python module by name. - */ + /* Try to load the Python module by name. */ if (plugin_priv_ctx->module_name) { Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: Trying to load module with name %s\n", @@ -1222,22 +1194,24 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) "python-fd: Successfully loaded module with name %s\n", plugin_priv_ctx->module_name); - /* - * Get the Python dictionary for lookups in the Python namespace. - */ + /* Get the Python dictionary for lookups in the Python namespace. */ plugin_priv_ctx->pyModuleFunctionsDict = PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ - /* - * Encode the bpContext so a Python method can pass it in on calling back. - */ + /* Encode the bpContext so a Python method can pass it in on calling back.*/ plugin_priv_ctx->py_bpContext = PyCreatebpContext(bareos_plugin_ctx); - void* ctx_from_bareosfd_module = PyCapsule_Import("bareosfd.bpContext", 0); + /* get the pointer to the module variable that is exported via the + * capsule + */ + bpContext** bareosfd_bpContext = + (bpContext**)PyCapsule_Import("bareosfd.bpContext", 0); - /* - * Lookup the load_bareos_plugin() function in the python module. + /* set the bareosfd.bpContext capsule pointer to point to bareos_plugin_ctx */ + *bareosfd_bpContext = bareos_plugin_ctx; + + /* Lookup the load_bareos_plugin() function in the python module. */ pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, "load_bareos_plugin"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { @@ -1246,8 +1220,8 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) pPluginDefinition = PyString_FromString((char*)value); if (!pPluginDefinition) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs( - pFunc, plugin_priv_ctx->py_bpContext, pPluginDefinition, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); + /* pFunc, plugin_priv_ctx->py_bpContext, pPluginDefinition, NULL); */ Py_DECREF(pPluginDefinition); if (!pRetVal) { @@ -1303,8 +1277,7 @@ static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) pPluginDefinition = PyString_FromString((char*)value); if (!pPluginDefinition) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, - pPluginDefinition, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); Py_DECREF(pPluginDefinition); if (!pRetVal) { @@ -1361,8 +1334,7 @@ static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, pEventType = PyInt_FromLong(event->eventType); - pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, - pEventType, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pEventType, NULL); Py_DECREF(pEventType); if (!pRetVal) { @@ -1636,8 +1608,7 @@ static bRC PyStartBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) pSavePkt = NativeToPySavePacket(sp); if (!pSavePkt) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, - (PyObject*)pSavePkt, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, (PyObject*)pSavePkt, NULL); if (!pRetVal) { Py_DECREF((PyObject*)pSavePkt); goto bail_out; @@ -1685,8 +1656,7 @@ static bRC PyEndBackupFile(bpContext* bareos_plugin_ctx) if (pFunc && PyCallable_Check(pFunc)) { PyObject* pRetVal; - pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, - NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, NULL); if (!pRetVal) { goto bail_out; } else { @@ -1799,8 +1769,7 @@ static bRC PyPluginIO(bpContext* bareos_plugin_ctx, struct io_pkt* io) pIoPkt = NativeToPyIoPacket(io); if (!pIoPkt) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, - (PyObject*)pIoPkt, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, (PyObject*)pIoPkt, NULL); if (!pRetVal) { Py_DECREF((PyObject*)pIoPkt); goto bail_out; @@ -1851,8 +1820,7 @@ static bRC PyStartRestoreFile(bpContext* bareos_plugin_ctx, const char* cmd) pCmd = PyString_FromString(cmd); if (!pCmd) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, - pCmd, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pCmd, NULL); Py_DECREF(pCmd); if (!pRetVal) { @@ -1892,8 +1860,7 @@ static bRC PyEndRestoreFile(bpContext* bareos_plugin_ctx) if (pFunc && PyCallable_Check(pFunc)) { PyObject* pRetVal; - pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, - NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, NULL); if (!pRetVal) { goto bail_out; } else { @@ -1980,8 +1947,7 @@ static bRC PyCreateFile(bpContext* bareos_plugin_ctx, struct restore_pkt* rp) pRestorePacket = NativeToPyRestorePacket(rp); if (!pRestorePacket) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, - pRestorePacket, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pRestorePacket, NULL); if (!pRetVal) { Py_DECREF(pRestorePacket); goto bail_out; @@ -2027,8 +1993,7 @@ static bRC PySetFileAttributes(bpContext* bareos_plugin_ctx, pRestorePacket = NativeToPyRestorePacket(rp); if (!pRestorePacket) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, - pRestorePacket, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pRestorePacket, NULL); if (!pRetVal) { Py_DECREF(pRestorePacket); goto bail_out; @@ -2068,8 +2033,7 @@ static bRC PyCheckFile(bpContext* bareos_plugin_ctx, char* fname) PyObject *pFname, *pRetVal; pFname = PyString_FromString(fname); - pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, - pFname, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pFname, NULL); Py_DECREF(pFname); if (!pRetVal) { @@ -2152,8 +2116,7 @@ static bRC PyGetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) pAclPkt = NativeToPyAclPacket(ap); if (!pAclPkt) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, - pAclPkt, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pAclPkt, NULL); if (!pRetVal) { Py_DECREF((PyObject*)pAclPkt); goto bail_out; @@ -2201,8 +2164,7 @@ static bRC PySetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) pAclPkt = NativeToPyAclPacket(ap); if (!pAclPkt) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, - pAclPkt, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pAclPkt, NULL); Py_DECREF(pAclPkt); if (!pRetVal) { @@ -2308,8 +2270,7 @@ static bRC PyGetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) pXattrPkt = NativeToPyXattrPacket(xp); if (!pXattrPkt) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, - pXattrPkt, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pXattrPkt, NULL); if (!pRetVal) { Py_DECREF((PyObject*)pXattrPkt); goto bail_out; @@ -2357,8 +2318,7 @@ static bRC PySetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) pXattrPkt = NativeToPyXattrPacket(xp); if (!pXattrPkt) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, - pXattrPkt, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pXattrPkt, NULL); Py_DECREF(pXattrPkt); if (!pRetVal) { @@ -2424,8 +2384,7 @@ static bRC PyRestoreObjectData(bpContext* bareos_plugin_ctx, pRestoreObject = NativeToPyRestoreObject(rop); if (!pRestoreObject) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, - pRestoreObject, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pRestoreObject, NULL); Py_DECREF(pRestoreObject); if (!pRetVal) { @@ -2468,8 +2427,7 @@ static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) pSavePkt = NativeToPySavePacket(sp); if (!pSavePkt) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, - pSavePkt, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pSavePkt, NULL); if (!pRetVal) { Py_DECREF((PyObject*)pSavePkt); goto bail_out; @@ -2504,12 +2462,10 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; bpContext* bareos_plugin_ctx = NULL; - PyObject* pyCtx; + PyObject* pRetVal = NULL; - if (!PyArg_ParseTuple(args, "Oi:BareosGetValue", &pyCtx, &var)) { - return NULL; - } + if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } switch (var) { case bVarFDName: @@ -2534,7 +2490,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarPrefixLinks: { int value = 0; - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (bVariable)var, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); @@ -2548,7 +2504,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarRegexWhere: { char* value = NULL; - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (bVariable)var, &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } @@ -2558,7 +2514,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarFileSeen: break; /* a write only variable, ignore read request */ default: - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: PyBareosGetValue unknown variable requested %d\n", var); break; @@ -2581,9 +2537,9 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) int var; bpContext* bareos_plugin_ctx = NULL; bRC retval = bRC_Error; - PyObject *pyCtx, *pyValue; + PyObject* pyValue; - if (!PyArg_ParseTuple(args, "OiO:BareosSetValue", &pyCtx, &var, &pyValue)) { + if (!PyArg_ParseTuple(args, "iO:BareosSetValue", &var, &pyValue)) { goto bail_out; } @@ -2611,7 +2567,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) break; } default: - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: PyBareosSetValue unknown variable requested %d\n", var); break; @@ -2631,15 +2587,13 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) int level; char* dbgmsg = NULL; bpContext* bareos_plugin_ctx; - PyObject* pyCtx; - if (!PyArg_ParseTuple(args, "Oi|z:BareosDebugMessage", &pyCtx, &level, - &dbgmsg)) { + if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; } if (dbgmsg) { - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); Dmsg(bareos_plugin_ctx, level, "python-fd: %s", dbgmsg); } @@ -2657,15 +2611,14 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) int type; char* jobmsg = NULL; bpContext* bareos_plugin_ctx; - PyObject* pyCtx; - if (!PyArg_ParseTuple(args, "Oi|z:BareosJobMessage", &pyCtx, &type, - &jobmsg)) { + + if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; } if (jobmsg) { - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); Jmsg(bareos_plugin_ctx, type, "python-fd: %s", jobmsg); } @@ -2683,9 +2636,9 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) int len, event; bpContext* bareos_plugin_ctx; bRC retval = bRC_Error; - PyObject *pyCtx, *pyEvents, *pySeq, *pyEvent; + PyObject *pyEvents, *pySeq, *pyEvent; - if (!PyArg_ParseTuple(args, "OO:BareosRegisterEvents", &pyCtx, &pyEvents)) { + if (!PyArg_ParseTuple(args, "O:BareosRegisterEvents", &pyEvents)) { goto bail_out; } @@ -2694,7 +2647,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); @@ -2724,9 +2677,9 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) int len, event; bpContext* bareos_plugin_ctx; bRC retval = bRC_Error; - PyObject *pyCtx, *pyEvents, *pySeq, *pyEvent; + PyObject *pyEvents, *pySeq, *pyEvent; - if (!PyArg_ParseTuple(args, "OO:BareosUnRegisterEvents", &pyCtx, &pyEvents)) { + if (!PyArg_ParseTuple(args, "O:BareosUnRegisterEvents", &pyEvents)) { goto bail_out; } @@ -2735,7 +2688,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); @@ -2762,14 +2715,12 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; bpContext* bareos_plugin_ctx = NULL; - PyObject* pyCtx; + PyObject* pRetVal = NULL; - if (!PyArg_ParseTuple(args, "O:BareosGetInstanceCount", &pyCtx)) { - return NULL; - } + if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); if (bfuncs->getInstanceCount(bareos_plugin_ctx, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } @@ -2790,15 +2741,13 @@ static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) { char* file = NULL; bpContext* bareos_plugin_ctx; - PyObject* pyCtx; + bRC retval = bRC_Error; - if (!PyArg_ParseTuple(args, "O|z:BareosAddExclude", &pyCtx, &file)) { - goto bail_out; - } + if (!PyArg_ParseTuple(args, "|z:BareosAddExclude", &file)) { goto bail_out; } if (file) { - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); retval = bfuncs->AddExclude(bareos_plugin_ctx, file); } @@ -2814,15 +2763,13 @@ static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) { char* file = NULL; bpContext* bareos_plugin_ctx; - PyObject* pyCtx; + bRC retval = bRC_Error; - if (!PyArg_ParseTuple(args, "O|z:BareosAddInclude", &pyCtx, &file)) { - goto bail_out; - } + if (!PyArg_ParseTuple(args, "|z:BareosAddInclude", &file)) { goto bail_out; } if (file) { - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); retval = bfuncs->AddInclude(bareos_plugin_ctx, file); } @@ -2838,15 +2785,13 @@ static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) { char* opts = NULL; bpContext* bareos_plugin_ctx; - PyObject* pyCtx; + bRC retval = bRC_Error; - if (!PyArg_ParseTuple(args, "O|z:BareosAddOptions", &pyCtx, &opts)) { - goto bail_out; - } + if (!PyArg_ParseTuple(args, "|z:BareosAddOptions", &opts)) { goto bail_out; } if (opts) { - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); retval = bfuncs->AddOptions(bareos_plugin_ctx, opts); } @@ -2863,15 +2808,15 @@ static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) int type; char* item = NULL; bpContext* bareos_plugin_ctx; - PyObject* pyCtx; + bRC retval = bRC_Error; - if (!PyArg_ParseTuple(args, "O|zi:BareosAddRegex", &pyCtx, &item, &type)) { + if (!PyArg_ParseTuple(args, "|zi:BareosAddRegex", &item, &type)) { goto bail_out; } if (item) { - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); retval = bfuncs->AddRegex(bareos_plugin_ctx, item, type); } @@ -2888,15 +2833,15 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) int type; char* item = NULL; bpContext* bareos_plugin_ctx; - PyObject* pyCtx; + bRC retval = bRC_Error; - if (!PyArg_ParseTuple(args, "O|zi:BareosAddWild", &pyCtx, &item, &type)) { + if (!PyArg_ParseTuple(args, "|zi:BareosAddWild", &item, &type)) { goto bail_out; } if (item) { - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); retval = bfuncs->AddWild(bareos_plugin_ctx, item, type); } @@ -2911,12 +2856,12 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) { bpContext* bareos_plugin_ctx; - PyObject* pyCtx; + bRC retval = bRC_Error; - if (!PyArg_ParseTuple(args, "O:BareosNewOptions", &pyCtx)) { goto bail_out; } + if (!PyArg_ParseTuple(args, ":BareosNewOptions")) { goto bail_out; } - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); retval = bfuncs->NewOptions(bareos_plugin_ctx); bail_out: @@ -2930,12 +2875,12 @@ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) { bpContext* bareos_plugin_ctx; - PyObject* pyCtx; + bRC retval = bRC_Error; - if (!PyArg_ParseTuple(args, "O:BareosNewInclude", &pyCtx)) { goto bail_out; } + if (!PyArg_ParseTuple(args, ":BareosNewInclude")) { goto bail_out; } - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); retval = bfuncs->NewInclude(bareos_plugin_ctx); bail_out: @@ -2949,14 +2894,12 @@ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) { bpContext* bareos_plugin_ctx; - PyObject* pyCtx; + bRC retval = bRC_Error; - if (!PyArg_ParseTuple(args, "O:BareosNewPreInclude", &pyCtx)) { - goto bail_out; - } + if (!PyArg_ParseTuple(args, ":BareosNewPreInclude")) { goto bail_out; } - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); retval = bfuncs->NewPreInclude(bareos_plugin_ctx); bail_out: @@ -2971,16 +2914,16 @@ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) { bpContext* bareos_plugin_ctx; - PyObject* pyCtx; + struct save_pkt sp; bRC retval = bRC_Error; PySavePacket* pSavePkt; - if (!PyArg_ParseTuple(args, "OO:BareosCheckChanges", &pyCtx, &pSavePkt)) { + if (!PyArg_ParseTuple(args, "O:BareosCheckChanges", &pSavePkt)) { goto bail_out; } - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); /* * CheckFile only has a need for a limited version of the PySavePacket so we @@ -3025,16 +2968,15 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) { bpContext* bareos_plugin_ctx; - PyObject* pyCtx; struct save_pkt sp; bRC retval = bRC_Error; PySavePacket* pSavePkt; - if (!PyArg_ParseTuple(args, "OO:BareosAcceptFile", &pyCtx, &pSavePkt)) { + if (!PyArg_ParseTuple(args, "O:BareosAcceptFile", &pSavePkt)) { goto bail_out; } - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); /* * Acceptfile only needs fname and statp from PySavePacket so we handle @@ -3072,14 +3014,13 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) bpContext* bareos_plugin_ctx; char* fname = NULL; bRC retval = bRC_Error; - PyObject *pyCtx, *pyBool; + PyObject* pyBool; - if (!PyArg_ParseTuple(args, "OO|s:BareosSetSeenBitmap", &pyCtx, &pyBool, - &fname)) { + if (!PyArg_ParseTuple(args, "O|s:BareosSetSeenBitmap", &pyBool, &fname)) { goto bail_out; } - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); all = PyObject_IsTrue(pyBool); retval = bfuncs->SetSeenBitmap(bareos_plugin_ctx, all, fname); @@ -3097,14 +3038,13 @@ static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) bpContext* bareos_plugin_ctx; char* fname = NULL; bRC retval = bRC_Error; - PyObject *pyCtx, *pyBool; + PyObject* pyBool; - if (!PyArg_ParseTuple(args, "OO|s:BareosClearSeenBitmap", &pyCtx, &pyBool, - &fname)) { + if (!PyArg_ParseTuple(args, "O|s:BareosClearSeenBitmap", &pyBool, &fname)) { goto bail_out; } - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); all = PyObject_IsTrue(pyBool); retval = bfuncs->ClearSeenBitmap(bareos_plugin_ctx, all, fname); diff --git a/core/src/plugins/filed/python-fd.h b/core/src/plugins/filed/python-fd.h index bec96231d0c..2f44c17756c 100644 --- a/core/src/plugins/filed/python-fd.h +++ b/core/src/plugins/filed/python-fd.h @@ -758,6 +758,7 @@ static PyMethodDef BareosFDMethods[] = { #define MOD_DEF(ob, name, doc, methods) ob = Py_InitModule3(name, methods, doc); #endif +static void* bareos_plugin_context = NULL; MOD_INIT(bareosfd) { @@ -766,13 +767,12 @@ MOD_INIT(bareosfd) * set after loading the bareosfd binary python module and will be used for * all calls. */ - static void* bareos_plugin_context = NULL; PyObject* BareosFdModule = NULL; /* Pointer Capsules to avoid context transfer back and forth */ PyObject* PyFdModulePluginContext = - PyCapsule_New((void*)&bareos_plugin_context, "bareosfd.bpContext", NULL); + PyCapsule_New((void*)&bareos_plugin_"bareosfd.bpContext", NULL); if (!PyFdModulePluginContext) { printf("python-fd.h: PyCapsule_New failed\n"); diff --git a/core/src/plugins/stored/BareosSdPluginBaseclass.py b/core/src/plugins/stored/BareosSdPluginBaseclass.py index 44c85f79e39..c862db234cb 100644 --- a/core/src/plugins/stored/BareosSdPluginBaseclass.py +++ b/core/src/plugins/stored/BareosSdPluginBaseclass.py @@ -33,23 +33,22 @@ class BareosSdPluginBaseclass(object): """ Bareos storage python plugin base class """ - def __init__(self, context, plugindef): + def __init__(self, plugindef): bareossd.DebugMessage( - context, 100, "Constructor called in module %s\n" % (__name__) + 100, "Constructor called in module %s\n" % (__name__) ) events = [] events.append(bsdEventType["bsdEventJobStart"]) events.append(bsdEventType["bsdEventJobEnd"]) - bareossd.RegisterEvents(context, events) + bareossd.RegisterEvents(events) # get some static Bareos values - self.jobName = bareossd.GetValue(context, bsdrVariable["bsdVarJobName"]) - self.jobLevel = chr(bareossd.GetValue(context, bsdrVariable["bsdVarLevel"])) - self.jobId = int(bareossd.GetValue(context, bsdrVariable["bsdVarJobId"])) + self.jobName = bareossd.GetValue(bsdrVariable["bsdVarJobName"]) + self.jobLevel = chr(bareossd.GetValue(bsdrVariable["bsdVarLevel"])) + self.jobId = int(bareossd.GetValue(bsdrVariable["bsdVarJobId"])) bareossd.DebugMessage( - context, 100, "JobName = %s - Level = %s - Id = %s - BareosSdPluginBaseclass\n" % (self.jobName, self.jobLevel, self.jobId), @@ -63,7 +62,7 @@ def __str__(self): self.jobLevel, ) - def parse_plugin_definition(self, context, plugindef): + def parse_plugin_definition(self, plugindef): """ Called with the plugin options from the bareos configfiles You should overload this method with your own and do option checking @@ -72,21 +71,21 @@ def parse_plugin_definition(self, context, plugindef): make sanity check on self.options afterwards """ bareossd.DebugMessage( - context, 100, "plugin def parser called with %s\n" % (plugindef) + 100, "plugin def parser called with %s\n" % (plugindef) ) # Parse plugin options into a dict self.options = dict() plugin_options = plugindef.split(":") for current_option in plugin_options: key, sep, val = current_option.partition("=") - bareossd.DebugMessage(context, 100, "key:val = %s:%s" % (key, val)) + bareossd.DebugMessage(100, "key:val = %s:%s" % (key, val)) if val == "": continue else: self.options[key] = val return bRCs["bRC_OK"] - def handle_plugin_event(self, context, event): + def handle_plugin_event(self, event): """ This method is called for each of the above registered events Overload this method to implement your actions for the events, @@ -96,7 +95,6 @@ def handle_plugin_event(self, context, event): if event == bsdEventType["bsdEventJobStart"]: self.jobStartTime = time.time() bareossd.DebugMessage( - context, 100, "bsdEventJobStart event triggered at Unix time %s\n" % (self.jobStartTime), @@ -105,22 +103,20 @@ def handle_plugin_event(self, context, event): elif event == bsdEventType["bsdEventJobEnd"]: self.jobEndTime = time.time() bareossd.DebugMessage( - context, 100, "bsdEventJobEnd event triggered at Unix time %s\n" % (self.jobEndTime), ) self.jobBytes = int( - bareossd.GetValue(context, bsdrVariable["bsdVarJobBytes"]) + bareossd.GetValue(bsdrVariable["bsdVarJobBytes"]) ) self.jobFiles = int( - bareossd.GetValue(context, bsdrVariable["bsdVarJobFiles"]) + bareossd.GetValue(bsdrVariable["bsdVarJobFiles"]) ) self.jobRunningTime = self.jobEndTime - self.jobStartTime self.throughput = 0 if self.jobRunningTime > 0: self.throughput = self.jobBytes / self.jobRunningTime bareossd.DebugMessage( - context, 100, "jobRunningTime: %s s, Throughput: %s Bytes/s\n" % (self.jobRunningTime, self.throughput), diff --git a/core/src/plugins/stored/BareosSdWrapper.py b/core/src/plugins/stored/BareosSdWrapper.py index 0aac65b9aa3..15ba0090cec 100644 --- a/core/src/plugins/stored/BareosSdWrapper.py +++ b/core/src/plugins/stored/BareosSdWrapper.py @@ -30,12 +30,12 @@ bareos_sd_plugin_object = None -def parse_plugin_definition(context, plugindef): - return bareos_sd_plugin_object.parse_plugin_definition(context, plugindef) +def parse_plugin_definition(plugindef): + return bareos_sd_plugin_object.parse_plugin_definition(plugindef) -def handle_plugin_event(context, event): - return bareos_sd_plugin_object.handle_plugin_event(context, event) +def handle_plugin_event(event): + return bareos_sd_plugin_object.handle_plugin_event(event) # vim: ts=4 tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/core/src/plugins/stored/bareos-sd-class-plugin.py b/core/src/plugins/stored/bareos-sd-class-plugin.py index 93731560c18..6377f49c627 100644 --- a/core/src/plugins/stored/bareos-sd-class-plugin.py +++ b/core/src/plugins/stored/bareos-sd-class-plugin.py @@ -37,7 +37,7 @@ import BareosSdPluginBaseclass -def load_bareos_plugin(context, plugindef): +def load_bareos_plugin(plugindef): """ This function is called by the Bareos-SD to load the plugin We use it to instantiate the plugin class @@ -45,7 +45,7 @@ def load_bareos_plugin(context, plugindef): # BareosSdWrapper.bareos_sd_plugin_object is the module attribute that # holds the plugin class object BareosSdWrapper.bareos_sd_plugin_object = BareosSdPluginBaseclass.BareosSdPluginBaseclass( - context, plugindef + plugindef ) return bareos_sd_consts.bRCs["bRC_OK"] diff --git a/core/src/plugins/stored/bareos-sd.py.template b/core/src/plugins/stored/bareos-sd.py.template index a7942742ef3..f4570da7dbc 100644 --- a/core/src/plugins/stored/bareos-sd.py.template +++ b/core/src/plugins/stored/bareos-sd.py.template @@ -23,20 +23,20 @@ from bareossd import * from bareos_sd_consts import * -def load_bareos_plugin(context, plugindef): +def load_bareos_plugin(plugindef): DebugMessage( - context, 100, "load_bareos_plugin called with param: " + plugindef + "\n" + 100, "load_bareos_plugin called with param: " + plugindef + "\n" ) events = [] events.append(bsdEventType["bsdEventJobStart"]) events.append(bsdEventType["bsdEventJobEnd"]) - RegisterEvents(context, events) + RegisterEvents(events) return bRCs["bRC_OK"] -def parse_plugin_definition(context, plugindef): +def parse_plugin_definition(plugindef): DebugMessage( - context, 100, "parse_plugin_definition called with param: " + plugindef + "\n" + 100, "parse_plugin_definition called with param: " + plugindef + "\n" ) plugin_options = plugindef.split(":") for current_option in plugin_options: @@ -55,7 +55,6 @@ def parse_plugin_definition(context, plugindef): else: DebugMessage( - context, 100, "parse_plugin_definition unknown option " + key @@ -68,15 +67,15 @@ def parse_plugin_definition(context, plugindef): return bRCs["bRC_OK"] -def handle_plugin_event(context, event): +def handle_plugin_event(event): if event == bsdEventType["bsdEventJobStart"]: - DebugMessage(context, 100, "bsdEventJobStart event triggered\n") - jobname = GetValue(context, bsdrVariable["bsdVarJobName"]) - DebugMessage(context, 100, "Job " + jobname + " starting\n") + DebugMessage(100, "bsdEventJobStart event triggered\n") + jobname = GetValue(bsdrVariable["bsdVarJobName"]) + DebugMessage(100, "Job " + jobname + " starting\n") elif event == bsdEventType["bsdEventJobEnd"]: - DebugMessage(context, 100, "bsdEventJobEnd event triggered\n") - jobname = GetValue(context, bsdrVariable["bsdVarJobName"]) - DebugMessage(context, 100, "Job " + jobname + " stopped\n") + DebugMessage(100, "bsdEventJobEnd event triggered\n") + jobname = GetValue(bsdrVariable["bsdVarJobName"]) + DebugMessage(100, "Job " + jobname + " stopped\n") return bRCs["bRC_OK"] diff --git a/systemtests/tests/dbcopy-mysql-postgresql/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py b/systemtests/tests/dbcopy-mysql-postgresql/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py index 7a5c2e5e7a4..fc9fcf1e11f 100644 --- a/systemtests/tests/dbcopy-mysql-postgresql/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py +++ b/systemtests/tests/dbcopy-mysql-postgresql/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py @@ -47,16 +47,15 @@ class BareosFdPluginLocalFilesetWithRestoreObjects( and compressed restore objects are tested. """ - def __init__(self, context, plugindef): + def __init__(self, plugindef): bareosfd.DebugMessage( - context, 100, "Constructor called in module %s with plugindef=%s\n" % (__name__, plugindef), ) # Last argument of super constructor is a list of mandatory arguments super(BareosFdPluginLocalFilesetWithRestoreObjects, self).__init__( - context, plugindef, ["filename"] + plugindef, ["filename"] ) self.files_to_backup = [] self.allow = None @@ -64,7 +63,7 @@ def __init__(self, context, plugindef): self.object_index_seq = int((time.time() - 1546297200) * 10) self.sha256sums_by_filename = {} - def filename_is_allowed(self, context, filename, allowregex, denyregex): + def filename_is_allowed(self, filename, allowregex, denyregex): """ Check, if filename is allowed. True, if matches allowreg and not denyregex. @@ -81,10 +80,9 @@ def filename_is_allowed(self, context, filename, allowregex, denyregex): denied = True if not allowed or denied: bareosfd.DebugMessage( - context, 100, "File %s denied by configuration\n" % (filename) + 100, "File %s denied by configuration\n" % (filename) ) bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "File %s denied by configuration\n" % (filename), ) @@ -92,7 +90,7 @@ def filename_is_allowed(self, context, filename, allowregex, denyregex): else: return True - def start_backup_job(self, context): + def start_backup_job(self): """ At this point, plugin options were passed and checked already. We try to read from filename and setup the list of file to backup @@ -100,7 +98,6 @@ def start_backup_job(self, context): """ bareosfd.DebugMessage( - context, 100, "Using %s to search for local files\n" % (self.options["filename"]), ) @@ -109,14 +106,13 @@ def start_backup_job(self, context): config_file = open(self.options["filename"], "rb") except: bareosfd.DebugMessage( - context, 100, "Could not open file %s\n" % (self.options["filename"]), ) return bRCs["bRC_Error"] else: bareosfd.DebugMessage( - context, 100, "File %s does not exist\n" % (self.options["filename"]) + 100, "File %s does not exist\n" % (self.options["filename"]) ) return bRCs["bRC_Error"] # Check, if we have allow or deny regular expressions defined @@ -127,14 +123,13 @@ def start_backup_job(self, context): for listItem in config_file.read().splitlines(): if os.path.isfile(listItem) and self.filename_is_allowed( - context, listItem, self.allow, self.deny + listItem, self.allow, self.deny ): self.files_to_backup.append(listItem) if os.path.isdir(listItem): for topdir, dirNames, fileNames in os.walk(listItem): for fileName in fileNames: if self.filename_is_allowed( - context, os.path.join(topdir, fileName), self.allow, self.deny, @@ -159,7 +154,6 @@ def start_backup_job(self, context): if not self.files_to_backup: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "No (allowed) files to backup found\n", ) @@ -167,24 +161,24 @@ def start_backup_job(self, context): else: return bRCs["bRC_Cancel"] - def start_backup_file(self, context, savepkt): + def start_backup_file(self, savepkt): """ Defines the file to backup and creates the savepkt. In this example only files (no directories) are allowed """ - bareosfd.DebugMessage(context, 100, "start_backup_file() called\n") + bareosfd.DebugMessage(100, "start_backup_file() called\n") if not self.files_to_backup: - bareosfd.DebugMessage(context, 100, "No files to backup\n") + bareosfd.DebugMessage(100, "No files to backup\n") return bRCs["bRC_Skip"] file_to_backup = self.files_to_backup.pop() - bareosfd.DebugMessage(context, 100, "file: " + file_to_backup + "\n") + bareosfd.DebugMessage(100, "file: " + file_to_backup + "\n") statp = bareosfd.StatPacket() savepkt.statp = statp if file_to_backup.endswith(".sha256sum"): - checksum = self.get_sha256sum(context, os.path.splitext(file_to_backup)[0]) + checksum = self.get_sha256sum(os.path.splitext(file_to_backup)[0]) savepkt.type = bFileType["FT_RESTORE_FIRST"] savepkt.fname = file_to_backup savepkt.object_name = file_to_backup @@ -217,28 +211,26 @@ def start_backup_file(self, context, savepkt): savepkt.type = bFileType["FT_REG"] bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], "Starting backup of %s\n" % (file_to_backup), ) return bRCs["bRC_OK"] - def end_backup_file(self, context): + def end_backup_file(self): """ Here we return 'bRC_More' as long as our list files_to_backup is not empty and bRC_OK when we are done """ bareosfd.DebugMessage( - context, 100, "end_backup_file() entry point in Python called\n" + 100, "end_backup_file() entry point in Python called\n" ) if self.files_to_backup: return bRCs["bRC_More"] else: return bRCs["bRC_OK"] - def set_file_attributes(self, context, restorepkt): + def set_file_attributes(self, restorepkt): bareosfd.DebugMessage( - context, 100, "set_file_attributes() entry point in Python called with %s\n" % (str(restorepkt)), @@ -247,16 +239,14 @@ def set_file_attributes(self, context, restorepkt): orig_fname = "/" + os.path.relpath(restorepkt.ofname, restorepkt.where) restoreobject_sha256sum = self.sha256sums_by_filename[orig_fname] - file_sha256sum = self.get_sha256sum(context, orig_fname) + file_sha256sum = self.get_sha256sum(orig_fname) bareosfd.DebugMessage( - context, 100, "set_file_attributes() orig_fname: %s restoreobject_sha256sum: %s file_sha256sum: %s\n" % (orig_fname, repr(restoreobject_sha256sum), repr(file_sha256sum)), ) if file_sha256sum != restoreobject_sha256sum: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "bad restoreobject orig_fname: %s restoreobject_sha256sum: %s file_sha256sum: %s\n" % (orig_fname, repr(restoreobject_sha256sum), repr(file_sha256sum)), @@ -264,13 +254,13 @@ def set_file_attributes(self, context, restorepkt): return bRCs["bRC_OK"] - def end_restore_file(self, context): + def end_restore_file(self): bareosfd.DebugMessage( - context, 100, "end_restore_file() self.FNAME: %s\n" % self.FNAME + 100, "end_restore_file() self.FNAME: %s\n" % self.FNAME ) return bRCs["bRC_OK"] - def restore_object_data(self, context, ROP): + def restore_object_data(self, ROP): """ Note: This is called in two cases: @@ -281,34 +271,29 @@ def restore_object_data(self, context, ROP): is "I" until the bEventStartBackupJob event """ bareosfd.DebugMessage( - context, 100, "BareosFdPluginLocalFilesetWithRestoreObjects:restore_object_data() called with ROP:%s\n" % (ROP), ) bareosfd.DebugMessage( - context, 100, "ROP.object_name(%s): %s\n" % (type(ROP.object_name), ROP.object_name), ) bareosfd.DebugMessage( - context, 100, "ROP.plugin_name(%s): %s\n" % (type(ROP.plugin_name), ROP.plugin_name), ) bareosfd.DebugMessage( - context, 100, "ROP.object_len(%s): %s\n" % (type(ROP.object_len), ROP.object_len), ) bareosfd.DebugMessage( - context, 100, "ROP.object_full_len(%s): %s\n" % (type(ROP.object_full_len), ROP.object_full_len), ) bareosfd.DebugMessage( - context, 100, "ROP.object(%s): %s\n" % (type(ROP.object), repr(ROP.object)) + 100, "ROP.object(%s): %s\n" % (type(ROP.object), repr(ROP.object)) ) orig_filename = os.path.splitext(ROP.object_name)[0] if ROP.object_name.endswith(".sha256sum"): @@ -316,7 +301,6 @@ def restore_object_data(self, context, ROP): elif ROP.object_name.endswith(".abspath"): if str(ROP.object) != orig_filename: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "bad restoreobject orig_fname: %s restoreobject_fname: %s\n" % (orig_filename, repr(str(ROP.object))), @@ -325,20 +309,18 @@ def restore_object_data(self, context, ROP): stored_length = int(os.path.splitext(ROP.object_name)[0]) if str(ROP.object) != "a" * stored_length: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "bad long restoreobject %s does not match stored object\n" % (ROP.object_name), ) else: bareosfd.DebugMessage( - context, 100, "not checking restoreobject: %s\n" % (type(ROP.object_name)), ) return bRCs["bRC_OK"] - def get_sha256sum(self, context, filename): + def get_sha256sum(self, filename): f = open(filename, "rb") m = hashlib.sha256() while True: diff --git a/systemtests/tests/dbcopy-mysql-postgresql/python-modules/bareos-fd-local-fileset-with-restoreobjects.py b/systemtests/tests/dbcopy-mysql-postgresql/python-modules/bareos-fd-local-fileset-with-restoreobjects.py index b64ef29960f..b03eb7013d8 100644 --- a/systemtests/tests/dbcopy-mysql-postgresql/python-modules/bareos-fd-local-fileset-with-restoreobjects.py +++ b/systemtests/tests/dbcopy-mysql-postgresql/python-modules/bareos-fd-local-fileset-with-restoreobjects.py @@ -43,7 +43,7 @@ import BareosFdPluginLocalFilesetWithRestoreObjects -def load_bareos_plugin(context, plugindef): +def load_bareos_plugin(plugindef): """ This function is called by the Bareos-FD to load the plugin We use it to instantiate the plugin class @@ -51,7 +51,7 @@ def load_bareos_plugin(context, plugindef): # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that # holds the plugin class object BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLocalFilesetWithRestoreObjects.BareosFdPluginLocalFilesetWithRestoreObjects( - context, plugindef + plugindef ) return bareos_fd_consts.bRCs["bRC_OK"] diff --git a/systemtests/tests/pyplug-dir/python-modules/bareos-dir-test.py b/systemtests/tests/pyplug-dir/python-modules/bareos-dir-test.py index e80f593378e..1d93545abbe 100644 --- a/systemtests/tests/pyplug-dir/python-modules/bareos-dir-test.py +++ b/systemtests/tests/pyplug-dir/python-modules/bareos-dir-test.py @@ -23,17 +23,17 @@ from bareos_dir_consts import * -def load_bareos_plugin(context, plugindef): +def load_bareos_plugin(plugindef): events = [] events.append(bDirEventType["bDirEventJobStart"]) events.append(bDirEventType["bDirEventJobEnd"]) events.append(bDirEventType["bDirEventJobInit"]) events.append(bDirEventType["bDirEventJobRun"]) - RegisterEvents(context, events) + RegisterEvents(events) return bRCs["bRC_OK"] -def parse_plugin_definition(context, plugindef): +def parse_plugin_definition(plugindef): plugin_options = plugindef.split(":") for current_option in plugin_options: key, sep, val = current_option.partition("=") @@ -56,7 +56,7 @@ def parse_plugin_definition(context, plugindef): return bRCs["bRC_OK"] -def handle_plugin_event(context, event): +def handle_plugin_event(event): if event == bDirEventType["bDirEventJobStart"]: toFile("bDirEventJobStart\n") diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py index 42509286683..554ff298e8c 100644 --- a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py +++ b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py @@ -47,16 +47,15 @@ class BareosFdPluginLocalFilesetWithRestoreObjects( and compressed restore objects are tested. """ - def __init__(self, context, plugindef): + def __init__(self, plugindef): bareosfd.DebugMessage( - context, 100, "Constructor called in module %s with plugindef=%s\n" % (__name__, plugindef), ) # Last argument of super constructor is a list of mandatory arguments super(BareosFdPluginLocalFilesetWithRestoreObjects, self).__init__( - context, plugindef, ["filename"] + plugindef, ["filename"] ) self.files_to_backup = [] self.allow = None @@ -73,7 +72,7 @@ def __init__(self, context, plugindef): ) - def filename_is_allowed(self, context, filename, allowregex, denyregex): + def filename_is_allowed(self, filename, allowregex, denyregex): """ Check, if filename is allowed. True, if matches allowreg and not denyregex. @@ -90,10 +89,9 @@ def filename_is_allowed(self, context, filename, allowregex, denyregex): denied = True if not allowed or denied: bareosfd.DebugMessage( - context, 100, "File %s denied by configuration\n" % (filename) + 100, "File %s denied by configuration\n" % (filename) ) bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "File %s denied by configuration\n" % (filename), ) @@ -101,7 +99,7 @@ def filename_is_allowed(self, context, filename, allowregex, denyregex): else: return True - def start_backup_job(self, context): + def start_backup_job(self): """ At this point, plugin options were passed and checked already. We try to read from filename and setup the list of file to backup @@ -109,7 +107,6 @@ def start_backup_job(self, context): """ bareosfd.DebugMessage( - context, 100, "Using %s to search for local files\n" % (self.options["filename"]), ) @@ -118,14 +115,13 @@ def start_backup_job(self, context): config_file = open(self.options["filename"], "rb") except: bareosfd.DebugMessage( - context, 100, "Could not open file %s\n" % (self.options["filename"]), ) return bRCs["bRC_Error"] else: bareosfd.DebugMessage( - context, 100, "File %s does not exist\n" % (self.options["filename"]) + 100, "File %s does not exist\n" % (self.options["filename"]) ) return bRCs["bRC_Error"] # Check, if we have allow or deny regular expressions defined @@ -136,14 +132,13 @@ def start_backup_job(self, context): for listItem in config_file.read().splitlines(): if os.path.isfile(listItem) and self.filename_is_allowed( - context, listItem, self.allow, self.deny + listItem, self.allow, self.deny ): self.files_to_backup.append(listItem) if os.path.isdir(listItem): for topdir, dirNames, fileNames in os.walk(listItem): for fileName in fileNames: if self.filename_is_allowed( - context, os.path.join(topdir, fileName), self.allow, self.deny, @@ -168,7 +163,6 @@ def start_backup_job(self, context): if not self.files_to_backup: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "No (allowed) files to backup found\n", ) @@ -176,24 +170,24 @@ def start_backup_job(self, context): else: return bRCs["bRC_Cancel"] - def start_backup_file(self, context, savepkt): + def start_backup_file(self, savepkt): """ Defines the file to backup and creates the savepkt. In this example only files (no directories) are allowed """ - bareosfd.DebugMessage(context, 100, "start_backup_file() called\n") + bareosfd.DebugMessage(100, "start_backup_file() called\n") if not self.files_to_backup: - bareosfd.DebugMessage(context, 100, "No files to backup\n") + bareosfd.DebugMessage(100, "No files to backup\n") return bRCs["bRC_Skip"] file_to_backup = self.files_to_backup.pop() - bareosfd.DebugMessage(context, 100, "file: " + file_to_backup + "\n") + bareosfd.DebugMessage(100, "file: " + file_to_backup + "\n") statp = bareosfd.StatPacket() savepkt.statp = statp if file_to_backup.endswith(".sha256sum"): - checksum = self.get_sha256sum(context, os.path.splitext(file_to_backup)[0]) + checksum = self.get_sha256sum(os.path.splitext(file_to_backup)[0]) savepkt.type = bFileType["FT_RESTORE_FIRST"] savepkt.fname = file_to_backup savepkt.object_name = file_to_backup @@ -226,28 +220,26 @@ def start_backup_file(self, context, savepkt): savepkt.type = bFileType["FT_REG"] bareosfd.JobMessage( - context, bJobMessageType["M_INFO"], "Starting backup of %s\n" % (file_to_backup), ) return bRCs["bRC_OK"] - def end_backup_file(self, context): + def end_backup_file(self): """ Here we return 'bRC_More' as long as our list files_to_backup is not empty and bRC_OK when we are done """ bareosfd.DebugMessage( - context, 100, "end_backup_file() entry point in Python called\n" + 100, "end_backup_file() entry point in Python called\n" ) if self.files_to_backup: return bRCs["bRC_More"] else: return bRCs["bRC_OK"] - def set_file_attributes(self, context, restorepkt): + def set_file_attributes(self, restorepkt): bareosfd.DebugMessage( - context, 100, "set_file_attributes() entry point in Python called with %s\n" % (str(restorepkt)), @@ -256,16 +248,14 @@ def set_file_attributes(self, context, restorepkt): orig_fname = "/" + os.path.relpath(restorepkt.ofname, restorepkt.where) restoreobject_sha256sum = self.sha256sums_by_filename[orig_fname] - file_sha256sum = self.get_sha256sum(context, orig_fname) + file_sha256sum = self.get_sha256sum(orig_fname) bareosfd.DebugMessage( - context, 100, "set_file_attributes() orig_fname: %s restoreobject_sha256sum: %s file_sha256sum: %s\n" % (orig_fname, repr(restoreobject_sha256sum), repr(file_sha256sum)), ) if file_sha256sum != restoreobject_sha256sum: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "bad restoreobject orig_fname: %s restoreobject_sha256sum: %s file_sha256sum: %s\n" % (orig_fname, repr(restoreobject_sha256sum), repr(file_sha256sum)), @@ -273,13 +263,13 @@ def set_file_attributes(self, context, restorepkt): return bRCs["bRC_OK"] - def end_restore_file(self, context): + def end_restore_file(self): bareosfd.DebugMessage( - context, 100, "end_restore_file() self.FNAME: %s\n" % self.FNAME + 100, "end_restore_file() self.FNAME: %s\n" % self.FNAME ) return bRCs["bRC_OK"] - def restore_object_data(self, context, ROP): + def restore_object_data(self, ROP): """ Note: This is called in two cases: @@ -290,34 +280,29 @@ def restore_object_data(self, context, ROP): is "I" until the bEventStartBackupJob event """ bareosfd.DebugMessage( - context, 100, "BareosFdPluginLocalFilesetWithRestoreObjects:restore_object_data() called with ROP:%s\n" % (ROP), ) bareosfd.DebugMessage( - context, 100, "ROP.object_name(%s): %s\n" % (type(ROP.object_name), ROP.object_name), ) bareosfd.DebugMessage( - context, 100, "ROP.plugin_name(%s): %s\n" % (type(ROP.plugin_name), ROP.plugin_name), ) bareosfd.DebugMessage( - context, 100, "ROP.object_len(%s): %s\n" % (type(ROP.object_len), ROP.object_len), ) bareosfd.DebugMessage( - context, 100, "ROP.object_full_len(%s): %s\n" % (type(ROP.object_full_len), ROP.object_full_len), ) bareosfd.DebugMessage( - context, 100, "ROP.object(%s): %s\n" % (type(ROP.object), repr(ROP.object)) + 100, "ROP.object(%s): %s\n" % (type(ROP.object), repr(ROP.object)) ) orig_filename = os.path.splitext(ROP.object_name)[0] if ROP.object_name.endswith(".sha256sum"): @@ -325,7 +310,6 @@ def restore_object_data(self, context, ROP): elif ROP.object_name.endswith(".abspath"): if str(ROP.object) != orig_filename: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "bad restoreobject orig_fname: %s restoreobject_fname: %s\n" % (orig_filename, repr(str(ROP.object))), @@ -334,20 +318,18 @@ def restore_object_data(self, context, ROP): stored_length = int(os.path.splitext(ROP.object_name)[0]) if str(ROP.object) != "a" * stored_length: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "bad long restoreobject %s does not match stored object\n" % (ROP.object_name), ) else: bareosfd.DebugMessage( - context, 100, "not checking restoreobject: %s\n" % (type(ROP.object_name)), ) return bRCs["bRC_OK"] - def get_sha256sum(self, context, filename): + def get_sha256sum(self, filename): f = open(filename, "rb") m = hashlib.sha256() while True: diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/bareos-fd-local-fileset-with-restoreobjects.py b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/bareos-fd-local-fileset-with-restoreobjects.py index b64ef29960f..b03eb7013d8 100644 --- a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/bareos-fd-local-fileset-with-restoreobjects.py +++ b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/bareos-fd-local-fileset-with-restoreobjects.py @@ -43,7 +43,7 @@ import BareosFdPluginLocalFilesetWithRestoreObjects -def load_bareos_plugin(context, plugindef): +def load_bareos_plugin(plugindef): """ This function is called by the Bareos-FD to load the plugin We use it to instantiate the plugin class @@ -51,7 +51,7 @@ def load_bareos_plugin(context, plugindef): # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that # holds the plugin class object BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLocalFilesetWithRestoreObjects.BareosFdPluginLocalFilesetWithRestoreObjects( - context, plugindef + plugindef ) return bareos_fd_consts.bRCs["bRC_OK"] diff --git a/systemtests/tests/pyplug-sd/python-modules/bareos-sd-test.py b/systemtests/tests/pyplug-sd/python-modules/bareos-sd-test.py index 34fb9bff3cc..09cbc024f2e 100644 --- a/systemtests/tests/pyplug-sd/python-modules/bareos-sd-test.py +++ b/systemtests/tests/pyplug-sd/python-modules/bareos-sd-test.py @@ -23,7 +23,7 @@ from bareos_sd_consts import * -def load_bareos_plugin(context, plugindef): +def load_bareos_plugin(plugindef): events = [] events.append(bsdEventType["bsdEventJobStart"]) events.append(bsdEventType["bsdEventDeviceReserve"]) @@ -39,11 +39,11 @@ def load_bareos_plugin(context, plugindef): events.append(bsdEventType["bsdEventDeviceUnmount"]) events.append(bsdEventType["bsdEventDeviceClose"]) events.append(bsdEventType["bsdEventJobEnd"]) - RegisterEvents(context, events) + RegisterEvents(events) return bRCs["bRC_OK"] -def parse_plugin_definition(context, plugindef): +def parse_plugin_definition(plugindef): plugin_options = plugindef.split(":") for current_option in plugin_options: key, sep, val = current_option.partition("=") @@ -66,7 +66,7 @@ def parse_plugin_definition(context, plugindef): return bRCs["bRC_OK"] -def handle_plugin_event(context, event): +def handle_plugin_event(event): if event == bsdEventType["bsdEventJobStart"]: toFile("bsdEventJobStart\n") elif event == bsdEventType["bsdEventDeviceReserve"]: From 16e94a5b2b71bae4a16d4e9926f53bc684336a64 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 29 Feb 2020 21:44:36 +0100 Subject: [PATCH 008/341] python-dir: rename variables --- core/src/plugins/dird/python-dir.cc | 368 +++++++++++++++------------- core/src/plugins/dird/python-dir.h | 21 +- 2 files changed, 212 insertions(+), 177 deletions(-) diff --git a/core/src/plugins/dird/python-dir.cc b/core/src/plugins/dird/python-dir.cc index 32268205668..859e6baba5e 100644 --- a/core/src/plugins/dird/python-dir.cc +++ b/core/src/plugins/dird/python-dir.cc @@ -63,21 +63,33 @@ static const int debuglevel = 150; bfuncs->JobMessage(context, __FILE__, __LINE__, type, 0, __VA_ARGS__) /* Forward referenced functions */ -static bRC newPlugin(bpContext* ctx); -static bRC freePlugin(bpContext* ctx); -static bRC getPluginValue(bpContext* ctx, pDirVariable var, void* value); -static bRC setPluginValue(bpContext* ctx, pDirVariable var, void* value); -static bRC handlePluginEvent(bpContext* ctx, bDirEvent* event, void* value); -static bRC parse_plugin_definition(bpContext* ctx, +static bRC newPlugin(bpContext* bareos_plugin_ctx); +static bRC freePlugin(bpContext* bareos_plugin_ctx); +static bRC getPluginValue(bpContext* bareos_plugin_ctx, + pDirVariable var, + void* value); +static bRC setPluginValue(bpContext* bareos_plugin_ctx, + pDirVariable var, + void* value); +static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, + bDirEvent* event, + void* value); +static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, void* value, PoolMem& plugin_options); -static void PyErrorHandler(bpContext* ctx, int msgtype); -static bRC PyLoadModule(bpContext* ctx, void* value); -static bRC PyParsePluginDefinition(bpContext* ctx, void* value); -static bRC PyGetPluginValue(bpContext* ctx, pDirVariable var, void* value); -static bRC PySetPluginValue(bpContext* ctx, pDirVariable var, void* value); -static bRC PyHandlePluginEvent(bpContext* ctx, bDirEvent* event, void* value); +static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype); +static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value); +static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value); +static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, + pDirVariable var, + void* value); +static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, + pDirVariable var, + void* value); +static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, + bDirEvent* event, + void* value); /* Pointers to Bareos functions */ static bDirFuncs* bfuncs = NULL; @@ -107,10 +119,10 @@ struct plugin_ctx { char* module_path; /* Plugin Module Path */ char* module_name; /* Plugin Module Name */ PyThreadState* - interpreter; /* Python interpreter for this instance of the plugin */ - PyObject* pModule; /* Python Module entry point */ - PyObject* pDict; /* Python Dictionary */ - PyObject* bpContext; /* Python representation of plugin context */ + interpreter; /* Python interpreter for this instance of the plugin */ + PyObject* pModule; /* Python Module entry point */ + PyObject* pyModuleFunctionsDict; /* Python Dictionary */ + PyObject* py_bpContext; /* Python representation of plugin context */ }; /** @@ -175,90 +187,102 @@ bRC unloadPlugin() } #endif -static bRC newPlugin(bpContext* ctx) +static bRC newPlugin(bpContext* bareos_plugin_ctx) { - struct plugin_ctx* p_ctx; + struct plugin_ctx* plugin_priv_ctx; - p_ctx = (struct plugin_ctx*)malloc(sizeof(struct plugin_ctx)); - if (!p_ctx) { return bRC_Error; } - memset(p_ctx, 0, sizeof(struct plugin_ctx)); - ctx->pContext = (void*)p_ctx; /* set our context pointer */ + plugin_priv_ctx = (struct plugin_ctx*)malloc(sizeof(struct plugin_ctx)); + if (!plugin_priv_ctx) { return bRC_Error; } + memset(plugin_priv_ctx, 0, sizeof(struct plugin_ctx)); + bareos_plugin_ctx->pContext = + (void*)plugin_priv_ctx; /* set our context pointer */ /* * For each plugin instance we instantiate a new Python interpreter. */ PyEval_AcquireThread(mainThreadState); - p_ctx->interpreter = Py_NewInterpreter(); - PyEval_ReleaseThread(p_ctx->interpreter); + plugin_priv_ctx->interpreter = Py_NewInterpreter(); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); /* * Always register some events the python plugin itself can register * any other events it is interested in. */ - bfuncs->registerBareosEvents(ctx, 1, bDirEventNewPluginOptions); + bfuncs->registerBareosEvents(bareos_plugin_ctx, 1, bDirEventNewPluginOptions); return bRC_OK; } -static bRC freePlugin(bpContext* ctx) +static bRC freePlugin(bpContext* bareos_plugin_ctx) { - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* plugin_priv_ctx = + (struct plugin_ctx*)bareos_plugin_ctx->pContext; - if (!p_ctx) { return bRC_Error; } + if (!plugin_priv_ctx) { return bRC_Error; } /* * Stop any sub interpreter started per plugin instance. */ - PyEval_AcquireThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); /* * Do python cleanup calls. */ - if (p_ctx->bpContext) { Py_DECREF(p_ctx->bpContext); } + if (plugin_priv_ctx->py_bpContext) { + Py_DECREF(plugin_priv_ctx->py_bpContext); + } - if (p_ctx->pModule) { Py_DECREF(p_ctx->pModule); } + if (plugin_priv_ctx->pModule) { Py_DECREF(plugin_priv_ctx->pModule); } - Py_EndInterpreter(p_ctx->interpreter); + Py_EndInterpreter(plugin_priv_ctx->interpreter); PyEval_ReleaseLock(); - free(p_ctx); - ctx->pContext = NULL; + free(plugin_priv_ctx); + bareos_plugin_ctx->pContext = NULL; return bRC_OK; } -static bRC getPluginValue(bpContext* ctx, pDirVariable var, void* value) +static bRC getPluginValue(bpContext* bareos_plugin_ctx, + pDirVariable var, + void* value) { - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* plugin_priv_ctx = + (struct plugin_ctx*)bareos_plugin_ctx->pContext; bRC retval = bRC_Error; - PyEval_AcquireThread(p_ctx->interpreter); - retval = PyGetPluginValue(ctx, var, value); - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyGetPluginValue(bareos_plugin_ctx, var, value); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); return retval; } -static bRC setPluginValue(bpContext* ctx, pDirVariable var, void* value) +static bRC setPluginValue(bpContext* bareos_plugin_ctx, + pDirVariable var, + void* value) { - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* plugin_priv_ctx = + (struct plugin_ctx*)bareos_plugin_ctx->pContext; bRC retval = bRC_Error; - PyEval_AcquireThread(p_ctx->interpreter); - retval = PySetPluginValue(ctx, var, value); - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PySetPluginValue(bareos_plugin_ctx, var, value); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); return retval; } -static bRC handlePluginEvent(bpContext* ctx, bDirEvent* event, void* value) +static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, + bDirEvent* event, + void* value) { bRC retval = bRC_Error; bool event_dispatched = false; PoolMem plugin_options(PM_FNAME); - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* plugin_priv_ctx = (plugin_ctx*)bareos_plugin_ctx->pContext; - if (!p_ctx) { goto bail_out; } + if (!plugin_priv_ctx) { goto bail_out; } /* * First handle some events internally before calling python if it @@ -267,7 +291,8 @@ static bRC handlePluginEvent(bpContext* ctx, bDirEvent* event, void* value) switch (event->eventType) { case bDirEventNewPluginOptions: event_dispatched = true; - retval = parse_plugin_definition(ctx, value, plugin_options); + retval = + parse_plugin_definition(bareos_plugin_ctx, value, plugin_options); break; default: break; @@ -280,7 +305,7 @@ static bRC handlePluginEvent(bpContext* ctx, bDirEvent* event, void* value) * processing was successful (e.g. retval == bRC_OK). */ if (!event_dispatched || retval == bRC_OK) { - PyEval_AcquireThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); /* * Now dispatch the event to Python. @@ -291,15 +316,16 @@ static bRC handlePluginEvent(bpContext* ctx, bDirEvent* event, void* value) /* * See if we already loaded the Python modules. */ - if (!p_ctx->python_loaded) { - retval = PyLoadModule(ctx, plugin_options.c_str()); + if (!plugin_priv_ctx->python_loaded) { + retval = PyLoadModule(bareos_plugin_ctx, plugin_options.c_str()); } /* * Only try to call when the loading succeeded. */ if (retval == bRC_OK) { - retval = PyParsePluginDefinition(ctx, plugin_options.c_str()); + retval = PyParsePluginDefinition(bareos_plugin_ctx, + plugin_options.c_str()); } break; default: @@ -308,15 +334,15 @@ static bRC handlePluginEvent(bpContext* ctx, bDirEvent* event, void* value) * We only try to call Python when we loaded the right module until * that time we pretend the call succeeded. */ - if (p_ctx->python_loaded) { - retval = PyHandlePluginEvent(ctx, event, value); + if (plugin_priv_ctx->python_loaded) { + retval = PyHandlePluginEvent(bareos_plugin_ctx, event, value); } else { retval = bRC_OK; } break; } - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); } bail_out: @@ -384,7 +410,7 @@ static inline void SetString(char** destination, char* value) * * python:module_path=:module_name=:... */ -static bRC parse_plugin_definition(bpContext* ctx, +static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, void* value, PoolMem& plugin_options) { @@ -392,7 +418,7 @@ static bRC parse_plugin_definition(bpContext* ctx, int i, cnt; PoolMem plugin_definition(PM_FNAME); char *bp, *argument, *argument_value; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* plugin_priv_ctx = (plugin_ctx*)bareos_plugin_ctx->pContext; if (!value) { return bRC_Error; } @@ -404,9 +430,11 @@ static bRC parse_plugin_definition(bpContext* ctx, bp = strchr(plugin_definition.c_str(), ':'); if (!bp) { - Jmsg(ctx, M_FATAL, "python-dir: Illegal plugin definition %s\n", + Jmsg(bareos_plugin_ctx, M_FATAL, + "python-dir: Illegal plugin definition %s\n", plugin_definition.c_str()); - Dmsg(ctx, debuglevel, "python-dir: Illegal plugin definition %s\n", + Dmsg(bareos_plugin_ctx, debuglevel, + "python-dir: Illegal plugin definition %s\n", plugin_definition.c_str()); goto bail_out; } @@ -430,10 +458,10 @@ static bRC parse_plugin_definition(bpContext* ctx, argument = bp; argument_value = strchr(bp, '='); if (!argument_value) { - Jmsg(ctx, M_FATAL, "python-dir: Illegal argument %s without value\n", - argument); - Dmsg(ctx, debuglevel, "python-dir: Illegal argument %s without value\n", - argument); + Jmsg(bareos_plugin_ctx, M_FATAL, + "python-dir: Illegal argument %s without value\n", argument); + Dmsg(bareos_plugin_ctx, debuglevel, + "python-dir: Illegal argument %s without value\n", argument); goto bail_out; } *argument_value++ = '\0'; @@ -463,13 +491,13 @@ static bRC parse_plugin_definition(bpContext* ctx, switch (plugin_arguments[i].type) { case argument_instance: - int_destination = &p_ctx->instance; + int_destination = &plugin_priv_ctx->instance; break; case argument_module_path: - str_destination = &p_ctx->module_path; + str_destination = &plugin_priv_ctx->module_path; break; case argument_module_name: - str_destination = &p_ctx->module_name; + str_destination = &plugin_priv_ctx->module_name; break; default: break; @@ -518,49 +546,18 @@ static bRC parse_plugin_definition(bpContext* ctx, return bRC_Error; } -/** - * Work around API changes in Python versions. - * These function abstract the storage and retrieval of the bpContext - * which is passed to the Python methods and which the method can pass - * back and which allow the callback function to understand what bpContext - * its talking about. - */ -#if ((PY_VERSION_HEX < 0x02070000) || \ - ((PY_VERSION_HEX >= 0x03000000) && (PY_VERSION_HEX < 0x03010000))) -/** - * Python version before 2.7 and 3.0. - */ -static PyObject* PyCreatebpContext(bpContext* ctx) -{ - /* - * Setup a new CObject which holds the bpContext structure used here - * internally. - */ - return PyCObject_FromVoidPtr((void*)ctx, NULL); -} - -static bpContext* PyGetbpContext(PyObject* pyCtx) -{ - return (bpContext*)PyCObject_AsVoidPtr(pyCtx); -} -#else /** * Python version after 2.6 and 3.1. */ -static PyObject* PyCreatebpContext(bpContext* ctx) +static PyObject* PyCreatebpContext(bpContext* bareos_plugin_ctx) { - /* - * Setup a new Capsule which holds the bpContext structure used here - * internally. - */ - return PyCapsule_New((void*)ctx, "bareos.bpContext", NULL); + return PyCapsule_New((void*)bareos_plugin_ctx, "bareos.bpContext", NULL); } static bpContext* PyGetbpContext(PyObject* pyCtx) { return (bpContext*)PyCapsule_GetPointer(pyCtx, "bareos.bpContext"); } -#endif /** * Convert a return value into a bRC enum value. @@ -587,7 +584,7 @@ static inline PyObject* conv_retval_python(bRC retval) * return "".join(traceback.format_exception(sys.exc_type, * sys.exc_value, sys.exc_traceback)) */ -static void PyErrorHandler(bpContext* ctx, int msgtype) +static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype) { PyObject *type, *value, *traceback; PyObject* tracebackModule; @@ -622,8 +619,10 @@ static void PyErrorHandler(bpContext* ctx, int msgtype) Py_XDECREF(value); Py_XDECREF(traceback); - Dmsg(ctx, debuglevel, "python-dir: %s\n", error_string); - if (msgtype) { Jmsg(ctx, msgtype, "python-dir: %s\n", error_string); } + Dmsg(bareos_plugin_ctx, debuglevel, "python-dir: %s\n", error_string); + if (msgtype) { + Jmsg(bareos_plugin_ctx, msgtype, "python-dir: %s\n", error_string); + } free(error_string); } @@ -635,62 +634,66 @@ static void PyErrorHandler(bpContext* ctx, int msgtype) * module path and the module to load. We also load the dictionary used * for looking up the Python methods. */ -static bRC PyLoadModule(bpContext* ctx, void* value) +static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* plugin_priv_ctx = + (struct plugin_ctx*)bareos_plugin_ctx->pContext; PyObject *sysPath, *mPath, *pName, *pFunc; /* * See if we already setup the python search path. */ - if (!p_ctx->python_path_set) { + if (!plugin_priv_ctx->python_path_set) { /* * Extend the Python search path with the given module_path. */ - if (p_ctx->module_path) { + if (plugin_priv_ctx->module_path) { sysPath = PySys_GetObject((char*)"path"); - mPath = PyString_FromString(p_ctx->module_path); + mPath = PyString_FromString(plugin_priv_ctx->module_path); PyList_Append(sysPath, mPath); Py_DECREF(mPath); - p_ctx->python_path_set = true; + plugin_priv_ctx->python_path_set = true; } } /* * Try to load the Python module by name. */ - if (p_ctx->module_name) { - Dmsg(ctx, debuglevel, "python-dir: Trying to load module with name %s\n", - p_ctx->module_name); - pName = PyString_FromString(p_ctx->module_name); - p_ctx->pModule = PyImport_Import(pName); + if (plugin_priv_ctx->module_name) { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-dir: Trying to load module with name %s\n", + plugin_priv_ctx->module_name); + pName = PyString_FromString(plugin_priv_ctx->module_name); + plugin_priv_ctx->pModule = PyImport_Import(pName); Py_DECREF(pName); - if (!p_ctx->pModule) { - Dmsg(ctx, debuglevel, "python-dir: Failed to load module with name %s\n", - p_ctx->module_name); + if (!plugin_priv_ctx->pModule) { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-dir: Failed to load module with name %s\n", + plugin_priv_ctx->module_name); goto bail_out; } - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-dir: Successfully loaded module with name %s\n", - p_ctx->module_name); + plugin_priv_ctx->module_name); /* * Get the Python dictionary for lookups in the Python namespace. */ - p_ctx->pDict = PyModule_GetDict(p_ctx->pModule); /* Borrowed reference */ + plugin_priv_ctx->pyModuleFunctionsDict = + PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ /* * Encode the bpContext so a Python method can pass it in on calling back. */ - p_ctx->bpContext = PyCreatebpContext(ctx); + plugin_priv_ctx->py_bpContext = PyCreatebpContext(bareos_plugin_ctx); /* * Lookup the load_bareos_plugin() function in the python module. */ - pFunc = PyDict_GetItemString(p_ctx->pDict, + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, "load_bareos_plugin"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyObject *pPluginDefinition, *pRetVal; @@ -698,8 +701,8 @@ static bRC PyLoadModule(bpContext* ctx, void* value) pPluginDefinition = PyString_FromString((char*)value); if (!pPluginDefinition) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, - pPluginDefinition, NULL); + pRetVal = PyObject_CallFunctionObjArgs( + pFunc, plugin_priv_ctx->py_bpContext, pPluginDefinition, NULL); Py_DECREF(pPluginDefinition); if (!pRetVal) { @@ -709,7 +712,7 @@ static bRC PyLoadModule(bpContext* ctx, void* value) Py_DECREF(pRetVal); } } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-dir: Failed to find function named load_bareos_plugins()\n"); goto bail_out; } @@ -717,13 +720,13 @@ static bRC PyLoadModule(bpContext* ctx, void* value) /* * Keep track we successfully loaded. */ - p_ctx->python_loaded = true; + plugin_priv_ctx->python_loaded = true; } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } @@ -734,24 +737,26 @@ static bRC PyLoadModule(bpContext* ctx, void* value) * PyLoadModule() has loaded the Python module and made sure things are * operational. */ -static bRC PyParsePluginDefinition(bpContext* ctx, void* value) +static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* plugin_priv_ctx = + (struct plugin_ctx*)bareos_plugin_ctx->pContext; PyObject* pFunc; /* * Lookup the parse_plugin_definition() function in the python module. */ - pFunc = PyDict_GetItemString( - p_ctx->pDict, "parse_plugin_definition"); /* Borrowed reference */ + pFunc = + PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "parse_plugin_definition"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyObject *pPluginDefinition, *pRetVal; pPluginDefinition = PyString_FromString((char*)value); if (!pPluginDefinition) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, + pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, pPluginDefinition, NULL); Py_DECREF(pPluginDefinition); @@ -764,46 +769,52 @@ static bRC PyParsePluginDefinition(bpContext* ctx, void* value) return retval; } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-dir: Failed to find function named " "parse_plugin_definition()\n"); return bRC_Error; } bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } -static bRC PyGetPluginValue(bpContext* ctx, pDirVariable var, void* value) +static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, + pDirVariable var, + void* value) { return bRC_OK; } -static bRC PySetPluginValue(bpContext* ctx, pDirVariable var, void* value) +static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, + pDirVariable var, + void* value) { return bRC_OK; } -static bRC PyHandlePluginEvent(bpContext* ctx, bDirEvent* event, void* value) +static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, + bDirEvent* event, + void* value) { bRC retval = bRC_Error; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* plugin_priv_ctx = (plugin_ctx*)bareos_plugin_ctx->pContext; PyObject* pFunc; /* * Lookup the handle_plugin_event() function in the python module. */ - pFunc = PyDict_GetItemString(p_ctx->pDict, + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, "handle_plugin_event"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyObject *pEventType, *pRetVal; pEventType = PyInt_FromLong(event->eventType); - pRetVal = - PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, pEventType, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, + pEventType, NULL); Py_DECREF(pEventType); if (!pRetVal) { @@ -813,14 +824,14 @@ static bRC PyHandlePluginEvent(bpContext* ctx, bDirEvent* event, void* value) Py_DECREF(pRetVal); } } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-dir: Failed to find function named handle_plugin_event()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } @@ -832,7 +843,7 @@ static bRC PyHandlePluginEvent(bpContext* ctx, bDirEvent* event, void* value) static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - bpContext* ctx = NULL; + bpContext* bareos_plugin_ctx = NULL; PyObject* pyCtx; PyObject* pRetVal = NULL; @@ -851,8 +862,9 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarSDJobStatus: { int value = 0; - ctx = PyGetbpContext(pyCtx); - if (bfuncs->getBareosValue(ctx, (brDirVariable)var, &value) == bRC_OK) { + bareos_plugin_ctx = PyGetbpContext(pyCtx); + if (bfuncs->getBareosValue(bareos_plugin_ctx, (brDirVariable)var, + &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } break; @@ -866,8 +878,9 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarReadBytes: { uint64_t value = 0; - ctx = PyGetbpContext(pyCtx); - if (bfuncs->getBareosValue(ctx, (brDirVariable)var, &value) == bRC_OK) { + bareos_plugin_ctx = PyGetbpContext(pyCtx); + if (bfuncs->getBareosValue(bareos_plugin_ctx, (brDirVariable)var, + &value) == bRC_OK) { pRetVal = PyLong_FromUnsignedLong(value); } break; @@ -884,8 +897,9 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarVolumeName: { char* value = NULL; - ctx = PyGetbpContext(pyCtx); - if (bfuncs->getBareosValue(ctx, (brDirVariable)var, &value) == bRC_OK) { + bareos_plugin_ctx = PyGetbpContext(pyCtx); + if (bfuncs->getBareosValue(bareos_plugin_ctx, (brDirVariable)var, + &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } } break; @@ -899,8 +913,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) break; } default: - ctx = PyGetbpContext(pyCtx); - Dmsg(ctx, debuglevel, + bareos_plugin_ctx = PyGetbpContext(pyCtx); + Dmsg(bareos_plugin_ctx, debuglevel, "python-dir: PyBareosGetValue unknown variable requested %d\n", var); break; } @@ -920,7 +934,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - bpContext* ctx = NULL; + bpContext* bareos_plugin_ctx = NULL; bRC retval = bRC_Error; PyObject *pyCtx, *pyValue; @@ -932,10 +946,11 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bwDirVarVolumeName: { char* value; - ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(pyCtx); value = PyString_AsString(pyValue); if (value) { - retval = bfuncs->setBareosValue(ctx, (bwDirVariable)var, value); + retval = bfuncs->setBareosValue(bareos_plugin_ctx, (bwDirVariable)var, + value); } break; @@ -944,16 +959,17 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bwDirVarJobLevel: { int value; - ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(pyCtx); value = PyInt_AsLong(pyValue); if (value >= 0) { - retval = bfuncs->setBareosValue(ctx, (bwDirVariable)var, &value); + retval = bfuncs->setBareosValue(bareos_plugin_ctx, (bwDirVariable)var, + &value); } break; } default: - ctx = PyGetbpContext(pyCtx); - Dmsg(ctx, debuglevel, + bareos_plugin_ctx = PyGetbpContext(pyCtx); + Dmsg(bareos_plugin_ctx, debuglevel, "python-dir: PyBareosSetValue unknown variable requested %d\n", var); break; } @@ -971,7 +987,7 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - bpContext* ctx; + bpContext* bareos_plugin_ctx; PyObject* pyCtx; if (!PyArg_ParseTuple(args, "Oi|z:BareosDebugMessage", &pyCtx, &level, @@ -980,8 +996,8 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) } if (dbgmsg) { - ctx = PyGetbpContext(pyCtx); - Dmsg(ctx, level, "python-dir: %s", dbgmsg); + bareos_plugin_ctx = PyGetbpContext(pyCtx); + Dmsg(bareos_plugin_ctx, level, "python-dir: %s", dbgmsg); } Py_INCREF(Py_None); @@ -997,7 +1013,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - bpContext* ctx; + bpContext* bareos_plugin_ctx; PyObject* pyCtx; if (!PyArg_ParseTuple(args, "Oi|z:BareosJobMessage", &pyCtx, &type, @@ -1006,8 +1022,8 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) } if (jobmsg) { - ctx = PyGetbpContext(pyCtx); - Jmsg(ctx, type, "python-dir: %s", jobmsg); + bareos_plugin_ctx = PyGetbpContext(pyCtx); + Jmsg(bareos_plugin_ctx, type, "python-dir: %s", jobmsg); } Py_INCREF(Py_None); @@ -1022,7 +1038,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* ctx; + bpContext* bareos_plugin_ctx; bRC retval = bRC_Error; PyObject *pyCtx, *pyEvents, *pySeq, *pyEvent; @@ -1035,15 +1051,15 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(pyCtx); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-dir: PyBareosRegisterEvents registering event %d\n", event); - retval = bfuncs->registerBareosEvents(ctx, 1, event); + retval = bfuncs->registerBareosEvents(bareos_plugin_ctx, 1, event); if (retval != bRC_OK) { break; } } @@ -1063,7 +1079,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* ctx; + bpContext* bareos_plugin_ctx; bRC retval = bRC_Error; PyObject *pyCtx, *pyEvents, *pySeq, *pyEvent; @@ -1076,15 +1092,15 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(pyCtx); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { - Dmsg(ctx, debuglevel, "PyBareosUnRegisterEvents: registering event %d\n", - event); - retval = bfuncs->unregisterBareosEvents(ctx, 1, event); + Dmsg(bareos_plugin_ctx, debuglevel, + "PyBareosUnRegisterEvents: registering event %d\n", event); + retval = bfuncs->unregisterBareosEvents(bareos_plugin_ctx, 1, event); if (retval != bRC_OK) { break; } } @@ -1104,7 +1120,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - bpContext* ctx = NULL; + bpContext* bareos_plugin_ctx = NULL; PyObject* pyCtx; PyObject* pRetVal = NULL; @@ -1112,8 +1128,8 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) return NULL; } - ctx = PyGetbpContext(pyCtx); - if (bfuncs->getInstanceCount(ctx, &value) == bRC_OK) { + bareos_plugin_ctx = PyGetbpContext(pyCtx); + if (bfuncs->getInstanceCount(bareos_plugin_ctx, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } diff --git a/core/src/plugins/dird/python-dir.h b/core/src/plugins/dird/python-dir.h index 397e86cdbbe..ff4591be7c0 100644 --- a/core/src/plugins/dird/python-dir.h +++ b/core/src/plugins/dird/python-dir.h @@ -92,11 +92,30 @@ static PyMethodDef BareosDIRMethods[] = { #define MOD_DEF(ob, name, doc, methods) ob = Py_InitModule3(name, methods, doc); #endif +static void* bareos_plugin_context = NULL; MOD_INIT(bareosdir) { - PyObject* BareosDirModule; + PyObject* BareosDirModule = NULL; + + /* Pointer Capsules to avoid context transfer back and forth */ + PyObject* PyDirModulePluginContext = + PyCapsule_New((void*)&bareos_plugin_context, "bareosdir.bpContext", NULL); + + if (!PyDirModulePluginContext) { + printf("python-dir.h: PyCapsule_New failed\n"); + return MOD_ERROR_VAL; + } + MOD_DEF(BareosDirModule, "bareosdir", NULL, BareosDIRMethods) + + if (PyDirModulePluginContext) { + PyModule_AddObject(BareosDirModule, "bpContext", PyDirModulePluginContext); + } else { + printf("python-dir.h:PyModule_AddObject failed\n"); + return MOD_ERROR_VAL; + } + return MOD_SUCCESS_VAL(BareosDirModule); } From 84395c62f08ade8335ce4d2fd3a8c247f4cf5adc Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 29 Feb 2020 22:27:48 +0100 Subject: [PATCH 009/341] python-fd: cleanup --- core/src/plugins/dird/python-dir.cc | 67 ++++++++++------------- core/src/plugins/filed/python-fd.cc | 84 +++++++++++++---------------- 2 files changed, 66 insertions(+), 85 deletions(-) diff --git a/core/src/plugins/dird/python-dir.cc b/core/src/plugins/dird/python-dir.cc index 859e6baba5e..e92b86b9802 100644 --- a/core/src/plugins/dird/python-dir.cc +++ b/core/src/plugins/dird/python-dir.cc @@ -546,17 +546,15 @@ static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, return bRC_Error; } -/** - * Python version after 2.6 and 3.1. - */ static PyObject* PyCreatebpContext(bpContext* bareos_plugin_ctx) { return PyCapsule_New((void*)bareos_plugin_ctx, "bareos.bpContext", NULL); } -static bpContext* PyGetbpContext(PyObject* pyCtx) +static bpContext* PyGetbpContext() { - return (bpContext*)PyCapsule_GetPointer(pyCtx, "bareos.bpContext"); + bpContext** retval = (bpContext**)PyCapsule_Import("bareosfd.bpContext", 0); + return *retval; } /** @@ -688,7 +686,7 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) /* * Encode the bpContext so a Python method can pass it in on calling back. */ - plugin_priv_ctx->py_bpContext = PyCreatebpContext(bareos_plugin_ctx); + /* plugin_priv_ctx->py_bpContext = PyCreatebpContext(bareos_plugin_ctx); */ /* * Lookup the load_bareos_plugin() function in the python module. @@ -844,12 +842,9 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; bpContext* bareos_plugin_ctx = NULL; - PyObject* pyCtx; PyObject* pRetVal = NULL; - if (!PyArg_ParseTuple(args, "Oi:BareosGetValue", &pyCtx, &var)) { - return NULL; - } + if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } switch (var) { case bDirVarJobId: @@ -862,7 +857,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarSDJobStatus: { int value = 0; - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); @@ -878,7 +873,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarReadBytes: { uint64_t value = 0; - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { pRetVal = PyLong_FromUnsignedLong(value); @@ -897,7 +892,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarVolumeName: { char* value = NULL; - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } @@ -913,7 +908,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) break; } default: - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); Dmsg(bareos_plugin_ctx, debuglevel, "python-dir: PyBareosGetValue unknown variable requested %d\n", var); break; @@ -936,9 +931,9 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) int var; bpContext* bareos_plugin_ctx = NULL; bRC retval = bRC_Error; - PyObject *pyCtx, *pyValue; + PyObject* pyValue; - if (!PyArg_ParseTuple(args, "OiO:BareosSetValue", &pyCtx, &var, &pyValue)) { + if (!PyArg_ParseTuple(args, "iO:BareosSetValue", &var, &pyValue)) { goto bail_out; } @@ -946,7 +941,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bwDirVarVolumeName: { char* value; - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); value = PyString_AsString(pyValue); if (value) { retval = bfuncs->setBareosValue(bareos_plugin_ctx, (bwDirVariable)var, @@ -959,7 +954,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bwDirVarJobLevel: { int value; - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); value = PyInt_AsLong(pyValue); if (value >= 0) { retval = bfuncs->setBareosValue(bareos_plugin_ctx, (bwDirVariable)var, @@ -968,7 +963,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) break; } default: - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); Dmsg(bareos_plugin_ctx, debuglevel, "python-dir: PyBareosSetValue unknown variable requested %d\n", var); break; @@ -988,15 +983,14 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) int level; char* dbgmsg = NULL; bpContext* bareos_plugin_ctx; - PyObject* pyCtx; - if (!PyArg_ParseTuple(args, "Oi|z:BareosDebugMessage", &pyCtx, &level, - &dbgmsg)) { + + if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; } if (dbgmsg) { - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); Dmsg(bareos_plugin_ctx, level, "python-dir: %s", dbgmsg); } @@ -1014,15 +1008,14 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) int type; char* jobmsg = NULL; bpContext* bareos_plugin_ctx; - PyObject* pyCtx; - if (!PyArg_ParseTuple(args, "Oi|z:BareosJobMessage", &pyCtx, &type, - &jobmsg)) { + + if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; } if (jobmsg) { - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); Jmsg(bareos_plugin_ctx, type, "python-dir: %s", jobmsg); } @@ -1040,9 +1033,9 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) int len, event; bpContext* bareos_plugin_ctx; bRC retval = bRC_Error; - PyObject *pyCtx, *pyEvents, *pySeq, *pyEvent; + PyObject *pyEvents, *pySeq, *pyEvent; - if (!PyArg_ParseTuple(args, "OO:BareosRegisterEvents", &pyCtx, &pyEvents)) { + if (!PyArg_ParseTuple(args, "O:BareosRegisterEvents", &pyEvents)) { goto bail_out; } @@ -1051,7 +1044,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); @@ -1081,9 +1074,9 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) int len, event; bpContext* bareos_plugin_ctx; bRC retval = bRC_Error; - PyObject *pyCtx, *pyEvents, *pySeq, *pyEvent; + PyObject *pyEvents, *pySeq, *pyEvent; - if (!PyArg_ParseTuple(args, "OO:BareosUnRegisterEvents", &pyCtx, &pyEvents)) { + if (!PyArg_ParseTuple(args, "O:BareosUnRegisterEvents", &pyEvents)) { goto bail_out; } @@ -1092,7 +1085,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); @@ -1121,14 +1114,12 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; bpContext* bareos_plugin_ctx = NULL; - PyObject* pyCtx; + PyObject* pRetVal = NULL; - if (!PyArg_ParseTuple(args, "O:BareosGetInstanceCount", &pyCtx)) { - return NULL; - } + if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } - bareos_plugin_ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); if (bfuncs->getInstanceCount(bareos_plugin_ctx, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } diff --git a/core/src/plugins/filed/python-fd.cc b/core/src/plugins/filed/python-fd.cc index 33504d09bdc..da1fd51cad7 100644 --- a/core/src/plugins/filed/python-fd.cc +++ b/core/src/plugins/filed/python-fd.cc @@ -1056,27 +1056,25 @@ static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, return bRC_Error; } -static PyObject* PyCreatebpContext(bpContext* bareos_plugin_ctx) +/* static PyObject* PyCreatebpContext(bpContext* bareos_plugin_ctx) */ +/* { */ +/* return PyCapsule_New((void*)bareos_plugin_ctx, "bareos.bpContext", NULL); + */ +/* } */ + +static void StorePluginContextInPythonModule(bpContext* bareos_plugin_ctx) { - /* - * Setup a new Capsule which holds the bpContext structure used here - * internally. - */ - /* printf("PyCreatebpContext: bpContext is: %p\n", bareos_plugin_ctx); */ - /* Dmsg(bareos_plugin_ctx, 10, "PyGetbpContext: bpContext is: %p", */ - /* bareos_plugin_ctx); */ - /* Jmsg(bareos_plugin_ctx, M_INFO, "PyGetbpContext: bpContext is: %p", */ - /* bareos_plugin_ctx); */ - return PyCapsule_New((void*)bareos_plugin_ctx, "bareos.bpContext", NULL); + /* get the pointer to the module variable that is exported via the capsule */ + bpContext** bareosfd_bpContext = + (bpContext**)PyCapsule_Import("bareosfd.bpContext", 0); + + /* store bareos_plugin_ctx in module */ + *bareosfd_bpContext = bareos_plugin_ctx; } -static bpContext* PyGetbpContext() +static bpContext* GetPluginContextFromPythonModule() { bpContext** retval = (bpContext**)PyCapsule_Import("bareosfd.bpContext", 0); - - /* (bpContext*)PyCapsule_GetPointer(pyCtx, "bareos.bpContext"); */ - /* Dmsg(*retval, 10, "PyGetbpContext: bpContext is: %p\n", retval); */ - /* Jmsg(*retval, M_INFO, "PyGetbpContext: bpContext is: %p\n", retval); */ return *retval; } @@ -1199,17 +1197,9 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ /* Encode the bpContext so a Python method can pass it in on calling back.*/ - plugin_priv_ctx->py_bpContext = PyCreatebpContext(bareos_plugin_ctx); - - /* get the pointer to the module variable that is exported via the - * capsule - */ - bpContext** bareosfd_bpContext = - (bpContext**)PyCapsule_Import("bareosfd.bpContext", 0); + /* plugin_priv_ctx->py_bpContext = PyCreatebpContext(bareos_plugin_ctx); */ - /* set the bareosfd.bpContext capsule pointer to point to bareos_plugin_ctx - */ - *bareosfd_bpContext = bareos_plugin_ctx; + StorePluginContextInPythonModule(bareos_plugin_ctx); /* Lookup the load_bareos_plugin() function in the python module. */ pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, @@ -2490,7 +2480,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarPrefixLinks: { int value = 0; - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (bVariable)var, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); @@ -2504,7 +2494,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarRegexWhere: { char* value = NULL; - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (bVariable)var, &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } @@ -2514,7 +2504,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarFileSeen: break; /* a write only variable, ignore read request */ default: - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: PyBareosGetValue unknown variable requested %d\n", var); break; @@ -2567,7 +2557,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) break; } default: - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: PyBareosSetValue unknown variable requested %d\n", var); break; @@ -2593,7 +2583,7 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) } if (dbgmsg) { - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); Dmsg(bareos_plugin_ctx, level, "python-fd: %s", dbgmsg); } @@ -2618,7 +2608,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) } if (jobmsg) { - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); Jmsg(bareos_plugin_ctx, type, "python-fd: %s", jobmsg); } @@ -2647,7 +2637,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); @@ -2688,7 +2678,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); @@ -2720,7 +2710,7 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getInstanceCount(bareos_plugin_ctx, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } @@ -2747,7 +2737,7 @@ static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "|z:BareosAddExclude", &file)) { goto bail_out; } if (file) { - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); retval = bfuncs->AddExclude(bareos_plugin_ctx, file); } @@ -2769,7 +2759,7 @@ static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "|z:BareosAddInclude", &file)) { goto bail_out; } if (file) { - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); retval = bfuncs->AddInclude(bareos_plugin_ctx, file); } @@ -2791,7 +2781,7 @@ static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "|z:BareosAddOptions", &opts)) { goto bail_out; } if (opts) { - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); retval = bfuncs->AddOptions(bareos_plugin_ctx, opts); } @@ -2816,7 +2806,7 @@ static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) } if (item) { - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); retval = bfuncs->AddRegex(bareos_plugin_ctx, item, type); } @@ -2841,7 +2831,7 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) } if (item) { - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); retval = bfuncs->AddWild(bareos_plugin_ctx, item, type); } @@ -2861,7 +2851,7 @@ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, ":BareosNewOptions")) { goto bail_out; } - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); retval = bfuncs->NewOptions(bareos_plugin_ctx); bail_out: @@ -2880,7 +2870,7 @@ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, ":BareosNewInclude")) { goto bail_out; } - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); retval = bfuncs->NewInclude(bareos_plugin_ctx); bail_out: @@ -2899,7 +2889,7 @@ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, ":BareosNewPreInclude")) { goto bail_out; } - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); retval = bfuncs->NewPreInclude(bareos_plugin_ctx); bail_out: @@ -2923,7 +2913,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) goto bail_out; } - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); /* * CheckFile only has a need for a limited version of the PySavePacket so we @@ -2976,7 +2966,7 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) goto bail_out; } - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); /* * Acceptfile only needs fname and statp from PySavePacket so we handle @@ -3020,7 +3010,7 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) goto bail_out; } - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); all = PyObject_IsTrue(pyBool); retval = bfuncs->SetSeenBitmap(bareos_plugin_ctx, all, fname); @@ -3044,7 +3034,7 @@ static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) goto bail_out; } - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); all = PyObject_IsTrue(pyBool); retval = bfuncs->ClearSeenBitmap(bareos_plugin_ctx, all, fname); From 527bc95e322e3b3c941f413895b3ec9741dd79de Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 2 Mar 2020 08:53:04 +0100 Subject: [PATCH 010/341] python-dir-plugin test passes --- core/src/plugins/dird/python-dir.cc | 31 +++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/core/src/plugins/dird/python-dir.cc b/core/src/plugins/dird/python-dir.cc index e92b86b9802..3d73b164186 100644 --- a/core/src/plugins/dird/python-dir.cc +++ b/core/src/plugins/dird/python-dir.cc @@ -546,14 +546,26 @@ static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, return bRC_Error; } -static PyObject* PyCreatebpContext(bpContext* bareos_plugin_ctx) +/* static PyObject* PyCreatebpContext(bpContext* bareos_plugin_ctx) */ +/* { */ +/* return PyCapsule_New((void*)bareos_plugin_ctx, "bareos.bpContext", NULL); + */ +/* } */ + +static void StorePluginContextInPythonModule(bpContext* bareos_plugin_ctx) { - return PyCapsule_New((void*)bareos_plugin_ctx, "bareos.bpContext", NULL); + /* get the pointer to the module variable that is exported via the capsule */ + bpContext** bareosfd_bpContext = + (bpContext**)PyCapsule_Import("bareosdir.bpContext", 0); + + /* store bareos_plugin_ctx in module */ + *bareosfd_bpContext = bareos_plugin_ctx; } + static bpContext* PyGetbpContext() { - bpContext** retval = (bpContext**)PyCapsule_Import("bareosfd.bpContext", 0); + bpContext** retval = (bpContext**)PyCapsule_Import("bareosdir.bpContext", 0); return *retval; } @@ -628,7 +640,7 @@ static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype) /** * Initial load of the Python module. * - * Based on the parsed plugin options we set some prerequisits like the + * Based on the parsed plugin options we set some prerequisites like the * module path and the module to load. We also load the dictionary used * for looking up the Python methods. */ @@ -688,6 +700,8 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) */ /* plugin_priv_ctx->py_bpContext = PyCreatebpContext(bareos_plugin_ctx); */ + StorePluginContextInPythonModule(bareos_plugin_ctx); + /* * Lookup the load_bareos_plugin() function in the python module. */ @@ -699,8 +713,7 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) pPluginDefinition = PyString_FromString((char*)value); if (!pPluginDefinition) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs( - pFunc, plugin_priv_ctx->py_bpContext, pPluginDefinition, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); Py_DECREF(pPluginDefinition); if (!pRetVal) { @@ -754,8 +767,7 @@ static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) pPluginDefinition = PyString_FromString((char*)value); if (!pPluginDefinition) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, - pPluginDefinition, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); Py_DECREF(pPluginDefinition); if (!pRetVal) { @@ -811,8 +823,7 @@ static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, pEventType = PyInt_FromLong(event->eventType); - pRetVal = PyObject_CallFunctionObjArgs(pFunc, plugin_priv_ctx->py_bpContext, - pEventType, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pEventType, NULL); Py_DECREF(pEventType); if (!pRetVal) { From 22048d7ae1c75c110d3513ff756e5c8203049f1d Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 2 Mar 2020 09:38:58 +0100 Subject: [PATCH 011/341] python-sd test works --- core/src/plugins/dird/python-dir.cc | 11 - core/src/plugins/stored/python-sd.cc | 421 +++++++++++++-------------- core/src/plugins/stored/python-sd.h | 24 +- 3 files changed, 233 insertions(+), 223 deletions(-) diff --git a/core/src/plugins/dird/python-dir.cc b/core/src/plugins/dird/python-dir.cc index 3d73b164186..c21e03e7aab 100644 --- a/core/src/plugins/dird/python-dir.cc +++ b/core/src/plugins/dird/python-dir.cc @@ -546,12 +546,6 @@ static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, return bRC_Error; } -/* static PyObject* PyCreatebpContext(bpContext* bareos_plugin_ctx) */ -/* { */ -/* return PyCapsule_New((void*)bareos_plugin_ctx, "bareos.bpContext", NULL); - */ -/* } */ - static void StorePluginContextInPythonModule(bpContext* bareos_plugin_ctx) { /* get the pointer to the module variable that is exported via the capsule */ @@ -695,11 +689,6 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) plugin_priv_ctx->pyModuleFunctionsDict = PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ - /* - * Encode the bpContext so a Python method can pass it in on calling back. - */ - /* plugin_priv_ctx->py_bpContext = PyCreatebpContext(bareos_plugin_ctx); */ - StorePluginContextInPythonModule(bareos_plugin_ctx); /* diff --git a/core/src/plugins/stored/python-sd.cc b/core/src/plugins/stored/python-sd.cc index f3428a8db21..1711b3651b7 100644 --- a/core/src/plugins/stored/python-sd.cc +++ b/core/src/plugins/stored/python-sd.cc @@ -35,12 +35,14 @@ #endif #include "stored/stored.h" -using namespace storagedaemon; #if (PY_VERSION_HEX < 0x02060000) #error "Need at least Python version 2.6 or newer" #endif +#include "python-sd.h" +#include "lib/edit.h" +namespace storagedaemon { static const int debuglevel = 150; #define PLUGIN_LICENSE "Bareos AGPLv3" @@ -58,21 +60,33 @@ static const int debuglevel = 150; bfuncs->JobMessage(context, __FILE__, __LINE__, type, 0, __VA_ARGS__) /* Forward referenced functions */ -static bRC newPlugin(bpContext* ctx); -static bRC freePlugin(bpContext* ctx); -static bRC getPluginValue(bpContext* ctx, psdVariable var, void* value); -static bRC setPluginValue(bpContext* ctx, psdVariable var, void* value); -static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value); -static bRC parse_plugin_definition(bpContext* ctx, +static bRC newPlugin(bpContext* bareos_plugin_ctx); +static bRC freePlugin(bpContext* bareos_plugin_ctx); +static bRC getPluginValue(bpContext* bareos_plugin_ctx, + psdVariable var, + void* value); +static bRC setPluginValue(bpContext* bareos_plugin_ctx, + psdVariable var, + void* value); +static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, + bsdEvent* event, + void* value); +static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, void* value, PoolMem& plugin_options); -static void PyErrorHandler(bpContext* ctx, int msgtype); -static bRC PyLoadModule(bpContext* ctx, void* value); -static bRC PyParsePluginDefinition(bpContext* ctx, void* value); -static bRC PyGetPluginValue(bpContext* ctx, psdVariable var, void* value); -static bRC PySetPluginValue(bpContext* ctx, psdVariable var, void* value); -static bRC PyHandlePluginEvent(bpContext* ctx, bsdEvent* event, void* value); +static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype); +static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value); +static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value); +static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, + psdVariable var, + void* value); +static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, + psdVariable var, + void* value); +static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, + bsdEvent* event, + void* value); /* Pointers to Bareos functions */ static bsdFuncs* bfuncs = NULL; @@ -102,14 +116,11 @@ struct plugin_ctx { char* module_path; /* Plugin Module Path */ char* module_name; /* Plugin Module Name */ PyThreadState* - interpreter; /* Python interpreter for this instance of the plugin */ - PyObject* pModule; /* Python Module entry point */ - PyObject* pDict; /* Python Dictionary */ - PyObject* bpContext; /* Python representation of plugin context */ + interpreter; /* Python interpreter for this instance of the plugin */ + PyObject* pModule; /* Python Module entry point */ + PyObject* pyModuleFunctionsDict; /* Python Dictionary */ }; -#include "python-sd.h" -#include "lib/edit.h" /** * We don't actually use this but we need it to tear down the @@ -179,27 +190,28 @@ bRC unloadPlugin() /** * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bpContext* ctx) +static bRC newPlugin(bpContext* bareos_plugin_ctx) { - struct plugin_ctx* p_ctx; + struct plugin_ctx* plugin_priv_ctx; - p_ctx = (struct plugin_ctx*)malloc(sizeof(struct plugin_ctx)); - if (!p_ctx) { return bRC_Error; } - memset(p_ctx, 0, sizeof(struct plugin_ctx)); - ctx->pContext = (void*)p_ctx; /* set our context pointer */ + plugin_priv_ctx = (struct plugin_ctx*)malloc(sizeof(struct plugin_ctx)); + if (!plugin_priv_ctx) { return bRC_Error; } + memset(plugin_priv_ctx, 0, sizeof(struct plugin_ctx)); + bareos_plugin_ctx->pContext = + (void*)plugin_priv_ctx; /* set our context pointer */ /* * For each plugin instance we instantiate a new Python interpreter. */ PyEval_AcquireThread(mainThreadState); - p_ctx->interpreter = Py_NewInterpreter(); - PyEval_ReleaseThread(p_ctx->interpreter); + plugin_priv_ctx->interpreter = Py_NewInterpreter(); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); /* * Always register some events the python plugin itself can register * any other events it is interested in. */ - bfuncs->registerBareosEvents(ctx, 1, bsdEventNewPluginOptions); + bfuncs->registerBareosEvents(bareos_plugin_ctx, 1, bsdEventNewPluginOptions); return bRC_OK; } @@ -207,29 +219,26 @@ static bRC newPlugin(bpContext* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bpContext* ctx) +static bRC freePlugin(bpContext* bareos_plugin_ctx) { - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* plugin_priv_ctx = + (struct plugin_ctx*)bareos_plugin_ctx->pContext; - if (!p_ctx) { return bRC_Error; } + if (!plugin_priv_ctx) { return bRC_Error; } /* * Stop any sub interpreter started per plugin instance. */ - PyEval_AcquireThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); - /* - * Do python cleanup calls. - */ - if (p_ctx->bpContext) { Py_DECREF(p_ctx->bpContext); } - if (p_ctx->pModule) { Py_DECREF(p_ctx->pModule); } + if (plugin_priv_ctx->pModule) { Py_DECREF(plugin_priv_ctx->pModule); } - Py_EndInterpreter(p_ctx->interpreter); + Py_EndInterpreter(plugin_priv_ctx->interpreter); PyEval_ReleaseLock(); - free(p_ctx); - ctx->pContext = NULL; + free(plugin_priv_ctx); + bareos_plugin_ctx->pContext = NULL; return bRC_OK; } @@ -237,14 +246,17 @@ static bRC freePlugin(bpContext* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bpContext* ctx, psdVariable var, void* value) +static bRC getPluginValue(bpContext* bareos_plugin_ctx, + psdVariable var, + void* value) { - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* plugin_priv_ctx = + (struct plugin_ctx*)bareos_plugin_ctx->pContext; bRC retval = bRC_Error; - PyEval_AcquireThread(p_ctx->interpreter); - retval = PyGetPluginValue(ctx, var, value); - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyGetPluginValue(bareos_plugin_ctx, var, value); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); return retval; } @@ -252,14 +264,17 @@ static bRC getPluginValue(bpContext* ctx, psdVariable var, void* value) /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bpContext* ctx, psdVariable var, void* value) +static bRC setPluginValue(bpContext* bareos_plugin_ctx, + psdVariable var, + void* value) { - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* plugin_priv_ctx = + (struct plugin_ctx*)bareos_plugin_ctx->pContext; bRC retval = bRC_Error; - PyEval_AcquireThread(p_ctx->interpreter); - retval = PySetPluginValue(ctx, var, value); - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PySetPluginValue(bareos_plugin_ctx, var, value); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); return retval; } @@ -267,14 +282,16 @@ static bRC setPluginValue(bpContext* ctx, psdVariable var, void* value) /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value) +static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, + bsdEvent* event, + void* value) { bRC retval = bRC_Error; bool event_dispatched = false; PoolMem plugin_options(PM_FNAME); - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* plugin_priv_ctx = (plugin_ctx*)bareos_plugin_ctx->pContext; - if (!p_ctx) { goto bail_out; } + if (!plugin_priv_ctx) { goto bail_out; } /* * First handle some events internally before calling python if it @@ -283,7 +300,8 @@ static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value) switch (event->eventType) { case bsdEventNewPluginOptions: event_dispatched = true; - retval = parse_plugin_definition(ctx, value, plugin_options); + retval = + parse_plugin_definition(bareos_plugin_ctx, value, plugin_options); break; default: break; @@ -296,7 +314,7 @@ static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value) * processing was successfull (e.g. retval == bRC_OK). */ if (!event_dispatched || retval == bRC_OK) { - PyEval_AcquireThread(p_ctx->interpreter); + PyEval_AcquireThread(plugin_priv_ctx->interpreter); /* * Now dispatch the event to Python. @@ -307,15 +325,16 @@ static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value) /* * See if we already loaded the Python modules. */ - if (!p_ctx->python_loaded) { - retval = PyLoadModule(ctx, plugin_options.c_str()); + if (!plugin_priv_ctx->python_loaded) { + retval = PyLoadModule(bareos_plugin_ctx, plugin_options.c_str()); } /* * Only try to call when the loading succeeded. */ if (retval == bRC_OK) { - retval = PyParsePluginDefinition(ctx, plugin_options.c_str()); + retval = PyParsePluginDefinition(bareos_plugin_ctx, + plugin_options.c_str()); } break; default: @@ -324,15 +343,15 @@ static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value) * We only try to call Python when we loaded the right module until * that time we pretend the call succeeded. */ - if (p_ctx->python_loaded) { - retval = PyHandlePluginEvent(ctx, event, value); + if (plugin_priv_ctx->python_loaded) { + retval = PyHandlePluginEvent(bareos_plugin_ctx, event, value); } else { retval = bRC_OK; } break; } - PyEval_ReleaseThread(p_ctx->interpreter); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); } bail_out: @@ -400,7 +419,7 @@ static inline void SetString(char** destination, char* value) * * python:module_path=:module_name=:... */ -static bRC parse_plugin_definition(bpContext* ctx, +static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, void* value, PoolMem& plugin_options) { @@ -408,7 +427,7 @@ static bRC parse_plugin_definition(bpContext* ctx, int i, cnt; PoolMem plugin_definition(PM_FNAME); char *bp, *argument, *argument_value; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* plugin_priv_ctx = (plugin_ctx*)bareos_plugin_ctx->pContext; if (!value) { return bRC_Error; } @@ -420,9 +439,11 @@ static bRC parse_plugin_definition(bpContext* ctx, bp = strchr(plugin_definition.c_str(), ':'); if (!bp) { - Jmsg(ctx, M_FATAL, "python-sd: Illegal plugin definition %s\n", + Jmsg(bareos_plugin_ctx, M_FATAL, + "python-sd: Illegal plugin definition %s\n", plugin_definition.c_str()); - Dmsg(ctx, debuglevel, "python-sd: Illegal plugin definition %s\n", + Dmsg(bareos_plugin_ctx, debuglevel, + "python-sd: Illegal plugin definition %s\n", plugin_definition.c_str()); goto bail_out; } @@ -446,10 +467,10 @@ static bRC parse_plugin_definition(bpContext* ctx, argument = bp; argument_value = strchr(bp, '='); if (!argument_value) { - Jmsg(ctx, M_FATAL, "python-sd: Illegal argument %s without value\n", - argument); - Dmsg(ctx, debuglevel, "python-sd: Illegal argument %s without value\n", - argument); + Jmsg(bareos_plugin_ctx, M_FATAL, + "python-sd: Illegal argument %s without value\n", argument); + Dmsg(bareos_plugin_ctx, debuglevel, + "python-sd: Illegal argument %s without value\n", argument); goto bail_out; } *argument_value++ = '\0'; @@ -479,13 +500,13 @@ static bRC parse_plugin_definition(bpContext* ctx, switch (plugin_arguments[i].type) { case argument_instance: - int_destination = &p_ctx->instance; + int_destination = &plugin_priv_ctx->instance; break; case argument_module_path: - str_destination = &p_ctx->module_path; + str_destination = &plugin_priv_ctx->module_path; break; case argument_module_name: - str_destination = &p_ctx->module_name; + str_destination = &plugin_priv_ctx->module_name; break; default: break; @@ -534,49 +555,22 @@ static bRC parse_plugin_definition(bpContext* ctx, return bRC_Error; } -/** - * Work around API changes in Python versions. - * These function abstract the storage and retrieval of the bpContext - * which is passed to the Python methods and which the method can pass - * back and which allow the callback function to understand what bpContext - * its talking about. - */ -#if ((PY_VERSION_HEX < 0x02070000) || \ - ((PY_VERSION_HEX >= 0x03000000) && (PY_VERSION_HEX < 0x03010000))) -/** - * Python version before 2.7 and 3.0. - */ -static PyObject* PyCreatebpContext(bpContext* ctx) +static void StorePluginContextInPythonModule(bpContext* bareos_plugin_ctx) { - /* - * Setup a new CObject which holds the bpContext structure used here - * internally. - */ - return PyCObject_FromVoidPtr((void*)ctx, NULL); -} + /* get the pointer to the module variable that is exported via the capsule */ + bpContext** bareosfd_bpContext = + (bpContext**)PyCapsule_Import("bareossd.bpContext", 0); -static bpContext* PyGetbpContext(PyObject* pyCtx) -{ - return (bpContext*)PyCObject_AsVoidPtr(pyCtx); -} -#else -/** - * Python version after 2.6 and 3.1. - */ -static PyObject* PyCreatebpContext(bpContext* ctx) -{ - /* - * Setup a new Capsule which holds the bpContext structure used here - * internally. - */ - return PyCapsule_New((void*)ctx, "bareos.bpContext", NULL); + /* store bareos_plugin_ctx in module */ + *bareosfd_bpContext = bareos_plugin_ctx; } -static bpContext* PyGetbpContext(PyObject* pyCtx) + +static bpContext* PyGetbpContext() { - return (bpContext*)PyCapsule_GetPointer(pyCtx, "bareos.bpContext"); + bpContext** retval = (bpContext**)PyCapsule_Import("bareossd.bpContext", 0); + return *retval; } -#endif /** * Convert a return value into a bRC enum value. @@ -603,7 +597,7 @@ static inline PyObject* conv_retval_python(bRC retval) * return "".join(traceback.format_exception(sys.exc_type, * sys.exc_value, sys.exc_traceback)) */ -static void PyErrorHandler(bpContext* ctx, int msgtype) +static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype) { PyObject *type, *value, *traceback; PyObject* tracebackModule; @@ -638,8 +632,10 @@ static void PyErrorHandler(bpContext* ctx, int msgtype) Py_XDECREF(value); Py_XDECREF(traceback); - Dmsg(ctx, debuglevel, "python-sd: %s\n", error_string); - if (msgtype) { Jmsg(ctx, msgtype, "python-sd: %s\n", error_string); } + Dmsg(bareos_plugin_ctx, debuglevel, "python-sd: %s\n", error_string); + if (msgtype) { + Jmsg(bareos_plugin_ctx, msgtype, "python-sd: %s\n", error_string); + } free(error_string); } @@ -647,66 +643,67 @@ static void PyErrorHandler(bpContext* ctx, int msgtype) /** * Initial load of the Python module. * - * Based on the parsed plugin options we set some prerequisits like the + * Based on the parsed plugin options we set some prerequisites like the * module path and the module to load. We also load the dictionary used * for looking up the Python methods. */ -static bRC PyLoadModule(bpContext* ctx, void* value) +static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* plugin_priv_ctx = + (struct plugin_ctx*)bareos_plugin_ctx->pContext; PyObject *sysPath, *mPath, *pName, *pFunc; /* * See if we already setup the python search path. */ - if (!p_ctx->python_path_set) { + if (!plugin_priv_ctx->python_path_set) { /* * Extend the Python search path with the given module_path. */ - if (p_ctx->module_path) { + if (plugin_priv_ctx->module_path) { sysPath = PySys_GetObject((char*)"path"); - mPath = PyString_FromString(p_ctx->module_path); + mPath = PyString_FromString(plugin_priv_ctx->module_path); PyList_Append(sysPath, mPath); Py_DECREF(mPath); - p_ctx->python_path_set = true; + plugin_priv_ctx->python_path_set = true; } } /* * Try to load the Python module by name. */ - if (p_ctx->module_name) { - Dmsg(ctx, debuglevel, "python-sd: Trying to load module with name %s\n", - p_ctx->module_name); - pName = PyString_FromString(p_ctx->module_name); - p_ctx->pModule = PyImport_Import(pName); + if (plugin_priv_ctx->module_name) { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-sd: Trying to load module with name %s\n", + plugin_priv_ctx->module_name); + pName = PyString_FromString(plugin_priv_ctx->module_name); + plugin_priv_ctx->pModule = PyImport_Import(pName); Py_DECREF(pName); - if (!p_ctx->pModule) { - Dmsg(ctx, debuglevel, "python-sd: Failed to load module with name %s\n", - p_ctx->module_name); + if (!plugin_priv_ctx->pModule) { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-sd: Failed to load module with name %s\n", + plugin_priv_ctx->module_name); goto bail_out; } - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-sd: Successfully loaded module with name %s\n", - p_ctx->module_name); + plugin_priv_ctx->module_name); /* * Get the Python dictionary for lookups in the Python namespace. */ - p_ctx->pDict = PyModule_GetDict(p_ctx->pModule); /* Borrowed reference */ + plugin_priv_ctx->pyModuleFunctionsDict = + PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ - /* - * Encode the bpContext so a Python method can pass it in on calling back. - */ - p_ctx->bpContext = PyCreatebpContext(ctx); + StorePluginContextInPythonModule(bareos_plugin_ctx); /* * Lookup the load_bareos_plugin() function in the python module. */ - pFunc = PyDict_GetItemString(p_ctx->pDict, + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, "load_bareos_plugin"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyObject *pPluginDefinition, *pRetVal; @@ -714,8 +711,7 @@ static bRC PyLoadModule(bpContext* ctx, void* value) pPluginDefinition = PyString_FromString((char*)value); if (!pPluginDefinition) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, - pPluginDefinition, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); Py_DECREF(pPluginDefinition); if (!pRetVal) { @@ -725,7 +721,7 @@ static bRC PyLoadModule(bpContext* ctx, void* value) Py_DECREF(pRetVal); } } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-sd: Failed to find function named load_bareos_plugins()\n"); goto bail_out; } @@ -733,13 +729,13 @@ static bRC PyLoadModule(bpContext* ctx, void* value) /* * Keep track we successfully loaded. */ - p_ctx->python_loaded = true; + plugin_priv_ctx->python_loaded = true; } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } @@ -750,25 +746,26 @@ static bRC PyLoadModule(bpContext* ctx, void* value) * PyLoadModule() has loaded the Python module and made sure things are * operational. */ -static bRC PyParsePluginDefinition(bpContext* ctx, void* value) +static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* plugin_priv_ctx = + (struct plugin_ctx*)bareos_plugin_ctx->pContext; PyObject* pFunc; /* * Lookup the parse_plugin_definition() function in the python module. */ - pFunc = PyDict_GetItemString( - p_ctx->pDict, "parse_plugin_definition"); /* Borrowed reference */ + pFunc = + PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "parse_plugin_definition"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyObject *pPluginDefinition, *pRetVal; pPluginDefinition = PyString_FromString((char*)value); if (!pPluginDefinition) { goto bail_out; } - pRetVal = PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, - pPluginDefinition, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); Py_DECREF(pPluginDefinition); if (!pRetVal) { @@ -781,45 +778,50 @@ static bRC PyParsePluginDefinition(bpContext* ctx, void* value) return retval; } else { Dmsg( - ctx, debuglevel, + bareos_plugin_ctx, debuglevel, "python-sd: Failed to find function named parse_plugin_definition()\n"); return bRC_Error; } bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } -static bRC PyGetPluginValue(bpContext* ctx, psdVariable var, void* value) +static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, + psdVariable var, + void* value) { return bRC_OK; } -static bRC PySetPluginValue(bpContext* ctx, psdVariable var, void* value) +static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, + psdVariable var, + void* value) { return bRC_OK; } -static bRC PyHandlePluginEvent(bpContext* ctx, bsdEvent* event, void* value) +static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, + bsdEvent* event, + void* value) { bRC retval = bRC_Error; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* plugin_priv_ctx = (plugin_ctx*)bareos_plugin_ctx->pContext; PyObject* pFunc; /* * Lookup the handle_plugin_event() function in the python module. */ - pFunc = PyDict_GetItemString(p_ctx->pDict, + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, "handle_plugin_event"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { PyObject *pEventType, *pRetVal; pEventType = PyInt_FromLong(event->eventType); - pRetVal = - PyObject_CallFunctionObjArgs(pFunc, p_ctx->bpContext, pEventType, NULL); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pEventType, NULL); Py_DECREF(pEventType); if (!pRetVal) { @@ -829,14 +831,14 @@ static bRC PyHandlePluginEvent(bpContext* ctx, bsdEvent* event, void* value) Py_DECREF(pRetVal); } } else { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-sd: Failed to find function named handle_plugin_event()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } return retval; } @@ -848,13 +850,10 @@ static bRC PyHandlePluginEvent(bpContext* ctx, bsdEvent* event, void* value) static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - bpContext* ctx = NULL; - PyObject* pyCtx; + bpContext* bareos_plugin_ctx = NULL; PyObject* pRetVal = NULL; - if (!PyArg_ParseTuple(args, "Oi:BareosGetValue", &pyCtx, &var)) { - return NULL; - } + if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } switch (var) { case bsdVarJobId: @@ -863,8 +862,9 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bsdVarJobStatus: { int value; - ctx = PyGetbpContext(pyCtx); - if (bfuncs->getBareosValue(ctx, (bsdrVariable)var, &value) == bRC_OK) { + bareos_plugin_ctx = PyGetbpContext(); + if (bfuncs->getBareosValue(bareos_plugin_ctx, (bsdrVariable)var, + &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } break; @@ -874,8 +874,9 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bsdVarJobBytes: { uint64_t value = 0; - ctx = PyGetbpContext(pyCtx); - if (bfuncs->getBareosValue(ctx, (bsdrVariable)var, &value) == bRC_OK) { + bareos_plugin_ctx = PyGetbpContext(); + if (bfuncs->getBareosValue(bareos_plugin_ctx, (bsdrVariable)var, + &value) == bRC_OK) { pRetVal = PyLong_FromUnsignedLong(value); } break; @@ -890,8 +891,9 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bsdVarVolumeName: { char* value = NULL; - ctx = PyGetbpContext(pyCtx); - if (bfuncs->getBareosValue(ctx, (bsdrVariable)var, &value) == bRC_OK) { + bareos_plugin_ctx = PyGetbpContext(); + if (bfuncs->getBareosValue(bareos_plugin_ctx, (bsdrVariable)var, + &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } } break; @@ -916,8 +918,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) break; } default: - ctx = PyGetbpContext(pyCtx); - Dmsg(ctx, debuglevel, + bareos_plugin_ctx = PyGetbpContext(); + Dmsg(bareos_plugin_ctx, debuglevel, "python-sd: PyBareosGetValue unknown variable requested %d\n", var); break; } @@ -937,11 +939,11 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - bpContext* ctx = NULL; + bpContext* bareos_plugin_ctx = NULL; bRC retval = bRC_Error; - PyObject *pyCtx, *pyValue; + PyObject* pyValue; - if (!PyArg_ParseTuple(args, "OiO:BareosSetValue", &pyCtx, &var, &pyValue)) { + if (!PyArg_ParseTuple(args, "iO:BareosSetValue", &var, &pyValue)) { goto bail_out; } @@ -949,9 +951,11 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bsdwVarVolumeName: { char* value; - ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); value = PyString_AsString(pyValue); - if (value) { bfuncs->setBareosValue(ctx, (bsdwVariable)var, value); } + if (value) { + bfuncs->setBareosValue(bareos_plugin_ctx, (bsdwVariable)var, value); + } break; } @@ -959,16 +963,17 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bsdwVarJobLevel: { int value; - ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); value = PyInt_AsLong(pyValue); if (value >= 0) { - retval = bfuncs->setBareosValue(ctx, (bsdwVariable)var, &value); + retval = bfuncs->setBareosValue(bareos_plugin_ctx, (bsdwVariable)var, + &value); } break; } default: - ctx = PyGetbpContext(pyCtx); - Dmsg(ctx, debuglevel, + bareos_plugin_ctx = PyGetbpContext(); + Dmsg(bareos_plugin_ctx, debuglevel, "python-sd: PyBareosSetValue unknown variable requested %d\n", var); break; } @@ -986,17 +991,15 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - bpContext* ctx; - PyObject* pyCtx; + bpContext* bareos_plugin_ctx; - if (!PyArg_ParseTuple(args, "Oi|z:BareosDebugMessage", &pyCtx, &level, - &dbgmsg)) { + if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; } if (dbgmsg) { - ctx = PyGetbpContext(pyCtx); - Dmsg(ctx, level, "python-sd: %s", dbgmsg); + bareos_plugin_ctx = PyGetbpContext(); + Dmsg(bareos_plugin_ctx, level, "python-sd: %s", dbgmsg); } Py_INCREF(Py_None); @@ -1012,17 +1015,15 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - bpContext* ctx; - PyObject* pyCtx; + bpContext* bareos_plugin_ctx; - if (!PyArg_ParseTuple(args, "Oi|z:BareosJobMessage", &pyCtx, &type, - &jobmsg)) { + if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; } if (jobmsg) { - ctx = PyGetbpContext(pyCtx); - Jmsg(ctx, type, "python-sd: %s", jobmsg); + bareos_plugin_ctx = PyGetbpContext(); + Jmsg(bareos_plugin_ctx, type, "python-sd: %s", jobmsg); } Py_INCREF(Py_None); @@ -1037,11 +1038,11 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* ctx; + bpContext* bareos_plugin_ctx; bRC retval = bRC_Error; - PyObject *pyCtx, *pyEvents, *pySeq, *pyEvent; + PyObject *pyEvents, *pySeq, *pyEvent; - if (!PyArg_ParseTuple(args, "OO:BareosRegisterEvents", &pyCtx, &pyEvents)) { + if (!PyArg_ParseTuple(args, "O:BareosRegisterEvents", &pyEvents)) { goto bail_out; } @@ -1050,15 +1051,15 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); if (event >= bsdEventJobStart && event <= bsdEventWriteRecordTranslation) { - Dmsg(ctx, debuglevel, + Dmsg(bareos_plugin_ctx, debuglevel, "python-sd: PyBareosRegisterEvents registering event %d\n", event); - retval = bfuncs->registerBareosEvents(ctx, 1, event); + retval = bfuncs->registerBareosEvents(bareos_plugin_ctx, 1, event); if (retval != bRC_OK) { break; } } @@ -1078,11 +1079,11 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* ctx; + bpContext* bareos_plugin_ctx; bRC retval = bRC_Error; - PyObject *pyCtx, *pyEvents, *pySeq, *pyEvent; + PyObject *pyEvents, *pySeq, *pyEvent; - if (!PyArg_ParseTuple(args, "OO:BareosUnRegisterEvents", &pyCtx, &pyEvents)) { + if (!PyArg_ParseTuple(args, "O:BareosUnRegisterEvents", &pyEvents)) { goto bail_out; } @@ -1091,15 +1092,15 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - ctx = PyGetbpContext(pyCtx); + bareos_plugin_ctx = PyGetbpContext(); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); if (event >= bsdEventJobStart && event <= bsdEventWriteRecordTranslation) { - Dmsg(ctx, debuglevel, "PyBareosUnRegisterEvents: registering event %d\n", - event); - retval = bfuncs->unregisterBareosEvents(ctx, 1, event); + Dmsg(bareos_plugin_ctx, debuglevel, + "PyBareosUnRegisterEvents: registering event %d\n", event); + retval = bfuncs->unregisterBareosEvents(bareos_plugin_ctx, 1, event); if (retval != bRC_OK) { break; } } @@ -1119,16 +1120,13 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - bpContext* ctx = NULL; - PyObject* pyCtx; + bpContext* bareos_plugin_ctx = NULL; PyObject* pRetVal = NULL; - if (!PyArg_ParseTuple(args, "O:BareosGetInstanceCount", &pyCtx)) { - return NULL; - } + if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } - ctx = PyGetbpContext(pyCtx); - if (bfuncs->getInstanceCount(ctx, &value) == bRC_OK) { + bareos_plugin_ctx = PyGetbpContext(); + if (bfuncs->getInstanceCount(bareos_plugin_ctx, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } @@ -1139,3 +1137,4 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) return pRetVal; } +} /* namespace storagedaemon*/ diff --git a/core/src/plugins/stored/python-sd.h b/core/src/plugins/stored/python-sd.h index 0b3e003c26f..eb220b7c705 100644 --- a/core/src/plugins/stored/python-sd.h +++ b/core/src/plugins/stored/python-sd.h @@ -27,6 +27,8 @@ #ifndef BAREOS_PLUGINS_STORED_PYTHON_SD_H_ #define BAREOS_PLUGINS_STORED_PYTHON_SD_H_ 1 +namespace storagedaemon { + /** * This defines the arguments that the plugin parser understands. */ @@ -90,12 +92,32 @@ static PyMethodDef BareosSDMethods[] = { #define MOD_DEF(ob, name, doc, methods) ob = Py_InitModule3(name, methods, doc); #endif +static void* bareos_plugin_context = NULL; MOD_INIT(bareossd) { - PyObject* BareosSdModule; + PyObject* BareosSdModule = NULL; + + /* Pointer Capsules to avoid context transfer back and forth */ + PyObject* PySdModulePluginContext = + PyCapsule_New((void*)&bareos_plugin_context, "bareossd.bpContext", NULL); + + if (!PySdModulePluginContext) { + printf("python-dir.h: PyCapsule_New failed\n"); + return MOD_ERROR_VAL; + } + MOD_DEF(BareosSdModule, "bareossd", NULL, BareosSDMethods) + + if (PySdModulePluginContext) { + PyModule_AddObject(BareosSdModule, "bpContext", PySdModulePluginContext); + } else { + printf("python-sd.h:PyModule_AddObject failed\n"); + return MOD_ERROR_VAL; + } + return MOD_SUCCESS_VAL(BareosSdModule); } +} /* namespace storagedaemon*/ #endif /* BAREOS_PLUGINS_STORED_PYTHON_SD_H_ */ From 1de286c4857b71bc8d3dc7e328db033fa3f916b2 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 2 Mar 2020 09:42:36 +0100 Subject: [PATCH 012/341] python plugins: remove plugin_priv_ctx->py_bpContext everywhere --- core/src/plugins/dird/python-dir.cc | 7 ----- core/src/plugins/filed/python-fd.cc | 7 ----- core/src/plugins/stored/python-sd.cc | 38 +++++++++++++++------------- 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/core/src/plugins/dird/python-dir.cc b/core/src/plugins/dird/python-dir.cc index c21e03e7aab..611ac976c93 100644 --- a/core/src/plugins/dird/python-dir.cc +++ b/core/src/plugins/dird/python-dir.cc @@ -122,7 +122,6 @@ struct plugin_ctx { interpreter; /* Python interpreter for this instance of the plugin */ PyObject* pModule; /* Python Module entry point */ PyObject* pyModuleFunctionsDict; /* Python Dictionary */ - PyObject* py_bpContext; /* Python representation of plugin context */ }; /** @@ -225,12 +224,6 @@ static bRC freePlugin(bpContext* bareos_plugin_ctx) */ PyEval_AcquireThread(plugin_priv_ctx->interpreter); - /* - * Do python cleanup calls. - */ - if (plugin_priv_ctx->py_bpContext) { - Py_DECREF(plugin_priv_ctx->py_bpContext); - } if (plugin_priv_ctx->pModule) { Py_DECREF(plugin_priv_ctx->pModule); } diff --git a/core/src/plugins/filed/python-fd.cc b/core/src/plugins/filed/python-fd.cc index da1fd51cad7..8326d1b7e3b 100644 --- a/core/src/plugins/filed/python-fd.cc +++ b/core/src/plugins/filed/python-fd.cc @@ -156,7 +156,6 @@ struct plugin_private_context { interpreter; /* Python interpreter for this instance of the plugin */ PyObject* pModule; /* Python Module entry point */ PyObject* pyModuleFunctionsDict; /* Python Dictionary */ - PyObject* py_bpContext; /* Python representation of plugin context */ }; /** @@ -284,12 +283,6 @@ static bRC freePlugin(bpContext* bareos_plugin_ctx) */ PyEval_AcquireThread(plugin_priv_ctx->interpreter); - /* - * Do python cleanup calls. - */ - if (plugin_priv_ctx->py_bpContext) { - Py_DECREF(plugin_priv_ctx->py_bpContext); - } if (plugin_priv_ctx->pModule) { Py_DECREF(plugin_priv_ctx->pModule); } diff --git a/core/src/plugins/stored/python-sd.cc b/core/src/plugins/stored/python-sd.cc index 1711b3651b7..261af0e834a 100644 --- a/core/src/plugins/stored/python-sd.cc +++ b/core/src/plugins/stored/python-sd.cc @@ -109,7 +109,7 @@ static psdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, /** * Plugin private context */ -struct plugin_ctx { +struct plugin_private_context { int64_t instance; /* Instance number of plugin */ bool python_loaded; /* Plugin has python module loaded ? */ bool python_path_set; /* Python plugin search path is set ? */ @@ -192,11 +192,12 @@ bRC unloadPlugin() */ static bRC newPlugin(bpContext* bareos_plugin_ctx) { - struct plugin_ctx* plugin_priv_ctx; + struct plugin_private_context* plugin_priv_ctx; - plugin_priv_ctx = (struct plugin_ctx*)malloc(sizeof(struct plugin_ctx)); + plugin_priv_ctx = (struct plugin_private_context*)malloc( + sizeof(struct plugin_private_context)); if (!plugin_priv_ctx) { return bRC_Error; } - memset(plugin_priv_ctx, 0, sizeof(struct plugin_ctx)); + memset(plugin_priv_ctx, 0, sizeof(struct plugin_private_context)); bareos_plugin_ctx->pContext = (void*)plugin_priv_ctx; /* set our context pointer */ @@ -221,8 +222,8 @@ static bRC newPlugin(bpContext* bareos_plugin_ctx) */ static bRC freePlugin(bpContext* bareos_plugin_ctx) { - struct plugin_ctx* plugin_priv_ctx = - (struct plugin_ctx*)bareos_plugin_ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; if (!plugin_priv_ctx) { return bRC_Error; } @@ -250,8 +251,8 @@ static bRC getPluginValue(bpContext* bareos_plugin_ctx, psdVariable var, void* value) { - struct plugin_ctx* plugin_priv_ctx = - (struct plugin_ctx*)bareos_plugin_ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; bRC retval = bRC_Error; PyEval_AcquireThread(plugin_priv_ctx->interpreter); @@ -268,8 +269,8 @@ static bRC setPluginValue(bpContext* bareos_plugin_ctx, psdVariable var, void* value) { - struct plugin_ctx* plugin_priv_ctx = - (struct plugin_ctx*)bareos_plugin_ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; bRC retval = bRC_Error; PyEval_AcquireThread(plugin_priv_ctx->interpreter); @@ -289,7 +290,8 @@ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, bRC retval = bRC_Error; bool event_dispatched = false; PoolMem plugin_options(PM_FNAME); - plugin_ctx* plugin_priv_ctx = (plugin_ctx*)bareos_plugin_ctx->pContext; + plugin_private_context* plugin_priv_ctx = + (plugin_private_context*)bareos_plugin_ctx->pContext; if (!plugin_priv_ctx) { goto bail_out; } @@ -427,7 +429,8 @@ static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, int i, cnt; PoolMem plugin_definition(PM_FNAME); char *bp, *argument, *argument_value; - plugin_ctx* plugin_priv_ctx = (plugin_ctx*)bareos_plugin_ctx->pContext; + plugin_private_context* plugin_priv_ctx = + (plugin_private_context*)bareos_plugin_ctx->pContext; if (!value) { return bRC_Error; } @@ -650,8 +653,8 @@ static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype) static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; - struct plugin_ctx* plugin_priv_ctx = - (struct plugin_ctx*)bareos_plugin_ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject *sysPath, *mPath, *pName, *pFunc; /* @@ -749,8 +752,8 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; - struct plugin_ctx* plugin_priv_ctx = - (struct plugin_ctx*)bareos_plugin_ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; /* @@ -808,7 +811,8 @@ static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; - plugin_ctx* plugin_priv_ctx = (plugin_ctx*)bareos_plugin_ctx->pContext; + plugin_private_context* plugin_priv_ctx = + (plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; /* From 8809603035b4d342a7ed35ec981f83b1f7a7fa5c Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 2 Mar 2020 10:08:02 +0100 Subject: [PATCH 013/341] python plugins: introduced common module header files --- core/src/plugins/dird/python-dir.h | 26 ++++++++------------ core/src/plugins/filed/python-fd.h | 20 ++++------------ core/src/plugins/python_plugins_common.h | 24 +++++++++++++++++++ core/src/plugins/python_plugins_common.inc | 0 core/src/plugins/stored/python-sd.h | 28 +++++++++------------- 5 files changed, 49 insertions(+), 49 deletions(-) create mode 100644 core/src/plugins/python_plugins_common.h create mode 100644 core/src/plugins/python_plugins_common.inc diff --git a/core/src/plugins/dird/python-dir.h b/core/src/plugins/dird/python-dir.h index ff4591be7c0..459f1dd2db8 100644 --- a/core/src/plugins/dird/python-dir.h +++ b/core/src/plugins/dird/python-dir.h @@ -27,6 +27,10 @@ #ifndef BAREOS_PLUGINS_DIRD_PYTHON_DIR_H_ #define BAREOS_PLUGINS_DIRD_PYTHON_DIR_H_ 1 +/* common code for all python plugins */ +#include "../python_plugins_common.h" +#include "../python_plugins_common.inc" + namespace directordaemon { /** @@ -76,26 +80,16 @@ static PyMethodDef BareosDIRMethods[] = { {NULL, NULL, 0, NULL}}; -#if PY_MAJOR_VERSION >= 3 -#define MOD_ERROR_VAL NULL -#define MOD_SUCCESS_VAL(val) val -#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void) -#define MOD_DEF(ob, name, doc, methods) \ - static struct PyModuleDef moduledef = { \ - PyModuleDef_HEAD_INIT, name, doc, -1, methods, \ - }; \ - ob = PyModule_Create(&moduledef); -#else -#define MOD_ERROR_VAL -#define MOD_SUCCESS_VAL(val) -#define MOD_INIT(name) void Init_##name(void) -#define MOD_DEF(ob, name, doc, methods) ob = Py_InitModule3(name, methods, doc); -#endif - static void* bareos_plugin_context = NULL; MOD_INIT(bareosdir) { + /* bareos_plugin_context holds the bpContext instead of passing to Python and + * extracting it back like it was before. bareos_plugin_context needs to be + * set after loading the bareosdir binary python module and will be used for + * all calls. + */ + PyObject* BareosDirModule = NULL; /* Pointer Capsules to avoid context transfer back and forth */ diff --git a/core/src/plugins/filed/python-fd.h b/core/src/plugins/filed/python-fd.h index 2f44c17756c..f7b9bbe3290 100644 --- a/core/src/plugins/filed/python-fd.h +++ b/core/src/plugins/filed/python-fd.h @@ -27,6 +27,10 @@ #ifndef BAREOS_PLUGINS_FILED_PYTHON_FD_H_ #define BAREOS_PLUGINS_FILED_PYTHON_FD_H_ 1 +/* common code for all python plugins */ +#include "../python_plugins_common.h" +#include "../python_plugins_common.inc" + #include "structmember.h" namespace filedaemon { @@ -742,22 +746,6 @@ static PyMethodDef BareosFDMethods[] = { {NULL, NULL, 0, NULL}}; -#if PY_MAJOR_VERSION >= 3 -#define MOD_ERROR_VAL NULL -#define MOD_SUCCESS_VAL(val) val -#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void) -#define MOD_DEF(ob, name, doc, methods) \ - static struct PyModuleDef moduledef = { \ - PyModuleDef_HEAD_INIT, name, doc, -1, methods, \ - }; \ - ob = PyModule_Create(&moduledef); -#else -#define MOD_ERROR_VAL -#define MOD_SUCCESS_VAL(val) -#define MOD_INIT(name) void Init_##name(void) -#define MOD_DEF(ob, name, doc, methods) ob = Py_InitModule3(name, methods, doc); -#endif - static void* bareos_plugin_context = NULL; MOD_INIT(bareosfd) diff --git a/core/src/plugins/python_plugins_common.h b/core/src/plugins/python_plugins_common.h new file mode 100644 index 00000000000..d2a88129526 --- /dev/null +++ b/core/src/plugins/python_plugins_common.h @@ -0,0 +1,24 @@ + +#ifndef BAREOS_PYTHON_PLUGINS_COMMON_H_ +#define BAREOS_PYTHON_PLUGINS_COMMON_H_ + +/* macros for uniform python module definition + see http://python3porting.com/cextensions.html */ +#if PY_MAJOR_VERSION >= 3 +#define MOD_ERROR_VAL NULL +#define MOD_SUCCESS_VAL(val) val +#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void) +#define MOD_DEF(ob, name, doc, methods) \ + static struct PyModuleDef moduledef = { \ + PyModuleDef_HEAD_INIT, name, doc, -1, methods, \ + }; \ + ob = PyModule_Create(&moduledef); +#else +#define MOD_ERROR_VAL +#define MOD_SUCCESS_VAL(val) +#define MOD_INIT(name) void Init_##name(void) +#define MOD_DEF(ob, name, doc, methods) ob = Py_InitModule3(name, methods, doc); +#endif + + +#endif // BAREOS_PYTHON_PLUGINS_COMMON_H_ diff --git a/core/src/plugins/python_plugins_common.inc b/core/src/plugins/python_plugins_common.inc new file mode 100644 index 00000000000..e69de29bb2d diff --git a/core/src/plugins/stored/python-sd.h b/core/src/plugins/stored/python-sd.h index eb220b7c705..a52557c2b00 100644 --- a/core/src/plugins/stored/python-sd.h +++ b/core/src/plugins/stored/python-sd.h @@ -27,6 +27,10 @@ #ifndef BAREOS_PLUGINS_STORED_PYTHON_SD_H_ #define BAREOS_PLUGINS_STORED_PYTHON_SD_H_ 1 +/* common code for all python plugins */ +#include "../python_plugins_common.h" +#include "../python_plugins_common.inc" + namespace storagedaemon { /** @@ -76,26 +80,16 @@ static PyMethodDef BareosSDMethods[] = { {NULL, NULL, 0, NULL}}; -#if PY_MAJOR_VERSION >= 3 -#define MOD_ERROR_VAL NULL -#define MOD_SUCCESS_VAL(val) val -#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void) -#define MOD_DEF(ob, name, doc, methods) \ - static struct PyModuleDef moduledef = { \ - PyModuleDef_HEAD_INIT, name, doc, -1, methods, \ - }; \ - ob = PyModule_Create(&moduledef); -#else -#define MOD_ERROR_VAL -#define MOD_SUCCESS_VAL(val) -#define MOD_INIT(name) void Init_##name(void) -#define MOD_DEF(ob, name, doc, methods) ob = Py_InitModule3(name, methods, doc); -#endif - static void* bareos_plugin_context = NULL; MOD_INIT(bareossd) { + /* bareos_plugin_context holds the bpContext instead of passing to Python and + * extracting it back like it was before. bareos_plugin_context needs to be + * set after loading the bareossd binary python module and will be used for + * all calls. + */ + PyObject* BareosSdModule = NULL; /* Pointer Capsules to avoid context transfer back and forth */ @@ -103,7 +97,7 @@ MOD_INIT(bareossd) PyCapsule_New((void*)&bareos_plugin_context, "bareossd.bpContext", NULL); if (!PySdModulePluginContext) { - printf("python-dir.h: PyCapsule_New failed\n"); + printf("python-sd.h: PyCapsule_New failed\n"); return MOD_ERROR_VAL; } From c3f34c9766f37c1bc13bec7d8d3a3efff8d697b7 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 2 Mar 2020 11:52:39 +0100 Subject: [PATCH 014/341] python plugins: have common pVariable definition --- core/src/dird/dir_plugins.h | 12 +-- core/src/filed/fd_plugins.h | 2 +- core/src/plugins/dird/python-dir.cc | 84 +++++++++++---------- core/src/plugins/filed/python-fd.cc | 80 +++++--------------- core/src/plugins/python_plugins_common.h | 2 + core/src/plugins/stored/autoxflate-sd.cc | 8 +- core/src/plugins/stored/python-sd.cc | 41 +++------- core/src/plugins/stored/scsicrypto-sd.cc | 8 +- core/src/plugins/stored/scsitapealert-sd.cc | 8 +- core/src/stored/sd_plugins.h | 12 +-- 10 files changed, 98 insertions(+), 159 deletions(-) diff --git a/core/src/dird/dir_plugins.h b/core/src/dird/dir_plugins.h index e22116c72d5..5fdc6f9790e 100644 --- a/core/src/dird/dir_plugins.h +++ b/core/src/dird/dir_plugins.h @@ -3,7 +3,7 @@ Copyright (C) 2007-2011 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2016 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -182,9 +182,9 @@ bRC GeneratePluginEvent(JobControlRecord* jcr, */ typedef enum { - pDirVarName = 1, - pDirVarDescription = 2 -} pDirVariable; + pVarName = 1, + pVarDescription = 2 +} pVariable; #define DIR_PLUGIN_MAGIC "*DirPluginData*" #define DIR_PLUGIN_INTERFACE_VERSION 4 @@ -194,8 +194,8 @@ typedef struct s_dirpluginFuncs { uint32_t version; bRC (*newPlugin)(bpContext* ctx); bRC (*freePlugin)(bpContext* ctx); - bRC (*getPluginValue)(bpContext* ctx, pDirVariable var, void* value); - bRC (*setPluginValue)(bpContext* ctx, pDirVariable var, void* value); + bRC (*getPluginValue)(bpContext* ctx, pVariable var, void* value); + bRC (*setPluginValue)(bpContext* ctx, pVariable var, void* value); bRC (*handlePluginEvent)(bpContext* ctx, bDirEvent* event, void* value); } pDirFuncs; diff --git a/core/src/filed/fd_plugins.h b/core/src/filed/fd_plugins.h index 8d968ffb4f6..f031d7c5655 100644 --- a/core/src/filed/fd_plugins.h +++ b/core/src/filed/fd_plugins.h @@ -3,7 +3,7 @@ Copyright (C) 2007-2012 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2019 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public diff --git a/core/src/plugins/dird/python-dir.cc b/core/src/plugins/dird/python-dir.cc index 611ac976c93..b8c781badce 100644 --- a/core/src/plugins/dird/python-dir.cc +++ b/core/src/plugins/dird/python-dir.cc @@ -57,19 +57,15 @@ static const int debuglevel = 150; "python:instance=:module_path=:module_" \ "name=" -#define Dmsg(context, level, ...) \ - bfuncs->DebugMessage(context, __FILE__, __LINE__, level, __VA_ARGS__) -#define Jmsg(context, type, ...) \ - bfuncs->JobMessage(context, __FILE__, __LINE__, type, 0, __VA_ARGS__) /* Forward referenced functions */ static bRC newPlugin(bpContext* bareos_plugin_ctx); static bRC freePlugin(bpContext* bareos_plugin_ctx); static bRC getPluginValue(bpContext* bareos_plugin_ctx, - pDirVariable var, + pVariable var, void* value); static bRC setPluginValue(bpContext* bareos_plugin_ctx, - pDirVariable var, + pVariable var, void* value); static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, bDirEvent* event, @@ -82,10 +78,10 @@ static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype); static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value); static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value); static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, - pDirVariable var, + pVariable var, void* value); static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, - pDirVariable var, + pVariable var, void* value); static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, bDirEvent* event, @@ -105,14 +101,14 @@ static pDirFuncs pluginFuncs = { sizeof(pluginFuncs), DIR_PLUGIN_INTERFACE_VERSION, /* Entry points into plugin */ - newPlugin, /* New plugin instance */ - freePlugin, /* Free plugin instance */ + newPlugin, /* new plugin instance */ + freePlugin, /* free plugin instance */ getPluginValue, setPluginValue, handlePluginEvent}; /** * Plugin private context */ -struct plugin_ctx { +struct plugin_private_context { int64_t instance; /* Instance number of plugin */ bool python_loaded; /* Plugin has python module loaded ? */ bool python_path_set; /* Python plugin search path is set ? */ @@ -153,9 +149,7 @@ bRC loadPlugin(bDirInfo* lbinfo, *pinfo = &pluginInfo; /* Return pointer to our info */ *pfuncs = &pluginFuncs; /* Return pointer to our functions */ - /* - * Setup Python - */ + /* Setup Python */ #if PY_MAJOR_VERSION >= 3 PyImport_AppendInittab("bareosdir", &PyInit_bareosdir); #else @@ -186,19 +180,18 @@ bRC unloadPlugin() } #endif +/* Create a new instance of the plugin i.e. allocate our private storage */ static bRC newPlugin(bpContext* bareos_plugin_ctx) { - struct plugin_ctx* plugin_priv_ctx; - - plugin_priv_ctx = (struct plugin_ctx*)malloc(sizeof(struct plugin_ctx)); + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)malloc( + sizeof(struct plugin_private_context)); if (!plugin_priv_ctx) { return bRC_Error; } - memset(plugin_priv_ctx, 0, sizeof(struct plugin_ctx)); + memset(plugin_priv_ctx, 0, sizeof(struct plugin_private_context)); bareos_plugin_ctx->pContext = (void*)plugin_priv_ctx; /* set our context pointer */ - /* - * For each plugin instance we instantiate a new Python interpreter. - */ + /* For each plugin instance we instantiate a new Python interpreter. */ PyEval_AcquireThread(mainThreadState); plugin_priv_ctx->interpreter = Py_NewInterpreter(); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); @@ -212,10 +205,14 @@ static bRC newPlugin(bpContext* bareos_plugin_ctx) return bRC_OK; } +/** + * Release everything concerning a particular instance of a + * plugin. Normally called when the Job terminates. + */ static bRC freePlugin(bpContext* bareos_plugin_ctx) { - struct plugin_ctx* plugin_priv_ctx = - (struct plugin_ctx*)bareos_plugin_ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; if (!plugin_priv_ctx) { return bRC_Error; } @@ -237,28 +234,33 @@ static bRC freePlugin(bpContext* bareos_plugin_ctx) } static bRC getPluginValue(bpContext* bareos_plugin_ctx, - pDirVariable var, + pVariable var, void* value) { - struct plugin_ctx* plugin_priv_ctx = - (struct plugin_ctx*)bareos_plugin_ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; bRC retval = bRC_Error; + if (!plugin_priv_ctx) { goto bail_out; } + PyEval_AcquireThread(plugin_priv_ctx->interpreter); retval = PyGetPluginValue(bareos_plugin_ctx, var, value); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); +bail_out: return retval; } static bRC setPluginValue(bpContext* bareos_plugin_ctx, - pDirVariable var, + pVariable var, void* value) { - struct plugin_ctx* plugin_priv_ctx = - (struct plugin_ctx*)bareos_plugin_ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; bRC retval = bRC_Error; + if (!plugin_priv_ctx) { return bRC_Error; } + PyEval_AcquireThread(plugin_priv_ctx->interpreter); retval = PySetPluginValue(bareos_plugin_ctx, var, value); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); @@ -273,7 +275,8 @@ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, bRC retval = bRC_Error; bool event_dispatched = false; PoolMem plugin_options(PM_FNAME); - plugin_ctx* plugin_priv_ctx = (plugin_ctx*)bareos_plugin_ctx->pContext; + plugin_private_context* plugin_priv_ctx = + (plugin_private_context*)bareos_plugin_ctx->pContext; if (!plugin_priv_ctx) { goto bail_out; } @@ -411,7 +414,8 @@ static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, int i, cnt; PoolMem plugin_definition(PM_FNAME); char *bp, *argument, *argument_value; - plugin_ctx* plugin_priv_ctx = (plugin_ctx*)bareos_plugin_ctx->pContext; + plugin_private_context* plugin_priv_ctx = + (plugin_private_context*)bareos_plugin_ctx->pContext; if (!value) { return bRC_Error; } @@ -634,8 +638,8 @@ static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype) static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; - struct plugin_ctx* plugin_priv_ctx = - (struct plugin_ctx*)bareos_plugin_ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject *sysPath, *mPath, *pName, *pFunc; /* @@ -733,8 +737,8 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; - struct plugin_ctx* plugin_priv_ctx = - (struct plugin_ctx*)bareos_plugin_ctx->pContext; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; /* @@ -774,14 +778,14 @@ static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) } static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, - pDirVariable var, + pVariable var, void* value) { return bRC_OK; } static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, - pDirVariable var, + pVariable var, void* value) { return bRC_OK; @@ -792,7 +796,8 @@ static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; - plugin_ctx* plugin_priv_ctx = (plugin_ctx*)bareos_plugin_ctx->pContext; + plugin_private_context* plugin_priv_ctx = + (plugin_private_context*)bareos_plugin_ctx->pContext; PyObject* pFunc; /* @@ -977,7 +982,6 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) char* dbgmsg = NULL; bpContext* bareos_plugin_ctx; - if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; } @@ -1002,7 +1006,6 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) char* jobmsg = NULL; bpContext* bareos_plugin_ctx; - if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; } @@ -1107,7 +1110,6 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; bpContext* bareos_plugin_ctx = NULL; - PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } diff --git a/core/src/plugins/filed/python-fd.cc b/core/src/plugins/filed/python-fd.cc index 8326d1b7e3b..1ed0d15e054 100644 --- a/core/src/plugins/filed/python-fd.cc +++ b/core/src/plugins/filed/python-fd.cc @@ -37,7 +37,6 @@ #endif #include "filed/fd_plugins.h" -#include "plugins/filed/fd_common.h" #include "python-fd.h" namespace filedaemon { @@ -57,9 +56,7 @@ static const int debuglevel = 150; "python:module_path=:module_name=:..." -/** - * Forward referenced functions - */ +/* Forward referenced functions */ static bRC newPlugin(bpContext* bareos_plugin_ctx); static bRC freePlugin(bpContext* bareos_plugin_ctx); static bRC getPluginValue(bpContext* bareos_plugin_ctx, @@ -118,9 +115,7 @@ static bRC PyRestoreObjectData(bpContext* bareos_plugin_ctx, static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp); -/** - * Pointers to Bareos functions - */ +/* Pointers to Bareos functions */ static bFuncs* bfuncs = NULL; static bInfo* binfo = NULL; @@ -228,11 +223,8 @@ static bRC newPlugin(bpContext* bareos_plugin_ctx) struct plugin_private_context* plugin_priv_ctx = (struct plugin_private_context*)malloc( sizeof(struct plugin_private_context)); - if (!plugin_priv_ctx) { return bRC_Error; } - memset(plugin_priv_ctx, 0, sizeof(struct plugin_private_context)); - bareos_plugin_ctx->pContext = (void*)plugin_priv_ctx; /* set our context pointer */ @@ -295,10 +287,6 @@ static bRC freePlugin(bpContext* bareos_plugin_ctx) return bRC_OK; } -/** - * Called by core code to get a variable from the plugin. - * Not currently used. - */ static bRC getPluginValue(bpContext* bareos_plugin_ctx, pVariable var, void* value) @@ -317,10 +305,6 @@ static bRC getPluginValue(bpContext* bareos_plugin_ctx, return retval; } -/** - * Called by core code to set a plugin variable. - * Not currently used. - */ static bRC setPluginValue(bpContext* bareos_plugin_ctx, pVariable var, void* value) @@ -338,10 +322,6 @@ static bRC setPluginValue(bpContext* bareos_plugin_ctx, return retval; } -/** - * Called by Bareos when there are certain events that the - * plugin might want to know. The value depends on the event. - */ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, bEvent* event, void* value) @@ -370,22 +350,16 @@ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, * Fall-through wanted */ case bEventRestoreCommand: - /* - * Fall-through wanted - */ + /* Fall-through wanted */ case bEventEstimateCommand: - /* - * Fall-through wanted - */ + /* Fall-through wanted */ case bEventPluginCommand: event_dispatched = true; retval = parse_plugin_definition(bareos_plugin_ctx, value, plugin_options); break; case bEventNewPluginOptions: - /* - * Free any previous value. - */ + /* Free any previous value. */ if (plugin_priv_ctx->plugin_options) { free(plugin_priv_ctx->plugin_options); plugin_priv_ctx->plugin_options = NULL; @@ -395,9 +369,7 @@ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, retval = parse_plugin_definition(bareos_plugin_ctx, value, plugin_options); - /* - * Save that we got a plugin override. - */ + /* Save that we got a plugin override. */ plugin_priv_ctx->plugin_options = strdup((char*)value); break; case bEventRestoreObject: { @@ -405,10 +377,8 @@ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, rop = (struct restore_object_pkt*)value; - /* - * Only use the plugin definition of a restore object if we - * didn't get any other plugin definition from some other source before. - */ + /* Only use the plugin definition of a restore object if we + * didn't get any other plugin definition from some other source before.*/ if (!plugin_priv_ctx->python_loaded) { if (rop && *rop->plugin_name) { event_dispatched = true; @@ -426,7 +396,7 @@ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, * See if we have been triggered in the previous switch if not we have to * always dispatch the event. If we already processed the event internally * we only do a dispatch to the python entry point when that internal - * processing was successfull (e.g. retval == bRC_OK). + * processing was successful (e.g. retval == bRC_OK). */ if (!event_dispatched || retval == bRC_OK) { PyEval_AcquireThread(plugin_priv_ctx->interpreter); @@ -437,32 +407,20 @@ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, */ switch (event->eventType) { case bEventBackupCommand: - /* - * Fall-through wanted - */ + /* Fall-through wanted */ case bEventRestoreCommand: - /* - * Fall-through wanted - */ + /* Fall-through wanted */ case bEventEstimateCommand: - /* - * Fall-through wanted - */ + /* Fall-through wanted */ case bEventPluginCommand: - /* - * Fall-through wanted - */ + /* Fall-through wanted */ case bEventNewPluginOptions: - /* - * See if we already loaded the Python modules. - */ + /* See if we already loaded the Python modules. */ if (!plugin_priv_ctx->python_loaded) { retval = PyLoadModule(bareos_plugin_ctx, plugin_options.c_str()); } - /* - * Only try to call when the loading succeeded. - */ + /* Only try to call when the loading succeeded. */ if (retval == bRC_OK) { retval = PyParsePluginDefinition(bareos_plugin_ctx, plugin_options.c_str()); @@ -479,15 +437,11 @@ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, */ retval = bRC_OK; } else { - /* - * See if we already loaded the Python modules. - */ + /* See if we already loaded the Python modules. */ if (!plugin_priv_ctx->python_loaded && *rop->plugin_name) { retval = PyLoadModule(bareos_plugin_ctx, plugin_options.c_str()); - /* - * Only try to call when the loading succeeded. - */ + /* Only try to call when the loading succeeded. */ if (retval == bRC_OK) { retval = PyParsePluginDefinition(bareos_plugin_ctx, plugin_options.c_str()); diff --git a/core/src/plugins/python_plugins_common.h b/core/src/plugins/python_plugins_common.h index d2a88129526..047fce9a2cd 100644 --- a/core/src/plugins/python_plugins_common.h +++ b/core/src/plugins/python_plugins_common.h @@ -20,5 +20,7 @@ #define MOD_DEF(ob, name, doc, methods) ob = Py_InitModule3(name, methods, doc); #endif +#include "plugins/filed/fd_common.h" + #endif // BAREOS_PYTHON_PLUGINS_COMMON_H_ diff --git a/core/src/plugins/stored/autoxflate-sd.cc b/core/src/plugins/stored/autoxflate-sd.cc index ff3d7df5fe3..afc42fd0817 100644 --- a/core/src/plugins/stored/autoxflate-sd.cc +++ b/core/src/plugins/stored/autoxflate-sd.cc @@ -66,8 +66,8 @@ using namespace storagedaemon; */ static bRC newPlugin(bpContext* ctx); static bRC freePlugin(bpContext* ctx); -static bRC getPluginValue(bpContext* ctx, psdVariable var, void* value); -static bRC setPluginValue(bpContext* ctx, psdVariable var, void* value); +static bRC getPluginValue(bpContext* ctx, pVariable var, void* value); +static bRC setPluginValue(bpContext* ctx, pVariable var, void* value); static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value); static bRC handleJobEnd(bpContext* ctx); static bRC setup_record_translation(bpContext* ctx, void* value); @@ -221,7 +221,7 @@ static bRC freePlugin(bpContext* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bpContext* ctx, psdVariable var, void* value) +static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) { Dmsg(ctx, debuglevel, "autoxflate-sd: getPluginValue var=%d\n", var); @@ -231,7 +231,7 @@ static bRC getPluginValue(bpContext* ctx, psdVariable var, void* value) /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bpContext* ctx, psdVariable var, void* value) +static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) { Dmsg(ctx, debuglevel, "autoxflate-sd: setPluginValue var=%d\n", var); diff --git a/core/src/plugins/stored/python-sd.cc b/core/src/plugins/stored/python-sd.cc index 261af0e834a..98f6d1e9f62 100644 --- a/core/src/plugins/stored/python-sd.cc +++ b/core/src/plugins/stored/python-sd.cc @@ -63,10 +63,10 @@ static const int debuglevel = 150; static bRC newPlugin(bpContext* bareos_plugin_ctx); static bRC freePlugin(bpContext* bareos_plugin_ctx); static bRC getPluginValue(bpContext* bareos_plugin_ctx, - psdVariable var, + pVariable var, void* value); static bRC setPluginValue(bpContext* bareos_plugin_ctx, - psdVariable var, + pVariable var, void* value); static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, bsdEvent* event, @@ -79,10 +79,10 @@ static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype); static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value); static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value); static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, - psdVariable var, + pVariable var, void* value); static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, - psdVariable var, + pVariable var, void* value); static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, bsdEvent* event, @@ -121,7 +121,6 @@ struct plugin_private_context { PyObject* pyModuleFunctionsDict; /* Python Dictionary */ }; - /** * We don't actually use this but we need it to tear down the * final python interpreter on unload of the plugin. Each instance of @@ -182,14 +181,7 @@ bRC unloadPlugin() } #endif -/** - * The following entry points are accessed through the function - * pointers we supplied to Bareos. Each plugin type (dir, fd, sd) - * has its own set of entry points that the plugin must define. - */ -/** - * Create a new instance of the plugin i.e. allocate our private storage - */ +/* Create a new instance of the plugin i.e. allocate our private storage */ static bRC newPlugin(bpContext* bareos_plugin_ctx) { struct plugin_private_context* plugin_priv_ctx; @@ -217,9 +209,7 @@ static bRC newPlugin(bpContext* bareos_plugin_ctx) return bRC_OK; } -/** - * Free a plugin instance, i.e. release our private storage - */ +/* Free a plugin instance, i.e. release our private storage */ static bRC freePlugin(bpContext* bareos_plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = @@ -244,11 +234,8 @@ static bRC freePlugin(bpContext* bareos_plugin_ctx) return bRC_OK; } -/** - * Return some plugin value (none defined) - */ static bRC getPluginValue(bpContext* bareos_plugin_ctx, - psdVariable var, + pVariable var, void* value) { struct plugin_private_context* plugin_priv_ctx = @@ -262,11 +249,8 @@ static bRC getPluginValue(bpContext* bareos_plugin_ctx, return retval; } -/** - * Set a plugin value (none defined) - */ static bRC setPluginValue(bpContext* bareos_plugin_ctx, - psdVariable var, + pVariable var, void* value) { struct plugin_private_context* plugin_priv_ctx = @@ -280,9 +264,6 @@ static bRC setPluginValue(bpContext* bareos_plugin_ctx, return retval; } -/** - * Handle an event that was generated in Bareos - */ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, bsdEvent* event, void* value) @@ -313,7 +294,7 @@ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, * See if we have been triggered in the previous switch if not we have to * always dispatch the event. If we already processed the event internally * we only do a dispatch to the python entry point when that internal - * processing was successfull (e.g. retval == bRC_OK). + * processing was successful (e.g. retval == bRC_OK). */ if (!event_dispatched || retval == bRC_OK) { PyEval_AcquireThread(plugin_priv_ctx->interpreter); @@ -793,14 +774,14 @@ static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) } static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, - psdVariable var, + pVariable var, void* value) { return bRC_OK; } static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, - psdVariable var, + pVariable var, void* value) { return bRC_OK; diff --git a/core/src/plugins/stored/scsicrypto-sd.cc b/core/src/plugins/stored/scsicrypto-sd.cc index 37b8f2478b7..1357d68d72b 100644 --- a/core/src/plugins/stored/scsicrypto-sd.cc +++ b/core/src/plugins/stored/scsicrypto-sd.cc @@ -82,8 +82,8 @@ using namespace storagedaemon; */ static bRC newPlugin(bpContext* ctx); static bRC freePlugin(bpContext* ctx); -static bRC getPluginValue(bpContext* ctx, psdVariable var, void* value); -static bRC setPluginValue(bpContext* ctx, psdVariable var, void* value); +static bRC getPluginValue(bpContext* ctx, pVariable var, void* value); +static bRC setPluginValue(bpContext* ctx, pVariable var, void* value); static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value); static bRC do_set_scsi_encryption_key(void* value); static bRC do_clear_scsi_encryption_key(void* value); @@ -215,7 +215,7 @@ static bRC freePlugin(bpContext* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bpContext* ctx, psdVariable var, void* value) +static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) { Dmsg1(debuglevel, "scsicrypto-sd: getPluginValue var=%d\n", var); @@ -225,7 +225,7 @@ static bRC getPluginValue(bpContext* ctx, psdVariable var, void* value) /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bpContext* ctx, psdVariable var, void* value) +static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) { Dmsg1(debuglevel, "scsicrypto-sd: setPluginValue var=%d\n", var); diff --git a/core/src/plugins/stored/scsitapealert-sd.cc b/core/src/plugins/stored/scsitapealert-sd.cc index 02cdda2e7c4..a4b989706df 100644 --- a/core/src/plugins/stored/scsitapealert-sd.cc +++ b/core/src/plugins/stored/scsitapealert-sd.cc @@ -45,8 +45,8 @@ using namespace storagedaemon; */ static bRC newPlugin(bpContext* ctx); static bRC freePlugin(bpContext* ctx); -static bRC getPluginValue(bpContext* ctx, psdVariable var, void* value); -static bRC setPluginValue(bpContext* ctx, psdVariable var, void* value); +static bRC getPluginValue(bpContext* ctx, pVariable var, void* value); +static bRC setPluginValue(bpContext* ctx, pVariable var, void* value); static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value); static bRC handle_tapealert_readout(void* value); @@ -149,7 +149,7 @@ static bRC freePlugin(bpContext* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bpContext* ctx, psdVariable var, void* value) +static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) { Dmsg1(debuglevel, "scsitapealert-sd: getPluginValue var=%d\n", var); @@ -159,7 +159,7 @@ static bRC getPluginValue(bpContext* ctx, psdVariable var, void* value) /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bpContext* ctx, psdVariable var, void* value) +static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) { Dmsg1(debuglevel, "scsitapealert-sd: setPluginValue var=%d\n", var); diff --git a/core/src/stored/sd_plugins.h b/core/src/stored/sd_plugins.h index 8c495271477..64dfc345b22 100644 --- a/core/src/stored/sd_plugins.h +++ b/core/src/stored/sd_plugins.h @@ -3,7 +3,7 @@ Copyright (C) 2007-2011 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2016 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -198,9 +198,9 @@ bRC GeneratePluginEvent(JobControlRecord* jcr, typedef enum { - psdVarName = 1, - psdVarDescription = 2 -} psdVariable; + pVarName = 1, + pVarDescription = 2 +} pVariable; #define SD_PLUGIN_MAGIC "*SDPluginData*" #define SD_PLUGIN_INTERFACE_VERSION 4 @@ -213,8 +213,8 @@ typedef struct s_sdpluginFuncs { uint32_t version; bRC (*newPlugin)(bpContext* ctx); bRC (*freePlugin)(bpContext* ctx); - bRC (*getPluginValue)(bpContext* ctx, psdVariable var, void* value); - bRC (*setPluginValue)(bpContext* ctx, psdVariable var, void* value); + bRC (*getPluginValue)(bpContext* ctx, pVariable var, void* value); + bRC (*setPluginValue)(bpContext* ctx, pVariable var, void* value); bRC (*handlePluginEvent)(bpContext* ctx, bsdEvent* event, void* value); } psdFuncs; From 2bb46c9bf7458e633339185fdf057bd8f21ffa5b Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 2 Mar 2020 14:47:46 +0100 Subject: [PATCH 015/341] python plugins: moved common functions to python_plugins_common.inc With the macro PYTHON_MODULE_NAME more functions can be used in common. --- core/src/plugins/dird/python-dir.cc | 152 +------------------- core/src/plugins/dird/python-dir.h | 31 ++-- core/src/plugins/filed/python-fd.cc | 141 ++---------------- core/src/plugins/filed/python-fd.h | 50 ++++--- core/src/plugins/python_plugins_common.h | 2 + core/src/plugins/python_plugins_common.inc | 143 ++++++++++++++++++ core/src/plugins/stored/python-sd.cc | 160 ++------------------- core/src/plugins/stored/python-sd.h | 31 ++-- 8 files changed, 228 insertions(+), 482 deletions(-) diff --git a/core/src/plugins/dird/python-dir.cc b/core/src/plugins/dird/python-dir.cc index b8c781badce..bb4fe0b64f5 100644 --- a/core/src/plugins/dird/python-dir.cc +++ b/core/src/plugins/dird/python-dir.cc @@ -34,7 +34,6 @@ #include #include "include/bareos.h" #endif - #include "dird/dird.h" #if (PY_VERSION_HEX < 0x02060000) @@ -127,10 +126,14 @@ struct plugin_private_context { */ static PyThreadState* mainThreadState; +/* functions common to all plugins */ +#include "../python_plugins_common.inc" + #ifdef __cplusplus extern "C" { #endif + /** * loadPlugin() and unloadPlugin() are entry points that are * exported, so Bareos can directly call these two entry points @@ -205,10 +208,7 @@ static bRC newPlugin(bpContext* bareos_plugin_ctx) return bRC_OK; } -/** - * Release everything concerning a particular instance of a - * plugin. Normally called when the Job terminates. - */ +/* Free a plugin instance, i.e. release our private storage */ static bRC freePlugin(bpContext* bareos_plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = @@ -233,40 +233,6 @@ static bRC freePlugin(bpContext* bareos_plugin_ctx) return bRC_OK; } -static bRC getPluginValue(bpContext* bareos_plugin_ctx, - pVariable var, - void* value) -{ - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; - bRC retval = bRC_Error; - - if (!plugin_priv_ctx) { goto bail_out; } - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyGetPluginValue(bareos_plugin_ctx, var, value); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - -bail_out: - return retval; -} - -static bRC setPluginValue(bpContext* bareos_plugin_ctx, - pVariable var, - void* value) -{ - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; - bRC retval = bRC_Error; - - if (!plugin_priv_ctx) { return bRC_Error; } - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PySetPluginValue(bareos_plugin_ctx, var, value); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - - return retval; -} static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, bDirEvent* event, @@ -316,9 +282,7 @@ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, retval = PyLoadModule(bareos_plugin_ctx, plugin_options.c_str()); } - /* - * Only try to call when the loading succeeded. - */ + /* Only try to call when the loading succeeded. */ if (retval == bRC_OK) { retval = PyParsePluginDefinition(bareos_plugin_ctx, plugin_options.c_str()); @@ -345,59 +309,6 @@ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, return retval; } -/** - * Strip any backslashes in the string. - */ -static inline void StripBackSlashes(char* value) -{ - char* bp; - - bp = value; - while (*bp) { - switch (*bp) { - case '\\': - bstrinlinecpy(bp, bp + 1); - break; - default: - break; - } - - bp++; - } -} - -/** - * Parse a integer value. - */ -static inline int64_t parse_integer(const char* argument_value) -{ - return str_to_int64(argument_value); -} - -/** - * Parse a boolean value e.g. check if its yes or true anything else translates - * to false. - */ -static inline bool ParseBoolean(const char* argument_value) -{ - if (Bstrcasecmp(argument_value, "yes") || - Bstrcasecmp(argument_value, "true")) { - return true; - } else { - return false; - } -} - -/** - * Always set destination to value and clean any previous one. - */ -static inline void SetString(char** destination, char* value) -{ - if (*destination) { free(*destination); } - - *destination = strdup(value); - StripBackSlashes(*destination); -} /** * Parse the plugin definition passed in. @@ -576,57 +487,6 @@ static inline PyObject* conv_retval_python(bRC retval) return (PyObject*)PyInt_FromLong((int)retval); } -/** - * Handle a Python error. - * - * Python equivalent: - * - * import traceback, sys - * return "".join(traceback.format_exception(sys.exc_type, - * sys.exc_value, sys.exc_traceback)) - */ -static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype) -{ - PyObject *type, *value, *traceback; - PyObject* tracebackModule; - char* error_string; - - PyErr_Fetch(&type, &value, &traceback); - - tracebackModule = PyImport_ImportModule("traceback"); - if (tracebackModule != NULL) { - PyObject *tbList, *emptyString, *strRetval; - - tbList = - PyObject_CallMethod(tracebackModule, (char*)"format_exception", - (char*)"OOO", type, value == NULL ? Py_None : value, - traceback == NULL ? Py_None : traceback); - - emptyString = PyString_FromString(""); - strRetval = - PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); - - error_string = strdup(PyString_AsString(strRetval)); - - Py_DECREF(tbList); - Py_DECREF(emptyString); - Py_DECREF(strRetval); - Py_DECREF(tracebackModule); - } else { - error_string = strdup("Unable to import traceback module."); - } - - Py_DECREF(type); - Py_XDECREF(value); - Py_XDECREF(traceback); - - Dmsg(bareos_plugin_ctx, debuglevel, "python-dir: %s\n", error_string); - if (msgtype) { - Jmsg(bareos_plugin_ctx, msgtype, "python-dir: %s\n", error_string); - } - - free(error_string); -} /** * Initial load of the Python module. diff --git a/core/src/plugins/dird/python-dir.h b/core/src/plugins/dird/python-dir.h index 459f1dd2db8..9d09512c67f 100644 --- a/core/src/plugins/dird/python-dir.h +++ b/core/src/plugins/dird/python-dir.h @@ -27,9 +27,10 @@ #ifndef BAREOS_PLUGINS_DIRD_PYTHON_DIR_H_ #define BAREOS_PLUGINS_DIRD_PYTHON_DIR_H_ 1 +#define PYTHON_MODULE_NAME bareosdir + /* common code for all python plugins */ #include "../python_plugins_common.h" -#include "../python_plugins_common.inc" namespace directordaemon { @@ -65,7 +66,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args); static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args); static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args); -static PyMethodDef BareosDIRMethods[] = { +static PyMethodDef Methods[] = { {"GetValue", PyBareosGetValue, METH_VARARGS, "Get a Plugin value"}, {"SetValue", PyBareosSetValue, METH_VARARGS, "Set a Plugin value"}, {"DebugMessage", PyBareosDebugMessage, METH_VARARGS, @@ -82,35 +83,37 @@ static PyMethodDef BareosDIRMethods[] = { static void* bareos_plugin_context = NULL; +// MOD_INIT(PYTHON_MODULE_NAME) MOD_INIT(bareosdir) { /* bareos_plugin_context holds the bpContext instead of passing to Python and * extracting it back like it was before. bareos_plugin_context needs to be - * set after loading the bareosdir binary python module and will be used for - * all calls. + * set after loading the PYTHON_MODULE_NAME binary python module and will be + * used for all calls. */ - PyObject* BareosDirModule = NULL; + PyObject* m = NULL; /* Pointer Capsules to avoid context transfer back and forth */ - PyObject* PyDirModulePluginContext = - PyCapsule_New((void*)&bareos_plugin_context, "bareosdir.bpContext", NULL); + PyObject* PyModulePluginContext = + PyCapsule_New((void*)&bareos_plugin_context, + Quote(PYTHON_MODULE_NAME) ".bpContext", NULL); - if (!PyDirModulePluginContext) { - printf("python-dir.h: PyCapsule_New failed\n"); + if (!PyModulePluginContext) { + printf(Quote(PYTHON_MODULE_NAME) ": PyCapsule_New failed\n"); return MOD_ERROR_VAL; } - MOD_DEF(BareosDirModule, "bareosdir", NULL, BareosDIRMethods) + MOD_DEF(m, Quote(PYTHON_MODULE_NAME), NULL, Methods) - if (PyDirModulePluginContext) { - PyModule_AddObject(BareosDirModule, "bpContext", PyDirModulePluginContext); + if (PyModulePluginContext) { + PyModule_AddObject(m, "bpContext", PyModulePluginContext); } else { - printf("python-dir.h:PyModule_AddObject failed\n"); + printf(Quote(PYTHON_MODULE_NAME) ":PyModule_AddObject failed\n"); return MOD_ERROR_VAL; } - return MOD_SUCCESS_VAL(BareosDirModule); + return MOD_SUCCESS_VAL(m); } } /* namespace directordaemon */ diff --git a/core/src/plugins/filed/python-fd.cc b/core/src/plugins/filed/python-fd.cc index 1ed0d15e054..5268e29813c 100644 --- a/core/src/plugins/filed/python-fd.cc +++ b/core/src/plugins/filed/python-fd.cc @@ -37,14 +37,17 @@ #endif #include "filed/fd_plugins.h" -#include "python-fd.h" -namespace filedaemon { #if (PY_VERSION_HEX < 0x02060000) #error "Need at least Python version 2.6 or newer" #endif +#include "python-fd.h" +#include "lib/edit.h" + +namespace filedaemon { + static const int debuglevel = 150; #define PLUGIN_LICENSE "Bareos AGPLv3" @@ -160,6 +163,9 @@ struct plugin_private_context { */ static PyThreadState* mainThreadState; +/* functions common to all plugins */ +#include "../python_plugins_common.inc" + #ifdef __cplusplus extern "C" { #endif @@ -287,40 +293,6 @@ static bRC freePlugin(bpContext* bareos_plugin_ctx) return bRC_OK; } -static bRC getPluginValue(bpContext* bareos_plugin_ctx, - pVariable var, - void* value) -{ - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; - bRC retval = bRC_Error; - - if (!plugin_priv_ctx) { goto bail_out; } - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyGetPluginValue(bareos_plugin_ctx, var, value); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - -bail_out: - return retval; -} - -static bRC setPluginValue(bpContext* bareos_plugin_ctx, - pVariable var, - void* value) -{ - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; - bRC retval = bRC_Error; - - if (!plugin_priv_ctx) { return bRC_Error; } - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PySetPluginValue(bareos_plugin_ctx, var, value); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - - return retval; -} static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, bEvent* event, @@ -751,41 +723,6 @@ static bRC setXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) return retval; } -/** - * Strip any backslashes in the string. - */ -static inline void StripBackSlashes(char* value) -{ - char* bp; - - bp = value; - while (*bp) { - switch (*bp) { - case '\\': - bstrinlinecpy(bp, bp + 1); - break; - default: - break; - } - - bp++; - } -} - -/** - * Parse a boolean value e.g. check if its yes or true anything else translates - * to false. - */ -static inline bool ParseBoolean(const char* argument_value) -{ - if (Bstrcasecmp(argument_value, "yes") || - Bstrcasecmp(argument_value, "true")) { - return true; - } else { - return false; - } -} - /** * Only set destination to value when it has no previous setting. */ @@ -797,17 +734,6 @@ static inline void SetStringIfNull(char** destination, char* value) } } -/** - * Always set destination to value and clean any previous one. - */ -static inline void SetString(char** destination, char* value) -{ - if (*destination) { free(*destination); } - - *destination = strdup(value); - StripBackSlashes(*destination); -} - /** * Parse the plugin definition passed in. * @@ -1041,57 +967,6 @@ static inline PyObject* conv_retval_python(bRC retval) return (PyObject*)PyInt_FromLong((int)retval); } -/** - * Handle a Python error. - * - * Python equivalent: - * - * import traceback, sys - * return "".join(traceback.format_exception(sys.exc_type, - * sys.exc_value, sys.exc_traceback)) - */ -static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype) -{ - PyObject *type, *value, *traceback; - PyObject* tracebackModule; - char* error_string; - - PyErr_Fetch(&type, &value, &traceback); - - tracebackModule = PyImport_ImportModule("traceback"); - if (tracebackModule != NULL) { - PyObject *tbList, *emptyString, *strRetval; - - tbList = - PyObject_CallMethod(tracebackModule, (char*)"format_exception", - (char*)"OOO", type, value == NULL ? Py_None : value, - traceback == NULL ? Py_None : traceback); - - emptyString = PyString_FromString(""); - strRetval = - PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); - - error_string = strdup(PyString_AsString(strRetval)); - - Py_DECREF(tbList); - Py_DECREF(emptyString); - Py_DECREF(strRetval); - Py_DECREF(tracebackModule); - } else { - error_string = strdup("Unable to import traceback module."); - } - - Py_DECREF(type); - Py_XDECREF(value); - Py_XDECREF(traceback); - - Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: %s\n", error_string); - if (msgtype) { - Jmsg(bareos_plugin_ctx, msgtype, "python-fd: %s\n", error_string); - } - - free(error_string); -} /** * Initial load of the Python module. diff --git a/core/src/plugins/filed/python-fd.h b/core/src/plugins/filed/python-fd.h index f7b9bbe3290..008d5c59e8f 100644 --- a/core/src/plugins/filed/python-fd.h +++ b/core/src/plugins/filed/python-fd.h @@ -27,9 +27,10 @@ #ifndef BAREOS_PLUGINS_FILED_PYTHON_FD_H_ #define BAREOS_PLUGINS_FILED_PYTHON_FD_H_ 1 +#define PYTHON_MODULE_NAME bareosfd + /* common code for all python plugins */ #include "../python_plugins_common.h" -#include "../python_plugins_common.inc" #include "structmember.h" @@ -714,7 +715,7 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args); static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args); static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args); -static PyMethodDef BareosFDMethods[] = { +static PyMethodDef Methods[] = { {"GetValue", PyBareosGetValue, METH_VARARGS, "Get a Plugin value"}, {"SetValue", PyBareosSetValue, METH_VARARGS, "Set a Plugin value"}, {"DebugMessage", PyBareosDebugMessage, METH_VARARGS, @@ -748,31 +749,33 @@ static PyMethodDef BareosFDMethods[] = { static void* bareos_plugin_context = NULL; +// MOD_INIT(PYTHON_MODULE_NAME) MOD_INIT(bareosfd) { /* bareos_plugin_context holds the bpContext instead of passing to Python and * extracting it back like it was before. bareos_plugin_context needs to be - * set after loading the bareosfd binary python module and will be used for - * all calls. + * set after loading the PYTHON_MODULE_NAME binary python module and will be + * used for all calls. */ - PyObject* BareosFdModule = NULL; + PyObject* m = NULL; /* Pointer Capsules to avoid context transfer back and forth */ - PyObject* PyFdModulePluginContext = - PyCapsule_New((void*)&bareos_plugin_"bareosfd.bpContext", NULL); + PyObject* PyModulePluginContext = + PyCapsule_New((void*)&bareos_plugin_context, + Quote(PYTHON_MODULE_NAME) ".bpContext", NULL); - if (!PyFdModulePluginContext) { - printf("python-fd.h: PyCapsule_New failed\n"); + if (!PyModulePluginContext) { + printf(Quote(PYTHON_MODULE_NAME) ": PyCapsule_New failed\n"); return MOD_ERROR_VAL; } - MOD_DEF(BareosFdModule, "bareosfd", NULL, BareosFDMethods) + MOD_DEF(m, Quote(PYTHON_MODULE_NAME), NULL, Methods) - if (PyFdModulePluginContext) { - PyModule_AddObject(BareosFdModule, "bpContext", PyFdModulePluginContext); + if (PyModulePluginContext) { + PyModule_AddObject(m, "bpContext", PyModulePluginContext); } else { - printf("python-fd.h:PyModule_AddObject failed\n"); + printf(Quote(PYTHON_MODULE_NAME) ":PyModule_AddObject failed\n"); return MOD_ERROR_VAL; } @@ -799,32 +802,27 @@ MOD_INIT(bareosfd) if (PyType_Ready(&PyXattrPacketType) < 0) { return MOD_ERROR_VAL; } Py_INCREF(&PyRestoreObjectType); - PyModule_AddObject(BareosFdModule, "RestoreObject", - (PyObject*)&PyRestoreObjectType); + PyModule_AddObject(m, "RestoreObject", (PyObject*)&PyRestoreObjectType); Py_INCREF(&PyStatPacketType); - PyModule_AddObject(BareosFdModule, "StatPacket", - (PyObject*)&PyStatPacketType); + PyModule_AddObject(m, "StatPacket", (PyObject*)&PyStatPacketType); Py_INCREF(&PySavePacketType); - PyModule_AddObject(BareosFdModule, "SavePacket", - (PyObject*)&PySavePacketType); + PyModule_AddObject(m, "SavePacket", (PyObject*)&PySavePacketType); Py_INCREF(&PyRestorePacketType); - PyModule_AddObject(BareosFdModule, "RestorePacket", - (PyObject*)&PyRestorePacketType); + PyModule_AddObject(m, "RestorePacket", (PyObject*)&PyRestorePacketType); Py_INCREF(&PyIoPacketType); - PyModule_AddObject(BareosFdModule, "IoPacket", (PyObject*)&PyIoPacketType); + PyModule_AddObject(m, "IoPacket", (PyObject*)&PyIoPacketType); Py_INCREF(&PyAclPacketType); - PyModule_AddObject(BareosFdModule, "AclPacket", (PyObject*)&PyAclPacketType); + PyModule_AddObject(m, "AclPacket", (PyObject*)&PyAclPacketType); Py_INCREF(&PyXattrPacketType); - PyModule_AddObject(BareosFdModule, "XattrPacket", - (PyObject*)&PyXattrPacketType); + PyModule_AddObject(m, "XattrPacket", (PyObject*)&PyXattrPacketType); - return MOD_SUCCESS_VAL(BareosFdModule); + return MOD_SUCCESS_VAL(m); } } /* namespace filedaemon */ #endif /* BAREOS_PLUGINS_FILED_PYTHON_FD_H_ */ diff --git a/core/src/plugins/python_plugins_common.h b/core/src/plugins/python_plugins_common.h index 047fce9a2cd..a18f2a8aec2 100644 --- a/core/src/plugins/python_plugins_common.h +++ b/core/src/plugins/python_plugins_common.h @@ -20,6 +20,8 @@ #define MOD_DEF(ob, name, doc, methods) ob = Py_InitModule3(name, methods, doc); #endif +#define Quote(macro) #macro + #include "plugins/filed/fd_common.h" diff --git a/core/src/plugins/python_plugins_common.inc b/core/src/plugins/python_plugins_common.inc index e69de29bb2d..614898d3489 100644 --- a/core/src/plugins/python_plugins_common.inc +++ b/core/src/plugins/python_plugins_common.inc @@ -0,0 +1,143 @@ + +static bRC getPluginValue(bpContext* bareos_plugin_ctx, + pVariable var, + void* value) +{ + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; + bRC retval = bRC_Error; + + if (!plugin_priv_ctx) { goto bail_out; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyGetPluginValue(bareos_plugin_ctx, var, value); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + +bail_out: + return retval; +} + +static bRC setPluginValue(bpContext* bareos_plugin_ctx, + pVariable var, + void* value) +{ + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; + bRC retval = bRC_Error; + + if (!plugin_priv_ctx) { return bRC_Error; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PySetPluginValue(bareos_plugin_ctx, var, value); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + + return retval; +} + + +/** + * Strip any backslashes in the string. + */ +static inline void StripBackSlashes(char* value) +{ + char* bp; + + bp = value; + while (*bp) { + switch (*bp) { + case '\\': + bstrinlinecpy(bp, bp + 1); + break; + default: + break; + } + + bp++; + } +} + +/** + * Parse a boolean value e.g. check if its yes or true anything else translates + * to false. + */ +static inline bool ParseBoolean(const char* argument_value) +{ + if (Bstrcasecmp(argument_value, "yes") || + Bstrcasecmp(argument_value, "true")) { + return true; + } else { + return false; + } +} + +/** + * Parse a integer value. + */ +static inline int64_t parse_integer(const char* argument_value) +{ + return str_to_int64(argument_value); +} + +/** + * Always set destination to value and clean any previous one. + */ +static inline void SetString(char** destination, char* value) +{ + if (*destination) { free(*destination); } + + *destination = strdup(value); + StripBackSlashes(*destination); +} + + +/** + * Handle a Python error. + * + * Python equivalent: + * + * import traceback, sys + * return "".join(traceback.format_exception(sys.exc_type, + * sys.exc_value, sys.exc_traceback)) + */ +static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype) +{ + PyObject *type, *value, *traceback; + PyObject* tracebackModule; + char* error_string; + + PyErr_Fetch(&type, &value, &traceback); + + tracebackModule = PyImport_ImportModule("traceback"); + if (tracebackModule != NULL) { + PyObject *tbList, *emptyString, *strRetval; + + tbList = + PyObject_CallMethod(tracebackModule, (char*)"format_exception", + (char*)"OOO", type, value == NULL ? Py_None : value, + traceback == NULL ? Py_None : traceback); + + emptyString = PyString_FromString(""); + strRetval = + PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); + + error_string = strdup(PyString_AsString(strRetval)); + + Py_DECREF(tbList); + Py_DECREF(emptyString); + Py_DECREF(strRetval); + Py_DECREF(tracebackModule); + } else { + error_string = strdup("Unable to import traceback module."); + } + + Py_DECREF(type); + Py_XDECREF(value); + Py_XDECREF(traceback); + + Dmsg(bareos_plugin_ctx, debuglevel, Quote(PYTHON_MODULE_NAME) ": %s\n", error_string); + if (msgtype) { + Jmsg(bareos_plugin_ctx, msgtype, Quote(PYTHON_MODULE_NAME) ": %s\n", error_string); + } + + free(error_string); +} diff --git a/core/src/plugins/stored/python-sd.cc b/core/src/plugins/stored/python-sd.cc index 98f6d1e9f62..2ad9c151215 100644 --- a/core/src/plugins/stored/python-sd.cc +++ b/core/src/plugins/stored/python-sd.cc @@ -26,6 +26,7 @@ * @file * Python Storage daemon Plugin program */ + #if defined(HAVE_WIN32) #include "include/bareos.h" #include @@ -35,14 +36,15 @@ #endif #include "stored/stored.h" - #if (PY_VERSION_HEX < 0x02060000) #error "Need at least Python version 2.6 or newer" #endif #include "python-sd.h" #include "lib/edit.h" + namespace storagedaemon { + static const int debuglevel = 150; #define PLUGIN_LICENSE "Bareos AGPLv3" @@ -54,10 +56,6 @@ static const int debuglevel = 150; "python:instance=:module_path=:module_" \ "name=" -#define Dmsg(context, level, ...) \ - bfuncs->DebugMessage(context, __FILE__, __LINE__, level, __VA_ARGS__) -#define Jmsg(context, type, ...) \ - bfuncs->JobMessage(context, __FILE__, __LINE__, type, 0, __VA_ARGS__) /* Forward referenced functions */ static bRC newPlugin(bpContext* bareos_plugin_ctx); @@ -128,6 +126,9 @@ struct plugin_private_context { */ static PyThreadState* mainThreadState; +/* functions common to all plugins */ +#include "../python_plugins_common.inc" + #ifdef __cplusplus extern "C" { #endif @@ -184,18 +185,15 @@ bRC unloadPlugin() /* Create a new instance of the plugin i.e. allocate our private storage */ static bRC newPlugin(bpContext* bareos_plugin_ctx) { - struct plugin_private_context* plugin_priv_ctx; - - plugin_priv_ctx = (struct plugin_private_context*)malloc( - sizeof(struct plugin_private_context)); + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)malloc( + sizeof(struct plugin_private_context)); if (!plugin_priv_ctx) { return bRC_Error; } memset(plugin_priv_ctx, 0, sizeof(struct plugin_private_context)); bareos_plugin_ctx->pContext = (void*)plugin_priv_ctx; /* set our context pointer */ - /* - * For each plugin instance we instantiate a new Python interpreter. - */ + /* For each plugin instance we instantiate a new Python interpreter. */ PyEval_AcquireThread(mainThreadState); plugin_priv_ctx->interpreter = Py_NewInterpreter(); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); @@ -234,35 +232,6 @@ static bRC freePlugin(bpContext* bareos_plugin_ctx) return bRC_OK; } -static bRC getPluginValue(bpContext* bareos_plugin_ctx, - pVariable var, - void* value) -{ - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; - bRC retval = bRC_Error; - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyGetPluginValue(bareos_plugin_ctx, var, value); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - - return retval; -} - -static bRC setPluginValue(bpContext* bareos_plugin_ctx, - pVariable var, - void* value) -{ - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; - bRC retval = bRC_Error; - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PySetPluginValue(bareos_plugin_ctx, var, value); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - - return retval; -} static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, bsdEvent* event, @@ -312,9 +281,7 @@ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, retval = PyLoadModule(bareos_plugin_ctx, plugin_options.c_str()); } - /* - * Only try to call when the loading succeeded. - */ + /* Only try to call when the loading succeeded. */ if (retval == bRC_OK) { retval = PyParsePluginDefinition(bareos_plugin_ctx, plugin_options.c_str()); @@ -341,60 +308,6 @@ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, return retval; } -/** - * Strip any backslashes in the string. - */ -static inline void StripBackSlashes(char* value) -{ - char* bp; - - bp = value; - while (*bp) { - switch (*bp) { - case '\\': - bstrinlinecpy(bp, bp + 1); - break; - default: - break; - } - - bp++; - } -} - -/** - * Parse a integer value. - */ -static inline int64_t parse_integer(const char* argument_value) -{ - return str_to_int64(argument_value); -} - -/** - * Parse a boolean value e.g. check if its yes or true anything else translates - * to false. - */ -static inline bool ParseBoolean(const char* argument_value) -{ - if (Bstrcasecmp(argument_value, "yes") || - Bstrcasecmp(argument_value, "true")) { - return true; - } else { - return false; - } -} - -/** - * Always set destination to value and clean any previous one. - */ -static inline void SetString(char** destination, char* value) -{ - if (*destination) { free(*destination); } - - *destination = strdup(value); - StripBackSlashes(*destination); -} - /** * Parse the plugin definition passed in. * @@ -572,57 +485,6 @@ static inline PyObject* conv_retval_python(bRC retval) return (PyObject*)PyInt_FromLong((int)retval); } -/** - * Handle a Python error. - * - * Python equivalent: - * - * import traceback, sys - * return "".join(traceback.format_exception(sys.exc_type, - * sys.exc_value, sys.exc_traceback)) - */ -static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype) -{ - PyObject *type, *value, *traceback; - PyObject* tracebackModule; - char* error_string; - - PyErr_Fetch(&type, &value, &traceback); - - tracebackModule = PyImport_ImportModule("traceback"); - if (tracebackModule != NULL) { - PyObject *tbList, *emptyString, *strRetval; - - tbList = - PyObject_CallMethod(tracebackModule, (char*)"format_exception", - (char*)"OOO", type, value == NULL ? Py_None : value, - traceback == NULL ? Py_None : traceback); - - emptyString = PyString_FromString(""); - strRetval = - PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); - - error_string = strdup(PyString_AsString(strRetval)); - - Py_DECREF(tbList); - Py_DECREF(emptyString); - Py_DECREF(strRetval); - Py_DECREF(tracebackModule); - } else { - error_string = strdup("Unable to import traceback module."); - } - - Py_DECREF(type); - Py_XDECREF(value); - Py_XDECREF(traceback); - - Dmsg(bareos_plugin_ctx, debuglevel, "python-sd: %s\n", error_string); - if (msgtype) { - Jmsg(bareos_plugin_ctx, msgtype, "python-sd: %s\n", error_string); - } - - free(error_string); -} /** * Initial load of the Python module. diff --git a/core/src/plugins/stored/python-sd.h b/core/src/plugins/stored/python-sd.h index a52557c2b00..3c3c00fcf2a 100644 --- a/core/src/plugins/stored/python-sd.h +++ b/core/src/plugins/stored/python-sd.h @@ -27,9 +27,10 @@ #ifndef BAREOS_PLUGINS_STORED_PYTHON_SD_H_ #define BAREOS_PLUGINS_STORED_PYTHON_SD_H_ 1 +#define PYTHON_MODULE_NAME bareossd + /* common code for all python plugins */ #include "../python_plugins_common.h" -#include "../python_plugins_common.inc" namespace storagedaemon { @@ -65,7 +66,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args); static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args); static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args); -static PyMethodDef BareosSDMethods[] = { +static PyMethodDef Methods[] = { {"GetValue", PyBareosGetValue, METH_VARARGS, "Get a Plugin value"}, {"SetValue", PyBareosSetValue, METH_VARARGS, "Set a Plugin value"}, {"DebugMessage", PyBareosDebugMessage, METH_VARARGS, @@ -82,35 +83,37 @@ static PyMethodDef BareosSDMethods[] = { static void* bareos_plugin_context = NULL; +// MOD_INIT(PYTHON_MODULE_NAME) MOD_INIT(bareossd) { /* bareos_plugin_context holds the bpContext instead of passing to Python and * extracting it back like it was before. bareos_plugin_context needs to be - * set after loading the bareossd binary python module and will be used for - * all calls. + * set after loading the PYTHON_MODULE_NAME binary python module and will be + * used for all calls. */ - PyObject* BareosSdModule = NULL; + PyObject* m = NULL; /* Pointer Capsules to avoid context transfer back and forth */ - PyObject* PySdModulePluginContext = - PyCapsule_New((void*)&bareos_plugin_context, "bareossd.bpContext", NULL); + PyObject* PyModulePluginContext = + PyCapsule_New((void*)&bareos_plugin_context, + Quote(PYTHON_MODULE_NAME) ".bpContext", NULL); - if (!PySdModulePluginContext) { - printf("python-sd.h: PyCapsule_New failed\n"); + if (!PyModulePluginContext) { + printf(Quote(PYTHON_MODULE_NAME) ": PyCapsule_New failed\n"); return MOD_ERROR_VAL; } - MOD_DEF(BareosSdModule, "bareossd", NULL, BareosSDMethods) + MOD_DEF(m, Quote(PYTHON_MODULE_NAME), NULL, Methods) - if (PySdModulePluginContext) { - PyModule_AddObject(BareosSdModule, "bpContext", PySdModulePluginContext); + if (PyModulePluginContext) { + PyModule_AddObject(m, "bpContext", PyModulePluginContext); } else { - printf("python-sd.h:PyModule_AddObject failed\n"); + printf(Quote(PYTHON_MODULE_NAME) ":PyModule_AddObject failed\n"); return MOD_ERROR_VAL; } - return MOD_SUCCESS_VAL(BareosSdModule); + return MOD_SUCCESS_VAL(m); } } /* namespace storagedaemon*/ From 4db6042345a7fafb05fa38e1fb348cae946ff86b Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 2 Mar 2020 15:02:36 +0100 Subject: [PATCH 016/341] python plugins: Put more functions into common inc file and rename them --- core/src/plugins/dird/python-dir.cc | 70 ++++---------- core/src/plugins/filed/python-fd.cc | 102 +++++++-------------- core/src/plugins/python_plugins_common.h | 22 +++++ core/src/plugins/python_plugins_common.inc | 60 +++++++++++- core/src/plugins/stored/python-sd.cc | 69 ++++---------- 5 files changed, 148 insertions(+), 175 deletions(-) diff --git a/core/src/plugins/dird/python-dir.cc b/core/src/plugins/dird/python-dir.cc index bb4fe0b64f5..e453f580493 100644 --- a/core/src/plugins/dird/python-dir.cc +++ b/core/src/plugins/dird/python-dir.cc @@ -454,40 +454,6 @@ static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, return bRC_Error; } -static void StorePluginContextInPythonModule(bpContext* bareos_plugin_ctx) -{ - /* get the pointer to the module variable that is exported via the capsule */ - bpContext** bareosfd_bpContext = - (bpContext**)PyCapsule_Import("bareosdir.bpContext", 0); - - /* store bareos_plugin_ctx in module */ - *bareosfd_bpContext = bareos_plugin_ctx; -} - - -static bpContext* PyGetbpContext() -{ - bpContext** retval = (bpContext**)PyCapsule_Import("bareosdir.bpContext", 0); - return *retval; -} - -/** - * Convert a return value into a bRC enum value. - */ -static inline bRC conv_python_retval(PyObject* pRetVal) -{ - return (bRC)PyInt_AsLong(pRetVal); -} - -/** - * Convert a return value from bRC enum value into Python Object. - */ -static inline PyObject* conv_retval_python(bRC retval) -{ - return (PyObject*)PyInt_FromLong((int)retval); -} - - /** * Initial load of the Python module. * @@ -565,7 +531,7 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) if (!pRetVal) { goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); } } else { @@ -619,7 +585,7 @@ static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) if (!pRetVal) { goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); } @@ -676,7 +642,7 @@ static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, if (!pRetVal) { goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); } } else { @@ -715,7 +681,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarSDJobStatus: { int value = 0; - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); @@ -731,7 +697,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarReadBytes: { uint64_t value = 0; - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { pRetVal = PyLong_FromUnsignedLong(value); @@ -750,7 +716,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarVolumeName: { char* value = NULL; - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } @@ -766,7 +732,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) break; } default: - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); Dmsg(bareos_plugin_ctx, debuglevel, "python-dir: PyBareosGetValue unknown variable requested %d\n", var); break; @@ -799,7 +765,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bwDirVarVolumeName: { char* value; - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); value = PyString_AsString(pyValue); if (value) { retval = bfuncs->setBareosValue(bareos_plugin_ctx, (bwDirVariable)var, @@ -812,7 +778,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bwDirVarJobLevel: { int value; - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); value = PyInt_AsLong(pyValue); if (value >= 0) { retval = bfuncs->setBareosValue(bareos_plugin_ctx, (bwDirVariable)var, @@ -821,14 +787,14 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) break; } default: - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); Dmsg(bareos_plugin_ctx, debuglevel, "python-dir: PyBareosSetValue unknown variable requested %d\n", var); break; } bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -847,7 +813,7 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) } if (dbgmsg) { - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); Dmsg(bareos_plugin_ctx, level, "python-dir: %s", dbgmsg); } @@ -871,7 +837,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) } if (jobmsg) { - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); Jmsg(bareos_plugin_ctx, type, "python-dir: %s", jobmsg); } @@ -900,7 +866,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); @@ -917,7 +883,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) Py_DECREF(pySeq); bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -941,7 +907,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); @@ -958,7 +924,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) Py_DECREF(pySeq); bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -974,7 +940,7 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getInstanceCount(bareos_plugin_ctx, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } diff --git a/core/src/plugins/filed/python-fd.cc b/core/src/plugins/filed/python-fd.cc index 5268e29813c..b32eb9a8ed2 100644 --- a/core/src/plugins/filed/python-fd.cc +++ b/core/src/plugins/filed/python-fd.cc @@ -929,44 +929,6 @@ static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, return bRC_Error; } -/* static PyObject* PyCreatebpContext(bpContext* bareos_plugin_ctx) */ -/* { */ -/* return PyCapsule_New((void*)bareos_plugin_ctx, "bareos.bpContext", NULL); - */ -/* } */ - -static void StorePluginContextInPythonModule(bpContext* bareos_plugin_ctx) -{ - /* get the pointer to the module variable that is exported via the capsule */ - bpContext** bareosfd_bpContext = - (bpContext**)PyCapsule_Import("bareosfd.bpContext", 0); - - /* store bareos_plugin_ctx in module */ - *bareosfd_bpContext = bareos_plugin_ctx; -} - -static bpContext* GetPluginContextFromPythonModule() -{ - bpContext** retval = (bpContext**)PyCapsule_Import("bareosfd.bpContext", 0); - return *retval; -} - -/** - * Convert a return value into a bRC enum value. - */ -static inline bRC conv_python_retval(PyObject* pRetVal) -{ - return (bRC)PyInt_AsLong(pRetVal); -} - -/** - * Convert a return value from bRC enum value into Python Object. - */ -static inline PyObject* conv_retval_python(bRC retval) -{ - return (PyObject*)PyInt_FromLong((int)retval); -} - /** * Initial load of the Python module. @@ -1039,7 +1001,7 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) if (!pRetVal) { goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); } } else { @@ -1095,7 +1057,7 @@ static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) if (!pRetVal) { goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); } @@ -1152,7 +1114,7 @@ static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, if (!pRetVal) { goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); } } else { @@ -1425,7 +1387,7 @@ static bRC PyStartBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) Py_DECREF((PyObject*)pSavePkt); goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); if (!PySavePacketToNative(pSavePkt, sp, plugin_priv_ctx, false)) { @@ -1472,7 +1434,7 @@ static bRC PyEndBackupFile(bpContext* bareos_plugin_ctx) if (!pRetVal) { goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); } } else { Dmsg(bareos_plugin_ctx, debuglevel, @@ -1586,7 +1548,7 @@ static bRC PyPluginIO(bpContext* bareos_plugin_ctx, struct io_pkt* io) Py_DECREF((PyObject*)pIoPkt); goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); if (!PyIoPacketToNative(pIoPkt, io)) { @@ -1638,7 +1600,7 @@ static bRC PyStartRestoreFile(bpContext* bareos_plugin_ctx, const char* cmd) if (!pRetVal) { goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); } } else { @@ -1676,7 +1638,7 @@ static bRC PyEndRestoreFile(bpContext* bareos_plugin_ctx) if (!pRetVal) { goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); } } else { Dmsg(bareos_plugin_ctx, debuglevel, @@ -1764,7 +1726,7 @@ static bRC PyCreateFile(bpContext* bareos_plugin_ctx, struct restore_pkt* rp) Py_DECREF(pRestorePacket); goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); PyRestorePacketToNative(pRestorePacket, rp); @@ -1810,7 +1772,7 @@ static bRC PySetFileAttributes(bpContext* bareos_plugin_ctx, Py_DECREF(pRestorePacket); goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); Py_DECREF(pRestorePacket); } @@ -1851,7 +1813,7 @@ static bRC PyCheckFile(bpContext* bareos_plugin_ctx, char* fname) if (!pRetVal) { goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); } } else { @@ -1933,7 +1895,7 @@ static bRC PyGetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) Py_DECREF((PyObject*)pAclPkt); goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); if (!PyAclPacketToNative(pAclPkt, ap)) { @@ -1982,7 +1944,7 @@ static bRC PySetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) if (!pRetVal) { goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); } } else { @@ -2087,7 +2049,7 @@ static bRC PyGetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) Py_DECREF((PyObject*)pXattrPkt); goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); if (!PyXattrPacketToNative(pXattrPkt, xp)) { @@ -2136,7 +2098,7 @@ static bRC PySetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) if (!pRetVal) { goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); } } else { @@ -2202,7 +2164,7 @@ static bRC PyRestoreObjectData(bpContext* bareos_plugin_ctx, if (!pRetVal) { goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); } } else { @@ -2244,7 +2206,7 @@ static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) Py_DECREF((PyObject*)pSavePkt); goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); if (!PySavePacketToNative(pSavePkt, sp, plugin_priv_ctx, true)) { @@ -2386,7 +2348,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) } bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -2476,7 +2438,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) Py_DECREF(pySeq); bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -2515,7 +2477,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) Py_DECREF(pySeq); bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -2564,7 +2526,7 @@ static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) } bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -2586,7 +2548,7 @@ static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) } bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -2608,7 +2570,7 @@ static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) } bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -2633,7 +2595,7 @@ static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) } bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -2658,7 +2620,7 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) } bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -2677,7 +2639,7 @@ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) retval = bfuncs->NewOptions(bareos_plugin_ctx); bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -2696,7 +2658,7 @@ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) retval = bfuncs->NewInclude(bareos_plugin_ctx); bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -2715,7 +2677,7 @@ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) retval = bfuncs->NewPreInclude(bareos_plugin_ctx); bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -2769,7 +2731,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) pSavePkt->accurate_found = sp.accurate_found; bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -2813,7 +2775,7 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) retval = bfuncs->AcceptFile(bareos_plugin_ctx, &sp); bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -2837,7 +2799,7 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) retval = bfuncs->SetSeenBitmap(bareos_plugin_ctx, all, fname); bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -2861,7 +2823,7 @@ static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) retval = bfuncs->ClearSeenBitmap(bareos_plugin_ctx, all, fname); bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** diff --git a/core/src/plugins/python_plugins_common.h b/core/src/plugins/python_plugins_common.h index a18f2a8aec2..0b7ac2208ed 100644 --- a/core/src/plugins/python_plugins_common.h +++ b/core/src/plugins/python_plugins_common.h @@ -1,3 +1,25 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2020-2020 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation, which is + listed in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +/* Common definitions used in all python plugins. */ #ifndef BAREOS_PYTHON_PLUGINS_COMMON_H_ #define BAREOS_PYTHON_PLUGINS_COMMON_H_ diff --git a/core/src/plugins/python_plugins_common.inc b/core/src/plugins/python_plugins_common.inc index 614898d3489..5c70c486187 100644 --- a/core/src/plugins/python_plugins_common.inc +++ b/core/src/plugins/python_plugins_common.inc @@ -1,4 +1,25 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + Copyright (C) 2020-2020 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation, which is + listed in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +/* Common functions used in all python plugins. */ static bRC getPluginValue(bpContext* bareos_plugin_ctx, pVariable var, void* value) @@ -134,10 +155,45 @@ static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype) Py_XDECREF(value); Py_XDECREF(traceback); - Dmsg(bareos_plugin_ctx, debuglevel, Quote(PYTHON_MODULE_NAME) ": %s\n", error_string); + Dmsg(bareos_plugin_ctx, debuglevel, Quote(PYTHON_MODULE_NAME) ": %s\n", + error_string); if (msgtype) { - Jmsg(bareos_plugin_ctx, msgtype, Quote(PYTHON_MODULE_NAME) ": %s\n", error_string); + Jmsg(bareos_plugin_ctx, msgtype, Quote(PYTHON_MODULE_NAME) ": %s\n", + error_string); } free(error_string); } + +static void StorePluginContextInPythonModule(bpContext* bareos_plugin_ctx) +{ + /* get the pointer to the module variable that is exported via the capsule */ + bpContext** bareosfd_bpContext = + (bpContext**)PyCapsule_Import(Quote(PYTHON_MODULE_NAME) ".bpContext", 0); + + /* store bareos_plugin_ctx in module */ + *bareosfd_bpContext = bareos_plugin_ctx; +} + +static bpContext* GetPluginContextFromPythonModule() +{ + bpContext** retval = + (bpContext**)PyCapsule_Import(Quote(PYTHON_MODULE_NAME) ".bpContext", 0); + return *retval; +} + +/** + * Convert a return value into a bRC enum value. + */ +static inline bRC ConvertPythonRetvalTobRCRetval(PyObject* pRetVal) +{ + return (bRC)PyInt_AsLong(pRetVal); +} + +/** + * Convert a return value from bRC enum value into Python Object. + */ +static inline PyObject* ConvertbRCRetvalToPythonRetval(bRC retval) +{ + return (PyObject*)PyInt_FromLong((int)retval); +} diff --git a/core/src/plugins/stored/python-sd.cc b/core/src/plugins/stored/python-sd.cc index 2ad9c151215..35495141d2a 100644 --- a/core/src/plugins/stored/python-sd.cc +++ b/core/src/plugins/stored/python-sd.cc @@ -452,39 +452,6 @@ static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, return bRC_Error; } -static void StorePluginContextInPythonModule(bpContext* bareos_plugin_ctx) -{ - /* get the pointer to the module variable that is exported via the capsule */ - bpContext** bareosfd_bpContext = - (bpContext**)PyCapsule_Import("bareossd.bpContext", 0); - - /* store bareos_plugin_ctx in module */ - *bareosfd_bpContext = bareos_plugin_ctx; -} - - -static bpContext* PyGetbpContext() -{ - bpContext** retval = (bpContext**)PyCapsule_Import("bareossd.bpContext", 0); - return *retval; -} - -/** - * Convert a return value into a bRC enum value. - */ -static inline bRC conv_python_retval(PyObject* pRetVal) -{ - return (bRC)PyInt_AsLong(pRetVal); -} - -/** - * Convert a return value from bRC enum value into Python Object. - */ -static inline PyObject* conv_retval_python(bRC retval) -{ - return (PyObject*)PyInt_FromLong((int)retval); -} - /** * Initial load of the Python module. @@ -563,7 +530,7 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) if (!pRetVal) { goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); } } else { @@ -617,7 +584,7 @@ static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) if (!pRetVal) { goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); } @@ -674,7 +641,7 @@ static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, if (!pRetVal) { goto bail_out; } else { - retval = conv_python_retval(pRetVal); + retval = ConvertPythonRetvalTobRCRetval(pRetVal); Py_DECREF(pRetVal); } } else { @@ -709,7 +676,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bsdVarJobStatus: { int value; - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (bsdrVariable)var, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); @@ -721,7 +688,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bsdVarJobBytes: { uint64_t value = 0; - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (bsdrVariable)var, &value) == bRC_OK) { pRetVal = PyLong_FromUnsignedLong(value); @@ -738,7 +705,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bsdVarVolumeName: { char* value = NULL; - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (bsdrVariable)var, &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } @@ -765,7 +732,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) break; } default: - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); Dmsg(bareos_plugin_ctx, debuglevel, "python-sd: PyBareosGetValue unknown variable requested %d\n", var); break; @@ -798,7 +765,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bsdwVarVolumeName: { char* value; - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); value = PyString_AsString(pyValue); if (value) { bfuncs->setBareosValue(bareos_plugin_ctx, (bsdwVariable)var, value); @@ -810,7 +777,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bsdwVarJobLevel: { int value; - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); value = PyInt_AsLong(pyValue); if (value >= 0) { retval = bfuncs->setBareosValue(bareos_plugin_ctx, (bsdwVariable)var, @@ -819,14 +786,14 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) break; } default: - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); Dmsg(bareos_plugin_ctx, debuglevel, "python-sd: PyBareosSetValue unknown variable requested %d\n", var); break; } bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -845,7 +812,7 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) } if (dbgmsg) { - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); Dmsg(bareos_plugin_ctx, level, "python-sd: %s", dbgmsg); } @@ -869,7 +836,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) } if (jobmsg) { - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); Jmsg(bareos_plugin_ctx, type, "python-sd: %s", jobmsg); } @@ -898,7 +865,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); @@ -915,7 +882,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) Py_DECREF(pySeq); bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -939,7 +906,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); @@ -956,7 +923,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) Py_DECREF(pySeq); bail_out: - return conv_retval_python(retval); + return ConvertbRCRetvalToPythonRetval(retval); } /** @@ -972,7 +939,7 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } - bareos_plugin_ctx = PyGetbpContext(); + bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getInstanceCount(bareos_plugin_ctx, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } From e9f1d9752b8983eee5cf73288eb96ce73f220512 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 2 Mar 2020 15:43:16 +0100 Subject: [PATCH 017/341] python plugins: introduced PYTHON_MODULE_NAME_QUOTED macro --- core/src/plugins/dird/python-dir.h | 9 +++++---- core/src/plugins/filed/python-fd.h | 9 +++++---- core/src/plugins/python_plugins_common.inc | 15 ++++++++++----- core/src/plugins/stored/python-sd.h | 9 +++++---- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/core/src/plugins/dird/python-dir.h b/core/src/plugins/dird/python-dir.h index 9d09512c67f..5f704a93ef7 100644 --- a/core/src/plugins/dird/python-dir.h +++ b/core/src/plugins/dird/python-dir.h @@ -28,6 +28,7 @@ #define BAREOS_PLUGINS_DIRD_PYTHON_DIR_H_ 1 #define PYTHON_MODULE_NAME bareosdir +#define PYTHON_MODULE_NAME_QUOTED "bareosdir" /* common code for all python plugins */ #include "../python_plugins_common.h" @@ -97,19 +98,19 @@ MOD_INIT(bareosdir) /* Pointer Capsules to avoid context transfer back and forth */ PyObject* PyModulePluginContext = PyCapsule_New((void*)&bareos_plugin_context, - Quote(PYTHON_MODULE_NAME) ".bpContext", NULL); + PYTHON_MODULE_NAME_QUOTED ".bpContext", NULL); if (!PyModulePluginContext) { - printf(Quote(PYTHON_MODULE_NAME) ": PyCapsule_New failed\n"); + printf(PYTHON_MODULE_NAME_QUOTED ": PyCapsule_New failed\n"); return MOD_ERROR_VAL; } - MOD_DEF(m, Quote(PYTHON_MODULE_NAME), NULL, Methods) + MOD_DEF(m, PYTHON_MODULE_NAME_QUOTED, NULL, Methods) if (PyModulePluginContext) { PyModule_AddObject(m, "bpContext", PyModulePluginContext); } else { - printf(Quote(PYTHON_MODULE_NAME) ":PyModule_AddObject failed\n"); + printf(PYTHON_MODULE_NAME_QUOTED ":PyModule_AddObject failed\n"); return MOD_ERROR_VAL; } diff --git a/core/src/plugins/filed/python-fd.h b/core/src/plugins/filed/python-fd.h index 008d5c59e8f..e4bea61c3cf 100644 --- a/core/src/plugins/filed/python-fd.h +++ b/core/src/plugins/filed/python-fd.h @@ -28,6 +28,7 @@ #define BAREOS_PLUGINS_FILED_PYTHON_FD_H_ 1 #define PYTHON_MODULE_NAME bareosfd +#define PYTHON_MODULE_NAME_QUOTED "bareosfd" /* common code for all python plugins */ #include "../python_plugins_common.h" @@ -763,19 +764,19 @@ MOD_INIT(bareosfd) /* Pointer Capsules to avoid context transfer back and forth */ PyObject* PyModulePluginContext = PyCapsule_New((void*)&bareos_plugin_context, - Quote(PYTHON_MODULE_NAME) ".bpContext", NULL); + PYTHON_MODULE_NAME_QUOTED ".bpContext", NULL); if (!PyModulePluginContext) { - printf(Quote(PYTHON_MODULE_NAME) ": PyCapsule_New failed\n"); + printf(PYTHON_MODULE_NAME_QUOTED ": PyCapsule_New failed\n"); return MOD_ERROR_VAL; } - MOD_DEF(m, Quote(PYTHON_MODULE_NAME), NULL, Methods) + MOD_DEF(m, PYTHON_MODULE_NAME_QUOTED, NULL, Methods) if (PyModulePluginContext) { PyModule_AddObject(m, "bpContext", PyModulePluginContext); } else { - printf(Quote(PYTHON_MODULE_NAME) ":PyModule_AddObject failed\n"); + printf(PYTHON_MODULE_NAME_QUOTED ":PyModule_AddObject failed\n"); return MOD_ERROR_VAL; } diff --git a/core/src/plugins/python_plugins_common.inc b/core/src/plugins/python_plugins_common.inc index 5c70c486187..b4daf686bd8 100644 --- a/core/src/plugins/python_plugins_common.inc +++ b/core/src/plugins/python_plugins_common.inc @@ -155,10 +155,10 @@ static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype) Py_XDECREF(value); Py_XDECREF(traceback); - Dmsg(bareos_plugin_ctx, debuglevel, Quote(PYTHON_MODULE_NAME) ": %s\n", + Dmsg(bareos_plugin_ctx, debuglevel, PYTHON_MODULE_NAME_QUOTED ": %s\n", error_string); if (msgtype) { - Jmsg(bareos_plugin_ctx, msgtype, Quote(PYTHON_MODULE_NAME) ": %s\n", + Jmsg(bareos_plugin_ctx, msgtype, PYTHON_MODULE_NAME_QUOTED ": %s\n", error_string); } @@ -169,16 +169,21 @@ static void StorePluginContextInPythonModule(bpContext* bareos_plugin_ctx) { /* get the pointer to the module variable that is exported via the capsule */ bpContext** bareosfd_bpContext = - (bpContext**)PyCapsule_Import(Quote(PYTHON_MODULE_NAME) ".bpContext", 0); + (bpContext**)PyCapsule_Import(PYTHON_MODULE_NAME_QUOTED ".bpContext", 0); /* store bareos_plugin_ctx in module */ - *bareosfd_bpContext = bareos_plugin_ctx; + if (bareosfd_bpContext) { + *bareosfd_bpContext = bareos_plugin_ctx; + } else { + printf(PYTHON_MODULE_NAME_QUOTED ": could not get bareosfd_bpContext from module\n"); + } } static bpContext* GetPluginContextFromPythonModule() { + const char* capsule_name = PYTHON_MODULE_NAME_QUOTED ".bpContext"; bpContext** retval = - (bpContext**)PyCapsule_Import(Quote(PYTHON_MODULE_NAME) ".bpContext", 0); + (bpContext**)PyCapsule_Import(capsule_name, 0); return *retval; } diff --git a/core/src/plugins/stored/python-sd.h b/core/src/plugins/stored/python-sd.h index 3c3c00fcf2a..625f676cadc 100644 --- a/core/src/plugins/stored/python-sd.h +++ b/core/src/plugins/stored/python-sd.h @@ -28,6 +28,7 @@ #define BAREOS_PLUGINS_STORED_PYTHON_SD_H_ 1 #define PYTHON_MODULE_NAME bareossd +#define PYTHON_MODULE_NAME_QUOTED "bareossd" /* common code for all python plugins */ #include "../python_plugins_common.h" @@ -97,19 +98,19 @@ MOD_INIT(bareossd) /* Pointer Capsules to avoid context transfer back and forth */ PyObject* PyModulePluginContext = PyCapsule_New((void*)&bareos_plugin_context, - Quote(PYTHON_MODULE_NAME) ".bpContext", NULL); + PYTHON_MODULE_NAME_QUOTED ".bpContext", NULL); if (!PyModulePluginContext) { - printf(Quote(PYTHON_MODULE_NAME) ": PyCapsule_New failed\n"); + printf(PYTHON_MODULE_NAME_QUOTED ": PyCapsule_New failed\n"); return MOD_ERROR_VAL; } - MOD_DEF(m, Quote(PYTHON_MODULE_NAME), NULL, Methods) + MOD_DEF(m, PYTHON_MODULE_NAME_QUOTED, NULL, Methods) if (PyModulePluginContext) { PyModule_AddObject(m, "bpContext", PyModulePluginContext); } else { - printf(Quote(PYTHON_MODULE_NAME) ":PyModule_AddObject failed\n"); + printf(PYTHON_MODULE_NAME_QUOTED ":PyModule_AddObject failed\n"); return MOD_ERROR_VAL; } From 6cecdcb341adcc3267ee2e3ad3ae08830f1c292a Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 2 Mar 2020 17:00:41 +0100 Subject: [PATCH 018/341] python-fd: build python binary module --- core/src/plugins/filed/CMakeLists.txt | 23 +++++++++++++++++++++++ core/src/plugins/filed/setup.py.in | 13 +++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 core/src/plugins/filed/setup.py.in diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index 40347bc588e..98689701955 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -107,6 +107,29 @@ if(HAVE_PYTHON) target_link_libraries(python-fd ${PYTHON_LIBRARIES} bareos) endif() +if(HAVE_PYTHON) + add_executable( bareosfd_module_main bareosfd_module_main.cc) + target_link_libraries(bareosfd_module_main ${PYTHON_LIBRARIES} bareos) +endif() + +if(HAVE_PYTHON) + configure_file(setup.py.in setup.py) + add_custom_command(OUTPUT pythonmodules/bareosfd.so + COMMAND ${PYTHON_EXECUTABLE} setup.py build + COMMAND ${PYTHON_EXECUTABLE} setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + DEPENDS python-fd.cc) + add_custom_target(bareosfd ALL DEPENDS bareos pythonmodules/bareosfd.so) + + add_test(NAME bareosfd-python-module + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/bareosfd_test.py + ) + set_property(TEST bareosfd-python-module PROPERTY ENVIRONMENT PYTHONPATH=pythonmodules/ LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib) +endif() + + + + + if(${HAVE_GLUSTERFS}) add_library(gfapi-fd MODULE gfapi-fd.cc) set_target_properties(gfapi-fd PROPERTIES PREFIX "") diff --git a/core/src/plugins/filed/setup.py.in b/core/src/plugins/filed/setup.py.in new file mode 100644 index 00000000000..6d154066330 --- /dev/null +++ b/core/src/plugins/filed/setup.py.in @@ -0,0 +1,13 @@ +from distutils.core import setup, Extension + +module1 = Extension('bareosfd', + sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python-fd.cc'], + include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..'], + libraries = ['bareos'], + library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'] + ) + +setup (name = 'bareosfd', + version = '@BAREOS_FULL_VERSION@', + description = 'bareos package', + ext_modules = [module1]) From 2b9da1d856f47954b40fa16f269d21ad67559644 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 2 Mar 2020 17:09:30 +0100 Subject: [PATCH 019/341] python plugins: fix name of init function --- core/src/plugins/dird/python-dir.cc | 2 +- core/src/plugins/filed/python-fd.cc | 2 +- core/src/plugins/filed/test/bareosfd_module_main_test.py | 8 ++++++++ core/src/plugins/python_plugins_common.h | 2 +- core/src/plugins/stored/python-sd.cc | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 core/src/plugins/filed/test/bareosfd_module_main_test.py diff --git a/core/src/plugins/dird/python-dir.cc b/core/src/plugins/dird/python-dir.cc index e453f580493..76482c5c404 100644 --- a/core/src/plugins/dird/python-dir.cc +++ b/core/src/plugins/dird/python-dir.cc @@ -156,7 +156,7 @@ bRC loadPlugin(bDirInfo* lbinfo, #if PY_MAJOR_VERSION >= 3 PyImport_AppendInittab("bareosdir", &PyInit_bareosdir); #else - PyImport_AppendInittab("bareosdir", Init_bareosdir); + PyImport_AppendInittab("bareosdir", initbareosdir); #endif Py_InitializeEx(0); PyEval_InitThreads(); diff --git a/core/src/plugins/filed/python-fd.cc b/core/src/plugins/filed/python-fd.cc index b32eb9a8ed2..8c16a1450f3 100644 --- a/core/src/plugins/filed/python-fd.cc +++ b/core/src/plugins/filed/python-fd.cc @@ -188,7 +188,7 @@ bRC loadPlugin(bInfo* lbinfo, #if PY_MAJOR_VERSION >= 3 PyImport_AppendInittab("bareosfd", &PyInit_bareosfd); #else - PyImport_AppendInittab("bareosfd", Init_bareosfd); + PyImport_AppendInittab("bareosfd", initbareosfd); #endif Py_InitializeEx(0); diff --git a/core/src/plugins/filed/test/bareosfd_module_main_test.py b/core/src/plugins/filed/test/bareosfd_module_main_test.py new file mode 100644 index 00000000000..8535f6789cb --- /dev/null +++ b/core/src/plugins/filed/test/bareosfd_module_main_test.py @@ -0,0 +1,8 @@ +import bareosfd + +def load_bareos_plugin( plugindef): + print ("Hello from load_bareos_plugin") + #print (context) + print (plugindef) + print (bareosfd) + bareosfd.DebugMessage(100, "Kuckuck") diff --git a/core/src/plugins/python_plugins_common.h b/core/src/plugins/python_plugins_common.h index 0b7ac2208ed..c33cbdbf5e0 100644 --- a/core/src/plugins/python_plugins_common.h +++ b/core/src/plugins/python_plugins_common.h @@ -38,7 +38,7 @@ #else #define MOD_ERROR_VAL #define MOD_SUCCESS_VAL(val) -#define MOD_INIT(name) void Init_##name(void) +#define MOD_INIT(name) void init##name(void) #define MOD_DEF(ob, name, doc, methods) ob = Py_InitModule3(name, methods, doc); #endif diff --git a/core/src/plugins/stored/python-sd.cc b/core/src/plugins/stored/python-sd.cc index 35495141d2a..a1cc27123de 100644 --- a/core/src/plugins/stored/python-sd.cc +++ b/core/src/plugins/stored/python-sd.cc @@ -155,7 +155,7 @@ bRC loadPlugin(bsdInfo* lbinfo, #if PY_MAJOR_VERSION >= 3 PyImport_AppendInittab("bareossd", &PyInit_bareossd); #else - PyImport_AppendInittab("bareossd", Init_bareossd); + PyImport_AppendInittab("bareossd", initbareossd); #endif Py_InitializeEx(0); PyEval_InitThreads(); From f4abc109d047d2185a05b012307848adfc9a9be1 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 3 Mar 2020 08:39:49 +0100 Subject: [PATCH 020/341] python plugins: fix MOD_INIT macro --- core/src/plugins/dird/python-dir.h | 1 + core/src/plugins/filed/python-fd.cc | 4 ++++ core/src/plugins/filed/python-fd.h | 8 ++++++-- core/src/plugins/python_plugins_common.h | 8 ++------ core/src/plugins/stored/python-sd.h | 1 + 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/core/src/plugins/dird/python-dir.h b/core/src/plugins/dird/python-dir.h index 5f704a93ef7..880b54b78d0 100644 --- a/core/src/plugins/dird/python-dir.h +++ b/core/src/plugins/dird/python-dir.h @@ -32,6 +32,7 @@ /* common code for all python plugins */ #include "../python_plugins_common.h" +#include "plugins/filed/fd_common.h" namespace directordaemon { diff --git a/core/src/plugins/filed/python-fd.cc b/core/src/plugins/filed/python-fd.cc index 8c16a1450f3..2eb57635a9e 100644 --- a/core/src/plugins/filed/python-fd.cc +++ b/core/src/plugins/filed/python-fd.cc @@ -26,6 +26,7 @@ * @file * Python plugin for the Bareos File Daemon */ +#define PY_SSIZE_T_CLEAN #define BUILD_PLUGIN #if defined(HAVE_WIN32) @@ -170,6 +171,7 @@ static PyThreadState* mainThreadState; extern "C" { #endif + /** * Plugin called here when it is first loaded */ @@ -3345,4 +3347,6 @@ static void PyXattrPacket_dealloc(PyXattrPacket* self) if (self->name) { Py_XDECREF(self->name); } PyObject_Del(self); } + + } /* namespace filedaemon */ diff --git a/core/src/plugins/filed/python-fd.h b/core/src/plugins/filed/python-fd.h index e4bea61c3cf..2620e91f566 100644 --- a/core/src/plugins/filed/python-fd.h +++ b/core/src/plugins/filed/python-fd.h @@ -32,6 +32,7 @@ /* common code for all python plugins */ #include "../python_plugins_common.h" +#include "plugins/filed/fd_common.h" #include "structmember.h" @@ -748,9 +749,11 @@ static PyMethodDef Methods[] = { {NULL, NULL, 0, NULL}}; +} /* namespace filedaemon */ +using namespace filedaemon; + static void* bareos_plugin_context = NULL; -// MOD_INIT(PYTHON_MODULE_NAME) MOD_INIT(bareosfd) { /* bareos_plugin_context holds the bpContext instead of passing to Python and @@ -825,5 +828,6 @@ MOD_INIT(bareosfd) return MOD_SUCCESS_VAL(m); } -} /* namespace filedaemon */ + + #endif /* BAREOS_PLUGINS_FILED_PYTHON_FD_H_ */ diff --git a/core/src/plugins/python_plugins_common.h b/core/src/plugins/python_plugins_common.h index c33cbdbf5e0..0623985aab8 100644 --- a/core/src/plugins/python_plugins_common.h +++ b/core/src/plugins/python_plugins_common.h @@ -34,17 +34,13 @@ static struct PyModuleDef moduledef = { \ PyModuleDef_HEAD_INIT, name, doc, -1, methods, \ }; \ + \ ob = PyModule_Create(&moduledef); #else #define MOD_ERROR_VAL #define MOD_SUCCESS_VAL(val) -#define MOD_INIT(name) void init##name(void) +#define MOD_INIT(name) PyMODINIT_FUNC init##name(void) #define MOD_DEF(ob, name, doc, methods) ob = Py_InitModule3(name, methods, doc); #endif -#define Quote(macro) #macro - -#include "plugins/filed/fd_common.h" - - #endif // BAREOS_PYTHON_PLUGINS_COMMON_H_ diff --git a/core/src/plugins/stored/python-sd.h b/core/src/plugins/stored/python-sd.h index 625f676cadc..b58eebc9594 100644 --- a/core/src/plugins/stored/python-sd.h +++ b/core/src/plugins/stored/python-sd.h @@ -32,6 +32,7 @@ /* common code for all python plugins */ #include "../python_plugins_common.h" +#include "plugins/filed/fd_common.h" namespace storagedaemon { From 5dbc978c5d463c23aa1f5b0b67bc391aa5319b84 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 3 Mar 2020 08:56:10 +0100 Subject: [PATCH 021/341] python-fd binary module: add cmake cleanup target --- core/src/plugins/filed/CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index 98689701955..a9f785b9024 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -114,11 +114,13 @@ endif() if(HAVE_PYTHON) configure_file(setup.py.in setup.py) - add_custom_command(OUTPUT pythonmodules/bareosfd.so + + add_custom_target(bareosfd ALL + #OUTPUT pythonmodules/bareosfd.so + COMMENT "building python module pythonmodules/bareosfd.so" COMMAND ${PYTHON_EXECUTABLE} setup.py build COMMAND ${PYTHON_EXECUTABLE} setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - DEPENDS python-fd.cc) - add_custom_target(bareosfd ALL DEPENDS bareos pythonmodules/bareosfd.so) + DEPENDS python-fd.cc python-fd.h bareos) add_test(NAME bareosfd-python-module COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/bareosfd_test.py From 146f484ee8fb80ae1a71ac747ece81c3ff913cac Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 3 Mar 2020 09:14:09 +0100 Subject: [PATCH 022/341] python-fd: import and adapt unittest --- core/src/plugins/filed/CMakeLists.txt | 6 +- core/src/plugins/filed/fd_common.h | 24 +++-- core/src/plugins/filed/python-fd.cc | 84 +++++++++-------- .../filed/test/bareosfd_module_main_test.py | 2 +- core/src/plugins/filed/test/bareosfd_test.py | 94 +++++++++++++++++++ 5 files changed, 159 insertions(+), 51 deletions(-) create mode 100644 core/src/plugins/filed/test/bareosfd_test.py diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index a9f785b9024..241e1405f0a 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -116,16 +116,16 @@ if(HAVE_PYTHON) configure_file(setup.py.in setup.py) add_custom_target(bareosfd ALL - #OUTPUT pythonmodules/bareosfd.so COMMENT "building python module pythonmodules/bareosfd.so" COMMAND ${PYTHON_EXECUTABLE} setup.py build COMMAND ${PYTHON_EXECUTABLE} setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - DEPENDS python-fd.cc python-fd.h bareos) + DEPENDS python-fd + ) add_test(NAME bareosfd-python-module COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/bareosfd_test.py ) - set_property(TEST bareosfd-python-module PROPERTY ENVIRONMENT PYTHONPATH=pythonmodules/ LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib) + set_property(TEST bareosfd-python-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/test" LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib) endif() diff --git a/core/src/plugins/filed/fd_common.h b/core/src/plugins/filed/fd_common.h index 72e3429638e..98aebd2954c 100644 --- a/core/src/plugins/filed/fd_common.h +++ b/core/src/plugins/filed/fd_common.h @@ -2,7 +2,7 @@ BAREOS® - Backup Archiving REcovery Open Sourced Copyright (C) 2010-2011 Bacula Systems(R) SA - Copyright (C) 2016-2016 Bareos GmbH & Co. KG + Copyright (C) 2016-2020 Bareos GmbH & Co. KG This program is Free Software; you can modify it under the terms of version three of the GNU Affero General Public License as published by the @@ -35,9 +35,21 @@ #define L_INCREMENTAL 'I' /* since last backup */ #define L_DIFFERENTIAL 'D' /* since last full backup */ -#define Dmsg(context, level, ...) \ - bfuncs->DebugMessage(context, __FILE__, __LINE__, level, __VA_ARGS__) -#define Jmsg(context, type, ...) \ - bfuncs->JobMessage(context, __FILE__, __LINE__, type, 0, __VA_ARGS__) - +#define Dmsg(context, level, ...) \ + if (bfuncs && context) { \ + bfuncs->DebugMessage(context, __FILE__, __LINE__, level, __VA_ARGS__); \ + } else { \ + printf( \ + "Dmsg: bfuncs(%p) and context(%p) need to be set before Dmsg call\n", \ + bfuncs, context); \ + } + +#define Jmsg(context, type, ...) \ + if (bfuncs && context) { \ + bfuncs->JobMessage(context, __FILE__, __LINE__, type, 0, __VA_ARGS__); \ + } else { \ + printf( \ + "Jmsg: bfuncs(%p) and context(%p) need to be set before Jmsg call\n", \ + bfuncs, context); \ + } #endif diff --git a/core/src/plugins/filed/python-fd.cc b/core/src/plugins/filed/python-fd.cc index 2eb57635a9e..498d0af5844 100644 --- a/core/src/plugins/filed/python-fd.cc +++ b/core/src/plugins/filed/python-fd.cc @@ -2370,17 +2370,18 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) if (dbgmsg) { bareos_plugin_ctx = GetPluginContextFromPythonModule(); - Dmsg(bareos_plugin_ctx, level, "python-fd: %s", dbgmsg); + if (bareos_plugin_ctx && bfuncs) { + Dmsg(bareos_plugin_ctx, level, "python-fd: %s", dbgmsg); + } } - Py_INCREF(Py_None); return Py_None; } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue Job messages using the Bareos Job message - * facility. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue Job messages using the Bareos Job + * message facility. */ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { @@ -2403,9 +2404,9 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a Register Event to register additional events - * it wants to receive. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Register Event to register + * additional events it wants to receive. */ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { @@ -2444,9 +2445,9 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue an Unregister Event to unregister events it - * doesn't want to receive anymore. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue an Unregister Event to unregister + * events it doesn't want to receive anymore. */ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { @@ -2483,9 +2484,9 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a GetInstanceCount to retrieve the number of - * instances of the current plugin being loaded into the daemon. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a GetInstanceCount to retrieve the + * number of instances of the current plugin being loaded into the daemon. */ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { @@ -2510,8 +2511,8 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a Add Exclude pattern to the fileset. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Add Exclude pattern to the fileset. */ static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) { @@ -2532,8 +2533,8 @@ static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a Add Include pattern to the fileset. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Add Include pattern to the fileset. */ static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) { @@ -2554,8 +2555,8 @@ static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a Add Include Options to the fileset. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Add Include Options to the fileset. */ static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) { @@ -2576,8 +2577,8 @@ static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a Add Regex to the fileset. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Add Regex to the fileset. */ static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) { @@ -2601,8 +2602,8 @@ static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a Add Wildcard to the fileset. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Add Wildcard to the fileset. */ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) { @@ -2626,8 +2627,8 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a Add New Option block. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Add New Option block. */ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) { @@ -2645,8 +2646,8 @@ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a Add New Include block. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Add New Include block. */ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) { @@ -2664,8 +2665,8 @@ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a Add New Pre Include block. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Add New Pre Include block. */ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) { @@ -2683,9 +2684,9 @@ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a check if a file have to be backed up using - * Accurate code. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a check if a file have to be backed up + * using Accurate code. */ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) { @@ -2737,9 +2738,9 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a check if a file would be saved using current - * Include/Exclude code. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a check if a file would be saved using + * current Include/Exclude code. */ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) { @@ -2781,8 +2782,8 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a Set bit in the Accurate Seen bitmap. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Set bit in the Accurate Seen bitmap. */ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) { @@ -2805,8 +2806,9 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a Clear bit in the Accurate Seen bitmap. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Clear bit in the Accurate Seen + * bitmap. */ static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) { @@ -3001,7 +3003,7 @@ static void PyStatPacket_dealloc(PyStatPacket* self) { PyObject_Del(self); } static inline const char* print_flags_bitmap(PyObject* bitmap) { static char visual_bitmap[FO_MAX + 1]; - + if (!bitmap) { return ""; } if (PyByteArray_Check(bitmap)) { int cnt; char* flags; diff --git a/core/src/plugins/filed/test/bareosfd_module_main_test.py b/core/src/plugins/filed/test/bareosfd_module_main_test.py index 8535f6789cb..08dcb75567a 100644 --- a/core/src/plugins/filed/test/bareosfd_module_main_test.py +++ b/core/src/plugins/filed/test/bareosfd_module_main_test.py @@ -1,6 +1,6 @@ import bareosfd -def load_bareos_plugin( plugindef): +def load_bareos_plugin(plugindef): print ("Hello from load_bareos_plugin") #print (context) print (plugindef) diff --git a/core/src/plugins/filed/test/bareosfd_test.py b/core/src/plugins/filed/test/bareosfd_test.py new file mode 100644 index 00000000000..37fe3b04c2f --- /dev/null +++ b/core/src/plugins/filed/test/bareosfd_test.py @@ -0,0 +1,94 @@ +import unittest +import bareosfd +import time + + +class TestBareosFd(unittest.TestCase): + + def test_SetValue(self): + bareosfd.SetValue(1, 123) + + def test_DebugMessage(self): + bareosfd.DebugMessage(100,"testdebugmessage\n") + + def test_RestoreObject(self): + test_RestoreObject = bareosfd.RestoreObject() + self.assertEqual( + 'RestoreObject(object_name="", object="", plugin_name="", object_type=0, object_len=0, object_full_len=0, object_index=0, object_compression=0, stream=0, jobid=0)', + str(test_RestoreObject), + ) + + #r2 = bareosfd.RestoreObject() + #r2.object_name="this is a very long object name" + #r2.object="123456780" + ##r2.plugin_name="this is a plugin name" + #r2.object_type=3 + #r2.object_len=111111 + #r2.object_full_len=11111111 + #r2.object_index=1234 + #r2.object_compression=1 + #r2.stream=4 + #r2.jobid=123123 + #print (r2) + #self.assertEqual( + # 'RestoreObject(object_name="this is a very long object name", object="", plugin_name="", object_type=3, object_len=111111, object_full_len=11111111, object_index=1234, object_compression=1, stream=4, jobid=123123)', + # str(test_RestoreObject), + #) + + + + def test_StatPacket(self): + timestamp = time.time() + test_StatPacket = bareosfd.StatPacket() + + # check that the initialization of timestamps from current time stamp works + self.assertAlmostEqual(test_StatPacket.atime, timestamp, delta=1) + self.assertAlmostEqual(test_StatPacket.mtime, timestamp, delta=1) + self.assertAlmostEqual(test_StatPacket.ctime, timestamp, delta=1) + + # set fixed values for comparison + test_StatPacket.atime=999 + test_StatPacket.mtime=1000 + test_StatPacket.ctime=1001 + self.assertEqual( + "StatPacket(dev=0, ino=0, mode=0700, nlink=0, uid=0, gid=0, rdev=0, size=-1, atime=999, mtime=1000, ctime=1001, blksize=4096, blocks=1)", + str(test_StatPacket), + ) + sp2 = bareosfd.StatPacket(dev=0, ino=0, mode=0700, nlink=0, uid=0, gid=0, rdev=0, size=-1, atime=1, mtime=1, ctime=1, blksize=4096, blocks=1) + self.assertEqual('StatPacket(dev=0, ino=0, mode=0700, nlink=0, uid=0, gid=0, rdev=0, size=-1, atime=1, mtime=1, ctime=1, blksize=4096, blocks=1)', str(sp2)) + + def test_SavePacket(self): + test_SavePacket = bareosfd.SavePacket() + self.assertEqual( + 'SavePacket(fname="", link="", type=0, flags=, no_read=0, portable=0, accurate_found=0, cmd="", save_time=0, delta_seq=0, object_name="", object="", object_len=0, object_index=0)', + str(test_SavePacket), + ) + + def test_RestorePacket(self): + test_RestorePacket = bareosfd.RestorePacket() + self.assertEqual( + 'RestorePacket(stream=0, data_stream=0, type=0, file_index=0, linkFI=0, uid=0, statp="", attrEx="", ofname="", olname="", where="", RegexWhere="", replace=0, create_status=0)', + str(test_RestorePacket), + ) + + def test_IoPacket(self): + test_IoPacket = bareosfd.IoPacket() + self.assertEqual( + 'IoPacket(func=0, count=0, flags=0, mode=0000, buf="", fname="", status=0, io_errno=0, lerror=0, whence=0, offset=0, win32=0)', + str(test_IoPacket), + ) + + def test_AclPacket(self): + test_AclPacket = bareosfd.AclPacket() + self.assertEqual('AclPacket(fname="", content="")', str(test_AclPacket)) + + + def test_XattrPacket(self): + test_XattrPacket = bareosfd.XattrPacket() + self.assertEqual( + 'XattrPacket(fname="", name="", value="")', str(test_XattrPacket) + ) + + +if __name__ == "__main__": + unittest.main() From e79140141b7efb2334c11beead31508acb378c17 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 3 Mar 2020 09:49:06 +0100 Subject: [PATCH 023/341] python-dir: build as python module add add unit test --- core/src/plugins/dird/CMakeLists.txt | 16 ++++++++++ core/src/plugins/dird/test/bareosdir_test.py | 31 ++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 core/src/plugins/dird/test/bareosdir_test.py diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index 8a3d56038ad..025046a8264 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -44,3 +44,19 @@ if(HAVE_PYTHON) install(FILES ${PYFILES} DESTINATION ${plugindir}) endif() + + +if(HAVE_PYTHON) + configure_file(setup.py.in setup.py) + add_custom_target(bareosdir ALL + COMMENT "building python module pythonmodules/bareosdir.so" + COMMAND ${PYTHON_EXECUTABLE} setup.py build + COMMAND ${PYTHON_EXECUTABLE} setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + DEPENDS python-dir + ) + + add_test(NAME bareosdir-python-module + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/bareosdir_test.py + ) + set_property(TEST bareosdir-python-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/test" LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib) +endif() diff --git a/core/src/plugins/dird/test/bareosdir_test.py b/core/src/plugins/dird/test/bareosdir_test.py new file mode 100644 index 00000000000..c9cfb1c5591 --- /dev/null +++ b/core/src/plugins/dird/test/bareosdir_test.py @@ -0,0 +1,31 @@ +import unittest +import bareosdir +import time + + +class TestBareosFd(unittest.TestCase): + + def test_GetValue(self): + bareosdir.GetValue() + + def test_SetValue(self): + bareosdir.SetValue() + + def test_DebugMessage(self): + bareosdir.DebugMessage() + + def test_JobMessage(self): + bareosdir.JobMessage() + + def test_RegisterEvents(self): + bareosdir.RegisterEvents() + + def test_UnRegisterEvents(self): + bareosdir.UnRegisterEvents() + + def test_GetInstanceCount(self): + bareosdir.GetInstanceCount() + + +if __name__ == "__main__": + unittest.main() From 77602baf471ec0ced3333cdcd185b709b3b90394 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 3 Mar 2020 10:05:29 +0100 Subject: [PATCH 024/341] python-sd: build as module and add unit test --- .gitignore | 3 ++ core/src/plugins/dird/CMakeLists.txt | 2 +- core/src/plugins/dird/setup.py.in | 13 ++++++++ core/src/plugins/filed/CMakeLists.txt | 2 +- core/src/plugins/stored/CMakeLists.txt | 16 ++++++++++ core/src/plugins/stored/setup.py.in | 13 ++++++++ core/src/plugins/stored/test/bareossd_test.py | 31 +++++++++++++++++++ 7 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 core/src/plugins/dird/setup.py.in create mode 100644 core/src/plugins/stored/setup.py.in create mode 100644 core/src/plugins/stored/test/bareossd_test.py diff --git a/.gitignore b/.gitignore index 86cb7f34380..e26b37ded39 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ *.lo *.o +# Python compiled files +*.pyc + # Compiled Dynamic libraries *.so *.dylib diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index 025046a8264..e588d5bd38e 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -48,7 +48,7 @@ endif() if(HAVE_PYTHON) configure_file(setup.py.in setup.py) - add_custom_target(bareosdir ALL + add_custom_target(bareosdir-pymodule ALL COMMENT "building python module pythonmodules/bareosdir.so" COMMAND ${PYTHON_EXECUTABLE} setup.py build COMMAND ${PYTHON_EXECUTABLE} setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules diff --git a/core/src/plugins/dird/setup.py.in b/core/src/plugins/dird/setup.py.in new file mode 100644 index 00000000000..c1f6187a048 --- /dev/null +++ b/core/src/plugins/dird/setup.py.in @@ -0,0 +1,13 @@ +from distutils.core import setup, Extension + +module1 = Extension('bareosdir', + sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python-dir.cc'], + include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..'], + libraries = ['bareos'], + library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'] + ) + +setup (name = 'bareosdir', + version = '@BAREOS_FULL_VERSION@', + description = 'bareos package', + ext_modules = [module1]) diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index 241e1405f0a..e1bdacbe37f 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -115,7 +115,7 @@ endif() if(HAVE_PYTHON) configure_file(setup.py.in setup.py) - add_custom_target(bareosfd ALL + add_custom_target(bareosfd-pymodule ALL COMMENT "building python module pythonmodules/bareosfd.so" COMMAND ${PYTHON_EXECUTABLE} setup.py build COMMAND ${PYTHON_EXECUTABLE} setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules diff --git a/core/src/plugins/stored/CMakeLists.txt b/core/src/plugins/stored/CMakeLists.txt index 5ab676619ae..6f02b9080b7 100644 --- a/core/src/plugins/stored/CMakeLists.txt +++ b/core/src/plugins/stored/CMakeLists.txt @@ -61,3 +61,19 @@ if(HAVE_PYTHON) install(FILES ${PYFILES} DESTINATION ${plugindir}) endif() + + +if(HAVE_PYTHON) + configure_file(setup.py.in setup.py) + add_custom_target(bareossd-pymodule ALL + COMMENT "building python module pythonmodules/bareossd.so" + COMMAND ${PYTHON_EXECUTABLE} setup.py build + COMMAND ${PYTHON_EXECUTABLE} setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + DEPENDS python-sd + ) + + add_test(NAME bareossd-python-module + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/bareossd_test.py + ) + set_property(TEST bareossd-python-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/test" LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib) +endif() diff --git a/core/src/plugins/stored/setup.py.in b/core/src/plugins/stored/setup.py.in new file mode 100644 index 00000000000..fe92766278d --- /dev/null +++ b/core/src/plugins/stored/setup.py.in @@ -0,0 +1,13 @@ +from distutils.core import setup, Extension + +module1 = Extension('bareossd', + sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python-sd.cc'], + include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..'], + libraries = ['bareos'], + library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'] + ) + +setup (name = 'bareossd', + version = '@BAREOS_FULL_VERSION@', + description = 'bareos package', + ext_modules = [module1]) diff --git a/core/src/plugins/stored/test/bareossd_test.py b/core/src/plugins/stored/test/bareossd_test.py new file mode 100644 index 00000000000..38291140133 --- /dev/null +++ b/core/src/plugins/stored/test/bareossd_test.py @@ -0,0 +1,31 @@ +import unittest +import bareossd +import time + + +class TestBareosFd(unittest.TestCase): + + def test_GetValue(self): + bareossd.GetValue() + + def test_SetValue(self): + bareossd.SetValue() + + def test_DebugMessage(self): + bareossd.DebugMessage() + + def test_JobMessage(self): + bareossd.JobMessage() + + def test_RegisterEvents(self): + bareossd.RegisterEvents() + + def test_UnRegisterEvents(self): + bareossd.UnRegisterEvents() + + def test_GetInstanceCount(self): + bareossd.GetInstanceCount() + + +if __name__ == "__main__": + unittest.main() From 1b8a89e2bd37d0137ce19c13e7a204bf3f290db8 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 13 Aug 2020 10:56:04 +0200 Subject: [PATCH 025/341] all plugins: put each plugin in own subdirectory Every python plugin also gets its own subdirectory below python/ --- .gitignore | 6 + core/src/plugins/dird/CMakeLists.txt | 16 +-- .../dird/{ => example}/example-plugin-dir.cc | 0 .../pyfiles}/BareosDirPluginBaseclass.py | 0 .../{ => python/pyfiles}/BareosDirWrapper.py | 0 .../pyfiles}/bareos-dir-class-plugin.py | 0 .../pyfiles}/bareos-dir.py.template | 0 .../{ => python/pyfiles}/bareos_dir_consts.py | 0 .../plugins/dird/{ => python}/python-dir.cc | 2 +- .../plugins/dird/{ => python}/python-dir.h | 2 +- .../src/plugins/dird/{ => python}/setup.py.in | 2 +- .../dird/{ => python}/test/bareosdir_test.py | 0 .../python}/test/bareosfd_test.py | 0 core/src/plugins/filed/CMakeLists.txt | 27 ++-- .../src/plugins/filed/{ => bpipe}/bpipe-fd.cc | 4 +- .../fileset/plugin-cephfs.conf.example | 1 - .../job/BackupCephfs.conf.example | 1 - .../job/RestoreCephfs.conf.example | 1 - .../plugins/filed/{ => cephfs}/cephfs-fd.cc | 2 +- .../filed/{ => example}/example-plugin-fd.cc | 0 core/src/plugins/filed/fd_common.h | 6 +- .../fileset/plugin-gfapi.conf.example | 1 - .../bareos-dir.d/job/BackupGFAPI.conf.example | 1 - .../job/RestoreGFAPI.conf.example | 0 .../src/plugins/filed/{ => gfapi}/gfapi-fd.cc | 2 +- .../filed/python/bareosfd_module_main.cc | 107 +++++++++++++++ .../{ => python/ldap}/BareosFdPluginLDAP.py | 0 .../filed/{ => python/ldap}/bareos-fd-ldap.py | 0 .../fileset/plugin-ldap.conf.example | 13 ++ .../fileset/plugin-ldap.conf.example.in | 0 .../bareos-dir.d/job/backup-ldap.conf.example | 0 .../job/restore-ldap.conf.example | 0 .../{ => python/ovirt}/BareosFdPluginOvirt.py | 0 .../{ => python/ovirt}/bareos-fd-ovirt.py | 0 .../fileset/plugin-ovirt.conf.example | 10 ++ .../fileset/plugin-ovirt.conf.example.in | 0 .../job/backup-ovirt.conf.example | 0 .../BareosFdPluginPerconaXtraBackup.py | 0 .../bareos-fd-percona-xtrabackup.py | 0 .../pyfiles}/BareosFdPluginBaseclass.py | 0 .../pyfiles}/BareosFdPluginLocalFileset.py | 0 .../{ => python/pyfiles}/BareosFdWrapper.py | 0 .../pyfiles}/bareos-fd-local-fileset.py | 0 .../pyfiles}/bareos-fd-mock-test.py | 0 .../pyfiles}/bareos-fd.py.template | 0 .../{ => python/pyfiles}/bareos_fd_consts.py | 0 .../plugins/filed/{ => python}/python-fd.cc | 2 +- .../plugins/filed/{ => python}/python-fd.h | 2 +- .../plugins/filed/{ => python}/setup.py.in | 2 +- .../test/bareosfd_module_main_test.py | 1 - .../filed/python/test/bareosfd_test.py | 94 +++++++++++++ .../fileset/plugin-rados.conf.example | 1 - .../bareos-dir.d/job/BackupRados.conf.example | 1 - .../job/RestoreRados.conf.example | 0 .../src/plugins/filed/{ => rados}/rados-fd.cc | 4 +- .../{ => test-deltaseq}/test-deltaseq-fd.cc | 4 +- .../filed/{ => test-plugin}/test-plugin-fd.cc | 4 +- core/src/plugins/stored/CMakeLists.txt | 19 ++- .../stored/{ => autoxflate}/autoxflate-sd.cc | 0 .../stored/{ => example}/example-plugin-sd.cc | 0 .../pyfiles}/BareosSdPluginBaseclass.py | 0 .../{ => python/pyfiles}/BareosSdWrapper.py | 0 .../pyfiles}/bareos-sd-class-plugin.py | 0 .../pyfiles}/bareos-sd.py.template | 0 .../{ => python/pyfiles}/bareos_sd_consts.py | 0 .../plugins/stored/{ => python}/python-sd.cc | 2 +- .../plugins/stored/{ => python}/python-sd.h | 2 +- .../plugins/stored/{ => python}/setup.py.in | 2 +- .../stored/{ => python}/test/bareossd_test.py | 0 .../stored/{ => scsicrypto}/scsicrypto-sd.cc | 0 .../{ => scsitapealert}/scsitapealert-sd.cc | 0 systemtests/CMakeLists.txt | 127 +----------------- systemtests/environment.in | 1 + 73 files changed, 286 insertions(+), 186 deletions(-) rename core/src/plugins/dird/{ => example}/example-plugin-dir.cc (100%) rename core/src/plugins/dird/{ => python/pyfiles}/BareosDirPluginBaseclass.py (100%) rename core/src/plugins/dird/{ => python/pyfiles}/BareosDirWrapper.py (100%) rename core/src/plugins/dird/{ => python/pyfiles}/bareos-dir-class-plugin.py (100%) rename core/src/plugins/dird/{ => python/pyfiles}/bareos-dir.py.template (100%) rename core/src/plugins/dird/{ => python/pyfiles}/bareos_dir_consts.py (100%) rename core/src/plugins/dird/{ => python}/python-dir.cc (99%) rename core/src/plugins/dird/{ => python}/python-dir.h (98%) rename core/src/plugins/dird/{ => python}/setup.py.in (96%) rename core/src/plugins/dird/{ => python}/test/bareosdir_test.py (100%) rename core/src/plugins/{filed => dird/python}/test/bareosfd_test.py (100%) rename core/src/plugins/filed/{ => bpipe}/bpipe-fd.cc (99%) rename core/src/plugins/filed/{ => cephfs}/cephfs-conf.d/bareos-dir.d/fileset/plugin-cephfs.conf.example (99%) rename core/src/plugins/filed/{ => cephfs}/cephfs-conf.d/bareos-dir.d/job/BackupCephfs.conf.example (99%) rename core/src/plugins/filed/{ => cephfs}/cephfs-conf.d/bareos-dir.d/job/RestoreCephfs.conf.example (99%) rename core/src/plugins/filed/{ => cephfs}/cephfs-fd.cc (99%) rename core/src/plugins/filed/{ => example}/example-plugin-fd.cc (100%) rename core/src/plugins/filed/{ => gfapi}/gfapi-conf.d/bareos-dir.d/fileset/plugin-gfapi.conf.example (99%) rename core/src/plugins/filed/{ => gfapi}/gfapi-conf.d/bareos-dir.d/job/BackupGFAPI.conf.example (99%) rename core/src/plugins/filed/{ => gfapi}/gfapi-conf.d/bareos-dir.d/job/RestoreGFAPI.conf.example (100%) rename core/src/plugins/filed/{ => gfapi}/gfapi-fd.cc (99%) create mode 100644 core/src/plugins/filed/python/bareosfd_module_main.cc rename core/src/plugins/filed/{ => python/ldap}/BareosFdPluginLDAP.py (100%) rename core/src/plugins/filed/{ => python/ldap}/bareos-fd-ldap.py (100%) create mode 100644 core/src/plugins/filed/python/ldap/python-ldap-conf.d/bareos-dir.d/fileset/plugin-ldap.conf.example rename core/src/plugins/filed/{ => python/ldap}/python-ldap-conf.d/bareos-dir.d/fileset/plugin-ldap.conf.example.in (100%) rename core/src/plugins/filed/{ => python/ldap}/python-ldap-conf.d/bareos-dir.d/job/backup-ldap.conf.example (100%) rename core/src/plugins/filed/{ => python/ldap}/python-ldap-conf.d/bareos-dir.d/job/restore-ldap.conf.example (100%) rename core/src/plugins/filed/{ => python/ovirt}/BareosFdPluginOvirt.py (100%) rename core/src/plugins/filed/{ => python/ovirt}/bareos-fd-ovirt.py (100%) create mode 100644 core/src/plugins/filed/python/ovirt/python-ovirt-conf.d/bareos-dir.d/fileset/plugin-ovirt.conf.example rename core/src/plugins/filed/{ => python/ovirt}/python-ovirt-conf.d/bareos-dir.d/fileset/plugin-ovirt.conf.example.in (100%) rename core/src/plugins/filed/{ => python/ovirt}/python-ovirt-conf.d/bareos-dir.d/job/backup-ovirt.conf.example (100%) rename core/src/plugins/filed/{ => python/percona-xtrabackup}/BareosFdPluginPerconaXtraBackup.py (100%) rename core/src/plugins/filed/{ => python/percona-xtrabackup}/bareos-fd-percona-xtrabackup.py (100%) rename core/src/plugins/filed/{ => python/pyfiles}/BareosFdPluginBaseclass.py (100%) rename core/src/plugins/filed/{ => python/pyfiles}/BareosFdPluginLocalFileset.py (100%) rename core/src/plugins/filed/{ => python/pyfiles}/BareosFdWrapper.py (100%) rename core/src/plugins/filed/{ => python/pyfiles}/bareos-fd-local-fileset.py (100%) rename core/src/plugins/filed/{ => python/pyfiles}/bareos-fd-mock-test.py (100%) rename core/src/plugins/filed/{ => python/pyfiles}/bareos-fd.py.template (100%) rename core/src/plugins/filed/{ => python/pyfiles}/bareos_fd_consts.py (100%) rename core/src/plugins/filed/{ => python}/python-fd.cc (99%) rename core/src/plugins/filed/{ => python}/python-fd.h (99%) rename core/src/plugins/filed/{ => python}/setup.py.in (96%) rename core/src/plugins/filed/{ => python}/test/bareosfd_module_main_test.py (89%) create mode 100644 core/src/plugins/filed/python/test/bareosfd_test.py rename core/src/plugins/filed/{ => rados}/rados-conf.d/bareos-dir.d/fileset/plugin-rados.conf.example (99%) rename core/src/plugins/filed/{ => rados}/rados-conf.d/bareos-dir.d/job/BackupRados.conf.example (99%) rename core/src/plugins/filed/{ => rados}/rados-conf.d/bareos-dir.d/job/RestoreRados.conf.example (100%) rename core/src/plugins/filed/{ => rados}/rados-fd.cc (99%) rename core/src/plugins/filed/{ => test-deltaseq}/test-deltaseq-fd.cc (99%) rename core/src/plugins/filed/{ => test-plugin}/test-plugin-fd.cc (99%) rename core/src/plugins/stored/{ => autoxflate}/autoxflate-sd.cc (100%) rename core/src/plugins/stored/{ => example}/example-plugin-sd.cc (100%) rename core/src/plugins/stored/{ => python/pyfiles}/BareosSdPluginBaseclass.py (100%) rename core/src/plugins/stored/{ => python/pyfiles}/BareosSdWrapper.py (100%) rename core/src/plugins/stored/{ => python/pyfiles}/bareos-sd-class-plugin.py (100%) rename core/src/plugins/stored/{ => python/pyfiles}/bareos-sd.py.template (100%) rename core/src/plugins/stored/{ => python/pyfiles}/bareos_sd_consts.py (100%) rename core/src/plugins/stored/{ => python}/python-sd.cc (99%) rename core/src/plugins/stored/{ => python}/python-sd.h (98%) rename core/src/plugins/stored/{ => python}/setup.py.in (96%) rename core/src/plugins/stored/{ => python}/test/bareossd_test.py (100%) rename core/src/plugins/stored/{ => scsicrypto}/scsicrypto-sd.cc (100%) rename core/src/plugins/stored/{ => scsitapealert}/scsitapealert-sd.cc (100%) diff --git a/.gitignore b/.gitignore index e26b37ded39..03f8666cba5 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,9 @@ # Python compiled files *.pyc +# vim swap file +*.swp + # Compiled Dynamic libraries *.so *.dylib @@ -80,3 +83,6 @@ compile_commands.json # JetBrains Pycharm .idea + +# ctest testing subdirs +*/Testing/* diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index e588d5bd38e..496b3ff5822 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -31,32 +31,32 @@ if(HAVE_WIN32) endif() if(HAVE_PYTHON) - add_library(python-dir MODULE python-dir.cc) + add_library(python-dir MODULE python/python-dir.cc) # do not prefix with "lib" set_target_properties(python-dir PROPERTIES PREFIX "") install(TARGETS python-dir DESTINATION ${plugindir}) target_link_libraries(python-dir ${PYTHON_LIBRARIES} bareos) set(PYFILES - bareos-dir.py.template bareos-dir-class-plugin.py bareos_dir_consts.py - BareosDirPluginBaseclass.py BareosDirWrapper.py + pyfiles/bareos-dir.py.template pyfiles/bareos-dir-class-plugin.py + pyfiles/bareos_dir_consts.py pyfiles/BareosDirPluginBaseclass.py + pyfiles/BareosDirWrapper.py ) install(FILES ${PYFILES} DESTINATION ${plugindir}) endif() - if(HAVE_PYTHON) - configure_file(setup.py.in setup.py) + configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) add_custom_target(bareosdir-pymodule ALL COMMENT "building python module pythonmodules/bareosdir.so" - COMMAND ${PYTHON_EXECUTABLE} setup.py build - COMMAND ${PYTHON_EXECUTABLE} setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + COMMAND ${PYTHON_EXECUTABLE} python/setup.py build + COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/python/pythonmodules DEPENDS python-dir ) add_test(NAME bareosdir-python-module COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/bareosdir_test.py ) - set_property(TEST bareosdir-python-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/test" LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib) + set_property(TEST bareosdir-python-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/python/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib) endif() diff --git a/core/src/plugins/dird/example-plugin-dir.cc b/core/src/plugins/dird/example/example-plugin-dir.cc similarity index 100% rename from core/src/plugins/dird/example-plugin-dir.cc rename to core/src/plugins/dird/example/example-plugin-dir.cc diff --git a/core/src/plugins/dird/BareosDirPluginBaseclass.py b/core/src/plugins/dird/python/pyfiles/BareosDirPluginBaseclass.py similarity index 100% rename from core/src/plugins/dird/BareosDirPluginBaseclass.py rename to core/src/plugins/dird/python/pyfiles/BareosDirPluginBaseclass.py diff --git a/core/src/plugins/dird/BareosDirWrapper.py b/core/src/plugins/dird/python/pyfiles/BareosDirWrapper.py similarity index 100% rename from core/src/plugins/dird/BareosDirWrapper.py rename to core/src/plugins/dird/python/pyfiles/BareosDirWrapper.py diff --git a/core/src/plugins/dird/bareos-dir-class-plugin.py b/core/src/plugins/dird/python/pyfiles/bareos-dir-class-plugin.py similarity index 100% rename from core/src/plugins/dird/bareos-dir-class-plugin.py rename to core/src/plugins/dird/python/pyfiles/bareos-dir-class-plugin.py diff --git a/core/src/plugins/dird/bareos-dir.py.template b/core/src/plugins/dird/python/pyfiles/bareos-dir.py.template similarity index 100% rename from core/src/plugins/dird/bareos-dir.py.template rename to core/src/plugins/dird/python/pyfiles/bareos-dir.py.template diff --git a/core/src/plugins/dird/bareos_dir_consts.py b/core/src/plugins/dird/python/pyfiles/bareos_dir_consts.py similarity index 100% rename from core/src/plugins/dird/bareos_dir_consts.py rename to core/src/plugins/dird/python/pyfiles/bareos_dir_consts.py diff --git a/core/src/plugins/dird/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc similarity index 99% rename from core/src/plugins/dird/python-dir.cc rename to core/src/plugins/dird/python/python-dir.cc index 76482c5c404..868c6f3aec7 100644 --- a/core/src/plugins/dird/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -127,7 +127,7 @@ struct plugin_private_context { static PyThreadState* mainThreadState; /* functions common to all plugins */ -#include "../python_plugins_common.inc" +#include "plugins/python_plugins_common.inc" #ifdef __cplusplus extern "C" { diff --git a/core/src/plugins/dird/python-dir.h b/core/src/plugins/dird/python/python-dir.h similarity index 98% rename from core/src/plugins/dird/python-dir.h rename to core/src/plugins/dird/python/python-dir.h index 880b54b78d0..26bf63576ae 100644 --- a/core/src/plugins/dird/python-dir.h +++ b/core/src/plugins/dird/python/python-dir.h @@ -31,7 +31,7 @@ #define PYTHON_MODULE_NAME_QUOTED "bareosdir" /* common code for all python plugins */ -#include "../python_plugins_common.h" +#include "plugins/python_plugins_common.h" #include "plugins/filed/fd_common.h" namespace directordaemon { diff --git a/core/src/plugins/dird/setup.py.in b/core/src/plugins/dird/python/setup.py.in similarity index 96% rename from core/src/plugins/dird/setup.py.in rename to core/src/plugins/dird/python/setup.py.in index c1f6187a048..ec9f2d55e37 100644 --- a/core/src/plugins/dird/setup.py.in +++ b/core/src/plugins/dird/python/setup.py.in @@ -1,7 +1,7 @@ from distutils.core import setup, Extension module1 = Extension('bareosdir', - sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python-dir.cc'], + sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/python-dir.cc'], include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..'], libraries = ['bareos'], library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'] diff --git a/core/src/plugins/dird/test/bareosdir_test.py b/core/src/plugins/dird/python/test/bareosdir_test.py similarity index 100% rename from core/src/plugins/dird/test/bareosdir_test.py rename to core/src/plugins/dird/python/test/bareosdir_test.py diff --git a/core/src/plugins/filed/test/bareosfd_test.py b/core/src/plugins/dird/python/test/bareosfd_test.py similarity index 100% rename from core/src/plugins/filed/test/bareosfd_test.py rename to core/src/plugins/dird/python/test/bareosfd_test.py diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index e1bdacbe37f..b0b0bae4818 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -45,7 +45,7 @@ include_directories(${OPENSSL_INCLUDE_DIR}) # set(DLLIBS dl) -add_library(bpipe-fd MODULE bpipe-fd.cc) +add_library(bpipe-fd MODULE bpipe/bpipe-fd.cc) set_target_properties(bpipe-fd PROPERTIES PREFIX "") install( TARGETS bpipe-fd @@ -72,7 +72,7 @@ if(HAVE_WIN32) endif() if(${HAVE_CEPHFS}) - add_library(cephfs-fd MODULE cephfs-fd.cc) + add_library(cephfs-fd MODULE cephfs/cephfs-fd.cc) set_target_properties(cephfs-fd PROPERTIES PREFIX "") install( TARGETS cephfs-fd @@ -82,7 +82,7 @@ if(${HAVE_CEPHFS}) endif() if(${HAVE_CEPH_RADOS}) - add_library(rados-fd MODULE rados-fd.cc) + add_library(rados-fd MODULE rados/rados-fd.cc) set_target_properties(rados-fd PROPERTIES PREFIX "") install( TARGETS rados-fd @@ -92,12 +92,12 @@ if(${HAVE_CEPH_RADOS}) endif() if(NOT HAVE_WIN32) - add_library(example-plugin-fd MODULE example-plugin-fd.cc) + add_library(example-plugin-fd MODULE example/example-plugin-fd.cc) set_target_properties(example-plugin-fd PROPERTIES PREFIX "") endif() if(HAVE_PYTHON) - add_library(python-fd MODULE python-fd.cc) + add_library(python-fd MODULE python/python-fd.cc) set_target_properties(python-fd PROPERTIES PREFIX "") install( TARGETS python-fd @@ -108,24 +108,23 @@ if(HAVE_PYTHON) endif() if(HAVE_PYTHON) - add_executable( bareosfd_module_main bareosfd_module_main.cc) + add_executable(bareosfd_module_main python/bareosfd_module_main.cc) target_link_libraries(bareosfd_module_main ${PYTHON_LIBRARIES} bareos) endif() if(HAVE_PYTHON) - configure_file(setup.py.in setup.py) - + configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) add_custom_target(bareosfd-pymodule ALL COMMENT "building python module pythonmodules/bareosfd.so" - COMMAND ${PYTHON_EXECUTABLE} setup.py build - COMMAND ${PYTHON_EXECUTABLE} setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + COMMAND ${PYTHON_EXECUTABLE} python/setup.py build + COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules DEPENDS python-fd ) add_test(NAME bareosfd-python-module - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/bareosfd_test.py + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosfd_test.py ) - set_property(TEST bareosfd-python-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/test" LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib) + set_property(TEST bareosfd-python-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib) endif() @@ -133,7 +132,7 @@ endif() if(${HAVE_GLUSTERFS}) - add_library(gfapi-fd MODULE gfapi-fd.cc) + add_library(gfapi-fd MODULE gfapi/gfapi-fd.cc) set_target_properties(gfapi-fd PROPERTIES PREFIX "") install( TARGETS gfapi-fd @@ -145,7 +144,7 @@ if(${HAVE_GLUSTERFS}) endif() if(${HAVE_TEST_PLUGIN}) - add_library(test-plugin-fd MODULE test-plugin-fd.cc) + add_library(test-plugin-fd MODULE test-plugin/test-plugin-fd.cc) # do not prefix with "lib" set_target_properties(test-plugin-fd PROPERTIES PREFIX "") install( diff --git a/core/src/plugins/filed/bpipe-fd.cc b/core/src/plugins/filed/bpipe/bpipe-fd.cc similarity index 99% rename from core/src/plugins/filed/bpipe-fd.cc rename to core/src/plugins/filed/bpipe/bpipe-fd.cc index 8faf81308ff..c77caf1c5f4 100644 --- a/core/src/plugins/filed/bpipe-fd.cc +++ b/core/src/plugins/filed/bpipe/bpipe-fd.cc @@ -2,7 +2,7 @@ BAREOS® - Backup Archiving REcovery Open Sourced Copyright (C) 2007-2012 Free Software Foundation Europe e.V. - Copyright (C) 2014-2018 Bareos GmbH & Co. KG + Copyright (C) 2014-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -28,7 +28,7 @@ */ #include "include/bareos.h" #include "filed/fd_plugins.h" -#include "fd_common.h" +#include "plugins/filed/fd_common.h" namespace filedaemon { diff --git a/core/src/plugins/filed/cephfs-conf.d/bareos-dir.d/fileset/plugin-cephfs.conf.example b/core/src/plugins/filed/cephfs/cephfs-conf.d/bareos-dir.d/fileset/plugin-cephfs.conf.example similarity index 99% rename from core/src/plugins/filed/cephfs-conf.d/bareos-dir.d/fileset/plugin-cephfs.conf.example rename to core/src/plugins/filed/cephfs/cephfs-conf.d/bareos-dir.d/fileset/plugin-cephfs.conf.example index 7ef1ca61854..3629d57fd2d 100644 --- a/core/src/plugins/filed/cephfs-conf.d/bareos-dir.d/fileset/plugin-cephfs.conf.example +++ b/core/src/plugins/filed/cephfs/cephfs-conf.d/bareos-dir.d/fileset/plugin-cephfs.conf.example @@ -11,4 +11,3 @@ FileSet { Plugin = "cephfs:conffile=:basedir=:" } } - diff --git a/core/src/plugins/filed/cephfs-conf.d/bareos-dir.d/job/BackupCephfs.conf.example b/core/src/plugins/filed/cephfs/cephfs-conf.d/bareos-dir.d/job/BackupCephfs.conf.example similarity index 99% rename from core/src/plugins/filed/cephfs-conf.d/bareos-dir.d/job/BackupCephfs.conf.example rename to core/src/plugins/filed/cephfs/cephfs-conf.d/bareos-dir.d/job/BackupCephfs.conf.example index 865d91c72f6..92319f37b61 100644 --- a/core/src/plugins/filed/cephfs-conf.d/bareos-dir.d/job/BackupCephfs.conf.example +++ b/core/src/plugins/filed/cephfs/cephfs-conf.d/bareos-dir.d/job/BackupCephfs.conf.example @@ -4,4 +4,3 @@ Job { FileSet = "plugin-cephfs" # Client = "cephfshost-fd" } - diff --git a/core/src/plugins/filed/cephfs-conf.d/bareos-dir.d/job/RestoreCephfs.conf.example b/core/src/plugins/filed/cephfs/cephfs-conf.d/bareos-dir.d/job/RestoreCephfs.conf.example similarity index 99% rename from core/src/plugins/filed/cephfs-conf.d/bareos-dir.d/job/RestoreCephfs.conf.example rename to core/src/plugins/filed/cephfs/cephfs-conf.d/bareos-dir.d/job/RestoreCephfs.conf.example index 122a583f3a1..d0b688c46b0 100644 --- a/core/src/plugins/filed/cephfs-conf.d/bareos-dir.d/job/RestoreCephfs.conf.example +++ b/core/src/plugins/filed/cephfs/cephfs-conf.d/bareos-dir.d/job/RestoreCephfs.conf.example @@ -5,4 +5,3 @@ Job { Fileset= "plugin-cephfs" # Client = "cephfshost-fd" } - diff --git a/core/src/plugins/filed/cephfs-fd.cc b/core/src/plugins/filed/cephfs/cephfs-fd.cc similarity index 99% rename from core/src/plugins/filed/cephfs-fd.cc rename to core/src/plugins/filed/cephfs/cephfs-fd.cc index c58833097fc..047b587dd5b 100644 --- a/core/src/plugins/filed/cephfs-fd.cc +++ b/core/src/plugins/filed/cephfs/cephfs-fd.cc @@ -25,7 +25,7 @@ */ #include "include/bareos.h" #include "filed/fd_plugins.h" -#include "fd_common.h" +#include "plugins/filed/fd_common.h" #include "include/fileopts.h" #include "lib/alist.h" #include "lib/berrno.h" diff --git a/core/src/plugins/filed/example-plugin-fd.cc b/core/src/plugins/filed/example/example-plugin-fd.cc similarity index 100% rename from core/src/plugins/filed/example-plugin-fd.cc rename to core/src/plugins/filed/example/example-plugin-fd.cc diff --git a/core/src/plugins/filed/fd_common.h b/core/src/plugins/filed/fd_common.h index 98aebd2954c..04167789ec0 100644 --- a/core/src/plugins/filed/fd_common.h +++ b/core/src/plugins/filed/fd_common.h @@ -39,7 +39,8 @@ if (bfuncs && context) { \ bfuncs->DebugMessage(context, __FILE__, __LINE__, level, __VA_ARGS__); \ } else { \ - printf( \ + fprintf( \ + stderr, \ "Dmsg: bfuncs(%p) and context(%p) need to be set before Dmsg call\n", \ bfuncs, context); \ } @@ -48,7 +49,8 @@ if (bfuncs && context) { \ bfuncs->JobMessage(context, __FILE__, __LINE__, type, 0, __VA_ARGS__); \ } else { \ - printf( \ + fprintf( \ + stderr, \ "Jmsg: bfuncs(%p) and context(%p) need to be set before Jmsg call\n", \ bfuncs, context); \ } diff --git a/core/src/plugins/filed/gfapi-conf.d/bareos-dir.d/fileset/plugin-gfapi.conf.example b/core/src/plugins/filed/gfapi/gfapi-conf.d/bareos-dir.d/fileset/plugin-gfapi.conf.example similarity index 99% rename from core/src/plugins/filed/gfapi-conf.d/bareos-dir.d/fileset/plugin-gfapi.conf.example rename to core/src/plugins/filed/gfapi/gfapi-conf.d/bareos-dir.d/fileset/plugin-gfapi.conf.example index 80de839a5a2..b89618eeab8 100644 --- a/core/src/plugins/filed/gfapi-conf.d/bareos-dir.d/fileset/plugin-gfapi.conf.example +++ b/core/src/plugins/filed/gfapi/gfapi-conf.d/bareos-dir.d/fileset/plugin-gfapi.conf.example @@ -10,4 +10,3 @@ FileSet { Plugin = "gfapi:volume=gluster\\://glusterhost.example.com/dvol1/data:" } } - diff --git a/core/src/plugins/filed/gfapi-conf.d/bareos-dir.d/job/BackupGFAPI.conf.example b/core/src/plugins/filed/gfapi/gfapi-conf.d/bareos-dir.d/job/BackupGFAPI.conf.example similarity index 99% rename from core/src/plugins/filed/gfapi-conf.d/bareos-dir.d/job/BackupGFAPI.conf.example rename to core/src/plugins/filed/gfapi/gfapi-conf.d/bareos-dir.d/job/BackupGFAPI.conf.example index 3f076322f6f..cd4d0f442b7 100644 --- a/core/src/plugins/filed/gfapi-conf.d/bareos-dir.d/job/BackupGFAPI.conf.example +++ b/core/src/plugins/filed/gfapi/gfapi-conf.d/bareos-dir.d/job/BackupGFAPI.conf.example @@ -4,4 +4,3 @@ Job { FileSet = "plugin-gfapi" # Client = "gfapihost-fd" } - diff --git a/core/src/plugins/filed/gfapi-conf.d/bareos-dir.d/job/RestoreGFAPI.conf.example b/core/src/plugins/filed/gfapi/gfapi-conf.d/bareos-dir.d/job/RestoreGFAPI.conf.example similarity index 100% rename from core/src/plugins/filed/gfapi-conf.d/bareos-dir.d/job/RestoreGFAPI.conf.example rename to core/src/plugins/filed/gfapi/gfapi-conf.d/bareos-dir.d/job/RestoreGFAPI.conf.example diff --git a/core/src/plugins/filed/gfapi-fd.cc b/core/src/plugins/filed/gfapi/gfapi-fd.cc similarity index 99% rename from core/src/plugins/filed/gfapi-fd.cc rename to core/src/plugins/filed/gfapi/gfapi-fd.cc index 33506601453..a7321a4c510 100644 --- a/core/src/plugins/filed/gfapi-fd.cc +++ b/core/src/plugins/filed/gfapi/gfapi-fd.cc @@ -25,7 +25,7 @@ */ #include "include/bareos.h" #include "filed/fd_plugins.h" -#include "fd_common.h" +#include "plugins/filed/fd_common.h" #include "include/fileopts.h" #include "lib/alist.h" #include "lib/path_list.h" diff --git a/core/src/plugins/filed/python/bareosfd_module_main.cc b/core/src/plugins/filed/python/bareosfd_module_main.cc new file mode 100644 index 00000000000..4ea0ca846fd --- /dev/null +++ b/core/src/plugins/filed/python/bareosfd_module_main.cc @@ -0,0 +1,107 @@ +#include "Python.h" +class PoolMem; +#define NbytesForBits(n) ((((n)-1) >> 3) + 1) +typedef off_t boffset_t; + +#include "lib/plugins.h" +#include "filed/fd_plugins.h" + +static void PyErrorHandler() +{ + PyObject *type, *value, *traceback; + PyObject* tracebackModule; + char* error_string; + + PyErr_Fetch(&type, &value, &traceback); + + tracebackModule = PyImport_ImportModule("traceback"); + if (tracebackModule != NULL) { + PyObject *tbList, *emptyString, *strRetval; + + tbList = + PyObject_CallMethod(tracebackModule, (char*)"format_exception", + (char*)"OOO", type, value == NULL ? Py_None : value, + traceback == NULL ? Py_None : traceback); + + emptyString = PyString_FromString(""); + strRetval = + PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); + + error_string = strdup(PyString_AsString(strRetval)); + + Py_DECREF(tbList); + Py_DECREF(emptyString); + Py_DECREF(strRetval); + Py_DECREF(tracebackModule); + } else { + error_string = strdup("Unable to import traceback module."); + } + Py_DECREF(type); + Py_XDECREF(value); + Py_XDECREF(traceback); + printf("%s", error_string); + + free(error_string); + exit(1); +} + +using namespace filedaemon; + +int main(int argc, char* argv[]) +{ + static filedaemon::bFuncs bfuncs; + Py_SetProgramName(argv[0]); + Py_Initialize(); + PyRun_SimpleString( + "from time import time,ctime\n" + "print 'Today is',ctime(time())\n"); + + + PyObject* bareosfdModule = PyImport_ImportModule("bareosfd"); + if (bareosfdModule) { + printf("loading bareosfd successfully\n"); + } else { + printf("loaded bareosfd failed\n"); + } + if (PyErr_Occurred()) { PyErrorHandler(); } + + // Extract capsule pointer from bareosfd module + void* ctx_from_bareosfd_module = PyCapsule_Import("bareosfd.bpContext", 0); + + if (ctx_from_bareosfd_module) { + printf("module_main: imported capsule successfully\n"); + printf("module_main: ctx_from_bareosfd_module is at %p\n", + ctx_from_bareosfd_module); + + printf("bfuncs are at: %p\n", &bfuncs); + ctx_from_bareosfd_module = &bfuncs; + printf("ctx_from_bareosfd_module contains %p\n", ctx_from_bareosfd_module); + } + + PyObject* pModule = PyImport_ImportModule("bareosfd_module_main_test"); + + if (PyErr_Occurred()) { PyErrorHandler(); } + + PyObject* pDict = PyModule_GetDict(pModule); + PyObject* pFunc = PyDict_GetItemString(pDict, "load_bareos_plugin"); + + if (pFunc && PyCallable_Check(pFunc)) { + printf("load_bareos_plugin found and is callable\n"); + PyObject *pPluginDefinition, *pRetVal; + + + pPluginDefinition = PyString_FromString((char*)"PluginDefinition"); + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); + + Py_DECREF(pPluginDefinition); + if (pRetVal) { Py_DECREF(pRetVal); } + if (PyErr_Occurred()) { PyErrorHandler(); } + } else { + printf("load_bareos_plugin() not found in module"); + } + Py_DECREF(pDict); + Py_DECREF(pFunc); + Py_Finalize(); + return 0; +} diff --git a/core/src/plugins/filed/BareosFdPluginLDAP.py b/core/src/plugins/filed/python/ldap/BareosFdPluginLDAP.py similarity index 100% rename from core/src/plugins/filed/BareosFdPluginLDAP.py rename to core/src/plugins/filed/python/ldap/BareosFdPluginLDAP.py diff --git a/core/src/plugins/filed/bareos-fd-ldap.py b/core/src/plugins/filed/python/ldap/bareos-fd-ldap.py similarity index 100% rename from core/src/plugins/filed/bareos-fd-ldap.py rename to core/src/plugins/filed/python/ldap/bareos-fd-ldap.py diff --git a/core/src/plugins/filed/python/ldap/python-ldap-conf.d/bareos-dir.d/fileset/plugin-ldap.conf.example b/core/src/plugins/filed/python/ldap/python-ldap-conf.d/bareos-dir.d/fileset/plugin-ldap.conf.example new file mode 100644 index 00000000000..61a873a3780 --- /dev/null +++ b/core/src/plugins/filed/python/ldap/python-ldap-conf.d/bareos-dir.d/fileset/plugin-ldap.conf.example @@ -0,0 +1,13 @@ + +FileSet { + Name = "plugin-ldap" + Include { + Options { + signature = MD5 + } + # adapt the LDAP settings to your environment. + # uri and basedn are mandantory, + # base_dn and password are optional. + Plugin = "python:module_path=/usr/local/lib64/bareos/plugins:module_name=bareos-fd-ldap:uri=ldap\\://localhost:basedn=dc=example,dc=com:bind_dn=cn=admin,dc=example,dc=com:password=secret" + } +} diff --git a/core/src/plugins/filed/python-ldap-conf.d/bareos-dir.d/fileset/plugin-ldap.conf.example.in b/core/src/plugins/filed/python/ldap/python-ldap-conf.d/bareos-dir.d/fileset/plugin-ldap.conf.example.in similarity index 100% rename from core/src/plugins/filed/python-ldap-conf.d/bareos-dir.d/fileset/plugin-ldap.conf.example.in rename to core/src/plugins/filed/python/ldap/python-ldap-conf.d/bareos-dir.d/fileset/plugin-ldap.conf.example.in diff --git a/core/src/plugins/filed/python-ldap-conf.d/bareos-dir.d/job/backup-ldap.conf.example b/core/src/plugins/filed/python/ldap/python-ldap-conf.d/bareos-dir.d/job/backup-ldap.conf.example similarity index 100% rename from core/src/plugins/filed/python-ldap-conf.d/bareos-dir.d/job/backup-ldap.conf.example rename to core/src/plugins/filed/python/ldap/python-ldap-conf.d/bareos-dir.d/job/backup-ldap.conf.example diff --git a/core/src/plugins/filed/python-ldap-conf.d/bareos-dir.d/job/restore-ldap.conf.example b/core/src/plugins/filed/python/ldap/python-ldap-conf.d/bareos-dir.d/job/restore-ldap.conf.example similarity index 100% rename from core/src/plugins/filed/python-ldap-conf.d/bareos-dir.d/job/restore-ldap.conf.example rename to core/src/plugins/filed/python/ldap/python-ldap-conf.d/bareos-dir.d/job/restore-ldap.conf.example diff --git a/core/src/plugins/filed/BareosFdPluginOvirt.py b/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py similarity index 100% rename from core/src/plugins/filed/BareosFdPluginOvirt.py rename to core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py diff --git a/core/src/plugins/filed/bareos-fd-ovirt.py b/core/src/plugins/filed/python/ovirt/bareos-fd-ovirt.py similarity index 100% rename from core/src/plugins/filed/bareos-fd-ovirt.py rename to core/src/plugins/filed/python/ovirt/bareos-fd-ovirt.py diff --git a/core/src/plugins/filed/python/ovirt/python-ovirt-conf.d/bareos-dir.d/fileset/plugin-ovirt.conf.example b/core/src/plugins/filed/python/ovirt/python-ovirt-conf.d/bareos-dir.d/fileset/plugin-ovirt.conf.example new file mode 100644 index 00000000000..0dc15fb400d --- /dev/null +++ b/core/src/plugins/filed/python/ovirt/python-ovirt-conf.d/bareos-dir.d/fileset/plugin-ovirt.conf.example @@ -0,0 +1,10 @@ +FileSet { + Name = "plugin-ovirt" + Include { + Options { + signature = MD5 + } + # + Plugin = "python:module_path=/usr/local/lib64/bareos/plugins:module_name=bareos-fd-ovirt:ca=/etc/bareos/ovirt-ca.cert:server=ovirt-engine.example.com:username=admin@internal:password=yourSecretPassword:vm_name=testvm1" + } +} diff --git a/core/src/plugins/filed/python-ovirt-conf.d/bareos-dir.d/fileset/plugin-ovirt.conf.example.in b/core/src/plugins/filed/python/ovirt/python-ovirt-conf.d/bareos-dir.d/fileset/plugin-ovirt.conf.example.in similarity index 100% rename from core/src/plugins/filed/python-ovirt-conf.d/bareos-dir.d/fileset/plugin-ovirt.conf.example.in rename to core/src/plugins/filed/python/ovirt/python-ovirt-conf.d/bareos-dir.d/fileset/plugin-ovirt.conf.example.in diff --git a/core/src/plugins/filed/python-ovirt-conf.d/bareos-dir.d/job/backup-ovirt.conf.example b/core/src/plugins/filed/python/ovirt/python-ovirt-conf.d/bareos-dir.d/job/backup-ovirt.conf.example similarity index 100% rename from core/src/plugins/filed/python-ovirt-conf.d/bareos-dir.d/job/backup-ovirt.conf.example rename to core/src/plugins/filed/python/ovirt/python-ovirt-conf.d/bareos-dir.d/job/backup-ovirt.conf.example diff --git a/core/src/plugins/filed/BareosFdPluginPerconaXtraBackup.py b/core/src/plugins/filed/python/percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py similarity index 100% rename from core/src/plugins/filed/BareosFdPluginPerconaXtraBackup.py rename to core/src/plugins/filed/python/percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py diff --git a/core/src/plugins/filed/bareos-fd-percona-xtrabackup.py b/core/src/plugins/filed/python/percona-xtrabackup/bareos-fd-percona-xtrabackup.py similarity index 100% rename from core/src/plugins/filed/bareos-fd-percona-xtrabackup.py rename to core/src/plugins/filed/python/percona-xtrabackup/bareos-fd-percona-xtrabackup.py diff --git a/core/src/plugins/filed/BareosFdPluginBaseclass.py b/core/src/plugins/filed/python/pyfiles/BareosFdPluginBaseclass.py similarity index 100% rename from core/src/plugins/filed/BareosFdPluginBaseclass.py rename to core/src/plugins/filed/python/pyfiles/BareosFdPluginBaseclass.py diff --git a/core/src/plugins/filed/BareosFdPluginLocalFileset.py b/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py similarity index 100% rename from core/src/plugins/filed/BareosFdPluginLocalFileset.py rename to core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py diff --git a/core/src/plugins/filed/BareosFdWrapper.py b/core/src/plugins/filed/python/pyfiles/BareosFdWrapper.py similarity index 100% rename from core/src/plugins/filed/BareosFdWrapper.py rename to core/src/plugins/filed/python/pyfiles/BareosFdWrapper.py diff --git a/core/src/plugins/filed/bareos-fd-local-fileset.py b/core/src/plugins/filed/python/pyfiles/bareos-fd-local-fileset.py similarity index 100% rename from core/src/plugins/filed/bareos-fd-local-fileset.py rename to core/src/plugins/filed/python/pyfiles/bareos-fd-local-fileset.py diff --git a/core/src/plugins/filed/bareos-fd-mock-test.py b/core/src/plugins/filed/python/pyfiles/bareos-fd-mock-test.py similarity index 100% rename from core/src/plugins/filed/bareos-fd-mock-test.py rename to core/src/plugins/filed/python/pyfiles/bareos-fd-mock-test.py diff --git a/core/src/plugins/filed/bareos-fd.py.template b/core/src/plugins/filed/python/pyfiles/bareos-fd.py.template similarity index 100% rename from core/src/plugins/filed/bareos-fd.py.template rename to core/src/plugins/filed/python/pyfiles/bareos-fd.py.template diff --git a/core/src/plugins/filed/bareos_fd_consts.py b/core/src/plugins/filed/python/pyfiles/bareos_fd_consts.py similarity index 100% rename from core/src/plugins/filed/bareos_fd_consts.py rename to core/src/plugins/filed/python/pyfiles/bareos_fd_consts.py diff --git a/core/src/plugins/filed/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc similarity index 99% rename from core/src/plugins/filed/python-fd.cc rename to core/src/plugins/filed/python/python-fd.cc index 498d0af5844..bcf5bc56c0f 100644 --- a/core/src/plugins/filed/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -165,7 +165,7 @@ struct plugin_private_context { static PyThreadState* mainThreadState; /* functions common to all plugins */ -#include "../python_plugins_common.inc" +#include "plugins/python_plugins_common.inc" #ifdef __cplusplus extern "C" { diff --git a/core/src/plugins/filed/python-fd.h b/core/src/plugins/filed/python/python-fd.h similarity index 99% rename from core/src/plugins/filed/python-fd.h rename to core/src/plugins/filed/python/python-fd.h index 2620e91f566..b48d2519b19 100644 --- a/core/src/plugins/filed/python-fd.h +++ b/core/src/plugins/filed/python/python-fd.h @@ -31,7 +31,7 @@ #define PYTHON_MODULE_NAME_QUOTED "bareosfd" /* common code for all python plugins */ -#include "../python_plugins_common.h" +#include "plugins/python_plugins_common.h" #include "plugins/filed/fd_common.h" #include "structmember.h" diff --git a/core/src/plugins/filed/setup.py.in b/core/src/plugins/filed/python/setup.py.in similarity index 96% rename from core/src/plugins/filed/setup.py.in rename to core/src/plugins/filed/python/setup.py.in index 6d154066330..6b8995e853a 100644 --- a/core/src/plugins/filed/setup.py.in +++ b/core/src/plugins/filed/python/setup.py.in @@ -1,7 +1,7 @@ from distutils.core import setup, Extension module1 = Extension('bareosfd', - sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python-fd.cc'], + sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/python-fd.cc'], include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..'], libraries = ['bareos'], library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'] diff --git a/core/src/plugins/filed/test/bareosfd_module_main_test.py b/core/src/plugins/filed/python/test/bareosfd_module_main_test.py similarity index 89% rename from core/src/plugins/filed/test/bareosfd_module_main_test.py rename to core/src/plugins/filed/python/test/bareosfd_module_main_test.py index 08dcb75567a..54b21faf71c 100644 --- a/core/src/plugins/filed/test/bareosfd_module_main_test.py +++ b/core/src/plugins/filed/python/test/bareosfd_module_main_test.py @@ -2,7 +2,6 @@ def load_bareos_plugin(plugindef): print ("Hello from load_bareos_plugin") - #print (context) print (plugindef) print (bareosfd) bareosfd.DebugMessage(100, "Kuckuck") diff --git a/core/src/plugins/filed/python/test/bareosfd_test.py b/core/src/plugins/filed/python/test/bareosfd_test.py new file mode 100644 index 00000000000..37fe3b04c2f --- /dev/null +++ b/core/src/plugins/filed/python/test/bareosfd_test.py @@ -0,0 +1,94 @@ +import unittest +import bareosfd +import time + + +class TestBareosFd(unittest.TestCase): + + def test_SetValue(self): + bareosfd.SetValue(1, 123) + + def test_DebugMessage(self): + bareosfd.DebugMessage(100,"testdebugmessage\n") + + def test_RestoreObject(self): + test_RestoreObject = bareosfd.RestoreObject() + self.assertEqual( + 'RestoreObject(object_name="", object="", plugin_name="", object_type=0, object_len=0, object_full_len=0, object_index=0, object_compression=0, stream=0, jobid=0)', + str(test_RestoreObject), + ) + + #r2 = bareosfd.RestoreObject() + #r2.object_name="this is a very long object name" + #r2.object="123456780" + ##r2.plugin_name="this is a plugin name" + #r2.object_type=3 + #r2.object_len=111111 + #r2.object_full_len=11111111 + #r2.object_index=1234 + #r2.object_compression=1 + #r2.stream=4 + #r2.jobid=123123 + #print (r2) + #self.assertEqual( + # 'RestoreObject(object_name="this is a very long object name", object="", plugin_name="", object_type=3, object_len=111111, object_full_len=11111111, object_index=1234, object_compression=1, stream=4, jobid=123123)', + # str(test_RestoreObject), + #) + + + + def test_StatPacket(self): + timestamp = time.time() + test_StatPacket = bareosfd.StatPacket() + + # check that the initialization of timestamps from current time stamp works + self.assertAlmostEqual(test_StatPacket.atime, timestamp, delta=1) + self.assertAlmostEqual(test_StatPacket.mtime, timestamp, delta=1) + self.assertAlmostEqual(test_StatPacket.ctime, timestamp, delta=1) + + # set fixed values for comparison + test_StatPacket.atime=999 + test_StatPacket.mtime=1000 + test_StatPacket.ctime=1001 + self.assertEqual( + "StatPacket(dev=0, ino=0, mode=0700, nlink=0, uid=0, gid=0, rdev=0, size=-1, atime=999, mtime=1000, ctime=1001, blksize=4096, blocks=1)", + str(test_StatPacket), + ) + sp2 = bareosfd.StatPacket(dev=0, ino=0, mode=0700, nlink=0, uid=0, gid=0, rdev=0, size=-1, atime=1, mtime=1, ctime=1, blksize=4096, blocks=1) + self.assertEqual('StatPacket(dev=0, ino=0, mode=0700, nlink=0, uid=0, gid=0, rdev=0, size=-1, atime=1, mtime=1, ctime=1, blksize=4096, blocks=1)', str(sp2)) + + def test_SavePacket(self): + test_SavePacket = bareosfd.SavePacket() + self.assertEqual( + 'SavePacket(fname="", link="", type=0, flags=, no_read=0, portable=0, accurate_found=0, cmd="", save_time=0, delta_seq=0, object_name="", object="", object_len=0, object_index=0)', + str(test_SavePacket), + ) + + def test_RestorePacket(self): + test_RestorePacket = bareosfd.RestorePacket() + self.assertEqual( + 'RestorePacket(stream=0, data_stream=0, type=0, file_index=0, linkFI=0, uid=0, statp="", attrEx="", ofname="", olname="", where="", RegexWhere="", replace=0, create_status=0)', + str(test_RestorePacket), + ) + + def test_IoPacket(self): + test_IoPacket = bareosfd.IoPacket() + self.assertEqual( + 'IoPacket(func=0, count=0, flags=0, mode=0000, buf="", fname="", status=0, io_errno=0, lerror=0, whence=0, offset=0, win32=0)', + str(test_IoPacket), + ) + + def test_AclPacket(self): + test_AclPacket = bareosfd.AclPacket() + self.assertEqual('AclPacket(fname="", content="")', str(test_AclPacket)) + + + def test_XattrPacket(self): + test_XattrPacket = bareosfd.XattrPacket() + self.assertEqual( + 'XattrPacket(fname="", name="", value="")', str(test_XattrPacket) + ) + + +if __name__ == "__main__": + unittest.main() diff --git a/core/src/plugins/filed/rados-conf.d/bareos-dir.d/fileset/plugin-rados.conf.example b/core/src/plugins/filed/rados/rados-conf.d/bareos-dir.d/fileset/plugin-rados.conf.example similarity index 99% rename from core/src/plugins/filed/rados-conf.d/bareos-dir.d/fileset/plugin-rados.conf.example rename to core/src/plugins/filed/rados/rados-conf.d/bareos-dir.d/fileset/plugin-rados.conf.example index 96ef57c270b..9b318808ceb 100644 --- a/core/src/plugins/filed/rados-conf.d/bareos-dir.d/fileset/plugin-rados.conf.example +++ b/core/src/plugins/filed/rados/rados-conf.d/bareos-dir.d/fileset/plugin-rados.conf.example @@ -12,4 +12,3 @@ FileSet { Plugin = "rados:conffile=:clientid=:poolname=:namespace=:snapshotname=:" } } - diff --git a/core/src/plugins/filed/rados-conf.d/bareos-dir.d/job/BackupRados.conf.example b/core/src/plugins/filed/rados/rados-conf.d/bareos-dir.d/job/BackupRados.conf.example similarity index 99% rename from core/src/plugins/filed/rados-conf.d/bareos-dir.d/job/BackupRados.conf.example rename to core/src/plugins/filed/rados/rados-conf.d/bareos-dir.d/job/BackupRados.conf.example index a9f0758557f..85884545176 100644 --- a/core/src/plugins/filed/rados-conf.d/bareos-dir.d/job/BackupRados.conf.example +++ b/core/src/plugins/filed/rados/rados-conf.d/bareos-dir.d/job/BackupRados.conf.example @@ -4,4 +4,3 @@ Job { FileSet = "plugin-rados" # Client = "radoshost-fd" } - diff --git a/core/src/plugins/filed/rados-conf.d/bareos-dir.d/job/RestoreRados.conf.example b/core/src/plugins/filed/rados/rados-conf.d/bareos-dir.d/job/RestoreRados.conf.example similarity index 100% rename from core/src/plugins/filed/rados-conf.d/bareos-dir.d/job/RestoreRados.conf.example rename to core/src/plugins/filed/rados/rados-conf.d/bareos-dir.d/job/RestoreRados.conf.example diff --git a/core/src/plugins/filed/rados-fd.cc b/core/src/plugins/filed/rados/rados-fd.cc similarity index 99% rename from core/src/plugins/filed/rados-fd.cc rename to core/src/plugins/filed/rados/rados-fd.cc index 53cf2594407..f7ae647c8d8 100644 --- a/core/src/plugins/filed/rados-fd.cc +++ b/core/src/plugins/filed/rados/rados-fd.cc @@ -2,7 +2,7 @@ BAREOS® - Backup Archiving REcovery Open Sourced Copyright (C) 2014-2016 Planets Communications B.V. - Copyright (C) 2014-2016 Bareos GmbH & Co. KG + Copyright (C) 2014-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -25,7 +25,7 @@ */ #include "include/bareos.h" #include "filed/fd_plugins.h" -#include "fd_common.h" +#include "plugins/filed/fd_common.h" #include "lib/berrno.h" #include diff --git a/core/src/plugins/filed/test-deltaseq-fd.cc b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc similarity index 99% rename from core/src/plugins/filed/test-deltaseq-fd.cc rename to core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc index 2e7c5c7ce7c..6c82398c563 100644 --- a/core/src/plugins/filed/test-deltaseq-fd.cc +++ b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc @@ -2,7 +2,7 @@ BAREOS® - Backup Archiving REcovery Open Sourced Copyright (C) 2007-2011 Free Software Foundation Europe e.V. - Copyright (C) 2016-2016 Bareos GmbH & Co. KG + Copyright (C) 2016-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -27,7 +27,7 @@ */ #include "include/bareos.h" #include "fd_plugins.h" -#include "fd_common.h" +#include "plugins/filed/fd_common.h" namespace filedaemon { diff --git a/core/src/plugins/filed/test-plugin-fd.cc b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc similarity index 99% rename from core/src/plugins/filed/test-plugin-fd.cc rename to core/src/plugins/filed/test-plugin/test-plugin-fd.cc index 09592afe9fa..ab5452cd2b7 100644 --- a/core/src/plugins/filed/test-plugin-fd.cc +++ b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc @@ -2,7 +2,7 @@ BAREOS® - Backup Archiving REcovery Open Sourced Copyright (C) 2007-2012 Free Software Foundation Europe e.V. - Copyright (C) 2016-2016 Bareos GmbH & Co. KG + Copyright (C) 2016-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -29,7 +29,7 @@ */ #include "include/bareos.h" #include "filed/fd_plugins.h" -#include "fd_common.h" +#include "plugins/filed/fd_common.h" #include "lib/ini.h" #include diff --git a/core/src/plugins/stored/CMakeLists.txt b/core/src/plugins/stored/CMakeLists.txt index 6f02b9080b7..d48f3eabfaa 100644 --- a/core/src/plugins/stored/CMakeLists.txt +++ b/core/src/plugins/stored/CMakeLists.txt @@ -30,17 +30,17 @@ if(HAVE_WIN32) add_definitions(-DMS_WIN${WINDOWS_BITS}) endif() -add_library(autoxflate-sd MODULE autoxflate-sd.cc) +add_library(autoxflate-sd MODULE autoxflate/autoxflate-sd.cc) set_target_properties(autoxflate-sd PROPERTIES PREFIX "") target_link_libraries(autoxflate-sd bareos) install(TARGETS autoxflate-sd DESTINATION ${plugindir}) if(NOT HAVE_WIN32 AND NOT HAVE_DARWIN_OS) - add_library(scsicrypto-sd MODULE scsicrypto-sd.cc) + add_library(scsicrypto-sd MODULE scsicrypto/scsicrypto-sd.cc) set_target_properties(scsicrypto-sd PROPERTIES PREFIX "") install(TARGETS scsicrypto-sd DESTINATION ${plugindir}) - add_library(scsitapealert-sd MODULE scsitapealert-sd.cc) + add_library(scsitapealert-sd MODULE scsitapealert/scsitapealert-sd.cc) set_target_properties(scsitapealert-sd PROPERTIES PREFIX "") install(TARGETS scsitapealert-sd DESTINATION ${plugindir}) if(HAVE_DARWIN_OS) @@ -49,7 +49,7 @@ if(NOT HAVE_WIN32 AND NOT HAVE_DARWIN_OS) endif() if(HAVE_PYTHON) - add_library(python-sd MODULE python-sd.cc) + add_library(python-sd MODULE python/python-sd.cc) set_target_properties(python-sd PROPERTIES PREFIX "") install(TARGETS python-sd DESTINATION ${plugindir}) target_link_libraries(python-sd ${PYTHON_LIBRARIES} bareos) @@ -62,18 +62,17 @@ if(HAVE_PYTHON) install(FILES ${PYFILES} DESTINATION ${plugindir}) endif() - if(HAVE_PYTHON) - configure_file(setup.py.in setup.py) + configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) add_custom_target(bareossd-pymodule ALL COMMENT "building python module pythonmodules/bareossd.so" - COMMAND ${PYTHON_EXECUTABLE} setup.py build - COMMAND ${PYTHON_EXECUTABLE} setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + COMMAND ${PYTHON_EXECUTABLE} python/setup.py build + COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules DEPENDS python-sd ) add_test(NAME bareossd-python-module - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/bareossd_test.py + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareossd_test.py ) - set_property(TEST bareossd-python-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/test" LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib) + set_property(TEST bareossd-python-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib) endif() diff --git a/core/src/plugins/stored/autoxflate-sd.cc b/core/src/plugins/stored/autoxflate/autoxflate-sd.cc similarity index 100% rename from core/src/plugins/stored/autoxflate-sd.cc rename to core/src/plugins/stored/autoxflate/autoxflate-sd.cc diff --git a/core/src/plugins/stored/example-plugin-sd.cc b/core/src/plugins/stored/example/example-plugin-sd.cc similarity index 100% rename from core/src/plugins/stored/example-plugin-sd.cc rename to core/src/plugins/stored/example/example-plugin-sd.cc diff --git a/core/src/plugins/stored/BareosSdPluginBaseclass.py b/core/src/plugins/stored/python/pyfiles/BareosSdPluginBaseclass.py similarity index 100% rename from core/src/plugins/stored/BareosSdPluginBaseclass.py rename to core/src/plugins/stored/python/pyfiles/BareosSdPluginBaseclass.py diff --git a/core/src/plugins/stored/BareosSdWrapper.py b/core/src/plugins/stored/python/pyfiles/BareosSdWrapper.py similarity index 100% rename from core/src/plugins/stored/BareosSdWrapper.py rename to core/src/plugins/stored/python/pyfiles/BareosSdWrapper.py diff --git a/core/src/plugins/stored/bareos-sd-class-plugin.py b/core/src/plugins/stored/python/pyfiles/bareos-sd-class-plugin.py similarity index 100% rename from core/src/plugins/stored/bareos-sd-class-plugin.py rename to core/src/plugins/stored/python/pyfiles/bareos-sd-class-plugin.py diff --git a/core/src/plugins/stored/bareos-sd.py.template b/core/src/plugins/stored/python/pyfiles/bareos-sd.py.template similarity index 100% rename from core/src/plugins/stored/bareos-sd.py.template rename to core/src/plugins/stored/python/pyfiles/bareos-sd.py.template diff --git a/core/src/plugins/stored/bareos_sd_consts.py b/core/src/plugins/stored/python/pyfiles/bareos_sd_consts.py similarity index 100% rename from core/src/plugins/stored/bareos_sd_consts.py rename to core/src/plugins/stored/python/pyfiles/bareos_sd_consts.py diff --git a/core/src/plugins/stored/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc similarity index 99% rename from core/src/plugins/stored/python-sd.cc rename to core/src/plugins/stored/python/python-sd.cc index a1cc27123de..61266c3e05c 100644 --- a/core/src/plugins/stored/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -127,7 +127,7 @@ struct plugin_private_context { static PyThreadState* mainThreadState; /* functions common to all plugins */ -#include "../python_plugins_common.inc" +#include "plugins/python_plugins_common.inc" #ifdef __cplusplus extern "C" { diff --git a/core/src/plugins/stored/python-sd.h b/core/src/plugins/stored/python/python-sd.h similarity index 98% rename from core/src/plugins/stored/python-sd.h rename to core/src/plugins/stored/python/python-sd.h index b58eebc9594..7e85a12686e 100644 --- a/core/src/plugins/stored/python-sd.h +++ b/core/src/plugins/stored/python/python-sd.h @@ -31,7 +31,7 @@ #define PYTHON_MODULE_NAME_QUOTED "bareossd" /* common code for all python plugins */ -#include "../python_plugins_common.h" +#include "plugins/python_plugins_common.h" #include "plugins/filed/fd_common.h" namespace storagedaemon { diff --git a/core/src/plugins/stored/setup.py.in b/core/src/plugins/stored/python/setup.py.in similarity index 96% rename from core/src/plugins/stored/setup.py.in rename to core/src/plugins/stored/python/setup.py.in index fe92766278d..5adda30f721 100644 --- a/core/src/plugins/stored/setup.py.in +++ b/core/src/plugins/stored/python/setup.py.in @@ -1,7 +1,7 @@ from distutils.core import setup, Extension module1 = Extension('bareossd', - sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python-sd.cc'], + sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/python-sd.cc'], include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..'], libraries = ['bareos'], library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'] diff --git a/core/src/plugins/stored/test/bareossd_test.py b/core/src/plugins/stored/python/test/bareossd_test.py similarity index 100% rename from core/src/plugins/stored/test/bareossd_test.py rename to core/src/plugins/stored/python/test/bareossd_test.py diff --git a/core/src/plugins/stored/scsicrypto-sd.cc b/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc similarity index 100% rename from core/src/plugins/stored/scsicrypto-sd.cc rename to core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc diff --git a/core/src/plugins/stored/scsitapealert-sd.cc b/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc similarity index 100% rename from core/src/plugins/stored/scsitapealert-sd.cc rename to core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 8311a60ff87..367a8bea0f5 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -127,129 +127,6 @@ macro(CheckForEnabledAndDisabledListEntry TEST_NAME_TO_CHECK) endif() endmacro() -macro(handle_python_plugin_modules test_name) - set(PYMODULES_TO_LINK_TO_SRC) - - string(REGEX MATCH ^dbcopy.* starts_with_dbcopy ${test_name}) - string(REGEX MATCH ^pyplug-fd.* starts_with_pyplug-fd ${test_name}) - if(starts_with_pyplug-fd OR starts_with_dbcopy) - list(APPEND PYMODULES_TO_LINK_TO_SRC filed/BareosFdWrapper.py - filed/BareosFdPluginBaseclass.py filed/bareos_fd_consts.py - filed/bareos-fd-mock-test.py - ) - endif() - - string(REGEX MATCH ^pyplug-sd.* starts_with_pyplug-sd ${test_name}) - if(starts_with_pyplug-sd) - list(APPEND SD_PYMODULES_TO_LINK_TO_SRC bareos_sd_consts.py - bareos-sd-class-plugin.py BareosSdPluginBaseclass.py - BareosSdWrapper.py - ) - endif() - - string(REGEX MATCH ^pyplug-dir.* starts_with_pyplug-dir ${test_name}) - if(starts_with_pyplug-dir) - list(APPEND DIR_PYMODULES_TO_LINK_TO_SRC bareos_dir_consts.py - BareosDirPluginBaseclass.py bareos-dir-class-plugin.py - BareosDirWrapper.py - ) - endif() - - if(${test_name} STREQUAL pyplug-dir) - list(APPEND DIR_PYMODULES_TO_LINK_TO_SRC) - endif() - - if(${test_name} STREQUAL pyplug-fd-percona-xtrabackup) - list(APPEND FD_PYMODULES_TO_LINK_TO_SRC BareosFdPluginPerconaXtraBackup.py - bareos-fd-percona-xtrabackup.py - ) - endif() - - if(${test_name} STREQUAL pyplug-fd-ovirt) - list(APPEND FD_PYMODULES_TO_LINK_TO_SRC BareosFdPluginOvirt.py - bareos-fd-ovirt.py - ) - endif() - - if(${test_name} STREQUAL pyplug-fd-local-fileset) - list(APPEND FD_PYMODULES_TO_LINK_TO_SRC bareos-fd-local-fileset.py - BareosFdPluginLocalFileset.py - ) - endif() - - if(${test_name} STREQUAL pyplug-fd-local-fileset-restoreobject) - list(APPEND FD_PYMODULES_TO_LINK_TO_SRC bareos-fd-local-fileset.py - BareosFdPluginLocalFileset.py - ) - endif() - - if(${test_name} STREQUAL pyplug-fd-postgres) - list(APPEND FD_PYMODULES_TO_LINK_TO_SRC bareos-fd-postgres.py - BareosFdPluginLocalFileset.py BareosFdPluginPostgres.py - BareosFdPluginBaseclass.py - ) - - endif() - if(${test_name} STREQUAL pyplug-fd-vmware) - list(APPEND FD_PYMODULES_TO_LINK_TO_SRC bareos-fd-vmware.py - BareosFdPluginVMware.py - ) - endif() - - # still missing: filed/BareosFdPluginLDAP.py filed/bareos-fd-ldap.py - - if(NOT EXISTS ${python_plugin_module_src_test_dir}) - file(MAKE_DIRECTORY ${python_plugin_module_src_test_dir}) - endif() - - foreach(PYMODULE_SOURCEPATH ${PYMODULES_TO_LINK_TO_SRC}) - get_filename_component(PYMODULE_NAME ${PYMODULE_SOURCEPATH} NAME) - execute_process( - COMMAND - ${CMAKE_COMMAND} -E create_symlink - ${PROJECT_SOURCE_DIR}/../core/src/plugins/${PYMODULE_SOURCEPATH} - ${python_plugin_module_src_test_dir}/${PYMODULE_NAME} - ) - endforeach() - - foreach(PYMODULE ${DIR_PYMODULES_TO_LINK_TO_SRC}) - get_filename_component(PYMODULE_NAME ${PYMODULE} NAME) - if(RUN_SYSTEMTESTS_ON_INSTALLED_FILES) - set(ORIGINAL_FILE ${python_plugin_module_src_dir}/${PYMODULE}) - else() - set(ORIGINAL_FILE ${python_plugin_module_src_dir}/dird/${PYMODULE}) - endif() - create_symlink( - ${ORIGINAL_FILE} ${python_plugin_module_src_test_dir}/${PYMODULE_NAME} - ) - endforeach() - - foreach(PYMODULE ${FD_PYMODULES_TO_LINK_TO_SRC}) - get_filename_component(PYMODULE_NAME ${PYMODULE} NAME) - if(RUN_SYSTEMTESTS_ON_INSTALLED_FILES) - set(ORIGINAL_FILE ${python_plugin_module_src_dir}/${PYMODULE}) - else() - set(ORIGINAL_FILE ${python_plugin_module_src_dir}/filed/${PYMODULE}) - endif() - create_symlink( - ${ORIGINAL_FILE} ${python_plugin_module_src_test_dir}/${PYMODULE_NAME} - ) - endforeach() - - foreach(PYMODULE ${SD_PYMODULES_TO_LINK_TO_SRC}) - get_filename_component(PYMODULE_NAME ${PYMODULE} NAME) - if(RUN_SYSTEMTESTS_ON_INSTALLED_FILES) - set(ORIGINAL_FILE ${python_plugin_module_src_dir}/${PYMODULE}) - else() - set(ORIGINAL_FILE ${python_plugin_module_src_dir}/stored/${PYMODULE}) - endif() - create_symlink( - ${ORIGINAL_FILE} ${python_plugin_module_src_test_dir}/${PYMODULE_NAME} - ) - endforeach() - -endmacro() - # set the data encryption and signature keys set(pki_keypair ${CMAKE_CURRENT_SOURCE_DIR}/pki/fd.pem) set(pki_master_key ${CMAKE_CURRENT_SOURCE_DIR}/pki/master.cert) @@ -700,7 +577,7 @@ else() list(APPEND SYSTEM_TESTS_DISABLED droplet-s3) endif() -if(glusterfs_uri) +if(SD_GFAPI_DIR_TO_TEST AND glusterfs_uri) list(APPEND SYSTEM_TESTS glusterfs-backend) else() list(APPEND SYSTEM_TESTS_DISABLED glusterfs-backend) @@ -719,6 +596,7 @@ endif() if(EXISTS /run/.containerenv) message(STATUS "detected container environment, disabling python-bareos") set(in_container TRUE) + list(APPEND SYSTEM_TESTS "dbcopy-mysql-postgresql-test") else() set(in_container FALSE) endif() @@ -914,7 +792,6 @@ foreach(TEST_NAME ${SYSTEM_TESTS}) prepare_test() configurefilestosystemtest("systemtests" "tests/${TEST_NAME}" "*" @ONLY "") - handle_python_plugin_modules(${TEST_NAME}) configure_file("environment.in" "tests/${TEST_NAME}/environment" @ONLY) diff --git a/systemtests/environment.in b/systemtests/environment.in index ffb68b5318b..b65ec6cd005 100644 --- a/systemtests/environment.in +++ b/systemtests/environment.in @@ -114,6 +114,7 @@ if [ -d /usr/lib/postgresql ]; then else export PATH=/sbin:/usr/sbin:$PATH fi +export PYTHONPATH=@pythonpath@ # enable deprecated database handling in scripts export BAREOS_TEST_RUNNING=yes From 9925c648021c2c4d902288c0f2c7a3cff82df915 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 3 Mar 2020 15:31:04 +0100 Subject: [PATCH 026/341] systemtests: set PYTHONPATH correctly --- systemtests/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 367a8bea0f5..370fc7c212e 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -792,6 +792,9 @@ foreach(TEST_NAME ${SYSTEM_TESTS}) prepare_test() configurefilestosystemtest("systemtests" "tests/${TEST_NAME}" "*" @ONLY "") + set(pythonpath + "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/pyfiles:${CMAKE_SOURCE_DIR}/core/src/plugins/stored/python/pyfiles:${CMAKE_SOURCE_DIR}/core/src/plugins/dird/python/pyfiles:${CMAKE_CURRENT_SOURCE_DIR}/tests/${TEST_NAME}/python-modules") + configure_file("environment.in" "tests/${TEST_NAME}/environment" @ONLY) From 62b8f09b25ef5a75a75df4731ad4d1367111d7d4 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 3 Mar 2020 17:04:55 +0100 Subject: [PATCH 027/341] python plugins: RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET Also enhanced the python module tests --- core/src/plugins/.gitignore | 1 + core/src/plugins/dird/CMakeLists.txt | 2 +- core/src/plugins/dird/python/python-dir.cc | 15 +++-- .../dird/python/test/bareosdir_test.py | 18 ++++-- core/src/plugins/filed/CMakeLists.txt | 11 +++- core/src/plugins/filed/python/python-fd.cc | 59 +++++++++++-------- ...e_main_test.py => bareosfd-module-test.py} | 0 .../filed/python/test/bareosfd_test.py | 4 +- .../python-fd-module-tester.cc} | 6 +- core/src/plugins/python_plugins_common.h | 10 ++++ core/src/plugins/stored/python/python-sd.cc | 23 ++++++-- .../stored/python/test/bareossd_test.py | 24 ++++---- 12 files changed, 116 insertions(+), 57 deletions(-) create mode 100644 core/src/plugins/.gitignore rename core/src/plugins/filed/python/test/{bareosfd_module_main_test.py => bareosfd-module-test.py} (100%) rename core/src/plugins/filed/python/{bareosfd_module_main.cc => test/python-fd-module-tester.cc} (94%) diff --git a/core/src/plugins/.gitignore b/core/src/plugins/.gitignore new file mode 100644 index 00000000000..73709ba6866 --- /dev/null +++ b/core/src/plugins/.gitignore @@ -0,0 +1 @@ +Testing diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index 496b3ff5822..3e37d6d3a91 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -56,7 +56,7 @@ if(HAVE_PYTHON) ) add_test(NAME bareosdir-python-module - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/bareosdir_test.py + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosdir_test.py ) set_property(TEST bareosdir-python-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/python/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib) endif() diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index 868c6f3aec7..f46e517407d 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -669,6 +669,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() switch (var) { case bDirVarJobId: @@ -760,6 +761,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "iO:BareosSetValue", &var, &pyValue)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() switch (var) { case bwDirVarVolumeName: { @@ -806,11 +808,12 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (dbgmsg) { bareos_plugin_ctx = GetPluginContextFromPythonModule(); @@ -830,11 +833,12 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (jobmsg) { bareos_plugin_ctx = GetPluginContextFromPythonModule(); @@ -853,13 +857,14 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; if (!PyArg_ParseTuple(args, "O:BareosRegisterEvents", &pyEvents)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); if (!pySeq) { goto bail_out; } @@ -894,13 +899,14 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; if (!PyArg_ParseTuple(args, "O:BareosUnRegisterEvents", &pyEvents)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); if (!pySeq) { goto bail_out; } @@ -939,6 +945,7 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getInstanceCount(bareos_plugin_ctx, &value) == bRC_OK) { diff --git a/core/src/plugins/dird/python/test/bareosdir_test.py b/core/src/plugins/dird/python/test/bareosdir_test.py index c9cfb1c5591..e28951bbf60 100644 --- a/core/src/plugins/dird/python/test/bareosdir_test.py +++ b/core/src/plugins/dird/python/test/bareosdir_test.py @@ -6,25 +6,31 @@ class TestBareosFd(unittest.TestCase): def test_GetValue(self): - bareosdir.GetValue() + self.assertRaises(RuntimeError, bareosdir.GetValue, 1) + self.assertRaises(RuntimeError, bareosdir.GetValue, 1) def test_SetValue(self): bareosdir.SetValue() + # self.assertRaises(RuntimeError, bareosdir.SetValue) + # self.assertRaises(RuntimeError, bareosdir.SetValue, 2) def test_DebugMessage(self): - bareosdir.DebugMessage() + self.assertRaises(TypeError, bareosdir.DebugMessage, "This is a debug message") + self.assertRaises(RuntimeError, bareosdir.DebugMessage,100, "This is a debug message") def test_JobMessage(self): - bareosdir.JobMessage() + self.assertRaises(TypeError, bareosdir.JobMessage, "This is a Job message") + self.assertRaises(RuntimeError, bareosdir.JobMessage,100, "This is a Job message") def test_RegisterEvents(self): - bareosdir.RegisterEvents() + # self.assertRaises(TypeError, bareosdir.RegisterEvents) + self.assertRaises(RuntimeError, bareosdir.RegisterEvents, 1) def test_UnRegisterEvents(self): - bareosdir.UnRegisterEvents() + self.assertRaises(RuntimeError, bareosdir.UnRegisterEvents, 1) def test_GetInstanceCount(self): - bareosdir.GetInstanceCount() + self.assertRaises(RuntimeError, bareosdir.GetInstanceCount) if __name__ == "__main__": diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index b0b0bae4818..e44f0411839 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -108,8 +108,15 @@ if(HAVE_PYTHON) endif() if(HAVE_PYTHON) - add_executable(bareosfd_module_main python/bareosfd_module_main.cc) - target_link_libraries(bareosfd_module_main ${PYTHON_LIBRARIES} bareos) + add_executable(bareos-fd-module-tester python/test/python-fd-module-tester.cc) + target_link_libraries(bareos-fd-module-tester ${PYTHON_LIBRARIES} bareos) + + add_test(NAME bareosfd-python-module-tester + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bareos-fd-module-tester + ) + set_property(TEST bareosfd-python-module-tester + PROPERTY ENVIRONMENT PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/python/test/:${CMAKE_CURRENT_BINARY_DIR}/pythonmodules) + endif() if(HAVE_PYTHON) diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index bcf5bc56c0f..cfc35a157ea 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -2242,6 +2242,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() switch (var) { case bVarFDName: @@ -2318,6 +2319,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "iO:BareosSetValue", &var, &pyValue)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() ctx = PyGetbpContext(pyCtx); switch (var) { @@ -2362,18 +2364,14 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (dbgmsg) { - bareos_plugin_ctx = GetPluginContextFromPythonModule(); - if (bareos_plugin_ctx && bfuncs) { - Dmsg(bareos_plugin_ctx, level, "python-fd: %s", dbgmsg); - } - } + if (dbgmsg) { Dmsg(bareos_plugin_ctx, level, "python-fd: %s", dbgmsg); } Py_INCREF(Py_None); return Py_None; } @@ -2387,12 +2385,12 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - bpContext* bareos_plugin_ctx; - + bpContext* bareos_plugin_ctx = NULL; if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (jobmsg) { bareos_plugin_ctx = GetPluginContextFromPythonModule(); @@ -2411,13 +2409,14 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; if (!PyArg_ParseTuple(args, "O:BareosRegisterEvents", &pyEvents)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); if (!pySeq) { goto bail_out; } @@ -2452,13 +2451,14 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; if (!PyArg_ParseTuple(args, "O:BareosUnRegisterEvents", &pyEvents)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); if (!pySeq) { goto bail_out; } @@ -2496,6 +2496,7 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getInstanceCount(bareos_plugin_ctx, &value) == bRC_OK) { @@ -2517,10 +2518,11 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) { char* file = NULL; - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; bRC retval = bRC_Error; + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (!PyArg_ParseTuple(args, "|z:BareosAddExclude", &file)) { goto bail_out; } if (file) { @@ -2539,10 +2541,11 @@ static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) { char* file = NULL; - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; bRC retval = bRC_Error; + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (!PyArg_ParseTuple(args, "|z:BareosAddInclude", &file)) { goto bail_out; } if (file) { @@ -2561,10 +2564,11 @@ static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) { char* opts = NULL; - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; bRC retval = bRC_Error; + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (!PyArg_ParseTuple(args, "|z:BareosAddOptions", &opts)) { goto bail_out; } if (opts) { @@ -2584,10 +2588,11 @@ static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) { int type; char* item = NULL; - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; bRC retval = bRC_Error; + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (!PyArg_ParseTuple(args, "|zi:BareosAddRegex", &item, &type)) { goto bail_out; } @@ -2609,13 +2614,14 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) { int type; char* item = NULL; - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, "|zi:BareosAddWild", &item, &type)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (item) { bareos_plugin_ctx = GetPluginContextFromPythonModule(); @@ -2632,11 +2638,12 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewOptions")) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() bareos_plugin_ctx = GetPluginContextFromPythonModule(); retval = bfuncs->NewOptions(bareos_plugin_ctx); @@ -2651,11 +2658,12 @@ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewInclude")) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() bareos_plugin_ctx = GetPluginContextFromPythonModule(); retval = bfuncs->NewInclude(bareos_plugin_ctx); @@ -2670,11 +2678,12 @@ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewPreInclude")) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() bareos_plugin_ctx = GetPluginContextFromPythonModule(); retval = bfuncs->NewPreInclude(bareos_plugin_ctx); @@ -2690,7 +2699,7 @@ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) */ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; struct save_pkt sp; bRC retval = bRC_Error; @@ -2699,6 +2708,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "O:BareosCheckChanges", &pSavePkt)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() bareos_plugin_ctx = GetPluginContextFromPythonModule(); @@ -2744,7 +2754,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) */ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; struct save_pkt sp; bRC retval = bRC_Error; PySavePacket* pSavePkt; @@ -2752,6 +2762,7 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "O:BareosAcceptFile", &pSavePkt)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() bareos_plugin_ctx = GetPluginContextFromPythonModule(); @@ -2788,7 +2799,7 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) { bool all; - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; @@ -2796,6 +2807,7 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "O|s:BareosSetSeenBitmap", &pyBool, &fname)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() bareos_plugin_ctx = GetPluginContextFromPythonModule(); all = PyObject_IsTrue(pyBool); @@ -2813,7 +2825,7 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) { bool all; - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; @@ -2821,6 +2833,7 @@ static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "O|s:BareosClearSeenBitmap", &pyBool, &fname)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() bareos_plugin_ctx = GetPluginContextFromPythonModule(); all = PyObject_IsTrue(pyBool); diff --git a/core/src/plugins/filed/python/test/bareosfd_module_main_test.py b/core/src/plugins/filed/python/test/bareosfd-module-test.py similarity index 100% rename from core/src/plugins/filed/python/test/bareosfd_module_main_test.py rename to core/src/plugins/filed/python/test/bareosfd-module-test.py diff --git a/core/src/plugins/filed/python/test/bareosfd_test.py b/core/src/plugins/filed/python/test/bareosfd_test.py index 37fe3b04c2f..5d4a2a49a55 100644 --- a/core/src/plugins/filed/python/test/bareosfd_test.py +++ b/core/src/plugins/filed/python/test/bareosfd_test.py @@ -6,10 +6,10 @@ class TestBareosFd(unittest.TestCase): def test_SetValue(self): - bareosfd.SetValue(1, 123) + self.assertRaises(RuntimeError, bareosfd.SetValue, 2) def test_DebugMessage(self): - bareosfd.DebugMessage(100,"testdebugmessage\n") + self.assertRaises(RuntimeError, bareosfd.DebugMessage, "This is a debug message") def test_RestoreObject(self): test_RestoreObject = bareosfd.RestoreObject() diff --git a/core/src/plugins/filed/python/bareosfd_module_main.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc similarity index 94% rename from core/src/plugins/filed/python/bareosfd_module_main.cc rename to core/src/plugins/filed/python/test/python-fd-module-tester.cc index 4ea0ca846fd..870f1bbffe8 100644 --- a/core/src/plugins/filed/python/bareosfd_module_main.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -52,10 +52,6 @@ int main(int argc, char* argv[]) static filedaemon::bFuncs bfuncs; Py_SetProgramName(argv[0]); Py_Initialize(); - PyRun_SimpleString( - "from time import time,ctime\n" - "print 'Today is',ctime(time())\n"); - PyObject* bareosfdModule = PyImport_ImportModule("bareosfd"); if (bareosfdModule) { @@ -78,7 +74,7 @@ int main(int argc, char* argv[]) printf("ctx_from_bareosfd_module contains %p\n", ctx_from_bareosfd_module); } - PyObject* pModule = PyImport_ImportModule("bareosfd_module_main_test"); + PyObject* pModule = PyImport_ImportModule("bareosfd-module-test"); if (PyErr_Occurred()) { PyErrorHandler(); } diff --git a/core/src/plugins/python_plugins_common.h b/core/src/plugins/python_plugins_common.h index 0623985aab8..3795da6d3e9 100644 --- a/core/src/plugins/python_plugins_common.h +++ b/core/src/plugins/python_plugins_common.h @@ -43,4 +43,14 @@ #define MOD_DEF(ob, name, doc, methods) ob = Py_InitModule3(name, methods, doc); #endif +/* check if bareos_plugin_ctx and bfunc are set. + * Otherwise return NULL and throw RuntimeError */ +#define RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() \ + if (!bareos_plugin_ctx) { \ + PyErr_SetString(PyExc_RuntimeError, "bareos_plugin_ctx is unset"); \ + return NULL; \ + } \ + if (!bfuncs) { PyErr_SetString(PyExc_RuntimeError, "bfuncs is unset"); } \ + return NULL; + #endif // BAREOS_PYTHON_PLUGINS_COMMON_H_ diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index 61266c3e05c..ae58bd93788 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -668,6 +668,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() switch (var) { case bsdVarJobId: @@ -760,6 +761,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "iO:BareosSetValue", &var, &pyValue)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() switch (var) { case bsdwVarVolumeName: { @@ -805,11 +807,12 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (dbgmsg) { bareos_plugin_ctx = GetPluginContextFromPythonModule(); @@ -829,11 +832,12 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (jobmsg) { bareos_plugin_ctx = GetPluginContextFromPythonModule(); @@ -852,13 +856,14 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; if (!PyArg_ParseTuple(args, "O:BareosRegisterEvents", &pyEvents)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); if (!pySeq) { goto bail_out; } @@ -893,13 +898,14 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx; + bpContext* bareos_plugin_ctx = NULL; bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; if (!PyArg_ParseTuple(args, "O:BareosUnRegisterEvents", &pyEvents)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); if (!pySeq) { goto bail_out; } @@ -938,8 +944,17 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() bareos_plugin_ctx = GetPluginContextFromPythonModule(); + if (!bareos_plugin_ctx) { + PyErr_SetString(PyExc_ValueError, "bareos_plugin_ctx is unset"); + return NULL; + } + if (!bfuncs) { + PyErr_SetString(PyExc_ValueError, "bfuncs is unset"); + return NULL; + } if (bfuncs->getInstanceCount(bareos_plugin_ctx, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } diff --git a/core/src/plugins/stored/python/test/bareossd_test.py b/core/src/plugins/stored/python/test/bareossd_test.py index 38291140133..63d811d588f 100644 --- a/core/src/plugins/stored/python/test/bareossd_test.py +++ b/core/src/plugins/stored/python/test/bareossd_test.py @@ -6,25 +6,29 @@ class TestBareosFd(unittest.TestCase): def test_GetValue(self): - bareossd.GetValue() + self.assertRaises(TypeError, bareossd.GetValue) + self.assertRaises(RuntimeError, bareossd.GetValue, 1) - def test_SetValue(self): - bareossd.SetValue() + # def test_SetValue(self): + # self.assertRaises(TypeError, bareossd.SetValue) + # self.assertRaises(RuntimeError, bareossd.SetValue, 2) def test_DebugMessage(self): - bareossd.DebugMessage() + self.assertRaises(TypeError, bareossd.DebugMessage, "This is a Debug message") + self.assertRaises(RuntimeError, bareossd.DebugMessage, 100, "This is a Debug message") def test_JobMessage(self): - bareossd.JobMessage() + self.assertRaises(TypeError, bareossd.JobMessage, "This is a Job message") + self.assertRaises(RuntimeError, bareossd.JobMessage, 100, "This is a Job message") - def test_RegisterEvents(self): - bareossd.RegisterEvents() + # def test_RegisterEvents(self): + # self.assertRaises(RuntimeError, bareossd.RegisterEvents) - def test_UnRegisterEvents(self): - bareossd.UnRegisterEvents() + # def test_UnRegisterEvents(self): + # self.assertRaises(RuntimeError, bareossd.UnRegisterEvents) def test_GetInstanceCount(self): - bareossd.GetInstanceCount() + self.assertRaises(RuntimeError, bareossd.GetInstanceCount) if __name__ == "__main__": From 5c67c5c978349dca33220851042bff88c7ea8a94 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 4 Mar 2020 11:51:39 +0100 Subject: [PATCH 028/341] python module tests: set LD_LIBRARY_PATH and PYTHONPATH --- core/src/plugins/dird/CMakeLists.txt | 8 +- core/src/plugins/filed/CMakeLists.txt | 4 +- core/src/plugins/filed/python/python-fd.cc | 16 +- core/src/plugins/filed/python/python-fd.h | 64 ++++-- .../python/test/python-fd-module-tester.cc | 190 ++++++++++++++++-- core/src/plugins/python_plugins_common.h | 16 +- core/src/plugins/stored/CMakeLists.txt | 4 +- 7 files changed, 257 insertions(+), 45 deletions(-) diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index 3e37d6d3a91..23664218e05 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -48,15 +48,17 @@ endif() if(HAVE_PYTHON) configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) - add_custom_target(bareosdir-pymodule ALL + add_custom_command( TARGET python-dir + POST_BUILD COMMENT "building python module pythonmodules/bareosdir.so" COMMAND ${PYTHON_EXECUTABLE} python/setup.py build - COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/python/pythonmodules + COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build DEPENDS python-dir ) add_test(NAME bareosdir-python-module COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosdir_test.py ) - set_property(TEST bareosdir-python-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/python/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib) + set_property(TEST bareosdir-python-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib) endif() diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index e44f0411839..c7b435e1986 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -121,10 +121,12 @@ endif() if(HAVE_PYTHON) configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) - add_custom_target(bareosfd-pymodule ALL + add_custom_command( TARGET python-fd + POST_BUILD COMMENT "building python module pythonmodules/bareosfd.so" COMMAND ${PYTHON_EXECUTABLE} python/setup.py build COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build DEPENDS python-fd ) diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index cfc35a157ea..505225f0452 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -186,17 +186,17 @@ bRC loadPlugin(bInfo* lbinfo, *pinfo = &pluginInfo; /* Return pointer to our info */ *pfuncs = &pluginFuncs; /* Return pointer to our functions */ - /* Setup Python */ + if (!Py_IsInitialized()) { + /* Setup Python */ #if PY_MAJOR_VERSION >= 3 - PyImport_AppendInittab("bareosfd", &PyInit_bareosfd); + PyImport_AppendInittab("bareosfd", &PyInit_bareosfd); #else - PyImport_AppendInittab("bareosfd", initbareosfd); + PyImport_AppendInittab("bareosfd", initbareosfd); #endif - - Py_InitializeEx(0); - PyEval_InitThreads(); - mainThreadState = PyEval_SaveThread(); - + Py_InitializeEx(0); + PyEval_InitThreads(); + mainThreadState = PyEval_SaveThread(); + } return bRC_OK; } diff --git a/core/src/plugins/filed/python/python-fd.h b/core/src/plugins/filed/python/python-fd.h index b48d2519b19..5b229050c40 100644 --- a/core/src/plugins/filed/python/python-fd.h +++ b/core/src/plugins/filed/python/python-fd.h @@ -752,34 +752,72 @@ static PyMethodDef Methods[] = { } /* namespace filedaemon */ using namespace filedaemon; +/* variables storing bareos pointers */ static void* bareos_plugin_context = NULL; +static void* bfuncs = NULL; + +#ifdef __cplusplus +extern "C" { +#endif +/* Forward declaration of loadPlugin() as it is stored in Capsule */ +bRC loadPlugin(bInfo* lbinfo, + bFuncs* lbfuncs, + genpInfo** pinfo, + pFuncs** pfuncs); +#ifdef __cplusplus +} +#endif MOD_INIT(bareosfd) { - /* bareos_plugin_context holds the bpContext instead of passing to Python and - * extracting it back like it was before. bareos_plugin_context needs to be - * set after loading the PYTHON_MODULE_NAME binary python module and will be - * used for all calls. - */ - PyObject* m = NULL; + MOD_DEF(m, PYTHON_MODULE_NAME_QUOTED, NULL, Methods) - /* Pointer Capsules to avoid context transfer back and forth */ + + /* add bpContext Capsule */ PyObject* PyModulePluginContext = PyCapsule_New((void*)&bareos_plugin_context, PYTHON_MODULE_NAME_QUOTED ".bpContext", NULL); - if (!PyModulePluginContext) { - printf(PYTHON_MODULE_NAME_QUOTED ": PyCapsule_New failed\n"); + printf(PYTHON_MODULE_NAME_QUOTED ":bpContext PyCapsule_New failed\n"); return MOD_ERROR_VAL; } - - MOD_DEF(m, PYTHON_MODULE_NAME_QUOTED, NULL, Methods) - if (PyModulePluginContext) { PyModule_AddObject(m, "bpContext", PyModulePluginContext); + printf(PYTHON_MODULE_NAME_QUOTED ": added bpContext@%p\n", + &bareos_plugin_context); + } else { + printf(PYTHON_MODULE_NAME_QUOTED ":bpContext PyModule_AddObject failed\n"); + return MOD_ERROR_VAL; + } + + /* add bpFuncs Capsule */ + PyObject* PyModulePluginFuncs = + PyCapsule_New((void*)&bfuncs, PYTHON_MODULE_NAME_QUOTED ".bFuncs", NULL); + if (!PyModulePluginFuncs) { + printf(PYTHON_MODULE_NAME_QUOTED ":bFuncs PyCapsule_New failed\n"); + return MOD_ERROR_VAL; + } + if (PyModulePluginFuncs) { + PyModule_AddObject(m, "bFuncs", PyModulePluginFuncs); + printf(PYTHON_MODULE_NAME_QUOTED ": added bFuncs@%p\n", &bfuncs); + } else { + printf(PYTHON_MODULE_NAME_QUOTED ":bFuncs PyModule_AddObject failed\n"); + return MOD_ERROR_VAL; + } + + /* add loadPlugin Capsule */ + PyObject* PyModuleLoadPlugin = PyCapsule_New( + (void*)&loadPlugin, PYTHON_MODULE_NAME_QUOTED ".loadPlugin", NULL); + if (!PyModuleLoadPlugin) { + printf(PYTHON_MODULE_NAME_QUOTED "loadPlugin PyCapsule_New failed\n"); + return MOD_ERROR_VAL; + } + if (PyModuleLoadPlugin) { + PyModule_AddObject(m, "loadPlugin", PyModuleLoadPlugin); + printf(PYTHON_MODULE_NAME_QUOTED ": added loadPlugin@%p\n", &loadPlugin); } else { - printf(PYTHON_MODULE_NAME_QUOTED ":PyModule_AddObject failed\n"); + printf(PYTHON_MODULE_NAME_QUOTED "loadPlugin PyModule_AddObject failed\n"); return MOD_ERROR_VAL; } diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index 870f1bbffe8..a43a47873a6 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -1,3 +1,26 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2020-2020 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation, which is + listed in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +/* Load the python-fd plugin and test it */ + #include "Python.h" class PoolMem; #define NbytesForBits(n) ((((n)-1) >> 3) + 1) @@ -45,35 +68,178 @@ static void PyErrorHandler() exit(1); } -using namespace filedaemon; +// using namespace filedaemon; +bRC bareosRegisterEvents(bpContext* ctx, int nr_events, ...) { return bRC_OK; }; +bRC bareosUnRegisterEvents(bpContext* ctx, int nr_events, ...) +{ + return bRC_OK; +}; +bRC bareosGetInstanceCount(bpContext* ctx, int* ret) { return bRC_OK; }; +bRC bareosGetValue(bpContext* ctx, filedaemon::bVariable var, void* value) +{ + return bRC_OK; +}; +bRC bareosSetValue(bpContext* ctx, filedaemon::bVariable var, void* value) +{ + return bRC_OK; +}; +bRC bareosJobMsg(bpContext* ctx, + const char* file, + int line, + int type, + utime_t mtime, + const char* fmt, + ...) +{ + return bRC_OK; +}; +bRC bareosDebugMsg(bpContext* ctx, + const char* file, + int line, + int level, + const char* fmt, + ...) +{ + printf("bareosDebugMsg file:%s line:%d level: %d fmt:%s\n", file, line, level, + fmt); + return bRC_OK; +}; +void* bareosMalloc(bpContext* ctx, const char* file, int line, size_t size) +{ + return NULL; +}; +void bareosFree(bpContext* ctx, const char* file, int line, void* mem) +{ + return; +}; +bRC bareosAddExclude(bpContext* ctx, const char* file) { return bRC_OK; }; +bRC bareosAddInclude(bpContext* ctx, const char* file) { return bRC_OK; }; +bRC bareosAddOptions(bpContext* ctx, const char* opts) { return bRC_OK; }; +bRC bareosAddRegex(bpContext* ctx, const char* item, int type) +{ + return bRC_OK; +}; +bRC bareosAddWild(bpContext* ctx, const char* item, int type) +{ + return bRC_OK; +}; +bRC bareosNewOptions(bpContext* ctx) { return bRC_OK; }; +bRC bareosNewInclude(bpContext* ctx) { return bRC_OK; }; +bRC bareosNewPreInclude(bpContext* ctx) { return bRC_OK; }; +bRC bareosCheckChanges(bpContext* ctx, struct filedaemon::save_pkt* sp) +{ + return bRC_OK; +}; +bRC bareosAcceptFile(bpContext* ctx, struct filedaemon::save_pkt* sp) +{ + return bRC_OK; +}; /* Need fname and statp */ +bRC bareosSetSeenBitmap(bpContext* ctx, bool all, char* fname) +{ + return bRC_OK; +}; +bRC bareosClearSeenBitmap(bpContext* ctx, bool all, char* fname) +{ + return bRC_OK; +}; + + +/* Bareos entry points */ +static filedaemon::bFuncs bfuncs = {sizeof(filedaemon::bFuncs), + FD_PLUGIN_INTERFACE_VERSION, + bareosRegisterEvents, + bareosUnRegisterEvents, + bareosGetInstanceCount, + bareosGetValue, + bareosSetValue, + bareosJobMsg, + bareosDebugMsg, + bareosMalloc, + bareosFree, + bareosAddExclude, + bareosAddInclude, + bareosAddOptions, + bareosAddRegex, + bareosAddWild, + bareosNewOptions, + bareosNewInclude, + bareosNewPreInclude, + bareosCheckChanges, + bareosAcceptFile, + bareosSetSeenBitmap, + bareosClearSeenBitmap}; + +static void* bareos_plugin_context = NULL; int main(int argc, char* argv[]) { - static filedaemon::bFuncs bfuncs; Py_SetProgramName(argv[0]); Py_Initialize(); PyObject* bareosfdModule = PyImport_ImportModule("bareosfd"); if (bareosfdModule) { - printf("loading bareosfd successfully\n"); + printf("loaded bareosfd successfully\n"); } else { - printf("loaded bareosfd failed\n"); + printf("loading of bareosfd failed\n"); } if (PyErr_Occurred()) { PyErrorHandler(); } - // Extract capsule pointer from bareosfd module + printf("bfuncs is at %p\n", &bfuncs); + printf("bareos_plugin_context %p\n", &bareos_plugin_context); + + // Extract capsules pointer from bareosfd module void* ctx_from_bareosfd_module = PyCapsule_Import("bareosfd.bpContext", 0); + if (!ctx_from_bareosfd_module) { + printf("importing bareosfd.bpContext failed \n"); + } + + // Extract capsules pointer from bareosfd module + void* bfuncs_from_bareosfd_module = PyCapsule_Import("bareosfd.bFuncs", 0); + if (!bfuncs_from_bareosfd_module) { + printf("importing bareosfd.bFuncs failed \n"); + } - if (ctx_from_bareosfd_module) { - printf("module_main: imported capsule successfully\n"); - printf("module_main: ctx_from_bareosfd_module is at %p\n", - ctx_from_bareosfd_module); + // Extract capsules pointer from bareosfd module + void (*loadplugin_from_bareosfd_module)( + filedaemon::bInfo * lbinfo, filedaemon::bFuncs * lbfuncs, + genpInfo * *pinfo, filedaemon::pFuncs * *pfuncs) = + (void (*)(filedaemon::bInfo*, filedaemon::bFuncs*, genpInfo**, + filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", + 0); - printf("bfuncs are at: %p\n", &bfuncs); - ctx_from_bareosfd_module = &bfuncs; - printf("ctx_from_bareosfd_module contains %p\n", ctx_from_bareosfd_module); + if (!loadplugin_from_bareosfd_module) { + printf("importing bareosfd.loadPlugin failed \n"); } + printf("ctx_from_bareosfd_module is at %p\n", ctx_from_bareosfd_module); + printf("bfuncs_from_bareosfd_module is at %p\n", + bfuncs_from_bareosfd_module); + printf("loadplugin_from_bareosfd_module is @ %p\n", + loadplugin_from_bareosfd_module); + + printf("ctx_from_bareosfd_module contains %p\n", + *(void**)ctx_from_bareosfd_module); + printf("bfuncs_from_bareosfd_module contains %p\n", + *(void**)bfuncs_from_bareosfd_module); + + *(void**)ctx_from_bareosfd_module = &bareos_plugin_context; + *(void**)bfuncs_from_bareosfd_module = &bfuncs; + + /* call loadPlugin in plugin */ + filedaemon::bInfo myInfo; + genpInfo pinfo; + filedaemon::pFuncs pfuncs; + + loadplugin_from_bareosfd_module(&myInfo, &bfuncs, (genpInfo**)&pinfo, + (filedaemon::pFuncs**)&pfuncs); + + + printf("ctx_from_bareosfd_module contains %p\n", + *(void**)ctx_from_bareosfd_module); + printf("bfuncs_from_bareosfd_module contains %p\n", + *(void**)bfuncs_from_bareosfd_module); + + PyObject* pModule = PyImport_ImportModule("bareosfd-module-test"); if (PyErr_Occurred()) { PyErrorHandler(); } diff --git a/core/src/plugins/python_plugins_common.h b/core/src/plugins/python_plugins_common.h index 3795da6d3e9..24cd42efc4d 100644 --- a/core/src/plugins/python_plugins_common.h +++ b/core/src/plugins/python_plugins_common.h @@ -45,12 +45,14 @@ /* check if bareos_plugin_ctx and bfunc are set. * Otherwise return NULL and throw RuntimeError */ -#define RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() \ - if (!bareos_plugin_ctx) { \ - PyErr_SetString(PyExc_RuntimeError, "bareos_plugin_ctx is unset"); \ - return NULL; \ - } \ - if (!bfuncs) { PyErr_SetString(PyExc_RuntimeError, "bfuncs is unset"); } \ - return NULL; +#define RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() \ + if (!bareos_plugin_ctx) { \ + PyErr_SetString(PyExc_RuntimeError, "bareos_plugin_ctx is unset"); \ + return NULL; \ + } \ + if (!bfuncs) { \ + PyErr_SetString(PyExc_RuntimeError, "bfuncs is unset"); \ + return NULL; \ + } #endif // BAREOS_PYTHON_PLUGINS_COMMON_H_ diff --git a/core/src/plugins/stored/CMakeLists.txt b/core/src/plugins/stored/CMakeLists.txt index d48f3eabfaa..75292122533 100644 --- a/core/src/plugins/stored/CMakeLists.txt +++ b/core/src/plugins/stored/CMakeLists.txt @@ -64,10 +64,12 @@ endif() if(HAVE_PYTHON) configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) - add_custom_target(bareossd-pymodule ALL + add_custom_command( TARGET python-sd + POST_BUILD COMMENT "building python module pythonmodules/bareossd.so" COMMAND ${PYTHON_EXECUTABLE} python/setup.py build COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build DEPENDS python-sd ) From c2fb8e1e8692fc2ada9c3f2b117cede6027ca3b6 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 10 Mar 2020 10:32:07 +0100 Subject: [PATCH 029/341] python-fd: some changes to python-fd-module-tester --- core/src/plugins/filed/CMakeLists.txt | 2 +- .../filed/python/test/bareosfd-module-test.py | 2 ++ .../python/test/python-fd-module-tester.cc | 25 ++++++++++--------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index c7b435e1986..533ef8270ff 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -115,7 +115,7 @@ if(HAVE_PYTHON) COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bareos-fd-module-tester ) set_property(TEST bareosfd-python-module-tester - PROPERTY ENVIRONMENT PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/python/test/:${CMAKE_CURRENT_BINARY_DIR}/pythonmodules) + PROPERTY ENVIRONMENT PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/python/test/:${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/pyfiles) endif() diff --git a/core/src/plugins/filed/python/test/bareosfd-module-test.py b/core/src/plugins/filed/python/test/bareosfd-module-test.py index 54b21faf71c..4ba1c6afb9c 100644 --- a/core/src/plugins/filed/python/test/bareosfd-module-test.py +++ b/core/src/plugins/filed/python/test/bareosfd-module-test.py @@ -1,7 +1,9 @@ import bareosfd +import bareos_fd_consts def load_bareos_plugin(plugindef): print ("Hello from load_bareos_plugin") print (plugindef) print (bareosfd) + bareosfd.JobMessage(100, "Kuckuck") bareosfd.DebugMessage(100, "Kuckuck") diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index a43a47873a6..ddb5e05c6c1 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -184,8 +184,8 @@ int main(int argc, char* argv[]) } if (PyErr_Occurred()) { PyErrorHandler(); } - printf("bfuncs is at %p\n", &bfuncs); - printf("bareos_plugin_context %p\n", &bareos_plugin_context); + /* printf("bfuncs is at %p\n", &bfuncs); */ + /* printf("bareos_plugin_context %p\n", &bareos_plugin_context); */ // Extract capsules pointer from bareosfd module void* ctx_from_bareosfd_module = PyCapsule_Import("bareosfd.bpContext", 0); @@ -211,16 +211,17 @@ int main(int argc, char* argv[]) printf("importing bareosfd.loadPlugin failed \n"); } - printf("ctx_from_bareosfd_module is at %p\n", ctx_from_bareosfd_module); - printf("bfuncs_from_bareosfd_module is at %p\n", - bfuncs_from_bareosfd_module); - printf("loadplugin_from_bareosfd_module is @ %p\n", - loadplugin_from_bareosfd_module); - - printf("ctx_from_bareosfd_module contains %p\n", - *(void**)ctx_from_bareosfd_module); - printf("bfuncs_from_bareosfd_module contains %p\n", - *(void**)bfuncs_from_bareosfd_module); + /* printf("ctx_from_bareosfd_module is at %p\n", + * ctx_from_bareosfd_module); */ + /* printf("bfuncs_from_bareosfd_module is at %p\n", */ + /* bfuncs_from_bareosfd_module); */ + /* printf("loadplugin_from_bareosfd_module is @ %p\n", */ + /* loadplugin_from_bareosfd_module); */ + + /* printf("ctx_from_bareosfd_module contains %p\n", */ + /* *(void**)ctx_from_bareosfd_module); */ + /* printf("bfuncs_from_bareosfd_module contains %p\n", */ + /* *(void**)bfuncs_from_bareosfd_module); */ *(void**)ctx_from_bareosfd_module = &bareos_plugin_context; *(void**)bfuncs_from_bareosfd_module = &bfuncs; From f1dc742412bababd92a070752d5e0245a02c1324 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 13 Mar 2020 18:37:31 +0100 Subject: [PATCH 030/341] python-fd-module-tester: make BareosJobMessage work. --- core/src/plugins/filed/python/python-fd.cc | 7 ++----- core/src/plugins/filed/python/test/bareosfd-module-test.py | 2 +- .../plugins/filed/python/test/python-fd-module-tester.cc | 4 +++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 505225f0452..3b645d91987 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -2385,17 +2385,14 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (jobmsg) { - bareos_plugin_ctx = GetPluginContextFromPythonModule(); - Jmsg(bareos_plugin_ctx, type, "python-fd: %s", jobmsg); - } + if (jobmsg) { Jmsg(bareos_plugin_ctx, type, "python-fd: %s", jobmsg); } Py_INCREF(Py_None); return Py_None; diff --git a/core/src/plugins/filed/python/test/bareosfd-module-test.py b/core/src/plugins/filed/python/test/bareosfd-module-test.py index 4ba1c6afb9c..d2b7dc9cf51 100644 --- a/core/src/plugins/filed/python/test/bareosfd-module-test.py +++ b/core/src/plugins/filed/python/test/bareosfd-module-test.py @@ -5,5 +5,5 @@ def load_bareos_plugin(plugindef): print ("Hello from load_bareos_plugin") print (plugindef) print (bareosfd) - bareosfd.JobMessage(100, "Kuckuck") bareosfd.DebugMessage(100, "Kuckuck") + bareosfd.JobMessage(100, "Kuckuck") diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index ddb5e05c6c1..7607add5c78 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -91,6 +91,8 @@ bRC bareosJobMsg(bpContext* ctx, const char* fmt, ...) { + printf("bareosJobMsg file:%s line:%d type:%d time: %ld, fmt:%s\n", file, line, + type, (int64_t)mtime, fmt); return bRC_OK; }; bRC bareosDebugMsg(bpContext* ctx, @@ -100,7 +102,7 @@ bRC bareosDebugMsg(bpContext* ctx, const char* fmt, ...) { - printf("bareosDebugMsg file:%s line:%d level: %d fmt:%s\n", file, line, level, + printf("bareosDebugMsg file:%s line:%d level:%d fmt:%s\n", file, line, level, fmt); return bRC_OK; }; From de0e0514ca1e13c55e489b51400f6be6dee977aa Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 13 Mar 2020 20:07:18 +0100 Subject: [PATCH 031/341] python-fd: move bareosfd_consts.py info into python-fd module itself --- core/src/plugins/filed/python/python-fd.h | 191 ++++++++++++++++++ .../filed/python/test/bareosfd_test.py | 23 ++- core/src/plugins/python_plugins_common.h | 13 ++ 3 files changed, 223 insertions(+), 4 deletions(-) diff --git a/core/src/plugins/filed/python/python-fd.h b/core/src/plugins/filed/python/python-fd.h index 5b229050c40..887a2e7d7e7 100644 --- a/core/src/plugins/filed/python/python-fd.h +++ b/core/src/plugins/filed/python/python-fd.h @@ -768,6 +768,7 @@ bRC loadPlugin(bInfo* lbinfo, } #endif + MOD_INIT(bareosfd) { PyObject* m = NULL; @@ -864,6 +865,196 @@ MOD_INIT(bareosfd) Py_INCREF(&PyXattrPacketType); PyModule_AddObject(m, "XattrPacket", (PyObject*)&PyXattrPacketType); + + /* constants */ + const char* bJobMessageType = "bJobMessageType"; + PyObject* pDictJobMessageType = NULL; + pDictJobMessageType = PyDict_New(); + if (!pDictJobMessageType) { return MOD_ERROR_VAL; } + DictSet_StrLong(pDictJobMessageType, M_ABORT, 1); + DictSet_StrLong(pDictJobMessageType, M_DEBUG, 2); + DictSet_StrLong(pDictJobMessageType, M_FATAL, 3); + DictSet_StrLong(pDictJobMessageType, M_ERROR, 4); + DictSet_StrLong(pDictJobMessageType, M_WARNING, 5); + DictSet_StrLong(pDictJobMessageType, M_INFO, 6); + DictSet_StrLong(pDictJobMessageType, M_SAVED, 7); + DictSet_StrLong(pDictJobMessageType, M_NOTSAVED, 8); + DictSet_StrLong(pDictJobMessageType, M_SKIPPED, 9); + DictSet_StrLong(pDictJobMessageType, M_MOUNT, 10); + DictSet_StrLong(pDictJobMessageType, M_ERROR_TERM, 11); + DictSet_StrLong(pDictJobMessageType, M_TERM, 12); + DictSet_StrLong(pDictJobMessageType, M_RESTORED, 13); + DictSet_StrLong(pDictJobMessageType, M_SECURITY, 14); + DictSet_StrLong(pDictJobMessageType, M_ALERT, 15); + DictSet_StrLong(pDictJobMessageType, M_VOLMGMT, 16); + if (PyModule_AddObject(m, bJobMessageType, pDictJobMessageType)) { + return MOD_ERROR_VAL; + } + + + const char* bVariable = "bVariable"; + PyObject* pDictbVariable = NULL; + pDictbVariable = PyDict_New(); + if (!pDictbVariable) { return MOD_ERROR_VAL; } + DictSet_StrLong(pDictbVariable, bVarJobId, 1); + DictSet_StrLong(pDictbVariable, bVarFDName, 2); + DictSet_StrLong(pDictbVariable, bVarLevel, 3); + DictSet_StrLong(pDictbVariable, bVarType, 4); + DictSet_StrLong(pDictbVariable, bVarClient, 5); + DictSet_StrLong(pDictbVariable, bVarJobName, 6); + DictSet_StrLong(pDictbVariable, bVarJobStatus, 7); + DictSet_StrLong(pDictbVariable, bVarSinceTime, 8); + DictSet_StrLong(pDictbVariable, bVarAccurate, 9); + DictSet_StrLong(pDictbVariable, bVarFileSeen, 10); + DictSet_StrLong(pDictbVariable, bVarVssClient, 11); + DictSet_StrLong(pDictbVariable, bVarWorkingDir, 12); + DictSet_StrLong(pDictbVariable, bVarWhere, 13); + DictSet_StrLong(pDictbVariable, bVarRegexWhere, 14); + DictSet_StrLong(pDictbVariable, bVarExePath, 15); + DictSet_StrLong(pDictbVariable, bVarVersion, 16); + DictSet_StrLong(pDictbVariable, bVarDistName, 17); + DictSet_StrLong(pDictbVariable, bVarPrevJobName, 18); + DictSet_StrLong(pDictbVariable, bVarPrefixLinks, 19); + if (PyModule_AddObject(m, bVariable, pDictbVariable)) { + return MOD_ERROR_VAL; + } + + + const char* bFileType = "bFileType"; + PyObject* pDictbFileType = NULL; + pDictbFileType = PyDict_New(); + DictSet_StrLong(pDictbFileType, FT_LNKSAVED, 1); + DictSet_StrLong(pDictbFileType, FT_REGE, 2); + DictSet_StrLong(pDictbFileType, FT_REG, 3); + DictSet_StrLong(pDictbFileType, FT_LNK, 4); + DictSet_StrLong(pDictbFileType, FT_DIREND, 5); + DictSet_StrLong(pDictbFileType, FT_SPEC, 6); + DictSet_StrLong(pDictbFileType, FT_NOACCESS, 7); + DictSet_StrLong(pDictbFileType, FT_NOFOLLOW, 8); + DictSet_StrLong(pDictbFileType, FT_NOSTAT, 9); + DictSet_StrLong(pDictbFileType, FT_NOCHG, 10); + DictSet_StrLong(pDictbFileType, FT_DIRNOCHG, 11); + DictSet_StrLong(pDictbFileType, FT_ISARCH, 12); + DictSet_StrLong(pDictbFileType, FT_NORECURSE, 13); + DictSet_StrLong(pDictbFileType, FT_NOFSCHG, 14); + DictSet_StrLong(pDictbFileType, FT_NOOPEN, 15); + DictSet_StrLong(pDictbFileType, FT_RAW, 16); + DictSet_StrLong(pDictbFileType, FT_FIFO, 17); + DictSet_StrLong(pDictbFileType, FT_DIRBEGIN, 18); + DictSet_StrLong(pDictbFileType, FT_INVALIDFS, 19); + DictSet_StrLong(pDictbFileType, FT_INVALIDDT, 20); + DictSet_StrLong(pDictbFileType, FT_REPARSE, 21); + DictSet_StrLong(pDictbFileType, FT_PLUGIN, 22); + DictSet_StrLong(pDictbFileType, FT_DELETED, 23); + DictSet_StrLong(pDictbFileType, FT_BASE, 24); + DictSet_StrLong(pDictbFileType, FT_RESTORE_FIRST, 25); + DictSet_StrLong(pDictbFileType, FT_JUNCTION, 26); + DictSet_StrLong(pDictbFileType, FT_PLUGIN_CONFIG, 27); + DictSet_StrLong(pDictbFileType, FT_PLUGIN_CONFIG_FILLED, 28); + if (!pDictbFileType) { return MOD_ERROR_VAL; } + if (PyModule_AddObject(m, bFileType, pDictbFileType)) { + return MOD_ERROR_VAL; + } + + + const char* bRCs = "bRCs"; + PyObject* pDictbRCs = NULL; + pDictbRCs = PyDict_New(); + DictSet_StrLong(pDictbRCs, bRC_OK, 0); + DictSet_StrLong(pDictbRCs, bRC_Stop, 1); + DictSet_StrLong(pDictbRCs, bRC_Error, 2); + DictSet_StrLong(pDictbRCs, bRC_More, 3); + DictSet_StrLong(pDictbRCs, bRC_Term, 4); + DictSet_StrLong(pDictbRCs, bRC_Seen, 5); + DictSet_StrLong(pDictbRCs, bRC_Core, 6); + DictSet_StrLong(pDictbRCs, bRC_Skip, 7); + DictSet_StrLong(pDictbRCs, bRC_Cancel, 8); + if (!pDictbRCs) { return MOD_ERROR_VAL; } + if (PyModule_AddObject(m, bRCs, pDictbRCs)) { return MOD_ERROR_VAL; } + + + const char* bcfs = "bcfs"; + PyObject* pDictbcfs = NULL; + pDictbcfs = PyDict_New(); + DictSet_StrLong(pDictbcfs, cf_skip, 1); + DictSet_StrLong(pDictbcfs, cf_error, 2); + DictSet_StrLong(pDictbcfs, cf_extract, 3); + DictSet_StrLong(pDictbcfs, cf_created, 4); + DictSet_StrLong(pDictbcfs, cf_core, 5); + if (!pDictbcfs) { return MOD_ERROR_VAL; } + if (PyModule_AddObject(m, bcfs, pDictbcfs)) { return MOD_ERROR_VAL; } + + const char* bEventType = "bEventType"; + PyObject* pDictbEventType = NULL; + pDictbEventType = PyDict_New(); + DictSet_StrLong(pDictbEventType, bEventJobStart, 1); + DictSet_StrLong(pDictbEventType, bEventJobEnd, 2); + DictSet_StrLong(pDictbEventType, bEventStartBackupJob, 3); + DictSet_StrLong(pDictbEventType, bEventEndBackupJob, 4); + DictSet_StrLong(pDictbEventType, bEventStartRestoreJob, 5); + DictSet_StrLong(pDictbEventType, bEventEndRestoreJob, 6); + DictSet_StrLong(pDictbEventType, bEventStartVerifyJob, 7); + DictSet_StrLong(pDictbEventType, bEventEndVerifyJob, 8); + DictSet_StrLong(pDictbEventType, bEventBackupCommand, 9); + DictSet_StrLong(pDictbEventType, bEventRestoreCommand, 10); + DictSet_StrLong(pDictbEventType, bEventEstimateCommand, 11); + DictSet_StrLong(pDictbEventType, bEventLevel, 12); + DictSet_StrLong(pDictbEventType, bEventSince, 13); + DictSet_StrLong(pDictbEventType, bEventCancelCommand, 14); + DictSet_StrLong(pDictbEventType, bEventRestoreObject, 15); + DictSet_StrLong(pDictbEventType, bEventEndFileSet, 16); + DictSet_StrLong(pDictbEventType, bEventPluginCommand, 17); + DictSet_StrLong(pDictbEventType, bEventOptionPlugin, 18); + DictSet_StrLong(pDictbEventType, bEventHandleBackupFile, 19); + DictSet_StrLong(pDictbEventType, bEventNewPluginOptions, 20); + DictSet_StrLong(pDictbEventType, bEventVssInitializeForBackup, 21); + DictSet_StrLong(pDictbEventType, bEventVssInitializeForRestore, 22); + DictSet_StrLong(pDictbEventType, bEventVssSetBackupState, 23); + DictSet_StrLong(pDictbEventType, bEventVssPrepareForBackup, 24); + DictSet_StrLong(pDictbEventType, bEventVssBackupAddComponents, 25); + DictSet_StrLong(pDictbEventType, bEventVssPrepareSnapshot, 26); + DictSet_StrLong(pDictbEventType, bEventVssCreateSnapshots, 27); + DictSet_StrLong(pDictbEventType, bEventVssRestoreLoadComponentMetadata, 28); + DictSet_StrLong(pDictbEventType, bEventVssRestoreSetComponentsSelected, 29); + DictSet_StrLong(pDictbEventType, bEventVssCloseRestore, 30); + DictSet_StrLong(pDictbEventType, bEventVssBackupComplete, 31); + if (!pDictbEventType) { return MOD_ERROR_VAL; } + if (PyModule_AddObject(m, bEventType, pDictbEventType)) { + return MOD_ERROR_VAL; + } + + + const char* bIOPS = "bIOPS"; + PyObject* pDictbIOPS = NULL; + pDictbIOPS = PyDict_New(); + DictSet_StrLong(pDictbIOPS, IO_OPEN, 1); + DictSet_StrLong(pDictbIOPS, IO_READ, 2); + DictSet_StrLong(pDictbIOPS, IO_WRITE, 3); + DictSet_StrLong(pDictbIOPS, IO_CLOSE, 4); + DictSet_StrLong(pDictbIOPS, IO_SEEK, 5); + if (!pDictbIOPS) { return MOD_ERROR_VAL; } + if (PyModule_AddObject(m, bIOPS, pDictbIOPS)) { return MOD_ERROR_VAL; } + + + const char* bLevels = "bLevels"; + PyObject* pDictbLevels = NULL; + pDictbLevels = PyDict_New(); + DictSet_StrStr(pDictbLevels, L_FULL, "F"); + DictSet_StrStr(pDictbLevels, L_INCREMENTAL, "I"); + DictSet_StrStr(pDictbLevels, L_DIFFERENTIAL, "D"); + DictSet_StrStr(pDictbLevels, L_SINCE, "S"); + DictSet_StrStr(pDictbLevels, L_VERIFY_CATALOG, "C"); + DictSet_StrStr(pDictbLevels, L_VERIFY_INIT, "V"); + DictSet_StrStr(pDictbLevels, L_VERIFY_VOLUME_TO_CATALOG, "O"); + DictSet_StrStr(pDictbLevels, L_VERIFY_DISK_TO_CATALOG, "d"); + DictSet_StrStr(pDictbLevels, L_VERIFY_DATA, "A"); + DictSet_StrStr(pDictbLevels, L_BASE, "B"); + DictSet_StrStr(pDictbLevels, L_NONE, " "); + DictSet_StrStr(pDictbLevels, L_VIRTUAL_FULL, "f"); + if (!pDictbLevels) { return MOD_ERROR_VAL; } + if (PyModule_AddObject(m, bLevels, pDictbLevels)) { return MOD_ERROR_VAL; } + + return MOD_SUCCESS_VAL(m); } diff --git a/core/src/plugins/filed/python/test/bareosfd_test.py b/core/src/plugins/filed/python/test/bareosfd_test.py index 5d4a2a49a55..e56d43fb003 100644 --- a/core/src/plugins/filed/python/test/bareosfd_test.py +++ b/core/src/plugins/filed/python/test/bareosfd_test.py @@ -1,15 +1,30 @@ import unittest import bareosfd import time - +# print dir(bareosfd) +# print "bareosfd.bJobMessageType:", str( bareosfd.bJobMessageType) +# print "bareosfd.bVariable:", str( bareosfd.bVariable) +# print "bareosfd.bEventType:", str( bareosfd.bEventType) +# print "bareosfd.bFileType:", str( bareosfd.bFileType) +# print "bareosfd.bFuncs:", str( bareosfd.bFuncs) +# print "bareosfd.bIOPS:", str( bareosfd.bIOPS) +# print "bareosfd.bLevels:", str( bareosfd.bLevels) +# print "bareosfd.bRCs:", str( bareosfd.bRCs) +# print "bareosfd.bVariable:", str( bareosfd.bVariable) +# print "bareosfd.bcfs:", str( bareosfd.bcfs) class TestBareosFd(unittest.TestCase): - def test_SetValue(self): - self.assertRaises(RuntimeError, bareosfd.SetValue, 2) + def test_bJobMessageType(self): + bareosfd.DebugMessage( bareosfd.bJobMessageType['M_INFO'], "This is a Job message") + self.assertEqual(str(bareosfd.bJobMessageType), """{'M_MOUNT': 10L, 'M_SECURITY': 14L, 'M_DEBUG': 2L, 'M_WARNING': 5L, 'M_SAVED': 7L, 'M_TERM': 12L, 'M_ABORT': 1L, 'M_INFO': 6L, 'M_ERROR': 4L, 'M_FATAL': 3L, 'M_NOTSAVED': 8L, 'M_RESTORED': 13L, 'M_ERROR_TERM': 11L, 'M_ALERT': 15L, 'M_VOLMGMT': 16L, 'M_SKIPPED': 9L}""" +) + + # def test_SetValue(self): + # self.assertRaises(RuntimeError, bareosfd.SetValue, 2) def test_DebugMessage(self): - self.assertRaises(RuntimeError, bareosfd.DebugMessage, "This is a debug message") + self.assertRaises(RuntimeError, bareosfd.DebugMessage, 100, "This is a debug message") def test_RestoreObject(self): test_RestoreObject = bareosfd.RestoreObject() diff --git a/core/src/plugins/python_plugins_common.h b/core/src/plugins/python_plugins_common.h index 24cd42efc4d..98b047e43b7 100644 --- a/core/src/plugins/python_plugins_common.h +++ b/core/src/plugins/python_plugins_common.h @@ -55,4 +55,17 @@ return NULL; \ } +#define DictSet_StrLong(dict, string, value) \ + if (PyDict_SetItem(dict, PyBytes_FromString(#string), \ + PyLong_FromLong(value))) { \ + return MOD_ERROR_VAL; \ + } + +#define DictSet_StrStr(dict, string, value) \ + if (PyDict_SetItem(dict, PyBytes_FromString(#string), \ + PyBytes_FromString(value))) { \ + return MOD_ERROR_VAL; \ + } + + #endif // BAREOS_PYTHON_PLUGINS_COMMON_H_ From dd27f214bbc14ac67a1829220bcfe315d0cab03b Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 14 Mar 2020 10:04:21 +0100 Subject: [PATCH 032/341] python-fd: move constants into python-fd module --- core/src/plugins/dird/python/python-dir.h | 108 ++++++++++++ .../filed/python/pyfiles/bareos_fd_consts.py | 157 ------------------ core/src/plugins/filed/python/python-fd.h | 22 +-- core/src/plugins/stored/python/python-sd.h | 111 +++++++++++++ 4 files changed, 230 insertions(+), 168 deletions(-) delete mode 100644 core/src/plugins/filed/python/pyfiles/bareos_fd_consts.py diff --git a/core/src/plugins/dird/python/python-dir.h b/core/src/plugins/dird/python/python-dir.h index 26bf63576ae..cbf4d72ba4c 100644 --- a/core/src/plugins/dird/python/python-dir.h +++ b/core/src/plugins/dird/python/python-dir.h @@ -115,6 +115,114 @@ MOD_INIT(bareosdir) return MOD_ERROR_VAL; } + + /* module dictionaries */ + const char* bJobMessageType = "bJobMessageType"; + PyObject* pDictJobMessageType = NULL; + pDictJobMessageType = PyDict_New(); + if (!pDictJobMessageType) { return MOD_ERROR_VAL; } + DictSet_StrLong(pDictJobMessageType, M_ABORT, 1); + DictSet_StrLong(pDictJobMessageType, M_DEBUG, 2); + DictSet_StrLong(pDictJobMessageType, M_FATAL, 3); + DictSet_StrLong(pDictJobMessageType, M_ERROR, 4); + DictSet_StrLong(pDictJobMessageType, M_WARNING, 5); + DictSet_StrLong(pDictJobMessageType, M_INFO, 6); + DictSet_StrLong(pDictJobMessageType, M_SAVED, 7); + DictSet_StrLong(pDictJobMessageType, M_NOTSAVED, 8); + DictSet_StrLong(pDictJobMessageType, M_SKIPPED, 9); + DictSet_StrLong(pDictJobMessageType, M_MOUNT, 10); + DictSet_StrLong(pDictJobMessageType, M_ERROR_TERM, 11); + DictSet_StrLong(pDictJobMessageType, M_TERM, 12); + DictSet_StrLong(pDictJobMessageType, M_RESTORED, 13); + DictSet_StrLong(pDictJobMessageType, M_SECURITY, 14); + DictSet_StrLong(pDictJobMessageType, M_ALERT, 15); + DictSet_StrLong(pDictJobMessageType, M_VOLMGMT, 16); + if (PyModule_AddObject(m, bJobMessageType, pDictJobMessageType)) { + return MOD_ERROR_VAL; + } + + const char* bDirVariable = "bDirVariable"; + PyObject* pDictbDirVariable = NULL; + pDictbDirVariable = PyDict_New(); + if (!pDictbDirVariable) { return MOD_ERROR_VAL; } + DictSet_StrLong(pDictbDirVariable, bDirVarJob, 1); + DictSet_StrLong(pDictbDirVariable, bDirVarLevel, 2); + DictSet_StrLong(pDictbDirVariable, bDirVarType, 3); + DictSet_StrLong(pDictbDirVariable, bDirVarJobId, 4); + DictSet_StrLong(pDictbDirVariable, bDirVarClient, 5); + DictSet_StrLong(pDictbDirVariable, bDirVarNumVols, 6); + DictSet_StrLong(pDictbDirVariable, bDirVarPool, 7); + DictSet_StrLong(pDictbDirVariable, bDirVarStorage, 8); + DictSet_StrLong(pDictbDirVariable, bDirVarWriteStorage, 9); + DictSet_StrLong(pDictbDirVariable, bDirVarReadStorage, 10); + DictSet_StrLong(pDictbDirVariable, bDirVarCatalog, 11); + DictSet_StrLong(pDictbDirVariable, bDirVarMediaType, 12); + DictSet_StrLong(pDictbDirVariable, bDirVarJobName, 13); + DictSet_StrLong(pDictbDirVariable, bDirVarJobStatus, 14); + DictSet_StrLong(pDictbDirVariable, bDirVarPriority, 15); + DictSet_StrLong(pDictbDirVariable, bDirVarVolumeName, 16); + DictSet_StrLong(pDictbDirVariable, bDirVarCatalogRes, 17); + DictSet_StrLong(pDictbDirVariable, bDirVarJobErrors, 18); + DictSet_StrLong(pDictbDirVariable, bDirVarJobFiles, 19); + DictSet_StrLong(pDictbDirVariable, bDirVarSDJobFiles, 20); + DictSet_StrLong(pDictbDirVariable, bDirVarSDErrors, 21); + DictSet_StrLong(pDictbDirVariable, bDirVarFDJobStatus, 22); + DictSet_StrLong(pDictbDirVariable, bDirVarSDJobStatus, 23); + DictSet_StrLong(pDictbDirVariable, bDirVarPluginDir, 24); + DictSet_StrLong(pDictbDirVariable, bDirVarLastRate, 25); + DictSet_StrLong(pDictbDirVariable, bDirVarJobBytes, 26); + DictSet_StrLong(pDictbDirVariable, bDirVarReadBytes, 27); + if (PyModule_AddObject(m, bDirVariable, pDictbDirVariable)) { + return MOD_ERROR_VAL; + } + + const char* bwDirVariable = "bwDirVariable"; + PyObject* pDictbwDirVariable = NULL; + pDictbwDirVariable = PyDict_New(); + if (!pDictbwDirVariable) { return MOD_ERROR_VAL; } + DictSet_StrLong(pDictbwDirVariable, bwDirVarJobReport, 1); + DictSet_StrLong(pDictbwDirVariable, bwDirVarVolumeName, 2); + DictSet_StrLong(pDictbwDirVariable, bwDirVarPriority, 3); + DictSet_StrLong(pDictbwDirVariable, bwDirVarJobLevel, 4); + if (PyModule_AddObject(m, bwDirVariable, pDictbwDirVariable)) { + return MOD_ERROR_VAL; + } + + const char* bRCs = "bRCs"; + PyObject* pDictbRCs = NULL; + pDictbRCs = PyDict_New(); + DictSet_StrLong(pDictbRCs, bRC_OK, 0); + DictSet_StrLong(pDictbRCs, bRC_Stop, 1); + DictSet_StrLong(pDictbRCs, bRC_Error, 2); + DictSet_StrLong(pDictbRCs, bRC_More, 3); + DictSet_StrLong(pDictbRCs, bRC_Term, 4); + DictSet_StrLong(pDictbRCs, bRC_Seen, 5); + DictSet_StrLong(pDictbRCs, bRC_Core, 6); + DictSet_StrLong(pDictbRCs, bRC_Skip, 7); + DictSet_StrLong(pDictbRCs, bRC_Cancel, 8); + if (!pDictbRCs) { return MOD_ERROR_VAL; } + if (PyModule_AddObject(m, bRCs, pDictbRCs)) { return MOD_ERROR_VAL; } + + const char* bDirEvent = "bDirEvent"; + PyObject* pDictbDirEvent = NULL; + pDictbDirEvent = PyDict_New(); + DictSet_StrLong(pDictbDirEvent, bEventJobStart, 1); + DictSet_StrLong(pDictbDirEvent, bEventJobEnd, 2); + DictSet_StrLong(pDictbDirEvent, bDirEventJobInit, 3); + DictSet_StrLong(pDictbDirEvent, bDirEventJobRun, 4); + DictSet_StrLong(pDictbDirEvent, bDirEventVolumePurged, 5); + DictSet_StrLong(pDictbDirEvent, bDirEventNewVolume, 6); + DictSet_StrLong(pDictbDirEvent, bDirEventNeedVolume, 7); + DictSet_StrLong(pDictbDirEvent, bDirEventVolumeFull, 8); + DictSet_StrLong(pDictbDirEvent, bDirEventRecyle, 9); + DictSet_StrLong(pDictbDirEvent, bDirEventGetScratch, 10); + DictSet_StrLong(pDictbDirEvent, bDirEventNewPluginOptions, 11); + if (!pDictbDirEvent) { return MOD_ERROR_VAL; } + if (PyModule_AddObject(m, bDirEvent, pDictbDirEvent)) { + return MOD_ERROR_VAL; + } + + return MOD_SUCCESS_VAL(m); } diff --git a/core/src/plugins/filed/python/pyfiles/bareos_fd_consts.py b/core/src/plugins/filed/python/pyfiles/bareos_fd_consts.py deleted file mode 100644 index f83e7d64cc1..00000000000 --- a/core/src/plugins/filed/python/pyfiles/bareos_fd_consts.py +++ /dev/null @@ -1,157 +0,0 @@ -# BAREOS - Backup Archiving REcovery Open Sourced -# -# Copyright (C) 2013-2014 Bareos GmbH & Co. KG -# -# This program is Free Software; you can redistribute it and/or -# modify it under the terms of version three of the GNU Affero General Public -# License as published by the Free Software Foundation, which is -# listed in the file LICENSE. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# Author: Marco van Wieringen -# -bJobMessageType = dict( - M_ABORT=1, - M_DEBUG=2, - M_FATAL=3, - M_ERROR=4, - M_WARNING=5, - M_INFO=6, - M_SAVED=7, - M_NOTSAVED=8, - M_SKIPPED=9, - M_MOUNT=10, - M_ERROR_TERM=11, - M_TERM=12, - M_RESTORED=13, - M_SECURITY=14, - M_ALERT=15, - M_VOLMGMT=16, -) - -bVariable = dict( - bVarJobId=1, - bVarFDName=2, - bVarLevel=3, - bVarType=4, - bVarClient=5, - bVarJobName=6, - bVarJobStatus=7, - bVarSinceTime=8, - bVarAccurate=9, - bVarFileSeen=10, - bVarVssClient=11, - bVarWorkingDir=12, - bVarWhere=13, - bVarRegexWhere=14, - bVarExePath=15, - bVarVersion=16, - bVarDistName=17, - bVarPrevJobName=18, - bVarPrefixLinks=19, -) - -bFileType = dict( - FT_LNKSAVED=1, - FT_REGE=2, - FT_REG=3, - FT_LNK=4, - FT_DIREND=5, - FT_SPEC=6, - FT_NOACCESS=7, - FT_NOFOLLOW=8, - FT_NOSTAT=9, - FT_NOCHG=10, - FT_DIRNOCHG=11, - FT_ISARCH=12, - FT_NORECURSE=13, - FT_NOFSCHG=14, - FT_NOOPEN=15, - FT_RAW=16, - FT_FIFO=17, - FT_DIRBEGIN=18, - FT_INVALIDFS=19, - FT_INVALIDDT=20, - FT_REPARSE=21, - FT_PLUGIN=22, - FT_DELETED=23, - FT_BASE=24, - FT_RESTORE_FIRST=25, - FT_JUNCTION=26, - FT_PLUGIN_CONFIG=27, - FT_PLUGIN_CONFIG_FILLED=28, -) - -bRCs = dict( - bRC_OK=0, - bRC_Stop=1, - bRC_Error=2, - bRC_More=3, - bRC_Term=4, - bRC_Seen=5, - bRC_Core=6, - bRC_Skip=7, - bRC_Cancel=8, -) - -bCFs = dict(CF_SKIP=1, CF_ERROR=2, CF_EXTRACT=3, CF_CREATED=4, CF_CORE=5) - -bEventType = dict( - bEventJobStart=1, - bEventJobEnd=2, - bEventStartBackupJob=3, - bEventEndBackupJob=4, - bEventStartRestoreJob=5, - bEventEndRestoreJob=6, - bEventStartVerifyJob=7, - bEventEndVerifyJob=8, - bEventBackupCommand=9, - bEventRestoreCommand=10, - bEventEstimateCommand=11, - bEventLevel=12, - bEventSince=13, - bEventCancelCommand=14, - bEventRestoreObject=15, - bEventEndFileSet=16, - bEventPluginCommand=17, - bEventOptionPlugin=18, - bEventHandleBackupFile=19, - bEventNewPluginOptions=20, - bEventVssInitializeForBackup=21, - bEventVssInitializeForRestore=22, - bEventVssSetBackupState=23, - bEventVssPrepareForBackup=24, - bEventVssBackupAddComponents=25, - bEventVssPrepareSnapshot=26, - bEventVssCreateSnapshots=27, - bEventVssRestoreLoadComponentMetadata=28, - bEventVssRestoreSetComponentsSelected=29, - bEventVssCloseRestore=30, - bEventVssBackupComplete=31, -) - -bIOPS = dict(IO_OPEN=1, IO_READ=2, IO_WRITE=3, IO_CLOSE=4, IO_SEEK=5) - -bLevels = dict( - L_FULL="F", - L_INCREMENTAL="I", - L_DIFFERENTIAL="D", - L_SINCE="S", - L_VERIFY_CATALOG="C", - L_VERIFY_INIT="V", - L_VERIFY_VOLUME_TO_CATALOG="O", - L_VERIFY_DISK_TO_CATALOG="d", - L_VERIFY_DATA="A", - L_BASE="B", - L_NONE=" ", - L_VIRTUAL_FULL="f", -) diff --git a/core/src/plugins/filed/python/python-fd.h b/core/src/plugins/filed/python/python-fd.h index 887a2e7d7e7..f51bb22f34a 100644 --- a/core/src/plugins/filed/python/python-fd.h +++ b/core/src/plugins/filed/python/python-fd.h @@ -866,7 +866,7 @@ MOD_INIT(bareosfd) PyModule_AddObject(m, "XattrPacket", (PyObject*)&PyXattrPacketType); - /* constants */ + /* module dictionaries */ const char* bJobMessageType = "bJobMessageType"; PyObject* pDictJobMessageType = NULL; pDictJobMessageType = PyDict_New(); @@ -973,16 +973,16 @@ MOD_INIT(bareosfd) if (PyModule_AddObject(m, bRCs, pDictbRCs)) { return MOD_ERROR_VAL; } - const char* bcfs = "bcfs"; - PyObject* pDictbcfs = NULL; - pDictbcfs = PyDict_New(); - DictSet_StrLong(pDictbcfs, cf_skip, 1); - DictSet_StrLong(pDictbcfs, cf_error, 2); - DictSet_StrLong(pDictbcfs, cf_extract, 3); - DictSet_StrLong(pDictbcfs, cf_created, 4); - DictSet_StrLong(pDictbcfs, cf_core, 5); - if (!pDictbcfs) { return MOD_ERROR_VAL; } - if (PyModule_AddObject(m, bcfs, pDictbcfs)) { return MOD_ERROR_VAL; } + const char* bCFs = "bCFs"; + PyObject* pDictbCFs = NULL; + pDictbCFs = PyDict_New(); + DictSet_StrLong(pDictbCFs, CF_SKIP, 1); + DictSet_StrLong(pDictbCFs, CF_ERROR, 2); + DictSet_StrLong(pDictbCFs, CF_EXTRACT, 3); + DictSet_StrLong(pDictbCFs, CF_CREATED, 4); + DictSet_StrLong(pDictbCFs, CF_CORE, 5); + if (!pDictbCFs) { return MOD_ERROR_VAL; } + if (PyModule_AddObject(m, bCFs, pDictbCFs)) { return MOD_ERROR_VAL; } const char* bEventType = "bEventType"; PyObject* pDictbEventType = NULL; diff --git a/core/src/plugins/stored/python/python-sd.h b/core/src/plugins/stored/python/python-sd.h index 7e85a12686e..060aedabba4 100644 --- a/core/src/plugins/stored/python/python-sd.h +++ b/core/src/plugins/stored/python/python-sd.h @@ -115,6 +115,117 @@ MOD_INIT(bareossd) return MOD_ERROR_VAL; } + /* module dictionaries */ + const char* bJobMessageType = "bJobMessageType"; + PyObject* pDictJobMessageType = NULL; + pDictJobMessageType = PyDict_New(); + if (!pDictJobMessageType) { return MOD_ERROR_VAL; } + DictSet_StrLong(pDictJobMessageType, M_ABORT, 1); + DictSet_StrLong(pDictJobMessageType, M_DEBUG, 2); + DictSet_StrLong(pDictJobMessageType, M_FATAL, 3); + DictSet_StrLong(pDictJobMessageType, M_ERROR, 4); + DictSet_StrLong(pDictJobMessageType, M_WARNING, 5); + DictSet_StrLong(pDictJobMessageType, M_INFO, 6); + DictSet_StrLong(pDictJobMessageType, M_SAVED, 7); + DictSet_StrLong(pDictJobMessageType, M_NOTSAVED, 8); + DictSet_StrLong(pDictJobMessageType, M_SKIPPED, 9); + DictSet_StrLong(pDictJobMessageType, M_MOUNT, 10); + DictSet_StrLong(pDictJobMessageType, M_ERROR_TERM, 11); + DictSet_StrLong(pDictJobMessageType, M_TERM, 12); + DictSet_StrLong(pDictJobMessageType, M_RESTORED, 13); + DictSet_StrLong(pDictJobMessageType, M_SECURITY, 14); + DictSet_StrLong(pDictJobMessageType, M_ALERT, 15); + DictSet_StrLong(pDictJobMessageType, M_VOLMGMT, 16); + if (PyModule_AddObject(m, bJobMessageType, pDictJobMessageType)) { + return MOD_ERROR_VAL; + } + + const char* bsdVariable = "bsdVariable"; + PyObject* pDictsdVariable = NULL; + pDictsdVariable = PyDict_New(); + if (!pDictsdVariable) { return MOD_ERROR_VAL; } + DictSet_StrLong(pDictsdVariable, bsdVarJob, 1); + DictSet_StrLong(pDictsdVariable, bsdVarLevel, 2); + DictSet_StrLong(pDictsdVariable, bsdVarType, 3); + DictSet_StrLong(pDictsdVariable, bsdVarJobId, 4); + DictSet_StrLong(pDictsdVariable, bsdVarClient, 5); + DictSet_StrLong(pDictsdVariable, bsdVarPool, 6); + DictSet_StrLong(pDictsdVariable, bsdVarPoolType, 7); + DictSet_StrLong(pDictsdVariable, bsdVarStorage, 8); + DictSet_StrLong(pDictsdVariable, bsdVarMediaType, 9); + DictSet_StrLong(pDictsdVariable, bsdVarJobName, 10); + DictSet_StrLong(pDictsdVariable, bsdVarJobStatus, 11); + DictSet_StrLong(pDictsdVariable, bsdVarVolumeName, 12); + DictSet_StrLong(pDictsdVariable, bsdVarJobErrors, 13); + DictSet_StrLong(pDictsdVariable, bsdVarJobFiles, 14); + DictSet_StrLong(pDictsdVariable, bsdVarJobBytes, 15); + DictSet_StrLong(pDictsdVariable, bsdVarCompatible, 16); + DictSet_StrLong(pDictsdVariable, bsdVarPluginDir, 17); + if (PyModule_AddObject(m, bsdVariable, pDictsdVariable)) { + return MOD_ERROR_VAL; + } + + const char* bsdwVariable = "bsdwVariable"; + PyObject* pDictsdwVariable = NULL; + pDictsdwVariable = PyDict_New(); + if (!pDictsdwVariable) { return MOD_ERROR_VAL; } + DictSet_StrLong(pDictsdwVariable, bsdwVarJobReport, 1); + DictSet_StrLong(pDictsdwVariable, bsdwVarVolumeName, 2); + DictSet_StrLong(pDictsdwVariable, bsdwVarPriority, 3); + DictSet_StrLong(pDictsdwVariable, bsdwVarJobLevel, 4); + if (PyModule_AddObject(m, bsdwVariable, pDictsdwVariable)) { + return MOD_ERROR_VAL; + } + + const char* bRCs = "bRCs"; + PyObject* pDictbRCs = NULL; + pDictbRCs = PyDict_New(); + DictSet_StrLong(pDictbRCs, bRC_OK, 0); + DictSet_StrLong(pDictbRCs, bRC_Stop, 1); + DictSet_StrLong(pDictbRCs, bRC_Error, 2); + DictSet_StrLong(pDictbRCs, bRC_More, 3); + DictSet_StrLong(pDictbRCs, bRC_Term, 4); + DictSet_StrLong(pDictbRCs, bRC_Seen, 5); + DictSet_StrLong(pDictbRCs, bRC_Core, 6); + DictSet_StrLong(pDictbRCs, bRC_Skip, 7); + DictSet_StrLong(pDictbRCs, bRC_Cancel, 8); + if (!pDictbRCs) { return MOD_ERROR_VAL; } + if (PyModule_AddObject(m, bRCs, pDictbRCs)) { return MOD_ERROR_VAL; } + + + const char* bsdEventType = "bsdEventType"; + PyObject* pDictbsdEventType = NULL; + pDictbsdEventType = PyDict_New(); + DictSet_StrLong(pDictbsdEventType, bsdEventJobStart, 1); + DictSet_StrLong(pDictbsdEventType, bsdEventJobEnd, 2); + DictSet_StrLong(pDictbsdEventType, bsdEventDeviceInit, 3); + DictSet_StrLong(pDictbsdEventType, bsdEventDeviceMount, 4); + DictSet_StrLong(pDictbsdEventType, bsdEventVolumeLoad, 5); + DictSet_StrLong(pDictbsdEventType, bsdEventDeviceReserve, 6); + DictSet_StrLong(pDictbsdEventType, bsdEventDeviceOpen, 7); + DictSet_StrLong(pDictbsdEventType, bsdEventLabelRead, 8); + DictSet_StrLong(pDictbsdEventType, bsdEventLabelVerified, 9); + DictSet_StrLong(pDictbsdEventType, bsdEventLabelWrite, 10); + DictSet_StrLong(pDictbsdEventType, bsdEventDeviceClose, 11); + DictSet_StrLong(pDictbsdEventType, bsdEventVolumeUnload, 12); + DictSet_StrLong(pDictbsdEventType, bsdEventDeviceUnmount, 13); + DictSet_StrLong(pDictbsdEventType, bsdEventReadError, 14); + DictSet_StrLong(pDictbsdEventType, bsdEventWriteError, 15); + DictSet_StrLong(pDictbsdEventType, bsdEventDriveStatus, 16); + DictSet_StrLong(pDictbsdEventType, bsdEventVolumeStatus, 17); + DictSet_StrLong(pDictbsdEventType, bsdEventSetupRecordTranslation, 18); + DictSet_StrLong(pDictbsdEventType, bsdEventReadRecordTranslation, 19); + DictSet_StrLong(pDictbsdEventType, bsdEventWriteRecordTranslation, 20); + DictSet_StrLong(pDictbsdEventType, bsdEventDeviceRelease, 21); + DictSet_StrLong(pDictbsdEventType, bsdEventNewPluginOptions, 22); + DictSet_StrLong(pDictbsdEventType, bsdEventChangerLock, 23); + DictSet_StrLong(pDictbsdEventType, bsdEventChangerUnlock, 24); + + if (!pDictbsdEventType) { return MOD_ERROR_VAL; } + if (PyModule_AddObject(m, bsdEventType, pDictbsdEventType)) { + return MOD_ERROR_VAL; + } + return MOD_SUCCESS_VAL(m); } From b961063ef95ffe64b47318c512251764ce73add6 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 14 Mar 2020 10:07:28 +0100 Subject: [PATCH 033/341] python-dir: move constants into python-dir module --- .../dird/python/pyfiles/bareos_dir_consts.py | 99 ------------------- 1 file changed, 99 deletions(-) delete mode 100644 core/src/plugins/dird/python/pyfiles/bareos_dir_consts.py diff --git a/core/src/plugins/dird/python/pyfiles/bareos_dir_consts.py b/core/src/plugins/dird/python/pyfiles/bareos_dir_consts.py deleted file mode 100644 index c48d9c7bb8c..00000000000 --- a/core/src/plugins/dird/python/pyfiles/bareos_dir_consts.py +++ /dev/null @@ -1,99 +0,0 @@ -# BAREOS - Backup Archiving REcovery Open Sourced -# -# Copyright (C) 2013-2014 Bareos GmbH & Co. KG -# -# This program is Free Software; you can redistribute it and/or -# modify it under the terms of version three of the GNU Affero General Public -# License as published by the Free Software Foundation, which is -# listed in the file LICENSE. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# Author: Marco van Wieringen -# -bJobMessageType = dict( - M_ABORT=1, - M_DEBUG=2, - M_FATAL=3, - M_ERROR=4, - M_WARNING=5, - M_INFO=6, - M_SAVED=7, - M_NOTSAVED=8, - M_SKIPPED=9, - M_MOUNT=10, - M_ERROR_TERM=11, - M_TERM=12, - M_RESTORED=13, - M_SECURITY=14, - M_ALERT=15, - M_VOLMGMT=16, -) - -brDirVariable = dict( - bDirVarJob=1, - bDirVarLevel=2, - bDirVarType=3, - bDirVarJobId=4, - bDirVarClient=5, - bDirVarNumVols=6, - bDirVarPool=7, - bDirVarStorage=8, - bDirVarWriteStorage=9, - bDirVarReadStorage=10, - bDirVarCatalog=11, - bDirVarMediaType=12, - bDirVarJobName=13, - bDirVarJobStatus=14, - bDirVarPriority=15, - bDirVarVolumeName=16, - bDirVarCatalogRes=17, - bDirVarJobErrors=18, - bDirVarJobFiles=19, - bDirVarSDJobFiles=20, - bDirVarSDErrors=21, - bDirVarFDJobStatus=22, - bDirVarSDJobStatus=23, - bDirVarPluginDir=24, - bDirVarLastRate=25, - bDirVarJobBytes=26, - bDirVarReadBytes=27, -) - -bwDirVariable = dict( - bwDirVarJobReport=1, bwDirVarVolumeName=2, bwDirVarPriority=3, bwDirVarJobLevel=4 -) - -bRCs = dict( - bRC_OK=0, - bRC_Stop=1, - bRC_Error=2, - bRC_More=3, - bRC_Term=4, - bRC_Seen=5, - bRC_Core=6, - bRC_Skip=7, - bRC_Cancel=8, -) - -bDirEventType = dict( - bDirEventJobStart=1, - bDirEventJobEnd=2, - bDirEventJobInit=3, - bDirEventJobRun=4, - bDirEventVolumePurged=5, - bDirEventNewVolume=6, - bDirEventNeedVolume=7, - bDirEventVolumeFull=8, - bDirEventRecyle=9, - bDirEventGetScratch=10, - bDirEventNewPluginOptions=11, -) From 9580dde6b75dcde78d8880fcc409c1731dc73380 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 14 Mar 2020 10:10:04 +0100 Subject: [PATCH 034/341] python-sd: move sd constants into python-sd module --- .../stored/python/pyfiles/bareos_sd_consts.py | 102 ------------------ 1 file changed, 102 deletions(-) delete mode 100644 core/src/plugins/stored/python/pyfiles/bareos_sd_consts.py diff --git a/core/src/plugins/stored/python/pyfiles/bareos_sd_consts.py b/core/src/plugins/stored/python/pyfiles/bareos_sd_consts.py deleted file mode 100644 index fbfec4ed580..00000000000 --- a/core/src/plugins/stored/python/pyfiles/bareos_sd_consts.py +++ /dev/null @@ -1,102 +0,0 @@ -# BAREOS - Backup Archiving REcovery Open Sourced -# -# Copyright (C) 2013-2014 Bareos GmbH & Co. KG -# -# This program is Free Software; you can redistribute it and/or -# modify it under the terms of version three of the GNU Affero General Public -# License as published by the Free Software Foundation, which is -# listed in the file LICENSE. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# Author: Marco van Wieringen -# -bJobMessageType = dict( - M_ABORT=1, - M_DEBUG=2, - M_FATAL=3, - M_ERROR=4, - M_WARNING=5, - M_INFO=6, - M_SAVED=7, - M_NOTSAVED=8, - M_SKIPPED=9, - M_MOUNT=10, - M_ERROR_TERM=11, - M_TERM=12, - M_RESTORED=13, - M_SECURITY=14, - M_ALERT=15, - M_VOLMGMT=16, -) - -bsdrVariable = dict( - bsdVarJob=1, - bsdVarLevel=2, - bsdVarType=3, - bsdVarJobId=4, - bsdVarClient=5, - bsdVarPool=6, - bsdVarPoolType=7, - bsdVarStorage=8, - bsdVarMediaType=9, - bsdVarJobName=10, - bsdVarJobStatus=11, - bsdVarVolumeName=12, - bsdVarJobErrors=13, - bsdVarJobFiles=14, - bsdVarJobBytes=15, - bsdVarCompatible=16, - bsdVarPluginDir=17, -) - -bsdwVariable = dict( - bsdwVarJobReport=1, bsdwVarVolumeName=2, bsdwVarPriority=3, bsdwVarJobLevel=4 -) - -bRCs = dict( - bRC_OK=0, - bRC_Stop=1, - bRC_Error=2, - bRC_More=3, - bRC_Term=4, - bRC_Seen=5, - bRC_Core=6, - bRC_Skip=7, - bRC_Cancel=8, -) - -bsdEventType = dict( - bsdEventJobStart=1, - bsdEventJobEnd=2, - bsdEventDeviceInit=3, - bsdEventDeviceMount=4, - bsdEventVolumeLoad=5, - bsdEventDeviceReserve=6, - bsdEventDeviceOpen=7, - bsdEventLabelRead=8, - bsdEventLabelVerified=9, - bsdEventLabelWrite=10, - bsdEventDeviceClose=11, - bsdEventVolumeUnload=12, - bsdEventDeviceUnmount=13, - bsdEventReadError=14, - bsdEventWriteError=15, - bsdEventDriveStatus=16, - bsdEventVolumeStatus=17, - bsdEventSetupRecordTranslation=18, - bsdEventReadRecordTranslation=19, - bsdEventWriteRecordTranslation=20, - bsdEventDeviceRelease=21, - bsdEventNewPluginOptions=22, - bsdEventChangerLock=23, - bsdEventChangerUnlock=24, -) From 851af017af7f7dd1ea009cc3cc605f64c122ebd5 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 14 Mar 2020 10:46:22 +0100 Subject: [PATCH 035/341] python plugins: move common module dicts into python_plugins_common.h --- core/src/plugins/dird/python/python-dir.h | 40 ++------------------- core/src/plugins/filed/python/python-fd.h | 42 ++-------------------- core/src/plugins/python_plugins_common.h | 39 ++++++++++++++++++++ core/src/plugins/stored/python/python-sd.h | 40 ++------------------- 4 files changed, 45 insertions(+), 116 deletions(-) diff --git a/core/src/plugins/dird/python/python-dir.h b/core/src/plugins/dird/python/python-dir.h index cbf4d72ba4c..ffa4b2b5dcc 100644 --- a/core/src/plugins/dird/python/python-dir.h +++ b/core/src/plugins/dird/python/python-dir.h @@ -117,29 +117,8 @@ MOD_INIT(bareosdir) /* module dictionaries */ - const char* bJobMessageType = "bJobMessageType"; - PyObject* pDictJobMessageType = NULL; - pDictJobMessageType = PyDict_New(); - if (!pDictJobMessageType) { return MOD_ERROR_VAL; } - DictSet_StrLong(pDictJobMessageType, M_ABORT, 1); - DictSet_StrLong(pDictJobMessageType, M_DEBUG, 2); - DictSet_StrLong(pDictJobMessageType, M_FATAL, 3); - DictSet_StrLong(pDictJobMessageType, M_ERROR, 4); - DictSet_StrLong(pDictJobMessageType, M_WARNING, 5); - DictSet_StrLong(pDictJobMessageType, M_INFO, 6); - DictSet_StrLong(pDictJobMessageType, M_SAVED, 7); - DictSet_StrLong(pDictJobMessageType, M_NOTSAVED, 8); - DictSet_StrLong(pDictJobMessageType, M_SKIPPED, 9); - DictSet_StrLong(pDictJobMessageType, M_MOUNT, 10); - DictSet_StrLong(pDictJobMessageType, M_ERROR_TERM, 11); - DictSet_StrLong(pDictJobMessageType, M_TERM, 12); - DictSet_StrLong(pDictJobMessageType, M_RESTORED, 13); - DictSet_StrLong(pDictJobMessageType, M_SECURITY, 14); - DictSet_StrLong(pDictJobMessageType, M_ALERT, 15); - DictSet_StrLong(pDictJobMessageType, M_VOLMGMT, 16); - if (PyModule_AddObject(m, bJobMessageType, pDictJobMessageType)) { - return MOD_ERROR_VAL; - } + DEFINE_bRCs_DICT(); + DEFINE_bJobMessageTypes_DICT(); const char* bDirVariable = "bDirVariable"; PyObject* pDictbDirVariable = NULL; @@ -188,21 +167,6 @@ MOD_INIT(bareosdir) return MOD_ERROR_VAL; } - const char* bRCs = "bRCs"; - PyObject* pDictbRCs = NULL; - pDictbRCs = PyDict_New(); - DictSet_StrLong(pDictbRCs, bRC_OK, 0); - DictSet_StrLong(pDictbRCs, bRC_Stop, 1); - DictSet_StrLong(pDictbRCs, bRC_Error, 2); - DictSet_StrLong(pDictbRCs, bRC_More, 3); - DictSet_StrLong(pDictbRCs, bRC_Term, 4); - DictSet_StrLong(pDictbRCs, bRC_Seen, 5); - DictSet_StrLong(pDictbRCs, bRC_Core, 6); - DictSet_StrLong(pDictbRCs, bRC_Skip, 7); - DictSet_StrLong(pDictbRCs, bRC_Cancel, 8); - if (!pDictbRCs) { return MOD_ERROR_VAL; } - if (PyModule_AddObject(m, bRCs, pDictbRCs)) { return MOD_ERROR_VAL; } - const char* bDirEvent = "bDirEvent"; PyObject* pDictbDirEvent = NULL; pDictbDirEvent = PyDict_New(); diff --git a/core/src/plugins/filed/python/python-fd.h b/core/src/plugins/filed/python/python-fd.h index f51bb22f34a..e95434e96ff 100644 --- a/core/src/plugins/filed/python/python-fd.h +++ b/core/src/plugins/filed/python/python-fd.h @@ -867,30 +867,8 @@ MOD_INIT(bareosfd) /* module dictionaries */ - const char* bJobMessageType = "bJobMessageType"; - PyObject* pDictJobMessageType = NULL; - pDictJobMessageType = PyDict_New(); - if (!pDictJobMessageType) { return MOD_ERROR_VAL; } - DictSet_StrLong(pDictJobMessageType, M_ABORT, 1); - DictSet_StrLong(pDictJobMessageType, M_DEBUG, 2); - DictSet_StrLong(pDictJobMessageType, M_FATAL, 3); - DictSet_StrLong(pDictJobMessageType, M_ERROR, 4); - DictSet_StrLong(pDictJobMessageType, M_WARNING, 5); - DictSet_StrLong(pDictJobMessageType, M_INFO, 6); - DictSet_StrLong(pDictJobMessageType, M_SAVED, 7); - DictSet_StrLong(pDictJobMessageType, M_NOTSAVED, 8); - DictSet_StrLong(pDictJobMessageType, M_SKIPPED, 9); - DictSet_StrLong(pDictJobMessageType, M_MOUNT, 10); - DictSet_StrLong(pDictJobMessageType, M_ERROR_TERM, 11); - DictSet_StrLong(pDictJobMessageType, M_TERM, 12); - DictSet_StrLong(pDictJobMessageType, M_RESTORED, 13); - DictSet_StrLong(pDictJobMessageType, M_SECURITY, 14); - DictSet_StrLong(pDictJobMessageType, M_ALERT, 15); - DictSet_StrLong(pDictJobMessageType, M_VOLMGMT, 16); - if (PyModule_AddObject(m, bJobMessageType, pDictJobMessageType)) { - return MOD_ERROR_VAL; - } - + DEFINE_bRCs_DICT(); + DEFINE_bJobMessageTypes_DICT(); const char* bVariable = "bVariable"; PyObject* pDictbVariable = NULL; @@ -957,22 +935,6 @@ MOD_INIT(bareosfd) } - const char* bRCs = "bRCs"; - PyObject* pDictbRCs = NULL; - pDictbRCs = PyDict_New(); - DictSet_StrLong(pDictbRCs, bRC_OK, 0); - DictSet_StrLong(pDictbRCs, bRC_Stop, 1); - DictSet_StrLong(pDictbRCs, bRC_Error, 2); - DictSet_StrLong(pDictbRCs, bRC_More, 3); - DictSet_StrLong(pDictbRCs, bRC_Term, 4); - DictSet_StrLong(pDictbRCs, bRC_Seen, 5); - DictSet_StrLong(pDictbRCs, bRC_Core, 6); - DictSet_StrLong(pDictbRCs, bRC_Skip, 7); - DictSet_StrLong(pDictbRCs, bRC_Cancel, 8); - if (!pDictbRCs) { return MOD_ERROR_VAL; } - if (PyModule_AddObject(m, bRCs, pDictbRCs)) { return MOD_ERROR_VAL; } - - const char* bCFs = "bCFs"; PyObject* pDictbCFs = NULL; pDictbCFs = PyDict_New(); diff --git a/core/src/plugins/python_plugins_common.h b/core/src/plugins/python_plugins_common.h index 98b047e43b7..376594a8a82 100644 --- a/core/src/plugins/python_plugins_common.h +++ b/core/src/plugins/python_plugins_common.h @@ -67,5 +67,44 @@ return MOD_ERROR_VAL; \ } +#define DEFINE_bRCs_DICT() \ + const char* bRCs = "bRCs"; \ + PyObject* pDictbRCs = NULL; \ + pDictbRCs = PyDict_New(); \ + DictSet_StrLong(pDictbRCs, bRC_OK, 0); \ + DictSet_StrLong(pDictbRCs, bRC_Stop, 1); \ + DictSet_StrLong(pDictbRCs, bRC_Error, 2); \ + DictSet_StrLong(pDictbRCs, bRC_More, 3); \ + DictSet_StrLong(pDictbRCs, bRC_Term, 4); \ + DictSet_StrLong(pDictbRCs, bRC_Seen, 5); \ + DictSet_StrLong(pDictbRCs, bRC_Core, 6); \ + DictSet_StrLong(pDictbRCs, bRC_Skip, 7); \ + DictSet_StrLong(pDictbRCs, bRC_Cancel, 8); \ + if (!pDictbRCs) { return MOD_ERROR_VAL; } \ + if (PyModule_AddObject(m, bRCs, pDictbRCs)) { return MOD_ERROR_VAL; } +#define DEFINE_bJobMessageTypes_DICT() \ + const char* bJobMessageType = "bJobMessageType"; \ + PyObject* pDictJobMessageType = NULL; \ + pDictJobMessageType = PyDict_New(); \ + if (!pDictJobMessageType) { return MOD_ERROR_VAL; } \ + DictSet_StrLong(pDictJobMessageType, M_ABORT, 1); \ + DictSet_StrLong(pDictJobMessageType, M_DEBUG, 2); \ + DictSet_StrLong(pDictJobMessageType, M_FATAL, 3); \ + DictSet_StrLong(pDictJobMessageType, M_ERROR, 4); \ + DictSet_StrLong(pDictJobMessageType, M_WARNING, 5); \ + DictSet_StrLong(pDictJobMessageType, M_INFO, 6); \ + DictSet_StrLong(pDictJobMessageType, M_SAVED, 7); \ + DictSet_StrLong(pDictJobMessageType, M_NOTSAVED, 8); \ + DictSet_StrLong(pDictJobMessageType, M_SKIPPED, 9); \ + DictSet_StrLong(pDictJobMessageType, M_MOUNT, 10); \ + DictSet_StrLong(pDictJobMessageType, M_ERROR_TERM, 11); \ + DictSet_StrLong(pDictJobMessageType, M_TERM, 12); \ + DictSet_StrLong(pDictJobMessageType, M_RESTORED, 13); \ + DictSet_StrLong(pDictJobMessageType, M_SECURITY, 14); \ + DictSet_StrLong(pDictJobMessageType, M_ALERT, 15); \ + DictSet_StrLong(pDictJobMessageType, M_VOLMGMT, 16); \ + if (PyModule_AddObject(m, bJobMessageType, pDictJobMessageType)) { \ + return MOD_ERROR_VAL; \ + } #endif // BAREOS_PYTHON_PLUGINS_COMMON_H_ diff --git a/core/src/plugins/stored/python/python-sd.h b/core/src/plugins/stored/python/python-sd.h index 060aedabba4..fe07cf1b60c 100644 --- a/core/src/plugins/stored/python/python-sd.h +++ b/core/src/plugins/stored/python/python-sd.h @@ -116,29 +116,8 @@ MOD_INIT(bareossd) } /* module dictionaries */ - const char* bJobMessageType = "bJobMessageType"; - PyObject* pDictJobMessageType = NULL; - pDictJobMessageType = PyDict_New(); - if (!pDictJobMessageType) { return MOD_ERROR_VAL; } - DictSet_StrLong(pDictJobMessageType, M_ABORT, 1); - DictSet_StrLong(pDictJobMessageType, M_DEBUG, 2); - DictSet_StrLong(pDictJobMessageType, M_FATAL, 3); - DictSet_StrLong(pDictJobMessageType, M_ERROR, 4); - DictSet_StrLong(pDictJobMessageType, M_WARNING, 5); - DictSet_StrLong(pDictJobMessageType, M_INFO, 6); - DictSet_StrLong(pDictJobMessageType, M_SAVED, 7); - DictSet_StrLong(pDictJobMessageType, M_NOTSAVED, 8); - DictSet_StrLong(pDictJobMessageType, M_SKIPPED, 9); - DictSet_StrLong(pDictJobMessageType, M_MOUNT, 10); - DictSet_StrLong(pDictJobMessageType, M_ERROR_TERM, 11); - DictSet_StrLong(pDictJobMessageType, M_TERM, 12); - DictSet_StrLong(pDictJobMessageType, M_RESTORED, 13); - DictSet_StrLong(pDictJobMessageType, M_SECURITY, 14); - DictSet_StrLong(pDictJobMessageType, M_ALERT, 15); - DictSet_StrLong(pDictJobMessageType, M_VOLMGMT, 16); - if (PyModule_AddObject(m, bJobMessageType, pDictJobMessageType)) { - return MOD_ERROR_VAL; - } + DEFINE_bRCs_DICT(); + DEFINE_bJobMessageTypes_DICT(); const char* bsdVariable = "bsdVariable"; PyObject* pDictsdVariable = NULL; @@ -177,21 +156,6 @@ MOD_INIT(bareossd) return MOD_ERROR_VAL; } - const char* bRCs = "bRCs"; - PyObject* pDictbRCs = NULL; - pDictbRCs = PyDict_New(); - DictSet_StrLong(pDictbRCs, bRC_OK, 0); - DictSet_StrLong(pDictbRCs, bRC_Stop, 1); - DictSet_StrLong(pDictbRCs, bRC_Error, 2); - DictSet_StrLong(pDictbRCs, bRC_More, 3); - DictSet_StrLong(pDictbRCs, bRC_Term, 4); - DictSet_StrLong(pDictbRCs, bRC_Seen, 5); - DictSet_StrLong(pDictbRCs, bRC_Core, 6); - DictSet_StrLong(pDictbRCs, bRC_Skip, 7); - DictSet_StrLong(pDictbRCs, bRC_Cancel, 8); - if (!pDictbRCs) { return MOD_ERROR_VAL; } - if (PyModule_AddObject(m, bRCs, pDictbRCs)) { return MOD_ERROR_VAL; } - const char* bsdEventType = "bsdEventType"; PyObject* pDictbsdEventType = NULL; From d2a6b591d22a8cccac812f0ec3e3f7b6b9bbbdbe Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 14 Mar 2020 19:32:58 +0100 Subject: [PATCH 036/341] python modules: define constants both in dictionary and as module constant --- core/src/plugins/dird/python/python-dir.h | 84 ++++---- .../dird/python/test/bareosdir_test.py | 1 + .../plugins/dird/python/test/bareosfd_test.py | 94 -------- core/src/plugins/filed/python/python-fd.h | 200 +++++++++--------- .../filed/python/test/bareosfd_test.py | 20 +- core/src/plugins/python_plugins_common.h | 89 +++++--- core/src/plugins/stored/python/python-sd.h | 90 ++++---- .../stored/python/test/bareossd_test.py | 1 + 8 files changed, 262 insertions(+), 317 deletions(-) delete mode 100644 core/src/plugins/dird/python/test/bareosfd_test.py diff --git a/core/src/plugins/dird/python/python-dir.h b/core/src/plugins/dird/python/python-dir.h index ffa4b2b5dcc..216abb7e766 100644 --- a/core/src/plugins/dird/python/python-dir.h +++ b/core/src/plugins/dird/python/python-dir.h @@ -124,33 +124,33 @@ MOD_INIT(bareosdir) PyObject* pDictbDirVariable = NULL; pDictbDirVariable = PyDict_New(); if (!pDictbDirVariable) { return MOD_ERROR_VAL; } - DictSet_StrLong(pDictbDirVariable, bDirVarJob, 1); - DictSet_StrLong(pDictbDirVariable, bDirVarLevel, 2); - DictSet_StrLong(pDictbDirVariable, bDirVarType, 3); - DictSet_StrLong(pDictbDirVariable, bDirVarJobId, 4); - DictSet_StrLong(pDictbDirVariable, bDirVarClient, 5); - DictSet_StrLong(pDictbDirVariable, bDirVarNumVols, 6); - DictSet_StrLong(pDictbDirVariable, bDirVarPool, 7); - DictSet_StrLong(pDictbDirVariable, bDirVarStorage, 8); - DictSet_StrLong(pDictbDirVariable, bDirVarWriteStorage, 9); - DictSet_StrLong(pDictbDirVariable, bDirVarReadStorage, 10); - DictSet_StrLong(pDictbDirVariable, bDirVarCatalog, 11); - DictSet_StrLong(pDictbDirVariable, bDirVarMediaType, 12); - DictSet_StrLong(pDictbDirVariable, bDirVarJobName, 13); - DictSet_StrLong(pDictbDirVariable, bDirVarJobStatus, 14); - DictSet_StrLong(pDictbDirVariable, bDirVarPriority, 15); - DictSet_StrLong(pDictbDirVariable, bDirVarVolumeName, 16); - DictSet_StrLong(pDictbDirVariable, bDirVarCatalogRes, 17); - DictSet_StrLong(pDictbDirVariable, bDirVarJobErrors, 18); - DictSet_StrLong(pDictbDirVariable, bDirVarJobFiles, 19); - DictSet_StrLong(pDictbDirVariable, bDirVarSDJobFiles, 20); - DictSet_StrLong(pDictbDirVariable, bDirVarSDErrors, 21); - DictSet_StrLong(pDictbDirVariable, bDirVarFDJobStatus, 22); - DictSet_StrLong(pDictbDirVariable, bDirVarSDJobStatus, 23); - DictSet_StrLong(pDictbDirVariable, bDirVarPluginDir, 24); - DictSet_StrLong(pDictbDirVariable, bDirVarLastRate, 25); - DictSet_StrLong(pDictbDirVariable, bDirVarJobBytes, 26); - DictSet_StrLong(pDictbDirVariable, bDirVarReadBytes, 27); + ConstSet_StrLong(pDictbDirVariable, bDirVarJob, 1); + ConstSet_StrLong(pDictbDirVariable, bDirVarLevel, 2); + ConstSet_StrLong(pDictbDirVariable, bDirVarType, 3); + ConstSet_StrLong(pDictbDirVariable, bDirVarJobId, 4); + ConstSet_StrLong(pDictbDirVariable, bDirVarClient, 5); + ConstSet_StrLong(pDictbDirVariable, bDirVarNumVols, 6); + ConstSet_StrLong(pDictbDirVariable, bDirVarPool, 7); + ConstSet_StrLong(pDictbDirVariable, bDirVarStorage, 8); + ConstSet_StrLong(pDictbDirVariable, bDirVarWriteStorage, 9); + ConstSet_StrLong(pDictbDirVariable, bDirVarReadStorage, 10); + ConstSet_StrLong(pDictbDirVariable, bDirVarCatalog, 11); + ConstSet_StrLong(pDictbDirVariable, bDirVarMediaType, 12); + ConstSet_StrLong(pDictbDirVariable, bDirVarJobName, 13); + ConstSet_StrLong(pDictbDirVariable, bDirVarJobStatus, 14); + ConstSet_StrLong(pDictbDirVariable, bDirVarPriority, 15); + ConstSet_StrLong(pDictbDirVariable, bDirVarVolumeName, 16); + ConstSet_StrLong(pDictbDirVariable, bDirVarCatalogRes, 17); + ConstSet_StrLong(pDictbDirVariable, bDirVarJobErrors, 18); + ConstSet_StrLong(pDictbDirVariable, bDirVarJobFiles, 19); + ConstSet_StrLong(pDictbDirVariable, bDirVarSDJobFiles, 20); + ConstSet_StrLong(pDictbDirVariable, bDirVarSDErrors, 21); + ConstSet_StrLong(pDictbDirVariable, bDirVarFDJobStatus, 22); + ConstSet_StrLong(pDictbDirVariable, bDirVarSDJobStatus, 23); + ConstSet_StrLong(pDictbDirVariable, bDirVarPluginDir, 24); + ConstSet_StrLong(pDictbDirVariable, bDirVarLastRate, 25); + ConstSet_StrLong(pDictbDirVariable, bDirVarJobBytes, 26); + ConstSet_StrLong(pDictbDirVariable, bDirVarReadBytes, 27); if (PyModule_AddObject(m, bDirVariable, pDictbDirVariable)) { return MOD_ERROR_VAL; } @@ -159,10 +159,10 @@ MOD_INIT(bareosdir) PyObject* pDictbwDirVariable = NULL; pDictbwDirVariable = PyDict_New(); if (!pDictbwDirVariable) { return MOD_ERROR_VAL; } - DictSet_StrLong(pDictbwDirVariable, bwDirVarJobReport, 1); - DictSet_StrLong(pDictbwDirVariable, bwDirVarVolumeName, 2); - DictSet_StrLong(pDictbwDirVariable, bwDirVarPriority, 3); - DictSet_StrLong(pDictbwDirVariable, bwDirVarJobLevel, 4); + ConstSet_StrLong(pDictbwDirVariable, bwDirVarJobReport, 1); + ConstSet_StrLong(pDictbwDirVariable, bwDirVarVolumeName, 2); + ConstSet_StrLong(pDictbwDirVariable, bwDirVarPriority, 3); + ConstSet_StrLong(pDictbwDirVariable, bwDirVarJobLevel, 4); if (PyModule_AddObject(m, bwDirVariable, pDictbwDirVariable)) { return MOD_ERROR_VAL; } @@ -170,17 +170,17 @@ MOD_INIT(bareosdir) const char* bDirEvent = "bDirEvent"; PyObject* pDictbDirEvent = NULL; pDictbDirEvent = PyDict_New(); - DictSet_StrLong(pDictbDirEvent, bEventJobStart, 1); - DictSet_StrLong(pDictbDirEvent, bEventJobEnd, 2); - DictSet_StrLong(pDictbDirEvent, bDirEventJobInit, 3); - DictSet_StrLong(pDictbDirEvent, bDirEventJobRun, 4); - DictSet_StrLong(pDictbDirEvent, bDirEventVolumePurged, 5); - DictSet_StrLong(pDictbDirEvent, bDirEventNewVolume, 6); - DictSet_StrLong(pDictbDirEvent, bDirEventNeedVolume, 7); - DictSet_StrLong(pDictbDirEvent, bDirEventVolumeFull, 8); - DictSet_StrLong(pDictbDirEvent, bDirEventRecyle, 9); - DictSet_StrLong(pDictbDirEvent, bDirEventGetScratch, 10); - DictSet_StrLong(pDictbDirEvent, bDirEventNewPluginOptions, 11); + ConstSet_StrLong(pDictbDirEvent, bEventJobStart, 1); + ConstSet_StrLong(pDictbDirEvent, bEventJobEnd, 2); + ConstSet_StrLong(pDictbDirEvent, bDirEventJobInit, 3); + ConstSet_StrLong(pDictbDirEvent, bDirEventJobRun, 4); + ConstSet_StrLong(pDictbDirEvent, bDirEventVolumePurged, 5); + ConstSet_StrLong(pDictbDirEvent, bDirEventNewVolume, 6); + ConstSet_StrLong(pDictbDirEvent, bDirEventNeedVolume, 7); + ConstSet_StrLong(pDictbDirEvent, bDirEventVolumeFull, 8); + ConstSet_StrLong(pDictbDirEvent, bDirEventRecyle, 9); + ConstSet_StrLong(pDictbDirEvent, bDirEventGetScratch, 10); + ConstSet_StrLong(pDictbDirEvent, bDirEventNewPluginOptions, 11); if (!pDictbDirEvent) { return MOD_ERROR_VAL; } if (PyModule_AddObject(m, bDirEvent, pDictbDirEvent)) { return MOD_ERROR_VAL; diff --git a/core/src/plugins/dird/python/test/bareosdir_test.py b/core/src/plugins/dird/python/test/bareosdir_test.py index e28951bbf60..8b1e7aeba76 100644 --- a/core/src/plugins/dird/python/test/bareosdir_test.py +++ b/core/src/plugins/dird/python/test/bareosdir_test.py @@ -2,6 +2,7 @@ import bareosdir import time +print help(bareosdir) class TestBareosFd(unittest.TestCase): diff --git a/core/src/plugins/dird/python/test/bareosfd_test.py b/core/src/plugins/dird/python/test/bareosfd_test.py deleted file mode 100644 index 37fe3b04c2f..00000000000 --- a/core/src/plugins/dird/python/test/bareosfd_test.py +++ /dev/null @@ -1,94 +0,0 @@ -import unittest -import bareosfd -import time - - -class TestBareosFd(unittest.TestCase): - - def test_SetValue(self): - bareosfd.SetValue(1, 123) - - def test_DebugMessage(self): - bareosfd.DebugMessage(100,"testdebugmessage\n") - - def test_RestoreObject(self): - test_RestoreObject = bareosfd.RestoreObject() - self.assertEqual( - 'RestoreObject(object_name="", object="", plugin_name="", object_type=0, object_len=0, object_full_len=0, object_index=0, object_compression=0, stream=0, jobid=0)', - str(test_RestoreObject), - ) - - #r2 = bareosfd.RestoreObject() - #r2.object_name="this is a very long object name" - #r2.object="123456780" - ##r2.plugin_name="this is a plugin name" - #r2.object_type=3 - #r2.object_len=111111 - #r2.object_full_len=11111111 - #r2.object_index=1234 - #r2.object_compression=1 - #r2.stream=4 - #r2.jobid=123123 - #print (r2) - #self.assertEqual( - # 'RestoreObject(object_name="this is a very long object name", object="", plugin_name="", object_type=3, object_len=111111, object_full_len=11111111, object_index=1234, object_compression=1, stream=4, jobid=123123)', - # str(test_RestoreObject), - #) - - - - def test_StatPacket(self): - timestamp = time.time() - test_StatPacket = bareosfd.StatPacket() - - # check that the initialization of timestamps from current time stamp works - self.assertAlmostEqual(test_StatPacket.atime, timestamp, delta=1) - self.assertAlmostEqual(test_StatPacket.mtime, timestamp, delta=1) - self.assertAlmostEqual(test_StatPacket.ctime, timestamp, delta=1) - - # set fixed values for comparison - test_StatPacket.atime=999 - test_StatPacket.mtime=1000 - test_StatPacket.ctime=1001 - self.assertEqual( - "StatPacket(dev=0, ino=0, mode=0700, nlink=0, uid=0, gid=0, rdev=0, size=-1, atime=999, mtime=1000, ctime=1001, blksize=4096, blocks=1)", - str(test_StatPacket), - ) - sp2 = bareosfd.StatPacket(dev=0, ino=0, mode=0700, nlink=0, uid=0, gid=0, rdev=0, size=-1, atime=1, mtime=1, ctime=1, blksize=4096, blocks=1) - self.assertEqual('StatPacket(dev=0, ino=0, mode=0700, nlink=0, uid=0, gid=0, rdev=0, size=-1, atime=1, mtime=1, ctime=1, blksize=4096, blocks=1)', str(sp2)) - - def test_SavePacket(self): - test_SavePacket = bareosfd.SavePacket() - self.assertEqual( - 'SavePacket(fname="", link="", type=0, flags=, no_read=0, portable=0, accurate_found=0, cmd="", save_time=0, delta_seq=0, object_name="", object="", object_len=0, object_index=0)', - str(test_SavePacket), - ) - - def test_RestorePacket(self): - test_RestorePacket = bareosfd.RestorePacket() - self.assertEqual( - 'RestorePacket(stream=0, data_stream=0, type=0, file_index=0, linkFI=0, uid=0, statp="", attrEx="", ofname="", olname="", where="", RegexWhere="", replace=0, create_status=0)', - str(test_RestorePacket), - ) - - def test_IoPacket(self): - test_IoPacket = bareosfd.IoPacket() - self.assertEqual( - 'IoPacket(func=0, count=0, flags=0, mode=0000, buf="", fname="", status=0, io_errno=0, lerror=0, whence=0, offset=0, win32=0)', - str(test_IoPacket), - ) - - def test_AclPacket(self): - test_AclPacket = bareosfd.AclPacket() - self.assertEqual('AclPacket(fname="", content="")', str(test_AclPacket)) - - - def test_XattrPacket(self): - test_XattrPacket = bareosfd.XattrPacket() - self.assertEqual( - 'XattrPacket(fname="", name="", value="")', str(test_XattrPacket) - ) - - -if __name__ == "__main__": - unittest.main() diff --git a/core/src/plugins/filed/python/python-fd.h b/core/src/plugins/filed/python/python-fd.h index e95434e96ff..4f2778af614 100644 --- a/core/src/plugins/filed/python/python-fd.h +++ b/core/src/plugins/filed/python/python-fd.h @@ -874,25 +874,25 @@ MOD_INIT(bareosfd) PyObject* pDictbVariable = NULL; pDictbVariable = PyDict_New(); if (!pDictbVariable) { return MOD_ERROR_VAL; } - DictSet_StrLong(pDictbVariable, bVarJobId, 1); - DictSet_StrLong(pDictbVariable, bVarFDName, 2); - DictSet_StrLong(pDictbVariable, bVarLevel, 3); - DictSet_StrLong(pDictbVariable, bVarType, 4); - DictSet_StrLong(pDictbVariable, bVarClient, 5); - DictSet_StrLong(pDictbVariable, bVarJobName, 6); - DictSet_StrLong(pDictbVariable, bVarJobStatus, 7); - DictSet_StrLong(pDictbVariable, bVarSinceTime, 8); - DictSet_StrLong(pDictbVariable, bVarAccurate, 9); - DictSet_StrLong(pDictbVariable, bVarFileSeen, 10); - DictSet_StrLong(pDictbVariable, bVarVssClient, 11); - DictSet_StrLong(pDictbVariable, bVarWorkingDir, 12); - DictSet_StrLong(pDictbVariable, bVarWhere, 13); - DictSet_StrLong(pDictbVariable, bVarRegexWhere, 14); - DictSet_StrLong(pDictbVariable, bVarExePath, 15); - DictSet_StrLong(pDictbVariable, bVarVersion, 16); - DictSet_StrLong(pDictbVariable, bVarDistName, 17); - DictSet_StrLong(pDictbVariable, bVarPrevJobName, 18); - DictSet_StrLong(pDictbVariable, bVarPrefixLinks, 19); + ConstSet_StrLong(pDictbVariable, bVarJobId, 1); + ConstSet_StrLong(pDictbVariable, bVarFDName, 2); + ConstSet_StrLong(pDictbVariable, bVarLevel, 3); + ConstSet_StrLong(pDictbVariable, bVarType, 4); + ConstSet_StrLong(pDictbVariable, bVarClient, 5); + ConstSet_StrLong(pDictbVariable, bVarJobName, 6); + ConstSet_StrLong(pDictbVariable, bVarJobStatus, 7); + ConstSet_StrLong(pDictbVariable, bVarSinceTime, 8); + ConstSet_StrLong(pDictbVariable, bVarAccurate, 9); + ConstSet_StrLong(pDictbVariable, bVarFileSeen, 10); + ConstSet_StrLong(pDictbVariable, bVarVssClient, 11); + ConstSet_StrLong(pDictbVariable, bVarWorkingDir, 12); + ConstSet_StrLong(pDictbVariable, bVarWhere, 13); + ConstSet_StrLong(pDictbVariable, bVarRegexWhere, 14); + ConstSet_StrLong(pDictbVariable, bVarExePath, 15); + ConstSet_StrLong(pDictbVariable, bVarVersion, 16); + ConstSet_StrLong(pDictbVariable, bVarDistName, 17); + ConstSet_StrLong(pDictbVariable, bVarPrevJobName, 18); + ConstSet_StrLong(pDictbVariable, bVarPrefixLinks, 19); if (PyModule_AddObject(m, bVariable, pDictbVariable)) { return MOD_ERROR_VAL; } @@ -901,34 +901,34 @@ MOD_INIT(bareosfd) const char* bFileType = "bFileType"; PyObject* pDictbFileType = NULL; pDictbFileType = PyDict_New(); - DictSet_StrLong(pDictbFileType, FT_LNKSAVED, 1); - DictSet_StrLong(pDictbFileType, FT_REGE, 2); - DictSet_StrLong(pDictbFileType, FT_REG, 3); - DictSet_StrLong(pDictbFileType, FT_LNK, 4); - DictSet_StrLong(pDictbFileType, FT_DIREND, 5); - DictSet_StrLong(pDictbFileType, FT_SPEC, 6); - DictSet_StrLong(pDictbFileType, FT_NOACCESS, 7); - DictSet_StrLong(pDictbFileType, FT_NOFOLLOW, 8); - DictSet_StrLong(pDictbFileType, FT_NOSTAT, 9); - DictSet_StrLong(pDictbFileType, FT_NOCHG, 10); - DictSet_StrLong(pDictbFileType, FT_DIRNOCHG, 11); - DictSet_StrLong(pDictbFileType, FT_ISARCH, 12); - DictSet_StrLong(pDictbFileType, FT_NORECURSE, 13); - DictSet_StrLong(pDictbFileType, FT_NOFSCHG, 14); - DictSet_StrLong(pDictbFileType, FT_NOOPEN, 15); - DictSet_StrLong(pDictbFileType, FT_RAW, 16); - DictSet_StrLong(pDictbFileType, FT_FIFO, 17); - DictSet_StrLong(pDictbFileType, FT_DIRBEGIN, 18); - DictSet_StrLong(pDictbFileType, FT_INVALIDFS, 19); - DictSet_StrLong(pDictbFileType, FT_INVALIDDT, 20); - DictSet_StrLong(pDictbFileType, FT_REPARSE, 21); - DictSet_StrLong(pDictbFileType, FT_PLUGIN, 22); - DictSet_StrLong(pDictbFileType, FT_DELETED, 23); - DictSet_StrLong(pDictbFileType, FT_BASE, 24); - DictSet_StrLong(pDictbFileType, FT_RESTORE_FIRST, 25); - DictSet_StrLong(pDictbFileType, FT_JUNCTION, 26); - DictSet_StrLong(pDictbFileType, FT_PLUGIN_CONFIG, 27); - DictSet_StrLong(pDictbFileType, FT_PLUGIN_CONFIG_FILLED, 28); + ConstSet_StrLong(pDictbFileType, FT_LNKSAVED, 1); + ConstSet_StrLong(pDictbFileType, FT_REGE, 2); + ConstSet_StrLong(pDictbFileType, FT_REG, 3); + ConstSet_StrLong(pDictbFileType, FT_LNK, 4); + ConstSet_StrLong(pDictbFileType, FT_DIREND, 5); + ConstSet_StrLong(pDictbFileType, FT_SPEC, 6); + ConstSet_StrLong(pDictbFileType, FT_NOACCESS, 7); + ConstSet_StrLong(pDictbFileType, FT_NOFOLLOW, 8); + ConstSet_StrLong(pDictbFileType, FT_NOSTAT, 9); + ConstSet_StrLong(pDictbFileType, FT_NOCHG, 10); + ConstSet_StrLong(pDictbFileType, FT_DIRNOCHG, 11); + ConstSet_StrLong(pDictbFileType, FT_ISARCH, 12); + ConstSet_StrLong(pDictbFileType, FT_NORECURSE, 13); + ConstSet_StrLong(pDictbFileType, FT_NOFSCHG, 14); + ConstSet_StrLong(pDictbFileType, FT_NOOPEN, 15); + ConstSet_StrLong(pDictbFileType, FT_RAW, 16); + ConstSet_StrLong(pDictbFileType, FT_FIFO, 17); + ConstSet_StrLong(pDictbFileType, FT_DIRBEGIN, 18); + ConstSet_StrLong(pDictbFileType, FT_INVALIDFS, 19); + ConstSet_StrLong(pDictbFileType, FT_INVALIDDT, 20); + ConstSet_StrLong(pDictbFileType, FT_REPARSE, 21); + ConstSet_StrLong(pDictbFileType, FT_PLUGIN, 22); + ConstSet_StrLong(pDictbFileType, FT_DELETED, 23); + ConstSet_StrLong(pDictbFileType, FT_BASE, 24); + ConstSet_StrLong(pDictbFileType, FT_RESTORE_FIRST, 25); + ConstSet_StrLong(pDictbFileType, FT_JUNCTION, 26); + ConstSet_StrLong(pDictbFileType, FT_PLUGIN_CONFIG, 27); + ConstSet_StrLong(pDictbFileType, FT_PLUGIN_CONFIG_FILLED, 28); if (!pDictbFileType) { return MOD_ERROR_VAL; } if (PyModule_AddObject(m, bFileType, pDictbFileType)) { return MOD_ERROR_VAL; @@ -938,48 +938,48 @@ MOD_INIT(bareosfd) const char* bCFs = "bCFs"; PyObject* pDictbCFs = NULL; pDictbCFs = PyDict_New(); - DictSet_StrLong(pDictbCFs, CF_SKIP, 1); - DictSet_StrLong(pDictbCFs, CF_ERROR, 2); - DictSet_StrLong(pDictbCFs, CF_EXTRACT, 3); - DictSet_StrLong(pDictbCFs, CF_CREATED, 4); - DictSet_StrLong(pDictbCFs, CF_CORE, 5); + ConstSet_StrLong(pDictbCFs, CF_SKIP, 1); + ConstSet_StrLong(pDictbCFs, CF_ERROR, 2); + ConstSet_StrLong(pDictbCFs, CF_EXTRACT, 3); + ConstSet_StrLong(pDictbCFs, CF_CREATED, 4); + ConstSet_StrLong(pDictbCFs, CF_CORE, 5); if (!pDictbCFs) { return MOD_ERROR_VAL; } if (PyModule_AddObject(m, bCFs, pDictbCFs)) { return MOD_ERROR_VAL; } const char* bEventType = "bEventType"; PyObject* pDictbEventType = NULL; pDictbEventType = PyDict_New(); - DictSet_StrLong(pDictbEventType, bEventJobStart, 1); - DictSet_StrLong(pDictbEventType, bEventJobEnd, 2); - DictSet_StrLong(pDictbEventType, bEventStartBackupJob, 3); - DictSet_StrLong(pDictbEventType, bEventEndBackupJob, 4); - DictSet_StrLong(pDictbEventType, bEventStartRestoreJob, 5); - DictSet_StrLong(pDictbEventType, bEventEndRestoreJob, 6); - DictSet_StrLong(pDictbEventType, bEventStartVerifyJob, 7); - DictSet_StrLong(pDictbEventType, bEventEndVerifyJob, 8); - DictSet_StrLong(pDictbEventType, bEventBackupCommand, 9); - DictSet_StrLong(pDictbEventType, bEventRestoreCommand, 10); - DictSet_StrLong(pDictbEventType, bEventEstimateCommand, 11); - DictSet_StrLong(pDictbEventType, bEventLevel, 12); - DictSet_StrLong(pDictbEventType, bEventSince, 13); - DictSet_StrLong(pDictbEventType, bEventCancelCommand, 14); - DictSet_StrLong(pDictbEventType, bEventRestoreObject, 15); - DictSet_StrLong(pDictbEventType, bEventEndFileSet, 16); - DictSet_StrLong(pDictbEventType, bEventPluginCommand, 17); - DictSet_StrLong(pDictbEventType, bEventOptionPlugin, 18); - DictSet_StrLong(pDictbEventType, bEventHandleBackupFile, 19); - DictSet_StrLong(pDictbEventType, bEventNewPluginOptions, 20); - DictSet_StrLong(pDictbEventType, bEventVssInitializeForBackup, 21); - DictSet_StrLong(pDictbEventType, bEventVssInitializeForRestore, 22); - DictSet_StrLong(pDictbEventType, bEventVssSetBackupState, 23); - DictSet_StrLong(pDictbEventType, bEventVssPrepareForBackup, 24); - DictSet_StrLong(pDictbEventType, bEventVssBackupAddComponents, 25); - DictSet_StrLong(pDictbEventType, bEventVssPrepareSnapshot, 26); - DictSet_StrLong(pDictbEventType, bEventVssCreateSnapshots, 27); - DictSet_StrLong(pDictbEventType, bEventVssRestoreLoadComponentMetadata, 28); - DictSet_StrLong(pDictbEventType, bEventVssRestoreSetComponentsSelected, 29); - DictSet_StrLong(pDictbEventType, bEventVssCloseRestore, 30); - DictSet_StrLong(pDictbEventType, bEventVssBackupComplete, 31); + ConstSet_StrLong(pDictbEventType, bEventJobStart, 1); + ConstSet_StrLong(pDictbEventType, bEventJobEnd, 2); + ConstSet_StrLong(pDictbEventType, bEventStartBackupJob, 3); + ConstSet_StrLong(pDictbEventType, bEventEndBackupJob, 4); + ConstSet_StrLong(pDictbEventType, bEventStartRestoreJob, 5); + ConstSet_StrLong(pDictbEventType, bEventEndRestoreJob, 6); + ConstSet_StrLong(pDictbEventType, bEventStartVerifyJob, 7); + ConstSet_StrLong(pDictbEventType, bEventEndVerifyJob, 8); + ConstSet_StrLong(pDictbEventType, bEventBackupCommand, 9); + ConstSet_StrLong(pDictbEventType, bEventRestoreCommand, 10); + ConstSet_StrLong(pDictbEventType, bEventEstimateCommand, 11); + ConstSet_StrLong(pDictbEventType, bEventLevel, 12); + ConstSet_StrLong(pDictbEventType, bEventSince, 13); + ConstSet_StrLong(pDictbEventType, bEventCancelCommand, 14); + ConstSet_StrLong(pDictbEventType, bEventRestoreObject, 15); + ConstSet_StrLong(pDictbEventType, bEventEndFileSet, 16); + ConstSet_StrLong(pDictbEventType, bEventPluginCommand, 17); + ConstSet_StrLong(pDictbEventType, bEventOptionPlugin, 18); + ConstSet_StrLong(pDictbEventType, bEventHandleBackupFile, 19); + ConstSet_StrLong(pDictbEventType, bEventNewPluginOptions, 20); + ConstSet_StrLong(pDictbEventType, bEventVssInitializeForBackup, 21); + ConstSet_StrLong(pDictbEventType, bEventVssInitializeForRestore, 22); + ConstSet_StrLong(pDictbEventType, bEventVssSetBackupState, 23); + ConstSet_StrLong(pDictbEventType, bEventVssPrepareForBackup, 24); + ConstSet_StrLong(pDictbEventType, bEventVssBackupAddComponents, 25); + ConstSet_StrLong(pDictbEventType, bEventVssPrepareSnapshot, 26); + ConstSet_StrLong(pDictbEventType, bEventVssCreateSnapshots, 27); + ConstSet_StrLong(pDictbEventType, bEventVssRestoreLoadComponentMetadata, 28); + ConstSet_StrLong(pDictbEventType, bEventVssRestoreSetComponentsSelected, 29); + ConstSet_StrLong(pDictbEventType, bEventVssCloseRestore, 30); + ConstSet_StrLong(pDictbEventType, bEventVssBackupComplete, 31); if (!pDictbEventType) { return MOD_ERROR_VAL; } if (PyModule_AddObject(m, bEventType, pDictbEventType)) { return MOD_ERROR_VAL; @@ -989,11 +989,11 @@ MOD_INIT(bareosfd) const char* bIOPS = "bIOPS"; PyObject* pDictbIOPS = NULL; pDictbIOPS = PyDict_New(); - DictSet_StrLong(pDictbIOPS, IO_OPEN, 1); - DictSet_StrLong(pDictbIOPS, IO_READ, 2); - DictSet_StrLong(pDictbIOPS, IO_WRITE, 3); - DictSet_StrLong(pDictbIOPS, IO_CLOSE, 4); - DictSet_StrLong(pDictbIOPS, IO_SEEK, 5); + ConstSet_StrLong(pDictbIOPS, IO_OPEN, 1); + ConstSet_StrLong(pDictbIOPS, IO_READ, 2); + ConstSet_StrLong(pDictbIOPS, IO_WRITE, 3); + ConstSet_StrLong(pDictbIOPS, IO_CLOSE, 4); + ConstSet_StrLong(pDictbIOPS, IO_SEEK, 5); if (!pDictbIOPS) { return MOD_ERROR_VAL; } if (PyModule_AddObject(m, bIOPS, pDictbIOPS)) { return MOD_ERROR_VAL; } @@ -1001,18 +1001,18 @@ MOD_INIT(bareosfd) const char* bLevels = "bLevels"; PyObject* pDictbLevels = NULL; pDictbLevels = PyDict_New(); - DictSet_StrStr(pDictbLevels, L_FULL, "F"); - DictSet_StrStr(pDictbLevels, L_INCREMENTAL, "I"); - DictSet_StrStr(pDictbLevels, L_DIFFERENTIAL, "D"); - DictSet_StrStr(pDictbLevels, L_SINCE, "S"); - DictSet_StrStr(pDictbLevels, L_VERIFY_CATALOG, "C"); - DictSet_StrStr(pDictbLevels, L_VERIFY_INIT, "V"); - DictSet_StrStr(pDictbLevels, L_VERIFY_VOLUME_TO_CATALOG, "O"); - DictSet_StrStr(pDictbLevels, L_VERIFY_DISK_TO_CATALOG, "d"); - DictSet_StrStr(pDictbLevels, L_VERIFY_DATA, "A"); - DictSet_StrStr(pDictbLevels, L_BASE, "B"); - DictSet_StrStr(pDictbLevels, L_NONE, " "); - DictSet_StrStr(pDictbLevels, L_VIRTUAL_FULL, "f"); + ConstSet_StrStr(pDictbLevels, L_FULL, "F"); + ConstSet_StrStr(pDictbLevels, L_INCREMENTAL, "I"); + ConstSet_StrStr(pDictbLevels, L_DIFFERENTIAL, "D"); + ConstSet_StrStr(pDictbLevels, L_SINCE, "S"); + ConstSet_StrStr(pDictbLevels, L_VERIFY_CATALOG, "C"); + ConstSet_StrStr(pDictbLevels, L_VERIFY_INIT, "V"); + ConstSet_StrStr(pDictbLevels, L_VERIFY_VOLUME_TO_CATALOG, "O"); + ConstSet_StrStr(pDictbLevels, L_VERIFY_DISK_TO_CATALOG, "d"); + ConstSet_StrStr(pDictbLevels, L_VERIFY_DATA, "A"); + ConstSet_StrStr(pDictbLevels, L_BASE, "B"); + ConstSet_StrStr(pDictbLevels, L_NONE, " "); + ConstSet_StrStr(pDictbLevels, L_VIRTUAL_FULL, "f"); if (!pDictbLevels) { return MOD_ERROR_VAL; } if (PyModule_AddObject(m, bLevels, pDictbLevels)) { return MOD_ERROR_VAL; } diff --git a/core/src/plugins/filed/python/test/bareosfd_test.py b/core/src/plugins/filed/python/test/bareosfd_test.py index e56d43fb003..f148f326dc1 100644 --- a/core/src/plugins/filed/python/test/bareosfd_test.py +++ b/core/src/plugins/filed/python/test/bareosfd_test.py @@ -1,7 +1,8 @@ import unittest import bareosfd import time -# print dir(bareosfd) +import types +#print dir(bareosfd) # print "bareosfd.bJobMessageType:", str( bareosfd.bJobMessageType) # print "bareosfd.bVariable:", str( bareosfd.bVariable) # print "bareosfd.bEventType:", str( bareosfd.bEventType) @@ -15,8 +16,23 @@ class TestBareosFd(unittest.TestCase): + def test_ModuleDicts(self): + help (bareosfd) + print bareosfd.bCFs + print bareosfd.CF_ERROR + + # print bCFs + # bEventType + # bFileType + # bFuncs + # bIOPS + # bJobMessageType + # bLevels + # bRCs + # bVariable + def test_bJobMessageType(self): - bareosfd.DebugMessage( bareosfd.bJobMessageType['M_INFO'], "This is a Job message") + # bareosfd.DebugMessage( bareosfd.bJobMessageType['M_INFO'], "This is a Job message") self.assertEqual(str(bareosfd.bJobMessageType), """{'M_MOUNT': 10L, 'M_SECURITY': 14L, 'M_DEBUG': 2L, 'M_WARNING': 5L, 'M_SAVED': 7L, 'M_TERM': 12L, 'M_ABORT': 1L, 'M_INFO': 6L, 'M_ERROR': 4L, 'M_FATAL': 3L, 'M_NOTSAVED': 8L, 'M_RESTORED': 13L, 'M_ERROR_TERM': 11L, 'M_ALERT': 15L, 'M_VOLMGMT': 16L, 'M_SKIPPED': 9L}""" ) diff --git a/core/src/plugins/python_plugins_common.h b/core/src/plugins/python_plugins_common.h index 376594a8a82..13cff3dde34 100644 --- a/core/src/plugins/python_plugins_common.h +++ b/core/src/plugins/python_plugins_common.h @@ -55,32 +55,53 @@ return NULL; \ } -#define DictSet_StrLong(dict, string, value) \ + +/* define the given string constant as member of an dict and additionally + add it directly as constant to the module. + + This is both done for string to long and for string to string mappings. + + The result is that the module both contains a dict: + bIOPS = {'IO_CLOSE': 4L, 'IO_OPEN': 1L, 'IO_READ': 2L, 'IO_SEEK': 5L, + 'IO_WRITE': 3L} + and the single values directly: + IO_CLOSE = 4 + IO_OPEN = 1 + IO_READ = 2 + IO_SEEK = 5 + IO_WRITE = 3 + */ + +#define ConstSet_StrLong(dict, string, value) \ if (PyDict_SetItem(dict, PyBytes_FromString(#string), \ PyLong_FromLong(value))) { \ return MOD_ERROR_VAL; \ - } + } \ + if (PyModule_AddIntConstant(m, #string, value)) { return MOD_ERROR_VAL; } -#define DictSet_StrStr(dict, string, value) \ +#define ConstSet_StrStr(dict, string, value) \ if (PyDict_SetItem(dict, PyBytes_FromString(#string), \ PyBytes_FromString(value))) { \ return MOD_ERROR_VAL; \ - } + } \ + if (PyModule_AddStringConstant(m, #string, value)) { return MOD_ERROR_VAL; } + -#define DEFINE_bRCs_DICT() \ - const char* bRCs = "bRCs"; \ - PyObject* pDictbRCs = NULL; \ - pDictbRCs = PyDict_New(); \ - DictSet_StrLong(pDictbRCs, bRC_OK, 0); \ - DictSet_StrLong(pDictbRCs, bRC_Stop, 1); \ - DictSet_StrLong(pDictbRCs, bRC_Error, 2); \ - DictSet_StrLong(pDictbRCs, bRC_More, 3); \ - DictSet_StrLong(pDictbRCs, bRC_Term, 4); \ - DictSet_StrLong(pDictbRCs, bRC_Seen, 5); \ - DictSet_StrLong(pDictbRCs, bRC_Core, 6); \ - DictSet_StrLong(pDictbRCs, bRC_Skip, 7); \ - DictSet_StrLong(pDictbRCs, bRC_Cancel, 8); \ - if (!pDictbRCs) { return MOD_ERROR_VAL; } \ +/* commonly used definitions in multiple python modules */ +#define DEFINE_bRCs_DICT() \ + const char* bRCs = "bRCs"; \ + PyObject* pDictbRCs = NULL; \ + pDictbRCs = PyDict_New(); \ + ConstSet_StrLong(pDictbRCs, bRC_OK, 0); \ + ConstSet_StrLong(pDictbRCs, bRC_Stop, 1); \ + ConstSet_StrLong(pDictbRCs, bRC_Error, 2); \ + ConstSet_StrLong(pDictbRCs, bRC_More, 3); \ + ConstSet_StrLong(pDictbRCs, bRC_Term, 4); \ + ConstSet_StrLong(pDictbRCs, bRC_Seen, 5); \ + ConstSet_StrLong(pDictbRCs, bRC_Core, 6); \ + ConstSet_StrLong(pDictbRCs, bRC_Skip, 7); \ + ConstSet_StrLong(pDictbRCs, bRC_Cancel, 8); \ + if (!pDictbRCs) { return MOD_ERROR_VAL; } \ if (PyModule_AddObject(m, bRCs, pDictbRCs)) { return MOD_ERROR_VAL; } #define DEFINE_bJobMessageTypes_DICT() \ @@ -88,22 +109,22 @@ PyObject* pDictJobMessageType = NULL; \ pDictJobMessageType = PyDict_New(); \ if (!pDictJobMessageType) { return MOD_ERROR_VAL; } \ - DictSet_StrLong(pDictJobMessageType, M_ABORT, 1); \ - DictSet_StrLong(pDictJobMessageType, M_DEBUG, 2); \ - DictSet_StrLong(pDictJobMessageType, M_FATAL, 3); \ - DictSet_StrLong(pDictJobMessageType, M_ERROR, 4); \ - DictSet_StrLong(pDictJobMessageType, M_WARNING, 5); \ - DictSet_StrLong(pDictJobMessageType, M_INFO, 6); \ - DictSet_StrLong(pDictJobMessageType, M_SAVED, 7); \ - DictSet_StrLong(pDictJobMessageType, M_NOTSAVED, 8); \ - DictSet_StrLong(pDictJobMessageType, M_SKIPPED, 9); \ - DictSet_StrLong(pDictJobMessageType, M_MOUNT, 10); \ - DictSet_StrLong(pDictJobMessageType, M_ERROR_TERM, 11); \ - DictSet_StrLong(pDictJobMessageType, M_TERM, 12); \ - DictSet_StrLong(pDictJobMessageType, M_RESTORED, 13); \ - DictSet_StrLong(pDictJobMessageType, M_SECURITY, 14); \ - DictSet_StrLong(pDictJobMessageType, M_ALERT, 15); \ - DictSet_StrLong(pDictJobMessageType, M_VOLMGMT, 16); \ + ConstSet_StrLong(pDictJobMessageType, M_ABORT, 1); \ + ConstSet_StrLong(pDictJobMessageType, M_DEBUG, 2); \ + ConstSet_StrLong(pDictJobMessageType, M_FATAL, 3); \ + ConstSet_StrLong(pDictJobMessageType, M_ERROR, 4); \ + ConstSet_StrLong(pDictJobMessageType, M_WARNING, 5); \ + ConstSet_StrLong(pDictJobMessageType, M_INFO, 6); \ + ConstSet_StrLong(pDictJobMessageType, M_SAVED, 7); \ + ConstSet_StrLong(pDictJobMessageType, M_NOTSAVED, 8); \ + ConstSet_StrLong(pDictJobMessageType, M_SKIPPED, 9); \ + ConstSet_StrLong(pDictJobMessageType, M_MOUNT, 10); \ + ConstSet_StrLong(pDictJobMessageType, M_ERROR_TERM, 11); \ + ConstSet_StrLong(pDictJobMessageType, M_TERM, 12); \ + ConstSet_StrLong(pDictJobMessageType, M_RESTORED, 13); \ + ConstSet_StrLong(pDictJobMessageType, M_SECURITY, 14); \ + ConstSet_StrLong(pDictJobMessageType, M_ALERT, 15); \ + ConstSet_StrLong(pDictJobMessageType, M_VOLMGMT, 16); \ if (PyModule_AddObject(m, bJobMessageType, pDictJobMessageType)) { \ return MOD_ERROR_VAL; \ } diff --git a/core/src/plugins/stored/python/python-sd.h b/core/src/plugins/stored/python/python-sd.h index fe07cf1b60c..580ffc3c565 100644 --- a/core/src/plugins/stored/python/python-sd.h +++ b/core/src/plugins/stored/python/python-sd.h @@ -123,23 +123,23 @@ MOD_INIT(bareossd) PyObject* pDictsdVariable = NULL; pDictsdVariable = PyDict_New(); if (!pDictsdVariable) { return MOD_ERROR_VAL; } - DictSet_StrLong(pDictsdVariable, bsdVarJob, 1); - DictSet_StrLong(pDictsdVariable, bsdVarLevel, 2); - DictSet_StrLong(pDictsdVariable, bsdVarType, 3); - DictSet_StrLong(pDictsdVariable, bsdVarJobId, 4); - DictSet_StrLong(pDictsdVariable, bsdVarClient, 5); - DictSet_StrLong(pDictsdVariable, bsdVarPool, 6); - DictSet_StrLong(pDictsdVariable, bsdVarPoolType, 7); - DictSet_StrLong(pDictsdVariable, bsdVarStorage, 8); - DictSet_StrLong(pDictsdVariable, bsdVarMediaType, 9); - DictSet_StrLong(pDictsdVariable, bsdVarJobName, 10); - DictSet_StrLong(pDictsdVariable, bsdVarJobStatus, 11); - DictSet_StrLong(pDictsdVariable, bsdVarVolumeName, 12); - DictSet_StrLong(pDictsdVariable, bsdVarJobErrors, 13); - DictSet_StrLong(pDictsdVariable, bsdVarJobFiles, 14); - DictSet_StrLong(pDictsdVariable, bsdVarJobBytes, 15); - DictSet_StrLong(pDictsdVariable, bsdVarCompatible, 16); - DictSet_StrLong(pDictsdVariable, bsdVarPluginDir, 17); + ConstSet_StrLong(pDictsdVariable, bsdVarJob, 1); + ConstSet_StrLong(pDictsdVariable, bsdVarLevel, 2); + ConstSet_StrLong(pDictsdVariable, bsdVarType, 3); + ConstSet_StrLong(pDictsdVariable, bsdVarJobId, 4); + ConstSet_StrLong(pDictsdVariable, bsdVarClient, 5); + ConstSet_StrLong(pDictsdVariable, bsdVarPool, 6); + ConstSet_StrLong(pDictsdVariable, bsdVarPoolType, 7); + ConstSet_StrLong(pDictsdVariable, bsdVarStorage, 8); + ConstSet_StrLong(pDictsdVariable, bsdVarMediaType, 9); + ConstSet_StrLong(pDictsdVariable, bsdVarJobName, 10); + ConstSet_StrLong(pDictsdVariable, bsdVarJobStatus, 11); + ConstSet_StrLong(pDictsdVariable, bsdVarVolumeName, 12); + ConstSet_StrLong(pDictsdVariable, bsdVarJobErrors, 13); + ConstSet_StrLong(pDictsdVariable, bsdVarJobFiles, 14); + ConstSet_StrLong(pDictsdVariable, bsdVarJobBytes, 15); + ConstSet_StrLong(pDictsdVariable, bsdVarCompatible, 16); + ConstSet_StrLong(pDictsdVariable, bsdVarPluginDir, 17); if (PyModule_AddObject(m, bsdVariable, pDictsdVariable)) { return MOD_ERROR_VAL; } @@ -148,10 +148,10 @@ MOD_INIT(bareossd) PyObject* pDictsdwVariable = NULL; pDictsdwVariable = PyDict_New(); if (!pDictsdwVariable) { return MOD_ERROR_VAL; } - DictSet_StrLong(pDictsdwVariable, bsdwVarJobReport, 1); - DictSet_StrLong(pDictsdwVariable, bsdwVarVolumeName, 2); - DictSet_StrLong(pDictsdwVariable, bsdwVarPriority, 3); - DictSet_StrLong(pDictsdwVariable, bsdwVarJobLevel, 4); + ConstSet_StrLong(pDictsdwVariable, bsdwVarJobReport, 1); + ConstSet_StrLong(pDictsdwVariable, bsdwVarVolumeName, 2); + ConstSet_StrLong(pDictsdwVariable, bsdwVarPriority, 3); + ConstSet_StrLong(pDictsdwVariable, bsdwVarJobLevel, 4); if (PyModule_AddObject(m, bsdwVariable, pDictsdwVariable)) { return MOD_ERROR_VAL; } @@ -160,30 +160,30 @@ MOD_INIT(bareossd) const char* bsdEventType = "bsdEventType"; PyObject* pDictbsdEventType = NULL; pDictbsdEventType = PyDict_New(); - DictSet_StrLong(pDictbsdEventType, bsdEventJobStart, 1); - DictSet_StrLong(pDictbsdEventType, bsdEventJobEnd, 2); - DictSet_StrLong(pDictbsdEventType, bsdEventDeviceInit, 3); - DictSet_StrLong(pDictbsdEventType, bsdEventDeviceMount, 4); - DictSet_StrLong(pDictbsdEventType, bsdEventVolumeLoad, 5); - DictSet_StrLong(pDictbsdEventType, bsdEventDeviceReserve, 6); - DictSet_StrLong(pDictbsdEventType, bsdEventDeviceOpen, 7); - DictSet_StrLong(pDictbsdEventType, bsdEventLabelRead, 8); - DictSet_StrLong(pDictbsdEventType, bsdEventLabelVerified, 9); - DictSet_StrLong(pDictbsdEventType, bsdEventLabelWrite, 10); - DictSet_StrLong(pDictbsdEventType, bsdEventDeviceClose, 11); - DictSet_StrLong(pDictbsdEventType, bsdEventVolumeUnload, 12); - DictSet_StrLong(pDictbsdEventType, bsdEventDeviceUnmount, 13); - DictSet_StrLong(pDictbsdEventType, bsdEventReadError, 14); - DictSet_StrLong(pDictbsdEventType, bsdEventWriteError, 15); - DictSet_StrLong(pDictbsdEventType, bsdEventDriveStatus, 16); - DictSet_StrLong(pDictbsdEventType, bsdEventVolumeStatus, 17); - DictSet_StrLong(pDictbsdEventType, bsdEventSetupRecordTranslation, 18); - DictSet_StrLong(pDictbsdEventType, bsdEventReadRecordTranslation, 19); - DictSet_StrLong(pDictbsdEventType, bsdEventWriteRecordTranslation, 20); - DictSet_StrLong(pDictbsdEventType, bsdEventDeviceRelease, 21); - DictSet_StrLong(pDictbsdEventType, bsdEventNewPluginOptions, 22); - DictSet_StrLong(pDictbsdEventType, bsdEventChangerLock, 23); - DictSet_StrLong(pDictbsdEventType, bsdEventChangerUnlock, 24); + ConstSet_StrLong(pDictbsdEventType, bsdEventJobStart, 1); + ConstSet_StrLong(pDictbsdEventType, bsdEventJobEnd, 2); + ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceInit, 3); + ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceMount, 4); + ConstSet_StrLong(pDictbsdEventType, bsdEventVolumeLoad, 5); + ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceReserve, 6); + ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceOpen, 7); + ConstSet_StrLong(pDictbsdEventType, bsdEventLabelRead, 8); + ConstSet_StrLong(pDictbsdEventType, bsdEventLabelVerified, 9); + ConstSet_StrLong(pDictbsdEventType, bsdEventLabelWrite, 10); + ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceClose, 11); + ConstSet_StrLong(pDictbsdEventType, bsdEventVolumeUnload, 12); + ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceUnmount, 13); + ConstSet_StrLong(pDictbsdEventType, bsdEventReadError, 14); + ConstSet_StrLong(pDictbsdEventType, bsdEventWriteError, 15); + ConstSet_StrLong(pDictbsdEventType, bsdEventDriveStatus, 16); + ConstSet_StrLong(pDictbsdEventType, bsdEventVolumeStatus, 17); + ConstSet_StrLong(pDictbsdEventType, bsdEventSetupRecordTranslation, 18); + ConstSet_StrLong(pDictbsdEventType, bsdEventReadRecordTranslation, 19); + ConstSet_StrLong(pDictbsdEventType, bsdEventWriteRecordTranslation, 20); + ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceRelease, 21); + ConstSet_StrLong(pDictbsdEventType, bsdEventNewPluginOptions, 22); + ConstSet_StrLong(pDictbsdEventType, bsdEventChangerLock, 23); + ConstSet_StrLong(pDictbsdEventType, bsdEventChangerUnlock, 24); if (!pDictbsdEventType) { return MOD_ERROR_VAL; } if (PyModule_AddObject(m, bsdEventType, pDictbsdEventType)) { diff --git a/core/src/plugins/stored/python/test/bareossd_test.py b/core/src/plugins/stored/python/test/bareossd_test.py index 63d811d588f..b4fd33de162 100644 --- a/core/src/plugins/stored/python/test/bareossd_test.py +++ b/core/src/plugins/stored/python/test/bareossd_test.py @@ -2,6 +2,7 @@ import bareossd import time +print help (bareossd) class TestBareosFd(unittest.TestCase): From bdf9ffc89c95bed3740982430e32564f48352f2f Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 17 Mar 2020 10:11:01 +0100 Subject: [PATCH 037/341] python-fd.cc: get bpContext from PythonModule first in each function --- core/src/plugins/filed/python/python-fd.cc | 38 ++++++++++------------ 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 3b645d91987..0a3c963aaa5 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -2237,8 +2237,7 @@ static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - bpContext* bareos_plugin_ctx = NULL; - + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } @@ -2312,7 +2311,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject* pyValue; @@ -2406,21 +2405,20 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; if (!PyArg_ParseTuple(args, "O:BareosRegisterEvents", &pyEvents)) { goto bail_out; } + bareos_plugin_ctx = GetPluginContextFromPythonModule(); RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); if (!pySeq) { goto bail_out; } - len = PySequence_Fast_GET_SIZE(pySeq); - bareos_plugin_ctx = GetPluginContextFromPythonModule(); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); @@ -2448,7 +2446,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -2488,7 +2486,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; @@ -2515,7 +2513,7 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) { char* file = NULL; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; @@ -2538,7 +2536,7 @@ static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) { char* file = NULL; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; @@ -2561,7 +2559,7 @@ static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) { char* opts = NULL; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; @@ -2585,7 +2583,7 @@ static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) { int type; char* item = NULL; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; @@ -2611,7 +2609,7 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) { int type; char* item = NULL; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; @@ -2635,7 +2633,7 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; @@ -2655,7 +2653,7 @@ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; @@ -2675,7 +2673,7 @@ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; @@ -2696,7 +2694,7 @@ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) */ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); struct save_pkt sp; bRC retval = bRC_Error; @@ -2751,7 +2749,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) */ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); struct save_pkt sp; bRC retval = bRC_Error; PySavePacket* pSavePkt; @@ -2796,7 +2794,7 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) { bool all; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; @@ -2822,7 +2820,7 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) { bool all; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; From f9e8296cdc0a84cb1dc88ae7aa0fe22cf00481f8 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 13 Aug 2020 12:25:42 +0200 Subject: [PATCH 038/341] python-fd-plugin-local-fileset-test: use bareosfd constants --- .../python/pyfiles/BareosFdPluginBaseclass.py | 124 +++++++++--------- .../filed/python/test/bareosfd-module-test.py | 1 - ...sFdPluginLocalFilesetWithRestoreObjects.py | 51 +++---- ...os-fd-local-fileset-with-restoreobjects.py | 11 +- 4 files changed, 95 insertions(+), 92 deletions(-) diff --git a/core/src/plugins/filed/python/pyfiles/BareosFdPluginBaseclass.py b/core/src/plugins/filed/python/pyfiles/BareosFdPluginBaseclass.py index 4ccca7cbcfe..67fb20befde 100644 --- a/core/src/plugins/filed/python/pyfiles/BareosFdPluginBaseclass.py +++ b/core/src/plugins/filed/python/pyfiles/BareosFdPluginBaseclass.py @@ -25,8 +25,7 @@ # Functions taken and adapted from bareos-fd.py import bareosfd -from bareos_fd_consts import bVariable, bFileType, bRCs, bCFs -from bareos_fd_consts import bEventType, bIOPS, bJobMessageType +from bareosfd import * import os import stat import time @@ -43,24 +42,24 @@ def __init__(self, plugindef, mandatory_options=None): % (__name__, plugindef), ) events = [] - events.append(bEventType["bEventJobEnd"]) - events.append(bEventType["bEventEndBackupJob"]) - events.append(bEventType["bEventEndFileSet"]) - events.append(bEventType["bEventHandleBackupFile"]) - events.append(bEventType["bEventStartBackupJob"]) - events.append(bEventType["bEventStartRestoreJob"]) + events.append(bEventJobEnd) + events.append(bEventEndBackupJob) + events.append(bEventEndFileSet) + events.append(bEventHandleBackupFile) + events.append(bEventStartBackupJob) + events.append(bEventStartRestoreJob) bareosfd.RegisterEvents(events) # get some static Bareos values - self.fdname = bareosfd.GetValue(bVariable["bVarFDName"]) - self.jobId = bareosfd.GetValue(bVariable["bVarJobId"]) - self.client = bareosfd.GetValue(bVariable["bVarClient"]) - self.since = bareosfd.GetValue(bVariable["bVarSinceTime"]) - self.level = bareosfd.GetValue(bVariable["bVarLevel"]) - self.jobName = bareosfd.GetValue(bVariable["bVarJobName"]) + self.fdname = bareosfd.GetValue(bVarFDName) + self.jobId = bareosfd.GetValue(bVarJobId) + self.client = bareosfd.GetValue(bVarClient) + self.since = bareosfd.GetValue(bVarSinceTime) + self.level = bareosfd.GetValue(bVarLevel) + self.jobName = bareosfd.GetValue(bVarJobName) # jobName is of format myName.2020-05-12_11.35.27_05 # short Name is everything left of the third point seen from the right self.shortName = self.jobName.rsplit(".", 3)[0] - self.workingdir = bareosfd.GetValue(context, bVariable["bVarWorkingDir"]) + self.workingdir = bareosfd.GetValue(bVarWorkingDir) self.startTime = int(time.time()) self.FNAME = "undef" self.filetype = "undef" @@ -120,21 +119,21 @@ def check_options(self, mandatory_options=None): If you have more to veriy, just overwrite ths method in your class """ if mandatory_options is None: - return bRCs["bRC_OK"] + return bRC_OK for option in mandatory_options: if option not in self.options: bareosfd.DebugMessage( 100, "Mandatory option '%s' not defined.\n" % option ) bareosfd.JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "Mandatory option '%s' not defined.\n" % (option), ) - return bRCs["bRC_Error"] + return bRC_Error bareosfd.DebugMessage( 100, "Using Option %s=%s\n" % (option, self.options[option]) ) - return bRCs["bRC_OK"] + return bRC_OK def plugin_io_open(self, IOP): self.FNAME = IOP.fname.decode("string_escape") @@ -148,22 +147,21 @@ def plugin_io_open(self, IOP): 100, "Did not open file %s of type %s\n" % (self.FNAME, self.fileType), ) - return bRCs["bRC_OK"] + return bRC_OK elif os.path.islink(self.FNAME): self.fileType = "FT_LNK" bareosfd.DebugMessage( 100, "Did not open file %s of type %s\n" % (self.FNAME, self.fileType), ) - return bRCs["bRC_OK"] + return bRC_OK" elif os.path.exists(self.FNAME) and stat.S_ISFIFO(os.stat(self.FNAME).st_mode): self.fileType = "FT_FIFO" bareosfd.DebugMessage( - context, 100, "Did not open file %s of type %s\n" % (self.FNAME, self.fileType), ) - return bRCs["bRC_OK"] + return bRC_OK else: self.fileType = "FT_REG" bareosfd.DebugMessage( @@ -193,17 +191,17 @@ def plugin_io_open(self, IOP): self.file = open(self.FNAME, "rb") except: IOP.status = -1 - return bRCs["bRC_Error"] - return bRCs["bRC_OK"] + return bRC_Error + return bRC_OK def plugin_io_close(self, IOP): bareosfd.DebugMessage(100, "Closing file " + "\n") if self.fileType == "FT_REG": self.file.close() - return bRCs["bRC_OK"] + return bRC_OK def plugin_io_seek(self, IOP): - return bRCs["bRC_OK"] + return bRC_OK def plugin_io_read(self, IOP): if self.fileType == "FT_REG": @@ -216,12 +214,12 @@ def plugin_io_read(self, IOP): IOP.io_errno = 0 except Exception as e: bareosfd.JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, 'Could net read %d bytes from file %s. "%s"' % (IOP.count, file_to_backup, e.message), ) IOP.io_errno = e.errno - return bRCs["bRC_Error"] + return bRC_Error else: bareosfd.DebugMessage( 100, @@ -230,7 +228,7 @@ def plugin_io_read(self, IOP): IOP.buf = bytearray() IOP.status = 0 IOP.io_errno = 0 - return bRCs["bRC_OK"] + return bRC_OK def plugin_io_write(self, IOP): bareosfd.DebugMessage( @@ -240,15 +238,15 @@ def plugin_io_write(self, IOP): self.file.write(IOP.buf) except Exception as e: bareosfd.JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, 'Could net write to file %s. "%s"' % (file_to_backup, e.message), ) IOP.io_errno = e.errno IOP.status = 0 - return bRCs["bRC_Error"] + return bRC_Error IOP.status = IOP.count IOP.io_errno = 0 - return bRCs["bRC_OK"] + return bRC_OK def plugin_io(self, IOP): """ @@ -261,43 +259,43 @@ def plugin_io(self, IOP): "plugin_io called with function %s filename %s\n" % (IOP.func, IOP.fname), ) bareosfd.DebugMessage(250, "self.FNAME is set to %s\n" % (self.FNAME)) - if IOP.func == bIOPS["O_OPEN"]: + if IOP.func == O_OPEN: return self.plugin_io_open(IOP) - elif IOP.func == bIOPS["IO_CLOSE"]: + elif IOP.func == IO_CLOSE: return self.plugin_io_close(IOP) - elif IOP.func == bIOPS["IO_SEEK"]: + elif IOP.func == IO_SEEK: return self.plugin_io_seek(IOP) - elif IOP.func == bIOPS["IO_READ"]: + elif IOP.func == IO_READ: return self.plugin_io_read(IOP) - elif IOP.func == bIOPS["IO_WRITE"]: + elif IOP.func == IO_WRITE: return self.plugin_io_write(IOP) def handle_plugin_event(self, event): - if event == bEventType["bEventJobEnd"]: + if event == bEventJobEnd: bareosfd.DebugMessage( 100, "handle_plugin_event called with bEventJobEnd\n" ) return self.end_job() - elif event == bEventType["bEventEndBackupJob"]: + elif event == bEventEndBackupJob: bareosfd.DebugMessage( 100, "handle_plugin_event called with bEventEndBackupJob\n" ) return self.end_backup_job() - elif event == bEventType["bEventEndFileSet"]: + elif event == bEventEndFileSet: bareosfd.DebugMessage( 100, "handle_plugin_event called with bEventEndFileSet\n" ) return self.end_fileset() - elif event == bEventType["bEventStartBackupJob"]: + elif event == bEventStartBackupJob: bareosfd.DebugMessage( 100, "handle_plugin_event() called with bEventStartBackupJob\n" ) return self.start_backup_job() - elif event == bEventType["bEventStartRestoreJob"]: + elif event == bEventStartRestoreJob: bareosfd.DebugMessage( 100, "handle_plugin_event() called with bEventStartRestoreJob\n", @@ -308,28 +306,28 @@ def handle_plugin_event(self, event): bareosfd.DebugMessage( 100, "handle_plugin_event called with event %s\n" % (event) ) - return bRCs["bRC_OK"] + return bRC_OK def start_backup_job(self): """ Start of Backup Job. Called just before backup job really start. Overload this to arrange whatever you have to do at this time. """ - return bRCs["bRC_OK"] + return bRC_OK def end_job(self: """ Called if job ends regularyly (not for cancelled jobs) Overload this to arrange whatever you have to do at this time. """ - return bRCs["bRC_OK"] + return bRC_OK def end_backup_job(self): """ Called if backup job ends, before ClientAfterJob Overload this to arrange whatever you have to do at this time. """ - return bRCs["bRC_OK"] + return bRC_OK def start_backup_file(self,savepkt): """ @@ -337,45 +335,45 @@ def start_backup_file(self,savepkt): implementation to add files to backup fileset """ bareosfd.DebugMessage(100, "start_backup called\n") - return bRCs["bRC_Skip"] + return bRC_Skip def end_backup_file(self): bareosfd.DebugMessage( 100, "end_backup_file() entry point in Python called\n" ) - return bRCs["bRC_OK"] + return bRC_OK def end_fileset(self): bareosfd.DebugMessage( 100, "end_fileset() entry point in Python called\n" ) - return bRCs["bRC_OK"] + return bRC_OK def start_restore_job(self): """ Start of Restore Job. Called , if you have Restore objects. Overload this to handle restore objects, if applicable """ - return bRCs["bRC_OK"] + return bRC_OK def start_restore_file(self, cmd): bareosfd.DebugMessage( 100, "start_restore_file() entry point in Python called with %s\n" % (cmd), ) - return bRCs["bRC_OK"] + return bRC_OK def end_restore_file(self): bareosfd.DebugMessage( 100, "end_restore_file() entry point in Python called\n" ) - return bRCs["bRC_OK"] + return bRC_OK def restore_object_data(self, ROP): bareosfd.DebugMessage( 100, "restore_object_data called with " + str(ROP) + "\n" ) - return bRCs["bRC_OK"] + return bRC_OK def create_file(self, restorepkt): """ @@ -388,8 +386,8 @@ def create_file(self, restorepkt): "create_file() entry point in Python called with %s\n" % (restorepkt), ) # We leave file creation up to the core for the default case - restorepkt.create_status = bCFs["CF_CORE"] - return bRCs["bRC_OK"] + restorepkt.create_status = CF_CORE + return bRC_OK def set_file_attributes(self, restorepkt): bareosfd.DebugMessage( @@ -397,45 +395,45 @@ def set_file_attributes(self, restorepkt): "set_file_attributes() entry point in Python called with %s\n" % (str(restorepkt)), ) - return bRCs["bRC_OK"] + return bRC_OK def check_file(self, fname): bareosfd.DebugMessage( 100, "check_file() entry point in Python called with %s\n" % (fname), ) - return bRCs["bRC_OK"] + return bRC_OK def get_acl(self, acl): bareosfd.DebugMessage( 100, "get_acl() entry point in Python called with %s\n" % (acl) ) - return bRCs["bRC_OK"] + return bRC_OK def set_acl(self, acl): bareosfd.DebugMessage( 100, "set_acl() entry point in Python called with %s\n" % (acl) ) - return bRCs["bRC_OK"] + return bRC_OK def get_xattr(self, xattr): bareosfd.DebugMessage( 100, "get_xattr() entry point in Python called with %s\n" % (xattr) ) - return bRCs["bRC_OK"] + return bRC_OK def set_xattr(self, xattr): bareosfd.DebugMessage( 100, "set_xattr() entry point in Python called with %s\n" % (xattr) ) - return bRCs["bRC_OK"] + return bRC_OK def handle_backup_file(self, savepkt): bareosfd.DebugMessage( 100, "handle_backup_file() entry point in Python called with %s\n" % (savepkt), ) - return bRCs["bRC_OK"] + return bRC_OK # vim: ts=4 tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/core/src/plugins/filed/python/test/bareosfd-module-test.py b/core/src/plugins/filed/python/test/bareosfd-module-test.py index d2b7dc9cf51..43650f35dd9 100644 --- a/core/src/plugins/filed/python/test/bareosfd-module-test.py +++ b/core/src/plugins/filed/python/test/bareosfd-module-test.py @@ -1,5 +1,4 @@ import bareosfd -import bareos_fd_consts def load_bareos_plugin(plugindef): print ("Hello from load_bareos_plugin") diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py index 554ff298e8c..972845cfd95 100644 --- a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py +++ b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py @@ -24,8 +24,9 @@ # Bareos python plugins class that adds files from a local list to # the backup fileset + import bareosfd -from bareos_fd_consts import bJobMessageType, bFileType, bRCs, bVariable +from bareosfd import * import os import re import hashlib @@ -62,12 +63,12 @@ def __init__(self, plugindef): self.deny = None self.object_index_seq = int((time.time() - 1546297200) * 10) self.sha256sums_by_filename = {} - bareosfd.SetValue(context,bVariable["bVarSinceTime"],999) - triple_nine = bareosfd.GetValue(context,bVariable["bVarSinceTime"]) + bareosfd.SetValue(context,bVarSinceTime,999) + triple_nine = bareosfd.GetValue(context,bVarSinceTime) if triple_nine != 999: bareosfd.JobMessage( context, - bJobMessageType["M_ERROR"], + M_ERROR, "Wrong value for since time (should be 999 but is %d)\n" % triple_nine ) @@ -92,7 +93,7 @@ def filename_is_allowed(self, filename, allowregex, denyregex): 100, "File %s denied by configuration\n" % (filename) ) bareosfd.JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, "File %s denied by configuration\n" % (filename), ) return False @@ -118,12 +119,12 @@ def start_backup_job(self): 100, "Could not open file %s\n" % (self.options["filename"]), ) - return bRCs["bRC_Error"] + return bRC_Error else: bareosfd.DebugMessage( 100, "File %s does not exist\n" % (self.options["filename"]) ) - return bRCs["bRC_Error"] + return bRC_Error # Check, if we have allow or deny regular expressions defined if "allow" in self.options: self.allow = re.compile(self.options["allow"]) @@ -163,12 +164,12 @@ def start_backup_job(self): if not self.files_to_backup: bareosfd.JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, "No (allowed) files to backup found\n", ) - return bRCs["bRC_Error"] + return bRC_Error else: - return bRCs["bRC_Cancel"] + return bRC_Cancel def start_backup_file(self, savepkt): """ @@ -178,7 +179,7 @@ def start_backup_file(self, savepkt): bareosfd.DebugMessage(100, "start_backup_file() called\n") if not self.files_to_backup: bareosfd.DebugMessage(100, "No files to backup\n") - return bRCs["bRC_Skip"] + return bRC_Skip file_to_backup = self.files_to_backup.pop() bareosfd.DebugMessage(100, "file: " + file_to_backup + "\n") @@ -188,7 +189,7 @@ def start_backup_file(self, savepkt): if file_to_backup.endswith(".sha256sum"): checksum = self.get_sha256sum(os.path.splitext(file_to_backup)[0]) - savepkt.type = bFileType["FT_RESTORE_FIRST"] + savepkt.type = FT_RESTORE_FIRST savepkt.fname = file_to_backup savepkt.object_name = file_to_backup savepkt.object = bytearray(checksum) @@ -197,7 +198,7 @@ def start_backup_file(self, savepkt): self.object_index_seq += 1 elif file_to_backup.endswith(".abspath"): - savepkt.type = bFileType["FT_RESTORE_FIRST"] + savepkt.type = FT_RESTORE_FIRST savepkt.fname = file_to_backup savepkt.object_name = file_to_backup savepkt.object = bytearray(os.path.splitext(file_to_backup)[0]) @@ -207,7 +208,7 @@ def start_backup_file(self, savepkt): elif file_to_backup.endswith(".longrestoreobject"): teststring_length = int(os.path.splitext(file_to_backup)[0]) - savepkt.type = bFileType["FT_RESTORE_FIRST"] + savepkt.type = FT_RESTORE_FIRST savepkt.fname = file_to_backup savepkt.object_name = file_to_backup savepkt.object = bytearray("a" * teststring_length) @@ -217,13 +218,13 @@ def start_backup_file(self, savepkt): else: savepkt.fname = file_to_backup - savepkt.type = bFileType["FT_REG"] + savepkt.type = FT_REG bareosfd.JobMessage( - bJobMessageType["M_INFO"], + M_INFO, "Starting backup of %s\n" % (file_to_backup), ) - return bRCs["bRC_OK"] + return bRC_OK def end_backup_file(self): """ @@ -234,9 +235,9 @@ def end_backup_file(self): 100, "end_backup_file() entry point in Python called\n" ) if self.files_to_backup: - return bRCs["bRC_More"] + return bRC_More else: - return bRCs["bRC_OK"] + return bRC_OK def set_file_attributes(self, restorepkt): bareosfd.DebugMessage( @@ -256,18 +257,18 @@ def set_file_attributes(self, restorepkt): ) if file_sha256sum != restoreobject_sha256sum: bareosfd.JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, "bad restoreobject orig_fname: %s restoreobject_sha256sum: %s file_sha256sum: %s\n" % (orig_fname, repr(restoreobject_sha256sum), repr(file_sha256sum)), ) - return bRCs["bRC_OK"] + return bRC_OK def end_restore_file(self): bareosfd.DebugMessage( 100, "end_restore_file() self.FNAME: %s\n" % self.FNAME ) - return bRCs["bRC_OK"] + return bRC_OK def restore_object_data(self, ROP): """ @@ -310,7 +311,7 @@ def restore_object_data(self, ROP): elif ROP.object_name.endswith(".abspath"): if str(ROP.object) != orig_filename: bareosfd.JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, "bad restoreobject orig_fname: %s restoreobject_fname: %s\n" % (orig_filename, repr(str(ROP.object))), ) @@ -318,7 +319,7 @@ def restore_object_data(self, ROP): stored_length = int(os.path.splitext(ROP.object_name)[0]) if str(ROP.object) != "a" * stored_length: bareosfd.JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, "bad long restoreobject %s does not match stored object\n" % (ROP.object_name), ) @@ -327,7 +328,7 @@ def restore_object_data(self, ROP): 100, "not checking restoreobject: %s\n" % (type(ROP.object_name)), ) - return bRCs["bRC_OK"] + return bRC_OK def get_sha256sum(self, filename): f = open(filename, "rb") diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/bareos-fd-local-fileset-with-restoreobjects.py b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/bareos-fd-local-fileset-with-restoreobjects.py index b03eb7013d8..4385cf5ea1c 100644 --- a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/bareos-fd-local-fileset-with-restoreobjects.py +++ b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/bareos-fd-local-fileset-with-restoreobjects.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # BAREOS - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2014-2014 Bareos GmbH & Co. KG +# Copyright (C) 2014-2020 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -30,7 +30,9 @@ # # Provided by the Bareos FD Python plugin interface -import bareos_fd_consts +#import bareos_fd_consts +import bareosfd +from bareosfd import * # This module contains the wrapper functions called by the Bareos-FD, the # functions call the corresponding methods from your plugin class @@ -43,6 +45,7 @@ import BareosFdPluginLocalFilesetWithRestoreObjects + def load_bareos_plugin(plugindef): """ This function is called by the Bareos-FD to load the plugin @@ -53,7 +56,9 @@ def load_bareos_plugin(plugindef): BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLocalFilesetWithRestoreObjects.BareosFdPluginLocalFilesetWithRestoreObjects( plugindef ) - return bareos_fd_consts.bRCs["bRC_OK"] + return bRC_OK + # return bareosfd.bRC_OK + # return bareosfd.bRCs["bRC_OK"] # the rest is done in the Plugin module From fe78da254b24a46b536ca9458b10aae3fa57f571 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 13 Aug 2020 12:28:48 +0200 Subject: [PATCH 039/341] python plugins: fix pyfiles/ subdir changes and apply cmake-format --- core/src/plugins/dird/CMakeLists.txt | 30 +++++++---- core/src/plugins/filed/CMakeLists.txt | 74 ++++++++++++++------------ core/src/plugins/stored/CMakeLists.txt | 31 +++++++---- 3 files changed, 81 insertions(+), 54 deletions(-) diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index 23664218e05..6fc28e79d04 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -38,9 +38,9 @@ if(HAVE_PYTHON) target_link_libraries(python-dir ${PYTHON_LIBRARIES} bareos) set(PYFILES - pyfiles/bareos-dir.py.template pyfiles/bareos-dir-class-plugin.py - pyfiles/bareos_dir_consts.py pyfiles/BareosDirPluginBaseclass.py - pyfiles/BareosDirWrapper.py + python/pyfiles/bareos-dir.py.template python/pyfiles/bareos-dir-class-plugin.py + python/pyfiles/bareos_dir_consts.py python/pyfiles/BareosDirPluginBaseclass.py + python/pyfiles/BareosDirWrapper.py ) install(FILES ${PYFILES} DESTINATION ${plugindir}) @@ -48,17 +48,25 @@ endif() if(HAVE_PYTHON) configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) - add_custom_command( TARGET python-dir + add_custom_command( + TARGET python-dir POST_BUILD COMMENT "building python module pythonmodules/bareosdir.so" COMMAND ${PYTHON_EXECUTABLE} python/setup.py build - COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build - DEPENDS python-dir - ) + COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib + ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build DEPENDS python-dir + ) add_test(NAME bareosdir-python-module - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosdir_test.py - ) - set_property(TEST bareosdir-python-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib) + COMMAND ${PYTHON_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosdir_test.py + ) + set_property( + TEST bareosdir-python-module + PROPERTY + ENVIRONMENT + "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" + LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib + ) endif() diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index 533ef8270ff..157e9725f23 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -112,34 +112,42 @@ if(HAVE_PYTHON) target_link_libraries(bareos-fd-module-tester ${PYTHON_LIBRARIES} bareos) add_test(NAME bareosfd-python-module-tester - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bareos-fd-module-tester - ) - set_property(TEST bareosfd-python-module-tester - PROPERTY ENVIRONMENT PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/python/test/:${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/pyfiles) + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bareos-fd-module-tester + ) + set_property( + TEST bareosfd-python-module-tester + PROPERTY + ENVIRONMENT + PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/python/test/:${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/pyfiles + ) endif() if(HAVE_PYTHON) configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) - add_custom_command( TARGET python-fd + add_custom_command( + TARGET python-fd POST_BUILD COMMENT "building python module pythonmodules/bareosfd.so" COMMAND ${PYTHON_EXECUTABLE} python/setup.py build - COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build - DEPENDS python-fd - ) + COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib + ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build DEPENDS python-fd + ) add_test(NAME bareosfd-python-module - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosfd_test.py - ) - set_property(TEST bareosfd-python-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib) + COMMAND ${PYTHON_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosfd_test.py + ) + set_property( + TEST bareosfd-python-module + PROPERTY + ENVIRONMENT + "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" + LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib + ) endif() - - - - if(${HAVE_GLUSTERFS}) add_library(gfapi-fd MODULE gfapi/gfapi-fd.cc) set_target_properties(gfapi-fd PROPERTIES PREFIX "") @@ -164,23 +172,23 @@ if(${HAVE_TEST_PLUGIN}) endif() set(PYFILES - bareos-fd.py.template - bareos-fd-local-fileset.py - bareos-fd-mock-test.py - BareosFdPluginBaseclass.py - BareosFdPluginLocalFileset.py - BareosFdWrapper.py - bareos_fd_consts.py - bareos-fd-ldap.py - BareosFdPluginLDAP.py - bareos-fd-ovirt.py - BareosFdPluginOvirt.py - bareos-fd-percona-xtrabackup.py - BareosFdPluginPerconaXtraBackup.py - BareosFdPluginPostgres.py - bareos-fd-postgres.py - BareosFdPluginVMware.py - bareos-fd-vmware.py + python/pyfiles/bareos-fd.py.template + python/pyfiles/bareos-fd-local-fileset.py + python/pyfiles/bareos-fd-mock-test.py + python/pyfiles/BareosFdPluginBaseclass.py + python/pyfiles/BareosFdPluginLocalFileset.py + python/pyfiles/BareosFdWrapper.py + python/pyfiles/bareos_fd_consts.py + python/pyfiles/bareos-fd-ldap.py + python/pyfiles/BareosFdPluginLDAP.py + python/pyfiles/bareos-fd-ovirt.py + python/pyfiles/BareosFdPluginOvirt.py + python/pyfiles/bareos-fd-percona-xtrabackup.py + python/pyfiles/BareosFdPluginPerconaXtraBackup.py + python/pyfiles/BareosFdPluginPostgres.py + python/pyfiles/bareos-fd-postgres.py + python/pyfiles/BareosFdPluginVMware.py + python/pyfiles/bareos-fd-vmware.py ) if(${HAVE_VIXDISKLIB}) list(APPEND PYFILES BareosFdPluginVMware.py bareos-fd-vmware.py) diff --git a/core/src/plugins/stored/CMakeLists.txt b/core/src/plugins/stored/CMakeLists.txt index 75292122533..ba3b5da4e5a 100644 --- a/core/src/plugins/stored/CMakeLists.txt +++ b/core/src/plugins/stored/CMakeLists.txt @@ -55,8 +55,11 @@ if(HAVE_PYTHON) target_link_libraries(python-sd ${PYTHON_LIBRARIES} bareos) set(PYFILES - bareos-sd-class-plugin.py bareos_sd_consts.py BareosSdPluginBaseclass.py - bareos-sd.py.template BareosSdWrapper.py + python/pyfiles/bareos-sd-class-plugin.py + python/pyfiles/bareos_sd_consts.py + python/pyfiles/BareosSdPluginBaseclass.py + python/pyfiles/bareos-sd.py.template + python/pyfiles/BareosSdWrapper.py ) install(FILES ${PYFILES} DESTINATION ${plugindir}) @@ -64,17 +67,25 @@ endif() if(HAVE_PYTHON) configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) - add_custom_command( TARGET python-sd + add_custom_command( + TARGET python-sd POST_BUILD COMMENT "building python module pythonmodules/bareossd.so" COMMAND ${PYTHON_EXECUTABLE} python/setup.py build - COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build - DEPENDS python-sd - ) + COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib + ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build DEPENDS python-sd + ) add_test(NAME bareossd-python-module - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareossd_test.py - ) - set_property(TEST bareossd-python-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib) + COMMAND ${PYTHON_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareossd_test.py + ) + set_property( + TEST bareossd-python-module + PROPERTY + ENVIRONMENT + "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" + LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib + ) endif() From 64cc61dc6d0444616c76a6c844746a550c4ca515 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 13 Aug 2020 12:41:34 +0200 Subject: [PATCH 040/341] python plugins: remove *_consts.py files --- .../bareos.com-common/pkg-plist.devel | 3 --- .../pkg-plist.director-python-plugin | 1 - .../pkg-plist.filedaemon-python-plugin | 1 - .../pkg-plist.storage-python-plugin | 1 - .../bareos.com-common/pkg-plist.traymonitor | 3 --- .../bareos-freebsd/bareos.com-common/plist | 3 --- core/platforms/packaging/bareos.spec | 3 --- core/src/plugins/dird/CMakeLists.txt | 2 +- core/src/plugins/filed/CMakeLists.txt | 18 +++++++++--------- core/src/plugins/stored/CMakeLists.txt | 1 - .../bareos-director-python-plugin.install.in | 1 - .../bareos-filedaemon-python-plugin.install.in | 1 - debian/bareos-storage-python-plugin.install.in | 1 - 13 files changed, 10 insertions(+), 29 deletions(-) diff --git a/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.devel b/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.devel index 0e38d545416..5ff361c007a 100644 --- a/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.devel +++ b/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.devel @@ -204,9 +204,6 @@ lib/bareos/plugins/bareos-fd-mock-test.py lib/bareos/plugins/bareos-fd.py.template lib/bareos/plugins/bareos-sd-class-plugin.py lib/bareos/plugins/bareos-sd.py.template -lib/bareos/plugins/bareos_dir_consts.py -lib/bareos/plugins/bareos_fd_consts.py -lib/bareos/plugins/bareos_sd_consts.py lib/bareos/plugins/bpipe-fd.so lib/bareos/plugins/python-dir.so lib/bareos/plugins/python-fd.so diff --git a/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.director-python-plugin b/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.director-python-plugin index 347a223a05d..2d6dff86bf3 100644 --- a/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.director-python-plugin +++ b/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.director-python-plugin @@ -1,7 +1,6 @@ lib/bareos/plugins/python-dir.so lib/bareos/plugins/bareos-dir.py.template -lib/bareos/plugins/bareos_dir_consts.py lib/bareos/plugins/BareosDirPluginBaseclass.py lib/bareos/plugins/bareos-dir-class-plugin.py lib/bareos/plugins/BareosDirWrapper.py diff --git a/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.filedaemon-python-plugin b/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.filedaemon-python-plugin index 98c6b364f2a..1ebd2546edd 100644 --- a/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.filedaemon-python-plugin +++ b/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.filedaemon-python-plugin @@ -6,4 +6,3 @@ lib/bareos/plugins/bareos-fd-mock-test.py lib/bareos/plugins/BareosFdPluginBaseclass.py lib/bareos/plugins/BareosFdPluginLocalFileset.py lib/bareos/plugins/BareosFdWrapper.py -lib/bareos/plugins/bareos_fd_consts.py diff --git a/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.storage-python-plugin b/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.storage-python-plugin index 2650fb0d0cb..924c3bf51e7 100644 --- a/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.storage-python-plugin +++ b/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.storage-python-plugin @@ -1,7 +1,6 @@ lib/bareos/plugins/python-sd.so lib/bareos/plugins/bareos-sd.py.template -lib/bareos/plugins/bareos_sd_consts.py lib/bareos/plugins/BareosSdPluginBaseclass.py lib/bareos/plugins/BareosSdWrapper.py lib/bareos/plugins/bareos-sd-class-plugin.py diff --git a/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.traymonitor b/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.traymonitor index 850ef3d33f3..55d4ab569d6 100644 --- a/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.traymonitor +++ b/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.traymonitor @@ -204,9 +204,6 @@ lib/bareos/plugins/bareos-fd-mock-test.py lib/bareos/plugins/bareos-fd.py.template lib/bareos/plugins/bareos-sd-class-plugin.py lib/bareos/plugins/bareos-sd.py.template -lib/bareos/plugins/bareos_dir_consts.py -lib/bareos/plugins/bareos_fd_consts.py -lib/bareos/plugins/bareos_sd_consts.py lib/bareos/plugins/bpipe-fd.so lib/bareos/plugins/python-dir.so lib/bareos/plugins/python-fd.so diff --git a/core/platforms/freebsd/bareos-freebsd/bareos.com-common/plist b/core/platforms/freebsd/bareos-freebsd/bareos.com-common/plist index 51e03ae1e19..9a108f9c23e 100644 --- a/core/platforms/freebsd/bareos-freebsd/bareos.com-common/plist +++ b/core/platforms/freebsd/bareos-freebsd/bareos.com-common/plist @@ -204,9 +204,6 @@ lib/bareos/plugins/bareos-fd-mock-test.py lib/bareos/plugins/bareos-fd.py.template lib/bareos/plugins/bareos-sd-class-plugin.py lib/bareos/plugins/bareos-sd.py.template -lib/bareos/plugins/bareos_dir_consts.py -lib/bareos/plugins/bareos_fd_consts.py -lib/bareos/plugins/bareos_sd_consts.py lib/bareos/plugins/bpipe-fd.so lib/bareos/plugins/python-dir.so lib/bareos/plugins/python-fd.so diff --git a/core/platforms/packaging/bareos.spec b/core/platforms/packaging/bareos.spec index a61edaabb98..2fe3d07fdd5 100644 --- a/core/platforms/packaging/bareos.spec +++ b/core/platforms/packaging/bareos.spec @@ -1549,7 +1549,6 @@ mkdir -p %{?buildroot}/%{_libdir}/bareos/plugins/vmware_plugin %{plugin_dir}/BareosFdPluginBaseclass.py* %{plugin_dir}/BareosFdPluginLocalFileset.py* %{plugin_dir}/BareosFdWrapper.py* -%{plugin_dir}/bareos_fd_consts.py* %files filedaemon-ldap-python-plugin %defattr(-, root, root) @@ -1583,7 +1582,6 @@ mkdir -p %{?buildroot}/%{_libdir}/bareos/plugins/vmware_plugin %defattr(-, root, root) %{plugin_dir}/python-dir.so %{plugin_dir}/bareos-dir.py* -%{plugin_dir}/bareos_dir_consts.py* %{plugin_dir}/BareosDirPluginBaseclass.py* %{plugin_dir}/bareos-dir-class-plugin.py* %{plugin_dir}/BareosDirWrapper.py* @@ -1592,7 +1590,6 @@ mkdir -p %{?buildroot}/%{_libdir}/bareos/plugins/vmware_plugin %defattr(-, root, root) %{plugin_dir}/python-sd.so %{plugin_dir}/bareos-sd.py* -%{plugin_dir}/bareos_sd_consts.py* %{plugin_dir}/BareosSdPluginBaseclass.py* %{plugin_dir}/BareosSdWrapper.py* %{plugin_dir}/bareos-sd-class-plugin.py* diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index 6fc28e79d04..bda14aaf2be 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -39,7 +39,7 @@ if(HAVE_PYTHON) set(PYFILES python/pyfiles/bareos-dir.py.template python/pyfiles/bareos-dir-class-plugin.py - python/pyfiles/bareos_dir_consts.py python/pyfiles/BareosDirPluginBaseclass.py + python/pyfiles/BareosDirPluginBaseclass.py python/pyfiles/BareosDirWrapper.py ) diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index 157e9725f23..e0f5a74eaee 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -178,17 +178,17 @@ set(PYFILES python/pyfiles/BareosFdPluginBaseclass.py python/pyfiles/BareosFdPluginLocalFileset.py python/pyfiles/BareosFdWrapper.py - python/pyfiles/bareos_fd_consts.py - python/pyfiles/bareos-fd-ldap.py - python/pyfiles/BareosFdPluginLDAP.py - python/pyfiles/bareos-fd-ovirt.py - python/pyfiles/BareosFdPluginOvirt.py - python/pyfiles/bareos-fd-percona-xtrabackup.py - python/pyfiles/BareosFdPluginPerconaXtraBackup.py - python/pyfiles/BareosFdPluginPostgres.py + python/pyfiles/bareos-fd.py.template python/pyfiles/bareos-fd-postgres.py - python/pyfiles/BareosFdPluginVMware.py + python/pyfiles/BareosFdPluginPostgres.py python/pyfiles/bareos-fd-vmware.py + python/pyfiles/BareosFdPluginVMware.py + python/pyfiles/ldap/BareosFdPluginLDAP.py + python/pyfiles/ldap/bareos-fd-ldap.py + python/pyfiles/ovirt/BareosFdPluginOvirt.py + python/pyfiles/ovirt/bareos-fd-ovirt.py + python/pyfiles/percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py + python/pyfiles/percona-xtrabackup/bareos-fd-percona-xtrabackup.py ) if(${HAVE_VIXDISKLIB}) list(APPEND PYFILES BareosFdPluginVMware.py bareos-fd-vmware.py) diff --git a/core/src/plugins/stored/CMakeLists.txt b/core/src/plugins/stored/CMakeLists.txt index ba3b5da4e5a..2e5ecf51a51 100644 --- a/core/src/plugins/stored/CMakeLists.txt +++ b/core/src/plugins/stored/CMakeLists.txt @@ -56,7 +56,6 @@ if(HAVE_PYTHON) set(PYFILES python/pyfiles/bareos-sd-class-plugin.py - python/pyfiles/bareos_sd_consts.py python/pyfiles/BareosSdPluginBaseclass.py python/pyfiles/bareos-sd.py.template python/pyfiles/BareosSdWrapper.py diff --git a/debian/bareos-director-python-plugin.install.in b/debian/bareos-director-python-plugin.install.in index 12702a8230c..b672b4350b8 100644 --- a/debian/bareos-director-python-plugin.install.in +++ b/debian/bareos-director-python-plugin.install.in @@ -1,6 +1,5 @@ @plugindir@/python-dir.so @plugindir@/bareos-dir.py* -@plugindir@/bareos_dir_consts.py* @plugindir@/BareosDirWrapper.py* @plugindir@/BareosDirPluginBaseclass.py* @plugindir@/bareos-dir-class-plugin.py* diff --git a/debian/bareos-filedaemon-python-plugin.install.in b/debian/bareos-filedaemon-python-plugin.install.in index 573d06207dd..3bf491d5480 100644 --- a/debian/bareos-filedaemon-python-plugin.install.in +++ b/debian/bareos-filedaemon-python-plugin.install.in @@ -5,4 +5,3 @@ @plugindir@/BareosFdPluginBaseclass.py* @plugindir@/BareosFdPluginLocalFileset.py* @plugindir@/BareosFdWrapper.py* -@plugindir@/bareos_fd_consts.py* diff --git a/debian/bareos-storage-python-plugin.install.in b/debian/bareos-storage-python-plugin.install.in index aa57582d98b..d04f8550fb0 100644 --- a/debian/bareos-storage-python-plugin.install.in +++ b/debian/bareos-storage-python-plugin.install.in @@ -1,6 +1,5 @@ @plugindir@/python-sd.so @plugindir@/bareos-sd.py* -@plugindir@/bareos_sd_consts.py* @plugindir@/BareosSdPluginBaseclass.py* @plugindir@/BareosSdWrapper.py* @plugindir@/bareos-sd-class-plugin.py* From 731fe115e04e92626ea7573ae285af7c467a7e49 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 13 Aug 2020 12:42:49 +0200 Subject: [PATCH 041/341] cmake: make BareosInstallConfigFiles work with plugin subdirs --- core/CMakeLists.txt | 30 +++++++++++++++++++++++ core/cmake/BareosInstallConfigFiles.cmake | 12 ++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 2c54f4f164e..c3bf0fd50f7 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -674,6 +674,36 @@ if(${lmdb}) endif() # info what the config files need to be installed PLUGINS ############ +set(PLUGINS python-ldap) +list(APPEND PLUGINS python-ovirt) + +if(${HAVE_CEPHFS}) + list(APPEND PLUGINS cephfs) +endif() +if(${HAVE_CEPH_RADOS}) + list(APPEND PLUGINS rados) +endif() + +if(${HAVE_GLUSTERFS}) + list(APPEND PLUGINS gfapi) +endif() + +# BACKENDS #### +if(build_client_only) + set(BACKENDS "") +else() + set(BACKENDS unix_tape_device.d) + list(APPEND BACKENDS unix_fifo_device.d) + if(${HAVE_CEPHFS}) + list(APPEND BACKENDS rados_device.d) + endif() + if(${HAVE_GLUSTERFS}) + list(APPEND BACKENDS gfapi_device.d) + endif() + if(${HAVE_DROPLET}) + list(APPEND BACKENDS droplet_device.d) + endif() +endif() set(support_systemd "") set(batch_insert_db_backends "") diff --git a/core/cmake/BareosInstallConfigFiles.cmake b/core/cmake/BareosInstallConfigFiles.cmake index 25d6723a68f..bd311cc2178 100644 --- a/core/cmake/BareosInstallConfigFiles.cmake +++ b/core/cmake/BareosInstallConfigFiles.cmake @@ -159,8 +159,18 @@ macro( # install configs from fd plugins foreach(PLUGIN ${PLUGINS}) message(STATUS "install config files for PLUGIN ${PLUGIN}") + + # if plugin has -, conf.d directory is: + # python-ovirt -> python/ovirt/python-ovirt-conf.d + # else it is : + # cephfs -> cephfs/cephfs-conf.d + + string(REPLACE "-" "/" PLUGINPATH "${PLUGIN}") + string(APPEND PLUGINPATH "/" ${PLUGIN} "-conf.d") + message(STATUS "PLUGINPATH for PLUGIN ${PLUGIN} is ${PLUGINPATH}") + file(GLOB resourcedirs - "${SRC_DIR}/src/plugins/filed/${PLUGIN}/${CONFIGBASEDIRECTORY}/*") + "${SRC_DIR}/src/plugins/filed/${PLUGINPATH}/${CONFIGBASEDIRECTORY}/*") foreach(resdir ${resourcedirs}) file(GLOB configfiles "${resdir}/*.conf*") get_filename_component(resname ${resdir} NAME) From 9aa41ec096f740985c621ae05a88508de195f8ce Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 18 Mar 2020 17:47:41 +0100 Subject: [PATCH 042/341] python modules: add c++11 compile settings in setup.py.in --- core/src/plugins/dird/python/setup.py.in | 3 ++- core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py | 2 +- core/src/plugins/filed/python/setup.py.in | 3 ++- core/src/plugins/stored/python/setup.py.in | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/src/plugins/dird/python/setup.py.in b/core/src/plugins/dird/python/setup.py.in index ec9f2d55e37..ddcb9227aec 100644 --- a/core/src/plugins/dird/python/setup.py.in +++ b/core/src/plugins/dird/python/setup.py.in @@ -4,7 +4,8 @@ module1 = Extension('bareosdir', sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/python-dir.cc'], include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..'], libraries = ['bareos'], - library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'] + library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'], + extra_compile_args=['-std=c++11'], ) setup (name = 'bareosdir', diff --git a/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py b/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py index ef626899836..98083a10a9d 100644 --- a/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py +++ b/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py @@ -1075,7 +1075,7 @@ def get_proxy_connection(self, proxy_url): # your CA certificate of the engine in the system, you need to pass it to HTTPSConnection. context.load_verify_locations(cafile=self.ca) - return HTTPSConnection(proxy_url.hostname, proxy_url.port=context) + return HTTPSConnection(proxy_url.hostname, proxy_url.port) def start_download(self, snapshot, disk): diff --git a/core/src/plugins/filed/python/setup.py.in b/core/src/plugins/filed/python/setup.py.in index 6b8995e853a..c60bc1b0597 100644 --- a/core/src/plugins/filed/python/setup.py.in +++ b/core/src/plugins/filed/python/setup.py.in @@ -4,7 +4,8 @@ module1 = Extension('bareosfd', sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/python-fd.cc'], include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..'], libraries = ['bareos'], - library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'] + library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'], + extra_compile_args=['-std=c++11'], ) setup (name = 'bareosfd', diff --git a/core/src/plugins/stored/python/setup.py.in b/core/src/plugins/stored/python/setup.py.in index 5adda30f721..ea277906cba 100644 --- a/core/src/plugins/stored/python/setup.py.in +++ b/core/src/plugins/stored/python/setup.py.in @@ -4,7 +4,8 @@ module1 = Extension('bareossd', sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/python-sd.cc'], include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..'], libraries = ['bareos'], - library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'] + library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'], + extra_compile_args=['-std=c++11'], ) setup (name = 'bareossd', From c61c5d0252f92f7cc0d48363afaf9e1ba58ae69f Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 18 Mar 2020 18:19:03 +0100 Subject: [PATCH 043/341] python plugins: don't build on windows or darwin --- core/src/plugins/dird/CMakeLists.txt | 2 +- core/src/plugins/filed/CMakeLists.txt | 4 ++-- core/src/plugins/stored/CMakeLists.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index bda14aaf2be..5abc8d5ca39 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -46,7 +46,7 @@ if(HAVE_PYTHON) install(FILES ${PYFILES} DESTINATION ${plugindir}) endif() -if(HAVE_PYTHON) +if(HAVE_PYTHON AND NOT HAVE_WIN32) configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) add_custom_command( TARGET python-dir diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index e0f5a74eaee..5fb9bd8800a 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -107,7 +107,7 @@ if(HAVE_PYTHON) target_link_libraries(python-fd ${PYTHON_LIBRARIES} bareos) endif() -if(HAVE_PYTHON) +if(HAVE_PYTHON AND NOT HAVE_WIN32) add_executable(bareos-fd-module-tester python/test/python-fd-module-tester.cc) target_link_libraries(bareos-fd-module-tester ${PYTHON_LIBRARIES} bareos) @@ -123,7 +123,7 @@ if(HAVE_PYTHON) endif() -if(HAVE_PYTHON) +if(HAVE_PYTHON AND NOT HAVE_WIN32 AND NOT HAVE_DARWIN_OS) configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) add_custom_command( TARGET python-fd diff --git a/core/src/plugins/stored/CMakeLists.txt b/core/src/plugins/stored/CMakeLists.txt index 2e5ecf51a51..75e9429edda 100644 --- a/core/src/plugins/stored/CMakeLists.txt +++ b/core/src/plugins/stored/CMakeLists.txt @@ -64,7 +64,7 @@ if(HAVE_PYTHON) install(FILES ${PYFILES} DESTINATION ${plugindir}) endif() -if(HAVE_PYTHON) +if(HAVE_PYTHON AND NOT HAVE_WIN32) configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) add_custom_command( TARGET python-sd From 1b3a2d1d9686ce73ec340b7f513ba8af4cab1ede Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 19 Mar 2020 15:05:27 +0100 Subject: [PATCH 044/341] windows installer: don't try to package bareos_{sd,fd,dir}_consts.py --- core/platforms/win32/winbareos-nsi.spec | 3 ++- core/platforms/win32/winbareos.nsi | 3 --- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/core/platforms/win32/winbareos-nsi.spec b/core/platforms/win32/winbareos-nsi.spec index 27fe6452c67..e9f8a6e7475 100644 --- a/core/platforms/win32/winbareos-nsi.spec +++ b/core/platforms/win32/winbareos-nsi.spec @@ -262,7 +262,8 @@ for flavor in %{flavors}; do cp -rv /bareos*/platforms/win32/fillup.sed $RPM_BUILD_ROOT/$flavor/release${BITS}/config mkdir $RPM_BUILD_ROOT/$flavor/release${BITS}/Plugins - cp -rv /bareos*/src/plugins/*/*.py $RPM_BUILD_ROOT/$flavor/release${BITS}/Plugins + + cp -rv /bareos*/src/plugins/*/pyfiles/*.py $RPM_BUILD_ROOT/$flavor/release${BITS}/Plugins cp %SOURCE1 %SOURCE2 %SOURCE3 %SOURCE4 %SOURCE6 %SOURCE9 \ %_sourcedir/LICENSE $RPM_BUILD_ROOT/$flavor/release${BITS} diff --git a/core/platforms/win32/winbareos.nsi b/core/platforms/win32/winbareos.nsi index 016fd62a9b7..aecfa6689a8 100644 --- a/core/platforms/win32/winbareos.nsi +++ b/core/platforms/win32/winbareos.nsi @@ -624,7 +624,6 @@ SectionIn 1 2 3 4 File "Plugins\BareosFd*.py" File "Plugins\bareos-fd*.py" - File "Plugins\bareos_fd*.py" SectionEnd @@ -687,7 +686,6 @@ SectionIn 2 3 File "*-sd.dll" File "Plugins\BareosSd*.py" File "Plugins\bareos-sd*.py" - File "Plugins\bareos_sd*.py" SectionEnd @@ -903,7 +901,6 @@ SectionIn 2 3 File "*-dir.dll" File "Plugins\BareosDir*.py" File "Plugins\bareos-dir*.py" - File "Plugins\bareos_dir*.py" SectionEnd From caf6522c9cb412c67ca8e9df6b20dca17a16ca80 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 19 Mar 2020 17:11:13 +0100 Subject: [PATCH 045/341] python-fd: build on Darwin (Mac) --- core/CMakeLists.txt | 1 + core/src/plugins/filed/CMakeLists.txt | 2 +- core/src/plugins/filed/python/setup.py.in | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index c3bf0fd50f7..c675f08622f 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -161,6 +161,7 @@ include(CTest) if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(OPENSSL_ROOT_DIR /usr/local/opt/openssl) set(Readline_ROOT_DIR /usr/local/opt/readline) + set(Intl_ROOT_DIR /usr/local/opt/gettext) endif() if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index 5fb9bd8800a..5f9ab0039d4 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -123,7 +123,7 @@ if(HAVE_PYTHON AND NOT HAVE_WIN32) endif() -if(HAVE_PYTHON AND NOT HAVE_WIN32 AND NOT HAVE_DARWIN_OS) +if(HAVE_PYTHON AND NOT HAVE_WIN32) configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) add_custom_command( TARGET python-fd diff --git a/core/src/plugins/filed/python/setup.py.in b/core/src/plugins/filed/python/setup.py.in index c60bc1b0597..9fbe9b40976 100644 --- a/core/src/plugins/filed/python/setup.py.in +++ b/core/src/plugins/filed/python/setup.py.in @@ -2,7 +2,7 @@ from distutils.core import setup, Extension module1 = Extension('bareosfd', sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/python-fd.cc'], - include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..'], + include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..', '/usr/local/opt/gettext/include', '/usr/local/opt/openssl/include'], libraries = ['bareos'], library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'], extra_compile_args=['-std=c++11'], From 2c2e251a035a9501e5897dc12961dfcec970dc97 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 20 Mar 2020 07:42:46 +0100 Subject: [PATCH 046/341] python-fd: do GetPluginContextFromPythonModule() before checking with macro --- core/src/plugins/filed/python/python-fd.cc | 46 +++++++--------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 0a3c963aaa5..ca155e09cc3 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -2412,7 +2412,6 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "O:BareosRegisterEvents", &pyEvents)) { goto bail_out; } - bareos_plugin_ctx = GetPluginContextFromPythonModule(); RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); @@ -2459,8 +2458,6 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) if (!pySeq) { goto bail_out; } len = PySequence_Fast_GET_SIZE(pySeq); - - bareos_plugin_ctx = GetPluginContextFromPythonModule(); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); @@ -2487,13 +2484,11 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getInstanceCount(bareos_plugin_ctx, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } @@ -2513,12 +2508,11 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) { char* file = NULL; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (!PyArg_ParseTuple(args, "|z:BareosAddExclude", &file)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (file) { bareos_plugin_ctx = GetPluginContextFromPythonModule(); @@ -2536,12 +2530,11 @@ static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) { char* file = NULL; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (!PyArg_ParseTuple(args, "|z:BareosAddInclude", &file)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (file) { bareos_plugin_ctx = GetPluginContextFromPythonModule(); @@ -2559,12 +2552,11 @@ static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) { char* opts = NULL; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (!PyArg_ParseTuple(args, "|z:BareosAddOptions", &opts)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (opts) { bareos_plugin_ctx = GetPluginContextFromPythonModule(); @@ -2583,19 +2575,14 @@ static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) { int type; char* item = NULL; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; - - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|zi:BareosAddRegex", &item, &type)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (item) { - bareos_plugin_ctx = GetPluginContextFromPythonModule(); - retval = bfuncs->AddRegex(bareos_plugin_ctx, item, type); - } + if (item) { retval = bfuncs->AddRegex(bareos_plugin_ctx, item, type); } bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2609,9 +2596,8 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) { int type; char* item = NULL; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|zi:BareosAddWild", &item, &type)) { goto bail_out; @@ -2634,7 +2620,6 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) { bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewOptions")) { goto bail_out; } @@ -2654,7 +2639,6 @@ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) { bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewInclude")) { goto bail_out; } @@ -2674,7 +2658,6 @@ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) { bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewPreInclude")) { goto bail_out; } @@ -2699,13 +2682,13 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) struct save_pkt sp; bRC retval = bRC_Error; PySavePacket* pSavePkt; + bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "O:BareosCheckChanges", &pSavePkt)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - bareos_plugin_ctx = GetPluginContextFromPythonModule(); /* * CheckFile only has a need for a limited version of the PySavePacket so we @@ -2753,14 +2736,13 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) struct save_pkt sp; bRC retval = bRC_Error; PySavePacket* pSavePkt; + bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "O:BareosAcceptFile", &pSavePkt)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - bareos_plugin_ctx = GetPluginContextFromPythonModule(); - /* * Acceptfile only needs fname and statp from PySavePacket so we handle * that here separately and don't call PySavePacketToNative(). @@ -2798,13 +2780,13 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; + bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "O|s:BareosSetSeenBitmap", &pyBool, &fname)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - bareos_plugin_ctx = GetPluginContextFromPythonModule(); all = PyObject_IsTrue(pyBool); retval = bfuncs->SetSeenBitmap(bareos_plugin_ctx, all, fname); @@ -2824,13 +2806,13 @@ static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; + bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "O|s:BareosClearSeenBitmap", &pyBool, &fname)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - bareos_plugin_ctx = GetPluginContextFromPythonModule(); all = PyObject_IsTrue(pyBool); retval = bfuncs->ClearSeenBitmap(bareos_plugin_ctx, all, fname); From effb2928d90b62e9cc4058102a42364a02e4c92a Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 20 Mar 2020 07:44:54 +0100 Subject: [PATCH 047/341] python-fd: remove not required bareos_plugin_ctx = GetPluginContextFromPythonModule --- core/src/plugins/filed/python/python-fd.cc | 31 +++------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index ca155e09cc3..676aabce58d 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -2266,7 +2266,6 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarPrefixLinks: { int value = 0; - bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (bVariable)var, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); @@ -2280,7 +2279,6 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarRegexWhere: { char* value = NULL; - bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (bVariable)var, &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } @@ -2290,7 +2288,6 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarFileSeen: break; /* a write only variable, ignore read request */ default: - bareos_plugin_ctx = GetPluginContextFromPythonModule(); Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: PyBareosGetValue unknown variable requested %d\n", var); break; @@ -2344,7 +2341,6 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) break; } default: - bareos_plugin_ctx = GetPluginContextFromPythonModule(); Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: PyBareosSetValue unknown variable requested %d\n", var); break; @@ -2514,10 +2510,7 @@ static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "|z:BareosAddExclude", &file)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (file) { - bareos_plugin_ctx = GetPluginContextFromPythonModule(); - retval = bfuncs->AddExclude(bareos_plugin_ctx, file); - } + if (file) { retval = bfuncs->AddExclude(bareos_plugin_ctx, file); } bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2536,10 +2529,7 @@ static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "|z:BareosAddInclude", &file)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (file) { - bareos_plugin_ctx = GetPluginContextFromPythonModule(); - retval = bfuncs->AddInclude(bareos_plugin_ctx, file); - } + if (file) { retval = bfuncs->AddInclude(bareos_plugin_ctx, file); } bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2558,10 +2548,7 @@ static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "|z:BareosAddOptions", &opts)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (opts) { - bareos_plugin_ctx = GetPluginContextFromPythonModule(); - retval = bfuncs->AddOptions(bareos_plugin_ctx, opts); - } + if (opts) { retval = bfuncs->AddOptions(bareos_plugin_ctx, opts); } bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2604,10 +2591,7 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (item) { - bareos_plugin_ctx = GetPluginContextFromPythonModule(); - retval = bfuncs->AddWild(bareos_plugin_ctx, item, type); - } + if (item) { retval = bfuncs->AddWild(bareos_plugin_ctx, item, type); } bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2625,7 +2609,6 @@ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, ":BareosNewOptions")) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - bareos_plugin_ctx = GetPluginContextFromPythonModule(); retval = bfuncs->NewOptions(bareos_plugin_ctx); bail_out: @@ -2644,7 +2627,6 @@ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, ":BareosNewInclude")) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - bareos_plugin_ctx = GetPluginContextFromPythonModule(); retval = bfuncs->NewInclude(bareos_plugin_ctx); bail_out: @@ -2663,7 +2645,6 @@ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, ":BareosNewPreInclude")) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - bareos_plugin_ctx = GetPluginContextFromPythonModule(); retval = bfuncs->NewPreInclude(bareos_plugin_ctx); bail_out: @@ -2682,7 +2663,6 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) struct save_pkt sp; bRC retval = bRC_Error; PySavePacket* pSavePkt; - bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "O:BareosCheckChanges", &pSavePkt)) { goto bail_out; @@ -2736,7 +2716,6 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) struct save_pkt sp; bRC retval = bRC_Error; PySavePacket* pSavePkt; - bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "O:BareosAcceptFile", &pSavePkt)) { goto bail_out; @@ -2780,7 +2759,6 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; - bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "O|s:BareosSetSeenBitmap", &pyBool, &fname)) { goto bail_out; @@ -2806,7 +2784,6 @@ static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; - bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "O|s:BareosClearSeenBitmap", &pyBool, &fname)) { goto bail_out; From 0eb943019e1f844910e9e26848cad9599272caf6 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 20 Mar 2020 17:38:42 +0100 Subject: [PATCH 048/341] python plugins: split up macros for check of plugin function pointers --- core/src/plugins/filed/python/python-fd.cc | 2 +- core/src/plugins/python_plugins_common.h | 26 +++++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 676aabce58d..41b54cd75d3 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -2364,7 +2364,7 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + RETURN_RUNTIME_ERROR_IF_BAREOS_PLUGIN_CTX_UNSET() if (dbgmsg) { Dmsg(bareos_plugin_ctx, level, "python-fd: %s", dbgmsg); } Py_INCREF(Py_None); diff --git a/core/src/plugins/python_plugins_common.h b/core/src/plugins/python_plugins_common.h index 13cff3dde34..efff02c04b2 100644 --- a/core/src/plugins/python_plugins_common.h +++ b/core/src/plugins/python_plugins_common.h @@ -43,18 +43,28 @@ #define MOD_DEF(ob, name, doc, methods) ob = Py_InitModule3(name, methods, doc); #endif +#define STRINGIFY(x) #x +#define TOSTRING(x) STRINGIFY(x) +#define AT __FILE__ ":" TOSTRING(__LINE__) + /* check if bareos_plugin_ctx and bfunc are set. * Otherwise return NULL and throw RuntimeError */ -#define RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() \ - if (!bareos_plugin_ctx) { \ - PyErr_SetString(PyExc_RuntimeError, "bareos_plugin_ctx is unset"); \ - return NULL; \ - } \ - if (!bfuncs) { \ - PyErr_SetString(PyExc_RuntimeError, "bfuncs is unset"); \ - return NULL; \ + +#define RETURN_RUNTIME_ERROR_IF_BAREOS_PLUGIN_CTX_UNSET() \ + if (!bareos_plugin_ctx) { \ + PyErr_SetString(PyExc_RuntimeError, AT " :bareos_plugin_ctx is unset"); \ + return NULL; \ + } + +#define RETURN_RUNTIME_ERROR_IF_BFUNC_UNSET() \ + if (!bfuncs) { \ + PyErr_SetString(PyExc_RuntimeError, AT ": bfuncs is unset"); \ + return NULL; \ } +#define RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() \ + RETURN_RUNTIME_ERROR_IF_BAREOS_PLUGIN_CTX_UNSET() \ + RETURN_RUNTIME_ERROR_IF_BFUNC_UNSET() /* define the given string constant as member of an dict and additionally add it directly as constant to the module. From 44022d4e8366e67c073d1ef0c70b4338d3d919c7 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 20 Mar 2020 18:00:59 +0100 Subject: [PATCH 049/341] python-fd.cc: store bfuncs in plugin_priv_context --- core/src/plugins/filed/python/python-fd.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 41b54cd75d3..66b04be2b68 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -155,6 +155,7 @@ struct plugin_private_context { interpreter; /* Python interpreter for this instance of the plugin */ PyObject* pModule; /* Python Module entry point */ PyObject* pyModuleFunctionsDict; /* Python Dictionary */ + bFuncs* bfuncs; /* pointer to bfuncs */ }; /** @@ -236,6 +237,8 @@ static bRC newPlugin(bpContext* bareos_plugin_ctx) bareos_plugin_ctx->pContext = (void*)plugin_priv_ctx; /* set our context pointer */ + plugin_priv_ctx->bfuncs = bfuncs; + /* For each plugin instance we instantiate a new Python interpreter. */ PyEval_AcquireThread(mainThreadState); plugin_priv_ctx->interpreter = Py_NewInterpreter(); @@ -2360,6 +2363,9 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) int level; char* dbgmsg = NULL; bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + plugin_private_context* ppc = + (plugin_private_context*)bareos_plugin_ctx->pContext; + bfuncs = ppc->bfuncs; if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; From 22d7f750b197250928046f5ccdba2de3f435ae75 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 27 Mar 2020 14:31:55 +0100 Subject: [PATCH 050/341] PyStatPacket: give members the name as in os.stat() result --- core/src/plugins/filed/python/python-fd.h | 28 ++++++++++++----------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/core/src/plugins/filed/python/python-fd.h b/core/src/plugins/filed/python/python-fd.h index 4f2778af614..fcbfae17190 100644 --- a/core/src/plugins/filed/python/python-fd.h +++ b/core/src/plugins/filed/python/python-fd.h @@ -190,26 +190,28 @@ static PyMethodDef PyStatPacket_methods[] = { }; static PyMemberDef PyStatPacket_members[] = { - {(char*)"dev", T_UINT, offsetof(PyStatPacket, dev), 0, (char*)"Device"}, - {(char*)"ino", T_ULONGLONG, offsetof(PyStatPacket, ino), 0, + {(char*)"st_dev", T_UINT, offsetof(PyStatPacket, dev), 0, (char*)"Device"}, + {(char*)"st_ino", T_ULONGLONG, offsetof(PyStatPacket, ino), 0, (char*)"Inode number"}, - {(char*)"mode", T_USHORT, offsetof(PyStatPacket, mode), 0, (char*)"Mode"}, - {(char*)"nlink", T_USHORT, offsetof(PyStatPacket, nlink), 0, + {(char*)"st_mode", T_USHORT, offsetof(PyStatPacket, mode), 0, + (char*)"Mode"}, + {(char*)"st_nlink", T_USHORT, offsetof(PyStatPacket, nlink), 0, (char*)"Number of hardlinks"}, - {(char*)"uid", T_UINT, offsetof(PyStatPacket, uid), 0, (char*)"User Id"}, - {(char*)"gid", T_UINT, offsetof(PyStatPacket, gid), 0, (char*)"Group Id"}, - {(char*)"rdev", T_UINT, offsetof(PyStatPacket, rdev), 0, (char*)"Rdev"}, - {(char*)"size", T_ULONGLONG, offsetof(PyStatPacket, size), 0, + {(char*)"st_uid", T_UINT, offsetof(PyStatPacket, uid), 0, (char*)"User Id"}, + {(char*)"st_gid", T_UINT, offsetof(PyStatPacket, gid), 0, + (char*)"Group Id"}, + {(char*)"st_rdev", T_UINT, offsetof(PyStatPacket, rdev), 0, (char*)"Rdev"}, + {(char*)"st_size", T_ULONGLONG, offsetof(PyStatPacket, size), 0, (char*)"Size"}, - {(char*)"atime", T_UINT, offsetof(PyStatPacket, atime), 0, + {(char*)"st_atime", T_UINT, offsetof(PyStatPacket, atime), 0, (char*)"Access Time"}, - {(char*)"mtime", T_UINT, offsetof(PyStatPacket, mtime), 0, + {(char*)"st_mtime", T_UINT, offsetof(PyStatPacket, mtime), 0, (char*)"Modification Time"}, - {(char*)"ctime", T_UINT, offsetof(PyStatPacket, ctime), 0, + {(char*)"st_ctime", T_UINT, offsetof(PyStatPacket, ctime), 0, (char*)"Change Time"}, - {(char*)"blksize", T_UINT, offsetof(PyStatPacket, blksize), 0, + {(char*)"st_blksize", T_UINT, offsetof(PyStatPacket, blksize), 0, (char*)"Blocksize"}, - {(char*)"blocks", T_ULONGLONG, offsetof(PyStatPacket, blocks), 0, + {(char*)"st_blocks", T_ULONGLONG, offsetof(PyStatPacket, blocks), 0, (char*)"Blocks"}, {NULL}}; From 3eb58b6a6805c72e3e8d2ec1f799ff4dea5869aa Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 27 Apr 2020 16:41:45 +0200 Subject: [PATCH 051/341] python-sd: immediately do GetPluginContextFromPythonModule() --- .../python/pyfiles/BareosSdPluginBaseclass.py | 4 +-- core/src/plugins/stored/python/python-sd.cc | 34 +++++-------------- .../python-modules/bareos-sd-test.py | 34 +++++++++---------- 3 files changed, 28 insertions(+), 44 deletions(-) diff --git a/core/src/plugins/stored/python/pyfiles/BareosSdPluginBaseclass.py b/core/src/plugins/stored/python/pyfiles/BareosSdPluginBaseclass.py index c862db234cb..ca5ff9a2f6b 100644 --- a/core/src/plugins/stored/python/pyfiles/BareosSdPluginBaseclass.py +++ b/core/src/plugins/stored/python/pyfiles/BareosSdPluginBaseclass.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # BAREOS - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2014-2014 Bareos GmbH & Co. KG +# Copyright (C) 2014-2020 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -25,7 +25,7 @@ # Functions taken and adapted from bareos-sd.py import bareossd -from bareos_sd_consts import bsdEventType, bsdrVariable, bRCs +from bareossd import bsdEventType, bsdrVariable, bRCs import time diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index ae58bd93788..ae154a2574d 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -664,7 +664,7 @@ static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } @@ -677,7 +677,6 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bsdVarJobStatus: { int value; - bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (bsdrVariable)var, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); @@ -689,7 +688,6 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bsdVarJobBytes: { uint64_t value = 0; - bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (bsdrVariable)var, &value) == bRC_OK) { pRetVal = PyLong_FromUnsignedLong(value); @@ -706,7 +704,6 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bsdVarVolumeName: { char* value = NULL; - bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (bsdrVariable)var, &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } @@ -733,7 +730,6 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) break; } default: - bareos_plugin_ctx = GetPluginContextFromPythonModule(); Dmsg(bareos_plugin_ctx, debuglevel, "python-sd: PyBareosGetValue unknown variable requested %d\n", var); break; @@ -754,7 +750,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject* pyValue; @@ -767,7 +763,6 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bsdwVarVolumeName: { char* value; - bareos_plugin_ctx = GetPluginContextFromPythonModule(); value = PyString_AsString(pyValue); if (value) { bfuncs->setBareosValue(bareos_plugin_ctx, (bsdwVariable)var, value); @@ -779,7 +774,6 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bsdwVarJobLevel: { int value; - bareos_plugin_ctx = GetPluginContextFromPythonModule(); value = PyInt_AsLong(pyValue); if (value >= 0) { retval = bfuncs->setBareosValue(bareos_plugin_ctx, (bsdwVariable)var, @@ -788,7 +782,6 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) break; } default: - bareos_plugin_ctx = GetPluginContextFromPythonModule(); Dmsg(bareos_plugin_ctx, debuglevel, "python-sd: PyBareosSetValue unknown variable requested %d\n", var); break; @@ -807,17 +800,14 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (dbgmsg) { - bareos_plugin_ctx = GetPluginContextFromPythonModule(); - Dmsg(bareos_plugin_ctx, level, "python-sd: %s", dbgmsg); - } + if (dbgmsg) { Dmsg(bareos_plugin_ctx, level, "python-sd: %s", dbgmsg); } Py_INCREF(Py_None); return Py_None; @@ -832,17 +822,14 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (jobmsg) { - bareos_plugin_ctx = GetPluginContextFromPythonModule(); - Jmsg(bareos_plugin_ctx, type, "python-sd: %s", jobmsg); - } + if (jobmsg) { Jmsg(bareos_plugin_ctx, type, "python-sd: %s", jobmsg); } Py_INCREF(Py_None); return Py_None; @@ -856,7 +843,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -870,7 +857,6 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - bareos_plugin_ctx = GetPluginContextFromPythonModule(); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); @@ -898,7 +884,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -912,7 +898,6 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - bareos_plugin_ctx = GetPluginContextFromPythonModule(); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); @@ -940,13 +925,12 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!bareos_plugin_ctx) { PyErr_SetString(PyExc_ValueError, "bareos_plugin_ctx is unset"); return NULL; diff --git a/systemtests/tests/pyplug-sd/python-modules/bareos-sd-test.py b/systemtests/tests/pyplug-sd/python-modules/bareos-sd-test.py index 09cbc024f2e..182506411b2 100644 --- a/systemtests/tests/pyplug-sd/python-modules/bareos-sd-test.py +++ b/systemtests/tests/pyplug-sd/python-modules/bareos-sd-test.py @@ -1,6 +1,6 @@ # BAREOS - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2019-2019 Bareos GmbH & Co. KG +# Copyright (C) 2019-2020 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -20,27 +20,27 @@ # Author: Tobias Plum # from bareossd import * -from bareos_sd_consts import * +#from bareos_sd_consts import * def load_bareos_plugin(plugindef): events = [] - events.append(bsdEventType["bsdEventJobStart"]) - events.append(bsdEventType["bsdEventDeviceReserve"]) - events.append(bsdEventType["bsdEventVolumeUnload"]) - events.append(bsdEventType["bsdEventVolumeLoad"]) - events.append(bsdEventType["bsdEventDeviceOpen"]) - events.append(bsdEventType["bsdEventDeviceMount"]) - events.append(bsdEventType["bsdEventLabelRead"]) - events.append(bsdEventType["bsdEventLabelVerified"]) - events.append(bsdEventType["bsdEventLabelWrite"]) - events.append(bsdEventType["bsdEventSetupRecordTranslation"]) - events.append(bsdEventType["bsdEventWriteRecordTranslation"]) - events.append(bsdEventType["bsdEventDeviceUnmount"]) - events.append(bsdEventType["bsdEventDeviceClose"]) - events.append(bsdEventType["bsdEventJobEnd"]) + events.append(bsdEventJobStart) + events.append(bsdEventDeviceReserve) + events.append(bsdEventVolumeUnload) + events.append(bsdEventVolumeLoad) + events.append(bsdEventDeviceOpen) + events.append(bsdEventDeviceMount) + events.append(bsdEventLabelRead) + events.append(bsdEventLabelVerified) + events.append(bsdEventLabelWrite) + events.append(bsdEventSetupRecordTranslation) + events.append(bsdEventWriteRecordTranslation) + events.append(bsdEventDeviceUnmount) + events.append(bsdEventDeviceClose) + events.append(bsdEventJobEnd) RegisterEvents(events) - return bRCs["bRC_OK"] + return bRC_OK def parse_plugin_definition(plugindef): From 467056f763caa4f710ad38e58117683128751995 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 27 Apr 2020 16:58:55 +0200 Subject: [PATCH 052/341] python-dir: fix header file and python test --- core/src/plugins/dird/python/python-dir.cc | 34 +++++-------------- core/src/plugins/dird/python/python-dir.h | 6 ++-- .../python-modules/bareos-dir-test.py | 21 ++++++------ .../python-modules/bareos-sd-test.py | 2 -- 4 files changed, 22 insertions(+), 41 deletions(-) diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index f46e517407d..77b266f3f36 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -665,7 +665,7 @@ static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } @@ -682,7 +682,6 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarSDJobStatus: { int value = 0; - bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); @@ -698,7 +697,6 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarReadBytes: { uint64_t value = 0; - bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { pRetVal = PyLong_FromUnsignedLong(value); @@ -717,7 +715,6 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarVolumeName: { char* value = NULL; - bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getBareosValue(bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } @@ -733,7 +730,6 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) break; } default: - bareos_plugin_ctx = GetPluginContextFromPythonModule(); Dmsg(bareos_plugin_ctx, debuglevel, "python-dir: PyBareosGetValue unknown variable requested %d\n", var); break; @@ -754,7 +750,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject* pyValue; @@ -767,7 +763,6 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bwDirVarVolumeName: { char* value; - bareos_plugin_ctx = GetPluginContextFromPythonModule(); value = PyString_AsString(pyValue); if (value) { retval = bfuncs->setBareosValue(bareos_plugin_ctx, (bwDirVariable)var, @@ -780,7 +775,6 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bwDirVarJobLevel: { int value; - bareos_plugin_ctx = GetPluginContextFromPythonModule(); value = PyInt_AsLong(pyValue); if (value >= 0) { retval = bfuncs->setBareosValue(bareos_plugin_ctx, (bwDirVariable)var, @@ -789,7 +783,6 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) break; } default: - bareos_plugin_ctx = GetPluginContextFromPythonModule(); Dmsg(bareos_plugin_ctx, debuglevel, "python-dir: PyBareosSetValue unknown variable requested %d\n", var); break; @@ -808,17 +801,14 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (dbgmsg) { - bareos_plugin_ctx = GetPluginContextFromPythonModule(); - Dmsg(bareos_plugin_ctx, level, "python-dir: %s", dbgmsg); - } + if (dbgmsg) { Dmsg(bareos_plugin_ctx, level, "python-dir: %s", dbgmsg); } Py_INCREF(Py_None); return Py_None; @@ -833,17 +823,14 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (jobmsg) { - bareos_plugin_ctx = GetPluginContextFromPythonModule(); - Jmsg(bareos_plugin_ctx, type, "python-dir: %s", jobmsg); - } + if (jobmsg) { Jmsg(bareos_plugin_ctx, type, "python-dir: %s", jobmsg); } Py_INCREF(Py_None); return Py_None; @@ -857,7 +844,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -871,7 +858,6 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - bareos_plugin_ctx = GetPluginContextFromPythonModule(); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); @@ -899,7 +885,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -913,7 +899,6 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); - bareos_plugin_ctx = GetPluginContextFromPythonModule(); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); event = PyInt_AsLong(pyEvent); @@ -941,13 +926,12 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - bpContext* bareos_plugin_ctx = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (bfuncs->getInstanceCount(bareos_plugin_ctx, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } diff --git a/core/src/plugins/dird/python/python-dir.h b/core/src/plugins/dird/python/python-dir.h index 216abb7e766..891f533fe28 100644 --- a/core/src/plugins/dird/python/python-dir.h +++ b/core/src/plugins/dird/python/python-dir.h @@ -167,11 +167,11 @@ MOD_INIT(bareosdir) return MOD_ERROR_VAL; } - const char* bDirEvent = "bDirEvent"; + const char* bDirEvent = "bDirEventType"; PyObject* pDictbDirEvent = NULL; pDictbDirEvent = PyDict_New(); - ConstSet_StrLong(pDictbDirEvent, bEventJobStart, 1); - ConstSet_StrLong(pDictbDirEvent, bEventJobEnd, 2); + ConstSet_StrLong(pDictbDirEvent, bDirEventJobStart, 1); + ConstSet_StrLong(pDictbDirEvent, bDirEventJobEnd, 2); ConstSet_StrLong(pDictbDirEvent, bDirEventJobInit, 3); ConstSet_StrLong(pDictbDirEvent, bDirEventJobRun, 4); ConstSet_StrLong(pDictbDirEvent, bDirEventVolumePurged, 5); diff --git a/systemtests/tests/pyplug-dir/python-modules/bareos-dir-test.py b/systemtests/tests/pyplug-dir/python-modules/bareos-dir-test.py index 1d93545abbe..dcef111a4cf 100644 --- a/systemtests/tests/pyplug-dir/python-modules/bareos-dir-test.py +++ b/systemtests/tests/pyplug-dir/python-modules/bareos-dir-test.py @@ -1,6 +1,6 @@ # BAREOS - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2019-2019 Bareos GmbH & Co. KG +# Copyright (C) 2019-2020 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -20,17 +20,16 @@ # Author: Tobias Plum # from bareosdir import * -from bareos_dir_consts import * def load_bareos_plugin(plugindef): events = [] - events.append(bDirEventType["bDirEventJobStart"]) - events.append(bDirEventType["bDirEventJobEnd"]) - events.append(bDirEventType["bDirEventJobInit"]) - events.append(bDirEventType["bDirEventJobRun"]) + events.append(bDirEventJobStart) + events.append(bDirEventJobEnd) + events.append(bDirEventJobInit) + events.append(bDirEventJobRun) RegisterEvents(events) - return bRCs["bRC_OK"] + return bRC_OK def parse_plugin_definition(plugindef): @@ -57,16 +56,16 @@ def parse_plugin_definition(plugindef): def handle_plugin_event(event): - if event == bDirEventType["bDirEventJobStart"]: + if event == bDirEventJobStart: toFile("bDirEventJobStart\n") - elif event == bDirEventType["bDirEventJobEnd"]: + elif event == bDirEventJobEnd: toFile("bDirEventJobEnd\n") - elif event == bDirEventType["bDirEventJobInit"]: + elif event == bDirEventJobInit: toFile("bDirEventJobInit\n") - elif event == bDirEventType["bDirEventJobRun"]: + elif event == bDirEventJobRun: toFile("bDirEventJobRun\n") return bRCs["bRC_OK"] diff --git a/systemtests/tests/pyplug-sd/python-modules/bareos-sd-test.py b/systemtests/tests/pyplug-sd/python-modules/bareos-sd-test.py index 182506411b2..a99ffa2ffe5 100644 --- a/systemtests/tests/pyplug-sd/python-modules/bareos-sd-test.py +++ b/systemtests/tests/pyplug-sd/python-modules/bareos-sd-test.py @@ -20,8 +20,6 @@ # Author: Tobias Plum # from bareossd import * -#from bareos_sd_consts import * - def load_bareos_plugin(plugindef): events = [] From a820022d128ac3f4876db24b00ef059fa66c304b Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 27 Apr 2020 17:13:28 +0200 Subject: [PATCH 053/341] systemtests: set default timeout to 180 --- systemtests/CMakeLists.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 370fc7c212e..a80223c318a 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -793,8 +793,8 @@ foreach(TEST_NAME ${SYSTEM_TESTS}) configurefilestosystemtest("systemtests" "tests/${TEST_NAME}" "*" @ONLY "") set(pythonpath - "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/pyfiles:${CMAKE_SOURCE_DIR}/core/src/plugins/stored/python/pyfiles:${CMAKE_SOURCE_DIR}/core/src/plugins/dird/python/pyfiles:${CMAKE_CURRENT_SOURCE_DIR}/tests/${TEST_NAME}/python-modules") - + "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/pyfiles:${CMAKE_SOURCE_DIR}/core/src/plugins/stored/python/pyfiles:${CMAKE_SOURCE_DIR}/core/src/plugins/dird/python/pyfiles:${CMAKE_CURRENT_SOURCE_DIR}/tests/${TEST_NAME}/python-modules" + ) configure_file("environment.in" "tests/${TEST_NAME}/environment" @ONLY) @@ -805,7 +805,7 @@ foreach(TEST_NAME ${SYSTEM_TESTS}) COMMAND ${tests_dir}/${TEST_NAME}/testrunner WORKING_DIRECTORY ${tests_dir}/${TEST_NAME} ) - set_tests_properties(${SYSTEMTEST_PREFIX}${TEST_NAME} PROPERTIES TIMEOUT 90) + set_tests_properties(${SYSTEMTEST_PREFIX}${TEST_NAME} PROPERTIES TIMEOUT 180) math(EXPR BASEPORT "${BASEPORT} + 10") endforeach() @@ -865,7 +865,9 @@ if(ENABLE_WEBUI_SELENIUM_TEST) COMMAND ${tests_dir}/${TEST_NAME}/testrunner WORKING_DIRECTORY ${tests_dir}/${TEST_NAME} ) - set_tests_properties(${WEBUI_TEST_PREFIX}${TEST_NAME} PROPERTIES TIMEOUT 90) + set_tests_properties( + ${WEBUI_TEST_PREFIX}${TEST_NAME} PROPERTIES TIMEOUT 180 + ) math(EXPR BASEPORT "${BASEPORT} + 10") endforeach() endif() From 6540958ae24b8231ee9d50ec537d08df7a71ad11 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 28 Apr 2020 14:34:01 +0200 Subject: [PATCH 054/341] python-fd.cc: current status of bareosfd_test.py --- core/src/plugins/filed/python/python-fd.cc | 1 - .../plugins/filed/python/test/bareosfd_test.py | 16 ++++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 66b04be2b68..317a9f13dc8 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -2365,7 +2365,6 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); plugin_private_context* ppc = (plugin_private_context*)bareos_plugin_ctx->pContext; - bfuncs = ppc->bfuncs; if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; diff --git a/core/src/plugins/filed/python/test/bareosfd_test.py b/core/src/plugins/filed/python/test/bareosfd_test.py index f148f326dc1..3a66b4d3b2b 100644 --- a/core/src/plugins/filed/python/test/bareosfd_test.py +++ b/core/src/plugins/filed/python/test/bareosfd_test.py @@ -39,8 +39,8 @@ def test_bJobMessageType(self): # def test_SetValue(self): # self.assertRaises(RuntimeError, bareosfd.SetValue, 2) - def test_DebugMessage(self): - self.assertRaises(RuntimeError, bareosfd.DebugMessage, 100, "This is a debug message") + # def test_DebugMessage(self): + # self.assertRaises(RuntimeError, bareosfd.DebugMessage, 100, "This is a debug message") def test_RestoreObject(self): test_RestoreObject = bareosfd.RestoreObject() @@ -73,14 +73,14 @@ def test_StatPacket(self): test_StatPacket = bareosfd.StatPacket() # check that the initialization of timestamps from current time stamp works - self.assertAlmostEqual(test_StatPacket.atime, timestamp, delta=1) - self.assertAlmostEqual(test_StatPacket.mtime, timestamp, delta=1) - self.assertAlmostEqual(test_StatPacket.ctime, timestamp, delta=1) + self.assertAlmostEqual(test_StatPacket.st_atime, timestamp, delta=1) + self.assertAlmostEqual(test_StatPacket.st_mtime, timestamp, delta=1) + self.assertAlmostEqual(test_StatPacket.st_ctime, timestamp, delta=1) # set fixed values for comparison - test_StatPacket.atime=999 - test_StatPacket.mtime=1000 - test_StatPacket.ctime=1001 + test_StatPacket.st_atime=999 + test_StatPacket.st_mtime=1000 + test_StatPacket.st_ctime=1001 self.assertEqual( "StatPacket(dev=0, ino=0, mode=0700, nlink=0, uid=0, gid=0, rdev=0, size=-1, atime=999, mtime=1000, ctime=1001, blksize=4096, blocks=1)", str(test_StatPacket), From 1a50630c647ba691b125079c38adac91fe6c8e5a Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 20 Mar 2020 10:26:02 +0100 Subject: [PATCH 055/341] first try: to really load the bareosfd.so instead of the built-in one --- core/src/plugins/filed/python/python-fd.cc | 54 +++++++++++++++++++++- systemtests/CMakeLists.txt | 11 ++++- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 317a9f13dc8..f49e5cf5bd9 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -172,6 +172,45 @@ static PyThreadState* mainThreadState; extern "C" { #endif +static void PyErrorHandler() +{ + PyObject *type, *value, *traceback; + PyObject* tracebackModule; + char* error_string; + + PyErr_Fetch(&type, &value, &traceback); + + tracebackModule = PyImport_ImportModule("traceback"); + if (tracebackModule != NULL) { + PyObject *tbList, *emptyString, *strRetval; + + tbList = + PyObject_CallMethod(tracebackModule, (char*)"format_exception", + (char*)"OOO", type, value == NULL ? Py_None : value, + traceback == NULL ? Py_None : traceback); + + emptyString = PyString_FromString(""); + strRetval = + PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); + + error_string = strdup(PyString_AsString(strRetval)); + + Py_DECREF(tbList); + Py_DECREF(emptyString); + Py_DECREF(strRetval); + Py_DECREF(tracebackModule); + } else { + error_string = strdup("Unable to import traceback module."); + } + Py_DECREF(type); + Py_XDECREF(value); + Py_XDECREF(traceback); + printf("%s", error_string); + + free(error_string); + exit(1); +} + /** * Plugin called here when it is first loaded @@ -190,11 +229,22 @@ bRC loadPlugin(bInfo* lbinfo, if (!Py_IsInitialized()) { /* Setup Python */ #if PY_MAJOR_VERSION >= 3 - PyImport_AppendInittab("bareosfd", &PyInit_bareosfd); + /* PyImport_AppendInittab("bareosfd", &PyInit_bareosfd); */ #else - PyImport_AppendInittab("bareosfd", initbareosfd); + /* PyImport_AppendInittab("bareosfd", initbareosfd); */ #endif Py_InitializeEx(0); + + /* import the bareosfd module */ + PyObject* bareosfdModule = PyImport_ImportModule("bareosfd"); + if (bareosfdModule) { + printf("loaded bareosfd successfully\n"); + } else { + printf("loading of bareosfd failed\n"); + } + + if (PyErr_Occurred()) { PyErrorHandler(); } + PyEval_InitThreads(); mainThreadState = PyEval_SaveThread(); } diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index a80223c318a..9fef5df6788 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -792,8 +792,15 @@ foreach(TEST_NAME ${SYSTEM_TESTS}) prepare_test() configurefilestosystemtest("systemtests" "tests/${TEST_NAME}" "*" @ONLY "") - set(pythonpath - "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/pyfiles:${CMAKE_SOURCE_DIR}/core/src/plugins/stored/python/pyfiles:${CMAKE_SOURCE_DIR}/core/src/plugins/dird/python/pyfiles:${CMAKE_CURRENT_SOURCE_DIR}/tests/${TEST_NAME}/python-modules" + string( + CONCAT pythonpath + "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/pyfiles:" + "${CMAKE_SOURCE_DIR}/core/src/plugins/stored/python/pyfiles:" + "${CMAKE_SOURCE_DIR}/core/src/plugins/dird/python/pyfiles:" + "${CMAKE_BINARY_DIR}/core/src/plugins/filed/pythonmodules:" + "${CMAKE_BINARY_DIR}/core/src/plugins/stored/pythonmodules:" + "${CMAKE_SOURCE_DIR}/core/src/plugins/dird/pythonmodules:" + "${CMAKE_CURRENT_SOURCE_DIR}/tests/${TEST_NAME}/python-modules" ) configure_file("environment.in" "tests/${TEST_NAME}/environment" @ONLY) From 37da4e1caefb703faf44e6b8a7b385214ab4326f Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 29 Apr 2020 14:08:09 +0200 Subject: [PATCH 056/341] python-fd.cc: builds successfully --- core/src/plugins/filed/python/python-fd.cc | 47 +++++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index f49e5cf5bd9..00d3b159330 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -245,6 +245,49 @@ bRC loadPlugin(bInfo* lbinfo, if (PyErr_Occurred()) { PyErrorHandler(); } + // Extract capsules pointer from bareosfd module + void (*loadplugin_from_bareosfd_module)( + filedaemon::bInfo * lbinfo, filedaemon::bFuncs * lbfuncs, + genpInfo * *pinfo, filedaemon::pFuncs * *pfuncs) = + (void (*)(filedaemon::bInfo*, filedaemon::bFuncs*, genpInfo**, + filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", + 0); + + // Extract capsule bareosfd.bpContext + void* ctx_from_bareosfd_module = PyCapsule_Import("bareosfd.bpContext", 0); + if (!ctx_from_bareosfd_module) { + printf("importing bareosfd.bpContext failed \n"); + } + + // Extract capsules bareosfd.bFuncs + void* bfuncs_from_bareosfd_module = PyCapsule_Import("bareosfd.bFuncs", 0); + if (!bfuncs_from_bareosfd_module) { + printf("importing bareosfd.bFuncs failed \n"); + } + + if (!loadplugin_from_bareosfd_module) { + printf("importing bareosfd.loadPlugin failed \n"); + } + + + *(void**)ctx_from_bareosfd_module = &bareos_plugin_context; + *(void**)bfuncs_from_bareosfd_module = &bfuncs; + + /* call loadPlugin in plugin */ + filedaemon::bInfo myInfo; + genpInfo pinfo; + filedaemon::pFuncs pfuncs; + + loadplugin_from_bareosfd_module(&myInfo, bfuncs, (genpInfo**)&pinfo, + (filedaemon::pFuncs**)&pfuncs); + + + printf("ctx_from_bareosfd_module contains %p\n", + *(void**)ctx_from_bareosfd_module); + printf("bfuncs_from_bareosfd_module contains %p\n", + *(void**)bfuncs_from_bareosfd_module); + + PyEval_InitThreads(); mainThreadState = PyEval_SaveThread(); } @@ -2413,8 +2456,8 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) int level; char* dbgmsg = NULL; bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - plugin_private_context* ppc = - (plugin_private_context*)bareos_plugin_ctx->pContext; + /* plugin_private_context* ppc = */ + /* (plugin_private_context*)bareos_plugin_ctx->pContext; */ if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; From a1ce4d85baedec73a585c198b44d06f968132c7f Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 29 Apr 2020 15:50:04 +0200 Subject: [PATCH 057/341] bareosfd.cc python module has own source file --- core/src/plugins/filed/CMakeLists.txt | 13 +- core/src/plugins/filed/python/bareosfd.cc | 2708 +++++++++++++++++++++ core/src/plugins/filed/python/setup.py.in | 2 +- 3 files changed, 2718 insertions(+), 5 deletions(-) create mode 100644 core/src/plugins/filed/python/bareosfd.cc diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index 5f9ab0039d4..b2e775dd0e7 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -126,15 +126,20 @@ endif() if(HAVE_PYTHON AND NOT HAVE_WIN32) configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) add_custom_command( - TARGET python-fd - POST_BUILD - COMMENT "building python module pythonmodules/bareosfd.so" + OUTPUT pythonmodules/bareosfd.so + MAIN_DEPENDENCY ./python/bareosfd.cc + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py + #TARGET python-fd + #POST_BUILD COMMAND ${PYTHON_EXECUTABLE} python/setup.py build COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build DEPENDS python-fd + # COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build DEPENDS python-fd + COMMENT "building python module pythonmodules/bareosfd.so" ) + add_custom_target(bareosfd DEPENDS pythonmodules/bareosfd.so) + add_test(NAME bareosfd-python-module COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosfd_test.py diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc new file mode 100644 index 00000000000..3f3545a2585 --- /dev/null +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -0,0 +1,2708 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2011-2015 Planets Communications B.V. + Copyright (C) 2013-2020 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation, which is + listed in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +/* + * Marco van Wieringen, August 2012 + */ +/** + * @file + * Python plugin for the Bareos File Daemon + */ +#define PY_SSIZE_T_CLEAN +#define BUILD_PLUGIN + +#if defined(HAVE_WIN32) +#include "include/bareos.h" +#include +#else +#include +#include "include/bareos.h" +#endif + +#include "filed/fd_plugins.h" + + +#include "python-fd.h" +#include "lib/edit.h" + +namespace filedaemon { + +static const int debuglevel = 150; + +/* #define PLUGIN_LICENSE "Bareos AGPLv3" */ +/* #define PLUGIN_AUTHOR "Marco van Wieringen" */ +/* #define PLUGIN_DATE "May 2014" */ +/* #define PLUGIN_VERSION "3" */ +/* #define PLUGIN_DESCRIPTION "Python File Daemon Plugin" */ +/* #define PLUGIN_USAGE \ */ +/* "python:module_path=:module_name=:..." */ + +/* Forward referenced functions */ +/* static bRC newPlugin(bpContext* bareos_plugin_ctx); */ +/* static bRC freePlugin(bpContext* bareos_plugin_ctx); */ +/* static bRC getPluginValue(bpContext* bareos_plugin_ctx, */ +/* pVariable var, */ +/* void* value); */ +/* static bRC setPluginValue(bpContext* bareos_plugin_ctx, */ +/* pVariable var, */ +/* void* value); */ +/* static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, */ +/* bEvent* event, */ +/* void* value); */ +/* static bRC startBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* + * sp); */ +/* static bRC endBackupFile(bpContext* bareos_plugin_ctx); */ +/* static bRC pluginIO(bpContext* bareos_plugin_ctx, struct io_pkt* io); */ +/* static bRC startRestoreFile(bpContext* bareos_plugin_ctx, const char* cmd); + */ +/* static bRC endRestoreFile(bpContext* bareos_plugin_ctx); */ +/* static bRC createFile(bpContext* bareos_plugin_ctx, struct restore_pkt* rp); + */ +/* static bRC setFileAttributes(bpContext* bareos_plugin_ctx, */ +/* struct restore_pkt* rp); */ +/* static bRC checkFile(bpContext* bareos_plugin_ctx, char* fname); */ +/* static bRC getAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap); */ +/* static bRC setAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap); */ +/* static bRC getXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp); */ +/* static bRC setXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp); */ +/* static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, */ +/* void* value, */ +/* PoolMem& plugin_options); */ + + +static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype); +static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value); +static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value); +static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, + bEvent* event, + void* value); +static bRC PyStartBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp); +static bRC PyEndBackupFile(bpContext* bareos_plugin_ctx); +static bRC PyPluginIO(bpContext* bareos_plugin_ctx, struct io_pkt* io); +static bRC PyStartRestoreFile(bpContext* bareos_plugin_ctx, const char* cmd); +static bRC PyEndRestoreFile(bpContext* bareos_plugin_ctx); +static bRC PyCreateFile(bpContext* bareos_plugin_ctx, struct restore_pkt* rp); +static bRC PySetFileAttributes(bpContext* bareos_plugin_ctx, + struct restore_pkt* rp); +static bRC PyCheckFile(bpContext* bareos_plugin_ctx, char* fname); +static bRC PyGetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC PySetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC PyGetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC PySetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC PyRestoreObjectData(bpContext* bareos_plugin_ctx, + struct restore_object_pkt* rop); +static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, + struct save_pkt* sp); + +/* Pointers to Bareos functions */ +static bFuncs* bfuncs = NULL; +static bInfo* binfo = NULL; + +/* static genpInfo pluginInfo = {sizeof(pluginInfo), + * FD_PLUGIN_INTERFACE_VERSION, */ +/* FD_PLUGIN_MAGIC, PLUGIN_LICENSE, */ +/* PLUGIN_AUTHOR, PLUGIN_DATE, */ +/* PLUGIN_VERSION, PLUGIN_DESCRIPTION, */ +/* PLUGIN_USAGE}; */ + +/* static pFuncs pluginFuncs = { */ +/* sizeof(pluginFuncs), FD_PLUGIN_INTERFACE_VERSION, */ + +/* /1* Entry points into plugin *1/ */ +/* newPlugin, /1* new plugin instance *1/ */ +/* freePlugin, /1* free plugin instance *1/ */ +/* getPluginValue, setPluginValue, handlePluginEvent, startBackupFile, */ +/* endBackupFile, startRestoreFile, endRestoreFile, pluginIO, createFile, */ +/* setFileAttributes, checkFile, getAcl, setAcl, getXattr, setXattr}; */ + +struct plugin_private_context { + int32_t backup_level; /* Backup level e.g. Full/Differential/Incremental */ + utime_t since; /* Since time for Differential/Incremental */ + bool python_loaded; /* Plugin has python module loaded ? */ + bool python_path_set; /* Python plugin search path is set ? */ + char* plugin_options; /* Plugin Option string */ + char* module_path; /* Plugin Module Path */ + char* module_name; /* Plugin Module Name */ + char* fname; /* Next filename to save */ + char* link; /* Target symlink points to */ + char* object_name; /* Restore Object Name */ + char* object; /* Restore Object Content */ + PyThreadState* + interpreter; /* Python interpreter for this instance of the plugin */ + PyObject* pModule; /* Python Module entry point */ + PyObject* pyModuleFunctionsDict; /* Python Dictionary */ + bFuncs* bfuncs; /* pointer to bfuncs */ +}; + +/** + * We don't actually use this but we need it to tear down the + * final python interpreter on unload of the plugin. Each instance of + * the plugin get its own interpreter. + */ +static PyThreadState* mainThreadState; + +/* functions common to all plugins */ +#include "plugins/python_plugins_common.inc" + +#ifdef __cplusplus +extern "C" { +#endif + +static void PyErrorHandler() +{ + PyObject *type, *value, *traceback; + PyObject* tracebackModule; + char* error_string; + + PyErr_Fetch(&type, &value, &traceback); + + tracebackModule = PyImport_ImportModule("traceback"); + if (tracebackModule != NULL) { + PyObject *tbList, *emptyString, *strRetval; + + tbList = + PyObject_CallMethod(tracebackModule, (char*)"format_exception", + (char*)"OOO", type, value == NULL ? Py_None : value, + traceback == NULL ? Py_None : traceback); + + emptyString = PyString_FromString(""); + strRetval = + PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); + + error_string = strdup(PyString_AsString(strRetval)); + + Py_DECREF(tbList); + Py_DECREF(emptyString); + Py_DECREF(strRetval); + Py_DECREF(tracebackModule); + } else { + error_string = strdup("Unable to import traceback module."); + } + Py_DECREF(type); + Py_XDECREF(value); + Py_XDECREF(traceback); + printf("%s", error_string); + + free(error_string); + exit(1); +} + + +/** + * Plugin called here when it is first loaded + */ +/* bRC loadPlugin(bInfo* lbinfo, */ +/* bFuncs* lbfuncs, */ +/* genpInfo** pinfo, */ +/* pFuncs** pfuncs) */ +/* { */ +/* bfuncs = lbfuncs; /1* Set Bareos funct pointers *1/ */ +/* binfo = lbinfo; */ + +/* *pinfo = &pluginInfo; /1* Return pointer to our info *1/ */ +/* *pfuncs = &pluginFuncs; /1* Return pointer to our functions *1/ */ + +/* if (!Py_IsInitialized()) { */ +/* /1* Setup Python *1/ */ +/* #if PY_MAJOR_VERSION >= 3 */ +/* /1* PyImport_AppendInittab("bareosfd", &PyInit_bareosfd); *1/ */ +/* #else */ +/* /1* PyImport_AppendInittab("bareosfd", initbareosfd); *1/ */ +/* #endif */ +/* Py_InitializeEx(0); */ + +/* /1* import the bareosfd module *1/ */ +/* PyObject* bareosfdModule = PyImport_ImportModule("bareosfd"); */ +/* if (bareosfdModule) { */ +/* printf("loaded bareosfd successfully\n"); */ +/* } else { */ +/* printf("loading of bareosfd failed\n"); */ +/* } */ + +/* if (PyErr_Occurred()) { PyErrorHandler(); } */ + +/* // Extract capsules pointer from bareosfd module */ +/* void (*loadplugin_from_bareosfd_module)( */ +/* filedaemon::bInfo * lbinfo, filedaemon::bFuncs * lbfuncs, */ +/* genpInfo * *pinfo, filedaemon::pFuncs * *pfuncs) = */ +/* (void (*)(filedaemon::bInfo*, filedaemon::bFuncs*, genpInfo**, */ +/* filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", + */ +/* 0); */ + +/* // Extract capsule bareosfd.bpContext */ +/* void* ctx_from_bareosfd_module = PyCapsule_Import("bareosfd.bpContext", + * 0); */ +/* if (!ctx_from_bareosfd_module) { */ +/* printf("importing bareosfd.bpContext failed \n"); */ +/* } */ + +/* // Extract capsules bareosfd.bFuncs */ +/* void* bfuncs_from_bareosfd_module = PyCapsule_Import("bareosfd.bFuncs", + * 0); */ +/* if (!bfuncs_from_bareosfd_module) { */ +/* printf("importing bareosfd.bFuncs failed \n"); */ +/* } */ + +/* if (!loadplugin_from_bareosfd_module) { */ +/* printf("importing bareosfd.loadPlugin failed \n"); */ +/* } */ + + +/* *(void**)ctx_from_bareosfd_module = &bareos_plugin_context; */ +/* *(void**)bfuncs_from_bareosfd_module = &bfuncs; */ + +/* /1* call loadPlugin in plugin *1/ */ +/* filedaemon::bInfo myInfo; */ +/* genpInfo pinfo; */ +/* filedaemon::pFuncs pfuncs; */ + +/* loadplugin_from_bareosfd_module(&myInfo, bfuncs, (genpInfo**)&pinfo, */ +/* (filedaemon::pFuncs**)&pfuncs); */ + + +/* printf("ctx_from_bareosfd_module contains %p\n", */ +/* *(void**)ctx_from_bareosfd_module); */ +/* printf("bfuncs_from_bareosfd_module contains %p\n", */ +/* *(void**)bfuncs_from_bareosfd_module); */ + + +/* PyEval_InitThreads(); */ +/* mainThreadState = PyEval_SaveThread(); */ +/* } */ +/* return bRC_OK; */ +/* } */ + +/** + * Plugin called here when it is unloaded, normally when Bareos is going to + * exit. + */ +/*bRC unloadPlugin()*/ +/*{*/ +/* */ +/* * Terminate Python*/ +/* */ +/* PyEval_RestoreThread(mainThreadState);*/ +/* Py_Finalize();*/ + +/* return bRC_OK;*/ +/*}*/ + +#ifdef __cplusplus +} +#endif + + +/** + * Initial load of the Python module. + * + * Based on the parsed plugin options we set some prerequisites like the + * module path and the module to load. We also load the dictionary used + * for looking up the Python methods. + */ +static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; + PyObject *sysPath, *mPath, *pName, *pFunc; + + /* See if we already setup the python search path. */ + if (!plugin_priv_ctx->python_path_set) { + /* Extend the Python search path with the given module_path. */ + if (plugin_priv_ctx->module_path) { + sysPath = PySys_GetObject((char*)"path"); + mPath = PyString_FromString(plugin_priv_ctx->module_path); + PyList_Append(sysPath, mPath); + Py_DECREF(mPath); + plugin_priv_ctx->python_path_set = true; + } + } + + /* Try to load the Python module by name. */ + if (plugin_priv_ctx->module_name) { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Trying to load module with name %s\n", + plugin_priv_ctx->module_name); + pName = PyString_FromString(plugin_priv_ctx->module_name); + plugin_priv_ctx->pModule = PyImport_Import(pName); + Py_DECREF(pName); + + if (!plugin_priv_ctx->pModule) { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Failed to load module with name %s\n", + plugin_priv_ctx->module_name); + goto bail_out; + } + + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Successfully loaded module with name %s\n", + plugin_priv_ctx->module_name); + + /* Get the Python dictionary for lookups in the Python namespace. */ + plugin_priv_ctx->pyModuleFunctionsDict = + PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ + + /* Encode the bpContext so a Python method can pass it in on calling back.*/ + /* plugin_priv_ctx->py_bpContext = PyCreatebpContext(bareos_plugin_ctx); */ + + StorePluginContextInPythonModule(bareos_plugin_ctx); + + /* Lookup the load_bareos_plugin() function in the python module. */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "load_bareos_plugin"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyObject *pPluginDefinition, *pRetVal; + + pPluginDefinition = PyString_FromString((char*)value); + if (!pPluginDefinition) { goto bail_out; } + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); + /* pFunc, plugin_priv_ctx->py_bpContext, pPluginDefinition, NULL); */ + Py_DECREF(pPluginDefinition); + + if (!pRetVal) { + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + } + } else { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Failed to find function named load_bareos_plugins()\n"); + goto bail_out; + } + + /* + * Keep track we successfully loaded. + */ + plugin_priv_ctx->python_loaded = true; + } + + return retval; + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + return retval; +} + +/** + * Any plugin options which are passed in are dispatched here to a Python method + * and it can parse the plugin options. This function is also called after + * PyLoadModule() has loaded the Python module and made sure things are + * operational. Normally you would only get one set of plugin options but for a + * restore overrides can be passed in before the actual plugin options are + * restored as part of the restore stream handling. + */ +static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; + PyObject* pFunc; + + /* + * Lookup the parse_plugin_definition() function in the python module. + */ + pFunc = + PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "parse_plugin_definition"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyObject *pPluginDefinition, *pRetVal; + + pPluginDefinition = PyString_FromString((char*)value); + if (!pPluginDefinition) { goto bail_out; } + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); + Py_DECREF(pPluginDefinition); + + if (!pRetVal) { + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + } + + return retval; + } else { + Dmsg( + bareos_plugin_ctx, debuglevel, + "python-fd: Failed to find function named parse_plugin_definition()\n"); + return bRC_Error; + } + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + return retval; +} + +static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, + pVariable var, + void* value) +{ + return bRC_OK; +} + +static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, + pVariable var, + void* value) +{ + return bRC_OK; +} + +static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, + bEvent* event, + void* value) +{ + bRC retval = bRC_Error; + plugin_private_context* plugin_priv_ctx = + (plugin_private_context*)bareos_plugin_ctx->pContext; + PyObject* pFunc; + + /* + * Lookup the handle_plugin_event() function in the python module. + */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "handle_plugin_event"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyObject *pEventType, *pRetVal; + + pEventType = PyInt_FromLong(event->eventType); + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pEventType, NULL); + Py_DECREF(pEventType); + + if (!pRetVal) { + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + } + } else { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Failed to find function named handle_plugin_event()\n"); + } + + return retval; + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + return retval; +} + +static inline PyStatPacket* NativeToPyStatPacket(struct stat* statp) +{ + PyStatPacket* pStatp = PyObject_New(PyStatPacket, &PyStatPacketType); + + if (pStatp) { + pStatp->dev = statp->st_dev; + pStatp->ino = statp->st_ino; + pStatp->mode = statp->st_mode; + pStatp->nlink = statp->st_nlink; + pStatp->uid = statp->st_uid; + pStatp->gid = statp->st_gid; + pStatp->rdev = statp->st_rdev; + pStatp->size = statp->st_size; + pStatp->atime = statp->st_atime; + pStatp->mtime = statp->st_mtime; + pStatp->ctime = statp->st_ctime; + pStatp->blksize = statp->st_blksize; + pStatp->blocks = statp->st_blocks; + } + + return pStatp; +} + +static inline void PyStatPacketToNative(PyStatPacket* pStatp, + struct stat* statp) +{ + statp->st_dev = pStatp->dev; + statp->st_ino = pStatp->ino; + statp->st_mode = pStatp->mode; + statp->st_nlink = pStatp->nlink; + statp->st_uid = pStatp->uid; + statp->st_gid = pStatp->gid; + statp->st_rdev = pStatp->rdev; + statp->st_size = pStatp->size; + statp->st_atime = pStatp->atime; + statp->st_mtime = pStatp->mtime; + statp->st_ctime = pStatp->ctime; + statp->st_blksize = pStatp->blksize; + statp->st_blocks = pStatp->blocks; +} + +static inline PySavePacket* NativeToPySavePacket(struct save_pkt* sp) +{ + PySavePacket* pSavePkt = PyObject_New(PySavePacket, &PySavePacketType); + + if (pSavePkt) { + /* + * Initialize the Python SavePkt with the data we got passed in. + */ + if (sp->fname) { + pSavePkt->fname = PyString_FromString(sp->fname); + } else { + pSavePkt->fname = NULL; + } + + if (sp->link) { + pSavePkt->link = PyString_FromString(sp->link); + } else { + pSavePkt->link = NULL; + } + + if (sp->statp.st_mode) { + pSavePkt->statp = (PyObject*)NativeToPyStatPacket(&sp->statp); + } else { + pSavePkt->statp = NULL; + } + + pSavePkt->type = sp->type; + pSavePkt->flags = + PyByteArray_FromStringAndSize(sp->flags, sizeof(sp->flags)); + pSavePkt->no_read = sp->no_read; + pSavePkt->portable = sp->portable; + pSavePkt->accurate_found = sp->accurate_found; + pSavePkt->cmd = sp->cmd; + pSavePkt->save_time = sp->save_time; + pSavePkt->delta_seq = sp->delta_seq; + pSavePkt->object_name = NULL; + pSavePkt->object = NULL; + pSavePkt->object_len = sp->object_len; + pSavePkt->object_index = sp->index; + } + + return pSavePkt; +} + +static inline bool PySavePacketToNative( + PySavePacket* pSavePkt, + struct save_pkt* sp, + struct plugin_private_context* plugin_priv_ctx, + bool is_options_plugin) +{ + /* + * See if this is for an Options Plugin. + */ + if (!is_options_plugin) { + /* + * Only copy back the arguments that are allowed to change. + */ + if (pSavePkt->fname) { + /* + * As this has to linger as long as the backup is running we save it in + * our plugin context. + */ + if (PyString_Check(pSavePkt->fname)) { + if (plugin_priv_ctx->fname) { free(plugin_priv_ctx->fname); } + plugin_priv_ctx->fname = strdup(PyString_AsString(pSavePkt->fname)); + sp->fname = plugin_priv_ctx->fname; + } + } else { + goto bail_out; + } + + /* + * Optional field. + */ + if (pSavePkt->link) { + /* + * As this has to linger as long as the backup is running we save it in + * our plugin context. + */ + if (PyString_Check(pSavePkt->link)) { + if (plugin_priv_ctx->link) { free(plugin_priv_ctx->link); } + plugin_priv_ctx->link = strdup(PyString_AsString(pSavePkt->link)); + sp->link = plugin_priv_ctx->link; + } + } + + /* + * Handle the stat structure. + */ + if (pSavePkt->statp) { + PyStatPacketToNative((PyStatPacket*)pSavePkt->statp, &sp->statp); + } else { + goto bail_out; + } + + sp->type = pSavePkt->type; + + if (PyByteArray_Check(pSavePkt->flags)) { + char* flags; + + if (PyByteArray_Size(pSavePkt->flags) != sizeof(sp->flags)) { + goto bail_out; + } + + if ((flags = PyByteArray_AsString(pSavePkt->flags))) { + memcpy(sp->flags, flags, sizeof(sp->flags)); + } else { + goto bail_out; + } + } else { + goto bail_out; + } + + /* + * Special code for handling restore objects. + */ + if (IS_FT_OBJECT(sp->type)) { + /* + * See if a proper restore object was created. + */ + if (pSavePkt->object_len > 0) { + /* + * As this has to linger as long as the backup is running we save it in + * our plugin context. + */ + if (pSavePkt->object_name && pSavePkt->object && + PyString_Check(pSavePkt->object_name) && + PyByteArray_Check(pSavePkt->object)) { + char* buf; + + if (plugin_priv_ctx->object_name) { + free(plugin_priv_ctx->object_name); + } + plugin_priv_ctx->object_name = + strdup(PyString_AsString(pSavePkt->object_name)); + sp->object_name = plugin_priv_ctx->object_name; + + sp->object_len = pSavePkt->object_len; + sp->index = pSavePkt->object_index; + + if ((buf = PyByteArray_AsString(pSavePkt->object))) { + if (plugin_priv_ctx->object) { free(plugin_priv_ctx->object); } + plugin_priv_ctx->object = (char*)malloc(pSavePkt->object_len); + memcpy(plugin_priv_ctx->object, buf, pSavePkt->object_len); + sp->object = plugin_priv_ctx->object; + } else { + goto bail_out; + } + } else { + goto bail_out; + } + } else { + goto bail_out; + } + } else { + sp->no_read = pSavePkt->no_read; + sp->delta_seq = pSavePkt->delta_seq; + } + } else { + sp->no_read = pSavePkt->no_read; + sp->delta_seq = pSavePkt->delta_seq; + + if (PyByteArray_Check(pSavePkt->flags)) { + char* flags; + + if (PyByteArray_Size(pSavePkt->flags) != sizeof(sp->flags)) { + goto bail_out; + } + + if ((flags = PyByteArray_AsString(pSavePkt->flags))) { + memcpy(sp->flags, flags, sizeof(sp->flags)); + } else { + goto bail_out; + } + } else { + goto bail_out; + } + } + + return true; + +bail_out: + return false; +} + +/** + * Called when starting to backup a file. Here the plugin must + * return the "stat" packet for the directory/file and provide + * certain information so that Bareos knows what the file is. + * The plugin can create "Virtual" files by giving them a + * name that is not normally found on the file system. + */ +static bRC PyStartBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; + PyObject* pFunc; + + /* + * Lookup the start_backup_file() function in the python module. + */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "start_backup_file"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PySavePacket* pSavePkt; + PyObject* pRetVal; + + pSavePkt = NativeToPySavePacket(sp); + if (!pSavePkt) { goto bail_out; } + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, (PyObject*)pSavePkt, NULL); + if (!pRetVal) { + Py_DECREF((PyObject*)pSavePkt); + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + + if (!PySavePacketToNative(pSavePkt, sp, plugin_priv_ctx, false)) { + Py_DECREF((PyObject*)pSavePkt); + goto bail_out; + } + Py_DECREF((PyObject*)pSavePkt); + } + } else { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Failed to find function named start_backup_file()\n"); + } + + return retval; + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + return retval; +} + +/** + * Called at the end of backing up a file for a command plugin. + * If the plugin's work is done, it should return bRC_OK. + * If the plugin wishes to create another file and back it up, + * then it must return bRC_More (not yet implemented). + */ +static bRC PyEndBackupFile(bpContext* bareos_plugin_ctx) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; + PyObject* pFunc; + + /* + * Lookup the end_backup_file() function in the python module. + */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "end_backup_file"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyObject* pRetVal; + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, NULL); + if (!pRetVal) { + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + } + } else { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Failed to find function named end_backup_file()\n"); + } + + return retval; + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + return retval; +} + +static inline PyIoPacket* NativeToPyIoPacket(struct io_pkt* io) +{ + PyIoPacket* pIoPkt = PyObject_New(PyIoPacket, &PyIoPacketType); + + if (pIoPkt) { + /* + * Initialize the Python IoPkt with the data we got passed in. + */ + pIoPkt->func = io->func; + pIoPkt->count = io->count; + pIoPkt->flags = io->flags; + pIoPkt->mode = io->mode; + pIoPkt->fname = io->fname; + pIoPkt->whence = io->whence; + pIoPkt->offset = io->offset; + if (io->func == IO_WRITE && io->count > 0) { + /* + * Only initialize the buffer with read data when we are writing and there + * is data. + */ + pIoPkt->buf = PyByteArray_FromStringAndSize(io->buf, io->count); + if (!pIoPkt->buf) { + Py_DECREF((PyObject*)pIoPkt); + return (PyIoPacket*)NULL; + } + } else { + pIoPkt->buf = NULL; + } + + /* + * These must be set by the Python function but we initialize them to zero + * to be sure they have some valid setting an not random data. + */ + pIoPkt->io_errno = 0; + pIoPkt->lerror = 0; + pIoPkt->win32 = false; + pIoPkt->status = 0; + } + + return pIoPkt; +} + +static inline bool PyIoPacketToNative(PyIoPacket* pIoPkt, struct io_pkt* io) +{ + /* + * Only copy back the arguments that are allowed to change. + */ + io->io_errno = pIoPkt->io_errno; + io->lerror = pIoPkt->lerror; + io->win32 = pIoPkt->win32; + io->status = pIoPkt->status; + if (io->func == IO_READ && io->status > 0) { + /* + * Only copy back the data when doing a read and there is data. + */ + if (PyByteArray_Check(pIoPkt->buf)) { + char* buf; + + if (PyByteArray_Size(pIoPkt->buf) > io->count || io->status > io->count) { + return false; + } + + if (!(buf = PyByteArray_AsString(pIoPkt->buf))) { return false; } + memcpy(io->buf, buf, io->status); + } + } + + return true; +} + +/** + * Do actual I/O. Bareos calls this after startBackupFile + * or after startRestoreFile to do the actual file + * input or output. + */ +static bRC PyPluginIO(bpContext* bareos_plugin_ctx, struct io_pkt* io) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; + PyObject* pFunc; + + /* + * Lookup the plugin_io() function in the python module. + */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "plugin_io"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyIoPacket* pIoPkt; + PyObject* pRetVal; + + pIoPkt = NativeToPyIoPacket(io); + if (!pIoPkt) { goto bail_out; } + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, (PyObject*)pIoPkt, NULL); + if (!pRetVal) { + Py_DECREF((PyObject*)pIoPkt); + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + + if (!PyIoPacketToNative(pIoPkt, io)) { + Py_DECREF((PyObject*)pIoPkt); + goto bail_out; + } + } + Py_DECREF((PyObject*)pIoPkt); + } else { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Failed to find function named plugin_io()\n"); + } + + return retval; + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + io->status = -1; + + return retval; +} + +/** + * Called when the first record is read from the Volume that was previously + * written by the command plugin. + */ +static bRC PyStartRestoreFile(bpContext* bareos_plugin_ctx, const char* cmd) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; + PyObject* pFunc; + + /* + * Lookup the start_restore_file() function in the python module. + */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "start_restore_file"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyObject *pCmd, *pRetVal; + + pCmd = PyString_FromString(cmd); + if (!pCmd) { goto bail_out; } + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pCmd, NULL); + Py_DECREF(pCmd); + + if (!pRetVal) { + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + } + } else { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Failed to find function named start_restore_file()\n"); + } + + return retval; + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + return retval; +} + +/** + * Called when a command plugin is done restoring a file. + */ +static bRC PyEndRestoreFile(bpContext* bareos_plugin_ctx) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; + PyObject* pFunc; + + /* + * Lookup the end_restore_file() function in the python module. + */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "end_restore_file"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyObject* pRetVal; + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, NULL); + if (!pRetVal) { + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + } + } else { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Failed to find function named end_restore_file()\n"); + } + + return retval; + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + return retval; +} + +static inline PyRestorePacket* NativeToPyRestorePacket(struct restore_pkt* rp) +{ + PyRestorePacket* pRestorePacket = + PyObject_New(PyRestorePacket, &PyRestorePacketType); + + if (pRestorePacket) { + pRestorePacket->stream = rp->stream; + pRestorePacket->data_stream = rp->data_stream; + pRestorePacket->type = rp->type; + pRestorePacket->file_index = rp->file_index; + pRestorePacket->LinkFI = rp->LinkFI; + pRestorePacket->uid = rp->uid; + pRestorePacket->statp = (PyObject*)NativeToPyStatPacket(&rp->statp); + pRestorePacket->attrEx = rp->attrEx; + pRestorePacket->ofname = rp->ofname; + pRestorePacket->olname = rp->olname; + pRestorePacket->where = rp->where; + pRestorePacket->RegexWhere = rp->RegexWhere; + pRestorePacket->replace = rp->replace; + pRestorePacket->create_status = rp->create_status; + } + + return pRestorePacket; +} + +static inline void PyRestorePacketToNative(PyRestorePacket* pRestorePacket, + struct restore_pkt* rp) +{ + /* + * Only copy back the fields that are allowed to be changed. + */ + rp->create_status = pRestorePacket->create_status; +} + +/** + * Called for a command plugin to create a file during a Restore job before + * restoring the data. This entry point is called before any I/O is done on the + * file. After this call, Bareos will call pluginIO() to open the file for + * write. + * + * We must return in rp->create_status: + * + * CF_ERROR -- error + * CF_SKIP -- skip processing this file + * CF_EXTRACT -- extract the file (i.e.call i/o routines) + * CF_CREATED -- created, but no content to extract (typically directories) + */ +static bRC PyCreateFile(bpContext* bareos_plugin_ctx, struct restore_pkt* rp) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; + PyObject* pFunc; + + if (!rp) { return bRC_Error; } + + /* + * Lookup the create_file() function in the python module. + */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "create_file"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyRestorePacket* pRestorePacket; + PyObject* pRetVal; + + pRestorePacket = NativeToPyRestorePacket(rp); + if (!pRestorePacket) { goto bail_out; } + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pRestorePacket, NULL); + if (!pRetVal) { + Py_DECREF(pRestorePacket); + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + + PyRestorePacketToNative(pRestorePacket, rp); + Py_DECREF(pRestorePacket); + } + } else { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Failed to find function named create_file()\n"); + } + + return retval; + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + return retval; +} + +static bRC PySetFileAttributes(bpContext* bareos_plugin_ctx, + struct restore_pkt* rp) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; + PyObject* pFunc; + + if (!rp) { return bRC_Error; } + + /* + * Lookup the set_file_attributes() function in the python module. + */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "set_file_attributes"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyRestorePacket* pRestorePacket; + PyObject* pRetVal; + + pRestorePacket = NativeToPyRestorePacket(rp); + if (!pRestorePacket) { goto bail_out; } + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pRestorePacket, NULL); + if (!pRetVal) { + Py_DECREF(pRestorePacket); + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + Py_DECREF(pRestorePacket); + } + } else { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Failed to find function named set_file_attributes()\n"); + } + + return retval; + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + return retval; +} + +static bRC PyCheckFile(bpContext* bareos_plugin_ctx, char* fname) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; + PyObject* pFunc; + + if (!fname) { return bRC_Error; } + + /* + * Lookup the check_file() function in the python module. + */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "check_file"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyObject *pFname, *pRetVal; + + pFname = PyString_FromString(fname); + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pFname, NULL); + Py_DECREF(pFname); + + if (!pRetVal) { + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + } + } else { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Failed to find function named check_file()\n"); + } + + return retval; + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + return retval; +} + +static inline PyAclPacket* NativeToPyAclPacket(struct acl_pkt* ap) +{ + PyAclPacket* pAclPacket = PyObject_New(PyAclPacket, &PyAclPacketType); + + if (pAclPacket) { + pAclPacket->fname = ap->fname; + + if (ap->content_length && ap->content) { + pAclPacket->content = + PyByteArray_FromStringAndSize(ap->content, ap->content_length); + } else { + pAclPacket->content = NULL; + } + } + + return pAclPacket; +} + +static inline bool PyAclPacketToNative(PyAclPacket* pAclPacket, + struct acl_pkt* ap) +{ + if (!pAclPacket->content) { return true; } + + if (PyByteArray_Check(pAclPacket->content)) { + char* buf; + + ap->content_length = PyByteArray_Size(pAclPacket->content); + if (ap->content_length <= 0 || + !(buf = PyByteArray_AsString(pAclPacket->content))) { + return false; + } + + if (ap->content) { free(ap->content); } + ap->content = (char*)malloc(ap->content_length); + memcpy(ap->content, buf, ap->content_length); + } + + return true; +} + +static bRC PyGetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; + PyObject* pFunc; + + if (!ap) { return bRC_Error; } + + /* + * Lookup the get_acl() function in the python module. + */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "get_acl"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyAclPacket* pAclPkt; + PyObject* pRetVal; + + pAclPkt = NativeToPyAclPacket(ap); + if (!pAclPkt) { goto bail_out; } + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pAclPkt, NULL); + if (!pRetVal) { + Py_DECREF((PyObject*)pAclPkt); + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + + if (!PyAclPacketToNative(pAclPkt, ap)) { + Py_DECREF((PyObject*)pAclPkt); + goto bail_out; + } + Py_DECREF(pAclPkt); + } + } else { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Failed to find function named get_acl()\n"); + } + + return retval; + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + return retval; +} + +static bRC PySetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; + PyObject* pFunc; + + if (!ap) { return bRC_Error; } + + /* + * Lookup the set_acl() function in the python module. + */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "set_acl"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyAclPacket* pAclPkt; + PyObject* pRetVal; + + pAclPkt = NativeToPyAclPacket(ap); + if (!pAclPkt) { goto bail_out; } + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pAclPkt, NULL); + Py_DECREF(pAclPkt); + + if (!pRetVal) { + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + } + } else { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Failed to find function named set_acl()\n"); + } + + return retval; + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + return retval; +} + +static inline PyXattrPacket* NativeToPyXattrPacket(struct xattr_pkt* xp) +{ + PyXattrPacket* pXattrPacket = PyObject_New(PyXattrPacket, &PyXattrPacketType); + + if (pXattrPacket) { + pXattrPacket->fname = xp->fname; + + if (xp->name_length && xp->name) { + pXattrPacket->name = + PyByteArray_FromStringAndSize(xp->name, xp->name_length); + } else { + pXattrPacket->name = NULL; + } + if (xp->value_length && xp->value) { + pXattrPacket->value = + PyByteArray_FromStringAndSize(xp->value, xp->value_length); + } else { + pXattrPacket->value = NULL; + } + } + + return pXattrPacket; +} + +static inline bool PyXattrPacketToNative(PyXattrPacket* pXattrPacket, + struct xattr_pkt* xp) +{ + if (!pXattrPacket->name) { return true; } + + if (PyByteArray_Check(pXattrPacket->name)) { + char* buf; + + xp->name_length = PyByteArray_Size(pXattrPacket->name); + if (xp->name_length <= 0 || + !(buf = PyByteArray_AsString(pXattrPacket->name))) { + return false; + } + + if (xp->name) { free(xp->name); } + xp->name = (char*)malloc(xp->name_length); + memcpy(xp->name, buf, xp->name_length); + } + + if (pXattrPacket->value && PyByteArray_Check(pXattrPacket->value)) { + char* buf; + + xp->value_length = PyByteArray_Size(pXattrPacket->value); + if (xp->name_length <= 0 || + !(buf = PyByteArray_AsString(pXattrPacket->name))) { + return false; + } + + if (xp->value) { free(xp->value); } + xp->value = (char*)malloc(xp->value_length); + memcpy(xp->value, buf, xp->value_length); + } else { + if (xp->value) { free(xp->value); } + xp->value = NULL; + } + + return true; +} + +static bRC PyGetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; + PyObject* pFunc; + + if (!xp) { return bRC_Error; } + + /* + * Lookup the get_xattr() function in the python module. + */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "get_xattr"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyXattrPacket* pXattrPkt; + PyObject* pRetVal; + + pXattrPkt = NativeToPyXattrPacket(xp); + if (!pXattrPkt) { goto bail_out; } + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pXattrPkt, NULL); + if (!pRetVal) { + Py_DECREF((PyObject*)pXattrPkt); + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + + if (!PyXattrPacketToNative(pXattrPkt, xp)) { + Py_DECREF((PyObject*)pXattrPkt); + goto bail_out; + } + Py_DECREF(pXattrPkt); + } + } else { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Failed to find function named get_xattr()\n"); + } + + return retval; + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + return retval; +} + +static bRC PySetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; + PyObject* pFunc; + + if (!xp) { return bRC_Error; } + + /* + * Lookup the set_acl() function in the python module. + */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "set_xattr"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyXattrPacket* pXattrPkt; + PyObject* pRetVal; + + pXattrPkt = NativeToPyXattrPacket(xp); + if (!pXattrPkt) { goto bail_out; } + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pXattrPkt, NULL); + Py_DECREF(pXattrPkt); + + if (!pRetVal) { + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + } + } else { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Failed to find function named set_xattr()\n"); + } + + return retval; +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + return retval; +} + +static inline PyRestoreObject* NativeToPyRestoreObject( + struct restore_object_pkt* rop) +{ + PyRestoreObject* pRestoreObject = + PyObject_New(PyRestoreObject, &PyRestoreObjectType); + + if (pRestoreObject) { + pRestoreObject->object_name = PyString_FromString(rop->object_name); + pRestoreObject->object = + PyByteArray_FromStringAndSize(rop->object, rop->object_len); + pRestoreObject->plugin_name = rop->plugin_name; + pRestoreObject->object_type = rop->object_type; + pRestoreObject->object_len = rop->object_len; + pRestoreObject->object_full_len = rop->object_full_len; + pRestoreObject->object_index = rop->object_index; + pRestoreObject->object_compression = rop->object_compression; + pRestoreObject->stream = rop->stream; + pRestoreObject->JobId = rop->JobId; + } + + return pRestoreObject; +} + +static bRC PyRestoreObjectData(bpContext* bareos_plugin_ctx, + struct restore_object_pkt* rop) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; + PyObject* pFunc; + + if (!rop) { return bRC_OK; } + + /* + * Lookup the restore_object_data() function in the python module. + */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "restore_object_data"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyRestoreObject* pRestoreObject; + PyObject* pRetVal; + + pRestoreObject = NativeToPyRestoreObject(rop); + if (!pRestoreObject) { goto bail_out; } + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pRestoreObject, NULL); + Py_DECREF(pRestoreObject); + + if (!pRetVal) { + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + } + } else { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Failed to find function named start_restore_file()\n"); + } + + return retval; + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + return retval; +} + +static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->pContext; + PyObject* pFunc; + + if (!sp) { return bRC_Error; } + + /* + * Lookup the handle_backup_file() function in the python module. + */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "handle_backup_file"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PySavePacket* pSavePkt; + PyObject* pRetVal; + + pSavePkt = NativeToPySavePacket(sp); + if (!pSavePkt) { goto bail_out; } + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pSavePkt, NULL); + if (!pRetVal) { + Py_DECREF((PyObject*)pSavePkt); + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + + if (!PySavePacketToNative(pSavePkt, sp, plugin_priv_ctx, true)) { + Py_DECREF((PyObject*)pSavePkt); + goto bail_out; + } + Py_DECREF(pSavePkt); + } + } else { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Failed to find function named handle_backup_file()\n"); + } + + return retval; + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + return retval; +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to get certain internal values of the current Job. + */ +static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) +{ + int var; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PyObject* pRetVal = NULL; + + if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + switch (var) { + case bVarFDName: + case bVarWorkingDir: + case bVarExePath: + case bVarVersion: + case bVarDistName: { + char* value = NULL; + + if (bfuncs->getBareosValue(bareos_plugin_ctx, (bVariable)var, &value) == + bRC_OK) { + if (value) { pRetVal = PyString_FromString(value); } + } + break; + } + case bVarJobId: + case bVarLevel: + case bVarType: + case bVarJobStatus: + case bVarSinceTime: + case bVarAccurate: + case bVarPrefixLinks: { + int value = 0; + + if (bfuncs->getBareosValue(bareos_plugin_ctx, (bVariable)var, &value) == + bRC_OK) { + pRetVal = PyInt_FromLong(value); + } + break; + } + case bVarClient: + case bVarJobName: + case bVarPrevJobName: + case bVarWhere: + case bVarRegexWhere: { + char* value = NULL; + + if (bfuncs->getBareosValue(bareos_plugin_ctx, (bVariable)var, &value) == + bRC_OK) { + if (value) { pRetVal = PyString_FromString(value); } + } + break; + } + case bVarFileSeen: + break; /* a write only variable, ignore read request */ + default: + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: PyBareosGetValue unknown variable requested %d\n", var); + break; + } + + if (!pRetVal) { + Py_INCREF(Py_None); + pRetVal = Py_None; + } + + return pRetVal; +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to get certain internal values of the current Job. + */ +static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) +{ + int var; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bRC retval = bRC_Error; + PyObject* pyValue; + + if (!PyArg_ParseTuple(args, "iO:BareosSetValue", &var, &pyValue)) { + goto bail_out; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + switch (var) { + case bVarLevel: { + int value = 0; + + value = PyInt_AsLong(pyValue); + if (value) { + retval = + bfuncs->setBareosValue(bareos_plugin_ctx, (bVariable)var, &value); + } + break; + } + case bVarFileSeen: { + char* value; + + value = PyString_AsString(pyValue); + if (value) { + retval = + bfuncs->setBareosValue(bareos_plugin_ctx, (bVariable)var, value); + } + break; + } + default: + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: PyBareosSetValue unknown variable requested %d\n", var); + break; + } + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to issue debug messages using the Bareos debug message + * facility. + */ +static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) +{ + int level; + char* dbgmsg = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + /* plugin_private_context* ppc = */ + /* (plugin_private_context*)bareos_plugin_ctx->pContext; */ + + if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { + return NULL; + } + RETURN_RUNTIME_ERROR_IF_BAREOS_PLUGIN_CTX_UNSET() + + if (dbgmsg) { Dmsg(bareos_plugin_ctx, level, "python-fd: %s", dbgmsg); } + Py_INCREF(Py_None); + return Py_None; +} + +/** + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue Job messages using the Bareos Job + * message facility. + */ +static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) +{ + int type; + char* jobmsg = NULL; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + + if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { + return NULL; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + if (jobmsg) { Jmsg(bareos_plugin_ctx, type, "python-fd: %s", jobmsg); } + + Py_INCREF(Py_None); + return Py_None; +} + +/** + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Register Event to register + * additional events it wants to receive. + */ +static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) +{ + int len, event; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bRC retval = bRC_Error; + PyObject *pyEvents, *pySeq, *pyEvent; + + if (!PyArg_ParseTuple(args, "O:BareosRegisterEvents", &pyEvents)) { + goto bail_out; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); + if (!pySeq) { goto bail_out; } + len = PySequence_Fast_GET_SIZE(pySeq); + + for (int i = 0; i < len; i++) { + pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); + event = PyInt_AsLong(pyEvent); + + if (event >= bEventJobStart && event <= FD_NR_EVENTS) { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: PyBareosRegisterEvents registering event %d\n", event); + retval = bfuncs->registerBareosEvents(bareos_plugin_ctx, 1, event); + + if (retval != bRC_OK) { break; } + } + } + + Py_DECREF(pySeq); + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue an Unregister Event to unregister + * events it doesn't want to receive anymore. + */ +static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) +{ + int len, event; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bRC retval = bRC_Error; + PyObject *pyEvents, *pySeq, *pyEvent; + + if (!PyArg_ParseTuple(args, "O:BareosUnRegisterEvents", &pyEvents)) { + goto bail_out; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); + if (!pySeq) { goto bail_out; } + + len = PySequence_Fast_GET_SIZE(pySeq); + for (int i = 0; i < len; i++) { + pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); + event = PyInt_AsLong(pyEvent); + + if (event >= bEventJobStart && event <= FD_NR_EVENTS) { + Dmsg(bareos_plugin_ctx, debuglevel, + "PyBareosUnRegisterEvents: unregistering event %d\n", event); + retval = bfuncs->unregisterBareosEvents(bareos_plugin_ctx, 1, event); + } + } + + Py_DECREF(pySeq); + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a GetInstanceCount to retrieve the + * number of instances of the current plugin being loaded into the daemon. + */ +static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) +{ + int value; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PyObject* pRetVal = NULL; + + if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + if (bfuncs->getInstanceCount(bareos_plugin_ctx, &value) == bRC_OK) { + pRetVal = PyInt_FromLong(value); + } + + if (!pRetVal) { + Py_INCREF(Py_None); + pRetVal = Py_None; + } + + return pRetVal; +} + +/** + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Add Exclude pattern to the fileset. + */ +static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) +{ + char* file = NULL; + bRC retval = bRC_Error; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + + if (!PyArg_ParseTuple(args, "|z:BareosAddExclude", &file)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + if (file) { retval = bfuncs->AddExclude(bareos_plugin_ctx, file); } + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Add Include pattern to the fileset. + */ +static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) +{ + char* file = NULL; + bRC retval = bRC_Error; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + + if (!PyArg_ParseTuple(args, "|z:BareosAddInclude", &file)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + if (file) { retval = bfuncs->AddInclude(bareos_plugin_ctx, file); } + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Add Include Options to the fileset. + */ +static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) +{ + char* opts = NULL; + bRC retval = bRC_Error; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + + if (!PyArg_ParseTuple(args, "|z:BareosAddOptions", &opts)) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + if (opts) { retval = bfuncs->AddOptions(bareos_plugin_ctx, opts); } + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Add Regex to the fileset. + */ +static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) +{ + int type; + char* item = NULL; + bRC retval = bRC_Error; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + if (!PyArg_ParseTuple(args, "|zi:BareosAddRegex", &item, &type)) { + goto bail_out; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + if (item) { retval = bfuncs->AddRegex(bareos_plugin_ctx, item, type); } + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Add Wildcard to the fileset. + */ +static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) +{ + int type; + char* item = NULL; + bRC retval = bRC_Error; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + + if (!PyArg_ParseTuple(args, "|zi:BareosAddWild", &item, &type)) { + goto bail_out; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + if (item) { retval = bfuncs->AddWild(bareos_plugin_ctx, item, type); } + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Add New Option block. + */ +static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) +{ + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bRC retval = bRC_Error; + + if (!PyArg_ParseTuple(args, ":BareosNewOptions")) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + retval = bfuncs->NewOptions(bareos_plugin_ctx); + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Add New Include block. + */ +static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) +{ + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bRC retval = bRC_Error; + + if (!PyArg_ParseTuple(args, ":BareosNewInclude")) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + retval = bfuncs->NewInclude(bareos_plugin_ctx); + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Add New Pre Include block. + */ +static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) +{ + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bRC retval = bRC_Error; + + if (!PyArg_ParseTuple(args, ":BareosNewPreInclude")) { goto bail_out; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + retval = bfuncs->NewPreInclude(bareos_plugin_ctx); + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a check if a file have to be backed up + * using Accurate code. + */ +static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) +{ + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + + struct save_pkt sp; + bRC retval = bRC_Error; + PySavePacket* pSavePkt; + + if (!PyArg_ParseTuple(args, "O:BareosCheckChanges", &pSavePkt)) { + goto bail_out; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + + /* + * CheckFile only has a need for a limited version of the PySavePacket so we + * handle that here separately and don't call PySavePacketToNative(). + */ + sp.type = pSavePkt->type; + if (pSavePkt->fname) { + if (PyString_Check(pSavePkt->fname)) { + sp.fname = PyString_AsString(pSavePkt->fname); + } else { + goto bail_out; + } + } else { + goto bail_out; + } + if (pSavePkt->link) { + if (PyString_Check(pSavePkt->link)) { + sp.link = PyString_AsString(pSavePkt->link); + } else { + goto bail_out; + } + } + sp.save_time = pSavePkt->save_time; + + retval = bfuncs->checkChanges(bareos_plugin_ctx, &sp); + + /* + * Copy back the two fields that are changed by checkChanges(). + */ + pSavePkt->delta_seq = sp.delta_seq; + pSavePkt->accurate_found = sp.accurate_found; + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a check if a file would be saved using + * current Include/Exclude code. + */ +static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) +{ + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + struct save_pkt sp; + bRC retval = bRC_Error; + PySavePacket* pSavePkt; + + if (!PyArg_ParseTuple(args, "O:BareosAcceptFile", &pSavePkt)) { + goto bail_out; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + /* + * Acceptfile only needs fname and statp from PySavePacket so we handle + * that here separately and don't call PySavePacketToNative(). + */ + if (pSavePkt->fname) { + if (PyString_Check(pSavePkt->fname)) { + sp.fname = PyString_AsString(pSavePkt->fname); + } else { + goto bail_out; + } + } else { + goto bail_out; + } + + if (pSavePkt->statp) { + PyStatPacketToNative((PyStatPacket*)pSavePkt->statp, &sp.statp); + } else { + goto bail_out; + } + + retval = bfuncs->AcceptFile(bareos_plugin_ctx, &sp); + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Set bit in the Accurate Seen bitmap. + */ +static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) +{ + bool all; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + char* fname = NULL; + bRC retval = bRC_Error; + PyObject* pyBool; + + if (!PyArg_ParseTuple(args, "O|s:BareosSetSeenBitmap", &pyBool, &fname)) { + goto bail_out; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + all = PyObject_IsTrue(pyBool); + retval = bfuncs->SetSeenBitmap(bareos_plugin_ctx, all, fname); + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Clear bit in the Accurate Seen + * bitmap. + */ +static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) +{ + bool all; + bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + char* fname = NULL; + bRC retval = bRC_Error; + PyObject* pyBool; + + if (!PyArg_ParseTuple(args, "O|s:BareosClearSeenBitmap", &pyBool, &fname)) { + goto bail_out; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + all = PyObject_IsTrue(pyBool); + retval = bfuncs->ClearSeenBitmap(bareos_plugin_ctx, all, fname); + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Some helper functions. + */ +static inline char* PyGetStringValue(PyObject* object) +{ + if (!object || !PyString_Check(object)) { return (char*)""; } + + return PyString_AsString(object); +} + +static inline char* PyGetByteArrayValue(PyObject* object) +{ + if (!object || !PyByteArray_Check(object)) { return (char*)""; } + + return PyByteArray_AsString(object); +} + +/** + * Python specific handlers for PyRestoreObject structure mapping. + */ + +/** + * Representation. + */ +static PyObject* PyRestoreObject_repr(PyRestoreObject* self) +{ + PyObject* s; + PoolMem buf(PM_MESSAGE); + + Mmsg(buf, + "RestoreObject(object_name=\"%s\", object=\"%s\", plugin_name=\"%s\", " + "object_type=%d, object_len=%d, object_full_len=%d, " + "object_index=%d, object_compression=%d, stream=%d, jobid=%u)", + PyGetStringValue(self->object_name), PyGetByteArrayValue(self->object), + self->plugin_name, self->object_type, self->object_len, + self->object_full_len, self->object_index, self->object_compression, + self->stream, self->JobId); + s = PyString_FromString(buf.c_str()); + + return s; +} + +/** + * Initialization. + */ +static int PyRestoreObject_init(PyRestoreObject* self, + PyObject* args, + PyObject* kwds) +{ + static char* kwlist[] = {(char*)"object_name", + (char*)"object", + (char*)"plugin_name", + (char*)"object_type", + (char*)"object_len", + (char*)"object_full_len", + (char*)"object_index", + (char*)"object_compression", + (char*)"stream", + (char*)"jobid", + NULL}; + + self->object_name = NULL; + self->object = NULL; + self->plugin_name = NULL; + self->object_type = 0; + self->object_len = 0; + self->object_full_len = 0; + self->object_index = 0; + self->object_compression = 0; + self->stream = 0; + self->JobId = 0; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|oosiiiiiiI", kwlist, &self->object_name, &self->object, + &self->plugin_name, &self->object_type, &self->object_len, + &self->object_full_len, &self->object_index, + &self->object_compression, &self->stream, &self->JobId)) { + return -1; + } + + return 0; +} + +/** + * Destructor. + */ +static void PyRestoreObject_dealloc(PyRestoreObject* self) +{ + if (self->object_name) { Py_XDECREF(self->object_name); } + if (self->object) { Py_XDECREF(self->object); } + PyObject_Del(self); +} + +/** + * Python specific handlers for PyStatPacket structure mapping. + */ + +/** + * Representation. + */ +static PyObject* PyStatPacket_repr(PyStatPacket* self) +{ + PyObject* s; + PoolMem buf(PM_MESSAGE); + + Mmsg(buf, + "StatPacket(dev=%ld, ino=%lld, mode=%04o, nlink=%d, " + "uid=%ld, gid=%ld, rdev=%ld, size=%lld, " + "atime=%ld, mtime=%ld, ctime=%ld, blksize=%ld, blocks=%lld)", + self->dev, self->ino, (self->mode & ~S_IFMT), self->nlink, self->uid, + self->gid, self->rdev, self->size, self->atime, self->mtime, self->ctime, + self->blksize, self->blocks); + + s = PyString_FromString(buf.c_str()); + + return s; +} + +/** + * Initialization. + */ +static int PyStatPacket_init(PyStatPacket* self, PyObject* args, PyObject* kwds) +{ + time_t now; + static char* kwlist[] = {(char*)"dev", (char*)"ino", + (char*)"mode", (char*)"nlink", + (char*)"uid", (char*)"gid", + (char*)"rdev", (char*)"size", + (char*)"atime", (char*)"mtime", + (char*)"ctime", (char*)"blksize", + (char*)"blocks", NULL}; + + now = time(NULL); + self->dev = 0; + self->ino = 0; + self->mode = 0700 | S_IFREG; + self->nlink = 0; + self->uid = 0; + self->gid = 0; + self->rdev = 0; + self->size = -1; + self->atime = now; + self->mtime = now; + self->ctime = now; + self->blksize = 4096; + self->blocks = 1; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|IKHHIIIKIIIIK", kwlist, &self->dev, &self->ino, + &self->mode, &self->nlink, &self->uid, &self->gid, &self->rdev, + &self->size, &self->atime, &self->mtime, &self->ctime, &self->blksize, + &self->blocks)) { + return -1; + } + + return 0; +} + +/** + * Destructor. + */ +static void PyStatPacket_dealloc(PyStatPacket* self) { PyObject_Del(self); } + +/** + * Python specific handlers for PySavePacket structure mapping. + */ + +/** + * Representation. + */ +static inline const char* print_flags_bitmap(PyObject* bitmap) +{ + static char visual_bitmap[FO_MAX + 1]; + if (!bitmap) { return ""; } + if (PyByteArray_Check(bitmap)) { + int cnt; + char* flags; + + if (PyByteArray_Size(bitmap) == FOPTS_BYTES) { + if ((flags = PyByteArray_AsString(bitmap))) { + memset(visual_bitmap, 0, sizeof(visual_bitmap)); + for (cnt = 0; cnt <= FO_MAX; cnt++) { + if (BitIsSet(cnt, flags)) { + visual_bitmap[cnt] = '1'; + } else { + visual_bitmap[cnt] = '0'; + } + } + + return visual_bitmap; + } + } + } + + return "Unknown"; +} + +static PyObject* PySavePacket_repr(PySavePacket* self) +{ + PyObject* s; + PoolMem buf(PM_MESSAGE); + + Mmsg(buf, + "SavePacket(fname=\"%s\", link=\"%s\", type=%ld, flags=%s, " + "no_read=%d, portable=%d, accurate_found=%d, " + "cmd=\"%s\", save_time=%ld, delta_seq=%ld, object_name=\"%s\", " + "object=\"%s\", object_len=%ld, object_index=%ld)", + PyGetStringValue(self->fname), PyGetStringValue(self->link), self->type, + print_flags_bitmap(self->flags), self->no_read, self->portable, + self->accurate_found, self->cmd, self->save_time, self->delta_seq, + PyGetStringValue(self->object_name), PyGetByteArrayValue(self->object), + self->object_len, self->object_index); + + s = PyString_FromString(buf.c_str()); + + return s; +} + +/** + * Initialization. + */ +static int PySavePacket_init(PySavePacket* self, PyObject* args, PyObject* kwds) +{ + static char* kwlist[] = { + (char*)"fname", (char*)"link", (char*)"type", + (char*)"flags", (char*)"no_read", (char*)"portable", + (char*)"accurate_found", (char*)"cmd", (char*)"save_time", + (char*)"delta_seq", (char*)"object_name", (char*)"object", + (char*)"object_len", (char*)"object_index", NULL}; + + self->fname = NULL; + self->link = NULL; + self->type = 0; + self->flags = NULL; + self->no_read = false; + self->portable = false; + self->accurate_found = false; + self->cmd = NULL; + self->save_time = 0; + self->delta_seq = 0; + self->object_name = NULL; + self->object = NULL; + self->object_len = 0; + self->object_index = 0; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|ooiocccsiiooii", kwlist, &self->fname, &self->link, + &self->type, &self->flags, &self->no_read, &self->portable, + &self->accurate_found, &self->cmd, &self->save_time, &self->delta_seq, + &self->object_name, &self->object, &self->object_len, + &self->object_index)) { + return -1; + } + + return 0; +} + +/** + * Destructor. + */ +static void PySavePacket_dealloc(PySavePacket* self) +{ + if (self->fname) { Py_XDECREF(self->fname); } + if (self->link) { Py_XDECREF(self->link); } + if (self->flags) { Py_XDECREF(self->flags); } + if (self->object_name) { Py_XDECREF(self->object_name); } + if (self->object) { Py_XDECREF(self->object); } + PyObject_Del(self); +} + +/** + * Python specific handlers for PyRestorePacket structure mapping. + */ + +/** + * Representation. + */ +static PyObject* PyRestorePacket_repr(PyRestorePacket* self) +{ + PyObject *stat_repr, *s; + PoolMem buf(PM_MESSAGE); + + stat_repr = PyObject_Repr(self->statp); + Mmsg(buf, + "RestorePacket(stream=%d, data_stream=%ld, type=%ld, file_index=%ld, " + "linkFI=%ld, uid=%ld, statp=\"%s\", attrEx=\"%s\", ofname=\"%s\", " + "olname=\"%s\", where=\"%s\", RegexWhere=\"%s\", replace=%d, " + "create_status=%d)", + self->stream, self->data_stream, self->type, self->file_index, + self->LinkFI, self->uid, PyGetStringValue(stat_repr), self->attrEx, + self->ofname, self->olname, self->where, self->RegexWhere, self->replace, + self->create_status); + + s = PyString_FromString(buf.c_str()); + Py_DECREF(stat_repr); + + return s; +} + +/** + * Initialization. + */ +static int PyRestorePacket_init(PyRestorePacket* self, + PyObject* args, + PyObject* kwds) +{ + static char* kwlist[] = { + (char*)"stream", (char*)"data_stream", (char*)"type", + (char*)"file_index", (char*)"linkFI", (char*)"uid", + (char*)"statp", (char*)"attrEX", (char*)"ofname", + (char*)"olname", (char*)"where", (char*)"regexwhere", + (char*)"replace", (char*)"create_status", NULL}; + + self->stream = 0; + self->data_stream = 0; + self->type = 0; + self->file_index = 0; + self->LinkFI = 0; + self->uid = 0; + self->statp = NULL; + self->attrEx = NULL; + self->ofname = NULL; + self->olname = NULL; + self->where = NULL; + self->RegexWhere = NULL; + self->replace = 0; + self->create_status = 0; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|iiiiiIosssssii", kwlist, &self->stream, + &self->data_stream, &self->type, &self->file_index, &self->LinkFI, + &self->uid, &self->statp, &self->attrEx, &self->ofname, &self->olname, + &self->where, &self->RegexWhere, &self->replace, + &self->create_status)) { + return -1; + } + + return 0; +} + +/** + * Destructor. + */ +static void PyRestorePacket_dealloc(PyRestorePacket* self) +{ + PyObject_Del(self); +} + +/** + * Python specific handlers for PyIoPacket structure mapping. + */ + +/** + * Representation. + */ +static PyObject* PyIoPacket_repr(PyIoPacket* self) +{ + PyObject* s; + PoolMem buf(PM_MESSAGE); + + Mmsg(buf, + "IoPacket(func=%d, count=%ld, flags=%ld, mode=%04o, " + "buf=\"%s\", fname=\"%s\", status=%ld, io_errno=%ld, lerror=%ld, " + "whence=%ld, offset=%lld, win32=%d)", + self->func, self->count, self->flags, (self->mode & ~S_IFMT), + PyGetByteArrayValue(self->buf), self->fname, self->status, + self->io_errno, self->lerror, self->whence, self->offset, self->win32); + s = PyString_FromString(buf.c_str()); + + return s; +} + +/** + * Initialization. + */ +static int PyIoPacket_init(PyIoPacket* self, PyObject* args, PyObject* kwds) +{ + static char* kwlist[] = {(char*)"func", + (char*)"count", + (char*)"flags", + (char*)"mode", + (char*)"buf", + (char*)"fname", + (char*)"status", + (char*)"io_errno", + (char*)"lerror", + (char*)"whence", + (char*)"offset", + (char*)"win32", + NULL}; + + self->func = 0; + self->count = 0; + self->flags = 0; + self->mode = 0; + self->buf = NULL; + self->fname = NULL; + self->status = 0; + self->io_errno = 0; + self->lerror = 0; + self->whence = 0; + self->offset = 0; + self->win32 = false; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|Hiiiosiiiilc", kwlist, &self->func, &self->count, + &self->flags, &self->mode, &self->buf, &self->fname, &self->status, + &self->io_errno, &self->lerror, &self->whence, &self->offset, + &self->win32)) { + return -1; + } + + return 0; +} + +/** + * Destructor. + */ +static void PyIoPacket_dealloc(PyIoPacket* self) +{ + if (self->buf) { Py_XDECREF(self->buf); } + PyObject_Del(self); +} + +/** + * Python specific handlers for PyAclPacket structure mapping. + */ + +/** + * Representation. + */ +static PyObject* PyAclPacket_repr(PyAclPacket* self) +{ + PyObject* s; + PoolMem buf(PM_MESSAGE); + + Mmsg(buf, "AclPacket(fname=\"%s\", content=\"%s\")", self->fname, + PyGetByteArrayValue(self->content)); + s = PyString_FromString(buf.c_str()); + + return s; +} + +/** + * Initialization. + */ +static int PyAclPacket_init(PyAclPacket* self, PyObject* args, PyObject* kwds) +{ + static char* kwlist[] = {(char*)"fname", (char*)"content", NULL}; + + self->fname = NULL; + self->content = NULL; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|so", kwlist, &self->fname, + &self->content)) { + return -1; + } + + return 0; +} + +/** + * Destructor. + */ +static void PyAclPacket_dealloc(PyAclPacket* self) +{ + if (self->content) { Py_XDECREF(self->content); } + PyObject_Del(self); +} + +/** + * Python specific handlers for PyIOPacket structure mapping. + */ + +/** + * Representation. + */ +static PyObject* PyXattrPacket_repr(PyXattrPacket* self) +{ + PyObject* s; + PoolMem buf(PM_MESSAGE); + + Mmsg(buf, "XattrPacket(fname=\"%s\", name=\"%s\", value=\"%s\")", self->fname, + PyGetByteArrayValue(self->name), PyGetByteArrayValue(self->value)); + s = PyString_FromString(buf.c_str()); + + return s; +} + +/** + * Initialization. + */ +static int PyXattrPacket_init(PyXattrPacket* self, + PyObject* args, + PyObject* kwds) +{ + static char* kwlist[] = {(char*)"fname", (char*)"name", (char*)"value", NULL}; + + self->fname = NULL; + self->name = NULL; + self->value = NULL; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|soo", kwlist, &self->fname, + &self->name, &self->value)) { + return -1; + } + + return 0; +} + +/** + * Destructor. + */ +static void PyXattrPacket_dealloc(PyXattrPacket* self) +{ + if (self->value) { Py_XDECREF(self->value); } + if (self->name) { Py_XDECREF(self->name); } + PyObject_Del(self); +} + + +} /* namespace filedaemon */ diff --git a/core/src/plugins/filed/python/setup.py.in b/core/src/plugins/filed/python/setup.py.in index 9fbe9b40976..f7e84d692f8 100644 --- a/core/src/plugins/filed/python/setup.py.in +++ b/core/src/plugins/filed/python/setup.py.in @@ -1,7 +1,7 @@ from distutils.core import setup, Extension module1 = Extension('bareosfd', - sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/python-fd.cc'], + sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/bareosfd.cc'], include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..', '/usr/local/opt/gettext/include', '/usr/local/opt/openssl/include'], libraries = ['bareos'], library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'], From 3166f4d93cd1edd38d157238ae7cea11360b96de Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 30 Apr 2020 08:42:51 +0200 Subject: [PATCH 058/341] plugins: rename bInfo -> Core_PluginApiDefinition --- core/src/filed/fd_plugins.cc | 3 ++- core/src/filed/fd_plugins.h | 2 +- core/src/plugins/filed/bpipe/bpipe-fd.cc | 4 ++-- core/src/plugins/filed/cephfs/cephfs-fd.cc | 4 ++-- .../src/plugins/filed/example/example-plugin-fd.cc | 4 ++-- core/src/plugins/filed/gfapi/gfapi-fd.cc | 4 ++-- core/src/plugins/filed/python/bareosfd.cc | 12 +++++++----- core/src/plugins/filed/python/python-fd.cc | 14 ++++++++------ core/src/plugins/filed/rados/rados-fd.cc | 4 ++-- .../filed/test-deltaseq/test-deltaseq-fd.cc | 4 ++-- .../plugins/filed/test-plugin/test-plugin-fd.cc | 4 ++-- core/src/tools/bpluginfo.cc | 8 ++++---- core/src/win32/plugins/filed/mssqlvdi-fd.cc | 6 +++--- 13 files changed, 39 insertions(+), 34 deletions(-) diff --git a/core/src/filed/fd_plugins.cc b/core/src/filed/fd_plugins.cc index a4ee338b0de..ac38000ed55 100644 --- a/core/src/filed/fd_plugins.cc +++ b/core/src/filed/fd_plugins.cc @@ -135,7 +135,8 @@ static boffset_t MyPluginBlseek(BareosWinFilePacket* bfd, int whence); /* Bareos info */ -static bInfo binfo = {sizeof(bInfo), FD_PLUGIN_INTERFACE_VERSION}; +static Core_PluginApiDefinition binfo = {sizeof(Core_PluginApiDefinition), + FD_PLUGIN_INTERFACE_VERSION}; /* Bareos entry points */ static bFuncs bfuncs = {sizeof(bFuncs), diff --git a/core/src/filed/fd_plugins.h b/core/src/filed/fd_plugins.h index f031d7c5655..792e3089ff5 100644 --- a/core/src/filed/fd_plugins.h +++ b/core/src/filed/fd_plugins.h @@ -257,7 +257,7 @@ typedef struct s_bEvent { typedef struct s_bareosInfo { uint32_t size; uint32_t version; -} bInfo; +} Core_PluginApiDefinition; /* * Bareos Core Routines -- not used within a plugin diff --git a/core/src/plugins/filed/bpipe/bpipe-fd.cc b/core/src/plugins/filed/bpipe/bpipe-fd.cc index c77caf1c5f4..a52bac661e2 100644 --- a/core/src/plugins/filed/bpipe/bpipe-fd.cc +++ b/core/src/plugins/filed/bpipe/bpipe-fd.cc @@ -70,7 +70,7 @@ static bRC plugin_has_all_arguments(bpContext* ctx); /* Pointers to Bareos functions */ static bFuncs* bfuncs = NULL; -static bInfo* binfo = NULL; +static Core_PluginApiDefinition* binfo = NULL; /* Plugin Information block */ static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, @@ -139,7 +139,7 @@ extern "C" { /** * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(bInfo* lbinfo, +bRC loadPlugin(Core_PluginApiDefinition* lbinfo, bFuncs* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs) diff --git a/core/src/plugins/filed/cephfs/cephfs-fd.cc b/core/src/plugins/filed/cephfs/cephfs-fd.cc index 047b587dd5b..cab6fbf8d12 100644 --- a/core/src/plugins/filed/cephfs/cephfs-fd.cc +++ b/core/src/plugins/filed/cephfs/cephfs-fd.cc @@ -77,7 +77,7 @@ static bRC end_restore_job(bpContext* ctx, void* value); * Pointers to Bareos functions */ static bFuncs* bfuncs = NULL; -static bInfo* binfo = NULL; +static Core_PluginApiDefinition* binfo = NULL; /** * Plugin Information block @@ -179,7 +179,7 @@ extern "C" { * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(bInfo* lbinfo, +bRC loadPlugin(Core_PluginApiDefinition* lbinfo, bFuncs* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs) diff --git a/core/src/plugins/filed/example/example-plugin-fd.cc b/core/src/plugins/filed/example/example-plugin-fd.cc index 6964681507e..23647ce3a74 100644 --- a/core/src/plugins/filed/example/example-plugin-fd.cc +++ b/core/src/plugins/filed/example/example-plugin-fd.cc @@ -47,7 +47,7 @@ static bRC setXattr(bpContext* ctx, xattr_pkt* xp); /* Pointers to Bareos functions */ static bFuncs* bfuncs = NULL; -static bInfo* binfo = NULL; +static Core_PluginApiDefinition* binfo = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, FD_PLUGIN_MAGIC, PLUGIN_LICENSE, @@ -71,7 +71,7 @@ extern "C" { /* * Plugin called here when it is first loaded */ -bRC loadPlugin(bInfo* lbinfo, +bRC loadPlugin(Core_PluginApiDefinition* lbinfo, bFuncs* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs) diff --git a/core/src/plugins/filed/gfapi/gfapi-fd.cc b/core/src/plugins/filed/gfapi/gfapi-fd.cc index a7321a4c510..ea8328113bb 100644 --- a/core/src/plugins/filed/gfapi/gfapi-fd.cc +++ b/core/src/plugins/filed/gfapi/gfapi-fd.cc @@ -92,7 +92,7 @@ static bRC setup_restore(bpContext* ctx, void* value); * Pointers to Bareos functions */ static bFuncs* bfuncs = NULL; -static bInfo* binfo = NULL; +static Core_PluginApiDefinition* binfo = NULL; /** * Plugin Information block @@ -313,7 +313,7 @@ extern "C" { * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(bInfo* lbinfo, +bRC loadPlugin(Core_PluginApiDefinition* lbinfo, bFuncs* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs) diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 3f3545a2585..29102de9238 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -122,7 +122,7 @@ static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, /* Pointers to Bareos functions */ static bFuncs* bfuncs = NULL; -static bInfo* binfo = NULL; +static Core_PluginApiDefinition* binfo = NULL; /* static genpInfo pluginInfo = {sizeof(pluginInfo), * FD_PLUGIN_INTERFACE_VERSION, */ @@ -217,7 +217,7 @@ static void PyErrorHandler() /** * Plugin called here when it is first loaded */ -/* bRC loadPlugin(bInfo* lbinfo, */ +/* bRC loadPlugin(Core_PluginApiDefinition* lbinfo, */ /* bFuncs* lbfuncs, */ /* genpInfo** pinfo, */ /* pFuncs** pfuncs) */ @@ -249,9 +249,11 @@ static void PyErrorHandler() /* // Extract capsules pointer from bareosfd module */ /* void (*loadplugin_from_bareosfd_module)( */ -/* filedaemon::bInfo * lbinfo, filedaemon::bFuncs * lbfuncs, */ +/* filedaemon::Core_PluginApiDefinition * lbinfo, filedaemon::bFuncs * + * lbfuncs, */ /* genpInfo * *pinfo, filedaemon::pFuncs * *pfuncs) = */ -/* (void (*)(filedaemon::bInfo*, filedaemon::bFuncs*, genpInfo**, */ +/* (void (*)(filedaemon::Core_PluginApiDefinition*, filedaemon::bFuncs*, + * genpInfo**, */ /* filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", */ /* 0); */ @@ -279,7 +281,7 @@ static void PyErrorHandler() /* *(void**)bfuncs_from_bareosfd_module = &bfuncs; */ /* /1* call loadPlugin in plugin *1/ */ -/* filedaemon::bInfo myInfo; */ +/* filedaemon::Core_PluginApiDefinition myInfo; */ /* genpInfo pinfo; */ /* filedaemon::pFuncs pfuncs; */ diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 00d3b159330..2ceca2f59a6 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -121,7 +121,7 @@ static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, /* Pointers to Bareos functions */ static bFuncs* bfuncs = NULL; -static bInfo* binfo = NULL; +static Core_PluginApiDefinition* binfo = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, FD_PLUGIN_MAGIC, PLUGIN_LICENSE, @@ -215,7 +215,7 @@ static void PyErrorHandler() /** * Plugin called here when it is first loaded */ -bRC loadPlugin(bInfo* lbinfo, +bRC loadPlugin(Core_PluginApiDefinition* lbinfo, bFuncs* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs) @@ -247,9 +247,11 @@ bRC loadPlugin(bInfo* lbinfo, // Extract capsules pointer from bareosfd module void (*loadplugin_from_bareosfd_module)( - filedaemon::bInfo * lbinfo, filedaemon::bFuncs * lbfuncs, - genpInfo * *pinfo, filedaemon::pFuncs * *pfuncs) = - (void (*)(filedaemon::bInfo*, filedaemon::bFuncs*, genpInfo**, + filedaemon::Core_PluginApiDefinition * lbinfo, + filedaemon::bFuncs * lbfuncs, genpInfo * *pinfo, + filedaemon::pFuncs * *pfuncs) = + (void (*)(filedaemon::Core_PluginApiDefinition*, filedaemon::bFuncs*, + genpInfo**, filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", 0); @@ -274,7 +276,7 @@ bRC loadPlugin(bInfo* lbinfo, *(void**)bfuncs_from_bareosfd_module = &bfuncs; /* call loadPlugin in plugin */ - filedaemon::bInfo myInfo; + filedaemon::Core_PluginApiDefinition myInfo; genpInfo pinfo; filedaemon::pFuncs pfuncs; diff --git a/core/src/plugins/filed/rados/rados-fd.cc b/core/src/plugins/filed/rados/rados-fd.cc index f7ae647c8d8..a9f3119f8c7 100644 --- a/core/src/plugins/filed/rados/rados-fd.cc +++ b/core/src/plugins/filed/rados/rados-fd.cc @@ -85,7 +85,7 @@ static bRC end_restore_job(bpContext* ctx, void* value); * Pointers to Bareos functions */ static bFuncs* bfuncs = NULL; -static bInfo* binfo = NULL; +static Core_PluginApiDefinition* binfo = NULL; /** * Plugin Information block @@ -178,7 +178,7 @@ extern "C" { * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(bInfo* lbinfo, +bRC loadPlugin(Core_PluginApiDefinition* lbinfo, bFuncs* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs) diff --git a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc index 6c82398c563..fed40888da1 100644 --- a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc +++ b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc @@ -55,7 +55,7 @@ static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp); /* Pointers to Bareos functions */ static bFuncs* bfuncs = NULL; -static bInfo* binfo = NULL; +static Core_PluginApiDefinition* binfo = NULL; /* Plugin Information block */ static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, @@ -116,7 +116,7 @@ extern "C" { /** * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(bInfo* lbinfo, +bRC loadPlugin(Core_PluginApiDefinition* lbinfo, bFuncs* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs) diff --git a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc index ab5452cd2b7..4ae68c9e42e 100644 --- a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc +++ b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc @@ -64,7 +64,7 @@ static bRC setXattr(bpContext* ctx, xattr_pkt* xp); /* Pointers to Bareos functions */ static bFuncs* bfuncs = NULL; -static bInfo* binfo = NULL; +static Core_PluginApiDefinition* binfo = NULL; /* Plugin Information block */ static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, @@ -122,7 +122,7 @@ extern "C" { /** * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(bInfo* lbinfo, +bRC loadPlugin(Core_PluginApiDefinition* lbinfo, bFuncs* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs) diff --git a/core/src/tools/bpluginfo.cc b/core/src/tools/bpluginfo.cc index df3288881d9..bea5e2b1858 100644 --- a/core/src/tools/bpluginfo.cc +++ b/core/src/tools/bpluginfo.cc @@ -3,7 +3,7 @@ Copyright (C) 2006-2012 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2016 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -106,13 +106,13 @@ struct _bareosfuncs { /* * bDirInfo - * bInfo + * Core_PluginApiDefinition * bsdInfo */ typedef union _bareosinfos bareosinfos; union _bareosinfos { directordaemon::bDirInfo bdirinfo; - filedaemon::bInfo bfdinfo; + filedaemon::Core_PluginApiDefinition bfdinfo; storagedaemon::bsdInfo bsdinfo; }; @@ -140,7 +140,7 @@ struct _progdata { #define FREE(ptr) \ if (ptr != NULL) { \ - free(ptr); \ + free(ptr); \ ptr = NULL; \ } diff --git a/core/src/win32/plugins/filed/mssqlvdi-fd.cc b/core/src/win32/plugins/filed/mssqlvdi-fd.cc index dfb7ede755f..40d2cdd8d4c 100644 --- a/core/src/win32/plugins/filed/mssqlvdi-fd.cc +++ b/core/src/win32/plugins/filed/mssqlvdi-fd.cc @@ -3,7 +3,7 @@ Copyright (C) 2010 Zilvinas Krapavickas Copyright (C) 2013-2014 Planets Communications B.V. - Copyright (C) 2013-2019 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -113,7 +113,7 @@ static bool adoReportError(bpContext* ctx); * Pointers to Bareos functions */ static bFuncs* bfuncs = NULL; -static bInfo* binfo = NULL; +static Core_PluginApiDefinition* binfo = NULL; /** * Plugin Information block @@ -227,7 +227,7 @@ extern "C" { * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(bInfo* lbinfo, +bRC loadPlugin(Core_PluginApiDefinition* lbinfo, bFuncs* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs) From d48375f677540f9e28622c66eaae35073a6bfd1a Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 30 Apr 2020 08:44:26 +0200 Subject: [PATCH 059/341] python-fd.h: fixup problems after rename --- core/src/plugins/filed/python/python-fd.h | 2 +- .../filed/python/test/python-fd-module-tester.cc | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/src/plugins/filed/python/python-fd.h b/core/src/plugins/filed/python/python-fd.h index fcbfae17190..0dac21d6cb7 100644 --- a/core/src/plugins/filed/python/python-fd.h +++ b/core/src/plugins/filed/python/python-fd.h @@ -762,7 +762,7 @@ static void* bfuncs = NULL; extern "C" { #endif /* Forward declaration of loadPlugin() as it is stored in Capsule */ -bRC loadPlugin(bInfo* lbinfo, +bRC loadPlugin(::Core_PluginApiDefinition* lbinfo, bFuncs* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs); diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index 7607add5c78..63b178c1a21 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -203,9 +203,11 @@ int main(int argc, char* argv[]) // Extract capsules pointer from bareosfd module void (*loadplugin_from_bareosfd_module)( - filedaemon::bInfo * lbinfo, filedaemon::bFuncs * lbfuncs, - genpInfo * *pinfo, filedaemon::pFuncs * *pfuncs) = - (void (*)(filedaemon::bInfo*, filedaemon::bFuncs*, genpInfo**, + filedaemon::Core_PluginApiDefinition * lbinfo, + filedaemon::bFuncs * lbfuncs, genpInfo * *pinfo, + filedaemon::pFuncs * *pfuncs) = + (void (*)(filedaemon::Core_PluginApiDefinition*, filedaemon::bFuncs*, + genpInfo**, filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", 0); @@ -229,7 +231,7 @@ int main(int argc, char* argv[]) *(void**)bfuncs_from_bareosfd_module = &bfuncs; /* call loadPlugin in plugin */ - filedaemon::bInfo myInfo; + filedaemon::Core_PluginApiDefinition myInfo; genpInfo pinfo; filedaemon::pFuncs pfuncs; From 802e2bd06ed2930e5cb2cf3e4221ca149f707743 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 30 Apr 2020 08:46:26 +0200 Subject: [PATCH 060/341] plugins: rename bFuncs -> BareosCoreFunctions --- core/src/filed/fd_plugins.cc | 46 +++++++-------- core/src/filed/fd_plugins.h | 2 +- core/src/plugins/filed/bpipe/bpipe-fd.cc | 4 +- core/src/plugins/filed/cephfs/cephfs-fd.cc | 4 +- .../filed/example/example-plugin-fd.cc | 4 +- core/src/plugins/filed/gfapi/gfapi-fd.cc | 4 +- core/src/plugins/filed/python/bareosfd.cc | 22 +++---- core/src/plugins/filed/python/python-fd.cc | 19 +++--- core/src/plugins/filed/python/python-fd.h | 17 +++--- .../filed/python/test/bareosfd_test.py | 4 +- .../python/test/python-fd-module-tester.cc | 58 ++++++++++--------- core/src/plugins/filed/rados/rados-fd.cc | 4 +- .../filed/test-deltaseq/test-deltaseq-fd.cc | 4 +- .../filed/test-plugin/test-plugin-fd.cc | 4 +- core/src/tools/bpluginfo.cc | 2 +- core/src/win32/plugins/filed/mssqlvdi-fd.cc | 4 +- 16 files changed, 104 insertions(+), 98 deletions(-) diff --git a/core/src/filed/fd_plugins.cc b/core/src/filed/fd_plugins.cc index ac38000ed55..6709975ca2b 100644 --- a/core/src/filed/fd_plugins.cc +++ b/core/src/filed/fd_plugins.cc @@ -139,29 +139,29 @@ static Core_PluginApiDefinition binfo = {sizeof(Core_PluginApiDefinition), FD_PLUGIN_INTERFACE_VERSION}; /* Bareos entry points */ -static bFuncs bfuncs = {sizeof(bFuncs), - FD_PLUGIN_INTERFACE_VERSION, - bareosRegisterEvents, - bareosUnRegisterEvents, - bareosGetInstanceCount, - bareosGetValue, - bareosSetValue, - bareosJobMsg, - bareosDebugMsg, - bareosMalloc, - bareosFree, - bareosAddExclude, - bareosAddInclude, - bareosAddOptions, - bareosAddRegex, - bareosAddWild, - bareosNewOptions, - bareosNewInclude, - bareosNewPreInclude, - bareosCheckChanges, - bareosAcceptFile, - bareosSetSeenBitmap, - bareosClearSeenBitmap}; +static BareosCoreFunctions bfuncs = {sizeof(BareosCoreFunctions), + FD_PLUGIN_INTERFACE_VERSION, + bareosRegisterEvents, + bareosUnRegisterEvents, + bareosGetInstanceCount, + bareosGetValue, + bareosSetValue, + bareosJobMsg, + bareosDebugMsg, + bareosMalloc, + bareosFree, + bareosAddExclude, + bareosAddInclude, + bareosAddOptions, + bareosAddRegex, + bareosAddWild, + bareosNewOptions, + bareosNewInclude, + bareosNewPreInclude, + bareosCheckChanges, + bareosAcceptFile, + bareosSetSeenBitmap, + bareosClearSeenBitmap}; /** * Bareos private context diff --git a/core/src/filed/fd_plugins.h b/core/src/filed/fd_plugins.h index 792e3089ff5..69394930c3d 100644 --- a/core/src/filed/fd_plugins.h +++ b/core/src/filed/fd_plugins.h @@ -355,7 +355,7 @@ typedef struct s_bareosFuncs { struct save_pkt* sp); /* Need fname and statp */ bRC (*SetSeenBitmap)(bpContext* ctx, bool all, char* fname); bRC (*ClearSeenBitmap)(bpContext* ctx, bool all, char* fname); -} bFuncs; +} BareosCoreFunctions; /**************************************************************************** * * diff --git a/core/src/plugins/filed/bpipe/bpipe-fd.cc b/core/src/plugins/filed/bpipe/bpipe-fd.cc index a52bac661e2..b5ee5de2a4c 100644 --- a/core/src/plugins/filed/bpipe/bpipe-fd.cc +++ b/core/src/plugins/filed/bpipe/bpipe-fd.cc @@ -69,7 +69,7 @@ static bRC parse_plugin_definition(bpContext* ctx, void* value); static bRC plugin_has_all_arguments(bpContext* ctx); /* Pointers to Bareos functions */ -static bFuncs* bfuncs = NULL; +static BareosCoreFunctions* bfuncs = NULL; static Core_PluginApiDefinition* binfo = NULL; /* Plugin Information block */ @@ -140,7 +140,7 @@ extern "C" { * External entry point called by Bareos to "load" the plugin */ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, - bFuncs* lbfuncs, + BareosCoreFunctions* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs) { diff --git a/core/src/plugins/filed/cephfs/cephfs-fd.cc b/core/src/plugins/filed/cephfs/cephfs-fd.cc index cab6fbf8d12..812c144fb98 100644 --- a/core/src/plugins/filed/cephfs/cephfs-fd.cc +++ b/core/src/plugins/filed/cephfs/cephfs-fd.cc @@ -76,7 +76,7 @@ static bRC end_restore_job(bpContext* ctx, void* value); /** * Pointers to Bareos functions */ -static bFuncs* bfuncs = NULL; +static BareosCoreFunctions* bfuncs = NULL; static Core_PluginApiDefinition* binfo = NULL; /** @@ -180,7 +180,7 @@ extern "C" { * External entry point called by Bareos to "load" the plugin */ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, - bFuncs* lbfuncs, + BareosCoreFunctions* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs) { diff --git a/core/src/plugins/filed/example/example-plugin-fd.cc b/core/src/plugins/filed/example/example-plugin-fd.cc index 23647ce3a74..63d1a26f1b8 100644 --- a/core/src/plugins/filed/example/example-plugin-fd.cc +++ b/core/src/plugins/filed/example/example-plugin-fd.cc @@ -46,7 +46,7 @@ static bRC setXattr(bpContext* ctx, xattr_pkt* xp); /* Pointers to Bareos functions */ -static bFuncs* bfuncs = NULL; +static BareosCoreFunctions* bfuncs = NULL; static Core_PluginApiDefinition* binfo = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, @@ -72,7 +72,7 @@ extern "C" { * Plugin called here when it is first loaded */ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, - bFuncs* lbfuncs, + BareosCoreFunctions* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs) { diff --git a/core/src/plugins/filed/gfapi/gfapi-fd.cc b/core/src/plugins/filed/gfapi/gfapi-fd.cc index ea8328113bb..a3eb2d002ee 100644 --- a/core/src/plugins/filed/gfapi/gfapi-fd.cc +++ b/core/src/plugins/filed/gfapi/gfapi-fd.cc @@ -91,7 +91,7 @@ static bRC setup_restore(bpContext* ctx, void* value); /** * Pointers to Bareos functions */ -static bFuncs* bfuncs = NULL; +static BareosCoreFunctions* bfuncs = NULL; static Core_PluginApiDefinition* binfo = NULL; /** @@ -314,7 +314,7 @@ extern "C" { * External entry point called by Bareos to "load" the plugin */ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, - bFuncs* lbfuncs, + BareosCoreFunctions* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs) { diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 29102de9238..f3f3871dc3a 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -121,7 +121,7 @@ static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp); /* Pointers to Bareos functions */ -static bFuncs* bfuncs = NULL; +static BareosCoreFunctions* bfuncs = NULL; static Core_PluginApiDefinition* binfo = NULL; /* static genpInfo pluginInfo = {sizeof(pluginInfo), @@ -157,7 +157,7 @@ struct plugin_private_context { interpreter; /* Python interpreter for this instance of the plugin */ PyObject* pModule; /* Python Module entry point */ PyObject* pyModuleFunctionsDict; /* Python Dictionary */ - bFuncs* bfuncs; /* pointer to bfuncs */ + BareosCoreFunctions* bfuncs; /* pointer to bfuncs */ }; /** @@ -218,7 +218,7 @@ static void PyErrorHandler() * Plugin called here when it is first loaded */ /* bRC loadPlugin(Core_PluginApiDefinition* lbinfo, */ -/* bFuncs* lbfuncs, */ +/* BareosCoreFunctions* lbfuncs, */ /* genpInfo** pinfo, */ /* pFuncs** pfuncs) */ /* { */ @@ -249,11 +249,11 @@ static void PyErrorHandler() /* // Extract capsules pointer from bareosfd module */ /* void (*loadplugin_from_bareosfd_module)( */ -/* filedaemon::Core_PluginApiDefinition * lbinfo, filedaemon::bFuncs * - * lbfuncs, */ +/* filedaemon::Core_PluginApiDefinition * lbinfo, + * filedaemon::BareosCoreFunctions * lbfuncs, */ /* genpInfo * *pinfo, filedaemon::pFuncs * *pfuncs) = */ -/* (void (*)(filedaemon::Core_PluginApiDefinition*, filedaemon::bFuncs*, - * genpInfo**, */ +/* (void (*)(filedaemon::Core_PluginApiDefinition*, + * filedaemon::BareosCoreFunctions*, genpInfo**, */ /* filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", */ /* 0); */ @@ -265,11 +265,11 @@ static void PyErrorHandler() /* printf("importing bareosfd.bpContext failed \n"); */ /* } */ -/* // Extract capsules bareosfd.bFuncs */ -/* void* bfuncs_from_bareosfd_module = PyCapsule_Import("bareosfd.bFuncs", - * 0); */ +/* // Extract capsules bareosfd.BareosCoreFunctions */ +/* void* bfuncs_from_bareosfd_module = + * PyCapsule_Import("bareosfd.BareosCoreFunctions", 0); */ /* if (!bfuncs_from_bareosfd_module) { */ -/* printf("importing bareosfd.bFuncs failed \n"); */ +/* printf("importing bareosfd.BareosCoreFunctions failed \n"); */ /* } */ /* if (!loadplugin_from_bareosfd_module) { */ diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 2ceca2f59a6..ddc49c62715 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -120,7 +120,7 @@ static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp); /* Pointers to Bareos functions */ -static bFuncs* bfuncs = NULL; +static BareosCoreFunctions* bfuncs = NULL; static Core_PluginApiDefinition* binfo = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, @@ -155,7 +155,7 @@ struct plugin_private_context { interpreter; /* Python interpreter for this instance of the plugin */ PyObject* pModule; /* Python Module entry point */ PyObject* pyModuleFunctionsDict; /* Python Dictionary */ - bFuncs* bfuncs; /* pointer to bfuncs */ + BareosCoreFunctions* bfuncs; /* pointer to bfuncs */ }; /** @@ -216,7 +216,7 @@ static void PyErrorHandler() * Plugin called here when it is first loaded */ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, - bFuncs* lbfuncs, + BareosCoreFunctions* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs) { @@ -248,10 +248,10 @@ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, // Extract capsules pointer from bareosfd module void (*loadplugin_from_bareosfd_module)( filedaemon::Core_PluginApiDefinition * lbinfo, - filedaemon::bFuncs * lbfuncs, genpInfo * *pinfo, + filedaemon::BareosCoreFunctions * lbfuncs, genpInfo * *pinfo, filedaemon::pFuncs * *pfuncs) = - (void (*)(filedaemon::Core_PluginApiDefinition*, filedaemon::bFuncs*, - genpInfo**, + (void (*)(filedaemon::Core_PluginApiDefinition*, + filedaemon::BareosCoreFunctions*, genpInfo**, filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", 0); @@ -261,10 +261,11 @@ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, printf("importing bareosfd.bpContext failed \n"); } - // Extract capsules bareosfd.bFuncs - void* bfuncs_from_bareosfd_module = PyCapsule_Import("bareosfd.bFuncs", 0); + // Extract capsules bareosfd.BareosCoreFunctions + void* bfuncs_from_bareosfd_module = + PyCapsule_Import("bareosfd.BareosCoreFunctions", 0); if (!bfuncs_from_bareosfd_module) { - printf("importing bareosfd.bFuncs failed \n"); + printf("importing bareosfd.BareosCoreFunctions failed \n"); } if (!loadplugin_from_bareosfd_module) { diff --git a/core/src/plugins/filed/python/python-fd.h b/core/src/plugins/filed/python/python-fd.h index 0dac21d6cb7..3b115e87b9d 100644 --- a/core/src/plugins/filed/python/python-fd.h +++ b/core/src/plugins/filed/python/python-fd.h @@ -763,7 +763,7 @@ extern "C" { #endif /* Forward declaration of loadPlugin() as it is stored in Capsule */ bRC loadPlugin(::Core_PluginApiDefinition* lbinfo, - bFuncs* lbfuncs, + BareosCoreFunctions* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs); #ifdef __cplusplus @@ -795,17 +795,20 @@ MOD_INIT(bareosfd) } /* add bpFuncs Capsule */ - PyObject* PyModulePluginFuncs = - PyCapsule_New((void*)&bfuncs, PYTHON_MODULE_NAME_QUOTED ".bFuncs", NULL); + PyObject* PyModulePluginFuncs = PyCapsule_New( + (void*)&bfuncs, PYTHON_MODULE_NAME_QUOTED ".BareosCoreFunctions", NULL); if (!PyModulePluginFuncs) { - printf(PYTHON_MODULE_NAME_QUOTED ":bFuncs PyCapsule_New failed\n"); + printf(PYTHON_MODULE_NAME_QUOTED + ":BareosCoreFunctions PyCapsule_New failed\n"); return MOD_ERROR_VAL; } if (PyModulePluginFuncs) { - PyModule_AddObject(m, "bFuncs", PyModulePluginFuncs); - printf(PYTHON_MODULE_NAME_QUOTED ": added bFuncs@%p\n", &bfuncs); + PyModule_AddObject(m, "BareosCoreFunctions", PyModulePluginFuncs); + printf(PYTHON_MODULE_NAME_QUOTED ": added BareosCoreFunctions@%p\n", + &bfuncs); } else { - printf(PYTHON_MODULE_NAME_QUOTED ":bFuncs PyModule_AddObject failed\n"); + printf(PYTHON_MODULE_NAME_QUOTED + ":BareosCoreFunctions PyModule_AddObject failed\n"); return MOD_ERROR_VAL; } diff --git a/core/src/plugins/filed/python/test/bareosfd_test.py b/core/src/plugins/filed/python/test/bareosfd_test.py index 3a66b4d3b2b..1d93a9f19a0 100644 --- a/core/src/plugins/filed/python/test/bareosfd_test.py +++ b/core/src/plugins/filed/python/test/bareosfd_test.py @@ -7,7 +7,7 @@ # print "bareosfd.bVariable:", str( bareosfd.bVariable) # print "bareosfd.bEventType:", str( bareosfd.bEventType) # print "bareosfd.bFileType:", str( bareosfd.bFileType) -# print "bareosfd.bFuncs:", str( bareosfd.bFuncs) +# print "bareosfd.BareosCoreFunctions:", str( bareosfd.BareosCoreFunctions) # print "bareosfd.bIOPS:", str( bareosfd.bIOPS) # print "bareosfd.bLevels:", str( bareosfd.bLevels) # print "bareosfd.bRCs:", str( bareosfd.bRCs) @@ -24,7 +24,7 @@ def test_ModuleDicts(self): # print bCFs # bEventType # bFileType - # bFuncs + # BareosCoreFunctions # bIOPS # bJobMessageType # bLevels diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index 63b178c1a21..743e7748175 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -147,29 +147,30 @@ bRC bareosClearSeenBitmap(bpContext* ctx, bool all, char* fname) /* Bareos entry points */ -static filedaemon::bFuncs bfuncs = {sizeof(filedaemon::bFuncs), - FD_PLUGIN_INTERFACE_VERSION, - bareosRegisterEvents, - bareosUnRegisterEvents, - bareosGetInstanceCount, - bareosGetValue, - bareosSetValue, - bareosJobMsg, - bareosDebugMsg, - bareosMalloc, - bareosFree, - bareosAddExclude, - bareosAddInclude, - bareosAddOptions, - bareosAddRegex, - bareosAddWild, - bareosNewOptions, - bareosNewInclude, - bareosNewPreInclude, - bareosCheckChanges, - bareosAcceptFile, - bareosSetSeenBitmap, - bareosClearSeenBitmap}; +static filedaemon::BareosCoreFunctions bfuncs = { + sizeof(filedaemon::BareosCoreFunctions), + FD_PLUGIN_INTERFACE_VERSION, + bareosRegisterEvents, + bareosUnRegisterEvents, + bareosGetInstanceCount, + bareosGetValue, + bareosSetValue, + bareosJobMsg, + bareosDebugMsg, + bareosMalloc, + bareosFree, + bareosAddExclude, + bareosAddInclude, + bareosAddOptions, + bareosAddRegex, + bareosAddWild, + bareosNewOptions, + bareosNewInclude, + bareosNewPreInclude, + bareosCheckChanges, + bareosAcceptFile, + bareosSetSeenBitmap, + bareosClearSeenBitmap}; static void* bareos_plugin_context = NULL; @@ -196,18 +197,19 @@ int main(int argc, char* argv[]) } // Extract capsules pointer from bareosfd module - void* bfuncs_from_bareosfd_module = PyCapsule_Import("bareosfd.bFuncs", 0); + void* bfuncs_from_bareosfd_module = + PyCapsule_Import("bareosfd.BareosCoreFunctions", 0); if (!bfuncs_from_bareosfd_module) { - printf("importing bareosfd.bFuncs failed \n"); + printf("importing bareosfd.BareosCoreFunctions failed \n"); } // Extract capsules pointer from bareosfd module void (*loadplugin_from_bareosfd_module)( filedaemon::Core_PluginApiDefinition * lbinfo, - filedaemon::bFuncs * lbfuncs, genpInfo * *pinfo, + filedaemon::BareosCoreFunctions * lbfuncs, genpInfo * *pinfo, filedaemon::pFuncs * *pfuncs) = - (void (*)(filedaemon::Core_PluginApiDefinition*, filedaemon::bFuncs*, - genpInfo**, + (void (*)(filedaemon::Core_PluginApiDefinition*, + filedaemon::BareosCoreFunctions*, genpInfo**, filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", 0); diff --git a/core/src/plugins/filed/rados/rados-fd.cc b/core/src/plugins/filed/rados/rados-fd.cc index a9f3119f8c7..cf53d98dab6 100644 --- a/core/src/plugins/filed/rados/rados-fd.cc +++ b/core/src/plugins/filed/rados/rados-fd.cc @@ -84,7 +84,7 @@ static bRC end_restore_job(bpContext* ctx, void* value); /** * Pointers to Bareos functions */ -static bFuncs* bfuncs = NULL; +static BareosCoreFunctions* bfuncs = NULL; static Core_PluginApiDefinition* binfo = NULL; /** @@ -179,7 +179,7 @@ extern "C" { * External entry point called by Bareos to "load" the plugin */ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, - bFuncs* lbfuncs, + BareosCoreFunctions* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs) { diff --git a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc index fed40888da1..a9749fd32bb 100644 --- a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc +++ b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc @@ -54,7 +54,7 @@ static bRC createFile(bpContext* ctx, struct restore_pkt* rp); static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp); /* Pointers to Bareos functions */ -static bFuncs* bfuncs = NULL; +static BareosCoreFunctions* bfuncs = NULL; static Core_PluginApiDefinition* binfo = NULL; /* Plugin Information block */ @@ -117,7 +117,7 @@ extern "C" { * External entry point called by Bareos to "load" the plugin */ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, - bFuncs* lbfuncs, + BareosCoreFunctions* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs) { diff --git a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc index 4ae68c9e42e..7450527d0ae 100644 --- a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc +++ b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc @@ -63,7 +63,7 @@ static bRC getXattr(bpContext* ctx, xattr_pkt* xp); static bRC setXattr(bpContext* ctx, xattr_pkt* xp); /* Pointers to Bareos functions */ -static bFuncs* bfuncs = NULL; +static BareosCoreFunctions* bfuncs = NULL; static Core_PluginApiDefinition* binfo = NULL; /* Plugin Information block */ @@ -123,7 +123,7 @@ extern "C" { * External entry point called by Bareos to "load" the plugin */ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, - bFuncs* lbfuncs, + BareosCoreFunctions* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs) { diff --git a/core/src/tools/bpluginfo.cc b/core/src/tools/bpluginfo.cc index bea5e2b1858..f5e2b40950d 100644 --- a/core/src/tools/bpluginfo.cc +++ b/core/src/tools/bpluginfo.cc @@ -77,7 +77,7 @@ union _plugfuncs { /* * bDirFuncs - * bFuncs + * BareosCoreFunctions * bsdFuncs */ typedef struct _bareosfuncs bareosfuncs; diff --git a/core/src/win32/plugins/filed/mssqlvdi-fd.cc b/core/src/win32/plugins/filed/mssqlvdi-fd.cc index 40d2cdd8d4c..be73f9f085e 100644 --- a/core/src/win32/plugins/filed/mssqlvdi-fd.cc +++ b/core/src/win32/plugins/filed/mssqlvdi-fd.cc @@ -112,7 +112,7 @@ static bool adoReportError(bpContext* ctx); /** * Pointers to Bareos functions */ -static bFuncs* bfuncs = NULL; +static BareosCoreFunctions* bfuncs = NULL; static Core_PluginApiDefinition* binfo = NULL; /** @@ -228,7 +228,7 @@ extern "C" { * External entry point called by Bareos to "load" the plugin */ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, - bFuncs* lbfuncs, + BareosCoreFunctions* lbfuncs, genpInfo** pinfo, pFuncs** pfuncs) { From 1a21179f7fd42f01e1390eca2353879bd3d3875d Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 30 Apr 2020 08:47:47 +0200 Subject: [PATCH 061/341] plugins: rename bfuncs -> bareos_core_functions --- core/src/dird/dir_plugins.cc | 21 ++-- core/src/filed/fd_plugins.cc | 50 +++++----- core/src/lib/ini.cc | 8 +- core/src/lib/plugins.cc | 19 ++-- core/src/lib/plugins.h | 6 +- .../dird/example/example-plugin-dir.cc | 49 +++++----- core/src/plugins/dird/python/python-dir.cc | 42 ++++---- core/src/plugins/filed/bpipe/bpipe-fd.cc | 9 +- core/src/plugins/filed/cephfs/cephfs-fd.cc | 19 ++-- .../filed/example/example-plugin-fd.cc | 18 ++-- core/src/plugins/filed/fd_common.h | 26 ++--- core/src/plugins/filed/gfapi/gfapi-fd.cc | 29 +++--- core/src/plugins/filed/python/bareosfd.cc | 90 ++++++++++------- core/src/plugins/filed/python/python-fd.cc | 98 +++++++++++-------- core/src/plugins/filed/python/python-fd.h | 11 ++- .../python/test/python-fd-module-tester.cc | 30 +++--- core/src/plugins/filed/rados/rados-fd.cc | 21 ++-- .../filed/test-deltaseq/test-deltaseq-fd.cc | 16 +-- .../filed/test-plugin/test-plugin-fd.cc | 34 ++++--- core/src/plugins/python_plugins_common.h | 9 +- .../stored/autoxflate/autoxflate-sd.cc | 42 ++++---- .../stored/example/example-plugin-sd.cc | 28 +++--- core/src/plugins/stored/python/python-sd.cc | 48 +++++---- .../stored/scsicrypto/scsicrypto-sd.cc | 28 +++--- .../stored/scsitapealert/scsitapealert-sd.cc | 17 ++-- core/src/stored/sd_plugins.cc | 21 ++-- core/src/tools/bpluginfo.cc | 17 +++- core/src/win32/plugins/filed/mssqlvdi-fd.cc | 13 +-- 28 files changed, 459 insertions(+), 360 deletions(-) diff --git a/core/src/dird/dir_plugins.cc b/core/src/dird/dir_plugins.cc index 8d18959f638..7664b882346 100644 --- a/core/src/dird/dir_plugins.cc +++ b/core/src/dird/dir_plugins.cc @@ -3,7 +3,7 @@ Copyright (C) 2007-2011 Free Software Foundation Europe e.V. Copyright (C) 2011-2016 Planets Communications B.V. - Copyright (C) 2013-2019 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -70,11 +70,12 @@ static bool IsPluginCompatible(Plugin* plugin); static bDirInfo binfo = {sizeof(bDirFuncs), DIR_PLUGIN_INTERFACE_VERSION}; /* BAREOS entry points */ -static bDirFuncs bfuncs = {sizeof(bDirFuncs), DIR_PLUGIN_INTERFACE_VERSION, - bareosRegisterEvents, bareosUnRegisterEvents, - bareosGetInstanceCount, bareosGetValue, - bareosSetValue, bareosJobMsg, - bareosDebugMsg}; +static bDirFuncs bareos_core_functions = { + sizeof(bDirFuncs), DIR_PLUGIN_INTERFACE_VERSION, + bareosRegisterEvents, bareosUnRegisterEvents, + bareosGetInstanceCount, bareosGetValue, + bareosSetValue, bareosJobMsg, + bareosDebugMsg}; /* * BAREOS private context @@ -293,8 +294,9 @@ void LoadDirPlugins(const char* plugin_dir, alist* plugin_names) } dird_plugin_list = new alist(10, not_owned_by_alist); - if (!LoadPlugins((void*)&binfo, (void*)&bfuncs, dird_plugin_list, plugin_dir, - plugin_names, plugin_type, IsPluginCompatible)) { + if (!LoadPlugins((void*)&binfo, (void*)&bareos_core_functions, + dird_plugin_list, plugin_dir, plugin_names, plugin_type, + IsPluginCompatible)) { /* Either none found, or some error */ if (dird_plugin_list->size() == 0) { delete dird_plugin_list; @@ -613,8 +615,7 @@ static bRC bareosGetValue(bpContext* ctx, brDirVariable var, void* value) case bDirVarNumVols: { PoolDbRecord pr; - bstrncpy(pr.Name, jcr->impl->res.pool->resource_name_, - sizeof(pr.Name)); + bstrncpy(pr.Name, jcr->impl->res.pool->resource_name_, sizeof(pr.Name)); if (!jcr->db->GetPoolRecord(jcr, &pr)) { retval = bRC_Error; } *((int*)value) = pr.NumVols; Dmsg1(debuglevel, "dir-plugin: return bDirVarNumVols=%d\n", pr.NumVols); diff --git a/core/src/filed/fd_plugins.cc b/core/src/filed/fd_plugins.cc index 6709975ca2b..9d8b5b81ae6 100644 --- a/core/src/filed/fd_plugins.cc +++ b/core/src/filed/fd_plugins.cc @@ -139,29 +139,29 @@ static Core_PluginApiDefinition binfo = {sizeof(Core_PluginApiDefinition), FD_PLUGIN_INTERFACE_VERSION}; /* Bareos entry points */ -static BareosCoreFunctions bfuncs = {sizeof(BareosCoreFunctions), - FD_PLUGIN_INTERFACE_VERSION, - bareosRegisterEvents, - bareosUnRegisterEvents, - bareosGetInstanceCount, - bareosGetValue, - bareosSetValue, - bareosJobMsg, - bareosDebugMsg, - bareosMalloc, - bareosFree, - bareosAddExclude, - bareosAddInclude, - bareosAddOptions, - bareosAddRegex, - bareosAddWild, - bareosNewOptions, - bareosNewInclude, - bareosNewPreInclude, - bareosCheckChanges, - bareosAcceptFile, - bareosSetSeenBitmap, - bareosClearSeenBitmap}; +static BareosCoreFunctions bareos_core_functions = {sizeof(BareosCoreFunctions), + FD_PLUGIN_INTERFACE_VERSION, + bareosRegisterEvents, + bareosUnRegisterEvents, + bareosGetInstanceCount, + bareosGetValue, + bareosSetValue, + bareosJobMsg, + bareosDebugMsg, + bareosMalloc, + bareosFree, + bareosAddExclude, + bareosAddInclude, + bareosAddOptions, + bareosAddRegex, + bareosAddWild, + bareosNewOptions, + bareosNewInclude, + bareosNewPreInclude, + bareosCheckChanges, + bareosAcceptFile, + bareosSetSeenBitmap, + bareosClearSeenBitmap}; /** * Bareos private context @@ -1714,8 +1714,8 @@ void LoadFdPlugins(const char* plugin_dir, alist* plugin_names) } fd_plugin_list = new alist(10, not_owned_by_alist); - if (!LoadPlugins((void*)&binfo, (void*)&bfuncs, fd_plugin_list, plugin_dir, - plugin_names, plugin_type, IsPluginCompatible)) { + if (!LoadPlugins((void*)&binfo, (void*)&bareos_core_functions, fd_plugin_list, + plugin_dir, plugin_names, plugin_type, IsPluginCompatible)) { /* * Either none found, or some error */ diff --git a/core/src/lib/ini.cc b/core/src/lib/ini.cc index 7076e7e9180..1208e6d65e7 100644 --- a/core/src/lib/ini.cc +++ b/core/src/lib/ini.cc @@ -1,7 +1,7 @@ /* Copyright (C) 2011-2011 Bacula Systems(R) SA Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2013 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can modify it under the terms of version three of the GNU Affero General Public License as published by the @@ -244,7 +244,8 @@ static void s_err(const char* file, int line, LEX* lc, const char* msg, ...) buf.c_str(), lc->line_no, lc->col_no, lc->fname, lc->line); // } else if (ini->ctx) { /* called from plugin */ - // ini->bfuncs->JobMessage(ini->ctx, __FILE__, __LINE__, M_FATAL, 0, + // ini->bareos_core_functions->JobMessage(ini->ctx, __FILE__, __LINE__, + // M_FATAL, 0, // _("Config file error: %s\n" // " : Line %d, col %d of file %s\n%s\n"), // buf.c_str(), lc->line_no, lc->col_no, @@ -290,7 +291,8 @@ static void s_warn(const char* file, int line, LEX* lc, const char* msg, ...) buf.c_str(), lc->line_no, lc->col_no, lc->fname, lc->line); // } else if (ini->ctx) { /* called from plugin */ - // ini->bfuncs->JobMessage(ini->ctx, __FILE__, __LINE__, M_WARNING, 0, + // ini->bareos_core_functions->JobMessage(ini->ctx, __FILE__, __LINE__, + // M_WARNING, 0, // _("Config file warning: %s\n" // " : Line %d, col %d of file %s\n%s\n"), // buf.c_str(), lc->line_no, lc->col_no, diff --git a/core/src/lib/plugins.cc b/core/src/lib/plugins.cc index a4e679d15a0..52200026dce 100644 --- a/core/src/lib/plugins.cc +++ b/core/src/lib/plugins.cc @@ -3,7 +3,7 @@ Copyright (C) 2007-2012 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2019 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -107,7 +107,7 @@ static void ClosePlugin(Plugin* plugin) * entry points, the license is compatible and the initialize the plugin. */ static bool load_a_plugin(void* binfo, - void* bfuncs, + void* bareos_core_functions, const char* plugin_pathname, const char* plugin_name, const char* type, @@ -168,7 +168,8 @@ static bool load_a_plugin(void* binfo, /* * Initialize the plugin */ - if (loadPlugin(binfo, bfuncs, &plugin->pinfo, &plugin->pfuncs) != bRC_OK) { + if (loadPlugin(binfo, bareos_core_functions, &plugin->pinfo, + &plugin->pfuncs) != bRC_OK) { ClosePlugin(plugin); return false; @@ -193,7 +194,7 @@ static bool load_a_plugin(void* binfo, * to load from the specified directory. */ bool LoadPlugins(void* binfo, - void* bfuncs, + void* bareos_core_functions, alist* plugin_list, const char* plugin_dir, alist* plugin_names, @@ -241,8 +242,9 @@ bool LoadPlugins(void* binfo, /* * Try to load the plugin and resolve the wanted symbols. */ - if (load_a_plugin(binfo, bfuncs, fname.c_str(), plugin_name.c_str(), type, - plugin_list, IsPluginCompatible)) { + if (load_a_plugin(binfo, bareos_core_functions, fname.c_str(), + plugin_name.c_str(), type, plugin_list, + IsPluginCompatible)) { found = true; } } @@ -311,8 +313,9 @@ bool LoadPlugins(void* binfo, /* * Try to load the plugin and resolve the wanted symbols. */ - if (load_a_plugin(binfo, bfuncs, fname.c_str(), result->d_name, type, - plugin_list, IsPluginCompatible)) { + if (load_a_plugin(binfo, bareos_core_functions, fname.c_str(), + result->d_name, type, plugin_list, + IsPluginCompatible)) { found = true; } } diff --git a/core/src/lib/plugins.h b/core/src/lib/plugins.h index b6420bdbe3b..e39a32178ec 100644 --- a/core/src/lib/plugins.h +++ b/core/src/lib/plugins.h @@ -3,7 +3,7 @@ Copyright (C) 2007-2011 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2016 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -60,7 +60,7 @@ typedef enum extern "C" { typedef bRC (*t_loadPlugin)(void* binfo, - void* bfuncs, + void* bareos_core_functions, void** pinfo, void** pfuncs); typedef bRC (*t_unloadPlugin)(void); @@ -102,7 +102,7 @@ class alist; /* Functions */ bool LoadPlugins(void* binfo, - void* bfuncs, + void* bareos_core_functions, alist* plugin_list, const char* plugin_dir, alist* plugin_names, diff --git a/core/src/plugins/dird/example/example-plugin-dir.cc b/core/src/plugins/dird/example/example-plugin-dir.cc index a0198de19ea..4bcddca5cd5 100644 --- a/core/src/plugins/dird/example/example-plugin-dir.cc +++ b/core/src/plugins/dird/example/example-plugin-dir.cc @@ -2,7 +2,7 @@ BAREOS® - Backup Archiving REcovery Open Sourced Copyright (C) 2007-2010 Free Software Foundation Europe e.V. - Copyright (C) 2016-2016 Bareos GmbH & Co. KG + Copyright (C) 2016-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -46,7 +46,7 @@ static bRC handlePluginEvent(bpContext* ctx, bDirEvent* event, void* value); /* Pointers to Bareos functions */ -static bDirFuncs* bfuncs = NULL; +static bDirFuncs* bareos_core_functions = NULL; static bDirInfo* binfo = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), DIR_PLUGIN_INTERFACE_VERSION, @@ -74,13 +74,15 @@ extern "C" { * External entry point called by Bareos to "load" the plugin */ bRC loadPlugin(bDirInfo* lbinfo, - bDirFuncs* lbfuncs, + bDirFuncs* lbareos_core_functions, genpInfo** pinfo, pDirFuncs** pfuncs) { - bfuncs = lbfuncs; /* set Bareos funct pointers */ + bareos_core_functions = + lbareos_core_functions; /* set Bareos funct pointers */ binfo = lbinfo; - printf("plugin: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->version); + printf("plugin: Loaded: size=%d version=%d\n", bareos_core_functions->size, + bareos_core_functions->version); *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ @@ -104,16 +106,17 @@ bRC unloadPlugin() static bRC newPlugin(bpContext* ctx) { int JobId = 0; - bfuncs->getBareosValue(ctx, bDirVarJobId, (void*)&JobId); + bareos_core_functions->getBareosValue(ctx, bDirVarJobId, (void*)&JobId); printf("plugin: newPlugin JobId=%d\n", JobId); - bfuncs->registerBareosEvents(ctx, 2, bDirEventJobStart, bDirEventJobEnd); + bareos_core_functions->registerBareosEvents(ctx, 2, bDirEventJobStart, + bDirEventJobEnd); return bRC_OK; } static bRC freePlugin(bpContext* ctx) { int JobId = 0; - bfuncs->getBareosValue(ctx, bDirVarJobId, (void*)&JobId); + bareos_core_functions->getBareosValue(ctx, bDirVarJobId, (void*)&JobId); printf("plugin: freePlugin JobId=%d\n", JobId); return bRC_OK; } @@ -140,34 +143,36 @@ static bRC handlePluginEvent(bpContext* ctx, bDirEvent* event, void* value) break; case bDirEventJobEnd: printf("plugin: HandleEvent JobEnd\n"); - bfuncs->getBareosValue(ctx, bDirVarJob, (void*)&name); + bareos_core_functions->getBareosValue(ctx, bDirVarJob, (void*)&name); printf("plugin: bDirVarJob=%s\n", name); - bfuncs->getBareosValue(ctx, bDirVarJobId, (void*)&val); + bareos_core_functions->getBareosValue(ctx, bDirVarJobId, (void*)&val); printf("plugin: bDirVarJobId=%d\n", val); - bfuncs->getBareosValue(ctx, bDirVarType, (void*)&val); + bareos_core_functions->getBareosValue(ctx, bDirVarType, (void*)&val); printf("plugin: bDirVarType=%c\n", val); - bfuncs->getBareosValue(ctx, bDirVarLevel, (void*)&val); + bareos_core_functions->getBareosValue(ctx, bDirVarLevel, (void*)&val); printf("plugin: bDirVarLevel=%c\n", val); - bfuncs->getBareosValue(ctx, bDirVarClient, (void*)&name); + bareos_core_functions->getBareosValue(ctx, bDirVarClient, (void*)&name); printf("plugin: bDirVarClient=%s\n", name); - bfuncs->getBareosValue(ctx, bDirVarCatalog, (void*)&name); + bareos_core_functions->getBareosValue(ctx, bDirVarCatalog, (void*)&name); printf("plugin: bDirVarCatalog=%s\n", name); - bfuncs->getBareosValue(ctx, bDirVarPool, (void*)&name); + bareos_core_functions->getBareosValue(ctx, bDirVarPool, (void*)&name); printf("plugin: bDirVarPool=%s\n", name); - bfuncs->getBareosValue(ctx, bDirVarStorage, (void*)&name); + bareos_core_functions->getBareosValue(ctx, bDirVarStorage, (void*)&name); printf("plugin: bDirVarStorage=%s\n", name); - bfuncs->getBareosValue(ctx, bDirVarJobErrors, (void*)&val); + bareos_core_functions->getBareosValue(ctx, bDirVarJobErrors, (void*)&val); printf("plugin: bDirVarJobErrors=%d\n", val); - bfuncs->getBareosValue(ctx, bDirVarJobFiles, (void*)&val); + bareos_core_functions->getBareosValue(ctx, bDirVarJobFiles, (void*)&val); printf("plugin: bDirVarJobFiles=%d\n", val); - bfuncs->getBareosValue(ctx, bDirVarNumVols, (void*)&val); + bareos_core_functions->getBareosValue(ctx, bDirVarNumVols, (void*)&val); printf("plugin: bDirVarNumVols=%d\n", val); break; } - bfuncs->getBareosValue(ctx, bDirVarJobName, (void*)&name); + bareos_core_functions->getBareosValue(ctx, bDirVarJobName, (void*)&name); printf("Job Name=%s\n", name); - bfuncs->JobMessage(ctx, __FILE__, __LINE__, M_INFO, 0, "JobMesssage message"); - bfuncs->DebugMessage(ctx, __FILE__, __LINE__, 1, "DebugMesssage message"); + bareos_core_functions->JobMessage(ctx, __FILE__, __LINE__, M_INFO, 0, + "JobMesssage message"); + bareos_core_functions->DebugMessage(ctx, __FILE__, __LINE__, 1, + "DebugMesssage message"); return bRC_OK; } } /* namespace directordaemon */ diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index 77b266f3f36..95837d93580 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -87,7 +87,7 @@ static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, void* value); /* Pointers to Bareos functions */ -static bDirFuncs* bfuncs = NULL; +static bDirFuncs* bareos_core_functions = NULL; static bDirInfo* binfo = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), DIR_PLUGIN_INTERFACE_VERSION, @@ -142,11 +142,12 @@ extern "C" { * External entry point called by Bareos to "load" the plugin */ bRC loadPlugin(bDirInfo* lbinfo, - bDirFuncs* lbfuncs, + bDirFuncs* lbareos_core_functions, genpInfo** pinfo, pDirFuncs** pfuncs) { - bfuncs = lbfuncs; /* Set Bareos funct pointers */ + bareos_core_functions = + lbareos_core_functions; /* Set Bareos funct pointers */ binfo = lbinfo; *pinfo = &pluginInfo; /* Return pointer to our info */ @@ -203,7 +204,8 @@ static bRC newPlugin(bpContext* bareos_plugin_ctx) * Always register some events the python plugin itself can register * any other events it is interested in. */ - bfuncs->registerBareosEvents(bareos_plugin_ctx, 1, bDirEventNewPluginOptions); + bareos_core_functions->registerBareosEvents(bareos_plugin_ctx, 1, + bDirEventNewPluginOptions); return bRC_OK; } @@ -682,8 +684,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarSDJobStatus: { int value = 0; - if (bfuncs->getBareosValue(bareos_plugin_ctx, (brDirVariable)var, - &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue( + bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } break; @@ -697,8 +699,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarReadBytes: { uint64_t value = 0; - if (bfuncs->getBareosValue(bareos_plugin_ctx, (brDirVariable)var, - &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue( + bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { pRetVal = PyLong_FromUnsignedLong(value); } break; @@ -715,8 +717,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarVolumeName: { char* value = NULL; - if (bfuncs->getBareosValue(bareos_plugin_ctx, (brDirVariable)var, - &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue( + bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } } break; @@ -724,7 +726,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarPluginDir: { char* value = NULL; - if (bfuncs->getBareosValue(NULL, (brDirVariable)var, &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue(NULL, (brDirVariable)var, + &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } } break; @@ -765,8 +768,8 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) value = PyString_AsString(pyValue); if (value) { - retval = bfuncs->setBareosValue(bareos_plugin_ctx, (bwDirVariable)var, - value); + retval = bareos_core_functions->setBareosValue( + bareos_plugin_ctx, (bwDirVariable)var, value); } break; @@ -777,8 +780,8 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) value = PyInt_AsLong(pyValue); if (value >= 0) { - retval = bfuncs->setBareosValue(bareos_plugin_ctx, (bwDirVariable)var, - &value); + retval = bareos_core_functions->setBareosValue( + bareos_plugin_ctx, (bwDirVariable)var, &value); } break; } @@ -865,7 +868,8 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { Dmsg(bareos_plugin_ctx, debuglevel, "python-dir: PyBareosRegisterEvents registering event %d\n", event); - retval = bfuncs->registerBareosEvents(bareos_plugin_ctx, 1, event); + retval = bareos_core_functions->registerBareosEvents(bareos_plugin_ctx, 1, + event); if (retval != bRC_OK) { break; } } @@ -906,7 +910,8 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { Dmsg(bareos_plugin_ctx, debuglevel, "PyBareosUnRegisterEvents: registering event %d\n", event); - retval = bfuncs->unregisterBareosEvents(bareos_plugin_ctx, 1, event); + retval = bareos_core_functions->unregisterBareosEvents(bareos_plugin_ctx, + 1, event); if (retval != bRC_OK) { break; } } @@ -932,7 +937,8 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (bfuncs->getInstanceCount(bareos_plugin_ctx, &value) == bRC_OK) { + if (bareos_core_functions->getInstanceCount(bareos_plugin_ctx, &value) == + bRC_OK) { pRetVal = PyInt_FromLong(value); } diff --git a/core/src/plugins/filed/bpipe/bpipe-fd.cc b/core/src/plugins/filed/bpipe/bpipe-fd.cc index b5ee5de2a4c..80e403404c0 100644 --- a/core/src/plugins/filed/bpipe/bpipe-fd.cc +++ b/core/src/plugins/filed/bpipe/bpipe-fd.cc @@ -69,7 +69,7 @@ static bRC parse_plugin_definition(bpContext* ctx, void* value); static bRC plugin_has_all_arguments(bpContext* ctx); /* Pointers to Bareos functions */ -static BareosCoreFunctions* bfuncs = NULL; +static BareosCoreFunctions* bareos_core_functions = NULL; static Core_PluginApiDefinition* binfo = NULL; /* Plugin Information block */ @@ -140,11 +140,12 @@ extern "C" { * External entry point called by Bareos to "load" the plugin */ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, - BareosCoreFunctions* lbfuncs, + BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs) { - bfuncs = lbfuncs; /* set Bareos funct pointers */ + bareos_core_functions = + lbareos_core_functions; /* set Bareos funct pointers */ binfo = lbinfo; *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ @@ -177,7 +178,7 @@ static bRC newPlugin(bpContext* ctx) memset(p_ctx, 0, sizeof(struct plugin_ctx)); ctx->pContext = (void*)p_ctx; /* set our context pointer */ - bfuncs->registerBareosEvents( + bareos_core_functions->registerBareosEvents( ctx, 6, bEventNewPluginOptions, bEventPluginCommand, bEventJobStart, bEventRestoreCommand, bEventEstimateCommand, bEventBackupCommand); diff --git a/core/src/plugins/filed/cephfs/cephfs-fd.cc b/core/src/plugins/filed/cephfs/cephfs-fd.cc index 812c144fb98..42064f57c08 100644 --- a/core/src/plugins/filed/cephfs/cephfs-fd.cc +++ b/core/src/plugins/filed/cephfs/cephfs-fd.cc @@ -76,7 +76,7 @@ static bRC end_restore_job(bpContext* ctx, void* value); /** * Pointers to Bareos functions */ -static BareosCoreFunctions* bfuncs = NULL; +static BareosCoreFunctions* bareos_core_functions = NULL; static Core_PluginApiDefinition* binfo = NULL; /** @@ -180,11 +180,12 @@ extern "C" { * External entry point called by Bareos to "load" the plugin */ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, - BareosCoreFunctions* lbfuncs, + BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs) { - bfuncs = lbfuncs; /* set Bareos funct pointers */ + bareos_core_functions = + lbareos_core_functions; /* set Bareos funct pointers */ binfo = lbinfo; *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ @@ -248,10 +249,10 @@ static bRC newPlugin(bpContext* ctx) /* * Only register the events we are really interested in. */ - bfuncs->registerBareosEvents(ctx, 7, bEventLevel, bEventSince, - bEventRestoreCommand, bEventBackupCommand, - bEventPluginCommand, bEventEndRestoreJob, - bEventNewPluginOptions); + bareos_core_functions->registerBareosEvents( + ctx, 7, bEventLevel, bEventSince, bEventRestoreCommand, + bEventBackupCommand, bEventPluginCommand, bEventEndRestoreJob, + bEventNewPluginOptions); return bRC_OK; } @@ -573,7 +574,7 @@ static bRC get_next_file_to_backup(bpContext* ctx) #else memcpy(&sp.statp, &p_ctx->statp, sizeof(sp.statp)); #endif - if (bfuncs->AcceptFile(ctx, &sp) == bRC_Skip) { + if (bareos_core_functions->AcceptFile(ctx, &sp) == bRC_Skip) { Dmsg(ctx, debuglevel, "cephfs-fd: file %s skipped due to current fileset settings\n", p_ctx->next_filename); @@ -748,7 +749,7 @@ static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) switch (p_ctx->backup_level) { case L_INCREMENTAL: case L_DIFFERENTIAL: - switch (bfuncs->checkChanges(ctx, sp)) { + switch (bareos_core_functions->checkChanges(ctx, sp)) { case bRC_Seen: Dmsg(ctx, debuglevel, "cephfs-fd: skipping %s checkChanges returns bRC_Seen\n", diff --git a/core/src/plugins/filed/example/example-plugin-fd.cc b/core/src/plugins/filed/example/example-plugin-fd.cc index 63d1a26f1b8..6afba518a59 100644 --- a/core/src/plugins/filed/example/example-plugin-fd.cc +++ b/core/src/plugins/filed/example/example-plugin-fd.cc @@ -46,7 +46,7 @@ static bRC setXattr(bpContext* ctx, xattr_pkt* xp); /* Pointers to Bareos functions */ -static BareosCoreFunctions* bfuncs = NULL; +static BareosCoreFunctions* bareos_core_functions = NULL; static Core_PluginApiDefinition* binfo = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, @@ -72,13 +72,15 @@ extern "C" { * Plugin called here when it is first loaded */ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, - BareosCoreFunctions* lbfuncs, + BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs) { - bfuncs = lbfuncs; /* set Bareos funct pointers */ + bareos_core_functions = + lbareos_core_functions; /* set Bareos funct pointers */ binfo = lbinfo; - printf("plugin: Loaded: size=%d version=%d\n", bfuncs->size, bfuncs->version); + printf("plugin: Loaded: size=%d version=%d\n", bareos_core_functions->size, + bareos_core_functions->version); *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ @@ -110,9 +112,9 @@ bRC unloadPlugin() static bRC newPlugin(bpContext* ctx) { int JobId = 0; - bfuncs->getBareosValue(ctx, bVarJobId, (void*)&JobId); + bareos_core_functions->getBareosValue(ctx, bVarJobId, (void*)&JobId); // printf("plugin: newPlugin JobId=%d\n", JobId); - bfuncs->registerBareosEvents( + bareos_core_functions->registerBareosEvents( ctx, 10, bEventJobStart, bEventJobEnd, bEventStartBackupJob, bEventEndBackupJob, bEventLevel, bEventSince, bEventStartRestoreJob, bEventEndRestoreJob, bEventRestoreCommand, bEventBackupCommand); @@ -126,7 +128,7 @@ static bRC newPlugin(bpContext* ctx) static bRC freePlugin(bpContext* ctx) { int JobId = 0; - bfuncs->getBareosValue(ctx, bVarJobId, (void*)&JobId); + bareos_core_functions->getBareosValue(ctx, bVarJobId, (void*)&JobId); // printf("plugin: freePlugin JobId=%d\n", JobId); return bRC_OK; } @@ -201,7 +203,7 @@ static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) default: printf("plugin: unknown event=%d\n", event->eventType); } - bfuncs->getBareosValue(ctx, bVarFDName, (void*)&name); + bareos_core_functions->getBareosValue(ctx, bVarFDName, (void*)&name); return bRC_OK; } diff --git a/core/src/plugins/filed/fd_common.h b/core/src/plugins/filed/fd_common.h index 04167789ec0..f7fcb3d0df0 100644 --- a/core/src/plugins/filed/fd_common.h +++ b/core/src/plugins/filed/fd_common.h @@ -36,22 +36,24 @@ #define L_DIFFERENTIAL 'D' /* since last full backup */ #define Dmsg(context, level, ...) \ - if (bfuncs && context) { \ - bfuncs->DebugMessage(context, __FILE__, __LINE__, level, __VA_ARGS__); \ + if (bareos_core_functions && context) { \ + bareos_core_functions->DebugMessage(context, __FILE__, __LINE__, level, \ + __VA_ARGS__); \ } else { \ - fprintf( \ - stderr, \ - "Dmsg: bfuncs(%p) and context(%p) need to be set before Dmsg call\n", \ - bfuncs, context); \ + fprintf(stderr, \ + "Dmsg: bareos_core_functions(%p) and context(%p) need to be set " \ + "before Dmsg call\n", \ + bareos_core_functions, context); \ } #define Jmsg(context, type, ...) \ - if (bfuncs && context) { \ - bfuncs->JobMessage(context, __FILE__, __LINE__, type, 0, __VA_ARGS__); \ + if (bareos_core_functions && context) { \ + bareos_core_functions->JobMessage(context, __FILE__, __LINE__, type, 0, \ + __VA_ARGS__); \ } else { \ - fprintf( \ - stderr, \ - "Jmsg: bfuncs(%p) and context(%p) need to be set before Jmsg call\n", \ - bfuncs, context); \ + fprintf(stderr, \ + "Jmsg: bareos_core_functions(%p) and context(%p) need to be set " \ + "before Jmsg call\n", \ + bareos_core_functions, context); \ } #endif diff --git a/core/src/plugins/filed/gfapi/gfapi-fd.cc b/core/src/plugins/filed/gfapi/gfapi-fd.cc index a3eb2d002ee..cff764f72d3 100644 --- a/core/src/plugins/filed/gfapi/gfapi-fd.cc +++ b/core/src/plugins/filed/gfapi/gfapi-fd.cc @@ -91,7 +91,7 @@ static bRC setup_restore(bpContext* ctx, void* value); /** * Pointers to Bareos functions */ -static BareosCoreFunctions* bfuncs = NULL; +static BareosCoreFunctions* bareos_core_functions = NULL; static Core_PluginApiDefinition* binfo = NULL; /** @@ -314,11 +314,12 @@ extern "C" { * External entry point called by Bareos to "load" the plugin */ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, - BareosCoreFunctions* lbfuncs, + BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs) { - bfuncs = lbfuncs; /* set Bareos funct pointers */ + bareos_core_functions = + lbareos_core_functions; /* set Bareos funct pointers */ binfo = lbinfo; *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ @@ -371,10 +372,10 @@ static bRC newPlugin(bpContext* ctx) /* * Only register the events we are really interested in. */ - bfuncs->registerBareosEvents(ctx, 7, bEventLevel, bEventSince, - bEventRestoreCommand, bEventBackupCommand, - bEventPluginCommand, bEventEndRestoreJob, - bEventNewPluginOptions); + bareos_core_functions->registerBareosEvents( + ctx, 7, bEventLevel, bEventSince, bEventRestoreCommand, + bEventBackupCommand, bEventPluginCommand, bEventEndRestoreJob, + bEventNewPluginOptions); return bRC_OK; } @@ -639,7 +640,8 @@ static bRC get_next_file_to_backup(bpContext* ctx) *bp++ = '\0'; if (p_ctx->is_accurate) { UrllibUnquotePlus(p_ctx->next_filename); - bfuncs->ClearSeenBitmap(ctx, false, p_ctx->next_filename); + bareos_core_functions->ClearSeenBitmap(ctx, false, + p_ctx->next_filename); } bstrinlinecpy(p_ctx->next_filename, bp); UrllibUnquotePlus(p_ctx->next_filename); @@ -652,7 +654,8 @@ static bRC get_next_file_to_backup(bpContext* ctx) bstrinlinecpy(p_ctx->next_filename, p_ctx->next_filename + gf_mapping->compare_size); UrllibUnquotePlus(p_ctx->next_filename); - bfuncs->ClearSeenBitmap(ctx, false, p_ctx->next_filename); + bareos_core_functions->ClearSeenBitmap(ctx, false, + p_ctx->next_filename); } continue; default: @@ -810,7 +813,7 @@ static bRC get_next_file_to_backup(bpContext* ctx) sp.type = p_ctx->type; memcpy(&sp.statp, &p_ctx->statp, sizeof(sp.statp)); - if (bfuncs->AcceptFile(ctx, &sp) == bRC_Skip) { + if (bareos_core_functions->AcceptFile(ctx, &sp) == bRC_Skip) { Dmsg(ctx, debuglevel, "gfapi-fd: file %s skipped due to current fileset settings\n", p_ctx->next_filename); @@ -994,7 +997,7 @@ static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) break; } - switch (bfuncs->checkChanges(ctx, sp)) { + switch (bareos_core_functions->checkChanges(ctx, sp)) { case bRC_Seen: Dmsg(ctx, debuglevel, "gfapi-fd: skipping %s checkChanges returns bRC_Seen\n", @@ -1587,7 +1590,7 @@ static bRC setup_backup(bpContext* ctx, void* value) /* * Get the setting for accurate for this Job. */ - bfuncs->getBareosValue(ctx, bVarAccurate, (void*)&accurate); + bareos_core_functions->getBareosValue(ctx, bVarAccurate, (void*)&accurate); if (accurate) { p_ctx->is_accurate = true; } p_ctx->crawl_fs = false; @@ -1609,7 +1612,7 @@ static bRC setup_backup(bpContext* ctx, void* value) switch (p_ctx->backup_level) { case L_INCREMENTAL: case L_DIFFERENTIAL: - if (bfuncs->SetSeenBitmap(ctx, true, NULL) != bRC_OK) { + if (bareos_core_functions->SetSeenBitmap(ctx, true, NULL) != bRC_OK) { Jmsg(ctx, M_FATAL, "Failed to enable all entries in Seen bitmap, not an accurate " "backup ?\n"); diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index f3f3871dc3a..7a214091393 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -121,7 +121,7 @@ static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp); /* Pointers to Bareos functions */ -static BareosCoreFunctions* bfuncs = NULL; +static BareosCoreFunctions* bareos_core_functions = NULL; static Core_PluginApiDefinition* binfo = NULL; /* static genpInfo pluginInfo = {sizeof(pluginInfo), @@ -157,7 +157,8 @@ struct plugin_private_context { interpreter; /* Python interpreter for this instance of the plugin */ PyObject* pModule; /* Python Module entry point */ PyObject* pyModuleFunctionsDict; /* Python Dictionary */ - BareosCoreFunctions* bfuncs; /* pointer to bfuncs */ + BareosCoreFunctions* + bareos_core_functions; /* pointer to bareos_core_functions */ }; /** @@ -218,11 +219,12 @@ static void PyErrorHandler() * Plugin called here when it is first loaded */ /* bRC loadPlugin(Core_PluginApiDefinition* lbinfo, */ -/* BareosCoreFunctions* lbfuncs, */ +/* BareosCoreFunctions* lbareos_core_functions, */ /* genpInfo** pinfo, */ /* pFuncs** pfuncs) */ /* { */ -/* bfuncs = lbfuncs; /1* Set Bareos funct pointers *1/ */ +/* bareos_core_functions = lbareos_core_functions; /1* Set Bareos funct + * pointers *1/ */ /* binfo = lbinfo; */ /* *pinfo = &pluginInfo; /1* Return pointer to our info *1/ */ @@ -250,7 +252,7 @@ static void PyErrorHandler() /* // Extract capsules pointer from bareosfd module */ /* void (*loadplugin_from_bareosfd_module)( */ /* filedaemon::Core_PluginApiDefinition * lbinfo, - * filedaemon::BareosCoreFunctions * lbfuncs, */ + * filedaemon::BareosCoreFunctions * lbareos_core_functions, */ /* genpInfo * *pinfo, filedaemon::pFuncs * *pfuncs) = */ /* (void (*)(filedaemon::Core_PluginApiDefinition*, * filedaemon::BareosCoreFunctions*, genpInfo**, */ @@ -266,9 +268,9 @@ static void PyErrorHandler() /* } */ /* // Extract capsules bareosfd.BareosCoreFunctions */ -/* void* bfuncs_from_bareosfd_module = +/* void* bareos_core_functions_from_bareosfd_module = * PyCapsule_Import("bareosfd.BareosCoreFunctions", 0); */ -/* if (!bfuncs_from_bareosfd_module) { */ +/* if (!bareos_core_functions_from_bareosfd_module) { */ /* printf("importing bareosfd.BareosCoreFunctions failed \n"); */ /* } */ @@ -278,21 +280,23 @@ static void PyErrorHandler() /* *(void**)ctx_from_bareosfd_module = &bareos_plugin_context; */ -/* *(void**)bfuncs_from_bareosfd_module = &bfuncs; */ +/* *(void**)bareos_core_functions_from_bareosfd_module = + * &bareos_core_functions; */ /* /1* call loadPlugin in plugin *1/ */ /* filedaemon::Core_PluginApiDefinition myInfo; */ /* genpInfo pinfo; */ /* filedaemon::pFuncs pfuncs; */ -/* loadplugin_from_bareosfd_module(&myInfo, bfuncs, (genpInfo**)&pinfo, */ +/* loadplugin_from_bareosfd_module(&myInfo, bareos_core_functions, + * (genpInfo**)&pinfo, */ /* (filedaemon::pFuncs**)&pfuncs); */ /* printf("ctx_from_bareosfd_module contains %p\n", */ /* *(void**)ctx_from_bareosfd_module); */ -/* printf("bfuncs_from_bareosfd_module contains %p\n", */ -/* *(void**)bfuncs_from_bareosfd_module); */ +/* printf("bareos_core_functions_from_bareosfd_module contains %p\n", */ +/* *(void**)bareos_core_functions_from_bareosfd_module); */ /* PyEval_InitThreads(); */ @@ -1640,8 +1644,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarDistName: { char* value = NULL; - if (bfuncs->getBareosValue(bareos_plugin_ctx, (bVariable)var, &value) == - bRC_OK) { + if (bareos_core_functions->getBareosValue( + bareos_plugin_ctx, (bVariable)var, &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } } break; @@ -1655,8 +1659,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarPrefixLinks: { int value = 0; - if (bfuncs->getBareosValue(bareos_plugin_ctx, (bVariable)var, &value) == - bRC_OK) { + if (bareos_core_functions->getBareosValue( + bareos_plugin_ctx, (bVariable)var, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } break; @@ -1668,8 +1672,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarRegexWhere: { char* value = NULL; - if (bfuncs->getBareosValue(bareos_plugin_ctx, (bVariable)var, &value) == - bRC_OK) { + if (bareos_core_functions->getBareosValue( + bareos_plugin_ctx, (bVariable)var, &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } } break; @@ -1712,8 +1716,8 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) value = PyInt_AsLong(pyValue); if (value) { - retval = - bfuncs->setBareosValue(bareos_plugin_ctx, (bVariable)var, &value); + retval = bareos_core_functions->setBareosValue(bareos_plugin_ctx, + (bVariable)var, &value); } break; } @@ -1722,8 +1726,8 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) value = PyString_AsString(pyValue); if (value) { - retval = - bfuncs->setBareosValue(bareos_plugin_ctx, (bVariable)var, value); + retval = bareos_core_functions->setBareosValue(bareos_plugin_ctx, + (bVariable)var, value); } break; } @@ -1810,7 +1814,8 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) if (event >= bEventJobStart && event <= FD_NR_EVENTS) { Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: PyBareosRegisterEvents registering event %d\n", event); - retval = bfuncs->registerBareosEvents(bareos_plugin_ctx, 1, event); + retval = bareos_core_functions->registerBareosEvents(bareos_plugin_ctx, 1, + event); if (retval != bRC_OK) { break; } } @@ -1850,7 +1855,8 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) if (event >= bEventJobStart && event <= FD_NR_EVENTS) { Dmsg(bareos_plugin_ctx, debuglevel, "PyBareosUnRegisterEvents: unregistering event %d\n", event); - retval = bfuncs->unregisterBareosEvents(bareos_plugin_ctx, 1, event); + retval = bareos_core_functions->unregisterBareosEvents(bareos_plugin_ctx, + 1, event); } } @@ -1874,7 +1880,8 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (bfuncs->getInstanceCount(bareos_plugin_ctx, &value) == bRC_OK) { + if (bareos_core_functions->getInstanceCount(bareos_plugin_ctx, &value) == + bRC_OK) { pRetVal = PyInt_FromLong(value); } @@ -1899,7 +1906,9 @@ static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "|z:BareosAddExclude", &file)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (file) { retval = bfuncs->AddExclude(bareos_plugin_ctx, file); } + if (file) { + retval = bareos_core_functions->AddExclude(bareos_plugin_ctx, file); + } bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -1918,7 +1927,9 @@ static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "|z:BareosAddInclude", &file)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (file) { retval = bfuncs->AddInclude(bareos_plugin_ctx, file); } + if (file) { + retval = bareos_core_functions->AddInclude(bareos_plugin_ctx, file); + } bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -1937,7 +1948,9 @@ static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "|z:BareosAddOptions", &opts)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (opts) { retval = bfuncs->AddOptions(bareos_plugin_ctx, opts); } + if (opts) { + retval = bareos_core_functions->AddOptions(bareos_plugin_ctx, opts); + } bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -1958,7 +1971,9 @@ static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (item) { retval = bfuncs->AddRegex(bareos_plugin_ctx, item, type); } + if (item) { + retval = bareos_core_functions->AddRegex(bareos_plugin_ctx, item, type); + } bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -1980,7 +1995,9 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (item) { retval = bfuncs->AddWild(bareos_plugin_ctx, item, type); } + if (item) { + retval = bareos_core_functions->AddWild(bareos_plugin_ctx, item, type); + } bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -1998,7 +2015,7 @@ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, ":BareosNewOptions")) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - retval = bfuncs->NewOptions(bareos_plugin_ctx); + retval = bareos_core_functions->NewOptions(bareos_plugin_ctx); bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2016,7 +2033,7 @@ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, ":BareosNewInclude")) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - retval = bfuncs->NewInclude(bareos_plugin_ctx); + retval = bareos_core_functions->NewInclude(bareos_plugin_ctx); bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2034,7 +2051,7 @@ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, ":BareosNewPreInclude")) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - retval = bfuncs->NewPreInclude(bareos_plugin_ctx); + retval = bareos_core_functions->NewPreInclude(bareos_plugin_ctx); bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2082,7 +2099,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) } sp.save_time = pSavePkt->save_time; - retval = bfuncs->checkChanges(bareos_plugin_ctx, &sp); + retval = bareos_core_functions->checkChanges(bareos_plugin_ctx, &sp); /* * Copy back the two fields that are changed by checkChanges(). @@ -2131,7 +2148,7 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) goto bail_out; } - retval = bfuncs->AcceptFile(bareos_plugin_ctx, &sp); + retval = bareos_core_functions->AcceptFile(bareos_plugin_ctx, &sp); bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2155,7 +2172,7 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() all = PyObject_IsTrue(pyBool); - retval = bfuncs->SetSeenBitmap(bareos_plugin_ctx, all, fname); + retval = bareos_core_functions->SetSeenBitmap(bareos_plugin_ctx, all, fname); bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2180,7 +2197,8 @@ static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() all = PyObject_IsTrue(pyBool); - retval = bfuncs->ClearSeenBitmap(bareos_plugin_ctx, all, fname); + retval = + bareos_core_functions->ClearSeenBitmap(bareos_plugin_ctx, all, fname); bail_out: return ConvertbRCRetvalToPythonRetval(retval); diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index ddc49c62715..87a5638eea4 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -120,7 +120,7 @@ static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp); /* Pointers to Bareos functions */ -static BareosCoreFunctions* bfuncs = NULL; +static BareosCoreFunctions* bareos_core_functions = NULL; static Core_PluginApiDefinition* binfo = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, @@ -155,7 +155,8 @@ struct plugin_private_context { interpreter; /* Python interpreter for this instance of the plugin */ PyObject* pModule; /* Python Module entry point */ PyObject* pyModuleFunctionsDict; /* Python Dictionary */ - BareosCoreFunctions* bfuncs; /* pointer to bfuncs */ + BareosCoreFunctions* + bareos_core_functions; /* pointer to bareos_core_functions */ }; /** @@ -216,11 +217,12 @@ static void PyErrorHandler() * Plugin called here when it is first loaded */ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, - BareosCoreFunctions* lbfuncs, + BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs) { - bfuncs = lbfuncs; /* Set Bareos funct pointers */ + bareos_core_functions = + lbareos_core_functions; /* Set Bareos funct pointers */ binfo = lbinfo; *pinfo = &pluginInfo; /* Return pointer to our info */ @@ -248,8 +250,8 @@ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, // Extract capsules pointer from bareosfd module void (*loadplugin_from_bareosfd_module)( filedaemon::Core_PluginApiDefinition * lbinfo, - filedaemon::BareosCoreFunctions * lbfuncs, genpInfo * *pinfo, - filedaemon::pFuncs * *pfuncs) = + filedaemon::BareosCoreFunctions * lbareos_core_functions, + genpInfo * *pinfo, filedaemon::pFuncs * *pfuncs) = (void (*)(filedaemon::Core_PluginApiDefinition*, filedaemon::BareosCoreFunctions*, genpInfo**, filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", @@ -262,9 +264,9 @@ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, } // Extract capsules bareosfd.BareosCoreFunctions - void* bfuncs_from_bareosfd_module = + void* bareos_core_functions_from_bareosfd_module = PyCapsule_Import("bareosfd.BareosCoreFunctions", 0); - if (!bfuncs_from_bareosfd_module) { + if (!bareos_core_functions_from_bareosfd_module) { printf("importing bareosfd.BareosCoreFunctions failed \n"); } @@ -274,21 +276,23 @@ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, *(void**)ctx_from_bareosfd_module = &bareos_plugin_context; - *(void**)bfuncs_from_bareosfd_module = &bfuncs; + *(void**)bareos_core_functions_from_bareosfd_module = + &bareos_core_functions; /* call loadPlugin in plugin */ filedaemon::Core_PluginApiDefinition myInfo; genpInfo pinfo; filedaemon::pFuncs pfuncs; - loadplugin_from_bareosfd_module(&myInfo, bfuncs, (genpInfo**)&pinfo, + loadplugin_from_bareosfd_module(&myInfo, bareos_core_functions, + (genpInfo**)&pinfo, (filedaemon::pFuncs**)&pfuncs); printf("ctx_from_bareosfd_module contains %p\n", *(void**)ctx_from_bareosfd_module); - printf("bfuncs_from_bareosfd_module contains %p\n", - *(void**)bfuncs_from_bareosfd_module); + printf("bareos_core_functions_from_bareosfd_module contains %p\n", + *(void**)bareos_core_functions_from_bareosfd_module); PyEval_InitThreads(); @@ -333,7 +337,7 @@ static bRC newPlugin(bpContext* bareos_plugin_ctx) bareos_plugin_ctx->pContext = (void*)plugin_priv_ctx; /* set our context pointer */ - plugin_priv_ctx->bfuncs = bfuncs; + plugin_priv_ctx->bareos_core_functions = bareos_core_functions; /* For each plugin instance we instantiate a new Python interpreter. */ PyEval_AcquireThread(mainThreadState); @@ -342,7 +346,7 @@ static bRC newPlugin(bpContext* bareos_plugin_ctx) /* Always register some events the python plugin itself can register any other events it is interested in. */ - bfuncs->registerBareosEvents( + bareos_core_functions->registerBareosEvents( bareos_plugin_ctx, 9, bEventLevel, bEventSince, bEventNewPluginOptions, bEventPluginCommand, bEventJobStart, bEventRestoreCommand, bEventEstimateCommand, bEventBackupCommand, bEventRestoreObject); @@ -587,7 +591,7 @@ static bRC startBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) sp->save_time = plugin_priv_ctx->since; } - switch (bfuncs->checkChanges(bareos_plugin_ctx, sp)) { + switch (bareos_core_functions->checkChanges(bareos_plugin_ctx, sp)) { case bRC_Seen: switch (sp->type) { case FT_DIRBEGIN: @@ -2350,8 +2354,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarDistName: { char* value = NULL; - if (bfuncs->getBareosValue(bareos_plugin_ctx, (bVariable)var, &value) == - bRC_OK) { + if (bareos_core_functions->getBareosValue( + bareos_plugin_ctx, (bVariable)var, &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } } break; @@ -2365,8 +2369,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarPrefixLinks: { int value = 0; - if (bfuncs->getBareosValue(bareos_plugin_ctx, (bVariable)var, &value) == - bRC_OK) { + if (bareos_core_functions->getBareosValue( + bareos_plugin_ctx, (bVariable)var, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } break; @@ -2378,8 +2382,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarRegexWhere: { char* value = NULL; - if (bfuncs->getBareosValue(bareos_plugin_ctx, (bVariable)var, &value) == - bRC_OK) { + if (bareos_core_functions->getBareosValue( + bareos_plugin_ctx, (bVariable)var, &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } } break; @@ -2424,8 +2428,8 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) value = PyInt_AsLong(pyValue); if (value) { - retval = - bfuncs->setBareosValue(bareos_plugin_ctx, (bVariable)var, &value); + retval = bareos_core_functions->setBareosValue(bareos_plugin_ctx, + (bVariable)var, &value); } break; } @@ -2434,8 +2438,8 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) value = PyString_AsString(pyValue); if (value) { - retval = - bfuncs->setBareosValue(bareos_plugin_ctx, (bVariable)var, value); + retval = bareos_core_functions->setBareosValue(bareos_plugin_ctx, + (bVariable)var, value); } break; } @@ -2522,7 +2526,8 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) if (event >= bEventJobStart && event <= FD_NR_EVENTS) { Dmsg(bareos_plugin_ctx, debuglevel, "python-fd: PyBareosRegisterEvents registering event %d\n", event); - retval = bfuncs->registerBareosEvents(bareos_plugin_ctx, 1, event); + retval = bareos_core_functions->registerBareosEvents(bareos_plugin_ctx, 1, + event); if (retval != bRC_OK) { break; } } @@ -2562,7 +2567,8 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) if (event >= bEventJobStart && event <= FD_NR_EVENTS) { Dmsg(bareos_plugin_ctx, debuglevel, "PyBareosUnRegisterEvents: unregistering event %d\n", event); - retval = bfuncs->unregisterBareosEvents(bareos_plugin_ctx, 1, event); + retval = bareos_core_functions->unregisterBareosEvents(bareos_plugin_ctx, + 1, event); } } @@ -2586,7 +2592,8 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (bfuncs->getInstanceCount(bareos_plugin_ctx, &value) == bRC_OK) { + if (bareos_core_functions->getInstanceCount(bareos_plugin_ctx, &value) == + bRC_OK) { pRetVal = PyInt_FromLong(value); } @@ -2611,7 +2618,9 @@ static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "|z:BareosAddExclude", &file)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (file) { retval = bfuncs->AddExclude(bareos_plugin_ctx, file); } + if (file) { + retval = bareos_core_functions->AddExclude(bareos_plugin_ctx, file); + } bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2630,7 +2639,9 @@ static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "|z:BareosAddInclude", &file)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (file) { retval = bfuncs->AddInclude(bareos_plugin_ctx, file); } + if (file) { + retval = bareos_core_functions->AddInclude(bareos_plugin_ctx, file); + } bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2649,7 +2660,9 @@ static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, "|z:BareosAddOptions", &opts)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (opts) { retval = bfuncs->AddOptions(bareos_plugin_ctx, opts); } + if (opts) { + retval = bareos_core_functions->AddOptions(bareos_plugin_ctx, opts); + } bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2670,7 +2683,9 @@ static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (item) { retval = bfuncs->AddRegex(bareos_plugin_ctx, item, type); } + if (item) { + retval = bareos_core_functions->AddRegex(bareos_plugin_ctx, item, type); + } bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2692,7 +2707,9 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (item) { retval = bfuncs->AddWild(bareos_plugin_ctx, item, type); } + if (item) { + retval = bareos_core_functions->AddWild(bareos_plugin_ctx, item, type); + } bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2710,7 +2727,7 @@ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, ":BareosNewOptions")) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - retval = bfuncs->NewOptions(bareos_plugin_ctx); + retval = bareos_core_functions->NewOptions(bareos_plugin_ctx); bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2728,7 +2745,7 @@ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, ":BareosNewInclude")) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - retval = bfuncs->NewInclude(bareos_plugin_ctx); + retval = bareos_core_functions->NewInclude(bareos_plugin_ctx); bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2746,7 +2763,7 @@ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) if (!PyArg_ParseTuple(args, ":BareosNewPreInclude")) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - retval = bfuncs->NewPreInclude(bareos_plugin_ctx); + retval = bareos_core_functions->NewPreInclude(bareos_plugin_ctx); bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2794,7 +2811,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) } sp.save_time = pSavePkt->save_time; - retval = bfuncs->checkChanges(bareos_plugin_ctx, &sp); + retval = bareos_core_functions->checkChanges(bareos_plugin_ctx, &sp); /* * Copy back the two fields that are changed by checkChanges(). @@ -2843,7 +2860,7 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) goto bail_out; } - retval = bfuncs->AcceptFile(bareos_plugin_ctx, &sp); + retval = bareos_core_functions->AcceptFile(bareos_plugin_ctx, &sp); bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2867,7 +2884,7 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() all = PyObject_IsTrue(pyBool); - retval = bfuncs->SetSeenBitmap(bareos_plugin_ctx, all, fname); + retval = bareos_core_functions->SetSeenBitmap(bareos_plugin_ctx, all, fname); bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -2892,7 +2909,8 @@ static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() all = PyObject_IsTrue(pyBool); - retval = bfuncs->ClearSeenBitmap(bareos_plugin_ctx, all, fname); + retval = + bareos_core_functions->ClearSeenBitmap(bareos_plugin_ctx, all, fname); bail_out: return ConvertbRCRetvalToPythonRetval(retval); diff --git a/core/src/plugins/filed/python/python-fd.h b/core/src/plugins/filed/python/python-fd.h index 3b115e87b9d..7ffa65039ca 100644 --- a/core/src/plugins/filed/python/python-fd.h +++ b/core/src/plugins/filed/python/python-fd.h @@ -756,14 +756,14 @@ using namespace filedaemon; /* variables storing bareos pointers */ static void* bareos_plugin_context = NULL; -static void* bfuncs = NULL; +static void* bareos_core_functions = NULL; #ifdef __cplusplus extern "C" { #endif /* Forward declaration of loadPlugin() as it is stored in Capsule */ bRC loadPlugin(::Core_PluginApiDefinition* lbinfo, - BareosCoreFunctions* lbfuncs, + BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs); #ifdef __cplusplus @@ -795,8 +795,9 @@ MOD_INIT(bareosfd) } /* add bpFuncs Capsule */ - PyObject* PyModulePluginFuncs = PyCapsule_New( - (void*)&bfuncs, PYTHON_MODULE_NAME_QUOTED ".BareosCoreFunctions", NULL); + PyObject* PyModulePluginFuncs = + PyCapsule_New((void*)&bareos_core_functions, + PYTHON_MODULE_NAME_QUOTED ".BareosCoreFunctions", NULL); if (!PyModulePluginFuncs) { printf(PYTHON_MODULE_NAME_QUOTED ":BareosCoreFunctions PyCapsule_New failed\n"); @@ -805,7 +806,7 @@ MOD_INIT(bareosfd) if (PyModulePluginFuncs) { PyModule_AddObject(m, "BareosCoreFunctions", PyModulePluginFuncs); printf(PYTHON_MODULE_NAME_QUOTED ": added BareosCoreFunctions@%p\n", - &bfuncs); + &bareos_core_functions); } else { printf(PYTHON_MODULE_NAME_QUOTED ":BareosCoreFunctions PyModule_AddObject failed\n"); diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index 743e7748175..90f4837851b 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -147,7 +147,7 @@ bRC bareosClearSeenBitmap(bpContext* ctx, bool all, char* fname) /* Bareos entry points */ -static filedaemon::BareosCoreFunctions bfuncs = { +static filedaemon::BareosCoreFunctions bareos_core_functions = { sizeof(filedaemon::BareosCoreFunctions), FD_PLUGIN_INTERFACE_VERSION, bareosRegisterEvents, @@ -187,7 +187,8 @@ int main(int argc, char* argv[]) } if (PyErr_Occurred()) { PyErrorHandler(); } - /* printf("bfuncs is at %p\n", &bfuncs); */ + /* printf("bareos_core_functions is at %p\n", + * &bareos_core_functions); */ /* printf("bareos_plugin_context %p\n", &bareos_plugin_context); */ // Extract capsules pointer from bareosfd module @@ -197,17 +198,17 @@ int main(int argc, char* argv[]) } // Extract capsules pointer from bareosfd module - void* bfuncs_from_bareosfd_module = + void* bareos_core_functions_from_bareosfd_module = PyCapsule_Import("bareosfd.BareosCoreFunctions", 0); - if (!bfuncs_from_bareosfd_module) { + if (!bareos_core_functions_from_bareosfd_module) { printf("importing bareosfd.BareosCoreFunctions failed \n"); } // Extract capsules pointer from bareosfd module void (*loadplugin_from_bareosfd_module)( filedaemon::Core_PluginApiDefinition * lbinfo, - filedaemon::BareosCoreFunctions * lbfuncs, genpInfo * *pinfo, - filedaemon::pFuncs * *pfuncs) = + filedaemon::BareosCoreFunctions * lbareos_core_functions, + genpInfo * *pinfo, filedaemon::pFuncs * *pfuncs) = (void (*)(filedaemon::Core_PluginApiDefinition*, filedaemon::BareosCoreFunctions*, genpInfo**, filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", @@ -219,32 +220,33 @@ int main(int argc, char* argv[]) /* printf("ctx_from_bareosfd_module is at %p\n", * ctx_from_bareosfd_module); */ - /* printf("bfuncs_from_bareosfd_module is at %p\n", */ - /* bfuncs_from_bareosfd_module); */ + /* printf("bareos_core_functions_from_bareosfd_module is at %p\n", */ + /* bareos_core_functions_from_bareosfd_module); */ /* printf("loadplugin_from_bareosfd_module is @ %p\n", */ /* loadplugin_from_bareosfd_module); */ /* printf("ctx_from_bareosfd_module contains %p\n", */ /* *(void**)ctx_from_bareosfd_module); */ - /* printf("bfuncs_from_bareosfd_module contains %p\n", */ - /* *(void**)bfuncs_from_bareosfd_module); */ + /* printf("bareos_core_functions_from_bareosfd_module contains %p\n", */ + /* *(void**)bareos_core_functions_from_bareosfd_module); */ *(void**)ctx_from_bareosfd_module = &bareos_plugin_context; - *(void**)bfuncs_from_bareosfd_module = &bfuncs; + *(void**)bareos_core_functions_from_bareosfd_module = &bareos_core_functions; /* call loadPlugin in plugin */ filedaemon::Core_PluginApiDefinition myInfo; genpInfo pinfo; filedaemon::pFuncs pfuncs; - loadplugin_from_bareosfd_module(&myInfo, &bfuncs, (genpInfo**)&pinfo, + loadplugin_from_bareosfd_module(&myInfo, &bareos_core_functions, + (genpInfo**)&pinfo, (filedaemon::pFuncs**)&pfuncs); printf("ctx_from_bareosfd_module contains %p\n", *(void**)ctx_from_bareosfd_module); - printf("bfuncs_from_bareosfd_module contains %p\n", - *(void**)bfuncs_from_bareosfd_module); + printf("bareos_core_functions_from_bareosfd_module contains %p\n", + *(void**)bareos_core_functions_from_bareosfd_module); PyObject* pModule = PyImport_ImportModule("bareosfd-module-test"); diff --git a/core/src/plugins/filed/rados/rados-fd.cc b/core/src/plugins/filed/rados/rados-fd.cc index cf53d98dab6..1efad184723 100644 --- a/core/src/plugins/filed/rados/rados-fd.cc +++ b/core/src/plugins/filed/rados/rados-fd.cc @@ -84,7 +84,7 @@ static bRC end_restore_job(bpContext* ctx, void* value); /** * Pointers to Bareos functions */ -static BareosCoreFunctions* bfuncs = NULL; +static BareosCoreFunctions* bareos_core_functions = NULL; static Core_PluginApiDefinition* binfo = NULL; /** @@ -179,11 +179,12 @@ extern "C" { * External entry point called by Bareos to "load" the plugin */ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, - BareosCoreFunctions* lbfuncs, + BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs) { - bfuncs = lbfuncs; /* set Bareos funct pointers */ + bareos_core_functions = + lbareos_core_functions; /* set Bareos funct pointers */ binfo = lbinfo; *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ @@ -217,15 +218,15 @@ static bRC newPlugin(bpContext* ctx) ctx->pContext = (void*)p_ctx; /* set our context pointer */ p_ctx->next_filename = GetPoolMemory(PM_FNAME); - bfuncs->getBareosValue(ctx, bVarJobId, (void*)&p_ctx->JobId); + bareos_core_functions->getBareosValue(ctx, bVarJobId, (void*)&p_ctx->JobId); /* * Only register the events we are really interested in. */ - bfuncs->registerBareosEvents(ctx, 7, bEventLevel, bEventSince, - bEventRestoreCommand, bEventBackupCommand, - bEventPluginCommand, bEventEndRestoreJob, - bEventNewPluginOptions); + bareos_core_functions->registerBareosEvents( + ctx, 7, bEventLevel, bEventSince, bEventRestoreCommand, + bEventBackupCommand, bEventPluginCommand, bEventEndRestoreJob, + bEventNewPluginOptions); return bRC_OK; } @@ -407,7 +408,7 @@ static bRC get_next_object_to_backup(bpContext* ctx) sp.fname = p_ctx->next_filename; sp.statp.st_mode = 0700 | S_IFREG; - if (bfuncs->AcceptFile(ctx, &sp) == bRC_Skip) { continue; } + if (bareos_core_functions->AcceptFile(ctx, &sp) == bRC_Skip) { continue; } status = rados_stat(p_ctx->ioctx, p_ctx->object_name, &p_ctx->object_size, &p_ctx->object_mtime); @@ -454,7 +455,7 @@ static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) switch (p_ctx->backup_level) { case L_INCREMENTAL: case L_DIFFERENTIAL: - switch (bfuncs->checkChanges(ctx, sp)) { + switch (bareos_core_functions->checkChanges(ctx, sp)) { case bRC_Seen: sp->type = FT_NOCHG; break; diff --git a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc index a9749fd32bb..9ac36e71b1f 100644 --- a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc +++ b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc @@ -54,7 +54,7 @@ static bRC createFile(bpContext* ctx, struct restore_pkt* rp); static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp); /* Pointers to Bareos functions */ -static BareosCoreFunctions* bfuncs = NULL; +static BareosCoreFunctions* bareos_core_functions = NULL; static Core_PluginApiDefinition* binfo = NULL; /* Plugin Information block */ @@ -117,11 +117,12 @@ extern "C" { * External entry point called by Bareos to "load" the plugin */ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, - BareosCoreFunctions* lbfuncs, + BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs) { - bfuncs = lbfuncs; /* set Bareos funct pointers */ + bareos_core_functions = + lbareos_core_functions; /* set Bareos funct pointers */ binfo = lbinfo; *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ @@ -161,8 +162,8 @@ static bRC newPlugin(bpContext* ctx) if (!self) { return bRC_Error; } ctx->pContext = (void*)self; /* set our context pointer */ - bfuncs->registerBareosEvents(ctx, 3, bEventLevel, bEventRestoreCommand, - bEventBackupCommand); + bareos_core_functions->registerBareosEvents( + ctx, 3, bEventLevel, bEventRestoreCommand, bEventBackupCommand); return bRC_OK; } @@ -224,7 +225,8 @@ static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) Dmsg(ctx, debuglevel, "delta-test-fd: pluginEvent cmd=%s\n", (char*)value); if (self->level == 'I' || self->level == 'D') { - bfuncs->getBareosValue(ctx, bVarAccurate, (void*)&accurate); + bareos_core_functions->getBareosValue(ctx, bVarAccurate, + (void*)&accurate); if (!accurate) { /* can be changed to FATAL */ Jmsg(ctx, M_FATAL, "Accurate mode should be turned on when using the " @@ -263,7 +265,7 @@ static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) sp->statp.st_blksize = 4096; sp->statp.st_blocks = 1; if (self->level == 'I' || self->level == 'D') { - bRC state = bfuncs->checkChanges(ctx, sp); + bRC state = bareos_core_functions->checkChanges(ctx, sp); /* Should always be bRC_OK */ sp->type = (state == bRC_Seen) ? FT_NOCHG : FT_REG; SetBit(FO_DELTA, sp->flags); diff --git a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc index 7450527d0ae..35f64c5ab22 100644 --- a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc +++ b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc @@ -63,7 +63,7 @@ static bRC getXattr(bpContext* ctx, xattr_pkt* xp); static bRC setXattr(bpContext* ctx, xattr_pkt* xp); /* Pointers to Bareos functions */ -static BareosCoreFunctions* bfuncs = NULL; +static BareosCoreFunctions* bareos_core_functions = NULL; static Core_PluginApiDefinition* binfo = NULL; /* Plugin Information block */ @@ -123,11 +123,12 @@ extern "C" { * External entry point called by Bareos to "load" the plugin */ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, - BareosCoreFunctions* lbfuncs, + BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs) { - bfuncs = lbfuncs; /* set Bareos funct pointers */ + bareos_core_functions = + lbareos_core_functions; /* set Bareos funct pointers */ binfo = lbinfo; *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ @@ -160,9 +161,9 @@ static bRC newPlugin(bpContext* ctx) p_ctx = (plugin_ctx*)memset(p_ctx, 0, sizeof(struct plugin_ctx)); ctx->pContext = (void*)p_ctx; /* set our context pointer */ - bfuncs->registerBareosEvents(ctx, 5, bEventJobStart, bEventEndFileSet, - bEventRestoreObject, bEventEstimateCommand, - bEventBackupCommand); + bareos_core_functions->registerBareosEvents( + ctx, 5, bEventJobStart, bEventEndFileSet, bEventRestoreObject, + bEventEstimateCommand, bEventBackupCommand); return bRC_OK; } @@ -216,11 +217,12 @@ static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) /* * End of Dir FileSet commands, now we can add excludes */ - bfuncs->NewOptions(ctx); - bfuncs->AddWild(ctx, "*.c", ' '); - bfuncs->AddWild(ctx, "*.cpp", ' '); - bfuncs->AddOptions(ctx, "ei"); /* exclude, ignore case */ - bfuncs->AddExclude(ctx, "/home/user/bareos/regress/README"); + bareos_core_functions->NewOptions(ctx); + bareos_core_functions->AddWild(ctx, "*.c", ' '); + bareos_core_functions->AddWild(ctx, "*.cpp", ' '); + bareos_core_functions->AddOptions(ctx, "ei"); /* exclude, ignore case */ + bareos_core_functions->AddExclude(ctx, + "/home/user/bareos/regress/README"); break; case bEventRestoreObject: { FILE* fp; @@ -240,7 +242,7 @@ static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) rop->object); q = GetPoolMemory(PM_FNAME); - bfuncs->getBareosValue(ctx, bVarWorkingDir, &working); + bareos_core_functions->getBareosValue(ctx, bVarWorkingDir, &working); Mmsg(q, "%s/restore.%d", working, _nb++); if ((fp = fopen(q, "w")) != NULL) { fwrite(rop->object, rop->object_len, 1, fp); @@ -325,15 +327,15 @@ static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) if (p_ctx->nb_obj == 0) { sp->fname = (char*)"takeme.h"; Dmsg(ctx, debuglevel, "AcceptFile=%s = %d\n", sp->fname, - bfuncs->AcceptFile(ctx, sp)); + bareos_core_functions->AcceptFile(ctx, sp)); sp->fname = (char*)"/path/to/excludeme.o"; Dmsg(ctx, debuglevel, "AcceptFile=%s = %d\n", sp->fname, - bfuncs->AcceptFile(ctx, sp)); + bareos_core_functions->AcceptFile(ctx, sp)); sp->fname = (char*)"/path/to/excludeme.c"; Dmsg(ctx, debuglevel, "AcceptFile=%s = %d\n", sp->fname, - bfuncs->AcceptFile(ctx, sp)); + bareos_core_functions->AcceptFile(ctx, sp)); } if (p_ctx->nb_obj == 0) { @@ -540,7 +542,7 @@ static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) char* working; FILE* fp; - bfuncs->getBareosValue(ctx, bVarWorkingDir, &working); + bareos_core_functions->getBareosValue(ctx, bVarWorkingDir, &working); Mmsg(q, "%s/torestore.%d", working, _nb++); if ((fp = fopen(q, "w")) != NULL) { fwrite(sp->object, sp->object_len, 1, fp); diff --git a/core/src/plugins/python_plugins_common.h b/core/src/plugins/python_plugins_common.h index efff02c04b2..5775bc51d1d 100644 --- a/core/src/plugins/python_plugins_common.h +++ b/core/src/plugins/python_plugins_common.h @@ -56,10 +56,11 @@ return NULL; \ } -#define RETURN_RUNTIME_ERROR_IF_BFUNC_UNSET() \ - if (!bfuncs) { \ - PyErr_SetString(PyExc_RuntimeError, AT ": bfuncs is unset"); \ - return NULL; \ +#define RETURN_RUNTIME_ERROR_IF_BFUNC_UNSET() \ + if (!bareos_core_functions) { \ + PyErr_SetString(PyExc_RuntimeError, \ + AT ": bareos_core_functions is unset"); \ + return NULL; \ } #define RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() \ diff --git a/core/src/plugins/stored/autoxflate/autoxflate-sd.cc b/core/src/plugins/stored/autoxflate/autoxflate-sd.cc index afc42fd0817..b03e5b1be3f 100644 --- a/core/src/plugins/stored/autoxflate/autoxflate-sd.cc +++ b/core/src/plugins/stored/autoxflate/autoxflate-sd.cc @@ -45,10 +45,12 @@ using namespace storagedaemon; #define PLUGIN_DESCRIPTION "Auto Xflation Storage Daemon Plugin" #define PLUGIN_USAGE "(No usage yet)" -#define Dmsg(context, level, ...) \ - bfuncs->DebugMessage(context, __FILE__, __LINE__, level, __VA_ARGS__) -#define Jmsg(context, type, ...) \ - bfuncs->JobMessage(context, __FILE__, __LINE__, type, 0, __VA_ARGS__) +#define Dmsg(context, level, ...) \ + bareos_core_functions->DebugMessage(context, __FILE__, __LINE__, level, \ + __VA_ARGS__) +#define Jmsg(context, type, ...) \ + bareos_core_functions->JobMessage(context, __FILE__, __LINE__, type, 0, \ + __VA_ARGS__) #define SETTING_YES (char*)"yes" #define SETTING_NO (char*)"no" @@ -87,7 +89,7 @@ static bool sd_enabled_compatible = false; /** * Pointers to Bareos functions */ -static bsdFuncs* bfuncs = NULL; +static bsdFuncs* bareos_core_functions = NULL; static bsdInfo* binfo = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, @@ -133,11 +135,12 @@ extern "C" { * External entry point called by Bareos to "load the plugin */ bRC loadPlugin(bsdInfo* lbinfo, - bsdFuncs* lbfuncs, + bsdFuncs* lbareos_core_functions, genpInfo** pinfo, psdFuncs** pfuncs) { - bfuncs = lbfuncs; /* set Bareos funct pointers */ + bareos_core_functions = + lbareos_core_functions; /* set Bareos funct pointers */ binfo = lbinfo; *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ @@ -145,7 +148,8 @@ bRC loadPlugin(bsdInfo* lbinfo, /* * Get the current setting of the compatible flag. */ - bfuncs->getBareosValue(NULL, bsdVarCompatible, (void*)&sd_enabled_compatible); + bareos_core_functions->getBareosValue(NULL, bsdVarCompatible, + (void*)&sd_enabled_compatible); return bRC_OK; } @@ -171,7 +175,7 @@ static bRC newPlugin(bpContext* ctx) int JobId = 0; struct plugin_ctx* p_ctx; - bfuncs->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); + bareos_core_functions->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); Dmsg(ctx, debuglevel, "autoxflate-sd: newPlugin JobId=%d\n", JobId); p_ctx = (struct plugin_ctx*)malloc(sizeof(struct plugin_ctx)); @@ -189,7 +193,7 @@ static bRC newPlugin(bpContext* ctx) * translation. bsdEventWriteRecordTranslation - Perform write-side record * translantion. */ - bfuncs->registerBareosEvents( + bareos_core_functions->registerBareosEvents( ctx, 4, bsdEventJobEnd, bsdEventSetupRecordTranslation, bsdEventReadRecordTranslation, bsdEventWriteRecordTranslation); @@ -204,7 +208,7 @@ static bRC freePlugin(bpContext* ctx) int JobId = 0; struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; - bfuncs->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); + bareos_core_functions->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); Dmsg(ctx, debuglevel, "autoxflate-sd: freePlugin JobId=%d\n", JobId); if (!p_ctx) { @@ -651,8 +655,8 @@ static bool AutoDeflateRecord(bpContext* ctx, DeviceControlRecord* dcr) * DeviceRecord without a new memory buffer so we call new_record here * with the with_data boolean set explicitly to false. */ - nrec = bfuncs->new_record(false); - bfuncs->CopyRecordState(nrec, rec); + nrec = bareos_core_functions->new_record(false); + bareos_core_functions->CopyRecordState(nrec, rec); /* * Setup the converted DeviceRecord to point with its data buffer to the @@ -680,7 +684,7 @@ static bool AutoDeflateRecord(bpContext* ctx, DeviceControlRecord* dcr) if (!CompressData(dcr->jcr, dcr->device_resource->autodeflate_algorithm, rec->data, rec->data_len, data, max_compression_length, &nrec->data_len)) { - bfuncs->FreeRecord(nrec); + bareos_core_functions->FreeRecord(nrec); goto bail_out; } @@ -749,7 +753,7 @@ static bool AutoDeflateRecord(bpContext* ctx, DeviceControlRecord* dcr) /* * If the input is just an intermediate value free it now. */ - if (intermediate_value) { bfuncs->FreeRecord(dcr->after_rec); } + if (intermediate_value) { bareos_core_functions->FreeRecord(dcr->after_rec); } dcr->after_rec = nrec; retval = true; @@ -807,8 +811,8 @@ static bool AutoInflateRecord(bpContext* ctx, DeviceControlRecord* dcr) * DeviceRecord without a new memory buffer so we call new_record here * with the with_data boolean set explicitly to false. */ - nrec = bfuncs->new_record(false); - bfuncs->CopyRecordState(nrec, rec); + nrec = bareos_core_functions->new_record(false); + bareos_core_functions->CopyRecordState(nrec, rec); /* * Setup the converted record to point to the original data. @@ -821,7 +825,7 @@ static bool AutoInflateRecord(bpContext* ctx, DeviceControlRecord* dcr) if (!DecompressData(dcr->jcr, "Unknown", rec->maskedStream, &nrec->data, &nrec->data_len, true)) { - bfuncs->FreeRecord(nrec); + bareos_core_functions->FreeRecord(nrec); goto bail_out; } @@ -856,7 +860,7 @@ static bool AutoInflateRecord(bpContext* ctx, DeviceControlRecord* dcr) /* * If the input is just an intermediate value free it now. */ - if (intermediate_value) { bfuncs->FreeRecord(dcr->after_rec); } + if (intermediate_value) { bareos_core_functions->FreeRecord(dcr->after_rec); } dcr->after_rec = nrec; retval = true; diff --git a/core/src/plugins/stored/example/example-plugin-sd.cc b/core/src/plugins/stored/example/example-plugin-sd.cc index 509ff4666f3..feeadba6f84 100644 --- a/core/src/plugins/stored/example/example-plugin-sd.cc +++ b/core/src/plugins/stored/example/example-plugin-sd.cc @@ -2,7 +2,7 @@ BAREOS® - Backup Archiving REcovery Open Sourced Copyright (C) 2007-2011 Free Software Foundation Europe e.V. - Copyright (C) 2016-2016 Bareos GmbH & Co. KG + Copyright (C) 2016-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -44,7 +44,7 @@ static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value); /* Pointers to Bareos functions */ -static bsdFuncs* bfuncs = NULL; +static bsdFuncs* bareos_core_functions = NULL; static bsdInfo* binfo = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, @@ -72,14 +72,15 @@ extern "C" { * External entry point called by Bareos to "load" the plugin */ bRC loadPlugin(bsdInfo* lbinfo, - bsdFuncs* lbfuncs, + bsdFuncs* lbareos_core_functions, genpInfo** pinfo, psdFuncs** pfuncs) { - bfuncs = lbfuncs; /* set Bareos funct pointers */ + bareos_core_functions = + lbareos_core_functions; /* set Bareos funct pointers */ binfo = lbinfo; - printf("example-plugin-sd: Loaded: size=%d version=%d\n", bfuncs->size, - bfuncs->version); + printf("example-plugin-sd: Loaded: size=%d version=%d\n", + bareos_core_functions->size, bareos_core_functions->version); *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ printf("example-plugin-sd: Loaded\n"); @@ -110,9 +111,10 @@ bRC unloadPlugin() static bRC newPlugin(bpContext* ctx) { int JobId = 0; - bfuncs->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); + bareos_core_functions->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); printf("example-plugin-sd: newPlugin JobId=%d\n", JobId); - bfuncs->registerBareosEvents(ctx, 2, bsdEventJobStart, bsdEventJobEnd); + bareos_core_functions->registerBareosEvents(ctx, 2, bsdEventJobStart, + bsdEventJobEnd); return bRC_OK; } @@ -122,7 +124,7 @@ static bRC newPlugin(bpContext* ctx) static bRC freePlugin(bpContext* ctx) { int JobId = 0; - bfuncs->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); + bareos_core_functions->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); printf("example-plugin-sd: freePlugin JobId=%d\n", JobId); return bRC_OK; } @@ -159,9 +161,11 @@ static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value) printf("example-plugin-sd: HandleEvent JobEnd\n"); break; } - bfuncs->getBareosValue(ctx, bsdVarJobName, (void*)&name); + bareos_core_functions->getBareosValue(ctx, bsdVarJobName, (void*)&name); printf("Job Name=%s\n", name); - bfuncs->JobMessage(ctx, __FILE__, __LINE__, 1, 0, "JobMesssage message"); - bfuncs->DebugMessage(ctx, __FILE__, __LINE__, 1, "DebugMesssage message"); + bareos_core_functions->JobMessage(ctx, __FILE__, __LINE__, 1, 0, + "JobMesssage message"); + bareos_core_functions->DebugMessage(ctx, __FILE__, __LINE__, 1, + "DebugMesssage message"); return bRC_OK; } diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index ae154a2574d..11af472e76b 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -87,7 +87,7 @@ static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, void* value); /* Pointers to Bareos functions */ -static bsdFuncs* bfuncs = NULL; +static bsdFuncs* bareos_core_functions = NULL; static bsdInfo* binfo = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, @@ -141,11 +141,12 @@ extern "C" { * External entry point called by Bareos to "load" the plugin */ bRC loadPlugin(bsdInfo* lbinfo, - bsdFuncs* lbfuncs, + bsdFuncs* lbareos_core_functions, genpInfo** pinfo, psdFuncs** pfuncs) { - bfuncs = lbfuncs; /* Set Bareos funct pointers */ + bareos_core_functions = + lbareos_core_functions; /* Set Bareos funct pointers */ binfo = lbinfo; *pinfo = &pluginInfo; /* Return pointer to our info */ @@ -202,7 +203,8 @@ static bRC newPlugin(bpContext* bareos_plugin_ctx) * Always register some events the python plugin itself can register * any other events it is interested in. */ - bfuncs->registerBareosEvents(bareos_plugin_ctx, 1, bsdEventNewPluginOptions); + bareos_core_functions->registerBareosEvents(bareos_plugin_ctx, 1, + bsdEventNewPluginOptions); return bRC_OK; } @@ -677,8 +679,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bsdVarJobStatus: { int value; - if (bfuncs->getBareosValue(bareos_plugin_ctx, (bsdrVariable)var, - &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue( + bareos_plugin_ctx, (bsdrVariable)var, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } break; @@ -688,8 +690,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bsdVarJobBytes: { uint64_t value = 0; - if (bfuncs->getBareosValue(bareos_plugin_ctx, (bsdrVariable)var, - &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue( + bareos_plugin_ctx, (bsdrVariable)var, &value) == bRC_OK) { pRetVal = PyLong_FromUnsignedLong(value); } break; @@ -704,8 +706,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bsdVarVolumeName: { char* value = NULL; - if (bfuncs->getBareosValue(bareos_plugin_ctx, (bsdrVariable)var, - &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue( + bareos_plugin_ctx, (bsdrVariable)var, &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } } break; @@ -713,7 +715,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bsdVarCompatible: { bool value; - if (bfuncs->getBareosValue(NULL, (bsdrVariable)var, &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue(NULL, (bsdrVariable)var, + &value) == bRC_OK) { long bool_value; bool_value = (value) ? 1 : 0; @@ -724,7 +727,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bsdVarPluginDir: { char* value = NULL; - if (bfuncs->getBareosValue(NULL, (bsdrVariable)var, &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue(NULL, (bsdrVariable)var, + &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } } break; @@ -765,7 +769,8 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) value = PyString_AsString(pyValue); if (value) { - bfuncs->setBareosValue(bareos_plugin_ctx, (bsdwVariable)var, value); + bareos_core_functions->setBareosValue(bareos_plugin_ctx, + (bsdwVariable)var, value); } break; @@ -776,8 +781,8 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) value = PyInt_AsLong(pyValue); if (value >= 0) { - retval = bfuncs->setBareosValue(bareos_plugin_ctx, (bsdwVariable)var, - &value); + retval = bareos_core_functions->setBareosValue( + bareos_plugin_ctx, (bsdwVariable)var, &value); } break; } @@ -864,7 +869,8 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) if (event >= bsdEventJobStart && event <= bsdEventWriteRecordTranslation) { Dmsg(bareos_plugin_ctx, debuglevel, "python-sd: PyBareosRegisterEvents registering event %d\n", event); - retval = bfuncs->registerBareosEvents(bareos_plugin_ctx, 1, event); + retval = bareos_core_functions->registerBareosEvents(bareos_plugin_ctx, 1, + event); if (retval != bRC_OK) { break; } } @@ -905,7 +911,8 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) if (event >= bsdEventJobStart && event <= bsdEventWriteRecordTranslation) { Dmsg(bareos_plugin_ctx, debuglevel, "PyBareosUnRegisterEvents: registering event %d\n", event); - retval = bfuncs->unregisterBareosEvents(bareos_plugin_ctx, 1, event); + retval = bareos_core_functions->unregisterBareosEvents(bareos_plugin_ctx, + 1, event); if (retval != bRC_OK) { break; } } @@ -935,11 +942,12 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) PyErr_SetString(PyExc_ValueError, "bareos_plugin_ctx is unset"); return NULL; } - if (!bfuncs) { - PyErr_SetString(PyExc_ValueError, "bfuncs is unset"); + if (!bareos_core_functions) { + PyErr_SetString(PyExc_ValueError, "bareos_core_functions is unset"); return NULL; } - if (bfuncs->getInstanceCount(bareos_plugin_ctx, &value) == bRC_OK) { + if (bareos_core_functions->getInstanceCount(bareos_plugin_ctx, &value) == + bRC_OK) { pRetVal = PyInt_FromLong(value); } diff --git a/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc b/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc index 1357d68d72b..ebf9adac09b 100644 --- a/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc +++ b/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc @@ -94,7 +94,7 @@ static bRC send_volume_encryption_status(void* value); /** * Pointers to Bareos functions */ -static bsdFuncs* bfuncs = NULL; +static bsdFuncs* bareos_core_functions = NULL; static bsdInfo* binfo = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, @@ -127,14 +127,15 @@ extern "C" { * External entry point called by Bareos to "load the plugin */ bRC loadPlugin(bsdInfo* lbinfo, - bsdFuncs* lbfuncs, + bsdFuncs* lbareos_core_functions, genpInfo** pinfo, psdFuncs** pfuncs) { - bfuncs = lbfuncs; /* set Bareos funct pointers */ + bareos_core_functions = + lbareos_core_functions; /* set Bareos funct pointers */ binfo = lbinfo; - Dmsg2(debuglevel, "scsicrypto-sd: Loaded: size=%d version=%d\n", bfuncs->size, - bfuncs->version); + Dmsg2(debuglevel, "scsicrypto-sd: Loaded: size=%d version=%d\n", + bareos_core_functions->size, bareos_core_functions->version); *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ @@ -161,7 +162,7 @@ static bRC newPlugin(bpContext* ctx) { int JobId = 0; - bfuncs->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); + bareos_core_functions->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); Dmsg1(debuglevel, "scsicrypto-sd: newPlugin JobId=%d\n", JobId); /* @@ -191,10 +192,10 @@ static bRC newPlugin(bpContext* ctx) * bsdEventVolumeStatus - plugin callback for encryption status * of the volume loaded in the drive. */ - bfuncs->registerBareosEvents(ctx, 7, bsdEventLabelRead, bsdEventLabelVerified, - bsdEventLabelWrite, bsdEventVolumeUnload, - bsdEventReadError, bsdEventDriveStatus, - bsdEventVolumeStatus); + bareos_core_functions->registerBareosEvents( + ctx, 7, bsdEventLabelRead, bsdEventLabelVerified, bsdEventLabelWrite, + bsdEventVolumeUnload, bsdEventReadError, bsdEventDriveStatus, + bsdEventVolumeStatus); return bRC_OK; } @@ -206,7 +207,7 @@ static bRC freePlugin(bpContext* ctx) { int JobId = 0; - bfuncs->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); + bareos_core_functions->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); Dmsg1(debuglevel, "scsicrypto-sd: freePlugin JobId=%d\n", JobId); return bRC_OK; @@ -274,7 +275,7 @@ static inline bool GetVolumeEncryptionKey(DeviceControlRecord* dcr, * No valid VolCatInfo but we can get the info as we have * a connection to the director. */ - if (bfuncs->UpdateVolumeInfo(dcr)) { + if (bareos_core_functions->UpdateVolumeInfo(dcr)) { bstrncpy(VolEncrKey, dcr->VolCatInfo.VolEncrKey, MAX_NAME_LENGTH); return true; } @@ -287,7 +288,8 @@ static inline bool GetVolumeEncryptionKey(DeviceControlRecord* dcr, */ char* cached_key; - if ((cached_key = bfuncs->LookupCryptoKey(dcr->VolumeName))) { + if ((cached_key = + bareos_core_functions->LookupCryptoKey(dcr->VolumeName))) { bstrncpy(VolEncrKey, cached_key, MAX_NAME_LENGTH); free(cached_key); return true; diff --git a/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc b/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc index a4b989706df..0a9edb8486f 100644 --- a/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc +++ b/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc @@ -53,7 +53,7 @@ static bRC handle_tapealert_readout(void* value); /** * Pointers to Bareos functions */ -static bsdFuncs* bfuncs = NULL; +static bsdFuncs* bareos_core_functions = NULL; static bsdInfo* binfo = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, @@ -86,14 +86,15 @@ extern "C" { * External entry point called by Bareos to "load the plugin */ bRC loadPlugin(bsdInfo* lbinfo, - bsdFuncs* lbfuncs, + bsdFuncs* lbareos_core_functions, genpInfo** pinfo, psdFuncs** pfuncs) { - bfuncs = lbfuncs; /* set Bareos funct pointers */ + bareos_core_functions = + lbareos_core_functions; /* set Bareos funct pointers */ binfo = lbinfo; Dmsg2(debuglevel, "scsitapealert-sd: Loaded: size=%d version=%d\n", - bfuncs->size, bfuncs->version); + bareos_core_functions->size, bareos_core_functions->version); *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ @@ -120,13 +121,13 @@ static bRC newPlugin(bpContext* ctx) { int JobId = 0; - bfuncs->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); + bareos_core_functions->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); Dmsg1(debuglevel, "scsitapealert-sd: newPlugin JobId=%d\n", JobId); /* * Only register plugin events we are interested in. */ - bfuncs->registerBareosEvents( + bareos_core_functions->registerBareosEvents( ctx, 6, bsdEventVolumeLoad, bsdEventLabelVerified, bsdEventReadError, bsdEventWriteError, bsdEventVolumeUnload, bsdEventDeviceRelease); @@ -140,7 +141,7 @@ static bRC freePlugin(bpContext* ctx) { int JobId = 0; - bfuncs->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); + bareos_core_functions->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); Dmsg1(debuglevel, "scsitapealert-sd: freePlugin JobId=%d\n", JobId); return bRC_OK; @@ -231,7 +232,7 @@ static bRC handle_tapealert_readout(void* value) debuglevel, "scsitapealert-sd: tapealerts on device %s, calling UpdateTapeAlerts\n", dev->dev_name); - bfuncs->UpdateTapeAlert(dcr, flags); + bareos_core_functions->UpdateTapeAlert(dcr, flags); } return bRC_OK; diff --git a/core/src/stored/sd_plugins.cc b/core/src/stored/sd_plugins.cc index 69626409caf..34d6430c8df 100644 --- a/core/src/stored/sd_plugins.cc +++ b/core/src/stored/sd_plugins.cc @@ -86,14 +86,15 @@ static bool IsPluginCompatible(Plugin* plugin); static bsdInfo binfo = {sizeof(bsdFuncs), SD_PLUGIN_INTERFACE_VERSION}; /* Bareos entry points */ -static bsdFuncs bfuncs = {sizeof(bsdFuncs), SD_PLUGIN_INTERFACE_VERSION, - bareosRegisterEvents, bareosUnRegisterEvents, - bareosGetInstanceCount, bareosGetValue, - bareosSetValue, bareosJobMsg, - bareosDebugMsg, bareosEditDeviceCodes, - bareosLookupCryptoKey, bareosUpdateVolumeInfo, - bareosUpdateTapeAlert, bareosNewRecord, - bareosCopyRecordState, bareosFreeRecord}; +static bsdFuncs bareos_core_functions = { + sizeof(bsdFuncs), SD_PLUGIN_INTERFACE_VERSION, + bareosRegisterEvents, bareosUnRegisterEvents, + bareosGetInstanceCount, bareosGetValue, + bareosSetValue, bareosJobMsg, + bareosDebugMsg, bareosEditDeviceCodes, + bareosLookupCryptoKey, bareosUpdateVolumeInfo, + bareosUpdateTapeAlert, bareosNewRecord, + bareosCopyRecordState, bareosFreeRecord}; /** * Bareos private context @@ -407,8 +408,8 @@ void LoadSdPlugins(const char* plugin_dir, alist* plugin_names) return; } sd_plugin_list = new alist(10, not_owned_by_alist); - if (!LoadPlugins((void*)&binfo, (void*)&bfuncs, sd_plugin_list, plugin_dir, - plugin_names, plugin_type, IsPluginCompatible)) { + if (!LoadPlugins((void*)&binfo, (void*)&bareos_core_functions, sd_plugin_list, + plugin_dir, plugin_names, plugin_type, IsPluginCompatible)) { /* * Either none found, or some error */ diff --git a/core/src/tools/bpluginfo.cc b/core/src/tools/bpluginfo.cc index f5e2b40950d..c041125b8d3 100644 --- a/core/src/tools/bpluginfo.cc +++ b/core/src/tools/bpluginfo.cc @@ -48,7 +48,7 @@ extern "C" { typedef int (*loadPlugin)(void* binfo, - void* bfuncs, + void* bareos_core_functions, void** pinfo, void** pfuncs); typedef int (*unloadPlugin)(void); @@ -470,9 +470,15 @@ int main(int argc, char* argv[]) progdata* pdata; loadPlugin loadplugfunc; unloadPlugin unloadplugfunc; - bareosfuncs bfuncs = { - sizeof(bfuncs), 1, registerBareosEvents, getBareosValue, - setBareosValue, JobMessage, DebugMessage, bareosMalloc, + bareosfuncs bareos_core_functions = { + sizeof(bareos_core_functions), + 1, + registerBareosEvents, + getBareosValue, + setBareosValue, + JobMessage, + DebugMessage, + bareosMalloc, bareosFree, }; bareosinfos binfos; @@ -508,7 +514,8 @@ int main(int argc, char* argv[]) if (pdata->bapiversion > 0) { binfos.bdirinfo.version = pdata->bapiversion; } - loadplugfunc(&binfos, &bfuncs, (void**)&pdata->pinfo, (void**)&pdata->pfuncs); + loadplugfunc(&binfos, &bareos_core_functions, (void**)&pdata->pinfo, + (void**)&pdata->pfuncs); pdata->bplugtype = Getplugintype(pdata); diff --git a/core/src/win32/plugins/filed/mssqlvdi-fd.cc b/core/src/win32/plugins/filed/mssqlvdi-fd.cc index be73f9f085e..0194f56e1af 100644 --- a/core/src/win32/plugins/filed/mssqlvdi-fd.cc +++ b/core/src/win32/plugins/filed/mssqlvdi-fd.cc @@ -112,7 +112,7 @@ static bool adoReportError(bpContext* ctx); /** * Pointers to Bareos functions */ -static BareosCoreFunctions* bfuncs = NULL; +static BareosCoreFunctions* bareos_core_functions = NULL; static Core_PluginApiDefinition* binfo = NULL; /** @@ -228,11 +228,12 @@ extern "C" { * External entry point called by Bareos to "load" the plugin */ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, - BareosCoreFunctions* lbfuncs, + BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs) { - bfuncs = lbfuncs; /* set Bareos funct pointers */ + bareos_core_functions = + lbareos_core_functions; /* set Bareos funct pointers */ binfo = lbinfo; *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ @@ -277,9 +278,9 @@ static bRC newPlugin(bpContext* ctx) /* * Only register the events we are really interested in. */ - bfuncs->registerBareosEvents(ctx, 6, bEventLevel, bEventRestoreCommand, - bEventBackupCommand, bEventPluginCommand, - bEventEndRestoreJob, bEventNewPluginOptions); + bareos_core_functions->registerBareosEvents( + ctx, 6, bEventLevel, bEventRestoreCommand, bEventBackupCommand, + bEventPluginCommand, bEventEndRestoreJob, bEventNewPluginOptions); return bRC_OK; } From 462f7477952e8150238ca8c939c7ad7b4c9b30d8 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 30 Apr 2020 08:59:42 +0200 Subject: [PATCH 062/341] plugins: rename binfo -> bareos_plugin_interface_version --- core/src/dird/dir_plugins.cc | 9 ++- core/src/filed/fd_plugins.cc | 9 ++- core/src/lib/plugins.cc | 16 ++-- core/src/lib/plugins.h | 4 +- .../dird/example/example-plugin-dir.cc | 6 +- core/src/plugins/dird/python/python-dir.cc | 6 +- core/src/plugins/filed/bpipe/bpipe-fd.cc | 6 +- core/src/plugins/filed/cephfs/cephfs-fd.cc | 6 +- .../filed/example/example-plugin-fd.cc | 6 +- core/src/plugins/filed/gfapi/gfapi-fd.cc | 6 +- core/src/plugins/filed/python/bareosfd.cc | 11 +-- core/src/plugins/filed/python/python-fd.cc | 8 +- core/src/plugins/filed/python/python-fd.h | 2 +- .../python/test/python-fd-module-tester.cc | 2 +- core/src/plugins/filed/rados/rados-fd.cc | 6 +- .../filed/test-deltaseq/test-deltaseq-fd.cc | 6 +- .../filed/test-plugin/test-plugin-fd.cc | 6 +- .../stored/autoxflate/autoxflate-sd.cc | 6 +- .../stored/example/example-plugin-sd.cc | 6 +- core/src/plugins/stored/python/python-sd.cc | 6 +- .../stored/scsicrypto/scsicrypto-sd.cc | 6 +- .../stored/scsitapealert/scsitapealert-sd.cc | 6 +- core/src/stored/sd_plugins.cc | 8 +- core/src/tools/bpluginfo.cc | 17 +++-- core/src/win32/compat/compat.cc | 76 +++++++++++-------- core/src/win32/plugins/filed/mssqlvdi-fd.cc | 6 +- 26 files changed, 138 insertions(+), 114 deletions(-) diff --git a/core/src/dird/dir_plugins.cc b/core/src/dird/dir_plugins.cc index 7664b882346..89eb7fbe3bf 100644 --- a/core/src/dird/dir_plugins.cc +++ b/core/src/dird/dir_plugins.cc @@ -67,7 +67,8 @@ static bRC bareosDebugMsg(bpContext* ctx, static bool IsPluginCompatible(Plugin* plugin); /* BAREOS info */ -static bDirInfo binfo = {sizeof(bDirFuncs), DIR_PLUGIN_INTERFACE_VERSION}; +static bDirInfo bareos_plugin_interface_version = { + sizeof(bDirFuncs), DIR_PLUGIN_INTERFACE_VERSION}; /* BAREOS entry points */ static bDirFuncs bareos_core_functions = { @@ -294,9 +295,9 @@ void LoadDirPlugins(const char* plugin_dir, alist* plugin_names) } dird_plugin_list = new alist(10, not_owned_by_alist); - if (!LoadPlugins((void*)&binfo, (void*)&bareos_core_functions, - dird_plugin_list, plugin_dir, plugin_names, plugin_type, - IsPluginCompatible)) { + if (!LoadPlugins((void*)&bareos_plugin_interface_version, + (void*)&bareos_core_functions, dird_plugin_list, plugin_dir, + plugin_names, plugin_type, IsPluginCompatible)) { /* Either none found, or some error */ if (dird_plugin_list->size() == 0) { delete dird_plugin_list; diff --git a/core/src/filed/fd_plugins.cc b/core/src/filed/fd_plugins.cc index 9d8b5b81ae6..9f815e900bf 100644 --- a/core/src/filed/fd_plugins.cc +++ b/core/src/filed/fd_plugins.cc @@ -135,8 +135,8 @@ static boffset_t MyPluginBlseek(BareosWinFilePacket* bfd, int whence); /* Bareos info */ -static Core_PluginApiDefinition binfo = {sizeof(Core_PluginApiDefinition), - FD_PLUGIN_INTERFACE_VERSION}; +static Core_PluginApiDefinition bareos_plugin_interface_version = { + sizeof(Core_PluginApiDefinition), FD_PLUGIN_INTERFACE_VERSION}; /* Bareos entry points */ static BareosCoreFunctions bareos_core_functions = {sizeof(BareosCoreFunctions), @@ -1714,8 +1714,9 @@ void LoadFdPlugins(const char* plugin_dir, alist* plugin_names) } fd_plugin_list = new alist(10, not_owned_by_alist); - if (!LoadPlugins((void*)&binfo, (void*)&bareos_core_functions, fd_plugin_list, - plugin_dir, plugin_names, plugin_type, IsPluginCompatible)) { + if (!LoadPlugins((void*)&bareos_plugin_interface_version, + (void*)&bareos_core_functions, fd_plugin_list, plugin_dir, + plugin_names, plugin_type, IsPluginCompatible)) { /* * Either none found, or some error */ diff --git a/core/src/lib/plugins.cc b/core/src/lib/plugins.cc index 52200026dce..5f1c59a293c 100644 --- a/core/src/lib/plugins.cc +++ b/core/src/lib/plugins.cc @@ -106,7 +106,7 @@ static void ClosePlugin(Plugin* plugin) * Load a specific plugin and check if the plugin had the correct * entry points, the license is compatible and the initialize the plugin. */ -static bool load_a_plugin(void* binfo, +static bool load_a_plugin(void* bareos_plugin_interface_version, void* bareos_core_functions, const char* plugin_pathname, const char* plugin_name, @@ -168,8 +168,8 @@ static bool load_a_plugin(void* binfo, /* * Initialize the plugin */ - if (loadPlugin(binfo, bareos_core_functions, &plugin->pinfo, - &plugin->pfuncs) != bRC_OK) { + if (loadPlugin(bareos_plugin_interface_version, bareos_core_functions, + &plugin->pinfo, &plugin->pfuncs) != bRC_OK) { ClosePlugin(plugin); return false; @@ -193,7 +193,7 @@ static bool load_a_plugin(void* binfo, * Or when plugin_names is give it has a list of plugins * to load from the specified directory. */ -bool LoadPlugins(void* binfo, +bool LoadPlugins(void* bareos_plugin_interface_version, void* bareos_core_functions, alist* plugin_list, const char* plugin_dir, @@ -242,8 +242,8 @@ bool LoadPlugins(void* binfo, /* * Try to load the plugin and resolve the wanted symbols. */ - if (load_a_plugin(binfo, bareos_core_functions, fname.c_str(), - plugin_name.c_str(), type, plugin_list, + if (load_a_plugin(bareos_plugin_interface_version, bareos_core_functions, + fname.c_str(), plugin_name.c_str(), type, plugin_list, IsPluginCompatible)) { found = true; } @@ -313,8 +313,8 @@ bool LoadPlugins(void* binfo, /* * Try to load the plugin and resolve the wanted symbols. */ - if (load_a_plugin(binfo, bareos_core_functions, fname.c_str(), - result->d_name, type, plugin_list, + if (load_a_plugin(bareos_plugin_interface_version, bareos_core_functions, + fname.c_str(), result->d_name, type, plugin_list, IsPluginCompatible)) { found = true; } diff --git a/core/src/lib/plugins.h b/core/src/lib/plugins.h index e39a32178ec..83d72b92b28 100644 --- a/core/src/lib/plugins.h +++ b/core/src/lib/plugins.h @@ -59,7 +59,7 @@ typedef enum #define HIGHEST_PLUGIN_INSTANCE 127 extern "C" { -typedef bRC (*t_loadPlugin)(void* binfo, +typedef bRC (*t_loadPlugin)(void* bareos_plugin_interface_version, void* bareos_core_functions, void** pinfo, void** pfuncs); @@ -101,7 +101,7 @@ typedef struct gen_pluginInfo { class alist; /* Functions */ -bool LoadPlugins(void* binfo, +bool LoadPlugins(void* bareos_plugin_interface_version, void* bareos_core_functions, alist* plugin_list, const char* plugin_dir, diff --git a/core/src/plugins/dird/example/example-plugin-dir.cc b/core/src/plugins/dird/example/example-plugin-dir.cc index 4bcddca5cd5..c2a7f455c9a 100644 --- a/core/src/plugins/dird/example/example-plugin-dir.cc +++ b/core/src/plugins/dird/example/example-plugin-dir.cc @@ -47,7 +47,7 @@ static bRC handlePluginEvent(bpContext* ctx, bDirEvent* event, void* value); /* Pointers to Bareos functions */ static bDirFuncs* bareos_core_functions = NULL; -static bDirInfo* binfo = NULL; +static bDirInfo* bareos_plugin_interface_version = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), DIR_PLUGIN_INTERFACE_VERSION, DIR_PLUGIN_MAGIC, PLUGIN_LICENSE, @@ -73,14 +73,14 @@ extern "C" { * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(bDirInfo* lbinfo, +bRC loadPlugin(bDirInfo* lbareos_plugin_interface_version, bDirFuncs* lbareos_core_functions, genpInfo** pinfo, pDirFuncs** pfuncs) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ - binfo = lbinfo; + bareos_plugin_interface_version = lbareos_plugin_interface_version; printf("plugin: Loaded: size=%d version=%d\n", bareos_core_functions->size, bareos_core_functions->version); diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index 95837d93580..b9b673cbd03 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -88,7 +88,7 @@ static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, /* Pointers to Bareos functions */ static bDirFuncs* bareos_core_functions = NULL; -static bDirInfo* binfo = NULL; +static bDirInfo* bareos_plugin_interface_version = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), DIR_PLUGIN_INTERFACE_VERSION, DIR_PLUGIN_MAGIC, PLUGIN_LICENSE, @@ -141,14 +141,14 @@ extern "C" { * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(bDirInfo* lbinfo, +bRC loadPlugin(bDirInfo* lbareos_plugin_interface_version, bDirFuncs* lbareos_core_functions, genpInfo** pinfo, pDirFuncs** pfuncs) { bareos_core_functions = lbareos_core_functions; /* Set Bareos funct pointers */ - binfo = lbinfo; + bareos_plugin_interface_version = lbareos_plugin_interface_version; *pinfo = &pluginInfo; /* Return pointer to our info */ *pfuncs = &pluginFuncs; /* Return pointer to our functions */ diff --git a/core/src/plugins/filed/bpipe/bpipe-fd.cc b/core/src/plugins/filed/bpipe/bpipe-fd.cc index 80e403404c0..e7ff6d1b20b 100644 --- a/core/src/plugins/filed/bpipe/bpipe-fd.cc +++ b/core/src/plugins/filed/bpipe/bpipe-fd.cc @@ -70,7 +70,7 @@ static bRC plugin_has_all_arguments(bpContext* ctx); /* Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* binfo = NULL; +static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; /* Plugin Information block */ static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, @@ -139,14 +139,14 @@ extern "C" { /** * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(Core_PluginApiDefinition* lbinfo, +bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ - binfo = lbinfo; + bareos_plugin_interface_version = lbareos_plugin_interface_version; *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ diff --git a/core/src/plugins/filed/cephfs/cephfs-fd.cc b/core/src/plugins/filed/cephfs/cephfs-fd.cc index 42064f57c08..99374d8d101 100644 --- a/core/src/plugins/filed/cephfs/cephfs-fd.cc +++ b/core/src/plugins/filed/cephfs/cephfs-fd.cc @@ -77,7 +77,7 @@ static bRC end_restore_job(bpContext* ctx, void* value); * Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* binfo = NULL; +static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; /** * Plugin Information block @@ -179,14 +179,14 @@ extern "C" { * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(Core_PluginApiDefinition* lbinfo, +bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ - binfo = lbinfo; + bareos_plugin_interface_version = lbareos_plugin_interface_version; *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ diff --git a/core/src/plugins/filed/example/example-plugin-fd.cc b/core/src/plugins/filed/example/example-plugin-fd.cc index 6afba518a59..ee5b75edd08 100644 --- a/core/src/plugins/filed/example/example-plugin-fd.cc +++ b/core/src/plugins/filed/example/example-plugin-fd.cc @@ -47,7 +47,7 @@ static bRC setXattr(bpContext* ctx, xattr_pkt* xp); /* Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* binfo = NULL; +static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, FD_PLUGIN_MAGIC, PLUGIN_LICENSE, @@ -71,14 +71,14 @@ extern "C" { /* * Plugin called here when it is first loaded */ -bRC loadPlugin(Core_PluginApiDefinition* lbinfo, +bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ - binfo = lbinfo; + bareos_plugin_interface_version = lbareos_plugin_interface_version; printf("plugin: Loaded: size=%d version=%d\n", bareos_core_functions->size, bareos_core_functions->version); diff --git a/core/src/plugins/filed/gfapi/gfapi-fd.cc b/core/src/plugins/filed/gfapi/gfapi-fd.cc index cff764f72d3..0f11760a115 100644 --- a/core/src/plugins/filed/gfapi/gfapi-fd.cc +++ b/core/src/plugins/filed/gfapi/gfapi-fd.cc @@ -92,7 +92,7 @@ static bRC setup_restore(bpContext* ctx, void* value); * Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* binfo = NULL; +static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; /** * Plugin Information block @@ -313,14 +313,14 @@ extern "C" { * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(Core_PluginApiDefinition* lbinfo, +bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ - binfo = lbinfo; + bareos_plugin_interface_version = lbareos_plugin_interface_version; *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 7a214091393..6afd8874528 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -122,7 +122,7 @@ static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, /* Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* binfo = NULL; +static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; /* static genpInfo pluginInfo = {sizeof(pluginInfo), * FD_PLUGIN_INTERFACE_VERSION, */ @@ -218,14 +218,14 @@ static void PyErrorHandler() /** * Plugin called here when it is first loaded */ -/* bRC loadPlugin(Core_PluginApiDefinition* lbinfo, */ +/* bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, */ /* BareosCoreFunctions* lbareos_core_functions, */ /* genpInfo** pinfo, */ /* pFuncs** pfuncs) */ /* { */ /* bareos_core_functions = lbareos_core_functions; /1* Set Bareos funct * pointers *1/ */ -/* binfo = lbinfo; */ +/* bareos_plugin_interface_version = lbareos_plugin_interface_version; */ /* *pinfo = &pluginInfo; /1* Return pointer to our info *1/ */ /* *pfuncs = &pluginFuncs; /1* Return pointer to our functions *1/ */ @@ -251,8 +251,9 @@ static void PyErrorHandler() /* // Extract capsules pointer from bareosfd module */ /* void (*loadplugin_from_bareosfd_module)( */ -/* filedaemon::Core_PluginApiDefinition * lbinfo, - * filedaemon::BareosCoreFunctions * lbareos_core_functions, */ +/* filedaemon::Core_PluginApiDefinition * + * lbareos_plugin_interface_version, filedaemon::BareosCoreFunctions * + * lbareos_core_functions, */ /* genpInfo * *pinfo, filedaemon::pFuncs * *pfuncs) = */ /* (void (*)(filedaemon::Core_PluginApiDefinition*, * filedaemon::BareosCoreFunctions*, genpInfo**, */ diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 87a5638eea4..4942fbdd0c1 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -121,7 +121,7 @@ static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, /* Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* binfo = NULL; +static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, FD_PLUGIN_MAGIC, PLUGIN_LICENSE, @@ -216,14 +216,14 @@ static void PyErrorHandler() /** * Plugin called here when it is first loaded */ -bRC loadPlugin(Core_PluginApiDefinition* lbinfo, +bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs) { bareos_core_functions = lbareos_core_functions; /* Set Bareos funct pointers */ - binfo = lbinfo; + bareos_plugin_interface_version = lbareos_plugin_interface_version; *pinfo = &pluginInfo; /* Return pointer to our info */ *pfuncs = &pluginFuncs; /* Return pointer to our functions */ @@ -249,7 +249,7 @@ bRC loadPlugin(Core_PluginApiDefinition* lbinfo, // Extract capsules pointer from bareosfd module void (*loadplugin_from_bareosfd_module)( - filedaemon::Core_PluginApiDefinition * lbinfo, + filedaemon::Core_PluginApiDefinition * lbareos_plugin_interface_version, filedaemon::BareosCoreFunctions * lbareos_core_functions, genpInfo * *pinfo, filedaemon::pFuncs * *pfuncs) = (void (*)(filedaemon::Core_PluginApiDefinition*, diff --git a/core/src/plugins/filed/python/python-fd.h b/core/src/plugins/filed/python/python-fd.h index 7ffa65039ca..c1c8296e311 100644 --- a/core/src/plugins/filed/python/python-fd.h +++ b/core/src/plugins/filed/python/python-fd.h @@ -762,7 +762,7 @@ static void* bareos_core_functions = NULL; extern "C" { #endif /* Forward declaration of loadPlugin() as it is stored in Capsule */ -bRC loadPlugin(::Core_PluginApiDefinition* lbinfo, +bRC loadPlugin(::Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs); diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index 90f4837851b..bf40ac6931e 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -206,7 +206,7 @@ int main(int argc, char* argv[]) // Extract capsules pointer from bareosfd module void (*loadplugin_from_bareosfd_module)( - filedaemon::Core_PluginApiDefinition * lbinfo, + filedaemon::Core_PluginApiDefinition * lbareos_plugin_interface_version, filedaemon::BareosCoreFunctions * lbareos_core_functions, genpInfo * *pinfo, filedaemon::pFuncs * *pfuncs) = (void (*)(filedaemon::Core_PluginApiDefinition*, diff --git a/core/src/plugins/filed/rados/rados-fd.cc b/core/src/plugins/filed/rados/rados-fd.cc index 1efad184723..c605e37db3d 100644 --- a/core/src/plugins/filed/rados/rados-fd.cc +++ b/core/src/plugins/filed/rados/rados-fd.cc @@ -85,7 +85,7 @@ static bRC end_restore_job(bpContext* ctx, void* value); * Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* binfo = NULL; +static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; /** * Plugin Information block @@ -178,14 +178,14 @@ extern "C" { * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(Core_PluginApiDefinition* lbinfo, +bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ - binfo = lbinfo; + bareos_plugin_interface_version = lbareos_plugin_interface_version; *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ diff --git a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc index 9ac36e71b1f..a507c73a134 100644 --- a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc +++ b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc @@ -55,7 +55,7 @@ static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp); /* Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* binfo = NULL; +static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; /* Plugin Information block */ static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, @@ -116,14 +116,14 @@ extern "C" { /** * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(Core_PluginApiDefinition* lbinfo, +bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ - binfo = lbinfo; + bareos_plugin_interface_version = lbareos_plugin_interface_version; *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ diff --git a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc index 35f64c5ab22..f3a877ab8e9 100644 --- a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc +++ b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc @@ -64,7 +64,7 @@ static bRC setXattr(bpContext* ctx, xattr_pkt* xp); /* Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* binfo = NULL; +static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; /* Plugin Information block */ static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, @@ -122,14 +122,14 @@ extern "C" { /** * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(Core_PluginApiDefinition* lbinfo, +bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ - binfo = lbinfo; + bareos_plugin_interface_version = lbareos_plugin_interface_version; *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ diff --git a/core/src/plugins/stored/autoxflate/autoxflate-sd.cc b/core/src/plugins/stored/autoxflate/autoxflate-sd.cc index b03e5b1be3f..c0e4338da0e 100644 --- a/core/src/plugins/stored/autoxflate/autoxflate-sd.cc +++ b/core/src/plugins/stored/autoxflate/autoxflate-sd.cc @@ -90,7 +90,7 @@ static bool sd_enabled_compatible = false; * Pointers to Bareos functions */ static bsdFuncs* bareos_core_functions = NULL; -static bsdInfo* binfo = NULL; +static bsdInfo* bareos_plugin_interface_version = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, SD_PLUGIN_MAGIC, PLUGIN_LICENSE, @@ -134,14 +134,14 @@ extern "C" { * * External entry point called by Bareos to "load the plugin */ -bRC loadPlugin(bsdInfo* lbinfo, +bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, bsdFuncs* lbareos_core_functions, genpInfo** pinfo, psdFuncs** pfuncs) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ - binfo = lbinfo; + bareos_plugin_interface_version = lbareos_plugin_interface_version; *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ diff --git a/core/src/plugins/stored/example/example-plugin-sd.cc b/core/src/plugins/stored/example/example-plugin-sd.cc index feeadba6f84..057dafa037d 100644 --- a/core/src/plugins/stored/example/example-plugin-sd.cc +++ b/core/src/plugins/stored/example/example-plugin-sd.cc @@ -45,7 +45,7 @@ static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value); /* Pointers to Bareos functions */ static bsdFuncs* bareos_core_functions = NULL; -static bsdInfo* binfo = NULL; +static bsdInfo* bareos_plugin_interface_version = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, SD_PLUGIN_MAGIC, PLUGIN_LICENSE, @@ -71,14 +71,14 @@ extern "C" { * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(bsdInfo* lbinfo, +bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, bsdFuncs* lbareos_core_functions, genpInfo** pinfo, psdFuncs** pfuncs) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ - binfo = lbinfo; + bareos_plugin_interface_version = lbareos_plugin_interface_version; printf("example-plugin-sd: Loaded: size=%d version=%d\n", bareos_core_functions->size, bareos_core_functions->version); *pinfo = &pluginInfo; /* return pointer to our info */ diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index 11af472e76b..eddf3c1c174 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -88,7 +88,7 @@ static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, /* Pointers to Bareos functions */ static bsdFuncs* bareos_core_functions = NULL; -static bsdInfo* binfo = NULL; +static bsdInfo* bareos_plugin_interface_version = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, SD_PLUGIN_MAGIC, PLUGIN_LICENSE, @@ -140,14 +140,14 @@ extern "C" { * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(bsdInfo* lbinfo, +bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, bsdFuncs* lbareos_core_functions, genpInfo** pinfo, psdFuncs** pfuncs) { bareos_core_functions = lbareos_core_functions; /* Set Bareos funct pointers */ - binfo = lbinfo; + bareos_plugin_interface_version = lbareos_plugin_interface_version; *pinfo = &pluginInfo; /* Return pointer to our info */ *pfuncs = &pluginFuncs; /* Return pointer to our functions */ diff --git a/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc b/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc index ebf9adac09b..a6452390975 100644 --- a/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc +++ b/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc @@ -95,7 +95,7 @@ static bRC send_volume_encryption_status(void* value); * Pointers to Bareos functions */ static bsdFuncs* bareos_core_functions = NULL; -static bsdInfo* binfo = NULL; +static bsdInfo* bareos_plugin_interface_version = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, SD_PLUGIN_MAGIC, PLUGIN_LICENSE, @@ -126,14 +126,14 @@ extern "C" { * * External entry point called by Bareos to "load the plugin */ -bRC loadPlugin(bsdInfo* lbinfo, +bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, bsdFuncs* lbareos_core_functions, genpInfo** pinfo, psdFuncs** pfuncs) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ - binfo = lbinfo; + bareos_plugin_interface_version = lbareos_plugin_interface_version; Dmsg2(debuglevel, "scsicrypto-sd: Loaded: size=%d version=%d\n", bareos_core_functions->size, bareos_core_functions->version); *pinfo = &pluginInfo; /* return pointer to our info */ diff --git a/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc b/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc index 0a9edb8486f..59262e6d0fd 100644 --- a/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc +++ b/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc @@ -54,7 +54,7 @@ static bRC handle_tapealert_readout(void* value); * Pointers to Bareos functions */ static bsdFuncs* bareos_core_functions = NULL; -static bsdInfo* binfo = NULL; +static bsdInfo* bareos_plugin_interface_version = NULL; static genpInfo pluginInfo = {sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, SD_PLUGIN_MAGIC, PLUGIN_LICENSE, @@ -85,14 +85,14 @@ extern "C" { * * External entry point called by Bareos to "load the plugin */ -bRC loadPlugin(bsdInfo* lbinfo, +bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, bsdFuncs* lbareos_core_functions, genpInfo** pinfo, psdFuncs** pfuncs) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ - binfo = lbinfo; + bareos_plugin_interface_version = lbareos_plugin_interface_version; Dmsg2(debuglevel, "scsitapealert-sd: Loaded: size=%d version=%d\n", bareos_core_functions->size, bareos_core_functions->version); *pinfo = &pluginInfo; /* return pointer to our info */ diff --git a/core/src/stored/sd_plugins.cc b/core/src/stored/sd_plugins.cc index 34d6430c8df..7554f6d7513 100644 --- a/core/src/stored/sd_plugins.cc +++ b/core/src/stored/sd_plugins.cc @@ -83,7 +83,8 @@ static void bareosFreeRecord(DeviceRecord* rec); static bool IsPluginCompatible(Plugin* plugin); /* Bareos info */ -static bsdInfo binfo = {sizeof(bsdFuncs), SD_PLUGIN_INTERFACE_VERSION}; +static bsdInfo bareos_plugin_interface_version = {sizeof(bsdFuncs), + SD_PLUGIN_INTERFACE_VERSION}; /* Bareos entry points */ static bsdFuncs bareos_core_functions = { @@ -408,8 +409,9 @@ void LoadSdPlugins(const char* plugin_dir, alist* plugin_names) return; } sd_plugin_list = new alist(10, not_owned_by_alist); - if (!LoadPlugins((void*)&binfo, (void*)&bareos_core_functions, sd_plugin_list, - plugin_dir, plugin_names, plugin_type, IsPluginCompatible)) { + if (!LoadPlugins((void*)&bareos_plugin_interface_version, + (void*)&bareos_core_functions, sd_plugin_list, plugin_dir, + plugin_names, plugin_type, IsPluginCompatible)) { /* * Either none found, or some error */ diff --git a/core/src/tools/bpluginfo.cc b/core/src/tools/bpluginfo.cc index c041125b8d3..3fce50d3f00 100644 --- a/core/src/tools/bpluginfo.cc +++ b/core/src/tools/bpluginfo.cc @@ -47,7 +47,7 @@ #endif extern "C" { -typedef int (*loadPlugin)(void* binfo, +typedef int (*loadPlugin)(void* bareos_plugin_interface_version, void* bareos_core_functions, void** pinfo, void** pfuncs); @@ -481,13 +481,14 @@ int main(int argc, char* argv[]) bareosMalloc, bareosFree, }; - bareosinfos binfos; + bareosinfos bareos_plugin_interface_version; pdata = allocpdata(); ParseArgs(pdata, argc, argv); - binfos.bfdinfo.size = sizeof(binfos); - binfos.bfdinfo.version = DEFAULT_API_VERSION; + bareos_plugin_interface_version.bfdinfo.size = + sizeof(bareos_plugin_interface_version); + bareos_plugin_interface_version.bfdinfo.version = DEFAULT_API_VERSION; pdata->pluginhandle = dlopen(pdata->pluginfile, RTLD_LAZY); if (pdata->pluginhandle == NULL) { @@ -512,10 +513,12 @@ int main(int argc, char* argv[]) exit(3); } - if (pdata->bapiversion > 0) { binfos.bdirinfo.version = pdata->bapiversion; } + if (pdata->bapiversion > 0) { + bareos_plugin_interface_version.bdirinfo.version = pdata->bapiversion; + } - loadplugfunc(&binfos, &bareos_core_functions, (void**)&pdata->pinfo, - (void**)&pdata->pfuncs); + loadplugfunc(&bareos_plugin_interface_version, &bareos_core_functions, + (void**)&pdata->pinfo, (void**)&pdata->pfuncs); pdata->bplugtype = Getplugintype(pdata); diff --git a/core/src/win32/compat/compat.cc b/core/src/win32/compat/compat.cc index 3f24a5616dd..a1c24050697 100644 --- a/core/src/win32/compat/compat.cc +++ b/core/src/win32/compat/compat.cc @@ -3,7 +3,7 @@ Copyright (C) 2004-2010 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2019 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -1322,7 +1322,7 @@ static int GetWindowsFileInfo(const char* filename, WIN32_FIND_DATAW info_w; // window's file info WIN32_FIND_DATAA info_a; // window's file info #if (_WIN32_WINNT >= 0x0600) - FILE_BASIC_INFO binfo; // window's basic file info + FILE_BASIC_INFO bareos_plugin_interface_version; // window's basic file info HANDLE h = INVALID_HANDLE_VALUE; #endif HANDLE fh = INVALID_HANDLE_VALUE; @@ -1401,15 +1401,20 @@ static int GetWindowsFileInfo(const char* filename, */ if (h != INVALID_HANDLE_VALUE) { if (p_GetFileInformationByHandleEx) { - if (p_GetFileInformationByHandleEx(h, FileBasicInfo, &binfo, - sizeof(binfo))) { - pftLastAccessTime = (FILETIME*)&binfo.LastAccessTime; - pftLastWriteTime = (FILETIME*)&binfo.LastWriteTime; - if (CvtFtimeToUtime(binfo.CreationTime) > - CvtFtimeToUtime(binfo.ChangeTime)) { - pftCreationTime = (FILETIME*)&binfo.CreationTime; + if (p_GetFileInformationByHandleEx( + h, FileBasicInfo, &bareos_plugin_interface_version, + sizeof(bareos_plugin_interface_version))) { + pftLastAccessTime = + (FILETIME*)&bareos_plugin_interface_version.LastAccessTime; + pftLastWriteTime = + (FILETIME*)&bareos_plugin_interface_version.LastWriteTime; + if (CvtFtimeToUtime(bareos_plugin_interface_version.CreationTime) > + CvtFtimeToUtime(bareos_plugin_interface_version.ChangeTime)) { + pftCreationTime = + (FILETIME*)&bareos_plugin_interface_version.CreationTime; } else { - pftCreationTime = (FILETIME*)&binfo.ChangeTime; + pftCreationTime = + (FILETIME*)&bareos_plugin_interface_version.ChangeTime; } use_fallback_data = false; } @@ -1630,17 +1635,23 @@ int fstat(intptr_t fd, struct stat* sb) #if (_WIN32_WINNT >= 0x0600) if (p_GetFileInformationByHandleEx) { - FILE_BASIC_INFO binfo; - - if (p_GetFileInformationByHandleEx((HANDLE)_get_osfhandle(fd), - FileBasicInfo, &binfo, sizeof(binfo))) { - sb->st_atime = CvtFtimeToUtime(binfo.LastAccessTime); - sb->st_mtime = CvtFtimeToUtime(binfo.LastWriteTime); - if (CvtFtimeToUtime(binfo.CreationTime) > - CvtFtimeToUtime(binfo.ChangeTime)) { - sb->st_ctime = CvtFtimeToUtime(binfo.CreationTime); + FILE_BASIC_INFO bareos_plugin_interface_version; + + if (p_GetFileInformationByHandleEx( + (HANDLE)_get_osfhandle(fd), FileBasicInfo, + &bareos_plugin_interface_version, + sizeof(bareos_plugin_interface_version))) { + sb->st_atime = + CvtFtimeToUtime(bareos_plugin_interface_version.LastAccessTime); + sb->st_mtime = + CvtFtimeToUtime(bareos_plugin_interface_version.LastWriteTime); + if (CvtFtimeToUtime(bareos_plugin_interface_version.CreationTime) > + CvtFtimeToUtime(bareos_plugin_interface_version.ChangeTime)) { + sb->st_ctime = + CvtFtimeToUtime(bareos_plugin_interface_version.CreationTime); } else { - sb->st_ctime = CvtFtimeToUtime(binfo.ChangeTime); + sb->st_ctime = + CvtFtimeToUtime(bareos_plugin_interface_version.ChangeTime); } use_fallback_data = false; } @@ -1841,17 +1852,22 @@ int stat(const char* filename, struct stat* sb) } if (h != INVALID_HANDLE_VALUE) { - FILE_BASIC_INFO binfo; - - if (p_GetFileInformationByHandleEx(h, FileBasicInfo, &binfo, - sizeof(binfo))) { - sb->st_atime = CvtFtimeToUtime(binfo.LastAccessTime); - sb->st_mtime = CvtFtimeToUtime(binfo.LastWriteTime); - if (CvtFtimeToUtime(binfo.CreationTime) > - CvtFtimeToUtime(binfo.ChangeTime)) { - sb->st_ctime = CvtFtimeToUtime(binfo.CreationTime); + FILE_BASIC_INFO bareos_plugin_interface_version; + + if (p_GetFileInformationByHandleEx( + h, FileBasicInfo, &bareos_plugin_interface_version, + sizeof(bareos_plugin_interface_version))) { + sb->st_atime = + CvtFtimeToUtime(bareos_plugin_interface_version.LastAccessTime); + sb->st_mtime = + CvtFtimeToUtime(bareos_plugin_interface_version.LastWriteTime); + if (CvtFtimeToUtime(bareos_plugin_interface_version.CreationTime) > + CvtFtimeToUtime(bareos_plugin_interface_version.ChangeTime)) { + sb->st_ctime = + CvtFtimeToUtime(bareos_plugin_interface_version.CreationTime); } else { - sb->st_ctime = CvtFtimeToUtime(binfo.ChangeTime); + sb->st_ctime = + CvtFtimeToUtime(bareos_plugin_interface_version.ChangeTime); } use_fallback_data = false; } diff --git a/core/src/win32/plugins/filed/mssqlvdi-fd.cc b/core/src/win32/plugins/filed/mssqlvdi-fd.cc index 0194f56e1af..cf0a55dbf7f 100644 --- a/core/src/win32/plugins/filed/mssqlvdi-fd.cc +++ b/core/src/win32/plugins/filed/mssqlvdi-fd.cc @@ -113,7 +113,7 @@ static bool adoReportError(bpContext* ctx); * Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* binfo = NULL; +static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; /** * Plugin Information block @@ -227,14 +227,14 @@ extern "C" { * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(Core_PluginApiDefinition* lbinfo, +bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, genpInfo** pinfo, pFuncs** pfuncs) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ - binfo = lbinfo; + bareos_plugin_interface_version = lbareos_plugin_interface_version; *pinfo = &pluginInfo; /* return pointer to our info */ *pfuncs = &pluginFuncs; /* return pointer to our functions */ From 95beeafa8585de0320fa1683572e8defbf776f2a Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 30 Apr 2020 09:06:59 +0200 Subject: [PATCH 063/341] plugins: rename genpInfo -> PluginInformation --- core/src/dird/dir_plugins.cc | 10 ++++----- core/src/dird/dir_plugins.h | 2 +- core/src/filed/fd_plugins.cc | 10 ++++----- core/src/filed/fd_plugins.h | 2 +- core/src/lib/plugins.cc | 2 +- core/src/lib/plugins.h | 2 +- .../dird/example/example-plugin-dir.cc | 11 +++++----- core/src/plugins/dird/python/python-dir.cc | 13 ++++++------ core/src/plugins/filed/bpipe/bpipe-fd.cc | 13 ++++++------ core/src/plugins/filed/cephfs/cephfs-fd.cc | 13 ++++++------ .../filed/example/example-plugin-fd.cc | 11 +++++----- core/src/plugins/filed/gfapi/gfapi-fd.cc | 13 ++++++------ core/src/plugins/filed/python/bareosfd.cc | 12 +++++------ core/src/plugins/filed/python/python-fd.cc | 21 ++++++++++--------- core/src/plugins/filed/python/python-fd.h | 2 +- .../python/test/python-fd-module-tester.cc | 8 +++---- core/src/plugins/filed/rados/rados-fd.cc | 13 ++++++------ .../filed/test-deltaseq/test-deltaseq-fd.cc | 11 +++++----- .../filed/test-plugin/test-plugin-fd.cc | 11 +++++----- .../stored/autoxflate/autoxflate-sd.cc | 13 ++++++------ .../stored/example/example-plugin-sd.cc | 11 +++++----- core/src/plugins/stored/python/python-sd.cc | 13 ++++++------ .../stored/scsicrypto/scsicrypto-sd.cc | 13 ++++++------ .../stored/scsitapealert/scsitapealert-sd.cc | 13 ++++++------ core/src/stored/sd_plugins.cc | 10 ++++----- core/src/stored/sd_plugins.h | 2 +- core/src/win32/plugins/filed/mssqlvdi-fd.cc | 13 ++++++------ 27 files changed, 142 insertions(+), 126 deletions(-) diff --git a/core/src/dird/dir_plugins.cc b/core/src/dird/dir_plugins.cc index 89eb7fbe3bf..cf4a922b6ab 100644 --- a/core/src/dird/dir_plugins.cc +++ b/core/src/dird/dir_plugins.cc @@ -263,11 +263,11 @@ bRC GeneratePluginEvent(JobControlRecord* jcr, */ void DumpDirPlugin(Plugin* plugin, FILE* fp) { - genpInfo* info; + PluginInformation* info; if (!plugin) { return; } - info = (genpInfo*)plugin->pinfo; + info = (PluginInformation*)plugin->pinfo; fprintf(fp, "\tversion=%d\n", info->version); fprintf(fp, "\tdate=%s\n", NPRTB(info->plugin_date)); fprintf(fp, "\tmagic=%s\n", NPRTB(info->plugin_magic)); @@ -334,7 +334,7 @@ int ListDirPlugins(PoolMem& msg) { return ListPlugins(dird_plugin_list, msg); } */ static bool IsPluginCompatible(Plugin* plugin) { - genpInfo* info = (genpInfo*)plugin->pinfo; + PluginInformation* info = (PluginInformation*)plugin->pinfo; Dmsg0(50, "IsPluginCompatible called\n"); if (debug_level >= 50) { DumpDirPlugin(plugin, stdin); } @@ -364,10 +364,10 @@ static bool IsPluginCompatible(Plugin* plugin) plugin->file, info->plugin_license); return false; } - if (info->size != sizeof(genpInfo)) { + if (info->size != sizeof(PluginInformation)) { Jmsg(NULL, M_ERROR, 0, _("Plugin size incorrect. Plugin=%s wanted=%d got=%d\n"), plugin->file, - sizeof(genpInfo), info->size); + sizeof(PluginInformation), info->size); return false; } diff --git a/core/src/dird/dir_plugins.h b/core/src/dird/dir_plugins.h index 5fdc6f9790e..f2e545a7f6a 100644 --- a/core/src/dird/dir_plugins.h +++ b/core/src/dird/dir_plugins.h @@ -200,7 +200,7 @@ typedef struct s_dirpluginFuncs { } pDirFuncs; #define DirplugFunc(plugin) ((pDirFuncs*)(plugin->pfuncs)) -#define dirplug_info(plugin) ((genpInfo*)(plugin->pinfo)) +#define dirplug_info(plugin) ((PluginInformation*)(plugin->pinfo)) #ifdef __cplusplus } diff --git a/core/src/filed/fd_plugins.cc b/core/src/filed/fd_plugins.cc index 9f815e900bf..d4bb86c8868 100644 --- a/core/src/filed/fd_plugins.cc +++ b/core/src/filed/fd_plugins.cc @@ -1684,11 +1684,11 @@ BxattrExitCode PluginParseXattrStreams(JobControlRecord* jcr, */ static void DumpFdPlugin(Plugin* plugin, FILE* fp) { - genpInfo* info; + PluginInformation* info; if (!plugin) { return; } - info = (genpInfo*)plugin->pinfo; + info = (PluginInformation*)plugin->pinfo; fprintf(fp, "\tversion=%d\n", info->version); fprintf(fp, "\tdate=%s\n", NPRTB(info->plugin_date)); fprintf(fp, "\tmagic=%s\n", NPRTB(info->plugin_magic)); @@ -1764,7 +1764,7 @@ int ListFdPlugins(PoolMem& msg) { return ListPlugins(fd_plugin_list, msg); } */ static bool IsPluginCompatible(Plugin* plugin) { - genpInfo* info = (genpInfo*)plugin->pinfo; + PluginInformation* info = (PluginInformation*)plugin->pinfo; Dmsg0(debuglevel, "IsPluginCompatible called\n"); if (debug_level >= 50) { DumpFdPlugin(plugin, stdin); } if (!bstrcmp(info->plugin_magic, FD_PLUGIN_MAGIC)) { @@ -1793,10 +1793,10 @@ static bool IsPluginCompatible(Plugin* plugin) plugin->file, info->plugin_license); return false; } - if (info->size != sizeof(genpInfo)) { + if (info->size != sizeof(PluginInformation)) { Jmsg(NULL, M_ERROR, 0, _("Plugin size incorrect. Plugin=%s wanted=%d got=%d\n"), plugin->file, - sizeof(genpInfo), info->size); + sizeof(PluginInformation), info->size); return false; } diff --git a/core/src/filed/fd_plugins.h b/core/src/filed/fd_plugins.h index 69394930c3d..fb9eea4c190 100644 --- a/core/src/filed/fd_plugins.h +++ b/core/src/filed/fd_plugins.h @@ -398,7 +398,7 @@ typedef struct s_pluginFuncs { } pFuncs; #define PlugFunc(plugin) ((pFuncs*)(plugin->pfuncs)) -#define plug_info(plugin) ((genpInfo*)(plugin->pinfo)) +#define plug_info(plugin) ((PluginInformation*)(plugin->pinfo)) #ifdef __cplusplus } diff --git a/core/src/lib/plugins.cc b/core/src/lib/plugins.cc index 5f1c59a293c..a5a53d30c14 100644 --- a/core/src/lib/plugins.cc +++ b/core/src/lib/plugins.cc @@ -374,7 +374,7 @@ int ListPlugins(alist* plugin_list, PoolMem& msg) PmStrcat(msg, " Plugin : "); len = PmStrcat(msg, plugin->file); if (plugin->pinfo) { - genpInfo* info = (genpInfo*)plugin->pinfo; + PluginInformation* info = (PluginInformation*)plugin->pinfo; PmStrcat(msg, "\n"); PmStrcat(msg, " Description: "); PmStrcat(msg, NPRT(info->plugin_description)); diff --git a/core/src/lib/plugins.h b/core/src/lib/plugins.h index 83d72b92b28..9252d2589be 100644 --- a/core/src/lib/plugins.h +++ b/core/src/lib/plugins.h @@ -96,7 +96,7 @@ typedef struct gen_pluginInfo { const char* plugin_version; const char* plugin_description; const char* plugin_usage; -} genpInfo; +} PluginInformation; class alist; diff --git a/core/src/plugins/dird/example/example-plugin-dir.cc b/core/src/plugins/dird/example/example-plugin-dir.cc index c2a7f455c9a..b76077f91e7 100644 --- a/core/src/plugins/dird/example/example-plugin-dir.cc +++ b/core/src/plugins/dird/example/example-plugin-dir.cc @@ -49,10 +49,11 @@ static bRC handlePluginEvent(bpContext* ctx, bDirEvent* event, void* value); static bDirFuncs* bareos_core_functions = NULL; static bDirInfo* bareos_plugin_interface_version = NULL; -static genpInfo pluginInfo = {sizeof(pluginInfo), DIR_PLUGIN_INTERFACE_VERSION, - DIR_PLUGIN_MAGIC, PLUGIN_LICENSE, - PLUGIN_AUTHOR, PLUGIN_DATE, - PLUGIN_VERSION, PLUGIN_DESCRIPTION}; +static PluginInformation pluginInfo = { + sizeof(pluginInfo), DIR_PLUGIN_INTERFACE_VERSION, + DIR_PLUGIN_MAGIC, PLUGIN_LICENSE, + PLUGIN_AUTHOR, PLUGIN_DATE, + PLUGIN_VERSION, PLUGIN_DESCRIPTION}; static pDirFuncs pluginFuncs = { sizeof(pluginFuncs), DIR_PLUGIN_INTERFACE_VERSION, @@ -75,7 +76,7 @@ extern "C" { */ bRC loadPlugin(bDirInfo* lbareos_plugin_interface_version, bDirFuncs* lbareos_core_functions, - genpInfo** pinfo, + PluginInformation** pinfo, pDirFuncs** pfuncs) { bareos_core_functions = diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index b9b673cbd03..e90655fc1d5 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -90,11 +90,12 @@ static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, static bDirFuncs* bareos_core_functions = NULL; static bDirInfo* bareos_plugin_interface_version = NULL; -static genpInfo pluginInfo = {sizeof(pluginInfo), DIR_PLUGIN_INTERFACE_VERSION, - DIR_PLUGIN_MAGIC, PLUGIN_LICENSE, - PLUGIN_AUTHOR, PLUGIN_DATE, - PLUGIN_VERSION, PLUGIN_DESCRIPTION, - PLUGIN_USAGE}; +static PluginInformation pluginInfo = { + sizeof(pluginInfo), DIR_PLUGIN_INTERFACE_VERSION, + DIR_PLUGIN_MAGIC, PLUGIN_LICENSE, + PLUGIN_AUTHOR, PLUGIN_DATE, + PLUGIN_VERSION, PLUGIN_DESCRIPTION, + PLUGIN_USAGE}; static pDirFuncs pluginFuncs = { sizeof(pluginFuncs), DIR_PLUGIN_INTERFACE_VERSION, @@ -143,7 +144,7 @@ extern "C" { */ bRC loadPlugin(bDirInfo* lbareos_plugin_interface_version, bDirFuncs* lbareos_core_functions, - genpInfo** pinfo, + PluginInformation** pinfo, pDirFuncs** pfuncs) { bareos_core_functions = diff --git a/core/src/plugins/filed/bpipe/bpipe-fd.cc b/core/src/plugins/filed/bpipe/bpipe-fd.cc index e7ff6d1b20b..adae20512be 100644 --- a/core/src/plugins/filed/bpipe/bpipe-fd.cc +++ b/core/src/plugins/filed/bpipe/bpipe-fd.cc @@ -73,11 +73,12 @@ static BareosCoreFunctions* bareos_core_functions = NULL; static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; /* Plugin Information block */ -static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, - FD_PLUGIN_MAGIC, PLUGIN_LICENSE, - PLUGIN_AUTHOR, PLUGIN_DATE, - PLUGIN_VERSION, PLUGIN_DESCRIPTION, - PLUGIN_USAGE}; +static PluginInformation pluginInfo = { + sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, + FD_PLUGIN_MAGIC, PLUGIN_LICENSE, + PLUGIN_AUTHOR, PLUGIN_DATE, + PLUGIN_VERSION, PLUGIN_DESCRIPTION, + PLUGIN_USAGE}; /* Plugin entry points for Bareos */ static pFuncs pluginFuncs = { @@ -141,7 +142,7 @@ extern "C" { */ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - genpInfo** pinfo, + PluginInformation** pinfo, pFuncs** pfuncs) { bareos_core_functions = diff --git a/core/src/plugins/filed/cephfs/cephfs-fd.cc b/core/src/plugins/filed/cephfs/cephfs-fd.cc index 99374d8d101..3804943b10b 100644 --- a/core/src/plugins/filed/cephfs/cephfs-fd.cc +++ b/core/src/plugins/filed/cephfs/cephfs-fd.cc @@ -82,11 +82,12 @@ static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; /** * Plugin Information block */ -static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, - FD_PLUGIN_MAGIC, PLUGIN_LICENSE, - PLUGIN_AUTHOR, PLUGIN_DATE, - PLUGIN_VERSION, PLUGIN_DESCRIPTION, - PLUGIN_USAGE}; +static PluginInformation pluginInfo = { + sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, + FD_PLUGIN_MAGIC, PLUGIN_LICENSE, + PLUGIN_AUTHOR, PLUGIN_DATE, + PLUGIN_VERSION, PLUGIN_DESCRIPTION, + PLUGIN_USAGE}; /** * Plugin entry points for Bareos @@ -181,7 +182,7 @@ extern "C" { */ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - genpInfo** pinfo, + PluginInformation** pinfo, pFuncs** pfuncs) { bareos_core_functions = diff --git a/core/src/plugins/filed/example/example-plugin-fd.cc b/core/src/plugins/filed/example/example-plugin-fd.cc index ee5b75edd08..d1814c2ff40 100644 --- a/core/src/plugins/filed/example/example-plugin-fd.cc +++ b/core/src/plugins/filed/example/example-plugin-fd.cc @@ -49,10 +49,11 @@ static bRC setXattr(bpContext* ctx, xattr_pkt* xp); static BareosCoreFunctions* bareos_core_functions = NULL; static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; -static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, - FD_PLUGIN_MAGIC, PLUGIN_LICENSE, - PLUGIN_AUTHOR, PLUGIN_DATE, - PLUGIN_VERSION, PLUGIN_DESCRIPTION}; +static PluginInformation pluginInfo = { + sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, + FD_PLUGIN_MAGIC, PLUGIN_LICENSE, + PLUGIN_AUTHOR, PLUGIN_DATE, + PLUGIN_VERSION, PLUGIN_DESCRIPTION}; static pFuncs pluginFuncs = { sizeof(pluginFuncs), FD_PLUGIN_INTERFACE_VERSION, @@ -73,7 +74,7 @@ extern "C" { */ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - genpInfo** pinfo, + PluginInformation** pinfo, pFuncs** pfuncs) { bareos_core_functions = diff --git a/core/src/plugins/filed/gfapi/gfapi-fd.cc b/core/src/plugins/filed/gfapi/gfapi-fd.cc index 0f11760a115..9330f722211 100644 --- a/core/src/plugins/filed/gfapi/gfapi-fd.cc +++ b/core/src/plugins/filed/gfapi/gfapi-fd.cc @@ -97,11 +97,12 @@ static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; /** * Plugin Information block */ -static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, - FD_PLUGIN_MAGIC, PLUGIN_LICENSE, - PLUGIN_AUTHOR, PLUGIN_DATE, - PLUGIN_VERSION, PLUGIN_DESCRIPTION, - PLUGIN_USAGE}; +static PluginInformation pluginInfo = { + sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, + FD_PLUGIN_MAGIC, PLUGIN_LICENSE, + PLUGIN_AUTHOR, PLUGIN_DATE, + PLUGIN_VERSION, PLUGIN_DESCRIPTION, + PLUGIN_USAGE}; /** * Plugin entry points for Bareos @@ -315,7 +316,7 @@ extern "C" { */ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - genpInfo** pinfo, + PluginInformation** pinfo, pFuncs** pfuncs) { bareos_core_functions = diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 6afd8874528..0edb5c2d2c4 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -124,7 +124,7 @@ static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, static BareosCoreFunctions* bareos_core_functions = NULL; static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; -/* static genpInfo pluginInfo = {sizeof(pluginInfo), +/* static PluginInformation pluginInfo = {sizeof(pluginInfo), * FD_PLUGIN_INTERFACE_VERSION, */ /* FD_PLUGIN_MAGIC, PLUGIN_LICENSE, */ /* PLUGIN_AUTHOR, PLUGIN_DATE, */ @@ -220,7 +220,7 @@ static void PyErrorHandler() */ /* bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, */ /* BareosCoreFunctions* lbareos_core_functions, */ -/* genpInfo** pinfo, */ +/* PluginInformation** pinfo, */ /* pFuncs** pfuncs) */ /* { */ /* bareos_core_functions = lbareos_core_functions; /1* Set Bareos funct @@ -254,9 +254,9 @@ static void PyErrorHandler() /* filedaemon::Core_PluginApiDefinition * * lbareos_plugin_interface_version, filedaemon::BareosCoreFunctions * * lbareos_core_functions, */ -/* genpInfo * *pinfo, filedaemon::pFuncs * *pfuncs) = */ +/* PluginInformation * *pinfo, filedaemon::pFuncs * *pfuncs) = */ /* (void (*)(filedaemon::Core_PluginApiDefinition*, - * filedaemon::BareosCoreFunctions*, genpInfo**, */ + * filedaemon::BareosCoreFunctions*, PluginInformation**, */ /* filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", */ /* 0); */ @@ -286,11 +286,11 @@ static void PyErrorHandler() /* /1* call loadPlugin in plugin *1/ */ /* filedaemon::Core_PluginApiDefinition myInfo; */ -/* genpInfo pinfo; */ +/* PluginInformation pinfo; */ /* filedaemon::pFuncs pfuncs; */ /* loadplugin_from_bareosfd_module(&myInfo, bareos_core_functions, - * (genpInfo**)&pinfo, */ + * (PluginInformation**)&pinfo, */ /* (filedaemon::pFuncs**)&pfuncs); */ diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 4942fbdd0c1..74b71c9cac2 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -123,11 +123,12 @@ static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, static BareosCoreFunctions* bareos_core_functions = NULL; static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; -static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, - FD_PLUGIN_MAGIC, PLUGIN_LICENSE, - PLUGIN_AUTHOR, PLUGIN_DATE, - PLUGIN_VERSION, PLUGIN_DESCRIPTION, - PLUGIN_USAGE}; +static PluginInformation pluginInfo = { + sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, + FD_PLUGIN_MAGIC, PLUGIN_LICENSE, + PLUGIN_AUTHOR, PLUGIN_DATE, + PLUGIN_VERSION, PLUGIN_DESCRIPTION, + PLUGIN_USAGE}; static pFuncs pluginFuncs = { sizeof(pluginFuncs), FD_PLUGIN_INTERFACE_VERSION, @@ -218,7 +219,7 @@ static void PyErrorHandler() */ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - genpInfo** pinfo, + PluginInformation** pinfo, pFuncs** pfuncs) { bareos_core_functions = @@ -251,9 +252,9 @@ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, void (*loadplugin_from_bareosfd_module)( filedaemon::Core_PluginApiDefinition * lbareos_plugin_interface_version, filedaemon::BareosCoreFunctions * lbareos_core_functions, - genpInfo * *pinfo, filedaemon::pFuncs * *pfuncs) = + PluginInformation * *pinfo, filedaemon::pFuncs * *pfuncs) = (void (*)(filedaemon::Core_PluginApiDefinition*, - filedaemon::BareosCoreFunctions*, genpInfo**, + filedaemon::BareosCoreFunctions*, PluginInformation**, filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", 0); @@ -281,11 +282,11 @@ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, /* call loadPlugin in plugin */ filedaemon::Core_PluginApiDefinition myInfo; - genpInfo pinfo; + PluginInformation pinfo; filedaemon::pFuncs pfuncs; loadplugin_from_bareosfd_module(&myInfo, bareos_core_functions, - (genpInfo**)&pinfo, + (PluginInformation**)&pinfo, (filedaemon::pFuncs**)&pfuncs); diff --git a/core/src/plugins/filed/python/python-fd.h b/core/src/plugins/filed/python/python-fd.h index c1c8296e311..45114fad695 100644 --- a/core/src/plugins/filed/python/python-fd.h +++ b/core/src/plugins/filed/python/python-fd.h @@ -764,7 +764,7 @@ extern "C" { /* Forward declaration of loadPlugin() as it is stored in Capsule */ bRC loadPlugin(::Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - genpInfo** pinfo, + PluginInformation** pinfo, pFuncs** pfuncs); #ifdef __cplusplus } diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index bf40ac6931e..b35fa9cabe9 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -208,9 +208,9 @@ int main(int argc, char* argv[]) void (*loadplugin_from_bareosfd_module)( filedaemon::Core_PluginApiDefinition * lbareos_plugin_interface_version, filedaemon::BareosCoreFunctions * lbareos_core_functions, - genpInfo * *pinfo, filedaemon::pFuncs * *pfuncs) = + PluginInformation * *pinfo, filedaemon::pFuncs * *pfuncs) = (void (*)(filedaemon::Core_PluginApiDefinition*, - filedaemon::BareosCoreFunctions*, genpInfo**, + filedaemon::BareosCoreFunctions*, PluginInformation**, filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", 0); @@ -235,11 +235,11 @@ int main(int argc, char* argv[]) /* call loadPlugin in plugin */ filedaemon::Core_PluginApiDefinition myInfo; - genpInfo pinfo; + PluginInformation pinfo; filedaemon::pFuncs pfuncs; loadplugin_from_bareosfd_module(&myInfo, &bareos_core_functions, - (genpInfo**)&pinfo, + (PluginInformation**)&pinfo, (filedaemon::pFuncs**)&pfuncs); diff --git a/core/src/plugins/filed/rados/rados-fd.cc b/core/src/plugins/filed/rados/rados-fd.cc index c605e37db3d..dc223e2e1c8 100644 --- a/core/src/plugins/filed/rados/rados-fd.cc +++ b/core/src/plugins/filed/rados/rados-fd.cc @@ -90,11 +90,12 @@ static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; /** * Plugin Information block */ -static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, - FD_PLUGIN_MAGIC, PLUGIN_LICENSE, - PLUGIN_AUTHOR, PLUGIN_DATE, - PLUGIN_VERSION, PLUGIN_DESCRIPTION, - PLUGIN_USAGE}; +static PluginInformation pluginInfo = { + sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, + FD_PLUGIN_MAGIC, PLUGIN_LICENSE, + PLUGIN_AUTHOR, PLUGIN_DATE, + PLUGIN_VERSION, PLUGIN_DESCRIPTION, + PLUGIN_USAGE}; /** * Plugin entry points for Bareos @@ -180,7 +181,7 @@ extern "C" { */ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - genpInfo** pinfo, + PluginInformation** pinfo, pFuncs** pfuncs) { bareos_core_functions = diff --git a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc index a507c73a134..4ecfdf113cc 100644 --- a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc +++ b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc @@ -58,10 +58,11 @@ static BareosCoreFunctions* bareos_core_functions = NULL; static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; /* Plugin Information block */ -static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, - FD_PLUGIN_MAGIC, PLUGIN_LICENSE, - PLUGIN_AUTHOR, PLUGIN_DATE, - PLUGIN_VERSION, PLUGIN_DESCRIPTION}; +static PluginInformation pluginInfo = { + sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, + FD_PLUGIN_MAGIC, PLUGIN_LICENSE, + PLUGIN_AUTHOR, PLUGIN_DATE, + PLUGIN_VERSION, PLUGIN_DESCRIPTION}; /* Plugin entry points for Bareos */ static pFuncs pluginFuncs = { @@ -118,7 +119,7 @@ extern "C" { */ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - genpInfo** pinfo, + PluginInformation** pinfo, pFuncs** pfuncs) { bareos_core_functions = diff --git a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc index f3a877ab8e9..bbad051b0d4 100644 --- a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc +++ b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc @@ -67,10 +67,11 @@ static BareosCoreFunctions* bareos_core_functions = NULL; static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; /* Plugin Information block */ -static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, - FD_PLUGIN_MAGIC, PLUGIN_LICENSE, - PLUGIN_AUTHOR, PLUGIN_DATE, - PLUGIN_VERSION, PLUGIN_DESCRIPTION}; +static PluginInformation pluginInfo = { + sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, + FD_PLUGIN_MAGIC, PLUGIN_LICENSE, + PLUGIN_AUTHOR, PLUGIN_DATE, + PLUGIN_VERSION, PLUGIN_DESCRIPTION}; /* Plugin entry points for Bareos */ static pFuncs pluginFuncs = { @@ -124,7 +125,7 @@ extern "C" { */ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - genpInfo** pinfo, + PluginInformation** pinfo, pFuncs** pfuncs) { bareos_core_functions = diff --git a/core/src/plugins/stored/autoxflate/autoxflate-sd.cc b/core/src/plugins/stored/autoxflate/autoxflate-sd.cc index c0e4338da0e..00ffacd0d11 100644 --- a/core/src/plugins/stored/autoxflate/autoxflate-sd.cc +++ b/core/src/plugins/stored/autoxflate/autoxflate-sd.cc @@ -92,11 +92,12 @@ static bool sd_enabled_compatible = false; static bsdFuncs* bareos_core_functions = NULL; static bsdInfo* bareos_plugin_interface_version = NULL; -static genpInfo pluginInfo = {sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, - SD_PLUGIN_MAGIC, PLUGIN_LICENSE, - PLUGIN_AUTHOR, PLUGIN_DATE, - PLUGIN_VERSION, PLUGIN_DESCRIPTION, - PLUGIN_USAGE}; +static PluginInformation pluginInfo = { + sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, + SD_PLUGIN_MAGIC, PLUGIN_LICENSE, + PLUGIN_AUTHOR, PLUGIN_DATE, + PLUGIN_VERSION, PLUGIN_DESCRIPTION, + PLUGIN_USAGE}; static psdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, @@ -136,7 +137,7 @@ extern "C" { */ bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, bsdFuncs* lbareos_core_functions, - genpInfo** pinfo, + PluginInformation** pinfo, psdFuncs** pfuncs) { bareos_core_functions = diff --git a/core/src/plugins/stored/example/example-plugin-sd.cc b/core/src/plugins/stored/example/example-plugin-sd.cc index 057dafa037d..7bb2108ffe7 100644 --- a/core/src/plugins/stored/example/example-plugin-sd.cc +++ b/core/src/plugins/stored/example/example-plugin-sd.cc @@ -47,10 +47,11 @@ static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value); static bsdFuncs* bareos_core_functions = NULL; static bsdInfo* bareos_plugin_interface_version = NULL; -static genpInfo pluginInfo = {sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, - SD_PLUGIN_MAGIC, PLUGIN_LICENSE, - PLUGIN_AUTHOR, PLUGIN_DATE, - PLUGIN_VERSION, PLUGIN_DESCRIPTION}; +static PluginInformation pluginInfo = { + sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, + SD_PLUGIN_MAGIC, PLUGIN_LICENSE, + PLUGIN_AUTHOR, PLUGIN_DATE, + PLUGIN_VERSION, PLUGIN_DESCRIPTION}; static psdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, @@ -73,7 +74,7 @@ extern "C" { */ bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, bsdFuncs* lbareos_core_functions, - genpInfo** pinfo, + PluginInformation** pinfo, psdFuncs** pfuncs) { bareos_core_functions = diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index eddf3c1c174..c20b4f30365 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -90,11 +90,12 @@ static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, static bsdFuncs* bareos_core_functions = NULL; static bsdInfo* bareos_plugin_interface_version = NULL; -static genpInfo pluginInfo = {sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, - SD_PLUGIN_MAGIC, PLUGIN_LICENSE, - PLUGIN_AUTHOR, PLUGIN_DATE, - PLUGIN_VERSION, PLUGIN_DESCRIPTION, - PLUGIN_USAGE}; +static PluginInformation pluginInfo = { + sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, + SD_PLUGIN_MAGIC, PLUGIN_LICENSE, + PLUGIN_AUTHOR, PLUGIN_DATE, + PLUGIN_VERSION, PLUGIN_DESCRIPTION, + PLUGIN_USAGE}; static psdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, @@ -142,7 +143,7 @@ extern "C" { */ bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, bsdFuncs* lbareos_core_functions, - genpInfo** pinfo, + PluginInformation** pinfo, psdFuncs** pfuncs) { bareos_core_functions = diff --git a/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc b/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc index a6452390975..410970f77b6 100644 --- a/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc +++ b/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc @@ -97,11 +97,12 @@ static bRC send_volume_encryption_status(void* value); static bsdFuncs* bareos_core_functions = NULL; static bsdInfo* bareos_plugin_interface_version = NULL; -static genpInfo pluginInfo = {sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, - SD_PLUGIN_MAGIC, PLUGIN_LICENSE, - PLUGIN_AUTHOR, PLUGIN_DATE, - PLUGIN_VERSION, PLUGIN_DESCRIPTION, - PLUGIN_USAGE}; +static PluginInformation pluginInfo = { + sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, + SD_PLUGIN_MAGIC, PLUGIN_LICENSE, + PLUGIN_AUTHOR, PLUGIN_DATE, + PLUGIN_VERSION, PLUGIN_DESCRIPTION, + PLUGIN_USAGE}; static psdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, @@ -128,7 +129,7 @@ extern "C" { */ bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, bsdFuncs* lbareos_core_functions, - genpInfo** pinfo, + PluginInformation** pinfo, psdFuncs** pfuncs) { bareos_core_functions = diff --git a/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc b/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc index 59262e6d0fd..f5ea8ba2140 100644 --- a/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc +++ b/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc @@ -56,11 +56,12 @@ static bRC handle_tapealert_readout(void* value); static bsdFuncs* bareos_core_functions = NULL; static bsdInfo* bareos_plugin_interface_version = NULL; -static genpInfo pluginInfo = {sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, - SD_PLUGIN_MAGIC, PLUGIN_LICENSE, - PLUGIN_AUTHOR, PLUGIN_DATE, - PLUGIN_VERSION, PLUGIN_DESCRIPTION, - PLUGIN_USAGE}; +static PluginInformation pluginInfo = { + sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, + SD_PLUGIN_MAGIC, PLUGIN_LICENSE, + PLUGIN_AUTHOR, PLUGIN_DATE, + PLUGIN_VERSION, PLUGIN_DESCRIPTION, + PLUGIN_USAGE}; static psdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, @@ -87,7 +88,7 @@ extern "C" { */ bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, bsdFuncs* lbareos_core_functions, - genpInfo** pinfo, + PluginInformation** pinfo, psdFuncs** pfuncs) { bareos_core_functions = diff --git a/core/src/stored/sd_plugins.cc b/core/src/stored/sd_plugins.cc index 7554f6d7513..e878e32f247 100644 --- a/core/src/stored/sd_plugins.cc +++ b/core/src/stored/sd_plugins.cc @@ -378,11 +378,11 @@ bRC GeneratePluginEvent(JobControlRecord* jcr, */ void DumpSdPlugin(Plugin* plugin, FILE* fp) { - genpInfo* info; + PluginInformation* info; if (!plugin) { return; } - info = (genpInfo*)plugin->pinfo; + info = (PluginInformation*)plugin->pinfo; fprintf(fp, "\tversion=%d\n", info->version); fprintf(fp, "\tdate=%s\n", NPRTB(info->plugin_date)); fprintf(fp, "\tmagic=%s\n", NPRTB(info->plugin_magic)); @@ -449,7 +449,7 @@ int ListSdPlugins(PoolMem& msg) { return ListPlugins(sd_plugin_list, msg); } */ static bool IsPluginCompatible(Plugin* plugin) { - genpInfo* info = (genpInfo*)plugin->pinfo; + PluginInformation* info = (PluginInformation*)plugin->pinfo; Dmsg0(50, "IsPluginCompatible called\n"); if (debug_level >= 50) { DumpSdPlugin(plugin, stdin); } if (!bstrcmp(info->plugin_magic, SD_PLUGIN_MAGIC)) { @@ -478,10 +478,10 @@ static bool IsPluginCompatible(Plugin* plugin) plugin->file, info->plugin_license); return false; } - if (info->size != sizeof(genpInfo)) { + if (info->size != sizeof(PluginInformation)) { Jmsg(NULL, M_ERROR, 0, _("Plugin size incorrect. Plugin=%s wanted=%d got=%d\n"), plugin->file, - sizeof(genpInfo), info->size); + sizeof(PluginInformation), info->size); return false; } diff --git a/core/src/stored/sd_plugins.h b/core/src/stored/sd_plugins.h index 64dfc345b22..7780195807b 100644 --- a/core/src/stored/sd_plugins.h +++ b/core/src/stored/sd_plugins.h @@ -219,7 +219,7 @@ typedef struct s_sdpluginFuncs { } psdFuncs; #define SdplugFunc(plugin) ((psdFuncs*)(plugin->pfuncs)) -#define sdplug_info(plugin) ((genpInfo*)(plugin->pinfo)) +#define sdplug_info(plugin) ((PluginInformation*)(plugin->pinfo)) #ifdef __cplusplus } diff --git a/core/src/win32/plugins/filed/mssqlvdi-fd.cc b/core/src/win32/plugins/filed/mssqlvdi-fd.cc index cf0a55dbf7f..601e2dd7bbf 100644 --- a/core/src/win32/plugins/filed/mssqlvdi-fd.cc +++ b/core/src/win32/plugins/filed/mssqlvdi-fd.cc @@ -118,11 +118,12 @@ static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; /** * Plugin Information block */ -static genpInfo pluginInfo = {sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, - FD_PLUGIN_MAGIC, PLUGIN_LICENSE, - PLUGIN_AUTHOR, PLUGIN_DATE, - PLUGIN_VERSION, PLUGIN_DESCRIPTION, - PLUGIN_USAGE}; +static PluginInformation pluginInfo = { + sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, + FD_PLUGIN_MAGIC, PLUGIN_LICENSE, + PLUGIN_AUTHOR, PLUGIN_DATE, + PLUGIN_VERSION, PLUGIN_DESCRIPTION, + PLUGIN_USAGE}; /** * Plugin entry points for Bareos @@ -229,7 +230,7 @@ extern "C" { */ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - genpInfo** pinfo, + PluginInformation** pinfo, pFuncs** pfuncs) { bareos_core_functions = From ec0d5236f2741ea50813178fbfe1ac6ff9a10a99 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 30 Apr 2020 09:13:28 +0200 Subject: [PATCH 064/341] plugins: rename pfuncs -> plugin_functions, pHandle -> plugin_handle, pinfo -> plugin_information --- core/src/dird/dir_plugins.cc | 4 +- core/src/dird/dir_plugins.h | 4 +- core/src/filed/fd_plugins.cc | 4 +- core/src/filed/fd_plugins.h | 4 +- core/src/lib/plugins.cc | 23 ++-- core/src/lib/plugins.h | 10 +- .../dird/example/example-plugin-dir.cc | 8 +- core/src/plugins/dird/python/python-dir.cc | 8 +- core/src/plugins/filed/bpipe/bpipe-fd.cc | 8 +- core/src/plugins/filed/cephfs/cephfs-fd.cc | 8 +- .../filed/example/example-plugin-fd.cc | 8 +- core/src/plugins/filed/gfapi/gfapi-fd.cc | 8 +- core/src/plugins/filed/python/bareosfd.cc | 21 +-- core/src/plugins/filed/python/python-fd.cc | 19 +-- core/src/plugins/filed/python/python-fd.h | 4 +- .../python/test/python-fd-module-tester.cc | 11 +- core/src/plugins/filed/rados/rados-fd.cc | 8 +- .../filed/test-deltaseq/test-deltaseq-fd.cc | 8 +- .../filed/test-plugin/test-plugin-fd.cc | 8 +- .../stored/autoxflate/autoxflate-sd.cc | 8 +- .../stored/example/example-plugin-sd.cc | 8 +- core/src/plugins/stored/python/python-sd.cc | 8 +- .../stored/scsicrypto/scsicrypto-sd.cc | 8 +- .../stored/scsitapealert/scsitapealert-sd.cc | 8 +- core/src/stored/sd_plugins.cc | 4 +- core/src/stored/sd_plugins.h | 4 +- core/src/tools/bpluginfo.cc | 126 +++++++++++------- core/src/win32/plugins/filed/mssqlvdi-fd.cc | 8 +- 28 files changed, 197 insertions(+), 161 deletions(-) diff --git a/core/src/dird/dir_plugins.cc b/core/src/dird/dir_plugins.cc index cf4a922b6ab..5b13ae78900 100644 --- a/core/src/dird/dir_plugins.cc +++ b/core/src/dird/dir_plugins.cc @@ -267,7 +267,7 @@ void DumpDirPlugin(Plugin* plugin, FILE* fp) if (!plugin) { return; } - info = (PluginInformation*)plugin->pinfo; + info = (PluginInformation*)plugin->plugin_information; fprintf(fp, "\tversion=%d\n", info->version); fprintf(fp, "\tdate=%s\n", NPRTB(info->plugin_date)); fprintf(fp, "\tmagic=%s\n", NPRTB(info->plugin_magic)); @@ -334,7 +334,7 @@ int ListDirPlugins(PoolMem& msg) { return ListPlugins(dird_plugin_list, msg); } */ static bool IsPluginCompatible(Plugin* plugin) { - PluginInformation* info = (PluginInformation*)plugin->pinfo; + PluginInformation* info = (PluginInformation*)plugin->plugin_information; Dmsg0(50, "IsPluginCompatible called\n"); if (debug_level >= 50) { DumpDirPlugin(plugin, stdin); } diff --git a/core/src/dird/dir_plugins.h b/core/src/dird/dir_plugins.h index f2e545a7f6a..76396b35999 100644 --- a/core/src/dird/dir_plugins.h +++ b/core/src/dird/dir_plugins.h @@ -199,8 +199,8 @@ typedef struct s_dirpluginFuncs { bRC (*handlePluginEvent)(bpContext* ctx, bDirEvent* event, void* value); } pDirFuncs; -#define DirplugFunc(plugin) ((pDirFuncs*)(plugin->pfuncs)) -#define dirplug_info(plugin) ((PluginInformation*)(plugin->pinfo)) +#define DirplugFunc(plugin) ((pDirFuncs*)(plugin->plugin_functions)) +#define dirplug_info(plugin) ((PluginInformation*)(plugin->plugin_information)) #ifdef __cplusplus } diff --git a/core/src/filed/fd_plugins.cc b/core/src/filed/fd_plugins.cc index d4bb86c8868..422cf8765ac 100644 --- a/core/src/filed/fd_plugins.cc +++ b/core/src/filed/fd_plugins.cc @@ -1688,7 +1688,7 @@ static void DumpFdPlugin(Plugin* plugin, FILE* fp) if (!plugin) { return; } - info = (PluginInformation*)plugin->pinfo; + info = (PluginInformation*)plugin->plugin_information; fprintf(fp, "\tversion=%d\n", info->version); fprintf(fp, "\tdate=%s\n", NPRTB(info->plugin_date)); fprintf(fp, "\tmagic=%s\n", NPRTB(info->plugin_magic)); @@ -1764,7 +1764,7 @@ int ListFdPlugins(PoolMem& msg) { return ListPlugins(fd_plugin_list, msg); } */ static bool IsPluginCompatible(Plugin* plugin) { - PluginInformation* info = (PluginInformation*)plugin->pinfo; + PluginInformation* info = (PluginInformation*)plugin->plugin_information; Dmsg0(debuglevel, "IsPluginCompatible called\n"); if (debug_level >= 50) { DumpFdPlugin(plugin, stdin); } if (!bstrcmp(info->plugin_magic, FD_PLUGIN_MAGIC)) { diff --git a/core/src/filed/fd_plugins.h b/core/src/filed/fd_plugins.h index fb9eea4c190..ee2e2c2726d 100644 --- a/core/src/filed/fd_plugins.h +++ b/core/src/filed/fd_plugins.h @@ -397,8 +397,8 @@ typedef struct s_pluginFuncs { bRC (*setXattr)(bpContext* ctx, struct xattr_pkt* xp); } pFuncs; -#define PlugFunc(plugin) ((pFuncs*)(plugin->pfuncs)) -#define plug_info(plugin) ((PluginInformation*)(plugin->pinfo)) +#define PlugFunc(plugin) ((pFuncs*)(plugin->plugin_functions)) +#define plug_info(plugin) ((PluginInformation*)(plugin->plugin_information)) #ifdef __cplusplus } diff --git a/core/src/lib/plugins.cc b/core/src/lib/plugins.cc index a5a53d30c14..a242cd74cec 100644 --- a/core/src/lib/plugins.cc +++ b/core/src/lib/plugins.cc @@ -97,7 +97,7 @@ static void ClosePlugin(Plugin* plugin) Dmsg1(50, "Got plugin=%s but not accepted.\n", plugin->file); } if (plugin->unloadPlugin) { plugin->unloadPlugin(); } - if (plugin->pHandle) { dlclose(plugin->pHandle); } + if (plugin->plugin_handle) { dlclose(plugin->plugin_handle); } if (plugin->file) { free(plugin->file); } free(plugin); } @@ -121,9 +121,9 @@ static bool load_a_plugin(void* bareos_plugin_interface_version, plugin->file = strdup(plugin_name); plugin->file_len = strstr(plugin->file, type) - plugin->file; - plugin->pHandle = dlopen(plugin_pathname, LT_LAZY_OR_NOW | LT_GLOBAL); + plugin->plugin_handle = dlopen(plugin_pathname, LT_LAZY_OR_NOW | LT_GLOBAL); - if (!plugin->pHandle) { + if (!plugin->plugin_handle) { const char* error = dlerror(); Jmsg(NULL, M_ERROR, 0, _("dlopen plugin %s failed: ERR=%s\n"), @@ -139,7 +139,7 @@ static bool load_a_plugin(void* bareos_plugin_interface_version, /* * Get two global entry points */ - loadPlugin = (t_loadPlugin)dlsym(plugin->pHandle, "loadPlugin"); + loadPlugin = (t_loadPlugin)dlsym(plugin->plugin_handle, "loadPlugin"); if (!loadPlugin) { Jmsg(NULL, M_ERROR, 0, _("Lookup of loadPlugin in plugin %s failed: ERR=%s\n"), @@ -152,7 +152,8 @@ static bool load_a_plugin(void* bareos_plugin_interface_version, return false; } - plugin->unloadPlugin = (t_unloadPlugin)dlsym(plugin->pHandle, "unloadPlugin"); + plugin->unloadPlugin = + (t_unloadPlugin)dlsym(plugin->plugin_handle, "unloadPlugin"); if (!plugin->unloadPlugin) { Jmsg(NULL, M_ERROR, 0, _("Lookup of unloadPlugin in plugin %s failed: ERR=%s\n"), @@ -169,7 +170,8 @@ static bool load_a_plugin(void* bareos_plugin_interface_version, * Initialize the plugin */ if (loadPlugin(bareos_plugin_interface_version, bareos_core_functions, - &plugin->pinfo, &plugin->pfuncs) != bRC_OK) { + &plugin->plugin_information, + &plugin->plugin_functions) != bRC_OK) { ClosePlugin(plugin); return false; @@ -344,7 +346,7 @@ void UnloadPlugins(alist* plugin_list) * Shut it down and unload it */ plugin->unloadPlugin(); - dlclose(plugin->pHandle); + dlclose(plugin->plugin_handle); if (plugin->file) { free(plugin->file); } free(plugin); } @@ -356,7 +358,7 @@ void UnloadPlugin(alist* plugin_list, Plugin* plugin, int index) * Shut it down and unload it */ plugin->unloadPlugin(); - dlclose(plugin->pHandle); + dlclose(plugin->plugin_handle); if (plugin->file) { free(plugin->file); } plugin_list->remove(index); free(plugin); @@ -373,8 +375,9 @@ int ListPlugins(alist* plugin_list, PoolMem& msg) foreach_alist_index (i, plugin, plugin_list) { PmStrcat(msg, " Plugin : "); len = PmStrcat(msg, plugin->file); - if (plugin->pinfo) { - PluginInformation* info = (PluginInformation*)plugin->pinfo; + if (plugin->plugin_information) { + PluginInformation* info = + (PluginInformation*)plugin->plugin_information; PmStrcat(msg, "\n"); PmStrcat(msg, " Description: "); PmStrcat(msg, NPRT(info->plugin_description)); diff --git a/core/src/lib/plugins.h b/core/src/lib/plugins.h index 9252d2589be..07f022268c9 100644 --- a/core/src/lib/plugins.h +++ b/core/src/lib/plugins.h @@ -61,8 +61,8 @@ typedef enum extern "C" { typedef bRC (*t_loadPlugin)(void* bareos_plugin_interface_version, void* bareos_core_functions, - void** pinfo, - void** pfuncs); + void** plugin_information, + void** plugin_functions); typedef bRC (*t_unloadPlugin)(void); } @@ -71,9 +71,9 @@ class Plugin { char* file; int32_t file_len; t_unloadPlugin unloadPlugin; - void* pinfo; - void* pfuncs; - void* pHandle; + void* plugin_information; + void* plugin_functions; + void* plugin_handle; }; /** diff --git a/core/src/plugins/dird/example/example-plugin-dir.cc b/core/src/plugins/dird/example/example-plugin-dir.cc index b76077f91e7..0bf10f3c5ef 100644 --- a/core/src/plugins/dird/example/example-plugin-dir.cc +++ b/core/src/plugins/dird/example/example-plugin-dir.cc @@ -76,8 +76,8 @@ extern "C" { */ bRC loadPlugin(bDirInfo* lbareos_plugin_interface_version, bDirFuncs* lbareos_core_functions, - PluginInformation** pinfo, - pDirFuncs** pfuncs) + PluginInformation** plugin_information, + pDirFuncs** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ @@ -85,8 +85,8 @@ bRC loadPlugin(bDirInfo* lbareos_plugin_interface_version, printf("plugin: Loaded: size=%d version=%d\n", bareos_core_functions->size, bareos_core_functions->version); - *pinfo = &pluginInfo; /* return pointer to our info */ - *pfuncs = &pluginFuncs; /* return pointer to our functions */ + *plugin_information = &pluginInfo; /* return pointer to our info */ + *plugin_functions = &pluginFuncs; /* return pointer to our functions */ return bRC_OK; } diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index e90655fc1d5..534e42905ba 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -144,15 +144,15 @@ extern "C" { */ bRC loadPlugin(bDirInfo* lbareos_plugin_interface_version, bDirFuncs* lbareos_core_functions, - PluginInformation** pinfo, - pDirFuncs** pfuncs) + PluginInformation** plugin_information, + pDirFuncs** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* Set Bareos funct pointers */ bareos_plugin_interface_version = lbareos_plugin_interface_version; - *pinfo = &pluginInfo; /* Return pointer to our info */ - *pfuncs = &pluginFuncs; /* Return pointer to our functions */ + *plugin_information = &pluginInfo; /* Return pointer to our info */ + *plugin_functions = &pluginFuncs; /* Return pointer to our functions */ /* Setup Python */ #if PY_MAJOR_VERSION >= 3 diff --git a/core/src/plugins/filed/bpipe/bpipe-fd.cc b/core/src/plugins/filed/bpipe/bpipe-fd.cc index adae20512be..d71e132676e 100644 --- a/core/src/plugins/filed/bpipe/bpipe-fd.cc +++ b/core/src/plugins/filed/bpipe/bpipe-fd.cc @@ -142,14 +142,14 @@ extern "C" { */ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - PluginInformation** pinfo, - pFuncs** pfuncs) + PluginInformation** plugin_information, + pFuncs** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ bareos_plugin_interface_version = lbareos_plugin_interface_version; - *pinfo = &pluginInfo; /* return pointer to our info */ - *pfuncs = &pluginFuncs; /* return pointer to our functions */ + *plugin_information = &pluginInfo; /* return pointer to our info */ + *plugin_functions = &pluginFuncs; /* return pointer to our functions */ return bRC_OK; } diff --git a/core/src/plugins/filed/cephfs/cephfs-fd.cc b/core/src/plugins/filed/cephfs/cephfs-fd.cc index 3804943b10b..a0366eea9a2 100644 --- a/core/src/plugins/filed/cephfs/cephfs-fd.cc +++ b/core/src/plugins/filed/cephfs/cephfs-fd.cc @@ -182,14 +182,14 @@ extern "C" { */ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - PluginInformation** pinfo, - pFuncs** pfuncs) + PluginInformation** plugin_information, + pFuncs** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ bareos_plugin_interface_version = lbareos_plugin_interface_version; - *pinfo = &pluginInfo; /* return pointer to our info */ - *pfuncs = &pluginFuncs; /* return pointer to our functions */ + *plugin_information = &pluginInfo; /* return pointer to our info */ + *plugin_functions = &pluginFuncs; /* return pointer to our functions */ return bRC_OK; } diff --git a/core/src/plugins/filed/example/example-plugin-fd.cc b/core/src/plugins/filed/example/example-plugin-fd.cc index d1814c2ff40..2a8c3741bcc 100644 --- a/core/src/plugins/filed/example/example-plugin-fd.cc +++ b/core/src/plugins/filed/example/example-plugin-fd.cc @@ -74,8 +74,8 @@ extern "C" { */ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - PluginInformation** pinfo, - pFuncs** pfuncs) + PluginInformation** plugin_information, + pFuncs** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ @@ -83,8 +83,8 @@ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, printf("plugin: Loaded: size=%d version=%d\n", bareos_core_functions->size, bareos_core_functions->version); - *pinfo = &pluginInfo; /* return pointer to our info */ - *pfuncs = &pluginFuncs; /* return pointer to our functions */ + *plugin_information = &pluginInfo; /* return pointer to our info */ + *plugin_functions = &pluginFuncs; /* return pointer to our functions */ return bRC_OK; } diff --git a/core/src/plugins/filed/gfapi/gfapi-fd.cc b/core/src/plugins/filed/gfapi/gfapi-fd.cc index 9330f722211..744246fd877 100644 --- a/core/src/plugins/filed/gfapi/gfapi-fd.cc +++ b/core/src/plugins/filed/gfapi/gfapi-fd.cc @@ -316,14 +316,14 @@ extern "C" { */ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - PluginInformation** pinfo, - pFuncs** pfuncs) + PluginInformation** plugin_information, + pFuncs** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ bareos_plugin_interface_version = lbareos_plugin_interface_version; - *pinfo = &pluginInfo; /* return pointer to our info */ - *pfuncs = &pluginFuncs; /* return pointer to our functions */ + *plugin_information = &pluginInfo; /* return pointer to our info */ + *plugin_functions = &pluginFuncs; /* return pointer to our functions */ return bRC_OK; } diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 0edb5c2d2c4..69c25f26adb 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -220,15 +220,16 @@ static void PyErrorHandler() */ /* bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, */ /* BareosCoreFunctions* lbareos_core_functions, */ -/* PluginInformation** pinfo, */ -/* pFuncs** pfuncs) */ +/* PluginInformation** plugin_information, */ +/* pFuncs** plugin_functions) */ /* { */ /* bareos_core_functions = lbareos_core_functions; /1* Set Bareos funct * pointers *1/ */ /* bareos_plugin_interface_version = lbareos_plugin_interface_version; */ -/* *pinfo = &pluginInfo; /1* Return pointer to our info *1/ */ -/* *pfuncs = &pluginFuncs; /1* Return pointer to our functions *1/ */ +/* *plugin_information = &pluginInfo; /1* Return pointer to our info *1/ */ +/* *plugin_functions = &pluginFuncs; /1* Return pointer to our functions *1/ + */ /* if (!Py_IsInitialized()) { */ /* /1* Setup Python *1/ */ @@ -254,7 +255,8 @@ static void PyErrorHandler() /* filedaemon::Core_PluginApiDefinition * * lbareos_plugin_interface_version, filedaemon::BareosCoreFunctions * * lbareos_core_functions, */ -/* PluginInformation * *pinfo, filedaemon::pFuncs * *pfuncs) = */ +/* PluginInformation * *plugin_information, filedaemon::pFuncs * + * *plugin_functions) = */ /* (void (*)(filedaemon::Core_PluginApiDefinition*, * filedaemon::BareosCoreFunctions*, PluginInformation**, */ /* filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", @@ -286,12 +288,13 @@ static void PyErrorHandler() /* /1* call loadPlugin in plugin *1/ */ /* filedaemon::Core_PluginApiDefinition myInfo; */ -/* PluginInformation pinfo; */ -/* filedaemon::pFuncs pfuncs; */ +/* PluginInformation plugin_information; */ +/* filedaemon::pFuncs plugin_functions; */ /* loadplugin_from_bareosfd_module(&myInfo, bareos_core_functions, - * (PluginInformation**)&pinfo, */ -/* (filedaemon::pFuncs**)&pfuncs); */ + * (PluginInformation**)&plugin_information, */ +/* (filedaemon::pFuncs**)&plugin_functions); + */ /* printf("ctx_from_bareosfd_module contains %p\n", */ diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 74b71c9cac2..28caf7bdcfd 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -219,15 +219,15 @@ static void PyErrorHandler() */ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - PluginInformation** pinfo, - pFuncs** pfuncs) + PluginInformation** plugin_information, + pFuncs** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* Set Bareos funct pointers */ bareos_plugin_interface_version = lbareos_plugin_interface_version; - *pinfo = &pluginInfo; /* Return pointer to our info */ - *pfuncs = &pluginFuncs; /* Return pointer to our functions */ + *plugin_information = &pluginInfo; /* Return pointer to our info */ + *plugin_functions = &pluginFuncs; /* Return pointer to our functions */ if (!Py_IsInitialized()) { /* Setup Python */ @@ -252,7 +252,8 @@ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, void (*loadplugin_from_bareosfd_module)( filedaemon::Core_PluginApiDefinition * lbareos_plugin_interface_version, filedaemon::BareosCoreFunctions * lbareos_core_functions, - PluginInformation * *pinfo, filedaemon::pFuncs * *pfuncs) = + PluginInformation * *plugin_information, + filedaemon::pFuncs * *plugin_functions) = (void (*)(filedaemon::Core_PluginApiDefinition*, filedaemon::BareosCoreFunctions*, PluginInformation**, filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", @@ -282,12 +283,12 @@ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, /* call loadPlugin in plugin */ filedaemon::Core_PluginApiDefinition myInfo; - PluginInformation pinfo; - filedaemon::pFuncs pfuncs; + PluginInformation plugin_information; + filedaemon::pFuncs plugin_functions; loadplugin_from_bareosfd_module(&myInfo, bareos_core_functions, - (PluginInformation**)&pinfo, - (filedaemon::pFuncs**)&pfuncs); + (PluginInformation**)&plugin_information, + (filedaemon::pFuncs**)&plugin_functions); printf("ctx_from_bareosfd_module contains %p\n", diff --git a/core/src/plugins/filed/python/python-fd.h b/core/src/plugins/filed/python/python-fd.h index 45114fad695..0b89c2259bf 100644 --- a/core/src/plugins/filed/python/python-fd.h +++ b/core/src/plugins/filed/python/python-fd.h @@ -764,8 +764,8 @@ extern "C" { /* Forward declaration of loadPlugin() as it is stored in Capsule */ bRC loadPlugin(::Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - PluginInformation** pinfo, - pFuncs** pfuncs); + PluginInformation** plugin_information, + pFuncs** plugin_functions); #ifdef __cplusplus } #endif diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index b35fa9cabe9..22d569fd4c6 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -208,7 +208,8 @@ int main(int argc, char* argv[]) void (*loadplugin_from_bareosfd_module)( filedaemon::Core_PluginApiDefinition * lbareos_plugin_interface_version, filedaemon::BareosCoreFunctions * lbareos_core_functions, - PluginInformation * *pinfo, filedaemon::pFuncs * *pfuncs) = + PluginInformation * *plugin_information, + filedaemon::pFuncs * *plugin_functions) = (void (*)(filedaemon::Core_PluginApiDefinition*, filedaemon::BareosCoreFunctions*, PluginInformation**, filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", @@ -235,12 +236,12 @@ int main(int argc, char* argv[]) /* call loadPlugin in plugin */ filedaemon::Core_PluginApiDefinition myInfo; - PluginInformation pinfo; - filedaemon::pFuncs pfuncs; + PluginInformation plugin_information; + filedaemon::pFuncs plugin_functions; loadplugin_from_bareosfd_module(&myInfo, &bareos_core_functions, - (PluginInformation**)&pinfo, - (filedaemon::pFuncs**)&pfuncs); + (PluginInformation**)&plugin_information, + (filedaemon::pFuncs**)&plugin_functions); printf("ctx_from_bareosfd_module contains %p\n", diff --git a/core/src/plugins/filed/rados/rados-fd.cc b/core/src/plugins/filed/rados/rados-fd.cc index dc223e2e1c8..7b75b29926d 100644 --- a/core/src/plugins/filed/rados/rados-fd.cc +++ b/core/src/plugins/filed/rados/rados-fd.cc @@ -181,14 +181,14 @@ extern "C" { */ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - PluginInformation** pinfo, - pFuncs** pfuncs) + PluginInformation** plugin_information, + pFuncs** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ bareos_plugin_interface_version = lbareos_plugin_interface_version; - *pinfo = &pluginInfo; /* return pointer to our info */ - *pfuncs = &pluginFuncs; /* return pointer to our functions */ + *plugin_information = &pluginInfo; /* return pointer to our info */ + *plugin_functions = &pluginFuncs; /* return pointer to our functions */ return bRC_OK; } diff --git a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc index 4ecfdf113cc..e84d723b9e9 100644 --- a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc +++ b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc @@ -119,14 +119,14 @@ extern "C" { */ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - PluginInformation** pinfo, - pFuncs** pfuncs) + PluginInformation** plugin_information, + pFuncs** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ bareos_plugin_interface_version = lbareos_plugin_interface_version; - *pinfo = &pluginInfo; /* return pointer to our info */ - *pfuncs = &pluginFuncs; /* return pointer to our functions */ + *plugin_information = &pluginInfo; /* return pointer to our info */ + *plugin_functions = &pluginFuncs; /* return pointer to our functions */ /* Activate this plugin only in developer mode */ #ifdef DEVELOPER diff --git a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc index bbad051b0d4..47f102f70c0 100644 --- a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc +++ b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc @@ -125,14 +125,14 @@ extern "C" { */ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - PluginInformation** pinfo, - pFuncs** pfuncs) + PluginInformation** plugin_information, + pFuncs** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ bareos_plugin_interface_version = lbareos_plugin_interface_version; - *pinfo = &pluginInfo; /* return pointer to our info */ - *pfuncs = &pluginFuncs; /* return pointer to our functions */ + *plugin_information = &pluginInfo; /* return pointer to our info */ + *plugin_functions = &pluginFuncs; /* return pointer to our functions */ return bRC_OK; } diff --git a/core/src/plugins/stored/autoxflate/autoxflate-sd.cc b/core/src/plugins/stored/autoxflate/autoxflate-sd.cc index 00ffacd0d11..ddedbcccb02 100644 --- a/core/src/plugins/stored/autoxflate/autoxflate-sd.cc +++ b/core/src/plugins/stored/autoxflate/autoxflate-sd.cc @@ -137,14 +137,14 @@ extern "C" { */ bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, bsdFuncs* lbareos_core_functions, - PluginInformation** pinfo, - psdFuncs** pfuncs) + PluginInformation** plugin_information, + psdFuncs** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ bareos_plugin_interface_version = lbareos_plugin_interface_version; - *pinfo = &pluginInfo; /* return pointer to our info */ - *pfuncs = &pluginFuncs; /* return pointer to our functions */ + *plugin_information = &pluginInfo; /* return pointer to our info */ + *plugin_functions = &pluginFuncs; /* return pointer to our functions */ /* * Get the current setting of the compatible flag. diff --git a/core/src/plugins/stored/example/example-plugin-sd.cc b/core/src/plugins/stored/example/example-plugin-sd.cc index 7bb2108ffe7..17efc69a99d 100644 --- a/core/src/plugins/stored/example/example-plugin-sd.cc +++ b/core/src/plugins/stored/example/example-plugin-sd.cc @@ -74,16 +74,16 @@ extern "C" { */ bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, bsdFuncs* lbareos_core_functions, - PluginInformation** pinfo, - psdFuncs** pfuncs) + PluginInformation** plugin_information, + psdFuncs** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ bareos_plugin_interface_version = lbareos_plugin_interface_version; printf("example-plugin-sd: Loaded: size=%d version=%d\n", bareos_core_functions->size, bareos_core_functions->version); - *pinfo = &pluginInfo; /* return pointer to our info */ - *pfuncs = &pluginFuncs; /* return pointer to our functions */ + *plugin_information = &pluginInfo; /* return pointer to our info */ + *plugin_functions = &pluginFuncs; /* return pointer to our functions */ printf("example-plugin-sd: Loaded\n"); return bRC_OK; } diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index c20b4f30365..41e563ed9b7 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -143,15 +143,15 @@ extern "C" { */ bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, bsdFuncs* lbareos_core_functions, - PluginInformation** pinfo, - psdFuncs** pfuncs) + PluginInformation** plugin_information, + psdFuncs** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* Set Bareos funct pointers */ bareos_plugin_interface_version = lbareos_plugin_interface_version; - *pinfo = &pluginInfo; /* Return pointer to our info */ - *pfuncs = &pluginFuncs; /* Return pointer to our functions */ + *plugin_information = &pluginInfo; /* Return pointer to our info */ + *plugin_functions = &pluginFuncs; /* Return pointer to our functions */ /* Setup Python */ #if PY_MAJOR_VERSION >= 3 diff --git a/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc b/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc index 410970f77b6..8079692b525 100644 --- a/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc +++ b/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc @@ -129,16 +129,16 @@ extern "C" { */ bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, bsdFuncs* lbareos_core_functions, - PluginInformation** pinfo, - psdFuncs** pfuncs) + PluginInformation** plugin_information, + psdFuncs** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ bareos_plugin_interface_version = lbareos_plugin_interface_version; Dmsg2(debuglevel, "scsicrypto-sd: Loaded: size=%d version=%d\n", bareos_core_functions->size, bareos_core_functions->version); - *pinfo = &pluginInfo; /* return pointer to our info */ - *pfuncs = &pluginFuncs; /* return pointer to our functions */ + *plugin_information = &pluginInfo; /* return pointer to our info */ + *plugin_functions = &pluginFuncs; /* return pointer to our functions */ return bRC_OK; } diff --git a/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc b/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc index f5ea8ba2140..3d6f8243b19 100644 --- a/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc +++ b/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc @@ -88,16 +88,16 @@ extern "C" { */ bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, bsdFuncs* lbareos_core_functions, - PluginInformation** pinfo, - psdFuncs** pfuncs) + PluginInformation** plugin_information, + psdFuncs** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ bareos_plugin_interface_version = lbareos_plugin_interface_version; Dmsg2(debuglevel, "scsitapealert-sd: Loaded: size=%d version=%d\n", bareos_core_functions->size, bareos_core_functions->version); - *pinfo = &pluginInfo; /* return pointer to our info */ - *pfuncs = &pluginFuncs; /* return pointer to our functions */ + *plugin_information = &pluginInfo; /* return pointer to our info */ + *plugin_functions = &pluginFuncs; /* return pointer to our functions */ return bRC_OK; } diff --git a/core/src/stored/sd_plugins.cc b/core/src/stored/sd_plugins.cc index e878e32f247..db6cfee78f7 100644 --- a/core/src/stored/sd_plugins.cc +++ b/core/src/stored/sd_plugins.cc @@ -382,7 +382,7 @@ void DumpSdPlugin(Plugin* plugin, FILE* fp) if (!plugin) { return; } - info = (PluginInformation*)plugin->pinfo; + info = (PluginInformation*)plugin->plugin_information; fprintf(fp, "\tversion=%d\n", info->version); fprintf(fp, "\tdate=%s\n", NPRTB(info->plugin_date)); fprintf(fp, "\tmagic=%s\n", NPRTB(info->plugin_magic)); @@ -449,7 +449,7 @@ int ListSdPlugins(PoolMem& msg) { return ListPlugins(sd_plugin_list, msg); } */ static bool IsPluginCompatible(Plugin* plugin) { - PluginInformation* info = (PluginInformation*)plugin->pinfo; + PluginInformation* info = (PluginInformation*)plugin->plugin_information; Dmsg0(50, "IsPluginCompatible called\n"); if (debug_level >= 50) { DumpSdPlugin(plugin, stdin); } if (!bstrcmp(info->plugin_magic, SD_PLUGIN_MAGIC)) { diff --git a/core/src/stored/sd_plugins.h b/core/src/stored/sd_plugins.h index 7780195807b..5940f980412 100644 --- a/core/src/stored/sd_plugins.h +++ b/core/src/stored/sd_plugins.h @@ -218,8 +218,8 @@ typedef struct s_sdpluginFuncs { bRC (*handlePluginEvent)(bpContext* ctx, bsdEvent* event, void* value); } psdFuncs; -#define SdplugFunc(plugin) ((psdFuncs*)(plugin->pfuncs)) -#define sdplug_info(plugin) ((PluginInformation*)(plugin->pinfo)) +#define SdplugFunc(plugin) ((psdFuncs*)(plugin->plugin_functions)) +#define sdplug_info(plugin) ((PluginInformation*)(plugin->plugin_information)) #ifdef __cplusplus } diff --git a/core/src/tools/bpluginfo.cc b/core/src/tools/bpluginfo.cc index 3fce50d3f00..ea17169b127 100644 --- a/core/src/tools/bpluginfo.cc +++ b/core/src/tools/bpluginfo.cc @@ -49,8 +49,8 @@ extern "C" { typedef int (*loadPlugin)(void* bareos_plugin_interface_version, void* bareos_core_functions, - void** pinfo, - void** pfuncs); + void** plugin_information, + void** plugin_functions); typedef int (*unloadPlugin)(void); } #define DEFAULT_API_VERSION 1 @@ -125,8 +125,8 @@ struct _progdata { void* pluginhandle; int bapiversion; int bplugtype; - gen_pluginInfo* pinfo; - plugfuncs* pfuncs; + gen_pluginInfo* plugin_information; + plugfuncs* plugin_functions; }; /* memory allocation/deallocation */ @@ -316,18 +316,20 @@ int Getplugintype(progdata* pdata) { ASSERT_NVAL_RET_V(pdata, ERRORPLUGIN); - gen_pluginInfo* pinfo = pdata->pinfo; + gen_pluginInfo* plugin_information = pdata->plugin_information; - ASSERT_NVAL_RET_V(pinfo, ERRORPLUGIN); + ASSERT_NVAL_RET_V(plugin_information, ERRORPLUGIN); - if (pinfo->plugin_magic && bstrcmp(pinfo->plugin_magic, DIR_PLUGIN_MAGIC)) { + if (plugin_information->plugin_magic && + bstrcmp(plugin_information->plugin_magic, DIR_PLUGIN_MAGIC)) { return DIRPLUGIN; } else { - if (pinfo->plugin_magic && bstrcmp(pinfo->plugin_magic, FD_PLUGIN_MAGIC)) { + if (plugin_information->plugin_magic && + bstrcmp(plugin_information->plugin_magic, FD_PLUGIN_MAGIC)) { return FDPLUGIN; } else { - if (pinfo->plugin_magic && - bstrcmp(pinfo->plugin_magic, SD_PLUGIN_MAGIC)) { + if (plugin_information->plugin_magic && + bstrcmp(plugin_information->plugin_magic, SD_PLUGIN_MAGIC)) { return SDPLUGIN; } else { return ERRORPLUGIN; @@ -348,13 +350,13 @@ void DumpPluginfo(progdata* pdata) { ASSERT_NVAL_RET(pdata); - gen_pluginInfo* pinfo = pdata->pinfo; + gen_pluginInfo* plugin_information = pdata->plugin_information; - ASSERT_NVAL_RET(pinfo); + ASSERT_NVAL_RET(plugin_information); - plugfuncs* pfuncs = pdata->pfuncs; + plugfuncs* plugin_functions = pdata->plugin_functions; - ASSERT_NVAL_RET(pfuncs); + ASSERT_NVAL_RET(plugin_functions); switch (pdata->bplugtype) { case DIRPLUGIN: @@ -372,16 +374,17 @@ void DumpPluginfo(progdata* pdata) } if (pdata->verbose) { - printf("Plugin magic:\t\t%s\n", NPRT(pinfo->plugin_magic)); + printf("Plugin magic:\t\t%s\n", NPRT(plugin_information->plugin_magic)); } - printf("Plugin version:\t\t%s\n", pinfo->plugin_version); - printf("Plugin release date:\t%s\n", NPRT(pinfo->plugin_date)); - printf("Plugin author:\t\t%s\n", NPRT(pinfo->plugin_author)); - printf("Plugin licence:\t\t%s\n", NPRT(pinfo->plugin_license)); - printf("Plugin description:\t%s\n", NPRT(pinfo->plugin_description)); - printf("Plugin API version:\t%d\n", pinfo->version); - if (pinfo->plugin_usage) { - printf("Plugin usage:\n%s\n", pinfo->plugin_usage); + printf("Plugin version:\t\t%s\n", plugin_information->plugin_version); + printf("Plugin release date:\t%s\n", NPRT(plugin_information->plugin_date)); + printf("Plugin author:\t\t%s\n", NPRT(plugin_information->plugin_author)); + printf("Plugin licence:\t\t%s\n", NPRT(plugin_information->plugin_license)); + printf("Plugin description:\t%s\n", + NPRT(plugin_information->plugin_description)); + printf("Plugin API version:\t%d\n", plugin_information->version); + if (plugin_information->plugin_usage) { + printf("Plugin usage:\n%s\n", plugin_information->plugin_usage); } } @@ -397,55 +400,79 @@ void DumpPlugfuncs(progdata* pdata) { ASSERT_NVAL_RET(pdata); - plugfuncs* pfuncs = pdata->pfuncs; + plugfuncs* plugin_functions = pdata->plugin_functions; - ASSERT_NVAL_RET(pfuncs); + ASSERT_NVAL_RET(plugin_functions); printf("\nPlugin functions:\n"); switch (pdata->bplugtype) { case DIRPLUGIN: if (pdata->verbose) { - if (pfuncs->pdirfuncs.newPlugin) { printf(" newPlugin()\n"); } - if (pfuncs->pdirfuncs.freePlugin) { printf(" freePlugin()\n"); } + if (plugin_functions->pdirfuncs.newPlugin) { printf(" newPlugin()\n"); } + if (plugin_functions->pdirfuncs.freePlugin) { + printf(" freePlugin()\n"); + } } - if (pfuncs->pdirfuncs.getPluginValue) { printf(" getPluginValue()\n"); } - if (pfuncs->pdirfuncs.setPluginValue) { printf(" setPluginValue()\n"); } - if (pfuncs->pdirfuncs.handlePluginEvent) { + if (plugin_functions->pdirfuncs.getPluginValue) { + printf(" getPluginValue()\n"); + } + if (plugin_functions->pdirfuncs.setPluginValue) { + printf(" setPluginValue()\n"); + } + if (plugin_functions->pdirfuncs.handlePluginEvent) { printf(" handlePluginEvent()\n"); } break; case FDPLUGIN: if (pdata->verbose) { - if (pfuncs->pfdfuncs.newPlugin) { printf(" newPlugin()\n"); } - if (pfuncs->pfdfuncs.freePlugin) { printf(" freePlugin()\n"); } + if (plugin_functions->pfdfuncs.newPlugin) { printf(" newPlugin()\n"); } + if (plugin_functions->pfdfuncs.freePlugin) { + printf(" freePlugin()\n"); + } + } + if (plugin_functions->pfdfuncs.getPluginValue) { + printf(" getPluginValue()\n"); } - if (pfuncs->pfdfuncs.getPluginValue) { printf(" getPluginValue()\n"); } - if (pfuncs->pfdfuncs.setPluginValue) { printf(" setPluginValue()\n"); } - if (pfuncs->pfdfuncs.handlePluginEvent) { + if (plugin_functions->pfdfuncs.setPluginValue) { + printf(" setPluginValue()\n"); + } + if (plugin_functions->pfdfuncs.handlePluginEvent) { printf(" handlePluginEvent()\n"); } - if (pfuncs->pfdfuncs.startBackupFile) { printf(" startBackupFile()\n"); } - if (pfuncs->pfdfuncs.endBackupFile) { printf(" endBackupFile()\n"); } - if (pfuncs->pfdfuncs.startRestoreFile) { + if (plugin_functions->pfdfuncs.startBackupFile) { + printf(" startBackupFile()\n"); + } + if (plugin_functions->pfdfuncs.endBackupFile) { + printf(" endBackupFile()\n"); + } + if (plugin_functions->pfdfuncs.startRestoreFile) { printf(" startRestoreFile()\n"); } - if (pfuncs->pfdfuncs.endRestoreFile) { printf(" endRestoreFile()\n"); } - if (pfuncs->pfdfuncs.pluginIO) { printf(" pluginIO()\n"); } - if (pfuncs->pfdfuncs.createFile) { printf(" createFile()\n"); } - if (pfuncs->pfdfuncs.setFileAttributes) { + if (plugin_functions->pfdfuncs.endRestoreFile) { + printf(" endRestoreFile()\n"); + } + if (plugin_functions->pfdfuncs.pluginIO) { printf(" pluginIO()\n"); } + if (plugin_functions->pfdfuncs.createFile) { printf(" createFile()\n"); } + if (plugin_functions->pfdfuncs.setFileAttributes) { printf(" setFileAttributes()\n"); } - if (pfuncs->pfdfuncs.checkFile) { printf(" checkFile()\n"); } + if (plugin_functions->pfdfuncs.checkFile) { printf(" checkFile()\n"); } break; case SDPLUGIN: if (pdata->verbose) { - if (pfuncs->psdfuncs.newPlugin) { printf(" newPlugin()\n"); } - if (pfuncs->psdfuncs.freePlugin) { printf(" freePlugin()\n"); } + if (plugin_functions->psdfuncs.newPlugin) { printf(" newPlugin()\n"); } + if (plugin_functions->psdfuncs.freePlugin) { + printf(" freePlugin()\n"); + } + } + if (plugin_functions->psdfuncs.getPluginValue) { + printf(" getPluginValue()\n"); + } + if (plugin_functions->psdfuncs.setPluginValue) { + printf(" setPluginValue()\n"); } - if (pfuncs->psdfuncs.getPluginValue) { printf(" getPluginValue()\n"); } - if (pfuncs->psdfuncs.setPluginValue) { printf(" setPluginValue()\n"); } - if (pfuncs->psdfuncs.handlePluginEvent) { + if (plugin_functions->psdfuncs.handlePluginEvent) { printf(" handlePluginEvent()\n"); } break; @@ -518,7 +545,8 @@ int main(int argc, char* argv[]) } loadplugfunc(&bareos_plugin_interface_version, &bareos_core_functions, - (void**)&pdata->pinfo, (void**)&pdata->pfuncs); + (void**)&pdata->plugin_information, + (void**)&pdata->plugin_functions); pdata->bplugtype = Getplugintype(pdata); diff --git a/core/src/win32/plugins/filed/mssqlvdi-fd.cc b/core/src/win32/plugins/filed/mssqlvdi-fd.cc index 601e2dd7bbf..558e8e08bdb 100644 --- a/core/src/win32/plugins/filed/mssqlvdi-fd.cc +++ b/core/src/win32/plugins/filed/mssqlvdi-fd.cc @@ -230,14 +230,14 @@ extern "C" { */ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, - PluginInformation** pinfo, - pFuncs** pfuncs) + PluginInformation** plugin_information, + pFuncs** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ bareos_plugin_interface_version = lbareos_plugin_interface_version; - *pinfo = &pluginInfo; /* return pointer to our info */ - *pfuncs = &pluginFuncs; /* return pointer to our functions */ + *plugin_information = &pluginInfo; /* return pointer to our info */ + *plugin_functions = &pluginFuncs; /* return pointer to our functions */ return bRC_OK; } From fa338e639e09eaa074853d457505877a20b33c19 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 30 Apr 2020 09:21:29 +0200 Subject: [PATCH 065/341] plugins: rename bContext -> core_private_context, pContext -> plugin_private_context --- core/src/dird/dir_plugins.cc | 95 +++--- core/src/dird/dir_plugins.h | 36 +- core/src/filed/fd_plugins.cc | 195 ++++++----- core/src/filed/fd_plugins.h | 92 +++--- core/src/findlib/bfile.cc | 94 +++--- core/src/findlib/bfile.h | 8 +- core/src/include/jcr.h | 4 +- core/src/lib/plugins.h | 6 +- .../dird/example/example-plugin-dir.cc | 32 +- core/src/plugins/dird/python/python-dir.cc | 83 +++-- core/src/plugins/dird/python/python-dir.h | 12 +- core/src/plugins/filed/bpipe/bpipe-fd.cc | 128 ++++--- core/src/plugins/filed/cephfs/cephfs-fd.cc | 145 ++++---- .../filed/example/example-plugin-fd.cc | 97 ++++-- core/src/plugins/filed/gfapi/gfapi-fd.cc | 145 ++++---- core/src/plugins/filed/python/bareosfd.cc | 254 ++++++++------ core/src/plugins/filed/python/python-fd.cc | 312 ++++++++++-------- core/src/plugins/filed/python/python-fd.h | 14 +- .../python/test/python-fd-module-tester.cc | 74 +++-- core/src/plugins/filed/rados/rados-fd.cc | 140 ++++---- .../filed/test-deltaseq/test-deltaseq-fd.cc | 72 ++-- .../filed/test-plugin/test-plugin-fd.cc | 108 +++--- core/src/plugins/python_plugins_common.inc | 30 +- .../stored/autoxflate/autoxflate-sd.cc | 86 +++-- .../stored/example/example-plugin-sd.cc | 32 +- core/src/plugins/stored/python/python-sd.cc | 83 +++-- core/src/plugins/stored/python/python-sd.h | 12 +- .../stored/scsicrypto/scsicrypto-sd.cc | 32 +- .../stored/scsitapealert/scsitapealert-sd.cc | 32 +- core/src/stored/sd_plugins.cc | 95 +++--- core/src/stored/sd_plugins.h | 36 +- core/src/win32/plugins/filed/mssqlvdi-fd.cc | 155 +++++---- 32 files changed, 1621 insertions(+), 1118 deletions(-) diff --git a/core/src/dird/dir_plugins.cc b/core/src/dird/dir_plugins.cc index 5b13ae78900..5e9454ab1fd 100644 --- a/core/src/dird/dir_plugins.cc +++ b/core/src/dird/dir_plugins.cc @@ -46,19 +46,27 @@ static alist* dird_plugin_list; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; /* Forward referenced functions */ -static bRC bareosGetValue(bpContext* ctx, brDirVariable var, void* value); -static bRC bareosSetValue(bpContext* ctx, bwDirVariable var, void* value); -static bRC bareosRegisterEvents(bpContext* ctx, int nr_events, ...); -static bRC bareosUnRegisterEvents(bpContext* ctx, int nr_events, ...); -static bRC bareosGetInstanceCount(bpContext* ctx, int* ret); -static bRC bareosJobMsg(bpContext* ctx, +static bRC bareosGetValue(bplugin_private_context* ctx, + brDirVariable var, + void* value); +static bRC bareosSetValue(bplugin_private_context* ctx, + bwDirVariable var, + void* value); +static bRC bareosRegisterEvents(bplugin_private_context* ctx, + int nr_events, + ...); +static bRC bareosUnRegisterEvents(bplugin_private_context* ctx, + int nr_events, + ...); +static bRC bareosGetInstanceCount(bplugin_private_context* ctx, int* ret); +static bRC bareosJobMsg(bplugin_private_context* ctx, const char* file, int line, int type, utime_t mtime, const char* fmt, ...); -static bRC bareosDebugMsg(bpContext* ctx, +static bRC bareosDebugMsg(bplugin_private_context* ctx, const char* file, int line, int level, @@ -89,31 +97,32 @@ struct b_plugin_ctx { Plugin* plugin; /* pointer to plugin of which this is an instance off */ }; -static inline bool IsEventEnabled(bpContext* ctx, bDirEventType eventType) +static inline bool IsEventEnabled(bplugin_private_context* ctx, + bDirEventType eventType) { b_plugin_ctx* b_ctx; if (!ctx) { return false; } - b_ctx = (b_plugin_ctx*)ctx->bContext; + b_ctx = (b_plugin_ctx*)ctx->core_private_context; if (!b_ctx) { return false; } return BitIsSet(eventType, b_ctx->events); } -static inline bool IsPluginDisabled(bpContext* ctx) +static inline bool IsPluginDisabled(bplugin_private_context* ctx) { b_plugin_ctx* b_ctx; if (!ctx) { return true; } - b_ctx = (b_plugin_ctx*)ctx->bContext; + b_ctx = (b_plugin_ctx*)ctx->core_private_context; if (!b_ctx) { return true; } return b_ctx->disabled; } -static bool IsCtxGood(bpContext* ctx, +static bool IsCtxGood(bplugin_private_context* ctx, JobControlRecord*& jcr, b_plugin_ctx*& bctx) { if (!ctx) { return false; } - bctx = (b_plugin_ctx*)ctx->bContext; + bctx = (b_plugin_ctx*)ctx->core_private_context; if (!bctx) { return false; } jcr = bctx->jcr; @@ -125,7 +134,7 @@ static bool IsCtxGood(bpContext* ctx, static inline bool trigger_plugin_event(JobControlRecord* jcr, bDirEventType eventType, bDirEvent* event, - bpContext* ctx, + bplugin_private_context* ctx, void* value, alist* plugin_ctx_list, int* index, @@ -230,7 +239,7 @@ bRC GeneratePluginEvent(JobControlRecord* jcr, * See if we need to trigger the loaded plugins in reverse order. */ if (reverse) { - bpContext* ctx; + bplugin_private_context* ctx; foreach_alist_rindex (i, ctx, plugin_ctx_list) { if (trigger_plugin_event(jcr, eventType, &event, ctx, value, @@ -239,7 +248,7 @@ bRC GeneratePluginEvent(JobControlRecord* jcr, } } } else { - bpContext* ctx; + bplugin_private_context* ctx; foreach_alist_index (i, ctx, plugin_ctx_list) { if (trigger_plugin_event(jcr, eventType, &event, ctx, value, @@ -377,11 +386,11 @@ static bool IsPluginCompatible(Plugin* plugin) /** * Instantiate a new plugin instance. */ -static inline bpContext* instantiate_plugin(JobControlRecord* jcr, - Plugin* plugin, - uint32_t instance) +static inline bplugin_private_context* instantiate_plugin(JobControlRecord* jcr, + Plugin* plugin, + uint32_t instance) { - bpContext* ctx; + bplugin_private_context* ctx; b_plugin_ctx* b_ctx; b_ctx = (b_plugin_ctx*)malloc(sizeof(b_plugin_ctx)); @@ -392,11 +401,11 @@ static inline bpContext* instantiate_plugin(JobControlRecord* jcr, Dmsg2(debuglevel, "Instantiate dir-plugin_ctx_list=%p JobId=%d\n", jcr->plugin_ctx_list, jcr->JobId); - ctx = (bpContext*)malloc(sizeof(bpContext)); + ctx = (bplugin_private_context*)malloc(sizeof(bplugin_private_context)); ctx->instance = instance; ctx->plugin = plugin; - ctx->bContext = (void*)b_ctx; - ctx->pContext = NULL; + ctx->core_private_context = (void*)b_ctx; + ctx->plugin_private_context = NULL; jcr->plugin_ctx_list->append(ctx); @@ -413,7 +422,7 @@ void DispatchNewPluginOptions(JobControlRecord* jcr) { int i, j, len; Plugin* plugin; - bpContext* ctx = nullptr; + bplugin_private_context* ctx = nullptr; uint32_t instance; bDirEvent event; bDirEventType eventType; @@ -539,7 +548,7 @@ void NewPlugins(JobControlRecord* jcr) */ void FreePlugins(JobControlRecord* jcr) { - bpContext* ctx = nullptr; + bplugin_private_context* ctx = nullptr; if (!dird_plugin_list || !jcr->plugin_ctx_list) { return; } @@ -550,7 +559,7 @@ void FreePlugins(JobControlRecord* jcr) * Free the plugin instance */ DirplugFunc(ctx->plugin)->freePlugin(ctx); - free(ctx->bContext); /* Free BAREOS private context */ + free(ctx->core_private_context); /* Free BAREOS private context */ } delete jcr->plugin_ctx_list; @@ -562,7 +571,9 @@ void FreePlugins(JobControlRecord* jcr) * Callbacks from the plugin * */ -static bRC bareosGetValue(bpContext* ctx, brDirVariable var, void* value) +static bRC bareosGetValue(bplugin_private_context* ctx, + brDirVariable var, + void* value) { JobControlRecord* jcr = NULL; bRC retval = bRC_OK; @@ -577,7 +588,7 @@ static bRC bareosGetValue(bpContext* ctx, brDirVariable var, void* value) break; default: if (!ctx) { return bRC_Error; } - jcr = ((b_plugin_ctx*)ctx->bContext)->jcr; + jcr = ((b_plugin_ctx*)ctx->core_private_context)->jcr; if (!jcr) { return bRC_Error; } break; } @@ -747,13 +758,15 @@ static bRC bareosGetValue(bpContext* ctx, brDirVariable var, void* value) return retval; } -static bRC bareosSetValue(bpContext* ctx, bwDirVariable var, void* value) +static bRC bareosSetValue(bplugin_private_context* ctx, + bwDirVariable var, + void* value) { JobControlRecord* jcr; if (!value || !ctx) { return bRC_Error; } - jcr = ((b_plugin_ctx*)ctx->bContext)->jcr; + jcr = ((b_plugin_ctx*)ctx->core_private_context)->jcr; if (!jcr) { return bRC_Error; } Dmsg1(debuglevel, "dir-plugin: bareosSetValue var=%d\n", var); @@ -774,7 +787,9 @@ static bRC bareosSetValue(bpContext* ctx, bwDirVariable var, void* value) return bRC_OK; } -static bRC bareosRegisterEvents(bpContext* ctx, int nr_events, ...) +static bRC bareosRegisterEvents(bplugin_private_context* ctx, + int nr_events, + ...) { int i; va_list args; @@ -782,7 +797,7 @@ static bRC bareosRegisterEvents(bpContext* ctx, int nr_events, ...) b_plugin_ctx* b_ctx; if (!ctx) { return bRC_Error; } - b_ctx = (b_plugin_ctx*)ctx->bContext; + b_ctx = (b_plugin_ctx*)ctx->core_private_context; va_start(args, nr_events); for (i = 0; i < nr_events; i++) { event = va_arg(args, uint32_t); @@ -794,7 +809,9 @@ static bRC bareosRegisterEvents(bpContext* ctx, int nr_events, ...) return bRC_OK; } -static bRC bareosUnRegisterEvents(bpContext* ctx, int nr_events, ...) +static bRC bareosUnRegisterEvents(bplugin_private_context* ctx, + int nr_events, + ...) { int i; va_list args; @@ -802,7 +819,7 @@ static bRC bareosUnRegisterEvents(bpContext* ctx, int nr_events, ...) b_plugin_ctx* b_ctx; if (!ctx) { return bRC_Error; } - b_ctx = (b_plugin_ctx*)ctx->bContext; + b_ctx = (b_plugin_ctx*)ctx->core_private_context; va_start(args, nr_events); for (i = 0; i < nr_events; i++) { event = va_arg(args, uint32_t); @@ -814,11 +831,11 @@ static bRC bareosUnRegisterEvents(bpContext* ctx, int nr_events, ...) return bRC_OK; } -static bRC bareosGetInstanceCount(bpContext* ctx, int* ret) +static bRC bareosGetInstanceCount(bplugin_private_context* ctx, int* ret) { int cnt; JobControlRecord *jcr, *njcr; - bpContext* nctx; + bplugin_private_context* nctx; b_plugin_ctx* bctx; bRC retval = bRC_Error; @@ -845,7 +862,7 @@ static bRC bareosGetInstanceCount(bpContext* ctx, int* ret) return retval; } -static bRC bareosJobMsg(bpContext* ctx, +static bRC bareosJobMsg(bplugin_private_context* ctx, const char* file, int line, int type, @@ -858,7 +875,7 @@ static bRC bareosJobMsg(bpContext* ctx, PoolMem buffer(PM_MESSAGE); if (ctx) { - jcr = ((b_plugin_ctx*)ctx->bContext)->jcr; + jcr = ((b_plugin_ctx*)ctx->core_private_context)->jcr; } else { jcr = NULL; } @@ -871,7 +888,7 @@ static bRC bareosJobMsg(bpContext* ctx, return bRC_OK; } -static bRC bareosDebugMsg(bpContext* ctx, +static bRC bareosDebugMsg(bplugin_private_context* ctx, const char* file, int line, int level, diff --git a/core/src/dird/dir_plugins.h b/core/src/dird/dir_plugins.h index 76396b35999..ced14d9bf04 100644 --- a/core/src/dird/dir_plugins.h +++ b/core/src/dird/dir_plugins.h @@ -141,19 +141,25 @@ extern "C" { typedef struct s_dirbareosFuncs { uint32_t size; uint32_t version; - bRC (*registerBareosEvents)(bpContext* ctx, int nr_events, ...); - bRC (*unregisterBareosEvents)(bpContext* ctx, int nr_events, ...); - bRC (*getInstanceCount)(bpContext* ctx, int* ret); - bRC (*getBareosValue)(bpContext* ctx, brDirVariable var, void* value); - bRC (*setBareosValue)(bpContext* ctx, bwDirVariable var, void* value); - bRC (*JobMessage)(bpContext* ctx, + bRC (*registerBareosEvents)(bplugin_private_context* ctx, int nr_events, ...); + bRC (*unregisterBareosEvents)(bplugin_private_context* ctx, + int nr_events, + ...); + bRC (*getInstanceCount)(bplugin_private_context* ctx, int* ret); + bRC (*getBareosValue)(bplugin_private_context* ctx, + brDirVariable var, + void* value); + bRC (*setBareosValue)(bplugin_private_context* ctx, + bwDirVariable var, + void* value); + bRC (*JobMessage)(bplugin_private_context* ctx, const char* file, int line, int type, utime_t mtime, const char* fmt, ...); - bRC (*DebugMessage)(bpContext* ctx, + bRC (*DebugMessage)(bplugin_private_context* ctx, const char* file, int line, int level, @@ -192,11 +198,17 @@ typedef enum typedef struct s_dirpluginFuncs { uint32_t size; uint32_t version; - bRC (*newPlugin)(bpContext* ctx); - bRC (*freePlugin)(bpContext* ctx); - bRC (*getPluginValue)(bpContext* ctx, pVariable var, void* value); - bRC (*setPluginValue)(bpContext* ctx, pVariable var, void* value); - bRC (*handlePluginEvent)(bpContext* ctx, bDirEvent* event, void* value); + bRC (*newPlugin)(bplugin_private_context* ctx); + bRC (*freePlugin)(bplugin_private_context* ctx); + bRC (*getPluginValue)(bplugin_private_context* ctx, + pVariable var, + void* value); + bRC (*setPluginValue)(bplugin_private_context* ctx, + pVariable var, + void* value); + bRC (*handlePluginEvent)(bplugin_private_context* ctx, + bDirEvent* event, + void* value); } pDirFuncs; #define DirplugFunc(plugin) ((pDirFuncs*)(plugin->plugin_functions)) diff --git a/core/src/filed/fd_plugins.cc b/core/src/filed/fd_plugins.cc index 422cf8765ac..5e419589dac 100644 --- a/core/src/filed/fd_plugins.cc +++ b/core/src/filed/fd_plugins.cc @@ -80,43 +80,63 @@ extern int SaveFile(JobControlRecord* jcr, /** * Forward referenced functions */ -static bRC bareosGetValue(bpContext* ctx, bVariable var, void* value); -static bRC bareosSetValue(bpContext* ctx, bVariable var, void* value); -static bRC bareosRegisterEvents(bpContext* ctx, int nr_events, ...); -static bRC bareosUnRegisterEvents(bpContext* ctx, int nr_events, ...); -static bRC bareosJobMsg(bpContext* ctx, +static bRC bareosGetValue(bplugin_private_context* ctx, + bVariable var, + void* value); +static bRC bareosSetValue(bplugin_private_context* ctx, + bVariable var, + void* value); +static bRC bareosRegisterEvents(bplugin_private_context* ctx, + int nr_events, + ...); +static bRC bareosUnRegisterEvents(bplugin_private_context* ctx, + int nr_events, + ...); +static bRC bareosJobMsg(bplugin_private_context* ctx, const char* fname, int line, int type, utime_t mtime, const char* fmt, ...); -static bRC bareosDebugMsg(bpContext* ctx, +static bRC bareosDebugMsg(bplugin_private_context* ctx, const char* fname, int line, int level, const char* fmt, ...); -static void* bareosMalloc(bpContext* ctx, +static void* bareosMalloc(bplugin_private_context* ctx, const char* fname, int line, size_t size); -static void bareosFree(bpContext* ctx, const char* file, int line, void* mem); -static bRC bareosAddExclude(bpContext* ctx, const char* file); -static bRC bareosAddInclude(bpContext* ctx, const char* file); -static bRC bareosAddOptions(bpContext* ctx, const char* opts); -static bRC bareosAddRegex(bpContext* ctx, const char* item, int type); -static bRC bareosAddWild(bpContext* ctx, const char* item, int type); -static bRC bareosNewOptions(bpContext* ctx); -static bRC bareosNewInclude(bpContext* ctx); -static bRC bareosNewPreInclude(bpContext* ctx); +static void bareosFree(bplugin_private_context* ctx, + const char* file, + int line, + void* mem); +static bRC bareosAddExclude(bplugin_private_context* ctx, const char* file); +static bRC bareosAddInclude(bplugin_private_context* ctx, const char* file); +static bRC bareosAddOptions(bplugin_private_context* ctx, const char* opts); +static bRC bareosAddRegex(bplugin_private_context* ctx, + const char* item, + int type); +static bRC bareosAddWild(bplugin_private_context* ctx, + const char* item, + int type); +static bRC bareosNewOptions(bplugin_private_context* ctx); +static bRC bareosNewInclude(bplugin_private_context* ctx); +static bRC bareosNewPreInclude(bplugin_private_context* ctx); static bool IsPluginCompatible(Plugin* plugin); static bool GetPluginName(JobControlRecord* jcr, char* cmd, int* ret); -static bRC bareosCheckChanges(bpContext* ctx, struct save_pkt* sp); -static bRC bareosAcceptFile(bpContext* ctx, struct save_pkt* sp); -static bRC bareosSetSeenBitmap(bpContext* ctx, bool all, char* fname); -static bRC bareosClearSeenBitmap(bpContext* ctx, bool all, char* fname); -static bRC bareosGetInstanceCount(bpContext* ctx, int* ret); +static bRC bareosCheckChanges(bplugin_private_context* ctx, + struct save_pkt* sp); +static bRC bareosAcceptFile(bplugin_private_context* ctx, struct save_pkt* sp); +static bRC bareosSetSeenBitmap(bplugin_private_context* ctx, + bool all, + char* fname); +static bRC bareosClearSeenBitmap(bplugin_private_context* ctx, + bool all, + char* fname); +static bRC bareosGetInstanceCount(bplugin_private_context* ctx, int* ret); /** * These will be plugged into the global pointer structure for the findlib. @@ -178,37 +198,38 @@ struct b_plugin_ctx { Plugin* plugin; /* pointer to plugin of which this is an instance off */ }; -static inline bool IsEventEnabled(bpContext* ctx, bEventType eventType) +static inline bool IsEventEnabled(bplugin_private_context* ctx, + bEventType eventType) { b_plugin_ctx* b_ctx; if (!ctx) { return false; } - b_ctx = (b_plugin_ctx*)ctx->bContext; + b_ctx = (b_plugin_ctx*)ctx->core_private_context; if (!b_ctx) { return false; } return BitIsSet(eventType, b_ctx->events); } -static inline bool IsPluginDisabled(bpContext* ctx) +static inline bool IsPluginDisabled(bplugin_private_context* ctx) { b_plugin_ctx* b_ctx; if (!ctx) { return true; } - b_ctx = (b_plugin_ctx*)ctx->bContext; + b_ctx = (b_plugin_ctx*)ctx->core_private_context; if (!b_ctx) { return true; } return b_ctx->disabled; } -static bool IsCtxGood(bpContext* ctx, +static bool IsCtxGood(bplugin_private_context* ctx, JobControlRecord*& jcr, b_plugin_ctx*& bctx) { if (!ctx) { return false; } - bctx = (b_plugin_ctx*)ctx->bContext; + bctx = (b_plugin_ctx*)ctx->core_private_context; if (!bctx) { return false; } jcr = bctx->jcr; @@ -255,7 +276,7 @@ static bool for_thIsPlugin(Plugin* plugin, char* name, int len) static inline bool trigger_plugin_event(JobControlRecord* jcr, bEventType eventType, bEvent* event, - bpContext* ctx, + bplugin_private_context* ctx, void* value, alist* plugin_ctx_list, int* index, @@ -276,7 +297,7 @@ static inline bool trigger_plugin_event(JobControlRecord* jcr, } if (eventType == bEventEndRestoreJob) { - b_plugin_ctx* b_ctx = (b_plugin_ctx*)ctx->bContext; + b_plugin_ctx* b_ctx = (b_plugin_ctx*)ctx->core_private_context; Dmsg0(50, "eventType == bEventEndRestoreJob\n"); if (b_ctx && b_ctx->restoreFileStarted) { @@ -349,7 +370,7 @@ bRC GeneratePluginEvent(JobControlRecord* jcr, int len = 0; bool call_if_canceled = false; restore_object_pkt* rop; - bpContext* ctx = nullptr; + bplugin_private_context* ctx = nullptr; alist* plugin_ctx_list; bRC rc = bRC_OK; @@ -401,8 +422,8 @@ bRC GeneratePluginEvent(JobControlRecord* jcr, break; case bEventStartRestoreJob: foreach_alist (ctx, plugin_ctx_list) { - ((b_plugin_ctx*)ctx->bContext)->restoreFileStarted = false; - ((b_plugin_ctx*)ctx->bContext)->createFileCalled = false; + ((b_plugin_ctx*)ctx->core_private_context)->restoreFileStarted = false; + ((b_plugin_ctx*)ctx->core_private_context)->createFileCalled = false; } break; case bEventEndRestoreJob: @@ -471,7 +492,7 @@ bRC GeneratePluginEvent(JobControlRecord* jcr, */ bool PluginCheckFile(JobControlRecord* jcr, char* fname) { - bpContext* ctx = nullptr; + bplugin_private_context* ctx = nullptr; alist* plugin_ctx_list; int retval = bRC_OK; @@ -587,7 +608,7 @@ bRC PluginOptionHandleFile(JobControlRecord* jcr, bRC retval = bRC_Core; bEvent event; bEventType eventType; - bpContext* ctx = nullptr; + bplugin_private_context* ctx = nullptr; alist* plugin_ctx_list; cmd = ff_pkt->plugin; @@ -672,7 +693,7 @@ int PluginSave(JobControlRecord* jcr, FindFilesPacket* ff_pkt, bool top_level) bRC retval; char* cmd; bEvent event; - bpContext* ctx = nullptr; + bplugin_private_context* ctx = nullptr; struct save_pkt sp; bEventType eventType; PoolMem fname(PM_FNAME); @@ -932,7 +953,7 @@ int PluginEstimate(JobControlRecord* jcr, bEventType eventType; PoolMem fname(PM_FNAME); PoolMem link(PM_FNAME); - bpContext* ctx = nullptr; + bplugin_private_context* ctx = nullptr; alist* plugin_ctx_list; Attributes attr; @@ -1137,7 +1158,7 @@ bool PluginNameStream(JobControlRecord* jcr, char* name) char* p = name; bool start; bool retval = true; - bpContext* ctx = nullptr; + bplugin_private_context* ctx = nullptr; alist* plugin_ctx_list; Dmsg1(debuglevel, "Read plugin stream string=%s\n", name); @@ -1159,7 +1180,8 @@ bool PluginNameStream(JobControlRecord* jcr, char* name) */ if (jcr->plugin_ctx) { Plugin* plugin = jcr->plugin_ctx->plugin; - b_plugin_ctx* b_ctx = (b_plugin_ctx*)jcr->plugin_ctx->bContext; + b_plugin_ctx* b_ctx = + (b_plugin_ctx*)jcr->plugin_ctx->core_private_context; Dmsg2(debuglevel, "End plugin data plugin=%p ctx=%p\n", plugin, jcr->plugin_ctx); @@ -1216,7 +1238,7 @@ bool PluginNameStream(JobControlRecord* jcr, char* name) jcr->plugin_ctx = ctx; jcr->cmd_plugin = true; - b_ctx = (b_plugin_ctx*)ctx->bContext; + b_ctx = (b_plugin_ctx*)ctx->core_private_context; if (PlugFunc(ctx->plugin) ->handlePluginEvent(jcr->plugin_ctx, &event, cmd) != bRC_OK) { @@ -1266,8 +1288,8 @@ int PluginCreateFile(JobControlRecord* jcr, int status; Plugin* plugin; struct restore_pkt rp; - bpContext* ctx = jcr->plugin_ctx; - b_plugin_ctx* b_ctx = (b_plugin_ctx*)jcr->plugin_ctx->bContext; + bplugin_private_context* ctx = jcr->plugin_ctx; + b_plugin_ctx* b_ctx = (b_plugin_ctx*)jcr->plugin_ctx->core_private_context; if (!ctx || !SetCmdPlugin(bfd, jcr) || jcr->IsJobCanceled()) { return CF_ERROR; @@ -1806,11 +1828,11 @@ static bool IsPluginCompatible(Plugin* plugin) /** * Instantiate a new plugin instance. */ -static inline bpContext* instantiate_plugin(JobControlRecord* jcr, - Plugin* plugin, - char instance) +static inline bplugin_private_context* instantiate_plugin(JobControlRecord* jcr, + Plugin* plugin, + char instance) { - bpContext* ctx; + bplugin_private_context* ctx; b_plugin_ctx* b_ctx; b_ctx = (b_plugin_ctx*)malloc(sizeof(b_plugin_ctx)); @@ -1818,11 +1840,11 @@ static inline bpContext* instantiate_plugin(JobControlRecord* jcr, b_ctx->jcr = jcr; b_ctx->plugin = plugin; - ctx = (bpContext*)malloc(sizeof(bpContext)); + ctx = (bplugin_private_context*)malloc(sizeof(bplugin_private_context)); ctx->instance = instance; ctx->plugin = plugin; - ctx->bContext = (void*)b_ctx; - ctx->pContext = NULL; + ctx->core_private_context = (void*)b_ctx; + ctx->plugin_private_context = NULL; jcr->plugin_ctx_list->append(ctx); @@ -1873,7 +1895,7 @@ void NewPlugins(JobControlRecord* jcr) */ void FreePlugins(JobControlRecord* jcr) { - bpContext* ctx = nullptr; + bplugin_private_context* ctx = nullptr; if (!fd_plugin_list || !jcr->plugin_ctx_list) { return; } @@ -1884,7 +1906,7 @@ void FreePlugins(JobControlRecord* jcr) * Free the plugin instance */ PlugFunc(ctx->plugin)->freePlugin(ctx); - free(ctx->bContext); /* Free BAREOS private context */ + free(ctx->core_private_context); /* Free BAREOS private context */ } delete jcr->plugin_ctx_list; @@ -2082,7 +2104,9 @@ static boffset_t MyPluginBlseek(BareosWinFilePacket* bfd, * * ============================================================== */ -static bRC bareosGetValue(bpContext* ctx, bVariable var, void* value) +static bRC bareosGetValue(bplugin_private_context* ctx, + bVariable var, + void* value) { JobControlRecord* jcr = NULL; if (!value) { return bRC_Error; } @@ -2108,7 +2132,7 @@ static bRC bareosGetValue(bpContext* ctx, bVariable var, void* value) return bRC_Error; } - jcr = ((b_plugin_ctx*)ctx->bContext)->jcr; + jcr = ((b_plugin_ctx*)ctx->core_private_context)->jcr; if (!jcr) { return bRC_Error; } break; } @@ -2194,13 +2218,15 @@ static bRC bareosGetValue(bpContext* ctx, bVariable var, void* value) return bRC_OK; } -static bRC bareosSetValue(bpContext* ctx, bVariable var, void* value) +static bRC bareosSetValue(bplugin_private_context* ctx, + bVariable var, + void* value) { JobControlRecord* jcr; if (!value || !ctx) { return bRC_Error; } - jcr = ((b_plugin_ctx*)ctx->bContext)->jcr; + jcr = ((b_plugin_ctx*)ctx->core_private_context)->jcr; if (!jcr) { return bRC_Error; } switch (var) { @@ -2222,7 +2248,9 @@ static bRC bareosSetValue(bpContext* ctx, bVariable var, void* value) return bRC_OK; } -static bRC bareosRegisterEvents(bpContext* ctx, int nr_events, ...) +static bRC bareosRegisterEvents(bplugin_private_context* ctx, + int nr_events, + ...) { int i; va_list args; @@ -2230,7 +2258,7 @@ static bRC bareosRegisterEvents(bpContext* ctx, int nr_events, ...) b_plugin_ctx* b_ctx; if (!ctx) { return bRC_Error; } - b_ctx = (b_plugin_ctx*)ctx->bContext; + b_ctx = (b_plugin_ctx*)ctx->core_private_context; va_start(args, nr_events); for (i = 0; i < nr_events; i++) { @@ -2246,11 +2274,11 @@ static bRC bareosRegisterEvents(bpContext* ctx, int nr_events, ...) /** * Get the number of instaces instantiated of a certain plugin. */ -static bRC bareosGetInstanceCount(bpContext* ctx, int* ret) +static bRC bareosGetInstanceCount(bplugin_private_context* ctx, int* ret) { int cnt; JobControlRecord *jcr, *njcr; - bpContext* nctx; + bplugin_private_context* nctx; b_plugin_ctx* bctx; bRC retval = bRC_Error; @@ -2277,7 +2305,9 @@ static bRC bareosGetInstanceCount(bpContext* ctx, int* ret) return retval; } -static bRC bareosUnRegisterEvents(bpContext* ctx, int nr_events, ...) +static bRC bareosUnRegisterEvents(bplugin_private_context* ctx, + int nr_events, + ...) { int i; va_list args; @@ -2285,7 +2315,7 @@ static bRC bareosUnRegisterEvents(bpContext* ctx, int nr_events, ...) b_plugin_ctx* b_ctx; if (!ctx) { return bRC_Error; } - b_ctx = (b_plugin_ctx*)ctx->bContext; + b_ctx = (b_plugin_ctx*)ctx->core_private_context; va_start(args, nr_events); for (i = 0; i < nr_events; i++) { @@ -2298,7 +2328,7 @@ static bRC bareosUnRegisterEvents(bpContext* ctx, int nr_events, ...) return bRC_OK; } -static bRC bareosJobMsg(bpContext* ctx, +static bRC bareosJobMsg(bplugin_private_context* ctx, const char* fname, int line, int type, @@ -2311,7 +2341,7 @@ static bRC bareosJobMsg(bpContext* ctx, PoolMem buffer(PM_MESSAGE); if (ctx) { - jcr = ((b_plugin_ctx*)ctx->bContext)->jcr; + jcr = ((b_plugin_ctx*)ctx->core_private_context)->jcr; } else { jcr = NULL; } @@ -2324,7 +2354,7 @@ static bRC bareosJobMsg(bpContext* ctx, return bRC_OK; } -static bRC bareosDebugMsg(bpContext* ctx, +static bRC bareosDebugMsg(bplugin_private_context* ctx, const char* fname, int line, int level, @@ -2342,7 +2372,7 @@ static bRC bareosDebugMsg(bpContext* ctx, return bRC_OK; } -static void* bareosMalloc(bpContext* ctx, +static void* bareosMalloc(bplugin_private_context* ctx, const char* fname, int line, size_t size) @@ -2350,7 +2380,10 @@ static void* bareosMalloc(bpContext* ctx, return malloc(size); } -static void bareosFree(bpContext* ctx, const char* fname, int line, void* mem) +static void bareosFree(bplugin_private_context* ctx, + const char* fname, + int line, + void* mem) { free(mem); } @@ -2359,7 +2392,7 @@ static void bareosFree(bpContext* ctx, const char* fname, int line, void* mem) * Let the plugin define files/directories to be excluded from the main * backup. */ -static bRC bareosAddExclude(bpContext* ctx, const char* fname) +static bRC bareosAddExclude(bplugin_private_context* ctx, const char* fname) { JobControlRecord* jcr; findIncludeExcludeItem* old; @@ -2401,7 +2434,7 @@ static bRC bareosAddExclude(bpContext* ctx, const char* fname) * Let the plugin define files/directories to be excluded from the main * backup. */ -static bRC bareosAddInclude(bpContext* ctx, const char* fname) +static bRC bareosAddInclude(bplugin_private_context* ctx, const char* fname) { JobControlRecord* jcr; findIncludeExcludeItem* old; @@ -2436,7 +2469,7 @@ static bRC bareosAddInclude(bpContext* ctx, const char* fname) return bRC_OK; } -static bRC bareosAddOptions(bpContext* ctx, const char* opts) +static bRC bareosAddOptions(bplugin_private_context* ctx, const char* opts) { JobControlRecord* jcr; b_plugin_ctx* bctx; @@ -2450,7 +2483,9 @@ static bRC bareosAddOptions(bpContext* ctx, const char* opts) return bRC_OK; } -static bRC bareosAddRegex(bpContext* ctx, const char* item, int type) +static bRC bareosAddRegex(bplugin_private_context* ctx, + const char* item, + int type) { JobControlRecord* jcr; b_plugin_ctx* bctx; @@ -2464,7 +2499,9 @@ static bRC bareosAddRegex(bpContext* ctx, const char* item, int type) return bRC_OK; } -static bRC bareosAddWild(bpContext* ctx, const char* item, int type) +static bRC bareosAddWild(bplugin_private_context* ctx, + const char* item, + int type) { JobControlRecord* jcr; b_plugin_ctx* bctx; @@ -2478,7 +2515,7 @@ static bRC bareosAddWild(bpContext* ctx, const char* item, int type) return bRC_OK; } -static bRC bareosNewOptions(bpContext* ctx) +static bRC bareosNewOptions(bplugin_private_context* ctx) { JobControlRecord* jcr; b_plugin_ctx* bctx; @@ -2489,7 +2526,7 @@ static bRC bareosNewOptions(bpContext* ctx) return bRC_OK; } -static bRC bareosNewInclude(bpContext* ctx) +static bRC bareosNewInclude(bplugin_private_context* ctx) { JobControlRecord* jcr; b_plugin_ctx* bctx; @@ -2500,7 +2537,7 @@ static bRC bareosNewInclude(bpContext* ctx) return bRC_OK; } -static bRC bareosNewPreInclude(bpContext* ctx) +static bRC bareosNewPreInclude(bplugin_private_context* ctx) { JobControlRecord* jcr; b_plugin_ctx* bctx; @@ -2517,7 +2554,7 @@ static bRC bareosNewPreInclude(bpContext* ctx) /** * Check if a file have to be backed up using Accurate code */ -static bRC bareosCheckChanges(bpContext* ctx, struct save_pkt* sp) +static bRC bareosCheckChanges(bplugin_private_context* ctx, struct save_pkt* sp) { JobControlRecord* jcr; b_plugin_ctx* bctx; @@ -2568,7 +2605,7 @@ static bRC bareosCheckChanges(bpContext* ctx, struct save_pkt* sp) /** * Check if a file would be saved using current Include/Exclude code */ -static bRC bareosAcceptFile(bpContext* ctx, struct save_pkt* sp) +static bRC bareosAcceptFile(bplugin_private_context* ctx, struct save_pkt* sp) { JobControlRecord* jcr; FindFilesPacket* ff_pkt; @@ -2596,7 +2633,9 @@ static bRC bareosAcceptFile(bpContext* ctx, struct save_pkt* sp) /** * Manipulate the accurate seen bitmap for setting bits */ -static bRC bareosSetSeenBitmap(bpContext* ctx, bool all, char* fname) +static bRC bareosSetSeenBitmap(bplugin_private_context* ctx, + bool all, + char* fname) { JobControlRecord* jcr; b_plugin_ctx* bctx; @@ -2624,7 +2663,9 @@ static bRC bareosSetSeenBitmap(bpContext* ctx, bool all, char* fname) /** * Manipulate the accurate seen bitmap for clearing bits */ -static bRC bareosClearSeenBitmap(bpContext* ctx, bool all, char* fname) +static bRC bareosClearSeenBitmap(bplugin_private_context* ctx, + bool all, + char* fname) { JobControlRecord* jcr; b_plugin_ctx* bctx; diff --git a/core/src/filed/fd_plugins.h b/core/src/filed/fd_plugins.h index ee2e2c2726d..724e958443b 100644 --- a/core/src/filed/fd_plugins.h +++ b/core/src/filed/fd_plugins.h @@ -319,42 +319,51 @@ extern "C" { typedef struct s_bareosFuncs { uint32_t size; uint32_t version; - bRC (*registerBareosEvents)(bpContext* ctx, int nr_events, ...); - bRC (*unregisterBareosEvents)(bpContext* ctx, int nr_events, ...); - bRC (*getInstanceCount)(bpContext* ctx, int* ret); - bRC (*getBareosValue)(bpContext* ctx, bVariable var, void* value); - bRC (*setBareosValue)(bpContext* ctx, bVariable var, void* value); - bRC (*JobMessage)(bpContext* ctx, + bRC (*registerBareosEvents)(bplugin_private_context* ctx, int nr_events, ...); + bRC (*unregisterBareosEvents)(bplugin_private_context* ctx, + int nr_events, + ...); + bRC (*getInstanceCount)(bplugin_private_context* ctx, int* ret); + bRC (*getBareosValue)(bplugin_private_context* ctx, + bVariable var, + void* value); + bRC (*setBareosValue)(bplugin_private_context* ctx, + bVariable var, + void* value); + bRC (*JobMessage)(bplugin_private_context* ctx, const char* file, int line, int type, utime_t mtime, const char* fmt, ...); - bRC (*DebugMessage)(bpContext* ctx, + bRC (*DebugMessage)(bplugin_private_context* ctx, const char* file, int line, int level, const char* fmt, ...); - void* (*bareosMalloc)(bpContext* ctx, + void* (*bareosMalloc)(bplugin_private_context* ctx, const char* file, int line, size_t size); - void (*bareosFree)(bpContext* ctx, const char* file, int line, void* mem); - bRC (*AddExclude)(bpContext* ctx, const char* file); - bRC (*AddInclude)(bpContext* ctx, const char* file); - bRC (*AddOptions)(bpContext* ctx, const char* opts); - bRC (*AddRegex)(bpContext* ctx, const char* item, int type); - bRC (*AddWild)(bpContext* ctx, const char* item, int type); - bRC (*NewOptions)(bpContext* ctx); - bRC (*NewInclude)(bpContext* ctx); - bRC (*NewPreInclude)(bpContext* ctx); - bRC (*checkChanges)(bpContext* ctx, struct save_pkt* sp); - bRC (*AcceptFile)(bpContext* ctx, + void (*bareosFree)(bplugin_private_context* ctx, + const char* file, + int line, + void* mem); + bRC (*AddExclude)(bplugin_private_context* ctx, const char* file); + bRC (*AddInclude)(bplugin_private_context* ctx, const char* file); + bRC (*AddOptions)(bplugin_private_context* ctx, const char* opts); + bRC (*AddRegex)(bplugin_private_context* ctx, const char* item, int type); + bRC (*AddWild)(bplugin_private_context* ctx, const char* item, int type); + bRC (*NewOptions)(bplugin_private_context* ctx); + bRC (*NewInclude)(bplugin_private_context* ctx); + bRC (*NewPreInclude)(bplugin_private_context* ctx); + bRC (*checkChanges)(bplugin_private_context* ctx, struct save_pkt* sp); + bRC (*AcceptFile)(bplugin_private_context* ctx, struct save_pkt* sp); /* Need fname and statp */ - bRC (*SetSeenBitmap)(bpContext* ctx, bool all, char* fname); - bRC (*ClearSeenBitmap)(bpContext* ctx, bool all, char* fname); + bRC (*SetSeenBitmap)(bplugin_private_context* ctx, bool all, char* fname); + bRC (*ClearSeenBitmap)(bplugin_private_context* ctx, bool all, char* fname); } BareosCoreFunctions; /**************************************************************************** @@ -378,23 +387,30 @@ typedef enum typedef struct s_pluginFuncs { uint32_t size; uint32_t version; - bRC (*newPlugin)(bpContext* ctx); - bRC (*freePlugin)(bpContext* ctx); - bRC (*getPluginValue)(bpContext* ctx, pVariable var, void* value); - bRC (*setPluginValue)(bpContext* ctx, pVariable var, void* value); - bRC (*handlePluginEvent)(bpContext* ctx, bEvent* event, void* value); - bRC (*startBackupFile)(bpContext* ctx, struct save_pkt* sp); - bRC (*endBackupFile)(bpContext* ctx); - bRC (*startRestoreFile)(bpContext* ctx, const char* cmd); - bRC (*endRestoreFile)(bpContext* ctx); - bRC (*pluginIO)(bpContext* ctx, struct io_pkt* io); - bRC (*createFile)(bpContext* ctx, struct restore_pkt* rp); - bRC (*setFileAttributes)(bpContext* ctx, struct restore_pkt* rp); - bRC (*checkFile)(bpContext* ctx, char* fname); - bRC (*getAcl)(bpContext* ctx, struct acl_pkt* ap); - bRC (*setAcl)(bpContext* ctx, struct acl_pkt* ap); - bRC (*getXattr)(bpContext* ctx, struct xattr_pkt* xp); - bRC (*setXattr)(bpContext* ctx, struct xattr_pkt* xp); + bRC (*newPlugin)(bplugin_private_context* ctx); + bRC (*freePlugin)(bplugin_private_context* ctx); + bRC (*getPluginValue)(bplugin_private_context* ctx, + pVariable var, + void* value); + bRC (*setPluginValue)(bplugin_private_context* ctx, + pVariable var, + void* value); + bRC (*handlePluginEvent)(bplugin_private_context* ctx, + bEvent* event, + void* value); + bRC (*startBackupFile)(bplugin_private_context* ctx, struct save_pkt* sp); + bRC (*endBackupFile)(bplugin_private_context* ctx); + bRC (*startRestoreFile)(bplugin_private_context* ctx, const char* cmd); + bRC (*endRestoreFile)(bplugin_private_context* ctx); + bRC (*pluginIO)(bplugin_private_context* ctx, struct io_pkt* io); + bRC (*createFile)(bplugin_private_context* ctx, struct restore_pkt* rp); + bRC (*setFileAttributes)(bplugin_private_context* ctx, + struct restore_pkt* rp); + bRC (*checkFile)(bplugin_private_context* ctx, char* fname); + bRC (*getAcl)(bplugin_private_context* ctx, struct acl_pkt* ap); + bRC (*setAcl)(bplugin_private_context* ctx, struct acl_pkt* ap); + bRC (*getXattr)(bplugin_private_context* ctx, struct xattr_pkt* xp); + bRC (*setXattr)(bplugin_private_context* ctx, struct xattr_pkt* xp); } pFuncs; #define PlugFunc(plugin) ((pFuncs*)(plugin->plugin_functions)) diff --git a/core/src/findlib/bfile.cc b/core/src/findlib/bfile.cc index 141be2d175a..d3667c4e2c6 100644 --- a/core/src/findlib/bfile.cc +++ b/core/src/findlib/bfile.cc @@ -3,7 +3,7 @@ Copyright (C) 2003-2010 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2019 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -274,7 +274,8 @@ bool processWin32BackupAPIBlock(BareosWinFilePacket* bfd, BackupRead stream beginning at pos 0 and ending at the end. */ - PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT* pContext = &(bfd->win32DecompContext); + PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT* plugin_private_context = + &(bfd->win32Decomplugin_private_context); bool bContinue = false; int64_t dwDataOffset = 0; int64_t dwDataLen; @@ -285,36 +286,37 @@ bool processWin32BackupAPIBlock(BareosWinFilePacket* bfd, int32_t dwSizeHeader = 20; do { - if (pContext->liNextHeader >= dwSize) { + if (plugin_private_context->liNextHeader >= dwSize) { dwDataLen = dwSize - dwDataOffset; bContinue = false; /* 1 iteration is enough */ } else { - dwDataLen = pContext->liNextHeader - dwDataOffset; + dwDataLen = plugin_private_context->liNextHeader - dwDataOffset; bContinue = true; /* multiple iterations may be necessary */ } /* flush */ /* copy block of real DATA */ - if (pContext->bIsInData) { + if (plugin_private_context->bIsInData) { if (bwrite(bfd, ((char*)pBuffer) + dwDataOffset, dwDataLen) != (ssize_t)dwDataLen) return false; } - if (pContext->liNextHeader < dwSize) { /* is a header in this block ? */ + if (plugin_private_context->liNextHeader < + dwSize) { /* is a header in this block ? */ int32_t dwOffsetTarget; int32_t dwOffsetSource; - if (pContext->liNextHeader < 0) { + if (plugin_private_context->liNextHeader < 0) { /* start of header was before this block, so we * continue with the part in the current block */ - dwOffsetTarget = -pContext->liNextHeader; + dwOffsetTarget = -plugin_private_context->liNextHeader; dwOffsetSource = 0; } else { /* start of header is inside of this block */ dwOffsetTarget = 0; - dwOffsetSource = pContext->liNextHeader; + dwOffsetSource = plugin_private_context->liNextHeader; } int32_t dwHeaderPartLen = dwSizeHeader - dwOffsetTarget; @@ -332,33 +334,37 @@ bool processWin32BackupAPIBlock(BareosWinFilePacket* bfd, } /* copy the available portion of header to persistent copy */ - memcpy(((char*)&pContext->header_stream) + dwOffsetTarget, + memcpy(((char*)&plugin_private_context->header_stream) + dwOffsetTarget, ((char*)pBuffer) + dwOffsetSource, dwHeaderPartLen); /* recalculate position of next header */ if (bHeaderIsComplete) { /* convert stream name size (32 bit little endian) to machine type */ int32_t dwNameSize; - int32_LE2BE(&dwNameSize, pContext->header_stream.dwStreamNameSize); - dwDataOffset = dwNameSize + pContext->liNextHeader + dwSizeHeader; + int32_LE2BE(&dwNameSize, + plugin_private_context->header_stream.dwStreamNameSize); + dwDataOffset = + dwNameSize + plugin_private_context->liNextHeader + dwSizeHeader; /* convert stream size (64 bit little endian) to machine type */ - int64_LE2BE(&(pContext->liNextHeader), pContext->header_stream.Size); - pContext->liNextHeader += dwDataOffset; + int64_LE2BE(&(plugin_private_context->liNextHeader), + plugin_private_context->header_stream.Size); + plugin_private_context->liNextHeader += dwDataOffset; - pContext->bIsInData = - pContext->header_stream.dwStreamId == WIN32_BACKUP_DATA; + plugin_private_context->bIsInData = + plugin_private_context->header_stream.dwStreamId == + WIN32_BACKUP_DATA; if (dwDataOffset == dwSize) bContinue = false; } else { /* stop and continue with next block */ bContinue = false; - pContext->bIsInData = false; + plugin_private_context->bIsInData = false; } } } while (bContinue); /* set "NextHeader" relative to the beginning of the next block */ - pContext->liNextHeader -= dwSize; + plugin_private_context->liNextHeader -= dwSize; return TRUE; } @@ -754,9 +760,9 @@ static inline int BopenNonencrypted(BareosWinFilePacket* bfd, } bfd->errmsg = NULL; - bfd->lpContext = NULL; - bfd->win32DecompContext.bIsInData = false; - bfd->win32DecompContext.liNextHeader = 0; + bfd->lplugin_private_context = NULL; + bfd->win32Decomplugin_private_context.bIsInData = false; + bfd->win32Decomplugin_private_context.liNextHeader = 0; FreePoolMemory(win32_fname_wchar); FreePoolMemory(win32_fname); @@ -836,28 +842,30 @@ static inline int BcloseNonencrypted(BareosWinFilePacket* bfd) /* * We need to tell the API to release the buffer it - * allocated in lpContext. We do so by calling the + * allocated in lplugin_private_context. We do so by calling the * API one more time, but with the Abort bit set. */ if (bfd->use_backup_api && bfd->mode == BF_READ) { BYTE buf[10]; - if (bfd->lpContext && !p_BackupRead(bfd->fh, buf, /* buffer */ - (DWORD)0, /* bytes to read */ - &bfd->rw_bytes, /* bytes read */ - 1, /* Abort */ - 1, /* ProcessSecurity */ - &bfd->lpContext)) { /* Read context */ + if (bfd->lplugin_private_context && + !p_BackupRead(bfd->fh, buf, /* buffer */ + (DWORD)0, /* bytes to read */ + &bfd->rw_bytes, /* bytes read */ + 1, /* Abort */ + 1, /* ProcessSecurity */ + &bfd->lplugin_private_context)) { /* Read context */ errno = b_errno_win32; status = -1; } } else if (bfd->use_backup_api && bfd->mode == BF_WRITE) { BYTE buf[10]; - if (bfd->lpContext && !p_BackupWrite(bfd->fh, buf, /* buffer */ - (DWORD)0, /* bytes to read */ - &bfd->rw_bytes, /* bytes written */ - 1, /* Abort */ - 1, /* ProcessSecurity */ - &bfd->lpContext)) { /* Write context */ + if (bfd->lplugin_private_context && + !p_BackupWrite(bfd->fh, buf, /* buffer */ + (DWORD)0, /* bytes to read */ + &bfd->rw_bytes, /* bytes written */ + 1, /* Abort */ + 1, /* ProcessSecurity */ + &bfd->lplugin_private_context)) { /* Write context */ errno = b_errno_win32; status = -1; } @@ -873,7 +881,7 @@ static inline int BcloseNonencrypted(BareosWinFilePacket* bfd) bfd->errmsg = NULL; } bfd->mode = BF_CLOSED; - bfd->lpContext = NULL; + bfd->lplugin_private_context = NULL; bfd->cmd_plugin = false; return status; @@ -904,9 +912,9 @@ ssize_t bread(BareosWinFilePacket* bfd, void* buf, size_t count) if (bfd->use_backup_api) { if (!p_BackupRead(bfd->fh, (BYTE*)buf, count, &bfd->rw_bytes, - 0, /* no Abort */ - 1, /* Process Security */ - &bfd->lpContext)) { /* Context */ + 0, /* no Abort */ + 1, /* Process Security */ + &bfd->lplugin_private_context)) { /* Context */ bfd->lerror = GetLastError(); bfd->BErrNo = b_errno_win32; errno = b_errno_win32; @@ -934,9 +942,9 @@ ssize_t bwrite(BareosWinFilePacket* bfd, void* buf, size_t count) if (bfd->use_backup_api) { if (!p_BackupWrite(bfd->fh, (BYTE*)buf, count, &bfd->rw_bytes, - 0, /* No abort */ - 1, /* Process Security */ - &bfd->lpContext)) { /* Context */ + 0, /* No abort */ + 1, /* Process Security */ + &bfd->lplugin_private_context)) { /* Context */ bfd->lerror = GetLastError(); bfd->BErrNo = b_errno_win32; errno = b_errno_win32; @@ -1129,8 +1137,8 @@ int bopen(BareosWinFilePacket* bfd, Dmsg1(400, "Open file %d\n", bfd->fid); errno = bfd->BErrNo; - bfd->win32DecompContext.bIsInData = false; - bfd->win32DecompContext.liNextHeader = 0; + bfd->win32Decomplugin_private_context.bIsInData = false; + bfd->win32Decomplugin_private_context.liNextHeader = 0; #if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_WILLNEED) /* If not RDWR or WRONLY must be Read Only */ diff --git a/core/src/findlib/bfile.h b/core/src/findlib/bfile.h index 12f687544c5..8df1b1d5ae4 100644 --- a/core/src/findlib/bfile.h +++ b/core/src/findlib/bfile.h @@ -3,7 +3,7 @@ Copyright (C) 2003-2010 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2019 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -79,7 +79,7 @@ struct BareosWinFilePacket { int mode = BF_CLOSED; /**< set if file is open */ HANDLE fh = INVALID_HANDLE_VALUE; /**< Win32 file handle */ int fid = 0; /**< fd if doing Unix style */ - LPVOID lpContext = nullptr; /**< BackupRead/Write context */ + LPVOID lplugin_private_context = nullptr; /**< BackupRead/Write context */ PVOID pvContext = nullptr; /**< Encryption context */ POOLMEM* errmsg = nullptr; /**< error message buffer */ DWORD rw_bytes = 0; /**< Bytes read or written */ @@ -87,7 +87,7 @@ struct BareosWinFilePacket { int BErrNo = 0; /**< errno */ boffset_t offset = 0; /**< Delta offset */ JobControlRecord* jcr = nullptr; /**< jcr for editing job codes */ - PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext{0}; /**< context for decomposition + PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32Decomplugin_private_context{0}; /**< context for decomposition of win32 backup streams */ int use_backup_decomp = 0; /**< set if using BackupRead Stream Decomposition */ bool reparse_point = false; /**< set if reparse point */ @@ -115,7 +115,7 @@ struct BareosWinFilePacket { int32_t lerror{0}; /**< not used - simplies Win32 builds */ boffset_t offset{0}; /**< Delta offset */ JobControlRecord* jcr{nullptr}; /**< jcr for editing job codes */ - PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32DecompContext{0}; /**< context for decomposition + PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT win32Decomplugin_private_context{0}; /**< context for decomposition of win32 backup streams */ int use_backup_decomp{0}; /**< set if using BackupRead Stream Decomposition */ bool reparse_point{false}; /**< not used in Unix */ diff --git a/core/src/include/jcr.h b/core/src/include/jcr.h index cce2ac41697..7ac2b8949e4 100644 --- a/core/src/include/jcr.h +++ b/core/src/include/jcr.h @@ -49,7 +49,7 @@ class htable; class JobControlRecord; struct AttributesDbRecord; -struct bpContext; +struct bplugin_private_context; struct JobControlRecordPrivate; struct VolumeSessionInfo; @@ -221,7 +221,7 @@ class JobControlRecord { guid_list* id_list{}; /**< User/group id to name list */ alist* plugin_ctx_list{}; /**< List of contexts for plugins */ - bpContext* plugin_ctx{}; /**< Current plugin context */ + bplugin_private_context* plugin_ctx{}; /**< Current plugin context */ POOLMEM* comment{}; /**< Comment for this Job */ int64_t max_bandwidth{}; /**< Bandwidth limit for this Job */ htable* path_list{}; /**< Directory list (used by findlib) */ diff --git a/core/src/lib/plugins.h b/core/src/lib/plugins.h index 07f022268c9..e0bb06c1297 100644 --- a/core/src/lib/plugins.h +++ b/core/src/lib/plugins.h @@ -79,11 +79,11 @@ class Plugin { /** * Context packet as first argument of all functions */ -struct bpContext { +struct bplugin_private_context { uint32_t instance; Plugin* plugin; - void* bContext; /* BAREOS private context */ - void* pContext; /* Plugin private context */ + void* core_private_context; /* BAREOS private context */ + void* plugin_private_context; /* Plugin private context */ }; typedef struct gen_pluginInfo { diff --git a/core/src/plugins/dird/example/example-plugin-dir.cc b/core/src/plugins/dird/example/example-plugin-dir.cc index 0bf10f3c5ef..9b3e11e3575 100644 --- a/core/src/plugins/dird/example/example-plugin-dir.cc +++ b/core/src/plugins/dird/example/example-plugin-dir.cc @@ -38,11 +38,17 @@ namespace directordaemon { /* Forward referenced functions */ -static bRC newPlugin(bpContext* ctx); -static bRC freePlugin(bpContext* ctx); -static bRC getPluginValue(bpContext* ctx, pDirVariable var, void* value); -static bRC setPluginValue(bpContext* ctx, pDirVariable var, void* value); -static bRC handlePluginEvent(bpContext* ctx, bDirEvent* event, void* value); +static bRC newPlugin(bplugin_private_context* ctx); +static bRC freePlugin(bplugin_private_context* ctx); +static bRC getPluginValue(bplugin_private_context* ctx, + pDirVariable var, + void* value); +static bRC setPluginValue(bplugin_private_context* ctx, + pDirVariable var, + void* value); +static bRC handlePluginEvent(bplugin_private_context* ctx, + bDirEvent* event, + void* value); /* Pointers to Bareos functions */ @@ -104,7 +110,7 @@ bRC unloadPlugin() } #endif -static bRC newPlugin(bpContext* ctx) +static bRC newPlugin(bplugin_private_context* ctx) { int JobId = 0; bareos_core_functions->getBareosValue(ctx, bDirVarJobId, (void*)&JobId); @@ -114,7 +120,7 @@ static bRC newPlugin(bpContext* ctx) return bRC_OK; } -static bRC freePlugin(bpContext* ctx) +static bRC freePlugin(bplugin_private_context* ctx) { int JobId = 0; bareos_core_functions->getBareosValue(ctx, bDirVarJobId, (void*)&JobId); @@ -122,19 +128,25 @@ static bRC freePlugin(bpContext* ctx) return bRC_OK; } -static bRC getPluginValue(bpContext* ctx, pDirVariable var, void* value) +static bRC getPluginValue(bplugin_private_context* ctx, + pDirVariable var, + void* value) { printf("plugin: getPluginValue var=%d\n", var); return bRC_OK; } -static bRC setPluginValue(bpContext* ctx, pDirVariable var, void* value) +static bRC setPluginValue(bplugin_private_context* ctx, + pDirVariable var, + void* value) { printf("plugin: setPluginValue var=%d\n", var); return bRC_OK; } -static bRC handlePluginEvent(bpContext* ctx, bDirEvent* event, void* value) +static bRC handlePluginEvent(bplugin_private_context* ctx, + bDirEvent* event, + void* value) { char* name; int val; diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index 534e42905ba..e1b1b85c45b 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -58,31 +58,34 @@ static const int debuglevel = 150; /* Forward referenced functions */ -static bRC newPlugin(bpContext* bareos_plugin_ctx); -static bRC freePlugin(bpContext* bareos_plugin_ctx); -static bRC getPluginValue(bpContext* bareos_plugin_ctx, +static bRC newPlugin(bplugin_private_context* bareos_plugin_ctx); +static bRC freePlugin(bplugin_private_context* bareos_plugin_ctx); +static bRC getPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value); -static bRC setPluginValue(bpContext* bareos_plugin_ctx, +static bRC setPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value); -static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, +static bRC handlePluginEvent(bplugin_private_context* bareos_plugin_ctx, bDirEvent* event, void* value); -static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, +static bRC parse_plugin_definition(bplugin_private_context* bareos_plugin_ctx, void* value, PoolMem& plugin_options); -static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype); -static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value); -static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value); -static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, +static void PyErrorHandler(bplugin_private_context* bareos_plugin_ctx, + int msgtype); +static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, + void* value); +static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, + void* value); +static bRC PyGetPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value); -static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, +static bRC PySetPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value); -static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(bplugin_private_context* bareos_plugin_ctx, bDirEvent* event, void* value); @@ -186,14 +189,14 @@ bRC unloadPlugin() #endif /* Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bpContext* bareos_plugin_ctx) +static bRC newPlugin(bplugin_private_context* bareos_plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = (struct plugin_private_context*)malloc( sizeof(struct plugin_private_context)); if (!plugin_priv_ctx) { return bRC_Error; } memset(plugin_priv_ctx, 0, sizeof(struct plugin_private_context)); - bareos_plugin_ctx->pContext = + bareos_plugin_ctx->plugin_private_context = (void*)plugin_priv_ctx; /* set our context pointer */ /* For each plugin instance we instantiate a new Python interpreter. */ @@ -212,10 +215,10 @@ static bRC newPlugin(bpContext* bareos_plugin_ctx) } /* Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bpContext* bareos_plugin_ctx) +static bRC freePlugin(bplugin_private_context* bareos_plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { return bRC_Error; } @@ -231,13 +234,13 @@ static bRC freePlugin(bpContext* bareos_plugin_ctx) PyEval_ReleaseLock(); free(plugin_priv_ctx); - bareos_plugin_ctx->pContext = NULL; + bareos_plugin_ctx->plugin_private_context = NULL; return bRC_OK; } -static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, +static bRC handlePluginEvent(bplugin_private_context* bareos_plugin_ctx, bDirEvent* event, void* value) { @@ -245,7 +248,7 @@ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, bool event_dispatched = false; PoolMem plugin_options(PM_FNAME); plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->pContext; + (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } @@ -320,7 +323,7 @@ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, * * python:module_path=:module_name=:... */ -static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, +static bRC parse_plugin_definition(bplugin_private_context* bareos_plugin_ctx, void* value, PoolMem& plugin_options) { @@ -329,7 +332,7 @@ static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, PoolMem plugin_definition(PM_FNAME); char *bp, *argument, *argument_value; plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->pContext; + (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!value) { return bRC_Error; } @@ -464,11 +467,11 @@ static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, * module path and the module to load. We also load the dictionary used * for looking up the Python methods. */ -static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) +static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject *sysPath, *mPath, *pName, *pFunc; /* @@ -563,11 +566,12 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) * PyLoadModule() has loaded the Python module and made sure things are * operational. */ -static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) +static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, + void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -606,27 +610,27 @@ static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) return retval; } -static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, +static bRC PyGetPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, +static bRC PySetPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(bplugin_private_context* bareos_plugin_ctx, bDirEvent* event, void* value) { bRC retval = bRC_Error; plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->pContext; + (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -668,7 +672,8 @@ static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } @@ -754,7 +759,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject* pyValue; @@ -805,7 +811,8 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; @@ -827,7 +834,8 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; @@ -848,7 +856,8 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -890,7 +899,8 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -932,7 +942,8 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } diff --git a/core/src/plugins/dird/python/python-dir.h b/core/src/plugins/dird/python/python-dir.h index 891f533fe28..f0069b0dd4f 100644 --- a/core/src/plugins/dird/python/python-dir.h +++ b/core/src/plugins/dird/python/python-dir.h @@ -88,10 +88,10 @@ static void* bareos_plugin_context = NULL; // MOD_INIT(PYTHON_MODULE_NAME) MOD_INIT(bareosdir) { - /* bareos_plugin_context holds the bpContext instead of passing to Python and - * extracting it back like it was before. bareos_plugin_context needs to be - * set after loading the PYTHON_MODULE_NAME binary python module and will be - * used for all calls. + /* bareos_plugin_context holds the bplugin_private_context instead of passing + * to Python and extracting it back like it was before. bareos_plugin_context + * needs to be set after loading the PYTHON_MODULE_NAME binary python module + * and will be used for all calls. */ PyObject* m = NULL; @@ -99,7 +99,7 @@ MOD_INIT(bareosdir) /* Pointer Capsules to avoid context transfer back and forth */ PyObject* PyModulePluginContext = PyCapsule_New((void*)&bareos_plugin_context, - PYTHON_MODULE_NAME_QUOTED ".bpContext", NULL); + PYTHON_MODULE_NAME_QUOTED ".bplugin_private_context", NULL); if (!PyModulePluginContext) { printf(PYTHON_MODULE_NAME_QUOTED ": PyCapsule_New failed\n"); @@ -109,7 +109,7 @@ MOD_INIT(bareosdir) MOD_DEF(m, PYTHON_MODULE_NAME_QUOTED, NULL, Methods) if (PyModulePluginContext) { - PyModule_AddObject(m, "bpContext", PyModulePluginContext); + PyModule_AddObject(m, "bplugin_private_context", PyModulePluginContext); } else { printf(PYTHON_MODULE_NAME_QUOTED ":PyModule_AddObject failed\n"); return MOD_ERROR_VAL; diff --git a/core/src/plugins/filed/bpipe/bpipe-fd.cc b/core/src/plugins/filed/bpipe/bpipe-fd.cc index d71e132676e..b51333f1f44 100644 --- a/core/src/plugins/filed/bpipe/bpipe-fd.cc +++ b/core/src/plugins/filed/bpipe/bpipe-fd.cc @@ -46,27 +46,34 @@ static const int debuglevel = 150; " the data is internally stored as filepath (e.g. mybackup/backup1)" /* Forward referenced functions */ -static bRC newPlugin(bpContext* ctx); -static bRC freePlugin(bpContext* ctx); -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value); -static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp); -static bRC endBackupFile(bpContext* ctx); -static bRC pluginIO(bpContext* ctx, struct io_pkt* io); -static bRC startRestoreFile(bpContext* ctx, const char* cmd); -static bRC endRestoreFile(bpContext* ctx); -static bRC createFile(bpContext* ctx, struct restore_pkt* rp); -static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp); -static bRC checkFile(bpContext* ctx, char* fname); -static bRC getAcl(bpContext* ctx, acl_pkt* ap); -static bRC setAcl(bpContext* ctx, acl_pkt* ap); -static bRC getXattr(bpContext* ctx, xattr_pkt* xp); -static bRC setXattr(bpContext* ctx, xattr_pkt* xp); - -static char* apply_rp_codes(bpContext* ctx); -static bRC parse_plugin_definition(bpContext* ctx, void* value); -static bRC plugin_has_all_arguments(bpContext* ctx); +static bRC newPlugin(bplugin_private_context* ctx); +static bRC freePlugin(bplugin_private_context* ctx); +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC handlePluginEvent(bplugin_private_context* ctx, + bEvent* event, + void* value); +static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp); +static bRC endBackupFile(bplugin_private_context* ctx); +static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io); +static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd); +static bRC endRestoreFile(bplugin_private_context* ctx); +static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp); +static bRC setFileAttributes(bplugin_private_context* ctx, + struct restore_pkt* rp); +static bRC checkFile(bplugin_private_context* ctx, char* fname); +static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap); +static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap); +static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp); +static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp); + +static char* apply_rp_codes(bplugin_private_context* ctx); +static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value); +static bRC plugin_has_all_arguments(bplugin_private_context* ctx); /* Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; @@ -171,13 +178,13 @@ bRC unloadPlugin() { return bRC_OK; } /** * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bpContext* ctx) +static bRC newPlugin(bplugin_private_context* ctx) { struct plugin_ctx* p_ctx = (struct plugin_ctx*)malloc(sizeof(struct plugin_ctx)); if (!p_ctx) { return bRC_Error; } memset(p_ctx, 0, sizeof(struct plugin_ctx)); - ctx->pContext = (void*)p_ctx; /* set our context pointer */ + ctx->plugin_private_context = (void*)p_ctx; /* set our context pointer */ bareos_core_functions->registerBareosEvents( ctx, 6, bEventNewPluginOptions, bEventPluginCommand, bEventJobStart, @@ -189,9 +196,9 @@ static bRC newPlugin(bpContext* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bpContext* ctx) +static bRC freePlugin(bplugin_private_context* ctx) { - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -211,7 +218,9 @@ static bRC freePlugin(bpContext* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { return bRC_OK; } @@ -219,7 +228,9 @@ static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { return bRC_OK; } @@ -227,10 +238,12 @@ static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) +static bRC handlePluginEvent(bplugin_private_context* ctx, + bEvent* event, + void* value) { bRC retval = bRC_OK; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -282,14 +295,14 @@ static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) /** * Start the backup of a specific file */ -static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) +static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) { time_t now; struct plugin_ctx* p_ctx; if (plugin_has_all_arguments(ctx) != bRC_OK) { return bRC_Error; } - p_ctx = (struct plugin_ctx*)ctx->pContext; + p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } now = time(NULL); @@ -309,7 +322,7 @@ static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) /** * Done with backup of this file */ -static bRC endBackupFile(bpContext* ctx) +static bRC endBackupFile(bplugin_private_context* ctx) { /* * We would return bRC_More if we wanted startBackupFile to be called again to @@ -321,9 +334,9 @@ static bRC endBackupFile(bpContext* ctx) /** * Bareos is calling us to do the actual I/O */ -static bRC pluginIO(bpContext* ctx, struct io_pkt* io) +static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) { - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } io->status = 0; @@ -425,7 +438,7 @@ static bRC pluginIO(bpContext* ctx, struct io_pkt* io) * Bareos is notifying us that a plugin name string was found, and * passing us the plugin command, so we can prepare for a restore. */ -static bRC startRestoreFile(bpContext* ctx, const char* cmd) +static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) { if (plugin_has_all_arguments(ctx) != bRC_OK) { return bRC_Error; } @@ -436,9 +449,9 @@ static bRC startRestoreFile(bpContext* ctx, const char* cmd) * Bareos is notifying us that the plugin data has terminated, so * the restore for this particular file is done. */ -static bRC endRestoreFile(bpContext* ctx) +static bRC endRestoreFile(bplugin_private_context* ctx) { - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } return bRC_OK; @@ -453,7 +466,7 @@ static bRC endRestoreFile(bpContext* ctx) * CF_EXTRACT -- extract the file (i.e.call i/o routines) * CF_CREATED -- created, but no content to extract (typically directories) */ -static bRC createFile(bpContext* ctx, struct restore_pkt* rp) +static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) { if (strlen(rp->where) > 512) { printf( @@ -461,14 +474,16 @@ static bRC createFile(bpContext* ctx, struct restore_pkt* rp) "bytes.\n"); } - bstrncpy(((struct plugin_ctx*)ctx->pContext)->where, rp->where, 513); - ((struct plugin_ctx*)ctx->pContext)->replace = rp->replace; + bstrncpy(((struct plugin_ctx*)ctx->plugin_private_context)->where, rp->where, + 513); + ((struct plugin_ctx*)ctx->plugin_private_context)->replace = rp->replace; rp->create_status = CF_EXTRACT; return bRC_OK; } -static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp) +static bRC setFileAttributes(bplugin_private_context* ctx, + struct restore_pkt* rp) { return bRC_OK; } @@ -476,15 +491,24 @@ static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp) /** * When using Incremental dump, all previous dumps are necessary */ -static bRC checkFile(bpContext* ctx, char* fname) { return bRC_OK; } +static bRC checkFile(bplugin_private_context* ctx, char* fname) +{ + return bRC_OK; +} -static bRC getAcl(bpContext* ctx, acl_pkt* ap) { return bRC_OK; } +static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap) { return bRC_OK; } -static bRC setAcl(bpContext* ctx, acl_pkt* ap) { return bRC_OK; } +static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap) { return bRC_OK; } -static bRC getXattr(bpContext* ctx, xattr_pkt* xp) { return bRC_OK; } +static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp) +{ + return bRC_OK; +} -static bRC setXattr(bpContext* ctx, xattr_pkt* xp) { return bRC_OK; } +static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp) +{ + return bRC_OK; +} /** * Apply codes in writer command: @@ -502,13 +526,13 @@ static bRC setXattr(bpContext* ctx, xattr_pkt* xp) { return bRC_OK; } * * Inspired by edit_job_codes in lib/util.c */ -static char* apply_rp_codes(bpContext* ctx) +static char* apply_rp_codes(bplugin_private_context* ctx) { char add[10]; const char* str; char *p, *q, *omsg, *imsg; int w_count = 0, r_count = 0; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return NULL; } @@ -622,11 +646,11 @@ static inline void SetString(char** destination, char* value) * * bpipe:file=:read=:write= */ -static bRC parse_plugin_definition(bpContext* ctx, void* value) +static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value) { int i, cnt; char *plugin_definition, *bp, *argument, *argument_value; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; bool keep_existing; bool compatible = true; @@ -850,10 +874,10 @@ static bRC parse_plugin_definition(bpContext* ctx, void* value) return bRC_Error; } -static bRC plugin_has_all_arguments(bpContext* ctx) +static bRC plugin_has_all_arguments(bplugin_private_context* ctx) { bRC retval = bRC_OK; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { retval = bRC_Error; } diff --git a/core/src/plugins/filed/cephfs/cephfs-fd.cc b/core/src/plugins/filed/cephfs/cephfs-fd.cc index a0366eea9a2..2a1442ed57a 100644 --- a/core/src/plugins/filed/cephfs/cephfs-fd.cc +++ b/core/src/plugins/filed/cephfs/cephfs-fd.cc @@ -50,28 +50,35 @@ static const int debuglevel = 150; /** * Forward referenced functions */ -static bRC newPlugin(bpContext* ctx); -static bRC freePlugin(bpContext* ctx); -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value); -static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp); -static bRC endBackupFile(bpContext* ctx); -static bRC pluginIO(bpContext* ctx, struct io_pkt* io); -static bRC startRestoreFile(bpContext* ctx, const char* cmd); -static bRC endRestoreFile(bpContext* ctx); -static bRC createFile(bpContext* ctx, struct restore_pkt* rp); -static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp); -static bRC checkFile(bpContext* ctx, char* fname); -static bRC getAcl(bpContext* ctx, acl_pkt* ap); -static bRC setAcl(bpContext* ctx, acl_pkt* ap); -static bRC getXattr(bpContext* ctx, xattr_pkt* xp); -static bRC setXattr(bpContext* ctx, xattr_pkt* xp); - -static bRC parse_plugin_definition(bpContext* ctx, void* value); -static bRC setup_backup(bpContext* ctx, void* value); -static bRC setup_restore(bpContext* ctx, void* value); -static bRC end_restore_job(bpContext* ctx, void* value); +static bRC newPlugin(bplugin_private_context* ctx); +static bRC freePlugin(bplugin_private_context* ctx); +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC handlePluginEvent(bplugin_private_context* ctx, + bEvent* event, + void* value); +static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp); +static bRC endBackupFile(bplugin_private_context* ctx); +static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io); +static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd); +static bRC endRestoreFile(bplugin_private_context* ctx); +static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp); +static bRC setFileAttributes(bplugin_private_context* ctx, + struct restore_pkt* rp); +static bRC checkFile(bplugin_private_context* ctx, char* fname); +static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap); +static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap); +static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp); +static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp); + +static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value); +static bRC setup_backup(bplugin_private_context* ctx, void* value); +static bRC setup_restore(bplugin_private_context* ctx, void* value); +static bRC end_restore_job(bplugin_private_context* ctx, void* value); /** * Pointers to Bareos functions @@ -210,14 +217,14 @@ bRC unloadPlugin() { return bRC_OK; } * * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bpContext* ctx) +static bRC newPlugin(bplugin_private_context* ctx) { plugin_ctx* p_ctx; p_ctx = (plugin_ctx*)malloc(sizeof(plugin_ctx)); if (!p_ctx) { return bRC_Error; } memset(p_ctx, 0, sizeof(plugin_ctx)); - ctx->pContext = (void*)p_ctx; /* set our context pointer */ + ctx->plugin_private_context = (void*)p_ctx; /* set our context pointer */ /* * Allocate some internal memory for: @@ -261,9 +268,9 @@ static bRC newPlugin(bpContext* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bpContext* ctx) +static bRC freePlugin(bplugin_private_context* ctx) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } Dmsg(ctx, debuglevel, "cephfs-fd: entering freePlugin\n"); @@ -307,7 +314,9 @@ static bRC freePlugin(bpContext* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { return bRC_OK; } @@ -315,7 +324,9 @@ static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { return bRC_OK; } @@ -323,10 +334,12 @@ static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) +static bRC handlePluginEvent(bplugin_private_context* ctx, + bEvent* event, + void* value) { bRC retval; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -382,12 +395,12 @@ static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) /** * Get the next file to backup. */ -static bRC get_next_file_to_backup(bpContext* ctx) +static bRC get_next_file_to_backup(bplugin_private_context* ctx) { int status; struct save_pkt sp; struct dirent* entry; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; /* * See if we just saved the directory then we are done processing this @@ -597,10 +610,10 @@ static bRC get_next_file_to_backup(bpContext* ctx) /** * Start the backup of a specific file */ -static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) +static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) { int status; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; /* * Save the current flags used to save the next file. @@ -776,9 +789,9 @@ static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) /** * Done with backup of this file */ -static bRC endBackupFile(bpContext* ctx) +static bRC endBackupFile(bplugin_private_context* ctx) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -852,12 +865,12 @@ static inline void SetString(char** destination, char* value) * * cephfs:conffile=:basedir=: */ -static bRC parse_plugin_definition(bpContext* ctx, void* value) +static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value) { int i; bool keep_existing; char *plugin_definition, *bp, *argument, *argument_value; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx || !value) { return bRC_Error; } @@ -994,10 +1007,10 @@ static bRC parse_plugin_definition(bpContext* ctx, void* value) /** * Open a CEPHFS mountpoint. */ -static bRC connect_to_cephfs(bpContext* ctx) +static bRC connect_to_cephfs(bplugin_private_context* ctx) { int status; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; /* * If we get called and we already have a handle to cephfs we should tear it @@ -1045,9 +1058,9 @@ static bRC connect_to_cephfs(bpContext* ctx) /** * Generic setup for performing a backup. */ -static bRC setup_backup(bpContext* ctx, void* value) +static bRC setup_backup(bplugin_private_context* ctx, void* value) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx || !value) { return bRC_Error; } @@ -1080,9 +1093,9 @@ static bRC setup_backup(bpContext* ctx, void* value) /** * Generic setup for performing a restore. */ -static bRC setup_restore(bpContext* ctx, void* value) +static bRC setup_restore(bplugin_private_context* ctx, void* value) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx || !value) { return bRC_Error; } @@ -1101,9 +1114,9 @@ static bRC setup_restore(bpContext* ctx, void* value) /** * Bareos is calling us to do the actual I/O */ -static bRC pluginIO(bpContext* ctx, struct io_pkt* io) +static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -1191,10 +1204,10 @@ static bRC pluginIO(bpContext* ctx, struct io_pkt* io) /** * See if we need to do any postprocessing after the restore. */ -static bRC end_restore_job(bpContext* ctx, void* value) +static bRC end_restore_job(bplugin_private_context* ctx, void* value) { bRC retval = bRC_OK; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -1209,13 +1222,16 @@ static bRC end_restore_job(bpContext* ctx, void* value) * Bareos is notifying us that a plugin name string was found, * and passing us the plugin command, so we can prepare for a restore. */ -static bRC startRestoreFile(bpContext* ctx, const char* cmd) { return bRC_OK; } +static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) +{ + return bRC_OK; +} /** * Bareos is notifying us that the plugin data has terminated, * so the restore for this particular file is done. */ -static bRC endRestoreFile(bpContext* ctx) { return bRC_OK; } +static bRC endRestoreFile(bplugin_private_context* ctx) { return bRC_OK; } /** * Create a parent directory using the cephfs API. @@ -1300,7 +1316,7 @@ static inline bool CephfsMakedirs(plugin_ctx* p_ctx, const char* directory) * CF_EXTRACT -- extract the file (i.e.call i/o routines) * CF_CREATED -- created, but no content to extract (typically directories) */ -static bRC createFile(bpContext* ctx, struct restore_pkt* rp) +static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) { int status; bool exists = false; @@ -1309,7 +1325,7 @@ static bRC createFile(bpContext* ctx, struct restore_pkt* rp) #else struct stat st; #endif - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -1483,11 +1499,12 @@ static bRC createFile(bpContext* ctx, struct restore_pkt* rp) return bRC_OK; } -static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp) +static bRC setFileAttributes(bplugin_private_context* ctx, + struct restore_pkt* rp) { int status; struct utimbuf times; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -1537,9 +1554,9 @@ static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp) /** * When using Incremental dump, all previous dumps are necessary */ -static bRC checkFile(bpContext* ctx, char* fname) +static bRC checkFile(bplugin_private_context* ctx, char* fname) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -1591,7 +1608,7 @@ static inline uint32_t serialize_acl_stream(PoolMem* buf, return offset + content_length; } -static bRC getAcl(bpContext* ctx, acl_pkt* ap) +static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap) { bool skip_xattr, abort_retrieval; int current_size; @@ -1599,7 +1616,7 @@ static bRC getAcl(bpContext* ctx, acl_pkt* ap) uint32_t content_length = 0; uint32_t expected_serialize_len; PoolMem xattr_value(PM_MESSAGE), serialized_acls(PM_MESSAGE); - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -1678,7 +1695,7 @@ static bRC getAcl(bpContext* ctx, acl_pkt* ap) return bRC_OK; } -static bRC setAcl(bpContext* ctx, acl_pkt* ap) +static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap) { int status; unser_declare; @@ -1686,7 +1703,7 @@ static bRC setAcl(bpContext* ctx, acl_pkt* ap) uint32_t xattr_value_length; PoolMem xattr_value(PM_MESSAGE), acl_name(PM_MESSAGE); - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -1724,14 +1741,14 @@ static bRC setAcl(bpContext* ctx, acl_pkt* ap) return bRC_OK; } -static bRC getXattr(bpContext* ctx, xattr_pkt* xp) +static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp) { char* bp; bool skip_xattr; int status, current_size; int32_t xattr_value_length; PoolMem xattr_value(PM_MESSAGE); - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -1891,10 +1908,10 @@ static bRC getXattr(bpContext* ctx, xattr_pkt* xp) return bRC_OK; } -static bRC setXattr(bpContext* ctx, xattr_pkt* xp) +static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp) { int status; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } diff --git a/core/src/plugins/filed/example/example-plugin-fd.cc b/core/src/plugins/filed/example/example-plugin-fd.cc index 2a8c3741bcc..816cbe64550 100644 --- a/core/src/plugins/filed/example/example-plugin-fd.cc +++ b/core/src/plugins/filed/example/example-plugin-fd.cc @@ -26,23 +26,30 @@ namespace filedaemon { /* Forward referenced functions */ -static bRC newPlugin(bpContext* ctx); -static bRC freePlugin(bpContext* ctx); -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value); -static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp); -static bRC endBackupFile(bpContext* ctx); -static bRC pluginIO(bpContext* ctx, struct io_pkt* io); -static bRC startRestoreFile(bpContext* ctx, const char* cmd); -static bRC endRestoreFile(bpContext* ctx); -static bRC createFile(bpContext* ctx, struct restore_pkt* rp); -static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp); -static bRC checkFile(bpContext* ctx, char* fname); -static bRC getAcl(bpContext* ctx, acl_pkt* ap); -static bRC setAcl(bpContext* ctx, acl_pkt* ap); -static bRC getXattr(bpContext* ctx, xattr_pkt* xp); -static bRC setXattr(bpContext* ctx, xattr_pkt* xp); +static bRC newPlugin(bplugin_private_context* ctx); +static bRC freePlugin(bplugin_private_context* ctx); +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC handlePluginEvent(bplugin_private_context* ctx, + bEvent* event, + void* value); +static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp); +static bRC endBackupFile(bplugin_private_context* ctx); +static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io); +static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd); +static bRC endRestoreFile(bplugin_private_context* ctx); +static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp); +static bRC setFileAttributes(bplugin_private_context* ctx, + struct restore_pkt* rp); +static bRC checkFile(bplugin_private_context* ctx, char* fname); +static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap); +static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap); +static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp); +static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp); /* Pointers to Bareos functions */ @@ -110,7 +117,7 @@ bRC unloadPlugin() * plugin instance must be thread safe and keep its own * local data. */ -static bRC newPlugin(bpContext* ctx) +static bRC newPlugin(bplugin_private_context* ctx) { int JobId = 0; bareos_core_functions->getBareosValue(ctx, bVarJobId, (void*)&JobId); @@ -126,7 +133,7 @@ static bRC newPlugin(bpContext* ctx) * Release everything concerning a particular instance of a * plugin. Normally called when the Job terminates. */ -static bRC freePlugin(bpContext* ctx) +static bRC freePlugin(bplugin_private_context* ctx) { int JobId = 0; bareos_core_functions->getBareosValue(ctx, bVarJobId, (void*)&JobId); @@ -138,7 +145,9 @@ static bRC freePlugin(bpContext* ctx) * Called by core code to get a variable from the plugin. * Not currently used. */ -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { // printf("plugin: getPluginValue var=%d\n", var); return bRC_OK; @@ -148,7 +157,9 @@ static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) * Called by core code to set a plugin variable. * Not currently used. */ -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { // printf("plugin: setPluginValue var=%d\n", var); return bRC_OK; @@ -159,7 +170,9 @@ static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) * plugin might want to know. The value depends on the * event. */ -static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) +static bRC handlePluginEvent(bplugin_private_context* ctx, + bEvent* event, + void* value) { char* name; @@ -216,7 +229,7 @@ static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) * The plugin can create "Virtual" files by giving them a * name that is not normally found on the file system. */ -static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) +static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) { return bRC_OK; } @@ -224,13 +237,13 @@ static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) /* * Done backing up a file. */ -static bRC endBackupFile(bpContext* ctx) { return bRC_OK; } +static bRC endBackupFile(bplugin_private_context* ctx) { return bRC_OK; } /* * Do actual I/O. Bareos calls this after startBackupFile * or after startRestoreFile to do the actual file input or output. */ -static bRC pluginIO(bpContext* ctx, struct io_pkt* io) +static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) { io->status = 0; io->io_errno = 0; @@ -251,9 +264,12 @@ static bRC pluginIO(bpContext* ctx, struct io_pkt* io) return bRC_OK; } -static bRC startRestoreFile(bpContext* ctx, const char* cmd) { return bRC_OK; } +static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) +{ + return bRC_OK; +} -static bRC endRestoreFile(bpContext* ctx) { return bRC_OK; } +static bRC endRestoreFile(bplugin_private_context* ctx) { return bRC_OK; } /* * Called here to give the plugin the information needed to @@ -262,28 +278,41 @@ static bRC endRestoreFile(bpContext* ctx) { return bRC_OK; } * This data is what is needed to create the file, but does * not contain actual file data. */ -static bRC createFile(bpContext* ctx, struct restore_pkt* rp) { return bRC_OK; } +static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) +{ + return bRC_OK; +} /* * Called after the file has been restored. This can be used to set directory * permissions, ... */ -static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp) +static bRC setFileAttributes(bplugin_private_context* ctx, + struct restore_pkt* rp) { return bRC_OK; } -static bRC getAcl(bpContext* ctx, acl_pkt* ap) { return bRC_OK; } +static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap) { return bRC_OK; } -static bRC setAcl(bpContext* ctx, acl_pkt* ap) { return bRC_OK; } +static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap) { return bRC_OK; } -static bRC getXattr(bpContext* ctx, xattr_pkt* xp) { return bRC_OK; } +static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp) +{ + return bRC_OK; +} -static bRC setXattr(bpContext* ctx, xattr_pkt* xp) { return bRC_OK; } +static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp) +{ + return bRC_OK; +} /* * When using Incremental dump, all previous dumps are necessary */ -static bRC checkFile(bpContext* ctx, char* fname) { return bRC_OK; } +static bRC checkFile(bplugin_private_context* ctx, char* fname) +{ + return bRC_OK; +} } /* namespace filedaemon */ diff --git a/core/src/plugins/filed/gfapi/gfapi-fd.cc b/core/src/plugins/filed/gfapi/gfapi-fd.cc index 744246fd877..b935917b0c0 100644 --- a/core/src/plugins/filed/gfapi/gfapi-fd.cc +++ b/core/src/plugins/filed/gfapi/gfapi-fd.cc @@ -65,28 +65,35 @@ static const int debuglevel = 150; /** * Forward referenced functions */ -static bRC newPlugin(bpContext* ctx); -static bRC freePlugin(bpContext* ctx); -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value); -static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp); -static bRC endBackupFile(bpContext* ctx); -static bRC pluginIO(bpContext* ctx, struct io_pkt* io); -static bRC startRestoreFile(bpContext* ctx, const char* cmd); -static bRC endRestoreFile(bpContext* ctx); -static bRC createFile(bpContext* ctx, struct restore_pkt* rp); -static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp); -static bRC checkFile(bpContext* ctx, char* fname); -static bRC getAcl(bpContext* ctx, acl_pkt* ap); -static bRC setAcl(bpContext* ctx, acl_pkt* ap); -static bRC getXattr(bpContext* ctx, xattr_pkt* xp); -static bRC setXattr(bpContext* ctx, xattr_pkt* xp); - -static bRC parse_plugin_definition(bpContext* ctx, void* value); -static bRC end_restore_job(bpContext* ctx, void* value); -static bRC setup_backup(bpContext* ctx, void* value); -static bRC setup_restore(bpContext* ctx, void* value); +static bRC newPlugin(bplugin_private_context* ctx); +static bRC freePlugin(bplugin_private_context* ctx); +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC handlePluginEvent(bplugin_private_context* ctx, + bEvent* event, + void* value); +static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp); +static bRC endBackupFile(bplugin_private_context* ctx); +static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io); +static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd); +static bRC endRestoreFile(bplugin_private_context* ctx); +static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp); +static bRC setFileAttributes(bplugin_private_context* ctx, + struct restore_pkt* rp); +static bRC checkFile(bplugin_private_context* ctx, char* fname); +static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap); +static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap); +static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp); +static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp); + +static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value); +static bRC end_restore_job(bplugin_private_context* ctx, void* value); +static bRC setup_backup(bplugin_private_context* ctx, void* value); +static bRC setup_restore(bplugin_private_context* ctx, void* value); /** * Pointers to Bareos functions @@ -344,14 +351,14 @@ bRC unloadPlugin() { return bRC_OK; } * * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bpContext* ctx) +static bRC newPlugin(bplugin_private_context* ctx) { plugin_ctx* p_ctx; p_ctx = (plugin_ctx*)malloc(sizeof(plugin_ctx)); if (!p_ctx) { return bRC_Error; } memset(p_ctx, 0, sizeof(plugin_ctx)); - ctx->pContext = (void*)p_ctx; /* set our context pointer */ + ctx->plugin_private_context = (void*)p_ctx; /* set our context pointer */ /* * Allocate some internal memory for: @@ -384,9 +391,9 @@ static bRC newPlugin(bpContext* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bpContext* ctx) +static bRC freePlugin(bplugin_private_context* ctx) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } Dmsg(ctx, debuglevel, "gfapi-fd: entering freePlugin\n"); @@ -437,7 +444,9 @@ static bRC freePlugin(bpContext* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { return bRC_OK; } @@ -445,7 +454,9 @@ static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { return bRC_OK; } @@ -453,10 +464,12 @@ static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) +static bRC handlePluginEvent(bplugin_private_context* ctx, + bEvent* event, + void* value) { bRC retval; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -512,12 +525,12 @@ static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) /** * Get the next file to backup. */ -static bRC get_next_file_to_backup(bpContext* ctx) +static bRC get_next_file_to_backup(bplugin_private_context* ctx) { int status; struct save_pkt sp; struct dirent* entry; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; /* * See if we are actually crawling the fs ourself or depending on an external @@ -836,10 +849,10 @@ static bRC get_next_file_to_backup(bpContext* ctx) /** * Start the backup of a specific file */ -static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) +static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) { int status; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; /* * Save the current flags used to save the next file. @@ -1025,9 +1038,9 @@ static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) /** * Done with backup of this file */ -static bRC endBackupFile(bpContext* ctx) +static bRC endBackupFile(bplugin_private_context* ctx) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -1098,12 +1111,12 @@ static inline void SetString(char** destination, char* value) * * gfapi:volume=gluster[+transport]\\://[server[:port]]/volname[/dir][?socket=...] */ -static bRC parse_plugin_definition(bpContext* ctx, void* value) +static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value) { int i; bool keep_existing; char *plugin_definition, *bp, *argument, *argument_value; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx || !value) { return bRC_Error; } @@ -1504,10 +1517,10 @@ static inline bool parse_gfapi_devicename(char* devicename, /** * Open a volume using GFAPI. */ -static bRC connect_to_gluster(bpContext* ctx, bool is_backup) +static bRC connect_to_gluster(bplugin_private_context* ctx, bool is_backup) { int status; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx->gfapi_volume_spec) { return bRC_Error; } @@ -1563,10 +1576,10 @@ static bRC connect_to_gluster(bpContext* ctx, bool is_backup) /** * Generic setup for performing a backup. */ -static bRC setup_backup(bpContext* ctx, void* value) +static bRC setup_backup(bplugin_private_context* ctx, void* value) { bRC retval = bRC_Error; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx || !value) { goto bail_out; } @@ -1704,9 +1717,9 @@ static bRC setup_backup(bpContext* ctx, void* value) /** * Generic setup for performing a restore. */ -static bRC setup_restore(bpContext* ctx, void* value) +static bRC setup_restore(bplugin_private_context* ctx, void* value) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx || !value) { return bRC_Error; } @@ -1725,9 +1738,9 @@ static bRC setup_restore(bpContext* ctx, void* value) /** * Bareos is calling us to do the actual I/O */ -static bRC pluginIO(bpContext* ctx, struct io_pkt* io) +static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -1819,10 +1832,10 @@ static bRC pluginIO(bpContext* ctx, struct io_pkt* io) /** * See if we need to do any postprocessing after the restore. */ -static bRC end_restore_job(bpContext* ctx, void* value) +static bRC end_restore_job(bplugin_private_context* ctx, void* value) { bRC retval = bRC_OK; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -1837,13 +1850,16 @@ static bRC end_restore_job(bpContext* ctx, void* value) * Bareos is notifying us that a plugin name string was found, * and passing us the plugin command, so we can prepare for a restore. */ -static bRC startRestoreFile(bpContext* ctx, const char* cmd) { return bRC_OK; } +static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) +{ + return bRC_OK; +} /** * Bareos is notifying us that the plugin data has terminated, * so the restore for this particular file is done. */ -static bRC endRestoreFile(bpContext* ctx) { return bRC_OK; } +static bRC endRestoreFile(bplugin_private_context* ctx) { return bRC_OK; } /** * This is called during restore to create the file (if necessary) We must @@ -1854,12 +1870,12 @@ static bRC endRestoreFile(bpContext* ctx) { return bRC_OK; } * CF_EXTRACT -- extract the file (i.e.call i/o routines) * CF_CREATED -- created, but no content to extract (typically directories) */ -static bRC createFile(bpContext* ctx, struct restore_pkt* rp) +static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) { int status; bool exists = false; struct stat st; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -2020,11 +2036,12 @@ static bRC createFile(bpContext* ctx, struct restore_pkt* rp) return bRC_OK; } -static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp) +static bRC setFileAttributes(bplugin_private_context* ctx, + struct restore_pkt* rp) { int status; struct timespec times[2]; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -2076,9 +2093,9 @@ static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp) /** * When using Incremental dump, all previous dumps are necessary */ -static bRC checkFile(bpContext* ctx, char* fname) +static bRC checkFile(bplugin_private_context* ctx, char* fname) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -2130,7 +2147,7 @@ static inline uint32_t serialize_acl_stream(PoolMem* buf, return offset + content_length; } -static bRC getAcl(bpContext* ctx, acl_pkt* ap) +static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap) { bool skip_xattr, abort_retrieval; int current_size; @@ -2138,7 +2155,7 @@ static bRC getAcl(bpContext* ctx, acl_pkt* ap) uint32_t content_length = 0; uint32_t expected_serialize_len; PoolMem xattr_value(PM_MESSAGE), serialized_acls(PM_MESSAGE); - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -2217,7 +2234,7 @@ static bRC getAcl(bpContext* ctx, acl_pkt* ap) return bRC_OK; } -static bRC setAcl(bpContext* ctx, acl_pkt* ap) +static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap) { int status; unser_declare; @@ -2225,7 +2242,7 @@ static bRC setAcl(bpContext* ctx, acl_pkt* ap) uint32_t xattr_value_length; PoolMem xattr_value(PM_MESSAGE), acl_name(PM_MESSAGE); - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -2263,14 +2280,14 @@ static bRC setAcl(bpContext* ctx, acl_pkt* ap) return bRC_OK; } -static bRC getXattr(bpContext* ctx, xattr_pkt* xp) +static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp) { char* bp; bool skip_xattr; int status, current_size; int32_t xattr_value_length; PoolMem xattr_value(PM_MESSAGE); - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -2431,10 +2448,10 @@ static bRC getXattr(bpContext* ctx, xattr_pkt* xp) return bRC_OK; } -static bRC setXattr(bpContext* ctx, xattr_pkt* xp) +static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp) { int status; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 69c25f26adb..43325f32632 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -58,66 +58,84 @@ static const int debuglevel = 150; /* "load>:..." */ /* Forward referenced functions */ -/* static bRC newPlugin(bpContext* bareos_plugin_ctx); */ -/* static bRC freePlugin(bpContext* bareos_plugin_ctx); */ -/* static bRC getPluginValue(bpContext* bareos_plugin_ctx, */ +/* static bRC newPlugin(bplugin_private_context* bareos_plugin_ctx); */ +/* static bRC freePlugin(bplugin_private_context* bareos_plugin_ctx); */ +/* static bRC getPluginValue(bplugin_private_context* bareos_plugin_ctx, */ /* pVariable var, */ /* void* value); */ -/* static bRC setPluginValue(bpContext* bareos_plugin_ctx, */ +/* static bRC setPluginValue(bplugin_private_context* bareos_plugin_ctx, */ /* pVariable var, */ /* void* value); */ -/* static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, */ +/* static bRC handlePluginEvent(bplugin_private_context* bareos_plugin_ctx, */ /* bEvent* event, */ /* void* value); */ -/* static bRC startBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* - * sp); */ -/* static bRC endBackupFile(bpContext* bareos_plugin_ctx); */ -/* static bRC pluginIO(bpContext* bareos_plugin_ctx, struct io_pkt* io); */ -/* static bRC startRestoreFile(bpContext* bareos_plugin_ctx, const char* cmd); - */ -/* static bRC endRestoreFile(bpContext* bareos_plugin_ctx); */ -/* static bRC createFile(bpContext* bareos_plugin_ctx, struct restore_pkt* rp); - */ -/* static bRC setFileAttributes(bpContext* bareos_plugin_ctx, */ +/* static bRC startBackupFile(bplugin_private_context* bareos_plugin_ctx, struct + * save_pkt* sp); */ +/* static bRC endBackupFile(bplugin_private_context* bareos_plugin_ctx); */ +/* static bRC pluginIO(bplugin_private_context* bareos_plugin_ctx, struct + * io_pkt* io); */ +/* static bRC startRestoreFile(bplugin_private_context* bareos_plugin_ctx, const + * char* cmd); + */ +/* static bRC endRestoreFile(bplugin_private_context* bareos_plugin_ctx); */ +/* static bRC createFile(bplugin_private_context* bareos_plugin_ctx, struct + * restore_pkt* rp); + */ +/* static bRC setFileAttributes(bplugin_private_context* bareos_plugin_ctx, */ /* struct restore_pkt* rp); */ -/* static bRC checkFile(bpContext* bareos_plugin_ctx, char* fname); */ -/* static bRC getAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap); */ -/* static bRC setAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap); */ -/* static bRC getXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp); */ -/* static bRC setXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp); */ -/* static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, */ +/* static bRC checkFile(bplugin_private_context* bareos_plugin_ctx, char* + * fname); */ +/* static bRC getAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap); + */ +/* static bRC setAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap); + */ +/* static bRC getXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* + * xp); */ +/* static bRC setXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* + * xp); */ +/* static bRC parse_plugin_definition(bplugin_private_context* + * bareos_plugin_ctx, */ /* void* value, */ /* PoolMem& plugin_options); */ -static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype); -static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value); -static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value); -static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, +static void PyErrorHandler(bplugin_private_context* bareos_plugin_ctx, + int msgtype); +static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, + void* value); +static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, + void* value); +static bRC PyGetPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value); -static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, +static bRC PySetPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value); -static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(bplugin_private_context* bareos_plugin_ctx, bEvent* event, void* value); -static bRC PyStartBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp); -static bRC PyEndBackupFile(bpContext* bareos_plugin_ctx); -static bRC PyPluginIO(bpContext* bareos_plugin_ctx, struct io_pkt* io); -static bRC PyStartRestoreFile(bpContext* bareos_plugin_ctx, const char* cmd); -static bRC PyEndRestoreFile(bpContext* bareos_plugin_ctx); -static bRC PyCreateFile(bpContext* bareos_plugin_ctx, struct restore_pkt* rp); -static bRC PySetFileAttributes(bpContext* bareos_plugin_ctx, +static bRC PyStartBackupFile(bplugin_private_context* bareos_plugin_ctx, + struct save_pkt* sp); +static bRC PyEndBackupFile(bplugin_private_context* bareos_plugin_ctx); +static bRC PyPluginIO(bplugin_private_context* bareos_plugin_ctx, + struct io_pkt* io); +static bRC PyStartRestoreFile(bplugin_private_context* bareos_plugin_ctx, + const char* cmd); +static bRC PyEndRestoreFile(bplugin_private_context* bareos_plugin_ctx); +static bRC PyCreateFile(bplugin_private_context* bareos_plugin_ctx, + struct restore_pkt* rp); +static bRC PySetFileAttributes(bplugin_private_context* bareos_plugin_ctx, struct restore_pkt* rp); -static bRC PyCheckFile(bpContext* bareos_plugin_ctx, char* fname); -static bRC PyGetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC PySetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC PyGetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC PySetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC PyRestoreObjectData(bpContext* bareos_plugin_ctx, +static bRC PyCheckFile(bplugin_private_context* bareos_plugin_ctx, char* fname); +static bRC PyGetAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap); +static bRC PySetAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap); +static bRC PyGetXattr(bplugin_private_context* bareos_plugin_ctx, + xattr_pkt* xp); +static bRC PySetXattr(bplugin_private_context* bareos_plugin_ctx, + xattr_pkt* xp); +static bRC PyRestoreObjectData(bplugin_private_context* bareos_plugin_ctx, struct restore_object_pkt* rop); -static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, +static bRC PyHandleBackupFile(bplugin_private_context* bareos_plugin_ctx, struct save_pkt* sp); /* Pointers to Bareos functions */ @@ -263,11 +281,11 @@ static void PyErrorHandler() */ /* 0); */ -/* // Extract capsule bareosfd.bpContext */ -/* void* ctx_from_bareosfd_module = PyCapsule_Import("bareosfd.bpContext", - * 0); */ +/* // Extract capsule bareosfd.bplugin_private_context */ +/* void* ctx_from_bareosfd_module = + * PyCapsule_Import("bareosfd.bplugin_private_context", 0); */ /* if (!ctx_from_bareosfd_module) { */ -/* printf("importing bareosfd.bpContext failed \n"); */ +/* printf("importing bareosfd.bplugin_private_context failed \n"); */ /* } */ /* // Extract capsules bareosfd.BareosCoreFunctions */ @@ -336,11 +354,11 @@ static void PyErrorHandler() * module path and the module to load. We also load the dictionary used * for looking up the Python methods. */ -static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) +static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject *sysPath, *mPath, *pName, *pFunc; /* See if we already setup the python search path. */ @@ -379,8 +397,10 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) plugin_priv_ctx->pyModuleFunctionsDict = PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ - /* Encode the bpContext so a Python method can pass it in on calling back.*/ - /* plugin_priv_ctx->py_bpContext = PyCreatebpContext(bareos_plugin_ctx); */ + /* Encode the bplugin_private_context so a Python method can pass it in on + * calling back.*/ + /* plugin_priv_ctx->py_bplugin_private_context = + * PyCreatebplugin_private_context(bareos_plugin_ctx); */ StorePluginContextInPythonModule(bareos_plugin_ctx); @@ -394,7 +414,8 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) if (!pPluginDefinition) { goto bail_out; } pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); - /* pFunc, plugin_priv_ctx->py_bpContext, pPluginDefinition, NULL); */ + /* pFunc, plugin_priv_ctx->py_bplugin_private_context, pPluginDefinition, + * NULL); */ Py_DECREF(pPluginDefinition); if (!pRetVal) { @@ -431,11 +452,12 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) * restore overrides can be passed in before the actual plugin options are * restored as part of the restore stream handling. */ -static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) +static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, + void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -474,27 +496,27 @@ static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) return retval; } -static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, +static bRC PyGetPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, +static bRC PySetPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(bplugin_private_context* bareos_plugin_ctx, bEvent* event, void* value) { bRC retval = bRC_Error; plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->pContext; + (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -762,11 +784,12 @@ static inline bool PySavePacketToNative( * The plugin can create "Virtual" files by giving them a * name that is not normally found on the file system. */ -static bRC PyStartBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) +static bRC PyStartBackupFile(bplugin_private_context* bareos_plugin_ctx, + struct save_pkt* sp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -814,11 +837,11 @@ static bRC PyStartBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) * If the plugin wishes to create another file and back it up, * then it must return bRC_More (not yet implemented). */ -static bRC PyEndBackupFile(bpContext* bareos_plugin_ctx) +static bRC PyEndBackupFile(bplugin_private_context* bareos_plugin_ctx) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -923,11 +946,12 @@ static inline bool PyIoPacketToNative(PyIoPacket* pIoPkt, struct io_pkt* io) * or after startRestoreFile to do the actual file * input or output. */ -static bRC PyPluginIO(bpContext* bareos_plugin_ctx, struct io_pkt* io) +static bRC PyPluginIO(bplugin_private_context* bareos_plugin_ctx, + struct io_pkt* io) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -975,11 +999,12 @@ static bRC PyPluginIO(bpContext* bareos_plugin_ctx, struct io_pkt* io) * Called when the first record is read from the Volume that was previously * written by the command plugin. */ -static bRC PyStartRestoreFile(bpContext* bareos_plugin_ctx, const char* cmd) +static bRC PyStartRestoreFile(bplugin_private_context* bareos_plugin_ctx, + const char* cmd) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -1018,11 +1043,11 @@ static bRC PyStartRestoreFile(bpContext* bareos_plugin_ctx, const char* cmd) /** * Called when a command plugin is done restoring a file. */ -static bRC PyEndRestoreFile(bpContext* bareos_plugin_ctx) +static bRC PyEndRestoreFile(bplugin_private_context* bareos_plugin_ctx) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -1099,11 +1124,12 @@ static inline void PyRestorePacketToNative(PyRestorePacket* pRestorePacket, * CF_EXTRACT -- extract the file (i.e.call i/o routines) * CF_CREATED -- created, but no content to extract (typically directories) */ -static bRC PyCreateFile(bpContext* bareos_plugin_ctx, struct restore_pkt* rp) +static bRC PyCreateFile(bplugin_private_context* bareos_plugin_ctx, + struct restore_pkt* rp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; if (!rp) { return bRC_Error; } @@ -1144,12 +1170,12 @@ static bRC PyCreateFile(bpContext* bareos_plugin_ctx, struct restore_pkt* rp) return retval; } -static bRC PySetFileAttributes(bpContext* bareos_plugin_ctx, +static bRC PySetFileAttributes(bplugin_private_context* bareos_plugin_ctx, struct restore_pkt* rp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; if (!rp) { return bRC_Error; } @@ -1188,11 +1214,11 @@ static bRC PySetFileAttributes(bpContext* bareos_plugin_ctx, return retval; } -static bRC PyCheckFile(bpContext* bareos_plugin_ctx, char* fname) +static bRC PyCheckFile(bplugin_private_context* bareos_plugin_ctx, char* fname) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; if (!fname) { return bRC_Error; } @@ -1268,11 +1294,11 @@ static inline bool PyAclPacketToNative(PyAclPacket* pAclPacket, return true; } -static bRC PyGetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) +static bRC PyGetAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; if (!ap) { return bRC_Error; } @@ -1316,11 +1342,11 @@ static bRC PyGetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) return retval; } -static bRC PySetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) +static bRC PySetAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; if (!ap) { return bRC_Error; } @@ -1422,11 +1448,11 @@ static inline bool PyXattrPacketToNative(PyXattrPacket* pXattrPacket, return true; } -static bRC PyGetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) +static bRC PyGetXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; if (!xp) { return bRC_Error; } @@ -1470,11 +1496,11 @@ static bRC PyGetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) return retval; } -static bRC PySetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) +static bRC PySetXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; if (!xp) { return bRC_Error; } @@ -1535,12 +1561,12 @@ static inline PyRestoreObject* NativeToPyRestoreObject( return pRestoreObject; } -static bRC PyRestoreObjectData(bpContext* bareos_plugin_ctx, +static bRC PyRestoreObjectData(bplugin_private_context* bareos_plugin_ctx, struct restore_object_pkt* rop) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; if (!rop) { return bRC_OK; } @@ -1579,11 +1605,12 @@ static bRC PyRestoreObjectData(bpContext* bareos_plugin_ctx, return retval; } -static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) +static bRC PyHandleBackupFile(bplugin_private_context* bareos_plugin_ctx, + struct save_pkt* sp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; if (!sp) { return bRC_Error; } @@ -1634,7 +1661,8 @@ static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } @@ -1705,7 +1733,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject* pyValue; @@ -1754,9 +1783,10 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); /* plugin_private_context* ppc = */ - /* (plugin_private_context*)bareos_plugin_ctx->pContext; */ + /* (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; */ if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; @@ -1777,7 +1807,8 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; @@ -1798,7 +1829,8 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -1839,7 +1871,8 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -1878,7 +1911,8 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } @@ -1905,7 +1939,8 @@ static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) { char* file = NULL; bRC retval = bRC_Error; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|z:BareosAddExclude", &file)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() @@ -1926,7 +1961,8 @@ static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) { char* file = NULL; bRC retval = bRC_Error; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|z:BareosAddInclude", &file)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() @@ -1947,7 +1983,8 @@ static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) { char* opts = NULL; bRC retval = bRC_Error; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|z:BareosAddOptions", &opts)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() @@ -1969,7 +2006,8 @@ static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) int type; char* item = NULL; bRC retval = bRC_Error; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|zi:BareosAddRegex", &item, &type)) { goto bail_out; } @@ -1992,7 +2030,8 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) int type; char* item = NULL; bRC retval = bRC_Error; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|zi:BareosAddWild", &item, &type)) { goto bail_out; @@ -2013,7 +2052,8 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewOptions")) { goto bail_out; } @@ -2031,7 +2071,8 @@ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewInclude")) { goto bail_out; } @@ -2049,7 +2090,8 @@ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewPreInclude")) { goto bail_out; } @@ -2068,7 +2110,8 @@ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) */ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); struct save_pkt sp; bRC retval = bRC_Error; @@ -2122,7 +2165,8 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) */ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); struct save_pkt sp; bRC retval = bRC_Error; PySavePacket* pSavePkt; @@ -2165,7 +2209,8 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) { bool all; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; @@ -2190,7 +2235,8 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) { bool all; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 28caf7bdcfd..2ff03799231 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -61,62 +61,75 @@ static const int debuglevel = 150; "load>:..." /* Forward referenced functions */ -static bRC newPlugin(bpContext* bareos_plugin_ctx); -static bRC freePlugin(bpContext* bareos_plugin_ctx); -static bRC getPluginValue(bpContext* bareos_plugin_ctx, +static bRC newPlugin(bplugin_private_context* bareos_plugin_ctx); +static bRC freePlugin(bplugin_private_context* bareos_plugin_ctx); +static bRC getPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value); -static bRC setPluginValue(bpContext* bareos_plugin_ctx, +static bRC setPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value); -static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, +static bRC handlePluginEvent(bplugin_private_context* bareos_plugin_ctx, bEvent* event, void* value); -static bRC startBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp); -static bRC endBackupFile(bpContext* bareos_plugin_ctx); -static bRC pluginIO(bpContext* bareos_plugin_ctx, struct io_pkt* io); -static bRC startRestoreFile(bpContext* bareos_plugin_ctx, const char* cmd); -static bRC endRestoreFile(bpContext* bareos_plugin_ctx); -static bRC createFile(bpContext* bareos_plugin_ctx, struct restore_pkt* rp); -static bRC setFileAttributes(bpContext* bareos_plugin_ctx, +static bRC startBackupFile(bplugin_private_context* bareos_plugin_ctx, + struct save_pkt* sp); +static bRC endBackupFile(bplugin_private_context* bareos_plugin_ctx); +static bRC pluginIO(bplugin_private_context* bareos_plugin_ctx, + struct io_pkt* io); +static bRC startRestoreFile(bplugin_private_context* bareos_plugin_ctx, + const char* cmd); +static bRC endRestoreFile(bplugin_private_context* bareos_plugin_ctx); +static bRC createFile(bplugin_private_context* bareos_plugin_ctx, + struct restore_pkt* rp); +static bRC setFileAttributes(bplugin_private_context* bareos_plugin_ctx, struct restore_pkt* rp); -static bRC checkFile(bpContext* bareos_plugin_ctx, char* fname); -static bRC getAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC setAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC getXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC setXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, +static bRC checkFile(bplugin_private_context* bareos_plugin_ctx, char* fname); +static bRC getAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap); +static bRC setAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap); +static bRC getXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* xp); +static bRC setXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* xp); +static bRC parse_plugin_definition(bplugin_private_context* bareos_plugin_ctx, void* value, PoolMem& plugin_options); -static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype); -static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value); -static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value); -static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, +static void PyErrorHandler(bplugin_private_context* bareos_plugin_ctx, + int msgtype); +static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, + void* value); +static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, + void* value); +static bRC PyGetPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value); -static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, +static bRC PySetPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value); -static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(bplugin_private_context* bareos_plugin_ctx, bEvent* event, void* value); -static bRC PyStartBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp); -static bRC PyEndBackupFile(bpContext* bareos_plugin_ctx); -static bRC PyPluginIO(bpContext* bareos_plugin_ctx, struct io_pkt* io); -static bRC PyStartRestoreFile(bpContext* bareos_plugin_ctx, const char* cmd); -static bRC PyEndRestoreFile(bpContext* bareos_plugin_ctx); -static bRC PyCreateFile(bpContext* bareos_plugin_ctx, struct restore_pkt* rp); -static bRC PySetFileAttributes(bpContext* bareos_plugin_ctx, +static bRC PyStartBackupFile(bplugin_private_context* bareos_plugin_ctx, + struct save_pkt* sp); +static bRC PyEndBackupFile(bplugin_private_context* bareos_plugin_ctx); +static bRC PyPluginIO(bplugin_private_context* bareos_plugin_ctx, + struct io_pkt* io); +static bRC PyStartRestoreFile(bplugin_private_context* bareos_plugin_ctx, + const char* cmd); +static bRC PyEndRestoreFile(bplugin_private_context* bareos_plugin_ctx); +static bRC PyCreateFile(bplugin_private_context* bareos_plugin_ctx, + struct restore_pkt* rp); +static bRC PySetFileAttributes(bplugin_private_context* bareos_plugin_ctx, struct restore_pkt* rp); -static bRC PyCheckFile(bpContext* bareos_plugin_ctx, char* fname); -static bRC PyGetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC PySetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC PyGetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC PySetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC PyRestoreObjectData(bpContext* bareos_plugin_ctx, +static bRC PyCheckFile(bplugin_private_context* bareos_plugin_ctx, char* fname); +static bRC PyGetAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap); +static bRC PySetAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap); +static bRC PyGetXattr(bplugin_private_context* bareos_plugin_ctx, + xattr_pkt* xp); +static bRC PySetXattr(bplugin_private_context* bareos_plugin_ctx, + xattr_pkt* xp); +static bRC PyRestoreObjectData(bplugin_private_context* bareos_plugin_ctx, struct restore_object_pkt* rop); -static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, +static bRC PyHandleBackupFile(bplugin_private_context* bareos_plugin_ctx, struct save_pkt* sp); /* Pointers to Bareos functions */ @@ -259,10 +272,11 @@ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", 0); - // Extract capsule bareosfd.bpContext - void* ctx_from_bareosfd_module = PyCapsule_Import("bareosfd.bpContext", 0); + // Extract capsule bareosfd.bplugin_private_context + void* ctx_from_bareosfd_module = + PyCapsule_Import("bareosfd.bplugin_private_context", 0); if (!ctx_from_bareosfd_module) { - printf("importing bareosfd.bpContext failed \n"); + printf("importing bareosfd.bplugin_private_context failed \n"); } // Extract capsules bareosfd.BareosCoreFunctions @@ -329,14 +343,14 @@ bRC unloadPlugin() * plugin instance must be thread safe and keep its own * local data. */ -static bRC newPlugin(bpContext* bareos_plugin_ctx) +static bRC newPlugin(bplugin_private_context* bareos_plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = (struct plugin_private_context*)malloc( sizeof(struct plugin_private_context)); if (!plugin_priv_ctx) { return bRC_Error; } memset(plugin_priv_ctx, 0, sizeof(struct plugin_private_context)); - bareos_plugin_ctx->pContext = + bareos_plugin_ctx->plugin_private_context = (void*)plugin_priv_ctx; /* set our context pointer */ plugin_priv_ctx->bareos_core_functions = bareos_core_functions; @@ -360,10 +374,10 @@ static bRC newPlugin(bpContext* bareos_plugin_ctx) * Release everything concerning a particular instance of a * plugin. Normally called when the Job terminates. */ -static bRC freePlugin(bpContext* bareos_plugin_ctx) +static bRC freePlugin(bplugin_private_context* bareos_plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { return bRC_Error; } @@ -395,13 +409,13 @@ static bRC freePlugin(bpContext* bareos_plugin_ctx) PyEval_ReleaseLock(); free(plugin_priv_ctx); - bareos_plugin_ctx->pContext = NULL; + bareos_plugin_ctx->plugin_private_context = NULL; return bRC_OK; } -static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, +static bRC handlePluginEvent(bplugin_private_context* bareos_plugin_ctx, bEvent* event, void* value) { @@ -409,7 +423,7 @@ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, bool event_dispatched = false; PoolMem plugin_options(PM_FNAME); plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->pContext; + (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } @@ -565,11 +579,12 @@ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, * The plugin can create "Virtual" files by giving them a * name that is not normally found on the file system. */ -static bRC startBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) +static bRC startBackupFile(bplugin_private_context* bareos_plugin_ctx, + struct save_pkt* sp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } @@ -616,11 +631,11 @@ static bRC startBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) /** * Done backing up a file. */ -static bRC endBackupFile(bpContext* bareos_plugin_ctx) +static bRC endBackupFile(bplugin_private_context* bareos_plugin_ctx) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } @@ -637,11 +652,12 @@ static bRC endBackupFile(bpContext* bareos_plugin_ctx) * or after startRestoreFile to do the actual file * input or output. */ -static bRC pluginIO(bpContext* bareos_plugin_ctx, struct io_pkt* io) +static bRC pluginIO(bplugin_private_context* bareos_plugin_ctx, + struct io_pkt* io) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } @@ -658,11 +674,12 @@ static bRC pluginIO(bpContext* bareos_plugin_ctx, struct io_pkt* io) /** * Start restore of a file. */ -static bRC startRestoreFile(bpContext* bareos_plugin_ctx, const char* cmd) +static bRC startRestoreFile(bplugin_private_context* bareos_plugin_ctx, + const char* cmd) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } @@ -677,11 +694,11 @@ static bRC startRestoreFile(bpContext* bareos_plugin_ctx, const char* cmd) /** * Done restoring a file. */ -static bRC endRestoreFile(bpContext* bareos_plugin_ctx) +static bRC endRestoreFile(bplugin_private_context* bareos_plugin_ctx) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } @@ -700,11 +717,12 @@ static bRC endRestoreFile(bpContext* bareos_plugin_ctx) * This data is what is needed to create the file, but does * not contain actual file data. */ -static bRC createFile(bpContext* bareos_plugin_ctx, struct restore_pkt* rp) +static bRC createFile(bplugin_private_context* bareos_plugin_ctx, + struct restore_pkt* rp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } @@ -720,12 +738,12 @@ static bRC createFile(bpContext* bareos_plugin_ctx, struct restore_pkt* rp) * Called after the file has been restored. This can be used to * set directory permissions, ... */ -static bRC setFileAttributes(bpContext* bareos_plugin_ctx, +static bRC setFileAttributes(bplugin_private_context* bareos_plugin_ctx, struct restore_pkt* rp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } @@ -740,11 +758,11 @@ static bRC setFileAttributes(bpContext* bareos_plugin_ctx, /** * When using Incremental dump, all previous dumps are necessary */ -static bRC checkFile(bpContext* bareos_plugin_ctx, char* fname) +static bRC checkFile(bplugin_private_context* bareos_plugin_ctx, char* fname) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } @@ -760,11 +778,11 @@ static bRC checkFile(bpContext* bareos_plugin_ctx, char* fname) /** */ -static bRC getAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) +static bRC getAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } @@ -778,11 +796,11 @@ static bRC getAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) /** */ -static bRC setAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) +static bRC setAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } @@ -796,11 +814,11 @@ static bRC setAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) /** */ -static bRC getXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) +static bRC getXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } @@ -814,11 +832,11 @@ static bRC getXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) /** */ -static bRC setXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) +static bRC setXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } @@ -848,7 +866,7 @@ static inline void SetStringIfNull(char** destination, char* value) * * python:module_path=:module_name=:... */ -static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, +static bRC parse_plugin_definition(bplugin_private_context* bareos_plugin_ctx, void* value, PoolMem& plugin_options) { @@ -858,7 +876,7 @@ static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, PoolMem plugin_definition(PM_FNAME); char *bp, *argument, *argument_value; plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->pContext; + (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!value) { return bRC_Error; } @@ -1044,11 +1062,11 @@ static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, * module path and the module to load. We also load the dictionary used * for looking up the Python methods. */ -static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) +static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject *sysPath, *mPath, *pName, *pFunc; /* See if we already setup the python search path. */ @@ -1087,8 +1105,10 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) plugin_priv_ctx->pyModuleFunctionsDict = PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ - /* Encode the bpContext so a Python method can pass it in on calling back.*/ - /* plugin_priv_ctx->py_bpContext = PyCreatebpContext(bareos_plugin_ctx); */ + /* Encode the bplugin_private_context so a Python method can pass it in on + * calling back.*/ + /* plugin_priv_ctx->py_bplugin_private_context = + * PyCreatebplugin_private_context(bareos_plugin_ctx); */ StorePluginContextInPythonModule(bareos_plugin_ctx); @@ -1102,7 +1122,8 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) if (!pPluginDefinition) { goto bail_out; } pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); - /* pFunc, plugin_priv_ctx->py_bpContext, pPluginDefinition, NULL); */ + /* pFunc, plugin_priv_ctx->py_bplugin_private_context, pPluginDefinition, + * NULL); */ Py_DECREF(pPluginDefinition); if (!pRetVal) { @@ -1139,11 +1160,12 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) * restore overrides can be passed in before the actual plugin options are * restored as part of the restore stream handling. */ -static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) +static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, + void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -1182,27 +1204,27 @@ static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) return retval; } -static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, +static bRC PyGetPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, +static bRC PySetPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(bplugin_private_context* bareos_plugin_ctx, bEvent* event, void* value) { bRC retval = bRC_Error; plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->pContext; + (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -1470,11 +1492,12 @@ static inline bool PySavePacketToNative( * The plugin can create "Virtual" files by giving them a * name that is not normally found on the file system. */ -static bRC PyStartBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) +static bRC PyStartBackupFile(bplugin_private_context* bareos_plugin_ctx, + struct save_pkt* sp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -1522,11 +1545,11 @@ static bRC PyStartBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) * If the plugin wishes to create another file and back it up, * then it must return bRC_More (not yet implemented). */ -static bRC PyEndBackupFile(bpContext* bareos_plugin_ctx) +static bRC PyEndBackupFile(bplugin_private_context* bareos_plugin_ctx) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -1631,11 +1654,12 @@ static inline bool PyIoPacketToNative(PyIoPacket* pIoPkt, struct io_pkt* io) * or after startRestoreFile to do the actual file * input or output. */ -static bRC PyPluginIO(bpContext* bareos_plugin_ctx, struct io_pkt* io) +static bRC PyPluginIO(bplugin_private_context* bareos_plugin_ctx, + struct io_pkt* io) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -1683,11 +1707,12 @@ static bRC PyPluginIO(bpContext* bareos_plugin_ctx, struct io_pkt* io) * Called when the first record is read from the Volume that was previously * written by the command plugin. */ -static bRC PyStartRestoreFile(bpContext* bareos_plugin_ctx, const char* cmd) +static bRC PyStartRestoreFile(bplugin_private_context* bareos_plugin_ctx, + const char* cmd) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -1726,11 +1751,11 @@ static bRC PyStartRestoreFile(bpContext* bareos_plugin_ctx, const char* cmd) /** * Called when a command plugin is done restoring a file. */ -static bRC PyEndRestoreFile(bpContext* bareos_plugin_ctx) +static bRC PyEndRestoreFile(bplugin_private_context* bareos_plugin_ctx) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -1807,11 +1832,12 @@ static inline void PyRestorePacketToNative(PyRestorePacket* pRestorePacket, * CF_EXTRACT -- extract the file (i.e.call i/o routines) * CF_CREATED -- created, but no content to extract (typically directories) */ -static bRC PyCreateFile(bpContext* bareos_plugin_ctx, struct restore_pkt* rp) +static bRC PyCreateFile(bplugin_private_context* bareos_plugin_ctx, + struct restore_pkt* rp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; if (!rp) { return bRC_Error; } @@ -1852,12 +1878,12 @@ static bRC PyCreateFile(bpContext* bareos_plugin_ctx, struct restore_pkt* rp) return retval; } -static bRC PySetFileAttributes(bpContext* bareos_plugin_ctx, +static bRC PySetFileAttributes(bplugin_private_context* bareos_plugin_ctx, struct restore_pkt* rp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; if (!rp) { return bRC_Error; } @@ -1896,11 +1922,11 @@ static bRC PySetFileAttributes(bpContext* bareos_plugin_ctx, return retval; } -static bRC PyCheckFile(bpContext* bareos_plugin_ctx, char* fname) +static bRC PyCheckFile(bplugin_private_context* bareos_plugin_ctx, char* fname) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; if (!fname) { return bRC_Error; } @@ -1976,11 +2002,11 @@ static inline bool PyAclPacketToNative(PyAclPacket* pAclPacket, return true; } -static bRC PyGetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) +static bRC PyGetAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; if (!ap) { return bRC_Error; } @@ -2024,11 +2050,11 @@ static bRC PyGetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) return retval; } -static bRC PySetAcl(bpContext* bareos_plugin_ctx, acl_pkt* ap) +static bRC PySetAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; if (!ap) { return bRC_Error; } @@ -2130,11 +2156,11 @@ static inline bool PyXattrPacketToNative(PyXattrPacket* pXattrPacket, return true; } -static bRC PyGetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) +static bRC PyGetXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; if (!xp) { return bRC_Error; } @@ -2178,11 +2204,11 @@ static bRC PyGetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) return retval; } -static bRC PySetXattr(bpContext* bareos_plugin_ctx, xattr_pkt* xp) +static bRC PySetXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; if (!xp) { return bRC_Error; } @@ -2243,12 +2269,12 @@ static inline PyRestoreObject* NativeToPyRestoreObject( return pRestoreObject; } -static bRC PyRestoreObjectData(bpContext* bareos_plugin_ctx, +static bRC PyRestoreObjectData(bplugin_private_context* bareos_plugin_ctx, struct restore_object_pkt* rop) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; if (!rop) { return bRC_OK; } @@ -2287,11 +2313,12 @@ static bRC PyRestoreObjectData(bpContext* bareos_plugin_ctx, return retval; } -static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) +static bRC PyHandleBackupFile(bplugin_private_context* bareos_plugin_ctx, + struct save_pkt* sp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; if (!sp) { return bRC_Error; } @@ -2342,7 +2369,8 @@ static bRC PyHandleBackupFile(bpContext* bareos_plugin_ctx, struct save_pkt* sp) static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } @@ -2413,7 +2441,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject* pyValue; @@ -2464,9 +2493,10 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); /* plugin_private_context* ppc = */ - /* (plugin_private_context*)bareos_plugin_ctx->pContext; */ + /* (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; */ if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; @@ -2487,7 +2517,8 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; @@ -2508,7 +2539,8 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -2549,7 +2581,8 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -2588,7 +2621,8 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } @@ -2615,7 +2649,8 @@ static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) { char* file = NULL; bRC retval = bRC_Error; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|z:BareosAddExclude", &file)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() @@ -2636,7 +2671,8 @@ static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) { char* file = NULL; bRC retval = bRC_Error; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|z:BareosAddInclude", &file)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() @@ -2657,7 +2693,8 @@ static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) { char* opts = NULL; bRC retval = bRC_Error; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|z:BareosAddOptions", &opts)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() @@ -2679,7 +2716,8 @@ static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) int type; char* item = NULL; bRC retval = bRC_Error; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|zi:BareosAddRegex", &item, &type)) { goto bail_out; } @@ -2702,7 +2740,8 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) int type; char* item = NULL; bRC retval = bRC_Error; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|zi:BareosAddWild", &item, &type)) { goto bail_out; @@ -2723,7 +2762,8 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewOptions")) { goto bail_out; } @@ -2741,7 +2781,8 @@ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewInclude")) { goto bail_out; } @@ -2759,7 +2800,8 @@ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewPreInclude")) { goto bail_out; } @@ -2778,7 +2820,8 @@ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) */ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); struct save_pkt sp; bRC retval = bRC_Error; @@ -2832,7 +2875,8 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) */ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) { - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); struct save_pkt sp; bRC retval = bRC_Error; PySavePacket* pSavePkt; @@ -2875,7 +2919,8 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) { bool all; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; @@ -2900,7 +2945,8 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) { bool all; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; diff --git a/core/src/plugins/filed/python/python-fd.h b/core/src/plugins/filed/python/python-fd.h index 0b89c2259bf..364f4e66d36 100644 --- a/core/src/plugins/filed/python/python-fd.h +++ b/core/src/plugins/filed/python/python-fd.h @@ -777,20 +777,22 @@ MOD_INIT(bareosfd) MOD_DEF(m, PYTHON_MODULE_NAME_QUOTED, NULL, Methods) - /* add bpContext Capsule */ + /* add bplugin_private_context Capsule */ PyObject* PyModulePluginContext = PyCapsule_New((void*)&bareos_plugin_context, - PYTHON_MODULE_NAME_QUOTED ".bpContext", NULL); + PYTHON_MODULE_NAME_QUOTED ".bplugin_private_context", NULL); if (!PyModulePluginContext) { - printf(PYTHON_MODULE_NAME_QUOTED ":bpContext PyCapsule_New failed\n"); + printf(PYTHON_MODULE_NAME_QUOTED + ":bplugin_private_context PyCapsule_New failed\n"); return MOD_ERROR_VAL; } if (PyModulePluginContext) { - PyModule_AddObject(m, "bpContext", PyModulePluginContext); - printf(PYTHON_MODULE_NAME_QUOTED ": added bpContext@%p\n", + PyModule_AddObject(m, "bplugin_private_context", PyModulePluginContext); + printf(PYTHON_MODULE_NAME_QUOTED ": added bplugin_private_context@%p\n", &bareos_plugin_context); } else { - printf(PYTHON_MODULE_NAME_QUOTED ":bpContext PyModule_AddObject failed\n"); + printf(PYTHON_MODULE_NAME_QUOTED + ":bplugin_private_context PyModule_AddObject failed\n"); return MOD_ERROR_VAL; } diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index 22d569fd4c6..9eccfe5d512 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -69,21 +69,31 @@ static void PyErrorHandler() } // using namespace filedaemon; -bRC bareosRegisterEvents(bpContext* ctx, int nr_events, ...) { return bRC_OK; }; -bRC bareosUnRegisterEvents(bpContext* ctx, int nr_events, ...) +bRC bareosRegisterEvents(bplugin_private_context* ctx, int nr_events, ...) { return bRC_OK; }; -bRC bareosGetInstanceCount(bpContext* ctx, int* ret) { return bRC_OK; }; -bRC bareosGetValue(bpContext* ctx, filedaemon::bVariable var, void* value) +bRC bareosUnRegisterEvents(bplugin_private_context* ctx, int nr_events, ...) { return bRC_OK; }; -bRC bareosSetValue(bpContext* ctx, filedaemon::bVariable var, void* value) +bRC bareosGetInstanceCount(bplugin_private_context* ctx, int* ret) { return bRC_OK; }; -bRC bareosJobMsg(bpContext* ctx, +bRC bareosGetValue(bplugin_private_context* ctx, + filedaemon::bVariable var, + void* value) +{ + return bRC_OK; +}; +bRC bareosSetValue(bplugin_private_context* ctx, + filedaemon::bVariable var, + void* value) +{ + return bRC_OK; +}; +bRC bareosJobMsg(bplugin_private_context* ctx, const char* file, int line, int type, @@ -95,7 +105,7 @@ bRC bareosJobMsg(bpContext* ctx, type, (int64_t)mtime, fmt); return bRC_OK; }; -bRC bareosDebugMsg(bpContext* ctx, +bRC bareosDebugMsg(bplugin_private_context* ctx, const char* file, int line, int level, @@ -106,41 +116,58 @@ bRC bareosDebugMsg(bpContext* ctx, fmt); return bRC_OK; }; -void* bareosMalloc(bpContext* ctx, const char* file, int line, size_t size) +void* bareosMalloc(bplugin_private_context* ctx, + const char* file, + int line, + size_t size) { return NULL; }; -void bareosFree(bpContext* ctx, const char* file, int line, void* mem) +void bareosFree(bplugin_private_context* ctx, + const char* file, + int line, + void* mem) { return; }; -bRC bareosAddExclude(bpContext* ctx, const char* file) { return bRC_OK; }; -bRC bareosAddInclude(bpContext* ctx, const char* file) { return bRC_OK; }; -bRC bareosAddOptions(bpContext* ctx, const char* opts) { return bRC_OK; }; -bRC bareosAddRegex(bpContext* ctx, const char* item, int type) +bRC bareosAddExclude(bplugin_private_context* ctx, const char* file) +{ + return bRC_OK; +}; +bRC bareosAddInclude(bplugin_private_context* ctx, const char* file) +{ + return bRC_OK; +}; +bRC bareosAddOptions(bplugin_private_context* ctx, const char* opts) +{ + return bRC_OK; +}; +bRC bareosAddRegex(bplugin_private_context* ctx, const char* item, int type) { return bRC_OK; }; -bRC bareosAddWild(bpContext* ctx, const char* item, int type) +bRC bareosAddWild(bplugin_private_context* ctx, const char* item, int type) { return bRC_OK; }; -bRC bareosNewOptions(bpContext* ctx) { return bRC_OK; }; -bRC bareosNewInclude(bpContext* ctx) { return bRC_OK; }; -bRC bareosNewPreInclude(bpContext* ctx) { return bRC_OK; }; -bRC bareosCheckChanges(bpContext* ctx, struct filedaemon::save_pkt* sp) +bRC bareosNewOptions(bplugin_private_context* ctx) { return bRC_OK; }; +bRC bareosNewInclude(bplugin_private_context* ctx) { return bRC_OK; }; +bRC bareosNewPreInclude(bplugin_private_context* ctx) { return bRC_OK; }; +bRC bareosCheckChanges(bplugin_private_context* ctx, + struct filedaemon::save_pkt* sp) { return bRC_OK; }; -bRC bareosAcceptFile(bpContext* ctx, struct filedaemon::save_pkt* sp) +bRC bareosAcceptFile(bplugin_private_context* ctx, + struct filedaemon::save_pkt* sp) { return bRC_OK; }; /* Need fname and statp */ -bRC bareosSetSeenBitmap(bpContext* ctx, bool all, char* fname) +bRC bareosSetSeenBitmap(bplugin_private_context* ctx, bool all, char* fname) { return bRC_OK; }; -bRC bareosClearSeenBitmap(bpContext* ctx, bool all, char* fname) +bRC bareosClearSeenBitmap(bplugin_private_context* ctx, bool all, char* fname) { return bRC_OK; }; @@ -192,9 +219,10 @@ int main(int argc, char* argv[]) /* printf("bareos_plugin_context %p\n", &bareos_plugin_context); */ // Extract capsules pointer from bareosfd module - void* ctx_from_bareosfd_module = PyCapsule_Import("bareosfd.bpContext", 0); + void* ctx_from_bareosfd_module = + PyCapsule_Import("bareosfd.bplugin_private_context", 0); if (!ctx_from_bareosfd_module) { - printf("importing bareosfd.bpContext failed \n"); + printf("importing bareosfd.bplugin_private_context failed \n"); } // Extract capsules pointer from bareosfd module diff --git a/core/src/plugins/filed/rados/rados-fd.cc b/core/src/plugins/filed/rados/rados-fd.cc index 7b75b29926d..98897fd799c 100644 --- a/core/src/plugins/filed/rados/rados-fd.cc +++ b/core/src/plugins/filed/rados/rados-fd.cc @@ -58,28 +58,35 @@ static const int debuglevel = 150; /** * Forward referenced functions */ -static bRC newPlugin(bpContext* ctx); -static bRC freePlugin(bpContext* ctx); -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value); -static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp); -static bRC endBackupFile(bpContext* ctx); -static bRC pluginIO(bpContext* ctx, struct io_pkt* io); -static bRC startRestoreFile(bpContext* ctx, const char* cmd); -static bRC endRestoreFile(bpContext* ctx); -static bRC createFile(bpContext* ctx, struct restore_pkt* rp); -static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp); -static bRC checkFile(bpContext* ctx, char* fname); -static bRC getAcl(bpContext* ctx, acl_pkt* ap); -static bRC setAcl(bpContext* ctx, acl_pkt* ap); -static bRC getXattr(bpContext* ctx, xattr_pkt* xp); -static bRC setXattr(bpContext* ctx, xattr_pkt* xp); - -static bRC parse_plugin_definition(bpContext* ctx, void* value); -static bRC setup_backup(bpContext* ctx, void* value); -static bRC setup_restore(bpContext* ctx, void* value); -static bRC end_restore_job(bpContext* ctx, void* value); +static bRC newPlugin(bplugin_private_context* ctx); +static bRC freePlugin(bplugin_private_context* ctx); +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC handlePluginEvent(bplugin_private_context* ctx, + bEvent* event, + void* value); +static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp); +static bRC endBackupFile(bplugin_private_context* ctx); +static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io); +static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd); +static bRC endRestoreFile(bplugin_private_context* ctx); +static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp); +static bRC setFileAttributes(bplugin_private_context* ctx, + struct restore_pkt* rp); +static bRC checkFile(bplugin_private_context* ctx, char* fname); +static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap); +static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap); +static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp); +static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp); + +static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value); +static bRC setup_backup(bplugin_private_context* ctx, void* value); +static bRC setup_restore(bplugin_private_context* ctx, void* value); +static bRC end_restore_job(bplugin_private_context* ctx, void* value); /** * Pointers to Bareos functions @@ -209,14 +216,14 @@ bRC unloadPlugin() { return bRC_OK; } * * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bpContext* ctx) +static bRC newPlugin(bplugin_private_context* ctx) { plugin_ctx* p_ctx; p_ctx = (plugin_ctx*)malloc(sizeof(plugin_ctx)); if (!p_ctx) { return bRC_Error; } memset(p_ctx, 0, sizeof(plugin_ctx)); - ctx->pContext = (void*)p_ctx; /* set our context pointer */ + ctx->plugin_private_context = (void*)p_ctx; /* set our context pointer */ p_ctx->next_filename = GetPoolMemory(PM_FNAME); bareos_core_functions->getBareosValue(ctx, bVarJobId, (void*)&p_ctx->JobId); @@ -235,9 +242,9 @@ static bRC newPlugin(bpContext* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bpContext* ctx) +static bRC freePlugin(bplugin_private_context* ctx) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } Dmsg(ctx, debuglevel, "rados-fd: entering freePlugin\n"); @@ -281,7 +288,9 @@ static bRC freePlugin(bpContext* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { return bRC_OK; } @@ -289,7 +298,9 @@ static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { return bRC_OK; } @@ -297,10 +308,12 @@ static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) +static bRC handlePluginEvent(bplugin_private_context* ctx, + bEvent* event, + void* value) { bRC retval; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -358,11 +371,11 @@ static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) * - Get the next objectname from the list iterator. * - Check using AcceptFile if it matches the fileset. */ -static bRC get_next_object_to_backup(bpContext* ctx) +static bRC get_next_object_to_backup(bplugin_private_context* ctx) { int status; struct save_pkt sp; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; while (1) { #if defined(HAVE_RADOS_NAMESPACES) && defined(HAVE_RADOS_NOBJECTS_LIST) @@ -433,9 +446,9 @@ static bRC get_next_object_to_backup(bpContext* ctx) /** * Start the backup of a specific file */ -static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) +static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -476,9 +489,9 @@ static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) /** * Done with backup of this file */ -static bRC endBackupFile(bpContext* ctx) +static bRC endBackupFile(bplugin_private_context* ctx) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx || !p_ctx->list_iterator) { return bRC_Error; } @@ -535,12 +548,12 @@ static inline void SetString(char** destination, char* value) * * rados:conffile=:namespace=:clientid=:clustername=:username=:snapshotname=: */ -static bRC parse_plugin_definition(bpContext* ctx, void* value) +static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value) { int i; bool keep_existing; char *plugin_definition, *bp, *argument, *argument_value; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx || !value) { return bRC_Error; } @@ -675,13 +688,13 @@ static bRC parse_plugin_definition(bpContext* ctx, void* value) /** * Connect via RADOS protocol to a CEPH cluster. */ -static bRC connect_to_rados(bpContext* ctx) +static bRC connect_to_rados(bplugin_private_context* ctx) { int status; #if LIBRADOS_VERSION_CODE >= 17408 uint64_t rados_flags = 0; #endif - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; /* * See if we need to initialize the cluster connection. @@ -768,10 +781,10 @@ static bRC connect_to_rados(bpContext* ctx) /** * Generic setup for performing a backup. */ -static bRC setup_backup(bpContext* ctx, void* value) +static bRC setup_backup(bplugin_private_context* ctx, void* value) { int status; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx || !value) { return bRC_Error; } @@ -860,9 +873,9 @@ static bRC setup_backup(bpContext* ctx, void* value) /** * Generic setup for performing a restore. */ -static bRC setup_restore(bpContext* ctx, void* value) +static bRC setup_restore(bplugin_private_context* ctx, void* value) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx || !value) { return bRC_Error; } @@ -874,10 +887,10 @@ static bRC setup_restore(bpContext* ctx, void* value) /** * Bareos is calling us to do the actual I/O */ -static bRC pluginIO(bpContext* ctx, struct io_pkt* io) +static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) { int io_count; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -942,10 +955,10 @@ static bRC pluginIO(bpContext* ctx, struct io_pkt* io) /** * See if we need to do any postprocessing after the restore. */ -static bRC end_restore_job(bpContext* ctx, void* value) +static bRC end_restore_job(bplugin_private_context* ctx, void* value) { bRC retval = bRC_OK; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -960,13 +973,16 @@ static bRC end_restore_job(bpContext* ctx, void* value) * Bareos is notifying us that a plugin name string was found, * and passing us the plugin command, so we can prepare for a restore. */ -static bRC startRestoreFile(bpContext* ctx, const char* cmd) { return bRC_OK; } +static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) +{ + return bRC_OK; +} /** * Bareos is notifying us that the plugin data has terminated, * so the restore for this particular file is done. */ -static bRC endRestoreFile(bpContext* ctx) { return bRC_OK; } +static bRC endRestoreFile(bplugin_private_context* ctx) { return bRC_OK; } /** * This is called during restore to create the file (if necessary) We must @@ -977,12 +993,12 @@ static bRC endRestoreFile(bpContext* ctx) { return bRC_OK; } * CF_EXTRACT -- extract the file (i.e.call i/o routines) * CF_CREATED -- created, but no content to extract (typically directories) */ -static bRC createFile(bpContext* ctx, struct restore_pkt* rp) +static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) { char* bp; int status; bool exists = false; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -1067,7 +1083,8 @@ static bRC createFile(bpContext* ctx, struct restore_pkt* rp) return bRC_OK; } -static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp) +static bRC setFileAttributes(bplugin_private_context* ctx, + struct restore_pkt* rp) { return bRC_OK; } @@ -1075,18 +1092,21 @@ static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp) /** * When using Incremental dump, all previous dumps are necessary */ -static bRC checkFile(bpContext* ctx, char* fname) { return bRC_OK; } +static bRC checkFile(bplugin_private_context* ctx, char* fname) +{ + return bRC_OK; +} -static bRC getAcl(bpContext* ctx, acl_pkt* ap) { return bRC_OK; } +static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap) { return bRC_OK; } -static bRC setAcl(bpContext* ctx, acl_pkt* ap) { return bRC_OK; } +static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap) { return bRC_OK; } -static bRC getXattr(bpContext* ctx, xattr_pkt* xp) +static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp) { int status; size_t xattr_value_length; const char *xattr_name, *xattr_value; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -1143,11 +1163,11 @@ static bRC getXattr(bpContext* ctx, xattr_pkt* xp) return bRC_Error; } -static bRC setXattr(bpContext* ctx, xattr_pkt* xp) +static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp) { int status; const char* bp; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } diff --git a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc index e84d723b9e9..379f5b24738 100644 --- a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc +++ b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc @@ -40,18 +40,25 @@ static const int debuglevel = 0; #define PLUGIN_DESCRIPTION "Bareos Delta Test Plugin" /* Forward referenced functions */ -static bRC newPlugin(bpContext* ctx); -static bRC freePlugin(bpContext* ctx); -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value); -static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp); -static bRC endBackupFile(bpContext* ctx); -static bRC pluginIO(bpContext* ctx, struct io_pkt* io); -static bRC startRestoreFile(bpContext* ctx, const char* cmd); -static bRC endRestoreFile(bpContext* ctx); -static bRC createFile(bpContext* ctx, struct restore_pkt* rp); -static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp); +static bRC newPlugin(bplugin_private_context* ctx); +static bRC freePlugin(bplugin_private_context* ctx); +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC handlePluginEvent(bplugin_private_context* ctx, + bEvent* event, + void* value); +static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp); +static bRC endBackupFile(bplugin_private_context* ctx); +static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io); +static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd); +static bRC endRestoreFile(bplugin_private_context* ctx); +static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp); +static bRC setFileAttributes(bplugin_private_context* ctx, + struct restore_pkt* rp); /* Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; @@ -80,11 +87,11 @@ static pFuncs pluginFuncs = { NULL /* no setXattr */ }; -#define get_self(x) ((delta_test*)((x)->pContext)) +#define get_self(x) ((delta_test*)((x)->plugin_private_context)) class delta_test { private: - bpContext* ctx; + bplugin_private_context* ctx; public: POOLMEM* fname; /* Filename to save */ @@ -93,7 +100,7 @@ class delta_test { bool done; int level; - delta_test(bpContext* bpc) + delta_test(bplugin_private_context* bpc) { fd = NULL; ctx = bpc; @@ -157,11 +164,11 @@ bRC unloadPlugin() /** * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bpContext* ctx) +static bRC newPlugin(bplugin_private_context* ctx) { delta_test* self = new delta_test(ctx); if (!self) { return bRC_Error; } - ctx->pContext = (void*)self; /* set our context pointer */ + ctx->plugin_private_context = (void*)self; /* set our context pointer */ bareos_core_functions->registerBareosEvents( ctx, 3, bEventLevel, bEventRestoreCommand, bEventBackupCommand); @@ -171,9 +178,9 @@ static bRC newPlugin(bpContext* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bpContext* ctx) +static bRC freePlugin(bplugin_private_context* ctx) { - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -185,7 +192,9 @@ static bRC freePlugin(bpContext* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { return bRC_OK; } @@ -193,7 +202,9 @@ static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { return bRC_OK; } @@ -201,7 +212,9 @@ static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) +static bRC handlePluginEvent(bplugin_private_context* ctx, + bEvent* event, + void* value) { delta_test* self = get_self(ctx); int accurate = 0; @@ -251,7 +264,7 @@ static int nb_files = 4; /** * Start the backup of a specific file */ -static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) +static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) { delta_test* self = get_self(ctx); if (!self) { return bRC_Error; } @@ -283,7 +296,7 @@ static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) /** * Done with backup of this file */ -static bRC endBackupFile(bpContext* ctx) +static bRC endBackupFile(bplugin_private_context* ctx) { /* * We would return bRC_More if we wanted startBackupFile to be @@ -295,7 +308,7 @@ static bRC endBackupFile(bpContext* ctx) /** * Bareos is calling us to do the actual I/O */ -static bRC pluginIO(bpContext* ctx, struct io_pkt* io) +static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) { delta_test* self = get_self(ctx); struct stat statp; @@ -397,7 +410,7 @@ static bRC pluginIO(bpContext* ctx, struct io_pkt* io) * Bareos is notifying us that a plugin name string was found, and * passing us the plugin command, so we can prepare for a restore. */ -static bRC startRestoreFile(bpContext* ctx, const char* cmd) +static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) { // Dmsg(ctx, debuglevel, "delta-test-fd: startRestoreFile cmd=%s\n", cmd); return bRC_OK; @@ -407,7 +420,7 @@ static bRC startRestoreFile(bpContext* ctx, const char* cmd) * Bareos is notifying us that the plugin data has terminated, so * the restore for this particular file is done. */ -static bRC endRestoreFile(bpContext* ctx) +static bRC endRestoreFile(bplugin_private_context* ctx) { // Dmsg(ctx, debuglevel, "delta-test-fd: endRestoreFile\n"); return bRC_OK; @@ -423,7 +436,7 @@ static bRC endRestoreFile(bpContext* ctx) * CF_CREATED -- created, but no content to extract (typically directories) * */ -static bRC createFile(bpContext* ctx, struct restore_pkt* rp) +static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) { delta_test* self = get_self(ctx); PmStrcpy(self->fname, rp->ofname); @@ -431,7 +444,8 @@ static bRC createFile(bpContext* ctx, struct restore_pkt* rp) return bRC_OK; } -static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp) +static bRC setFileAttributes(bplugin_private_context* ctx, + struct restore_pkt* rp) { // Dmsg(ctx, debuglevel, "delta-test-fd: setFileAttributes\n"); return bRC_OK; diff --git a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc index 47f102f70c0..28e8bcce203 100644 --- a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc +++ b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc @@ -44,23 +44,30 @@ static const int debuglevel = 000; #define PLUGIN_DESCRIPTION "Bareos Test File Daemon Plugin" /* Forward referenced functions */ -static bRC newPlugin(bpContext* ctx); -static bRC freePlugin(bpContext* ctx); -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value); -static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp); -static bRC endBackupFile(bpContext* ctx); -static bRC pluginIO(bpContext* ctx, struct io_pkt* io); -static bRC startRestoreFile(bpContext* ctx, const char* cmd); -static bRC endRestoreFile(bpContext* ctx); -static bRC createFile(bpContext* ctx, struct restore_pkt* rp); -static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp); -static bRC checkFile(bpContext* ctx, char* fname); -static bRC getAcl(bpContext* ctx, acl_pkt* ap); -static bRC setAcl(bpContext* ctx, acl_pkt* ap); -static bRC getXattr(bpContext* ctx, xattr_pkt* xp); -static bRC setXattr(bpContext* ctx, xattr_pkt* xp); +static bRC newPlugin(bplugin_private_context* ctx); +static bRC freePlugin(bplugin_private_context* ctx); +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC handlePluginEvent(bplugin_private_context* ctx, + bEvent* event, + void* value); +static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp); +static bRC endBackupFile(bplugin_private_context* ctx); +static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io); +static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd); +static bRC endRestoreFile(bplugin_private_context* ctx); +static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp); +static bRC setFileAttributes(bplugin_private_context* ctx, + struct restore_pkt* rp); +static bRC checkFile(bplugin_private_context* ctx, char* fname); +static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap); +static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap); +static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp); +static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp); /* Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; @@ -154,13 +161,13 @@ bRC unloadPlugin() { return bRC_OK; } /** * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bpContext* ctx) +static bRC newPlugin(bplugin_private_context* ctx) { struct plugin_ctx* p_ctx = (struct plugin_ctx*)malloc(sizeof(struct plugin_ctx)); if (!p_ctx) { return bRC_Error; } p_ctx = (plugin_ctx*)memset(p_ctx, 0, sizeof(struct plugin_ctx)); - ctx->pContext = (void*)p_ctx; /* set our context pointer */ + ctx->plugin_private_context = (void*)p_ctx; /* set our context pointer */ bareos_core_functions->registerBareosEvents( ctx, 5, bEventJobStart, bEventEndFileSet, bEventRestoreObject, @@ -172,21 +179,23 @@ static bRC newPlugin(bpContext* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bpContext* ctx) +static bRC freePlugin(bplugin_private_context* ctx) { - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } if (p_ctx->buf) { FreePoolMemory(p_ctx->buf); } if (p_ctx->cmd) { free(p_ctx->cmd); /* free any allocated command string */ } free(p_ctx); /* free our private context */ - ctx->pContext = NULL; + ctx->plugin_private_context = NULL; return bRC_OK; } /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { return bRC_OK; } @@ -194,7 +203,9 @@ static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { return bRC_OK; } @@ -202,9 +213,11 @@ static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) +static bRC handlePluginEvent(bplugin_private_context* ctx, + bEvent* event, + void* value) { - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; restore_object_pkt* rop; if (!p_ctx) { return bRC_Error; } @@ -320,9 +333,9 @@ static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) /** * Start the backup of a specific file */ -static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) +static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) { - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } if (p_ctx->nb_obj == 0) { @@ -581,18 +594,24 @@ static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) return bRC_OK; } -static bRC getAcl(bpContext* ctx, acl_pkt* ap) { return bRC_OK; } +static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap) { return bRC_OK; } -static bRC setAcl(bpContext* ctx, acl_pkt* ap) { return bRC_OK; } +static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap) { return bRC_OK; } -static bRC getXattr(bpContext* ctx, xattr_pkt* xp) { return bRC_OK; } +static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp) +{ + return bRC_OK; +} -static bRC setXattr(bpContext* ctx, xattr_pkt* xp) { return bRC_OK; } +static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp) +{ + return bRC_OK; +} /** * Done with backup of this file */ -static bRC endBackupFile(bpContext* ctx) +static bRC endBackupFile(bplugin_private_context* ctx) { /* * We would return bRC_More if we wanted startBackupFile to be @@ -605,9 +624,9 @@ static bRC endBackupFile(bpContext* ctx) /** * Bareos is calling us to do the actual I/O */ -static bRC pluginIO(bpContext* ctx, struct io_pkt* io) +static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) { - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } io->status = 0; @@ -619,7 +638,7 @@ static bRC pluginIO(bpContext* ctx, struct io_pkt* io) * Bareos is notifying us that a plugin name string was found, and * passing us the plugin command, so we can prepare for a restore. */ -static bRC startRestoreFile(bpContext* ctx, const char* cmd) +static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) { printf("test-plugin-fd: startRestoreFile cmd=%s\n", cmd); return bRC_OK; @@ -629,7 +648,7 @@ static bRC startRestoreFile(bpContext* ctx, const char* cmd) * Bareos is notifying us that the plugin data has terminated, so * the restore for this particular file is done. */ -static bRC endRestoreFile(bpContext* ctx) +static bRC endRestoreFile(bplugin_private_context* ctx) { printf("test-plugin-fd: endRestoreFile\n"); return bRC_OK; @@ -645,24 +664,29 @@ static bRC endRestoreFile(bpContext* ctx) * CF_CREATED -- created, but no content to extract (typically directories) * */ -static bRC createFile(bpContext* ctx, struct restore_pkt* rp) +static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) { printf("test-plugin-fd: createFile\n"); if (strlen(rp->where) > 512) { printf("Restore target dir too long. Restricting to first 512 bytes.\n"); } - bstrncpy(((struct plugin_ctx*)ctx->pContext)->where, rp->where, 513); - ((struct plugin_ctx*)ctx->pContext)->replace = rp->replace; + bstrncpy(((struct plugin_ctx*)ctx->plugin_private_context)->where, rp->where, + 513); + ((struct plugin_ctx*)ctx->plugin_private_context)->replace = rp->replace; rp->create_status = CF_EXTRACT; return bRC_OK; } -static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp) +static bRC setFileAttributes(bplugin_private_context* ctx, + struct restore_pkt* rp) { printf("test-plugin-fd: setFileAttributes\n"); return bRC_OK; } /* When using Incremental dump, all previous dumps are necessary */ -static bRC checkFile(bpContext* ctx, char* fname) { return bRC_OK; } +static bRC checkFile(bplugin_private_context* ctx, char* fname) +{ + return bRC_OK; +} } /* namespace filedaemon */ diff --git a/core/src/plugins/python_plugins_common.inc b/core/src/plugins/python_plugins_common.inc index b4daf686bd8..8b5ea4787e4 100644 --- a/core/src/plugins/python_plugins_common.inc +++ b/core/src/plugins/python_plugins_common.inc @@ -20,12 +20,12 @@ */ /* Common functions used in all python plugins. */ -static bRC getPluginValue(bpContext* bareos_plugin_ctx, +static bRC getPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value) { struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; bRC retval = bRC_Error; if (!plugin_priv_ctx) { goto bail_out; } @@ -38,12 +38,12 @@ bail_out: return retval; } -static bRC setPluginValue(bpContext* bareos_plugin_ctx, +static bRC setPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value) { struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; bRC retval = bRC_Error; if (!plugin_priv_ctx) { return bRC_Error; } @@ -120,7 +120,7 @@ static inline void SetString(char** destination, char* value) * return "".join(traceback.format_exception(sys.exc_type, * sys.exc_value, sys.exc_traceback)) */ -static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype) +static void PyErrorHandler(bplugin_private_context* bareos_plugin_ctx, int msgtype) { PyObject *type, *value, *traceback; PyObject* tracebackModule; @@ -165,25 +165,25 @@ static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype) free(error_string); } -static void StorePluginContextInPythonModule(bpContext* bareos_plugin_ctx) +static void StorePluginContextInPythonModule(bplugin_private_context* bareos_plugin_ctx) { /* get the pointer to the module variable that is exported via the capsule */ - bpContext** bareosfd_bpContext = - (bpContext**)PyCapsule_Import(PYTHON_MODULE_NAME_QUOTED ".bpContext", 0); + bplugin_private_context** bareosfd_bplugin_private_context = + (bplugin_private_context**)PyCapsule_Import(PYTHON_MODULE_NAME_QUOTED ".bplugin_private_context", 0); /* store bareos_plugin_ctx in module */ - if (bareosfd_bpContext) { - *bareosfd_bpContext = bareos_plugin_ctx; + if (bareosfd_bplugin_private_context) { + *bareosfd_bplugin_private_context = bareos_plugin_ctx; } else { - printf(PYTHON_MODULE_NAME_QUOTED ": could not get bareosfd_bpContext from module\n"); + printf(PYTHON_MODULE_NAME_QUOTED ": could not get bareosfd_bplugin_private_context from module\n"); } } -static bpContext* GetPluginContextFromPythonModule() +static bplugin_private_context* GetPluginContextFromPythonModule() { - const char* capsule_name = PYTHON_MODULE_NAME_QUOTED ".bpContext"; - bpContext** retval = - (bpContext**)PyCapsule_Import(capsule_name, 0); + const char* capsule_name = PYTHON_MODULE_NAME_QUOTED ".bplugin_private_context"; + bplugin_private_context** retval = + (bplugin_private_context**)PyCapsule_Import(capsule_name, 0); return *retval; } diff --git a/core/src/plugins/stored/autoxflate/autoxflate-sd.cc b/core/src/plugins/stored/autoxflate/autoxflate-sd.cc index ddedbcccb02..2c0ea0ed3fe 100644 --- a/core/src/plugins/stored/autoxflate/autoxflate-sd.cc +++ b/core/src/plugins/stored/autoxflate/autoxflate-sd.cc @@ -66,20 +66,30 @@ using namespace storagedaemon; /** * Forward referenced functions */ -static bRC newPlugin(bpContext* ctx); -static bRC freePlugin(bpContext* ctx); -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value); -static bRC handleJobEnd(bpContext* ctx); -static bRC setup_record_translation(bpContext* ctx, void* value); -static bRC handle_read_translation(bpContext* ctx, void* value); -static bRC handle_write_translation(bpContext* ctx, void* value); - -static bool SetupAutoDeflation(bpContext* ctx, DeviceControlRecord* dcr); -static bool SetupAutoInflation(bpContext* ctx, DeviceControlRecord* dcr); -static bool AutoDeflateRecord(bpContext* ctx, DeviceControlRecord* dcr); -static bool AutoInflateRecord(bpContext* ctx, DeviceControlRecord* dcr); +static bRC newPlugin(bplugin_private_context* ctx); +static bRC freePlugin(bplugin_private_context* ctx); +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC handlePluginEvent(bplugin_private_context* ctx, + bsdEvent* event, + void* value); +static bRC handleJobEnd(bplugin_private_context* ctx); +static bRC setup_record_translation(bplugin_private_context* ctx, void* value); +static bRC handle_read_translation(bplugin_private_context* ctx, void* value); +static bRC handle_write_translation(bplugin_private_context* ctx, void* value); + +static bool SetupAutoDeflation(bplugin_private_context* ctx, + DeviceControlRecord* dcr); +static bool SetupAutoInflation(bplugin_private_context* ctx, + DeviceControlRecord* dcr); +static bool AutoDeflateRecord(bplugin_private_context* ctx, + DeviceControlRecord* dcr); +static bool AutoInflateRecord(bplugin_private_context* ctx, + DeviceControlRecord* dcr); /** * Is the SD in compatible mode or not. @@ -171,7 +181,7 @@ bRC unloadPlugin() { return bRC_OK; } * * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bpContext* ctx) +static bRC newPlugin(bplugin_private_context* ctx) { int JobId = 0; struct plugin_ctx* p_ctx; @@ -183,7 +193,7 @@ static bRC newPlugin(bpContext* ctx) if (!p_ctx) { return bRC_Error; } memset(p_ctx, 0, sizeof(struct plugin_ctx)); - ctx->pContext = (void*)p_ctx; /* set our context pointer */ + ctx->plugin_private_context = (void*)p_ctx; /* set our context pointer */ /* * Only register plugin events we are interested in. @@ -204,10 +214,10 @@ static bRC newPlugin(bpContext* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bpContext* ctx) +static bRC freePlugin(bplugin_private_context* ctx) { int JobId = 0; - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; bareos_core_functions->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); Dmsg(ctx, debuglevel, "autoxflate-sd: freePlugin JobId=%d\n", JobId); @@ -218,7 +228,7 @@ static bRC freePlugin(bpContext* ctx) } if (p_ctx) { free(p_ctx); } - ctx->pContext = NULL; + ctx->plugin_private_context = NULL; return bRC_OK; } @@ -226,7 +236,9 @@ static bRC freePlugin(bpContext* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { Dmsg(ctx, debuglevel, "autoxflate-sd: getPluginValue var=%d\n", var); @@ -236,7 +248,9 @@ static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { Dmsg(ctx, debuglevel, "autoxflate-sd: setPluginValue var=%d\n", var); @@ -246,7 +260,9 @@ static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value) +static bRC handlePluginEvent(bplugin_private_context* ctx, + bsdEvent* event, + void* value) { switch (event->eventType) { case bsdEventSetupRecordTranslation: @@ -269,9 +285,9 @@ static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value) /** * At end of job report how inflate/deflate ratio was. */ -static bRC handleJobEnd(bpContext* ctx) +static bRC handleJobEnd(bplugin_private_context* ctx) { - struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { goto bail_out; } @@ -296,7 +312,7 @@ static bRC handleJobEnd(bpContext* ctx) return bRC_OK; } -static bRC setup_record_translation(bpContext* ctx, void* value) +static bRC setup_record_translation(bplugin_private_context* ctx, void* value) { DeviceControlRecord* dcr; bool did_setup = false; @@ -399,7 +415,7 @@ static bRC setup_record_translation(bpContext* ctx, void* value) return bRC_OK; } -static bRC handle_read_translation(bpContext* ctx, void* value) +static bRC handle_read_translation(bplugin_private_context* ctx, void* value) { DeviceControlRecord* dcr; bool swap_record = false; @@ -436,7 +452,7 @@ static bRC handle_read_translation(bpContext* ctx, void* value) return bRC_OK; } -static bRC handle_write_translation(bpContext* ctx, void* value) +static bRC handle_write_translation(bplugin_private_context* ctx, void* value) { DeviceControlRecord* dcr; bool swap_record = false; @@ -476,7 +492,8 @@ static bRC handle_write_translation(bpContext* ctx, void* value) /** * Setup deflate for auto deflate of data streams. */ -static bool SetupAutoDeflation(bpContext* ctx, DeviceControlRecord* dcr) +static bool SetupAutoDeflation(bplugin_private_context* ctx, + DeviceControlRecord* dcr) { JobControlRecord* jcr = dcr->jcr; bool retval = false; @@ -572,7 +589,8 @@ static bool SetupAutoDeflation(bpContext* ctx, DeviceControlRecord* dcr) /** * Setup inflation for auto inflation of data streams. */ -static bool SetupAutoInflation(bpContext* ctx, DeviceControlRecord* dcr) +static bool SetupAutoInflation(bplugin_private_context* ctx, + DeviceControlRecord* dcr) { JobControlRecord* jcr = dcr->jcr; uint32_t decompress_buf_size; @@ -606,7 +624,8 @@ static bool SetupAutoInflation(bpContext* ctx, DeviceControlRecord* dcr) * Perform automatic compression of certain stream types when enabled in the * config. */ -static bool AutoDeflateRecord(bpContext* ctx, DeviceControlRecord* dcr) +static bool AutoDeflateRecord(bplugin_private_context* ctx, + DeviceControlRecord* dcr) { ser_declare; bool retval = false; @@ -617,7 +636,7 @@ static bool AutoDeflateRecord(bpContext* ctx, DeviceControlRecord* dcr) bool intermediate_value = false; unsigned int max_compression_length = 0; - p_ctx = (struct plugin_ctx*)ctx->pContext; + p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { goto bail_out; } /* @@ -766,14 +785,15 @@ static bool AutoDeflateRecord(bpContext* ctx, DeviceControlRecord* dcr) * Inflate (uncompress) the content of a read record and return the data as an * alternative datastream. */ -static bool AutoInflateRecord(bpContext* ctx, DeviceControlRecord* dcr) +static bool AutoInflateRecord(bplugin_private_context* ctx, + DeviceControlRecord* dcr) { DeviceRecord *rec, *nrec; bool retval = false; struct plugin_ctx* p_ctx; bool intermediate_value = false; - p_ctx = (struct plugin_ctx*)ctx->pContext; + p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { goto bail_out; } /* diff --git a/core/src/plugins/stored/example/example-plugin-sd.cc b/core/src/plugins/stored/example/example-plugin-sd.cc index 17efc69a99d..e0e246f26eb 100644 --- a/core/src/plugins/stored/example/example-plugin-sd.cc +++ b/core/src/plugins/stored/example/example-plugin-sd.cc @@ -36,11 +36,17 @@ #define PLUGIN_DESCRIPTION "Test Storage Daemon Plugin" /* Forward referenced functions */ -static bRC newPlugin(bpContext* ctx); -static bRC freePlugin(bpContext* ctx); -static bRC getPluginValue(bpContext* ctx, psdVariable var, void* value); -static bRC setPluginValue(bpContext* ctx, psdVariable var, void* value); -static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value); +static bRC newPlugin(bplugin_private_context* ctx); +static bRC freePlugin(bplugin_private_context* ctx); +static bRC getPluginValue(bplugin_private_context* ctx, + psdVariable var, + void* value); +static bRC setPluginValue(bplugin_private_context* ctx, + psdVariable var, + void* value); +static bRC handlePluginEvent(bplugin_private_context* ctx, + bsdEvent* event, + void* value); /* Pointers to Bareos functions */ @@ -109,7 +115,7 @@ bRC unloadPlugin() /** * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bpContext* ctx) +static bRC newPlugin(bplugin_private_context* ctx) { int JobId = 0; bareos_core_functions->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); @@ -122,7 +128,7 @@ static bRC newPlugin(bpContext* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bpContext* ctx) +static bRC freePlugin(bplugin_private_context* ctx) { int JobId = 0; bareos_core_functions->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); @@ -133,7 +139,9 @@ static bRC freePlugin(bpContext* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bpContext* ctx, psdVariable var, void* value) +static bRC getPluginValue(bplugin_private_context* ctx, + psdVariable var, + void* value) { printf("example-plugin-sd: getPluginValue var=%d\n", var); return bRC_OK; @@ -142,7 +150,9 @@ static bRC getPluginValue(bpContext* ctx, psdVariable var, void* value) /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bpContext* ctx, psdVariable var, void* value) +static bRC setPluginValue(bplugin_private_context* ctx, + psdVariable var, + void* value) { printf("example-plugin-sd: setPluginValue var=%d\n", var); return bRC_OK; @@ -151,7 +161,9 @@ static bRC setPluginValue(bpContext* ctx, psdVariable var, void* value) /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value) +static bRC handlePluginEvent(bplugin_private_context* ctx, + bsdEvent* event, + void* value) { char* name; switch (event->eventType) { diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index 41e563ed9b7..4fa7efc80d8 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -58,31 +58,34 @@ static const int debuglevel = 150; /* Forward referenced functions */ -static bRC newPlugin(bpContext* bareos_plugin_ctx); -static bRC freePlugin(bpContext* bareos_plugin_ctx); -static bRC getPluginValue(bpContext* bareos_plugin_ctx, +static bRC newPlugin(bplugin_private_context* bareos_plugin_ctx); +static bRC freePlugin(bplugin_private_context* bareos_plugin_ctx); +static bRC getPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value); -static bRC setPluginValue(bpContext* bareos_plugin_ctx, +static bRC setPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value); -static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, +static bRC handlePluginEvent(bplugin_private_context* bareos_plugin_ctx, bsdEvent* event, void* value); -static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, +static bRC parse_plugin_definition(bplugin_private_context* bareos_plugin_ctx, void* value, PoolMem& plugin_options); -static void PyErrorHandler(bpContext* bareos_plugin_ctx, int msgtype); -static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value); -static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value); -static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, +static void PyErrorHandler(bplugin_private_context* bareos_plugin_ctx, + int msgtype); +static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, + void* value); +static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, + void* value); +static bRC PyGetPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value); -static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, +static bRC PySetPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value); -static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(bplugin_private_context* bareos_plugin_ctx, bsdEvent* event, void* value); @@ -185,14 +188,14 @@ bRC unloadPlugin() #endif /* Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bpContext* bareos_plugin_ctx) +static bRC newPlugin(bplugin_private_context* bareos_plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = (struct plugin_private_context*)malloc( sizeof(struct plugin_private_context)); if (!plugin_priv_ctx) { return bRC_Error; } memset(plugin_priv_ctx, 0, sizeof(struct plugin_private_context)); - bareos_plugin_ctx->pContext = + bareos_plugin_ctx->plugin_private_context = (void*)plugin_priv_ctx; /* set our context pointer */ /* For each plugin instance we instantiate a new Python interpreter. */ @@ -211,10 +214,10 @@ static bRC newPlugin(bpContext* bareos_plugin_ctx) } /* Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bpContext* bareos_plugin_ctx) +static bRC freePlugin(bplugin_private_context* bareos_plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { return bRC_Error; } @@ -230,13 +233,13 @@ static bRC freePlugin(bpContext* bareos_plugin_ctx) PyEval_ReleaseLock(); free(plugin_priv_ctx); - bareos_plugin_ctx->pContext = NULL; + bareos_plugin_ctx->plugin_private_context = NULL; return bRC_OK; } -static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, +static bRC handlePluginEvent(bplugin_private_context* bareos_plugin_ctx, bsdEvent* event, void* value) { @@ -244,7 +247,7 @@ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, bool event_dispatched = false; PoolMem plugin_options(PM_FNAME); plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->pContext; + (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } @@ -318,7 +321,7 @@ static bRC handlePluginEvent(bpContext* bareos_plugin_ctx, * * python:module_path=:module_name=:... */ -static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, +static bRC parse_plugin_definition(bplugin_private_context* bareos_plugin_ctx, void* value, PoolMem& plugin_options) { @@ -327,7 +330,7 @@ static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, PoolMem plugin_definition(PM_FNAME); char *bp, *argument, *argument_value; plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->pContext; + (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; if (!value) { return bRC_Error; } @@ -463,11 +466,11 @@ static bRC parse_plugin_definition(bpContext* bareos_plugin_ctx, * module path and the module to load. We also load the dictionary used * for looking up the Python methods. */ -static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) +static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject *sysPath, *mPath, *pName, *pFunc; /* @@ -562,11 +565,12 @@ static bRC PyLoadModule(bpContext* bareos_plugin_ctx, void* value) * PyLoadModule() has loaded the Python module and made sure things are * operational. */ -static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) +static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, + void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->pContext; + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -605,27 +609,27 @@ static bRC PyParsePluginDefinition(bpContext* bareos_plugin_ctx, void* value) return retval; } -static bRC PyGetPluginValue(bpContext* bareos_plugin_ctx, +static bRC PyGetPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PySetPluginValue(bpContext* bareos_plugin_ctx, +static bRC PySetPluginValue(bplugin_private_context* bareos_plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(bplugin_private_context* bareos_plugin_ctx, bsdEvent* event, void* value) { bRC retval = bRC_Error; plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->pContext; + (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -667,7 +671,8 @@ static bRC PyHandlePluginEvent(bpContext* bareos_plugin_ctx, static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } @@ -755,7 +760,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject* pyValue; @@ -806,7 +812,8 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; @@ -828,7 +835,8 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; @@ -849,7 +857,8 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -891,7 +900,8 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -933,7 +943,8 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - bpContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bplugin_private_context* bareos_plugin_ctx = + GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } diff --git a/core/src/plugins/stored/python/python-sd.h b/core/src/plugins/stored/python/python-sd.h index 580ffc3c565..ec14f673041 100644 --- a/core/src/plugins/stored/python/python-sd.h +++ b/core/src/plugins/stored/python/python-sd.h @@ -88,10 +88,10 @@ static void* bareos_plugin_context = NULL; // MOD_INIT(PYTHON_MODULE_NAME) MOD_INIT(bareossd) { - /* bareos_plugin_context holds the bpContext instead of passing to Python and - * extracting it back like it was before. bareos_plugin_context needs to be - * set after loading the PYTHON_MODULE_NAME binary python module and will be - * used for all calls. + /* bareos_plugin_context holds the bplugin_private_context instead of passing + * to Python and extracting it back like it was before. bareos_plugin_context + * needs to be set after loading the PYTHON_MODULE_NAME binary python module + * and will be used for all calls. */ PyObject* m = NULL; @@ -99,7 +99,7 @@ MOD_INIT(bareossd) /* Pointer Capsules to avoid context transfer back and forth */ PyObject* PyModulePluginContext = PyCapsule_New((void*)&bareos_plugin_context, - PYTHON_MODULE_NAME_QUOTED ".bpContext", NULL); + PYTHON_MODULE_NAME_QUOTED ".bplugin_private_context", NULL); if (!PyModulePluginContext) { printf(PYTHON_MODULE_NAME_QUOTED ": PyCapsule_New failed\n"); @@ -109,7 +109,7 @@ MOD_INIT(bareossd) MOD_DEF(m, PYTHON_MODULE_NAME_QUOTED, NULL, Methods) if (PyModulePluginContext) { - PyModule_AddObject(m, "bpContext", PyModulePluginContext); + PyModule_AddObject(m, "bplugin_private_context", PyModulePluginContext); } else { printf(PYTHON_MODULE_NAME_QUOTED ":PyModule_AddObject failed\n"); return MOD_ERROR_VAL; diff --git a/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc b/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc index 8079692b525..e0a5d486811 100644 --- a/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc +++ b/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc @@ -80,11 +80,17 @@ using namespace storagedaemon; /** * Forward referenced functions */ -static bRC newPlugin(bpContext* ctx); -static bRC freePlugin(bpContext* ctx); -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value); +static bRC newPlugin(bplugin_private_context* ctx); +static bRC freePlugin(bplugin_private_context* ctx); +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC handlePluginEvent(bplugin_private_context* ctx, + bsdEvent* event, + void* value); static bRC do_set_scsi_encryption_key(void* value); static bRC do_clear_scsi_encryption_key(void* value); static bRC handle_read_error(void* value); @@ -159,7 +165,7 @@ bRC unloadPlugin() { return bRC_OK; } * * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bpContext* ctx) +static bRC newPlugin(bplugin_private_context* ctx) { int JobId = 0; @@ -204,7 +210,7 @@ static bRC newPlugin(bpContext* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bpContext* ctx) +static bRC freePlugin(bplugin_private_context* ctx) { int JobId = 0; @@ -217,7 +223,9 @@ static bRC freePlugin(bpContext* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { Dmsg1(debuglevel, "scsicrypto-sd: getPluginValue var=%d\n", var); @@ -227,7 +235,9 @@ static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { Dmsg1(debuglevel, "scsicrypto-sd: setPluginValue var=%d\n", var); @@ -237,7 +247,9 @@ static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value) +static bRC handlePluginEvent(bplugin_private_context* ctx, + bsdEvent* event, + void* value) { switch (event->eventType) { case bsdEventLabelRead: diff --git a/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc b/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc index 3d6f8243b19..ddd7e4ac166 100644 --- a/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc +++ b/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc @@ -43,11 +43,17 @@ using namespace storagedaemon; /** * Forward referenced functions */ -static bRC newPlugin(bpContext* ctx); -static bRC freePlugin(bpContext* ctx); -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value); +static bRC newPlugin(bplugin_private_context* ctx); +static bRC freePlugin(bplugin_private_context* ctx); +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC handlePluginEvent(bplugin_private_context* ctx, + bsdEvent* event, + void* value); static bRC handle_tapealert_readout(void* value); /** @@ -118,7 +124,7 @@ bRC unloadPlugin() { return bRC_OK; } * * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bpContext* ctx) +static bRC newPlugin(bplugin_private_context* ctx) { int JobId = 0; @@ -138,7 +144,7 @@ static bRC newPlugin(bpContext* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bpContext* ctx) +static bRC freePlugin(bplugin_private_context* ctx) { int JobId = 0; @@ -151,7 +157,9 @@ static bRC freePlugin(bpContext* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { Dmsg1(debuglevel, "scsitapealert-sd: getPluginValue var=%d\n", var); @@ -161,7 +169,9 @@ static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { Dmsg1(debuglevel, "scsitapealert-sd: setPluginValue var=%d\n", var); @@ -171,7 +181,9 @@ static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bpContext* ctx, bsdEvent* event, void* value) +static bRC handlePluginEvent(bplugin_private_context* ctx, + bsdEvent* event, + void* value) { switch (event->eventType) { case bsdEventLabelVerified: diff --git a/core/src/stored/sd_plugins.cc b/core/src/stored/sd_plugins.cc index db6cfee78f7..b9fe3875aa8 100644 --- a/core/src/stored/sd_plugins.cc +++ b/core/src/stored/sd_plugins.cc @@ -52,19 +52,27 @@ static alist* sd_plugin_list = NULL; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; /* Forward referenced functions */ -static bRC bareosGetValue(bpContext* ctx, bsdrVariable var, void* value); -static bRC bareosSetValue(bpContext* ctx, bsdwVariable var, void* value); -static bRC bareosRegisterEvents(bpContext* ctx, int nr_events, ...); -static bRC bareosUnRegisterEvents(bpContext* ctx, int nr_events, ...); -static bRC bareosGetInstanceCount(bpContext* ctx, int* ret); -static bRC bareosJobMsg(bpContext* ctx, +static bRC bareosGetValue(bplugin_private_context* ctx, + bsdrVariable var, + void* value); +static bRC bareosSetValue(bplugin_private_context* ctx, + bsdwVariable var, + void* value); +static bRC bareosRegisterEvents(bplugin_private_context* ctx, + int nr_events, + ...); +static bRC bareosUnRegisterEvents(bplugin_private_context* ctx, + int nr_events, + ...); +static bRC bareosGetInstanceCount(bplugin_private_context* ctx, int* ret); +static bRC bareosJobMsg(bplugin_private_context* ctx, const char* file, int line, int type, utime_t mtime, const char* fmt, ...); -static bRC bareosDebugMsg(bpContext* ctx, +static bRC bareosDebugMsg(bplugin_private_context* ctx, const char* file, int line, int level, @@ -108,32 +116,33 @@ struct b_plugin_ctx { Plugin* plugin; /* pointer to plugin of which this is an instance off */ }; -static inline bool IsEventEnabled(bpContext* ctx, bsdEventType eventType) +static inline bool IsEventEnabled(bplugin_private_context* ctx, + bsdEventType eventType) { b_plugin_ctx* b_ctx; if (!ctx) { return false; } - b_ctx = (b_plugin_ctx*)ctx->bContext; + b_ctx = (b_plugin_ctx*)ctx->core_private_context; if (!b_ctx) { return false; } return BitIsSet(eventType, b_ctx->events); } -static inline bool IsPluginDisabled(bpContext* ctx) +static inline bool IsPluginDisabled(bplugin_private_context* ctx) { b_plugin_ctx* b_ctx; if (!ctx) { return true; } - b_ctx = (b_plugin_ctx*)ctx->bContext; + b_ctx = (b_plugin_ctx*)ctx->core_private_context; if (!b_ctx) { return true; } return b_ctx->disabled; } -static bool IsCtxGood(bpContext* ctx, +static bool IsCtxGood(bplugin_private_context* ctx, JobControlRecord*& jcr, b_plugin_ctx*& bctx) { if (!ctx) { return false; } - bctx = (b_plugin_ctx*)ctx->bContext; + bctx = (b_plugin_ctx*)ctx->core_private_context; if (!bctx) { return false; } jcr = bctx->jcr; @@ -240,7 +249,7 @@ char* edit_device_codes(DeviceControlRecord* dcr, static inline bool trigger_plugin_event(JobControlRecord* jcr, bsdEventType eventType, bsdEvent* event, - bpContext* ctx, + bplugin_private_context* ctx, void* value, alist* plugin_ctx_list, int* index, @@ -345,7 +354,7 @@ bRC GeneratePluginEvent(JobControlRecord* jcr, * See if we need to trigger the loaded plugins in reverse order. */ if (reverse) { - bpContext* ctx; + bplugin_private_context* ctx; foreach_alist_rindex (i, ctx, plugin_ctx_list) { if (trigger_plugin_event(jcr, eventType, &event, ctx, value, @@ -354,7 +363,7 @@ bRC GeneratePluginEvent(JobControlRecord* jcr, } } } else { - bpContext* ctx; + bplugin_private_context* ctx; foreach_alist_index (i, ctx, plugin_ctx_list) { if (trigger_plugin_event(jcr, eventType, &event, ctx, value, @@ -491,11 +500,11 @@ static bool IsPluginCompatible(Plugin* plugin) /** * Instantiate a new plugin instance. */ -static inline bpContext* instantiate_plugin(JobControlRecord* jcr, - Plugin* plugin, - uint32_t instance) +static inline bplugin_private_context* instantiate_plugin(JobControlRecord* jcr, + Plugin* plugin, + uint32_t instance) { - bpContext* ctx; + bplugin_private_context* ctx; b_plugin_ctx* b_ctx; b_ctx = (b_plugin_ctx*)malloc(sizeof(b_plugin_ctx)); @@ -506,11 +515,11 @@ static inline bpContext* instantiate_plugin(JobControlRecord* jcr, Dmsg2(debuglevel, "Instantiate dir-plugin_ctx_list=%p JobId=%d\n", jcr->plugin_ctx_list, jcr->JobId); - ctx = (bpContext*)malloc(sizeof(bpContext)); + ctx = (bplugin_private_context*)malloc(sizeof(bplugin_private_context)); ctx->instance = instance; ctx->plugin = plugin; - ctx->bContext = (void*)b_ctx; - ctx->pContext = NULL; + ctx->core_private_context = (void*)b_ctx; + ctx->plugin_private_context = NULL; jcr->plugin_ctx_list->append(ctx); @@ -527,7 +536,7 @@ void DispatchNewPluginOptions(JobControlRecord* jcr) { int i, j, len; Plugin* plugin; - bpContext* ctx = nullptr; + bplugin_private_context* ctx = nullptr; uint32_t instance; bsdEvent event; bsdEventType eventType; @@ -655,7 +664,7 @@ void NewPlugins(JobControlRecord* jcr) */ void FreePlugins(JobControlRecord* jcr) { - bpContext* ctx = nullptr; + bplugin_private_context* ctx = nullptr; if (!sd_plugin_list || !jcr->plugin_ctx_list) { return; } @@ -666,7 +675,7 @@ void FreePlugins(JobControlRecord* jcr) * Free the plugin instance */ SdplugFunc(ctx->plugin)->freePlugin(ctx); - free(ctx->bContext); /* Free BAREOS private context */ + free(ctx->core_private_context); /* Free BAREOS private context */ } delete jcr->plugin_ctx_list; @@ -679,7 +688,9 @@ void FreePlugins(JobControlRecord* jcr) * * ============================================================== */ -static bRC bareosGetValue(bpContext* ctx, bsdrVariable var, void* value) +static bRC bareosGetValue(bplugin_private_context* ctx, + bsdrVariable var, + void* value) { JobControlRecord* jcr = NULL; bRC retval = bRC_OK; @@ -700,7 +711,7 @@ static bRC bareosGetValue(bpContext* ctx, bsdrVariable var, void* value) default: if (!ctx) { return bRC_Error; } - jcr = ((b_plugin_ctx*)ctx->bContext)->jcr; + jcr = ((b_plugin_ctx*)ctx->core_private_context)->jcr; if (!jcr) { return bRC_Error; } break; } @@ -811,12 +822,14 @@ static bRC bareosGetValue(bpContext* ctx, bsdrVariable var, void* value) return retval; } -static bRC bareosSetValue(bpContext* ctx, bsdwVariable var, void* value) +static bRC bareosSetValue(bplugin_private_context* ctx, + bsdwVariable var, + void* value) { JobControlRecord* jcr; if (!value || !ctx) { return bRC_Error; } - jcr = ((b_plugin_ctx*)ctx->bContext)->jcr; + jcr = ((b_plugin_ctx*)ctx->core_private_context)->jcr; if (!jcr) { return bRC_Error; } Dmsg1(debuglevel, "sd-plugin: bareosSetValue var=%d\n", var); @@ -837,7 +850,9 @@ static bRC bareosSetValue(bpContext* ctx, bsdwVariable var, void* value) return bRC_OK; } -static bRC bareosRegisterEvents(bpContext* ctx, int nr_events, ...) +static bRC bareosRegisterEvents(bplugin_private_context* ctx, + int nr_events, + ...) { int i; va_list args; @@ -845,7 +860,7 @@ static bRC bareosRegisterEvents(bpContext* ctx, int nr_events, ...) b_plugin_ctx* b_ctx; if (!ctx) { return bRC_Error; } - b_ctx = (b_plugin_ctx*)ctx->bContext; + b_ctx = (b_plugin_ctx*)ctx->core_private_context; va_start(args, nr_events); for (i = 0; i < nr_events; i++) { event = va_arg(args, uint32_t); @@ -856,7 +871,9 @@ static bRC bareosRegisterEvents(bpContext* ctx, int nr_events, ...) return bRC_OK; } -static bRC bareosUnRegisterEvents(bpContext* ctx, int nr_events, ...) +static bRC bareosUnRegisterEvents(bplugin_private_context* ctx, + int nr_events, + ...) { int i; va_list args; @@ -864,7 +881,7 @@ static bRC bareosUnRegisterEvents(bpContext* ctx, int nr_events, ...) b_plugin_ctx* b_ctx; if (!ctx) { return bRC_Error; } - b_ctx = (b_plugin_ctx*)ctx->bContext; + b_ctx = (b_plugin_ctx*)ctx->core_private_context; va_start(args, nr_events); for (i = 0; i < nr_events; i++) { event = va_arg(args, uint32_t); @@ -875,11 +892,11 @@ static bRC bareosUnRegisterEvents(bpContext* ctx, int nr_events, ...) return bRC_OK; } -static bRC bareosGetInstanceCount(bpContext* ctx, int* ret) +static bRC bareosGetInstanceCount(bplugin_private_context* ctx, int* ret) { int cnt; JobControlRecord *jcr, *njcr; - bpContext* nctx; + bplugin_private_context* nctx; b_plugin_ctx* bctx; bRC retval = bRC_Error; @@ -906,7 +923,7 @@ static bRC bareosGetInstanceCount(bpContext* ctx, int* ret) return retval; } -static bRC bareosJobMsg(bpContext* ctx, +static bRC bareosJobMsg(bplugin_private_context* ctx, const char* file, int line, int type, @@ -919,7 +936,7 @@ static bRC bareosJobMsg(bpContext* ctx, PoolMem buffer(PM_MESSAGE); if (ctx) { - jcr = ((b_plugin_ctx*)ctx->bContext)->jcr; + jcr = ((b_plugin_ctx*)ctx->core_private_context)->jcr; } else { jcr = NULL; } @@ -932,7 +949,7 @@ static bRC bareosJobMsg(bpContext* ctx, return bRC_OK; } -static bRC bareosDebugMsg(bpContext* ctx, +static bRC bareosDebugMsg(bplugin_private_context* ctx, const char* file, int line, int level, diff --git a/core/src/stored/sd_plugins.h b/core/src/stored/sd_plugins.h index 5940f980412..b50efdb7ae1 100644 --- a/core/src/stored/sd_plugins.h +++ b/core/src/stored/sd_plugins.h @@ -146,19 +146,25 @@ struct DeviceRecord; typedef struct s_sdbareosFuncs { uint32_t size; uint32_t version; - bRC (*registerBareosEvents)(bpContext* ctx, int nr_events, ...); - bRC (*unregisterBareosEvents)(bpContext* ctx, int nr_events, ...); - bRC (*getInstanceCount)(bpContext* ctx, int* ret); - bRC (*getBareosValue)(bpContext* ctx, bsdrVariable var, void* value); - bRC (*setBareosValue)(bpContext* ctx, bsdwVariable var, void* value); - bRC (*JobMessage)(bpContext* ctx, + bRC (*registerBareosEvents)(bplugin_private_context* ctx, int nr_events, ...); + bRC (*unregisterBareosEvents)(bplugin_private_context* ctx, + int nr_events, + ...); + bRC (*getInstanceCount)(bplugin_private_context* ctx, int* ret); + bRC (*getBareosValue)(bplugin_private_context* ctx, + bsdrVariable var, + void* value); + bRC (*setBareosValue)(bplugin_private_context* ctx, + bsdwVariable var, + void* value); + bRC (*JobMessage)(bplugin_private_context* ctx, const char* file, int line, int type, utime_t mtime, const char* fmt, ...); - bRC (*DebugMessage)(bpContext* ctx, + bRC (*DebugMessage)(bplugin_private_context* ctx, const char* file, int line, int level, @@ -211,11 +217,17 @@ typedef enum typedef struct s_sdpluginFuncs { uint32_t size; uint32_t version; - bRC (*newPlugin)(bpContext* ctx); - bRC (*freePlugin)(bpContext* ctx); - bRC (*getPluginValue)(bpContext* ctx, pVariable var, void* value); - bRC (*setPluginValue)(bpContext* ctx, pVariable var, void* value); - bRC (*handlePluginEvent)(bpContext* ctx, bsdEvent* event, void* value); + bRC (*newPlugin)(bplugin_private_context* ctx); + bRC (*freePlugin)(bplugin_private_context* ctx); + bRC (*getPluginValue)(bplugin_private_context* ctx, + pVariable var, + void* value); + bRC (*setPluginValue)(bplugin_private_context* ctx, + pVariable var, + void* value); + bRC (*handlePluginEvent)(bplugin_private_context* ctx, + bsdEvent* event, + void* value); } psdFuncs; #define SdplugFunc(plugin) ((psdFuncs*)(plugin->plugin_functions)) diff --git a/core/src/win32/plugins/filed/mssqlvdi-fd.cc b/core/src/win32/plugins/filed/mssqlvdi-fd.cc index 558e8e08bdb..137b7221c4b 100644 --- a/core/src/win32/plugins/filed/mssqlvdi-fd.cc +++ b/core/src/win32/plugins/filed/mssqlvdi-fd.cc @@ -90,24 +90,31 @@ static const int debuglevel = 150; /** * Forward referenced functions */ -static bRC newPlugin(bpContext* ctx); -static bRC freePlugin(bpContext* ctx); -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value); -static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value); -static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp); -static bRC endBackupFile(bpContext* ctx); -static bRC pluginIO(bpContext* ctx, struct io_pkt* io); -static bRC startRestoreFile(bpContext* ctx, const char* cmd); -static bRC endRestoreFile(bpContext* ctx); -static bRC createFile(bpContext* ctx, struct restore_pkt* rp); -static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp); -static bRC checkFile(bpContext* ctx, char* fname); - -static bRC parse_plugin_definition(bpContext* ctx, void* value); -static bRC end_restore_job(bpContext* ctx, void* value); +static bRC newPlugin(bplugin_private_context* ctx); +static bRC freePlugin(bplugin_private_context* ctx); +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value); +static bRC handlePluginEvent(bplugin_private_context* ctx, + bEvent* event, + void* value); +static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp); +static bRC endBackupFile(bplugin_private_context* ctx); +static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io); +static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd); +static bRC endRestoreFile(bplugin_private_context* ctx); +static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp); +static bRC setFileAttributes(bplugin_private_context* ctx, + struct restore_pkt* rp); +static bRC checkFile(bplugin_private_context* ctx, char* fname); + +static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value); +static bRC end_restore_job(bplugin_private_context* ctx, void* value); static void CloseVdiDeviceset(struct plugin_ctx* p_ctx); -static bool adoReportError(bpContext* ctx); +static bool adoReportError(bplugin_private_context* ctx); /** * Pointers to Bareos functions @@ -258,7 +265,7 @@ bRC unloadPlugin() { return bRC_OK; } * * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bpContext* ctx) +static bRC newPlugin(bplugin_private_context* ctx) { HRESULT hr; plugin_ctx* p_ctx; @@ -274,7 +281,7 @@ static bRC newPlugin(bpContext* ctx) p_ctx = (plugin_ctx*)malloc(sizeof(plugin_ctx)); if (!p_ctx) { return bRC_Error; } memset(p_ctx, 0, sizeof(plugin_ctx)); - ctx->pContext = (void*)p_ctx; /* set our context pointer */ + ctx->plugin_private_context = (void*)p_ctx; /* set our context pointer */ /* * Only register the events we are really interested in. @@ -289,9 +296,9 @@ static bRC newPlugin(bpContext* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bpContext* ctx) +static bRC freePlugin(bplugin_private_context* ctx) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } Dmsg(ctx, debuglevel, "mssqlvdi-fd: entering freePlugin\n"); @@ -351,7 +358,9 @@ static bRC freePlugin(bpContext* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC getPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { return bRC_OK; } @@ -359,7 +368,9 @@ static bRC getPluginValue(bpContext* ctx, pVariable var, void* value) /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) +static bRC setPluginValue(bplugin_private_context* ctx, + pVariable var, + void* value) { return bRC_OK; } @@ -367,10 +378,12 @@ static bRC setPluginValue(bpContext* ctx, pVariable var, void* value) /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) +static bRC handlePluginEvent(bplugin_private_context* ctx, + bEvent* event, + void* value) { bRC retval; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -423,12 +436,12 @@ static bRC handlePluginEvent(bpContext* ctx, bEvent* event, void* value) /** * Start the backup of a specific file */ -static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) +static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) { time_t now; PoolMem fname(PM_NAME); char dt[MAX_TIME_LENGTH]; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -488,7 +501,7 @@ static bRC startBackupFile(bpContext* ctx, struct save_pkt* sp) /** * Done with backup of this file */ -static bRC endBackupFile(bpContext* ctx) +static bRC endBackupFile(bplugin_private_context* ctx) { /* * We would return bRC_More if we wanted startBackupFile to be called again to @@ -576,12 +589,12 @@ static inline void SetString(char** destination, char* value) * * mssqlvdi:instance=:database=: */ -static bRC parse_plugin_definition(bpContext* ctx, void* value) +static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value) { int i; bool keep_existing; char *plugin_definition, *bp, *argument, *argument_value; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx || !value) { return bRC_Error; } @@ -777,7 +790,7 @@ static void CloseVdiDeviceset(plugin_ctx* p_ctx) /** * Generic COM error reporting function. */ -static void comReportError(bpContext* ctx, HRESULT hrErr) +static void comReportError(bplugin_private_context* ctx, HRESULT hrErr) { IErrorInfo* pErrorInfo; BSTR pSource = NULL; @@ -837,7 +850,7 @@ static void comReportError(bpContext* ctx, HRESULT hrErr) /** * Retrieve errors from ADO Connection. */ -static bool adoGetErrors(bpContext* ctx, +static bool adoGetErrors(bplugin_private_context* ctx, _ADOConnection* adoConnection, PoolMem& ado_errorstr) { @@ -915,9 +928,9 @@ static bool adoGetErrors(bpContext* ctx, /** * Print errors (when available) collected by adoThreadSetError function. */ -static bool adoReportError(bpContext* ctx) +static bool adoReportError(bplugin_private_context* ctx) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (p_ctx->ado_errorstr) { Jmsg(ctx, M_FATAL, "%s\n", p_ctx->ado_errorstr); @@ -936,11 +949,12 @@ static bool adoReportError(bpContext* ctx) * Retrieve errors from ADO Connection when running the query in a separate * thread. */ -static void adoThreadSetError(bpContext* ctx, _ADOConnection* adoConnection) +static void adoThreadSetError(bplugin_private_context* ctx, + _ADOConnection* adoConnection) { int cancel_type; PoolMem ado_errorstr(PM_NAME); - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (p_ctx->ado_errorstr) { return; } @@ -1011,8 +1025,8 @@ static void* adoThread(void* data) { HRESULT hr; adoThreadContext ado_ctx; - bpContext* ctx = (bpContext*)data; - plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->pContext; + bplugin_private_context* ctx = (bplugin_private_context*)data; + plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; memset(&ado_ctx, 0, sizeof(ado_ctx)); @@ -1080,10 +1094,10 @@ static void* adoThread(void* data) /** * Create a connection string for connecting to the master database. */ -static void SetAdoConnectString(bpContext* ctx) +static void SetAdoConnectString(bplugin_private_context* ctx) { PoolMem ado_connect_string(PM_NAME); - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (Bstrcasecmp(p_ctx->instance, DEFAULT_INSTANCE)) { Mmsg(ado_connect_string, @@ -1118,9 +1132,9 @@ static void SetAdoConnectString(bpContext* ctx) * Generate a valid connect string and the backup command we should execute * in the separate database controling thread. */ -static inline void PerformAdoBackup(bpContext* ctx) +static inline void PerformAdoBackup(bplugin_private_context* ctx) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; PoolMem ado_connect_string(PM_NAME), ado_query(PM_NAME); POOLMEM* vdsname; @@ -1169,11 +1183,11 @@ static inline void PerformAdoBackup(bpContext* ctx) * Generate a valid connect string and the restore command we should execute * in the separate database controlling thread. */ -static inline void perform_aDoRestore(bpContext* ctx) +static inline void perform_aDoRestore(bplugin_private_context* ctx) { PoolMem ado_query(PM_NAME), temp(PM_NAME); POOLMEM* vdsname; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; /* * If no explicit instance name given use the DEFAULT_INSTANCE name. @@ -1241,14 +1255,14 @@ static inline void perform_aDoRestore(bpContext* ctx) /** * Run a query not in a separate thread. */ -static inline bool RunAdoQuery(bpContext* ctx, const char* query) +static inline bool RunAdoQuery(bplugin_private_context* ctx, const char* query) { bool retval = false; HRESULT hr; BSTR ado_connect_string = NULL; BSTR ado_query = NULL; _ADOConnection* adoConnection = NULL; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; Dmsg(ctx, debuglevel, "RunAdoQuery: ADO Query '%s'\n", query); @@ -1316,10 +1330,10 @@ static inline bool RunAdoQuery(bpContext* ctx, const char* query) /** * Automatically recover the database at the end of the whole restore process. */ -static inline bool PerformAdoRecover(bpContext* ctx) +static inline bool PerformAdoRecover(bplugin_private_context* ctx) { PoolMem recovery_query(PM_NAME); - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; SetAdoConnectString(ctx); Mmsg(recovery_query, "RESTORE DATABASE [%s] WITH RECOVERY", p_ctx->database); @@ -1330,12 +1344,13 @@ static inline bool PerformAdoRecover(bpContext* ctx) /** * Setup a VDI device for performing a backup or restore operation. */ -static inline bool SetupVdiDevice(bpContext* ctx, struct io_pkt* io) +static inline bool SetupVdiDevice(bplugin_private_context* ctx, + struct io_pkt* io) { int status; HRESULT hr = NOERROR; GUID vdsId; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if ((p_ctx->username && !p_ctx->password) || (!p_ctx->username && p_ctx->password)) { @@ -1499,11 +1514,11 @@ static inline bool SetupVdiDevice(bpContext* ctx, struct io_pkt* io) /** * Perform an I/O operation to a file as part of a restore. */ -static inline bool PerformFileIo(bpContext* ctx, +static inline bool PerformFileIo(bplugin_private_context* ctx, struct io_pkt* io, DWORD* completionCode) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; switch (io->func) { case IO_OPEN: @@ -1570,13 +1585,13 @@ static inline bool PerformFileIo(bpContext* ctx, /** * Perform an I/O operation to a virtual device as part of a backup or restore. */ -static inline bool PerformVdiIo(bpContext* ctx, +static inline bool PerformVdiIo(bplugin_private_context* ctx, struct io_pkt* io, DWORD* completionCode) { HRESULT hr = NOERROR; VDC_Command* cmd; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; /* * See what command is available on the VDIDevice. @@ -1669,11 +1684,12 @@ static inline bool PerformVdiIo(bpContext* ctx, /** * End of I/O tear down the VDI and check if everything did go to plan. */ -static inline bool TearDownVdiDevice(bpContext* ctx, struct io_pkt* io) +static inline bool TearDownVdiDevice(bplugin_private_context* ctx, + struct io_pkt* io) { HRESULT hr = NOERROR; VDC_Command* cmd; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; Dmsg(ctx, debuglevel, "mssqlvdi-fd: entering TearDownVdiDevice\n"); @@ -1724,10 +1740,10 @@ static inline bool TearDownVdiDevice(bpContext* ctx, struct io_pkt* io) /** * Bareos is calling us to do the actual I/O */ -static bRC pluginIO(bpContext* ctx, struct io_pkt* io) +static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) { DWORD completionCode = ERROR_BAD_ENVIRONMENT; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -1795,10 +1811,10 @@ static bRC pluginIO(bpContext* ctx, struct io_pkt* io) /** * See if we need to do any postprocessing after the restore. */ -static bRC end_restore_job(bpContext* ctx, void* value) +static bRC end_restore_job(bplugin_private_context* ctx, void* value) { bRC retval = bRC_OK; - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -1817,13 +1833,16 @@ static bRC end_restore_job(bpContext* ctx, void* value) * Bareos is notifying us that a plugin name string was found, * and passing us the plugin command, so we can prepare for a restore. */ -static bRC startRestoreFile(bpContext* ctx, const char* cmd) { return bRC_OK; } +static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) +{ + return bRC_OK; +} /** * Bareos is notifying us that the plugin data has terminated, * so the restore for this particular file is done. */ -static bRC endRestoreFile(bpContext* ctx) { return bRC_OK; } +static bRC endRestoreFile(bplugin_private_context* ctx) { return bRC_OK; } /** * This is called during restore to create the file (if necessary) We must @@ -1835,9 +1854,9 @@ static bRC endRestoreFile(bpContext* ctx) { return bRC_OK; } * CF_CREATED -- created, but no content to extract (typically directories) * CF_CORE -- let bareos core create the file */ -static bRC createFile(bpContext* ctx, struct restore_pkt* rp) +static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) { - plugin_ctx* p_ctx = (plugin_ctx*)ctx->pContext; + plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -1856,7 +1875,8 @@ static bRC createFile(bpContext* ctx, struct restore_pkt* rp) * We will get here if the File is a directory after everything is written in * the directory. */ -static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp) +static bRC setFileAttributes(bplugin_private_context* ctx, + struct restore_pkt* rp) { return bRC_OK; } @@ -1864,6 +1884,9 @@ static bRC setFileAttributes(bpContext* ctx, struct restore_pkt* rp) /** * When using Incremental dump, all previous dumps are necessary */ -static bRC checkFile(bpContext* ctx, char* fname) { return bRC_OK; } +static bRC checkFile(bplugin_private_context* ctx, char* fname) +{ + return bRC_OK; +} } /* namespace filedaemon */ From 97018b51c23bb863c4ceb3df03ac0a02c81e8e6b Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 30 Apr 2020 09:26:55 +0200 Subject: [PATCH 066/341] plugins: fixup bplugin_private_context -> PluginContext --- core/src/dird/dir_plugins.cc | 73 +++--- core/src/dird/dir_plugins.h | 36 +-- core/src/filed/fd_plugins.cc | 154 +++++------- core/src/filed/fd_plugins.h | 92 +++---- core/src/include/jcr.h | 4 +- core/src/lib/plugins.h | 2 +- .../dird/example/example-plugin-dir.cc | 32 +-- core/src/plugins/dird/python/python-dir.cc | 65 +++-- core/src/plugins/dird/python/python-dir.h | 12 +- core/src/plugins/filed/bpipe/bpipe-fd.cc | 105 ++++---- core/src/plugins/filed/cephfs/cephfs-fd.cc | 104 ++++---- .../filed/example/example-plugin-fd.cc | 91 +++---- core/src/plugins/filed/gfapi/gfapi-fd.cc | 104 ++++---- core/src/plugins/filed/python/bareosfd.cc | 194 +++++++-------- core/src/plugins/filed/python/python-fd.cc | 232 ++++++++---------- core/src/plugins/filed/python/python-fd.h | 19 +- .../python/test/python-fd-module-tester.cc | 76 ++---- core/src/plugins/filed/rados/rados-fd.cc | 107 ++++---- .../filed/test-deltaseq/test-deltaseq-fd.cc | 66 ++--- .../filed/test-plugin/test-plugin-fd.cc | 91 +++---- core/src/plugins/python_plugins_common.inc | 26 +- .../stored/autoxflate/autoxflate-sd.cc | 74 ++---- .../stored/example/example-plugin-sd.cc | 32 +-- core/src/plugins/stored/python/python-sd.cc | 65 +++-- core/src/plugins/stored/python/python-sd.h | 12 +- .../stored/scsicrypto/scsicrypto-sd.cc | 32 +-- .../stored/scsitapealert/scsitapealert-sd.cc | 32 +-- core/src/stored/sd_plugins.cc | 73 +++--- core/src/stored/sd_plugins.h | 36 +-- core/src/win32/plugins/filed/mssqlvdi-fd.cc | 112 ++++----- 30 files changed, 864 insertions(+), 1289 deletions(-) diff --git a/core/src/dird/dir_plugins.cc b/core/src/dird/dir_plugins.cc index 5e9454ab1fd..edb4b6eb9b9 100644 --- a/core/src/dird/dir_plugins.cc +++ b/core/src/dird/dir_plugins.cc @@ -46,27 +46,19 @@ static alist* dird_plugin_list; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; /* Forward referenced functions */ -static bRC bareosGetValue(bplugin_private_context* ctx, - brDirVariable var, - void* value); -static bRC bareosSetValue(bplugin_private_context* ctx, - bwDirVariable var, - void* value); -static bRC bareosRegisterEvents(bplugin_private_context* ctx, - int nr_events, - ...); -static bRC bareosUnRegisterEvents(bplugin_private_context* ctx, - int nr_events, - ...); -static bRC bareosGetInstanceCount(bplugin_private_context* ctx, int* ret); -static bRC bareosJobMsg(bplugin_private_context* ctx, +static bRC bareosGetValue(PluginContext* ctx, brDirVariable var, void* value); +static bRC bareosSetValue(PluginContext* ctx, bwDirVariable var, void* value); +static bRC bareosRegisterEvents(PluginContext* ctx, int nr_events, ...); +static bRC bareosUnRegisterEvents(PluginContext* ctx, int nr_events, ...); +static bRC bareosGetInstanceCount(PluginContext* ctx, int* ret); +static bRC bareosJobMsg(PluginContext* ctx, const char* file, int line, int type, utime_t mtime, const char* fmt, ...); -static bRC bareosDebugMsg(bplugin_private_context* ctx, +static bRC bareosDebugMsg(PluginContext* ctx, const char* file, int line, int level, @@ -97,8 +89,7 @@ struct b_plugin_ctx { Plugin* plugin; /* pointer to plugin of which this is an instance off */ }; -static inline bool IsEventEnabled(bplugin_private_context* ctx, - bDirEventType eventType) +static inline bool IsEventEnabled(PluginContext* ctx, bDirEventType eventType) { b_plugin_ctx* b_ctx; if (!ctx) { return false; } @@ -107,7 +98,7 @@ static inline bool IsEventEnabled(bplugin_private_context* ctx, return BitIsSet(eventType, b_ctx->events); } -static inline bool IsPluginDisabled(bplugin_private_context* ctx) +static inline bool IsPluginDisabled(PluginContext* ctx) { b_plugin_ctx* b_ctx; if (!ctx) { return true; } @@ -116,7 +107,7 @@ static inline bool IsPluginDisabled(bplugin_private_context* ctx) return b_ctx->disabled; } -static bool IsCtxGood(bplugin_private_context* ctx, +static bool IsCtxGood(PluginContext* ctx, JobControlRecord*& jcr, b_plugin_ctx*& bctx) { @@ -134,7 +125,7 @@ static bool IsCtxGood(bplugin_private_context* ctx, static inline bool trigger_plugin_event(JobControlRecord* jcr, bDirEventType eventType, bDirEvent* event, - bplugin_private_context* ctx, + PluginContext* ctx, void* value, alist* plugin_ctx_list, int* index, @@ -239,7 +230,7 @@ bRC GeneratePluginEvent(JobControlRecord* jcr, * See if we need to trigger the loaded plugins in reverse order. */ if (reverse) { - bplugin_private_context* ctx; + PluginContext* ctx; foreach_alist_rindex (i, ctx, plugin_ctx_list) { if (trigger_plugin_event(jcr, eventType, &event, ctx, value, @@ -248,7 +239,7 @@ bRC GeneratePluginEvent(JobControlRecord* jcr, } } } else { - bplugin_private_context* ctx; + PluginContext* ctx; foreach_alist_index (i, ctx, plugin_ctx_list) { if (trigger_plugin_event(jcr, eventType, &event, ctx, value, @@ -386,11 +377,11 @@ static bool IsPluginCompatible(Plugin* plugin) /** * Instantiate a new plugin instance. */ -static inline bplugin_private_context* instantiate_plugin(JobControlRecord* jcr, - Plugin* plugin, - uint32_t instance) +static inline PluginContext* instantiate_plugin(JobControlRecord* jcr, + Plugin* plugin, + uint32_t instance) { - bplugin_private_context* ctx; + PluginContext* ctx; b_plugin_ctx* b_ctx; b_ctx = (b_plugin_ctx*)malloc(sizeof(b_plugin_ctx)); @@ -401,7 +392,7 @@ static inline bplugin_private_context* instantiate_plugin(JobControlRecord* jcr, Dmsg2(debuglevel, "Instantiate dir-plugin_ctx_list=%p JobId=%d\n", jcr->plugin_ctx_list, jcr->JobId); - ctx = (bplugin_private_context*)malloc(sizeof(bplugin_private_context)); + ctx = (PluginContext*)malloc(sizeof(PluginContext)); ctx->instance = instance; ctx->plugin = plugin; ctx->core_private_context = (void*)b_ctx; @@ -422,7 +413,7 @@ void DispatchNewPluginOptions(JobControlRecord* jcr) { int i, j, len; Plugin* plugin; - bplugin_private_context* ctx = nullptr; + PluginContext* ctx = nullptr; uint32_t instance; bDirEvent event; bDirEventType eventType; @@ -548,7 +539,7 @@ void NewPlugins(JobControlRecord* jcr) */ void FreePlugins(JobControlRecord* jcr) { - bplugin_private_context* ctx = nullptr; + PluginContext* ctx = nullptr; if (!dird_plugin_list || !jcr->plugin_ctx_list) { return; } @@ -571,9 +562,7 @@ void FreePlugins(JobControlRecord* jcr) * Callbacks from the plugin * */ -static bRC bareosGetValue(bplugin_private_context* ctx, - brDirVariable var, - void* value) +static bRC bareosGetValue(PluginContext* ctx, brDirVariable var, void* value) { JobControlRecord* jcr = NULL; bRC retval = bRC_OK; @@ -758,9 +747,7 @@ static bRC bareosGetValue(bplugin_private_context* ctx, return retval; } -static bRC bareosSetValue(bplugin_private_context* ctx, - bwDirVariable var, - void* value) +static bRC bareosSetValue(PluginContext* ctx, bwDirVariable var, void* value) { JobControlRecord* jcr; @@ -787,9 +774,7 @@ static bRC bareosSetValue(bplugin_private_context* ctx, return bRC_OK; } -static bRC bareosRegisterEvents(bplugin_private_context* ctx, - int nr_events, - ...) +static bRC bareosRegisterEvents(PluginContext* ctx, int nr_events, ...) { int i; va_list args; @@ -809,9 +794,7 @@ static bRC bareosRegisterEvents(bplugin_private_context* ctx, return bRC_OK; } -static bRC bareosUnRegisterEvents(bplugin_private_context* ctx, - int nr_events, - ...) +static bRC bareosUnRegisterEvents(PluginContext* ctx, int nr_events, ...) { int i; va_list args; @@ -831,11 +814,11 @@ static bRC bareosUnRegisterEvents(bplugin_private_context* ctx, return bRC_OK; } -static bRC bareosGetInstanceCount(bplugin_private_context* ctx, int* ret) +static bRC bareosGetInstanceCount(PluginContext* ctx, int* ret) { int cnt; JobControlRecord *jcr, *njcr; - bplugin_private_context* nctx; + PluginContext* nctx; b_plugin_ctx* bctx; bRC retval = bRC_Error; @@ -862,7 +845,7 @@ static bRC bareosGetInstanceCount(bplugin_private_context* ctx, int* ret) return retval; } -static bRC bareosJobMsg(bplugin_private_context* ctx, +static bRC bareosJobMsg(PluginContext* ctx, const char* file, int line, int type, @@ -888,7 +871,7 @@ static bRC bareosJobMsg(bplugin_private_context* ctx, return bRC_OK; } -static bRC bareosDebugMsg(bplugin_private_context* ctx, +static bRC bareosDebugMsg(PluginContext* ctx, const char* file, int line, int level, diff --git a/core/src/dird/dir_plugins.h b/core/src/dird/dir_plugins.h index ced14d9bf04..137c8e687e3 100644 --- a/core/src/dird/dir_plugins.h +++ b/core/src/dird/dir_plugins.h @@ -141,25 +141,19 @@ extern "C" { typedef struct s_dirbareosFuncs { uint32_t size; uint32_t version; - bRC (*registerBareosEvents)(bplugin_private_context* ctx, int nr_events, ...); - bRC (*unregisterBareosEvents)(bplugin_private_context* ctx, - int nr_events, - ...); - bRC (*getInstanceCount)(bplugin_private_context* ctx, int* ret); - bRC (*getBareosValue)(bplugin_private_context* ctx, - brDirVariable var, - void* value); - bRC (*setBareosValue)(bplugin_private_context* ctx, - bwDirVariable var, - void* value); - bRC (*JobMessage)(bplugin_private_context* ctx, + bRC (*registerBareosEvents)(PluginContext* ctx, int nr_events, ...); + bRC (*unregisterBareosEvents)(PluginContext* ctx, int nr_events, ...); + bRC (*getInstanceCount)(PluginContext* ctx, int* ret); + bRC (*getBareosValue)(PluginContext* ctx, brDirVariable var, void* value); + bRC (*setBareosValue)(PluginContext* ctx, bwDirVariable var, void* value); + bRC (*JobMessage)(PluginContext* ctx, const char* file, int line, int type, utime_t mtime, const char* fmt, ...); - bRC (*DebugMessage)(bplugin_private_context* ctx, + bRC (*DebugMessage)(PluginContext* ctx, const char* file, int line, int level, @@ -198,17 +192,11 @@ typedef enum typedef struct s_dirpluginFuncs { uint32_t size; uint32_t version; - bRC (*newPlugin)(bplugin_private_context* ctx); - bRC (*freePlugin)(bplugin_private_context* ctx); - bRC (*getPluginValue)(bplugin_private_context* ctx, - pVariable var, - void* value); - bRC (*setPluginValue)(bplugin_private_context* ctx, - pVariable var, - void* value); - bRC (*handlePluginEvent)(bplugin_private_context* ctx, - bDirEvent* event, - void* value); + bRC (*newPlugin)(PluginContext* ctx); + bRC (*freePlugin)(PluginContext* ctx); + bRC (*getPluginValue)(PluginContext* ctx, pVariable var, void* value); + bRC (*setPluginValue)(PluginContext* ctx, pVariable var, void* value); + bRC (*handlePluginEvent)(PluginContext* ctx, bDirEvent* event, void* value); } pDirFuncs; #define DirplugFunc(plugin) ((pDirFuncs*)(plugin->plugin_functions)) diff --git a/core/src/filed/fd_plugins.cc b/core/src/filed/fd_plugins.cc index 5e419589dac..ce366ca89c6 100644 --- a/core/src/filed/fd_plugins.cc +++ b/core/src/filed/fd_plugins.cc @@ -80,63 +80,46 @@ extern int SaveFile(JobControlRecord* jcr, /** * Forward referenced functions */ -static bRC bareosGetValue(bplugin_private_context* ctx, - bVariable var, - void* value); -static bRC bareosSetValue(bplugin_private_context* ctx, - bVariable var, - void* value); -static bRC bareosRegisterEvents(bplugin_private_context* ctx, - int nr_events, - ...); -static bRC bareosUnRegisterEvents(bplugin_private_context* ctx, - int nr_events, - ...); -static bRC bareosJobMsg(bplugin_private_context* ctx, +static bRC bareosGetValue(PluginContext* ctx, bVariable var, void* value); +static bRC bareosSetValue(PluginContext* ctx, bVariable var, void* value); +static bRC bareosRegisterEvents(PluginContext* ctx, int nr_events, ...); +static bRC bareosUnRegisterEvents(PluginContext* ctx, int nr_events, ...); +static bRC bareosJobMsg(PluginContext* ctx, const char* fname, int line, int type, utime_t mtime, const char* fmt, ...); -static bRC bareosDebugMsg(bplugin_private_context* ctx, +static bRC bareosDebugMsg(PluginContext* ctx, const char* fname, int line, int level, const char* fmt, ...); -static void* bareosMalloc(bplugin_private_context* ctx, +static void* bareosMalloc(PluginContext* ctx, const char* fname, int line, size_t size); -static void bareosFree(bplugin_private_context* ctx, +static void bareosFree(PluginContext* ctx, const char* file, int line, void* mem); -static bRC bareosAddExclude(bplugin_private_context* ctx, const char* file); -static bRC bareosAddInclude(bplugin_private_context* ctx, const char* file); -static bRC bareosAddOptions(bplugin_private_context* ctx, const char* opts); -static bRC bareosAddRegex(bplugin_private_context* ctx, - const char* item, - int type); -static bRC bareosAddWild(bplugin_private_context* ctx, - const char* item, - int type); -static bRC bareosNewOptions(bplugin_private_context* ctx); -static bRC bareosNewInclude(bplugin_private_context* ctx); -static bRC bareosNewPreInclude(bplugin_private_context* ctx); +static bRC bareosAddExclude(PluginContext* ctx, const char* file); +static bRC bareosAddInclude(PluginContext* ctx, const char* file); +static bRC bareosAddOptions(PluginContext* ctx, const char* opts); +static bRC bareosAddRegex(PluginContext* ctx, const char* item, int type); +static bRC bareosAddWild(PluginContext* ctx, const char* item, int type); +static bRC bareosNewOptions(PluginContext* ctx); +static bRC bareosNewInclude(PluginContext* ctx); +static bRC bareosNewPreInclude(PluginContext* ctx); static bool IsPluginCompatible(Plugin* plugin); static bool GetPluginName(JobControlRecord* jcr, char* cmd, int* ret); -static bRC bareosCheckChanges(bplugin_private_context* ctx, - struct save_pkt* sp); -static bRC bareosAcceptFile(bplugin_private_context* ctx, struct save_pkt* sp); -static bRC bareosSetSeenBitmap(bplugin_private_context* ctx, - bool all, - char* fname); -static bRC bareosClearSeenBitmap(bplugin_private_context* ctx, - bool all, - char* fname); -static bRC bareosGetInstanceCount(bplugin_private_context* ctx, int* ret); +static bRC bareosCheckChanges(PluginContext* ctx, struct save_pkt* sp); +static bRC bareosAcceptFile(PluginContext* ctx, struct save_pkt* sp); +static bRC bareosSetSeenBitmap(PluginContext* ctx, bool all, char* fname); +static bRC bareosClearSeenBitmap(PluginContext* ctx, bool all, char* fname); +static bRC bareosGetInstanceCount(PluginContext* ctx, int* ret); /** * These will be plugged into the global pointer structure for the findlib. @@ -198,8 +181,7 @@ struct b_plugin_ctx { Plugin* plugin; /* pointer to plugin of which this is an instance off */ }; -static inline bool IsEventEnabled(bplugin_private_context* ctx, - bEventType eventType) +static inline bool IsEventEnabled(PluginContext* ctx, bEventType eventType) { b_plugin_ctx* b_ctx; @@ -211,7 +193,7 @@ static inline bool IsEventEnabled(bplugin_private_context* ctx, return BitIsSet(eventType, b_ctx->events); } -static inline bool IsPluginDisabled(bplugin_private_context* ctx) +static inline bool IsPluginDisabled(PluginContext* ctx) { b_plugin_ctx* b_ctx; @@ -223,7 +205,7 @@ static inline bool IsPluginDisabled(bplugin_private_context* ctx) return b_ctx->disabled; } -static bool IsCtxGood(bplugin_private_context* ctx, +static bool IsCtxGood(PluginContext* ctx, JobControlRecord*& jcr, b_plugin_ctx*& bctx) { @@ -276,7 +258,7 @@ static bool for_thIsPlugin(Plugin* plugin, char* name, int len) static inline bool trigger_plugin_event(JobControlRecord* jcr, bEventType eventType, bEvent* event, - bplugin_private_context* ctx, + PluginContext* ctx, void* value, alist* plugin_ctx_list, int* index, @@ -370,7 +352,7 @@ bRC GeneratePluginEvent(JobControlRecord* jcr, int len = 0; bool call_if_canceled = false; restore_object_pkt* rop; - bplugin_private_context* ctx = nullptr; + PluginContext* ctx = nullptr; alist* plugin_ctx_list; bRC rc = bRC_OK; @@ -492,7 +474,7 @@ bRC GeneratePluginEvent(JobControlRecord* jcr, */ bool PluginCheckFile(JobControlRecord* jcr, char* fname) { - bplugin_private_context* ctx = nullptr; + PluginContext* ctx = nullptr; alist* plugin_ctx_list; int retval = bRC_OK; @@ -608,7 +590,7 @@ bRC PluginOptionHandleFile(JobControlRecord* jcr, bRC retval = bRC_Core; bEvent event; bEventType eventType; - bplugin_private_context* ctx = nullptr; + PluginContext* ctx = nullptr; alist* plugin_ctx_list; cmd = ff_pkt->plugin; @@ -693,7 +675,7 @@ int PluginSave(JobControlRecord* jcr, FindFilesPacket* ff_pkt, bool top_level) bRC retval; char* cmd; bEvent event; - bplugin_private_context* ctx = nullptr; + PluginContext* ctx = nullptr; struct save_pkt sp; bEventType eventType; PoolMem fname(PM_FNAME); @@ -953,7 +935,7 @@ int PluginEstimate(JobControlRecord* jcr, bEventType eventType; PoolMem fname(PM_FNAME); PoolMem link(PM_FNAME); - bplugin_private_context* ctx = nullptr; + PluginContext* ctx = nullptr; alist* plugin_ctx_list; Attributes attr; @@ -1158,7 +1140,7 @@ bool PluginNameStream(JobControlRecord* jcr, char* name) char* p = name; bool start; bool retval = true; - bplugin_private_context* ctx = nullptr; + PluginContext* ctx = nullptr; alist* plugin_ctx_list; Dmsg1(debuglevel, "Read plugin stream string=%s\n", name); @@ -1288,7 +1270,7 @@ int PluginCreateFile(JobControlRecord* jcr, int status; Plugin* plugin; struct restore_pkt rp; - bplugin_private_context* ctx = jcr->plugin_ctx; + PluginContext* ctx = jcr->plugin_ctx; b_plugin_ctx* b_ctx = (b_plugin_ctx*)jcr->plugin_ctx->core_private_context; if (!ctx || !SetCmdPlugin(bfd, jcr) || jcr->IsJobCanceled()) { @@ -1828,11 +1810,11 @@ static bool IsPluginCompatible(Plugin* plugin) /** * Instantiate a new plugin instance. */ -static inline bplugin_private_context* instantiate_plugin(JobControlRecord* jcr, - Plugin* plugin, - char instance) +static inline PluginContext* instantiate_plugin(JobControlRecord* jcr, + Plugin* plugin, + char instance) { - bplugin_private_context* ctx; + PluginContext* ctx; b_plugin_ctx* b_ctx; b_ctx = (b_plugin_ctx*)malloc(sizeof(b_plugin_ctx)); @@ -1840,7 +1822,7 @@ static inline bplugin_private_context* instantiate_plugin(JobControlRecord* jcr, b_ctx->jcr = jcr; b_ctx->plugin = plugin; - ctx = (bplugin_private_context*)malloc(sizeof(bplugin_private_context)); + ctx = (PluginContext*)malloc(sizeof(PluginContext)); ctx->instance = instance; ctx->plugin = plugin; ctx->core_private_context = (void*)b_ctx; @@ -1895,7 +1877,7 @@ void NewPlugins(JobControlRecord* jcr) */ void FreePlugins(JobControlRecord* jcr) { - bplugin_private_context* ctx = nullptr; + PluginContext* ctx = nullptr; if (!fd_plugin_list || !jcr->plugin_ctx_list) { return; } @@ -2104,9 +2086,7 @@ static boffset_t MyPluginBlseek(BareosWinFilePacket* bfd, * * ============================================================== */ -static bRC bareosGetValue(bplugin_private_context* ctx, - bVariable var, - void* value) +static bRC bareosGetValue(PluginContext* ctx, bVariable var, void* value) { JobControlRecord* jcr = NULL; if (!value) { return bRC_Error; } @@ -2218,9 +2198,7 @@ static bRC bareosGetValue(bplugin_private_context* ctx, return bRC_OK; } -static bRC bareosSetValue(bplugin_private_context* ctx, - bVariable var, - void* value) +static bRC bareosSetValue(PluginContext* ctx, bVariable var, void* value) { JobControlRecord* jcr; @@ -2248,9 +2226,7 @@ static bRC bareosSetValue(bplugin_private_context* ctx, return bRC_OK; } -static bRC bareosRegisterEvents(bplugin_private_context* ctx, - int nr_events, - ...) +static bRC bareosRegisterEvents(PluginContext* ctx, int nr_events, ...) { int i; va_list args; @@ -2274,11 +2250,11 @@ static bRC bareosRegisterEvents(bplugin_private_context* ctx, /** * Get the number of instaces instantiated of a certain plugin. */ -static bRC bareosGetInstanceCount(bplugin_private_context* ctx, int* ret) +static bRC bareosGetInstanceCount(PluginContext* ctx, int* ret) { int cnt; JobControlRecord *jcr, *njcr; - bplugin_private_context* nctx; + PluginContext* nctx; b_plugin_ctx* bctx; bRC retval = bRC_Error; @@ -2305,9 +2281,7 @@ static bRC bareosGetInstanceCount(bplugin_private_context* ctx, int* ret) return retval; } -static bRC bareosUnRegisterEvents(bplugin_private_context* ctx, - int nr_events, - ...) +static bRC bareosUnRegisterEvents(PluginContext* ctx, int nr_events, ...) { int i; va_list args; @@ -2328,7 +2302,7 @@ static bRC bareosUnRegisterEvents(bplugin_private_context* ctx, return bRC_OK; } -static bRC bareosJobMsg(bplugin_private_context* ctx, +static bRC bareosJobMsg(PluginContext* ctx, const char* fname, int line, int type, @@ -2354,7 +2328,7 @@ static bRC bareosJobMsg(bplugin_private_context* ctx, return bRC_OK; } -static bRC bareosDebugMsg(bplugin_private_context* ctx, +static bRC bareosDebugMsg(PluginContext* ctx, const char* fname, int line, int level, @@ -2372,7 +2346,7 @@ static bRC bareosDebugMsg(bplugin_private_context* ctx, return bRC_OK; } -static void* bareosMalloc(bplugin_private_context* ctx, +static void* bareosMalloc(PluginContext* ctx, const char* fname, int line, size_t size) @@ -2380,7 +2354,7 @@ static void* bareosMalloc(bplugin_private_context* ctx, return malloc(size); } -static void bareosFree(bplugin_private_context* ctx, +static void bareosFree(PluginContext* ctx, const char* fname, int line, void* mem) @@ -2392,7 +2366,7 @@ static void bareosFree(bplugin_private_context* ctx, * Let the plugin define files/directories to be excluded from the main * backup. */ -static bRC bareosAddExclude(bplugin_private_context* ctx, const char* fname) +static bRC bareosAddExclude(PluginContext* ctx, const char* fname) { JobControlRecord* jcr; findIncludeExcludeItem* old; @@ -2434,7 +2408,7 @@ static bRC bareosAddExclude(bplugin_private_context* ctx, const char* fname) * Let the plugin define files/directories to be excluded from the main * backup. */ -static bRC bareosAddInclude(bplugin_private_context* ctx, const char* fname) +static bRC bareosAddInclude(PluginContext* ctx, const char* fname) { JobControlRecord* jcr; findIncludeExcludeItem* old; @@ -2469,7 +2443,7 @@ static bRC bareosAddInclude(bplugin_private_context* ctx, const char* fname) return bRC_OK; } -static bRC bareosAddOptions(bplugin_private_context* ctx, const char* opts) +static bRC bareosAddOptions(PluginContext* ctx, const char* opts) { JobControlRecord* jcr; b_plugin_ctx* bctx; @@ -2483,9 +2457,7 @@ static bRC bareosAddOptions(bplugin_private_context* ctx, const char* opts) return bRC_OK; } -static bRC bareosAddRegex(bplugin_private_context* ctx, - const char* item, - int type) +static bRC bareosAddRegex(PluginContext* ctx, const char* item, int type) { JobControlRecord* jcr; b_plugin_ctx* bctx; @@ -2499,9 +2471,7 @@ static bRC bareosAddRegex(bplugin_private_context* ctx, return bRC_OK; } -static bRC bareosAddWild(bplugin_private_context* ctx, - const char* item, - int type) +static bRC bareosAddWild(PluginContext* ctx, const char* item, int type) { JobControlRecord* jcr; b_plugin_ctx* bctx; @@ -2515,7 +2485,7 @@ static bRC bareosAddWild(bplugin_private_context* ctx, return bRC_OK; } -static bRC bareosNewOptions(bplugin_private_context* ctx) +static bRC bareosNewOptions(PluginContext* ctx) { JobControlRecord* jcr; b_plugin_ctx* bctx; @@ -2526,7 +2496,7 @@ static bRC bareosNewOptions(bplugin_private_context* ctx) return bRC_OK; } -static bRC bareosNewInclude(bplugin_private_context* ctx) +static bRC bareosNewInclude(PluginContext* ctx) { JobControlRecord* jcr; b_plugin_ctx* bctx; @@ -2537,7 +2507,7 @@ static bRC bareosNewInclude(bplugin_private_context* ctx) return bRC_OK; } -static bRC bareosNewPreInclude(bplugin_private_context* ctx) +static bRC bareosNewPreInclude(PluginContext* ctx) { JobControlRecord* jcr; b_plugin_ctx* bctx; @@ -2554,7 +2524,7 @@ static bRC bareosNewPreInclude(bplugin_private_context* ctx) /** * Check if a file have to be backed up using Accurate code */ -static bRC bareosCheckChanges(bplugin_private_context* ctx, struct save_pkt* sp) +static bRC bareosCheckChanges(PluginContext* ctx, struct save_pkt* sp) { JobControlRecord* jcr; b_plugin_ctx* bctx; @@ -2605,7 +2575,7 @@ static bRC bareosCheckChanges(bplugin_private_context* ctx, struct save_pkt* sp) /** * Check if a file would be saved using current Include/Exclude code */ -static bRC bareosAcceptFile(bplugin_private_context* ctx, struct save_pkt* sp) +static bRC bareosAcceptFile(PluginContext* ctx, struct save_pkt* sp) { JobControlRecord* jcr; FindFilesPacket* ff_pkt; @@ -2633,9 +2603,7 @@ static bRC bareosAcceptFile(bplugin_private_context* ctx, struct save_pkt* sp) /** * Manipulate the accurate seen bitmap for setting bits */ -static bRC bareosSetSeenBitmap(bplugin_private_context* ctx, - bool all, - char* fname) +static bRC bareosSetSeenBitmap(PluginContext* ctx, bool all, char* fname) { JobControlRecord* jcr; b_plugin_ctx* bctx; @@ -2663,9 +2631,7 @@ static bRC bareosSetSeenBitmap(bplugin_private_context* ctx, /** * Manipulate the accurate seen bitmap for clearing bits */ -static bRC bareosClearSeenBitmap(bplugin_private_context* ctx, - bool all, - char* fname) +static bRC bareosClearSeenBitmap(PluginContext* ctx, bool all, char* fname) { JobControlRecord* jcr; b_plugin_ctx* bctx; diff --git a/core/src/filed/fd_plugins.h b/core/src/filed/fd_plugins.h index 724e958443b..2d785929395 100644 --- a/core/src/filed/fd_plugins.h +++ b/core/src/filed/fd_plugins.h @@ -319,51 +319,42 @@ extern "C" { typedef struct s_bareosFuncs { uint32_t size; uint32_t version; - bRC (*registerBareosEvents)(bplugin_private_context* ctx, int nr_events, ...); - bRC (*unregisterBareosEvents)(bplugin_private_context* ctx, - int nr_events, - ...); - bRC (*getInstanceCount)(bplugin_private_context* ctx, int* ret); - bRC (*getBareosValue)(bplugin_private_context* ctx, - bVariable var, - void* value); - bRC (*setBareosValue)(bplugin_private_context* ctx, - bVariable var, - void* value); - bRC (*JobMessage)(bplugin_private_context* ctx, + bRC (*registerBareosEvents)(PluginContext* ctx, int nr_events, ...); + bRC (*unregisterBareosEvents)(PluginContext* ctx, int nr_events, ...); + bRC (*getInstanceCount)(PluginContext* ctx, int* ret); + bRC (*getBareosValue)(PluginContext* ctx, bVariable var, void* value); + bRC (*setBareosValue)(PluginContext* ctx, bVariable var, void* value); + bRC (*JobMessage)(PluginContext* ctx, const char* file, int line, int type, utime_t mtime, const char* fmt, ...); - bRC (*DebugMessage)(bplugin_private_context* ctx, + bRC (*DebugMessage)(PluginContext* ctx, const char* file, int line, int level, const char* fmt, ...); - void* (*bareosMalloc)(bplugin_private_context* ctx, + void* (*bareosMalloc)(PluginContext* ctx, const char* file, int line, size_t size); - void (*bareosFree)(bplugin_private_context* ctx, - const char* file, - int line, - void* mem); - bRC (*AddExclude)(bplugin_private_context* ctx, const char* file); - bRC (*AddInclude)(bplugin_private_context* ctx, const char* file); - bRC (*AddOptions)(bplugin_private_context* ctx, const char* opts); - bRC (*AddRegex)(bplugin_private_context* ctx, const char* item, int type); - bRC (*AddWild)(bplugin_private_context* ctx, const char* item, int type); - bRC (*NewOptions)(bplugin_private_context* ctx); - bRC (*NewInclude)(bplugin_private_context* ctx); - bRC (*NewPreInclude)(bplugin_private_context* ctx); - bRC (*checkChanges)(bplugin_private_context* ctx, struct save_pkt* sp); - bRC (*AcceptFile)(bplugin_private_context* ctx, + void (*bareosFree)(PluginContext* ctx, const char* file, int line, void* mem); + bRC (*AddExclude)(PluginContext* ctx, const char* file); + bRC (*AddInclude)(PluginContext* ctx, const char* file); + bRC (*AddOptions)(PluginContext* ctx, const char* opts); + bRC (*AddRegex)(PluginContext* ctx, const char* item, int type); + bRC (*AddWild)(PluginContext* ctx, const char* item, int type); + bRC (*NewOptions)(PluginContext* ctx); + bRC (*NewInclude)(PluginContext* ctx); + bRC (*NewPreInclude)(PluginContext* ctx); + bRC (*checkChanges)(PluginContext* ctx, struct save_pkt* sp); + bRC (*AcceptFile)(PluginContext* ctx, struct save_pkt* sp); /* Need fname and statp */ - bRC (*SetSeenBitmap)(bplugin_private_context* ctx, bool all, char* fname); - bRC (*ClearSeenBitmap)(bplugin_private_context* ctx, bool all, char* fname); + bRC (*SetSeenBitmap)(PluginContext* ctx, bool all, char* fname); + bRC (*ClearSeenBitmap)(PluginContext* ctx, bool all, char* fname); } BareosCoreFunctions; /**************************************************************************** @@ -387,30 +378,23 @@ typedef enum typedef struct s_pluginFuncs { uint32_t size; uint32_t version; - bRC (*newPlugin)(bplugin_private_context* ctx); - bRC (*freePlugin)(bplugin_private_context* ctx); - bRC (*getPluginValue)(bplugin_private_context* ctx, - pVariable var, - void* value); - bRC (*setPluginValue)(bplugin_private_context* ctx, - pVariable var, - void* value); - bRC (*handlePluginEvent)(bplugin_private_context* ctx, - bEvent* event, - void* value); - bRC (*startBackupFile)(bplugin_private_context* ctx, struct save_pkt* sp); - bRC (*endBackupFile)(bplugin_private_context* ctx); - bRC (*startRestoreFile)(bplugin_private_context* ctx, const char* cmd); - bRC (*endRestoreFile)(bplugin_private_context* ctx); - bRC (*pluginIO)(bplugin_private_context* ctx, struct io_pkt* io); - bRC (*createFile)(bplugin_private_context* ctx, struct restore_pkt* rp); - bRC (*setFileAttributes)(bplugin_private_context* ctx, - struct restore_pkt* rp); - bRC (*checkFile)(bplugin_private_context* ctx, char* fname); - bRC (*getAcl)(bplugin_private_context* ctx, struct acl_pkt* ap); - bRC (*setAcl)(bplugin_private_context* ctx, struct acl_pkt* ap); - bRC (*getXattr)(bplugin_private_context* ctx, struct xattr_pkt* xp); - bRC (*setXattr)(bplugin_private_context* ctx, struct xattr_pkt* xp); + bRC (*newPlugin)(PluginContext* ctx); + bRC (*freePlugin)(PluginContext* ctx); + bRC (*getPluginValue)(PluginContext* ctx, pVariable var, void* value); + bRC (*setPluginValue)(PluginContext* ctx, pVariable var, void* value); + bRC (*handlePluginEvent)(PluginContext* ctx, bEvent* event, void* value); + bRC (*startBackupFile)(PluginContext* ctx, struct save_pkt* sp); + bRC (*endBackupFile)(PluginContext* ctx); + bRC (*startRestoreFile)(PluginContext* ctx, const char* cmd); + bRC (*endRestoreFile)(PluginContext* ctx); + bRC (*pluginIO)(PluginContext* ctx, struct io_pkt* io); + bRC (*createFile)(PluginContext* ctx, struct restore_pkt* rp); + bRC (*setFileAttributes)(PluginContext* ctx, struct restore_pkt* rp); + bRC (*checkFile)(PluginContext* ctx, char* fname); + bRC (*getAcl)(PluginContext* ctx, struct acl_pkt* ap); + bRC (*setAcl)(PluginContext* ctx, struct acl_pkt* ap); + bRC (*getXattr)(PluginContext* ctx, struct xattr_pkt* xp); + bRC (*setXattr)(PluginContext* ctx, struct xattr_pkt* xp); } pFuncs; #define PlugFunc(plugin) ((pFuncs*)(plugin->plugin_functions)) diff --git a/core/src/include/jcr.h b/core/src/include/jcr.h index 7ac2b8949e4..a645883cf71 100644 --- a/core/src/include/jcr.h +++ b/core/src/include/jcr.h @@ -49,7 +49,7 @@ class htable; class JobControlRecord; struct AttributesDbRecord; -struct bplugin_private_context; +struct PluginContext; struct JobControlRecordPrivate; struct VolumeSessionInfo; @@ -221,7 +221,7 @@ class JobControlRecord { guid_list* id_list{}; /**< User/group id to name list */ alist* plugin_ctx_list{}; /**< List of contexts for plugins */ - bplugin_private_context* plugin_ctx{}; /**< Current plugin context */ + PluginContext* plugin_ctx{}; /**< Current plugin context */ POOLMEM* comment{}; /**< Comment for this Job */ int64_t max_bandwidth{}; /**< Bandwidth limit for this Job */ htable* path_list{}; /**< Directory list (used by findlib) */ diff --git a/core/src/lib/plugins.h b/core/src/lib/plugins.h index e0bb06c1297..1127e737a9d 100644 --- a/core/src/lib/plugins.h +++ b/core/src/lib/plugins.h @@ -79,7 +79,7 @@ class Plugin { /** * Context packet as first argument of all functions */ -struct bplugin_private_context { +struct PluginContext { uint32_t instance; Plugin* plugin; void* core_private_context; /* BAREOS private context */ diff --git a/core/src/plugins/dird/example/example-plugin-dir.cc b/core/src/plugins/dird/example/example-plugin-dir.cc index 9b3e11e3575..d06a19bbc2e 100644 --- a/core/src/plugins/dird/example/example-plugin-dir.cc +++ b/core/src/plugins/dird/example/example-plugin-dir.cc @@ -38,17 +38,11 @@ namespace directordaemon { /* Forward referenced functions */ -static bRC newPlugin(bplugin_private_context* ctx); -static bRC freePlugin(bplugin_private_context* ctx); -static bRC getPluginValue(bplugin_private_context* ctx, - pDirVariable var, - void* value); -static bRC setPluginValue(bplugin_private_context* ctx, - pDirVariable var, - void* value); -static bRC handlePluginEvent(bplugin_private_context* ctx, - bDirEvent* event, - void* value); +static bRC newPlugin(PluginContext* ctx); +static bRC freePlugin(PluginContext* ctx); +static bRC getPluginValue(PluginContext* ctx, pDirVariable var, void* value); +static bRC setPluginValue(PluginContext* ctx, pDirVariable var, void* value); +static bRC handlePluginEvent(PluginContext* ctx, bDirEvent* event, void* value); /* Pointers to Bareos functions */ @@ -110,7 +104,7 @@ bRC unloadPlugin() } #endif -static bRC newPlugin(bplugin_private_context* ctx) +static bRC newPlugin(PluginContext* ctx) { int JobId = 0; bareos_core_functions->getBareosValue(ctx, bDirVarJobId, (void*)&JobId); @@ -120,7 +114,7 @@ static bRC newPlugin(bplugin_private_context* ctx) return bRC_OK; } -static bRC freePlugin(bplugin_private_context* ctx) +static bRC freePlugin(PluginContext* ctx) { int JobId = 0; bareos_core_functions->getBareosValue(ctx, bDirVarJobId, (void*)&JobId); @@ -128,25 +122,19 @@ static bRC freePlugin(bplugin_private_context* ctx) return bRC_OK; } -static bRC getPluginValue(bplugin_private_context* ctx, - pDirVariable var, - void* value) +static bRC getPluginValue(PluginContext* ctx, pDirVariable var, void* value) { printf("plugin: getPluginValue var=%d\n", var); return bRC_OK; } -static bRC setPluginValue(bplugin_private_context* ctx, - pDirVariable var, - void* value) +static bRC setPluginValue(PluginContext* ctx, pDirVariable var, void* value) { printf("plugin: setPluginValue var=%d\n", var); return bRC_OK; } -static bRC handlePluginEvent(bplugin_private_context* ctx, - bDirEvent* event, - void* value) +static bRC handlePluginEvent(PluginContext* ctx, bDirEvent* event, void* value) { char* name; int val; diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index e1b1b85c45b..c4cd6865e79 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -58,34 +58,32 @@ static const int debuglevel = 150; /* Forward referenced functions */ -static bRC newPlugin(bplugin_private_context* bareos_plugin_ctx); -static bRC freePlugin(bplugin_private_context* bareos_plugin_ctx); -static bRC getPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC newPlugin(PluginContext* bareos_plugin_ctx); +static bRC freePlugin(PluginContext* bareos_plugin_ctx); +static bRC getPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); -static bRC setPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC setPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); -static bRC handlePluginEvent(bplugin_private_context* bareos_plugin_ctx, +static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, bDirEvent* event, void* value); -static bRC parse_plugin_definition(bplugin_private_context* bareos_plugin_ctx, +static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, void* value, PoolMem& plugin_options); -static void PyErrorHandler(bplugin_private_context* bareos_plugin_ctx, - int msgtype); -static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, - void* value); -static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, +static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); +static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); +static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, void* value); -static bRC PyGetPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); -static bRC PySetPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); -static bRC PyHandlePluginEvent(bplugin_private_context* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, bDirEvent* event, void* value); @@ -189,7 +187,7 @@ bRC unloadPlugin() #endif /* Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bplugin_private_context* bareos_plugin_ctx) +static bRC newPlugin(PluginContext* bareos_plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = (struct plugin_private_context*)malloc( @@ -215,7 +213,7 @@ static bRC newPlugin(bplugin_private_context* bareos_plugin_ctx) } /* Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bplugin_private_context* bareos_plugin_ctx) +static bRC freePlugin(PluginContext* bareos_plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; @@ -240,7 +238,7 @@ static bRC freePlugin(bplugin_private_context* bareos_plugin_ctx) } -static bRC handlePluginEvent(bplugin_private_context* bareos_plugin_ctx, +static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, bDirEvent* event, void* value) { @@ -323,7 +321,7 @@ static bRC handlePluginEvent(bplugin_private_context* bareos_plugin_ctx, * * python:module_path=:module_name=:... */ -static bRC parse_plugin_definition(bplugin_private_context* bareos_plugin_ctx, +static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, void* value, PoolMem& plugin_options) { @@ -467,7 +465,7 @@ static bRC parse_plugin_definition(bplugin_private_context* bareos_plugin_ctx, * module path and the module to load. We also load the dictionary used * for looking up the Python methods. */ -static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, void* value) +static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -566,7 +564,7 @@ static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, void* value) * PyLoadModule() has loaded the Python module and made sure things are * operational. */ -static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, +static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; @@ -610,21 +608,21 @@ static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, return retval; } -static bRC PyGetPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PySetPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PyHandlePluginEvent(bplugin_private_context* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, bDirEvent* event, void* value) { @@ -672,8 +670,7 @@ static bRC PyHandlePluginEvent(bplugin_private_context* bareos_plugin_ctx, static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } @@ -759,8 +756,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject* pyValue; @@ -811,8 +807,7 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; @@ -834,8 +829,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; @@ -856,8 +850,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -899,8 +892,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -942,8 +934,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } diff --git a/core/src/plugins/dird/python/python-dir.h b/core/src/plugins/dird/python/python-dir.h index f0069b0dd4f..543986ff99a 100644 --- a/core/src/plugins/dird/python/python-dir.h +++ b/core/src/plugins/dird/python/python-dir.h @@ -83,13 +83,13 @@ static PyMethodDef Methods[] = { {NULL, NULL, 0, NULL}}; -static void* bareos_plugin_context = NULL; +static void* bareos_PluginContext = NULL; // MOD_INIT(PYTHON_MODULE_NAME) MOD_INIT(bareosdir) { - /* bareos_plugin_context holds the bplugin_private_context instead of passing - * to Python and extracting it back like it was before. bareos_plugin_context + /* bareos_PluginContext holds the PluginContext instead of passing + * to Python and extracting it back like it was before. bareos_PluginContext * needs to be set after loading the PYTHON_MODULE_NAME binary python module * and will be used for all calls. */ @@ -98,8 +98,8 @@ MOD_INIT(bareosdir) /* Pointer Capsules to avoid context transfer back and forth */ PyObject* PyModulePluginContext = - PyCapsule_New((void*)&bareos_plugin_context, - PYTHON_MODULE_NAME_QUOTED ".bplugin_private_context", NULL); + PyCapsule_New((void*)&bareos_PluginContext, + PYTHON_MODULE_NAME_QUOTED ".PluginContext", NULL); if (!PyModulePluginContext) { printf(PYTHON_MODULE_NAME_QUOTED ": PyCapsule_New failed\n"); @@ -109,7 +109,7 @@ MOD_INIT(bareosdir) MOD_DEF(m, PYTHON_MODULE_NAME_QUOTED, NULL, Methods) if (PyModulePluginContext) { - PyModule_AddObject(m, "bplugin_private_context", PyModulePluginContext); + PyModule_AddObject(m, "PluginContext", PyModulePluginContext); } else { printf(PYTHON_MODULE_NAME_QUOTED ":PyModule_AddObject failed\n"); return MOD_ERROR_VAL; diff --git a/core/src/plugins/filed/bpipe/bpipe-fd.cc b/core/src/plugins/filed/bpipe/bpipe-fd.cc index b51333f1f44..b2aeaaa8f93 100644 --- a/core/src/plugins/filed/bpipe/bpipe-fd.cc +++ b/core/src/plugins/filed/bpipe/bpipe-fd.cc @@ -46,34 +46,27 @@ static const int debuglevel = 150; " the data is internally stored as filepath (e.g. mybackup/backup1)" /* Forward referenced functions */ -static bRC newPlugin(bplugin_private_context* ctx); -static bRC freePlugin(bplugin_private_context* ctx); -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC handlePluginEvent(bplugin_private_context* ctx, - bEvent* event, - void* value); -static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp); -static bRC endBackupFile(bplugin_private_context* ctx); -static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io); -static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd); -static bRC endRestoreFile(bplugin_private_context* ctx); -static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp); -static bRC setFileAttributes(bplugin_private_context* ctx, - struct restore_pkt* rp); -static bRC checkFile(bplugin_private_context* ctx, char* fname); -static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap); -static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap); -static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp); -static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp); - -static char* apply_rp_codes(bplugin_private_context* ctx); -static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value); -static bRC plugin_has_all_arguments(bplugin_private_context* ctx); +static bRC newPlugin(PluginContext* ctx); +static bRC freePlugin(PluginContext* ctx); +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC handlePluginEvent(PluginContext* ctx, bEvent* event, void* value); +static bRC startBackupFile(PluginContext* ctx, struct save_pkt* sp); +static bRC endBackupFile(PluginContext* ctx); +static bRC pluginIO(PluginContext* ctx, struct io_pkt* io); +static bRC startRestoreFile(PluginContext* ctx, const char* cmd); +static bRC endRestoreFile(PluginContext* ctx); +static bRC createFile(PluginContext* ctx, struct restore_pkt* rp); +static bRC setFileAttributes(PluginContext* ctx, struct restore_pkt* rp); +static bRC checkFile(PluginContext* ctx, char* fname); +static bRC getAcl(PluginContext* ctx, acl_pkt* ap); +static bRC setAcl(PluginContext* ctx, acl_pkt* ap); +static bRC getXattr(PluginContext* ctx, xattr_pkt* xp); +static bRC setXattr(PluginContext* ctx, xattr_pkt* xp); + +static char* apply_rp_codes(PluginContext* ctx); +static bRC parse_plugin_definition(PluginContext* ctx, void* value); +static bRC plugin_has_all_arguments(PluginContext* ctx); /* Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; @@ -178,7 +171,7 @@ bRC unloadPlugin() { return bRC_OK; } /** * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bplugin_private_context* ctx) +static bRC newPlugin(PluginContext* ctx) { struct plugin_ctx* p_ctx = (struct plugin_ctx*)malloc(sizeof(struct plugin_ctx)); @@ -196,7 +189,7 @@ static bRC newPlugin(bplugin_private_context* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bplugin_private_context* ctx) +static bRC freePlugin(PluginContext* ctx) { struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; @@ -218,9 +211,7 @@ static bRC freePlugin(bplugin_private_context* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value) { return bRC_OK; } @@ -228,9 +219,7 @@ static bRC getPluginValue(bplugin_private_context* ctx, /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value) { return bRC_OK; } @@ -238,9 +227,7 @@ static bRC setPluginValue(bplugin_private_context* ctx, /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bplugin_private_context* ctx, - bEvent* event, - void* value) +static bRC handlePluginEvent(PluginContext* ctx, bEvent* event, void* value) { bRC retval = bRC_OK; struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; @@ -295,7 +282,7 @@ static bRC handlePluginEvent(bplugin_private_context* ctx, /** * Start the backup of a specific file */ -static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) +static bRC startBackupFile(PluginContext* ctx, struct save_pkt* sp) { time_t now; struct plugin_ctx* p_ctx; @@ -322,7 +309,7 @@ static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) /** * Done with backup of this file */ -static bRC endBackupFile(bplugin_private_context* ctx) +static bRC endBackupFile(PluginContext* ctx) { /* * We would return bRC_More if we wanted startBackupFile to be called again to @@ -334,7 +321,7 @@ static bRC endBackupFile(bplugin_private_context* ctx) /** * Bareos is calling us to do the actual I/O */ -static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) +static bRC pluginIO(PluginContext* ctx, struct io_pkt* io) { struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -438,7 +425,7 @@ static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) * Bareos is notifying us that a plugin name string was found, and * passing us the plugin command, so we can prepare for a restore. */ -static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) +static bRC startRestoreFile(PluginContext* ctx, const char* cmd) { if (plugin_has_all_arguments(ctx) != bRC_OK) { return bRC_Error; } @@ -449,7 +436,7 @@ static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) * Bareos is notifying us that the plugin data has terminated, so * the restore for this particular file is done. */ -static bRC endRestoreFile(bplugin_private_context* ctx) +static bRC endRestoreFile(PluginContext* ctx) { struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -466,7 +453,7 @@ static bRC endRestoreFile(bplugin_private_context* ctx) * CF_EXTRACT -- extract the file (i.e.call i/o routines) * CF_CREATED -- created, but no content to extract (typically directories) */ -static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) +static bRC createFile(PluginContext* ctx, struct restore_pkt* rp) { if (strlen(rp->where) > 512) { printf( @@ -482,8 +469,7 @@ static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) return bRC_OK; } -static bRC setFileAttributes(bplugin_private_context* ctx, - struct restore_pkt* rp) +static bRC setFileAttributes(PluginContext* ctx, struct restore_pkt* rp) { return bRC_OK; } @@ -491,24 +477,15 @@ static bRC setFileAttributes(bplugin_private_context* ctx, /** * When using Incremental dump, all previous dumps are necessary */ -static bRC checkFile(bplugin_private_context* ctx, char* fname) -{ - return bRC_OK; -} +static bRC checkFile(PluginContext* ctx, char* fname) { return bRC_OK; } -static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap) { return bRC_OK; } +static bRC getAcl(PluginContext* ctx, acl_pkt* ap) { return bRC_OK; } -static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap) { return bRC_OK; } +static bRC setAcl(PluginContext* ctx, acl_pkt* ap) { return bRC_OK; } -static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp) -{ - return bRC_OK; -} +static bRC getXattr(PluginContext* ctx, xattr_pkt* xp) { return bRC_OK; } -static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp) -{ - return bRC_OK; -} +static bRC setXattr(PluginContext* ctx, xattr_pkt* xp) { return bRC_OK; } /** * Apply codes in writer command: @@ -526,7 +503,7 @@ static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp) * * Inspired by edit_job_codes in lib/util.c */ -static char* apply_rp_codes(bplugin_private_context* ctx) +static char* apply_rp_codes(PluginContext* ctx) { char add[10]; const char* str; @@ -646,7 +623,7 @@ static inline void SetString(char** destination, char* value) * * bpipe:file=:read=:write= */ -static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value) +static bRC parse_plugin_definition(PluginContext* ctx, void* value) { int i, cnt; char *plugin_definition, *bp, *argument, *argument_value; @@ -874,7 +851,7 @@ static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value) return bRC_Error; } -static bRC plugin_has_all_arguments(bplugin_private_context* ctx) +static bRC plugin_has_all_arguments(PluginContext* ctx) { bRC retval = bRC_OK; plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; diff --git a/core/src/plugins/filed/cephfs/cephfs-fd.cc b/core/src/plugins/filed/cephfs/cephfs-fd.cc index 2a1442ed57a..1225669b97c 100644 --- a/core/src/plugins/filed/cephfs/cephfs-fd.cc +++ b/core/src/plugins/filed/cephfs/cephfs-fd.cc @@ -50,35 +50,28 @@ static const int debuglevel = 150; /** * Forward referenced functions */ -static bRC newPlugin(bplugin_private_context* ctx); -static bRC freePlugin(bplugin_private_context* ctx); -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC handlePluginEvent(bplugin_private_context* ctx, - bEvent* event, - void* value); -static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp); -static bRC endBackupFile(bplugin_private_context* ctx); -static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io); -static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd); -static bRC endRestoreFile(bplugin_private_context* ctx); -static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp); -static bRC setFileAttributes(bplugin_private_context* ctx, - struct restore_pkt* rp); -static bRC checkFile(bplugin_private_context* ctx, char* fname); -static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap); -static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap); -static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp); -static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp); - -static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value); -static bRC setup_backup(bplugin_private_context* ctx, void* value); -static bRC setup_restore(bplugin_private_context* ctx, void* value); -static bRC end_restore_job(bplugin_private_context* ctx, void* value); +static bRC newPlugin(PluginContext* ctx); +static bRC freePlugin(PluginContext* ctx); +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC handlePluginEvent(PluginContext* ctx, bEvent* event, void* value); +static bRC startBackupFile(PluginContext* ctx, struct save_pkt* sp); +static bRC endBackupFile(PluginContext* ctx); +static bRC pluginIO(PluginContext* ctx, struct io_pkt* io); +static bRC startRestoreFile(PluginContext* ctx, const char* cmd); +static bRC endRestoreFile(PluginContext* ctx); +static bRC createFile(PluginContext* ctx, struct restore_pkt* rp); +static bRC setFileAttributes(PluginContext* ctx, struct restore_pkt* rp); +static bRC checkFile(PluginContext* ctx, char* fname); +static bRC getAcl(PluginContext* ctx, acl_pkt* ap); +static bRC setAcl(PluginContext* ctx, acl_pkt* ap); +static bRC getXattr(PluginContext* ctx, xattr_pkt* xp); +static bRC setXattr(PluginContext* ctx, xattr_pkt* xp); + +static bRC parse_plugin_definition(PluginContext* ctx, void* value); +static bRC setup_backup(PluginContext* ctx, void* value); +static bRC setup_restore(PluginContext* ctx, void* value); +static bRC end_restore_job(PluginContext* ctx, void* value); /** * Pointers to Bareos functions @@ -217,7 +210,7 @@ bRC unloadPlugin() { return bRC_OK; } * * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bplugin_private_context* ctx) +static bRC newPlugin(PluginContext* ctx) { plugin_ctx* p_ctx; @@ -268,7 +261,7 @@ static bRC newPlugin(bplugin_private_context* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bplugin_private_context* ctx) +static bRC freePlugin(PluginContext* ctx) { plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -314,9 +307,7 @@ static bRC freePlugin(bplugin_private_context* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value) { return bRC_OK; } @@ -324,9 +315,7 @@ static bRC getPluginValue(bplugin_private_context* ctx, /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value) { return bRC_OK; } @@ -334,9 +323,7 @@ static bRC setPluginValue(bplugin_private_context* ctx, /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bplugin_private_context* ctx, - bEvent* event, - void* value) +static bRC handlePluginEvent(PluginContext* ctx, bEvent* event, void* value) { bRC retval; plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -395,7 +382,7 @@ static bRC handlePluginEvent(bplugin_private_context* ctx, /** * Get the next file to backup. */ -static bRC get_next_file_to_backup(bplugin_private_context* ctx) +static bRC get_next_file_to_backup(PluginContext* ctx) { int status; struct save_pkt sp; @@ -610,7 +597,7 @@ static bRC get_next_file_to_backup(bplugin_private_context* ctx) /** * Start the backup of a specific file */ -static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) +static bRC startBackupFile(PluginContext* ctx, struct save_pkt* sp) { int status; plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -789,7 +776,7 @@ static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) /** * Done with backup of this file */ -static bRC endBackupFile(bplugin_private_context* ctx) +static bRC endBackupFile(PluginContext* ctx) { plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -865,7 +852,7 @@ static inline void SetString(char** destination, char* value) * * cephfs:conffile=:basedir=: */ -static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value) +static bRC parse_plugin_definition(PluginContext* ctx, void* value) { int i; bool keep_existing; @@ -1007,7 +994,7 @@ static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value) /** * Open a CEPHFS mountpoint. */ -static bRC connect_to_cephfs(bplugin_private_context* ctx) +static bRC connect_to_cephfs(PluginContext* ctx) { int status; plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -1058,7 +1045,7 @@ static bRC connect_to_cephfs(bplugin_private_context* ctx) /** * Generic setup for performing a backup. */ -static bRC setup_backup(bplugin_private_context* ctx, void* value) +static bRC setup_backup(PluginContext* ctx, void* value) { plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -1093,7 +1080,7 @@ static bRC setup_backup(bplugin_private_context* ctx, void* value) /** * Generic setup for performing a restore. */ -static bRC setup_restore(bplugin_private_context* ctx, void* value) +static bRC setup_restore(PluginContext* ctx, void* value) { plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -1114,7 +1101,7 @@ static bRC setup_restore(bplugin_private_context* ctx, void* value) /** * Bareos is calling us to do the actual I/O */ -static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) +static bRC pluginIO(PluginContext* ctx, struct io_pkt* io) { plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -1204,7 +1191,7 @@ static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) /** * See if we need to do any postprocessing after the restore. */ -static bRC end_restore_job(bplugin_private_context* ctx, void* value) +static bRC end_restore_job(PluginContext* ctx, void* value) { bRC retval = bRC_OK; plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -1222,7 +1209,7 @@ static bRC end_restore_job(bplugin_private_context* ctx, void* value) * Bareos is notifying us that a plugin name string was found, * and passing us the plugin command, so we can prepare for a restore. */ -static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) +static bRC startRestoreFile(PluginContext* ctx, const char* cmd) { return bRC_OK; } @@ -1231,7 +1218,7 @@ static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) * Bareos is notifying us that the plugin data has terminated, * so the restore for this particular file is done. */ -static bRC endRestoreFile(bplugin_private_context* ctx) { return bRC_OK; } +static bRC endRestoreFile(PluginContext* ctx) { return bRC_OK; } /** * Create a parent directory using the cephfs API. @@ -1316,7 +1303,7 @@ static inline bool CephfsMakedirs(plugin_ctx* p_ctx, const char* directory) * CF_EXTRACT -- extract the file (i.e.call i/o routines) * CF_CREATED -- created, but no content to extract (typically directories) */ -static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) +static bRC createFile(PluginContext* ctx, struct restore_pkt* rp) { int status; bool exists = false; @@ -1499,8 +1486,7 @@ static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) return bRC_OK; } -static bRC setFileAttributes(bplugin_private_context* ctx, - struct restore_pkt* rp) +static bRC setFileAttributes(PluginContext* ctx, struct restore_pkt* rp) { int status; struct utimbuf times; @@ -1554,7 +1540,7 @@ static bRC setFileAttributes(bplugin_private_context* ctx, /** * When using Incremental dump, all previous dumps are necessary */ -static bRC checkFile(bplugin_private_context* ctx, char* fname) +static bRC checkFile(PluginContext* ctx, char* fname) { plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -1608,7 +1594,7 @@ static inline uint32_t serialize_acl_stream(PoolMem* buf, return offset + content_length; } -static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap) +static bRC getAcl(PluginContext* ctx, acl_pkt* ap) { bool skip_xattr, abort_retrieval; int current_size; @@ -1695,7 +1681,7 @@ static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap) return bRC_OK; } -static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap) +static bRC setAcl(PluginContext* ctx, acl_pkt* ap) { int status; unser_declare; @@ -1741,7 +1727,7 @@ static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap) return bRC_OK; } -static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp) +static bRC getXattr(PluginContext* ctx, xattr_pkt* xp) { char* bp; bool skip_xattr; @@ -1908,7 +1894,7 @@ static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp) return bRC_OK; } -static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp) +static bRC setXattr(PluginContext* ctx, xattr_pkt* xp) { int status; plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; diff --git a/core/src/plugins/filed/example/example-plugin-fd.cc b/core/src/plugins/filed/example/example-plugin-fd.cc index 816cbe64550..6f1cc34e6bc 100644 --- a/core/src/plugins/filed/example/example-plugin-fd.cc +++ b/core/src/plugins/filed/example/example-plugin-fd.cc @@ -26,30 +26,23 @@ namespace filedaemon { /* Forward referenced functions */ -static bRC newPlugin(bplugin_private_context* ctx); -static bRC freePlugin(bplugin_private_context* ctx); -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC handlePluginEvent(bplugin_private_context* ctx, - bEvent* event, - void* value); -static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp); -static bRC endBackupFile(bplugin_private_context* ctx); -static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io); -static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd); -static bRC endRestoreFile(bplugin_private_context* ctx); -static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp); -static bRC setFileAttributes(bplugin_private_context* ctx, - struct restore_pkt* rp); -static bRC checkFile(bplugin_private_context* ctx, char* fname); -static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap); -static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap); -static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp); -static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp); +static bRC newPlugin(PluginContext* ctx); +static bRC freePlugin(PluginContext* ctx); +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC handlePluginEvent(PluginContext* ctx, bEvent* event, void* value); +static bRC startBackupFile(PluginContext* ctx, struct save_pkt* sp); +static bRC endBackupFile(PluginContext* ctx); +static bRC pluginIO(PluginContext* ctx, struct io_pkt* io); +static bRC startRestoreFile(PluginContext* ctx, const char* cmd); +static bRC endRestoreFile(PluginContext* ctx); +static bRC createFile(PluginContext* ctx, struct restore_pkt* rp); +static bRC setFileAttributes(PluginContext* ctx, struct restore_pkt* rp); +static bRC checkFile(PluginContext* ctx, char* fname); +static bRC getAcl(PluginContext* ctx, acl_pkt* ap); +static bRC setAcl(PluginContext* ctx, acl_pkt* ap); +static bRC getXattr(PluginContext* ctx, xattr_pkt* xp); +static bRC setXattr(PluginContext* ctx, xattr_pkt* xp); /* Pointers to Bareos functions */ @@ -117,7 +110,7 @@ bRC unloadPlugin() * plugin instance must be thread safe and keep its own * local data. */ -static bRC newPlugin(bplugin_private_context* ctx) +static bRC newPlugin(PluginContext* ctx) { int JobId = 0; bareos_core_functions->getBareosValue(ctx, bVarJobId, (void*)&JobId); @@ -133,7 +126,7 @@ static bRC newPlugin(bplugin_private_context* ctx) * Release everything concerning a particular instance of a * plugin. Normally called when the Job terminates. */ -static bRC freePlugin(bplugin_private_context* ctx) +static bRC freePlugin(PluginContext* ctx) { int JobId = 0; bareos_core_functions->getBareosValue(ctx, bVarJobId, (void*)&JobId); @@ -145,9 +138,7 @@ static bRC freePlugin(bplugin_private_context* ctx) * Called by core code to get a variable from the plugin. * Not currently used. */ -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value) { // printf("plugin: getPluginValue var=%d\n", var); return bRC_OK; @@ -157,9 +148,7 @@ static bRC getPluginValue(bplugin_private_context* ctx, * Called by core code to set a plugin variable. * Not currently used. */ -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value) { // printf("plugin: setPluginValue var=%d\n", var); return bRC_OK; @@ -170,9 +159,7 @@ static bRC setPluginValue(bplugin_private_context* ctx, * plugin might want to know. The value depends on the * event. */ -static bRC handlePluginEvent(bplugin_private_context* ctx, - bEvent* event, - void* value) +static bRC handlePluginEvent(PluginContext* ctx, bEvent* event, void* value) { char* name; @@ -229,7 +216,7 @@ static bRC handlePluginEvent(bplugin_private_context* ctx, * The plugin can create "Virtual" files by giving them a * name that is not normally found on the file system. */ -static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) +static bRC startBackupFile(PluginContext* ctx, struct save_pkt* sp) { return bRC_OK; } @@ -237,13 +224,13 @@ static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) /* * Done backing up a file. */ -static bRC endBackupFile(bplugin_private_context* ctx) { return bRC_OK; } +static bRC endBackupFile(PluginContext* ctx) { return bRC_OK; } /* * Do actual I/O. Bareos calls this after startBackupFile * or after startRestoreFile to do the actual file input or output. */ -static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) +static bRC pluginIO(PluginContext* ctx, struct io_pkt* io) { io->status = 0; io->io_errno = 0; @@ -264,12 +251,12 @@ static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) return bRC_OK; } -static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) +static bRC startRestoreFile(PluginContext* ctx, const char* cmd) { return bRC_OK; } -static bRC endRestoreFile(bplugin_private_context* ctx) { return bRC_OK; } +static bRC endRestoreFile(PluginContext* ctx) { return bRC_OK; } /* * Called here to give the plugin the information needed to @@ -278,7 +265,7 @@ static bRC endRestoreFile(bplugin_private_context* ctx) { return bRC_OK; } * This data is what is needed to create the file, but does * not contain actual file data. */ -static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) +static bRC createFile(PluginContext* ctx, struct restore_pkt* rp) { return bRC_OK; } @@ -287,32 +274,22 @@ static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) * Called after the file has been restored. This can be used to set directory * permissions, ... */ -static bRC setFileAttributes(bplugin_private_context* ctx, - struct restore_pkt* rp) +static bRC setFileAttributes(PluginContext* ctx, struct restore_pkt* rp) { return bRC_OK; } -static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap) { return bRC_OK; } +static bRC getAcl(PluginContext* ctx, acl_pkt* ap) { return bRC_OK; } -static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap) { return bRC_OK; } +static bRC setAcl(PluginContext* ctx, acl_pkt* ap) { return bRC_OK; } -static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp) -{ - return bRC_OK; -} +static bRC getXattr(PluginContext* ctx, xattr_pkt* xp) { return bRC_OK; } -static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp) -{ - return bRC_OK; -} +static bRC setXattr(PluginContext* ctx, xattr_pkt* xp) { return bRC_OK; } /* * When using Incremental dump, all previous dumps are necessary */ -static bRC checkFile(bplugin_private_context* ctx, char* fname) -{ - return bRC_OK; -} +static bRC checkFile(PluginContext* ctx, char* fname) { return bRC_OK; } } /* namespace filedaemon */ diff --git a/core/src/plugins/filed/gfapi/gfapi-fd.cc b/core/src/plugins/filed/gfapi/gfapi-fd.cc index b935917b0c0..d5a713907d0 100644 --- a/core/src/plugins/filed/gfapi/gfapi-fd.cc +++ b/core/src/plugins/filed/gfapi/gfapi-fd.cc @@ -65,35 +65,28 @@ static const int debuglevel = 150; /** * Forward referenced functions */ -static bRC newPlugin(bplugin_private_context* ctx); -static bRC freePlugin(bplugin_private_context* ctx); -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC handlePluginEvent(bplugin_private_context* ctx, - bEvent* event, - void* value); -static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp); -static bRC endBackupFile(bplugin_private_context* ctx); -static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io); -static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd); -static bRC endRestoreFile(bplugin_private_context* ctx); -static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp); -static bRC setFileAttributes(bplugin_private_context* ctx, - struct restore_pkt* rp); -static bRC checkFile(bplugin_private_context* ctx, char* fname); -static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap); -static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap); -static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp); -static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp); - -static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value); -static bRC end_restore_job(bplugin_private_context* ctx, void* value); -static bRC setup_backup(bplugin_private_context* ctx, void* value); -static bRC setup_restore(bplugin_private_context* ctx, void* value); +static bRC newPlugin(PluginContext* ctx); +static bRC freePlugin(PluginContext* ctx); +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC handlePluginEvent(PluginContext* ctx, bEvent* event, void* value); +static bRC startBackupFile(PluginContext* ctx, struct save_pkt* sp); +static bRC endBackupFile(PluginContext* ctx); +static bRC pluginIO(PluginContext* ctx, struct io_pkt* io); +static bRC startRestoreFile(PluginContext* ctx, const char* cmd); +static bRC endRestoreFile(PluginContext* ctx); +static bRC createFile(PluginContext* ctx, struct restore_pkt* rp); +static bRC setFileAttributes(PluginContext* ctx, struct restore_pkt* rp); +static bRC checkFile(PluginContext* ctx, char* fname); +static bRC getAcl(PluginContext* ctx, acl_pkt* ap); +static bRC setAcl(PluginContext* ctx, acl_pkt* ap); +static bRC getXattr(PluginContext* ctx, xattr_pkt* xp); +static bRC setXattr(PluginContext* ctx, xattr_pkt* xp); + +static bRC parse_plugin_definition(PluginContext* ctx, void* value); +static bRC end_restore_job(PluginContext* ctx, void* value); +static bRC setup_backup(PluginContext* ctx, void* value); +static bRC setup_restore(PluginContext* ctx, void* value); /** * Pointers to Bareos functions @@ -351,7 +344,7 @@ bRC unloadPlugin() { return bRC_OK; } * * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bplugin_private_context* ctx) +static bRC newPlugin(PluginContext* ctx) { plugin_ctx* p_ctx; @@ -391,7 +384,7 @@ static bRC newPlugin(bplugin_private_context* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bplugin_private_context* ctx) +static bRC freePlugin(PluginContext* ctx) { plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -444,9 +437,7 @@ static bRC freePlugin(bplugin_private_context* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value) { return bRC_OK; } @@ -454,9 +445,7 @@ static bRC getPluginValue(bplugin_private_context* ctx, /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value) { return bRC_OK; } @@ -464,9 +453,7 @@ static bRC setPluginValue(bplugin_private_context* ctx, /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bplugin_private_context* ctx, - bEvent* event, - void* value) +static bRC handlePluginEvent(PluginContext* ctx, bEvent* event, void* value) { bRC retval; plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -525,7 +512,7 @@ static bRC handlePluginEvent(bplugin_private_context* ctx, /** * Get the next file to backup. */ -static bRC get_next_file_to_backup(bplugin_private_context* ctx) +static bRC get_next_file_to_backup(PluginContext* ctx) { int status; struct save_pkt sp; @@ -849,7 +836,7 @@ static bRC get_next_file_to_backup(bplugin_private_context* ctx) /** * Start the backup of a specific file */ -static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) +static bRC startBackupFile(PluginContext* ctx, struct save_pkt* sp) { int status; plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -1038,7 +1025,7 @@ static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) /** * Done with backup of this file */ -static bRC endBackupFile(bplugin_private_context* ctx) +static bRC endBackupFile(PluginContext* ctx) { plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -1111,7 +1098,7 @@ static inline void SetString(char** destination, char* value) * * gfapi:volume=gluster[+transport]\\://[server[:port]]/volname[/dir][?socket=...] */ -static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value) +static bRC parse_plugin_definition(PluginContext* ctx, void* value) { int i; bool keep_existing; @@ -1517,7 +1504,7 @@ static inline bool parse_gfapi_devicename(char* devicename, /** * Open a volume using GFAPI. */ -static bRC connect_to_gluster(bplugin_private_context* ctx, bool is_backup) +static bRC connect_to_gluster(PluginContext* ctx, bool is_backup) { int status; plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -1576,7 +1563,7 @@ static bRC connect_to_gluster(bplugin_private_context* ctx, bool is_backup) /** * Generic setup for performing a backup. */ -static bRC setup_backup(bplugin_private_context* ctx, void* value) +static bRC setup_backup(PluginContext* ctx, void* value) { bRC retval = bRC_Error; plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -1717,7 +1704,7 @@ static bRC setup_backup(bplugin_private_context* ctx, void* value) /** * Generic setup for performing a restore. */ -static bRC setup_restore(bplugin_private_context* ctx, void* value) +static bRC setup_restore(PluginContext* ctx, void* value) { plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -1738,7 +1725,7 @@ static bRC setup_restore(bplugin_private_context* ctx, void* value) /** * Bareos is calling us to do the actual I/O */ -static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) +static bRC pluginIO(PluginContext* ctx, struct io_pkt* io) { plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -1832,7 +1819,7 @@ static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) /** * See if we need to do any postprocessing after the restore. */ -static bRC end_restore_job(bplugin_private_context* ctx, void* value) +static bRC end_restore_job(PluginContext* ctx, void* value) { bRC retval = bRC_OK; plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -1850,7 +1837,7 @@ static bRC end_restore_job(bplugin_private_context* ctx, void* value) * Bareos is notifying us that a plugin name string was found, * and passing us the plugin command, so we can prepare for a restore. */ -static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) +static bRC startRestoreFile(PluginContext* ctx, const char* cmd) { return bRC_OK; } @@ -1859,7 +1846,7 @@ static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) * Bareos is notifying us that the plugin data has terminated, * so the restore for this particular file is done. */ -static bRC endRestoreFile(bplugin_private_context* ctx) { return bRC_OK; } +static bRC endRestoreFile(PluginContext* ctx) { return bRC_OK; } /** * This is called during restore to create the file (if necessary) We must @@ -1870,7 +1857,7 @@ static bRC endRestoreFile(bplugin_private_context* ctx) { return bRC_OK; } * CF_EXTRACT -- extract the file (i.e.call i/o routines) * CF_CREATED -- created, but no content to extract (typically directories) */ -static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) +static bRC createFile(PluginContext* ctx, struct restore_pkt* rp) { int status; bool exists = false; @@ -2036,8 +2023,7 @@ static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) return bRC_OK; } -static bRC setFileAttributes(bplugin_private_context* ctx, - struct restore_pkt* rp) +static bRC setFileAttributes(PluginContext* ctx, struct restore_pkt* rp) { int status; struct timespec times[2]; @@ -2093,7 +2079,7 @@ static bRC setFileAttributes(bplugin_private_context* ctx, /** * When using Incremental dump, all previous dumps are necessary */ -static bRC checkFile(bplugin_private_context* ctx, char* fname) +static bRC checkFile(PluginContext* ctx, char* fname) { plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -2147,7 +2133,7 @@ static inline uint32_t serialize_acl_stream(PoolMem* buf, return offset + content_length; } -static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap) +static bRC getAcl(PluginContext* ctx, acl_pkt* ap) { bool skip_xattr, abort_retrieval; int current_size; @@ -2234,7 +2220,7 @@ static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap) return bRC_OK; } -static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap) +static bRC setAcl(PluginContext* ctx, acl_pkt* ap) { int status; unser_declare; @@ -2280,7 +2266,7 @@ static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap) return bRC_OK; } -static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp) +static bRC getXattr(PluginContext* ctx, xattr_pkt* xp) { char* bp; bool skip_xattr; @@ -2448,7 +2434,7 @@ static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp) return bRC_OK; } -static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp) +static bRC setXattr(PluginContext* ctx, xattr_pkt* xp) { int status; plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 43325f32632..1687933441f 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -58,84 +58,79 @@ static const int debuglevel = 150; /* "load>:..." */ /* Forward referenced functions */ -/* static bRC newPlugin(bplugin_private_context* bareos_plugin_ctx); */ -/* static bRC freePlugin(bplugin_private_context* bareos_plugin_ctx); */ -/* static bRC getPluginValue(bplugin_private_context* bareos_plugin_ctx, */ +/* static bRC newPlugin(PluginContext* bareos_plugin_ctx); */ +/* static bRC freePlugin(PluginContext* bareos_plugin_ctx); */ +/* static bRC getPluginValue(PluginContext* bareos_plugin_ctx, */ /* pVariable var, */ /* void* value); */ -/* static bRC setPluginValue(bplugin_private_context* bareos_plugin_ctx, */ +/* static bRC setPluginValue(PluginContext* bareos_plugin_ctx, */ /* pVariable var, */ /* void* value); */ -/* static bRC handlePluginEvent(bplugin_private_context* bareos_plugin_ctx, */ +/* static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, */ /* bEvent* event, */ /* void* value); */ -/* static bRC startBackupFile(bplugin_private_context* bareos_plugin_ctx, struct +/* static bRC startBackupFile(PluginContext* bareos_plugin_ctx, struct * save_pkt* sp); */ -/* static bRC endBackupFile(bplugin_private_context* bareos_plugin_ctx); */ -/* static bRC pluginIO(bplugin_private_context* bareos_plugin_ctx, struct +/* static bRC endBackupFile(PluginContext* bareos_plugin_ctx); */ +/* static bRC pluginIO(PluginContext* bareos_plugin_ctx, struct * io_pkt* io); */ -/* static bRC startRestoreFile(bplugin_private_context* bareos_plugin_ctx, const +/* static bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const * char* cmd); */ -/* static bRC endRestoreFile(bplugin_private_context* bareos_plugin_ctx); */ -/* static bRC createFile(bplugin_private_context* bareos_plugin_ctx, struct +/* static bRC endRestoreFile(PluginContext* bareos_plugin_ctx); */ +/* static bRC createFile(PluginContext* bareos_plugin_ctx, struct * restore_pkt* rp); */ -/* static bRC setFileAttributes(bplugin_private_context* bareos_plugin_ctx, */ +/* static bRC setFileAttributes(PluginContext* bareos_plugin_ctx, */ /* struct restore_pkt* rp); */ -/* static bRC checkFile(bplugin_private_context* bareos_plugin_ctx, char* +/* static bRC checkFile(PluginContext* bareos_plugin_ctx, char* * fname); */ -/* static bRC getAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap); +/* static bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); */ -/* static bRC setAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap); +/* static bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); */ -/* static bRC getXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* +/* static bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* * xp); */ -/* static bRC setXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* +/* static bRC setXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* * xp); */ -/* static bRC parse_plugin_definition(bplugin_private_context* +/* static bRC parse_plugin_definition(PluginContext* * bareos_plugin_ctx, */ /* void* value, */ /* PoolMem& plugin_options); */ -static void PyErrorHandler(bplugin_private_context* bareos_plugin_ctx, - int msgtype); -static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, - void* value); -static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, +static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); +static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); +static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, void* value); -static bRC PyGetPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); -static bRC PySetPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); -static bRC PyHandlePluginEvent(bplugin_private_context* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, bEvent* event, void* value); -static bRC PyStartBackupFile(bplugin_private_context* bareos_plugin_ctx, +static bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); -static bRC PyEndBackupFile(bplugin_private_context* bareos_plugin_ctx); -static bRC PyPluginIO(bplugin_private_context* bareos_plugin_ctx, - struct io_pkt* io); -static bRC PyStartRestoreFile(bplugin_private_context* bareos_plugin_ctx, +static bRC PyEndBackupFile(PluginContext* bareos_plugin_ctx); +static bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); +static bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); -static bRC PyEndRestoreFile(bplugin_private_context* bareos_plugin_ctx); -static bRC PyCreateFile(bplugin_private_context* bareos_plugin_ctx, +static bRC PyEndRestoreFile(PluginContext* bareos_plugin_ctx); +static bRC PyCreateFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); -static bRC PySetFileAttributes(bplugin_private_context* bareos_plugin_ctx, +static bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); -static bRC PyCheckFile(bplugin_private_context* bareos_plugin_ctx, char* fname); -static bRC PyGetAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap); -static bRC PySetAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap); -static bRC PyGetXattr(bplugin_private_context* bareos_plugin_ctx, - xattr_pkt* xp); -static bRC PySetXattr(bplugin_private_context* bareos_plugin_ctx, - xattr_pkt* xp); -static bRC PyRestoreObjectData(bplugin_private_context* bareos_plugin_ctx, +static bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname); +static bRC PyGetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC PySetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, struct restore_object_pkt* rop); -static bRC PyHandleBackupFile(bplugin_private_context* bareos_plugin_ctx, +static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); /* Pointers to Bareos functions */ @@ -281,11 +276,11 @@ static void PyErrorHandler() */ /* 0); */ -/* // Extract capsule bareosfd.bplugin_private_context */ +/* // Extract capsule bareosfd.PluginContext */ /* void* ctx_from_bareosfd_module = - * PyCapsule_Import("bareosfd.bplugin_private_context", 0); */ + * PyCapsule_Import("bareosfd.PluginContext", 0); */ /* if (!ctx_from_bareosfd_module) { */ -/* printf("importing bareosfd.bplugin_private_context failed \n"); */ +/* printf("importing bareosfd.PluginContext failed \n"); */ /* } */ /* // Extract capsules bareosfd.BareosCoreFunctions */ @@ -300,7 +295,7 @@ static void PyErrorHandler() /* } */ -/* *(void**)ctx_from_bareosfd_module = &bareos_plugin_context; */ +/* *(void**)ctx_from_bareosfd_module = &bareos_PluginContext; */ /* *(void**)bareos_core_functions_from_bareosfd_module = * &bareos_core_functions; */ @@ -354,7 +349,7 @@ static void PyErrorHandler() * module path and the module to load. We also load the dictionary used * for looking up the Python methods. */ -static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, void* value) +static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -397,10 +392,10 @@ static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, void* value) plugin_priv_ctx->pyModuleFunctionsDict = PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ - /* Encode the bplugin_private_context so a Python method can pass it in on + /* Encode the PluginContext so a Python method can pass it in on * calling back.*/ - /* plugin_priv_ctx->py_bplugin_private_context = - * PyCreatebplugin_private_context(bareos_plugin_ctx); */ + /* plugin_priv_ctx->py_PluginContext = + * PyCreatePluginContext(bareos_plugin_ctx); */ StorePluginContextInPythonModule(bareos_plugin_ctx); @@ -414,7 +409,7 @@ static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, void* value) if (!pPluginDefinition) { goto bail_out; } pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); - /* pFunc, plugin_priv_ctx->py_bplugin_private_context, pPluginDefinition, + /* pFunc, plugin_priv_ctx->py_PluginContext, pPluginDefinition, * NULL); */ Py_DECREF(pPluginDefinition); @@ -452,7 +447,7 @@ static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, void* value) * restore overrides can be passed in before the actual plugin options are * restored as part of the restore stream handling. */ -static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, +static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; @@ -496,21 +491,21 @@ static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, return retval; } -static bRC PyGetPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PySetPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PyHandlePluginEvent(bplugin_private_context* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, bEvent* event, void* value) { @@ -784,7 +779,7 @@ static inline bool PySavePacketToNative( * The plugin can create "Virtual" files by giving them a * name that is not normally found on the file system. */ -static bRC PyStartBackupFile(bplugin_private_context* bareos_plugin_ctx, +static bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp) { bRC retval = bRC_Error; @@ -837,7 +832,7 @@ static bRC PyStartBackupFile(bplugin_private_context* bareos_plugin_ctx, * If the plugin wishes to create another file and back it up, * then it must return bRC_More (not yet implemented). */ -static bRC PyEndBackupFile(bplugin_private_context* bareos_plugin_ctx) +static bRC PyEndBackupFile(PluginContext* bareos_plugin_ctx) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -946,8 +941,7 @@ static inline bool PyIoPacketToNative(PyIoPacket* pIoPkt, struct io_pkt* io) * or after startRestoreFile to do the actual file * input or output. */ -static bRC PyPluginIO(bplugin_private_context* bareos_plugin_ctx, - struct io_pkt* io) +static bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -999,8 +993,7 @@ static bRC PyPluginIO(bplugin_private_context* bareos_plugin_ctx, * Called when the first record is read from the Volume that was previously * written by the command plugin. */ -static bRC PyStartRestoreFile(bplugin_private_context* bareos_plugin_ctx, - const char* cmd) +static bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -1043,7 +1036,7 @@ static bRC PyStartRestoreFile(bplugin_private_context* bareos_plugin_ctx, /** * Called when a command plugin is done restoring a file. */ -static bRC PyEndRestoreFile(bplugin_private_context* bareos_plugin_ctx) +static bRC PyEndRestoreFile(PluginContext* bareos_plugin_ctx) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -1124,7 +1117,7 @@ static inline void PyRestorePacketToNative(PyRestorePacket* pRestorePacket, * CF_EXTRACT -- extract the file (i.e.call i/o routines) * CF_CREATED -- created, but no content to extract (typically directories) */ -static bRC PyCreateFile(bplugin_private_context* bareos_plugin_ctx, +static bRC PyCreateFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) { bRC retval = bRC_Error; @@ -1170,7 +1163,7 @@ static bRC PyCreateFile(bplugin_private_context* bareos_plugin_ctx, return retval; } -static bRC PySetFileAttributes(bplugin_private_context* bareos_plugin_ctx, +static bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) { bRC retval = bRC_Error; @@ -1214,7 +1207,7 @@ static bRC PySetFileAttributes(bplugin_private_context* bareos_plugin_ctx, return retval; } -static bRC PyCheckFile(bplugin_private_context* bareos_plugin_ctx, char* fname) +static bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -1294,7 +1287,7 @@ static inline bool PyAclPacketToNative(PyAclPacket* pAclPacket, return true; } -static bRC PyGetAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap) +static bRC PyGetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -1342,7 +1335,7 @@ static bRC PyGetAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap) return retval; } -static bRC PySetAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap) +static bRC PySetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -1448,7 +1441,7 @@ static inline bool PyXattrPacketToNative(PyXattrPacket* pXattrPacket, return true; } -static bRC PyGetXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* xp) +static bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -1496,7 +1489,7 @@ static bRC PyGetXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* xp) return retval; } -static bRC PySetXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* xp) +static bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -1561,7 +1554,7 @@ static inline PyRestoreObject* NativeToPyRestoreObject( return pRestoreObject; } -static bRC PyRestoreObjectData(bplugin_private_context* bareos_plugin_ctx, +static bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, struct restore_object_pkt* rop) { bRC retval = bRC_Error; @@ -1605,7 +1598,7 @@ static bRC PyRestoreObjectData(bplugin_private_context* bareos_plugin_ctx, return retval; } -static bRC PyHandleBackupFile(bplugin_private_context* bareos_plugin_ctx, +static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp) { bRC retval = bRC_Error; @@ -1661,8 +1654,7 @@ static bRC PyHandleBackupFile(bplugin_private_context* bareos_plugin_ctx, static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } @@ -1733,8 +1725,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject* pyValue; @@ -1783,8 +1774,7 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); /* plugin_private_context* ppc = */ /* (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; */ @@ -1807,8 +1797,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; @@ -1829,8 +1818,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -1871,8 +1859,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -1911,8 +1898,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } @@ -1939,8 +1925,7 @@ static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) { char* file = NULL; bRC retval = bRC_Error; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|z:BareosAddExclude", &file)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() @@ -1961,8 +1946,7 @@ static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) { char* file = NULL; bRC retval = bRC_Error; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|z:BareosAddInclude", &file)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() @@ -1983,8 +1967,7 @@ static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) { char* opts = NULL; bRC retval = bRC_Error; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|z:BareosAddOptions", &opts)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() @@ -2006,8 +1989,7 @@ static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) int type; char* item = NULL; bRC retval = bRC_Error; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|zi:BareosAddRegex", &item, &type)) { goto bail_out; } @@ -2030,8 +2012,7 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) int type; char* item = NULL; bRC retval = bRC_Error; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|zi:BareosAddWild", &item, &type)) { goto bail_out; @@ -2052,8 +2033,7 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) { - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewOptions")) { goto bail_out; } @@ -2071,8 +2051,7 @@ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) { - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewInclude")) { goto bail_out; } @@ -2090,8 +2069,7 @@ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) { - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewPreInclude")) { goto bail_out; } @@ -2110,8 +2088,7 @@ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) */ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) { - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); struct save_pkt sp; bRC retval = bRC_Error; @@ -2165,8 +2142,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) */ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) { - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); struct save_pkt sp; bRC retval = bRC_Error; PySavePacket* pSavePkt; @@ -2209,8 +2185,7 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) { bool all; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; @@ -2235,8 +2210,7 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) { bool all; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 2ff03799231..d09ada7b68f 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -61,75 +61,67 @@ static const int debuglevel = 150; "load>:..." /* Forward referenced functions */ -static bRC newPlugin(bplugin_private_context* bareos_plugin_ctx); -static bRC freePlugin(bplugin_private_context* bareos_plugin_ctx); -static bRC getPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC newPlugin(PluginContext* bareos_plugin_ctx); +static bRC freePlugin(PluginContext* bareos_plugin_ctx); +static bRC getPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); -static bRC setPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC setPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); -static bRC handlePluginEvent(bplugin_private_context* bareos_plugin_ctx, +static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, bEvent* event, void* value); -static bRC startBackupFile(bplugin_private_context* bareos_plugin_ctx, +static bRC startBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); -static bRC endBackupFile(bplugin_private_context* bareos_plugin_ctx); -static bRC pluginIO(bplugin_private_context* bareos_plugin_ctx, - struct io_pkt* io); -static bRC startRestoreFile(bplugin_private_context* bareos_plugin_ctx, - const char* cmd); -static bRC endRestoreFile(bplugin_private_context* bareos_plugin_ctx); -static bRC createFile(bplugin_private_context* bareos_plugin_ctx, - struct restore_pkt* rp); -static bRC setFileAttributes(bplugin_private_context* bareos_plugin_ctx, +static bRC endBackupFile(PluginContext* bareos_plugin_ctx); +static bRC pluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); +static bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); +static bRC endRestoreFile(PluginContext* bareos_plugin_ctx); +static bRC createFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); +static bRC setFileAttributes(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); -static bRC checkFile(bplugin_private_context* bareos_plugin_ctx, char* fname); -static bRC getAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap); -static bRC setAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap); -static bRC getXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* xp); -static bRC setXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* xp); -static bRC parse_plugin_definition(bplugin_private_context* bareos_plugin_ctx, +static bRC checkFile(PluginContext* bareos_plugin_ctx, char* fname); +static bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC setXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, void* value, PoolMem& plugin_options); -static void PyErrorHandler(bplugin_private_context* bareos_plugin_ctx, - int msgtype); -static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, - void* value); -static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, +static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); +static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); +static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, void* value); -static bRC PyGetPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); -static bRC PySetPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); -static bRC PyHandlePluginEvent(bplugin_private_context* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, bEvent* event, void* value); -static bRC PyStartBackupFile(bplugin_private_context* bareos_plugin_ctx, +static bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); -static bRC PyEndBackupFile(bplugin_private_context* bareos_plugin_ctx); -static bRC PyPluginIO(bplugin_private_context* bareos_plugin_ctx, - struct io_pkt* io); -static bRC PyStartRestoreFile(bplugin_private_context* bareos_plugin_ctx, +static bRC PyEndBackupFile(PluginContext* bareos_plugin_ctx); +static bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); +static bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); -static bRC PyEndRestoreFile(bplugin_private_context* bareos_plugin_ctx); -static bRC PyCreateFile(bplugin_private_context* bareos_plugin_ctx, +static bRC PyEndRestoreFile(PluginContext* bareos_plugin_ctx); +static bRC PyCreateFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); -static bRC PySetFileAttributes(bplugin_private_context* bareos_plugin_ctx, +static bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); -static bRC PyCheckFile(bplugin_private_context* bareos_plugin_ctx, char* fname); -static bRC PyGetAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap); -static bRC PySetAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap); -static bRC PyGetXattr(bplugin_private_context* bareos_plugin_ctx, - xattr_pkt* xp); -static bRC PySetXattr(bplugin_private_context* bareos_plugin_ctx, - xattr_pkt* xp); -static bRC PyRestoreObjectData(bplugin_private_context* bareos_plugin_ctx, +static bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname); +static bRC PyGetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC PySetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, struct restore_object_pkt* rop); -static bRC PyHandleBackupFile(bplugin_private_context* bareos_plugin_ctx, +static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); /* Pointers to Bareos functions */ @@ -272,11 +264,11 @@ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", 0); - // Extract capsule bareosfd.bplugin_private_context + // Extract capsule bareosfd.PluginContext void* ctx_from_bareosfd_module = - PyCapsule_Import("bareosfd.bplugin_private_context", 0); + PyCapsule_Import("bareosfd.PluginContext", 0); if (!ctx_from_bareosfd_module) { - printf("importing bareosfd.bplugin_private_context failed \n"); + printf("importing bareosfd.PluginContext failed \n"); } // Extract capsules bareosfd.BareosCoreFunctions @@ -291,7 +283,7 @@ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, } - *(void**)ctx_from_bareosfd_module = &bareos_plugin_context; + *(void**)ctx_from_bareosfd_module = &bareos_PluginContext; *(void**)bareos_core_functions_from_bareosfd_module = &bareos_core_functions; @@ -343,7 +335,7 @@ bRC unloadPlugin() * plugin instance must be thread safe and keep its own * local data. */ -static bRC newPlugin(bplugin_private_context* bareos_plugin_ctx) +static bRC newPlugin(PluginContext* bareos_plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = (struct plugin_private_context*)malloc( @@ -374,7 +366,7 @@ static bRC newPlugin(bplugin_private_context* bareos_plugin_ctx) * Release everything concerning a particular instance of a * plugin. Normally called when the Job terminates. */ -static bRC freePlugin(bplugin_private_context* bareos_plugin_ctx) +static bRC freePlugin(PluginContext* bareos_plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; @@ -415,7 +407,7 @@ static bRC freePlugin(bplugin_private_context* bareos_plugin_ctx) } -static bRC handlePluginEvent(bplugin_private_context* bareos_plugin_ctx, +static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, bEvent* event, void* value) { @@ -579,7 +571,7 @@ static bRC handlePluginEvent(bplugin_private_context* bareos_plugin_ctx, * The plugin can create "Virtual" files by giving them a * name that is not normally found on the file system. */ -static bRC startBackupFile(bplugin_private_context* bareos_plugin_ctx, +static bRC startBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp) { bRC retval = bRC_Error; @@ -631,7 +623,7 @@ static bRC startBackupFile(bplugin_private_context* bareos_plugin_ctx, /** * Done backing up a file. */ -static bRC endBackupFile(bplugin_private_context* bareos_plugin_ctx) +static bRC endBackupFile(PluginContext* bareos_plugin_ctx) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -652,8 +644,7 @@ static bRC endBackupFile(bplugin_private_context* bareos_plugin_ctx) * or after startRestoreFile to do the actual file * input or output. */ -static bRC pluginIO(bplugin_private_context* bareos_plugin_ctx, - struct io_pkt* io) +static bRC pluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -674,8 +665,7 @@ static bRC pluginIO(bplugin_private_context* bareos_plugin_ctx, /** * Start restore of a file. */ -static bRC startRestoreFile(bplugin_private_context* bareos_plugin_ctx, - const char* cmd) +static bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -694,7 +684,7 @@ static bRC startRestoreFile(bplugin_private_context* bareos_plugin_ctx, /** * Done restoring a file. */ -static bRC endRestoreFile(bplugin_private_context* bareos_plugin_ctx) +static bRC endRestoreFile(PluginContext* bareos_plugin_ctx) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -717,8 +707,7 @@ static bRC endRestoreFile(bplugin_private_context* bareos_plugin_ctx) * This data is what is needed to create the file, but does * not contain actual file data. */ -static bRC createFile(bplugin_private_context* bareos_plugin_ctx, - struct restore_pkt* rp) +static bRC createFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -738,7 +727,7 @@ static bRC createFile(bplugin_private_context* bareos_plugin_ctx, * Called after the file has been restored. This can be used to * set directory permissions, ... */ -static bRC setFileAttributes(bplugin_private_context* bareos_plugin_ctx, +static bRC setFileAttributes(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) { bRC retval = bRC_Error; @@ -758,7 +747,7 @@ static bRC setFileAttributes(bplugin_private_context* bareos_plugin_ctx, /** * When using Incremental dump, all previous dumps are necessary */ -static bRC checkFile(bplugin_private_context* bareos_plugin_ctx, char* fname) +static bRC checkFile(PluginContext* bareos_plugin_ctx, char* fname) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -778,7 +767,7 @@ static bRC checkFile(bplugin_private_context* bareos_plugin_ctx, char* fname) /** */ -static bRC getAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap) +static bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -796,7 +785,7 @@ static bRC getAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap) /** */ -static bRC setAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap) +static bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -814,7 +803,7 @@ static bRC setAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap) /** */ -static bRC getXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* xp) +static bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -832,7 +821,7 @@ static bRC getXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* xp) /** */ -static bRC setXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* xp) +static bRC setXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -866,7 +855,7 @@ static inline void SetStringIfNull(char** destination, char* value) * * python:module_path=:module_name=:... */ -static bRC parse_plugin_definition(bplugin_private_context* bareos_plugin_ctx, +static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, void* value, PoolMem& plugin_options) { @@ -1062,7 +1051,7 @@ static bRC parse_plugin_definition(bplugin_private_context* bareos_plugin_ctx, * module path and the module to load. We also load the dictionary used * for looking up the Python methods. */ -static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, void* value) +static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -1105,10 +1094,10 @@ static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, void* value) plugin_priv_ctx->pyModuleFunctionsDict = PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ - /* Encode the bplugin_private_context so a Python method can pass it in on + /* Encode the PluginContext so a Python method can pass it in on * calling back.*/ - /* plugin_priv_ctx->py_bplugin_private_context = - * PyCreatebplugin_private_context(bareos_plugin_ctx); */ + /* plugin_priv_ctx->py_PluginContext = + * PyCreatePluginContext(bareos_plugin_ctx); */ StorePluginContextInPythonModule(bareos_plugin_ctx); @@ -1122,7 +1111,7 @@ static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, void* value) if (!pPluginDefinition) { goto bail_out; } pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); - /* pFunc, plugin_priv_ctx->py_bplugin_private_context, pPluginDefinition, + /* pFunc, plugin_priv_ctx->py_PluginContext, pPluginDefinition, * NULL); */ Py_DECREF(pPluginDefinition); @@ -1160,7 +1149,7 @@ static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, void* value) * restore overrides can be passed in before the actual plugin options are * restored as part of the restore stream handling. */ -static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, +static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; @@ -1204,21 +1193,21 @@ static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, return retval; } -static bRC PyGetPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PySetPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PyHandlePluginEvent(bplugin_private_context* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, bEvent* event, void* value) { @@ -1492,7 +1481,7 @@ static inline bool PySavePacketToNative( * The plugin can create "Virtual" files by giving them a * name that is not normally found on the file system. */ -static bRC PyStartBackupFile(bplugin_private_context* bareos_plugin_ctx, +static bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp) { bRC retval = bRC_Error; @@ -1545,7 +1534,7 @@ static bRC PyStartBackupFile(bplugin_private_context* bareos_plugin_ctx, * If the plugin wishes to create another file and back it up, * then it must return bRC_More (not yet implemented). */ -static bRC PyEndBackupFile(bplugin_private_context* bareos_plugin_ctx) +static bRC PyEndBackupFile(PluginContext* bareos_plugin_ctx) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -1654,8 +1643,7 @@ static inline bool PyIoPacketToNative(PyIoPacket* pIoPkt, struct io_pkt* io) * or after startRestoreFile to do the actual file * input or output. */ -static bRC PyPluginIO(bplugin_private_context* bareos_plugin_ctx, - struct io_pkt* io) +static bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -1707,8 +1695,7 @@ static bRC PyPluginIO(bplugin_private_context* bareos_plugin_ctx, * Called when the first record is read from the Volume that was previously * written by the command plugin. */ -static bRC PyStartRestoreFile(bplugin_private_context* bareos_plugin_ctx, - const char* cmd) +static bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -1751,7 +1738,7 @@ static bRC PyStartRestoreFile(bplugin_private_context* bareos_plugin_ctx, /** * Called when a command plugin is done restoring a file. */ -static bRC PyEndRestoreFile(bplugin_private_context* bareos_plugin_ctx) +static bRC PyEndRestoreFile(PluginContext* bareos_plugin_ctx) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -1832,7 +1819,7 @@ static inline void PyRestorePacketToNative(PyRestorePacket* pRestorePacket, * CF_EXTRACT -- extract the file (i.e.call i/o routines) * CF_CREATED -- created, but no content to extract (typically directories) */ -static bRC PyCreateFile(bplugin_private_context* bareos_plugin_ctx, +static bRC PyCreateFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) { bRC retval = bRC_Error; @@ -1878,7 +1865,7 @@ static bRC PyCreateFile(bplugin_private_context* bareos_plugin_ctx, return retval; } -static bRC PySetFileAttributes(bplugin_private_context* bareos_plugin_ctx, +static bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) { bRC retval = bRC_Error; @@ -1922,7 +1909,7 @@ static bRC PySetFileAttributes(bplugin_private_context* bareos_plugin_ctx, return retval; } -static bRC PyCheckFile(bplugin_private_context* bareos_plugin_ctx, char* fname) +static bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -2002,7 +1989,7 @@ static inline bool PyAclPacketToNative(PyAclPacket* pAclPacket, return true; } -static bRC PyGetAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap) +static bRC PyGetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -2050,7 +2037,7 @@ static bRC PyGetAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap) return retval; } -static bRC PySetAcl(bplugin_private_context* bareos_plugin_ctx, acl_pkt* ap) +static bRC PySetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -2156,7 +2143,7 @@ static inline bool PyXattrPacketToNative(PyXattrPacket* pXattrPacket, return true; } -static bRC PyGetXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* xp) +static bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -2204,7 +2191,7 @@ static bRC PyGetXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* xp) return retval; } -static bRC PySetXattr(bplugin_private_context* bareos_plugin_ctx, xattr_pkt* xp) +static bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -2269,7 +2256,7 @@ static inline PyRestoreObject* NativeToPyRestoreObject( return pRestoreObject; } -static bRC PyRestoreObjectData(bplugin_private_context* bareos_plugin_ctx, +static bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, struct restore_object_pkt* rop) { bRC retval = bRC_Error; @@ -2313,7 +2300,7 @@ static bRC PyRestoreObjectData(bplugin_private_context* bareos_plugin_ctx, return retval; } -static bRC PyHandleBackupFile(bplugin_private_context* bareos_plugin_ctx, +static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp) { bRC retval = bRC_Error; @@ -2369,8 +2356,7 @@ static bRC PyHandleBackupFile(bplugin_private_context* bareos_plugin_ctx, static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } @@ -2441,8 +2427,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject* pyValue; @@ -2493,8 +2478,7 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); /* plugin_private_context* ppc = */ /* (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; */ @@ -2517,8 +2501,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; @@ -2539,8 +2522,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -2581,8 +2563,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -2621,8 +2602,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } @@ -2649,8 +2629,7 @@ static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) { char* file = NULL; bRC retval = bRC_Error; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|z:BareosAddExclude", &file)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() @@ -2671,8 +2650,7 @@ static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) { char* file = NULL; bRC retval = bRC_Error; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|z:BareosAddInclude", &file)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() @@ -2693,8 +2671,7 @@ static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) { char* opts = NULL; bRC retval = bRC_Error; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|z:BareosAddOptions", &opts)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() @@ -2716,8 +2693,7 @@ static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) int type; char* item = NULL; bRC retval = bRC_Error; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|zi:BareosAddRegex", &item, &type)) { goto bail_out; } @@ -2740,8 +2716,7 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) int type; char* item = NULL; bRC retval = bRC_Error; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|zi:BareosAddWild", &item, &type)) { goto bail_out; @@ -2762,8 +2737,7 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) { - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewOptions")) { goto bail_out; } @@ -2781,8 +2755,7 @@ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) { - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewInclude")) { goto bail_out; } @@ -2800,8 +2773,7 @@ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) { - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewPreInclude")) { goto bail_out; } @@ -2820,8 +2792,7 @@ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) */ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) { - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); struct save_pkt sp; bRC retval = bRC_Error; @@ -2875,8 +2846,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) */ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) { - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); struct save_pkt sp; bRC retval = bRC_Error; PySavePacket* pSavePkt; @@ -2919,8 +2889,7 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) { bool all; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; @@ -2945,8 +2914,7 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) { bool all; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; diff --git a/core/src/plugins/filed/python/python-fd.h b/core/src/plugins/filed/python/python-fd.h index 364f4e66d36..71256b01adf 100644 --- a/core/src/plugins/filed/python/python-fd.h +++ b/core/src/plugins/filed/python/python-fd.h @@ -755,7 +755,7 @@ static PyMethodDef Methods[] = { using namespace filedaemon; /* variables storing bareos pointers */ -static void* bareos_plugin_context = NULL; +static void* bareos_PluginContext = NULL; static void* bareos_core_functions = NULL; #ifdef __cplusplus @@ -777,22 +777,21 @@ MOD_INIT(bareosfd) MOD_DEF(m, PYTHON_MODULE_NAME_QUOTED, NULL, Methods) - /* add bplugin_private_context Capsule */ + /* add PluginContext Capsule */ PyObject* PyModulePluginContext = - PyCapsule_New((void*)&bareos_plugin_context, - PYTHON_MODULE_NAME_QUOTED ".bplugin_private_context", NULL); + PyCapsule_New((void*)&bareos_PluginContext, + PYTHON_MODULE_NAME_QUOTED ".PluginContext", NULL); if (!PyModulePluginContext) { - printf(PYTHON_MODULE_NAME_QUOTED - ":bplugin_private_context PyCapsule_New failed\n"); + printf(PYTHON_MODULE_NAME_QUOTED ":PluginContext PyCapsule_New failed\n"); return MOD_ERROR_VAL; } if (PyModulePluginContext) { - PyModule_AddObject(m, "bplugin_private_context", PyModulePluginContext); - printf(PYTHON_MODULE_NAME_QUOTED ": added bplugin_private_context@%p\n", - &bareos_plugin_context); + PyModule_AddObject(m, "PluginContext", PyModulePluginContext); + printf(PYTHON_MODULE_NAME_QUOTED ": added PluginContext@%p\n", + &bareos_PluginContext); } else { printf(PYTHON_MODULE_NAME_QUOTED - ":bplugin_private_context PyModule_AddObject failed\n"); + ":PluginContext PyModule_AddObject failed\n"); return MOD_ERROR_VAL; } diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index 9eccfe5d512..e2107e27b14 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -69,31 +69,24 @@ static void PyErrorHandler() } // using namespace filedaemon; -bRC bareosRegisterEvents(bplugin_private_context* ctx, int nr_events, ...) +bRC bareosRegisterEvents(PluginContext* ctx, int nr_events, ...) { return bRC_OK; }; -bRC bareosUnRegisterEvents(bplugin_private_context* ctx, int nr_events, ...) +bRC bareosUnRegisterEvents(PluginContext* ctx, int nr_events, ...) { return bRC_OK; }; -bRC bareosGetInstanceCount(bplugin_private_context* ctx, int* ret) +bRC bareosGetInstanceCount(PluginContext* ctx, int* ret) { return bRC_OK; }; +bRC bareosGetValue(PluginContext* ctx, filedaemon::bVariable var, void* value) { return bRC_OK; }; -bRC bareosGetValue(bplugin_private_context* ctx, - filedaemon::bVariable var, - void* value) +bRC bareosSetValue(PluginContext* ctx, filedaemon::bVariable var, void* value) { return bRC_OK; }; -bRC bareosSetValue(bplugin_private_context* ctx, - filedaemon::bVariable var, - void* value) -{ - return bRC_OK; -}; -bRC bareosJobMsg(bplugin_private_context* ctx, +bRC bareosJobMsg(PluginContext* ctx, const char* file, int line, int type, @@ -105,7 +98,7 @@ bRC bareosJobMsg(bplugin_private_context* ctx, type, (int64_t)mtime, fmt); return bRC_OK; }; -bRC bareosDebugMsg(bplugin_private_context* ctx, +bRC bareosDebugMsg(PluginContext* ctx, const char* file, int line, int level, @@ -116,58 +109,41 @@ bRC bareosDebugMsg(bplugin_private_context* ctx, fmt); return bRC_OK; }; -void* bareosMalloc(bplugin_private_context* ctx, - const char* file, - int line, - size_t size) +void* bareosMalloc(PluginContext* ctx, const char* file, int line, size_t size) { return NULL; }; -void bareosFree(bplugin_private_context* ctx, - const char* file, - int line, - void* mem) +void bareosFree(PluginContext* ctx, const char* file, int line, void* mem) { return; }; -bRC bareosAddExclude(bplugin_private_context* ctx, const char* file) -{ - return bRC_OK; -}; -bRC bareosAddInclude(bplugin_private_context* ctx, const char* file) -{ - return bRC_OK; -}; -bRC bareosAddOptions(bplugin_private_context* ctx, const char* opts) -{ - return bRC_OK; -}; -bRC bareosAddRegex(bplugin_private_context* ctx, const char* item, int type) +bRC bareosAddExclude(PluginContext* ctx, const char* file) { return bRC_OK; }; +bRC bareosAddInclude(PluginContext* ctx, const char* file) { return bRC_OK; }; +bRC bareosAddOptions(PluginContext* ctx, const char* opts) { return bRC_OK; }; +bRC bareosAddRegex(PluginContext* ctx, const char* item, int type) { return bRC_OK; }; -bRC bareosAddWild(bplugin_private_context* ctx, const char* item, int type) +bRC bareosAddWild(PluginContext* ctx, const char* item, int type) { return bRC_OK; }; -bRC bareosNewOptions(bplugin_private_context* ctx) { return bRC_OK; }; -bRC bareosNewInclude(bplugin_private_context* ctx) { return bRC_OK; }; -bRC bareosNewPreInclude(bplugin_private_context* ctx) { return bRC_OK; }; -bRC bareosCheckChanges(bplugin_private_context* ctx, - struct filedaemon::save_pkt* sp) +bRC bareosNewOptions(PluginContext* ctx) { return bRC_OK; }; +bRC bareosNewInclude(PluginContext* ctx) { return bRC_OK; }; +bRC bareosNewPreInclude(PluginContext* ctx) { return bRC_OK; }; +bRC bareosCheckChanges(PluginContext* ctx, struct filedaemon::save_pkt* sp) { return bRC_OK; }; -bRC bareosAcceptFile(bplugin_private_context* ctx, - struct filedaemon::save_pkt* sp) +bRC bareosAcceptFile(PluginContext* ctx, struct filedaemon::save_pkt* sp) { return bRC_OK; }; /* Need fname and statp */ -bRC bareosSetSeenBitmap(bplugin_private_context* ctx, bool all, char* fname) +bRC bareosSetSeenBitmap(PluginContext* ctx, bool all, char* fname) { return bRC_OK; }; -bRC bareosClearSeenBitmap(bplugin_private_context* ctx, bool all, char* fname) +bRC bareosClearSeenBitmap(PluginContext* ctx, bool all, char* fname) { return bRC_OK; }; @@ -199,7 +175,7 @@ static filedaemon::BareosCoreFunctions bareos_core_functions = { bareosSetSeenBitmap, bareosClearSeenBitmap}; -static void* bareos_plugin_context = NULL; +static void* bareos_PluginContext = NULL; int main(int argc, char* argv[]) { @@ -216,13 +192,13 @@ int main(int argc, char* argv[]) /* printf("bareos_core_functions is at %p\n", * &bareos_core_functions); */ - /* printf("bareos_plugin_context %p\n", &bareos_plugin_context); */ + /* printf("bareos_PluginContext %p\n", &bareos_PluginContext); */ // Extract capsules pointer from bareosfd module void* ctx_from_bareosfd_module = - PyCapsule_Import("bareosfd.bplugin_private_context", 0); + PyCapsule_Import("bareosfd.PluginContext", 0); if (!ctx_from_bareosfd_module) { - printf("importing bareosfd.bplugin_private_context failed \n"); + printf("importing bareosfd.PluginContext failed \n"); } // Extract capsules pointer from bareosfd module @@ -259,7 +235,7 @@ int main(int argc, char* argv[]) /* printf("bareos_core_functions_from_bareosfd_module contains %p\n", */ /* *(void**)bareos_core_functions_from_bareosfd_module); */ - *(void**)ctx_from_bareosfd_module = &bareos_plugin_context; + *(void**)ctx_from_bareosfd_module = &bareos_PluginContext; *(void**)bareos_core_functions_from_bareosfd_module = &bareos_core_functions; /* call loadPlugin in plugin */ diff --git a/core/src/plugins/filed/rados/rados-fd.cc b/core/src/plugins/filed/rados/rados-fd.cc index 98897fd799c..4355db725c6 100644 --- a/core/src/plugins/filed/rados/rados-fd.cc +++ b/core/src/plugins/filed/rados/rados-fd.cc @@ -58,35 +58,28 @@ static const int debuglevel = 150; /** * Forward referenced functions */ -static bRC newPlugin(bplugin_private_context* ctx); -static bRC freePlugin(bplugin_private_context* ctx); -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC handlePluginEvent(bplugin_private_context* ctx, - bEvent* event, - void* value); -static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp); -static bRC endBackupFile(bplugin_private_context* ctx); -static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io); -static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd); -static bRC endRestoreFile(bplugin_private_context* ctx); -static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp); -static bRC setFileAttributes(bplugin_private_context* ctx, - struct restore_pkt* rp); -static bRC checkFile(bplugin_private_context* ctx, char* fname); -static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap); -static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap); -static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp); -static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp); - -static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value); -static bRC setup_backup(bplugin_private_context* ctx, void* value); -static bRC setup_restore(bplugin_private_context* ctx, void* value); -static bRC end_restore_job(bplugin_private_context* ctx, void* value); +static bRC newPlugin(PluginContext* ctx); +static bRC freePlugin(PluginContext* ctx); +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC handlePluginEvent(PluginContext* ctx, bEvent* event, void* value); +static bRC startBackupFile(PluginContext* ctx, struct save_pkt* sp); +static bRC endBackupFile(PluginContext* ctx); +static bRC pluginIO(PluginContext* ctx, struct io_pkt* io); +static bRC startRestoreFile(PluginContext* ctx, const char* cmd); +static bRC endRestoreFile(PluginContext* ctx); +static bRC createFile(PluginContext* ctx, struct restore_pkt* rp); +static bRC setFileAttributes(PluginContext* ctx, struct restore_pkt* rp); +static bRC checkFile(PluginContext* ctx, char* fname); +static bRC getAcl(PluginContext* ctx, acl_pkt* ap); +static bRC setAcl(PluginContext* ctx, acl_pkt* ap); +static bRC getXattr(PluginContext* ctx, xattr_pkt* xp); +static bRC setXattr(PluginContext* ctx, xattr_pkt* xp); + +static bRC parse_plugin_definition(PluginContext* ctx, void* value); +static bRC setup_backup(PluginContext* ctx, void* value); +static bRC setup_restore(PluginContext* ctx, void* value); +static bRC end_restore_job(PluginContext* ctx, void* value); /** * Pointers to Bareos functions @@ -216,7 +209,7 @@ bRC unloadPlugin() { return bRC_OK; } * * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bplugin_private_context* ctx) +static bRC newPlugin(PluginContext* ctx) { plugin_ctx* p_ctx; @@ -242,7 +235,7 @@ static bRC newPlugin(bplugin_private_context* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bplugin_private_context* ctx) +static bRC freePlugin(PluginContext* ctx) { plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -288,9 +281,7 @@ static bRC freePlugin(bplugin_private_context* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value) { return bRC_OK; } @@ -298,9 +289,7 @@ static bRC getPluginValue(bplugin_private_context* ctx, /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value) { return bRC_OK; } @@ -308,9 +297,7 @@ static bRC setPluginValue(bplugin_private_context* ctx, /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bplugin_private_context* ctx, - bEvent* event, - void* value) +static bRC handlePluginEvent(PluginContext* ctx, bEvent* event, void* value) { bRC retval; plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -371,7 +358,7 @@ static bRC handlePluginEvent(bplugin_private_context* ctx, * - Get the next objectname from the list iterator. * - Check using AcceptFile if it matches the fileset. */ -static bRC get_next_object_to_backup(bplugin_private_context* ctx) +static bRC get_next_object_to_backup(PluginContext* ctx) { int status; struct save_pkt sp; @@ -446,7 +433,7 @@ static bRC get_next_object_to_backup(bplugin_private_context* ctx) /** * Start the backup of a specific file */ -static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) +static bRC startBackupFile(PluginContext* ctx, struct save_pkt* sp) { plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -489,7 +476,7 @@ static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) /** * Done with backup of this file */ -static bRC endBackupFile(bplugin_private_context* ctx) +static bRC endBackupFile(PluginContext* ctx) { plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -548,7 +535,7 @@ static inline void SetString(char** destination, char* value) * * rados:conffile=:namespace=:clientid=:clustername=:username=:snapshotname=: */ -static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value) +static bRC parse_plugin_definition(PluginContext* ctx, void* value) { int i; bool keep_existing; @@ -688,7 +675,7 @@ static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value) /** * Connect via RADOS protocol to a CEPH cluster. */ -static bRC connect_to_rados(bplugin_private_context* ctx) +static bRC connect_to_rados(PluginContext* ctx) { int status; #if LIBRADOS_VERSION_CODE >= 17408 @@ -781,7 +768,7 @@ static bRC connect_to_rados(bplugin_private_context* ctx) /** * Generic setup for performing a backup. */ -static bRC setup_backup(bplugin_private_context* ctx, void* value) +static bRC setup_backup(PluginContext* ctx, void* value) { int status; plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -873,7 +860,7 @@ static bRC setup_backup(bplugin_private_context* ctx, void* value) /** * Generic setup for performing a restore. */ -static bRC setup_restore(bplugin_private_context* ctx, void* value) +static bRC setup_restore(PluginContext* ctx, void* value) { plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -887,7 +874,7 @@ static bRC setup_restore(bplugin_private_context* ctx, void* value) /** * Bareos is calling us to do the actual I/O */ -static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) +static bRC pluginIO(PluginContext* ctx, struct io_pkt* io) { int io_count; plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -955,7 +942,7 @@ static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) /** * See if we need to do any postprocessing after the restore. */ -static bRC end_restore_job(bplugin_private_context* ctx, void* value) +static bRC end_restore_job(PluginContext* ctx, void* value) { bRC retval = bRC_OK; plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -973,7 +960,7 @@ static bRC end_restore_job(bplugin_private_context* ctx, void* value) * Bareos is notifying us that a plugin name string was found, * and passing us the plugin command, so we can prepare for a restore. */ -static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) +static bRC startRestoreFile(PluginContext* ctx, const char* cmd) { return bRC_OK; } @@ -982,7 +969,7 @@ static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) * Bareos is notifying us that the plugin data has terminated, * so the restore for this particular file is done. */ -static bRC endRestoreFile(bplugin_private_context* ctx) { return bRC_OK; } +static bRC endRestoreFile(PluginContext* ctx) { return bRC_OK; } /** * This is called during restore to create the file (if necessary) We must @@ -993,7 +980,7 @@ static bRC endRestoreFile(bplugin_private_context* ctx) { return bRC_OK; } * CF_EXTRACT -- extract the file (i.e.call i/o routines) * CF_CREATED -- created, but no content to extract (typically directories) */ -static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) +static bRC createFile(PluginContext* ctx, struct restore_pkt* rp) { char* bp; int status; @@ -1083,8 +1070,7 @@ static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) return bRC_OK; } -static bRC setFileAttributes(bplugin_private_context* ctx, - struct restore_pkt* rp) +static bRC setFileAttributes(PluginContext* ctx, struct restore_pkt* rp) { return bRC_OK; } @@ -1092,16 +1078,13 @@ static bRC setFileAttributes(bplugin_private_context* ctx, /** * When using Incremental dump, all previous dumps are necessary */ -static bRC checkFile(bplugin_private_context* ctx, char* fname) -{ - return bRC_OK; -} +static bRC checkFile(PluginContext* ctx, char* fname) { return bRC_OK; } -static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap) { return bRC_OK; } +static bRC getAcl(PluginContext* ctx, acl_pkt* ap) { return bRC_OK; } -static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap) { return bRC_OK; } +static bRC setAcl(PluginContext* ctx, acl_pkt* ap) { return bRC_OK; } -static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp) +static bRC getXattr(PluginContext* ctx, xattr_pkt* xp) { int status; size_t xattr_value_length; @@ -1163,7 +1146,7 @@ static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp) return bRC_Error; } -static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp) +static bRC setXattr(PluginContext* ctx, xattr_pkt* xp) { int status; const char* bp; diff --git a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc index 379f5b24738..2e5b44f933b 100644 --- a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc +++ b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc @@ -40,25 +40,18 @@ static const int debuglevel = 0; #define PLUGIN_DESCRIPTION "Bareos Delta Test Plugin" /* Forward referenced functions */ -static bRC newPlugin(bplugin_private_context* ctx); -static bRC freePlugin(bplugin_private_context* ctx); -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC handlePluginEvent(bplugin_private_context* ctx, - bEvent* event, - void* value); -static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp); -static bRC endBackupFile(bplugin_private_context* ctx); -static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io); -static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd); -static bRC endRestoreFile(bplugin_private_context* ctx); -static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp); -static bRC setFileAttributes(bplugin_private_context* ctx, - struct restore_pkt* rp); +static bRC newPlugin(PluginContext* ctx); +static bRC freePlugin(PluginContext* ctx); +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC handlePluginEvent(PluginContext* ctx, bEvent* event, void* value); +static bRC startBackupFile(PluginContext* ctx, struct save_pkt* sp); +static bRC endBackupFile(PluginContext* ctx); +static bRC pluginIO(PluginContext* ctx, struct io_pkt* io); +static bRC startRestoreFile(PluginContext* ctx, const char* cmd); +static bRC endRestoreFile(PluginContext* ctx); +static bRC createFile(PluginContext* ctx, struct restore_pkt* rp); +static bRC setFileAttributes(PluginContext* ctx, struct restore_pkt* rp); /* Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; @@ -91,7 +84,7 @@ static pFuncs pluginFuncs = { class delta_test { private: - bplugin_private_context* ctx; + PluginContext* ctx; public: POOLMEM* fname; /* Filename to save */ @@ -100,7 +93,7 @@ class delta_test { bool done; int level; - delta_test(bplugin_private_context* bpc) + delta_test(PluginContext* bpc) { fd = NULL; ctx = bpc; @@ -164,7 +157,7 @@ bRC unloadPlugin() /** * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bplugin_private_context* ctx) +static bRC newPlugin(PluginContext* ctx) { delta_test* self = new delta_test(ctx); if (!self) { return bRC_Error; } @@ -178,7 +171,7 @@ static bRC newPlugin(bplugin_private_context* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bplugin_private_context* ctx) +static bRC freePlugin(PluginContext* ctx) { struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; @@ -192,9 +185,7 @@ static bRC freePlugin(bplugin_private_context* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value) { return bRC_OK; } @@ -202,9 +193,7 @@ static bRC getPluginValue(bplugin_private_context* ctx, /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value) { return bRC_OK; } @@ -212,9 +201,7 @@ static bRC setPluginValue(bplugin_private_context* ctx, /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bplugin_private_context* ctx, - bEvent* event, - void* value) +static bRC handlePluginEvent(PluginContext* ctx, bEvent* event, void* value) { delta_test* self = get_self(ctx); int accurate = 0; @@ -264,7 +251,7 @@ static int nb_files = 4; /** * Start the backup of a specific file */ -static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) +static bRC startBackupFile(PluginContext* ctx, struct save_pkt* sp) { delta_test* self = get_self(ctx); if (!self) { return bRC_Error; } @@ -296,7 +283,7 @@ static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) /** * Done with backup of this file */ -static bRC endBackupFile(bplugin_private_context* ctx) +static bRC endBackupFile(PluginContext* ctx) { /* * We would return bRC_More if we wanted startBackupFile to be @@ -308,7 +295,7 @@ static bRC endBackupFile(bplugin_private_context* ctx) /** * Bareos is calling us to do the actual I/O */ -static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) +static bRC pluginIO(PluginContext* ctx, struct io_pkt* io) { delta_test* self = get_self(ctx); struct stat statp; @@ -410,7 +397,7 @@ static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) * Bareos is notifying us that a plugin name string was found, and * passing us the plugin command, so we can prepare for a restore. */ -static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) +static bRC startRestoreFile(PluginContext* ctx, const char* cmd) { // Dmsg(ctx, debuglevel, "delta-test-fd: startRestoreFile cmd=%s\n", cmd); return bRC_OK; @@ -420,7 +407,7 @@ static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) * Bareos is notifying us that the plugin data has terminated, so * the restore for this particular file is done. */ -static bRC endRestoreFile(bplugin_private_context* ctx) +static bRC endRestoreFile(PluginContext* ctx) { // Dmsg(ctx, debuglevel, "delta-test-fd: endRestoreFile\n"); return bRC_OK; @@ -436,7 +423,7 @@ static bRC endRestoreFile(bplugin_private_context* ctx) * CF_CREATED -- created, but no content to extract (typically directories) * */ -static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) +static bRC createFile(PluginContext* ctx, struct restore_pkt* rp) { delta_test* self = get_self(ctx); PmStrcpy(self->fname, rp->ofname); @@ -444,8 +431,7 @@ static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) return bRC_OK; } -static bRC setFileAttributes(bplugin_private_context* ctx, - struct restore_pkt* rp) +static bRC setFileAttributes(PluginContext* ctx, struct restore_pkt* rp) { // Dmsg(ctx, debuglevel, "delta-test-fd: setFileAttributes\n"); return bRC_OK; diff --git a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc index 28e8bcce203..867b18c9a9f 100644 --- a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc +++ b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc @@ -44,30 +44,23 @@ static const int debuglevel = 000; #define PLUGIN_DESCRIPTION "Bareos Test File Daemon Plugin" /* Forward referenced functions */ -static bRC newPlugin(bplugin_private_context* ctx); -static bRC freePlugin(bplugin_private_context* ctx); -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC handlePluginEvent(bplugin_private_context* ctx, - bEvent* event, - void* value); -static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp); -static bRC endBackupFile(bplugin_private_context* ctx); -static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io); -static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd); -static bRC endRestoreFile(bplugin_private_context* ctx); -static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp); -static bRC setFileAttributes(bplugin_private_context* ctx, - struct restore_pkt* rp); -static bRC checkFile(bplugin_private_context* ctx, char* fname); -static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap); -static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap); -static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp); -static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp); +static bRC newPlugin(PluginContext* ctx); +static bRC freePlugin(PluginContext* ctx); +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC handlePluginEvent(PluginContext* ctx, bEvent* event, void* value); +static bRC startBackupFile(PluginContext* ctx, struct save_pkt* sp); +static bRC endBackupFile(PluginContext* ctx); +static bRC pluginIO(PluginContext* ctx, struct io_pkt* io); +static bRC startRestoreFile(PluginContext* ctx, const char* cmd); +static bRC endRestoreFile(PluginContext* ctx); +static bRC createFile(PluginContext* ctx, struct restore_pkt* rp); +static bRC setFileAttributes(PluginContext* ctx, struct restore_pkt* rp); +static bRC checkFile(PluginContext* ctx, char* fname); +static bRC getAcl(PluginContext* ctx, acl_pkt* ap); +static bRC setAcl(PluginContext* ctx, acl_pkt* ap); +static bRC getXattr(PluginContext* ctx, xattr_pkt* xp); +static bRC setXattr(PluginContext* ctx, xattr_pkt* xp); /* Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; @@ -161,7 +154,7 @@ bRC unloadPlugin() { return bRC_OK; } /** * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bplugin_private_context* ctx) +static bRC newPlugin(PluginContext* ctx) { struct plugin_ctx* p_ctx = (struct plugin_ctx*)malloc(sizeof(struct plugin_ctx)); @@ -179,7 +172,7 @@ static bRC newPlugin(bplugin_private_context* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bplugin_private_context* ctx) +static bRC freePlugin(PluginContext* ctx) { struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -193,9 +186,7 @@ static bRC freePlugin(bplugin_private_context* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value) { return bRC_OK; } @@ -203,9 +194,7 @@ static bRC getPluginValue(bplugin_private_context* ctx, /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value) { return bRC_OK; } @@ -213,9 +202,7 @@ static bRC setPluginValue(bplugin_private_context* ctx, /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bplugin_private_context* ctx, - bEvent* event, - void* value) +static bRC handlePluginEvent(PluginContext* ctx, bEvent* event, void* value) { struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; restore_object_pkt* rop; @@ -333,7 +320,7 @@ static bRC handlePluginEvent(bplugin_private_context* ctx, /** * Start the backup of a specific file */ -static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) +static bRC startBackupFile(PluginContext* ctx, struct save_pkt* sp) { struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -594,24 +581,18 @@ static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) return bRC_OK; } -static bRC getAcl(bplugin_private_context* ctx, acl_pkt* ap) { return bRC_OK; } +static bRC getAcl(PluginContext* ctx, acl_pkt* ap) { return bRC_OK; } -static bRC setAcl(bplugin_private_context* ctx, acl_pkt* ap) { return bRC_OK; } +static bRC setAcl(PluginContext* ctx, acl_pkt* ap) { return bRC_OK; } -static bRC getXattr(bplugin_private_context* ctx, xattr_pkt* xp) -{ - return bRC_OK; -} +static bRC getXattr(PluginContext* ctx, xattr_pkt* xp) { return bRC_OK; } -static bRC setXattr(bplugin_private_context* ctx, xattr_pkt* xp) -{ - return bRC_OK; -} +static bRC setXattr(PluginContext* ctx, xattr_pkt* xp) { return bRC_OK; } /** * Done with backup of this file */ -static bRC endBackupFile(bplugin_private_context* ctx) +static bRC endBackupFile(PluginContext* ctx) { /* * We would return bRC_More if we wanted startBackupFile to be @@ -624,7 +605,7 @@ static bRC endBackupFile(bplugin_private_context* ctx) /** * Bareos is calling us to do the actual I/O */ -static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) +static bRC pluginIO(PluginContext* ctx, struct io_pkt* io) { struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -638,7 +619,7 @@ static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) * Bareos is notifying us that a plugin name string was found, and * passing us the plugin command, so we can prepare for a restore. */ -static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) +static bRC startRestoreFile(PluginContext* ctx, const char* cmd) { printf("test-plugin-fd: startRestoreFile cmd=%s\n", cmd); return bRC_OK; @@ -648,7 +629,7 @@ static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) * Bareos is notifying us that the plugin data has terminated, so * the restore for this particular file is done. */ -static bRC endRestoreFile(bplugin_private_context* ctx) +static bRC endRestoreFile(PluginContext* ctx) { printf("test-plugin-fd: endRestoreFile\n"); return bRC_OK; @@ -664,7 +645,7 @@ static bRC endRestoreFile(bplugin_private_context* ctx) * CF_CREATED -- created, but no content to extract (typically directories) * */ -static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) +static bRC createFile(PluginContext* ctx, struct restore_pkt* rp) { printf("test-plugin-fd: createFile\n"); if (strlen(rp->where) > 512) { @@ -677,16 +658,12 @@ static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) return bRC_OK; } -static bRC setFileAttributes(bplugin_private_context* ctx, - struct restore_pkt* rp) +static bRC setFileAttributes(PluginContext* ctx, struct restore_pkt* rp) { printf("test-plugin-fd: setFileAttributes\n"); return bRC_OK; } /* When using Incremental dump, all previous dumps are necessary */ -static bRC checkFile(bplugin_private_context* ctx, char* fname) -{ - return bRC_OK; -} +static bRC checkFile(PluginContext* ctx, char* fname) { return bRC_OK; } } /* namespace filedaemon */ diff --git a/core/src/plugins/python_plugins_common.inc b/core/src/plugins/python_plugins_common.inc index 8b5ea4787e4..a8beb19d146 100644 --- a/core/src/plugins/python_plugins_common.inc +++ b/core/src/plugins/python_plugins_common.inc @@ -20,7 +20,7 @@ */ /* Common functions used in all python plugins. */ -static bRC getPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC getPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value) { @@ -38,7 +38,7 @@ bail_out: return retval; } -static bRC setPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC setPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value) { @@ -120,7 +120,7 @@ static inline void SetString(char** destination, char* value) * return "".join(traceback.format_exception(sys.exc_type, * sys.exc_value, sys.exc_traceback)) */ -static void PyErrorHandler(bplugin_private_context* bareos_plugin_ctx, int msgtype) +static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype) { PyObject *type, *value, *traceback; PyObject* tracebackModule; @@ -165,25 +165,25 @@ static void PyErrorHandler(bplugin_private_context* bareos_plugin_ctx, int msgty free(error_string); } -static void StorePluginContextInPythonModule(bplugin_private_context* bareos_plugin_ctx) +static void StorePluginContextInPythonModule(PluginContext* bareos_plugin_ctx) { /* get the pointer to the module variable that is exported via the capsule */ - bplugin_private_context** bareosfd_bplugin_private_context = - (bplugin_private_context**)PyCapsule_Import(PYTHON_MODULE_NAME_QUOTED ".bplugin_private_context", 0); + PluginContext** bareosfd_PluginContext = + (PluginContext**)PyCapsule_Import(PYTHON_MODULE_NAME_QUOTED ".PluginContext", 0); /* store bareos_plugin_ctx in module */ - if (bareosfd_bplugin_private_context) { - *bareosfd_bplugin_private_context = bareos_plugin_ctx; + if (bareosfd_PluginContext) { + *bareosfd_PluginContext = bareos_plugin_ctx; } else { - printf(PYTHON_MODULE_NAME_QUOTED ": could not get bareosfd_bplugin_private_context from module\n"); + printf(PYTHON_MODULE_NAME_QUOTED ": could not get bareosfd_PluginContext from module\n"); } } -static bplugin_private_context* GetPluginContextFromPythonModule() +static PluginContext* GetPluginContextFromPythonModule() { - const char* capsule_name = PYTHON_MODULE_NAME_QUOTED ".bplugin_private_context"; - bplugin_private_context** retval = - (bplugin_private_context**)PyCapsule_Import(capsule_name, 0); + const char* capsule_name = PYTHON_MODULE_NAME_QUOTED ".PluginContext"; + PluginContext** retval = + (PluginContext**)PyCapsule_Import(capsule_name, 0); return *retval; } diff --git a/core/src/plugins/stored/autoxflate/autoxflate-sd.cc b/core/src/plugins/stored/autoxflate/autoxflate-sd.cc index 2c0ea0ed3fe..e477f16c041 100644 --- a/core/src/plugins/stored/autoxflate/autoxflate-sd.cc +++ b/core/src/plugins/stored/autoxflate/autoxflate-sd.cc @@ -66,30 +66,20 @@ using namespace storagedaemon; /** * Forward referenced functions */ -static bRC newPlugin(bplugin_private_context* ctx); -static bRC freePlugin(bplugin_private_context* ctx); -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC handlePluginEvent(bplugin_private_context* ctx, - bsdEvent* event, - void* value); -static bRC handleJobEnd(bplugin_private_context* ctx); -static bRC setup_record_translation(bplugin_private_context* ctx, void* value); -static bRC handle_read_translation(bplugin_private_context* ctx, void* value); -static bRC handle_write_translation(bplugin_private_context* ctx, void* value); - -static bool SetupAutoDeflation(bplugin_private_context* ctx, - DeviceControlRecord* dcr); -static bool SetupAutoInflation(bplugin_private_context* ctx, - DeviceControlRecord* dcr); -static bool AutoDeflateRecord(bplugin_private_context* ctx, - DeviceControlRecord* dcr); -static bool AutoInflateRecord(bplugin_private_context* ctx, - DeviceControlRecord* dcr); +static bRC newPlugin(PluginContext* ctx); +static bRC freePlugin(PluginContext* ctx); +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC handlePluginEvent(PluginContext* ctx, bsdEvent* event, void* value); +static bRC handleJobEnd(PluginContext* ctx); +static bRC setup_record_translation(PluginContext* ctx, void* value); +static bRC handle_read_translation(PluginContext* ctx, void* value); +static bRC handle_write_translation(PluginContext* ctx, void* value); + +static bool SetupAutoDeflation(PluginContext* ctx, DeviceControlRecord* dcr); +static bool SetupAutoInflation(PluginContext* ctx, DeviceControlRecord* dcr); +static bool AutoDeflateRecord(PluginContext* ctx, DeviceControlRecord* dcr); +static bool AutoInflateRecord(PluginContext* ctx, DeviceControlRecord* dcr); /** * Is the SD in compatible mode or not. @@ -181,7 +171,7 @@ bRC unloadPlugin() { return bRC_OK; } * * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bplugin_private_context* ctx) +static bRC newPlugin(PluginContext* ctx) { int JobId = 0; struct plugin_ctx* p_ctx; @@ -214,7 +204,7 @@ static bRC newPlugin(bplugin_private_context* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bplugin_private_context* ctx) +static bRC freePlugin(PluginContext* ctx) { int JobId = 0; struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; @@ -236,9 +226,7 @@ static bRC freePlugin(bplugin_private_context* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value) { Dmsg(ctx, debuglevel, "autoxflate-sd: getPluginValue var=%d\n", var); @@ -248,9 +236,7 @@ static bRC getPluginValue(bplugin_private_context* ctx, /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value) { Dmsg(ctx, debuglevel, "autoxflate-sd: setPluginValue var=%d\n", var); @@ -260,9 +246,7 @@ static bRC setPluginValue(bplugin_private_context* ctx, /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bplugin_private_context* ctx, - bsdEvent* event, - void* value) +static bRC handlePluginEvent(PluginContext* ctx, bsdEvent* event, void* value) { switch (event->eventType) { case bsdEventSetupRecordTranslation: @@ -285,7 +269,7 @@ static bRC handlePluginEvent(bplugin_private_context* ctx, /** * At end of job report how inflate/deflate ratio was. */ -static bRC handleJobEnd(bplugin_private_context* ctx) +static bRC handleJobEnd(PluginContext* ctx) { struct plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; @@ -312,7 +296,7 @@ static bRC handleJobEnd(bplugin_private_context* ctx) return bRC_OK; } -static bRC setup_record_translation(bplugin_private_context* ctx, void* value) +static bRC setup_record_translation(PluginContext* ctx, void* value) { DeviceControlRecord* dcr; bool did_setup = false; @@ -415,7 +399,7 @@ static bRC setup_record_translation(bplugin_private_context* ctx, void* value) return bRC_OK; } -static bRC handle_read_translation(bplugin_private_context* ctx, void* value) +static bRC handle_read_translation(PluginContext* ctx, void* value) { DeviceControlRecord* dcr; bool swap_record = false; @@ -452,7 +436,7 @@ static bRC handle_read_translation(bplugin_private_context* ctx, void* value) return bRC_OK; } -static bRC handle_write_translation(bplugin_private_context* ctx, void* value) +static bRC handle_write_translation(PluginContext* ctx, void* value) { DeviceControlRecord* dcr; bool swap_record = false; @@ -492,8 +476,7 @@ static bRC handle_write_translation(bplugin_private_context* ctx, void* value) /** * Setup deflate for auto deflate of data streams. */ -static bool SetupAutoDeflation(bplugin_private_context* ctx, - DeviceControlRecord* dcr) +static bool SetupAutoDeflation(PluginContext* ctx, DeviceControlRecord* dcr) { JobControlRecord* jcr = dcr->jcr; bool retval = false; @@ -589,8 +572,7 @@ static bool SetupAutoDeflation(bplugin_private_context* ctx, /** * Setup inflation for auto inflation of data streams. */ -static bool SetupAutoInflation(bplugin_private_context* ctx, - DeviceControlRecord* dcr) +static bool SetupAutoInflation(PluginContext* ctx, DeviceControlRecord* dcr) { JobControlRecord* jcr = dcr->jcr; uint32_t decompress_buf_size; @@ -624,8 +606,7 @@ static bool SetupAutoInflation(bplugin_private_context* ctx, * Perform automatic compression of certain stream types when enabled in the * config. */ -static bool AutoDeflateRecord(bplugin_private_context* ctx, - DeviceControlRecord* dcr) +static bool AutoDeflateRecord(PluginContext* ctx, DeviceControlRecord* dcr) { ser_declare; bool retval = false; @@ -785,8 +766,7 @@ static bool AutoDeflateRecord(bplugin_private_context* ctx, * Inflate (uncompress) the content of a read record and return the data as an * alternative datastream. */ -static bool AutoInflateRecord(bplugin_private_context* ctx, - DeviceControlRecord* dcr) +static bool AutoInflateRecord(PluginContext* ctx, DeviceControlRecord* dcr) { DeviceRecord *rec, *nrec; bool retval = false; diff --git a/core/src/plugins/stored/example/example-plugin-sd.cc b/core/src/plugins/stored/example/example-plugin-sd.cc index e0e246f26eb..927842a451f 100644 --- a/core/src/plugins/stored/example/example-plugin-sd.cc +++ b/core/src/plugins/stored/example/example-plugin-sd.cc @@ -36,17 +36,11 @@ #define PLUGIN_DESCRIPTION "Test Storage Daemon Plugin" /* Forward referenced functions */ -static bRC newPlugin(bplugin_private_context* ctx); -static bRC freePlugin(bplugin_private_context* ctx); -static bRC getPluginValue(bplugin_private_context* ctx, - psdVariable var, - void* value); -static bRC setPluginValue(bplugin_private_context* ctx, - psdVariable var, - void* value); -static bRC handlePluginEvent(bplugin_private_context* ctx, - bsdEvent* event, - void* value); +static bRC newPlugin(PluginContext* ctx); +static bRC freePlugin(PluginContext* ctx); +static bRC getPluginValue(PluginContext* ctx, psdVariable var, void* value); +static bRC setPluginValue(PluginContext* ctx, psdVariable var, void* value); +static bRC handlePluginEvent(PluginContext* ctx, bsdEvent* event, void* value); /* Pointers to Bareos functions */ @@ -115,7 +109,7 @@ bRC unloadPlugin() /** * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bplugin_private_context* ctx) +static bRC newPlugin(PluginContext* ctx) { int JobId = 0; bareos_core_functions->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); @@ -128,7 +122,7 @@ static bRC newPlugin(bplugin_private_context* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bplugin_private_context* ctx) +static bRC freePlugin(PluginContext* ctx) { int JobId = 0; bareos_core_functions->getBareosValue(ctx, bsdVarJobId, (void*)&JobId); @@ -139,9 +133,7 @@ static bRC freePlugin(bplugin_private_context* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bplugin_private_context* ctx, - psdVariable var, - void* value) +static bRC getPluginValue(PluginContext* ctx, psdVariable var, void* value) { printf("example-plugin-sd: getPluginValue var=%d\n", var); return bRC_OK; @@ -150,9 +142,7 @@ static bRC getPluginValue(bplugin_private_context* ctx, /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bplugin_private_context* ctx, - psdVariable var, - void* value) +static bRC setPluginValue(PluginContext* ctx, psdVariable var, void* value) { printf("example-plugin-sd: setPluginValue var=%d\n", var); return bRC_OK; @@ -161,9 +151,7 @@ static bRC setPluginValue(bplugin_private_context* ctx, /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bplugin_private_context* ctx, - bsdEvent* event, - void* value) +static bRC handlePluginEvent(PluginContext* ctx, bsdEvent* event, void* value) { char* name; switch (event->eventType) { diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index 4fa7efc80d8..de6b5787ac2 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -58,34 +58,32 @@ static const int debuglevel = 150; /* Forward referenced functions */ -static bRC newPlugin(bplugin_private_context* bareos_plugin_ctx); -static bRC freePlugin(bplugin_private_context* bareos_plugin_ctx); -static bRC getPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC newPlugin(PluginContext* bareos_plugin_ctx); +static bRC freePlugin(PluginContext* bareos_plugin_ctx); +static bRC getPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); -static bRC setPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC setPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); -static bRC handlePluginEvent(bplugin_private_context* bareos_plugin_ctx, +static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, bsdEvent* event, void* value); -static bRC parse_plugin_definition(bplugin_private_context* bareos_plugin_ctx, +static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, void* value, PoolMem& plugin_options); -static void PyErrorHandler(bplugin_private_context* bareos_plugin_ctx, - int msgtype); -static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, - void* value); -static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, +static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); +static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); +static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, void* value); -static bRC PyGetPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); -static bRC PySetPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); -static bRC PyHandlePluginEvent(bplugin_private_context* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, bsdEvent* event, void* value); @@ -188,7 +186,7 @@ bRC unloadPlugin() #endif /* Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bplugin_private_context* bareos_plugin_ctx) +static bRC newPlugin(PluginContext* bareos_plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = (struct plugin_private_context*)malloc( @@ -214,7 +212,7 @@ static bRC newPlugin(bplugin_private_context* bareos_plugin_ctx) } /* Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bplugin_private_context* bareos_plugin_ctx) +static bRC freePlugin(PluginContext* bareos_plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; @@ -239,7 +237,7 @@ static bRC freePlugin(bplugin_private_context* bareos_plugin_ctx) } -static bRC handlePluginEvent(bplugin_private_context* bareos_plugin_ctx, +static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, bsdEvent* event, void* value) { @@ -321,7 +319,7 @@ static bRC handlePluginEvent(bplugin_private_context* bareos_plugin_ctx, * * python:module_path=:module_name=:... */ -static bRC parse_plugin_definition(bplugin_private_context* bareos_plugin_ctx, +static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, void* value, PoolMem& plugin_options) { @@ -466,7 +464,7 @@ static bRC parse_plugin_definition(bplugin_private_context* bareos_plugin_ctx, * module path and the module to load. We also load the dictionary used * for looking up the Python methods. */ -static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, void* value) +static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = @@ -565,7 +563,7 @@ static bRC PyLoadModule(bplugin_private_context* bareos_plugin_ctx, void* value) * PyLoadModule() has loaded the Python module and made sure things are * operational. */ -static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, +static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, void* value) { bRC retval = bRC_Error; @@ -609,21 +607,21 @@ static bRC PyParsePluginDefinition(bplugin_private_context* bareos_plugin_ctx, return retval; } -static bRC PyGetPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PySetPluginValue(bplugin_private_context* bareos_plugin_ctx, +static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PyHandlePluginEvent(bplugin_private_context* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, bsdEvent* event, void* value) { @@ -671,8 +669,7 @@ static bRC PyHandlePluginEvent(bplugin_private_context* bareos_plugin_ctx, static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } @@ -760,8 +757,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject* pyValue; @@ -812,8 +808,7 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; @@ -835,8 +830,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; @@ -857,8 +851,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -900,8 +893,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -943,8 +935,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - bplugin_private_context* bareos_plugin_ctx = - GetPluginContextFromPythonModule(); + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } diff --git a/core/src/plugins/stored/python/python-sd.h b/core/src/plugins/stored/python/python-sd.h index ec14f673041..c3216931732 100644 --- a/core/src/plugins/stored/python/python-sd.h +++ b/core/src/plugins/stored/python/python-sd.h @@ -83,13 +83,13 @@ static PyMethodDef Methods[] = { {NULL, NULL, 0, NULL}}; -static void* bareos_plugin_context = NULL; +static void* bareos_PluginContext = NULL; // MOD_INIT(PYTHON_MODULE_NAME) MOD_INIT(bareossd) { - /* bareos_plugin_context holds the bplugin_private_context instead of passing - * to Python and extracting it back like it was before. bareos_plugin_context + /* bareos_PluginContext holds the PluginContext instead of passing + * to Python and extracting it back like it was before. bareos_PluginContext * needs to be set after loading the PYTHON_MODULE_NAME binary python module * and will be used for all calls. */ @@ -98,8 +98,8 @@ MOD_INIT(bareossd) /* Pointer Capsules to avoid context transfer back and forth */ PyObject* PyModulePluginContext = - PyCapsule_New((void*)&bareos_plugin_context, - PYTHON_MODULE_NAME_QUOTED ".bplugin_private_context", NULL); + PyCapsule_New((void*)&bareos_PluginContext, + PYTHON_MODULE_NAME_QUOTED ".PluginContext", NULL); if (!PyModulePluginContext) { printf(PYTHON_MODULE_NAME_QUOTED ": PyCapsule_New failed\n"); @@ -109,7 +109,7 @@ MOD_INIT(bareossd) MOD_DEF(m, PYTHON_MODULE_NAME_QUOTED, NULL, Methods) if (PyModulePluginContext) { - PyModule_AddObject(m, "bplugin_private_context", PyModulePluginContext); + PyModule_AddObject(m, "PluginContext", PyModulePluginContext); } else { printf(PYTHON_MODULE_NAME_QUOTED ":PyModule_AddObject failed\n"); return MOD_ERROR_VAL; diff --git a/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc b/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc index e0a5d486811..e4104bfd5ca 100644 --- a/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc +++ b/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc @@ -80,17 +80,11 @@ using namespace storagedaemon; /** * Forward referenced functions */ -static bRC newPlugin(bplugin_private_context* ctx); -static bRC freePlugin(bplugin_private_context* ctx); -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC handlePluginEvent(bplugin_private_context* ctx, - bsdEvent* event, - void* value); +static bRC newPlugin(PluginContext* ctx); +static bRC freePlugin(PluginContext* ctx); +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC handlePluginEvent(PluginContext* ctx, bsdEvent* event, void* value); static bRC do_set_scsi_encryption_key(void* value); static bRC do_clear_scsi_encryption_key(void* value); static bRC handle_read_error(void* value); @@ -165,7 +159,7 @@ bRC unloadPlugin() { return bRC_OK; } * * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bplugin_private_context* ctx) +static bRC newPlugin(PluginContext* ctx) { int JobId = 0; @@ -210,7 +204,7 @@ static bRC newPlugin(bplugin_private_context* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bplugin_private_context* ctx) +static bRC freePlugin(PluginContext* ctx) { int JobId = 0; @@ -223,9 +217,7 @@ static bRC freePlugin(bplugin_private_context* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value) { Dmsg1(debuglevel, "scsicrypto-sd: getPluginValue var=%d\n", var); @@ -235,9 +227,7 @@ static bRC getPluginValue(bplugin_private_context* ctx, /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value) { Dmsg1(debuglevel, "scsicrypto-sd: setPluginValue var=%d\n", var); @@ -247,9 +237,7 @@ static bRC setPluginValue(bplugin_private_context* ctx, /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bplugin_private_context* ctx, - bsdEvent* event, - void* value) +static bRC handlePluginEvent(PluginContext* ctx, bsdEvent* event, void* value) { switch (event->eventType) { case bsdEventLabelRead: diff --git a/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc b/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc index ddd7e4ac166..218e78711d9 100644 --- a/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc +++ b/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc @@ -43,17 +43,11 @@ using namespace storagedaemon; /** * Forward referenced functions */ -static bRC newPlugin(bplugin_private_context* ctx); -static bRC freePlugin(bplugin_private_context* ctx); -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC handlePluginEvent(bplugin_private_context* ctx, - bsdEvent* event, - void* value); +static bRC newPlugin(PluginContext* ctx); +static bRC freePlugin(PluginContext* ctx); +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC handlePluginEvent(PluginContext* ctx, bsdEvent* event, void* value); static bRC handle_tapealert_readout(void* value); /** @@ -124,7 +118,7 @@ bRC unloadPlugin() { return bRC_OK; } * * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bplugin_private_context* ctx) +static bRC newPlugin(PluginContext* ctx) { int JobId = 0; @@ -144,7 +138,7 @@ static bRC newPlugin(bplugin_private_context* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bplugin_private_context* ctx) +static bRC freePlugin(PluginContext* ctx) { int JobId = 0; @@ -157,9 +151,7 @@ static bRC freePlugin(bplugin_private_context* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value) { Dmsg1(debuglevel, "scsitapealert-sd: getPluginValue var=%d\n", var); @@ -169,9 +161,7 @@ static bRC getPluginValue(bplugin_private_context* ctx, /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value) { Dmsg1(debuglevel, "scsitapealert-sd: setPluginValue var=%d\n", var); @@ -181,9 +171,7 @@ static bRC setPluginValue(bplugin_private_context* ctx, /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bplugin_private_context* ctx, - bsdEvent* event, - void* value) +static bRC handlePluginEvent(PluginContext* ctx, bsdEvent* event, void* value) { switch (event->eventType) { case bsdEventLabelVerified: diff --git a/core/src/stored/sd_plugins.cc b/core/src/stored/sd_plugins.cc index b9fe3875aa8..59060618040 100644 --- a/core/src/stored/sd_plugins.cc +++ b/core/src/stored/sd_plugins.cc @@ -52,27 +52,19 @@ static alist* sd_plugin_list = NULL; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; /* Forward referenced functions */ -static bRC bareosGetValue(bplugin_private_context* ctx, - bsdrVariable var, - void* value); -static bRC bareosSetValue(bplugin_private_context* ctx, - bsdwVariable var, - void* value); -static bRC bareosRegisterEvents(bplugin_private_context* ctx, - int nr_events, - ...); -static bRC bareosUnRegisterEvents(bplugin_private_context* ctx, - int nr_events, - ...); -static bRC bareosGetInstanceCount(bplugin_private_context* ctx, int* ret); -static bRC bareosJobMsg(bplugin_private_context* ctx, +static bRC bareosGetValue(PluginContext* ctx, bsdrVariable var, void* value); +static bRC bareosSetValue(PluginContext* ctx, bsdwVariable var, void* value); +static bRC bareosRegisterEvents(PluginContext* ctx, int nr_events, ...); +static bRC bareosUnRegisterEvents(PluginContext* ctx, int nr_events, ...); +static bRC bareosGetInstanceCount(PluginContext* ctx, int* ret); +static bRC bareosJobMsg(PluginContext* ctx, const char* file, int line, int type, utime_t mtime, const char* fmt, ...); -static bRC bareosDebugMsg(bplugin_private_context* ctx, +static bRC bareosDebugMsg(PluginContext* ctx, const char* file, int line, int level, @@ -116,8 +108,7 @@ struct b_plugin_ctx { Plugin* plugin; /* pointer to plugin of which this is an instance off */ }; -static inline bool IsEventEnabled(bplugin_private_context* ctx, - bsdEventType eventType) +static inline bool IsEventEnabled(PluginContext* ctx, bsdEventType eventType) { b_plugin_ctx* b_ctx; if (!ctx) { return false; } @@ -127,7 +118,7 @@ static inline bool IsEventEnabled(bplugin_private_context* ctx, return BitIsSet(eventType, b_ctx->events); } -static inline bool IsPluginDisabled(bplugin_private_context* ctx) +static inline bool IsPluginDisabled(PluginContext* ctx) { b_plugin_ctx* b_ctx; if (!ctx) { return true; } @@ -136,7 +127,7 @@ static inline bool IsPluginDisabled(bplugin_private_context* ctx) return b_ctx->disabled; } -static bool IsCtxGood(bplugin_private_context* ctx, +static bool IsCtxGood(PluginContext* ctx, JobControlRecord*& jcr, b_plugin_ctx*& bctx) { @@ -249,7 +240,7 @@ char* edit_device_codes(DeviceControlRecord* dcr, static inline bool trigger_plugin_event(JobControlRecord* jcr, bsdEventType eventType, bsdEvent* event, - bplugin_private_context* ctx, + PluginContext* ctx, void* value, alist* plugin_ctx_list, int* index, @@ -354,7 +345,7 @@ bRC GeneratePluginEvent(JobControlRecord* jcr, * See if we need to trigger the loaded plugins in reverse order. */ if (reverse) { - bplugin_private_context* ctx; + PluginContext* ctx; foreach_alist_rindex (i, ctx, plugin_ctx_list) { if (trigger_plugin_event(jcr, eventType, &event, ctx, value, @@ -363,7 +354,7 @@ bRC GeneratePluginEvent(JobControlRecord* jcr, } } } else { - bplugin_private_context* ctx; + PluginContext* ctx; foreach_alist_index (i, ctx, plugin_ctx_list) { if (trigger_plugin_event(jcr, eventType, &event, ctx, value, @@ -500,11 +491,11 @@ static bool IsPluginCompatible(Plugin* plugin) /** * Instantiate a new plugin instance. */ -static inline bplugin_private_context* instantiate_plugin(JobControlRecord* jcr, - Plugin* plugin, - uint32_t instance) +static inline PluginContext* instantiate_plugin(JobControlRecord* jcr, + Plugin* plugin, + uint32_t instance) { - bplugin_private_context* ctx; + PluginContext* ctx; b_plugin_ctx* b_ctx; b_ctx = (b_plugin_ctx*)malloc(sizeof(b_plugin_ctx)); @@ -515,7 +506,7 @@ static inline bplugin_private_context* instantiate_plugin(JobControlRecord* jcr, Dmsg2(debuglevel, "Instantiate dir-plugin_ctx_list=%p JobId=%d\n", jcr->plugin_ctx_list, jcr->JobId); - ctx = (bplugin_private_context*)malloc(sizeof(bplugin_private_context)); + ctx = (PluginContext*)malloc(sizeof(PluginContext)); ctx->instance = instance; ctx->plugin = plugin; ctx->core_private_context = (void*)b_ctx; @@ -536,7 +527,7 @@ void DispatchNewPluginOptions(JobControlRecord* jcr) { int i, j, len; Plugin* plugin; - bplugin_private_context* ctx = nullptr; + PluginContext* ctx = nullptr; uint32_t instance; bsdEvent event; bsdEventType eventType; @@ -664,7 +655,7 @@ void NewPlugins(JobControlRecord* jcr) */ void FreePlugins(JobControlRecord* jcr) { - bplugin_private_context* ctx = nullptr; + PluginContext* ctx = nullptr; if (!sd_plugin_list || !jcr->plugin_ctx_list) { return; } @@ -688,9 +679,7 @@ void FreePlugins(JobControlRecord* jcr) * * ============================================================== */ -static bRC bareosGetValue(bplugin_private_context* ctx, - bsdrVariable var, - void* value) +static bRC bareosGetValue(PluginContext* ctx, bsdrVariable var, void* value) { JobControlRecord* jcr = NULL; bRC retval = bRC_OK; @@ -822,9 +811,7 @@ static bRC bareosGetValue(bplugin_private_context* ctx, return retval; } -static bRC bareosSetValue(bplugin_private_context* ctx, - bsdwVariable var, - void* value) +static bRC bareosSetValue(PluginContext* ctx, bsdwVariable var, void* value) { JobControlRecord* jcr; if (!value || !ctx) { return bRC_Error; } @@ -850,9 +837,7 @@ static bRC bareosSetValue(bplugin_private_context* ctx, return bRC_OK; } -static bRC bareosRegisterEvents(bplugin_private_context* ctx, - int nr_events, - ...) +static bRC bareosRegisterEvents(PluginContext* ctx, int nr_events, ...) { int i; va_list args; @@ -871,9 +856,7 @@ static bRC bareosRegisterEvents(bplugin_private_context* ctx, return bRC_OK; } -static bRC bareosUnRegisterEvents(bplugin_private_context* ctx, - int nr_events, - ...) +static bRC bareosUnRegisterEvents(PluginContext* ctx, int nr_events, ...) { int i; va_list args; @@ -892,11 +875,11 @@ static bRC bareosUnRegisterEvents(bplugin_private_context* ctx, return bRC_OK; } -static bRC bareosGetInstanceCount(bplugin_private_context* ctx, int* ret) +static bRC bareosGetInstanceCount(PluginContext* ctx, int* ret) { int cnt; JobControlRecord *jcr, *njcr; - bplugin_private_context* nctx; + PluginContext* nctx; b_plugin_ctx* bctx; bRC retval = bRC_Error; @@ -923,7 +906,7 @@ static bRC bareosGetInstanceCount(bplugin_private_context* ctx, int* ret) return retval; } -static bRC bareosJobMsg(bplugin_private_context* ctx, +static bRC bareosJobMsg(PluginContext* ctx, const char* file, int line, int type, @@ -949,7 +932,7 @@ static bRC bareosJobMsg(bplugin_private_context* ctx, return bRC_OK; } -static bRC bareosDebugMsg(bplugin_private_context* ctx, +static bRC bareosDebugMsg(PluginContext* ctx, const char* file, int line, int level, diff --git a/core/src/stored/sd_plugins.h b/core/src/stored/sd_plugins.h index b50efdb7ae1..e702de41e0c 100644 --- a/core/src/stored/sd_plugins.h +++ b/core/src/stored/sd_plugins.h @@ -146,25 +146,19 @@ struct DeviceRecord; typedef struct s_sdbareosFuncs { uint32_t size; uint32_t version; - bRC (*registerBareosEvents)(bplugin_private_context* ctx, int nr_events, ...); - bRC (*unregisterBareosEvents)(bplugin_private_context* ctx, - int nr_events, - ...); - bRC (*getInstanceCount)(bplugin_private_context* ctx, int* ret); - bRC (*getBareosValue)(bplugin_private_context* ctx, - bsdrVariable var, - void* value); - bRC (*setBareosValue)(bplugin_private_context* ctx, - bsdwVariable var, - void* value); - bRC (*JobMessage)(bplugin_private_context* ctx, + bRC (*registerBareosEvents)(PluginContext* ctx, int nr_events, ...); + bRC (*unregisterBareosEvents)(PluginContext* ctx, int nr_events, ...); + bRC (*getInstanceCount)(PluginContext* ctx, int* ret); + bRC (*getBareosValue)(PluginContext* ctx, bsdrVariable var, void* value); + bRC (*setBareosValue)(PluginContext* ctx, bsdwVariable var, void* value); + bRC (*JobMessage)(PluginContext* ctx, const char* file, int line, int type, utime_t mtime, const char* fmt, ...); - bRC (*DebugMessage)(bplugin_private_context* ctx, + bRC (*DebugMessage)(PluginContext* ctx, const char* file, int line, int level, @@ -217,17 +211,11 @@ typedef enum typedef struct s_sdpluginFuncs { uint32_t size; uint32_t version; - bRC (*newPlugin)(bplugin_private_context* ctx); - bRC (*freePlugin)(bplugin_private_context* ctx); - bRC (*getPluginValue)(bplugin_private_context* ctx, - pVariable var, - void* value); - bRC (*setPluginValue)(bplugin_private_context* ctx, - pVariable var, - void* value); - bRC (*handlePluginEvent)(bplugin_private_context* ctx, - bsdEvent* event, - void* value); + bRC (*newPlugin)(PluginContext* ctx); + bRC (*freePlugin)(PluginContext* ctx); + bRC (*getPluginValue)(PluginContext* ctx, pVariable var, void* value); + bRC (*setPluginValue)(PluginContext* ctx, pVariable var, void* value); + bRC (*handlePluginEvent)(PluginContext* ctx, bsdEvent* event, void* value); } psdFuncs; #define SdplugFunc(plugin) ((psdFuncs*)(plugin->plugin_functions)) diff --git a/core/src/win32/plugins/filed/mssqlvdi-fd.cc b/core/src/win32/plugins/filed/mssqlvdi-fd.cc index 137b7221c4b..d2b551ea5ba 100644 --- a/core/src/win32/plugins/filed/mssqlvdi-fd.cc +++ b/core/src/win32/plugins/filed/mssqlvdi-fd.cc @@ -90,31 +90,24 @@ static const int debuglevel = 150; /** * Forward referenced functions */ -static bRC newPlugin(bplugin_private_context* ctx); -static bRC freePlugin(bplugin_private_context* ctx); -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value); -static bRC handlePluginEvent(bplugin_private_context* ctx, - bEvent* event, - void* value); -static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp); -static bRC endBackupFile(bplugin_private_context* ctx); -static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io); -static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd); -static bRC endRestoreFile(bplugin_private_context* ctx); -static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp); -static bRC setFileAttributes(bplugin_private_context* ctx, - struct restore_pkt* rp); -static bRC checkFile(bplugin_private_context* ctx, char* fname); - -static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value); -static bRC end_restore_job(bplugin_private_context* ctx, void* value); +static bRC newPlugin(PluginContext* ctx); +static bRC freePlugin(PluginContext* ctx); +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value); +static bRC handlePluginEvent(PluginContext* ctx, bEvent* event, void* value); +static bRC startBackupFile(PluginContext* ctx, struct save_pkt* sp); +static bRC endBackupFile(PluginContext* ctx); +static bRC pluginIO(PluginContext* ctx, struct io_pkt* io); +static bRC startRestoreFile(PluginContext* ctx, const char* cmd); +static bRC endRestoreFile(PluginContext* ctx); +static bRC createFile(PluginContext* ctx, struct restore_pkt* rp); +static bRC setFileAttributes(PluginContext* ctx, struct restore_pkt* rp); +static bRC checkFile(PluginContext* ctx, char* fname); + +static bRC parse_plugin_definition(PluginContext* ctx, void* value); +static bRC end_restore_job(PluginContext* ctx, void* value); static void CloseVdiDeviceset(struct plugin_ctx* p_ctx); -static bool adoReportError(bplugin_private_context* ctx); +static bool adoReportError(PluginContext* ctx); /** * Pointers to Bareos functions @@ -265,7 +258,7 @@ bRC unloadPlugin() { return bRC_OK; } * * Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(bplugin_private_context* ctx) +static bRC newPlugin(PluginContext* ctx) { HRESULT hr; plugin_ctx* p_ctx; @@ -296,7 +289,7 @@ static bRC newPlugin(bplugin_private_context* ctx) /** * Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(bplugin_private_context* ctx) +static bRC freePlugin(PluginContext* ctx) { plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; if (!p_ctx) { return bRC_Error; } @@ -358,9 +351,7 @@ static bRC freePlugin(bplugin_private_context* ctx) /** * Return some plugin value (none defined) */ -static bRC getPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value) { return bRC_OK; } @@ -368,9 +359,7 @@ static bRC getPluginValue(bplugin_private_context* ctx, /** * Set a plugin value (none defined) */ -static bRC setPluginValue(bplugin_private_context* ctx, - pVariable var, - void* value) +static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value) { return bRC_OK; } @@ -378,9 +367,7 @@ static bRC setPluginValue(bplugin_private_context* ctx, /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(bplugin_private_context* ctx, - bEvent* event, - void* value) +static bRC handlePluginEvent(PluginContext* ctx, bEvent* event, void* value) { bRC retval; plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -436,7 +423,7 @@ static bRC handlePluginEvent(bplugin_private_context* ctx, /** * Start the backup of a specific file */ -static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) +static bRC startBackupFile(PluginContext* ctx, struct save_pkt* sp) { time_t now; PoolMem fname(PM_NAME); @@ -501,7 +488,7 @@ static bRC startBackupFile(bplugin_private_context* ctx, struct save_pkt* sp) /** * Done with backup of this file */ -static bRC endBackupFile(bplugin_private_context* ctx) +static bRC endBackupFile(PluginContext* ctx) { /* * We would return bRC_More if we wanted startBackupFile to be called again to @@ -589,7 +576,7 @@ static inline void SetString(char** destination, char* value) * * mssqlvdi:instance=:database=: */ -static bRC parse_plugin_definition(bplugin_private_context* ctx, void* value) +static bRC parse_plugin_definition(PluginContext* ctx, void* value) { int i; bool keep_existing; @@ -790,7 +777,7 @@ static void CloseVdiDeviceset(plugin_ctx* p_ctx) /** * Generic COM error reporting function. */ -static void comReportError(bplugin_private_context* ctx, HRESULT hrErr) +static void comReportError(PluginContext* ctx, HRESULT hrErr) { IErrorInfo* pErrorInfo; BSTR pSource = NULL; @@ -850,7 +837,7 @@ static void comReportError(bplugin_private_context* ctx, HRESULT hrErr) /** * Retrieve errors from ADO Connection. */ -static bool adoGetErrors(bplugin_private_context* ctx, +static bool adoGetErrors(PluginContext* ctx, _ADOConnection* adoConnection, PoolMem& ado_errorstr) { @@ -928,7 +915,7 @@ static bool adoGetErrors(bplugin_private_context* ctx, /** * Print errors (when available) collected by adoThreadSetError function. */ -static bool adoReportError(bplugin_private_context* ctx) +static bool adoReportError(PluginContext* ctx) { plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -949,8 +936,7 @@ static bool adoReportError(bplugin_private_context* ctx) * Retrieve errors from ADO Connection when running the query in a separate * thread. */ -static void adoThreadSetError(bplugin_private_context* ctx, - _ADOConnection* adoConnection) +static void adoThreadSetError(PluginContext* ctx, _ADOConnection* adoConnection) { int cancel_type; PoolMem ado_errorstr(PM_NAME); @@ -1025,7 +1011,7 @@ static void* adoThread(void* data) { HRESULT hr; adoThreadContext ado_ctx; - bplugin_private_context* ctx = (bplugin_private_context*)data; + PluginContext* ctx = (PluginContext*)data; plugin_ctx* p_ctx = (struct plugin_ctx*)ctx->plugin_private_context; memset(&ado_ctx, 0, sizeof(ado_ctx)); @@ -1094,7 +1080,7 @@ static void* adoThread(void* data) /** * Create a connection string for connecting to the master database. */ -static void SetAdoConnectString(bplugin_private_context* ctx) +static void SetAdoConnectString(PluginContext* ctx) { PoolMem ado_connect_string(PM_NAME); plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -1132,7 +1118,7 @@ static void SetAdoConnectString(bplugin_private_context* ctx) * Generate a valid connect string and the backup command we should execute * in the separate database controling thread. */ -static inline void PerformAdoBackup(bplugin_private_context* ctx) +static inline void PerformAdoBackup(PluginContext* ctx) { plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; PoolMem ado_connect_string(PM_NAME), ado_query(PM_NAME); @@ -1183,7 +1169,7 @@ static inline void PerformAdoBackup(bplugin_private_context* ctx) * Generate a valid connect string and the restore command we should execute * in the separate database controlling thread. */ -static inline void perform_aDoRestore(bplugin_private_context* ctx) +static inline void perform_aDoRestore(PluginContext* ctx) { PoolMem ado_query(PM_NAME), temp(PM_NAME); POOLMEM* vdsname; @@ -1255,7 +1241,7 @@ static inline void perform_aDoRestore(bplugin_private_context* ctx) /** * Run a query not in a separate thread. */ -static inline bool RunAdoQuery(bplugin_private_context* ctx, const char* query) +static inline bool RunAdoQuery(PluginContext* ctx, const char* query) { bool retval = false; HRESULT hr; @@ -1330,7 +1316,7 @@ static inline bool RunAdoQuery(bplugin_private_context* ctx, const char* query) /** * Automatically recover the database at the end of the whole restore process. */ -static inline bool PerformAdoRecover(bplugin_private_context* ctx) +static inline bool PerformAdoRecover(PluginContext* ctx) { PoolMem recovery_query(PM_NAME); plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -1344,8 +1330,7 @@ static inline bool PerformAdoRecover(bplugin_private_context* ctx) /** * Setup a VDI device for performing a backup or restore operation. */ -static inline bool SetupVdiDevice(bplugin_private_context* ctx, - struct io_pkt* io) +static inline bool SetupVdiDevice(PluginContext* ctx, struct io_pkt* io) { int status; HRESULT hr = NOERROR; @@ -1514,7 +1499,7 @@ static inline bool SetupVdiDevice(bplugin_private_context* ctx, /** * Perform an I/O operation to a file as part of a restore. */ -static inline bool PerformFileIo(bplugin_private_context* ctx, +static inline bool PerformFileIo(PluginContext* ctx, struct io_pkt* io, DWORD* completionCode) { @@ -1585,7 +1570,7 @@ static inline bool PerformFileIo(bplugin_private_context* ctx, /** * Perform an I/O operation to a virtual device as part of a backup or restore. */ -static inline bool PerformVdiIo(bplugin_private_context* ctx, +static inline bool PerformVdiIo(PluginContext* ctx, struct io_pkt* io, DWORD* completionCode) { @@ -1684,8 +1669,7 @@ static inline bool PerformVdiIo(bplugin_private_context* ctx, /** * End of I/O tear down the VDI and check if everything did go to plan. */ -static inline bool TearDownVdiDevice(bplugin_private_context* ctx, - struct io_pkt* io) +static inline bool TearDownVdiDevice(PluginContext* ctx, struct io_pkt* io) { HRESULT hr = NOERROR; VDC_Command* cmd; @@ -1740,7 +1724,7 @@ static inline bool TearDownVdiDevice(bplugin_private_context* ctx, /** * Bareos is calling us to do the actual I/O */ -static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) +static bRC pluginIO(PluginContext* ctx, struct io_pkt* io) { DWORD completionCode = ERROR_BAD_ENVIRONMENT; plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -1811,7 +1795,7 @@ static bRC pluginIO(bplugin_private_context* ctx, struct io_pkt* io) /** * See if we need to do any postprocessing after the restore. */ -static bRC end_restore_job(bplugin_private_context* ctx, void* value) +static bRC end_restore_job(PluginContext* ctx, void* value) { bRC retval = bRC_OK; plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -1833,7 +1817,7 @@ static bRC end_restore_job(bplugin_private_context* ctx, void* value) * Bareos is notifying us that a plugin name string was found, * and passing us the plugin command, so we can prepare for a restore. */ -static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) +static bRC startRestoreFile(PluginContext* ctx, const char* cmd) { return bRC_OK; } @@ -1842,7 +1826,7 @@ static bRC startRestoreFile(bplugin_private_context* ctx, const char* cmd) * Bareos is notifying us that the plugin data has terminated, * so the restore for this particular file is done. */ -static bRC endRestoreFile(bplugin_private_context* ctx) { return bRC_OK; } +static bRC endRestoreFile(PluginContext* ctx) { return bRC_OK; } /** * This is called during restore to create the file (if necessary) We must @@ -1854,7 +1838,7 @@ static bRC endRestoreFile(bplugin_private_context* ctx) { return bRC_OK; } * CF_CREATED -- created, but no content to extract (typically directories) * CF_CORE -- let bareos core create the file */ -static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) +static bRC createFile(PluginContext* ctx, struct restore_pkt* rp) { plugin_ctx* p_ctx = (plugin_ctx*)ctx->plugin_private_context; @@ -1875,8 +1859,7 @@ static bRC createFile(bplugin_private_context* ctx, struct restore_pkt* rp) * We will get here if the File is a directory after everything is written in * the directory. */ -static bRC setFileAttributes(bplugin_private_context* ctx, - struct restore_pkt* rp) +static bRC setFileAttributes(PluginContext* ctx, struct restore_pkt* rp) { return bRC_OK; } @@ -1884,9 +1867,6 @@ static bRC setFileAttributes(bplugin_private_context* ctx, /** * When using Incremental dump, all previous dumps are necessary */ -static bRC checkFile(bplugin_private_context* ctx, char* fname) -{ - return bRC_OK; -} +static bRC checkFile(PluginContext* ctx, char* fname) { return bRC_OK; } } /* namespace filedaemon */ From ac59746ac1278acaac320bcb04662a9e0f4e4058 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 30 Apr 2020 10:53:44 +0200 Subject: [PATCH 067/341] cmake: introduced dependency on bareos python modules --- core/src/plugins/dird/CMakeLists.txt | 12 +- core/src/plugins/dird/python/bareosdir.cc | 955 ++++++++++++++++++++++ core/src/plugins/filed/CMakeLists.txt | 3 +- core/src/plugins/filed/python/bareosfd.cc | 239 +++--- core/src/plugins/stored/CMakeLists.txt | 1 + 5 files changed, 1082 insertions(+), 128 deletions(-) create mode 100644 core/src/plugins/dird/python/bareosdir.cc diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index 5abc8d5ca39..eb9a34abbc4 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -36,6 +36,7 @@ if(HAVE_PYTHON) set_target_properties(python-dir PROPERTIES PREFIX "") install(TARGETS python-dir DESTINATION ${plugindir}) target_link_libraries(python-dir ${PYTHON_LIBRARIES} bareos) + add_dependencies(python-dir bareosdir) set(PYFILES python/pyfiles/bareos-dir.py.template python/pyfiles/bareos-dir-class-plugin.py @@ -49,15 +50,18 @@ endif() if(HAVE_PYTHON AND NOT HAVE_WIN32) configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) add_custom_command( - TARGET python-dir - POST_BUILD - COMMENT "building python module pythonmodules/bareosdir.so" + OUTPUT pythonmodules/bareosdir.so + MAIN_DEPENDENCY ./python/bareosdir.cc + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py COMMAND ${PYTHON_EXECUTABLE} python/setup.py build COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build DEPENDS python-dir + # COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build DEPENDS python-dir + COMMENT "building python module pythonmodules/bareosdir.so" ) + add_custom_target(bareosdir DEPENDS pythonmodules/bareosdir.so) + add_test(NAME bareosdir-python-module COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosdir_test.py diff --git a/core/src/plugins/dird/python/bareosdir.cc b/core/src/plugins/dird/python/bareosdir.cc new file mode 100644 index 00000000000..c4cd6865e79 --- /dev/null +++ b/core/src/plugins/dird/python/bareosdir.cc @@ -0,0 +1,955 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2011-2014 Planets Communications B.V. + Copyright (C) 2013-2020 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation, which is + listed in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +/* + * Marco van Wieringen, August 2012 + */ +/** + * @file + * Python Director Plugin program + */ + +#if defined(HAVE_WIN32) +#include "include/bareos.h" +#include +#else +#include +#include "include/bareos.h" +#endif +#include "dird/dird.h" + +#if (PY_VERSION_HEX < 0x02060000) +#error "Need at least Python version 2.6 or newer" +#endif + +#include "python-dir.h" +#include "lib/edit.h" + +namespace directordaemon { + +static const int debuglevel = 150; + +#define PLUGIN_LICENSE "Bareos AGPLv3" +#define PLUGIN_AUTHOR "Marco van Wieringen" +#define PLUGIN_DATE "October 2013" +#define PLUGIN_VERSION "3" +#define PLUGIN_DESCRIPTION "Python Director Daemon Plugin" +#define PLUGIN_USAGE \ + "python:instance=:module_path=:module_" \ + "name=" + + +/* Forward referenced functions */ +static bRC newPlugin(PluginContext* bareos_plugin_ctx); +static bRC freePlugin(PluginContext* bareos_plugin_ctx); +static bRC getPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC setPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, + bDirEvent* event, + void* value); +static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, + void* value, + PoolMem& plugin_options); + +static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); +static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); +static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, + void* value); +static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, + bDirEvent* event, + void* value); + +/* Pointers to Bareos functions */ +static bDirFuncs* bareos_core_functions = NULL; +static bDirInfo* bareos_plugin_interface_version = NULL; + +static PluginInformation pluginInfo = { + sizeof(pluginInfo), DIR_PLUGIN_INTERFACE_VERSION, + DIR_PLUGIN_MAGIC, PLUGIN_LICENSE, + PLUGIN_AUTHOR, PLUGIN_DATE, + PLUGIN_VERSION, PLUGIN_DESCRIPTION, + PLUGIN_USAGE}; + +static pDirFuncs pluginFuncs = { + sizeof(pluginFuncs), DIR_PLUGIN_INTERFACE_VERSION, + + /* Entry points into plugin */ + newPlugin, /* new plugin instance */ + freePlugin, /* free plugin instance */ + getPluginValue, setPluginValue, handlePluginEvent}; + +/** + * Plugin private context + */ +struct plugin_private_context { + int64_t instance; /* Instance number of plugin */ + bool python_loaded; /* Plugin has python module loaded ? */ + bool python_path_set; /* Python plugin search path is set ? */ + char* module_path; /* Plugin Module Path */ + char* module_name; /* Plugin Module Name */ + PyThreadState* + interpreter; /* Python interpreter for this instance of the plugin */ + PyObject* pModule; /* Python Module entry point */ + PyObject* pyModuleFunctionsDict; /* Python Dictionary */ +}; + +/** + * We don't actually use this but we need it to tear down the + * final python interpreter on unload of the plugin. Each instance of + * the plugin get its own interpreter. + */ +static PyThreadState* mainThreadState; + +/* functions common to all plugins */ +#include "plugins/python_plugins_common.inc" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * loadPlugin() and unloadPlugin() are entry points that are + * exported, so Bareos can directly call these two entry points + * they are common to all Bareos plugins. + * + * External entry point called by Bareos to "load" the plugin + */ +bRC loadPlugin(bDirInfo* lbareos_plugin_interface_version, + bDirFuncs* lbareos_core_functions, + PluginInformation** plugin_information, + pDirFuncs** plugin_functions) +{ + bareos_core_functions = + lbareos_core_functions; /* Set Bareos funct pointers */ + bareos_plugin_interface_version = lbareos_plugin_interface_version; + + *plugin_information = &pluginInfo; /* Return pointer to our info */ + *plugin_functions = &pluginFuncs; /* Return pointer to our functions */ + + /* Setup Python */ +#if PY_MAJOR_VERSION >= 3 + PyImport_AppendInittab("bareosdir", &PyInit_bareosdir); +#else + PyImport_AppendInittab("bareosdir", initbareosdir); +#endif + Py_InitializeEx(0); + PyEval_InitThreads(); + mainThreadState = PyEval_SaveThread(); + + return bRC_OK; +} + +/** + * External entry point to unload the plugin + */ +bRC unloadPlugin() +{ + /* + * Terminate Python + */ + PyEval_RestoreThread(mainThreadState); + Py_Finalize(); + + return bRC_OK; +} + +#ifdef __cplusplus +} +#endif + +/* Create a new instance of the plugin i.e. allocate our private storage */ +static bRC newPlugin(PluginContext* bareos_plugin_ctx) +{ + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)malloc( + sizeof(struct plugin_private_context)); + if (!plugin_priv_ctx) { return bRC_Error; } + memset(plugin_priv_ctx, 0, sizeof(struct plugin_private_context)); + bareos_plugin_ctx->plugin_private_context = + (void*)plugin_priv_ctx; /* set our context pointer */ + + /* For each plugin instance we instantiate a new Python interpreter. */ + PyEval_AcquireThread(mainThreadState); + plugin_priv_ctx->interpreter = Py_NewInterpreter(); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + + /* + * Always register some events the python plugin itself can register + * any other events it is interested in. + */ + bareos_core_functions->registerBareosEvents(bareos_plugin_ctx, 1, + bDirEventNewPluginOptions); + + return bRC_OK; +} + +/* Free a plugin instance, i.e. release our private storage */ +static bRC freePlugin(PluginContext* bareos_plugin_ctx) +{ + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + + if (!plugin_priv_ctx) { return bRC_Error; } + + /* + * Stop any sub interpreter started per plugin instance. + */ + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + + + if (plugin_priv_ctx->pModule) { Py_DECREF(plugin_priv_ctx->pModule); } + + Py_EndInterpreter(plugin_priv_ctx->interpreter); + PyEval_ReleaseLock(); + + free(plugin_priv_ctx); + bareos_plugin_ctx->plugin_private_context = NULL; + + return bRC_OK; +} + + +static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, + bDirEvent* event, + void* value) +{ + bRC retval = bRC_Error; + bool event_dispatched = false; + PoolMem plugin_options(PM_FNAME); + plugin_private_context* plugin_priv_ctx = + (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + + if (!plugin_priv_ctx) { goto bail_out; } + + /* + * First handle some events internally before calling python if it + * want to do some special handling on the event triggered. + */ + switch (event->eventType) { + case bDirEventNewPluginOptions: + event_dispatched = true; + retval = + parse_plugin_definition(bareos_plugin_ctx, value, plugin_options); + break; + default: + break; + } + + /* + * See if we have been triggered in the previous switch if not we have to + * always dispatch the event. If we already processed the event internally + * we only do a dispatch to the python entry point when that internal + * processing was successful (e.g. retval == bRC_OK). + */ + if (!event_dispatched || retval == bRC_OK) { + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + + /* + * Now dispatch the event to Python. + * First the calls that need special handling. + */ + switch (event->eventType) { + case bDirEventNewPluginOptions: + /* + * See if we already loaded the Python modules. + */ + if (!plugin_priv_ctx->python_loaded) { + retval = PyLoadModule(bareos_plugin_ctx, plugin_options.c_str()); + } + + /* Only try to call when the loading succeeded. */ + if (retval == bRC_OK) { + retval = PyParsePluginDefinition(bareos_plugin_ctx, + plugin_options.c_str()); + } + break; + default: + /* + * Handle the generic events e.g. the ones which are just passed on. + * We only try to call Python when we loaded the right module until + * that time we pretend the call succeeded. + */ + if (plugin_priv_ctx->python_loaded) { + retval = PyHandlePluginEvent(bareos_plugin_ctx, event, value); + } else { + retval = bRC_OK; + } + break; + } + + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + } + +bail_out: + return retval; +} + + +/** + * Parse the plugin definition passed in. + * + * The definition is in this form: + * + * python:module_path=:module_name=:... + */ +static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, + void* value, + PoolMem& plugin_options) +{ + bool found; + int i, cnt; + PoolMem plugin_definition(PM_FNAME); + char *bp, *argument, *argument_value; + plugin_private_context* plugin_priv_ctx = + (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + + if (!value) { return bRC_Error; } + + /* + * Parse the plugin definition. + * Make a private copy of the whole string. + */ + PmStrcpy(plugin_definition, (char*)value); + + bp = strchr(plugin_definition.c_str(), ':'); + if (!bp) { + Jmsg(bareos_plugin_ctx, M_FATAL, + "python-dir: Illegal plugin definition %s\n", + plugin_definition.c_str()); + Dmsg(bareos_plugin_ctx, debuglevel, + "python-dir: Illegal plugin definition %s\n", + plugin_definition.c_str()); + goto bail_out; + } + + /* + * Skip the first ':' + */ + bp++; + + cnt = 0; + while (bp) { + if (strlen(bp) == 0) { break; } + + /* + * Each argument is in the form: + * = + * + * So we setup the right pointers here, argument to the beginning + * of the argument, argument_value to the beginning of the argument_value. + */ + argument = bp; + argument_value = strchr(bp, '='); + if (!argument_value) { + Jmsg(bareos_plugin_ctx, M_FATAL, + "python-dir: Illegal argument %s without value\n", argument); + Dmsg(bareos_plugin_ctx, debuglevel, + "python-dir: Illegal argument %s without value\n", argument); + goto bail_out; + } + *argument_value++ = '\0'; + + /* + * See if there are more arguments and setup for the next run. + */ + bp = argument_value; + do { + bp = strchr(bp, ':'); + if (bp) { + if (*(bp - 1) != '\\') { + *bp++ = '\0'; + break; + } else { + bp++; + } + } + } while (bp); + + found = false; + for (i = 0; plugin_arguments[i].name; i++) { + if (Bstrcasecmp(argument, plugin_arguments[i].name)) { + int64_t* int_destination = NULL; + char** str_destination = NULL; + bool* bool_destination = NULL; + + switch (plugin_arguments[i].type) { + case argument_instance: + int_destination = &plugin_priv_ctx->instance; + break; + case argument_module_path: + str_destination = &plugin_priv_ctx->module_path; + break; + case argument_module_name: + str_destination = &plugin_priv_ctx->module_name; + break; + default: + break; + } + + if (int_destination) { + *int_destination = parse_integer(argument_value); + } + + if (str_destination) { SetString(str_destination, argument_value); } + + if (bool_destination) { + *bool_destination = ParseBoolean(argument_value); + } + + /* + * When we have a match break the loop. + */ + found = true; + break; + } + } + + /* + * If we didn't consume this parameter we add it to the plugin_options list. + */ + if (!found) { + PoolMem option(PM_FNAME); + + if (cnt) { + Mmsg(option, ":%s=%s", argument, argument_value); + PmStrcat(plugin_options, option.c_str()); + } else { + Mmsg(option, "%s=%s", argument, argument_value); + PmStrcat(plugin_options, option.c_str()); + } + cnt++; + } + } + + if (cnt > 0) { PmStrcat(plugin_options, ":"); } + + return bRC_OK; + +bail_out: + return bRC_Error; +} + +/** + * Initial load of the Python module. + * + * Based on the parsed plugin options we set some prerequisites like the + * module path and the module to load. We also load the dictionary used + * for looking up the Python methods. + */ +static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + PyObject *sysPath, *mPath, *pName, *pFunc; + + /* + * See if we already setup the python search path. + */ + if (!plugin_priv_ctx->python_path_set) { + /* + * Extend the Python search path with the given module_path. + */ + if (plugin_priv_ctx->module_path) { + sysPath = PySys_GetObject((char*)"path"); + mPath = PyString_FromString(plugin_priv_ctx->module_path); + PyList_Append(sysPath, mPath); + Py_DECREF(mPath); + plugin_priv_ctx->python_path_set = true; + } + } + + /* + * Try to load the Python module by name. + */ + if (plugin_priv_ctx->module_name) { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-dir: Trying to load module with name %s\n", + plugin_priv_ctx->module_name); + pName = PyString_FromString(plugin_priv_ctx->module_name); + plugin_priv_ctx->pModule = PyImport_Import(pName); + Py_DECREF(pName); + + if (!plugin_priv_ctx->pModule) { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-dir: Failed to load module with name %s\n", + plugin_priv_ctx->module_name); + goto bail_out; + } + + Dmsg(bareos_plugin_ctx, debuglevel, + "python-dir: Successfully loaded module with name %s\n", + plugin_priv_ctx->module_name); + + /* + * Get the Python dictionary for lookups in the Python namespace. + */ + plugin_priv_ctx->pyModuleFunctionsDict = + PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ + + StorePluginContextInPythonModule(bareos_plugin_ctx); + + /* + * Lookup the load_bareos_plugin() function in the python module. + */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "load_bareos_plugin"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyObject *pPluginDefinition, *pRetVal; + + pPluginDefinition = PyString_FromString((char*)value); + if (!pPluginDefinition) { goto bail_out; } + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); + Py_DECREF(pPluginDefinition); + + if (!pRetVal) { + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + } + } else { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-dir: Failed to find function named load_bareos_plugins()\n"); + goto bail_out; + } + + /* + * Keep track we successfully loaded. + */ + plugin_priv_ctx->python_loaded = true; + } + + return retval; + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + return retval; +} + +/** + * Any plugin options which are passed in are dispatched here to a Python method + * and it can parse the plugin options. This function is also called after + * PyLoadModule() has loaded the Python module and made sure things are + * operational. + */ +static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, + void* value) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + PyObject* pFunc; + + /* + * Lookup the parse_plugin_definition() function in the python module. + */ + pFunc = + PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "parse_plugin_definition"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyObject *pPluginDefinition, *pRetVal; + + pPluginDefinition = PyString_FromString((char*)value); + if (!pPluginDefinition) { goto bail_out; } + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); + Py_DECREF(pPluginDefinition); + + if (!pRetVal) { + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + } + + return retval; + } else { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-dir: Failed to find function named " + "parse_plugin_definition()\n"); + return bRC_Error; + } + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + return retval; +} + +static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value) +{ + return bRC_OK; +} + +static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value) +{ + return bRC_OK; +} + +static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, + bDirEvent* event, + void* value) +{ + bRC retval = bRC_Error; + plugin_private_context* plugin_priv_ctx = + (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + PyObject* pFunc; + + /* + * Lookup the handle_plugin_event() function in the python module. + */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "handle_plugin_event"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyObject *pEventType, *pRetVal; + + pEventType = PyInt_FromLong(event->eventType); + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pEventType, NULL); + Py_DECREF(pEventType); + + if (!pRetVal) { + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + } + } else { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-dir: Failed to find function named handle_plugin_event()\n"); + } + + return retval; + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + + return retval; +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to get certain internal values of the current Job. + */ +static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) +{ + int var; + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PyObject* pRetVal = NULL; + + if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + switch (var) { + case bDirVarJobId: + case bDirVarLevel: + case bDirVarType: + case bDirVarNumVols: + case bDirVarJobStatus: + case bDirVarPriority: + case bDirVarFDJobStatus: + case bDirVarSDJobStatus: { + int value = 0; + + if (bareos_core_functions->getBareosValue( + bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { + pRetVal = PyInt_FromLong(value); + } + break; + } + case bDirVarJobErrors: + case bDirVarSDErrors: + case bDirVarJobFiles: + case bDirVarSDJobFiles: + case bDirVarLastRate: + case bDirVarJobBytes: + case bDirVarReadBytes: { + uint64_t value = 0; + + if (bareos_core_functions->getBareosValue( + bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { + pRetVal = PyLong_FromUnsignedLong(value); + } + break; + } + case bDirVarJobName: + case bDirVarJob: + case bDirVarClient: + case bDirVarPool: + case bDirVarStorage: + case bDirVarWriteStorage: + case bDirVarReadStorage: + case bDirVarCatalog: + case bDirVarMediaType: + case bDirVarVolumeName: { + char* value = NULL; + + if (bareos_core_functions->getBareosValue( + bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { + if (value) { pRetVal = PyString_FromString(value); } + } + break; + } + case bDirVarPluginDir: { + char* value = NULL; + + if (bareos_core_functions->getBareosValue(NULL, (brDirVariable)var, + &value) == bRC_OK) { + if (value) { pRetVal = PyString_FromString(value); } + } + break; + } + default: + Dmsg(bareos_plugin_ctx, debuglevel, + "python-dir: PyBareosGetValue unknown variable requested %d\n", var); + break; + } + + if (!pRetVal) { + Py_INCREF(Py_None); + pRetVal = Py_None; + } + + return pRetVal; +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to set certain internal values of the current Job. + */ +static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) +{ + int var; + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bRC retval = bRC_Error; + PyObject* pyValue; + + if (!PyArg_ParseTuple(args, "iO:BareosSetValue", &var, &pyValue)) { + goto bail_out; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + switch (var) { + case bwDirVarVolumeName: { + char* value; + + value = PyString_AsString(pyValue); + if (value) { + retval = bareos_core_functions->setBareosValue( + bareos_plugin_ctx, (bwDirVariable)var, value); + } + + break; + } + case bwDirVarPriority: + case bwDirVarJobLevel: { + int value; + + value = PyInt_AsLong(pyValue); + if (value >= 0) { + retval = bareos_core_functions->setBareosValue( + bareos_plugin_ctx, (bwDirVariable)var, &value); + } + break; + } + default: + Dmsg(bareos_plugin_ctx, debuglevel, + "python-dir: PyBareosSetValue unknown variable requested %d\n", var); + break; + } + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to issue debug messages using the Bareos debug message + * facility. + */ +static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) +{ + int level; + char* dbgmsg = NULL; + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + + if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { + return NULL; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + if (dbgmsg) { Dmsg(bareos_plugin_ctx, level, "python-dir: %s", dbgmsg); } + + Py_INCREF(Py_None); + return Py_None; +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to issue Job messages using the Bareos Job message + * facility. + */ +static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) +{ + int type; + char* jobmsg = NULL; + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + + if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { + return NULL; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + if (jobmsg) { Jmsg(bareos_plugin_ctx, type, "python-dir: %s", jobmsg); } + + Py_INCREF(Py_None); + return Py_None; +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to issue a Register Event to register additional events + * it wants to receive. + */ +static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) +{ + int len, event; + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bRC retval = bRC_Error; + PyObject *pyEvents, *pySeq, *pyEvent; + + if (!PyArg_ParseTuple(args, "O:BareosRegisterEvents", &pyEvents)) { + goto bail_out; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); + if (!pySeq) { goto bail_out; } + + len = PySequence_Fast_GET_SIZE(pySeq); + + for (int i = 0; i < len; i++) { + pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); + event = PyInt_AsLong(pyEvent); + + if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-dir: PyBareosRegisterEvents registering event %d\n", event); + retval = bareos_core_functions->registerBareosEvents(bareos_plugin_ctx, 1, + event); + + if (retval != bRC_OK) { break; } + } + } + + Py_DECREF(pySeq); + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to issue an Unregister Event to unregister events it + * doesn't want to receive anymore. + */ +static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) +{ + int len, event; + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + bRC retval = bRC_Error; + PyObject *pyEvents, *pySeq, *pyEvent; + + if (!PyArg_ParseTuple(args, "O:BareosUnRegisterEvents", &pyEvents)) { + goto bail_out; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); + if (!pySeq) { goto bail_out; } + + len = PySequence_Fast_GET_SIZE(pySeq); + + for (int i = 0; i < len; i++) { + pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); + event = PyInt_AsLong(pyEvent); + + if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { + Dmsg(bareos_plugin_ctx, debuglevel, + "PyBareosUnRegisterEvents: registering event %d\n", event); + retval = bareos_core_functions->unregisterBareosEvents(bareos_plugin_ctx, + 1, event); + + if (retval != bRC_OK) { break; } + } + } + + Py_DECREF(pySeq); + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to issue a GetInstanceCount to retrieve the number of + * instances of the current plugin being loaded into the daemon. + */ +static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) +{ + int value; + PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PyObject* pRetVal = NULL; + + if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + if (bareos_core_functions->getInstanceCount(bareos_plugin_ctx, &value) == + bRC_OK) { + pRetVal = PyInt_FromLong(value); + } + + if (!pRetVal) { + Py_INCREF(Py_None); + pRetVal = Py_None; + } + + return pRetVal; +} +} /* namespace directordaemon */ diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index b2e775dd0e7..0da9ee97c3a 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -105,6 +105,7 @@ if(HAVE_PYTHON) COMPONENT filedaemon ) target_link_libraries(python-fd ${PYTHON_LIBRARIES} bareos) + add_dependencies(python-fd bareosfd) endif() if(HAVE_PYTHON AND NOT HAVE_WIN32) @@ -129,8 +130,6 @@ if(HAVE_PYTHON AND NOT HAVE_WIN32) OUTPUT pythonmodules/bareosfd.so MAIN_DEPENDENCY ./python/bareosfd.cc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py - #TARGET python-fd - #POST_BUILD COMMAND ${PYTHON_EXECUTABLE} python/setup.py build COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 1687933441f..e6e1c866135 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -231,111 +231,103 @@ static void PyErrorHandler() /** * Plugin called here when it is first loaded */ -/* bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, */ -/* BareosCoreFunctions* lbareos_core_functions, */ -/* PluginInformation** plugin_information, */ -/* pFuncs** plugin_functions) */ -/* { */ -/* bareos_core_functions = lbareos_core_functions; /1* Set Bareos funct - * pointers *1/ */ -/* bareos_plugin_interface_version = lbareos_plugin_interface_version; */ - -/* *plugin_information = &pluginInfo; /1* Return pointer to our info *1/ */ -/* *plugin_functions = &pluginFuncs; /1* Return pointer to our functions *1/ - */ - -/* if (!Py_IsInitialized()) { */ -/* /1* Setup Python *1/ */ -/* #if PY_MAJOR_VERSION >= 3 */ -/* /1* PyImport_AppendInittab("bareosfd", &PyInit_bareosfd); *1/ */ -/* #else */ -/* /1* PyImport_AppendInittab("bareosfd", initbareosfd); *1/ */ -/* #endif */ -/* Py_InitializeEx(0); */ - -/* /1* import the bareosfd module *1/ */ -/* PyObject* bareosfdModule = PyImport_ImportModule("bareosfd"); */ -/* if (bareosfdModule) { */ -/* printf("loaded bareosfd successfully\n"); */ -/* } else { */ -/* printf("loading of bareosfd failed\n"); */ -/* } */ - -/* if (PyErr_Occurred()) { PyErrorHandler(); } */ - -/* // Extract capsules pointer from bareosfd module */ -/* void (*loadplugin_from_bareosfd_module)( */ -/* filedaemon::Core_PluginApiDefinition * - * lbareos_plugin_interface_version, filedaemon::BareosCoreFunctions * - * lbareos_core_functions, */ -/* PluginInformation * *plugin_information, filedaemon::pFuncs * - * *plugin_functions) = */ -/* (void (*)(filedaemon::Core_PluginApiDefinition*, - * filedaemon::BareosCoreFunctions*, PluginInformation**, */ -/* filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", - */ -/* 0); */ - -/* // Extract capsule bareosfd.PluginContext */ -/* void* ctx_from_bareosfd_module = - * PyCapsule_Import("bareosfd.PluginContext", 0); */ -/* if (!ctx_from_bareosfd_module) { */ -/* printf("importing bareosfd.PluginContext failed \n"); */ -/* } */ - -/* // Extract capsules bareosfd.BareosCoreFunctions */ -/* void* bareos_core_functions_from_bareosfd_module = - * PyCapsule_Import("bareosfd.BareosCoreFunctions", 0); */ -/* if (!bareos_core_functions_from_bareosfd_module) { */ -/* printf("importing bareosfd.BareosCoreFunctions failed \n"); */ -/* } */ - -/* if (!loadplugin_from_bareosfd_module) { */ -/* printf("importing bareosfd.loadPlugin failed \n"); */ -/* } */ - - -/* *(void**)ctx_from_bareosfd_module = &bareos_PluginContext; */ -/* *(void**)bareos_core_functions_from_bareosfd_module = - * &bareos_core_functions; */ - -/* /1* call loadPlugin in plugin *1/ */ -/* filedaemon::Core_PluginApiDefinition myInfo; */ -/* PluginInformation plugin_information; */ -/* filedaemon::pFuncs plugin_functions; */ - -/* loadplugin_from_bareosfd_module(&myInfo, bareos_core_functions, - * (PluginInformation**)&plugin_information, */ -/* (filedaemon::pFuncs**)&plugin_functions); - */ - - -/* printf("ctx_from_bareosfd_module contains %p\n", */ -/* *(void**)ctx_from_bareosfd_module); */ -/* printf("bareos_core_functions_from_bareosfd_module contains %p\n", */ -/* *(void**)bareos_core_functions_from_bareosfd_module); */ - - -/* PyEval_InitThreads(); */ -/* mainThreadState = PyEval_SaveThread(); */ -/* } */ -/* return bRC_OK; */ -/* } */ +bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, + BareosCoreFunctions* lbareos_core_functions, + PluginInformation** plugin_information, + pFuncs** plugin_functions) +{ + bareos_core_functions = + lbareos_core_functions; /* Set Bareos funct * pointers */ + bareos_plugin_interface_version = lbareos_plugin_interface_version; + + *plugin_information = &pluginInfo; /* Return pointer to our info */ + *plugin_functions = &pluginFuncs; /* Return pointer to our functions */ + + if (!Py_IsInitialized()) { + /* Setup Python */ +#if PY_MAJOR_VERSION >= 3 + /* PyImport_AppendInittab("bareosfd", &PyInit_bareosfd); */ +#else + /* PyImport_AppendInittab("bareosfd", initbareosfd); */ +#endif + Py_InitializeEx(0); + + /* import the bareosfd module */ + PyObject* bareosfdModule = PyImport_ImportModule("bareosfd"); + if (bareosfdModule) { + printf("loaded bareosfd successfully\n"); + } else { + printf("loading of bareosfd failed\n"); + } + + if (PyErr_Occurred()) { PyErrorHandler(); } + // Extract capsules pointer from bareosfd module + void (*loadplugin_from_bareosfd_module)( + filedaemon::Core_PluginApiDefinition * lbareos_plugin_interface_version, + filedaemon::BareosCoreFunctions * lbareos_core_functions, + PluginInformation * *plugin_information, + filedaemon::pFuncs * **plugin_functions) = + (void (*)(filedaemon::Core_PluginApiDefinition*, + filedaemon::BareosCoreFunctions*, PluginInformation**, + filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", + 0); + + /* // Extract capsule bareosfd.PluginContext */ + void* ctx_from_bareosfd_module = + PyCapsule_Import("bareosfd.PluginContext", 0); + if (!ctx_from_bareosfd_module) { + printf("importing bareosfd.PluginContext failed \n"); + } + + // Extract capsules bareosfd.BareosCoreFunctions + void* bareos_core_functions_from_bareosfd_module = + PyCapsule_Import("bareosfd.BareosCoreFunctions", 0); + if (!bareos_core_functions_from_bareosfd_module) { + printf("importing bareosfd.BareosCoreFunctions failed \n"); + } + + if (!loadplugin_from_bareosfd_module) { + printf("importing bareosfd.loadPlugin failed \n"); + } + + + *(void**)ctx_from_bareosfd_module = &bareos_PluginContext; + *(void**)bareos_core_functions_from_bareosfd_module = + &bareos_core_functions; + + /* call loadPlugin in plugin */ + filedaemon::Core_PluginApiDefinition myInfo; + PluginInformation plugin_information; + filedaemon::pFuncs plugin_functions; + + loadplugin_from_bareosfd_module(&myInfo, bareos_core_functions, + (PluginInformation**)&plugin_information, + (filedaemon::pFuncs**)&plugin_functions); + + + printf("ctx_from_bareosfd_module contains %p\n", + *(void**)ctx_from_bareosfd_module); + printf("bareos_core_functions_from_bareosfd_module contains %p\n", + *(void**)bareos_core_functions_from_bareosfd_module); + + + PyEval_InitThreads(); + mainThreadState = PyEval_SaveThread(); + } + return bRC_OK; +} /** * Plugin called here when it is unloaded, normally when Bareos is going to * exit. */ -/*bRC unloadPlugin()*/ -/*{*/ -/* */ -/* * Terminate Python*/ -/* */ -/* PyEval_RestoreThread(mainThreadState);*/ -/* Py_Finalize();*/ - -/* return bRC_OK;*/ -/*}*/ +bRC unloadPlugin() +{ + /* Terminate Python */ + PyEval_RestoreThread(mainThreadState); + Py_Finalize(); + return bRC_OK; +} #ifdef __cplusplus } @@ -440,11 +432,11 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) } /** - * Any plugin options which are passed in are dispatched here to a Python method - * and it can parse the plugin options. This function is also called after - * PyLoadModule() has loaded the Python module and made sure things are - * operational. Normally you would only get one set of plugin options but for a - * restore overrides can be passed in before the actual plugin options are + * Any plugin options which are passed in are dispatched here to a Python + * method and it can parse the plugin options. This function is also called + * after PyLoadModule() has loaded the Python module and made sure things are + * operational. Normally you would only get one set of plugin options but for + * a restore overrides can be passed in before the actual plugin options are * restored as part of the restore stream handling. */ static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, @@ -479,9 +471,9 @@ static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, return retval; } else { - Dmsg( - bareos_plugin_ctx, debuglevel, - "python-fd: Failed to find function named parse_plugin_definition()\n"); + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Failed to find function named " + "parse_plugin_definition()\n"); return bRC_Error; } @@ -709,8 +701,8 @@ static inline bool PySavePacketToNative( */ if (pSavePkt->object_len > 0) { /* - * As this has to linger as long as the backup is running we save it in - * our plugin context. + * As this has to linger as long as the backup is running we save it + * in our plugin context. */ if (pSavePkt->object_name && pSavePkt->object && PyString_Check(pSavePkt->object_name) && @@ -883,8 +875,8 @@ static inline PyIoPacket* NativeToPyIoPacket(struct io_pkt* io) pIoPkt->offset = io->offset; if (io->func == IO_WRITE && io->count > 0) { /* - * Only initialize the buffer with read data when we are writing and there - * is data. + * Only initialize the buffer with read data when we are writing and + * there is data. */ pIoPkt->buf = PyByteArray_FromStringAndSize(io->buf, io->count); if (!pIoPkt->buf) { @@ -1106,8 +1098,8 @@ static inline void PyRestorePacketToNative(PyRestorePacket* pRestorePacket, /** * Called for a command plugin to create a file during a Restore job before - * restoring the data. This entry point is called before any I/O is done on the - * file. After this call, Bareos will call pluginIO() to open the file for + * restoring the data. This entry point is called before any I/O is done on + * the file. After this call, Bareos will call pluginIO() to open the file for * write. * * We must return in rp->create_status: @@ -1648,8 +1640,9 @@ static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to get certain internal values of the current Job. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to get certain internal values of the current + * Job. */ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { @@ -1719,8 +1712,9 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to get certain internal values of the current Job. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to get certain internal values of the current + * Job. */ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { @@ -1766,9 +1760,9 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue debug messages using the Bareos debug message - * facility. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue debug messages using the Bareos debug + * message facility. */ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { @@ -1776,7 +1770,8 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) char* dbgmsg = NULL; PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); /* plugin_private_context* ppc = */ - /* (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; */ + /* (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + */ if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; diff --git a/core/src/plugins/stored/CMakeLists.txt b/core/src/plugins/stored/CMakeLists.txt index 75e9429edda..c14108ae43b 100644 --- a/core/src/plugins/stored/CMakeLists.txt +++ b/core/src/plugins/stored/CMakeLists.txt @@ -53,6 +53,7 @@ if(HAVE_PYTHON) set_target_properties(python-sd PROPERTIES PREFIX "") install(TARGETS python-sd DESTINATION ${plugindir}) target_link_libraries(python-sd ${PYTHON_LIBRARIES} bareos) + add_dependencies(python-sd bareossd) set(PYFILES python/pyfiles/bareos-sd-class-plugin.py From ec566ead68fbba6648d3f2de9bf07f7905da7867 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 30 Apr 2020 17:26:09 +0200 Subject: [PATCH 068/341] bareosfd.cc: builds successfully --- core/src/plugins/filed/python/bareosfd.cc | 113 ++++++++++------------ 1 file changed, 51 insertions(+), 62 deletions(-) diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index e6e1c866135..d7944c4e4f9 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -47,56 +47,45 @@ namespace filedaemon { static const int debuglevel = 150; -/* #define PLUGIN_LICENSE "Bareos AGPLv3" */ -/* #define PLUGIN_AUTHOR "Marco van Wieringen" */ -/* #define PLUGIN_DATE "May 2014" */ -/* #define PLUGIN_VERSION "3" */ -/* #define PLUGIN_DESCRIPTION "Python File Daemon Plugin" */ -/* #define PLUGIN_USAGE \ */ -/* "python:module_path=:module_name=:module_name=:..." */ /* Forward referenced functions */ -/* static bRC newPlugin(PluginContext* bareos_plugin_ctx); */ -/* static bRC freePlugin(PluginContext* bareos_plugin_ctx); */ -/* static bRC getPluginValue(PluginContext* bareos_plugin_ctx, */ -/* pVariable var, */ -/* void* value); */ -/* static bRC setPluginValue(PluginContext* bareos_plugin_ctx, */ -/* pVariable var, */ -/* void* value); */ -/* static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, */ -/* bEvent* event, */ -/* void* value); */ -/* static bRC startBackupFile(PluginContext* bareos_plugin_ctx, struct - * save_pkt* sp); */ -/* static bRC endBackupFile(PluginContext* bareos_plugin_ctx); */ -/* static bRC pluginIO(PluginContext* bareos_plugin_ctx, struct - * io_pkt* io); */ -/* static bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const - * char* cmd); - */ -/* static bRC endRestoreFile(PluginContext* bareos_plugin_ctx); */ -/* static bRC createFile(PluginContext* bareos_plugin_ctx, struct - * restore_pkt* rp); - */ -/* static bRC setFileAttributes(PluginContext* bareos_plugin_ctx, */ -/* struct restore_pkt* rp); */ -/* static bRC checkFile(PluginContext* bareos_plugin_ctx, char* - * fname); */ -/* static bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); - */ -/* static bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); - */ -/* static bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* - * xp); */ -/* static bRC setXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* - * xp); */ -/* static bRC parse_plugin_definition(PluginContext* - * bareos_plugin_ctx, */ -/* void* value, */ -/* PoolMem& plugin_options); */ +static bRC newPlugin(PluginContext* bareos_plugin_ctx); +static bRC freePlugin(PluginContext* bareos_plugin_ctx); +static bRC getPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC setPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, + bEvent* event, + void* value); +static bRC startBackupFile(PluginContext* bareos_plugin_ctx, + struct save_pkt* sp); +static bRC endBackupFile(PluginContext* bareos_plugin_ctx); +static bRC pluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); +static bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); +static bRC endRestoreFile(PluginContext* bareos_plugin_ctx); +static bRC createFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); +static bRC setFileAttributes(PluginContext* bareos_plugin_ctx, + struct restore_pkt* rp); +static bRC checkFile(PluginContext* bareos_plugin_ctx, char* fname); +static bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC setXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, + void* value, + PoolMem& plugin_options); static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); @@ -137,22 +126,22 @@ static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, static BareosCoreFunctions* bareos_core_functions = NULL; static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; -/* static PluginInformation pluginInfo = {sizeof(pluginInfo), - * FD_PLUGIN_INTERFACE_VERSION, */ -/* FD_PLUGIN_MAGIC, PLUGIN_LICENSE, */ -/* PLUGIN_AUTHOR, PLUGIN_DATE, */ -/* PLUGIN_VERSION, PLUGIN_DESCRIPTION, */ -/* PLUGIN_USAGE}; */ +static PluginInformation pluginInfo = { + sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, + FD_PLUGIN_MAGIC, PLUGIN_LICENSE, + PLUGIN_AUTHOR, PLUGIN_DATE, + PLUGIN_VERSION, PLUGIN_DESCRIPTION, + PLUGIN_USAGE}; -/* static pFuncs pluginFuncs = { */ -/* sizeof(pluginFuncs), FD_PLUGIN_INTERFACE_VERSION, */ +static pFuncs pluginFuncs = { + sizeof(pluginFuncs), FD_PLUGIN_INTERFACE_VERSION, -/* /1* Entry points into plugin *1/ */ -/* newPlugin, /1* new plugin instance *1/ */ -/* freePlugin, /1* free plugin instance *1/ */ -/* getPluginValue, setPluginValue, handlePluginEvent, startBackupFile, */ -/* endBackupFile, startRestoreFile, endRestoreFile, pluginIO, createFile, */ -/* setFileAttributes, checkFile, getAcl, setAcl, getXattr, setXattr}; */ + /* Entry points into plugin */ + newPlugin, /* new plugin instance */ + freePlugin, /* free plugin instance */ + getPluginValue, setPluginValue, handlePluginEvent, startBackupFile, + endBackupFile, startRestoreFile, endRestoreFile, pluginIO, createFile, + setFileAttributes, checkFile, getAcl, setAcl, getXattr, setXattr}; struct plugin_private_context { int32_t backup_level; /* Backup level e.g. Full/Differential/Incremental */ @@ -172,7 +161,7 @@ struct plugin_private_context { PyObject* pyModuleFunctionsDict; /* Python Dictionary */ BareosCoreFunctions* bareos_core_functions; /* pointer to bareos_core_functions */ -}; +}; // namespace filedaemon /** * We don't actually use this but we need it to tear down the @@ -266,7 +255,7 @@ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, filedaemon::Core_PluginApiDefinition * lbareos_plugin_interface_version, filedaemon::BareosCoreFunctions * lbareos_core_functions, PluginInformation * *plugin_information, - filedaemon::pFuncs * **plugin_functions) = + filedaemon::pFuncs * *plugin_functions) = (void (*)(filedaemon::Core_PluginApiDefinition*, filedaemon::BareosCoreFunctions*, PluginInformation**, filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", From d5263bd9bb95f205940ccdaa61b300cc793b8274 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 6 May 2020 15:10:57 +0200 Subject: [PATCH 069/341] python-fd: bareosfd.h introduced, fd loads --- core/src/plugins/filed/CMakeLists.txt | 8 +- core/src/plugins/filed/python/bareosfd.cc | 717 +++++++++++++- core/src/plugins/filed/python/bareosfd.h | 1031 +++++++++++++++++++++ 3 files changed, 1752 insertions(+), 4 deletions(-) create mode 100644 core/src/plugins/filed/python/bareosfd.h diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index 0da9ee97c3a..59f7be2ac02 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -129,11 +129,13 @@ if(HAVE_PYTHON AND NOT HAVE_WIN32) add_custom_command( OUTPUT pythonmodules/bareosfd.so MAIN_DEPENDENCY ./python/bareosfd.cc + DEPENDS ./python/bareosfd.h DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py COMMAND ${PYTHON_EXECUTABLE} python/setup.py build - COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib - ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - # COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build DEPENDS python-fd + COMMAND + ${PYTHON_EXECUTABLE} python/setup.py install --install-lib + ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + # COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build DEPENDS python-fd COMMENT "building python module pythonmodules/bareosfd.so" ) diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index d7944c4e4f9..db6e3ced031 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -40,7 +40,7 @@ #include "filed/fd_plugins.h" -#include "python-fd.h" +#include "bareosfd.h" #include "lib/edit.h" namespace filedaemon { @@ -322,6 +322,721 @@ bRC unloadPlugin() } #endif +/** + * Called here to make a new instance of the plugin -- i.e. when + * a new Job is started. There can be multiple instances of + * each plugin that are running at the same time. Your + * plugin instance must be thread safe and keep its own + * local data. + */ +static bRC newPlugin(PluginContext* bareos_plugin_ctx) +{ + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)malloc( + sizeof(struct plugin_private_context)); + if (!plugin_priv_ctx) { return bRC_Error; } + memset(plugin_priv_ctx, 0, sizeof(struct plugin_private_context)); + bareos_plugin_ctx->plugin_private_context = + (void*)plugin_priv_ctx; /* set our context pointer */ + + plugin_priv_ctx->bareos_core_functions = bareos_core_functions; + + /* For each plugin instance we instantiate a new Python interpreter. */ + PyEval_AcquireThread(mainThreadState); + plugin_priv_ctx->interpreter = Py_NewInterpreter(); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + + /* Always register some events the python plugin itself can register + any other events it is interested in. */ + bareos_core_functions->registerBareosEvents( + bareos_plugin_ctx, 9, bEventLevel, bEventSince, bEventNewPluginOptions, + bEventPluginCommand, bEventJobStart, bEventRestoreCommand, + bEventEstimateCommand, bEventBackupCommand, bEventRestoreObject); + + return bRC_OK; +} + +/** + * Release everything concerning a particular instance of a + * plugin. Normally called when the Job terminates. + */ +static bRC freePlugin(PluginContext* bareos_plugin_ctx) +{ + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + + if (!plugin_priv_ctx) { return bRC_Error; } + + if (plugin_priv_ctx->plugin_options) { + free(plugin_priv_ctx->plugin_options); + } + + if (plugin_priv_ctx->module_path) { free(plugin_priv_ctx->module_path); } + + if (plugin_priv_ctx->module_name) { free(plugin_priv_ctx->module_name); } + + if (plugin_priv_ctx->fname) { free(plugin_priv_ctx->fname); } + + if (plugin_priv_ctx->link) { free(plugin_priv_ctx->link); } + + if (plugin_priv_ctx->object_name) { free(plugin_priv_ctx->object_name); } + + if (plugin_priv_ctx->object) { free(plugin_priv_ctx->object); } + + /* + * Stop any sub interpreter started per plugin instance. + */ + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + + + if (plugin_priv_ctx->pModule) { Py_DECREF(plugin_priv_ctx->pModule); } + + Py_EndInterpreter(plugin_priv_ctx->interpreter); + PyEval_ReleaseLock(); + + free(plugin_priv_ctx); + bareos_plugin_ctx->plugin_private_context = NULL; + + return bRC_OK; +} + + +static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, + bEvent* event, + void* value) +{ + bRC retval = bRC_Error; + bool event_dispatched = false; + PoolMem plugin_options(PM_FNAME); + plugin_private_context* plugin_priv_ctx = + (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + + if (!plugin_priv_ctx) { goto bail_out; } + + /* + * First handle some events internally before calling python if it + * want to do some special handling on the event triggered. + */ + switch (event->eventType) { + case bEventLevel: + plugin_priv_ctx->backup_level = (int64_t)value; + break; + case bEventSince: + plugin_priv_ctx->since = (int64_t)value; + break; + case bEventBackupCommand: + /* + * Fall-through wanted + */ + case bEventRestoreCommand: + /* Fall-through wanted */ + case bEventEstimateCommand: + /* Fall-through wanted */ + case bEventPluginCommand: + event_dispatched = true; + retval = + parse_plugin_definition(bareos_plugin_ctx, value, plugin_options); + break; + case bEventNewPluginOptions: + /* Free any previous value. */ + if (plugin_priv_ctx->plugin_options) { + free(plugin_priv_ctx->plugin_options); + plugin_priv_ctx->plugin_options = NULL; + } + + event_dispatched = true; + retval = + parse_plugin_definition(bareos_plugin_ctx, value, plugin_options); + + /* Save that we got a plugin override. */ + plugin_priv_ctx->plugin_options = strdup((char*)value); + break; + case bEventRestoreObject: { + struct restore_object_pkt* rop; + + rop = (struct restore_object_pkt*)value; + + /* Only use the plugin definition of a restore object if we + * didn't get any other plugin definition from some other source before.*/ + if (!plugin_priv_ctx->python_loaded) { + if (rop && *rop->plugin_name) { + event_dispatched = true; + retval = parse_plugin_definition(bareos_plugin_ctx, rop->plugin_name, + plugin_options); + } + } + break; + } + default: + break; + } + + /* + * See if we have been triggered in the previous switch if not we have to + * always dispatch the event. If we already processed the event internally + * we only do a dispatch to the python entry point when that internal + * processing was successful (e.g. retval == bRC_OK). + */ + if (!event_dispatched || retval == bRC_OK) { + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + + /* + * Now dispatch the event to Python. + * First the calls that need special handling. + */ + switch (event->eventType) { + case bEventBackupCommand: + /* Fall-through wanted */ + case bEventRestoreCommand: + /* Fall-through wanted */ + case bEventEstimateCommand: + /* Fall-through wanted */ + case bEventPluginCommand: + /* Fall-through wanted */ + case bEventNewPluginOptions: + /* See if we already loaded the Python modules. */ + if (!plugin_priv_ctx->python_loaded) { + retval = PyLoadModule(bareos_plugin_ctx, plugin_options.c_str()); + } + + /* Only try to call when the loading succeeded. */ + if (retval == bRC_OK) { + retval = PyParsePluginDefinition(bareos_plugin_ctx, + plugin_options.c_str()); + } + break; + case bEventRestoreObject: { + struct restore_object_pkt* rop; + + rop = (struct restore_object_pkt*)value; + if (!rop) { + /* + * If rop == NULL this means we got the last restore object. + * No need to call into python so just return. + */ + retval = bRC_OK; + } else { + /* See if we already loaded the Python modules. */ + if (!plugin_priv_ctx->python_loaded && *rop->plugin_name) { + retval = PyLoadModule(bareos_plugin_ctx, plugin_options.c_str()); + + /* Only try to call when the loading succeeded. */ + if (retval == bRC_OK) { + retval = PyParsePluginDefinition(bareos_plugin_ctx, + plugin_options.c_str()); + if (retval == bRC_OK) { + retval = PyRestoreObjectData(bareos_plugin_ctx, rop); + } + } + } else { + retval = PyRestoreObjectData(bareos_plugin_ctx, rop); + } + } + break; + } + case bEventHandleBackupFile: + retval = PyHandleBackupFile(bareos_plugin_ctx, (struct save_pkt*)value); + break; + default: + /* + * Handle the generic events e.g. the ones which are just passed on. + * We only try to call Python when we loaded the right module until + * that time we pretend the call succeeded. + */ + if (plugin_priv_ctx->python_loaded) { + retval = PyHandlePluginEvent(bareos_plugin_ctx, event, value); + } else { + retval = bRC_OK; + } + break; + } + + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + } + +bail_out: + return retval; +} + +/** + * Called when starting to backup a file. Here the plugin must + * return the "stat" packet for the directory/file and provide + * certain information so that Bareos knows what the file is. + * The plugin can create "Virtual" files by giving them a + * name that is not normally found on the file system. + */ +static bRC startBackupFile(PluginContext* bareos_plugin_ctx, + struct save_pkt* sp) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + + if (!plugin_priv_ctx) { goto bail_out; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyStartBackupFile(bareos_plugin_ctx, sp); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + + /* + * For Incremental and Differential backups use checkChanges method to + * see if we need to backup this file. + */ + switch (plugin_priv_ctx->backup_level) { + case L_INCREMENTAL: + case L_DIFFERENTIAL: + /* + * If the plugin didn't set a save_time but we have a since time + * from the bEventSince event we use that as basis for the actual + * save_time to check. + */ + if (sp->save_time == 0 && plugin_priv_ctx->since) { + sp->save_time = plugin_priv_ctx->since; + } + + switch (bareos_core_functions->checkChanges(bareos_plugin_ctx, sp)) { + case bRC_Seen: + switch (sp->type) { + case FT_DIRBEGIN: + sp->type = FT_DIRNOCHG; + break; + default: + sp->type = FT_NOCHG; + break; + } + break; + default: + break; + } + } + +bail_out: + return retval; +} + +/** + * Done backing up a file. + */ +static bRC endBackupFile(PluginContext* bareos_plugin_ctx) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + + if (!plugin_priv_ctx) { goto bail_out; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyEndBackupFile(bareos_plugin_ctx); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + +bail_out: + return retval; +} + +/** + * Do actual I/O. Bareos calls this after startBackupFile + * or after startRestoreFile to do the actual file + * input or output. + */ +static bRC pluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + + if (!plugin_priv_ctx) { goto bail_out; } + + if (!plugin_priv_ctx->python_loaded) { goto bail_out; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyPluginIO(bareos_plugin_ctx, io); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + +bail_out: + return retval; +} + +/** + * Start restore of a file. + */ +static bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + + if (!plugin_priv_ctx) { goto bail_out; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyStartRestoreFile(bareos_plugin_ctx, cmd); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + +bail_out: + return retval; +} + +/** + * Done restoring a file. + */ +static bRC endRestoreFile(PluginContext* bareos_plugin_ctx) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + + if (!plugin_priv_ctx) { goto bail_out; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyEndRestoreFile(bareos_plugin_ctx); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + +bail_out: + return retval; +} + +/** + * Called here to give the plugin the information needed to + * re-create the file on a restore. It basically gets the + * stat packet that was created during the backup phase. + * This data is what is needed to create the file, but does + * not contain actual file data. + */ +static bRC createFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + + if (!plugin_priv_ctx) { goto bail_out; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyCreateFile(bareos_plugin_ctx, rp); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + +bail_out: + return retval; +} + +/** + * Called after the file has been restored. This can be used to + * set directory permissions, ... + */ +static bRC setFileAttributes(PluginContext* bareos_plugin_ctx, + struct restore_pkt* rp) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + + if (!plugin_priv_ctx) { goto bail_out; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PySetFileAttributes(bareos_plugin_ctx, rp); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + +bail_out: + return retval; +} + +/** + * When using Incremental dump, all previous dumps are necessary + */ +static bRC checkFile(PluginContext* bareos_plugin_ctx, char* fname) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + + if (!plugin_priv_ctx) { goto bail_out; } + + if (!plugin_priv_ctx->python_loaded) { return bRC_OK; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyCheckFile(bareos_plugin_ctx, fname); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + +bail_out: + return retval; +} + +/** + */ +static bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + + if (!plugin_priv_ctx) { goto bail_out; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyGetAcl(bareos_plugin_ctx, ap); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + +bail_out: + return retval; +} + +/** + */ +static bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + + if (!plugin_priv_ctx) { goto bail_out; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PySetAcl(bareos_plugin_ctx, ap); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + +bail_out: + return retval; +} + +/** + */ +static bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + + if (!plugin_priv_ctx) { goto bail_out; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PyGetXattr(bareos_plugin_ctx, xp); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + +bail_out: + return retval; +} + +/** + */ +static bRC setXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + + if (!plugin_priv_ctx) { goto bail_out; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = PySetXattr(bareos_plugin_ctx, xp); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + +bail_out: + return retval; +} + +/** + * Only set destination to value when it has no previous setting. + */ +static inline void SetStringIfNull(char** destination, char* value) +{ + if (!*destination) { + *destination = strdup(value); + StripBackSlashes(*destination); + } +} + +/** + * Parse the plugin definition passed in. + * + * The definition is in this form: + * + * python:module_path=:module_name=:... + */ +static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, + void* value, + PoolMem& plugin_options) +{ + bool found; + int i, cnt; + bool keep_existing; + PoolMem plugin_definition(PM_FNAME); + char *bp, *argument, *argument_value; + plugin_private_context* plugin_priv_ctx = + (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + + if (!value) { return bRC_Error; } + + /* + * Skip this plugin when getting plugin definition "*all*" + * This allows to restore a Windows Backup on a Linux FD with + * Python Plugins enabled. + */ + if (bstrcmp((char*)value, "*all*")) { + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Got plugin definition %s, skipping to ignore\n", + (char*)value); + return bRC_Skip; + } + + keep_existing = (plugin_priv_ctx->plugin_options) ? true : false; + + /* + * Parse the plugin definition. + * Make a private copy of the whole string. + */ + if (!plugin_priv_ctx->python_loaded && plugin_priv_ctx->plugin_options) { + int len; + + /* + * We got some option string which got pushed before we actual were able to + * send it to the python module as the entry point was not instantiated. So + * we prepend that now in the option string and append the new option string + * with the first argument being the pluginname removed as that is already + * part of the other plugin option string. + */ + len = strlen(plugin_priv_ctx->plugin_options); + PmStrcpy(plugin_definition, plugin_priv_ctx->plugin_options); + + bp = strchr((char*)value, ':'); + if (!bp) { + Jmsg(bareos_plugin_ctx, M_FATAL, + "python-fd: Illegal plugin definition %s\n", (char*)value); + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Illegal plugin definition %s\n", (char*)value); + goto bail_out; + } + + /* + * See if option string end with ':' + */ + if (plugin_priv_ctx->plugin_options[len - 1] != ':') { + PmStrcat(plugin_definition, (char*)bp); + } else { + PmStrcat(plugin_definition, (char*)bp + 1); + } + } else { + PmStrcpy(plugin_definition, (char*)value); + } + + bp = strchr(plugin_definition.c_str(), ':'); + if (!bp) { + Jmsg(bareos_plugin_ctx, M_FATAL, + "python-fd: Illegal plugin definition %s\n", + plugin_definition.c_str()); + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Illegal plugin definition %s\n", + plugin_definition.c_str()); + goto bail_out; + } + + /* + * Skip the first ':' + */ + bp++; + + cnt = 0; + while (bp) { + if (strlen(bp) == 0) { break; } + + /* + * Each argument is in the form: + * = + * + * So we setup the right pointers here, argument to the beginning + * of the argument, argument_value to the beginning of the argument_value. + */ + argument = bp; + argument_value = strchr(bp, '='); + if (!argument_value) { + Jmsg(bareos_plugin_ctx, M_FATAL, + "python-fd: Illegal argument %s without value\n", argument); + Dmsg(bareos_plugin_ctx, debuglevel, + "python-fd: Illegal argument %s without value\n", argument); + goto bail_out; + } + *argument_value++ = '\0'; + + /* + * See if there are more arguments and setup for the next run. + */ + bp = argument_value; + do { + bp = strchr(bp, ':'); + if (bp) { + if (*(bp - 1) != '\\') { + *bp++ = '\0'; + break; + } else { + bp++; + } + } + } while (bp); + + found = false; + for (i = 0; plugin_arguments[i].name; i++) { + if (Bstrcasecmp(argument, plugin_arguments[i].name)) { + char** str_destination = NULL; + bool* bool_destination = NULL; + + switch (plugin_arguments[i].type) { + case argument_module_path: + str_destination = &plugin_priv_ctx->module_path; + break; + case argument_module_name: + str_destination = &plugin_priv_ctx->module_name; + break; + default: + break; + } + + /* + * Keep the first value, ignore any next setting. + */ + if (str_destination) { + if (keep_existing) { + SetStringIfNull(str_destination, argument_value); + } else { + SetString(str_destination, argument_value); + } + } + + /* + * Set any boolean variable. + */ + if (bool_destination) { + *bool_destination = ParseBoolean(argument_value); + } + + /* + * When we have a match break the loop. + */ + found = true; + break; + } + } + + /* + * If we didn't consume this parameter we add it to the plugin_options list. + */ + if (!found) { + PoolMem option(PM_FNAME); + + if (cnt) { + Mmsg(option, ":%s=%s", argument, argument_value); + PmStrcat(plugin_options, option.c_str()); + } else { + Mmsg(option, "%s=%s", argument, argument_value); + PmStrcat(plugin_options, option.c_str()); + } + cnt++; + } + } + + if (cnt > 0) { PmStrcat(plugin_options, ":"); } + + return bRC_OK; + +bail_out: + return bRC_Error; +} + /** * Initial load of the Python module. diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/bareosfd.h new file mode 100644 index 00000000000..8d870c628d0 --- /dev/null +++ b/core/src/plugins/filed/python/bareosfd.h @@ -0,0 +1,1031 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2013-2014 Planets Communications B.V. + Copyright (C) 2013-2020 Bareos GmbH & Co. KG + + This program is Free Software; you can modify it under the terms of + version three of the GNU Affero General Public License as published by the + Free Software Foundation, which is listed in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +/** + * @file + * This defines the Python types in C++ and the callbacks from Python we + * support. + */ + +#ifndef BAREOS_PLUGINS_FILED_BAREOS_FD_H_ +#define BAREOS_PLUGINS_FILED_BAREOS_FD_H_ 1 + +#define PYTHON_MODULE_NAME bareosfd +#define PYTHON_MODULE_NAME_QUOTED "bareosfd" + +/* common code for all python plugins */ +#include "plugins/python_plugins_common.h" +#include "plugins/filed/fd_common.h" + +#include "structmember.h" + +namespace filedaemon { + +/** + * This defines the arguments that the plugin parser understands. + */ +enum plugin_argument_type +{ + argument_none, + argument_module_path, + argument_module_name +}; + +struct plugin_argument { + const char* name; + enum plugin_argument_type type; +}; + +static plugin_argument plugin_arguments[] = { + {"module_path", argument_module_path}, + {"module_name", argument_module_name}, + {NULL, argument_none}}; + +/** + * Python structures mapping C++ ones. + */ + +/** + * This packet is used for the restore objects. + * It is passed to the plugin when restoring the object. + */ +typedef struct { + PyObject_HEAD PyObject* object_name; /* Object name */ + PyObject* object; /* Restore object data to restore */ + char* plugin_name; /* Plugin name */ + int32_t object_type; /* FT_xx for this file */ + int32_t object_len; /* restore object length */ + int32_t object_full_len; /* restore object uncompressed length */ + int32_t object_index; /* restore object index */ + int32_t object_compression; /* set to compression type */ + int32_t stream; /* attribute stream id */ + uint32_t JobId; /* JobId object came from */ +} PyRestoreObject; + +/** + * Forward declarations of type specific functions. + */ +static void PyRestoreObject_dealloc(PyRestoreObject* self); +static int PyRestoreObject_init(PyRestoreObject* self, + PyObject* args, + PyObject* kwds); +static PyObject* PyRestoreObject_repr(PyRestoreObject* self); + +static PyMethodDef PyRestoreObject_methods[] = { + {NULL} /* Sentinel */ +}; + +static PyMemberDef PyRestoreObject_members[] = { + {(char*)"object_name", T_OBJECT, offsetof(PyRestoreObject, object_name), 0, + (char*)"Object Name"}, + {(char*)"object", T_OBJECT, offsetof(PyRestoreObject, object), 0, + (char*)"Object Content"}, + {(char*)"plugin_name", T_STRING, offsetof(PyRestoreObject, plugin_name), 0, + (char*)"Plugin Name"}, + {(char*)"object_type", T_INT, offsetof(PyRestoreObject, object_type), 0, + (char*)"Object Type"}, + {(char*)"object_len", T_INT, offsetof(PyRestoreObject, object_len), 0, + (char*)"Object Length"}, + {(char*)"object_full_len", T_INT, + offsetof(PyRestoreObject, object_full_len), 0, + (char*)"Object Full Length"}, + {(char*)"object_index", T_INT, offsetof(PyRestoreObject, object_index), 0, + (char*)"Object Index"}, + {(char*)"object_compression", T_INT, + offsetof(PyRestoreObject, object_compression), 0, + (char*)"Object Compression"}, + {(char*)"stream", T_INT, offsetof(PyRestoreObject, stream), 0, + (char*)"Attribute Stream"}, + {(char*)"jobid", T_UINT, offsetof(PyRestoreObject, JobId), 0, + (char*)"Jobid"}, + {NULL}}; + +static PyTypeObject PyRestoreObjectType = { + PyVarObject_HEAD_INIT(NULL, 0) "restore_object", /* tp_name */ + sizeof(PyRestoreObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)PyRestoreObject_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + (reprfunc)PyRestoreObject_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/ + "io_pkt object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PyRestoreObject_methods, /* tp_methods */ + PyRestoreObject_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)PyRestoreObject_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/** + * The PyStatPacket type + */ +typedef struct { + PyObject_HEAD uint32_t dev; + uint64_t ino; + uint16_t mode; + int16_t nlink; + uint32_t uid; + uint32_t gid; + uint32_t rdev; + uint64_t size; + time_t atime; + time_t mtime; + time_t ctime; + uint32_t blksize; + uint64_t blocks; +} PyStatPacket; + +/** + * Forward declarations of type specific functions. + */ +static void PyStatPacket_dealloc(PyStatPacket* self); +static int PyStatPacket_init(PyStatPacket* self, + PyObject* args, + PyObject* kwds); +static PyObject* PyStatPacket_repr(PyStatPacket* self); + +static PyMethodDef PyStatPacket_methods[] = { + {NULL} /* Sentinel */ +}; + +static PyMemberDef PyStatPacket_members[] = { + {(char*)"st_dev", T_UINT, offsetof(PyStatPacket, dev), 0, (char*)"Device"}, + {(char*)"st_ino", T_ULONGLONG, offsetof(PyStatPacket, ino), 0, + (char*)"Inode number"}, + {(char*)"st_mode", T_USHORT, offsetof(PyStatPacket, mode), 0, + (char*)"Mode"}, + {(char*)"st_nlink", T_USHORT, offsetof(PyStatPacket, nlink), 0, + (char*)"Number of hardlinks"}, + {(char*)"st_uid", T_UINT, offsetof(PyStatPacket, uid), 0, (char*)"User Id"}, + {(char*)"st_gid", T_UINT, offsetof(PyStatPacket, gid), 0, + (char*)"Group Id"}, + {(char*)"st_rdev", T_UINT, offsetof(PyStatPacket, rdev), 0, (char*)"Rdev"}, + {(char*)"st_size", T_ULONGLONG, offsetof(PyStatPacket, size), 0, + (char*)"Size"}, + {(char*)"st_atime", T_UINT, offsetof(PyStatPacket, atime), 0, + (char*)"Access Time"}, + {(char*)"st_mtime", T_UINT, offsetof(PyStatPacket, mtime), 0, + (char*)"Modification Time"}, + {(char*)"st_ctime", T_UINT, offsetof(PyStatPacket, ctime), 0, + (char*)"Change Time"}, + {(char*)"st_blksize", T_UINT, offsetof(PyStatPacket, blksize), 0, + (char*)"Blocksize"}, + {(char*)"st_blocks", T_ULONGLONG, offsetof(PyStatPacket, blocks), 0, + (char*)"Blocks"}, + {NULL}}; + +static PyTypeObject PyStatPacketType = { + PyVarObject_HEAD_INIT(NULL, 0) "stat_pkt", /* tp_name */ + sizeof(PyStatPacket), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)PyStatPacket_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + (reprfunc)PyStatPacket_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/ + "io_pkt object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PyStatPacket_methods, /* tp_methods */ + PyStatPacket_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)PyStatPacket_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/** + * The PySavePacket type + */ +typedef struct { + PyObject_HEAD PyObject* fname; /* Full path and filename */ + PyObject* link; /* Link name if any */ + PyObject* statp; /* System stat() packet for file */ + int32_t type; /* FT_xx for this file */ + PyObject* flags; /* Bareos internal flags */ + bool no_read; /* During the save, the file should not be saved */ + bool portable; /* set if data format is portable */ + bool accurate_found; /* Found in accurate list (valid after CheckChanges()) */ + char* cmd; /* Command */ + time_t save_time; /* Start of incremental time */ + uint32_t delta_seq; /* Delta sequence number */ + PyObject* object_name; /* Object name to create */ + PyObject* object; /* Restore object data to save */ + int32_t object_len; /* Restore object length */ + int32_t object_index; /* Restore object index */ +} PySavePacket; + +/** + * Forward declarations of type specific functions. + */ +static void PySavePacket_dealloc(PySavePacket* self); +static int PySavePacket_init(PySavePacket* self, + PyObject* args, + PyObject* kwds); +static PyObject* PySavePacket_repr(PySavePacket* self); + +static PyMethodDef PySavePacket_methods[] = { + {NULL} /* Sentinel */ +}; + +static PyMemberDef PySavePacket_members[] = { + {(char*)"fname", T_OBJECT, offsetof(PySavePacket, fname), 0, + (char*)"Filename"}, + {(char*)"link", T_OBJECT, offsetof(PySavePacket, link), 0, + (char*)"Linkname"}, + {(char*)"statp", T_OBJECT, offsetof(PySavePacket, statp), 0, + (char*)"Stat Packet"}, + {(char*)"type", T_INT, offsetof(PySavePacket, type), 0, (char*)"Type"}, + {(char*)"flags", T_OBJECT, offsetof(PySavePacket, flags), 0, + (char*)"Flags"}, + {(char*)"no_read", T_BOOL, offsetof(PySavePacket, no_read), 0, + (char*)"No Read"}, + {(char*)"portable", T_BOOL, offsetof(PySavePacket, portable), 0, + (char*)"Portable"}, + {(char*)"accurate_found", T_BOOL, offsetof(PySavePacket, accurate_found), 0, + (char*)"Accurate Found"}, + {(char*)"cmd", T_STRING, offsetof(PySavePacket, cmd), 0, (char*)"Command"}, + {(char*)"save_time", T_UINT, offsetof(PySavePacket, save_time), 0, + (char*)"Save Time"}, + {(char*)"delta_seq", T_UINT, offsetof(PySavePacket, delta_seq), 0, + (char*)"Delta Sequence"}, + {(char*)"object_name", T_OBJECT, offsetof(PySavePacket, object_name), 0, + (char*)"Restore Object Name"}, + {(char*)"object", T_OBJECT, offsetof(PySavePacket, object), 0, + (char*)"Restore ObjectName"}, + {(char*)"object_len", T_INT, offsetof(PySavePacket, object_len), 0, + (char*)"Restore ObjectLen"}, + {(char*)"object_index", T_INT, offsetof(PySavePacket, object_index), 0, + (char*)"Restore ObjectIndex"}, + {NULL}}; + +static PyTypeObject PySavePacketType = { + PyVarObject_HEAD_INIT(NULL, 0) "save_pkt", /* tp_name */ + sizeof(PySavePacket), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)PySavePacket_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + (reprfunc)PySavePacket_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/ + "save_pkt object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PySavePacket_methods, /* tp_methods */ + PySavePacket_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)PySavePacket_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/** + * The PyRestorePacket type + */ +typedef struct { + PyObject_HEAD int32_t stream; /* Attribute stream id */ + int32_t data_stream; /* Id of data stream to follow */ + int32_t type; /* File type FT */ + int32_t file_index; /* File index */ + int32_t LinkFI; /* File index to data if hard link */ + uint32_t uid; /* Userid */ + PyObject* statp; /* Decoded stat packet */ + const char* attrEx; /* Extended attributes if any */ + const char* ofname; /* Output filename */ + const char* olname; /* Output link name */ + const char* where; /* Where */ + const char* RegexWhere; /* Regex where */ + int replace; /* Replace flag */ + int create_status; /* Status from createFile() */ +} PyRestorePacket; + +/** + * Forward declarations of type specific functions. + */ +static void PyRestorePacket_dealloc(PyRestorePacket* self); +static int PyRestorePacket_init(PyRestorePacket* self, + PyObject* args, + PyObject* kwds); +static PyObject* PyRestorePacket_repr(PyRestorePacket* self); + +static PyMethodDef PyRestorePacket_methods[] = { + {NULL} /* Sentinel */ +}; + +static PyMemberDef PyRestorePacket_members[] = { + {(char*)"stream", T_INT, offsetof(PyRestorePacket, stream), 0, + (char*)"Attribute stream id"}, + {(char*)"data_stream", T_INT, offsetof(PyRestorePacket, data_stream), 0, + (char*)"Id of data stream to follow"}, + {(char*)"type", T_INT, offsetof(PyRestorePacket, type), 0, + (char*)"File type FT"}, + {(char*)"file_index", T_INT, offsetof(PyRestorePacket, file_index), 0, + (char*)"File index"}, + {(char*)"linkFI", T_INT, offsetof(PyRestorePacket, LinkFI), 0, + (char*)"File index to data if hard link"}, + {(char*)"uid", T_UINT, offsetof(PyRestorePacket, uid), 0, (char*)"User Id"}, + {(char*)"statp", T_OBJECT, offsetof(PyRestorePacket, statp), 0, + (char*)"Stat Packet"}, + {(char*)"attrEX", T_STRING, offsetof(PyRestorePacket, attrEx), 0, + (char*)"Extended attributes"}, + {(char*)"ofname", T_STRING, offsetof(PyRestorePacket, ofname), 0, + (char*)"Output filename"}, + {(char*)"olname", T_STRING, offsetof(PyRestorePacket, olname), 0, + (char*)"Output link name"}, + {(char*)"where", T_STRING, offsetof(PyRestorePacket, where), 0, + (char*)"Where"}, + {(char*)"regexwhere", T_STRING, offsetof(PyRestorePacket, RegexWhere), 0, + (char*)"Regex where"}, + {(char*)"replace", T_INT, offsetof(PyRestorePacket, replace), 0, + (char*)"Replace flag"}, + {(char*)"create_status", T_INT, offsetof(PyRestorePacket, create_status), 0, + (char*)"Status from createFile()"}, + {NULL}}; + +static PyTypeObject PyRestorePacketType = { + PyVarObject_HEAD_INIT(NULL, 0) "restore_pkt", /* tp_name */ + sizeof(PyRestorePacket), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)PyRestorePacket_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + (reprfunc)PyRestorePacket_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/ + "restore_pkt object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PyRestorePacket_methods, /* tp_methods */ + PyRestorePacket_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)PyRestorePacket_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/** + * The PyIOPacket type + */ +typedef struct { + PyObject_HEAD uint16_t func; /* Function code */ + int32_t count; /* Read/Write count */ + int32_t flags; /* Open flags */ + int32_t mode; /* Permissions for created files */ + PyObject* buf; /* Read/Write buffer */ + const char* fname; /* Open filename */ + int32_t status; /* Return status */ + int32_t io_errno; /* Errno code */ + int32_t lerror; /* Win32 error code */ + int32_t whence; /* Lseek argument */ + int64_t offset; /* Lseek argument */ + bool win32; /* Win32 GetLastError returned */ +} PyIoPacket; + +/** + * Forward declarations of type specific functions. + */ +static void PyIoPacket_dealloc(PyIoPacket* self); +static int PyIoPacket_init(PyIoPacket* self, PyObject* args, PyObject* kwds); +static PyObject* PyIoPacket_repr(PyIoPacket* self); + +static PyMethodDef PyIoPacket_methods[] = { + {NULL} /* Sentinel */ +}; + +static PyMemberDef PyIoPacket_members[] = { + {(char*)"func", T_USHORT, offsetof(PyIoPacket, func), 0, + (char*)"Function code"}, + {(char*)"count", T_INT, offsetof(PyIoPacket, count), 0, + (char*)"Read/write count"}, + {(char*)"flags", T_INT, offsetof(PyIoPacket, flags), 0, + (char*)"Open flags"}, + {(char*)"mode", T_INT, offsetof(PyIoPacket, mode), 0, + (char*)"Permissions for created files"}, + {(char*)"buf", T_OBJECT, offsetof(PyIoPacket, buf), 0, + (char*)"Read/write buffer"}, + {(char*)"fname", T_STRING, offsetof(PyIoPacket, fname), 0, + (char*)"Open filename"}, + {(char*)"status", T_INT, offsetof(PyIoPacket, status), 0, + (char*)"Return status"}, + {(char*)"io_errno", T_INT, offsetof(PyIoPacket, io_errno), 0, + (char*)"Errno code"}, + {(char*)"lerror", T_INT, offsetof(PyIoPacket, lerror), 0, + (char*)"Win32 error code"}, + {(char*)"whence", T_INT, offsetof(PyIoPacket, whence), 0, + (char*)"Lseek argument"}, + {(char*)"offset", T_LONGLONG, offsetof(PyIoPacket, offset), 0, + (char*)"Lseek argument"}, + {(char*)"win32", T_BOOL, offsetof(PyIoPacket, win32), 0, + (char*)"Win32 GetLastError returned"}, + {NULL}}; + +static PyTypeObject PyIoPacketType = { + PyVarObject_HEAD_INIT(NULL, 0) "io_pkt", /* tp_name */ + sizeof(PyIoPacket), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)PyIoPacket_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + (reprfunc)PyIoPacket_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/ + "io_pkt object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PyIoPacket_methods, /* tp_methods */ + PyIoPacket_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)PyIoPacket_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/** + * The PyAclPacket type + */ +typedef struct { + PyObject_HEAD const char* fname; /* Filename */ + PyObject* content; /* ACL content */ +} PyAclPacket; + +/** + * Forward declarations of type specific functions. + */ +static void PyAclPacket_dealloc(PyAclPacket* self); +static int PyAclPacket_init(PyAclPacket* self, PyObject* args, PyObject* kwds); +static PyObject* PyAclPacket_repr(PyAclPacket* self); + +static PyMethodDef PyAclPacket_methods[] = { + {NULL} /* Sentinel */ +}; + +static PyMemberDef PyAclPacket_members[] = { + {(char*)"fname", T_STRING, offsetof(PyAclPacket, fname), 0, + (char*)"Filename"}, + {(char*)"content", T_OBJECT, offsetof(PyAclPacket, content), 0, + (char*)"ACL content buffer"}, + {NULL}}; + +static PyTypeObject PyAclPacketType = { + PyVarObject_HEAD_INIT(NULL, 0) "acl_pkt", /* tp_name */ + sizeof(PyAclPacket), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)PyAclPacket_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + (reprfunc)PyAclPacket_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/ + "acl_pkt object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PyAclPacket_methods, /* tp_methods */ + PyAclPacket_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)PyAclPacket_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/** + * The PyXattrPacket type + */ +typedef struct { + PyObject_HEAD const char* fname; /* Filename */ + PyObject* name; /* XATTR name */ + PyObject* value; /* XATTR value */ +} PyXattrPacket; + +/** + * Forward declarations of type specific functions. + */ +static void PyXattrPacket_dealloc(PyXattrPacket* self); +static int PyXattrPacket_init(PyXattrPacket* self, + PyObject* args, + PyObject* kwds); +static PyObject* PyXattrPacket_repr(PyXattrPacket* self); + +static PyMethodDef PyXattrPacket_methods[] = { + {NULL} /* Sentinel */ +}; + +static PyMemberDef PyXattrPacket_members[] = { + {(char*)"fname", T_STRING, offsetof(PyXattrPacket, fname), 0, + (char*)"Filename"}, + {(char*)"name", T_OBJECT, offsetof(PyXattrPacket, name), 0, + (char*)"XATTR name buffer"}, + {(char*)"value", T_OBJECT, offsetof(PyXattrPacket, value), 0, + (char*)"XATTR value buffer"}, + {NULL}}; + +static PyTypeObject PyXattrPacketType = { + PyVarObject_HEAD_INIT(NULL, 0) "xattr_pkt", /* tp_name */ + sizeof(PyXattrPacket), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)PyXattrPacket_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + (reprfunc)PyXattrPacket_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/ + "xattr_pkt object", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PyXattrPacket_methods, /* tp_methods */ + PyXattrPacket_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)PyXattrPacket_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +/** + * Callback methods from Python. + */ +static PyObject* PyBareosGetValue(PyObject* self, PyObject* args); +static PyObject* PyBareosSetValue(PyObject* self, PyObject* args); +static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args); +static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args); +static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args); +static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args); +static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args); +static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args); +static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args); +static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args); +static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args); +static PyObject* PyBareosAddWild(PyObject* self, PyObject* args); +static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args); +static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args); +static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args); +static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args); +static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args); +static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args); +static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args); + +static PyMethodDef Methods[] = { + {"GetValue", PyBareosGetValue, METH_VARARGS, "Get a Plugin value"}, + {"SetValue", PyBareosSetValue, METH_VARARGS, "Set a Plugin value"}, + {"DebugMessage", PyBareosDebugMessage, METH_VARARGS, + "Print a Debug message"}, + {"JobMessage", PyBareosJobMessage, METH_VARARGS, "Print a Job message"}, + {"RegisterEvents", PyBareosRegisterEvents, METH_VARARGS, + "Register Plugin Events"}, + {"UnRegisterEvents", PyBareosUnRegisterEvents, METH_VARARGS, + "Unregister Plugin Events"}, + {"GetInstanceCount", PyBareosGetInstanceCount, METH_VARARGS, + "Get number of instances of current plugin"}, + {"AddExclude", PyBareosAddExclude, METH_VARARGS, "Add Exclude pattern"}, + {"AddInclude", PyBareosAddInclude, METH_VARARGS, "Add Include pattern"}, + {"AddOptions", PyBareosAddOptions, METH_VARARGS, "Add Include options"}, + {"AddRegex", PyBareosAddRegex, METH_VARARGS, "Add regex"}, + {"AddWild", PyBareosAddWild, METH_VARARGS, "Add wildcard"}, + {"NewOptions", PyBareosNewOptions, METH_VARARGS, "Add new option block"}, + {"NewInclude", PyBareosNewInclude, METH_VARARGS, "Add new include block"}, + {"NewPreInclude", PyBareosNewPreInclude, METH_VARARGS, + "Add new pre include block"}, + {"CheckChanges", PyBareosCheckChanges, METH_VARARGS, + "Check if a file have to be backed up using Accurate code"}, + {"AcceptFile", PyBareosAcceptFile, METH_VARARGS, + "Check if a file would be saved using current Include/Exclude code"}, + {"SetSeenBitmap", PyBareosSetSeenBitmap, METH_VARARGS, + "Set bit in the Accurate Seen bitmap"}, + {"ClearSeenBitmap", PyBareosClearSeenBitmap, METH_VARARGS, + "Clear bit in the Accurate Seen bitmap"}, + {NULL, NULL, 0, NULL}}; + + +} /* namespace filedaemon */ +using namespace filedaemon; + +/* variables storing bareos pointers */ +static void* bareos_PluginContext = NULL; +static void* bareos_core_functions = NULL; + +#ifdef __cplusplus +extern "C" { +#endif +/* Forward declaration of loadPlugin() as it is stored in Capsule */ +bRC loadPlugin(::Core_PluginApiDefinition* lbareos_plugin_interface_version, + BareosCoreFunctions* lbareos_core_functions, + PluginInformation** plugin_information, + pFuncs** plugin_functions); +#ifdef __cplusplus +} +#endif + + +MOD_INIT(bareosfd) +{ + PyObject* m = NULL; + MOD_DEF(m, PYTHON_MODULE_NAME_QUOTED, NULL, Methods) + + + /* add PluginContext Capsule */ + PyObject* PyModulePluginContext = + PyCapsule_New((void*)&bareos_PluginContext, + PYTHON_MODULE_NAME_QUOTED ".PluginContext", NULL); + if (!PyModulePluginContext) { + printf(PYTHON_MODULE_NAME_QUOTED ":PluginContext PyCapsule_New failed\n"); + return MOD_ERROR_VAL; + } + if (PyModulePluginContext) { + PyModule_AddObject(m, "PluginContext", PyModulePluginContext); + printf(PYTHON_MODULE_NAME_QUOTED ": added PluginContext@%p\n", + &bareos_PluginContext); + } else { + printf(PYTHON_MODULE_NAME_QUOTED + ":PluginContext PyModule_AddObject failed\n"); + return MOD_ERROR_VAL; + } + + /* add bpFuncs Capsule */ + PyObject* PyModulePluginFuncs = + PyCapsule_New((void*)&bareos_core_functions, + PYTHON_MODULE_NAME_QUOTED ".BareosCoreFunctions", NULL); + if (!PyModulePluginFuncs) { + printf(PYTHON_MODULE_NAME_QUOTED + ":BareosCoreFunctions PyCapsule_New failed\n"); + return MOD_ERROR_VAL; + } + if (PyModulePluginFuncs) { + PyModule_AddObject(m, "BareosCoreFunctions", PyModulePluginFuncs); + printf(PYTHON_MODULE_NAME_QUOTED ": added BareosCoreFunctions@%p\n", + &bareos_core_functions); + } else { + printf(PYTHON_MODULE_NAME_QUOTED + ":BareosCoreFunctions PyModule_AddObject failed\n"); + return MOD_ERROR_VAL; + } + + /* add loadPlugin Capsule */ + PyObject* PyModuleLoadPlugin = PyCapsule_New( + (void*)&loadPlugin, PYTHON_MODULE_NAME_QUOTED ".loadPlugin", NULL); + if (!PyModuleLoadPlugin) { + printf(PYTHON_MODULE_NAME_QUOTED "loadPlugin PyCapsule_New failed\n"); + return MOD_ERROR_VAL; + } + if (PyModuleLoadPlugin) { + PyModule_AddObject(m, "loadPlugin", PyModuleLoadPlugin); + printf(PYTHON_MODULE_NAME_QUOTED ": added loadPlugin@%p\n", &loadPlugin); + } else { + printf(PYTHON_MODULE_NAME_QUOTED "loadPlugin PyModule_AddObject failed\n"); + return MOD_ERROR_VAL; + } + + + PyRestoreObjectType.tp_new = PyType_GenericNew; + if (PyType_Ready(&PyRestoreObjectType) < 0) { return MOD_ERROR_VAL; } + + PyStatPacketType.tp_new = PyType_GenericNew; + if (PyType_Ready(&PyStatPacketType) < 0) { return MOD_ERROR_VAL; } + + PySavePacketType.tp_new = PyType_GenericNew; + if (PyType_Ready(&PySavePacketType) < 0) { return MOD_ERROR_VAL; } + + PyRestorePacketType.tp_new = PyType_GenericNew; + if (PyType_Ready(&PyRestorePacketType) < 0) { return MOD_ERROR_VAL; } + + PyIoPacketType.tp_new = PyType_GenericNew; + if (PyType_Ready(&PyIoPacketType) < 0) { return MOD_ERROR_VAL; } + + PyAclPacketType.tp_new = PyType_GenericNew; + if (PyType_Ready(&PyAclPacketType) < 0) { return MOD_ERROR_VAL; } + + PyXattrPacketType.tp_new = PyType_GenericNew; + if (PyType_Ready(&PyXattrPacketType) < 0) { return MOD_ERROR_VAL; } + + Py_INCREF(&PyRestoreObjectType); + PyModule_AddObject(m, "RestoreObject", (PyObject*)&PyRestoreObjectType); + + Py_INCREF(&PyStatPacketType); + PyModule_AddObject(m, "StatPacket", (PyObject*)&PyStatPacketType); + + Py_INCREF(&PySavePacketType); + PyModule_AddObject(m, "SavePacket", (PyObject*)&PySavePacketType); + + Py_INCREF(&PyRestorePacketType); + PyModule_AddObject(m, "RestorePacket", (PyObject*)&PyRestorePacketType); + + Py_INCREF(&PyIoPacketType); + PyModule_AddObject(m, "IoPacket", (PyObject*)&PyIoPacketType); + + Py_INCREF(&PyAclPacketType); + PyModule_AddObject(m, "AclPacket", (PyObject*)&PyAclPacketType); + + Py_INCREF(&PyXattrPacketType); + PyModule_AddObject(m, "XattrPacket", (PyObject*)&PyXattrPacketType); + + + /* module dictionaries */ + DEFINE_bRCs_DICT(); + DEFINE_bJobMessageTypes_DICT(); + + const char* bVariable = "bVariable"; + PyObject* pDictbVariable = NULL; + pDictbVariable = PyDict_New(); + if (!pDictbVariable) { return MOD_ERROR_VAL; } + ConstSet_StrLong(pDictbVariable, bVarJobId, 1); + ConstSet_StrLong(pDictbVariable, bVarFDName, 2); + ConstSet_StrLong(pDictbVariable, bVarLevel, 3); + ConstSet_StrLong(pDictbVariable, bVarType, 4); + ConstSet_StrLong(pDictbVariable, bVarClient, 5); + ConstSet_StrLong(pDictbVariable, bVarJobName, 6); + ConstSet_StrLong(pDictbVariable, bVarJobStatus, 7); + ConstSet_StrLong(pDictbVariable, bVarSinceTime, 8); + ConstSet_StrLong(pDictbVariable, bVarAccurate, 9); + ConstSet_StrLong(pDictbVariable, bVarFileSeen, 10); + ConstSet_StrLong(pDictbVariable, bVarVssClient, 11); + ConstSet_StrLong(pDictbVariable, bVarWorkingDir, 12); + ConstSet_StrLong(pDictbVariable, bVarWhere, 13); + ConstSet_StrLong(pDictbVariable, bVarRegexWhere, 14); + ConstSet_StrLong(pDictbVariable, bVarExePath, 15); + ConstSet_StrLong(pDictbVariable, bVarVersion, 16); + ConstSet_StrLong(pDictbVariable, bVarDistName, 17); + ConstSet_StrLong(pDictbVariable, bVarPrevJobName, 18); + ConstSet_StrLong(pDictbVariable, bVarPrefixLinks, 19); + if (PyModule_AddObject(m, bVariable, pDictbVariable)) { + return MOD_ERROR_VAL; + } + + + const char* bFileType = "bFileType"; + PyObject* pDictbFileType = NULL; + pDictbFileType = PyDict_New(); + ConstSet_StrLong(pDictbFileType, FT_LNKSAVED, 1); + ConstSet_StrLong(pDictbFileType, FT_REGE, 2); + ConstSet_StrLong(pDictbFileType, FT_REG, 3); + ConstSet_StrLong(pDictbFileType, FT_LNK, 4); + ConstSet_StrLong(pDictbFileType, FT_DIREND, 5); + ConstSet_StrLong(pDictbFileType, FT_SPEC, 6); + ConstSet_StrLong(pDictbFileType, FT_NOACCESS, 7); + ConstSet_StrLong(pDictbFileType, FT_NOFOLLOW, 8); + ConstSet_StrLong(pDictbFileType, FT_NOSTAT, 9); + ConstSet_StrLong(pDictbFileType, FT_NOCHG, 10); + ConstSet_StrLong(pDictbFileType, FT_DIRNOCHG, 11); + ConstSet_StrLong(pDictbFileType, FT_ISARCH, 12); + ConstSet_StrLong(pDictbFileType, FT_NORECURSE, 13); + ConstSet_StrLong(pDictbFileType, FT_NOFSCHG, 14); + ConstSet_StrLong(pDictbFileType, FT_NOOPEN, 15); + ConstSet_StrLong(pDictbFileType, FT_RAW, 16); + ConstSet_StrLong(pDictbFileType, FT_FIFO, 17); + ConstSet_StrLong(pDictbFileType, FT_DIRBEGIN, 18); + ConstSet_StrLong(pDictbFileType, FT_INVALIDFS, 19); + ConstSet_StrLong(pDictbFileType, FT_INVALIDDT, 20); + ConstSet_StrLong(pDictbFileType, FT_REPARSE, 21); + ConstSet_StrLong(pDictbFileType, FT_PLUGIN, 22); + ConstSet_StrLong(pDictbFileType, FT_DELETED, 23); + ConstSet_StrLong(pDictbFileType, FT_BASE, 24); + ConstSet_StrLong(pDictbFileType, FT_RESTORE_FIRST, 25); + ConstSet_StrLong(pDictbFileType, FT_JUNCTION, 26); + ConstSet_StrLong(pDictbFileType, FT_PLUGIN_CONFIG, 27); + ConstSet_StrLong(pDictbFileType, FT_PLUGIN_CONFIG_FILLED, 28); + if (!pDictbFileType) { return MOD_ERROR_VAL; } + if (PyModule_AddObject(m, bFileType, pDictbFileType)) { + return MOD_ERROR_VAL; + } + + + const char* bCFs = "bCFs"; + PyObject* pDictbCFs = NULL; + pDictbCFs = PyDict_New(); + ConstSet_StrLong(pDictbCFs, CF_SKIP, 1); + ConstSet_StrLong(pDictbCFs, CF_ERROR, 2); + ConstSet_StrLong(pDictbCFs, CF_EXTRACT, 3); + ConstSet_StrLong(pDictbCFs, CF_CREATED, 4); + ConstSet_StrLong(pDictbCFs, CF_CORE, 5); + if (!pDictbCFs) { return MOD_ERROR_VAL; } + if (PyModule_AddObject(m, bCFs, pDictbCFs)) { return MOD_ERROR_VAL; } + + const char* bEventType = "bEventType"; + PyObject* pDictbEventType = NULL; + pDictbEventType = PyDict_New(); + ConstSet_StrLong(pDictbEventType, bEventJobStart, 1); + ConstSet_StrLong(pDictbEventType, bEventJobEnd, 2); + ConstSet_StrLong(pDictbEventType, bEventStartBackupJob, 3); + ConstSet_StrLong(pDictbEventType, bEventEndBackupJob, 4); + ConstSet_StrLong(pDictbEventType, bEventStartRestoreJob, 5); + ConstSet_StrLong(pDictbEventType, bEventEndRestoreJob, 6); + ConstSet_StrLong(pDictbEventType, bEventStartVerifyJob, 7); + ConstSet_StrLong(pDictbEventType, bEventEndVerifyJob, 8); + ConstSet_StrLong(pDictbEventType, bEventBackupCommand, 9); + ConstSet_StrLong(pDictbEventType, bEventRestoreCommand, 10); + ConstSet_StrLong(pDictbEventType, bEventEstimateCommand, 11); + ConstSet_StrLong(pDictbEventType, bEventLevel, 12); + ConstSet_StrLong(pDictbEventType, bEventSince, 13); + ConstSet_StrLong(pDictbEventType, bEventCancelCommand, 14); + ConstSet_StrLong(pDictbEventType, bEventRestoreObject, 15); + ConstSet_StrLong(pDictbEventType, bEventEndFileSet, 16); + ConstSet_StrLong(pDictbEventType, bEventPluginCommand, 17); + ConstSet_StrLong(pDictbEventType, bEventOptionPlugin, 18); + ConstSet_StrLong(pDictbEventType, bEventHandleBackupFile, 19); + ConstSet_StrLong(pDictbEventType, bEventNewPluginOptions, 20); + ConstSet_StrLong(pDictbEventType, bEventVssInitializeForBackup, 21); + ConstSet_StrLong(pDictbEventType, bEventVssInitializeForRestore, 22); + ConstSet_StrLong(pDictbEventType, bEventVssSetBackupState, 23); + ConstSet_StrLong(pDictbEventType, bEventVssPrepareForBackup, 24); + ConstSet_StrLong(pDictbEventType, bEventVssBackupAddComponents, 25); + ConstSet_StrLong(pDictbEventType, bEventVssPrepareSnapshot, 26); + ConstSet_StrLong(pDictbEventType, bEventVssCreateSnapshots, 27); + ConstSet_StrLong(pDictbEventType, bEventVssRestoreLoadComponentMetadata, 28); + ConstSet_StrLong(pDictbEventType, bEventVssRestoreSetComponentsSelected, 29); + ConstSet_StrLong(pDictbEventType, bEventVssCloseRestore, 30); + ConstSet_StrLong(pDictbEventType, bEventVssBackupComplete, 31); + if (!pDictbEventType) { return MOD_ERROR_VAL; } + if (PyModule_AddObject(m, bEventType, pDictbEventType)) { + return MOD_ERROR_VAL; + } + + + const char* bIOPS = "bIOPS"; + PyObject* pDictbIOPS = NULL; + pDictbIOPS = PyDict_New(); + ConstSet_StrLong(pDictbIOPS, IO_OPEN, 1); + ConstSet_StrLong(pDictbIOPS, IO_READ, 2); + ConstSet_StrLong(pDictbIOPS, IO_WRITE, 3); + ConstSet_StrLong(pDictbIOPS, IO_CLOSE, 4); + ConstSet_StrLong(pDictbIOPS, IO_SEEK, 5); + if (!pDictbIOPS) { return MOD_ERROR_VAL; } + if (PyModule_AddObject(m, bIOPS, pDictbIOPS)) { return MOD_ERROR_VAL; } + + + const char* bLevels = "bLevels"; + PyObject* pDictbLevels = NULL; + pDictbLevels = PyDict_New(); + ConstSet_StrStr(pDictbLevels, L_FULL, "F"); + ConstSet_StrStr(pDictbLevels, L_INCREMENTAL, "I"); + ConstSet_StrStr(pDictbLevels, L_DIFFERENTIAL, "D"); + ConstSet_StrStr(pDictbLevels, L_SINCE, "S"); + ConstSet_StrStr(pDictbLevels, L_VERIFY_CATALOG, "C"); + ConstSet_StrStr(pDictbLevels, L_VERIFY_INIT, "V"); + ConstSet_StrStr(pDictbLevels, L_VERIFY_VOLUME_TO_CATALOG, "O"); + ConstSet_StrStr(pDictbLevels, L_VERIFY_DISK_TO_CATALOG, "d"); + ConstSet_StrStr(pDictbLevels, L_VERIFY_DATA, "A"); + ConstSet_StrStr(pDictbLevels, L_BASE, "B"); + ConstSet_StrStr(pDictbLevels, L_NONE, " "); + ConstSet_StrStr(pDictbLevels, L_VIRTUAL_FULL, "f"); + if (!pDictbLevels) { return MOD_ERROR_VAL; } + if (PyModule_AddObject(m, bLevels, pDictbLevels)) { return MOD_ERROR_VAL; } + + + return MOD_SUCCESS_VAL(m); +} + + +#endif /* BAREOS_PLUGINS_FILED_BAREOS_FD_H_ */ From 82d92414d9928ad2e6fb5dc511f55fee8ad52801 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 6 May 2020 17:37:01 +0200 Subject: [PATCH 070/341] bareosfd: introduced C_API --- core/src/plugins/filed/python/bareosfd.cc | 3 +- core/src/plugins/filed/python/bareosfd.h | 44 +++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index db6e3ced031..cd6153d2275 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -39,7 +39,7 @@ #include "filed/fd_plugins.h" - +#define BAREOSFD_MODULE #include "bareosfd.h" #include "lib/edit.h" @@ -248,7 +248,6 @@ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, } else { printf("loading of bareosfd failed\n"); } - if (PyErr_Occurred()) { PyErrorHandler(); } // Extract capsules pointer from bareosfd module void (*loadplugin_from_bareosfd_module)( diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/bareosfd.h index 8d870c628d0..b56446d78b7 100644 --- a/core/src/plugins/filed/python/bareosfd.h +++ b/core/src/plugins/filed/python/bareosfd.h @@ -771,10 +771,54 @@ bRC loadPlugin(::Core_PluginApiDefinition* lbareos_plugin_interface_version, #endif +/* C API functions */ +#define Bareosfd_PyLoadModule_NUM 0 +#define Bareosfd_PyLoadModule_RETURN bRC +#define Bareosfd_PyLoadModule_PROTO \ + (PluginContext * bareos_plugin_ctx, void* value); + + +/* Total number of C API pointers */ +#define Bareosfd_API_pointers 1 + +#ifdef BAREOSFD_MODULE +/* This section is used when compiling bareosfd.cc */ + +static Bareosfd_PyLoadModule_RETURN Bareosfd_PyLoadModule + Bareosfd_PyLoadModule_PROTO; + +#else +/* This section is used in modules that use bareosfd's API */ + +static void** Bareosfd_API; + +#define Bareosfd_PyLoadModule \ + (*(Bareosfd_PyLoadModule_RETURN(*) \ + Bareosfd_PyLoadModule_PROTO)Bareosfd_API[Bareosfd_PyLoadModule_NUM]) + +static int import_bareosfd() +{ + Bareosfd_API = (void**)PyCapsule_Import("bareosfd._C_API", 0); + return (Bareosfd_API != NULL) ? 0 : -1; +} + +#endif // BAREOSFD_MODULE + MOD_INIT(bareosfd) { PyObject* m = NULL; MOD_DEF(m, PYTHON_MODULE_NAME_QUOTED, NULL, Methods) + static void* Bareosfd_API[Bareosfd_API_pointers]; + PyObject* c_api_object; + + /* Initialize the C API pointer array */ + Bareosfd_API[Bareosfd_PyLoadModule_NUM] = (void*)Bareosfd_PyLoadModule; + + /* Create a Capsule containing the API pointer array's address */ + c_api_object = PyCapsule_New((void*)Bareosfd_API, + PYTHON_MODULE_NAME_QUOTED "._C_API", NULL); + + if (c_api_object != NULL) PyModule_AddObject(m, "_C_API", c_api_object); /* add PluginContext Capsule */ From 5a3ed5b1de1aff21158784f11171d5f9fb940dd2 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 6 May 2020 18:04:02 +0200 Subject: [PATCH 071/341] bareosfd python plugin: C_API import works --- core/src/plugins/filed/python/bareosfd.h | 4 +++- .../filed/python/test/python-fd-module-tester.cc | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/bareosfd.h index b56446d78b7..7efde64f0e8 100644 --- a/core/src/plugins/filed/python/bareosfd.h +++ b/core/src/plugins/filed/python/bareosfd.h @@ -751,6 +751,7 @@ static PyMethodDef Methods[] = { {NULL, NULL, 0, NULL}}; +static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); } /* namespace filedaemon */ using namespace filedaemon; @@ -766,6 +767,7 @@ bRC loadPlugin(::Core_PluginApiDefinition* lbareos_plugin_interface_version, BareosCoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, pFuncs** plugin_functions); + #ifdef __cplusplus } #endif @@ -812,7 +814,7 @@ MOD_INIT(bareosfd) PyObject* c_api_object; /* Initialize the C API pointer array */ - Bareosfd_API[Bareosfd_PyLoadModule_NUM] = (void*)Bareosfd_PyLoadModule; + Bareosfd_API[Bareosfd_PyLoadModule_NUM] = (void*)PyLoadModule; /* Create a Capsule containing the API pointer array's address */ c_api_object = PyCapsule_New((void*)Bareosfd_API, diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index e2107e27b14..df864d05305 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -28,7 +28,7 @@ typedef off_t boffset_t; #include "lib/plugins.h" #include "filed/fd_plugins.h" - +//#include "plugins/filed/python/bareosfd.h" static void PyErrorHandler() { PyObject *type, *value, *traceback; @@ -190,6 +190,14 @@ int main(int argc, char* argv[]) } if (PyErr_Occurred()) { PyErrorHandler(); } + + static void** Bareosfd_API = (void**)PyCapsule_Import("bareosfd._C_API", 0); + if (!Bareosfd_API) { + printf("importing bareosfd._C_API failed \n"); + } else { + printf("importing bareosfd._C_API successful \n"); + } + /* printf("bareos_core_functions is at %p\n", * &bareos_core_functions); */ /* printf("bareos_PluginContext %p\n", &bareos_PluginContext); */ From d09cd9ec6a77040e69a05c89004ec4fc1ee888b0 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 6 May 2020 18:43:26 +0200 Subject: [PATCH 072/341] bareosfd: fix C_API macro --- core/src/plugins/filed/python/bareosfd.h | 71 ++++++++++--------- .../python/test/python-fd-module-tester.cc | 19 +++-- 2 files changed, 50 insertions(+), 40 deletions(-) diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/bareosfd.h index 7efde64f0e8..5dac9aabecd 100644 --- a/core/src/plugins/filed/python/bareosfd.h +++ b/core/src/plugins/filed/python/bareosfd.h @@ -36,6 +36,23 @@ #include "structmember.h" +/* C API functions */ +#define Bareosfd_PyLoadModule_NUM 0 +#define Bareosfd_PyLoadModule_RETURN bRC +#define Bareosfd_PyLoadModule_PROTO \ + (PluginContext * bareos_plugin_ctx, void* value) + + +/* Total number of C API pointers */ +#define Bareosfd_API_pointers 1 + +#ifdef BAREOSFD_MODULE +/* This section is used when compiling bareosfd.cc */ + +static Bareosfd_PyLoadModule_RETURN Bareosfd_PyLoadModule + Bareosfd_PyLoadModule_PROTO; + + namespace filedaemon { /** @@ -773,39 +790,6 @@ bRC loadPlugin(::Core_PluginApiDefinition* lbareos_plugin_interface_version, #endif -/* C API functions */ -#define Bareosfd_PyLoadModule_NUM 0 -#define Bareosfd_PyLoadModule_RETURN bRC -#define Bareosfd_PyLoadModule_PROTO \ - (PluginContext * bareos_plugin_ctx, void* value); - - -/* Total number of C API pointers */ -#define Bareosfd_API_pointers 1 - -#ifdef BAREOSFD_MODULE -/* This section is used when compiling bareosfd.cc */ - -static Bareosfd_PyLoadModule_RETURN Bareosfd_PyLoadModule - Bareosfd_PyLoadModule_PROTO; - -#else -/* This section is used in modules that use bareosfd's API */ - -static void** Bareosfd_API; - -#define Bareosfd_PyLoadModule \ - (*(Bareosfd_PyLoadModule_RETURN(*) \ - Bareosfd_PyLoadModule_PROTO)Bareosfd_API[Bareosfd_PyLoadModule_NUM]) - -static int import_bareosfd() -{ - Bareosfd_API = (void**)PyCapsule_Import("bareosfd._C_API", 0); - return (Bareosfd_API != NULL) ? 0 : -1; -} - -#endif // BAREOSFD_MODULE - MOD_INIT(bareosfd) { PyObject* m = NULL; @@ -1074,4 +1058,25 @@ MOD_INIT(bareosfd) } +#else // NOT BAREOSFD_MODULE + + +/* This section is used in modules that use bareosfd's API */ + +static void** Bareosfd_API; + + +#define Bareosfd_PyLoadModule \ + (*(Bareosfd_PyLoadModule_RETURN(*) \ + Bareosfd_PyLoadModule_PROTO)Bareosfd_API[Bareosfd_PyLoadModule_NUM]) + +static int import_bareosfd() +{ + Bareosfd_API = (void**)PyCapsule_Import("bareosfd._C_API", 0); + return (Bareosfd_API != NULL) ? 0 : -1; +} + + +#endif // BAREOSFD_MODULE + #endif /* BAREOS_PLUGINS_FILED_BAREOS_FD_H_ */ diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index df864d05305..7ac82b54649 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -28,7 +28,7 @@ typedef off_t boffset_t; #include "lib/plugins.h" #include "filed/fd_plugins.h" -//#include "plugins/filed/python/bareosfd.h" +#include "plugins/filed/python/bareosfd.h" static void PyErrorHandler() { PyObject *type, *value, *traceback; @@ -191,12 +191,17 @@ int main(int argc, char* argv[]) if (PyErr_Occurred()) { PyErrorHandler(); } - static void** Bareosfd_API = (void**)PyCapsule_Import("bareosfd._C_API", 0); - if (!Bareosfd_API) { - printf("importing bareosfd._C_API failed \n"); - } else { - printf("importing bareosfd._C_API successful \n"); - } + /* static void** Bareosfd_API = (void**)PyCapsule_Import("bareosfd._C_API", + * 0); */ + /* if (!Bareosfd_API) { */ + /* printf("importing bareosfd._C_API failed \n"); */ + /* } else { */ + /* printf("importing bareosfd._C_API successful \n"); */ + /* } */ + + + import_bareosfd(); + bRC retval = Bareosfd_PyLoadModule((PluginContext*)nullptr, nullptr); /* printf("bareos_core_functions is at %p\n", * &bareos_core_functions); */ From b7b018f25e878cb2de65f23e4c62808af76b79fe Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 7 May 2020 07:58:30 +0200 Subject: [PATCH 073/341] bareosfd C_API: added API functions --- core/src/plugins/filed/python/bareosfd.h | 116 +++++++++++++++++- .../python/test/python-fd-module-tester.cc | 2 +- 2 files changed, 116 insertions(+), 2 deletions(-) diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/bareosfd.h index 5dac9aabecd..abd23d90369 100644 --- a/core/src/plugins/filed/python/bareosfd.h +++ b/core/src/plugins/filed/python/bareosfd.h @@ -36,15 +36,129 @@ #include "structmember.h" + /* C API functions */ +// bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); #define Bareosfd_PyLoadModule_NUM 0 #define Bareosfd_PyLoadModule_RETURN bRC #define Bareosfd_PyLoadModule_PROTO \ (PluginContext * bareos_plugin_ctx, void* value) +// bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, void* value); +#define Bareosfd_PyParsePluginDefinition_NUM 1 +#define Bareosfd_PyParsePluginDefinition_RETURN bRC +#define Bareosfd_PyParsePluginDefinition_PROTO \ + (PluginContext * bareos_plugin_ctx, void* value) + +// bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* +// value); +#define Bareosfd_PyGetPluginValue_NUM 2 +#define Bareosfd_PyGetPluginValue_RETURN bRC +#define Bareosfd_PyGetPluginValue_PROTO \ + (PluginContext * bareos_plugin_ctx, pVariable var, void* value) + +// bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* +// value); +#define Bareosfd_PySetPluginValue_NUM 3 +#define Bareosfd_PySetPluginValue_RETURN bRC +#define Bareosfd_PySetPluginValue_PROTO \ + (PluginContext * bareos_plugin_ctx, pVariable var, void* value) + +// bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, bEvent* event, +// void* value); +#define Bareosfd_PyHandlePluginEvent_NUM 4 +#define Bareosfd_PyHandlePluginEvent_RETURN bRC +#define Bareosfd_PyHandlePluginEvent_PROTO \ + (PluginContext * bareos_plugin_ctx, bEvent * event, void* value) + +// bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); +#define Bareosfd_PyStartBackupFile_NUM 5 +#define Bareosfd_PyStartBackupFile_RETURN bRC +#define Bareosfd_PyStartBackupFile_PROTO \ + (PluginContext * bareos_plugin_ctx, struct save_pkt * sp) + +// bRC PyEndBackupFile(PluginContext* bareos_plugin_ctx); +#define Bareosfd_PyEndBackupFile_NUM 6 +#define Bareosfd_PyEndBackupFile_RETURN bRC +#define Bareosfd_PyEndBackupFile_PROTO (PluginContext * bareos_plugin_ctx) + +// bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); +#define Bareosfd_PyPluginIO_NUM 7 +#define Bareosfd_PyPluginIO_RETURN bRC +#define Bareosfd_PyPluginIO_PROTO \ + (PluginContext * bareos_plugin_ctx, struct io_pkt * io) + +// bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); +#define Bareosfd_PyStartRestoreFile_NUM 8 +#define Bareosfd_PyStartRestoreFile_RETURN bRC +#define Bareosfd_PyStartRestoreFile_PROTO \ + (PluginContext * bareos_plugin_ctx, const char* cmd) + +// bRC PyEndRestoreFile(PluginContext* bareos_plugin_ctx); +#define Bareosfd_PyEndRestoreFile_NUM 9 +#define Bareosfd_PyEndRestoreFile_RETURN bRC +#define Bareosfd_PyEndRestoreFile_PROTO (PluginContext * bareos_plugin_ctx) + +// bRC PyCreateFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); +#define Bareosfd_PyCreateFile_NUM 10 +#define Bareosfd_PyCreateFile_RETURN bRC +#define Bareosfd_PyCreateFile_PROTO \ + (PluginContext * bareos_plugin_ctx, struct restore_pkt * rp) + +// bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, struct restore_pkt* +// rp); +#define Bareosfd_PySetFileAttributes_NUM 11 +#define Bareosfd_PySetFileAttributes_RETURN bRC +#define Bareosfd_PySetFileAttributes_PROTO \ + (PluginContext * bareos_plugin_ctx, struct restore_pkt * rp) + +// bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname); +#define Bareosfd_PyCheckFile_NUM 12 +#define Bareosfd_PyCheckFile_RETURN bRC +#define Bareosfd_PyCheckFile_PROTO \ + (PluginContext * bareos_plugin_ctx, char* fname) + +// bRC PyGetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +#define Bareosfd_PyGetAcl_NUM 13 +#define Bareosfd_PyGetAcl_RETURN bRC +#define Bareosfd_PyGetAcl_PROTO \ + (PluginContext * bareos_plugin_ctx, acl_pkt * ap) + +// bRC PySetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +#define Bareosfd_PySetAcl_NUM 14 +#define Bareosfd_PySetAcl_RETURN bRC +#define Bareosfd_PySetAcl_PROTO \ + (PluginContext * bareos_plugin_ctx, acl_pkt * ap) + +// bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +#define Bareosfd_PyGetXattr_NUM 15 +#define Bareosfd_PyGetXattr_RETURN bRC +#define Bareosfd_PyGetXattr_PROTO \ + (PluginContext * bareos_plugin_ctx, xattr_pkt * xp) + +// bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +#define Bareosfd_PySetXattr_NUM 16 +#define Bareosfd_PySetXattr_RETURN bRC +#define Bareosfd_PySetXattr_PROTO \ + (PluginContext * bareos_plugin_ctx, xattr_pkt * xp) + +// bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, struct +// restore_object_pkt* rop); +#define Bareosfd_PyRestoreObjectData_NUM 17 +#define Bareosfd_PyRestoreObjectData_RETURN bRC +#define Bareosfd_PyRestoreObjectData_PROTO \ + (PluginContext * bareos_plugin_ctx, struct restore_object_pkt * rop) + +// bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* +// sp); +#define Bareosfd_PyHandleBackupFile_NUM 18 +#define Bareosfd_PyHandleBackupFile_RETURN bRC +#define Bareosfd_PyHandleBackupFile_PROTO \ + (PluginContext * bareos_plugin_ctx, struct save_pkt * sp) /* Total number of C API pointers */ -#define Bareosfd_API_pointers 1 +#define Bareosfd_API_pointers 19 + #ifdef BAREOSFD_MODULE /* This section is used when compiling bareosfd.cc */ diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index 7ac82b54649..e3166620e00 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -201,7 +201,7 @@ int main(int argc, char* argv[]) import_bareosfd(); - bRC retval = Bareosfd_PyLoadModule((PluginContext*)nullptr, nullptr); + // bRC retval = Bareosfd_PyLoadModule((PluginContext*)nullptr, nullptr); /* printf("bareos_core_functions is at %p\n", * &bareos_core_functions); */ From aa1f497d8c1aeeb223bd13b40160621d2cfb7d92 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 7 May 2020 10:35:24 +0200 Subject: [PATCH 074/341] bareosfd C_API: autogenerate bareosfd.h c API --- core/src/plugins/filed/CMakeLists.txt | 3 +- core/src/plugins/filed/python/bareosfd.cc | 8 + core/src/plugins/filed/python/bareosfd.h | 130 +----------- .../filed/python/bareosfd_api_funcs.txt | 38 ++++ core/src/plugins/filed/python/capi_1.inc | 194 ++++++++++++++++++ core/src/plugins/filed/python/capi_2.inc | 76 +++++++ .../create_CAPI_from_bareos_api_funcs.sh | 35 ++++ core/src/plugins/filed/python/python-fd.cc | 102 +++++---- 8 files changed, 415 insertions(+), 171 deletions(-) create mode 100644 core/src/plugins/filed/python/bareosfd_api_funcs.txt create mode 100644 core/src/plugins/filed/python/capi_1.inc create mode 100644 core/src/plugins/filed/python/capi_2.inc create mode 100755 core/src/plugins/filed/python/create_CAPI_from_bareos_api_funcs.sh diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index 59f7be2ac02..04fdb48981f 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -131,11 +131,12 @@ if(HAVE_PYTHON AND NOT HAVE_WIN32) MAIN_DEPENDENCY ./python/bareosfd.cc DEPENDS ./python/bareosfd.h DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py + COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${PYTHON_EXECUTABLE} python/setup.py build COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - # COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build DEPENDS python-fd + # DEPENDS python-fd COMMENT "building python module pythonmodules/bareosfd.so" ) diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index cd6153d2275..557ef58790d 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -321,6 +321,14 @@ bRC unloadPlugin() } #endif +/* set the bareos_core_functions pointer to the given value */ +static bRC set_bareos_core_functions( + BareosCoreFunctions* new_bareos_core_functions) +{ + bareos_core_functions = new_bareos_core_functions; +} + + /** * Called here to make a new instance of the plugin -- i.e. when * a new Job is started. There can be multiple instances of diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/bareosfd.h index abd23d90369..be25e1e2f29 100644 --- a/core/src/plugins/filed/python/bareosfd.h +++ b/core/src/plugins/filed/python/bareosfd.h @@ -36,128 +36,8 @@ #include "structmember.h" - -/* C API functions */ -// bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); -#define Bareosfd_PyLoadModule_NUM 0 -#define Bareosfd_PyLoadModule_RETURN bRC -#define Bareosfd_PyLoadModule_PROTO \ - (PluginContext * bareos_plugin_ctx, void* value) - -// bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, void* value); -#define Bareosfd_PyParsePluginDefinition_NUM 1 -#define Bareosfd_PyParsePluginDefinition_RETURN bRC -#define Bareosfd_PyParsePluginDefinition_PROTO \ - (PluginContext * bareos_plugin_ctx, void* value) - -// bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* -// value); -#define Bareosfd_PyGetPluginValue_NUM 2 -#define Bareosfd_PyGetPluginValue_RETURN bRC -#define Bareosfd_PyGetPluginValue_PROTO \ - (PluginContext * bareos_plugin_ctx, pVariable var, void* value) - -// bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* -// value); -#define Bareosfd_PySetPluginValue_NUM 3 -#define Bareosfd_PySetPluginValue_RETURN bRC -#define Bareosfd_PySetPluginValue_PROTO \ - (PluginContext * bareos_plugin_ctx, pVariable var, void* value) - -// bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, bEvent* event, -// void* value); -#define Bareosfd_PyHandlePluginEvent_NUM 4 -#define Bareosfd_PyHandlePluginEvent_RETURN bRC -#define Bareosfd_PyHandlePluginEvent_PROTO \ - (PluginContext * bareos_plugin_ctx, bEvent * event, void* value) - -// bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); -#define Bareosfd_PyStartBackupFile_NUM 5 -#define Bareosfd_PyStartBackupFile_RETURN bRC -#define Bareosfd_PyStartBackupFile_PROTO \ - (PluginContext * bareos_plugin_ctx, struct save_pkt * sp) - -// bRC PyEndBackupFile(PluginContext* bareos_plugin_ctx); -#define Bareosfd_PyEndBackupFile_NUM 6 -#define Bareosfd_PyEndBackupFile_RETURN bRC -#define Bareosfd_PyEndBackupFile_PROTO (PluginContext * bareos_plugin_ctx) - -// bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); -#define Bareosfd_PyPluginIO_NUM 7 -#define Bareosfd_PyPluginIO_RETURN bRC -#define Bareosfd_PyPluginIO_PROTO \ - (PluginContext * bareos_plugin_ctx, struct io_pkt * io) - -// bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); -#define Bareosfd_PyStartRestoreFile_NUM 8 -#define Bareosfd_PyStartRestoreFile_RETURN bRC -#define Bareosfd_PyStartRestoreFile_PROTO \ - (PluginContext * bareos_plugin_ctx, const char* cmd) - -// bRC PyEndRestoreFile(PluginContext* bareos_plugin_ctx); -#define Bareosfd_PyEndRestoreFile_NUM 9 -#define Bareosfd_PyEndRestoreFile_RETURN bRC -#define Bareosfd_PyEndRestoreFile_PROTO (PluginContext * bareos_plugin_ctx) - -// bRC PyCreateFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); -#define Bareosfd_PyCreateFile_NUM 10 -#define Bareosfd_PyCreateFile_RETURN bRC -#define Bareosfd_PyCreateFile_PROTO \ - (PluginContext * bareos_plugin_ctx, struct restore_pkt * rp) - -// bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, struct restore_pkt* -// rp); -#define Bareosfd_PySetFileAttributes_NUM 11 -#define Bareosfd_PySetFileAttributes_RETURN bRC -#define Bareosfd_PySetFileAttributes_PROTO \ - (PluginContext * bareos_plugin_ctx, struct restore_pkt * rp) - -// bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname); -#define Bareosfd_PyCheckFile_NUM 12 -#define Bareosfd_PyCheckFile_RETURN bRC -#define Bareosfd_PyCheckFile_PROTO \ - (PluginContext * bareos_plugin_ctx, char* fname) - -// bRC PyGetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -#define Bareosfd_PyGetAcl_NUM 13 -#define Bareosfd_PyGetAcl_RETURN bRC -#define Bareosfd_PyGetAcl_PROTO \ - (PluginContext * bareos_plugin_ctx, acl_pkt * ap) - -// bRC PySetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -#define Bareosfd_PySetAcl_NUM 14 -#define Bareosfd_PySetAcl_RETURN bRC -#define Bareosfd_PySetAcl_PROTO \ - (PluginContext * bareos_plugin_ctx, acl_pkt * ap) - -// bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -#define Bareosfd_PyGetXattr_NUM 15 -#define Bareosfd_PyGetXattr_RETURN bRC -#define Bareosfd_PyGetXattr_PROTO \ - (PluginContext * bareos_plugin_ctx, xattr_pkt * xp) - -// bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -#define Bareosfd_PySetXattr_NUM 16 -#define Bareosfd_PySetXattr_RETURN bRC -#define Bareosfd_PySetXattr_PROTO \ - (PluginContext * bareos_plugin_ctx, xattr_pkt * xp) - -// bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, struct -// restore_object_pkt* rop); -#define Bareosfd_PyRestoreObjectData_NUM 17 -#define Bareosfd_PyRestoreObjectData_RETURN bRC -#define Bareosfd_PyRestoreObjectData_PROTO \ - (PluginContext * bareos_plugin_ctx, struct restore_object_pkt * rop) - -// bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* -// sp); -#define Bareosfd_PyHandleBackupFile_NUM 18 -#define Bareosfd_PyHandleBackupFile_RETURN bRC -#define Bareosfd_PyHandleBackupFile_PROTO \ - (PluginContext * bareos_plugin_ctx, struct save_pkt * sp) - -/* Total number of C API pointers */ -#define Bareosfd_API_pointers 19 +/* include automatically generated C API */ +#include "capi_1.inc" #ifdef BAREOSFD_MODULE @@ -1179,10 +1059,8 @@ MOD_INIT(bareosfd) static void** Bareosfd_API; - -#define Bareosfd_PyLoadModule \ - (*(Bareosfd_PyLoadModule_RETURN(*) \ - Bareosfd_PyLoadModule_PROTO)Bareosfd_API[Bareosfd_PyLoadModule_NUM]) +/* include automatically generated C API */ +#include "capi_2.inc" static int import_bareosfd() { diff --git a/core/src/plugins/filed/python/bareosfd_api_funcs.txt b/core/src/plugins/filed/python/bareosfd_api_funcs.txt new file mode 100644 index 00000000000..865be37a422 --- /dev/null +++ b/core/src/plugins/filed/python/bareosfd_api_funcs.txt @@ -0,0 +1,38 @@ +bRC newPlugin(PluginContext* bareos_plugin_ctx); +bRC freePlugin(PluginContext* bareos_plugin_ctx); +bRC getPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); +bRC setPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); +bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, bEvent* event, void* value); +bRC startBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); +bRC endBackupFile(PluginContext* bareos_plugin_ctx); +bRC pluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); +bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); +bRC endRestoreFile(PluginContext* bareos_plugin_ctx); +bRC createFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); +bRC setFileAttributes(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); +bRC checkFile(PluginContext* bareos_plugin_ctx, char* fname); +bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +bRC setXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, void* value, PoolMem& plugin_options); +bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); +bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, void* value); +bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); +bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); +bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, bEvent* event, void* value); +bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); +bRC PyEndBackupFile(PluginContext* bareos_plugin_ctx); +bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); +bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); +bRC PyEndRestoreFile(PluginContext* bareos_plugin_ctx); +bRC PyCreateFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); +bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); +bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname); +bRC PyGetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +bRC PySetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, struct restore_object_pkt* rop); +bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); +bRC set_bareos_core_functions(BareosCoreFunctions* new_bareos_core_functions); diff --git a/core/src/plugins/filed/python/capi_1.inc b/core/src/plugins/filed/python/capi_1.inc new file mode 100644 index 00000000000..6923d41ccf6 --- /dev/null +++ b/core/src/plugins/filed/python/capi_1.inc @@ -0,0 +1,194 @@ +/* C API functions */ + +/* static bRC newPlugin(PluginContext* bareos_plugin_ctx); */ +#define Bareosfd_newPlugin_NUM 0 +#define Bareosfd_newPlugin_RETURN bRC +#define Bareosfd_newPlugin_PROTO (PluginContext* bareos_plugin_ctx) + +/* static bRC freePlugin(PluginContext* bareos_plugin_ctx); */ +#define Bareosfd_freePlugin_NUM 1 +#define Bareosfd_freePlugin_RETURN bRC +#define Bareosfd_freePlugin_PROTO (PluginContext* bareos_plugin_ctx) + +/* static bRC getPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); */ +#define Bareosfd_getPluginValue_NUM 2 +#define Bareosfd_getPluginValue_RETURN bRC +#define Bareosfd_getPluginValue_PROTO (PluginContext* bareos_plugin_ctx, pVariable var, void* value) + +/* static bRC setPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); */ +#define Bareosfd_setPluginValue_NUM 3 +#define Bareosfd_setPluginValue_RETURN bRC +#define Bareosfd_setPluginValue_PROTO (PluginContext* bareos_plugin_ctx, pVariable var, void* value) + +/* static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, bEvent* event, void* value); */ +#define Bareosfd_handlePluginEvent_NUM 4 +#define Bareosfd_handlePluginEvent_RETURN bRC +#define Bareosfd_handlePluginEvent_PROTO (PluginContext* bareos_plugin_ctx, bEvent* event, void* value) + +/* static bRC startBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); */ +#define Bareosfd_startBackupFile_NUM 5 +#define Bareosfd_startBackupFile_RETURN bRC +#define Bareosfd_startBackupFile_PROTO (PluginContext* bareos_plugin_ctx, struct save_pkt* sp) + +/* static bRC endBackupFile(PluginContext* bareos_plugin_ctx); */ +#define Bareosfd_endBackupFile_NUM 6 +#define Bareosfd_endBackupFile_RETURN bRC +#define Bareosfd_endBackupFile_PROTO (PluginContext* bareos_plugin_ctx) + +/* static bRC pluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); */ +#define Bareosfd_pluginIO_NUM 7 +#define Bareosfd_pluginIO_RETURN bRC +#define Bareosfd_pluginIO_PROTO (PluginContext* bareos_plugin_ctx, struct io_pkt* io) + +/* static bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); */ +#define Bareosfd_startRestoreFile_NUM 8 +#define Bareosfd_startRestoreFile_RETURN bRC +#define Bareosfd_startRestoreFile_PROTO (PluginContext* bareos_plugin_ctx, const char* cmd) + +/* static bRC endRestoreFile(PluginContext* bareos_plugin_ctx); */ +#define Bareosfd_endRestoreFile_NUM 9 +#define Bareosfd_endRestoreFile_RETURN bRC +#define Bareosfd_endRestoreFile_PROTO (PluginContext* bareos_plugin_ctx) + +/* static bRC createFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); */ +#define Bareosfd_createFile_NUM 10 +#define Bareosfd_createFile_RETURN bRC +#define Bareosfd_createFile_PROTO (PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) + +/* static bRC setFileAttributes(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); */ +#define Bareosfd_setFileAttributes_NUM 11 +#define Bareosfd_setFileAttributes_RETURN bRC +#define Bareosfd_setFileAttributes_PROTO (PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) + +/* static bRC checkFile(PluginContext* bareos_plugin_ctx, char* fname); */ +#define Bareosfd_checkFile_NUM 12 +#define Bareosfd_checkFile_RETURN bRC +#define Bareosfd_checkFile_PROTO (PluginContext* bareos_plugin_ctx, char* fname) + +/* static bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); */ +#define Bareosfd_getAcl_NUM 13 +#define Bareosfd_getAcl_RETURN bRC +#define Bareosfd_getAcl_PROTO (PluginContext* bareos_plugin_ctx, acl_pkt* ap) + +/* static bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); */ +#define Bareosfd_setAcl_NUM 14 +#define Bareosfd_setAcl_RETURN bRC +#define Bareosfd_setAcl_PROTO (PluginContext* bareos_plugin_ctx, acl_pkt* ap) + +/* static bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); */ +#define Bareosfd_getXattr_NUM 15 +#define Bareosfd_getXattr_RETURN bRC +#define Bareosfd_getXattr_PROTO (PluginContext* bareos_plugin_ctx, xattr_pkt* xp) + +/* static bRC setXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); */ +#define Bareosfd_setXattr_NUM 16 +#define Bareosfd_setXattr_RETURN bRC +#define Bareosfd_setXattr_PROTO (PluginContext* bareos_plugin_ctx, xattr_pkt* xp) + +/* static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, void* value, PoolMem& plugin_options); */ +#define Bareosfd_parse_plugin_definition_NUM 17 +#define Bareosfd_parse_plugin_definition_RETURN bRC +#define Bareosfd_parse_plugin_definition_PROTO (PluginContext* bareos_plugin_ctx, void* value, PoolMem& plugin_options) + +/* static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); */ +#define Bareosfd_PyLoadModule_NUM 18 +#define Bareosfd_PyLoadModule_RETURN bRC +#define Bareosfd_PyLoadModule_PROTO (PluginContext* bareos_plugin_ctx, void* value) + +/* static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, void* value); */ +#define Bareosfd_PyParsePluginDefinition_NUM 19 +#define Bareosfd_PyParsePluginDefinition_RETURN bRC +#define Bareosfd_PyParsePluginDefinition_PROTO (PluginContext* bareos_plugin_ctx, void* value) + +/* static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); */ +#define Bareosfd_PyGetPluginValue_NUM 20 +#define Bareosfd_PyGetPluginValue_RETURN bRC +#define Bareosfd_PyGetPluginValue_PROTO (PluginContext* bareos_plugin_ctx, pVariable var, void* value) + +/* static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); */ +#define Bareosfd_PySetPluginValue_NUM 21 +#define Bareosfd_PySetPluginValue_RETURN bRC +#define Bareosfd_PySetPluginValue_PROTO (PluginContext* bareos_plugin_ctx, pVariable var, void* value) + +/* static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, bEvent* event, void* value); */ +#define Bareosfd_PyHandlePluginEvent_NUM 22 +#define Bareosfd_PyHandlePluginEvent_RETURN bRC +#define Bareosfd_PyHandlePluginEvent_PROTO (PluginContext* bareos_plugin_ctx, bEvent* event, void* value) + +/* static bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); */ +#define Bareosfd_PyStartBackupFile_NUM 23 +#define Bareosfd_PyStartBackupFile_RETURN bRC +#define Bareosfd_PyStartBackupFile_PROTO (PluginContext* bareos_plugin_ctx, struct save_pkt* sp) + +/* static bRC PyEndBackupFile(PluginContext* bareos_plugin_ctx); */ +#define Bareosfd_PyEndBackupFile_NUM 24 +#define Bareosfd_PyEndBackupFile_RETURN bRC +#define Bareosfd_PyEndBackupFile_PROTO (PluginContext* bareos_plugin_ctx) + +/* static bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); */ +#define Bareosfd_PyPluginIO_NUM 25 +#define Bareosfd_PyPluginIO_RETURN bRC +#define Bareosfd_PyPluginIO_PROTO (PluginContext* bareos_plugin_ctx, struct io_pkt* io) + +/* static bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); */ +#define Bareosfd_PyStartRestoreFile_NUM 26 +#define Bareosfd_PyStartRestoreFile_RETURN bRC +#define Bareosfd_PyStartRestoreFile_PROTO (PluginContext* bareos_plugin_ctx, const char* cmd) + +/* static bRC PyEndRestoreFile(PluginContext* bareos_plugin_ctx); */ +#define Bareosfd_PyEndRestoreFile_NUM 27 +#define Bareosfd_PyEndRestoreFile_RETURN bRC +#define Bareosfd_PyEndRestoreFile_PROTO (PluginContext* bareos_plugin_ctx) + +/* static bRC PyCreateFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); */ +#define Bareosfd_PyCreateFile_NUM 28 +#define Bareosfd_PyCreateFile_RETURN bRC +#define Bareosfd_PyCreateFile_PROTO (PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) + +/* static bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); */ +#define Bareosfd_PySetFileAttributes_NUM 29 +#define Bareosfd_PySetFileAttributes_RETURN bRC +#define Bareosfd_PySetFileAttributes_PROTO (PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) + +/* static bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname); */ +#define Bareosfd_PyCheckFile_NUM 30 +#define Bareosfd_PyCheckFile_RETURN bRC +#define Bareosfd_PyCheckFile_PROTO (PluginContext* bareos_plugin_ctx, char* fname) + +/* static bRC PyGetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); */ +#define Bareosfd_PyGetAcl_NUM 31 +#define Bareosfd_PyGetAcl_RETURN bRC +#define Bareosfd_PyGetAcl_PROTO (PluginContext* bareos_plugin_ctx, acl_pkt* ap) + +/* static bRC PySetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); */ +#define Bareosfd_PySetAcl_NUM 32 +#define Bareosfd_PySetAcl_RETURN bRC +#define Bareosfd_PySetAcl_PROTO (PluginContext* bareos_plugin_ctx, acl_pkt* ap) + +/* static bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); */ +#define Bareosfd_PyGetXattr_NUM 33 +#define Bareosfd_PyGetXattr_RETURN bRC +#define Bareosfd_PyGetXattr_PROTO (PluginContext* bareos_plugin_ctx, xattr_pkt* xp) + +/* static bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); */ +#define Bareosfd_PySetXattr_NUM 34 +#define Bareosfd_PySetXattr_RETURN bRC +#define Bareosfd_PySetXattr_PROTO (PluginContext* bareos_plugin_ctx, xattr_pkt* xp) + +/* static bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, struct restore_object_pkt* rop); */ +#define Bareosfd_PyRestoreObjectData_NUM 35 +#define Bareosfd_PyRestoreObjectData_RETURN bRC +#define Bareosfd_PyRestoreObjectData_PROTO (PluginContext* bareos_plugin_ctx, struct restore_object_pkt* rop) + +/* static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); */ +#define Bareosfd_PyHandleBackupFile_NUM 36 +#define Bareosfd_PyHandleBackupFile_RETURN bRC +#define Bareosfd_PyHandleBackupFile_PROTO (PluginContext* bareos_plugin_ctx, struct save_pkt* sp) + +/* static bRC set_bareos_core_functions(BareosCoreFunctions* new_bareos_core_functions); */ +#define Bareosfd_set_bareos_core_functions_NUM 37 +#define Bareosfd_set_bareos_core_functions_RETURN bRC +#define Bareosfd_set_bareos_core_functions_PROTO (BareosCoreFunctions* new_bareos_core_functions ) + +/*Total Number of C API function pointers */ +#define Bareosfd_API_pointers 38 diff --git a/core/src/plugins/filed/python/capi_2.inc b/core/src/plugins/filed/python/capi_2.inc new file mode 100644 index 00000000000..45dbc584e62 --- /dev/null +++ b/core/src/plugins/filed/python/capi_2.inc @@ -0,0 +1,76 @@ +#define Bareosfd_newPlugin (*(Bareosfd_newPlugin_RETURN(*)Bareosfd_newPlugin_PROTO) Bareosfd_API[Bareosfd_newPlugin_NUM]) + +#define Bareosfd_freePlugin (*(Bareosfd_freePlugin_RETURN(*)Bareosfd_freePlugin_PROTO) Bareosfd_API[Bareosfd_freePlugin_NUM]) + +#define Bareosfd_getPluginValue (*(Bareosfd_getPluginValue_RETURN(*)Bareosfd_getPluginValue_PROTO) Bareosfd_API[Bareosfd_getPluginValue_NUM]) + +#define Bareosfd_setPluginValue (*(Bareosfd_setPluginValue_RETURN(*)Bareosfd_setPluginValue_PROTO) Bareosfd_API[Bareosfd_setPluginValue_NUM]) + +#define Bareosfd_handlePluginEvent (*(Bareosfd_handlePluginEvent_RETURN(*)Bareosfd_handlePluginEvent_PROTO) Bareosfd_API[Bareosfd_handlePluginEvent_NUM]) + +#define Bareosfd_startBackupFile (*(Bareosfd_startBackupFile_RETURN(*)Bareosfd_startBackupFile_PROTO) Bareosfd_API[Bareosfd_startBackupFile_NUM]) + +#define Bareosfd_endBackupFile (*(Bareosfd_endBackupFile_RETURN(*)Bareosfd_endBackupFile_PROTO) Bareosfd_API[Bareosfd_endBackupFile_NUM]) + +#define Bareosfd_pluginIO (*(Bareosfd_pluginIO_RETURN(*)Bareosfd_pluginIO_PROTO) Bareosfd_API[Bareosfd_pluginIO_NUM]) + +#define Bareosfd_startRestoreFile (*(Bareosfd_startRestoreFile_RETURN(*)Bareosfd_startRestoreFile_PROTO) Bareosfd_API[Bareosfd_startRestoreFile_NUM]) + +#define Bareosfd_endRestoreFile (*(Bareosfd_endRestoreFile_RETURN(*)Bareosfd_endRestoreFile_PROTO) Bareosfd_API[Bareosfd_endRestoreFile_NUM]) + +#define Bareosfd_createFile (*(Bareosfd_createFile_RETURN(*)Bareosfd_createFile_PROTO) Bareosfd_API[Bareosfd_createFile_NUM]) + +#define Bareosfd_setFileAttributes (*(Bareosfd_setFileAttributes_RETURN(*)Bareosfd_setFileAttributes_PROTO) Bareosfd_API[Bareosfd_setFileAttributes_NUM]) + +#define Bareosfd_checkFile (*(Bareosfd_checkFile_RETURN(*)Bareosfd_checkFile_PROTO) Bareosfd_API[Bareosfd_checkFile_NUM]) + +#define Bareosfd_getAcl (*(Bareosfd_getAcl_RETURN(*)Bareosfd_getAcl_PROTO) Bareosfd_API[Bareosfd_getAcl_NUM]) + +#define Bareosfd_setAcl (*(Bareosfd_setAcl_RETURN(*)Bareosfd_setAcl_PROTO) Bareosfd_API[Bareosfd_setAcl_NUM]) + +#define Bareosfd_getXattr (*(Bareosfd_getXattr_RETURN(*)Bareosfd_getXattr_PROTO) Bareosfd_API[Bareosfd_getXattr_NUM]) + +#define Bareosfd_setXattr (*(Bareosfd_setXattr_RETURN(*)Bareosfd_setXattr_PROTO) Bareosfd_API[Bareosfd_setXattr_NUM]) + +#define Bareosfd_parse_plugin_definition (*(Bareosfd_parse_plugin_definition_RETURN(*)Bareosfd_parse_plugin_definition_PROTO) Bareosfd_API[Bareosfd_parse_plugin_definition_NUM]) + +#define Bareosfd_PyLoadModule (*(Bareosfd_PyLoadModule_RETURN(*)Bareosfd_PyLoadModule_PROTO) Bareosfd_API[Bareosfd_PyLoadModule_NUM]) + +#define Bareosfd_PyParsePluginDefinition (*(Bareosfd_PyParsePluginDefinition_RETURN(*)Bareosfd_PyParsePluginDefinition_PROTO) Bareosfd_API[Bareosfd_PyParsePluginDefinition_NUM]) + +#define Bareosfd_PyGetPluginValue (*(Bareosfd_PyGetPluginValue_RETURN(*)Bareosfd_PyGetPluginValue_PROTO) Bareosfd_API[Bareosfd_PyGetPluginValue_NUM]) + +#define Bareosfd_PySetPluginValue (*(Bareosfd_PySetPluginValue_RETURN(*)Bareosfd_PySetPluginValue_PROTO) Bareosfd_API[Bareosfd_PySetPluginValue_NUM]) + +#define Bareosfd_PyHandlePluginEvent (*(Bareosfd_PyHandlePluginEvent_RETURN(*)Bareosfd_PyHandlePluginEvent_PROTO) Bareosfd_API[Bareosfd_PyHandlePluginEvent_NUM]) + +#define Bareosfd_PyStartBackupFile (*(Bareosfd_PyStartBackupFile_RETURN(*)Bareosfd_PyStartBackupFile_PROTO) Bareosfd_API[Bareosfd_PyStartBackupFile_NUM]) + +#define Bareosfd_PyEndBackupFile (*(Bareosfd_PyEndBackupFile_RETURN(*)Bareosfd_PyEndBackupFile_PROTO) Bareosfd_API[Bareosfd_PyEndBackupFile_NUM]) + +#define Bareosfd_PyPluginIO (*(Bareosfd_PyPluginIO_RETURN(*)Bareosfd_PyPluginIO_PROTO) Bareosfd_API[Bareosfd_PyPluginIO_NUM]) + +#define Bareosfd_PyStartRestoreFile (*(Bareosfd_PyStartRestoreFile_RETURN(*)Bareosfd_PyStartRestoreFile_PROTO) Bareosfd_API[Bareosfd_PyStartRestoreFile_NUM]) + +#define Bareosfd_PyEndRestoreFile (*(Bareosfd_PyEndRestoreFile_RETURN(*)Bareosfd_PyEndRestoreFile_PROTO) Bareosfd_API[Bareosfd_PyEndRestoreFile_NUM]) + +#define Bareosfd_PyCreateFile (*(Bareosfd_PyCreateFile_RETURN(*)Bareosfd_PyCreateFile_PROTO) Bareosfd_API[Bareosfd_PyCreateFile_NUM]) + +#define Bareosfd_PySetFileAttributes (*(Bareosfd_PySetFileAttributes_RETURN(*)Bareosfd_PySetFileAttributes_PROTO) Bareosfd_API[Bareosfd_PySetFileAttributes_NUM]) + +#define Bareosfd_PyCheckFile (*(Bareosfd_PyCheckFile_RETURN(*)Bareosfd_PyCheckFile_PROTO) Bareosfd_API[Bareosfd_PyCheckFile_NUM]) + +#define Bareosfd_PyGetAcl (*(Bareosfd_PyGetAcl_RETURN(*)Bareosfd_PyGetAcl_PROTO) Bareosfd_API[Bareosfd_PyGetAcl_NUM]) + +#define Bareosfd_PySetAcl (*(Bareosfd_PySetAcl_RETURN(*)Bareosfd_PySetAcl_PROTO) Bareosfd_API[Bareosfd_PySetAcl_NUM]) + +#define Bareosfd_PyGetXattr (*(Bareosfd_PyGetXattr_RETURN(*)Bareosfd_PyGetXattr_PROTO) Bareosfd_API[Bareosfd_PyGetXattr_NUM]) + +#define Bareosfd_PySetXattr (*(Bareosfd_PySetXattr_RETURN(*)Bareosfd_PySetXattr_PROTO) Bareosfd_API[Bareosfd_PySetXattr_NUM]) + +#define Bareosfd_PyRestoreObjectData (*(Bareosfd_PyRestoreObjectData_RETURN(*)Bareosfd_PyRestoreObjectData_PROTO) Bareosfd_API[Bareosfd_PyRestoreObjectData_NUM]) + +#define Bareosfd_PyHandleBackupFile (*(Bareosfd_PyHandleBackupFile_RETURN(*)Bareosfd_PyHandleBackupFile_PROTO) Bareosfd_API[Bareosfd_PyHandleBackupFile_NUM]) + +#define Bareosfd_set_bareos_core_functions (*(Bareosfd_set_bareos_core_functions_RETURN(*)Bareosfd_set_bareos_core_functions_PROTO) Bareosfd_API[Bareosfd_set_bareos_core_functions_NUM]) + diff --git a/core/src/plugins/filed/python/create_CAPI_from_bareos_api_funcs.sh b/core/src/plugins/filed/python/create_CAPI_from_bareos_api_funcs.sh new file mode 100755 index 00000000000..e76f83e1749 --- /dev/null +++ b/core/src/plugins/filed/python/create_CAPI_from_bareos_api_funcs.sh @@ -0,0 +1,35 @@ +#!/bin/bash +IFS=' +' + +exec >capi_1.inc + +echo "/* C API functions */" +NUM=0 +for i in $(cat bareosfd_api_funcs.txt); do + retval=$(echo $i | sed 's/ .*//g') + funcname=$(echo $i | cut -b 5- | sed s/\(.*//g) + prot=$(echo $i | sed s/.*\(//g | sed 's/);//g') +echo " +/* static $i */ +#define Bareosfd_${funcname}_NUM $NUM +#define Bareosfd_${funcname}_RETURN $retval +#define Bareosfd_${funcname}_PROTO (${prot})" + +((NUM=NUM+1)) +done +echo " +/*Total Number of C API function pointers */ +#define Bareosfd_API_pointers $NUM" + +exec >capi_2.inc + +NUM=0 +for i in $(cat bareosfd_api_funcs.txt); do + retval=$(echo $i | sed 's/ .*//g') + funcname=$(echo $i | cut -b 5- | sed s/\(.*//g) + prot=$(echo $i | sed s/.*\(//g | sed 's/);//g') + echo "#define Bareosfd_${funcname} (*(Bareosfd_${funcname}_RETURN(*)Bareosfd_${funcname}_PROTO) Bareosfd_API[Bareosfd_${funcname}_NUM]) +" +((NUM=NUM+1)) +done diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index d09ada7b68f..82b6de5affc 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -45,6 +45,7 @@ #endif #include "python-fd.h" +#include "bareosfd.h" #include "lib/edit.h" namespace filedaemon { @@ -227,13 +228,6 @@ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, PluginInformation** plugin_information, pFuncs** plugin_functions) { - bareos_core_functions = - lbareos_core_functions; /* Set Bareos funct pointers */ - bareos_plugin_interface_version = lbareos_plugin_interface_version; - - *plugin_information = &pluginInfo; /* Return pointer to our info */ - *plugin_functions = &pluginFuncs; /* Return pointer to our functions */ - if (!Py_IsInitialized()) { /* Setup Python */ #if PY_MAJOR_VERSION >= 3 @@ -249,58 +243,78 @@ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, printf("loaded bareosfd successfully\n"); } else { printf("loading of bareosfd failed\n"); + if (PyErr_Occurred()) { PyErrorHandler(); } } + /* import the CAPI from the bareosfd python module */ + import_bareosfd(); + + + bareos_core_functions = + lbareos_core_functions; /* Set Bareos funct pointers */ + bareos_plugin_interface_version = lbareos_plugin_interface_version; - if (PyErr_Occurred()) { PyErrorHandler(); } + *plugin_information = &pluginInfo; /* Return pointer to our info */ + *plugin_functions = &pluginFuncs; /* Return pointer to our functions */ + + /* filedaemon::Core_PluginApiDefinition myInfo; */ + /* PluginInformation plugin_information; */ + /* filedaemon::pFuncs plugin_functions; */ + /* Bareosfd_loadPlugin(&myInfo, bareos_core_functions, */ + /* (PluginInformation**)&plugin_information, */ + /* (filedaemon::pFuncs**)&plugin_functions); */ // Extract capsules pointer from bareosfd module - void (*loadplugin_from_bareosfd_module)( - filedaemon::Core_PluginApiDefinition * lbareos_plugin_interface_version, - filedaemon::BareosCoreFunctions * lbareos_core_functions, - PluginInformation * *plugin_information, - filedaemon::pFuncs * *plugin_functions) = - (void (*)(filedaemon::Core_PluginApiDefinition*, - filedaemon::BareosCoreFunctions*, PluginInformation**, - filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", - 0); + /* void (*loadplugin_from_bareosfd_module)( */ + /* filedaemon::Core_PluginApiDefinition * + * lbareos_plugin_interface_version, */ + /* filedaemon::BareosCoreFunctions * lbareos_core_functions, */ + /* PluginInformation * *plugin_information, */ + /* filedaemon::pFuncs * *plugin_functions) = */ + /* (void (*)(filedaemon::Core_PluginApiDefinition*, */ + /* filedaemon::BareosCoreFunctions*, PluginInformation**, + */ + /* filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", + */ + /* 0); */ // Extract capsule bareosfd.PluginContext - void* ctx_from_bareosfd_module = - PyCapsule_Import("bareosfd.PluginContext", 0); - if (!ctx_from_bareosfd_module) { - printf("importing bareosfd.PluginContext failed \n"); - } + /* void* ctx_from_bareosfd_module = */ + /* PyCapsule_Import("bareosfd.PluginContext", 0); */ + /* if (!ctx_from_bareosfd_module) { */ + /* printf("importing bareosfd.PluginContext failed \n"); */ + /* } */ // Extract capsules bareosfd.BareosCoreFunctions - void* bareos_core_functions_from_bareosfd_module = - PyCapsule_Import("bareosfd.BareosCoreFunctions", 0); - if (!bareos_core_functions_from_bareosfd_module) { - printf("importing bareosfd.BareosCoreFunctions failed \n"); - } + /* void* bareos_core_functions_from_bareosfd_module = */ + /* PyCapsule_Import("bareosfd.BareosCoreFunctions", 0); */ + /* if (!bareos_core_functions_from_bareosfd_module) { */ + /* printf("importing bareosfd.BareosCoreFunctions failed \n"); */ + /* } */ - if (!loadplugin_from_bareosfd_module) { - printf("importing bareosfd.loadPlugin failed \n"); - } + /* if (!loadplugin_from_bareosfd_module) { */ + /* printf("importing bareosfd.loadPlugin failed \n"); */ + /* } */ - *(void**)ctx_from_bareosfd_module = &bareos_PluginContext; - *(void**)bareos_core_functions_from_bareosfd_module = - &bareos_core_functions; + /* *(void**)ctx_from_bareosfd_module = &bareos_PluginContext; */ + /* *(void**)bareos_core_functions_from_bareosfd_module = */ + /* &bareos_core_functions; */ /* call loadPlugin in plugin */ - filedaemon::Core_PluginApiDefinition myInfo; - PluginInformation plugin_information; - filedaemon::pFuncs plugin_functions; - - loadplugin_from_bareosfd_module(&myInfo, bareos_core_functions, - (PluginInformation**)&plugin_information, - (filedaemon::pFuncs**)&plugin_functions); + /* filedaemon::Core_PluginApiDefinition myInfo; */ + /* PluginInformation plugin_information; */ + /* filedaemon::pFuncs plugin_functions; */ + /* loadplugin_from_bareosfd_module(&myInfo, bareos_core_functions, */ + /* (PluginInformation**)&plugin_information, + */ + /* (filedaemon::pFuncs**)&plugin_functions); + */ - printf("ctx_from_bareosfd_module contains %p\n", - *(void**)ctx_from_bareosfd_module); - printf("bareos_core_functions_from_bareosfd_module contains %p\n", - *(void**)bareos_core_functions_from_bareosfd_module); + /* printf("ctx_from_bareosfd_module contains %p\n", */ + /* *(void**)ctx_from_bareosfd_module); */ + /* printf("bareos_core_functions_from_bareosfd_module contains %p\n", */ + /* *(void**)bareos_core_functions_from_bareosfd_module); */ PyEval_InitThreads(); From f65e7eb941570e6b9cd36aa3b72519707604848f Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 7 May 2020 13:16:37 +0200 Subject: [PATCH 075/341] C_API: autogenerate even more parts --- core/src/plugins/filed/python/bareosfd.cc | 3 + core/src/plugins/filed/python/bareosfd.h | 138 +++++++++++++++++- core/src/plugins/filed/python/capi_3.inc | 38 +++++ .../create_CAPI_from_bareos_api_funcs.sh | 11 ++ core/src/plugins/filed/python/python-fd.cc | 3 + 5 files changed, 188 insertions(+), 5 deletions(-) create mode 100644 core/src/plugins/filed/python/capi_3.inc diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 557ef58790d..c8a9f5e96c4 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -58,6 +58,8 @@ static const int debuglevel = 150; /* "load>:..." */ /* Forward referenced functions */ +static bRC set_bareos_core_functions( + BareosCoreFunctions* new_bareos_core_functions); static bRC newPlugin(PluginContext* bareos_plugin_ctx); static bRC freePlugin(PluginContext* bareos_plugin_ctx); static bRC getPluginValue(PluginContext* bareos_plugin_ctx, @@ -326,6 +328,7 @@ static bRC set_bareos_core_functions( BareosCoreFunctions* new_bareos_core_functions) { bareos_core_functions = new_bareos_core_functions; + return bRC_OK; } diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/bareosfd.h index be25e1e2f29..062746eddf9 100644 --- a/core/src/plugins/filed/python/bareosfd.h +++ b/core/src/plugins/filed/python/bareosfd.h @@ -36,6 +36,73 @@ #include "structmember.h" +#if 0 +static bRC set_bareos_core_functions( + BareosCoreFunctions* new_bareos_core_functions); +static bRC newPlugin(PluginContext* bareos_plugin_ctx); +static bRC freePlugin(PluginContext* bareos_plugin_ctx); +static bRC getPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC setPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, + bEvent* event, + void* value); +static bRC startBackupFile(PluginContext* bareos_plugin_ctx, + struct save_pkt* sp); +static bRC endBackupFile(PluginContext* bareos_plugin_ctx); +static bRC pluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); +static bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); +static bRC endRestoreFile(PluginContext* bareos_plugin_ctx); +static bRC createFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); +static bRC setFileAttributes(PluginContext* bareos_plugin_ctx, + struct restore_pkt* rp); +static bRC checkFile(PluginContext* bareos_plugin_ctx, char* fname); +static bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC setXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, + void* value, + PoolMem& plugin_options); + + +static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); +static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); +static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, + void* value); +static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, + bEvent* event, + void* value); +static bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, + struct save_pkt* sp); +static bRC PyEndBackupFile(PluginContext* bareos_plugin_ctx); +static bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); +static bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, + const char* cmd); +static bRC PyEndRestoreFile(PluginContext* bareos_plugin_ctx); +static bRC PyCreateFile(PluginContext* bareos_plugin_ctx, + struct restore_pkt* rp); +static bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, + struct restore_pkt* rp); +static bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname); +static bRC PyGetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC PySetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, + struct restore_object_pkt* rop); +static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, + struct save_pkt* sp); +#endif /* include automatically generated C API */ #include "capi_1.inc" @@ -43,10 +110,6 @@ #ifdef BAREOSFD_MODULE /* This section is used when compiling bareosfd.cc */ -static Bareosfd_PyLoadModule_RETURN Bareosfd_PyLoadModule - Bareosfd_PyLoadModule_PROTO; - - namespace filedaemon { /** @@ -762,7 +825,72 @@ static PyMethodDef Methods[] = { {NULL, NULL, 0, NULL}}; +static bRC set_bareos_core_functions( + BareosCoreFunctions* new_bareos_core_functions); +static bRC newPlugin(PluginContext* bareos_plugin_ctx); +static bRC freePlugin(PluginContext* bareos_plugin_ctx); +static bRC getPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC setPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, + bEvent* event, + void* value); +static bRC startBackupFile(PluginContext* bareos_plugin_ctx, + struct save_pkt* sp); +static bRC endBackupFile(PluginContext* bareos_plugin_ctx); +static bRC pluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); +static bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); +static bRC endRestoreFile(PluginContext* bareos_plugin_ctx); +static bRC createFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); +static bRC setFileAttributes(PluginContext* bareos_plugin_ctx, + struct restore_pkt* rp); +static bRC checkFile(PluginContext* bareos_plugin_ctx, char* fname); +static bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC setXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, + void* value, + PoolMem& plugin_options); + + +static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); +static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, + void* value); +static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value); +static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, + bEvent* event, + void* value); +static bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, + struct save_pkt* sp); +static bRC PyEndBackupFile(PluginContext* bareos_plugin_ctx); +static bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); +static bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, + const char* cmd); +static bRC PyEndRestoreFile(PluginContext* bareos_plugin_ctx); +static bRC PyCreateFile(PluginContext* bareos_plugin_ctx, + struct restore_pkt* rp); +static bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, + struct restore_pkt* rp); +static bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname); +static bRC PyGetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC PySetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); +static bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); +static bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, + struct restore_object_pkt* rop); +static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, + struct save_pkt* sp); + } /* namespace filedaemon */ using namespace filedaemon; @@ -792,7 +920,7 @@ MOD_INIT(bareosfd) PyObject* c_api_object; /* Initialize the C API pointer array */ - Bareosfd_API[Bareosfd_PyLoadModule_NUM] = (void*)PyLoadModule; +#include "capi_3.inc" /* Create a Capsule containing the API pointer array's address */ c_api_object = PyCapsule_New((void*)Bareosfd_API, diff --git a/core/src/plugins/filed/python/capi_3.inc b/core/src/plugins/filed/python/capi_3.inc new file mode 100644 index 00000000000..15f72de97ce --- /dev/null +++ b/core/src/plugins/filed/python/capi_3.inc @@ -0,0 +1,38 @@ + Bareosfd_API[Bareosfd_newPlugin_NUM] = (void*)newPlugin; + Bareosfd_API[Bareosfd_freePlugin_NUM] = (void*)freePlugin; + Bareosfd_API[Bareosfd_getPluginValue_NUM] = (void*)getPluginValue; + Bareosfd_API[Bareosfd_setPluginValue_NUM] = (void*)setPluginValue; + Bareosfd_API[Bareosfd_handlePluginEvent_NUM] = (void*)handlePluginEvent; + Bareosfd_API[Bareosfd_startBackupFile_NUM] = (void*)startBackupFile; + Bareosfd_API[Bareosfd_endBackupFile_NUM] = (void*)endBackupFile; + Bareosfd_API[Bareosfd_pluginIO_NUM] = (void*)pluginIO; + Bareosfd_API[Bareosfd_startRestoreFile_NUM] = (void*)startRestoreFile; + Bareosfd_API[Bareosfd_endRestoreFile_NUM] = (void*)endRestoreFile; + Bareosfd_API[Bareosfd_createFile_NUM] = (void*)createFile; + Bareosfd_API[Bareosfd_setFileAttributes_NUM] = (void*)setFileAttributes; + Bareosfd_API[Bareosfd_checkFile_NUM] = (void*)checkFile; + Bareosfd_API[Bareosfd_getAcl_NUM] = (void*)getAcl; + Bareosfd_API[Bareosfd_setAcl_NUM] = (void*)setAcl; + Bareosfd_API[Bareosfd_getXattr_NUM] = (void*)getXattr; + Bareosfd_API[Bareosfd_setXattr_NUM] = (void*)setXattr; + Bareosfd_API[Bareosfd_parse_plugin_definition_NUM] = (void*)parse_plugin_definition; + Bareosfd_API[Bareosfd_PyLoadModule_NUM] = (void*)PyLoadModule; + Bareosfd_API[Bareosfd_PyParsePluginDefinition_NUM] = (void*)PyParsePluginDefinition; + Bareosfd_API[Bareosfd_PyGetPluginValue_NUM] = (void*)PyGetPluginValue; + Bareosfd_API[Bareosfd_PySetPluginValue_NUM] = (void*)PySetPluginValue; + Bareosfd_API[Bareosfd_PyHandlePluginEvent_NUM] = (void*)PyHandlePluginEvent; + Bareosfd_API[Bareosfd_PyStartBackupFile_NUM] = (void*)PyStartBackupFile; + Bareosfd_API[Bareosfd_PyEndBackupFile_NUM] = (void*)PyEndBackupFile; + Bareosfd_API[Bareosfd_PyPluginIO_NUM] = (void*)PyPluginIO; + Bareosfd_API[Bareosfd_PyStartRestoreFile_NUM] = (void*)PyStartRestoreFile; + Bareosfd_API[Bareosfd_PyEndRestoreFile_NUM] = (void*)PyEndRestoreFile; + Bareosfd_API[Bareosfd_PyCreateFile_NUM] = (void*)PyCreateFile; + Bareosfd_API[Bareosfd_PySetFileAttributes_NUM] = (void*)PySetFileAttributes; + Bareosfd_API[Bareosfd_PyCheckFile_NUM] = (void*)PyCheckFile; + Bareosfd_API[Bareosfd_PyGetAcl_NUM] = (void*)PyGetAcl; + Bareosfd_API[Bareosfd_PySetAcl_NUM] = (void*)PySetAcl; + Bareosfd_API[Bareosfd_PyGetXattr_NUM] = (void*)PyGetXattr; + Bareosfd_API[Bareosfd_PySetXattr_NUM] = (void*)PySetXattr; + Bareosfd_API[Bareosfd_PyRestoreObjectData_NUM] = (void*)PyRestoreObjectData; + Bareosfd_API[Bareosfd_PyHandleBackupFile_NUM] = (void*)PyHandleBackupFile; + Bareosfd_API[Bareosfd_set_bareos_core_functions_NUM] = (void*)set_bareos_core_functions; diff --git a/core/src/plugins/filed/python/create_CAPI_from_bareos_api_funcs.sh b/core/src/plugins/filed/python/create_CAPI_from_bareos_api_funcs.sh index e76f83e1749..29467ae178c 100755 --- a/core/src/plugins/filed/python/create_CAPI_from_bareos_api_funcs.sh +++ b/core/src/plugins/filed/python/create_CAPI_from_bareos_api_funcs.sh @@ -33,3 +33,14 @@ for i in $(cat bareosfd_api_funcs.txt); do " ((NUM=NUM+1)) done + +exec >capi_3.inc + +NUM=0 +for i in $(cat bareosfd_api_funcs.txt); do + retval=$(echo $i | sed 's/ .*//g') + funcname=$(echo $i | cut -b 5- | sed s/\(.*//g) + prot=$(echo $i | sed s/.*\(//g | sed 's/);//g') + echo " Bareosfd_API[Bareosfd_${funcname}_NUM] = (void*)${funcname};" +((NUM=NUM+1)) +done diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 82b6de5affc..f71956ced03 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -248,6 +248,9 @@ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, /* import the CAPI from the bareosfd python module */ import_bareosfd(); + Bareosfd_PyHandleBackupFile(nullptr, nullptr); + + Bareosfd_set_bareos_core_functions(lbareos_core_functions); bareos_core_functions = lbareos_core_functions; /* Set Bareos funct pointers */ From a842394ab40a72df70426dab3e7a12803c9c5294 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 7 May 2020 13:20:34 +0200 Subject: [PATCH 076/341] bareosfd.h: cleanup --- core/src/plugins/filed/python/bareosfd.h | 67 ------------------------ 1 file changed, 67 deletions(-) diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/bareosfd.h index 062746eddf9..8e86bc1c656 100644 --- a/core/src/plugins/filed/python/bareosfd.h +++ b/core/src/plugins/filed/python/bareosfd.h @@ -36,73 +36,6 @@ #include "structmember.h" -#if 0 -static bRC set_bareos_core_functions( - BareosCoreFunctions* new_bareos_core_functions); -static bRC newPlugin(PluginContext* bareos_plugin_ctx); -static bRC freePlugin(PluginContext* bareos_plugin_ctx); -static bRC getPluginValue(PluginContext* bareos_plugin_ctx, - pVariable var, - void* value); -static bRC setPluginValue(PluginContext* bareos_plugin_ctx, - pVariable var, - void* value); -static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, - bEvent* event, - void* value); -static bRC startBackupFile(PluginContext* bareos_plugin_ctx, - struct save_pkt* sp); -static bRC endBackupFile(PluginContext* bareos_plugin_ctx); -static bRC pluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); -static bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); -static bRC endRestoreFile(PluginContext* bareos_plugin_ctx); -static bRC createFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); -static bRC setFileAttributes(PluginContext* bareos_plugin_ctx, - struct restore_pkt* rp); -static bRC checkFile(PluginContext* bareos_plugin_ctx, char* fname); -static bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC setXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, - void* value, - PoolMem& plugin_options); - - -static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); -static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); -static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, - void* value); -static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, - pVariable var, - void* value); -static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, - pVariable var, - void* value); -static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, - bEvent* event, - void* value); -static bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, - struct save_pkt* sp); -static bRC PyEndBackupFile(PluginContext* bareos_plugin_ctx); -static bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); -static bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, - const char* cmd); -static bRC PyEndRestoreFile(PluginContext* bareos_plugin_ctx); -static bRC PyCreateFile(PluginContext* bareos_plugin_ctx, - struct restore_pkt* rp); -static bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, - struct restore_pkt* rp); -static bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname); -static bRC PyGetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC PySetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, - struct restore_object_pkt* rop); -static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, - struct save_pkt* sp); -#endif /* include automatically generated C API */ #include "capi_1.inc" From c44e9693a50110b758abb4191e3ab4376b924e20 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 7 May 2020 14:02:42 +0200 Subject: [PATCH 077/341] python-fd.cc: works with loaded bareosfd module --- core/src/plugins/filed/python/python-fd.cc | 45 ++++++++++++---------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index f71956ced03..ff8190d93c5 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -104,24 +104,25 @@ static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, bEvent* event, void* value); -static bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, - struct save_pkt* sp); +/* static bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, */ +/* struct save_pkt* sp); */ static bRC PyEndBackupFile(PluginContext* bareos_plugin_ctx); -static bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); +/* static bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); + */ static bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); static bRC PyEndRestoreFile(PluginContext* bareos_plugin_ctx); -static bRC PyCreateFile(PluginContext* bareos_plugin_ctx, - struct restore_pkt* rp); -static bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, - struct restore_pkt* rp); +/* static bRC PyCreateFile(PluginContext* bareos_plugin_ctx, */ +/* struct restore_pkt* rp); */ +/* static bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, */ +/* struct restore_pkt* rp); */ static bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname); static bRC PyGetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); static bRC PySetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); static bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); static bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, - struct restore_object_pkt* rop); +/* static bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, */ +/* struct restore_object_pkt* rop); */ static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); @@ -248,7 +249,7 @@ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, /* import the CAPI from the bareosfd python module */ import_bareosfd(); - Bareosfd_PyHandleBackupFile(nullptr, nullptr); + // Bareosfd_PyHandleBackupFile(nullptr, nullptr); Bareosfd_set_bareos_core_functions(lbareos_core_functions); @@ -548,11 +549,11 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, retval = PyParsePluginDefinition(bareos_plugin_ctx, plugin_options.c_str()); if (retval == bRC_OK) { - retval = PyRestoreObjectData(bareos_plugin_ctx, rop); + retval = Bareosfd_PyRestoreObjectData(bareos_plugin_ctx, rop); } } } else { - retval = PyRestoreObjectData(bareos_plugin_ctx, rop); + retval = Bareosfd_PyRestoreObjectData(bareos_plugin_ctx, rop); } } break; @@ -598,7 +599,7 @@ static bRC startBackupFile(PluginContext* bareos_plugin_ctx, if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyStartBackupFile(bareos_plugin_ctx, sp); + retval = Bareosfd_PyStartBackupFile(bareos_plugin_ctx, sp); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); /* @@ -672,7 +673,7 @@ static bRC pluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io) if (!plugin_priv_ctx->python_loaded) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyPluginIO(bareos_plugin_ctx, io); + retval = Bareosfd_PyPluginIO(bareos_plugin_ctx, io); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -733,7 +734,7 @@ static bRC createFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyCreateFile(bareos_plugin_ctx, rp); + retval = Bareosfd_PyCreateFile(bareos_plugin_ctx, rp); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -754,7 +755,7 @@ static bRC setFileAttributes(PluginContext* bareos_plugin_ctx, if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PySetFileAttributes(bareos_plugin_ctx, rp); + retval = Bareosfd_PySetFileAttributes(bareos_plugin_ctx, rp); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -1490,7 +1491,7 @@ static inline bool PySavePacketToNative( bail_out: return false; } - +#if 0 /** * Called when starting to backup a file. Here the plugin must * return the "stat" packet for the directory/file and provide @@ -1544,7 +1545,7 @@ static bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, return retval; } - +#endif /** * Called at the end of backing up a file for a command plugin. * If the plugin's work is done, it should return bRC_OK. @@ -1655,6 +1656,7 @@ static inline bool PyIoPacketToNative(PyIoPacket* pIoPkt, struct io_pkt* io) return true; } +#if 0 /** * Do actual I/O. Bareos calls this after startBackupFile * or after startRestoreFile to do the actual file @@ -1707,7 +1709,7 @@ static bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io) return retval; } - +#endif /** * Called when the first record is read from the Volume that was previously * written by the command plugin. @@ -1823,6 +1825,7 @@ static inline void PyRestorePacketToNative(PyRestorePacket* pRestorePacket, rp->create_status = pRestorePacket->create_status; } +#if 0 /** * Called for a command plugin to create a file during a Restore job before * restoring the data. This entry point is called before any I/O is done on the @@ -1881,7 +1884,6 @@ static bRC PyCreateFile(PluginContext* bareos_plugin_ctx, return retval; } - static bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) { @@ -1925,6 +1927,7 @@ static bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, return retval; } +#endif static bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname) { @@ -2273,6 +2276,7 @@ static inline PyRestoreObject* NativeToPyRestoreObject( return pRestoreObject; } +#if 0 static bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, struct restore_object_pkt* rop) { @@ -2316,6 +2320,7 @@ static bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, return retval; } +#endif static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp) From 69dff7fee2517e0cb972584d5116285dbeccbb22 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 7 May 2020 14:22:14 +0200 Subject: [PATCH 078/341] python-fd.cc: use many functions form the bareosfd module --- core/src/plugins/filed/python/python-fd.cc | 866 +-------------------- 1 file changed, 22 insertions(+), 844 deletions(-) diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index ff8190d93c5..8f883a604ee 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -93,38 +93,13 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); -static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, - void* value); + static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); -static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, - bEvent* event, - void* value); -/* static bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, */ -/* struct save_pkt* sp); */ -static bRC PyEndBackupFile(PluginContext* bareos_plugin_ctx); -/* static bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); - */ -static bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, - const char* cmd); -static bRC PyEndRestoreFile(PluginContext* bareos_plugin_ctx); -/* static bRC PyCreateFile(PluginContext* bareos_plugin_ctx, */ -/* struct restore_pkt* rp); */ -/* static bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, */ -/* struct restore_pkt* rp); */ -static bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname); -static bRC PyGetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC PySetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -/* static bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, */ -/* struct restore_object_pkt* rop); */ -static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, - struct save_pkt* sp); /* Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; @@ -246,10 +221,12 @@ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, printf("loading of bareosfd failed\n"); if (PyErr_Occurred()) { PyErrorHandler(); } } - /* import the CAPI from the bareosfd python module */ - import_bareosfd(); - // Bareosfd_PyHandleBackupFile(nullptr, nullptr); + /* import the CAPI from the bareosfd python module + * afterwards, Bareosfd_* macros are initialized to + * point to the corresponding functions in the bareosfd python + * module */ + import_bareosfd(); Bareosfd_set_bareos_core_functions(lbareos_core_functions); @@ -260,67 +237,6 @@ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, *plugin_information = &pluginInfo; /* Return pointer to our info */ *plugin_functions = &pluginFuncs; /* Return pointer to our functions */ - /* filedaemon::Core_PluginApiDefinition myInfo; */ - /* PluginInformation plugin_information; */ - /* filedaemon::pFuncs plugin_functions; */ - /* Bareosfd_loadPlugin(&myInfo, bareos_core_functions, */ - /* (PluginInformation**)&plugin_information, */ - /* (filedaemon::pFuncs**)&plugin_functions); */ - - // Extract capsules pointer from bareosfd module - /* void (*loadplugin_from_bareosfd_module)( */ - /* filedaemon::Core_PluginApiDefinition * - * lbareos_plugin_interface_version, */ - /* filedaemon::BareosCoreFunctions * lbareos_core_functions, */ - /* PluginInformation * *plugin_information, */ - /* filedaemon::pFuncs * *plugin_functions) = */ - /* (void (*)(filedaemon::Core_PluginApiDefinition*, */ - /* filedaemon::BareosCoreFunctions*, PluginInformation**, - */ - /* filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", - */ - /* 0); */ - - // Extract capsule bareosfd.PluginContext - /* void* ctx_from_bareosfd_module = */ - /* PyCapsule_Import("bareosfd.PluginContext", 0); */ - /* if (!ctx_from_bareosfd_module) { */ - /* printf("importing bareosfd.PluginContext failed \n"); */ - /* } */ - - // Extract capsules bareosfd.BareosCoreFunctions - /* void* bareos_core_functions_from_bareosfd_module = */ - /* PyCapsule_Import("bareosfd.BareosCoreFunctions", 0); */ - /* if (!bareos_core_functions_from_bareosfd_module) { */ - /* printf("importing bareosfd.BareosCoreFunctions failed \n"); */ - /* } */ - - /* if (!loadplugin_from_bareosfd_module) { */ - /* printf("importing bareosfd.loadPlugin failed \n"); */ - /* } */ - - - /* *(void**)ctx_from_bareosfd_module = &bareos_PluginContext; */ - /* *(void**)bareos_core_functions_from_bareosfd_module = */ - /* &bareos_core_functions; */ - - /* call loadPlugin in plugin */ - /* filedaemon::Core_PluginApiDefinition myInfo; */ - /* PluginInformation plugin_information; */ - /* filedaemon::pFuncs plugin_functions; */ - - /* loadplugin_from_bareosfd_module(&myInfo, bareos_core_functions, */ - /* (PluginInformation**)&plugin_information, - */ - /* (filedaemon::pFuncs**)&plugin_functions); - */ - - /* printf("ctx_from_bareosfd_module contains %p\n", */ - /* *(void**)ctx_from_bareosfd_module); */ - /* printf("bareos_core_functions_from_bareosfd_module contains %p\n", */ - /* *(void**)bareos_core_functions_from_bareosfd_module); */ - - PyEval_InitThreads(); mainThreadState = PyEval_SaveThread(); } @@ -525,8 +441,8 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, /* Only try to call when the loading succeeded. */ if (retval == bRC_OK) { - retval = PyParsePluginDefinition(bareos_plugin_ctx, - plugin_options.c_str()); + retval = Bareosfd_PyParsePluginDefinition(bareos_plugin_ctx, + plugin_options.c_str()); } break; case bEventRestoreObject: { @@ -546,8 +462,8 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, /* Only try to call when the loading succeeded. */ if (retval == bRC_OK) { - retval = PyParsePluginDefinition(bareos_plugin_ctx, - plugin_options.c_str()); + retval = Bareosfd_PyParsePluginDefinition(bareos_plugin_ctx, + plugin_options.c_str()); if (retval == bRC_OK) { retval = Bareosfd_PyRestoreObjectData(bareos_plugin_ctx, rop); } @@ -559,7 +475,8 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, break; } case bEventHandleBackupFile: - retval = PyHandleBackupFile(bareos_plugin_ctx, (struct save_pkt*)value); + retval = Bareosfd_PyHandleBackupFile(bareos_plugin_ctx, + (struct save_pkt*)value); break; default: /* @@ -568,7 +485,8 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, * that time we pretend the call succeeded. */ if (plugin_priv_ctx->python_loaded) { - retval = PyHandlePluginEvent(bareos_plugin_ctx, event, value); + retval = + Bareosfd_PyHandlePluginEvent(bareos_plugin_ctx, event, value); } else { retval = bRC_OK; } @@ -650,7 +568,7 @@ static bRC endBackupFile(PluginContext* bareos_plugin_ctx) if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyEndBackupFile(bareos_plugin_ctx); + retval = Bareosfd_PyEndBackupFile(bareos_plugin_ctx); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -692,7 +610,7 @@ static bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd) if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyStartRestoreFile(bareos_plugin_ctx, cmd); + retval = Bareosfd_PyStartRestoreFile(bareos_plugin_ctx, cmd); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -711,7 +629,7 @@ static bRC endRestoreFile(PluginContext* bareos_plugin_ctx) if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyEndRestoreFile(bareos_plugin_ctx); + retval = Bareosfd_PyEndRestoreFile(bareos_plugin_ctx); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -776,7 +694,7 @@ static bRC checkFile(PluginContext* bareos_plugin_ctx, char* fname) if (!plugin_priv_ctx->python_loaded) { return bRC_OK; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyCheckFile(bareos_plugin_ctx, fname); + retval = Bareosfd_PyCheckFile(bareos_plugin_ctx, fname); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -794,7 +712,7 @@ static bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyGetAcl(bareos_plugin_ctx, ap); + retval = Bareosfd_PyGetAcl(bareos_plugin_ctx, ap); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -812,7 +730,7 @@ static bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PySetAcl(bareos_plugin_ctx, ap); + retval = Bareosfd_PySetAcl(bareos_plugin_ctx, ap); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -830,7 +748,7 @@ static bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyGetXattr(bareos_plugin_ctx, xp); + retval = Bareosfd_PyGetXattr(bareos_plugin_ctx, xp); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -848,7 +766,7 @@ static bRC setXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PySetXattr(bareos_plugin_ctx, xp); + retval = Bareosfd_PySetXattr(bareos_plugin_ctx, xp); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -1159,58 +1077,6 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) return retval; } -/** - * Any plugin options which are passed in are dispatched here to a Python method - * and it can parse the plugin options. This function is also called after - * PyLoadModule() has loaded the Python module and made sure things are - * operational. Normally you would only get one set of plugin options but for a - * restore overrides can be passed in before the actual plugin options are - * restored as part of the restore stream handling. - */ -static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, - void* value) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - PyObject* pFunc; - - /* - * Lookup the parse_plugin_definition() function in the python module. - */ - pFunc = - PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "parse_plugin_definition"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyObject *pPluginDefinition, *pRetVal; - - pPluginDefinition = PyString_FromString((char*)value); - if (!pPluginDefinition) { goto bail_out; } - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); - Py_DECREF(pPluginDefinition); - - if (!pRetVal) { - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - } - - return retval; - } else { - Dmsg( - bareos_plugin_ctx, debuglevel, - "python-fd: Failed to find function named parse_plugin_definition()\n"); - return bRC_Error; - } - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } - - return retval; -} - static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value) @@ -1225,47 +1091,6 @@ static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, return bRC_OK; } -static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, - bEvent* event, - void* value) -{ - bRC retval = bRC_Error; - plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - PyObject* pFunc; - - /* - * Lookup the handle_plugin_event() function in the python module. - */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "handle_plugin_event"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyObject *pEventType, *pRetVal; - - pEventType = PyInt_FromLong(event->eventType); - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pEventType, NULL); - Py_DECREF(pEventType); - - if (!pRetVal) { - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - } - } else { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Failed to find function named handle_plugin_event()\n"); - } - - return retval; - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } - - return retval; -} - static inline PyStatPacket* NativeToPyStatPacket(struct stat* statp) { PyStatPacket* pStatp = PyObject_New(PyStatPacket, &PyStatPacketType); @@ -1491,100 +1316,6 @@ static inline bool PySavePacketToNative( bail_out: return false; } -#if 0 -/** - * Called when starting to backup a file. Here the plugin must - * return the "stat" packet for the directory/file and provide - * certain information so that Bareos knows what the file is. - * The plugin can create "Virtual" files by giving them a - * name that is not normally found on the file system. - */ -static bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, - struct save_pkt* sp) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - PyObject* pFunc; - - /* - * Lookup the start_backup_file() function in the python module. - */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "start_backup_file"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PySavePacket* pSavePkt; - PyObject* pRetVal; - - pSavePkt = NativeToPySavePacket(sp); - if (!pSavePkt) { goto bail_out; } - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, (PyObject*)pSavePkt, NULL); - if (!pRetVal) { - Py_DECREF((PyObject*)pSavePkt); - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - - if (!PySavePacketToNative(pSavePkt, sp, plugin_priv_ctx, false)) { - Py_DECREF((PyObject*)pSavePkt); - goto bail_out; - } - Py_DECREF((PyObject*)pSavePkt); - } - } else { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Failed to find function named start_backup_file()\n"); - } - - return retval; - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } - - return retval; -} -#endif -/** - * Called at the end of backing up a file for a command plugin. - * If the plugin's work is done, it should return bRC_OK. - * If the plugin wishes to create another file and back it up, - * then it must return bRC_More (not yet implemented). - */ -static bRC PyEndBackupFile(PluginContext* bareos_plugin_ctx) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - PyObject* pFunc; - - /* - * Lookup the end_backup_file() function in the python module. - */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "end_backup_file"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyObject* pRetVal; - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, NULL); - if (!pRetVal) { - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - } - } else { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Failed to find function named end_backup_file()\n"); - } - - return retval; - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } - - return retval; -} static inline PyIoPacket* NativeToPyIoPacket(struct io_pkt* io) { @@ -1656,141 +1387,6 @@ static inline bool PyIoPacketToNative(PyIoPacket* pIoPkt, struct io_pkt* io) return true; } -#if 0 -/** - * Do actual I/O. Bareos calls this after startBackupFile - * or after startRestoreFile to do the actual file - * input or output. - */ -static bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - PyObject* pFunc; - - /* - * Lookup the plugin_io() function in the python module. - */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "plugin_io"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyIoPacket* pIoPkt; - PyObject* pRetVal; - - pIoPkt = NativeToPyIoPacket(io); - if (!pIoPkt) { goto bail_out; } - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, (PyObject*)pIoPkt, NULL); - if (!pRetVal) { - Py_DECREF((PyObject*)pIoPkt); - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - - if (!PyIoPacketToNative(pIoPkt, io)) { - Py_DECREF((PyObject*)pIoPkt); - goto bail_out; - } - } - Py_DECREF((PyObject*)pIoPkt); - } else { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Failed to find function named plugin_io()\n"); - } - - return retval; - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } - - io->status = -1; - - return retval; -} -#endif -/** - * Called when the first record is read from the Volume that was previously - * written by the command plugin. - */ -static bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - PyObject* pFunc; - - /* - * Lookup the start_restore_file() function in the python module. - */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "start_restore_file"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyObject *pCmd, *pRetVal; - - pCmd = PyString_FromString(cmd); - if (!pCmd) { goto bail_out; } - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pCmd, NULL); - Py_DECREF(pCmd); - - if (!pRetVal) { - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - } - } else { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Failed to find function named start_restore_file()\n"); - } - - return retval; - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } - - return retval; -} - -/** - * Called when a command plugin is done restoring a file. - */ -static bRC PyEndRestoreFile(PluginContext* bareos_plugin_ctx) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - PyObject* pFunc; - - /* - * Lookup the end_restore_file() function in the python module. - */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "end_restore_file"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyObject* pRetVal; - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, NULL); - if (!pRetVal) { - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - } - } else { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Failed to find function named end_restore_file()\n"); - } - - return retval; - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } - - return retval; -} - static inline PyRestorePacket* NativeToPyRestorePacket(struct restore_pkt* rp) { PyRestorePacket* pRestorePacket = @@ -1825,149 +1421,6 @@ static inline void PyRestorePacketToNative(PyRestorePacket* pRestorePacket, rp->create_status = pRestorePacket->create_status; } -#if 0 -/** - * Called for a command plugin to create a file during a Restore job before - * restoring the data. This entry point is called before any I/O is done on the - * file. After this call, Bareos will call pluginIO() to open the file for - * write. - * - * We must return in rp->create_status: - * - * CF_ERROR -- error - * CF_SKIP -- skip processing this file - * CF_EXTRACT -- extract the file (i.e.call i/o routines) - * CF_CREATED -- created, but no content to extract (typically directories) - */ -static bRC PyCreateFile(PluginContext* bareos_plugin_ctx, - struct restore_pkt* rp) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - PyObject* pFunc; - - if (!rp) { return bRC_Error; } - - /* - * Lookup the create_file() function in the python module. - */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "create_file"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyRestorePacket* pRestorePacket; - PyObject* pRetVal; - - pRestorePacket = NativeToPyRestorePacket(rp); - if (!pRestorePacket) { goto bail_out; } - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pRestorePacket, NULL); - if (!pRetVal) { - Py_DECREF(pRestorePacket); - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - - PyRestorePacketToNative(pRestorePacket, rp); - Py_DECREF(pRestorePacket); - } - } else { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Failed to find function named create_file()\n"); - } - - return retval; - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } - - return retval; -} -static bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, - struct restore_pkt* rp) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - PyObject* pFunc; - - if (!rp) { return bRC_Error; } - - /* - * Lookup the set_file_attributes() function in the python module. - */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "set_file_attributes"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyRestorePacket* pRestorePacket; - PyObject* pRetVal; - - pRestorePacket = NativeToPyRestorePacket(rp); - if (!pRestorePacket) { goto bail_out; } - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pRestorePacket, NULL); - if (!pRetVal) { - Py_DECREF(pRestorePacket); - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - Py_DECREF(pRestorePacket); - } - } else { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Failed to find function named set_file_attributes()\n"); - } - - return retval; - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } - - return retval; -} -#endif - -static bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - PyObject* pFunc; - - if (!fname) { return bRC_Error; } - - /* - * Lookup the check_file() function in the python module. - */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "check_file"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyObject *pFname, *pRetVal; - - pFname = PyString_FromString(fname); - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pFname, NULL); - Py_DECREF(pFname); - - if (!pRetVal) { - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - } - } else { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Failed to find function named check_file()\n"); - } - - return retval; - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } - - return retval; -} static inline PyAclPacket* NativeToPyAclPacket(struct acl_pkt* ap) { @@ -2009,97 +1462,6 @@ static inline bool PyAclPacketToNative(PyAclPacket* pAclPacket, return true; } -static bRC PyGetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - PyObject* pFunc; - - if (!ap) { return bRC_Error; } - - /* - * Lookup the get_acl() function in the python module. - */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "get_acl"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyAclPacket* pAclPkt; - PyObject* pRetVal; - - pAclPkt = NativeToPyAclPacket(ap); - if (!pAclPkt) { goto bail_out; } - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pAclPkt, NULL); - if (!pRetVal) { - Py_DECREF((PyObject*)pAclPkt); - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - - if (!PyAclPacketToNative(pAclPkt, ap)) { - Py_DECREF((PyObject*)pAclPkt); - goto bail_out; - } - Py_DECREF(pAclPkt); - } - } else { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Failed to find function named get_acl()\n"); - } - - return retval; - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } - - return retval; -} - -static bRC PySetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - PyObject* pFunc; - - if (!ap) { return bRC_Error; } - - /* - * Lookup the set_acl() function in the python module. - */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "set_acl"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyAclPacket* pAclPkt; - PyObject* pRetVal; - - pAclPkt = NativeToPyAclPacket(ap); - if (!pAclPkt) { goto bail_out; } - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pAclPkt, NULL); - Py_DECREF(pAclPkt); - - if (!pRetVal) { - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - } - } else { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Failed to find function named set_acl()\n"); - } - - return retval; - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } - - return retval; -} - static inline PyXattrPacket* NativeToPyXattrPacket(struct xattr_pkt* xp) { PyXattrPacket* pXattrPacket = PyObject_New(PyXattrPacket, &PyXattrPacketType); @@ -2163,96 +1525,6 @@ static inline bool PyXattrPacketToNative(PyXattrPacket* pXattrPacket, return true; } -static bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - PyObject* pFunc; - - if (!xp) { return bRC_Error; } - - /* - * Lookup the get_xattr() function in the python module. - */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "get_xattr"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyXattrPacket* pXattrPkt; - PyObject* pRetVal; - - pXattrPkt = NativeToPyXattrPacket(xp); - if (!pXattrPkt) { goto bail_out; } - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pXattrPkt, NULL); - if (!pRetVal) { - Py_DECREF((PyObject*)pXattrPkt); - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - - if (!PyXattrPacketToNative(pXattrPkt, xp)) { - Py_DECREF((PyObject*)pXattrPkt); - goto bail_out; - } - Py_DECREF(pXattrPkt); - } - } else { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Failed to find function named get_xattr()\n"); - } - - return retval; - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } - - return retval; -} - -static bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - PyObject* pFunc; - - if (!xp) { return bRC_Error; } - - /* - * Lookup the set_acl() function in the python module. - */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "set_xattr"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyXattrPacket* pXattrPkt; - PyObject* pRetVal; - - pXattrPkt = NativeToPyXattrPacket(xp); - if (!pXattrPkt) { goto bail_out; } - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pXattrPkt, NULL); - Py_DECREF(pXattrPkt); - - if (!pRetVal) { - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - } - } else { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Failed to find function named set_xattr()\n"); - } - - return retval; -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } - - return retval; -} - static inline PyRestoreObject* NativeToPyRestoreObject( struct restore_object_pkt* rop) { @@ -2276,100 +1548,6 @@ static inline PyRestoreObject* NativeToPyRestoreObject( return pRestoreObject; } -#if 0 -static bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, - struct restore_object_pkt* rop) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - PyObject* pFunc; - - if (!rop) { return bRC_OK; } - - /* - * Lookup the restore_object_data() function in the python module. - */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "restore_object_data"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyRestoreObject* pRestoreObject; - PyObject* pRetVal; - - pRestoreObject = NativeToPyRestoreObject(rop); - if (!pRestoreObject) { goto bail_out; } - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pRestoreObject, NULL); - Py_DECREF(pRestoreObject); - - if (!pRetVal) { - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - } - } else { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Failed to find function named start_restore_file()\n"); - } - - return retval; - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } - - return retval; -} -#endif - -static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, - struct save_pkt* sp) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - PyObject* pFunc; - - if (!sp) { return bRC_Error; } - - /* - * Lookup the handle_backup_file() function in the python module. - */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "handle_backup_file"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PySavePacket* pSavePkt; - PyObject* pRetVal; - - pSavePkt = NativeToPySavePacket(sp); - if (!pSavePkt) { goto bail_out; } - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pSavePkt, NULL); - if (!pRetVal) { - Py_DECREF((PyObject*)pSavePkt); - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - - if (!PySavePacketToNative(pSavePkt, sp, plugin_priv_ctx, true)) { - Py_DECREF((PyObject*)pSavePkt); - goto bail_out; - } - Py_DECREF(pSavePkt); - } - } else { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Failed to find function named handle_backup_file()\n"); - } - - return retval; - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } - - return retval; -} /** * Callback function which is exposed as a part of the additional methods which From 425983762b5527c900db1fad0fc97954ba8ea754 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 7 May 2020 16:14:45 +0200 Subject: [PATCH 079/341] bareosfd.cc: removed unneeded functions --- core/src/plugins/filed/python/bareosfd.cc | 982 +----------------- core/src/plugins/filed/python/bareosfd.h | 39 +- .../filed/python/bareosfd_api_funcs.txt | 19 - core/src/plugins/filed/python/capi_1.inc | 135 +-- core/src/plugins/filed/python/capi_2.inc | 38 - core/src/plugins/filed/python/capi_3.inc | 19 - core/src/plugins/filed/python/python-fd.cc | 5 - .../python/test/python-fd-module-tester.cc | 17 +- core/src/plugins/python_plugins_common.inc | 2 + 9 files changed, 39 insertions(+), 1217 deletions(-) diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index c8a9f5e96c4..49ba74d60d2 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -47,51 +47,11 @@ namespace filedaemon { static const int debuglevel = 150; -#define PLUGIN_LICENSE "Bareos AGPLv3" -#define PLUGIN_AUTHOR "Marco van Wieringen" -#define PLUGIN_DATE "May 2014" -#define PLUGIN_VERSION "3" -#define PLUGIN_DESCRIPTION "Python File Daemon Plugin" -#define PLUGIN_USAGE \ -/* "python:module_path=:module_name=:..." */ - -/* Forward referenced functions */ static bRC set_bareos_core_functions( BareosCoreFunctions* new_bareos_core_functions); -static bRC newPlugin(PluginContext* bareos_plugin_ctx); -static bRC freePlugin(PluginContext* bareos_plugin_ctx); -static bRC getPluginValue(PluginContext* bareos_plugin_ctx, - pVariable var, - void* value); -static bRC setPluginValue(PluginContext* bareos_plugin_ctx, - pVariable var, - void* value); -static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, - bEvent* event, - void* value); -static bRC startBackupFile(PluginContext* bareos_plugin_ctx, - struct save_pkt* sp); -static bRC endBackupFile(PluginContext* bareos_plugin_ctx); -static bRC pluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); -static bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); -static bRC endRestoreFile(PluginContext* bareos_plugin_ctx); -static bRC createFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); -static bRC setFileAttributes(PluginContext* bareos_plugin_ctx, - struct restore_pkt* rp); -static bRC checkFile(PluginContext* bareos_plugin_ctx, char* fname); -static bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC setXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, - void* value, - PoolMem& plugin_options); static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); -static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, void* value); static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, @@ -128,23 +88,8 @@ static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, static BareosCoreFunctions* bareos_core_functions = NULL; static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; -static PluginInformation pluginInfo = { - sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, - FD_PLUGIN_MAGIC, PLUGIN_LICENSE, - PLUGIN_AUTHOR, PLUGIN_DATE, - PLUGIN_VERSION, PLUGIN_DESCRIPTION, - PLUGIN_USAGE}; - -static pFuncs pluginFuncs = { - sizeof(pluginFuncs), FD_PLUGIN_INTERFACE_VERSION, - - /* Entry points into plugin */ - newPlugin, /* new plugin instance */ - freePlugin, /* free plugin instance */ - getPluginValue, setPluginValue, handlePluginEvent, startBackupFile, - endBackupFile, startRestoreFile, endRestoreFile, pluginIO, createFile, - setFileAttributes, checkFile, getAcl, setAcl, getXattr, setXattr}; +// TODO: put this in its own header file struct plugin_private_context { int32_t backup_level; /* Backup level e.g. Full/Differential/Incremental */ utime_t since; /* Since time for Differential/Incremental */ @@ -165,18 +110,13 @@ struct plugin_private_context { bareos_core_functions; /* pointer to bareos_core_functions */ }; // namespace filedaemon -/** - * We don't actually use this but we need it to tear down the - * final python interpreter on unload of the plugin. Each instance of - * the plugin get its own interpreter. - */ -static PyThreadState* mainThreadState; +#define NOPLUGINSETGETVALUE 1 /* functions common to all plugins */ #include "plugins/python_plugins_common.inc" #ifdef __cplusplus -extern "C" { +// extern "C" { #endif static void PyErrorHandler() @@ -219,108 +159,8 @@ static void PyErrorHandler() } -/** - * Plugin called here when it is first loaded - */ -bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, - BareosCoreFunctions* lbareos_core_functions, - PluginInformation** plugin_information, - pFuncs** plugin_functions) -{ - bareos_core_functions = - lbareos_core_functions; /* Set Bareos funct * pointers */ - bareos_plugin_interface_version = lbareos_plugin_interface_version; - - *plugin_information = &pluginInfo; /* Return pointer to our info */ - *plugin_functions = &pluginFuncs; /* Return pointer to our functions */ - - if (!Py_IsInitialized()) { - /* Setup Python */ -#if PY_MAJOR_VERSION >= 3 - /* PyImport_AppendInittab("bareosfd", &PyInit_bareosfd); */ -#else - /* PyImport_AppendInittab("bareosfd", initbareosfd); */ -#endif - Py_InitializeEx(0); - - /* import the bareosfd module */ - PyObject* bareosfdModule = PyImport_ImportModule("bareosfd"); - if (bareosfdModule) { - printf("loaded bareosfd successfully\n"); - } else { - printf("loading of bareosfd failed\n"); - } - if (PyErr_Occurred()) { PyErrorHandler(); } - // Extract capsules pointer from bareosfd module - void (*loadplugin_from_bareosfd_module)( - filedaemon::Core_PluginApiDefinition * lbareos_plugin_interface_version, - filedaemon::BareosCoreFunctions * lbareos_core_functions, - PluginInformation * *plugin_information, - filedaemon::pFuncs * *plugin_functions) = - (void (*)(filedaemon::Core_PluginApiDefinition*, - filedaemon::BareosCoreFunctions*, PluginInformation**, - filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", - 0); - - /* // Extract capsule bareosfd.PluginContext */ - void* ctx_from_bareosfd_module = - PyCapsule_Import("bareosfd.PluginContext", 0); - if (!ctx_from_bareosfd_module) { - printf("importing bareosfd.PluginContext failed \n"); - } - - // Extract capsules bareosfd.BareosCoreFunctions - void* bareos_core_functions_from_bareosfd_module = - PyCapsule_Import("bareosfd.BareosCoreFunctions", 0); - if (!bareos_core_functions_from_bareosfd_module) { - printf("importing bareosfd.BareosCoreFunctions failed \n"); - } - - if (!loadplugin_from_bareosfd_module) { - printf("importing bareosfd.loadPlugin failed \n"); - } - - - *(void**)ctx_from_bareosfd_module = &bareos_PluginContext; - *(void**)bareos_core_functions_from_bareosfd_module = - &bareos_core_functions; - - /* call loadPlugin in plugin */ - filedaemon::Core_PluginApiDefinition myInfo; - PluginInformation plugin_information; - filedaemon::pFuncs plugin_functions; - - loadplugin_from_bareosfd_module(&myInfo, bareos_core_functions, - (PluginInformation**)&plugin_information, - (filedaemon::pFuncs**)&plugin_functions); - - - printf("ctx_from_bareosfd_module contains %p\n", - *(void**)ctx_from_bareosfd_module); - printf("bareos_core_functions_from_bareosfd_module contains %p\n", - *(void**)bareos_core_functions_from_bareosfd_module); - - - PyEval_InitThreads(); - mainThreadState = PyEval_SaveThread(); - } - return bRC_OK; -} - -/** - * Plugin called here when it is unloaded, normally when Bareos is going to - * exit. - */ -bRC unloadPlugin() -{ - /* Terminate Python */ - PyEval_RestoreThread(mainThreadState); - Py_Finalize(); - return bRC_OK; -} - #ifdef __cplusplus -} +//} #endif /* set the bareos_core_functions pointer to the given value */ @@ -331,820 +171,6 @@ static bRC set_bareos_core_functions( return bRC_OK; } - -/** - * Called here to make a new instance of the plugin -- i.e. when - * a new Job is started. There can be multiple instances of - * each plugin that are running at the same time. Your - * plugin instance must be thread safe and keep its own - * local data. - */ -static bRC newPlugin(PluginContext* bareos_plugin_ctx) -{ - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)malloc( - sizeof(struct plugin_private_context)); - if (!plugin_priv_ctx) { return bRC_Error; } - memset(plugin_priv_ctx, 0, sizeof(struct plugin_private_context)); - bareos_plugin_ctx->plugin_private_context = - (void*)plugin_priv_ctx; /* set our context pointer */ - - plugin_priv_ctx->bareos_core_functions = bareos_core_functions; - - /* For each plugin instance we instantiate a new Python interpreter. */ - PyEval_AcquireThread(mainThreadState); - plugin_priv_ctx->interpreter = Py_NewInterpreter(); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - - /* Always register some events the python plugin itself can register - any other events it is interested in. */ - bareos_core_functions->registerBareosEvents( - bareos_plugin_ctx, 9, bEventLevel, bEventSince, bEventNewPluginOptions, - bEventPluginCommand, bEventJobStart, bEventRestoreCommand, - bEventEstimateCommand, bEventBackupCommand, bEventRestoreObject); - - return bRC_OK; -} - -/** - * Release everything concerning a particular instance of a - * plugin. Normally called when the Job terminates. - */ -static bRC freePlugin(PluginContext* bareos_plugin_ctx) -{ - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - - if (!plugin_priv_ctx) { return bRC_Error; } - - if (plugin_priv_ctx->plugin_options) { - free(plugin_priv_ctx->plugin_options); - } - - if (plugin_priv_ctx->module_path) { free(plugin_priv_ctx->module_path); } - - if (plugin_priv_ctx->module_name) { free(plugin_priv_ctx->module_name); } - - if (plugin_priv_ctx->fname) { free(plugin_priv_ctx->fname); } - - if (plugin_priv_ctx->link) { free(plugin_priv_ctx->link); } - - if (plugin_priv_ctx->object_name) { free(plugin_priv_ctx->object_name); } - - if (plugin_priv_ctx->object) { free(plugin_priv_ctx->object); } - - /* - * Stop any sub interpreter started per plugin instance. - */ - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - - - if (plugin_priv_ctx->pModule) { Py_DECREF(plugin_priv_ctx->pModule); } - - Py_EndInterpreter(plugin_priv_ctx->interpreter); - PyEval_ReleaseLock(); - - free(plugin_priv_ctx); - bareos_plugin_ctx->plugin_private_context = NULL; - - return bRC_OK; -} - - -static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, - bEvent* event, - void* value) -{ - bRC retval = bRC_Error; - bool event_dispatched = false; - PoolMem plugin_options(PM_FNAME); - plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - - if (!plugin_priv_ctx) { goto bail_out; } - - /* - * First handle some events internally before calling python if it - * want to do some special handling on the event triggered. - */ - switch (event->eventType) { - case bEventLevel: - plugin_priv_ctx->backup_level = (int64_t)value; - break; - case bEventSince: - plugin_priv_ctx->since = (int64_t)value; - break; - case bEventBackupCommand: - /* - * Fall-through wanted - */ - case bEventRestoreCommand: - /* Fall-through wanted */ - case bEventEstimateCommand: - /* Fall-through wanted */ - case bEventPluginCommand: - event_dispatched = true; - retval = - parse_plugin_definition(bareos_plugin_ctx, value, plugin_options); - break; - case bEventNewPluginOptions: - /* Free any previous value. */ - if (plugin_priv_ctx->plugin_options) { - free(plugin_priv_ctx->plugin_options); - plugin_priv_ctx->plugin_options = NULL; - } - - event_dispatched = true; - retval = - parse_plugin_definition(bareos_plugin_ctx, value, plugin_options); - - /* Save that we got a plugin override. */ - plugin_priv_ctx->plugin_options = strdup((char*)value); - break; - case bEventRestoreObject: { - struct restore_object_pkt* rop; - - rop = (struct restore_object_pkt*)value; - - /* Only use the plugin definition of a restore object if we - * didn't get any other plugin definition from some other source before.*/ - if (!plugin_priv_ctx->python_loaded) { - if (rop && *rop->plugin_name) { - event_dispatched = true; - retval = parse_plugin_definition(bareos_plugin_ctx, rop->plugin_name, - plugin_options); - } - } - break; - } - default: - break; - } - - /* - * See if we have been triggered in the previous switch if not we have to - * always dispatch the event. If we already processed the event internally - * we only do a dispatch to the python entry point when that internal - * processing was successful (e.g. retval == bRC_OK). - */ - if (!event_dispatched || retval == bRC_OK) { - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - - /* - * Now dispatch the event to Python. - * First the calls that need special handling. - */ - switch (event->eventType) { - case bEventBackupCommand: - /* Fall-through wanted */ - case bEventRestoreCommand: - /* Fall-through wanted */ - case bEventEstimateCommand: - /* Fall-through wanted */ - case bEventPluginCommand: - /* Fall-through wanted */ - case bEventNewPluginOptions: - /* See if we already loaded the Python modules. */ - if (!plugin_priv_ctx->python_loaded) { - retval = PyLoadModule(bareos_plugin_ctx, plugin_options.c_str()); - } - - /* Only try to call when the loading succeeded. */ - if (retval == bRC_OK) { - retval = PyParsePluginDefinition(bareos_plugin_ctx, - plugin_options.c_str()); - } - break; - case bEventRestoreObject: { - struct restore_object_pkt* rop; - - rop = (struct restore_object_pkt*)value; - if (!rop) { - /* - * If rop == NULL this means we got the last restore object. - * No need to call into python so just return. - */ - retval = bRC_OK; - } else { - /* See if we already loaded the Python modules. */ - if (!plugin_priv_ctx->python_loaded && *rop->plugin_name) { - retval = PyLoadModule(bareos_plugin_ctx, plugin_options.c_str()); - - /* Only try to call when the loading succeeded. */ - if (retval == bRC_OK) { - retval = PyParsePluginDefinition(bareos_plugin_ctx, - plugin_options.c_str()); - if (retval == bRC_OK) { - retval = PyRestoreObjectData(bareos_plugin_ctx, rop); - } - } - } else { - retval = PyRestoreObjectData(bareos_plugin_ctx, rop); - } - } - break; - } - case bEventHandleBackupFile: - retval = PyHandleBackupFile(bareos_plugin_ctx, (struct save_pkt*)value); - break; - default: - /* - * Handle the generic events e.g. the ones which are just passed on. - * We only try to call Python when we loaded the right module until - * that time we pretend the call succeeded. - */ - if (plugin_priv_ctx->python_loaded) { - retval = PyHandlePluginEvent(bareos_plugin_ctx, event, value); - } else { - retval = bRC_OK; - } - break; - } - - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - } - -bail_out: - return retval; -} - -/** - * Called when starting to backup a file. Here the plugin must - * return the "stat" packet for the directory/file and provide - * certain information so that Bareos knows what the file is. - * The plugin can create "Virtual" files by giving them a - * name that is not normally found on the file system. - */ -static bRC startBackupFile(PluginContext* bareos_plugin_ctx, - struct save_pkt* sp) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - - if (!plugin_priv_ctx) { goto bail_out; } - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyStartBackupFile(bareos_plugin_ctx, sp); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - - /* - * For Incremental and Differential backups use checkChanges method to - * see if we need to backup this file. - */ - switch (plugin_priv_ctx->backup_level) { - case L_INCREMENTAL: - case L_DIFFERENTIAL: - /* - * If the plugin didn't set a save_time but we have a since time - * from the bEventSince event we use that as basis for the actual - * save_time to check. - */ - if (sp->save_time == 0 && plugin_priv_ctx->since) { - sp->save_time = plugin_priv_ctx->since; - } - - switch (bareos_core_functions->checkChanges(bareos_plugin_ctx, sp)) { - case bRC_Seen: - switch (sp->type) { - case FT_DIRBEGIN: - sp->type = FT_DIRNOCHG; - break; - default: - sp->type = FT_NOCHG; - break; - } - break; - default: - break; - } - } - -bail_out: - return retval; -} - -/** - * Done backing up a file. - */ -static bRC endBackupFile(PluginContext* bareos_plugin_ctx) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - - if (!plugin_priv_ctx) { goto bail_out; } - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyEndBackupFile(bareos_plugin_ctx); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - -bail_out: - return retval; -} - -/** - * Do actual I/O. Bareos calls this after startBackupFile - * or after startRestoreFile to do the actual file - * input or output. - */ -static bRC pluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - - if (!plugin_priv_ctx) { goto bail_out; } - - if (!plugin_priv_ctx->python_loaded) { goto bail_out; } - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyPluginIO(bareos_plugin_ctx, io); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - -bail_out: - return retval; -} - -/** - * Start restore of a file. - */ -static bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - - if (!plugin_priv_ctx) { goto bail_out; } - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyStartRestoreFile(bareos_plugin_ctx, cmd); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - -bail_out: - return retval; -} - -/** - * Done restoring a file. - */ -static bRC endRestoreFile(PluginContext* bareos_plugin_ctx) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - - if (!plugin_priv_ctx) { goto bail_out; } - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyEndRestoreFile(bareos_plugin_ctx); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - -bail_out: - return retval; -} - -/** - * Called here to give the plugin the information needed to - * re-create the file on a restore. It basically gets the - * stat packet that was created during the backup phase. - * This data is what is needed to create the file, but does - * not contain actual file data. - */ -static bRC createFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - - if (!plugin_priv_ctx) { goto bail_out; } - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyCreateFile(bareos_plugin_ctx, rp); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - -bail_out: - return retval; -} - -/** - * Called after the file has been restored. This can be used to - * set directory permissions, ... - */ -static bRC setFileAttributes(PluginContext* bareos_plugin_ctx, - struct restore_pkt* rp) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - - if (!plugin_priv_ctx) { goto bail_out; } - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PySetFileAttributes(bareos_plugin_ctx, rp); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - -bail_out: - return retval; -} - -/** - * When using Incremental dump, all previous dumps are necessary - */ -static bRC checkFile(PluginContext* bareos_plugin_ctx, char* fname) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - - if (!plugin_priv_ctx) { goto bail_out; } - - if (!plugin_priv_ctx->python_loaded) { return bRC_OK; } - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyCheckFile(bareos_plugin_ctx, fname); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - -bail_out: - return retval; -} - -/** - */ -static bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - - if (!plugin_priv_ctx) { goto bail_out; } - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyGetAcl(bareos_plugin_ctx, ap); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - -bail_out: - return retval; -} - -/** - */ -static bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - - if (!plugin_priv_ctx) { goto bail_out; } - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PySetAcl(bareos_plugin_ctx, ap); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - -bail_out: - return retval; -} - -/** - */ -static bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - - if (!plugin_priv_ctx) { goto bail_out; } - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyGetXattr(bareos_plugin_ctx, xp); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - -bail_out: - return retval; -} - -/** - */ -static bRC setXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - - if (!plugin_priv_ctx) { goto bail_out; } - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PySetXattr(bareos_plugin_ctx, xp); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - -bail_out: - return retval; -} - -/** - * Only set destination to value when it has no previous setting. - */ -static inline void SetStringIfNull(char** destination, char* value) -{ - if (!*destination) { - *destination = strdup(value); - StripBackSlashes(*destination); - } -} - -/** - * Parse the plugin definition passed in. - * - * The definition is in this form: - * - * python:module_path=:module_name=:... - */ -static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, - void* value, - PoolMem& plugin_options) -{ - bool found; - int i, cnt; - bool keep_existing; - PoolMem plugin_definition(PM_FNAME); - char *bp, *argument, *argument_value; - plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - - if (!value) { return bRC_Error; } - - /* - * Skip this plugin when getting plugin definition "*all*" - * This allows to restore a Windows Backup on a Linux FD with - * Python Plugins enabled. - */ - if (bstrcmp((char*)value, "*all*")) { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Got plugin definition %s, skipping to ignore\n", - (char*)value); - return bRC_Skip; - } - - keep_existing = (plugin_priv_ctx->plugin_options) ? true : false; - - /* - * Parse the plugin definition. - * Make a private copy of the whole string. - */ - if (!plugin_priv_ctx->python_loaded && plugin_priv_ctx->plugin_options) { - int len; - - /* - * We got some option string which got pushed before we actual were able to - * send it to the python module as the entry point was not instantiated. So - * we prepend that now in the option string and append the new option string - * with the first argument being the pluginname removed as that is already - * part of the other plugin option string. - */ - len = strlen(plugin_priv_ctx->plugin_options); - PmStrcpy(plugin_definition, plugin_priv_ctx->plugin_options); - - bp = strchr((char*)value, ':'); - if (!bp) { - Jmsg(bareos_plugin_ctx, M_FATAL, - "python-fd: Illegal plugin definition %s\n", (char*)value); - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Illegal plugin definition %s\n", (char*)value); - goto bail_out; - } - - /* - * See if option string end with ':' - */ - if (plugin_priv_ctx->plugin_options[len - 1] != ':') { - PmStrcat(plugin_definition, (char*)bp); - } else { - PmStrcat(plugin_definition, (char*)bp + 1); - } - } else { - PmStrcpy(plugin_definition, (char*)value); - } - - bp = strchr(plugin_definition.c_str(), ':'); - if (!bp) { - Jmsg(bareos_plugin_ctx, M_FATAL, - "python-fd: Illegal plugin definition %s\n", - plugin_definition.c_str()); - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Illegal plugin definition %s\n", - plugin_definition.c_str()); - goto bail_out; - } - - /* - * Skip the first ':' - */ - bp++; - - cnt = 0; - while (bp) { - if (strlen(bp) == 0) { break; } - - /* - * Each argument is in the form: - * = - * - * So we setup the right pointers here, argument to the beginning - * of the argument, argument_value to the beginning of the argument_value. - */ - argument = bp; - argument_value = strchr(bp, '='); - if (!argument_value) { - Jmsg(bareos_plugin_ctx, M_FATAL, - "python-fd: Illegal argument %s without value\n", argument); - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Illegal argument %s without value\n", argument); - goto bail_out; - } - *argument_value++ = '\0'; - - /* - * See if there are more arguments and setup for the next run. - */ - bp = argument_value; - do { - bp = strchr(bp, ':'); - if (bp) { - if (*(bp - 1) != '\\') { - *bp++ = '\0'; - break; - } else { - bp++; - } - } - } while (bp); - - found = false; - for (i = 0; plugin_arguments[i].name; i++) { - if (Bstrcasecmp(argument, plugin_arguments[i].name)) { - char** str_destination = NULL; - bool* bool_destination = NULL; - - switch (plugin_arguments[i].type) { - case argument_module_path: - str_destination = &plugin_priv_ctx->module_path; - break; - case argument_module_name: - str_destination = &plugin_priv_ctx->module_name; - break; - default: - break; - } - - /* - * Keep the first value, ignore any next setting. - */ - if (str_destination) { - if (keep_existing) { - SetStringIfNull(str_destination, argument_value); - } else { - SetString(str_destination, argument_value); - } - } - - /* - * Set any boolean variable. - */ - if (bool_destination) { - *bool_destination = ParseBoolean(argument_value); - } - - /* - * When we have a match break the loop. - */ - found = true; - break; - } - } - - /* - * If we didn't consume this parameter we add it to the plugin_options list. - */ - if (!found) { - PoolMem option(PM_FNAME); - - if (cnt) { - Mmsg(option, ":%s=%s", argument, argument_value); - PmStrcat(plugin_options, option.c_str()); - } else { - Mmsg(option, "%s=%s", argument, argument_value); - PmStrcat(plugin_options, option.c_str()); - } - cnt++; - } - } - - if (cnt > 0) { PmStrcat(plugin_options, ":"); } - - return bRC_OK; - -bail_out: - return bRC_Error; -} - - -/** - * Initial load of the Python module. - * - * Based on the parsed plugin options we set some prerequisites like the - * module path and the module to load. We also load the dictionary used - * for looking up the Python methods. - */ -static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - PyObject *sysPath, *mPath, *pName, *pFunc; - - /* See if we already setup the python search path. */ - if (!plugin_priv_ctx->python_path_set) { - /* Extend the Python search path with the given module_path. */ - if (plugin_priv_ctx->module_path) { - sysPath = PySys_GetObject((char*)"path"); - mPath = PyString_FromString(plugin_priv_ctx->module_path); - PyList_Append(sysPath, mPath); - Py_DECREF(mPath); - plugin_priv_ctx->python_path_set = true; - } - } - - /* Try to load the Python module by name. */ - if (plugin_priv_ctx->module_name) { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Trying to load module with name %s\n", - plugin_priv_ctx->module_name); - pName = PyString_FromString(plugin_priv_ctx->module_name); - plugin_priv_ctx->pModule = PyImport_Import(pName); - Py_DECREF(pName); - - if (!plugin_priv_ctx->pModule) { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Failed to load module with name %s\n", - plugin_priv_ctx->module_name); - goto bail_out; - } - - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Successfully loaded module with name %s\n", - plugin_priv_ctx->module_name); - - /* Get the Python dictionary for lookups in the Python namespace. */ - plugin_priv_ctx->pyModuleFunctionsDict = - PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ - - /* Encode the PluginContext so a Python method can pass it in on - * calling back.*/ - /* plugin_priv_ctx->py_PluginContext = - * PyCreatePluginContext(bareos_plugin_ctx); */ - - StorePluginContextInPythonModule(bareos_plugin_ctx); - - /* Lookup the load_bareos_plugin() function in the python module. */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "load_bareos_plugin"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyObject *pPluginDefinition, *pRetVal; - - pPluginDefinition = PyString_FromString((char*)value); - if (!pPluginDefinition) { goto bail_out; } - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); - /* pFunc, plugin_priv_ctx->py_PluginContext, pPluginDefinition, - * NULL); */ - Py_DECREF(pPluginDefinition); - - if (!pRetVal) { - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - } - } else { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Failed to find function named load_bareos_plugins()\n"); - goto bail_out; - } - - /* - * Keep track we successfully loaded. - */ - plugin_priv_ctx->python_loaded = true; - } - - return retval; - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } - - return retval; -} - /** * Any plugin options which are passed in are dispatched here to a Python * method and it can parse the plugin options. This function is also called diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/bareosfd.h index 8e86bc1c656..0e7493ccf1c 100644 --- a/core/src/plugins/filed/python/bareosfd.h +++ b/core/src/plugins/filed/python/bareosfd.h @@ -760,38 +760,7 @@ static PyMethodDef Methods[] = { static bRC set_bareos_core_functions( BareosCoreFunctions* new_bareos_core_functions); -static bRC newPlugin(PluginContext* bareos_plugin_ctx); -static bRC freePlugin(PluginContext* bareos_plugin_ctx); -static bRC getPluginValue(PluginContext* bareos_plugin_ctx, - pVariable var, - void* value); -static bRC setPluginValue(PluginContext* bareos_plugin_ctx, - pVariable var, - void* value); -static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, - bEvent* event, - void* value); -static bRC startBackupFile(PluginContext* bareos_plugin_ctx, - struct save_pkt* sp); -static bRC endBackupFile(PluginContext* bareos_plugin_ctx); -static bRC pluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); -static bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); -static bRC endRestoreFile(PluginContext* bareos_plugin_ctx); -static bRC createFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); -static bRC setFileAttributes(PluginContext* bareos_plugin_ctx, - struct restore_pkt* rp); -static bRC checkFile(PluginContext* bareos_plugin_ctx, char* fname); -static bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC setXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, - void* value, - PoolMem& plugin_options); - - static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); -static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, void* value); static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, @@ -834,11 +803,6 @@ static void* bareos_core_functions = NULL; #ifdef __cplusplus extern "C" { #endif -/* Forward declaration of loadPlugin() as it is stored in Capsule */ -bRC loadPlugin(::Core_PluginApiDefinition* lbareos_plugin_interface_version, - BareosCoreFunctions* lbareos_core_functions, - PluginInformation** plugin_information, - pFuncs** plugin_functions); #ifdef __cplusplus } @@ -899,6 +863,7 @@ MOD_INIT(bareosfd) return MOD_ERROR_VAL; } +#if 0 /* add loadPlugin Capsule */ PyObject* PyModuleLoadPlugin = PyCapsule_New( (void*)&loadPlugin, PYTHON_MODULE_NAME_QUOTED ".loadPlugin", NULL); @@ -913,7 +878,7 @@ MOD_INIT(bareosfd) printf(PYTHON_MODULE_NAME_QUOTED "loadPlugin PyModule_AddObject failed\n"); return MOD_ERROR_VAL; } - +#endif PyRestoreObjectType.tp_new = PyType_GenericNew; if (PyType_Ready(&PyRestoreObjectType) < 0) { return MOD_ERROR_VAL; } diff --git a/core/src/plugins/filed/python/bareosfd_api_funcs.txt b/core/src/plugins/filed/python/bareosfd_api_funcs.txt index 865be37a422..f9b79fc0688 100644 --- a/core/src/plugins/filed/python/bareosfd_api_funcs.txt +++ b/core/src/plugins/filed/python/bareosfd_api_funcs.txt @@ -1,22 +1,3 @@ -bRC newPlugin(PluginContext* bareos_plugin_ctx); -bRC freePlugin(PluginContext* bareos_plugin_ctx); -bRC getPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); -bRC setPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); -bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, bEvent* event, void* value); -bRC startBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); -bRC endBackupFile(PluginContext* bareos_plugin_ctx); -bRC pluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); -bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); -bRC endRestoreFile(PluginContext* bareos_plugin_ctx); -bRC createFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); -bRC setFileAttributes(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); -bRC checkFile(PluginContext* bareos_plugin_ctx, char* fname); -bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -bRC setXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, void* value, PoolMem& plugin_options); -bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, void* value); bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); diff --git a/core/src/plugins/filed/python/capi_1.inc b/core/src/plugins/filed/python/capi_1.inc index 6923d41ccf6..2dce9fe71ca 100644 --- a/core/src/plugins/filed/python/capi_1.inc +++ b/core/src/plugins/filed/python/capi_1.inc @@ -1,194 +1,99 @@ /* C API functions */ -/* static bRC newPlugin(PluginContext* bareos_plugin_ctx); */ -#define Bareosfd_newPlugin_NUM 0 -#define Bareosfd_newPlugin_RETURN bRC -#define Bareosfd_newPlugin_PROTO (PluginContext* bareos_plugin_ctx) - -/* static bRC freePlugin(PluginContext* bareos_plugin_ctx); */ -#define Bareosfd_freePlugin_NUM 1 -#define Bareosfd_freePlugin_RETURN bRC -#define Bareosfd_freePlugin_PROTO (PluginContext* bareos_plugin_ctx) - -/* static bRC getPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); */ -#define Bareosfd_getPluginValue_NUM 2 -#define Bareosfd_getPluginValue_RETURN bRC -#define Bareosfd_getPluginValue_PROTO (PluginContext* bareos_plugin_ctx, pVariable var, void* value) - -/* static bRC setPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); */ -#define Bareosfd_setPluginValue_NUM 3 -#define Bareosfd_setPluginValue_RETURN bRC -#define Bareosfd_setPluginValue_PROTO (PluginContext* bareos_plugin_ctx, pVariable var, void* value) - -/* static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, bEvent* event, void* value); */ -#define Bareosfd_handlePluginEvent_NUM 4 -#define Bareosfd_handlePluginEvent_RETURN bRC -#define Bareosfd_handlePluginEvent_PROTO (PluginContext* bareos_plugin_ctx, bEvent* event, void* value) - -/* static bRC startBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); */ -#define Bareosfd_startBackupFile_NUM 5 -#define Bareosfd_startBackupFile_RETURN bRC -#define Bareosfd_startBackupFile_PROTO (PluginContext* bareos_plugin_ctx, struct save_pkt* sp) - -/* static bRC endBackupFile(PluginContext* bareos_plugin_ctx); */ -#define Bareosfd_endBackupFile_NUM 6 -#define Bareosfd_endBackupFile_RETURN bRC -#define Bareosfd_endBackupFile_PROTO (PluginContext* bareos_plugin_ctx) - -/* static bRC pluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); */ -#define Bareosfd_pluginIO_NUM 7 -#define Bareosfd_pluginIO_RETURN bRC -#define Bareosfd_pluginIO_PROTO (PluginContext* bareos_plugin_ctx, struct io_pkt* io) - -/* static bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); */ -#define Bareosfd_startRestoreFile_NUM 8 -#define Bareosfd_startRestoreFile_RETURN bRC -#define Bareosfd_startRestoreFile_PROTO (PluginContext* bareos_plugin_ctx, const char* cmd) - -/* static bRC endRestoreFile(PluginContext* bareos_plugin_ctx); */ -#define Bareosfd_endRestoreFile_NUM 9 -#define Bareosfd_endRestoreFile_RETURN bRC -#define Bareosfd_endRestoreFile_PROTO (PluginContext* bareos_plugin_ctx) - -/* static bRC createFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); */ -#define Bareosfd_createFile_NUM 10 -#define Bareosfd_createFile_RETURN bRC -#define Bareosfd_createFile_PROTO (PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) - -/* static bRC setFileAttributes(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); */ -#define Bareosfd_setFileAttributes_NUM 11 -#define Bareosfd_setFileAttributes_RETURN bRC -#define Bareosfd_setFileAttributes_PROTO (PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) - -/* static bRC checkFile(PluginContext* bareos_plugin_ctx, char* fname); */ -#define Bareosfd_checkFile_NUM 12 -#define Bareosfd_checkFile_RETURN bRC -#define Bareosfd_checkFile_PROTO (PluginContext* bareos_plugin_ctx, char* fname) - -/* static bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); */ -#define Bareosfd_getAcl_NUM 13 -#define Bareosfd_getAcl_RETURN bRC -#define Bareosfd_getAcl_PROTO (PluginContext* bareos_plugin_ctx, acl_pkt* ap) - -/* static bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); */ -#define Bareosfd_setAcl_NUM 14 -#define Bareosfd_setAcl_RETURN bRC -#define Bareosfd_setAcl_PROTO (PluginContext* bareos_plugin_ctx, acl_pkt* ap) - -/* static bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); */ -#define Bareosfd_getXattr_NUM 15 -#define Bareosfd_getXattr_RETURN bRC -#define Bareosfd_getXattr_PROTO (PluginContext* bareos_plugin_ctx, xattr_pkt* xp) - -/* static bRC setXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); */ -#define Bareosfd_setXattr_NUM 16 -#define Bareosfd_setXattr_RETURN bRC -#define Bareosfd_setXattr_PROTO (PluginContext* bareos_plugin_ctx, xattr_pkt* xp) - -/* static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, void* value, PoolMem& plugin_options); */ -#define Bareosfd_parse_plugin_definition_NUM 17 -#define Bareosfd_parse_plugin_definition_RETURN bRC -#define Bareosfd_parse_plugin_definition_PROTO (PluginContext* bareos_plugin_ctx, void* value, PoolMem& plugin_options) - -/* static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); */ -#define Bareosfd_PyLoadModule_NUM 18 -#define Bareosfd_PyLoadModule_RETURN bRC -#define Bareosfd_PyLoadModule_PROTO (PluginContext* bareos_plugin_ctx, void* value) - /* static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, void* value); */ -#define Bareosfd_PyParsePluginDefinition_NUM 19 +#define Bareosfd_PyParsePluginDefinition_NUM 0 #define Bareosfd_PyParsePluginDefinition_RETURN bRC #define Bareosfd_PyParsePluginDefinition_PROTO (PluginContext* bareos_plugin_ctx, void* value) /* static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); */ -#define Bareosfd_PyGetPluginValue_NUM 20 +#define Bareosfd_PyGetPluginValue_NUM 1 #define Bareosfd_PyGetPluginValue_RETURN bRC #define Bareosfd_PyGetPluginValue_PROTO (PluginContext* bareos_plugin_ctx, pVariable var, void* value) /* static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); */ -#define Bareosfd_PySetPluginValue_NUM 21 +#define Bareosfd_PySetPluginValue_NUM 2 #define Bareosfd_PySetPluginValue_RETURN bRC #define Bareosfd_PySetPluginValue_PROTO (PluginContext* bareos_plugin_ctx, pVariable var, void* value) /* static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, bEvent* event, void* value); */ -#define Bareosfd_PyHandlePluginEvent_NUM 22 +#define Bareosfd_PyHandlePluginEvent_NUM 3 #define Bareosfd_PyHandlePluginEvent_RETURN bRC #define Bareosfd_PyHandlePluginEvent_PROTO (PluginContext* bareos_plugin_ctx, bEvent* event, void* value) /* static bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); */ -#define Bareosfd_PyStartBackupFile_NUM 23 +#define Bareosfd_PyStartBackupFile_NUM 4 #define Bareosfd_PyStartBackupFile_RETURN bRC #define Bareosfd_PyStartBackupFile_PROTO (PluginContext* bareos_plugin_ctx, struct save_pkt* sp) /* static bRC PyEndBackupFile(PluginContext* bareos_plugin_ctx); */ -#define Bareosfd_PyEndBackupFile_NUM 24 +#define Bareosfd_PyEndBackupFile_NUM 5 #define Bareosfd_PyEndBackupFile_RETURN bRC #define Bareosfd_PyEndBackupFile_PROTO (PluginContext* bareos_plugin_ctx) /* static bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); */ -#define Bareosfd_PyPluginIO_NUM 25 +#define Bareosfd_PyPluginIO_NUM 6 #define Bareosfd_PyPluginIO_RETURN bRC #define Bareosfd_PyPluginIO_PROTO (PluginContext* bareos_plugin_ctx, struct io_pkt* io) /* static bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); */ -#define Bareosfd_PyStartRestoreFile_NUM 26 +#define Bareosfd_PyStartRestoreFile_NUM 7 #define Bareosfd_PyStartRestoreFile_RETURN bRC #define Bareosfd_PyStartRestoreFile_PROTO (PluginContext* bareos_plugin_ctx, const char* cmd) /* static bRC PyEndRestoreFile(PluginContext* bareos_plugin_ctx); */ -#define Bareosfd_PyEndRestoreFile_NUM 27 +#define Bareosfd_PyEndRestoreFile_NUM 8 #define Bareosfd_PyEndRestoreFile_RETURN bRC #define Bareosfd_PyEndRestoreFile_PROTO (PluginContext* bareos_plugin_ctx) /* static bRC PyCreateFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); */ -#define Bareosfd_PyCreateFile_NUM 28 +#define Bareosfd_PyCreateFile_NUM 9 #define Bareosfd_PyCreateFile_RETURN bRC #define Bareosfd_PyCreateFile_PROTO (PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) /* static bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); */ -#define Bareosfd_PySetFileAttributes_NUM 29 +#define Bareosfd_PySetFileAttributes_NUM 10 #define Bareosfd_PySetFileAttributes_RETURN bRC #define Bareosfd_PySetFileAttributes_PROTO (PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) /* static bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname); */ -#define Bareosfd_PyCheckFile_NUM 30 +#define Bareosfd_PyCheckFile_NUM 11 #define Bareosfd_PyCheckFile_RETURN bRC #define Bareosfd_PyCheckFile_PROTO (PluginContext* bareos_plugin_ctx, char* fname) /* static bRC PyGetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); */ -#define Bareosfd_PyGetAcl_NUM 31 +#define Bareosfd_PyGetAcl_NUM 12 #define Bareosfd_PyGetAcl_RETURN bRC #define Bareosfd_PyGetAcl_PROTO (PluginContext* bareos_plugin_ctx, acl_pkt* ap) /* static bRC PySetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); */ -#define Bareosfd_PySetAcl_NUM 32 +#define Bareosfd_PySetAcl_NUM 13 #define Bareosfd_PySetAcl_RETURN bRC #define Bareosfd_PySetAcl_PROTO (PluginContext* bareos_plugin_ctx, acl_pkt* ap) /* static bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); */ -#define Bareosfd_PyGetXattr_NUM 33 +#define Bareosfd_PyGetXattr_NUM 14 #define Bareosfd_PyGetXattr_RETURN bRC #define Bareosfd_PyGetXattr_PROTO (PluginContext* bareos_plugin_ctx, xattr_pkt* xp) /* static bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); */ -#define Bareosfd_PySetXattr_NUM 34 +#define Bareosfd_PySetXattr_NUM 15 #define Bareosfd_PySetXattr_RETURN bRC #define Bareosfd_PySetXattr_PROTO (PluginContext* bareos_plugin_ctx, xattr_pkt* xp) /* static bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, struct restore_object_pkt* rop); */ -#define Bareosfd_PyRestoreObjectData_NUM 35 +#define Bareosfd_PyRestoreObjectData_NUM 16 #define Bareosfd_PyRestoreObjectData_RETURN bRC #define Bareosfd_PyRestoreObjectData_PROTO (PluginContext* bareos_plugin_ctx, struct restore_object_pkt* rop) /* static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); */ -#define Bareosfd_PyHandleBackupFile_NUM 36 +#define Bareosfd_PyHandleBackupFile_NUM 17 #define Bareosfd_PyHandleBackupFile_RETURN bRC #define Bareosfd_PyHandleBackupFile_PROTO (PluginContext* bareos_plugin_ctx, struct save_pkt* sp) /* static bRC set_bareos_core_functions(BareosCoreFunctions* new_bareos_core_functions); */ -#define Bareosfd_set_bareos_core_functions_NUM 37 +#define Bareosfd_set_bareos_core_functions_NUM 18 #define Bareosfd_set_bareos_core_functions_RETURN bRC #define Bareosfd_set_bareos_core_functions_PROTO (BareosCoreFunctions* new_bareos_core_functions ) /*Total Number of C API function pointers */ -#define Bareosfd_API_pointers 38 +#define Bareosfd_API_pointers 19 diff --git a/core/src/plugins/filed/python/capi_2.inc b/core/src/plugins/filed/python/capi_2.inc index 45dbc584e62..5cffa65680a 100644 --- a/core/src/plugins/filed/python/capi_2.inc +++ b/core/src/plugins/filed/python/capi_2.inc @@ -1,41 +1,3 @@ -#define Bareosfd_newPlugin (*(Bareosfd_newPlugin_RETURN(*)Bareosfd_newPlugin_PROTO) Bareosfd_API[Bareosfd_newPlugin_NUM]) - -#define Bareosfd_freePlugin (*(Bareosfd_freePlugin_RETURN(*)Bareosfd_freePlugin_PROTO) Bareosfd_API[Bareosfd_freePlugin_NUM]) - -#define Bareosfd_getPluginValue (*(Bareosfd_getPluginValue_RETURN(*)Bareosfd_getPluginValue_PROTO) Bareosfd_API[Bareosfd_getPluginValue_NUM]) - -#define Bareosfd_setPluginValue (*(Bareosfd_setPluginValue_RETURN(*)Bareosfd_setPluginValue_PROTO) Bareosfd_API[Bareosfd_setPluginValue_NUM]) - -#define Bareosfd_handlePluginEvent (*(Bareosfd_handlePluginEvent_RETURN(*)Bareosfd_handlePluginEvent_PROTO) Bareosfd_API[Bareosfd_handlePluginEvent_NUM]) - -#define Bareosfd_startBackupFile (*(Bareosfd_startBackupFile_RETURN(*)Bareosfd_startBackupFile_PROTO) Bareosfd_API[Bareosfd_startBackupFile_NUM]) - -#define Bareosfd_endBackupFile (*(Bareosfd_endBackupFile_RETURN(*)Bareosfd_endBackupFile_PROTO) Bareosfd_API[Bareosfd_endBackupFile_NUM]) - -#define Bareosfd_pluginIO (*(Bareosfd_pluginIO_RETURN(*)Bareosfd_pluginIO_PROTO) Bareosfd_API[Bareosfd_pluginIO_NUM]) - -#define Bareosfd_startRestoreFile (*(Bareosfd_startRestoreFile_RETURN(*)Bareosfd_startRestoreFile_PROTO) Bareosfd_API[Bareosfd_startRestoreFile_NUM]) - -#define Bareosfd_endRestoreFile (*(Bareosfd_endRestoreFile_RETURN(*)Bareosfd_endRestoreFile_PROTO) Bareosfd_API[Bareosfd_endRestoreFile_NUM]) - -#define Bareosfd_createFile (*(Bareosfd_createFile_RETURN(*)Bareosfd_createFile_PROTO) Bareosfd_API[Bareosfd_createFile_NUM]) - -#define Bareosfd_setFileAttributes (*(Bareosfd_setFileAttributes_RETURN(*)Bareosfd_setFileAttributes_PROTO) Bareosfd_API[Bareosfd_setFileAttributes_NUM]) - -#define Bareosfd_checkFile (*(Bareosfd_checkFile_RETURN(*)Bareosfd_checkFile_PROTO) Bareosfd_API[Bareosfd_checkFile_NUM]) - -#define Bareosfd_getAcl (*(Bareosfd_getAcl_RETURN(*)Bareosfd_getAcl_PROTO) Bareosfd_API[Bareosfd_getAcl_NUM]) - -#define Bareosfd_setAcl (*(Bareosfd_setAcl_RETURN(*)Bareosfd_setAcl_PROTO) Bareosfd_API[Bareosfd_setAcl_NUM]) - -#define Bareosfd_getXattr (*(Bareosfd_getXattr_RETURN(*)Bareosfd_getXattr_PROTO) Bareosfd_API[Bareosfd_getXattr_NUM]) - -#define Bareosfd_setXattr (*(Bareosfd_setXattr_RETURN(*)Bareosfd_setXattr_PROTO) Bareosfd_API[Bareosfd_setXattr_NUM]) - -#define Bareosfd_parse_plugin_definition (*(Bareosfd_parse_plugin_definition_RETURN(*)Bareosfd_parse_plugin_definition_PROTO) Bareosfd_API[Bareosfd_parse_plugin_definition_NUM]) - -#define Bareosfd_PyLoadModule (*(Bareosfd_PyLoadModule_RETURN(*)Bareosfd_PyLoadModule_PROTO) Bareosfd_API[Bareosfd_PyLoadModule_NUM]) - #define Bareosfd_PyParsePluginDefinition (*(Bareosfd_PyParsePluginDefinition_RETURN(*)Bareosfd_PyParsePluginDefinition_PROTO) Bareosfd_API[Bareosfd_PyParsePluginDefinition_NUM]) #define Bareosfd_PyGetPluginValue (*(Bareosfd_PyGetPluginValue_RETURN(*)Bareosfd_PyGetPluginValue_PROTO) Bareosfd_API[Bareosfd_PyGetPluginValue_NUM]) diff --git a/core/src/plugins/filed/python/capi_3.inc b/core/src/plugins/filed/python/capi_3.inc index 15f72de97ce..aea83ca87de 100644 --- a/core/src/plugins/filed/python/capi_3.inc +++ b/core/src/plugins/filed/python/capi_3.inc @@ -1,22 +1,3 @@ - Bareosfd_API[Bareosfd_newPlugin_NUM] = (void*)newPlugin; - Bareosfd_API[Bareosfd_freePlugin_NUM] = (void*)freePlugin; - Bareosfd_API[Bareosfd_getPluginValue_NUM] = (void*)getPluginValue; - Bareosfd_API[Bareosfd_setPluginValue_NUM] = (void*)setPluginValue; - Bareosfd_API[Bareosfd_handlePluginEvent_NUM] = (void*)handlePluginEvent; - Bareosfd_API[Bareosfd_startBackupFile_NUM] = (void*)startBackupFile; - Bareosfd_API[Bareosfd_endBackupFile_NUM] = (void*)endBackupFile; - Bareosfd_API[Bareosfd_pluginIO_NUM] = (void*)pluginIO; - Bareosfd_API[Bareosfd_startRestoreFile_NUM] = (void*)startRestoreFile; - Bareosfd_API[Bareosfd_endRestoreFile_NUM] = (void*)endRestoreFile; - Bareosfd_API[Bareosfd_createFile_NUM] = (void*)createFile; - Bareosfd_API[Bareosfd_setFileAttributes_NUM] = (void*)setFileAttributes; - Bareosfd_API[Bareosfd_checkFile_NUM] = (void*)checkFile; - Bareosfd_API[Bareosfd_getAcl_NUM] = (void*)getAcl; - Bareosfd_API[Bareosfd_setAcl_NUM] = (void*)setAcl; - Bareosfd_API[Bareosfd_getXattr_NUM] = (void*)getXattr; - Bareosfd_API[Bareosfd_setXattr_NUM] = (void*)setXattr; - Bareosfd_API[Bareosfd_parse_plugin_definition_NUM] = (void*)parse_plugin_definition; - Bareosfd_API[Bareosfd_PyLoadModule_NUM] = (void*)PyLoadModule; Bareosfd_API[Bareosfd_PyParsePluginDefinition_NUM] = (void*)PyParsePluginDefinition; Bareosfd_API[Bareosfd_PyGetPluginValue_NUM] = (void*)PyGetPluginValue; Bareosfd_API[Bareosfd_PySetPluginValue_NUM] = (void*)PySetPluginValue; diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 8f883a604ee..732c2508810 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -39,11 +39,6 @@ #include "filed/fd_plugins.h" - -#if (PY_VERSION_HEX < 0x02060000) -#error "Need at least Python version 2.6 or newer" -#endif - #include "python-fd.h" #include "bareosfd.h" #include "lib/edit.h" diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index e3166620e00..ed3d7ce073b 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -68,7 +68,7 @@ static void PyErrorHandler() exit(1); } -// using namespace filedaemon; +using namespace filedaemon; bRC bareosRegisterEvents(PluginContext* ctx, int nr_events, ...) { return bRC_OK; @@ -201,6 +201,9 @@ int main(int argc, char* argv[]) import_bareosfd(); + Bareosfd_set_bareos_core_functions(&bareos_core_functions); + + // bRC retval = Bareosfd_PyLoadModule((PluginContext*)nullptr, nullptr); /* printf("bareos_core_functions is at %p\n", @@ -220,7 +223,7 @@ int main(int argc, char* argv[]) if (!bareos_core_functions_from_bareosfd_module) { printf("importing bareosfd.BareosCoreFunctions failed \n"); } - +#if 0 // Extract capsules pointer from bareosfd module void (*loadplugin_from_bareosfd_module)( filedaemon::Core_PluginApiDefinition * lbareos_plugin_interface_version, @@ -235,7 +238,7 @@ int main(int argc, char* argv[]) if (!loadplugin_from_bareosfd_module) { printf("importing bareosfd.loadPlugin failed \n"); } - +#endif /* printf("ctx_from_bareosfd_module is at %p\n", * ctx_from_bareosfd_module); */ /* printf("bareos_core_functions_from_bareosfd_module is at %p\n", */ @@ -256,9 +259,11 @@ int main(int argc, char* argv[]) PluginInformation plugin_information; filedaemon::pFuncs plugin_functions; - loadplugin_from_bareosfd_module(&myInfo, &bareos_core_functions, - (PluginInformation**)&plugin_information, - (filedaemon::pFuncs**)&plugin_functions); + /* loadplugin_from_bareosfd_module(&myInfo, &bareos_core_functions, */ + /* (PluginInformation**)&plugin_information, + */ + /* (filedaemon::pFuncs**)&plugin_functions); + */ printf("ctx_from_bareosfd_module contains %p\n", diff --git a/core/src/plugins/python_plugins_common.inc b/core/src/plugins/python_plugins_common.inc index a8beb19d146..4a3baa874a4 100644 --- a/core/src/plugins/python_plugins_common.inc +++ b/core/src/plugins/python_plugins_common.inc @@ -19,6 +19,7 @@ 02110-1301, USA. */ +#ifndef NOPLUGINSETGETVALUE /* Common functions used in all python plugins. */ static bRC getPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, @@ -54,6 +55,7 @@ static bRC setPluginValue(PluginContext* bareos_plugin_ctx, return retval; } +#endif /** From c6ad5c7c10916c879320617362705e4fa66af6b9 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 7 May 2020 16:21:20 +0200 Subject: [PATCH 080/341] python-fd.cc: created plugin_private_context.h --- core/src/plugins/filed/python/bareosfd.cc | 23 +-------- .../filed/python/plugin_private_context.h | 26 ++++++++++ core/src/plugins/filed/python/python-fd.cc | 20 +------- .../python/test/python-fd-module-tester.cc | 49 ------------------- 4 files changed, 28 insertions(+), 90 deletions(-) create mode 100644 core/src/plugins/filed/python/plugin_private_context.h diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 49ba74d60d2..39b6ecc5e5b 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -88,28 +88,7 @@ static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, static BareosCoreFunctions* bareos_core_functions = NULL; static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; - -// TODO: put this in its own header file -struct plugin_private_context { - int32_t backup_level; /* Backup level e.g. Full/Differential/Incremental */ - utime_t since; /* Since time for Differential/Incremental */ - bool python_loaded; /* Plugin has python module loaded ? */ - bool python_path_set; /* Python plugin search path is set ? */ - char* plugin_options; /* Plugin Option string */ - char* module_path; /* Plugin Module Path */ - char* module_name; /* Plugin Module Name */ - char* fname; /* Next filename to save */ - char* link; /* Target symlink points to */ - char* object_name; /* Restore Object Name */ - char* object; /* Restore Object Content */ - PyThreadState* - interpreter; /* Python interpreter for this instance of the plugin */ - PyObject* pModule; /* Python Module entry point */ - PyObject* pyModuleFunctionsDict; /* Python Dictionary */ - BareosCoreFunctions* - bareos_core_functions; /* pointer to bareos_core_functions */ -}; // namespace filedaemon - +#include "plugin_private_context.h" #define NOPLUGINSETGETVALUE 1 /* functions common to all plugins */ diff --git a/core/src/plugins/filed/python/plugin_private_context.h b/core/src/plugins/filed/python/plugin_private_context.h new file mode 100644 index 00000000000..0d3f65fa34b --- /dev/null +++ b/core/src/plugins/filed/python/plugin_private_context.h @@ -0,0 +1,26 @@ + +#ifndef BAREOS_CORE_SRC_PLUGINS_FILED_PYTHON_PLUGIN_PRIVATE_CONTEXT_H_ +#define BAREOS_CORE_SRC_PLUGINS_FILED_PYTHON_PLUGIN_PRIVATE_CONTEXT_H_ + +struct plugin_private_context { + int32_t backup_level; /* Backup level e.g. Full/Differential/Incremental */ + utime_t since; /* Since time for Differential/Incremental */ + bool python_loaded; /* Plugin has python module loaded ? */ + bool python_path_set; /* Python plugin search path is set ? */ + char* plugin_options; /* Plugin Option string */ + char* module_path; /* Plugin Module Path */ + char* module_name; /* Plugin Module Name */ + char* fname; /* Next filename to save */ + char* link; /* Target symlink points to */ + char* object_name; /* Restore Object Name */ + char* object; /* Restore Object Content */ + PyThreadState* + interpreter; /* Python interpreter for this instance of the plugin */ + PyObject* pModule; /* Python Module entry point */ + PyObject* pyModuleFunctionsDict; /* Python Dictionary */ + BareosCoreFunctions* + bareos_core_functions; /* pointer to bareos_core_functions */ +}; // namespace filedaemon + + +#endif // BAREOS_CORE_SRC_PLUGINS_FILED_PYTHON_PLUGIN_PRIVATE_CONTEXT_H_ diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 732c2508810..afc7077e209 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -117,25 +117,7 @@ static pFuncs pluginFuncs = { endBackupFile, startRestoreFile, endRestoreFile, pluginIO, createFile, setFileAttributes, checkFile, getAcl, setAcl, getXattr, setXattr}; -struct plugin_private_context { - int32_t backup_level; /* Backup level e.g. Full/Differential/Incremental */ - utime_t since; /* Since time for Differential/Incremental */ - bool python_loaded; /* Plugin has python module loaded ? */ - bool python_path_set; /* Python plugin search path is set ? */ - char* plugin_options; /* Plugin Option string */ - char* module_path; /* Plugin Module Path */ - char* module_name; /* Plugin Module Name */ - char* fname; /* Next filename to save */ - char* link; /* Target symlink points to */ - char* object_name; /* Restore Object Name */ - char* object; /* Restore Object Content */ - PyThreadState* - interpreter; /* Python interpreter for this instance of the plugin */ - PyObject* pModule; /* Python Module entry point */ - PyObject* pyModuleFunctionsDict; /* Python Dictionary */ - BareosCoreFunctions* - bareos_core_functions; /* pointer to bareos_core_functions */ -}; +#include "plugin_private_context.h" /** * We don't actually use this but we need it to tear down the diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index ed3d7ce073b..4cf4ae30ceb 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -190,26 +190,10 @@ int main(int argc, char* argv[]) } if (PyErr_Occurred()) { PyErrorHandler(); } - - /* static void** Bareosfd_API = (void**)PyCapsule_Import("bareosfd._C_API", - * 0); */ - /* if (!Bareosfd_API) { */ - /* printf("importing bareosfd._C_API failed \n"); */ - /* } else { */ - /* printf("importing bareosfd._C_API successful \n"); */ - /* } */ - - import_bareosfd(); Bareosfd_set_bareos_core_functions(&bareos_core_functions); - // bRC retval = Bareosfd_PyLoadModule((PluginContext*)nullptr, nullptr); - - /* printf("bareos_core_functions is at %p\n", - * &bareos_core_functions); */ - /* printf("bareos_PluginContext %p\n", &bareos_PluginContext); */ - // Extract capsules pointer from bareosfd module void* ctx_from_bareosfd_module = PyCapsule_Import("bareosfd.PluginContext", 0); @@ -223,33 +207,6 @@ int main(int argc, char* argv[]) if (!bareos_core_functions_from_bareosfd_module) { printf("importing bareosfd.BareosCoreFunctions failed \n"); } -#if 0 - // Extract capsules pointer from bareosfd module - void (*loadplugin_from_bareosfd_module)( - filedaemon::Core_PluginApiDefinition * lbareos_plugin_interface_version, - filedaemon::BareosCoreFunctions * lbareos_core_functions, - PluginInformation * *plugin_information, - filedaemon::pFuncs * *plugin_functions) = - (void (*)(filedaemon::Core_PluginApiDefinition*, - filedaemon::BareosCoreFunctions*, PluginInformation**, - filedaemon::pFuncs**))PyCapsule_Import("bareosfd.loadPlugin", - 0); - - if (!loadplugin_from_bareosfd_module) { - printf("importing bareosfd.loadPlugin failed \n"); - } -#endif - /* printf("ctx_from_bareosfd_module is at %p\n", - * ctx_from_bareosfd_module); */ - /* printf("bareos_core_functions_from_bareosfd_module is at %p\n", */ - /* bareos_core_functions_from_bareosfd_module); */ - /* printf("loadplugin_from_bareosfd_module is @ %p\n", */ - /* loadplugin_from_bareosfd_module); */ - - /* printf("ctx_from_bareosfd_module contains %p\n", */ - /* *(void**)ctx_from_bareosfd_module); */ - /* printf("bareos_core_functions_from_bareosfd_module contains %p\n", */ - /* *(void**)bareos_core_functions_from_bareosfd_module); */ *(void**)ctx_from_bareosfd_module = &bareos_PluginContext; *(void**)bareos_core_functions_from_bareosfd_module = &bareos_core_functions; @@ -259,12 +216,6 @@ int main(int argc, char* argv[]) PluginInformation plugin_information; filedaemon::pFuncs plugin_functions; - /* loadplugin_from_bareosfd_module(&myInfo, &bareos_core_functions, */ - /* (PluginInformation**)&plugin_information, - */ - /* (filedaemon::pFuncs**)&plugin_functions); - */ - printf("ctx_from_bareosfd_module contains %p\n", *(void**)ctx_from_bareosfd_module); From 0d85a92cd8975cf39c850163c0d3aa7914f2dac0 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 8 May 2020 12:00:39 +0200 Subject: [PATCH 081/341] python-fd.cc: fixup for plugin_private_context.h --- core/src/plugins/filed/python/python-fd.cc | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index afc7077e209..3b55410909e 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -182,12 +182,6 @@ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, pFuncs** plugin_functions) { if (!Py_IsInitialized()) { - /* Setup Python */ -#if PY_MAJOR_VERSION >= 3 - /* PyImport_AppendInittab("bareosfd", &PyInit_bareosfd); */ -#else - /* PyImport_AppendInittab("bareosfd", initbareosfd); */ -#endif Py_InitializeEx(0); /* import the bareosfd module */ @@ -205,6 +199,7 @@ bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, * module */ import_bareosfd(); + /* set bareos_core_functions inside of barosfd module */ Bareosfd_set_bareos_core_functions(lbareos_core_functions); bareos_core_functions = @@ -342,9 +337,7 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, plugin_priv_ctx->since = (int64_t)value; break; case bEventBackupCommand: - /* - * Fall-through wanted - */ + /* Fall-through wanted */ case bEventRestoreCommand: /* Fall-through wanted */ case bEventEstimateCommand: From 11c6d0a0a6160bb85b2fd8ebbb96391e56e4bff5 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 8 May 2020 12:32:17 +0200 Subject: [PATCH 082/341] python-fd.{cc,h}: removed unneeded code from --- core/src/plugins/filed/python/bareosfd.cc | 17 +- core/src/plugins/filed/python/python-fd.cc | 1564 +------------------- core/src/plugins/filed/python/python-fd.h | 969 ------------ core/src/plugins/python_plugins_common.inc | 1 - 4 files changed, 3 insertions(+), 2548 deletions(-) diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 39b6ecc5e5b..d09d9244ca7 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -1,8 +1,7 @@ /* BAREOS® - Backup Archiving REcovery Open Sourced - Copyright (C) 2011-2015 Planets Communications B.V. - Copyright (C) 2013-2020 Bareos GmbH & Co. KG + Copyright (C) 2020-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -19,12 +18,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/* - * Marco van Wieringen, August 2012 - */ /** * @file - * Python plugin for the Bareos File Daemon + * Python module for the bareos filedaemon plugin */ #define PY_SSIZE_T_CLEAN #define BUILD_PLUGIN @@ -94,10 +90,6 @@ static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; /* functions common to all plugins */ #include "plugins/python_plugins_common.inc" -#ifdef __cplusplus -// extern "C" { -#endif - static void PyErrorHandler() { PyObject *type, *value, *traceback; @@ -137,11 +129,6 @@ static void PyErrorHandler() exit(1); } - -#ifdef __cplusplus -//} -#endif - /* set the bareos_core_functions pointer to the given value */ static bRC set_bareos_core_functions( BareosCoreFunctions* new_bareos_core_functions) diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 3b55410909e..24ffd699c39 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -88,7 +88,6 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); - static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, pVariable var, void* value); @@ -117,6 +116,7 @@ static pFuncs pluginFuncs = { endBackupFile, startRestoreFile, endRestoreFile, pluginIO, createFile, setFileAttributes, checkFile, getAcl, setAcl, getXattr, setXattr}; + #include "plugin_private_context.h" /** @@ -1061,1566 +1061,4 @@ static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, return bRC_OK; } -static inline PyStatPacket* NativeToPyStatPacket(struct stat* statp) -{ - PyStatPacket* pStatp = PyObject_New(PyStatPacket, &PyStatPacketType); - - if (pStatp) { - pStatp->dev = statp->st_dev; - pStatp->ino = statp->st_ino; - pStatp->mode = statp->st_mode; - pStatp->nlink = statp->st_nlink; - pStatp->uid = statp->st_uid; - pStatp->gid = statp->st_gid; - pStatp->rdev = statp->st_rdev; - pStatp->size = statp->st_size; - pStatp->atime = statp->st_atime; - pStatp->mtime = statp->st_mtime; - pStatp->ctime = statp->st_ctime; - pStatp->blksize = statp->st_blksize; - pStatp->blocks = statp->st_blocks; - } - - return pStatp; -} - -static inline void PyStatPacketToNative(PyStatPacket* pStatp, - struct stat* statp) -{ - statp->st_dev = pStatp->dev; - statp->st_ino = pStatp->ino; - statp->st_mode = pStatp->mode; - statp->st_nlink = pStatp->nlink; - statp->st_uid = pStatp->uid; - statp->st_gid = pStatp->gid; - statp->st_rdev = pStatp->rdev; - statp->st_size = pStatp->size; - statp->st_atime = pStatp->atime; - statp->st_mtime = pStatp->mtime; - statp->st_ctime = pStatp->ctime; - statp->st_blksize = pStatp->blksize; - statp->st_blocks = pStatp->blocks; -} - -static inline PySavePacket* NativeToPySavePacket(struct save_pkt* sp) -{ - PySavePacket* pSavePkt = PyObject_New(PySavePacket, &PySavePacketType); - - if (pSavePkt) { - /* - * Initialize the Python SavePkt with the data we got passed in. - */ - if (sp->fname) { - pSavePkt->fname = PyString_FromString(sp->fname); - } else { - pSavePkt->fname = NULL; - } - - if (sp->link) { - pSavePkt->link = PyString_FromString(sp->link); - } else { - pSavePkt->link = NULL; - } - - if (sp->statp.st_mode) { - pSavePkt->statp = (PyObject*)NativeToPyStatPacket(&sp->statp); - } else { - pSavePkt->statp = NULL; - } - - pSavePkt->type = sp->type; - pSavePkt->flags = - PyByteArray_FromStringAndSize(sp->flags, sizeof(sp->flags)); - pSavePkt->no_read = sp->no_read; - pSavePkt->portable = sp->portable; - pSavePkt->accurate_found = sp->accurate_found; - pSavePkt->cmd = sp->cmd; - pSavePkt->save_time = sp->save_time; - pSavePkt->delta_seq = sp->delta_seq; - pSavePkt->object_name = NULL; - pSavePkt->object = NULL; - pSavePkt->object_len = sp->object_len; - pSavePkt->object_index = sp->index; - } - - return pSavePkt; -} - -static inline bool PySavePacketToNative( - PySavePacket* pSavePkt, - struct save_pkt* sp, - struct plugin_private_context* plugin_priv_ctx, - bool is_options_plugin) -{ - /* - * See if this is for an Options Plugin. - */ - if (!is_options_plugin) { - /* - * Only copy back the arguments that are allowed to change. - */ - if (pSavePkt->fname) { - /* - * As this has to linger as long as the backup is running we save it in - * our plugin context. - */ - if (PyString_Check(pSavePkt->fname)) { - if (plugin_priv_ctx->fname) { free(plugin_priv_ctx->fname); } - plugin_priv_ctx->fname = strdup(PyString_AsString(pSavePkt->fname)); - sp->fname = plugin_priv_ctx->fname; - } - } else { - goto bail_out; - } - - /* - * Optional field. - */ - if (pSavePkt->link) { - /* - * As this has to linger as long as the backup is running we save it in - * our plugin context. - */ - if (PyString_Check(pSavePkt->link)) { - if (plugin_priv_ctx->link) { free(plugin_priv_ctx->link); } - plugin_priv_ctx->link = strdup(PyString_AsString(pSavePkt->link)); - sp->link = plugin_priv_ctx->link; - } - } - - /* - * Handle the stat structure. - */ - if (pSavePkt->statp) { - PyStatPacketToNative((PyStatPacket*)pSavePkt->statp, &sp->statp); - } else { - goto bail_out; - } - - sp->type = pSavePkt->type; - - if (PyByteArray_Check(pSavePkt->flags)) { - char* flags; - - if (PyByteArray_Size(pSavePkt->flags) != sizeof(sp->flags)) { - goto bail_out; - } - - if ((flags = PyByteArray_AsString(pSavePkt->flags))) { - memcpy(sp->flags, flags, sizeof(sp->flags)); - } else { - goto bail_out; - } - } else { - goto bail_out; - } - - /* - * Special code for handling restore objects. - */ - if (IS_FT_OBJECT(sp->type)) { - /* - * See if a proper restore object was created. - */ - if (pSavePkt->object_len > 0) { - /* - * As this has to linger as long as the backup is running we save it in - * our plugin context. - */ - if (pSavePkt->object_name && pSavePkt->object && - PyString_Check(pSavePkt->object_name) && - PyByteArray_Check(pSavePkt->object)) { - char* buf; - - if (plugin_priv_ctx->object_name) { - free(plugin_priv_ctx->object_name); - } - plugin_priv_ctx->object_name = - strdup(PyString_AsString(pSavePkt->object_name)); - sp->object_name = plugin_priv_ctx->object_name; - - sp->object_len = pSavePkt->object_len; - sp->index = pSavePkt->object_index; - - if ((buf = PyByteArray_AsString(pSavePkt->object))) { - if (plugin_priv_ctx->object) { free(plugin_priv_ctx->object); } - plugin_priv_ctx->object = (char*)malloc(pSavePkt->object_len); - memcpy(plugin_priv_ctx->object, buf, pSavePkt->object_len); - sp->object = plugin_priv_ctx->object; - } else { - goto bail_out; - } - } else { - goto bail_out; - } - } else { - goto bail_out; - } - } else { - sp->no_read = pSavePkt->no_read; - sp->delta_seq = pSavePkt->delta_seq; - } - } else { - sp->no_read = pSavePkt->no_read; - sp->delta_seq = pSavePkt->delta_seq; - - if (PyByteArray_Check(pSavePkt->flags)) { - char* flags; - - if (PyByteArray_Size(pSavePkt->flags) != sizeof(sp->flags)) { - goto bail_out; - } - - if ((flags = PyByteArray_AsString(pSavePkt->flags))) { - memcpy(sp->flags, flags, sizeof(sp->flags)); - } else { - goto bail_out; - } - } else { - goto bail_out; - } - } - - return true; - -bail_out: - return false; -} - -static inline PyIoPacket* NativeToPyIoPacket(struct io_pkt* io) -{ - PyIoPacket* pIoPkt = PyObject_New(PyIoPacket, &PyIoPacketType); - - if (pIoPkt) { - /* - * Initialize the Python IoPkt with the data we got passed in. - */ - pIoPkt->func = io->func; - pIoPkt->count = io->count; - pIoPkt->flags = io->flags; - pIoPkt->mode = io->mode; - pIoPkt->fname = io->fname; - pIoPkt->whence = io->whence; - pIoPkt->offset = io->offset; - if (io->func == IO_WRITE && io->count > 0) { - /* - * Only initialize the buffer with read data when we are writing and there - * is data. - */ - pIoPkt->buf = PyByteArray_FromStringAndSize(io->buf, io->count); - if (!pIoPkt->buf) { - Py_DECREF((PyObject*)pIoPkt); - return (PyIoPacket*)NULL; - } - } else { - pIoPkt->buf = NULL; - } - - /* - * These must be set by the Python function but we initialize them to zero - * to be sure they have some valid setting an not random data. - */ - pIoPkt->io_errno = 0; - pIoPkt->lerror = 0; - pIoPkt->win32 = false; - pIoPkt->status = 0; - } - - return pIoPkt; -} - -static inline bool PyIoPacketToNative(PyIoPacket* pIoPkt, struct io_pkt* io) -{ - /* - * Only copy back the arguments that are allowed to change. - */ - io->io_errno = pIoPkt->io_errno; - io->lerror = pIoPkt->lerror; - io->win32 = pIoPkt->win32; - io->status = pIoPkt->status; - if (io->func == IO_READ && io->status > 0) { - /* - * Only copy back the data when doing a read and there is data. - */ - if (PyByteArray_Check(pIoPkt->buf)) { - char* buf; - - if (PyByteArray_Size(pIoPkt->buf) > io->count || io->status > io->count) { - return false; - } - - if (!(buf = PyByteArray_AsString(pIoPkt->buf))) { return false; } - memcpy(io->buf, buf, io->status); - } - } - - return true; -} - -static inline PyRestorePacket* NativeToPyRestorePacket(struct restore_pkt* rp) -{ - PyRestorePacket* pRestorePacket = - PyObject_New(PyRestorePacket, &PyRestorePacketType); - - if (pRestorePacket) { - pRestorePacket->stream = rp->stream; - pRestorePacket->data_stream = rp->data_stream; - pRestorePacket->type = rp->type; - pRestorePacket->file_index = rp->file_index; - pRestorePacket->LinkFI = rp->LinkFI; - pRestorePacket->uid = rp->uid; - pRestorePacket->statp = (PyObject*)NativeToPyStatPacket(&rp->statp); - pRestorePacket->attrEx = rp->attrEx; - pRestorePacket->ofname = rp->ofname; - pRestorePacket->olname = rp->olname; - pRestorePacket->where = rp->where; - pRestorePacket->RegexWhere = rp->RegexWhere; - pRestorePacket->replace = rp->replace; - pRestorePacket->create_status = rp->create_status; - } - - return pRestorePacket; -} - -static inline void PyRestorePacketToNative(PyRestorePacket* pRestorePacket, - struct restore_pkt* rp) -{ - /* - * Only copy back the fields that are allowed to be changed. - */ - rp->create_status = pRestorePacket->create_status; -} - - -static inline PyAclPacket* NativeToPyAclPacket(struct acl_pkt* ap) -{ - PyAclPacket* pAclPacket = PyObject_New(PyAclPacket, &PyAclPacketType); - - if (pAclPacket) { - pAclPacket->fname = ap->fname; - - if (ap->content_length && ap->content) { - pAclPacket->content = - PyByteArray_FromStringAndSize(ap->content, ap->content_length); - } else { - pAclPacket->content = NULL; - } - } - - return pAclPacket; -} - -static inline bool PyAclPacketToNative(PyAclPacket* pAclPacket, - struct acl_pkt* ap) -{ - if (!pAclPacket->content) { return true; } - - if (PyByteArray_Check(pAclPacket->content)) { - char* buf; - - ap->content_length = PyByteArray_Size(pAclPacket->content); - if (ap->content_length <= 0 || - !(buf = PyByteArray_AsString(pAclPacket->content))) { - return false; - } - - if (ap->content) { free(ap->content); } - ap->content = (char*)malloc(ap->content_length); - memcpy(ap->content, buf, ap->content_length); - } - - return true; -} - -static inline PyXattrPacket* NativeToPyXattrPacket(struct xattr_pkt* xp) -{ - PyXattrPacket* pXattrPacket = PyObject_New(PyXattrPacket, &PyXattrPacketType); - - if (pXattrPacket) { - pXattrPacket->fname = xp->fname; - - if (xp->name_length && xp->name) { - pXattrPacket->name = - PyByteArray_FromStringAndSize(xp->name, xp->name_length); - } else { - pXattrPacket->name = NULL; - } - if (xp->value_length && xp->value) { - pXattrPacket->value = - PyByteArray_FromStringAndSize(xp->value, xp->value_length); - } else { - pXattrPacket->value = NULL; - } - } - - return pXattrPacket; -} - -static inline bool PyXattrPacketToNative(PyXattrPacket* pXattrPacket, - struct xattr_pkt* xp) -{ - if (!pXattrPacket->name) { return true; } - - if (PyByteArray_Check(pXattrPacket->name)) { - char* buf; - - xp->name_length = PyByteArray_Size(pXattrPacket->name); - if (xp->name_length <= 0 || - !(buf = PyByteArray_AsString(pXattrPacket->name))) { - return false; - } - - if (xp->name) { free(xp->name); } - xp->name = (char*)malloc(xp->name_length); - memcpy(xp->name, buf, xp->name_length); - } - - if (pXattrPacket->value && PyByteArray_Check(pXattrPacket->value)) { - char* buf; - - xp->value_length = PyByteArray_Size(pXattrPacket->value); - if (xp->name_length <= 0 || - !(buf = PyByteArray_AsString(pXattrPacket->name))) { - return false; - } - - if (xp->value) { free(xp->value); } - xp->value = (char*)malloc(xp->value_length); - memcpy(xp->value, buf, xp->value_length); - } else { - if (xp->value) { free(xp->value); } - xp->value = NULL; - } - - return true; -} - -static inline PyRestoreObject* NativeToPyRestoreObject( - struct restore_object_pkt* rop) -{ - PyRestoreObject* pRestoreObject = - PyObject_New(PyRestoreObject, &PyRestoreObjectType); - - if (pRestoreObject) { - pRestoreObject->object_name = PyString_FromString(rop->object_name); - pRestoreObject->object = - PyByteArray_FromStringAndSize(rop->object, rop->object_len); - pRestoreObject->plugin_name = rop->plugin_name; - pRestoreObject->object_type = rop->object_type; - pRestoreObject->object_len = rop->object_len; - pRestoreObject->object_full_len = rop->object_full_len; - pRestoreObject->object_index = rop->object_index; - pRestoreObject->object_compression = rop->object_compression; - pRestoreObject->stream = rop->stream; - pRestoreObject->JobId = rop->JobId; - } - - return pRestoreObject; -} - - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to get certain internal values of the current Job. - */ -static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) -{ - int var; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - PyObject* pRetVal = NULL; - - if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - switch (var) { - case bVarFDName: - case bVarWorkingDir: - case bVarExePath: - case bVarVersion: - case bVarDistName: { - char* value = NULL; - - if (bareos_core_functions->getBareosValue( - bareos_plugin_ctx, (bVariable)var, &value) == bRC_OK) { - if (value) { pRetVal = PyString_FromString(value); } - } - break; - } - case bVarJobId: - case bVarLevel: - case bVarType: - case bVarJobStatus: - case bVarSinceTime: - case bVarAccurate: - case bVarPrefixLinks: { - int value = 0; - - if (bareos_core_functions->getBareosValue( - bareos_plugin_ctx, (bVariable)var, &value) == bRC_OK) { - pRetVal = PyInt_FromLong(value); - } - break; - } - case bVarClient: - case bVarJobName: - case bVarPrevJobName: - case bVarWhere: - case bVarRegexWhere: { - char* value = NULL; - - if (bareos_core_functions->getBareosValue( - bareos_plugin_ctx, (bVariable)var, &value) == bRC_OK) { - if (value) { pRetVal = PyString_FromString(value); } - } - break; - } - case bVarFileSeen: - break; /* a write only variable, ignore read request */ - default: - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: PyBareosGetValue unknown variable requested %d\n", var); - break; - } - - if (!pRetVal) { - Py_INCREF(Py_None); - pRetVal = Py_None; - } - - return pRetVal; -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to set certain internal values of the current Job. - */ -static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) -{ - int var; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; - PyObject* pyValue; - - if (!PyArg_ParseTuple(args, "iO:BareosSetValue", &var, &pyValue)) { - goto bail_out; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - ctx = PyGetbpContext(pyCtx); - switch (var) { - case bVarSinceTime: - case bVarLevel: { - int value = 0; - - value = PyInt_AsLong(pyValue); - if (value) { - retval = bareos_core_functions->setBareosValue(bareos_plugin_ctx, - (bVariable)var, &value); - } - break; - } - case bVarFileSeen: { - char* value; - - value = PyString_AsString(pyValue); - if (value) { - retval = bareos_core_functions->setBareosValue(bareos_plugin_ctx, - (bVariable)var, value); - } - break; - } - default: - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: PyBareosSetValue unknown variable requested %d\n", var); - break; - } - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue debug messages using the Bareos debug message - * facility. - */ -static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) -{ - int level; - char* dbgmsg = NULL; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - /* plugin_private_context* ppc = */ - /* (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; */ - - if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { - return NULL; - } - RETURN_RUNTIME_ERROR_IF_BAREOS_PLUGIN_CTX_UNSET() - - if (dbgmsg) { Dmsg(bareos_plugin_ctx, level, "python-fd: %s", dbgmsg); } - Py_INCREF(Py_None); - return Py_None; -} - -/** - * Callback function which is exposed as a part of the additional methods - * which allow a Python plugin to issue Job messages using the Bareos Job - * message facility. - */ -static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) -{ - int type; - char* jobmsg = NULL; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - - if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { - return NULL; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - if (jobmsg) { Jmsg(bareos_plugin_ctx, type, "python-fd: %s", jobmsg); } - - Py_INCREF(Py_None); - return Py_None; -} - -/** - * Callback function which is exposed as a part of the additional methods - * which allow a Python plugin to issue a Register Event to register - * additional events it wants to receive. - */ -static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) -{ - int len, event; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; - PyObject *pyEvents, *pySeq, *pyEvent; - - if (!PyArg_ParseTuple(args, "O:BareosRegisterEvents", &pyEvents)) { - goto bail_out; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); - if (!pySeq) { goto bail_out; } - len = PySequence_Fast_GET_SIZE(pySeq); - - for (int i = 0; i < len; i++) { - pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); - event = PyInt_AsLong(pyEvent); - - if (event >= bEventJobStart && event <= FD_NR_EVENTS) { - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: PyBareosRegisterEvents registering event %d\n", event); - retval = bareos_core_functions->registerBareosEvents(bareos_plugin_ctx, 1, - event); - - if (retval != bRC_OK) { break; } - } - } - - Py_DECREF(pySeq); - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods - * which allow a Python plugin to issue an Unregister Event to unregister - * events it doesn't want to receive anymore. - */ -static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) -{ - int len, event; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; - PyObject *pyEvents, *pySeq, *pyEvent; - - if (!PyArg_ParseTuple(args, "O:BareosUnRegisterEvents", &pyEvents)) { - goto bail_out; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); - if (!pySeq) { goto bail_out; } - - len = PySequence_Fast_GET_SIZE(pySeq); - for (int i = 0; i < len; i++) { - pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); - event = PyInt_AsLong(pyEvent); - - if (event >= bEventJobStart && event <= FD_NR_EVENTS) { - Dmsg(bareos_plugin_ctx, debuglevel, - "PyBareosUnRegisterEvents: unregistering event %d\n", event); - retval = bareos_core_functions->unregisterBareosEvents(bareos_plugin_ctx, - 1, event); - } - } - - Py_DECREF(pySeq); - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods - * which allow a Python plugin to issue a GetInstanceCount to retrieve the - * number of instances of the current plugin being loaded into the daemon. - */ -static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) -{ - int value; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - PyObject* pRetVal = NULL; - - if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - if (bareos_core_functions->getInstanceCount(bareos_plugin_ctx, &value) == - bRC_OK) { - pRetVal = PyInt_FromLong(value); - } - - if (!pRetVal) { - Py_INCREF(Py_None); - pRetVal = Py_None; - } - - return pRetVal; -} - -/** - * Callback function which is exposed as a part of the additional methods - * which allow a Python plugin to issue a Add Exclude pattern to the fileset. - */ -static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) -{ - char* file = NULL; - bRC retval = bRC_Error; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - - if (!PyArg_ParseTuple(args, "|z:BareosAddExclude", &file)) { goto bail_out; } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - if (file) { - retval = bareos_core_functions->AddExclude(bareos_plugin_ctx, file); - } - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods - * which allow a Python plugin to issue a Add Include pattern to the fileset. - */ -static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) -{ - char* file = NULL; - bRC retval = bRC_Error; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - - if (!PyArg_ParseTuple(args, "|z:BareosAddInclude", &file)) { goto bail_out; } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - if (file) { - retval = bareos_core_functions->AddInclude(bareos_plugin_ctx, file); - } - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods - * which allow a Python plugin to issue a Add Include Options to the fileset. - */ -static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) -{ - char* opts = NULL; - bRC retval = bRC_Error; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - - if (!PyArg_ParseTuple(args, "|z:BareosAddOptions", &opts)) { goto bail_out; } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - if (opts) { - retval = bareos_core_functions->AddOptions(bareos_plugin_ctx, opts); - } - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods - * which allow a Python plugin to issue a Add Regex to the fileset. - */ -static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) -{ - int type; - char* item = NULL; - bRC retval = bRC_Error; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - if (!PyArg_ParseTuple(args, "|zi:BareosAddRegex", &item, &type)) { - goto bail_out; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - if (item) { - retval = bareos_core_functions->AddRegex(bareos_plugin_ctx, item, type); - } - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods - * which allow a Python plugin to issue a Add Wildcard to the fileset. - */ -static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) -{ - int type; - char* item = NULL; - bRC retval = bRC_Error; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - - if (!PyArg_ParseTuple(args, "|zi:BareosAddWild", &item, &type)) { - goto bail_out; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - if (item) { - retval = bareos_core_functions->AddWild(bareos_plugin_ctx, item, type); - } - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods - * which allow a Python plugin to issue a Add New Option block. - */ -static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) -{ - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; - - if (!PyArg_ParseTuple(args, ":BareosNewOptions")) { goto bail_out; } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - retval = bareos_core_functions->NewOptions(bareos_plugin_ctx); - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods - * which allow a Python plugin to issue a Add New Include block. - */ -static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) -{ - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; - - if (!PyArg_ParseTuple(args, ":BareosNewInclude")) { goto bail_out; } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - retval = bareos_core_functions->NewInclude(bareos_plugin_ctx); - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods - * which allow a Python plugin to issue a Add New Pre Include block. - */ -static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) -{ - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; - - if (!PyArg_ParseTuple(args, ":BareosNewPreInclude")) { goto bail_out; } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - retval = bareos_core_functions->NewPreInclude(bareos_plugin_ctx); - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods - * which allow a Python plugin to issue a check if a file have to be backed up - * using Accurate code. - */ -static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) -{ - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - - struct save_pkt sp; - bRC retval = bRC_Error; - PySavePacket* pSavePkt; - - if (!PyArg_ParseTuple(args, "O:BareosCheckChanges", &pSavePkt)) { - goto bail_out; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - - /* - * CheckFile only has a need for a limited version of the PySavePacket so we - * handle that here separately and don't call PySavePacketToNative(). - */ - sp.type = pSavePkt->type; - if (pSavePkt->fname) { - if (PyString_Check(pSavePkt->fname)) { - sp.fname = PyString_AsString(pSavePkt->fname); - } else { - goto bail_out; - } - } else { - goto bail_out; - } - if (pSavePkt->link) { - if (PyString_Check(pSavePkt->link)) { - sp.link = PyString_AsString(pSavePkt->link); - } else { - goto bail_out; - } - } - sp.save_time = pSavePkt->save_time; - - retval = bareos_core_functions->checkChanges(bareos_plugin_ctx, &sp); - - /* - * Copy back the two fields that are changed by checkChanges(). - */ - pSavePkt->delta_seq = sp.delta_seq; - pSavePkt->accurate_found = sp.accurate_found; - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods - * which allow a Python plugin to issue a check if a file would be saved using - * current Include/Exclude code. - */ -static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) -{ - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - struct save_pkt sp; - bRC retval = bRC_Error; - PySavePacket* pSavePkt; - - if (!PyArg_ParseTuple(args, "O:BareosAcceptFile", &pSavePkt)) { - goto bail_out; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - /* - * Acceptfile only needs fname and statp from PySavePacket so we handle - * that here separately and don't call PySavePacketToNative(). - */ - if (pSavePkt->fname) { - if (PyString_Check(pSavePkt->fname)) { - sp.fname = PyString_AsString(pSavePkt->fname); - } else { - goto bail_out; - } - } else { - goto bail_out; - } - - if (pSavePkt->statp) { - PyStatPacketToNative((PyStatPacket*)pSavePkt->statp, &sp.statp); - } else { - goto bail_out; - } - - retval = bareos_core_functions->AcceptFile(bareos_plugin_ctx, &sp); - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods - * which allow a Python plugin to issue a Set bit in the Accurate Seen bitmap. - */ -static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) -{ - bool all; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - char* fname = NULL; - bRC retval = bRC_Error; - PyObject* pyBool; - - if (!PyArg_ParseTuple(args, "O|s:BareosSetSeenBitmap", &pyBool, &fname)) { - goto bail_out; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - all = PyObject_IsTrue(pyBool); - retval = bareos_core_functions->SetSeenBitmap(bareos_plugin_ctx, all, fname); - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods - * which allow a Python plugin to issue a Clear bit in the Accurate Seen - * bitmap. - */ -static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) -{ - bool all; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); - char* fname = NULL; - bRC retval = bRC_Error; - PyObject* pyBool; - - if (!PyArg_ParseTuple(args, "O|s:BareosClearSeenBitmap", &pyBool, &fname)) { - goto bail_out; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - all = PyObject_IsTrue(pyBool); - retval = - bareos_core_functions->ClearSeenBitmap(bareos_plugin_ctx, all, fname); - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Some helper functions. - */ -static inline char* PyGetStringValue(PyObject* object) -{ - if (!object || !PyString_Check(object)) { return (char*)""; } - - return PyString_AsString(object); -} - -static inline char* PyGetByteArrayValue(PyObject* object) -{ - if (!object || !PyByteArray_Check(object)) { return (char*)""; } - - return PyByteArray_AsString(object); -} - -/** - * Python specific handlers for PyRestoreObject structure mapping. - */ - -/** - * Representation. - */ -static PyObject* PyRestoreObject_repr(PyRestoreObject* self) -{ - PyObject* s; - PoolMem buf(PM_MESSAGE); - - Mmsg(buf, - "RestoreObject(object_name=\"%s\", object=\"%s\", plugin_name=\"%s\", " - "object_type=%d, object_len=%d, object_full_len=%d, " - "object_index=%d, object_compression=%d, stream=%d, jobid=%u)", - PyGetStringValue(self->object_name), PyGetByteArrayValue(self->object), - self->plugin_name, self->object_type, self->object_len, - self->object_full_len, self->object_index, self->object_compression, - self->stream, self->JobId); - s = PyString_FromString(buf.c_str()); - - return s; -} - -/** - * Initialization. - */ -static int PyRestoreObject_init(PyRestoreObject* self, - PyObject* args, - PyObject* kwds) -{ - static char* kwlist[] = {(char*)"object_name", - (char*)"object", - (char*)"plugin_name", - (char*)"object_type", - (char*)"object_len", - (char*)"object_full_len", - (char*)"object_index", - (char*)"object_compression", - (char*)"stream", - (char*)"jobid", - NULL}; - - self->object_name = NULL; - self->object = NULL; - self->plugin_name = NULL; - self->object_type = 0; - self->object_len = 0; - self->object_full_len = 0; - self->object_index = 0; - self->object_compression = 0; - self->stream = 0; - self->JobId = 0; - - if (!PyArg_ParseTupleAndKeywords( - args, kwds, "|oosiiiiiiI", kwlist, &self->object_name, &self->object, - &self->plugin_name, &self->object_type, &self->object_len, - &self->object_full_len, &self->object_index, - &self->object_compression, &self->stream, &self->JobId)) { - return -1; - } - - return 0; -} - -/** - * Destructor. - */ -static void PyRestoreObject_dealloc(PyRestoreObject* self) -{ - if (self->object_name) { Py_XDECREF(self->object_name); } - if (self->object) { Py_XDECREF(self->object); } - PyObject_Del(self); -} - -/** - * Python specific handlers for PyStatPacket structure mapping. - */ - -/** - * Representation. - */ -static PyObject* PyStatPacket_repr(PyStatPacket* self) -{ - PyObject* s; - PoolMem buf(PM_MESSAGE); - - Mmsg(buf, - "StatPacket(dev=%ld, ino=%lld, mode=%04o, nlink=%d, " - "uid=%ld, gid=%ld, rdev=%ld, size=%lld, " - "atime=%ld, mtime=%ld, ctime=%ld, blksize=%ld, blocks=%lld)", - self->dev, self->ino, (self->mode & ~S_IFMT), self->nlink, self->uid, - self->gid, self->rdev, self->size, self->atime, self->mtime, self->ctime, - self->blksize, self->blocks); - - s = PyString_FromString(buf.c_str()); - - return s; -} - -/** - * Initialization. - */ -static int PyStatPacket_init(PyStatPacket* self, PyObject* args, PyObject* kwds) -{ - time_t now; - static char* kwlist[] = {(char*)"dev", (char*)"ino", - (char*)"mode", (char*)"nlink", - (char*)"uid", (char*)"gid", - (char*)"rdev", (char*)"size", - (char*)"atime", (char*)"mtime", - (char*)"ctime", (char*)"blksize", - (char*)"blocks", NULL}; - - now = time(NULL); - self->dev = 0; - self->ino = 0; - self->mode = 0700 | S_IFREG; - self->nlink = 0; - self->uid = 0; - self->gid = 0; - self->rdev = 0; - self->size = -1; - self->atime = now; - self->mtime = now; - self->ctime = now; - self->blksize = 4096; - self->blocks = 1; - - if (!PyArg_ParseTupleAndKeywords( - args, kwds, "|IKHHIIIKIIIIK", kwlist, &self->dev, &self->ino, - &self->mode, &self->nlink, &self->uid, &self->gid, &self->rdev, - &self->size, &self->atime, &self->mtime, &self->ctime, &self->blksize, - &self->blocks)) { - return -1; - } - - return 0; -} - -/** - * Destructor. - */ -static void PyStatPacket_dealloc(PyStatPacket* self) { PyObject_Del(self); } - -/** - * Python specific handlers for PySavePacket structure mapping. - */ - -/** - * Representation. - */ -static inline const char* print_flags_bitmap(PyObject* bitmap) -{ - static char visual_bitmap[FO_MAX + 1]; - if (!bitmap) { return ""; } - if (PyByteArray_Check(bitmap)) { - int cnt; - char* flags; - - if (PyByteArray_Size(bitmap) == FOPTS_BYTES) { - if ((flags = PyByteArray_AsString(bitmap))) { - memset(visual_bitmap, 0, sizeof(visual_bitmap)); - for (cnt = 0; cnt <= FO_MAX; cnt++) { - if (BitIsSet(cnt, flags)) { - visual_bitmap[cnt] = '1'; - } else { - visual_bitmap[cnt] = '0'; - } - } - - return visual_bitmap; - } - } - } - - return "Unknown"; -} - -static PyObject* PySavePacket_repr(PySavePacket* self) -{ - PyObject* s; - PoolMem buf(PM_MESSAGE); - - Mmsg(buf, - "SavePacket(fname=\"%s\", link=\"%s\", type=%ld, flags=%s, " - "no_read=%d, portable=%d, accurate_found=%d, " - "cmd=\"%s\", save_time=%ld, delta_seq=%ld, object_name=\"%s\", " - "object=\"%s\", object_len=%ld, object_index=%ld)", - PyGetStringValue(self->fname), PyGetStringValue(self->link), self->type, - print_flags_bitmap(self->flags), self->no_read, self->portable, - self->accurate_found, self->cmd, self->save_time, self->delta_seq, - PyGetStringValue(self->object_name), PyGetByteArrayValue(self->object), - self->object_len, self->object_index); - - s = PyString_FromString(buf.c_str()); - - return s; -} - -/** - * Initialization. - */ -static int PySavePacket_init(PySavePacket* self, PyObject* args, PyObject* kwds) -{ - static char* kwlist[] = { - (char*)"fname", (char*)"link", (char*)"type", - (char*)"flags", (char*)"no_read", (char*)"portable", - (char*)"accurate_found", (char*)"cmd", (char*)"save_time", - (char*)"delta_seq", (char*)"object_name", (char*)"object", - (char*)"object_len", (char*)"object_index", NULL}; - - self->fname = NULL; - self->link = NULL; - self->type = 0; - self->flags = NULL; - self->no_read = false; - self->portable = false; - self->accurate_found = false; - self->cmd = NULL; - self->save_time = 0; - self->delta_seq = 0; - self->object_name = NULL; - self->object = NULL; - self->object_len = 0; - self->object_index = 0; - - if (!PyArg_ParseTupleAndKeywords( - args, kwds, "|ooiocccsiiooii", kwlist, &self->fname, &self->link, - &self->type, &self->flags, &self->no_read, &self->portable, - &self->accurate_found, &self->cmd, &self->save_time, &self->delta_seq, - &self->object_name, &self->object, &self->object_len, - &self->object_index)) { - return -1; - } - - return 0; -} - -/** - * Destructor. - */ -static void PySavePacket_dealloc(PySavePacket* self) -{ - if (self->fname) { Py_XDECREF(self->fname); } - if (self->link) { Py_XDECREF(self->link); } - if (self->flags) { Py_XDECREF(self->flags); } - if (self->object_name) { Py_XDECREF(self->object_name); } - if (self->object) { Py_XDECREF(self->object); } - PyObject_Del(self); -} - -/** - * Python specific handlers for PyRestorePacket structure mapping. - */ - -/** - * Representation. - */ -static PyObject* PyRestorePacket_repr(PyRestorePacket* self) -{ - PyObject *stat_repr, *s; - PoolMem buf(PM_MESSAGE); - - stat_repr = PyObject_Repr(self->statp); - Mmsg(buf, - "RestorePacket(stream=%d, data_stream=%ld, type=%ld, file_index=%ld, " - "linkFI=%ld, uid=%ld, statp=\"%s\", attrEx=\"%s\", ofname=\"%s\", " - "olname=\"%s\", where=\"%s\", RegexWhere=\"%s\", replace=%d, " - "create_status=%d)", - self->stream, self->data_stream, self->type, self->file_index, - self->LinkFI, self->uid, PyGetStringValue(stat_repr), self->attrEx, - self->ofname, self->olname, self->where, self->RegexWhere, self->replace, - self->create_status); - - s = PyString_FromString(buf.c_str()); - Py_DECREF(stat_repr); - - return s; -} - -/** - * Initialization. - */ -static int PyRestorePacket_init(PyRestorePacket* self, - PyObject* args, - PyObject* kwds) -{ - static char* kwlist[] = { - (char*)"stream", (char*)"data_stream", (char*)"type", - (char*)"file_index", (char*)"linkFI", (char*)"uid", - (char*)"statp", (char*)"attrEX", (char*)"ofname", - (char*)"olname", (char*)"where", (char*)"regexwhere", - (char*)"replace", (char*)"create_status", NULL}; - - self->stream = 0; - self->data_stream = 0; - self->type = 0; - self->file_index = 0; - self->LinkFI = 0; - self->uid = 0; - self->statp = NULL; - self->attrEx = NULL; - self->ofname = NULL; - self->olname = NULL; - self->where = NULL; - self->RegexWhere = NULL; - self->replace = 0; - self->create_status = 0; - - if (!PyArg_ParseTupleAndKeywords( - args, kwds, "|iiiiiIosssssii", kwlist, &self->stream, - &self->data_stream, &self->type, &self->file_index, &self->LinkFI, - &self->uid, &self->statp, &self->attrEx, &self->ofname, &self->olname, - &self->where, &self->RegexWhere, &self->replace, - &self->create_status)) { - return -1; - } - - return 0; -} - -/** - * Destructor. - */ -static void PyRestorePacket_dealloc(PyRestorePacket* self) -{ - PyObject_Del(self); -} - -/** - * Python specific handlers for PyIoPacket structure mapping. - */ - -/** - * Representation. - */ -static PyObject* PyIoPacket_repr(PyIoPacket* self) -{ - PyObject* s; - PoolMem buf(PM_MESSAGE); - - Mmsg(buf, - "IoPacket(func=%d, count=%ld, flags=%ld, mode=%04o, " - "buf=\"%s\", fname=\"%s\", status=%ld, io_errno=%ld, lerror=%ld, " - "whence=%ld, offset=%lld, win32=%d)", - self->func, self->count, self->flags, (self->mode & ~S_IFMT), - PyGetByteArrayValue(self->buf), self->fname, self->status, - self->io_errno, self->lerror, self->whence, self->offset, self->win32); - s = PyString_FromString(buf.c_str()); - - return s; -} - -/** - * Initialization. - */ -static int PyIoPacket_init(PyIoPacket* self, PyObject* args, PyObject* kwds) -{ - static char* kwlist[] = {(char*)"func", - (char*)"count", - (char*)"flags", - (char*)"mode", - (char*)"buf", - (char*)"fname", - (char*)"status", - (char*)"io_errno", - (char*)"lerror", - (char*)"whence", - (char*)"offset", - (char*)"win32", - NULL}; - - self->func = 0; - self->count = 0; - self->flags = 0; - self->mode = 0; - self->buf = NULL; - self->fname = NULL; - self->status = 0; - self->io_errno = 0; - self->lerror = 0; - self->whence = 0; - self->offset = 0; - self->win32 = false; - - if (!PyArg_ParseTupleAndKeywords( - args, kwds, "|Hiiiosiiiilc", kwlist, &self->func, &self->count, - &self->flags, &self->mode, &self->buf, &self->fname, &self->status, - &self->io_errno, &self->lerror, &self->whence, &self->offset, - &self->win32)) { - return -1; - } - - return 0; -} - -/** - * Destructor. - */ -static void PyIoPacket_dealloc(PyIoPacket* self) -{ - if (self->buf) { Py_XDECREF(self->buf); } - PyObject_Del(self); -} - -/** - * Python specific handlers for PyAclPacket structure mapping. - */ - -/** - * Representation. - */ -static PyObject* PyAclPacket_repr(PyAclPacket* self) -{ - PyObject* s; - PoolMem buf(PM_MESSAGE); - - Mmsg(buf, "AclPacket(fname=\"%s\", content=\"%s\")", self->fname, - PyGetByteArrayValue(self->content)); - s = PyString_FromString(buf.c_str()); - - return s; -} - -/** - * Initialization. - */ -static int PyAclPacket_init(PyAclPacket* self, PyObject* args, PyObject* kwds) -{ - static char* kwlist[] = {(char*)"fname", (char*)"content", NULL}; - - self->fname = NULL; - self->content = NULL; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|so", kwlist, &self->fname, - &self->content)) { - return -1; - } - - return 0; -} - -/** - * Destructor. - */ -static void PyAclPacket_dealloc(PyAclPacket* self) -{ - if (self->content) { Py_XDECREF(self->content); } - PyObject_Del(self); -} - -/** - * Python specific handlers for PyIOPacket structure mapping. - */ - -/** - * Representation. - */ -static PyObject* PyXattrPacket_repr(PyXattrPacket* self) -{ - PyObject* s; - PoolMem buf(PM_MESSAGE); - - Mmsg(buf, "XattrPacket(fname=\"%s\", name=\"%s\", value=\"%s\")", self->fname, - PyGetByteArrayValue(self->name), PyGetByteArrayValue(self->value)); - s = PyString_FromString(buf.c_str()); - - return s; -} - -/** - * Initialization. - */ -static int PyXattrPacket_init(PyXattrPacket* self, - PyObject* args, - PyObject* kwds) -{ - static char* kwlist[] = {(char*)"fname", (char*)"name", (char*)"value", NULL}; - - self->fname = NULL; - self->name = NULL; - self->value = NULL; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|soo", kwlist, &self->fname, - &self->name, &self->value)) { - return -1; - } - - return 0; -} - -/** - * Destructor. - */ -static void PyXattrPacket_dealloc(PyXattrPacket* self) -{ - if (self->value) { Py_XDECREF(self->value); } - if (self->name) { Py_XDECREF(self->name); } - PyObject_Del(self); -} - - } /* namespace filedaemon */ diff --git a/core/src/plugins/filed/python/python-fd.h b/core/src/plugins/filed/python/python-fd.h index 71256b01adf..cb4cff65a2e 100644 --- a/core/src/plugins/filed/python/python-fd.h +++ b/core/src/plugins/filed/python/python-fd.h @@ -58,974 +58,5 @@ static plugin_argument plugin_arguments[] = { {"module_name", argument_module_name}, {NULL, argument_none}}; -/** - * Python structures mapping C++ ones. - */ - -/** - * This packet is used for the restore objects. - * It is passed to the plugin when restoring the object. - */ -typedef struct { - PyObject_HEAD PyObject* object_name; /* Object name */ - PyObject* object; /* Restore object data to restore */ - char* plugin_name; /* Plugin name */ - int32_t object_type; /* FT_xx for this file */ - int32_t object_len; /* restore object length */ - int32_t object_full_len; /* restore object uncompressed length */ - int32_t object_index; /* restore object index */ - int32_t object_compression; /* set to compression type */ - int32_t stream; /* attribute stream id */ - uint32_t JobId; /* JobId object came from */ -} PyRestoreObject; - -/** - * Forward declarations of type specific functions. - */ -static void PyRestoreObject_dealloc(PyRestoreObject* self); -static int PyRestoreObject_init(PyRestoreObject* self, - PyObject* args, - PyObject* kwds); -static PyObject* PyRestoreObject_repr(PyRestoreObject* self); - -static PyMethodDef PyRestoreObject_methods[] = { - {NULL} /* Sentinel */ -}; - -static PyMemberDef PyRestoreObject_members[] = { - {(char*)"object_name", T_OBJECT, offsetof(PyRestoreObject, object_name), 0, - (char*)"Object Name"}, - {(char*)"object", T_OBJECT, offsetof(PyRestoreObject, object), 0, - (char*)"Object Content"}, - {(char*)"plugin_name", T_STRING, offsetof(PyRestoreObject, plugin_name), 0, - (char*)"Plugin Name"}, - {(char*)"object_type", T_INT, offsetof(PyRestoreObject, object_type), 0, - (char*)"Object Type"}, - {(char*)"object_len", T_INT, offsetof(PyRestoreObject, object_len), 0, - (char*)"Object Length"}, - {(char*)"object_full_len", T_INT, - offsetof(PyRestoreObject, object_full_len), 0, - (char*)"Object Full Length"}, - {(char*)"object_index", T_INT, offsetof(PyRestoreObject, object_index), 0, - (char*)"Object Index"}, - {(char*)"object_compression", T_INT, - offsetof(PyRestoreObject, object_compression), 0, - (char*)"Object Compression"}, - {(char*)"stream", T_INT, offsetof(PyRestoreObject, stream), 0, - (char*)"Attribute Stream"}, - {(char*)"jobid", T_UINT, offsetof(PyRestoreObject, JobId), 0, - (char*)"Jobid"}, - {NULL}}; - -static PyTypeObject PyRestoreObjectType = { - PyVarObject_HEAD_INIT(NULL, 0) "restore_object", /* tp_name */ - sizeof(PyRestoreObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)PyRestoreObject_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - (reprfunc)PyRestoreObject_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/ - "io_pkt object", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - PyRestoreObject_methods, /* tp_methods */ - PyRestoreObject_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)PyRestoreObject_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ -}; - -/** - * The PyStatPacket type - */ -typedef struct { - PyObject_HEAD uint32_t dev; - uint64_t ino; - uint16_t mode; - int16_t nlink; - uint32_t uid; - uint32_t gid; - uint32_t rdev; - uint64_t size; - time_t atime; - time_t mtime; - time_t ctime; - uint32_t blksize; - uint64_t blocks; -} PyStatPacket; - -/** - * Forward declarations of type specific functions. - */ -static void PyStatPacket_dealloc(PyStatPacket* self); -static int PyStatPacket_init(PyStatPacket* self, - PyObject* args, - PyObject* kwds); -static PyObject* PyStatPacket_repr(PyStatPacket* self); - -static PyMethodDef PyStatPacket_methods[] = { - {NULL} /* Sentinel */ -}; - -static PyMemberDef PyStatPacket_members[] = { - {(char*)"st_dev", T_UINT, offsetof(PyStatPacket, dev), 0, (char*)"Device"}, - {(char*)"st_ino", T_ULONGLONG, offsetof(PyStatPacket, ino), 0, - (char*)"Inode number"}, - {(char*)"st_mode", T_USHORT, offsetof(PyStatPacket, mode), 0, - (char*)"Mode"}, - {(char*)"st_nlink", T_USHORT, offsetof(PyStatPacket, nlink), 0, - (char*)"Number of hardlinks"}, - {(char*)"st_uid", T_UINT, offsetof(PyStatPacket, uid), 0, (char*)"User Id"}, - {(char*)"st_gid", T_UINT, offsetof(PyStatPacket, gid), 0, - (char*)"Group Id"}, - {(char*)"st_rdev", T_UINT, offsetof(PyStatPacket, rdev), 0, (char*)"Rdev"}, - {(char*)"st_size", T_ULONGLONG, offsetof(PyStatPacket, size), 0, - (char*)"Size"}, - {(char*)"st_atime", T_UINT, offsetof(PyStatPacket, atime), 0, - (char*)"Access Time"}, - {(char*)"st_mtime", T_UINT, offsetof(PyStatPacket, mtime), 0, - (char*)"Modification Time"}, - {(char*)"st_ctime", T_UINT, offsetof(PyStatPacket, ctime), 0, - (char*)"Change Time"}, - {(char*)"st_blksize", T_UINT, offsetof(PyStatPacket, blksize), 0, - (char*)"Blocksize"}, - {(char*)"st_blocks", T_ULONGLONG, offsetof(PyStatPacket, blocks), 0, - (char*)"Blocks"}, - {NULL}}; - -static PyTypeObject PyStatPacketType = { - PyVarObject_HEAD_INIT(NULL, 0) "stat_pkt", /* tp_name */ - sizeof(PyStatPacket), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)PyStatPacket_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - (reprfunc)PyStatPacket_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/ - "io_pkt object", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - PyStatPacket_methods, /* tp_methods */ - PyStatPacket_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)PyStatPacket_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ -}; - -/** - * The PySavePacket type - */ -typedef struct { - PyObject_HEAD PyObject* fname; /* Full path and filename */ - PyObject* link; /* Link name if any */ - PyObject* statp; /* System stat() packet for file */ - int32_t type; /* FT_xx for this file */ - PyObject* flags; /* Bareos internal flags */ - bool no_read; /* During the save, the file should not be saved */ - bool portable; /* set if data format is portable */ - bool accurate_found; /* Found in accurate list (valid after CheckChanges()) */ - char* cmd; /* Command */ - time_t save_time; /* Start of incremental time */ - uint32_t delta_seq; /* Delta sequence number */ - PyObject* object_name; /* Object name to create */ - PyObject* object; /* Restore object data to save */ - int32_t object_len; /* Restore object length */ - int32_t object_index; /* Restore object index */ -} PySavePacket; - -/** - * Forward declarations of type specific functions. - */ -static void PySavePacket_dealloc(PySavePacket* self); -static int PySavePacket_init(PySavePacket* self, - PyObject* args, - PyObject* kwds); -static PyObject* PySavePacket_repr(PySavePacket* self); - -static PyMethodDef PySavePacket_methods[] = { - {NULL} /* Sentinel */ -}; - -static PyMemberDef PySavePacket_members[] = { - {(char*)"fname", T_OBJECT, offsetof(PySavePacket, fname), 0, - (char*)"Filename"}, - {(char*)"link", T_OBJECT, offsetof(PySavePacket, link), 0, - (char*)"Linkname"}, - {(char*)"statp", T_OBJECT, offsetof(PySavePacket, statp), 0, - (char*)"Stat Packet"}, - {(char*)"type", T_INT, offsetof(PySavePacket, type), 0, (char*)"Type"}, - {(char*)"flags", T_OBJECT, offsetof(PySavePacket, flags), 0, - (char*)"Flags"}, - {(char*)"no_read", T_BOOL, offsetof(PySavePacket, no_read), 0, - (char*)"No Read"}, - {(char*)"portable", T_BOOL, offsetof(PySavePacket, portable), 0, - (char*)"Portable"}, - {(char*)"accurate_found", T_BOOL, offsetof(PySavePacket, accurate_found), 0, - (char*)"Accurate Found"}, - {(char*)"cmd", T_STRING, offsetof(PySavePacket, cmd), 0, (char*)"Command"}, - {(char*)"save_time", T_UINT, offsetof(PySavePacket, save_time), 0, - (char*)"Save Time"}, - {(char*)"delta_seq", T_UINT, offsetof(PySavePacket, delta_seq), 0, - (char*)"Delta Sequence"}, - {(char*)"object_name", T_OBJECT, offsetof(PySavePacket, object_name), 0, - (char*)"Restore Object Name"}, - {(char*)"object", T_OBJECT, offsetof(PySavePacket, object), 0, - (char*)"Restore ObjectName"}, - {(char*)"object_len", T_INT, offsetof(PySavePacket, object_len), 0, - (char*)"Restore ObjectLen"}, - {(char*)"object_index", T_INT, offsetof(PySavePacket, object_index), 0, - (char*)"Restore ObjectIndex"}, - {NULL}}; - -static PyTypeObject PySavePacketType = { - PyVarObject_HEAD_INIT(NULL, 0) "save_pkt", /* tp_name */ - sizeof(PySavePacket), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)PySavePacket_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - (reprfunc)PySavePacket_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/ - "save_pkt object", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - PySavePacket_methods, /* tp_methods */ - PySavePacket_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)PySavePacket_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ -}; - -/** - * The PyRestorePacket type - */ -typedef struct { - PyObject_HEAD int32_t stream; /* Attribute stream id */ - int32_t data_stream; /* Id of data stream to follow */ - int32_t type; /* File type FT */ - int32_t file_index; /* File index */ - int32_t LinkFI; /* File index to data if hard link */ - uint32_t uid; /* Userid */ - PyObject* statp; /* Decoded stat packet */ - const char* attrEx; /* Extended attributes if any */ - const char* ofname; /* Output filename */ - const char* olname; /* Output link name */ - const char* where; /* Where */ - const char* RegexWhere; /* Regex where */ - int replace; /* Replace flag */ - int create_status; /* Status from createFile() */ -} PyRestorePacket; - -/** - * Forward declarations of type specific functions. - */ -static void PyRestorePacket_dealloc(PyRestorePacket* self); -static int PyRestorePacket_init(PyRestorePacket* self, - PyObject* args, - PyObject* kwds); -static PyObject* PyRestorePacket_repr(PyRestorePacket* self); - -static PyMethodDef PyRestorePacket_methods[] = { - {NULL} /* Sentinel */ -}; - -static PyMemberDef PyRestorePacket_members[] = { - {(char*)"stream", T_INT, offsetof(PyRestorePacket, stream), 0, - (char*)"Attribute stream id"}, - {(char*)"data_stream", T_INT, offsetof(PyRestorePacket, data_stream), 0, - (char*)"Id of data stream to follow"}, - {(char*)"type", T_INT, offsetof(PyRestorePacket, type), 0, - (char*)"File type FT"}, - {(char*)"file_index", T_INT, offsetof(PyRestorePacket, file_index), 0, - (char*)"File index"}, - {(char*)"linkFI", T_INT, offsetof(PyRestorePacket, LinkFI), 0, - (char*)"File index to data if hard link"}, - {(char*)"uid", T_UINT, offsetof(PyRestorePacket, uid), 0, (char*)"User Id"}, - {(char*)"statp", T_OBJECT, offsetof(PyRestorePacket, statp), 0, - (char*)"Stat Packet"}, - {(char*)"attrEX", T_STRING, offsetof(PyRestorePacket, attrEx), 0, - (char*)"Extended attributes"}, - {(char*)"ofname", T_STRING, offsetof(PyRestorePacket, ofname), 0, - (char*)"Output filename"}, - {(char*)"olname", T_STRING, offsetof(PyRestorePacket, olname), 0, - (char*)"Output link name"}, - {(char*)"where", T_STRING, offsetof(PyRestorePacket, where), 0, - (char*)"Where"}, - {(char*)"regexwhere", T_STRING, offsetof(PyRestorePacket, RegexWhere), 0, - (char*)"Regex where"}, - {(char*)"replace", T_INT, offsetof(PyRestorePacket, replace), 0, - (char*)"Replace flag"}, - {(char*)"create_status", T_INT, offsetof(PyRestorePacket, create_status), 0, - (char*)"Status from createFile()"}, - {NULL}}; - -static PyTypeObject PyRestorePacketType = { - PyVarObject_HEAD_INIT(NULL, 0) "restore_pkt", /* tp_name */ - sizeof(PyRestorePacket), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)PyRestorePacket_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - (reprfunc)PyRestorePacket_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/ - "restore_pkt object", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - PyRestorePacket_methods, /* tp_methods */ - PyRestorePacket_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)PyRestorePacket_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ -}; - -/** - * The PyIOPacket type - */ -typedef struct { - PyObject_HEAD uint16_t func; /* Function code */ - int32_t count; /* Read/Write count */ - int32_t flags; /* Open flags */ - int32_t mode; /* Permissions for created files */ - PyObject* buf; /* Read/Write buffer */ - const char* fname; /* Open filename */ - int32_t status; /* Return status */ - int32_t io_errno; /* Errno code */ - int32_t lerror; /* Win32 error code */ - int32_t whence; /* Lseek argument */ - int64_t offset; /* Lseek argument */ - bool win32; /* Win32 GetLastError returned */ -} PyIoPacket; - -/** - * Forward declarations of type specific functions. - */ -static void PyIoPacket_dealloc(PyIoPacket* self); -static int PyIoPacket_init(PyIoPacket* self, PyObject* args, PyObject* kwds); -static PyObject* PyIoPacket_repr(PyIoPacket* self); - -static PyMethodDef PyIoPacket_methods[] = { - {NULL} /* Sentinel */ -}; - -static PyMemberDef PyIoPacket_members[] = { - {(char*)"func", T_USHORT, offsetof(PyIoPacket, func), 0, - (char*)"Function code"}, - {(char*)"count", T_INT, offsetof(PyIoPacket, count), 0, - (char*)"Read/write count"}, - {(char*)"flags", T_INT, offsetof(PyIoPacket, flags), 0, - (char*)"Open flags"}, - {(char*)"mode", T_INT, offsetof(PyIoPacket, mode), 0, - (char*)"Permissions for created files"}, - {(char*)"buf", T_OBJECT, offsetof(PyIoPacket, buf), 0, - (char*)"Read/write buffer"}, - {(char*)"fname", T_STRING, offsetof(PyIoPacket, fname), 0, - (char*)"Open filename"}, - {(char*)"status", T_INT, offsetof(PyIoPacket, status), 0, - (char*)"Return status"}, - {(char*)"io_errno", T_INT, offsetof(PyIoPacket, io_errno), 0, - (char*)"Errno code"}, - {(char*)"lerror", T_INT, offsetof(PyIoPacket, lerror), 0, - (char*)"Win32 error code"}, - {(char*)"whence", T_INT, offsetof(PyIoPacket, whence), 0, - (char*)"Lseek argument"}, - {(char*)"offset", T_LONGLONG, offsetof(PyIoPacket, offset), 0, - (char*)"Lseek argument"}, - {(char*)"win32", T_BOOL, offsetof(PyIoPacket, win32), 0, - (char*)"Win32 GetLastError returned"}, - {NULL}}; - -static PyTypeObject PyIoPacketType = { - PyVarObject_HEAD_INIT(NULL, 0) "io_pkt", /* tp_name */ - sizeof(PyIoPacket), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)PyIoPacket_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - (reprfunc)PyIoPacket_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/ - "io_pkt object", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - PyIoPacket_methods, /* tp_methods */ - PyIoPacket_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)PyIoPacket_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ -}; - -/** - * The PyAclPacket type - */ -typedef struct { - PyObject_HEAD const char* fname; /* Filename */ - PyObject* content; /* ACL content */ -} PyAclPacket; - -/** - * Forward declarations of type specific functions. - */ -static void PyAclPacket_dealloc(PyAclPacket* self); -static int PyAclPacket_init(PyAclPacket* self, PyObject* args, PyObject* kwds); -static PyObject* PyAclPacket_repr(PyAclPacket* self); - -static PyMethodDef PyAclPacket_methods[] = { - {NULL} /* Sentinel */ -}; - -static PyMemberDef PyAclPacket_members[] = { - {(char*)"fname", T_STRING, offsetof(PyAclPacket, fname), 0, - (char*)"Filename"}, - {(char*)"content", T_OBJECT, offsetof(PyAclPacket, content), 0, - (char*)"ACL content buffer"}, - {NULL}}; - -static PyTypeObject PyAclPacketType = { - PyVarObject_HEAD_INIT(NULL, 0) "acl_pkt", /* tp_name */ - sizeof(PyAclPacket), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)PyAclPacket_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - (reprfunc)PyAclPacket_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/ - "acl_pkt object", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - PyAclPacket_methods, /* tp_methods */ - PyAclPacket_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)PyAclPacket_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ -}; - -/** - * The PyXattrPacket type - */ -typedef struct { - PyObject_HEAD const char* fname; /* Filename */ - PyObject* name; /* XATTR name */ - PyObject* value; /* XATTR value */ -} PyXattrPacket; - -/** - * Forward declarations of type specific functions. - */ -static void PyXattrPacket_dealloc(PyXattrPacket* self); -static int PyXattrPacket_init(PyXattrPacket* self, - PyObject* args, - PyObject* kwds); -static PyObject* PyXattrPacket_repr(PyXattrPacket* self); - -static PyMethodDef PyXattrPacket_methods[] = { - {NULL} /* Sentinel */ -}; - -static PyMemberDef PyXattrPacket_members[] = { - {(char*)"fname", T_STRING, offsetof(PyXattrPacket, fname), 0, - (char*)"Filename"}, - {(char*)"name", T_OBJECT, offsetof(PyXattrPacket, name), 0, - (char*)"XATTR name buffer"}, - {(char*)"value", T_OBJECT, offsetof(PyXattrPacket, value), 0, - (char*)"XATTR value buffer"}, - {NULL}}; - -static PyTypeObject PyXattrPacketType = { - PyVarObject_HEAD_INIT(NULL, 0) "xattr_pkt", /* tp_name */ - sizeof(PyXattrPacket), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)PyXattrPacket_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - (reprfunc)PyXattrPacket_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/ - "xattr_pkt object", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - PyXattrPacket_methods, /* tp_methods */ - PyXattrPacket_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)PyXattrPacket_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ -}; - -/** - * Callback methods from Python. - */ -static PyObject* PyBareosGetValue(PyObject* self, PyObject* args); -static PyObject* PyBareosSetValue(PyObject* self, PyObject* args); -static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args); -static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args); -static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args); -static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args); -static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args); -static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args); -static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args); -static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args); -static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args); -static PyObject* PyBareosAddWild(PyObject* self, PyObject* args); -static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args); -static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args); -static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args); -static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args); -static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args); -static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args); -static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args); - -static PyMethodDef Methods[] = { - {"GetValue", PyBareosGetValue, METH_VARARGS, "Get a Plugin value"}, - {"SetValue", PyBareosSetValue, METH_VARARGS, "Set a Plugin value"}, - {"DebugMessage", PyBareosDebugMessage, METH_VARARGS, - "Print a Debug message"}, - {"JobMessage", PyBareosJobMessage, METH_VARARGS, "Print a Job message"}, - {"RegisterEvents", PyBareosRegisterEvents, METH_VARARGS, - "Register Plugin Events"}, - {"UnRegisterEvents", PyBareosUnRegisterEvents, METH_VARARGS, - "Unregister Plugin Events"}, - {"GetInstanceCount", PyBareosGetInstanceCount, METH_VARARGS, - "Get number of instances of current plugin"}, - {"AddExclude", PyBareosAddExclude, METH_VARARGS, "Add Exclude pattern"}, - {"AddInclude", PyBareosAddInclude, METH_VARARGS, "Add Include pattern"}, - {"AddOptions", PyBareosAddOptions, METH_VARARGS, "Add Include options"}, - {"AddRegex", PyBareosAddRegex, METH_VARARGS, "Add regex"}, - {"AddWild", PyBareosAddWild, METH_VARARGS, "Add wildcard"}, - {"NewOptions", PyBareosNewOptions, METH_VARARGS, "Add new option block"}, - {"NewInclude", PyBareosNewInclude, METH_VARARGS, "Add new include block"}, - {"NewPreInclude", PyBareosNewPreInclude, METH_VARARGS, - "Add new pre include block"}, - {"CheckChanges", PyBareosCheckChanges, METH_VARARGS, - "Check if a file have to be backed up using Accurate code"}, - {"AcceptFile", PyBareosAcceptFile, METH_VARARGS, - "Check if a file would be saved using current Include/Exclude code"}, - {"SetSeenBitmap", PyBareosSetSeenBitmap, METH_VARARGS, - "Set bit in the Accurate Seen bitmap"}, - {"ClearSeenBitmap", PyBareosClearSeenBitmap, METH_VARARGS, - "Clear bit in the Accurate Seen bitmap"}, - {NULL, NULL, 0, NULL}}; - - } /* namespace filedaemon */ -using namespace filedaemon; - -/* variables storing bareos pointers */ -static void* bareos_PluginContext = NULL; -static void* bareos_core_functions = NULL; - -#ifdef __cplusplus -extern "C" { -#endif -/* Forward declaration of loadPlugin() as it is stored in Capsule */ -bRC loadPlugin(::Core_PluginApiDefinition* lbareos_plugin_interface_version, - BareosCoreFunctions* lbareos_core_functions, - PluginInformation** plugin_information, - pFuncs** plugin_functions); -#ifdef __cplusplus -} -#endif - - -MOD_INIT(bareosfd) -{ - PyObject* m = NULL; - MOD_DEF(m, PYTHON_MODULE_NAME_QUOTED, NULL, Methods) - - - /* add PluginContext Capsule */ - PyObject* PyModulePluginContext = - PyCapsule_New((void*)&bareos_PluginContext, - PYTHON_MODULE_NAME_QUOTED ".PluginContext", NULL); - if (!PyModulePluginContext) { - printf(PYTHON_MODULE_NAME_QUOTED ":PluginContext PyCapsule_New failed\n"); - return MOD_ERROR_VAL; - } - if (PyModulePluginContext) { - PyModule_AddObject(m, "PluginContext", PyModulePluginContext); - printf(PYTHON_MODULE_NAME_QUOTED ": added PluginContext@%p\n", - &bareos_PluginContext); - } else { - printf(PYTHON_MODULE_NAME_QUOTED - ":PluginContext PyModule_AddObject failed\n"); - return MOD_ERROR_VAL; - } - - /* add bpFuncs Capsule */ - PyObject* PyModulePluginFuncs = - PyCapsule_New((void*)&bareos_core_functions, - PYTHON_MODULE_NAME_QUOTED ".BareosCoreFunctions", NULL); - if (!PyModulePluginFuncs) { - printf(PYTHON_MODULE_NAME_QUOTED - ":BareosCoreFunctions PyCapsule_New failed\n"); - return MOD_ERROR_VAL; - } - if (PyModulePluginFuncs) { - PyModule_AddObject(m, "BareosCoreFunctions", PyModulePluginFuncs); - printf(PYTHON_MODULE_NAME_QUOTED ": added BareosCoreFunctions@%p\n", - &bareos_core_functions); - } else { - printf(PYTHON_MODULE_NAME_QUOTED - ":BareosCoreFunctions PyModule_AddObject failed\n"); - return MOD_ERROR_VAL; - } - - /* add loadPlugin Capsule */ - PyObject* PyModuleLoadPlugin = PyCapsule_New( - (void*)&loadPlugin, PYTHON_MODULE_NAME_QUOTED ".loadPlugin", NULL); - if (!PyModuleLoadPlugin) { - printf(PYTHON_MODULE_NAME_QUOTED "loadPlugin PyCapsule_New failed\n"); - return MOD_ERROR_VAL; - } - if (PyModuleLoadPlugin) { - PyModule_AddObject(m, "loadPlugin", PyModuleLoadPlugin); - printf(PYTHON_MODULE_NAME_QUOTED ": added loadPlugin@%p\n", &loadPlugin); - } else { - printf(PYTHON_MODULE_NAME_QUOTED "loadPlugin PyModule_AddObject failed\n"); - return MOD_ERROR_VAL; - } - - - PyRestoreObjectType.tp_new = PyType_GenericNew; - if (PyType_Ready(&PyRestoreObjectType) < 0) { return MOD_ERROR_VAL; } - - PyStatPacketType.tp_new = PyType_GenericNew; - if (PyType_Ready(&PyStatPacketType) < 0) { return MOD_ERROR_VAL; } - - PySavePacketType.tp_new = PyType_GenericNew; - if (PyType_Ready(&PySavePacketType) < 0) { return MOD_ERROR_VAL; } - - PyRestorePacketType.tp_new = PyType_GenericNew; - if (PyType_Ready(&PyRestorePacketType) < 0) { return MOD_ERROR_VAL; } - - PyIoPacketType.tp_new = PyType_GenericNew; - if (PyType_Ready(&PyIoPacketType) < 0) { return MOD_ERROR_VAL; } - - PyAclPacketType.tp_new = PyType_GenericNew; - if (PyType_Ready(&PyAclPacketType) < 0) { return MOD_ERROR_VAL; } - - PyXattrPacketType.tp_new = PyType_GenericNew; - if (PyType_Ready(&PyXattrPacketType) < 0) { return MOD_ERROR_VAL; } - - Py_INCREF(&PyRestoreObjectType); - PyModule_AddObject(m, "RestoreObject", (PyObject*)&PyRestoreObjectType); - - Py_INCREF(&PyStatPacketType); - PyModule_AddObject(m, "StatPacket", (PyObject*)&PyStatPacketType); - - Py_INCREF(&PySavePacketType); - PyModule_AddObject(m, "SavePacket", (PyObject*)&PySavePacketType); - - Py_INCREF(&PyRestorePacketType); - PyModule_AddObject(m, "RestorePacket", (PyObject*)&PyRestorePacketType); - - Py_INCREF(&PyIoPacketType); - PyModule_AddObject(m, "IoPacket", (PyObject*)&PyIoPacketType); - - Py_INCREF(&PyAclPacketType); - PyModule_AddObject(m, "AclPacket", (PyObject*)&PyAclPacketType); - - Py_INCREF(&PyXattrPacketType); - PyModule_AddObject(m, "XattrPacket", (PyObject*)&PyXattrPacketType); - - - /* module dictionaries */ - DEFINE_bRCs_DICT(); - DEFINE_bJobMessageTypes_DICT(); - - const char* bVariable = "bVariable"; - PyObject* pDictbVariable = NULL; - pDictbVariable = PyDict_New(); - if (!pDictbVariable) { return MOD_ERROR_VAL; } - ConstSet_StrLong(pDictbVariable, bVarJobId, 1); - ConstSet_StrLong(pDictbVariable, bVarFDName, 2); - ConstSet_StrLong(pDictbVariable, bVarLevel, 3); - ConstSet_StrLong(pDictbVariable, bVarType, 4); - ConstSet_StrLong(pDictbVariable, bVarClient, 5); - ConstSet_StrLong(pDictbVariable, bVarJobName, 6); - ConstSet_StrLong(pDictbVariable, bVarJobStatus, 7); - ConstSet_StrLong(pDictbVariable, bVarSinceTime, 8); - ConstSet_StrLong(pDictbVariable, bVarAccurate, 9); - ConstSet_StrLong(pDictbVariable, bVarFileSeen, 10); - ConstSet_StrLong(pDictbVariable, bVarVssClient, 11); - ConstSet_StrLong(pDictbVariable, bVarWorkingDir, 12); - ConstSet_StrLong(pDictbVariable, bVarWhere, 13); - ConstSet_StrLong(pDictbVariable, bVarRegexWhere, 14); - ConstSet_StrLong(pDictbVariable, bVarExePath, 15); - ConstSet_StrLong(pDictbVariable, bVarVersion, 16); - ConstSet_StrLong(pDictbVariable, bVarDistName, 17); - ConstSet_StrLong(pDictbVariable, bVarPrevJobName, 18); - ConstSet_StrLong(pDictbVariable, bVarPrefixLinks, 19); - if (PyModule_AddObject(m, bVariable, pDictbVariable)) { - return MOD_ERROR_VAL; - } - - - const char* bFileType = "bFileType"; - PyObject* pDictbFileType = NULL; - pDictbFileType = PyDict_New(); - ConstSet_StrLong(pDictbFileType, FT_LNKSAVED, 1); - ConstSet_StrLong(pDictbFileType, FT_REGE, 2); - ConstSet_StrLong(pDictbFileType, FT_REG, 3); - ConstSet_StrLong(pDictbFileType, FT_LNK, 4); - ConstSet_StrLong(pDictbFileType, FT_DIREND, 5); - ConstSet_StrLong(pDictbFileType, FT_SPEC, 6); - ConstSet_StrLong(pDictbFileType, FT_NOACCESS, 7); - ConstSet_StrLong(pDictbFileType, FT_NOFOLLOW, 8); - ConstSet_StrLong(pDictbFileType, FT_NOSTAT, 9); - ConstSet_StrLong(pDictbFileType, FT_NOCHG, 10); - ConstSet_StrLong(pDictbFileType, FT_DIRNOCHG, 11); - ConstSet_StrLong(pDictbFileType, FT_ISARCH, 12); - ConstSet_StrLong(pDictbFileType, FT_NORECURSE, 13); - ConstSet_StrLong(pDictbFileType, FT_NOFSCHG, 14); - ConstSet_StrLong(pDictbFileType, FT_NOOPEN, 15); - ConstSet_StrLong(pDictbFileType, FT_RAW, 16); - ConstSet_StrLong(pDictbFileType, FT_FIFO, 17); - ConstSet_StrLong(pDictbFileType, FT_DIRBEGIN, 18); - ConstSet_StrLong(pDictbFileType, FT_INVALIDFS, 19); - ConstSet_StrLong(pDictbFileType, FT_INVALIDDT, 20); - ConstSet_StrLong(pDictbFileType, FT_REPARSE, 21); - ConstSet_StrLong(pDictbFileType, FT_PLUGIN, 22); - ConstSet_StrLong(pDictbFileType, FT_DELETED, 23); - ConstSet_StrLong(pDictbFileType, FT_BASE, 24); - ConstSet_StrLong(pDictbFileType, FT_RESTORE_FIRST, 25); - ConstSet_StrLong(pDictbFileType, FT_JUNCTION, 26); - ConstSet_StrLong(pDictbFileType, FT_PLUGIN_CONFIG, 27); - ConstSet_StrLong(pDictbFileType, FT_PLUGIN_CONFIG_FILLED, 28); - if (!pDictbFileType) { return MOD_ERROR_VAL; } - if (PyModule_AddObject(m, bFileType, pDictbFileType)) { - return MOD_ERROR_VAL; - } - - - const char* bCFs = "bCFs"; - PyObject* pDictbCFs = NULL; - pDictbCFs = PyDict_New(); - ConstSet_StrLong(pDictbCFs, CF_SKIP, 1); - ConstSet_StrLong(pDictbCFs, CF_ERROR, 2); - ConstSet_StrLong(pDictbCFs, CF_EXTRACT, 3); - ConstSet_StrLong(pDictbCFs, CF_CREATED, 4); - ConstSet_StrLong(pDictbCFs, CF_CORE, 5); - if (!pDictbCFs) { return MOD_ERROR_VAL; } - if (PyModule_AddObject(m, bCFs, pDictbCFs)) { return MOD_ERROR_VAL; } - - const char* bEventType = "bEventType"; - PyObject* pDictbEventType = NULL; - pDictbEventType = PyDict_New(); - ConstSet_StrLong(pDictbEventType, bEventJobStart, 1); - ConstSet_StrLong(pDictbEventType, bEventJobEnd, 2); - ConstSet_StrLong(pDictbEventType, bEventStartBackupJob, 3); - ConstSet_StrLong(pDictbEventType, bEventEndBackupJob, 4); - ConstSet_StrLong(pDictbEventType, bEventStartRestoreJob, 5); - ConstSet_StrLong(pDictbEventType, bEventEndRestoreJob, 6); - ConstSet_StrLong(pDictbEventType, bEventStartVerifyJob, 7); - ConstSet_StrLong(pDictbEventType, bEventEndVerifyJob, 8); - ConstSet_StrLong(pDictbEventType, bEventBackupCommand, 9); - ConstSet_StrLong(pDictbEventType, bEventRestoreCommand, 10); - ConstSet_StrLong(pDictbEventType, bEventEstimateCommand, 11); - ConstSet_StrLong(pDictbEventType, bEventLevel, 12); - ConstSet_StrLong(pDictbEventType, bEventSince, 13); - ConstSet_StrLong(pDictbEventType, bEventCancelCommand, 14); - ConstSet_StrLong(pDictbEventType, bEventRestoreObject, 15); - ConstSet_StrLong(pDictbEventType, bEventEndFileSet, 16); - ConstSet_StrLong(pDictbEventType, bEventPluginCommand, 17); - ConstSet_StrLong(pDictbEventType, bEventOptionPlugin, 18); - ConstSet_StrLong(pDictbEventType, bEventHandleBackupFile, 19); - ConstSet_StrLong(pDictbEventType, bEventNewPluginOptions, 20); - ConstSet_StrLong(pDictbEventType, bEventVssInitializeForBackup, 21); - ConstSet_StrLong(pDictbEventType, bEventVssInitializeForRestore, 22); - ConstSet_StrLong(pDictbEventType, bEventVssSetBackupState, 23); - ConstSet_StrLong(pDictbEventType, bEventVssPrepareForBackup, 24); - ConstSet_StrLong(pDictbEventType, bEventVssBackupAddComponents, 25); - ConstSet_StrLong(pDictbEventType, bEventVssPrepareSnapshot, 26); - ConstSet_StrLong(pDictbEventType, bEventVssCreateSnapshots, 27); - ConstSet_StrLong(pDictbEventType, bEventVssRestoreLoadComponentMetadata, 28); - ConstSet_StrLong(pDictbEventType, bEventVssRestoreSetComponentsSelected, 29); - ConstSet_StrLong(pDictbEventType, bEventVssCloseRestore, 30); - ConstSet_StrLong(pDictbEventType, bEventVssBackupComplete, 31); - if (!pDictbEventType) { return MOD_ERROR_VAL; } - if (PyModule_AddObject(m, bEventType, pDictbEventType)) { - return MOD_ERROR_VAL; - } - - - const char* bIOPS = "bIOPS"; - PyObject* pDictbIOPS = NULL; - pDictbIOPS = PyDict_New(); - ConstSet_StrLong(pDictbIOPS, IO_OPEN, 1); - ConstSet_StrLong(pDictbIOPS, IO_READ, 2); - ConstSet_StrLong(pDictbIOPS, IO_WRITE, 3); - ConstSet_StrLong(pDictbIOPS, IO_CLOSE, 4); - ConstSet_StrLong(pDictbIOPS, IO_SEEK, 5); - if (!pDictbIOPS) { return MOD_ERROR_VAL; } - if (PyModule_AddObject(m, bIOPS, pDictbIOPS)) { return MOD_ERROR_VAL; } - - - const char* bLevels = "bLevels"; - PyObject* pDictbLevels = NULL; - pDictbLevels = PyDict_New(); - ConstSet_StrStr(pDictbLevels, L_FULL, "F"); - ConstSet_StrStr(pDictbLevels, L_INCREMENTAL, "I"); - ConstSet_StrStr(pDictbLevels, L_DIFFERENTIAL, "D"); - ConstSet_StrStr(pDictbLevels, L_SINCE, "S"); - ConstSet_StrStr(pDictbLevels, L_VERIFY_CATALOG, "C"); - ConstSet_StrStr(pDictbLevels, L_VERIFY_INIT, "V"); - ConstSet_StrStr(pDictbLevels, L_VERIFY_VOLUME_TO_CATALOG, "O"); - ConstSet_StrStr(pDictbLevels, L_VERIFY_DISK_TO_CATALOG, "d"); - ConstSet_StrStr(pDictbLevels, L_VERIFY_DATA, "A"); - ConstSet_StrStr(pDictbLevels, L_BASE, "B"); - ConstSet_StrStr(pDictbLevels, L_NONE, " "); - ConstSet_StrStr(pDictbLevels, L_VIRTUAL_FULL, "f"); - if (!pDictbLevels) { return MOD_ERROR_VAL; } - if (PyModule_AddObject(m, bLevels, pDictbLevels)) { return MOD_ERROR_VAL; } - - - return MOD_SUCCESS_VAL(m); -} - - #endif /* BAREOS_PLUGINS_FILED_PYTHON_FD_H_ */ diff --git a/core/src/plugins/python_plugins_common.inc b/core/src/plugins/python_plugins_common.inc index 4a3baa874a4..89dcba4b632 100644 --- a/core/src/plugins/python_plugins_common.inc +++ b/core/src/plugins/python_plugins_common.inc @@ -180,7 +180,6 @@ static void StorePluginContextInPythonModule(PluginContext* bareos_plugin_ctx) printf(PYTHON_MODULE_NAME_QUOTED ": could not get bareosfd_PluginContext from module\n"); } } - static PluginContext* GetPluginContextFromPythonModule() { const char* capsule_name = PYTHON_MODULE_NAME_QUOTED ".PluginContext"; From 650cf651f4733aa0223a3c3bf5a286366fb77bcf Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 8 May 2020 12:34:47 +0200 Subject: [PATCH 083/341] python-fd: python-fd-module-tester cleanup --- .../src/plugins/filed/python/test/python-fd-module-tester.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index 4cf4ae30ceb..608a62b6303 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -211,11 +211,6 @@ int main(int argc, char* argv[]) *(void**)ctx_from_bareosfd_module = &bareos_PluginContext; *(void**)bareos_core_functions_from_bareosfd_module = &bareos_core_functions; - /* call loadPlugin in plugin */ - filedaemon::Core_PluginApiDefinition myInfo; - PluginInformation plugin_information; - filedaemon::pFuncs plugin_functions; - printf("ctx_from_bareosfd_module contains %p\n", *(void**)ctx_from_bareosfd_module); From 76019f7452d2f2bcf7163936f604e1334bd00f9a Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 8 May 2020 13:19:58 +0200 Subject: [PATCH 084/341] bareosfd.cc and .h: cleanup --- core/src/plugins/filed/python/bareosfd.cc | 38 ----------------------- core/src/plugins/filed/python/bareosfd.h | 20 ------------ 2 files changed, 58 deletions(-) diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index d09d9244ca7..30345df8d90 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -90,44 +90,6 @@ static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; /* functions common to all plugins */ #include "plugins/python_plugins_common.inc" -static void PyErrorHandler() -{ - PyObject *type, *value, *traceback; - PyObject* tracebackModule; - char* error_string; - - PyErr_Fetch(&type, &value, &traceback); - - tracebackModule = PyImport_ImportModule("traceback"); - if (tracebackModule != NULL) { - PyObject *tbList, *emptyString, *strRetval; - - tbList = - PyObject_CallMethod(tracebackModule, (char*)"format_exception", - (char*)"OOO", type, value == NULL ? Py_None : value, - traceback == NULL ? Py_None : traceback); - - emptyString = PyString_FromString(""); - strRetval = - PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); - - error_string = strdup(PyString_AsString(strRetval)); - - Py_DECREF(tbList); - Py_DECREF(emptyString); - Py_DECREF(strRetval); - Py_DECREF(tracebackModule); - } else { - error_string = strdup("Unable to import traceback module."); - } - Py_DECREF(type); - Py_XDECREF(value); - Py_XDECREF(traceback); - printf("%s", error_string); - - free(error_string); - exit(1); -} /* set the bareos_core_functions pointer to the given value */ static bRC set_bareos_core_functions( diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/bareosfd.h index 0e7493ccf1c..b948f13db94 100644 --- a/core/src/plugins/filed/python/bareosfd.h +++ b/core/src/plugins/filed/python/bareosfd.h @@ -45,26 +45,6 @@ namespace filedaemon { -/** - * This defines the arguments that the plugin parser understands. - */ -enum plugin_argument_type -{ - argument_none, - argument_module_path, - argument_module_name -}; - -struct plugin_argument { - const char* name; - enum plugin_argument_type type; -}; - -static plugin_argument plugin_arguments[] = { - {"module_path", argument_module_path}, - {"module_name", argument_module_name}, - {NULL, argument_none}}; - /** * Python structures mapping C++ ones. */ From 761f96fd701fdbd153316a22f4b658abcf034905 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 8 May 2020 13:28:04 +0200 Subject: [PATCH 085/341] bareosfd.cc: introduced Bareosfd_set_plugin_context() --- core/src/plugins/filed/python/bareosfd.cc | 7 +++++++ core/src/plugins/filed/python/bareosfd.h | 10 +++++----- core/src/plugins/filed/python/bareosfd_api_funcs.txt | 4 +++- core/src/plugins/filed/python/capi_1.inc | 11 ++++++++--- core/src/plugins/filed/python/capi_2.inc | 2 ++ core/src/plugins/filed/python/capi_3.inc | 1 + 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 30345df8d90..9fd0fe0b8a3 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -99,6 +99,13 @@ static bRC set_bareos_core_functions( return bRC_OK; } +/* set the plugin context pointer to the given value */ +static bRC set_plugin_context(PluginContext* new_plugin_context) +{ + plugin_context = new_plugin_context; + return bRC_OK; +} + /** * Any plugin options which are passed in are dispatched here to a Python * method and it can parse the plugin options. This function is also called diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/bareosfd.h index b948f13db94..92a9cb722bc 100644 --- a/core/src/plugins/filed/python/bareosfd.h +++ b/core/src/plugins/filed/python/bareosfd.h @@ -740,6 +740,7 @@ static PyMethodDef Methods[] = { static bRC set_bareos_core_functions( BareosCoreFunctions* new_bareos_core_functions); +static bRC set_plugin_context(PluginContext* new_plugin_context); static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, void* value); @@ -777,7 +778,7 @@ static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, using namespace filedaemon; /* variables storing bareos pointers */ -static void* bareos_PluginContext = NULL; +static void* plugin_context = NULL; static void* bareos_core_functions = NULL; #ifdef __cplusplus @@ -807,9 +808,8 @@ MOD_INIT(bareosfd) /* add PluginContext Capsule */ - PyObject* PyModulePluginContext = - PyCapsule_New((void*)&bareos_PluginContext, - PYTHON_MODULE_NAME_QUOTED ".PluginContext", NULL); + PyObject* PyModulePluginContext = PyCapsule_New( + (void*)&plugin_context, PYTHON_MODULE_NAME_QUOTED ".PluginContext", NULL); if (!PyModulePluginContext) { printf(PYTHON_MODULE_NAME_QUOTED ":PluginContext PyCapsule_New failed\n"); return MOD_ERROR_VAL; @@ -817,7 +817,7 @@ MOD_INIT(bareosfd) if (PyModulePluginContext) { PyModule_AddObject(m, "PluginContext", PyModulePluginContext); printf(PYTHON_MODULE_NAME_QUOTED ": added PluginContext@%p\n", - &bareos_PluginContext); + &plugin_context); } else { printf(PYTHON_MODULE_NAME_QUOTED ":PluginContext PyModule_AddObject failed\n"); diff --git a/core/src/plugins/filed/python/bareosfd_api_funcs.txt b/core/src/plugins/filed/python/bareosfd_api_funcs.txt index f9b79fc0688..6a41de55d5a 100644 --- a/core/src/plugins/filed/python/bareosfd_api_funcs.txt +++ b/core/src/plugins/filed/python/bareosfd_api_funcs.txt @@ -16,4 +16,6 @@ bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, struct restore_object_pkt* rop); bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); -bRC set_bareos_core_functions(BareosCoreFunctions* new_bareos_core_functions); +bRC set_bareos_core_functions(BareosCoreFunctions* new_bareos_core_functions); +bRC set_plugin_context(PluginContext* new_plugin_context); + diff --git a/core/src/plugins/filed/python/capi_1.inc b/core/src/plugins/filed/python/capi_1.inc index 2dce9fe71ca..3b64a2b4901 100644 --- a/core/src/plugins/filed/python/capi_1.inc +++ b/core/src/plugins/filed/python/capi_1.inc @@ -90,10 +90,15 @@ #define Bareosfd_PyHandleBackupFile_RETURN bRC #define Bareosfd_PyHandleBackupFile_PROTO (PluginContext* bareos_plugin_ctx, struct save_pkt* sp) -/* static bRC set_bareos_core_functions(BareosCoreFunctions* new_bareos_core_functions); */ +/* static bRC set_bareos_core_functions(BareosCoreFunctions* new_bareos_core_functions); */ #define Bareosfd_set_bareos_core_functions_NUM 18 #define Bareosfd_set_bareos_core_functions_RETURN bRC -#define Bareosfd_set_bareos_core_functions_PROTO (BareosCoreFunctions* new_bareos_core_functions ) +#define Bareosfd_set_bareos_core_functions_PROTO (BareosCoreFunctions* new_bareos_core_functions) + +/* static bRC set_plugin_context(PluginContext* new_plugin_context); */ +#define Bareosfd_set_plugin_context_NUM 19 +#define Bareosfd_set_plugin_context_RETURN bRC +#define Bareosfd_set_plugin_context_PROTO (PluginContext* new_plugin_context) /*Total Number of C API function pointers */ -#define Bareosfd_API_pointers 19 +#define Bareosfd_API_pointers 20 diff --git a/core/src/plugins/filed/python/capi_2.inc b/core/src/plugins/filed/python/capi_2.inc index 5cffa65680a..55cbf75ca27 100644 --- a/core/src/plugins/filed/python/capi_2.inc +++ b/core/src/plugins/filed/python/capi_2.inc @@ -36,3 +36,5 @@ #define Bareosfd_set_bareos_core_functions (*(Bareosfd_set_bareos_core_functions_RETURN(*)Bareosfd_set_bareos_core_functions_PROTO) Bareosfd_API[Bareosfd_set_bareos_core_functions_NUM]) +#define Bareosfd_set_plugin_context (*(Bareosfd_set_plugin_context_RETURN(*)Bareosfd_set_plugin_context_PROTO) Bareosfd_API[Bareosfd_set_plugin_context_NUM]) + diff --git a/core/src/plugins/filed/python/capi_3.inc b/core/src/plugins/filed/python/capi_3.inc index aea83ca87de..27226b75953 100644 --- a/core/src/plugins/filed/python/capi_3.inc +++ b/core/src/plugins/filed/python/capi_3.inc @@ -17,3 +17,4 @@ Bareosfd_API[Bareosfd_PyRestoreObjectData_NUM] = (void*)PyRestoreObjectData; Bareosfd_API[Bareosfd_PyHandleBackupFile_NUM] = (void*)PyHandleBackupFile; Bareosfd_API[Bareosfd_set_bareos_core_functions_NUM] = (void*)set_bareos_core_functions; + Bareosfd_API[Bareosfd_set_plugin_context_NUM] = (void*)set_plugin_context; From 9481a87c243f485030e64fb92ccdc9faad16625c Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 8 May 2020 13:42:22 +0200 Subject: [PATCH 086/341] python plugins: renamed bareos_plugin_ctx -> plugin_ctx --- core/src/plugins/dird/python/bareosdir.cc | 155 +++++------ core/src/plugins/dird/python/python-dir.cc | 155 +++++------ core/src/plugins/filed/python/bareosfd.cc | 291 +++++++++----------- core/src/plugins/filed/python/bareosfd.h | 4 +- core/src/plugins/filed/python/python-fd.cc | 223 +++++++-------- core/src/plugins/python_plugins_common.h | 10 +- core/src/plugins/stored/python/python-sd.cc | 161 ++++++----- 7 files changed, 475 insertions(+), 524 deletions(-) diff --git a/core/src/plugins/dird/python/bareosdir.cc b/core/src/plugins/dird/python/bareosdir.cc index c4cd6865e79..2f5e007f086 100644 --- a/core/src/plugins/dird/python/bareosdir.cc +++ b/core/src/plugins/dird/python/bareosdir.cc @@ -58,32 +58,31 @@ static const int debuglevel = 150; /* Forward referenced functions */ -static bRC newPlugin(PluginContext* bareos_plugin_ctx); -static bRC freePlugin(PluginContext* bareos_plugin_ctx); -static bRC getPluginValue(PluginContext* bareos_plugin_ctx, +static bRC newPlugin(PluginContext* plugin_ctx); +static bRC freePlugin(PluginContext* plugin_ctx); +static bRC getPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); -static bRC setPluginValue(PluginContext* bareos_plugin_ctx, +static bRC setPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); -static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, +static bRC handlePluginEvent(PluginContext* plugin_ctx, bDirEvent* event, void* value); -static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, +static bRC parse_plugin_definition(PluginContext* plugin_ctx, void* value, PoolMem& plugin_options); -static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); -static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); -static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, - void* value); -static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, +static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); +static bRC PyLoadModule(PluginContext* plugin_ctx, void* value); +static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); +static bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); -static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, +static bRC PySetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); -static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, bDirEvent* event, void* value); @@ -187,14 +186,14 @@ bRC unloadPlugin() #endif /* Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(PluginContext* bareos_plugin_ctx) +static bRC newPlugin(PluginContext* plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = (struct plugin_private_context*)malloc( sizeof(struct plugin_private_context)); if (!plugin_priv_ctx) { return bRC_Error; } memset(plugin_priv_ctx, 0, sizeof(struct plugin_private_context)); - bareos_plugin_ctx->plugin_private_context = + plugin_ctx->plugin_private_context = (void*)plugin_priv_ctx; /* set our context pointer */ /* For each plugin instance we instantiate a new Python interpreter. */ @@ -206,17 +205,17 @@ static bRC newPlugin(PluginContext* bareos_plugin_ctx) * Always register some events the python plugin itself can register * any other events it is interested in. */ - bareos_core_functions->registerBareosEvents(bareos_plugin_ctx, 1, + bareos_core_functions->registerBareosEvents(plugin_ctx, 1, bDirEventNewPluginOptions); return bRC_OK; } /* Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(PluginContext* bareos_plugin_ctx) +static bRC freePlugin(PluginContext* plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { return bRC_Error; } @@ -232,13 +231,13 @@ static bRC freePlugin(PluginContext* bareos_plugin_ctx) PyEval_ReleaseLock(); free(plugin_priv_ctx); - bareos_plugin_ctx->plugin_private_context = NULL; + plugin_ctx->plugin_private_context = NULL; return bRC_OK; } -static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, +static bRC handlePluginEvent(PluginContext* plugin_ctx, bDirEvent* event, void* value) { @@ -246,7 +245,7 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, bool event_dispatched = false; PoolMem plugin_options(PM_FNAME); plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } @@ -257,8 +256,7 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, switch (event->eventType) { case bDirEventNewPluginOptions: event_dispatched = true; - retval = - parse_plugin_definition(bareos_plugin_ctx, value, plugin_options); + retval = parse_plugin_definition(plugin_ctx, value, plugin_options); break; default: break; @@ -283,13 +281,12 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, * See if we already loaded the Python modules. */ if (!plugin_priv_ctx->python_loaded) { - retval = PyLoadModule(bareos_plugin_ctx, plugin_options.c_str()); + retval = PyLoadModule(plugin_ctx, plugin_options.c_str()); } /* Only try to call when the loading succeeded. */ if (retval == bRC_OK) { - retval = PyParsePluginDefinition(bareos_plugin_ctx, - plugin_options.c_str()); + retval = PyParsePluginDefinition(plugin_ctx, plugin_options.c_str()); } break; default: @@ -299,7 +296,7 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, * that time we pretend the call succeeded. */ if (plugin_priv_ctx->python_loaded) { - retval = PyHandlePluginEvent(bareos_plugin_ctx, event, value); + retval = PyHandlePluginEvent(plugin_ctx, event, value); } else { retval = bRC_OK; } @@ -321,7 +318,7 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, * * python:module_path=:module_name=:... */ -static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, +static bRC parse_plugin_definition(PluginContext* plugin_ctx, void* value, PoolMem& plugin_options) { @@ -330,7 +327,7 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, PoolMem plugin_definition(PM_FNAME); char *bp, *argument, *argument_value; plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (plugin_private_context*)plugin_ctx->plugin_private_context; if (!value) { return bRC_Error; } @@ -342,11 +339,9 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, bp = strchr(plugin_definition.c_str(), ':'); if (!bp) { - Jmsg(bareos_plugin_ctx, M_FATAL, - "python-dir: Illegal plugin definition %s\n", + Jmsg(plugin_ctx, M_FATAL, "python-dir: Illegal plugin definition %s\n", plugin_definition.c_str()); - Dmsg(bareos_plugin_ctx, debuglevel, - "python-dir: Illegal plugin definition %s\n", + Dmsg(plugin_ctx, debuglevel, "python-dir: Illegal plugin definition %s\n", plugin_definition.c_str()); goto bail_out; } @@ -370,9 +365,9 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, argument = bp; argument_value = strchr(bp, '='); if (!argument_value) { - Jmsg(bareos_plugin_ctx, M_FATAL, + Jmsg(plugin_ctx, M_FATAL, "python-dir: Illegal argument %s without value\n", argument); - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: Illegal argument %s without value\n", argument); goto bail_out; } @@ -465,11 +460,11 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, * module path and the module to load. We also load the dictionary used * for looking up the Python methods. */ -static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) +static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject *sysPath, *mPath, *pName, *pFunc; /* @@ -492,7 +487,7 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) * Try to load the Python module by name. */ if (plugin_priv_ctx->module_name) { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: Trying to load module with name %s\n", plugin_priv_ctx->module_name); pName = PyString_FromString(plugin_priv_ctx->module_name); @@ -500,13 +495,13 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) Py_DECREF(pName); if (!plugin_priv_ctx->pModule) { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: Failed to load module with name %s\n", plugin_priv_ctx->module_name); goto bail_out; } - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: Successfully loaded module with name %s\n", plugin_priv_ctx->module_name); @@ -516,7 +511,7 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) plugin_priv_ctx->pyModuleFunctionsDict = PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ - StorePluginContextInPythonModule(bareos_plugin_ctx); + StorePluginContextInPythonModule(plugin_ctx); /* * Lookup the load_bareos_plugin() function in the python module. @@ -539,7 +534,7 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) Py_DECREF(pRetVal); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: Failed to find function named load_bareos_plugins()\n"); goto bail_out; } @@ -553,7 +548,7 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } @@ -564,12 +559,11 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) * PyLoadModule() has loaded the Python module and made sure things are * operational. */ -static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, - void* value) +static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -596,39 +590,39 @@ static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, return retval; } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: Failed to find function named " "parse_plugin_definition()\n"); return bRC_Error; } bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } -static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, +static bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, +static bRC PySetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, bDirEvent* event, void* value) { bRC retval = bRC_Error; plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -651,14 +645,14 @@ static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, Py_DECREF(pRetVal); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: Failed to find function named handle_plugin_event()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } @@ -670,7 +664,7 @@ static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } @@ -687,8 +681,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarSDJobStatus: { int value = 0; - if (bareos_core_functions->getBareosValue( - bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue(plugin_ctx, (brDirVariable)var, + &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } break; @@ -702,8 +696,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarReadBytes: { uint64_t value = 0; - if (bareos_core_functions->getBareosValue( - bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue(plugin_ctx, (brDirVariable)var, + &value) == bRC_OK) { pRetVal = PyLong_FromUnsignedLong(value); } break; @@ -720,8 +714,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarVolumeName: { char* value = NULL; - if (bareos_core_functions->getBareosValue( - bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue(plugin_ctx, (brDirVariable)var, + &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } } break; @@ -736,7 +730,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) break; } default: - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: PyBareosGetValue unknown variable requested %d\n", var); break; } @@ -756,7 +750,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject* pyValue; @@ -772,7 +766,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) value = PyString_AsString(pyValue); if (value) { retval = bareos_core_functions->setBareosValue( - bareos_plugin_ctx, (bwDirVariable)var, value); + plugin_ctx, (bwDirVariable)var, value); } break; @@ -784,12 +778,12 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) value = PyInt_AsLong(pyValue); if (value >= 0) { retval = bareos_core_functions->setBareosValue( - bareos_plugin_ctx, (bwDirVariable)var, &value); + plugin_ctx, (bwDirVariable)var, &value); } break; } default: - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: PyBareosSetValue unknown variable requested %d\n", var); break; } @@ -807,14 +801,14 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (dbgmsg) { Dmsg(bareos_plugin_ctx, level, "python-dir: %s", dbgmsg); } + if (dbgmsg) { Dmsg(plugin_ctx, level, "python-dir: %s", dbgmsg); } Py_INCREF(Py_None); return Py_None; @@ -829,14 +823,14 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (jobmsg) { Jmsg(bareos_plugin_ctx, type, "python-dir: %s", jobmsg); } + if (jobmsg) { Jmsg(plugin_ctx, type, "python-dir: %s", jobmsg); } Py_INCREF(Py_None); return Py_None; @@ -850,7 +844,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -869,10 +863,10 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) event = PyInt_AsLong(pyEvent); if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: PyBareosRegisterEvents registering event %d\n", event); - retval = bareos_core_functions->registerBareosEvents(bareos_plugin_ctx, 1, - event); + retval = + bareos_core_functions->registerBareosEvents(plugin_ctx, 1, event); if (retval != bRC_OK) { break; } } @@ -892,7 +886,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -911,10 +905,10 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) event = PyInt_AsLong(pyEvent); if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "PyBareosUnRegisterEvents: registering event %d\n", event); - retval = bareos_core_functions->unregisterBareosEvents(bareos_plugin_ctx, - 1, event); + retval = + bareos_core_functions->unregisterBareosEvents(plugin_ctx, 1, event); if (retval != bRC_OK) { break; } } @@ -934,14 +928,13 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (bareos_core_functions->getInstanceCount(bareos_plugin_ctx, &value) == - bRC_OK) { + if (bareos_core_functions->getInstanceCount(plugin_ctx, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index c4cd6865e79..2f5e007f086 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -58,32 +58,31 @@ static const int debuglevel = 150; /* Forward referenced functions */ -static bRC newPlugin(PluginContext* bareos_plugin_ctx); -static bRC freePlugin(PluginContext* bareos_plugin_ctx); -static bRC getPluginValue(PluginContext* bareos_plugin_ctx, +static bRC newPlugin(PluginContext* plugin_ctx); +static bRC freePlugin(PluginContext* plugin_ctx); +static bRC getPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); -static bRC setPluginValue(PluginContext* bareos_plugin_ctx, +static bRC setPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); -static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, +static bRC handlePluginEvent(PluginContext* plugin_ctx, bDirEvent* event, void* value); -static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, +static bRC parse_plugin_definition(PluginContext* plugin_ctx, void* value, PoolMem& plugin_options); -static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); -static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); -static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, - void* value); -static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, +static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); +static bRC PyLoadModule(PluginContext* plugin_ctx, void* value); +static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); +static bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); -static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, +static bRC PySetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); -static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, bDirEvent* event, void* value); @@ -187,14 +186,14 @@ bRC unloadPlugin() #endif /* Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(PluginContext* bareos_plugin_ctx) +static bRC newPlugin(PluginContext* plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = (struct plugin_private_context*)malloc( sizeof(struct plugin_private_context)); if (!plugin_priv_ctx) { return bRC_Error; } memset(plugin_priv_ctx, 0, sizeof(struct plugin_private_context)); - bareos_plugin_ctx->plugin_private_context = + plugin_ctx->plugin_private_context = (void*)plugin_priv_ctx; /* set our context pointer */ /* For each plugin instance we instantiate a new Python interpreter. */ @@ -206,17 +205,17 @@ static bRC newPlugin(PluginContext* bareos_plugin_ctx) * Always register some events the python plugin itself can register * any other events it is interested in. */ - bareos_core_functions->registerBareosEvents(bareos_plugin_ctx, 1, + bareos_core_functions->registerBareosEvents(plugin_ctx, 1, bDirEventNewPluginOptions); return bRC_OK; } /* Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(PluginContext* bareos_plugin_ctx) +static bRC freePlugin(PluginContext* plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { return bRC_Error; } @@ -232,13 +231,13 @@ static bRC freePlugin(PluginContext* bareos_plugin_ctx) PyEval_ReleaseLock(); free(plugin_priv_ctx); - bareos_plugin_ctx->plugin_private_context = NULL; + plugin_ctx->plugin_private_context = NULL; return bRC_OK; } -static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, +static bRC handlePluginEvent(PluginContext* plugin_ctx, bDirEvent* event, void* value) { @@ -246,7 +245,7 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, bool event_dispatched = false; PoolMem plugin_options(PM_FNAME); plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } @@ -257,8 +256,7 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, switch (event->eventType) { case bDirEventNewPluginOptions: event_dispatched = true; - retval = - parse_plugin_definition(bareos_plugin_ctx, value, plugin_options); + retval = parse_plugin_definition(plugin_ctx, value, plugin_options); break; default: break; @@ -283,13 +281,12 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, * See if we already loaded the Python modules. */ if (!plugin_priv_ctx->python_loaded) { - retval = PyLoadModule(bareos_plugin_ctx, plugin_options.c_str()); + retval = PyLoadModule(plugin_ctx, plugin_options.c_str()); } /* Only try to call when the loading succeeded. */ if (retval == bRC_OK) { - retval = PyParsePluginDefinition(bareos_plugin_ctx, - plugin_options.c_str()); + retval = PyParsePluginDefinition(plugin_ctx, plugin_options.c_str()); } break; default: @@ -299,7 +296,7 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, * that time we pretend the call succeeded. */ if (plugin_priv_ctx->python_loaded) { - retval = PyHandlePluginEvent(bareos_plugin_ctx, event, value); + retval = PyHandlePluginEvent(plugin_ctx, event, value); } else { retval = bRC_OK; } @@ -321,7 +318,7 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, * * python:module_path=:module_name=:... */ -static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, +static bRC parse_plugin_definition(PluginContext* plugin_ctx, void* value, PoolMem& plugin_options) { @@ -330,7 +327,7 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, PoolMem plugin_definition(PM_FNAME); char *bp, *argument, *argument_value; plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (plugin_private_context*)plugin_ctx->plugin_private_context; if (!value) { return bRC_Error; } @@ -342,11 +339,9 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, bp = strchr(plugin_definition.c_str(), ':'); if (!bp) { - Jmsg(bareos_plugin_ctx, M_FATAL, - "python-dir: Illegal plugin definition %s\n", + Jmsg(plugin_ctx, M_FATAL, "python-dir: Illegal plugin definition %s\n", plugin_definition.c_str()); - Dmsg(bareos_plugin_ctx, debuglevel, - "python-dir: Illegal plugin definition %s\n", + Dmsg(plugin_ctx, debuglevel, "python-dir: Illegal plugin definition %s\n", plugin_definition.c_str()); goto bail_out; } @@ -370,9 +365,9 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, argument = bp; argument_value = strchr(bp, '='); if (!argument_value) { - Jmsg(bareos_plugin_ctx, M_FATAL, + Jmsg(plugin_ctx, M_FATAL, "python-dir: Illegal argument %s without value\n", argument); - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: Illegal argument %s without value\n", argument); goto bail_out; } @@ -465,11 +460,11 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, * module path and the module to load. We also load the dictionary used * for looking up the Python methods. */ -static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) +static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject *sysPath, *mPath, *pName, *pFunc; /* @@ -492,7 +487,7 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) * Try to load the Python module by name. */ if (plugin_priv_ctx->module_name) { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: Trying to load module with name %s\n", plugin_priv_ctx->module_name); pName = PyString_FromString(plugin_priv_ctx->module_name); @@ -500,13 +495,13 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) Py_DECREF(pName); if (!plugin_priv_ctx->pModule) { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: Failed to load module with name %s\n", plugin_priv_ctx->module_name); goto bail_out; } - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: Successfully loaded module with name %s\n", plugin_priv_ctx->module_name); @@ -516,7 +511,7 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) plugin_priv_ctx->pyModuleFunctionsDict = PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ - StorePluginContextInPythonModule(bareos_plugin_ctx); + StorePluginContextInPythonModule(plugin_ctx); /* * Lookup the load_bareos_plugin() function in the python module. @@ -539,7 +534,7 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) Py_DECREF(pRetVal); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: Failed to find function named load_bareos_plugins()\n"); goto bail_out; } @@ -553,7 +548,7 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } @@ -564,12 +559,11 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) * PyLoadModule() has loaded the Python module and made sure things are * operational. */ -static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, - void* value) +static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -596,39 +590,39 @@ static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, return retval; } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: Failed to find function named " "parse_plugin_definition()\n"); return bRC_Error; } bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } -static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, +static bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, +static bRC PySetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, bDirEvent* event, void* value) { bRC retval = bRC_Error; plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -651,14 +645,14 @@ static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, Py_DECREF(pRetVal); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: Failed to find function named handle_plugin_event()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } @@ -670,7 +664,7 @@ static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } @@ -687,8 +681,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarSDJobStatus: { int value = 0; - if (bareos_core_functions->getBareosValue( - bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue(plugin_ctx, (brDirVariable)var, + &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } break; @@ -702,8 +696,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarReadBytes: { uint64_t value = 0; - if (bareos_core_functions->getBareosValue( - bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue(plugin_ctx, (brDirVariable)var, + &value) == bRC_OK) { pRetVal = PyLong_FromUnsignedLong(value); } break; @@ -720,8 +714,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bDirVarVolumeName: { char* value = NULL; - if (bareos_core_functions->getBareosValue( - bareos_plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue(plugin_ctx, (brDirVariable)var, + &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } } break; @@ -736,7 +730,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) break; } default: - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: PyBareosGetValue unknown variable requested %d\n", var); break; } @@ -756,7 +750,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject* pyValue; @@ -772,7 +766,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) value = PyString_AsString(pyValue); if (value) { retval = bareos_core_functions->setBareosValue( - bareos_plugin_ctx, (bwDirVariable)var, value); + plugin_ctx, (bwDirVariable)var, value); } break; @@ -784,12 +778,12 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) value = PyInt_AsLong(pyValue); if (value >= 0) { retval = bareos_core_functions->setBareosValue( - bareos_plugin_ctx, (bwDirVariable)var, &value); + plugin_ctx, (bwDirVariable)var, &value); } break; } default: - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: PyBareosSetValue unknown variable requested %d\n", var); break; } @@ -807,14 +801,14 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (dbgmsg) { Dmsg(bareos_plugin_ctx, level, "python-dir: %s", dbgmsg); } + if (dbgmsg) { Dmsg(plugin_ctx, level, "python-dir: %s", dbgmsg); } Py_INCREF(Py_None); return Py_None; @@ -829,14 +823,14 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (jobmsg) { Jmsg(bareos_plugin_ctx, type, "python-dir: %s", jobmsg); } + if (jobmsg) { Jmsg(plugin_ctx, type, "python-dir: %s", jobmsg); } Py_INCREF(Py_None); return Py_None; @@ -850,7 +844,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -869,10 +863,10 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) event = PyInt_AsLong(pyEvent); if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-dir: PyBareosRegisterEvents registering event %d\n", event); - retval = bareos_core_functions->registerBareosEvents(bareos_plugin_ctx, 1, - event); + retval = + bareos_core_functions->registerBareosEvents(plugin_ctx, 1, event); if (retval != bRC_OK) { break; } } @@ -892,7 +886,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -911,10 +905,10 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) event = PyInt_AsLong(pyEvent); if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "PyBareosUnRegisterEvents: registering event %d\n", event); - retval = bareos_core_functions->unregisterBareosEvents(bareos_plugin_ctx, - 1, event); + retval = + bareos_core_functions->unregisterBareosEvents(plugin_ctx, 1, event); if (retval != bRC_OK) { break; } } @@ -934,14 +928,13 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (bareos_core_functions->getInstanceCount(bareos_plugin_ctx, &value) == - bRC_OK) { + if (bareos_core_functions->getInstanceCount(plugin_ctx, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 9fd0fe0b8a3..3017473e9a6 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -47,38 +47,33 @@ static bRC set_bareos_core_functions( BareosCoreFunctions* new_bareos_core_functions); -static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); -static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, - void* value); -static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, +static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); +static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); +static bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); -static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, +static bRC PySetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); -static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, bEvent* event, void* value); -static bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, - struct save_pkt* sp); -static bRC PyEndBackupFile(PluginContext* bareos_plugin_ctx); -static bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); -static bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, - const char* cmd); -static bRC PyEndRestoreFile(PluginContext* bareos_plugin_ctx); -static bRC PyCreateFile(PluginContext* bareos_plugin_ctx, - struct restore_pkt* rp); -static bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, +static bRC PyStartBackupFile(PluginContext* plugin_ctx, struct save_pkt* sp); +static bRC PyEndBackupFile(PluginContext* plugin_ctx); +static bRC PyPluginIO(PluginContext* plugin_ctx, struct io_pkt* io); +static bRC PyStartRestoreFile(PluginContext* plugin_ctx, const char* cmd); +static bRC PyEndRestoreFile(PluginContext* plugin_ctx); +static bRC PyCreateFile(PluginContext* plugin_ctx, struct restore_pkt* rp); +static bRC PySetFileAttributes(PluginContext* plugin_ctx, struct restore_pkt* rp); -static bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname); -static bRC PyGetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC PySetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, +static bRC PyCheckFile(PluginContext* plugin_ctx, char* fname); +static bRC PyGetAcl(PluginContext* plugin_ctx, acl_pkt* ap); +static bRC PySetAcl(PluginContext* plugin_ctx, acl_pkt* ap); +static bRC PyGetXattr(PluginContext* plugin_ctx, xattr_pkt* xp); +static bRC PySetXattr(PluginContext* plugin_ctx, xattr_pkt* xp); +static bRC PyRestoreObjectData(PluginContext* plugin_ctx, struct restore_object_pkt* rop); -static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, - struct save_pkt* sp); +static bRC PyHandleBackupFile(PluginContext* plugin_ctx, struct save_pkt* sp); /* Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; @@ -114,12 +109,11 @@ static bRC set_plugin_context(PluginContext* new_plugin_context) * a restore overrides can be passed in before the actual plugin options are * restored as part of the restore stream handling. */ -static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, - void* value) +static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -146,39 +140,39 @@ static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, return retval; } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Failed to find function named " "parse_plugin_definition()\n"); return bRC_Error; } bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } -static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, +static bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, +static bRC PySetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, bEvent* event, void* value) { bRC retval = bRC_Error; plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -201,14 +195,14 @@ static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, Py_DECREF(pRetVal); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Failed to find function named handle_plugin_event()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } @@ -446,12 +440,11 @@ static inline bool PySavePacketToNative( * The plugin can create "Virtual" files by giving them a * name that is not normally found on the file system. */ -static bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, - struct save_pkt* sp) +static bRC PyStartBackupFile(PluginContext* plugin_ctx, struct save_pkt* sp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -481,14 +474,14 @@ static bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, Py_DECREF((PyObject*)pSavePkt); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Failed to find function named start_backup_file()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } @@ -499,11 +492,11 @@ static bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, * If the plugin wishes to create another file and back it up, * then it must return bRC_More (not yet implemented). */ -static bRC PyEndBackupFile(PluginContext* bareos_plugin_ctx) +static bRC PyEndBackupFile(PluginContext* plugin_ctx) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -521,14 +514,14 @@ static bRC PyEndBackupFile(PluginContext* bareos_plugin_ctx) retval = ConvertPythonRetvalTobRCRetval(pRetVal); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Failed to find function named end_backup_file()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } @@ -608,11 +601,11 @@ static inline bool PyIoPacketToNative(PyIoPacket* pIoPkt, struct io_pkt* io) * or after startRestoreFile to do the actual file * input or output. */ -static bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io) +static bRC PyPluginIO(PluginContext* plugin_ctx, struct io_pkt* io) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -642,14 +635,14 @@ static bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io) } Py_DECREF((PyObject*)pIoPkt); } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Failed to find function named plugin_io()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } io->status = -1; @@ -660,11 +653,11 @@ static bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io) * Called when the first record is read from the Volume that was previously * written by the command plugin. */ -static bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd) +static bRC PyStartRestoreFile(PluginContext* plugin_ctx, const char* cmd) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -688,14 +681,14 @@ static bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd) Py_DECREF(pRetVal); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Failed to find function named start_restore_file()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } @@ -703,11 +696,11 @@ static bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd) /** * Called when a command plugin is done restoring a file. */ -static bRC PyEndRestoreFile(PluginContext* bareos_plugin_ctx) +static bRC PyEndRestoreFile(PluginContext* plugin_ctx) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -725,14 +718,14 @@ static bRC PyEndRestoreFile(PluginContext* bareos_plugin_ctx) retval = ConvertPythonRetvalTobRCRetval(pRetVal); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Failed to find function named end_restore_file()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } @@ -784,12 +777,11 @@ static inline void PyRestorePacketToNative(PyRestorePacket* pRestorePacket, * CF_EXTRACT -- extract the file (i.e.call i/o routines) * CF_CREATED -- created, but no content to extract (typically directories) */ -static bRC PyCreateFile(PluginContext* bareos_plugin_ctx, - struct restore_pkt* rp) +static bRC PyCreateFile(PluginContext* plugin_ctx, struct restore_pkt* rp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; if (!rp) { return bRC_Error; } @@ -818,24 +810,24 @@ static bRC PyCreateFile(PluginContext* bareos_plugin_ctx, Py_DECREF(pRestorePacket); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Failed to find function named create_file()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } -static bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, +static bRC PySetFileAttributes(PluginContext* plugin_ctx, struct restore_pkt* rp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; if (!rp) { return bRC_Error; } @@ -862,23 +854,23 @@ static bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, Py_DECREF(pRestorePacket); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Failed to find function named set_file_attributes()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } -static bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname) +static bRC PyCheckFile(PluginContext* plugin_ctx, char* fname) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; if (!fname) { return bRC_Error; } @@ -902,14 +894,14 @@ static bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname) Py_DECREF(pRetVal); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Failed to find function named check_file()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } @@ -954,11 +946,11 @@ static inline bool PyAclPacketToNative(PyAclPacket* pAclPacket, return true; } -static bRC PyGetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) +static bRC PyGetAcl(PluginContext* plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; if (!ap) { return bRC_Error; } @@ -990,23 +982,23 @@ static bRC PyGetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) Py_DECREF(pAclPkt); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Failed to find function named get_acl()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } -static bRC PySetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) +static bRC PySetAcl(PluginContext* plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; if (!ap) { return bRC_Error; } @@ -1033,14 +1025,14 @@ static bRC PySetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) Py_DECREF(pRetVal); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Failed to find function named set_acl()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } @@ -1108,11 +1100,11 @@ static inline bool PyXattrPacketToNative(PyXattrPacket* pXattrPacket, return true; } -static bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) +static bRC PyGetXattr(PluginContext* plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; if (!xp) { return bRC_Error; } @@ -1144,23 +1136,23 @@ static bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) Py_DECREF(pXattrPkt); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Failed to find function named get_xattr()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } -static bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) +static bRC PySetXattr(PluginContext* plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; if (!xp) { return bRC_Error; } @@ -1187,13 +1179,13 @@ static bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) Py_DECREF(pRetVal); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Failed to find function named set_xattr()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } @@ -1221,12 +1213,12 @@ static inline PyRestoreObject* NativeToPyRestoreObject( return pRestoreObject; } -static bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, +static bRC PyRestoreObjectData(PluginContext* plugin_ctx, struct restore_object_pkt* rop) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; if (!rop) { return bRC_OK; } @@ -1253,24 +1245,23 @@ static bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, Py_DECREF(pRetVal); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Failed to find function named start_restore_file()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } -static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, - struct save_pkt* sp) +static bRC PyHandleBackupFile(PluginContext* plugin_ctx, struct save_pkt* sp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; if (!sp) { return bRC_Error; } @@ -1302,14 +1293,14 @@ static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, Py_DECREF(pSavePkt); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Failed to find function named handle_backup_file()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } @@ -1322,7 +1313,7 @@ static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } @@ -1336,8 +1327,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarDistName: { char* value = NULL; - if (bareos_core_functions->getBareosValue( - bareos_plugin_ctx, (bVariable)var, &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue(plugin_ctx, (bVariable)var, + &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } } break; @@ -1351,8 +1342,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarPrefixLinks: { int value = 0; - if (bareos_core_functions->getBareosValue( - bareos_plugin_ctx, (bVariable)var, &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue(plugin_ctx, (bVariable)var, + &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } break; @@ -1364,8 +1355,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarRegexWhere: { char* value = NULL; - if (bareos_core_functions->getBareosValue( - bareos_plugin_ctx, (bVariable)var, &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue(plugin_ctx, (bVariable)var, + &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } } break; @@ -1373,7 +1364,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bVarFileSeen: break; /* a write only variable, ignore read request */ default: - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: PyBareosGetValue unknown variable requested %d\n", var); break; } @@ -1394,7 +1385,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject* pyValue; @@ -1409,7 +1400,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) value = PyInt_AsLong(pyValue); if (value) { - retval = bareos_core_functions->setBareosValue(bareos_plugin_ctx, + retval = bareos_core_functions->setBareosValue(plugin_ctx, (bVariable)var, &value); } break; @@ -1419,13 +1410,13 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) value = PyString_AsString(pyValue); if (value) { - retval = bareos_core_functions->setBareosValue(bareos_plugin_ctx, + retval = bareos_core_functions->setBareosValue(plugin_ctx, (bVariable)var, value); } break; } default: - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: PyBareosSetValue unknown variable requested %d\n", var); break; } @@ -1443,9 +1434,9 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); /* plugin_private_context* ppc = */ - /* (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + /* (plugin_private_context*)plugin_ctx->plugin_private_context; */ if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { @@ -1453,7 +1444,7 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) } RETURN_RUNTIME_ERROR_IF_BAREOS_PLUGIN_CTX_UNSET() - if (dbgmsg) { Dmsg(bareos_plugin_ctx, level, "python-fd: %s", dbgmsg); } + if (dbgmsg) { Dmsg(plugin_ctx, level, "python-fd: %s", dbgmsg); } Py_INCREF(Py_None); return Py_None; } @@ -1467,14 +1458,14 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (jobmsg) { Jmsg(bareos_plugin_ctx, type, "python-fd: %s", jobmsg); } + if (jobmsg) { Jmsg(plugin_ctx, type, "python-fd: %s", jobmsg); } Py_INCREF(Py_None); return Py_None; @@ -1488,7 +1479,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -1506,10 +1497,10 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) event = PyInt_AsLong(pyEvent); if (event >= bEventJobStart && event <= FD_NR_EVENTS) { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: PyBareosRegisterEvents registering event %d\n", event); - retval = bareos_core_functions->registerBareosEvents(bareos_plugin_ctx, 1, - event); + retval = + bareos_core_functions->registerBareosEvents(plugin_ctx, 1, event); if (retval != bRC_OK) { break; } } @@ -1529,7 +1520,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -1547,10 +1538,10 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) event = PyInt_AsLong(pyEvent); if (event >= bEventJobStart && event <= FD_NR_EVENTS) { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "PyBareosUnRegisterEvents: unregistering event %d\n", event); - retval = bareos_core_functions->unregisterBareosEvents(bareos_plugin_ctx, - 1, event); + retval = + bareos_core_functions->unregisterBareosEvents(plugin_ctx, 1, event); } } @@ -1568,14 +1559,13 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (bareos_core_functions->getInstanceCount(bareos_plugin_ctx, &value) == - bRC_OK) { + if (bareos_core_functions->getInstanceCount(plugin_ctx, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } @@ -1595,14 +1585,12 @@ static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) { char* file = NULL; bRC retval = bRC_Error; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|z:BareosAddExclude", &file)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (file) { - retval = bareos_core_functions->AddExclude(bareos_plugin_ctx, file); - } + if (file) { retval = bareos_core_functions->AddExclude(plugin_ctx, file); } bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -1616,14 +1604,12 @@ static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) { char* file = NULL; bRC retval = bRC_Error; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|z:BareosAddInclude", &file)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (file) { - retval = bareos_core_functions->AddInclude(bareos_plugin_ctx, file); - } + if (file) { retval = bareos_core_functions->AddInclude(plugin_ctx, file); } bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -1637,14 +1623,12 @@ static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) { char* opts = NULL; bRC retval = bRC_Error; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|z:BareosAddOptions", &opts)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (opts) { - retval = bareos_core_functions->AddOptions(bareos_plugin_ctx, opts); - } + if (opts) { retval = bareos_core_functions->AddOptions(plugin_ctx, opts); } bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -1659,14 +1643,14 @@ static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) int type; char* item = NULL; bRC retval = bRC_Error; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|zi:BareosAddRegex", &item, &type)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (item) { - retval = bareos_core_functions->AddRegex(bareos_plugin_ctx, item, type); + retval = bareos_core_functions->AddRegex(plugin_ctx, item, type); } bail_out: @@ -1682,16 +1666,14 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) int type; char* item = NULL; bRC retval = bRC_Error; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "|zi:BareosAddWild", &item, &type)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (item) { - retval = bareos_core_functions->AddWild(bareos_plugin_ctx, item, type); - } + if (item) { retval = bareos_core_functions->AddWild(plugin_ctx, item, type); } bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -1703,13 +1685,13 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) { - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewOptions")) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - retval = bareos_core_functions->NewOptions(bareos_plugin_ctx); + retval = bareos_core_functions->NewOptions(plugin_ctx); bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -1721,13 +1703,13 @@ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) { - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewInclude")) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - retval = bareos_core_functions->NewInclude(bareos_plugin_ctx); + retval = bareos_core_functions->NewInclude(plugin_ctx); bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -1739,13 +1721,13 @@ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) { - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewPreInclude")) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - retval = bareos_core_functions->NewPreInclude(bareos_plugin_ctx); + retval = bareos_core_functions->NewPreInclude(plugin_ctx); bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -1758,7 +1740,7 @@ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) */ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) { - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); struct save_pkt sp; bRC retval = bRC_Error; @@ -1793,7 +1775,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) } sp.save_time = pSavePkt->save_time; - retval = bareos_core_functions->checkChanges(bareos_plugin_ctx, &sp); + retval = bareos_core_functions->checkChanges(plugin_ctx, &sp); /* * Copy back the two fields that are changed by checkChanges(). @@ -1812,7 +1794,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) */ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) { - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); struct save_pkt sp; bRC retval = bRC_Error; PySavePacket* pSavePkt; @@ -1842,7 +1824,7 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) goto bail_out; } - retval = bareos_core_functions->AcceptFile(bareos_plugin_ctx, &sp); + retval = bareos_core_functions->AcceptFile(plugin_ctx, &sp); bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -1855,7 +1837,7 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) { bool all; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; @@ -1866,7 +1848,7 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() all = PyObject_IsTrue(pyBool); - retval = bareos_core_functions->SetSeenBitmap(bareos_plugin_ctx, all, fname); + retval = bareos_core_functions->SetSeenBitmap(plugin_ctx, all, fname); bail_out: return ConvertbRCRetvalToPythonRetval(retval); @@ -1880,7 +1862,7 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) { bool all; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; @@ -1891,8 +1873,7 @@ static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() all = PyObject_IsTrue(pyBool); - retval = - bareos_core_functions->ClearSeenBitmap(bareos_plugin_ctx, all, fname); + retval = bareos_core_functions->ClearSeenBitmap(plugin_ctx, all, fname); bail_out: return ConvertbRCRetvalToPythonRetval(retval); diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/bareosfd.h index 92a9cb722bc..d5e75eccbf7 100644 --- a/core/src/plugins/filed/python/bareosfd.h +++ b/core/src/plugins/filed/python/bareosfd.h @@ -806,7 +806,7 @@ MOD_INIT(bareosfd) if (c_api_object != NULL) PyModule_AddObject(m, "_C_API", c_api_object); - +#if 0 /* add PluginContext Capsule */ PyObject* PyModulePluginContext = PyCapsule_New( (void*)&plugin_context, PYTHON_MODULE_NAME_QUOTED ".PluginContext", NULL); @@ -823,7 +823,7 @@ MOD_INIT(bareosfd) ":PluginContext PyModule_AddObject failed\n"); return MOD_ERROR_VAL; } - +#endif /* add bpFuncs Capsule */ PyObject* PyModulePluginFuncs = PyCapsule_New((void*)&bareos_core_functions, diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 24ffd699c39..452b9b82455 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -19,9 +19,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/* - * Marco van Wieringen, August 2012 - */ /** * @file * Python plugin for the Bareos File Daemon @@ -48,50 +45,48 @@ namespace filedaemon { static const int debuglevel = 150; #define PLUGIN_LICENSE "Bareos AGPLv3" -#define PLUGIN_AUTHOR "Marco van Wieringen" -#define PLUGIN_DATE "May 2014" -#define PLUGIN_VERSION "3" +#define PLUGIN_AUTHOR "Bareos GmbH & Co.KG" +#define PLUGIN_DATE "May 2020" +#define PLUGIN_VERSION "4" #define PLUGIN_DESCRIPTION "Python File Daemon Plugin" #define PLUGIN_USAGE \ "python:module_path=:module_name=:..." /* Forward referenced functions */ -static bRC newPlugin(PluginContext* bareos_plugin_ctx); -static bRC freePlugin(PluginContext* bareos_plugin_ctx); -static bRC getPluginValue(PluginContext* bareos_plugin_ctx, +static bRC newPlugin(PluginContext* plugin_ctx); +static bRC freePlugin(PluginContext* plugin_ctx); +static bRC getPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); -static bRC setPluginValue(PluginContext* bareos_plugin_ctx, +static bRC setPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); -static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, +static bRC handlePluginEvent(PluginContext* plugin_ctx, bEvent* event, void* value); -static bRC startBackupFile(PluginContext* bareos_plugin_ctx, - struct save_pkt* sp); -static bRC endBackupFile(PluginContext* bareos_plugin_ctx); -static bRC pluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); -static bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd); -static bRC endRestoreFile(PluginContext* bareos_plugin_ctx); -static bRC createFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp); -static bRC setFileAttributes(PluginContext* bareos_plugin_ctx, - struct restore_pkt* rp); -static bRC checkFile(PluginContext* bareos_plugin_ctx, char* fname); -static bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC setXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, +static bRC startBackupFile(PluginContext* plugin_ctx, struct save_pkt* sp); +static bRC endBackupFile(PluginContext* plugin_ctx); +static bRC pluginIO(PluginContext* plugin_ctx, struct io_pkt* io); +static bRC startRestoreFile(PluginContext* plugin_ctx, const char* cmd); +static bRC endRestoreFile(PluginContext* plugin_ctx); +static bRC createFile(PluginContext* plugin_ctx, struct restore_pkt* rp); +static bRC setFileAttributes(PluginContext* plugin_ctx, struct restore_pkt* rp); +static bRC checkFile(PluginContext* plugin_ctx, char* fname); +static bRC getAcl(PluginContext* plugin_ctx, acl_pkt* ap); +static bRC setAcl(PluginContext* plugin_ctx, acl_pkt* ap); +static bRC getXattr(PluginContext* plugin_ctx, xattr_pkt* xp); +static bRC setXattr(PluginContext* plugin_ctx, xattr_pkt* xp); +static bRC parse_plugin_definition(PluginContext* plugin_ctx, void* value, PoolMem& plugin_options); -static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); -static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); -static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, +static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); +static bRC PyLoadModule(PluginContext* plugin_ctx, void* value); +static bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); -static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, +static bRC PySetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); @@ -241,18 +236,21 @@ bRC unloadPlugin() * plugin instance must be thread safe and keep its own * local data. */ -static bRC newPlugin(PluginContext* bareos_plugin_ctx) +static bRC newPlugin(PluginContext* plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = (struct plugin_private_context*)malloc( sizeof(struct plugin_private_context)); if (!plugin_priv_ctx) { return bRC_Error; } memset(plugin_priv_ctx, 0, sizeof(struct plugin_private_context)); - bareos_plugin_ctx->plugin_private_context = + plugin_ctx->plugin_private_context = (void*)plugin_priv_ctx; /* set our context pointer */ plugin_priv_ctx->bareos_core_functions = bareos_core_functions; + /* set bareos_core_functions inside of barosfd module */ + Bareosfd_set_plugin_context(plugin_ctx); + /* For each plugin instance we instantiate a new Python interpreter. */ PyEval_AcquireThread(mainThreadState); plugin_priv_ctx->interpreter = Py_NewInterpreter(); @@ -261,7 +259,7 @@ static bRC newPlugin(PluginContext* bareos_plugin_ctx) /* Always register some events the python plugin itself can register any other events it is interested in. */ bareos_core_functions->registerBareosEvents( - bareos_plugin_ctx, 9, bEventLevel, bEventSince, bEventNewPluginOptions, + plugin_ctx, 9, bEventLevel, bEventSince, bEventNewPluginOptions, bEventPluginCommand, bEventJobStart, bEventRestoreCommand, bEventEstimateCommand, bEventBackupCommand, bEventRestoreObject); @@ -272,10 +270,10 @@ static bRC newPlugin(PluginContext* bareos_plugin_ctx) * Release everything concerning a particular instance of a * plugin. Normally called when the Job terminates. */ -static bRC freePlugin(PluginContext* bareos_plugin_ctx) +static bRC freePlugin(PluginContext* plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { return bRC_Error; } @@ -307,13 +305,13 @@ static bRC freePlugin(PluginContext* bareos_plugin_ctx) PyEval_ReleaseLock(); free(plugin_priv_ctx); - bareos_plugin_ctx->plugin_private_context = NULL; + plugin_ctx->plugin_private_context = NULL; return bRC_OK; } -static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, +static bRC handlePluginEvent(PluginContext* plugin_ctx, bEvent* event, void* value) { @@ -321,7 +319,7 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, bool event_dispatched = false; PoolMem plugin_options(PM_FNAME); plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } @@ -344,8 +342,7 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, /* Fall-through wanted */ case bEventPluginCommand: event_dispatched = true; - retval = - parse_plugin_definition(bareos_plugin_ctx, value, plugin_options); + retval = parse_plugin_definition(plugin_ctx, value, plugin_options); break; case bEventNewPluginOptions: /* Free any previous value. */ @@ -355,8 +352,7 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, } event_dispatched = true; - retval = - parse_plugin_definition(bareos_plugin_ctx, value, plugin_options); + retval = parse_plugin_definition(plugin_ctx, value, plugin_options); /* Save that we got a plugin override. */ plugin_priv_ctx->plugin_options = strdup((char*)value); @@ -371,7 +367,7 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, if (!plugin_priv_ctx->python_loaded) { if (rop && *rop->plugin_name) { event_dispatched = true; - retval = parse_plugin_definition(bareos_plugin_ctx, rop->plugin_name, + retval = parse_plugin_definition(plugin_ctx, rop->plugin_name, plugin_options); } } @@ -406,12 +402,12 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, case bEventNewPluginOptions: /* See if we already loaded the Python modules. */ if (!plugin_priv_ctx->python_loaded) { - retval = PyLoadModule(bareos_plugin_ctx, plugin_options.c_str()); + retval = PyLoadModule(plugin_ctx, plugin_options.c_str()); } /* Only try to call when the loading succeeded. */ if (retval == bRC_OK) { - retval = Bareosfd_PyParsePluginDefinition(bareos_plugin_ctx, + retval = Bareosfd_PyParsePluginDefinition(plugin_ctx, plugin_options.c_str()); } break; @@ -428,25 +424,25 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, } else { /* See if we already loaded the Python modules. */ if (!plugin_priv_ctx->python_loaded && *rop->plugin_name) { - retval = PyLoadModule(bareos_plugin_ctx, plugin_options.c_str()); + retval = PyLoadModule(plugin_ctx, plugin_options.c_str()); /* Only try to call when the loading succeeded. */ if (retval == bRC_OK) { - retval = Bareosfd_PyParsePluginDefinition(bareos_plugin_ctx, + retval = Bareosfd_PyParsePluginDefinition(plugin_ctx, plugin_options.c_str()); if (retval == bRC_OK) { - retval = Bareosfd_PyRestoreObjectData(bareos_plugin_ctx, rop); + retval = Bareosfd_PyRestoreObjectData(plugin_ctx, rop); } } } else { - retval = Bareosfd_PyRestoreObjectData(bareos_plugin_ctx, rop); + retval = Bareosfd_PyRestoreObjectData(plugin_ctx, rop); } } break; } case bEventHandleBackupFile: - retval = Bareosfd_PyHandleBackupFile(bareos_plugin_ctx, - (struct save_pkt*)value); + retval = + Bareosfd_PyHandleBackupFile(plugin_ctx, (struct save_pkt*)value); break; default: /* @@ -455,8 +451,7 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, * that time we pretend the call succeeded. */ if (plugin_priv_ctx->python_loaded) { - retval = - Bareosfd_PyHandlePluginEvent(bareos_plugin_ctx, event, value); + retval = Bareosfd_PyHandlePluginEvent(plugin_ctx, event, value); } else { retval = bRC_OK; } @@ -477,17 +472,16 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, * The plugin can create "Virtual" files by giving them a * name that is not normally found on the file system. */ -static bRC startBackupFile(PluginContext* bareos_plugin_ctx, - struct save_pkt* sp) +static bRC startBackupFile(PluginContext* plugin_ctx, struct save_pkt* sp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = Bareosfd_PyStartBackupFile(bareos_plugin_ctx, sp); + retval = Bareosfd_PyStartBackupFile(plugin_ctx, sp); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); /* @@ -506,7 +500,7 @@ static bRC startBackupFile(PluginContext* bareos_plugin_ctx, sp->save_time = plugin_priv_ctx->since; } - switch (bareos_core_functions->checkChanges(bareos_plugin_ctx, sp)) { + switch (bareos_core_functions->checkChanges(plugin_ctx, sp)) { case bRC_Seen: switch (sp->type) { case FT_DIRBEGIN: @@ -529,16 +523,16 @@ static bRC startBackupFile(PluginContext* bareos_plugin_ctx, /** * Done backing up a file. */ -static bRC endBackupFile(PluginContext* bareos_plugin_ctx) +static bRC endBackupFile(PluginContext* plugin_ctx) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = Bareosfd_PyEndBackupFile(bareos_plugin_ctx); + retval = Bareosfd_PyEndBackupFile(plugin_ctx); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -550,18 +544,18 @@ static bRC endBackupFile(PluginContext* bareos_plugin_ctx) * or after startRestoreFile to do the actual file * input or output. */ -static bRC pluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io) +static bRC pluginIO(PluginContext* plugin_ctx, struct io_pkt* io) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } if (!plugin_priv_ctx->python_loaded) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = Bareosfd_PyPluginIO(bareos_plugin_ctx, io); + retval = Bareosfd_PyPluginIO(plugin_ctx, io); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -571,16 +565,16 @@ static bRC pluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io) /** * Start restore of a file. */ -static bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd) +static bRC startRestoreFile(PluginContext* plugin_ctx, const char* cmd) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = Bareosfd_PyStartRestoreFile(bareos_plugin_ctx, cmd); + retval = Bareosfd_PyStartRestoreFile(plugin_ctx, cmd); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -590,16 +584,16 @@ static bRC startRestoreFile(PluginContext* bareos_plugin_ctx, const char* cmd) /** * Done restoring a file. */ -static bRC endRestoreFile(PluginContext* bareos_plugin_ctx) +static bRC endRestoreFile(PluginContext* plugin_ctx) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = Bareosfd_PyEndRestoreFile(bareos_plugin_ctx); + retval = Bareosfd_PyEndRestoreFile(plugin_ctx); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -613,16 +607,16 @@ static bRC endRestoreFile(PluginContext* bareos_plugin_ctx) * This data is what is needed to create the file, but does * not contain actual file data. */ -static bRC createFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) +static bRC createFile(PluginContext* plugin_ctx, struct restore_pkt* rp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = Bareosfd_PyCreateFile(bareos_plugin_ctx, rp); + retval = Bareosfd_PyCreateFile(plugin_ctx, rp); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -633,17 +627,16 @@ static bRC createFile(PluginContext* bareos_plugin_ctx, struct restore_pkt* rp) * Called after the file has been restored. This can be used to * set directory permissions, ... */ -static bRC setFileAttributes(PluginContext* bareos_plugin_ctx, - struct restore_pkt* rp) +static bRC setFileAttributes(PluginContext* plugin_ctx, struct restore_pkt* rp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = Bareosfd_PySetFileAttributes(bareos_plugin_ctx, rp); + retval = Bareosfd_PySetFileAttributes(plugin_ctx, rp); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -653,18 +646,18 @@ static bRC setFileAttributes(PluginContext* bareos_plugin_ctx, /** * When using Incremental dump, all previous dumps are necessary */ -static bRC checkFile(PluginContext* bareos_plugin_ctx, char* fname) +static bRC checkFile(PluginContext* plugin_ctx, char* fname) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } if (!plugin_priv_ctx->python_loaded) { return bRC_OK; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = Bareosfd_PyCheckFile(bareos_plugin_ctx, fname); + retval = Bareosfd_PyCheckFile(plugin_ctx, fname); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -673,16 +666,16 @@ static bRC checkFile(PluginContext* bareos_plugin_ctx, char* fname) /** */ -static bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) +static bRC getAcl(PluginContext* plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = Bareosfd_PyGetAcl(bareos_plugin_ctx, ap); + retval = Bareosfd_PyGetAcl(plugin_ctx, ap); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -691,16 +684,16 @@ static bRC getAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) /** */ -static bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) +static bRC setAcl(PluginContext* plugin_ctx, acl_pkt* ap) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = Bareosfd_PySetAcl(bareos_plugin_ctx, ap); + retval = Bareosfd_PySetAcl(plugin_ctx, ap); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -709,16 +702,16 @@ static bRC setAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap) /** */ -static bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) +static bRC getXattr(PluginContext* plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = Bareosfd_PyGetXattr(bareos_plugin_ctx, xp); + retval = Bareosfd_PyGetXattr(plugin_ctx, xp); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -727,16 +720,16 @@ static bRC getXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) /** */ -static bRC setXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp) +static bRC setXattr(PluginContext* plugin_ctx, xattr_pkt* xp) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = Bareosfd_PySetXattr(bareos_plugin_ctx, xp); + retval = Bareosfd_PySetXattr(plugin_ctx, xp); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); bail_out: @@ -761,7 +754,7 @@ static inline void SetStringIfNull(char** destination, char* value) * * python:module_path=:module_name=:... */ -static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, +static bRC parse_plugin_definition(PluginContext* plugin_ctx, void* value, PoolMem& plugin_options) { @@ -771,7 +764,7 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, PoolMem plugin_definition(PM_FNAME); char *bp, *argument, *argument_value; plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (plugin_private_context*)plugin_ctx->plugin_private_context; if (!value) { return bRC_Error; } @@ -781,7 +774,7 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, * Python Plugins enabled. */ if (bstrcmp((char*)value, "*all*")) { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Got plugin definition %s, skipping to ignore\n", (char*)value); return bRC_Skip; @@ -808,10 +801,10 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, bp = strchr((char*)value, ':'); if (!bp) { - Jmsg(bareos_plugin_ctx, M_FATAL, - "python-fd: Illegal plugin definition %s\n", (char*)value); - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Illegal plugin definition %s\n", (char*)value); + Jmsg(plugin_ctx, M_FATAL, "python-fd: Illegal plugin definition %s\n", + (char*)value); + Dmsg(plugin_ctx, debuglevel, "python-fd: Illegal plugin definition %s\n", + (char*)value); goto bail_out; } @@ -829,11 +822,9 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, bp = strchr(plugin_definition.c_str(), ':'); if (!bp) { - Jmsg(bareos_plugin_ctx, M_FATAL, - "python-fd: Illegal plugin definition %s\n", + Jmsg(plugin_ctx, M_FATAL, "python-fd: Illegal plugin definition %s\n", plugin_definition.c_str()); - Dmsg(bareos_plugin_ctx, debuglevel, - "python-fd: Illegal plugin definition %s\n", + Dmsg(plugin_ctx, debuglevel, "python-fd: Illegal plugin definition %s\n", plugin_definition.c_str()); goto bail_out; } @@ -857,9 +848,9 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, argument = bp; argument_value = strchr(bp, '='); if (!argument_value) { - Jmsg(bareos_plugin_ctx, M_FATAL, + Jmsg(plugin_ctx, M_FATAL, "python-fd: Illegal argument %s without value\n", argument); - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Illegal argument %s without value\n", argument); goto bail_out; } @@ -957,11 +948,11 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, * module path and the module to load. We also load the dictionary used * for looking up the Python methods. */ -static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) +static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject *sysPath, *mPath, *pName, *pFunc; /* See if we already setup the python search path. */ @@ -978,7 +969,7 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) /* Try to load the Python module by name. */ if (plugin_priv_ctx->module_name) { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Trying to load module with name %s\n", plugin_priv_ctx->module_name); pName = PyString_FromString(plugin_priv_ctx->module_name); @@ -986,13 +977,13 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) Py_DECREF(pName); if (!plugin_priv_ctx->pModule) { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Failed to load module with name %s\n", plugin_priv_ctx->module_name); goto bail_out; } - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Successfully loaded module with name %s\n", plugin_priv_ctx->module_name); @@ -1003,9 +994,9 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) /* Encode the PluginContext so a Python method can pass it in on * calling back.*/ /* plugin_priv_ctx->py_PluginContext = - * PyCreatePluginContext(bareos_plugin_ctx); */ + * PyCreatePluginContext(plugin_ctx); */ - StorePluginContextInPythonModule(bareos_plugin_ctx); + StorePluginContextInPythonModule(plugin_ctx); /* Lookup the load_bareos_plugin() function in the python module. */ pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, @@ -1028,7 +1019,7 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) Py_DECREF(pRetVal); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-fd: Failed to find function named load_bareos_plugins()\n"); goto bail_out; } @@ -1042,19 +1033,19 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } -static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, +static bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, +static bRC PySetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value) { diff --git a/core/src/plugins/python_plugins_common.h b/core/src/plugins/python_plugins_common.h index 5775bc51d1d..29c7c6add53 100644 --- a/core/src/plugins/python_plugins_common.h +++ b/core/src/plugins/python_plugins_common.h @@ -47,13 +47,13 @@ #define TOSTRING(x) STRINGIFY(x) #define AT __FILE__ ":" TOSTRING(__LINE__) -/* check if bareos_plugin_ctx and bfunc are set. +/* check if plugin_ctx and bfunc are set. * Otherwise return NULL and throw RuntimeError */ -#define RETURN_RUNTIME_ERROR_IF_BAREOS_PLUGIN_CTX_UNSET() \ - if (!bareos_plugin_ctx) { \ - PyErr_SetString(PyExc_RuntimeError, AT " :bareos_plugin_ctx is unset"); \ - return NULL; \ +#define RETURN_RUNTIME_ERROR_IF_BAREOS_PLUGIN_CTX_UNSET() \ + if (!plugin_ctx) { \ + PyErr_SetString(PyExc_RuntimeError, AT " :plugin_ctx is unset"); \ + return NULL; \ } #define RETURN_RUNTIME_ERROR_IF_BFUNC_UNSET() \ diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index de6b5787ac2..ccf7777c0a6 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -58,32 +58,31 @@ static const int debuglevel = 150; /* Forward referenced functions */ -static bRC newPlugin(PluginContext* bareos_plugin_ctx); -static bRC freePlugin(PluginContext* bareos_plugin_ctx); -static bRC getPluginValue(PluginContext* bareos_plugin_ctx, +static bRC newPlugin(PluginContext* plugin_ctx); +static bRC freePlugin(PluginContext* plugin_ctx); +static bRC getPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); -static bRC setPluginValue(PluginContext* bareos_plugin_ctx, +static bRC setPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); -static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, +static bRC handlePluginEvent(PluginContext* plugin_ctx, bsdEvent* event, void* value); -static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, +static bRC parse_plugin_definition(PluginContext* plugin_ctx, void* value, PoolMem& plugin_options); -static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); -static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value); -static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, - void* value); -static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, +static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); +static bRC PyLoadModule(PluginContext* plugin_ctx, void* value); +static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); +static bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); -static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, +static bRC PySetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); -static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, bsdEvent* event, void* value); @@ -186,14 +185,14 @@ bRC unloadPlugin() #endif /* Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(PluginContext* bareos_plugin_ctx) +static bRC newPlugin(PluginContext* plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = (struct plugin_private_context*)malloc( sizeof(struct plugin_private_context)); if (!plugin_priv_ctx) { return bRC_Error; } memset(plugin_priv_ctx, 0, sizeof(struct plugin_private_context)); - bareos_plugin_ctx->plugin_private_context = + plugin_ctx->plugin_private_context = (void*)plugin_priv_ctx; /* set our context pointer */ /* For each plugin instance we instantiate a new Python interpreter. */ @@ -205,17 +204,17 @@ static bRC newPlugin(PluginContext* bareos_plugin_ctx) * Always register some events the python plugin itself can register * any other events it is interested in. */ - bareos_core_functions->registerBareosEvents(bareos_plugin_ctx, 1, + bareos_core_functions->registerBareosEvents(plugin_ctx, 1, bsdEventNewPluginOptions); return bRC_OK; } /* Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(PluginContext* bareos_plugin_ctx) +static bRC freePlugin(PluginContext* plugin_ctx) { struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { return bRC_Error; } @@ -231,13 +230,13 @@ static bRC freePlugin(PluginContext* bareos_plugin_ctx) PyEval_ReleaseLock(); free(plugin_priv_ctx); - bareos_plugin_ctx->plugin_private_context = NULL; + plugin_ctx->plugin_private_context = NULL; return bRC_OK; } -static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, +static bRC handlePluginEvent(PluginContext* plugin_ctx, bsdEvent* event, void* value) { @@ -245,7 +244,7 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, bool event_dispatched = false; PoolMem plugin_options(PM_FNAME); plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (plugin_private_context*)plugin_ctx->plugin_private_context; if (!plugin_priv_ctx) { goto bail_out; } @@ -256,8 +255,7 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, switch (event->eventType) { case bsdEventNewPluginOptions: event_dispatched = true; - retval = - parse_plugin_definition(bareos_plugin_ctx, value, plugin_options); + retval = parse_plugin_definition(plugin_ctx, value, plugin_options); break; default: break; @@ -282,13 +280,12 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, * See if we already loaded the Python modules. */ if (!plugin_priv_ctx->python_loaded) { - retval = PyLoadModule(bareos_plugin_ctx, plugin_options.c_str()); + retval = PyLoadModule(plugin_ctx, plugin_options.c_str()); } /* Only try to call when the loading succeeded. */ if (retval == bRC_OK) { - retval = PyParsePluginDefinition(bareos_plugin_ctx, - plugin_options.c_str()); + retval = PyParsePluginDefinition(plugin_ctx, plugin_options.c_str()); } break; default: @@ -298,7 +295,7 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, * that time we pretend the call succeeded. */ if (plugin_priv_ctx->python_loaded) { - retval = PyHandlePluginEvent(bareos_plugin_ctx, event, value); + retval = PyHandlePluginEvent(plugin_ctx, event, value); } else { retval = bRC_OK; } @@ -319,7 +316,7 @@ static bRC handlePluginEvent(PluginContext* bareos_plugin_ctx, * * python:module_path=:module_name=:... */ -static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, +static bRC parse_plugin_definition(PluginContext* plugin_ctx, void* value, PoolMem& plugin_options) { @@ -328,7 +325,7 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, PoolMem plugin_definition(PM_FNAME); char *bp, *argument, *argument_value; plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (plugin_private_context*)plugin_ctx->plugin_private_context; if (!value) { return bRC_Error; } @@ -340,11 +337,9 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, bp = strchr(plugin_definition.c_str(), ':'); if (!bp) { - Jmsg(bareos_plugin_ctx, M_FATAL, - "python-sd: Illegal plugin definition %s\n", + Jmsg(plugin_ctx, M_FATAL, "python-sd: Illegal plugin definition %s\n", plugin_definition.c_str()); - Dmsg(bareos_plugin_ctx, debuglevel, - "python-sd: Illegal plugin definition %s\n", + Dmsg(plugin_ctx, debuglevel, "python-sd: Illegal plugin definition %s\n", plugin_definition.c_str()); goto bail_out; } @@ -368,9 +363,9 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, argument = bp; argument_value = strchr(bp, '='); if (!argument_value) { - Jmsg(bareos_plugin_ctx, M_FATAL, + Jmsg(plugin_ctx, M_FATAL, "python-sd: Illegal argument %s without value\n", argument); - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-sd: Illegal argument %s without value\n", argument); goto bail_out; } @@ -464,11 +459,11 @@ static bRC parse_plugin_definition(PluginContext* bareos_plugin_ctx, * module path and the module to load. We also load the dictionary used * for looking up the Python methods. */ -static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) +static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject *sysPath, *mPath, *pName, *pFunc; /* @@ -491,7 +486,7 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) * Try to load the Python module by name. */ if (plugin_priv_ctx->module_name) { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-sd: Trying to load module with name %s\n", plugin_priv_ctx->module_name); pName = PyString_FromString(plugin_priv_ctx->module_name); @@ -499,13 +494,13 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) Py_DECREF(pName); if (!plugin_priv_ctx->pModule) { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-sd: Failed to load module with name %s\n", plugin_priv_ctx->module_name); goto bail_out; } - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-sd: Successfully loaded module with name %s\n", plugin_priv_ctx->module_name); @@ -515,7 +510,7 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) plugin_priv_ctx->pyModuleFunctionsDict = PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ - StorePluginContextInPythonModule(bareos_plugin_ctx); + StorePluginContextInPythonModule(plugin_ctx); /* * Lookup the load_bareos_plugin() function in the python module. @@ -538,7 +533,7 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) Py_DECREF(pRetVal); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-sd: Failed to find function named load_bareos_plugins()\n"); goto bail_out; } @@ -552,7 +547,7 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } @@ -563,12 +558,11 @@ static bRC PyLoadModule(PluginContext* bareos_plugin_ctx, void* value) * PyLoadModule() has loaded the Python module and made sure things are * operational. */ -static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, - void* value) +static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value) { bRC retval = bRC_Error; struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -596,38 +590,38 @@ static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, return retval; } else { Dmsg( - bareos_plugin_ctx, debuglevel, + plugin_ctx, debuglevel, "python-sd: Failed to find function named parse_plugin_definition()\n"); return bRC_Error; } bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } -static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, +static bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, +static bRC PySetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value) { return bRC_OK; } -static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, bsdEvent* event, void* value) { bRC retval = bRC_Error; plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + (plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -650,14 +644,14 @@ static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, Py_DECREF(pRetVal); } } else { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-sd: Failed to find function named handle_plugin_event()\n"); } return retval; bail_out: - if (PyErr_Occurred()) { PyErrorHandler(bareos_plugin_ctx, M_FATAL); } + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } return retval; } @@ -669,7 +663,7 @@ static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } @@ -682,8 +676,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bsdVarJobStatus: { int value; - if (bareos_core_functions->getBareosValue( - bareos_plugin_ctx, (bsdrVariable)var, &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue(plugin_ctx, (bsdrVariable)var, + &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } break; @@ -693,8 +687,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bsdVarJobBytes: { uint64_t value = 0; - if (bareos_core_functions->getBareosValue( - bareos_plugin_ctx, (bsdrVariable)var, &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue(plugin_ctx, (bsdrVariable)var, + &value) == bRC_OK) { pRetVal = PyLong_FromUnsignedLong(value); } break; @@ -709,8 +703,8 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) case bsdVarVolumeName: { char* value = NULL; - if (bareos_core_functions->getBareosValue( - bareos_plugin_ctx, (bsdrVariable)var, &value) == bRC_OK) { + if (bareos_core_functions->getBareosValue(plugin_ctx, (bsdrVariable)var, + &value) == bRC_OK) { if (value) { pRetVal = PyString_FromString(value); } } break; @@ -737,7 +731,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) break; } default: - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-sd: PyBareosGetValue unknown variable requested %d\n", var); break; } @@ -757,7 +751,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject* pyValue; @@ -772,8 +766,8 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) value = PyString_AsString(pyValue); if (value) { - bareos_core_functions->setBareosValue(bareos_plugin_ctx, - (bsdwVariable)var, value); + bareos_core_functions->setBareosValue(plugin_ctx, (bsdwVariable)var, + value); } break; @@ -785,12 +779,12 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) value = PyInt_AsLong(pyValue); if (value >= 0) { retval = bareos_core_functions->setBareosValue( - bareos_plugin_ctx, (bsdwVariable)var, &value); + plugin_ctx, (bsdwVariable)var, &value); } break; } default: - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-sd: PyBareosSetValue unknown variable requested %d\n", var); break; } @@ -808,14 +802,14 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (dbgmsg) { Dmsg(bareos_plugin_ctx, level, "python-sd: %s", dbgmsg); } + if (dbgmsg) { Dmsg(plugin_ctx, level, "python-sd: %s", dbgmsg); } Py_INCREF(Py_None); return Py_None; @@ -830,14 +824,14 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (jobmsg) { Jmsg(bareos_plugin_ctx, type, "python-sd: %s", jobmsg); } + if (jobmsg) { Jmsg(plugin_ctx, type, "python-sd: %s", jobmsg); } Py_INCREF(Py_None); return Py_None; @@ -851,7 +845,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -870,10 +864,10 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) event = PyInt_AsLong(pyEvent); if (event >= bsdEventJobStart && event <= bsdEventWriteRecordTranslation) { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "python-sd: PyBareosRegisterEvents registering event %d\n", event); - retval = bareos_core_functions->registerBareosEvents(bareos_plugin_ctx, 1, - event); + retval = + bareos_core_functions->registerBareosEvents(plugin_ctx, 1, event); if (retval != bRC_OK) { break; } } @@ -893,7 +887,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -912,10 +906,10 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) event = PyInt_AsLong(pyEvent); if (event >= bsdEventJobStart && event <= bsdEventWriteRecordTranslation) { - Dmsg(bareos_plugin_ctx, debuglevel, + Dmsg(plugin_ctx, debuglevel, "PyBareosUnRegisterEvents: registering event %d\n", event); - retval = bareos_core_functions->unregisterBareosEvents(bareos_plugin_ctx, - 1, event); + retval = + bareos_core_functions->unregisterBareosEvents(plugin_ctx, 1, event); if (retval != bRC_OK) { break; } } @@ -935,22 +929,21 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - PluginContext* bareos_plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (!bareos_plugin_ctx) { - PyErr_SetString(PyExc_ValueError, "bareos_plugin_ctx is unset"); + if (!plugin_ctx) { + PyErr_SetString(PyExc_ValueError, "plugin_ctx is unset"); return NULL; } if (!bareos_core_functions) { PyErr_SetString(PyExc_ValueError, "bareos_core_functions is unset"); return NULL; } - if (bareos_core_functions->getInstanceCount(bareos_plugin_ctx, &value) == - bRC_OK) { + if (bareos_core_functions->getInstanceCount(plugin_ctx, &value) == bRC_OK) { pRetVal = PyInt_FromLong(value); } From 3e779f4ea02c28f875e7d6997a61a4bb188cc11b Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 8 May 2020 13:54:11 +0200 Subject: [PATCH 087/341] python plugins: add module-global plugin_context --- core/src/plugins/filed/python/bareosfd.cc | 44 ++++++++------- core/src/plugins/filed/python/bareosfd.h | 63 +++++++--------------- core/src/plugins/filed/python/python-fd.cc | 19 ------- core/src/plugins/python_plugins_common.inc | 4 +- 4 files changed, 43 insertions(+), 87 deletions(-) diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 3017473e9a6..4e421514b4f 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -45,9 +45,7 @@ static const int debuglevel = 150; static bRC set_bareos_core_functions( BareosCoreFunctions* new_bareos_core_functions); - - -static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); +static bRC set_plugin_context(PluginContext* new_plugin_context); static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); static bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, @@ -77,7 +75,7 @@ static bRC PyHandleBackupFile(PluginContext* plugin_ctx, struct save_pkt* sp); /* Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; +// static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; #include "plugin_private_context.h" @@ -1313,7 +1311,7 @@ static bRC PyHandleBackupFile(PluginContext* plugin_ctx, struct save_pkt* sp) static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } @@ -1385,7 +1383,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; bRC retval = bRC_Error; PyObject* pyValue; @@ -1434,7 +1432,7 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; /* plugin_private_context* ppc = */ /* (plugin_private_context*)plugin_ctx->plugin_private_context; */ @@ -1458,7 +1456,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; @@ -1479,7 +1477,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -1520,7 +1518,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -1559,7 +1557,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } @@ -1585,7 +1583,7 @@ static PyObject* PyBareosAddExclude(PyObject* self, PyObject* args) { char* file = NULL; bRC retval = bRC_Error; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; if (!PyArg_ParseTuple(args, "|z:BareosAddExclude", &file)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() @@ -1604,7 +1602,7 @@ static PyObject* PyBareosAddInclude(PyObject* self, PyObject* args) { char* file = NULL; bRC retval = bRC_Error; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; if (!PyArg_ParseTuple(args, "|z:BareosAddInclude", &file)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() @@ -1623,7 +1621,7 @@ static PyObject* PyBareosAddOptions(PyObject* self, PyObject* args) { char* opts = NULL; bRC retval = bRC_Error; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; if (!PyArg_ParseTuple(args, "|z:BareosAddOptions", &opts)) { goto bail_out; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() @@ -1643,7 +1641,7 @@ static PyObject* PyBareosAddRegex(PyObject* self, PyObject* args) int type; char* item = NULL; bRC retval = bRC_Error; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; if (!PyArg_ParseTuple(args, "|zi:BareosAddRegex", &item, &type)) { goto bail_out; } @@ -1666,7 +1664,7 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) int type; char* item = NULL; bRC retval = bRC_Error; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; if (!PyArg_ParseTuple(args, "|zi:BareosAddWild", &item, &type)) { goto bail_out; @@ -1685,7 +1683,7 @@ static PyObject* PyBareosAddWild(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) { - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewOptions")) { goto bail_out; } @@ -1703,7 +1701,7 @@ static PyObject* PyBareosNewOptions(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) { - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewInclude")) { goto bail_out; } @@ -1721,7 +1719,7 @@ static PyObject* PyBareosNewInclude(PyObject* self, PyObject* args) */ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) { - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; bRC retval = bRC_Error; if (!PyArg_ParseTuple(args, ":BareosNewPreInclude")) { goto bail_out; } @@ -1740,7 +1738,7 @@ static PyObject* PyBareosNewPreInclude(PyObject* self, PyObject* args) */ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) { - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; struct save_pkt sp; bRC retval = bRC_Error; @@ -1794,7 +1792,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) */ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) { - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; struct save_pkt sp; bRC retval = bRC_Error; PySavePacket* pSavePkt; @@ -1837,7 +1835,7 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) { bool all; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; @@ -1862,7 +1860,7 @@ static PyObject* PyBareosSetSeenBitmap(PyObject* self, PyObject* args) static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) { bool all; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; char* fname = NULL; bRC retval = bRC_Error; PyObject* pyBool; diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/bareosfd.h index d5e75eccbf7..a93b63cbf72 100644 --- a/core/src/plugins/filed/python/bareosfd.h +++ b/core/src/plugins/filed/python/bareosfd.h @@ -741,44 +741,39 @@ static PyMethodDef Methods[] = { static bRC set_bareos_core_functions( BareosCoreFunctions* new_bareos_core_functions); static bRC set_plugin_context(PluginContext* new_plugin_context); -static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype); -static bRC PyParsePluginDefinition(PluginContext* bareos_plugin_ctx, - void* value); -static bRC PyGetPluginValue(PluginContext* bareos_plugin_ctx, +static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); +static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); +static bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); -static bRC PySetPluginValue(PluginContext* bareos_plugin_ctx, +static bRC PySetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); -static bRC PyHandlePluginEvent(PluginContext* bareos_plugin_ctx, +static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, bEvent* event, void* value); -static bRC PyStartBackupFile(PluginContext* bareos_plugin_ctx, - struct save_pkt* sp); -static bRC PyEndBackupFile(PluginContext* bareos_plugin_ctx); -static bRC PyPluginIO(PluginContext* bareos_plugin_ctx, struct io_pkt* io); -static bRC PyStartRestoreFile(PluginContext* bareos_plugin_ctx, - const char* cmd); -static bRC PyEndRestoreFile(PluginContext* bareos_plugin_ctx); -static bRC PyCreateFile(PluginContext* bareos_plugin_ctx, - struct restore_pkt* rp); -static bRC PySetFileAttributes(PluginContext* bareos_plugin_ctx, +static bRC PyStartBackupFile(PluginContext* plugin_ctx, struct save_pkt* sp); +static bRC PyEndBackupFile(PluginContext* plugin_ctx); +static bRC PyPluginIO(PluginContext* plugin_ctx, struct io_pkt* io); +static bRC PyStartRestoreFile(PluginContext* plugin_ctx, const char* cmd); +static bRC PyEndRestoreFile(PluginContext* plugin_ctx); +static bRC PyCreateFile(PluginContext* plugin_ctx, struct restore_pkt* rp); +static bRC PySetFileAttributes(PluginContext* plugin_ctx, struct restore_pkt* rp); -static bRC PyCheckFile(PluginContext* bareos_plugin_ctx, char* fname); -static bRC PyGetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC PySetAcl(PluginContext* bareos_plugin_ctx, acl_pkt* ap); -static bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); -static bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, +static bRC PyCheckFile(PluginContext* plugin_ctx, char* fname); +static bRC PyGetAcl(PluginContext* plugin_ctx, acl_pkt* ap); +static bRC PySetAcl(PluginContext* plugin_ctx, acl_pkt* ap); +static bRC PyGetXattr(PluginContext* plugin_ctx, xattr_pkt* xp); +static bRC PySetXattr(PluginContext* plugin_ctx, xattr_pkt* xp); +static bRC PyRestoreObjectData(PluginContext* plugin_ctx, struct restore_object_pkt* rop); -static bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, - struct save_pkt* sp); +static bRC PyHandleBackupFile(PluginContext* plugin_ctx, struct save_pkt* sp); } /* namespace filedaemon */ using namespace filedaemon; /* variables storing bareos pointers */ -static void* plugin_context = NULL; +PluginContext* plugin_context = NULL; static void* bareos_core_functions = NULL; #ifdef __cplusplus @@ -806,24 +801,6 @@ MOD_INIT(bareosfd) if (c_api_object != NULL) PyModule_AddObject(m, "_C_API", c_api_object); -#if 0 - /* add PluginContext Capsule */ - PyObject* PyModulePluginContext = PyCapsule_New( - (void*)&plugin_context, PYTHON_MODULE_NAME_QUOTED ".PluginContext", NULL); - if (!PyModulePluginContext) { - printf(PYTHON_MODULE_NAME_QUOTED ":PluginContext PyCapsule_New failed\n"); - return MOD_ERROR_VAL; - } - if (PyModulePluginContext) { - PyModule_AddObject(m, "PluginContext", PyModulePluginContext); - printf(PYTHON_MODULE_NAME_QUOTED ": added PluginContext@%p\n", - &plugin_context); - } else { - printf(PYTHON_MODULE_NAME_QUOTED - ":PluginContext PyModule_AddObject failed\n"); - return MOD_ERROR_VAL; - } -#endif /* add bpFuncs Capsule */ PyObject* PyModulePluginFuncs = PyCapsule_New((void*)&bareos_core_functions, diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 452b9b82455..c6e01395714 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -92,25 +92,6 @@ static bRC PySetPluginValue(PluginContext* plugin_ctx, /* Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; - -static PluginInformation pluginInfo = { - sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, - FD_PLUGIN_MAGIC, PLUGIN_LICENSE, - PLUGIN_AUTHOR, PLUGIN_DATE, - PLUGIN_VERSION, PLUGIN_DESCRIPTION, - PLUGIN_USAGE}; - -static pFuncs pluginFuncs = { - sizeof(pluginFuncs), FD_PLUGIN_INTERFACE_VERSION, - - /* Entry points into plugin */ - newPlugin, /* new plugin instance */ - freePlugin, /* free plugin instance */ - getPluginValue, setPluginValue, handlePluginEvent, startBackupFile, - endBackupFile, startRestoreFile, endRestoreFile, pluginIO, createFile, - setFileAttributes, checkFile, getAcl, setAcl, getXattr, setXattr}; - #include "plugin_private_context.h" diff --git a/core/src/plugins/python_plugins_common.inc b/core/src/plugins/python_plugins_common.inc index 89dcba4b632..295ea9f1c42 100644 --- a/core/src/plugins/python_plugins_common.inc +++ b/core/src/plugins/python_plugins_common.inc @@ -166,7 +166,7 @@ static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype) free(error_string); } - +#if 0 static void StorePluginContextInPythonModule(PluginContext* bareos_plugin_ctx) { /* get the pointer to the module variable that is exported via the capsule */ @@ -187,7 +187,7 @@ static PluginContext* GetPluginContextFromPythonModule() (PluginContext**)PyCapsule_Import(capsule_name, 0); return *retval; } - +#endif /** * Convert a return value into a bRC enum value. */ From 93f996310de5a78e160f25a38ac60579bb371609 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 8 May 2020 16:38:56 +0200 Subject: [PATCH 088/341] plugins: apply changes to other daemon python plugins --- core/src/dird/dir_plugins.cc | 19 +- core/src/dird/dir_plugins.h | 4 +- core/src/plugins/dird/python/bareosdir.cc | 503 +-------------------- core/src/plugins/dird/python/python-dir.cc | 107 +++-- core/src/plugins/dird/python/python-dir.h | 132 ------ core/src/plugins/filed/python/bareosfd.cc | 3 +- core/src/plugins/filed/python/python-fd.cc | 5 - core/src/tools/bpluginfo.cc | 4 +- 8 files changed, 107 insertions(+), 670 deletions(-) diff --git a/core/src/dird/dir_plugins.cc b/core/src/dird/dir_plugins.cc index edb4b6eb9b9..937c1547880 100644 --- a/core/src/dird/dir_plugins.cc +++ b/core/src/dird/dir_plugins.cc @@ -67,16 +67,19 @@ static bRC bareosDebugMsg(PluginContext* ctx, static bool IsPluginCompatible(Plugin* plugin); /* BAREOS info */ -static bDirInfo bareos_plugin_interface_version = { - sizeof(bDirFuncs), DIR_PLUGIN_INTERFACE_VERSION}; +static Dir_PluginApiDefiniton bareos_plugin_interface_version = { + sizeof(DirCoreFunctions), DIR_PLUGIN_INTERFACE_VERSION}; /* BAREOS entry points */ -static bDirFuncs bareos_core_functions = { - sizeof(bDirFuncs), DIR_PLUGIN_INTERFACE_VERSION, - bareosRegisterEvents, bareosUnRegisterEvents, - bareosGetInstanceCount, bareosGetValue, - bareosSetValue, bareosJobMsg, - bareosDebugMsg}; +static DirCoreFunctions bareos_core_functions = {sizeof(DirCoreFunctions), + DIR_PLUGIN_INTERFACE_VERSION, + bareosRegisterEvents, + bareosUnRegisterEvents, + bareosGetInstanceCount, + bareosGetValue, + bareosSetValue, + bareosJobMsg, + bareosDebugMsg}; /* * BAREOS private context diff --git a/core/src/dird/dir_plugins.h b/core/src/dird/dir_plugins.h index 137c8e687e3..7cdcc5fee8e 100644 --- a/core/src/dird/dir_plugins.h +++ b/core/src/dird/dir_plugins.h @@ -129,7 +129,7 @@ typedef struct s_bDirEvent { typedef struct s_dirbareosInfo { uint32_t size; uint32_t version; -} bDirInfo; +} Dir_PluginApiDefiniton; #ifdef __cplusplus extern "C" { @@ -159,7 +159,7 @@ typedef struct s_dirbareosFuncs { int level, const char* fmt, ...); -} bDirFuncs; +} DirCoreFunctions; /** * Bareos Core Routines -- not used within a plugin diff --git a/core/src/plugins/dird/python/bareosdir.cc b/core/src/plugins/dird/python/bareosdir.cc index 2f5e007f086..ed3d0f7caff 100644 --- a/core/src/plugins/dird/python/bareosdir.cc +++ b/core/src/plugins/dird/python/bareosdir.cc @@ -1,7 +1,6 @@ /* BAREOS® - Backup Archiving REcovery Open Sourced - Copyright (C) 2011-2014 Planets Communications B.V. Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or @@ -19,13 +18,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/* - * Marco van Wieringen, August 2012 - */ /** * @file - * Python Director Plugin program + * Python module for the Bareos director plugin */ +#define PY_SSIZE_T_CLEAN +#define BUILD_PLUGIN #if defined(HAVE_WIN32) #include "include/bareos.h" @@ -36,45 +34,19 @@ #endif #include "dird/dird.h" -#if (PY_VERSION_HEX < 0x02060000) -#error "Need at least Python version 2.6 or newer" -#endif -#include "python-dir.h" +#define BAREOSDIR_MODULE +#include "bareosdir.h" #include "lib/edit.h" namespace directordaemon { static const int debuglevel = 150; -#define PLUGIN_LICENSE "Bareos AGPLv3" -#define PLUGIN_AUTHOR "Marco van Wieringen" -#define PLUGIN_DATE "October 2013" -#define PLUGIN_VERSION "3" -#define PLUGIN_DESCRIPTION "Python Director Daemon Plugin" -#define PLUGIN_USAGE \ - "python:instance=:module_path=:module_" \ - "name=" - - -/* Forward referenced functions */ -static bRC newPlugin(PluginContext* plugin_ctx); -static bRC freePlugin(PluginContext* plugin_ctx); -static bRC getPluginValue(PluginContext* plugin_ctx, - pVariable var, - void* value); -static bRC setPluginValue(PluginContext* plugin_ctx, - pVariable var, - void* value); -static bRC handlePluginEvent(PluginContext* plugin_ctx, - bDirEvent* event, - void* value); -static bRC parse_plugin_definition(PluginContext* plugin_ctx, - void* value, - PoolMem& plugin_options); - -static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); -static bRC PyLoadModule(PluginContext* plugin_ctx, void* value); +static bRC set_bareos_core_functions( + DirCoreFunctions* new_bareos_core_functions); +static bRC set_plugin_context(PluginContext* new_plugin_context); + static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); static bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, @@ -88,470 +60,27 @@ static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, /* Pointers to Bareos functions */ static bDirFuncs* bareos_core_functions = NULL; -static bDirInfo* bareos_plugin_interface_version = NULL; - -static PluginInformation pluginInfo = { - sizeof(pluginInfo), DIR_PLUGIN_INTERFACE_VERSION, - DIR_PLUGIN_MAGIC, PLUGIN_LICENSE, - PLUGIN_AUTHOR, PLUGIN_DATE, - PLUGIN_VERSION, PLUGIN_DESCRIPTION, - PLUGIN_USAGE}; -static pDirFuncs pluginFuncs = { - sizeof(pluginFuncs), DIR_PLUGIN_INTERFACE_VERSION, - - /* Entry points into plugin */ - newPlugin, /* new plugin instance */ - freePlugin, /* free plugin instance */ - getPluginValue, setPluginValue, handlePluginEvent}; - -/** - * Plugin private context - */ -struct plugin_private_context { - int64_t instance; /* Instance number of plugin */ - bool python_loaded; /* Plugin has python module loaded ? */ - bool python_path_set; /* Python plugin search path is set ? */ - char* module_path; /* Plugin Module Path */ - char* module_name; /* Plugin Module Name */ - PyThreadState* - interpreter; /* Python interpreter for this instance of the plugin */ - PyObject* pModule; /* Python Module entry point */ - PyObject* pyModuleFunctionsDict; /* Python Dictionary */ -}; - -/** - * We don't actually use this but we need it to tear down the - * final python interpreter on unload of the plugin. Each instance of - * the plugin get its own interpreter. - */ -static PyThreadState* mainThreadState; /* functions common to all plugins */ #include "plugins/python_plugins_common.inc" -#ifdef __cplusplus -extern "C" { -#endif - -/** - * loadPlugin() and unloadPlugin() are entry points that are - * exported, so Bareos can directly call these two entry points - * they are common to all Bareos plugins. - * - * External entry point called by Bareos to "load" the plugin - */ -bRC loadPlugin(bDirInfo* lbareos_plugin_interface_version, - bDirFuncs* lbareos_core_functions, - PluginInformation** plugin_information, - pDirFuncs** plugin_functions) +/* set the bareos_core_functions pointer to the given value */ +static bRC set_bareos_core_functions( + BareosCoreFunctions* new_bareos_core_functions) { - bareos_core_functions = - lbareos_core_functions; /* Set Bareos funct pointers */ - bareos_plugin_interface_version = lbareos_plugin_interface_version; - - *plugin_information = &pluginInfo; /* Return pointer to our info */ - *plugin_functions = &pluginFuncs; /* Return pointer to our functions */ - - /* Setup Python */ -#if PY_MAJOR_VERSION >= 3 - PyImport_AppendInittab("bareosdir", &PyInit_bareosdir); -#else - PyImport_AppendInittab("bareosdir", initbareosdir); -#endif - Py_InitializeEx(0); - PyEval_InitThreads(); - mainThreadState = PyEval_SaveThread(); - + bareos_core_functions = new_bareos_core_functions; return bRC_OK; } -/** - * External entry point to unload the plugin - */ -bRC unloadPlugin() +/* set the plugin context pointer to the given value */ +static bRC set_plugin_context(PluginContext* new_plugin_context) { - /* - * Terminate Python - */ - PyEval_RestoreThread(mainThreadState); - Py_Finalize(); - + plugin_context = new_plugin_context; return bRC_OK; } -#ifdef __cplusplus -} -#endif - -/* Create a new instance of the plugin i.e. allocate our private storage */ -static bRC newPlugin(PluginContext* plugin_ctx) -{ - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)malloc( - sizeof(struct plugin_private_context)); - if (!plugin_priv_ctx) { return bRC_Error; } - memset(plugin_priv_ctx, 0, sizeof(struct plugin_private_context)); - plugin_ctx->plugin_private_context = - (void*)plugin_priv_ctx; /* set our context pointer */ - - /* For each plugin instance we instantiate a new Python interpreter. */ - PyEval_AcquireThread(mainThreadState); - plugin_priv_ctx->interpreter = Py_NewInterpreter(); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - - /* - * Always register some events the python plugin itself can register - * any other events it is interested in. - */ - bareos_core_functions->registerBareosEvents(plugin_ctx, 1, - bDirEventNewPluginOptions); - - return bRC_OK; -} - -/* Free a plugin instance, i.e. release our private storage */ -static bRC freePlugin(PluginContext* plugin_ctx) -{ - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)plugin_ctx->plugin_private_context; - - if (!plugin_priv_ctx) { return bRC_Error; } - - /* - * Stop any sub interpreter started per plugin instance. - */ - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - - - if (plugin_priv_ctx->pModule) { Py_DECREF(plugin_priv_ctx->pModule); } - - Py_EndInterpreter(plugin_priv_ctx->interpreter); - PyEval_ReleaseLock(); - - free(plugin_priv_ctx); - plugin_ctx->plugin_private_context = NULL; - - return bRC_OK; -} - - -static bRC handlePluginEvent(PluginContext* plugin_ctx, - bDirEvent* event, - void* value) -{ - bRC retval = bRC_Error; - bool event_dispatched = false; - PoolMem plugin_options(PM_FNAME); - plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)plugin_ctx->plugin_private_context; - - if (!plugin_priv_ctx) { goto bail_out; } - - /* - * First handle some events internally before calling python if it - * want to do some special handling on the event triggered. - */ - switch (event->eventType) { - case bDirEventNewPluginOptions: - event_dispatched = true; - retval = parse_plugin_definition(plugin_ctx, value, plugin_options); - break; - default: - break; - } - - /* - * See if we have been triggered in the previous switch if not we have to - * always dispatch the event. If we already processed the event internally - * we only do a dispatch to the python entry point when that internal - * processing was successful (e.g. retval == bRC_OK). - */ - if (!event_dispatched || retval == bRC_OK) { - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - - /* - * Now dispatch the event to Python. - * First the calls that need special handling. - */ - switch (event->eventType) { - case bDirEventNewPluginOptions: - /* - * See if we already loaded the Python modules. - */ - if (!plugin_priv_ctx->python_loaded) { - retval = PyLoadModule(plugin_ctx, plugin_options.c_str()); - } - - /* Only try to call when the loading succeeded. */ - if (retval == bRC_OK) { - retval = PyParsePluginDefinition(plugin_ctx, plugin_options.c_str()); - } - break; - default: - /* - * Handle the generic events e.g. the ones which are just passed on. - * We only try to call Python when we loaded the right module until - * that time we pretend the call succeeded. - */ - if (plugin_priv_ctx->python_loaded) { - retval = PyHandlePluginEvent(plugin_ctx, event, value); - } else { - retval = bRC_OK; - } - break; - } - - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - } - -bail_out: - return retval; -} - - -/** - * Parse the plugin definition passed in. - * - * The definition is in this form: - * - * python:module_path=:module_name=:... - */ -static bRC parse_plugin_definition(PluginContext* plugin_ctx, - void* value, - PoolMem& plugin_options) -{ - bool found; - int i, cnt; - PoolMem plugin_definition(PM_FNAME); - char *bp, *argument, *argument_value; - plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)plugin_ctx->plugin_private_context; - - if (!value) { return bRC_Error; } - - /* - * Parse the plugin definition. - * Make a private copy of the whole string. - */ - PmStrcpy(plugin_definition, (char*)value); - - bp = strchr(plugin_definition.c_str(), ':'); - if (!bp) { - Jmsg(plugin_ctx, M_FATAL, "python-dir: Illegal plugin definition %s\n", - plugin_definition.c_str()); - Dmsg(plugin_ctx, debuglevel, "python-dir: Illegal plugin definition %s\n", - plugin_definition.c_str()); - goto bail_out; - } - - /* - * Skip the first ':' - */ - bp++; - - cnt = 0; - while (bp) { - if (strlen(bp) == 0) { break; } - - /* - * Each argument is in the form: - * = - * - * So we setup the right pointers here, argument to the beginning - * of the argument, argument_value to the beginning of the argument_value. - */ - argument = bp; - argument_value = strchr(bp, '='); - if (!argument_value) { - Jmsg(plugin_ctx, M_FATAL, - "python-dir: Illegal argument %s without value\n", argument); - Dmsg(plugin_ctx, debuglevel, - "python-dir: Illegal argument %s without value\n", argument); - goto bail_out; - } - *argument_value++ = '\0'; - - /* - * See if there are more arguments and setup for the next run. - */ - bp = argument_value; - do { - bp = strchr(bp, ':'); - if (bp) { - if (*(bp - 1) != '\\') { - *bp++ = '\0'; - break; - } else { - bp++; - } - } - } while (bp); - - found = false; - for (i = 0; plugin_arguments[i].name; i++) { - if (Bstrcasecmp(argument, plugin_arguments[i].name)) { - int64_t* int_destination = NULL; - char** str_destination = NULL; - bool* bool_destination = NULL; - - switch (plugin_arguments[i].type) { - case argument_instance: - int_destination = &plugin_priv_ctx->instance; - break; - case argument_module_path: - str_destination = &plugin_priv_ctx->module_path; - break; - case argument_module_name: - str_destination = &plugin_priv_ctx->module_name; - break; - default: - break; - } - - if (int_destination) { - *int_destination = parse_integer(argument_value); - } - - if (str_destination) { SetString(str_destination, argument_value); } - - if (bool_destination) { - *bool_destination = ParseBoolean(argument_value); - } - - /* - * When we have a match break the loop. - */ - found = true; - break; - } - } - - /* - * If we didn't consume this parameter we add it to the plugin_options list. - */ - if (!found) { - PoolMem option(PM_FNAME); - - if (cnt) { - Mmsg(option, ":%s=%s", argument, argument_value); - PmStrcat(plugin_options, option.c_str()); - } else { - Mmsg(option, "%s=%s", argument, argument_value); - PmStrcat(plugin_options, option.c_str()); - } - cnt++; - } - } - - if (cnt > 0) { PmStrcat(plugin_options, ":"); } - - return bRC_OK; - -bail_out: - return bRC_Error; -} - -/** - * Initial load of the Python module. - * - * Based on the parsed plugin options we set some prerequisites like the - * module path and the module to load. We also load the dictionary used - * for looking up the Python methods. - */ -static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)plugin_ctx->plugin_private_context; - PyObject *sysPath, *mPath, *pName, *pFunc; - - /* - * See if we already setup the python search path. - */ - if (!plugin_priv_ctx->python_path_set) { - /* - * Extend the Python search path with the given module_path. - */ - if (plugin_priv_ctx->module_path) { - sysPath = PySys_GetObject((char*)"path"); - mPath = PyString_FromString(plugin_priv_ctx->module_path); - PyList_Append(sysPath, mPath); - Py_DECREF(mPath); - plugin_priv_ctx->python_path_set = true; - } - } - - /* - * Try to load the Python module by name. - */ - if (plugin_priv_ctx->module_name) { - Dmsg(plugin_ctx, debuglevel, - "python-dir: Trying to load module with name %s\n", - plugin_priv_ctx->module_name); - pName = PyString_FromString(plugin_priv_ctx->module_name); - plugin_priv_ctx->pModule = PyImport_Import(pName); - Py_DECREF(pName); - - if (!plugin_priv_ctx->pModule) { - Dmsg(plugin_ctx, debuglevel, - "python-dir: Failed to load module with name %s\n", - plugin_priv_ctx->module_name); - goto bail_out; - } - - Dmsg(plugin_ctx, debuglevel, - "python-dir: Successfully loaded module with name %s\n", - plugin_priv_ctx->module_name); - - /* - * Get the Python dictionary for lookups in the Python namespace. - */ - plugin_priv_ctx->pyModuleFunctionsDict = - PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ - - StorePluginContextInPythonModule(plugin_ctx); - - /* - * Lookup the load_bareos_plugin() function in the python module. - */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "load_bareos_plugin"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyObject *pPluginDefinition, *pRetVal; - - pPluginDefinition = PyString_FromString((char*)value); - if (!pPluginDefinition) { goto bail_out; } - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); - Py_DECREF(pPluginDefinition); - - if (!pRetVal) { - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - } - } else { - Dmsg(plugin_ctx, debuglevel, - "python-dir: Failed to find function named load_bareos_plugins()\n"); - goto bail_out; - } - - /* - * Keep track we successfully loaded. - */ - plugin_priv_ctx->python_loaded = true; - } - - return retval; - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } - - return retval; -} /** * Any plugin options which are passed in are dispatched here to a Python method diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index 2f5e007f086..ab2850cd9b5 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -19,13 +19,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/* - * Marco van Wieringen, August 2012 - */ /** * @file - * Python Director Plugin program + * Python plugin for the Bareos Director Daemon */ +#define PY_SSIZE_T_CLEAN +#define BUILD_PLUGIN #if defined(HAVE_WIN32) #include "include/bareos.h" @@ -36,11 +35,8 @@ #endif #include "dird/dird.h" -#if (PY_VERSION_HEX < 0x02060000) -#error "Need at least Python version 2.6 or newer" -#endif - #include "python-dir.h" +#include "bareosdir.h" #include "lib/edit.h" namespace directordaemon { @@ -75,7 +71,6 @@ static bRC parse_plugin_definition(PluginContext* plugin_ctx, static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); static bRC PyLoadModule(PluginContext* plugin_ctx, void* value); -static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); static bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); @@ -87,8 +82,8 @@ static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, void* value); /* Pointers to Bareos functions */ -static bDirFuncs* bareos_core_functions = NULL; -static bDirInfo* bareos_plugin_interface_version = NULL; +static DirCoreFunctions* bareos_core_functions = NULL; +static Dir_PluginApiDefiniton* bareos_plugin_interface_version = NULL; static PluginInformation pluginInfo = { sizeof(pluginInfo), DIR_PLUGIN_INTERFACE_VERSION, @@ -134,6 +129,45 @@ static PyThreadState* mainThreadState; extern "C" { #endif +static void PyErrorHandler() +{ + PyObject *type, *value, *traceback; + PyObject* tracebackModule; + char* error_string; + + PyErr_Fetch(&type, &value, &traceback); + + tracebackModule = PyImport_ImportModule("traceback"); + if (tracebackModule != NULL) { + PyObject *tbList, *emptyString, *strRetval; + + tbList = + PyObject_CallMethod(tracebackModule, (char*)"format_exception", + (char*)"OOO", type, value == NULL ? Py_None : value, + traceback == NULL ? Py_None : traceback); + + emptyString = PyString_FromString(""); + strRetval = + PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); + + error_string = strdup(PyString_AsString(strRetval)); + + Py_DECREF(tbList); + Py_DECREF(emptyString); + Py_DECREF(strRetval); + Py_DECREF(tracebackModule); + } else { + error_string = strdup("Unable to import traceback module."); + } + Py_DECREF(type); + Py_XDECREF(value); + Py_XDECREF(traceback); + printf("%s", error_string); + + free(error_string); + exit(1); +} + /** * loadPlugin() and unloadPlugin() are entry points that are @@ -142,11 +176,31 @@ extern "C" { * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(bDirInfo* lbareos_plugin_interface_version, - bDirFuncs* lbareos_core_functions, +bRC loadPlugin(Dir_PluginApiDefiniton* lbareos_plugin_interface_version, + DirCoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, pDirFuncs** plugin_functions) { + /* Setup Python */ + Py_InitializeEx(0); + /* import the bareosdir module */ + PyObject* bareosdirModule = PyImport_ImportModule("bareosdir"); + if (bareosdirModule) { + printf("loaded bareosdir successfully\n"); + } else { + printf("loading of bareosdir failed\n"); + if (PyErr_Occurred()) { PyErrorHandler(); } + } + + /* import the CAPI from the bareosdir python module + * afterwards, Bareosdir_* macros are initialized to + * point to the corresponding functions in the bareosdir python + * module */ + import_bareosdir(); + + /* set bareos_core_functions inside of barosdir module */ + Bareosdir_set_bareos_core_functions(lbareos_core_functions); + bareos_core_functions = lbareos_core_functions; /* Set Bareos funct pointers */ bareos_plugin_interface_version = lbareos_plugin_interface_version; @@ -154,13 +208,6 @@ bRC loadPlugin(bDirInfo* lbareos_plugin_interface_version, *plugin_information = &pluginInfo; /* Return pointer to our info */ *plugin_functions = &pluginFuncs; /* Return pointer to our functions */ - /* Setup Python */ -#if PY_MAJOR_VERSION >= 3 - PyImport_AppendInittab("bareosdir", &PyInit_bareosdir); -#else - PyImport_AppendInittab("bareosdir", initbareosdir); -#endif - Py_InitializeEx(0); PyEval_InitThreads(); mainThreadState = PyEval_SaveThread(); @@ -286,7 +333,8 @@ static bRC handlePluginEvent(PluginContext* plugin_ctx, /* Only try to call when the loading succeeded. */ if (retval == bRC_OK) { - retval = PyParsePluginDefinition(plugin_ctx, plugin_options.c_str()); + retval = Bareosfdir_PyParsePluginDefinition(plugin_ctx, + plugin_options.c_str()); } break; default: @@ -466,14 +514,9 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) struct plugin_private_context* plugin_priv_ctx = (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject *sysPath, *mPath, *pName, *pFunc; - - /* - * See if we already setup the python search path. - */ + /* See if we already setup the python search path. */ if (!plugin_priv_ctx->python_path_set) { - /* - * Extend the Python search path with the given module_path. - */ + /* Extend the Python search path with the given module_path. */ if (plugin_priv_ctx->module_path) { sysPath = PySys_GetObject((char*)"path"); mPath = PyString_FromString(plugin_priv_ctx->module_path); @@ -483,9 +526,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) } } - /* - * Try to load the Python module by name. - */ + /* Try to load the Python module by name. */ if (plugin_priv_ctx->module_name) { Dmsg(plugin_ctx, debuglevel, "python-dir: Trying to load module with name %s\n", @@ -511,7 +552,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) plugin_priv_ctx->pyModuleFunctionsDict = PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ - StorePluginContextInPythonModule(plugin_ctx); + // StorePluginContextInPythonModule(plugin_ctx); /* * Lookup the load_bareos_plugin() function in the python module. @@ -553,6 +594,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) return retval; } +#if 0 /** * Any plugin options which are passed in are dispatched here to a Python method * and it can parse the plugin options. This function is also called after @@ -945,4 +987,5 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) return pRetVal; } +#endif } /* namespace directordaemon */ diff --git a/core/src/plugins/dird/python/python-dir.h b/core/src/plugins/dird/python/python-dir.h index 543986ff99a..d332142d8b2 100644 --- a/core/src/plugins/dird/python/python-dir.h +++ b/core/src/plugins/dird/python/python-dir.h @@ -57,138 +57,6 @@ static plugin_argument plugin_arguments[] = { {"module_path", argument_module_path}, {"module_name", argument_module_name}, {NULL, argument_none}}; -/** - * Callback methods from Python. - */ -static PyObject* PyBareosGetValue(PyObject* self, PyObject* args); -static PyObject* PyBareosSetValue(PyObject* self, PyObject* args); -static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args); -static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args); -static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args); -static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args); -static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args); - -static PyMethodDef Methods[] = { - {"GetValue", PyBareosGetValue, METH_VARARGS, "Get a Plugin value"}, - {"SetValue", PyBareosSetValue, METH_VARARGS, "Set a Plugin value"}, - {"DebugMessage", PyBareosDebugMessage, METH_VARARGS, - "Print a Debug message"}, - {"JobMessage", PyBareosJobMessage, METH_VARARGS, "Print a Job message"}, - {"RegisterEvents", PyBareosRegisterEvents, METH_VARARGS, - "Register Plugin Events"}, - {"UnRegisterEvents", PyBareosUnRegisterEvents, METH_VARARGS, - "Unregister Plugin Events"}, - {"GetInstanceCount", PyBareosGetInstanceCount, METH_VARARGS, - "Get number of instances of current plugin"}, - {NULL, NULL, 0, NULL}}; - - -static void* bareos_PluginContext = NULL; - -// MOD_INIT(PYTHON_MODULE_NAME) -MOD_INIT(bareosdir) -{ - /* bareos_PluginContext holds the PluginContext instead of passing - * to Python and extracting it back like it was before. bareos_PluginContext - * needs to be set after loading the PYTHON_MODULE_NAME binary python module - * and will be used for all calls. - */ - - PyObject* m = NULL; - - /* Pointer Capsules to avoid context transfer back and forth */ - PyObject* PyModulePluginContext = - PyCapsule_New((void*)&bareos_PluginContext, - PYTHON_MODULE_NAME_QUOTED ".PluginContext", NULL); - - if (!PyModulePluginContext) { - printf(PYTHON_MODULE_NAME_QUOTED ": PyCapsule_New failed\n"); - return MOD_ERROR_VAL; - } - - MOD_DEF(m, PYTHON_MODULE_NAME_QUOTED, NULL, Methods) - - if (PyModulePluginContext) { - PyModule_AddObject(m, "PluginContext", PyModulePluginContext); - } else { - printf(PYTHON_MODULE_NAME_QUOTED ":PyModule_AddObject failed\n"); - return MOD_ERROR_VAL; - } - - - /* module dictionaries */ - DEFINE_bRCs_DICT(); - DEFINE_bJobMessageTypes_DICT(); - - const char* bDirVariable = "bDirVariable"; - PyObject* pDictbDirVariable = NULL; - pDictbDirVariable = PyDict_New(); - if (!pDictbDirVariable) { return MOD_ERROR_VAL; } - ConstSet_StrLong(pDictbDirVariable, bDirVarJob, 1); - ConstSet_StrLong(pDictbDirVariable, bDirVarLevel, 2); - ConstSet_StrLong(pDictbDirVariable, bDirVarType, 3); - ConstSet_StrLong(pDictbDirVariable, bDirVarJobId, 4); - ConstSet_StrLong(pDictbDirVariable, bDirVarClient, 5); - ConstSet_StrLong(pDictbDirVariable, bDirVarNumVols, 6); - ConstSet_StrLong(pDictbDirVariable, bDirVarPool, 7); - ConstSet_StrLong(pDictbDirVariable, bDirVarStorage, 8); - ConstSet_StrLong(pDictbDirVariable, bDirVarWriteStorage, 9); - ConstSet_StrLong(pDictbDirVariable, bDirVarReadStorage, 10); - ConstSet_StrLong(pDictbDirVariable, bDirVarCatalog, 11); - ConstSet_StrLong(pDictbDirVariable, bDirVarMediaType, 12); - ConstSet_StrLong(pDictbDirVariable, bDirVarJobName, 13); - ConstSet_StrLong(pDictbDirVariable, bDirVarJobStatus, 14); - ConstSet_StrLong(pDictbDirVariable, bDirVarPriority, 15); - ConstSet_StrLong(pDictbDirVariable, bDirVarVolumeName, 16); - ConstSet_StrLong(pDictbDirVariable, bDirVarCatalogRes, 17); - ConstSet_StrLong(pDictbDirVariable, bDirVarJobErrors, 18); - ConstSet_StrLong(pDictbDirVariable, bDirVarJobFiles, 19); - ConstSet_StrLong(pDictbDirVariable, bDirVarSDJobFiles, 20); - ConstSet_StrLong(pDictbDirVariable, bDirVarSDErrors, 21); - ConstSet_StrLong(pDictbDirVariable, bDirVarFDJobStatus, 22); - ConstSet_StrLong(pDictbDirVariable, bDirVarSDJobStatus, 23); - ConstSet_StrLong(pDictbDirVariable, bDirVarPluginDir, 24); - ConstSet_StrLong(pDictbDirVariable, bDirVarLastRate, 25); - ConstSet_StrLong(pDictbDirVariable, bDirVarJobBytes, 26); - ConstSet_StrLong(pDictbDirVariable, bDirVarReadBytes, 27); - if (PyModule_AddObject(m, bDirVariable, pDictbDirVariable)) { - return MOD_ERROR_VAL; - } - - const char* bwDirVariable = "bwDirVariable"; - PyObject* pDictbwDirVariable = NULL; - pDictbwDirVariable = PyDict_New(); - if (!pDictbwDirVariable) { return MOD_ERROR_VAL; } - ConstSet_StrLong(pDictbwDirVariable, bwDirVarJobReport, 1); - ConstSet_StrLong(pDictbwDirVariable, bwDirVarVolumeName, 2); - ConstSet_StrLong(pDictbwDirVariable, bwDirVarPriority, 3); - ConstSet_StrLong(pDictbwDirVariable, bwDirVarJobLevel, 4); - if (PyModule_AddObject(m, bwDirVariable, pDictbwDirVariable)) { - return MOD_ERROR_VAL; - } - - const char* bDirEvent = "bDirEventType"; - PyObject* pDictbDirEvent = NULL; - pDictbDirEvent = PyDict_New(); - ConstSet_StrLong(pDictbDirEvent, bDirEventJobStart, 1); - ConstSet_StrLong(pDictbDirEvent, bDirEventJobEnd, 2); - ConstSet_StrLong(pDictbDirEvent, bDirEventJobInit, 3); - ConstSet_StrLong(pDictbDirEvent, bDirEventJobRun, 4); - ConstSet_StrLong(pDictbDirEvent, bDirEventVolumePurged, 5); - ConstSet_StrLong(pDictbDirEvent, bDirEventNewVolume, 6); - ConstSet_StrLong(pDictbDirEvent, bDirEventNeedVolume, 7); - ConstSet_StrLong(pDictbDirEvent, bDirEventVolumeFull, 8); - ConstSet_StrLong(pDictbDirEvent, bDirEventRecyle, 9); - ConstSet_StrLong(pDictbDirEvent, bDirEventGetScratch, 10); - ConstSet_StrLong(pDictbDirEvent, bDirEventNewPluginOptions, 11); - if (!pDictbDirEvent) { return MOD_ERROR_VAL; } - if (PyModule_AddObject(m, bDirEvent, pDictbDirEvent)) { - return MOD_ERROR_VAL; - } - - - return MOD_SUCCESS_VAL(m); -} } /* namespace directordaemon */ #endif /* BAREOS_PLUGINS_DIRD_PYTHON_DIR_H_ */ diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 4e421514b4f..b4d541c0067 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -20,7 +20,7 @@ */ /** * @file - * Python module for the bareos filedaemon plugin + * Python module for the Bareos filedaemon plugin */ #define PY_SSIZE_T_CLEAN #define BUILD_PLUGIN @@ -75,7 +75,6 @@ static bRC PyHandleBackupFile(PluginContext* plugin_ctx, struct save_pkt* sp); /* Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; -// static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; #include "plugin_private_context.h" diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index c6e01395714..ab7e9301788 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -972,11 +972,6 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) plugin_priv_ctx->pyModuleFunctionsDict = PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ - /* Encode the PluginContext so a Python method can pass it in on - * calling back.*/ - /* plugin_priv_ctx->py_PluginContext = - * PyCreatePluginContext(plugin_ctx); */ - StorePluginContextInPythonModule(plugin_ctx); /* Lookup the load_bareos_plugin() function in the python module. */ diff --git a/core/src/tools/bpluginfo.cc b/core/src/tools/bpluginfo.cc index ea17169b127..d0c07f09e99 100644 --- a/core/src/tools/bpluginfo.cc +++ b/core/src/tools/bpluginfo.cc @@ -105,13 +105,13 @@ struct _bareosfuncs { }; /* - * bDirInfo + * Dir_PluginApiDefiniton * Core_PluginApiDefinition * bsdInfo */ typedef union _bareosinfos bareosinfos; union _bareosinfos { - directordaemon::bDirInfo bdirinfo; + directordaemon::Dir_PluginApiDefiniton bdirinfo; filedaemon::Core_PluginApiDefinition bfdinfo; storagedaemon::bsdInfo bsdinfo; }; From ad9058bfd74956837f26ae82372d25f8bb90263e Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 8 May 2020 16:44:15 +0200 Subject: [PATCH 089/341] python-dir: works basically --- core/src/plugins/dird/python/python-dir.cc | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index ab2850cd9b5..b782ce971c7 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -71,15 +71,6 @@ static bRC parse_plugin_definition(PluginContext* plugin_ctx, static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); static bRC PyLoadModule(PluginContext* plugin_ctx, void* value); -static bRC PyGetPluginValue(PluginContext* plugin_ctx, - pVariable var, - void* value); -static bRC PySetPluginValue(PluginContext* plugin_ctx, - pVariable var, - void* value); -static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, - bDirEvent* event, - void* value); /* Pointers to Bareos functions */ static DirCoreFunctions* bareos_core_functions = NULL; @@ -122,6 +113,8 @@ struct plugin_private_context { */ static PyThreadState* mainThreadState; + +#define NOPLUGINSETGETVALUE /* functions common to all plugins */ #include "plugins/python_plugins_common.inc" @@ -333,8 +326,8 @@ static bRC handlePluginEvent(PluginContext* plugin_ctx, /* Only try to call when the loading succeeded. */ if (retval == bRC_OK) { - retval = Bareosfdir_PyParsePluginDefinition(plugin_ctx, - plugin_options.c_str()); + retval = Bareosdir_PyParsePluginDefinition(plugin_ctx, + plugin_options.c_str()); } break; default: @@ -344,7 +337,7 @@ static bRC handlePluginEvent(PluginContext* plugin_ctx, * that time we pretend the call succeeded. */ if (plugin_priv_ctx->python_loaded) { - retval = PyHandlePluginEvent(plugin_ctx, event, value); + retval = Bareosdir_PyHandlePluginEvent(plugin_ctx, event, value); } else { retval = bRC_OK; } From 64b3aebdb87fdeff721433a555f64612ae456858 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 11 May 2020 13:41:27 +0200 Subject: [PATCH 090/341] python dir and sd plugins: build sucessfully --- core/src/dird/dir_plugins.cc | 2 +- core/src/dird/dir_plugins.h | 2 +- core/src/plugins/dird/python/bareosdir.h | 213 ++++++++++++ .../dird/python/bareosdir_api_funcs.txt | 6 + .../create_CAPI_from_bareos_api_funcs.sh | 46 +++ core/src/plugins/dird/python/python-dir.cc | 7 +- core/src/plugins/filed/python/bareosfd.h | 25 -- core/src/plugins/filed/python/python-fd.cc | 22 +- core/src/plugins/stored/python/python-sd.cc | 312 +----------------- core/src/tools/bpluginfo.cc | 2 +- 10 files changed, 297 insertions(+), 340 deletions(-) create mode 100644 core/src/plugins/dird/python/bareosdir.h create mode 100644 core/src/plugins/dird/python/bareosdir_api_funcs.txt create mode 100755 core/src/plugins/dird/python/create_CAPI_from_bareos_api_funcs.sh diff --git a/core/src/dird/dir_plugins.cc b/core/src/dird/dir_plugins.cc index 937c1547880..0119757fd11 100644 --- a/core/src/dird/dir_plugins.cc +++ b/core/src/dird/dir_plugins.cc @@ -67,7 +67,7 @@ static bRC bareosDebugMsg(PluginContext* ctx, static bool IsPluginCompatible(Plugin* plugin); /* BAREOS info */ -static Dir_PluginApiDefiniton bareos_plugin_interface_version = { +static Dir_PluginApiDefinition bareos_plugin_interface_version = { sizeof(DirCoreFunctions), DIR_PLUGIN_INTERFACE_VERSION}; /* BAREOS entry points */ diff --git a/core/src/dird/dir_plugins.h b/core/src/dird/dir_plugins.h index 7cdcc5fee8e..17ce966bdc5 100644 --- a/core/src/dird/dir_plugins.h +++ b/core/src/dird/dir_plugins.h @@ -129,7 +129,7 @@ typedef struct s_bDirEvent { typedef struct s_dirbareosInfo { uint32_t size; uint32_t version; -} Dir_PluginApiDefiniton; +} Dir_PluginApiDefinition; #ifdef __cplusplus extern "C" { diff --git a/core/src/plugins/dird/python/bareosdir.h b/core/src/plugins/dird/python/bareosdir.h new file mode 100644 index 00000000000..9a950e07f04 --- /dev/null +++ b/core/src/plugins/dird/python/bareosdir.h @@ -0,0 +1,213 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2013-2014 Planets Communications B.V. + Copyright (C) 2013-2020 Bareos GmbH & Co. KG + + This program is Free Software; you can modify it under the terms of + version three of the GNU Affero General Public License as published by the + Free Software Foundation, which is listed in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +/** + * @file + * This defines the Python types in C++ and the callbacks from Python we + * support. + */ + +#ifndef BAREOS_PLUGINS_DIRD_BAREOSDIR_H_ +#define BAREOS_PLUGINS_DIRD_BAREOSDIR_H_ 1 + +#define PYTHON_MODULE_NAME bareosdir +#define PYTHON_MODULE_NAME_QUOTED "bareosdir" + +/* common code for all python plugins */ +#include "plugins/python_plugins_common.h" + + +/* include automatically generated C API */ +#include "capi_1.inc" + + +#ifdef BAREOSDIR_MODULE +/* This section is used when compiling bareosdir.cc */ + +namespace filedaemon { + +/** + * Python structures mapping C++ ones. + */ + +/** + * Callback methods from Python. + */ +static PyObject* PyBareosGetValue(PyObject* self, PyObject* args); +static PyObject* PyBareosSetValue(PyObject* self, PyObject* args); +static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args); +static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args); +static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args); +static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args); +static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args); + +static PyMethodDef Methods[] = { + {"GetValue", PyBareosGetValue, METH_VARARGS, "Get a Plugin value"}, + {"SetValue", PyBareosSetValue, METH_VARARGS, "Set a Plugin value"}, + {"DebugMessage", PyBareosDebugMessage, METH_VARARGS, + "Print a Debug message"}, + {"JobMessage", PyBareosJobMessage, METH_VARARGS, "Print a Job message"}, + {"RegisterEvents", PyBareosRegisterEvents, METH_VARARGS, + "Register Plugin Events"}, + {"UnRegisterEvents", PyBareosUnRegisterEvents, METH_VARARGS, + "Unregister Plugin Events"}, + {"GetInstanceCount", PyBareosGetInstanceCount, METH_VARARGS, + "Get number of instances of current plugin"}, + {NULL, NULL, 0, NULL}}; + + +static void* bareos_PluginContext = NULL; + +} // namespace filedaemon +using namespace directordaemon; + +/* variables storing bareos pointers */ +PluginContext* plugin_context = NULL; +static void* bareos_core_functions = NULL; + +MOD_INIT(bareosdir) +{ + PyObject* m = NULL; + MOD_DEF(m, PYTHON_MODULE_NAME_QUOTED, NULL, Methods) + static void* Bareosdir_API[Bareosdir_API_pointers]; + PyObject* c_api_object; + + /* Initialize the C API pointer array */ +#include "capi_3.inc" + + /* Create a Capsule containing the API pointer array's address */ + c_api_object = PyCapsule_New((void*)Bareosdir_API, + PYTHON_MODULE_NAME_QUOTED "._C_API", NULL); + + if (c_api_object != NULL) PyModule_AddObject(m, "_C_API", c_api_object); + + /* add bpFuncs Capsule */ + PyObject* PyModulePluginFuncs = + PyCapsule_New((void*)&bareos_core_functions, + PYTHON_MODULE_NAME_QUOTED ".BareosCoreFunctions", NULL); + if (!PyModulePluginFuncs) { + printf(PYTHON_MODULE_NAME_QUOTED + ":BareosCoreFunctions PyCapsule_New failed\n"); + return MOD_ERROR_VAL; + } + if (PyModulePluginFuncs) { + PyModule_AddObject(m, "BareosCoreFunctions", PyModulePluginFuncs); + printf(PYTHON_MODULE_NAME_QUOTED ": added BareosCoreFunctions@%p\n", + &bareos_core_functions); + } else { + printf(PYTHON_MODULE_NAME_QUOTED + ":BareosCoreFunctions PyModule_AddObject failed\n"); + return MOD_ERROR_VAL; + } + + + /* module dictionaries */ + DEFINE_bRCs_DICT(); + DEFINE_bJobMessageTypes_DICT(); + + const char* bDirVariable = "bDirVariable"; + PyObject* pDictbDirVariable = NULL; + pDictbDirVariable = PyDict_New(); + if (!pDictbDirVariable) { return MOD_ERROR_VAL; } + ConstSet_StrLong(pDictbDirVariable, bDirVarJob, 1); + ConstSet_StrLong(pDictbDirVariable, bDirVarLevel, 2); + ConstSet_StrLong(pDictbDirVariable, bDirVarType, 3); + ConstSet_StrLong(pDictbDirVariable, bDirVarJobId, 4); + ConstSet_StrLong(pDictbDirVariable, bDirVarClient, 5); + ConstSet_StrLong(pDictbDirVariable, bDirVarNumVols, 6); + ConstSet_StrLong(pDictbDirVariable, bDirVarPool, 7); + ConstSet_StrLong(pDictbDirVariable, bDirVarStorage, 8); + ConstSet_StrLong(pDictbDirVariable, bDirVarWriteStorage, 9); + ConstSet_StrLong(pDictbDirVariable, bDirVarReadStorage, 10); + ConstSet_StrLong(pDictbDirVariable, bDirVarCatalog, 11); + ConstSet_StrLong(pDictbDirVariable, bDirVarMediaType, 12); + ConstSet_StrLong(pDictbDirVariable, bDirVarJobName, 13); + ConstSet_StrLong(pDictbDirVariable, bDirVarJobStatus, 14); + ConstSet_StrLong(pDictbDirVariable, bDirVarPriority, 15); + ConstSet_StrLong(pDictbDirVariable, bDirVarVolumeName, 16); + ConstSet_StrLong(pDictbDirVariable, bDirVarCatalogRes, 17); + ConstSet_StrLong(pDictbDirVariable, bDirVarJobErrors, 18); + ConstSet_StrLong(pDictbDirVariable, bDirVarJobFiles, 19); + ConstSet_StrLong(pDictbDirVariable, bDirVarSDJobFiles, 20); + ConstSet_StrLong(pDictbDirVariable, bDirVarSDErrors, 21); + ConstSet_StrLong(pDictbDirVariable, bDirVarFDJobStatus, 22); + ConstSet_StrLong(pDictbDirVariable, bDirVarSDJobStatus, 23); + ConstSet_StrLong(pDictbDirVariable, bDirVarPluginDir, 24); + ConstSet_StrLong(pDictbDirVariable, bDirVarLastRate, 25); + ConstSet_StrLong(pDictbDirVariable, bDirVarJobBytes, 26); + ConstSet_StrLong(pDictbDirVariable, bDirVarReadBytes, 27); + if (PyModule_AddObject(m, bDirVariable, pDictbDirVariable)) { + return MOD_ERROR_VAL; + } + + const char* bwDirVariable = "bwDirVariable"; + PyObject* pDictbwDirVariable = NULL; + pDictbwDirVariable = PyDict_New(); + if (!pDictbwDirVariable) { return MOD_ERROR_VAL; } + ConstSet_StrLong(pDictbwDirVariable, bwDirVarJobReport, 1); + ConstSet_StrLong(pDictbwDirVariable, bwDirVarVolumeName, 2); + ConstSet_StrLong(pDictbwDirVariable, bwDirVarPriority, 3); + ConstSet_StrLong(pDictbwDirVariable, bwDirVarJobLevel, 4); + if (PyModule_AddObject(m, bwDirVariable, pDictbwDirVariable)) { + return MOD_ERROR_VAL; + } + + const char* bDirEvent = "bDirEventType"; + PyObject* pDictbDirEvent = NULL; + pDictbDirEvent = PyDict_New(); + ConstSet_StrLong(pDictbDirEvent, bDirEventJobStart, 1); + ConstSet_StrLong(pDictbDirEvent, bDirEventJobEnd, 2); + ConstSet_StrLong(pDictbDirEvent, bDirEventJobInit, 3); + ConstSet_StrLong(pDictbDirEvent, bDirEventJobRun, 4); + ConstSet_StrLong(pDictbDirEvent, bDirEventVolumePurged, 5); + ConstSet_StrLong(pDictbDirEvent, bDirEventNewVolume, 6); + ConstSet_StrLong(pDictbDirEvent, bDirEventNeedVolume, 7); + ConstSet_StrLong(pDictbDirEvent, bDirEventVolumeFull, 8); + ConstSet_StrLong(pDictbDirEvent, bDirEventRecyle, 9); + ConstSet_StrLong(pDictbDirEvent, bDirEventGetScratch, 10); + ConstSet_StrLong(pDictbDirEvent, bDirEventNewPluginOptions, 11); + if (!pDictbDirEvent) { return MOD_ERROR_VAL; } + if (PyModule_AddObject(m, bDirEvent, pDictbDirEvent)) { + return MOD_ERROR_VAL; + } + + + return MOD_SUCCESS_VAL(m); +} + + +#else // NOT BAREOSDIR_MODULE + + +/* This section is used in modules that use bareosdir's API */ + +static void** Bareosdir_API; + +/* include automatically generated C API */ +#include "capi_2.inc" + +static int import_bareosdir() +{ + Bareosdir_API = (void**)PyCapsule_Import("bareosdir._C_API", 0); + return (Bareosdir_API != NULL) ? 0 : -1; +} +#endif // BAREOSDIR_MODULE + +#endif /* BAREOS_PLUGINS_DIRD_BAREOSDIR_H_ */ diff --git a/core/src/plugins/dird/python/bareosdir_api_funcs.txt b/core/src/plugins/dird/python/bareosdir_api_funcs.txt new file mode 100644 index 00000000000..bb5ba0f867f --- /dev/null +++ b/core/src/plugins/dird/python/bareosdir_api_funcs.txt @@ -0,0 +1,6 @@ +bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); +bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); +bRC PySetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); +bRC PyHandlePluginEvent(PluginContext* plugin_ctx, bDirEvent* event, void* value); +bRC set_bareos_core_functions( DirCoreFunctions* new_bareos_core_functions); +bRC set_plugin_context(PluginContext* new_plugin_context); diff --git a/core/src/plugins/dird/python/create_CAPI_from_bareos_api_funcs.sh b/core/src/plugins/dird/python/create_CAPI_from_bareos_api_funcs.sh new file mode 100755 index 00000000000..f3c83c8e290 --- /dev/null +++ b/core/src/plugins/dird/python/create_CAPI_from_bareos_api_funcs.sh @@ -0,0 +1,46 @@ +#!/bin/bash +IFS=' +' + +exec >capi_1.inc + +echo "/* C API functions */" +NUM=0 +for i in $(cat bareosdir_api_funcs.txt); do + retval=$(echo $i | sed 's/ .*//g') + funcname=$(echo $i | cut -b 5- | sed s/\(.*//g) + prot=$(echo $i | sed s/.*\(//g | sed 's/);//g') +echo " +/* static $i */ +#define Bareosdir_${funcname}_NUM $NUM +#define Bareosdir_${funcname}_RETURN $retval +#define Bareosdir_${funcname}_PROTO (${prot})" + +((NUM=NUM+1)) +done +echo " +/*Total Number of C API function pointers */ +#define Bareosdir_API_pointers $NUM" + +exec >capi_2.inc + +NUM=0 +for i in $(cat bareosdir_api_funcs.txt); do + retval=$(echo $i | sed 's/ .*//g') + funcname=$(echo $i | cut -b 5- | sed s/\(.*//g) + prot=$(echo $i | sed s/.*\(//g | sed 's/);//g') + echo "#define Bareosdir_${funcname} (*(Bareosdir_${funcname}_RETURN(*)Bareosdir_${funcname}_PROTO) Bareosdir_API[Bareosdir_${funcname}_NUM]) +" +((NUM=NUM+1)) +done + +exec >capi_3.inc + +NUM=0 +for i in $(cat bareosdir_api_funcs.txt); do + retval=$(echo $i | sed 's/ .*//g') + funcname=$(echo $i | cut -b 5- | sed s/\(.*//g) + prot=$(echo $i | sed s/.*\(//g | sed 's/);//g') + echo " Bareosdir_API[Bareosdir_${funcname}_NUM] = (void*)${funcname};" +((NUM=NUM+1)) +done diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index b782ce971c7..74ae8d908be 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -37,6 +37,7 @@ #include "python-dir.h" #include "bareosdir.h" +#include "lib/plugins.h" #include "lib/edit.h" namespace directordaemon { @@ -74,7 +75,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value); /* Pointers to Bareos functions */ static DirCoreFunctions* bareos_core_functions = NULL; -static Dir_PluginApiDefiniton* bareos_plugin_interface_version = NULL; +static Dir_PluginApiDefinition* bareos_plugin_interface_version = NULL; static PluginInformation pluginInfo = { sizeof(pluginInfo), DIR_PLUGIN_INTERFACE_VERSION, @@ -169,7 +170,7 @@ static void PyErrorHandler() * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(Dir_PluginApiDefiniton* lbareos_plugin_interface_version, +bRC loadPlugin(Dir_PluginApiDefinition* lbareos_plugin_interface_version, DirCoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, pDirFuncs** plugin_functions) @@ -519,7 +520,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) } } - /* Try to load the Python module by name. */ + /* Try to load the Python module by name. */ if (plugin_priv_ctx->module_name) { Dmsg(plugin_ctx, debuglevel, "python-dir: Trying to load module with name %s\n", diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/bareosfd.h index a93b63cbf72..c39f693a47f 100644 --- a/core/src/plugins/filed/python/bareosfd.h +++ b/core/src/plugins/filed/python/bareosfd.h @@ -776,15 +776,6 @@ using namespace filedaemon; PluginContext* plugin_context = NULL; static void* bareos_core_functions = NULL; -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - - MOD_INIT(bareosfd) { PyObject* m = NULL; @@ -820,22 +811,6 @@ MOD_INIT(bareosfd) return MOD_ERROR_VAL; } -#if 0 - /* add loadPlugin Capsule */ - PyObject* PyModuleLoadPlugin = PyCapsule_New( - (void*)&loadPlugin, PYTHON_MODULE_NAME_QUOTED ".loadPlugin", NULL); - if (!PyModuleLoadPlugin) { - printf(PYTHON_MODULE_NAME_QUOTED "loadPlugin PyCapsule_New failed\n"); - return MOD_ERROR_VAL; - } - if (PyModuleLoadPlugin) { - PyModule_AddObject(m, "loadPlugin", PyModuleLoadPlugin); - printf(PYTHON_MODULE_NAME_QUOTED ": added loadPlugin@%p\n", &loadPlugin); - } else { - printf(PYTHON_MODULE_NAME_QUOTED "loadPlugin PyModule_AddObject failed\n"); - return MOD_ERROR_VAL; - } -#endif PyRestoreObjectType.tp_new = PyType_GenericNew; if (PyType_Ready(&PyRestoreObjectType) < 0) { return MOD_ERROR_VAL; } diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index ab7e9301788..66da3549ae6 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -92,9 +92,27 @@ static bRC PySetPluginValue(PluginContext* plugin_ctx, /* Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; +static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; -#include "plugin_private_context.h" +static PluginInformation pluginInfo = { + sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, + FD_PLUGIN_MAGIC, PLUGIN_LICENSE, + PLUGIN_AUTHOR, PLUGIN_DATE, + PLUGIN_VERSION, PLUGIN_DESCRIPTION, + PLUGIN_USAGE}; + +static pFuncs pluginFuncs = { + sizeof(pluginFuncs), FD_PLUGIN_INTERFACE_VERSION, + + /* Entry points into plugin */ + newPlugin, /* new plugin instance */ + freePlugin, /* free plugin instance */ + getPluginValue, setPluginValue, handlePluginEvent, startBackupFile, + endBackupFile, startRestoreFile, endRestoreFile, pluginIO, createFile, + setFileAttributes, checkFile, getAcl, setAcl, getXattr, setXattr}; + +#include "plugin_private_context.h" /** * We don't actually use this but we need it to tear down the * final python interpreter on unload of the plugin. Each instance of @@ -972,7 +990,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) plugin_priv_ctx->pyModuleFunctionsDict = PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ - StorePluginContextInPythonModule(plugin_ctx); + // StorePluginContextInPythonModule(plugin_ctx); /* Lookup the load_bareos_plugin() function in the python module. */ pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index ccf7777c0a6..1f193066bc2 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -19,13 +19,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/* - * Marco van Wieringen, August 2012 - */ /** * @file - * Python Storage daemon Plugin program + * Python plugin for the Bareos Storage Daemon */ +#define PY_SSIZE_T_CLEAN +#define BUILD_PLUGIN #if defined(HAVE_WIN32) #include "include/bareos.h" @@ -36,11 +35,8 @@ #endif #include "stored/stored.h" -#if (PY_VERSION_HEX < 0x02060000) -#error "Need at least Python version 2.6 or newer" -#endif - #include "python-sd.h" +//#include "bareossd.h" #include "lib/edit.h" namespace storagedaemon { @@ -510,7 +506,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) plugin_priv_ctx->pyModuleFunctionsDict = PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ - StorePluginContextInPythonModule(plugin_ctx); + // StorePluginContextInPythonModule(plugin_ctx); /* * Lookup the load_bareos_plugin() function in the python module. @@ -656,302 +652,4 @@ static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, return retval; } -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to get certain internal values of the current Job. - */ -static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) -{ - int var; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); - PyObject* pRetVal = NULL; - - if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - switch (var) { - case bsdVarJobId: - case bsdVarLevel: - case bsdVarType: - case bsdVarJobStatus: { - int value; - - if (bareos_core_functions->getBareosValue(plugin_ctx, (bsdrVariable)var, - &value) == bRC_OK) { - pRetVal = PyInt_FromLong(value); - } - break; - } - case bsdVarJobErrors: - case bsdVarJobFiles: - case bsdVarJobBytes: { - uint64_t value = 0; - - if (bareos_core_functions->getBareosValue(plugin_ctx, (bsdrVariable)var, - &value) == bRC_OK) { - pRetVal = PyLong_FromUnsignedLong(value); - } - break; - } - case bsdVarJobName: - case bsdVarJob: - case bsdVarClient: - case bsdVarPool: - case bsdVarPoolType: - case bsdVarStorage: - case bsdVarMediaType: - case bsdVarVolumeName: { - char* value = NULL; - - if (bareos_core_functions->getBareosValue(plugin_ctx, (bsdrVariable)var, - &value) == bRC_OK) { - if (value) { pRetVal = PyString_FromString(value); } - } - break; - } - case bsdVarCompatible: { - bool value; - - if (bareos_core_functions->getBareosValue(NULL, (bsdrVariable)var, - &value) == bRC_OK) { - long bool_value; - - bool_value = (value) ? 1 : 0; - pRetVal = PyBool_FromLong(bool_value); - } - break; - } - case bsdVarPluginDir: { - char* value = NULL; - - if (bareos_core_functions->getBareosValue(NULL, (bsdrVariable)var, - &value) == bRC_OK) { - if (value) { pRetVal = PyString_FromString(value); } - } - break; - } - default: - Dmsg(plugin_ctx, debuglevel, - "python-sd: PyBareosGetValue unknown variable requested %d\n", var); - break; - } - - if (!pRetVal) { - Py_INCREF(Py_None); - pRetVal = Py_None; - } - - return pRetVal; -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to get certain internal values of the current Job. - */ -static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) -{ - int var; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; - PyObject* pyValue; - - if (!PyArg_ParseTuple(args, "iO:BareosSetValue", &var, &pyValue)) { - goto bail_out; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - switch (var) { - case bsdwVarVolumeName: { - char* value; - - value = PyString_AsString(pyValue); - if (value) { - bareos_core_functions->setBareosValue(plugin_ctx, (bsdwVariable)var, - value); - } - - break; - } - case bsdwVarPriority: - case bsdwVarJobLevel: { - int value; - - value = PyInt_AsLong(pyValue); - if (value >= 0) { - retval = bareos_core_functions->setBareosValue( - plugin_ctx, (bsdwVariable)var, &value); - } - break; - } - default: - Dmsg(plugin_ctx, debuglevel, - "python-sd: PyBareosSetValue unknown variable requested %d\n", var); - break; - } - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue debug messages using the Bareos debug message - * facility. - */ -static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) -{ - int level; - char* dbgmsg = NULL; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); - - if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { - return NULL; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - if (dbgmsg) { Dmsg(plugin_ctx, level, "python-sd: %s", dbgmsg); } - - Py_INCREF(Py_None); - return Py_None; -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue Job messages using the Bareos Job message - * facility. - */ -static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) -{ - int type; - char* jobmsg = NULL; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); - - if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { - return NULL; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - if (jobmsg) { Jmsg(plugin_ctx, type, "python-sd: %s", jobmsg); } - - Py_INCREF(Py_None); - return Py_None; -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a Register Event to register additional events - * it wants to receive. - */ -static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) -{ - int len, event; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; - PyObject *pyEvents, *pySeq, *pyEvent; - - if (!PyArg_ParseTuple(args, "O:BareosRegisterEvents", &pyEvents)) { - goto bail_out; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); - if (!pySeq) { goto bail_out; } - - len = PySequence_Fast_GET_SIZE(pySeq); - - for (int i = 0; i < len; i++) { - pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); - event = PyInt_AsLong(pyEvent); - - if (event >= bsdEventJobStart && event <= bsdEventWriteRecordTranslation) { - Dmsg(plugin_ctx, debuglevel, - "python-sd: PyBareosRegisterEvents registering event %d\n", event); - retval = - bareos_core_functions->registerBareosEvents(plugin_ctx, 1, event); - - if (retval != bRC_OK) { break; } - } - } - - Py_DECREF(pySeq); - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue an Unregister Event to unregister events it - * doesn't want to receive anymore. - */ -static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) -{ - int len, event; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; - PyObject *pyEvents, *pySeq, *pyEvent; - - if (!PyArg_ParseTuple(args, "O:BareosUnRegisterEvents", &pyEvents)) { - goto bail_out; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); - if (!pySeq) { goto bail_out; } - - len = PySequence_Fast_GET_SIZE(pySeq); - - for (int i = 0; i < len; i++) { - pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); - event = PyInt_AsLong(pyEvent); - - if (event >= bsdEventJobStart && event <= bsdEventWriteRecordTranslation) { - Dmsg(plugin_ctx, debuglevel, - "PyBareosUnRegisterEvents: registering event %d\n", event); - retval = - bareos_core_functions->unregisterBareosEvents(plugin_ctx, 1, event); - - if (retval != bRC_OK) { break; } - } - } - - Py_DECREF(pySeq); - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a GetInstanceCount to retrieve the number of - * instances of the current plugin being loaded into the daemon. - */ -static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) -{ - int value; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); - PyObject* pRetVal = NULL; - - if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - if (!plugin_ctx) { - PyErr_SetString(PyExc_ValueError, "plugin_ctx is unset"); - return NULL; - } - if (!bareos_core_functions) { - PyErr_SetString(PyExc_ValueError, "bareos_core_functions is unset"); - return NULL; - } - if (bareos_core_functions->getInstanceCount(plugin_ctx, &value) == bRC_OK) { - pRetVal = PyInt_FromLong(value); - } - - if (!pRetVal) { - Py_INCREF(Py_None); - pRetVal = Py_None; - } - - return pRetVal; -} } /* namespace storagedaemon*/ diff --git a/core/src/tools/bpluginfo.cc b/core/src/tools/bpluginfo.cc index d0c07f09e99..0d79ac4be79 100644 --- a/core/src/tools/bpluginfo.cc +++ b/core/src/tools/bpluginfo.cc @@ -111,7 +111,7 @@ struct _bareosfuncs { */ typedef union _bareosinfos bareosinfos; union _bareosinfos { - directordaemon::Dir_PluginApiDefiniton bdirinfo; + directordaemon::Dir_PluginApiDefinition bdirinfo; filedaemon::Core_PluginApiDefinition bfdinfo; storagedaemon::bsdInfo bsdinfo; }; From f0afb96c9de76993c1df59d73adc9c94d7a6c75a Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 11 May 2020 14:00:28 +0200 Subject: [PATCH 091/341] plugin_private_context: removed unneeded bareos_core_functions --- core/src/plugins/filed/python/plugin_private_context.h | 4 +--- core/src/plugins/filed/python/python-fd.cc | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/core/src/plugins/filed/python/plugin_private_context.h b/core/src/plugins/filed/python/plugin_private_context.h index 0d3f65fa34b..37142776380 100644 --- a/core/src/plugins/filed/python/plugin_private_context.h +++ b/core/src/plugins/filed/python/plugin_private_context.h @@ -18,9 +18,7 @@ struct plugin_private_context { interpreter; /* Python interpreter for this instance of the plugin */ PyObject* pModule; /* Python Module entry point */ PyObject* pyModuleFunctionsDict; /* Python Dictionary */ - BareosCoreFunctions* - bareos_core_functions; /* pointer to bareos_core_functions */ -}; // namespace filedaemon +}; #endif // BAREOS_CORE_SRC_PLUGINS_FILED_PYTHON_PLUGIN_PRIVATE_CONTEXT_H_ diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 66da3549ae6..9f45a678399 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -245,7 +245,6 @@ static bRC newPlugin(PluginContext* plugin_ctx) plugin_ctx->plugin_private_context = (void*)plugin_priv_ctx; /* set our context pointer */ - plugin_priv_ctx->bareos_core_functions = bareos_core_functions; /* set bareos_core_functions inside of barosfd module */ Bareosfd_set_plugin_context(plugin_ctx); From 27e6a6b9e3503f058d98da0cf943d3a02a196283 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 11 May 2020 15:19:57 +0200 Subject: [PATCH 092/341] python-dir and python-fd: can be successfully build --- core/src/plugins/dird/python/bareosdir.cc | 394 +++++++++++++++ core/src/plugins/dird/python/bareosdir.h | 4 +- core/src/plugins/dird/python/python-dir.cc | 447 ++---------------- core/src/plugins/filed/python/bareosfd.cc | 2 +- core/src/plugins/filed/python/python-fd.cc | 45 +- .../python/test/python-fd-module-tester.cc | 39 +- core/src/plugins/python_plugins_common.inc | 38 -- 7 files changed, 497 insertions(+), 472 deletions(-) diff --git a/core/src/plugins/dird/python/bareosdir.cc b/core/src/plugins/dird/python/bareosdir.cc index ed3d0f7caff..b0de1decdd4 100644 --- a/core/src/plugins/dird/python/bareosdir.cc +++ b/core/src/plugins/dird/python/bareosdir.cc @@ -474,4 +474,398 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) return pRetVal; } + +/** + * Any plugin options which are passed in are dispatched here to a Python method + * and it can parse the plugin options. This function is also called after + * PyLoadModule() has loaded the Python module and made sure things are + * operational. + */ +static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)plugin_ctx->plugin_private_context; + PyObject* pFunc; + + /* + * Lookup the parse_plugin_definition() function in the python module. + */ + pFunc = + PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "parse_plugin_definition"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyObject *pPluginDefinition, *pRetVal; + + pPluginDefinition = PyString_FromString((char*)value); + if (!pPluginDefinition) { goto bail_out; } + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); + Py_DECREF(pPluginDefinition); + + if (!pRetVal) { + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + } + + return retval; + } else { + Dmsg(plugin_ctx, debuglevel, + "python-dir: Failed to find function named " + "parse_plugin_definition()\n"); + return bRC_Error; + } + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } + + return retval; +} + +static bRC PyGetPluginValue(PluginContext* plugin_ctx, + pVariable var, + void* value) +{ + return bRC_OK; +} + +static bRC PySetPluginValue(PluginContext* plugin_ctx, + pVariable var, + void* value) +{ + return bRC_OK; +} + +static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, + bDirEvent* event, + void* value) +{ + bRC retval = bRC_Error; + plugin_private_context* plugin_priv_ctx = + (plugin_private_context*)plugin_ctx->plugin_private_context; + PyObject* pFunc; + + /* + * Lookup the handle_plugin_event() function in the python module. + */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "handle_plugin_event"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyObject *pEventType, *pRetVal; + + pEventType = PyInt_FromLong(event->eventType); + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pEventType, NULL); + Py_DECREF(pEventType); + + if (!pRetVal) { + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + } + } else { + Dmsg(plugin_ctx, debuglevel, + "python-dir: Failed to find function named handle_plugin_event()\n"); + } + + return retval; + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } + + return retval; +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to get certain internal values of the current Job. + */ +static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) +{ + int var; + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PyObject* pRetVal = NULL; + + if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + switch (var) { + case bDirVarJobId: + case bDirVarLevel: + case bDirVarType: + case bDirVarNumVols: + case bDirVarJobStatus: + case bDirVarPriority: + case bDirVarFDJobStatus: + case bDirVarSDJobStatus: { + int value = 0; + + if (bareos_core_functions->getBareosValue(plugin_ctx, (brDirVariable)var, + &value) == bRC_OK) { + pRetVal = PyInt_FromLong(value); + } + break; + } + case bDirVarJobErrors: + case bDirVarSDErrors: + case bDirVarJobFiles: + case bDirVarSDJobFiles: + case bDirVarLastRate: + case bDirVarJobBytes: + case bDirVarReadBytes: { + uint64_t value = 0; + + if (bareos_core_functions->getBareosValue(plugin_ctx, (brDirVariable)var, + &value) == bRC_OK) { + pRetVal = PyLong_FromUnsignedLong(value); + } + break; + } + case bDirVarJobName: + case bDirVarJob: + case bDirVarClient: + case bDirVarPool: + case bDirVarStorage: + case bDirVarWriteStorage: + case bDirVarReadStorage: + case bDirVarCatalog: + case bDirVarMediaType: + case bDirVarVolumeName: { + char* value = NULL; + + if (bareos_core_functions->getBareosValue(plugin_ctx, (brDirVariable)var, + &value) == bRC_OK) { + if (value) { pRetVal = PyString_FromString(value); } + } + break; + } + case bDirVarPluginDir: { + char* value = NULL; + + if (bareos_core_functions->getBareosValue(NULL, (brDirVariable)var, + &value) == bRC_OK) { + if (value) { pRetVal = PyString_FromString(value); } + } + break; + } + default: + Dmsg(plugin_ctx, debuglevel, + "python-dir: PyBareosGetValue unknown variable requested %d\n", var); + break; + } + + if (!pRetVal) { + Py_INCREF(Py_None); + pRetVal = Py_None; + } + + return pRetVal; +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to set certain internal values of the current Job. + */ +static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) +{ + int var; + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + bRC retval = bRC_Error; + PyObject* pyValue; + + if (!PyArg_ParseTuple(args, "iO:BareosSetValue", &var, &pyValue)) { + goto bail_out; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + switch (var) { + case bwDirVarVolumeName: { + char* value; + + value = PyString_AsString(pyValue); + if (value) { + retval = bareos_core_functions->setBareosValue( + plugin_ctx, (bwDirVariable)var, value); + } + + break; + } + case bwDirVarPriority: + case bwDirVarJobLevel: { + int value; + + value = PyInt_AsLong(pyValue); + if (value >= 0) { + retval = bareos_core_functions->setBareosValue( + plugin_ctx, (bwDirVariable)var, &value); + } + break; + } + default: + Dmsg(plugin_ctx, debuglevel, + "python-dir: PyBareosSetValue unknown variable requested %d\n", var); + break; + } + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to issue debug messages using the Bareos debug message + * facility. + */ +static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) +{ + int level; + char* dbgmsg = NULL; + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + + if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { + return NULL; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + if (dbgmsg) { Dmsg(plugin_ctx, level, "python-dir: %s", dbgmsg); } + + Py_INCREF(Py_None); + return Py_None; +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to issue Job messages using the Bareos Job message + * facility. + */ +static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) +{ + int type; + char* jobmsg = NULL; + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + + if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { + return NULL; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + if (jobmsg) { Jmsg(plugin_ctx, type, "python-dir: %s", jobmsg); } + + Py_INCREF(Py_None); + return Py_None; +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to issue a Register Event to register additional events + * it wants to receive. + */ +static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) +{ + int len, event; + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + bRC retval = bRC_Error; + PyObject *pyEvents, *pySeq, *pyEvent; + + if (!PyArg_ParseTuple(args, "O:BareosRegisterEvents", &pyEvents)) { + goto bail_out; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); + if (!pySeq) { goto bail_out; } + + len = PySequence_Fast_GET_SIZE(pySeq); + + for (int i = 0; i < len; i++) { + pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); + event = PyInt_AsLong(pyEvent); + + if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { + Dmsg(plugin_ctx, debuglevel, + "python-dir: PyBareosRegisterEvents registering event %d\n", event); + retval = + bareos_core_functions->registerBareosEvents(plugin_ctx, 1, event); + + if (retval != bRC_OK) { break; } + } + } + + Py_DECREF(pySeq); + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to issue an Unregister Event to unregister events it + * doesn't want to receive anymore. + */ +static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) +{ + int len, event; + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + bRC retval = bRC_Error; + PyObject *pyEvents, *pySeq, *pyEvent; + + if (!PyArg_ParseTuple(args, "O:BareosUnRegisterEvents", &pyEvents)) { + goto bail_out; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); + if (!pySeq) { goto bail_out; } + + len = PySequence_Fast_GET_SIZE(pySeq); + + for (int i = 0; i < len; i++) { + pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); + event = PyInt_AsLong(pyEvent); + + if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { + Dmsg(plugin_ctx, debuglevel, + "PyBareosUnRegisterEvents: registering event %d\n", event); + retval = + bareos_core_functions->unregisterBareosEvents(plugin_ctx, 1, event); + + if (retval != bRC_OK) { break; } + } + } + + Py_DECREF(pySeq); + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to issue a GetInstanceCount to retrieve the number of + * instances of the current plugin being loaded into the daemon. + */ +static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) +{ + int value; + PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PyObject* pRetVal = NULL; + + if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + if (bareos_core_functions->getInstanceCount(plugin_ctx, &value) == bRC_OK) { + pRetVal = PyInt_FromLong(value); + } + + if (!pRetVal) { + Py_INCREF(Py_None); + pRetVal = Py_None; + } + + return pRetVal; +} + } /* namespace directordaemon */ diff --git a/core/src/plugins/dird/python/bareosdir.h b/core/src/plugins/dird/python/bareosdir.h index 9a950e07f04..d6677357e76 100644 --- a/core/src/plugins/dird/python/bareosdir.h +++ b/core/src/plugins/dird/python/bareosdir.h @@ -41,7 +41,7 @@ #ifdef BAREOSDIR_MODULE /* This section is used when compiling bareosdir.cc */ -namespace filedaemon { +namespace directordaemon { /** * Python structures mapping C++ ones. @@ -75,7 +75,7 @@ static PyMethodDef Methods[] = { static void* bareos_PluginContext = NULL; -} // namespace filedaemon +} // namespace directordaemon using namespace directordaemon; /* variables storing bareos pointers */ diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index 74ae8d908be..f5f2cf9cf67 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -73,6 +73,14 @@ static bRC parse_plugin_definition(PluginContext* plugin_ctx, static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); static bRC PyLoadModule(PluginContext* plugin_ctx, void* value); +#if 0 +static bRC PyGetPluginValue(PluginContext* plugin_ctx, + pVariable var, + void* value); +static bRC PySetPluginValue(PluginContext* plugin_ctx, + pVariable var, + void* value); +#endif /* Pointers to Bareos functions */ static DirCoreFunctions* bareos_core_functions = NULL; static Dir_PluginApiDefinition* bareos_plugin_interface_version = NULL; @@ -114,11 +122,46 @@ struct plugin_private_context { */ static PyThreadState* mainThreadState; - -#define NOPLUGINSETGETVALUE /* functions common to all plugins */ #include "plugins/python_plugins_common.inc" +/* Common functions used in all python plugins. */ +static bRC getPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value) +{ + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + bRC retval = bRC_Error; + + if (!plugin_priv_ctx) { goto bail_out; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = Bareosdir_PyGetPluginValue(bareos_plugin_ctx, var, value); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + +bail_out: + return retval; +} + +static bRC setPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value) +{ + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + bRC retval = bRC_Error; + + if (!plugin_priv_ctx) { return bRC_Error; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = Bareosdir_PySetPluginValue(bareos_plugin_ctx, var, value); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + + return retval; +} + + #ifdef __cplusplus extern "C" { #endif @@ -237,15 +280,15 @@ static bRC newPlugin(PluginContext* plugin_ctx) plugin_ctx->plugin_private_context = (void*)plugin_priv_ctx; /* set our context pointer */ + /* set bareos_core_functions inside of barosdir module */ + Bareosdir_set_plugin_context(plugin_ctx); /* For each plugin instance we instantiate a new Python interpreter. */ PyEval_AcquireThread(mainThreadState); plugin_priv_ctx->interpreter = Py_NewInterpreter(); PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - /* - * Always register some events the python plugin itself can register - * any other events it is interested in. - */ + /* Always register some events the python plugin itself can register + any other events it is interested in. */ bareos_core_functions->registerBareosEvents(plugin_ctx, 1, bDirEventNewPluginOptions); @@ -589,397 +632,5 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) } #if 0 -/** - * Any plugin options which are passed in are dispatched here to a Python method - * and it can parse the plugin options. This function is also called after - * PyLoadModule() has loaded the Python module and made sure things are - * operational. - */ -static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)plugin_ctx->plugin_private_context; - PyObject* pFunc; - - /* - * Lookup the parse_plugin_definition() function in the python module. - */ - pFunc = - PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "parse_plugin_definition"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyObject *pPluginDefinition, *pRetVal; - - pPluginDefinition = PyString_FromString((char*)value); - if (!pPluginDefinition) { goto bail_out; } - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); - Py_DECREF(pPluginDefinition); - - if (!pRetVal) { - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - } - - return retval; - } else { - Dmsg(plugin_ctx, debuglevel, - "python-dir: Failed to find function named " - "parse_plugin_definition()\n"); - return bRC_Error; - } - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } - - return retval; -} - -static bRC PyGetPluginValue(PluginContext* plugin_ctx, - pVariable var, - void* value) -{ - return bRC_OK; -} - -static bRC PySetPluginValue(PluginContext* plugin_ctx, - pVariable var, - void* value) -{ - return bRC_OK; -} - -static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, - bDirEvent* event, - void* value) -{ - bRC retval = bRC_Error; - plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)plugin_ctx->plugin_private_context; - PyObject* pFunc; - - /* - * Lookup the handle_plugin_event() function in the python module. - */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "handle_plugin_event"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyObject *pEventType, *pRetVal; - - pEventType = PyInt_FromLong(event->eventType); - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pEventType, NULL); - Py_DECREF(pEventType); - - if (!pRetVal) { - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - } - } else { - Dmsg(plugin_ctx, debuglevel, - "python-dir: Failed to find function named handle_plugin_event()\n"); - } - - return retval; - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } - - return retval; -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to get certain internal values of the current Job. - */ -static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) -{ - int var; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); - PyObject* pRetVal = NULL; - - if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - switch (var) { - case bDirVarJobId: - case bDirVarLevel: - case bDirVarType: - case bDirVarNumVols: - case bDirVarJobStatus: - case bDirVarPriority: - case bDirVarFDJobStatus: - case bDirVarSDJobStatus: { - int value = 0; - - if (bareos_core_functions->getBareosValue(plugin_ctx, (brDirVariable)var, - &value) == bRC_OK) { - pRetVal = PyInt_FromLong(value); - } - break; - } - case bDirVarJobErrors: - case bDirVarSDErrors: - case bDirVarJobFiles: - case bDirVarSDJobFiles: - case bDirVarLastRate: - case bDirVarJobBytes: - case bDirVarReadBytes: { - uint64_t value = 0; - - if (bareos_core_functions->getBareosValue(plugin_ctx, (brDirVariable)var, - &value) == bRC_OK) { - pRetVal = PyLong_FromUnsignedLong(value); - } - break; - } - case bDirVarJobName: - case bDirVarJob: - case bDirVarClient: - case bDirVarPool: - case bDirVarStorage: - case bDirVarWriteStorage: - case bDirVarReadStorage: - case bDirVarCatalog: - case bDirVarMediaType: - case bDirVarVolumeName: { - char* value = NULL; - - if (bareos_core_functions->getBareosValue(plugin_ctx, (brDirVariable)var, - &value) == bRC_OK) { - if (value) { pRetVal = PyString_FromString(value); } - } - break; - } - case bDirVarPluginDir: { - char* value = NULL; - - if (bareos_core_functions->getBareosValue(NULL, (brDirVariable)var, - &value) == bRC_OK) { - if (value) { pRetVal = PyString_FromString(value); } - } - break; - } - default: - Dmsg(plugin_ctx, debuglevel, - "python-dir: PyBareosGetValue unknown variable requested %d\n", var); - break; - } - - if (!pRetVal) { - Py_INCREF(Py_None); - pRetVal = Py_None; - } - - return pRetVal; -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to set certain internal values of the current Job. - */ -static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) -{ - int var; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; - PyObject* pyValue; - - if (!PyArg_ParseTuple(args, "iO:BareosSetValue", &var, &pyValue)) { - goto bail_out; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - switch (var) { - case bwDirVarVolumeName: { - char* value; - - value = PyString_AsString(pyValue); - if (value) { - retval = bareos_core_functions->setBareosValue( - plugin_ctx, (bwDirVariable)var, value); - } - - break; - } - case bwDirVarPriority: - case bwDirVarJobLevel: { - int value; - - value = PyInt_AsLong(pyValue); - if (value >= 0) { - retval = bareos_core_functions->setBareosValue( - plugin_ctx, (bwDirVariable)var, &value); - } - break; - } - default: - Dmsg(plugin_ctx, debuglevel, - "python-dir: PyBareosSetValue unknown variable requested %d\n", var); - break; - } - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue debug messages using the Bareos debug message - * facility. - */ -static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) -{ - int level; - char* dbgmsg = NULL; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); - - if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { - return NULL; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - if (dbgmsg) { Dmsg(plugin_ctx, level, "python-dir: %s", dbgmsg); } - - Py_INCREF(Py_None); - return Py_None; -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue Job messages using the Bareos Job message - * facility. - */ -static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) -{ - int type; - char* jobmsg = NULL; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); - - if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { - return NULL; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - if (jobmsg) { Jmsg(plugin_ctx, type, "python-dir: %s", jobmsg); } - - Py_INCREF(Py_None); - return Py_None; -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a Register Event to register additional events - * it wants to receive. - */ -static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) -{ - int len, event; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; - PyObject *pyEvents, *pySeq, *pyEvent; - - if (!PyArg_ParseTuple(args, "O:BareosRegisterEvents", &pyEvents)) { - goto bail_out; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); - if (!pySeq) { goto bail_out; } - - len = PySequence_Fast_GET_SIZE(pySeq); - - for (int i = 0; i < len; i++) { - pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); - event = PyInt_AsLong(pyEvent); - - if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { - Dmsg(plugin_ctx, debuglevel, - "python-dir: PyBareosRegisterEvents registering event %d\n", event); - retval = - bareos_core_functions->registerBareosEvents(plugin_ctx, 1, event); - - if (retval != bRC_OK) { break; } - } - } - - Py_DECREF(pySeq); - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue an Unregister Event to unregister events it - * doesn't want to receive anymore. - */ -static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) -{ - int len, event; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); - bRC retval = bRC_Error; - PyObject *pyEvents, *pySeq, *pyEvent; - - if (!PyArg_ParseTuple(args, "O:BareosUnRegisterEvents", &pyEvents)) { - goto bail_out; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); - if (!pySeq) { goto bail_out; } - - len = PySequence_Fast_GET_SIZE(pySeq); - - for (int i = 0; i < len; i++) { - pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); - event = PyInt_AsLong(pyEvent); - - if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { - Dmsg(plugin_ctx, debuglevel, - "PyBareosUnRegisterEvents: registering event %d\n", event); - retval = - bareos_core_functions->unregisterBareosEvents(plugin_ctx, 1, event); - - if (retval != bRC_OK) { break; } - } - } - - Py_DECREF(pySeq); - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a GetInstanceCount to retrieve the number of - * instances of the current plugin being loaded into the daemon. - */ -static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) -{ - int value; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); - PyObject* pRetVal = NULL; - - if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - if (bareos_core_functions->getInstanceCount(plugin_ctx, &value) == bRC_OK) { - pRetVal = PyInt_FromLong(value); - } - - if (!pRetVal) { - Py_INCREF(Py_None); - pRetVal = Py_None; - } - - return pRetVal; -} #endif } /* namespace directordaemon */ diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index b4d541c0067..78ec5f9e634 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -47,6 +47,7 @@ static bRC set_bareos_core_functions( BareosCoreFunctions* new_bareos_core_functions); static bRC set_plugin_context(PluginContext* new_plugin_context); static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); + static bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); @@ -2396,5 +2397,4 @@ static void PyXattrPacket_dealloc(PyXattrPacket* self) PyObject_Del(self); } - } /* namespace filedaemon */ diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 9f45a678399..7b2546d08e2 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -56,12 +56,14 @@ static const int debuglevel = 150; /* Forward referenced functions */ static bRC newPlugin(PluginContext* plugin_ctx); static bRC freePlugin(PluginContext* plugin_ctx); + static bRC getPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); static bRC setPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); + static bRC handlePluginEvent(PluginContext* plugin_ctx, bEvent* event, void* value); @@ -83,12 +85,6 @@ static bRC parse_plugin_definition(PluginContext* plugin_ctx, static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); static bRC PyLoadModule(PluginContext* plugin_ctx, void* value); -static bRC PyGetPluginValue(PluginContext* plugin_ctx, - pVariable var, - void* value); -static bRC PySetPluginValue(PluginContext* plugin_ctx, - pVariable var, - void* value); /* Pointers to Bareos functions */ static BareosCoreFunctions* bareos_core_functions = NULL; @@ -1031,18 +1027,39 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) return retval; } -static bRC PyGetPluginValue(PluginContext* plugin_ctx, - pVariable var, - void* value) +static bRC getPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value) { - return bRC_OK; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + bRC retval = bRC_Error; + + if (!plugin_priv_ctx) { goto bail_out; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = Bareosfd_PyGetPluginValue(bareos_plugin_ctx, var, value); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + +bail_out: + return retval; } -static bRC PySetPluginValue(PluginContext* plugin_ctx, - pVariable var, - void* value) +static bRC setPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value) { - return bRC_OK; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + bRC retval = bRC_Error; + + if (!plugin_priv_ctx) { return bRC_Error; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = Bareosfd_PySetPluginValue(bareos_plugin_ctx, var, value); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + + return retval; } } /* namespace filedaemon */ diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index 608a62b6303..52a4e01d368 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -175,7 +175,7 @@ static filedaemon::BareosCoreFunctions bareos_core_functions = { bareosSetSeenBitmap, bareosClearSeenBitmap}; -static void* bareos_PluginContext = NULL; +static PluginContext* bareos_PluginContext = NULL; int main(int argc, char* argv[]) { @@ -192,34 +192,35 @@ int main(int argc, char* argv[]) import_bareosfd(); Bareosfd_set_bareos_core_functions(&bareos_core_functions); + Bareosfd_set_plugin_context(bareos_PluginContext); + PyObject* pModule = PyImport_ImportModule("bareosfd-module-test"); // Extract capsules pointer from bareosfd module - void* ctx_from_bareosfd_module = - PyCapsule_Import("bareosfd.PluginContext", 0); - if (!ctx_from_bareosfd_module) { - printf("importing bareosfd.PluginContext failed \n"); - } + /* void* ctx_from_bareosfd_module = */ + /* PyCapsule_Import("bareosfd.PluginContext", 0); */ + /* if (!ctx_from_bareosfd_module) { */ + /* printf("importing bareosfd.PluginContext failed \n"); */ + /* } */ // Extract capsules pointer from bareosfd module - void* bareos_core_functions_from_bareosfd_module = - PyCapsule_Import("bareosfd.BareosCoreFunctions", 0); - if (!bareos_core_functions_from_bareosfd_module) { - printf("importing bareosfd.BareosCoreFunctions failed \n"); - } + /* void* bareos_core_functions_from_bareosfd_module = */ + /* PyCapsule_Import("bareosfd.BareosCoreFunctions", 0); */ + /* if (!bareos_core_functions_from_bareosfd_module) { */ + /* printf("importing bareosfd.BareosCoreFunctions failed \n"); */ + /* } */ - *(void**)ctx_from_bareosfd_module = &bareos_PluginContext; - *(void**)bareos_core_functions_from_bareosfd_module = &bareos_core_functions; + /* *(void**)ctx_from_bareosfd_module = &bareos_PluginContext; */ + /* *(void**)bareos_core_functions_from_bareosfd_module = + * &bareos_core_functions; */ - printf("ctx_from_bareosfd_module contains %p\n", - *(void**)ctx_from_bareosfd_module); - printf("bareos_core_functions_from_bareosfd_module contains %p\n", - *(void**)bareos_core_functions_from_bareosfd_module); + /* printf("ctx_from_bareosfd_module contains %p\n", */ + /* *(void**)ctx_from_bareosfd_module); */ + /* printf("bareos_core_functions_from_bareosfd_module contains %p\n", */ + /* *(void**)bareos_core_functions_from_bareosfd_module); */ - PyObject* pModule = PyImport_ImportModule("bareosfd-module-test"); - if (PyErr_Occurred()) { PyErrorHandler(); } PyObject* pDict = PyModule_GetDict(pModule); diff --git a/core/src/plugins/python_plugins_common.inc b/core/src/plugins/python_plugins_common.inc index 295ea9f1c42..180ee9d7c1c 100644 --- a/core/src/plugins/python_plugins_common.inc +++ b/core/src/plugins/python_plugins_common.inc @@ -19,44 +19,6 @@ 02110-1301, USA. */ -#ifndef NOPLUGINSETGETVALUE -/* Common functions used in all python plugins. */ -static bRC getPluginValue(PluginContext* bareos_plugin_ctx, - pVariable var, - void* value) -{ - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - bRC retval = bRC_Error; - - if (!plugin_priv_ctx) { goto bail_out; } - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PyGetPluginValue(bareos_plugin_ctx, var, value); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - -bail_out: - return retval; -} - -static bRC setPluginValue(PluginContext* bareos_plugin_ctx, - pVariable var, - void* value) -{ - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; - bRC retval = bRC_Error; - - if (!plugin_priv_ctx) { return bRC_Error; } - - PyEval_AcquireThread(plugin_priv_ctx->interpreter); - retval = PySetPluginValue(bareos_plugin_ctx, var, value); - PyEval_ReleaseThread(plugin_priv_ctx->interpreter); - - return retval; -} -#endif - /** * Strip any backslashes in the string. From 5b1c8df94a8f3738efb5a7797df9d648b0bab7a7 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 11 May 2020 15:32:51 +0200 Subject: [PATCH 093/341] cmake: adaptions for dird and filed --- core/src/plugins/dird/CMakeLists.txt | 11 +++++++---- core/src/plugins/filed/CMakeLists.txt | 13 ++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index eb9a34abbc4..076c00a7a01 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -36,10 +36,11 @@ if(HAVE_PYTHON) set_target_properties(python-dir PROPERTIES PREFIX "") install(TARGETS python-dir DESTINATION ${plugindir}) target_link_libraries(python-dir ${PYTHON_LIBRARIES} bareos) - add_dependencies(python-dir bareosdir) + add_dependencies(python-dir bareosdir-pymod) set(PYFILES - python/pyfiles/bareos-dir.py.template python/pyfiles/bareos-dir-class-plugin.py + python/pyfiles/bareos-dir.py.template + python/pyfiles/bareos-dir-class-plugin.py python/pyfiles/BareosDirPluginBaseclass.py python/pyfiles/BareosDirWrapper.py ) @@ -52,15 +53,17 @@ if(HAVE_PYTHON AND NOT HAVE_WIN32) add_custom_command( OUTPUT pythonmodules/bareosdir.so MAIN_DEPENDENCY ./python/bareosdir.cc + DEPENDS ./python/bareosdir.h DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py COMMAND ${PYTHON_EXECUTABLE} python/setup.py build COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - # COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build DEPENDS python-dir + COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build + # COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build DEPENDS python-dir COMMENT "building python module pythonmodules/bareosdir.so" ) - add_custom_target(bareosdir DEPENDS pythonmodules/bareosdir.so) + add_custom_target(bareosdir-pymod DEPENDS pythonmodules/bareosdir.so) add_test(NAME bareosdir-python-module COMMAND ${PYTHON_EXECUTABLE} diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index 04fdb48981f..acca78a50f2 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -105,7 +105,7 @@ if(HAVE_PYTHON) COMPONENT filedaemon ) target_link_libraries(python-fd ${PYTHON_LIBRARIES} bareos) - add_dependencies(python-fd bareosfd) + add_dependencies(python-fd bareosfd-pymod) endif() if(HAVE_PYTHON AND NOT HAVE_WIN32) @@ -131,16 +131,15 @@ if(HAVE_PYTHON AND NOT HAVE_WIN32) MAIN_DEPENDENCY ./python/bareosfd.cc DEPENDS ./python/bareosfd.h DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py - COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build + COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${PYTHON_EXECUTABLE} python/setup.py build - COMMAND - ${PYTHON_EXECUTABLE} python/setup.py install --install-lib - ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - # DEPENDS python-fd + COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib + ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python module pythonmodules/bareosfd.so" ) - add_custom_target(bareosfd DEPENDS pythonmodules/bareosfd.so) + add_custom_target(bareosfd-pymod DEPENDS pythonmodules/bareosfd.so) add_test(NAME bareosfd-python-module COMMAND ${PYTHON_EXECUTABLE} From 5f320f68e0b0d1d67efe30ff9185e2230c6176bc Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 11 May 2020 15:39:45 +0200 Subject: [PATCH 094/341] python-fd: python-fd-module-tester updated --- .../plugins/filed/python/test/python-fd-module-tester.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index 52a4e01d368..ae270bd877a 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -175,7 +175,12 @@ static filedaemon::BareosCoreFunctions bareos_core_functions = { bareosSetSeenBitmap, bareosClearSeenBitmap}; -static PluginContext* bareos_PluginContext = NULL; + +// create plugin context + +Plugin plugin = {(char*)"python-fd-module-teste", 123, NULL, NULL, NULL}; + +static PluginContext bareos_PluginContext = {0, &plugin, NULL, NULL}; int main(int argc, char* argv[]) { @@ -192,7 +197,7 @@ int main(int argc, char* argv[]) import_bareosfd(); Bareosfd_set_bareos_core_functions(&bareos_core_functions); - Bareosfd_set_plugin_context(bareos_PluginContext); + Bareosfd_set_plugin_context(&bareos_PluginContext); PyObject* pModule = PyImport_ImportModule("bareosfd-module-test"); From 10a738f728542f85fb0e7a7c232d743974f7fa12 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 11 May 2020 15:53:29 +0200 Subject: [PATCH 095/341] pythonfd.cc: fix dependency --- core/src/plugins/filed/CMakeLists.txt | 1 + core/src/plugins/filed/python/python-fd.cc | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index acca78a50f2..286c74b739a 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -130,6 +130,7 @@ if(HAVE_PYTHON AND NOT HAVE_WIN32) OUTPUT pythonmodules/bareosfd.so MAIN_DEPENDENCY ./python/bareosfd.cc DEPENDS ./python/bareosfd.h + DEPENDS bareos DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${PYTHON_EXECUTABLE} python/setup.py build diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 7b2546d08e2..7eacbd95874 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -242,7 +242,7 @@ static bRC newPlugin(PluginContext* plugin_ctx) (void*)plugin_priv_ctx; /* set our context pointer */ - /* set bareos_core_functions inside of barosfd module */ + /* set bareos_plugin_context inside of barosfd module */ Bareosfd_set_plugin_context(plugin_ctx); /* For each plugin instance we instantiate a new Python interpreter. */ From d58daa8cab8d9aae00613cbec5d774f4d1c013e3 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 11 May 2020 17:21:31 +0200 Subject: [PATCH 096/341] python-dir plugin: test works --- core/src/dird/dir_plugins.cc | 21 ++++---- core/src/dird/dir_plugins.h | 2 +- core/src/plugins/dird/python/bareosdir.cc | 48 +++++++++++-------- core/src/plugins/dird/python/bareosdir.h | 17 ++++++- .../dird/python/bareosdir_api_funcs.txt | 2 +- .../dird/python/plugin_private_context.h | 19 ++++++++ core/src/plugins/dird/python/python-dir.cc | 27 ++--------- core/src/plugins/dird/python/setup.py.in | 2 +- core/src/plugins/filed/python/bareosfd.h | 2 - core/src/plugins/stored/python/python-sd.h | 1 + core/src/plugins/stored/python/setup.py.in | 2 +- 11 files changed, 82 insertions(+), 61 deletions(-) create mode 100644 core/src/plugins/dird/python/plugin_private_context.h diff --git a/core/src/dird/dir_plugins.cc b/core/src/dird/dir_plugins.cc index 0119757fd11..92f6f3125d0 100644 --- a/core/src/dird/dir_plugins.cc +++ b/core/src/dird/dir_plugins.cc @@ -68,18 +68,19 @@ static bool IsPluginCompatible(Plugin* plugin); /* BAREOS info */ static Dir_PluginApiDefinition bareos_plugin_interface_version = { - sizeof(DirCoreFunctions), DIR_PLUGIN_INTERFACE_VERSION}; + sizeof(DirectorCoreFunctions), DIR_PLUGIN_INTERFACE_VERSION}; /* BAREOS entry points */ -static DirCoreFunctions bareos_core_functions = {sizeof(DirCoreFunctions), - DIR_PLUGIN_INTERFACE_VERSION, - bareosRegisterEvents, - bareosUnRegisterEvents, - bareosGetInstanceCount, - bareosGetValue, - bareosSetValue, - bareosJobMsg, - bareosDebugMsg}; +static DirectorCoreFunctions bareos_core_functions = { + sizeof(DirectorCoreFunctions), + DIR_PLUGIN_INTERFACE_VERSION, + bareosRegisterEvents, + bareosUnRegisterEvents, + bareosGetInstanceCount, + bareosGetValue, + bareosSetValue, + bareosJobMsg, + bareosDebugMsg}; /* * BAREOS private context diff --git a/core/src/dird/dir_plugins.h b/core/src/dird/dir_plugins.h index 17ce966bdc5..42639ea2aa9 100644 --- a/core/src/dird/dir_plugins.h +++ b/core/src/dird/dir_plugins.h @@ -159,7 +159,7 @@ typedef struct s_dirbareosFuncs { int level, const char* fmt, ...); -} DirCoreFunctions; +} DirectorCoreFunctions; /** * Bareos Core Routines -- not used within a plugin diff --git a/core/src/plugins/dird/python/bareosdir.cc b/core/src/plugins/dird/python/bareosdir.cc index b0de1decdd4..4dcfc0af72e 100644 --- a/core/src/plugins/dird/python/bareosdir.cc +++ b/core/src/plugins/dird/python/bareosdir.cc @@ -1,7 +1,7 @@ /* BAREOS® - Backup Archiving REcovery Open Sourced - Copyright (C) 2013-2020 Bareos GmbH & Co. KG + Copyright (C) 2020-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -33,6 +33,11 @@ #include "include/bareos.h" #endif #include "dird/dird.h" +#include "dird/dir_plugins.h" + + +#include "plugins/filed/fd_common.h" // for Dmsg Macro +#include "plugin_private_context.h" #define BAREOSDIR_MODULE @@ -44,7 +49,7 @@ namespace directordaemon { static const int debuglevel = 150; static bRC set_bareos_core_functions( - DirCoreFunctions* new_bareos_core_functions); + DirectorCoreFunctions* new_bareos_core_functions); static bRC set_plugin_context(PluginContext* new_plugin_context); static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); @@ -59,16 +64,17 @@ static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, void* value); /* Pointers to Bareos functions */ -static bDirFuncs* bareos_core_functions = NULL; +static DirectorCoreFunctions* bareos_core_functions = NULL; +#define NOPLUGINSETGETVALUE 1 /* functions common to all plugins */ #include "plugins/python_plugins_common.inc" /* set the bareos_core_functions pointer to the given value */ static bRC set_bareos_core_functions( - BareosCoreFunctions* new_bareos_core_functions) + DirectorCoreFunctions* new_bareos_core_functions) { bareos_core_functions = new_bareos_core_functions; return bRC_OK; @@ -150,8 +156,8 @@ static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, void* value) { bRC retval = bRC_Error; - plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)plugin_ctx->plugin_private_context; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject* pFunc; /* @@ -193,7 +199,7 @@ static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } @@ -279,7 +285,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; bRC retval = bRC_Error; PyObject* pyValue; @@ -330,7 +336,7 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; @@ -352,7 +358,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; @@ -373,7 +379,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -415,7 +421,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -457,7 +463,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } @@ -475,6 +481,7 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) return pRetVal; } +#if 0 /** * Any plugin options which are passed in are dispatched here to a Python method * and it can parse the plugin options. This function is also called after @@ -586,7 +593,7 @@ static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { int var; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } @@ -672,7 +679,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { int var; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; bRC retval = bRC_Error; PyObject* pyValue; @@ -723,7 +730,7 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { int level; char* dbgmsg = NULL; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { return NULL; @@ -745,7 +752,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { int type; char* jobmsg = NULL; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { return NULL; @@ -766,7 +773,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { int len, event; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -808,7 +815,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { int len, event; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; bRC retval = bRC_Error; PyObject *pyEvents, *pySeq, *pyEvent; @@ -850,7 +857,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { int value; - PluginContext* plugin_ctx = GetPluginContextFromPythonModule(); + PluginContext* plugin_ctx = plugin_context; PyObject* pRetVal = NULL; if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } @@ -868,4 +875,5 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) return pRetVal; } +#endif } /* namespace directordaemon */ diff --git a/core/src/plugins/dird/python/bareosdir.h b/core/src/plugins/dird/python/bareosdir.h index d6677357e76..e47ca89279c 100644 --- a/core/src/plugins/dird/python/bareosdir.h +++ b/core/src/plugins/dird/python/bareosdir.h @@ -73,7 +73,22 @@ static PyMethodDef Methods[] = { {NULL, NULL, 0, NULL}}; -static void* bareos_PluginContext = NULL; +static bRC set_bareos_core_functions( + DirectorCoreFunctions* new_bareos_core_functions); +static bRC set_plugin_context(PluginContext* new_plugin_context); +static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); +static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); +static bRC PyGetPluginValue(PluginContext* plugin_ctx, + pVariable var, + void* value); +static bRC PySetPluginValue(PluginContext* plugin_ctx, + pVariable var, + void* value); +static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, + bDirEvent* event, + void* value); + +// static void* bareos_PluginContext = NULL; } // namespace directordaemon using namespace directordaemon; diff --git a/core/src/plugins/dird/python/bareosdir_api_funcs.txt b/core/src/plugins/dird/python/bareosdir_api_funcs.txt index bb5ba0f867f..8a637daf14f 100644 --- a/core/src/plugins/dird/python/bareosdir_api_funcs.txt +++ b/core/src/plugins/dird/python/bareosdir_api_funcs.txt @@ -2,5 +2,5 @@ bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); bRC PySetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); bRC PyHandlePluginEvent(PluginContext* plugin_ctx, bDirEvent* event, void* value); -bRC set_bareos_core_functions( DirCoreFunctions* new_bareos_core_functions); +bRC set_bareos_core_functions( DirectorCoreFunctions* new_bareos_core_functions); bRC set_plugin_context(PluginContext* new_plugin_context); diff --git a/core/src/plugins/dird/python/plugin_private_context.h b/core/src/plugins/dird/python/plugin_private_context.h new file mode 100644 index 00000000000..897db2123a6 --- /dev/null +++ b/core/src/plugins/dird/python/plugin_private_context.h @@ -0,0 +1,19 @@ + +#ifndef BAREOS_CORE_SRC_PLUGINS_DIRD_PYTHON_PLUGIN_PRIVATE_CONTEXT_H_ +#define BAREOS_CORE_SRC_PLUGINS_DIRD_PYTHON_PLUGIN_PRIVATE_CONTEXT_H_ +/** + * Plugin private context + */ +struct plugin_private_context { + int64_t instance; /* Instance number of plugin */ + bool python_loaded; /* Plugin has python module loaded ? */ + bool python_path_set; /* Python plugin search path is set ? */ + char* module_path; /* Plugin Module Path */ + char* module_name; /* Plugin Module Name */ + PyThreadState* + interpreter; /* Python interpreter for this instance of the plugin */ + PyObject* pModule; /* Python Module entry point */ + PyObject* pyModuleFunctionsDict; /* Python Dictionary */ +}; + +#endif // BAREOS_CORE_SRC_PLUGINS_DIRD_PYTHON_PLUGIN_PRIVATE_CONTEXT_H_ diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index f5f2cf9cf67..bd72cbffcb9 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -73,16 +73,8 @@ static bRC parse_plugin_definition(PluginContext* plugin_ctx, static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); static bRC PyLoadModule(PluginContext* plugin_ctx, void* value); -#if 0 -static bRC PyGetPluginValue(PluginContext* plugin_ctx, - pVariable var, - void* value); -static bRC PySetPluginValue(PluginContext* plugin_ctx, - pVariable var, - void* value); -#endif /* Pointers to Bareos functions */ -static DirCoreFunctions* bareos_core_functions = NULL; +static DirectorCoreFunctions* bareos_core_functions = NULL; static Dir_PluginApiDefinition* bareos_plugin_interface_version = NULL; static PluginInformation pluginInfo = { @@ -100,20 +92,7 @@ static pDirFuncs pluginFuncs = { freePlugin, /* free plugin instance */ getPluginValue, setPluginValue, handlePluginEvent}; -/** - * Plugin private context - */ -struct plugin_private_context { - int64_t instance; /* Instance number of plugin */ - bool python_loaded; /* Plugin has python module loaded ? */ - bool python_path_set; /* Python plugin search path is set ? */ - char* module_path; /* Plugin Module Path */ - char* module_name; /* Plugin Module Name */ - PyThreadState* - interpreter; /* Python interpreter for this instance of the plugin */ - PyObject* pModule; /* Python Module entry point */ - PyObject* pyModuleFunctionsDict; /* Python Dictionary */ -}; +#include "plugin_private_context.h" /** * We don't actually use this but we need it to tear down the @@ -214,7 +193,7 @@ static void PyErrorHandler() * External entry point called by Bareos to "load" the plugin */ bRC loadPlugin(Dir_PluginApiDefinition* lbareos_plugin_interface_version, - DirCoreFunctions* lbareos_core_functions, + DirectorCoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, pDirFuncs** plugin_functions) { diff --git a/core/src/plugins/dird/python/setup.py.in b/core/src/plugins/dird/python/setup.py.in index ddcb9227aec..2cadff09c34 100644 --- a/core/src/plugins/dird/python/setup.py.in +++ b/core/src/plugins/dird/python/setup.py.in @@ -1,7 +1,7 @@ from distutils.core import setup, Extension module1 = Extension('bareosdir', - sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/python-dir.cc'], + sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/bareosdir.cc'], include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..'], libraries = ['bareos'], library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'], diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/bareosfd.h index c39f693a47f..9502a0ae871 100644 --- a/core/src/plugins/filed/python/bareosfd.h +++ b/core/src/plugins/filed/python/bareosfd.h @@ -1025,8 +1025,6 @@ static int import_bareosfd() Bareosfd_API = (void**)PyCapsule_Import("bareosfd._C_API", 0); return (Bareosfd_API != NULL) ? 0 : -1; } - - #endif // BAREOSFD_MODULE #endif /* BAREOS_PLUGINS_FILED_BAREOS_FD_H_ */ diff --git a/core/src/plugins/stored/python/python-sd.h b/core/src/plugins/stored/python/python-sd.h index c3216931732..e64f6ed50bb 100644 --- a/core/src/plugins/stored/python/python-sd.h +++ b/core/src/plugins/stored/python/python-sd.h @@ -57,6 +57,7 @@ static plugin_argument plugin_arguments[] = { {"module_path", argument_module_path}, {"module_name", argument_module_name}, {NULL, argument_none}}; + /** * Callback methods from Python. */ diff --git a/core/src/plugins/stored/python/setup.py.in b/core/src/plugins/stored/python/setup.py.in index ea277906cba..0ff22defaa7 100644 --- a/core/src/plugins/stored/python/setup.py.in +++ b/core/src/plugins/stored/python/setup.py.in @@ -1,7 +1,7 @@ from distutils.core import setup, Extension module1 = Extension('bareossd', - sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/python-sd.cc'], + sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/bareossd.cc'], include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..'], libraries = ['bareos'], library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'], From ab8ef920faf2cccf026393953c52fb31b32152a4 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 11 May 2020 18:42:11 +0200 Subject: [PATCH 097/341] Plugins: unified api --- core/src/plugins/dird/python/bareosdir.h | 2 - core/src/plugins/dird/python/python-dir.cc | 2 - core/src/plugins/filed/python/bareosfd.h | 3 +- core/src/plugins/filed/python/python-fd.cc | 3 +- core/src/plugins/stored/python/bareossd.cc | 87 ++++++ core/src/plugins/stored/python/bareossd.h | 225 ++++++++++++++ .../create_CAPI_from_bareos_api_funcs.sh | 46 +++ .../stored/python/plugin_private_context.h | 21 ++ core/src/plugins/stored/python/python-sd.cc | 280 ++++++++---------- core/src/plugins/stored/python/python-sd.h | 136 --------- .../stored/scsitapealert/scsitapealert-sd.cc | 10 +- core/src/stored/acquire.cc | 2 +- core/src/stored/append.cc | 2 +- core/src/stored/autochanger.cc | 6 +- core/src/stored/block.cc | 4 +- core/src/stored/dev.cc | 14 +- core/src/stored/dir_cmd.cc | 2 +- core/src/stored/fd_cmds.cc | 2 +- core/src/stored/job.cc | 6 +- core/src/stored/label.cc | 24 +- core/src/stored/mac.cc | 6 +- core/src/stored/mount.cc | 6 +- core/src/stored/ndmp_tape.cc | 4 +- core/src/stored/read.cc | 2 +- core/src/stored/read_record.cc | 4 +- core/src/stored/record.cc | 4 +- core/src/stored/reserve.cc | 4 +- core/src/stored/sd_cmds.cc | 4 +- core/src/stored/sd_plugins.cc | 48 +-- core/src/stored/sd_plugins.h | 72 ++--- core/src/stored/status.cc | 2 +- core/src/stored/stored.cc | 2 +- core/src/tests/test_sd_plugins.cc | 10 +- core/src/tools/bpluginfo.cc | 6 +- 34 files changed, 628 insertions(+), 423 deletions(-) create mode 100644 core/src/plugins/stored/python/bareossd.cc create mode 100644 core/src/plugins/stored/python/bareossd.h create mode 100755 core/src/plugins/stored/python/create_CAPI_from_bareos_api_funcs.sh create mode 100644 core/src/plugins/stored/python/plugin_private_context.h diff --git a/core/src/plugins/dird/python/bareosdir.h b/core/src/plugins/dird/python/bareosdir.h index e47ca89279c..b11b5c342ad 100644 --- a/core/src/plugins/dird/python/bareosdir.h +++ b/core/src/plugins/dird/python/bareosdir.h @@ -88,8 +88,6 @@ static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, bDirEvent* event, void* value); -// static void* bareos_PluginContext = NULL; - } // namespace directordaemon using namespace directordaemon; diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index bd72cbffcb9..2c11f2c567f 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -610,6 +610,4 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) return retval; } -#if 0 -#endif } /* namespace directordaemon */ diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/bareosfd.h index 9502a0ae871..17a74f219b9 100644 --- a/core/src/plugins/filed/python/bareosfd.h +++ b/core/src/plugins/filed/python/bareosfd.h @@ -791,7 +791,7 @@ MOD_INIT(bareosfd) PYTHON_MODULE_NAME_QUOTED "._C_API", NULL); if (c_api_object != NULL) PyModule_AddObject(m, "_C_API", c_api_object); - +#if 0 /* add bpFuncs Capsule */ PyObject* PyModulePluginFuncs = PyCapsule_New((void*)&bareos_core_functions, @@ -810,6 +810,7 @@ MOD_INIT(bareosfd) ":BareosCoreFunctions PyModule_AddObject failed\n"); return MOD_ERROR_VAL; } +#endif PyRestoreObjectType.tp_new = PyType_GenericNew; diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 7eacbd95874..30892dc8166 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -63,9 +63,8 @@ static bRC getPluginValue(PluginContext* plugin_ctx, static bRC setPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); - static bRC handlePluginEvent(PluginContext* plugin_ctx, - bEvent* event, + bSdEvent* event, void* value); static bRC startBackupFile(PluginContext* plugin_ctx, struct save_pkt* sp); static bRC endBackupFile(PluginContext* plugin_ctx); diff --git a/core/src/plugins/stored/python/bareossd.cc b/core/src/plugins/stored/python/bareossd.cc new file mode 100644 index 00000000000..d798393bc85 --- /dev/null +++ b/core/src/plugins/stored/python/bareossd.cc @@ -0,0 +1,87 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2020-2020 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation, which is + listed in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +/** + * @file + * Python module for the Bareos storagedaemon plugin + */ +#define PY_SSIZE_T_CLEAN +#define BUILD_PLUGIN + +#if defined(HAVE_WIN32) +#include "include/bareos.h" +#include +#else +#include +#include "include/bareos.h" +#endif + +#include "stored/sd_plugins.h" + +#define BAREOSSD_MODULE +#include "bareossd.h" +#include "lib/edit.h" + +namespace storagedaemon { + +static const int debuglevel = 150; + +static bRC set_bareos_core_functions( + StorageDaemonCoreFunctions* new_bareos_core_functions); +static bRC set_plugin_context(PluginContext* new_plugin_context); +static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); + +static bRC PyGetPluginValue(PluginContext* plugin_ctx, + pVariable var, + void* value); +static bRC PySetPluginValue(PluginContext* plugin_ctx, + pVariable var, + void* value); +static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, + bSdEvent* event, + void* value); + +/* Pointers to Bareos functions */ +static StorageDaemonCoreFunctions* bareos_core_functions = NULL; + +#include "plugin_private_context.h" + +#define NOPLUGINSETGETVALUE 1 +/* functions common to all plugins */ +#include "plugins/python_plugins_common.inc" + + +/* set the bareos_core_functions pointer to the given value */ +static bRC set_bareos_core_functions( + StorageDaemonCoreFunctions* new_bareos_core_functions) +{ + bareos_core_functions = new_bareos_core_functions; + return bRC_OK; +} + +/* set the plugin context pointer to the given value */ +static bRC set_plugin_context(PluginContext* new_plugin_context) +{ + plugin_context = new_plugin_context; + return bRC_OK; +} + + +} /* namespace storagedaemon*/ diff --git a/core/src/plugins/stored/python/bareossd.h b/core/src/plugins/stored/python/bareossd.h new file mode 100644 index 00000000000..911c5817fbd --- /dev/null +++ b/core/src/plugins/stored/python/bareossd.h @@ -0,0 +1,225 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2013-2020 Bareos GmbH & Co. KG + + This program is Free Software; you can modify it under the terms of + version three of the GNU Affero General Public License as published by the + Free Software Foundation, which is listed in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +/** + * @file + * This defines the Python types in C++ and the callbacks from Python we + * support. + */ + +#ifndef BAREOS_PLUGINS_STORED_BAREOSSD_H_ +#define BAREOS_PLUGINS_STORED_BAREOSSD_H_ 1 + +#define PYTHON_MODULE_NAME bareossd +#define PYTHON_MODULE_NAME_QUOTED "bareossd" + +/* common code for all python plugins */ +#include "plugins/python_plugins_common.h" +#include "plugins/filed/fd_common.h" + +#include "capi_1.inc" + + +#ifdef BAREOSSD_MODULE +/* This section is used when compiling bareossd.cc */ + +namespace storagedaemon { +/* include automatically generated C API */ + + +/** + * Callback methods from Python. + */ +static PyObject* PyBareosGetValue(PyObject* self, PyObject* args); +static PyObject* PyBareosSetValue(PyObject* self, PyObject* args); +static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args); +static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args); +static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args); +static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args); +static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args); + +static PyMethodDef Methods[] = { + {"GetValue", PyBareosGetValue, METH_VARARGS, "Get a Plugin value"}, + {"SetValue", PyBareosSetValue, METH_VARARGS, "Set a Plugin value"}, + {"DebugMessage", PyBareosDebugMessage, METH_VARARGS, + "Print a Debug message"}, + {"JobMessage", PyBareosJobMessage, METH_VARARGS, "Print a Job message"}, + {"RegisterEvents", PyBareosRegisterEvents, METH_VARARGS, + "Register Plugin Events"}, + {"UnRegisterEvents", PyBareosUnRegisterEvents, METH_VARARGS, + "Unregister Plugin Events"}, + {"GetInstanceCount", PyBareosGetInstanceCount, METH_VARARGS, + "Get number of instances of current plugin"}, + {NULL, NULL, 0, NULL}}; + + +static bRC set_bareos_core_functions( + StorageDaemonCoreFunctions* new_bareos_core_functions); +static bRC set_plugin_context(PluginContext* new_plugin_context); +static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); +static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); +static bRC PyGetPluginValue(PluginContext* plugin_ctx, + pVariable var, + void* value); +static bRC PySetPluginValue(PluginContext* plugin_ctx, + pVariable var, + void* value); +static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, + bSdEvent* event, + void* value); + +} /* namespace storagedaemon*/ +using namespace storagedaemon; + +/* variables storing bareos pointers */ +PluginContext* plugin_context = NULL; +static void* bareos_core_functions = NULL; + +MOD_INIT(bareossd) +{ + PyObject* m = NULL; + MOD_DEF(m, PYTHON_MODULE_NAME_QUOTED, NULL, Methods) + static void* Bareossd_API[Bareossd_API_pointers]; + PyObject* c_api_object; + + /* Initialize the C API pointer array */ +#include "capi_3.inc" + + /* Create a Capsule containing the API pointer array's address */ + c_api_object = PyCapsule_New((void*)Bareossd_API, + PYTHON_MODULE_NAME_QUOTED "._C_API", NULL); + + if (c_api_object != NULL) PyModule_AddObject(m, "_C_API", c_api_object); +#if 0 + /* add bpFuncs Capsule */ + PyObject* PyModulePluginFuncs = + PyCapsule_New((void*)&bareos_core_functions, + PYTHON_MODULE_NAME_QUOTED ".BareosCoreFunctions", NULL); + if (!PyModulePluginFuncs) { + printf(PYTHON_MODULE_NAME_QUOTED + ":BareosCoreFunctions PyCapsule_New failed\n"); + return MOD_ERROR_VAL; + } + if (PyModulePluginFuncs) { + PyModule_AddObject(m, "BareosCoreFunctions", PyModulePluginFuncs); + printf(PYTHON_MODULE_NAME_QUOTED ": added BareosCoreFunctions@%p\n", + &bareos_core_functions); + } else { + printf(PYTHON_MODULE_NAME_QUOTED + ":BareosCoreFunctions PyModule_AddObject failed\n"); + return MOD_ERROR_VAL; + } +#endif + /* module dictionaries */ + DEFINE_bRCs_DICT(); + DEFINE_bJobMessageTypes_DICT(); + + const char* bsdVariable = "bsdVariable"; + PyObject* pDictsdVariable = NULL; + pDictsdVariable = PyDict_New(); + if (!pDictsdVariable) { return MOD_ERROR_VAL; } + ConstSet_StrLong(pDictsdVariable, bsdVarJob, 1); + ConstSet_StrLong(pDictsdVariable, bsdVarLevel, 2); + ConstSet_StrLong(pDictsdVariable, bsdVarType, 3); + ConstSet_StrLong(pDictsdVariable, bsdVarJobId, 4); + ConstSet_StrLong(pDictsdVariable, bsdVarClient, 5); + ConstSet_StrLong(pDictsdVariable, bsdVarPool, 6); + ConstSet_StrLong(pDictsdVariable, bsdVarPoolType, 7); + ConstSet_StrLong(pDictsdVariable, bsdVarStorage, 8); + ConstSet_StrLong(pDictsdVariable, bsdVarMediaType, 9); + ConstSet_StrLong(pDictsdVariable, bsdVarJobName, 10); + ConstSet_StrLong(pDictsdVariable, bsdVarJobStatus, 11); + ConstSet_StrLong(pDictsdVariable, bsdVarVolumeName, 12); + ConstSet_StrLong(pDictsdVariable, bsdVarJobErrors, 13); + ConstSet_StrLong(pDictsdVariable, bsdVarJobFiles, 14); + ConstSet_StrLong(pDictsdVariable, bsdVarJobBytes, 15); + ConstSet_StrLong(pDictsdVariable, bsdVarCompatible, 16); + ConstSet_StrLong(pDictsdVariable, bsdVarPluginDir, 17); + if (PyModule_AddObject(m, bsdVariable, pDictsdVariable)) { + return MOD_ERROR_VAL; + } + + const char* bsdwVariable = "bsdwVariable"; + PyObject* pDictsdwVariable = NULL; + pDictsdwVariable = PyDict_New(); + if (!pDictsdwVariable) { return MOD_ERROR_VAL; } + ConstSet_StrLong(pDictsdwVariable, bsdwVarJobReport, 1); + ConstSet_StrLong(pDictsdwVariable, bsdwVarVolumeName, 2); + ConstSet_StrLong(pDictsdwVariable, bsdwVarPriority, 3); + ConstSet_StrLong(pDictsdwVariable, bsdwVarJobLevel, 4); + if (PyModule_AddObject(m, bsdwVariable, pDictsdwVariable)) { + return MOD_ERROR_VAL; + } + + + const char* bsdEventType = "bsdEventType"; + PyObject* pDictbsdEventType = NULL; + pDictbsdEventType = PyDict_New(); + ConstSet_StrLong(pDictbsdEventType, bsdEventJobStart, 1); + ConstSet_StrLong(pDictbsdEventType, bsdEventJobEnd, 2); + ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceInit, 3); + ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceMount, 4); + ConstSet_StrLong(pDictbsdEventType, bsdEventVolumeLoad, 5); + ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceReserve, 6); + ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceOpen, 7); + ConstSet_StrLong(pDictbsdEventType, bsdEventLabelRead, 8); + ConstSet_StrLong(pDictbsdEventType, bsdEventLabelVerified, 9); + ConstSet_StrLong(pDictbsdEventType, bsdEventLabelWrite, 10); + ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceClose, 11); + ConstSet_StrLong(pDictbsdEventType, bsdEventVolumeUnload, 12); + ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceUnmount, 13); + ConstSet_StrLong(pDictbsdEventType, bsdEventReadError, 14); + ConstSet_StrLong(pDictbsdEventType, bsdEventWriteError, 15); + ConstSet_StrLong(pDictbsdEventType, bsdEventDriveStatus, 16); + ConstSet_StrLong(pDictbsdEventType, bsdEventVolumeStatus, 17); + ConstSet_StrLong(pDictbsdEventType, bsdEventSetupRecordTranslation, 18); + ConstSet_StrLong(pDictbsdEventType, bsdEventReadRecordTranslation, 19); + ConstSet_StrLong(pDictbsdEventType, bsdEventWriteRecordTranslation, 20); + ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceRelease, 21); + ConstSet_StrLong(pDictbsdEventType, bsdEventNewPluginOptions, 22); + ConstSet_StrLong(pDictbsdEventType, bsdEventChangerLock, 23); + ConstSet_StrLong(pDictbsdEventType, bsdEventChangerUnlock, 24); + + if (!pDictbsdEventType) { return MOD_ERROR_VAL; } + if (PyModule_AddObject(m, bsdEventType, pDictbsdEventType)) { + return MOD_ERROR_VAL; + } + + return MOD_SUCCESS_VAL(m); +} + + +#else // NOT BAREOSSD_MODULE + + +/* This section is used in modules that use bareossd's API */ + +static void** Bareossd_API; + +/* include automatically generated C API */ +#include "capi_2.inc" + +static int import_bareossd() +{ + Bareossd_API = (void**)PyCapsule_Import("bareossd._C_API", 0); + return (Bareossd_API != NULL) ? 0 : -1; +} +#endif // BAREOSSD_MODULE + +#endif /* BAREOS_PLUGINS_STORED_BAREOSSD_H_ */ diff --git a/core/src/plugins/stored/python/create_CAPI_from_bareos_api_funcs.sh b/core/src/plugins/stored/python/create_CAPI_from_bareos_api_funcs.sh new file mode 100755 index 00000000000..a931d67a6a4 --- /dev/null +++ b/core/src/plugins/stored/python/create_CAPI_from_bareos_api_funcs.sh @@ -0,0 +1,46 @@ +#!/bin/bash +IFS=' +' + +exec >capi_1.inc + +echo "/* C API functions */" +NUM=0 +for i in $(cat bareossd_api_funcs.txt); do + retval=$(echo $i | sed 's/ .*//g') + funcname=$(echo $i | cut -b 5- | sed s/\(.*//g) + prot=$(echo $i | sed s/.*\(//g | sed 's/);//g') +echo " +/* static $i */ +#define Bareossd_${funcname}_NUM $NUM +#define Bareossd_${funcname}_RETURN $retval +#define Bareossd_${funcname}_PROTO (${prot})" + +((NUM=NUM+1)) +done +echo " +/*Total Number of C API function pointers */ +#define Bareossd_API_pointers $NUM" + +exec >capi_2.inc + +NUM=0 +for i in $(cat bareossd_api_funcs.txt); do + retval=$(echo $i | sed 's/ .*//g') + funcname=$(echo $i | cut -b 5- | sed s/\(.*//g) + prot=$(echo $i | sed s/.*\(//g | sed 's/);//g') + echo "#define Bareossd_${funcname} (*(Bareossd_${funcname}_RETURN(*)Bareossd_${funcname}_PROTO) Bareossd_API[Bareossd_${funcname}_NUM]) +" +((NUM=NUM+1)) +done + +exec >capi_3.inc + +NUM=0 +for i in $(cat bareossd_api_funcs.txt); do + retval=$(echo $i | sed 's/ .*//g') + funcname=$(echo $i | cut -b 5- | sed s/\(.*//g) + prot=$(echo $i | sed s/.*\(//g | sed 's/);//g') + echo " Bareossd_API[Bareossd_${funcname}_NUM] = (void*)${funcname};" +((NUM=NUM+1)) +done diff --git a/core/src/plugins/stored/python/plugin_private_context.h b/core/src/plugins/stored/python/plugin_private_context.h new file mode 100644 index 00000000000..d44b3548532 --- /dev/null +++ b/core/src/plugins/stored/python/plugin_private_context.h @@ -0,0 +1,21 @@ + +#ifndef BAREOS_CORE_SRC_PLUGINS_STORED_PYTHON_PLUGIN_PRIVATE_CONTEXT_H_ +#define BAREOS_CORE_SRC_PLUGINS_STORED_PYTHON_PLUGIN_PRIVATE_CONTEXT_H_ + +/** + * Plugin private context + */ +struct plugin_private_context { + int64_t instance; /* Instance number of plugin */ + bool python_loaded; /* Plugin has python module loaded ? */ + bool python_path_set; /* Python plugin search path is set ? */ + char* module_path; /* Plugin Module Path */ + char* module_name; /* Plugin Module Name */ + PyThreadState* + interpreter; /* Python interpreter for this instance of the plugin */ + PyObject* pModule; /* Python Module entry point */ + PyObject* pyModuleFunctionsDict; /* Python Dictionary */ +}; + + +#endif // BAREOS_CORE_SRC_PLUGINS_STORED_PYTHON_PLUGIN_PRIVATE_CONTEXT_H_ diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index 1f193066bc2..4bcb82d42ad 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -36,7 +36,7 @@ #include "stored/stored.h" #include "python-sd.h" -//#include "bareossd.h" +#include "bareossd.h" #include "lib/edit.h" namespace storagedaemon { @@ -63,7 +63,7 @@ static bRC setPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); static bRC handlePluginEvent(PluginContext* plugin_ctx, - bsdEvent* event, + bSdEvent* event, void* value); static bRC parse_plugin_definition(PluginContext* plugin_ctx, void* value, @@ -71,20 +71,10 @@ static bRC parse_plugin_definition(PluginContext* plugin_ctx, static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); static bRC PyLoadModule(PluginContext* plugin_ctx, void* value); -static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); -static bRC PyGetPluginValue(PluginContext* plugin_ctx, - pVariable var, - void* value); -static bRC PySetPluginValue(PluginContext* plugin_ctx, - pVariable var, - void* value); -static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, - bsdEvent* event, - void* value); /* Pointers to Bareos functions */ -static bsdFuncs* bareos_core_functions = NULL; -static bsdInfo* bareos_plugin_interface_version = NULL; +static StorageDaemonCoreFunctions* bareos_core_functions = NULL; +static Sd_PluginApiDefinition* bareos_plugin_interface_version = NULL; static PluginInformation pluginInfo = { sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, @@ -93,7 +83,7 @@ static PluginInformation pluginInfo = { PLUGIN_VERSION, PLUGIN_DESCRIPTION, PLUGIN_USAGE}; -static psdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, +static pSdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, /* Entry points into plugin */ newPlugin, /* new plugin instance */ @@ -101,20 +91,8 @@ static psdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, getPluginValue, setPluginValue, handlePluginEvent}; -/** - * Plugin private context - */ -struct plugin_private_context { - int64_t instance; /* Instance number of plugin */ - bool python_loaded; /* Plugin has python module loaded ? */ - bool python_path_set; /* Python plugin search path is set ? */ - char* module_path; /* Plugin Module Path */ - char* module_name; /* Plugin Module Name */ - PyThreadState* - interpreter; /* Python interpreter for this instance of the plugin */ - PyObject* pModule; /* Python Module entry point */ - PyObject* pyModuleFunctionsDict; /* Python Dictionary */ -}; +#include "plugin_private_context.h" + /** * We don't actually use this but we need it to tear down the @@ -126,10 +104,87 @@ static PyThreadState* mainThreadState; /* functions common to all plugins */ #include "plugins/python_plugins_common.inc" +/* Common functions used in all python plugins. */ +static bRC getPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value) +{ + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + bRC retval = bRC_Error; + + if (!plugin_priv_ctx) { goto bail_out; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = Bareossd_PyGetPluginValue(bareos_plugin_ctx, var, value); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + +bail_out: + return retval; +} + +static bRC setPluginValue(PluginContext* bareos_plugin_ctx, + pVariable var, + void* value) +{ + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)bareos_plugin_ctx->plugin_private_context; + bRC retval = bRC_Error; + + if (!plugin_priv_ctx) { return bRC_Error; } + + PyEval_AcquireThread(plugin_priv_ctx->interpreter); + retval = Bareossd_PySetPluginValue(bareos_plugin_ctx, var, value); + PyEval_ReleaseThread(plugin_priv_ctx->interpreter); + + return retval; +} + + #ifdef __cplusplus extern "C" { #endif +static void PyErrorHandler() +{ + PyObject *type, *value, *traceback; + PyObject* tracebackModule; + char* error_string; + + PyErr_Fetch(&type, &value, &traceback); + + tracebackModule = PyImport_ImportModule("traceback"); + if (tracebackModule != NULL) { + PyObject *tbList, *emptyString, *strRetval; + + tbList = + PyObject_CallMethod(tracebackModule, (char*)"format_exception", + (char*)"OOO", type, value == NULL ? Py_None : value, + traceback == NULL ? Py_None : traceback); + + emptyString = PyString_FromString(""); + strRetval = + PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); + + error_string = strdup(PyString_AsString(strRetval)); + + Py_DECREF(tbList); + Py_DECREF(emptyString); + Py_DECREF(strRetval); + Py_DECREF(tracebackModule); + } else { + error_string = strdup("Unable to import traceback module."); + } + Py_DECREF(type); + Py_XDECREF(value); + Py_XDECREF(traceback); + printf("%s", error_string); + + free(error_string); + exit(1); +} + + /** * loadPlugin() and unloadPlugin() are entry points that are * exported, so Bareos can directly call these two entry points @@ -137,11 +192,31 @@ extern "C" { * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, - bsdFuncs* lbareos_core_functions, +bRC loadPlugin(Sd_PluginApiDefinition* lbareos_plugin_interface_version, + StorageDaemonCoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, - psdFuncs** plugin_functions) + pSdFuncs** plugin_functions) { + Py_InitializeEx(0); + + /* import the bareossd module */ + PyObject* bareossdModule = PyImport_ImportModule("bareossd"); + if (bareossdModule) { + printf("loaded bareossd successfully\n"); + } else { + printf("loading of bareossd failed\n"); + if (PyErr_Occurred()) { PyErrorHandler(); } + } + + /* import the CAPI from the bareossd python module + * afterwards, Bareossd_* macros are initialized to + * point to the corresponding functions in the bareossd python + * module */ + import_bareossd(); + + /* set bareos_core_functions inside of barossd module */ + Bareossd_set_bareos_core_functions(lbareos_core_functions); + bareos_core_functions = lbareos_core_functions; /* Set Bareos funct pointers */ bareos_plugin_interface_version = lbareos_plugin_interface_version; @@ -149,16 +224,8 @@ bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, *plugin_information = &pluginInfo; /* Return pointer to our info */ *plugin_functions = &pluginFuncs; /* Return pointer to our functions */ - /* Setup Python */ -#if PY_MAJOR_VERSION >= 3 - PyImport_AppendInittab("bareossd", &PyInit_bareossd); -#else - PyImport_AppendInittab("bareossd", initbareossd); -#endif - Py_InitializeEx(0); PyEval_InitThreads(); mainThreadState = PyEval_SaveThread(); - return bRC_OK; } @@ -191,6 +258,8 @@ static bRC newPlugin(PluginContext* plugin_ctx) plugin_ctx->plugin_private_context = (void*)plugin_priv_ctx; /* set our context pointer */ + /* set bareos_plugin_context inside of barossd module */ + Bareossd_set_plugin_context(plugin_ctx); /* For each plugin instance we instantiate a new Python interpreter. */ PyEval_AcquireThread(mainThreadState); plugin_priv_ctx->interpreter = Py_NewInterpreter(); @@ -201,7 +270,7 @@ static bRC newPlugin(PluginContext* plugin_ctx) * any other events it is interested in. */ bareos_core_functions->registerBareosEvents(plugin_ctx, 1, - bsdEventNewPluginOptions); + bSdEventNewPluginOptions); return bRC_OK; } @@ -233,7 +302,7 @@ static bRC freePlugin(PluginContext* plugin_ctx) static bRC handlePluginEvent(PluginContext* plugin_ctx, - bsdEvent* event, + bSdEvent* event, void* value) { bRC retval = bRC_Error; @@ -249,7 +318,7 @@ static bRC handlePluginEvent(PluginContext* plugin_ctx, * want to do some special handling on the event triggered. */ switch (event->eventType) { - case bsdEventNewPluginOptions: + case bSdEventNewPluginOptions: event_dispatched = true; retval = parse_plugin_definition(plugin_ctx, value, plugin_options); break; @@ -271,7 +340,7 @@ static bRC handlePluginEvent(PluginContext* plugin_ctx, * First the calls that need special handling. */ switch (event->eventType) { - case bsdEventNewPluginOptions: + case bSdEventNewPluginOptions: /* * See if we already loaded the Python modules. */ @@ -281,7 +350,8 @@ static bRC handlePluginEvent(PluginContext* plugin_ctx, /* Only try to call when the loading succeeded. */ if (retval == bRC_OK) { - retval = PyParsePluginDefinition(plugin_ctx, plugin_options.c_str()); + retval = Bareossd_PyParsePluginDefinition(plugin_ctx, + plugin_options.c_str()); } break; default: @@ -291,7 +361,7 @@ static bRC handlePluginEvent(PluginContext* plugin_ctx, * that time we pretend the call succeeded. */ if (plugin_priv_ctx->python_loaded) { - retval = PyHandlePluginEvent(plugin_ctx, event, value); + retval = Bareossd_PyHandlePluginEvent(plugin_ctx, event, value); } else { retval = bRC_OK; } @@ -447,7 +517,6 @@ static bRC parse_plugin_definition(PluginContext* plugin_ctx, return bRC_Error; } - /** * Initial load of the Python module. * @@ -461,14 +530,9 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) struct plugin_private_context* plugin_priv_ctx = (struct plugin_private_context*)plugin_ctx->plugin_private_context; PyObject *sysPath, *mPath, *pName, *pFunc; - - /* - * See if we already setup the python search path. - */ + /* See if we already setup the python search path. */ if (!plugin_priv_ctx->python_path_set) { - /* - * Extend the Python search path with the given module_path. - */ + /* Extend the Python search path with the given module_path */ if (plugin_priv_ctx->module_path) { sysPath = PySys_GetObject((char*)"path"); mPath = PyString_FromString(plugin_priv_ctx->module_path); @@ -478,9 +542,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) } } - /* - * Try to load the Python module by name. - */ + /* Try to load the Python module by name. */ if (plugin_priv_ctx->module_name) { Dmsg(plugin_ctx, debuglevel, "python-sd: Trying to load module with name %s\n", @@ -548,108 +610,4 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) return retval; } -/** - * Any plugin options which are passed in are dispatched here to a Python method - * and it can parse the plugin options. This function is also called after - * PyLoadModule() has loaded the Python module and made sure things are - * operational. - */ -static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)plugin_ctx->plugin_private_context; - PyObject* pFunc; - - /* - * Lookup the parse_plugin_definition() function in the python module. - */ - pFunc = - PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "parse_plugin_definition"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyObject *pPluginDefinition, *pRetVal; - - pPluginDefinition = PyString_FromString((char*)value); - if (!pPluginDefinition) { goto bail_out; } - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); - Py_DECREF(pPluginDefinition); - - if (!pRetVal) { - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - } - - return retval; - } else { - Dmsg( - plugin_ctx, debuglevel, - "python-sd: Failed to find function named parse_plugin_definition()\n"); - return bRC_Error; - } - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } - - return retval; -} - -static bRC PyGetPluginValue(PluginContext* plugin_ctx, - pVariable var, - void* value) -{ - return bRC_OK; -} - -static bRC PySetPluginValue(PluginContext* plugin_ctx, - pVariable var, - void* value) -{ - return bRC_OK; -} - -static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, - bsdEvent* event, - void* value) -{ - bRC retval = bRC_Error; - plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)plugin_ctx->plugin_private_context; - PyObject* pFunc; - - /* - * Lookup the handle_plugin_event() function in the python module. - */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "handle_plugin_event"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyObject *pEventType, *pRetVal; - - pEventType = PyInt_FromLong(event->eventType); - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pEventType, NULL); - Py_DECREF(pEventType); - - if (!pRetVal) { - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - } - } else { - Dmsg(plugin_ctx, debuglevel, - "python-sd: Failed to find function named handle_plugin_event()\n"); - } - - return retval; - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } - - return retval; -} - } /* namespace storagedaemon*/ diff --git a/core/src/plugins/stored/python/python-sd.h b/core/src/plugins/stored/python/python-sd.h index e64f6ed50bb..29ddac8c17e 100644 --- a/core/src/plugins/stored/python/python-sd.h +++ b/core/src/plugins/stored/python/python-sd.h @@ -58,141 +58,5 @@ static plugin_argument plugin_arguments[] = { {"module_name", argument_module_name}, {NULL, argument_none}}; -/** - * Callback methods from Python. - */ -static PyObject* PyBareosGetValue(PyObject* self, PyObject* args); -static PyObject* PyBareosSetValue(PyObject* self, PyObject* args); -static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args); -static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args); -static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args); -static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args); -static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args); - -static PyMethodDef Methods[] = { - {"GetValue", PyBareosGetValue, METH_VARARGS, "Get a Plugin value"}, - {"SetValue", PyBareosSetValue, METH_VARARGS, "Set a Plugin value"}, - {"DebugMessage", PyBareosDebugMessage, METH_VARARGS, - "Print a Debug message"}, - {"JobMessage", PyBareosJobMessage, METH_VARARGS, "Print a Job message"}, - {"RegisterEvents", PyBareosRegisterEvents, METH_VARARGS, - "Register Plugin Events"}, - {"UnRegisterEvents", PyBareosUnRegisterEvents, METH_VARARGS, - "Unregister Plugin Events"}, - {"GetInstanceCount", PyBareosGetInstanceCount, METH_VARARGS, - "Get number of instances of current plugin"}, - {NULL, NULL, 0, NULL}}; - - -static void* bareos_PluginContext = NULL; - -// MOD_INIT(PYTHON_MODULE_NAME) -MOD_INIT(bareossd) -{ - /* bareos_PluginContext holds the PluginContext instead of passing - * to Python and extracting it back like it was before. bareos_PluginContext - * needs to be set after loading the PYTHON_MODULE_NAME binary python module - * and will be used for all calls. - */ - - PyObject* m = NULL; - - /* Pointer Capsules to avoid context transfer back and forth */ - PyObject* PyModulePluginContext = - PyCapsule_New((void*)&bareos_PluginContext, - PYTHON_MODULE_NAME_QUOTED ".PluginContext", NULL); - - if (!PyModulePluginContext) { - printf(PYTHON_MODULE_NAME_QUOTED ": PyCapsule_New failed\n"); - return MOD_ERROR_VAL; - } - - MOD_DEF(m, PYTHON_MODULE_NAME_QUOTED, NULL, Methods) - - if (PyModulePluginContext) { - PyModule_AddObject(m, "PluginContext", PyModulePluginContext); - } else { - printf(PYTHON_MODULE_NAME_QUOTED ":PyModule_AddObject failed\n"); - return MOD_ERROR_VAL; - } - - /* module dictionaries */ - DEFINE_bRCs_DICT(); - DEFINE_bJobMessageTypes_DICT(); - - const char* bsdVariable = "bsdVariable"; - PyObject* pDictsdVariable = NULL; - pDictsdVariable = PyDict_New(); - if (!pDictsdVariable) { return MOD_ERROR_VAL; } - ConstSet_StrLong(pDictsdVariable, bsdVarJob, 1); - ConstSet_StrLong(pDictsdVariable, bsdVarLevel, 2); - ConstSet_StrLong(pDictsdVariable, bsdVarType, 3); - ConstSet_StrLong(pDictsdVariable, bsdVarJobId, 4); - ConstSet_StrLong(pDictsdVariable, bsdVarClient, 5); - ConstSet_StrLong(pDictsdVariable, bsdVarPool, 6); - ConstSet_StrLong(pDictsdVariable, bsdVarPoolType, 7); - ConstSet_StrLong(pDictsdVariable, bsdVarStorage, 8); - ConstSet_StrLong(pDictsdVariable, bsdVarMediaType, 9); - ConstSet_StrLong(pDictsdVariable, bsdVarJobName, 10); - ConstSet_StrLong(pDictsdVariable, bsdVarJobStatus, 11); - ConstSet_StrLong(pDictsdVariable, bsdVarVolumeName, 12); - ConstSet_StrLong(pDictsdVariable, bsdVarJobErrors, 13); - ConstSet_StrLong(pDictsdVariable, bsdVarJobFiles, 14); - ConstSet_StrLong(pDictsdVariable, bsdVarJobBytes, 15); - ConstSet_StrLong(pDictsdVariable, bsdVarCompatible, 16); - ConstSet_StrLong(pDictsdVariable, bsdVarPluginDir, 17); - if (PyModule_AddObject(m, bsdVariable, pDictsdVariable)) { - return MOD_ERROR_VAL; - } - - const char* bsdwVariable = "bsdwVariable"; - PyObject* pDictsdwVariable = NULL; - pDictsdwVariable = PyDict_New(); - if (!pDictsdwVariable) { return MOD_ERROR_VAL; } - ConstSet_StrLong(pDictsdwVariable, bsdwVarJobReport, 1); - ConstSet_StrLong(pDictsdwVariable, bsdwVarVolumeName, 2); - ConstSet_StrLong(pDictsdwVariable, bsdwVarPriority, 3); - ConstSet_StrLong(pDictsdwVariable, bsdwVarJobLevel, 4); - if (PyModule_AddObject(m, bsdwVariable, pDictsdwVariable)) { - return MOD_ERROR_VAL; - } - - - const char* bsdEventType = "bsdEventType"; - PyObject* pDictbsdEventType = NULL; - pDictbsdEventType = PyDict_New(); - ConstSet_StrLong(pDictbsdEventType, bsdEventJobStart, 1); - ConstSet_StrLong(pDictbsdEventType, bsdEventJobEnd, 2); - ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceInit, 3); - ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceMount, 4); - ConstSet_StrLong(pDictbsdEventType, bsdEventVolumeLoad, 5); - ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceReserve, 6); - ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceOpen, 7); - ConstSet_StrLong(pDictbsdEventType, bsdEventLabelRead, 8); - ConstSet_StrLong(pDictbsdEventType, bsdEventLabelVerified, 9); - ConstSet_StrLong(pDictbsdEventType, bsdEventLabelWrite, 10); - ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceClose, 11); - ConstSet_StrLong(pDictbsdEventType, bsdEventVolumeUnload, 12); - ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceUnmount, 13); - ConstSet_StrLong(pDictbsdEventType, bsdEventReadError, 14); - ConstSet_StrLong(pDictbsdEventType, bsdEventWriteError, 15); - ConstSet_StrLong(pDictbsdEventType, bsdEventDriveStatus, 16); - ConstSet_StrLong(pDictbsdEventType, bsdEventVolumeStatus, 17); - ConstSet_StrLong(pDictbsdEventType, bsdEventSetupRecordTranslation, 18); - ConstSet_StrLong(pDictbsdEventType, bsdEventReadRecordTranslation, 19); - ConstSet_StrLong(pDictbsdEventType, bsdEventWriteRecordTranslation, 20); - ConstSet_StrLong(pDictbsdEventType, bsdEventDeviceRelease, 21); - ConstSet_StrLong(pDictbsdEventType, bsdEventNewPluginOptions, 22); - ConstSet_StrLong(pDictbsdEventType, bsdEventChangerLock, 23); - ConstSet_StrLong(pDictbsdEventType, bsdEventChangerUnlock, 24); - - if (!pDictbsdEventType) { return MOD_ERROR_VAL; } - if (PyModule_AddObject(m, bsdEventType, pDictbsdEventType)) { - return MOD_ERROR_VAL; - } - - return MOD_SUCCESS_VAL(m); -} - } /* namespace storagedaemon*/ #endif /* BAREOS_PLUGINS_STORED_PYTHON_SD_H_ */ diff --git a/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc b/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc index 218e78711d9..0b34080bddc 100644 --- a/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc +++ b/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc @@ -47,13 +47,13 @@ static bRC newPlugin(PluginContext* ctx); static bRC freePlugin(PluginContext* ctx); static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value); static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value); -static bRC handlePluginEvent(PluginContext* ctx, bsdEvent* event, void* value); +static bRC handlePluginEvent(PluginContext* ctx, bSdEvent* event, void* value); static bRC handle_tapealert_readout(void* value); /** * Pointers to Bareos functions */ -static bsdFuncs* bareos_core_functions = NULL; +static StorageDaemonCoreFunctions* bareos_core_functions = NULL; static bsdInfo* bareos_plugin_interface_version = NULL; static PluginInformation pluginInfo = { @@ -63,7 +63,7 @@ static PluginInformation pluginInfo = { PLUGIN_VERSION, PLUGIN_DESCRIPTION, PLUGIN_USAGE}; -static psdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, +static pSdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, /* * Entry points into plugin @@ -87,9 +87,9 @@ extern "C" { * External entry point called by Bareos to "load the plugin */ bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, - bsdFuncs* lbareos_core_functions, + StorageDaemonCoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, - psdFuncs** plugin_functions) + pSdFuncs** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ diff --git a/core/src/stored/acquire.cc b/core/src/stored/acquire.cc index 3211f1fce74..db2f014ba62 100644 --- a/core/src/stored/acquire.cc +++ b/core/src/stored/acquire.cc @@ -704,7 +704,7 @@ bool ReleaseDevice(DeviceControlRecord* dcr) * plugins can register to. */ if (dev->NumReserved() == 0) { - GeneratePluginEvent(jcr, bsdEventDeviceRelease, dcr); + GeneratePluginEvent(jcr, bSdEventDeviceRelease, dcr); } } } diff --git a/core/src/stored/append.cc b/core/src/stored/append.cc index 63652b409b2..d52384dce68 100644 --- a/core/src/stored/append.cc +++ b/core/src/stored/append.cc @@ -87,7 +87,7 @@ bool DoAppendData(JobControlRecord* jcr, BareosSocket* bs, const char* what) if (!AcquireDeviceForAppend(dcr)) { goto bail_out; } - if (GeneratePluginEvent(jcr, bsdEventSetupRecordTranslation, dcr) != bRC_OK) { + if (GeneratePluginEvent(jcr, bSdEventSetupRecordTranslation, dcr) != bRC_OK) { goto bail_out; } diff --git a/core/src/stored/autochanger.cc b/core/src/stored/autochanger.cc index bceef561fb8..052f69f0501 100644 --- a/core/src/stored/autochanger.cc +++ b/core/src/stored/autochanger.cc @@ -418,8 +418,8 @@ static bool LockChanger(DeviceControlRecord* dcr) * We just locked the changer for exclusive use so let any plugin know we * have. */ - if (GeneratePluginEvent(dcr->jcr, bsdEventChangerLock, dcr) != bRC_OK) { - Dmsg0(100, "Locking changer: bsdEventChangerLock failed\n"); + if (GeneratePluginEvent(dcr->jcr, bSdEventChangerLock, dcr) != bRC_OK) { + Dmsg0(100, "Locking changer: bSdEventChangerLock failed\n"); RwlWriteunlock(&changer_res->changer_lock); return false; } @@ -435,7 +435,7 @@ static bool UnlockChanger(DeviceControlRecord* dcr) if (changer_res) { int errstat; - GeneratePluginEvent(dcr->jcr, bsdEventChangerUnlock, dcr); + GeneratePluginEvent(dcr->jcr, bSdEventChangerUnlock, dcr); Dmsg1(200, "Unlocking changer %s\n", changer_res->resource_name_); if ((errstat = RwlWriteunlock(&changer_res->changer_lock)) != 0) { diff --git a/core/src/stored/block.cc b/core/src/stored/block.cc index 4cee6736c7c..2bb9b3cd022 100644 --- a/core/src/stored/block.cc +++ b/core/src/stored/block.cc @@ -822,7 +822,7 @@ bool DeviceControlRecord::WriteBlockToDev() be.bstrerror()); } - GeneratePluginEvent(jcr, bsdEventWriteError, dcr); + GeneratePluginEvent(jcr, bSdEventWriteError, dcr); if (dev->dev_errno != ENOSPC) { Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg); } @@ -1055,7 +1055,7 @@ DeviceControlRecord::ReadStatus DeviceControlRecord::ReadBlockFromDev( dev->fd(), dev->file, dev->block_num, dev->print_name(), be.bstrerror()); - GeneratePluginEvent(jcr, bsdEventReadError, dcr); + GeneratePluginEvent(jcr, bSdEventReadError, dcr); Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg); if (device_resource->eof_on_error_is_eot && dev->AtEof()) { diff --git a/core/src/stored/dev.cc b/core/src/stored/dev.cc index 0bcc01c644a..1d3a6fa3c73 100644 --- a/core/src/stored/dev.cc +++ b/core/src/stored/dev.cc @@ -630,8 +630,8 @@ bool Device::open(DeviceControlRecord* dcr, DeviceMode omode) /* * We are about to open the device so let any plugin know we are. */ - if (dcr && GeneratePluginEvent(dcr->jcr, bsdEventDeviceOpen, dcr) != bRC_OK) { - Dmsg0(100, "open_dev: bsdEventDeviceOpen failed\n"); + if (dcr && GeneratePluginEvent(dcr->jcr, bSdEventDeviceOpen, dcr) != bRC_OK) { + Dmsg0(100, "open_dev: bSdEventDeviceOpen failed\n"); return false; } @@ -1054,7 +1054,7 @@ bool Device::close(DeviceControlRecord* dcr) /* * We closed the device so let any plugin know we did. */ - if (dcr) { GeneratePluginEvent(dcr->jcr, bsdEventDeviceClose, dcr); } + if (dcr) { GeneratePluginEvent(dcr->jcr, bSdEventDeviceClose, dcr); } bail_out: return retval; @@ -1076,11 +1076,11 @@ bool Device::mount(DeviceControlRecord* dcr, int timeout) /* * When the mount command succeeded sent a - * bsdEventDeviceMount plugin event so any plugin + * bSdEventDeviceMount plugin event so any plugin * that want to do something can do things now. */ if (retval && - GeneratePluginEvent(dcr->jcr, bsdEventDeviceMount, dcr) != bRC_OK) { + GeneratePluginEvent(dcr->jcr, bSdEventDeviceMount, dcr) != bRC_OK) { retval = false; } @@ -1109,11 +1109,11 @@ bool Device::unmount(DeviceControlRecord* dcr, int timeout) /* * Before running the unmount program sent a - * bsdEventDeviceUnmount plugin event so any plugin + * bSdEventDeviceUnmount plugin event so any plugin * that want to do something can do things now. */ if (dcr && - GeneratePluginEvent(dcr->jcr, bsdEventDeviceUnmount, dcr) != bRC_OK) { + GeneratePluginEvent(dcr->jcr, bSdEventDeviceUnmount, dcr) != bRC_OK) { retval = false; goto bail_out; } diff --git a/core/src/stored/dir_cmd.cc b/core/src/stored/dir_cmd.cc index dd5604caf8a..d853eaa0845 100644 --- a/core/src/stored/dir_cmd.cc +++ b/core/src/stored/dir_cmd.cc @@ -332,7 +332,7 @@ void* HandleDirectorConnection(BareosSocket* dir) } bail_out: - GeneratePluginEvent(jcr, bsdEventJobEnd); + GeneratePluginEvent(jcr, bSdEventJobEnd); DequeueMessages(jcr); /* send any queued messages */ dir->signal(BNET_TERMINATE); FreePlugins(jcr); /* release instantiated plugins */ diff --git a/core/src/stored/fd_cmds.cc b/core/src/stored/fd_cmds.cc index 132aad1e23b..d499e6cdd00 100644 --- a/core/src/stored/fd_cmds.cc +++ b/core/src/stored/fd_cmds.cc @@ -187,7 +187,7 @@ void RunJob(JobControlRecord* jcr) DequeueMessages(jcr); /* send any queued messages */ jcr->setJobStatus(JS_Terminated); - GeneratePluginEvent(jcr, bsdEventJobEnd); + GeneratePluginEvent(jcr, bSdEventJobEnd); dir->fsend(Job_end, jcr->Job, jcr->JobStatus, jcr->JobFiles, edit_uint64(jcr->JobBytes, ec1), jcr->JobErrors); diff --git a/core/src/stored/job.cc b/core/src/stored/job.cc index b43ef9e5864..211d765937f 100644 --- a/core/src/stored/job.cc +++ b/core/src/stored/job.cc @@ -3,7 +3,7 @@ Copyright (C) 2000-2011 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2016 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -172,7 +172,7 @@ bool job_cmd(JobControlRecord* jcr) Dmsg2(50, ">dird jid=%u: %s", (uint32_t)jcr->JobId, dir->msg); DispatchNewPluginOptions(jcr); - GeneratePluginEvent(jcr, bsdEventJobStart, (void*)"JobStart"); + GeneratePluginEvent(jcr, bSdEventJobStart, (void*)"JobStart"); return true; } @@ -369,7 +369,7 @@ bool FinishCmd(JobControlRecord* jcr) break; } - GeneratePluginEvent(jcr, bsdEventJobEnd); + GeneratePluginEvent(jcr, bSdEventJobEnd); dir->fsend(Job_end, jcr->Job, jcr->JobStatus, jcr->JobFiles, edit_uint64(jcr->JobBytes, ec1), jcr->JobErrors); diff --git a/core/src/stored/label.cc b/core/src/stored/label.cc index f76e4ff0897..a2b435063c6 100644 --- a/core/src/stored/label.cc +++ b/core/src/stored/label.cc @@ -110,11 +110,11 @@ int ReadDevVolumeLabel(DeviceControlRecord* dcr) bstrncpy(dev->VolHdr.Id, "**error**", sizeof(dev->VolHdr.Id)); /* - * The stored plugin handling the bsdEventLabelRead event can abort + * The stored plugin handling the bSdEventLabelRead event can abort * the reading of the label by returning a non bRC_OK. */ - if (GeneratePluginEvent(jcr, bsdEventLabelRead, dcr) != bRC_OK) { - Dmsg0(200, "Error from bsdEventLabelRead plugin event.\n"); + if (GeneratePluginEvent(jcr, bSdEventLabelRead, dcr) != bRC_OK) { + Dmsg0(200, "Error from bSdEventLabelRead plugin event.\n"); return VOL_NO_MEDIA; } @@ -275,15 +275,15 @@ int ReadDevVolumeLabel(DeviceControlRecord* dcr) ok_out: /* - * The stored plugin handling the bsdEventLabelVerified event can override + * The stored plugin handling the bSdEventLabelVerified event can override * the return value e.g. although we think the volume label is ok the plugin * has reasons to override that. So when the plugin returns something else * then bRC_OK it want to tell us the volume is not OK to use and as * such we return VOL_NAME_ERROR as error although it might not be the * best error it should be sufficient. */ - if (GeneratePluginEvent(jcr, bsdEventLabelVerified, dcr) != bRC_OK) { - Dmsg0(200, "Error from bsdEventLabelVerified plugin event.\n"); + if (GeneratePluginEvent(jcr, bSdEventLabelVerified, dcr) != bRC_OK) { + Dmsg0(200, "Error from bSdEventLabelVerified plugin event.\n"); status = VOL_NAME_ERROR; goto bail_out; } @@ -398,8 +398,8 @@ bool WriteNewVolumeLabelToDev(DeviceControlRecord* dcr, * Let any stored plugin know that we are about to write a new label to the * volume. */ - if (GeneratePluginEvent(jcr, bsdEventLabelWrite, dcr) != bRC_OK) { - Dmsg0(200, "Error from bsdEventLabelWrite plugin event.\n"); + if (GeneratePluginEvent(jcr, bSdEventLabelWrite, dcr) != bRC_OK) { + Dmsg0(200, "Error from bSdEventLabelWrite plugin event.\n"); goto bail_out; } @@ -1109,8 +1109,8 @@ bool DeviceControlRecord::RewriteVolumeLabel(bool recycle) /* * Let any stored plugin know that we are (re)writing the label. */ - if (GeneratePluginEvent(jcr, bsdEventLabelWrite, dcr) != bRC_OK) { - Dmsg0(200, "Error from bsdEventLabelWrite plugin event.\n"); + if (GeneratePluginEvent(jcr, bSdEventLabelWrite, dcr) != bRC_OK) { + Dmsg0(200, "Error from bSdEventLabelWrite plugin event.\n"); return false; } @@ -1228,8 +1228,8 @@ bool DeviceControlRecord::RewriteVolumeLabel(bool recycle) * Let any stored plugin know the label was rewritten and as such is verified * . */ - if (GeneratePluginEvent(jcr, bsdEventLabelVerified, dcr) != bRC_OK) { - Dmsg0(200, "Error from bsdEventLabelVerified plugin event.\n"); + if (GeneratePluginEvent(jcr, bSdEventLabelVerified, dcr) != bRC_OK) { + Dmsg0(200, "Error from bSdEventLabelVerified plugin event.\n"); return false; } diff --git a/core/src/stored/mac.cc b/core/src/stored/mac.cc index 8a18d21c436..1893f8bd9f8 100644 --- a/core/src/stored/mac.cc +++ b/core/src/stored/mac.cc @@ -226,14 +226,14 @@ static bool CloneRecordInternally(DeviceControlRecord* dcr, DeviceRecord* rec) */ jcr->impl->dcr->before_rec = rec; jcr->impl->dcr->after_rec = NULL; - if (GeneratePluginEvent(jcr, bsdEventWriteRecordTranslation, + if (GeneratePluginEvent(jcr, bSdEventWriteRecordTranslation, jcr->impl->dcr) != bRC_OK) { goto bail_out; } /* * The record got translated when we got an after_rec pointer after calling - * the bsdEventWriteRecordTranslation plugin event. If no translation has + * the bSdEventWriteRecordTranslation plugin event. If no translation has * taken place we just point the after_rec pointer to same DeviceRecord as in * the before_rec pointer. */ @@ -798,7 +798,7 @@ bool DoMacRun(JobControlRecord* jcr) DequeueMessages(jcr); /* send any queued messages */ if (ok) { jcr->setJobStatus(JS_Terminated); } - GeneratePluginEvent(jcr, bsdEventJobEnd); + GeneratePluginEvent(jcr, bSdEventJobEnd); dir->fsend(Job_end, jcr->Job, jcr->JobStatus, jcr->JobFiles, edit_uint64(jcr->JobBytes, ec1), jcr->JobErrors); Dmsg4(100, Job_end, jcr->Job, jcr->JobStatus, jcr->JobFiles, ec1); diff --git a/core/src/stored/mount.cc b/core/src/stored/mount.cc index 36af9bf59a9..6ad5c0248e9 100644 --- a/core/src/stored/mount.cc +++ b/core/src/stored/mount.cc @@ -606,7 +606,7 @@ bool DeviceControlRecord::DoUnload() { DeviceControlRecord* dcr = this; - if (GeneratePluginEvent(jcr, bsdEventVolumeUnload, dcr) != bRC_OK) { + if (GeneratePluginEvent(jcr, bSdEventVolumeUnload, dcr) != bRC_OK) { return false; } @@ -632,7 +632,7 @@ bool DeviceControlRecord::DoLoad(bool IsWriting) retval = true; } - if (GeneratePluginEvent(jcr, bsdEventVolumeLoad, dcr) != bRC_OK) { + if (GeneratePluginEvent(jcr, bSdEventVolumeLoad, dcr) != bRC_OK) { retval = false; } @@ -874,7 +874,7 @@ void DeviceControlRecord::ReleaseVolume() UnloadAutochanger(dcr, -1); - GeneratePluginEvent(jcr, bsdEventVolumeUnload, dcr); + GeneratePluginEvent(jcr, bSdEventVolumeUnload, dcr); if (WroteVol) { Jmsg0(jcr, M_ERROR, 0, _("Hey!!!!! WroteVol non-zero !!!!!\n")); diff --git a/core/src/stored/ndmp_tape.cc b/core/src/stored/ndmp_tape.cc index a633beae649..c66e7fff85c 100644 --- a/core/src/stored/ndmp_tape.cc +++ b/core/src/stored/ndmp_tape.cc @@ -664,7 +664,7 @@ extern "C" ndmp9_error bndmp_tape_open(struct ndm_session* sess, * Let any SD plugin know now its time to setup the record translation * infra. */ - if (GeneratePluginEvent(jcr, bsdEventSetupRecordTranslation, dcr) != + if (GeneratePluginEvent(jcr, bSdEventSetupRecordTranslation, dcr) != bRC_OK) { goto bail_out; } @@ -750,7 +750,7 @@ extern "C" ndmp9_error bndmp_tape_open(struct ndm_session* sess, * Let any SD plugin know now its time to setup the record translation * infra. */ - if (GeneratePluginEvent(jcr, bsdEventSetupRecordTranslation, dcr) != + if (GeneratePluginEvent(jcr, bSdEventSetupRecordTranslation, dcr) != bRC_OK) { goto bail_out; } diff --git a/core/src/stored/read.cc b/core/src/stored/read.cc index 3353b5c0207..06642092b93 100644 --- a/core/src/stored/read.cc +++ b/core/src/stored/read.cc @@ -89,7 +89,7 @@ bool DoReadData(JobControlRecord* jcr) /* * Let any SD plugin know now its time to setup the record translation infra. */ - if (GeneratePluginEvent(jcr, bsdEventSetupRecordTranslation, dcr) != bRC_OK) { + if (GeneratePluginEvent(jcr, bSdEventSetupRecordTranslation, dcr) != bRC_OK) { jcr->setJobStatus(JS_ErrorTerminated); return false; } diff --git a/core/src/stored/read_record.cc b/core/src/stored/read_record.cc index 2101b0b3456..a8de77d1af5 100644 --- a/core/src/stored/read_record.cc +++ b/core/src/stored/read_record.cc @@ -482,7 +482,7 @@ bool ReadRecords(DeviceControlRecord* dcr, * GeneratePluginEvent() the reverse argument so it knows that we want * the plugins to be called in that order. */ - if (GeneratePluginEvent(jcr, bsdEventReadRecordTranslation, dcr, + if (GeneratePluginEvent(jcr, bSdEventReadRecordTranslation, dcr, true) != bRC_OK) { ok = false; continue; @@ -490,7 +490,7 @@ bool ReadRecords(DeviceControlRecord* dcr, /* * The record got translated when we got an after_rec pointer after - * calling the bsdEventReadRecordTranslation plugin event. If no + * calling the bSdEventReadRecordTranslation plugin event. If no * translation has taken place we just point the rec pointer to same * DeviceRecord as in the before_rec pointer. */ diff --git a/core/src/stored/record.cc b/core/src/stored/record.cc index fcd1671614a..4673127260c 100644 --- a/core/src/stored/record.cc +++ b/core/src/stored/record.cc @@ -658,14 +658,14 @@ bool DeviceControlRecord::WriteRecord() */ before_rec = rec; after_rec = NULL; - if (GeneratePluginEvent(jcr, bsdEventWriteRecordTranslation, this) != + if (GeneratePluginEvent(jcr, bSdEventWriteRecordTranslation, this) != bRC_OK) { goto bail_out; } /* * The record got translated when we got an after_rec pointer after calling - * the bsdEventWriteRecordTranslation plugin event. If no translation has + * the bSdEventWriteRecordTranslation plugin event. If no translation has * taken place we just point the after_rec pointer to same DeviceRecord as in * the before_rec pointer. */ diff --git a/core/src/stored/reserve.cc b/core/src/stored/reserve.cc index a10e4c8af61..5e7d37009fa 100644 --- a/core/src/stored/reserve.cc +++ b/core/src/stored/reserve.cc @@ -890,7 +890,7 @@ static bool ReserveDeviceForRead(DeviceControlRecord* dcr) /* * Note: on failure this returns jcr->errmsg properly edited */ - if (GeneratePluginEvent(jcr, bsdEventDeviceReserve, dcr) != bRC_OK) { + if (GeneratePluginEvent(jcr, bSdEventDeviceReserve, dcr) != bRC_OK) { QueueReserveMessage(jcr); goto bail_out; } @@ -967,7 +967,7 @@ static bool ReserveDeviceForAppend(DeviceControlRecord* dcr, /* * Note: on failure this returns jcr->errmsg properly edited */ - if (GeneratePluginEvent(jcr, bsdEventDeviceReserve, dcr) != bRC_OK) { + if (GeneratePluginEvent(jcr, bSdEventDeviceReserve, dcr) != bRC_OK) { QueueReserveMessage(jcr); goto bail_out; } diff --git a/core/src/stored/sd_cmds.cc b/core/src/stored/sd_cmds.cc index db1c490e687..f656825ee69 100644 --- a/core/src/stored/sd_cmds.cc +++ b/core/src/stored/sd_cmds.cc @@ -2,7 +2,7 @@ BAREOS - Backup Archiving REcovery Open Sourced Copyright (C) 2012 Planets Communications B.V. - Copyright (C) 2013-2016 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -277,7 +277,7 @@ bool DoListenRun(JobControlRecord* jcr) jcr->setJobStatus(JS_Terminated); cleanup: - GeneratePluginEvent(jcr, bsdEventJobEnd); + GeneratePluginEvent(jcr, bSdEventJobEnd); dir->fsend(Job_end, jcr->Job, jcr->JobStatus, jcr->JobFiles, edit_uint64(jcr->JobBytes, ec1), jcr->JobErrors); diff --git a/core/src/stored/sd_plugins.cc b/core/src/stored/sd_plugins.cc index 59060618040..3b1d699ed41 100644 --- a/core/src/stored/sd_plugins.cc +++ b/core/src/stored/sd_plugins.cc @@ -83,19 +83,27 @@ static void bareosFreeRecord(DeviceRecord* rec); static bool IsPluginCompatible(Plugin* plugin); /* Bareos info */ -static bsdInfo bareos_plugin_interface_version = {sizeof(bsdFuncs), - SD_PLUGIN_INTERFACE_VERSION}; +static Sd_PluginApiDefinition bareos_plugin_interface_version = { + sizeof(pSdFuncs), SD_PLUGIN_INTERFACE_VERSION}; /* Bareos entry points */ -static bsdFuncs bareos_core_functions = { - sizeof(bsdFuncs), SD_PLUGIN_INTERFACE_VERSION, - bareosRegisterEvents, bareosUnRegisterEvents, - bareosGetInstanceCount, bareosGetValue, - bareosSetValue, bareosJobMsg, - bareosDebugMsg, bareosEditDeviceCodes, - bareosLookupCryptoKey, bareosUpdateVolumeInfo, - bareosUpdateTapeAlert, bareosNewRecord, - bareosCopyRecordState, bareosFreeRecord}; +static StorageDaemonCoreFunctions bareos_core_functions = { + sizeof(StorageDaemonCoreFunctions), + SD_PLUGIN_INTERFACE_VERSION, + bareosRegisterEvents, + bareosUnRegisterEvents, + bareosGetInstanceCount, + bareosGetValue, + bareosSetValue, + bareosJobMsg, + bareosDebugMsg, + bareosEditDeviceCodes, + bareosLookupCryptoKey, + bareosUpdateVolumeInfo, + bareosUpdateTapeAlert, + bareosNewRecord, + bareosCopyRecordState, + bareosFreeRecord}; /** * Bareos private context @@ -108,7 +116,7 @@ struct b_plugin_ctx { Plugin* plugin; /* pointer to plugin of which this is an instance off */ }; -static inline bool IsEventEnabled(PluginContext* ctx, bsdEventType eventType) +static inline bool IsEventEnabled(PluginContext* ctx, bSdEventType eventType) { b_plugin_ctx* b_ctx; if (!ctx) { return false; } @@ -238,8 +246,8 @@ char* edit_device_codes(DeviceControlRecord* dcr, } static inline bool trigger_plugin_event(JobControlRecord* jcr, - bsdEventType eventType, - bsdEvent* event, + bSdEventType eventType, + bSdEvent* event, PluginContext* ctx, void* value, alist* plugin_ctx_list, @@ -308,12 +316,12 @@ static inline bool trigger_plugin_event(JobControlRecord* jcr, * Create a plugin event */ bRC GeneratePluginEvent(JobControlRecord* jcr, - bsdEventType eventType, + bSdEventType eventType, void* value, bool reverse) { int i; - bsdEvent event; + bSdEvent event; alist* plugin_ctx_list; bRC rc = bRC_OK; @@ -520,7 +528,7 @@ static inline PluginContext* instantiate_plugin(JobControlRecord* jcr, } /** - * Send a bsdEventNewPluginOptions event to all plugins configured in + * Send a bSdEventNewPluginOptions event to all plugins configured in * jcr->impl_->plugin_options. */ void DispatchNewPluginOptions(JobControlRecord* jcr) @@ -529,8 +537,8 @@ void DispatchNewPluginOptions(JobControlRecord* jcr) Plugin* plugin; PluginContext* ctx = nullptr; uint32_t instance; - bsdEvent event; - bsdEventType eventType; + bSdEvent event; + bSdEventType eventType; char *bp, *plugin_name, *option; const char* plugin_options; PoolMem priv_plugin_options(PM_MESSAGE); @@ -538,7 +546,7 @@ void DispatchNewPluginOptions(JobControlRecord* jcr) if (!sd_plugin_list || sd_plugin_list->empty()) { return; } if (jcr->impl->plugin_options && jcr->impl->plugin_options->size()) { - eventType = bsdEventNewPluginOptions; + eventType = bSdEventNewPluginOptions; event.eventType = eventType; foreach_alist_index (i, plugin_options, jcr->impl->plugin_options) { diff --git a/core/src/stored/sd_plugins.h b/core/src/stored/sd_plugins.h index e702de41e0c..432163b7b9c 100644 --- a/core/src/stored/sd_plugins.h +++ b/core/src/stored/sd_plugins.h @@ -96,42 +96,42 @@ typedef enum */ typedef enum { - bsdEventJobStart = 1, - bsdEventJobEnd = 2, - bsdEventDeviceInit = 3, - bsdEventDeviceMount = 4, - bsdEventVolumeLoad = 5, - bsdEventDeviceReserve = 6, - bsdEventDeviceOpen = 7, - bsdEventLabelRead = 8, - bsdEventLabelVerified = 9, - bsdEventLabelWrite = 10, - bsdEventDeviceClose = 11, - bsdEventVolumeUnload = 12, - bsdEventDeviceUnmount = 13, - bsdEventReadError = 14, - bsdEventWriteError = 15, - bsdEventDriveStatus = 16, - bsdEventVolumeStatus = 17, - bsdEventSetupRecordTranslation = 18, - bsdEventReadRecordTranslation = 19, - bsdEventWriteRecordTranslation = 20, - bsdEventDeviceRelease = 21, - bsdEventNewPluginOptions = 22, - bsdEventChangerLock = 23, - bsdEventChangerUnlock = 24 -} bsdEventType; - -#define SD_NR_EVENTS bsdEventChangerUnlock /**< keep this updated ! */ - -typedef struct s_bsdEvent { + bSdEventJobStart = 1, + bSdEventJobEnd = 2, + bSdEventDeviceInit = 3, + bSdEventDeviceMount = 4, + bSdEventVolumeLoad = 5, + bSdEventDeviceReserve = 6, + bSdEventDeviceOpen = 7, + bSdEventLabelRead = 8, + bSdEventLabelVerified = 9, + bSdEventLabelWrite = 10, + bSdEventDeviceClose = 11, + bSdEventVolumeUnload = 12, + bSdEventDeviceUnmount = 13, + bSdEventReadError = 14, + bSdEventWriteError = 15, + bSdEventDriveStatus = 16, + bSdEventVolumeStatus = 17, + bSdEventSetupRecordTranslation = 18, + bSdEventReadRecordTranslation = 19, + bSdEventWriteRecordTranslation = 20, + bSdEventDeviceRelease = 21, + bSdEventNewPluginOptions = 22, + bSdEventChangerLock = 23, + bSdEventChangerUnlock = 24 +} bSdEventType; + +#define SD_NR_EVENTS bSdEventChangerUnlock /**< keep this updated ! */ + +typedef struct s_bSdEvent { uint32_t eventType; -} bsdEvent; +} bSdEvent; typedef struct s_sdbareosInfo { uint32_t size; uint32_t version; -} bsdInfo; +} Sd_PluginApiDefinition; #ifdef __cplusplus extern "C" { @@ -174,7 +174,7 @@ typedef struct s_sdbareosFuncs { DeviceRecord* (*new_record)(bool with_data); void (*CopyRecordState)(DeviceRecord* dst, DeviceRecord* src); void (*FreeRecord)(DeviceRecord* rec); -} bsdFuncs; +} StorageDaemonCoreFunctions; /* * Bareos Core Routines -- not used within a plugin @@ -187,7 +187,7 @@ void DispatchNewPluginOptions(JobControlRecord* jcr); void NewPlugins(JobControlRecord* jcr); void FreePlugins(JobControlRecord* jcr); bRC GeneratePluginEvent(JobControlRecord* jcr, - bsdEventType event, + bSdEventType event, void* value = NULL, bool reverse = false); #endif @@ -215,10 +215,10 @@ typedef struct s_sdpluginFuncs { bRC (*freePlugin)(PluginContext* ctx); bRC (*getPluginValue)(PluginContext* ctx, pVariable var, void* value); bRC (*setPluginValue)(PluginContext* ctx, pVariable var, void* value); - bRC (*handlePluginEvent)(PluginContext* ctx, bsdEvent* event, void* value); -} psdFuncs; + bRC (*handlePluginEvent)(PluginContext* ctx, bSdEvent* event, void* value); +} pSdFuncs; -#define SdplugFunc(plugin) ((psdFuncs*)(plugin->plugin_functions)) +#define SdplugFunc(plugin) ((pSdFuncs*)(plugin->plugin_functions)) #define sdplug_info(plugin) ((PluginInformation*)(plugin->plugin_information)) #ifdef __cplusplus diff --git a/core/src/stored/status.cc b/core/src/stored/status.cc index f63fbb72278..f4a54088ca6 100644 --- a/core/src/stored/status.cc +++ b/core/src/stored/status.cc @@ -192,7 +192,7 @@ static bool NeedToListDevice(const char* devicenames, static void trigger_device_status_hook(JobControlRecord* jcr, DeviceResource* device_resource, StatusPacket* sp, - bsdEventType eventType) + bSdEventType eventType) { DeviceStatusInformation dst; diff --git a/core/src/stored/stored.cc b/core/src/stored/stored.cc index f81906aa626..b343f1e88a4 100644 --- a/core/src/stored/stored.cc +++ b/core/src/stored/stored.cc @@ -578,7 +578,7 @@ extern "C" void* device_initialization(void* arg) jcr->impl->dcr = dcr; SetupNewDcrDevice(jcr, dcr, dev, NULL); jcr->impl->dcr->SetWillWrite(); - GeneratePluginEvent(jcr, bsdEventDeviceInit, dcr); + GeneratePluginEvent(jcr, bSdEventDeviceInit, dcr); if (dev->IsAutochanger()) { /* * If autochanger set slot in dev structure diff --git a/core/src/tests/test_sd_plugins.cc b/core/src/tests/test_sd_plugins.cc index a1d8647e342..dbd38b0da63 100644 --- a/core/src/tests/test_sd_plugins.cc +++ b/core/src/tests/test_sd_plugins.cc @@ -3,7 +3,7 @@ Copyright (C) 2007-2011 Free Software Foundation Europe e.V. Copyright (C) 2011-2012 Planets Communications B.V. - Copyright (C) 2013-2019 Bareos GmbH & Co. KG + Copyright (C) 2013-2020 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -62,13 +62,13 @@ TEST(sd, sd_plugins) jcr2->JobId = 222; NewPlugins(jcr2); - EXPECT_EQ(GeneratePluginEvent(jcr1, bsdEventJobStart, (void*)"Start Job 1"), + EXPECT_EQ(GeneratePluginEvent(jcr1, bSdEventJobStart, (void*)"Start Job 1"), bRC_OK); - EXPECT_EQ(GeneratePluginEvent(jcr1, bsdEventJobEnd), bRC_OK); - EXPECT_EQ(GeneratePluginEvent(jcr2, bsdEventJobStart, (void*)"Start Job 1"), + EXPECT_EQ(GeneratePluginEvent(jcr1, bSdEventJobEnd), bRC_OK); + EXPECT_EQ(GeneratePluginEvent(jcr2, bSdEventJobStart, (void*)"Start Job 1"), bRC_OK); FreePlugins(jcr1); - EXPECT_EQ(GeneratePluginEvent(jcr2, bsdEventJobEnd), bRC_OK); + EXPECT_EQ(GeneratePluginEvent(jcr2, bSdEventJobEnd), bRC_OK); FreePlugins(jcr2); UnloadSdPlugins(); diff --git a/core/src/tools/bpluginfo.cc b/core/src/tools/bpluginfo.cc index 0d79ac4be79..9d2f3d7e92b 100644 --- a/core/src/tools/bpluginfo.cc +++ b/core/src/tools/bpluginfo.cc @@ -72,7 +72,7 @@ typedef union _plugfuncs plugfuncs; union _plugfuncs { directordaemon::pDirFuncs pdirfuncs; filedaemon::pFuncs pfdfuncs; - storagedaemon::psdFuncs psdfuncs; + storagedaemon::pSdFuncs psdfuncs; }; /* @@ -107,13 +107,13 @@ struct _bareosfuncs { /* * Dir_PluginApiDefiniton * Core_PluginApiDefinition - * bsdInfo + * Sd_PluginApiDefinition */ typedef union _bareosinfos bareosinfos; union _bareosinfos { directordaemon::Dir_PluginApiDefinition bdirinfo; filedaemon::Core_PluginApiDefinition bfdinfo; - storagedaemon::bsdInfo bsdinfo; + storagedaemon::Sd_PluginApiDefinition bsdinfo; }; typedef struct _progdata progdata; From 40171152db78c9fbc2be1c2f8ec3bd97470a1ad1 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 11 May 2020 19:00:36 +0200 Subject: [PATCH 098/341] dir and sd python plugins: working c_api --- core/src/plugins/dird/python/capi_1.inc | 34 ++ core/src/plugins/dird/python/capi_2.inc | 12 + core/src/plugins/dird/python/capi_3.inc | 6 + core/src/plugins/filed/python/python-fd.cc | 2 +- .../stored/autoxflate/autoxflate-sd.cc | 36 +- core/src/plugins/stored/python/bareossd.cc | 403 ++++++++++++++++++ .../stored/python/bareossd_api_funcs.txt | 6 + core/src/plugins/stored/python/capi_1.inc | 34 ++ core/src/plugins/stored/python/capi_2.inc | 12 + core/src/plugins/stored/python/capi_3.inc | 6 + .../stored/scsicrypto/scsicrypto-sd.cc | 52 +-- .../stored/scsitapealert/scsitapealert-sd.cc | 18 +- 12 files changed, 567 insertions(+), 54 deletions(-) create mode 100644 core/src/plugins/dird/python/capi_1.inc create mode 100644 core/src/plugins/dird/python/capi_2.inc create mode 100644 core/src/plugins/dird/python/capi_3.inc create mode 100644 core/src/plugins/stored/python/bareossd_api_funcs.txt create mode 100644 core/src/plugins/stored/python/capi_1.inc create mode 100644 core/src/plugins/stored/python/capi_2.inc create mode 100644 core/src/plugins/stored/python/capi_3.inc diff --git a/core/src/plugins/dird/python/capi_1.inc b/core/src/plugins/dird/python/capi_1.inc new file mode 100644 index 00000000000..3b1be83c9cf --- /dev/null +++ b/core/src/plugins/dird/python/capi_1.inc @@ -0,0 +1,34 @@ +/* C API functions */ + +/* static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); */ +#define Bareosdir_PyParsePluginDefinition_NUM 0 +#define Bareosdir_PyParsePluginDefinition_RETURN bRC +#define Bareosdir_PyParsePluginDefinition_PROTO (PluginContext* plugin_ctx, void* value) + +/* static bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); */ +#define Bareosdir_PyGetPluginValue_NUM 1 +#define Bareosdir_PyGetPluginValue_RETURN bRC +#define Bareosdir_PyGetPluginValue_PROTO (PluginContext* plugin_ctx, pVariable var, void* value) + +/* static bRC PySetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); */ +#define Bareosdir_PySetPluginValue_NUM 2 +#define Bareosdir_PySetPluginValue_RETURN bRC +#define Bareosdir_PySetPluginValue_PROTO (PluginContext* plugin_ctx, pVariable var, void* value) + +/* static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, bDirEvent* event, void* value); */ +#define Bareosdir_PyHandlePluginEvent_NUM 3 +#define Bareosdir_PyHandlePluginEvent_RETURN bRC +#define Bareosdir_PyHandlePluginEvent_PROTO (PluginContext* plugin_ctx, bDirEvent* event, void* value) + +/* static bRC set_bareos_core_functions( DirectorCoreFunctions* new_bareos_core_functions); */ +#define Bareosdir_set_bareos_core_functions_NUM 4 +#define Bareosdir_set_bareos_core_functions_RETURN bRC +#define Bareosdir_set_bareos_core_functions_PROTO ( DirectorCoreFunctions* new_bareos_core_functions) + +/* static bRC set_plugin_context(PluginContext* new_plugin_context); */ +#define Bareosdir_set_plugin_context_NUM 5 +#define Bareosdir_set_plugin_context_RETURN bRC +#define Bareosdir_set_plugin_context_PROTO (PluginContext* new_plugin_context) + +/*Total Number of C API function pointers */ +#define Bareosdir_API_pointers 6 diff --git a/core/src/plugins/dird/python/capi_2.inc b/core/src/plugins/dird/python/capi_2.inc new file mode 100644 index 00000000000..f96c706ff3e --- /dev/null +++ b/core/src/plugins/dird/python/capi_2.inc @@ -0,0 +1,12 @@ +#define Bareosdir_PyParsePluginDefinition (*(Bareosdir_PyParsePluginDefinition_RETURN(*)Bareosdir_PyParsePluginDefinition_PROTO) Bareosdir_API[Bareosdir_PyParsePluginDefinition_NUM]) + +#define Bareosdir_PyGetPluginValue (*(Bareosdir_PyGetPluginValue_RETURN(*)Bareosdir_PyGetPluginValue_PROTO) Bareosdir_API[Bareosdir_PyGetPluginValue_NUM]) + +#define Bareosdir_PySetPluginValue (*(Bareosdir_PySetPluginValue_RETURN(*)Bareosdir_PySetPluginValue_PROTO) Bareosdir_API[Bareosdir_PySetPluginValue_NUM]) + +#define Bareosdir_PyHandlePluginEvent (*(Bareosdir_PyHandlePluginEvent_RETURN(*)Bareosdir_PyHandlePluginEvent_PROTO) Bareosdir_API[Bareosdir_PyHandlePluginEvent_NUM]) + +#define Bareosdir_set_bareos_core_functions (*(Bareosdir_set_bareos_core_functions_RETURN(*)Bareosdir_set_bareos_core_functions_PROTO) Bareosdir_API[Bareosdir_set_bareos_core_functions_NUM]) + +#define Bareosdir_set_plugin_context (*(Bareosdir_set_plugin_context_RETURN(*)Bareosdir_set_plugin_context_PROTO) Bareosdir_API[Bareosdir_set_plugin_context_NUM]) + diff --git a/core/src/plugins/dird/python/capi_3.inc b/core/src/plugins/dird/python/capi_3.inc new file mode 100644 index 00000000000..57ea7e917ad --- /dev/null +++ b/core/src/plugins/dird/python/capi_3.inc @@ -0,0 +1,6 @@ + Bareosdir_API[Bareosdir_PyParsePluginDefinition_NUM] = (void*)PyParsePluginDefinition; + Bareosdir_API[Bareosdir_PyGetPluginValue_NUM] = (void*)PyGetPluginValue; + Bareosdir_API[Bareosdir_PySetPluginValue_NUM] = (void*)PySetPluginValue; + Bareosdir_API[Bareosdir_PyHandlePluginEvent_NUM] = (void*)PyHandlePluginEvent; + Bareosdir_API[Bareosdir_set_bareos_core_functions_NUM] = (void*)set_bareos_core_functions; + Bareosdir_API[Bareosdir_set_plugin_context_NUM] = (void*)set_plugin_context; diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 30892dc8166..7c45efcac3b 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -64,7 +64,7 @@ static bRC setPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); static bRC handlePluginEvent(PluginContext* plugin_ctx, - bSdEvent* event, + bEvent* event, void* value); static bRC startBackupFile(PluginContext* plugin_ctx, struct save_pkt* sp); static bRC endBackupFile(PluginContext* plugin_ctx); diff --git a/core/src/plugins/stored/autoxflate/autoxflate-sd.cc b/core/src/plugins/stored/autoxflate/autoxflate-sd.cc index e477f16c041..1dc83f61d35 100644 --- a/core/src/plugins/stored/autoxflate/autoxflate-sd.cc +++ b/core/src/plugins/stored/autoxflate/autoxflate-sd.cc @@ -70,7 +70,7 @@ static bRC newPlugin(PluginContext* ctx); static bRC freePlugin(PluginContext* ctx); static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value); static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value); -static bRC handlePluginEvent(PluginContext* ctx, bsdEvent* event, void* value); +static bRC handlePluginEvent(PluginContext* ctx, bSdEvent* event, void* value); static bRC handleJobEnd(PluginContext* ctx); static bRC setup_record_translation(PluginContext* ctx, void* value); static bRC handle_read_translation(PluginContext* ctx, void* value); @@ -89,8 +89,8 @@ static bool sd_enabled_compatible = false; /** * Pointers to Bareos functions */ -static bsdFuncs* bareos_core_functions = NULL; -static bsdInfo* bareos_plugin_interface_version = NULL; +static StorageDaemonCoreFunctions* bareos_core_functions = NULL; +static Sd_PluginApiDefinition* bareos_plugin_interface_version = NULL; static PluginInformation pluginInfo = { sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, @@ -99,7 +99,7 @@ static PluginInformation pluginInfo = { PLUGIN_VERSION, PLUGIN_DESCRIPTION, PLUGIN_USAGE}; -static psdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, +static pSdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, /* * Entry points into plugin @@ -135,10 +135,10 @@ extern "C" { * * External entry point called by Bareos to "load the plugin */ -bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, - bsdFuncs* lbareos_core_functions, +bRC loadPlugin(Sd_PluginApiDefinition* lbareos_plugin_interface_version, + StorageDaemonCoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, - psdFuncs** plugin_functions) + pSdFuncs** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ @@ -188,15 +188,15 @@ static bRC newPlugin(PluginContext* ctx) /* * Only register plugin events we are interested in. * - * bsdEventJobEnd - SD Job finished. - * bsdEventSetupRecordTranslation - Setup the buffers for doing record - * translation. bsdEventReadRecordTranslation - Perform read-side record - * translation. bsdEventWriteRecordTranslation - Perform write-side record + * bSdEventJobEnd - SD Job finished. + * bSdEventSetupRecordTranslation - Setup the buffers for doing record + * translation. bSdEventReadRecordTranslation - Perform read-side record + * translation. bSdEventWriteRecordTranslation - Perform write-side record * translantion. */ bareos_core_functions->registerBareosEvents( - ctx, 4, bsdEventJobEnd, bsdEventSetupRecordTranslation, - bsdEventReadRecordTranslation, bsdEventWriteRecordTranslation); + ctx, 4, bSdEventJobEnd, bSdEventSetupRecordTranslation, + bSdEventReadRecordTranslation, bSdEventWriteRecordTranslation); return bRC_OK; } @@ -246,16 +246,16 @@ static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value) /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(PluginContext* ctx, bsdEvent* event, void* value) +static bRC handlePluginEvent(PluginContext* ctx, bSdEvent* event, void* value) { switch (event->eventType) { - case bsdEventSetupRecordTranslation: + case bSdEventSetupRecordTranslation: return setup_record_translation(ctx, value); - case bsdEventReadRecordTranslation: + case bSdEventReadRecordTranslation: return handle_read_translation(ctx, value); - case bsdEventWriteRecordTranslation: + case bSdEventWriteRecordTranslation: return handle_write_translation(ctx, value); - case bsdEventJobEnd: + case bSdEventJobEnd: return handleJobEnd(ctx); default: Dmsg(ctx, debuglevel, "autoxflate-sd: Unknown event %d\n", diff --git a/core/src/plugins/stored/python/bareossd.cc b/core/src/plugins/stored/python/bareossd.cc index d798393bc85..24ba608d544 100644 --- a/core/src/plugins/stored/python/bareossd.cc +++ b/core/src/plugins/stored/python/bareossd.cc @@ -83,5 +83,408 @@ static bRC set_plugin_context(PluginContext* new_plugin_context) return bRC_OK; } +/** + * Any plugin options which are passed in are dispatched here to a Python method + * and it can parse the plugin options. This function is also called after + * PyLoadModule() has loaded the Python module and made sure things are + * operational. + */ +static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value) +{ + bRC retval = bRC_Error; + struct plugin_private_context* plugin_priv_ctx = + (struct plugin_private_context*)plugin_ctx->plugin_private_context; + PyObject* pFunc; + + /* + * Lookup the parse_plugin_definition() function in the python module. + */ + pFunc = + PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "parse_plugin_definition"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyObject *pPluginDefinition, *pRetVal; + + pPluginDefinition = PyString_FromString((char*)value); + if (!pPluginDefinition) { goto bail_out; } + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); + Py_DECREF(pPluginDefinition); + + if (!pRetVal) { + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + } + + return retval; + } else { + Dmsg( + plugin_ctx, debuglevel, + "python-sd: Failed to find function named parse_plugin_definition()\n"); + return bRC_Error; + } + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } + + return retval; +} + +static bRC PyGetPluginValue(PluginContext* plugin_ctx, + pVariable var, + void* value) +{ + return bRC_OK; +} + +static bRC PySetPluginValue(PluginContext* plugin_ctx, + pVariable var, + void* value) +{ + return bRC_OK; +} + +static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, + bSdEvent* event, + void* value) +{ + bRC retval = bRC_Error; + plugin_private_context* plugin_priv_ctx = + (plugin_private_context*)plugin_ctx->plugin_private_context; + PyObject* pFunc; + + /* + * Lookup the handle_plugin_event() function in the python module. + */ + pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, + "handle_plugin_event"); /* Borrowed reference */ + if (pFunc && PyCallable_Check(pFunc)) { + PyObject *pEventType, *pRetVal; + + pEventType = PyInt_FromLong(event->eventType); + + pRetVal = PyObject_CallFunctionObjArgs(pFunc, pEventType, NULL); + Py_DECREF(pEventType); + + if (!pRetVal) { + goto bail_out; + } else { + retval = ConvertPythonRetvalTobRCRetval(pRetVal); + Py_DECREF(pRetVal); + } + } else { + Dmsg(plugin_ctx, debuglevel, + "python-sd: Failed to find function named handle_plugin_event()\n"); + } + + return retval; + +bail_out: + if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } + + return retval; +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to get certain internal values of the current Job. + */ +static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) +{ + int var; + PluginContext* plugin_ctx = plugin_context; + PyObject* pRetVal = NULL; + + if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + switch (var) { + case bsdVarJobId: + case bsdVarLevel: + case bsdVarType: + case bsdVarJobStatus: { + int value; + + if (bareos_core_functions->getBareosValue(plugin_ctx, (bsdrVariable)var, + &value) == bRC_OK) { + pRetVal = PyInt_FromLong(value); + } + break; + } + case bsdVarJobErrors: + case bsdVarJobFiles: + case bsdVarJobBytes: { + uint64_t value = 0; + + if (bareos_core_functions->getBareosValue(plugin_ctx, (bsdrVariable)var, + &value) == bRC_OK) { + pRetVal = PyLong_FromUnsignedLong(value); + } + break; + } + case bsdVarJobName: + case bsdVarJob: + case bsdVarClient: + case bsdVarPool: + case bsdVarPoolType: + case bsdVarStorage: + case bsdVarMediaType: + case bsdVarVolumeName: { + char* value = NULL; + + if (bareos_core_functions->getBareosValue(plugin_ctx, (bsdrVariable)var, + &value) == bRC_OK) { + if (value) { pRetVal = PyString_FromString(value); } + } + break; + } + case bsdVarCompatible: { + bool value; + + if (bareos_core_functions->getBareosValue(NULL, (bsdrVariable)var, + &value) == bRC_OK) { + long bool_value; + + bool_value = (value) ? 1 : 0; + pRetVal = PyBool_FromLong(bool_value); + } + break; + } + case bsdVarPluginDir: { + char* value = NULL; + + if (bareos_core_functions->getBareosValue(NULL, (bsdrVariable)var, + &value) == bRC_OK) { + if (value) { pRetVal = PyString_FromString(value); } + } + break; + } + default: + Dmsg(plugin_ctx, debuglevel, + "python-sd: PyBareosGetValue unknown variable requested %d\n", var); + break; + } + + if (!pRetVal) { + Py_INCREF(Py_None); + pRetVal = Py_None; + } + + return pRetVal; +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to get certain internal values of the current Job. + */ +static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) +{ + int var; + PluginContext* plugin_ctx = plugin_context; + bRC retval = bRC_Error; + PyObject* pyValue; + + if (!PyArg_ParseTuple(args, "iO:BareosSetValue", &var, &pyValue)) { + goto bail_out; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + switch (var) { + case bsdwVarVolumeName: { + char* value; + + value = PyString_AsString(pyValue); + if (value) { + bareos_core_functions->setBareosValue(plugin_ctx, (bsdwVariable)var, + value); + } + + break; + } + case bsdwVarPriority: + case bsdwVarJobLevel: { + int value; + + value = PyInt_AsLong(pyValue); + if (value >= 0) { + retval = bareos_core_functions->setBareosValue( + plugin_ctx, (bsdwVariable)var, &value); + } + break; + } + default: + Dmsg(plugin_ctx, debuglevel, + "python-sd: PyBareosSetValue unknown variable requested %d\n", var); + break; + } + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to issue debug messages using the Bareos debug message + * facility. + */ +static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) +{ + int level; + char* dbgmsg = NULL; + PluginContext* plugin_ctx = plugin_context; + + if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { + return NULL; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + if (dbgmsg) { Dmsg(plugin_ctx, level, "python-sd: %s", dbgmsg); } + + Py_INCREF(Py_None); + return Py_None; +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to issue Job messages using the Bareos Job message + * facility. + */ +static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) +{ + int type; + char* jobmsg = NULL; + PluginContext* plugin_ctx = plugin_context; + + if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { + return NULL; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + if (jobmsg) { Jmsg(plugin_ctx, type, "python-sd: %s", jobmsg); } + + Py_INCREF(Py_None); + return Py_None; +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to issue a Register Event to register additional events + * it wants to receive. + */ +static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) +{ + int len, event; + PluginContext* plugin_ctx = plugin_context; + bRC retval = bRC_Error; + PyObject *pyEvents, *pySeq, *pyEvent; + + if (!PyArg_ParseTuple(args, "O:BareosRegisterEvents", &pyEvents)) { + goto bail_out; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); + if (!pySeq) { goto bail_out; } + + len = PySequence_Fast_GET_SIZE(pySeq); + + for (int i = 0; i < len; i++) { + pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); + event = PyInt_AsLong(pyEvent); + + if (event >= bSdEventJobStart && event <= bSdEventWriteRecordTranslation) { + Dmsg(plugin_ctx, debuglevel, + "python-sd: PyBareosRegisterEvents registering event %d\n", event); + retval = + bareos_core_functions->registerBareosEvents(plugin_ctx, 1, event); + + if (retval != bRC_OK) { break; } + } + } + + Py_DECREF(pySeq); + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to issue an Unregister Event to unregister events it + * doesn't want to receive anymore. + */ +static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) +{ + int len, event; + PluginContext* plugin_ctx = plugin_context; + bRC retval = bRC_Error; + PyObject *pyEvents, *pySeq, *pyEvent; + + if (!PyArg_ParseTuple(args, "O:BareosUnRegisterEvents", &pyEvents)) { + goto bail_out; + } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); + if (!pySeq) { goto bail_out; } + + len = PySequence_Fast_GET_SIZE(pySeq); + + for (int i = 0; i < len; i++) { + pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); + event = PyInt_AsLong(pyEvent); + + if (event >= bSdEventJobStart && event <= bSdEventWriteRecordTranslation) { + Dmsg(plugin_ctx, debuglevel, + "PyBareosUnRegisterEvents: registering event %d\n", event); + retval = + bareos_core_functions->unregisterBareosEvents(plugin_ctx, 1, event); + + if (retval != bRC_OK) { break; } + } + } + + Py_DECREF(pySeq); + +bail_out: + return ConvertbRCRetvalToPythonRetval(retval); +} + +/** + * Callback function which is exposed as a part of the additional methods which + * allow a Python plugin to issue a GetInstanceCount to retrieve the number of + * instances of the current plugin being loaded into the daemon. + */ +static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) +{ + int value; + PluginContext* plugin_ctx = plugin_context; + PyObject* pRetVal = NULL; + + if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } + RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() + + if (!plugin_ctx) { + PyErr_SetString(PyExc_ValueError, "plugin_ctx is unset"); + return NULL; + } + if (!bareos_core_functions) { + PyErr_SetString(PyExc_ValueError, "bareos_core_functions is unset"); + return NULL; + } + if (bareos_core_functions->getInstanceCount(plugin_ctx, &value) == bRC_OK) { + pRetVal = PyInt_FromLong(value); + } + + if (!pRetVal) { + Py_INCREF(Py_None); + pRetVal = Py_None; + } + + return pRetVal; +} + } /* namespace storagedaemon*/ diff --git a/core/src/plugins/stored/python/bareossd_api_funcs.txt b/core/src/plugins/stored/python/bareossd_api_funcs.txt new file mode 100644 index 00000000000..c5e46c93b35 --- /dev/null +++ b/core/src/plugins/stored/python/bareossd_api_funcs.txt @@ -0,0 +1,6 @@ +bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); +bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); +bRC PySetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); +bRC PyHandlePluginEvent(PluginContext* plugin_ctx, bSdEvent* event, void* value); +bRC set_bareos_core_functions( StorageDaemonCoreFunctions* new_bareos_core_functions); +bRC set_plugin_context(PluginContext* new_plugin_context); diff --git a/core/src/plugins/stored/python/capi_1.inc b/core/src/plugins/stored/python/capi_1.inc new file mode 100644 index 00000000000..a0ec08e0a5a --- /dev/null +++ b/core/src/plugins/stored/python/capi_1.inc @@ -0,0 +1,34 @@ +/* C API functions */ + +/* static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); */ +#define Bareossd_PyParsePluginDefinition_NUM 0 +#define Bareossd_PyParsePluginDefinition_RETURN bRC +#define Bareossd_PyParsePluginDefinition_PROTO (PluginContext* plugin_ctx, void* value) + +/* static bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); */ +#define Bareossd_PyGetPluginValue_NUM 1 +#define Bareossd_PyGetPluginValue_RETURN bRC +#define Bareossd_PyGetPluginValue_PROTO (PluginContext* plugin_ctx, pVariable var, void* value) + +/* static bRC PySetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); */ +#define Bareossd_PySetPluginValue_NUM 2 +#define Bareossd_PySetPluginValue_RETURN bRC +#define Bareossd_PySetPluginValue_PROTO (PluginContext* plugin_ctx, pVariable var, void* value) + +/* static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, bSdEvent* event, void* value); */ +#define Bareossd_PyHandlePluginEvent_NUM 3 +#define Bareossd_PyHandlePluginEvent_RETURN bRC +#define Bareossd_PyHandlePluginEvent_PROTO (PluginContext* plugin_ctx, bSdEvent* event, void* value) + +/* static bRC set_bareos_core_functions( StorageDaemonCoreFunctions* new_bareos_core_functions); */ +#define Bareossd_set_bareos_core_functions_NUM 4 +#define Bareossd_set_bareos_core_functions_RETURN bRC +#define Bareossd_set_bareos_core_functions_PROTO ( StorageDaemonCoreFunctions* new_bareos_core_functions) + +/* static bRC set_plugin_context(PluginContext* new_plugin_context); */ +#define Bareossd_set_plugin_context_NUM 5 +#define Bareossd_set_plugin_context_RETURN bRC +#define Bareossd_set_plugin_context_PROTO (PluginContext* new_plugin_context) + +/*Total Number of C API function pointers */ +#define Bareossd_API_pointers 6 diff --git a/core/src/plugins/stored/python/capi_2.inc b/core/src/plugins/stored/python/capi_2.inc new file mode 100644 index 00000000000..aa1c731c505 --- /dev/null +++ b/core/src/plugins/stored/python/capi_2.inc @@ -0,0 +1,12 @@ +#define Bareossd_PyParsePluginDefinition (*(Bareossd_PyParsePluginDefinition_RETURN(*)Bareossd_PyParsePluginDefinition_PROTO) Bareossd_API[Bareossd_PyParsePluginDefinition_NUM]) + +#define Bareossd_PyGetPluginValue (*(Bareossd_PyGetPluginValue_RETURN(*)Bareossd_PyGetPluginValue_PROTO) Bareossd_API[Bareossd_PyGetPluginValue_NUM]) + +#define Bareossd_PySetPluginValue (*(Bareossd_PySetPluginValue_RETURN(*)Bareossd_PySetPluginValue_PROTO) Bareossd_API[Bareossd_PySetPluginValue_NUM]) + +#define Bareossd_PyHandlePluginEvent (*(Bareossd_PyHandlePluginEvent_RETURN(*)Bareossd_PyHandlePluginEvent_PROTO) Bareossd_API[Bareossd_PyHandlePluginEvent_NUM]) + +#define Bareossd_set_bareos_core_functions (*(Bareossd_set_bareos_core_functions_RETURN(*)Bareossd_set_bareos_core_functions_PROTO) Bareossd_API[Bareossd_set_bareos_core_functions_NUM]) + +#define Bareossd_set_plugin_context (*(Bareossd_set_plugin_context_RETURN(*)Bareossd_set_plugin_context_PROTO) Bareossd_API[Bareossd_set_plugin_context_NUM]) + diff --git a/core/src/plugins/stored/python/capi_3.inc b/core/src/plugins/stored/python/capi_3.inc new file mode 100644 index 00000000000..f6da5a9a11a --- /dev/null +++ b/core/src/plugins/stored/python/capi_3.inc @@ -0,0 +1,6 @@ + Bareossd_API[Bareossd_PyParsePluginDefinition_NUM] = (void*)PyParsePluginDefinition; + Bareossd_API[Bareossd_PyGetPluginValue_NUM] = (void*)PyGetPluginValue; + Bareossd_API[Bareossd_PySetPluginValue_NUM] = (void*)PySetPluginValue; + Bareossd_API[Bareossd_PyHandlePluginEvent_NUM] = (void*)PyHandlePluginEvent; + Bareossd_API[Bareossd_set_bareos_core_functions_NUM] = (void*)set_bareos_core_functions; + Bareossd_API[Bareossd_set_plugin_context_NUM] = (void*)set_plugin_context; diff --git a/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc b/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc index e4104bfd5ca..91ede058a3e 100644 --- a/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc +++ b/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc @@ -84,7 +84,7 @@ static bRC newPlugin(PluginContext* ctx); static bRC freePlugin(PluginContext* ctx); static bRC getPluginValue(PluginContext* ctx, pVariable var, void* value); static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value); -static bRC handlePluginEvent(PluginContext* ctx, bsdEvent* event, void* value); +static bRC handlePluginEvent(PluginContext* ctx, bSdEvent* event, void* value); static bRC do_set_scsi_encryption_key(void* value); static bRC do_clear_scsi_encryption_key(void* value); static bRC handle_read_error(void* value); @@ -94,8 +94,8 @@ static bRC send_volume_encryption_status(void* value); /** * Pointers to Bareos functions */ -static bsdFuncs* bareos_core_functions = NULL; -static bsdInfo* bareos_plugin_interface_version = NULL; +static StorageDaemonCoreFunctions* bareos_core_functions = NULL; +static Sd_PluginApiDefinition* bareos_plugin_interface_version = NULL; static PluginInformation pluginInfo = { sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, @@ -104,7 +104,7 @@ static PluginInformation pluginInfo = { PLUGIN_VERSION, PLUGIN_DESCRIPTION, PLUGIN_USAGE}; -static psdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, +static pSdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, /* * Entry points into plugin @@ -127,10 +127,10 @@ extern "C" { * * External entry point called by Bareos to "load the plugin */ -bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, - bsdFuncs* lbareos_core_functions, +bRC loadPlugin(Sd_PluginApiDefinition* lbareos_plugin_interface_version, + StorageDaemonCoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, - psdFuncs** plugin_functions) + pSdFuncs** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ @@ -169,34 +169,34 @@ static bRC newPlugin(PluginContext* ctx) /* * Only register plugin events we are interested in. * - * bsdEventLabelRead - Read of volume label clear key as volume + * bSdEventLabelRead - Read of volume label clear key as volume * labels are unencrypted (as we are in mixed * decryption mode we could leave the current * encryption key but most likely its the key * from an previous volume and most of the times * it will be cleared already by the - * bsdEventVolumeUnload event already.) - * bsdEventLabelVerified - Label of volume is verified and found + * bSdEventVolumeUnload event already.) + * bSdEventLabelVerified - Label of volume is verified and found * to be OK, any next data read from the * volume will be backup data and most * likely encrypted so load the volume * specific encryption key. - * bsdEventLabelWrite - Write of volume label clear key as volume + * bSdEventLabelWrite - Write of volume label clear key as volume * labels are unencrypted. - * bsdEventVolumeUnload - Unload of volume clear key - * bsdEventReadError - Read error on volume see if its due to + * bSdEventVolumeUnload - Unload of volume clear key + * bSdEventReadError - Read error on volume see if its due to * the fact encryption is enabled and we * have either the wrong key loaded or no key * at all. - * bsdEventDriveStatus - plugin callback for encryption status + * bSdEventDriveStatus - plugin callback for encryption status * of the drive. - * bsdEventVolumeStatus - plugin callback for encryption status + * bSdEventVolumeStatus - plugin callback for encryption status * of the volume loaded in the drive. */ bareos_core_functions->registerBareosEvents( - ctx, 7, bsdEventLabelRead, bsdEventLabelVerified, bsdEventLabelWrite, - bsdEventVolumeUnload, bsdEventReadError, bsdEventDriveStatus, - bsdEventVolumeStatus); + ctx, 7, bSdEventLabelRead, bSdEventLabelVerified, bSdEventLabelWrite, + bSdEventVolumeUnload, bSdEventReadError, bSdEventDriveStatus, + bSdEventVolumeStatus); return bRC_OK; } @@ -237,20 +237,20 @@ static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value) /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(PluginContext* ctx, bsdEvent* event, void* value) +static bRC handlePluginEvent(PluginContext* ctx, bSdEvent* event, void* value) { switch (event->eventType) { - case bsdEventLabelRead: - case bsdEventLabelWrite: - case bsdEventVolumeUnload: + case bSdEventLabelRead: + case bSdEventLabelWrite: + case bSdEventVolumeUnload: return do_clear_scsi_encryption_key(value); - case bsdEventLabelVerified: + case bSdEventLabelVerified: return do_set_scsi_encryption_key(value); - case bsdEventReadError: + case bSdEventReadError: return handle_read_error(value); - case bsdEventDriveStatus: + case bSdEventDriveStatus: return send_device_encryption_status(value); - case bsdEventVolumeStatus: + case bSdEventVolumeStatus: return send_volume_encryption_status(value); default: Dmsg1(debuglevel, "scsicrypto-sd: Unknown event %d\n", event->eventType); diff --git a/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc b/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc index 0b34080bddc..ccd443b320d 100644 --- a/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc +++ b/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc @@ -54,7 +54,7 @@ static bRC handle_tapealert_readout(void* value); * Pointers to Bareos functions */ static StorageDaemonCoreFunctions* bareos_core_functions = NULL; -static bsdInfo* bareos_plugin_interface_version = NULL; +static Sd_PluginApiDefinition* bareos_plugin_interface_version = NULL; static PluginInformation pluginInfo = { sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, @@ -86,7 +86,7 @@ extern "C" { * * External entry point called by Bareos to "load the plugin */ -bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, +bRC loadPlugin(Sd_PluginApiDefinition* lbareos_plugin_interface_version, StorageDaemonCoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, pSdFuncs** plugin_functions) @@ -129,8 +129,8 @@ static bRC newPlugin(PluginContext* ctx) * Only register plugin events we are interested in. */ bareos_core_functions->registerBareosEvents( - ctx, 6, bsdEventVolumeLoad, bsdEventLabelVerified, bsdEventReadError, - bsdEventWriteError, bsdEventVolumeUnload, bsdEventDeviceRelease); + ctx, 6, bSdEventVolumeLoad, bSdEventLabelVerified, bSdEventReadError, + bSdEventWriteError, bSdEventVolumeUnload, bSdEventDeviceRelease); return bRC_OK; } @@ -171,13 +171,13 @@ static bRC setPluginValue(PluginContext* ctx, pVariable var, void* value) /** * Handle an event that was generated in Bareos */ -static bRC handlePluginEvent(PluginContext* ctx, bsdEvent* event, void* value) +static bRC handlePluginEvent(PluginContext* ctx, bSdEvent* event, void* value) { switch (event->eventType) { - case bsdEventLabelVerified: - case bsdEventReadError: - case bsdEventWriteError: - case bsdEventVolumeUnload: + case bSdEventLabelVerified: + case bSdEventReadError: + case bSdEventWriteError: + case bSdEventVolumeUnload: return handle_tapealert_readout(value); default: Dmsg1(debuglevel, "scsitapealert-sd: Unknown event %d\n", From 7cf4c44c6003b67a527670dd35f4658432baec5c Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 11 May 2020 19:08:17 +0200 Subject: [PATCH 099/341] cmake: unify python build parts --- core/src/plugins/dird/CMakeLists.txt | 3 ++- core/src/plugins/filed/CMakeLists.txt | 2 +- core/src/plugins/stored/CMakeLists.txt | 17 +++++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index 076c00a7a01..28e808d1de2 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -54,12 +54,13 @@ if(HAVE_PYTHON AND NOT HAVE_WIN32) OUTPUT pythonmodules/bareosdir.so MAIN_DEPENDENCY ./python/bareosdir.cc DEPENDS ./python/bareosdir.h + DEPENDS bareos DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py + COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${PYTHON_EXECUTABLE} python/setup.py build COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build - # COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build DEPENDS python-dir COMMENT "building python module pythonmodules/bareosdir.so" ) diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index 286c74b739a..6a7d5804c9d 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -136,7 +136,7 @@ if(HAVE_PYTHON AND NOT HAVE_WIN32) COMMAND ${PYTHON_EXECUTABLE} python/setup.py build COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build + COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python module pythonmodules/bareosfd.so" ) diff --git a/core/src/plugins/stored/CMakeLists.txt b/core/src/plugins/stored/CMakeLists.txt index c14108ae43b..02dfaef1886 100644 --- a/core/src/plugins/stored/CMakeLists.txt +++ b/core/src/plugins/stored/CMakeLists.txt @@ -58,8 +58,7 @@ if(HAVE_PYTHON) set(PYFILES python/pyfiles/bareos-sd-class-plugin.py python/pyfiles/BareosSdPluginBaseclass.py - python/pyfiles/bareos-sd.py.template - python/pyfiles/BareosSdWrapper.py + python/pyfiles/bareos-sd.py.template python/pyfiles/BareosSdWrapper.py ) install(FILES ${PYFILES} DESTINATION ${plugindir}) @@ -68,15 +67,21 @@ endif() if(HAVE_PYTHON AND NOT HAVE_WIN32) configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) add_custom_command( - TARGET python-sd - POST_BUILD - COMMENT "building python module pythonmodules/bareossd.so" + OUTPUT pythonmodules/bareossd.so + MAIN_DEPENDENCY ./python/bareossd.cc + DEPENDS ./python/bareossd.h + DEPENDS bareos + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py + COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${PYTHON_EXECUTABLE} python/setup.py build COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - COMMAND rm -R ${CMAKE_CURRENT_BINARY_DIR}/build DEPENDS python-sd + COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build + COMMENT "building python module pythonmodules/bareossd.so" ) + add_custom_target(bareossd-pymod DEPENDS pythonmodules/bareossd.so) + add_test(NAME bareossd-python-module COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareossd_test.py From 0eacb47d3f5faeae8956f96e96f1aea7a281d850 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 11 May 2020 19:13:30 +0200 Subject: [PATCH 100/341] cmake: fix bareossd python module dependency --- core/src/plugins/stored/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/plugins/stored/CMakeLists.txt b/core/src/plugins/stored/CMakeLists.txt index 02dfaef1886..e8196cf5a2c 100644 --- a/core/src/plugins/stored/CMakeLists.txt +++ b/core/src/plugins/stored/CMakeLists.txt @@ -53,7 +53,7 @@ if(HAVE_PYTHON) set_target_properties(python-sd PROPERTIES PREFIX "") install(TARGETS python-sd DESTINATION ${plugindir}) target_link_libraries(python-sd ${PYTHON_LIBRARIES} bareos) - add_dependencies(python-sd bareossd) + add_dependencies(python-sd bareossd-pymod) set(PYFILES python/pyfiles/bareos-sd-class-plugin.py From 9817f5a5d589a902b2d5be244f8e87276a1c5c2d Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 12 May 2020 12:41:09 +0200 Subject: [PATCH 101/341] systemtests: fix python-dir-plugin-test PYTHONPATH --- systemtests/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 9fef5df6788..594b40cc203 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -800,6 +800,7 @@ foreach(TEST_NAME ${SYSTEM_TESTS}) "${CMAKE_BINARY_DIR}/core/src/plugins/filed/pythonmodules:" "${CMAKE_BINARY_DIR}/core/src/plugins/stored/pythonmodules:" "${CMAKE_SOURCE_DIR}/core/src/plugins/dird/pythonmodules:" + "${CMAKE_BINARY_DIR}/core/src/plugins/dird/pythonmodules:" "${CMAKE_CURRENT_SOURCE_DIR}/tests/${TEST_NAME}/python-modules" ) From 144bd63c617bc4d5a39d29665a17848bc3c1e1eb Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 12 May 2020 13:39:59 +0200 Subject: [PATCH 102/341] plugins api: unified naming with name spaces --- core/src/dird/dir_plugins.cc | 18 +++---- core/src/dird/dir_plugins.h | 8 +-- core/src/filed/fd_plugins.cc | 50 +++++++++---------- core/src/filed/fd_plugins.h | 8 +-- .../dird/example/example-plugin-dir.cc | 4 +- core/src/plugins/dird/python/bareosdir.cc | 8 ++- core/src/plugins/dird/python/bareosdir.h | 16 +++--- .../dird/python/bareosdir_api_funcs.txt | 2 +- core/src/plugins/dird/python/capi_1.inc | 4 +- core/src/plugins/dird/python/python-dir.cc | 12 ++--- core/src/plugins/filed/bpipe/bpipe-fd.cc | 12 ++--- core/src/plugins/filed/cephfs/cephfs-fd.cc | 12 ++--- .../filed/example/example-plugin-fd.cc | 12 ++--- core/src/plugins/filed/gfapi/gfapi-fd.cc | 12 ++--- core/src/plugins/filed/python/bareosfd.cc | 8 ++- core/src/plugins/filed/python/bareosfd.h | 15 +++--- .../filed/python/bareosfd_api_funcs.txt | 2 +- core/src/plugins/filed/python/capi_1.inc | 4 +- core/src/plugins/filed/python/python-fd.cc | 12 ++--- .../filed/python/test/bareosfd_test.py | 4 +- .../python/test/python-fd-module-tester.cc | 8 +-- core/src/plugins/filed/rados/rados-fd.cc | 12 ++--- .../filed/test-deltaseq/test-deltaseq-fd.cc | 12 ++--- .../filed/test-plugin/test-plugin-fd.cc | 12 ++--- .../stored/autoxflate/autoxflate-sd.cc | 26 +++++----- .../stored/example/example-plugin-sd.cc | 14 +++--- core/src/plugins/stored/python/bareossd.cc | 8 ++- core/src/plugins/stored/python/bareossd.h | 15 +++--- .../stored/python/bareossd_api_funcs.txt | 2 +- core/src/plugins/stored/python/capi_1.inc | 4 +- core/src/plugins/stored/python/python-sd.cc | 22 ++++---- .../stored/scsicrypto/scsicrypto-sd.cc | 26 +++++----- .../stored/scsitapealert/scsitapealert-sd.cc | 26 +++++----- core/src/stored/sd_plugins.cc | 30 ++++------- core/src/stored/sd_plugins.h | 8 +-- core/src/tools/bpluginfo.cc | 24 ++++----- core/src/win32/plugins/filed/mssqlvdi-fd.cc | 26 +++++----- .../source/DeveloperGuide/pluginAPI.rst | 28 +++++------ 38 files changed, 249 insertions(+), 277 deletions(-) diff --git a/core/src/dird/dir_plugins.cc b/core/src/dird/dir_plugins.cc index 92f6f3125d0..5dfde681f25 100644 --- a/core/src/dird/dir_plugins.cc +++ b/core/src/dird/dir_plugins.cc @@ -67,19 +67,15 @@ static bRC bareosDebugMsg(PluginContext* ctx, static bool IsPluginCompatible(Plugin* plugin); /* BAREOS info */ -static Dir_PluginApiDefinition bareos_plugin_interface_version = { - sizeof(DirectorCoreFunctions), DIR_PLUGIN_INTERFACE_VERSION}; +static PluginApiDefinition bareos_plugin_interface_version = { + sizeof(CoreFunctions), DIR_PLUGIN_INTERFACE_VERSION}; /* BAREOS entry points */ -static DirectorCoreFunctions bareos_core_functions = { - sizeof(DirectorCoreFunctions), - DIR_PLUGIN_INTERFACE_VERSION, - bareosRegisterEvents, - bareosUnRegisterEvents, - bareosGetInstanceCount, - bareosGetValue, - bareosSetValue, - bareosJobMsg, +static CoreFunctions bareos_core_functions = { + sizeof(CoreFunctions), DIR_PLUGIN_INTERFACE_VERSION, + bareosRegisterEvents, bareosUnRegisterEvents, + bareosGetInstanceCount, bareosGetValue, + bareosSetValue, bareosJobMsg, bareosDebugMsg}; /* diff --git a/core/src/dird/dir_plugins.h b/core/src/dird/dir_plugins.h index 42639ea2aa9..9ee43d86c84 100644 --- a/core/src/dird/dir_plugins.h +++ b/core/src/dird/dir_plugins.h @@ -129,7 +129,7 @@ typedef struct s_bDirEvent { typedef struct s_dirbareosInfo { uint32_t size; uint32_t version; -} Dir_PluginApiDefinition; +} PluginApiDefinition; #ifdef __cplusplus extern "C" { @@ -159,7 +159,7 @@ typedef struct s_dirbareosFuncs { int level, const char* fmt, ...); -} DirectorCoreFunctions; +} CoreFunctions; /** * Bareos Core Routines -- not used within a plugin @@ -197,9 +197,9 @@ typedef struct s_dirpluginFuncs { bRC (*getPluginValue)(PluginContext* ctx, pVariable var, void* value); bRC (*setPluginValue)(PluginContext* ctx, pVariable var, void* value); bRC (*handlePluginEvent)(PluginContext* ctx, bDirEvent* event, void* value); -} pDirFuncs; +} PluginFunctions; -#define DirplugFunc(plugin) ((pDirFuncs*)(plugin->plugin_functions)) +#define DirplugFunc(plugin) ((PluginFunctions*)(plugin->plugin_functions)) #define dirplug_info(plugin) ((PluginInformation*)(plugin->plugin_information)) #ifdef __cplusplus diff --git a/core/src/filed/fd_plugins.cc b/core/src/filed/fd_plugins.cc index ce366ca89c6..a763ce8020f 100644 --- a/core/src/filed/fd_plugins.cc +++ b/core/src/filed/fd_plugins.cc @@ -138,33 +138,33 @@ static boffset_t MyPluginBlseek(BareosWinFilePacket* bfd, int whence); /* Bareos info */ -static Core_PluginApiDefinition bareos_plugin_interface_version = { - sizeof(Core_PluginApiDefinition), FD_PLUGIN_INTERFACE_VERSION}; +static PluginApiDefinition bareos_plugin_interface_version = { + sizeof(PluginApiDefinition), FD_PLUGIN_INTERFACE_VERSION}; /* Bareos entry points */ -static BareosCoreFunctions bareos_core_functions = {sizeof(BareosCoreFunctions), - FD_PLUGIN_INTERFACE_VERSION, - bareosRegisterEvents, - bareosUnRegisterEvents, - bareosGetInstanceCount, - bareosGetValue, - bareosSetValue, - bareosJobMsg, - bareosDebugMsg, - bareosMalloc, - bareosFree, - bareosAddExclude, - bareosAddInclude, - bareosAddOptions, - bareosAddRegex, - bareosAddWild, - bareosNewOptions, - bareosNewInclude, - bareosNewPreInclude, - bareosCheckChanges, - bareosAcceptFile, - bareosSetSeenBitmap, - bareosClearSeenBitmap}; +static CoreFunctions bareos_core_functions = {sizeof(CoreFunctions), + FD_PLUGIN_INTERFACE_VERSION, + bareosRegisterEvents, + bareosUnRegisterEvents, + bareosGetInstanceCount, + bareosGetValue, + bareosSetValue, + bareosJobMsg, + bareosDebugMsg, + bareosMalloc, + bareosFree, + bareosAddExclude, + bareosAddInclude, + bareosAddOptions, + bareosAddRegex, + bareosAddWild, + bareosNewOptions, + bareosNewInclude, + bareosNewPreInclude, + bareosCheckChanges, + bareosAcceptFile, + bareosSetSeenBitmap, + bareosClearSeenBitmap}; /** * Bareos private context diff --git a/core/src/filed/fd_plugins.h b/core/src/filed/fd_plugins.h index 2d785929395..05e3b6837e6 100644 --- a/core/src/filed/fd_plugins.h +++ b/core/src/filed/fd_plugins.h @@ -257,7 +257,7 @@ typedef struct s_bEvent { typedef struct s_bareosInfo { uint32_t size; uint32_t version; -} Core_PluginApiDefinition; +} PluginApiDefinition; /* * Bareos Core Routines -- not used within a plugin @@ -355,7 +355,7 @@ typedef struct s_bareosFuncs { struct save_pkt* sp); /* Need fname and statp */ bRC (*SetSeenBitmap)(PluginContext* ctx, bool all, char* fname); bRC (*ClearSeenBitmap)(PluginContext* ctx, bool all, char* fname); -} BareosCoreFunctions; +} CoreFunctions; /**************************************************************************** * * @@ -395,9 +395,9 @@ typedef struct s_pluginFuncs { bRC (*setAcl)(PluginContext* ctx, struct acl_pkt* ap); bRC (*getXattr)(PluginContext* ctx, struct xattr_pkt* xp); bRC (*setXattr)(PluginContext* ctx, struct xattr_pkt* xp); -} pFuncs; +} PluginFunctions; -#define PlugFunc(plugin) ((pFuncs*)(plugin->plugin_functions)) +#define PlugFunc(plugin) ((PluginFunctions*)(plugin->plugin_functions)) #define plug_info(plugin) ((PluginInformation*)(plugin->plugin_information)) #ifdef __cplusplus diff --git a/core/src/plugins/dird/example/example-plugin-dir.cc b/core/src/plugins/dird/example/example-plugin-dir.cc index d06a19bbc2e..ea2a4394d4f 100644 --- a/core/src/plugins/dird/example/example-plugin-dir.cc +++ b/core/src/plugins/dird/example/example-plugin-dir.cc @@ -55,7 +55,7 @@ static PluginInformation pluginInfo = { PLUGIN_AUTHOR, PLUGIN_DATE, PLUGIN_VERSION, PLUGIN_DESCRIPTION}; -static pDirFuncs pluginFuncs = { +static PluginFunctions pluginFuncs = { sizeof(pluginFuncs), DIR_PLUGIN_INTERFACE_VERSION, /* Entry points into plugin */ @@ -77,7 +77,7 @@ extern "C" { bRC loadPlugin(bDirInfo* lbareos_plugin_interface_version, bDirFuncs* lbareos_core_functions, PluginInformation** plugin_information, - pDirFuncs** plugin_functions) + PluginFunctions** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ diff --git a/core/src/plugins/dird/python/bareosdir.cc b/core/src/plugins/dird/python/bareosdir.cc index 4dcfc0af72e..8dd5eea8307 100644 --- a/core/src/plugins/dird/python/bareosdir.cc +++ b/core/src/plugins/dird/python/bareosdir.cc @@ -48,8 +48,7 @@ namespace directordaemon { static const int debuglevel = 150; -static bRC set_bareos_core_functions( - DirectorCoreFunctions* new_bareos_core_functions); +static bRC set_bareos_core_functions(CoreFunctions* new_bareos_core_functions); static bRC set_plugin_context(PluginContext* new_plugin_context); static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); @@ -64,7 +63,7 @@ static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, void* value); /* Pointers to Bareos functions */ -static DirectorCoreFunctions* bareos_core_functions = NULL; +static CoreFunctions* bareos_core_functions = NULL; #define NOPLUGINSETGETVALUE 1 @@ -73,8 +72,7 @@ static DirectorCoreFunctions* bareos_core_functions = NULL; /* set the bareos_core_functions pointer to the given value */ -static bRC set_bareos_core_functions( - DirectorCoreFunctions* new_bareos_core_functions) +static bRC set_bareos_core_functions(CoreFunctions* new_bareos_core_functions) { bareos_core_functions = new_bareos_core_functions; return bRC_OK; diff --git a/core/src/plugins/dird/python/bareosdir.h b/core/src/plugins/dird/python/bareosdir.h index b11b5c342ad..9f6ee03b4c0 100644 --- a/core/src/plugins/dird/python/bareosdir.h +++ b/core/src/plugins/dird/python/bareosdir.h @@ -73,8 +73,7 @@ static PyMethodDef Methods[] = { {NULL, NULL, 0, NULL}}; -static bRC set_bareos_core_functions( - DirectorCoreFunctions* new_bareos_core_functions); +static bRC set_bareos_core_functions(CoreFunctions* new_bareos_core_functions); static bRC set_plugin_context(PluginContext* new_plugin_context); static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); @@ -111,22 +110,21 @@ MOD_INIT(bareosdir) if (c_api_object != NULL) PyModule_AddObject(m, "_C_API", c_api_object); - /* add bpFuncs Capsule */ + /* add bPluginFunctions Capsule */ PyObject* PyModulePluginFuncs = PyCapsule_New((void*)&bareos_core_functions, - PYTHON_MODULE_NAME_QUOTED ".BareosCoreFunctions", NULL); + PYTHON_MODULE_NAME_QUOTED ".CoreFunctions", NULL); if (!PyModulePluginFuncs) { - printf(PYTHON_MODULE_NAME_QUOTED - ":BareosCoreFunctions PyCapsule_New failed\n"); + printf(PYTHON_MODULE_NAME_QUOTED ":CoreFunctions PyCapsule_New failed\n"); return MOD_ERROR_VAL; } if (PyModulePluginFuncs) { - PyModule_AddObject(m, "BareosCoreFunctions", PyModulePluginFuncs); - printf(PYTHON_MODULE_NAME_QUOTED ": added BareosCoreFunctions@%p\n", + PyModule_AddObject(m, "CoreFunctions", PyModulePluginFuncs); + printf(PYTHON_MODULE_NAME_QUOTED ": added CoreFunctions@%p\n", &bareos_core_functions); } else { printf(PYTHON_MODULE_NAME_QUOTED - ":BareosCoreFunctions PyModule_AddObject failed\n"); + ":CoreFunctions PyModule_AddObject failed\n"); return MOD_ERROR_VAL; } diff --git a/core/src/plugins/dird/python/bareosdir_api_funcs.txt b/core/src/plugins/dird/python/bareosdir_api_funcs.txt index 8a637daf14f..de4b179207c 100644 --- a/core/src/plugins/dird/python/bareosdir_api_funcs.txt +++ b/core/src/plugins/dird/python/bareosdir_api_funcs.txt @@ -2,5 +2,5 @@ bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); bRC PySetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); bRC PyHandlePluginEvent(PluginContext* plugin_ctx, bDirEvent* event, void* value); -bRC set_bareos_core_functions( DirectorCoreFunctions* new_bareos_core_functions); +bRC set_bareos_core_functions( CoreFunctions* new_bareos_core_functions); bRC set_plugin_context(PluginContext* new_plugin_context); diff --git a/core/src/plugins/dird/python/capi_1.inc b/core/src/plugins/dird/python/capi_1.inc index 3b1be83c9cf..df8cdfa2611 100644 --- a/core/src/plugins/dird/python/capi_1.inc +++ b/core/src/plugins/dird/python/capi_1.inc @@ -20,10 +20,10 @@ #define Bareosdir_PyHandlePluginEvent_RETURN bRC #define Bareosdir_PyHandlePluginEvent_PROTO (PluginContext* plugin_ctx, bDirEvent* event, void* value) -/* static bRC set_bareos_core_functions( DirectorCoreFunctions* new_bareos_core_functions); */ +/* static bRC set_bareos_core_functions( CoreFunctions* new_bareos_core_functions); */ #define Bareosdir_set_bareos_core_functions_NUM 4 #define Bareosdir_set_bareos_core_functions_RETURN bRC -#define Bareosdir_set_bareos_core_functions_PROTO ( DirectorCoreFunctions* new_bareos_core_functions) +#define Bareosdir_set_bareos_core_functions_PROTO ( CoreFunctions* new_bareos_core_functions) /* static bRC set_plugin_context(PluginContext* new_plugin_context); */ #define Bareosdir_set_plugin_context_NUM 5 diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index 2c11f2c567f..7ef9140ebba 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -74,8 +74,8 @@ static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); static bRC PyLoadModule(PluginContext* plugin_ctx, void* value); /* Pointers to Bareos functions */ -static DirectorCoreFunctions* bareos_core_functions = NULL; -static Dir_PluginApiDefinition* bareos_plugin_interface_version = NULL; +static CoreFunctions* bareos_core_functions = NULL; +static PluginApiDefinition* bareos_plugin_interface_version = NULL; static PluginInformation pluginInfo = { sizeof(pluginInfo), DIR_PLUGIN_INTERFACE_VERSION, @@ -84,7 +84,7 @@ static PluginInformation pluginInfo = { PLUGIN_VERSION, PLUGIN_DESCRIPTION, PLUGIN_USAGE}; -static pDirFuncs pluginFuncs = { +static PluginFunctions pluginFuncs = { sizeof(pluginFuncs), DIR_PLUGIN_INTERFACE_VERSION, /* Entry points into plugin */ @@ -192,10 +192,10 @@ static void PyErrorHandler() * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(Dir_PluginApiDefinition* lbareos_plugin_interface_version, - DirectorCoreFunctions* lbareos_core_functions, +bRC loadPlugin(PluginApiDefinition* lbareos_plugin_interface_version, + CoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, - pDirFuncs** plugin_functions) + PluginFunctions** plugin_functions) { /* Setup Python */ Py_InitializeEx(0); diff --git a/core/src/plugins/filed/bpipe/bpipe-fd.cc b/core/src/plugins/filed/bpipe/bpipe-fd.cc index b2aeaaa8f93..e902260fc82 100644 --- a/core/src/plugins/filed/bpipe/bpipe-fd.cc +++ b/core/src/plugins/filed/bpipe/bpipe-fd.cc @@ -69,8 +69,8 @@ static bRC parse_plugin_definition(PluginContext* ctx, void* value); static bRC plugin_has_all_arguments(PluginContext* ctx); /* Pointers to Bareos functions */ -static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; +static CoreFunctions* bareos_core_functions = NULL; +static PluginApiDefinition* bareos_plugin_interface_version = NULL; /* Plugin Information block */ static PluginInformation pluginInfo = { @@ -81,7 +81,7 @@ static PluginInformation pluginInfo = { PLUGIN_USAGE}; /* Plugin entry points for Bareos */ -static pFuncs pluginFuncs = { +static PluginFunctions pluginFuncs = { sizeof(pluginFuncs), FD_PLUGIN_INTERFACE_VERSION, /* Entry points into plugin */ @@ -140,10 +140,10 @@ extern "C" { /** * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, - BareosCoreFunctions* lbareos_core_functions, +bRC loadPlugin(PluginApiDefinition* lbareos_plugin_interface_version, + CoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, - pFuncs** plugin_functions) + PluginFunctions** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ diff --git a/core/src/plugins/filed/cephfs/cephfs-fd.cc b/core/src/plugins/filed/cephfs/cephfs-fd.cc index 1225669b97c..7040b310fe7 100644 --- a/core/src/plugins/filed/cephfs/cephfs-fd.cc +++ b/core/src/plugins/filed/cephfs/cephfs-fd.cc @@ -76,8 +76,8 @@ static bRC end_restore_job(PluginContext* ctx, void* value); /** * Pointers to Bareos functions */ -static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; +static CoreFunctions* bareos_core_functions = NULL; +static PluginApiDefinition* bareos_plugin_interface_version = NULL; /** * Plugin Information block @@ -92,7 +92,7 @@ static PluginInformation pluginInfo = { /** * Plugin entry points for Bareos */ -static pFuncs pluginFuncs = { +static PluginFunctions pluginFuncs = { sizeof(pluginFuncs), FD_PLUGIN_INTERFACE_VERSION, /* Entry points into plugin */ @@ -180,10 +180,10 @@ extern "C" { * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, - BareosCoreFunctions* lbareos_core_functions, +bRC loadPlugin(PluginApiDefinition* lbareos_plugin_interface_version, + CoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, - pFuncs** plugin_functions) + PluginFunctions** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ diff --git a/core/src/plugins/filed/example/example-plugin-fd.cc b/core/src/plugins/filed/example/example-plugin-fd.cc index 6f1cc34e6bc..ba8ac9183a9 100644 --- a/core/src/plugins/filed/example/example-plugin-fd.cc +++ b/core/src/plugins/filed/example/example-plugin-fd.cc @@ -46,8 +46,8 @@ static bRC setXattr(PluginContext* ctx, xattr_pkt* xp); /* Pointers to Bareos functions */ -static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; +static CoreFunctions* bareos_core_functions = NULL; +static PluginApiDefinition* bareos_plugin_interface_version = NULL; static PluginInformation pluginInfo = { sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, @@ -55,7 +55,7 @@ static PluginInformation pluginInfo = { PLUGIN_AUTHOR, PLUGIN_DATE, PLUGIN_VERSION, PLUGIN_DESCRIPTION}; -static pFuncs pluginFuncs = { +static PluginFunctions pluginFuncs = { sizeof(pluginFuncs), FD_PLUGIN_INTERFACE_VERSION, /* Entry points into plugin */ @@ -72,10 +72,10 @@ extern "C" { /* * Plugin called here when it is first loaded */ -bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, - BareosCoreFunctions* lbareos_core_functions, +bRC loadPlugin(PluginApiDefinition* lbareos_plugin_interface_version, + CoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, - pFuncs** plugin_functions) + PluginFunctions** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ diff --git a/core/src/plugins/filed/gfapi/gfapi-fd.cc b/core/src/plugins/filed/gfapi/gfapi-fd.cc index d5a713907d0..041a5215299 100644 --- a/core/src/plugins/filed/gfapi/gfapi-fd.cc +++ b/core/src/plugins/filed/gfapi/gfapi-fd.cc @@ -91,8 +91,8 @@ static bRC setup_restore(PluginContext* ctx, void* value); /** * Pointers to Bareos functions */ -static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; +static CoreFunctions* bareos_core_functions = NULL; +static PluginApiDefinition* bareos_plugin_interface_version = NULL; /** * Plugin Information block @@ -107,7 +107,7 @@ static PluginInformation pluginInfo = { /** * Plugin entry points for Bareos */ -static pFuncs pluginFuncs = { +static PluginFunctions pluginFuncs = { sizeof(pluginFuncs), FD_PLUGIN_INTERFACE_VERSION, /* Entry points into plugin */ @@ -314,10 +314,10 @@ extern "C" { * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, - BareosCoreFunctions* lbareos_core_functions, +bRC loadPlugin(PluginApiDefinition* lbareos_plugin_interface_version, + CoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, - pFuncs** plugin_functions) + PluginFunctions** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 78ec5f9e634..152054c6102 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -43,8 +43,7 @@ namespace filedaemon { static const int debuglevel = 150; -static bRC set_bareos_core_functions( - BareosCoreFunctions* new_bareos_core_functions); +static bRC set_bareos_core_functions(CoreFunctions* new_bareos_core_functions); static bRC set_plugin_context(PluginContext* new_plugin_context); static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); @@ -75,7 +74,7 @@ static bRC PyRestoreObjectData(PluginContext* plugin_ctx, static bRC PyHandleBackupFile(PluginContext* plugin_ctx, struct save_pkt* sp); /* Pointers to Bareos functions */ -static BareosCoreFunctions* bareos_core_functions = NULL; +static CoreFunctions* bareos_core_functions = NULL; #include "plugin_private_context.h" @@ -85,8 +84,7 @@ static BareosCoreFunctions* bareos_core_functions = NULL; /* set the bareos_core_functions pointer to the given value */ -static bRC set_bareos_core_functions( - BareosCoreFunctions* new_bareos_core_functions) +static bRC set_bareos_core_functions(CoreFunctions* new_bareos_core_functions) { bareos_core_functions = new_bareos_core_functions; return bRC_OK; diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/bareosfd.h index 17a74f219b9..2edec3f1d29 100644 --- a/core/src/plugins/filed/python/bareosfd.h +++ b/core/src/plugins/filed/python/bareosfd.h @@ -738,8 +738,7 @@ static PyMethodDef Methods[] = { {NULL, NULL, 0, NULL}}; -static bRC set_bareos_core_functions( - BareosCoreFunctions* new_bareos_core_functions); +static bRC set_bareos_core_functions(CoreFunctions* new_bareos_core_functions); static bRC set_plugin_context(PluginContext* new_plugin_context); static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); @@ -792,22 +791,22 @@ MOD_INIT(bareosfd) if (c_api_object != NULL) PyModule_AddObject(m, "_C_API", c_api_object); #if 0 - /* add bpFuncs Capsule */ + /* add bPluginFunctions Capsule */ PyObject* PyModulePluginFuncs = PyCapsule_New((void*)&bareos_core_functions, - PYTHON_MODULE_NAME_QUOTED ".BareosCoreFunctions", NULL); + PYTHON_MODULE_NAME_QUOTED ".CoreFunctions", NULL); if (!PyModulePluginFuncs) { printf(PYTHON_MODULE_NAME_QUOTED - ":BareosCoreFunctions PyCapsule_New failed\n"); + ":CoreFunctions PyCapsule_New failed\n"); return MOD_ERROR_VAL; } if (PyModulePluginFuncs) { - PyModule_AddObject(m, "BareosCoreFunctions", PyModulePluginFuncs); - printf(PYTHON_MODULE_NAME_QUOTED ": added BareosCoreFunctions@%p\n", + PyModule_AddObject(m, "CoreFunctions", PyModulePluginFuncs); + printf(PYTHON_MODULE_NAME_QUOTED ": added CoreFunctions@%p\n", &bareos_core_functions); } else { printf(PYTHON_MODULE_NAME_QUOTED - ":BareosCoreFunctions PyModule_AddObject failed\n"); + ":CoreFunctions PyModule_AddObject failed\n"); return MOD_ERROR_VAL; } #endif diff --git a/core/src/plugins/filed/python/bareosfd_api_funcs.txt b/core/src/plugins/filed/python/bareosfd_api_funcs.txt index 6a41de55d5a..10c69af67bc 100644 --- a/core/src/plugins/filed/python/bareosfd_api_funcs.txt +++ b/core/src/plugins/filed/python/bareosfd_api_funcs.txt @@ -16,6 +16,6 @@ bRC PyGetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); bRC PySetXattr(PluginContext* bareos_plugin_ctx, xattr_pkt* xp); bRC PyRestoreObjectData(PluginContext* bareos_plugin_ctx, struct restore_object_pkt* rop); bRC PyHandleBackupFile(PluginContext* bareos_plugin_ctx, struct save_pkt* sp); -bRC set_bareos_core_functions(BareosCoreFunctions* new_bareos_core_functions); +bRC set_bareos_core_functions(CoreFunctions* new_bareos_core_functions); bRC set_plugin_context(PluginContext* new_plugin_context); diff --git a/core/src/plugins/filed/python/capi_1.inc b/core/src/plugins/filed/python/capi_1.inc index 3b64a2b4901..a80b61585e2 100644 --- a/core/src/plugins/filed/python/capi_1.inc +++ b/core/src/plugins/filed/python/capi_1.inc @@ -90,10 +90,10 @@ #define Bareosfd_PyHandleBackupFile_RETURN bRC #define Bareosfd_PyHandleBackupFile_PROTO (PluginContext* bareos_plugin_ctx, struct save_pkt* sp) -/* static bRC set_bareos_core_functions(BareosCoreFunctions* new_bareos_core_functions); */ +/* static bRC set_bareos_core_functions(CoreFunctions* new_bareos_core_functions); */ #define Bareosfd_set_bareos_core_functions_NUM 18 #define Bareosfd_set_bareos_core_functions_RETURN bRC -#define Bareosfd_set_bareos_core_functions_PROTO (BareosCoreFunctions* new_bareos_core_functions) +#define Bareosfd_set_bareos_core_functions_PROTO (CoreFunctions* new_bareos_core_functions) /* static bRC set_plugin_context(PluginContext* new_plugin_context); */ #define Bareosfd_set_plugin_context_NUM 19 diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 7c45efcac3b..11bdc35e567 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -86,8 +86,8 @@ static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); static bRC PyLoadModule(PluginContext* plugin_ctx, void* value); /* Pointers to Bareos functions */ -static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; +static CoreFunctions* bareos_core_functions = NULL; +static PluginApiDefinition* bareos_plugin_interface_version = NULL; static PluginInformation pluginInfo = { sizeof(pluginInfo), FD_PLUGIN_INTERFACE_VERSION, @@ -96,7 +96,7 @@ static PluginInformation pluginInfo = { PLUGIN_VERSION, PLUGIN_DESCRIPTION, PLUGIN_USAGE}; -static pFuncs pluginFuncs = { +static PluginFunctions pluginFuncs = { sizeof(pluginFuncs), FD_PLUGIN_INTERFACE_VERSION, /* Entry points into plugin */ @@ -165,10 +165,10 @@ static void PyErrorHandler() /** * Plugin called here when it is first loaded */ -bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, - BareosCoreFunctions* lbareos_core_functions, +bRC loadPlugin(PluginApiDefinition* lbareos_plugin_interface_version, + CoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, - pFuncs** plugin_functions) + PluginFunctions** plugin_functions) { if (!Py_IsInitialized()) { Py_InitializeEx(0); diff --git a/core/src/plugins/filed/python/test/bareosfd_test.py b/core/src/plugins/filed/python/test/bareosfd_test.py index 1d93a9f19a0..deec9d25d66 100644 --- a/core/src/plugins/filed/python/test/bareosfd_test.py +++ b/core/src/plugins/filed/python/test/bareosfd_test.py @@ -7,7 +7,7 @@ # print "bareosfd.bVariable:", str( bareosfd.bVariable) # print "bareosfd.bEventType:", str( bareosfd.bEventType) # print "bareosfd.bFileType:", str( bareosfd.bFileType) -# print "bareosfd.BareosCoreFunctions:", str( bareosfd.BareosCoreFunctions) +# print "bareosfd.CoreFunctions:", str( bareosfd.CoreFunctions) # print "bareosfd.bIOPS:", str( bareosfd.bIOPS) # print "bareosfd.bLevels:", str( bareosfd.bLevels) # print "bareosfd.bRCs:", str( bareosfd.bRCs) @@ -24,7 +24,7 @@ def test_ModuleDicts(self): # print bCFs # bEventType # bFileType - # BareosCoreFunctions + # CoreFunctions # bIOPS # bJobMessageType # bLevels diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index ae270bd877a..81f2c0014be 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -150,8 +150,8 @@ bRC bareosClearSeenBitmap(PluginContext* ctx, bool all, char* fname) /* Bareos entry points */ -static filedaemon::BareosCoreFunctions bareos_core_functions = { - sizeof(filedaemon::BareosCoreFunctions), +static filedaemon::CoreFunctions bareos_core_functions = { + sizeof(filedaemon::CoreFunctions), FD_PLUGIN_INTERFACE_VERSION, bareosRegisterEvents, bareosUnRegisterEvents, @@ -210,9 +210,9 @@ int main(int argc, char* argv[]) // Extract capsules pointer from bareosfd module /* void* bareos_core_functions_from_bareosfd_module = */ - /* PyCapsule_Import("bareosfd.BareosCoreFunctions", 0); */ + /* PyCapsule_Import("bareosfd.CoreFunctions", 0); */ /* if (!bareos_core_functions_from_bareosfd_module) { */ - /* printf("importing bareosfd.BareosCoreFunctions failed \n"); */ + /* printf("importing bareosfd.CoreFunctions failed \n"); */ /* } */ /* *(void**)ctx_from_bareosfd_module = &bareos_PluginContext; */ diff --git a/core/src/plugins/filed/rados/rados-fd.cc b/core/src/plugins/filed/rados/rados-fd.cc index 4355db725c6..dffacdc702d 100644 --- a/core/src/plugins/filed/rados/rados-fd.cc +++ b/core/src/plugins/filed/rados/rados-fd.cc @@ -84,8 +84,8 @@ static bRC end_restore_job(PluginContext* ctx, void* value); /** * Pointers to Bareos functions */ -static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; +static CoreFunctions* bareos_core_functions = NULL; +static PluginApiDefinition* bareos_plugin_interface_version = NULL; /** * Plugin Information block @@ -100,7 +100,7 @@ static PluginInformation pluginInfo = { /** * Plugin entry points for Bareos */ -static pFuncs pluginFuncs = { +static PluginFunctions pluginFuncs = { sizeof(pluginFuncs), FD_PLUGIN_INTERFACE_VERSION, /* Entry points into plugin */ @@ -179,10 +179,10 @@ extern "C" { * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, - BareosCoreFunctions* lbareos_core_functions, +bRC loadPlugin(PluginApiDefinition* lbareos_plugin_interface_version, + CoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, - pFuncs** plugin_functions) + PluginFunctions** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ diff --git a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc index 2e5b44f933b..d989d0ee3d5 100644 --- a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc +++ b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc @@ -54,8 +54,8 @@ static bRC createFile(PluginContext* ctx, struct restore_pkt* rp); static bRC setFileAttributes(PluginContext* ctx, struct restore_pkt* rp); /* Pointers to Bareos functions */ -static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; +static CoreFunctions* bareos_core_functions = NULL; +static PluginApiDefinition* bareos_plugin_interface_version = NULL; /* Plugin Information block */ static PluginInformation pluginInfo = { @@ -65,7 +65,7 @@ static PluginInformation pluginInfo = { PLUGIN_VERSION, PLUGIN_DESCRIPTION}; /* Plugin entry points for Bareos */ -static pFuncs pluginFuncs = { +static PluginFunctions pluginFuncs = { sizeof(pluginFuncs), FD_PLUGIN_INTERFACE_VERSION, /* Entry points into plugin */ @@ -117,10 +117,10 @@ extern "C" { /** * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, - BareosCoreFunctions* lbareos_core_functions, +bRC loadPlugin(PluginApiDefinition* lbareos_plugin_interface_version, + CoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, - pFuncs** plugin_functions) + PluginFunctions** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ diff --git a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc index 867b18c9a9f..11c534b9c1f 100644 --- a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc +++ b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc @@ -63,8 +63,8 @@ static bRC getXattr(PluginContext* ctx, xattr_pkt* xp); static bRC setXattr(PluginContext* ctx, xattr_pkt* xp); /* Pointers to Bareos functions */ -static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; +static CoreFunctions* bareos_core_functions = NULL; +static PluginApiDefinition* bareos_plugin_interface_version = NULL; /* Plugin Information block */ static PluginInformation pluginInfo = { @@ -74,7 +74,7 @@ static PluginInformation pluginInfo = { PLUGIN_VERSION, PLUGIN_DESCRIPTION}; /* Plugin entry points for Bareos */ -static pFuncs pluginFuncs = { +static PluginFunctions pluginFuncs = { sizeof(pluginFuncs), FD_PLUGIN_INTERFACE_VERSION, /* Entry points into plugin */ @@ -123,10 +123,10 @@ extern "C" { /** * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, - BareosCoreFunctions* lbareos_core_functions, +bRC loadPlugin(PluginApiDefinition* lbareos_plugin_interface_version, + CoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, - pFuncs** plugin_functions) + PluginFunctions** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ diff --git a/core/src/plugins/stored/autoxflate/autoxflate-sd.cc b/core/src/plugins/stored/autoxflate/autoxflate-sd.cc index 1dc83f61d35..7b7fbb59630 100644 --- a/core/src/plugins/stored/autoxflate/autoxflate-sd.cc +++ b/core/src/plugins/stored/autoxflate/autoxflate-sd.cc @@ -89,8 +89,8 @@ static bool sd_enabled_compatible = false; /** * Pointers to Bareos functions */ -static StorageDaemonCoreFunctions* bareos_core_functions = NULL; -static Sd_PluginApiDefinition* bareos_plugin_interface_version = NULL; +static CoreFunctions* bareos_core_functions = NULL; +static PluginApiDefinition* bareos_plugin_interface_version = NULL; static PluginInformation pluginInfo = { sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, @@ -99,15 +99,15 @@ static PluginInformation pluginInfo = { PLUGIN_VERSION, PLUGIN_DESCRIPTION, PLUGIN_USAGE}; -static pSdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, +static PluginFunctions pluginFuncs = { + sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, - /* - * Entry points into plugin - */ - newPlugin, /* new plugin instance */ - freePlugin, /* free plugin instance */ - getPluginValue, setPluginValue, - handlePluginEvent}; + /* + * Entry points into plugin + */ + newPlugin, /* new plugin instance */ + freePlugin, /* free plugin instance */ + getPluginValue, setPluginValue, handlePluginEvent}; /** * Plugin private context @@ -135,10 +135,10 @@ extern "C" { * * External entry point called by Bareos to "load the plugin */ -bRC loadPlugin(Sd_PluginApiDefinition* lbareos_plugin_interface_version, - StorageDaemonCoreFunctions* lbareos_core_functions, +bRC loadPlugin(PluginApiDefinition* lbareos_plugin_interface_version, + CoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, - pSdFuncs** plugin_functions) + PluginFunctions** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ diff --git a/core/src/plugins/stored/example/example-plugin-sd.cc b/core/src/plugins/stored/example/example-plugin-sd.cc index 927842a451f..d3cf34d3bb1 100644 --- a/core/src/plugins/stored/example/example-plugin-sd.cc +++ b/core/src/plugins/stored/example/example-plugin-sd.cc @@ -53,13 +53,13 @@ static PluginInformation pluginInfo = { PLUGIN_AUTHOR, PLUGIN_DATE, PLUGIN_VERSION, PLUGIN_DESCRIPTION}; -static psdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, +static PluginFunctions pluginFuncs = { + sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, - /* Entry points into plugin */ - newPlugin, /* new plugin instance */ - freePlugin, /* free plugin instance */ - getPluginValue, setPluginValue, - handlePluginEvent}; + /* Entry points into plugin */ + newPlugin, /* new plugin instance */ + freePlugin, /* free plugin instance */ + getPluginValue, setPluginValue, handlePluginEvent}; #ifdef __cplusplus extern "C" { @@ -75,7 +75,7 @@ extern "C" { bRC loadPlugin(bsdInfo* lbareos_plugin_interface_version, bsdFuncs* lbareos_core_functions, PluginInformation** plugin_information, - psdFuncs** plugin_functions) + PluginFunctions** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ diff --git a/core/src/plugins/stored/python/bareossd.cc b/core/src/plugins/stored/python/bareossd.cc index 24ba608d544..e5a6c43a475 100644 --- a/core/src/plugins/stored/python/bareossd.cc +++ b/core/src/plugins/stored/python/bareossd.cc @@ -43,8 +43,7 @@ namespace storagedaemon { static const int debuglevel = 150; -static bRC set_bareos_core_functions( - StorageDaemonCoreFunctions* new_bareos_core_functions); +static bRC set_bareos_core_functions(CoreFunctions* new_bareos_core_functions); static bRC set_plugin_context(PluginContext* new_plugin_context); static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); @@ -59,7 +58,7 @@ static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, void* value); /* Pointers to Bareos functions */ -static StorageDaemonCoreFunctions* bareos_core_functions = NULL; +static CoreFunctions* bareos_core_functions = NULL; #include "plugin_private_context.h" @@ -69,8 +68,7 @@ static StorageDaemonCoreFunctions* bareos_core_functions = NULL; /* set the bareos_core_functions pointer to the given value */ -static bRC set_bareos_core_functions( - StorageDaemonCoreFunctions* new_bareos_core_functions) +static bRC set_bareos_core_functions(CoreFunctions* new_bareos_core_functions) { bareos_core_functions = new_bareos_core_functions; return bRC_OK; diff --git a/core/src/plugins/stored/python/bareossd.h b/core/src/plugins/stored/python/bareossd.h index 911c5817fbd..899f36a072d 100644 --- a/core/src/plugins/stored/python/bareossd.h +++ b/core/src/plugins/stored/python/bareossd.h @@ -69,8 +69,7 @@ static PyMethodDef Methods[] = { {NULL, NULL, 0, NULL}}; -static bRC set_bareos_core_functions( - StorageDaemonCoreFunctions* new_bareos_core_functions); +static bRC set_bareos_core_functions(CoreFunctions* new_bareos_core_functions); static bRC set_plugin_context(PluginContext* new_plugin_context); static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); @@ -107,22 +106,22 @@ MOD_INIT(bareossd) if (c_api_object != NULL) PyModule_AddObject(m, "_C_API", c_api_object); #if 0 - /* add bpFuncs Capsule */ + /* add bPluginFunctions Capsule */ PyObject* PyModulePluginFuncs = PyCapsule_New((void*)&bareos_core_functions, - PYTHON_MODULE_NAME_QUOTED ".BareosCoreFunctions", NULL); + PYTHON_MODULE_NAME_QUOTED ".CoreFunctions", NULL); if (!PyModulePluginFuncs) { printf(PYTHON_MODULE_NAME_QUOTED - ":BareosCoreFunctions PyCapsule_New failed\n"); + ":CoreFunctions PyCapsule_New failed\n"); return MOD_ERROR_VAL; } if (PyModulePluginFuncs) { - PyModule_AddObject(m, "BareosCoreFunctions", PyModulePluginFuncs); - printf(PYTHON_MODULE_NAME_QUOTED ": added BareosCoreFunctions@%p\n", + PyModule_AddObject(m, "CoreFunctions", PyModulePluginFuncs); + printf(PYTHON_MODULE_NAME_QUOTED ": added CoreFunctions@%p\n", &bareos_core_functions); } else { printf(PYTHON_MODULE_NAME_QUOTED - ":BareosCoreFunctions PyModule_AddObject failed\n"); + ":CoreFunctions PyModule_AddObject failed\n"); return MOD_ERROR_VAL; } #endif diff --git a/core/src/plugins/stored/python/bareossd_api_funcs.txt b/core/src/plugins/stored/python/bareossd_api_funcs.txt index c5e46c93b35..b94b9014bda 100644 --- a/core/src/plugins/stored/python/bareossd_api_funcs.txt +++ b/core/src/plugins/stored/python/bareossd_api_funcs.txt @@ -2,5 +2,5 @@ bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value); bRC PyGetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); bRC PySetPluginValue(PluginContext* plugin_ctx, pVariable var, void* value); bRC PyHandlePluginEvent(PluginContext* plugin_ctx, bSdEvent* event, void* value); -bRC set_bareos_core_functions( StorageDaemonCoreFunctions* new_bareos_core_functions); +bRC set_bareos_core_functions( CoreFunctions* new_bareos_core_functions); bRC set_plugin_context(PluginContext* new_plugin_context); diff --git a/core/src/plugins/stored/python/capi_1.inc b/core/src/plugins/stored/python/capi_1.inc index a0ec08e0a5a..b55910301d0 100644 --- a/core/src/plugins/stored/python/capi_1.inc +++ b/core/src/plugins/stored/python/capi_1.inc @@ -20,10 +20,10 @@ #define Bareossd_PyHandlePluginEvent_RETURN bRC #define Bareossd_PyHandlePluginEvent_PROTO (PluginContext* plugin_ctx, bSdEvent* event, void* value) -/* static bRC set_bareos_core_functions( StorageDaemonCoreFunctions* new_bareos_core_functions); */ +/* static bRC set_bareos_core_functions( CoreFunctions* new_bareos_core_functions); */ #define Bareossd_set_bareos_core_functions_NUM 4 #define Bareossd_set_bareos_core_functions_RETURN bRC -#define Bareossd_set_bareos_core_functions_PROTO ( StorageDaemonCoreFunctions* new_bareos_core_functions) +#define Bareossd_set_bareos_core_functions_PROTO ( CoreFunctions* new_bareos_core_functions) /* static bRC set_plugin_context(PluginContext* new_plugin_context); */ #define Bareossd_set_plugin_context_NUM 5 diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index 4bcb82d42ad..7fa140edd2e 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -73,8 +73,8 @@ static void PyErrorHandler(PluginContext* plugin_ctx, int msgtype); static bRC PyLoadModule(PluginContext* plugin_ctx, void* value); /* Pointers to Bareos functions */ -static StorageDaemonCoreFunctions* bareos_core_functions = NULL; -static Sd_PluginApiDefinition* bareos_plugin_interface_version = NULL; +static CoreFunctions* bareos_core_functions = NULL; +static PluginApiDefinition* bareos_plugin_interface_version = NULL; static PluginInformation pluginInfo = { sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, @@ -83,13 +83,13 @@ static PluginInformation pluginInfo = { PLUGIN_VERSION, PLUGIN_DESCRIPTION, PLUGIN_USAGE}; -static pSdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, +static PluginFunctions pluginFuncs = { + sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, - /* Entry points into plugin */ - newPlugin, /* new plugin instance */ - freePlugin, /* free plugin instance */ - getPluginValue, setPluginValue, - handlePluginEvent}; + /* Entry points into plugin */ + newPlugin, /* new plugin instance */ + freePlugin, /* free plugin instance */ + getPluginValue, setPluginValue, handlePluginEvent}; #include "plugin_private_context.h" @@ -192,10 +192,10 @@ static void PyErrorHandler() * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(Sd_PluginApiDefinition* lbareos_plugin_interface_version, - StorageDaemonCoreFunctions* lbareos_core_functions, +bRC loadPlugin(PluginApiDefinition* lbareos_plugin_interface_version, + CoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, - pSdFuncs** plugin_functions) + PluginFunctions** plugin_functions) { Py_InitializeEx(0); diff --git a/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc b/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc index 91ede058a3e..95167f86cf9 100644 --- a/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc +++ b/core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc @@ -94,8 +94,8 @@ static bRC send_volume_encryption_status(void* value); /** * Pointers to Bareos functions */ -static StorageDaemonCoreFunctions* bareos_core_functions = NULL; -static Sd_PluginApiDefinition* bareos_plugin_interface_version = NULL; +static CoreFunctions* bareos_core_functions = NULL; +static PluginApiDefinition* bareos_plugin_interface_version = NULL; static PluginInformation pluginInfo = { sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, @@ -104,15 +104,15 @@ static PluginInformation pluginInfo = { PLUGIN_VERSION, PLUGIN_DESCRIPTION, PLUGIN_USAGE}; -static pSdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, +static PluginFunctions pluginFuncs = { + sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, - /* - * Entry points into plugin - */ - newPlugin, /* new plugin instance */ - freePlugin, /* free plugin instance */ - getPluginValue, setPluginValue, - handlePluginEvent}; + /* + * Entry points into plugin + */ + newPlugin, /* new plugin instance */ + freePlugin, /* free plugin instance */ + getPluginValue, setPluginValue, handlePluginEvent}; static int const debuglevel = 200; @@ -127,10 +127,10 @@ extern "C" { * * External entry point called by Bareos to "load the plugin */ -bRC loadPlugin(Sd_PluginApiDefinition* lbareos_plugin_interface_version, - StorageDaemonCoreFunctions* lbareos_core_functions, +bRC loadPlugin(PluginApiDefinition* lbareos_plugin_interface_version, + CoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, - pSdFuncs** plugin_functions) + PluginFunctions** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ diff --git a/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc b/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc index ccd443b320d..005e0b05fae 100644 --- a/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc +++ b/core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc @@ -53,8 +53,8 @@ static bRC handle_tapealert_readout(void* value); /** * Pointers to Bareos functions */ -static StorageDaemonCoreFunctions* bareos_core_functions = NULL; -static Sd_PluginApiDefinition* bareos_plugin_interface_version = NULL; +static CoreFunctions* bareos_core_functions = NULL; +static PluginApiDefinition* bareos_plugin_interface_version = NULL; static PluginInformation pluginInfo = { sizeof(pluginInfo), SD_PLUGIN_INTERFACE_VERSION, @@ -63,15 +63,15 @@ static PluginInformation pluginInfo = { PLUGIN_VERSION, PLUGIN_DESCRIPTION, PLUGIN_USAGE}; -static pSdFuncs pluginFuncs = {sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, +static PluginFunctions pluginFuncs = { + sizeof(pluginFuncs), SD_PLUGIN_INTERFACE_VERSION, - /* - * Entry points into plugin - */ - newPlugin, /* new plugin instance */ - freePlugin, /* free plugin instance */ - getPluginValue, setPluginValue, - handlePluginEvent}; + /* + * Entry points into plugin + */ + newPlugin, /* new plugin instance */ + freePlugin, /* free plugin instance */ + getPluginValue, setPluginValue, handlePluginEvent}; static int const debuglevel = 200; @@ -86,10 +86,10 @@ extern "C" { * * External entry point called by Bareos to "load the plugin */ -bRC loadPlugin(Sd_PluginApiDefinition* lbareos_plugin_interface_version, - StorageDaemonCoreFunctions* lbareos_core_functions, +bRC loadPlugin(PluginApiDefinition* lbareos_plugin_interface_version, + CoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, - pSdFuncs** plugin_functions) + PluginFunctions** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ diff --git a/core/src/stored/sd_plugins.cc b/core/src/stored/sd_plugins.cc index 3b1d699ed41..32ed0c7f9d4 100644 --- a/core/src/stored/sd_plugins.cc +++ b/core/src/stored/sd_plugins.cc @@ -83,27 +83,19 @@ static void bareosFreeRecord(DeviceRecord* rec); static bool IsPluginCompatible(Plugin* plugin); /* Bareos info */ -static Sd_PluginApiDefinition bareos_plugin_interface_version = { - sizeof(pSdFuncs), SD_PLUGIN_INTERFACE_VERSION}; +static PluginApiDefinition bareos_plugin_interface_version = { + sizeof(PluginFunctions), SD_PLUGIN_INTERFACE_VERSION}; /* Bareos entry points */ -static StorageDaemonCoreFunctions bareos_core_functions = { - sizeof(StorageDaemonCoreFunctions), - SD_PLUGIN_INTERFACE_VERSION, - bareosRegisterEvents, - bareosUnRegisterEvents, - bareosGetInstanceCount, - bareosGetValue, - bareosSetValue, - bareosJobMsg, - bareosDebugMsg, - bareosEditDeviceCodes, - bareosLookupCryptoKey, - bareosUpdateVolumeInfo, - bareosUpdateTapeAlert, - bareosNewRecord, - bareosCopyRecordState, - bareosFreeRecord}; +static CoreFunctions bareos_core_functions = { + sizeof(CoreFunctions), SD_PLUGIN_INTERFACE_VERSION, + bareosRegisterEvents, bareosUnRegisterEvents, + bareosGetInstanceCount, bareosGetValue, + bareosSetValue, bareosJobMsg, + bareosDebugMsg, bareosEditDeviceCodes, + bareosLookupCryptoKey, bareosUpdateVolumeInfo, + bareosUpdateTapeAlert, bareosNewRecord, + bareosCopyRecordState, bareosFreeRecord}; /** * Bareos private context diff --git a/core/src/stored/sd_plugins.h b/core/src/stored/sd_plugins.h index 432163b7b9c..7dbba6fdd20 100644 --- a/core/src/stored/sd_plugins.h +++ b/core/src/stored/sd_plugins.h @@ -131,7 +131,7 @@ typedef struct s_bSdEvent { typedef struct s_sdbareosInfo { uint32_t size; uint32_t version; -} Sd_PluginApiDefinition; +} PluginApiDefinition; #ifdef __cplusplus extern "C" { @@ -174,7 +174,7 @@ typedef struct s_sdbareosFuncs { DeviceRecord* (*new_record)(bool with_data); void (*CopyRecordState)(DeviceRecord* dst, DeviceRecord* src); void (*FreeRecord)(DeviceRecord* rec); -} StorageDaemonCoreFunctions; +} CoreFunctions; /* * Bareos Core Routines -- not used within a plugin @@ -216,9 +216,9 @@ typedef struct s_sdpluginFuncs { bRC (*getPluginValue)(PluginContext* ctx, pVariable var, void* value); bRC (*setPluginValue)(PluginContext* ctx, pVariable var, void* value); bRC (*handlePluginEvent)(PluginContext* ctx, bSdEvent* event, void* value); -} pSdFuncs; +} PluginFunctions; -#define SdplugFunc(plugin) ((pSdFuncs*)(plugin->plugin_functions)) +#define SdplugFunc(plugin) ((PluginFunctions*)(plugin->plugin_functions)) #define sdplug_info(plugin) ((PluginInformation*)(plugin->plugin_information)) #ifdef __cplusplus diff --git a/core/src/tools/bpluginfo.cc b/core/src/tools/bpluginfo.cc index 9d2f3d7e92b..a7cbc828e0d 100644 --- a/core/src/tools/bpluginfo.cc +++ b/core/src/tools/bpluginfo.cc @@ -64,21 +64,17 @@ enum plugintype }; /* - * pDirFuncs - * pFuncs - * psdFuncs + * PluginFunctions */ typedef union _plugfuncs plugfuncs; union _plugfuncs { - directordaemon::pDirFuncs pdirfuncs; - filedaemon::pFuncs pfdfuncs; - storagedaemon::pSdFuncs psdfuncs; + directordaemon::PluginFunctions pdirfuncs; + filedaemon::PluginFunctions pfdfuncs; + storagedaemon::PluginFunctions psdfuncs; }; /* - * bDirFuncs - * BareosCoreFunctions - * bsdFuncs + * CoreFunctions */ typedef struct _bareosfuncs bareosfuncs; struct _bareosfuncs { @@ -105,15 +101,13 @@ struct _bareosfuncs { }; /* - * Dir_PluginApiDefiniton - * Core_PluginApiDefinition - * Sd_PluginApiDefinition + * PluginApiDefinition */ typedef union _bareosinfos bareosinfos; union _bareosinfos { - directordaemon::Dir_PluginApiDefinition bdirinfo; - filedaemon::Core_PluginApiDefinition bfdinfo; - storagedaemon::Sd_PluginApiDefinition bsdinfo; + directordaemon::PluginApiDefinition bdirinfo; + filedaemon::PluginApiDefinition bfdinfo; + storagedaemon::PluginApiDefinition bsdinfo; }; typedef struct _progdata progdata; diff --git a/core/src/win32/plugins/filed/mssqlvdi-fd.cc b/core/src/win32/plugins/filed/mssqlvdi-fd.cc index d2b551ea5ba..5eb77005536 100644 --- a/core/src/win32/plugins/filed/mssqlvdi-fd.cc +++ b/core/src/win32/plugins/filed/mssqlvdi-fd.cc @@ -112,8 +112,8 @@ static bool adoReportError(PluginContext* ctx); /** * Pointers to Bareos functions */ -static BareosCoreFunctions* bareos_core_functions = NULL; -static Core_PluginApiDefinition* bareos_plugin_interface_version = NULL; +static CoreFunctions* bareos_core_functions = NULL; +static PluginApiDefinition* bareos_plugin_interface_version = NULL; /** * Plugin Information block @@ -128,15 +128,15 @@ static PluginInformation pluginInfo = { /** * Plugin entry points for Bareos */ -static pFuncs pluginFuncs = {sizeof(pluginFuncs), FD_PLUGIN_INTERFACE_VERSION, +static PluginFunctions pluginFuncs = { + sizeof(pluginFuncs), FD_PLUGIN_INTERFACE_VERSION, - /* Entry points into plugin */ - newPlugin, /* new plugin instance */ - freePlugin, /* free plugin instance */ - getPluginValue, setPluginValue, handlePluginEvent, - startBackupFile, endBackupFile, startRestoreFile, - endRestoreFile, pluginIO, createFile, - setFileAttributes, checkFile}; + /* Entry points into plugin */ + newPlugin, /* new plugin instance */ + freePlugin, /* free plugin instance */ + getPluginValue, setPluginValue, handlePluginEvent, startBackupFile, + endBackupFile, startRestoreFile, endRestoreFile, pluginIO, createFile, + setFileAttributes, checkFile}; /** * Plugin private context @@ -228,10 +228,10 @@ extern "C" { * * External entry point called by Bareos to "load" the plugin */ -bRC loadPlugin(Core_PluginApiDefinition* lbareos_plugin_interface_version, - BareosCoreFunctions* lbareos_core_functions, +bRC loadPlugin(PluginApiDefinition* lbareos_plugin_interface_version, + CoreFunctions* lbareos_core_functions, PluginInformation** plugin_information, - pFuncs** plugin_functions) + PluginFunctions** plugin_functions) { bareos_core_functions = lbareos_core_functions; /* set Bareos funct pointers */ diff --git a/docs/manuals/source/DeveloperGuide/pluginAPI.rst b/docs/manuals/source/DeveloperGuide/pluginAPI.rst index d97b7a3a85c..be453ff9fa4 100644 --- a/docs/manuals/source/DeveloperGuide/pluginAPI.rst +++ b/docs/manuals/source/DeveloperGuide/pluginAPI.rst @@ -97,7 +97,7 @@ The two entry points are: :: - bRC loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs) + bRC loadPlugin(PluginApiDefinition *lbinfo, CoreFunctions *lbfuncs, PluginInformation **pinfo, PluginFunctions **pfuncs) and @@ -160,26 +160,26 @@ must return to Bareos. The call is: :: - bRC loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs) + bRC loadPlugin(PluginApiDefinition *lbinfo, CoreFunctions *lbfuncs, PluginInformation **pinfo, PluginFunctions **pfuncs) and the arguments are: lbinfo This is information about Bareos in general. Currently, the only - value defined in the bInfo structure is the version, which is the + value defined in the PluginApiDefinition structure is the version, which is the Bareos plugin interface version, currently defined as 1. The **size** is set to the byte size of the structure. The exact - definition of the bInfo structure as of this writing is: + definition of the PluginApiDefinition structure as of this writing is: :: typedef struct s_bareosInfo { uint32_t size; uint32_t version; - } bInfo; + } PluginApiDefinition; lbfuncs - The bFuncs structure defines the callback entry points within Bareos + The CoreFunctions structure defines the callback entry points within Bareos that the plugin can use register events, get Bareos values, set Bareos values, and send messages to the Job output or debug output. @@ -200,12 +200,12 @@ lbfuncs void *(*bareosMalloc)(bpContext *ctx, const char *file, int line, size_t size); void (*bareosFree)(bpContext *ctx, const char *file, int line, void *mem); - } bFuncs; + } CoreFunctions; We will discuss these entry points and how to use them a bit later when describing the plugin code. -pInfo +PluginInformation When the loadPlugin entry point is called, the plugin must initialize an information structure about the plugin and return a pointer to this structure to Bareos. @@ -223,7 +223,7 @@ pInfo const char *plugin_date; const char *plugin_version; const char *plugin_description; - } pInfo; + } PluginInformation; Where: @@ -254,13 +254,13 @@ pInfo is a pointer to a string describing what the plugin does. The contents are determined by the plugin writer. - The pInfo structure must be defined in static memory because Bareos + The PluginInformation structure must be defined in static memory because Bareos does not copy it and may refer to the values at any time while the plugin is loaded. All values must be supplied or the plugin will not run (not yet implemented). All text strings must be either ASCII or UTF-8 strings that are terminated with a zero byte. -pFuncs +PluginFunctions When the loadPlugin entry point is called, the plugin must initialize an entry point structure about the plugin and return a pointer to this structure to Bareos. This structure contains pointer @@ -268,7 +268,7 @@ pFuncs When Bareos is actually running the plugin, it will call the defined entry points at particular times. All entry points must be defined. - The pFuncs structure must be defined in static memory because Bareos + The PluginFunctions structure must be defined in static memory because Bareos does not copy it and may refer to the values at any time while the plugin is loaded. @@ -292,7 +292,7 @@ pFuncs bRC (*createFile)(bpContext *ctx, struct restore_pkt *rp); bRC (*setFileAttributes)(bpContext *ctx, struct restore_pkt *rp); bRC (*checkFile)(bpContext *ctx, char *fname); - } pFuncs; + } PluginFunctions; The details of the entry points will be presented in separate sections below. @@ -324,7 +324,7 @@ Plugin Entry Points This section will describe each of the entry points (subroutines) within the plugin that the plugin must provide for Bareos, when they are called and their arguments. As noted above, pointers to these subroutines are -passed back to Bareos in the pFuncs structure when Bareos calls the +passed back to Bareos in the PluginFunctions structure when Bareos calls the loadPlugin() externally defined entry point. newPlugin(bpContext \*ctx) From 5e47a248b3dbd2fe2e45f24a2380277470855fae Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 12 May 2020 14:42:01 +0200 Subject: [PATCH 103/341] python plugins: successfully build for python 3 --- core/CMakeLists.txt | 10 ++-- core/cmake/BareosFindAllLibraries.cmake | 13 ++--- core/src/plugins/dird/CMakeLists.txt | 6 +-- core/src/plugins/dird/python/bareosdir.cc | 48 ++++++++++--------- core/src/plugins/dird/python/python-dir.cc | 2 + core/src/plugins/filed/CMakeLists.txt | 10 ++-- core/src/plugins/filed/python/bareosfd.cc | 3 ++ core/src/plugins/filed/python/bareosfd.h | 25 ++-------- core/src/plugins/filed/python/python-fd.cc | 1 + .../python/test/python-fd-module-tester.cc | 3 +- core/src/plugins/stored/CMakeLists.txt | 6 +-- core/src/plugins/stored/python/bareossd.cc | 1 + core/src/plugins/stored/python/bareossd.h | 1 - core/src/plugins/stored/python/python-sd.cc | 2 + 14 files changed, 61 insertions(+), 70 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index c675f08622f..a1e5b0b7d83 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -300,10 +300,10 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") set(WINDOWS_LIBRARIES ws2_32) - set(PYTHON_LIBRARIES + set(Python_LIBRARIES ${PROJECT_SOURCE_DIR}/src/win32/plugins/python/lib/${WINDOWS_BITS}/python27.dll ) - set(PYTHON_INCLUDE_DIRS + set(Python_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/win32/plugins/python/include ) set(HAVE_PYTHON 1) @@ -408,9 +408,9 @@ include(BareosDetermineHaveLowLevelScsiInterface) include(acltypes) -include_directories(SYSTEM ${PYTHON_INCLUDE_DIRS}) +include_directories(SYSTEM ${Python_INCLUDE_DIRS}) -include_directories(SYSTEM ${PYTHON_INCLUDE_PATH}) +include_directories(SYSTEM ${Python_INCLUDE_PATH}) include_directories(${PROJECT_SOURCE_DIR}/src) @@ -868,7 +868,7 @@ message( " CEPHFS support: ${CEPHFS_FOUND} ${CEPHFS_LIBRARIES} ${CEPHFS_INCLUDE_DIRS} " ) message( - " Python support: ${PYTHONLIBS_FOUND} ${PYTHONLIBS_VERSION_STRING} ${PYTHON_INCLUDE_PATH}" + " Python support: ${Python_FOUND} ${Python_VERSION} ${Python_INCLUDE_DIRS}" ) message(" systemd support: ${WITH_SYSTEMD} ${SYSTEMD_UNITDIR}") message(" Batch insert enabled: ${USE_BATCH_FILE_INSERT}") diff --git a/core/cmake/BareosFindAllLibraries.cmake b/core/cmake/BareosFindAllLibraries.cmake index e2d6c55402b..9bf1d0ff3a1 100644 --- a/core/cmake/BareosFindAllLibraries.cmake +++ b/core/cmake/BareosFindAllLibraries.cmake @@ -23,15 +23,16 @@ if(${SYSTEMD_FOUND}) endif() if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") - # make sure we get python 2 not 3 - set(Python_ADDITIONAL_VERSIONS 2.5 2.6 2.7 2.8 2.9) - find_package(PythonInterp) - include(FindPythonLibs) - - if(${PYTHONLIBS_FOUND}) + find_package (Python COMPONENTS Interpreter Development) + if(${Python_FOUND}) set(HAVE_PYTHON 1) endif() +endif() + + + +if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") include(FindPostgreSQL) endif() diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index 28e808d1de2..c22da11e941 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -57,8 +57,8 @@ if(HAVE_PYTHON AND NOT HAVE_WIN32) DEPENDS bareos DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${PYTHON_EXECUTABLE} python/setup.py build - COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib + COMMAND ${Python_EXECUTABLE} python/setup.py build + COMMAND ${Python_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python module pythonmodules/bareosdir.so" @@ -67,7 +67,7 @@ if(HAVE_PYTHON AND NOT HAVE_WIN32) add_custom_target(bareosdir-pymod DEPENDS pythonmodules/bareosdir.so) add_test(NAME bareosdir-python-module - COMMAND ${PYTHON_EXECUTABLE} + COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosdir_test.py ) set_property( diff --git a/core/src/plugins/dird/python/bareosdir.cc b/core/src/plugins/dird/python/bareosdir.cc index 8dd5eea8307..1b3e090a494 100644 --- a/core/src/plugins/dird/python/bareosdir.cc +++ b/core/src/plugins/dird/python/bareosdir.cc @@ -39,13 +39,13 @@ #include "plugins/filed/fd_common.h" // for Dmsg Macro #include "plugin_private_context.h" +#include "plugins/python3compat.h" #define BAREOSDIR_MODULE #include "bareosdir.h" #include "lib/edit.h" namespace directordaemon { - static const int debuglevel = 150; static bRC set_bareos_core_functions(CoreFunctions* new_bareos_core_functions); @@ -87,9 +87,9 @@ static bRC set_plugin_context(PluginContext* new_plugin_context) /** - * Any plugin options which are passed in are dispatched here to a Python method - * and it can parse the plugin options. This function is also called after - * PyLoadModule() has loaded the Python module and made sure things are + * Any plugin options which are passed in are dispatched here to a Python + * method and it can parse the plugin options. This function is also called + * after PyLoadModule() has loaded the Python module and made sure things are * operational. */ static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value) @@ -191,8 +191,9 @@ static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to get certain internal values of the current Job. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to get certain internal values of the current + * Job. */ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) { @@ -277,8 +278,9 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to set certain internal values of the current Job. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to set certain internal values of the current + * Job. */ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) { @@ -326,9 +328,9 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue debug messages using the Bareos debug message - * facility. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue debug messages using the Bareos debug + * message facility. */ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) { @@ -348,9 +350,9 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue Job messages using the Bareos Job message - * facility. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue Job messages using the Bareos Job + * message facility. */ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { @@ -370,9 +372,9 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a Register Event to register additional events - * it wants to receive. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a Register Event to register + * additional events it wants to receive. */ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) { @@ -412,9 +414,9 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue an Unregister Event to unregister events it - * doesn't want to receive anymore. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue an Unregister Event to unregister + * events it doesn't want to receive anymore. */ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) { @@ -454,9 +456,9 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) } /** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a GetInstanceCount to retrieve the number of - * instances of the current plugin being loaded into the daemon. + * Callback function which is exposed as a part of the additional methods + * which allow a Python plugin to issue a GetInstanceCount to retrieve the + * number of instances of the current plugin being loaded into the daemon. */ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) { diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index 7ef9140ebba..ae9a8239871 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -35,6 +35,8 @@ #endif #include "dird/dird.h" +#include "plugins/python3compat.h" + #include "python-dir.h" #include "bareosdir.h" #include "lib/plugins.h" diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index 6a7d5804c9d..c3cd7a71f80 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -37,8 +37,6 @@ if(HAVE_WIN32) ${PROJECT_SOURCE_DIR}/src/win32/plugins/python/lib/${WINDOWS_BITS} ) add_definitions(-DMS_WIN${WINDOWS_BITS}) -else() - include_directories(/usr/include/python2.7) endif() include_directories(${OPENSSL_INCLUDE_DIR}) @@ -110,7 +108,7 @@ endif() if(HAVE_PYTHON AND NOT HAVE_WIN32) add_executable(bareos-fd-module-tester python/test/python-fd-module-tester.cc) - target_link_libraries(bareos-fd-module-tester ${PYTHON_LIBRARIES} bareos) + target_link_libraries(bareos-fd-module-tester ${Python_LIBRARIES} bareos) add_test(NAME bareosfd-python-module-tester COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bareos-fd-module-tester @@ -133,8 +131,8 @@ if(HAVE_PYTHON AND NOT HAVE_WIN32) DEPENDS bareos DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${PYTHON_EXECUTABLE} python/setup.py build - COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib + COMMAND ${Python_EXECUTABLE} python/setup.py build + COMMAND ${Python_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python module pythonmodules/bareosfd.so" @@ -143,7 +141,7 @@ if(HAVE_PYTHON AND NOT HAVE_WIN32) add_custom_target(bareosfd-pymod DEPENDS pythonmodules/bareosfd.so) add_test(NAME bareosfd-python-module - COMMAND ${PYTHON_EXECUTABLE} + COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosfd_test.py ) set_property( diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 152054c6102..4a453488965 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -35,8 +35,11 @@ #include "filed/fd_plugins.h" +#include "plugins/python3compat.h" + #define BAREOSFD_MODULE #include "bareosfd.h" +#include "plugins/python3compat.h" #include "lib/edit.h" namespace filedaemon { diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/bareosfd.h index 2edec3f1d29..0540589cb76 100644 --- a/core/src/plugins/filed/python/bareosfd.h +++ b/core/src/plugins/filed/python/bareosfd.h @@ -773,7 +773,6 @@ using namespace filedaemon; /* variables storing bareos pointers */ PluginContext* plugin_context = NULL; -static void* bareos_core_functions = NULL; MOD_INIT(bareosfd) { @@ -789,28 +788,10 @@ MOD_INIT(bareosfd) c_api_object = PyCapsule_New((void*)Bareosfd_API, PYTHON_MODULE_NAME_QUOTED "._C_API", NULL); - if (c_api_object != NULL) PyModule_AddObject(m, "_C_API", c_api_object); -#if 0 - /* add bPluginFunctions Capsule */ - PyObject* PyModulePluginFuncs = - PyCapsule_New((void*)&bareos_core_functions, - PYTHON_MODULE_NAME_QUOTED ".CoreFunctions", NULL); - if (!PyModulePluginFuncs) { - printf(PYTHON_MODULE_NAME_QUOTED - ":CoreFunctions PyCapsule_New failed\n"); + if (c_api_object != NULL) + PyModule_AddObject(m, "_C_API", c_api_object); + else return MOD_ERROR_VAL; - } - if (PyModulePluginFuncs) { - PyModule_AddObject(m, "CoreFunctions", PyModulePluginFuncs); - printf(PYTHON_MODULE_NAME_QUOTED ": added CoreFunctions@%p\n", - &bareos_core_functions); - } else { - printf(PYTHON_MODULE_NAME_QUOTED - ":CoreFunctions PyModule_AddObject failed\n"); - return MOD_ERROR_VAL; - } -#endif - PyRestoreObjectType.tp_new = PyType_GenericNew; if (PyType_Ready(&PyRestoreObjectType) < 0) { return MOD_ERROR_VAL; } diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 11bdc35e567..7d30779ab19 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -35,6 +35,7 @@ #endif #include "filed/fd_plugins.h" +#include "plugins/python3compat.h" #include "python-fd.h" #include "bareosfd.h" diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index 81f2c0014be..d1be996d5e2 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -22,6 +22,7 @@ /* Load the python-fd plugin and test it */ #include "Python.h" +#include "plugins/python3compat.h" class PoolMem; #define NbytesForBits(n) ((((n)-1) >> 3) + 1) typedef off_t boffset_t; @@ -184,7 +185,7 @@ static PluginContext bareos_PluginContext = {0, &plugin, NULL, NULL}; int main(int argc, char* argv[]) { - Py_SetProgramName(argv[0]); + /* Py_SetProgramName(argv[0]); */ Py_Initialize(); PyObject* bareosfdModule = PyImport_ImportModule("bareosfd"); diff --git a/core/src/plugins/stored/CMakeLists.txt b/core/src/plugins/stored/CMakeLists.txt index e8196cf5a2c..86754b9ae43 100644 --- a/core/src/plugins/stored/CMakeLists.txt +++ b/core/src/plugins/stored/CMakeLists.txt @@ -73,8 +73,8 @@ if(HAVE_PYTHON AND NOT HAVE_WIN32) DEPENDS bareos DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${PYTHON_EXECUTABLE} python/setup.py build - COMMAND ${PYTHON_EXECUTABLE} python/setup.py install --install-lib + COMMAND ${Python_EXECUTABLE} python/setup.py build + COMMAND ${Python_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python module pythonmodules/bareossd.so" @@ -83,7 +83,7 @@ if(HAVE_PYTHON AND NOT HAVE_WIN32) add_custom_target(bareossd-pymod DEPENDS pythonmodules/bareossd.so) add_test(NAME bareossd-python-module - COMMAND ${PYTHON_EXECUTABLE} + COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareossd_test.py ) set_property( diff --git a/core/src/plugins/stored/python/bareossd.cc b/core/src/plugins/stored/python/bareossd.cc index e5a6c43a475..73ba4e6f042 100644 --- a/core/src/plugins/stored/python/bareossd.cc +++ b/core/src/plugins/stored/python/bareossd.cc @@ -37,6 +37,7 @@ #define BAREOSSD_MODULE #include "bareossd.h" +#include "plugins/python3compat.h" #include "lib/edit.h" namespace storagedaemon { diff --git a/core/src/plugins/stored/python/bareossd.h b/core/src/plugins/stored/python/bareossd.h index 899f36a072d..295ed340fa2 100644 --- a/core/src/plugins/stored/python/bareossd.h +++ b/core/src/plugins/stored/python/bareossd.h @@ -88,7 +88,6 @@ using namespace storagedaemon; /* variables storing bareos pointers */ PluginContext* plugin_context = NULL; -static void* bareos_core_functions = NULL; MOD_INIT(bareossd) { diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index 7fa140edd2e..6aa688c9b51 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -35,6 +35,8 @@ #endif #include "stored/stored.h" +#include "plugins/python3compat.h" + #include "python-sd.h" #include "bareossd.h" #include "lib/edit.h" From 8471555f8740a8e63ba3d8be5c0eef6678aaa605 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 12 May 2020 18:31:23 +0200 Subject: [PATCH 104/341] python plugins: introduce python3compat.h --- core/src/plugins/dird/CMakeLists.txt | 2 +- core/src/plugins/dird/python/bareosdir.cc | 5 +++-- core/src/plugins/filed/CMakeLists.txt | 2 +- core/src/plugins/filed/python/bareosfd.cc | 17 ++++++++--------- .../plugins/filed/python/test/bareosfd_test.py | 6 +++--- core/src/plugins/python3compat.h | 14 ++++++++++++++ core/src/plugins/stored/CMakeLists.txt | 2 +- core/src/plugins/stored/python/bareossd.cc | 9 ++++----- .../plugins/stored/python/test/bareossd_test.py | 2 +- 9 files changed, 36 insertions(+), 23 deletions(-) create mode 100644 core/src/plugins/python3compat.h diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index c22da11e941..ac75df5747c 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -35,7 +35,7 @@ if(HAVE_PYTHON) # do not prefix with "lib" set_target_properties(python-dir PROPERTIES PREFIX "") install(TARGETS python-dir DESTINATION ${plugindir}) - target_link_libraries(python-dir ${PYTHON_LIBRARIES} bareos) + target_link_libraries(python-dir ${Python_LIBRARIES} bareos) add_dependencies(python-dir bareosdir-pymod) set(PYFILES diff --git a/core/src/plugins/dird/python/bareosdir.cc b/core/src/plugins/dird/python/bareosdir.cc index 1b3e090a494..6ac98130280 100644 --- a/core/src/plugins/dird/python/bareosdir.cc +++ b/core/src/plugins/dird/python/bareosdir.cc @@ -296,12 +296,13 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) switch (var) { case bwDirVarVolumeName: { - char* value; + const char* value; value = PyString_AsString(pyValue); if (value) { retval = bareos_core_functions->setBareosValue( - plugin_ctx, (bwDirVariable)var, value); + plugin_ctx, (bwDirVariable)var, + static_cast(const_cast(value))); } break; diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index c3cd7a71f80..dda1acc09b9 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -102,7 +102,7 @@ if(HAVE_PYTHON) DESTINATION ${plugindir} COMPONENT filedaemon ) - target_link_libraries(python-fd ${PYTHON_LIBRARIES} bareos) + target_link_libraries(python-fd ${Python_LIBRARIES} bareos) add_dependencies(python-fd bareosfd-pymod) endif() diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 4a453488965..1636ae3fc1f 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -1405,12 +1405,11 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) break; } case bVarFileSeen: { - char* value; - - value = PyString_AsString(pyValue); + const char* value = PyString_AsString(pyValue); if (value) { - retval = bareos_core_functions->setBareosValue(plugin_ctx, - (bVariable)var, value); + retval = bareos_core_functions->setBareosValue( + plugin_ctx, (bVariable)var, + static_cast(const_cast(value))); } break; } @@ -1758,7 +1757,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) sp.type = pSavePkt->type; if (pSavePkt->fname) { if (PyString_Check(pSavePkt->fname)) { - sp.fname = PyString_AsString(pSavePkt->fname); + sp.fname = const_cast(PyString_AsString(pSavePkt->fname)); } else { goto bail_out; } @@ -1767,7 +1766,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) } if (pSavePkt->link) { if (PyString_Check(pSavePkt->link)) { - sp.link = PyString_AsString(pSavePkt->link); + sp.link = const_cast(PyString_AsString(pSavePkt->link)); } else { goto bail_out; } @@ -1809,7 +1808,7 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) */ if (pSavePkt->fname) { if (PyString_Check(pSavePkt->fname)) { - sp.fname = PyString_AsString(pSavePkt->fname); + sp.fname = const_cast(PyString_AsString(pSavePkt->fname)); } else { goto bail_out; } @@ -1885,7 +1884,7 @@ static inline char* PyGetStringValue(PyObject* object) { if (!object || !PyString_Check(object)) { return (char*)""; } - return PyString_AsString(object); + return const_cast(PyString_AsString(object)); } static inline char* PyGetByteArrayValue(PyObject* object) diff --git a/core/src/plugins/filed/python/test/bareosfd_test.py b/core/src/plugins/filed/python/test/bareosfd_test.py index deec9d25d66..e8decefe536 100644 --- a/core/src/plugins/filed/python/test/bareosfd_test.py +++ b/core/src/plugins/filed/python/test/bareosfd_test.py @@ -18,8 +18,8 @@ class TestBareosFd(unittest.TestCase): def test_ModuleDicts(self): help (bareosfd) - print bareosfd.bCFs - print bareosfd.CF_ERROR + print (bareosfd.bCFs) + print (bareosfd.CF_ERROR) # print bCFs # bEventType @@ -85,7 +85,7 @@ def test_StatPacket(self): "StatPacket(dev=0, ino=0, mode=0700, nlink=0, uid=0, gid=0, rdev=0, size=-1, atime=999, mtime=1000, ctime=1001, blksize=4096, blocks=1)", str(test_StatPacket), ) - sp2 = bareosfd.StatPacket(dev=0, ino=0, mode=0700, nlink=0, uid=0, gid=0, rdev=0, size=-1, atime=1, mtime=1, ctime=1, blksize=4096, blocks=1) + sp2 = bareosfd.StatPacket(dev=0, ino=0, mode=0o0700, nlink=0, uid=0, gid=0, rdev=0, size=-1, atime=1, mtime=1, ctime=1, blksize=4096, blocks=1) self.assertEqual('StatPacket(dev=0, ino=0, mode=0700, nlink=0, uid=0, gid=0, rdev=0, size=-1, atime=1, mtime=1, ctime=1, blksize=4096, blocks=1)', str(sp2)) def test_SavePacket(self): diff --git a/core/src/plugins/python3compat.h b/core/src/plugins/python3compat.h new file mode 100644 index 00000000000..5048d9cfe70 --- /dev/null +++ b/core/src/plugins/python3compat.h @@ -0,0 +1,14 @@ +#ifndef BAREOS_CORE_SRC_PLUGINS_PYTHON3COMPAT_H_ +#define BAREOS_CORE_SRC_PLUGINS_PYTHON3COMPAT_H_ + +/* redefine python2 calls to python3 pendants */ + +#if PY_VERSION_HEX >= 0x03000000 +#define PyInt_FromLong PyLong_FromLong +#define PyInt_AsLong PyLong_AsLong +#define PyString_FromString PyBytes_FromString +#define PyString_AsString PyUnicode_AsUTF8 +#define PyString_Check PyUnicode_Check +#endif + +#endif // BAREOS_CORE_SRC_PLUGINS_PYTHON3COMPAT_H_ diff --git a/core/src/plugins/stored/CMakeLists.txt b/core/src/plugins/stored/CMakeLists.txt index 86754b9ae43..1336a5babdd 100644 --- a/core/src/plugins/stored/CMakeLists.txt +++ b/core/src/plugins/stored/CMakeLists.txt @@ -52,7 +52,7 @@ if(HAVE_PYTHON) add_library(python-sd MODULE python/python-sd.cc) set_target_properties(python-sd PROPERTIES PREFIX "") install(TARGETS python-sd DESTINATION ${plugindir}) - target_link_libraries(python-sd ${PYTHON_LIBRARIES} bareos) + target_link_libraries(python-sd ${Python_LIBRARIES} bareos) add_dependencies(python-sd bareossd-pymod) set(PYFILES diff --git a/core/src/plugins/stored/python/bareossd.cc b/core/src/plugins/stored/python/bareossd.cc index 73ba4e6f042..fbfd45c9ec5 100644 --- a/core/src/plugins/stored/python/bareossd.cc +++ b/core/src/plugins/stored/python/bareossd.cc @@ -292,12 +292,11 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) switch (var) { case bsdwVarVolumeName: { - char* value; - - value = PyString_AsString(pyValue); + const char* value = PyString_AsString(pyValue); if (value) { - bareos_core_functions->setBareosValue(plugin_ctx, (bsdwVariable)var, - value); + bareos_core_functions->setBareosValue( + plugin_ctx, (bsdwVariable)var, + static_cast(const_cast(value))); } break; diff --git a/core/src/plugins/stored/python/test/bareossd_test.py b/core/src/plugins/stored/python/test/bareossd_test.py index b4fd33de162..84ad7719307 100644 --- a/core/src/plugins/stored/python/test/bareossd_test.py +++ b/core/src/plugins/stored/python/test/bareossd_test.py @@ -2,7 +2,7 @@ import bareossd import time -print help (bareossd) +print (help (bareossd)) class TestBareosFd(unittest.TestCase): From 2a7186523a660f854248c238fa89479f7e3c9b8f Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 13 May 2020 13:00:38 +0200 Subject: [PATCH 105/341] python plugins: error handler in module_tester works --- core/src/plugins/dird/python/python-dir.cc | 1 + core/src/plugins/filed/python/python-fd.cc | 1 + core/src/plugins/filed/python/test/python-fd-module-tester.cc | 4 +++- core/src/plugins/python_plugins_common.inc | 1 + core/src/plugins/stored/python/python-sd.cc | 1 + .../etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in | 2 +- .../bareos_fd_local_fileset_with_restoreobjects.py} | 2 +- 7 files changed, 9 insertions(+), 3 deletions(-) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject/python-modules/bareos-fd-local-fileset-with-restoreobjects.py => pyplug-fd-local-fileset/python-modules/bareos_fd_local_fileset_with_restoreobjects.py} (97%) diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index ae9a8239871..2bb6b1efa01 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -154,6 +154,7 @@ static void PyErrorHandler() char* error_string; PyErr_Fetch(&type, &value, &traceback); + PyErr_NormalizeException(&type, &value, &traceback); tracebackModule = PyImport_ImportModule("traceback"); if (tracebackModule != NULL) { diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 7d30779ab19..7ba777846d1 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -130,6 +130,7 @@ static void PyErrorHandler() char* error_string; PyErr_Fetch(&type, &value, &traceback); + PyErr_NormalizeException(&type, &value, &traceback); tracebackModule = PyImport_ImportModule("traceback"); if (tracebackModule != NULL) { diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index d1be996d5e2..837014cae8c 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -37,6 +37,7 @@ static void PyErrorHandler() char* error_string; PyErr_Fetch(&type, &value, &traceback); + PyErr_NormalizeException(&type, &value, &traceback); tracebackModule = PyImport_ImportModule("traceback"); if (tracebackModule != NULL) { @@ -47,7 +48,8 @@ static void PyErrorHandler() (char*)"OOO", type, value == NULL ? Py_None : value, traceback == NULL ? Py_None : traceback); - emptyString = PyString_FromString(""); + // emptyString = PyString_FromString(""); + emptyString = PyUnicode_FromString(""); strRetval = PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); diff --git a/core/src/plugins/python_plugins_common.inc b/core/src/plugins/python_plugins_common.inc index 180ee9d7c1c..a34bc3e80bb 100644 --- a/core/src/plugins/python_plugins_common.inc +++ b/core/src/plugins/python_plugins_common.inc @@ -91,6 +91,7 @@ static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype) char* error_string; PyErr_Fetch(&type, &value, &traceback); + PyErr_NormalizeException(&type, &value, &traceback); tracebackModule = PyImport_ImportModule("traceback"); if (tracebackModule != NULL) { diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index 6aa688c9b51..0d1969ab918 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -154,6 +154,7 @@ static void PyErrorHandler() char* error_string; PyErr_Fetch(&type, &value, &traceback); + PyErr_NormalizeException(&type, &value, &traceback); tracebackModule = PyImport_ImportModule("traceback"); if (tracebackModule != NULL) { diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in index 6c79a1eadee..0e1211e40b6 100644 --- a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in +++ b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in @@ -5,6 +5,6 @@ FileSet { Options { signature = MD5 } - Plugin = "python:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-local-fileset-with-restoreobjects:filename=@tmpdir@/file-list" + Plugin = "python:module_path=@python_plugin_module_src_test_dir@:module_name=bareos_fd_local_fileset_with_restoreobjects:filename=@tmpdir@/file_list" } } diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/bareos-fd-local-fileset-with-restoreobjects.py b/systemtests/tests/pyplug-fd-local-fileset/python-modules/bareos_fd_local_fileset_with_restoreobjects.py similarity index 97% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/bareos-fd-local-fileset-with-restoreobjects.py rename to systemtests/tests/pyplug-fd-local-fileset/python-modules/bareos_fd_local_fileset_with_restoreobjects.py index 4385cf5ea1c..9da5a32dd1e 100644 --- a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/bareos-fd-local-fileset-with-restoreobjects.py +++ b/systemtests/tests/pyplug-fd-local-fileset/python-modules/bareos_fd_local_fileset_with_restoreobjects.py @@ -19,7 +19,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. # -# bareos-fd-local-fileset-with-restoreobjects.py is a python Bareos FD Plugin using +# bareos_fd_local_fileset_with_restoreobjects.py is a python Bareos FD Plugin using # BareosFdPluginLocalFilesetWithRestoreObjects which was made for automated testing # purposes. # From 6b04079501263e870f0da1920f9ea78c8df85eea Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 15 May 2020 10:11:04 +0200 Subject: [PATCH 106/341] python: bareosfd-python-module passes --- core/src/filed/fd_plugins.cc | 2 +- core/src/plugins/dird/python/python-dir.cc | 3 +- core/src/plugins/filed/python/bareosfd.cc | 72 +++++++++---------- core/src/plugins/filed/python/python-fd.cc | 10 +-- .../filed/python/test/bareosfd_test.py | 39 +++++----- core/src/plugins/python_plugins_common.inc | 3 +- core/src/plugins/stored/python/python-sd.cc | 3 +- 7 files changed, 64 insertions(+), 68 deletions(-) diff --git a/core/src/filed/fd_plugins.cc b/core/src/filed/fd_plugins.cc index a763ce8020f..57e6b13706a 100644 --- a/core/src/filed/fd_plugins.cc +++ b/core/src/filed/fd_plugins.cc @@ -2538,7 +2538,7 @@ static bRC bareosCheckChanges(PluginContext* ctx, struct save_pkt* sp) ff_pkt = jcr->impl->ff; /* * Copy fname and link because SaveFile() zaps them. - * This avoids zaping the plugin's strings. + * This avoids zapping the plugin's strings. */ ff_pkt->type = sp->type; if (!sp->fname) { diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index 2bb6b1efa01..961d77a666c 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -165,7 +165,8 @@ static void PyErrorHandler() (char*)"OOO", type, value == NULL ? Py_None : value, traceback == NULL ? Py_None : traceback); - emptyString = PyString_FromString(""); + // emptyString = PyString_FromString(""); + emptyString = PyUnicode_FromString(""); strRetval = PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 1636ae3fc1f..de6bdbe58db 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -124,7 +124,8 @@ static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value) if (pFunc && PyCallable_Check(pFunc)) { PyObject *pPluginDefinition, *pRetVal; - pPluginDefinition = PyString_FromString((char*)value); + // pPluginDefinition = PyString_FromString((char*)value); + pPluginDefinition = PyUnicode_FromString((char*)value); if (!pPluginDefinition) { goto bail_out; } pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); @@ -252,21 +253,8 @@ static inline PySavePacket* NativeToPySavePacket(struct save_pkt* sp) PySavePacket* pSavePkt = PyObject_New(PySavePacket, &PySavePacketType); if (pSavePkt) { - /* - * Initialize the Python SavePkt with the data we got passed in. - */ - if (sp->fname) { - pSavePkt->fname = PyString_FromString(sp->fname); - } else { - pSavePkt->fname = NULL; - } - - if (sp->link) { - pSavePkt->link = PyString_FromString(sp->link); - } else { - pSavePkt->link = NULL; - } - + pSavePkt->fname = PyUnicode_FromString(sp->fname ? sp->fname : ""); + pSavePkt->link = PyUnicode_FromString(sp->link ? sp->link : ""); if (sp->statp.st_mode) { pSavePkt->statp = (PyObject*)NativeToPyStatPacket(&sp->statp); } else { @@ -289,7 +277,7 @@ static inline PySavePacket* NativeToPySavePacket(struct save_pkt* sp) } return pSavePkt; -} +} // namespace filedaemon static inline bool PySavePacketToNative( PySavePacket* pSavePkt, @@ -309,9 +297,9 @@ static inline bool PySavePacketToNative( * As this has to linger as long as the backup is running we save it in * our plugin context. */ - if (PyString_Check(pSavePkt->fname)) { + if (PyUnicode_Check(pSavePkt->fname)) { if (plugin_priv_ctx->fname) { free(plugin_priv_ctx->fname); } - plugin_priv_ctx->fname = strdup(PyString_AsString(pSavePkt->fname)); + plugin_priv_ctx->fname = strdup(PyUnicode_AsUTF8(pSavePkt->fname)); sp->fname = plugin_priv_ctx->fname; } } else { @@ -328,7 +316,7 @@ static inline bool PySavePacketToNative( */ if (PyString_Check(pSavePkt->link)) { if (plugin_priv_ctx->link) { free(plugin_priv_ctx->link); } - plugin_priv_ctx->link = strdup(PyString_AsString(pSavePkt->link)); + plugin_priv_ctx->link = strdup(PyUnicode_AsUTF8(pSavePkt->link)); sp->link = plugin_priv_ctx->link; } } @@ -381,7 +369,7 @@ static inline bool PySavePacketToNative( free(plugin_priv_ctx->object_name); } plugin_priv_ctx->object_name = - strdup(PyString_AsString(pSavePkt->object_name)); + strdup(PyUnicode_AsUTF8(pSavePkt->object_name)); sp->object_name = plugin_priv_ctx->object_name; sp->object_len = pSavePkt->object_len; @@ -667,7 +655,7 @@ static bRC PyStartRestoreFile(PluginContext* plugin_ctx, const char* cmd) if (pFunc && PyCallable_Check(pFunc)) { PyObject *pCmd, *pRetVal; - pCmd = PyString_FromString(cmd); + pCmd = PyUnicode_FromString(cmd); if (!pCmd) { goto bail_out; } pRetVal = PyObject_CallFunctionObjArgs(pFunc, pCmd, NULL); @@ -882,7 +870,7 @@ static bRC PyCheckFile(PluginContext* plugin_ctx, char* fname) if (pFunc && PyCallable_Check(pFunc)) { PyObject *pFname, *pRetVal; - pFname = PyString_FromString(fname); + pFname = PyUnicode_FromString(fname); pRetVal = PyObject_CallFunctionObjArgs(pFunc, pFname, NULL); Py_DECREF(pFname); @@ -1328,7 +1316,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) if (bareos_core_functions->getBareosValue(plugin_ctx, (bVariable)var, &value) == bRC_OK) { - if (value) { pRetVal = PyString_FromString(value); } + if (value) { pRetVal = PyUnicode_FromString(value); } } break; } @@ -1356,7 +1344,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) if (bareos_core_functions->getBareosValue(plugin_ctx, (bVariable)var, &value) == bRC_OK) { - if (value) { pRetVal = PyString_FromString(value); } + if (value) { pRetVal = PyUnicode_FromString(value); } } break; } @@ -1405,7 +1393,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) break; } case bVarFileSeen: { - const char* value = PyString_AsString(pyValue); + const char* value = PyUnicode_AsUTF8(pyValue); if (value) { retval = bareos_core_functions->setBareosValue( plugin_ctx, (bVariable)var, @@ -1757,7 +1745,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) sp.type = pSavePkt->type; if (pSavePkt->fname) { if (PyString_Check(pSavePkt->fname)) { - sp.fname = const_cast(PyString_AsString(pSavePkt->fname)); + sp.fname = const_cast(PyUnicode_AsUTF8(pSavePkt->fname)); } else { goto bail_out; } @@ -1766,7 +1754,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) } if (pSavePkt->link) { if (PyString_Check(pSavePkt->link)) { - sp.link = const_cast(PyString_AsString(pSavePkt->link)); + sp.link = const_cast(PyUnicode_AsUTF8(pSavePkt->link)); } else { goto bail_out; } @@ -1808,7 +1796,7 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) */ if (pSavePkt->fname) { if (PyString_Check(pSavePkt->fname)) { - sp.fname = const_cast(PyString_AsString(pSavePkt->fname)); + sp.fname = const_cast(PyUnicode_AsUTF8(pSavePkt->fname)); } else { goto bail_out; } @@ -1884,7 +1872,7 @@ static inline char* PyGetStringValue(PyObject* object) { if (!object || !PyString_Check(object)) { return (char*)""; } - return const_cast(PyString_AsString(object)); + return const_cast(PyUnicode_AsUTF8(object)); } static inline char* PyGetByteArrayValue(PyObject* object) @@ -1914,7 +1902,7 @@ static PyObject* PyRestoreObject_repr(PyRestoreObject* self) self->plugin_name, self->object_type, self->object_len, self->object_full_len, self->object_index, self->object_compression, self->stream, self->JobId); - s = PyString_FromString(buf.c_str()); + s = PyUnicode_FromString(buf.c_str()); return s; } @@ -1990,7 +1978,7 @@ static PyObject* PyStatPacket_repr(PyStatPacket* self) self->gid, self->rdev, self->size, self->atime, self->mtime, self->ctime, self->blksize, self->blocks); - s = PyString_FromString(buf.c_str()); + s = PyUnicode_FromString(buf.c_str()); return s; } @@ -2090,7 +2078,7 @@ static PyObject* PySavePacket_repr(PySavePacket* self) PyGetStringValue(self->object_name), PyGetByteArrayValue(self->object), self->object_len, self->object_index); - s = PyString_FromString(buf.c_str()); + s = PyUnicode_FromString(buf.c_str()); return s; } @@ -2106,7 +2094,6 @@ static int PySavePacket_init(PySavePacket* self, PyObject* args, PyObject* kwds) (char*)"accurate_found", (char*)"cmd", (char*)"save_time", (char*)"delta_seq", (char*)"object_name", (char*)"object", (char*)"object_len", (char*)"object_index", NULL}; - self->fname = NULL; self->link = NULL; self->type = 0; @@ -2122,15 +2109,20 @@ static int PySavePacket_init(PySavePacket* self, PyObject* args, PyObject* kwds) self->object_len = 0; self->object_index = 0; + if (!PyArg_ParseTupleAndKeywords( - args, kwds, "|ooiocccsiiooii", kwlist, &self->fname, &self->link, + args, kwds, "|OOiOpppsiiOOii", kwlist, &self->fname, &self->link, &self->type, &self->flags, &self->no_read, &self->portable, &self->accurate_found, &self->cmd, &self->save_time, &self->delta_seq, &self->object_name, &self->object, &self->object_len, &self->object_index)) { + // if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, + // &self->fname)) { return -1; } - + int a; + a = a + a; + printf("hello\n"); return 0; } @@ -2170,7 +2162,7 @@ static PyObject* PyRestorePacket_repr(PyRestorePacket* self) self->ofname, self->olname, self->where, self->RegexWhere, self->replace, self->create_status); - s = PyString_FromString(buf.c_str()); + s = PyUnicode_FromString(buf.c_str()); Py_DECREF(stat_repr); return s; @@ -2244,7 +2236,7 @@ static PyObject* PyIoPacket_repr(PyIoPacket* self) self->func, self->count, self->flags, (self->mode & ~S_IFMT), PyGetByteArrayValue(self->buf), self->fname, self->status, self->io_errno, self->lerror, self->whence, self->offset, self->win32); - s = PyString_FromString(buf.c_str()); + s = PyUnicode_FromString(buf.c_str()); return s; } @@ -2315,7 +2307,7 @@ static PyObject* PyAclPacket_repr(PyAclPacket* self) Mmsg(buf, "AclPacket(fname=\"%s\", content=\"%s\")", self->fname, PyGetByteArrayValue(self->content)); - s = PyString_FromString(buf.c_str()); + s = PyUnicode_FromString(buf.c_str()); return s; } @@ -2361,7 +2353,7 @@ static PyObject* PyXattrPacket_repr(PyXattrPacket* self) Mmsg(buf, "XattrPacket(fname=\"%s\", name=\"%s\", value=\"%s\")", self->fname, PyGetByteArrayValue(self->name), PyGetByteArrayValue(self->value)); - s = PyString_FromString(buf.c_str()); + s = PyUnicode_FromString(buf.c_str()); return s; } diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 7ba777846d1..0e9715d2df2 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -141,7 +141,8 @@ static void PyErrorHandler() (char*)"OOO", type, value == NULL ? Py_None : value, traceback == NULL ? Py_None : traceback); - emptyString = PyString_FromString(""); + // emptyString = PyString_FromString(""); + emptyString = PyUnicode_FromString(""); strRetval = PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); @@ -955,7 +956,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) /* Extend the Python search path with the given module_path. */ if (plugin_priv_ctx->module_path) { sysPath = PySys_GetObject((char*)"path"); - mPath = PyString_FromString(plugin_priv_ctx->module_path); + mPath = PyUnicode_FromString(plugin_priv_ctx->module_path); PyList_Append(sysPath, mPath); Py_DECREF(mPath); plugin_priv_ctx->python_path_set = true; @@ -967,7 +968,8 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) Dmsg(plugin_ctx, debuglevel, "python-fd: Trying to load module with name %s\n", plugin_priv_ctx->module_name); - pName = PyString_FromString(plugin_priv_ctx->module_name); + // pName = PyString_FromString(plugin_priv_ctx->module_name); + pName = PyUnicode_FromString(plugin_priv_ctx->module_name); plugin_priv_ctx->pModule = PyImport_Import(pName); Py_DECREF(pName); @@ -994,7 +996,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) if (pFunc && PyCallable_Check(pFunc)) { PyObject *pPluginDefinition, *pRetVal; - pPluginDefinition = PyString_FromString((char*)value); + pPluginDefinition = PyUnicode_FromString((char*)value); if (!pPluginDefinition) { goto bail_out; } pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); diff --git a/core/src/plugins/filed/python/test/bareosfd_test.py b/core/src/plugins/filed/python/test/bareosfd_test.py index e8decefe536..c39c9d4c091 100644 --- a/core/src/plugins/filed/python/test/bareosfd_test.py +++ b/core/src/plugins/filed/python/test/bareosfd_test.py @@ -17,7 +17,7 @@ class TestBareosFd(unittest.TestCase): def test_ModuleDicts(self): - help (bareosfd) + #help (bareosfd) print (bareosfd.bCFs) print (bareosfd.CF_ERROR) @@ -31,10 +31,10 @@ def test_ModuleDicts(self): # bRCs # bVariable - def test_bJobMessageType(self): - # bareosfd.DebugMessage( bareosfd.bJobMessageType['M_INFO'], "This is a Job message") - self.assertEqual(str(bareosfd.bJobMessageType), """{'M_MOUNT': 10L, 'M_SECURITY': 14L, 'M_DEBUG': 2L, 'M_WARNING': 5L, 'M_SAVED': 7L, 'M_TERM': 12L, 'M_ABORT': 1L, 'M_INFO': 6L, 'M_ERROR': 4L, 'M_FATAL': 3L, 'M_NOTSAVED': 8L, 'M_RESTORED': 13L, 'M_ERROR_TERM': 11L, 'M_ALERT': 15L, 'M_VOLMGMT': 16L, 'M_SKIPPED': 9L}""" -) + # def test_bJobMessageType(self): + # # bareosfd.DebugMessage( bareosfd.bJobMessageType['M_INFO'], "This is a Job message") + # self.assertEqual(str(bareosfd.bJobMessageType), """{'M_MOUNT': 10L, 'M_SECURITY': 14L, 'M_DEBUG': 2L, 'M_WARNING': 5L, 'M_SAVED': 7L, 'M_TERM': 12L, 'M_ABORT': 1L, 'M_INFO': 6L, 'M_ERROR': 4L, 'M_FATAL': 3L, 'M_NOTSAVED': 8L, 'M_RESTORED': 13L, 'M_ERROR_TERM': 11L, 'M_ALERT': 15L, 'M_VOLMGMT': 16L, 'M_SKIPPED': 9L}""" +# ) # def test_SetValue(self): # self.assertRaises(RuntimeError, bareosfd.SetValue, 2) @@ -48,19 +48,18 @@ def test_RestoreObject(self): 'RestoreObject(object_name="", object="", plugin_name="", object_type=0, object_len=0, object_full_len=0, object_index=0, object_compression=0, stream=0, jobid=0)', str(test_RestoreObject), ) - - #r2 = bareosfd.RestoreObject() - #r2.object_name="this is a very long object name" - #r2.object="123456780" - ##r2.plugin_name="this is a plugin name" - #r2.object_type=3 - #r2.object_len=111111 - #r2.object_full_len=11111111 - #r2.object_index=1234 - #r2.object_compression=1 - #r2.stream=4 - #r2.jobid=123123 - #print (r2) + r2 = bareosfd.RestoreObject() + r2.object_name="this is a very long object name" + r2.object="123456780" + #r2.plugin_name="this is a plugin name" + r2.object_type=3 + r2.object_len=111111 + r2.object_full_len=11111111 + r2.object_index=1234 + r2.object_compression=1 + r2.stream=4 + r2.jobid=123123 + print (r2) #self.assertEqual( # 'RestoreObject(object_name="this is a very long object name", object="", plugin_name="", object_type=3, object_len=111111, object_full_len=11111111, object_index=1234, object_compression=1, stream=4, jobid=123123)', # str(test_RestoreObject), @@ -89,9 +88,9 @@ def test_StatPacket(self): self.assertEqual('StatPacket(dev=0, ino=0, mode=0700, nlink=0, uid=0, gid=0, rdev=0, size=-1, atime=1, mtime=1, ctime=1, blksize=4096, blocks=1)', str(sp2)) def test_SavePacket(self): - test_SavePacket = bareosfd.SavePacket() + test_SavePacket = bareosfd.SavePacket(fname="testfilename") self.assertEqual( - 'SavePacket(fname="", link="", type=0, flags=, no_read=0, portable=0, accurate_found=0, cmd="", save_time=0, delta_seq=0, object_name="", object="", object_len=0, object_index=0)', + 'SavePacket(fname="testfilename", link="", type=0, flags=, no_read=0, portable=0, accurate_found=0, cmd="", save_time=0, delta_seq=0, object_name="", object="", object_len=0, object_index=0)', str(test_SavePacket), ) diff --git a/core/src/plugins/python_plugins_common.inc b/core/src/plugins/python_plugins_common.inc index a34bc3e80bb..79340b2d42f 100644 --- a/core/src/plugins/python_plugins_common.inc +++ b/core/src/plugins/python_plugins_common.inc @@ -102,7 +102,8 @@ static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype) (char*)"OOO", type, value == NULL ? Py_None : value, traceback == NULL ? Py_None : traceback); - emptyString = PyString_FromString(""); + // emptyString = PyString_FromString(""); + emptyString = PyUnicode_FromString(""); strRetval = PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index 0d1969ab918..8f50c793a17 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -165,7 +165,8 @@ static void PyErrorHandler() (char*)"OOO", type, value == NULL ? Py_None : value, traceback == NULL ? Py_None : traceback); - emptyString = PyString_FromString(""); + // emptyString = PyString_FromString(""); + emptyString = PyUnicode_FromString(""); strRetval = PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); From 9696274124273f42caca3b574d3fee9a61a2fcf3 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 15 May 2020 13:24:30 +0200 Subject: [PATCH 107/341] python: python-fd-plugin-local-fileset-test works on python3 --- core/src/plugins/filed/python/bareosfd.cc | 3 +- .../bareos-dir.d/fileset/PluginTest.conf.in | 2 +- ...sFdPluginLocalFilesetWithRestoreObjects.py | 73 ++++++++----------- 3 files changed, 34 insertions(+), 44 deletions(-) diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index de6bdbe58db..2dc7f42198c 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -1184,7 +1184,8 @@ static inline PyRestoreObject* NativeToPyRestoreObject( PyObject_New(PyRestoreObject, &PyRestoreObjectType); if (pRestoreObject) { - pRestoreObject->object_name = PyString_FromString(rop->object_name); + // pRestoreObject->object_name = PyString_FromString(rop->object_name); + pRestoreObject->object_name = PyUnicode_FromString(rop->object_name); pRestoreObject->object = PyByteArray_FromStringAndSize(rop->object, rop->object_len); pRestoreObject->plugin_name = rop->plugin_name; diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in index 0e1211e40b6..05b0219b9a8 100644 --- a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in +++ b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in @@ -5,6 +5,6 @@ FileSet { Options { signature = MD5 } - Plugin = "python:module_path=@python_plugin_module_src_test_dir@:module_name=bareos_fd_local_fileset_with_restoreobjects:filename=@tmpdir@/file_list" + Plugin = "python:module_path=@python_plugin_module_src_test_dir@:module_name=bareos_fd_local_fileset_with_restoreobjects:filename=@tmpdir@/file-list" } } diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py index 972845cfd95..671d7f5ed19 100644 --- a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py +++ b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py @@ -89,12 +89,9 @@ def filename_is_allowed(self, filename, allowregex, denyregex): else: denied = True if not allowed or denied: - bareosfd.DebugMessage( - 100, "File %s denied by configuration\n" % (filename) - ) + bareosfd.DebugMessage(100, "File %s denied by configuration\n" % (filename)) bareosfd.JobMessage( - M_ERROR, - "File %s denied by configuration\n" % (filename), + M_ERROR, "File %s denied by configuration\n" % (filename), ) return False else: @@ -108,16 +105,15 @@ def start_backup_job(self): """ bareosfd.DebugMessage( - 100, - "Using %s to search for local files\n" % (self.options["filename"]), + 100, "Using %s to search for local files\n" % (self.options["filename"]), ) if os.path.exists(self.options["filename"]): try: - config_file = open(self.options["filename"], "rb") + config_file = open(self.options["filename"], "r") + #config_file = open(self.options["filename"], "rb") except: bareosfd.DebugMessage( - 100, - "Could not open file %s\n" % (self.options["filename"]), + 100, "Could not open file %s\n" % (self.options["filename"]), ) return bRC_Error else: @@ -140,9 +136,7 @@ def start_backup_job(self): for topdir, dirNames, fileNames in os.walk(listItem): for fileName in fileNames: if self.filename_is_allowed( - os.path.join(topdir, fileName), - self.allow, - self.deny, + os.path.join(topdir, fileName), self.allow, self.deny, ): self.files_to_backup.append(os.path.join(topdir, fileName)) if os.path.isfile(os.path.join(topdir, fileName)): @@ -164,8 +158,7 @@ def start_backup_job(self): if not self.files_to_backup: bareosfd.JobMessage( - M_ERROR, - "No (allowed) files to backup found\n", + M_ERROR, "No (allowed) files to backup found\n", ) return bRC_Error else: @@ -182,7 +175,6 @@ def start_backup_file(self, savepkt): return bRC_Skip file_to_backup = self.files_to_backup.pop() - bareosfd.DebugMessage(100, "file: " + file_to_backup + "\n") statp = bareosfd.StatPacket() savepkt.statp = statp @@ -192,7 +184,7 @@ def start_backup_file(self, savepkt): savepkt.type = FT_RESTORE_FIRST savepkt.fname = file_to_backup savepkt.object_name = file_to_backup - savepkt.object = bytearray(checksum) + savepkt.object = bytearray(checksum.encode("utf-8")) savepkt.object_len = len(savepkt.object) savepkt.object_index = self.object_index_seq self.object_index_seq += 1 @@ -201,7 +193,8 @@ def start_backup_file(self, savepkt): savepkt.type = FT_RESTORE_FIRST savepkt.fname = file_to_backup savepkt.object_name = file_to_backup - savepkt.object = bytearray(os.path.splitext(file_to_backup)[0]) + savepkt.object = bytearray(os.path.splitext(file_to_backup)[0].encode("utf-8")) + savepkt.object_len = len(savepkt.object) savepkt.object_index = self.object_index_seq self.object_index_seq += 1 @@ -211,7 +204,7 @@ def start_backup_file(self, savepkt): savepkt.type = FT_RESTORE_FIRST savepkt.fname = file_to_backup savepkt.object_name = file_to_backup - savepkt.object = bytearray("a" * teststring_length) + savepkt.object = bytearray(b"a" * teststring_length) savepkt.object_len = len(savepkt.object) savepkt.object_index = self.object_index_seq self.object_index_seq += 1 @@ -221,8 +214,7 @@ def start_backup_file(self, savepkt): savepkt.type = FT_REG bareosfd.JobMessage( - M_INFO, - "Starting backup of %s\n" % (file_to_backup), + M_INFO, "Starting backup of {}\n" .format(file_to_backup), ) return bRC_OK @@ -231,9 +223,7 @@ def end_backup_file(self): Here we return 'bRC_More' as long as our list files_to_backup is not empty and bRC_OK when we are done """ - bareosfd.DebugMessage( - 100, "end_backup_file() entry point in Python called\n" - ) + bareosfd.DebugMessage(100, "end_backup_file() entry point in Python called\n") if self.files_to_backup: return bRC_More else: @@ -247,9 +237,13 @@ def set_file_attributes(self, restorepkt): ) orig_fname = "/" + os.path.relpath(restorepkt.ofname, restorepkt.where) + bareosfd.DebugMessage( + 100, + "set_file_attributes() orig_fname: {} \n".format (orig_fname) + ) restoreobject_sha256sum = self.sha256sums_by_filename[orig_fname] - file_sha256sum = self.get_sha256sum(orig_fname) + file_sha256sum = self.get_sha256sum(orig_fname).encode('utf-8') bareosfd.DebugMessage( 100, "set_file_attributes() orig_fname: %s restoreobject_sha256sum: %s file_sha256sum: %s\n" @@ -265,9 +259,7 @@ def set_file_attributes(self, restorepkt): return bRC_OK def end_restore_file(self): - bareosfd.DebugMessage( - 100, "end_restore_file() self.FNAME: %s\n" % self.FNAME - ) + bareosfd.DebugMessage(100, "end_restore_file() self.FNAME: %s\n" % self.FNAME) return bRC_OK def restore_object_data(self, ROP): @@ -286,16 +278,13 @@ def restore_object_data(self, ROP): % (ROP), ) bareosfd.DebugMessage( - 100, - "ROP.object_name(%s): %s\n" % (type(ROP.object_name), ROP.object_name), + 100, "ROP.object_name(%s): %s\n" % (type(ROP.object_name), ROP.object_name), ) bareosfd.DebugMessage( - 100, - "ROP.plugin_name(%s): %s\n" % (type(ROP.plugin_name), ROP.plugin_name), + 100, "ROP.plugin_name(%s): %s\n" % (type(ROP.plugin_name), ROP.plugin_name), ) bareosfd.DebugMessage( - 100, - "ROP.object_len(%s): %s\n" % (type(ROP.object_len), ROP.object_len), + 100, "ROP.object_len(%s): %s\n" % (type(ROP.object_len), ROP.object_len), ) bareosfd.DebugMessage( 100, @@ -307,26 +296,26 @@ def restore_object_data(self, ROP): ) orig_filename = os.path.splitext(ROP.object_name)[0] if ROP.object_name.endswith(".sha256sum"): - self.sha256sums_by_filename[orig_filename] = str(ROP.object) + self.sha256sums_by_filename[orig_filename] = ROP.object + #self.sha256sums_by_filename[orig_filename] = str(ROP.object) elif ROP.object_name.endswith(".abspath"): - if str(ROP.object) != orig_filename: + if ROP.object.decode() != orig_filename: bareosfd.JobMessage( M_ERROR, "bad restoreobject orig_fname: %s restoreobject_fname: %s\n" - % (orig_filename, repr(str(ROP.object))), + % (orig_filename, ROP.object.decode()), ) elif ROP.object_name.endswith(".longrestoreobject"): stored_length = int(os.path.splitext(ROP.object_name)[0]) - if str(ROP.object) != "a" * stored_length: + if ROP.object.decode() != "a" * stored_length: bareosfd.JobMessage( M_ERROR, - "bad long restoreobject %s does not match stored object\n" - % (ROP.object_name), + "bad long restoreobject {} does not match stored object: {}, {}\n" + .format (ROP.object_name, ROP.object.decode(), "a" * stored_length), ) else: bareosfd.DebugMessage( - 100, - "not checking restoreobject: %s\n" % (type(ROP.object_name)), + 100, "not checking restoreobject: %s\n" % (type(ROP.object_name)), ) return bRC_OK From 4b88ba66d02fa48f417e93076c476aeec67b8470 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 15 May 2020 14:20:28 +0200 Subject: [PATCH 108/341] python-fd: build plugins for py2 and py3 --- core/CMakeLists.txt | 8 +- core/cmake/BareosFindAllLibraries.cmake | 3 + core/src/plugins/filed/CMakeLists.txt | 105 +++++++++++++++++++----- 3 files changed, 95 insertions(+), 21 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index a1e5b0b7d83..bc4740620b4 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -868,7 +868,13 @@ message( " CEPHFS support: ${CEPHFS_FOUND} ${CEPHFS_LIBRARIES} ${CEPHFS_INCLUDE_DIRS} " ) message( - " Python support: ${Python_FOUND} ${Python_VERSION} ${Python_INCLUDE_DIRS}" + " Python support: ${Python_FOUND} ${Python_VERSION} ${Python_INCLUDE_DIRS} ${Python_EXECUTABLE}" +) +message( + " Python2 support: ${Python2_FOUND} ${Python2_VERSION} ${Python2_INCLUDE_DIRS} ${Python2_EXECUTABLE}" +) +message( + " Python3 support: ${Python3_FOUND} ${Python3_VERSION} ${Python3_INCLUDE_DIRS} ${Python3_EXECUTABLE}" ) message(" systemd support: ${WITH_SYSTEMD} ${SYSTEMD_UNITDIR}") message(" Batch insert enabled: ${USE_BATCH_FILE_INSERT}") diff --git a/core/cmake/BareosFindAllLibraries.cmake b/core/cmake/BareosFindAllLibraries.cmake index 9bf1d0ff3a1..876919ec55a 100644 --- a/core/cmake/BareosFindAllLibraries.cmake +++ b/core/cmake/BareosFindAllLibraries.cmake @@ -27,6 +27,9 @@ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") if(${Python_FOUND}) set(HAVE_PYTHON 1) endif() + find_package (Python2 COMPONENTS Interpreter Development) + find_package (Python3 COMPONENTS Interpreter Development) + endif() diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index dda1acc09b9..ce057e0f537 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -94,7 +94,7 @@ if(NOT HAVE_WIN32) set_target_properties(example-plugin-fd PROPERTIES PREFIX "") endif() -if(HAVE_PYTHON) +if(Python2_FOUND) add_library(python-fd MODULE python/python-fd.cc) set_target_properties(python-fd PROPERTIES PREFIX "") install( @@ -102,50 +102,115 @@ if(HAVE_PYTHON) DESTINATION ${plugindir} COMPONENT filedaemon ) - target_link_libraries(python-fd ${Python_LIBRARIES} bareos) - add_dependencies(python-fd bareosfd-pymod) + target_link_libraries(python-fd ${Python3_LIBRARIES} bareos) + add_dependencies(python-fd bareosfd-pymod2) endif() -if(HAVE_PYTHON AND NOT HAVE_WIN32) - add_executable(bareos-fd-module-tester python/test/python-fd-module-tester.cc) - target_link_libraries(bareos-fd-module-tester ${Python_LIBRARIES} bareos) +if(Python3_FOUND) + add_library(python3-fd MODULE python/python-fd.cc) + set_target_properties(python3-fd PROPERTIES PREFIX "") + install( + TARGETS python3-fd + DESTINATION ${plugindir} + COMPONENT filedaemon + ) + target_link_libraries(python3-fd ${Python3_LIBRARIES} bareos) + add_dependencies(python3-fd bareosfd-pymod3) +endif() - add_test(NAME bareosfd-python-module-tester - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bareos-fd-module-tester +if(Python2_FOUND AND NOT HAVE_WIN22) + add_executable( + bareosfd-python2-module-tester python/test/python-fd-module-tester.cc + ) + target_link_libraries( + bareosfd-python2-module-tester ${Python2_LIBRARIES} bareos + ) + + add_test(NAME bareosfd-python2-module-tester + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bareosfd-python2-module-tester ) set_property( - TEST bareosfd-python-module-tester + TEST bareosfd-python2-module-tester PROPERTY ENVIRONMENT PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/python/test/:${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/pyfiles ) +endif() + +if(Python3_FOUND AND NOT HAVE_WIN32) + add_executable( + bareosfd-python3-module-tester python/test/python-fd-module-tester.cc + ) + target_link_libraries( + bareosfd-python3-module-tester ${Python3_LIBRARIES} bareos + ) + add_test(NAME bareosfd-python3-module-tester + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bareosfd-python3-module-tester + ) + set_property( + TEST bareosfd-python3-module-tester + PROPERTY + ENVIRONMENT + PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/python/test/:${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/pyfiles + ) endif() -if(HAVE_PYTHON AND NOT HAVE_WIN32) - configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) +if(Python2_FOUND AND NOT HAVE_WIN22) + configure_file( + python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup_py2.py + ) add_custom_command( OUTPUT pythonmodules/bareosfd.so MAIN_DEPENDENCY ./python/bareosfd.cc DEPENDS ./python/bareosfd.h DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup_py2.py COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python_EXECUTABLE} python/setup.py build - COMMAND ${Python_EXECUTABLE} python/setup.py install --install-lib + COMMAND ${Python_EXECUTABLE} python/setup_py2.py build + COMMAND ${Python_EXECUTABLE} python/setup_py2.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build - COMMENT "building python module pythonmodules/bareosfd.so" + COMMENT "building python2 module pythonmodules/bareosfd.so" ) + add_custom_target(bareosfd-pymod2 DEPENDS pythonmodules/bareosfd.so) + add_test(NAME bareosfd-python2-module + COMMAND ${Python2_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosfd_test.py + ) + set_property( + TEST bareosfd-python2-module + PROPERTY + ENVIRONMENT + "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" + LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib + ) +endif() - add_custom_target(bareosfd-pymod DEPENDS pythonmodules/bareosfd.so) - - add_test(NAME bareosfd-python-module - COMMAND ${Python_EXECUTABLE} +if(Python3_FOUND AND NOT HAVE_WIN32) + configure_file( + python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup_py3.py + ) + add_custom_command( + OUTPUT pythonmodules/bareosfd.so + MAIN_DEPENDENCY ./python/bareosfd.cc + DEPENDS ./python/bareosfd.h + DEPENDS bareos + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup_py3.py + COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build + COMMAND ${Python_EXECUTABLE} python/setup_py3.py build + COMMAND ${Python_EXECUTABLE} python/setup_py3.py install --install-lib + ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build + COMMENT "building python3 module pythonmodules/bareosfd.so" + ) + add_custom_target(bareosfd-pymod3 DEPENDS pythonmodules/bareosfd.so) + add_test(NAME bareosfd-python3-module + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosfd_test.py ) set_property( - TEST bareosfd-python-module + TEST bareosfd-python3-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" From 81691213b4b61e9c30dfd59ee284df04119e3dfc Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 15 May 2020 15:43:45 +0200 Subject: [PATCH 109/341] python-fd: bareosfd builds for both python2 and 3 --- core/CMakeLists.txt | 4 +- core/src/plugins/dird/CMakeLists.txt | 4 +- core/src/plugins/dird/python/bareosdir.cc | 40 +++++++++---------- core/src/plugins/dird/python/python-dir.cc | 10 ++--- core/src/plugins/filed/CMakeLists.txt | 20 +++++++--- core/src/plugins/filed/python/bareosfd.cc | 24 +++++------ core/src/plugins/filed/python/python-fd.cc | 2 +- .../python/test/python-fd-module-tester.cc | 6 +-- core/src/plugins/python3compat.h | 19 +++++---- core/src/plugins/python_plugins_common.inc | 6 +-- core/src/plugins/stored/CMakeLists.txt | 3 +- core/src/plugins/stored/python/bareossd.cc | 20 +++++----- core/src/plugins/stored/python/python-sd.cc | 10 ++--- 13 files changed, 92 insertions(+), 76 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index bc4740620b4..db4c7886d36 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -408,9 +408,9 @@ include(BareosDetermineHaveLowLevelScsiInterface) include(acltypes) -include_directories(SYSTEM ${Python_INCLUDE_DIRS}) +# include_directories(SYSTEM ${Python_INCLUDE_DIRS}) -include_directories(SYSTEM ${Python_INCLUDE_PATH}) +# include_directories(SYSTEM ${Python_INCLUDE_PATH}) include_directories(${PROJECT_SOURCE_DIR}/src) diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index ac75df5747c..783c282ef65 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -30,7 +30,9 @@ if(HAVE_WIN32) add_definitions(-DMS_WIN${WINDOWS_BITS}) endif() -if(HAVE_PYTHON) +if(Python2_FOUND) + include_directories(SYSTEM ${Python2_INCLUDE_DIRS}) + add_library(python-dir MODULE python/python-dir.cc) # do not prefix with "lib" set_target_properties(python-dir PROPERTIES PREFIX "") diff --git a/core/src/plugins/dird/python/bareosdir.cc b/core/src/plugins/dird/python/bareosdir.cc index 6ac98130280..3b35ccd8063 100644 --- a/core/src/plugins/dird/python/bareosdir.cc +++ b/core/src/plugins/dird/python/bareosdir.cc @@ -108,7 +108,7 @@ static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value) if (pFunc && PyCallable_Check(pFunc)) { PyObject *pPluginDefinition, *pRetVal; - pPluginDefinition = PyString_FromString((char*)value); + pPluginDefinition = PyUnicode_FromString((char*)value); if (!pPluginDefinition) { goto bail_out; } pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); @@ -166,7 +166,7 @@ static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, if (pFunc && PyCallable_Check(pFunc)) { PyObject *pEventType, *pRetVal; - pEventType = PyInt_FromLong(event->eventType); + pEventType = PyLong_FromLong(event->eventType); pRetVal = PyObject_CallFunctionObjArgs(pFunc, pEventType, NULL); Py_DECREF(pEventType); @@ -217,7 +217,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) if (bareos_core_functions->getBareosValue(plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { - pRetVal = PyInt_FromLong(value); + pRetVal = PyLong_FromLong(value); } break; } @@ -250,7 +250,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) if (bareos_core_functions->getBareosValue(plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { - if (value) { pRetVal = PyString_FromString(value); } + if (value) { pRetVal = PyUnicode_FromString(value); } } break; } @@ -259,7 +259,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) if (bareos_core_functions->getBareosValue(NULL, (brDirVariable)var, &value) == bRC_OK) { - if (value) { pRetVal = PyString_FromString(value); } + if (value) { pRetVal = PyUnicode_FromString(value); } } break; } @@ -298,7 +298,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bwDirVarVolumeName: { const char* value; - value = PyString_AsString(pyValue); + value = PyUnicode_AsUTF8(pyValue); if (value) { retval = bareos_core_functions->setBareosValue( plugin_ctx, (bwDirVariable)var, @@ -311,7 +311,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bwDirVarJobLevel: { int value; - value = PyInt_AsLong(pyValue); + value = PyLong_AsLong(pyValue); if (value >= 0) { retval = bareos_core_functions->setBareosValue( plugin_ctx, (bwDirVariable)var, &value); @@ -396,7 +396,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); - event = PyInt_AsLong(pyEvent); + event = PyLong_AsLong(pyEvent); if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { Dmsg(plugin_ctx, debuglevel, @@ -438,7 +438,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); - event = PyInt_AsLong(pyEvent); + event = PyLong_AsLong(pyEvent); if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { Dmsg(plugin_ctx, debuglevel, @@ -471,7 +471,7 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (bareos_core_functions->getInstanceCount(plugin_ctx, &value) == bRC_OK) { - pRetVal = PyInt_FromLong(value); + pRetVal = PyLong_FromLong(value); } if (!pRetVal) { @@ -505,7 +505,7 @@ static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value) if (pFunc && PyCallable_Check(pFunc)) { PyObject *pPluginDefinition, *pRetVal; - pPluginDefinition = PyString_FromString((char*)value); + pPluginDefinition = PyUnicode_FromString((char*)value); if (!pPluginDefinition) { goto bail_out; } pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); @@ -563,7 +563,7 @@ static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, if (pFunc && PyCallable_Check(pFunc)) { PyObject *pEventType, *pRetVal; - pEventType = PyInt_FromLong(event->eventType); + pEventType = PyLong_FromLong(event->eventType); pRetVal = PyObject_CallFunctionObjArgs(pFunc, pEventType, NULL); Py_DECREF(pEventType); @@ -613,7 +613,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) if (bareos_core_functions->getBareosValue(plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { - pRetVal = PyInt_FromLong(value); + pRetVal = PyLong_FromLong(value); } break; } @@ -646,7 +646,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) if (bareos_core_functions->getBareosValue(plugin_ctx, (brDirVariable)var, &value) == bRC_OK) { - if (value) { pRetVal = PyString_FromString(value); } + if (value) { pRetVal = PyUnicode_FromString(value); } } break; } @@ -655,7 +655,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) if (bareos_core_functions->getBareosValue(NULL, (brDirVariable)var, &value) == bRC_OK) { - if (value) { pRetVal = PyString_FromString(value); } + if (value) { pRetVal = PyUnicode_FromString(value); } } break; } @@ -693,7 +693,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bwDirVarVolumeName: { char* value; - value = PyString_AsString(pyValue); + value = PyUnicode_AsUTF8(pyValue); if (value) { retval = bareos_core_functions->setBareosValue( plugin_ctx, (bwDirVariable)var, value); @@ -705,7 +705,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bwDirVarJobLevel: { int value; - value = PyInt_AsLong(pyValue); + value = PyLong_AsLong(pyValue); if (value >= 0) { retval = bareos_core_functions->setBareosValue( plugin_ctx, (bwDirVariable)var, &value); @@ -790,7 +790,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); - event = PyInt_AsLong(pyEvent); + event = PyLong_AsLong(pyEvent); if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { Dmsg(plugin_ctx, debuglevel, @@ -832,7 +832,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); - event = PyInt_AsLong(pyEvent); + event = PyLong_AsLong(pyEvent); if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { Dmsg(plugin_ctx, debuglevel, @@ -865,7 +865,7 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (bareos_core_functions->getInstanceCount(plugin_ctx, &value) == bRC_OK) { - pRetVal = PyInt_FromLong(value); + pRetVal = PyLong_FromLong(value); } if (!pRetVal) { diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index 961d77a666c..37127b3125e 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -165,12 +165,12 @@ static void PyErrorHandler() (char*)"OOO", type, value == NULL ? Py_None : value, traceback == NULL ? Py_None : traceback); - // emptyString = PyString_FromString(""); + // emptyString = PyUnicode_FromString(""); emptyString = PyUnicode_FromString(""); strRetval = PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); - error_string = strdup(PyString_AsString(strRetval)); + error_string = strdup(PyUnicode_AsUTF8(strRetval)); Py_DECREF(tbList); Py_DECREF(emptyString); @@ -539,7 +539,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) /* Extend the Python search path with the given module_path. */ if (plugin_priv_ctx->module_path) { sysPath = PySys_GetObject((char*)"path"); - mPath = PyString_FromString(plugin_priv_ctx->module_path); + mPath = PyUnicode_FromString(plugin_priv_ctx->module_path); PyList_Append(sysPath, mPath); Py_DECREF(mPath); plugin_priv_ctx->python_path_set = true; @@ -551,7 +551,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) Dmsg(plugin_ctx, debuglevel, "python-dir: Trying to load module with name %s\n", plugin_priv_ctx->module_name); - pName = PyString_FromString(plugin_priv_ctx->module_name); + pName = PyUnicode_FromString(plugin_priv_ctx->module_name); plugin_priv_ctx->pModule = PyImport_Import(pName); Py_DECREF(pName); @@ -582,7 +582,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) if (pFunc && PyCallable_Check(pFunc)) { PyObject *pPluginDefinition, *pRetVal; - pPluginDefinition = PyString_FromString((char*)value); + pPluginDefinition = PyUnicode_FromString((char*)value); if (!pPluginDefinition) { goto bail_out; } pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index ce057e0f537..f431e2f7d47 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -102,8 +102,10 @@ if(Python2_FOUND) DESTINATION ${plugindir} COMPONENT filedaemon ) - target_link_libraries(python-fd ${Python3_LIBRARIES} bareos) + target_link_libraries(python-fd ${Python2_LIBRARIES} bareos) + target_include_directories(python-fd PUBLIC SYSTEM ${Python2_INCLUDE_DIRS}) add_dependencies(python-fd bareosfd-pymod2) + add_dependencies(bareos-fd python-fd) endif() if(Python3_FOUND) @@ -115,7 +117,9 @@ if(Python3_FOUND) COMPONENT filedaemon ) target_link_libraries(python3-fd ${Python3_LIBRARIES} bareos) + target_include_directories(python3-fd PUBLIC SYSTEM ${Python3_INCLUDE_DIRS}) add_dependencies(python3-fd bareosfd-pymod3) + add_dependencies(bareos-fd python3-fd) endif() if(Python2_FOUND AND NOT HAVE_WIN22) @@ -125,6 +129,9 @@ if(Python2_FOUND AND NOT HAVE_WIN22) target_link_libraries( bareosfd-python2-module-tester ${Python2_LIBRARIES} bareos ) + target_include_directories( + bareosfd-python2-module-tester PUBLIC SYSTEM ${Python2_INCLUDE_DIRS} + ) add_test(NAME bareosfd-python2-module-tester COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bareosfd-python2-module-tester @@ -144,6 +151,9 @@ if(Python3_FOUND AND NOT HAVE_WIN32) target_link_libraries( bareosfd-python3-module-tester ${Python3_LIBRARIES} bareos ) + target_include_directories( + bareosfd-python3-module-tester PUBLIC SYSTEM ${Python3_INCLUDE_DIRS} + ) add_test(NAME bareosfd-python3-module-tester COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bareosfd-python3-module-tester @@ -167,8 +177,8 @@ if(Python2_FOUND AND NOT HAVE_WIN22) DEPENDS bareos DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup_py2.py COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python_EXECUTABLE} python/setup_py2.py build - COMMAND ${Python_EXECUTABLE} python/setup_py2.py install --install-lib + COMMAND ${Python2_EXECUTABLE} python/setup_py2.py build + COMMAND ${Python2_EXECUTABLE} python/setup_py2.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python2 module pythonmodules/bareosfd.so" @@ -198,8 +208,8 @@ if(Python3_FOUND AND NOT HAVE_WIN32) DEPENDS bareos DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup_py3.py COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python_EXECUTABLE} python/setup_py3.py build - COMMAND ${Python_EXECUTABLE} python/setup_py3.py install --install-lib + COMMAND ${Python3_EXECUTABLE} python/setup_py3.py build + COMMAND ${Python3_EXECUTABLE} python/setup_py3.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python3 module pythonmodules/bareosfd.so" diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 2dc7f42198c..fad5f3b12be 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -183,7 +183,7 @@ static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, if (pFunc && PyCallable_Check(pFunc)) { PyObject *pEventType, *pRetVal; - pEventType = PyInt_FromLong(event->eventType); + pEventType = PyLong_FromLong(event->eventType); pRetVal = PyObject_CallFunctionObjArgs(pFunc, pEventType, NULL); Py_DECREF(pEventType); @@ -314,7 +314,7 @@ static inline bool PySavePacketToNative( * As this has to linger as long as the backup is running we save it in * our plugin context. */ - if (PyString_Check(pSavePkt->link)) { + if (PyUnicode_Check(pSavePkt->link)) { if (plugin_priv_ctx->link) { free(plugin_priv_ctx->link); } plugin_priv_ctx->link = strdup(PyUnicode_AsUTF8(pSavePkt->link)); sp->link = plugin_priv_ctx->link; @@ -361,7 +361,7 @@ static inline bool PySavePacketToNative( * in our plugin context. */ if (pSavePkt->object_name && pSavePkt->object && - PyString_Check(pSavePkt->object_name) && + PyUnicode_Check(pSavePkt->object_name) && PyByteArray_Check(pSavePkt->object)) { char* buf; @@ -1332,7 +1332,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) if (bareos_core_functions->getBareosValue(plugin_ctx, (bVariable)var, &value) == bRC_OK) { - pRetVal = PyInt_FromLong(value); + pRetVal = PyLong_FromLong(value); } break; } @@ -1386,7 +1386,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bVarLevel: { int value = 0; - value = PyInt_AsLong(pyValue); + value = PyLong_AsLong(pyValue); if (value) { retval = bareos_core_functions->setBareosValue(plugin_ctx, (bVariable)var, &value); @@ -1481,7 +1481,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); - event = PyInt_AsLong(pyEvent); + event = PyLong_AsLong(pyEvent); if (event >= bEventJobStart && event <= FD_NR_EVENTS) { Dmsg(plugin_ctx, debuglevel, @@ -1522,7 +1522,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) len = PySequence_Fast_GET_SIZE(pySeq); for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); - event = PyInt_AsLong(pyEvent); + event = PyLong_AsLong(pyEvent); if (event >= bEventJobStart && event <= FD_NR_EVENTS) { Dmsg(plugin_ctx, debuglevel, @@ -1553,7 +1553,7 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() if (bareos_core_functions->getInstanceCount(plugin_ctx, &value) == bRC_OK) { - pRetVal = PyInt_FromLong(value); + pRetVal = PyLong_FromLong(value); } if (!pRetVal) { @@ -1745,7 +1745,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) */ sp.type = pSavePkt->type; if (pSavePkt->fname) { - if (PyString_Check(pSavePkt->fname)) { + if (PyUnicode_Check(pSavePkt->fname)) { sp.fname = const_cast(PyUnicode_AsUTF8(pSavePkt->fname)); } else { goto bail_out; @@ -1754,7 +1754,7 @@ static PyObject* PyBareosCheckChanges(PyObject* self, PyObject* args) goto bail_out; } if (pSavePkt->link) { - if (PyString_Check(pSavePkt->link)) { + if (PyUnicode_Check(pSavePkt->link)) { sp.link = const_cast(PyUnicode_AsUTF8(pSavePkt->link)); } else { goto bail_out; @@ -1796,7 +1796,7 @@ static PyObject* PyBareosAcceptFile(PyObject* self, PyObject* args) * that here separately and don't call PySavePacketToNative(). */ if (pSavePkt->fname) { - if (PyString_Check(pSavePkt->fname)) { + if (PyUnicode_Check(pSavePkt->fname)) { sp.fname = const_cast(PyUnicode_AsUTF8(pSavePkt->fname)); } else { goto bail_out; @@ -1871,7 +1871,7 @@ static PyObject* PyBareosClearSeenBitmap(PyObject* self, PyObject* args) */ static inline char* PyGetStringValue(PyObject* object) { - if (!object || !PyString_Check(object)) { return (char*)""; } + if (!object || !PyUnicode_Check(object)) { return (char*)""; } return const_cast(PyUnicode_AsUTF8(object)); } diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 0e9715d2df2..d2d913a6643 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -146,7 +146,7 @@ static void PyErrorHandler() strRetval = PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); - error_string = strdup(PyString_AsString(strRetval)); + error_string = strdup(PyUnicode_AsUTF8(strRetval)); Py_DECREF(tbList); Py_DECREF(emptyString); diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index 837014cae8c..adacf9298f0 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -48,12 +48,12 @@ static void PyErrorHandler() (char*)"OOO", type, value == NULL ? Py_None : value, traceback == NULL ? Py_None : traceback); - // emptyString = PyString_FromString(""); + // emptyString = PyUnicode_FromString(""); emptyString = PyUnicode_FromString(""); strRetval = PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); - error_string = strdup(PyString_AsString(strRetval)); + error_string = strdup(PyUnicode_AsUTF8(strRetval)); Py_DECREF(tbList); Py_DECREF(emptyString); @@ -239,7 +239,7 @@ int main(int argc, char* argv[]) PyObject *pPluginDefinition, *pRetVal; - pPluginDefinition = PyString_FromString((char*)"PluginDefinition"); + pPluginDefinition = PyUnicode_FromString((char*)"PluginDefinition"); pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); diff --git a/core/src/plugins/python3compat.h b/core/src/plugins/python3compat.h index 5048d9cfe70..f9368c33f79 100644 --- a/core/src/plugins/python3compat.h +++ b/core/src/plugins/python3compat.h @@ -1,14 +1,17 @@ #ifndef BAREOS_CORE_SRC_PLUGINS_PYTHON3COMPAT_H_ #define BAREOS_CORE_SRC_PLUGINS_PYTHON3COMPAT_H_ -/* redefine python2 calls to python3 pendants */ - -#if PY_VERSION_HEX >= 0x03000000 -#define PyInt_FromLong PyLong_FromLong -#define PyInt_AsLong PyLong_AsLong -#define PyString_FromString PyBytes_FromString -#define PyString_AsString PyUnicode_AsUTF8 -#define PyString_Check PyUnicode_Check +/* redefine python3 calls to python2 pendants */ + +#if PY_VERSION_HEX < 0x03000000 +#define PyLong_FromLong PyInt_FromLong +#define PyLong_AsLong PyInt_AsLong + +#define PyBytes_FromString PyString_FromString +#define PyUnicode_FromString PyString_FromString + +#define PyUnicode_AsUTF8 PyString_AsString +#define PyUnicode_Check PyString_Check #endif #endif // BAREOS_CORE_SRC_PLUGINS_PYTHON3COMPAT_H_ diff --git a/core/src/plugins/python_plugins_common.inc b/core/src/plugins/python_plugins_common.inc index 79340b2d42f..c668ad29d71 100644 --- a/core/src/plugins/python_plugins_common.inc +++ b/core/src/plugins/python_plugins_common.inc @@ -107,7 +107,7 @@ static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype) strRetval = PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); - error_string = strdup(PyString_AsString(strRetval)); + error_string = strdup(PyUnicode_AsUTF8(strRetval)); Py_DECREF(tbList); Py_DECREF(emptyString); @@ -157,7 +157,7 @@ static PluginContext* GetPluginContextFromPythonModule() */ static inline bRC ConvertPythonRetvalTobRCRetval(PyObject* pRetVal) { - return (bRC)PyInt_AsLong(pRetVal); + return (bRC)PyLong_AsLong(pRetVal); } /** @@ -165,5 +165,5 @@ static inline bRC ConvertPythonRetvalTobRCRetval(PyObject* pRetVal) */ static inline PyObject* ConvertbRCRetvalToPythonRetval(bRC retval) { - return (PyObject*)PyInt_FromLong((int)retval); + return (PyObject*)PyLong_FromLong((int)retval); } diff --git a/core/src/plugins/stored/CMakeLists.txt b/core/src/plugins/stored/CMakeLists.txt index 1336a5babdd..6aeed34d617 100644 --- a/core/src/plugins/stored/CMakeLists.txt +++ b/core/src/plugins/stored/CMakeLists.txt @@ -48,7 +48,8 @@ if(NOT HAVE_WIN32 AND NOT HAVE_DARWIN_OS) endif() endif() -if(HAVE_PYTHON) +if(Python2_FOUND) + include_directories(SYSTEM ${Python2_INCLUDE_DIRS}) add_library(python-sd MODULE python/python-sd.cc) set_target_properties(python-sd PROPERTIES PREFIX "") install(TARGETS python-sd DESTINATION ${plugindir}) diff --git a/core/src/plugins/stored/python/bareossd.cc b/core/src/plugins/stored/python/bareossd.cc index fbfd45c9ec5..a05db6b3003 100644 --- a/core/src/plugins/stored/python/bareossd.cc +++ b/core/src/plugins/stored/python/bareossd.cc @@ -104,7 +104,7 @@ static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value) if (pFunc && PyCallable_Check(pFunc)) { PyObject *pPluginDefinition, *pRetVal; - pPluginDefinition = PyString_FromString((char*)value); + pPluginDefinition = PyUnicode_FromString((char*)value); if (!pPluginDefinition) { goto bail_out; } pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); @@ -162,7 +162,7 @@ static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, if (pFunc && PyCallable_Check(pFunc)) { PyObject *pEventType, *pRetVal; - pEventType = PyInt_FromLong(event->eventType); + pEventType = PyLong_FromLong(event->eventType); pRetVal = PyObject_CallFunctionObjArgs(pFunc, pEventType, NULL); Py_DECREF(pEventType); @@ -208,7 +208,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) if (bareos_core_functions->getBareosValue(plugin_ctx, (bsdrVariable)var, &value) == bRC_OK) { - pRetVal = PyInt_FromLong(value); + pRetVal = PyLong_FromLong(value); } break; } @@ -235,7 +235,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) if (bareos_core_functions->getBareosValue(plugin_ctx, (bsdrVariable)var, &value) == bRC_OK) { - if (value) { pRetVal = PyString_FromString(value); } + if (value) { pRetVal = PyUnicode_FromString(value); } } break; } @@ -256,7 +256,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) if (bareos_core_functions->getBareosValue(NULL, (bsdrVariable)var, &value) == bRC_OK) { - if (value) { pRetVal = PyString_FromString(value); } + if (value) { pRetVal = PyUnicode_FromString(value); } } break; } @@ -292,7 +292,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) switch (var) { case bsdwVarVolumeName: { - const char* value = PyString_AsString(pyValue); + const char* value = PyUnicode_AsUTF8(pyValue); if (value) { bareos_core_functions->setBareosValue( plugin_ctx, (bsdwVariable)var, @@ -305,7 +305,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) case bsdwVarJobLevel: { int value; - value = PyInt_AsLong(pyValue); + value = PyLong_AsLong(pyValue); if (value >= 0) { retval = bareos_core_functions->setBareosValue( plugin_ctx, (bsdwVariable)var, &value); @@ -390,7 +390,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); - event = PyInt_AsLong(pyEvent); + event = PyLong_AsLong(pyEvent); if (event >= bSdEventJobStart && event <= bSdEventWriteRecordTranslation) { Dmsg(plugin_ctx, debuglevel, @@ -432,7 +432,7 @@ static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) for (int i = 0; i < len; i++) { pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); - event = PyInt_AsLong(pyEvent); + event = PyLong_AsLong(pyEvent); if (event >= bSdEventJobStart && event <= bSdEventWriteRecordTranslation) { Dmsg(plugin_ctx, debuglevel, @@ -473,7 +473,7 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) return NULL; } if (bareos_core_functions->getInstanceCount(plugin_ctx, &value) == bRC_OK) { - pRetVal = PyInt_FromLong(value); + pRetVal = PyLong_FromLong(value); } if (!pRetVal) { diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index 8f50c793a17..4d8e60c9b0e 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -165,12 +165,12 @@ static void PyErrorHandler() (char*)"OOO", type, value == NULL ? Py_None : value, traceback == NULL ? Py_None : traceback); - // emptyString = PyString_FromString(""); + // emptyString = PyUnicode_FromString(""); emptyString = PyUnicode_FromString(""); strRetval = PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); - error_string = strdup(PyString_AsString(strRetval)); + error_string = strdup(PyUnicode_AsUTF8(strRetval)); Py_DECREF(tbList); Py_DECREF(emptyString); @@ -539,7 +539,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) /* Extend the Python search path with the given module_path */ if (plugin_priv_ctx->module_path) { sysPath = PySys_GetObject((char*)"path"); - mPath = PyString_FromString(plugin_priv_ctx->module_path); + mPath = PyUnicode_FromString(plugin_priv_ctx->module_path); PyList_Append(sysPath, mPath); Py_DECREF(mPath); plugin_priv_ctx->python_path_set = true; @@ -551,7 +551,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) Dmsg(plugin_ctx, debuglevel, "python-sd: Trying to load module with name %s\n", plugin_priv_ctx->module_name); - pName = PyString_FromString(plugin_priv_ctx->module_name); + pName = PyUnicode_FromString(plugin_priv_ctx->module_name); plugin_priv_ctx->pModule = PyImport_Import(pName); Py_DECREF(pName); @@ -582,7 +582,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) if (pFunc && PyCallable_Check(pFunc)) { PyObject *pPluginDefinition, *pRetVal; - pPluginDefinition = PyString_FromString((char*)value); + pPluginDefinition = PyUnicode_FromString((char*)value); if (!pPluginDefinition) { goto bail_out; } pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); From 04fd4ebf972b11c96413e10a9814a83d8a69e83b Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 15 May 2020 16:58:52 +0200 Subject: [PATCH 110/341] python plugin: create a system test for both python2 and 3 fileset test --- core/cmake/BareosFindAllLibraries.cmake | 9 ++- core/src/plugins/dird/CMakeLists.txt | 67 ++++++++++++++++--- core/src/plugins/python3compat.h | 4 +- core/src/plugins/stored/CMakeLists.txt | 66 +++++++++++++++--- systemtests/CMakeLists.txt | 20 +++++- .../bareos/bareos-fd.d/client/myself.conf.in | 2 +- .../python3-fd-plugin-local-fileset-test | 1 + 7 files changed, 140 insertions(+), 29 deletions(-) create mode 120000 systemtests/tests/python3-fd-plugin-local-fileset-test diff --git a/core/cmake/BareosFindAllLibraries.cmake b/core/cmake/BareosFindAllLibraries.cmake index 876919ec55a..4ebb8ea8afa 100644 --- a/core/cmake/BareosFindAllLibraries.cmake +++ b/core/cmake/BareosFindAllLibraries.cmake @@ -23,13 +23,12 @@ if(${SYSTEMD_FOUND}) endif() if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") - find_package (Python COMPONENTS Interpreter Development) - if(${Python_FOUND}) - set(HAVE_PYTHON 1) - endif() + #find_package (Python COMPONENTS Interpreter Development) find_package (Python2 COMPONENTS Interpreter Development) find_package (Python3 COMPONENTS Interpreter Development) - + if(${Python2_FOUND} OR ${Python3_FOUND}) + set(HAVE_PYTHON 1) + endif() endif() diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index 783c282ef65..357276dab71 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -38,7 +38,7 @@ if(Python2_FOUND) set_target_properties(python-dir PROPERTIES PREFIX "") install(TARGETS python-dir DESTINATION ${plugindir}) target_link_libraries(python-dir ${Python_LIBRARIES} bareos) - add_dependencies(python-dir bareosdir-pymod) + add_dependencies(python-dir bareosdir-python2-module) set(PYFILES python/pyfiles/bareos-dir.py.template @@ -50,7 +50,7 @@ if(Python2_FOUND) install(FILES ${PYFILES} DESTINATION ${plugindir}) endif() -if(HAVE_PYTHON AND NOT HAVE_WIN32) +if(Python2_FOUND AND NOT HAVE_WIN32) configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) add_custom_command( OUTPUT pythonmodules/bareosdir.so @@ -59,21 +59,70 @@ if(HAVE_PYTHON AND NOT HAVE_WIN32) DEPENDS bareos DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python_EXECUTABLE} python/setup.py build - COMMAND ${Python_EXECUTABLE} python/setup.py install --install-lib + COMMAND ${Python2_EXECUTABLE} python/setup.py build + COMMAND ${Python2_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build - COMMENT "building python module pythonmodules/bareosdir.so" + COMMENT "building python2 module pythonmodules/bareosdir.so" ) + add_custom_target(bareosdir-python2-module DEPENDS pythonmodules/bareosdir.so) - add_custom_target(bareosdir-pymod DEPENDS pythonmodules/bareosdir.so) + add_test(NAME bareosdir-python2-module + COMMAND ${Python2_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosdir_test.py + ) + set_property( + TEST bareosdir-python2-module + PROPERTY + ENVIRONMENT + "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" + LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib + ) +endif() + +if(Python3_FOUND) + include_directories(SYSTEM ${Python2_INCLUDE_DIRS}) + + add_library(python3-dir MODULE python/python-dir.cc) + # do not prefix with "lib" + set_target_properties(python3-dir PROPERTIES PREFIX "") + install(TARGETS python3-dir DESTINATION ${plugindir}) + target_link_libraries(python3-dir ${Python_LIBRARIES} bareos) + add_dependencies(python3-dir bareosdir-python2-module) + + set(PYFILES + python/pyfiles/bareos-dir.py.template + python/pyfiles/bareos-dir-class-plugin.py + python/pyfiles/BareosDirPluginBaseclass.py + python/pyfiles/BareosDirWrapper.py + ) + + install(FILES ${PYFILES} DESTINATION ${plugindir}) +endif() + +if(Python3_FOUND AND NOT HAVE_WIN32) + configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) + add_custom_command( + OUTPUT pythonmodules/bareosdir.so + MAIN_DEPENDENCY ./python/bareosdir.cc + DEPENDS ./python/bareosdir.h + DEPENDS bareos + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py + COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build + COMMAND ${Python3_EXECUTABLE} python/setup.py build + COMMAND ${Python3_EXECUTABLE} python/setup.py install --install-lib + ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build + COMMENT "building python3 module pythonmodules/bareosdir.so" + ) + add_custom_target(bareosdir-python3-module DEPENDS pythonmodules/bareosdir.so) - add_test(NAME bareosdir-python-module - COMMAND ${Python_EXECUTABLE} + add_test(NAME bareosdir-python3-module + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosdir_test.py ) set_property( - TEST bareosdir-python-module + TEST bareosdir-python3-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" diff --git a/core/src/plugins/python3compat.h b/core/src/plugins/python3compat.h index f9368c33f79..6764c385f09 100644 --- a/core/src/plugins/python3compat.h +++ b/core/src/plugins/python3compat.h @@ -8,10 +8,10 @@ #define PyLong_AsLong PyInt_AsLong #define PyBytes_FromString PyString_FromString -#define PyUnicode_FromString PyString_FromString +//#define PyUnicode_FromString PyString_FromString #define PyUnicode_AsUTF8 PyString_AsString -#define PyUnicode_Check PyString_Check +//#define PyUnicode_Check PyString_Check #endif #endif // BAREOS_CORE_SRC_PLUGINS_PYTHON3COMPAT_H_ diff --git a/core/src/plugins/stored/CMakeLists.txt b/core/src/plugins/stored/CMakeLists.txt index 6aeed34d617..9e26fe4c43c 100644 --- a/core/src/plugins/stored/CMakeLists.txt +++ b/core/src/plugins/stored/CMakeLists.txt @@ -53,8 +53,8 @@ if(Python2_FOUND) add_library(python-sd MODULE python/python-sd.cc) set_target_properties(python-sd PROPERTIES PREFIX "") install(TARGETS python-sd DESTINATION ${plugindir}) - target_link_libraries(python-sd ${Python_LIBRARIES} bareos) - add_dependencies(python-sd bareossd-pymod) + target_link_libraries(python-sd ${Python2_LIBRARIES} bareos) + add_dependencies(python-sd bareossd-python2-module) set(PYFILES python/pyfiles/bareos-sd-class-plugin.py @@ -65,7 +65,7 @@ if(Python2_FOUND) install(FILES ${PYFILES} DESTINATION ${plugindir}) endif() -if(HAVE_PYTHON AND NOT HAVE_WIN32) +if(Python2_FOUND AND NOT HAVE_WIN32) configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) add_custom_command( OUTPUT pythonmodules/bareossd.so @@ -74,21 +74,69 @@ if(HAVE_PYTHON AND NOT HAVE_WIN32) DEPENDS bareos DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python_EXECUTABLE} python/setup.py build - COMMAND ${Python_EXECUTABLE} python/setup.py install --install-lib + COMMAND ${Python2_EXECUTABLE} python/setup.py build + COMMAND ${Python2_EXECUTABLE} python/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python module pythonmodules/bareossd.so" ) - add_custom_target(bareossd-pymod DEPENDS pythonmodules/bareossd.so) + add_custom_target(bareossd-python2-module DEPENDS pythonmodules/bareossd.so) - add_test(NAME bareossd-python-module - COMMAND ${Python_EXECUTABLE} + add_test(NAME bareossd-python2-module + COMMAND ${Python2_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareossd_test.py ) set_property( - TEST bareossd-python-module + TEST bareossd-python2-module + PROPERTY + ENVIRONMENT + "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" + LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib + ) +endif() + +if(Python3_FOUND) + include_directories(SYSTEM ${Python3_INCLUDE_DIRS}) + add_library(python3-sd MODULE python/python-sd.cc) + set_target_properties(python3-sd PROPERTIES PREFIX "") + install(TARGETS python3-sd DESTINATION ${plugindir}) + target_link_libraries(python3-sd ${Python3_LIBRARIES} bareos) + add_dependencies(python3-sd bareossd-python3-module) + + set(PYFILES + python/pyfiles/bareos-sd-class-plugin.py + python/pyfiles/BareosSdPluginBaseclass.py + python/pyfiles/bareos-sd.py.template python/pyfiles/BareosSdWrapper.py + ) + + install(FILES ${PYFILES} DESTINATION ${plugindir}) +endif() + +if(Python3_FOUND AND NOT HAVE_WIN32) + configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) + add_custom_command( + OUTPUT pythonmodules/bareossd.so + MAIN_DEPENDENCY ./python/bareossd.cc + DEPENDS ./python/bareossd.h + DEPENDS bareos + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py + COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build + COMMAND ${Python3_EXECUTABLE} python/setup.py build + COMMAND ${Python3_EXECUTABLE} python/setup.py install --install-lib + ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build + COMMENT "building python module pythonmodules/bareossd.so" + ) + + add_custom_target(bareossd-python3-module DEPENDS pythonmodules/bareossd.so) + + add_test(NAME bareossd-python3-module + COMMAND ${Python3_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareossd_test.py + ) + set_property( + TEST bareossd-python3-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 594b40cc203..d64beaf0cbf 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -329,6 +329,10 @@ if(RUN_SYSTEMTESTS_ON_INSTALLED_FILES) PYTHON_PLUGIN_TO_TEST python-fd.so PATHS /usr/lib/bareos/plugins /usr/lib64/bareos/plugins ) + find_program( + PYTHON_PLUGIN_TO_TEST python3-fd.so PATHS /usr/lib/bareos/plugins + /usr/lib64/bareos/plugins + ) find_program( CREATE_BAREOS_DATABASE_TO_TEST create_bareos_database PATHS /usr/lib/bareos/scripts @@ -435,13 +439,13 @@ set(python_plugin_module_src_test_dir_relative "python-modules") set(plugindirtmp ${PROJECT_BINARY_DIR}/plugindirtmp) set(rscripts ${PROJECT_BINARY_DIR}/scripts) -if(TARGET python-dir) +if(TARGET python-dir OR TARGET python3-dir) set(dir_plugin_binary_path ${DIR_PLUGINS_DIR_TO_TEST}) endif() -if(TARGET python-sd) +if(TARGET python-sd OR TARGET python3-sd) set(sd_plugin_binary_path ${SD_PLUGINS_DIR_TO_TEST}) endif() -if(TARGET python-fd) +if(TARGET python-fd OR TARGET python3-fd) set(fd_plugin_binary_path ${FD_PLUGINS_DIR_TO_TEST}) endif() @@ -650,6 +654,11 @@ else() list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-postgres") message("NOT OK, disabling pyplug-fd-postgres:") endif() +if(TARGET python3-fd) + list(APPEND SYSTEM_TESTS "python3-fd-plugin-local-fileset-test") +else() + list(APPEND SYSTEM_TESTS_DISABLED "python3-fd-plugin-local-fileset-test") +endif() if(TARGET python-fd AND ovirt_server) list(APPEND SYSTEM_TESTS "pyplug-fd-ovirt") @@ -789,6 +798,11 @@ endif() foreach(TEST_NAME ${SYSTEM_TESTS}) message(STATUS "Configuring test: ${SYSTEMTEST_PREFIX}${TEST_NAME}") + # string(REGEX MATCH "^python[^-]?-(fd|sd|dir)" PLUGIN_NAME "${TEST_NAME}") + string(REGEX MATCH "^python[^-]?" plugin_name "${TEST_NAME}") + if(plugin_name) + message(STATUS "plugin_name:" ${plugin_name}) + endif() prepare_test() configurefilestosystemtest("systemtests" "tests/${TEST_NAME}" "*" @ONLY "") diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-fd.d/client/myself.conf.in index 49039c29d18..d4c17f837e5 100644 --- a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-fd.d/client/myself.conf.in +++ b/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-fd.d/client/myself.conf.in @@ -7,7 +7,7 @@ Client { # otherwise all filedaemon plugins (*-fd.so) from the "Plugin Directory". # Plugin Directory = "@fd_plugin_binary_path@" - Plugin Names = "python" + Plugin Names = "@plugin_name@" # if compatible is set to yes, we are compatible with bacula # if set to no, new bareos features are enabled which is the default diff --git a/systemtests/tests/python3-fd-plugin-local-fileset-test b/systemtests/tests/python3-fd-plugin-local-fileset-test new file mode 120000 index 00000000000..abcf40b9b22 --- /dev/null +++ b/systemtests/tests/python3-fd-plugin-local-fileset-test @@ -0,0 +1 @@ +python-fd-plugin-local-fileset-test \ No newline at end of file From 9bcecc3f7b91a24a3296fec8dd479d63f15b3892 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 15 May 2020 18:15:01 +0200 Subject: [PATCH 111/341] python: build also other tests for python3 --- core/src/plugins/dird/CMakeLists.txt | 14 ++++++----- core/src/plugins/filed/CMakeLists.txt | 10 ++++---- core/src/plugins/filed/python/bareosfd.cc | 23 ++++++++---------- core/src/plugins/python3compat.h | 9 +++++-- core/src/plugins/stored/CMakeLists.txt | 10 ++++---- systemtests/CMakeLists.txt | 24 +++++++++---------- .../bareos-dir.d/director/bareos-dir.conf.in | 2 +- .../bareos/bareos-fd.d/client/myself.conf.in | 2 +- .../bareos-sd.d/storage/bareos-sd.conf.in | 2 +- systemtests/tests/python3-dir-plugin-test | 1 + systemtests/tests/python3-sd-plugin-test | 1 + 11 files changed, 52 insertions(+), 46 deletions(-) create mode 120000 systemtests/tests/python3-dir-plugin-test create mode 120000 systemtests/tests/python3-sd-plugin-test diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index 357276dab71..b7bdc69b02c 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -88,7 +88,7 @@ if(Python3_FOUND) set_target_properties(python3-dir PROPERTIES PREFIX "") install(TARGETS python3-dir DESTINATION ${plugindir}) target_link_libraries(python3-dir ${Python_LIBRARIES} bareos) - add_dependencies(python3-dir bareosdir-python2-module) + add_dependencies(python3-dir bareosdir-python3-module) set(PYFILES python/pyfiles/bareos-dir.py.template @@ -103,7 +103,7 @@ endif() if(Python3_FOUND AND NOT HAVE_WIN32) configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) add_custom_command( - OUTPUT pythonmodules/bareosdir.so + OUTPUT python3modules/bareosdir.so MAIN_DEPENDENCY ./python/bareosdir.cc DEPENDS ./python/bareosdir.h DEPENDS bareos @@ -111,11 +111,13 @@ if(Python3_FOUND AND NOT HAVE_WIN32) COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${Python3_EXECUTABLE} python/setup.py build COMMAND ${Python3_EXECUTABLE} python/setup.py install --install-lib - ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + ${CMAKE_CURRENT_BINARY_DIR}/python3modules COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build - COMMENT "building python3 module pythonmodules/bareosdir.so" + COMMENT "building python3 module python3modules/bareosdir.so" + ) + add_custom_target( + bareosdir-python3-module DEPENDS python3modules/bareosdir.so ) - add_custom_target(bareosdir-python3-module DEPENDS pythonmodules/bareosdir.so) add_test(NAME bareosdir-python3-module COMMAND ${Python3_EXECUTABLE} @@ -125,7 +127,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) TEST bareosdir-python3-module PROPERTY ENVIRONMENT - "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" + "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/python3modules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib ) endif() diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index f431e2f7d47..b29e915dd80 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -202,7 +202,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup_py3.py ) add_custom_command( - OUTPUT pythonmodules/bareosfd.so + OUTPUT python3modules/bareosfd.so MAIN_DEPENDENCY ./python/bareosfd.cc DEPENDS ./python/bareosfd.h DEPENDS bareos @@ -210,11 +210,11 @@ if(Python3_FOUND AND NOT HAVE_WIN32) COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${Python3_EXECUTABLE} python/setup_py3.py build COMMAND ${Python3_EXECUTABLE} python/setup_py3.py install --install-lib - ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + ${CMAKE_CURRENT_BINARY_DIR}/python3modules COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build - COMMENT "building python3 module pythonmodules/bareosfd.so" + COMMENT "building python3 module python3modules/bareosfd.so" ) - add_custom_target(bareosfd-pymod3 DEPENDS pythonmodules/bareosfd.so) + add_custom_target(bareosfd-pymod3 DEPENDS python3modules/bareosfd.so) add_test(NAME bareosfd-python3-module COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosfd_test.py @@ -223,7 +223,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) TEST bareosfd-python3-module PROPERTY ENVIRONMENT - "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" + "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/python3modules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib ) endif() diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index fad5f3b12be..df2b5e0b7c3 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -124,7 +124,6 @@ static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value) if (pFunc && PyCallable_Check(pFunc)) { PyObject *pPluginDefinition, *pRetVal; - // pPluginDefinition = PyString_FromString((char*)value); pPluginDefinition = PyUnicode_FromString((char*)value); if (!pPluginDefinition) { goto bail_out; } @@ -1184,7 +1183,6 @@ static inline PyRestoreObject* NativeToPyRestoreObject( PyObject_New(PyRestoreObject, &PyRestoreObjectType); if (pRestoreObject) { - // pRestoreObject->object_name = PyString_FromString(rop->object_name); pRestoreObject->object_name = PyUnicode_FromString(rop->object_name); pRestoreObject->object = PyByteArray_FromStringAndSize(rop->object, rop->object_len); @@ -2110,20 +2108,19 @@ static int PySavePacket_init(PySavePacket* self, PyObject* args, PyObject* kwds) self->object_len = 0; self->object_index = 0; - if (!PyArg_ParseTupleAndKeywords( - args, kwds, "|OOiOpppsiiOOii", kwlist, &self->fname, &self->link, - &self->type, &self->flags, &self->no_read, &self->portable, - &self->accurate_found, &self->cmd, &self->save_time, &self->delta_seq, - &self->object_name, &self->object, &self->object_len, - &self->object_index)) { - // if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, - // &self->fname)) { + args, kwds, +#if PY_VERSION_HEX < 0x03000000 + "|OOiOpppsiiOOii", +#else + "|ooiocccsiiooii", +#endif + kwlist, &self->fname, &self->link, &self->type, &self->flags, + &self->no_read, &self->portable, &self->accurate_found, &self->cmd, + &self->save_time, &self->delta_seq, &self->object_name, &self->object, + &self->object_len, &self->object_index)) { return -1; } - int a; - a = a + a; - printf("hello\n"); return 0; } diff --git a/core/src/plugins/python3compat.h b/core/src/plugins/python3compat.h index 6764c385f09..0c5d6c8ee5a 100644 --- a/core/src/plugins/python3compat.h +++ b/core/src/plugins/python3compat.h @@ -8,10 +8,15 @@ #define PyLong_AsLong PyInt_AsLong #define PyBytes_FromString PyString_FromString -//#define PyUnicode_FromString PyString_FromString + +#undef PyUnicode_FromString +#define PyUnicode_FromString PyString_FromString #define PyUnicode_AsUTF8 PyString_AsString -//#define PyUnicode_Check PyString_Check + +#undef PyUnicode_Check +#define PyUnicode_Check PyString_Check + #endif #endif // BAREOS_CORE_SRC_PLUGINS_PYTHON3COMPAT_H_ diff --git a/core/src/plugins/stored/CMakeLists.txt b/core/src/plugins/stored/CMakeLists.txt index 9e26fe4c43c..8d2077ea17d 100644 --- a/core/src/plugins/stored/CMakeLists.txt +++ b/core/src/plugins/stored/CMakeLists.txt @@ -116,7 +116,7 @@ endif() if(Python3_FOUND AND NOT HAVE_WIN32) configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) add_custom_command( - OUTPUT pythonmodules/bareossd.so + OUTPUT python3modules/bareossd.so MAIN_DEPENDENCY ./python/bareossd.cc DEPENDS ./python/bareossd.h DEPENDS bareos @@ -124,12 +124,12 @@ if(Python3_FOUND AND NOT HAVE_WIN32) COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${Python3_EXECUTABLE} python/setup.py build COMMAND ${Python3_EXECUTABLE} python/setup.py install --install-lib - ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + ${CMAKE_CURRENT_BINARY_DIR}/python3modules COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build - COMMENT "building python module pythonmodules/bareossd.so" + COMMENT "building python module python3modules/bareossd.so" ) - add_custom_target(bareossd-python3-module DEPENDS pythonmodules/bareossd.so) + add_custom_target(bareossd-python3-module DEPENDS python3modules/bareossd.so) add_test(NAME bareossd-python3-module COMMAND ${Python3_EXECUTABLE} @@ -139,7 +139,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) TEST bareossd-python3-module PROPERTY ENVIRONMENT - "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" + "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/python3modules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib ) endif() diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index d64beaf0cbf..c8f429a7cc0 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -799,23 +799,23 @@ endif() foreach(TEST_NAME ${SYSTEM_TESTS}) message(STATUS "Configuring test: ${SYSTEMTEST_PREFIX}${TEST_NAME}") # string(REGEX MATCH "^python[^-]?-(fd|sd|dir)" PLUGIN_NAME "${TEST_NAME}") - string(REGEX MATCH "^python[^-]?" plugin_name "${TEST_NAME}") - if(plugin_name) - message(STATUS "plugin_name:" ${plugin_name}) + string(REGEX MATCH "^python[^-]?" python_version "${TEST_NAME}") + if(python_version) + message(STATUS "python_version:" ${python_version}) # python or python3 endif() prepare_test() configurefilestosystemtest("systemtests" "tests/${TEST_NAME}" "*" @ONLY "") string( - CONCAT pythonpath - "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/pyfiles:" - "${CMAKE_SOURCE_DIR}/core/src/plugins/stored/python/pyfiles:" - "${CMAKE_SOURCE_DIR}/core/src/plugins/dird/python/pyfiles:" - "${CMAKE_BINARY_DIR}/core/src/plugins/filed/pythonmodules:" - "${CMAKE_BINARY_DIR}/core/src/plugins/stored/pythonmodules:" - "${CMAKE_SOURCE_DIR}/core/src/plugins/dird/pythonmodules:" - "${CMAKE_BINARY_DIR}/core/src/plugins/dird/pythonmodules:" - "${CMAKE_CURRENT_SOURCE_DIR}/tests/${TEST_NAME}/python-modules" + CONCAT + pythonpath + "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/pyfiles:" + "${CMAKE_SOURCE_DIR}/core/src/plugins/stored/python/pyfiles:" + "${CMAKE_SOURCE_DIR}/core/src/plugins/dird/python/pyfiles:" + "${CMAKE_BINARY_DIR}/core/src/plugins/filed/${python_version}modules:" + "${CMAKE_BINARY_DIR}/core/src/plugins/stored/${python_version}modules:" + "${CMAKE_BINARY_DIR}/core/src/plugins/dird/${python_version}modules:" + "${CMAKE_CURRENT_SOURCE_DIR}/tests/${TEST_NAME}/python-modules" ) configure_file("environment.in" "tests/${TEST_NAME}/environment" @ONLY) diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in b/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in index 79f9c1bc8c4..ec8127d61ad 100644 --- a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in +++ b/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in @@ -20,7 +20,7 @@ Director { # define myself # otherwise all director plugins (*-dir.so) from the "Plugin Directory". # Plugin Directory = "@dir_plugin_binary_path@" - Plugin Names = "python" + Plugin Names = "@python-version@" Working Directory = "@working_dir@" Pid Directory = "@piddir@" DirPort = @dir_port@ diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-fd.d/client/myself.conf.in index d4c17f837e5..d3978eea8a8 100644 --- a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-fd.d/client/myself.conf.in +++ b/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-fd.d/client/myself.conf.in @@ -7,7 +7,7 @@ Client { # otherwise all filedaemon plugins (*-fd.so) from the "Plugin Directory". # Plugin Directory = "@fd_plugin_binary_path@" - Plugin Names = "@plugin_name@" + Plugin Names = "@python_version@" # if compatible is set to yes, we are compatible with bacula # if set to no, new bareos features are enabled which is the default diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in b/systemtests/tests/pyplug-sd/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in index f6bc3ba1449..7b27afe81df 100644 --- a/systemtests/tests/pyplug-sd/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in +++ b/systemtests/tests/pyplug-sd/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in @@ -7,7 +7,7 @@ Storage { # otherwise all storage plugins (*-sd.so) from the "Plugin Directory". # Plugin Directory = "@sd_plugin_binary_path@" - Plugin Names = "python" + Plugin Names = "@python_version@" Working Directory = "@working_dir@" Pid Directory = "@piddir@" SD Port = @sd_port@ diff --git a/systemtests/tests/python3-dir-plugin-test b/systemtests/tests/python3-dir-plugin-test new file mode 120000 index 00000000000..f6f0f4a897f --- /dev/null +++ b/systemtests/tests/python3-dir-plugin-test @@ -0,0 +1 @@ +python-dir-plugin-test \ No newline at end of file diff --git a/systemtests/tests/python3-sd-plugin-test b/systemtests/tests/python3-sd-plugin-test new file mode 120000 index 00000000000..e67f6882c9d --- /dev/null +++ b/systemtests/tests/python3-sd-plugin-test @@ -0,0 +1 @@ +python-sd-plugin-test \ No newline at end of file From bfded94a55175f9f20714890360ee284233f0fe9 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 15 May 2020 18:41:31 +0200 Subject: [PATCH 112/341] python: cleanup --- core/src/plugins/dird/CMakeLists.txt | 4 ++-- core/src/plugins/dird/python/bareosdir.h | 20 ++---------------- core/src/plugins/dird/python/python-dir.cc | 6 +++--- .../dird/python/test/bareosdir_test.py | 2 +- core/src/plugins/filed/python/bareosfd.h | 5 +++-- core/src/plugins/filed/python/python-fd.cc | 6 +++--- core/src/plugins/stored/python/bareossd.h | 21 +++---------------- core/src/plugins/stored/python/python-sd.cc | 5 ++--- systemtests/CMakeLists.txt | 17 +++++++++------ .../bareos-dir.d/director/bareos-dir.conf.in | 2 +- 10 files changed, 31 insertions(+), 57 deletions(-) diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index b7bdc69b02c..7029a0b21d6 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -37,7 +37,7 @@ if(Python2_FOUND) # do not prefix with "lib" set_target_properties(python-dir PROPERTIES PREFIX "") install(TARGETS python-dir DESTINATION ${plugindir}) - target_link_libraries(python-dir ${Python_LIBRARIES} bareos) + target_link_libraries(python-dir ${Python2_LIBRARIES} bareos) add_dependencies(python-dir bareosdir-python2-module) set(PYFILES @@ -87,7 +87,7 @@ if(Python3_FOUND) # do not prefix with "lib" set_target_properties(python3-dir PROPERTIES PREFIX "") install(TARGETS python3-dir DESTINATION ${plugindir}) - target_link_libraries(python3-dir ${Python_LIBRARIES} bareos) + target_link_libraries(python3-dir ${Python3_LIBRARIES} bareos) add_dependencies(python3-dir bareosdir-python3-module) set(PYFILES diff --git a/core/src/plugins/dird/python/bareosdir.h b/core/src/plugins/dird/python/bareosdir.h index 9f6ee03b4c0..e5b76f0b637 100644 --- a/core/src/plugins/dird/python/bareosdir.h +++ b/core/src/plugins/dird/python/bareosdir.h @@ -92,7 +92,6 @@ using namespace directordaemon; /* variables storing bareos pointers */ PluginContext* plugin_context = NULL; -static void* bareos_core_functions = NULL; MOD_INIT(bareosdir) { @@ -108,27 +107,12 @@ MOD_INIT(bareosdir) c_api_object = PyCapsule_New((void*)Bareosdir_API, PYTHON_MODULE_NAME_QUOTED "._C_API", NULL); - if (c_api_object != NULL) PyModule_AddObject(m, "_C_API", c_api_object); - - /* add bPluginFunctions Capsule */ - PyObject* PyModulePluginFuncs = - PyCapsule_New((void*)&bareos_core_functions, - PYTHON_MODULE_NAME_QUOTED ".CoreFunctions", NULL); - if (!PyModulePluginFuncs) { - printf(PYTHON_MODULE_NAME_QUOTED ":CoreFunctions PyCapsule_New failed\n"); - return MOD_ERROR_VAL; - } - if (PyModulePluginFuncs) { - PyModule_AddObject(m, "CoreFunctions", PyModulePluginFuncs); - printf(PYTHON_MODULE_NAME_QUOTED ": added CoreFunctions@%p\n", - &bareos_core_functions); + if (c_api_object != NULL) { + PyModule_AddObject(m, "_C_API", c_api_object); } else { - printf(PYTHON_MODULE_NAME_QUOTED - ":CoreFunctions PyModule_AddObject failed\n"); return MOD_ERROR_VAL; } - /* module dictionaries */ DEFINE_bRCs_DICT(); DEFINE_bJobMessageTypes_DICT(); diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index 37127b3125e..84b63dfa02d 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -182,7 +182,7 @@ static void PyErrorHandler() Py_DECREF(type); Py_XDECREF(value); Py_XDECREF(traceback); - printf("%s", error_string); + // printf("%s", error_string); free(error_string); exit(1); @@ -206,9 +206,9 @@ bRC loadPlugin(PluginApiDefinition* lbareos_plugin_interface_version, /* import the bareosdir module */ PyObject* bareosdirModule = PyImport_ImportModule("bareosdir"); if (bareosdirModule) { - printf("loaded bareosdir successfully\n"); + // printf("loaded bareosdir successfully\n"); } else { - printf("loading of bareosdir failed\n"); + // printf("loading of bareosdir failed\n"); if (PyErr_Occurred()) { PyErrorHandler(); } } diff --git a/core/src/plugins/dird/python/test/bareosdir_test.py b/core/src/plugins/dird/python/test/bareosdir_test.py index 8b1e7aeba76..09bc5272ad8 100644 --- a/core/src/plugins/dird/python/test/bareosdir_test.py +++ b/core/src/plugins/dird/python/test/bareosdir_test.py @@ -2,7 +2,7 @@ import bareosdir import time -print help(bareosdir) +print (help(bareosdir)) class TestBareosFd(unittest.TestCase): diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/bareosfd.h index 0540589cb76..a6f2112d944 100644 --- a/core/src/plugins/filed/python/bareosfd.h +++ b/core/src/plugins/filed/python/bareosfd.h @@ -788,10 +788,11 @@ MOD_INIT(bareosfd) c_api_object = PyCapsule_New((void*)Bareosfd_API, PYTHON_MODULE_NAME_QUOTED "._C_API", NULL); - if (c_api_object != NULL) + if (c_api_object != NULL) { PyModule_AddObject(m, "_C_API", c_api_object); - else + } else { return MOD_ERROR_VAL; + } PyRestoreObjectType.tp_new = PyType_GenericNew; if (PyType_Ready(&PyRestoreObjectType) < 0) { return MOD_ERROR_VAL; } diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index d2d913a6643..b4a4051f31e 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -158,7 +158,7 @@ static void PyErrorHandler() Py_DECREF(type); Py_XDECREF(value); Py_XDECREF(traceback); - printf("%s", error_string); + // printf("%s", error_string); free(error_string); exit(1); @@ -179,9 +179,9 @@ bRC loadPlugin(PluginApiDefinition* lbareos_plugin_interface_version, /* import the bareosfd module */ PyObject* bareosfdModule = PyImport_ImportModule("bareosfd"); if (bareosfdModule) { - printf("loaded bareosfd successfully\n"); + // printf("loaded bareosfd successfully\n"); } else { - printf("loading of bareosfd failed\n"); + // printf("loading of bareosfd failed\n"); if (PyErr_Occurred()) { PyErrorHandler(); } } diff --git a/core/src/plugins/stored/python/bareossd.h b/core/src/plugins/stored/python/bareossd.h index 295ed340fa2..ae527158721 100644 --- a/core/src/plugins/stored/python/bareossd.h +++ b/core/src/plugins/stored/python/bareossd.h @@ -103,27 +103,12 @@ MOD_INIT(bareossd) c_api_object = PyCapsule_New((void*)Bareossd_API, PYTHON_MODULE_NAME_QUOTED "._C_API", NULL); - if (c_api_object != NULL) PyModule_AddObject(m, "_C_API", c_api_object); -#if 0 - /* add bPluginFunctions Capsule */ - PyObject* PyModulePluginFuncs = - PyCapsule_New((void*)&bareos_core_functions, - PYTHON_MODULE_NAME_QUOTED ".CoreFunctions", NULL); - if (!PyModulePluginFuncs) { - printf(PYTHON_MODULE_NAME_QUOTED - ":CoreFunctions PyCapsule_New failed\n"); - return MOD_ERROR_VAL; - } - if (PyModulePluginFuncs) { - PyModule_AddObject(m, "CoreFunctions", PyModulePluginFuncs); - printf(PYTHON_MODULE_NAME_QUOTED ": added CoreFunctions@%p\n", - &bareos_core_functions); + if (c_api_object != NULL) { + PyModule_AddObject(m, "_C_API", c_api_object); } else { - printf(PYTHON_MODULE_NAME_QUOTED - ":CoreFunctions PyModule_AddObject failed\n"); return MOD_ERROR_VAL; } -#endif + /* module dictionaries */ DEFINE_bRCs_DICT(); DEFINE_bJobMessageTypes_DICT(); diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index 4d8e60c9b0e..d2e75f4d443 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -182,7 +182,6 @@ static void PyErrorHandler() Py_DECREF(type); Py_XDECREF(value); Py_XDECREF(traceback); - printf("%s", error_string); free(error_string); exit(1); @@ -206,9 +205,9 @@ bRC loadPlugin(PluginApiDefinition* lbareos_plugin_interface_version, /* import the bareossd module */ PyObject* bareossdModule = PyImport_ImportModule("bareossd"); if (bareossdModule) { - printf("loaded bareossd successfully\n"); + // printf("loaded bareossd successfully\n"); } else { - printf("loading of bareossd failed\n"); + // printf("loading of bareossd failed\n"); if (PyErr_Occurred()) { PyErrorHandler(); } } diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index c8f429a7cc0..8546ce53a26 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -690,10 +690,16 @@ else() list(APPEND SYSTEM_TESTS_DISABLED "pyplug-dir") endif() -if(TARGET python-sd) - list(APPEND SYSTEM_TESTS "pyplug-sd") +if(TARGET python3-dir) + list(APPEND SYSTEM_TESTS "python3-dir-plugin-test") else() - list(APPEND SYSTEM_TESTS_DISABLED "pyplug-sd") + list(APPEND SYSTEM_TESTS_DISABLED "python3-dir-plugin-test") +endif() + +if(TARGET python3-sd) + list(APPEND SYSTEM_TESTS "python3-sd-plugin-test") +else() + list(APPEND SYSTEM_TESTS_DISABLED "python3-sd-plugin-test") endif() message(STATUS "Looking for pam test requirements ...") @@ -800,9 +806,8 @@ foreach(TEST_NAME ${SYSTEM_TESTS}) message(STATUS "Configuring test: ${SYSTEMTEST_PREFIX}${TEST_NAME}") # string(REGEX MATCH "^python[^-]?-(fd|sd|dir)" PLUGIN_NAME "${TEST_NAME}") string(REGEX MATCH "^python[^-]?" python_version "${TEST_NAME}") - if(python_version) - message(STATUS "python_version:" ${python_version}) # python or python3 - endif() + # if(python_version) message(STATUS "python_version:" ${python_version}) # + # python or python3 endif() prepare_test() configurefilestosystemtest("systemtests" "tests/${TEST_NAME}" "*" @ONLY "") diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in b/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in index ec8127d61ad..b62199bae0d 100644 --- a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in +++ b/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in @@ -20,7 +20,7 @@ Director { # define myself # otherwise all director plugins (*-dir.so) from the "Plugin Directory". # Plugin Directory = "@dir_plugin_binary_path@" - Plugin Names = "@python-version@" + Plugin Names = "@python_version@" Working Directory = "@working_dir@" Pid Directory = "@piddir@" DirPort = @dir_port@ From 075c61e29289532f11be26c4ce247c3144df173a Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 08:13:06 +0200 Subject: [PATCH 113/341] python tests: load the correct module (python / python3) --- .../etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in | 2 +- .../etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in | 2 +- .../etc/bareos/bareos-dir.d/fileset/OvirtTest.conf.in | 2 +- systemtests/tests/pyplug-fd-ovirt/testrunner | 2 +- .../bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in | 2 +- .../etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in b/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in index eef9dbe1f74..8b71aa56c39 100644 --- a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in +++ b/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in @@ -1,6 +1,6 @@ Job { Name = "backup-bareos-fd" - DIR Plugin Options ="python:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-dir-test:output=@tmp@/test-plugin.log" + DIR Plugin Options ="@python_version@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-dir-test:output=@tmp@/test-plugin.log" JobDefs = "DefaultJob" Client = "bareos-fd" } diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in index 05b0219b9a8..078a558a772 100644 --- a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in +++ b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in @@ -5,6 +5,6 @@ FileSet { Options { signature = MD5 } - Plugin = "python:module_path=@python_plugin_module_src_test_dir@:module_name=bareos_fd_local_fileset_with_restoreobjects:filename=@tmpdir@/file-list" + Plugin = "@python_version@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos_fd_local_fileset_with_restoreobjects:filename=@tmpdir@/file-list" } } diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/OvirtTest.conf.in b/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/OvirtTest.conf.in index 3ec20b67613..cddb4fe1551 100644 --- a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/OvirtTest.conf.in +++ b/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/OvirtTest.conf.in @@ -5,6 +5,6 @@ FileSet { Options { signature = MD5 } - Plugin = "python:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-ovirt:ca=@current_test_directory@/etc/bareos/ovirt-ca.cert:server=@ovirt_server@:username=@ovirt_user@:password=@ovirt_password@:vm_name=@ovirt_vm_name@:include_disk_aliases=@ovirt_include_disk_alias@" + Plugin = "@python_version@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-ovirt:ca=@current_test_directory@/etc/bareos/ovirt-ca.cert:server=@ovirt_server@:username=@ovirt_user@:password=@ovirt_password@:vm_name=@ovirt_vm_name@:include_disk_aliases=@ovirt_include_disk_alias@" } } diff --git a/systemtests/tests/pyplug-fd-ovirt/testrunner b/systemtests/tests/pyplug-fd-ovirt/testrunner index 36317e69d7b..90915d5b9e7 100755 --- a/systemtests/tests/pyplug-fd-ovirt/testrunner +++ b/systemtests/tests/pyplug-fd-ovirt/testrunner @@ -49,7 +49,7 @@ messages @# @$out $tmp/log2.out wait -restore client=bareos-fd fileset=OvirtTest where=$tmp/bareos-restores pluginoptions=python:local=yes select all done +restore client=bareos-fd fileset=OvirtTest where=$tmp/bareos-restores pluginoptions=@python_version@:local=yes select all done yes wait messages diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in b/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in index 3262866b0fc..97bce7fc929 100644 --- a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in +++ b/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in @@ -5,6 +5,6 @@ FileSet { Options { signature = MD5 } - Plugin = "python:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-percona-xtrabackup:dumpbinary=@XTRABACKUP@:extradumpoptions=@extradumpoptions@" + Plugin = "@python_version@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-percona-xtrabackup:dumpbinary=@XTRABACKUP@:extradumpoptions=@extradumpoptions@" } } diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in b/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in index 4f7736d7bba..b178362d83b 100644 --- a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in +++ b/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in @@ -1,6 +1,6 @@ Job { Name = "backup-bareos-fd" - SD Plugin Options = "python:instance=0:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-sd-test:output=@tmp@/test-plugin.log" + SD Plugin Options = "@python_version@:instance=0:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-sd-test:output=@tmp@/test-plugin.log" JobDefs = "DefaultJob" Client = "bareos-fd" } From c2f758b48419f607d21f344213671de6e54ef9a1 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 10:00:55 +0200 Subject: [PATCH 114/341] dird plugin: fix INCLUDE_DIRS typo;remove commented out parts --- core/src/plugins/dird/CMakeLists.txt | 2 +- core/src/plugins/dird/python/python-dir.cc | 1 - core/src/plugins/filed/python/python-fd.cc | 3 --- core/src/plugins/python_plugins_common.inc | 1 - core/src/plugins/stored/python/python-sd.cc | 1 - 5 files changed, 1 insertion(+), 7 deletions(-) diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index 7029a0b21d6..3c235c4b510 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -81,7 +81,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) endif() if(Python3_FOUND) - include_directories(SYSTEM ${Python2_INCLUDE_DIRS}) + include_directories(SYSTEM ${Python3_INCLUDE_DIRS}) add_library(python3-dir MODULE python/python-dir.cc) # do not prefix with "lib" diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index 84b63dfa02d..c4c7ab16a60 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -165,7 +165,6 @@ static void PyErrorHandler() (char*)"OOO", type, value == NULL ? Py_None : value, traceback == NULL ? Py_None : traceback); - // emptyString = PyUnicode_FromString(""); emptyString = PyUnicode_FromString(""); strRetval = PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index b4a4051f31e..dc4a2fe06da 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -141,7 +141,6 @@ static void PyErrorHandler() (char*)"OOO", type, value == NULL ? Py_None : value, traceback == NULL ? Py_None : traceback); - // emptyString = PyString_FromString(""); emptyString = PyUnicode_FromString(""); strRetval = PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); @@ -968,7 +967,6 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) Dmsg(plugin_ctx, debuglevel, "python-fd: Trying to load module with name %s\n", plugin_priv_ctx->module_name); - // pName = PyString_FromString(plugin_priv_ctx->module_name); pName = PyUnicode_FromString(plugin_priv_ctx->module_name); plugin_priv_ctx->pModule = PyImport_Import(pName); Py_DECREF(pName); @@ -988,7 +986,6 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) plugin_priv_ctx->pyModuleFunctionsDict = PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ - // StorePluginContextInPythonModule(plugin_ctx); /* Lookup the load_bareos_plugin() function in the python module. */ pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, diff --git a/core/src/plugins/python_plugins_common.inc b/core/src/plugins/python_plugins_common.inc index c668ad29d71..0b0237b1b07 100644 --- a/core/src/plugins/python_plugins_common.inc +++ b/core/src/plugins/python_plugins_common.inc @@ -102,7 +102,6 @@ static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype) (char*)"OOO", type, value == NULL ? Py_None : value, traceback == NULL ? Py_None : traceback); - // emptyString = PyString_FromString(""); emptyString = PyUnicode_FromString(""); strRetval = PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index d2e75f4d443..232cc329d24 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -165,7 +165,6 @@ static void PyErrorHandler() (char*)"OOO", type, value == NULL ? Py_None : value, traceback == NULL ? Py_None : traceback); - // emptyString = PyUnicode_FromString(""); emptyString = PyUnicode_FromString(""); strRetval = PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); From 6b3ebe5e208d3689c69e288c64af961326f45342 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 10:35:12 +0200 Subject: [PATCH 115/341] plugin CMakeLists: use target_include_directories --- core/src/plugins/dird/CMakeLists.txt | 6 ++---- core/src/plugins/stored/CMakeLists.txt | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index 3c235c4b510..ad52fdfeff2 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -31,13 +31,12 @@ if(HAVE_WIN32) endif() if(Python2_FOUND) - include_directories(SYSTEM ${Python2_INCLUDE_DIRS}) - add_library(python-dir MODULE python/python-dir.cc) # do not prefix with "lib" set_target_properties(python-dir PROPERTIES PREFIX "") install(TARGETS python-dir DESTINATION ${plugindir}) target_link_libraries(python-dir ${Python2_LIBRARIES} bareos) + target_include_directories(python-dir PUBLIC SYSTEM ${Python2_INCLUDE_DIRS}) add_dependencies(python-dir bareosdir-python2-module) set(PYFILES @@ -81,13 +80,12 @@ if(Python2_FOUND AND NOT HAVE_WIN32) endif() if(Python3_FOUND) - include_directories(SYSTEM ${Python3_INCLUDE_DIRS}) - add_library(python3-dir MODULE python/python-dir.cc) # do not prefix with "lib" set_target_properties(python3-dir PROPERTIES PREFIX "") install(TARGETS python3-dir DESTINATION ${plugindir}) target_link_libraries(python3-dir ${Python3_LIBRARIES} bareos) + target_include_directories(python3-dir PUBLIC SYSTEM ${Python3_INCLUDE_DIRS}) add_dependencies(python3-dir bareosdir-python3-module) set(PYFILES diff --git a/core/src/plugins/stored/CMakeLists.txt b/core/src/plugins/stored/CMakeLists.txt index 8d2077ea17d..3bf88f8115c 100644 --- a/core/src/plugins/stored/CMakeLists.txt +++ b/core/src/plugins/stored/CMakeLists.txt @@ -49,11 +49,11 @@ if(NOT HAVE_WIN32 AND NOT HAVE_DARWIN_OS) endif() if(Python2_FOUND) - include_directories(SYSTEM ${Python2_INCLUDE_DIRS}) add_library(python-sd MODULE python/python-sd.cc) set_target_properties(python-sd PROPERTIES PREFIX "") install(TARGETS python-sd DESTINATION ${plugindir}) target_link_libraries(python-sd ${Python2_LIBRARIES} bareos) + target_include_directories(python-sd PUBLIC SYSTEM ${Python3_INCLUDE_DIRS}) add_dependencies(python-sd bareossd-python2-module) set(PYFILES @@ -97,11 +97,11 @@ if(Python2_FOUND AND NOT HAVE_WIN32) endif() if(Python3_FOUND) - include_directories(SYSTEM ${Python3_INCLUDE_DIRS}) add_library(python3-sd MODULE python/python-sd.cc) set_target_properties(python3-sd PROPERTIES PREFIX "") install(TARGETS python3-sd DESTINATION ${plugindir}) target_link_libraries(python3-sd ${Python3_LIBRARIES} bareos) + target_include_directories(python3-sd PUBLIC SYSTEM ${Python3_INCLUDE_DIRS}) add_dependencies(python3-sd bareossd-python3-module) set(PYFILES From 7c9fce10e4219ee1ce4095bed5f7cb1a8b55a319 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 10:42:41 +0200 Subject: [PATCH 116/341] bareos-dir-test.py: fix bRCs --- .../tests/pyplug-dir/python-modules/bareos-dir-test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/systemtests/tests/pyplug-dir/python-modules/bareos-dir-test.py b/systemtests/tests/pyplug-dir/python-modules/bareos-dir-test.py index dcef111a4cf..cb273d02aef 100644 --- a/systemtests/tests/pyplug-dir/python-modules/bareos-dir-test.py +++ b/systemtests/tests/pyplug-dir/python-modules/bareos-dir-test.py @@ -49,10 +49,10 @@ def parse_plugin_definition(plugindef): elif key == "module_name": continue else: - return bRCs["bRC_Error"] + return bRC_Error toFile(outputfile) - return bRCs["bRC_OK"] + return bRC_OK def handle_plugin_event(event): @@ -68,7 +68,7 @@ def handle_plugin_event(event): elif event == bDirEventJobRun: toFile("bDirEventJobRun\n") - return bRCs["bRC_OK"] + return bRC_OK def toFile(text): From 94bd63fefe6911e64d9735cdcfabd7ef2493ff84 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 10:58:44 +0200 Subject: [PATCH 117/341] bareos-sd-test.py: works with python3 --- systemtests/CMakeLists.txt | 6 ++++ .../python-modules/bareos-sd-test.py | 34 +++++++++---------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 8546ce53a26..73d551c67c2 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -696,6 +696,12 @@ else() list(APPEND SYSTEM_TESTS_DISABLED "python3-dir-plugin-test") endif() +if(TARGET python-sd) + list(APPEND SYSTEM_TESTS "python-sd-plugin-test") +else() + list(APPEND SYSTEM_TESTS_DISABLED "python-sd-plugin-test") +endif() + if(TARGET python3-sd) list(APPEND SYSTEM_TESTS "python3-sd-plugin-test") else() diff --git a/systemtests/tests/pyplug-sd/python-modules/bareos-sd-test.py b/systemtests/tests/pyplug-sd/python-modules/bareos-sd-test.py index a99ffa2ffe5..05fa09424dc 100644 --- a/systemtests/tests/pyplug-sd/python-modules/bareos-sd-test.py +++ b/systemtests/tests/pyplug-sd/python-modules/bareos-sd-test.py @@ -58,43 +58,43 @@ def parse_plugin_definition(plugindef): elif key == "module_name": continue else: - return bRCs["bRC_Error"] + return bRC_Error toFile(outputfile) - return bRCs["bRC_OK"] + return bRC_OK def handle_plugin_event(event): - if event == bsdEventType["bsdEventJobStart"]: + if event == bsdEventJobStart: toFile("bsdEventJobStart\n") - elif event == bsdEventType["bsdEventDeviceReserve"]: + elif event == bsdEventDeviceReserve: toFile("bsdEventDeviceReserve\n") - elif event == bsdEventType["bsdEventVolumeUnload"]: + elif event == bsdEventVolumeUnload: toFile("bsdEventVolumeUnload\n") - elif event == bsdEventType["bsdEventVolumeLoad"]: + elif event == bsdEventVolumeLoad: toFile("bsdEventVolumeLoad\n") - elif event == bsdEventType["bsdEventDeviceOpen"]: + elif event == bsdEventDeviceOpen: toFile("bsdEventDeviceOpen\n") - elif event == bsdEventType["bsdEventDeviceMount"]: + elif event == bsdEventDeviceMount: toFile("bsdEventDeviceMount\n") - elif event == bsdEventType["bsdEventLabelRead"]: + elif event == bsdEventLabelRead: toFile("bsdEventLabelRead\n") - elif event == bsdEventType["bsdEventLabelVerified"]: + elif event == bsdEventLabelVerified: toFile("bsdEventLabelVerified\n") - elif event == bsdEventType["bsdEventLabelWrite"]: + elif event == bsdEventLabelWrite: toFile("bsdEventLabelWrite\n") - elif event == bsdEventType["bsdEventSetupRecordTranslation"]: + elif event == bsdEventSetupRecordTranslation: toFile("bsdEventSetupRecordTranslation\n") - elif event == bsdEventType["bsdEventWriteRecordTranslation"]: + elif event == bsdEventWriteRecordTranslation: toFile("bsdEventWriteRecordTranslation\n") - elif event == bsdEventType["bsdEventDeviceUnmount"]: + elif event == bsdEventDeviceUnmount: toFile("bsdEventDeviceUnmount\n") - elif event == bsdEventType["bsdEventDeviceClose"]: + elif event == bsdEventDeviceClose: toFile("bsdEventDeviceClose\n") - elif event == bsdEventType["bsdEventJobEnd"]: + elif event == bsdEventJobEnd: toFile("bsdEventJobEnd\n") - return bRCs["bRC_OK"] + return bRC_OK def toFile(text): From 59f83367a67a637680f373a62620958856339a38 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 11:57:56 +0200 Subject: [PATCH 118/341] bareosfd.cc: use original parse string, fix typo in stored cmakelists --- core/src/plugins/filed/python/bareosfd.cc | 15 +++++---------- core/src/plugins/stored/CMakeLists.txt | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index df2b5e0b7c3..39de41722ac 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -2109,16 +2109,11 @@ static int PySavePacket_init(PySavePacket* self, PyObject* args, PyObject* kwds) self->object_index = 0; if (!PyArg_ParseTupleAndKeywords( - args, kwds, -#if PY_VERSION_HEX < 0x03000000 - "|OOiOpppsiiOOii", -#else - "|ooiocccsiiooii", -#endif - kwlist, &self->fname, &self->link, &self->type, &self->flags, - &self->no_read, &self->portable, &self->accurate_found, &self->cmd, - &self->save_time, &self->delta_seq, &self->object_name, &self->object, - &self->object_len, &self->object_index)) { + args, kwds, "|OOiOpppsiiOOii", kwlist, &self->fname, &self->link, + &self->type, &self->flags, &self->no_read, &self->portable, + &self->accurate_found, &self->cmd, &self->save_time, &self->delta_seq, + &self->object_name, &self->object, &self->object_len, + &self->object_index)) { return -1; } return 0; diff --git a/core/src/plugins/stored/CMakeLists.txt b/core/src/plugins/stored/CMakeLists.txt index 3bf88f8115c..6274323fb3a 100644 --- a/core/src/plugins/stored/CMakeLists.txt +++ b/core/src/plugins/stored/CMakeLists.txt @@ -53,7 +53,7 @@ if(Python2_FOUND) set_target_properties(python-sd PROPERTIES PREFIX "") install(TARGETS python-sd DESTINATION ${plugindir}) target_link_libraries(python-sd ${Python2_LIBRARIES} bareos) - target_include_directories(python-sd PUBLIC SYSTEM ${Python3_INCLUDE_DIRS}) + target_include_directories(python-sd PUBLIC SYSTEM ${Python2_INCLUDE_DIRS}) add_dependencies(python-sd bareossd-python2-module) set(PYFILES From 567c5ff50c74cd6530601d45f6460d99d691eacf Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 12:35:27 +0200 Subject: [PATCH 119/341] python plugins: use Py_RETURN_NONE where applicable --- core/src/plugins/dird/python/bareosdir.cc | 413 +----------------- .../dird/python/test/bareosdir_test.py | 7 +- core/src/plugins/filed/CMakeLists.txt | 2 +- core/src/plugins/filed/python/bareosfd.cc | 17 +- core/src/plugins/stored/python/bareossd.cc | 16 +- 5 files changed, 17 insertions(+), 438 deletions(-) diff --git a/core/src/plugins/dird/python/bareosdir.cc b/core/src/plugins/dird/python/bareosdir.cc index 3b35ccd8063..2ff8c3e0268 100644 --- a/core/src/plugins/dird/python/bareosdir.cc +++ b/core/src/plugins/dird/python/bareosdir.cc @@ -269,10 +269,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) break; } - if (!pRetVal) { - Py_INCREF(Py_None); - pRetVal = Py_None; - } + if (!pRetVal) { Py_RETURN_NONE; } return pRetVal; } @@ -346,8 +343,7 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) if (dbgmsg) { Dmsg(plugin_ctx, level, "python-dir: %s", dbgmsg); } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /** @@ -368,8 +364,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) if (jobmsg) { Jmsg(plugin_ctx, type, "python-dir: %s", jobmsg); } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /** @@ -474,407 +469,9 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) pRetVal = PyLong_FromLong(value); } - if (!pRetVal) { - Py_INCREF(Py_None); - pRetVal = Py_None; - } - - return pRetVal; -} - -#if 0 -/** - * Any plugin options which are passed in are dispatched here to a Python method - * and it can parse the plugin options. This function is also called after - * PyLoadModule() has loaded the Python module and made sure things are - * operational. - */ -static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value) -{ - bRC retval = bRC_Error; - struct plugin_private_context* plugin_priv_ctx = - (struct plugin_private_context*)plugin_ctx->plugin_private_context; - PyObject* pFunc; - - /* - * Lookup the parse_plugin_definition() function in the python module. - */ - pFunc = - PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "parse_plugin_definition"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyObject *pPluginDefinition, *pRetVal; - - pPluginDefinition = PyUnicode_FromString((char*)value); - if (!pPluginDefinition) { goto bail_out; } - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); - Py_DECREF(pPluginDefinition); - - if (!pRetVal) { - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - } - - return retval; - } else { - Dmsg(plugin_ctx, debuglevel, - "python-dir: Failed to find function named " - "parse_plugin_definition()\n"); - return bRC_Error; - } - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } - - return retval; -} - -static bRC PyGetPluginValue(PluginContext* plugin_ctx, - pVariable var, - void* value) -{ - return bRC_OK; -} - -static bRC PySetPluginValue(PluginContext* plugin_ctx, - pVariable var, - void* value) -{ - return bRC_OK; -} - -static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, - bDirEvent* event, - void* value) -{ - bRC retval = bRC_Error; - plugin_private_context* plugin_priv_ctx = - (plugin_private_context*)plugin_ctx->plugin_private_context; - PyObject* pFunc; - - /* - * Lookup the handle_plugin_event() function in the python module. - */ - pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, - "handle_plugin_event"); /* Borrowed reference */ - if (pFunc && PyCallable_Check(pFunc)) { - PyObject *pEventType, *pRetVal; - - pEventType = PyLong_FromLong(event->eventType); - - pRetVal = PyObject_CallFunctionObjArgs(pFunc, pEventType, NULL); - Py_DECREF(pEventType); - - if (!pRetVal) { - goto bail_out; - } else { - retval = ConvertPythonRetvalTobRCRetval(pRetVal); - Py_DECREF(pRetVal); - } - } else { - Dmsg(plugin_ctx, debuglevel, - "python-dir: Failed to find function named handle_plugin_event()\n"); - } - - return retval; - -bail_out: - if (PyErr_Occurred()) { PyErrorHandler(plugin_ctx, M_FATAL); } - - return retval; -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to get certain internal values of the current Job. - */ -static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) -{ - int var; - PluginContext* plugin_ctx = plugin_context; - PyObject* pRetVal = NULL; - - if (!PyArg_ParseTuple(args, "i:BareosGetValue", &var)) { return NULL; } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - switch (var) { - case bDirVarJobId: - case bDirVarLevel: - case bDirVarType: - case bDirVarNumVols: - case bDirVarJobStatus: - case bDirVarPriority: - case bDirVarFDJobStatus: - case bDirVarSDJobStatus: { - int value = 0; - - if (bareos_core_functions->getBareosValue(plugin_ctx, (brDirVariable)var, - &value) == bRC_OK) { - pRetVal = PyLong_FromLong(value); - } - break; - } - case bDirVarJobErrors: - case bDirVarSDErrors: - case bDirVarJobFiles: - case bDirVarSDJobFiles: - case bDirVarLastRate: - case bDirVarJobBytes: - case bDirVarReadBytes: { - uint64_t value = 0; - - if (bareos_core_functions->getBareosValue(plugin_ctx, (brDirVariable)var, - &value) == bRC_OK) { - pRetVal = PyLong_FromUnsignedLong(value); - } - break; - } - case bDirVarJobName: - case bDirVarJob: - case bDirVarClient: - case bDirVarPool: - case bDirVarStorage: - case bDirVarWriteStorage: - case bDirVarReadStorage: - case bDirVarCatalog: - case bDirVarMediaType: - case bDirVarVolumeName: { - char* value = NULL; - - if (bareos_core_functions->getBareosValue(plugin_ctx, (brDirVariable)var, - &value) == bRC_OK) { - if (value) { pRetVal = PyUnicode_FromString(value); } - } - break; - } - case bDirVarPluginDir: { - char* value = NULL; - - if (bareos_core_functions->getBareosValue(NULL, (brDirVariable)var, - &value) == bRC_OK) { - if (value) { pRetVal = PyUnicode_FromString(value); } - } - break; - } - default: - Dmsg(plugin_ctx, debuglevel, - "python-dir: PyBareosGetValue unknown variable requested %d\n", var); - break; - } - - if (!pRetVal) { - Py_INCREF(Py_None); - pRetVal = Py_None; - } - - return pRetVal; -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to set certain internal values of the current Job. - */ -static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) -{ - int var; - PluginContext* plugin_ctx = plugin_context; - bRC retval = bRC_Error; - PyObject* pyValue; - - if (!PyArg_ParseTuple(args, "iO:BareosSetValue", &var, &pyValue)) { - goto bail_out; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - switch (var) { - case bwDirVarVolumeName: { - char* value; - - value = PyUnicode_AsUTF8(pyValue); - if (value) { - retval = bareos_core_functions->setBareosValue( - plugin_ctx, (bwDirVariable)var, value); - } - - break; - } - case bwDirVarPriority: - case bwDirVarJobLevel: { - int value; - - value = PyLong_AsLong(pyValue); - if (value >= 0) { - retval = bareos_core_functions->setBareosValue( - plugin_ctx, (bwDirVariable)var, &value); - } - break; - } - default: - Dmsg(plugin_ctx, debuglevel, - "python-dir: PyBareosSetValue unknown variable requested %d\n", var); - break; - } - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue debug messages using the Bareos debug message - * facility. - */ -static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) -{ - int level; - char* dbgmsg = NULL; - PluginContext* plugin_ctx = plugin_context; - - if (!PyArg_ParseTuple(args, "i|z:BareosDebugMessage", &level, &dbgmsg)) { - return NULL; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - if (dbgmsg) { Dmsg(plugin_ctx, level, "python-dir: %s", dbgmsg); } - - Py_INCREF(Py_None); - return Py_None; -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue Job messages using the Bareos Job message - * facility. - */ -static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) -{ - int type; - char* jobmsg = NULL; - PluginContext* plugin_ctx = plugin_context; - - if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { - return NULL; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - if (jobmsg) { Jmsg(plugin_ctx, type, "python-dir: %s", jobmsg); } - - Py_INCREF(Py_None); - return Py_None; -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a Register Event to register additional events - * it wants to receive. - */ -static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) -{ - int len, event; - PluginContext* plugin_ctx = plugin_context; - bRC retval = bRC_Error; - PyObject *pyEvents, *pySeq, *pyEvent; - - if (!PyArg_ParseTuple(args, "O:BareosRegisterEvents", &pyEvents)) { - goto bail_out; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); - if (!pySeq) { goto bail_out; } - - len = PySequence_Fast_GET_SIZE(pySeq); - - for (int i = 0; i < len; i++) { - pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); - event = PyLong_AsLong(pyEvent); - - if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { - Dmsg(plugin_ctx, debuglevel, - "python-dir: PyBareosRegisterEvents registering event %d\n", event); - retval = - bareos_core_functions->registerBareosEvents(plugin_ctx, 1, event); - - if (retval != bRC_OK) { break; } - } - } - - Py_DECREF(pySeq); - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue an Unregister Event to unregister events it - * doesn't want to receive anymore. - */ -static PyObject* PyBareosUnRegisterEvents(PyObject* self, PyObject* args) -{ - int len, event; - PluginContext* plugin_ctx = plugin_context; - bRC retval = bRC_Error; - PyObject *pyEvents, *pySeq, *pyEvent; - - if (!PyArg_ParseTuple(args, "O:BareosUnRegisterEvents", &pyEvents)) { - goto bail_out; - } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - pySeq = PySequence_Fast(pyEvents, "Expected a sequence of events"); - if (!pySeq) { goto bail_out; } - - len = PySequence_Fast_GET_SIZE(pySeq); - - for (int i = 0; i < len; i++) { - pyEvent = PySequence_Fast_GET_ITEM(pySeq, i); - event = PyLong_AsLong(pyEvent); - - if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { - Dmsg(plugin_ctx, debuglevel, - "PyBareosUnRegisterEvents: registering event %d\n", event); - retval = - bareos_core_functions->unregisterBareosEvents(plugin_ctx, 1, event); - - if (retval != bRC_OK) { break; } - } - } - - Py_DECREF(pySeq); - -bail_out: - return ConvertbRCRetvalToPythonRetval(retval); -} - -/** - * Callback function which is exposed as a part of the additional methods which - * allow a Python plugin to issue a GetInstanceCount to retrieve the number of - * instances of the current plugin being loaded into the daemon. - */ -static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) -{ - int value; - PluginContext* plugin_ctx = plugin_context; - PyObject* pRetVal = NULL; - - if (!PyArg_ParseTuple(args, ":BareosGetInstanceCount")) { return NULL; } - RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - - if (bareos_core_functions->getInstanceCount(plugin_ctx, &value) == bRC_OK) { - pRetVal = PyLong_FromLong(value); - } - - if (!pRetVal) { - Py_INCREF(Py_None); - pRetVal = Py_None; - } + if (!pRetVal) { Py_RETURN_NONE; } return pRetVal; } -#endif -} /* namespace directordaemon */ +#} /* namespace directordaemon */ diff --git a/core/src/plugins/dird/python/test/bareosdir_test.py b/core/src/plugins/dird/python/test/bareosdir_test.py index 09bc5272ad8..2ed71c8e642 100644 --- a/core/src/plugins/dird/python/test/bareosdir_test.py +++ b/core/src/plugins/dird/python/test/bareosdir_test.py @@ -2,18 +2,15 @@ import bareosdir import time -print (help(bareosdir)) +# print (help(bareosdir)) class TestBareosFd(unittest.TestCase): def test_GetValue(self): self.assertRaises(RuntimeError, bareosdir.GetValue, 1) - self.assertRaises(RuntimeError, bareosdir.GetValue, 1) def test_SetValue(self): - bareosdir.SetValue() - # self.assertRaises(RuntimeError, bareosdir.SetValue) - # self.assertRaises(RuntimeError, bareosdir.SetValue, 2) + self.assertRaises(RuntimeError, bareosdir.SetValue, 2, 2) def test_DebugMessage(self): self.assertRaises(TypeError, bareosdir.DebugMessage, "This is a debug message") diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index b29e915dd80..c78f5e22be5 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -162,7 +162,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) TEST bareosfd-python3-module-tester PROPERTY ENVIRONMENT - PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/python/test/:${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/pyfiles + PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/python/test/:${CMAKE_CURRENT_BINARY_DIR}/python3modules:${CMAKE_CURRENT_SOURCE_DIR}/python/pyfiles ) endif() diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 39de41722ac..47d97571275 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -1355,10 +1355,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) break; } - if (!pRetVal) { - Py_INCREF(Py_None); - pRetVal = Py_None; - } + if (!pRetVal) { Py_RETURN_NONE; } return pRetVal; } @@ -1430,8 +1427,8 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) RETURN_RUNTIME_ERROR_IF_BAREOS_PLUGIN_CTX_UNSET() if (dbgmsg) { Dmsg(plugin_ctx, level, "python-fd: %s", dbgmsg); } - Py_INCREF(Py_None); - return Py_None; + + Py_RETURN_NONE; } /** @@ -1452,8 +1449,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) if (jobmsg) { Jmsg(plugin_ctx, type, "python-fd: %s", jobmsg); } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /** @@ -1554,10 +1550,7 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) pRetVal = PyLong_FromLong(value); } - if (!pRetVal) { - Py_INCREF(Py_None); - pRetVal = Py_None; - } + if (!pRetVal) { Py_RETURN_NONE; } return pRetVal; } diff --git a/core/src/plugins/stored/python/bareossd.cc b/core/src/plugins/stored/python/bareossd.cc index a05db6b3003..ef87c51c94e 100644 --- a/core/src/plugins/stored/python/bareossd.cc +++ b/core/src/plugins/stored/python/bareossd.cc @@ -266,10 +266,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) break; } - if (!pRetVal) { - Py_INCREF(Py_None); - pRetVal = Py_None; - } + if (!pRetVal) { Py_RETURN_NONE; } return pRetVal; } @@ -340,8 +337,7 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) if (dbgmsg) { Dmsg(plugin_ctx, level, "python-sd: %s", dbgmsg); } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /** @@ -362,8 +358,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) if (jobmsg) { Jmsg(plugin_ctx, type, "python-sd: %s", jobmsg); } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /** @@ -476,10 +471,7 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) pRetVal = PyLong_FromLong(value); } - if (!pRetVal) { - Py_INCREF(Py_None); - pRetVal = Py_None; - } + if (!pRetVal) { Py_RETURN_NONE; } return pRetVal; } From 1acaf40bca434b269ad6cd9941dbe78a419edca1 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 13:04:29 +0200 Subject: [PATCH 120/341] python plugins: fix crash of python-fd-module-tester --- core/src/plugins/dird/python/bareosdir.cc | 2 +- core/src/plugins/filed/python/bareosfd.cc | 6 ++-- .../python/test/python-fd-module-tester.cc | 29 ++----------------- 3 files changed, 6 insertions(+), 31 deletions(-) diff --git a/core/src/plugins/dird/python/bareosdir.cc b/core/src/plugins/dird/python/bareosdir.cc index 2ff8c3e0268..ca2df1c6bad 100644 --- a/core/src/plugins/dird/python/bareosdir.cc +++ b/core/src/plugins/dird/python/bareosdir.cc @@ -474,4 +474,4 @@ static PyObject* PyBareosGetInstanceCount(PyObject* self, PyObject* args) return pRetVal; } -#} /* namespace directordaemon */ +} /* namespace directordaemon */ diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/bareosfd.cc index 47d97571275..b4142d2902a 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/bareosfd.cc @@ -1438,16 +1438,16 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) */ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) { - int type; + int level; char* jobmsg = NULL; PluginContext* plugin_ctx = plugin_context; - if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &type, &jobmsg)) { + if (!PyArg_ParseTuple(args, "i|z:BareosJobMessage", &level, &jobmsg)) { return NULL; } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (jobmsg) { Jmsg(plugin_ctx, type, "python-fd: %s", jobmsg); } + if (jobmsg) { Jmsg(plugin_ctx, level, "python-fd: %s", jobmsg); } Py_RETURN_NONE; } diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index adacf9298f0..99962216f4a 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -48,7 +48,6 @@ static void PyErrorHandler() (char*)"OOO", type, value == NULL ? Py_None : value, traceback == NULL ? Py_None : traceback); - // emptyString = PyUnicode_FromString(""); emptyString = PyUnicode_FromString(""); strRetval = PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); @@ -204,33 +203,7 @@ int main(int argc, char* argv[]) PyObject* pModule = PyImport_ImportModule("bareosfd-module-test"); - // Extract capsules pointer from bareosfd module - /* void* ctx_from_bareosfd_module = */ - /* PyCapsule_Import("bareosfd.PluginContext", 0); */ - /* if (!ctx_from_bareosfd_module) { */ - /* printf("importing bareosfd.PluginContext failed \n"); */ - /* } */ - - // Extract capsules pointer from bareosfd module - /* void* bareos_core_functions_from_bareosfd_module = */ - /* PyCapsule_Import("bareosfd.CoreFunctions", 0); */ - /* if (!bareos_core_functions_from_bareosfd_module) { */ - /* printf("importing bareosfd.CoreFunctions failed \n"); */ - /* } */ - - /* *(void**)ctx_from_bareosfd_module = &bareos_PluginContext; */ - /* *(void**)bareos_core_functions_from_bareosfd_module = - * &bareos_core_functions; */ - - - /* printf("ctx_from_bareosfd_module contains %p\n", */ - /* *(void**)ctx_from_bareosfd_module); */ - /* printf("bareos_core_functions_from_bareosfd_module contains %p\n", */ - /* *(void**)bareos_core_functions_from_bareosfd_module); */ - - if (PyErr_Occurred()) { PyErrorHandler(); } - PyObject* pDict = PyModule_GetDict(pModule); PyObject* pFunc = PyDict_GetItemString(pDict, "load_bareos_plugin"); @@ -251,6 +224,8 @@ int main(int argc, char* argv[]) } Py_DECREF(pDict); Py_DECREF(pFunc); + + Py_DECREF(pModule); Py_Finalize(); return 0; } From 62fa93c9220e647fe7808442382b370aa8c38598 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 13:36:41 +0200 Subject: [PATCH 121/341] python-dir plugin: moved bareosfd module files to module/ subdir --- core/src/plugins/filed/CMakeLists.txt | 30 ++++++++++--------- .../filed/python/{ => module}/bareosfd.cc | 2 +- .../filed/python/{ => module}/bareosfd.h | 0 .../{ => module}/bareosfd_api_funcs.txt | 0 .../filed/python/{ => module}/capi_1.inc | 0 .../filed/python/{ => module}/capi_2.inc | 0 .../filed/python/{ => module}/capi_3.inc | 0 .../create_CAPI_from_bareos_api_funcs.sh | 0 .../filed/python/{ => module}/setup.py.in | 2 +- core/src/plugins/filed/python/python-fd.cc | 2 +- .../python/test/python-fd-module-tester.cc | 2 +- systemtests/CMakeLists.txt | 19 ++++++++++++ 12 files changed, 39 insertions(+), 18 deletions(-) rename core/src/plugins/filed/python/{ => module}/bareosfd.cc (99%) rename core/src/plugins/filed/python/{ => module}/bareosfd.h (100%) rename core/src/plugins/filed/python/{ => module}/bareosfd_api_funcs.txt (100%) rename core/src/plugins/filed/python/{ => module}/capi_1.inc (100%) rename core/src/plugins/filed/python/{ => module}/capi_2.inc (100%) rename core/src/plugins/filed/python/{ => module}/capi_3.inc (100%) rename core/src/plugins/filed/python/{ => module}/create_CAPI_from_bareos_api_funcs.sh (100%) rename core/src/plugins/filed/python/{ => module}/setup.py.in (96%) diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index c78f5e22be5..68dd934dc58 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -168,18 +168,19 @@ endif() if(Python2_FOUND AND NOT HAVE_WIN22) configure_file( - python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup_py2.py + python/module/setup.py.in + ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup_py2.py ) add_custom_command( OUTPUT pythonmodules/bareosfd.so - MAIN_DEPENDENCY ./python/bareosfd.cc - DEPENDS ./python/bareosfd.h + MAIN_DEPENDENCY python/module/bareosfd.cc + DEPENDS python/module/bareosfd.h DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup_py2.py + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup_py2.py COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python2_EXECUTABLE} python/setup_py2.py build - COMMAND ${Python2_EXECUTABLE} python/setup_py2.py install --install-lib - ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + COMMAND ${Python2_EXECUTABLE} python/module/setup_py2.py build + COMMAND ${Python2_EXECUTABLE} python/module/setup_py2.py install + --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python2 module pythonmodules/bareosfd.so" ) @@ -199,18 +200,19 @@ endif() if(Python3_FOUND AND NOT HAVE_WIN32) configure_file( - python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup_py3.py + python/module/setup.py.in + ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup_py3.py ) add_custom_command( OUTPUT python3modules/bareosfd.so - MAIN_DEPENDENCY ./python/bareosfd.cc - DEPENDS ./python/bareosfd.h + MAIN_DEPENDENCY python/module/bareosfd.cc + DEPENDS python/module/bareosfd.h DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup_py3.py + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup_py3.py COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python3_EXECUTABLE} python/setup_py3.py build - COMMAND ${Python3_EXECUTABLE} python/setup_py3.py install --install-lib - ${CMAKE_CURRENT_BINARY_DIR}/python3modules + COMMAND ${Python3_EXECUTABLE} python/module/setup_py3.py build + COMMAND ${Python3_EXECUTABLE} python/module/setup_py3.py install + --install-lib ${CMAKE_CURRENT_BINARY_DIR}/python3modules COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python3 module python3modules/bareosfd.so" ) diff --git a/core/src/plugins/filed/python/bareosfd.cc b/core/src/plugins/filed/python/module/bareosfd.cc similarity index 99% rename from core/src/plugins/filed/python/bareosfd.cc rename to core/src/plugins/filed/python/module/bareosfd.cc index b4142d2902a..5c8ae435f98 100644 --- a/core/src/plugins/filed/python/bareosfd.cc +++ b/core/src/plugins/filed/python/module/bareosfd.cc @@ -79,7 +79,7 @@ static bRC PyHandleBackupFile(PluginContext* plugin_ctx, struct save_pkt* sp); /* Pointers to Bareos functions */ static CoreFunctions* bareos_core_functions = NULL; -#include "plugin_private_context.h" +#include "plugins/filed/python/plugin_private_context.h" #define NOPLUGINSETGETVALUE 1 /* functions common to all plugins */ diff --git a/core/src/plugins/filed/python/bareosfd.h b/core/src/plugins/filed/python/module/bareosfd.h similarity index 100% rename from core/src/plugins/filed/python/bareosfd.h rename to core/src/plugins/filed/python/module/bareosfd.h diff --git a/core/src/plugins/filed/python/bareosfd_api_funcs.txt b/core/src/plugins/filed/python/module/bareosfd_api_funcs.txt similarity index 100% rename from core/src/plugins/filed/python/bareosfd_api_funcs.txt rename to core/src/plugins/filed/python/module/bareosfd_api_funcs.txt diff --git a/core/src/plugins/filed/python/capi_1.inc b/core/src/plugins/filed/python/module/capi_1.inc similarity index 100% rename from core/src/plugins/filed/python/capi_1.inc rename to core/src/plugins/filed/python/module/capi_1.inc diff --git a/core/src/plugins/filed/python/capi_2.inc b/core/src/plugins/filed/python/module/capi_2.inc similarity index 100% rename from core/src/plugins/filed/python/capi_2.inc rename to core/src/plugins/filed/python/module/capi_2.inc diff --git a/core/src/plugins/filed/python/capi_3.inc b/core/src/plugins/filed/python/module/capi_3.inc similarity index 100% rename from core/src/plugins/filed/python/capi_3.inc rename to core/src/plugins/filed/python/module/capi_3.inc diff --git a/core/src/plugins/filed/python/create_CAPI_from_bareos_api_funcs.sh b/core/src/plugins/filed/python/module/create_CAPI_from_bareos_api_funcs.sh similarity index 100% rename from core/src/plugins/filed/python/create_CAPI_from_bareos_api_funcs.sh rename to core/src/plugins/filed/python/module/create_CAPI_from_bareos_api_funcs.sh diff --git a/core/src/plugins/filed/python/setup.py.in b/core/src/plugins/filed/python/module/setup.py.in similarity index 96% rename from core/src/plugins/filed/python/setup.py.in rename to core/src/plugins/filed/python/module/setup.py.in index f7e84d692f8..f1a24e8ae65 100644 --- a/core/src/plugins/filed/python/setup.py.in +++ b/core/src/plugins/filed/python/module/setup.py.in @@ -1,7 +1,7 @@ from distutils.core import setup, Extension module1 = Extension('bareosfd', - sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/bareosfd.cc'], + sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/module/bareosfd.cc'], include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..', '/usr/local/opt/gettext/include', '/usr/local/opt/openssl/include'], libraries = ['bareos'], library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'], diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index dc4a2fe06da..424927ce545 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -38,7 +38,7 @@ #include "plugins/python3compat.h" #include "python-fd.h" -#include "bareosfd.h" +#include "plugins/filed/python/module/bareosfd.h" #include "lib/edit.h" namespace filedaemon { diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index 99962216f4a..3837eef6410 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -29,7 +29,7 @@ typedef off_t boffset_t; #include "lib/plugins.h" #include "filed/fd_plugins.h" -#include "plugins/filed/python/bareosfd.h" +#include "../module/bareosfd.h" static void PyErrorHandler() { PyObject *type, *value, *traceback; diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 73d551c67c2..c2f05379aea 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -674,6 +674,15 @@ else() list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-vmware") endif() +if(TARGET python3-fd AND ovirt_server) + list(APPEND SYSTEM_TESTS "python3-fd-ovirt-plugin-test") +else() + message( + STATUS "disabling python3-fd-ovirt-plugin-test as ovirt_server is not set" + ) + list(APPEND SYSTEM_TESTS_DISABLED "python3-fd-ovirt-plugin-test") +endif() + if(TARGET python-fd AND XTRABACKUP) list(APPEND SYSTEM_TESTS "pyplug-fd-percona-xtrabackup") else() @@ -684,6 +693,16 @@ else() list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-percona-xtrabackup") endif() +if(TARGET python3-fd AND XTRABACKUP) + list(APPEND SYSTEM_TESTS "python3-fd-percona-xtrabackup-plugin-test") +else() + message( + STATUS + "disabling python3-fd-percona-xtrabackup-plugin-test as XTRABACKUP was not found" + ) + list(APPEND SYSTEM_TESTS_DISABLED "python3-fd-percona-xtrabackup-plugin-test") +endif() + if(TARGET python-dir) list(APPEND SYSTEM_TESTS "pyplug-dir") else() From 87220ddaa67af41b5a84cc71cb9fefa82625b654 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 14:00:59 +0200 Subject: [PATCH 122/341] python plugins: moved python plugin module files into module/ subdir --- core/src/plugins/dird/CMakeLists.txt | 30 +++++++++++-------- .../dird/python/{ => module}/bareosdir.cc | 3 +- .../dird/python/{ => module}/bareosdir.h | 0 .../{ => module}/bareosdir_api_funcs.txt | 0 .../dird/python/{ => module}/capi_1.inc | 0 .../dird/python/{ => module}/capi_2.inc | 0 .../dird/python/{ => module}/capi_3.inc | 0 .../create_CAPI_from_bareos_api_funcs.sh | 0 .../dird/python/{ => module}/setup.py.in | 2 +- core/src/plugins/dird/python/python-dir.cc | 2 +- core/src/plugins/filed/python/python-fd.cc | 2 +- core/src/plugins/stored/CMakeLists.txt | 30 +++++++++++-------- .../stored/python/{ => module}/bareossd.cc | 2 +- .../stored/python/{ => module}/bareossd.h | 0 .../{ => module}/bareossd_api_funcs.txt | 0 .../stored/python/{ => module}/capi_1.inc | 0 .../stored/python/{ => module}/capi_2.inc | 0 .../stored/python/{ => module}/capi_3.inc | 0 .../create_CAPI_from_bareos_api_funcs.sh | 0 .../stored/python/{ => module}/setup.py.in | 2 +- core/src/plugins/stored/python/python-sd.cc | 2 +- 21 files changed, 44 insertions(+), 31 deletions(-) rename core/src/plugins/dird/python/{ => module}/bareosdir.cc (99%) rename core/src/plugins/dird/python/{ => module}/bareosdir.h (100%) rename core/src/plugins/dird/python/{ => module}/bareosdir_api_funcs.txt (100%) rename core/src/plugins/dird/python/{ => module}/capi_1.inc (100%) rename core/src/plugins/dird/python/{ => module}/capi_2.inc (100%) rename core/src/plugins/dird/python/{ => module}/capi_3.inc (100%) rename core/src/plugins/dird/python/{ => module}/create_CAPI_from_bareos_api_funcs.sh (100%) rename core/src/plugins/dird/python/{ => module}/setup.py.in (95%) rename core/src/plugins/stored/python/{ => module}/bareossd.cc (99%) rename core/src/plugins/stored/python/{ => module}/bareossd.h (100%) rename core/src/plugins/stored/python/{ => module}/bareossd_api_funcs.txt (100%) rename core/src/plugins/stored/python/{ => module}/capi_1.inc (100%) rename core/src/plugins/stored/python/{ => module}/capi_2.inc (100%) rename core/src/plugins/stored/python/{ => module}/capi_3.inc (100%) rename core/src/plugins/stored/python/{ => module}/create_CAPI_from_bareos_api_funcs.sh (100%) rename core/src/plugins/stored/python/{ => module}/setup.py.in (95%) diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index ad52fdfeff2..28ef4bb8961 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -50,16 +50,19 @@ if(Python2_FOUND) endif() if(Python2_FOUND AND NOT HAVE_WIN32) - configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) + configure_file( + python/module/setup.py.in + ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup.py + ) add_custom_command( OUTPUT pythonmodules/bareosdir.so - MAIN_DEPENDENCY ./python/bareosdir.cc - DEPENDS ./python/bareosdir.h + MAIN_DEPENDENCY python/module/bareosdir.cc + DEPENDS python/module/bareosdir.h DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup.py COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python2_EXECUTABLE} python/setup.py build - COMMAND ${Python2_EXECUTABLE} python/setup.py install --install-lib + COMMAND ${Python2_EXECUTABLE} python/module/setup.py build + COMMAND ${Python2_EXECUTABLE} python/module/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python2 module pythonmodules/bareosdir.so" @@ -99,16 +102,19 @@ if(Python3_FOUND) endif() if(Python3_FOUND AND NOT HAVE_WIN32) - configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) + configure_file( + python/module/setup.py.in + ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup.py + ) add_custom_command( OUTPUT python3modules/bareosdir.so - MAIN_DEPENDENCY ./python/bareosdir.cc - DEPENDS ./python/bareosdir.h + MAIN_DEPENDENCY python/module/bareosdir.cc + DEPENDS python/module/bareosdir.h DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup.py COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python3_EXECUTABLE} python/setup.py build - COMMAND ${Python3_EXECUTABLE} python/setup.py install --install-lib + COMMAND ${Python3_EXECUTABLE} python/module/setup.py build + COMMAND ${Python3_EXECUTABLE} python/module/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/python3modules COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python3 module python3modules/bareosdir.so" diff --git a/core/src/plugins/dird/python/bareosdir.cc b/core/src/plugins/dird/python/module/bareosdir.cc similarity index 99% rename from core/src/plugins/dird/python/bareosdir.cc rename to core/src/plugins/dird/python/module/bareosdir.cc index ca2df1c6bad..d663da1124e 100644 --- a/core/src/plugins/dird/python/bareosdir.cc +++ b/core/src/plugins/dird/python/module/bareosdir.cc @@ -37,7 +37,8 @@ #include "plugins/filed/fd_common.h" // for Dmsg Macro -#include "plugin_private_context.h" + +#include "plugins/dird/python/plugin_private_context.h" #include "plugins/python3compat.h" diff --git a/core/src/plugins/dird/python/bareosdir.h b/core/src/plugins/dird/python/module/bareosdir.h similarity index 100% rename from core/src/plugins/dird/python/bareosdir.h rename to core/src/plugins/dird/python/module/bareosdir.h diff --git a/core/src/plugins/dird/python/bareosdir_api_funcs.txt b/core/src/plugins/dird/python/module/bareosdir_api_funcs.txt similarity index 100% rename from core/src/plugins/dird/python/bareosdir_api_funcs.txt rename to core/src/plugins/dird/python/module/bareosdir_api_funcs.txt diff --git a/core/src/plugins/dird/python/capi_1.inc b/core/src/plugins/dird/python/module/capi_1.inc similarity index 100% rename from core/src/plugins/dird/python/capi_1.inc rename to core/src/plugins/dird/python/module/capi_1.inc diff --git a/core/src/plugins/dird/python/capi_2.inc b/core/src/plugins/dird/python/module/capi_2.inc similarity index 100% rename from core/src/plugins/dird/python/capi_2.inc rename to core/src/plugins/dird/python/module/capi_2.inc diff --git a/core/src/plugins/dird/python/capi_3.inc b/core/src/plugins/dird/python/module/capi_3.inc similarity index 100% rename from core/src/plugins/dird/python/capi_3.inc rename to core/src/plugins/dird/python/module/capi_3.inc diff --git a/core/src/plugins/dird/python/create_CAPI_from_bareos_api_funcs.sh b/core/src/plugins/dird/python/module/create_CAPI_from_bareos_api_funcs.sh similarity index 100% rename from core/src/plugins/dird/python/create_CAPI_from_bareos_api_funcs.sh rename to core/src/plugins/dird/python/module/create_CAPI_from_bareos_api_funcs.sh diff --git a/core/src/plugins/dird/python/setup.py.in b/core/src/plugins/dird/python/module/setup.py.in similarity index 95% rename from core/src/plugins/dird/python/setup.py.in rename to core/src/plugins/dird/python/module/setup.py.in index 2cadff09c34..6a865781f30 100644 --- a/core/src/plugins/dird/python/setup.py.in +++ b/core/src/plugins/dird/python/module/setup.py.in @@ -1,7 +1,7 @@ from distutils.core import setup, Extension module1 = Extension('bareosdir', - sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/bareosdir.cc'], + sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/module/bareosdir.cc'], include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..'], libraries = ['bareos'], library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'], diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index c4c7ab16a60..19a5f327945 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -38,7 +38,7 @@ #include "plugins/python3compat.h" #include "python-dir.h" -#include "bareosdir.h" +#include "module/bareosdir.h" #include "lib/plugins.h" #include "lib/edit.h" diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 424927ce545..09b48e12a65 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -38,7 +38,7 @@ #include "plugins/python3compat.h" #include "python-fd.h" -#include "plugins/filed/python/module/bareosfd.h" +#include "module/bareosfd.h" #include "lib/edit.h" namespace filedaemon { diff --git a/core/src/plugins/stored/CMakeLists.txt b/core/src/plugins/stored/CMakeLists.txt index 6274323fb3a..c2fcf6b3bad 100644 --- a/core/src/plugins/stored/CMakeLists.txt +++ b/core/src/plugins/stored/CMakeLists.txt @@ -66,16 +66,19 @@ if(Python2_FOUND) endif() if(Python2_FOUND AND NOT HAVE_WIN32) - configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) + configure_file( + python/module/setup.py.in + ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup.py + ) add_custom_command( OUTPUT pythonmodules/bareossd.so - MAIN_DEPENDENCY ./python/bareossd.cc - DEPENDS ./python/bareossd.h + MAIN_DEPENDENCY python/module/bareossd.cc + DEPENDS python/module/bareossd.h DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup.py COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python2_EXECUTABLE} python/setup.py build - COMMAND ${Python2_EXECUTABLE} python/setup.py install --install-lib + COMMAND ${Python2_EXECUTABLE} python/module/setup.py build + COMMAND ${Python2_EXECUTABLE} python/module/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python module pythonmodules/bareossd.so" @@ -114,16 +117,19 @@ if(Python3_FOUND) endif() if(Python3_FOUND AND NOT HAVE_WIN32) - configure_file(python/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py) + configure_file( + python/module/setup.py.in + ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup.py + ) add_custom_command( OUTPUT python3modules/bareossd.so - MAIN_DEPENDENCY ./python/bareossd.cc - DEPENDS ./python/bareossd.h + MAIN_DEPENDENCY python/module/bareossd.cc + DEPENDS python/module/bareossd.h DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/setup.py + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup.py COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python3_EXECUTABLE} python/setup.py build - COMMAND ${Python3_EXECUTABLE} python/setup.py install --install-lib + COMMAND ${Python3_EXECUTABLE} python/module/setup.py build + COMMAND ${Python3_EXECUTABLE} python/module/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/python3modules COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python module python3modules/bareossd.so" diff --git a/core/src/plugins/stored/python/bareossd.cc b/core/src/plugins/stored/python/module/bareossd.cc similarity index 99% rename from core/src/plugins/stored/python/bareossd.cc rename to core/src/plugins/stored/python/module/bareossd.cc index ef87c51c94e..4cb322b18e0 100644 --- a/core/src/plugins/stored/python/bareossd.cc +++ b/core/src/plugins/stored/python/module/bareossd.cc @@ -61,7 +61,7 @@ static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, /* Pointers to Bareos functions */ static CoreFunctions* bareos_core_functions = NULL; -#include "plugin_private_context.h" +#include "plugins/stored/python/plugin_private_context.h" #define NOPLUGINSETGETVALUE 1 /* functions common to all plugins */ diff --git a/core/src/plugins/stored/python/bareossd.h b/core/src/plugins/stored/python/module/bareossd.h similarity index 100% rename from core/src/plugins/stored/python/bareossd.h rename to core/src/plugins/stored/python/module/bareossd.h diff --git a/core/src/plugins/stored/python/bareossd_api_funcs.txt b/core/src/plugins/stored/python/module/bareossd_api_funcs.txt similarity index 100% rename from core/src/plugins/stored/python/bareossd_api_funcs.txt rename to core/src/plugins/stored/python/module/bareossd_api_funcs.txt diff --git a/core/src/plugins/stored/python/capi_1.inc b/core/src/plugins/stored/python/module/capi_1.inc similarity index 100% rename from core/src/plugins/stored/python/capi_1.inc rename to core/src/plugins/stored/python/module/capi_1.inc diff --git a/core/src/plugins/stored/python/capi_2.inc b/core/src/plugins/stored/python/module/capi_2.inc similarity index 100% rename from core/src/plugins/stored/python/capi_2.inc rename to core/src/plugins/stored/python/module/capi_2.inc diff --git a/core/src/plugins/stored/python/capi_3.inc b/core/src/plugins/stored/python/module/capi_3.inc similarity index 100% rename from core/src/plugins/stored/python/capi_3.inc rename to core/src/plugins/stored/python/module/capi_3.inc diff --git a/core/src/plugins/stored/python/create_CAPI_from_bareos_api_funcs.sh b/core/src/plugins/stored/python/module/create_CAPI_from_bareos_api_funcs.sh similarity index 100% rename from core/src/plugins/stored/python/create_CAPI_from_bareos_api_funcs.sh rename to core/src/plugins/stored/python/module/create_CAPI_from_bareos_api_funcs.sh diff --git a/core/src/plugins/stored/python/setup.py.in b/core/src/plugins/stored/python/module/setup.py.in similarity index 95% rename from core/src/plugins/stored/python/setup.py.in rename to core/src/plugins/stored/python/module/setup.py.in index 0ff22defaa7..1baf851fc74 100644 --- a/core/src/plugins/stored/python/setup.py.in +++ b/core/src/plugins/stored/python/module/setup.py.in @@ -1,7 +1,7 @@ from distutils.core import setup, Extension module1 = Extension('bareossd', - sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/bareossd.cc'], + sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/module/bareossd.cc'], include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..'], libraries = ['bareos'], library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'], diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index 232cc329d24..c2b8b5bca8c 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -38,7 +38,7 @@ #include "plugins/python3compat.h" #include "python-sd.h" -#include "bareossd.h" +#include "module/bareossd.h" #include "lib/edit.h" namespace storagedaemon { From 3ae6d8db7256eb9664063cab6c40215a726a601b Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 14:15:09 +0200 Subject: [PATCH 123/341] plugins: introduced src/plugins/include directory --- .../plugins/dird/python/module/bareosdir.cc | 6 +- .../plugins/dird/python/module/bareosdir.h | 2 +- core/src/plugins/dird/python/python-dir.cc | 4 +- core/src/plugins/dird/python/python-dir.h | 4 +- core/src/plugins/filed/bpipe/bpipe-fd.cc | 2 +- .../plugins/filed/python/module/bareosfd.cc | 6 +- .../plugins/filed/python/module/bareosfd.h | 4 +- core/src/plugins/filed/python/python-fd.cc | 4 +- core/src/plugins/filed/python/python-fd.h | 4 +- .../python/test/python-fd-module-tester.cc | 2 +- .../{filed/fd_common.h => include/common.h} | 6 +- core/src/plugins/python3compat.h | 22 --- core/src/plugins/python_plugins_common.h | 142 --------------- core/src/plugins/python_plugins_common.inc | 168 ------------------ .../plugins/stored/python/module/bareossd.cc | 4 +- .../plugins/stored/python/module/bareossd.h | 4 +- core/src/plugins/stored/python/python-sd.cc | 4 +- core/src/plugins/stored/python/python-sd.h | 4 +- 18 files changed, 30 insertions(+), 362 deletions(-) rename core/src/plugins/{filed/fd_common.h => include/common.h} (95%) delete mode 100644 core/src/plugins/python3compat.h delete mode 100644 core/src/plugins/python_plugins_common.h delete mode 100644 core/src/plugins/python_plugins_common.inc diff --git a/core/src/plugins/dird/python/module/bareosdir.cc b/core/src/plugins/dird/python/module/bareosdir.cc index d663da1124e..3a26b3b3476 100644 --- a/core/src/plugins/dird/python/module/bareosdir.cc +++ b/core/src/plugins/dird/python/module/bareosdir.cc @@ -36,11 +36,11 @@ #include "dird/dir_plugins.h" -#include "plugins/filed/fd_common.h" // for Dmsg Macro +#include "plugins/include/common.h" // for Dmsg Macro #include "plugins/dird/python/plugin_private_context.h" -#include "plugins/python3compat.h" +#include "plugins/include/python3compat.h" #define BAREOSDIR_MODULE #include "bareosdir.h" @@ -69,7 +69,7 @@ static CoreFunctions* bareos_core_functions = NULL; #define NOPLUGINSETGETVALUE 1 /* functions common to all plugins */ -#include "plugins/python_plugins_common.inc" +#include "plugins/include/python_plugins_common.inc" /* set the bareos_core_functions pointer to the given value */ diff --git a/core/src/plugins/dird/python/module/bareosdir.h b/core/src/plugins/dird/python/module/bareosdir.h index e5b76f0b637..81d5b5bc9e2 100644 --- a/core/src/plugins/dird/python/module/bareosdir.h +++ b/core/src/plugins/dird/python/module/bareosdir.h @@ -31,7 +31,7 @@ #define PYTHON_MODULE_NAME_QUOTED "bareosdir" /* common code for all python plugins */ -#include "plugins/python_plugins_common.h" +#include "plugins/include/python_plugins_common.h" /* include automatically generated C API */ diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index 19a5f327945..d6a2ddc9048 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -35,7 +35,7 @@ #endif #include "dird/dird.h" -#include "plugins/python3compat.h" +#include "plugins/include/python3compat.h" #include "python-dir.h" #include "module/bareosdir.h" @@ -104,7 +104,7 @@ static PluginFunctions pluginFuncs = { static PyThreadState* mainThreadState; /* functions common to all plugins */ -#include "plugins/python_plugins_common.inc" +#include "plugins/include/python_plugins_common.inc" /* Common functions used in all python plugins. */ static bRC getPluginValue(PluginContext* bareos_plugin_ctx, diff --git a/core/src/plugins/dird/python/python-dir.h b/core/src/plugins/dird/python/python-dir.h index d332142d8b2..241e9a54358 100644 --- a/core/src/plugins/dird/python/python-dir.h +++ b/core/src/plugins/dird/python/python-dir.h @@ -31,8 +31,8 @@ #define PYTHON_MODULE_NAME_QUOTED "bareosdir" /* common code for all python plugins */ -#include "plugins/python_plugins_common.h" -#include "plugins/filed/fd_common.h" +#include "plugins/include/python_plugins_common.h" +#include "plugins/include/common.h" namespace directordaemon { diff --git a/core/src/plugins/filed/bpipe/bpipe-fd.cc b/core/src/plugins/filed/bpipe/bpipe-fd.cc index e902260fc82..8f76a385449 100644 --- a/core/src/plugins/filed/bpipe/bpipe-fd.cc +++ b/core/src/plugins/filed/bpipe/bpipe-fd.cc @@ -28,7 +28,7 @@ */ #include "include/bareos.h" #include "filed/fd_plugins.h" -#include "plugins/filed/fd_common.h" +#include "plugins/include/common.h" namespace filedaemon { diff --git a/core/src/plugins/filed/python/module/bareosfd.cc b/core/src/plugins/filed/python/module/bareosfd.cc index 5c8ae435f98..73ddfd03e47 100644 --- a/core/src/plugins/filed/python/module/bareosfd.cc +++ b/core/src/plugins/filed/python/module/bareosfd.cc @@ -35,11 +35,11 @@ #include "filed/fd_plugins.h" -#include "plugins/python3compat.h" +#include "plugins/include/python3compat.h" #define BAREOSFD_MODULE #include "bareosfd.h" -#include "plugins/python3compat.h" +#include "plugins/include/python3compat.h" #include "lib/edit.h" namespace filedaemon { @@ -83,7 +83,7 @@ static CoreFunctions* bareos_core_functions = NULL; #define NOPLUGINSETGETVALUE 1 /* functions common to all plugins */ -#include "plugins/python_plugins_common.inc" +#include "plugins/include/python_plugins_common.inc" /* set the bareos_core_functions pointer to the given value */ diff --git a/core/src/plugins/filed/python/module/bareosfd.h b/core/src/plugins/filed/python/module/bareosfd.h index a6f2112d944..3c083f43701 100644 --- a/core/src/plugins/filed/python/module/bareosfd.h +++ b/core/src/plugins/filed/python/module/bareosfd.h @@ -31,8 +31,8 @@ #define PYTHON_MODULE_NAME_QUOTED "bareosfd" /* common code for all python plugins */ -#include "plugins/python_plugins_common.h" -#include "plugins/filed/fd_common.h" +#include "plugins/include/python_plugins_common.h" +#include "plugins/include/common.h" #include "structmember.h" diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 09b48e12a65..6191d372741 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -35,7 +35,7 @@ #endif #include "filed/fd_plugins.h" -#include "plugins/python3compat.h" +#include "plugins/include/python3compat.h" #include "python-fd.h" #include "module/bareosfd.h" @@ -117,7 +117,7 @@ static PluginFunctions pluginFuncs = { static PyThreadState* mainThreadState; /* functions common to all plugins */ -#include "plugins/python_plugins_common.inc" +#include "plugins/include/python_plugins_common.inc" #ifdef __cplusplus extern "C" { diff --git a/core/src/plugins/filed/python/python-fd.h b/core/src/plugins/filed/python/python-fd.h index cb4cff65a2e..f5bbf3d0697 100644 --- a/core/src/plugins/filed/python/python-fd.h +++ b/core/src/plugins/filed/python/python-fd.h @@ -31,8 +31,8 @@ #define PYTHON_MODULE_NAME_QUOTED "bareosfd" /* common code for all python plugins */ -#include "plugins/python_plugins_common.h" -#include "plugins/filed/fd_common.h" +#include "plugins/include/python_plugins_common.h" +#include "plugins/include/common.h" #include "structmember.h" diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index 3837eef6410..b2f7e5e6ae9 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -22,7 +22,7 @@ /* Load the python-fd plugin and test it */ #include "Python.h" -#include "plugins/python3compat.h" +#include "plugins/include/python3compat.h" class PoolMem; #define NbytesForBits(n) ((((n)-1) >> 3) + 1) typedef off_t boffset_t; diff --git a/core/src/plugins/filed/fd_common.h b/core/src/plugins/include/common.h similarity index 95% rename from core/src/plugins/filed/fd_common.h rename to core/src/plugins/include/common.h index f7fcb3d0df0..565fc957c99 100644 --- a/core/src/plugins/filed/fd_common.h +++ b/core/src/plugins/include/common.h @@ -24,8 +24,8 @@ * access to some common tools and utilities provided by Bareos */ -#ifndef BAREOS_PLUGINS_FILED_FD_COMMON_H_ -#define BAREOS_PLUGINS_FILED_FD_COMMON_H_ +#ifndef BAREOS_PLUGINS_INCLUDE_COMMON_H_ +#define BAREOS_PLUGINS_INCLUDE_COMMON_H_ #define JT_BACKUP 'B' /* Backup Job */ @@ -56,4 +56,4 @@ "before Jmsg call\n", \ bareos_core_functions, context); \ } -#endif +#endif // BAREOS_PLUGINS_INCLUDE_COMMON_H_ diff --git a/core/src/plugins/python3compat.h b/core/src/plugins/python3compat.h deleted file mode 100644 index 0c5d6c8ee5a..00000000000 --- a/core/src/plugins/python3compat.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef BAREOS_CORE_SRC_PLUGINS_PYTHON3COMPAT_H_ -#define BAREOS_CORE_SRC_PLUGINS_PYTHON3COMPAT_H_ - -/* redefine python3 calls to python2 pendants */ - -#if PY_VERSION_HEX < 0x03000000 -#define PyLong_FromLong PyInt_FromLong -#define PyLong_AsLong PyInt_AsLong - -#define PyBytes_FromString PyString_FromString - -#undef PyUnicode_FromString -#define PyUnicode_FromString PyString_FromString - -#define PyUnicode_AsUTF8 PyString_AsString - -#undef PyUnicode_Check -#define PyUnicode_Check PyString_Check - -#endif - -#endif // BAREOS_CORE_SRC_PLUGINS_PYTHON3COMPAT_H_ diff --git a/core/src/plugins/python_plugins_common.h b/core/src/plugins/python_plugins_common.h deleted file mode 100644 index 29c7c6add53..00000000000 --- a/core/src/plugins/python_plugins_common.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - BAREOS® - Backup Archiving REcovery Open Sourced - - Copyright (C) 2020-2020 Bareos GmbH & Co. KG - - This program is Free Software; you can redistribute it and/or - modify it under the terms of version three of the GNU Affero General Public - License as published by the Free Software Foundation, which is - listed in the file LICENSE. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -/* Common definitions used in all python plugins. */ - -#ifndef BAREOS_PYTHON_PLUGINS_COMMON_H_ -#define BAREOS_PYTHON_PLUGINS_COMMON_H_ - -/* macros for uniform python module definition - see http://python3porting.com/cextensions.html */ -#if PY_MAJOR_VERSION >= 3 -#define MOD_ERROR_VAL NULL -#define MOD_SUCCESS_VAL(val) val -#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void) -#define MOD_DEF(ob, name, doc, methods) \ - static struct PyModuleDef moduledef = { \ - PyModuleDef_HEAD_INIT, name, doc, -1, methods, \ - }; \ - \ - ob = PyModule_Create(&moduledef); -#else -#define MOD_ERROR_VAL -#define MOD_SUCCESS_VAL(val) -#define MOD_INIT(name) PyMODINIT_FUNC init##name(void) -#define MOD_DEF(ob, name, doc, methods) ob = Py_InitModule3(name, methods, doc); -#endif - -#define STRINGIFY(x) #x -#define TOSTRING(x) STRINGIFY(x) -#define AT __FILE__ ":" TOSTRING(__LINE__) - -/* check if plugin_ctx and bfunc are set. - * Otherwise return NULL and throw RuntimeError */ - -#define RETURN_RUNTIME_ERROR_IF_BAREOS_PLUGIN_CTX_UNSET() \ - if (!plugin_ctx) { \ - PyErr_SetString(PyExc_RuntimeError, AT " :plugin_ctx is unset"); \ - return NULL; \ - } - -#define RETURN_RUNTIME_ERROR_IF_BFUNC_UNSET() \ - if (!bareos_core_functions) { \ - PyErr_SetString(PyExc_RuntimeError, \ - AT ": bareos_core_functions is unset"); \ - return NULL; \ - } - -#define RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() \ - RETURN_RUNTIME_ERROR_IF_BAREOS_PLUGIN_CTX_UNSET() \ - RETURN_RUNTIME_ERROR_IF_BFUNC_UNSET() - -/* define the given string constant as member of an dict and additionally - add it directly as constant to the module. - - This is both done for string to long and for string to string mappings. - - The result is that the module both contains a dict: - bIOPS = {'IO_CLOSE': 4L, 'IO_OPEN': 1L, 'IO_READ': 2L, 'IO_SEEK': 5L, - 'IO_WRITE': 3L} - and the single values directly: - IO_CLOSE = 4 - IO_OPEN = 1 - IO_READ = 2 - IO_SEEK = 5 - IO_WRITE = 3 - */ - -#define ConstSet_StrLong(dict, string, value) \ - if (PyDict_SetItem(dict, PyBytes_FromString(#string), \ - PyLong_FromLong(value))) { \ - return MOD_ERROR_VAL; \ - } \ - if (PyModule_AddIntConstant(m, #string, value)) { return MOD_ERROR_VAL; } - -#define ConstSet_StrStr(dict, string, value) \ - if (PyDict_SetItem(dict, PyBytes_FromString(#string), \ - PyBytes_FromString(value))) { \ - return MOD_ERROR_VAL; \ - } \ - if (PyModule_AddStringConstant(m, #string, value)) { return MOD_ERROR_VAL; } - - -/* commonly used definitions in multiple python modules */ -#define DEFINE_bRCs_DICT() \ - const char* bRCs = "bRCs"; \ - PyObject* pDictbRCs = NULL; \ - pDictbRCs = PyDict_New(); \ - ConstSet_StrLong(pDictbRCs, bRC_OK, 0); \ - ConstSet_StrLong(pDictbRCs, bRC_Stop, 1); \ - ConstSet_StrLong(pDictbRCs, bRC_Error, 2); \ - ConstSet_StrLong(pDictbRCs, bRC_More, 3); \ - ConstSet_StrLong(pDictbRCs, bRC_Term, 4); \ - ConstSet_StrLong(pDictbRCs, bRC_Seen, 5); \ - ConstSet_StrLong(pDictbRCs, bRC_Core, 6); \ - ConstSet_StrLong(pDictbRCs, bRC_Skip, 7); \ - ConstSet_StrLong(pDictbRCs, bRC_Cancel, 8); \ - if (!pDictbRCs) { return MOD_ERROR_VAL; } \ - if (PyModule_AddObject(m, bRCs, pDictbRCs)) { return MOD_ERROR_VAL; } - -#define DEFINE_bJobMessageTypes_DICT() \ - const char* bJobMessageType = "bJobMessageType"; \ - PyObject* pDictJobMessageType = NULL; \ - pDictJobMessageType = PyDict_New(); \ - if (!pDictJobMessageType) { return MOD_ERROR_VAL; } \ - ConstSet_StrLong(pDictJobMessageType, M_ABORT, 1); \ - ConstSet_StrLong(pDictJobMessageType, M_DEBUG, 2); \ - ConstSet_StrLong(pDictJobMessageType, M_FATAL, 3); \ - ConstSet_StrLong(pDictJobMessageType, M_ERROR, 4); \ - ConstSet_StrLong(pDictJobMessageType, M_WARNING, 5); \ - ConstSet_StrLong(pDictJobMessageType, M_INFO, 6); \ - ConstSet_StrLong(pDictJobMessageType, M_SAVED, 7); \ - ConstSet_StrLong(pDictJobMessageType, M_NOTSAVED, 8); \ - ConstSet_StrLong(pDictJobMessageType, M_SKIPPED, 9); \ - ConstSet_StrLong(pDictJobMessageType, M_MOUNT, 10); \ - ConstSet_StrLong(pDictJobMessageType, M_ERROR_TERM, 11); \ - ConstSet_StrLong(pDictJobMessageType, M_TERM, 12); \ - ConstSet_StrLong(pDictJobMessageType, M_RESTORED, 13); \ - ConstSet_StrLong(pDictJobMessageType, M_SECURITY, 14); \ - ConstSet_StrLong(pDictJobMessageType, M_ALERT, 15); \ - ConstSet_StrLong(pDictJobMessageType, M_VOLMGMT, 16); \ - if (PyModule_AddObject(m, bJobMessageType, pDictJobMessageType)) { \ - return MOD_ERROR_VAL; \ - } -#endif // BAREOS_PYTHON_PLUGINS_COMMON_H_ diff --git a/core/src/plugins/python_plugins_common.inc b/core/src/plugins/python_plugins_common.inc deleted file mode 100644 index 0b0237b1b07..00000000000 --- a/core/src/plugins/python_plugins_common.inc +++ /dev/null @@ -1,168 +0,0 @@ -/* - BAREOS® - Backup Archiving REcovery Open Sourced - - Copyright (C) 2020-2020 Bareos GmbH & Co. KG - - This program is Free Software; you can redistribute it and/or - modify it under the terms of version three of the GNU Affero General Public - License as published by the Free Software Foundation, which is - listed in the file LICENSE. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - - -/** - * Strip any backslashes in the string. - */ -static inline void StripBackSlashes(char* value) -{ - char* bp; - - bp = value; - while (*bp) { - switch (*bp) { - case '\\': - bstrinlinecpy(bp, bp + 1); - break; - default: - break; - } - - bp++; - } -} - -/** - * Parse a boolean value e.g. check if its yes or true anything else translates - * to false. - */ -static inline bool ParseBoolean(const char* argument_value) -{ - if (Bstrcasecmp(argument_value, "yes") || - Bstrcasecmp(argument_value, "true")) { - return true; - } else { - return false; - } -} - -/** - * Parse a integer value. - */ -static inline int64_t parse_integer(const char* argument_value) -{ - return str_to_int64(argument_value); -} - -/** - * Always set destination to value and clean any previous one. - */ -static inline void SetString(char** destination, char* value) -{ - if (*destination) { free(*destination); } - - *destination = strdup(value); - StripBackSlashes(*destination); -} - - -/** - * Handle a Python error. - * - * Python equivalent: - * - * import traceback, sys - * return "".join(traceback.format_exception(sys.exc_type, - * sys.exc_value, sys.exc_traceback)) - */ -static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype) -{ - PyObject *type, *value, *traceback; - PyObject* tracebackModule; - char* error_string; - - PyErr_Fetch(&type, &value, &traceback); - PyErr_NormalizeException(&type, &value, &traceback); - - tracebackModule = PyImport_ImportModule("traceback"); - if (tracebackModule != NULL) { - PyObject *tbList, *emptyString, *strRetval; - - tbList = - PyObject_CallMethod(tracebackModule, (char*)"format_exception", - (char*)"OOO", type, value == NULL ? Py_None : value, - traceback == NULL ? Py_None : traceback); - - emptyString = PyUnicode_FromString(""); - strRetval = - PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); - - error_string = strdup(PyUnicode_AsUTF8(strRetval)); - - Py_DECREF(tbList); - Py_DECREF(emptyString); - Py_DECREF(strRetval); - Py_DECREF(tracebackModule); - } else { - error_string = strdup("Unable to import traceback module."); - } - - Py_DECREF(type); - Py_XDECREF(value); - Py_XDECREF(traceback); - - Dmsg(bareos_plugin_ctx, debuglevel, PYTHON_MODULE_NAME_QUOTED ": %s\n", - error_string); - if (msgtype) { - Jmsg(bareos_plugin_ctx, msgtype, PYTHON_MODULE_NAME_QUOTED ": %s\n", - error_string); - } - - free(error_string); -} -#if 0 -static void StorePluginContextInPythonModule(PluginContext* bareos_plugin_ctx) -{ - /* get the pointer to the module variable that is exported via the capsule */ - PluginContext** bareosfd_PluginContext = - (PluginContext**)PyCapsule_Import(PYTHON_MODULE_NAME_QUOTED ".PluginContext", 0); - - /* store bareos_plugin_ctx in module */ - if (bareosfd_PluginContext) { - *bareosfd_PluginContext = bareos_plugin_ctx; - } else { - printf(PYTHON_MODULE_NAME_QUOTED ": could not get bareosfd_PluginContext from module\n"); - } -} -static PluginContext* GetPluginContextFromPythonModule() -{ - const char* capsule_name = PYTHON_MODULE_NAME_QUOTED ".PluginContext"; - PluginContext** retval = - (PluginContext**)PyCapsule_Import(capsule_name, 0); - return *retval; -} -#endif -/** - * Convert a return value into a bRC enum value. - */ -static inline bRC ConvertPythonRetvalTobRCRetval(PyObject* pRetVal) -{ - return (bRC)PyLong_AsLong(pRetVal); -} - -/** - * Convert a return value from bRC enum value into Python Object. - */ -static inline PyObject* ConvertbRCRetvalToPythonRetval(bRC retval) -{ - return (PyObject*)PyLong_FromLong((int)retval); -} diff --git a/core/src/plugins/stored/python/module/bareossd.cc b/core/src/plugins/stored/python/module/bareossd.cc index 4cb322b18e0..0745edb6668 100644 --- a/core/src/plugins/stored/python/module/bareossd.cc +++ b/core/src/plugins/stored/python/module/bareossd.cc @@ -37,7 +37,7 @@ #define BAREOSSD_MODULE #include "bareossd.h" -#include "plugins/python3compat.h" +#include "plugins/include/python3compat.h" #include "lib/edit.h" namespace storagedaemon { @@ -65,7 +65,7 @@ static CoreFunctions* bareos_core_functions = NULL; #define NOPLUGINSETGETVALUE 1 /* functions common to all plugins */ -#include "plugins/python_plugins_common.inc" +#include "plugins/include/python_plugins_common.inc" /* set the bareos_core_functions pointer to the given value */ diff --git a/core/src/plugins/stored/python/module/bareossd.h b/core/src/plugins/stored/python/module/bareossd.h index ae527158721..bc7aebb25c4 100644 --- a/core/src/plugins/stored/python/module/bareossd.h +++ b/core/src/plugins/stored/python/module/bareossd.h @@ -30,8 +30,8 @@ #define PYTHON_MODULE_NAME_QUOTED "bareossd" /* common code for all python plugins */ -#include "plugins/python_plugins_common.h" -#include "plugins/filed/fd_common.h" +#include "plugins/include/python_plugins_common.h" +#include "plugins/include/common.h" #include "capi_1.inc" diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index c2b8b5bca8c..838cd967124 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -35,7 +35,7 @@ #endif #include "stored/stored.h" -#include "plugins/python3compat.h" +#include "plugins/include/python3compat.h" #include "python-sd.h" #include "module/bareossd.h" @@ -104,7 +104,7 @@ static PluginFunctions pluginFuncs = { static PyThreadState* mainThreadState; /* functions common to all plugins */ -#include "plugins/python_plugins_common.inc" +#include "plugins/include/python_plugins_common.inc" /* Common functions used in all python plugins. */ static bRC getPluginValue(PluginContext* bareos_plugin_ctx, diff --git a/core/src/plugins/stored/python/python-sd.h b/core/src/plugins/stored/python/python-sd.h index 29ddac8c17e..5aa4948600e 100644 --- a/core/src/plugins/stored/python/python-sd.h +++ b/core/src/plugins/stored/python/python-sd.h @@ -31,8 +31,8 @@ #define PYTHON_MODULE_NAME_QUOTED "bareossd" /* common code for all python plugins */ -#include "plugins/python_plugins_common.h" -#include "plugins/filed/fd_common.h" +#include "plugins/include/python_plugins_common.h" +#include "plugins/include/common.h" namespace storagedaemon { From 8febc9f8ec08a449a1284d940084d9ae3c9be1c0 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 14:53:11 +0200 Subject: [PATCH 124/341] python plugins: move to python subdir, create c_api subdir --- core/src/plugins/filed/CMakeLists.txt | 167 +----------------- .../plugins/filed/python/module/bareosfd.h | 6 +- .../module/{ => c_api}/bareosfd_api_funcs.txt | 0 .../python/module/{ => c_api}/capi_1.inc | 0 .../python/module/{ => c_api}/capi_2.inc | 0 .../python/module/{ => c_api}/capi_3.inc | 0 .../create_CAPI_from_bareos_api_funcs.sh | 0 .../plugins/filed/python/module/setup.py.in | 4 +- .../plugins/stored/python/module/bareossd.h | 6 +- .../module/{ => c_api}/bareossd_api_funcs.txt | 0 .../python/module/{ => c_api}/capi_1.inc | 0 .../python/module/{ => c_api}/capi_2.inc | 0 .../python/module/{ => c_api}/capi_3.inc | 0 .../create_CAPI_from_bareos_api_funcs.sh | 0 14 files changed, 9 insertions(+), 174 deletions(-) rename core/src/plugins/filed/python/module/{ => c_api}/bareosfd_api_funcs.txt (100%) rename core/src/plugins/filed/python/module/{ => c_api}/capi_1.inc (100%) rename core/src/plugins/filed/python/module/{ => c_api}/capi_2.inc (100%) rename core/src/plugins/filed/python/module/{ => c_api}/capi_3.inc (100%) rename core/src/plugins/filed/python/module/{ => c_api}/create_CAPI_from_bareos_api_funcs.sh (100%) rename core/src/plugins/stored/python/module/{ => c_api}/bareossd_api_funcs.txt (100%) rename core/src/plugins/stored/python/module/{ => c_api}/capi_1.inc (100%) rename core/src/plugins/stored/python/module/{ => c_api}/capi_2.inc (100%) rename core/src/plugins/stored/python/module/{ => c_api}/capi_3.inc (100%) rename core/src/plugins/stored/python/module/{ => c_api}/create_CAPI_from_bareos_api_funcs.sh (100%) diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index 68dd934dc58..a831c3c01b1 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -41,7 +41,7 @@ endif() include_directories(${OPENSSL_INCLUDE_DIR}) -# set(DLLIBS dl) +add_subdirectory(python) add_library(bpipe-fd MODULE bpipe/bpipe-fd.cc) set_target_properties(bpipe-fd PROPERTIES PREFIX "") @@ -94,142 +94,6 @@ if(NOT HAVE_WIN32) set_target_properties(example-plugin-fd PROPERTIES PREFIX "") endif() -if(Python2_FOUND) - add_library(python-fd MODULE python/python-fd.cc) - set_target_properties(python-fd PROPERTIES PREFIX "") - install( - TARGETS python-fd - DESTINATION ${plugindir} - COMPONENT filedaemon - ) - target_link_libraries(python-fd ${Python2_LIBRARIES} bareos) - target_include_directories(python-fd PUBLIC SYSTEM ${Python2_INCLUDE_DIRS}) - add_dependencies(python-fd bareosfd-pymod2) - add_dependencies(bareos-fd python-fd) -endif() - -if(Python3_FOUND) - add_library(python3-fd MODULE python/python-fd.cc) - set_target_properties(python3-fd PROPERTIES PREFIX "") - install( - TARGETS python3-fd - DESTINATION ${plugindir} - COMPONENT filedaemon - ) - target_link_libraries(python3-fd ${Python3_LIBRARIES} bareos) - target_include_directories(python3-fd PUBLIC SYSTEM ${Python3_INCLUDE_DIRS}) - add_dependencies(python3-fd bareosfd-pymod3) - add_dependencies(bareos-fd python3-fd) -endif() - -if(Python2_FOUND AND NOT HAVE_WIN22) - add_executable( - bareosfd-python2-module-tester python/test/python-fd-module-tester.cc - ) - target_link_libraries( - bareosfd-python2-module-tester ${Python2_LIBRARIES} bareos - ) - target_include_directories( - bareosfd-python2-module-tester PUBLIC SYSTEM ${Python2_INCLUDE_DIRS} - ) - - add_test(NAME bareosfd-python2-module-tester - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bareosfd-python2-module-tester - ) - set_property( - TEST bareosfd-python2-module-tester - PROPERTY - ENVIRONMENT - PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/python/test/:${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/pyfiles - ) -endif() - -if(Python3_FOUND AND NOT HAVE_WIN32) - add_executable( - bareosfd-python3-module-tester python/test/python-fd-module-tester.cc - ) - target_link_libraries( - bareosfd-python3-module-tester ${Python3_LIBRARIES} bareos - ) - target_include_directories( - bareosfd-python3-module-tester PUBLIC SYSTEM ${Python3_INCLUDE_DIRS} - ) - - add_test(NAME bareosfd-python3-module-tester - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bareosfd-python3-module-tester - ) - set_property( - TEST bareosfd-python3-module-tester - PROPERTY - ENVIRONMENT - PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/python/test/:${CMAKE_CURRENT_BINARY_DIR}/python3modules:${CMAKE_CURRENT_SOURCE_DIR}/python/pyfiles - ) -endif() - -if(Python2_FOUND AND NOT HAVE_WIN22) - configure_file( - python/module/setup.py.in - ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup_py2.py - ) - add_custom_command( - OUTPUT pythonmodules/bareosfd.so - MAIN_DEPENDENCY python/module/bareosfd.cc - DEPENDS python/module/bareosfd.h - DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup_py2.py - COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python2_EXECUTABLE} python/module/setup_py2.py build - COMMAND ${Python2_EXECUTABLE} python/module/setup_py2.py install - --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build - COMMENT "building python2 module pythonmodules/bareosfd.so" - ) - add_custom_target(bareosfd-pymod2 DEPENDS pythonmodules/bareosfd.so) - add_test(NAME bareosfd-python2-module - COMMAND ${Python2_EXECUTABLE} - ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosfd_test.py - ) - set_property( - TEST bareosfd-python2-module - PROPERTY - ENVIRONMENT - "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" - LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib - ) -endif() - -if(Python3_FOUND AND NOT HAVE_WIN32) - configure_file( - python/module/setup.py.in - ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup_py3.py - ) - add_custom_command( - OUTPUT python3modules/bareosfd.so - MAIN_DEPENDENCY python/module/bareosfd.cc - DEPENDS python/module/bareosfd.h - DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup_py3.py - COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python3_EXECUTABLE} python/module/setup_py3.py build - COMMAND ${Python3_EXECUTABLE} python/module/setup_py3.py install - --install-lib ${CMAKE_CURRENT_BINARY_DIR}/python3modules - COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build - COMMENT "building python3 module python3modules/bareosfd.so" - ) - add_custom_target(bareosfd-pymod3 DEPENDS python3modules/bareosfd.so) - add_test(NAME bareosfd-python3-module - COMMAND ${Python3_EXECUTABLE} - ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosfd_test.py - ) - set_property( - TEST bareosfd-python3-module - PROPERTY - ENVIRONMENT - "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/python3modules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" - LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib - ) -endif() - if(${HAVE_GLUSTERFS}) add_library(gfapi-fd MODULE gfapi/gfapi-fd.cc) set_target_properties(gfapi-fd PROPERTIES PREFIX "") @@ -252,32 +116,3 @@ if(${HAVE_TEST_PLUGIN}) COMPONENT filedaemon ) endif() - -set(PYFILES - python/pyfiles/bareos-fd.py.template - python/pyfiles/bareos-fd-local-fileset.py - python/pyfiles/bareos-fd-mock-test.py - python/pyfiles/BareosFdPluginBaseclass.py - python/pyfiles/BareosFdPluginLocalFileset.py - python/pyfiles/BareosFdWrapper.py - python/pyfiles/bareos-fd.py.template - python/pyfiles/bareos-fd-postgres.py - python/pyfiles/BareosFdPluginPostgres.py - python/pyfiles/bareos-fd-vmware.py - python/pyfiles/BareosFdPluginVMware.py - python/pyfiles/ldap/BareosFdPluginLDAP.py - python/pyfiles/ldap/bareos-fd-ldap.py - python/pyfiles/ovirt/BareosFdPluginOvirt.py - python/pyfiles/ovirt/bareos-fd-ovirt.py - python/pyfiles/percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py - python/pyfiles/percona-xtrabackup/bareos-fd-percona-xtrabackup.py -) -if(${HAVE_VIXDISKLIB}) - list(APPEND PYFILES BareosFdPluginVMware.py bareos-fd-vmware.py) -endif() - -install( - FILES ${PYFILES} - DESTINATION ${plugindir} - COMPONENT filedaemon -) diff --git a/core/src/plugins/filed/python/module/bareosfd.h b/core/src/plugins/filed/python/module/bareosfd.h index 3c083f43701..67a9f9d5439 100644 --- a/core/src/plugins/filed/python/module/bareosfd.h +++ b/core/src/plugins/filed/python/module/bareosfd.h @@ -37,7 +37,7 @@ #include "structmember.h" /* include automatically generated C API */ -#include "capi_1.inc" +#include "c_api/capi_1.inc" #ifdef BAREOSFD_MODULE @@ -782,7 +782,7 @@ MOD_INIT(bareosfd) PyObject* c_api_object; /* Initialize the C API pointer array */ -#include "capi_3.inc" +#include "c_api/capi_3.inc" /* Create a Capsule containing the API pointer array's address */ c_api_object = PyCapsule_New((void*)Bareosfd_API, @@ -1000,7 +1000,7 @@ MOD_INIT(bareosfd) static void** Bareosfd_API; /* include automatically generated C API */ -#include "capi_2.inc" +#include "c_api/capi_2.inc" static int import_bareosfd() { diff --git a/core/src/plugins/filed/python/module/bareosfd_api_funcs.txt b/core/src/plugins/filed/python/module/c_api/bareosfd_api_funcs.txt similarity index 100% rename from core/src/plugins/filed/python/module/bareosfd_api_funcs.txt rename to core/src/plugins/filed/python/module/c_api/bareosfd_api_funcs.txt diff --git a/core/src/plugins/filed/python/module/capi_1.inc b/core/src/plugins/filed/python/module/c_api/capi_1.inc similarity index 100% rename from core/src/plugins/filed/python/module/capi_1.inc rename to core/src/plugins/filed/python/module/c_api/capi_1.inc diff --git a/core/src/plugins/filed/python/module/capi_2.inc b/core/src/plugins/filed/python/module/c_api/capi_2.inc similarity index 100% rename from core/src/plugins/filed/python/module/capi_2.inc rename to core/src/plugins/filed/python/module/c_api/capi_2.inc diff --git a/core/src/plugins/filed/python/module/capi_3.inc b/core/src/plugins/filed/python/module/c_api/capi_3.inc similarity index 100% rename from core/src/plugins/filed/python/module/capi_3.inc rename to core/src/plugins/filed/python/module/c_api/capi_3.inc diff --git a/core/src/plugins/filed/python/module/create_CAPI_from_bareos_api_funcs.sh b/core/src/plugins/filed/python/module/c_api/create_CAPI_from_bareos_api_funcs.sh similarity index 100% rename from core/src/plugins/filed/python/module/create_CAPI_from_bareos_api_funcs.sh rename to core/src/plugins/filed/python/module/c_api/create_CAPI_from_bareos_api_funcs.sh diff --git a/core/src/plugins/filed/python/module/setup.py.in b/core/src/plugins/filed/python/module/setup.py.in index f1a24e8ae65..69b4d89bd38 100644 --- a/core/src/plugins/filed/python/module/setup.py.in +++ b/core/src/plugins/filed/python/module/setup.py.in @@ -1,8 +1,8 @@ from distutils.core import setup, Extension module1 = Extension('bareosfd', - sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/module/bareosfd.cc'], - include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..', '/usr/local/opt/gettext/include', '/usr/local/opt/openssl/include'], + sources = ['@CMAKE_CURRENT_SOURCE_DIR@/module/bareosfd.cc'], + include_dirs = ['@PROJECT_SOURCE_DIR@/src', '/usr/local/opt/gettext/include', '/usr/local/opt/openssl/include'], libraries = ['bareos'], library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'], extra_compile_args=['-std=c++11'], diff --git a/core/src/plugins/stored/python/module/bareossd.h b/core/src/plugins/stored/python/module/bareossd.h index bc7aebb25c4..1d49dbde639 100644 --- a/core/src/plugins/stored/python/module/bareossd.h +++ b/core/src/plugins/stored/python/module/bareossd.h @@ -33,7 +33,7 @@ #include "plugins/include/python_plugins_common.h" #include "plugins/include/common.h" -#include "capi_1.inc" +#include "c_api/capi_1.inc" #ifdef BAREOSSD_MODULE @@ -97,7 +97,7 @@ MOD_INIT(bareossd) PyObject* c_api_object; /* Initialize the C API pointer array */ -#include "capi_3.inc" +#include "c_api/capi_3.inc" /* Create a Capsule containing the API pointer array's address */ c_api_object = PyCapsule_New((void*)Bareossd_API, @@ -196,7 +196,7 @@ MOD_INIT(bareossd) static void** Bareossd_API; /* include automatically generated C API */ -#include "capi_2.inc" +#include "c_api/capi_2.inc" static int import_bareossd() { diff --git a/core/src/plugins/stored/python/module/bareossd_api_funcs.txt b/core/src/plugins/stored/python/module/c_api/bareossd_api_funcs.txt similarity index 100% rename from core/src/plugins/stored/python/module/bareossd_api_funcs.txt rename to core/src/plugins/stored/python/module/c_api/bareossd_api_funcs.txt diff --git a/core/src/plugins/stored/python/module/capi_1.inc b/core/src/plugins/stored/python/module/c_api/capi_1.inc similarity index 100% rename from core/src/plugins/stored/python/module/capi_1.inc rename to core/src/plugins/stored/python/module/c_api/capi_1.inc diff --git a/core/src/plugins/stored/python/module/capi_2.inc b/core/src/plugins/stored/python/module/c_api/capi_2.inc similarity index 100% rename from core/src/plugins/stored/python/module/capi_2.inc rename to core/src/plugins/stored/python/module/c_api/capi_2.inc diff --git a/core/src/plugins/stored/python/module/capi_3.inc b/core/src/plugins/stored/python/module/c_api/capi_3.inc similarity index 100% rename from core/src/plugins/stored/python/module/capi_3.inc rename to core/src/plugins/stored/python/module/c_api/capi_3.inc diff --git a/core/src/plugins/stored/python/module/create_CAPI_from_bareos_api_funcs.sh b/core/src/plugins/stored/python/module/c_api/create_CAPI_from_bareos_api_funcs.sh similarity index 100% rename from core/src/plugins/stored/python/module/create_CAPI_from_bareos_api_funcs.sh rename to core/src/plugins/stored/python/module/c_api/create_CAPI_from_bareos_api_funcs.sh From 6a7c98af65fbc02dd3bef5ac6f4271adc2d30915 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 14:54:38 +0200 Subject: [PATCH 125/341] python dir plugin: added c_api --- core/src/plugins/dird/python/module/bareosdir.h | 6 +++--- .../dird/python/module/{ => c_api}/bareosdir_api_funcs.txt | 0 core/src/plugins/dird/python/module/{ => c_api}/capi_1.inc | 0 core/src/plugins/dird/python/module/{ => c_api}/capi_2.inc | 0 core/src/plugins/dird/python/module/{ => c_api}/capi_3.inc | 0 .../module/{ => c_api}/create_CAPI_from_bareos_api_funcs.sh | 0 6 files changed, 3 insertions(+), 3 deletions(-) rename core/src/plugins/dird/python/module/{ => c_api}/bareosdir_api_funcs.txt (100%) rename core/src/plugins/dird/python/module/{ => c_api}/capi_1.inc (100%) rename core/src/plugins/dird/python/module/{ => c_api}/capi_2.inc (100%) rename core/src/plugins/dird/python/module/{ => c_api}/capi_3.inc (100%) rename core/src/plugins/dird/python/module/{ => c_api}/create_CAPI_from_bareos_api_funcs.sh (100%) diff --git a/core/src/plugins/dird/python/module/bareosdir.h b/core/src/plugins/dird/python/module/bareosdir.h index 81d5b5bc9e2..12f33c0ef03 100644 --- a/core/src/plugins/dird/python/module/bareosdir.h +++ b/core/src/plugins/dird/python/module/bareosdir.h @@ -35,7 +35,7 @@ /* include automatically generated C API */ -#include "capi_1.inc" +#include "c_api/capi_1.inc" #ifdef BAREOSDIR_MODULE @@ -101,7 +101,7 @@ MOD_INIT(bareosdir) PyObject* c_api_object; /* Initialize the C API pointer array */ -#include "capi_3.inc" +#include "c_api/capi_3.inc" /* Create a Capsule containing the API pointer array's address */ c_api_object = PyCapsule_New((void*)Bareosdir_API, @@ -196,7 +196,7 @@ MOD_INIT(bareosdir) static void** Bareosdir_API; /* include automatically generated C API */ -#include "capi_2.inc" +#include "c_api/capi_2.inc" static int import_bareosdir() { diff --git a/core/src/plugins/dird/python/module/bareosdir_api_funcs.txt b/core/src/plugins/dird/python/module/c_api/bareosdir_api_funcs.txt similarity index 100% rename from core/src/plugins/dird/python/module/bareosdir_api_funcs.txt rename to core/src/plugins/dird/python/module/c_api/bareosdir_api_funcs.txt diff --git a/core/src/plugins/dird/python/module/capi_1.inc b/core/src/plugins/dird/python/module/c_api/capi_1.inc similarity index 100% rename from core/src/plugins/dird/python/module/capi_1.inc rename to core/src/plugins/dird/python/module/c_api/capi_1.inc diff --git a/core/src/plugins/dird/python/module/capi_2.inc b/core/src/plugins/dird/python/module/c_api/capi_2.inc similarity index 100% rename from core/src/plugins/dird/python/module/capi_2.inc rename to core/src/plugins/dird/python/module/c_api/capi_2.inc diff --git a/core/src/plugins/dird/python/module/capi_3.inc b/core/src/plugins/dird/python/module/c_api/capi_3.inc similarity index 100% rename from core/src/plugins/dird/python/module/capi_3.inc rename to core/src/plugins/dird/python/module/c_api/capi_3.inc diff --git a/core/src/plugins/dird/python/module/create_CAPI_from_bareos_api_funcs.sh b/core/src/plugins/dird/python/module/c_api/create_CAPI_from_bareos_api_funcs.sh similarity index 100% rename from core/src/plugins/dird/python/module/create_CAPI_from_bareos_api_funcs.sh rename to core/src/plugins/dird/python/module/c_api/create_CAPI_from_bareos_api_funcs.sh From b0ef356f65877c9fc3b0e40c9365683f6333a377 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 15:09:42 +0200 Subject: [PATCH 126/341] python plugins: use central c api definition generator --- ...osdir_api_funcs.txt => api_definition.txt} | 0 .../create_includes_form_api_definition.sh | 2 + ...eosfd_api_funcs.txt => api_definition.txt} | 0 .../create_CAPI_from_bareos_api_funcs.sh | 46 ------------------- .../create_includes_form_api_definition.sh | 2 + .../create_api_includes.sh} | 24 ++++++---- ...eossd_api_funcs.txt => api_definition.txt} | 0 .../create_CAPI_from_bareos_api_funcs.sh | 46 ------------------- .../create_includes_form_api_definition.sh | 2 + 9 files changed, 21 insertions(+), 101 deletions(-) rename core/src/plugins/dird/python/module/c_api/{bareosdir_api_funcs.txt => api_definition.txt} (100%) create mode 100755 core/src/plugins/dird/python/module/c_api/create_includes_form_api_definition.sh rename core/src/plugins/filed/python/module/c_api/{bareosfd_api_funcs.txt => api_definition.txt} (100%) delete mode 100755 core/src/plugins/filed/python/module/c_api/create_CAPI_from_bareos_api_funcs.sh create mode 100755 core/src/plugins/filed/python/module/c_api/create_includes_form_api_definition.sh rename core/src/plugins/{dird/python/module/c_api/create_CAPI_from_bareos_api_funcs.sh => scripts/create_api_includes.sh} (54%) rename core/src/plugins/stored/python/module/c_api/{bareossd_api_funcs.txt => api_definition.txt} (100%) delete mode 100755 core/src/plugins/stored/python/module/c_api/create_CAPI_from_bareos_api_funcs.sh create mode 100755 core/src/plugins/stored/python/module/c_api/create_includes_form_api_definition.sh diff --git a/core/src/plugins/dird/python/module/c_api/bareosdir_api_funcs.txt b/core/src/plugins/dird/python/module/c_api/api_definition.txt similarity index 100% rename from core/src/plugins/dird/python/module/c_api/bareosdir_api_funcs.txt rename to core/src/plugins/dird/python/module/c_api/api_definition.txt diff --git a/core/src/plugins/dird/python/module/c_api/create_includes_form_api_definition.sh b/core/src/plugins/dird/python/module/c_api/create_includes_form_api_definition.sh new file mode 100755 index 00000000000..61a4e5d6aa4 --- /dev/null +++ b/core/src/plugins/dird/python/module/c_api/create_includes_form_api_definition.sh @@ -0,0 +1,2 @@ +#!/bin/bash +../../../../scripts/create_api_includes.sh Bareosdir diff --git a/core/src/plugins/filed/python/module/c_api/bareosfd_api_funcs.txt b/core/src/plugins/filed/python/module/c_api/api_definition.txt similarity index 100% rename from core/src/plugins/filed/python/module/c_api/bareosfd_api_funcs.txt rename to core/src/plugins/filed/python/module/c_api/api_definition.txt diff --git a/core/src/plugins/filed/python/module/c_api/create_CAPI_from_bareos_api_funcs.sh b/core/src/plugins/filed/python/module/c_api/create_CAPI_from_bareos_api_funcs.sh deleted file mode 100755 index 29467ae178c..00000000000 --- a/core/src/plugins/filed/python/module/c_api/create_CAPI_from_bareos_api_funcs.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -IFS=' -' - -exec >capi_1.inc - -echo "/* C API functions */" -NUM=0 -for i in $(cat bareosfd_api_funcs.txt); do - retval=$(echo $i | sed 's/ .*//g') - funcname=$(echo $i | cut -b 5- | sed s/\(.*//g) - prot=$(echo $i | sed s/.*\(//g | sed 's/);//g') -echo " -/* static $i */ -#define Bareosfd_${funcname}_NUM $NUM -#define Bareosfd_${funcname}_RETURN $retval -#define Bareosfd_${funcname}_PROTO (${prot})" - -((NUM=NUM+1)) -done -echo " -/*Total Number of C API function pointers */ -#define Bareosfd_API_pointers $NUM" - -exec >capi_2.inc - -NUM=0 -for i in $(cat bareosfd_api_funcs.txt); do - retval=$(echo $i | sed 's/ .*//g') - funcname=$(echo $i | cut -b 5- | sed s/\(.*//g) - prot=$(echo $i | sed s/.*\(//g | sed 's/);//g') - echo "#define Bareosfd_${funcname} (*(Bareosfd_${funcname}_RETURN(*)Bareosfd_${funcname}_PROTO) Bareosfd_API[Bareosfd_${funcname}_NUM]) -" -((NUM=NUM+1)) -done - -exec >capi_3.inc - -NUM=0 -for i in $(cat bareosfd_api_funcs.txt); do - retval=$(echo $i | sed 's/ .*//g') - funcname=$(echo $i | cut -b 5- | sed s/\(.*//g) - prot=$(echo $i | sed s/.*\(//g | sed 's/);//g') - echo " Bareosfd_API[Bareosfd_${funcname}_NUM] = (void*)${funcname};" -((NUM=NUM+1)) -done diff --git a/core/src/plugins/filed/python/module/c_api/create_includes_form_api_definition.sh b/core/src/plugins/filed/python/module/c_api/create_includes_form_api_definition.sh new file mode 100755 index 00000000000..7b9e13730c7 --- /dev/null +++ b/core/src/plugins/filed/python/module/c_api/create_includes_form_api_definition.sh @@ -0,0 +1,2 @@ +#!/bin/bash +../../../../scripts/create_api_includes.sh Bareosfd diff --git a/core/src/plugins/dird/python/module/c_api/create_CAPI_from_bareos_api_funcs.sh b/core/src/plugins/scripts/create_api_includes.sh similarity index 54% rename from core/src/plugins/dird/python/module/c_api/create_CAPI_from_bareos_api_funcs.sh rename to core/src/plugins/scripts/create_api_includes.sh index f3c83c8e290..872ded5d51c 100755 --- a/core/src/plugins/dird/python/module/c_api/create_CAPI_from_bareos_api_funcs.sh +++ b/core/src/plugins/scripts/create_api_includes.sh @@ -2,34 +2,40 @@ IFS=' ' +PREFIX=$1 +if [ -z "$PREFIX" ]; then + echo "API prefix required. Bareosfd, Bareossd or Bareosdir" + exit 1 +fi + exec >capi_1.inc echo "/* C API functions */" NUM=0 -for i in $(cat bareosdir_api_funcs.txt); do +for i in $(cat api_definition.txt); do retval=$(echo $i | sed 's/ .*//g') funcname=$(echo $i | cut -b 5- | sed s/\(.*//g) prot=$(echo $i | sed s/.*\(//g | sed 's/);//g') echo " /* static $i */ -#define Bareosdir_${funcname}_NUM $NUM -#define Bareosdir_${funcname}_RETURN $retval -#define Bareosdir_${funcname}_PROTO (${prot})" +#define ${PREFIX}_${funcname}_NUM $NUM +#define ${PREFIX}_${funcname}_RETURN $retval +#define ${PREFIX}_${funcname}_PROTO (${prot})" ((NUM=NUM+1)) done echo " /*Total Number of C API function pointers */ -#define Bareosdir_API_pointers $NUM" +#define ${PREFIX}_API_pointers $NUM" exec >capi_2.inc NUM=0 -for i in $(cat bareosdir_api_funcs.txt); do +for i in $(cat api_definition.txt); do retval=$(echo $i | sed 's/ .*//g') funcname=$(echo $i | cut -b 5- | sed s/\(.*//g) prot=$(echo $i | sed s/.*\(//g | sed 's/);//g') - echo "#define Bareosdir_${funcname} (*(Bareosdir_${funcname}_RETURN(*)Bareosdir_${funcname}_PROTO) Bareosdir_API[Bareosdir_${funcname}_NUM]) + echo "#define ${PREFIX}_${funcname} (*(${PREFIX}_${funcname}_RETURN(*)${PREFIX}_${funcname}_PROTO) ${PREFIX}_API[${PREFIX}_${funcname}_NUM]) " ((NUM=NUM+1)) done @@ -37,10 +43,10 @@ done exec >capi_3.inc NUM=0 -for i in $(cat bareosdir_api_funcs.txt); do +for i in $(cat api_definition.txt); do retval=$(echo $i | sed 's/ .*//g') funcname=$(echo $i | cut -b 5- | sed s/\(.*//g) prot=$(echo $i | sed s/.*\(//g | sed 's/);//g') - echo " Bareosdir_API[Bareosdir_${funcname}_NUM] = (void*)${funcname};" + echo " ${PREFIX}_API[${PREFIX}_${funcname}_NUM] = (void*)${funcname};" ((NUM=NUM+1)) done diff --git a/core/src/plugins/stored/python/module/c_api/bareossd_api_funcs.txt b/core/src/plugins/stored/python/module/c_api/api_definition.txt similarity index 100% rename from core/src/plugins/stored/python/module/c_api/bareossd_api_funcs.txt rename to core/src/plugins/stored/python/module/c_api/api_definition.txt diff --git a/core/src/plugins/stored/python/module/c_api/create_CAPI_from_bareos_api_funcs.sh b/core/src/plugins/stored/python/module/c_api/create_CAPI_from_bareos_api_funcs.sh deleted file mode 100755 index a931d67a6a4..00000000000 --- a/core/src/plugins/stored/python/module/c_api/create_CAPI_from_bareos_api_funcs.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -IFS=' -' - -exec >capi_1.inc - -echo "/* C API functions */" -NUM=0 -for i in $(cat bareossd_api_funcs.txt); do - retval=$(echo $i | sed 's/ .*//g') - funcname=$(echo $i | cut -b 5- | sed s/\(.*//g) - prot=$(echo $i | sed s/.*\(//g | sed 's/);//g') -echo " -/* static $i */ -#define Bareossd_${funcname}_NUM $NUM -#define Bareossd_${funcname}_RETURN $retval -#define Bareossd_${funcname}_PROTO (${prot})" - -((NUM=NUM+1)) -done -echo " -/*Total Number of C API function pointers */ -#define Bareossd_API_pointers $NUM" - -exec >capi_2.inc - -NUM=0 -for i in $(cat bareossd_api_funcs.txt); do - retval=$(echo $i | sed 's/ .*//g') - funcname=$(echo $i | cut -b 5- | sed s/\(.*//g) - prot=$(echo $i | sed s/.*\(//g | sed 's/);//g') - echo "#define Bareossd_${funcname} (*(Bareossd_${funcname}_RETURN(*)Bareossd_${funcname}_PROTO) Bareossd_API[Bareossd_${funcname}_NUM]) -" -((NUM=NUM+1)) -done - -exec >capi_3.inc - -NUM=0 -for i in $(cat bareossd_api_funcs.txt); do - retval=$(echo $i | sed 's/ .*//g') - funcname=$(echo $i | cut -b 5- | sed s/\(.*//g) - prot=$(echo $i | sed s/.*\(//g | sed 's/);//g') - echo " Bareossd_API[Bareossd_${funcname}_NUM] = (void*)${funcname};" -((NUM=NUM+1)) -done diff --git a/core/src/plugins/stored/python/module/c_api/create_includes_form_api_definition.sh b/core/src/plugins/stored/python/module/c_api/create_includes_form_api_definition.sh new file mode 100755 index 00000000000..c6e9426a91b --- /dev/null +++ b/core/src/plugins/stored/python/module/c_api/create_includes_form_api_definition.sh @@ -0,0 +1,2 @@ +#!/bin/bash +../../../../scripts/create_api_includes.sh Bareossd From 3436515711930a9880bbf7b3e855f273a6015240 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 15:44:42 +0200 Subject: [PATCH 127/341] python-dir, python-sd: set PLUGIN information --- core/src/plugins/dird/python/python-dir.cc | 6 +++--- core/src/plugins/stored/python/python-sd.cc | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index d6a2ddc9048..35787f4a5dc 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -47,9 +47,9 @@ namespace directordaemon { static const int debuglevel = 150; #define PLUGIN_LICENSE "Bareos AGPLv3" -#define PLUGIN_AUTHOR "Marco van Wieringen" -#define PLUGIN_DATE "October 2013" -#define PLUGIN_VERSION "3" +#define PLUGIN_AUTHOR "Bareos GmbH & Co. KG" +#define PLUGIN_DATE "May 2020" +#define PLUGIN_VERSION "4" #define PLUGIN_DESCRIPTION "Python Director Daemon Plugin" #define PLUGIN_USAGE \ "python:instance=:module_path=:module_" \ diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index 838cd967124..6fa20ab02b7 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -46,9 +46,9 @@ namespace storagedaemon { static const int debuglevel = 150; #define PLUGIN_LICENSE "Bareos AGPLv3" -#define PLUGIN_AUTHOR "Marco van Wieringen" -#define PLUGIN_DATE "October 2013" -#define PLUGIN_VERSION "3" +#define PLUGIN_AUTHOR "Bareos GmbH & Co.KG" +#define PLUGIN_DATE "May 2020" +#define PLUGIN_VERSION "4" #define PLUGIN_DESCRIPTION "Python Storage Daemon Plugin" #define PLUGIN_USAGE \ "python:instance=:module_path=:module_" \ From 9c7e016118c6a2be41332ef59ffb23274a826c25 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 15:51:04 +0200 Subject: [PATCH 128/341] bareosdir, bareossd python modules: Copyright info --- core/src/plugins/dird/python/module/bareosdir.h | 3 +-- core/src/plugins/stored/python/module/bareossd.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/plugins/dird/python/module/bareosdir.h b/core/src/plugins/dird/python/module/bareosdir.h index 12f33c0ef03..07dd2195426 100644 --- a/core/src/plugins/dird/python/module/bareosdir.h +++ b/core/src/plugins/dird/python/module/bareosdir.h @@ -1,8 +1,7 @@ /* BAREOS® - Backup Archiving REcovery Open Sourced - Copyright (C) 2013-2014 Planets Communications B.V. - Copyright (C) 2013-2020 Bareos GmbH & Co. KG + Copyright (C) 2020-2020 Bareos GmbH & Co. KG This program is Free Software; you can modify it under the terms of version three of the GNU Affero General Public License as published by the diff --git a/core/src/plugins/stored/python/module/bareossd.h b/core/src/plugins/stored/python/module/bareossd.h index 1d49dbde639..f22784cdd21 100644 --- a/core/src/plugins/stored/python/module/bareossd.h +++ b/core/src/plugins/stored/python/module/bareossd.h @@ -1,7 +1,7 @@ /* BAREOS® - Backup Archiving REcovery Open Sourced - Copyright (C) 2013-2020 Bareos GmbH & Co. KG + Copyright (C) 2020-2020 Bareos GmbH & Co. KG This program is Free Software; you can modify it under the terms of version three of the GNU Affero General Public License as published by the From ed8443b842ed10abd9ff223a3c09f4b841b4706f Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 15:58:56 +0200 Subject: [PATCH 129/341] cmake: created own CMakefile for stored/python --- core/src/plugins/stored/CMakeLists.txt | 104 +--------------- core/src/plugins/stored/python/CMakeLists.txt | 112 ++++++++++++++++++ .../plugins/stored/python/module/setup.py.in | 4 +- 3 files changed, 116 insertions(+), 104 deletions(-) create mode 100644 core/src/plugins/stored/python/CMakeLists.txt diff --git a/core/src/plugins/stored/CMakeLists.txt b/core/src/plugins/stored/CMakeLists.txt index c2fcf6b3bad..0cc531691a0 100644 --- a/core/src/plugins/stored/CMakeLists.txt +++ b/core/src/plugins/stored/CMakeLists.txt @@ -30,6 +30,8 @@ if(HAVE_WIN32) add_definitions(-DMS_WIN${WINDOWS_BITS}) endif() +add_subdirectory(python) + add_library(autoxflate-sd MODULE autoxflate/autoxflate-sd.cc) set_target_properties(autoxflate-sd PROPERTIES PREFIX "") target_link_libraries(autoxflate-sd bareos) @@ -47,105 +49,3 @@ if(NOT HAVE_WIN32 AND NOT HAVE_DARWIN_OS) target_link_libraries(scsitapealert-sd bareossd) endif() endif() - -if(Python2_FOUND) - add_library(python-sd MODULE python/python-sd.cc) - set_target_properties(python-sd PROPERTIES PREFIX "") - install(TARGETS python-sd DESTINATION ${plugindir}) - target_link_libraries(python-sd ${Python2_LIBRARIES} bareos) - target_include_directories(python-sd PUBLIC SYSTEM ${Python2_INCLUDE_DIRS}) - add_dependencies(python-sd bareossd-python2-module) - - set(PYFILES - python/pyfiles/bareos-sd-class-plugin.py - python/pyfiles/BareosSdPluginBaseclass.py - python/pyfiles/bareos-sd.py.template python/pyfiles/BareosSdWrapper.py - ) - - install(FILES ${PYFILES} DESTINATION ${plugindir}) -endif() - -if(Python2_FOUND AND NOT HAVE_WIN32) - configure_file( - python/module/setup.py.in - ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup.py - ) - add_custom_command( - OUTPUT pythonmodules/bareossd.so - MAIN_DEPENDENCY python/module/bareossd.cc - DEPENDS python/module/bareossd.h - DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup.py - COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python2_EXECUTABLE} python/module/setup.py build - COMMAND ${Python2_EXECUTABLE} python/module/setup.py install --install-lib - ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build - COMMENT "building python module pythonmodules/bareossd.so" - ) - - add_custom_target(bareossd-python2-module DEPENDS pythonmodules/bareossd.so) - - add_test(NAME bareossd-python2-module - COMMAND ${Python2_EXECUTABLE} - ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareossd_test.py - ) - set_property( - TEST bareossd-python2-module - PROPERTY - ENVIRONMENT - "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" - LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib - ) -endif() - -if(Python3_FOUND) - add_library(python3-sd MODULE python/python-sd.cc) - set_target_properties(python3-sd PROPERTIES PREFIX "") - install(TARGETS python3-sd DESTINATION ${plugindir}) - target_link_libraries(python3-sd ${Python3_LIBRARIES} bareos) - target_include_directories(python3-sd PUBLIC SYSTEM ${Python3_INCLUDE_DIRS}) - add_dependencies(python3-sd bareossd-python3-module) - - set(PYFILES - python/pyfiles/bareos-sd-class-plugin.py - python/pyfiles/BareosSdPluginBaseclass.py - python/pyfiles/bareos-sd.py.template python/pyfiles/BareosSdWrapper.py - ) - - install(FILES ${PYFILES} DESTINATION ${plugindir}) -endif() - -if(Python3_FOUND AND NOT HAVE_WIN32) - configure_file( - python/module/setup.py.in - ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup.py - ) - add_custom_command( - OUTPUT python3modules/bareossd.so - MAIN_DEPENDENCY python/module/bareossd.cc - DEPENDS python/module/bareossd.h - DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup.py - COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python3_EXECUTABLE} python/module/setup.py build - COMMAND ${Python3_EXECUTABLE} python/module/setup.py install --install-lib - ${CMAKE_CURRENT_BINARY_DIR}/python3modules - COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build - COMMENT "building python module python3modules/bareossd.so" - ) - - add_custom_target(bareossd-python3-module DEPENDS python3modules/bareossd.so) - - add_test(NAME bareossd-python3-module - COMMAND ${Python3_EXECUTABLE} - ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareossd_test.py - ) - set_property( - TEST bareossd-python3-module - PROPERTY - ENVIRONMENT - "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/python3modules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" - LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib - ) -endif() diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt new file mode 100644 index 00000000000..c046fa28afe --- /dev/null +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -0,0 +1,112 @@ +# BAREOS® - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2020-2020 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation and included +# in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + +if(Python2_FOUND) + add_library(python-sd MODULE python-sd.cc) + set_target_properties(python-sd PROPERTIES PREFIX "") + install(TARGETS python-sd DESTINATION ${plugindir}) + target_link_libraries(python-sd ${Python2_LIBRARIES} bareos) + target_include_directories(python-sd PUBLIC SYSTEM ${Python2_INCLUDE_DIRS}) + add_dependencies(python-sd bareossd-python2-module) + + set(PYFILES + pyfiles/bareos-sd-class-plugin.py pyfiles/BareosSdPluginBaseclass.py + pyfiles/bareos-sd.py.template pyfiles/BareosSdWrapper.py + ) + + install(FILES ${PYFILES} DESTINATION ${plugindir}) +endif() + +if(Python2_FOUND AND NOT HAVE_WIN32) + configure_file(module/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py) + add_custom_command( + OUTPUT pythonmodules/bareossd.so + MAIN_DEPENDENCY module/bareossd.cc + DEPENDS module/bareossd.h + DEPENDS bareos + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py + COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build + COMMAND ${Python2_EXECUTABLE} module/setup.py build + COMMAND ${Python2_EXECUTABLE} module/setup.py install --install-lib + ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build + COMMENT "building python module pythonmodules/bareossd.so" + ) + + add_custom_target(bareossd-python2-module DEPENDS pythonmodules/bareossd.so) + + add_test(NAME bareossd-python2-module + COMMAND ${Python2_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/test/bareossd_test.py + ) + set_property( + TEST bareossd-python2-module + PROPERTY + ENVIRONMENT + "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/test" + LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib + ) +endif() + +if(Python3_FOUND) + add_library(python3-sd MODULE python-sd.cc) + set_target_properties(python3-sd PROPERTIES PREFIX "") + install(TARGETS python3-sd DESTINATION ${plugindir}) + target_link_libraries(python3-sd ${Python3_LIBRARIES} bareos) + target_include_directories(python3-sd PUBLIC SYSTEM ${Python3_INCLUDE_DIRS}) + add_dependencies(python3-sd bareossd-python3-module) + + set(PYFILES + pyfiles/bareos-sd-class-plugin.py pyfiles/BareosSdPluginBaseclass.py + pyfiles/bareos-sd.py.template pyfiles/BareosSdWrapper.py + ) + + install(FILES ${PYFILES} DESTINATION ${plugindir}) +endif() + +if(Python3_FOUND AND NOT HAVE_WIN32) + configure_file(module/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py) + add_custom_command( + OUTPUT python3modules/bareossd.so + MAIN_DEPENDENCY module/bareossd.cc + DEPENDS module/bareossd.h + DEPENDS bareos + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py + COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build + COMMAND ${Python3_EXECUTABLE} module/setup.py build + COMMAND ${Python3_EXECUTABLE} module/setup.py install --install-lib + ${CMAKE_CURRENT_BINARY_DIR}/python3modules + COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build + COMMENT "building python module python3modules/bareossd.so" + ) + + add_custom_target(bareossd-python3-module DEPENDS python3modules/bareossd.so) + + add_test(NAME bareossd-python3-module + COMMAND ${Python3_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/test/bareossd_test.py + ) + set_property( + TEST bareossd-python3-module + PROPERTY + ENVIRONMENT + "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/python3modules:${CMAKE_CURRENT_SOURCE_DIR}/test" + LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib + ) +endif() diff --git a/core/src/plugins/stored/python/module/setup.py.in b/core/src/plugins/stored/python/module/setup.py.in index 1baf851fc74..7f16f266f34 100644 --- a/core/src/plugins/stored/python/module/setup.py.in +++ b/core/src/plugins/stored/python/module/setup.py.in @@ -1,8 +1,8 @@ from distutils.core import setup, Extension module1 = Extension('bareossd', - sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/module/bareossd.cc'], - include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..'], + sources = ['@CMAKE_CURRENT_SOURCE_DIR@/module/bareossd.cc'], + include_dirs = ['@PROJECT_SOURCE_DIR@/src'], libraries = ['bareos'], library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'], extra_compile_args=['-std=c++11'], From 46e3eb0ab55e0c34cf727c0760a66f6b39ad0833 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 16:02:53 +0200 Subject: [PATCH 130/341] cmake: create own CMakeFile for python --- core/src/plugins/dird/CMakeLists.txt | 106 +----------------- .../plugins/dird/python/module/setup.py.in | 4 +- 2 files changed, 3 insertions(+), 107 deletions(-) diff --git a/core/src/plugins/dird/CMakeLists.txt b/core/src/plugins/dird/CMakeLists.txt index 28ef4bb8961..e477685d39c 100644 --- a/core/src/plugins/dird/CMakeLists.txt +++ b/core/src/plugins/dird/CMakeLists.txt @@ -30,108 +30,4 @@ if(HAVE_WIN32) add_definitions(-DMS_WIN${WINDOWS_BITS}) endif() -if(Python2_FOUND) - add_library(python-dir MODULE python/python-dir.cc) - # do not prefix with "lib" - set_target_properties(python-dir PROPERTIES PREFIX "") - install(TARGETS python-dir DESTINATION ${plugindir}) - target_link_libraries(python-dir ${Python2_LIBRARIES} bareos) - target_include_directories(python-dir PUBLIC SYSTEM ${Python2_INCLUDE_DIRS}) - add_dependencies(python-dir bareosdir-python2-module) - - set(PYFILES - python/pyfiles/bareos-dir.py.template - python/pyfiles/bareos-dir-class-plugin.py - python/pyfiles/BareosDirPluginBaseclass.py - python/pyfiles/BareosDirWrapper.py - ) - - install(FILES ${PYFILES} DESTINATION ${plugindir}) -endif() - -if(Python2_FOUND AND NOT HAVE_WIN32) - configure_file( - python/module/setup.py.in - ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup.py - ) - add_custom_command( - OUTPUT pythonmodules/bareosdir.so - MAIN_DEPENDENCY python/module/bareosdir.cc - DEPENDS python/module/bareosdir.h - DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup.py - COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python2_EXECUTABLE} python/module/setup.py build - COMMAND ${Python2_EXECUTABLE} python/module/setup.py install --install-lib - ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build - COMMENT "building python2 module pythonmodules/bareosdir.so" - ) - add_custom_target(bareosdir-python2-module DEPENDS pythonmodules/bareosdir.so) - - add_test(NAME bareosdir-python2-module - COMMAND ${Python2_EXECUTABLE} - ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosdir_test.py - ) - set_property( - TEST bareosdir-python2-module - PROPERTY - ENVIRONMENT - "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" - LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib - ) -endif() - -if(Python3_FOUND) - add_library(python3-dir MODULE python/python-dir.cc) - # do not prefix with "lib" - set_target_properties(python3-dir PROPERTIES PREFIX "") - install(TARGETS python3-dir DESTINATION ${plugindir}) - target_link_libraries(python3-dir ${Python3_LIBRARIES} bareos) - target_include_directories(python3-dir PUBLIC SYSTEM ${Python3_INCLUDE_DIRS}) - add_dependencies(python3-dir bareosdir-python3-module) - - set(PYFILES - python/pyfiles/bareos-dir.py.template - python/pyfiles/bareos-dir-class-plugin.py - python/pyfiles/BareosDirPluginBaseclass.py - python/pyfiles/BareosDirWrapper.py - ) - - install(FILES ${PYFILES} DESTINATION ${plugindir}) -endif() - -if(Python3_FOUND AND NOT HAVE_WIN32) - configure_file( - python/module/setup.py.in - ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup.py - ) - add_custom_command( - OUTPUT python3modules/bareosdir.so - MAIN_DEPENDENCY python/module/bareosdir.cc - DEPENDS python/module/bareosdir.h - DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python/module/setup.py - COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python3_EXECUTABLE} python/module/setup.py build - COMMAND ${Python3_EXECUTABLE} python/module/setup.py install --install-lib - ${CMAKE_CURRENT_BINARY_DIR}/python3modules - COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build - COMMENT "building python3 module python3modules/bareosdir.so" - ) - add_custom_target( - bareosdir-python3-module DEPENDS python3modules/bareosdir.so - ) - - add_test(NAME bareosdir-python3-module - COMMAND ${Python3_EXECUTABLE} - ${CMAKE_CURRENT_SOURCE_DIR}/python/test/bareosdir_test.py - ) - set_property( - TEST bareosdir-python3-module - PROPERTY - ENVIRONMENT - "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/python3modules:${CMAKE_CURRENT_SOURCE_DIR}/python/test" - LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib - ) -endif() +add_subdirectory(python) diff --git a/core/src/plugins/dird/python/module/setup.py.in b/core/src/plugins/dird/python/module/setup.py.in index 6a865781f30..04a79e2b5cb 100644 --- a/core/src/plugins/dird/python/module/setup.py.in +++ b/core/src/plugins/dird/python/module/setup.py.in @@ -1,8 +1,8 @@ from distutils.core import setup, Extension module1 = Extension('bareosdir', - sources = ['@CMAKE_CURRENT_SOURCE_DIR@/python/module/bareosdir.cc'], - include_dirs = ['@CMAKE_CURRENT_SOURCE_DIR@/../..'], + sources = ['@CMAKE_CURRENT_SOURCE_DIR@/module/bareosdir.cc'], + include_dirs = ['@PROJECT_SOURCE_DIR@/src'], libraries = ['bareos'], library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'], extra_compile_args=['-std=c++11'], From a1a92b790a9fd6749ed93c27258797b5a15ed57c Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 16:16:30 +0200 Subject: [PATCH 131/341] python plugins tests: added symlinks for xtrabackup and ovirt tests --- systemtests/tests/python3-fd-ovirt-plugin-test | 1 + systemtests/tests/python3-fd-percona-xtrabackup-plugin-test | 1 + 2 files changed, 2 insertions(+) create mode 120000 systemtests/tests/python3-fd-ovirt-plugin-test create mode 120000 systemtests/tests/python3-fd-percona-xtrabackup-plugin-test diff --git a/systemtests/tests/python3-fd-ovirt-plugin-test b/systemtests/tests/python3-fd-ovirt-plugin-test new file mode 120000 index 00000000000..92ee642c62e --- /dev/null +++ b/systemtests/tests/python3-fd-ovirt-plugin-test @@ -0,0 +1 @@ +python-fd-ovirt-plugin-test/ \ No newline at end of file diff --git a/systemtests/tests/python3-fd-percona-xtrabackup-plugin-test b/systemtests/tests/python3-fd-percona-xtrabackup-plugin-test new file mode 120000 index 00000000000..7adf3cb088e --- /dev/null +++ b/systemtests/tests/python3-fd-percona-xtrabackup-plugin-test @@ -0,0 +1 @@ +python-fd-percona-xtrabackup-plugin-test/ \ No newline at end of file From 63e0dd952c455c2df5d3f3803b7a8d4456d6713a Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 16:54:04 +0200 Subject: [PATCH 132/341] python systemtests: fix library output dir --- core/src/plugins/stored/python/CMakeLists.txt | 8 ++++++-- systemtests/CMakeLists.txt | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index c046fa28afe..03ca22d7f6c 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -19,7 +19,9 @@ if(Python2_FOUND) add_library(python-sd MODULE python-sd.cc) - set_target_properties(python-sd PROPERTIES PREFIX "") + set_target_properties( + python-sd PROPERTIES PREFIX "" LIBRARY_OUTPUT_DIRECTORY .. + ) install(TARGETS python-sd DESTINATION ${plugindir}) target_link_libraries(python-sd ${Python2_LIBRARIES} bareos) target_include_directories(python-sd PUBLIC SYSTEM ${Python2_INCLUDE_DIRS}) @@ -66,7 +68,9 @@ endif() if(Python3_FOUND) add_library(python3-sd MODULE python-sd.cc) - set_target_properties(python3-sd PROPERTIES PREFIX "") + set_target_properties( + python3-sd PROPERTIES PREFIX "" LIBRARY_OUTPUT_DIRECTORY .. + ) install(TARGETS python3-sd DESTINATION ${plugindir}) target_link_libraries(python3-sd ${Python3_LIBRARIES} bareos) target_include_directories(python3-sd PUBLIC SYSTEM ${Python3_INCLUDE_DIRS}) diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index c2f05379aea..d85e762ac3b 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -842,9 +842,9 @@ foreach(TEST_NAME ${SYSTEM_TESTS}) "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/pyfiles:" "${CMAKE_SOURCE_DIR}/core/src/plugins/stored/python/pyfiles:" "${CMAKE_SOURCE_DIR}/core/src/plugins/dird/python/pyfiles:" - "${CMAKE_BINARY_DIR}/core/src/plugins/filed/${python_version}modules:" - "${CMAKE_BINARY_DIR}/core/src/plugins/stored/${python_version}modules:" - "${CMAKE_BINARY_DIR}/core/src/plugins/dird/${python_version}modules:" + "${CMAKE_BINARY_DIR}/core/src/plugins/filed/python/${python_version}modules:" + "${CMAKE_BINARY_DIR}/core/src/plugins/stored/python/${python_version}modules:" + "${CMAKE_BINARY_DIR}/core/src/plugins/dird/python/${python_version}modules:" "${CMAKE_CURRENT_SOURCE_DIR}/tests/${TEST_NAME}/python-modules" ) From 7d78393338ea4789060e5ce96393ddde685e7643 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 17:17:53 +0200 Subject: [PATCH 133/341] python systemtests: adapt PYTHONPATH for subdir structure --- systemtests/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index d85e762ac3b..a4a851356f0 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -840,6 +840,8 @@ foreach(TEST_NAME ${SYSTEM_TESTS}) CONCAT pythonpath "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/pyfiles:" + "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/percona-xtrabackup:" + "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/ovirt:" "${CMAKE_SOURCE_DIR}/core/src/plugins/stored/python/pyfiles:" "${CMAKE_SOURCE_DIR}/core/src/plugins/dird/python/pyfiles:" "${CMAKE_BINARY_DIR}/core/src/plugins/filed/python/${python_version}modules:" From 93ec38c2aca664c4e9be40dc14d9e897b30a76e0 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 18 May 2020 18:00:50 +0200 Subject: [PATCH 134/341] percona plugin: working --- .../percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py | 3 +-- .../python/percona-xtrabackup/bareos-fd-percona-xtrabackup.py | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/core/src/plugins/filed/python/percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py b/core/src/plugins/filed/python/percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py index 9aa48e3a892..77d920052d3 100644 --- a/core/src/plugins/filed/python/percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py +++ b/core/src/plugins/filed/python/percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py @@ -22,7 +22,6 @@ # Uses Percona's xtrabackup for backup and restore of MySQL / MariaDB databases from bareosfd import * -from bareos_fd_consts import * import os from subprocess import * from BareosFdPluginBaseclass import * @@ -183,7 +182,7 @@ def start_backup_job(self): We will check, if database has changed since last backup in the incremental case """ - check_option_bRC = self.check_plugin_options(context) + check_option_bRC = self.check_plugin_options() if check_option_bRC != bRCs["bRC_OK"]: return check_option_bRC bareosfd.DebugMessage( diff --git a/core/src/plugins/filed/python/percona-xtrabackup/bareos-fd-percona-xtrabackup.py b/core/src/plugins/filed/python/percona-xtrabackup/bareos-fd-percona-xtrabackup.py index 9aa494f363e..e53eabba7c9 100644 --- a/core/src/plugins/filed/python/percona-xtrabackup/bareos-fd-percona-xtrabackup.py +++ b/core/src/plugins/filed/python/percona-xtrabackup/bareos-fd-percona-xtrabackup.py @@ -20,7 +20,6 @@ # Provided by the Bareos FD Python plugin interface from bareosfd import * -from bareos_fd_consts import * # This module contains the wrapper functions called by the Bareos-FD, the functions call the corresponding # methods from your plugin class From fd17085a11862c81495260cf67fdda343c914e0b Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 19 May 2020 17:31:29 +0200 Subject: [PATCH 135/341] systemtest: percona test adapted --- systemtests/CMakeLists.txt | 1 + .../mysqldefaults.in | 14 ++++++++++ .../fileset/PerconaXtraBackupTest.conf.in | 2 +- .../pyplug-fd-percona-xtrabackup/testrunner | 26 ++++++++++++++----- 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 systemtests/tests/pyplug-fd-local-fileset-restoreobject/mysqldefaults.in diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index a4a851356f0..82c48dfc96a 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -250,6 +250,7 @@ macro(prepare_test) math(EXPR sd_port "${BASEPORT} + 2") math(EXPR sd2_port "${BASEPORT} + 3") math(EXPR php_port "${BASEPORT} + 4") + math(EXPR test_db_port "${BASEPORT} + 5") # skip for tests without etc/bareos ("catalog" test) if(EXISTS ${current_test_source_directory}/etc/bareos) diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/mysqldefaults.in b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/mysqldefaults.in new file mode 100644 index 00000000000..e2f224594b5 --- /dev/null +++ b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/mysqldefaults.in @@ -0,0 +1,14 @@ +[client] +# TCP port to use to connect to mysqld server +port=@test_db_port@ +# Socket to use to connect to mysqld server +socket=@PROJECT_BINARY_DIR@/tests/@TEST_NAME@/mysql/mysql.sock +[mysqld] +# TCP port to make available for clients +bind-address=127.0.0.1 +port=@test_db_port@ +# Socket to make available for clients +socket=@PROJECT_BINARY_DIR@/tests/@TEST_NAME@/mysql/mysql.sock +# Where MariaDB should store all its data +datadir=@PROJECT_BINARY_DIR@/tests/@TEST_NAME@/mysql/data + diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in b/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in index 97bce7fc929..d2781285ba4 100644 --- a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in +++ b/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in @@ -5,6 +5,6 @@ FileSet { Options { signature = MD5 } - Plugin = "@python_version@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-percona-xtrabackup:dumpbinary=@XTRABACKUP@:extradumpoptions=@extradumpoptions@" + Plugin = "@python_version@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-percona-xtrabackup:dumpbinary=@XTRABACKUP@ --defaults-file=mysqldefaults:extradumpoptions=--user=root@extradumpoptions@:mysqlcmd=mysql --defaults-file=mysqldefaults --user=root" } } diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner b/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner index a927d9fae2e..cbac3797150 100755 --- a/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner +++ b/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner @@ -7,6 +7,8 @@ TestName="$(basename "$(pwd)")" export TestName +MYSQL="mysql --defaults-file=mysqldefaults --user=root" + JobName=backup-bareos-fd #shellcheck source=../environment.in . ./environment @@ -17,14 +19,24 @@ JobName=backup-bareos-fd "${rscripts}"/cleanup "${rscripts}"/setup + +mkdir -p mysql/data/ +# initialize mysql db +mysqld --defaults-file=mysqldefaults --user=pstorz --initialize-insecure > mysql/mysql_init.log 2>1 + +# start mysql server +mysqld --defaults-file=mysqldefaults >mysql/mysql.log 2>&1 & + +sleep 4 + xtrabackup_test_db="${db_name}_xtrabackup" start_test -echo "drop database ${xtrabackup_test_db}" | mysql -echo "create database ${xtrabackup_test_db}" | mysql -echo "CREATE TABLE test ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, data VARCHAR(100), created TIMESTAMP DEFAULT NOW()) " | mysql ${xtrabackup_test_db} -echo "insert into test (data) VALUES ('test entry 1') " | mysql ${xtrabackup_test_db} +echo "drop database ${xtrabackup_test_db}" | $MYSQL +echo "create database ${xtrabackup_test_db}" | $MYSQL +echo "CREATE TABLE test ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, data VARCHAR(100), created TIMESTAMP DEFAULT NOW()) " | $MYSQL ${xtrabackup_test_db} +echo "insert into test (data) VALUES ('test entry 1') " | $MYSQL ${xtrabackup_test_db} run_bareos "$@" @@ -36,7 +48,7 @@ echo "$COMMAND yes" | $BAREOS_BCONSOLE_BINARY -c "$conf"/bconsole.conf echo "wait JobName=$JobName" | $BAREOS_BCONSOLE_BINARY -c "$conf"/bconsole.conf echo "status dir" | $BAREOS_BCONSOLE_BINARY -c "$conf"/bconsole.conf # insert data and run incremental -echo "insert into test (data) VALUES ('test entry 2') " | mysql ${xtrabackup_test_db} +echo "insert into test (data) VALUES ('test entry 2') " | $MYSQL ${xtrabackup_test_db} COMMAND="$COMMAND level=Incremental" echo "$COMMAND yes" | $BAREOS_BCONSOLE_BINARY -c "$conf"/bconsole.conf #| grep "Job queued. JobId=" @@ -73,7 +85,9 @@ fi - +# shutdown mysql +kill $(cat mysql/data/*.pid) +rm -Rvf $current_test_directory/mysql/data/* check_for_zombie_jobs storage=File stop_bareos From c089e5a23ce4f67f4b64d87aece76c30b218e532 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 19 May 2020 17:58:56 +0200 Subject: [PATCH 136/341] percona test: more adaptions for python3 --- .../BareosFdPluginPerconaXtraBackup.py | 110 +++++++++--------- .../bareos-fd-percona-xtrabackup.py | 2 +- .../bareos/bareos-fd.d/client/myself.conf.in | 2 +- .../bareos/bareos-fd.d/client/myself.conf.in | 2 +- .../bareos/bareos-fd.d/client/myself.conf.in | 2 +- 5 files changed, 59 insertions(+), 59 deletions(-) diff --git a/core/src/plugins/filed/python/percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py b/core/src/plugins/filed/python/percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py index 77d920052d3..7a177b670ca 100644 --- a/core/src/plugins/filed/python/percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py +++ b/core/src/plugins/filed/python/percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py @@ -46,7 +46,7 @@ def __init__(self, plugindef): # the lsn file as restore-object self.files_to_backup = ["lsnfile", "stream"] self.tempdir = tempfile.mkdtemp() - # self.logdir = GetValue(bVariable['bVarWorkingDir']) + # self.logdir = GetValue(bVarWorkingDir) self.logdir = "/var/log/bareos/" self.log = "bareos-plugin-percona.log" self.rop_data = {} @@ -119,18 +119,18 @@ def parse_plugin_definition(self, plugindef): else: self.mysqlcmd = "mysql %s -r" % self.mycnf - return bRCs["bRC_OK"] + return bRC_OK def check_plugin_options(self, mandatory_options=None): - accurate_enabled = GetValue(bVariable["bVarAccurate"]) + accurate_enabled = GetValue(bVarAccurate) if accurate_enabled is not None and accurate_enabled != 0: JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "start_backup_job: Accurate backup not allowed please disable in Job\n", ) - return bRCs["bRC_Error"] + return bRC_Error else: - return bRCs["bRC_OK"] + return bRC_OK def create_file(self, restorepkt): """ @@ -150,7 +150,7 @@ def create_file(self, restorepkt): self.writeDir += "%010d" % origJobId else: JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, "No lsn information found in restore object for file %s from job %d\n" % (FNAME, origJobId), ) @@ -165,17 +165,17 @@ def create_file(self, restorepkt): # Percona requires empty directory if os.listdir(self.writeDir): JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "Restore with xbstream needs empty directory: %s\n" % self.writeDir, ) - return bRCs["bRC_Error"] + return bRC_Error self.restorecommand += self.writeDir DebugMessage( 100, 'Restore using xbstream to extract files with "%s"\n' % self.restorecommand, ) restorepkt.create_status = bCFs["CF_EXTRACT"] - return bRCs["bRC_OK"] + return bRC_OK def start_backup_job(self): """ @@ -183,7 +183,7 @@ def start_backup_job(self): in the incremental case """ check_option_bRC = self.check_plugin_options() - if check_option_bRC != bRCs["bRC_OK"]: + if check_option_bRC != bRC_OK: return check_option_bRC bareosfd.DebugMessage( 100, "start_backup_job, level: %s\n" % chr(self.level) @@ -192,10 +192,10 @@ def start_backup_job(self): # We check, if we have a LSN received by restore object from previous job if self.max_to_lsn == 0: JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "No LSN received to be used with incremental backup\n", ) - return bRCs["bRC_Error"] + return bRC_Error # Try to load MySQLdb module hasMySQLdbModule = False try: @@ -217,10 +217,10 @@ def start_backup_job(self): result = cursor.fetchall() if len(result) == 0: JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "Could not fetch SHOW ENGINE INNODB STATUS, unprivileged user?", ) - return bRCs["bRC_Error"] + return bRC_Error info = result[0][2] conn.close() for line in info.split("\n"): @@ -228,10 +228,10 @@ def start_backup_job(self): last_lsn = int(line.split(" ")[-1]) except Exception as e: JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "Could not get LSN, Error: %s" % e, ) - return bRCs["bRC_Error"] + return bRC_Error # use old method as fallback, if module MySQLdb not available else: get_lsn_command = ( @@ -246,22 +246,22 @@ def start_backup_job(self): (mysqlStdOut, mysqlStdErr) = last_lsn_proc.communicate() if returnCode != 0 or mysqlStdErr: JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, 'Could not get LSN with command "%s", Error: %s' % (get_lsn_command, mysqlStdErr), ) - return bRCs["bRC_Error"] + return bRC_Error else: try: last_lsn = int(mysqlStdOut) except: JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, 'Error reading LSN: "%s" not an integer' % mysqlStdOut, ) - return bRCs["bRC_Error"] + return bRC_Error JobMessage( - bJobMessageType["M_INFO"], "Backup until LSN: %d\n" % last_lsn + M_INFO, "Backup until LSN: %d\n" % last_lsn ) if ( self.max_to_lsn > 0 @@ -274,8 +274,8 @@ def start_backup_job(self): % (last_lsn, self.max_to_lsn), ) self.files_to_backup = ["lsn_only"] - return bRCs["bRC_OK"] - return bRCs["bRC_OK"] + return bRC_OK + return bRC_OK def start_backup_file(self, savepkt): """ @@ -294,7 +294,7 @@ def start_backup_file(self, savepkt): if self.file_to_backup == "stream": # This is the database backup as xbstream savepkt.fname = "/_percona/xbstream.%010d" % self.jobId - savepkt.type = bFileType["FT_REG"] + savepkt.type = FT_REG if self.max_to_lsn > 0: self.dumpoptions += " --incremental-lsn=%d" % self.max_to_lsn self.dumpcommand = "%s %s" % (self.dumpbinary, self.dumpoptions) @@ -309,7 +309,7 @@ def start_backup_file(self, savepkt): key, value = line.partition("=")[::2] checkpoints[key.strip()] = value.strip() savepkt.fname = "/_percona/xtrabackup_checkpoints" - savepkt.type = bFileType["FT_RESTORE_FIRST"] + savepkt.type = FT_RESTORE_FIRST savepkt.object_name = savepkt.fname savepkt.object = bytearray(json.dumps(checkpoints)) savepkt.object_len = len(savepkt.object) @@ -319,7 +319,7 @@ def start_backup_file(self, savepkt): # We have nothing to backup incremental, so we just have to pass # the restore object from previous job savepkt.fname = "/_percona/xtrabackup_checkpoints" - savepkt.type = bFileType["FT_RESTORE_FIRST"] + savepkt.type = FT_RESTORE_FIRST savepkt.object_name = savepkt.fname savepkt.object = bytearray(self.row_rop_raw) savepkt.object_len = len(savepkt.object) @@ -327,15 +327,15 @@ def start_backup_file(self, savepkt): else: # should not happen JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "Unknown error. Don't know how to handle %s\n" % self.file_to_backup, ) JobMessage( - bJobMessageType["M_INFO"], + M_INFO, "Starting backup of " + savepkt.fname + "\n", ) - return bRCs["bRC_OK"] + return bRC_OK def plugin_io(self, IOP): """ @@ -344,7 +344,7 @@ def plugin_io(self, IOP): """ DebugMessage(200, "plugin_io called with " + str(IOP.func) + "\n") - if IOP.func == bIOPS["IO_OPEN"]: + if IOP.func == IO_OPEN: DebugMessage(100, "plugin_io called with IO_OPEN\n") if self.log: try: @@ -373,15 +373,15 @@ def plugin_io(self, IOP): self.stream = Popen( self.dumpcommand, shell=True, stdout=PIPE, stderr=self.err_fd ) - return bRCs["bRC_OK"] + return bRC_OK - elif IOP.func == bIOPS["IO_READ"]: + elif IOP.func == IO_READ: IOP.buf = bytearray(IOP.count) IOP.status = self.stream.stdout.readinto(IOP.buf) IOP.io_errno = 0 - return bRCs["bRC_OK"] + return bRC_OK - elif IOP.func == bIOPS["IO_WRITE"]: + elif IOP.func == IO_WRITE: try: self.stream.stdin.write(IOP.buf) IOP.status = IOP.count @@ -391,9 +391,9 @@ def plugin_io(self, IOP): DebugMessage( 100, "Error writing data: " + format(str(msg)) + "\n" ) - return bRCs["bRC_OK"] + return bRC_OK - elif IOP.func == bIOPS["IO_CLOSE"]: + elif IOP.func == IO_CLOSE: DebugMessage(100, "plugin_io called with IO_CLOSE\n") self.subprocess_returnCode = self.stream.poll() if self.subprocess_returnCode is None: @@ -403,28 +403,28 @@ def plugin_io(self, IOP): self.subprocess_returnCode = self.stream.poll() except: JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, "Dump / restore command not finished properly\n", ) - bRCs["bRC_Error"] - return bRCs["bRC_OK"] + bRC_Error + return bRC_OK else: DebugMessage( 100, "Subprocess has terminated with returncode: %d\n" % self.subprocess_returnCode, ) - return bRCs["bRC_OK"] + return bRC_OK - elif IOP.func == bIOPS["IO_SEEK"]: - return bRCs["bRC_OK"] + elif IOP.func == IO_SEEK: + return bRC_OK else: DebugMessage( 100, "plugin_io called with unsupported IOP:" + str(IOP.func) + "\n", ) - return bRCs["bRC_OK"] + return bRC_OK def end_backup_file(self): """ @@ -436,7 +436,7 @@ def end_backup_file(self): returnCode = self.subprocess_returnCode if returnCode is None: JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, "Dump command not finished properly for unknown reason\n", ) returnCode = -99 @@ -454,10 +454,10 @@ def end_backup_file(self): if self.log: msg += ['log file: "%s"' % self.log] JobMessage( - bJobMessageType["M_FATAL"], ", ".join(msg) + "\n" + M_FATAL, ", ".join(msg) + "\n" ) if returnCode != 0: - return bRCs["bRC_Error"] + return bRC_Error if self.log: self.err_fd.write( @@ -467,9 +467,9 @@ def end_backup_file(self): self.err_fd.close() if self.files_to_backup: - return bRCs["bRC_More"] + return bRC_More else: - return bRCs["bRC_OK"] + return bRC_OK def end_restore_file(self): """ @@ -478,7 +478,7 @@ def end_restore_file(self): returnCode = self.subprocess_returnCode if returnCode is None: JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, "Restore command not finished properly for unknown reason\n", ) returnCode = -99 @@ -492,7 +492,7 @@ def end_restore_file(self): msg = ["Restore command returned non-zero value: %d" % return_code] if self.log: msg += ['log file: "%s"' % self.log] - JobMessage(bJobMessageType["M_ERROR"], ", ".join(msg) + "\n") + JobMessage(M_ERROR, ", ".join(msg) + "\n") if self.log: self.err_fd.write( "%s Restore Job %s closes stream\n" @@ -501,9 +501,9 @@ def end_restore_file(self): self.err_fd.close() if returnCode == 0: - return bRCs["bRC_OK"] + return bRC_OK else: - return bRCs["bRC_Error"] + return bRC_Error def restore_object_data(self, ROP): """ @@ -518,11 +518,11 @@ def restore_object_data(self, ROP): ): self.max_to_lsn = int(self.rop_data[ROP.jobid]["to_lsn"]) JobMessage( - bJobMessageType["M_INFO"], + M_INFO, "Got to_lsn %d from restore object of job %d\n" % (self.max_to_lsn, ROP.jobid), ) - return bRCs["bRC_OK"] + return bRC_OK # vim: ts=4 tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/core/src/plugins/filed/python/percona-xtrabackup/bareos-fd-percona-xtrabackup.py b/core/src/plugins/filed/python/percona-xtrabackup/bareos-fd-percona-xtrabackup.py index e53eabba7c9..81e3ba57ded 100644 --- a/core/src/plugins/filed/python/percona-xtrabackup/bareos-fd-percona-xtrabackup.py +++ b/core/src/plugins/filed/python/percona-xtrabackup/bareos-fd-percona-xtrabackup.py @@ -36,7 +36,7 @@ def load_bareos_plugin(plugindef): """ # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that holds the plugin class object BareosFdWrapper.bareos_fd_plugin_object = BareosFdPercona(plugindef) - return bRCs["bRC_OK"] + return bRC_OK # the rest is done in the Plugin module diff --git a/systemtests/tests/dbcopy-mysql-postgresql/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/dbcopy-mysql-postgresql/etc/bareos/bareos-fd.d/client/myself.conf.in index 097ea16e2a6..d112d62cf62 100644 --- a/systemtests/tests/dbcopy-mysql-postgresql/etc/bareos/bareos-fd.d/client/myself.conf.in +++ b/systemtests/tests/dbcopy-mysql-postgresql/etc/bareos/bareos-fd.d/client/myself.conf.in @@ -7,7 +7,7 @@ Client { # otherwise all filedaemon plugins (*-fd.so) from the "Plugin Directory". # Plugin Directory = "@fd_plugin_binary_path@" - Plugin Names = "python" + Plugin Names = "@python_version@" # if compatible is set to yes, we are compatible with bacula # if set to no, new bareos features are enabled which is the default diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/client/myself.conf.in index 49039c29d18..d3978eea8a8 100644 --- a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/client/myself.conf.in +++ b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/client/myself.conf.in @@ -7,7 +7,7 @@ Client { # otherwise all filedaemon plugins (*-fd.so) from the "Plugin Directory". # Plugin Directory = "@fd_plugin_binary_path@" - Plugin Names = "python" + Plugin Names = "@python_version@" # if compatible is set to yes, we are compatible with bacula # if set to no, new bareos features are enabled which is the default diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-fd.d/client/myself.conf.in index 49039c29d18..d3978eea8a8 100644 --- a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-fd.d/client/myself.conf.in +++ b/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-fd.d/client/myself.conf.in @@ -7,7 +7,7 @@ Client { # otherwise all filedaemon plugins (*-fd.so) from the "Plugin Directory". # Plugin Directory = "@fd_plugin_binary_path@" - Plugin Names = "python" + Plugin Names = "@python_version@" # if compatible is set to yes, we are compatible with bacula # if set to no, new bareos features are enabled which is the default From 91a0f48cee327d6ea903428cc58f97d1ed4e6e92 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 20 May 2020 13:37:57 +0200 Subject: [PATCH 137/341] python-fd-percona-test: clean up testrunner --- .../pyplug-fd-percona-xtrabackup/testrunner | 60 +++++++++++-------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner b/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner index cbac3797150..744eb8657d5 100755 --- a/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner +++ b/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner @@ -38,44 +38,52 @@ echo "create database ${xtrabackup_test_db}" | $MYSQL echo "CREATE TABLE test ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, data VARCHAR(100), created TIMESTAMP DEFAULT NOW()) " | $MYSQL ${xtrabackup_test_db} echo "insert into test (data) VALUES ('test entry 1') " | $MYSQL ${xtrabackup_test_db} +cat <$tmp/bconcmds +@$out $tmp/log1.out +run job=$JobName yes +wait JobName=$JobName +status dir -run_bareos "$@" - -echo "@$out $tmp/log1.out" | $BAREOS_BCONSOLE_BINARY -c "$conf"/bconsole.conf +run job=$JobName level=Incremental yes +wait JobName=$JobName +status dir -COMMAND="run job=$JobName" -echo "$COMMAND yes" | $BAREOS_BCONSOLE_BINARY -c "$conf"/bconsole.conf -echo "wait JobName=$JobName" | $BAREOS_BCONSOLE_BINARY -c "$conf"/bconsole.conf -echo "status dir" | $BAREOS_BCONSOLE_BINARY -c "$conf"/bconsole.conf # insert data and run incremental -echo "insert into test (data) VALUES ('test entry 2') " | $MYSQL ${xtrabackup_test_db} - -COMMAND="$COMMAND level=Incremental" -echo "$COMMAND yes" | $BAREOS_BCONSOLE_BINARY -c "$conf"/bconsole.conf #| grep "Job queued. JobId=" -echo "wait JobName=$JobName" | $BAREOS_BCONSOLE_BINARY -c "$conf"/bconsole.conf -echo "status dir" | $BAREOS_BCONSOLE_BINARY -c "$conf"/bconsole.conf +insert into test (data) VALUES ('test entry 2') +END_OF_DATA +run_bareos "$@" +cat <"$tmp/bconcmds" # run incremental again without any new data -echo "$COMMAND yes" | $BAREOS_BCONSOLE_BINARY -c "$conf"/bconsole.conf #| grep "Job queued. JobId=" -echo "wait JobName=$JobName" | $BAREOS_BCONSOLE_BINARY -c "$conf"/bconsole.conf -echo "status dir" | $BAREOS_BCONSOLE_BINARY -c "$conf"/bconsole.conf +run job=$JobName yes +wait JobName=$JobName +status dir +wait +messages +quit +END_OF_DATA2 +run_bareos "$@" +cat <"$tmp/bconcmds" +restore client=bareos-fd fileset=PerconaXtraBackupTest yes restorejob=RestoreFile select all done +@$out $tmp/log2.out +wait +END_OF_DATA3 -# run restore -RESTORECMD="restore client=bareos-fd fileset=PerconaXtraBackupTest yes restorejob=RestoreFile select all done" +run_bareos "$@" -echo "@$out $tmp/log2.out" | $BAREOS_BCONSOLE_BINARY -c "$conf"/bconsole.conf +#JOBID=$(echo "$RESTORECMD" | $BAREOS_BCONSOLE_BINARY -c "$conf"/bconsole.conf | grep "Job queued. JobId=" | sed s'/.*=//') +# +#if ! echo "wait jobid=$JOBID" | $BAREOS_BCONSOLE_BINARY -c "$conf"/bconsole.conf | grep -q "JobStatus=OK"; +#then +# echo "Restore Job $JOBID failed" +# estat=1 +#fi -JOBID=$(echo "$RESTORECMD" | $BAREOS_BCONSOLE_BINARY -c "$conf"/bconsole.conf | grep "Job queued. JobId=" | sed s'/.*=//') -if ! echo "wait jobid=$JOBID" | $BAREOS_BCONSOLE_BINARY -c "$conf"/bconsole.conf | grep -q "JobStatus=OK"; -then - echo "Restore Job $JOBID failed" - estat=1 -fi -# Check, if xtrabackup has extracted some files at least +# Check if xtrabackup has extracted some files at least # TODO: verify that xtrabackup --prepare works and eventually do complete datbase restore ls -lR $tmp/bareos-restores/_percona/ if [ -z "$(ls -A $tmp/bareos-restores/_percona/)" ]; then From 2735b6850b4deed6081dab8e8506d16f001d1091 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 20 May 2020 14:00:01 +0200 Subject: [PATCH 138/341] PerconaXtraBackup: ported to python3 --- .../percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/plugins/filed/python/percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py b/core/src/plugins/filed/python/percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py index 7a177b670ca..be8830338dc 100644 --- a/core/src/plugins/filed/python/percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py +++ b/core/src/plugins/filed/python/percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py @@ -174,7 +174,7 @@ def create_file(self, restorepkt): 100, 'Restore using xbstream to extract files with "%s"\n' % self.restorecommand, ) - restorepkt.create_status = bCFs["CF_EXTRACT"] + restorepkt.create_status = CF_EXTRACT return bRC_OK def start_backup_job(self): @@ -311,7 +311,7 @@ def start_backup_file(self, savepkt): savepkt.fname = "/_percona/xtrabackup_checkpoints" savepkt.type = FT_RESTORE_FIRST savepkt.object_name = savepkt.fname - savepkt.object = bytearray(json.dumps(checkpoints)) + savepkt.object = bytearray(json.dumps(checkpoints) ,encoding='utf8') savepkt.object_len = len(savepkt.object) savepkt.object_index = int(time.time()) shutil.rmtree(self.tempdir) @@ -511,10 +511,10 @@ def restore_object_data(self, ROP): """ # Improve: sanity / consistence check of restore object self.row_rop_raw = ROP.object - self.rop_data[ROP.jobid] = json.loads(str(self.row_rop_raw)) + self.rop_data[ROP.jobid] = json.loads((self.row_rop_raw.decode('utf-8'))) if ( "to_lsn" in self.rop_data[ROP.jobid] - and self.rop_data[ROP.jobid]["to_lsn"] > self.max_to_lsn + and int(self.rop_data[ROP.jobid]["to_lsn"]) > self.max_to_lsn ): self.max_to_lsn = int(self.rop_data[ROP.jobid]["to_lsn"]) JobMessage( From 7fa1f24fc108c8f6e8559da9d4e96755815509b7 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 22 May 2020 09:28:00 +0200 Subject: [PATCH 139/341] systemtests: repaired python-dir-plugin-test --- systemtests/CMakeLists.txt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 82c48dfc96a..a14454bd76f 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -378,11 +378,7 @@ else() # run systemtests on source and compiled files get_target_property(SD_BACKEND_DIR_TO_TEST bareossd-gfapi BINARY_DIR) endif() - if(TARGET python-dir) - get_target_property(DIR_PLUGINS_DIR_TO_TEST python-dir BINARY_DIR) - else() - set(DIR_PLUGINS_DIR_TO_TEST ${CMAKE_BINARY_DIR}/core/src/plugins/dird) - endif() + set(DIR_PLUGINS_DIR_TO_TEST ${CMAKE_BINARY_DIR}/core/src/plugins/dird) get_target_property(BACKEND_DIR_TO_TEST bareoscats BINARY_DIR) set(SCRIPTS_DIR_TO_TEST ${CMAKE_BINARY_DIR}/core/scripts) From 751aa4d999c0116a75c483aee5894291553e4a38 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 22 May 2020 10:32:55 +0200 Subject: [PATCH 140/341] python plugins and modules: introduce LOGPREFIX --- .../plugins/dird/python/module/bareosdir.cc | 22 +++++--- core/src/plugins/dird/python/python-dir.cc | 28 +++++++---- .../plugins/filed/python/module/bareosfd.cc | 50 +++++++++++-------- core/src/plugins/filed/python/python-fd.cc | 33 ++++++------ core/src/plugins/filed/python/python-fd.h | 1 - .../plugins/stored/python/module/bareossd.cc | 26 ++++++---- core/src/plugins/stored/python/python-sd.cc | 35 +++++++------ 7 files changed, 116 insertions(+), 79 deletions(-) diff --git a/core/src/plugins/dird/python/module/bareosdir.cc b/core/src/plugins/dird/python/module/bareosdir.cc index 3a26b3b3476..02a947718e0 100644 --- a/core/src/plugins/dird/python/module/bareosdir.cc +++ b/core/src/plugins/dird/python/module/bareosdir.cc @@ -32,6 +32,13 @@ #include #include "include/bareos.h" #endif + +#if PY_VERSION_HEX < 0x03000000 +#define LOGPREFIX "python-dir-mod: " +#else +#define LOGPREFIX "python3-dir-mod: " +#endif + #include "dird/dird.h" #include "dird/dir_plugins.h" @@ -125,7 +132,8 @@ static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value) return retval; } else { Dmsg(plugin_ctx, debuglevel, - "python-dir: Failed to find function named " + LOGPREFIX + "Failed to find function named " "parse_plugin_definition()\n"); return bRC_Error; } @@ -180,7 +188,7 @@ static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, } } else { Dmsg(plugin_ctx, debuglevel, - "python-dir: Failed to find function named handle_plugin_event()\n"); + LOGPREFIX "Failed to find function named handle_plugin_event()\n"); } return retval; @@ -266,7 +274,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) } default: Dmsg(plugin_ctx, debuglevel, - "python-dir: PyBareosGetValue unknown variable requested %d\n", var); + LOGPREFIX "PyBareosGetValue unknown variable requested %d\n", var); break; } @@ -318,7 +326,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) } default: Dmsg(plugin_ctx, debuglevel, - "python-dir: PyBareosSetValue unknown variable requested %d\n", var); + LOGPREFIX "PyBareosSetValue unknown variable requested %d\n", var); break; } @@ -342,7 +350,7 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (dbgmsg) { Dmsg(plugin_ctx, level, "python-dir: %s", dbgmsg); } + if (dbgmsg) { Dmsg(plugin_ctx, level, LOGPREFIX "%s", dbgmsg); } Py_RETURN_NONE; } @@ -363,7 +371,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (jobmsg) { Jmsg(plugin_ctx, type, "python-dir: %s", jobmsg); } + if (jobmsg) { Jmsg(plugin_ctx, type, LOGPREFIX "%s", jobmsg); } Py_RETURN_NONE; } @@ -396,7 +404,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) if (event >= bDirEventJobStart && event <= bDirEventGetScratch) { Dmsg(plugin_ctx, debuglevel, - "python-dir: PyBareosRegisterEvents registering event %d\n", event); + LOGPREFIX "PyBareosRegisterEvents registering event %d\n", event); retval = bareos_core_functions->registerBareosEvents(plugin_ctx, 1, event); diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index 35787f4a5dc..eda2032d4f9 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -33,8 +33,15 @@ #include #include "include/bareos.h" #endif -#include "dird/dird.h" +#if PY_VERSION_HEX < 0x03000000 +#define LOGPREFIX "python-dir: " +#else +#define LOGPREFIX "python3-dir " +#endif + + +#include "dird/dird.h" #include "plugins/include/python3compat.h" #include "python-dir.h" @@ -406,9 +413,9 @@ static bRC parse_plugin_definition(PluginContext* plugin_ctx, bp = strchr(plugin_definition.c_str(), ':'); if (!bp) { - Jmsg(plugin_ctx, M_FATAL, "python-dir: Illegal plugin definition %s\n", + Jmsg(plugin_ctx, M_FATAL, LOGPREFIX "Illegal plugin definition %s\n", plugin_definition.c_str()); - Dmsg(plugin_ctx, debuglevel, "python-dir: Illegal plugin definition %s\n", + Dmsg(plugin_ctx, debuglevel, LOGPREFIX "Illegal plugin definition %s\n", plugin_definition.c_str()); goto bail_out; } @@ -432,10 +439,10 @@ static bRC parse_plugin_definition(PluginContext* plugin_ctx, argument = bp; argument_value = strchr(bp, '='); if (!argument_value) { - Jmsg(plugin_ctx, M_FATAL, - "python-dir: Illegal argument %s without value\n", argument); + Jmsg(plugin_ctx, M_FATAL, LOGPREFIX "Illegal argument %s without value\n", + argument); Dmsg(plugin_ctx, debuglevel, - "python-dir: Illegal argument %s without value\n", argument); + LOGPREFIX "Illegal argument %s without value\n", argument); goto bail_out; } *argument_value++ = '\0'; @@ -548,7 +555,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) /* Try to load the Python module by name. */ if (plugin_priv_ctx->module_name) { Dmsg(plugin_ctx, debuglevel, - "python-dir: Trying to load module with name %s\n", + LOGPREFIX "Trying to load module with name %s\n", plugin_priv_ctx->module_name); pName = PyUnicode_FromString(plugin_priv_ctx->module_name); plugin_priv_ctx->pModule = PyImport_Import(pName); @@ -556,13 +563,13 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) if (!plugin_priv_ctx->pModule) { Dmsg(plugin_ctx, debuglevel, - "python-dir: Failed to load module with name %s\n", + LOGPREFIX "Failed to load module with name %s\n", plugin_priv_ctx->module_name); goto bail_out; } Dmsg(plugin_ctx, debuglevel, - "python-dir: Successfully loaded module with name %s\n", + LOGPREFIX "Successfully loaded module with name %s\n", plugin_priv_ctx->module_name); /* @@ -571,7 +578,6 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) plugin_priv_ctx->pyModuleFunctionsDict = PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ - // StorePluginContextInPythonModule(plugin_ctx); /* * Lookup the load_bareos_plugin() function in the python module. @@ -595,7 +601,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) } } else { Dmsg(plugin_ctx, debuglevel, - "python-dir: Failed to find function named load_bareos_plugins()\n"); + LOGPREFIX "Failed to find function named load_bareos_plugins()\n"); goto bail_out; } diff --git a/core/src/plugins/filed/python/module/bareosfd.cc b/core/src/plugins/filed/python/module/bareosfd.cc index 73ddfd03e47..c94af838249 100644 --- a/core/src/plugins/filed/python/module/bareosfd.cc +++ b/core/src/plugins/filed/python/module/bareosfd.cc @@ -33,6 +33,13 @@ #include "include/bareos.h" #endif +#if PY_VERSION_HEX < 0x03000000 +#define LOGPREFIX "python-fd-mod: " +#else +#define LOGPREFIX "python3-fd-mod: " +#endif + + #include "filed/fd_plugins.h" #include "plugins/include/python3compat.h" @@ -140,7 +147,8 @@ static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value) return retval; } else { Dmsg(plugin_ctx, debuglevel, - "python-fd: Failed to find function named " + LOGPREFIX + "Failed to find function named " "parse_plugin_definition()\n"); return bRC_Error; } @@ -195,7 +203,7 @@ static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, } } else { Dmsg(plugin_ctx, debuglevel, - "python-fd: Failed to find function named handle_plugin_event()\n"); + LOGPREFIX "Failed to find function named handle_plugin_event()\n"); } return retval; @@ -461,7 +469,7 @@ static bRC PyStartBackupFile(PluginContext* plugin_ctx, struct save_pkt* sp) } } else { Dmsg(plugin_ctx, debuglevel, - "python-fd: Failed to find function named start_backup_file()\n"); + LOGPREFIX "Failed to find function named start_backup_file()\n"); } return retval; @@ -501,7 +509,7 @@ static bRC PyEndBackupFile(PluginContext* plugin_ctx) } } else { Dmsg(plugin_ctx, debuglevel, - "python-fd: Failed to find function named end_backup_file()\n"); + LOGPREFIX "Failed to find function named end_backup_file()\n"); } return retval; @@ -622,7 +630,7 @@ static bRC PyPluginIO(PluginContext* plugin_ctx, struct io_pkt* io) Py_DECREF((PyObject*)pIoPkt); } else { Dmsg(plugin_ctx, debuglevel, - "python-fd: Failed to find function named plugin_io()\n"); + LOGPREFIX "Failed to find function named plugin_io()\n"); } return retval; @@ -668,7 +676,7 @@ static bRC PyStartRestoreFile(PluginContext* plugin_ctx, const char* cmd) } } else { Dmsg(plugin_ctx, debuglevel, - "python-fd: Failed to find function named start_restore_file()\n"); + LOGPREFIX "Failed to find function named start_restore_file()\n"); } return retval; @@ -705,7 +713,7 @@ static bRC PyEndRestoreFile(PluginContext* plugin_ctx) } } else { Dmsg(plugin_ctx, debuglevel, - "python-fd: Failed to find function named end_restore_file()\n"); + LOGPREFIX "Failed to find function named end_restore_file()\n"); } return retval; @@ -797,7 +805,7 @@ static bRC PyCreateFile(PluginContext* plugin_ctx, struct restore_pkt* rp) } } else { Dmsg(plugin_ctx, debuglevel, - "python-fd: Failed to find function named create_file()\n"); + LOGPREFIX "Failed to find function named create_file()\n"); } return retval; @@ -841,7 +849,7 @@ static bRC PySetFileAttributes(PluginContext* plugin_ctx, } } else { Dmsg(plugin_ctx, debuglevel, - "python-fd: Failed to find function named set_file_attributes()\n"); + LOGPREFIX "Failed to find function named set_file_attributes()\n"); } return retval; @@ -881,7 +889,7 @@ static bRC PyCheckFile(PluginContext* plugin_ctx, char* fname) } } else { Dmsg(plugin_ctx, debuglevel, - "python-fd: Failed to find function named check_file()\n"); + LOGPREFIX "Failed to find function named check_file()\n"); } return retval; @@ -969,7 +977,7 @@ static bRC PyGetAcl(PluginContext* plugin_ctx, acl_pkt* ap) } } else { Dmsg(plugin_ctx, debuglevel, - "python-fd: Failed to find function named get_acl()\n"); + LOGPREFIX "Failed to find function named get_acl()\n"); } return retval; @@ -1012,7 +1020,7 @@ static bRC PySetAcl(PluginContext* plugin_ctx, acl_pkt* ap) } } else { Dmsg(plugin_ctx, debuglevel, - "python-fd: Failed to find function named set_acl()\n"); + LOGPREFIX "Failed to find function named set_acl()\n"); } return retval; @@ -1123,7 +1131,7 @@ static bRC PyGetXattr(PluginContext* plugin_ctx, xattr_pkt* xp) } } else { Dmsg(plugin_ctx, debuglevel, - "python-fd: Failed to find function named get_xattr()\n"); + LOGPREFIX "Failed to find function named get_xattr()\n"); } return retval; @@ -1166,7 +1174,7 @@ static bRC PySetXattr(PluginContext* plugin_ctx, xattr_pkt* xp) } } else { Dmsg(plugin_ctx, debuglevel, - "python-fd: Failed to find function named set_xattr()\n"); + LOGPREFIX "Failed to find function named set_xattr()\n"); } return retval; @@ -1232,7 +1240,7 @@ static bRC PyRestoreObjectData(PluginContext* plugin_ctx, } } else { Dmsg(plugin_ctx, debuglevel, - "python-fd: Failed to find function named start_restore_file()\n"); + LOGPREFIX "Failed to find function named start_restore_file()\n"); } return retval; @@ -1280,7 +1288,7 @@ static bRC PyHandleBackupFile(PluginContext* plugin_ctx, struct save_pkt* sp) } } else { Dmsg(plugin_ctx, debuglevel, - "python-fd: Failed to find function named handle_backup_file()\n"); + LOGPREFIX "Failed to find function named handle_backup_file()\n"); } return retval; @@ -1351,7 +1359,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) break; /* a write only variable, ignore read request */ default: Dmsg(plugin_ctx, debuglevel, - "python-fd: PyBareosGetValue unknown variable requested %d\n", var); + LOGPREFIX "PyBareosGetValue unknown variable requested %d\n", var); break; } @@ -1399,7 +1407,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) } default: Dmsg(plugin_ctx, debuglevel, - "python-fd: PyBareosSetValue unknown variable requested %d\n", var); + LOGPREFIX "PyBareosSetValue unknown variable requested %d\n", var); break; } @@ -1426,7 +1434,7 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) } RETURN_RUNTIME_ERROR_IF_BAREOS_PLUGIN_CTX_UNSET() - if (dbgmsg) { Dmsg(plugin_ctx, level, "python-fd: %s", dbgmsg); } + if (dbgmsg) { Dmsg(plugin_ctx, level, LOGPREFIX "%s", dbgmsg); } Py_RETURN_NONE; } @@ -1447,7 +1455,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (jobmsg) { Jmsg(plugin_ctx, level, "python-fd: %s", jobmsg); } + if (jobmsg) { Jmsg(plugin_ctx, level, LOGPREFIX "%s", jobmsg); } Py_RETURN_NONE; } @@ -1479,7 +1487,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) if (event >= bEventJobStart && event <= FD_NR_EVENTS) { Dmsg(plugin_ctx, debuglevel, - "python-fd: PyBareosRegisterEvents registering event %d\n", event); + LOGPREFIX "PyBareosRegisterEvents registering event %d\n", event); retval = bareos_core_functions->registerBareosEvents(plugin_ctx, 1, event); diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 6191d372741..77f851b5853 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -34,6 +34,13 @@ #include "include/bareos.h" #endif +#if PY_VERSION_HEX < 0x03000000 +#define LOGPREFIX "python-fd: " +#else +#define LOGPREFIX "python3-fd: " +#endif + + #include "filed/fd_plugins.h" #include "plugins/include/python3compat.h" @@ -770,7 +777,7 @@ static bRC parse_plugin_definition(PluginContext* plugin_ctx, */ if (bstrcmp((char*)value, "*all*")) { Dmsg(plugin_ctx, debuglevel, - "python-fd: Got plugin definition %s, skipping to ignore\n", + LOGPREFIX "Got plugin definition %s, skipping to ignore\n", (char*)value); return bRC_Skip; } @@ -796,9 +803,9 @@ static bRC parse_plugin_definition(PluginContext* plugin_ctx, bp = strchr((char*)value, ':'); if (!bp) { - Jmsg(plugin_ctx, M_FATAL, "python-fd: Illegal plugin definition %s\n", + Jmsg(plugin_ctx, M_FATAL, LOGPREFIX "Illegal plugin definition %s\n", (char*)value); - Dmsg(plugin_ctx, debuglevel, "python-fd: Illegal plugin definition %s\n", + Dmsg(plugin_ctx, debuglevel, LOGPREFIX "Illegal plugin definition %s\n", (char*)value); goto bail_out; } @@ -817,9 +824,9 @@ static bRC parse_plugin_definition(PluginContext* plugin_ctx, bp = strchr(plugin_definition.c_str(), ':'); if (!bp) { - Jmsg(plugin_ctx, M_FATAL, "python-fd: Illegal plugin definition %s\n", + Jmsg(plugin_ctx, M_FATAL, LOGPREFIX "Illegal plugin definition %s\n", plugin_definition.c_str()); - Dmsg(plugin_ctx, debuglevel, "python-fd: Illegal plugin definition %s\n", + Dmsg(plugin_ctx, debuglevel, LOGPREFIX "Illegal plugin definition %s\n", plugin_definition.c_str()); goto bail_out; } @@ -843,10 +850,10 @@ static bRC parse_plugin_definition(PluginContext* plugin_ctx, argument = bp; argument_value = strchr(bp, '='); if (!argument_value) { - Jmsg(plugin_ctx, M_FATAL, - "python-fd: Illegal argument %s without value\n", argument); + Jmsg(plugin_ctx, M_FATAL, LOGPREFIX "Illegal argument %s without value\n", + argument); Dmsg(plugin_ctx, debuglevel, - "python-fd: Illegal argument %s without value\n", argument); + LOGPREFIX "Illegal argument %s without value\n", argument); goto bail_out; } *argument_value++ = '\0'; @@ -965,7 +972,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) /* Try to load the Python module by name. */ if (plugin_priv_ctx->module_name) { Dmsg(plugin_ctx, debuglevel, - "python-fd: Trying to load module with name %s\n", + LOGPREFIX "Trying to load module with name %s\n", plugin_priv_ctx->module_name); pName = PyUnicode_FromString(plugin_priv_ctx->module_name); plugin_priv_ctx->pModule = PyImport_Import(pName); @@ -973,13 +980,13 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) if (!plugin_priv_ctx->pModule) { Dmsg(plugin_ctx, debuglevel, - "python-fd: Failed to load module with name %s\n", + LOGPREFIX "Failed to load module with name %s\n", plugin_priv_ctx->module_name); goto bail_out; } Dmsg(plugin_ctx, debuglevel, - "python-fd: Successfully loaded module with name %s\n", + LOGPREFIX "Successfully loaded module with name %s\n", plugin_priv_ctx->module_name); /* Get the Python dictionary for lookups in the Python namespace. */ @@ -997,8 +1004,6 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) if (!pPluginDefinition) { goto bail_out; } pRetVal = PyObject_CallFunctionObjArgs(pFunc, pPluginDefinition, NULL); - /* pFunc, plugin_priv_ctx->py_PluginContext, pPluginDefinition, - * NULL); */ Py_DECREF(pPluginDefinition); if (!pRetVal) { @@ -1009,7 +1014,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) } } else { Dmsg(plugin_ctx, debuglevel, - "python-fd: Failed to find function named load_bareos_plugins()\n"); + LOGPREFIX "Failed to find function named load_bareos_plugins()\n"); goto bail_out; } diff --git a/core/src/plugins/filed/python/python-fd.h b/core/src/plugins/filed/python/python-fd.h index f5bbf3d0697..8998f9e0bee 100644 --- a/core/src/plugins/filed/python/python-fd.h +++ b/core/src/plugins/filed/python/python-fd.h @@ -33,7 +33,6 @@ /* common code for all python plugins */ #include "plugins/include/python_plugins_common.h" #include "plugins/include/common.h" - #include "structmember.h" namespace filedaemon { diff --git a/core/src/plugins/stored/python/module/bareossd.cc b/core/src/plugins/stored/python/module/bareossd.cc index 0745edb6668..33c9e3b1b47 100644 --- a/core/src/plugins/stored/python/module/bareossd.cc +++ b/core/src/plugins/stored/python/module/bareossd.cc @@ -33,6 +33,15 @@ #include "include/bareos.h" #endif +#if PY_VERSION_HEX < 0x03000000 +#define LOGPREFIX "python-sd-mod: " +#else +#define LOGPREFIX "python3-sd-mod: " +#endif + + +#include "filed/fd_plugins.h" + #include "stored/sd_plugins.h" #define BAREOSSD_MODULE @@ -119,9 +128,8 @@ static bRC PyParsePluginDefinition(PluginContext* plugin_ctx, void* value) return retval; } else { - Dmsg( - plugin_ctx, debuglevel, - "python-sd: Failed to find function named parse_plugin_definition()\n"); + Dmsg(plugin_ctx, debuglevel, + LOGPREFIX "Failed to find function named parse_plugin_definition()\n"); return bRC_Error; } @@ -175,7 +183,7 @@ static bRC PyHandlePluginEvent(PluginContext* plugin_ctx, } } else { Dmsg(plugin_ctx, debuglevel, - "python-sd: Failed to find function named handle_plugin_event()\n"); + LOGPREFIX "Failed to find function named handle_plugin_event()\n"); } return retval; @@ -262,7 +270,7 @@ static PyObject* PyBareosGetValue(PyObject* self, PyObject* args) } default: Dmsg(plugin_ctx, debuglevel, - "python-sd: PyBareosGetValue unknown variable requested %d\n", var); + LOGPREFIX "PyBareosGetValue unknown variable requested %d\n", var); break; } @@ -311,7 +319,7 @@ static PyObject* PyBareosSetValue(PyObject* self, PyObject* args) } default: Dmsg(plugin_ctx, debuglevel, - "python-sd: PyBareosSetValue unknown variable requested %d\n", var); + LOGPREFIX "PyBareosSetValue unknown variable requested %d\n", var); break; } @@ -335,7 +343,7 @@ static PyObject* PyBareosDebugMessage(PyObject* self, PyObject* args) } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (dbgmsg) { Dmsg(plugin_ctx, level, "python-sd: %s", dbgmsg); } + if (dbgmsg) { Dmsg(plugin_ctx, level, LOGPREFIX "%s", dbgmsg); } Py_RETURN_NONE; } @@ -356,7 +364,7 @@ static PyObject* PyBareosJobMessage(PyObject* self, PyObject* args) } RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() - if (jobmsg) { Jmsg(plugin_ctx, type, "python-sd: %s", jobmsg); } + if (jobmsg) { Jmsg(plugin_ctx, type, LOGPREFIX "%s", jobmsg); } Py_RETURN_NONE; } @@ -389,7 +397,7 @@ static PyObject* PyBareosRegisterEvents(PyObject* self, PyObject* args) if (event >= bSdEventJobStart && event <= bSdEventWriteRecordTranslation) { Dmsg(plugin_ctx, debuglevel, - "python-sd: PyBareosRegisterEvents registering event %d\n", event); + LOGPREFIX "PyBareosRegisterEvents registering event %d\n", event); retval = bareos_core_functions->registerBareosEvents(plugin_ctx, 1, event); diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index 6fa20ab02b7..5468357f7bf 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -33,6 +33,14 @@ #include #include "include/bareos.h" #endif + +#if PY_VERSION_HEX < 0x03000000 +#define LOGPREFIX "python-sd: " +#else +#define LOGPREFIX "python3-sd: " +#endif + + #include "stored/stored.h" #include "plugins/include/python3compat.h" @@ -405,9 +413,9 @@ static bRC parse_plugin_definition(PluginContext* plugin_ctx, bp = strchr(plugin_definition.c_str(), ':'); if (!bp) { - Jmsg(plugin_ctx, M_FATAL, "python-sd: Illegal plugin definition %s\n", + Jmsg(plugin_ctx, M_FATAL, LOGPREFIX "Illegal plugin definition %s\n", plugin_definition.c_str()); - Dmsg(plugin_ctx, debuglevel, "python-sd: Illegal plugin definition %s\n", + Dmsg(plugin_ctx, debuglevel, LOGPREFIX "Illegal plugin definition %s\n", plugin_definition.c_str()); goto bail_out; } @@ -431,10 +439,10 @@ static bRC parse_plugin_definition(PluginContext* plugin_ctx, argument = bp; argument_value = strchr(bp, '='); if (!argument_value) { - Jmsg(plugin_ctx, M_FATAL, - "python-sd: Illegal argument %s without value\n", argument); + Jmsg(plugin_ctx, M_FATAL, LOGPREFIX "Illegal argument %s without value\n", + argument); Dmsg(plugin_ctx, debuglevel, - "python-sd: Illegal argument %s without value\n", argument); + LOGPREFIX "Illegal argument %s without value\n", argument); goto bail_out; } *argument_value++ = '\0'; @@ -547,7 +555,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) /* Try to load the Python module by name. */ if (plugin_priv_ctx->module_name) { Dmsg(plugin_ctx, debuglevel, - "python-sd: Trying to load module with name %s\n", + LOGPREFIX "Trying to load module with name %s\n", plugin_priv_ctx->module_name); pName = PyUnicode_FromString(plugin_priv_ctx->module_name); plugin_priv_ctx->pModule = PyImport_Import(pName); @@ -555,26 +563,21 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) if (!plugin_priv_ctx->pModule) { Dmsg(plugin_ctx, debuglevel, - "python-sd: Failed to load module with name %s\n", + LOGPREFIX "Failed to load module with name %s\n", plugin_priv_ctx->module_name); goto bail_out; } Dmsg(plugin_ctx, debuglevel, - "python-sd: Successfully loaded module with name %s\n", + LOGPREFIX "Successfully loaded module with name %s\n", plugin_priv_ctx->module_name); - /* - * Get the Python dictionary for lookups in the Python namespace. - */ + /* Get the Python dictionary for lookups in the Python namespace. */ plugin_priv_ctx->pyModuleFunctionsDict = PyModule_GetDict(plugin_priv_ctx->pModule); /* Borrowed reference */ - // StorePluginContextInPythonModule(plugin_ctx); - /* - * Lookup the load_bareos_plugin() function in the python module. - */ + /* Lookup the load_bareos_plugin() function in the python module. */ pFunc = PyDict_GetItemString(plugin_priv_ctx->pyModuleFunctionsDict, "load_bareos_plugin"); /* Borrowed reference */ if (pFunc && PyCallable_Check(pFunc)) { @@ -594,7 +597,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) } } else { Dmsg(plugin_ctx, debuglevel, - "python-sd: Failed to find function named load_bareos_plugins()\n"); + LOGPREFIX "Failed to find function named load_bareos_plugins()\n"); goto bail_out; } From 622b6940465921115c75838f163f1025386ad5af Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 22 May 2020 11:12:18 +0200 Subject: [PATCH 141/341] python system tests: added postgres test --- systemtests/CMakeLists.txt | 1 + .../etc/bareos/bareos-fd.d/client/myself.conf.in | 2 +- .../etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index a14454bd76f..9025f80e03a 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -839,6 +839,7 @@ foreach(TEST_NAME ${SYSTEM_TESTS}) "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/pyfiles:" "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/percona-xtrabackup:" "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/ovirt:" + "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/postgres:" "${CMAKE_SOURCE_DIR}/core/src/plugins/stored/python/pyfiles:" "${CMAKE_SOURCE_DIR}/core/src/plugins/dird/python/pyfiles:" "${CMAKE_BINARY_DIR}/core/src/plugins/filed/python/${python_version}modules:" diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/client/myself.conf.in index 49039c29d18..d3978eea8a8 100644 --- a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/client/myself.conf.in +++ b/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/client/myself.conf.in @@ -7,7 +7,7 @@ Client { # otherwise all filedaemon plugins (*-fd.so) from the "Plugin Directory". # Plugin Directory = "@fd_plugin_binary_path@" - Plugin Names = "python" + Plugin Names = "@python_version@" # if compatible is set to yes, we are compatible with bacula # if set to no, new bareos features are enabled which is the default diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in index 5b135c52cc0..e4be9984ebb 100644 --- a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in +++ b/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in @@ -5,6 +5,6 @@ FileSet { Options { signature = MD5 } - Plugin = "python:module_path=@current_test_directory@/python-modules:module_name=bareos-fd-postgres:dbHost=/tmp/@TEST_NAME@:postgresDataDir=@current_test_directory@/database/data:walArchive=@current_test_directory@/database/wal_archive/" + Plugin = "@python_version@:module_path=@current_test_directory@/python-modules:module_name=bareos-fd-postgres:dbHost=@current_test_directory@/database/tmp:postgresDataDir=@current_test_directory@/database/data:walArchive=@current_test_directory@/database/wal_archive/" } } From 8202949dbb6400df2df7de0d5d1c9bdf346e151e Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 22 May 2020 18:05:34 +0200 Subject: [PATCH 142/341] python: introduced python3compat.h --- core/src/plugins/dird/python/CMakeLists.txt | 112 ++++++++++++ core/src/plugins/filed/python/CMakeLists.txt | 175 +++++++++++++++++++ core/src/plugins/include/python3compat.h | 43 +++++ 3 files changed, 330 insertions(+) create mode 100644 core/src/plugins/dird/python/CMakeLists.txt create mode 100644 core/src/plugins/filed/python/CMakeLists.txt create mode 100644 core/src/plugins/include/python3compat.h diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt new file mode 100644 index 00000000000..0e2b36f1154 --- /dev/null +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -0,0 +1,112 @@ +# BAREOS® - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2020-2020 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation and included +# in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + +if(Python2_FOUND) + add_library(python-dir MODULE python-dir.cc) + # do not prefix with "lib" + set_target_properties(python-dir PROPERTIES PREFIX "") + install(TARGETS python-dir DESTINATION ${plugindir}) + target_link_libraries(python-dir ${Python2_LIBRARIES} bareos) + target_include_directories(python-dir PUBLIC SYSTEM ${Python2_INCLUDE_DIRS}) + add_dependencies(python-dir bareosdir-python2-module) + + set(PYFILES pyfiles/bareos-dir.py.template pyfiles/bareos-dir-class-plugin.py + pyfiles/BareosDirPluginBaseclass.py pyfiles/BareosDirWrapper.py + ) + + install(FILES ${PYFILES} DESTINATION ${plugindir}) +endif() + +if(Python2_FOUND AND NOT HAVE_WIN32) + configure_file(module/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py) + add_custom_command( + OUTPUT pythonmodules/bareosdir.so + MAIN_DEPENDENCY module/bareosdir.cc + DEPENDS module/bareosdir.h + DEPENDS bareos + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py + COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build + COMMAND ${Python2_EXECUTABLE} module/setup.py build + COMMAND ${Python2_EXECUTABLE} module/setup.py install --install-lib + ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build + COMMENT "building python2 module pythonmodules/bareosdir.so" + ) + add_custom_target(bareosdir-python2-module DEPENDS pythonmodules/bareosdir.so) + + add_test(NAME bareosdir-python2-module + COMMAND ${Python2_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/test/bareosdir_test.py + ) + set_property( + TEST bareosdir-python2-module + PROPERTY + ENVIRONMENT + "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/test" + LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib + ) +endif() + +if(Python3_FOUND) + add_library(python3-dir MODULE python-dir.cc) + # do not prefix with "lib" + set_target_properties(python3-dir PROPERTIES PREFIX "") + install(TARGETS python3-dir DESTINATION ${plugindir}) + target_link_libraries(python3-dir ${Python3_LIBRARIES} bareos) + target_include_directories(python3-dir PUBLIC SYSTEM ${Python3_INCLUDE_DIRS}) + add_dependencies(python3-dir bareosdir-python3-module) + + set(PYFILES pyfiles/bareos-dir.py.template pyfiles/bareos-dir-class-plugin.py + pyfiles/BareosDirPluginBaseclass.py pyfiles/BareosDirWrapper.py + ) + + install(FILES ${PYFILES} DESTINATION ${plugindir}) +endif() + +if(Python3_FOUND AND NOT HAVE_WIN32) + configure_file(module/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py) + add_custom_command( + OUTPUT python3modules/bareosdir.so + MAIN_DEPENDENCY module/bareosdir.cc + DEPENDS module/bareosdir.h + DEPENDS bareos + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py + COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build + COMMAND ${Python3_EXECUTABLE} module/setup.py build + COMMAND ${Python3_EXECUTABLE} module/setup.py install --install-lib + ${CMAKE_CURRENT_BINARY_DIR}/python3modules + COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build + COMMENT "building python3 module python3modules/bareosdir.so" + ) + add_custom_target( + bareosdir-python3-module DEPENDS python3modules/bareosdir.so + ) + + add_test(NAME bareosdir-python3-module + COMMAND ${Python3_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/test/bareosdir_test.py + ) + set_property( + TEST bareosdir-python3-module + PROPERTY + ENVIRONMENT + "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/python3modules:${CMAKE_CURRENT_SOURCE_DIR}/test" + LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib + ) +endif() diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt new file mode 100644 index 00000000000..8ded7286efd --- /dev/null +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -0,0 +1,175 @@ +# BAREOS® - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2020-2020 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation and included +# in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + +if(Python2_FOUND) + add_library(python-fd MODULE python-fd.cc) + set_target_properties( + python-fd PROPERTIES PREFIX "" LIBRARY_OUTPUT_DIRECTORY .. + ) + install( + TARGETS python-fd + DESTINATION ${plugindir} + COMPONENT filedaemon + ) + target_link_libraries(python-fd ${Python2_LIBRARIES} bareos) + target_include_directories(python-fd PUBLIC SYSTEM ${Python2_INCLUDE_DIRS}) + add_dependencies(python-fd bareosfd-pymod2) + add_dependencies(bareos-fd python-fd) +endif() + +if(Python3_FOUND) + add_library(python3-fd MODULE python-fd.cc) + set_target_properties( + python3-fd PROPERTIES PREFIX "" LIBRARY_OUTPUT_DIRECTORY .. + ) + install( + TARGETS python3-fd + DESTINATION ${plugindir} + COMPONENT filedaemon + ) + target_link_libraries(python3-fd ${Python3_LIBRARIES} bareos) + target_include_directories(python3-fd PUBLIC SYSTEM ${Python3_INCLUDE_DIRS}) + add_dependencies(python3-fd bareosfd-pymod3) + add_dependencies(bareos-fd python3-fd) +endif() + +if(Python2_FOUND AND NOT HAVE_WIN22) + add_executable(bareosfd-python2-module-tester test/python-fd-module-tester.cc) + target_link_libraries( + bareosfd-python2-module-tester ${Python2_LIBRARIES} bareos + ) + target_include_directories( + bareosfd-python2-module-tester PUBLIC SYSTEM ${Python2_INCLUDE_DIRS} + ) + + add_test(NAME bareosfd-python2-module-tester + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bareosfd-python2-module-tester + ) + set_property( + TEST bareosfd-python2-module-tester + PROPERTY + ENVIRONMENT + PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/test/:${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/pyfiles + ) +endif() + +if(Python3_FOUND AND NOT HAVE_WIN32) + add_executable(bareosfd-python3-module-tester test/python-fd-module-tester.cc) + target_link_libraries( + bareosfd-python3-module-tester ${Python3_LIBRARIES} bareos + ) + target_include_directories( + bareosfd-python3-module-tester PUBLIC SYSTEM ${Python3_INCLUDE_DIRS} + ) + + add_test(NAME bareosfd-python3-module-tester + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bareosfd-python3-module-tester + ) + set_property( + TEST bareosfd-python3-module-tester + PROPERTY + ENVIRONMENT + PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/test/:${CMAKE_CURRENT_BINARY_DIR}/python3modules:${CMAKE_CURRENT_SOURCE_DIR}/pyfiles + ) +endif() + +if(Python2_FOUND AND NOT HAVE_WIN22) + configure_file( + module/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py2.py + ) + add_custom_command( + OUTPUT pythonmodules/bareosfd.so + MAIN_DEPENDENCY module/bareosfd.cc + DEPENDS module/bareosfd.h + DEPENDS bareos + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py2.py + COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build + COMMAND ${Python2_EXECUTABLE} module/setup_py2.py build + COMMAND ${Python2_EXECUTABLE} module/setup_py2.py install --install-lib + ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build + COMMENT "building python2 module pythonmodules/bareosfd.so" + ) + add_custom_target(bareosfd-pymod2 DEPENDS pythonmodules/bareosfd.so) + add_test(NAME bareosfd-python2-module + COMMAND ${Python2_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/test/bareosfd_test.py + ) + set_property( + TEST bareosfd-python2-module + PROPERTY + ENVIRONMENT + "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/test" + LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib + ) +endif() + +if(Python3_FOUND AND NOT HAVE_WIN32) + configure_file( + module/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py3.py + ) + add_custom_command( + OUTPUT python3modules/bareosfd.so + MAIN_DEPENDENCY module/bareosfd.cc + DEPENDS module/bareosfd.h + DEPENDS bareos + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py3.py + COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build + COMMAND ${Python3_EXECUTABLE} module/setup_py3.py build + COMMAND ${Python3_EXECUTABLE} module/setup_py3.py install --install-lib + ${CMAKE_CURRENT_BINARY_DIR}/python3modules + COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build + COMMENT "building python3 module python3modules/bareosfd.so" + ) + add_custom_target(bareosfd-pymod3 DEPENDS python3modules/bareosfd.so) + add_test(NAME bareosfd-python3-module + COMMAND ${Python3_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/test/bareosfd_test.py + ) + set_property( + TEST bareosfd-python3-module + PROPERTY + ENVIRONMENT + "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/python3modules:${CMAKE_CURRENT_SOURCE_DIR}/test" + LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib + ) +endif() + +set(PYFILES + pyfiles/bareos-fd.py.template + pyfiles/bareos-fd-local-fileset.py + pyfiles/bareos-fd-mock-test.py + pyfiles/BareosFdPluginBaseclass.py + pyfiles/BareosFdPluginLocalFileset.py + pyfiles/BareosFdWrapper.py + ldap/bareos-fd-ldap.py + ldap/BareosFdPluginLDAP.py + ovirt/bareos-fd-ovirt.py + ovirt/BareosFdPluginOvirt.py + percona-xtrabackup/bareos-fd-percona-xtrabackup.py + percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py + postgres/bareos-fd-postgres.py + postgres/BareosFdPluginPostgres.py +) + +install( + FILES ${PYFILES} + DESTINATION ${plugindir} + COMPONENT filedaemon +) diff --git a/core/src/plugins/include/python3compat.h b/core/src/plugins/include/python3compat.h new file mode 100644 index 00000000000..12a0d043c7c --- /dev/null +++ b/core/src/plugins/include/python3compat.h @@ -0,0 +1,43 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2020-2020 Bareos GmbH & Co. KG + + This program is Free Software; you can modify it under the terms of + version three of the GNU Affero General Public License as published by the + Free Software Foundation, which is listed in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#ifndef BAREOS_PYTHON3COMPAT_H_ +#define BAREOS_PYTHON3COMPAT_H_ + +/* redefine python3 calls to python2 pendants */ + +#if PY_VERSION_HEX < 0x03000000 +#define PyLong_FromLong PyInt_FromLong +#define PyLong_AsLong PyInt_AsLong + +#define PyBytes_FromString PyString_FromString + +#undef PyUnicode_FromString +#define PyUnicode_FromString PyString_FromString + +#define PyUnicode_AsUTF8 PyString_AsString + +#undef PyUnicode_Check +#define PyUnicode_Check PyString_Check + +#endif + + +#endif // BAREOS_PYTHON3COMPAT_H_ From b5c83a0a2190bb92ffdccd19fb607ee78fa6795f Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 22 May 2020 18:16:27 +0200 Subject: [PATCH 143/341] python_plugins_common.h: adaptions --- .../plugins/include/python_plugins_common.h | 142 +++++++++++++++++ .../plugins/include/python_plugins_common.inc | 148 ++++++++++++++++++ 2 files changed, 290 insertions(+) create mode 100644 core/src/plugins/include/python_plugins_common.h create mode 100644 core/src/plugins/include/python_plugins_common.inc diff --git a/core/src/plugins/include/python_plugins_common.h b/core/src/plugins/include/python_plugins_common.h new file mode 100644 index 00000000000..bf87bf136b1 --- /dev/null +++ b/core/src/plugins/include/python_plugins_common.h @@ -0,0 +1,142 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2020-2020 Bareos GmbH & Co. KG + + This program is Free Software; you can modify it under the terms of + version three of the GNU Affero General Public License as published by the + Free Software Foundation, which is listed in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#ifndef BAREOS_PYTHON_PLUGINS_COMMON_H_ +#define BAREOS_PYTHON_PLUGINS_COMMON_H_ + +/* Common definitions used in all python plugins. */ + +/* macros for uniform python module definition + see http://python3porting.com/cextensions.html */ +#if PY_MAJOR_VERSION >= 3 +#define MOD_ERROR_VAL NULL +#define MOD_SUCCESS_VAL(val) val +#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void) +#define MOD_DEF(ob, name, doc, methods) \ + static struct PyModuleDef moduledef = { \ + PyModuleDef_HEAD_INIT, name, doc, -1, methods, \ + }; \ + \ + ob = PyModule_Create(&moduledef); +#else +#define MOD_ERROR_VAL +#define MOD_SUCCESS_VAL(val) +#define MOD_INIT(name) PyMODINIT_FUNC init##name(void) +#define MOD_DEF(ob, name, doc, methods) ob = Py_InitModule3(name, methods, doc); +#endif + +#define STRINGIFY(x) #x +#define TOSTRING(x) STRINGIFY(x) +#define AT __FILE__ ":" TOSTRING(__LINE__) + +/* check if plugin_ctx and bfunc are set. + * Otherwise return NULL and throw RuntimeError */ + +#define RETURN_RUNTIME_ERROR_IF_BAREOS_PLUGIN_CTX_UNSET() \ + if (!plugin_ctx) { \ + PyErr_SetString(PyExc_RuntimeError, AT " :plugin_ctx is unset"); \ + return NULL; \ + } + +#define RETURN_RUNTIME_ERROR_IF_BFUNC_UNSET() \ + if (!bareos_core_functions) { \ + PyErr_SetString(PyExc_RuntimeError, \ + AT ": bareos_core_functions is unset"); \ + return NULL; \ + } + +#define RETURN_RUNTIME_ERROR_IF_BFUNC_OR_BAREOS_PLUGIN_CTX_UNSET() \ + RETURN_RUNTIME_ERROR_IF_BAREOS_PLUGIN_CTX_UNSET() \ + RETURN_RUNTIME_ERROR_IF_BFUNC_UNSET() + +/* define the given string constant as member of an dict and additionally + add it directly as constant to the module. + + This is both done for string to long and for string to string mappings. + + The result is that the module both contains a dict: + bIOPS = {'IO_CLOSE': 4L, 'IO_OPEN': 1L, 'IO_READ': 2L, 'IO_SEEK': 5L, + 'IO_WRITE': 3L} + and the single values directly: + IO_CLOSE = 4 + IO_OPEN = 1 + IO_READ = 2 + IO_SEEK = 5 + IO_WRITE = 3 + */ + +#define ConstSet_StrLong(dict, string, value) \ + if (PyDict_SetItem(dict, PyBytes_FromString(#string), \ + PyLong_FromLong(value))) { \ + return MOD_ERROR_VAL; \ + } \ + if (PyModule_AddIntConstant(m, #string, value)) { return MOD_ERROR_VAL; } + +#define ConstSet_StrStr(dict, string, value) \ + if (PyDict_SetItem(dict, PyBytes_FromString(#string), \ + PyBytes_FromString(value))) { \ + return MOD_ERROR_VAL; \ + } \ + if (PyModule_AddStringConstant(m, #string, value)) { return MOD_ERROR_VAL; } + + +/* commonly used definitions in multiple python modules */ +#define DEFINE_bRCs_DICT() \ + const char* bRCs = "bRCs"; \ + PyObject* pDictbRCs = NULL; \ + pDictbRCs = PyDict_New(); \ + ConstSet_StrLong(pDictbRCs, bRC_OK, 0); \ + ConstSet_StrLong(pDictbRCs, bRC_Stop, 1); \ + ConstSet_StrLong(pDictbRCs, bRC_Error, 2); \ + ConstSet_StrLong(pDictbRCs, bRC_More, 3); \ + ConstSet_StrLong(pDictbRCs, bRC_Term, 4); \ + ConstSet_StrLong(pDictbRCs, bRC_Seen, 5); \ + ConstSet_StrLong(pDictbRCs, bRC_Core, 6); \ + ConstSet_StrLong(pDictbRCs, bRC_Skip, 7); \ + ConstSet_StrLong(pDictbRCs, bRC_Cancel, 8); \ + if (!pDictbRCs) { return MOD_ERROR_VAL; } \ + if (PyModule_AddObject(m, bRCs, pDictbRCs)) { return MOD_ERROR_VAL; } + +#define DEFINE_bJobMessageTypes_DICT() \ + const char* bJobMessageType = "bJobMessageType"; \ + PyObject* pDictJobMessageType = NULL; \ + pDictJobMessageType = PyDict_New(); \ + if (!pDictJobMessageType) { return MOD_ERROR_VAL; } \ + ConstSet_StrLong(pDictJobMessageType, M_ABORT, 1); \ + ConstSet_StrLong(pDictJobMessageType, M_DEBUG, 2); \ + ConstSet_StrLong(pDictJobMessageType, M_FATAL, 3); \ + ConstSet_StrLong(pDictJobMessageType, M_ERROR, 4); \ + ConstSet_StrLong(pDictJobMessageType, M_WARNING, 5); \ + ConstSet_StrLong(pDictJobMessageType, M_INFO, 6); \ + ConstSet_StrLong(pDictJobMessageType, M_SAVED, 7); \ + ConstSet_StrLong(pDictJobMessageType, M_NOTSAVED, 8); \ + ConstSet_StrLong(pDictJobMessageType, M_SKIPPED, 9); \ + ConstSet_StrLong(pDictJobMessageType, M_MOUNT, 10); \ + ConstSet_StrLong(pDictJobMessageType, M_ERROR_TERM, 11); \ + ConstSet_StrLong(pDictJobMessageType, M_TERM, 12); \ + ConstSet_StrLong(pDictJobMessageType, M_RESTORED, 13); \ + ConstSet_StrLong(pDictJobMessageType, M_SECURITY, 14); \ + ConstSet_StrLong(pDictJobMessageType, M_ALERT, 15); \ + ConstSet_StrLong(pDictJobMessageType, M_VOLMGMT, 16); \ + if (PyModule_AddObject(m, bJobMessageType, pDictJobMessageType)) { \ + return MOD_ERROR_VAL; \ + } + +#endif // BAREOS_PYTHON_PLUGINS_COMMON_H_ diff --git a/core/src/plugins/include/python_plugins_common.inc b/core/src/plugins/include/python_plugins_common.inc new file mode 100644 index 00000000000..e7b00e217f9 --- /dev/null +++ b/core/src/plugins/include/python_plugins_common.inc @@ -0,0 +1,148 @@ +/* + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2020-2020 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation, which is + listed in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + + +/** + * Strip any backslashes in the string. + */ +static inline void StripBackSlashes(char* value) +{ + char* bp; + + bp = value; + while (*bp) { + switch (*bp) { + case '\\': + bstrinlinecpy(bp, bp + 1); + break; + default: + break; + } + + bp++; + } +} + +/** + * Parse a boolean value e.g. check if its yes or true anything else translates + * to false. + */ +static inline bool ParseBoolean(const char* argument_value) +{ + if (Bstrcasecmp(argument_value, "yes") || + Bstrcasecmp(argument_value, "true")) { + return true; + } else { + return false; + } +} + +/** + * Parse a integer value. + */ +static inline int64_t parse_integer(const char* argument_value) +{ + return str_to_int64(argument_value); +} + +/** + * Always set destination to value and clean any previous one. + */ +static inline void SetString(char** destination, char* value) +{ + if (*destination) { free(*destination); } + + *destination = strdup(value); + StripBackSlashes(*destination); +} + + +/** + * Handle a Python error. + * + * Python equivalent: + * + * import traceback, sys + * return "".join(traceback.format_exception(sys.exc_type, + * sys.exc_value, sys.exc_traceback)) + */ +static void PyErrorHandler(PluginContext* bareos_plugin_ctx, int msgtype) +{ + PyObject *type, *value, *traceback; + PyObject* tracebackModule; + char* error_string; + + PyErr_Fetch(&type, &value, &traceback); + PyErr_NormalizeException(&type, &value, &traceback); + + tracebackModule = PyImport_ImportModule("traceback"); + if (tracebackModule != NULL) { + PyObject *tbList, *emptyString, *strRetval; + + tbList = + PyObject_CallMethod(tracebackModule, (char*)"format_exception", + (char*)"OOO", type, value == NULL ? Py_None : value, + traceback == NULL ? Py_None : traceback); + + emptyString = PyUnicode_FromString(""); + strRetval = + PyObject_CallMethod(emptyString, (char*)"join", (char*)"O", tbList); + + error_string = strdup(PyUnicode_AsUTF8(strRetval)); + + Py_DECREF(tbList); + Py_DECREF(emptyString); + Py_DECREF(strRetval); + Py_DECREF(tracebackModule); + } else { + error_string = strdup("Unable to import traceback module."); + } + + Py_DECREF(type); + Py_XDECREF(value); + Py_XDECREF(traceback); + + Dmsg(bareos_plugin_ctx, debuglevel, PYTHON_MODULE_NAME_QUOTED ": %s\n", + error_string); + if (msgtype) { + Jmsg(bareos_plugin_ctx, msgtype, PYTHON_MODULE_NAME_QUOTED ": %s\n", + error_string); + } + + free(error_string); +} + +/** + * Convert a return value into a bRC enum value. + */ +static inline bRC ConvertPythonRetvalTobRCRetval(PyObject* pRetVal) +{ + return (bRC)PyLong_AsLong(pRetVal); +} + +/** + * Convert a return value from bRC enum value into Python Object. + */ +static inline PyObject* ConvertbRCRetvalToPythonRetval(bRC retval) +{ + return (PyObject*)PyLong_FromLong((int)retval); +} +// vim: set ft=c From 1187af33bc1c38a6d48d426f95bbad59c3be6527 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 22 May 2020 18:24:18 +0200 Subject: [PATCH 144/341] python cmake: target properties --- core/src/plugins/dird/python/CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt index 0e2b36f1154..33b0335aac5 100644 --- a/core/src/plugins/dird/python/CMakeLists.txt +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -20,7 +20,9 @@ if(Python2_FOUND) add_library(python-dir MODULE python-dir.cc) # do not prefix with "lib" - set_target_properties(python-dir PROPERTIES PREFIX "") + set_target_properties( + python-dir PROPERTIES PREFIX "" LIBRARY_OUTPUT_DIRECTORY .. + ) install(TARGETS python-dir DESTINATION ${plugindir}) target_link_libraries(python-dir ${Python2_LIBRARIES} bareos) target_include_directories(python-dir PUBLIC SYSTEM ${Python2_INCLUDE_DIRS}) @@ -66,7 +68,9 @@ endif() if(Python3_FOUND) add_library(python3-dir MODULE python-dir.cc) # do not prefix with "lib" - set_target_properties(python3-dir PROPERTIES PREFIX "") + set_target_properties( + python3-dir PROPERTIES PREFIX "" LIBRARY_OUTPUT_DIRECTORY .. + ) install(TARGETS python3-dir DESTINATION ${plugindir}) target_link_libraries(python3-dir ${Python3_LIBRARIES} bareos) target_include_directories(python3-dir PUBLIC SYSTEM ${Python3_INCLUDE_DIRS}) From 5a1b56842514c933102689b5fdd1f64c4550ff6d Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 23 May 2020 12:12:22 +0200 Subject: [PATCH 145/341] cmake: fixed bareosfd-python.?-module --- core/src/plugins/filed/python/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 8ded7286efd..4bae1850be1 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -29,7 +29,7 @@ if(Python2_FOUND) ) target_link_libraries(python-fd ${Python2_LIBRARIES} bareos) target_include_directories(python-fd PUBLIC SYSTEM ${Python2_INCLUDE_DIRS}) - add_dependencies(python-fd bareosfd-pymod2) + add_dependencies(python-fd bareosfd-pymod) add_dependencies(bareos-fd python-fd) endif() @@ -106,17 +106,17 @@ if(Python2_FOUND AND NOT HAVE_WIN22) COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python2 module pythonmodules/bareosfd.so" ) - add_custom_target(bareosfd-pymod2 DEPENDS pythonmodules/bareosfd.so) - add_test(NAME bareosfd-python2-module + add_custom_target(bareosfd-pymod DEPENDS pythonmodules/bareosfd.so) + add_test(NAME bareosfd-python-module COMMAND ${Python2_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/bareosfd_test.py ) set_property( - TEST bareosfd-python2-module + TEST bareosfd-python-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/test" - LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib + LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../../lib ) endif() @@ -147,7 +147,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/python3modules:${CMAKE_CURRENT_SOURCE_DIR}/test" - LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../lib + LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/../../../lib ) endif() From df43706d2ca2ff6de18f1d3e817ff40bfcdda92d Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 23 May 2020 21:05:26 +0200 Subject: [PATCH 146/341] systemtests: enable set -u --- systemtests/scripts/functions | 2 +- systemtests/tests/bareos/testrunner | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/systemtests/scripts/functions b/systemtests/scripts/functions index 96093df4c7a..7253e3b9b15 100644 --- a/systemtests/scripts/functions +++ b/systemtests/scripts/functions @@ -630,7 +630,7 @@ check_restore_diff() result=$? fi OUT="$(diff --no-dereference -ur --exclude="fifo*" "${dest}" "${tmp}/bareos-restores/${dest}")" - result=$((result + $?)) + result=$(( result + $?)) if is_debug; then printf "%s\n" "$OUT" fi diff --git a/systemtests/tests/bareos/testrunner b/systemtests/tests/bareos/testrunner index 84382e8c3bc..3c1693c66b2 100755 --- a/systemtests/tests/bareos/testrunner +++ b/systemtests/tests/bareos/testrunner @@ -29,7 +29,7 @@ setup_data "$@" start_test -cat <$tmp/bconcmds +cat <"$tmp/bconcmds" @$out /dev/null messages @$out $tmp/log1.out @@ -58,5 +58,5 @@ check_for_zombie_jobs storage=File stop_bareos check_two_logs -check_restore_diff ${BackupDirectory} +check_restore_diff "${BackupDirectory}" end_test From 0394f0b49e0551a675291dff2f88cbff58b9d324 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 23 May 2020 21:19:22 +0200 Subject: [PATCH 147/341] systemtests: switch all testrunners to bash and -e -u --- systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner | 4 +++- systemtests/tests/spool/testrunner | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner b/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner index 744eb8657d5..bcc39e73894 100755 --- a/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner +++ b/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner @@ -1,4 +1,6 @@ -#!/bin/sh +#!/bin/bash +set -e +set -u # # This systemtest tests the Percona plugin functionality # of the Bareos FD by using the supplied module diff --git a/systemtests/tests/spool/testrunner b/systemtests/tests/spool/testrunner index 03921b43daa..84382e8c3bc 100755 --- a/systemtests/tests/spool/testrunner +++ b/systemtests/tests/spool/testrunner @@ -1,4 +1,6 @@ -#!/bin/sh +#!/bin/bash +set -e +set -u # # Run a simple backup # then restore it. From 51f86f52dde41497c14097c8bda575ebfe9b2a2d Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 23 May 2020 21:59:21 +0200 Subject: [PATCH 148/341] systemtests: adapt percona testrunner to set -e -u --- .../pyplug-fd-percona-xtrabackup/testrunner | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner b/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner index bcc39e73894..a2e957170f1 100755 --- a/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner +++ b/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner @@ -22,9 +22,11 @@ JobName=backup-bareos-fd "${rscripts}"/setup +[ -f "mysql/data/${HOSTNAME}.pid" ] && kill "$(cat mysql/data/${HOSTNAME}.pid)" +rm -Rf mysql/data/* mkdir -p mysql/data/ # initialize mysql db -mysqld --defaults-file=mysqldefaults --user=pstorz --initialize-insecure > mysql/mysql_init.log 2>1 +mysqld --defaults-file=mysqldefaults --user=pstorz --initialize-insecure > mysql/mysql_init.log 2>&1 # start mysql server mysqld --defaults-file=mysqldefaults >mysql/mysql.log 2>&1 & @@ -35,12 +37,11 @@ xtrabackup_test_db="${db_name}_xtrabackup" start_test -echo "drop database ${xtrabackup_test_db}" | $MYSQL echo "create database ${xtrabackup_test_db}" | $MYSQL -echo "CREATE TABLE test ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, data VARCHAR(100), created TIMESTAMP DEFAULT NOW()) " | $MYSQL ${xtrabackup_test_db} -echo "insert into test (data) VALUES ('test entry 1') " | $MYSQL ${xtrabackup_test_db} +echo "CREATE TABLE test ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, data VARCHAR(100), created TIMESTAMP DEFAULT NOW()) " | $MYSQL "${xtrabackup_test_db}" +echo "insert into test (data) VALUES ('test entry 1') " | $MYSQL "${xtrabackup_test_db}" -cat <$tmp/bconcmds +cat <"$tmp/bconcmds" @$out $tmp/log1.out run job=$JobName yes wait JobName=$JobName @@ -87,8 +88,8 @@ run_bareos "$@" # Check if xtrabackup has extracted some files at least # TODO: verify that xtrabackup --prepare works and eventually do complete datbase restore -ls -lR $tmp/bareos-restores/_percona/ -if [ -z "$(ls -A $tmp/bareos-restores/_percona/)" ]; then +ls -lR "$tmp/bareos-restores/_percona/" +if [ -z "$(ls -A "$tmp"/bareos-restores/_percona/)" ]; then echo "No restore data found" estat=1 fi @@ -96,8 +97,8 @@ fi # shutdown mysql -kill $(cat mysql/data/*.pid) -rm -Rvf $current_test_directory/mysql/data/* +[ -f "mysql/data/${HOSTNAME}.pid" ] && kill "$(cat mysql/data/${HOSTNAME}.pid)" +rm -Rf mysql/data check_for_zombie_jobs storage=File stop_bareos From 727080ff5ab783536c64bb2090ace1965ebc4c68 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sun, 24 May 2020 08:12:17 +0200 Subject: [PATCH 149/341] percona test: fixup use --raw --- .../bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in b/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in index d2781285ba4..3678677ccc0 100644 --- a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in +++ b/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in @@ -5,6 +5,6 @@ FileSet { Options { signature = MD5 } - Plugin = "@python_version@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-percona-xtrabackup:dumpbinary=@XTRABACKUP@ --defaults-file=mysqldefaults:extradumpoptions=--user=root@extradumpoptions@:mysqlcmd=mysql --defaults-file=mysqldefaults --user=root" + Plugin = "@python_version@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-percona-xtrabackup:dumpbinary=@XTRABACKUP@ --defaults-file=mysqldefaults:extradumpoptions=--user=root@extradumpoptions@:mysqlcmd=mysql --defaults-file=mysqldefaults --user=root --raw" } } From ba0d883e67ee8d7141b45379462a0b5136cdbfb2 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sun, 24 May 2020 17:22:08 +0200 Subject: [PATCH 150/341] systemtests: start_bareos: fix unset variable --- systemtests/scripts/functions | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/systemtests/scripts/functions b/systemtests/scripts/functions index 7253e3b9b15..add08b2a1f6 100644 --- a/systemtests/scripts/functions +++ b/systemtests/scripts/functions @@ -392,13 +392,14 @@ check_duration_lt() start_bareos() { + DOLLAR1="${1:-}" debug_wait zstat=0 estat=0 if test "$debug" -eq 1 ; then "${rscripts}/bareos-ctl-dir" start -m -d 100 "${rscripts}/bareos-ctl-sd" start -m -d 100 - "${rscripts}/bareos-ctl-fd" start -m -d 100 + "${rscripts}/bareos-ctl-fd" start -m "$DOLLAR1" -d 100 else "${rscripts}/bareos" start >/dev/null 2>&1 fi From a35ee49f228d318da9a3523eb7d737abfe8278c8 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 26 May 2020 09:31:09 +0200 Subject: [PATCH 151/341] percona-test: accept fail of mysqld kill --- systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner b/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner index a2e957170f1..7d081747787 100755 --- a/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner +++ b/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner @@ -22,7 +22,7 @@ JobName=backup-bareos-fd "${rscripts}"/setup -[ -f "mysql/data/${HOSTNAME}.pid" ] && kill "$(cat mysql/data/${HOSTNAME}.pid)" +[ -f "mysql/data/${HOSTNAME}.pid" ] && kill "$(cat mysql/data/${HOSTNAME}.pid)" || : rm -Rf mysql/data/* mkdir -p mysql/data/ # initialize mysql db From c122dc02c4f9e782c5609430ab6f0f37aa32ccd8 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 26 May 2020 10:18:46 +0200 Subject: [PATCH 152/341] stored: status.cc: fix rebase name problems --- core/src/stored/status.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/stored/status.cc b/core/src/stored/status.cc index f4a54088ca6..7205e3fb4f0 100644 --- a/core/src/stored/status.cc +++ b/core/src/stored/status.cc @@ -320,7 +320,7 @@ static void ListDevices(JobControlRecord* jcr, } get_device_specific_status(device_resource, sp); - trigger_device_status_hook(jcr, device_resource, sp, bsdEventDriveStatus); + trigger_device_status_hook(jcr, device_resource, sp, bSdEventDriveStatus); SendBlockedStatus(dev, sp); @@ -355,7 +355,7 @@ static void ListDevices(JobControlRecord* jcr, sp->send(msg, len); trigger_device_status_hook(jcr, device_resource, sp, - bsdEventVolumeStatus); + bSdEventVolumeStatus); } else { if (dev) { len = Mmsg(msg, _("\nDevice %s is not open.\n"), dev->print_name()); From d5ab5a42ed785e9919aa049c3db017ecbfd7f8db Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 26 May 2020 10:53:47 +0200 Subject: [PATCH 153/341] BareosFdPlugins: fix mergeproblems --- .../python/pyfiles/BareosFdPluginBaseclass.py | 4 ++-- ...areosFdPluginLocalFilesetWithRestoreObjects.py | 15 +++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/core/src/plugins/filed/python/pyfiles/BareosFdPluginBaseclass.py b/core/src/plugins/filed/python/pyfiles/BareosFdPluginBaseclass.py index 67fb20befde..64106d13f47 100644 --- a/core/src/plugins/filed/python/pyfiles/BareosFdPluginBaseclass.py +++ b/core/src/plugins/filed/python/pyfiles/BareosFdPluginBaseclass.py @@ -259,7 +259,7 @@ def plugin_io(self, IOP): "plugin_io called with function %s filename %s\n" % (IOP.func, IOP.fname), ) bareosfd.DebugMessage(250, "self.FNAME is set to %s\n" % (self.FNAME)) - if IOP.func == O_OPEN: + if IOP.func == IO_OPEN: return self.plugin_io_open(IOP) elif IOP.func == IO_CLOSE: return self.plugin_io_close(IOP) @@ -315,7 +315,7 @@ def start_backup_job(self): """ return bRC_OK - def end_job(self: + def end_job(self): """ Called if job ends regularyly (not for cancelled jobs) Overload this to arrange whatever you have to do at this time. diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py index 671d7f5ed19..3c7424904a4 100644 --- a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py +++ b/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py @@ -63,14 +63,13 @@ def __init__(self, plugindef): self.deny = None self.object_index_seq = int((time.time() - 1546297200) * 10) self.sha256sums_by_filename = {} - bareosfd.SetValue(context,bVarSinceTime,999) - triple_nine = bareosfd.GetValue(context,bVarSinceTime) - if triple_nine != 999: - bareosfd.JobMessage( - context, - M_ERROR, - "Wrong value for since time (should be 999 but is %d)\n" % triple_nine - ) + # bareosfd.SetValue(bVarSinceTime,999) + # triple_nine = bareosfd.GetValue(bVarSinceTime) + # if triple_nine != 999: + # bareosfd.JobMessage( + # M_ERROR, + # "Wrong value for since time (should be 999 but is %d)\n" % triple_nine + # ) def filename_is_allowed(self, filename, allowregex, denyregex): From 16939ec585753a87f9e37d9e5caab26d827bc5da Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 26 May 2020 10:55:28 +0200 Subject: [PATCH 154/341] cmake: add python3-fd-postgres --- systemtests/CMakeLists.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 9025f80e03a..4f2b70b1616 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -631,6 +631,12 @@ else() list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-local-fileset") endif() +if(TARGET python3-fd) + list(APPEND SYSTEM_TESTS "python3-fd-plugin-local-fileset-test") +else() + list(APPEND SYSTEM_TESTS_DISABLED "python3-fd-plugin-local-fileset-test") +endif() + if(TARGET python-fd) list(APPEND SYSTEM_TESTS "pyplug-fd-local-fileset-restoreobject") else() @@ -652,9 +658,9 @@ else() message("NOT OK, disabling pyplug-fd-postgres:") endif() if(TARGET python3-fd) - list(APPEND SYSTEM_TESTS "python3-fd-plugin-local-fileset-test") + list(APPEND SYSTEM_TESTS "python3-fd-plugin-postgres-test") else() - list(APPEND SYSTEM_TESTS_DISABLED "python3-fd-plugin-local-fileset-test") + list(APPEND SYSTEM_TESTS_DISABLED "python3-fd-plugin-postgres-test") endif() if(TARGET python-fd AND ovirt_server) From deaedd0e117c81fec04025f655552b6303f85589 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 26 May 2020 12:43:44 +0200 Subject: [PATCH 155/341] python plugins: moved postgres files --- .../filed/{ => python/postgres}/BareosFdPluginPostgres.py | 0 .../plugins/filed/{ => python/postgres}/bareos-fd-postgres.py | 0 systemtests/tests/python3-fd-plugin-postgres-test | 1 + 3 files changed, 1 insertion(+) rename core/src/plugins/filed/{ => python/postgres}/BareosFdPluginPostgres.py (100%) rename core/src/plugins/filed/{ => python/postgres}/bareos-fd-postgres.py (100%) create mode 120000 systemtests/tests/python3-fd-plugin-postgres-test diff --git a/core/src/plugins/filed/BareosFdPluginPostgres.py b/core/src/plugins/filed/python/postgres/BareosFdPluginPostgres.py similarity index 100% rename from core/src/plugins/filed/BareosFdPluginPostgres.py rename to core/src/plugins/filed/python/postgres/BareosFdPluginPostgres.py diff --git a/core/src/plugins/filed/bareos-fd-postgres.py b/core/src/plugins/filed/python/postgres/bareos-fd-postgres.py similarity index 100% rename from core/src/plugins/filed/bareos-fd-postgres.py rename to core/src/plugins/filed/python/postgres/bareos-fd-postgres.py diff --git a/systemtests/tests/python3-fd-plugin-postgres-test b/systemtests/tests/python3-fd-plugin-postgres-test new file mode 120000 index 00000000000..9b59874a914 --- /dev/null +++ b/systemtests/tests/python3-fd-plugin-postgres-test @@ -0,0 +1 @@ +python-fd-plugin-postgres-test \ No newline at end of file From 928d79c0e1e2aebd5b4f8749353106479a0151a1 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 26 May 2020 15:33:15 +0200 Subject: [PATCH 156/341] BareosFdPluginPostgres: works for now --- .../python/postgres/BareosFdPluginPostgres.py | 186 ++++++++---------- .../python/postgres/bareos-fd-postgres.py | 14 +- .../pyfiles/BareosFdPluginLocalFileset.py | 38 ++-- .../tests/pyplug-fd-postgres/testrunner | 2 + 4 files changed, 109 insertions(+), 131 deletions(-) diff --git a/core/src/plugins/filed/python/postgres/BareosFdPluginPostgres.py b/core/src/plugins/filed/python/postgres/BareosFdPluginPostgres.py index 78d5e4c3f82..0ecd82da67a 100644 --- a/core/src/plugins/filed/python/postgres/BareosFdPluginPostgres.py +++ b/core/src/plugins/filed/python/postgres/BareosFdPluginPostgres.py @@ -24,8 +24,6 @@ # Bareos python plugins class that performs online backups (full and incremental) # from Postgres databases. Supports point-in-time (PIT) restores. -from bareosfd import * -from bareos_fd_consts import bJobMessageType, bFileType, bRCs import os import sys import re @@ -47,16 +45,15 @@ class BareosFdPluginPostgres( listed there Filename is taken from plugin argument 'filename' """ - def __init__(self, context, plugindef): + def __init__(self, plugindef): bareosfd.DebugMessage( - context, 100, "Constructor called in module %s with plugindef=%s\n" % (__name__, plugindef), ) # Last argument of super constructor is a list of mandatory arguments super(BareosFdPluginPostgres, self).__init__( - context, plugindef, ["postgresDataDir", "walArchive"] + plugindef, ["postgresDataDir", "walArchive"] ) self.ignoreSubdirs = ["pg_wal", "pg_log", "pg_xlog"] @@ -89,24 +86,23 @@ def __init__(self, context, plugindef): else time.timezone ) - def check_options(self, context, mandatory_options=None): + def check_options(self, mandatory_options=None): """ Check for mandatory options and verify database connection """ result = super(BareosFdPluginPostgres, self).check_options( - context, mandatory_options + mandatory_options ) - if not result == bRCs["bRC_OK"]: + if not result == bRC_OK: return result # Accurate may cause problems with plugins - accurate_enabled = GetValue(context, bVariable["bVarAccurate"]) + accurate_enabled = GetValue(bVarAccurate) if accurate_enabled is not None and accurate_enabled != 0: JobMessage( - context, - bJobMessageType["M_FATAL"], + M_FATAL, "start_backup_job: Accurate backup not allowed please disable in Job\n", ) - return bRCs["bRC_Error"] + return bRC_Error if not self.options["postgresDataDir"].endswith("/"): self.options["postgresDataDir"] += "/" self.labelFileName = self.options["postgresDataDir"] + "/backup_label" @@ -128,9 +124,9 @@ def check_options(self, context, mandatory_options=None): self.switchWal = self.options["switchWal"].lower() == "true" if "dbHost" in self.options: self.dbOpts += " host='%s'" % self.options["dbHost"] - return bRCs["bRC_OK"] + return bRC_OK - def execute_SQL(self, context, sqlStatement): + def execute_SQL(self, sqlStatement): """ Executes the SQL statement using the classes dbCursor """ @@ -138,8 +134,7 @@ def execute_SQL(self, context, sqlStatement): self.dbCursor.execute(sqlStatement) except Exception as e: bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], + M_ERROR, 'Query "%s" failed: "%s"' % (sqlStatement, e.message), ) return False @@ -155,12 +150,12 @@ def formatLSN(self, rawLSN): lsnPre, lsnPost = rawLSN.split("/") return lsnPre.zfill(8) + "/" + lsnPost.zfill(8) - def start_backup_job(self, context): + def start_backup_job(self): """ Make filelist in super class and tell Postgres that we start a backup now """ - bareosfd.DebugMessage(context, 100, "start_backup_job in PostgresPlugin called") + bareosfd.DebugMessage(100, "start_backup_job in PostgresPlugin called") try: self.dbCon = psycopg2.connect( "dbname=%s user=%s %s" % (self.dbname, self.dbuser, self.dbOpts) @@ -169,22 +164,20 @@ def start_backup_job(self, context): self.dbCursor.execute("SELECT current_setting('server_version_num')") self.pgVersion = int(self.dbCursor.fetchone()[0]) # bareosfd.DebugMessage( - # context, 1, "Connected to Postgres version %d\n" % self.pgVersion, + # 1, "Connected to Postgres version %d\n" % self.pgVersion, # ) ## WARNING: JobMessages cause fatal errors at this stage JobMessage( - context, - bJobMessageType["M_INFO"], + M_INFO, "Connected to Postgres version %d\n" % (self.pgVersion), ) except: bareosfd.JobMessage( - context, - bJobMessageType["M_FATAL"], + M_FATAL, "Could not connect to database %s, user %s\n" % (self.dbname, self.dbuser), ) - return bRCs["bRC_Error"] + return bRC_Error if chr(self.level) == "F": # For Full we backup the Postgres data directory # Restore object ROP comes later, after file backup @@ -192,7 +185,7 @@ def start_backup_job(self, context): startDir = self.options["postgresDataDir"] self.files_to_backup.append(startDir) bareosfd.DebugMessage( - context, 100, "dataDir: %s\n" % self.options["postgresDataDir"] + 100, "dataDir: %s\n" % self.options["postgresDataDir"] ) else: # If level is not Full, we only backup WAL files @@ -212,52 +205,46 @@ def start_backup_job(self, context): switchLsnStmt = "SELECT pg_switch_xlog()" if pgMajorVersion < 9: bareosfd.JobMessage( - context, - bJobMessageType["M_INFO"], + M_INFO, "WAL switching not supported on Postgres Version < 9\n", ) else: - if self.execute_SQL(context, getLsnStmt): + if self.execute_SQL(getLsnStmt): currentLSN = self.formatLSN(self.dbCursor.fetchone()[0]) bareosfd.JobMessage( - context, - bJobMessageType["M_INFO"], + M_INFO, "Current LSN %s, last LSN: %s\n" % (currentLSN, self.lastLSN), ) else: currrentLSN = 0 bareosfd.JobMessage( - context, - bJobMessageType["M_WARNING"], + M_WARNING, "Could not get current LSN, last LSN was: %s\n" % self.lastLSN, ) if currentLSN > self.lastLSN and self.switchWal: # Let Postgres write latest transaction into a new WAL file now - if not self.execute_SQL(context, switchLsnStmt): + if not self.execute_SQL(switchLsnStmt): bareosfd.JobMessage( - context, - bJobMessageType["M_WARNING"], + M_WARNING, "Could not switch to next WAL segment\n", ) - if self.execute_SQL(context, getLsnStmt): + if self.execute_SQL(getLsnStmt): currentLSN = self.formatLSN(self.dbCursor.fetchone()[0]) self.lastLSN = currentLSN # wait some seconds to make sure WAL file gets written time.sleep(10) else: bareosfd.JobMessage( - context, - bJobMessageType["M_WARNING"], + M_WARNING, "Could not read LSN after switching to new WAL segment\n", ) else: # Nothing has changed since last backup - only send ROP this time bareosfd.JobMessage( - context, - bJobMessageType["M_INFO"], + M_INFO, "Same LSN %s as last time - nothing to do\n" % currentLSN, ) - return bRCs["bRC_OK"] + return bRC_OK # Gather files from startDir (Postgres data dir or walArchive for incr/diff jobs) for fileName in os.listdir(startDir): @@ -265,27 +252,24 @@ def start_backup_job(self, context): # We need a trailing '/' for directories if os.path.isdir(fullName) and not fullName.endswith("/"): fullName += "/" - bareosfd.DebugMessage(context, 100, "fullName: %s\n" % fullName) + bareosfd.DebugMessage(100, "fullName: %s\n" % fullName) # Usually Bareos takes care about timestamps when doing incremental backups # but here we have to compare against last BackupPostgres timestamp try: mTime = os.stat(fullName).st_mtime except Exception as e: bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], + M_ERROR, 'Could net get stat-info for file %s: "%s"' % (file_to_backup, e.message), ) bareosfd.DebugMessage( - context, 150, "%s fullTime: %d mtime: %d\n" % (fullName, self.lastBackupStopTime, mTime), ) if mTime > self.lastBackupStopTime + 1: bareosfd.DebugMessage( - context, 150, "file: %s, fullTime: %d mtime: %d\n" % (fullName, self.lastBackupStopTime, mTime), @@ -304,52 +288,50 @@ def start_backup_job(self, context): # Will be written into the Restore Object if not chr(self.level) == "F": self.lastBackupStopTime = int(time.time()) - return bRCs["bRC_OK"] + return bRC_OK # For Full we check for a running job and tell Postgres that # we want to backup the DB files now. if os.path.exists(self.labelFileName): - self.parseBackupLabelFile(context) + self.parseBackupLabelFile() bareosfd.JobMessage( - context, - bJobMessageType["M_FATAL"], + M_FATAL, 'Another Postgres Backup Operation "%s" is in progress. ' - % self.labelItems["LABEL"] + % self.laLABEL + "You may stop it using SELECT pg_stop_backup()", ) - return bRCs["bRC_Error"] + return bRC_Error bareosfd.DebugMessage( - context, 100, "Send 'SELECT pg_start_backup' to Postgres\n" + 100, "Send 'SELECT pg_start_backup' to Postgres\n" ) # We tell Postgres that we want to start to backup file now self.backupStartTime = datetime.datetime.now( tz=dateutil.tz.tzoffset(None, self.tzOffset) ) if not self.execute_SQL( - context, "SELECT pg_start_backup('%s');" % self.backupLabelString + "SELECT pg_start_backup('%s');" % self.backupLabelString ): bareosfd.JobMessage( - context, bJobMessageType["M_FATAL"], "pg_start_backup statement failed." + M_FATAL, "pg_start_backup statement failed." ) - return bRCs["bRC_Error"] + return bRC_Error results = self.dbCursor.fetchall() - bareosfd.DebugMessage(context, 150, "Start response: %s\n" % str(results)) + bareosfd.DebugMessage(150, "Start response: %s\n" % str(results)) bareosfd.DebugMessage( - context, 150, "Adding label file %s to fileset\n" % self.labelFileName + 150, "Adding label file %s to fileset\n" % self.labelFileName ) self.files_to_backup.append(self.labelFileName) - bareosfd.DebugMessage(context, 150, "Filelist: %s\n" % (self.files_to_backup)) + bareosfd.DebugMessage(150, "Filelist: %s\n" % (self.files_to_backup)) self.PostgressFullBackupRunning = True - return bRCs["bRC_OK"] + return bRC_OK - def parseBackupLabelFile(self, context): + def parseBackupLabelFile(self): try: labelFile = open(self.labelFileName, "rb") except: bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], + M_ERROR, "Could not open Label File %s" % (self.labelFileName), ) @@ -357,48 +339,47 @@ def parseBackupLabelFile(self, context): k, v = labelItem.split(":", 1) self.labelItems.update({k.strip(): v.strip()}) labelFile.close() - bareosfd.DebugMessage(context, 150, "Labels read: %s\n" % str(self.labelItems)) + bareosfd.DebugMessage(150, "Labels read: %s\n" % str(self.labelItems)) - def start_backup_file(self, context, savepkt): + def start_backup_file(self, savepkt): """ For normal files we call the super method Special objects are treated here """ if not self.files_to_backup: - bareosfd.DebugMessage(context, 100, "No files to backup\n") - return bRCs["bRC_Skip"] + bareosfd.DebugMessage(100, "No files to backup\n") + return bRC_Skip # Plain files are handled by super class if self.files_to_backup[-1] not in ["ROP"]: return super(BareosFdPluginPostgres, self).start_backup_file( - context, savepkt + savepkt ) # Here we create the restore object self.file_to_backup = self.files_to_backup.pop() - bareosfd.DebugMessage(context, 100, "file: " + self.file_to_backup + "\n") + bareosfd.DebugMessage(100, "file: " + self.file_to_backup + "\n") savepkt.statp = StatPacket() if self.file_to_backup == "ROP": self.rop_data["lastBackupStopTime"] = self.lastBackupStopTime self.rop_data["lastLSN"] = self.lastLSN savepkt.fname = "/_bareos_postgres_plugin/metadata" - savepkt.type = bFileType["FT_RESTORE_FIRST"] + savepkt.type = FT_RESTORE_FIRST savepkt.object_name = savepkt.fname - bareosfd.DebugMessage(context, 150, "fname: " + savepkt.fname + "\n") - bareosfd.DebugMessage(context, 150, "rop " + str(self.rop_data) + "\n") + bareosfd.DebugMessage(150, "fname: " + savepkt.fname + "\n") + bareosfd.DebugMessage(150, "rop " + str(self.rop_data) + "\n") savepkt.object = bytearray(json.dumps(self.rop_data)) savepkt.object_len = len(savepkt.object) savepkt.object_index = int(time.time()) else: # should not happen JobMessage( - context, - bJobMessageType["M_FATAL"], + M_FATAL, "Unknown error. Don't know how to handle %s\n" % self.file_to_backup, ) - return bRCs["bRC_OK"] + return bRC_OK - def restore_object_data(self, context, ROP): + def restore_object_data(self, ROP): """ Called on restore and on diff/inc jobs. """ @@ -408,8 +389,7 @@ def restore_object_data(self, context, ROP): self.rop_data[ROP.jobid] = json.loads(str(self.row_rop_raw)) except Exception as e: bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], + M_ERROR, 'Could net parse restore object json-data "%s\ / "%s"' % (self.row_rop_raw, e.message), ) @@ -419,35 +399,32 @@ def restore_object_data(self, context, ROP): self.rop_data[ROP.jobid]["lastBackupStopTime"] ) JobMessage( - context, - bJobMessageType["M_INFO"], + M_INFO, "Got lastBackupStopTime %d from restore object of job %d\n" % (self.lastBackupStopTime, ROP.jobid), ) if "lastLSN" in self.rop_data[ROP.jobid]: self.lastLSN = self.rop_data[ROP.jobid]["lastLSN"] JobMessage( - context, - bJobMessageType["M_INFO"], + M_INFO, "Got lastLSN %s from restore object of job %d\n" % (self.lastLSN, ROP.jobid), ) - return bRCs["bRC_OK"] + return bRC_OK - def closeDbConnection(self, context): + def closeDbConnection(self): # TODO Error Handling # Get Backup Start Date - self.parseBackupLabelFile(context) + self.parseBackupLabelFile() # self.execute_SQL("SELECT pg_backup_start_time()") # self.backupStartTime = self.dbCursor.fetchone()[0] # Tell Postgres we are done - if self.execute_SQL(context, "SELECT pg_stop_backup();"): + if self.execute_SQL("SELECT pg_stop_backup();"): self.lastLSN = self.formatLSN(self.dbCursor.fetchone()[0]) self.lastBackupStopTime = int(time.time()) results = self.dbCursor.fetchall() bareosfd.JobMessage( - context, - bJobMessageType["M_INFO"], + M_INFO, "Database connection closed. " + "CHECKPOINT LOCATION: %s, " % self.labelItems["CHECKPOINT LOCATION"] + "START WAL LOCATION: %s\n" % self.labelItems["START WAL LOCATION"], @@ -455,10 +432,10 @@ def closeDbConnection(self, context): self.PostgressFullBackupRunning = False else: bareosfd.JobMessage( - context, bJobMessageType["M_ERROR"], "pg_stop_backup statement failed." + M_ERROR, "pg_stop_backup statement failed." ) - def checkForWalFiles(self, context): + def checkForWalFiles(self): """ Look for new WAL files and backup Backup start time is timezone aware, we need to add timezone @@ -474,8 +451,7 @@ def checkForWalFiles(self, context): st = os.stat(fullPath) except Exception as e: bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], + M_ERROR, 'Could net get stat-info for file %s: "%s"' % (fullPath, e.message), ) continue @@ -485,44 +461,44 @@ def checkForWalFiles(self, context): > self.backupStartTime ): bareosfd.DebugMessage( - context, 150, "Adding WAL file %s for backup\n" % fileName + 150, "Adding WAL file %s for backup\n" % fileName ) self.files_to_backup.append(fullPath) if self.files_to_backup: - return bRCs["bRC_More"] + return bRC_More else: - return bRCs["bRC_OK"] + return bRC_OK - def end_backup_file(self, context): + def end_backup_file(self): """ Here we return 'bRC_More' as long as our list files_to_backup is not empty and bRC_OK when we are done """ bareosfd.DebugMessage( - context, 100, "end_backup_file() entry point in Python called\n" + 100, "end_backup_file() entry point in Python called\n" ) if self.files_to_backup: - return bRCs["bRC_More"] + return bRC_More else: if self.PostgressFullBackupRunning: - self.closeDbConnection(context) + self.closeDbConnection() # Now we can also create the Restore object with the right timestamp self.files_to_backup.append("ROP") - return self.checkForWalFiles(context) + return self.checkForWalFiles() else: - return bRCs["bRC_OK"] + return bRC_OK - def end_backup_job(self, context): + def end_backup_job(self): """ - Called if backup job ends, before ClientAfterJob + Called if backup job ends, before ClientAfterJob Make sure that dbconnection was closed in any way, especially when job was cancelled """ if self.PostgressFullBackupRunning: - self.closeDbConnection(context) + self.closeDbConnection() self.PostgressFullBackupRunning = False - return bRCs["bRC_OK"] + return bRC_OK # vim: ts=4 tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/core/src/plugins/filed/python/postgres/bareos-fd-postgres.py b/core/src/plugins/filed/python/postgres/bareos-fd-postgres.py index 8afb9307345..64ec422c5ec 100644 --- a/core/src/plugins/filed/python/postgres/bareos-fd-postgres.py +++ b/core/src/plugins/filed/python/postgres/bareos-fd-postgres.py @@ -26,8 +26,8 @@ # # Provided by the Bareos FD Python plugin interface -import bareos_fd_consts import bareosfd +from bareosfd import * # This module contains the wrapper functions called by the Bareos-FD, the # functions call the corresponding methods from your plugin class import BareosFdWrapper @@ -39,7 +39,7 @@ import BareosFdPluginPostgres -def load_bareos_plugin(context, plugindef): +def load_bareos_plugin(plugindef): """ This function is called by the Bareos-FD to load the plugin We use it to instantiate the plugin class @@ -48,17 +48,17 @@ def load_bareos_plugin(context, plugindef): try: import psycopg2 except Exception as e: - bareosfd.JobMessage( context, - bareos_fd_consts.bJobMessageType["M_FATAL"], + bareosfd.JobMessage( + M_FATAL, "could not import Python module. %s" % e.message, ) - return bareos_fd_consts.bRCs["bRC_Error"] + return bRC_Error # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that # holds the plugin class object BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginPostgres.BareosFdPluginPostgres( - context, plugindef + plugindef ) - return bareos_fd_consts.bRCs["bRC_OK"] + return bRC_OK # the rest is done in the Plugin module diff --git a/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py b/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py index 84aa3b66b5f..20e49734609 100644 --- a/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py +++ b/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py @@ -25,7 +25,7 @@ # the backup fileset import bareosfd -from bareos_fd_consts import bJobMessageType, bFileType, bRCs, bCFs +from bareosfd import * import os import re import BareosFdPluginBaseclass @@ -81,7 +81,7 @@ def filename_is_allowed(self, filename, allowregex, denyregex): 100, "File %s denied by configuration\n" % (filename) ) bareosfd.JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, "File %s denied by configuration\n" % (filename), ) return False @@ -115,12 +115,12 @@ def start_backup_job(self): 100, "Could not open file %s\n" % (self.options["filename"]), ) - return bRCs["bRC_Error"] + return bRC_Error else: bareosfd.DebugMessage( 100, "File %s does not exist\n" % (self.options["filename"]) ) - return bRCs["bRC_Error"] + return bRC_Error # Check, if we have allow or deny regular expressions defined if "allow" in self.options: self.allow = re.compile(self.options["allow"]) @@ -155,12 +155,12 @@ def start_backup_job(self): if not self.files_to_backup: bareosfd.JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, "No (allowed) files to backup found\n", ) - return bRCs["bRC_Error"] + return bRC_Error else: - return bRCs["bRC_OK"] + return bRC_OK def start_backup_file(self, savepkt): """ @@ -170,7 +170,7 @@ def start_backup_file(self, savepkt): bareosfd.DebugMessage( 100, "start_backup_file() called\n") if not self.files_to_backup: bareosfd.DebugMessage( 100, "No files to backup\n") - return bRCs["bRC_Skip"] + return bRC_Skip self.file_to_backup = self.files_to_backup.pop().decode("string_escape") bareosfd.DebugMessage(100, "file: " + self.file_to_backup + "\n") @@ -183,7 +183,7 @@ def start_backup_file(self, savepkt): statp = os.stat(self.file_to_backup) except Exception as e: bareosfd.JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, 'Could net get stat-info for file %s: "%s"' % (self.file_to_backup, e.message), ) @@ -209,16 +209,16 @@ def start_backup_file(self, savepkt): # there is no trailing slash - we need to perform checks # on the stripped name but use it with trailing / for the backup itself if os.path.islink(self.file_to_backup.rstrip("/")): - savepkt.type = bFileType["FT_LNK"] + savepkt.type = FT_LNK savepkt.link = os.readlink( self.file_to_backup.rstrip("/").encode("string_escape") ) bareosfd.DebugMessage(150, "file type is: FT_LNK\n") elif os.path.isfile(self.file_to_backup): - savepkt.type = bFileType["FT_REG"] + savepkt.type = FT_REG bareosfd.DebugMessage(150, "file type is: FT_REG\n") elif os.path.isdir(self.file_to_backup): - savepkt.type = bFileType["FT_DIREND"] + savepkt.type = FT_DIREND savepkt.link = self.file_to_backup bareosfd.DebugMessage( 150, "file %s type is: FT_DIREND\n" % self.file_to_backup @@ -228,15 +228,15 @@ def start_backup_file(self, savepkt): bareosfd.DebugMessage(150, "file type is: FT_FIFO\n") else: bareosfd.JobMessage( - bJobMessageType["M_WARNING"], + M_WARNING, "File %s of unknown type" % (self.file_to_backup), ) - return bRCs["bRC_Skip"] + return bRC_Skip savepkt.statp = mystatp bareosfd.DebugMessage(150, "file statpx " + str(savepkt.statp) + "\n") - return bRCs["bRC_OK"] + return bRC_OK def create_file(self, restorepkt): """ @@ -333,11 +333,11 @@ def set_file_attributes(self, restorepkt): except Exception as e: bareosfd.JobMessage( - bJobMessageType["M_WARNING"], + M_WARNING, 'Could net set attributes for file %s: "%s"' % (file_name, e.message), ) - return bRCs["bRC_OK"] + return bRC_OK def end_restore_file(self): bareosfd.DebugMessage( @@ -377,9 +377,9 @@ def end_backup_file(self): 100, "end_backup_file() entry point in Python called\n" ) if self.files_to_backup: - return bRCs["bRC_More"] + return bRC_More else: - return bRCs["bRC_OK"] + return bRC_OK # vim: ts=4 tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/systemtests/tests/pyplug-fd-postgres/testrunner b/systemtests/tests/pyplug-fd-postgres/testrunner index 9ef55176ae0..40b699c3f8b 100755 --- a/systemtests/tests/pyplug-fd-postgres/testrunner +++ b/systemtests/tests/pyplug-fd-postgres/testrunner @@ -2,6 +2,8 @@ set -e set -u # +set -e +set -u # This systemtest tests the plugin functionality # of the Bareos FD by using the supplied module # bareos-fd-postgres From 50daecd7b2c3d008a25f44478580f3b96650359c Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 26 May 2020 17:21:00 +0200 Subject: [PATCH 157/341] PluginLocalFileset: postgres restore works --- .../pyfiles/BareosFdPluginLocalFileset.py | 57 +++++++++---------- .../tests/pyplug-fd-postgres/testrunner | 1 + 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py b/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py index 20e49734609..02426012a0f 100644 --- a/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py +++ b/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py @@ -191,19 +191,19 @@ def start_backup_file(self, savepkt): # In this case we have to translate names # For future releases consistent names are planned, allowing to assign the # complete stat object in one rush - if hasattr(mystatp, "st_uid"): - mystatp = statp - else: - mystatp.mode = statp.st_mode - mystatp.ino = statp.st_ino - mystatp.dev = statp.st_dev - mystatp.nlink = statp.st_nlink - mystatp.uid = statp.st_uid - mystatp.gid = statp.st_gid - mystatp.size = statp.st_size - mystatp.atime = statp.st_atime - mystatp.mtime = statp.st_mtime - mystatp.ctime = statp.st_ctime + # if hasattr(mystatp, "st_uid"): + # mystatp = statp + # else: + mystatp.st_mode = statp.st_mode + mystatp.st_ino = statp.st_ino + mystatp.st_dev = statp.st_dev + mystatp.st_nlink = statp.st_nlink + mystatp.st_uid = statp.st_uid + mystatp.st_gid = statp.st_gid + mystatp.st_size = statp.st_size + mystatp.st_atime = statp.st_atime + mystatp.st_mtime = statp.st_mtime + mystatp.st_ctime = statp.st_ctime savepkt.fname = self.file_to_backup.encode("string_escape") # os.islink will detect links to directories only when # there is no trailing slash - we need to perform checks @@ -224,7 +224,7 @@ def start_backup_file(self, savepkt): 150, "file %s type is: FT_DIREND\n" % self.file_to_backup ) elif stat.S_ISFIFO(os.stat(self.file_to_backup).st_mode): - savepkt.type = bFileType["FT_FIFO"] + savepkt.type = FT_FIFO bareosfd.DebugMessage(150, "file type is: FT_FIFO\n") else: bareosfd.JobMessage( @@ -250,7 +250,7 @@ def create_file(self, restorepkt): ) FNAME = restorepkt.ofname.decode("string_escape") if not FNAME: - return bRCs["bRC_Error"] + return bRC_Error dirname = os.path.dirname(FNAME.rstrip("/")) if not os.path.exists(dirname): bareosfd.DebugMessage( @@ -259,42 +259,42 @@ def create_file(self, restorepkt): os.makedirs(dirname) # open creates the file, if not yet existing, we close it again right # aways it will be opened again in plugin_io. - if restorepkt.type == bFileType["FT_REG"]: + if restorepkt.type == FT_REG: open(FNAME, "wb").close() - restorepkt.create_status = bCFs["CF_EXTRACT"] - elif restorepkt.type == bFileType["FT_LNK"]: + restorepkt.create_status = CF_EXTRACT + elif restorepkt.type == FT_LNK: linkNameEnc = restorepkt.olname linkNameClear = linkNameEnc.decode("string_escape") if not os.path.islink(FNAME.rstrip("/")): # if not os.path.exists(linkNameClear): os.symlink(linkNameClear, FNAME.rstrip("/")) - restorepkt.create_status = bCFs["CF_CREATED"] - elif restorepkt.type == bFileType["FT_LNKSAVED"]: + restorepkt.create_status = CF_CREATED + elif restorepkt.type == FT_LNKSAVED: linkNameEnc = restorepkt.olname linkNameClear = linkNameEnc.decode("string_escape") if not os.path.exists(linkNameClear): os.link(linkNameClear, FNAME.rstrip("/")) - restorepkt.create_status = bCFs["CF_CREATED"] - elif restorepkt.type == bFileType["FT_DIREND"]: + restorepkt.create_status = CF_CREATED + elif restorepkt.type == FT_DIREND: if not os.path.exists(FNAME): os.makedirs(FNAME) - restorepkt.create_status = bCFs["CF_CREATED"] - elif restorepkt.type == bFileType["FT_FIFO"]: + restorepkt.create_status = CF_CREATED + elif restorepkt.type == FT_FIFO: if not os.path.exists(FNAME): try: os.mkfifo(FNAME, 0o600) except Exception as e: bareosfd.JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, 'Could net create fifo %s: "%s"' % (FNAME, e.message), ) - restorepkt.create_status = bCFs["CF_CREATED"] + restorepkt.create_status = CF_CREATED else: bareosfd.JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, "Unknown type %s of file %s" % (restorepkt.type, FNAME), ) - return bRCs["bRC_OK"] + return bRC_OK def set_file_attributes(self, restorepkt): """ @@ -336,7 +336,6 @@ def set_file_attributes(self, restorepkt): M_WARNING, 'Could net set attributes for file %s: "%s"' % (file_name, e.message), ) - return bRC_OK def end_restore_file(self): diff --git a/systemtests/tests/pyplug-fd-postgres/testrunner b/systemtests/tests/pyplug-fd-postgres/testrunner index 40b699c3f8b..e93ecfdc566 100755 --- a/systemtests/tests/pyplug-fd-postgres/testrunner +++ b/systemtests/tests/pyplug-fd-postgres/testrunner @@ -95,6 +95,7 @@ messages @$out $tmp/log1.out restore client=bareos-fd where=/ select all done yes wait +messages END_OF_DATA run_bconsole From 571b09108fafa478dc8e0a201fc12bd4b187a42e Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 26 May 2020 19:09:13 +0200 Subject: [PATCH 158/341] postgres plugin: works for postgres 12 --- core/CMakeLists.txt | 1 + .../plugins/filed/python/postgres/BareosFdPluginPostgres.py | 4 ++-- systemtests/tests/pyplug-fd-postgres/testrunner | 3 --- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index db4c7886d36..b5351bafa4b 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -878,6 +878,7 @@ message( ) message(" systemd support: ${WITH_SYSTEMD} ${SYSTEMD_UNITDIR}") message(" Batch insert enabled: ${USE_BATCH_FILE_INSERT}") +message(" PostgreSQL Version: ${PostgreSQL_VERSION_STRING} ") if(GTEST_FOUND) message( " gtest support: ${GTEST_FOUND} ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} " diff --git a/core/src/plugins/filed/python/postgres/BareosFdPluginPostgres.py b/core/src/plugins/filed/python/postgres/BareosFdPluginPostgres.py index 0ecd82da67a..172feb93dba 100644 --- a/core/src/plugins/filed/python/postgres/BareosFdPluginPostgres.py +++ b/core/src/plugins/filed/python/postgres/BareosFdPluginPostgres.py @@ -328,7 +328,7 @@ def start_backup_job(self): def parseBackupLabelFile(self): try: - labelFile = open(self.labelFileName, "rb") + labelFile = open(self.labelFileName, "r") except: bareosfd.JobMessage( M_ERROR, @@ -368,7 +368,7 @@ def start_backup_file(self, savepkt): savepkt.object_name = savepkt.fname bareosfd.DebugMessage(150, "fname: " + savepkt.fname + "\n") bareosfd.DebugMessage(150, "rop " + str(self.rop_data) + "\n") - savepkt.object = bytearray(json.dumps(self.rop_data)) + savepkt.object = bytearray(json.dumps(self.rop_data),"utf-8") savepkt.object_len = len(savepkt.object) savepkt.object_index = int(time.time()) else: diff --git a/systemtests/tests/pyplug-fd-postgres/testrunner b/systemtests/tests/pyplug-fd-postgres/testrunner index e93ecfdc566..59472c27c99 100755 --- a/systemtests/tests/pyplug-fd-postgres/testrunner +++ b/systemtests/tests/pyplug-fd-postgres/testrunner @@ -1,9 +1,6 @@ #!/bin/bash set -e set -u -# -set -e -set -u # This systemtest tests the plugin functionality # of the Bareos FD by using the supplied module # bareos-fd-postgres From eb1b0eed357207f92873474e29bf14b47d722f4e Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 27 May 2020 07:58:57 +0200 Subject: [PATCH 159/341] ovirt plugin: first try to port to python3 --- .../filed/python/ovirt/BareosFdPluginOvirt.py | 228 +++++++++--------- .../filed/python/ovirt/bareos-fd-ovirt.py | 4 +- 2 files changed, 112 insertions(+), 120 deletions(-) diff --git a/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py b/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py index 98083a10a9d..3433cb200e4 100644 --- a/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py +++ b/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py @@ -3,15 +3,7 @@ # Bareos python class for Ovirt related backup and restore import bareosfd -from bareos_fd_consts import ( - bJobMessageType, - bFileType, - bRCs, - bIOPS, - bEventType, - bVariable, - bCFs, -) +from bareosfd import * import os import io @@ -22,7 +14,7 @@ import lxml.etree -import logging + import ovirtsdk4 as sdk import ovirtsdk4.types as types @@ -78,10 +70,10 @@ def parse_plugin_definition(self, plugindef): config_file = self.options.get("config_file") if config_file: if not self.parse_config_file(context): - return bRCs["bRC_Error"] + return bRC_Error self.ovirt.set_options(self.options) - return bRCs["bRC_OK"] + return bRC_OK def check_options(self, mandatory_options=None): """ @@ -92,7 +84,7 @@ def check_options(self, mandatory_options=None): may make more sense to invoke the options checking from start_backup_job() and start_restore_job() """ - return bRCs["bRC_OK"] + return bRC_OK def start_backup_job(self): """ @@ -105,14 +97,14 @@ def start_backup_job(self): if chr(self.level) != "F": bareosfd.JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "BareosFdPluginOvirt can only perform level F (Full) backups, but level is %s\n" % (chr(self.level)), ) - return bRCs["bRC_Error"] + return bRC_Error if not self.ovirt.connect_api(context): - return bRCs["bRC_Error"] + return bRC_Error return self.ovirt.prepare_vm_backup(context) @@ -126,10 +118,10 @@ def start_backup_file(self, savepkt): if not self.ovirt.backup_objects: bareosfd.JobMessage( - bJobMessageType["M_ERROR"], "Nothing to backup.\n" + M_ERROR, "Nothing to backup.\n" ) self.backup_obj = None - return bRCs["bRC_Skip"] + return bRC_Skip self.backup_obj = self.ovirt.backup_objects.pop(0) @@ -148,7 +140,7 @@ def start_backup_file(self, savepkt): % (vmfile["filename"], self.backup_obj["vmname"]), ) - savepkt.type = bFileType["FT_REG"] + savepkt.type = FT_REG savepkt.fname = "/VMS/%s-%s/%s" % ( self.backup_obj["vmname"], self.backup_obj["vmid"], @@ -169,7 +161,7 @@ def start_backup_file(self, savepkt): % (disk.alias, disk.id, snapshot.id, self.backup_obj["vmname"]), ) - savepkt.type = bFileType["FT_REG"] + savepkt.type = FT_REG savepkt.fname = "/VMS/%s-%s/%s-%s/%s" % ( self.backup_obj["vmname"], self.backup_obj["vmid"], @@ -182,11 +174,11 @@ def start_backup_file(self, savepkt): self.ovirt.start_download(snapshot, disk) except Exception as e: bareosfd.JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, "BareosFdPluginOvirt:start_backup_file() Error: %s" % str(e), ) self.ovirt.end_transfer(context) - return bRCs["bRC_Error"] + return bRC_Error elif "disk_metadata" in self.backup_obj: # save disk metadata as restoreobject @@ -210,7 +202,7 @@ def start_backup_file(self, savepkt): ), ) - savepkt.type = bFileType["FT_RESTORE_FIRST"] + savepkt.type = FT_RESTORE_FIRST savepkt.fname = "/VMS/%s-%s/%s-%s/%s.metadata" % ( self.backup_obj["vmname"], self.backup_obj["vmid"], @@ -225,18 +217,18 @@ def start_backup_file(self, savepkt): else: bareosfd.JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "BareosFdPluginOvirt:start_backup_file(): Invalid data in backup_obj, keys: %s\n" % (self.backup_obj.keys()), ) - return bRCs["bRC_Error"] + return bRC_Error bareosfd.JobMessage( - bJobMessageType["M_INFO"], + M_INFO, "Starting backup of %s\n" % savepkt.fname, ) - return bRCs["bRC_OK"] + returnbRC_OK def create_file(self, restorepkt): """ @@ -264,12 +256,12 @@ def create_file(self, restorepkt): ) if not self.ovirt.is_disk_alias_included(disk_alias): - restorepkt.create_status = bCFs["CF_SKIP"] - return bRCs["bRC_OK"] + restorepkt.create_status =CF_SKIP + returnbRC_OK if self.ovirt.is_disk_alias_excluded(disk_alias): - restorepkt.create_status = bCFs["CF_SKIP"] - return bRCs["bRC_OK"] + restorepkt.create_status = CF_SKIP + return bRC_OK if self.options.get("local") == "yes": FNAME = restorepkt.ofname @@ -285,7 +277,7 @@ def create_file(self, restorepkt): # But: only do this for regular files, prevent from # IOError: (21, 'Is a directory', '/tmp/bareos-restores/my/dir/') # if it's a directory - if restorepkt.type == bFileType["FT_REG"]: + if restorepkt.type == FT_REG: open(FNAME, "wb").close() else: if not restorepkt.ofname.endswith(".ovf"): @@ -295,17 +287,17 @@ def create_file(self, restorepkt): disk = self.ovirt.get_vm_disk_by_basename(FNAME) if disk is None: bareosfd.JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, "BareosFdPluginOvirt:create_file() Unable to restore disk %s.\n" % (FNAME), ) - return bRCs["bRC_Error"] + return bRC_Error else: self.ovirt.start_upload(disk) - if restorepkt.type == bFileType["FT_REG"]: - restorepkt.create_status = bCFs["CF_EXTRACT"] - return bRCs["bRC_OK"] + if restorepkt.type == FT_REG: + restorepkt.create_status = CF_EXTRACT + return bRC_OK def start_restore_job(self): """ @@ -320,20 +312,20 @@ def start_restore_job(self): 100, "BareosFdPluginOvirt:start_restore_job(): restore to local file, skipping checks\n", ) - return bRCs["bRC_OK"] + return bRC_OK else: # restore to VM to OVirt if not self.ovirt.connect_api(context): - return bRCs["bRC_Error"] + return bRC_Error - return bRCs["bRC_OK"] + return bRC_OK def start_restore_file(self, cmd): bareosfd.DebugMessage( 100, "BareosFdPluginOvirt:start_restore_file() called with %s\n" % (cmd), ) - return bRCs["bRC_OK"] + return bRC_OK def plugin_io(self, IOP): """ @@ -349,7 +341,7 @@ def plugin_io(self, IOP): "BareosFdPluginOvirt::plugin_io() jobType: %s\n" % (self.jobType), ) - if IOP.func == bIOPS["IO_OPEN"]: + if IOP.func == IO_OPEN: self.FNAME = IOP.fname bareosfd.DebugMessage( @@ -376,10 +368,10 @@ def plugin_io(self, IOP): else: IOP.status = -1 bareosfd.JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "plugin_io: option local=yes can only be used on restore\n", ) - return bRCs["bRC_Error"] + return bRC_Error except (OSError, IOError) as io_open_error: IOP.status = -1 bareosfd.DebugMessage( @@ -388,15 +380,15 @@ def plugin_io(self, IOP): % (self.FNAME, io_open_error.strerror), ) bareosfd.JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "plugin_io: failed to open %s: %s\n" % (self.FNAME, io_open_error.strerror), ) - return bRCs["bRC_Error"] + return bRC_Error - return bRCs["bRC_OK"] + return bRC_OK - elif IOP.func == bIOPS["IO_CLOSE"]: + elif IOP.func == IO_CLOSE: if self.file is not None: bareosfd.DebugMessage(100, "Closing file " + "\n") self.file.close() @@ -414,10 +406,10 @@ def plugin_io(self, IOP): return self.ovirt.prepare_vm_restore(context) else: self.ovirt.end_transfer(context) - return bRCs["bRC_OK"] - elif IOP.func == bIOPS["IO_SEEK"]: - return bRCs["bRC_OK"] - elif IOP.func == bIOPS["IO_READ"]: + return bRC_OK + elif IOP.func == IO_SEEK: + return bRC_OK + elif IOP.func == IO_READ: if "file" in self.backup_obj: IOP.buf = bytearray(IOP.count) IOP.status = self.backup_obj["file"]["fh"].readinto(IOP.buf) @@ -440,19 +432,19 @@ def plugin_io(self, IOP): IOP.io_errno = 0 except Exception as e: bareosfd.JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, "BareosFdPluginOvirt:plugin_io() Error: %s" % str(e), ) self.ovirt.end_transfer(context) - return bRCs["bRC_Error"] + return bRC_Error else: bareosfd.JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, "BareosFdPluginOvirt:plugin_io() Unable to read data to backup.", ) - return bRCs["bRC_Error"] - return bRCs["bRC_OK"] - elif IOP.func == bIOPS["IO_WRITE"]: + return bRC_Error + return bRC_OK + elif IOP.func == IO_WRITE: if self.file is not None: try: bareosfd.DebugMessage( @@ -466,7 +458,7 @@ def plugin_io(self, IOP): bareosfd.DebugMessage( 100, "Error writing data: " + msg + "\n" ) - return bRCs["bRC_Error"] + return bRC_Error elif self.FNAME.endswith(".ovf"): self.ovirt.process_ovf(IOP.buf) IOP.status = IOP.count @@ -475,11 +467,11 @@ def plugin_io(self, IOP): self.ovirt.process_upload(IOP.buf) IOP.status = IOP.count IOP.io_errno = 0 - return bRCs["bRC_OK"] + return bRC_OK def handle_plugin_event(self, event): - if event == bEventType["bEventEndBackupJob"]: + if event == bEventEndBackupJob: bareosfd.DebugMessage( 100, "BareosFdPluginOvirt::handle_plugin_event() called with bEventEndBackupJob\n", @@ -487,13 +479,13 @@ def handle_plugin_event(self, event): bareosfd.DebugMessage(100, "removing Snapshot\n") self.ovirt.end_vm_backup(context) - elif event == bEventType["bEventEndFileSet"]: + elif event == bEventEndFileSet: bareosfd.DebugMessage( 100, "BareosFdPluginOvirt::handle_plugin_event() called with bEventEndFileSet\n", ) - elif event == bEventType["bEventStartBackupJob"]: + elif event == bEventStartBackupJob: bareosfd.DebugMessage( 100, "BareosFdPluginOvirt::handle_plugin_event() called with bEventStartBackupJob\n", @@ -501,7 +493,7 @@ def handle_plugin_event(self, event): return self.start_backup_job(context) - elif event == bEventType["bEventStartRestoreJob"]: + elif event == bEventStartRestoreJob: bareosfd.DebugMessage( 100, "BareosFdPluginOvirt::handle_plugin_event() called with bEventStartRestoreJob\n", @@ -509,7 +501,7 @@ def handle_plugin_event(self, event): return self.start_restore_job(context) - elif event == bEventType["bEventEndRestoreJob"]: + elif event == bEventEndRestoreJob: bareosfd.DebugMessage( 100, "BareosFdPluginOvirt::handle_plugin_event() called with bEventEndRestoreJob\n", @@ -523,7 +515,7 @@ def handle_plugin_event(self, event): % (event), ) - return bRCs["bRC_OK"] + return bRC_OK def end_backup_file(self): bareosfd.DebugMessage( @@ -536,16 +528,16 @@ def end_backup_file(self): self.ovirt.init_bytes_to_transf / 1000.0 / elapsed_seconds, 1 ) bareosfd.JobMessage( - bJobMessageType["M_INFO"], + M_INFO, " Transfer time: %s s bytes: %s rate: %s KB/s\n" % (elapsed_seconds, self.ovirt.init_bytes_to_transf, download_rate), ) self.ovirt.transfer_start_time = None if self.ovirt.backup_objects: - return bRCs["bRC_More"] + return bRC_More else: - return bRCs["bRC_OK"] + return bRC_OK def end_restore_file(self): bareosfd.DebugMessage( @@ -558,12 +550,12 @@ def end_restore_file(self): self.ovirt.init_bytes_to_transf / 1000.0 / elapsed_seconds, 1 ) bareosfd.JobMessage( - bJobMessageType["M_INFO"], + M_INFO, " Upload time: %s s bytes: %s rate: %s KB/s\n" % (elapsed_seconds, self.ovirt.init_bytes_to_transf, download_rate), ) self.ovirt.transfer_start_time = None - return bRCs["bRC_OK"] + return bRC_OK def restore_object_data(self, ROP): """ @@ -604,7 +596,7 @@ def restore_object_data(self, ROP): "disk_metadata" ] - return bRCs["bRC_OK"] + return bRC_OK def parse_config_file(self): """ @@ -622,7 +614,7 @@ def parse_config_file(self): self.config.readfp(open(self.options["config_file"])) except IOError as err: bareosfd.JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "BareosFdPluginOvirt: Error reading config file %s: %s\n" % (self.options["config_file"], err.strerror), ) @@ -643,7 +635,7 @@ def check_config(self): for section in mandatory_sections: if not self.config.has_section(section): bareosfd.JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "BareosFdPluginOvirt: Section [%s] missing in config file %s\n" % (section, self.options["config_file"]), ) @@ -652,7 +644,7 @@ def check_config(self): for option in mandatory_options[section]: if not self.config.has_option(section, option): bareosfd.JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "BareosFdPluginOvirt: Options %s missing in Section [%s] in config file %s\n" % (option, section, self.options["config_file"]), ) @@ -661,7 +653,7 @@ def check_config(self): plugin_option = self.options.get(option) if plugin_option: bareosfd.JobMessage( - bJobMessageType["M_WARNING"], + M_WARNING, "BareosFdPluginOvirt: Overriding plugin option %s from config file %s\n" % (option, self.options["config_file"]), ) @@ -742,7 +734,7 @@ def connect_api(self): if not self.connection: bareosfd.JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "Cannot connect to host %s with user %s and ca file %s\n" % (self.options["server"], self.options["username"], self.ca), ) @@ -796,7 +788,7 @@ def prepare_vm_backup(self): if not self.get_vm(context): bareosfd.DebugMessage(100, "Error getting details for VM\n") - return bRCs["bRC_Error"] + return bRC_Error else: # Locate the service that manages the virtual machine: self.vm_service = self.vms_service.vm_service(self.vm.id) @@ -805,11 +797,11 @@ def prepare_vm_backup(self): snaps_service = self.vm_service.snapshots_service() if len(snaps_service.list()) > 1: bareosfd.JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "Error '%s' already have snapshosts. This is not supported\n" % (self.vm.name), ) - return bRCs["bRC_Error"] + return bRC_Error bareosfd.DebugMessage( 100, "Start the backup of VM %s\n" % (self.vm.name) @@ -838,12 +830,12 @@ def prepare_vm_backup(self): # get vm backup disks from snapshot if not self.all_disks_excluded and not self.get_vm_backup_disks(context): bareosfd.JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "Error getting Backup Disks VM %s from snapshot\n" % (self.vm.name), ) - return bRCs["bRC_Error"] + return bRC_Error - return bRCs["bRC_OK"] + return bRC_OK def get_vm(self): search = None @@ -903,7 +895,7 @@ def create_vm_snapshot(self): ), ) bareosfd.JobMessage( - bJobMessageType["M_INFO"], + M_INFO, "Sent request to create snapshot '%s', the id is '%s'.\n" % (snap.description, snap.id), ) @@ -925,7 +917,7 @@ def create_vm_snapshot(self): time.sleep(10) bareosfd.JobMessage( - bJobMessageType["M_INFO"], "' The snapshot is now complete.\n" + M_INFO, "' The snapshot is now complete.\n" ) def get_vm_disks_for_snapshot(self): @@ -950,7 +942,7 @@ def get_vm_disks_for_snapshot(self): # included_disks = (types.DiskAttachment(),) self.all_disks_excluded = True bareosfd.JobMessage( - bJobMessageType["M_INFO"], + M_INFO, "All disks excluded, only backing up VM configuration.\n", ) included_disks = [types.DiskAttachment()] @@ -1027,7 +1019,7 @@ def is_disk_alias_included(self, disk_alias): include_disk_aliases = self.options["include_disk_aliases"].split(",") if disk_alias in include_disk_aliases: bareosfd.JobMessage( - bJobMessageType["M_INFO"], + M_INFO, "Including disk with alias %s\n" % (disk_alias), ) return True @@ -1042,7 +1034,7 @@ def is_disk_alias_excluded(self, disk_alias): if "*" in exclude_disk_aliases or disk_alias in exclude_disk_aliases: bareosfd.JobMessage( - bJobMessageType["M_INFO"], + M_INFO, "Excluding disk with alias %s\n" % (disk_alias), ) return True @@ -1080,7 +1072,7 @@ def get_proxy_connection(self, proxy_url): def start_download(self, snapshot, disk): bareosfd.JobMessage( - bJobMessageType["M_INFO"], + M_INFO, "Downloading snapshot '%s' of disk '%s'('%s')\n" % (snapshot.id, disk.alias, disk.id), ) @@ -1106,7 +1098,7 @@ def start_download(self, snapshot, disk): # Check the response status: if self.response.status >= 300: bareosfd.JobMessage( - bJobMessageType["M_ERROR"], "Error: %s" % self.response.read() + M_ERROR, "Error: %s" % self.response.read() ) self.bytes_to_transf = int(self.response.getheader("Content-Length")) @@ -1126,7 +1118,7 @@ def start_download(self, snapshot, disk): ) bareosfd.JobMessage( - bJobMessageType["M_INFO"], + M_INFO, " Transfer disk snapshot of %s bytes\n" % (str(self.bytes_to_transf)), ) @@ -1160,7 +1152,7 @@ def process_download(self, chunk_size): 100, "process_download(): Socket disconnected. \n" ) bareosfd.JobMessage( - bJobMessageType["M_ERROR"], + M_ERROR, "process_download(): Socket disconnected.", ) @@ -1184,21 +1176,21 @@ def prepare_vm_restore(self): if self.connection is None: # if not connected yet if not self.connect_api(context): - return bRCs["bRC_Error"] + return bRC_Error if self.ovf_data is None: bareosfd.JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "Unable to restore VM. No OVF data. \n", ) - return bRCs["bRC_Error"] + return bRC_Error else: if "storage_domain" not in self.options: bareosfd.JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "No storage domain specified.\n", ) - return bRCs["bRC_Error"] + return bRC_Error storage_domain = self.options["storage_domain"] @@ -1232,33 +1224,33 @@ def prepare_vm_restore(self): ) if len(res) > 1: bareosfd.JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "Found %s VMs with name '%s'\n" % (len(res), str(vm_name)), ) - return bRCs["bRC_Error"] + return bRC_Error if len(res) == 1: if not self.options.get("overwrite") == "yes": bareosfd.JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "If you are sure you want to overwrite the existing VM '%s', please add the plugin option 'overwrite=yes'\n" % (str(vm_name)), ) - return bRCs["bRC_Error"] + return bRC_Error bareosfd.JobMessage( - bJobMessageType["M_INFO"], + M_INFO, "Restore to existing VM '%s'\n" % str(vm_name), ) self.vm = res[0] if self.vm.status != types.VmStatus.DOWN: bareosfd.JobMessage( - bJobMessageType["M_FATAL"], + M_FATAL, "VM '%s' must be down for restore, but status is %s\n" % (str(vm_name), self.vm.status), ) - return bRCs["bRC_Error"] + return bRC_Error restore_existing_vm = True @@ -1302,7 +1294,7 @@ def prepare_vm_restore(self): % (self.restore_objects, self.old_new_ids), ) - return bRCs["bRC_OK"] + return bRC_OK def create_vm(self, vm_name, cluster_name): @@ -1313,7 +1305,7 @@ def create_vm(self, vm_name, cluster_name): # Add the virtual machine, the transferred disks will be # attached to this virtual machine: bareosfd.JobMessage( - bJobMessageType["M_INFO"], "Adding virtual machine %s\n" % vm_name + M_INFO, "Adding virtual machine %s\n" % vm_name ) # vm type (server/desktop) @@ -1419,7 +1411,7 @@ def add_nics_to_vm(self): network = props["Connection"] if network not in self.network_profiles: bareosfd.JobMessage( - bJobMessageType["M_WARNING"], + M_WARNING, "No network profile found for '%s'\n" % (network), ) else: @@ -1503,7 +1495,7 @@ def get_vm_disk_by_basename(self, fname): found = disk else: bareosfd.JobMessage( - bJobMessageType["M_WARNING"], + M_WARNING, "The backup have snapshots and only base will be restored\n", ) @@ -1520,7 +1512,7 @@ def get_or_add_vm_disk(self, obj, disk_id=None): disk = None if "storage_domain" not in obj: bareosfd.JobMessage( - bJobMessageType["M_FATAL"], "No storage domain specified.\n" + M_FATAL, "No storage domain specified.\n" ) else: storage_domain = obj["storage_domain"] @@ -1608,7 +1600,7 @@ def get_or_add_vm_disk(self, obj, disk_id=None): def start_upload(self, disk): bareosfd.JobMessage( - bJobMessageType["M_INFO"], + M_INFO, "Uploading disk '%s'('%s')\n" % (disk.alias, disk.id), ) bareosfd.DebugMessage( @@ -1652,7 +1644,7 @@ def start_upload(self, disk): self.proxy_connection.endheaders() bareosfd.JobMessage( - bJobMessageType["M_INFO"], + M_INFO, " Upload disk of %s bytes\n" % (str(self.bytes_to_transf)), ) self.transfer_start_time = time.time() @@ -1699,7 +1691,7 @@ def end_vm_backup(self): snapshot_deleted_success = False bareosfd.JobMessage( - bJobMessageType["M_INFO"], + M_INFO, "Sending request to remove snapshot '%s', the id is '%s'.\n" % (snap.description, snap.id), ) @@ -1714,11 +1706,11 @@ def end_vm_backup(self): elapsed = int(time.time()) - t_start if elapsed >= self.snapshot_remove_timeout: bareosfd.JobMessage( - bJobMessageType["M_WARNING"], + M_WARNING, "Remove snapshot timed out after %s s, reason: %s! Please remove it manually.\n" % (elapsed, e.message), ) - return bRCs["bRC_Error"] + return bRC_Error bareosfd.DebugMessage( 100, @@ -1726,17 +1718,17 @@ def end_vm_backup(self): % (e.message, self.snapshot_remove_timeout - elapsed), ) bareosfd.JobMessage( - bJobMessageType["M_INFO"], + M_INFO, "Still waiting for snapshot removal, retrying until timeout (%s seconds left).\n" % (self.snapshot_remove_timeout - elapsed), ) else: bareosfd.JobMessage( - bJobMessageType["M_WARNING"], + M_WARNING, "Unexpected error removing snapshot: %s, Please remove it manually.\n" % e.message, ) - return bRCs["bRC_Error"] + return bRC_Error if self.wait_for_snapshot_removal(snap.id): snapshot_deleted_success = True @@ -1747,7 +1739,7 @@ def end_vm_backup(self): if snapshot_deleted_success: bareosfd.JobMessage( - bJobMessageType["M_INFO"], + M_INFO, "Removed the snapshot '%s'.\n" % snap.description, ) diff --git a/core/src/plugins/filed/python/ovirt/bareos-fd-ovirt.py b/core/src/plugins/filed/python/ovirt/bareos-fd-ovirt.py index 93a6fd4eae0..27216accd9d 100644 --- a/core/src/plugins/filed/python/ovirt/bareos-fd-ovirt.py +++ b/core/src/plugins/filed/python/ovirt/bareos-fd-ovirt.py @@ -7,7 +7,7 @@ sys.path.extend([l for l in libdirs if os.path.isdir(l)]) # Provided by the Bareos FD Python plugin interface -from bareos_fd_consts import bRCs +from bareosfd import * # This module contains the wrapper functions called by the Bareos-FD, the # functions call the corresponding @@ -46,7 +46,7 @@ def load_bareos_plugin(plugindef): plugindef ) - return bRCs["bRC_OK"] + return bRC_OK # the rest is done in the Plugin module From fefc2b808c403ecd17a4c39c000f0df23da6030d Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 27 May 2020 11:52:04 +0200 Subject: [PATCH 160/341] ovirt: make python3 compatible --- .../filed/python/ovirt/BareosFdPluginOvirt.py | 60 +++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py b/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py index 3433cb200e4..a4c77825d90 100644 --- a/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py +++ b/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py @@ -10,7 +10,12 @@ import time import uuid import json -import ConfigParser as configparser +try: + from configparser import ConfigParser +except ImportError: + from ConfigParser import SafeConfigParser as ConfigParser + +#import ConfigParser as configparser import lxml.etree @@ -20,7 +25,10 @@ import ssl -from httplib import HTTPSConnection +try: + from httplib import HTTPSConnection +except ImportError: + from http.client import HTTPSConnection try: from urllib.parse import urlparse @@ -29,6 +37,8 @@ import BareosFdPluginBaseclass +import logging + # The name of the application, to be used as the 'origin' of events # sent to the audit log: APPLICATION_NAME = "Bareos oVirt plugin" @@ -69,7 +79,7 @@ def parse_plugin_definition(self, plugindef): # if the option config_file is present, parse the given file config_file = self.options.get("config_file") if config_file: - if not self.parse_config_file(context): + if not self.parse_config_file(): return bRC_Error self.ovirt.set_options(self.options) @@ -103,10 +113,10 @@ def start_backup_job(self): ) return bRC_Error - if not self.ovirt.connect_api(context): + if not self.ovirt.connect_api(): return bRC_Error - return self.ovirt.prepare_vm_backup(context) + return self.ovirt.prepare_vm_backup() def start_backup_file(self, savepkt): """ @@ -146,7 +156,7 @@ def start_backup_file(self, savepkt): self.backup_obj["vmid"], vmfile["filename"], ) - self.backup_obj["file"]["fh"] = io.BytesIO(vmfile["data"]) + self.backup_obj["file"]["fh"] = io.BytesIO(vmfile["data"].encode('utf-8')) elif "disk" in self.backup_obj: @@ -177,7 +187,7 @@ def start_backup_file(self, savepkt): M_ERROR, "BareosFdPluginOvirt:start_backup_file() Error: %s" % str(e), ) - self.ovirt.end_transfer(context) + self.ovirt.end_transfer() return bRC_Error elif "disk_metadata" in self.backup_obj: @@ -228,7 +238,7 @@ def start_backup_file(self, savepkt): "Starting backup of %s\n" % savepkt.fname, ) - returnbRC_OK + return bRC_OK def create_file(self, restorepkt): """ @@ -315,7 +325,7 @@ def start_restore_job(self): return bRC_OK else: # restore to VM to OVirt - if not self.ovirt.connect_api(context): + if not self.ovirt.connect_api(): return bRC_Error return bRC_OK @@ -335,7 +345,7 @@ def plugin_io(self, IOP): 100, "plugin_io called with function %s\n" % (IOP.func) ) bareosfd.DebugMessage(100, "FNAME is set to %s\n" % (self.FNAME)) - self.jobType = chr(bareosfd.GetValue(bVariable["bVarType"])) + self.jobType = chr(bareosfd.GetValue(bareosfd.bVarType)) bareosfd.DebugMessage( 100, "BareosFdPluginOvirt::plugin_io() jobType: %s\n" % (self.jobType), @@ -400,12 +410,12 @@ def plugin_io(self, IOP): 100, "plugin_io: calling end_transfer()\n" ) # Backup Job - self.ovirt.end_transfer(context) + self.ovirt.end_transfer() elif self.jobType == "R": if self.FNAME.endswith(".ovf"): - return self.ovirt.prepare_vm_restore(context) + return self.ovirt.prepare_vm_restore() else: - self.ovirt.end_transfer(context) + self.ovirt.end_transfer() return bRC_OK elif IOP.func == IO_SEEK: return bRC_OK @@ -435,7 +445,7 @@ def plugin_io(self, IOP): M_ERROR, "BareosFdPluginOvirt:plugin_io() Error: %s" % str(e), ) - self.ovirt.end_transfer(context) + self.ovirt.end_transfer() return bRC_Error else: bareosfd.JobMessage( @@ -477,7 +487,7 @@ def handle_plugin_event(self, event): "BareosFdPluginOvirt::handle_plugin_event() called with bEventEndBackupJob\n", ) bareosfd.DebugMessage(100, "removing Snapshot\n") - self.ovirt.end_vm_backup(context) + self.ovirt.end_vm_backup() elif event == bEventEndFileSet: bareosfd.DebugMessage( @@ -491,7 +501,7 @@ def handle_plugin_event(self, event): "BareosFdPluginOvirt::handle_plugin_event() called with bEventStartBackupJob\n", ) - return self.start_backup_job(context) + return self.start_backup_job() elif event == bEventStartRestoreJob: bareosfd.DebugMessage( @@ -499,7 +509,7 @@ def handle_plugin_event(self, event): "BareosFdPluginOvirt::handle_plugin_event() called with bEventStartRestoreJob\n", ) - return self.start_restore_job(context) + return self.start_restore_job() elif event == bEventEndRestoreJob: bareosfd.DebugMessage( @@ -507,7 +517,7 @@ def handle_plugin_event(self, event): "BareosFdPluginOvirt::handle_plugin_event() called with bEventEndRestoreJob\n", ) bareosfd.DebugMessage(100, "removing Snapshot\n") - self.ovirt.end_vm_restore(context) + self.ovirt.end_vm_restore() else: bareosfd.DebugMessage( 100, @@ -620,7 +630,7 @@ def parse_config_file(self): ) return False - return self.check_config(context) + return self.check_config() def check_config(self): """ @@ -785,7 +795,7 @@ def prepare_vm_backup(self): "BareosOvirtWrapper::prepare_vm_backup: prepare VM to backup\n", ) - if not self.get_vm(context): + if not self.get_vm(): bareosfd.DebugMessage(100, "Error getting details for VM\n") return bRC_Error @@ -825,10 +835,10 @@ def prepare_vm_backup(self): ) # create vm snapshots - self.create_vm_snapshot(context) + self.create_vm_snapshot() # get vm backup disks from snapshot - if not self.all_disks_excluded and not self.get_vm_backup_disks(context): + if not self.all_disks_excluded and not self.get_vm_backup_disks(): bareosfd.JobMessage( M_FATAL, "Error getting Backup Disks VM %s from snapshot\n" % (self.vm.name), @@ -891,7 +901,7 @@ def create_vm_snapshot(self): snapshot=types.Snapshot( description=snap_description, persist_memorystate=False, - disk_attachments=self.get_vm_disks_for_snapshot(context), + disk_attachments=self.get_vm_disks_for_snapshot(), ), ) bareosfd.JobMessage( @@ -1175,7 +1185,7 @@ def prepare_vm_restore(self): restore_existing_vm = False if self.connection is None: # if not connected yet - if not self.connect_api(context): + if not self.connect_api(): return bRC_Error if self.ovf_data is None: @@ -1256,7 +1266,7 @@ def prepare_vm_restore(self): else: self.create_vm(vm_name, cluster_name) - self.add_nics_to_vm(context) + self.add_nics_to_vm() # Extract disk information from OVF disk_elements = self.ovf.get_elements("disk_elements") From 7f3db68ca0269ca57d063037a83ead404dddf363 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 27 May 2020 12:43:32 +0200 Subject: [PATCH 161/341] python3: convert e.message -> e --- .../filed/python/ovirt/BareosFdPluginOvirt.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py b/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py index a4c77825d90..91ff4a6e31d 100644 --- a/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py +++ b/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py @@ -803,13 +803,13 @@ def prepare_vm_backup(self): # Locate the service that manages the virtual machine: self.vm_service = self.vms_service.vm_service(self.vm.id) - # check if vm have snapshosts + # check if vm have snapshots snaps_service = self.vm_service.snapshots_service() if len(snaps_service.list()) > 1: bareosfd.JobMessage( M_FATAL, - "Error '%s' already have snapshosts. This is not supported\n" - % (self.vm.name), + "Error '%s' already has %d snapshots. This is not supported\n" + % (self.vm.name, len(snaps_service.list())), ) return bRC_Error @@ -982,7 +982,7 @@ def get_vm_backup_disks(self): snap_disks_service = self.snap_service.disks_service() snap_disks = snap_disks_service.list() - # download disk snaphost + # download disk snapshot for snap_disk in snap_disks: disk_id = snap_disk.id disk_alias = snap_disk.alias @@ -1718,14 +1718,14 @@ def end_vm_backup(self): bareosfd.JobMessage( M_WARNING, "Remove snapshot timed out after %s s, reason: %s! Please remove it manually.\n" - % (elapsed, e.message), + % (elapsed, e), ) return bRC_Error bareosfd.DebugMessage( 100, "Could not remove snapshot, reason: %s, retrying until timeout (%s seconds left).\n" - % (e.message, self.snapshot_remove_timeout - elapsed), + % (e, self.snapshot_remove_timeout - elapsed), ) bareosfd.JobMessage( M_INFO, @@ -1736,7 +1736,7 @@ def end_vm_backup(self): bareosfd.JobMessage( M_WARNING, "Unexpected error removing snapshot: %s, Please remove it manually.\n" - % e.message, + % e, ) return bRC_Error From dd56ab1d0de51f8bed55976107ec7e4f4b5caebf Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 27 May 2020 13:02:04 +0200 Subject: [PATCH 162/341] ovirt: change to xml from lxml lxml throws 'Interpreter change detected - this module can only be loaded into one interpreter per process' --- core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py b/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py index 91ff4a6e31d..16bbdecc134 100644 --- a/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py +++ b/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py @@ -17,7 +17,7 @@ #import ConfigParser as configparser -import lxml.etree +import xml.etree import ovirtsdk4 as sdk @@ -1843,7 +1843,7 @@ def __init__(self, ovf_data=None): """ # Parse the OVF as XML document: - self.ovf = lxml.etree.fromstring(ovf_data) + self.ovf = xml.etree.fromstring(ovf_data) def get_element(self, element_name): """ From 8ffe34f42bcdab2a4ff9d096a7c8687ec9251346 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 27 May 2020 13:27:51 +0200 Subject: [PATCH 163/341] ovirt: add \n when error happens --- core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py b/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py index 16bbdecc134..a2135c5a15e 100644 --- a/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py +++ b/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py @@ -185,7 +185,7 @@ def start_backup_file(self, savepkt): except Exception as e: bareosfd.JobMessage( M_ERROR, - "BareosFdPluginOvirt:start_backup_file() Error: %s" % str(e), + "BareosFdPluginOvirt:start_backup_file() Error: %s\n" % str(e), ) self.ovirt.end_transfer() return bRC_Error From 3eaaa8479d6e322eedd4c6fc9f55b359af855874 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 27 May 2020 17:39:26 +0200 Subject: [PATCH 164/341] postgres plugin: also work on psql 12 --- .../bareos-dir.d/fileset/PluginTest.conf.in | 2 +- .../tests/pyplug-fd-postgres/testrunner | 11 ++- .../database/setup_local_db.sh | 67 +++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100755 systemtests/tests/python-fd-plugin-postgres-test/database/setup_local_db.sh diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in index e4be9984ebb..938fb09486a 100644 --- a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in +++ b/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in @@ -5,6 +5,6 @@ FileSet { Options { signature = MD5 } - Plugin = "@python_version@:module_path=@current_test_directory@/python-modules:module_name=bareos-fd-postgres:dbHost=@current_test_directory@/database/tmp:postgresDataDir=@current_test_directory@/database/data:walArchive=@current_test_directory@/database/wal_archive/" + Plugin = "@python_version@:module_path=@current_test_directory@/python-modules:module_name=bareos-fd-postgres:dbHost=@current_test_directory@/tmp:postgresDataDir=@current_test_directory@/database/data:walArchive=@current_test_directory@/database/wal_archive/" } } diff --git a/systemtests/tests/pyplug-fd-postgres/testrunner b/systemtests/tests/pyplug-fd-postgres/testrunner index 59472c27c99..f96e54ca9a5 100755 --- a/systemtests/tests/pyplug-fd-postgres/testrunner +++ b/systemtests/tests/pyplug-fd-postgres/testrunner @@ -18,7 +18,7 @@ JobName=backup-bareos-fd # setup local database server DBNAME="backuptest" -TESTPGHOST="/tmp/${TestName}" +TESTPGHOST="${current_test_directory}/tmp" PSQL="psql --host $TESTPGHOST" [ -d "$TESTPGHOST" ] && rm -R "$TESTPGHOST" @@ -41,7 +41,11 @@ CREATE TABLE t(id serial PRIMARY KEY, text VARCHAR(20), created_on TIMESTAMP); INSERT INTO t (text, created_on) values ('test for FULL backup', current_timestamp); SELECT * FROM t; " +<<<<<<< HEAD:systemtests/tests/pyplug-fd-postgres/testrunner PSQL_VERSION=$(${PSQL} -qtAX ${DBNAME} <<< "SHOW server_version;" | sed 's/\..*//g') +======= +PSQL_VERSION=$(${PSQL} -qtAX ${DBNAME} <<< "SHOW server_version;") +>>>>>>> d3ff81156... fix postgres to also work on psql 12:systemtests/tests/python-fd-plugin-postgres-test/testrunner start_test @@ -83,6 +87,11 @@ pushd database/ > /dev/null local_db_stop_server "$TESTPGHOST" rm -Rf data rm -Rf wal_archive +<<<<<<< HEAD:systemtests/tests/pyplug-fd-postgres/testrunner +======= +echo "------------ stopped" + +>>>>>>> d3ff81156... fix postgres to also work on psql 12:systemtests/tests/python-fd-plugin-postgres-test/testrunner popd > /dev/null cat <$tmp/bconcmds diff --git a/systemtests/tests/python-fd-plugin-postgres-test/database/setup_local_db.sh b/systemtests/tests/python-fd-plugin-postgres-test/database/setup_local_db.sh new file mode 100755 index 00000000000..c4bd80d7414 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-postgres-test/database/setup_local_db.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +local_db_stop_server() { + echo "Stop db server" + pg_ctl --silent --pgdata=data stop + tries=10 + while psql --host="$1" --list > /dev/null 2>&1; do + echo " -- $tries -- " + [ $((tries-=1)) -eq 0 ] && { + echo "Could not stop postgres server" + return 1 + } + sleep 0.3 + done +} + +local_db_prepare_files() { + echo "Prepare files" + rm --recursive --force tmp data log wal_archive + mkdir tmp data log wal_archive + LANG= pg_ctl --silent --pgdata=data --log=log/postgres.log initdb + + sed -i.bak "s@#listen_addresses.*@listen_addresses = ''@g" data/postgresql.conf + sed -i.bak "s@#unix_socket_directories.*@unix_socket_directories = \'$1\'@g" data/postgresql.conf + + { + # for online backups we need wal_archiving + echo "wal_level = archive" + echo "archive_mode = on" + echo "archive_command = 'cp %p ../wal_archive'" + echo "max_wal_senders = 10" + } >> data/postgresql.conf +} + +local_db_start_server() { + echo "Start db server" + pg_ctl --silent --pgdata=data --log=log/logfile start + + tries=10 + while ! psql --host="$1" --list > /dev/null 2>&1; do + [ $((tries-=1)) -eq 0 ] && { + echo "Could not start postgres server" + cat log/logfile + cat database/log/*.log + return 1 + } + sleep 0.1 + done + + return 0 +} + +local_db_create_superuser_role() { + echo "CREATE ROLE root WITH SUPERUSER CREATEDB CREATEROLE REPLICATION LOGIN" |psql -h "$1" postgres +} + +setup_local_db() { + local_db_stop_server "$1" + local_db_prepare_files "$1" + if ! local_db_start_server "$1"; then return 1; fi + local_db_create_superuser_role "$1" + + echo stop server with "pg_ctl --pgdata=data stop" + + return 0 +} + From 6ca1de575e8764a1f69294414c503dd7a3483017 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 28 May 2020 09:16:22 +0200 Subject: [PATCH 165/341] ovirt: restore the context too much removed --- core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py b/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py index a2135c5a15e..73fbc7a25af 100644 --- a/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py +++ b/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py @@ -1071,13 +1071,13 @@ def get_proxy_connection(self, proxy_url): # At this stage, the SDK granted the permission to start transferring the disk, and the # user should choose its preferred tool for doing it - regardless of the SDK. # In this example, we will use Python's httplib.HTTPSConnection for transferring the data. - context = ssl.create_default_context() + sslcontext = ssl.create_default_context() # Note that ovirt-imageio-proxy by default checks the certificates, so if you don't have # your CA certificate of the engine in the system, you need to pass it to HTTPSConnection. - context.load_verify_locations(cafile=self.ca) + sslcontext.load_verify_locations(cafile=self.ca) - return HTTPSConnection(proxy_url.hostname, proxy_url.port) + return HTTPSConnection(proxy_url.hostname, proxy_url.port, context = sslcontext) def start_download(self, snapshot, disk): From 0a8ebc62da2ad0005298e8b80e45a335f08299bc Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 28 May 2020 10:43:36 +0200 Subject: [PATCH 166/341] ovirt: python3 compatibility --- .../src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py b/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py index 73fbc7a25af..2e72739e42c 100644 --- a/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py +++ b/core/src/plugins/filed/python/ovirt/BareosFdPluginOvirt.py @@ -221,7 +221,7 @@ def start_backup_file(self, savepkt): snapshot_id, ) savepkt.object_name = savepkt.fname - savepkt.object = bytearray(disk_metadata_json) + savepkt.object = bytearray(disk_metadata_json, 'utf-8') savepkt.object_len = len(savepkt.object) savepkt.object_index = int(time.time()) @@ -443,7 +443,7 @@ def plugin_io(self, IOP): except Exception as e: bareosfd.JobMessage( M_ERROR, - "BareosFdPluginOvirt:plugin_io() Error: %s" % str(e), + "BareosFdPluginOvirt:plugin_io() Error: %s\n" % str(e), ) self.ovirt.end_transfer() return bRC_Error @@ -809,7 +809,7 @@ def prepare_vm_backup(self): bareosfd.JobMessage( M_FATAL, "Error '%s' already has %d snapshots. This is not supported\n" - % (self.vm.name, len(snaps_service.list())), + % (self.vm.name, len(snaps_service.list()) - 1), ) return bRC_Error @@ -1137,7 +1137,7 @@ def start_download(self, snapshot, disk): def process_download(self, chunk_size): - chunk = "" + chunk = b"" bareosfd.DebugMessage( 100, From e23cd4092895d38b6d4b16967f5c5a0d9f81f941 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 29 May 2020 12:16:23 +0200 Subject: [PATCH 167/341] imported PyCapsuleAPI support header from py3 --- core/src/plugins/include/capsulethunk.h | 141 ++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 core/src/plugins/include/capsulethunk.h diff --git a/core/src/plugins/include/capsulethunk.h b/core/src/plugins/include/capsulethunk.h new file mode 100644 index 00000000000..6ad70041334 --- /dev/null +++ b/core/src/plugins/include/capsulethunk.h @@ -0,0 +1,141 @@ +/* Copyright (c) 2011, Larry Hastings + * Copyright (c) 2015, py3c contributors + * Licensed under the MIT license; see py3c.h + * + * (Note: Relicensed from PSF: http://bugs.python.org/issue24937#msg250191 ) + */ + +#ifndef __CAPSULETHUNK_H +#define __CAPSULETHUNK_H + +#if ( (PY_VERSION_HEX < 0x02070000) \ + || ((PY_VERSION_HEX >= 0x03000000) \ + && (PY_VERSION_HEX < 0x03010000)) ) + +#define __PyCapsule_GetField(capsule, field, error_value) \ + ( PyCapsule_CheckExact(capsule) \ + ? (((PyCObject *)capsule)->field) \ + : (PyErr_SetString(PyExc_TypeError, "CObject required"), (error_value)) \ + ) \ + +#define __PyCapsule_SetField(capsule, field, value) \ + ( PyCapsule_CheckExact(capsule) \ + ? (((PyCObject *)capsule)->field = value), 0 \ + : (PyErr_SetString(PyExc_TypeError, "CObject required"), 1) \ + ) \ + + +#define PyCapsule_Type PyCObject_Type + +#define PyCapsule_CheckExact(capsule) (PyCObject_Check(capsule)) +#define PyCapsule_IsValid(capsule, name) (PyCObject_Check(capsule)) + + +#define PyCapsule_New(pointer, name, destructor) \ + (PyCObject_FromVoidPtr(pointer, (void (*)(void*)) (destructor))) + + +#define PyCapsule_GetPointer(capsule, name) \ + (PyCObject_AsVoidPtr(capsule)) + +/* Don't call PyCObject_SetPointer here, it fails if there's a destructor */ +#define PyCapsule_SetPointer(capsule, pointer) \ + __PyCapsule_SetField(capsule, cobject, pointer) + + +#define PyCapsule_GetDestructor(capsule) \ + __PyCapsule_GetField(capsule, destructor, (void (*)(void*)) NULL) + +#define PyCapsule_SetDestructor(capsule, dtor) \ + __PyCapsule_SetField(capsule, destructor, (void (*)(void*)) dtor) + + +/* + * Sorry, there's simply no place + * to store a Capsule "name" in a CObject. + */ +#define PyCapsule_GetName(capsule) NULL + +static int +PyCapsule_SetName(PyObject *capsule, const char *unused) +{ + unused = unused; + PyErr_SetString(PyExc_NotImplementedError, + "can't use PyCapsule_SetName with CObjects"); + return 1; +} + + + +#define PyCapsule_GetContext(capsule) \ + __PyCapsule_GetField(capsule, desc, (void*) NULL) + +#define PyCapsule_SetContext(capsule, context) \ + __PyCapsule_SetField(capsule, desc, context) + + +static void * +PyCapsule_Import(const char *name, int no_block) +{ + PyObject *object = NULL; + void *return_value = NULL; + char *trace; + size_t name_length = (strlen(name) + 1) * sizeof(char); + char *name_dup = (char *)PyMem_MALLOC(name_length); + + if (!name_dup) { + return NULL; + } + + memcpy(name_dup, name, name_length); + + trace = name_dup; + while (trace) { + char *dot = strchr(trace, '.'); + if (dot) { + *dot++ = '\0'; + } + + if (object == NULL) { + if (no_block) { + object = PyImport_ImportModuleNoBlock(trace); + } else { + object = PyImport_ImportModule(trace); + if (!object) { + PyErr_Format(PyExc_ImportError, + "PyCapsule_Import could not " + "import module \"%s\"", trace); + } + } + } else { + PyObject *object2 = PyObject_GetAttrString(object, trace); + Py_DECREF(object); + object = object2; + } + if (!object) { + goto EXIT; + } + + trace = dot; + } + + if (PyCObject_Check(object)) { + PyCObject *cobject = (PyCObject *)object; + return_value = cobject->cobject; + } else { + PyErr_Format(PyExc_AttributeError, + "PyCapsule_Import \"%s\" is not valid", + name); + } + +EXIT: + Py_XDECREF(object); + if (name_dup) { + PyMem_FREE(name_dup); + } + return return_value; +} + +#endif /* #if PY_VERSION_HEX < 0x02070000 */ + +#endif /* __CAPSULETHUNK_H */ From 1fa79b184c0b7d7893ec3deb7abddc98ba665cc0 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 29 May 2020 12:23:21 +0200 Subject: [PATCH 168/341] python: support capsule for python 2.6 --- core/src/plugins/dird/python/module/bareosdir.cc | 1 + core/src/plugins/dird/python/python-dir.cc | 1 + core/src/plugins/filed/python/module/bareosfd.cc | 1 + core/src/plugins/filed/python/python-fd.cc | 1 + core/src/plugins/filed/python/test/python-fd-module-tester.cc | 1 + core/src/plugins/stored/python/module/bareossd.cc | 1 + core/src/plugins/stored/python/python-sd.cc | 1 + 7 files changed, 7 insertions(+) diff --git a/core/src/plugins/dird/python/module/bareosdir.cc b/core/src/plugins/dird/python/module/bareosdir.cc index 02a947718e0..eac3e572f44 100644 --- a/core/src/plugins/dird/python/module/bareosdir.cc +++ b/core/src/plugins/dird/python/module/bareosdir.cc @@ -30,6 +30,7 @@ #include #else #include +#include "plugins/include/capsulethunk.h" #include "include/bareos.h" #endif diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index eda2032d4f9..7b5054b591e 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -31,6 +31,7 @@ #include #else #include +#include "plugins/include/capsulethunk.h" #include "include/bareos.h" #endif diff --git a/core/src/plugins/filed/python/module/bareosfd.cc b/core/src/plugins/filed/python/module/bareosfd.cc index c94af838249..f2a05ed284d 100644 --- a/core/src/plugins/filed/python/module/bareosfd.cc +++ b/core/src/plugins/filed/python/module/bareosfd.cc @@ -30,6 +30,7 @@ #include #else #include +#include "plugins/include/capsulethunk.h" #include "include/bareos.h" #endif diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 77f851b5853..1e6664542c6 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -31,6 +31,7 @@ #include #else #include +#include "plugins/include/capsulethunk.h" #include "include/bareos.h" #endif diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index b2f7e5e6ae9..0f531dd86b0 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -22,6 +22,7 @@ /* Load the python-fd plugin and test it */ #include "Python.h" +#include "plugins/include/capsulethunk.h" #include "plugins/include/python3compat.h" class PoolMem; #define NbytesForBits(n) ((((n)-1) >> 3) + 1) diff --git a/core/src/plugins/stored/python/module/bareossd.cc b/core/src/plugins/stored/python/module/bareossd.cc index 33c9e3b1b47..23422d009e7 100644 --- a/core/src/plugins/stored/python/module/bareossd.cc +++ b/core/src/plugins/stored/python/module/bareossd.cc @@ -30,6 +30,7 @@ #include #else #include +#include "plugins/include/capsulethunk.h" #include "include/bareos.h" #endif diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index 5468357f7bf..b4210cfd276 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -31,6 +31,7 @@ #include #else #include +#include "plugins/include/capsulethunk.h" #include "include/bareos.h" #endif From a1ffec42fc8097b66e57a7cd9fd2b0dbb609c805 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 29 May 2020 13:36:36 +0200 Subject: [PATCH 169/341] fd plugins: moved forgotten includes to plugins/include/common.h --- core/src/plugins/filed/cephfs/cephfs-fd.cc | 2 +- core/src/plugins/filed/gfapi/gfapi-fd.cc | 2 +- core/src/plugins/filed/rados/rados-fd.cc | 2 +- core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc | 2 +- core/src/plugins/filed/test-plugin/test-plugin-fd.cc | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/plugins/filed/cephfs/cephfs-fd.cc b/core/src/plugins/filed/cephfs/cephfs-fd.cc index 7040b310fe7..e44a850aced 100644 --- a/core/src/plugins/filed/cephfs/cephfs-fd.cc +++ b/core/src/plugins/filed/cephfs/cephfs-fd.cc @@ -25,7 +25,7 @@ */ #include "include/bareos.h" #include "filed/fd_plugins.h" -#include "plugins/filed/fd_common.h" +#include "plugins/include/common.h" #include "include/fileopts.h" #include "lib/alist.h" #include "lib/berrno.h" diff --git a/core/src/plugins/filed/gfapi/gfapi-fd.cc b/core/src/plugins/filed/gfapi/gfapi-fd.cc index 041a5215299..ca6a0a067a6 100644 --- a/core/src/plugins/filed/gfapi/gfapi-fd.cc +++ b/core/src/plugins/filed/gfapi/gfapi-fd.cc @@ -25,7 +25,7 @@ */ #include "include/bareos.h" #include "filed/fd_plugins.h" -#include "plugins/filed/fd_common.h" +#include "plugins/include/common.h" #include "include/fileopts.h" #include "lib/alist.h" #include "lib/path_list.h" diff --git a/core/src/plugins/filed/rados/rados-fd.cc b/core/src/plugins/filed/rados/rados-fd.cc index dffacdc702d..6a8a2858a53 100644 --- a/core/src/plugins/filed/rados/rados-fd.cc +++ b/core/src/plugins/filed/rados/rados-fd.cc @@ -25,7 +25,7 @@ */ #include "include/bareos.h" #include "filed/fd_plugins.h" -#include "plugins/filed/fd_common.h" +#include "plugins/include/common.h" #include "lib/berrno.h" #include diff --git a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc index d989d0ee3d5..b2d1783dc31 100644 --- a/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc +++ b/core/src/plugins/filed/test-deltaseq/test-deltaseq-fd.cc @@ -27,7 +27,7 @@ */ #include "include/bareos.h" #include "fd_plugins.h" -#include "plugins/filed/fd_common.h" +#include "plugins/include/common.h" namespace filedaemon { diff --git a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc index 11c534b9c1f..7e2ef6d53d7 100644 --- a/core/src/plugins/filed/test-plugin/test-plugin-fd.cc +++ b/core/src/plugins/filed/test-plugin/test-plugin-fd.cc @@ -29,7 +29,7 @@ */ #include "include/bareos.h" #include "filed/fd_plugins.h" -#include "plugins/filed/fd_common.h" +#include "plugins/include/common.h" #include "lib/ini.h" #include From ef8c93d0309ad3f62eeb1ee69d29e20685f6ab3c Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 29 May 2020 15:19:36 +0200 Subject: [PATCH 170/341] cmake: use FindPythonInterp on cmake < 3.12 --- core/cmake/BareosFindAllLibraries.cmake | 26 ++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/core/cmake/BareosFindAllLibraries.cmake b/core/cmake/BareosFindAllLibraries.cmake index 4ebb8ea8afa..5c888ba0ef5 100644 --- a/core/cmake/BareosFindAllLibraries.cmake +++ b/core/cmake/BareosFindAllLibraries.cmake @@ -23,9 +23,29 @@ if(${SYSTEMD_FOUND}) endif() if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") - #find_package (Python COMPONENTS Interpreter Development) - find_package (Python2 COMPONENTS Interpreter Development) - find_package (Python3 COMPONENTS Interpreter Development) + if(${CMAKE_VERSION} VERSION_LESS "3.12.0") + message(status "CMake too old for FindPython2/3, using FindPythonInterp") + set( Python_ADDITIONAL_VERSIONS 2.6 2.7) + find_package(PythonInterp) + find_package(PythonLibs) + + set(Python2_FOUND PYTHONLIBS_FOUND) + set(Python2_LIBRARIES PYTHON_LIBRARIES) + set(Python2_INCLUDE_DIRS PYTHON_INCLUDE_DIRS) + set(Python2_EXECUTABLE PYTHON_EXECUTABLE) + + set( Python_ADDITIONAL_VERSIONS 3.6 3.7 3.8 3.9) + find_package(PythonInterp) + find_package(PythonLibs) + set(Python3_FOUND PYTHONLIBS_FOUND) + set(Python3_LIBRARIES PYTHON_LIBRARIES) + set(Python3_INCLUDE_DIRS PYTHON_INCLUDE_DIRS) + set(Python3_EXECUTABLE PYTHON_EXECUTABLE) + else() + find_package (Python2 COMPONENTS Interpreter Development) + find_package (Python3 COMPONENTS Interpreter Development) + endif() + if(${Python2_FOUND} OR ${Python3_FOUND}) set(HAVE_PYTHON 1) endif() From 4240c6b5d367bf4171f10acb4ac747df619b9334 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 29 May 2020 16:16:56 +0200 Subject: [PATCH 171/341] remove force clean of build dir --- core/src/plugins/dird/python/CMakeLists.txt | 8 ++++---- core/src/plugins/filed/python/CMakeLists.txt | 8 ++++---- core/src/plugins/stored/python/CMakeLists.txt | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt index 33b0335aac5..d48c50f8d0d 100644 --- a/core/src/plugins/dird/python/CMakeLists.txt +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -43,11 +43,11 @@ if(Python2_FOUND AND NOT HAVE_WIN32) DEPENDS module/bareosdir.h DEPENDS bareos DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py - COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build + # COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${Python2_EXECUTABLE} module/setup.py build COMMAND ${Python2_EXECUTABLE} module/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build + # COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python2 module pythonmodules/bareosdir.so" ) add_custom_target(bareosdir-python2-module DEPENDS pythonmodules/bareosdir.so) @@ -91,11 +91,11 @@ if(Python3_FOUND AND NOT HAVE_WIN32) DEPENDS module/bareosdir.h DEPENDS bareos DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py - COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build + # COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${Python3_EXECUTABLE} module/setup.py build COMMAND ${Python3_EXECUTABLE} module/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/python3modules - COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build + # COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python3 module python3modules/bareosdir.so" ) add_custom_target( diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 4bae1850be1..1a9321b1800 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -99,11 +99,11 @@ if(Python2_FOUND AND NOT HAVE_WIN22) DEPENDS module/bareosfd.h DEPENDS bareos DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py2.py - COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build + # COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${Python2_EXECUTABLE} module/setup_py2.py build COMMAND ${Python2_EXECUTABLE} module/setup_py2.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build + # COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python2 module pythonmodules/bareosfd.so" ) add_custom_target(bareosfd-pymod DEPENDS pythonmodules/bareosfd.so) @@ -130,11 +130,11 @@ if(Python3_FOUND AND NOT HAVE_WIN32) DEPENDS module/bareosfd.h DEPENDS bareos DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py3.py - COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build + # COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${Python3_EXECUTABLE} module/setup_py3.py build COMMAND ${Python3_EXECUTABLE} module/setup_py3.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/python3modules - COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build + # COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python3 module python3modules/bareosfd.so" ) add_custom_target(bareosfd-pymod3 DEPENDS python3modules/bareosfd.so) diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index 03ca22d7f6c..7fda918727a 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -43,11 +43,11 @@ if(Python2_FOUND AND NOT HAVE_WIN32) DEPENDS module/bareossd.h DEPENDS bareos DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py - COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build + # COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${Python2_EXECUTABLE} module/setup.py build COMMAND ${Python2_EXECUTABLE} module/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build + # COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python module pythonmodules/bareossd.so" ) @@ -92,11 +92,11 @@ if(Python3_FOUND AND NOT HAVE_WIN32) DEPENDS module/bareossd.h DEPENDS bareos DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py - COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build + # COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${Python3_EXECUTABLE} module/setup.py build COMMAND ${Python3_EXECUTABLE} module/setup.py install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/python3modules - COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build + # COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python module python3modules/bareossd.so" ) From 164b16f668cfb9b45072c0242029d4397fbbf647 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 29 May 2020 17:30:42 +0200 Subject: [PATCH 172/341] rpm packaging: also package python3.*sos --- core/platforms/packaging/bareos.spec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/platforms/packaging/bareos.spec b/core/platforms/packaging/bareos.spec index 2fe3d07fdd5..7edd28fb1ca 100644 --- a/core/platforms/packaging/bareos.spec +++ b/core/platforms/packaging/bareos.spec @@ -1542,7 +1542,7 @@ mkdir -p %{?buildroot}/%{_libdir}/bareos/plugins/vmware_plugin %if 0%{?python_plugins} %files filedaemon-python-plugin %defattr(-, root, root) -%{plugin_dir}/python-fd.so +%{plugin_dir}/python*-fd.so %{plugin_dir}/bareos-fd.py* %{plugin_dir}/bareos-fd-local-fileset.py* %{plugin_dir}/bareos-fd-mock-test.py* @@ -1580,7 +1580,7 @@ mkdir -p %{?buildroot}/%{_libdir}/bareos/plugins/vmware_plugin %files director-python-plugin %defattr(-, root, root) -%{plugin_dir}/python-dir.so +%{plugin_dir}/python*-dir.so %{plugin_dir}/bareos-dir.py* %{plugin_dir}/BareosDirPluginBaseclass.py* %{plugin_dir}/bareos-dir-class-plugin.py* @@ -1588,7 +1588,7 @@ mkdir -p %{?buildroot}/%{_libdir}/bareos/plugins/vmware_plugin %files storage-python-plugin %defattr(-, root, root) -%{plugin_dir}/python-sd.so +%{plugin_dir}/python*-sd.so %{plugin_dir}/bareos-sd.py* %{plugin_dir}/BareosSdPluginBaseclass.py* %{plugin_dir}/BareosSdWrapper.py* From 132c0de0f11f3e3f623024bfad1ccaf9456ac889 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 29 May 2020 17:41:35 +0200 Subject: [PATCH 173/341] BareosFindAllLibraries: fixup --- core/cmake/BareosFindAllLibraries.cmake | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/cmake/BareosFindAllLibraries.cmake b/core/cmake/BareosFindAllLibraries.cmake index 5c888ba0ef5..e35d9da04ab 100644 --- a/core/cmake/BareosFindAllLibraries.cmake +++ b/core/cmake/BareosFindAllLibraries.cmake @@ -29,18 +29,18 @@ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") find_package(PythonInterp) find_package(PythonLibs) - set(Python2_FOUND PYTHONLIBS_FOUND) - set(Python2_LIBRARIES PYTHON_LIBRARIES) - set(Python2_INCLUDE_DIRS PYTHON_INCLUDE_DIRS) - set(Python2_EXECUTABLE PYTHON_EXECUTABLE) + set(Python2_FOUND ${PYTHONLIBS_FOUND}) + set(Python2_LIBRARIES ${PYTHON_LIBRARIES}) + set(Python2_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS}) + set(Python2_EXECUTABLE ${PYTHON_EXECUTABLE}) set( Python_ADDITIONAL_VERSIONS 3.6 3.7 3.8 3.9) find_package(PythonInterp) find_package(PythonLibs) - set(Python3_FOUND PYTHONLIBS_FOUND) - set(Python3_LIBRARIES PYTHON_LIBRARIES) - set(Python3_INCLUDE_DIRS PYTHON_INCLUDE_DIRS) - set(Python3_EXECUTABLE PYTHON_EXECUTABLE) + set(Python3_FOUND ${PYTHONLIBS_FOUND}) + set(Python3_LIBRARIES ${PYTHON_LIBRARIES}) + set(Python3_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS}) + set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE}) else() find_package (Python2 COMPONENTS Interpreter Development) find_package (Python3 COMPONENTS Interpreter Development) From 7989b84dbbe136d83f24585596cfaf12f3697116 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 29 May 2020 17:59:00 +0200 Subject: [PATCH 174/341] mssqlvdi-fd.cc: fd_common.h does not exist --- core/src/win32/plugins/filed/mssqlvdi-fd.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/win32/plugins/filed/mssqlvdi-fd.cc b/core/src/win32/plugins/filed/mssqlvdi-fd.cc index 5eb77005536..c30fda6ce53 100644 --- a/core/src/win32/plugins/filed/mssqlvdi-fd.cc +++ b/core/src/win32/plugins/filed/mssqlvdi-fd.cc @@ -26,7 +26,7 @@ */ #include "include/bareos.h" #include "fd_plugins.h" -#include "fd_common.h" +#include "plugins/include/common.h" /** * Microsoft® Component Object Model (COM) From 19be9ce81210dae6dcb85cdbd4d5b6e0954368db Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 29 May 2020 21:36:37 +0200 Subject: [PATCH 175/341] winbareos-nsi.spec: copy .py files --- core/platforms/win32/winbareos-nsi.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/platforms/win32/winbareos-nsi.spec b/core/platforms/win32/winbareos-nsi.spec index e9f8a6e7475..41e6bbd5666 100644 --- a/core/platforms/win32/winbareos-nsi.spec +++ b/core/platforms/win32/winbareos-nsi.spec @@ -263,7 +263,7 @@ for flavor in %{flavors}; do mkdir $RPM_BUILD_ROOT/$flavor/release${BITS}/Plugins - cp -rv /bareos*/src/plugins/*/pyfiles/*.py $RPM_BUILD_ROOT/$flavor/release${BITS}/Plugins + cp -rv /bareos*/src/plugins/*/*/*/*.py $RPM_BUILD_ROOT/$flavor/release${BITS}/Plugins cp %SOURCE1 %SOURCE2 %SOURCE3 %SOURCE4 %SOURCE6 %SOURCE9 \ %_sourcedir/LICENSE $RPM_BUILD_ROOT/$flavor/release${BITS} From c7bb003094303b750a14d405398854f243feca14 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 29 May 2020 22:34:32 +0200 Subject: [PATCH 176/341] cmake: define HAVE_PYTHON and Python2_FOUND on windows --- core/CMakeLists.txt | 2 -- core/cmake/BareosFindAllLibraries.cmake | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index b5351bafa4b..f1c1b1fa756 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -306,8 +306,6 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") set(Python_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/win32/plugins/python/include ) - set(HAVE_PYTHON 1) - set(PostgreSQL_LIBRARY ${PROJECT_SOURCE_DIR}/src/win32/cats/pgsql/lib/${WINDOWS_BITS}/libpq.dll ) diff --git a/core/cmake/BareosFindAllLibraries.cmake b/core/cmake/BareosFindAllLibraries.cmake index e35d9da04ab..fcafc4a81aa 100644 --- a/core/cmake/BareosFindAllLibraries.cmake +++ b/core/cmake/BareosFindAllLibraries.cmake @@ -49,6 +49,9 @@ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") if(${Python2_FOUND} OR ${Python3_FOUND}) set(HAVE_PYTHON 1) endif() +else() # windows + set(HAVE_PYTHON 1) + set(Python2_FOUND 1) endif() From f78b5c5450a5484e224167c477eaa3b6cb45ffea Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 29 May 2020 22:57:10 +0200 Subject: [PATCH 177/341] cmake : Python2_xxx --- core/CMakeLists.txt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index f1c1b1fa756..ca9734e3f30 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -300,10 +300,10 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") set(WINDOWS_LIBRARIES ws2_32) - set(Python_LIBRARIES + set(Python2_LIBRARIES ${PROJECT_SOURCE_DIR}/src/win32/plugins/python/lib/${WINDOWS_BITS}/python27.dll ) - set(Python_INCLUDE_DIRS + set(Python2_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/win32/plugins/python/include ) set(PostgreSQL_LIBRARY @@ -865,9 +865,6 @@ message( message( " CEPHFS support: ${CEPHFS_FOUND} ${CEPHFS_LIBRARIES} ${CEPHFS_INCLUDE_DIRS} " ) -message( - " Python support: ${Python_FOUND} ${Python_VERSION} ${Python_INCLUDE_DIRS} ${Python_EXECUTABLE}" -) message( " Python2 support: ${Python2_FOUND} ${Python2_VERSION} ${Python2_INCLUDE_DIRS} ${Python2_EXECUTABLE}" ) From 3b8d082d89807581624e1464439601efbc3caa12 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 4 Jun 2020 07:51:10 +0200 Subject: [PATCH 178/341] cmake: add get_python_compile_settings.py --- core/cmake/get_python_compile_settings.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 core/cmake/get_python_compile_settings.py diff --git a/core/cmake/get_python_compile_settings.py b/core/cmake/get_python_compile_settings.py new file mode 100644 index 00000000000..7dde83d1e96 --- /dev/null +++ b/core/cmake/get_python_compile_settings.py @@ -0,0 +1,4 @@ +import sys +import sysconfig +for var in ("CC","CFLAGS","CCSHARED","INCLUDEPY","BLDSHARED","LDFLAGS","EXT_SUFFIX"): + print ("set(Python{}_{} '{}')" . format(sys.version_info.major, var, sysconfig.get_config_var(var))) From 680cfa5f13321c3ffd233691b55b7260bac31cf1 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 4 Jun 2020 10:10:14 +0200 Subject: [PATCH 179/341] cmake: autodetect python build options for compiler and linker --- core/cmake/BareosFindAllLibraries.cmake | 21 +++++++++++++++++++++ core/cmake/get_python_compile_settings.py | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/core/cmake/BareosFindAllLibraries.cmake b/core/cmake/BareosFindAllLibraries.cmake index fcafc4a81aa..5278201d4f5 100644 --- a/core/cmake/BareosFindAllLibraries.cmake +++ b/core/cmake/BareosFindAllLibraries.cmake @@ -49,6 +49,27 @@ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") if(${Python2_FOUND} OR ${Python3_FOUND}) set(HAVE_PYTHON 1) endif() + + if(${Python2_FOUND}) + execute_process( + COMMAND ${Python2_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/get_python_compile_settings.py + OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/py2settings.cmake + ) + include(${CMAKE_CURRENT_SOURCE_DIR}/py2settings.cmake) + message("Python2_CC is ${Python2_CC}") + endif() + + if(${Python3_FOUND}) + execute_process( + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/get_python_compile_settings.py + OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/py3settings.cmake + ) + include(${CMAKE_CURRENT_SOURCE_DIR}/py3settings.cmake) + message("Python3_CC is ${Python3_CC}") + endif() + + + else() # windows set(HAVE_PYTHON 1) set(Python2_FOUND 1) diff --git a/core/cmake/get_python_compile_settings.py b/core/cmake/get_python_compile_settings.py index 7dde83d1e96..9924a89747f 100644 --- a/core/cmake/get_python_compile_settings.py +++ b/core/cmake/get_python_compile_settings.py @@ -1,4 +1,5 @@ import sys import sysconfig for var in ("CC","CFLAGS","CCSHARED","INCLUDEPY","BLDSHARED","LDFLAGS","EXT_SUFFIX"): - print ("set(Python{}_{} '{}')" . format(sys.version_info.major, var, sysconfig.get_config_var(var))) + print ("message(STATUS \"Python{}_{}\ is\ {}\")" . format(sys.version_info.major, var, sysconfig.get_config_var(var))) + print ("set(Python{}_{} \"{}\")" . format(sys.version_info.major, var, sysconfig.get_config_var(var))) From 4f5c1241fba8be21c4d9ee8d72cf8b1dd4309676 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 4 Jun 2020 10:26:04 +0200 Subject: [PATCH 180/341] cmake: build bareosfd module without setuptools --- core/src/plugins/filed/python/CMakeLists.txt | 35 ++++++++++---------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 1a9321b1800..aaf9dfe1936 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -29,7 +29,7 @@ if(Python2_FOUND) ) target_link_libraries(python-fd ${Python2_LIBRARIES} bareos) target_include_directories(python-fd PUBLIC SYSTEM ${Python2_INCLUDE_DIRS}) - add_dependencies(python-fd bareosfd-pymod) + # add_dependencies(python-fd bareosfd-pymod) add_dependencies(bareos-fd python-fd) endif() @@ -90,23 +90,24 @@ if(Python3_FOUND AND NOT HAVE_WIN32) endif() if(Python2_FOUND AND NOT HAVE_WIN22) - configure_file( - module/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py2.py - ) - add_custom_command( - OUTPUT pythonmodules/bareosfd.so - MAIN_DEPENDENCY module/bareosfd.cc - DEPENDS module/bareosfd.h - DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py2.py - # COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python2_EXECUTABLE} module/setup_py2.py build - COMMAND ${Python2_EXECUTABLE} module/setup_py2.py install --install-lib - ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - # COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build - COMMENT "building python2 module pythonmodules/bareosfd.so" + # configure_file( module/setup.py.in + # ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py2.py ) add_custom_command( OUTPUT + # pythonmodules/bareosfd.so MAIN_DEPENDENCY module/bareosfd.cc DEPENDS + # module/bareosfd.h DEPENDS bareos DEPENDS + # ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py2.py # COMMAND rm -Rfv + # ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${Python2_EXECUTABLE} + # module/setup_py2.py build COMMAND ${Python2_EXECUTABLE} module/setup_py2.py + # install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules # COMMAND rm + # -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python2 module + # pythonmodules/bareosfd.so" ) add_custom_target(bareosfd-pymod DEPENDS + # pythonmodules/bareosfd.so) + + add_library(bareosfd MODULE module/bareosfd.cc) + target_link_libraries(bareosfd bareos) + set_target_properties( + bareosfd PROPERTIES PREFIX "" LIBRARY_OUTPUT_DIRECTORY .. ) - add_custom_target(bareosfd-pymod DEPENDS pythonmodules/bareosfd.so) + add_test(NAME bareosfd-python-module COMMAND ${Python2_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/bareosfd_test.py From 421596abcba866daed13bdb7cc7d1c812ea3631a Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 5 Jun 2020 14:22:26 +0200 Subject: [PATCH 181/341] cmake :unset PYTHON vars before rerunning find_package(PythonInterp) --- core/cmake/get_python_compile_settings.py | 10 +++- core/src/plugins/filed/python/CMakeLists.txt | 57 ++++++++++++++------ 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/core/cmake/get_python_compile_settings.py b/core/cmake/get_python_compile_settings.py index 9924a89747f..2616d730d6f 100644 --- a/core/cmake/get_python_compile_settings.py +++ b/core/cmake/get_python_compile_settings.py @@ -1,5 +1,13 @@ import sys import sysconfig -for var in ("CC","CFLAGS","CCSHARED","INCLUDEPY","BLDSHARED","LDFLAGS","EXT_SUFFIX"): +for var in ("CC", "BLDSHARED"): + print ("message(STATUS \"Python{}_{}\ is\ {}\")" . format(sys.version_info.major, var, sysconfig.get_config_var(var))) + print ("set(Python{}_{} \"{}\")" . format(sys.version_info.major, var, sysconfig.get_config_var(var))) + + # as these vars contain the compiler itself, we remove the first word and return it as _FLAGS + print ("message(STATUS \"Python{}_{}_FLAGS\ is\ {}\")" . format(sys.version_info.major, var, sysconfig.get_config_var(var).split(' ',1)[1])) + print ("set(Python{}_{}_FLAGS \"{}\")" . format(sys.version_info.major, var, sysconfig.get_config_var(var).split(' ',1)[1])) + +for var in ("CFLAGS","CCSHARED","INCLUDEPY","LDFLAGS","EXT_SUFFIX"): print ("message(STATUS \"Python{}_{}\ is\ {}\")" . format(sys.version_info.major, var, sysconfig.get_config_var(var))) print ("set(Python{}_{} \"{}\")" . format(sys.version_info.major, var, sysconfig.get_config_var(var))) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index aaf9dfe1936..194a055cb6c 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -90,23 +90,50 @@ if(Python3_FOUND AND NOT HAVE_WIN32) endif() if(Python2_FOUND AND NOT HAVE_WIN22) - # configure_file( module/setup.py.in - # ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py2.py ) add_custom_command( OUTPUT - # pythonmodules/bareosfd.so MAIN_DEPENDENCY module/bareosfd.cc DEPENDS - # module/bareosfd.h DEPENDS bareos DEPENDS - # ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py2.py # COMMAND rm -Rfv - # ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${Python2_EXECUTABLE} - # module/setup_py2.py build COMMAND ${Python2_EXECUTABLE} module/setup_py2.py - # install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules # COMMAND rm - # -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python2 module - # pythonmodules/bareosfd.so" ) add_custom_target(bareosfd-pymod DEPENDS - # pythonmodules/bareosfd.so) + configure_file( + module/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py2.py + ) + add_custom_command( + OUTPUT pythonmodules/bareosfd.so + MAIN_DEPENDENCY module/bareosfd.cc + DEPENDS module/bareosfd.h + DEPENDS bareos + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py2.py + # COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build + COMMAND ${Python2_EXECUTABLE} module/setup_py2.py build + COMMAND + ${Python2_EXECUTABLE} module/setup_py2.py install --install-lib + ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules + # COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build + COMMENT "building python2 module + pythonmodules/bareosfd.so" + ) + add_custom_target(bareosfd-pymod DEPENDS pythonmodules/bareosfd.so) + + # self compiled stuff sources = + # ['/home/pstorz/git/bareos/core/module/bareosfd.cc'], include_dirs = + # ['/home/pstorz/git/bareos/core/src', '/usr/local/opt/gettext/include', + # '/usr/local/opt/openssl/include'], libraries = ['bareos'], library_dirs = + # ['/home/pstorz/git/bareos/b/core/src/lib/'], + # extra_compile_args=['-std=c++11'], target_link_libraries(bareosfd_self + # bareos ${Python2_LIBRARIES}) - add_library(bareosfd MODULE module/bareosfd.cc) - target_link_libraries(bareosfd bareos) + # COMPILE IS: Python2_CC Python2_CFLAGS Python2_CCSHARED INCLUDES LINK IS : + # g++ Python2_BLDSHARED + + add_library(bareosfd_self MODULE module/bareosfd.cc) set_target_properties( - bareosfd PROPERTIES PREFIX "" LIBRARY_OUTPUT_DIRECTORY .. - ) + bareosfd_self + PROPERTIES PREFIX "" + # LIBRARY_OUTPUT_DIRECTORY pythonmodules + LIBRARY_OUTPUT_NAME bareosfd + # LANGUAGE C + COMPILE_FLAGS "${Python2_CFLAGS} ${Python2_CCSHARED} " + LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" + LINK_LIBRARIES "bareos ${Python2_LIBRARIES}" + LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib + ) + # self compiled stuff done add_test(NAME bareosfd-python-module COMMAND ${Python2_EXECUTABLE} From e687f1561fe6ec815f708c714a778d956572c8a3 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 5 Jun 2020 17:06:46 +0200 Subject: [PATCH 182/341] cmake: build without setup tools works --- core/src/plugins/filed/python/CMakeLists.txt | 76 +++++++++----------- 1 file changed, 33 insertions(+), 43 deletions(-) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 194a055cb6c..dfdcb619a00 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -17,7 +17,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. -if(Python2_FOUND) +if(Python2_FOUND_) add_library(python-fd MODULE python-fd.cc) set_target_properties( python-fd PROPERTIES PREFIX "" LIBRARY_OUTPUT_DIRECTORY .. @@ -33,7 +33,7 @@ if(Python2_FOUND) add_dependencies(bareos-fd python-fd) endif() -if(Python3_FOUND) +if(Python3_FOUND_) add_library(python3-fd MODULE python-fd.cc) set_target_properties( python3-fd PROPERTIES PREFIX "" LIBRARY_OUTPUT_DIRECTORY .. @@ -49,7 +49,7 @@ if(Python3_FOUND) add_dependencies(bareos-fd python3-fd) endif() -if(Python2_FOUND AND NOT HAVE_WIN22) +if(Python2_FOUND_ AND NOT HAVE_WIN22) add_executable(bareosfd-python2-module-tester test/python-fd-module-tester.cc) target_link_libraries( bareosfd-python2-module-tester ${Python2_LIBRARIES} bareos @@ -69,7 +69,7 @@ if(Python2_FOUND AND NOT HAVE_WIN22) ) endif() -if(Python3_FOUND AND NOT HAVE_WIN32) +if(Python3_FOUND_ AND NOT HAVE_WIN32) add_executable(bareosfd-python3-module-tester test/python-fd-module-tester.cc) target_link_libraries( bareosfd-python3-module-tester ${Python3_LIBRARIES} bareos @@ -90,50 +90,40 @@ if(Python3_FOUND AND NOT HAVE_WIN32) endif() if(Python2_FOUND AND NOT HAVE_WIN22) - configure_file( - module/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py2.py - ) - add_custom_command( - OUTPUT pythonmodules/bareosfd.so - MAIN_DEPENDENCY module/bareosfd.cc - DEPENDS module/bareosfd.h - DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py2.py - # COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python2_EXECUTABLE} module/setup_py2.py build - COMMAND - ${Python2_EXECUTABLE} module/setup_py2.py install --install-lib - ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - # COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build - COMMENT "building python2 module - pythonmodules/bareosfd.so" - ) - add_custom_target(bareosfd-pymod DEPENDS pythonmodules/bareosfd.so) - # self compiled stuff sources = - # ['/home/pstorz/git/bareos/core/module/bareosfd.cc'], include_dirs = - # ['/home/pstorz/git/bareos/core/src', '/usr/local/opt/gettext/include', - # '/usr/local/opt/openssl/include'], libraries = ['bareos'], library_dirs = - # ['/home/pstorz/git/bareos/b/core/src/lib/'], - # extra_compile_args=['-std=c++11'], target_link_libraries(bareosfd_self - # bareos ${Python2_LIBRARIES}) + # configure_file( module/setup.py.in + # ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py2.py ) add_custom_command( OUTPUT + # pythonmodules/bareosfd.so MAIN_DEPENDENCY module/bareosfd.cc DEPENDS + # module/bareosfd.h DEPENDS bareos DEPENDS + # ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py2.py # COMMAND rm -Rfv + # ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${Python2_EXECUTABLE} + # module/setup_py2.py build --verbose --force COMMAND ${Python2_EXECUTABLE} + # module/setup_py2.py install --install-lib + # ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules # COMMAND rm -Rf + # ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python2 module + # pythonmodules/bareosfd.so" ) add_custom_target(bareosfd-pymod DEPENDS + # pythonmodules/bareosfd.so) - # COMPILE IS: Python2_CC Python2_CFLAGS Python2_CCSHARED INCLUDES LINK IS : - # g++ Python2_BLDSHARED + # COMPILE IS: Python2_CC Python2_CFLAGS Python2_CCSHARED INCLUDES + # LINK IS : g++ Python2_BLDSHARED + + set_property(SOURCE module/bareosfd.cc PROPERTY LANGUAGE C) add_library(bareosfd_self MODULE module/bareosfd.cc) set_target_properties( bareosfd_self - PROPERTIES PREFIX "" - # LIBRARY_OUTPUT_DIRECTORY pythonmodules - LIBRARY_OUTPUT_NAME bareosfd - # LANGUAGE C - COMPILE_FLAGS "${Python2_CFLAGS} ${Python2_CCSHARED} " - LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" - LINK_LIBRARIES "bareos ${Python2_LIBRARIES}" - LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib - ) - # self compiled stuff done + PROPERTIES + PREFIX "" + # LIBRARY_OUTPUT_DIRECTORY pythonmodules + LIBRARY_OUTPUT_NAME bareosfd + LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" + LINKER_LANGUAGE CXX + COMPILE_OPTIONS ${Python2_CCSHARED} + INCLUDE_DIRECTORIES + "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + LINK_LIBRARIES "bareos ${Python2_LIBRARIES}" + LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib + ) add_test(NAME bareosfd-python-module COMMAND ${Python2_EXECUTABLE} @@ -148,7 +138,7 @@ if(Python2_FOUND AND NOT HAVE_WIN22) ) endif() -if(Python3_FOUND AND NOT HAVE_WIN32) +if(Python3_FOUND_ AND NOT HAVE_WIN32) configure_file( module/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py3.py ) From 4a10fcc2ee669964f4a6cdab0050e13e8e56dc94 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 5 Jun 2020 17:21:18 +0200 Subject: [PATCH 183/341] cmake: self compiled python2 and python3 modules --- core/src/plugins/filed/python/CMakeLists.txt | 71 +++++++++++--------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index dfdcb619a00..75feda21793 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -17,7 +17,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. -if(Python2_FOUND_) +if(Python2_FOUND) add_library(python-fd MODULE python-fd.cc) set_target_properties( python-fd PROPERTIES PREFIX "" LIBRARY_OUTPUT_DIRECTORY .. @@ -29,11 +29,10 @@ if(Python2_FOUND_) ) target_link_libraries(python-fd ${Python2_LIBRARIES} bareos) target_include_directories(python-fd PUBLIC SYSTEM ${Python2_INCLUDE_DIRS}) - # add_dependencies(python-fd bareosfd-pymod) add_dependencies(bareos-fd python-fd) endif() -if(Python3_FOUND_) +if(Python3_FOUND) add_library(python3-fd MODULE python-fd.cc) set_target_properties( python3-fd PROPERTIES PREFIX "" LIBRARY_OUTPUT_DIRECTORY .. @@ -49,7 +48,7 @@ if(Python3_FOUND_) add_dependencies(bareos-fd python3-fd) endif() -if(Python2_FOUND_ AND NOT HAVE_WIN22) +if(Python2_FOUND AND NOT HAVE_WIN22) add_executable(bareosfd-python2-module-tester test/python-fd-module-tester.cc) target_link_libraries( bareosfd-python2-module-tester ${Python2_LIBRARIES} bareos @@ -69,7 +68,7 @@ if(Python2_FOUND_ AND NOT HAVE_WIN22) ) endif() -if(Python3_FOUND_ AND NOT HAVE_WIN32) +if(Python3_FOUND AND NOT HAVE_WIN32) add_executable(bareosfd-python3-module-tester test/python-fd-module-tester.cc) target_link_libraries( bareosfd-python3-module-tester ${Python3_LIBRARIES} bareos @@ -90,6 +89,7 @@ if(Python3_FOUND_ AND NOT HAVE_WIN32) endif() if(Python2_FOUND AND NOT HAVE_WIN22) + # with setuptools externally # configure_file( module/setup.py.in # ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py2.py ) add_custom_command( OUTPUT @@ -104,17 +104,14 @@ if(Python2_FOUND AND NOT HAVE_WIN22) # pythonmodules/bareosfd.so" ) add_custom_target(bareosfd-pymod DEPENDS # pythonmodules/bareosfd.so) - # COMPILE IS: Python2_CC Python2_CFLAGS Python2_CCSHARED INCLUDES - - # LINK IS : g++ Python2_BLDSHARED - + # build ourselves emulating setuptools set_property(SOURCE module/bareosfd.cc PROPERTY LANGUAGE C) - add_library(bareosfd_self MODULE module/bareosfd.cc) + add_library(bareosfd-pymod2 MODULE module/bareosfd.cc) set_target_properties( - bareosfd_self + bareosfd-pymod2 PROPERTIES PREFIX "" - # LIBRARY_OUTPUT_DIRECTORY pythonmodules + LIBRARY_OUTPUT_DIRECTORY pythonmodules LIBRARY_OUTPUT_NAME bareosfd LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX @@ -138,28 +135,42 @@ if(Python2_FOUND AND NOT HAVE_WIN22) ) endif() -if(Python3_FOUND_ AND NOT HAVE_WIN32) - configure_file( - module/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py3.py - ) - add_custom_command( - OUTPUT python3modules/bareosfd.so - MAIN_DEPENDENCY module/bareosfd.cc - DEPENDS module/bareosfd.h - DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py3.py - # COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python3_EXECUTABLE} module/setup_py3.py build - COMMAND ${Python3_EXECUTABLE} module/setup_py3.py install --install-lib - ${CMAKE_CURRENT_BINARY_DIR}/python3modules - # COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build - COMMENT "building python3 module python3modules/bareosfd.so" - ) - add_custom_target(bareosfd-pymod3 DEPENDS python3modules/bareosfd.so) +if(Python3_FOUND AND NOT HAVE_WIN32) + # configure_file( module/setup.py.in + # ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py3.py ) add_custom_command( OUTPUT + # python3modules/bareosfd.so MAIN_DEPENDENCY module/bareosfd.cc DEPENDS + # module/bareosfd.h DEPENDS bareos DEPENDS + # ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py3.py # COMMAND rm -Rfv + # ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${Python3_EXECUTABLE} + # module/setup_py3.py build COMMAND ${Python3_EXECUTABLE} module/setup_py3.py + # install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/python3modules # COMMAND + # rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python3 module + # python3modules/bareosfd.so" ) add_custom_target(bareosfd-pymod3 DEPENDS + # python3modules/bareosfd.so) + + # build ourselves emulating setuptools + set_property(SOURCE module/bareosfd.cc PROPERTY LANGUAGE C) + add_library(bareosfd-pymod3 MODULE module/bareosfd.cc) + set_target_properties( + bareosfd-pymod3 + PROPERTIES + PREFIX "" + LIBRARY_OUTPUT_DIRECTORY python3modules + LIBRARY_OUTPUT_NAME bareosfd + LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" + LINKER_LANGUAGE CXX + COMPILE_OPTIONS ${Python3_CCSHARED} + INCLUDE_DIRECTORIES + "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + LINK_LIBRARIES "bareos ${Python3_LIBRARIES}" + LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib + ) + add_test(NAME bareosfd-python3-module COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/bareosfd_test.py ) + set_property( TEST bareosfd-python3-module PROPERTY From 1795911531d276c0b3f8205a45828c433ee78c4e Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 5 Jun 2020 17:51:17 +0200 Subject: [PATCH 184/341] cmake: build without setup tools works --- core/cmake/get_python_compile_settings.py | 9 +++- core/src/plugins/filed/python/CMakeLists.txt | 44 +++++--------------- 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/core/cmake/get_python_compile_settings.py b/core/cmake/get_python_compile_settings.py index 2616d730d6f..0466ebe6e5a 100644 --- a/core/cmake/get_python_compile_settings.py +++ b/core/cmake/get_python_compile_settings.py @@ -8,6 +8,13 @@ print ("message(STATUS \"Python{}_{}_FLAGS\ is\ {}\")" . format(sys.version_info.major, var, sysconfig.get_config_var(var).split(' ',1)[1])) print ("set(Python{}_{}_FLAGS \"{}\")" . format(sys.version_info.major, var, sysconfig.get_config_var(var).split(' ',1)[1])) -for var in ("CFLAGS","CCSHARED","INCLUDEPY","LDFLAGS","EXT_SUFFIX"): +for var in ("CFLAGS","CCSHARED","INCLUDEPY","LDFLAGS"): print ("message(STATUS \"Python{}_{}\ is\ {}\")" . format(sys.version_info.major, var, sysconfig.get_config_var(var))) print ("set(Python{}_{} \"{}\")" . format(sys.version_info.major, var, sysconfig.get_config_var(var))) + +for var in ("EXT_SUFFIX",): + value = sysconfig.get_config_var(var) + if value is None: + value = '' + print ("message(STATUS \"Python{}_{}\ is\ {}\")" . format(sys.version_info.major, var, value)) + print ("set(Python{}_{} \"{}\")" . format(sys.version_info.major, var, value)) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 75feda21793..24cbf2a7bb0 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -30,6 +30,7 @@ if(Python2_FOUND) target_link_libraries(python-fd ${Python2_LIBRARIES} bareos) target_include_directories(python-fd PUBLIC SYSTEM ${Python2_INCLUDE_DIRS}) add_dependencies(bareos-fd python-fd) + add_dependencies(python-fd bareosfd-python2-module) endif() if(Python3_FOUND) @@ -44,8 +45,8 @@ if(Python3_FOUND) ) target_link_libraries(python3-fd ${Python3_LIBRARIES} bareos) target_include_directories(python3-fd PUBLIC SYSTEM ${Python3_INCLUDE_DIRS}) - add_dependencies(python3-fd bareosfd-pymod3) add_dependencies(bareos-fd python3-fd) + add_dependencies(python3-fd bareosfd-python3-module) endif() if(Python2_FOUND AND NOT HAVE_WIN22) @@ -89,28 +90,13 @@ if(Python3_FOUND AND NOT HAVE_WIN32) endif() if(Python2_FOUND AND NOT HAVE_WIN22) - # with setuptools externally - - # configure_file( module/setup.py.in - # ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py2.py ) add_custom_command( OUTPUT - # pythonmodules/bareosfd.so MAIN_DEPENDENCY module/bareosfd.cc DEPENDS - # module/bareosfd.h DEPENDS bareos DEPENDS - # ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py2.py # COMMAND rm -Rfv - # ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${Python2_EXECUTABLE} - # module/setup_py2.py build --verbose --force COMMAND ${Python2_EXECUTABLE} - # module/setup_py2.py install --install-lib - # ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules # COMMAND rm -Rf - # ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python2 module - # pythonmodules/bareosfd.so" ) add_custom_target(bareosfd-pymod DEPENDS - # pythonmodules/bareosfd.so) - - # build ourselves emulating setuptools set_property(SOURCE module/bareosfd.cc PROPERTY LANGUAGE C) - add_library(bareosfd-pymod2 MODULE module/bareosfd.cc) + add_library(bareosfd-python2-module MODULE module/bareosfd.cc) set_target_properties( - bareosfd-pymod2 + bareosfd-python2-module PROPERTIES PREFIX "" + # SUFFIX ${Python2_EXT_SUFFIX} LIBRARY_OUTPUT_DIRECTORY pythonmodules LIBRARY_OUTPUT_NAME bareosfd LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" @@ -121,6 +107,7 @@ if(Python2_FOUND AND NOT HAVE_WIN22) LINK_LIBRARIES "bareos ${Python2_LIBRARIES}" LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) + add_dependencies(bareosfd-python2-module bareos) add_test(NAME bareosfd-python-module COMMAND ${Python2_EXECUTABLE} @@ -136,25 +123,13 @@ if(Python2_FOUND AND NOT HAVE_WIN22) endif() if(Python3_FOUND AND NOT HAVE_WIN32) - # configure_file( module/setup.py.in - # ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py3.py ) add_custom_command( OUTPUT - # python3modules/bareosfd.so MAIN_DEPENDENCY module/bareosfd.cc DEPENDS - # module/bareosfd.h DEPENDS bareos DEPENDS - # ${CMAKE_CURRENT_BINARY_DIR}/module/setup_py3.py # COMMAND rm -Rfv - # ${CMAKE_CURRENT_BINARY_DIR}/build COMMAND ${Python3_EXECUTABLE} - # module/setup_py3.py build COMMAND ${Python3_EXECUTABLE} module/setup_py3.py - # install --install-lib ${CMAKE_CURRENT_BINARY_DIR}/python3modules # COMMAND - # rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build COMMENT "building python3 module - # python3modules/bareosfd.so" ) add_custom_target(bareosfd-pymod3 DEPENDS - # python3modules/bareosfd.so) - - # build ourselves emulating setuptools set_property(SOURCE module/bareosfd.cc PROPERTY LANGUAGE C) - add_library(bareosfd-pymod3 MODULE module/bareosfd.cc) + add_library(bareosfd-python3-module MODULE module/bareosfd.cc) set_target_properties( - bareosfd-pymod3 + bareosfd-python3-module PROPERTIES PREFIX "" + SUFFIX ${Python3_EXT_SUFFIX} LIBRARY_OUTPUT_DIRECTORY python3modules LIBRARY_OUTPUT_NAME bareosfd LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" @@ -165,6 +140,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LINK_LIBRARIES "bareos ${Python3_LIBRARIES}" LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) + add_dependencies(bareosfd-python3-module bareos) add_test(NAME bareosfd-python3-module COMMAND ${Python3_EXECUTABLE} From 60e46cbb1b43bfa4b50ad26466095923868f982c Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 5 Jun 2020 18:00:20 +0200 Subject: [PATCH 185/341] build all modules without setuptools --- core/src/plugins/dird/python/CMakeLists.txt | 64 ++++++++++--------- core/src/plugins/stored/python/CMakeLists.txt | 64 ++++++++++--------- 2 files changed, 68 insertions(+), 60 deletions(-) diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt index d48c50f8d0d..7c884a60419 100644 --- a/core/src/plugins/dird/python/CMakeLists.txt +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -36,21 +36,24 @@ if(Python2_FOUND) endif() if(Python2_FOUND AND NOT HAVE_WIN32) - configure_file(module/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py) - add_custom_command( - OUTPUT pythonmodules/bareosdir.so - MAIN_DEPENDENCY module/bareosdir.cc - DEPENDS module/bareosdir.h - DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py - # COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python2_EXECUTABLE} module/setup.py build - COMMAND ${Python2_EXECUTABLE} module/setup.py install --install-lib - ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - # COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build - COMMENT "building python2 module pythonmodules/bareosdir.so" + set_property(SOURCE module/bareosdir.cc PROPERTY LANGUAGE C) + add_library(bareosdir-python2-module MODULE module/bareosdir.cc) + set_target_properties( + bareosdir-python2-module + PROPERTIES + PREFIX "" + # SUFFIX ${Python2_EXT_SUFFIX} + LIBRARY_OUTPUT_DIRECTORY pythonmodules + LIBRARY_OUTPUT_NAME bareosdir + LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" + LINKER_LANGUAGE CXX + COMPILE_OPTIONS ${Python2_CCSHARED} + INCLUDE_DIRECTORIES + "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + LINK_LIBRARIES "bareos ${Python2_LIBRARIES}" + LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) - add_custom_target(bareosdir-python2-module DEPENDS pythonmodules/bareosdir.so) + add_dependencies(bareosdir-python2-module bareos) add_test(NAME bareosdir-python2-module COMMAND ${Python2_EXECUTABLE} @@ -84,23 +87,24 @@ if(Python3_FOUND) endif() if(Python3_FOUND AND NOT HAVE_WIN32) - configure_file(module/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py) - add_custom_command( - OUTPUT python3modules/bareosdir.so - MAIN_DEPENDENCY module/bareosdir.cc - DEPENDS module/bareosdir.h - DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py - # COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python3_EXECUTABLE} module/setup.py build - COMMAND ${Python3_EXECUTABLE} module/setup.py install --install-lib - ${CMAKE_CURRENT_BINARY_DIR}/python3modules - # COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build - COMMENT "building python3 module python3modules/bareosdir.so" - ) - add_custom_target( - bareosdir-python3-module DEPENDS python3modules/bareosdir.so + set_property(SOURCE module/bareosdir.cc PROPERTY LANGUAGE C) + add_library(bareosdir-python3-module MODULE module/bareosdir.cc) + set_target_properties( + bareosdir-python3-module + PROPERTIES + PREFIX "" + SUFFIX ${Python3_EXT_SUFFIX} + LIBRARY_OUTPUT_DIRECTORY python3modules + LIBRARY_OUTPUT_NAME bareosdir + LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" + LINKER_LANGUAGE CXX + COMPILE_OPTIONS ${Python3_CCSHARED} + INCLUDE_DIRECTORIES + "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + LINK_LIBRARIES "bareos ${Python3_LIBRARIES}" + LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) + add_dependencies(bareosdir-python3-module bareos) add_test(NAME bareosdir-python3-module COMMAND ${Python3_EXECUTABLE} diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index 7fda918727a..d6fc6cec372 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -36,22 +36,24 @@ if(Python2_FOUND) endif() if(Python2_FOUND AND NOT HAVE_WIN32) - configure_file(module/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py) - add_custom_command( - OUTPUT pythonmodules/bareossd.so - MAIN_DEPENDENCY module/bareossd.cc - DEPENDS module/bareossd.h - DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py - # COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python2_EXECUTABLE} module/setup.py build - COMMAND ${Python2_EXECUTABLE} module/setup.py install --install-lib - ${CMAKE_CURRENT_BINARY_DIR}/pythonmodules - # COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build - COMMENT "building python module pythonmodules/bareossd.so" + set_property(SOURCE module/bareossd.cc PROPERTY LANGUAGE C) + add_library(bareossd-python2-module MODULE module/bareossd.cc) + set_target_properties( + bareossd-python2-module + PROPERTIES + PREFIX "" + # SUFFIX ${Python2_EXT_SUFFIX} + LIBRARY_OUTPUT_DIRECTORY pythonmodules + LIBRARY_OUTPUT_NAME bareossd + LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" + LINKER_LANGUAGE CXX + COMPILE_OPTIONS ${Python2_CCSHARED} + INCLUDE_DIRECTORIES + "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + LINK_LIBRARIES "bareos ${Python2_LIBRARIES}" + LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) - - add_custom_target(bareossd-python2-module DEPENDS pythonmodules/bareossd.so) + add_dependencies(bareossd-python2-module bareos) add_test(NAME bareossd-python2-module COMMAND ${Python2_EXECUTABLE} @@ -85,22 +87,24 @@ if(Python3_FOUND) endif() if(Python3_FOUND AND NOT HAVE_WIN32) - configure_file(module/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py) - add_custom_command( - OUTPUT python3modules/bareossd.so - MAIN_DEPENDENCY module/bareossd.cc - DEPENDS module/bareossd.h - DEPENDS bareos - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/module/setup.py - # COMMAND rm -Rfv ${CMAKE_CURRENT_BINARY_DIR}/build - COMMAND ${Python3_EXECUTABLE} module/setup.py build - COMMAND ${Python3_EXECUTABLE} module/setup.py install --install-lib - ${CMAKE_CURRENT_BINARY_DIR}/python3modules - # COMMAND rm -Rf ${CMAKE_CURRENT_BINARY_DIR}/build - COMMENT "building python module python3modules/bareossd.so" + set_property(SOURCE module/bareossd.cc PROPERTY LANGUAGE C) + add_library(bareossd-python3-module MODULE module/bareossd.cc) + set_target_properties( + bareossd-python3-module + PROPERTIES + PREFIX "" + SUFFIX ${Python3_EXT_SUFFIX} + LIBRARY_OUTPUT_DIRECTORY python3modules + LIBRARY_OUTPUT_NAME bareossd + LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" + LINKER_LANGUAGE CXX + COMPILE_OPTIONS ${Python3_CCSHARED} + INCLUDE_DIRECTORIES + "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + LINK_LIBRARIES "bareos ${Python3_LIBRARIES}" + LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) - - add_custom_target(bareossd-python3-module DEPENDS python3modules/bareossd.so) + add_dependencies(bareossd-python3-module bareos) add_test(NAME bareossd-python3-module COMMAND ${Python3_EXECUTABLE} From ab658780f572286f1f054a5bdf47188eb212c094 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 5 Jun 2020 18:02:03 +0200 Subject: [PATCH 186/341] python plugin build: removed setup.py --- core/src/plugins/dird/python/module/setup.py.in | 14 -------------- core/src/plugins/filed/python/module/setup.py.in | 14 -------------- core/src/plugins/stored/python/module/setup.py.in | 14 -------------- 3 files changed, 42 deletions(-) delete mode 100644 core/src/plugins/dird/python/module/setup.py.in delete mode 100644 core/src/plugins/filed/python/module/setup.py.in delete mode 100644 core/src/plugins/stored/python/module/setup.py.in diff --git a/core/src/plugins/dird/python/module/setup.py.in b/core/src/plugins/dird/python/module/setup.py.in deleted file mode 100644 index 04a79e2b5cb..00000000000 --- a/core/src/plugins/dird/python/module/setup.py.in +++ /dev/null @@ -1,14 +0,0 @@ -from distutils.core import setup, Extension - -module1 = Extension('bareosdir', - sources = ['@CMAKE_CURRENT_SOURCE_DIR@/module/bareosdir.cc'], - include_dirs = ['@PROJECT_SOURCE_DIR@/src'], - libraries = ['bareos'], - library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'], - extra_compile_args=['-std=c++11'], - ) - -setup (name = 'bareosdir', - version = '@BAREOS_FULL_VERSION@', - description = 'bareos package', - ext_modules = [module1]) diff --git a/core/src/plugins/filed/python/module/setup.py.in b/core/src/plugins/filed/python/module/setup.py.in deleted file mode 100644 index 69b4d89bd38..00000000000 --- a/core/src/plugins/filed/python/module/setup.py.in +++ /dev/null @@ -1,14 +0,0 @@ -from distutils.core import setup, Extension - -module1 = Extension('bareosfd', - sources = ['@CMAKE_CURRENT_SOURCE_DIR@/module/bareosfd.cc'], - include_dirs = ['@PROJECT_SOURCE_DIR@/src', '/usr/local/opt/gettext/include', '/usr/local/opt/openssl/include'], - libraries = ['bareos'], - library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'], - extra_compile_args=['-std=c++11'], - ) - -setup (name = 'bareosfd', - version = '@BAREOS_FULL_VERSION@', - description = 'bareos package', - ext_modules = [module1]) diff --git a/core/src/plugins/stored/python/module/setup.py.in b/core/src/plugins/stored/python/module/setup.py.in deleted file mode 100644 index 7f16f266f34..00000000000 --- a/core/src/plugins/stored/python/module/setup.py.in +++ /dev/null @@ -1,14 +0,0 @@ -from distutils.core import setup, Extension - -module1 = Extension('bareossd', - sources = ['@CMAKE_CURRENT_SOURCE_DIR@/module/bareossd.cc'], - include_dirs = ['@PROJECT_SOURCE_DIR@/src'], - libraries = ['bareos'], - library_dirs = ['@PROJECT_BINARY_DIR@/src/lib/'], - extra_compile_args=['-std=c++11'], - ) - -setup (name = 'bareossd', - version = '@BAREOS_FULL_VERSION@', - description = 'bareos package', - ext_modules = [module1]) From 7dab923e8269af1f60d7868770a1c42834453ae3 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 5 Jun 2020 18:13:25 +0200 Subject: [PATCH 187/341] cmake: cleanup get_python_compile_settings.py --- core/cmake/get_python_compile_settings.py | 39 +++++++++++++++++++---- 1 file changed, 33 insertions(+), 6 deletions(-) mode change 100644 => 100755 core/cmake/get_python_compile_settings.py diff --git a/core/cmake/get_python_compile_settings.py b/core/cmake/get_python_compile_settings.py old mode 100644 new mode 100755 index 0466ebe6e5a..221b3388151 --- a/core/cmake/get_python_compile_settings.py +++ b/core/cmake/get_python_compile_settings.py @@ -1,16 +1,43 @@ +#!/usr/bin/env python +""" + BAREOS® - Backup Archiving REcovery Open Sourced + + Copyright (C) 2020-2020 Bareos GmbH & Co. KG + + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation, which is + listed in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +""" +""" This program extracts the build configuration from the python interpreter. + The output is consumed by cmake where appropriate variables are set. + This is required to build python modules without setuptools. +""" import sys import sysconfig for var in ("CC", "BLDSHARED"): - print ("message(STATUS \"Python{}_{}\ is\ {}\")" . format(sys.version_info.major, var, sysconfig.get_config_var(var))) - print ("set(Python{}_{} \"{}\")" . format(sys.version_info.major, var, sysconfig.get_config_var(var))) + value = sysconfig.get_config_var(var) + print ("message(STATUS \"Python{}_{}\ is\ {}\")" . format(sys.version_info.major, var, value)) + print ("set(Python{}_{} \"{}\")" . format(sys.version_info.major, var, value)) # as these vars contain the compiler itself, we remove the first word and return it as _FLAGS - print ("message(STATUS \"Python{}_{}_FLAGS\ is\ {}\")" . format(sys.version_info.major, var, sysconfig.get_config_var(var).split(' ',1)[1])) - print ("set(Python{}_{}_FLAGS \"{}\")" . format(sys.version_info.major, var, sysconfig.get_config_var(var).split(' ',1)[1])) + print ("message(STATUS \"Python{}_{}_FLAGS\ is\ {}\")" . format(sys.version_info.major, var, value.split(' ',1)[1])) + print ("set(Python{}_{}_FLAGS \"{}\")" . format(sys.version_info.major, var, value.split(' ',1)[1])) for var in ("CFLAGS","CCSHARED","INCLUDEPY","LDFLAGS"): - print ("message(STATUS \"Python{}_{}\ is\ {}\")" . format(sys.version_info.major, var, sysconfig.get_config_var(var))) - print ("set(Python{}_{} \"{}\")" . format(sys.version_info.major, var, sysconfig.get_config_var(var))) + value = sysconfig.get_config_var(var) + print ("message(STATUS \"Python{}_{}\ is\ {}\")" . format(sys.version_info.major, var, value)) + print ("set(Python{}_{} \"{}\")" . format(sys.version_info.major, var, value)) for var in ("EXT_SUFFIX",): value = sysconfig.get_config_var(var) From 1bff1e5991000a81d77ee798a5bad5adce1799cf Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 5 Jun 2020 18:53:03 +0200 Subject: [PATCH 188/341] cmake: get_python_compile_settings.py: handle empty compile flags --- core/cmake/get_python_compile_settings.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/cmake/get_python_compile_settings.py b/core/cmake/get_python_compile_settings.py index 221b3388151..6e535d2079b 100755 --- a/core/cmake/get_python_compile_settings.py +++ b/core/cmake/get_python_compile_settings.py @@ -30,9 +30,14 @@ print ("message(STATUS \"Python{}_{}\ is\ {}\")" . format(sys.version_info.major, var, value)) print ("set(Python{}_{} \"{}\")" . format(sys.version_info.major, var, value)) + # if nothing comes after the compile command, the flags are empty + try: + value = value.split(' ',1)[1] + except: + value = '' # as these vars contain the compiler itself, we remove the first word and return it as _FLAGS - print ("message(STATUS \"Python{}_{}_FLAGS\ is\ {}\")" . format(sys.version_info.major, var, value.split(' ',1)[1])) - print ("set(Python{}_{}_FLAGS \"{}\")" . format(sys.version_info.major, var, value.split(' ',1)[1])) + print ("message(STATUS \"Python{}_{}_FLAGS\ is\ {}\")" . format(sys.version_info.major, var, value)) + print ("set(Python{}_{}_FLAGS \"{}\")" . format(sys.version_info.major, var, value)) for var in ("CFLAGS","CCSHARED","INCLUDEPY","LDFLAGS"): value = sysconfig.get_config_var(var) From 9105826ef0e6e841ae868f028227b6072fa1f995 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 5 Jun 2020 18:59:02 +0200 Subject: [PATCH 189/341] get_python_compile_settings.py: set coding --- core/cmake/get_python_compile_settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/core/cmake/get_python_compile_settings.py b/core/cmake/get_python_compile_settings.py index 6e535d2079b..d51e59792c5 100755 --- a/core/cmake/get_python_compile_settings.py +++ b/core/cmake/get_python_compile_settings.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- """ BAREOS® - Backup Archiving REcovery Open Sourced From 5e53cfdda823f8e0c210756191ff0ed86db0f51d Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 5 Jun 2020 22:11:27 +0200 Subject: [PATCH 190/341] cmake: fix for get_python_compile_settings.py --- core/cmake/get_python_compile_settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/cmake/get_python_compile_settings.py b/core/cmake/get_python_compile_settings.py index d51e59792c5..80d25385f6d 100755 --- a/core/cmake/get_python_compile_settings.py +++ b/core/cmake/get_python_compile_settings.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- """ - BAREOS® - Backup Archiving REcovery Open Sourced + BAREOS(R) - Backup Archiving REcovery Open Sourced Copyright (C) 2020-2020 Bareos GmbH & Co. KG From ca3fa588e207f2e1f9de2b691fa04a7d7449d557 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 5 Jun 2020 22:24:35 +0200 Subject: [PATCH 191/341] get_python_compile_settings.py : comment string changed --- core/cmake/get_python_compile_settings.py | 42 +++++++++++------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/core/cmake/get_python_compile_settings.py b/core/cmake/get_python_compile_settings.py index 80d25385f6d..cc003ff1988 100755 --- a/core/cmake/get_python_compile_settings.py +++ b/core/cmake/get_python_compile_settings.py @@ -1,29 +1,29 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -""" - BAREOS(R) - Backup Archiving REcovery Open Sourced - Copyright (C) 2020-2020 Bareos GmbH & Co. KG +# BAREOS(R) - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2020-2020 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation, which is +# listed in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. - This program is Free Software; you can redistribute it and/or - modify it under the terms of version three of the GNU Affero General Public - License as published by the Free Software Foundation, which is - listed in the file LICENSE. +# This program extracts the build configuration from the python interpreter. +# The output is consumed by cmake where appropriate variables are set. +# This is required to build python modules without setuptools. - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -""" -""" This program extracts the build configuration from the python interpreter. - The output is consumed by cmake where appropriate variables are set. - This is required to build python modules without setuptools. -""" import sys import sysconfig for var in ("CC", "BLDSHARED"): From 079de07c06dcb601fbf444ce921ea53f7448c5f2 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 6 Jun 2020 10:16:25 +0200 Subject: [PATCH 192/341] cmake: build python extensions: use c++11 standard --- core/src/plugins/dird/python/CMakeLists.txt | 2 ++ core/src/plugins/filed/python/CMakeLists.txt | 2 ++ core/src/plugins/stored/python/CMakeLists.txt | 2 ++ 3 files changed, 6 insertions(+) diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt index 7c884a60419..348e1ec6ba6 100644 --- a/core/src/plugins/dird/python/CMakeLists.txt +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -42,6 +42,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) bareosdir-python2-module PROPERTIES PREFIX "" + CXX_STANDARD 11 # SUFFIX ${Python2_EXT_SUFFIX} LIBRARY_OUTPUT_DIRECTORY pythonmodules LIBRARY_OUTPUT_NAME bareosdir @@ -93,6 +94,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) bareosdir-python3-module PROPERTIES PREFIX "" + CXX_STANDARD 11 SUFFIX ${Python3_EXT_SUFFIX} LIBRARY_OUTPUT_DIRECTORY python3modules LIBRARY_OUTPUT_NAME bareosdir diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 24cbf2a7bb0..bef74c38c70 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -96,6 +96,7 @@ if(Python2_FOUND AND NOT HAVE_WIN22) bareosfd-python2-module PROPERTIES PREFIX "" + CXX_STANDARD 11 # SUFFIX ${Python2_EXT_SUFFIX} LIBRARY_OUTPUT_DIRECTORY pythonmodules LIBRARY_OUTPUT_NAME bareosfd @@ -129,6 +130,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) bareosfd-python3-module PROPERTIES PREFIX "" + CXX_STANDARD 11 SUFFIX ${Python3_EXT_SUFFIX} LIBRARY_OUTPUT_DIRECTORY python3modules LIBRARY_OUTPUT_NAME bareosfd diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index d6fc6cec372..5e9106f5f43 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -42,6 +42,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) bareossd-python2-module PROPERTIES PREFIX "" + CXX_STANDARD 11 # SUFFIX ${Python2_EXT_SUFFIX} LIBRARY_OUTPUT_DIRECTORY pythonmodules LIBRARY_OUTPUT_NAME bareossd @@ -93,6 +94,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) bareossd-python3-module PROPERTIES PREFIX "" + CXX_STANDARD 11 SUFFIX ${Python3_EXT_SUFFIX} LIBRARY_OUTPUT_DIRECTORY python3modules LIBRARY_OUTPUT_NAME bareossd From 11b19fe063a76d924277f18562368fa956aa5f92 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 6 Jun 2020 10:27:23 +0200 Subject: [PATCH 193/341] cmake: set C_STD when building python plugins --- core/src/plugins/dird/python/CMakeLists.txt | 4 ++-- core/src/plugins/filed/python/CMakeLists.txt | 4 ++-- core/src/plugins/stored/python/CMakeLists.txt | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt index 348e1ec6ba6..c9f4e49e9ba 100644 --- a/core/src/plugins/dird/python/CMakeLists.txt +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -42,7 +42,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) bareosdir-python2-module PROPERTIES PREFIX "" - CXX_STANDARD 11 + C_STANDARD 11 # SUFFIX ${Python2_EXT_SUFFIX} LIBRARY_OUTPUT_DIRECTORY pythonmodules LIBRARY_OUTPUT_NAME bareosdir @@ -94,7 +94,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) bareosdir-python3-module PROPERTIES PREFIX "" - CXX_STANDARD 11 + C_STANDARD 11 SUFFIX ${Python3_EXT_SUFFIX} LIBRARY_OUTPUT_DIRECTORY python3modules LIBRARY_OUTPUT_NAME bareosdir diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index bef74c38c70..08706bdc04e 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -96,7 +96,7 @@ if(Python2_FOUND AND NOT HAVE_WIN22) bareosfd-python2-module PROPERTIES PREFIX "" - CXX_STANDARD 11 + C_STANDARD 11 # SUFFIX ${Python2_EXT_SUFFIX} LIBRARY_OUTPUT_DIRECTORY pythonmodules LIBRARY_OUTPUT_NAME bareosfd @@ -130,7 +130,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) bareosfd-python3-module PROPERTIES PREFIX "" - CXX_STANDARD 11 + C_STANDARD 11 SUFFIX ${Python3_EXT_SUFFIX} LIBRARY_OUTPUT_DIRECTORY python3modules LIBRARY_OUTPUT_NAME bareosfd diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index 5e9106f5f43..b56978298a8 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -42,7 +42,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) bareossd-python2-module PROPERTIES PREFIX "" - CXX_STANDARD 11 + C_STANDARD 11 # SUFFIX ${Python2_EXT_SUFFIX} LIBRARY_OUTPUT_DIRECTORY pythonmodules LIBRARY_OUTPUT_NAME bareossd @@ -94,7 +94,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) bareossd-python3-module PROPERTIES PREFIX "" - CXX_STANDARD 11 + C_STANDARD 11 SUFFIX ${Python3_EXT_SUFFIX} LIBRARY_OUTPUT_DIRECTORY python3modules LIBRARY_OUTPUT_NAME bareossd From f456773d1c9c370eb48ec58514370c3eefed87a0 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 6 Jun 2020 11:44:54 +0200 Subject: [PATCH 194/341] cmake: removed LANGUAGE C --- core/src/plugins/dird/python/CMakeLists.txt | 4 ++-- core/src/plugins/filed/python/CMakeLists.txt | 4 ++-- core/src/plugins/stored/python/CMakeLists.txt | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt index c9f4e49e9ba..d30e8fdf497 100644 --- a/core/src/plugins/dird/python/CMakeLists.txt +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -36,7 +36,7 @@ if(Python2_FOUND) endif() if(Python2_FOUND AND NOT HAVE_WIN32) - set_property(SOURCE module/bareosdir.cc PROPERTY LANGUAGE C) + # set_property(SOURCE module/bareosdir.cc PROPERTY LANGUAGE C) add_library(bareosdir-python2-module MODULE module/bareosdir.cc) set_target_properties( bareosdir-python2-module @@ -88,7 +88,7 @@ if(Python3_FOUND) endif() if(Python3_FOUND AND NOT HAVE_WIN32) - set_property(SOURCE module/bareosdir.cc PROPERTY LANGUAGE C) + # set_property(SOURCE module/bareosdir.cc PROPERTY LANGUAGE C) add_library(bareosdir-python3-module MODULE module/bareosdir.cc) set_target_properties( bareosdir-python3-module diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 08706bdc04e..f233e2276e4 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -90,7 +90,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) endif() if(Python2_FOUND AND NOT HAVE_WIN22) - set_property(SOURCE module/bareosfd.cc PROPERTY LANGUAGE C) + # set_property(SOURCE module/bareosfd.cc PROPERTY LANGUAGE C) add_library(bareosfd-python2-module MODULE module/bareosfd.cc) set_target_properties( bareosfd-python2-module @@ -124,7 +124,7 @@ if(Python2_FOUND AND NOT HAVE_WIN22) endif() if(Python3_FOUND AND NOT HAVE_WIN32) - set_property(SOURCE module/bareosfd.cc PROPERTY LANGUAGE C) + # set_property(SOURCE module/bareosfd.cc PROPERTY LANGUAGE C) add_library(bareosfd-python3-module MODULE module/bareosfd.cc) set_target_properties( bareosfd-python3-module diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index b56978298a8..a049deaa082 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -36,7 +36,7 @@ if(Python2_FOUND) endif() if(Python2_FOUND AND NOT HAVE_WIN32) - set_property(SOURCE module/bareossd.cc PROPERTY LANGUAGE C) + # set_property(SOURCE module/bareossd.cc PROPERTY LANGUAGE C) add_library(bareossd-python2-module MODULE module/bareossd.cc) set_target_properties( bareossd-python2-module @@ -88,7 +88,7 @@ if(Python3_FOUND) endif() if(Python3_FOUND AND NOT HAVE_WIN32) - set_property(SOURCE module/bareossd.cc PROPERTY LANGUAGE C) + # set_property(SOURCE module/bareossd.cc PROPERTY LANGUAGE C) add_library(bareossd-python3-module MODULE module/bareossd.cc) set_target_properties( bareossd-python3-module From b366082f23411c7fde5f96780c82016a3cdf7d23 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 6 Jun 2020 12:14:57 +0200 Subject: [PATCH 195/341] cmake: cleanup --- core/src/plugins/dird/python/CMakeLists.txt | 6 ++---- core/src/plugins/filed/python/CMakeLists.txt | 6 ++---- core/src/plugins/stored/python/CMakeLists.txt | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt index d30e8fdf497..cc9f7aedffc 100644 --- a/core/src/plugins/dird/python/CMakeLists.txt +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -51,10 +51,9 @@ if(Python2_FOUND AND NOT HAVE_WIN32) COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" - LINK_LIBRARIES "bareos ${Python2_LIBRARIES}" LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) - add_dependencies(bareosdir-python2-module bareos) + target_link_libraries(bareosdir-python2-module bareos ${Python2_LIBRARIES}) add_test(NAME bareosdir-python2-module COMMAND ${Python2_EXECUTABLE} @@ -103,10 +102,9 @@ if(Python3_FOUND AND NOT HAVE_WIN32) COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" - LINK_LIBRARIES "bareos ${Python3_LIBRARIES}" LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) - add_dependencies(bareosdir-python3-module bareos) + target_link_libraries(bareosdir-python3-module bareos ${Python3_LIBRARIES}) add_test(NAME bareosdir-python3-module COMMAND ${Python3_EXECUTABLE} diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index f233e2276e4..e55d79211fc 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -105,10 +105,9 @@ if(Python2_FOUND AND NOT HAVE_WIN22) COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" - LINK_LIBRARIES "bareos ${Python2_LIBRARIES}" LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) - add_dependencies(bareosfd-python2-module bareos) + target_link_libraries(bareosfd-python2-module bareos ${Python2_LIBRARIES}) add_test(NAME bareosfd-python-module COMMAND ${Python2_EXECUTABLE} @@ -139,10 +138,9 @@ if(Python3_FOUND AND NOT HAVE_WIN32) COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" - LINK_LIBRARIES "bareos ${Python3_LIBRARIES}" LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) - add_dependencies(bareosfd-python3-module bareos) + target_link_libraries(bareosfd-python3-module bareos ${Python3_LIBRARIES}) add_test(NAME bareosfd-python3-module COMMAND ${Python3_EXECUTABLE} diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index a049deaa082..a8d6495c6a0 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -51,10 +51,9 @@ if(Python2_FOUND AND NOT HAVE_WIN32) COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" - LINK_LIBRARIES "bareos ${Python2_LIBRARIES}" LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) - add_dependencies(bareossd-python2-module bareos) + target_link_libraries(bareossd-python2-module bareos ${Python2_LIBRARIES}) add_test(NAME bareossd-python2-module COMMAND ${Python2_EXECUTABLE} @@ -103,10 +102,9 @@ if(Python3_FOUND AND NOT HAVE_WIN32) COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" - LINK_LIBRARIES "bareos ${Python3_LIBRARIES}" LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) - add_dependencies(bareossd-python3-module bareos) + target_link_libraries(bareossd-python3-module bareos ${Python3_LIBRARIES}) add_test(NAME bareossd-python3-module COMMAND ${Python3_EXECUTABLE} From 160db02c817bdf5ade314d1b8d85ccd79afd0d5e Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 6 Jun 2020 13:22:49 +0200 Subject: [PATCH 196/341] cmake: make python2.6 compatible for centos 6 --- core/cmake/get_python_compile_settings.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/core/cmake/get_python_compile_settings.py b/core/cmake/get_python_compile_settings.py index cc003ff1988..508db2d3384 100755 --- a/core/cmake/get_python_compile_settings.py +++ b/core/cmake/get_python_compile_settings.py @@ -25,11 +25,15 @@ # This is required to build python modules without setuptools. import sys -import sysconfig +try: + import sysconfig +except: + import distutils.sysconfig as sysconfig + for var in ("CC", "BLDSHARED"): value = sysconfig.get_config_var(var) - print ("message(STATUS \"Python{}_{}\ is\ {}\")" . format(sys.version_info.major, var, value)) - print ("set(Python{}_{} \"{}\")" . format(sys.version_info.major, var, value)) + print ("message(STATUS \"Python{0}_{1}\ is\ {2}\")" . format(sys.version_info[0], var, value)) + print ("set(Python{0}_{1} \"{2}\")" . format(sys.version_info[0], var, value)) # if nothing comes after the compile command, the flags are empty try: @@ -37,17 +41,17 @@ except: value = '' # as these vars contain the compiler itself, we remove the first word and return it as _FLAGS - print ("message(STATUS \"Python{}_{}_FLAGS\ is\ {}\")" . format(sys.version_info.major, var, value)) - print ("set(Python{}_{}_FLAGS \"{}\")" . format(sys.version_info.major, var, value)) + print ("message(STATUS \"Python{0}_{1}_FLAGS\ is\ {2}\")" . format(sys.version_info[0], var, value)) + print ("set(Python{0}_{1}_FLAGS \"{2}\")" . format(sys.version_info[0], var, value)) for var in ("CFLAGS","CCSHARED","INCLUDEPY","LDFLAGS"): value = sysconfig.get_config_var(var) - print ("message(STATUS \"Python{}_{}\ is\ {}\")" . format(sys.version_info.major, var, value)) - print ("set(Python{}_{} \"{}\")" . format(sys.version_info.major, var, value)) + print ("message(STATUS \"Python{0}_{1}\ is\ {2}\")" . format(sys.version_info[0], var, value)) + print ("set(Python{0}_{1} \"{2}\")" . format(sys.version_info[0], var, value)) for var in ("EXT_SUFFIX",): value = sysconfig.get_config_var(var) if value is None: value = '' - print ("message(STATUS \"Python{}_{}\ is\ {}\")" . format(sys.version_info.major, var, value)) - print ("set(Python{}_{} \"{}\")" . format(sys.version_info.major, var, value)) + print ("message(STATUS \"Python{0}_{1}\ is\ {2}\")" . format(sys.version_info[0], var, value)) + print ("set(Python{0}_{1} \"{2}\")" . format(sys.version_info[0], var, value)) From a686d2c37fabeecd148b53b5ab9df3510b103a71 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sun, 7 Jun 2020 11:18:45 +0200 Subject: [PATCH 197/341] cmake: REMOVED LINK_DIRECTORIES --- core/src/plugins/dird/python/CMakeLists.txt | 4 ++-- core/src/plugins/filed/python/CMakeLists.txt | 4 ++-- core/src/plugins/stored/python/CMakeLists.txt | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt index cc9f7aedffc..9a22f4da9cd 100644 --- a/core/src/plugins/dird/python/CMakeLists.txt +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -51,7 +51,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" - LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib + # LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) target_link_libraries(bareosdir-python2-module bareos ${Python2_LIBRARIES}) @@ -102,7 +102,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" - LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib + # LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) target_link_libraries(bareosdir-python3-module bareos ${Python3_LIBRARIES}) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index e55d79211fc..14e9845e3df 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -105,7 +105,7 @@ if(Python2_FOUND AND NOT HAVE_WIN22) COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" - LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib + # LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) target_link_libraries(bareosfd-python2-module bareos ${Python2_LIBRARIES}) @@ -138,7 +138,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" - LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib + # LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) target_link_libraries(bareosfd-python3-module bareos ${Python3_LIBRARIES}) diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index a8d6495c6a0..8509d166f22 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -51,7 +51,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" - LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib + # LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) target_link_libraries(bareossd-python2-module bareos ${Python2_LIBRARIES}) @@ -102,7 +102,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" - LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib + # LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) target_link_libraries(bareossd-python3-module bareos ${Python3_LIBRARIES}) From b82ff03033e453c304fba5f3e73299bf92004aa8 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sun, 7 Jun 2020 11:29:07 +0200 Subject: [PATCH 198/341] systemtests: warning removed --- core/cmake/BareosFindAllLibraries.cmake | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/cmake/BareosFindAllLibraries.cmake b/core/cmake/BareosFindAllLibraries.cmake index 5278201d4f5..109176fdf2a 100644 --- a/core/cmake/BareosFindAllLibraries.cmake +++ b/core/cmake/BareosFindAllLibraries.cmake @@ -56,7 +56,6 @@ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/py2settings.cmake ) include(${CMAKE_CURRENT_SOURCE_DIR}/py2settings.cmake) - message("Python2_CC is ${Python2_CC}") endif() if(${Python3_FOUND}) @@ -65,7 +64,6 @@ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/py3settings.cmake ) include(${CMAKE_CURRENT_SOURCE_DIR}/py3settings.cmake) - message("Python3_CC is ${Python3_CC}") endif() From 0ac658d4d7b5f4db1763ef48a74359e51f9f256c Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sun, 7 Jun 2020 11:40:37 +0200 Subject: [PATCH 199/341] python plugins: FreeBSD include dir --- core/src/plugins/dird/python/CMakeLists.txt | 4 ++-- core/src/plugins/filed/python/CMakeLists.txt | 4 ++-- core/src/plugins/stored/python/CMakeLists.txt | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt index 9a22f4da9cd..4f393c87dd9 100644 --- a/core/src/plugins/dird/python/CMakeLists.txt +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -50,7 +50,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) LINKER_LANGUAGE CXX COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES - "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/include;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" # LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) target_link_libraries(bareosdir-python2-module bareos ${Python2_LIBRARIES}) @@ -101,7 +101,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LINKER_LANGUAGE CXX COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES - "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/include;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" # LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) target_link_libraries(bareosdir-python3-module bareos ${Python3_LIBRARIES}) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 14e9845e3df..dfe87708f18 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -104,7 +104,7 @@ if(Python2_FOUND AND NOT HAVE_WIN22) LINKER_LANGUAGE CXX COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES - "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/include;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" # LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) target_link_libraries(bareosfd-python2-module bareos ${Python2_LIBRARIES}) @@ -137,7 +137,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LINKER_LANGUAGE CXX COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES - "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/include;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" # LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) target_link_libraries(bareosfd-python3-module bareos ${Python3_LIBRARIES}) diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index 8509d166f22..7f980c2b9d8 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -50,7 +50,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) LINKER_LANGUAGE CXX COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES - "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/include;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" # LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) target_link_libraries(bareossd-python2-module bareos ${Python2_LIBRARIES}) @@ -101,7 +101,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LINKER_LANGUAGE CXX COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES - "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/include;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" # LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) target_link_libraries(bareossd-python3-module bareos ${Python3_LIBRARIES}) From bdcab7ed82fdf34a6418be04e43f289c04e08005 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sun, 7 Jun 2020 12:02:50 +0200 Subject: [PATCH 200/341] cmake: python plugin build: cleanup --- core/src/plugins/dird/python/CMakeLists.txt | 4 ---- core/src/plugins/filed/python/CMakeLists.txt | 4 ---- core/src/plugins/stored/python/CMakeLists.txt | 4 ---- 3 files changed, 12 deletions(-) diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt index 4f393c87dd9..2c93eb9b526 100644 --- a/core/src/plugins/dird/python/CMakeLists.txt +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -36,7 +36,6 @@ if(Python2_FOUND) endif() if(Python2_FOUND AND NOT HAVE_WIN32) - # set_property(SOURCE module/bareosdir.cc PROPERTY LANGUAGE C) add_library(bareosdir-python2-module MODULE module/bareosdir.cc) set_target_properties( bareosdir-python2-module @@ -51,7 +50,6 @@ if(Python2_FOUND AND NOT HAVE_WIN32) COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/include;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" - # LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) target_link_libraries(bareosdir-python2-module bareos ${Python2_LIBRARIES}) @@ -87,7 +85,6 @@ if(Python3_FOUND) endif() if(Python3_FOUND AND NOT HAVE_WIN32) - # set_property(SOURCE module/bareosdir.cc PROPERTY LANGUAGE C) add_library(bareosdir-python3-module MODULE module/bareosdir.cc) set_target_properties( bareosdir-python3-module @@ -102,7 +99,6 @@ if(Python3_FOUND AND NOT HAVE_WIN32) COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/include;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" - # LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) target_link_libraries(bareosdir-python3-module bareos ${Python3_LIBRARIES}) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index dfe87708f18..ceea8813aa3 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -90,7 +90,6 @@ if(Python3_FOUND AND NOT HAVE_WIN32) endif() if(Python2_FOUND AND NOT HAVE_WIN22) - # set_property(SOURCE module/bareosfd.cc PROPERTY LANGUAGE C) add_library(bareosfd-python2-module MODULE module/bareosfd.cc) set_target_properties( bareosfd-python2-module @@ -105,7 +104,6 @@ if(Python2_FOUND AND NOT HAVE_WIN22) COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/include;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" - # LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) target_link_libraries(bareosfd-python2-module bareos ${Python2_LIBRARIES}) @@ -123,7 +121,6 @@ if(Python2_FOUND AND NOT HAVE_WIN22) endif() if(Python3_FOUND AND NOT HAVE_WIN32) - # set_property(SOURCE module/bareosfd.cc PROPERTY LANGUAGE C) add_library(bareosfd-python3-module MODULE module/bareosfd.cc) set_target_properties( bareosfd-python3-module @@ -138,7 +135,6 @@ if(Python3_FOUND AND NOT HAVE_WIN32) COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/include;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" - # LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) target_link_libraries(bareosfd-python3-module bareos ${Python3_LIBRARIES}) diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index 7f980c2b9d8..98be1e8faed 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -36,14 +36,12 @@ if(Python2_FOUND) endif() if(Python2_FOUND AND NOT HAVE_WIN32) - # set_property(SOURCE module/bareossd.cc PROPERTY LANGUAGE C) add_library(bareossd-python2-module MODULE module/bareossd.cc) set_target_properties( bareossd-python2-module PROPERTIES PREFIX "" C_STANDARD 11 - # SUFFIX ${Python2_EXT_SUFFIX} LIBRARY_OUTPUT_DIRECTORY pythonmodules LIBRARY_OUTPUT_NAME bareossd LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" @@ -51,7 +49,6 @@ if(Python2_FOUND AND NOT HAVE_WIN32) COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/include;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" - # LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) target_link_libraries(bareossd-python2-module bareos ${Python2_LIBRARIES}) @@ -102,7 +99,6 @@ if(Python3_FOUND AND NOT HAVE_WIN32) COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/include;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" - # LINK_DIRECTORIES ${PROJECT_BINARY_DIR}/src/lib ) target_link_libraries(bareossd-python3-module bareos ${Python3_LIBRARIES}) From 856ef8c6f549366c1502f902c1176370686486b9 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sun, 7 Jun 2020 12:40:19 +0200 Subject: [PATCH 201/341] cmake: INTLINCLUDE_DIRS --- core/src/plugins/dird/python/CMakeLists.txt | 4 ++-- core/src/plugins/filed/python/CMakeLists.txt | 4 ++-- core/src/plugins/stored/python/CMakeLists.txt | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt index 2c93eb9b526..1e788f05d44 100644 --- a/core/src/plugins/dird/python/CMakeLists.txt +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -49,7 +49,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) LINKER_LANGUAGE CXX COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES - "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/include;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${INTLINCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) target_link_libraries(bareosdir-python2-module bareos ${Python2_LIBRARIES}) @@ -98,7 +98,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LINKER_LANGUAGE CXX COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES - "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/include;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${INTLINCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) target_link_libraries(bareosdir-python3-module bareos ${Python3_LIBRARIES}) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index ceea8813aa3..6e6b6571873 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -103,7 +103,7 @@ if(Python2_FOUND AND NOT HAVE_WIN22) LINKER_LANGUAGE CXX COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES - "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/include;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${INTLINCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) target_link_libraries(bareosfd-python2-module bareos ${Python2_LIBRARIES}) @@ -134,7 +134,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LINKER_LANGUAGE CXX COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES - "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/include;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${INTLINCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) target_link_libraries(bareosfd-python3-module bareos ${Python3_LIBRARIES}) diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index 98be1e8faed..c23a26365a2 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -48,7 +48,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) LINKER_LANGUAGE CXX COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES - "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/include;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${INTLINCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) target_link_libraries(bareossd-python2-module bareos ${Python2_LIBRARIES}) @@ -98,7 +98,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LINKER_LANGUAGE CXX COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES - "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;/usr/local/include;/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${INTLINCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) target_link_libraries(bareossd-python3-module bareos ${Python3_LIBRARIES}) From 80bfe298ba8b5f813df07dd8d09a49529263c251 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sun, 7 Jun 2020 17:42:30 +0200 Subject: [PATCH 202/341] cmake: INTLINCLUDE_DIRS -> Intl_INCLUDE_DIRS --- core/src/plugins/dird/python/CMakeLists.txt | 4 ++-- core/src/plugins/filed/python/CMakeLists.txt | 4 ++-- core/src/plugins/stored/python/CMakeLists.txt | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt index 1e788f05d44..2f9b17f6d8e 100644 --- a/core/src/plugins/dird/python/CMakeLists.txt +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -49,7 +49,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) LINKER_LANGUAGE CXX COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES - "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${INTLINCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) target_link_libraries(bareosdir-python2-module bareos ${Python2_LIBRARIES}) @@ -98,7 +98,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LINKER_LANGUAGE CXX COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES - "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${INTLINCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) target_link_libraries(bareosdir-python3-module bareos ${Python3_LIBRARIES}) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 6e6b6571873..076fff1c745 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -103,7 +103,7 @@ if(Python2_FOUND AND NOT HAVE_WIN22) LINKER_LANGUAGE CXX COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES - "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${INTLINCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) target_link_libraries(bareosfd-python2-module bareos ${Python2_LIBRARIES}) @@ -134,7 +134,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LINKER_LANGUAGE CXX COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES - "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${INTLINCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) target_link_libraries(bareosfd-python3-module bareos ${Python3_LIBRARIES}) diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index c23a26365a2..fc333060e81 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -48,7 +48,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) LINKER_LANGUAGE CXX COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES - "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${INTLINCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) target_link_libraries(bareossd-python2-module bareos ${Python2_LIBRARIES}) @@ -98,7 +98,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LINKER_LANGUAGE CXX COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES - "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${INTLINCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) target_link_libraries(bareossd-python3-module bareos ${Python3_LIBRARIES}) From 85ae8ee693707d2a276e68e1a25bcd7531af93fa Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sun, 7 Jun 2020 18:21:14 +0200 Subject: [PATCH 203/341] cmake: python detection cmake < 3.12.0 --- core/cmake/BareosFindAllLibraries.cmake | 33 +++++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/core/cmake/BareosFindAllLibraries.cmake b/core/cmake/BareosFindAllLibraries.cmake index 109176fdf2a..4bddc77c55c 100644 --- a/core/cmake/BareosFindAllLibraries.cmake +++ b/core/cmake/BareosFindAllLibraries.cmake @@ -25,22 +25,39 @@ endif() if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") if(${CMAKE_VERSION} VERSION_LESS "3.12.0") message(status "CMake too old for FindPython2/3, using FindPythonInterp") + set( Python_ADDITIONAL_VERSIONS 2.6 2.7) find_package(PythonInterp) find_package(PythonLibs) - set(Python2_FOUND ${PYTHONLIBS_FOUND}) - set(Python2_LIBRARIES ${PYTHON_LIBRARIES}) - set(Python2_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS}) - set(Python2_EXECUTABLE ${PYTHON_EXECUTABLE}) + if (Python_VERSION_MAJOR EQUAL 2) + set(Python2_FOUND ${PYTHONLIBS_FOUND}) + set(Python2_LIBRARIES ${PYTHON_LIBRARIES}) + set(Python2_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS}) + set(Python2_EXECUTABLE ${PYTHON_EXECUTABLE}) + elseif (Python_VERSION_MAJOR EQUAL 3) + set(Python3_FOUND ${PYTHONLIBS_FOUND}) + set(Python3_LIBRARIES ${PYTHON_LIBRARIES}) + set(Python3_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS}) + set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE}) + endif() set( Python_ADDITIONAL_VERSIONS 3.6 3.7 3.8 3.9) find_package(PythonInterp) find_package(PythonLibs) - set(Python3_FOUND ${PYTHONLIBS_FOUND}) - set(Python3_LIBRARIES ${PYTHON_LIBRARIES}) - set(Python3_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS}) - set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE}) + + if (Python_VERSION_MAJOR EQUAL 2) + set(Python2_FOUND ${PYTHONLIBS_FOUND}) + set(Python2_LIBRARIES ${PYTHON_LIBRARIES}) + set(Python2_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS}) + set(Python2_EXECUTABLE ${PYTHON_EXECUTABLE}) + elseif (Python_VERSION_MAJOR EQUAL 3) + set(Python3_FOUND ${PYTHONLIBS_FOUND}) + set(Python3_LIBRARIES ${PYTHON_LIBRARIES}) + set(Python3_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS}) + set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE}) + endif() + else() find_package (Python2 COMPONENTS Interpreter Development) find_package (Python3 COMPONENTS Interpreter Development) From 57a4231d935d2497d1108ef109de362726cb6296 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sun, 7 Jun 2020 18:23:23 +0200 Subject: [PATCH 204/341] cmake: CCCSHARED removed --- core/src/plugins/dird/python/CMakeLists.txt | 4 ++-- core/src/plugins/filed/python/CMakeLists.txt | 4 ++-- core/src/plugins/stored/python/CMakeLists.txt | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt index 2f9b17f6d8e..226a2b8ea8b 100644 --- a/core/src/plugins/dird/python/CMakeLists.txt +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -47,7 +47,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) LIBRARY_OUTPUT_NAME bareosdir LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX - COMPILE_OPTIONS ${Python2_CCSHARED} + #COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) @@ -96,7 +96,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LIBRARY_OUTPUT_NAME bareosdir LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX - COMPILE_OPTIONS ${Python3_CCSHARED} + #COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 076fff1c745..084f0e349a6 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -101,7 +101,7 @@ if(Python2_FOUND AND NOT HAVE_WIN22) LIBRARY_OUTPUT_NAME bareosfd LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX - COMPILE_OPTIONS ${Python2_CCSHARED} + #COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) @@ -132,7 +132,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LIBRARY_OUTPUT_NAME bareosfd LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX - COMPILE_OPTIONS ${Python3_CCSHARED} + #COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index fc333060e81..c5c24479fe1 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -46,7 +46,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) LIBRARY_OUTPUT_NAME bareossd LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX - COMPILE_OPTIONS ${Python2_CCSHARED} + #COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) @@ -96,7 +96,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LIBRARY_OUTPUT_NAME bareossd LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX - COMPILE_OPTIONS ${Python3_CCSHARED} + #COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) From db3a90d01c6cf36070fbd90b09961d892273d29b Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sun, 7 Jun 2020 19:02:25 +0200 Subject: [PATCH 205/341] Revert "CCCSHARED removed" This reverts commit 84b4f716bfd06e1d1b91e9621c5f587e92222891. --- core/src/plugins/dird/python/CMakeLists.txt | 4 ++-- core/src/plugins/filed/python/CMakeLists.txt | 4 ++-- core/src/plugins/stored/python/CMakeLists.txt | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt index 226a2b8ea8b..2f9b17f6d8e 100644 --- a/core/src/plugins/dird/python/CMakeLists.txt +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -47,7 +47,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) LIBRARY_OUTPUT_NAME bareosdir LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX - #COMPILE_OPTIONS ${Python2_CCSHARED} + COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) @@ -96,7 +96,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LIBRARY_OUTPUT_NAME bareosdir LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX - #COMPILE_OPTIONS ${Python3_CCSHARED} + COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 084f0e349a6..076fff1c745 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -101,7 +101,7 @@ if(Python2_FOUND AND NOT HAVE_WIN22) LIBRARY_OUTPUT_NAME bareosfd LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX - #COMPILE_OPTIONS ${Python2_CCSHARED} + COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) @@ -132,7 +132,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LIBRARY_OUTPUT_NAME bareosfd LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX - #COMPILE_OPTIONS ${Python3_CCSHARED} + COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index c5c24479fe1..fc333060e81 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -46,7 +46,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) LIBRARY_OUTPUT_NAME bareossd LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX - #COMPILE_OPTIONS ${Python2_CCSHARED} + COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) @@ -96,7 +96,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LIBRARY_OUTPUT_NAME bareossd LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX - #COMPILE_OPTIONS ${Python3_CCSHARED} + COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) From b6e28f76db60539179cd1efda98d041d3b1c3f78 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sun, 7 Jun 2020 19:15:37 +0200 Subject: [PATCH 206/341] cmake: set COMPILE_OPTIONS only if they are empty --- core/src/plugins/dird/python/CMakeLists.txt | 14 ++++++++++++-- core/src/plugins/filed/python/CMakeLists.txt | 14 ++++++++++++-- core/src/plugins/stored/python/CMakeLists.txt | 12 ++++++++++-- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt index 2f9b17f6d8e..70b72173012 100644 --- a/core/src/plugins/dird/python/CMakeLists.txt +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -47,10 +47,15 @@ if(Python2_FOUND AND NOT HAVE_WIN32) LIBRARY_OUTPUT_NAME bareosdir LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX - COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) + if(NOT "${Python2_CCSHARED}" STREQUAL "") + set_property( + TARGET bareosdir-python2-module PROPERTY COMPILE_OPTIONS + ${Python2_CCSHARED} + ) + endif() target_link_libraries(bareosdir-python2-module bareos ${Python2_LIBRARIES}) add_test(NAME bareosdir-python2-module @@ -96,10 +101,15 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LIBRARY_OUTPUT_NAME bareosdir LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX - COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) + if(NOT "${Python3_CCSHARED}" STREQUAL "") + set_property( + TARGET bareosdir-python3-module PROPERTY COMPILE_OPTIONS + ${Python3_CCSHARED} + ) + endif() target_link_libraries(bareosdir-python3-module bareos ${Python3_LIBRARIES}) add_test(NAME bareosdir-python3-module diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 076fff1c745..69f3e89118d 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -101,10 +101,15 @@ if(Python2_FOUND AND NOT HAVE_WIN22) LIBRARY_OUTPUT_NAME bareosfd LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX - COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) + if(NOT "${Python2_CCSHARED}" STREQUAL "") + set_property( + TARGET bareosdir-python2-module PROPERTY COMPILE_OPTIONS + ${Python2_CCSHARED} + ) + endif() target_link_libraries(bareosfd-python2-module bareos ${Python2_LIBRARIES}) add_test(NAME bareosfd-python-module @@ -132,10 +137,15 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LIBRARY_OUTPUT_NAME bareosfd LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX - COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) + if(NOT "${Python3_CCSHARED}" STREQUAL "") + set_property( + TARGET bareosdir-python3-module PROPERTY COMPILE_OPTIONS + ${Python3_CCSHARED} + ) + endif() target_link_libraries(bareosfd-python3-module bareos ${Python3_LIBRARIES}) add_test(NAME bareosfd-python3-module diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index fc333060e81..7c74262eaf2 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -46,10 +46,14 @@ if(Python2_FOUND AND NOT HAVE_WIN32) LIBRARY_OUTPUT_NAME bareossd LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX - COMPILE_OPTIONS ${Python2_CCSHARED} INCLUDE_DIRECTORIES "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) + if(NOT "${Python2_CCSHARED}" STREQUAL "") + set_property( + TARGET bareosdir-python2-module PROPERTY COMPILE_OPTIONS + ${Python2_CCSHARED} + ) target_link_libraries(bareossd-python2-module bareos ${Python2_LIBRARIES}) add_test(NAME bareossd-python2-module @@ -96,10 +100,14 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LIBRARY_OUTPUT_NAME bareossd LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX - COMPILE_OPTIONS ${Python3_CCSHARED} INCLUDE_DIRECTORIES "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" ) + if(NOT "${Python3_CCSHARED}" STREQUAL "") + set_property( + TARGET bareosdir-python3-module PROPERTY COMPILE_OPTIONS + ${Python3_CCSHARED} + ) target_link_libraries(bareossd-python3-module bareos ${Python3_LIBRARIES}) add_test(NAME bareossd-python3-module From df8b99c50e3a46601a60ef3b5f3e4447a5a1f21e Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sun, 7 Jun 2020 19:23:56 +0200 Subject: [PATCH 207/341] cmake: fixup endif --- core/src/plugins/stored/python/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index 7c74262eaf2..ec65c9260aa 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -54,6 +54,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) TARGET bareosdir-python2-module PROPERTY COMPILE_OPTIONS ${Python2_CCSHARED} ) + endif() target_link_libraries(bareossd-python2-module bareos ${Python2_LIBRARIES}) add_test(NAME bareossd-python2-module @@ -108,6 +109,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) TARGET bareosdir-python3-module PROPERTY COMPILE_OPTIONS ${Python3_CCSHARED} ) + endif() target_link_libraries(bareossd-python3-module bareos ${Python3_LIBRARIES}) add_test(NAME bareossd-python3-module From d7f20c358418efd915f84a56e77e0c31f9c0d3b0 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sun, 7 Jun 2020 19:30:18 +0200 Subject: [PATCH 208/341] cmake python: fix names --- core/src/plugins/filed/python/CMakeLists.txt | 8 ++++---- core/src/plugins/stored/python/CMakeLists.txt | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 69f3e89118d..475b44bb58f 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -106,8 +106,8 @@ if(Python2_FOUND AND NOT HAVE_WIN22) ) if(NOT "${Python2_CCSHARED}" STREQUAL "") set_property( - TARGET bareosdir-python2-module PROPERTY COMPILE_OPTIONS - ${Python2_CCSHARED} + TARGET bareosfd-python2-module PROPERTY COMPILE_OPTIONS + ${Python2_CCSHARED} ) endif() target_link_libraries(bareosfd-python2-module bareos ${Python2_LIBRARIES}) @@ -142,8 +142,8 @@ if(Python3_FOUND AND NOT HAVE_WIN32) ) if(NOT "${Python3_CCSHARED}" STREQUAL "") set_property( - TARGET bareosdir-python3-module PROPERTY COMPILE_OPTIONS - ${Python3_CCSHARED} + TARGET bareosfd-python3-module PROPERTY COMPILE_OPTIONS + ${Python3_CCSHARED} ) endif() target_link_libraries(bareosfd-python3-module bareos ${Python3_LIBRARIES}) diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index ec65c9260aa..205dc59e585 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -51,8 +51,8 @@ if(Python2_FOUND AND NOT HAVE_WIN32) ) if(NOT "${Python2_CCSHARED}" STREQUAL "") set_property( - TARGET bareosdir-python2-module PROPERTY COMPILE_OPTIONS - ${Python2_CCSHARED} + TARGET bareossd-python2-module PROPERTY COMPILE_OPTIONS + ${Python2_CCSHARED} ) endif() target_link_libraries(bareossd-python2-module bareos ${Python2_LIBRARIES}) @@ -106,8 +106,8 @@ if(Python3_FOUND AND NOT HAVE_WIN32) ) if(NOT "${Python3_CCSHARED}" STREQUAL "") set_property( - TARGET bareosdir-python3-module PROPERTY COMPILE_OPTIONS - ${Python3_CCSHARED} + TARGET bareossd-python3-module PROPERTY COMPILE_OPTIONS + ${Python3_CCSHARED} ) endif() target_link_libraries(bareossd-python3-module bareos ${Python3_LIBRARIES}) From 94ef37b2ff8b65b79dfc075927a6aeae90b8dddd Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sun, 7 Jun 2020 20:27:14 +0200 Subject: [PATCH 209/341] cmake: PYTHON_VERSION_MAJOR spelling --- core/cmake/BareosFindAllLibraries.cmake | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core/cmake/BareosFindAllLibraries.cmake b/core/cmake/BareosFindAllLibraries.cmake index 4bddc77c55c..f5c304f9e5d 100644 --- a/core/cmake/BareosFindAllLibraries.cmake +++ b/core/cmake/BareosFindAllLibraries.cmake @@ -24,18 +24,19 @@ endif() if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") if(${CMAKE_VERSION} VERSION_LESS "3.12.0") - message(status "CMake too old for FindPython2/3, using FindPythonInterp") + message(STATUS "CMake too old for FindPython2/3, using FindPythonInterp") set( Python_ADDITIONAL_VERSIONS 2.6 2.7) find_package(PythonInterp) find_package(PythonLibs) - - if (Python_VERSION_MAJOR EQUAL 2) + message(STATUS "Found PYTHON_VERSION_MAJOR" ${PYTHON_VERSION_MAJOR}) + if (PYTHON_VERSION_MAJOR EQUAL 2) set(Python2_FOUND ${PYTHONLIBS_FOUND}) set(Python2_LIBRARIES ${PYTHON_LIBRARIES}) set(Python2_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS}) set(Python2_EXECUTABLE ${PYTHON_EXECUTABLE}) - elseif (Python_VERSION_MAJOR EQUAL 3) + + elseif (PYTHON_VERSION_MAJOR EQUAL 3) set(Python3_FOUND ${PYTHONLIBS_FOUND}) set(Python3_LIBRARIES ${PYTHON_LIBRARIES}) set(Python3_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS}) @@ -45,13 +46,14 @@ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") set( Python_ADDITIONAL_VERSIONS 3.6 3.7 3.8 3.9) find_package(PythonInterp) find_package(PythonLibs) + message(STATUS "Found PYTHON_VERSION_MAJOR" ${PYTHON_VERSION_MAJOR}) - if (Python_VERSION_MAJOR EQUAL 2) + if (PYTHON_VERSION_MAJOR EQUAL 2) set(Python2_FOUND ${PYTHONLIBS_FOUND}) set(Python2_LIBRARIES ${PYTHON_LIBRARIES}) set(Python2_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS}) set(Python2_EXECUTABLE ${PYTHON_EXECUTABLE}) - elseif (Python_VERSION_MAJOR EQUAL 3) + elseif (PYTHON_VERSION_MAJOR EQUAL 3) set(Python3_FOUND ${PYTHONLIBS_FOUND}) set(Python3_LIBRARIES ${PYTHON_LIBRARIES}) set(Python3_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS}) From ff16ccd650cb40bb9f65bf1a6ff705385a0585c9 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sun, 7 Jun 2020 20:47:57 +0200 Subject: [PATCH 210/341] cmake: Initialize Python{2,3}_FOUND --- core/cmake/BareosFindAllLibraries.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/cmake/BareosFindAllLibraries.cmake b/core/cmake/BareosFindAllLibraries.cmake index f5c304f9e5d..b6c88a30b46 100644 --- a/core/cmake/BareosFindAllLibraries.cmake +++ b/core/cmake/BareosFindAllLibraries.cmake @@ -25,7 +25,8 @@ endif() if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") if(${CMAKE_VERSION} VERSION_LESS "3.12.0") message(STATUS "CMake too old for FindPython2/3, using FindPythonInterp") - + set(Python2_FOUND FALSE) + set(Python3_FOUND FALSE) set( Python_ADDITIONAL_VERSIONS 2.6 2.7) find_package(PythonInterp) find_package(PythonLibs) From 105caf29229f7f0159867e6514d76ad5539cf581 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sun, 7 Jun 2020 21:16:49 +0200 Subject: [PATCH 211/341] cmake: exclude sd and dir from win32 --- core/cmake/BareosFindAllLibraries.cmake | 2 -- core/src/plugins/dird/python/CMakeLists.txt | 2 +- core/src/plugins/stored/python/CMakeLists.txt | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/core/cmake/BareosFindAllLibraries.cmake b/core/cmake/BareosFindAllLibraries.cmake index b6c88a30b46..ca0699df185 100644 --- a/core/cmake/BareosFindAllLibraries.cmake +++ b/core/cmake/BareosFindAllLibraries.cmake @@ -86,8 +86,6 @@ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") include(${CMAKE_CURRENT_SOURCE_DIR}/py3settings.cmake) endif() - - else() # windows set(HAVE_PYTHON 1) set(Python2_FOUND 1) diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt index 70b72173012..75771dbef05 100644 --- a/core/src/plugins/dird/python/CMakeLists.txt +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -17,7 +17,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. -if(Python2_FOUND) +if(Python2_FOUND AND NOT HAVE_WIN32) add_library(python-dir MODULE python-dir.cc) # do not prefix with "lib" set_target_properties( diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index 205dc59e585..0bdd75f716a 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -17,7 +17,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. -if(Python2_FOUND) +if(Python2_FOUND AND NOT HAVE_WIN32) add_library(python-sd MODULE python-sd.cc) set_target_properties( python-sd PROPERTIES PREFIX "" LIBRARY_OUTPUT_DIRECTORY .. From fd797ce0f1aaba9e4a792f6380226461462e554e Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 8 Jun 2020 12:23:03 +0200 Subject: [PATCH 212/341] cmake: windows cross build works without extracting to sources --- CMakeLists.txt | 8 ++++---- core/CMakeLists.txt | 19 ++++++------------- core/src/plugins/filed/python/CMakeLists.txt | 4 ++-- .../python/test/python-fd-module-tester.cc | 4 ++++ 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8826daac6f..8df5f781348 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,11 +24,11 @@ project(bareos NONE) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/core/cmake") -add_custom_target(uninstall - "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake" +add_custom_target( + uninstall "${CMAKE_COMMAND}" -P + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake" ) - set(default_build_type "Debug") find_package(Git) @@ -74,7 +74,7 @@ endif() if(BUILD_BAREOS_BINARIES) add_subdirectory(core) add_subdirectory(webui) - if(NOT client-only AND NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") + if(NOT client-only AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") add_subdirectory(systemtests) endif() endif() diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index ca9734e3f30..fd4850717df 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -300,19 +300,12 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") set(WINDOWS_LIBRARIES ws2_32) - set(Python2_LIBRARIES - ${PROJECT_SOURCE_DIR}/src/win32/plugins/python/lib/${WINDOWS_BITS}/python27.dll - ) - set(Python2_INCLUDE_DIRS - ${PROJECT_SOURCE_DIR}/src/win32/plugins/python/include - ) - set(PostgreSQL_LIBRARY - ${PROJECT_SOURCE_DIR}/src/win32/cats/pgsql/lib/${WINDOWS_BITS}/libpq.dll - ) - set(PostgreSQL_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/src/win32/cats/pgsql/include) - set(PostgreSQL_TYPE_INCLUDE_DIR - ${PROJECT_SOURCE_DIR}/src/win32/plugins/python/include - ) + set(Python2_LIBRARIES python27.dll) + set(Python2_INCLUDE_DIRS ) + + set(PostgreSQL_LIBRARY libpq.dll) + set(PostgreSQL_INCLUDE_DIR "") + set(PostgreSQL_TYPE_INCLUDE_DIR "") set(dynamic-storage-backends OFF) set(HAVE_DYNAMIC_SD_BACKENDS 0) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 475b44bb58f..a9aaf3ddd91 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -49,7 +49,7 @@ if(Python3_FOUND) add_dependencies(python3-fd bareosfd-python3-module) endif() -if(Python2_FOUND AND NOT HAVE_WIN22) +if(Python2_FOUND) add_executable(bareosfd-python2-module-tester test/python-fd-module-tester.cc) target_link_libraries( bareosfd-python2-module-tester ${Python2_LIBRARIES} bareos @@ -89,7 +89,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) ) endif() -if(Python2_FOUND AND NOT HAVE_WIN22) +if(Python2_FOUND) add_library(bareosfd-python2-module MODULE module/bareosfd.cc) set_target_properties( bareosfd-python2-module diff --git a/core/src/plugins/filed/python/test/python-fd-module-tester.cc b/core/src/plugins/filed/python/test/python-fd-module-tester.cc index 0f531dd86b0..47bf038823d 100644 --- a/core/src/plugins/filed/python/test/python-fd-module-tester.cc +++ b/core/src/plugins/filed/python/test/python-fd-module-tester.cc @@ -21,6 +21,10 @@ /* Load the python-fd plugin and test it */ +#if defined(HAVE_MINGW) +#include "include/bareos.h" +#endif + #include "Python.h" #include "plugins/include/capsulethunk.h" #include "plugins/include/python3compat.h" From b54dbed5f9022442a273641516ccbca0f2e854ab Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 8 Jun 2020 12:25:17 +0200 Subject: [PATCH 213/341] cmake filed: fixup forgotten parts --- core/src/plugins/filed/python/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index a9aaf3ddd91..2a7dd7b1e64 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -102,7 +102,7 @@ if(Python2_FOUND) LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX INCLUDE_DIRECTORIES - "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include;${PROJECT_SOURCE_DIR}/src/win32/compat/include;${PROJECT_SOURCE_DIR}/src/win32/include" ) if(NOT "${Python2_CCSHARED}" STREQUAL "") set_property( From 431e0e4256726de0b2558d66ed43657255ad293b Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 8 Jun 2020 14:55:22 +0200 Subject: [PATCH 214/341] python ldap plugin: add examples --- core/CMakeLists.txt | 2 +- .../bareos-dir.d/fileset/plugin-ldap.conf.example | 13 ------------- .../bareos-dir.d/fileset/plugin-ovirt.conf.example | 10 ---------- 3 files changed, 1 insertion(+), 24 deletions(-) delete mode 100644 core/src/plugins/filed/python/ldap/python-ldap-conf.d/bareos-dir.d/fileset/plugin-ldap.conf.example delete mode 100644 core/src/plugins/filed/python/ovirt/python-ovirt-conf.d/bareos-dir.d/fileset/plugin-ovirt.conf.example diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index fd4850717df..23d408f88b6 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -301,7 +301,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") set(WINDOWS_LIBRARIES ws2_32) set(Python2_LIBRARIES python27.dll) - set(Python2_INCLUDE_DIRS ) + set(Python2_INCLUDE_DIRS /usr/x86_64-w64-mingw32/include/python2/) set(PostgreSQL_LIBRARY libpq.dll) set(PostgreSQL_INCLUDE_DIR "") diff --git a/core/src/plugins/filed/python/ldap/python-ldap-conf.d/bareos-dir.d/fileset/plugin-ldap.conf.example b/core/src/plugins/filed/python/ldap/python-ldap-conf.d/bareos-dir.d/fileset/plugin-ldap.conf.example deleted file mode 100644 index 61a873a3780..00000000000 --- a/core/src/plugins/filed/python/ldap/python-ldap-conf.d/bareos-dir.d/fileset/plugin-ldap.conf.example +++ /dev/null @@ -1,13 +0,0 @@ - -FileSet { - Name = "plugin-ldap" - Include { - Options { - signature = MD5 - } - # adapt the LDAP settings to your environment. - # uri and basedn are mandantory, - # base_dn and password are optional. - Plugin = "python:module_path=/usr/local/lib64/bareos/plugins:module_name=bareos-fd-ldap:uri=ldap\\://localhost:basedn=dc=example,dc=com:bind_dn=cn=admin,dc=example,dc=com:password=secret" - } -} diff --git a/core/src/plugins/filed/python/ovirt/python-ovirt-conf.d/bareos-dir.d/fileset/plugin-ovirt.conf.example b/core/src/plugins/filed/python/ovirt/python-ovirt-conf.d/bareos-dir.d/fileset/plugin-ovirt.conf.example deleted file mode 100644 index 0dc15fb400d..00000000000 --- a/core/src/plugins/filed/python/ovirt/python-ovirt-conf.d/bareos-dir.d/fileset/plugin-ovirt.conf.example +++ /dev/null @@ -1,10 +0,0 @@ -FileSet { - Name = "plugin-ovirt" - Include { - Options { - signature = MD5 - } - # - Plugin = "python:module_path=/usr/local/lib64/bareos/plugins:module_name=bareos-fd-ovirt:ca=/etc/bareos/ovirt-ca.cert:server=ovirt-engine.example.com:username=admin@internal:password=yourSecretPassword:vm_name=testvm1" - } -} From b17fdcd3d45c8a8af2e712bc5a731fc5c437eead Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 8 Jun 2020 16:26:19 +0200 Subject: [PATCH 215/341] windows: build Python3 and Python2 --- core/CMakeLists.txt | 11 ++++++++++- core/cmake/BareosFindAllLibraries.cmake | 4 ++++ core/src/plugins/dird/python/CMakeLists.txt | 10 +++++----- core/src/plugins/filed/python/CMakeLists.txt | 4 ++-- core/src/plugins/stored/python/CMakeLists.txt | 10 +++++----- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 23d408f88b6..744ef21b1dd 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -301,7 +301,16 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") set(WINDOWS_LIBRARIES ws2_32) set(Python2_LIBRARIES python27.dll) - set(Python2_INCLUDE_DIRS /usr/x86_64-w64-mingw32/include/python2/) + set(Python3_LIBRARIES python38.dll) + + if(${WINDOWS_BITS} MATCHES "32") + set(cross-prefix i686-w64-mingw32) + else() + set(cross-prefix x86_64-w64-mingw32) + endif() + + set(Python2_INCLUDE_DIRS /usr/${cross-prefix}/include/python2/) + set(Python3_INCLUDE_DIRS /usr/${cross-prefix}/include/python3/) set(PostgreSQL_LIBRARY libpq.dll) set(PostgreSQL_INCLUDE_DIR "") diff --git a/core/cmake/BareosFindAllLibraries.cmake b/core/cmake/BareosFindAllLibraries.cmake index ca0699df185..82c77c72ac2 100644 --- a/core/cmake/BareosFindAllLibraries.cmake +++ b/core/cmake/BareosFindAllLibraries.cmake @@ -89,6 +89,10 @@ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") else() # windows set(HAVE_PYTHON 1) set(Python2_FOUND 1) + set(Python2_EXT_SUFFIX ".dll") + + set(Python3_FOUND 1) + set(Python3_EXT_SUFFIX ".dll") endif() diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt index 75771dbef05..627d4ce5ed6 100644 --- a/core/src/plugins/dird/python/CMakeLists.txt +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -17,7 +17,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. -if(Python2_FOUND AND NOT HAVE_WIN32) +if(Python2_FOUND) add_library(python-dir MODULE python-dir.cc) # do not prefix with "lib" set_target_properties( @@ -35,7 +35,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) install(FILES ${PYFILES} DESTINATION ${plugindir}) endif() -if(Python2_FOUND AND NOT HAVE_WIN32) +if(Python2_FOUND) add_library(bareosdir-python2-module MODULE module/bareosdir.cc) set_target_properties( bareosdir-python2-module @@ -48,7 +48,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX INCLUDE_DIRECTORIES - "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include;${PROJECT_SOURCE_DIR}/src/win32/compat/include;${PROJECT_SOURCE_DIR}/src/win32/include" ) if(NOT "${Python2_CCSHARED}" STREQUAL "") set_property( @@ -89,7 +89,7 @@ if(Python3_FOUND) install(FILES ${PYFILES} DESTINATION ${plugindir}) endif() -if(Python3_FOUND AND NOT HAVE_WIN32) +if(Python3_FOUND) add_library(bareosdir-python3-module MODULE module/bareosdir.cc) set_target_properties( bareosdir-python3-module @@ -102,7 +102,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX INCLUDE_DIRECTORIES - "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include;${PROJECT_SOURCE_DIR}/src/win32/compat/include;${PROJECT_SOURCE_DIR}/src/win32/include" ) if(NOT "${Python3_CCSHARED}" STREQUAL "") set_property( diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 2a7dd7b1e64..7db66e3cb6b 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -125,7 +125,7 @@ if(Python2_FOUND) ) endif() -if(Python3_FOUND AND NOT HAVE_WIN32) +if(Python3_FOUND) add_library(bareosfd-python3-module MODULE module/bareosfd.cc) set_target_properties( bareosfd-python3-module @@ -138,7 +138,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX INCLUDE_DIRECTORIES - "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include;${PROJECT_SOURCE_DIR}/src/win32/compat/include;${PROJECT_SOURCE_DIR}/src/win32/include" ) if(NOT "${Python3_CCSHARED}" STREQUAL "") set_property( diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index 0bdd75f716a..3fc41b2c34c 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -17,7 +17,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. -if(Python2_FOUND AND NOT HAVE_WIN32) +if(Python2_FOUND) add_library(python-sd MODULE python-sd.cc) set_target_properties( python-sd PROPERTIES PREFIX "" LIBRARY_OUTPUT_DIRECTORY .. @@ -35,7 +35,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) install(FILES ${PYFILES} DESTINATION ${plugindir}) endif() -if(Python2_FOUND AND NOT HAVE_WIN32) +if(Python2_FOUND) add_library(bareossd-python2-module MODULE module/bareossd.cc) set_target_properties( bareossd-python2-module @@ -47,7 +47,7 @@ if(Python2_FOUND AND NOT HAVE_WIN32) LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX INCLUDE_DIRECTORIES - "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include;${PROJECT_SOURCE_DIR}/src/win32/compat/include;${PROJECT_SOURCE_DIR}/src/win32/include" ) if(NOT "${Python2_CCSHARED}" STREQUAL "") set_property( @@ -88,7 +88,7 @@ if(Python3_FOUND) install(FILES ${PYFILES} DESTINATION ${plugindir}) endif() -if(Python3_FOUND AND NOT HAVE_WIN32) +if(Python3_FOUND) # set_property(SOURCE module/bareossd.cc PROPERTY LANGUAGE C) add_library(bareossd-python3-module MODULE module/bareossd.cc) set_target_properties( @@ -102,7 +102,7 @@ if(Python3_FOUND AND NOT HAVE_WIN32) LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" LINKER_LANGUAGE CXX INCLUDE_DIRECTORIES - "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include" + "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include;${PROJECT_SOURCE_DIR}/src/win32/compat/include;${PROJECT_SOURCE_DIR}/src/win32/include" ) if(NOT "${Python3_CCSHARED}" STREQUAL "") set_property( From 37b99f64232dd652f3681bf00c3801a9359b38d4 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 8 Jun 2020 17:08:26 +0200 Subject: [PATCH 216/341] python: python3 extensions have the suffix :pyd --- core/cmake/BareosFindAllLibraries.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/cmake/BareosFindAllLibraries.cmake b/core/cmake/BareosFindAllLibraries.cmake index 82c77c72ac2..dd01dfc6c9a 100644 --- a/core/cmake/BareosFindAllLibraries.cmake +++ b/core/cmake/BareosFindAllLibraries.cmake @@ -92,7 +92,7 @@ else() # windows set(Python2_EXT_SUFFIX ".dll") set(Python3_FOUND 1) - set(Python3_EXT_SUFFIX ".dll") + set(Python3_EXT_SUFFIX ".pyd") endif() From 8758a8c46e3431545f6f58d6b3c3fe1ab61fb526 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 8 Jun 2020 17:53:18 +0200 Subject: [PATCH 217/341] cmake: calculate INCLUDE_DIRECTORIES for python modules centralized --- core/src/plugins/CMakeLists.txt | 26 ++++++++++++++ core/src/plugins/dird/python/CMakeLists.txt | 36 +++++++++---------- core/src/plugins/filed/python/CMakeLists.txt | 36 +++++++++---------- core/src/plugins/stored/python/CMakeLists.txt | 34 ++++++++---------- 4 files changed, 73 insertions(+), 59 deletions(-) diff --git a/core/src/plugins/CMakeLists.txt b/core/src/plugins/CMakeLists.txt index 4bfcfc6f859..fd970e79f72 100644 --- a/core/src/plugins/CMakeLists.txt +++ b/core/src/plugins/CMakeLists.txt @@ -18,6 +18,32 @@ # 02110-1301, USA. message("Entering ${CMAKE_CURRENT_SOURCE_DIR}") +# create include dirs needed when compiling python modules + +set(pymod_include_dirs ${PROJECT_SOURCE_DIR}/src) + +# FreeBSD +if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") + list(APPEND pymod_include_dirs ${Intl_INCLUDE_DIRS}) +endif() + +# Darwin +if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + list(APPEND pymod_include_dirs /usr/local/opt/gettext/include + /usr/local/opt/openssl/include + ) +endif() + +# Windows +if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + list(APPEND pymod_include_dirs ${PROJECT_SOURCE_DIR}/src/win32/compat/include + ${PROJECT_SOURCE_DIR}/src/win32/include + ) +endif() + +set(pymod2_include_dirs ${Python2_INCLUDE_DIRS} ${pymod_include_dirs}) +set(pymod3_include_dirs ${Python3_INCLUDE_DIRS} ${pymod_include_dirs}) + if(NOT client-only) add_subdirectory(dird) add_subdirectory(stored) diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt index 627d4ce5ed6..b0e997818bf 100644 --- a/core/src/plugins/dird/python/CMakeLists.txt +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -39,16 +39,14 @@ if(Python2_FOUND) add_library(bareosdir-python2-module MODULE module/bareosdir.cc) set_target_properties( bareosdir-python2-module - PROPERTIES - PREFIX "" - C_STANDARD 11 - # SUFFIX ${Python2_EXT_SUFFIX} - LIBRARY_OUTPUT_DIRECTORY pythonmodules - LIBRARY_OUTPUT_NAME bareosdir - LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" - LINKER_LANGUAGE CXX - INCLUDE_DIRECTORIES - "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include;${PROJECT_SOURCE_DIR}/src/win32/compat/include;${PROJECT_SOURCE_DIR}/src/win32/include" + PROPERTIES PREFIX "" + C_STANDARD 11 + # SUFFIX ${Python2_EXT_SUFFIX} + LIBRARY_OUTPUT_DIRECTORY pythonmodules + LIBRARY_OUTPUT_NAME bareosdir + LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" + LINKER_LANGUAGE CXX + INCLUDE_DIRECTORIES "${pymod2_include_dirs}" ) if(NOT "${Python2_CCSHARED}" STREQUAL "") set_property( @@ -93,16 +91,14 @@ if(Python3_FOUND) add_library(bareosdir-python3-module MODULE module/bareosdir.cc) set_target_properties( bareosdir-python3-module - PROPERTIES - PREFIX "" - C_STANDARD 11 - SUFFIX ${Python3_EXT_SUFFIX} - LIBRARY_OUTPUT_DIRECTORY python3modules - LIBRARY_OUTPUT_NAME bareosdir - LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" - LINKER_LANGUAGE CXX - INCLUDE_DIRECTORIES - "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include;${PROJECT_SOURCE_DIR}/src/win32/compat/include;${PROJECT_SOURCE_DIR}/src/win32/include" + PROPERTIES PREFIX "" + C_STANDARD 11 + SUFFIX ${Python3_EXT_SUFFIX} + LIBRARY_OUTPUT_DIRECTORY python3modules + LIBRARY_OUTPUT_NAME bareosdir + LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" + LINKER_LANGUAGE CXX + INCLUDE_DIRECTORIES "${pymod3_include_dirs}" ) if(NOT "${Python3_CCSHARED}" STREQUAL "") set_property( diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 7db66e3cb6b..94b323a8295 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -93,16 +93,14 @@ if(Python2_FOUND) add_library(bareosfd-python2-module MODULE module/bareosfd.cc) set_target_properties( bareosfd-python2-module - PROPERTIES - PREFIX "" - C_STANDARD 11 - # SUFFIX ${Python2_EXT_SUFFIX} - LIBRARY_OUTPUT_DIRECTORY pythonmodules - LIBRARY_OUTPUT_NAME bareosfd - LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" - LINKER_LANGUAGE CXX - INCLUDE_DIRECTORIES - "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include;${PROJECT_SOURCE_DIR}/src/win32/compat/include;${PROJECT_SOURCE_DIR}/src/win32/include" + PROPERTIES PREFIX "" + C_STANDARD 11 + # SUFFIX ${Python2_EXT_SUFFIX} + LIBRARY_OUTPUT_DIRECTORY pythonmodules + LIBRARY_OUTPUT_NAME bareosfd + LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" + LINKER_LANGUAGE CXX + INCLUDE_DIRECTORIES "${pymod2_include_dirs}" ) if(NOT "${Python2_CCSHARED}" STREQUAL "") set_property( @@ -129,16 +127,14 @@ if(Python3_FOUND) add_library(bareosfd-python3-module MODULE module/bareosfd.cc) set_target_properties( bareosfd-python3-module - PROPERTIES - PREFIX "" - C_STANDARD 11 - SUFFIX ${Python3_EXT_SUFFIX} - LIBRARY_OUTPUT_DIRECTORY python3modules - LIBRARY_OUTPUT_NAME bareosfd - LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" - LINKER_LANGUAGE CXX - INCLUDE_DIRECTORIES - "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include;${PROJECT_SOURCE_DIR}/src/win32/compat/include;${PROJECT_SOURCE_DIR}/src/win32/include" + PROPERTIES PREFIX "" + C_STANDARD 11 + SUFFIX ${Python3_EXT_SUFFIX} + LIBRARY_OUTPUT_DIRECTORY python3modules + LIBRARY_OUTPUT_NAME bareosfd + LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" + LINKER_LANGUAGE CXX + INCLUDE_DIRECTORIES "${pymod3_include_dirs}" ) if(NOT "${Python3_CCSHARED}" STREQUAL "") set_property( diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index 3fc41b2c34c..d1967ee174e 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -39,15 +39,13 @@ if(Python2_FOUND) add_library(bareossd-python2-module MODULE module/bareossd.cc) set_target_properties( bareossd-python2-module - PROPERTIES - PREFIX "" - C_STANDARD 11 - LIBRARY_OUTPUT_DIRECTORY pythonmodules - LIBRARY_OUTPUT_NAME bareossd - LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" - LINKER_LANGUAGE CXX - INCLUDE_DIRECTORIES - "${Python2_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include;${PROJECT_SOURCE_DIR}/src/win32/compat/include;${PROJECT_SOURCE_DIR}/src/win32/include" + PROPERTIES PREFIX "" + C_STANDARD 11 + LIBRARY_OUTPUT_DIRECTORY pythonmodules + LIBRARY_OUTPUT_NAME bareossd + LINK_FLAGS "${Python2_BLDSHARED_FLAGS}" + LINKER_LANGUAGE CXX + INCLUDE_DIRECTORIES "${pymod2_include_dirs}" ) if(NOT "${Python2_CCSHARED}" STREQUAL "") set_property( @@ -93,16 +91,14 @@ if(Python3_FOUND) add_library(bareossd-python3-module MODULE module/bareossd.cc) set_target_properties( bareossd-python3-module - PROPERTIES - PREFIX "" - C_STANDARD 11 - SUFFIX ${Python3_EXT_SUFFIX} - LIBRARY_OUTPUT_DIRECTORY python3modules - LIBRARY_OUTPUT_NAME bareossd - LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" - LINKER_LANGUAGE CXX - INCLUDE_DIRECTORIES - "${Python3_INCLUDE_DIRS};${PROJECT_SOURCE_DIR}/src;${Intl_INCLUDE_DIRS};/usr/local/opt/gettext/include;/usr/local/opt/openssl/include;${PROJECT_SOURCE_DIR}/src/win32/compat/include;${PROJECT_SOURCE_DIR}/src/win32/include" + PROPERTIES PREFIX "" + C_STANDARD 11 + SUFFIX ${Python3_EXT_SUFFIX} + LIBRARY_OUTPUT_DIRECTORY python3modules + LIBRARY_OUTPUT_NAME bareossd + LINK_FLAGS "${Python3_BLDSHARED_FLAGS}" + LINKER_LANGUAGE CXX + INCLUDE_DIRECTORIES "${pymod3_include_dirs}" ) if(NOT "${Python3_CCSHARED}" STREQUAL "") set_property( From 145902573c11a14ac3427637dbbed7abd11c2688 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 9 Jun 2020 13:08:27 +0200 Subject: [PATCH 218/341] python3: install the python3 modules --- core/src/plugins/dird/python/CMakeLists.txt | 2 ++ core/src/plugins/filed/python/CMakeLists.txt | 2 ++ core/src/plugins/stored/python/CMakeLists.txt | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/plugins/dird/python/CMakeLists.txt b/core/src/plugins/dird/python/CMakeLists.txt index b0e997818bf..7d6d3f50e99 100644 --- a/core/src/plugins/dird/python/CMakeLists.txt +++ b/core/src/plugins/dird/python/CMakeLists.txt @@ -37,6 +37,7 @@ endif() if(Python2_FOUND) add_library(bareosdir-python2-module MODULE module/bareosdir.cc) + install(TARGETS bareosdir-python2-module DESTINATION ${plugindir}) set_target_properties( bareosdir-python2-module PROPERTIES PREFIX "" @@ -89,6 +90,7 @@ endif() if(Python3_FOUND) add_library(bareosdir-python3-module MODULE module/bareosdir.cc) + install(TARGETS bareosdir-python3-module DESTINATION ${plugindir}) set_target_properties( bareosdir-python3-module PROPERTIES PREFIX "" diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 94b323a8295..73e1d319b33 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -91,6 +91,7 @@ endif() if(Python2_FOUND) add_library(bareosfd-python2-module MODULE module/bareosfd.cc) + install(TARGETS bareosfd-python2-module DESTINATION ${plugindir}) set_target_properties( bareosfd-python2-module PROPERTIES PREFIX "" @@ -125,6 +126,7 @@ endif() if(Python3_FOUND) add_library(bareosfd-python3-module MODULE module/bareosfd.cc) + install(TARGETS bareosfd-python3-module DESTINATION ${plugindir}) set_target_properties( bareosfd-python3-module PROPERTIES PREFIX "" diff --git a/core/src/plugins/stored/python/CMakeLists.txt b/core/src/plugins/stored/python/CMakeLists.txt index d1967ee174e..e413e2e55fb 100644 --- a/core/src/plugins/stored/python/CMakeLists.txt +++ b/core/src/plugins/stored/python/CMakeLists.txt @@ -37,6 +37,7 @@ endif() if(Python2_FOUND) add_library(bareossd-python2-module MODULE module/bareossd.cc) + install(TARGETS bareossd-python2-module DESTINATION ${plugindir}) set_target_properties( bareossd-python2-module PROPERTIES PREFIX "" @@ -87,8 +88,8 @@ if(Python3_FOUND) endif() if(Python3_FOUND) - # set_property(SOURCE module/bareossd.cc PROPERTY LANGUAGE C) add_library(bareossd-python3-module MODULE module/bareossd.cc) + install(TARGETS bareossd-python3-module DESTINATION ${plugindir}) set_target_properties( bareossd-python3-module PROPERTIES PREFIX "" From 5436bc1ba323e78bf077957c53f0ab2e59f0eb2d Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 9 Jun 2020 13:12:48 +0200 Subject: [PATCH 219/341] winbareos.nsi: plugin install *fd*. *sd* and *dir* to also fetch the .pyd files --- core/platforms/win32/winbareos.nsi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/platforms/win32/winbareos.nsi b/core/platforms/win32/winbareos.nsi index aecfa6689a8..ec401f7ff37 100644 --- a/core/platforms/win32/winbareos.nsi +++ b/core/platforms/win32/winbareos.nsi @@ -620,7 +620,7 @@ SectionIn 1 2 3 4 #File "bpipe-fd.dll" #File "mssqlvdi-fd.dll" #File "python-fd.dll" - File "*-fd.dll" + File "*fd*" File "Plugins\BareosFd*.py" File "Plugins\bareos-fd*.py" @@ -683,7 +683,7 @@ SectionIn 2 3 SetShellVarContext all SetOutPath "$INSTDIR\Plugins" SetOverwrite ifnewer - File "*-sd.dll" + File "*sd*" File "Plugins\BareosSd*.py" File "Plugins\bareos-sd*.py" SectionEnd @@ -898,7 +898,7 @@ SectionIn 2 3 SetOverwrite ifnewer #File "python-dir.dll" - File "*-dir.dll" + File "*dir*" File "Plugins\BareosDir*.py" File "Plugins\bareos-dir*.py" SectionEnd From 52dde8765f6b7e0bc996e3f9270866824ab3619d Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 9 Jun 2020 13:19:06 +0200 Subject: [PATCH 220/341] rpm packaging: package the python modules --- core/platforms/packaging/bareos.spec | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/platforms/packaging/bareos.spec b/core/platforms/packaging/bareos.spec index 7edd28fb1ca..82215dcbda2 100644 --- a/core/platforms/packaging/bareos.spec +++ b/core/platforms/packaging/bareos.spec @@ -1543,6 +1543,7 @@ mkdir -p %{?buildroot}/%{_libdir}/bareos/plugins/vmware_plugin %files filedaemon-python-plugin %defattr(-, root, root) %{plugin_dir}/python*-fd.so +%{plugin_dir}/bareosfd*.so %{plugin_dir}/bareos-fd.py* %{plugin_dir}/bareos-fd-local-fileset.py* %{plugin_dir}/bareos-fd-mock-test.py* @@ -1581,6 +1582,7 @@ mkdir -p %{?buildroot}/%{_libdir}/bareos/plugins/vmware_plugin %files director-python-plugin %defattr(-, root, root) %{plugin_dir}/python*-dir.so +%{plugin_dir}/bareosdir*.so %{plugin_dir}/bareos-dir.py* %{plugin_dir}/BareosDirPluginBaseclass.py* %{plugin_dir}/bareos-dir-class-plugin.py* @@ -1589,6 +1591,7 @@ mkdir -p %{?buildroot}/%{_libdir}/bareos/plugins/vmware_plugin %files storage-python-plugin %defattr(-, root, root) %{plugin_dir}/python*-sd.so +%{plugin_dir}/bareossd*.so %{plugin_dir}/bareos-sd.py* %{plugin_dir}/BareosSdPluginBaseclass.py* %{plugin_dir}/BareosSdWrapper.py* From fba909490996df7c06c5a0d58e50f88195c1090e Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 13 Aug 2020 15:41:07 +0200 Subject: [PATCH 221/341] systemtests: fixup merge problems --- core/cmake/BareosFindAllLibraries.cmake | 2 + systemtests/CMakeLists.txt | 74 +++++++++---------- .../bareos-dir.d/catalog/MyCatalog.conf.in | 0 .../bareos-dir.d/client/bareos-fd.conf.in | 0 .../bareos-dir.d/console/bareos-mon.conf.in | 0 .../bareos-dir.d/director/bareos-dir.conf.in | 0 .../bareos-dir.d/fileset/Catalog.conf.in | 0 .../bareos-dir.d/fileset/SelfTest.conf.in | 0 .../bareos-dir.d/job/BackupCatalog.conf.in | 0 .../bareos-dir.d/job/RestoreFiles.conf.in | 0 .../bareos-dir.d/job/backup-bareos-fd.conf.in | 0 .../bareos-dir.d/jobdefs/DefaultJob.conf.in | 0 .../bareos-dir.d/messages/Daemon.conf.in | 0 .../bareos-dir.d/messages/Standard.conf.in | 0 .../bareos-dir.d/pool/Differential.conf | 0 .../etc/bareos/bareos-dir.d/pool/Full.conf | 0 .../bareos/bareos-dir.d/pool/Incremental.conf | 0 .../etc/bareos/bareos-dir.d/pool/Scratch.conf | 0 .../bareos/bareos-dir.d/profile/operator.conf | 0 .../bareos/bareos-dir.d/storage/File.conf.in | 0 .../bareos/bareos-fd.d/client/myself.conf.in | 0 .../bareos-fd.d/director/bareos-dir.conf.in | 0 .../bareos-fd.d/director/bareos-mon.conf.in | 0 .../bareos/bareos-fd.d/messages/Standard.conf | 0 .../bareos-sd.d/device/FileStorage.conf | 0 .../bareos-sd.d/director/bareos-dir.conf.in | 0 .../bareos-sd.d/director/bareos-mon.conf.in | 0 .../bareos/bareos-sd.d/messages/Standard.conf | 0 .../bareos-sd.d/storage/bareos-sd.conf.in | 0 .../etc/bareos/bconsole.conf.in | 0 .../python-modules/bareos-dir-test.py | 0 .../{pyplug-dir => py2plug-dir}/testrunner | 0 .../bareos-dir.d/catalog/MyCatalog.conf.in | 0 .../bareos-dir.d/client/bareos-fd.conf.in | 0 .../bareos-dir.d/console/bareos-mon.conf.in | 0 .../bareos-dir.d/director/bareos-dir.conf.in | 0 .../bareos-dir.d/fileset/Catalog.conf.in | 0 .../bareos-dir.d/fileset/PluginTest.conf.in | 0 .../bareos-dir.d/fileset/SelfTest.conf.in | 0 .../bareos-dir.d/job/BackupCatalog.conf.in | 0 .../bareos-dir.d/job/RestoreFiles.conf.in | 0 .../bareos-dir.d/job/backup-bareos-fd.conf.in | 0 .../bareos-dir.d/jobdefs/DefaultJob.conf.in | 0 .../bareos-dir.d/messages/Daemon.conf.in | 0 .../bareos-dir.d/messages/Standard.conf.in | 0 .../bareos-dir.d/pool/Differential.conf | 0 .../etc/bareos/bareos-dir.d/pool/Full.conf | 0 .../bareos/bareos-dir.d/pool/Incremental.conf | 0 .../etc/bareos/bareos-dir.d/pool/Scratch.conf | 0 .../bareos/bareos-dir.d/profile/operator.conf | 0 .../bareos/bareos-dir.d/storage/File.conf.in | 0 .../bareos/bareos-fd.d/client/myself.conf.in | 0 .../bareos-fd.d/director/bareos-dir.conf.in | 0 .../bareos-fd.d/director/bareos-mon.conf.in | 0 .../bareos/bareos-fd.d/messages/Standard.conf | 0 .../bareos-sd.d/device/FileStorage.conf | 0 .../bareos-sd.d/director/bareos-dir.conf.in | 0 .../bareos-sd.d/director/bareos-mon.conf.in | 0 .../bareos/bareos-sd.d/messages/Standard.conf | 0 .../bareos-sd.d/storage/bareos-sd.conf.in | 0 .../etc/bareos/bconsole.conf.in | 0 .../mysqldefaults.in | 0 ...sFdPluginLocalFilesetWithRestoreObjects.py | 0 .../testrunner | 0 .../bareos-dir.d/catalog/MyCatalog.conf.in | 0 .../bareos-dir.d/client/bareos-fd.conf.in | 0 .../bareos-dir.d/console/bareos-mon.conf.in | 0 .../bareos-dir.d/director/bareos-dir.conf.in | 0 .../bareos-dir.d/fileset/Catalog.conf.in | 0 .../bareos-dir.d/fileset/PluginTest.conf.in | 0 .../bareos-dir.d/fileset/SelfTest.conf.in | 0 .../bareos-dir.d/job/BackupCatalog.conf.in | 0 .../bareos-dir.d/job/RestoreFiles.conf.in | 0 .../bareos-dir.d/job/backup-bareos-fd.conf.in | 0 .../bareos-dir.d/jobdefs/DefaultJob.conf.in | 0 .../bareos-dir.d/messages/Daemon.conf.in | 0 .../bareos-dir.d/messages/Standard.conf.in | 0 .../bareos-dir.d/pool/Differential.conf | 0 .../etc/bareos/bareos-dir.d/pool/Full.conf | 0 .../bareos/bareos-dir.d/pool/Incremental.conf | 0 .../etc/bareos/bareos-dir.d/pool/Scratch.conf | 0 .../bareos/bareos-dir.d/profile/operator.conf | 0 .../bareos/bareos-dir.d/storage/File.conf.in | 0 .../bareos/bareos-fd.d/client/myself.conf.in | 0 .../bareos-fd.d/director/bareos-dir.conf.in | 0 .../bareos-fd.d/director/bareos-mon.conf.in | 0 .../bareos/bareos-fd.d/messages/Standard.conf | 0 .../bareos-sd.d/device/FileStorage.conf | 0 .../bareos-sd.d/director/bareos-dir.conf.in | 0 .../bareos-sd.d/director/bareos-mon.conf.in | 0 .../bareos/bareos-sd.d/messages/Standard.conf | 0 .../bareos-sd.d/storage/bareos-sd.conf.in | 0 .../etc/bareos/bconsole.conf.in | 0 ...sFdPluginLocalFilesetWithRestoreObjects.py | 0 ...os-fd-local-fileset-with-restoreobjects.py | 0 ...os_fd_local_fileset_with_restoreobjects.py | 0 .../testrunner | 0 .../bareos-dir.d/catalog/MyCatalog.conf.in | 0 .../bareos-dir.d/client/bareos-fd.conf.in | 0 .../bareos-dir.d/console/bareos-mon.conf.in | 0 .../bareos-dir.d/director/bareos-dir.conf.in | 0 .../bareos-dir.d/fileset/Catalog.conf.in | 0 .../bareos-dir.d/fileset/OvirtTest.conf.in | 0 .../bareos-dir.d/fileset/SelfTest.conf.in | 0 .../bareos-dir.d/job/BackupCatalog.conf.in | 0 .../bareos-dir.d/job/RestoreFiles.conf.in | 0 .../bareos-dir.d/job/backup-bareos-fd.conf.in | 0 .../bareos-dir.d/jobdefs/DefaultJob.conf.in | 0 .../bareos-dir.d/messages/Daemon.conf.in | 0 .../bareos-dir.d/messages/Standard.conf.in | 0 .../bareos-dir.d/pool/Differential.conf | 0 .../etc/bareos/bareos-dir.d/pool/Full.conf | 0 .../bareos/bareos-dir.d/pool/Incremental.conf | 0 .../etc/bareos/bareos-dir.d/pool/Scratch.conf | 0 .../bareos/bareos-dir.d/profile/operator.conf | 0 .../bareos/bareos-dir.d/storage/File.conf.in | 0 .../bareos/bareos-fd.d/client/myself.conf.in | 0 .../bareos-fd.d/director/bareos-dir.conf.in | 0 .../bareos-fd.d/director/bareos-mon.conf.in | 0 .../bareos/bareos-fd.d/messages/Standard.conf | 0 .../bareos-sd.d/device/FileStorage.conf | 0 .../bareos-sd.d/director/bareos-dir.conf.in | 0 .../bareos-sd.d/director/bareos-mon.conf.in | 0 .../bareos/bareos-sd.d/messages/Standard.conf | 0 .../bareos-sd.d/storage/bareos-sd.conf.in | 0 .../etc/bareos/bconsole.conf.in | 0 .../testrunner | 0 .../bareos-dir.d/catalog/MyCatalog.conf.in | 0 .../bareos-dir.d/client/bareos-fd.conf.in | 0 .../bareos-dir.d/console/bareos-mon.conf.in | 0 .../bareos-dir.d/director/bareos-dir.conf.in | 0 .../bareos-dir.d/fileset/Catalog.conf.in | 0 .../fileset/PerconaXtraBackupTest.conf.in | 0 .../bareos-dir.d/fileset/SelfTest.conf.in | 0 .../bareos-dir.d/job/BackupCatalog.conf.in | 0 .../bareos-dir.d/job/RestoreFiles.conf.in | 0 .../bareos-dir.d/job/backup-bareos-fd.conf.in | 0 .../bareos-dir.d/jobdefs/DefaultJob.conf.in | 0 .../bareos-dir.d/messages/Daemon.conf.in | 0 .../bareos-dir.d/messages/Standard.conf.in | 0 .../bareos-dir.d/pool/Differential.conf | 0 .../etc/bareos/bareos-dir.d/pool/Full.conf | 0 .../bareos/bareos-dir.d/pool/Incremental.conf | 0 .../etc/bareos/bareos-dir.d/pool/Scratch.conf | 0 .../bareos/bareos-dir.d/profile/operator.conf | 0 .../bareos/bareos-dir.d/storage/File.conf.in | 0 .../bareos/bareos-fd.d/client/myself.conf.in | 0 .../bareos-fd.d/director/bareos-dir.conf.in | 0 .../bareos-fd.d/director/bareos-mon.conf.in | 0 .../bareos/bareos-fd.d/messages/Standard.conf | 0 .../bareos-sd.d/device/FileStorage.conf | 0 .../bareos-sd.d/director/bareos-dir.conf.in | 0 .../bareos-sd.d/director/bareos-mon.conf.in | 0 .../bareos/bareos-sd.d/messages/Standard.conf | 0 .../bareos-sd.d/storage/bareos-sd.conf.in | 0 .../etc/bareos/bconsole.conf.in | 0 .../testrunner | 0 .../database/setup_local_db.sh | 0 .../bareos-dir.d/catalog/MyCatalog.conf.in | 0 .../bareos-dir.d/client/bareos-fd.conf.in | 0 .../bareos-dir.d/console/bareos-mon.conf.in | 0 .../bareos-dir.d/director/bareos-dir.conf.in | 0 .../bareos-dir.d/fileset/Catalog.conf.in | 0 .../bareos-dir.d/fileset/PluginTest.conf.in | 0 .../bareos-dir.d/fileset/SelfTest.conf.in | 0 .../bareos-dir.d/job/BackupCatalog.conf.in | 0 .../bareos-dir.d/job/RestoreFiles.conf.in | 0 .../bareos-dir.d/job/backup-bareos-fd.conf.in | 0 .../bareos-dir.d/jobdefs/DefaultJob.conf.in | 0 .../bareos-dir.d/messages/Daemon.conf.in | 0 .../bareos-dir.d/messages/Standard.conf.in | 0 .../bareos-dir.d/pool/Differential.conf | 0 .../etc/bareos/bareos-dir.d/pool/Full.conf | 0 .../bareos/bareos-dir.d/pool/Incremental.conf | 0 .../etc/bareos/bareos-dir.d/pool/Scratch.conf | 0 .../bareos/bareos-dir.d/profile/operator.conf | 0 .../bareos/bareos-dir.d/storage/File.conf.in | 0 .../bareos/bareos-fd.d/client/myself.conf.in | 0 .../bareos-fd.d/director/bareos-dir.conf.in | 0 .../bareos-fd.d/director/bareos-mon.conf.in | 0 .../bareos/bareos-fd.d/messages/Standard.conf | 0 .../bareos-sd.d/device/FileStorage.conf | 0 .../bareos-sd.d/director/bareos-dir.conf.in | 0 .../bareos-sd.d/director/bareos-mon.conf.in | 0 .../bareos/bareos-sd.d/messages/Standard.conf | 0 .../bareos-sd.d/storage/bareos-sd.conf.in | 0 .../etc/bareos/bconsole.conf.in | 0 ...sFdPluginLocalFilesetWithRestoreObjects.py | 0 ...os-fd-local-fileset-with-restoreobjects.py | 0 .../testrunner | 0 .../etc/bareos/VMwareTest.ini.in | 0 .../bareos-dir.d/catalog/MyCatalog.conf.in | 0 .../bareos-dir.d/client/bareos-fd.conf.in | 0 .../bareos-dir.d/console/bareos-mon.conf.in | 0 .../bareos-dir.d/director/bareos-dir.conf.in | 0 .../bareos-dir.d/fileset/Catalog.conf.in | 0 .../bareos-dir.d/fileset/SelfTest.conf.in | 0 .../bareos-dir.d/fileset/VMwareTest.conf.in | 0 .../bareos-dir.d/job/BackupCatalog.conf.in | 0 .../bareos-dir.d/job/RestoreFiles.conf.in | 0 .../bareos-dir.d/job/backup-bareos-fd.conf.in | 0 .../bareos-dir.d/jobdefs/DefaultJob.conf.in | 0 .../bareos-dir.d/messages/Daemon.conf.in | 0 .../bareos-dir.d/messages/Standard.conf.in | 0 .../bareos-dir.d/pool/Differential.conf | 0 .../etc/bareos/bareos-dir.d/pool/Full.conf | 0 .../bareos/bareos-dir.d/pool/Incremental.conf | 0 .../etc/bareos/bareos-dir.d/pool/Scratch.conf | 0 .../bareos/bareos-dir.d/profile/operator.conf | 0 .../bareos/bareos-dir.d/storage/File.conf.in | 0 .../bareos/bareos-fd.d/client/myself.conf.in | 0 .../bareos-fd.d/director/bareos-dir.conf.in | 0 .../bareos-fd.d/director/bareos-mon.conf.in | 0 .../bareos/bareos-fd.d/messages/Standard.conf | 0 .../bareos-sd.d/device/FileStorage.conf | 0 .../bareos-sd.d/director/bareos-dir.conf.in | 0 .../bareos-sd.d/director/bareos-mon.conf.in | 0 .../bareos/bareos-sd.d/messages/Standard.conf | 0 .../bareos-sd.d/storage/bareos-sd.conf.in | 0 .../etc/bareos/bconsole.conf.in | 0 .../reset_cbt.sh | 0 .../testrunner | 0 .../bareos-dir.d/catalog/MyCatalog.conf.in | 0 .../bareos-dir.d/client/bareos-fd.conf.in | 0 .../bareos-dir.d/console/bareos-mon.conf.in | 0 .../bareos-dir.d/director/bareos-dir.conf.in | 0 .../bareos-dir.d/fileset/Catalog.conf.in | 0 .../bareos-dir.d/fileset/SelfTest.conf.in | 0 .../bareos-dir.d/job/BackupCatalog.conf.in | 0 .../bareos-dir.d/job/RestoreFiles.conf.in | 0 .../bareos-dir.d/job/backup-bareos-fd.conf.in | 0 .../bareos-dir.d/jobdefs/DefaultJob.conf.in | 0 .../bareos-dir.d/messages/Daemon.conf.in | 0 .../bareos-dir.d/messages/Standard.conf.in | 0 .../bareos-dir.d/pool/Differential.conf | 0 .../etc/bareos/bareos-dir.d/pool/Full.conf | 0 .../bareos/bareos-dir.d/pool/Incremental.conf | 0 .../etc/bareos/bareos-dir.d/pool/Scratch.conf | 0 .../bareos/bareos-dir.d/profile/operator.conf | 0 .../bareos/bareos-dir.d/storage/File.conf.in | 0 .../bareos/bareos-fd.d/client/myself.conf.in | 0 .../bareos-fd.d/director/bareos-dir.conf.in | 0 .../bareos-fd.d/director/bareos-mon.conf.in | 0 .../bareos/bareos-fd.d/messages/Standard.conf | 0 .../bareos-sd.d/device/FileStorage.conf | 0 .../bareos-sd.d/director/bareos-dir.conf.in | 0 .../bareos-sd.d/director/bareos-mon.conf.in | 0 .../bareos/bareos-sd.d/messages/Standard.conf | 0 .../bareos-sd.d/storage/bareos-sd.conf.in | 0 .../etc/bareos/bconsole.conf.in | 0 .../python-modules/bareos-sd-test.py | 0 .../{pyplug-sd => py2plug-sd}/testrunner | 0 systemtests/tests/py3plug-dir | 1 + systemtests/tests/py3plug-fd-local-fileset | 1 + .../py3plug-fd-local-fileset-restoreobject | 1 + systemtests/tests/py3plug-fd-ovirt | 1 + .../tests/py3plug-fd-percona-xtrabackup | 1 + systemtests/tests/py3plug-fd-postgres | 1 + systemtests/tests/py3plug-fd-vmware | 1 + systemtests/tests/py3plug-sd | 1 + .../database/setup_local_db.sh | 67 ----------------- systemtests/tests/python3-dir-plugin-test | 1 - .../tests/python3-fd-ovirt-plugin-test | 1 - .../python3-fd-percona-xtrabackup-plugin-test | 1 - .../python3-fd-plugin-local-fileset-test | 1 - .../tests/python3-fd-plugin-postgres-test | 1 - systemtests/tests/python3-sd-plugin-test | 1 - 267 files changed, 45 insertions(+), 112 deletions(-) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-dir.d/messages/Daemon.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-dir.d/messages/Standard.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-dir.d/pool/Differential.conf (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-dir.d/pool/Full.conf (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-dir.d/pool/Incremental.conf (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-dir.d/pool/Scratch.conf (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-dir.d/profile/operator.conf (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-dir.d/storage/File.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-fd.d/client/myself.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-fd.d/messages/Standard.conf (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-sd.d/device/FileStorage.conf (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-sd.d/messages/Standard.conf (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/etc/bareos/bconsole.conf.in (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/python-modules/bareos-dir-test.py (100%) rename systemtests/tests/{pyplug-dir => py2plug-dir}/testrunner (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-dir.d/messages/Daemon.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-dir.d/messages/Standard.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-dir.d/pool/Differential.conf (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-dir.d/pool/Full.conf (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-dir.d/pool/Incremental.conf (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-dir.d/pool/Scratch.conf (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-dir.d/profile/operator.conf (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-dir.d/storage/File.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-fd.d/client/myself.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-fd.d/messages/Standard.conf (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-sd.d/device/FileStorage.conf (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-sd.d/messages/Standard.conf (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/etc/bareos/bconsole.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/mysqldefaults.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py (100%) rename systemtests/tests/{pyplug-fd-local-fileset-restoreobject => py2plug-fd-local-fileset-restoreobject}/testrunner (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-dir.d/messages/Daemon.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-dir.d/messages/Standard.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-dir.d/pool/Differential.conf (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-dir.d/pool/Full.conf (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-dir.d/pool/Incremental.conf (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-dir.d/pool/Scratch.conf (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-dir.d/profile/operator.conf (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-dir.d/storage/File.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-fd.d/client/myself.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-fd.d/messages/Standard.conf (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-sd.d/device/FileStorage.conf (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-sd.d/messages/Standard.conf (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/etc/bareos/bconsole.conf.in (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/python-modules/bareos-fd-local-fileset-with-restoreobjects.py (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/python-modules/bareos_fd_local_fileset_with_restoreobjects.py (100%) rename systemtests/tests/{pyplug-fd-local-fileset => py2plug-fd-local-fileset}/testrunner (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-dir.d/fileset/OvirtTest.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-dir.d/messages/Daemon.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-dir.d/messages/Standard.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-dir.d/pool/Differential.conf (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-dir.d/pool/Full.conf (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-dir.d/pool/Incremental.conf (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-dir.d/pool/Scratch.conf (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-dir.d/profile/operator.conf (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-dir.d/storage/File.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-fd.d/client/myself.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-fd.d/messages/Standard.conf (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-sd.d/device/FileStorage.conf (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-sd.d/messages/Standard.conf (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/etc/bareos/bconsole.conf.in (100%) rename systemtests/tests/{pyplug-fd-ovirt => py2plug-fd-ovirt}/testrunner (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-dir.d/messages/Daemon.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-dir.d/messages/Standard.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-dir.d/pool/Differential.conf (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-dir.d/pool/Full.conf (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-dir.d/pool/Incremental.conf (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-dir.d/pool/Scratch.conf (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-dir.d/profile/operator.conf (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-dir.d/storage/File.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-fd.d/client/myself.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-fd.d/messages/Standard.conf (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-sd.d/device/FileStorage.conf (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-sd.d/messages/Standard.conf (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/etc/bareos/bconsole.conf.in (100%) rename systemtests/tests/{pyplug-fd-percona-xtrabackup => py2plug-fd-percona-xtrabackup}/testrunner (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/database/setup_local_db.sh (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-dir.d/messages/Daemon.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-dir.d/messages/Standard.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-dir.d/pool/Differential.conf (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-dir.d/pool/Full.conf (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-dir.d/pool/Incremental.conf (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-dir.d/pool/Scratch.conf (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-dir.d/profile/operator.conf (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-dir.d/storage/File.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-fd.d/client/myself.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-fd.d/messages/Standard.conf (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-sd.d/device/FileStorage.conf (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-sd.d/messages/Standard.conf (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/etc/bareos/bconsole.conf.in (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/python-modules/bareos-fd-local-fileset-with-restoreobjects.py (100%) rename systemtests/tests/{pyplug-fd-postgres => py2plug-fd-postgres}/testrunner (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/VMwareTest.ini.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-dir.d/fileset/VMwareTest.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-dir.d/messages/Daemon.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-dir.d/messages/Standard.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-dir.d/pool/Differential.conf (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-dir.d/pool/Full.conf (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-dir.d/pool/Incremental.conf (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-dir.d/pool/Scratch.conf (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-dir.d/profile/operator.conf (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-dir.d/storage/File.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-fd.d/client/myself.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-fd.d/messages/Standard.conf (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-sd.d/device/FileStorage.conf (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-sd.d/messages/Standard.conf (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/etc/bareos/bconsole.conf.in (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/reset_cbt.sh (100%) rename systemtests/tests/{pyplug-fd-vmware => py2plug-fd-vmware}/testrunner (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-dir.d/messages/Daemon.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-dir.d/messages/Standard.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-dir.d/pool/Differential.conf (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-dir.d/pool/Full.conf (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-dir.d/pool/Incremental.conf (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-dir.d/pool/Scratch.conf (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-dir.d/profile/operator.conf (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-dir.d/storage/File.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-fd.d/client/myself.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-fd.d/messages/Standard.conf (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-sd.d/device/FileStorage.conf (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-sd.d/messages/Standard.conf (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/etc/bareos/bconsole.conf.in (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/python-modules/bareos-sd-test.py (100%) rename systemtests/tests/{pyplug-sd => py2plug-sd}/testrunner (100%) create mode 120000 systemtests/tests/py3plug-dir create mode 120000 systemtests/tests/py3plug-fd-local-fileset create mode 120000 systemtests/tests/py3plug-fd-local-fileset-restoreobject create mode 120000 systemtests/tests/py3plug-fd-ovirt create mode 120000 systemtests/tests/py3plug-fd-percona-xtrabackup create mode 120000 systemtests/tests/py3plug-fd-postgres create mode 120000 systemtests/tests/py3plug-fd-vmware create mode 120000 systemtests/tests/py3plug-sd delete mode 100755 systemtests/tests/python-fd-plugin-postgres-test/database/setup_local_db.sh delete mode 120000 systemtests/tests/python3-dir-plugin-test delete mode 120000 systemtests/tests/python3-fd-ovirt-plugin-test delete mode 120000 systemtests/tests/python3-fd-percona-xtrabackup-plugin-test delete mode 120000 systemtests/tests/python3-fd-plugin-local-fileset-test delete mode 120000 systemtests/tests/python3-fd-plugin-postgres-test delete mode 120000 systemtests/tests/python3-sd-plugin-test diff --git a/core/cmake/BareosFindAllLibraries.cmake b/core/cmake/BareosFindAllLibraries.cmake index dd01dfc6c9a..4788dac155e 100644 --- a/core/cmake/BareosFindAllLibraries.cmake +++ b/core/cmake/BareosFindAllLibraries.cmake @@ -71,6 +71,7 @@ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") endif() if(${Python2_FOUND}) + set(PYTHON_EXECUTABLE ${Python2_EXECUTABLE} PARENT_SCOPE) execute_process( COMMAND ${Python2_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/get_python_compile_settings.py OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/py2settings.cmake @@ -79,6 +80,7 @@ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") endif() if(${Python3_FOUND}) + set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE} PARENT_SCOPE) execute_process( COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/get_python_compile_settings.py OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/py3settings.cmake diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 4f2b70b1616..3ebe93660e7 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -626,24 +626,24 @@ else() endif() if(TARGET python-fd) - list(APPEND SYSTEM_TESTS "pyplug-fd-local-fileset") + list(APPEND SYSTEM_TESTS "py2plug-fd-local-fileset") else() - list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-local-fileset") + list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-local-fileset") endif() if(TARGET python3-fd) - list(APPEND SYSTEM_TESTS "python3-fd-plugin-local-fileset-test") + list(APPEND SYSTEM_TESTS "py3plug-fd-local-fileset") else() - list(APPEND SYSTEM_TESTS_DISABLED "python3-fd-plugin-local-fileset-test") + list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-local-fileset") endif() if(TARGET python-fd) - list(APPEND SYSTEM_TESTS "pyplug-fd-local-fileset-restoreobject") + list(APPEND SYSTEM_TESTS "py2plug-fd-local-fileset-restoreobject") else() - list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-local-fileset-restoreobject") + list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-local-fileset-restoreobject") endif() -message("checking for requirements of pyplug-fd-postgres:") +message("checking for requirements of py2plug-fd-postgres:") check_pymodule_available("psycopg2") check_pymodule_available("dateutil") @@ -651,11 +651,11 @@ if(TARGET python-fd AND PYMODULE_PSYCOPG2_FOUND AND PYMODULE_DATEUTIL_FOUND ) - message("OK, enabling pyplug-fd-postgres:") - list(APPEND SYSTEM_TESTS "pyplug-fd-postgres") + message("OK, enabling py2plug-fd-postgres:") + list(APPEND SYSTEM_TESTS "py2plug-fd-postgres") else() - list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-postgres") - message("NOT OK, disabling pyplug-fd-postgres:") + list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-postgres") + message("NOT OK, disabling py2plug-fd-postgres:") endif() if(TARGET python3-fd) list(APPEND SYSTEM_TESTS "python3-fd-plugin-postgres-test") @@ -664,70 +664,67 @@ else() endif() if(TARGET python-fd AND ovirt_server) - list(APPEND SYSTEM_TESTS "pyplug-fd-ovirt") + list(APPEND SYSTEM_TESTS "py2plug-fd-ovirt") else() - message(STATUS "disabling pyplug-fd-ovirt-test as ovirt_server is not set") - list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-ovirt") + message(STATUS "disabling py2plug-fd-ovirt-test as ovirt_server is not set") + list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-ovirt") endif() if(TARGET python-fd AND enable_vmware_test) - list(APPEND SYSTEM_TESTS "pyplug-fd-vmware") + list(APPEND SYSTEM_TESTS "py2plug-fd-vmware") else() - message(STATUS "disabling pyplug-fd-vmware as vmware_server was not set") - list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-vmware") + message(STATUS "disabling py2plug-fd-vmware as vmware_server was not set") + list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-vmware") endif() if(TARGET python3-fd AND ovirt_server) - list(APPEND SYSTEM_TESTS "python3-fd-ovirt-plugin-test") + list(APPEND SYSTEM_TESTS "py3plug-fd-ovirt") else() - message( - STATUS "disabling python3-fd-ovirt-plugin-test as ovirt_server is not set" - ) - list(APPEND SYSTEM_TESTS_DISABLED "python3-fd-ovirt-plugin-test") + message(STATUS "disabling py3plug-fd-ovirt as ovirt_server is not set") + list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-ovirt") endif() if(TARGET python-fd AND XTRABACKUP) - list(APPEND SYSTEM_TESTS "pyplug-fd-percona-xtrabackup") + list(APPEND SYSTEM_TESTS "py2plug-fd-percona-xtrabackup") else() message( STATUS - "disabling pyplug-fd-percona-xtrabackup-test as XTRABACKUP was not found" + "disabling py2plug-fd-percona-xtrabackup-test as XTRABACKUP was not found" ) - list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-percona-xtrabackup") + list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-percona-xtrabackup") endif() if(TARGET python3-fd AND XTRABACKUP) - list(APPEND SYSTEM_TESTS "python3-fd-percona-xtrabackup-plugin-test") + list(APPEND SYSTEM_TESTS "py3plug-fd-percona-xtrabackup") else() message( - STATUS - "disabling python3-fd-percona-xtrabackup-plugin-test as XTRABACKUP was not found" + STATUS "disabling py3plug-fd-percona-xtrabackup as XTRABACKUP was not found" ) - list(APPEND SYSTEM_TESTS_DISABLED "python3-fd-percona-xtrabackup-plugin-test") + list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-percona-xtrabackup") endif() if(TARGET python-dir) - list(APPEND SYSTEM_TESTS "pyplug-dir") + list(APPEND SYSTEM_TESTS "py2plug-dir") else() - list(APPEND SYSTEM_TESTS_DISABLED "pyplug-dir") + list(APPEND SYSTEM_TESTS_DISABLED "py2plug-dir") endif() if(TARGET python3-dir) - list(APPEND SYSTEM_TESTS "python3-dir-plugin-test") + list(APPEND SYSTEM_TESTS "py3plug-dir") else() - list(APPEND SYSTEM_TESTS_DISABLED "python3-dir-plugin-test") + list(APPEND SYSTEM_TESTS_DISABLED "py3plug-dir") endif() if(TARGET python-sd) - list(APPEND SYSTEM_TESTS "python-sd-plugin-test") + list(APPEND SYSTEM_TESTS "py2plug-sd") else() - list(APPEND SYSTEM_TESTS_DISABLED "python-sd-plugin-test") + list(APPEND SYSTEM_TESTS_DISABLED "py2plug-sd") endif() if(TARGET python3-sd) - list(APPEND SYSTEM_TESTS "python3-sd-plugin-test") + list(APPEND SYSTEM_TESTS "py3plug-sd") else() - list(APPEND SYSTEM_TESTS_DISABLED "python3-sd-plugin-test") + list(APPEND SYSTEM_TESTS_DISABLED "py3plug-sd") endif() message(STATUS "Looking for pam test requirements ...") @@ -832,8 +829,7 @@ endif() foreach(TEST_NAME ${SYSTEM_TESTS}) message(STATUS "Configuring test: ${SYSTEMTEST_PREFIX}${TEST_NAME}") - # string(REGEX MATCH "^python[^-]?-(fd|sd|dir)" PLUGIN_NAME "${TEST_NAME}") - string(REGEX MATCH "^python[^-]?" python_version "${TEST_NAME}") + string(REGEX MATCH "^pyplug[^-]?" python_version "${TEST_NAME}") # if(python_version) message(STATUS "python_version:" ${python_version}) # # python or python3 endif() prepare_test() diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/messages/Daemon.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/messages/Daemon.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/messages/Daemon.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/messages/Daemon.conf.in diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/messages/Standard.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/messages/Standard.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/messages/Standard.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/messages/Standard.conf.in diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/pool/Differential.conf b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/pool/Differential.conf similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/pool/Differential.conf rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/pool/Differential.conf diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/pool/Full.conf b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/pool/Full.conf similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/pool/Full.conf rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/pool/Full.conf diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/pool/Incremental.conf b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/pool/Incremental.conf similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/pool/Incremental.conf rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/pool/Incremental.conf diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/pool/Scratch.conf b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/pool/Scratch.conf similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/pool/Scratch.conf rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/pool/Scratch.conf diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/profile/operator.conf b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/profile/operator.conf similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/profile/operator.conf rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/profile/operator.conf diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/storage/File.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/storage/File.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-dir.d/storage/File.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/storage/File.conf.in diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-fd.d/client/myself.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-fd.d/client/myself.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-fd.d/client/myself.conf.in diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-fd.d/messages/Standard.conf b/systemtests/tests/py2plug-dir/etc/bareos/bareos-fd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-fd.d/messages/Standard.conf rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-fd.d/messages/Standard.conf diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-sd.d/device/FileStorage.conf b/systemtests/tests/py2plug-dir/etc/bareos/bareos-sd.d/device/FileStorage.conf similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-sd.d/device/FileStorage.conf rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-sd.d/device/FileStorage.conf diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-sd.d/messages/Standard.conf b/systemtests/tests/py2plug-dir/etc/bareos/bareos-sd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-sd.d/messages/Standard.conf rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-sd.d/messages/Standard.conf diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in diff --git a/systemtests/tests/pyplug-dir/etc/bareos/bconsole.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bconsole.conf.in similarity index 100% rename from systemtests/tests/pyplug-dir/etc/bareos/bconsole.conf.in rename to systemtests/tests/py2plug-dir/etc/bareos/bconsole.conf.in diff --git a/systemtests/tests/pyplug-dir/python-modules/bareos-dir-test.py b/systemtests/tests/py2plug-dir/python-modules/bareos-dir-test.py similarity index 100% rename from systemtests/tests/pyplug-dir/python-modules/bareos-dir-test.py rename to systemtests/tests/py2plug-dir/python-modules/bareos-dir-test.py diff --git a/systemtests/tests/pyplug-dir/testrunner b/systemtests/tests/py2plug-dir/testrunner similarity index 100% rename from systemtests/tests/pyplug-dir/testrunner rename to systemtests/tests/py2plug-dir/testrunner diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/messages/Daemon.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/messages/Daemon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/messages/Daemon.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/messages/Daemon.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/messages/Standard.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/messages/Standard.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/messages/Standard.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/messages/Standard.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/pool/Differential.conf b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/pool/Differential.conf similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/pool/Differential.conf rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/pool/Differential.conf diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/pool/Full.conf b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/pool/Full.conf similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/pool/Full.conf rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/pool/Full.conf diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/pool/Incremental.conf b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/pool/Incremental.conf similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/pool/Incremental.conf rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/pool/Incremental.conf diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/pool/Scratch.conf b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/pool/Scratch.conf similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/pool/Scratch.conf rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/pool/Scratch.conf diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/profile/operator.conf b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/profile/operator.conf similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/profile/operator.conf rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/profile/operator.conf diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/storage/File.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/storage/File.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/storage/File.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/storage/File.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/client/myself.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/client/myself.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/client/myself.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/messages/Standard.conf b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/messages/Standard.conf rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/messages/Standard.conf diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/device/FileStorage.conf b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/device/FileStorage.conf similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/device/FileStorage.conf rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/device/FileStorage.conf diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/messages/Standard.conf b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/messages/Standard.conf rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/messages/Standard.conf diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bconsole.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bconsole.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/etc/bareos/bconsole.conf.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bconsole.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/mysqldefaults.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/mysqldefaults.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/mysqldefaults.in rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/mysqldefaults.in diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py diff --git a/systemtests/tests/pyplug-fd-local-fileset-restoreobject/testrunner b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/testrunner similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset-restoreobject/testrunner rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/testrunner diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/messages/Daemon.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/messages/Daemon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/messages/Daemon.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/messages/Daemon.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/messages/Standard.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/messages/Standard.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/messages/Standard.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/messages/Standard.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/pool/Differential.conf b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/pool/Differential.conf similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/pool/Differential.conf rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/pool/Differential.conf diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/pool/Full.conf b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/pool/Full.conf similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/pool/Full.conf rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/pool/Full.conf diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/pool/Incremental.conf b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/pool/Incremental.conf similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/pool/Incremental.conf rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/pool/Incremental.conf diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/pool/Scratch.conf b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/pool/Scratch.conf similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/pool/Scratch.conf rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/pool/Scratch.conf diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/profile/operator.conf b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/profile/operator.conf similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/profile/operator.conf rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/profile/operator.conf diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/storage/File.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/storage/File.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-dir.d/storage/File.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/storage/File.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-fd.d/client/myself.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-fd.d/client/myself.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-fd.d/client/myself.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-fd.d/messages/Standard.conf b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-fd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-fd.d/messages/Standard.conf rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-fd.d/messages/Standard.conf diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-sd.d/device/FileStorage.conf b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-sd.d/device/FileStorage.conf similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-sd.d/device/FileStorage.conf rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-sd.d/device/FileStorage.conf diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-sd.d/messages/Standard.conf b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-sd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-sd.d/messages/Standard.conf rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-sd.d/messages/Standard.conf diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bconsole.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bconsole.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/etc/bareos/bconsole.conf.in rename to systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bconsole.conf.in diff --git a/systemtests/tests/pyplug-fd-local-fileset/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py rename to systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py diff --git a/systemtests/tests/pyplug-fd-local-fileset/python-modules/bareos-fd-local-fileset-with-restoreobjects.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset-with-restoreobjects.py similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/python-modules/bareos-fd-local-fileset-with-restoreobjects.py rename to systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset-with-restoreobjects.py diff --git a/systemtests/tests/pyplug-fd-local-fileset/python-modules/bareos_fd_local_fileset_with_restoreobjects.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos_fd_local_fileset_with_restoreobjects.py similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/python-modules/bareos_fd_local_fileset_with_restoreobjects.py rename to systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos_fd_local_fileset_with_restoreobjects.py diff --git a/systemtests/tests/pyplug-fd-local-fileset/testrunner b/systemtests/tests/py2plug-fd-local-fileset/testrunner similarity index 100% rename from systemtests/tests/pyplug-fd-local-fileset/testrunner rename to systemtests/tests/py2plug-fd-local-fileset/testrunner diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/OvirtTest.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/OvirtTest.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/OvirtTest.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/OvirtTest.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/messages/Daemon.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/messages/Daemon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/messages/Daemon.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/messages/Daemon.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/messages/Standard.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/messages/Standard.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/messages/Standard.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/messages/Standard.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/pool/Differential.conf b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/pool/Differential.conf similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/pool/Differential.conf rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/pool/Differential.conf diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/pool/Full.conf b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/pool/Full.conf similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/pool/Full.conf rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/pool/Full.conf diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/pool/Incremental.conf b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/pool/Incremental.conf similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/pool/Incremental.conf rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/pool/Incremental.conf diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/pool/Scratch.conf b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/pool/Scratch.conf similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/pool/Scratch.conf rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/pool/Scratch.conf diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/profile/operator.conf b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/profile/operator.conf similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/profile/operator.conf rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/profile/operator.conf diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/storage/File.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/storage/File.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-dir.d/storage/File.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/storage/File.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-fd.d/client/myself.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-fd.d/client/myself.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-fd.d/client/myself.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-fd.d/messages/Standard.conf b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-fd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-fd.d/messages/Standard.conf rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-fd.d/messages/Standard.conf diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-sd.d/device/FileStorage.conf b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-sd.d/device/FileStorage.conf similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-sd.d/device/FileStorage.conf rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-sd.d/device/FileStorage.conf diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-sd.d/messages/Standard.conf b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-sd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-sd.d/messages/Standard.conf rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-sd.d/messages/Standard.conf diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/etc/bareos/bconsole.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bconsole.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/etc/bareos/bconsole.conf.in rename to systemtests/tests/py2plug-fd-ovirt/etc/bareos/bconsole.conf.in diff --git a/systemtests/tests/pyplug-fd-ovirt/testrunner b/systemtests/tests/py2plug-fd-ovirt/testrunner similarity index 100% rename from systemtests/tests/pyplug-fd-ovirt/testrunner rename to systemtests/tests/py2plug-fd-ovirt/testrunner diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/messages/Daemon.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/messages/Daemon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/messages/Daemon.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/messages/Daemon.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/messages/Standard.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/messages/Standard.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/messages/Standard.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/messages/Standard.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/pool/Differential.conf b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/pool/Differential.conf similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/pool/Differential.conf rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/pool/Differential.conf diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/pool/Full.conf b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/pool/Full.conf similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/pool/Full.conf rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/pool/Full.conf diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/pool/Incremental.conf b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/pool/Incremental.conf similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/pool/Incremental.conf rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/pool/Incremental.conf diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/pool/Scratch.conf b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/pool/Scratch.conf similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/pool/Scratch.conf rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/pool/Scratch.conf diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/profile/operator.conf b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/profile/operator.conf similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/profile/operator.conf rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/profile/operator.conf diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/storage/File.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/storage/File.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/storage/File.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/storage/File.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/client/myself.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/client/myself.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/client/myself.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/messages/Standard.conf b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/messages/Standard.conf rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/messages/Standard.conf diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/device/FileStorage.conf b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/device/FileStorage.conf similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/device/FileStorage.conf rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/device/FileStorage.conf diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/messages/Standard.conf b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/messages/Standard.conf rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/messages/Standard.conf diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bconsole.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bconsole.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/etc/bareos/bconsole.conf.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bconsole.conf.in diff --git a/systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner b/systemtests/tests/py2plug-fd-percona-xtrabackup/testrunner similarity index 100% rename from systemtests/tests/pyplug-fd-percona-xtrabackup/testrunner rename to systemtests/tests/py2plug-fd-percona-xtrabackup/testrunner diff --git a/systemtests/tests/pyplug-fd-postgres/database/setup_local_db.sh b/systemtests/tests/py2plug-fd-postgres/database/setup_local_db.sh similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/database/setup_local_db.sh rename to systemtests/tests/py2plug-fd-postgres/database/setup_local_db.sh diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/messages/Daemon.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/messages/Daemon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/messages/Daemon.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/messages/Daemon.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/messages/Standard.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/messages/Standard.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/messages/Standard.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/messages/Standard.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/pool/Differential.conf b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/pool/Differential.conf similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/pool/Differential.conf rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/pool/Differential.conf diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/pool/Full.conf b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/pool/Full.conf similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/pool/Full.conf rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/pool/Full.conf diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/pool/Incremental.conf b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/pool/Incremental.conf similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/pool/Incremental.conf rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/pool/Incremental.conf diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/pool/Scratch.conf b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/pool/Scratch.conf similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/pool/Scratch.conf rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/pool/Scratch.conf diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/profile/operator.conf b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/profile/operator.conf similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/profile/operator.conf rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/profile/operator.conf diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/storage/File.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/storage/File.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-dir.d/storage/File.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/storage/File.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-fd.d/client/myself.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-fd.d/client/myself.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-fd.d/client/myself.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-fd.d/messages/Standard.conf b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-fd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-fd.d/messages/Standard.conf rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-fd.d/messages/Standard.conf diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-sd.d/device/FileStorage.conf b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-sd.d/device/FileStorage.conf similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-sd.d/device/FileStorage.conf rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-sd.d/device/FileStorage.conf diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-sd.d/messages/Standard.conf b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-sd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-sd.d/messages/Standard.conf rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-sd.d/messages/Standard.conf diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/etc/bareos/bconsole.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bconsole.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/etc/bareos/bconsole.conf.in rename to systemtests/tests/py2plug-fd-postgres/etc/bareos/bconsole.conf.in diff --git a/systemtests/tests/pyplug-fd-postgres/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py b/systemtests/tests/py2plug-fd-postgres/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py rename to systemtests/tests/py2plug-fd-postgres/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py diff --git a/systemtests/tests/pyplug-fd-postgres/python-modules/bareos-fd-local-fileset-with-restoreobjects.py b/systemtests/tests/py2plug-fd-postgres/python-modules/bareos-fd-local-fileset-with-restoreobjects.py similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/python-modules/bareos-fd-local-fileset-with-restoreobjects.py rename to systemtests/tests/py2plug-fd-postgres/python-modules/bareos-fd-local-fileset-with-restoreobjects.py diff --git a/systemtests/tests/pyplug-fd-postgres/testrunner b/systemtests/tests/py2plug-fd-postgres/testrunner similarity index 100% rename from systemtests/tests/pyplug-fd-postgres/testrunner rename to systemtests/tests/py2plug-fd-postgres/testrunner diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/VMwareTest.ini.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/VMwareTest.ini.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/VMwareTest.ini.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/VMwareTest.ini.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/fileset/VMwareTest.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/fileset/VMwareTest.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/fileset/VMwareTest.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/fileset/VMwareTest.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/messages/Daemon.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/messages/Daemon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/messages/Daemon.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/messages/Daemon.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/messages/Standard.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/messages/Standard.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/messages/Standard.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/messages/Standard.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/pool/Differential.conf b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/pool/Differential.conf similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/pool/Differential.conf rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/pool/Differential.conf diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/pool/Full.conf b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/pool/Full.conf similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/pool/Full.conf rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/pool/Full.conf diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/pool/Incremental.conf b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/pool/Incremental.conf similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/pool/Incremental.conf rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/pool/Incremental.conf diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/pool/Scratch.conf b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/pool/Scratch.conf similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/pool/Scratch.conf rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/pool/Scratch.conf diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/profile/operator.conf b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/profile/operator.conf similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/profile/operator.conf rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/profile/operator.conf diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/storage/File.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/storage/File.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-dir.d/storage/File.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-dir.d/storage/File.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-fd.d/client/myself.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-fd.d/client/myself.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-fd.d/client/myself.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-fd.d/messages/Standard.conf b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-fd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-fd.d/messages/Standard.conf rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-fd.d/messages/Standard.conf diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-sd.d/device/FileStorage.conf b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-sd.d/device/FileStorage.conf similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-sd.d/device/FileStorage.conf rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-sd.d/device/FileStorage.conf diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-sd.d/messages/Standard.conf b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-sd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-sd.d/messages/Standard.conf rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-sd.d/messages/Standard.conf diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/etc/bareos/bconsole.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bconsole.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/etc/bareos/bconsole.conf.in rename to systemtests/tests/py2plug-fd-vmware/etc/bareos/bconsole.conf.in diff --git a/systemtests/tests/pyplug-fd-vmware/reset_cbt.sh b/systemtests/tests/py2plug-fd-vmware/reset_cbt.sh similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/reset_cbt.sh rename to systemtests/tests/py2plug-fd-vmware/reset_cbt.sh diff --git a/systemtests/tests/pyplug-fd-vmware/testrunner b/systemtests/tests/py2plug-fd-vmware/testrunner similarity index 100% rename from systemtests/tests/pyplug-fd-vmware/testrunner rename to systemtests/tests/py2plug-fd-vmware/testrunner diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/messages/Daemon.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/messages/Daemon.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/messages/Daemon.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/messages/Daemon.conf.in diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/messages/Standard.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/messages/Standard.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/messages/Standard.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/messages/Standard.conf.in diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/pool/Differential.conf b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/pool/Differential.conf similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/pool/Differential.conf rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/pool/Differential.conf diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/pool/Full.conf b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/pool/Full.conf similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/pool/Full.conf rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/pool/Full.conf diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/pool/Incremental.conf b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/pool/Incremental.conf similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/pool/Incremental.conf rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/pool/Incremental.conf diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/pool/Scratch.conf b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/pool/Scratch.conf similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/pool/Scratch.conf rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/pool/Scratch.conf diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/profile/operator.conf b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/profile/operator.conf similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/profile/operator.conf rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/profile/operator.conf diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/storage/File.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/storage/File.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-dir.d/storage/File.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/storage/File.conf.in diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-fd.d/client/myself.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-fd.d/client/myself.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-fd.d/client/myself.conf.in diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-fd.d/messages/Standard.conf b/systemtests/tests/py2plug-sd/etc/bareos/bareos-fd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-fd.d/messages/Standard.conf rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-fd.d/messages/Standard.conf diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-sd.d/device/FileStorage.conf b/systemtests/tests/py2plug-sd/etc/bareos/bareos-sd.d/device/FileStorage.conf similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-sd.d/device/FileStorage.conf rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-sd.d/device/FileStorage.conf diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-sd.d/messages/Standard.conf b/systemtests/tests/py2plug-sd/etc/bareos/bareos-sd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-sd.d/messages/Standard.conf rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-sd.d/messages/Standard.conf diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in diff --git a/systemtests/tests/pyplug-sd/etc/bareos/bconsole.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bconsole.conf.in similarity index 100% rename from systemtests/tests/pyplug-sd/etc/bareos/bconsole.conf.in rename to systemtests/tests/py2plug-sd/etc/bareos/bconsole.conf.in diff --git a/systemtests/tests/pyplug-sd/python-modules/bareos-sd-test.py b/systemtests/tests/py2plug-sd/python-modules/bareos-sd-test.py similarity index 100% rename from systemtests/tests/pyplug-sd/python-modules/bareos-sd-test.py rename to systemtests/tests/py2plug-sd/python-modules/bareos-sd-test.py diff --git a/systemtests/tests/pyplug-sd/testrunner b/systemtests/tests/py2plug-sd/testrunner similarity index 100% rename from systemtests/tests/pyplug-sd/testrunner rename to systemtests/tests/py2plug-sd/testrunner diff --git a/systemtests/tests/py3plug-dir b/systemtests/tests/py3plug-dir new file mode 120000 index 00000000000..5db90547d1d --- /dev/null +++ b/systemtests/tests/py3plug-dir @@ -0,0 +1 @@ +py2plug-dir \ No newline at end of file diff --git a/systemtests/tests/py3plug-fd-local-fileset b/systemtests/tests/py3plug-fd-local-fileset new file mode 120000 index 00000000000..616bb8019ed --- /dev/null +++ b/systemtests/tests/py3plug-fd-local-fileset @@ -0,0 +1 @@ +py2plug-fd-local-fileset \ No newline at end of file diff --git a/systemtests/tests/py3plug-fd-local-fileset-restoreobject b/systemtests/tests/py3plug-fd-local-fileset-restoreobject new file mode 120000 index 00000000000..befa7eebc3d --- /dev/null +++ b/systemtests/tests/py3plug-fd-local-fileset-restoreobject @@ -0,0 +1 @@ +py2plug-fd-local-fileset-restoreobject \ No newline at end of file diff --git a/systemtests/tests/py3plug-fd-ovirt b/systemtests/tests/py3plug-fd-ovirt new file mode 120000 index 00000000000..767308e2f8b --- /dev/null +++ b/systemtests/tests/py3plug-fd-ovirt @@ -0,0 +1 @@ +py2plug-fd-ovirt \ No newline at end of file diff --git a/systemtests/tests/py3plug-fd-percona-xtrabackup b/systemtests/tests/py3plug-fd-percona-xtrabackup new file mode 120000 index 00000000000..4bd2f2740a4 --- /dev/null +++ b/systemtests/tests/py3plug-fd-percona-xtrabackup @@ -0,0 +1 @@ +py2plug-fd-percona-xtrabackup \ No newline at end of file diff --git a/systemtests/tests/py3plug-fd-postgres b/systemtests/tests/py3plug-fd-postgres new file mode 120000 index 00000000000..206d3ba3334 --- /dev/null +++ b/systemtests/tests/py3plug-fd-postgres @@ -0,0 +1 @@ +py2plug-fd-postgres \ No newline at end of file diff --git a/systemtests/tests/py3plug-fd-vmware b/systemtests/tests/py3plug-fd-vmware new file mode 120000 index 00000000000..a43d01ee18b --- /dev/null +++ b/systemtests/tests/py3plug-fd-vmware @@ -0,0 +1 @@ +py2plug-fd-vmware \ No newline at end of file diff --git a/systemtests/tests/py3plug-sd b/systemtests/tests/py3plug-sd new file mode 120000 index 00000000000..f2095de8722 --- /dev/null +++ b/systemtests/tests/py3plug-sd @@ -0,0 +1 @@ +py2plug-sd \ No newline at end of file diff --git a/systemtests/tests/python-fd-plugin-postgres-test/database/setup_local_db.sh b/systemtests/tests/python-fd-plugin-postgres-test/database/setup_local_db.sh deleted file mode 100755 index c4bd80d7414..00000000000 --- a/systemtests/tests/python-fd-plugin-postgres-test/database/setup_local_db.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/bash - -local_db_stop_server() { - echo "Stop db server" - pg_ctl --silent --pgdata=data stop - tries=10 - while psql --host="$1" --list > /dev/null 2>&1; do - echo " -- $tries -- " - [ $((tries-=1)) -eq 0 ] && { - echo "Could not stop postgres server" - return 1 - } - sleep 0.3 - done -} - -local_db_prepare_files() { - echo "Prepare files" - rm --recursive --force tmp data log wal_archive - mkdir tmp data log wal_archive - LANG= pg_ctl --silent --pgdata=data --log=log/postgres.log initdb - - sed -i.bak "s@#listen_addresses.*@listen_addresses = ''@g" data/postgresql.conf - sed -i.bak "s@#unix_socket_directories.*@unix_socket_directories = \'$1\'@g" data/postgresql.conf - - { - # for online backups we need wal_archiving - echo "wal_level = archive" - echo "archive_mode = on" - echo "archive_command = 'cp %p ../wal_archive'" - echo "max_wal_senders = 10" - } >> data/postgresql.conf -} - -local_db_start_server() { - echo "Start db server" - pg_ctl --silent --pgdata=data --log=log/logfile start - - tries=10 - while ! psql --host="$1" --list > /dev/null 2>&1; do - [ $((tries-=1)) -eq 0 ] && { - echo "Could not start postgres server" - cat log/logfile - cat database/log/*.log - return 1 - } - sleep 0.1 - done - - return 0 -} - -local_db_create_superuser_role() { - echo "CREATE ROLE root WITH SUPERUSER CREATEDB CREATEROLE REPLICATION LOGIN" |psql -h "$1" postgres -} - -setup_local_db() { - local_db_stop_server "$1" - local_db_prepare_files "$1" - if ! local_db_start_server "$1"; then return 1; fi - local_db_create_superuser_role "$1" - - echo stop server with "pg_ctl --pgdata=data stop" - - return 0 -} - diff --git a/systemtests/tests/python3-dir-plugin-test b/systemtests/tests/python3-dir-plugin-test deleted file mode 120000 index f6f0f4a897f..00000000000 --- a/systemtests/tests/python3-dir-plugin-test +++ /dev/null @@ -1 +0,0 @@ -python-dir-plugin-test \ No newline at end of file diff --git a/systemtests/tests/python3-fd-ovirt-plugin-test b/systemtests/tests/python3-fd-ovirt-plugin-test deleted file mode 120000 index 92ee642c62e..00000000000 --- a/systemtests/tests/python3-fd-ovirt-plugin-test +++ /dev/null @@ -1 +0,0 @@ -python-fd-ovirt-plugin-test/ \ No newline at end of file diff --git a/systemtests/tests/python3-fd-percona-xtrabackup-plugin-test b/systemtests/tests/python3-fd-percona-xtrabackup-plugin-test deleted file mode 120000 index 7adf3cb088e..00000000000 --- a/systemtests/tests/python3-fd-percona-xtrabackup-plugin-test +++ /dev/null @@ -1 +0,0 @@ -python-fd-percona-xtrabackup-plugin-test/ \ No newline at end of file diff --git a/systemtests/tests/python3-fd-plugin-local-fileset-test b/systemtests/tests/python3-fd-plugin-local-fileset-test deleted file mode 120000 index abcf40b9b22..00000000000 --- a/systemtests/tests/python3-fd-plugin-local-fileset-test +++ /dev/null @@ -1 +0,0 @@ -python-fd-plugin-local-fileset-test \ No newline at end of file diff --git a/systemtests/tests/python3-fd-plugin-postgres-test b/systemtests/tests/python3-fd-plugin-postgres-test deleted file mode 120000 index 9b59874a914..00000000000 --- a/systemtests/tests/python3-fd-plugin-postgres-test +++ /dev/null @@ -1 +0,0 @@ -python-fd-plugin-postgres-test \ No newline at end of file diff --git a/systemtests/tests/python3-sd-plugin-test b/systemtests/tests/python3-sd-plugin-test deleted file mode 120000 index e67f6882c9d..00000000000 --- a/systemtests/tests/python3-sd-plugin-test +++ /dev/null @@ -1 +0,0 @@ -python-sd-plugin-test \ No newline at end of file From eb7c6f92d76002e43cdaa8e4a41b76fe6845acc8 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 14 Aug 2020 10:02:19 +0200 Subject: [PATCH 222/341] tests: fix python_module_name problem --- systemtests/CMakeLists.txt | 27 +++++++++++++------ .../bareos/bareos-fd.d/client/myself.conf.in | 2 +- .../bareos-dir.d/director/bareos-dir.conf.in | 2 +- .../bareos-dir.d/job/backup-bareos-fd.conf.in | 2 +- .../bareos-dir.d/fileset/PluginTest.conf.in | 2 +- .../bareos/bareos-fd.d/client/myself.conf.in | 2 +- .../bareos/bareos-fd.d/client/myself.conf.in | 2 +- .../bareos-dir.d/fileset/OvirtTest.conf.in | 2 +- .../bareos/bareos-fd.d/client/myself.conf.in | 2 +- systemtests/tests/py2plug-fd-ovirt/testrunner | 2 +- .../fileset/PerconaXtraBackupTest.conf.in | 2 +- .../bareos/bareos-fd.d/client/myself.conf.in | 2 +- .../bareos-dir.d/fileset/PluginTest.conf.in | 2 +- .../bareos-dir.d/job/backup-bareos-fd.conf.in | 2 +- .../bareos-sd.d/storage/bareos-sd.conf.in | 2 +- 15 files changed, 33 insertions(+), 22 deletions(-) diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 3ebe93660e7..fa0fea7586f 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -658,9 +658,9 @@ else() message("NOT OK, disabling py2plug-fd-postgres:") endif() if(TARGET python3-fd) - list(APPEND SYSTEM_TESTS "python3-fd-plugin-postgres-test") + list(APPEND SYSTEM_TESTS "py3plug-fd-postgres") else() - list(APPEND SYSTEM_TESTS_DISABLED "python3-fd-plugin-postgres-test") + list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-postgres") endif() if(TARGET python-fd AND ovirt_server) @@ -829,9 +829,20 @@ endif() foreach(TEST_NAME ${SYSTEM_TESTS}) message(STATUS "Configuring test: ${SYSTEMTEST_PREFIX}${TEST_NAME}") - string(REGEX MATCH "^pyplug[^-]?" python_version "${TEST_NAME}") - # if(python_version) message(STATUS "python_version:" ${python_version}) # - # python or python3 endif() + string(REGEX MATCH "py2plug" py_v2 "${TEST_NAME}") + string(REGEX MATCH "py3plug" py_v3 "${TEST_NAME}") + if(py_v2) + set(python_module_name python) + message(ERROR + "python_module_name: ${python_module_name}, TEST_NAME: ${TEST_NAME}" + ) + endif() + if(py_v3) + set(python_module_name python3) + message(ERROR + "python_module_name: ${python_module_name}, TEST_NAME: ${TEST_NAME}" + ) + endif() prepare_test() configurefilestosystemtest("systemtests" "tests/${TEST_NAME}" "*" @ONLY "") @@ -844,9 +855,9 @@ foreach(TEST_NAME ${SYSTEM_TESTS}) "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/postgres:" "${CMAKE_SOURCE_DIR}/core/src/plugins/stored/python/pyfiles:" "${CMAKE_SOURCE_DIR}/core/src/plugins/dird/python/pyfiles:" - "${CMAKE_BINARY_DIR}/core/src/plugins/filed/python/${python_version}modules:" - "${CMAKE_BINARY_DIR}/core/src/plugins/stored/python/${python_version}modules:" - "${CMAKE_BINARY_DIR}/core/src/plugins/dird/python/${python_version}modules:" + "${CMAKE_BINARY_DIR}/core/src/plugins/filed/python/${python_module_name}modules:" + "${CMAKE_BINARY_DIR}/core/src/plugins/stored/python/${python_module_name}modules:" + "${CMAKE_BINARY_DIR}/core/src/plugins/dird/python/${python_module_name}modules:" "${CMAKE_CURRENT_SOURCE_DIR}/tests/${TEST_NAME}/python-modules" ) diff --git a/systemtests/tests/dbcopy-mysql-postgresql/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/dbcopy-mysql-postgresql/etc/bareos/bareos-fd.d/client/myself.conf.in index d112d62cf62..d3159177cdf 100644 --- a/systemtests/tests/dbcopy-mysql-postgresql/etc/bareos/bareos-fd.d/client/myself.conf.in +++ b/systemtests/tests/dbcopy-mysql-postgresql/etc/bareos/bareos-fd.d/client/myself.conf.in @@ -7,7 +7,7 @@ Client { # otherwise all filedaemon plugins (*-fd.so) from the "Plugin Directory". # Plugin Directory = "@fd_plugin_binary_path@" - Plugin Names = "@python_version@" + Plugin Names = "@python_module_name@" # if compatible is set to yes, we are compatible with bacula # if set to no, new bareos features are enabled which is the default diff --git a/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in index b62199bae0d..7fdb44c8ee3 100644 --- a/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in +++ b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in @@ -20,7 +20,7 @@ Director { # define myself # otherwise all director plugins (*-dir.so) from the "Plugin Directory". # Plugin Directory = "@dir_plugin_binary_path@" - Plugin Names = "@python_version@" + Plugin Names = "@python_module_name@" Working Directory = "@working_dir@" Pid Directory = "@piddir@" DirPort = @dir_port@ diff --git a/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in index 8b71aa56c39..b77a57e34a4 100644 --- a/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in +++ b/systemtests/tests/py2plug-dir/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in @@ -1,6 +1,6 @@ Job { Name = "backup-bareos-fd" - DIR Plugin Options ="@python_version@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-dir-test:output=@tmp@/test-plugin.log" + DIR Plugin Options ="@python_module_name@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-dir-test:output=@tmp@/test-plugin.log" JobDefs = "DefaultJob" Client = "bareos-fd" } diff --git a/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in index 078a558a772..c016559247f 100644 --- a/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in +++ b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in @@ -5,6 +5,6 @@ FileSet { Options { signature = MD5 } - Plugin = "@python_version@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos_fd_local_fileset_with_restoreobjects:filename=@tmpdir@/file-list" + Plugin = "@python_module_name@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos_fd_local_fileset_with_restoreobjects:filename=@tmpdir@/file-list" } } diff --git a/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/client/myself.conf.in index d3978eea8a8..3a7cce9488e 100644 --- a/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/client/myself.conf.in +++ b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-fd.d/client/myself.conf.in @@ -7,7 +7,7 @@ Client { # otherwise all filedaemon plugins (*-fd.so) from the "Plugin Directory". # Plugin Directory = "@fd_plugin_binary_path@" - Plugin Names = "@python_version@" + Plugin Names = "@python_module_name@" # if compatible is set to yes, we are compatible with bacula # if set to no, new bareos features are enabled which is the default diff --git a/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-fd.d/client/myself.conf.in index d3978eea8a8..3a7cce9488e 100644 --- a/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-fd.d/client/myself.conf.in +++ b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-fd.d/client/myself.conf.in @@ -7,7 +7,7 @@ Client { # otherwise all filedaemon plugins (*-fd.so) from the "Plugin Directory". # Plugin Directory = "@fd_plugin_binary_path@" - Plugin Names = "@python_version@" + Plugin Names = "@python_module_name@" # if compatible is set to yes, we are compatible with bacula # if set to no, new bareos features are enabled which is the default diff --git a/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/OvirtTest.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/OvirtTest.conf.in index cddb4fe1551..1a96c118645 100644 --- a/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/OvirtTest.conf.in +++ b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-dir.d/fileset/OvirtTest.conf.in @@ -5,6 +5,6 @@ FileSet { Options { signature = MD5 } - Plugin = "@python_version@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-ovirt:ca=@current_test_directory@/etc/bareos/ovirt-ca.cert:server=@ovirt_server@:username=@ovirt_user@:password=@ovirt_password@:vm_name=@ovirt_vm_name@:include_disk_aliases=@ovirt_include_disk_alias@" + Plugin = "@python_module_name@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-ovirt:ca=@current_test_directory@/etc/bareos/ovirt-ca.cert:server=@ovirt_server@:username=@ovirt_user@:password=@ovirt_password@:vm_name=@ovirt_vm_name@:include_disk_aliases=@ovirt_include_disk_alias@" } } diff --git a/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-fd.d/client/myself.conf.in index d3978eea8a8..3a7cce9488e 100644 --- a/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-fd.d/client/myself.conf.in +++ b/systemtests/tests/py2plug-fd-ovirt/etc/bareos/bareos-fd.d/client/myself.conf.in @@ -7,7 +7,7 @@ Client { # otherwise all filedaemon plugins (*-fd.so) from the "Plugin Directory". # Plugin Directory = "@fd_plugin_binary_path@" - Plugin Names = "@python_version@" + Plugin Names = "@python_module_name@" # if compatible is set to yes, we are compatible with bacula # if set to no, new bareos features are enabled which is the default diff --git a/systemtests/tests/py2plug-fd-ovirt/testrunner b/systemtests/tests/py2plug-fd-ovirt/testrunner index 90915d5b9e7..2a7beb145f6 100755 --- a/systemtests/tests/py2plug-fd-ovirt/testrunner +++ b/systemtests/tests/py2plug-fd-ovirt/testrunner @@ -49,7 +49,7 @@ messages @# @$out $tmp/log2.out wait -restore client=bareos-fd fileset=OvirtTest where=$tmp/bareos-restores pluginoptions=@python_version@:local=yes select all done +restore client=bareos-fd fileset=OvirtTest where=$tmp/bareos-restores pluginoptions=@python_module_name@:local=yes select all done yes wait messages diff --git a/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in index 3678677ccc0..57a884125ea 100644 --- a/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in +++ b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-dir.d/fileset/PerconaXtraBackupTest.conf.in @@ -5,6 +5,6 @@ FileSet { Options { signature = MD5 } - Plugin = "@python_version@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-percona-xtrabackup:dumpbinary=@XTRABACKUP@ --defaults-file=mysqldefaults:extradumpoptions=--user=root@extradumpoptions@:mysqlcmd=mysql --defaults-file=mysqldefaults --user=root --raw" + Plugin = "@python_module_name@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-percona-xtrabackup:dumpbinary=@XTRABACKUP@ --defaults-file=mysqldefaults:extradumpoptions=--user=root@extradumpoptions@:mysqlcmd=mysql --defaults-file=mysqldefaults --user=root --raw" } } diff --git a/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/client/myself.conf.in index d3978eea8a8..3a7cce9488e 100644 --- a/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/client/myself.conf.in +++ b/systemtests/tests/py2plug-fd-percona-xtrabackup/etc/bareos/bareos-fd.d/client/myself.conf.in @@ -7,7 +7,7 @@ Client { # otherwise all filedaemon plugins (*-fd.so) from the "Plugin Directory". # Plugin Directory = "@fd_plugin_binary_path@" - Plugin Names = "@python_version@" + Plugin Names = "@python_module_name@" # if compatible is set to yes, we are compatible with bacula # if set to no, new bareos features are enabled which is the default diff --git a/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in index 938fb09486a..95bfeda92a1 100644 --- a/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in +++ b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in @@ -5,6 +5,6 @@ FileSet { Options { signature = MD5 } - Plugin = "@python_version@:module_path=@current_test_directory@/python-modules:module_name=bareos-fd-postgres:dbHost=@current_test_directory@/tmp:postgresDataDir=@current_test_directory@/database/data:walArchive=@current_test_directory@/database/wal_archive/" + Plugin = "@python_module_name@:module_path=@current_test_directory@/python-modules:module_name=bareos-fd-postgres:dbHost=@current_test_directory@/tmp:postgresDataDir=@current_test_directory@/database/data:walArchive=@current_test_directory@/database/wal_archive/" } } diff --git a/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in index b178362d83b..1a0f1ed618d 100644 --- a/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in +++ b/systemtests/tests/py2plug-sd/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in @@ -1,6 +1,6 @@ Job { Name = "backup-bareos-fd" - SD Plugin Options = "@python_version@:instance=0:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-sd-test:output=@tmp@/test-plugin.log" + SD Plugin Options = "@python_module_name@:instance=0:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-sd-test:output=@tmp@/test-plugin.log" JobDefs = "DefaultJob" Client = "bareos-fd" } diff --git a/systemtests/tests/py2plug-sd/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in b/systemtests/tests/py2plug-sd/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in index 7b27afe81df..d2cb09ca4ac 100644 --- a/systemtests/tests/py2plug-sd/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in +++ b/systemtests/tests/py2plug-sd/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in @@ -7,7 +7,7 @@ Storage { # otherwise all storage plugins (*-sd.so) from the "Plugin Directory". # Plugin Directory = "@sd_plugin_binary_path@" - Plugin Names = "@python_version@" + Plugin Names = "@python_module_name@" Working Directory = "@working_dir@" Pid Directory = "@piddir@" SD Port = @sd_port@ From 5d3d989ad004e256930dab8e86ed07f7e1af72ca Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 14 Aug 2020 10:50:45 +0200 Subject: [PATCH 223/341] python plugins: fix typo in function name load_bareos_plugin --- core/src/plugins/dird/python/python-dir.cc | 2 +- core/src/plugins/filed/python/python-fd.cc | 2 +- core/src/plugins/stored/python/python-sd.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/plugins/dird/python/python-dir.cc b/core/src/plugins/dird/python/python-dir.cc index 7b5054b591e..a40cf575a85 100644 --- a/core/src/plugins/dird/python/python-dir.cc +++ b/core/src/plugins/dird/python/python-dir.cc @@ -602,7 +602,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) } } else { Dmsg(plugin_ctx, debuglevel, - LOGPREFIX "Failed to find function named load_bareos_plugins()\n"); + LOGPREFIX "Failed to find function named load_bareos_plugin()\n"); goto bail_out; } diff --git a/core/src/plugins/filed/python/python-fd.cc b/core/src/plugins/filed/python/python-fd.cc index 1e6664542c6..00b8c58e6f7 100644 --- a/core/src/plugins/filed/python/python-fd.cc +++ b/core/src/plugins/filed/python/python-fd.cc @@ -1015,7 +1015,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) } } else { Dmsg(plugin_ctx, debuglevel, - LOGPREFIX "Failed to find function named load_bareos_plugins()\n"); + LOGPREFIX "Failed to find function named load_bareos_plugin()\n"); goto bail_out; } diff --git a/core/src/plugins/stored/python/python-sd.cc b/core/src/plugins/stored/python/python-sd.cc index b4210cfd276..3284863e030 100644 --- a/core/src/plugins/stored/python/python-sd.cc +++ b/core/src/plugins/stored/python/python-sd.cc @@ -598,7 +598,7 @@ static bRC PyLoadModule(PluginContext* plugin_ctx, void* value) } } else { Dmsg(plugin_ctx, debuglevel, - LOGPREFIX "Failed to find function named load_bareos_plugins()\n"); + LOGPREFIX "Failed to find function named load_bareos_plugin()\n"); goto bail_out; } From 021ee5d3704d32ce63a257bc258f322638402e79 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 14 Aug 2020 13:22:35 +0200 Subject: [PATCH 224/341] merge fixes: more cleanup --- core/src/plugins/filed/bareos-fd-vmware.py | 6 +- .../python/pyfiles/BareosFdPluginBaseclass.py | 4 +- .../python/pyfiles/bareos-fd-local-fileset.py | 4 +- systemtests/CMakeLists.txt | 14 ++--- .../bareos-dir.d/fileset/PluginTest.conf.in | 2 +- ...os-fd-local-fileset-with-restoreobjects.py | 6 +- ...os-fd-local-fileset-with-restoreobjects.py | 59 ------------------- 7 files changed, 18 insertions(+), 77 deletions(-) rename systemtests/tests/{dbcopy-mysql-postgresql => py2plug-fd-local-fileset-restoreobject}/python-modules/bareos-fd-local-fileset-with-restoreobjects.py (95%) delete mode 100644 systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset-with-restoreobjects.py diff --git a/core/src/plugins/filed/bareos-fd-vmware.py b/core/src/plugins/filed/bareos-fd-vmware.py index 1f31bab0cb2..92a05971913 100644 --- a/core/src/plugins/filed/bareos-fd-vmware.py +++ b/core/src/plugins/filed/bareos-fd-vmware.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # BAREOS® - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2014-2017 Bareos GmbH & Co. KG +# Copyright (C) 2014-2020 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -57,13 +57,13 @@ import BareosFdPluginVMware -def load_bareos_plugin(context, plugindef): +def load_bareos_plugin(plugindef): """ This function is called by the Bareos-FD to load the plugin We use it to intantiate the plugin class """ BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginVMware.BareosFdPluginVMware( - context, plugindef + plugindef ) return bRCs["bRC_OK"] diff --git a/core/src/plugins/filed/python/pyfiles/BareosFdPluginBaseclass.py b/core/src/plugins/filed/python/pyfiles/BareosFdPluginBaseclass.py index 64106d13f47..4008a924443 100644 --- a/core/src/plugins/filed/python/pyfiles/BareosFdPluginBaseclass.py +++ b/core/src/plugins/filed/python/pyfiles/BareosFdPluginBaseclass.py @@ -138,7 +138,7 @@ def check_options(self, mandatory_options=None): def plugin_io_open(self, IOP): self.FNAME = IOP.fname.decode("string_escape") bareosfd.DebugMessage( - context, 250, "io_open: self.FNAME is set to %s\n" % (self.FNAME) + 250, "io_open: self.FNAME is set to %s\n" % (self.FNAME) ) if os.path.isdir(self.FNAME): bareosfd.DebugMessage(100, "%s is a directory\n" % (self.FNAME)) @@ -154,7 +154,7 @@ def plugin_io_open(self, IOP): 100, "Did not open file %s of type %s\n" % (self.FNAME, self.fileType), ) - return bRC_OK" + return bRC_OK elif os.path.exists(self.FNAME) and stat.S_ISFIFO(os.stat(self.FNAME).st_mode): self.fileType = "FT_FIFO" bareosfd.DebugMessage( diff --git a/core/src/plugins/filed/python/pyfiles/bareos-fd-local-fileset.py b/core/src/plugins/filed/python/pyfiles/bareos-fd-local-fileset.py index a8be185d9ec..da08418b637 100644 --- a/core/src/plugins/filed/python/pyfiles/bareos-fd-local-fileset.py +++ b/core/src/plugins/filed/python/pyfiles/bareos-fd-local-fileset.py @@ -27,7 +27,7 @@ # # Provided by the Bareos FD Python plugin interface -import bareos_fd_consts +import bareosfd # This module contains the wrapper functions called by the Bareos-FD, the # functions call the corresponding methods from your plugin class @@ -50,7 +50,7 @@ def load_bareos_plugin(plugindef): BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLocalFileset.BareosFdPluginLocalFileset( plugindef ) - return bareos_fd_consts.bRCs["bRC_OK"] + return bareosfd.bRC_OK # the rest is done in the Plugin module diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index fa0fea7586f..47f30ded52a 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -643,6 +643,12 @@ else() list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-local-fileset-restoreobject") endif() +if(TARGET python3-fd) + list(APPEND SYSTEM_TESTS "py3plug-fd-local-fileset-restoreobject") +else() + list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-local-fileset-restoreobject") +endif() + message("checking for requirements of py2plug-fd-postgres:") check_pymodule_available("psycopg2") check_pymodule_available("dateutil") @@ -833,15 +839,9 @@ foreach(TEST_NAME ${SYSTEM_TESTS}) string(REGEX MATCH "py3plug" py_v3 "${TEST_NAME}") if(py_v2) set(python_module_name python) - message(ERROR - "python_module_name: ${python_module_name}, TEST_NAME: ${TEST_NAME}" - ) endif() if(py_v3) set(python_module_name python3) - message(ERROR - "python_module_name: ${python_module_name}, TEST_NAME: ${TEST_NAME}" - ) endif() prepare_test() @@ -849,10 +849,10 @@ foreach(TEST_NAME ${SYSTEM_TESTS}) string( CONCAT pythonpath - "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/pyfiles:" "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/percona-xtrabackup:" "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/ovirt:" "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/postgres:" + "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/pyfiles:" "${CMAKE_SOURCE_DIR}/core/src/plugins/stored/python/pyfiles:" "${CMAKE_SOURCE_DIR}/core/src/plugins/dird/python/pyfiles:" "${CMAKE_BINARY_DIR}/core/src/plugins/filed/python/${python_module_name}modules:" diff --git a/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in index c016559247f..67383455aad 100644 --- a/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in +++ b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in @@ -5,6 +5,6 @@ FileSet { Options { signature = MD5 } - Plugin = "@python_module_name@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos_fd_local_fileset_with_restoreobjects:filename=@tmpdir@/file-list" + Plugin = "@python_module_name@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-local-fileset-with-restoreobjects:filename=@tmpdir@/file-list" } } diff --git a/systemtests/tests/dbcopy-mysql-postgresql/python-modules/bareos-fd-local-fileset-with-restoreobjects.py b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/python-modules/bareos-fd-local-fileset-with-restoreobjects.py similarity index 95% rename from systemtests/tests/dbcopy-mysql-postgresql/python-modules/bareos-fd-local-fileset-with-restoreobjects.py rename to systemtests/tests/py2plug-fd-local-fileset-restoreobject/python-modules/bareos-fd-local-fileset-with-restoreobjects.py index b03eb7013d8..aa8f22ca94c 100644 --- a/systemtests/tests/dbcopy-mysql-postgresql/python-modules/bareos-fd-local-fileset-with-restoreobjects.py +++ b/systemtests/tests/py2plug-fd-local-fileset-restoreobject/python-modules/bareos-fd-local-fileset-with-restoreobjects.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # BAREOS - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2014-2014 Bareos GmbH & Co. KG +# Copyright (C) 2014-2020 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -30,7 +30,7 @@ # # Provided by the Bareos FD Python plugin interface -import bareos_fd_consts +import bareosfd # This module contains the wrapper functions called by the Bareos-FD, the # functions call the corresponding methods from your plugin class @@ -53,7 +53,7 @@ def load_bareos_plugin(plugindef): BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLocalFilesetWithRestoreObjects.BareosFdPluginLocalFilesetWithRestoreObjects( plugindef ) - return bareos_fd_consts.bRCs["bRC_OK"] + return bareosfd.bRC_OK # the rest is done in the Plugin module diff --git a/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset-with-restoreobjects.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset-with-restoreobjects.py deleted file mode 100644 index b64ef29960f..00000000000 --- a/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset-with-restoreobjects.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# BAREOS - Backup Archiving REcovery Open Sourced -# -# Copyright (C) 2014-2014 Bareos GmbH & Co. KG -# -# This program is Free Software; you can redistribute it and/or -# modify it under the terms of version three of the GNU Affero General Public -# License as published by the Free Software Foundation, which is -# listed in the file LICENSE. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# bareos-fd-local-fileset-with-restoreobjects.py is a python Bareos FD Plugin using -# BareosFdPluginLocalFilesetWithRestoreObjects which was made for automated testing -# purposes. -# -# The plugin argument 'filename' is used to read all files listed in that file and -# add it to the fileset -# -# Author: Maik Aussendorf -# - -# Provided by the Bareos FD Python plugin interface -import bareos_fd_consts - -# This module contains the wrapper functions called by the Bareos-FD, the -# functions call the corresponding methods from your plugin class -import BareosFdWrapper - -# from BareosFdWrapper import parse_plugin_definition, handle_plugin_event, start_backup_file, end_backup_file, start_restore_file, end_restore_file, restore_object_data, plugin_io, create_file, check_file, handle_backup_file # noqa -from BareosFdWrapper import * # noqa - -# This module contains the used plugin class -import BareosFdPluginLocalFilesetWithRestoreObjects - - -def load_bareos_plugin(context, plugindef): - """ - This function is called by the Bareos-FD to load the plugin - We use it to instantiate the plugin class - """ - # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that - # holds the plugin class object - BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLocalFilesetWithRestoreObjects.BareosFdPluginLocalFilesetWithRestoreObjects( - context, plugindef - ) - return bareos_fd_consts.bRCs["bRC_OK"] - - -# the rest is done in the Plugin module From bbf7f417c5f339ef6cc6e331d411cca420a845d3 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 14 Aug 2020 13:41:33 +0200 Subject: [PATCH 225/341] python fd base class: remove unneeded and in py3 unsupported decode(string_escape) --- .../src/plugins/filed/python/pyfiles/BareosFdPluginBaseclass.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/plugins/filed/python/pyfiles/BareosFdPluginBaseclass.py b/core/src/plugins/filed/python/pyfiles/BareosFdPluginBaseclass.py index 4008a924443..651807e955c 100644 --- a/core/src/plugins/filed/python/pyfiles/BareosFdPluginBaseclass.py +++ b/core/src/plugins/filed/python/pyfiles/BareosFdPluginBaseclass.py @@ -136,7 +136,7 @@ def check_options(self, mandatory_options=None): return bRC_OK def plugin_io_open(self, IOP): - self.FNAME = IOP.fname.decode("string_escape") + self.FNAME = IOP.fname bareosfd.DebugMessage( 250, "io_open: self.FNAME is set to %s\n" % (self.FNAME) ) From 415e08df8bf2842512115ab4a7bc6754c077f7f1 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 17 Aug 2020 10:17:22 +0200 Subject: [PATCH 226/341] pretest: kill all daemons via bareos-*.pid --- systemtests/ctest_custom_pretest.sh.in | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/systemtests/ctest_custom_pretest.sh.in b/systemtests/ctest_custom_pretest.sh.in index 2a8b438aa7d..3511b3dbbaf 100755 --- a/systemtests/ctest_custom_pretest.sh.in +++ b/systemtests/ctest_custom_pretest.sh.in @@ -1,5 +1,19 @@ -#!/bin/sh +#!/bin/bash +set -e +set -u echo "PRETEST: running $0 script" echo "PRETEST: @TEST_INFO_TEXT@" echo "PRETEST: executing @BAREOS_DIR_TO_TEST@ -?" -@BAREOS_DIR_TO_TEST@ -? 2>&1 | grep Version >/dev/null +if ! @BAREOS_DIR_TO_TEST@ -? 2>&1 | grep Version >/dev/null; then + echo "PRETEST: ERROR: could not start director. Forgot to build before testing?" + exit 1 +fi +nr_killed=0 +for pidfile in $(find . -name bareos-\*.pid); do + ((nr_killed=nr_killed+1)) + kill -9 "$(cat "$pidfile")" >/dev/null 2>&1 || : + rm -f "$pidfile" +done +if [ $nr_killed -gt 0 ]; then + echo "PRETEST: killed $nr_killed dangling systemtest processes" +fi From 0643a98be268b79969513d1cb816e0e1aa107e1d Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 17 Aug 2020 10:17:49 +0200 Subject: [PATCH 227/341] ctest: add py3plug-fd-ovirt and py3plug-fd-vmware --- systemtests/CMakeLists.txt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 47f30ded52a..a2158597a9e 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -676,6 +676,13 @@ else() list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-ovirt") endif() +if(TARGET python3-fd AND ovirt_server) + list(APPEND SYSTEM_TESTS "py3plug-fd-ovirt") +else() + message(STATUS "disabling py3plug-fd-ovirt as ovirt_server is not set") + list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-ovirt") +endif() + if(TARGET python-fd AND enable_vmware_test) list(APPEND SYSTEM_TESTS "py2plug-fd-vmware") else() @@ -683,11 +690,11 @@ else() list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-vmware") endif() -if(TARGET python3-fd AND ovirt_server) - list(APPEND SYSTEM_TESTS "py3plug-fd-ovirt") +if(TARGET python3-fd AND enable_vmware_test) + list(APPEND SYSTEM_TESTS "py3plug-fd-vmware") else() - message(STATUS "disabling py3plug-fd-ovirt as ovirt_server is not set") - list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-ovirt") + message(STATUS "disabling py3plug-fd-vmware as vmware_server was not set") + list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-vmware") endif() if(TARGET python-fd AND XTRABACKUP) From 6c13f8d6b0a5c9dd114b0b8c73176fc957020215 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 17 Aug 2020 11:38:23 +0200 Subject: [PATCH 228/341] BareosFdPluginLocalFileset: do not encode fname --- .../pyfiles/BareosFdPluginLocalFileset.py | 4 +- .../BareosFdPluginLocalFileset.py | 402 ++++++++++++++++++ ...sFdPluginLocalFilesetWithRestoreObjects.py | 362 ---------------- ...eobjects.py => bareos-fd-local-fileset.py} | 28 +- 4 files changed, 414 insertions(+), 382 deletions(-) create mode 100644 systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py delete mode 100644 systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py rename systemtests/tests/py2plug-fd-local-fileset/python-modules/{bareos_fd_local_fileset_with_restoreobjects.py => bareos-fd-local-fileset.py} (72%) diff --git a/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py b/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py index 02426012a0f..8125e2bc56d 100644 --- a/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py +++ b/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py @@ -204,7 +204,7 @@ def start_backup_file(self, savepkt): mystatp.st_atime = statp.st_atime mystatp.st_mtime = statp.st_mtime mystatp.st_ctime = statp.st_ctime - savepkt.fname = self.file_to_backup.encode("string_escape") + savepkt.fname = self.file_to_backup #.encode("string_escape") # os.islink will detect links to directories only when # there is no trailing slash - we need to perform checks # on the stripped name but use it with trailing / for the backup itself @@ -258,7 +258,7 @@ def create_file(self, restorepkt): ) os.makedirs(dirname) # open creates the file, if not yet existing, we close it again right - # aways it will be opened again in plugin_io. + # away it will be opened again in plugin_io. if restorepkt.type == FT_REG: open(FNAME, "wb").close() restorepkt.create_status = CF_EXTRACT diff --git a/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py new file mode 100644 index 00000000000..2618e17e368 --- /dev/null +++ b/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py @@ -0,0 +1,402 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# BAREOS - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2014-2020 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation, which is +# listed in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# Author: Maik Aussendorf +# +# Bareos python plugins class that adds files from a local list to +# the backup fileset + +import bareosfd +from bareos_fd_consts import bJobMessageType, bFileType, bRCs, bCFs +import os +import re +import BareosFdPluginBaseclass +import stat + + +class BareosFdPluginLocalFileset( + BareosFdPluginBaseclass.BareosFdPluginBaseclass +): # noqa + """ + Simple Bareos-FD-Plugin-Class that parses a file and backups all files + listed there Filename is taken from plugin argument 'filename' + """ + + def __init__(self, context, plugindef, mandatory_options=None): + bareosfd.DebugMessage( + context, + 100, + "Constructor called in module %s with plugindef=%s\n" + % (__name__, plugindef), + ) + if mandatory_options is None: + mandatory_options = ["filename"] + # Last argument of super constructor is a list of mandatory arguments + super(BareosFdPluginLocalFileset, self).__init__( + context, plugindef, mandatory_options + ) + self.files_to_backup = [] + self.file_to_backup = "" + # We need to get the stat-packet in set_file_attributes + # and use it again in end_restore_file, and this may be mixed up + # with different files + self.statp = {} + self.allow = None + self.deny = None + + def filename_is_allowed(self, context, filename, allowregex, denyregex): + """ + Check, if filename is allowed. + True, if matches allowreg and not denyregex. + If allowreg is None, filename always matches + If denyreg is None, it never matches + """ + if allowregex is None or allowregex.search(filename): + allowed = True + else: + allowed = False + if denyregex is None or not denyregex.search(filename): + denied = False + else: + denied = True + if not allowed or denied: + bareosfd.DebugMessage( + context, 100, "File %s denied by configuration\n" % (filename) + ) + bareosfd.JobMessage( + context, + bJobMessageType["M_ERROR"], + "File %s denied by configuration\n" % (filename), + ) + return False + else: + return True + + def append_file_to_backup(self, context, filename): + """ + Basically add filename to list of files to backup in + files_to_backup + Overload this, if you want to check for extra stuff + of do other things with files to backup + """ + self.files_to_backup.append(filename) + + def start_backup_job(self, context): + """ + At this point, plugin options were passed and checked already. + We try to read from filename and setup the list of file to backup + in self.files_to_backup + """ + bareosfd.DebugMessage( + context, + 100, + "Using %s to search for local files\n" % self.options["filename"], + ) + if os.path.exists(self.options["filename"]): + try: + config_file = open(self.options["filename"], "rb") + except: + bareosfd.DebugMessage( + context, + 100, + "Could not open file %s\n" % (self.options["filename"]), + ) + return bRCs["bRC_Error"] + else: + bareosfd.DebugMessage( + context, 100, "File %s does not exist\n" % (self.options["filename"]) + ) + return bRCs["bRC_Error"] + # Check, if we have allow or deny regular expressions defined + if "allow" in self.options: + self.allow = re.compile(self.options["allow"]) + if "deny" in self.options: + self.deny = re.compile(self.options["deny"]) + + for listItem in config_file.read().splitlines(): + if os.path.isfile(listItem) and self.filename_is_allowed( + context, listItem, self.allow, self.deny + ): + self.append_file_to_backup(context, listItem) + if os.path.isdir(listItem): + fullDirName = listItem + # FD requires / at the end of a directory name + if not fullDirName.endswith("/"): + fullDirName += "/" + self.append_file_to_backup(context, fullDirName) + for topdir, dirNames, fileNames in os.walk(listItem): + for fileName in fileNames: + if self.filename_is_allowed( + context, + os.path.join(topdir, fileName), + self.allow, + self.deny, + ): + self.append_file_to_backup( + context, os.path.join(topdir, fileName) + ) + for dirName in dirNames: + fullDirName = os.path.join(topdir, dirName) + "/" + self.append_file_to_backup(context, fullDirName) + bareosfd.DebugMessage(context, 150, "Filelist: %s\n" % (self.files_to_backup)) + + if not self.files_to_backup: + bareosfd.JobMessage( + context, + bJobMessageType["M_ERROR"], + "No (allowed) files to backup found\n", + ) + return bRCs["bRC_Error"] + else: + return bRCs["bRC_OK"] + + def start_backup_file(self, context, savepkt): + """ + Defines the file to backup and creates the savepkt. In this example + only files (no directories) are allowed + """ + bareosfd.DebugMessage(context, 100, "start_backup_file() called\n") + if not self.files_to_backup: + bareosfd.DebugMessage(context, 100, "No files to backup\n") + return bRCs["bRC_Skip"] + + self.file_to_backup = self.files_to_backup.pop().decode("string_escape") + bareosfd.DebugMessage(context, 100, "file: " + self.file_to_backup + "\n") + + mystatp = bareosfd.StatPacket() + try: + if os.path.islink(self.file_to_backup): + statp = os.lstat(self.file_to_backup) + else: + statp = os.stat(self.file_to_backup) + except Exception as e: + bareosfd.JobMessage( + context, + bJobMessageType["M_ERROR"], + 'Could net get stat-info for file %s: "%s"' + % (self.file_to_backup, e.message), + ) + # As of Bareos 19.2.7 attribute names in bareosfd.StatPacket differ from os.stat + # In this case we have to translate names + # For future releases consistent names are planned, allowing to assign the + # complete stat object in one rush + if hasattr(mystatp, "st_uid"): + mystatp = statp + else: + mystatp.mode = statp.st_mode + mystatp.ino = statp.st_ino + mystatp.dev = statp.st_dev + mystatp.nlink = statp.st_nlink + mystatp.uid = statp.st_uid + mystatp.gid = statp.st_gid + mystatp.size = statp.st_size + mystatp.atime = statp.st_atime + mystatp.mtime = statp.st_mtime + mystatp.ctime = statp.st_ctime + savepkt.fname = self.file_to_backup.encode("string_escape") + # os.islink will detect links to directories only when + # there is no trailing slash - we need to perform checks + # on the stripped name but use it with trailing / for the backup itself + if os.path.islink(self.file_to_backup.rstrip("/")): + savepkt.type = bFileType["FT_LNK"] + savepkt.link = os.readlink( + self.file_to_backup.rstrip("/").encode("string_escape") + ) + bareosfd.DebugMessage(context, 150, "file type is: FT_LNK\n") + elif os.path.isfile(self.file_to_backup): + savepkt.type = bFileType["FT_REG"] + bareosfd.DebugMessage(context, 150, "file type is: FT_REG\n") + elif os.path.isdir(self.file_to_backup): + savepkt.type = bFileType["FT_DIREND"] + savepkt.link = self.file_to_backup + bareosfd.DebugMessage( + context, 150, "file %s type is: FT_DIREND\n" % self.file_to_backup + ) + elif stat.S_ISFIFO(os.stat(self.file_to_backup).st_mode): + savepkt.type = bFileType["FT_FIFO"] + bareosfd.DebugMessage(context, 150, "file type is: FT_FIFO\n") + else: + bareosfd.JobMessage( + context, + bJobMessageType["M_WARNING"], + "File %s of unknown type" % (self.file_to_backup), + ) + return bRCs["bRC_Skip"] + + savepkt.statp = mystatp + bareosfd.DebugMessage(context, 150, "file statpx " + str(savepkt.statp) + "\n") + + return bRCs["bRC_OK"] + + def create_file(self, context, restorepkt): + """ + Creates the file to be restored and directory structure, if needed. + Adapt this in your derived class, if you need modifications for + virtual files or similar + """ + bareosfd.DebugMessage( + context, + 100, + "create_file() entry point in Python called with %s\n" % (restorepkt), + ) + FNAME = restorepkt.ofname.decode("string_escape") + if not FNAME: + return bRCs["bRC_Error"] + dirname = os.path.dirname(FNAME.rstrip("/")) + if not os.path.exists(dirname): + bareosfd.DebugMessage( + context, 200, "Directory %s does not exist, creating it now\n" % dirname + ) + os.makedirs(dirname) + # open creates the file, if not yet existing, we close it again right + # aways it will be opened again in plugin_io. + if restorepkt.type == bFileType["FT_REG"]: + open(FNAME, "wb").close() + restorepkt.create_status = bCFs["CF_EXTRACT"] + elif restorepkt.type == bFileType["FT_LNK"]: + linkNameEnc = restorepkt.olname + linkNameClear = linkNameEnc.decode("string_escape") + if not os.path.islink(FNAME.rstrip("/")): + # if not os.path.exists(linkNameClear): + os.symlink(linkNameClear, FNAME.rstrip("/")) + restorepkt.create_status = bCFs["CF_CREATED"] + elif restorepkt.type == bFileType["FT_LNKSAVED"]: + linkNameEnc = restorepkt.olname + linkNameClear = linkNameEnc.decode("string_escape") + if not os.path.exists(linkNameClear): + os.link(linkNameClear, FNAME.rstrip("/")) + restorepkt.create_status = bCFs["CF_CREATED"] + elif restorepkt.type == bFileType["FT_DIREND"]: + if not os.path.exists(FNAME): + os.makedirs(FNAME) + restorepkt.create_status = bCFs["CF_CREATED"] + elif restorepkt.type == bFileType["FT_FIFO"]: + if not os.path.exists(FNAME): + try: + os.mkfifo(FNAME, 0o600) + except Exception as e: + bareosfd.JobMessage( + context, + bJobMessageType["M_ERROR"], + 'Could net create fifo %s: "%s"' % (FNAME, e.message), + ) + restorepkt.create_status = bCFs["CF_CREATED"] + else: + bareosfd.JobMessage( + context, + bJobMessageType["M_ERROR"], + "Unknown type %s of file %s" % (restorepkt.type, FNAME), + ) + return bRCs["bRC_OK"] + + def set_file_attributes(self, context, restorepkt): + """ + Need to verify: we set attributes here but on plugin_io close + the mtime will be modified again. + approach: save stat-packet here and set it on + end_restore_file + """ + # restorepkt.create_status = bCFs["CF_CORE"] + # return bRCs["bRC_OK"] + + # Python attribute setting does not work properly with links + # if restorepkt.type in [bFileType["FT_LNK"],bFileType["FT_LNKSAVED"]]: + # return bRCs["bRC_OK"] + file_name = restorepkt.ofname.decode("string_escape") + file_attr = restorepkt.statp + self.statp[file_name] = file_attr + + bareosfd.DebugMessage( + context, + 150, + "Set file attributes " + file_name + " with stat " + str(file_attr) + "\n", + ) + try: + os.chown(file_name, file_attr.uid, file_attr.gid) + os.chmod(file_name, file_attr.mode) + os.utime(file_name, (file_attr.atime, file_attr.mtime)) + newStat = os.stat(file_name) + bareosfd.DebugMessage( + context, + 150, + "Verified file attributes " + + file_name + + " with stat " + + str(newStat) + + "\n", + ) + + except Exception as e: + bareosfd.JobMessage( + context, + bJobMessageType["M_WARNING"], + 'Could net set attributes for file %s: "%s"' % (file_name, e.message), + ) + + return bRCs["bRC_OK"] + + def end_restore_file(self, context): + bareosfd.DebugMessage( + context, + 100, + "end_restore_file() entry point in Python called FNAME: %s\n" % self.FNAME, + ) + bareosfd.DebugMessage( + context, + 150, + "end_restore_file set file attributes " + + self.FNAME + + " with stat " + + str(self.statp[self.FNAME]) + + "\n", + ) + try: + os.chown(self.FNAME, self.statp[self.FNAME].uid, self.statp[self.FNAME].gid) + os.chmod(self.FNAME, self.statp[self.FNAME].mode) + os.utime( + self.FNAME, (self.statp[self.FNAME].atime, self.statp[self.FNAME].mtime) + ) + # del sometimes leads to no-key errors, it seams that end_restore_file is sometimes called + # multipl times. + # del self.statp[self.FNAME] + except Exception as e: + bareosfd.JobMessage( + context, + bJobMessageType["M_WARNING"], + 'Could net set attributes for file %s: "%s"' % (self.FNAME, e.message), + ) + return bRCs["bRC_OK"] + + def end_backup_file(self, context): + """ + Here we return 'bRC_More' as long as our list files_to_backup is not + empty and bRC_OK when we are done + """ + bareosfd.DebugMessage( + context, 100, "end_backup_file() entry point in Python called\n" + ) + if self.files_to_backup: + return bRCs["bRC_More"] + else: + return bRCs["bRC_OK"] + + +# vim: ts=4 tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py deleted file mode 100644 index 42509286683..00000000000 --- a/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py +++ /dev/null @@ -1,362 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# BAREOS - Backup Archiving REcovery Open Sourced -# -# Copyright (C) 2014-2020 Bareos GmbH & Co. KG -# -# This program is Free Software; you can redistribute it and/or -# modify it under the terms of version three of the GNU Affero General Public -# License as published by the Free Software Foundation, which is -# listed in the file LICENSE. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# Author: Maik Aussendorf -# -# Bareos python plugins class that adds files from a local list to -# the backup fileset - -import bareosfd -from bareos_fd_consts import bJobMessageType, bFileType, bRCs, bVariable -import os -import re -import hashlib -import time -import BareosFdPluginBaseclass - - -class BareosFdPluginLocalFilesetWithRestoreObjects( - BareosFdPluginBaseclass.BareosFdPluginBaseclass -): - """ - This Bareos-FD-Plugin-Class was created for automated test purposes only. - It is based on the BareosFdPluginLocalFileset class that parses a file - and backups all files listed there. - Filename is taken from plugin argument 'filename'. - In addition to the file backup and restore, this plugin also tests - restore objects of different sizes. As restore objects are compressed - automatically, when they are greater then 1000 bytes, both uncompressed - and compressed restore objects are tested. - """ - - def __init__(self, context, plugindef): - bareosfd.DebugMessage( - context, - 100, - "Constructor called in module %s with plugindef=%s\n" - % (__name__, plugindef), - ) - # Last argument of super constructor is a list of mandatory arguments - super(BareosFdPluginLocalFilesetWithRestoreObjects, self).__init__( - context, plugindef, ["filename"] - ) - self.files_to_backup = [] - self.allow = None - self.deny = None - self.object_index_seq = int((time.time() - 1546297200) * 10) - self.sha256sums_by_filename = {} - bareosfd.SetValue(context,bVariable["bVarSinceTime"],999) - triple_nine = bareosfd.GetValue(context,bVariable["bVarSinceTime"]) - if triple_nine != 999: - bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], - "Wrong value for since time (should be 999 but is %d)\n" % triple_nine - ) - - - def filename_is_allowed(self, context, filename, allowregex, denyregex): - """ - Check, if filename is allowed. - True, if matches allowreg and not denyregex. - If allowreg is None, filename always matches - If denyreg is None, it never matches - """ - if allowregex is None or allowregex.search(filename): - allowed = True - else: - allowed = False - if denyregex is None or not denyregex.search(filename): - denied = False - else: - denied = True - if not allowed or denied: - bareosfd.DebugMessage( - context, 100, "File %s denied by configuration\n" % (filename) - ) - bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], - "File %s denied by configuration\n" % (filename), - ) - return False - else: - return True - - def start_backup_job(self, context): - """ - At this point, plugin options were passed and checked already. - We try to read from filename and setup the list of file to backup - in self.files_to_backup - """ - - bareosfd.DebugMessage( - context, - 100, - "Using %s to search for local files\n" % (self.options["filename"]), - ) - if os.path.exists(self.options["filename"]): - try: - config_file = open(self.options["filename"], "rb") - except: - bareosfd.DebugMessage( - context, - 100, - "Could not open file %s\n" % (self.options["filename"]), - ) - return bRCs["bRC_Error"] - else: - bareosfd.DebugMessage( - context, 100, "File %s does not exist\n" % (self.options["filename"]) - ) - return bRCs["bRC_Error"] - # Check, if we have allow or deny regular expressions defined - if "allow" in self.options: - self.allow = re.compile(self.options["allow"]) - if "deny" in self.options: - self.deny = re.compile(self.options["deny"]) - - for listItem in config_file.read().splitlines(): - if os.path.isfile(listItem) and self.filename_is_allowed( - context, listItem, self.allow, self.deny - ): - self.files_to_backup.append(listItem) - if os.path.isdir(listItem): - for topdir, dirNames, fileNames in os.walk(listItem): - for fileName in fileNames: - if self.filename_is_allowed( - context, - os.path.join(topdir, fileName), - self.allow, - self.deny, - ): - self.files_to_backup.append(os.path.join(topdir, fileName)) - if os.path.isfile(os.path.join(topdir, fileName)): - self.files_to_backup.append( - os.path.join(topdir, fileName) + ".sha256sum" - ) - self.files_to_backup.append( - os.path.join(topdir, fileName) + ".abspath" - ) - else: - if os.path.isfile(listItem): - self.files_to_backup.append(listItem + ".sha256sum") - self.files_to_backup.append(listItem + ".abspath") - - for longrestoreobject_length in range(998, 1004): - self.files_to_backup.append( - "%s.longrestoreobject" % longrestoreobject_length - ) - - if not self.files_to_backup: - bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], - "No (allowed) files to backup found\n", - ) - return bRCs["bRC_Error"] - else: - return bRCs["bRC_Cancel"] - - def start_backup_file(self, context, savepkt): - """ - Defines the file to backup and creates the savepkt. In this example - only files (no directories) are allowed - """ - bareosfd.DebugMessage(context, 100, "start_backup_file() called\n") - if not self.files_to_backup: - bareosfd.DebugMessage(context, 100, "No files to backup\n") - return bRCs["bRC_Skip"] - - file_to_backup = self.files_to_backup.pop() - bareosfd.DebugMessage(context, 100, "file: " + file_to_backup + "\n") - - statp = bareosfd.StatPacket() - savepkt.statp = statp - - if file_to_backup.endswith(".sha256sum"): - checksum = self.get_sha256sum(context, os.path.splitext(file_to_backup)[0]) - savepkt.type = bFileType["FT_RESTORE_FIRST"] - savepkt.fname = file_to_backup - savepkt.object_name = file_to_backup - savepkt.object = bytearray(checksum) - savepkt.object_len = len(savepkt.object) - savepkt.object_index = self.object_index_seq - self.object_index_seq += 1 - - elif file_to_backup.endswith(".abspath"): - savepkt.type = bFileType["FT_RESTORE_FIRST"] - savepkt.fname = file_to_backup - savepkt.object_name = file_to_backup - savepkt.object = bytearray(os.path.splitext(file_to_backup)[0]) - savepkt.object_len = len(savepkt.object) - savepkt.object_index = self.object_index_seq - self.object_index_seq += 1 - - elif file_to_backup.endswith(".longrestoreobject"): - teststring_length = int(os.path.splitext(file_to_backup)[0]) - savepkt.type = bFileType["FT_RESTORE_FIRST"] - savepkt.fname = file_to_backup - savepkt.object_name = file_to_backup - savepkt.object = bytearray("a" * teststring_length) - savepkt.object_len = len(savepkt.object) - savepkt.object_index = self.object_index_seq - self.object_index_seq += 1 - - else: - savepkt.fname = file_to_backup - savepkt.type = bFileType["FT_REG"] - - bareosfd.JobMessage( - context, - bJobMessageType["M_INFO"], - "Starting backup of %s\n" % (file_to_backup), - ) - return bRCs["bRC_OK"] - - def end_backup_file(self, context): - """ - Here we return 'bRC_More' as long as our list files_to_backup is not - empty and bRC_OK when we are done - """ - bareosfd.DebugMessage( - context, 100, "end_backup_file() entry point in Python called\n" - ) - if self.files_to_backup: - return bRCs["bRC_More"] - else: - return bRCs["bRC_OK"] - - def set_file_attributes(self, context, restorepkt): - bareosfd.DebugMessage( - context, - 100, - "set_file_attributes() entry point in Python called with %s\n" - % (str(restorepkt)), - ) - - orig_fname = "/" + os.path.relpath(restorepkt.ofname, restorepkt.where) - restoreobject_sha256sum = self.sha256sums_by_filename[orig_fname] - - file_sha256sum = self.get_sha256sum(context, orig_fname) - bareosfd.DebugMessage( - context, - 100, - "set_file_attributes() orig_fname: %s restoreobject_sha256sum: %s file_sha256sum: %s\n" - % (orig_fname, repr(restoreobject_sha256sum), repr(file_sha256sum)), - ) - if file_sha256sum != restoreobject_sha256sum: - bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], - "bad restoreobject orig_fname: %s restoreobject_sha256sum: %s file_sha256sum: %s\n" - % (orig_fname, repr(restoreobject_sha256sum), repr(file_sha256sum)), - ) - - return bRCs["bRC_OK"] - - def end_restore_file(self, context): - bareosfd.DebugMessage( - context, 100, "end_restore_file() self.FNAME: %s\n" % self.FNAME - ) - return bRCs["bRC_OK"] - - def restore_object_data(self, context, ROP): - """ - Note: - This is called in two cases: - - on diff/inc backup (should be called only once) - - on restore (for every job id being restored) - But at the point in time called, it is not possible - to distinguish which of them it is, because job type - is "I" until the bEventStartBackupJob event - """ - bareosfd.DebugMessage( - context, - 100, - "BareosFdPluginLocalFilesetWithRestoreObjects:restore_object_data() called with ROP:%s\n" - % (ROP), - ) - bareosfd.DebugMessage( - context, - 100, - "ROP.object_name(%s): %s\n" % (type(ROP.object_name), ROP.object_name), - ) - bareosfd.DebugMessage( - context, - 100, - "ROP.plugin_name(%s): %s\n" % (type(ROP.plugin_name), ROP.plugin_name), - ) - bareosfd.DebugMessage( - context, - 100, - "ROP.object_len(%s): %s\n" % (type(ROP.object_len), ROP.object_len), - ) - bareosfd.DebugMessage( - context, - 100, - "ROP.object_full_len(%s): %s\n" - % (type(ROP.object_full_len), ROP.object_full_len), - ) - bareosfd.DebugMessage( - context, 100, "ROP.object(%s): %s\n" % (type(ROP.object), repr(ROP.object)) - ) - orig_filename = os.path.splitext(ROP.object_name)[0] - if ROP.object_name.endswith(".sha256sum"): - self.sha256sums_by_filename[orig_filename] = str(ROP.object) - elif ROP.object_name.endswith(".abspath"): - if str(ROP.object) != orig_filename: - bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], - "bad restoreobject orig_fname: %s restoreobject_fname: %s\n" - % (orig_filename, repr(str(ROP.object))), - ) - elif ROP.object_name.endswith(".longrestoreobject"): - stored_length = int(os.path.splitext(ROP.object_name)[0]) - if str(ROP.object) != "a" * stored_length: - bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], - "bad long restoreobject %s does not match stored object\n" - % (ROP.object_name), - ) - else: - bareosfd.DebugMessage( - context, - 100, - "not checking restoreobject: %s\n" % (type(ROP.object_name)), - ) - return bRCs["bRC_OK"] - - def get_sha256sum(self, context, filename): - f = open(filename, "rb") - m = hashlib.sha256() - while True: - d = f.read(8096) - if not d: - break - m.update(d) - f.close() - return m.hexdigest() - - -# vim: ts=4 tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos_fd_local_fileset_with_restoreobjects.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py similarity index 72% rename from systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos_fd_local_fileset_with_restoreobjects.py rename to systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py index 9da5a32dd1e..44d84a92d87 100644 --- a/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos_fd_local_fileset_with_restoreobjects.py +++ b/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # BAREOS - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2014-2020 Bareos GmbH & Co. KG +# Copyright (C) 2014-2014 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -19,20 +19,15 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. # -# bareos_fd_local_fileset_with_restoreobjects.py is a python Bareos FD Plugin using -# BareosFdPluginLocalFilesetWithRestoreObjects which was made for automated testing -# purposes. -# -# The plugin argument 'filename' is used to read all files listed in that file and -# add it to the fileset +# Bareos-fd-local-fileset a simple example for a python Bareos FD Plugin using +# BareosFdPluginLocalFileset. The plugin argument 'filename' is used to read +# all files listed in that file and add it to the fileset # # Author: Maik Aussendorf # # Provided by the Bareos FD Python plugin interface -#import bareos_fd_consts -import bareosfd -from bareosfd import * +import bareos_fd_consts # This module contains the wrapper functions called by the Bareos-FD, the # functions call the corresponding methods from your plugin class @@ -42,23 +37,20 @@ from BareosFdWrapper import * # noqa # This module contains the used plugin class -import BareosFdPluginLocalFilesetWithRestoreObjects - +import BareosFdPluginLocalFileset -def load_bareos_plugin(plugindef): +def load_bareos_plugin(context, plugindef): """ This function is called by the Bareos-FD to load the plugin We use it to instantiate the plugin class """ # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that # holds the plugin class object - BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLocalFilesetWithRestoreObjects.BareosFdPluginLocalFilesetWithRestoreObjects( - plugindef + BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLocalFileset.BareosFdPluginLocalFileset( + context, plugindef ) - return bRC_OK - # return bareosfd.bRC_OK - # return bareosfd.bRCs["bRC_OK"] + return bareos_fd_consts.bRCs["bRC_OK"] # the rest is done in the Plugin module From db4f52576bd65f8a8f12750d2e741a64711b4a95 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 17 Aug 2020 12:41:30 +0200 Subject: [PATCH 229/341] LocalFileset work but diff fails on python3 --- .../pyfiles/BareosFdPluginLocalFileset.py | 28 +++++++++---------- .../bareos-dir.d/fileset/PluginTest.conf.in | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py b/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py index 8125e2bc56d..092aa1574ba 100644 --- a/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py +++ b/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py @@ -109,7 +109,7 @@ def start_backup_job(self): ) if os.path.exists(self.options["filename"]): try: - config_file = open(self.options["filename"], "rb") + config_file = open(self.options["filename"], "r") except: bareosfd.DebugMessage( 100, @@ -135,7 +135,7 @@ def start_backup_job(self): if os.path.isdir(listItem): fullDirName = listItem # FD requires / at the end of a directory name - if not fullDirName.endswith("/"): + if not fullDirName.endswith(tuple("/")): fullDirName += "/" self.append_file_to_backup(fullDirName) for topdir, dirNames, fileNames in os.walk(listItem): @@ -172,7 +172,7 @@ def start_backup_file(self, savepkt): bareosfd.DebugMessage( 100, "No files to backup\n") return bRC_Skip - self.file_to_backup = self.files_to_backup.pop().decode("string_escape") + self.file_to_backup = self.files_to_backup.pop() bareosfd.DebugMessage(100, "file: " + self.file_to_backup + "\n") mystatp = bareosfd.StatPacket() @@ -185,7 +185,7 @@ def start_backup_file(self, savepkt): bareosfd.JobMessage( M_ERROR, 'Could net get stat-info for file %s: "%s"' - % (self.file_to_backup, e.message), + % (self.file_to_backup, e), ) # As of Bareos 19.2.7 attribute names in bareosfd.StatPacket differ from os.stat # In this case we have to translate names @@ -211,7 +211,7 @@ def start_backup_file(self, savepkt): if os.path.islink(self.file_to_backup.rstrip("/")): savepkt.type = FT_LNK savepkt.link = os.readlink( - self.file_to_backup.rstrip("/").encode("string_escape") + self.file_to_backup.rstrip("/")#.encode("string_escape") ) bareosfd.DebugMessage(150, "file type is: FT_LNK\n") elif os.path.isfile(self.file_to_backup): @@ -248,7 +248,7 @@ def create_file(self, restorepkt): 100, "create_file() entry point in Python called with %s\n" % (restorepkt), ) - FNAME = restorepkt.ofname.decode("string_escape") + FNAME = restorepkt.ofname if not FNAME: return bRC_Error dirname = os.path.dirname(FNAME.rstrip("/")) @@ -264,14 +264,14 @@ def create_file(self, restorepkt): restorepkt.create_status = CF_EXTRACT elif restorepkt.type == FT_LNK: linkNameEnc = restorepkt.olname - linkNameClear = linkNameEnc.decode("string_escape") + linkNameClear = linkNameEnc#.decode("string_escape") if not os.path.islink(FNAME.rstrip("/")): # if not os.path.exists(linkNameClear): os.symlink(linkNameClear, FNAME.rstrip("/")) restorepkt.create_status = CF_CREATED elif restorepkt.type == FT_LNKSAVED: linkNameEnc = restorepkt.olname - linkNameClear = linkNameEnc.decode("string_escape") + linkNameClear = linkNameEnc#.decode("string_escape") if not os.path.exists(linkNameClear): os.link(linkNameClear, FNAME.rstrip("/")) restorepkt.create_status = CF_CREATED @@ -286,7 +286,7 @@ def create_file(self, restorepkt): except Exception as e: bareosfd.JobMessage( M_ERROR, - 'Could net create fifo %s: "%s"' % (FNAME, e.message), + 'Could net create fifo %s: "%s"' % (FNAME, e), ) restorepkt.create_status = CF_CREATED else: @@ -309,7 +309,7 @@ def set_file_attributes(self, restorepkt): # Python attribute setting does not work properly with links # if restorepkt.type in [bFileType["FT_LNK"],bFileType["FT_LNKSAVED"]]: # return bRCs["bRC_OK"] - file_name = restorepkt.ofname.decode("string_escape") + file_name = restorepkt.ofname#.decode("string_escape") file_attr = restorepkt.statp self.statp[file_name] = file_attr @@ -334,7 +334,7 @@ def set_file_attributes(self, restorepkt): except Exception as e: bareosfd.JobMessage( M_WARNING, - 'Could net set attributes for file %s: "%s"' % (file_name, e.message), + 'Could net set attributes for file %s: "%s"' % (file_name, e), ) return bRC_OK @@ -362,10 +362,10 @@ def end_restore_file(self): # del self.statp[self.FNAME] except Exception as e: bareosfd.JobMessage( - bJobMessageType["M_WARNING"], - 'Could net set attributes for file %s: "%s"' % (self.FNAME, e.message), + M_WARNING, + 'Could net set attributes for file %s: "%s"' % (self.FNAME, e), ) - return bRCs["bRC_OK"] + return bRC_OK def end_backup_file(self): """ diff --git a/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in index 18d7965be2c..dabb88ceb79 100644 --- a/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in +++ b/systemtests/tests/py2plug-fd-local-fileset/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in @@ -2,6 +2,6 @@ FileSet { Name = "PluginTest" Description = "Test the Plugin functionality with a Python Plugin." Include { - Plugin = "python:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-local-fileset:filename=@tmpdir@/file-list" + Plugin = "@python_module_name@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-local-fileset:filename=@tmpdir@/file-list" } } From c0c54210eb798d3cc7f1a97abc4c3d3b0ed3e9f9 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 17 Aug 2020 13:56:40 +0200 Subject: [PATCH 230/341] python-modules: symlinking --- core/src/plugins/filed/python/CMakeLists.txt | 2 - .../pyfiles/BareosFdPluginLocalFileset.py | 384 ------------------ .../python/pyfiles/bareos-fd-local-fileset.py | 56 --- systemtests/CMakeLists.txt | 20 +- .../BareosFdPluginLocalFileset.py | 200 +++++---- .../python-modules/bareos-fd-local-fileset.py | 10 +- .../tests/py2plug-fd-local-fileset/testrunner | 4 +- 7 files changed, 114 insertions(+), 562 deletions(-) delete mode 100644 core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py delete mode 100644 core/src/plugins/filed/python/pyfiles/bareos-fd-local-fileset.py diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 73e1d319b33..c1f80ac25ed 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -162,10 +162,8 @@ endif() set(PYFILES pyfiles/bareos-fd.py.template - pyfiles/bareos-fd-local-fileset.py pyfiles/bareos-fd-mock-test.py pyfiles/BareosFdPluginBaseclass.py - pyfiles/BareosFdPluginLocalFileset.py pyfiles/BareosFdWrapper.py ldap/bareos-fd-ldap.py ldap/BareosFdPluginLDAP.py diff --git a/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py b/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py deleted file mode 100644 index 092aa1574ba..00000000000 --- a/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py +++ /dev/null @@ -1,384 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# BAREOS - Backup Archiving REcovery Open Sourced -# -# Copyright (C) 2014-2020 Bareos GmbH & Co. KG -# -# This program is Free Software; you can redistribute it and/or -# modify it under the terms of version three of the GNU Affero General Public -# License as published by the Free Software Foundation, which is -# listed in the file LICENSE. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# Author: Maik Aussendorf -# -# Bareos python plugins class that adds files from a local list to -# the backup fileset - -import bareosfd -from bareosfd import * -import os -import re -import BareosFdPluginBaseclass -import stat - - -class BareosFdPluginLocalFileset( - BareosFdPluginBaseclass.BareosFdPluginBaseclass -): # noqa - """ - Simple Bareos-FD-Plugin-Class that parses a file and backups all files - listed there Filename is taken from plugin argument 'filename' - """ - - def __init__(self,plugindef, mandatory_options=None): - bareosfd.DebugMessage( - 100, - "Constructor called in module %s with plugindef=%s\n" - % (__name__, plugindef), - ) - if mandatory_options is None: - mandatory_options = ["filename"] - # Last argument of super constructor is a list of mandatory arguments - super(BareosFdPluginLocalFileset, self).__init__( - plugindef, mandatory_options - ) - self.files_to_backup = [] - self.file_to_backup = "" - # We need to get the stat-packet in set_file_attributes - # and use it again in end_restore_file, and this may be mixed up - # with different files - self.statp = {} - self.allow = None - self.deny = None - - def filename_is_allowed(self, filename, allowregex, denyregex): - """ - Check, if filename is allowed. - True, if matches allowreg and not denyregex. - If allowreg is None, filename always matches - If denyreg is None, it never matches - """ - if allowregex is None or allowregex.search(filename): - allowed = True - else: - allowed = False - if denyregex is None or not denyregex.search(filename): - denied = False - else: - denied = True - if not allowed or denied: - bareosfd.DebugMessage( - 100, "File %s denied by configuration\n" % (filename) - ) - bareosfd.JobMessage( - M_ERROR, - "File %s denied by configuration\n" % (filename), - ) - return False - else: - return True - - def append_file_to_backup(self, filename): - """ - Basically add filename to list of files to backup in - files_to_backup - Overload this, if you want to check for extra stuff - of do other things with files to backup - """ - self.files_to_backup.append(filename) - - def start_backup_job(self): - """ - At this point, plugin options were passed and checked already. - We try to read from filename and setup the list of file to backup - in self.files_to_backup - """ - bareosfd.DebugMessage( - 100, - "Using %s to search for local files\n" % self.options["filename"], - ) - if os.path.exists(self.options["filename"]): - try: - config_file = open(self.options["filename"], "r") - except: - bareosfd.DebugMessage( - 100, - "Could not open file %s\n" % (self.options["filename"]), - ) - return bRC_Error - else: - bareosfd.DebugMessage( - 100, "File %s does not exist\n" % (self.options["filename"]) - ) - return bRC_Error - # Check, if we have allow or deny regular expressions defined - if "allow" in self.options: - self.allow = re.compile(self.options["allow"]) - if "deny" in self.options: - self.deny = re.compile(self.options["deny"]) - - for listItem in config_file.read().splitlines(): - if os.path.isfile(listItem) and self.filename_is_allowed( - listItem, self.allow, self.deny - ): - self.append_file_to_backup(listItem) - if os.path.isdir(listItem): - fullDirName = listItem - # FD requires / at the end of a directory name - if not fullDirName.endswith(tuple("/")): - fullDirName += "/" - self.append_file_to_backup(fullDirName) - for topdir, dirNames, fileNames in os.walk(listItem): - for fileName in fileNames: - if self.filename_is_allowed( - os.path.join(topdir, fileName), - self.allow, - self.deny, - ): - self.append_file_to_backup( - os.path.join(topdir, fileName) - ) - for dirName in dirNames: - fullDirName = os.path.join(topdir, dirName) + "/" - self.append_file_to_backup(fullDirName) - bareosfd.DebugMessage(150, "Filelist: %s\n" % (self.files_to_backup)) - - if not self.files_to_backup: - bareosfd.JobMessage( - M_ERROR, - "No (allowed) files to backup found\n", - ) - return bRC_Error - else: - return bRC_OK - - def start_backup_file(self, savepkt): - """ - Defines the file to backup and creates the savepkt. In this example - only files (no directories) are allowed - """ - bareosfd.DebugMessage( 100, "start_backup_file() called\n") - if not self.files_to_backup: - bareosfd.DebugMessage( 100, "No files to backup\n") - return bRC_Skip - - self.file_to_backup = self.files_to_backup.pop() - bareosfd.DebugMessage(100, "file: " + self.file_to_backup + "\n") - - mystatp = bareosfd.StatPacket() - try: - if os.path.islink(self.file_to_backup): - statp = os.lstat(self.file_to_backup) - else: - statp = os.stat(self.file_to_backup) - except Exception as e: - bareosfd.JobMessage( - M_ERROR, - 'Could net get stat-info for file %s: "%s"' - % (self.file_to_backup, e), - ) - # As of Bareos 19.2.7 attribute names in bareosfd.StatPacket differ from os.stat - # In this case we have to translate names - # For future releases consistent names are planned, allowing to assign the - # complete stat object in one rush - # if hasattr(mystatp, "st_uid"): - # mystatp = statp - # else: - mystatp.st_mode = statp.st_mode - mystatp.st_ino = statp.st_ino - mystatp.st_dev = statp.st_dev - mystatp.st_nlink = statp.st_nlink - mystatp.st_uid = statp.st_uid - mystatp.st_gid = statp.st_gid - mystatp.st_size = statp.st_size - mystatp.st_atime = statp.st_atime - mystatp.st_mtime = statp.st_mtime - mystatp.st_ctime = statp.st_ctime - savepkt.fname = self.file_to_backup #.encode("string_escape") - # os.islink will detect links to directories only when - # there is no trailing slash - we need to perform checks - # on the stripped name but use it with trailing / for the backup itself - if os.path.islink(self.file_to_backup.rstrip("/")): - savepkt.type = FT_LNK - savepkt.link = os.readlink( - self.file_to_backup.rstrip("/")#.encode("string_escape") - ) - bareosfd.DebugMessage(150, "file type is: FT_LNK\n") - elif os.path.isfile(self.file_to_backup): - savepkt.type = FT_REG - bareosfd.DebugMessage(150, "file type is: FT_REG\n") - elif os.path.isdir(self.file_to_backup): - savepkt.type = FT_DIREND - savepkt.link = self.file_to_backup - bareosfd.DebugMessage( - 150, "file %s type is: FT_DIREND\n" % self.file_to_backup - ) - elif stat.S_ISFIFO(os.stat(self.file_to_backup).st_mode): - savepkt.type = FT_FIFO - bareosfd.DebugMessage(150, "file type is: FT_FIFO\n") - else: - bareosfd.JobMessage( - M_WARNING, - "File %s of unknown type" % (self.file_to_backup), - ) - return bRC_Skip - - savepkt.statp = mystatp - bareosfd.DebugMessage(150, "file statpx " + str(savepkt.statp) + "\n") - - return bRC_OK - - def create_file(self, restorepkt): - """ - Creates the file to be restored and directory structure, if needed. - Adapt this in your derived class, if you need modifications for - virtual files or similar - """ - bareosfd.DebugMessage( - 100, - "create_file() entry point in Python called with %s\n" % (restorepkt), - ) - FNAME = restorepkt.ofname - if not FNAME: - return bRC_Error - dirname = os.path.dirname(FNAME.rstrip("/")) - if not os.path.exists(dirname): - bareosfd.DebugMessage( - 200, "Directory %s does not exist, creating it now\n" % dirname - ) - os.makedirs(dirname) - # open creates the file, if not yet existing, we close it again right - # away it will be opened again in plugin_io. - if restorepkt.type == FT_REG: - open(FNAME, "wb").close() - restorepkt.create_status = CF_EXTRACT - elif restorepkt.type == FT_LNK: - linkNameEnc = restorepkt.olname - linkNameClear = linkNameEnc#.decode("string_escape") - if not os.path.islink(FNAME.rstrip("/")): - # if not os.path.exists(linkNameClear): - os.symlink(linkNameClear, FNAME.rstrip("/")) - restorepkt.create_status = CF_CREATED - elif restorepkt.type == FT_LNKSAVED: - linkNameEnc = restorepkt.olname - linkNameClear = linkNameEnc#.decode("string_escape") - if not os.path.exists(linkNameClear): - os.link(linkNameClear, FNAME.rstrip("/")) - restorepkt.create_status = CF_CREATED - elif restorepkt.type == FT_DIREND: - if not os.path.exists(FNAME): - os.makedirs(FNAME) - restorepkt.create_status = CF_CREATED - elif restorepkt.type == FT_FIFO: - if not os.path.exists(FNAME): - try: - os.mkfifo(FNAME, 0o600) - except Exception as e: - bareosfd.JobMessage( - M_ERROR, - 'Could net create fifo %s: "%s"' % (FNAME, e), - ) - restorepkt.create_status = CF_CREATED - else: - bareosfd.JobMessage( - M_ERROR, - "Unknown type %s of file %s" % (restorepkt.type, FNAME), - ) - return bRC_OK - - def set_file_attributes(self, restorepkt): - """ - Need to verify: we set attributes here but on plugin_io close - the mtime will be modified again. - approach: save stat-packet here and set it on - end_restore_file - """ - # restorepkt.create_status = bCFs["CF_CORE"] - # return bRCs["bRC_OK"] - - # Python attribute setting does not work properly with links - # if restorepkt.type in [bFileType["FT_LNK"],bFileType["FT_LNKSAVED"]]: - # return bRCs["bRC_OK"] - file_name = restorepkt.ofname#.decode("string_escape") - file_attr = restorepkt.statp - self.statp[file_name] = file_attr - - bareosfd.DebugMessage( - 150, - "Set file attributes " + file_name + " with stat " + str(file_attr) + "\n", - ) - try: - os.chown(file_name, file_attr.uid, file_attr.gid) - os.chmod(file_name, file_attr.mode) - os.utime(file_name, (file_attr.atime, file_attr.mtime)) - newStat = os.stat(file_name) - bareosfd.DebugMessage( - 150, - "Verified file attributes " - + file_name - + " with stat " - + str(newStat) - + "\n", - ) - - except Exception as e: - bareosfd.JobMessage( - M_WARNING, - 'Could net set attributes for file %s: "%s"' % (file_name, e), - ) - return bRC_OK - - def end_restore_file(self): - bareosfd.DebugMessage( - 100, - "end_restore_file() entry point in Python called FNAME: %s\n" % self.FNAME, - ) - bareosfd.DebugMessage( - 150, - "end_restore_file set file attributes " - + self.FNAME - + " with stat " - + str(self.statp[self.FNAME]) - + "\n", - ) - try: - os.chown(self.FNAME, self.statp[self.FNAME].uid, self.statp[self.FNAME].gid) - os.chmod(self.FNAME, self.statp[self.FNAME].mode) - os.utime( - self.FNAME, (self.statp[self.FNAME].atime, self.statp[self.FNAME].mtime) - ) - # del sometimes leads to no-key errors, it seams that end_restore_file is sometimes called - # multipl times. - # del self.statp[self.FNAME] - except Exception as e: - bareosfd.JobMessage( - M_WARNING, - 'Could net set attributes for file %s: "%s"' % (self.FNAME, e), - ) - return bRC_OK - - def end_backup_file(self): - """ - Here we return 'bRC_More' as long as our list files_to_backup is not - empty and bRC_OK when we are done - """ - bareosfd.DebugMessage( - 100, "end_backup_file() entry point in Python called\n" - ) - if self.files_to_backup: - return bRC_More - else: - return bRC_OK - - -# vim: ts=4 tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/core/src/plugins/filed/python/pyfiles/bareos-fd-local-fileset.py b/core/src/plugins/filed/python/pyfiles/bareos-fd-local-fileset.py deleted file mode 100644 index da08418b637..00000000000 --- a/core/src/plugins/filed/python/pyfiles/bareos-fd-local-fileset.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# BAREOS - Backup Archiving REcovery Open Sourced -# -# Copyright (C) 2014-2020 Bareos GmbH & Co. KG -# -# This program is Free Software; you can redistribute it and/or -# modify it under the terms of version three of the GNU Affero General Public -# License as published by the Free Software Foundation, which is -# listed in the file LICENSE. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# Bareos-fd-local-fileset a simple example for a python Bareos FD Plugin using -# BareosFdPluginLocalFileset. The plugin argument 'filename' is used to read -# all files listed in that file and add it to the fileset -# -# Author: Maik Aussendorf -# - -# Provided by the Bareos FD Python plugin interface -import bareosfd - -# This module contains the wrapper functions called by the Bareos-FD, the -# functions call the corresponding methods from your plugin class -import BareosFdWrapper - -# from BareosFdWrapper import parse_plugin_definition, handle_plugin_event, start_backup_file, end_backup_file, start_restore_file, end_restore_file, restore_object_data, plugin_io, create_file, check_file, handle_backup_file # noqa -from BareosFdWrapper import * # noqa - -# This module contains the used plugin class -import BareosFdPluginLocalFileset - - -def load_bareos_plugin(plugindef): - """ - This function is called by the Bareos-FD to load the plugin - We use it to instantiate the plugin class - """ - # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that - # holds the plugin class object - BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLocalFileset.BareosFdPluginLocalFileset( - plugindef - ) - return bareosfd.bRC_OK - - -# the rest is done in the Plugin module diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index a2158597a9e..ade67520a0b 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -82,11 +82,21 @@ function(ConfigureFilesToSystemtest srcbasedir dirname globexpression string(REGEX REPLACE ".in$" "" TARGET_FILE ${TARGET_FILE}) # do not mess # with .ini files string(REPLACE "${srcbasedir}/${srcdirname}" "" TARGET_FILE ${TARGET_FILE}) - # MESSAGE(STATUS "configuring ${TARGET_FILE}" ) - configure_file( - ${CURRENT_FILE} ${PROJECT_BINARY_DIR}/${dirname}/${TARGET_FILE} - ${configure_option} - ) + get_filename_component(DIR_NAME ${TARGET_FILE} DIRECTORY) + if(DIR_NAME MATCHES "python-modules$") + message( + STATUS + "symlinking ${CURRENT_FILE} ${PROJECT_BINARY_DIR}/${dirname}/${TARGET_FILE}" + ) + create_symlink( + ${CURRENT_FILE} ${PROJECT_BINARY_DIR}/${dirname}/${TARGET_FILE} + ) + else() + configure_file( + ${CURRENT_FILE} ${PROJECT_BINARY_DIR}/${dirname}/${TARGET_FILE} + ${configure_option} + ) + endif() endforeach() endfunction() diff --git a/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py index 2618e17e368..092aa1574ba 100644 --- a/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py +++ b/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py @@ -25,7 +25,7 @@ # the backup fileset import bareosfd -from bareos_fd_consts import bJobMessageType, bFileType, bRCs, bCFs +from bareosfd import * import os import re import BareosFdPluginBaseclass @@ -40,9 +40,8 @@ class BareosFdPluginLocalFileset( listed there Filename is taken from plugin argument 'filename' """ - def __init__(self, context, plugindef, mandatory_options=None): + def __init__(self,plugindef, mandatory_options=None): bareosfd.DebugMessage( - context, 100, "Constructor called in module %s with plugindef=%s\n" % (__name__, plugindef), @@ -51,7 +50,7 @@ def __init__(self, context, plugindef, mandatory_options=None): mandatory_options = ["filename"] # Last argument of super constructor is a list of mandatory arguments super(BareosFdPluginLocalFileset, self).__init__( - context, plugindef, mandatory_options + plugindef, mandatory_options ) self.files_to_backup = [] self.file_to_backup = "" @@ -62,7 +61,7 @@ def __init__(self, context, plugindef, mandatory_options=None): self.allow = None self.deny = None - def filename_is_allowed(self, context, filename, allowregex, denyregex): + def filename_is_allowed(self, filename, allowregex, denyregex): """ Check, if filename is allowed. True, if matches allowreg and not denyregex. @@ -79,18 +78,17 @@ def filename_is_allowed(self, context, filename, allowregex, denyregex): denied = True if not allowed or denied: bareosfd.DebugMessage( - context, 100, "File %s denied by configuration\n" % (filename) + 100, "File %s denied by configuration\n" % (filename) ) bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], + M_ERROR, "File %s denied by configuration\n" % (filename), ) return False else: return True - def append_file_to_backup(self, context, filename): + def append_file_to_backup(self, filename): """ Basically add filename to list of files to backup in files_to_backup @@ -99,32 +97,30 @@ def append_file_to_backup(self, context, filename): """ self.files_to_backup.append(filename) - def start_backup_job(self, context): + def start_backup_job(self): """ At this point, plugin options were passed and checked already. We try to read from filename and setup the list of file to backup in self.files_to_backup """ bareosfd.DebugMessage( - context, 100, "Using %s to search for local files\n" % self.options["filename"], ) if os.path.exists(self.options["filename"]): try: - config_file = open(self.options["filename"], "rb") + config_file = open(self.options["filename"], "r") except: bareosfd.DebugMessage( - context, 100, "Could not open file %s\n" % (self.options["filename"]), ) - return bRCs["bRC_Error"] + return bRC_Error else: bareosfd.DebugMessage( - context, 100, "File %s does not exist\n" % (self.options["filename"]) + 100, "File %s does not exist\n" % (self.options["filename"]) ) - return bRCs["bRC_Error"] + return bRC_Error # Check, if we have allow or deny regular expressions defined if "allow" in self.options: self.allow = re.compile(self.options["allow"]) @@ -133,53 +129,51 @@ def start_backup_job(self, context): for listItem in config_file.read().splitlines(): if os.path.isfile(listItem) and self.filename_is_allowed( - context, listItem, self.allow, self.deny + listItem, self.allow, self.deny ): - self.append_file_to_backup(context, listItem) + self.append_file_to_backup(listItem) if os.path.isdir(listItem): fullDirName = listItem # FD requires / at the end of a directory name - if not fullDirName.endswith("/"): + if not fullDirName.endswith(tuple("/")): fullDirName += "/" - self.append_file_to_backup(context, fullDirName) + self.append_file_to_backup(fullDirName) for topdir, dirNames, fileNames in os.walk(listItem): for fileName in fileNames: if self.filename_is_allowed( - context, os.path.join(topdir, fileName), self.allow, self.deny, ): self.append_file_to_backup( - context, os.path.join(topdir, fileName) + os.path.join(topdir, fileName) ) for dirName in dirNames: fullDirName = os.path.join(topdir, dirName) + "/" - self.append_file_to_backup(context, fullDirName) - bareosfd.DebugMessage(context, 150, "Filelist: %s\n" % (self.files_to_backup)) + self.append_file_to_backup(fullDirName) + bareosfd.DebugMessage(150, "Filelist: %s\n" % (self.files_to_backup)) if not self.files_to_backup: bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], + M_ERROR, "No (allowed) files to backup found\n", ) - return bRCs["bRC_Error"] + return bRC_Error else: - return bRCs["bRC_OK"] + return bRC_OK - def start_backup_file(self, context, savepkt): + def start_backup_file(self, savepkt): """ Defines the file to backup and creates the savepkt. In this example only files (no directories) are allowed """ - bareosfd.DebugMessage(context, 100, "start_backup_file() called\n") + bareosfd.DebugMessage( 100, "start_backup_file() called\n") if not self.files_to_backup: - bareosfd.DebugMessage(context, 100, "No files to backup\n") - return bRCs["bRC_Skip"] + bareosfd.DebugMessage( 100, "No files to backup\n") + return bRC_Skip - self.file_to_backup = self.files_to_backup.pop().decode("string_escape") - bareosfd.DebugMessage(context, 100, "file: " + self.file_to_backup + "\n") + self.file_to_backup = self.files_to_backup.pop() + bareosfd.DebugMessage(100, "file: " + self.file_to_backup + "\n") mystatp = bareosfd.StatPacket() try: @@ -189,125 +183,120 @@ def start_backup_file(self, context, savepkt): statp = os.stat(self.file_to_backup) except Exception as e: bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], + M_ERROR, 'Could net get stat-info for file %s: "%s"' - % (self.file_to_backup, e.message), + % (self.file_to_backup, e), ) # As of Bareos 19.2.7 attribute names in bareosfd.StatPacket differ from os.stat # In this case we have to translate names # For future releases consistent names are planned, allowing to assign the # complete stat object in one rush - if hasattr(mystatp, "st_uid"): - mystatp = statp - else: - mystatp.mode = statp.st_mode - mystatp.ino = statp.st_ino - mystatp.dev = statp.st_dev - mystatp.nlink = statp.st_nlink - mystatp.uid = statp.st_uid - mystatp.gid = statp.st_gid - mystatp.size = statp.st_size - mystatp.atime = statp.st_atime - mystatp.mtime = statp.st_mtime - mystatp.ctime = statp.st_ctime - savepkt.fname = self.file_to_backup.encode("string_escape") + # if hasattr(mystatp, "st_uid"): + # mystatp = statp + # else: + mystatp.st_mode = statp.st_mode + mystatp.st_ino = statp.st_ino + mystatp.st_dev = statp.st_dev + mystatp.st_nlink = statp.st_nlink + mystatp.st_uid = statp.st_uid + mystatp.st_gid = statp.st_gid + mystatp.st_size = statp.st_size + mystatp.st_atime = statp.st_atime + mystatp.st_mtime = statp.st_mtime + mystatp.st_ctime = statp.st_ctime + savepkt.fname = self.file_to_backup #.encode("string_escape") # os.islink will detect links to directories only when # there is no trailing slash - we need to perform checks # on the stripped name but use it with trailing / for the backup itself if os.path.islink(self.file_to_backup.rstrip("/")): - savepkt.type = bFileType["FT_LNK"] + savepkt.type = FT_LNK savepkt.link = os.readlink( - self.file_to_backup.rstrip("/").encode("string_escape") + self.file_to_backup.rstrip("/")#.encode("string_escape") ) - bareosfd.DebugMessage(context, 150, "file type is: FT_LNK\n") + bareosfd.DebugMessage(150, "file type is: FT_LNK\n") elif os.path.isfile(self.file_to_backup): - savepkt.type = bFileType["FT_REG"] - bareosfd.DebugMessage(context, 150, "file type is: FT_REG\n") + savepkt.type = FT_REG + bareosfd.DebugMessage(150, "file type is: FT_REG\n") elif os.path.isdir(self.file_to_backup): - savepkt.type = bFileType["FT_DIREND"] + savepkt.type = FT_DIREND savepkt.link = self.file_to_backup bareosfd.DebugMessage( - context, 150, "file %s type is: FT_DIREND\n" % self.file_to_backup + 150, "file %s type is: FT_DIREND\n" % self.file_to_backup ) elif stat.S_ISFIFO(os.stat(self.file_to_backup).st_mode): - savepkt.type = bFileType["FT_FIFO"] - bareosfd.DebugMessage(context, 150, "file type is: FT_FIFO\n") + savepkt.type = FT_FIFO + bareosfd.DebugMessage(150, "file type is: FT_FIFO\n") else: bareosfd.JobMessage( - context, - bJobMessageType["M_WARNING"], + M_WARNING, "File %s of unknown type" % (self.file_to_backup), ) - return bRCs["bRC_Skip"] + return bRC_Skip savepkt.statp = mystatp - bareosfd.DebugMessage(context, 150, "file statpx " + str(savepkt.statp) + "\n") + bareosfd.DebugMessage(150, "file statpx " + str(savepkt.statp) + "\n") - return bRCs["bRC_OK"] + return bRC_OK - def create_file(self, context, restorepkt): + def create_file(self, restorepkt): """ Creates the file to be restored and directory structure, if needed. Adapt this in your derived class, if you need modifications for virtual files or similar """ bareosfd.DebugMessage( - context, 100, "create_file() entry point in Python called with %s\n" % (restorepkt), ) - FNAME = restorepkt.ofname.decode("string_escape") + FNAME = restorepkt.ofname if not FNAME: - return bRCs["bRC_Error"] + return bRC_Error dirname = os.path.dirname(FNAME.rstrip("/")) if not os.path.exists(dirname): bareosfd.DebugMessage( - context, 200, "Directory %s does not exist, creating it now\n" % dirname + 200, "Directory %s does not exist, creating it now\n" % dirname ) os.makedirs(dirname) # open creates the file, if not yet existing, we close it again right - # aways it will be opened again in plugin_io. - if restorepkt.type == bFileType["FT_REG"]: + # away it will be opened again in plugin_io. + if restorepkt.type == FT_REG: open(FNAME, "wb").close() - restorepkt.create_status = bCFs["CF_EXTRACT"] - elif restorepkt.type == bFileType["FT_LNK"]: + restorepkt.create_status = CF_EXTRACT + elif restorepkt.type == FT_LNK: linkNameEnc = restorepkt.olname - linkNameClear = linkNameEnc.decode("string_escape") + linkNameClear = linkNameEnc#.decode("string_escape") if not os.path.islink(FNAME.rstrip("/")): # if not os.path.exists(linkNameClear): os.symlink(linkNameClear, FNAME.rstrip("/")) - restorepkt.create_status = bCFs["CF_CREATED"] - elif restorepkt.type == bFileType["FT_LNKSAVED"]: + restorepkt.create_status = CF_CREATED + elif restorepkt.type == FT_LNKSAVED: linkNameEnc = restorepkt.olname - linkNameClear = linkNameEnc.decode("string_escape") + linkNameClear = linkNameEnc#.decode("string_escape") if not os.path.exists(linkNameClear): os.link(linkNameClear, FNAME.rstrip("/")) - restorepkt.create_status = bCFs["CF_CREATED"] - elif restorepkt.type == bFileType["FT_DIREND"]: + restorepkt.create_status = CF_CREATED + elif restorepkt.type == FT_DIREND: if not os.path.exists(FNAME): os.makedirs(FNAME) - restorepkt.create_status = bCFs["CF_CREATED"] - elif restorepkt.type == bFileType["FT_FIFO"]: + restorepkt.create_status = CF_CREATED + elif restorepkt.type == FT_FIFO: if not os.path.exists(FNAME): try: os.mkfifo(FNAME, 0o600) except Exception as e: bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], - 'Could net create fifo %s: "%s"' % (FNAME, e.message), + M_ERROR, + 'Could net create fifo %s: "%s"' % (FNAME, e), ) - restorepkt.create_status = bCFs["CF_CREATED"] + restorepkt.create_status = CF_CREATED else: bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], + M_ERROR, "Unknown type %s of file %s" % (restorepkt.type, FNAME), ) - return bRCs["bRC_OK"] + return bRC_OK - def set_file_attributes(self, context, restorepkt): + def set_file_attributes(self, restorepkt): """ Need to verify: we set attributes here but on plugin_io close the mtime will be modified again. @@ -320,12 +309,11 @@ def set_file_attributes(self, context, restorepkt): # Python attribute setting does not work properly with links # if restorepkt.type in [bFileType["FT_LNK"],bFileType["FT_LNKSAVED"]]: # return bRCs["bRC_OK"] - file_name = restorepkt.ofname.decode("string_escape") + file_name = restorepkt.ofname#.decode("string_escape") file_attr = restorepkt.statp self.statp[file_name] = file_attr bareosfd.DebugMessage( - context, 150, "Set file attributes " + file_name + " with stat " + str(file_attr) + "\n", ) @@ -335,7 +323,6 @@ def set_file_attributes(self, context, restorepkt): os.utime(file_name, (file_attr.atime, file_attr.mtime)) newStat = os.stat(file_name) bareosfd.DebugMessage( - context, 150, "Verified file attributes " + file_name @@ -346,21 +333,17 @@ def set_file_attributes(self, context, restorepkt): except Exception as e: bareosfd.JobMessage( - context, - bJobMessageType["M_WARNING"], - 'Could net set attributes for file %s: "%s"' % (file_name, e.message), + M_WARNING, + 'Could net set attributes for file %s: "%s"' % (file_name, e), ) + return bRC_OK - return bRCs["bRC_OK"] - - def end_restore_file(self, context): + def end_restore_file(self): bareosfd.DebugMessage( - context, 100, "end_restore_file() entry point in Python called FNAME: %s\n" % self.FNAME, ) bareosfd.DebugMessage( - context, 150, "end_restore_file set file attributes " + self.FNAME @@ -379,24 +362,23 @@ def end_restore_file(self, context): # del self.statp[self.FNAME] except Exception as e: bareosfd.JobMessage( - context, - bJobMessageType["M_WARNING"], - 'Could net set attributes for file %s: "%s"' % (self.FNAME, e.message), + M_WARNING, + 'Could net set attributes for file %s: "%s"' % (self.FNAME, e), ) - return bRCs["bRC_OK"] + return bRC_OK - def end_backup_file(self, context): + def end_backup_file(self): """ Here we return 'bRC_More' as long as our list files_to_backup is not empty and bRC_OK when we are done """ bareosfd.DebugMessage( - context, 100, "end_backup_file() entry point in Python called\n" + 100, "end_backup_file() entry point in Python called\n" ) if self.files_to_backup: - return bRCs["bRC_More"] + return bRC_More else: - return bRCs["bRC_OK"] + return bRC_OK # vim: ts=4 tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py index 44d84a92d87..da08418b637 100644 --- a/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py +++ b/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # BAREOS - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2014-2014 Bareos GmbH & Co. KG +# Copyright (C) 2014-2020 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -27,7 +27,7 @@ # # Provided by the Bareos FD Python plugin interface -import bareos_fd_consts +import bareosfd # This module contains the wrapper functions called by the Bareos-FD, the # functions call the corresponding methods from your plugin class @@ -40,7 +40,7 @@ import BareosFdPluginLocalFileset -def load_bareos_plugin(context, plugindef): +def load_bareos_plugin(plugindef): """ This function is called by the Bareos-FD to load the plugin We use it to instantiate the plugin class @@ -48,9 +48,9 @@ def load_bareos_plugin(context, plugindef): # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that # holds the plugin class object BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLocalFileset.BareosFdPluginLocalFileset( - context, plugindef + plugindef ) - return bareos_fd_consts.bRCs["bRC_OK"] + return bareosfd.bRC_OK # the rest is done in the Plugin module diff --git a/systemtests/tests/py2plug-fd-local-fileset/testrunner b/systemtests/tests/py2plug-fd-local-fileset/testrunner index 80e23934e57..0030a3ba0dd 100755 --- a/systemtests/tests/py2plug-fd-local-fileset/testrunner +++ b/systemtests/tests/py2plug-fd-local-fileset/testrunner @@ -1,6 +1,8 @@ #!/bin/bash +set -e +set -u # -# This systemtest tests the plugin functionality +# This systemtest tests the plugin functionality # of the Bareos FD by using the supplied module # bareos-fd-local-fileset.py # From a2c64d3862f78675915b8cd990c1de4256b0ea62 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 17 Aug 2020 14:49:06 +0200 Subject: [PATCH 231/341] python plugins: Imported BareosFdLocalFileset files from master --- systemtests/CMakeLists.txt | 9 +- .../BareosFdPluginLocalFileset.py | 200 ++++++++++-------- .../python-modules/bareos-fd-local-fileset.py | 10 +- 3 files changed, 119 insertions(+), 100 deletions(-) diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index ade67520a0b..2f94645cc66 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -84,10 +84,11 @@ function(ConfigureFilesToSystemtest srcbasedir dirname globexpression string(REPLACE "${srcbasedir}/${srcdirname}" "" TARGET_FILE ${TARGET_FILE}) get_filename_component(DIR_NAME ${TARGET_FILE} DIRECTORY) if(DIR_NAME MATCHES "python-modules$") - message( - STATUS - "symlinking ${CURRENT_FILE} ${PROJECT_BINARY_DIR}/${dirname}/${TARGET_FILE}" - ) + if(NOT EXISTS ${PROJECT_BINARY_DIR}/${dirname}/${DIR_NAME}) + file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/${dirname}/${DIR_NAME}) + endif() + # message( STATUS "symlinking ${CURRENT_FILE} + # ${PROJECT_BINARY_DIR}/${dirname}/${TARGET_FILE}" ) create_symlink( ${CURRENT_FILE} ${PROJECT_BINARY_DIR}/${dirname}/${TARGET_FILE} ) diff --git a/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py index 092aa1574ba..2618e17e368 100644 --- a/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py +++ b/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py @@ -25,7 +25,7 @@ # the backup fileset import bareosfd -from bareosfd import * +from bareos_fd_consts import bJobMessageType, bFileType, bRCs, bCFs import os import re import BareosFdPluginBaseclass @@ -40,8 +40,9 @@ class BareosFdPluginLocalFileset( listed there Filename is taken from plugin argument 'filename' """ - def __init__(self,plugindef, mandatory_options=None): + def __init__(self, context, plugindef, mandatory_options=None): bareosfd.DebugMessage( + context, 100, "Constructor called in module %s with plugindef=%s\n" % (__name__, plugindef), @@ -50,7 +51,7 @@ def __init__(self,plugindef, mandatory_options=None): mandatory_options = ["filename"] # Last argument of super constructor is a list of mandatory arguments super(BareosFdPluginLocalFileset, self).__init__( - plugindef, mandatory_options + context, plugindef, mandatory_options ) self.files_to_backup = [] self.file_to_backup = "" @@ -61,7 +62,7 @@ def __init__(self,plugindef, mandatory_options=None): self.allow = None self.deny = None - def filename_is_allowed(self, filename, allowregex, denyregex): + def filename_is_allowed(self, context, filename, allowregex, denyregex): """ Check, if filename is allowed. True, if matches allowreg and not denyregex. @@ -78,17 +79,18 @@ def filename_is_allowed(self, filename, allowregex, denyregex): denied = True if not allowed or denied: bareosfd.DebugMessage( - 100, "File %s denied by configuration\n" % (filename) + context, 100, "File %s denied by configuration\n" % (filename) ) bareosfd.JobMessage( - M_ERROR, + context, + bJobMessageType["M_ERROR"], "File %s denied by configuration\n" % (filename), ) return False else: return True - def append_file_to_backup(self, filename): + def append_file_to_backup(self, context, filename): """ Basically add filename to list of files to backup in files_to_backup @@ -97,30 +99,32 @@ def append_file_to_backup(self, filename): """ self.files_to_backup.append(filename) - def start_backup_job(self): + def start_backup_job(self, context): """ At this point, plugin options were passed and checked already. We try to read from filename and setup the list of file to backup in self.files_to_backup """ bareosfd.DebugMessage( + context, 100, "Using %s to search for local files\n" % self.options["filename"], ) if os.path.exists(self.options["filename"]): try: - config_file = open(self.options["filename"], "r") + config_file = open(self.options["filename"], "rb") except: bareosfd.DebugMessage( + context, 100, "Could not open file %s\n" % (self.options["filename"]), ) - return bRC_Error + return bRCs["bRC_Error"] else: bareosfd.DebugMessage( - 100, "File %s does not exist\n" % (self.options["filename"]) + context, 100, "File %s does not exist\n" % (self.options["filename"]) ) - return bRC_Error + return bRCs["bRC_Error"] # Check, if we have allow or deny regular expressions defined if "allow" in self.options: self.allow = re.compile(self.options["allow"]) @@ -129,51 +133,53 @@ def start_backup_job(self): for listItem in config_file.read().splitlines(): if os.path.isfile(listItem) and self.filename_is_allowed( - listItem, self.allow, self.deny + context, listItem, self.allow, self.deny ): - self.append_file_to_backup(listItem) + self.append_file_to_backup(context, listItem) if os.path.isdir(listItem): fullDirName = listItem # FD requires / at the end of a directory name - if not fullDirName.endswith(tuple("/")): + if not fullDirName.endswith("/"): fullDirName += "/" - self.append_file_to_backup(fullDirName) + self.append_file_to_backup(context, fullDirName) for topdir, dirNames, fileNames in os.walk(listItem): for fileName in fileNames: if self.filename_is_allowed( + context, os.path.join(topdir, fileName), self.allow, self.deny, ): self.append_file_to_backup( - os.path.join(topdir, fileName) + context, os.path.join(topdir, fileName) ) for dirName in dirNames: fullDirName = os.path.join(topdir, dirName) + "/" - self.append_file_to_backup(fullDirName) - bareosfd.DebugMessage(150, "Filelist: %s\n" % (self.files_to_backup)) + self.append_file_to_backup(context, fullDirName) + bareosfd.DebugMessage(context, 150, "Filelist: %s\n" % (self.files_to_backup)) if not self.files_to_backup: bareosfd.JobMessage( - M_ERROR, + context, + bJobMessageType["M_ERROR"], "No (allowed) files to backup found\n", ) - return bRC_Error + return bRCs["bRC_Error"] else: - return bRC_OK + return bRCs["bRC_OK"] - def start_backup_file(self, savepkt): + def start_backup_file(self, context, savepkt): """ Defines the file to backup and creates the savepkt. In this example only files (no directories) are allowed """ - bareosfd.DebugMessage( 100, "start_backup_file() called\n") + bareosfd.DebugMessage(context, 100, "start_backup_file() called\n") if not self.files_to_backup: - bareosfd.DebugMessage( 100, "No files to backup\n") - return bRC_Skip + bareosfd.DebugMessage(context, 100, "No files to backup\n") + return bRCs["bRC_Skip"] - self.file_to_backup = self.files_to_backup.pop() - bareosfd.DebugMessage(100, "file: " + self.file_to_backup + "\n") + self.file_to_backup = self.files_to_backup.pop().decode("string_escape") + bareosfd.DebugMessage(context, 100, "file: " + self.file_to_backup + "\n") mystatp = bareosfd.StatPacket() try: @@ -183,120 +189,125 @@ def start_backup_file(self, savepkt): statp = os.stat(self.file_to_backup) except Exception as e: bareosfd.JobMessage( - M_ERROR, + context, + bJobMessageType["M_ERROR"], 'Could net get stat-info for file %s: "%s"' - % (self.file_to_backup, e), + % (self.file_to_backup, e.message), ) # As of Bareos 19.2.7 attribute names in bareosfd.StatPacket differ from os.stat # In this case we have to translate names # For future releases consistent names are planned, allowing to assign the # complete stat object in one rush - # if hasattr(mystatp, "st_uid"): - # mystatp = statp - # else: - mystatp.st_mode = statp.st_mode - mystatp.st_ino = statp.st_ino - mystatp.st_dev = statp.st_dev - mystatp.st_nlink = statp.st_nlink - mystatp.st_uid = statp.st_uid - mystatp.st_gid = statp.st_gid - mystatp.st_size = statp.st_size - mystatp.st_atime = statp.st_atime - mystatp.st_mtime = statp.st_mtime - mystatp.st_ctime = statp.st_ctime - savepkt.fname = self.file_to_backup #.encode("string_escape") + if hasattr(mystatp, "st_uid"): + mystatp = statp + else: + mystatp.mode = statp.st_mode + mystatp.ino = statp.st_ino + mystatp.dev = statp.st_dev + mystatp.nlink = statp.st_nlink + mystatp.uid = statp.st_uid + mystatp.gid = statp.st_gid + mystatp.size = statp.st_size + mystatp.atime = statp.st_atime + mystatp.mtime = statp.st_mtime + mystatp.ctime = statp.st_ctime + savepkt.fname = self.file_to_backup.encode("string_escape") # os.islink will detect links to directories only when # there is no trailing slash - we need to perform checks # on the stripped name but use it with trailing / for the backup itself if os.path.islink(self.file_to_backup.rstrip("/")): - savepkt.type = FT_LNK + savepkt.type = bFileType["FT_LNK"] savepkt.link = os.readlink( - self.file_to_backup.rstrip("/")#.encode("string_escape") + self.file_to_backup.rstrip("/").encode("string_escape") ) - bareosfd.DebugMessage(150, "file type is: FT_LNK\n") + bareosfd.DebugMessage(context, 150, "file type is: FT_LNK\n") elif os.path.isfile(self.file_to_backup): - savepkt.type = FT_REG - bareosfd.DebugMessage(150, "file type is: FT_REG\n") + savepkt.type = bFileType["FT_REG"] + bareosfd.DebugMessage(context, 150, "file type is: FT_REG\n") elif os.path.isdir(self.file_to_backup): - savepkt.type = FT_DIREND + savepkt.type = bFileType["FT_DIREND"] savepkt.link = self.file_to_backup bareosfd.DebugMessage( - 150, "file %s type is: FT_DIREND\n" % self.file_to_backup + context, 150, "file %s type is: FT_DIREND\n" % self.file_to_backup ) elif stat.S_ISFIFO(os.stat(self.file_to_backup).st_mode): - savepkt.type = FT_FIFO - bareosfd.DebugMessage(150, "file type is: FT_FIFO\n") + savepkt.type = bFileType["FT_FIFO"] + bareosfd.DebugMessage(context, 150, "file type is: FT_FIFO\n") else: bareosfd.JobMessage( - M_WARNING, + context, + bJobMessageType["M_WARNING"], "File %s of unknown type" % (self.file_to_backup), ) - return bRC_Skip + return bRCs["bRC_Skip"] savepkt.statp = mystatp - bareosfd.DebugMessage(150, "file statpx " + str(savepkt.statp) + "\n") + bareosfd.DebugMessage(context, 150, "file statpx " + str(savepkt.statp) + "\n") - return bRC_OK + return bRCs["bRC_OK"] - def create_file(self, restorepkt): + def create_file(self, context, restorepkt): """ Creates the file to be restored and directory structure, if needed. Adapt this in your derived class, if you need modifications for virtual files or similar """ bareosfd.DebugMessage( + context, 100, "create_file() entry point in Python called with %s\n" % (restorepkt), ) - FNAME = restorepkt.ofname + FNAME = restorepkt.ofname.decode("string_escape") if not FNAME: - return bRC_Error + return bRCs["bRC_Error"] dirname = os.path.dirname(FNAME.rstrip("/")) if not os.path.exists(dirname): bareosfd.DebugMessage( - 200, "Directory %s does not exist, creating it now\n" % dirname + context, 200, "Directory %s does not exist, creating it now\n" % dirname ) os.makedirs(dirname) # open creates the file, if not yet existing, we close it again right - # away it will be opened again in plugin_io. - if restorepkt.type == FT_REG: + # aways it will be opened again in plugin_io. + if restorepkt.type == bFileType["FT_REG"]: open(FNAME, "wb").close() - restorepkt.create_status = CF_EXTRACT - elif restorepkt.type == FT_LNK: + restorepkt.create_status = bCFs["CF_EXTRACT"] + elif restorepkt.type == bFileType["FT_LNK"]: linkNameEnc = restorepkt.olname - linkNameClear = linkNameEnc#.decode("string_escape") + linkNameClear = linkNameEnc.decode("string_escape") if not os.path.islink(FNAME.rstrip("/")): # if not os.path.exists(linkNameClear): os.symlink(linkNameClear, FNAME.rstrip("/")) - restorepkt.create_status = CF_CREATED - elif restorepkt.type == FT_LNKSAVED: + restorepkt.create_status = bCFs["CF_CREATED"] + elif restorepkt.type == bFileType["FT_LNKSAVED"]: linkNameEnc = restorepkt.olname - linkNameClear = linkNameEnc#.decode("string_escape") + linkNameClear = linkNameEnc.decode("string_escape") if not os.path.exists(linkNameClear): os.link(linkNameClear, FNAME.rstrip("/")) - restorepkt.create_status = CF_CREATED - elif restorepkt.type == FT_DIREND: + restorepkt.create_status = bCFs["CF_CREATED"] + elif restorepkt.type == bFileType["FT_DIREND"]: if not os.path.exists(FNAME): os.makedirs(FNAME) - restorepkt.create_status = CF_CREATED - elif restorepkt.type == FT_FIFO: + restorepkt.create_status = bCFs["CF_CREATED"] + elif restorepkt.type == bFileType["FT_FIFO"]: if not os.path.exists(FNAME): try: os.mkfifo(FNAME, 0o600) except Exception as e: bareosfd.JobMessage( - M_ERROR, - 'Could net create fifo %s: "%s"' % (FNAME, e), + context, + bJobMessageType["M_ERROR"], + 'Could net create fifo %s: "%s"' % (FNAME, e.message), ) - restorepkt.create_status = CF_CREATED + restorepkt.create_status = bCFs["CF_CREATED"] else: bareosfd.JobMessage( - M_ERROR, + context, + bJobMessageType["M_ERROR"], "Unknown type %s of file %s" % (restorepkt.type, FNAME), ) - return bRC_OK + return bRCs["bRC_OK"] - def set_file_attributes(self, restorepkt): + def set_file_attributes(self, context, restorepkt): """ Need to verify: we set attributes here but on plugin_io close the mtime will be modified again. @@ -309,11 +320,12 @@ def set_file_attributes(self, restorepkt): # Python attribute setting does not work properly with links # if restorepkt.type in [bFileType["FT_LNK"],bFileType["FT_LNKSAVED"]]: # return bRCs["bRC_OK"] - file_name = restorepkt.ofname#.decode("string_escape") + file_name = restorepkt.ofname.decode("string_escape") file_attr = restorepkt.statp self.statp[file_name] = file_attr bareosfd.DebugMessage( + context, 150, "Set file attributes " + file_name + " with stat " + str(file_attr) + "\n", ) @@ -323,6 +335,7 @@ def set_file_attributes(self, restorepkt): os.utime(file_name, (file_attr.atime, file_attr.mtime)) newStat = os.stat(file_name) bareosfd.DebugMessage( + context, 150, "Verified file attributes " + file_name @@ -333,17 +346,21 @@ def set_file_attributes(self, restorepkt): except Exception as e: bareosfd.JobMessage( - M_WARNING, - 'Could net set attributes for file %s: "%s"' % (file_name, e), + context, + bJobMessageType["M_WARNING"], + 'Could net set attributes for file %s: "%s"' % (file_name, e.message), ) - return bRC_OK - def end_restore_file(self): + return bRCs["bRC_OK"] + + def end_restore_file(self, context): bareosfd.DebugMessage( + context, 100, "end_restore_file() entry point in Python called FNAME: %s\n" % self.FNAME, ) bareosfd.DebugMessage( + context, 150, "end_restore_file set file attributes " + self.FNAME @@ -362,23 +379,24 @@ def end_restore_file(self): # del self.statp[self.FNAME] except Exception as e: bareosfd.JobMessage( - M_WARNING, - 'Could net set attributes for file %s: "%s"' % (self.FNAME, e), + context, + bJobMessageType["M_WARNING"], + 'Could net set attributes for file %s: "%s"' % (self.FNAME, e.message), ) - return bRC_OK + return bRCs["bRC_OK"] - def end_backup_file(self): + def end_backup_file(self, context): """ Here we return 'bRC_More' as long as our list files_to_backup is not empty and bRC_OK when we are done """ bareosfd.DebugMessage( - 100, "end_backup_file() entry point in Python called\n" + context, 100, "end_backup_file() entry point in Python called\n" ) if self.files_to_backup: - return bRC_More + return bRCs["bRC_More"] else: - return bRC_OK + return bRCs["bRC_OK"] # vim: ts=4 tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py index da08418b637..44d84a92d87 100644 --- a/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py +++ b/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # BAREOS - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2014-2020 Bareos GmbH & Co. KG +# Copyright (C) 2014-2014 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -27,7 +27,7 @@ # # Provided by the Bareos FD Python plugin interface -import bareosfd +import bareos_fd_consts # This module contains the wrapper functions called by the Bareos-FD, the # functions call the corresponding methods from your plugin class @@ -40,7 +40,7 @@ import BareosFdPluginLocalFileset -def load_bareos_plugin(plugindef): +def load_bareos_plugin(context, plugindef): """ This function is called by the Bareos-FD to load the plugin We use it to instantiate the plugin class @@ -48,9 +48,9 @@ def load_bareos_plugin(plugindef): # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that # holds the plugin class object BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLocalFileset.BareosFdPluginLocalFileset( - plugindef + context, plugindef ) - return bareosfd.bRC_OK + return bareos_fd_consts.bRCs["bRC_OK"] # the rest is done in the Plugin module From 58a9353a3901a96cddb49da920a8a1aed216edc9 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 17 Aug 2020 17:56:47 +0200 Subject: [PATCH 232/341] fixing still failing tests: partly done --- .../BareosFdPluginLocalFileset.py | 152 ++++---- ...sFdPluginLocalFilesetWithRestoreObjects.py | 353 ------------------ ...os-fd-local-fileset-with-restoreobjects.py | 59 --- .../tests/py2plug-fd-postgres/testrunner | 8 - 4 files changed, 67 insertions(+), 505 deletions(-) delete mode 100644 systemtests/tests/py2plug-fd-postgres/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py delete mode 100644 systemtests/tests/py2plug-fd-postgres/python-modules/bareos-fd-local-fileset-with-restoreobjects.py diff --git a/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py index 2618e17e368..dd576049aff 100644 --- a/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py +++ b/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py @@ -25,7 +25,6 @@ # the backup fileset import bareosfd -from bareos_fd_consts import bJobMessageType, bFileType, bRCs, bCFs import os import re import BareosFdPluginBaseclass @@ -40,9 +39,8 @@ class BareosFdPluginLocalFileset( listed there Filename is taken from plugin argument 'filename' """ - def __init__(self, context, plugindef, mandatory_options=None): + def __init__(self, plugindef, mandatory_options=None): bareosfd.DebugMessage( - context, 100, "Constructor called in module %s with plugindef=%s\n" % (__name__, plugindef), @@ -51,7 +49,7 @@ def __init__(self, context, plugindef, mandatory_options=None): mandatory_options = ["filename"] # Last argument of super constructor is a list of mandatory arguments super(BareosFdPluginLocalFileset, self).__init__( - context, plugindef, mandatory_options + plugindef, mandatory_options ) self.files_to_backup = [] self.file_to_backup = "" @@ -62,7 +60,7 @@ def __init__(self, context, plugindef, mandatory_options=None): self.allow = None self.deny = None - def filename_is_allowed(self, context, filename, allowregex, denyregex): + def filename_is_allowed(self, filename, allowregex, denyregex): """ Check, if filename is allowed. True, if matches allowreg and not denyregex. @@ -79,18 +77,17 @@ def filename_is_allowed(self, context, filename, allowregex, denyregex): denied = True if not allowed or denied: bareosfd.DebugMessage( - context, 100, "File %s denied by configuration\n" % (filename) + 100, "File %s denied by configuration\n" % (filename) ) bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], + bareosfd.M_ERROR, "File %s denied by configuration\n" % (filename), ) return False else: return True - def append_file_to_backup(self, context, filename): + def append_file_to_backup(self, filename): """ Basically add filename to list of files to backup in files_to_backup @@ -99,14 +96,13 @@ def append_file_to_backup(self, context, filename): """ self.files_to_backup.append(filename) - def start_backup_job(self, context): + def start_backup_job(self): """ At this point, plugin options were passed and checked already. We try to read from filename and setup the list of file to backup in self.files_to_backup """ bareosfd.DebugMessage( - context, 100, "Using %s to search for local files\n" % self.options["filename"], ) @@ -115,16 +111,15 @@ def start_backup_job(self, context): config_file = open(self.options["filename"], "rb") except: bareosfd.DebugMessage( - context, 100, "Could not open file %s\n" % (self.options["filename"]), ) - return bRCs["bRC_Error"] + return bareosfd.bRC_Error else: bareosfd.DebugMessage( - context, 100, "File %s does not exist\n" % (self.options["filename"]) + 100, "File %s does not exist\n" % (self.options["filename"]) ) - return bRCs["bRC_Error"] + return bareosfd.bRC_Error # Check, if we have allow or deny regular expressions defined if "allow" in self.options: self.allow = re.compile(self.options["allow"]) @@ -133,53 +128,51 @@ def start_backup_job(self, context): for listItem in config_file.read().splitlines(): if os.path.isfile(listItem) and self.filename_is_allowed( - context, listItem, self.allow, self.deny + listItem, self.allow, self.deny ): - self.append_file_to_backup(context, listItem) + self.append_file_to_backup(listItem) if os.path.isdir(listItem): fullDirName = listItem # FD requires / at the end of a directory name if not fullDirName.endswith("/"): fullDirName += "/" - self.append_file_to_backup(context, fullDirName) + self.append_file_to_backup(fullDirName) for topdir, dirNames, fileNames in os.walk(listItem): for fileName in fileNames: if self.filename_is_allowed( - context, os.path.join(topdir, fileName), self.allow, self.deny, ): self.append_file_to_backup( - context, os.path.join(topdir, fileName) + os.path.join(topdir, fileName) ) for dirName in dirNames: fullDirName = os.path.join(topdir, dirName) + "/" - self.append_file_to_backup(context, fullDirName) - bareosfd.DebugMessage(context, 150, "Filelist: %s\n" % (self.files_to_backup)) + self.append_file_to_backup(fullDirName) + bareosfd.DebugMessage(150, "Filelist: %s\n" % (self.files_to_backup)) if not self.files_to_backup: bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], + bareosfd.M_ERROR, "No (allowed) files to backup found\n", ) - return bRCs["bRC_Error"] + return bareosfd.bRC_Error else: - return bRCs["bRC_OK"] + return bareosfd.bRC_OK - def start_backup_file(self, context, savepkt): + def start_backup_file(self, savepkt): """ Defines the file to backup and creates the savepkt. In this example only files (no directories) are allowed """ - bareosfd.DebugMessage(context, 100, "start_backup_file() called\n") + bareosfd.DebugMessage(100, "start_backup_file() called\n") if not self.files_to_backup: - bareosfd.DebugMessage(context, 100, "No files to backup\n") - return bRCs["bRC_Skip"] + bareosfd.DebugMessage(100, "No files to backup\n") + return bareosfd.bRC_Skip self.file_to_backup = self.files_to_backup.pop().decode("string_escape") - bareosfd.DebugMessage(context, 100, "file: " + self.file_to_backup + "\n") + bareosfd.DebugMessage(100, "file: " + self.file_to_backup + "\n") mystatp = bareosfd.StatPacket() try: @@ -189,8 +182,7 @@ def start_backup_file(self, context, savepkt): statp = os.stat(self.file_to_backup) except Exception as e: bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], + bareosfd.M_ERROR, 'Could net get stat-info for file %s: "%s"' % (self.file_to_backup, e.message), ) @@ -216,116 +208,111 @@ def start_backup_file(self, context, savepkt): # there is no trailing slash - we need to perform checks # on the stripped name but use it with trailing / for the backup itself if os.path.islink(self.file_to_backup.rstrip("/")): - savepkt.type = bFileType["FT_LNK"] + savepkt.type = bareosfd.FT_LNK savepkt.link = os.readlink( self.file_to_backup.rstrip("/").encode("string_escape") ) - bareosfd.DebugMessage(context, 150, "file type is: FT_LNK\n") + bareosfd.DebugMessage(150, "file type is: FT_LNK\n") elif os.path.isfile(self.file_to_backup): - savepkt.type = bFileType["FT_REG"] - bareosfd.DebugMessage(context, 150, "file type is: FT_REG\n") + savepkt.type = bareosfd.FT_REG + bareosfd.DebugMessage(150, "file type is: FT_REG\n") elif os.path.isdir(self.file_to_backup): - savepkt.type = bFileType["FT_DIREND"] + savepkt.type = bareosfd.FT_DIREND savepkt.link = self.file_to_backup bareosfd.DebugMessage( - context, 150, "file %s type is: FT_DIREND\n" % self.file_to_backup + 150, "file %s type is: FT_DIREND\n" % self.file_to_backup ) elif stat.S_ISFIFO(os.stat(self.file_to_backup).st_mode): - savepkt.type = bFileType["FT_FIFO"] - bareosfd.DebugMessage(context, 150, "file type is: FT_FIFO\n") + savepkt.type = bareosfd.FT_FIFO + bareosfd.DebugMessage(150, "file type is: FT_FIFO\n") else: bareosfd.JobMessage( - context, - bJobMessageType["M_WARNING"], + bareosfd.M_WARNING, "File %s of unknown type" % (self.file_to_backup), ) - return bRCs["bRC_Skip"] + return bareosfd.bRC_Skip savepkt.statp = mystatp - bareosfd.DebugMessage(context, 150, "file statpx " + str(savepkt.statp) + "\n") + bareosfd.DebugMessage(150, "file statpx " + str(savepkt.statp) + "\n") - return bRCs["bRC_OK"] + return bareosfd.bRC_OK - def create_file(self, context, restorepkt): + def create_file(self, restorepkt): """ Creates the file to be restored and directory structure, if needed. Adapt this in your derived class, if you need modifications for virtual files or similar """ bareosfd.DebugMessage( - context, 100, "create_file() entry point in Python called with %s\n" % (restorepkt), ) FNAME = restorepkt.ofname.decode("string_escape") if not FNAME: - return bRCs["bRC_Error"] + return bareosfd.bRC_Error dirname = os.path.dirname(FNAME.rstrip("/")) if not os.path.exists(dirname): bareosfd.DebugMessage( - context, 200, "Directory %s does not exist, creating it now\n" % dirname + 200, "Directory %s does not exist, creating it now\n" % dirname ) os.makedirs(dirname) # open creates the file, if not yet existing, we close it again right # aways it will be opened again in plugin_io. - if restorepkt.type == bFileType["FT_REG"]: + if restorepkt.type == bareosfd.FT_REG: open(FNAME, "wb").close() - restorepkt.create_status = bCFs["CF_EXTRACT"] - elif restorepkt.type == bFileType["FT_LNK"]: + restorepkt.create_status = bareosfd.CF_EXTRACT + elif restorepkt.type == bareosfd.FT_LNK: linkNameEnc = restorepkt.olname linkNameClear = linkNameEnc.decode("string_escape") if not os.path.islink(FNAME.rstrip("/")): # if not os.path.exists(linkNameClear): os.symlink(linkNameClear, FNAME.rstrip("/")) - restorepkt.create_status = bCFs["CF_CREATED"] - elif restorepkt.type == bFileType["FT_LNKSAVED"]: + restorepkt.create_status = bareosfd.CF_CREATED + elif restorepkt.type == bareosfd.FT_LNKSAVED: linkNameEnc = restorepkt.olname linkNameClear = linkNameEnc.decode("string_escape") if not os.path.exists(linkNameClear): os.link(linkNameClear, FNAME.rstrip("/")) - restorepkt.create_status = bCFs["CF_CREATED"] - elif restorepkt.type == bFileType["FT_DIREND"]: + restorepkt.create_status = bareosfd.CF_CREATED + elif restorepkt.type == bareosfd.FT_DIREND: if not os.path.exists(FNAME): os.makedirs(FNAME) - restorepkt.create_status = bCFs["CF_CREATED"] - elif restorepkt.type == bFileType["FT_FIFO"]: + restorepkt.create_status = bareosfd.CF_CREATED + elif restorepkt.type == bareosfd.FT_FIFO: if not os.path.exists(FNAME): try: os.mkfifo(FNAME, 0o600) except Exception as e: bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], + bareosfd.M_ERROR, 'Could net create fifo %s: "%s"' % (FNAME, e.message), ) - restorepkt.create_status = bCFs["CF_CREATED"] + restorepkt.create_status = bareosfd.CF_CREATED else: bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], + bareosfd.M_ERROR, "Unknown type %s of file %s" % (restorepkt.type, FNAME), ) - return bRCs["bRC_OK"] + return bareosfd.bRC_OK - def set_file_attributes(self, context, restorepkt): + def set_file_attributes(self, restorepkt): """ Need to verify: we set attributes here but on plugin_io close the mtime will be modified again. approach: save stat-packet here and set it on end_restore_file """ - # restorepkt.create_status = bCFs["CF_CORE"] - # return bRCs["bRC_OK"] + # restorepkt.create_status = bareosfd.CF_CORE + # return bareosfd.bRC_OK # Python attribute setting does not work properly with links - # if restorepkt.type in [bFileType["FT_LNK"],bFileType["FT_LNKSAVED"]]: - # return bRCs["bRC_OK"] + # if restorepkt.type in [bareosfd.FT_LNK,bareosfd.FT_LNKSAVED]: + # return bareosfd.bRC_OK file_name = restorepkt.ofname.decode("string_escape") file_attr = restorepkt.statp self.statp[file_name] = file_attr bareosfd.DebugMessage( - context, 150, "Set file attributes " + file_name + " with stat " + str(file_attr) + "\n", ) @@ -335,7 +322,6 @@ def set_file_attributes(self, context, restorepkt): os.utime(file_name, (file_attr.atime, file_attr.mtime)) newStat = os.stat(file_name) bareosfd.DebugMessage( - context, 150, "Verified file attributes " + file_name @@ -346,21 +332,18 @@ def set_file_attributes(self, context, restorepkt): except Exception as e: bareosfd.JobMessage( - context, - bJobMessageType["M_WARNING"], + bareosfd.M_WARNING, 'Could net set attributes for file %s: "%s"' % (file_name, e.message), ) - return bRCs["bRC_OK"] + return bareosfd.bRC_OK - def end_restore_file(self, context): + def end_restore_file(self): bareosfd.DebugMessage( - context, 100, "end_restore_file() entry point in Python called FNAME: %s\n" % self.FNAME, ) bareosfd.DebugMessage( - context, 150, "end_restore_file set file attributes " + self.FNAME @@ -379,24 +362,23 @@ def end_restore_file(self, context): # del self.statp[self.FNAME] except Exception as e: bareosfd.JobMessage( - context, - bJobMessageType["M_WARNING"], + bareosfd.M_WARNING, 'Could net set attributes for file %s: "%s"' % (self.FNAME, e.message), ) - return bRCs["bRC_OK"] + return bareosfd.bRC_OK - def end_backup_file(self, context): + def end_backup_file(self): """ Here we return 'bRC_More' as long as our list files_to_backup is not empty and bRC_OK when we are done """ bareosfd.DebugMessage( - context, 100, "end_backup_file() entry point in Python called\n" + 100, "end_backup_file() entry point in Python called\n" ) if self.files_to_backup: - return bRCs["bRC_More"] + return bareosfd.bRC_More else: - return bRCs["bRC_OK"] + return bareosfd.bRC_OK # vim: ts=4 tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/systemtests/tests/py2plug-fd-postgres/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py b/systemtests/tests/py2plug-fd-postgres/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py deleted file mode 100644 index 7a5c2e5e7a4..00000000000 --- a/systemtests/tests/py2plug-fd-postgres/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py +++ /dev/null @@ -1,353 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# BAREOS - Backup Archiving REcovery Open Sourced -# -# Copyright (C) 2014-2019 Bareos GmbH & Co. KG -# -# This program is Free Software; you can redistribute it and/or -# modify it under the terms of version three of the GNU Affero General Public -# License as published by the Free Software Foundation, which is -# listed in the file LICENSE. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# Author: Maik Aussendorf -# -# Bareos python plugins class that adds files from a local list to -# the backup fileset - -import bareosfd -from bareos_fd_consts import bJobMessageType, bFileType, bRCs -import os -import re -import hashlib -import time -import BareosFdPluginBaseclass - - -class BareosFdPluginLocalFilesetWithRestoreObjects( - BareosFdPluginBaseclass.BareosFdPluginBaseclass -): - """ - This Bareos-FD-Plugin-Class was created for automated test purposes only. - It is based on the BareosFdPluginLocalFileset class that parses a file - and backups all files listed there. - Filename is taken from plugin argument 'filename'. - In addition to the file backup and restore, this plugin also tests - restore objects of different sizes. As restore objects are compressed - automatically, when they are greater then 1000 bytes, both uncompressed - and compressed restore objects are tested. - """ - - def __init__(self, context, plugindef): - bareosfd.DebugMessage( - context, - 100, - "Constructor called in module %s with plugindef=%s\n" - % (__name__, plugindef), - ) - # Last argument of super constructor is a list of mandatory arguments - super(BareosFdPluginLocalFilesetWithRestoreObjects, self).__init__( - context, plugindef, ["filename"] - ) - self.files_to_backup = [] - self.allow = None - self.deny = None - self.object_index_seq = int((time.time() - 1546297200) * 10) - self.sha256sums_by_filename = {} - - def filename_is_allowed(self, context, filename, allowregex, denyregex): - """ - Check, if filename is allowed. - True, if matches allowreg and not denyregex. - If allowreg is None, filename always matches - If denyreg is None, it never matches - """ - if allowregex is None or allowregex.search(filename): - allowed = True - else: - allowed = False - if denyregex is None or not denyregex.search(filename): - denied = False - else: - denied = True - if not allowed or denied: - bareosfd.DebugMessage( - context, 100, "File %s denied by configuration\n" % (filename) - ) - bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], - "File %s denied by configuration\n" % (filename), - ) - return False - else: - return True - - def start_backup_job(self, context): - """ - At this point, plugin options were passed and checked already. - We try to read from filename and setup the list of file to backup - in self.files_to_backup - """ - - bareosfd.DebugMessage( - context, - 100, - "Using %s to search for local files\n" % (self.options["filename"]), - ) - if os.path.exists(self.options["filename"]): - try: - config_file = open(self.options["filename"], "rb") - except: - bareosfd.DebugMessage( - context, - 100, - "Could not open file %s\n" % (self.options["filename"]), - ) - return bRCs["bRC_Error"] - else: - bareosfd.DebugMessage( - context, 100, "File %s does not exist\n" % (self.options["filename"]) - ) - return bRCs["bRC_Error"] - # Check, if we have allow or deny regular expressions defined - if "allow" in self.options: - self.allow = re.compile(self.options["allow"]) - if "deny" in self.options: - self.deny = re.compile(self.options["deny"]) - - for listItem in config_file.read().splitlines(): - if os.path.isfile(listItem) and self.filename_is_allowed( - context, listItem, self.allow, self.deny - ): - self.files_to_backup.append(listItem) - if os.path.isdir(listItem): - for topdir, dirNames, fileNames in os.walk(listItem): - for fileName in fileNames: - if self.filename_is_allowed( - context, - os.path.join(topdir, fileName), - self.allow, - self.deny, - ): - self.files_to_backup.append(os.path.join(topdir, fileName)) - if os.path.isfile(os.path.join(topdir, fileName)): - self.files_to_backup.append( - os.path.join(topdir, fileName) + ".sha256sum" - ) - self.files_to_backup.append( - os.path.join(topdir, fileName) + ".abspath" - ) - else: - if os.path.isfile(listItem): - self.files_to_backup.append(listItem + ".sha256sum") - self.files_to_backup.append(listItem + ".abspath") - - for longrestoreobject_length in range(998, 1004): - self.files_to_backup.append( - "%s.longrestoreobject" % longrestoreobject_length - ) - - if not self.files_to_backup: - bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], - "No (allowed) files to backup found\n", - ) - return bRCs["bRC_Error"] - else: - return bRCs["bRC_Cancel"] - - def start_backup_file(self, context, savepkt): - """ - Defines the file to backup and creates the savepkt. In this example - only files (no directories) are allowed - """ - bareosfd.DebugMessage(context, 100, "start_backup_file() called\n") - if not self.files_to_backup: - bareosfd.DebugMessage(context, 100, "No files to backup\n") - return bRCs["bRC_Skip"] - - file_to_backup = self.files_to_backup.pop() - bareosfd.DebugMessage(context, 100, "file: " + file_to_backup + "\n") - - statp = bareosfd.StatPacket() - savepkt.statp = statp - - if file_to_backup.endswith(".sha256sum"): - checksum = self.get_sha256sum(context, os.path.splitext(file_to_backup)[0]) - savepkt.type = bFileType["FT_RESTORE_FIRST"] - savepkt.fname = file_to_backup - savepkt.object_name = file_to_backup - savepkt.object = bytearray(checksum) - savepkt.object_len = len(savepkt.object) - savepkt.object_index = self.object_index_seq - self.object_index_seq += 1 - - elif file_to_backup.endswith(".abspath"): - savepkt.type = bFileType["FT_RESTORE_FIRST"] - savepkt.fname = file_to_backup - savepkt.object_name = file_to_backup - savepkt.object = bytearray(os.path.splitext(file_to_backup)[0]) - savepkt.object_len = len(savepkt.object) - savepkt.object_index = self.object_index_seq - self.object_index_seq += 1 - - elif file_to_backup.endswith(".longrestoreobject"): - teststring_length = int(os.path.splitext(file_to_backup)[0]) - savepkt.type = bFileType["FT_RESTORE_FIRST"] - savepkt.fname = file_to_backup - savepkt.object_name = file_to_backup - savepkt.object = bytearray("a" * teststring_length) - savepkt.object_len = len(savepkt.object) - savepkt.object_index = self.object_index_seq - self.object_index_seq += 1 - - else: - savepkt.fname = file_to_backup - savepkt.type = bFileType["FT_REG"] - - bareosfd.JobMessage( - context, - bJobMessageType["M_INFO"], - "Starting backup of %s\n" % (file_to_backup), - ) - return bRCs["bRC_OK"] - - def end_backup_file(self, context): - """ - Here we return 'bRC_More' as long as our list files_to_backup is not - empty and bRC_OK when we are done - """ - bareosfd.DebugMessage( - context, 100, "end_backup_file() entry point in Python called\n" - ) - if self.files_to_backup: - return bRCs["bRC_More"] - else: - return bRCs["bRC_OK"] - - def set_file_attributes(self, context, restorepkt): - bareosfd.DebugMessage( - context, - 100, - "set_file_attributes() entry point in Python called with %s\n" - % (str(restorepkt)), - ) - - orig_fname = "/" + os.path.relpath(restorepkt.ofname, restorepkt.where) - restoreobject_sha256sum = self.sha256sums_by_filename[orig_fname] - - file_sha256sum = self.get_sha256sum(context, orig_fname) - bareosfd.DebugMessage( - context, - 100, - "set_file_attributes() orig_fname: %s restoreobject_sha256sum: %s file_sha256sum: %s\n" - % (orig_fname, repr(restoreobject_sha256sum), repr(file_sha256sum)), - ) - if file_sha256sum != restoreobject_sha256sum: - bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], - "bad restoreobject orig_fname: %s restoreobject_sha256sum: %s file_sha256sum: %s\n" - % (orig_fname, repr(restoreobject_sha256sum), repr(file_sha256sum)), - ) - - return bRCs["bRC_OK"] - - def end_restore_file(self, context): - bareosfd.DebugMessage( - context, 100, "end_restore_file() self.FNAME: %s\n" % self.FNAME - ) - return bRCs["bRC_OK"] - - def restore_object_data(self, context, ROP): - """ - Note: - This is called in two cases: - - on diff/inc backup (should be called only once) - - on restore (for every job id being restored) - But at the point in time called, it is not possible - to distinguish which of them it is, because job type - is "I" until the bEventStartBackupJob event - """ - bareosfd.DebugMessage( - context, - 100, - "BareosFdPluginLocalFilesetWithRestoreObjects:restore_object_data() called with ROP:%s\n" - % (ROP), - ) - bareosfd.DebugMessage( - context, - 100, - "ROP.object_name(%s): %s\n" % (type(ROP.object_name), ROP.object_name), - ) - bareosfd.DebugMessage( - context, - 100, - "ROP.plugin_name(%s): %s\n" % (type(ROP.plugin_name), ROP.plugin_name), - ) - bareosfd.DebugMessage( - context, - 100, - "ROP.object_len(%s): %s\n" % (type(ROP.object_len), ROP.object_len), - ) - bareosfd.DebugMessage( - context, - 100, - "ROP.object_full_len(%s): %s\n" - % (type(ROP.object_full_len), ROP.object_full_len), - ) - bareosfd.DebugMessage( - context, 100, "ROP.object(%s): %s\n" % (type(ROP.object), repr(ROP.object)) - ) - orig_filename = os.path.splitext(ROP.object_name)[0] - if ROP.object_name.endswith(".sha256sum"): - self.sha256sums_by_filename[orig_filename] = str(ROP.object) - elif ROP.object_name.endswith(".abspath"): - if str(ROP.object) != orig_filename: - bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], - "bad restoreobject orig_fname: %s restoreobject_fname: %s\n" - % (orig_filename, repr(str(ROP.object))), - ) - elif ROP.object_name.endswith(".longrestoreobject"): - stored_length = int(os.path.splitext(ROP.object_name)[0]) - if str(ROP.object) != "a" * stored_length: - bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], - "bad long restoreobject %s does not match stored object\n" - % (ROP.object_name), - ) - else: - bareosfd.DebugMessage( - context, - 100, - "not checking restoreobject: %s\n" % (type(ROP.object_name)), - ) - return bRCs["bRC_OK"] - - def get_sha256sum(self, context, filename): - f = open(filename, "rb") - m = hashlib.sha256() - while True: - d = f.read(8096) - if not d: - break - m.update(d) - f.close() - return m.hexdigest() - - -# vim: ts=4 tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/systemtests/tests/py2plug-fd-postgres/python-modules/bareos-fd-local-fileset-with-restoreobjects.py b/systemtests/tests/py2plug-fd-postgres/python-modules/bareos-fd-local-fileset-with-restoreobjects.py deleted file mode 100644 index b64ef29960f..00000000000 --- a/systemtests/tests/py2plug-fd-postgres/python-modules/bareos-fd-local-fileset-with-restoreobjects.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# BAREOS - Backup Archiving REcovery Open Sourced -# -# Copyright (C) 2014-2014 Bareos GmbH & Co. KG -# -# This program is Free Software; you can redistribute it and/or -# modify it under the terms of version three of the GNU Affero General Public -# License as published by the Free Software Foundation, which is -# listed in the file LICENSE. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# bareos-fd-local-fileset-with-restoreobjects.py is a python Bareos FD Plugin using -# BareosFdPluginLocalFilesetWithRestoreObjects which was made for automated testing -# purposes. -# -# The plugin argument 'filename' is used to read all files listed in that file and -# add it to the fileset -# -# Author: Maik Aussendorf -# - -# Provided by the Bareos FD Python plugin interface -import bareos_fd_consts - -# This module contains the wrapper functions called by the Bareos-FD, the -# functions call the corresponding methods from your plugin class -import BareosFdWrapper - -# from BareosFdWrapper import parse_plugin_definition, handle_plugin_event, start_backup_file, end_backup_file, start_restore_file, end_restore_file, restore_object_data, plugin_io, create_file, check_file, handle_backup_file # noqa -from BareosFdWrapper import * # noqa - -# This module contains the used plugin class -import BareosFdPluginLocalFilesetWithRestoreObjects - - -def load_bareos_plugin(context, plugindef): - """ - This function is called by the Bareos-FD to load the plugin - We use it to instantiate the plugin class - """ - # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that - # holds the plugin class object - BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLocalFilesetWithRestoreObjects.BareosFdPluginLocalFilesetWithRestoreObjects( - context, plugindef - ) - return bareos_fd_consts.bRCs["bRC_OK"] - - -# the rest is done in the Plugin module diff --git a/systemtests/tests/py2plug-fd-postgres/testrunner b/systemtests/tests/py2plug-fd-postgres/testrunner index f96e54ca9a5..ae22a4ca594 100755 --- a/systemtests/tests/py2plug-fd-postgres/testrunner +++ b/systemtests/tests/py2plug-fd-postgres/testrunner @@ -41,11 +41,7 @@ CREATE TABLE t(id serial PRIMARY KEY, text VARCHAR(20), created_on TIMESTAMP); INSERT INTO t (text, created_on) values ('test for FULL backup', current_timestamp); SELECT * FROM t; " -<<<<<<< HEAD:systemtests/tests/pyplug-fd-postgres/testrunner PSQL_VERSION=$(${PSQL} -qtAX ${DBNAME} <<< "SHOW server_version;" | sed 's/\..*//g') -======= -PSQL_VERSION=$(${PSQL} -qtAX ${DBNAME} <<< "SHOW server_version;") ->>>>>>> d3ff81156... fix postgres to also work on psql 12:systemtests/tests/python-fd-plugin-postgres-test/testrunner start_test @@ -87,11 +83,7 @@ pushd database/ > /dev/null local_db_stop_server "$TESTPGHOST" rm -Rf data rm -Rf wal_archive -<<<<<<< HEAD:systemtests/tests/pyplug-fd-postgres/testrunner -======= echo "------------ stopped" - ->>>>>>> d3ff81156... fix postgres to also work on psql 12:systemtests/tests/python-fd-plugin-postgres-test/testrunner popd > /dev/null cat <$tmp/bconcmds From fb7d62e42af7c00ded9839849a990e8114a5e670 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 17 Aug 2020 18:31:53 +0200 Subject: [PATCH 233/341] python plugins: py2plug-fd-local-fileset works --- core/src/plugins/filed/python/CMakeLists.txt | 4 +- .../BareosFdPluginLocalFileset.py | 57 ++++++++++--------- .../python-modules/bareos-fd-local-fileset.py | 11 ++-- 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index c1f80ac25ed..844e33e18c9 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -111,12 +111,12 @@ if(Python2_FOUND) endif() target_link_libraries(bareosfd-python2-module bareos ${Python2_LIBRARIES}) - add_test(NAME bareosfd-python-module + add_test(NAME bareosfd-python2-module COMMAND ${Python2_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/bareosfd_test.py ) set_property( - TEST bareosfd-python-module + TEST bareosfd-python2-module PROPERTY ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/pythonmodules:${CMAKE_CURRENT_SOURCE_DIR}/test" diff --git a/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py index dd576049aff..f8c7ac861a8 100644 --- a/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py +++ b/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py @@ -171,7 +171,7 @@ def start_backup_file(self, savepkt): bareosfd.DebugMessage(100, "No files to backup\n") return bareosfd.bRC_Skip - self.file_to_backup = self.files_to_backup.pop().decode("string_escape") + self.file_to_backup = self.files_to_backup.pop() bareosfd.DebugMessage(100, "file: " + self.file_to_backup + "\n") mystatp = bareosfd.StatPacket() @@ -184,33 +184,36 @@ def start_backup_file(self, savepkt): bareosfd.JobMessage( bareosfd.M_ERROR, 'Could net get stat-info for file %s: "%s"' - % (self.file_to_backup, e.message), + % (self.file_to_backup, e), ) # As of Bareos 19.2.7 attribute names in bareosfd.StatPacket differ from os.stat # In this case we have to translate names # For future releases consistent names are planned, allowing to assign the # complete stat object in one rush - if hasattr(mystatp, "st_uid"): - mystatp = statp - else: - mystatp.mode = statp.st_mode - mystatp.ino = statp.st_ino - mystatp.dev = statp.st_dev - mystatp.nlink = statp.st_nlink - mystatp.uid = statp.st_uid - mystatp.gid = statp.st_gid - mystatp.size = statp.st_size - mystatp.atime = statp.st_atime - mystatp.mtime = statp.st_mtime - mystatp.ctime = statp.st_ctime - savepkt.fname = self.file_to_backup.encode("string_escape") + # if hasattr(mystatp, "st_uid"): + # mystatp = statp + # else: + + mystatp.st_mode = statp.st_mode + mystatp.st_ino = statp.st_ino + mystatp.st_dev = statp.st_dev + mystatp.st_nlink = statp.st_nlink + mystatp.st_uid = statp.st_uid + mystatp.st_gid = statp.st_gid + mystatp.st_size = statp.st_size + mystatp.st_atime = statp.st_atime + mystatp.st_mtime = statp.st_mtime + mystatp.st_ctime = statp.st_ctime + bareosfd.JobMessage( bareosfd.M_ERROR, '\nmystatp: %s\nstatp: %s\n' % (mystatp,statp)) + + savepkt.fname = self.file_to_backup # os.islink will detect links to directories only when # there is no trailing slash - we need to perform checks # on the stripped name but use it with trailing / for the backup itself if os.path.islink(self.file_to_backup.rstrip("/")): savepkt.type = bareosfd.FT_LNK savepkt.link = os.readlink( - self.file_to_backup.rstrip("/").encode("string_escape") + self.file_to_backup.rstrip("/") ) bareosfd.DebugMessage(150, "file type is: FT_LNK\n") elif os.path.isfile(self.file_to_backup): @@ -247,7 +250,7 @@ def create_file(self, restorepkt): 100, "create_file() entry point in Python called with %s\n" % (restorepkt), ) - FNAME = restorepkt.ofname.decode("string_escape") + FNAME = restorepkt.ofname if not FNAME: return bareosfd.bRC_Error dirname = os.path.dirname(FNAME.rstrip("/")) @@ -263,14 +266,14 @@ def create_file(self, restorepkt): restorepkt.create_status = bareosfd.CF_EXTRACT elif restorepkt.type == bareosfd.FT_LNK: linkNameEnc = restorepkt.olname - linkNameClear = linkNameEnc.decode("string_escape") + linkNameClear = linkNameEnc if not os.path.islink(FNAME.rstrip("/")): # if not os.path.exists(linkNameClear): os.symlink(linkNameClear, FNAME.rstrip("/")) restorepkt.create_status = bareosfd.CF_CREATED elif restorepkt.type == bareosfd.FT_LNKSAVED: linkNameEnc = restorepkt.olname - linkNameClear = linkNameEnc.decode("string_escape") + linkNameClear = linkNameEnc if not os.path.exists(linkNameClear): os.link(linkNameClear, FNAME.rstrip("/")) restorepkt.create_status = bareosfd.CF_CREATED @@ -285,7 +288,7 @@ def create_file(self, restorepkt): except Exception as e: bareosfd.JobMessage( bareosfd.M_ERROR, - 'Could net create fifo %s: "%s"' % (FNAME, e.message), + 'Could net create fifo %s: "%s"' % (FNAME, e), ) restorepkt.create_status = bareosfd.CF_CREATED else: @@ -308,7 +311,7 @@ def set_file_attributes(self, restorepkt): # Python attribute setting does not work properly with links # if restorepkt.type in [bareosfd.FT_LNK,bareosfd.FT_LNKSAVED]: # return bareosfd.bRC_OK - file_name = restorepkt.ofname.decode("string_escape") + file_name = restorepkt.ofname file_attr = restorepkt.statp self.statp[file_name] = file_attr @@ -317,9 +320,9 @@ def set_file_attributes(self, restorepkt): "Set file attributes " + file_name + " with stat " + str(file_attr) + "\n", ) try: - os.chown(file_name, file_attr.uid, file_attr.gid) - os.chmod(file_name, file_attr.mode) - os.utime(file_name, (file_attr.atime, file_attr.mtime)) + os.chown(file_name, file_attr.st_uid, file_attr.st_gid) + os.chmod(file_name, file_attr.st_mode) + os.utime(file_name, (file_attr.st_atime, file_attr.st_mtime)) newStat = os.stat(file_name) bareosfd.DebugMessage( 150, @@ -333,7 +336,7 @@ def set_file_attributes(self, restorepkt): except Exception as e: bareosfd.JobMessage( bareosfd.M_WARNING, - 'Could net set attributes for file %s: "%s"' % (file_name, e.message), + 'Could net set attributes for file %s: "%s"' % (file_name, e), ) return bareosfd.bRC_OK @@ -363,7 +366,7 @@ def end_restore_file(self): except Exception as e: bareosfd.JobMessage( bareosfd.M_WARNING, - 'Could net set attributes for file %s: "%s"' % (self.FNAME, e.message), + 'Could net set attributes for file %s: "%s"' % (self.FNAME, e), ) return bareosfd.bRC_OK diff --git a/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py index 44d84a92d87..1ac499f6457 100644 --- a/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py +++ b/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # BAREOS - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2014-2014 Bareos GmbH & Co. KG +# Copyright (C) 2014-2020 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -27,20 +27,19 @@ # # Provided by the Bareos FD Python plugin interface -import bareos_fd_consts +import bareosfd # This module contains the wrapper functions called by the Bareos-FD, the # functions call the corresponding methods from your plugin class import BareosFdWrapper -# from BareosFdWrapper import parse_plugin_definition, handle_plugin_event, start_backup_file, end_backup_file, start_restore_file, end_restore_file, restore_object_data, plugin_io, create_file, check_file, handle_backup_file # noqa from BareosFdWrapper import * # noqa # This module contains the used plugin class import BareosFdPluginLocalFileset -def load_bareos_plugin(context, plugindef): +def load_bareos_plugin(gcplugindef): """ This function is called by the Bareos-FD to load the plugin We use it to instantiate the plugin class @@ -48,9 +47,9 @@ def load_bareos_plugin(context, plugindef): # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that # holds the plugin class object BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLocalFileset.BareosFdPluginLocalFileset( - context, plugindef + gcplugindef ) - return bareos_fd_consts.bRCs["bRC_OK"] + return bareosfd.bRC_OK # the rest is done in the Plugin module From de9e8a7abd2b12c726f3a7dfd87582fe9dc833eb Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 17 Aug 2020 18:44:18 +0200 Subject: [PATCH 234/341] python systemtest: py2 local-fileset works --- .../python-modules/BareosFdPluginLocalFileset.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py index f8c7ac861a8..f147345f128 100644 --- a/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py +++ b/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py @@ -204,7 +204,7 @@ def start_backup_file(self, savepkt): mystatp.st_atime = statp.st_atime mystatp.st_mtime = statp.st_mtime mystatp.st_ctime = statp.st_ctime - bareosfd.JobMessage( bareosfd.M_ERROR, '\nmystatp: %s\nstatp: %s\n' % (mystatp,statp)) + #bareosfd.JobMessage( bareosfd.M_ERROR, '\nmystatp: %s\nstatp: %s\n' % (mystatp,statp)) savepkt.fname = self.file_to_backup # os.islink will detect links to directories only when @@ -355,10 +355,10 @@ def end_restore_file(self): + "\n", ) try: - os.chown(self.FNAME, self.statp[self.FNAME].uid, self.statp[self.FNAME].gid) - os.chmod(self.FNAME, self.statp[self.FNAME].mode) + os.chown(self.FNAME, self.statp[self.FNAME].st_uid, self.statp[self.FNAME].st_gid) + os.chmod(self.FNAME, self.statp[self.FNAME].st_mode) os.utime( - self.FNAME, (self.statp[self.FNAME].atime, self.statp[self.FNAME].mtime) + self.FNAME, (self.statp[self.FNAME].st_atime, self.statp[self.FNAME].st_mtime) ) # del sometimes leads to no-key errors, it seams that end_restore_file is sometimes called # multipl times. From 9c866b4e9ff381fbd82ca8b17b4b781ca821f5f6 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 17 Aug 2020 18:46:26 +0200 Subject: [PATCH 235/341] systemtest: py3 local-fileset works --- .../python-modules/BareosFdPluginLocalFileset.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py index f147345f128..a109b5ab5c9 100644 --- a/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py +++ b/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py @@ -108,7 +108,7 @@ def start_backup_job(self): ) if os.path.exists(self.options["filename"]): try: - config_file = open(self.options["filename"], "rb") + config_file = open(self.options["filename"], "r") except: bareosfd.DebugMessage( 100, @@ -134,7 +134,7 @@ def start_backup_job(self): if os.path.isdir(listItem): fullDirName = listItem # FD requires / at the end of a directory name - if not fullDirName.endswith("/"): + if not fullDirName.endswith(tuple("/")): fullDirName += "/" self.append_file_to_backup(fullDirName) for topdir, dirNames, fileNames in os.walk(listItem): From 687a11f3f95a34d0f9b6069389dc9c2b79805748 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 17 Aug 2020 19:05:51 +0200 Subject: [PATCH 236/341] mysqlf.conf.in: use Plugin Names = @python_module_name@ --- .../etc/bareos/bareos-fd.d/client/myself.conf.in | 2 +- .../etc/bareos/bareos-fd.d/client/myself.conf.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-fd.d/client/myself.conf.in index 49039c29d18..3a7cce9488e 100644 --- a/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-fd.d/client/myself.conf.in +++ b/systemtests/tests/py2plug-fd-postgres/etc/bareos/bareos-fd.d/client/myself.conf.in @@ -7,7 +7,7 @@ Client { # otherwise all filedaemon plugins (*-fd.so) from the "Plugin Directory". # Plugin Directory = "@fd_plugin_binary_path@" - Plugin Names = "python" + Plugin Names = "@python_module_name@" # if compatible is set to yes, we are compatible with bacula # if set to no, new bareos features are enabled which is the default diff --git a/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-fd.d/client/myself.conf.in index 49039c29d18..3a7cce9488e 100644 --- a/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-fd.d/client/myself.conf.in +++ b/systemtests/tests/py2plug-fd-vmware/etc/bareos/bareos-fd.d/client/myself.conf.in @@ -7,7 +7,7 @@ Client { # otherwise all filedaemon plugins (*-fd.so) from the "Plugin Directory". # Plugin Directory = "@fd_plugin_binary_path@" - Plugin Names = "python" + Plugin Names = "@python_module_name@" # if compatible is set to yes, we are compatible with bacula # if set to no, new bareos features are enabled which is the default From 4d9132d4ae8845584852409136460b912df26178 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 18 Aug 2020 13:03:51 +0200 Subject: [PATCH 237/341] cmake: enhance check_pymodule_available to support python 2 and 3 --- core/cmake/BareosFindAllLibraries.cmake | 2 + systemtests/CMakeLists.txt | 54 ++++++++++++------- .../BareosFdPluginLocalFileset.py | 1 + 3 files changed, 39 insertions(+), 18 deletions(-) create mode 120000 systemtests/tests/py2plug-fd-postgres/python-modules/BareosFdPluginLocalFileset.py diff --git a/core/cmake/BareosFindAllLibraries.cmake b/core/cmake/BareosFindAllLibraries.cmake index 4788dac155e..e64e2d73070 100644 --- a/core/cmake/BareosFindAllLibraries.cmake +++ b/core/cmake/BareosFindAllLibraries.cmake @@ -72,6 +72,7 @@ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") if(${Python2_FOUND}) set(PYTHON_EXECUTABLE ${Python2_EXECUTABLE} PARENT_SCOPE) + set(Python2_EXECUTABLE ${Python2_EXECUTABLE} PARENT_SCOPE) execute_process( COMMAND ${Python2_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/get_python_compile_settings.py OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/py2settings.cmake @@ -81,6 +82,7 @@ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") if(${Python3_FOUND}) set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE} PARENT_SCOPE) + set(Python3_EXECUTABLE ${Python3_EXECUTABLE} PARENT_SCOPE) execute_process( COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/get_python_compile_settings.py OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/py3settings.cmake diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 2f94645cc66..9e96a58151a 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -101,29 +101,40 @@ function(ConfigureFilesToSystemtest srcbasedir dirname globexpression endforeach() endfunction() -# generic function to probe for a python module -function(check_pymodule_available module) - if(NOT PYTHON_EXECUTABLE) - message(FATAL_ERROR "PYTHON_EXECUTABLE ist not set") +# generic function to probe for a python module for the given python version (2 +# or 3) +function(check_pymodule_available python_version module) + if(NOT python_version) + message(FATAL_ERROR "python_version ist not set") endif() + if(${python_version} EQUAL 2) + set(python_exe ${Python2_EXECUTABLE}) + elseif(${python_version} EQUAL 3) + set(python_exe ${Python3_EXECUTABLE}) + else() + message(FATAL_ERROR "unsupported python_version ${python_version}") + endif() + # message(STATUS "running ${python_exe} -c import ${module}") execute_process( - COMMAND "${PYTHON_EXECUTABLE}" "-c" "import ${module}" + COMMAND "${python_exe}" "-c" "import ${module}" RESULT_VARIABLE ${module}_status ERROR_QUIET ) string(TOUPPER ${module} module_uppercase) if(${module}_status EQUAL 0) - set("PYMODULE_${module_uppercase}_FOUND" + set("PYMODULE_${python_version}_${module_uppercase}_FOUND" TRUE PARENT_SCOPE ) - message(STATUS "python module ${module} found") + message(STATUS "python module pyversion ${python_version} ${module} found") else() - set("PYMODULE_${module_uppercase}_FOUND" + set("PYMODULE_${python_version}_${module_uppercase}_FOUND" FALSE PARENT_SCOPE ) - message(STATUS "python module ${module} NOT found") + message( + STATUS "python module pyversion ${python_version} ${module} NOT found" + ) endif() endfunction() @@ -661,12 +672,11 @@ else() endif() message("checking for requirements of py2plug-fd-postgres:") -check_pymodule_available("psycopg2") -check_pymodule_available("dateutil") - +check_pymodule_available(2 psycopg2) +check_pymodule_available(2 dateutil) if(TARGET python-fd - AND PYMODULE_PSYCOPG2_FOUND - AND PYMODULE_DATEUTIL_FOUND + AND PYMODULE_2_PSYCOPG2_FOUND + AND PYMODULE_2_DATEUTIL_FOUND ) message("OK, enabling py2plug-fd-postgres:") list(APPEND SYSTEM_TESTS "py2plug-fd-postgres") @@ -674,7 +684,14 @@ else() list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-postgres") message("NOT OK, disabling py2plug-fd-postgres:") endif() -if(TARGET python3-fd) + +message("checking for requirements of py3plug-fd-postgres:") +check_pymodule_available(3 psycopg2) +check_pymodule_available(3 dateutil) +if(TARGET python-fd + AND PYMODULE_3_PSYCOPG2_FOUND + AND PYMODULE_3_DATEUTIL_FOUND +) list(APPEND SYSTEM_TESTS "py3plug-fd-postgres") else() list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-postgres") @@ -803,17 +820,18 @@ message(STATUS "Looking for webui test requirements ...") find_program(PHP php) find_program(CHROMEDRIVER chromedriver) -check_pymodule_available("selenium") # sets PYMODULE_SELENIUM_FOUND to TRUE or +check_pymodule_available(2 selenium) # sets PYMODULE_2_SELENIUM_FOUND to TRUE or +check_pymodule_available(3 selenium) # sets PYMODULE_3_SELENIUM_FOUND to TRUE or # FALSE message(" PHP: " ${PHP}) message(" PYTHON_EXECUTABLE: " ${PYTHON_EXECUTABLE}) -message(" PYMODULE_SELENIUM_FOUND:" ${PYMOD_SELENIUM_FOUND}) +message(" PYMODULE_2_SELENIUM_FOUND:" ${PYMODULE_2_SELENIUM_FOUND}) message(" CHROMEDRIVER: " ${CHROMEDRIVER}) if(PHP AND PYTHON_EXECUTABLE - AND PYMODULE_SELENIUM_FOUND + AND PYMODULE_2_SELENIUM_FOUND AND CHROMEDRIVER ) set(ENABLE_WEBUI_SELENIUM_TEST TRUE) diff --git a/systemtests/tests/py2plug-fd-postgres/python-modules/BareosFdPluginLocalFileset.py b/systemtests/tests/py2plug-fd-postgres/python-modules/BareosFdPluginLocalFileset.py new file mode 120000 index 00000000000..def88b18df5 --- /dev/null +++ b/systemtests/tests/py2plug-fd-postgres/python-modules/BareosFdPluginLocalFileset.py @@ -0,0 +1 @@ +../../py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py \ No newline at end of file From dc23f456f59ee1bb7d378eabc6920f72620c39f8 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 18 Aug 2020 18:09:58 +0200 Subject: [PATCH 238/341] systemtests: fix percona test --- .../mysqldefaults.in | 0 systemtests/tests/py2plug-fd-percona-xtrabackup/testrunner | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename systemtests/tests/{py2plug-fd-local-fileset-restoreobject => py2plug-fd-percona-xtrabackup}/mysqldefaults.in (100%) diff --git a/systemtests/tests/py2plug-fd-local-fileset-restoreobject/mysqldefaults.in b/systemtests/tests/py2plug-fd-percona-xtrabackup/mysqldefaults.in similarity index 100% rename from systemtests/tests/py2plug-fd-local-fileset-restoreobject/mysqldefaults.in rename to systemtests/tests/py2plug-fd-percona-xtrabackup/mysqldefaults.in diff --git a/systemtests/tests/py2plug-fd-percona-xtrabackup/testrunner b/systemtests/tests/py2plug-fd-percona-xtrabackup/testrunner index 7d081747787..75074fd468c 100755 --- a/systemtests/tests/py2plug-fd-percona-xtrabackup/testrunner +++ b/systemtests/tests/py2plug-fd-percona-xtrabackup/testrunner @@ -26,10 +26,10 @@ JobName=backup-bareos-fd rm -Rf mysql/data/* mkdir -p mysql/data/ # initialize mysql db -mysqld --defaults-file=mysqldefaults --user=pstorz --initialize-insecure > mysql/mysql_init.log 2>&1 +mysql_install_db --user="$USER" --defaults-file=mysqldefaults > mysql/mysql_init.log # start mysql server -mysqld --defaults-file=mysqldefaults >mysql/mysql.log 2>&1 & +mysqld_safe --defaults-file=mysqldefaults >mysql/mysql.log 2>&1 & sleep 4 From 717874a74396ab934f2c5d658bb329dbaf16b185 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 19 Aug 2020 13:51:50 +0200 Subject: [PATCH 239/341] pretest: try to connect to configured database types --- systemtests/ctest_custom_pretest.sh.in | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/systemtests/ctest_custom_pretest.sh.in b/systemtests/ctest_custom_pretest.sh.in index 3511b3dbbaf..3af6e5059fd 100755 --- a/systemtests/ctest_custom_pretest.sh.in +++ b/systemtests/ctest_custom_pretest.sh.in @@ -8,6 +8,29 @@ if ! @BAREOS_DIR_TO_TEST@ -? 2>&1 | grep Version >/dev/null; then echo "PRETEST: ERROR: could not start director. Forgot to build before testing?" exit 1 fi + +postgresql=@postgresql@ +if [ -n "$postgresql" ]; then + echo -n "PRETEST: checking postgresql connection ..." + if ! psql <<< "SELECT version()" 2>&1 >/dev/null; then + echo "could not connect postgresql server" + exit 1 + else + echo "OK" + fi +fi + +mysql=@mysql@ +if [ -n "$mysql" ]; then + echo -n "PRETEST: checking mysql connection ..." + if ! mysql <<< "SELECT version()" 2>&1 >/dev/null; then + echo "could not connect mysql server" + exit 1 + else + echo "OK" + fi +fi + nr_killed=0 for pidfile in $(find . -name bareos-\*.pid); do ((nr_killed=nr_killed+1)) From e6fa445f07300dc441a1e9053db8a3bc46164c80 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 20 Aug 2020 12:39:35 +0200 Subject: [PATCH 240/341] python: move bareos fd local fileset files to pyfiles --- core/src/plugins/filed/python/CMakeLists.txt | 2 + .../pyfiles/BareosFdPluginLocalFileset.py | 387 +++++++++++++++++ .../python/pyfiles/bareos-fd-local-fileset.py | 55 +++ .../BareosFdPluginLocalFileset.py | 388 +----------------- .../python-modules/bareos-fd-local-fileset.py | 56 +-- 5 files changed, 446 insertions(+), 442 deletions(-) create mode 100644 core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py create mode 100644 core/src/plugins/filed/python/pyfiles/bareos-fd-local-fileset.py mode change 100644 => 120000 systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py mode change 100644 => 120000 systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 844e33e18c9..b0c8de2e4e8 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -165,6 +165,8 @@ set(PYFILES pyfiles/bareos-fd-mock-test.py pyfiles/BareosFdPluginBaseclass.py pyfiles/BareosFdWrapper.py + pyfiles/BareosFdPluginLocalFileset.py + pyfiles/bareos-fd-local-fileset.py ldap/bareos-fd-ldap.py ldap/BareosFdPluginLDAP.py ovirt/bareos-fd-ovirt.py diff --git a/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py b/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py new file mode 100644 index 00000000000..a109b5ab5c9 --- /dev/null +++ b/core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py @@ -0,0 +1,387 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# BAREOS - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2014-2020 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation, which is +# listed in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# Author: Maik Aussendorf +# +# Bareos python plugins class that adds files from a local list to +# the backup fileset + +import bareosfd +import os +import re +import BareosFdPluginBaseclass +import stat + + +class BareosFdPluginLocalFileset( + BareosFdPluginBaseclass.BareosFdPluginBaseclass +): # noqa + """ + Simple Bareos-FD-Plugin-Class that parses a file and backups all files + listed there Filename is taken from plugin argument 'filename' + """ + + def __init__(self, plugindef, mandatory_options=None): + bareosfd.DebugMessage( + 100, + "Constructor called in module %s with plugindef=%s\n" + % (__name__, plugindef), + ) + if mandatory_options is None: + mandatory_options = ["filename"] + # Last argument of super constructor is a list of mandatory arguments + super(BareosFdPluginLocalFileset, self).__init__( + plugindef, mandatory_options + ) + self.files_to_backup = [] + self.file_to_backup = "" + # We need to get the stat-packet in set_file_attributes + # and use it again in end_restore_file, and this may be mixed up + # with different files + self.statp = {} + self.allow = None + self.deny = None + + def filename_is_allowed(self, filename, allowregex, denyregex): + """ + Check, if filename is allowed. + True, if matches allowreg and not denyregex. + If allowreg is None, filename always matches + If denyreg is None, it never matches + """ + if allowregex is None or allowregex.search(filename): + allowed = True + else: + allowed = False + if denyregex is None or not denyregex.search(filename): + denied = False + else: + denied = True + if not allowed or denied: + bareosfd.DebugMessage( + 100, "File %s denied by configuration\n" % (filename) + ) + bareosfd.JobMessage( + bareosfd.M_ERROR, + "File %s denied by configuration\n" % (filename), + ) + return False + else: + return True + + def append_file_to_backup(self, filename): + """ + Basically add filename to list of files to backup in + files_to_backup + Overload this, if you want to check for extra stuff + of do other things with files to backup + """ + self.files_to_backup.append(filename) + + def start_backup_job(self): + """ + At this point, plugin options were passed and checked already. + We try to read from filename and setup the list of file to backup + in self.files_to_backup + """ + bareosfd.DebugMessage( + 100, + "Using %s to search for local files\n" % self.options["filename"], + ) + if os.path.exists(self.options["filename"]): + try: + config_file = open(self.options["filename"], "r") + except: + bareosfd.DebugMessage( + 100, + "Could not open file %s\n" % (self.options["filename"]), + ) + return bareosfd.bRC_Error + else: + bareosfd.DebugMessage( + 100, "File %s does not exist\n" % (self.options["filename"]) + ) + return bareosfd.bRC_Error + # Check, if we have allow or deny regular expressions defined + if "allow" in self.options: + self.allow = re.compile(self.options["allow"]) + if "deny" in self.options: + self.deny = re.compile(self.options["deny"]) + + for listItem in config_file.read().splitlines(): + if os.path.isfile(listItem) and self.filename_is_allowed( + listItem, self.allow, self.deny + ): + self.append_file_to_backup(listItem) + if os.path.isdir(listItem): + fullDirName = listItem + # FD requires / at the end of a directory name + if not fullDirName.endswith(tuple("/")): + fullDirName += "/" + self.append_file_to_backup(fullDirName) + for topdir, dirNames, fileNames in os.walk(listItem): + for fileName in fileNames: + if self.filename_is_allowed( + os.path.join(topdir, fileName), + self.allow, + self.deny, + ): + self.append_file_to_backup( + os.path.join(topdir, fileName) + ) + for dirName in dirNames: + fullDirName = os.path.join(topdir, dirName) + "/" + self.append_file_to_backup(fullDirName) + bareosfd.DebugMessage(150, "Filelist: %s\n" % (self.files_to_backup)) + + if not self.files_to_backup: + bareosfd.JobMessage( + bareosfd.M_ERROR, + "No (allowed) files to backup found\n", + ) + return bareosfd.bRC_Error + else: + return bareosfd.bRC_OK + + def start_backup_file(self, savepkt): + """ + Defines the file to backup and creates the savepkt. In this example + only files (no directories) are allowed + """ + bareosfd.DebugMessage(100, "start_backup_file() called\n") + if not self.files_to_backup: + bareosfd.DebugMessage(100, "No files to backup\n") + return bareosfd.bRC_Skip + + self.file_to_backup = self.files_to_backup.pop() + bareosfd.DebugMessage(100, "file: " + self.file_to_backup + "\n") + + mystatp = bareosfd.StatPacket() + try: + if os.path.islink(self.file_to_backup): + statp = os.lstat(self.file_to_backup) + else: + statp = os.stat(self.file_to_backup) + except Exception as e: + bareosfd.JobMessage( + bareosfd.M_ERROR, + 'Could net get stat-info for file %s: "%s"' + % (self.file_to_backup, e), + ) + # As of Bareos 19.2.7 attribute names in bareosfd.StatPacket differ from os.stat + # In this case we have to translate names + # For future releases consistent names are planned, allowing to assign the + # complete stat object in one rush + # if hasattr(mystatp, "st_uid"): + # mystatp = statp + # else: + + mystatp.st_mode = statp.st_mode + mystatp.st_ino = statp.st_ino + mystatp.st_dev = statp.st_dev + mystatp.st_nlink = statp.st_nlink + mystatp.st_uid = statp.st_uid + mystatp.st_gid = statp.st_gid + mystatp.st_size = statp.st_size + mystatp.st_atime = statp.st_atime + mystatp.st_mtime = statp.st_mtime + mystatp.st_ctime = statp.st_ctime + #bareosfd.JobMessage( bareosfd.M_ERROR, '\nmystatp: %s\nstatp: %s\n' % (mystatp,statp)) + + savepkt.fname = self.file_to_backup + # os.islink will detect links to directories only when + # there is no trailing slash - we need to perform checks + # on the stripped name but use it with trailing / for the backup itself + if os.path.islink(self.file_to_backup.rstrip("/")): + savepkt.type = bareosfd.FT_LNK + savepkt.link = os.readlink( + self.file_to_backup.rstrip("/") + ) + bareosfd.DebugMessage(150, "file type is: FT_LNK\n") + elif os.path.isfile(self.file_to_backup): + savepkt.type = bareosfd.FT_REG + bareosfd.DebugMessage(150, "file type is: FT_REG\n") + elif os.path.isdir(self.file_to_backup): + savepkt.type = bareosfd.FT_DIREND + savepkt.link = self.file_to_backup + bareosfd.DebugMessage( + 150, "file %s type is: FT_DIREND\n" % self.file_to_backup + ) + elif stat.S_ISFIFO(os.stat(self.file_to_backup).st_mode): + savepkt.type = bareosfd.FT_FIFO + bareosfd.DebugMessage(150, "file type is: FT_FIFO\n") + else: + bareosfd.JobMessage( + bareosfd.M_WARNING, + "File %s of unknown type" % (self.file_to_backup), + ) + return bareosfd.bRC_Skip + + savepkt.statp = mystatp + bareosfd.DebugMessage(150, "file statpx " + str(savepkt.statp) + "\n") + + return bareosfd.bRC_OK + + def create_file(self, restorepkt): + """ + Creates the file to be restored and directory structure, if needed. + Adapt this in your derived class, if you need modifications for + virtual files or similar + """ + bareosfd.DebugMessage( + 100, + "create_file() entry point in Python called with %s\n" % (restorepkt), + ) + FNAME = restorepkt.ofname + if not FNAME: + return bareosfd.bRC_Error + dirname = os.path.dirname(FNAME.rstrip("/")) + if not os.path.exists(dirname): + bareosfd.DebugMessage( + 200, "Directory %s does not exist, creating it now\n" % dirname + ) + os.makedirs(dirname) + # open creates the file, if not yet existing, we close it again right + # aways it will be opened again in plugin_io. + if restorepkt.type == bareosfd.FT_REG: + open(FNAME, "wb").close() + restorepkt.create_status = bareosfd.CF_EXTRACT + elif restorepkt.type == bareosfd.FT_LNK: + linkNameEnc = restorepkt.olname + linkNameClear = linkNameEnc + if not os.path.islink(FNAME.rstrip("/")): + # if not os.path.exists(linkNameClear): + os.symlink(linkNameClear, FNAME.rstrip("/")) + restorepkt.create_status = bareosfd.CF_CREATED + elif restorepkt.type == bareosfd.FT_LNKSAVED: + linkNameEnc = restorepkt.olname + linkNameClear = linkNameEnc + if not os.path.exists(linkNameClear): + os.link(linkNameClear, FNAME.rstrip("/")) + restorepkt.create_status = bareosfd.CF_CREATED + elif restorepkt.type == bareosfd.FT_DIREND: + if not os.path.exists(FNAME): + os.makedirs(FNAME) + restorepkt.create_status = bareosfd.CF_CREATED + elif restorepkt.type == bareosfd.FT_FIFO: + if not os.path.exists(FNAME): + try: + os.mkfifo(FNAME, 0o600) + except Exception as e: + bareosfd.JobMessage( + bareosfd.M_ERROR, + 'Could net create fifo %s: "%s"' % (FNAME, e), + ) + restorepkt.create_status = bareosfd.CF_CREATED + else: + bareosfd.JobMessage( + bareosfd.M_ERROR, + "Unknown type %s of file %s" % (restorepkt.type, FNAME), + ) + return bareosfd.bRC_OK + + def set_file_attributes(self, restorepkt): + """ + Need to verify: we set attributes here but on plugin_io close + the mtime will be modified again. + approach: save stat-packet here and set it on + end_restore_file + """ + # restorepkt.create_status = bareosfd.CF_CORE + # return bareosfd.bRC_OK + + # Python attribute setting does not work properly with links + # if restorepkt.type in [bareosfd.FT_LNK,bareosfd.FT_LNKSAVED]: + # return bareosfd.bRC_OK + file_name = restorepkt.ofname + file_attr = restorepkt.statp + self.statp[file_name] = file_attr + + bareosfd.DebugMessage( + 150, + "Set file attributes " + file_name + " with stat " + str(file_attr) + "\n", + ) + try: + os.chown(file_name, file_attr.st_uid, file_attr.st_gid) + os.chmod(file_name, file_attr.st_mode) + os.utime(file_name, (file_attr.st_atime, file_attr.st_mtime)) + newStat = os.stat(file_name) + bareosfd.DebugMessage( + 150, + "Verified file attributes " + + file_name + + " with stat " + + str(newStat) + + "\n", + ) + + except Exception as e: + bareosfd.JobMessage( + bareosfd.M_WARNING, + 'Could net set attributes for file %s: "%s"' % (file_name, e), + ) + + return bareosfd.bRC_OK + + def end_restore_file(self): + bareosfd.DebugMessage( + 100, + "end_restore_file() entry point in Python called FNAME: %s\n" % self.FNAME, + ) + bareosfd.DebugMessage( + 150, + "end_restore_file set file attributes " + + self.FNAME + + " with stat " + + str(self.statp[self.FNAME]) + + "\n", + ) + try: + os.chown(self.FNAME, self.statp[self.FNAME].st_uid, self.statp[self.FNAME].st_gid) + os.chmod(self.FNAME, self.statp[self.FNAME].st_mode) + os.utime( + self.FNAME, (self.statp[self.FNAME].st_atime, self.statp[self.FNAME].st_mtime) + ) + # del sometimes leads to no-key errors, it seams that end_restore_file is sometimes called + # multipl times. + # del self.statp[self.FNAME] + except Exception as e: + bareosfd.JobMessage( + bareosfd.M_WARNING, + 'Could net set attributes for file %s: "%s"' % (self.FNAME, e), + ) + return bareosfd.bRC_OK + + def end_backup_file(self): + """ + Here we return 'bRC_More' as long as our list files_to_backup is not + empty and bRC_OK when we are done + """ + bareosfd.DebugMessage( + 100, "end_backup_file() entry point in Python called\n" + ) + if self.files_to_backup: + return bareosfd.bRC_More + else: + return bareosfd.bRC_OK + + +# vim: ts=4 tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/core/src/plugins/filed/python/pyfiles/bareos-fd-local-fileset.py b/core/src/plugins/filed/python/pyfiles/bareos-fd-local-fileset.py new file mode 100644 index 00000000000..1ac499f6457 --- /dev/null +++ b/core/src/plugins/filed/python/pyfiles/bareos-fd-local-fileset.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# BAREOS - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2014-2020 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation, which is +# listed in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# Bareos-fd-local-fileset a simple example for a python Bareos FD Plugin using +# BareosFdPluginLocalFileset. The plugin argument 'filename' is used to read +# all files listed in that file and add it to the fileset +# +# Author: Maik Aussendorf +# + +# Provided by the Bareos FD Python plugin interface +import bareosfd + +# This module contains the wrapper functions called by the Bareos-FD, the +# functions call the corresponding methods from your plugin class +import BareosFdWrapper + +from BareosFdWrapper import * # noqa + +# This module contains the used plugin class +import BareosFdPluginLocalFileset + + +def load_bareos_plugin(gcplugindef): + """ + This function is called by the Bareos-FD to load the plugin + We use it to instantiate the plugin class + """ + # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that + # holds the plugin class object + BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLocalFileset.BareosFdPluginLocalFileset( + gcplugindef + ) + return bareosfd.bRC_OK + + +# the rest is done in the Plugin module diff --git a/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py deleted file mode 100644 index a109b5ab5c9..00000000000 --- a/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py +++ /dev/null @@ -1,387 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# BAREOS - Backup Archiving REcovery Open Sourced -# -# Copyright (C) 2014-2020 Bareos GmbH & Co. KG -# -# This program is Free Software; you can redistribute it and/or -# modify it under the terms of version three of the GNU Affero General Public -# License as published by the Free Software Foundation, which is -# listed in the file LICENSE. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# Author: Maik Aussendorf -# -# Bareos python plugins class that adds files from a local list to -# the backup fileset - -import bareosfd -import os -import re -import BareosFdPluginBaseclass -import stat - - -class BareosFdPluginLocalFileset( - BareosFdPluginBaseclass.BareosFdPluginBaseclass -): # noqa - """ - Simple Bareos-FD-Plugin-Class that parses a file and backups all files - listed there Filename is taken from plugin argument 'filename' - """ - - def __init__(self, plugindef, mandatory_options=None): - bareosfd.DebugMessage( - 100, - "Constructor called in module %s with plugindef=%s\n" - % (__name__, plugindef), - ) - if mandatory_options is None: - mandatory_options = ["filename"] - # Last argument of super constructor is a list of mandatory arguments - super(BareosFdPluginLocalFileset, self).__init__( - plugindef, mandatory_options - ) - self.files_to_backup = [] - self.file_to_backup = "" - # We need to get the stat-packet in set_file_attributes - # and use it again in end_restore_file, and this may be mixed up - # with different files - self.statp = {} - self.allow = None - self.deny = None - - def filename_is_allowed(self, filename, allowregex, denyregex): - """ - Check, if filename is allowed. - True, if matches allowreg and not denyregex. - If allowreg is None, filename always matches - If denyreg is None, it never matches - """ - if allowregex is None or allowregex.search(filename): - allowed = True - else: - allowed = False - if denyregex is None or not denyregex.search(filename): - denied = False - else: - denied = True - if not allowed or denied: - bareosfd.DebugMessage( - 100, "File %s denied by configuration\n" % (filename) - ) - bareosfd.JobMessage( - bareosfd.M_ERROR, - "File %s denied by configuration\n" % (filename), - ) - return False - else: - return True - - def append_file_to_backup(self, filename): - """ - Basically add filename to list of files to backup in - files_to_backup - Overload this, if you want to check for extra stuff - of do other things with files to backup - """ - self.files_to_backup.append(filename) - - def start_backup_job(self): - """ - At this point, plugin options were passed and checked already. - We try to read from filename and setup the list of file to backup - in self.files_to_backup - """ - bareosfd.DebugMessage( - 100, - "Using %s to search for local files\n" % self.options["filename"], - ) - if os.path.exists(self.options["filename"]): - try: - config_file = open(self.options["filename"], "r") - except: - bareosfd.DebugMessage( - 100, - "Could not open file %s\n" % (self.options["filename"]), - ) - return bareosfd.bRC_Error - else: - bareosfd.DebugMessage( - 100, "File %s does not exist\n" % (self.options["filename"]) - ) - return bareosfd.bRC_Error - # Check, if we have allow or deny regular expressions defined - if "allow" in self.options: - self.allow = re.compile(self.options["allow"]) - if "deny" in self.options: - self.deny = re.compile(self.options["deny"]) - - for listItem in config_file.read().splitlines(): - if os.path.isfile(listItem) and self.filename_is_allowed( - listItem, self.allow, self.deny - ): - self.append_file_to_backup(listItem) - if os.path.isdir(listItem): - fullDirName = listItem - # FD requires / at the end of a directory name - if not fullDirName.endswith(tuple("/")): - fullDirName += "/" - self.append_file_to_backup(fullDirName) - for topdir, dirNames, fileNames in os.walk(listItem): - for fileName in fileNames: - if self.filename_is_allowed( - os.path.join(topdir, fileName), - self.allow, - self.deny, - ): - self.append_file_to_backup( - os.path.join(topdir, fileName) - ) - for dirName in dirNames: - fullDirName = os.path.join(topdir, dirName) + "/" - self.append_file_to_backup(fullDirName) - bareosfd.DebugMessage(150, "Filelist: %s\n" % (self.files_to_backup)) - - if not self.files_to_backup: - bareosfd.JobMessage( - bareosfd.M_ERROR, - "No (allowed) files to backup found\n", - ) - return bareosfd.bRC_Error - else: - return bareosfd.bRC_OK - - def start_backup_file(self, savepkt): - """ - Defines the file to backup and creates the savepkt. In this example - only files (no directories) are allowed - """ - bareosfd.DebugMessage(100, "start_backup_file() called\n") - if not self.files_to_backup: - bareosfd.DebugMessage(100, "No files to backup\n") - return bareosfd.bRC_Skip - - self.file_to_backup = self.files_to_backup.pop() - bareosfd.DebugMessage(100, "file: " + self.file_to_backup + "\n") - - mystatp = bareosfd.StatPacket() - try: - if os.path.islink(self.file_to_backup): - statp = os.lstat(self.file_to_backup) - else: - statp = os.stat(self.file_to_backup) - except Exception as e: - bareosfd.JobMessage( - bareosfd.M_ERROR, - 'Could net get stat-info for file %s: "%s"' - % (self.file_to_backup, e), - ) - # As of Bareos 19.2.7 attribute names in bareosfd.StatPacket differ from os.stat - # In this case we have to translate names - # For future releases consistent names are planned, allowing to assign the - # complete stat object in one rush - # if hasattr(mystatp, "st_uid"): - # mystatp = statp - # else: - - mystatp.st_mode = statp.st_mode - mystatp.st_ino = statp.st_ino - mystatp.st_dev = statp.st_dev - mystatp.st_nlink = statp.st_nlink - mystatp.st_uid = statp.st_uid - mystatp.st_gid = statp.st_gid - mystatp.st_size = statp.st_size - mystatp.st_atime = statp.st_atime - mystatp.st_mtime = statp.st_mtime - mystatp.st_ctime = statp.st_ctime - #bareosfd.JobMessage( bareosfd.M_ERROR, '\nmystatp: %s\nstatp: %s\n' % (mystatp,statp)) - - savepkt.fname = self.file_to_backup - # os.islink will detect links to directories only when - # there is no trailing slash - we need to perform checks - # on the stripped name but use it with trailing / for the backup itself - if os.path.islink(self.file_to_backup.rstrip("/")): - savepkt.type = bareosfd.FT_LNK - savepkt.link = os.readlink( - self.file_to_backup.rstrip("/") - ) - bareosfd.DebugMessage(150, "file type is: FT_LNK\n") - elif os.path.isfile(self.file_to_backup): - savepkt.type = bareosfd.FT_REG - bareosfd.DebugMessage(150, "file type is: FT_REG\n") - elif os.path.isdir(self.file_to_backup): - savepkt.type = bareosfd.FT_DIREND - savepkt.link = self.file_to_backup - bareosfd.DebugMessage( - 150, "file %s type is: FT_DIREND\n" % self.file_to_backup - ) - elif stat.S_ISFIFO(os.stat(self.file_to_backup).st_mode): - savepkt.type = bareosfd.FT_FIFO - bareosfd.DebugMessage(150, "file type is: FT_FIFO\n") - else: - bareosfd.JobMessage( - bareosfd.M_WARNING, - "File %s of unknown type" % (self.file_to_backup), - ) - return bareosfd.bRC_Skip - - savepkt.statp = mystatp - bareosfd.DebugMessage(150, "file statpx " + str(savepkt.statp) + "\n") - - return bareosfd.bRC_OK - - def create_file(self, restorepkt): - """ - Creates the file to be restored and directory structure, if needed. - Adapt this in your derived class, if you need modifications for - virtual files or similar - """ - bareosfd.DebugMessage( - 100, - "create_file() entry point in Python called with %s\n" % (restorepkt), - ) - FNAME = restorepkt.ofname - if not FNAME: - return bareosfd.bRC_Error - dirname = os.path.dirname(FNAME.rstrip("/")) - if not os.path.exists(dirname): - bareosfd.DebugMessage( - 200, "Directory %s does not exist, creating it now\n" % dirname - ) - os.makedirs(dirname) - # open creates the file, if not yet existing, we close it again right - # aways it will be opened again in plugin_io. - if restorepkt.type == bareosfd.FT_REG: - open(FNAME, "wb").close() - restorepkt.create_status = bareosfd.CF_EXTRACT - elif restorepkt.type == bareosfd.FT_LNK: - linkNameEnc = restorepkt.olname - linkNameClear = linkNameEnc - if not os.path.islink(FNAME.rstrip("/")): - # if not os.path.exists(linkNameClear): - os.symlink(linkNameClear, FNAME.rstrip("/")) - restorepkt.create_status = bareosfd.CF_CREATED - elif restorepkt.type == bareosfd.FT_LNKSAVED: - linkNameEnc = restorepkt.olname - linkNameClear = linkNameEnc - if not os.path.exists(linkNameClear): - os.link(linkNameClear, FNAME.rstrip("/")) - restorepkt.create_status = bareosfd.CF_CREATED - elif restorepkt.type == bareosfd.FT_DIREND: - if not os.path.exists(FNAME): - os.makedirs(FNAME) - restorepkt.create_status = bareosfd.CF_CREATED - elif restorepkt.type == bareosfd.FT_FIFO: - if not os.path.exists(FNAME): - try: - os.mkfifo(FNAME, 0o600) - except Exception as e: - bareosfd.JobMessage( - bareosfd.M_ERROR, - 'Could net create fifo %s: "%s"' % (FNAME, e), - ) - restorepkt.create_status = bareosfd.CF_CREATED - else: - bareosfd.JobMessage( - bareosfd.M_ERROR, - "Unknown type %s of file %s" % (restorepkt.type, FNAME), - ) - return bareosfd.bRC_OK - - def set_file_attributes(self, restorepkt): - """ - Need to verify: we set attributes here but on plugin_io close - the mtime will be modified again. - approach: save stat-packet here and set it on - end_restore_file - """ - # restorepkt.create_status = bareosfd.CF_CORE - # return bareosfd.bRC_OK - - # Python attribute setting does not work properly with links - # if restorepkt.type in [bareosfd.FT_LNK,bareosfd.FT_LNKSAVED]: - # return bareosfd.bRC_OK - file_name = restorepkt.ofname - file_attr = restorepkt.statp - self.statp[file_name] = file_attr - - bareosfd.DebugMessage( - 150, - "Set file attributes " + file_name + " with stat " + str(file_attr) + "\n", - ) - try: - os.chown(file_name, file_attr.st_uid, file_attr.st_gid) - os.chmod(file_name, file_attr.st_mode) - os.utime(file_name, (file_attr.st_atime, file_attr.st_mtime)) - newStat = os.stat(file_name) - bareosfd.DebugMessage( - 150, - "Verified file attributes " - + file_name - + " with stat " - + str(newStat) - + "\n", - ) - - except Exception as e: - bareosfd.JobMessage( - bareosfd.M_WARNING, - 'Could net set attributes for file %s: "%s"' % (file_name, e), - ) - - return bareosfd.bRC_OK - - def end_restore_file(self): - bareosfd.DebugMessage( - 100, - "end_restore_file() entry point in Python called FNAME: %s\n" % self.FNAME, - ) - bareosfd.DebugMessage( - 150, - "end_restore_file set file attributes " - + self.FNAME - + " with stat " - + str(self.statp[self.FNAME]) - + "\n", - ) - try: - os.chown(self.FNAME, self.statp[self.FNAME].st_uid, self.statp[self.FNAME].st_gid) - os.chmod(self.FNAME, self.statp[self.FNAME].st_mode) - os.utime( - self.FNAME, (self.statp[self.FNAME].st_atime, self.statp[self.FNAME].st_mtime) - ) - # del sometimes leads to no-key errors, it seams that end_restore_file is sometimes called - # multipl times. - # del self.statp[self.FNAME] - except Exception as e: - bareosfd.JobMessage( - bareosfd.M_WARNING, - 'Could net set attributes for file %s: "%s"' % (self.FNAME, e), - ) - return bareosfd.bRC_OK - - def end_backup_file(self): - """ - Here we return 'bRC_More' as long as our list files_to_backup is not - empty and bRC_OK when we are done - """ - bareosfd.DebugMessage( - 100, "end_backup_file() entry point in Python called\n" - ) - if self.files_to_backup: - return bareosfd.bRC_More - else: - return bareosfd.bRC_OK - - -# vim: ts=4 tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py new file mode 120000 index 00000000000..f3669bab53e --- /dev/null +++ b/systemtests/tests/py2plug-fd-local-fileset/python-modules/BareosFdPluginLocalFileset.py @@ -0,0 +1 @@ +../../../../core/src/plugins/filed/python/pyfiles/BareosFdPluginLocalFileset.py \ No newline at end of file diff --git a/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py deleted file mode 100644 index 1ac499f6457..00000000000 --- a/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# BAREOS - Backup Archiving REcovery Open Sourced -# -# Copyright (C) 2014-2020 Bareos GmbH & Co. KG -# -# This program is Free Software; you can redistribute it and/or -# modify it under the terms of version three of the GNU Affero General Public -# License as published by the Free Software Foundation, which is -# listed in the file LICENSE. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# Bareos-fd-local-fileset a simple example for a python Bareos FD Plugin using -# BareosFdPluginLocalFileset. The plugin argument 'filename' is used to read -# all files listed in that file and add it to the fileset -# -# Author: Maik Aussendorf -# - -# Provided by the Bareos FD Python plugin interface -import bareosfd - -# This module contains the wrapper functions called by the Bareos-FD, the -# functions call the corresponding methods from your plugin class -import BareosFdWrapper - -from BareosFdWrapper import * # noqa - -# This module contains the used plugin class -import BareosFdPluginLocalFileset - - -def load_bareos_plugin(gcplugindef): - """ - This function is called by the Bareos-FD to load the plugin - We use it to instantiate the plugin class - """ - # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that - # holds the plugin class object - BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLocalFileset.BareosFdPluginLocalFileset( - gcplugindef - ) - return bareosfd.bRC_OK - - -# the rest is done in the Plugin module diff --git a/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py b/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py new file mode 120000 index 00000000000..a0e0c3e7054 --- /dev/null +++ b/systemtests/tests/py2plug-fd-local-fileset/python-modules/bareos-fd-local-fileset.py @@ -0,0 +1 @@ +../../../../core/src/plugins/filed/python/pyfiles/bareos-fd-local-fileset.py \ No newline at end of file From 32a1e045fbeced9f0225e7de21491e59f4cdfdda Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 20 Aug 2020 16:13:17 +0200 Subject: [PATCH 241/341] plugins: fix installation of example configs --- core/src/filed/CMakeLists.txt | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/core/src/filed/CMakeLists.txt b/core/src/filed/CMakeLists.txt index abc127823df..a108f558653 100644 --- a/core/src/filed/CMakeLists.txt +++ b/core/src/filed/CMakeLists.txt @@ -91,26 +91,6 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") ) endif() -set(PLUGINS python-ldap-conf.d) -list(APPEND PLUGINS python-ovirt-conf.d) - -if(${HAVE_CEPHFS}) - list(APPEND PLUGINS cephfs-conf.d) -endif() -if(${HAVE_CEPH_RADOS}) - list(APPEND PLUGINS rados-conf.d) -endif() - -if(${HAVE_GLUSTERFS}) - list(APPEND PLUGINS gfapi-conf.d) -endif() - -set(PLUGINS - ${PLUGINS} - PARENT_SCOPE -) -message("PLUGINS: ${PLUGINS}") - install( TARGETS bareos-fd DESTINATION "${sbindir}" @@ -118,6 +98,7 @@ install( ) install(CODE "set(PLUGINS \"${PLUGINS}\")" COMPONENT filedaemon) +install(CODE "set(BACKENDS \"${BACKENDS}\")" COMPONENT filedaemon) install(CODE "set(configtemplatedir \"${configtemplatedir}\")" COMPONENT filedaemon ) From 500e937d05d6a50ee0f6902e6532ea22ebba95ba Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 20 Aug 2020 16:42:15 +0200 Subject: [PATCH 242/341] tests: environment: dereference links when searching for psql --- systemtests/environment.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/systemtests/environment.in b/systemtests/environment.in index b65ec6cd005..07a8efc369a 100644 --- a/systemtests/environment.in +++ b/systemtests/environment.in @@ -109,7 +109,7 @@ export OVIRT_SERVER=@ovirt_server@ # real postgres binaries are hidden on debian, instead there are wrappers # which we do not want for our tests if [ -d /usr/lib/postgresql ]; then - POSTGRES_BINARY_DIR=$(dirname $(find /usr/lib/postgresql | grep psql)) + POSTGRES_BINARY_DIR=$(dirname $(find -L /usr/lib/postgresql | grep psql)) export PATH=$POSTGRES_BINARY_DIR:$PATH else export PATH=/sbin:/usr/sbin:$PATH From 72506252ca8e02512f1a9508428d0b23be54a70f Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 20 Aug 2020 17:02:12 +0200 Subject: [PATCH 243/341] plugins: fix installation of python-vmware files --- core/CMakeLists.txt | 5 +++++ core/src/plugins/filed/python/CMakeLists.txt | 2 ++ .../filed/{ => python/vmware}/BareosFdPluginVMware.py | 0 .../plugins/filed/{ => python/vmware}/bareos-fd-vmware.py | 0 4 files changed, 7 insertions(+) rename core/src/plugins/filed/{ => python/vmware}/BareosFdPluginVMware.py (100%) rename core/src/plugins/filed/{ => python/vmware}/bareos-fd-vmware.py (100%) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 744ef21b1dd..a610406cdbe 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -676,8 +676,13 @@ endif() # info what the config files need to be installed PLUGINS ############ set(PLUGINS python-ldap) + list(APPEND PLUGINS python-ovirt) +if(VIXDISKLIB_FOUND) + list(APPEND PLUGINS python-vmware) +endif() + if(${HAVE_CEPHFS}) list(APPEND PLUGINS cephfs) endif() diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index b0c8de2e4e8..bccf2f5b828 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -175,6 +175,8 @@ set(PYFILES percona-xtrabackup/BareosFdPluginPerconaXtraBackup.py postgres/bareos-fd-postgres.py postgres/BareosFdPluginPostgres.py + vmware/bareos-fd-vmware.py + vmware/BareosFdPluginVMware.py ) install( diff --git a/core/src/plugins/filed/BareosFdPluginVMware.py b/core/src/plugins/filed/python/vmware/BareosFdPluginVMware.py similarity index 100% rename from core/src/plugins/filed/BareosFdPluginVMware.py rename to core/src/plugins/filed/python/vmware/BareosFdPluginVMware.py diff --git a/core/src/plugins/filed/bareos-fd-vmware.py b/core/src/plugins/filed/python/vmware/bareos-fd-vmware.py similarity index 100% rename from core/src/plugins/filed/bareos-fd-vmware.py rename to core/src/plugins/filed/python/vmware/bareos-fd-vmware.py From 259a6f04506d1130534afb3a5c36fc64af22248c Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 20 Aug 2020 17:12:16 +0200 Subject: [PATCH 244/341] plugin install: make PLUGINS known in PARENT SCOPE --- core/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index a610406cdbe..c991856b9ae 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -694,6 +694,11 @@ if(${HAVE_GLUSTERFS}) list(APPEND PLUGINS gfapi) endif() +set(PLUGINS + ${PLUGINS} + PARENT_SCOPE +) + # BACKENDS #### if(build_client_only) set(BACKENDS "") From 16dfefad0938a988d21ff059b4514ad565d86ffa Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 24 Aug 2020 17:30:14 +0200 Subject: [PATCH 245/341] plugins: enable restore of plugin data with newer plugin When trying to find the right plugin for an event in "IsEventForThisPlugin()", not only the full plugin name is matched like before. Now also we check if the name without the last character Matches. This is helpful to be able to restore data written with the "python" plugin with the "python3" plugin. --- core/src/filed/fd_plugins.cc | 36 ++++++++++++++++++++++++++---------- core/src/lib/plugins.cc | 2 +- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/core/src/filed/fd_plugins.cc b/core/src/filed/fd_plugins.cc index 57e6b13706a..7a11325dc33 100644 --- a/core/src/filed/fd_plugins.cc +++ b/core/src/filed/fd_plugins.cc @@ -223,10 +223,10 @@ static bool IsCtxGood(PluginContext* ctx, /** * Test if event is for this plugin */ -static bool for_thIsPlugin(Plugin* plugin, char* name, int len) +static bool IsEventForThisPlugin(Plugin* plugin, char* name, int len) { - Dmsg4(debuglevel, "name=%s len=%d plugin=%s plen=%d\n", name, len, - plugin->file, plugin->file_len); + Dmsg4(debuglevel, "IsEventForThisPlugin? name=%s len=%d plugin=%s plen=%d\n", + name, len, plugin->file, plugin->file_len); if (!name) { /* if no plugin name, all plugins get it */ return true; } @@ -246,8 +246,24 @@ static bool for_thIsPlugin(Plugin* plugin, char* name, int len) * Check if this is the correct plugin */ if (len == plugin->file_len && bstrncmp(plugin->file, name, len)) { + Dmsg4(debuglevel, + "IsEventForThisPlugin: yes, full match (plugin=%s, name=%s)\n", + plugin->file, name); return true; } + // To be able to restore "python" plugin streams with the "python3" plugin, + // we check if the required name is the same as the plugin name without the + // last character + if (len == plugin->file_len - 1 && bstrncmp(plugin->file, name, len)) { + Dmsg4(debuglevel, + "IsEventForThisPlugin: yes, without last character: (plugin=%s, " + "name=%s)\n", + plugin->file, name); + return true; + } + + Dmsg4(debuglevel, "IsEventForThisPlugin: no (plugin=%s, name=%s)\n", + plugin->file, name); return false; } @@ -433,7 +449,7 @@ bRC GeneratePluginEvent(JobControlRecord* jcr, if (reverse) { int i{}; foreach_alist_rindex (i, ctx, plugin_ctx_list) { - if (!for_thIsPlugin(ctx->plugin, name, len)) { + if (!IsEventForThisPlugin(ctx->plugin, name, len)) { Dmsg2(debuglevel, "Not for this plugin name=%s NULL=%d\n", name, (name == NULL) ? 1 : 0); continue; @@ -447,7 +463,7 @@ bRC GeneratePluginEvent(JobControlRecord* jcr, } else { int i{}; foreach_alist_index (i, ctx, plugin_ctx_list) { - if (!for_thIsPlugin(ctx->plugin, name, len)) { + if (!IsEventForThisPlugin(ctx->plugin, name, len)) { Dmsg2(debuglevel, "Not for this plugin name=%s NULL=%d\n", name, (name == NULL) ? 1 : 0); continue; @@ -507,7 +523,7 @@ bool PluginCheckFile(JobControlRecord* jcr, char* fname) * Get the first part of the the plugin command * systemstate:/@SYSTEMSTATE/ * => ret = 11 - * => can use for_thIsPlugin(plug, cmd, ret); + * => can use IsEventForThisPlugin(plug, cmd, ret); * * The plugin command can contain only the plugin name * Plugin = alldrives @@ -635,7 +651,7 @@ bRC PluginOptionHandleFile(JobControlRecord* jcr, foreach_alist (ctx, plugin_ctx_list) { Dmsg4(debuglevel, "plugin=%s plen=%d cmd=%s len=%d\n", ctx->plugin->file, ctx->plugin->file_len, cmd, len); - if (!for_thIsPlugin(ctx->plugin, cmd, len)) { continue; } + if (!IsEventForThisPlugin(ctx->plugin, cmd, len)) { continue; } if (!IsEventEnabled(ctx, eventType)) { Dmsg1(debuglevel, "Event %d disabled for this plugin.\n", eventType); @@ -715,7 +731,7 @@ int PluginSave(JobControlRecord* jcr, FindFilesPacket* ff_pkt, bool top_level) foreach_alist (ctx, plugin_ctx_list) { Dmsg4(debuglevel, "plugin=%s plen=%d cmd=%s len=%d\n", ctx->plugin->file, ctx->plugin->file_len, cmd, len); - if (!for_thIsPlugin(ctx->plugin, cmd, len)) { continue; } + if (!IsEventForThisPlugin(ctx->plugin, cmd, len)) { continue; } /* * We put the current plugin pointer, and the plugin context into the jcr, @@ -958,7 +974,7 @@ int PluginEstimate(JobControlRecord* jcr, foreach_alist (ctx, plugin_ctx_list) { Dmsg4(debuglevel, "plugin=%s plen=%d cmd=%s len=%d\n", ctx->plugin->file, ctx->plugin->file_len, cmd, len); - if (!for_thIsPlugin(ctx->plugin, cmd, len)) { continue; } + if (!IsEventForThisPlugin(ctx->plugin, cmd, len)) { continue; } /* * We put the current plugin pointer, and the plugin context into the jcr, @@ -1202,7 +1218,7 @@ bool PluginNameStream(JobControlRecord* jcr, char* name) b_plugin_ctx* b_ctx; Dmsg3(debuglevel, "plugin=%s cmd=%s len=%d\n", ctx->plugin->file, cmd, len); - if (!for_thIsPlugin(ctx->plugin, cmd, len)) { continue; } + if (!IsEventForThisPlugin(ctx->plugin, cmd, len)) { continue; } if (IsPluginDisabled(ctx)) { Dmsg1(debuglevel, "Plugin %s disabled\n", cmd); diff --git a/core/src/lib/plugins.cc b/core/src/lib/plugins.cc index a242cd74cec..6ee51f1638b 100644 --- a/core/src/lib/plugins.cc +++ b/core/src/lib/plugins.cc @@ -104,7 +104,7 @@ static void ClosePlugin(Plugin* plugin) /* * Load a specific plugin and check if the plugin had the correct - * entry points, the license is compatible and the initialize the plugin. + * entry points, the license is compatible and initialize the plugin. */ static bool load_a_plugin(void* bareos_plugin_interface_version, void* bareos_core_functions, From 311ae864fc220e37ed48b501b01b8054e5b15716 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Sat, 29 Aug 2020 16:32:31 +0200 Subject: [PATCH 246/341] systemtests: use postgresl database as default --- systemtests/ctest_custom_pretest.sh.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/systemtests/ctest_custom_pretest.sh.in b/systemtests/ctest_custom_pretest.sh.in index 3af6e5059fd..60b349ba067 100755 --- a/systemtests/ctest_custom_pretest.sh.in +++ b/systemtests/ctest_custom_pretest.sh.in @@ -12,7 +12,7 @@ fi postgresql=@postgresql@ if [ -n "$postgresql" ]; then echo -n "PRETEST: checking postgresql connection ..." - if ! psql <<< "SELECT version()" 2>&1 >/dev/null; then + if ! psql postgres <<< "SELECT version()" 2>&1 >/dev/null; then echo "could not connect postgresql server" exit 1 else From 1131466d0c8c174d97fd456994630056877da9dc Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Wed, 4 Mar 2020 14:49:56 +0100 Subject: [PATCH 247/341] plugins: add bareos-libcloud fd-plugin files --- .../plugins/filed/BareosFdPluginLibcloud.py | 446 ++++++++++++++++++ core/src/plugins/filed/bareos-fd-libcloud.py | 47 ++ 2 files changed, 493 insertions(+) create mode 100755 core/src/plugins/filed/BareosFdPluginLibcloud.py create mode 100644 core/src/plugins/filed/bareos-fd-libcloud.py diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py new file mode 100755 index 00000000000..da4a6754024 --- /dev/null +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -0,0 +1,446 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation, which is +# listed in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# Author: Alexandre Bruyelles +# + +import BareosFdPluginBaseclass +import bareosfd +import bareos_fd_consts +import datetime +import dateutil.parser +import io +import itertools +import libcloud +import multiprocessing +import os +import syslog +import time +import traceback + +from libcloud.storage.types import Provider +from libcloud.storage.providers import get_driver +from bareos_fd_consts import bRCs, bIOPS + +syslog.openlog(__name__, facility=syslog.LOG_LOCAL7) + +debug = False + + +def log(message): + if debug is True: + message = '[%s] %s' % (os.getpid(), message) + syslog.syslog(message) + + +def error(message): + message = '[%s] %s' % (os.getpid(), message) + syslog.syslog(message) + + +# Print the traceback to syslog +def log_exc(): + for line in traceback.format_exc().split('\n'): + error(line) + + +class IterStringIO(io.BufferedIOBase): + def __init__(self, iterable): + self.iter = itertools.chain.from_iterable(iterable) + + def read(self, n=None): + return bytearray(itertools.islice(self.iter, None, n)) + + +def str2bool(data): + if data == 'false' or data == 'False': + return False + if data == 'true' or data == 'True': + return True + raise Exception('%s: not a boolean' % (data,)) + + +def connect(options): + driver_opt = dict(options) + + # Some drivers does not support unknown options + # Here, we remove those used by libcloud and let the rest pass through + for opt in ('buckets_exclude', 'accurate', 'nb_prefetcher', 'prefetch_size', 'queue_size', 'provider', 'buckets_include', 'debug'): + if opt in options: + del driver_opt[opt] + + provider = getattr(Provider, options['provider']) + driver = get_driver(provider)(**driver_opt) + return driver + + +def get_object(driver, bucket, key): + try: + return driver.get_object(bucket, key) + except libcloud.common.types.InvalidCredsError: + # Something is buggy here, this bug is triggered by tilde-ending objects + # Our tokens are good, we used then before + error('BUGGY filename found, see the libcloud bug somewhere : %s/%s' % (bucket, key)) + return None + + +class Prefetcher(object): + def __init__(self, options, plugin_todo_queue, pref_todo_queue): + self.options = options + self.plugin_todo_queue = plugin_todo_queue + self.pref_todo_queue = pref_todo_queue + + def __call__(self): + try: + self.driver = connect(self.options) + self.__work() + except: + log('FATAL ERROR: I am a prefetcher, and I am dying !') + log_exc() + + def __work(self): + while True: + job = self.pref_todo_queue.get() + if job is None: + log('prefetcher[%s] : job completed, I will now die' % (os.getpid(),)) + return + + obj = get_object(self.driver, job['bucket'], job['name']) + if obj is None: + # Object cannot be fetched, an error is already logged + continue + + stream = obj.as_stream() + content = b''.join(list(stream)) + + prefetched = len(content) + if prefetched != job['size']: + error('FATAL ERROR: prefetched file %s: got %s bytes, not the real size (%s bytes)' % (job['name'], prefetched, job['size'])) + return + + data = io.BytesIO(content) + + job['data'] = data + self.plugin_todo_queue.put(job) + + +class Writer(object): + def __init__(self, plugin_todo_queue, pref_todo_queue, last_run, opts, pids): + self.plugin_todo_queue = plugin_todo_queue + self.pref_todo_queue = pref_todo_queue + self.last_run = last_run + self.options = opts + self.pids = pids + + self.driver = connect(self.options) + self.delta = datetime.timedelta(seconds=time.timezone) + + def __call__(self): + try: + self.__map() + except: + log_exc() + self.__end_job() + + def __map(self): + for bucket in self.driver.iterate_containers(): + if self.options['buckets_include'] is not None: + if bucket.name not in self.options['buckets_include']: + continue + + if self.options['buckets_exclude'] is not None: + if bucket.name in self.options['buckets_exclude']: + continue + + log('Backuping bucket %s' % (bucket.name,)) + + self.__generate(self.driver.iterate_container_objects(bucket)) + + def __get_mtime(self, obj): + mtime = dateutil.parser.parse(obj.extra['last_modified']) + mtime = mtime - self.delta + mtime = mtime.replace(tzinfo=None) + + ts = time.mktime(mtime.timetuple()) + return mtime, ts + + def __generate(self, iterator): + for obj in iterator: + mtime, mtime_ts = self.__get_mtime(obj) + + result = {'name': obj.name, + 'bucket': obj.container.name, + 'data': None, + 'size': obj.size, + 'mtime': mtime_ts + } + + pseudo = '%s/%s' % (obj.container.name, obj.name) + + if self.last_run > mtime: + log('File %s not changed, skipped (%s > %s)' % (pseudo, self.last_run, mtime)) + + # This object was present on our last backup + # Here, we push it directly to bareos, it will not be backed again + # but remembered as "still here" (for accurate mode) + # If accurate mode is off, we can simply skip that object + if self.options['accurate'] is True: + self.plugin_todo_queue.put(result) + + continue + + log('File %s changed (or new), backuping (%s < %s)' % (pseudo, self.last_run, mtime)) + + # Do not prefetch large objects + if obj.size >= self.options['prefetch_size']: + self.plugin_todo_queue.put(result) + else: + self.pref_todo_queue.put(result) + + def __end_job(self): + log('__end_job: waiting for prefetchers queue to drain') + while True: + size = self.pref_todo_queue.qsize() + if size == 0: + break + log('__end_job: %s items left in prefetchers queue, waiting' % (size,)) + time.sleep(2) + log('__end_job: prefetchers queue is drained') + + log('__end_job: I will ask prefetchers to die') + for i in range(0, self.options['nb_prefetcher']): + self.pref_todo_queue.put(None) + + # This is the last item ever put on that queue + # The plugin on the other end will know the backup is completed + self.plugin_todo_queue.put(None) + + +class BareosFdPluginLibcloud(BareosFdPluginBaseclass.BareosFdPluginBaseclass): + def __init__(self, context, plugindef): + log('BareosFdPluginLibcloud called with plugindef: %s' % (plugindef,)) + + super(BareosFdPluginLibcloud, self).__init__(context, plugindef) + super(BareosFdPluginLibcloud, self).parse_plugin_definition(context, plugindef) + self.__parse_options(context) + + self.last_run = datetime.datetime.fromtimestamp(self.since) + self.last_run = self.last_run.replace(tzinfo=None) + + # We force an action to the backend, to test our params + # If we can get anything, then it is ok + # Else, an exception will be raised, and the job will fail + driver = connect(self.options) + for _ in driver.iterate_containers(): + break + + # The job in process + # Setto None when the whole backup is completed + # Restore's path will not touch this + self.job = {} + + log('Last backup: %s (ts: %s)' % (self.last_run, self.since)) + + def __parse_options_bucket(self, name): + if name not in self.options: + self.options[name] = None + else: + buckets = list() + for bucket in self.options[name].split(','): + buckets.append(bucket) + self.options[name] = buckets + + def __parse_opt_int(self, name): + if name not in self.options: + return + + value = self.options[name] + self.options[name] = int(value) + + def __parse_options(self, context): + # Set our default values + if 'nb_prefetcher' not in self.options: + self.options['nb_prefetcher'] = 24 + if 'queue_size' not in self.options: + self.options['queue_size'] = 1000 + if 'prefetch_size' not in self.options: + self.options['prefetch_size'] = 10 * 1024 * 1024 + self.__parse_options_bucket('buckets_include') + self.__parse_options_bucket('buckets_exclude') + + # Do a couple of sanitization + if 'secure' in self.options: + old = self.options['secure'] + self.options['secure'] = str2bool(old) + + self.__parse_opt_int('port') + self.__parse_opt_int('nb_prefetcher') + self.__parse_opt_int('prefetch_size') + self.__parse_opt_int('queue_size') + self.__parse_opt_int('prefetch_size') + + if 'debug' in self.options: + old = self.options['debug'] + self.options['debug'] = str2bool(old) + + # Setup debugging + if self.options['debug'] is True: + global debug + debug = True + + accurate = bareos_fd_consts.bVariable['bVarAccurate'] + accurate = bareosfd.GetValue(context, accurate) + if accurate is None or accurate == 0: + self.options['accurate'] = False + else: + self.options['accurate'] = True + + def parse_plugin_definition(self, context, plugindef): + return bRCs['bRC_OK'] + + def start_backup_job(self, context): + self.manager = multiprocessing.Manager() + self.plugin_todo_queue = self.manager.Queue(maxsize=self.options['queue_size']) + self.pref_todo_queue = self.manager.Queue(maxsize=self.options['nb_prefetcher']) + + self.pf_pids = list() + self.prefetchers = list() + for i in range(0, self.options['nb_prefetcher']): + target = Prefetcher(self.options, self.plugin_todo_queue, self.pref_todo_queue) + proc = multiprocessing.Process(target=target) + proc.start() + self.pf_pids.append(proc.pid) + self.prefetchers.append(proc) + log('%s prefetcher started' % (len(self.pf_pids),)) + + writer = Writer(self.plugin_todo_queue, self.pref_todo_queue, self.last_run, self.options, self.pf_pids) + self.writer = multiprocessing.Process(target=writer) + self.writer.start() + self.driver = connect(self.options) + + def check_file(self, context, fname): + # All existing files are passed to bareos + # If bareos have not seen one, it does not exists anymore + return bRCs['bRC_Error'] + + def start_backup_file(self, context, savepkt): + try: + while True: + try: + self.job = self.plugin_todo_queue.get_nowait() + break + except: + size = self.plugin_todo_queue.qsize() + log('start_backup_file: queue is near empty : %s' % (size,)) + time.sleep(0.1) + except TypeError: + self.job = None + + if self.job is None: + log('End of queue found, backup is completed') + for i in self.prefetchers: + log('join() for a prefetcher (pid %s)' % (i.pid,)) + i.join() + log('Ok, all prefetchers are dead') + + try: + self.manager.shutdown() + except OSError: + # manager already dead, somehow ?! + pass + log('self.manager.shutdown()') + + log('Join() for the writer (pid %s)' % (self.writer.pid,)) + self.writer.join() + log('writer is dead') + + # savepkt is always checked, so we fill it with a dummy value + savepkt.fname = 'empty' + return bRCs['bRC_Skip'] + + filename = '%s/%s' % (self.job['bucket'], self.job['name']) + log('Backuping %s' % (filename,)) + + statp = bareosfd.StatPacket() + statp.size = self.job['size'] + statp.mtime = self.job['mtime'] + statp.atime = 0 + statp.ctime = 0 + + savepkt.statp = statp + savepkt.fname = filename + savepkt.type = bareos_fd_consts.bFileType['FT_REG'] + + return bRCs['bRC_OK'] + + def plugin_io(self, context, IOP): + if self.job is None: + return bRCs['bRC_Error'] + if IOP.func == bIOPS['IO_OPEN']: + # Only used by the 'restore' path + if IOP.flags & (os.O_CREAT | os.O_WRONLY): + self.FILE = open(IOP.fname, 'wb') + return bRCs['bRC_OK'] + + # 'Backup' path + if self.job['data'] is None: + obj = get_object(self.driver, self.job['bucket'], self.job['name']) + if obj is None: + self.FILE = None + return bRCs['bRC_Error'] + self.FILE = IterStringIO(obj.as_stream()) + else: + self.FILE = self.job['data'] + + elif IOP.func == bIOPS['IO_READ']: + IOP.buf = bytearray(IOP.count) + IOP.io_errno = 0 + if self.FILE is None: + return bRCs['bRC_Error'] + try: + buf = self.FILE.read(IOP.count) + IOP.buf[:] = buf + IOP.status = len(buf) + return bRCs['bRC_OK'] + except IOError as e: + log('Cannot read from %s : %s' % (IOP.fname, e)) + IOP.status = 0 + IOP.io_errno = e.errno + return bRCs['bRC_Error'] + + elif IOP.func == bIOPS['IO_WRITE']: + try: + self.FILE.write(IOP.buf) + IOP.status = IOP.count + IOP.io_errno = 0 + except IOError as msg: + IOP.io_errno = -1 + error('Failed to write data: %s' % (msg,)) + return bRCs['bRC_OK'] + elif IOP.func == bIOPS['IO_CLOSE']: + if self.FILE: + self.FILE.close() + return bRCs['bRC_OK'] + + return bRCs['bRC_OK'] + + def end_backup_file(self, context): + if self.job is not None: + return bRCs['bRC_More'] + else: + return bRCs['bRC_OK'] diff --git a/core/src/plugins/filed/bareos-fd-libcloud.py b/core/src/plugins/filed/bareos-fd-libcloud.py new file mode 100644 index 00000000000..c3b13b9a156 --- /dev/null +++ b/core/src/plugins/filed/bareos-fd-libcloud.py @@ -0,0 +1,47 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation, which is +# listed in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# Author: Alexandre Bruyelles +# + +# Provided by the Bareos FD Python plugin interface +import bareos_fd_consts + +# This module contains the wrapper functions called by the Bareos-FD, the +# functions call the corresponding methods from your plugin class +import BareosFdWrapper +# from BareosFdWrapper import parse_plugin_definition, handle_plugin_event, start_backup_file, end_backup_file, start_restore_file, end_restore_file, restore_object_data, plugin_io, create_file, check_file, handle_backup_file # noqa +from BareosFdWrapper import * # noqa + +# This module contains the used plugin class +import BareosFdPluginLibcloud + + +def load_bareos_plugin(context, plugindef): + ''' + This function is called by the Bareos-FD to load the plugin + We use it to instantiate the plugin class + ''' + # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that + # holds the plugin class object + BareosFdWrapper.bareos_fd_plugin_object = \ + BareosFdPluginLibcloud.BareosFdPluginLibcloud( + context, plugindef) + return bareos_fd_consts.bRCs['bRC_OK'] + +# the rest is done in the Plugin module From 6fe970c711ccaf0d1fb8d0643adfd4d343593f58 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 5 Mar 2020 12:20:49 +0100 Subject: [PATCH 248/341] systemtests: add test for libcloud fd plugin --- systemtests/CMakeLists.txt | 179 ++------- .../bareos-dir.d/catalog/MyCatalog.conf.in | 8 + .../bareos-dir.d/client/bareos-fd.conf.in | 7 + .../bareos-dir.d/console/bareos-mon.conf.in | 7 + .../bareos-dir.d/director/bareos-dir.conf.in | 27 ++ .../bareos-dir.d/fileset/Catalog.conf.in | 11 + .../bareos-dir.d/fileset/PluginTest.conf.in | 10 + .../bareos-dir.d/fileset/SelfTest.conf.in | 11 + .../bareos-dir.d/job/BackupCatalog.conf.in | 20 + .../bareos-dir.d/job/RestoreFiles.conf.in | 11 + .../bareos-dir.d/job/backup-bareos-fd.conf.in | 6 + .../bareos-dir.d/jobdefs/DefaultJob.conf.in | 15 + .../bareos-dir.d/messages/Daemon.conf.in | 7 + .../bareos-dir.d/messages/Standard.conf.in | 7 + .../bareos-dir.d/pool/Differential.conf | 10 + .../etc/bareos/bareos-dir.d/pool/Full.conf | 10 + .../bareos/bareos-dir.d/pool/Incremental.conf | 10 + .../etc/bareos/bareos-dir.d/pool/Scratch.conf | 4 + .../bareos/bareos-dir.d/profile/operator.conf | 18 + .../bareos/bareos-dir.d/storage/File.conf.in | 8 + .../bareos/bareos-fd.d/client/myself.conf.in | 19 + .../bareos-fd.d/director/bareos-dir.conf.in | 5 + .../bareos-fd.d/director/bareos-mon.conf.in | 6 + .../bareos/bareos-fd.d/messages/Standard.conf | 5 + .../bareos-sd.d/device/FileStorage.conf.in | 11 + .../bareos-sd.d/director/bareos-dir.conf.in | 5 + .../bareos-sd.d/director/bareos-mon.conf.in | 6 + .../bareos/bareos-sd.d/messages/Standard.conf | 5 + .../bareos-sd.d/storage/bareos-sd.conf.in | 14 + .../etc/bareos/bconsole.conf.in | 10 + .../client/FileDaemon-local.conf.in | 5 + .../director/Director-local.conf.in | 4 + .../tray-monitor.d/monitor/bareos-mon.conf.in | 7 + .../storage/StorageDaemon-local.conf.in | 5 + ...sFdPluginLocalFilesetWithRestoreObjects.py | 353 ++++++++++++++++++ ...os-fd-local-fileset-with-restoreobjects.py | 59 +++ .../python-fd-plugin-libcloud-test/testrunner | 74 ++++ 37 files changed, 836 insertions(+), 143 deletions(-) create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/messages/Daemon.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/messages/Standard.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Differential.conf create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Full.conf create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Incremental.conf create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Scratch.conf create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/profile/operator.conf create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/storage/File.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/client/myself.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/messages/Standard.conf create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/device/FileStorage.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/messages/Standard.conf create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bconsole.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/director/Director-local.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/monitor/bareos-mon.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/python-modules/bareos-fd-local-fileset-with-restoreobjects.py create mode 100755 systemtests/tests/python-fd-plugin-libcloud-test/testrunner diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 9e96a58151a..351d717810b 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -147,6 +147,7 @@ macro(CheckForEnabledAndDisabledListEntry TEST_NAME_TO_CHECK) "The test name: ${TEST_NAME} is listed ambiguously in SYSTEM_TESTS and SYSTEM_TESTS_DISABLED at the same time" ) endif() + endmacro() # set the data encryption and signature keys @@ -392,14 +393,12 @@ else() # run systemtests on source and compiled files get_target_property(FD_PLUGINS_DIR_TO_TEST bpipe-fd BINARY_DIR) get_target_property(SD_PLUGINS_DIR_TO_TEST autoxflate-sd BINARY_DIR) - if(TARGET bareossd-droplet) get_target_property(SD_BACKEND_DIR_TO_TEST bareossd-droplet BINARY_DIR) endif() if(TARGET bareossd-gfapi) get_target_property(SD_BACKEND_DIR_TO_TEST bareossd-gfapi BINARY_DIR) endif() - set(DIR_PLUGINS_DIR_TO_TEST ${CMAKE_BINARY_DIR}/core/src/plugins/dird) get_target_property(BACKEND_DIR_TO_TEST bareoscats BINARY_DIR) @@ -458,13 +457,13 @@ set(python_plugin_module_src_test_dir_relative "python-modules") set(plugindirtmp ${PROJECT_BINARY_DIR}/plugindirtmp) set(rscripts ${PROJECT_BINARY_DIR}/scripts) -if(TARGET python-dir OR TARGET python3-dir) +if(TARGET python-dir) set(dir_plugin_binary_path ${DIR_PLUGINS_DIR_TO_TEST}) endif() -if(TARGET python-sd OR TARGET python3-sd) +if(TARGET python-sd) set(sd_plugin_binary_path ${SD_PLUGINS_DIR_TO_TEST}) endif() -if(TARGET python-fd OR TARGET python3-fd) +if(TARGET python-fd) set(fd_plugin_binary_path ${FD_PLUGINS_DIR_TO_TEST}) endif() @@ -542,20 +541,17 @@ endforeach() set(tests_dir ${PROJECT_BINARY_DIR}/tests) set(SYSTEM_TESTS client-initiated - config-dump encrypt-signature encrypt-signature-tls-cert notls passive spool bareos - bareos-acl bscan bconsole-status-client config-syntax-crash copy-bscan copy-remote-bscan - deprecation messages multiplied-device reload-add-client @@ -580,26 +576,6 @@ set(glusterfs_uri ) mark_as_advanced(glusterfs_uri) -include(BareosCheckXattr) -if(SETFATTR_WORKS) - list(APPEND SYSTEM_TESTS xattr) -else() - list(APPEND SYSTEM_TESTS_DISABLED xattr) -endif() - -include(BareosCheckAcl) -if(SETFACL_WORKS) - list(APPEND SYSTEM_TESTS acl) -else() - list(APPEND SYSTEM_TESTS_DISABLED acl) -endif() - -if(TARGET droplet) - list(APPEND SYSTEM_TESTS droplet-s3) -else() - list(APPEND SYSTEM_TESTS_DISABLED droplet-s3) -endif() - if(SD_GFAPI_DIR_TO_TEST AND glusterfs_uri) list(APPEND SYSTEM_TESTS glusterfs-backend) else() @@ -619,7 +595,6 @@ endif() if(EXISTS /run/.containerenv) message(STATUS "detected container environment, disabling python-bareos") set(in_container TRUE) - list(APPEND SYSTEM_TESTS "dbcopy-mysql-postgresql-test") else() set(in_container FALSE) endif() @@ -648,124 +623,66 @@ else() endif() if(TARGET python-fd) - list(APPEND SYSTEM_TESTS "py2plug-fd-local-fileset") -else() - list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-local-fileset") -endif() - -if(TARGET python3-fd) - list(APPEND SYSTEM_TESTS "py3plug-fd-local-fileset") + list(APPEND SYSTEM_TESTS "pyplug-fd-local-fileset") else() - list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-local-fileset") + list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-local-fileset") endif() if(TARGET python-fd) - list(APPEND SYSTEM_TESTS "py2plug-fd-local-fileset-restoreobject") + list(APPEND SYSTEM_TESTS "pyplug-fd-local-fileset-restoreobject") else() - list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-local-fileset-restoreobject") + list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-local-fileset-restoreobject") endif() -if(TARGET python3-fd) - list(APPEND SYSTEM_TESTS "py3plug-fd-local-fileset-restoreobject") -else() - list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-local-fileset-restoreobject") -endif() +message("checking for requirements of pyplug-fd-postgres:") +check_pymodule_available("psycopg2") +check_pymodule_available("dateutil") -message("checking for requirements of py2plug-fd-postgres:") -check_pymodule_available(2 psycopg2) -check_pymodule_available(2 dateutil) if(TARGET python-fd - AND PYMODULE_2_PSYCOPG2_FOUND - AND PYMODULE_2_DATEUTIL_FOUND + AND PYMODULE_PSYCOPG2_FOUND + AND PYMODULE_DATEUTIL_FOUND ) - message("OK, enabling py2plug-fd-postgres:") - list(APPEND SYSTEM_TESTS "py2plug-fd-postgres") + message("OK, enabling pyplug-fd-postgres:") + list(APPEND SYSTEM_TESTS "pyplug-fd-postgres") else() - list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-postgres") - message("NOT OK, disabling py2plug-fd-postgres:") -endif() - -message("checking for requirements of py3plug-fd-postgres:") -check_pymodule_available(3 psycopg2) -check_pymodule_available(3 dateutil) -if(TARGET python-fd - AND PYMODULE_3_PSYCOPG2_FOUND - AND PYMODULE_3_DATEUTIL_FOUND -) - list(APPEND SYSTEM_TESTS "py3plug-fd-postgres") -else() - list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-postgres") + list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-postgres") + message("NOT OK, disabling pyplug-fd-postgres:") endif() if(TARGET python-fd AND ovirt_server) - list(APPEND SYSTEM_TESTS "py2plug-fd-ovirt") -else() - message(STATUS "disabling py2plug-fd-ovirt-test as ovirt_server is not set") - list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-ovirt") -endif() - -if(TARGET python3-fd AND ovirt_server) - list(APPEND SYSTEM_TESTS "py3plug-fd-ovirt") + list(APPEND SYSTEM_TESTS "pyplug-fd-ovirt") else() - message(STATUS "disabling py3plug-fd-ovirt as ovirt_server is not set") - list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-ovirt") + message(STATUS "disabling pyplug-fd-ovirt-test as ovirt_server is not set") + list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-ovirt") endif() if(TARGET python-fd AND enable_vmware_test) - list(APPEND SYSTEM_TESTS "py2plug-fd-vmware") -else() - message(STATUS "disabling py2plug-fd-vmware as vmware_server was not set") - list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-vmware") -endif() - -if(TARGET python3-fd AND enable_vmware_test) - list(APPEND SYSTEM_TESTS "py3plug-fd-vmware") + list(APPEND SYSTEM_TESTS "pyplug-fd-vmware") else() - message(STATUS "disabling py3plug-fd-vmware as vmware_server was not set") - list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-vmware") + message(STATUS "disabling pyplug-fd-vmware as vmware_server was not set") + list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-vmware") endif() if(TARGET python-fd AND XTRABACKUP) - list(APPEND SYSTEM_TESTS "py2plug-fd-percona-xtrabackup") + list(APPEND SYSTEM_TESTS "pyplug-fd-percona-xtrabackup") else() message( STATUS - "disabling py2plug-fd-percona-xtrabackup-test as XTRABACKUP was not found" - ) - list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-percona-xtrabackup") -endif() - -if(TARGET python3-fd AND XTRABACKUP) - list(APPEND SYSTEM_TESTS "py3plug-fd-percona-xtrabackup") -else() - message( - STATUS "disabling py3plug-fd-percona-xtrabackup as XTRABACKUP was not found" + "disabling pyplug-fd-percona-xtrabackup-test as XTRABACKUP was not found" ) - list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-percona-xtrabackup") + list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-percona-xtrabackup") endif() if(TARGET python-dir) - list(APPEND SYSTEM_TESTS "py2plug-dir") + list(APPEND SYSTEM_TESTS "pyplug-dir") else() - list(APPEND SYSTEM_TESTS_DISABLED "py2plug-dir") -endif() - -if(TARGET python3-dir) - list(APPEND SYSTEM_TESTS "py3plug-dir") -else() - list(APPEND SYSTEM_TESTS_DISABLED "py3plug-dir") + list(APPEND SYSTEM_TESTS_DISABLED "pyplug-dir") endif() if(TARGET python-sd) - list(APPEND SYSTEM_TESTS "py2plug-sd") -else() - list(APPEND SYSTEM_TESTS_DISABLED "py2plug-sd") -endif() - -if(TARGET python3-sd) - list(APPEND SYSTEM_TESTS "py3plug-sd") + list(APPEND SYSTEM_TESTS "pyplug-sd") else() - list(APPEND SYSTEM_TESTS_DISABLED "py3plug-sd") + list(APPEND SYSTEM_TESTS_DISABLED "pyplug-sd") endif() message(STATUS "Looking for pam test requirements ...") @@ -820,18 +737,17 @@ message(STATUS "Looking for webui test requirements ...") find_program(PHP php) find_program(CHROMEDRIVER chromedriver) -check_pymodule_available(2 selenium) # sets PYMODULE_2_SELENIUM_FOUND to TRUE or -check_pymodule_available(3 selenium) # sets PYMODULE_3_SELENIUM_FOUND to TRUE or +check_pymodule_available("selenium") # sets PYMODULE_SELENIUM_FOUND to TRUE or # FALSE message(" PHP: " ${PHP}) message(" PYTHON_EXECUTABLE: " ${PYTHON_EXECUTABLE}) -message(" PYMODULE_2_SELENIUM_FOUND:" ${PYMODULE_2_SELENIUM_FOUND}) +message(" PYMODULE_SELENIUM_FOUND:" ${PYMOD_SELENIUM_FOUND}) message(" CHROMEDRIVER: " ${CHROMEDRIVER}) if(PHP AND PYTHON_EXECUTABLE - AND PYMODULE_2_SELENIUM_FOUND + AND PYMODULE_SELENIUM_FOUND AND CHROMEDRIVER ) set(ENABLE_WEBUI_SELENIUM_TEST TRUE) @@ -871,31 +787,10 @@ endif() foreach(TEST_NAME ${SYSTEM_TESTS}) message(STATUS "Configuring test: ${SYSTEMTEST_PREFIX}${TEST_NAME}") - string(REGEX MATCH "py2plug" py_v2 "${TEST_NAME}") - string(REGEX MATCH "py3plug" py_v3 "${TEST_NAME}") - if(py_v2) - set(python_module_name python) - endif() - if(py_v3) - set(python_module_name python3) - endif() prepare_test() configurefilestosystemtest("systemtests" "tests/${TEST_NAME}" "*" @ONLY "") - string( - CONCAT - pythonpath - "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/percona-xtrabackup:" - "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/ovirt:" - "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/postgres:" - "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/pyfiles:" - "${CMAKE_SOURCE_DIR}/core/src/plugins/stored/python/pyfiles:" - "${CMAKE_SOURCE_DIR}/core/src/plugins/dird/python/pyfiles:" - "${CMAKE_BINARY_DIR}/core/src/plugins/filed/python/${python_module_name}modules:" - "${CMAKE_BINARY_DIR}/core/src/plugins/stored/python/${python_module_name}modules:" - "${CMAKE_BINARY_DIR}/core/src/plugins/dird/python/${python_module_name}modules:" - "${CMAKE_CURRENT_SOURCE_DIR}/tests/${TEST_NAME}/python-modules" - ) + handle_python_plugin_modules(${TEST_NAME}) configure_file("environment.in" "tests/${TEST_NAME}/environment" @ONLY) @@ -906,7 +801,7 @@ foreach(TEST_NAME ${SYSTEM_TESTS}) COMMAND ${tests_dir}/${TEST_NAME}/testrunner WORKING_DIRECTORY ${tests_dir}/${TEST_NAME} ) - set_tests_properties(${SYSTEMTEST_PREFIX}${TEST_NAME} PROPERTIES TIMEOUT 180) + set_tests_properties(${SYSTEMTEST_PREFIX}${TEST_NAME} PROPERTIES TIMEOUT 90) math(EXPR BASEPORT "${BASEPORT} + 10") endforeach() @@ -966,9 +861,7 @@ if(ENABLE_WEBUI_SELENIUM_TEST) COMMAND ${tests_dir}/${TEST_NAME}/testrunner WORKING_DIRECTORY ${tests_dir}/${TEST_NAME} ) - set_tests_properties( - ${WEBUI_TEST_PREFIX}${TEST_NAME} PROPERTIES TIMEOUT 180 - ) + set_tests_properties(${WEBUI_TEST_PREFIX}${TEST_NAME} PROPERTIES TIMEOUT 90) math(EXPR BASEPORT "${BASEPORT} + 10") endforeach() endif() diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in new file mode 100644 index 00000000000..479bc6fecbb --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in @@ -0,0 +1,8 @@ +Catalog { + Name = MyCatalog + #dbdriver = "@DEFAULT_DB_TYPE@" + dbdriver = "XXX_REPLACE_WITH_DATABASE_DRIVER_XXX" + dbname = "@db_name@" + dbuser = "@db_user@" + dbpassword = "@db_password@" +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in new file mode 100644 index 00000000000..470ca702035 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in @@ -0,0 +1,7 @@ +Client { + Name = bareos-fd + Description = "Client resource of the Director itself." + Address = localhost + Password = "@fd_password@" # password for FileDaemon + FD PORT = @fd_port@ +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in new file mode 100644 index 00000000000..d276adcb87d --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in @@ -0,0 +1,7 @@ +Console { + Name = bareos-mon + Description = "Restricted console used by tray-monitor to get the status of the director." + Password = "@mon_dir_password@" + CommandACL = status, .status + JobACL = *all* +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in new file mode 100644 index 00000000000..8346e62ddc7 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in @@ -0,0 +1,27 @@ +Director { # define myself + Name = bareos-dir + QueryFile = "@scriptdir@/query.sql" + Maximum Concurrent Jobs = 10 + Password = "@dir_password@" # Console password + Messages = Daemon + Auditing = yes + + # Enable the Heartbeat if you experience connection losses + # (eg. because of your router or firewall configuration). + # Additionally the Heartbeat can be enabled in bareos-sd and bareos-fd. + # + # Heartbeat Interval = 1 min + + # remove comment in next line to load dynamic backends from specified directory + Backend Directory = @backenddir@ + + # remove comment from "Plugin Directory" to load plugins from specified directory. + # if "Plugin Names" is defined, only the specified plugins will be loaded, + # otherwise all director plugins (*-dir.so) from the "Plugin Directory". + # + # Plugin Directory = "@dir_plugin_binary_path@" + # Plugin Names = "" + Working Directory = "@working_dir@" + Pid Directory = "@piddir@" + DirPort = @dir_port@ +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in new file mode 100644 index 00000000000..c7cdc433fe1 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in @@ -0,0 +1,11 @@ +FileSet { + Name = "Catalog" + Description = "Backup the catalog dump and Bareos configuration files." + Include { + Options { + signature = MD5 + } + File = "@working_dir@/@db_name@.sql" # database dump + File = "@confdir@" # configuration + } +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in new file mode 100644 index 00000000000..4518acbd992 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in @@ -0,0 +1,10 @@ +FileSet { + Name = "PluginTest" + Description = "Test the Plugin functionality with a Python Plugin." + Include { + Options { + signature = MD5 + } + Plugin = "python:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-libcloud:provider=S3:key=minioadmin:secret=minioadmin:host=127.0.0.1:port=9000:secure=false:buckets_include=test" + } +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in new file mode 100644 index 00000000000..ba39719ea3f --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in @@ -0,0 +1,11 @@ +FileSet { + Name = "SelfTest" + Description = "fileset just to backup some files for selftest" + Include { + Options { + Signature = MD5 # calculate md5 checksum per file + } + #File = "@sbindir@" + File=<@tmpdir@/file-list + } +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in new file mode 100644 index 00000000000..1da2a7af657 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in @@ -0,0 +1,20 @@ +Job { + Name = "BackupCatalog" + Description = "Backup the catalog database (after the nightly save)" + JobDefs = "DefaultJob" + Level = Full + FileSet="Catalog" + + # This creates an ASCII copy of the catalog + # Arguments to make_catalog_backup.pl are: + # make_catalog_backup.pl + RunBeforeJob = "@scriptdir@/make_catalog_backup.pl MyCatalog" + + # This deletes the copy of the catalog + RunAfterJob = "@scriptdir@/delete_catalog_backup" + + # This sends the bootstrap via mail for disaster recovery. + # Should be sent to another system, please change recipient accordingly + Write Bootstrap = "|@bindir@/bsmtp -h @smtp_host@ -f \"\(Bareos\) \" -s \"Bootstrap for Job %j\" @job_email@" # (#01) + Priority = 11 # run after main backup +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in new file mode 100644 index 00000000000..89256864d9a --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in @@ -0,0 +1,11 @@ +Job { + Name = "RestoreFiles" + Description = "Standard Restore template. Only one such job is needed for all standard Jobs/Clients/Storage ..." + Type = Restore + Client = bareos-fd + FileSet = SelfTest + Storage = File + Pool = Incremental + Messages = Standard + Where = @tmp@/bareos-restores +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in new file mode 100644 index 00000000000..d54d7ff8e17 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in @@ -0,0 +1,6 @@ +Job { + Name = "backup-bareos-fd" + JobDefs = "DefaultJob" + Client = "bareos-fd" + FileSet = "PluginTest" +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in new file mode 100644 index 00000000000..563126477c9 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in @@ -0,0 +1,15 @@ +JobDefs { + Name = "DefaultJob" + Type = Backup + Level = Incremental + Client = bareos-fd + FileSet = "SelfTest" + Storage = File + Messages = Standard + Pool = Incremental + Priority = 10 + Write Bootstrap = "@working_dir@/%c.bsr" + Full Backup Pool = Full # write Full Backups into "Full" Pool + Differential Backup Pool = Differential # write Diff Backups into "Differential" Pool + Incremental Backup Pool = Incremental # write Incr Backups into "Incremental" Pool +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/messages/Daemon.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/messages/Daemon.conf.in new file mode 100644 index 00000000000..cf6a8cfa1e2 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/messages/Daemon.conf.in @@ -0,0 +1,7 @@ +Messages { + Name = Daemon + Description = "Message delivery for daemon messages (no job)." + console = all, !skipped, !saved, !audit + append = "@logdir@/bareos.log" = all, !skipped, !audit + append = "@logdir@/bareos-audit.log" = audit +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/messages/Standard.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/messages/Standard.conf.in new file mode 100644 index 00000000000..b3556ba8c23 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/messages/Standard.conf.in @@ -0,0 +1,7 @@ +Messages { + Name = Standard + Description = "Reasonable message delivery -- send most everything to email address and to the console." + console = all, !skipped, !saved, !audit + append = "@logdir@/bareos.log" = all, !skipped, !saved, !audit + catalog = all, !skipped, !saved, !audit +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Differential.conf b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Differential.conf new file mode 100644 index 00000000000..25ce24821ab --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Differential.conf @@ -0,0 +1,10 @@ +Pool { + Name = Differential + Pool Type = Backup + Recycle = yes # Bareos can automatically recycle Volumes + AutoPrune = yes # Prune expired volumes + Volume Retention = 90 days # How long should the Differential Backups be kept? (#09) + Maximum Volume Bytes = 10G # Limit Volume size to something reasonable + Maximum Volumes = 100 # Limit number of Volumes in Pool + Label Format = "Differential-" # Volumes will be labeled "Differential-" +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Full.conf b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Full.conf new file mode 100644 index 00000000000..867fc66b483 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Full.conf @@ -0,0 +1,10 @@ +Pool { + Name = Full + Pool Type = Backup + Recycle = yes # Bareos can automatically recycle Volumes + AutoPrune = yes # Prune expired volumes + Volume Retention = 365 days # How long should the Full Backups be kept? (#06) + Maximum Volume Bytes = 50G # Limit Volume size to something reasonable + Maximum Volumes = 100 # Limit number of Volumes in Pool + Label Format = "Full-" # Volumes will be labeled "Full-" +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Incremental.conf b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Incremental.conf new file mode 100644 index 00000000000..f4dbbab6650 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Incremental.conf @@ -0,0 +1,10 @@ +Pool { + Name = Incremental + Pool Type = Backup + Recycle = yes # Bareos can automatically recycle Volumes + AutoPrune = yes # Prune expired volumes + Volume Retention = 30 days # How long should the Incremental Backups be kept? (#12) + Maximum Volume Bytes = 1G # Limit Volume size to something reasonable + Maximum Volumes = 100 # Limit number of Volumes in Pool + Label Format = "Incremental-" # Volumes will be labeled "Incremental-" +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Scratch.conf b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Scratch.conf new file mode 100644 index 00000000000..3a489b19871 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Scratch.conf @@ -0,0 +1,4 @@ +Pool { + Name = Scratch + Pool Type = Scratch +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/profile/operator.conf b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/profile/operator.conf new file mode 100644 index 00000000000..6edd0166dca --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/profile/operator.conf @@ -0,0 +1,18 @@ +Profile { + Name = operator + Description = "Profile allowing normal Bareos operations." + + Command ACL = !.bvfs_clear_cache, !.exit, !.sql + Command ACL = !configure, !create, !delete, !purge, !prune, !sqlquery, !umount, !unmount + Command ACL = *all* + + Catalog ACL = *all* + Client ACL = *all* + FileSet ACL = *all* + Job ACL = *all* + Plugin Options ACL = *all* + Pool ACL = *all* + Schedule ACL = *all* + Storage ACL = *all* + Where ACL = *all* +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/storage/File.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/storage/File.conf.in new file mode 100644 index 00000000000..4058ddc7edc --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/storage/File.conf.in @@ -0,0 +1,8 @@ +Storage { + Name = File + Address = @hostname@ # N.B. Use a fully qualified name here (do not use "localhost" here). + Password = "@sd_password@" + Device = FileStorage + Media Type = File + SD Port = @sd_port@ +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/client/myself.conf.in new file mode 100644 index 00000000000..49039c29d18 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/client/myself.conf.in @@ -0,0 +1,19 @@ +Client { + Name = @basename@-fd + Maximum Concurrent Jobs = 20 + + # remove comment from "Plugin Directory" to load plugins from specified directory. + # if "Plugin Names" is defined, only the specified plugins will be loaded, + # otherwise all filedaemon plugins (*-fd.so) from the "Plugin Directory". + # + Plugin Directory = "@fd_plugin_binary_path@" + Plugin Names = "python" + + # if compatible is set to yes, we are compatible with bacula + # if set to no, new bareos features are enabled which is the default + # compatible = yes + + Working Directory = "@working_dir@" + Pid Directory = "@piddir@" + FD Port = @fd_port@ +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in new file mode 100644 index 00000000000..c8dc7085a45 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in @@ -0,0 +1,5 @@ +Director { + Name = bareos-dir + Password = "@fd_password@" + Description = "Allow the configured Director to access this file daemon." +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in new file mode 100644 index 00000000000..630c3a9abd3 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in @@ -0,0 +1,6 @@ +Director { + Name = bareos-mon + Password = "@mon_fd_password@" + Monitor = yes + Description = "Restricted Director, used by tray-monitor to get the status of this file daemon." +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/messages/Standard.conf b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/messages/Standard.conf new file mode 100644 index 00000000000..97788e00573 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/messages/Standard.conf @@ -0,0 +1,5 @@ +Messages { + Name = Standard + Director = bareos-dir = all, !skipped, !restored + Description = "Send relevant messages to the Director." +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/device/FileStorage.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/device/FileStorage.conf.in new file mode 100644 index 00000000000..d7f2d1dcf19 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/device/FileStorage.conf.in @@ -0,0 +1,11 @@ +Device { + Name = FileStorage + Media Type = File + Archive Device = @archivedir@ + LabelMedia = yes; # lets Bareos label unlabeled media + Random Access = yes; + AutomaticMount = yes; # when device opened, read it + RemovableMedia = no; + AlwaysOpen = no; + Description = "File device. A connecting Director must have the same Name and MediaType." +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in new file mode 100644 index 00000000000..deef3360c2d --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in @@ -0,0 +1,5 @@ +Director { + Name = bareos-dir + Password = "@sd_password@" + Description = "Director, who is permitted to contact this storage daemon." +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in new file mode 100644 index 00000000000..e3cfdee6315 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in @@ -0,0 +1,6 @@ +Director { + Name = bareos-mon + Password = "@mon_sd_password@" + Monitor = yes + Description = "Restricted Director, used by tray-monitor to get the status of this storage daemon." +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/messages/Standard.conf b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/messages/Standard.conf new file mode 100644 index 00000000000..468348e62fc --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/messages/Standard.conf @@ -0,0 +1,5 @@ +Messages { + Name = Standard + Director = bareos-dir = all + Description = "Send all messages to the Director." +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in new file mode 100644 index 00000000000..3e1723fa60c --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in @@ -0,0 +1,14 @@ +Storage { + Name = bareos-sd + Maximum Concurrent Jobs = 20 + + # remove comment from "Plugin Directory" to load plugins from specified directory. + # if "Plugin Names" is defined, only the specified plugins will be loaded, + # otherwise all storage plugins (*-sd.so) from the "Plugin Directory". + # + # Plugin Directory = "@python_plugin_module_src_sd@" + # Plugin Names = "" + Working Directory = "@working_dir@" + Pid Directory = "@piddir@" + SD Port = @sd_port@ +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bconsole.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bconsole.conf.in new file mode 100644 index 00000000000..ecb6ad00dce --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bconsole.conf.in @@ -0,0 +1,10 @@ +# +# Bareos User Agent (or Console) Configuration File +# + +Director { + Name = @basename@-dir + DIRport = @dir_port@ + address = @hostname@ + Password = "@dir_password@" +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in new file mode 100644 index 00000000000..dd00dd9f103 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in @@ -0,0 +1,5 @@ +Client { + Name = @basename@-fd + Address = localhost + Password = "@mon_fd_password@" # password for FileDaemon +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/director/Director-local.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/director/Director-local.conf.in new file mode 100644 index 00000000000..55dae492250 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/director/Director-local.conf.in @@ -0,0 +1,4 @@ +Director { + Name = bareos-dir + Address = localhost +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/monitor/bareos-mon.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/monitor/bareos-mon.conf.in new file mode 100644 index 00000000000..cddfa253945 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/monitor/bareos-mon.conf.in @@ -0,0 +1,7 @@ +Monitor { + # Name to establish connections to Director Console, Storage Daemon and File Daemon. + Name = bareos-mon + # Password to access the Director + Password = "@mon_dir_password@" # password for the Directors + RefreshInterval = 30 seconds +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in new file mode 100644 index 00000000000..6538f4fd248 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in @@ -0,0 +1,5 @@ +Storage { + Name = bareos-sd + Address = localhost + Password = "@mon_sd_password@" # password for StorageDaemon +} diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py b/systemtests/tests/python-fd-plugin-libcloud-test/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py new file mode 100644 index 00000000000..7a5c2e5e7a4 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py @@ -0,0 +1,353 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# BAREOS - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2014-2019 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation, which is +# listed in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# Author: Maik Aussendorf +# +# Bareos python plugins class that adds files from a local list to +# the backup fileset + +import bareosfd +from bareos_fd_consts import bJobMessageType, bFileType, bRCs +import os +import re +import hashlib +import time +import BareosFdPluginBaseclass + + +class BareosFdPluginLocalFilesetWithRestoreObjects( + BareosFdPluginBaseclass.BareosFdPluginBaseclass +): + """ + This Bareos-FD-Plugin-Class was created for automated test purposes only. + It is based on the BareosFdPluginLocalFileset class that parses a file + and backups all files listed there. + Filename is taken from plugin argument 'filename'. + In addition to the file backup and restore, this plugin also tests + restore objects of different sizes. As restore objects are compressed + automatically, when they are greater then 1000 bytes, both uncompressed + and compressed restore objects are tested. + """ + + def __init__(self, context, plugindef): + bareosfd.DebugMessage( + context, + 100, + "Constructor called in module %s with plugindef=%s\n" + % (__name__, plugindef), + ) + # Last argument of super constructor is a list of mandatory arguments + super(BareosFdPluginLocalFilesetWithRestoreObjects, self).__init__( + context, plugindef, ["filename"] + ) + self.files_to_backup = [] + self.allow = None + self.deny = None + self.object_index_seq = int((time.time() - 1546297200) * 10) + self.sha256sums_by_filename = {} + + def filename_is_allowed(self, context, filename, allowregex, denyregex): + """ + Check, if filename is allowed. + True, if matches allowreg and not denyregex. + If allowreg is None, filename always matches + If denyreg is None, it never matches + """ + if allowregex is None or allowregex.search(filename): + allowed = True + else: + allowed = False + if denyregex is None or not denyregex.search(filename): + denied = False + else: + denied = True + if not allowed or denied: + bareosfd.DebugMessage( + context, 100, "File %s denied by configuration\n" % (filename) + ) + bareosfd.JobMessage( + context, + bJobMessageType["M_ERROR"], + "File %s denied by configuration\n" % (filename), + ) + return False + else: + return True + + def start_backup_job(self, context): + """ + At this point, plugin options were passed and checked already. + We try to read from filename and setup the list of file to backup + in self.files_to_backup + """ + + bareosfd.DebugMessage( + context, + 100, + "Using %s to search for local files\n" % (self.options["filename"]), + ) + if os.path.exists(self.options["filename"]): + try: + config_file = open(self.options["filename"], "rb") + except: + bareosfd.DebugMessage( + context, + 100, + "Could not open file %s\n" % (self.options["filename"]), + ) + return bRCs["bRC_Error"] + else: + bareosfd.DebugMessage( + context, 100, "File %s does not exist\n" % (self.options["filename"]) + ) + return bRCs["bRC_Error"] + # Check, if we have allow or deny regular expressions defined + if "allow" in self.options: + self.allow = re.compile(self.options["allow"]) + if "deny" in self.options: + self.deny = re.compile(self.options["deny"]) + + for listItem in config_file.read().splitlines(): + if os.path.isfile(listItem) and self.filename_is_allowed( + context, listItem, self.allow, self.deny + ): + self.files_to_backup.append(listItem) + if os.path.isdir(listItem): + for topdir, dirNames, fileNames in os.walk(listItem): + for fileName in fileNames: + if self.filename_is_allowed( + context, + os.path.join(topdir, fileName), + self.allow, + self.deny, + ): + self.files_to_backup.append(os.path.join(topdir, fileName)) + if os.path.isfile(os.path.join(topdir, fileName)): + self.files_to_backup.append( + os.path.join(topdir, fileName) + ".sha256sum" + ) + self.files_to_backup.append( + os.path.join(topdir, fileName) + ".abspath" + ) + else: + if os.path.isfile(listItem): + self.files_to_backup.append(listItem + ".sha256sum") + self.files_to_backup.append(listItem + ".abspath") + + for longrestoreobject_length in range(998, 1004): + self.files_to_backup.append( + "%s.longrestoreobject" % longrestoreobject_length + ) + + if not self.files_to_backup: + bareosfd.JobMessage( + context, + bJobMessageType["M_ERROR"], + "No (allowed) files to backup found\n", + ) + return bRCs["bRC_Error"] + else: + return bRCs["bRC_Cancel"] + + def start_backup_file(self, context, savepkt): + """ + Defines the file to backup and creates the savepkt. In this example + only files (no directories) are allowed + """ + bareosfd.DebugMessage(context, 100, "start_backup_file() called\n") + if not self.files_to_backup: + bareosfd.DebugMessage(context, 100, "No files to backup\n") + return bRCs["bRC_Skip"] + + file_to_backup = self.files_to_backup.pop() + bareosfd.DebugMessage(context, 100, "file: " + file_to_backup + "\n") + + statp = bareosfd.StatPacket() + savepkt.statp = statp + + if file_to_backup.endswith(".sha256sum"): + checksum = self.get_sha256sum(context, os.path.splitext(file_to_backup)[0]) + savepkt.type = bFileType["FT_RESTORE_FIRST"] + savepkt.fname = file_to_backup + savepkt.object_name = file_to_backup + savepkt.object = bytearray(checksum) + savepkt.object_len = len(savepkt.object) + savepkt.object_index = self.object_index_seq + self.object_index_seq += 1 + + elif file_to_backup.endswith(".abspath"): + savepkt.type = bFileType["FT_RESTORE_FIRST"] + savepkt.fname = file_to_backup + savepkt.object_name = file_to_backup + savepkt.object = bytearray(os.path.splitext(file_to_backup)[0]) + savepkt.object_len = len(savepkt.object) + savepkt.object_index = self.object_index_seq + self.object_index_seq += 1 + + elif file_to_backup.endswith(".longrestoreobject"): + teststring_length = int(os.path.splitext(file_to_backup)[0]) + savepkt.type = bFileType["FT_RESTORE_FIRST"] + savepkt.fname = file_to_backup + savepkt.object_name = file_to_backup + savepkt.object = bytearray("a" * teststring_length) + savepkt.object_len = len(savepkt.object) + savepkt.object_index = self.object_index_seq + self.object_index_seq += 1 + + else: + savepkt.fname = file_to_backup + savepkt.type = bFileType["FT_REG"] + + bareosfd.JobMessage( + context, + bJobMessageType["M_INFO"], + "Starting backup of %s\n" % (file_to_backup), + ) + return bRCs["bRC_OK"] + + def end_backup_file(self, context): + """ + Here we return 'bRC_More' as long as our list files_to_backup is not + empty and bRC_OK when we are done + """ + bareosfd.DebugMessage( + context, 100, "end_backup_file() entry point in Python called\n" + ) + if self.files_to_backup: + return bRCs["bRC_More"] + else: + return bRCs["bRC_OK"] + + def set_file_attributes(self, context, restorepkt): + bareosfd.DebugMessage( + context, + 100, + "set_file_attributes() entry point in Python called with %s\n" + % (str(restorepkt)), + ) + + orig_fname = "/" + os.path.relpath(restorepkt.ofname, restorepkt.where) + restoreobject_sha256sum = self.sha256sums_by_filename[orig_fname] + + file_sha256sum = self.get_sha256sum(context, orig_fname) + bareosfd.DebugMessage( + context, + 100, + "set_file_attributes() orig_fname: %s restoreobject_sha256sum: %s file_sha256sum: %s\n" + % (orig_fname, repr(restoreobject_sha256sum), repr(file_sha256sum)), + ) + if file_sha256sum != restoreobject_sha256sum: + bareosfd.JobMessage( + context, + bJobMessageType["M_ERROR"], + "bad restoreobject orig_fname: %s restoreobject_sha256sum: %s file_sha256sum: %s\n" + % (orig_fname, repr(restoreobject_sha256sum), repr(file_sha256sum)), + ) + + return bRCs["bRC_OK"] + + def end_restore_file(self, context): + bareosfd.DebugMessage( + context, 100, "end_restore_file() self.FNAME: %s\n" % self.FNAME + ) + return bRCs["bRC_OK"] + + def restore_object_data(self, context, ROP): + """ + Note: + This is called in two cases: + - on diff/inc backup (should be called only once) + - on restore (for every job id being restored) + But at the point in time called, it is not possible + to distinguish which of them it is, because job type + is "I" until the bEventStartBackupJob event + """ + bareosfd.DebugMessage( + context, + 100, + "BareosFdPluginLocalFilesetWithRestoreObjects:restore_object_data() called with ROP:%s\n" + % (ROP), + ) + bareosfd.DebugMessage( + context, + 100, + "ROP.object_name(%s): %s\n" % (type(ROP.object_name), ROP.object_name), + ) + bareosfd.DebugMessage( + context, + 100, + "ROP.plugin_name(%s): %s\n" % (type(ROP.plugin_name), ROP.plugin_name), + ) + bareosfd.DebugMessage( + context, + 100, + "ROP.object_len(%s): %s\n" % (type(ROP.object_len), ROP.object_len), + ) + bareosfd.DebugMessage( + context, + 100, + "ROP.object_full_len(%s): %s\n" + % (type(ROP.object_full_len), ROP.object_full_len), + ) + bareosfd.DebugMessage( + context, 100, "ROP.object(%s): %s\n" % (type(ROP.object), repr(ROP.object)) + ) + orig_filename = os.path.splitext(ROP.object_name)[0] + if ROP.object_name.endswith(".sha256sum"): + self.sha256sums_by_filename[orig_filename] = str(ROP.object) + elif ROP.object_name.endswith(".abspath"): + if str(ROP.object) != orig_filename: + bareosfd.JobMessage( + context, + bJobMessageType["M_ERROR"], + "bad restoreobject orig_fname: %s restoreobject_fname: %s\n" + % (orig_filename, repr(str(ROP.object))), + ) + elif ROP.object_name.endswith(".longrestoreobject"): + stored_length = int(os.path.splitext(ROP.object_name)[0]) + if str(ROP.object) != "a" * stored_length: + bareosfd.JobMessage( + context, + bJobMessageType["M_ERROR"], + "bad long restoreobject %s does not match stored object\n" + % (ROP.object_name), + ) + else: + bareosfd.DebugMessage( + context, + 100, + "not checking restoreobject: %s\n" % (type(ROP.object_name)), + ) + return bRCs["bRC_OK"] + + def get_sha256sum(self, context, filename): + f = open(filename, "rb") + m = hashlib.sha256() + while True: + d = f.read(8096) + if not d: + break + m.update(d) + f.close() + return m.hexdigest() + + +# vim: ts=4 tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/python-modules/bareos-fd-local-fileset-with-restoreobjects.py b/systemtests/tests/python-fd-plugin-libcloud-test/python-modules/bareos-fd-local-fileset-with-restoreobjects.py new file mode 100644 index 00000000000..b64ef29960f --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/python-modules/bareos-fd-local-fileset-with-restoreobjects.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# BAREOS - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2014-2014 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation, which is +# listed in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +# +# bareos-fd-local-fileset-with-restoreobjects.py is a python Bareos FD Plugin using +# BareosFdPluginLocalFilesetWithRestoreObjects which was made for automated testing +# purposes. +# +# The plugin argument 'filename' is used to read all files listed in that file and +# add it to the fileset +# +# Author: Maik Aussendorf +# + +# Provided by the Bareos FD Python plugin interface +import bareos_fd_consts + +# This module contains the wrapper functions called by the Bareos-FD, the +# functions call the corresponding methods from your plugin class +import BareosFdWrapper + +# from BareosFdWrapper import parse_plugin_definition, handle_plugin_event, start_backup_file, end_backup_file, start_restore_file, end_restore_file, restore_object_data, plugin_io, create_file, check_file, handle_backup_file # noqa +from BareosFdWrapper import * # noqa + +# This module contains the used plugin class +import BareosFdPluginLocalFilesetWithRestoreObjects + + +def load_bareos_plugin(context, plugindef): + """ + This function is called by the Bareos-FD to load the plugin + We use it to instantiate the plugin class + """ + # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that + # holds the plugin class object + BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLocalFilesetWithRestoreObjects.BareosFdPluginLocalFilesetWithRestoreObjects( + context, plugindef + ) + return bareos_fd_consts.bRCs["bRC_OK"] + + +# the rest is done in the Plugin module diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/testrunner b/systemtests/tests/python-fd-plugin-libcloud-test/testrunner new file mode 100755 index 00000000000..6cb42514933 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/testrunner @@ -0,0 +1,74 @@ +#!/bin/bash +# +# This systemtest tests the plugin functionality +# of the Bareos FD by using the supplied module +# bareos-fd-local-fileset.py +# +# The module will backup some files. +# This plugin is not intended for production, +# but is only a minimal example that shows +# how to use the python plugin interface. +# File attributes like uses and times will not be saved. +# +TestName="$(basename "$(pwd)")" +export TestName + +JobName=backup-bareos-fd +#shellcheck source=../environment.in +. ./environment + +JobName=backup-bareos-fd +#shellcheck source=../scripts/functions +. "${rscripts}"/functions +"${rscripts}"/cleanup +"${rscripts}"/setup + + + +# Directory to backup. +# This directory will be created by setup_data "$@"(). +BackupDirectory="${tmp}/data" + +# Use a tgz to setup data to be backed up. +# Data will be placed at "${tmp}/data/". +setup_data "$@" + +# this test does not work with links because of the restore objects +rm -r "${tmp}"/data/weird-files >/dev/null 2>&1 + +start_test + +cat <$tmp/bconcmds +@$out /dev/null +messages +@$out $tmp/log1.out +setdebug level=100 storage=File +label volume=TestVolume001 storage=File pool=Full +run job=$JobName yes +status director +status client +status storage=File +wait +messages +@# +@# now do a restore +@# +@$out $tmp/log2.out +wait +restore client=bareos-fd fileset=PluginTest where=$tmp/bareos-restores select all done +yes +wait +messages +quit +END_OF_DATA + +run_bareos "$@" +check_for_zombie_jobs storage=File +stop_bareos + +check_two_logs +list=( $(find "${BackupDirectory}" -type f) ) +# Using check_restore_only_files_diff instead of check_restore_diff +# to don't diff the file attributes, because they are not saved +check_restore_only_files_diff "${list[@]}" +end_test From d64031aa4066b8cf30ad0b7b2a1bb72b70d8bb82 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 5 Mar 2020 12:22:39 +0100 Subject: [PATCH 249/341] libcloud-plugin: apply black format to libcloud fd plugin code --- .../plugins/filed/BareosFdPluginLibcloud.py | 774 +++++++++--------- core/src/plugins/filed/bareos-fd-libcloud.py | 14 +- 2 files changed, 410 insertions(+), 378 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index da4a6754024..144239395ac 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -43,404 +43,434 @@ def log(message): - if debug is True: - message = '[%s] %s' % (os.getpid(), message) - syslog.syslog(message) + if debug is True: + message = "[%s] %s" % (os.getpid(), message) + syslog.syslog(message) def error(message): - message = '[%s] %s' % (os.getpid(), message) - syslog.syslog(message) + message = "[%s] %s" % (os.getpid(), message) + syslog.syslog(message) # Print the traceback to syslog def log_exc(): - for line in traceback.format_exc().split('\n'): - error(line) + for line in traceback.format_exc().split("\n"): + error(line) class IterStringIO(io.BufferedIOBase): - def __init__(self, iterable): - self.iter = itertools.chain.from_iterable(iterable) + def __init__(self, iterable): + self.iter = itertools.chain.from_iterable(iterable) - def read(self, n=None): - return bytearray(itertools.islice(self.iter, None, n)) + def read(self, n=None): + return bytearray(itertools.islice(self.iter, None, n)) def str2bool(data): - if data == 'false' or data == 'False': - return False - if data == 'true' or data == 'True': - return True - raise Exception('%s: not a boolean' % (data,)) + if data == "false" or data == "False": + return False + if data == "true" or data == "True": + return True + raise Exception("%s: not a boolean" % (data,)) def connect(options): - driver_opt = dict(options) - - # Some drivers does not support unknown options - # Here, we remove those used by libcloud and let the rest pass through - for opt in ('buckets_exclude', 'accurate', 'nb_prefetcher', 'prefetch_size', 'queue_size', 'provider', 'buckets_include', 'debug'): - if opt in options: - del driver_opt[opt] - - provider = getattr(Provider, options['provider']) - driver = get_driver(provider)(**driver_opt) - return driver + driver_opt = dict(options) + + # Some drivers does not support unknown options + # Here, we remove those used by libcloud and let the rest pass through + for opt in ( + "buckets_exclude", + "accurate", + "nb_prefetcher", + "prefetch_size", + "queue_size", + "provider", + "buckets_include", + "debug", + ): + if opt in options: + del driver_opt[opt] + + provider = getattr(Provider, options["provider"]) + driver = get_driver(provider)(**driver_opt) + return driver def get_object(driver, bucket, key): - try: - return driver.get_object(bucket, key) - except libcloud.common.types.InvalidCredsError: - # Something is buggy here, this bug is triggered by tilde-ending objects - # Our tokens are good, we used then before - error('BUGGY filename found, see the libcloud bug somewhere : %s/%s' % (bucket, key)) - return None + try: + return driver.get_object(bucket, key) + except libcloud.common.types.InvalidCredsError: + # Something is buggy here, this bug is triggered by tilde-ending objects + # Our tokens are good, we used then before + error( + "BUGGY filename found, see the libcloud bug somewhere : %s/%s" + % (bucket, key) + ) + return None class Prefetcher(object): - def __init__(self, options, plugin_todo_queue, pref_todo_queue): - self.options = options - self.plugin_todo_queue = plugin_todo_queue - self.pref_todo_queue = pref_todo_queue - - def __call__(self): - try: - self.driver = connect(self.options) - self.__work() - except: - log('FATAL ERROR: I am a prefetcher, and I am dying !') - log_exc() - - def __work(self): - while True: - job = self.pref_todo_queue.get() - if job is None: - log('prefetcher[%s] : job completed, I will now die' % (os.getpid(),)) - return - - obj = get_object(self.driver, job['bucket'], job['name']) - if obj is None: - # Object cannot be fetched, an error is already logged - continue - - stream = obj.as_stream() - content = b''.join(list(stream)) - - prefetched = len(content) - if prefetched != job['size']: - error('FATAL ERROR: prefetched file %s: got %s bytes, not the real size (%s bytes)' % (job['name'], prefetched, job['size'])) - return - - data = io.BytesIO(content) - - job['data'] = data - self.plugin_todo_queue.put(job) + def __init__(self, options, plugin_todo_queue, pref_todo_queue): + self.options = options + self.plugin_todo_queue = plugin_todo_queue + self.pref_todo_queue = pref_todo_queue + + def __call__(self): + try: + self.driver = connect(self.options) + self.__work() + except: + log("FATAL ERROR: I am a prefetcher, and I am dying !") + log_exc() + + def __work(self): + while True: + job = self.pref_todo_queue.get() + if job is None: + log("prefetcher[%s] : job completed, I will now die" % (os.getpid(),)) + return + + obj = get_object(self.driver, job["bucket"], job["name"]) + if obj is None: + # Object cannot be fetched, an error is already logged + continue + + stream = obj.as_stream() + content = b"".join(list(stream)) + + prefetched = len(content) + if prefetched != job["size"]: + error( + "FATAL ERROR: prefetched file %s: got %s bytes, not the real size (%s bytes)" + % (job["name"], prefetched, job["size"]) + ) + return + + data = io.BytesIO(content) + + job["data"] = data + self.plugin_todo_queue.put(job) class Writer(object): - def __init__(self, plugin_todo_queue, pref_todo_queue, last_run, opts, pids): - self.plugin_todo_queue = plugin_todo_queue - self.pref_todo_queue = pref_todo_queue - self.last_run = last_run - self.options = opts - self.pids = pids - - self.driver = connect(self.options) - self.delta = datetime.timedelta(seconds=time.timezone) - - def __call__(self): - try: - self.__map() - except: - log_exc() - self.__end_job() - - def __map(self): - for bucket in self.driver.iterate_containers(): - if self.options['buckets_include'] is not None: - if bucket.name not in self.options['buckets_include']: - continue - - if self.options['buckets_exclude'] is not None: - if bucket.name in self.options['buckets_exclude']: - continue - - log('Backuping bucket %s' % (bucket.name,)) - - self.__generate(self.driver.iterate_container_objects(bucket)) - - def __get_mtime(self, obj): - mtime = dateutil.parser.parse(obj.extra['last_modified']) - mtime = mtime - self.delta - mtime = mtime.replace(tzinfo=None) - - ts = time.mktime(mtime.timetuple()) - return mtime, ts - - def __generate(self, iterator): - for obj in iterator: - mtime, mtime_ts = self.__get_mtime(obj) - - result = {'name': obj.name, - 'bucket': obj.container.name, - 'data': None, - 'size': obj.size, - 'mtime': mtime_ts - } - - pseudo = '%s/%s' % (obj.container.name, obj.name) - - if self.last_run > mtime: - log('File %s not changed, skipped (%s > %s)' % (pseudo, self.last_run, mtime)) - - # This object was present on our last backup - # Here, we push it directly to bareos, it will not be backed again - # but remembered as "still here" (for accurate mode) - # If accurate mode is off, we can simply skip that object - if self.options['accurate'] is True: - self.plugin_todo_queue.put(result) - - continue - - log('File %s changed (or new), backuping (%s < %s)' % (pseudo, self.last_run, mtime)) - - # Do not prefetch large objects - if obj.size >= self.options['prefetch_size']: - self.plugin_todo_queue.put(result) - else: - self.pref_todo_queue.put(result) - - def __end_job(self): - log('__end_job: waiting for prefetchers queue to drain') - while True: - size = self.pref_todo_queue.qsize() - if size == 0: - break - log('__end_job: %s items left in prefetchers queue, waiting' % (size,)) - time.sleep(2) - log('__end_job: prefetchers queue is drained') - - log('__end_job: I will ask prefetchers to die') - for i in range(0, self.options['nb_prefetcher']): - self.pref_todo_queue.put(None) - - # This is the last item ever put on that queue - # The plugin on the other end will know the backup is completed - self.plugin_todo_queue.put(None) + def __init__(self, plugin_todo_queue, pref_todo_queue, last_run, opts, pids): + self.plugin_todo_queue = plugin_todo_queue + self.pref_todo_queue = pref_todo_queue + self.last_run = last_run + self.options = opts + self.pids = pids + + self.driver = connect(self.options) + self.delta = datetime.timedelta(seconds=time.timezone) + + def __call__(self): + try: + self.__map() + except: + log_exc() + self.__end_job() + + def __map(self): + for bucket in self.driver.iterate_containers(): + if self.options["buckets_include"] is not None: + if bucket.name not in self.options["buckets_include"]: + continue + + if self.options["buckets_exclude"] is not None: + if bucket.name in self.options["buckets_exclude"]: + continue + + log("Backuping bucket %s" % (bucket.name,)) + + self.__generate(self.driver.iterate_container_objects(bucket)) + + def __get_mtime(self, obj): + mtime = dateutil.parser.parse(obj.extra["last_modified"]) + mtime = mtime - self.delta + mtime = mtime.replace(tzinfo=None) + + ts = time.mktime(mtime.timetuple()) + return mtime, ts + + def __generate(self, iterator): + for obj in iterator: + mtime, mtime_ts = self.__get_mtime(obj) + + result = { + "name": obj.name, + "bucket": obj.container.name, + "data": None, + "size": obj.size, + "mtime": mtime_ts, + } + + pseudo = "%s/%s" % (obj.container.name, obj.name) + + if self.last_run > mtime: + log( + "File %s not changed, skipped (%s > %s)" + % (pseudo, self.last_run, mtime) + ) + + # This object was present on our last backup + # Here, we push it directly to bareos, it will not be backed again + # but remembered as "still here" (for accurate mode) + # If accurate mode is off, we can simply skip that object + if self.options["accurate"] is True: + self.plugin_todo_queue.put(result) + + continue + + log( + "File %s changed (or new), backuping (%s < %s)" + % (pseudo, self.last_run, mtime) + ) + + # Do not prefetch large objects + if obj.size >= self.options["prefetch_size"]: + self.plugin_todo_queue.put(result) + else: + self.pref_todo_queue.put(result) + + def __end_job(self): + log("__end_job: waiting for prefetchers queue to drain") + while True: + size = self.pref_todo_queue.qsize() + if size == 0: + break + log("__end_job: %s items left in prefetchers queue, waiting" % (size,)) + time.sleep(2) + log("__end_job: prefetchers queue is drained") + + log("__end_job: I will ask prefetchers to die") + for i in range(0, self.options["nb_prefetcher"]): + self.pref_todo_queue.put(None) + + # This is the last item ever put on that queue + # The plugin on the other end will know the backup is completed + self.plugin_todo_queue.put(None) class BareosFdPluginLibcloud(BareosFdPluginBaseclass.BareosFdPluginBaseclass): - def __init__(self, context, plugindef): - log('BareosFdPluginLibcloud called with plugindef: %s' % (plugindef,)) - - super(BareosFdPluginLibcloud, self).__init__(context, plugindef) - super(BareosFdPluginLibcloud, self).parse_plugin_definition(context, plugindef) - self.__parse_options(context) - - self.last_run = datetime.datetime.fromtimestamp(self.since) - self.last_run = self.last_run.replace(tzinfo=None) - - # We force an action to the backend, to test our params - # If we can get anything, then it is ok - # Else, an exception will be raised, and the job will fail - driver = connect(self.options) - for _ in driver.iterate_containers(): - break - - # The job in process - # Setto None when the whole backup is completed - # Restore's path will not touch this - self.job = {} - - log('Last backup: %s (ts: %s)' % (self.last_run, self.since)) - - def __parse_options_bucket(self, name): - if name not in self.options: - self.options[name] = None - else: - buckets = list() - for bucket in self.options[name].split(','): - buckets.append(bucket) - self.options[name] = buckets - - def __parse_opt_int(self, name): - if name not in self.options: - return - - value = self.options[name] - self.options[name] = int(value) - - def __parse_options(self, context): - # Set our default values - if 'nb_prefetcher' not in self.options: - self.options['nb_prefetcher'] = 24 - if 'queue_size' not in self.options: - self.options['queue_size'] = 1000 - if 'prefetch_size' not in self.options: - self.options['prefetch_size'] = 10 * 1024 * 1024 - self.__parse_options_bucket('buckets_include') - self.__parse_options_bucket('buckets_exclude') - - # Do a couple of sanitization - if 'secure' in self.options: - old = self.options['secure'] - self.options['secure'] = str2bool(old) - - self.__parse_opt_int('port') - self.__parse_opt_int('nb_prefetcher') - self.__parse_opt_int('prefetch_size') - self.__parse_opt_int('queue_size') - self.__parse_opt_int('prefetch_size') - - if 'debug' in self.options: - old = self.options['debug'] - self.options['debug'] = str2bool(old) - - # Setup debugging - if self.options['debug'] is True: - global debug - debug = True - - accurate = bareos_fd_consts.bVariable['bVarAccurate'] - accurate = bareosfd.GetValue(context, accurate) - if accurate is None or accurate == 0: - self.options['accurate'] = False - else: - self.options['accurate'] = True - - def parse_plugin_definition(self, context, plugindef): - return bRCs['bRC_OK'] - - def start_backup_job(self, context): - self.manager = multiprocessing.Manager() - self.plugin_todo_queue = self.manager.Queue(maxsize=self.options['queue_size']) - self.pref_todo_queue = self.manager.Queue(maxsize=self.options['nb_prefetcher']) - - self.pf_pids = list() - self.prefetchers = list() - for i in range(0, self.options['nb_prefetcher']): - target = Prefetcher(self.options, self.plugin_todo_queue, self.pref_todo_queue) - proc = multiprocessing.Process(target=target) - proc.start() - self.pf_pids.append(proc.pid) - self.prefetchers.append(proc) - log('%s prefetcher started' % (len(self.pf_pids),)) - - writer = Writer(self.plugin_todo_queue, self.pref_todo_queue, self.last_run, self.options, self.pf_pids) - self.writer = multiprocessing.Process(target=writer) - self.writer.start() - self.driver = connect(self.options) - - def check_file(self, context, fname): - # All existing files are passed to bareos - # If bareos have not seen one, it does not exists anymore - return bRCs['bRC_Error'] - - def start_backup_file(self, context, savepkt): - try: - while True: - try: - self.job = self.plugin_todo_queue.get_nowait() - break - except: - size = self.plugin_todo_queue.qsize() - log('start_backup_file: queue is near empty : %s' % (size,)) - time.sleep(0.1) - except TypeError: - self.job = None - - if self.job is None: - log('End of queue found, backup is completed') - for i in self.prefetchers: - log('join() for a prefetcher (pid %s)' % (i.pid,)) - i.join() - log('Ok, all prefetchers are dead') - - try: - self.manager.shutdown() - except OSError: - # manager already dead, somehow ?! - pass - log('self.manager.shutdown()') - - log('Join() for the writer (pid %s)' % (self.writer.pid,)) - self.writer.join() - log('writer is dead') - - # savepkt is always checked, so we fill it with a dummy value - savepkt.fname = 'empty' - return bRCs['bRC_Skip'] - - filename = '%s/%s' % (self.job['bucket'], self.job['name']) - log('Backuping %s' % (filename,)) - - statp = bareosfd.StatPacket() - statp.size = self.job['size'] - statp.mtime = self.job['mtime'] - statp.atime = 0 - statp.ctime = 0 - - savepkt.statp = statp - savepkt.fname = filename - savepkt.type = bareos_fd_consts.bFileType['FT_REG'] - - return bRCs['bRC_OK'] - - def plugin_io(self, context, IOP): - if self.job is None: - return bRCs['bRC_Error'] - if IOP.func == bIOPS['IO_OPEN']: - # Only used by the 'restore' path - if IOP.flags & (os.O_CREAT | os.O_WRONLY): - self.FILE = open(IOP.fname, 'wb') - return bRCs['bRC_OK'] - - # 'Backup' path - if self.job['data'] is None: - obj = get_object(self.driver, self.job['bucket'], self.job['name']) - if obj is None: - self.FILE = None - return bRCs['bRC_Error'] - self.FILE = IterStringIO(obj.as_stream()) - else: - self.FILE = self.job['data'] - - elif IOP.func == bIOPS['IO_READ']: - IOP.buf = bytearray(IOP.count) - IOP.io_errno = 0 - if self.FILE is None: - return bRCs['bRC_Error'] - try: - buf = self.FILE.read(IOP.count) - IOP.buf[:] = buf - IOP.status = len(buf) - return bRCs['bRC_OK'] - except IOError as e: - log('Cannot read from %s : %s' % (IOP.fname, e)) - IOP.status = 0 - IOP.io_errno = e.errno - return bRCs['bRC_Error'] - - elif IOP.func == bIOPS['IO_WRITE']: - try: - self.FILE.write(IOP.buf) - IOP.status = IOP.count - IOP.io_errno = 0 - except IOError as msg: - IOP.io_errno = -1 - error('Failed to write data: %s' % (msg,)) - return bRCs['bRC_OK'] - elif IOP.func == bIOPS['IO_CLOSE']: - if self.FILE: - self.FILE.close() - return bRCs['bRC_OK'] - - return bRCs['bRC_OK'] - - def end_backup_file(self, context): - if self.job is not None: - return bRCs['bRC_More'] - else: - return bRCs['bRC_OK'] + def __init__(self, context, plugindef): + log("BareosFdPluginLibcloud called with plugindef: %s" % (plugindef,)) + + super(BareosFdPluginLibcloud, self).__init__(context, plugindef) + super(BareosFdPluginLibcloud, self).parse_plugin_definition(context, plugindef) + self.__parse_options(context) + + self.last_run = datetime.datetime.fromtimestamp(self.since) + self.last_run = self.last_run.replace(tzinfo=None) + + # We force an action to the backend, to test our params + # If we can get anything, then it is ok + # Else, an exception will be raised, and the job will fail + driver = connect(self.options) + for _ in driver.iterate_containers(): + break + + # The job in process + # Setto None when the whole backup is completed + # Restore's path will not touch this + self.job = {} + + log("Last backup: %s (ts: %s)" % (self.last_run, self.since)) + + def __parse_options_bucket(self, name): + if name not in self.options: + self.options[name] = None + else: + buckets = list() + for bucket in self.options[name].split(","): + buckets.append(bucket) + self.options[name] = buckets + + def __parse_opt_int(self, name): + if name not in self.options: + return + + value = self.options[name] + self.options[name] = int(value) + + def __parse_options(self, context): + # Set our default values + if "nb_prefetcher" not in self.options: + self.options["nb_prefetcher"] = 24 + if "queue_size" not in self.options: + self.options["queue_size"] = 1000 + if "prefetch_size" not in self.options: + self.options["prefetch_size"] = 10 * 1024 * 1024 + self.__parse_options_bucket("buckets_include") + self.__parse_options_bucket("buckets_exclude") + + # Do a couple of sanitization + if "secure" in self.options: + old = self.options["secure"] + self.options["secure"] = str2bool(old) + + self.__parse_opt_int("port") + self.__parse_opt_int("nb_prefetcher") + self.__parse_opt_int("prefetch_size") + self.__parse_opt_int("queue_size") + self.__parse_opt_int("prefetch_size") + + if "debug" in self.options: + old = self.options["debug"] + self.options["debug"] = str2bool(old) + + # Setup debugging + if self.options["debug"] is True: + global debug + debug = True + + accurate = bareos_fd_consts.bVariable["bVarAccurate"] + accurate = bareosfd.GetValue(context, accurate) + if accurate is None or accurate == 0: + self.options["accurate"] = False + else: + self.options["accurate"] = True + + def parse_plugin_definition(self, context, plugindef): + return bRCs["bRC_OK"] + + def start_backup_job(self, context): + self.manager = multiprocessing.Manager() + self.plugin_todo_queue = self.manager.Queue(maxsize=self.options["queue_size"]) + self.pref_todo_queue = self.manager.Queue(maxsize=self.options["nb_prefetcher"]) + + self.pf_pids = list() + self.prefetchers = list() + for i in range(0, self.options["nb_prefetcher"]): + target = Prefetcher( + self.options, self.plugin_todo_queue, self.pref_todo_queue + ) + proc = multiprocessing.Process(target=target) + proc.start() + self.pf_pids.append(proc.pid) + self.prefetchers.append(proc) + log("%s prefetcher started" % (len(self.pf_pids),)) + + writer = Writer( + self.plugin_todo_queue, + self.pref_todo_queue, + self.last_run, + self.options, + self.pf_pids, + ) + self.writer = multiprocessing.Process(target=writer) + self.writer.start() + self.driver = connect(self.options) + + def check_file(self, context, fname): + # All existing files are passed to bareos + # If bareos have not seen one, it does not exists anymore + return bRCs["bRC_Error"] + + def start_backup_file(self, context, savepkt): + try: + while True: + try: + self.job = self.plugin_todo_queue.get_nowait() + break + except: + size = self.plugin_todo_queue.qsize() + log("start_backup_file: queue is near empty : %s" % (size,)) + time.sleep(0.1) + except TypeError: + self.job = None + + if self.job is None: + log("End of queue found, backup is completed") + for i in self.prefetchers: + log("join() for a prefetcher (pid %s)" % (i.pid,)) + i.join() + log("Ok, all prefetchers are dead") + + try: + self.manager.shutdown() + except OSError: + # manager already dead, somehow ?! + pass + log("self.manager.shutdown()") + + log("Join() for the writer (pid %s)" % (self.writer.pid,)) + self.writer.join() + log("writer is dead") + + # savepkt is always checked, so we fill it with a dummy value + savepkt.fname = "empty" + return bRCs["bRC_Skip"] + + filename = "%s/%s" % (self.job["bucket"], self.job["name"]) + log("Backuping %s" % (filename,)) + + statp = bareosfd.StatPacket() + statp.size = self.job["size"] + statp.mtime = self.job["mtime"] + statp.atime = 0 + statp.ctime = 0 + + savepkt.statp = statp + savepkt.fname = filename + savepkt.type = bareos_fd_consts.bFileType["FT_REG"] + + return bRCs["bRC_OK"] + + def plugin_io(self, context, IOP): + if self.job is None: + return bRCs["bRC_Error"] + if IOP.func == bIOPS["IO_OPEN"]: + # Only used by the 'restore' path + if IOP.flags & (os.O_CREAT | os.O_WRONLY): + self.FILE = open(IOP.fname, "wb") + return bRCs["bRC_OK"] + + # 'Backup' path + if self.job["data"] is None: + obj = get_object(self.driver, self.job["bucket"], self.job["name"]) + if obj is None: + self.FILE = None + return bRCs["bRC_Error"] + self.FILE = IterStringIO(obj.as_stream()) + else: + self.FILE = self.job["data"] + + elif IOP.func == bIOPS["IO_READ"]: + IOP.buf = bytearray(IOP.count) + IOP.io_errno = 0 + if self.FILE is None: + return bRCs["bRC_Error"] + try: + buf = self.FILE.read(IOP.count) + IOP.buf[:] = buf + IOP.status = len(buf) + return bRCs["bRC_OK"] + except IOError as e: + log("Cannot read from %s : %s" % (IOP.fname, e)) + IOP.status = 0 + IOP.io_errno = e.errno + return bRCs["bRC_Error"] + + elif IOP.func == bIOPS["IO_WRITE"]: + try: + self.FILE.write(IOP.buf) + IOP.status = IOP.count + IOP.io_errno = 0 + except IOError as msg: + IOP.io_errno = -1 + error("Failed to write data: %s" % (msg,)) + return bRCs["bRC_OK"] + elif IOP.func == bIOPS["IO_CLOSE"]: + if self.FILE: + self.FILE.close() + return bRCs["bRC_OK"] + + return bRCs["bRC_OK"] + + def end_backup_file(self, context): + if self.job is not None: + return bRCs["bRC_More"] + else: + return bRCs["bRC_OK"] diff --git a/core/src/plugins/filed/bareos-fd-libcloud.py b/core/src/plugins/filed/bareos-fd-libcloud.py index c3b13b9a156..44a6a1cc61b 100644 --- a/core/src/plugins/filed/bareos-fd-libcloud.py +++ b/core/src/plugins/filed/bareos-fd-libcloud.py @@ -25,6 +25,7 @@ # This module contains the wrapper functions called by the Bareos-FD, the # functions call the corresponding methods from your plugin class import BareosFdWrapper + # from BareosFdWrapper import parse_plugin_definition, handle_plugin_event, start_backup_file, end_backup_file, start_restore_file, end_restore_file, restore_object_data, plugin_io, create_file, check_file, handle_backup_file # noqa from BareosFdWrapper import * # noqa @@ -33,15 +34,16 @@ def load_bareos_plugin(context, plugindef): - ''' + """ This function is called by the Bareos-FD to load the plugin We use it to instantiate the plugin class - ''' + """ # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that # holds the plugin class object - BareosFdWrapper.bareos_fd_plugin_object = \ - BareosFdPluginLibcloud.BareosFdPluginLibcloud( - context, plugindef) - return bareos_fd_consts.bRCs['bRC_OK'] + BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLibcloud.BareosFdPluginLibcloud( + context, plugindef + ) + return bareos_fd_consts.bRCs["bRC_OK"] + # the rest is done in the Plugin module From d9b99f062924dc363c86f9f81caec08161067680 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 5 Mar 2020 15:31:18 +0100 Subject: [PATCH 250/341] libcloud-plugin: rename a variable --- core/src/plugins/filed/BareosFdPluginLibcloud.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 144239395ac..60402a40a45 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -198,7 +198,7 @@ def __generate(self, iterator): for obj in iterator: mtime, mtime_ts = self.__get_mtime(obj) - result = { + job = { "name": obj.name, "bucket": obj.container.name, "data": None, @@ -219,7 +219,7 @@ def __generate(self, iterator): # but remembered as "still here" (for accurate mode) # If accurate mode is off, we can simply skip that object if self.options["accurate"] is True: - self.plugin_todo_queue.put(result) + self.plugin_todo_queue.put(job) continue @@ -230,9 +230,9 @@ def __generate(self, iterator): # Do not prefetch large objects if obj.size >= self.options["prefetch_size"]: - self.plugin_todo_queue.put(result) + self.plugin_todo_queue.put(job) else: - self.pref_todo_queue.put(result) + self.pref_todo_queue.put(job) def __end_job(self): log("__end_job: waiting for prefetchers queue to drain") From 9346f6a2a0153c4973490bc1eb889e397c9ab769 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 5 Mar 2020 15:52:32 +0100 Subject: [PATCH 251/341] libcloud-plugin: reword names and log entries --- .../plugins/filed/BareosFdPluginLibcloud.py | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 60402a40a45..ac55b27bdc6 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -122,14 +122,14 @@ def __call__(self): self.driver = connect(self.options) self.__work() except: - log("FATAL ERROR: I am a prefetcher, and I am dying !") + log("FATAL ERROR: prefetcher could not connect to driver") log_exc() def __work(self): while True: job = self.pref_todo_queue.get() if job is None: - log("prefetcher[%s] : job completed, I will now die" % (os.getpid(),)) + log("prefetcher[%s] : job completed, will quit now" % (os.getpid(),)) return obj = get_object(self.driver, job["bucket"], job["name"]) @@ -167,12 +167,12 @@ def __init__(self, plugin_todo_queue, pref_todo_queue, last_run, opts, pids): def __call__(self): try: - self.__map() + self.__iterate_over_buckets() except: log_exc() self.__end_job() - def __map(self): + def __iterate_over_buckets(self): for bucket in self.driver.iterate_containers(): if self.options["buckets_include"] is not None: if bucket.name not in self.options["buckets_include"]: @@ -182,9 +182,9 @@ def __map(self): if bucket.name in self.options["buckets_exclude"]: continue - log("Backuping bucket %s" % (bucket.name,)) + log("Backing up bucket \"%s\"" % (bucket.name,)) - self.__generate(self.driver.iterate_container_objects(bucket)) + self.__generate_jobs_for_bucket_objects(self.driver.iterate_container_objects(bucket)) def __get_mtime(self, obj): mtime = dateutil.parser.parse(obj.extra["last_modified"]) @@ -194,8 +194,8 @@ def __get_mtime(self, obj): ts = time.mktime(mtime.timetuple()) return mtime, ts - def __generate(self, iterator): - for obj in iterator: + def __generate_jobs_for_bucket_objects(self, bucket_iterator): + for obj in bucket_iterator: mtime, mtime_ts = self.__get_mtime(obj) job = { @@ -206,12 +206,12 @@ def __generate(self, iterator): "mtime": mtime_ts, } - pseudo = "%s/%s" % (obj.container.name, obj.name) + object_name = "%s/%s" % (obj.container.name, obj.name) if self.last_run > mtime: log( "File %s not changed, skipped (%s > %s)" - % (pseudo, self.last_run, mtime) + % (object_name, self.last_run, mtime) ) # This object was present on our last backup @@ -224,8 +224,8 @@ def __generate(self, iterator): continue log( - "File %s changed (or new), backuping (%s < %s)" - % (pseudo, self.last_run, mtime) + "File %s was changed or is new, backing up (%s < %s)" + % (object_name, self.last_run, mtime) ) # Do not prefetch large objects @@ -235,16 +235,16 @@ def __generate(self, iterator): self.pref_todo_queue.put(job) def __end_job(self): - log("__end_job: waiting for prefetchers queue to drain") + log("__end_job: waiting for prefetchers queue to become empty") while True: size = self.pref_todo_queue.qsize() if size == 0: break log("__end_job: %s items left in prefetchers queue, waiting" % (size,)) time.sleep(2) - log("__end_job: prefetchers queue is drained") + log("__end_job: prefetchers queue is empty") - log("__end_job: I will ask prefetchers to die") + log("__end_job: I will shutdown all prefetchers now") for i in range(0, self.options["nb_prefetcher"]): self.pref_todo_queue.put(None) @@ -376,7 +376,7 @@ def start_backup_file(self, context, savepkt): break except: size = self.plugin_todo_queue.qsize() - log("start_backup_file: queue is near empty : %s" % (size,)) + log("start_backup_file: queue size: %s" % (size,)) time.sleep(0.1) except TypeError: self.job = None @@ -386,25 +386,25 @@ def start_backup_file(self, context, savepkt): for i in self.prefetchers: log("join() for a prefetcher (pid %s)" % (i.pid,)) i.join() - log("Ok, all prefetchers are dead") + log("Ok, all prefetchers are shut down") try: self.manager.shutdown() except OSError: - # manager already dead, somehow ?! + # should not happen! pass log("self.manager.shutdown()") log("Join() for the writer (pid %s)" % (self.writer.pid,)) self.writer.join() - log("writer is dead") + log("writer is shut down") # savepkt is always checked, so we fill it with a dummy value savepkt.fname = "empty" return bRCs["bRC_Skip"] filename = "%s/%s" % (self.job["bucket"], self.job["name"]) - log("Backuping %s" % (filename,)) + log("Backing up %s" % (filename,)) statp = bareosfd.StatPacket() statp.size = self.job["size"] From 7b50e0899ffcd030da8392f0ae91eff956d8d96a Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 5 Mar 2020 16:11:16 +0100 Subject: [PATCH 252/341] libcloud-plugin: replace an unused loopcounter by underscore --- core/src/plugins/filed/BareosFdPluginLibcloud.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index ac55b27bdc6..1ba8cfd87b6 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -245,7 +245,7 @@ def __end_job(self): log("__end_job: prefetchers queue is empty") log("__end_job: I will shutdown all prefetchers now") - for i in range(0, self.options["nb_prefetcher"]): + for _ in range(0, self.options["nb_prefetcher"]): self.pref_todo_queue.put(None) # This is the last item ever put on that queue @@ -342,7 +342,7 @@ def start_backup_job(self, context): self.pf_pids = list() self.prefetchers = list() - for i in range(0, self.options["nb_prefetcher"]): + for _ in range(0, self.options["nb_prefetcher"]): target = Prefetcher( self.options, self.plugin_todo_queue, self.pref_todo_queue ) From acacbe156b0a64a3ca1e6bb3e2293f9dfa8e5b06 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 5 Mar 2020 16:33:23 +0100 Subject: [PATCH 253/341] libcloud-plugin: synchronize the shutdown process with the workers --- core/src/plugins/filed/BareosFdPluginLibcloud.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 1ba8cfd87b6..4e29c04aa47 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -248,8 +248,10 @@ def __end_job(self): for _ in range(0, self.options["nb_prefetcher"]): self.pref_todo_queue.put(None) - # This is the last item ever put on that queue - # The plugin on the other end will know the backup is completed + while not self.pref_todo_queue.empty(): + pass + + # notify the plugin that the workers are ready self.plugin_todo_queue.put(None) From efe8582cfc9198c71c73a3c38fc720fb2097eb31 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 5 Mar 2020 16:34:40 +0100 Subject: [PATCH 254/341] libcloud-plugin: rename a queue and a list --- .../plugins/filed/BareosFdPluginLibcloud.py | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 4e29c04aa47..3792cf4b8f1 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -112,10 +112,10 @@ def get_object(driver, bucket, key): class Prefetcher(object): - def __init__(self, options, plugin_todo_queue, pref_todo_queue): + def __init__(self, options, plugin_todo_queue, prefetcher_todo_queue): self.options = options self.plugin_todo_queue = plugin_todo_queue - self.pref_todo_queue = pref_todo_queue + self.prefetcher_todo_queue = prefetcher_todo_queue def __call__(self): try: @@ -127,7 +127,7 @@ def __call__(self): def __work(self): while True: - job = self.pref_todo_queue.get() + job = self.prefetcher_todo_queue.get() if job is None: log("prefetcher[%s] : job completed, will quit now" % (os.getpid(),)) return @@ -155,9 +155,9 @@ def __work(self): class Writer(object): - def __init__(self, plugin_todo_queue, pref_todo_queue, last_run, opts, pids): + def __init__(self, plugin_todo_queue, prefetcher_todo_queue, last_run, opts, pids): self.plugin_todo_queue = plugin_todo_queue - self.pref_todo_queue = pref_todo_queue + self.prefetcher_todo_queue = prefetcher_todo_queue self.last_run = last_run self.options = opts self.pids = pids @@ -232,12 +232,12 @@ def __generate_jobs_for_bucket_objects(self, bucket_iterator): if obj.size >= self.options["prefetch_size"]: self.plugin_todo_queue.put(job) else: - self.pref_todo_queue.put(job) + self.prefetcher_todo_queue.put(job) def __end_job(self): log("__end_job: waiting for prefetchers queue to become empty") while True: - size = self.pref_todo_queue.qsize() + size = self.prefetcher_todo_queue.qsize() if size == 0: break log("__end_job: %s items left in prefetchers queue, waiting" % (size,)) @@ -246,9 +246,9 @@ def __end_job(self): log("__end_job: I will shutdown all prefetchers now") for _ in range(0, self.options["nb_prefetcher"]): - self.pref_todo_queue.put(None) + self.prefetcher_todo_queue.put(None) - while not self.pref_todo_queue.empty(): + while not self.prefetcher_todo_queue.empty(): pass # notify the plugin that the workers are ready @@ -340,26 +340,26 @@ def parse_plugin_definition(self, context, plugindef): def start_backup_job(self, context): self.manager = multiprocessing.Manager() self.plugin_todo_queue = self.manager.Queue(maxsize=self.options["queue_size"]) - self.pref_todo_queue = self.manager.Queue(maxsize=self.options["nb_prefetcher"]) + self.prefetcher_todo_queue = self.manager.Queue(maxsize=self.options["nb_prefetcher"]) - self.pf_pids = list() + self.prefetcher_pids = list() self.prefetchers = list() for _ in range(0, self.options["nb_prefetcher"]): target = Prefetcher( - self.options, self.plugin_todo_queue, self.pref_todo_queue + self.options, self.plugin_todo_queue, self.prefetcher_todo_queue ) proc = multiprocessing.Process(target=target) proc.start() - self.pf_pids.append(proc.pid) + self.prefetcher_pids.append(proc.pid) self.prefetchers.append(proc) - log("%s prefetcher started" % (len(self.pf_pids),)) + log("%s prefetcher started" % (len(self.prefetcher_pids),)) writer = Writer( self.plugin_todo_queue, - self.pref_todo_queue, + self.prefetcher_todo_queue, self.last_run, self.options, - self.pf_pids, + self.prefetcher_pids, ) self.writer = multiprocessing.Process(target=writer) self.writer.start() From 9e75f3735aacec7ffd2f0efffe3e4bf9274a068a Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 5 Mar 2020 18:21:15 +0100 Subject: [PATCH 255/341] libcloud-plugin: rename Prefetcher to Worker --- .../plugins/filed/BareosFdPluginLibcloud.py | 80 +++++++++---------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 3792cf4b8f1..9413158bfac 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -83,7 +83,7 @@ def connect(options): for opt in ( "buckets_exclude", "accurate", - "nb_prefetcher", + "nb_worker", "prefetch_size", "queue_size", "provider", @@ -111,25 +111,25 @@ def get_object(driver, bucket, key): return None -class Prefetcher(object): - def __init__(self, options, plugin_todo_queue, prefetcher_todo_queue): +class Worker(object): + def __init__(self, options, plugin_todo_queue, worker_todo_queue): self.options = options self.plugin_todo_queue = plugin_todo_queue - self.prefetcher_todo_queue = prefetcher_todo_queue + self.worker_todo_queue = worker_todo_queue def __call__(self): try: self.driver = connect(self.options) - self.__work() + self.__load_object() except: - log("FATAL ERROR: prefetcher could not connect to driver") + log("FATAL ERROR: worker could not connect to driver") log_exc() - def __work(self): + def __load_object(self): while True: - job = self.prefetcher_todo_queue.get() + job = self.worker_todo_queue.get() if job is None: - log("prefetcher[%s] : job completed, will quit now" % (os.getpid(),)) + log("worker[%s] : job completed, will quit now" % (os.getpid(),)) return obj = get_object(self.driver, job["bucket"], job["name"]) @@ -140,11 +140,11 @@ def __work(self): stream = obj.as_stream() content = b"".join(list(stream)) - prefetched = len(content) - if prefetched != job["size"]: + size_of_fetched_object = len(content) + if size_of_fetched_object != job["size"]: error( "FATAL ERROR: prefetched file %s: got %s bytes, not the real size (%s bytes)" - % (job["name"], prefetched, job["size"]) + % (job["name"], size_of_fetched_object, job["size"]) ) return @@ -155,9 +155,9 @@ def __work(self): class Writer(object): - def __init__(self, plugin_todo_queue, prefetcher_todo_queue, last_run, opts, pids): + def __init__(self, plugin_todo_queue, worker_todo_queue, last_run, opts, pids): self.plugin_todo_queue = plugin_todo_queue - self.prefetcher_todo_queue = prefetcher_todo_queue + self.worker_todo_queue = worker_todo_queue self.last_run = last_run self.options = opts self.pids = pids @@ -232,23 +232,23 @@ def __generate_jobs_for_bucket_objects(self, bucket_iterator): if obj.size >= self.options["prefetch_size"]: self.plugin_todo_queue.put(job) else: - self.prefetcher_todo_queue.put(job) + self.worker_todo_queue.put(job) def __end_job(self): - log("__end_job: waiting for prefetchers queue to become empty") + log("__end_job: waiting for workers queue to become empty") while True: - size = self.prefetcher_todo_queue.qsize() + size = self.worker_todo_queue.qsize() if size == 0: break - log("__end_job: %s items left in prefetchers queue, waiting" % (size,)) + log("__end_job: %s items left in workers queue, waiting" % (size,)) time.sleep(2) - log("__end_job: prefetchers queue is empty") + log("__end_job: workers queue is empty") - log("__end_job: I will shutdown all prefetchers now") - for _ in range(0, self.options["nb_prefetcher"]): - self.prefetcher_todo_queue.put(None) + log("__end_job: I will shutdown all workers now") + for _ in range(0, self.options["nb_worker"]): + self.worker_todo_queue.put(None) - while not self.prefetcher_todo_queue.empty(): + while not self.worker_todo_queue.empty(): pass # notify the plugin that the workers are ready @@ -298,8 +298,8 @@ def __parse_opt_int(self, name): def __parse_options(self, context): # Set our default values - if "nb_prefetcher" not in self.options: - self.options["nb_prefetcher"] = 24 + if "nb_worker" not in self.options: + self.options["nb_worker"] = 24 if "queue_size" not in self.options: self.options["queue_size"] = 1000 if "prefetch_size" not in self.options: @@ -313,7 +313,7 @@ def __parse_options(self, context): self.options["secure"] = str2bool(old) self.__parse_opt_int("port") - self.__parse_opt_int("nb_prefetcher") + self.__parse_opt_int("nb_worker") self.__parse_opt_int("prefetch_size") self.__parse_opt_int("queue_size") self.__parse_opt_int("prefetch_size") @@ -340,26 +340,26 @@ def parse_plugin_definition(self, context, plugindef): def start_backup_job(self, context): self.manager = multiprocessing.Manager() self.plugin_todo_queue = self.manager.Queue(maxsize=self.options["queue_size"]) - self.prefetcher_todo_queue = self.manager.Queue(maxsize=self.options["nb_prefetcher"]) + self.worker_todo_queue = self.manager.Queue(maxsize=self.options["nb_worker"]) - self.prefetcher_pids = list() - self.prefetchers = list() - for _ in range(0, self.options["nb_prefetcher"]): - target = Prefetcher( - self.options, self.plugin_todo_queue, self.prefetcher_todo_queue + self.worker_pids = list() + self.workers = list() + for _ in range(0, self.options["nb_worker"]): + target = Worker( + self.options, self.plugin_todo_queue, self.worker_todo_queue ) proc = multiprocessing.Process(target=target) proc.start() - self.prefetcher_pids.append(proc.pid) - self.prefetchers.append(proc) - log("%s prefetcher started" % (len(self.prefetcher_pids),)) + self.worker_pids.append(proc.pid) + self.workers.append(proc) + log("%s worker started" % (len(self.worker_pids),)) writer = Writer( self.plugin_todo_queue, - self.prefetcher_todo_queue, + self.worker_todo_queue, self.last_run, self.options, - self.prefetcher_pids, + self.worker_pids, ) self.writer = multiprocessing.Process(target=writer) self.writer.start() @@ -385,10 +385,10 @@ def start_backup_file(self, context, savepkt): if self.job is None: log("End of queue found, backup is completed") - for i in self.prefetchers: - log("join() for a prefetcher (pid %s)" % (i.pid,)) + for i in self.workers: + log("join() for a worker (pid %s)" % (i.pid,)) i.join() - log("Ok, all prefetchers are shut down") + log("Ok, all workers are shut down") try: self.manager.shutdown() From 045de90927766625ac309b7e08b47f43392a32a4 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 5 Mar 2020 18:40:50 +0100 Subject: [PATCH 256/341] libcloud-plugin: rename variable and move code to separate function --- .../plugins/filed/BareosFdPluginLibcloud.py | 67 ++++++++++--------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 9413158bfac..fe466d97a33 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -273,10 +273,10 @@ def __init__(self, context, plugindef): for _ in driver.iterate_containers(): break - # The job in process - # Setto None when the whole backup is completed + # The backup job in process + # Set to None when the whole backup is completed # Restore's path will not touch this - self.job = {} + self.current_backup_job = {} log("Last backup: %s (ts: %s)" % (self.last_run, self.since)) @@ -370,47 +370,48 @@ def check_file(self, context, fname): # If bareos have not seen one, it does not exists anymore return bRCs["bRC_Error"] + def __shutdown_and_join_worker(self): + log("End of queue found, backup is completed") + for i in self.workers: + log("join() for a worker (pid %s)" % (i.pid,)) + i.join() + log("Ok, all workers are shut down") + + try: + self.manager.shutdown() + except OSError: + # should not happen! + pass + log("self.manager.shutdown()") + + log("Join() for the writer (pid %s)" % (self.writer.pid,)) + self.writer.join() + log("writer is shut down") + def start_backup_file(self, context, savepkt): try: while True: try: - self.job = self.plugin_todo_queue.get_nowait() + self.current_backup_job = self.plugin_todo_queue.get_nowait() break except: size = self.plugin_todo_queue.qsize() log("start_backup_file: queue size: %s" % (size,)) time.sleep(0.1) except TypeError: - self.job = None - - if self.job is None: - log("End of queue found, backup is completed") - for i in self.workers: - log("join() for a worker (pid %s)" % (i.pid,)) - i.join() - log("Ok, all workers are shut down") + self.current_backup_job = None - try: - self.manager.shutdown() - except OSError: - # should not happen! - pass - log("self.manager.shutdown()") - - log("Join() for the writer (pid %s)" % (self.writer.pid,)) - self.writer.join() - log("writer is shut down") - - # savepkt is always checked, so we fill it with a dummy value - savepkt.fname = "empty" + if self.current_backup_job is None: + self.__shutdown_and_join_worker() + savepkt.fname = "empty" # dummy value, savepkt is always checked return bRCs["bRC_Skip"] - filename = "%s/%s" % (self.job["bucket"], self.job["name"]) + filename = "%s/%s" % (self.current_backup_job["bucket"], self.current_backup_job["name"]) log("Backing up %s" % (filename,)) statp = bareosfd.StatPacket() - statp.size = self.job["size"] - statp.mtime = self.job["mtime"] + statp.size = self.current_backup_job["size"] + statp.mtime = self.current_backup_job["mtime"] statp.atime = 0 statp.ctime = 0 @@ -421,7 +422,7 @@ def start_backup_file(self, context, savepkt): return bRCs["bRC_OK"] def plugin_io(self, context, IOP): - if self.job is None: + if self.current_backup_job is None: return bRCs["bRC_Error"] if IOP.func == bIOPS["IO_OPEN"]: # Only used by the 'restore' path @@ -430,14 +431,14 @@ def plugin_io(self, context, IOP): return bRCs["bRC_OK"] # 'Backup' path - if self.job["data"] is None: - obj = get_object(self.driver, self.job["bucket"], self.job["name"]) + if self.current_backup_job["data"] is None: + obj = get_object(self.driver, self.current_backup_job["bucket"], self.current_backup_job["name"]) if obj is None: self.FILE = None return bRCs["bRC_Error"] self.FILE = IterStringIO(obj.as_stream()) else: - self.FILE = self.job["data"] + self.FILE = self.current_backup_job["data"] elif IOP.func == bIOPS["IO_READ"]: IOP.buf = bytearray(IOP.count) @@ -472,7 +473,7 @@ def plugin_io(self, context, IOP): return bRCs["bRC_OK"] def end_backup_file(self, context): - if self.job is not None: + if self.current_backup_job is not None: return bRCs["bRC_More"] else: return bRCs["bRC_OK"] From 6302ba7d17b00ccc378980864b24d57469386c81 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 10 Mar 2020 10:49:15 +0100 Subject: [PATCH 257/341] libcloud-plugin: rename class Writer --- core/src/plugins/filed/BareosFdPluginLibcloud.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index fe466d97a33..e3b208022af 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -154,7 +154,7 @@ def __load_object(self): self.plugin_todo_queue.put(job) -class Writer(object): +class JobCreator(object): def __init__(self, plugin_todo_queue, worker_todo_queue, last_run, opts, pids): self.plugin_todo_queue = plugin_todo_queue self.worker_todo_queue = worker_todo_queue @@ -354,15 +354,15 @@ def start_backup_job(self, context): self.workers.append(proc) log("%s worker started" % (len(self.worker_pids),)) - writer = Writer( + job_generator = JobCreator( self.plugin_todo_queue, self.worker_todo_queue, self.last_run, self.options, self.worker_pids, ) - self.writer = multiprocessing.Process(target=writer) - self.writer.start() + self.job_generator = multiprocessing.Process(target=job_generator) + self.job_generator.start() self.driver = connect(self.options) def check_file(self, context, fname): @@ -384,9 +384,9 @@ def __shutdown_and_join_worker(self): pass log("self.manager.shutdown()") - log("Join() for the writer (pid %s)" % (self.writer.pid,)) - self.writer.join() - log("writer is shut down") + log("Join() for the job_generator (pid %s)" % (self.job_generator.pid,)) + self.job_generator.join() + log("job_generator is shut down") def start_backup_file(self, context, savepkt): try: From 99260ccf2cccf4c276d0626eee0e32dd3e42ded1 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 10 Mar 2020 15:24:24 +0100 Subject: [PATCH 258/341] libcloud-plugin: do not connect to libcloud for a filesystem restore --- .../plugins/filed/BareosFdPluginLibcloud.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index e3b208022af..d3ec03a654d 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -266,20 +266,11 @@ def __init__(self, context, plugindef): self.last_run = datetime.datetime.fromtimestamp(self.since) self.last_run = self.last_run.replace(tzinfo=None) - # We force an action to the backend, to test our params - # If we can get anything, then it is ok - # Else, an exception will be raised, and the job will fail - driver = connect(self.options) - for _ in driver.iterate_containers(): - break - # The backup job in process # Set to None when the whole backup is completed # Restore's path will not touch this self.current_backup_job = {} - log("Last backup: %s (ts: %s)" % (self.last_run, self.since)) - def __parse_options_bucket(self, name): if name not in self.options: self.options[name] = None @@ -338,6 +329,15 @@ def parse_plugin_definition(self, context, plugindef): return bRCs["bRC_OK"] def start_backup_job(self, context): + # We force an action to the backend, to test our params + # If we can get anything, then it is ok + # Else, an exception will be raised, and the job will fail + driver = connect(self.options) + for _ in driver.iterate_containers(): + break + + log("Last backup: %s (ts: %s)" % (self.last_run, self.since)) + self.manager = multiprocessing.Manager() self.plugin_todo_queue = self.manager.Queue(maxsize=self.options["queue_size"]) self.worker_todo_queue = self.manager.Queue(maxsize=self.options["nb_worker"]) From 004503a4b888021708ff7111bb3ffe2bee5b0bbb Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 11 Mar 2020 10:29:23 +0100 Subject: [PATCH 259/341] packaging: package bareos-filedaemon-libcloud-plugin --- core/platforms/packaging/bareos.spec | 46 ++++++------------- .../control.bareos-filedaemon-python-plugin | 11 +++++ 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/core/platforms/packaging/bareos.spec b/core/platforms/packaging/bareos.spec index 82215dcbda2..e31f4be607f 100644 --- a/core/platforms/packaging/bareos.spec +++ b/core/platforms/packaging/bareos.spec @@ -50,6 +50,7 @@ Vendor: The Bareos Team # cmake build directory %define CMAKE_BUILDDIR cmake-build + # rhel/centos 6 must not be built with libtirpc installed %if 0%{?rhel} == 6 BuildConflicts: libtirpc-devel @@ -248,6 +249,7 @@ BuildRequires: lsb-release BuildRequires: passwd + # Some magic to be able to determine what platform we are running on. %if 0%{?rhel_version} || 0%{?centos_version} || 0%{?fedora_version} @@ -288,9 +290,6 @@ BuildRequires: lsb-release %define our_find_requires %{_builddir}/%{name}-%{version}/find_requires %endif - - - Summary: Backup Archiving REcovery Open Sourced - metapackage Requires: %{name}-director = %{version} Requires: %{name}-storage = %{version} @@ -547,6 +546,12 @@ Requires: python-pycurl Requires: python-lxml Requires: python-ovirt-engine-sdk4 +%package filedaemon-libcloud-python-plugin +Summary: Libcloud Python plugin for Bareos File daemon +Group: Productivity/Archiving/Backup +Requires: bareos-filedaemon = %{version} +Requires: bareos-filedaemon-python-plugin = %{version} + %package filedaemon-postgresql-python-plugin Summary: PostgreSQL Python plugin for Bareos File daemon Group: Productivity/Archiving/Backup @@ -564,7 +569,6 @@ Summary: Python plugin for Bareos Storage daemon Group: Productivity/Archiving/Backup Requires: bareos-storage = %{version} - # vmware switch is set via --define="vmware 1" in build script when # vix disklib is detected @@ -606,8 +610,6 @@ Keeps bareos/plugins/vmware_plugin subdirectory, which have been used in Bareos # VMware Plugin END %endif - - %description director-python-plugin %{dscr} @@ -628,11 +630,15 @@ This package contains the LDAP python plugin for the file daemon This package contains the Ovirt python plugin for the file daemon +%description filedaemon-libcloud-python-plugin +%{dscr} + +This package contains the Libcloud python plugin for the file daemon + %description filedaemon-postgresql-python-plugin %{dscr} This package contains the PostgreSQL python plugin for the file daemon - %description filedaemon-percona-xtrabackup-python-plugin %{dscr} @@ -665,7 +671,6 @@ Summary: CEPH plugin for Bareos File daemon Group: Productivity/Archiving/Backup Requires: bareos-filedaemon = %{version} - %description filedaemon-ceph-plugin %{dscr} @@ -673,7 +678,6 @@ This package contains the CEPH plugins for the file daemon %endif - %package webui Summary: Bareos Web User Interface Group: Productivity/Archiving/Backup @@ -747,8 +751,6 @@ features that make it easy to find and recover lost or damaged files. \ Bareos source code has been released under the AGPL version 3 license. This package contains the webui (Bareos Web User Interface). - - %description client %{dscr} @@ -874,7 +876,6 @@ This package contains required files for Bareos regression testing. %setup -c -n bareos mv bareos-*/* . - %build # Cleanup defined in Fedora Packaging:Guidelines # and required repetitive local build of at least CentOS 5. @@ -890,7 +891,6 @@ export MTX=/usr/sbin/mtx mkdir %{CMAKE_BUILDDIR} pushd %{CMAKE_BUILDDIR} - # use Developer Toolset 7 compiler as standard is too old %if 0%{?centos_version} == 600 || 0%{?rhel_version} == 600 export PATH=/opt/rh/devtoolset-7/root/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin @@ -988,8 +988,8 @@ make clean REGRESS_DEBUG=1 ctest -j 10 -V -D Continuous || result=$? result=$? if [ $result -eq 1 ]; then -echo "ctest result $result is expected and OK" -exit 0 + echo "ctest result $result is expected and OK" + exit 0 else echo "ctest result $result is not 1, ERROR" fi @@ -1066,7 +1066,6 @@ for F in \ %{script_dir}/btraceback.mdb \ %{_docdir}/%{name}/INSTALL \ %{_sbindir}/%{name} - do rm -f "%{buildroot}/$F" done @@ -1076,7 +1075,6 @@ done find %{buildroot}/%{library_dir} -type l -name "libbareos*.so" -maxdepth 1 -exec rm {} \; ls -la %{buildroot}/%{library_dir} - %if ! 0%{?python_plugins} rm -f %{buildroot}/%{plugin_dir}/python-*.so rm -f %{buildroot}/%{plugin_dir}/*.py* @@ -1107,8 +1105,6 @@ rm %{buildroot}%{_mandir}/man1/bareos-tray-monitor.* rm -f %{buildroot}%{plugin_dir}/BareosFdPluginVMware.py* rm -f %{buildroot}%{plugin_dir}/bareos-fd-vmware.py* %endif - - # install systemd service files %if 0%{?systemd_support} install -d -m 755 %{buildroot}%{_unitdir} @@ -1127,12 +1123,8 @@ ln -sf service %{buildroot}%{_sbindir}/rcbareos-sd echo "This meta package emulates the former bareos-client package" > %{buildroot}%{_docdir}/%{name}/README.bareos-client echo "This is a meta package to install a full bareos system" > %{buildroot}%{_docdir}/%{name}/README.bareos - # create dir for bareos-vmware-plugin-compat mkdir -p %{?buildroot}/%{_libdir}/bareos/plugins/vmware_plugin - - - %files %defattr(-, root, root) %{_docdir}/%{name}/README.bareos @@ -1152,8 +1144,6 @@ mkdir -p %{?buildroot}/%{_libdir}/bareos/plugins/vmware_plugin %config %attr(644,root,root) /etc/bareos/bareos-dir.d/profile/webui-limited.conf.example %config(noreplace) %attr(644,root,root) /etc/bareos/bareos-dir.d/profile/webui-readonly.conf %config(noreplace) %{_apache_conf_dir}/bareos-webui.conf - - %files client %defattr(-, root, root) %dir %{_docdir}/%{name} @@ -1182,7 +1172,6 @@ mkdir -p %{?buildroot}/%{_libdir}/bareos/plugins/vmware_plugin #VMware Plugin END %endif - %files bconsole # console package %defattr(-, root, root) @@ -1570,7 +1559,6 @@ mkdir -p %{?buildroot}/%{_libdir}/bareos/plugins/vmware_plugin %defattr(-, root, root) %{plugin_dir}/BareosFdPluginPostgres.py* %{plugin_dir}/bareos-fd-postgres.py* - %files filedaemon-percona-xtrabackup-python-plugin %defattr(-, root, root) %{plugin_dir}/bareos-fd-percona-xtrabackup.py* @@ -1752,8 +1740,6 @@ if [ -e %1.rpmupdate.%{version}.keep ]; then \ rm %1.rpmupdate.%{version}.keep; \ fi; \ %nil - - %post webui %if 0%{?suse_version} >= 1110 @@ -1775,8 +1761,6 @@ a2enmod php5 &> /dev/null || true %endif - - %post director %post_backup_file /etc/%{name}/bareos-dir.conf %{script_dir}/bareos-config initialize_local_hostname diff --git a/debian/control.bareos-filedaemon-python-plugin b/debian/control.bareos-filedaemon-python-plugin index 1d951fda0dc..468213412d1 100644 --- a/debian/control.bareos-filedaemon-python-plugin +++ b/debian/control.bareos-filedaemon-python-plugin @@ -30,3 +30,14 @@ Description: Backup Archiving Recovery Open Sourced - file daemon LDAP plugin data across a network of computers of different kinds. . This package provides the Percona XtraBackup Python plugin for the filedaemon. + +Package: bareos-filedaemon-libcloud-python-plugin +Architecture: any +Section: python +Pre-Depends: debconf (>= 1.4.30) | debconf-2.0 +Depends: bareos-common (= ${binary:Version}), bareos-filedaemon-python-plugin (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends} +Description: Backup Archiving Recovery Open Sourced - file daemon LDAP plugin + Bareos is a set of programs to manage backup, recovery and verification of + data across a network of computers of different kinds. + . + This package provides the Libcloud Python plugin for the filedaemon. From 6512fff7a1d36595d7d1ab046a0a50a2d9826822 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 11 Mar 2020 11:57:45 +0100 Subject: [PATCH 260/341] filed: install libcloud plugin by cmake --- core/platforms/packaging/bareos.spec | 9 ++++++++- core/src/plugins/filed/CMakeLists.txt | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/platforms/packaging/bareos.spec b/core/platforms/packaging/bareos.spec index e31f4be607f..ff915e81932 100644 --- a/core/platforms/packaging/bareos.spec +++ b/core/platforms/packaging/bareos.spec @@ -556,7 +556,6 @@ Requires: bareos-filedaemon-python-plugin = %{version} Summary: PostgreSQL Python plugin for Bareos File daemon Group: Productivity/Archiving/Backup Requires: bareos-filedaemon = %{version} - %package filedaemon-percona-xtrabackup-python-plugin Summary: Percona xtrabackup Python plugin for Bareos File daemon Group: Productivity/Archiving/Backup @@ -1555,7 +1554,15 @@ mkdir -p %{?buildroot}/%{_libdir}/bareos/plugins/vmware_plugin %attr(0640, %{director_daemon_user}, %{daemon_group}) %{_sysconfdir}/%{name}/bareos-dir.d/fileset/plugin-ovirt.conf.example %attr(0640, %{director_daemon_user}, %{daemon_group}) %{_sysconfdir}/%{name}/bareos-dir.d/job/backup-ovirt.conf.example +%files filedaemon-libcloud-python-plugin +%defattr(-, root, root) +%{plugin_dir}/bareos-fd-libcloud.py* +%{plugin_dir}/BareosFdPluginLibcloud.py* +#attr(0640, #{director_daemon_user}, #{daemon_group}) #{_sysconfdir}/#{name}/bareos-dir.d/fileset/plugin-libcloud.conf.example +#attr(0640, #{director_daemon_user}, #{daemon_group}) #{_sysconfdir}/#{name}/bareos-dir.d/job/backup-libcloud.conf.example + %files filedaemon-postgresql-python-plugin + %defattr(-, root, root) %{plugin_dir}/BareosFdPluginPostgres.py* %{plugin_dir}/bareos-fd-postgres.py* diff --git a/core/src/plugins/filed/CMakeLists.txt b/core/src/plugins/filed/CMakeLists.txt index a831c3c01b1..8059160683e 100644 --- a/core/src/plugins/filed/CMakeLists.txt +++ b/core/src/plugins/filed/CMakeLists.txt @@ -94,6 +94,7 @@ if(NOT HAVE_WIN32) set_target_properties(example-plugin-fd PROPERTIES PREFIX "") endif() + if(${HAVE_GLUSTERFS}) add_library(gfapi-fd MODULE gfapi/gfapi-fd.cc) set_target_properties(gfapi-fd PROPERTIES PREFIX "") From 57e41beeffd4ca880494e9f1060ef708aeca40d0 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 12 Mar 2020 17:30:44 +0100 Subject: [PATCH 261/341] libcloud-plugin: implement a config file for libcloud parameters --- .../plugins/filed/BareosFdPluginLibcloud.py | 97 +++++++++++++++---- .../bareos-dir.d/fileset/PluginTest.conf.in | 2 +- .../etc/libcloud_config.ini | 14 +++ 3 files changed, 93 insertions(+), 20 deletions(-) create mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/etc/libcloud_config.ini diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index d3ec03a654d..a9a08752430 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -22,6 +22,7 @@ import BareosFdPluginBaseclass import bareosfd import bareos_fd_consts +import ConfigParser as configparser import datetime import dateutil.parser import io @@ -288,32 +289,13 @@ def __parse_opt_int(self, name): self.options[name] = int(value) def __parse_options(self, context): - # Set our default values - if "nb_worker" not in self.options: - self.options["nb_worker"] = 24 - if "queue_size" not in self.options: - self.options["queue_size"] = 1000 - if "prefetch_size" not in self.options: - self.options["prefetch_size"] = 10 * 1024 * 1024 self.__parse_options_bucket("buckets_include") self.__parse_options_bucket("buckets_exclude") - # Do a couple of sanitization - if "secure" in self.options: - old = self.options["secure"] - self.options["secure"] = str2bool(old) - - self.__parse_opt_int("port") - self.__parse_opt_int("nb_worker") - self.__parse_opt_int("prefetch_size") - self.__parse_opt_int("queue_size") - self.__parse_opt_int("prefetch_size") - if "debug" in self.options: old = self.options["debug"] self.options["debug"] = str2bool(old) - # Setup debugging if self.options["debug"] is True: global debug debug = True @@ -326,8 +308,85 @@ def __parse_options(self, context): self.options["accurate"] = True def parse_plugin_definition(self, context, plugindef): + log("Parse Plugin Definition") + config_file = self.options.get("config_file") + if config_file: + if not self.__parse_config_file(context, config_file): + return bRCs["bRC_Error"] return bRCs["bRC_OK"] + def __parse_config_file(self, context, config_file): + """ + Parse the config file given in the config_file plugin option + """ + bareosfd.DebugMessage( + context, + 100, + "BareosFdPluginLibcloud: parse_config_file(): parse %s\n" + % (config_file), + ) + + self.config = configparser.ConfigParser() + + try: + self.config.readfp(open(config_file)) + except IOError as err: + bareosfd.JobMessage( + context, + bJobMessageType["M_FATAL"], + "BareosFdPluginLibcloud: Error reading config file %s: %s\n" + % (self.options["config_file"], err.strerror), + ) + return False + + return self.__check_config(context, config_file) + + def __check_config(self, context, config_file): + """ + Check the configuration and set or override options if necessary, + considering mandatory: username and password in the [credentials] section + """ + mandatory_sections = ["credentials", "host", "misc"] + mandatory_options = {} + mandatory_options["credentials"] = ["username", "password"] + mandatory_options["host"] = ["hostname", "port", "provider", "tls"] + mandatory_options["misc"] = ["nb_worker", "queue_size", "prefetch_size"] + + #this maps config file options to libcloud options + option_map = {"hostname":"host", "port":"port", "provider":"provider", + "username":"key", "password":"secret"} + + for section in mandatory_sections: + if not self.config.has_section(section): + log("BareosFdPluginLibcloud: Section [%s] missing in config file %s\n" + % (section, config_file)) + return False + + for option in mandatory_options[section]: + if not self.config.has_option(section, option): + log("BareosFdPluginLibcloud: Option [%s] missing in Section %s\n" + % (option, section)) + return False + + value = self.config.get(section, option) + + try: + if option == "tls": + self.options["secure"] = str2bool(value) + elif option == "nb_worker": + self.options["nb_worker"] = int(value) + elif option == "queue_size": + self.options["queue_size"] = int(value) + elif option == "prefetch_size": + self.options["prefetch_size"] = eval(value) + else: + self.options[option_map[option]] = value + except: + log("Could not evaluate: %s in config file %s" % (value, config_file)) + return False + + return True + def start_backup_job(self, context): # We force an action to the backend, to test our params # If we can get anything, then it is ok diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in index 4518acbd992..fa1a7feb4f5 100644 --- a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in @@ -5,6 +5,6 @@ FileSet { Options { signature = MD5 } - Plugin = "python:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-libcloud:provider=S3:key=minioadmin:secret=minioadmin:host=127.0.0.1:port=9000:secure=false:buckets_include=test" + Plugin = "python:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-libcloud:config_file=config.ini:buckets_include=test" } } diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/libcloud_config.ini b/systemtests/tests/python-fd-plugin-libcloud-test/etc/libcloud_config.ini new file mode 100644 index 00000000000..aa089d5ab69 --- /dev/null +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/libcloud_config.ini @@ -0,0 +1,14 @@ +[host] +hostname=127.0.0.1 +port=9000 +tls=false +provider=S3 + +[credentials] +username=minioadmin +password=minioadmin + +[misc] +nb_worker=20 +queue_size=1000 +prefetch_size=10*1024*1024 From e2477670c664618e6bdfda3d6ee531dac0910ebf Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Fri, 13 Mar 2020 15:35:01 +0100 Subject: [PATCH 262/341] libcloud-plugin: add joblog --- .../plugins/filed/BareosFdPluginLibcloud.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index a9a08752430..342b31a146d 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -36,12 +36,22 @@ from libcloud.storage.types import Provider from libcloud.storage.providers import get_driver -from bareos_fd_consts import bRCs, bIOPS +from bareos_fd_consts import bRCs, bIOPS, bJobMessageType syslog.openlog(__name__, facility=syslog.LOG_LOCAL7) debug = False +fd_context = None +def joblog(message): + global fd_context + if fd_context != None: + message = "[%s] %s" % (os.getpid(), message) + bareosfd.JobMessage( + fd_context, + bJobMessageType["M_INFO"], + message + ) def log(message): if debug is True: @@ -258,6 +268,8 @@ def __end_job(self): class BareosFdPluginLibcloud(BareosFdPluginBaseclass.BareosFdPluginBaseclass): def __init__(self, context, plugindef): + global fd_context + fd_context = context log("BareosFdPluginLibcloud called with plugindef: %s" % (plugindef,)) super(BareosFdPluginLibcloud, self).__init__(context, plugindef) @@ -395,7 +407,7 @@ def start_backup_job(self, context): for _ in driver.iterate_containers(): break - log("Last backup: %s (ts: %s)" % (self.last_run, self.since)) + joblog("Last backup: %s (ts: %s)" % (self.last_run, self.since)) self.manager = multiprocessing.Manager() self.plugin_todo_queue = self.manager.Queue(maxsize=self.options["queue_size"]) @@ -455,7 +467,7 @@ def start_backup_file(self, context, savepkt): break except: size = self.plugin_todo_queue.qsize() - log("start_backup_file: queue size: %s" % (size,)) + joblog("start_backup_file: queue size: %s" % (size,)) time.sleep(0.1) except TypeError: self.current_backup_job = None @@ -466,7 +478,7 @@ def start_backup_file(self, context, savepkt): return bRCs["bRC_Skip"] filename = "%s/%s" % (self.current_backup_job["bucket"], self.current_backup_job["name"]) - log("Backing up %s" % (filename,)) + joblog("Backing up %s" % (filename,)) statp = bareosfd.StatPacket() statp.size = self.current_backup_job["size"] From 899ee433b3df8f2304b5779bf8b758435ab5174e Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Mon, 16 Mar 2020 17:14:54 +0100 Subject: [PATCH 263/341] libcloud-plugin: add a prefix to the path - PYLIBCLOUD:/ is prepended to the path to be able to distinguish the plugin --- core/src/plugins/filed/BareosFdPluginLibcloud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 342b31a146d..095dc3df2da 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -477,7 +477,7 @@ def start_backup_file(self, context, savepkt): savepkt.fname = "empty" # dummy value, savepkt is always checked return bRCs["bRC_Skip"] - filename = "%s/%s" % (self.current_backup_job["bucket"], self.current_backup_job["name"]) + filename = "PYLIBCLOUD:/%s/%s" % (self.current_backup_job["bucket"], self.current_backup_job["name"]) joblog("Backing up %s" % (filename,)) statp = bareosfd.StatPacket() From 79e92530acb14f6dc626428a0ce495c30ceef547 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Mon, 16 Mar 2020 22:37:22 +0100 Subject: [PATCH 264/341] libcloud-plugin: use debug and job messages instead of syslog --- .../plugins/filed/BareosFdPluginLibcloud.py | 141 ++++++++---------- .../bareos-dir.d/fileset/PluginTest.conf.in | 2 +- 2 files changed, 65 insertions(+), 78 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 095dc3df2da..9050b868e59 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -32,7 +32,6 @@ import os import syslog import time -import traceback from libcloud.storage.types import Provider from libcloud.storage.providers import get_driver @@ -40,35 +39,27 @@ syslog.openlog(__name__, facility=syslog.LOG_LOCAL7) -debug = False -fd_context = None +plugin_context = None -def joblog(message): - global fd_context - if fd_context != None: - message = "[%s] %s" % (os.getpid(), message) +def jobmessage(message_type, message): + global plugin_context + if plugin_context != None: + message = "BareosFdPluginLibcloud [%s]: %s\n" % (os.getpid(), message) bareosfd.JobMessage( - fd_context, - bJobMessageType["M_INFO"], + plugin_context, + bJobMessageType[message_type], message ) -def log(message): - if debug is True: - message = "[%s] %s" % (os.getpid(), message) - syslog.syslog(message) - - -def error(message): - message = "[%s] %s" % (os.getpid(), message) - syslog.syslog(message) - - -# Print the traceback to syslog -def log_exc(): - for line in traceback.format_exc().split("\n"): - error(line) - +def debugmessage(level, message): + global plugin_context + if plugin_context != None: + message = "BareosFdPluginLibcloud [%s]: %s\n" % (os.getpid(), message) + bareosfd.DebugMessage( + plugin_context, + level, + message + ) class IterStringIO(io.BufferedIOBase): def __init__(self, iterable): @@ -114,8 +105,8 @@ def get_object(driver, bucket, key): return driver.get_object(bucket, key) except libcloud.common.types.InvalidCredsError: # Something is buggy here, this bug is triggered by tilde-ending objects - # Our tokens are good, we used then before - error( + # Our tokens are good, we used them before + debugmessage(100, "BUGGY filename found, see the libcloud bug somewhere : %s/%s" % (bucket, key) ) @@ -133,14 +124,13 @@ def __call__(self): self.driver = connect(self.options) self.__load_object() except: - log("FATAL ERROR: worker could not connect to driver") - log_exc() + debugmessage(100, "Worker could not connect to driver") def __load_object(self): while True: job = self.worker_todo_queue.get() if job is None: - log("worker[%s] : job completed, will quit now" % (os.getpid(),)) + debugmessage(100, "worker[%s] : job completed, will quit now" % (os.getpid(),)) return obj = get_object(self.driver, job["bucket"], job["name"]) @@ -153,8 +143,8 @@ def __load_object(self): size_of_fetched_object = len(content) if size_of_fetched_object != job["size"]: - error( - "FATAL ERROR: prefetched file %s: got %s bytes, not the real size (%s bytes)" + debugmessage(100, + "prefetched file %s: got %s bytes, not the real size (%s bytes)" % (job["name"], size_of_fetched_object, job["size"]) ) return @@ -180,7 +170,7 @@ def __call__(self): try: self.__iterate_over_buckets() except: - log_exc() + debugmessage(100, "Error while iterating over buckets") self.__end_job() def __iterate_over_buckets(self): @@ -193,7 +183,7 @@ def __iterate_over_buckets(self): if bucket.name in self.options["buckets_exclude"]: continue - log("Backing up bucket \"%s\"" % (bucket.name,)) + debugmessage(100, "Backing up bucket \"%s\"" % (bucket.name,)) self.__generate_jobs_for_bucket_objects(self.driver.iterate_container_objects(bucket)) @@ -220,7 +210,7 @@ def __generate_jobs_for_bucket_objects(self, bucket_iterator): object_name = "%s/%s" % (obj.container.name, obj.name) if self.last_run > mtime: - log( + debugmessage(100, "File %s not changed, skipped (%s > %s)" % (object_name, self.last_run, mtime) ) @@ -234,7 +224,7 @@ def __generate_jobs_for_bucket_objects(self, bucket_iterator): continue - log( + debugmessage(100, "File %s was changed or is new, backing up (%s < %s)" % (object_name, self.last_run, mtime) ) @@ -246,16 +236,16 @@ def __generate_jobs_for_bucket_objects(self, bucket_iterator): self.worker_todo_queue.put(job) def __end_job(self): - log("__end_job: waiting for workers queue to become empty") + debugmessage(100, "__end_job: waiting for workers queue to become empty") while True: size = self.worker_todo_queue.qsize() if size == 0: break log("__end_job: %s items left in workers queue, waiting" % (size,)) time.sleep(2) - log("__end_job: workers queue is empty") + debugmessage(100, "__end_job: workers queue is empty") - log("__end_job: I will shutdown all workers now") + debugmessage(100, "__end_job: I will shutdown all workers now") for _ in range(0, self.options["nb_worker"]): self.worker_todo_queue.put(None) @@ -268,9 +258,9 @@ def __end_job(self): class BareosFdPluginLibcloud(BareosFdPluginBaseclass.BareosFdPluginBaseclass): def __init__(self, context, plugindef): - global fd_context - fd_context = context - log("BareosFdPluginLibcloud called with plugindef: %s" % (plugindef,)) + global plugin_context + plugin_context = context + debugmessage(100, "BareosFdPluginLibcloud called with plugindef: %s" % (plugindef,)) super(BareosFdPluginLibcloud, self).__init__(context, plugindef) super(BareosFdPluginLibcloud, self).parse_plugin_definition(context, plugindef) @@ -320,32 +310,26 @@ def __parse_options(self, context): self.options["accurate"] = True def parse_plugin_definition(self, context, plugindef): - log("Parse Plugin Definition") + debugmessage(100, "Parse Plugin Definition") config_file = self.options.get("config_file") if config_file: - if not self.__parse_config_file(context, config_file): - return bRCs["bRC_Error"] - return bRCs["bRC_OK"] + if self.__parse_config_file(context, config_file): + return bRCs["bRC_OK"] + jobmessage("M_FATAL", "Could not load configfile %s" % (config_file)) + return bRCs["bRC_Error"] def __parse_config_file(self, context, config_file): """ Parse the config file given in the config_file plugin option """ - bareosfd.DebugMessage( - context, - 100, - "BareosFdPluginLibcloud: parse_config_file(): parse %s\n" - % (config_file), - ) + debugmessage(100, "parse_config_file(): parse %s\n" % (config_file)) self.config = configparser.ConfigParser() try: self.config.readfp(open(config_file)) except IOError as err: - bareosfd.JobMessage( - context, - bJobMessageType["M_FATAL"], + debugmessage(100, "BareosFdPluginLibcloud: Error reading config file %s: %s\n" % (self.options["config_file"], err.strerror), ) @@ -370,13 +354,13 @@ def __check_config(self, context, config_file): for section in mandatory_sections: if not self.config.has_section(section): - log("BareosFdPluginLibcloud: Section [%s] missing in config file %s\n" + debugmessage(100, "BareosFdPluginLibcloud: Section [%s] missing in config file %s\n" % (section, config_file)) return False for option in mandatory_options[section]: if not self.config.has_option(section, option): - log("BareosFdPluginLibcloud: Option [%s] missing in Section %s\n" + debugmessage(100, "BareosFdPluginLibcloud: Option [%s] missing in Section %s\n" % (option, section)) return False @@ -394,20 +378,22 @@ def __check_config(self, context, config_file): else: self.options[option_map[option]] = value except: - log("Could not evaluate: %s in config file %s" % (value, config_file)) + debugmessage(100, "Could not evaluate: %s in config file %s" % (value, config_file)) return False return True def start_backup_job(self, context): - # We force an action to the backend, to test our params - # If we can get anything, then it is ok - # Else, an exception will be raised, and the job will fail - driver = connect(self.options) - for _ in driver.iterate_containers(): - break + try: + jobmessage("M_INFO", "Try to connect to:" + self.options["port"]) + driver = connect(self.options) + for _ in driver.iterate_containers(): + break + except: + jobmessage("M_FATAL", "Could not connect to libcloud driver") + return bRCs["bRC_Error"] - joblog("Last backup: %s (ts: %s)" % (self.last_run, self.since)) + jobmessage("M_INFO", "Last backup: %s (ts: %s)" % (self.last_run, self.since)) self.manager = multiprocessing.Manager() self.plugin_todo_queue = self.manager.Queue(maxsize=self.options["queue_size"]) @@ -423,7 +409,7 @@ def start_backup_job(self, context): proc.start() self.worker_pids.append(proc.pid) self.workers.append(proc) - log("%s worker started" % (len(self.worker_pids),)) + debugmessage(100, "%s worker started" % (len(self.worker_pids),)) job_generator = JobCreator( self.plugin_todo_queue, @@ -435,6 +421,8 @@ def start_backup_job(self, context): self.job_generator = multiprocessing.Process(target=job_generator) self.job_generator.start() self.driver = connect(self.options) + debugmessage(100, "%s job creator started" % (len(self.worker_pids),)) + return bRCs["bRC_OK"] def check_file(self, context, fname): # All existing files are passed to bareos @@ -442,32 +430,31 @@ def check_file(self, context, fname): return bRCs["bRC_Error"] def __shutdown_and_join_worker(self): - log("End of queue found, backup is completed") + jobmessage("M_INFO", "Backup is completed") for i in self.workers: - log("join() for a worker (pid %s)" % (i.pid,)) + debugmessage(100, "join() for a worker (pid %s)" % (i.pid,)) i.join() - log("Ok, all workers are shut down") + debugmessage(100, "Ok, all workers are shut down") try: self.manager.shutdown() except OSError: # should not happen! pass - log("self.manager.shutdown()") + debugmessage(100, "self.manager.shutdown()") - log("Join() for the job_generator (pid %s)" % (self.job_generator.pid,)) + debugmessage(100, "Join() for the job_generator (pid %s)" % (self.job_generator.pid,)) self.job_generator.join() - log("job_generator is shut down") + debugmessage(100, "job_generator is shut down") def start_backup_file(self, context, savepkt): + debugmessage(100, "start_backup_file() called, waiting for worker") try: while True: try: self.current_backup_job = self.plugin_todo_queue.get_nowait() break except: - size = self.plugin_todo_queue.qsize() - joblog("start_backup_file: queue size: %s" % (size,)) time.sleep(0.1) except TypeError: self.current_backup_job = None @@ -478,7 +465,7 @@ def start_backup_file(self, context, savepkt): return bRCs["bRC_Skip"] filename = "PYLIBCLOUD:/%s/%s" % (self.current_backup_job["bucket"], self.current_backup_job["name"]) - joblog("Backing up %s" % (filename,)) + jobmessage("M_INFO", "Backing up %s" % (filename,)) statp = bareosfd.StatPacket() statp.size = self.current_backup_job["size"] @@ -522,7 +509,7 @@ def plugin_io(self, context, IOP): IOP.status = len(buf) return bRCs["bRC_OK"] except IOError as e: - log("Cannot read from %s : %s" % (IOP.fname, e)) + jobmessage("M_ERROR", "Cannot read from %s : %s" % (IOP.fname, e)) IOP.status = 0 IOP.io_errno = e.errno return bRCs["bRC_Error"] @@ -534,7 +521,7 @@ def plugin_io(self, context, IOP): IOP.io_errno = 0 except IOError as msg: IOP.io_errno = -1 - error("Failed to write data: %s" % (msg,)) + jobmessage("M_ERROR", "Failed to write data: %s" % (msg,)) return bRCs["bRC_OK"] elif IOP.func == bIOPS["IO_CLOSE"]: if self.FILE: diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in index fa1a7feb4f5..7f00193980a 100644 --- a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in @@ -5,6 +5,6 @@ FileSet { Options { signature = MD5 } - Plugin = "python:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-libcloud:config_file=config.ini:buckets_include=test" + Plugin = "python:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-libcloud:config_file=etc/libcloud_config.ini:buckets_include=test" } } From 18783d17811f3cfaf0251522890c2790ac07b4a0 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 17 Mar 2020 11:41:45 +0100 Subject: [PATCH 265/341] libcloud-plugin: renam a variable and count number of backup objects --- .../plugins/filed/BareosFdPluginLibcloud.py | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 9050b868e59..fa206dc5615 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -33,9 +33,10 @@ import syslog import time +from bareos_fd_consts import bRCs, bIOPS, bJobMessageType from libcloud.storage.types import Provider from libcloud.storage.providers import get_driver -from bareos_fd_consts import bRCs, bIOPS, bJobMessageType +from sys import version_info syslog.openlog(__name__, facility=syslog.LOG_LOCAL7) @@ -273,6 +274,7 @@ def __init__(self, context, plugindef): # Set to None when the whole backup is completed # Restore's path will not touch this self.current_backup_job = {} + self.number_of_objects_to_backup = 0 def __parse_options_bucket(self, name): if name not in self.options: @@ -311,33 +313,36 @@ def __parse_options(self, context): def parse_plugin_definition(self, context, plugindef): debugmessage(100, "Parse Plugin Definition") - config_file = self.options.get("config_file") - if config_file: - if self.__parse_config_file(context, config_file): + config_filename = self.options.get("config_file") + if config_filename: + if self.__parse_config_file(context, config_filename): return bRCs["bRC_OK"] - jobmessage("M_FATAL", "Could not load configfile %s" % (config_file)) + jobmessage("M_FATAL", "Could not load configfile %s" % (config_filename)) return bRCs["bRC_Error"] - def __parse_config_file(self, context, config_file): + def __parse_config_file(self, context, config_filename): """ Parse the config file given in the config_file plugin option """ - debugmessage(100, "parse_config_file(): parse %s\n" % (config_file)) + debugmessage(100, "parse_config_file(): parse %s\n" % (config_filename)) self.config = configparser.ConfigParser() try: - self.config.readfp(open(config_file)) - except IOError as err: + if version_info[:3] < (3,2): + self.config.readfp(open(config_filename)) + else: + self.config.read_file(open(config_filename)) + except (IOError, OSError) as err: debugmessage(100, "BareosFdPluginLibcloud: Error reading config file %s: %s\n" % (self.options["config_file"], err.strerror), ) return False - return self.__check_config(context, config_file) + return self.__check_config(context, config_filename) - def __check_config(self, context, config_file): + def __check_config(self, context, config_filename): """ Check the configuration and set or override options if necessary, considering mandatory: username and password in the [credentials] section @@ -355,7 +360,7 @@ def __check_config(self, context, config_file): for section in mandatory_sections: if not self.config.has_section(section): debugmessage(100, "BareosFdPluginLibcloud: Section [%s] missing in config file %s\n" - % (section, config_file)) + % (section, config_filename)) return False for option in mandatory_options[section]: @@ -378,14 +383,14 @@ def __check_config(self, context, config_file): else: self.options[option_map[option]] = value except: - debugmessage(100, "Could not evaluate: %s in config file %s" % (value, config_file)) + debugmessage(100, "Could not evaluate: %s in config file %s" % (value, config_filename)) return False return True def start_backup_job(self, context): try: - jobmessage("M_INFO", "Try to connect to:" + self.options["port"]) + jobmessage("M_INFO", "Try to connect to %s:%s" % (self.options["host"], self.options["port"])) driver = connect(self.options) for _ in driver.iterate_containers(): break @@ -425,12 +430,15 @@ def start_backup_job(self, context): return bRCs["bRC_OK"] def check_file(self, context, fname): - # All existing files are passed to bareos + # All existing files/objects are passed to bareos # If bareos have not seen one, it does not exists anymore return bRCs["bRC_Error"] def __shutdown_and_join_worker(self): - jobmessage("M_INFO", "Backup is completed") + if self.number_of_objects_to_backup: + jobmessage("M_INFO", "Backup completed with %d objects" % self.number_of_objects_to_backup) + else: + jobmessage("M_INFO", "No objects to backup") for i in self.workers: debugmessage(100, "join() for a worker (pid %s)" % (i.pid,)) i.join() @@ -477,6 +485,8 @@ def start_backup_file(self, context, savepkt): savepkt.fname = filename savepkt.type = bareos_fd_consts.bFileType["FT_REG"] + self.number_of_objects_to_backup += 1 + return bRCs["bRC_OK"] def plugin_io(self, context, IOP): From 5fb5608d9d66109a47e9c0f2f4bff04d7a3767d8 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 17 Mar 2020 11:44:33 +0100 Subject: [PATCH 266/341] libcloud-plugin: reformat using black --- .../plugins/filed/BareosFdPluginLibcloud.py | 113 ++++++++++++------ 1 file changed, 75 insertions(+), 38 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index fa206dc5615..69515c03f1b 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -42,25 +42,20 @@ plugin_context = None + def jobmessage(message_type, message): global plugin_context if plugin_context != None: message = "BareosFdPluginLibcloud [%s]: %s\n" % (os.getpid(), message) - bareosfd.JobMessage( - plugin_context, - bJobMessageType[message_type], - message - ) + bareosfd.JobMessage(plugin_context, bJobMessageType[message_type], message) + def debugmessage(level, message): global plugin_context if plugin_context != None: message = "BareosFdPluginLibcloud [%s]: %s\n" % (os.getpid(), message) - bareosfd.DebugMessage( - plugin_context, - level, - message - ) + bareosfd.DebugMessage(plugin_context, level, message) + class IterStringIO(io.BufferedIOBase): def __init__(self, iterable): @@ -107,9 +102,10 @@ def get_object(driver, bucket, key): except libcloud.common.types.InvalidCredsError: # Something is buggy here, this bug is triggered by tilde-ending objects # Our tokens are good, we used them before - debugmessage(100, + debugmessage( + 100, "BUGGY filename found, see the libcloud bug somewhere : %s/%s" - % (bucket, key) + % (bucket, key), ) return None @@ -131,7 +127,9 @@ def __load_object(self): while True: job = self.worker_todo_queue.get() if job is None: - debugmessage(100, "worker[%s] : job completed, will quit now" % (os.getpid(),)) + debugmessage( + 100, "worker[%s] : job completed, will quit now" % (os.getpid(),) + ) return obj = get_object(self.driver, job["bucket"], job["name"]) @@ -144,9 +142,10 @@ def __load_object(self): size_of_fetched_object = len(content) if size_of_fetched_object != job["size"]: - debugmessage(100, + debugmessage( + 100, "prefetched file %s: got %s bytes, not the real size (%s bytes)" - % (job["name"], size_of_fetched_object, job["size"]) + % (job["name"], size_of_fetched_object, job["size"]), ) return @@ -184,9 +183,11 @@ def __iterate_over_buckets(self): if bucket.name in self.options["buckets_exclude"]: continue - debugmessage(100, "Backing up bucket \"%s\"" % (bucket.name,)) + debugmessage(100, 'Backing up bucket "%s"' % (bucket.name,)) - self.__generate_jobs_for_bucket_objects(self.driver.iterate_container_objects(bucket)) + self.__generate_jobs_for_bucket_objects( + self.driver.iterate_container_objects(bucket) + ) def __get_mtime(self, obj): mtime = dateutil.parser.parse(obj.extra["last_modified"]) @@ -211,9 +212,10 @@ def __generate_jobs_for_bucket_objects(self, bucket_iterator): object_name = "%s/%s" % (obj.container.name, obj.name) if self.last_run > mtime: - debugmessage(100, + debugmessage( + 100, "File %s not changed, skipped (%s > %s)" - % (object_name, self.last_run, mtime) + % (object_name, self.last_run, mtime), ) # This object was present on our last backup @@ -225,9 +227,10 @@ def __generate_jobs_for_bucket_objects(self, bucket_iterator): continue - debugmessage(100, + debugmessage( + 100, "File %s was changed or is new, backing up (%s < %s)" - % (object_name, self.last_run, mtime) + % (object_name, self.last_run, mtime), ) # Do not prefetch large objects @@ -261,7 +264,9 @@ class BareosFdPluginLibcloud(BareosFdPluginBaseclass.BareosFdPluginBaseclass): def __init__(self, context, plugindef): global plugin_context plugin_context = context - debugmessage(100, "BareosFdPluginLibcloud called with plugindef: %s" % (plugindef,)) + debugmessage( + 100, "BareosFdPluginLibcloud called with plugindef: %s" % (plugindef,) + ) super(BareosFdPluginLibcloud, self).__init__(context, plugindef) super(BareosFdPluginLibcloud, self).parse_plugin_definition(context, plugindef) @@ -329,12 +334,13 @@ def __parse_config_file(self, context, config_filename): self.config = configparser.ConfigParser() try: - if version_info[:3] < (3,2): + if version_info[:3] < (3, 2): self.config.readfp(open(config_filename)) else: self.config.read_file(open(config_filename)) except (IOError, OSError) as err: - debugmessage(100, + debugmessage( + 100, "BareosFdPluginLibcloud: Error reading config file %s: %s\n" % (self.options["config_file"], err.strerror), ) @@ -353,20 +359,31 @@ def __check_config(self, context, config_filename): mandatory_options["host"] = ["hostname", "port", "provider", "tls"] mandatory_options["misc"] = ["nb_worker", "queue_size", "prefetch_size"] - #this maps config file options to libcloud options - option_map = {"hostname":"host", "port":"port", "provider":"provider", - "username":"key", "password":"secret"} + # this maps config file options to libcloud options + option_map = { + "hostname": "host", + "port": "port", + "provider": "provider", + "username": "key", + "password": "secret", + } for section in mandatory_sections: if not self.config.has_section(section): - debugmessage(100, "BareosFdPluginLibcloud: Section [%s] missing in config file %s\n" - % (section, config_filename)) + debugmessage( + 100, + "BareosFdPluginLibcloud: Section [%s] missing in config file %s\n" + % (section, config_filename), + ) return False for option in mandatory_options[section]: if not self.config.has_option(section, option): - debugmessage(100, "BareosFdPluginLibcloud: Option [%s] missing in Section %s\n" - % (option, section)) + debugmessage( + 100, + "BareosFdPluginLibcloud: Option [%s] missing in Section %s\n" + % (option, section), + ) return False value = self.config.get(section, option) @@ -383,14 +400,22 @@ def __check_config(self, context, config_filename): else: self.options[option_map[option]] = value except: - debugmessage(100, "Could not evaluate: %s in config file %s" % (value, config_filename)) + debugmessage( + 100, + "Could not evaluate: %s in config file %s" + % (value, config_filename), + ) return False return True def start_backup_job(self, context): try: - jobmessage("M_INFO", "Try to connect to %s:%s" % (self.options["host"], self.options["port"])) + jobmessage( + "M_INFO", + "Try to connect to %s:%s" + % (self.options["host"], self.options["port"]), + ) driver = connect(self.options) for _ in driver.iterate_containers(): break @@ -436,7 +461,10 @@ def check_file(self, context, fname): def __shutdown_and_join_worker(self): if self.number_of_objects_to_backup: - jobmessage("M_INFO", "Backup completed with %d objects" % self.number_of_objects_to_backup) + jobmessage( + "M_INFO", + "Backup completed with %d objects" % self.number_of_objects_to_backup, + ) else: jobmessage("M_INFO", "No objects to backup") for i in self.workers: @@ -451,7 +479,9 @@ def __shutdown_and_join_worker(self): pass debugmessage(100, "self.manager.shutdown()") - debugmessage(100, "Join() for the job_generator (pid %s)" % (self.job_generator.pid,)) + debugmessage( + 100, "Join() for the job_generator (pid %s)" % (self.job_generator.pid,) + ) self.job_generator.join() debugmessage(100, "job_generator is shut down") @@ -469,10 +499,13 @@ def start_backup_file(self, context, savepkt): if self.current_backup_job is None: self.__shutdown_and_join_worker() - savepkt.fname = "empty" # dummy value, savepkt is always checked + savepkt.fname = "empty" # dummy value, savepkt is always checked return bRCs["bRC_Skip"] - filename = "PYLIBCLOUD:/%s/%s" % (self.current_backup_job["bucket"], self.current_backup_job["name"]) + filename = "PYLIBCLOUD:/%s/%s" % ( + self.current_backup_job["bucket"], + self.current_backup_job["name"], + ) jobmessage("M_INFO", "Backing up %s" % (filename,)) statp = bareosfd.StatPacket() @@ -500,7 +533,11 @@ def plugin_io(self, context, IOP): # 'Backup' path if self.current_backup_job["data"] is None: - obj = get_object(self.driver, self.current_backup_job["bucket"], self.current_backup_job["name"]) + obj = get_object( + self.driver, + self.current_backup_job["bucket"], + self.current_backup_job["name"], + ) if obj is None: self.FILE = None return bRCs["bRC_Error"] From 740df75640b4614feedc23239a833cc954f4f85f Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 17 Mar 2020 09:34:44 +0100 Subject: [PATCH 267/341] python-plugins debian packaging: remove ${shlibs:Depends} --- debian/control.bareos-filedaemon-python-plugin | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/debian/control.bareos-filedaemon-python-plugin b/debian/control.bareos-filedaemon-python-plugin index 468213412d1..f075c27a1d7 100644 --- a/debian/control.bareos-filedaemon-python-plugin +++ b/debian/control.bareos-filedaemon-python-plugin @@ -13,7 +13,7 @@ Package: bareos-filedaemon-ldap-python-plugin Architecture: any Section: python Pre-Depends: debconf (>= 1.4.30) | debconf-2.0 -Depends: bareos-common (= ${binary:Version}), bareos-filedaemon-python-plugin (= ${binary:Version}), python-ldap, ${shlibs:Depends}, ${misc:Depends} +Depends: bareos-common (= ${binary:Version}), bareos-filedaemon-python-plugin (= ${binary:Version}), python-ldap, ${misc:Depends} Description: Backup Archiving Recovery Open Sourced - file daemon LDAP plugin Bareos is a set of programs to manage backup, recovery and verification of data across a network of computers of different kinds. @@ -24,7 +24,7 @@ Package: bareos-filedaemon-percona-xtrabackup-python-plugin Architecture: any Section: python Pre-Depends: debconf (>= 1.4.30) | debconf-2.0 -Depends: bareos-common (= ${binary:Version}), bareos-filedaemon-python-plugin (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends} +Depends: bareos-common (= ${binary:Version}), bareos-filedaemon-python-plugin (= ${binary:Version}), ${misc:Depends} Description: Backup Archiving Recovery Open Sourced - file daemon LDAP plugin Bareos is a set of programs to manage backup, recovery and verification of data across a network of computers of different kinds. @@ -35,7 +35,7 @@ Package: bareos-filedaemon-libcloud-python-plugin Architecture: any Section: python Pre-Depends: debconf (>= 1.4.30) | debconf-2.0 -Depends: bareos-common (= ${binary:Version}), bareos-filedaemon-python-plugin (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends} +Depends: bareos-common (= ${binary:Version}), bareos-filedaemon-python-plugin (= ${binary:Version}), ${misc:Depends} Description: Backup Archiving Recovery Open Sourced - file daemon LDAP plugin Bareos is a set of programs to manage backup, recovery and verification of data across a network of computers of different kinds. From 6a4ea7f2a3f9f0b3f949d3286ccd4b4d5ce1a853 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 17 Mar 2020 09:39:05 +0100 Subject: [PATCH 268/341] libcloud-plugin: fix packaging .in file --- core/debian/bareos-filedaemon-libcloud-python-plugin.install.in | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 core/debian/bareos-filedaemon-libcloud-python-plugin.install.in diff --git a/core/debian/bareos-filedaemon-libcloud-python-plugin.install.in b/core/debian/bareos-filedaemon-libcloud-python-plugin.install.in new file mode 100644 index 00000000000..e48f58a8353 --- /dev/null +++ b/core/debian/bareos-filedaemon-libcloud-python-plugin.install.in @@ -0,0 +1,2 @@ +@plugindir@/bareos-fd-libcloud.py* +@plugindir@/BareosFdPluginLibcloud.py* From c6a3365f18671760fd26c6cbb41778827044ab74 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 17 Mar 2020 14:21:03 +0100 Subject: [PATCH 269/341] s3cfg added --- .../tests/python-fd-plugin-libcloud-test/s3cfg | 14 ++++++++++++++ core/CMakeLists.txt | 1 + core/cmake/BareosFindPrograms.cmake | 1 + systemtests/CMakeLists.txt | 7 +++++++ 4 files changed, 23 insertions(+) create mode 100644 b/systemtests/tests/python-fd-plugin-libcloud-test/s3cfg diff --git a/b/systemtests/tests/python-fd-plugin-libcloud-test/s3cfg b/b/systemtests/tests/python-fd-plugin-libcloud-test/s3cfg new file mode 100644 index 00000000000..43236c103da --- /dev/null +++ b/b/systemtests/tests/python-fd-plugin-libcloud-test/s3cfg @@ -0,0 +1,14 @@ +# Setup endpoint +host_base = 127.0.0.1:9000 +host_bucket = 127.0.0.1:9000 +bucket_location = us-east-1 +use_https = True + +# Setup access keys +access_key = minioadmin +secret_key = minioadmin + +# Enable S3 v4 signature APIs +signature_v2 = False + +use_https = False diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index c991856b9ae..3e390898c0a 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -925,6 +925,7 @@ message(" AWK: ${AWK}") message(" GAWK: ${GAWK}") message(" RPCGEN: ${RPCGEN}") message(" MTX: ${MTX}") +message(" S3CMD: ${S3CMD}") message(" XTRABACKUP: ${XTRABACKUP}") message(" DEVELOPER: ${developer}") message(" LocalBuildDefinitionsFile: ${BareosLocalBuildDefinitionsFile}") diff --git a/core/cmake/BareosFindPrograms.cmake b/core/cmake/BareosFindPrograms.cmake index db60cb13dde..8cd1d24c898 100644 --- a/core/cmake/BareosFindPrograms.cmake +++ b/core/cmake/BareosFindPrograms.cmake @@ -39,4 +39,5 @@ find_program(GDB gdb) find_program(DBX dbx) find_program(MDB mdb) find_program(XTRABACKUP xtrabackup) +find_program(S3CMD s3cmd) diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 351d717810b..38cff029657 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -629,10 +629,17 @@ else() endif() if(TARGET python-fd) + if(S3CMD) + list(APPEND SYSTEM_TESTS "python-fd-plugin-libcloud-test") + else() + message("s3cmd not found, disabling python-fd-plugin-libcloud-test") + list(APPEND SYSTEM_TESTS_DISABLED "python-fd-plugin-libcloud-test") + endif() list(APPEND SYSTEM_TESTS "pyplug-fd-local-fileset-restoreobject") else() list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-local-fileset-restoreobject") endif() + list(APPEND SYSTEM_TESTS_DISABLED "python-fd-plugin-libcloud-test") message("checking for requirements of pyplug-fd-postgres:") check_pymodule_available("psycopg2") From f6f3a99b263ab106fa17331fb353d74fa2c056b4 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 17 Mar 2020 16:11:19 +0100 Subject: [PATCH 270/341] s3cmd works --- systemtests/environment.in | 6 +++--- .../s3cfg | 0 .../tests/python-fd-plugin-libcloud-test/testrunner | 10 +++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) rename {b/systemtests/tests/python-fd-plugin-libcloud-test => systemtests}/s3cfg (100%) diff --git a/systemtests/environment.in b/systemtests/environment.in index 07a8efc369a..9028679940d 100644 --- a/systemtests/environment.in +++ b/systemtests/environment.in @@ -109,12 +109,12 @@ export OVIRT_SERVER=@ovirt_server@ # real postgres binaries are hidden on debian, instead there are wrappers # which we do not want for our tests if [ -d /usr/lib/postgresql ]; then - POSTGRES_BINARY_DIR=$(dirname $(find -L /usr/lib/postgresql | grep psql)) + POSTGRES_BINARY_DIR=$(dirname $(find /usr/lib/postgresql | grep psql)) export PATH=$POSTGRES_BINARY_DIR:$PATH else export PATH=/sbin:/usr/sbin:$PATH fi export PYTHONPATH=@pythonpath@ -# enable deprecated database handling in scripts -export BAREOS_TEST_RUNNING=yes +S3CMD="@S3CMD@" +S3CFG="${PROJECT_SOURCE_DIR}/s3cfg" diff --git a/b/systemtests/tests/python-fd-plugin-libcloud-test/s3cfg b/systemtests/s3cfg similarity index 100% rename from b/systemtests/tests/python-fd-plugin-libcloud-test/s3cfg rename to systemtests/s3cfg diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/testrunner b/systemtests/tests/python-fd-plugin-libcloud-test/testrunner index 6cb42514933..fdcbe63a94a 100755 --- a/systemtests/tests/python-fd-plugin-libcloud-test/testrunner +++ b/systemtests/tests/python-fd-plugin-libcloud-test/testrunner @@ -23,6 +23,14 @@ JobName=backup-bareos-fd "${rscripts}"/cleanup "${rscripts}"/setup +# shortcut for s3cmd +S3="${S3CMD} --config ${S3CFG}" + +# create s3 content for test +${S3} rb --recursive --force s3://test || echo "s3://test does not exist" +${S3} mb s3://test + + # Directory to backup. @@ -69,6 +77,6 @@ stop_bareos check_two_logs list=( $(find "${BackupDirectory}" -type f) ) # Using check_restore_only_files_diff instead of check_restore_diff -# to don't diff the file attributes, because they are not saved +# to don'"t diff the file attributes, because they are not saved check_restore_only_files_diff "${list[@]}" end_test From ec2f53785528c6acb161553da88b1c7fd18f1eb7 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 17 Mar 2020 16:16:05 +0100 Subject: [PATCH 271/341] upload BackupDirectory --- .../tests/python-fd-plugin-libcloud-test/testrunner | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/testrunner b/systemtests/tests/python-fd-plugin-libcloud-test/testrunner index fdcbe63a94a..2e4bfc4f7e3 100755 --- a/systemtests/tests/python-fd-plugin-libcloud-test/testrunner +++ b/systemtests/tests/python-fd-plugin-libcloud-test/testrunner @@ -26,12 +26,6 @@ JobName=backup-bareos-fd # shortcut for s3cmd S3="${S3CMD} --config ${S3CFG}" -# create s3 content for test -${S3} rb --recursive --force s3://test || echo "s3://test does not exist" -${S3} mb s3://test - - - # Directory to backup. # This directory will be created by setup_data "$@"(). @@ -41,6 +35,12 @@ BackupDirectory="${tmp}/data" # Data will be placed at "${tmp}/data/". setup_data "$@" +# create s3 content for test +${S3} rb --recursive --force s3://test || echo "s3://test does not exist" +${S3} mb s3://test +${S3} sync "$BackupDirectory" s3://test + + # this test does not work with links because of the restore objects rm -r "${tmp}"/data/weird-files >/dev/null 2>&1 From ab0146be4b31ee8c192afe8d0fcd11b2cc56da42 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 17 Mar 2020 16:26:41 +0100 Subject: [PATCH 272/341] libcloud test with local restore works --- .../tests/python-fd-plugin-libcloud-test/testrunner | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/testrunner b/systemtests/tests/python-fd-plugin-libcloud-test/testrunner index 2e4bfc4f7e3..627a37c0763 100755 --- a/systemtests/tests/python-fd-plugin-libcloud-test/testrunner +++ b/systemtests/tests/python-fd-plugin-libcloud-test/testrunner @@ -38,11 +38,11 @@ setup_data "$@" # create s3 content for test ${S3} rb --recursive --force s3://test || echo "s3://test does not exist" ${S3} mb s3://test -${S3} sync "$BackupDirectory" s3://test # this test does not work with links because of the restore objects rm -r "${tmp}"/data/weird-files >/dev/null 2>&1 +${S3} sync "$BackupDirectory" s3://test start_test @@ -78,5 +78,8 @@ check_two_logs list=( $(find "${BackupDirectory}" -type f) ) # Using check_restore_only_files_diff instead of check_restore_diff # to don'"t diff the file attributes, because they are not saved -check_restore_only_files_diff "${list[@]}" +#check_restore_only_files_diff "${list[@]}" + +diff -r tmp/data tmp/bareos-restores/PYLIBCLOUD\:/test/data + end_test From 01fc497979b3d1c787a0f1b0ac19bea261e5a409 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 17 Mar 2020 13:33:45 +0100 Subject: [PATCH 273/341] libcloud-plugin: add documentation --- .../source/TasksAndConcepts/Plugins.rst | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/docs/manuals/source/TasksAndConcepts/Plugins.rst b/docs/manuals/source/TasksAndConcepts/Plugins.rst index 4d1a8765e8d..e41d16a4aa8 100644 --- a/docs/manuals/source/TasksAndConcepts/Plugins.rst +++ b/docs/manuals/source/TasksAndConcepts/Plugins.rst @@ -1168,6 +1168,138 @@ This will create disk image files that could be examined for example by using the **guestfish** tool (see http://libguestfs.org/guestfish.1.html). This tool can also be used to extract single files from the disk image. +.. _LibcloudPlugin: + +Apache Libcloud Plugin +~~~~~~~~~~~~~~~~~~~~~~ + +.. index:: + pair: Plugin; libcloud + +The Libcloud plugin can be used to backup objects from backends that support the Simple Storage Service (S3) protcol. + +.. _LibcloudPlugin-status: + +Status +^^^^^^ + +The status of the Libcloud plugin is experimental. It can automatically recurse nested Buckets and backup all included Objects +on a S3 storage. However, restore of Objects cannot be done directly back to the storage. A restore will write these objects +as files on a filesystem. + +Transport encryption between plugin and the S3 backend is not implemented, yet. + +.. _LibcloudPlugin-requirements: + +Requirements +^^^^^^^^^^^^ + +To use the Apache Libcloud backend you need to have the Libcloud module available for either Python 3 or 2. + +.. _LibcloudPlugin-installation: + +Installation +^^^^^^^^^^^^ + +The installation is done by installing the package **bareos-filedaemon-libcloud-python-plugin**: + +.. code-block:: shell + + yum install bareos-filedaemon-libcloud-python-plugin + + +.. _LibcloudPlugin-configuration: + +Configuration +^^^^^^^^^^^^^ + +.. code-block:: bareosconfig + :caption: /etc/bareos/bareos-dir.d/fileset/PluginTest.conf + + FileSet { + Name = "PluginTest" + Description = "Test the Plugin functionality with a Python Plugin." + Include { + Options { + signature = MD5 + } + Plugin = "python:module_path=/usr/lib64/bareos/plugins:module_name=bareos-fd-libcloud:config_file=/etc/bareos/libcloud_config.ini:buckets_include=user_data:buckets_exclude=tmp" + } + } + +.. note:: + + The Plugin options string can currently not be split over multiple lines in the configuration file. + +And the job as follows: + +.. code-block:: bareosconfig + :caption: /etc/bareos/bareos-dir.d/job/testvm1_job.conf + + Job { + Name = "testlibcloud_job" + JobDefs = "DefaultJob" + FileSet = "PluginTest" + } + +And the config file as follows: + +.. code-block:: bareosconfig + :caption: /etc/bareos/libcloud_config.ini + + [host] + hostname=127.0.0.1 + port=9000 + tls=false + provider=S3 + + [credentials] + username=admin + password=admin + + [misc] + nb_worker=20 + queue_size=1000 + prefetch_size=10*1024*1024 + +.. note:: + + Do not use quotes in the above config file, it is processed by the Python ConfigParser module and the quotes would not be stripped from the string. + +Mandatory Plugin Options: + +All options in the config file are mandatory: + +hostname + The hostname/ip address of the storage backend server + +port + The portnumber for the backend server + +tls + Use Transport encryption, currently only 'False' + +provider + The provider string, currently only 'S3' + +username + The username to use for backups + +password + The password for the backup user + +nb_worker + The number of worker processes who can preload data from objects simultaneusly + before they are given to the plugin process that does the backup + +queue_size + The maximum size in numbers of objects of the internal communication queue + between the processes + +prefetch_size + The maximum size in kB for objects to be preloaded from the workers; objects above + this size are loaded by the plugin process itself + .. _PerconaXtrabackupPlugin: .. _backup-mysql-XtraBackup: From c5ecebc1bf0c9dad5aa39ce6d949f9b8697529b5 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 17 Mar 2020 16:19:45 +0100 Subject: [PATCH 274/341] libcloud-plugin: do not restore the plugin path prefix - all bucket-names get the "PYLIBLCOUD:/" prefix when doing a backup - on a restore to the filesystem the prefix is removed automatically by the plugin --- .../plugins/filed/BareosFdPluginLibcloud.py | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 69515c03f1b..f7439f5ae5d 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -33,7 +33,7 @@ import syslog import time -from bareos_fd_consts import bRCs, bIOPS, bJobMessageType +from bareos_fd_consts import bRCs, bCFs, bIOPS, bJobMessageType, bFileType from libcloud.storage.types import Provider from libcloud.storage.providers import get_driver from sys import version_info @@ -42,7 +42,6 @@ plugin_context = None - def jobmessage(message_type, message): global plugin_context if plugin_context != None: @@ -64,6 +63,17 @@ def __init__(self, iterable): def read(self, n=None): return bytearray(itertools.islice(self.iter, None, n)) +class FilenameConverter: + __pathprefix = 'PYLIBCLOUD:/' + + @staticmethod + def BucketToBackup(filename): + return FilenameConverter.__pathprefix + filename + + @staticmethod + def BackupToBucket(filename): + return filename.replace(FilenameConverter.__pathprefix, '') + def str2bool(data): if data == "false" or data == "False": @@ -502,9 +512,11 @@ def start_backup_file(self, context, savepkt): savepkt.fname = "empty" # dummy value, savepkt is always checked return bRCs["bRC_Skip"] - filename = "PYLIBCLOUD:/%s/%s" % ( + filename = FilenameConverter.BucketToBackup( + "%s/%s" % ( self.current_backup_job["bucket"], self.current_backup_job["name"], + ) ) jobmessage("M_INFO", "Backing up %s" % (filename,)) @@ -522,13 +534,24 @@ def start_backup_file(self, context, savepkt): return bRCs["bRC_OK"] + def create_file(self, context, restorepkt): + debugmessage(100, "create_file() entry point in Python called with %s\n" % (restorepkt)) + FNAME = FilenameConverter.BackupToBucket(restorepkt.ofname) + dirname = os.path.dirname(FNAME) + if not os.path.exists(dirname): + jobmessage("M_INFO", "Directory %s does not exist, creating it now\n" % dirname) + os.makedirs(dirname) + if restorepkt.type == bFileType["FT_REG"]: + restorepkt.create_status = bCFs["CF_EXTRACT"] + return bRCs["bRC_OK"] + def plugin_io(self, context, IOP): if self.current_backup_job is None: return bRCs["bRC_Error"] if IOP.func == bIOPS["IO_OPEN"]: # Only used by the 'restore' path if IOP.flags & (os.O_CREAT | os.O_WRONLY): - self.FILE = open(IOP.fname, "wb") + self.FILE = open(FilenameConverter.BackupToBucket(IOP.fname), "wb") return bRCs["bRC_OK"] # 'Backup' path @@ -556,7 +579,8 @@ def plugin_io(self, context, IOP): IOP.status = len(buf) return bRCs["bRC_OK"] except IOError as e: - jobmessage("M_ERROR", "Cannot read from %s : %s" % (IOP.fname, e)) + jobmessage("M_ERROR", "Cannot read from %s : %s" + % (FilenameConverter.BackupToBucket(IOP.fname), e)) IOP.status = 0 IOP.io_errno = e.errno return bRCs["bRC_Error"] From 9faddd44f7a2dc701a41e76ce180038551ab4bc1 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Wed, 18 Mar 2020 13:46:09 +0100 Subject: [PATCH 275/341] Updated AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index bbc676b85a4..56cd50fbdb6 100644 --- a/AUTHORS +++ b/AUTHORS @@ -13,6 +13,7 @@ Alessandro Rigopoulos Alexander Bergolth Alexander Kushnirenko Alexandre Baron +Alexandre Bruyelles Alexandre Simon Allan Black Alvaro Flaño From 4122777b73c6b28bf24c90e3ecf76f6d342036f0 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Wed, 18 Mar 2020 14:21:40 +0100 Subject: [PATCH 276/341] libcloud-plugin: updated docs --- docs/manuals/source/TasksAndConcepts/Plugins.rst | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/manuals/source/TasksAndConcepts/Plugins.rst b/docs/manuals/source/TasksAndConcepts/Plugins.rst index e41d16a4aa8..3a0beaa3a0f 100644 --- a/docs/manuals/source/TasksAndConcepts/Plugins.rst +++ b/docs/manuals/source/TasksAndConcepts/Plugins.rst @@ -1176,7 +1176,7 @@ Apache Libcloud Plugin .. index:: pair: Plugin; libcloud -The Libcloud plugin can be used to backup objects from backends that support the Simple Storage Service (S3) protcol. +The Libcloud plugin can be used to backup objects from backends that support the Simple Storage Service (S3) protcol. The plugin code is based on the work of Alexandre Bruyelles. .. _LibcloudPlugin-status: @@ -1187,14 +1187,12 @@ The status of the Libcloud plugin is experimental. It can automatically recurse on a S3 storage. However, restore of Objects cannot be done directly back to the storage. A restore will write these objects as files on a filesystem. -Transport encryption between plugin and the S3 backend is not implemented, yet. - .. _LibcloudPlugin-requirements: Requirements ^^^^^^^^^^^^ -To use the Apache Libcloud backend you need to have the Libcloud module available for either Python 3 or 2. +To use the Apache Libcloud backend you need to have the Libcloud module available for Python 2. .. _LibcloudPlugin-installation: @@ -1277,7 +1275,7 @@ port The portnumber for the backend server tls - Use Transport encryption, currently only 'False' + Use Transport encryption, if supported by the backend provider The provider string, currently only 'S3' From 53f527fe8141a8ac7123a030ada9227b1c67d8fb Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Wed, 18 Mar 2020 15:45:32 +0100 Subject: [PATCH 277/341] libcloud-test: evaluate the returncode of the diff command --- systemtests/tests/python-fd-plugin-libcloud-test/testrunner | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/testrunner b/systemtests/tests/python-fd-plugin-libcloud-test/testrunner index 627a37c0763..8f586494af2 100755 --- a/systemtests/tests/python-fd-plugin-libcloud-test/testrunner +++ b/systemtests/tests/python-fd-plugin-libcloud-test/testrunner @@ -80,6 +80,8 @@ list=( $(find "${BackupDirectory}" -type f) ) # to don'"t diff the file attributes, because they are not saved #check_restore_only_files_diff "${list[@]}" -diff -r tmp/data tmp/bareos-restores/PYLIBCLOUD\:/test/data +if ! diff -r tmp/data tmp/bareos-restores/test/data; then + export estat=1 +fi end_test From c31b9b66e4fa2918655e6b2cde5fe41df11cfbbe Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Wed, 18 Mar 2020 21:20:38 +0100 Subject: [PATCH 278/341] libcloud-plugin: removed dead code --- core/src/plugins/filed/BareosFdPluginLibcloud.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index f7439f5ae5d..da3085b0b3a 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -166,12 +166,11 @@ def __load_object(self): class JobCreator(object): - def __init__(self, plugin_todo_queue, worker_todo_queue, last_run, opts, pids): + def __init__(self, plugin_todo_queue, worker_todo_queue, last_run, opts): self.plugin_todo_queue = plugin_todo_queue self.worker_todo_queue = worker_todo_queue self.last_run = last_run self.options = opts - self.pids = pids self.driver = connect(self.options) self.delta = datetime.timedelta(seconds=time.timezone) @@ -456,7 +455,6 @@ def start_backup_job(self, context): self.worker_todo_queue, self.last_run, self.options, - self.worker_pids, ) self.job_generator = multiprocessing.Process(target=job_generator) self.job_generator.start() From 23d7bb706de493ac4ea67f2fbac22b415e8b7513 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Wed, 18 Mar 2020 21:37:21 +0100 Subject: [PATCH 279/341] libcloud-plugin: disabled multi processing --- .../plugins/filed/BareosFdPluginLibcloud.py | 112 ++---------------- 1 file changed, 12 insertions(+), 100 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index da3085b0b3a..a9ef0df70f1 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -119,56 +119,9 @@ def get_object(driver, bucket, key): ) return None - -class Worker(object): - def __init__(self, options, plugin_todo_queue, worker_todo_queue): - self.options = options - self.plugin_todo_queue = plugin_todo_queue - self.worker_todo_queue = worker_todo_queue - - def __call__(self): - try: - self.driver = connect(self.options) - self.__load_object() - except: - debugmessage(100, "Worker could not connect to driver") - - def __load_object(self): - while True: - job = self.worker_todo_queue.get() - if job is None: - debugmessage( - 100, "worker[%s] : job completed, will quit now" % (os.getpid(),) - ) - return - - obj = get_object(self.driver, job["bucket"], job["name"]) - if obj is None: - # Object cannot be fetched, an error is already logged - continue - - stream = obj.as_stream() - content = b"".join(list(stream)) - - size_of_fetched_object = len(content) - if size_of_fetched_object != job["size"]: - debugmessage( - 100, - "prefetched file %s: got %s bytes, not the real size (%s bytes)" - % (job["name"], size_of_fetched_object, job["size"]), - ) - return - - data = io.BytesIO(content) - - job["data"] = data - self.plugin_todo_queue.put(job) - - class JobCreator(object): - def __init__(self, plugin_todo_queue, worker_todo_queue, last_run, opts): + def __init__(self, plugin_todo_queue, last_run, opts): self.plugin_todo_queue = plugin_todo_queue - self.worker_todo_queue = worker_todo_queue self.last_run = last_run self.options = opts @@ -180,7 +133,8 @@ def __call__(self): self.__iterate_over_buckets() except: debugmessage(100, "Error while iterating over buckets") - self.__end_job() + + self.plugin_todo_queue.put(None) #end def __iterate_over_buckets(self): for bucket in self.driver.iterate_containers(): @@ -242,32 +196,7 @@ def __generate_jobs_for_bucket_objects(self, bucket_iterator): % (object_name, self.last_run, mtime), ) - # Do not prefetch large objects - if obj.size >= self.options["prefetch_size"]: - self.plugin_todo_queue.put(job) - else: - self.worker_todo_queue.put(job) - - def __end_job(self): - debugmessage(100, "__end_job: waiting for workers queue to become empty") - while True: - size = self.worker_todo_queue.qsize() - if size == 0: - break - log("__end_job: %s items left in workers queue, waiting" % (size,)) - time.sleep(2) - debugmessage(100, "__end_job: workers queue is empty") - - debugmessage(100, "__end_job: I will shutdown all workers now") - for _ in range(0, self.options["nb_worker"]): - self.worker_todo_queue.put(None) - - while not self.worker_todo_queue.empty(): - pass - - # notify the plugin that the workers are ready - self.plugin_todo_queue.put(None) - + self.plugin_todo_queue.put(job) class BareosFdPluginLibcloud(BareosFdPluginBaseclass.BareosFdPluginBaseclass): def __init__(self, context, plugindef): @@ -289,6 +218,7 @@ def __init__(self, context, plugindef): # Restore's path will not touch this self.current_backup_job = {} self.number_of_objects_to_backup = 0 + self.driver = None def __parse_options_bucket(self, name): if name not in self.options: @@ -425,9 +355,7 @@ def start_backup_job(self, context): "Try to connect to %s:%s" % (self.options["host"], self.options["port"]), ) - driver = connect(self.options) - for _ in driver.iterate_containers(): - break + self.driver = connect(self.options) except: jobmessage("M_FATAL", "Could not connect to libcloud driver") return bRCs["bRC_Error"] @@ -436,30 +364,15 @@ def start_backup_job(self, context): self.manager = multiprocessing.Manager() self.plugin_todo_queue = self.manager.Queue(maxsize=self.options["queue_size"]) - self.worker_todo_queue = self.manager.Queue(maxsize=self.options["nb_worker"]) - - self.worker_pids = list() - self.workers = list() - for _ in range(0, self.options["nb_worker"]): - target = Worker( - self.options, self.plugin_todo_queue, self.worker_todo_queue - ) - proc = multiprocessing.Process(target=target) - proc.start() - self.worker_pids.append(proc.pid) - self.workers.append(proc) - debugmessage(100, "%s worker started" % (len(self.worker_pids),)) job_generator = JobCreator( self.plugin_todo_queue, - self.worker_todo_queue, self.last_run, self.options, ) self.job_generator = multiprocessing.Process(target=job_generator) self.job_generator.start() - self.driver = connect(self.options) - debugmessage(100, "%s job creator started" % (len(self.worker_pids),)) + return bRCs["bRC_OK"] def check_file(self, context, fname): @@ -467,7 +380,7 @@ def check_file(self, context, fname): # If bareos have not seen one, it does not exists anymore return bRCs["bRC_Error"] - def __shutdown_and_join_worker(self): + def __shutdown_and_join_processes(self): if self.number_of_objects_to_backup: jobmessage( "M_INFO", @@ -475,10 +388,6 @@ def __shutdown_and_join_worker(self): ) else: jobmessage("M_INFO", "No objects to backup") - for i in self.workers: - debugmessage(100, "join() for a worker (pid %s)" % (i.pid,)) - i.join() - debugmessage(100, "Ok, all workers are shut down") try: self.manager.shutdown() @@ -503,10 +412,12 @@ def start_backup_file(self, context, savepkt): except: time.sleep(0.1) except TypeError: + debugmessage(100, "self.current_backup_job = None") self.current_backup_job = None if self.current_backup_job is None: - self.__shutdown_and_join_worker() + debugmessage(100, "Shutdown and join processes") + self.__shutdown_and_join_processes() savepkt.fname = "empty" # dummy value, savepkt is always checked return bRCs["bRC_Skip"] @@ -516,6 +427,7 @@ def start_backup_file(self, context, savepkt): self.current_backup_job["name"], ) ) + debugmessage(100, "backup %s" % (filename,)) jobmessage("M_INFO", "Backing up %s" % (filename,)) statp = bareosfd.StatPacket() From 39b08c56aa859a9cc92844cf055fd077cecd5ef0 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 19 Mar 2020 19:04:13 +0100 Subject: [PATCH 280/341] libcloud-plugin: refactored connect --- .../plugins/filed/BareosFdPluginLibcloud.py | 48 +++++++++++++------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index a9ef0df70f1..d90c4cc1f41 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -35,7 +35,6 @@ from bareos_fd_consts import bRCs, bCFs, bIOPS, bJobMessageType, bFileType from libcloud.storage.types import Provider -from libcloud.storage.providers import get_driver from sys import version_info syslog.openlog(__name__, facility=syslog.LOG_LOCAL7) @@ -83,7 +82,14 @@ def str2bool(data): raise Exception("%s: not a boolean" % (data,)) -def connect(options): +def get_driver(options): + + jobmessage( + "M_INFO", + "Try to connect to %s:%s" + % (options["host"], options["port"]), + ) + driver_opt = dict(options) # Some drivers does not support unknown options @@ -101,10 +107,23 @@ def connect(options): if opt in options: del driver_opt[opt] - provider = getattr(Provider, options["provider"]) - driver = get_driver(provider)(**driver_opt) - return driver + driver = None + + provider = getattr(libcloud.storage.types.Provider, options["provider"]) + driver = libcloud.storage.providers.get_driver(provider)(**driver_opt) + + try: + driver.get_container("probe123XXXbareosXXX123probe") + + #success + except libcloud.storage.types.ContainerDoesNotExistError: + return driver + + #error + except: + pass + return None def get_object(driver, bucket, key): try: @@ -125,7 +144,11 @@ def __init__(self, plugin_todo_queue, last_run, opts): self.last_run = last_run self.options = opts - self.driver = connect(self.options) + self.driver = get_driver(self.options) + if self.driver == None: + jobmessage("M_FATAL", "Could not connect to libcloud driver: %s:%s" + % (driver_opt["host"], driver_opt["port"])) + self.delta = datetime.timedelta(seconds=time.timezone) def __call__(self): @@ -349,15 +372,10 @@ def __check_config(self, context, config_filename): return True def start_backup_job(self, context): - try: - jobmessage( - "M_INFO", - "Try to connect to %s:%s" - % (self.options["host"], self.options["port"]), - ) - self.driver = connect(self.options) - except: - jobmessage("M_FATAL", "Could not connect to libcloud driver") + self.driver = get_driver(self.options) + if self.driver == None: + jobmessage("M_FATAL", "Could not connect to libcloud driver: %s:%s" + % (self.options["host"], self.options["port"])) return bRCs["bRC_Error"] jobmessage("M_INFO", "Last backup: %s (ts: %s)" % (self.last_run, self.since)) From 668519d5f1cfe569e2c6fe3ec3d83465a44678d3 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 19 Mar 2020 20:04:55 +0100 Subject: [PATCH 281/341] libcloud-plugin: cleanup --- .../plugins/filed/BareosFdPluginLibcloud.py | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index d90c4cc1f41..91c30aebbd8 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -30,15 +30,12 @@ import libcloud import multiprocessing import os -import syslog import time from bareos_fd_consts import bRCs, bCFs, bIOPS, bJobMessageType, bFileType from libcloud.storage.types import Provider from sys import version_info -syslog.openlog(__name__, facility=syslog.LOG_LOCAL7) - plugin_context = None def jobmessage(message_type, message): @@ -83,17 +80,9 @@ def str2bool(data): def get_driver(options): - - jobmessage( - "M_INFO", - "Try to connect to %s:%s" - % (options["host"], options["port"]), - ) - driver_opt = dict(options) - # Some drivers does not support unknown options - # Here, we remove those used by libcloud and let the rest pass through + # remove unknown options for opt in ( "buckets_exclude", "accurate", @@ -117,8 +106,13 @@ def get_driver(options): #success except libcloud.storage.types.ContainerDoesNotExistError: + debugmessage(100, "Wrong credentials for %s" % (driver_opt["host"])) return driver + #error + except libcloud.common.types.InvalidCredsError: + pass + #error except: pass @@ -133,22 +127,18 @@ def get_object(driver, bucket, key): # Our tokens are good, we used them before debugmessage( 100, - "BUGGY filename found, see the libcloud bug somewhere : %s/%s" + "Error triggered by tilde-ending objects: %s/%s" % (bucket, key), ) return None class JobCreator(object): - def __init__(self, plugin_todo_queue, last_run, opts): + def __init__(self, plugin_todo_queue, last_run, opts, driver): self.plugin_todo_queue = plugin_todo_queue self.last_run = last_run + self.driver = driver self.options = opts - self.driver = get_driver(self.options) - if self.driver == None: - jobmessage("M_FATAL", "Could not connect to libcloud driver: %s:%s" - % (driver_opt["host"], driver_opt["port"])) - self.delta = datetime.timedelta(seconds=time.timezone) def __call__(self): @@ -372,7 +362,14 @@ def __check_config(self, context, config_filename): return True def start_backup_job(self, context): + jobmessage( + "M_INFO", + "Try to connect to %s:%s" + % (self.options["host"], self.options["port"]), + ) + self.driver = get_driver(self.options) + if self.driver == None: jobmessage("M_FATAL", "Could not connect to libcloud driver: %s:%s" % (self.options["host"], self.options["port"])) @@ -387,6 +384,7 @@ def start_backup_job(self, context): self.plugin_todo_queue, self.last_run, self.options, + self.driver, ) self.job_generator = multiprocessing.Process(target=job_generator) self.job_generator.start() @@ -445,8 +443,7 @@ def start_backup_file(self, context, savepkt): self.current_backup_job["name"], ) ) - debugmessage(100, "backup %s" % (filename,)) - jobmessage("M_INFO", "Backing up %s" % (filename,)) + jobmessage("M_INFO", "Backup file: %s" % (filename,)) statp = bareosfd.StatPacket() statp.size = self.current_backup_job["size"] From a3ecdbdcc699031c5e207435be3a037857618824 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Sun, 22 Mar 2020 11:28:20 +0100 Subject: [PATCH 282/341] debian-build: reword the plugin paket descriptions --- debian/control.bareos-filedaemon-python-plugin | 6 +++--- docs/manuals/source/TasksAndConcepts/Plugins.rst | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/debian/control.bareos-filedaemon-python-plugin b/debian/control.bareos-filedaemon-python-plugin index f075c27a1d7..d09f5e690b8 100644 --- a/debian/control.bareos-filedaemon-python-plugin +++ b/debian/control.bareos-filedaemon-python-plugin @@ -25,7 +25,7 @@ Architecture: any Section: python Pre-Depends: debconf (>= 1.4.30) | debconf-2.0 Depends: bareos-common (= ${binary:Version}), bareos-filedaemon-python-plugin (= ${binary:Version}), ${misc:Depends} -Description: Backup Archiving Recovery Open Sourced - file daemon LDAP plugin +Description: Backup Archiving Recovery Open Sourced - file daemon Percona XtraBackup plugin Bareos is a set of programs to manage backup, recovery and verification of data across a network of computers of different kinds. . @@ -36,8 +36,8 @@ Architecture: any Section: python Pre-Depends: debconf (>= 1.4.30) | debconf-2.0 Depends: bareos-common (= ${binary:Version}), bareos-filedaemon-python-plugin (= ${binary:Version}), ${misc:Depends} -Description: Backup Archiving Recovery Open Sourced - file daemon LDAP plugin +Description: Backup Archiving Recovery Open Sourced - file daemon Apache Libcloud plugin Bareos is a set of programs to manage backup, recovery and verification of data across a network of computers of different kinds. . - This package provides the Libcloud Python plugin for the filedaemon. + This package provides the Apache Libcloud Python plugin for the filedaemon. diff --git a/docs/manuals/source/TasksAndConcepts/Plugins.rst b/docs/manuals/source/TasksAndConcepts/Plugins.rst index 3a0beaa3a0f..699b708f21d 100644 --- a/docs/manuals/source/TasksAndConcepts/Plugins.rst +++ b/docs/manuals/source/TasksAndConcepts/Plugins.rst @@ -1199,11 +1199,7 @@ To use the Apache Libcloud backend you need to have the Libcloud module availabl Installation ^^^^^^^^^^^^ -The installation is done by installing the package **bareos-filedaemon-libcloud-python-plugin**: - -.. code-block:: shell - - yum install bareos-filedaemon-libcloud-python-plugin +The installation is done by installing the package **bareos-filedaemon-libcloud-python-plugin**. .. _LibcloudPlugin-configuration: @@ -1225,6 +1221,10 @@ Configuration } } +.. note:: + + Replace 'lib64' by 'lib' where necessary + .. note:: The Plugin options string can currently not be split over multiple lines in the configuration file. From 856ef9ec09668fb7e1db1e2b9b49c29ce20e1347 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Mon, 30 Mar 2020 14:58:47 +0200 Subject: [PATCH 283/341] libcloud-plugin: add bareos-libcloud-api --- core/src/plugins/filed/bareos-libcloud-api.py | 160 ++++++++++++++++++ .../filed/bareos_libcloud_api/__init__.py | 0 .../filed/bareos_libcloud_api/__init__.pyc | Bin 0 -> 145 bytes .../__pycache__/__init__.cpython-37.pyc | Bin 0 -> 145 bytes .../bucket_explorer.cpython-37.pyc | Bin 0 -> 2965 bytes .../__pycache__/debug.cpython-37.pyc | Bin 0 -> 303 bytes .../get_libcloud_driver.cpython-37.pyc | Bin 0 -> 1195 bytes .../__pycache__/mtime.cpython-37.pyc | Bin 0 -> 1468 bytes .../__pycache__/process_base.cpython-37.pyc | Bin 0 -> 1886 bytes .../__pycache__/queue_message.cpython-37.pyc | Bin 0 -> 2143 bytes .../__pycache__/worker.cpython-37.pyc | Bin 0 -> 2321 bytes .../bareos_libcloud_api/bucket_explorer.py | 116 +++++++++++++ .../bareos_libcloud_api/bucket_explorer.pyc | Bin 0 -> 3679 bytes .../filed/bareos_libcloud_api/debug.py | 6 + .../filed/bareos_libcloud_api/debug.pyc | Bin 0 -> 373 bytes .../get_libcloud_driver.py | 68 ++++++++ .../get_libcloud_driver.pyc | Bin 0 -> 1555 bytes .../filed/bareos_libcloud_api/mtime.py | 33 ++++ .../filed/bareos_libcloud_api/mtime.pyc | Bin 0 -> 1886 bytes .../filed/bareos_libcloud_api/process_base.py | 37 ++++ .../bareos_libcloud_api/process_base.pyc | Bin 0 -> 2404 bytes .../bareos_libcloud_api/queue_message.py | 41 +++++ .../bareos_libcloud_api/queue_message.pyc | Bin 0 -> 2878 bytes .../filed/bareos_libcloud_api/worker.py | 81 +++++++++ .../filed/bareos_libcloud_api/worker.pyc | Bin 0 -> 2822 bytes 25 files changed, 542 insertions(+) create mode 100644 core/src/plugins/filed/bareos-libcloud-api.py create mode 100644 core/src/plugins/filed/bareos_libcloud_api/__init__.py create mode 100644 core/src/plugins/filed/bareos_libcloud_api/__init__.pyc create mode 100644 core/src/plugins/filed/bareos_libcloud_api/__pycache__/__init__.cpython-37.pyc create mode 100644 core/src/plugins/filed/bareos_libcloud_api/__pycache__/bucket_explorer.cpython-37.pyc create mode 100644 core/src/plugins/filed/bareos_libcloud_api/__pycache__/debug.cpython-37.pyc create mode 100644 core/src/plugins/filed/bareos_libcloud_api/__pycache__/get_libcloud_driver.cpython-37.pyc create mode 100644 core/src/plugins/filed/bareos_libcloud_api/__pycache__/mtime.cpython-37.pyc create mode 100644 core/src/plugins/filed/bareos_libcloud_api/__pycache__/process_base.cpython-37.pyc create mode 100644 core/src/plugins/filed/bareos_libcloud_api/__pycache__/queue_message.cpython-37.pyc create mode 100644 core/src/plugins/filed/bareos_libcloud_api/__pycache__/worker.cpython-37.pyc create mode 100644 core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py create mode 100644 core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.pyc create mode 100644 core/src/plugins/filed/bareos_libcloud_api/debug.py create mode 100644 core/src/plugins/filed/bareos_libcloud_api/debug.pyc create mode 100644 core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py create mode 100644 core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.pyc create mode 100644 core/src/plugins/filed/bareos_libcloud_api/mtime.py create mode 100644 core/src/plugins/filed/bareos_libcloud_api/mtime.pyc create mode 100644 core/src/plugins/filed/bareos_libcloud_api/process_base.py create mode 100644 core/src/plugins/filed/bareos_libcloud_api/process_base.pyc create mode 100644 core/src/plugins/filed/bareos_libcloud_api/queue_message.py create mode 100644 core/src/plugins/filed/bareos_libcloud_api/queue_message.pyc create mode 100644 core/src/plugins/filed/bareos_libcloud_api/worker.py create mode 100644 core/src/plugins/filed/bareos_libcloud_api/worker.pyc diff --git a/core/src/plugins/filed/bareos-libcloud-api.py b/core/src/plugins/filed/bareos-libcloud-api.py new file mode 100644 index 00000000000..8c004bebc1b --- /dev/null +++ b/core/src/plugins/filed/bareos-libcloud-api.py @@ -0,0 +1,160 @@ +from bareos_libcloud_api.bucket_explorer import BucketExplorer +from bareos_libcloud_api.debug import debugmessage +from bareos_libcloud_api.get_libcloud_driver import get_driver +from bareos_libcloud_api.get_libcloud_driver import options +from bareos_libcloud_api.mtime import ModificationTime +from bareos_libcloud_api.queue_message import MESSAGE_TYPE +from bareos_libcloud_api.worker import Worker +from libcloud.common.types import LibcloudError +from multiprocessing import Queue, Event + +import glob +import io +import libcloud +import os +import sys +import uuid + +NUMBER_OF_WORKERS = 20 + +SUCCESS = 0 +ERROR = 1 + +MESSAGE_TYPE = MESSAGE_TYPE() + + +class Api(object): + @staticmethod + def probe_driver(options): + driver = get_driver(options) + if driver != None: + return "success" + return "failed" + + def __init__(self, options, last_run, tmp_dir_path): + self.tmp_dir_path = tmp_dir_path + self.count_worker_ready = 0 + self.objects_count = 0 + + self.message_queue = Queue() + self.discovered_objects_queue = Queue() + self.downloaded_objects_queue = Queue() + + self.__create_tmp_dir() + + self.bucket_explorer = BucketExplorer( + options, + last_run, + self.message_queue, + self.discovered_objects_queue, + NUMBER_OF_WORKERS, + ) + + self.worker = [ + Worker( + options, + i + 1, + self.tmp_dir_path, + self.message_queue, + self.discovered_objects_queue, + self.downloaded_objects_queue, + ) + for i in range(NUMBER_OF_WORKERS) + ] + + self.bucket_explorer.start() + + for w in self.worker: + w.start() + + def run(self): + while not self.__worker_ready(): + if self.check_worker_messages() != SUCCESS: + break + job = self.get_next_job() + if job != None: + self.run_job(job) + + debugmessage(10, "*** Ready %d ***" % self.objects_count) + + def __worker_ready(self): + return self.count_worker_ready == NUMBER_OF_WORKERS + + def run_job(self, job): + debugmessage(10, "Running: %s" % job["name"]) + self.objects_count += 1 + + def check_worker_messages(self): + while not self.message_queue.empty(): + message = self.message_queue.get_nowait() + if message.type == MESSAGE_TYPE.InfoMessage: + debugmessage(message.level, message.message_string) + elif message.type == MESSAGE_TYPE.ReadyMessage: + if message.worker_id > 0: + self.count_worker_ready += 1 + elif message.type == MESSAGE_TYPE.ErrorMessage: + debugmessage(10, message.message_string) + return ERROR + elif message.type == MESSAGE_TYPE.WorkerException: + debugmessage(10, message.message_string) + debugmessage(10, message.exception) + return ERROR + else: + debugmessage(10, message) + return ERROR + return SUCCESS + + def get_next_job(self): + if not self.downloaded_objects_queue.empty(): + return self.downloaded_objects_queue.get_nowait() + return None + + def shutdown(self): + while not self.discovered_objects_queue.empty(): + self.discovered_objects_queue.get() + + while not self.downloaded_objects_queue.empty(): + self.downloaded_objects_queue.get() + + while not self.message_queue.empty(): + self.message_queue.get() + + self.bucket_explorer.shutdown() + + for w in self.worker: + w.shutdown() + + for w in self.worker: + w.join(timeout=0.3) + + self.bucket_explorer.join(timeout=0.3) + + for w in self.worker: + if w.is_alive(): + w.terminate() + + if self.bucket_explorer.is_alive(): + self.bucket_explorer.terminate() + + def __create_tmp_dir(self): + os.mkdir(self.tmp_dir_path) + + def __remove_tmp_dir(self): + files = glob.glob(self.tmp_dir_path + "/*") + for f in files: + os.remove(f) + os.rmdir(self.tmp_dir_path) + + def __del__(self): + self.__remove_tmp_dir() + + +if __name__ == "__main__": + if Api.probe_driver(options) == "success": + modification_time = ModificationTime() + + api = Api(options, modification_time.get_last_run(), "/dev/shm/bareos_libcloud") + api.run() + api.shutdown() + + debugmessage(10, "*** Exit ***") diff --git a/core/src/plugins/filed/bareos_libcloud_api/__init__.py b/core/src/plugins/filed/bareos_libcloud_api/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/core/src/plugins/filed/bareos_libcloud_api/__init__.pyc b/core/src/plugins/filed/bareos_libcloud_api/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9cbce18314b5350bacaa27e83d2c893261412733 GIT binary patch literal 145 zcmZSn%*%CqO=Da#0~9ag`kg4=5v<3RLd5CH>>K!yVl7qb9~6oz01O-8?!3`HPe1o6vCKO;XkRX?pL zF)zDR-@s6}peRefpt2+*KTkg?u_!gaI6fycDLE&TZlX-=vg$jr|`%m4r%V|$iK?EllaPI4tSR?YcUMR&La}KpA+E< z?-3E6q^DNs3I8tXw;qEP(x=th9hJvY>%B-z_-r4@f(w;=Efsuq|DB6un8Z<$1*Mp)0p; z{6tg$9{lm??qNQWyF(Ra<2nY9wD-h~ao4NEN?NHT$?--TK$7&k-187JRQb9uY9T~#* z1$*R&mav2k34yc-7ycaqslWt%2ayatOiI<+Gh4gexD>mMP5j4j;~M&3APQ1Ia8Dte zfcs}Guxf)BQtDv61<9wDCeYdi;OowIxbrGkmPXMjafou%Eh_<#s z09;#~$KZnohcI1g9mNYE&|8hG5^IyX<`>Wa{^u_}8}Oawj$#Z5J_z^~&#qi4y1{w!q`^UbXJ5Hjv~nO5SCe5?=y7?yJ-{a zRlq9?5bz3g=}i!X2CPlnK$|x8S(kR%eDhg9c3}7_+PFK!(k*!P&mbPoj|+$u93p1~ zA~!UVV+-qys4I6&oFV=#b)%#sK=sImBk0D14zygO-*5Ep*j4+eUwFty)DGzuF}xuQ z->lFoA%7+xo%`fI$#!f~w8w4rBZb3^l6e<%1T11W>po;kfc_iyAM#(4foz!cSb*2_ zt-UB7C)q)7Htp4<>RsK|SLeOkn5*8=VUo&T9e*4Z=UEXY8Nk0ED2!dWxlGQJF7+yO zs4FN8fm+xyEDDlrn6ChE{kcRRNHC3=9_0gVvRM1Hk zf!S#Kmcf8p15c{fN?nt01&DC#e5kzxvovmpP)56e5e66uR`MdV=@uYnzWo=xoNsMa znS3y~f=~x&{P2Irzm*ig^Xmx`)<8*Jxf}Nzzpo|S^?dnn{@Eun$W^+Mm0P z?M&-?C?CK@RAJSv-a2m>=6ZFDt1Fg`kg3u+kap^$%F^B^LOhASM5Elyoi4=w?h7`sWrWS@M#uVmY22GZiAf3q| zMIZp8LD(6Hi$#D$4MPb-He-=M31baoGb1C=0H7vDKTW1vTq&tZrRh1TWvMy0SPP0W z^Gbk%tPnnXZfbFHVtVRIh9WkgA-~M^GxBp&_0x(H^Ri3z4GeV)in8lIYq;sLXurm=t=1tJ(2IT(vLfHcq@MIh&bIbf@h a2zH>vEe@O9{FKt1R69l>uNb73g&6?$Mncs9 literal 0 HcmV?d00001 diff --git a/core/src/plugins/filed/bareos_libcloud_api/__pycache__/get_libcloud_driver.cpython-37.pyc b/core/src/plugins/filed/bareos_libcloud_api/__pycache__/get_libcloud_driver.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..275cfc0ad14a35c86c38aa0ee1917728f3e3b781 GIT binary patch literal 1195 zcmYjQPj4JG6t_M9ywmK`w4qh29#%q?SV6N*dqAq7YDt5Hgd#)`p_b@qcI;%Gof%JU zPnuoL9;$HW#F0aL8qz&r*jq;vXm<2Ff4j|4?f$y z4}DL5{1HN5wSK0w7=as6V@cM%<`Ix47-z{ z0cAu%_Cd@a02Vdq5-;(^ZH}LzpRO%QLmD&-^`OBG`2xKh9773~p2e1&d1wAvz{w?9 z`kfZOi5mYcK0yus1uwn%pz+>N?!5(q$Ef_qN9#SkS*$Hat~cHh>g+MZx&roJS9ZI_ zplTKHcgCN2o}GrMJ>8{ODnC;B^O$|htLLGOzKlcjvlh@y$26vd7kEy zmuVqDTWlX|Rh|yv8n`H}Omnlid7!n@!%UT>$gBh}*YaHG#V7l!&iSxZcH+Ss~!#Snn!oJb~mI$fKk8oxy)=EoeG;;t6RF+!XjgpPESP}*m)%kqu;JmXT1#x z)5fqbS*5`GZVs8*RF+VM+xwg8GbPNSvIiH^*e?Gz%v4dRl5KyzV!RI&&B_&2T9$Sc zw2`W;RHb3@Dt-cb>p2Kl2JL>???~T(;h%%?R25=;qSJC#kMHl@tMu8pn%k)=$CFeG zWs(iEB(3Dw<@(;Rinm+M^;L*905P8eAWS`iX^-NV_~a_yAp{S+9qfZpzz{G58^JqX zx3i^5QULoTdFMU@i;n6n6UK~UVBA$vyWs3jQRh}d6`d0CMZR7_V2Qr&z-8lN xx(AUY`a`Gs;zC+|&AA=%|G~{}_2-4+buJ#e1k4=(3R!Lek4>i@9fOTH`4`a4M5X`$ literal 0 HcmV?d00001 diff --git a/core/src/plugins/filed/bareos_libcloud_api/__pycache__/mtime.cpython-37.pyc b/core/src/plugins/filed/bareos_libcloud_api/__pycache__/mtime.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1a20c93c9ecc0e7b7ac631915c23c15848a450dd GIT binary patch literal 1468 zcmaJ>OK%e~5cXqt+O$Q0R85(fx$5*)YFK}YUA*Ct>uRI=)XFW6D%=qcjQiH(w^5gTHSDcXVxLJ%4m?to+ zArM6r%}6|7X-xf|{a$&@pA*FtKOu@wSscJFP$BF>9Zq>1>6(g;naOlCC9%+TRnubD z(7}|P(J7+@BmyKi&Is-leNEc+bFfOfJ*11lfO!J5x&=fNv>r1>6+0m@R~-HdT;otz z_T|w)_iT@X8V+0`I`Ryr|2HKQBEimt48ZRLhzkDY-SPU~&fd<}&hFOEUTgRM{_cbQ z-G^=|ODZe#QlkqZ-`X@P(x}}1Z${j0Gn_t zFFZEA#HM9&2vPkTcuNMqsnVHET;K%) z>9{PkTV8O|pSP*Odc7Ji0;zqMZav<=Mj!SzW7G&hj=9=MBK z3kmk6rKp6+^%FgS65)0 z+6Dmx`JBgTR8^e+MgF}vJuEUgovSE+)l7f5`+cd7rsYX}Sme`#NXeq&X>t&!MI(4r zCeyMFAU}Y6?v^JifNvti$^${z7WL?Wp6>M6*zK^#6kXs!ZNc~%MzsZEL5|2fij;KM zw-mnDtdfu&>MGdki?!InC9mTE-&goKvT<(b@ITJAkE7(WgRkNmpBIXE2Yk6kV4Z%` zzxhX=7cyf2+YAL?fzeV>Lna(C$OLQ2-qUkBY!f@p%BEJh&BSxU3^CeCAq!INu99Gr zsBr=n#aD}8uc6Y@>wTzwrwfEZCuvb$-#{to(pqD*_B5HaDAf%F=%T=^yCi&p!ou!g z-2%rhhBx}KE_lTz%HWFnQe2BZE~unFDooNAmDMH{^07%+096OkT`_hWJU$8Sg4gE- zwx!HpgKGn;5S;d9*V{I6URjm-+Tl(Q>diijn~swac9cBIB~&$DN~W Vt+t)~)RJ%yo09>$L&xVo_8%!yrSbp( literal 0 HcmV?d00001 diff --git a/core/src/plugins/filed/bareos_libcloud_api/__pycache__/queue_message.cpython-37.pyc b/core/src/plugins/filed/bareos_libcloud_api/__pycache__/queue_message.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e47d8706b6cc8c0e3b37e77ad33c43778a3de162 GIT binary patch literal 2143 zcmbVN&2AGh5VrR>ziog5EtlqiKzpDmcLb#vyM$JRcr~;BZ0~sHo3VGhTrLo3h0WoI9}Xcu5lkCkvIU|zs2#!y zr{^GooY_qZ*y1)|+h7Z@!(G6xuwdQ>>~SBkZ?FS6$Mb;m2D^X@ya>2xu*XY#Bq+CF zr?gqn+X7MdK?%~NoHQ*?n>M$a4!4^wcbXn|xpz*QKKJ4KoG$Iw_x7Ie)Y;qjuj&^R zKD%`Ucqle{16^cHi6l%C$(WB`qPv6+SF1#F?QMyqsdJ1W%nT79dD#dbtz*xMa%DEc_L&QmoB}5cn6bdSp)}6bQy&O zB#~7Vg(ydz@nf0stCP9{3onz(El8rxZJ^%KmDfncWY6tTi58|08@`c+7a-~ms1Y3z zMn)EBNE~R(q>nZNTjxKSSXi6urOr57rV`oi9%?5U^h97wq*bCP+MleL2@LscciRbL zSR%>;MW_eQaBbE}$i#SMBXA_HmSt2+s8&&7Rb-Um?G}t7sV28MDiQxLU$TN9WhruD zz)*A#Itlp-Bmq&@H=B~gI<|o(XG)W6wj4W%2{gteQk$hm-o>fQ0F3V#6#A?1ToJlN zhqtq}v=AQ{%1yM1Sq45#XwXd?j&Fge>+44@!+gs)1s!~+d{hCXeArn&ObNMDR=inO z(4=8SyOH=PB1mysJ8}&tuVV-&Cv~$#b9A_pIeZIIgsvdnTE$V~X-3y%w`H8HTVTuPUS}jAvq6%GFN5hk9GEoCg+dNcZIsW@} zahk2B$v;Gs;IH$A=H@?N4`FrYd}S}=g&4uzAE3<%BZwP;uf2HxShNyzUyo}aPo6nR f(j?ZneR%2SYp{fw7pinAR0STngJuq5(#>vL(T{AOF zVrzp`1&K=!oO`m5y;ME*52*TA%&ApRJ@>|`@9o--pjm5YX5YMd^WHaazURA*MvcJp z(_cS4Us)pLZ~T})4h+76S3QJ=6Ha3?paG>gwqk2w2X-;GV<&Jx=EUy63%r@E5>&n+ z+~wYD!aYGx?7-*t6Vk5y1J+2Jnx)4w?FyythDyL^ZBJ;%W%N?W9r$c~7j?REn(_Nm zrm~A`=8ruas2ea4B%quG)*I5JoO0{6AK2XH&T9fb6}t!S8{&|_!@Z5So65eB-O9`c z_82GHR9nz!qG?V}tcjIdxihsW$>E#Xxecw8yU@D12d&2mSfo2()K%F~Na@0I<1-c| zk!H+P(xHyhM47rC3>l9k8-{w{EJevM)9ghiGGXdzrWape$x$NiNgoYW4+~FO#AOw~ z8w0>9+!M2vmw2SQDS#z7OFIXmtJPvAJxt;>H1HQ>P>LB0pCdJ2suIXR#w2(ASqi<7=3Kgr3&=5z{4mRvj91i3SDr$pTWxi^Kh z1Dz|6$%`wyuzFINf?4Q&?2F^DcgCyt(k$k!B-Jehp;e~TgLYNo_9eDnDKrf@wN$bh zvSwNBXPN_gOuQ6{HeRHd654FCGAam43mIwwN4z+-pdm%bM++k>hant)56sT3wW&m$ zE(Kt9jngM&bOq%0!~vPL0qM-`4KlTkA;Ce%mk$q}U6O1$M7#Z(Jfh?n zuJyQyh;t{m@d}_74)Ry_Gx9x2tY;**5dCAgViR9ibLRxk?AX<{+&!Vk9$XO0y$#a0 zYiC4;9=klJtM(~W$uC7lSxeKc+xySuJk$>i>UA;|`-$%E=^JQLJC;FUjPFAMm zgszigA9g>V`-KIJ2Xu2E`lZ_hBKZ*_xzMk@rSfZtrMifvo>wuJU8FCNzp56oJO}NI zg|>W8yK$!W%@QTBJ$X-i`AluZi5#p>*772wUjWYh9FRtH=YjD$S+@_l7mOulGd@GBR%A zqSp2KWIH0)(G(AL_>OKHH%hoT8h>=UaXJ)9ON+rUm7yFJTZ}Ii?Ax0A6eWADl5ED8 z%b84}?EO_w+v^h3)VN?wkBkk>E-!*0C^)_}V5;|zx}so6(=3^ViMb@GhH&#VgfTGA zK^i5-i6fBiP30~|{q3WYA8pV#PL@SHaIw7w^=1a8sXTg8xGRzBCDb{% zeQ<%>wc=tL`ylNY8~ifWg$u@;?O*Api3TeLDy9DxSioV_1g zO*-B@CEx$^6jT?eP3RxgrW#{|lxH!H>kJA<7?(2zwad%klDq_sY0L^nSHv-6r(pr7 zt)LPzSyA|~Bq$FW@N31d7qWKMw9Y6bTf?&Ovkp{#X~7!v=~-&{hhR~FO2#fZyp2m% t=TlqVbTCMhEj=0vRh}^ZF(^DZb+{ZA#OvQKW50tnNnxfU>mr`M^&j8^bg}>d literal 0 HcmV?d00001 diff --git a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py new file mode 100644 index 00000000000..c04a8b53db5 --- /dev/null +++ b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py @@ -0,0 +1,116 @@ +from bareos_libcloud_api.process_base import ProcessBase +from bareos_libcloud_api.get_libcloud_driver import get_driver +from bareos_libcloud_api.mtime import ModificationTime + + +def parse_options_bucket(name, options): + if name not in options: + return None + else: + buckets = list() + for bucket in options[name].split(","): + buckets.append(bucket) + return buckets + + +class BucketExplorer(ProcessBase): + def __init__( + self, + options, + last_run, + message_queue, + discovered_objects_queue, + number_of_workers, + ): + super(BucketExplorer, self).__init__(0, message_queue) + self.options = options + self.last_run = last_run + self.discovered_objects_queue = discovered_objects_queue + self.buckets_include = parse_options_bucket("buckets_include", options) + self.buckets_exclude = parse_options_bucket("buckets_exclude", options) + self.number_of_workers = number_of_workers + self.object_count = 0 + + def run(self): + self.driver = get_driver(self.options) + + if self.driver == None: + self.error_message("Could not load driver") + return + + if not self.shutdown_event.is_set(): + self.__iterate_over_buckets() + + for _ in range(self.number_of_workers): + self.discovered_objects_queue.put(None) + + self.wait_for_shutdown() + + def __iterate_over_buckets(self): + try: + for bucket in self.driver.iterate_containers(): + if self.shutdown_event.is_set(): + break + + if self.buckets_include is not None: + if bucket.name not in self.buckets_include: + continue + + if self.buckets_exclude is not None: + if bucket.name in self.buckets_exclude: + continue + + self.info_message(100, 'Backing up bucket "%s"' % (bucket.name,)) + + self.__generate_jobs_for_bucket_objects( + self.driver.iterate_container_objects(bucket) + ) + except Exception as exception: + self.worker_exception("Error while iterating containers", exception) + + def __generate_jobs_for_bucket_objects(self, object_iterator): + try: + for obj in object_iterator: + if self.shutdown_event.is_set(): + break + + mtime, mtime_ts = ModificationTime().get_mtime(obj) + + job = { + "name": obj.name, + "bucket": obj.container.name, + "data": None, + "index": None, + "size": obj.size, + "mtime": mtime_ts, + } + + object_name = "%s/%s" % (obj.container.name, obj.name) + + if self.last_run > mtime: + self.info_message( + 100, + "File %s not changed, skipped (%s > %s)" + % (object_name, self.last_run, mtime), + ) + + # This object was present on our last backup + # Here, we push it directly to bareos, it will not be backed again + # but remembered as "still here" (for accurate mode) + # If accurate mode is off, we can simply skip that object + if self.options["accurate"] is True: + self.discovered_objects_queue.put(job) + self.object_count += 1 + + continue + + self.info_message( + 100, + "File %s was changed or is new, backing up (%s < %s)" + % (object_name, self.last_run, mtime), + ) + + self.discovered_objects_queue.put(job) + self.object_count += 1 + except Exception as exception: + self.worker_exception("Error while iterating objects", exception) diff --git a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.pyc b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b5739627f74d3efdb0f2e032eeca4cfaf17af56d GIT binary patch literal 3679 zcmcInOK%)S5U!rtM|NY!CJrV}04)h73vw_IDO{omoP-lt(HJFQk+jA$z4q*5W@DT+HrFZ+CTdb$8WQj}3pDZ9o3?+b0QCpAf$v zpi)j_f2Vdh)|y?8t}d3wy7$0OsKm?*}4 zY%Be(Nis0b$^zf-f`g>7pP;w8Q;f`NuZ;7-Wc9uGZ;s3U>iC)4De~2=xHN^;!)z-V z7L!!R<80N-&}M%;EJ{87A1ZMO31L_PL0w~I(3RRLcj9x`+_R%K4>sC7gc#@6X_lDo^Gq?t_$VAiC%*y@|a zS-m?k6BDtOz*q)WgO^kF&Univh77 zHa^-+t`aRWAD>sBwUK3aVE8J8TSgeEi@}_lMSwsXEUHU^Seg&X0pu=T`wN<9Khge= zVjFL7LPY)H$UG8MVZ?HU9>9)l9T*)LXi@o){TBB2L=M&uX?KBkA5z7Mbm2LlpWtlL zph4wx;e39?d5(ePLjwdN=`2bl5xlT?JZ*^*9&Xs>(WCr2)sTAzZ7P2zh1{S#b`ZW0 z`gwh>=u1HnV_`i*mn<7#ElvhmzTKIOJ3fwdt}WYZwu7nr43^H`PBt_hZ+B))irmFn z4*%{7;5bY;*6|TEjv1mWAV+KjA1Zk3h@*}V8XO+7yjM)|_&x}KL)^B(UJSW@v1J8C z{+vev$t|&%3YOEor?VW_?(Zi?vXx_>_t6Q-r6P721p>xMq9m_4p2Xlx^BC*=bT@hj zGxl}fPlakx%?Vf$lmJ<7uLKQs75#+66DyIEumE=lKJ@I4+W&~t&ArE~Z2t-shrD;p7}@7|1PI;pE+@#M5)83cOR5n*d1~Er2AZe*4I6V1ucx} zG zcQE_5B)5GT(ruPxU&Ff7UAju`T~3WB ze3pUc*c-TZm3zp&g*0_E$t@ArQj*G}>)exKf;IC+iCRH&IRiW5+!gWVqZ??XcJ^6- z6LM84cvmh;iQ%9{H!&w_kRxc6nIR~M22yNStGFzUIE|cnD!B%sTK`uR`WRgHHX3%` zS#jRWL8#j3H}P$&cDMxRZD2N3mzoP|9vP_tmzHrjuU^3#Umvk=Yt0wZ+VNiptw%*V z8Dc2KOY{b4(W~6NiRSpi(mR`STM9&my5-X}RBNU+*IHZ`i@6R+r&R6lj{W~0y@fwM z5qQY4l~3bjKurt&szzaKODsQafkz($(pR3GdH$D+3(#(RecusxV+G8^T=PMz^(VHf BF3Fezb1HeTI>6Do6z$x+*6e40)l7*GP*%95;anI8{k{}4wXq`qJs<}$-|7G_)%w)@5?AZ zS9~!1D9RHre(X`_JdR4K%}%9pqI4y8QIT>V@re&@%=+eOTSspkh_%_m=PzBibi4g! V{y(@0zj3BTrR2ozZ``Vl;1`zNPJRFY literal 0 HcmV?d00001 diff --git a/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py b/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py new file mode 100644 index 00000000000..11434ddb3ea --- /dev/null +++ b/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py @@ -0,0 +1,68 @@ +import ctypes +import libcloud +from multiprocessing.sharedctypes import RawArray + +options = { + "secret": "minioadmin", + "key": "minioadmin", + "host": "127.0.0.1", + "port": 9000, + "secure": False, + "buckets_include": "core", +} + + +def get_driver(options): + driver_opt = dict(options) + + # remove unknown options + for opt in ( + "buckets_exclude", + "accurate", + "nb_worker", + "prefetch_size", + "queue_size", + "provider", + "buckets_include", + "debug", + ): + if opt in options: + del driver_opt[opt] + + driver = None + + provider = getattr(libcloud.storage.types.Provider, "S3") + driver = libcloud.storage.providers.get_driver(provider)(**driver_opt) + + try: + driver.get_container("123invalidname123") + + # success + except libcloud.storage.types.ContainerDoesNotExistError: + return driver + + # error + except libcloud.common.types.InvalidCredsError: + print("Wrong credentials") + pass + + # error + except: + print("Error connecting driver") + pass + + print( + "Could not connect to libcloud driver: %s:%d" + % (driver_opt["host"], driver_opt["port"]) + ) + + return None + + +if __name__ == "__main__": + driver = get_driver(options) + + if driver == None: + exit(1) + + print("Success") diff --git a/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.pyc b/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6f3b7e4c268ecc0504e4396a577c3e60a480d45c GIT binary patch literal 1555 zcmb_cUvC>l5TCuXbUb0v`Z=vlplEj_-Ec4QM0dyzYO1t5};E z>zC&$9AsN=AZ$VyR{2DEm+CSvDyec#pozsf>|?n7yeE?ADkdKh(i}Hv+@vwEY}2cVt{O{Yi^i+8Xz9p!>!duO#_LNuH0dzPLI}7Whn=->eK+j<&O7K3(Cr4X%c7uf(JRD2m+mmzq&sI3 z-G2HEdDaa$`VSoHGQbg9k>z=1Gp{@YT@KTi#!i&=>(FLaohhG>Qm21Vp;a#`RjFEK z2xrz@XsK+%if3S@8dm4P1#usH?)>hf$GW`83N6cQs-QWxo>)_!_t0mlO0ToRxwl|F zwAR>OZpu>SUc*6JeW9%T5PSQkDrB!Te!1WCrdQ};UYJT=J3i?>a8Dk{ghwFZZ2Do= zxUhr=Em>pIWy0kp8%%-=&q|+dVSJ>{eGraJseB9ObLBJdZ2)W;G;BC;Y=&Kq=I1lz zg3CA8xCBg>Ai01beABwD05Pj5*k`%~=Q;Ee`d8gV9U{<4E3!$vw6a`Fu?8;5E9)u#<>6c=|o+z5v@dTi+7_~ zY{j=l1FI=wcs3!&;*B_f&q5S=AuS#s^>3u)q}2LnX`T@u+YngB)+6v-jIR0Y-nit12;CRYh*iWImj zAPM3_;Q;*&IrLBTH}xO%2ej`EWjjrdPAPFXJ6!J0y!UqEzqdAi|LeD3Gg)0Rp5Np4 zf57DU8>vL5=f07tIg3Z{`LRr6$s@^!lE?B^*5Ad4#o8tIW;niUyOPE6BjYy&!!71TH@(^$wjyP}PZ@}*F z?(g2+-MhQHzq9x4!QOWVd-uZ@;#KNHGH>!?R=8X@32O+um!VC&VGl#^s@VunQR5%L z8^37gZaiz#`gl3U!i%;XFJ6TgO+7wJTi5ucDvq+MS>{Q)D8}G8zeeW>9kDi0>sNuseEu7#ZOGe)R_#oc*6M4 zFkP`_ByS9hMb+ClEGHP_4lO*r^_{lUTord9YT}wmb}> zPxHE{XN?}SbF7x3sPyF`ZM|z%*y>tlYAJsOx^;^x&71-`0e1GYvsLHE|G_&f7nK{a zM1?W1(B`Prg;n4n6l?lVgRj#3+~IgK33dg~)*)uwY?>~$LU4b@{;E#;-{qFvUXsKQMw$qLVw z-Nty;5N;Y3zNPvt8CJPj&aii2E;3N>QbOiwqZ&N->6>9Z9IP7AJT2-Z@tmM69PB6u z%y$Pc9PD&yP%x?*dj(#g;bEl!?{(tqU`4!>D^!EtZ@I2k7)ZkWf2mF@dDu14N8HAf S+)bmu_(uPWYn$l4x6HpJ_H*i9`XW#2i{NxMG@kGs%()Eeqfcxo7TZM>@}rQUl4o) zU&J5r0WfDaP76gsf)IN*Gh=%^=gh_aw=@0f>&G_}n*V(Mf5fZ&!du9vM=??2QQ%S1 zprApCPk~P!t~DrbQqrQJ<#eCoHYFVjI!?9vu*$cmq==lI@NS@G5sqYo34+bBzqojf1y z>^y!t(l1|ck1Sp_4{vi^ng!DcYm-;`ls7{lm^o#r%rUbL!3V_iWRt;Fr@>cFwHp~uEZ9u&}!=}Vhtlvpm@a%!`rlZj1uZibO zJXLU@@W_Cd+sX}=hWlA!hSOr4zO9D$?%&Ca*)Tt}`&l~N9Tz4mbsX(Z;;ahwIFE+8 zs|CHwY~Rff6%v3|B4qN{y;ZO0O@ORkLehCQFc&jEJ)!3W0l=qF9!wd6bw#C61WS!o zSgko+$E)yW`s-*x?ZG(uZ{dP7_}9~{&~@Aw+34bKEJ_jWCoJD$VZpMMqMP|rbX=2M zkDg3|y6_OcRD|%JS5}Dyg(9^h8Ia11x!__M1@n4aZeEc4i06f#d%w#1uem{Jg7F3m zr!jI*bL%YtBC%WCl#FD7Qe9wGfh*|+>AwF^WN5JhbFM~noeeb_#D(<-G(09wqH%NL z7a(nRf2}{48BA9P2tJPiSxhyv_ztkLwCQEn z*x7twF5YmPZF7W!6T>(iCq`@A=c`&LSy;ua%J@@gRE2?}E@8Wj?FzPQydCF5q-D%p zM1?p?v})Vyb$foV#fy)v0WxMWJCiE5(R^G->7HT}DU_1?prD*=lo$oJEzXVFh;SmunAE*rMhmPwFL@t1@d27dq{{ukY>xcjV literal 0 HcmV?d00001 diff --git a/core/src/plugins/filed/bareos_libcloud_api/queue_message.py b/core/src/plugins/filed/bareos_libcloud_api/queue_message.py new file mode 100644 index 00000000000..15f31463701 --- /dev/null +++ b/core/src/plugins/filed/bareos_libcloud_api/queue_message.py @@ -0,0 +1,41 @@ +class MESSAGE_TYPE(object): + InfoMessage = 1 + ErrorMessage = 2 + WorkerException = 3 + ReadyMessage = 4 + + def __setattr__(self, *_): + raise Exception("class MESSAGE_TYPE is read only") + + +class QueueMessageBase(object): + def __init__(self, worker_id, message): + self.worker_id = worker_id + self.message_string = message + self.type = None + + +class ErrorMessage(QueueMessageBase): + def __init__(self, worker_id, message): + QueueMessageBase.__init__(self, worker_id, message) + self.type = MESSAGE_TYPE.ErrorMessage + + +class InfoMessage(QueueMessageBase): + def __init__(self, worker_id, level, message): + QueueMessageBase.__init__(self, worker_id, message) + self.type = MESSAGE_TYPE.InfoMessage + self.level = level + + +class WorkerException(QueueMessageBase): + def __init__(self, worker_id, message, exception): + QueueMessageBase.__init__(self, worker_id, message) + self.type = MESSAGE_TYPE.WorkerException + self.exception = exception + + +class ReadyMessage(QueueMessageBase): + def __init__(self, worker_id, message): + QueueMessageBase.__init__(self, worker_id, "") + self.type = MESSAGE_TYPE.ReadyMessage diff --git a/core/src/plugins/filed/bareos_libcloud_api/queue_message.pyc b/core/src/plugins/filed/bareos_libcloud_api/queue_message.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ebd14a654d04a70dcbf288f110c26511455cbdeb GIT binary patch literal 2878 zcmc&$OK;Oa5FXoU(xxr1N)?=lR0)g(q}&mYR#C;F5jaSwIbgZ*rgfUw!Mg#1a-tmg zzx)B_8z**YD?z0+B$~;3vb*#6zFDvHYrR_C{`Rp$(~rZyuUPa?Rw0oh>RJ?9^n>V> z=%CFH_RQ+!R-3{SDO=_))P4SYLTv`DhO*y+#kEx&#bU& zeC?>AiIP|r8#vRd-!+)vyR1l*e#xWyaWYW#ZW_cVqx$x5^Z6}p)q-m1Q3^#egha^2wX`Yfy@;K-5bdrbkilpY2naA4_Dy9*2 z*_wWB1C-vO4ATI10afTMW!z!W|9}sQE%a*%gHx*ssA@=J6 z$`A0g#>ShIYV->7baO#{1p-elR<)!%3oTbz!_N3A|42R4SiDM zZT|x-$QN()87z3iTnQG37eG*|T^7B?>TIXr4sqEL1s*hcB3JXWa|(eh@|=3e{uX{t zA;|}DoHa!=yQtvMNDh0dW3nS#&JP@Ea*laIR;(;oD5H5C*>XvGo?VMxSkrL H%u@Lck_9i- literal 0 HcmV?d00001 diff --git a/core/src/plugins/filed/bareos_libcloud_api/worker.py b/core/src/plugins/filed/bareos_libcloud_api/worker.py new file mode 100644 index 00000000000..2237bcb870c --- /dev/null +++ b/core/src/plugins/filed/bareos_libcloud_api/worker.py @@ -0,0 +1,81 @@ +from bareos_libcloud_api.process_base import ProcessBase +from bareos_libcloud_api.get_libcloud_driver import get_driver +import io +from libcloud.common.types import LibcloudError +import uuid + + +class Worker(ProcessBase): + def __init__( + self, + options, + worker_id, + tmp_dir_path, + message_queue, + discovered_objects_queue, + downloaded_objects_queue, + ): + super(Worker, self).__init__( + worker_id, message_queue, + ) + self.options = options + self.tmp_dir_path = tmp_dir_path + self.input_queue = discovered_objects_queue + self.output_queue = downloaded_objects_queue + + def run(self): + self.driver = get_driver(self.options) + if self.driver == None: + self.error_message("Could not load driver") + else: + while not self.shutdown_event.is_set(): + if self.__iterate_input_queue() == False: + break + # sleep(0.05) + self.ready_message() + self.wait_for_shutdown() + + def __iterate_input_queue(self): + while not self.input_queue.empty(): + job = self.input_queue.get() + if job == None: + return False + + try: + obj = self.driver.get_object(job["bucket"], job["name"]) + if obj is None: + # Object cannot be fetched, an error is already logged + continue + except Exception as exception: + self.worker_exception("Could not download file", exception) + return False + + stream = obj.as_stream() + content = b"".join(list(stream)) + + size_of_fetched_object = len(content) + if size_of_fetched_object != job["size"]: + self.error_message( + "prefetched file %s: got %s bytes, not the real size (%s bytes)" + % (job["name"], size_of_fetched_object, job["size"]), + ) + return False + + buf = io.BytesIO(content) + if size_of_fetched_object < 1024 * 10: + job["data"] = buf + else: + try: + tmpfilename = self.tmp_dir_path + "/" + str(uuid.uuid4()) + obj.download(tmpfilename) + job["data"] = None + job["index"] = tmpfilename + except OSError as e: + self.worker_exception("Could not open temporary file", e) + except LibcloudError as e: + self.worker_exception("Error downloading object", e) + except Exception as e: + self.worker_exception("Error using temporary file", e) + + self.output_queue.put(job) + return True diff --git a/core/src/plugins/filed/bareos_libcloud_api/worker.pyc b/core/src/plugins/filed/bareos_libcloud_api/worker.pyc new file mode 100644 index 0000000000000000000000000000000000000000..05c876989ab290702179d5c86092a0d07242a7d7 GIT binary patch literal 2822 zcmb_e-HzKt6h31o*-e`LX}jI+A}U!b6{%Eqsi+V_RRvqM5)#^0UZgD%!gAutt`o<0 zJ>%{MB^Rh%@d(`T0=xvzfVkm~7vP2mfbSe9S&GUPO+4fIIdkTm@BG>QbFKBm@85pi zr}@vt`x7+NLl@yuln{*-brmU|JCryycB$)DbC;4Db!$Rfqohvb26Y?Dy%p-NP*f+a zXrL%+(04>HiN5TvQsmN6X9d^9f8p0r7}-nco)%eO8*>mET`jh-c%p3(74ZvQ99D~K zSo}Qh^^>fO9u-Aa*alXPvtp!+r8dm-0L|P)r-_w-4iKU1ux31PStTCS$Uo|^`hAv( z8&4jhnNQJKJc_1}-l3sGQ#>^utEsF8E=}F^zY3M4w7`{ zBaHS>v$5VE6k$3l_us$!US16M^NBsp(*0go=*$Gk+-O0V$NQCBd-=p?NEiphI#Y8) zwVbBnf1i!W%|R1$lo-Gq0DGwDWd%RXfhnv?G;*l8D^qx-5UBJ+I=?MTbs9F<0nJx3 zUEwkC=QH={>GOMp=a^YFc}MZ6B_lB*i*RVJu^?HQL|&R%k3sP&*X*$S`YdaOJi}k@ zST@OFmTG}sv%dy&1K4$JnbXonKseAZbZW(wV-px{?c3N5Dz}DHHUgx3VJEeqBr*27Cs)O0-ty1b|1A4=zl|dy01X<n{$Zrf^#DHt~Ce)wGnf^W3FlyNguEPH-q*+$;Md zcrm+w8p7ju*aMca!!9rJGl&z7kVY&rrHQ}M<^cwIp$FRbPj%!mg?Gz*?42OyZW*sP zvD(~`2(+i#gWo3}pYuA4&D$}7S2q@f^9y;hT&JGZ<2)a=w-bpNlr*1#@;RUQ8%(gM zbQO2W+>g%tTB?C%+Ib$=%SBG^Au@#p0Ao>en8m3KlGs?eDAB3UnZR=TiZiJ&2Mph5 zPpWdj@e2-esx0G31m(d!DNPH#<=~Se0mElrKHn}^ARWo+FN#ukSPRK7vNga@`%dljS4T8D#=k-YV^vZ#hLDWU|3HBQZ-RNZN-YiOIQpG3->+bO Qz!|_W(3`LnTdVE-4YF5xEdT%j literal 0 HcmV?d00001 From 89a11a2928415a2ba27e328134be722252b81d7b Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Mon, 30 Mar 2020 18:59:50 +0200 Subject: [PATCH 284/341] libcloud-plugin: use bareos libcloud api instead of old code --- .../plugins/filed/BareosFdPluginLibcloud.py | 206 ++---------------- ...s-libcloud-api.py => BareosLibcloudApi.py} | 38 +++- .../filed/bareos_libcloud_api/debug.py | 25 ++- systemtests/CMakeLists.txt | 3 + 4 files changed, 70 insertions(+), 202 deletions(-) rename core/src/plugins/filed/{bareos-libcloud-api.py => BareosLibcloudApi.py} (82%) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 91c30aebbd8..953a6e50f27 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -25,6 +25,9 @@ import ConfigParser as configparser import datetime import dateutil.parser +from bareos_libcloud_api.debug import debugmessage +from bareos_libcloud_api.debug import jobmessage +from bareos_libcloud_api.debug import set_plugin_context import io import itertools import libcloud @@ -32,32 +35,11 @@ import os import time +from BareosLibcloudApi import BareosLibcloudApi from bareos_fd_consts import bRCs, bCFs, bIOPS, bJobMessageType, bFileType from libcloud.storage.types import Provider from sys import version_info -plugin_context = None - -def jobmessage(message_type, message): - global plugin_context - if plugin_context != None: - message = "BareosFdPluginLibcloud [%s]: %s\n" % (os.getpid(), message) - bareosfd.JobMessage(plugin_context, bJobMessageType[message_type], message) - - -def debugmessage(level, message): - global plugin_context - if plugin_context != None: - message = "BareosFdPluginLibcloud [%s]: %s\n" % (os.getpid(), message) - bareosfd.DebugMessage(plugin_context, level, message) - - -class IterStringIO(io.BufferedIOBase): - def __init__(self, iterable): - self.iter = itertools.chain.from_iterable(iterable) - - def read(self, n=None): - return bytearray(itertools.islice(self.iter, None, n)) class FilenameConverter: __pathprefix = 'PYLIBCLOUD:/' @@ -79,142 +61,9 @@ def str2bool(data): raise Exception("%s: not a boolean" % (data,)) -def get_driver(options): - driver_opt = dict(options) - - # remove unknown options - for opt in ( - "buckets_exclude", - "accurate", - "nb_worker", - "prefetch_size", - "queue_size", - "provider", - "buckets_include", - "debug", - ): - if opt in options: - del driver_opt[opt] - - driver = None - - provider = getattr(libcloud.storage.types.Provider, options["provider"]) - driver = libcloud.storage.providers.get_driver(provider)(**driver_opt) - - try: - driver.get_container("probe123XXXbareosXXX123probe") - - #success - except libcloud.storage.types.ContainerDoesNotExistError: - debugmessage(100, "Wrong credentials for %s" % (driver_opt["host"])) - return driver - - #error - except libcloud.common.types.InvalidCredsError: - pass - - #error - except: - pass - - return None - -def get_object(driver, bucket, key): - try: - return driver.get_object(bucket, key) - except libcloud.common.types.InvalidCredsError: - # Something is buggy here, this bug is triggered by tilde-ending objects - # Our tokens are good, we used them before - debugmessage( - 100, - "Error triggered by tilde-ending objects: %s/%s" - % (bucket, key), - ) - return None - -class JobCreator(object): - def __init__(self, plugin_todo_queue, last_run, opts, driver): - self.plugin_todo_queue = plugin_todo_queue - self.last_run = last_run - self.driver = driver - self.options = opts - - self.delta = datetime.timedelta(seconds=time.timezone) - - def __call__(self): - try: - self.__iterate_over_buckets() - except: - debugmessage(100, "Error while iterating over buckets") - - self.plugin_todo_queue.put(None) #end - - def __iterate_over_buckets(self): - for bucket in self.driver.iterate_containers(): - if self.options["buckets_include"] is not None: - if bucket.name not in self.options["buckets_include"]: - continue - - if self.options["buckets_exclude"] is not None: - if bucket.name in self.options["buckets_exclude"]: - continue - - debugmessage(100, 'Backing up bucket "%s"' % (bucket.name,)) - - self.__generate_jobs_for_bucket_objects( - self.driver.iterate_container_objects(bucket) - ) - - def __get_mtime(self, obj): - mtime = dateutil.parser.parse(obj.extra["last_modified"]) - mtime = mtime - self.delta - mtime = mtime.replace(tzinfo=None) - - ts = time.mktime(mtime.timetuple()) - return mtime, ts - - def __generate_jobs_for_bucket_objects(self, bucket_iterator): - for obj in bucket_iterator: - mtime, mtime_ts = self.__get_mtime(obj) - - job = { - "name": obj.name, - "bucket": obj.container.name, - "data": None, - "size": obj.size, - "mtime": mtime_ts, - } - - object_name = "%s/%s" % (obj.container.name, obj.name) - - if self.last_run > mtime: - debugmessage( - 100, - "File %s not changed, skipped (%s > %s)" - % (object_name, self.last_run, mtime), - ) - - # This object was present on our last backup - # Here, we push it directly to bareos, it will not be backed again - # but remembered as "still here" (for accurate mode) - # If accurate mode is off, we can simply skip that object - if self.options["accurate"] is True: - self.plugin_todo_queue.put(job) - - continue - - debugmessage( - 100, - "File %s was changed or is new, backing up (%s < %s)" - % (object_name, self.last_run, mtime), - ) - - self.plugin_todo_queue.put(job) - class BareosFdPluginLibcloud(BareosFdPluginBaseclass.BareosFdPluginBaseclass): def __init__(self, context, plugindef): - global plugin_context - plugin_context = context + set_plugin_context(context) debugmessage( 100, "BareosFdPluginLibcloud called with plugindef: %s" % (plugindef,) ) @@ -231,7 +80,6 @@ def __init__(self, context, plugindef): # Restore's path will not touch this self.current_backup_job = {} self.number_of_objects_to_backup = 0 - self.driver = None def __parse_options_bucket(self, name): if name not in self.options: @@ -242,25 +90,7 @@ def __parse_options_bucket(self, name): buckets.append(bucket) self.options[name] = buckets - def __parse_opt_int(self, name): - if name not in self.options: - return - - value = self.options[name] - self.options[name] = int(value) - def __parse_options(self, context): - self.__parse_options_bucket("buckets_include") - self.__parse_options_bucket("buckets_exclude") - - if "debug" in self.options: - old = self.options["debug"] - self.options["debug"] = str2bool(old) - - if self.options["debug"] is True: - global debug - debug = True - accurate = bareos_fd_consts.bVariable["bVarAccurate"] accurate = bareosfd.GetValue(context, accurate) if accurate is None or accurate == 0: @@ -368,26 +198,26 @@ def start_backup_job(self, context): % (self.options["host"], self.options["port"]), ) - self.driver = get_driver(self.options) - - if self.driver == None: + if BareosLibcloudApi.probe_driver(self.options) == "failed": jobmessage("M_FATAL", "Could not connect to libcloud driver: %s:%s" % (self.options["host"], self.options["port"])) return bRCs["bRC_Error"] jobmessage("M_INFO", "Last backup: %s (ts: %s)" % (self.last_run, self.since)) - self.manager = multiprocessing.Manager() - self.plugin_todo_queue = self.manager.Queue(maxsize=self.options["queue_size"]) + self.api = None + try: + self.api = BareosLibcloudApi(self.options, self.last_run, "/dev/shm/bareos_libcloud") + jobmessage("M_INFO", "*** Start Api ***") + self.api.run() + except Exception as e: + jobmessage("M_INFO", "Something went wrong: %s" % e) - job_generator = JobCreator( - self.plugin_todo_queue, - self.last_run, - self.options, - self.driver, - ) - self.job_generator = multiprocessing.Process(target=job_generator) - self.job_generator.start() + if self.api != None: + self.api.shutdown() + + jobmessage("M_FATAL", "Job Finished") + return bRCs["bRC_Cancel"] return bRCs["bRC_OK"] diff --git a/core/src/plugins/filed/bareos-libcloud-api.py b/core/src/plugins/filed/BareosLibcloudApi.py similarity index 82% rename from core/src/plugins/filed/bareos-libcloud-api.py rename to core/src/plugins/filed/BareosLibcloudApi.py index 8c004bebc1b..bfb3db2faae 100644 --- a/core/src/plugins/filed/bareos-libcloud-api.py +++ b/core/src/plugins/filed/BareosLibcloudApi.py @@ -1,5 +1,5 @@ from bareos_libcloud_api.bucket_explorer import BucketExplorer -from bareos_libcloud_api.debug import debugmessage +from bareos_libcloud_api.debug import debugmessage, jobmessage from bareos_libcloud_api.get_libcloud_driver import get_driver from bareos_libcloud_api.get_libcloud_driver import options from bareos_libcloud_api.mtime import ModificationTime @@ -7,6 +7,7 @@ from bareos_libcloud_api.worker import Worker from libcloud.common.types import LibcloudError from multiprocessing import Queue, Event +from time import sleep import glob import io @@ -15,7 +16,7 @@ import sys import uuid -NUMBER_OF_WORKERS = 20 +NUMBER_OF_WORKERS = 5 SUCCESS = 0 ERROR = 1 @@ -23,7 +24,7 @@ MESSAGE_TYPE = MESSAGE_TYPE() -class Api(object): +class BareosLibcloudApi(object): @staticmethod def probe_driver(options): driver = get_driver(options) @@ -75,7 +76,7 @@ def run(self): if job != None: self.run_job(job) - debugmessage(10, "*** Ready %d ***" % self.objects_count) + jobmessage("M_INFO", "*** Ready %d ***" % self.objects_count) def __worker_ready(self): return self.count_worker_ready == NUMBER_OF_WORKERS @@ -110,6 +111,7 @@ def get_next_job(self): return None def shutdown(self): + jobmessage("M_INFO", "Shutdown") while not self.discovered_objects_queue.empty(): self.discovered_objects_queue.get() @@ -120,6 +122,7 @@ def shutdown(self): self.message_queue.get() self.bucket_explorer.shutdown() + jobmessage("M_INFO", "Shutdown Worker") for w in self.worker: w.shutdown() @@ -135,25 +138,38 @@ def shutdown(self): if self.bucket_explorer.is_alive(): self.bucket_explorer.terminate() + jobmessage("M_INFO", "Shutdown Ready") def __create_tmp_dir(self): + try: + self.__remove_tmp_dir() + except: + pass os.mkdir(self.tmp_dir_path) def __remove_tmp_dir(self): - files = glob.glob(self.tmp_dir_path + "/*") - for f in files: - os.remove(f) - os.rmdir(self.tmp_dir_path) + try: + files = glob.glob(self.tmp_dir_path + "/*") + for f in files: + os.remove(f) + os.rmdir(self.tmp_dir_path) + except: + pass def __del__(self): - self.__remove_tmp_dir() + try: + self.__remove_tmp_dir() + except: + pass if __name__ == "__main__": - if Api.probe_driver(options) == "success": + if BareosLibcloudApi.probe_driver(options) == "success": modification_time = ModificationTime() - api = Api(options, modification_time.get_last_run(), "/dev/shm/bareos_libcloud") + api = BareosLibcloudApi( + options, modification_time.get_last_run(), "/dev/shm/bareos_libcloud" + ) api.run() api.shutdown() diff --git a/core/src/plugins/filed/bareos_libcloud_api/debug.py b/core/src/plugins/filed/bareos_libcloud_api/debug.py index e92c3ad42b9..a6237d5ee4d 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/debug.py +++ b/core/src/plugins/filed/bareos_libcloud_api/debug.py @@ -1,6 +1,25 @@ -debuglevel = 10 +import os +import bareosfd +from bareos_fd_consts import bJobMessageType + +debuglevel = 100 +plugin_context = None + + +def jobmessage(message_type, message): + global plugin_context + if plugin_context != None: + message = "BareosFdPluginLibcloud [%s]: %s\n" % (os.getpid(), message) + bareosfd.JobMessage(plugin_context, bJobMessageType[message_type], message) def debugmessage(level, message): - if level <= debuglevel: - print(message) + global plugin_context + if plugin_context != None: + message = "BareosFdPluginLibcloud [%s]: %s\n" % (os.getpid(), message) + bareosfd.DebugMessage(plugin_context, level, message) + + +def set_plugin_context(context): + global plugin_context + plugin_context = context diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 38cff029657..534701dc832 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -792,6 +792,7 @@ else() set(TEST_INFO_TEXT "running system tests on the sourcetree") endif() + foreach(TEST_NAME ${SYSTEM_TESTS}) message(STATUS "Configuring test: ${SYSTEMTEST_PREFIX}${TEST_NAME}") prepare_test() @@ -808,6 +809,7 @@ foreach(TEST_NAME ${SYSTEM_TESTS}) COMMAND ${tests_dir}/${TEST_NAME}/testrunner WORKING_DIRECTORY ${tests_dir}/${TEST_NAME} ) + set_tests_properties(${SYSTEMTEST_PREFIX}${TEST_NAME} PROPERTIES TIMEOUT 90) math(EXPR BASEPORT "${BASEPORT} + 10") @@ -882,6 +884,7 @@ foreach(TEST_NAME_DISABLED ${SYSTEM_TESTS_DISABLED}) message(STATUS "Disabled test: ${SYSTEMTEST_PREFIX}${TEST_NAME_DISABLED}") endforeach() + configure_file( "CTestCustom.cmake.in" "${CMAKE_BINARY_DIR}/CTestCustom.cmake" @ONLY ) From 0629415ce9b817f3a7be9e7aec9c138873b59a43 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 31 Mar 2020 10:51:53 +0200 Subject: [PATCH 285/341] cleanup: remove pyc files --- .../filed/bareos_libcloud_api/__init__.pyc | Bin 145 -> 0 bytes .../__pycache__/__init__.cpython-37.pyc | Bin 145 -> 0 bytes .../__pycache__/bucket_explorer.cpython-37.pyc | Bin 2965 -> 0 bytes .../__pycache__/debug.cpython-37.pyc | Bin 303 -> 0 bytes .../get_libcloud_driver.cpython-37.pyc | Bin 1195 -> 0 bytes .../__pycache__/mtime.cpython-37.pyc | Bin 1468 -> 0 bytes .../__pycache__/process_base.cpython-37.pyc | Bin 1886 -> 0 bytes .../__pycache__/queue_message.cpython-37.pyc | Bin 2143 -> 0 bytes .../__pycache__/worker.cpython-37.pyc | Bin 2321 -> 0 bytes .../bareos_libcloud_api/bucket_explorer.pyc | Bin 3679 -> 0 bytes .../plugins/filed/bareos_libcloud_api/debug.pyc | Bin 373 -> 0 bytes .../bareos_libcloud_api/get_libcloud_driver.pyc | Bin 1555 -> 0 bytes .../plugins/filed/bareos_libcloud_api/mtime.pyc | Bin 1886 -> 0 bytes .../filed/bareos_libcloud_api/process_base.pyc | Bin 2404 -> 0 bytes .../filed/bareos_libcloud_api/queue_message.pyc | Bin 2878 -> 0 bytes .../plugins/filed/bareos_libcloud_api/worker.pyc | Bin 2822 -> 0 bytes 16 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 core/src/plugins/filed/bareos_libcloud_api/__init__.pyc delete mode 100644 core/src/plugins/filed/bareos_libcloud_api/__pycache__/__init__.cpython-37.pyc delete mode 100644 core/src/plugins/filed/bareos_libcloud_api/__pycache__/bucket_explorer.cpython-37.pyc delete mode 100644 core/src/plugins/filed/bareos_libcloud_api/__pycache__/debug.cpython-37.pyc delete mode 100644 core/src/plugins/filed/bareos_libcloud_api/__pycache__/get_libcloud_driver.cpython-37.pyc delete mode 100644 core/src/plugins/filed/bareos_libcloud_api/__pycache__/mtime.cpython-37.pyc delete mode 100644 core/src/plugins/filed/bareos_libcloud_api/__pycache__/process_base.cpython-37.pyc delete mode 100644 core/src/plugins/filed/bareos_libcloud_api/__pycache__/queue_message.cpython-37.pyc delete mode 100644 core/src/plugins/filed/bareos_libcloud_api/__pycache__/worker.cpython-37.pyc delete mode 100644 core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.pyc delete mode 100644 core/src/plugins/filed/bareos_libcloud_api/debug.pyc delete mode 100644 core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.pyc delete mode 100644 core/src/plugins/filed/bareos_libcloud_api/mtime.pyc delete mode 100644 core/src/plugins/filed/bareos_libcloud_api/process_base.pyc delete mode 100644 core/src/plugins/filed/bareos_libcloud_api/queue_message.pyc delete mode 100644 core/src/plugins/filed/bareos_libcloud_api/worker.pyc diff --git a/core/src/plugins/filed/bareos_libcloud_api/__init__.pyc b/core/src/plugins/filed/bareos_libcloud_api/__init__.pyc deleted file mode 100644 index 9cbce18314b5350bacaa27e83d2c893261412733..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 145 zcmZSn%*%CqO=Da#0~9ag`kg4=5v<3RLd5CH>>K!yVl7qb9~6oz01O-8?!3`HPe1o6vCKO;XkRX?pL zF)zDR-@s6}peRefpt2+*KTkg?u_!gaI6fycDLE&TZlX-=vg$jr|`%m4r%V|$iK?EllaPI4tSR?YcUMR&La}KpA+E< z?-3E6q^DNs3I8tXw;qEP(x=th9hJvY>%B-z_-r4@f(w;=Efsuq|DB6un8Z<$1*Mp)0p; z{6tg$9{lm??qNQWyF(Ra<2nY9wD-h~ao4NEN?NHT$?--TK$7&k-187JRQb9uY9T~#* z1$*R&mav2k34yc-7ycaqslWt%2ayatOiI<+Gh4gexD>mMP5j4j;~M&3APQ1Ia8Dte zfcs}Guxf)BQtDv61<9wDCeYdi;OowIxbrGkmPXMjafou%Eh_<#s z09;#~$KZnohcI1g9mNYE&|8hG5^IyX<`>Wa{^u_}8}Oawj$#Z5J_z^~&#qi4y1{w!q`^UbXJ5Hjv~nO5SCe5?=y7?yJ-{a zRlq9?5bz3g=}i!X2CPlnK$|x8S(kR%eDhg9c3}7_+PFK!(k*!P&mbPoj|+$u93p1~ zA~!UVV+-qys4I6&oFV=#b)%#sK=sImBk0D14zygO-*5Ep*j4+eUwFty)DGzuF}xuQ z->lFoA%7+xo%`fI$#!f~w8w4rBZb3^l6e<%1T11W>po;kfc_iyAM#(4foz!cSb*2_ zt-UB7C)q)7Htp4<>RsK|SLeOkn5*8=VUo&T9e*4Z=UEXY8Nk0ED2!dWxlGQJF7+yO zs4FN8fm+xyEDDlrn6ChE{kcRRNHC3=9_0gVvRM1Hk zf!S#Kmcf8p15c{fN?nt01&DC#e5kzxvovmpP)56e5e66uR`MdV=@uYnzWo=xoNsMa znS3y~f=~x&{P2Irzm*ig^Xmx`)<8*Jxf}Nzzpo|S^?dnn{@Eun$W^+Mm0P z?M&-?C?CK@RAJSv-a2m>=6ZFDt1Fg`kg3u+kap^$%F^B^LOhASM5Elyoi4=w?h7`sWrWS@M#uVmY22GZiAf3q| zMIZp8LD(6Hi$#D$4MPb-He-=M31baoGb1C=0H7vDKTW1vTq&tZrRh1TWvMy0SPP0W z^Gbk%tPnnXZfbFHVtVRIh9WkgA-~M^GxBp&_0x(H^Ri3z4GeV)in8lIYq;sLXurm=t=1tJ(2IT(vLfHcq@MIh&bIbf@h a2zH>vEe@O9{FKt1R69l>uNb73g&6?$Mncs9 diff --git a/core/src/plugins/filed/bareos_libcloud_api/__pycache__/get_libcloud_driver.cpython-37.pyc b/core/src/plugins/filed/bareos_libcloud_api/__pycache__/get_libcloud_driver.cpython-37.pyc deleted file mode 100644 index 275cfc0ad14a35c86c38aa0ee1917728f3e3b781..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1195 zcmYjQPj4JG6t_M9ywmK`w4qh29#%q?SV6N*dqAq7YDt5Hgd#)`p_b@qcI;%Gof%JU zPnuoL9;$HW#F0aL8qz&r*jq;vXm<2Ff4j|4?f$y z4}DL5{1HN5wSK0w7=as6V@cM%<`Ix47-z{ z0cAu%_Cd@a02Vdq5-;(^ZH}LzpRO%QLmD&-^`OBG`2xKh9773~p2e1&d1wAvz{w?9 z`kfZOi5mYcK0yus1uwn%pz+>N?!5(q$Ef_qN9#SkS*$Hat~cHh>g+MZx&roJS9ZI_ zplTKHcgCN2o}GrMJ>8{ODnC;B^O$|htLLGOzKlcjvlh@y$26vd7kEy zmuVqDTWlX|Rh|yv8n`H}Omnlid7!n@!%UT>$gBh}*YaHG#V7l!&iSxZcH+Ss~!#Snn!oJb~mI$fKk8oxy)=EoeG;;t6RF+!XjgpPESP}*m)%kqu;JmXT1#x z)5fqbS*5`GZVs8*RF+VM+xwg8GbPNSvIiH^*e?Gz%v4dRl5KyzV!RI&&B_&2T9$Sc zw2`W;RHb3@Dt-cb>p2Kl2JL>???~T(;h%%?R25=;qSJC#kMHl@tMu8pn%k)=$CFeG zWs(iEB(3Dw<@(;Rinm+M^;L*905P8eAWS`iX^-NV_~a_yAp{S+9qfZpzz{G58^JqX zx3i^5QULoTdFMU@i;n6n6UK~UVBA$vyWs3jQRh}d6`d0CMZR7_V2Qr&z-8lN xx(AUY`a`Gs;zC+|&AA=%|G~{}_2-4+buJ#e1k4=(3R!Lek4>i@9fOTH`4`a4M5X`$ diff --git a/core/src/plugins/filed/bareos_libcloud_api/__pycache__/mtime.cpython-37.pyc b/core/src/plugins/filed/bareos_libcloud_api/__pycache__/mtime.cpython-37.pyc deleted file mode 100644 index 1a20c93c9ecc0e7b7ac631915c23c15848a450dd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1468 zcmaJ>OK%e~5cXqt+O$Q0R85(fx$5*)YFK}YUA*Ct>uRI=)XFW6D%=qcjQiH(w^5gTHSDcXVxLJ%4m?to+ zArM6r%}6|7X-xf|{a$&@pA*FtKOu@wSscJFP$BF>9Zq>1>6(g;naOlCC9%+TRnubD z(7}|P(J7+@BmyKi&Is-leNEc+bFfOfJ*11lfO!J5x&=fNv>r1>6+0m@R~-HdT;otz z_T|w)_iT@X8V+0`I`Ryr|2HKQBEimt48ZRLhzkDY-SPU~&fd<}&hFOEUTgRM{_cbQ z-G^=|ODZe#QlkqZ-`X@P(x}}1Z${j0Gn_t zFFZEA#HM9&2vPkTcuNMqsnVHET;K%) z>9{PkTV8O|pSP*Odc7Ji0;zqMZav<=Mj!SzW7G&hj=9=MBK z3kmk6rKp6+^%FgS65)0 z+6Dmx`JBgTR8^e+MgF}vJuEUgovSE+)l7f5`+cd7rsYX}Sme`#NXeq&X>t&!MI(4r zCeyMFAU}Y6?v^JifNvti$^${z7WL?Wp6>M6*zK^#6kXs!ZNc~%MzsZEL5|2fij;KM zw-mnDtdfu&>MGdki?!InC9mTE-&goKvT<(b@ITJAkE7(WgRkNmpBIXE2Yk6kV4Z%` zzxhX=7cyf2+YAL?fzeV>Lna(C$OLQ2-qUkBY!f@p%BEJh&BSxU3^CeCAq!INu99Gr zsBr=n#aD}8uc6Y@>wTzwrwfEZCuvb$-#{to(pqD*_B5HaDAf%F=%T=^yCi&p!ou!g z-2%rhhBx}KE_lTz%HWFnQe2BZE~unFDooNAmDMH{^07%+096OkT`_hWJU$8Sg4gE- zwx!HpgKGn;5S;d9*V{I6URjm-+Tl(Q>diijn~swac9cBIB~&$DN~W Vt+t)~)RJ%yo09>$L&xVo_8%!yrSbp( diff --git a/core/src/plugins/filed/bareos_libcloud_api/__pycache__/queue_message.cpython-37.pyc b/core/src/plugins/filed/bareos_libcloud_api/__pycache__/queue_message.cpython-37.pyc deleted file mode 100644 index e47d8706b6cc8c0e3b37e77ad33c43778a3de162..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2143 zcmbVN&2AGh5VrR>ziog5EtlqiKzpDmcLb#vyM$JRcr~;BZ0~sHo3VGhTrLo3h0WoI9}Xcu5lkCkvIU|zs2#!y zr{^GooY_qZ*y1)|+h7Z@!(G6xuwdQ>>~SBkZ?FS6$Mb;m2D^X@ya>2xu*XY#Bq+CF zr?gqn+X7MdK?%~NoHQ*?n>M$a4!4^wcbXn|xpz*QKKJ4KoG$Iw_x7Ie)Y;qjuj&^R zKD%`Ucqle{16^cHi6l%C$(WB`qPv6+SF1#F?QMyqsdJ1W%nT79dD#dbtz*xMa%DEc_L&QmoB}5cn6bdSp)}6bQy&O zB#~7Vg(ydz@nf0stCP9{3onz(El8rxZJ^%KmDfncWY6tTi58|08@`c+7a-~ms1Y3z zMn)EBNE~R(q>nZNTjxKSSXi6urOr57rV`oi9%?5U^h97wq*bCP+MleL2@LscciRbL zSR%>;MW_eQaBbE}$i#SMBXA_HmSt2+s8&&7Rb-Um?G}t7sV28MDiQxLU$TN9WhruD zz)*A#Itlp-Bmq&@H=B~gI<|o(XG)W6wj4W%2{gteQk$hm-o>fQ0F3V#6#A?1ToJlN zhqtq}v=AQ{%1yM1Sq45#XwXd?j&Fge>+44@!+gs)1s!~+d{hCXeArn&ObNMDR=inO z(4=8SyOH=PB1mysJ8}&tuVV-&Cv~$#b9A_pIeZIIgsvdnTE$V~X-3y%w`H8HTVTuPUS}jAvq6%GFN5hk9GEoCg+dNcZIsW@} zahk2B$v;Gs;IH$A=H@?N4`FrYd}S}=g&4uzAE3<%BZwP;uf2HxShNyzUyo}aPo6nR f(j?ZneR%2SYp{fw7pinAR0STngJuq5(#>vL(T{AOF zVrzp`1&K=!oO`m5y;ME*52*TA%&ApRJ@>|`@9o--pjm5YX5YMd^WHaazURA*MvcJp z(_cS4Us)pLZ~T})4h+76S3QJ=6Ha3?paG>gwqk2w2X-;GV<&Jx=EUy63%r@E5>&n+ z+~wYD!aYGx?7-*t6Vk5y1J+2Jnx)4w?FyythDyL^ZBJ;%W%N?W9r$c~7j?REn(_Nm zrm~A`=8ruas2ea4B%quG)*I5JoO0{6AK2XH&T9fb6}t!S8{&|_!@Z5So65eB-O9`c z_82GHR9nz!qG?V}tcjIdxihsW$>E#Xxecw8yU@D12d&2mSfo2()K%F~Na@0I<1-c| zk!H+P(xHyhM47rC3>l9k8-{w{EJevM)9ghiGGXdzrWape$x$NiNgoYW4+~FO#AOw~ z8w0>9+!M2vmw2SQDS#z7OFIXmtJPvAJxt;>H1HQ>P>LB0pCdJ2suIXR#w2(ASqi<7=3Kgr3&=5z{4mRvj91i3SDr$pTWxi^Kh z1Dz|6$%`wyuzFINf?4Q&?2F^DcgCyt(k$k!B-Jehp;e~TgLYNo_9eDnDKrf@wN$bh zvSwNBXPN_gOuQ6{HeRHd654FCGAam43mIwwN4z+-pdm%bM++k>hant)56sT3wW&m$ zE(Kt9jngM&bOq%0!~vPL0qM-`4KlTkA;Ce%mk$q}U6O1$M7#Z(Jfh?n zuJyQyh;t{m@d}_74)Ry_Gx9x2tY;**5dCAgViR9ibLRxk?AX<{+&!Vk9$XO0y$#a0 zYiC4;9=klJtM(~W$uC7lSxeKc+xySuJk$>i>UA;|`-$%E=^JQLJC;FUjPFAMm zgszigA9g>V`-KIJ2Xu2E`lZ_hBKZ*_xzMk@rSfZtrMifvo>wuJU8FCNzp56oJO}NI zg|>W8yK$!W%@QTBJ$X-i`AluZi5#p>*772wUjWYh9FRtH=YjD$S+@_l7mOulGd@GBR%A zqSp2KWIH0)(G(AL_>OKHH%hoT8h>=UaXJ)9ON+rUm7yFJTZ}Ii?Ax0A6eWADl5ED8 z%b84}?EO_w+v^h3)VN?wkBkk>E-!*0C^)_}V5;|zx}so6(=3^ViMb@GhH&#VgfTGA zK^i5-i6fBiP30~|{q3WYA8pV#PL@SHaIw7w^=1a8sXTg8xGRzBCDb{% zeQ<%>wc=tL`ylNY8~ifWg$u@;?O*Api3TeLDy9DxSioV_1g zO*-B@CEx$^6jT?eP3RxgrW#{|lxH!H>kJA<7?(2zwad%klDq_sY0L^nSHv-6r(pr7 zt)LPzSyA|~Bq$FW@N31d7qWKMw9Y6bTf?&Ovkp{#X~7!v=~-&{hhR~FO2#fZyp2m% t=TlqVbTCMhEj=0vRh}^ZF(^DZb+{ZA#OvQKW50tnNnxfU>mr`M^&j8^bg}>d diff --git a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.pyc b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.pyc deleted file mode 100644 index b5739627f74d3efdb0f2e032eeca4cfaf17af56d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3679 zcmcInOK%)S5U!rtM|NY!CJrV}04)h73vw_IDO{omoP-lt(HJFQk+jA$z4q*5W@DT+HrFZ+CTdb$8WQj}3pDZ9o3?+b0QCpAf$v zpi)j_f2Vdh)|y?8t}d3wy7$0OsKm?*}4 zY%Be(Nis0b$^zf-f`g>7pP;w8Q;f`NuZ;7-Wc9uGZ;s3U>iC)4De~2=xHN^;!)z-V z7L!!R<80N-&}M%;EJ{87A1ZMO31L_PL0w~I(3RRLcj9x`+_R%K4>sC7gc#@6X_lDo^Gq?t_$VAiC%*y@|a zS-m?k6BDtOz*q)WgO^kF&Univh77 zHa^-+t`aRWAD>sBwUK3aVE8J8TSgeEi@}_lMSwsXEUHU^Seg&X0pu=T`wN<9Khge= zVjFL7LPY)H$UG8MVZ?HU9>9)l9T*)LXi@o){TBB2L=M&uX?KBkA5z7Mbm2LlpWtlL zph4wx;e39?d5(ePLjwdN=`2bl5xlT?JZ*^*9&Xs>(WCr2)sTAzZ7P2zh1{S#b`ZW0 z`gwh>=u1HnV_`i*mn<7#ElvhmzTKIOJ3fwdt}WYZwu7nr43^H`PBt_hZ+B))irmFn z4*%{7;5bY;*6|TEjv1mWAV+KjA1Zk3h@*}V8XO+7yjM)|_&x}KL)^B(UJSW@v1J8C z{+vev$t|&%3YOEor?VW_?(Zi?vXx_>_t6Q-r6P721p>xMq9m_4p2Xlx^BC*=bT@hj zGxl}fPlakx%?Vf$lmJ<7uLKQs75#+66DyIEumE=lKJ@I4+W&~t&ArE~Z2t-shrD;p7}@7|1PI;pE+@#M5)83cOR5n*d1~Er2AZe*4I6V1ucx} zG zcQE_5B)5GT(ruPxU&Ff7UAju`T~3WB ze3pUc*c-TZm3zp&g*0_E$t@ArQj*G}>)exKf;IC+iCRH&IRiW5+!gWVqZ??XcJ^6- z6LM84cvmh;iQ%9{H!&w_kRxc6nIR~M22yNStGFzUIE|cnD!B%sTK`uR`WRgHHX3%` zS#jRWL8#j3H}P$&cDMxRZD2N3mzoP|9vP_tmzHrjuU^3#Umvk=Yt0wZ+VNiptw%*V z8Dc2KOY{b4(W~6NiRSpi(mR`STM9&my5-X}RBNU+*IHZ`i@6R+r&R6lj{W~0y@fwM z5qQY4l~3bjKurt&szzaKODsQafkz($(pR3GdH$D+3(#(RecusxV+G8^T=PMz^(VHf BF3Fezb1HeTI>6Do6z$x+*6e40)l7*GP*%95;anI8{k{}4wXq`qJs<}$-|7G_)%w)@5?AZ zS9~!1D9RHre(X`_JdR4K%}%9pqI4y8QIT>V@re&@%=+eOTSspkh_%_m=PzBibi4g! V{y(@0zj3BTrR2ozZ``Vl;1`zNPJRFY diff --git a/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.pyc b/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.pyc deleted file mode 100644 index 6f3b7e4c268ecc0504e4396a577c3e60a480d45c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1555 zcmb_cUvC>l5TCuXbUb0v`Z=vlplEj_-Ec4QM0dyzYO1t5};E z>zC&$9AsN=AZ$VyR{2DEm+CSvDyec#pozsf>|?n7yeE?ADkdKh(i}Hv+@vwEY}2cVt{O{Yi^i+8Xz9p!>!duO#_LNuH0dzPLI}7Whn=->eK+j<&O7K3(Cr4X%c7uf(JRD2m+mmzq&sI3 z-G2HEdDaa$`VSoHGQbg9k>z=1Gp{@YT@KTi#!i&=>(FLaohhG>Qm21Vp;a#`RjFEK z2xrz@XsK+%if3S@8dm4P1#usH?)>hf$GW`83N6cQs-QWxo>)_!_t0mlO0ToRxwl|F zwAR>OZpu>SUc*6JeW9%T5PSQkDrB!Te!1WCrdQ};UYJT=J3i?>a8Dk{ghwFZZ2Do= zxUhr=Em>pIWy0kp8%%-=&q|+dVSJ>{eGraJseB9ObLBJdZ2)W;G;BC;Y=&Kq=I1lz zg3CA8xCBg>Ai01beABwD05Pj5*k`%~=Q;Ee`d8gV9U{<4E3!$vw6a`Fu?8;5E9)u#<>6c=|o+z5v@dTi+7_~ zY{j=l1FI=wcs3!&;*B_f&q5S=AuS#s^>3u)q}2LnX`T@u+YngB)+6v-jIR0Y-nit12;CRYh*iWImj zAPM3_;Q;*&IrLBTH}xO%2ej`EWjjrdPAPFXJ6!J0y!UqEzqdAi|LeD3Gg)0Rp5Np4 zf57DU8>vL5=f07tIg3Z{`LRr6$s@^!lE?B^*5Ad4#o8tIW;niUyOPE6BjYy&!!71TH@(^$wjyP}PZ@}*F z?(g2+-MhQHzq9x4!QOWVd-uZ@;#KNHGH>!?R=8X@32O+um!VC&VGl#^s@VunQR5%L z8^37gZaiz#`gl3U!i%;XFJ6TgO+7wJTi5ucDvq+MS>{Q)D8}G8zeeW>9kDi0>sNuseEu7#ZOGe)R_#oc*6M4 zFkP`_ByS9hMb+ClEGHP_4lO*r^_{lUTord9YT}wmb}> zPxHE{XN?}SbF7x3sPyF`ZM|z%*y>tlYAJsOx^;^x&71-`0e1GYvsLHE|G_&f7nK{a zM1?W1(B`Prg;n4n6l?lVgRj#3+~IgK33dg~)*)uwY?>~$LU4b@{;E#;-{qFvUXsKQMw$qLVw z-Nty;5N;Y3zNPvt8CJPj&aii2E;3N>QbOiwqZ&N->6>9Z9IP7AJT2-Z@tmM69PB6u z%y$Pc9PD&yP%x?*dj(#g;bEl!?{(tqU`4!>D^!EtZ@I2k7)ZkWf2mF@dDu14N8HAf S+)bmu_(uPWYn$l4x6HpJ_H*i9`XW#2i{NxMG@kGs%()Eeqfcxo7TZM>@}rQUl4o) zU&J5r0WfDaP76gsf)IN*Gh=%^=gh_aw=@0f>&G_}n*V(Mf5fZ&!du9vM=??2QQ%S1 zprApCPk~P!t~DrbQqrQJ<#eCoHYFVjI!?9vu*$cmq==lI@NS@G5sqYo34+bBzqojf1y z>^y!t(l1|ck1Sp_4{vi^ng!DcYm-;`ls7{lm^o#r%rUbL!3V_iWRt;Fr@>cFwHp~uEZ9u&}!=}Vhtlvpm@a%!`rlZj1uZibO zJXLU@@W_Cd+sX}=hWlA!hSOr4zO9D$?%&Ca*)Tt}`&l~N9Tz4mbsX(Z;;ahwIFE+8 zs|CHwY~Rff6%v3|B4qN{y;ZO0O@ORkLehCQFc&jEJ)!3W0l=qF9!wd6bw#C61WS!o zSgko+$E)yW`s-*x?ZG(uZ{dP7_}9~{&~@Aw+34bKEJ_jWCoJD$VZpMMqMP|rbX=2M zkDg3|y6_OcRD|%JS5}Dyg(9^h8Ia11x!__M1@n4aZeEc4i06f#d%w#1uem{Jg7F3m zr!jI*bL%YtBC%WCl#FD7Qe9wGfh*|+>AwF^WN5JhbFM~noeeb_#D(<-G(09wqH%NL z7a(nRf2}{48BA9P2tJPiSxhyv_ztkLwCQEn z*x7twF5YmPZF7W!6T>(iCq`@A=c`&LSy;ua%J@@gRE2?}E@8Wj?FzPQydCF5q-D%p zM1?p?v})Vyb$foV#fy)v0WxMWJCiE5(R^G->7HT}DU_1?prD*=lo$oJEzXVFh;SmunAE*rMhmPwFL@t1@d27dq{{ukY>xcjV diff --git a/core/src/plugins/filed/bareos_libcloud_api/queue_message.pyc b/core/src/plugins/filed/bareos_libcloud_api/queue_message.pyc deleted file mode 100644 index ebd14a654d04a70dcbf288f110c26511455cbdeb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2878 zcmc&$OK;Oa5FXoU(xxr1N)?=lR0)g(q}&mYR#C;F5jaSwIbgZ*rgfUw!Mg#1a-tmg zzx)B_8z**YD?z0+B$~;3vb*#6zFDvHYrR_C{`Rp$(~rZyuUPa?Rw0oh>RJ?9^n>V> z=%CFH_RQ+!R-3{SDO=_))P4SYLTv`DhO*y+#kEx&#bU& zeC?>AiIP|r8#vRd-!+)vyR1l*e#xWyaWYW#ZW_cVqx$x5^Z6}p)q-m1Q3^#egha^2wX`Yfy@;K-5bdrbkilpY2naA4_Dy9*2 z*_wWB1C-vO4ATI10afTMW!z!W|9}sQE%a*%gHx*ssA@=J6 z$`A0g#>ShIYV->7baO#{1p-elR<)!%3oTbz!_N3A|42R4SiDM zZT|x-$QN()87z3iTnQG37eG*|T^7B?>TIXr4sqEL1s*hcB3JXWa|(eh@|=3e{uX{t zA;|}DoHa!=yQtvMNDh0dW3nS#&JP@Ea*laIR;(;oD5H5C*>XvGo?VMxSkrL H%u@Lck_9i- diff --git a/core/src/plugins/filed/bareos_libcloud_api/worker.pyc b/core/src/plugins/filed/bareos_libcloud_api/worker.pyc deleted file mode 100644 index 05c876989ab290702179d5c86092a0d07242a7d7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2822 zcmb_e-HzKt6h31o*-e`LX}jI+A}U!b6{%Eqsi+V_RRvqM5)#^0UZgD%!gAutt`o<0 zJ>%{MB^Rh%@d(`T0=xvzfVkm~7vP2mfbSe9S&GUPO+4fIIdkTm@BG>QbFKBm@85pi zr}@vt`x7+NLl@yuln{*-brmU|JCryycB$)DbC;4Db!$Rfqohvb26Y?Dy%p-NP*f+a zXrL%+(04>HiN5TvQsmN6X9d^9f8p0r7}-nco)%eO8*>mET`jh-c%p3(74ZvQ99D~K zSo}Qh^^>fO9u-Aa*alXPvtp!+r8dm-0L|P)r-_w-4iKU1ux31PStTCS$Uo|^`hAv( z8&4jhnNQJKJc_1}-l3sGQ#>^utEsF8E=}F^zY3M4w7`{ zBaHS>v$5VE6k$3l_us$!US16M^NBsp(*0go=*$Gk+-O0V$NQCBd-=p?NEiphI#Y8) zwVbBnf1i!W%|R1$lo-Gq0DGwDWd%RXfhnv?G;*l8D^qx-5UBJ+I=?MTbs9F<0nJx3 zUEwkC=QH={>GOMp=a^YFc}MZ6B_lB*i*RVJu^?HQL|&R%k3sP&*X*$S`YdaOJi}k@ zST@OFmTG}sv%dy&1K4$JnbXonKseAZbZW(wV-px{?c3N5Dz}DHHUgx3VJEeqBr*27Cs)O0-ty1b|1A4=zl|dy01X<n{$Zrf^#DHt~Ce)wGnf^W3FlyNguEPH-q*+$;Md zcrm+w8p7ju*aMca!!9rJGl&z7kVY&rrHQ}M<^cwIp$FRbPj%!mg?Gz*?42OyZW*sP zvD(~`2(+i#gWo3}pYuA4&D$}7S2q@f^9y;hT&JGZ<2)a=w-bpNlr*1#@;RUQ8%(gM zbQO2W+>g%tTB?C%+Ib$=%SBG^Au@#p0Ao>en8m3KlGs?eDAB3UnZR=TiZiJ&2Mph5 zPpWdj@e2-esx0G31m(d!DNPH#<=~Se0mElrKHn}^ARWo+FN#ukSPRK7vNga@`%dljS4T8D#=k-YV^vZ#hLDWU|3HBQZ-RNZN-YiOIQpG3->+bO Qz!|_W(3`LnTdVE-4YF5xEdT%j From 0f85414c67f66cc707a7fc54ca764327e99dd977 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 31 Mar 2020 12:05:18 +0200 Subject: [PATCH 286/341] libcloud-plugin: correct packaging --- core/platforms/packaging/bareos.spec | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/platforms/packaging/bareos.spec b/core/platforms/packaging/bareos.spec index ff915e81932..329e161c78b 100644 --- a/core/platforms/packaging/bareos.spec +++ b/core/platforms/packaging/bareos.spec @@ -1558,6 +1558,9 @@ mkdir -p %{?buildroot}/%{_libdir}/bareos/plugins/vmware_plugin %defattr(-, root, root) %{plugin_dir}/bareos-fd-libcloud.py* %{plugin_dir}/BareosFdPluginLibcloud.py* +%dir %{plugin_dir}/bareos_libcloud_api +%{plugin_dir}/bareos_libcloud_api/* + #attr(0640, #{director_daemon_user}, #{daemon_group}) #{_sysconfdir}/#{name}/bareos-dir.d/fileset/plugin-libcloud.conf.example #attr(0640, #{director_daemon_user}, #{daemon_group}) #{_sysconfdir}/#{name}/bareos-dir.d/job/backup-libcloud.conf.example From 42c436c5440c476bea214a4cbe0a7e8bd6ef0d26 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 31 Mar 2020 15:20:21 +0200 Subject: [PATCH 287/341] libcloud-plugin: queued backup objects running to sd --- .../plugins/filed/BareosFdPluginLibcloud.py | 58 +++++-------------- core/src/plugins/filed/BareosLibcloudApi.py | 4 +- .../filed/bareos_libcloud_api/mtime.py | 3 +- 3 files changed, 20 insertions(+), 45 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 953a6e50f27..ad64b94547d 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -35,6 +35,8 @@ import os import time +from BareosLibcloudApi import SUCCESS +from BareosLibcloudApi import ERROR from BareosLibcloudApi import BareosLibcloudApi from bareos_fd_consts import bRCs, bCFs, bIOPS, bJobMessageType, bFileType from libcloud.storage.types import Provider @@ -209,15 +211,9 @@ def start_backup_job(self, context): try: self.api = BareosLibcloudApi(self.options, self.last_run, "/dev/shm/bareos_libcloud") jobmessage("M_INFO", "*** Start Api ***") - self.api.run() except Exception as e: - jobmessage("M_INFO", "Something went wrong: %s" % e) - - if self.api != None: - self.api.shutdown() - - jobmessage("M_FATAL", "Job Finished") - return bRCs["bRC_Cancel"] + jobmessage("M_FATAL", "Something went wrong: %s" % e) + return bRCs["bRC_Cancel"] return bRCs["bRC_OK"] @@ -235,31 +231,20 @@ def __shutdown_and_join_processes(self): else: jobmessage("M_INFO", "No objects to backup") - try: - self.manager.shutdown() - except OSError: - # should not happen! - pass - debugmessage(100, "self.manager.shutdown()") - - debugmessage( - 100, "Join() for the job_generator (pid %s)" % (self.job_generator.pid,) - ) - self.job_generator.join() - debugmessage(100, "job_generator is shut down") + self.api.shutdown() + debugmessage(100, "self.api.shutdown()") def start_backup_file(self, context, savepkt): debugmessage(100, "start_backup_file() called, waiting for worker") - try: - while True: - try: - self.current_backup_job = self.plugin_todo_queue.get_nowait() - break - except: - time.sleep(0.1) - except TypeError: - debugmessage(100, "self.current_backup_job = None") - self.current_backup_job = None + while True: + if self.api.check_worker_messages() != SUCCESS: + self.current_backup_job = None + break + self.current_backup_job = self.api.get_next_job() + if self.current_backup_job != None: + break + if self.api.worker_ready(): + break if self.current_backup_job is None: debugmessage(100, "Shutdown and join processes") @@ -310,18 +295,7 @@ def plugin_io(self, context, IOP): return bRCs["bRC_OK"] # 'Backup' path - if self.current_backup_job["data"] is None: - obj = get_object( - self.driver, - self.current_backup_job["bucket"], - self.current_backup_job["name"], - ) - if obj is None: - self.FILE = None - return bRCs["bRC_Error"] - self.FILE = IterStringIO(obj.as_stream()) - else: - self.FILE = self.current_backup_job["data"] + self.FILE = self.current_backup_job["data"] elif IOP.func == bIOPS["IO_READ"]: IOP.buf = bytearray(IOP.count) diff --git a/core/src/plugins/filed/BareosLibcloudApi.py b/core/src/plugins/filed/BareosLibcloudApi.py index bfb3db2faae..8be69fc8893 100644 --- a/core/src/plugins/filed/BareosLibcloudApi.py +++ b/core/src/plugins/filed/BareosLibcloudApi.py @@ -69,7 +69,7 @@ def __init__(self, options, last_run, tmp_dir_path): w.start() def run(self): - while not self.__worker_ready(): + while not self.worker_ready(): if self.check_worker_messages() != SUCCESS: break job = self.get_next_job() @@ -78,7 +78,7 @@ def run(self): jobmessage("M_INFO", "*** Ready %d ***" % self.objects_count) - def __worker_ready(self): + def worker_ready(self): return self.count_worker_ready == NUMBER_OF_WORKERS def run_job(self, job): diff --git a/core/src/plugins/filed/bareos_libcloud_api/mtime.py b/core/src/plugins/filed/bareos_libcloud_api/mtime.py index 18f43f3adb7..63554f26cdb 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/mtime.py +++ b/core/src/plugins/filed/bareos_libcloud_api/mtime.py @@ -12,7 +12,8 @@ def __init__(self): class ModificationTime(object): def __init__(self): - self.timezone_delta = datetime.timedelta(seconds=time.timezone) + is_dst = time.daylight and time.localtime().tm_isdst + self.timezone_delta = datetime.timedelta(seconds=time.altzone if is_dst else time.timezone) def get_mtime(self, obj): mtime = dateutil.parser.parse(obj.extra["last_modified"]) From 27d9898997f8326ae90195dbe67d6a10a28752cd Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 31 Mar 2020 16:27:26 +0200 Subject: [PATCH 288/341] libcloud-plugin: test success --- .../src/plugins/filed/BareosFdPluginLibcloud.py | 17 ++++++++++++++--- core/src/plugins/filed/BareosLibcloudApi.py | 6 ++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index ad64b94547d..2c6746748fb 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -82,6 +82,7 @@ def __init__(self, context, plugindef): # Restore's path will not touch this self.current_backup_job = {} self.number_of_objects_to_backup = 0 + self.FILE = None def __parse_options_bucket(self, name): if name not in self.options: @@ -222,7 +223,7 @@ def check_file(self, context, fname): # If bareos have not seen one, it does not exists anymore return bRCs["bRC_Error"] - def __shutdown_and_join_processes(self): + def __shutdown(self): if self.number_of_objects_to_backup: jobmessage( "M_INFO", @@ -248,7 +249,7 @@ def start_backup_file(self, context, savepkt): if self.current_backup_job is None: debugmessage(100, "Shutdown and join processes") - self.__shutdown_and_join_processes() + self.__shutdown() savepkt.fname = "empty" # dummy value, savepkt is always checked return bRCs["bRC_Skip"] @@ -295,7 +296,17 @@ def plugin_io(self, context, IOP): return bRCs["bRC_OK"] # 'Backup' path - self.FILE = self.current_backup_job["data"] + if self.current_backup_job["data"] != None: + debugmessage(100, "********** Current Backup Data") + self.FILE = self.current_backup_job["data"] + else: + try: + debugmessage(100, "********** Try Open File: %s" % self.current_backup_job["index"]) + self.FILE = io.open(self.current_backup_job["index"], 'rb') + except Exception as e: + jobmessage("M_FATAL", "%s" % e) + self.__shutdown() + return bRCs["bRC_Error"] elif IOP.func == bIOPS["IO_READ"]: IOP.buf = bytearray(IOP.count) diff --git a/core/src/plugins/filed/BareosLibcloudApi.py b/core/src/plugins/filed/BareosLibcloudApi.py index 8be69fc8893..12d1945e8aa 100644 --- a/core/src/plugins/filed/BareosLibcloudApi.py +++ b/core/src/plugins/filed/BareosLibcloudApi.py @@ -138,6 +138,12 @@ def shutdown(self): if self.bucket_explorer.is_alive(): self.bucket_explorer.terminate() + + try: + self.__remove_tmp_dir() + except: + pass + jobmessage("M_INFO", "Shutdown Ready") def __create_tmp_dir(self): From bd8ad3e4e92c8afc8c058a25b1596b966ecac370 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 31 Mar 2020 16:27:36 +0200 Subject: [PATCH 289/341] docs: corrected a typo --- docs/manuals/source/TasksAndConcepts/Plugins.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/manuals/source/TasksAndConcepts/Plugins.rst b/docs/manuals/source/TasksAndConcepts/Plugins.rst index 699b708f21d..c771ab334a4 100644 --- a/docs/manuals/source/TasksAndConcepts/Plugins.rst +++ b/docs/manuals/source/TasksAndConcepts/Plugins.rst @@ -1176,7 +1176,7 @@ Apache Libcloud Plugin .. index:: pair: Plugin; libcloud -The Libcloud plugin can be used to backup objects from backends that support the Simple Storage Service (S3) protcol. The plugin code is based on the work of Alexandre Bruyelles. +The Libcloud plugin can be used to backup objects from backends that support the Simple Storage Service (S3) protocol. The plugin code is based on the work of Alexandre Bruyelles. .. _LibcloudPlugin-status: From 68af47f4aaa2b72e2fdc7c594179c12deb8bf833 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Wed, 1 Apr 2020 16:59:05 +0200 Subject: [PATCH 290/341] libcloud-plugin: implement cancel and limit queue size for discovered objects --- .../plugins/filed/BareosFdPluginLibcloud.py | 46 +++++++++---------- core/src/plugins/filed/BareosLibcloudApi.py | 30 +++++++----- .../bareos_libcloud_api/bucket_explorer.py | 7 ++- .../filed/bareos_libcloud_api/process_base.py | 13 ++++-- .../filed/bareos_libcloud_api/worker.py | 4 +- 5 files changed, 56 insertions(+), 44 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 2c6746748fb..d21cfc7e802 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -33,7 +33,7 @@ import libcloud import multiprocessing import os -import time +from time import sleep from BareosLibcloudApi import SUCCESS from BareosLibcloudApi import ERROR @@ -83,15 +83,7 @@ def __init__(self, context, plugindef): self.current_backup_job = {} self.number_of_objects_to_backup = 0 self.FILE = None - - def __parse_options_bucket(self, name): - if name not in self.options: - self.options[name] = None - else: - buckets = list() - for bucket in self.options[name].split(","): - buckets.append(bucket) - self.options[name] = buckets + self.active = True def __parse_options(self, context): accurate = bareos_fd_consts.bVariable["bVarAccurate"] @@ -218,6 +210,13 @@ def start_backup_job(self, context): return bRCs["bRC_OK"] + def end_backup_job(self, context): + debugmessage(100, "********** STOP *************") + self.active = False + self.api.shutdown() + debugmessage(100, "********** Shutdown finished *************") + return bRCs["bRC_OK"] + def check_file(self, context, fname): # All existing files/objects are passed to bareos # If bareos have not seen one, it does not exists anymore @@ -237,19 +236,22 @@ def __shutdown(self): def start_backup_file(self, context, savepkt): debugmessage(100, "start_backup_file() called, waiting for worker") - while True: + while self.active: if self.api.check_worker_messages() != SUCCESS: - self.current_backup_job = None - break - self.current_backup_job = self.api.get_next_job() - if self.current_backup_job != None: - break - if self.api.worker_ready(): - break - - if self.current_backup_job is None: + self.active = False + else: + self.current_backup_job = self.api.get_next_job() + if self.current_backup_job != None: + break + elif self.api.worker_ready(): + self.active = False + else: + sleep(0.01) + + if not self.active: debugmessage(100, "Shutdown and join processes") self.__shutdown() + debugmessage(100, "Is Shutdown") savepkt.fname = "empty" # dummy value, savepkt is always checked return bRCs["bRC_Skip"] @@ -297,14 +299,12 @@ def plugin_io(self, context, IOP): # 'Backup' path if self.current_backup_job["data"] != None: - debugmessage(100, "********** Current Backup Data") self.FILE = self.current_backup_job["data"] else: try: - debugmessage(100, "********** Try Open File: %s" % self.current_backup_job["index"]) self.FILE = io.open(self.current_backup_job["index"], 'rb') except Exception as e: - jobmessage("M_FATAL", "%s" % e) + jobmessage("M_FATAL", "Could not open temporary file." % e) self.__shutdown() return bRCs["bRC_Error"] diff --git a/core/src/plugins/filed/BareosLibcloudApi.py b/core/src/plugins/filed/BareosLibcloudApi.py index 12d1945e8aa..b331e89492d 100644 --- a/core/src/plugins/filed/BareosLibcloudApi.py +++ b/core/src/plugins/filed/BareosLibcloudApi.py @@ -16,8 +16,6 @@ import sys import uuid -NUMBER_OF_WORKERS = 5 - SUCCESS = 0 ERROR = 1 @@ -36,11 +34,14 @@ def __init__(self, options, last_run, tmp_dir_path): self.tmp_dir_path = tmp_dir_path self.count_worker_ready = 0 self.objects_count = 0 + queue_size = options["queue_size"] if options["queue_size"] > 0 else 1000 self.message_queue = Queue() - self.discovered_objects_queue = Queue() + self.discovered_objects_queue = Queue(queue_size) self.downloaded_objects_queue = Queue() + self.number_of_worker = options["nb_worker"] if options["nb_worker"] > 0 else 1 + self.__create_tmp_dir() self.bucket_explorer = BucketExplorer( @@ -48,7 +49,7 @@ def __init__(self, options, last_run, tmp_dir_path): last_run, self.message_queue, self.discovered_objects_queue, - NUMBER_OF_WORKERS, + self.number_of_worker, ) self.worker = [ @@ -60,7 +61,7 @@ def __init__(self, options, last_run, tmp_dir_path): self.discovered_objects_queue, self.downloaded_objects_queue, ) - for i in range(NUMBER_OF_WORKERS) + for i in range(self.number_of_worker) ] self.bucket_explorer.start() @@ -79,7 +80,7 @@ def run(self): jobmessage("M_INFO", "*** Ready %d ***" % self.objects_count) def worker_ready(self): - return self.count_worker_ready == NUMBER_OF_WORKERS + return self.count_worker_ready == self.number_of_worker def run_job(self, job): debugmessage(10, "Running: %s" % job["name"]) @@ -111,7 +112,16 @@ def get_next_job(self): return None def shutdown(self): - jobmessage("M_INFO", "Shutdown") + debugmessage(100, "Api Shutdown worker") + self.bucket_explorer.shutdown() + for w in self.worker: + w.shutdown() + + debugmessage(100, "Api Wait For worker") + while not self.worker_ready(): + self.check_worker_messages() + + debugmessage(100, "Api Worker Ready") while not self.discovered_objects_queue.empty(): self.discovered_objects_queue.get() @@ -121,11 +131,7 @@ def shutdown(self): while not self.message_queue.empty(): self.message_queue.get() - self.bucket_explorer.shutdown() - jobmessage("M_INFO", "Shutdown Worker") - - for w in self.worker: - w.shutdown() + debugmessage(100, "Api Join Worker") for w in self.worker: w.join(timeout=0.3) diff --git a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py index c04a8b53db5..2c928a15b55 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py +++ b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py @@ -99,8 +99,7 @@ def __generate_jobs_for_bucket_objects(self, object_iterator): # but remembered as "still here" (for accurate mode) # If accurate mode is off, we can simply skip that object if self.options["accurate"] is True: - self.discovered_objects_queue.put(job) - self.object_count += 1 + self.queue_try_put(self.discovered_objects_queue, job) continue @@ -110,7 +109,7 @@ def __generate_jobs_for_bucket_objects(self, object_iterator): % (object_name, self.last_run, mtime), ) - self.discovered_objects_queue.put(job) - self.object_count += 1 + self.queue_try_put(self.discovered_objects_queue, job) + except Exception as exception: self.worker_exception("Error while iterating objects", exception) diff --git a/core/src/plugins/filed/bareos_libcloud_api/process_base.py b/core/src/plugins/filed/bareos_libcloud_api/process_base.py index e3d9923e8b9..d5e1053ec52 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/process_base.py +++ b/core/src/plugins/filed/bareos_libcloud_api/process_base.py @@ -5,7 +5,7 @@ from bareos_libcloud_api.queue_message import ErrorMessage from bareos_libcloud_api.queue_message import WorkerException from bareos_libcloud_api.queue_message import MESSAGE_TYPE - +import Queue as Q class ProcessBase(Process): def __init__( @@ -20,9 +20,7 @@ def shutdown(self): self.shutdown_event.set() def wait_for_shutdown(self): - # print("Waiting for shutdown %d" % self.worker_id) self.shutdown_event.wait() - # print("Waiting for shutdown %d ready" % self.worker_id) def info_message(self, level, message): self.message_queue.put(InfoMessage(self.worker_id, level, message)) @@ -35,3 +33,12 @@ def error_message(self, message): def worker_exception(self, message, exception): self.message_queue.put(WorkerException(self.worker_id, message, exception)) + + def queue_try_put(self, queue, obj): + while not self.shutdown_event.is_set(): + try: + queue.put(obj, block=True, timeout=0.5) + return + except Q.Full: + self.info_message(400, "Queue %s is full" % queue) + continue diff --git a/core/src/plugins/filed/bareos_libcloud_api/worker.py b/core/src/plugins/filed/bareos_libcloud_api/worker.py index 2237bcb870c..224361973e9 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/worker.py +++ b/core/src/plugins/filed/bareos_libcloud_api/worker.py @@ -3,6 +3,7 @@ import io from libcloud.common.types import LibcloudError import uuid +from time import sleep class Worker(ProcessBase): @@ -31,12 +32,11 @@ def run(self): while not self.shutdown_event.is_set(): if self.__iterate_input_queue() == False: break - # sleep(0.05) self.ready_message() self.wait_for_shutdown() def __iterate_input_queue(self): - while not self.input_queue.empty(): + while not self.input_queue.empty() and not self.shutdown_event.is_set(): job = self.input_queue.get() if job == None: return False From d04615cd4ce2b6585ca5e6294d1f1adfeb76dbee Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Wed, 1 Apr 2020 18:24:44 +0200 Subject: [PATCH 291/341] libcloud-plugin: improve shutdown, cleanup --- .../plugins/filed/BareosFdPluginLibcloud.py | 16 +++--- core/src/plugins/filed/BareosLibcloudApi.py | 55 ++++++------------- .../bareos_libcloud_api/bucket_explorer.py | 10 ++-- .../filed/bareos_libcloud_api/process_base.py | 10 +++- .../filed/bareos_libcloud_api/worker.py | 6 +- 5 files changed, 40 insertions(+), 57 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index d21cfc7e802..ace8af09c56 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -203,18 +203,17 @@ def start_backup_job(self, context): self.api = None try: self.api = BareosLibcloudApi(self.options, self.last_run, "/dev/shm/bareos_libcloud") - jobmessage("M_INFO", "*** Start Api ***") + debugmessage(100, "BareosLibcloudApi started") except Exception as e: + debugmessage(100, "Error: %s" % e) jobmessage("M_FATAL", "Something went wrong: %s" % e) return bRCs["bRC_Cancel"] return bRCs["bRC_OK"] def end_backup_job(self, context): - debugmessage(100, "********** STOP *************") - self.active = False - self.api.shutdown() - debugmessage(100, "********** Shutdown finished *************") + if self.active: + self.__shutdown() return bRCs["bRC_OK"] def check_file(self, context, fname): @@ -223,6 +222,7 @@ def check_file(self, context, fname): return bRCs["bRC_Error"] def __shutdown(self): + self.active = False if self.number_of_objects_to_backup: jobmessage( "M_INFO", @@ -231,11 +231,11 @@ def __shutdown(self): else: jobmessage("M_INFO", "No objects to backup") + debugmessage(100, "Shut down BareosLibcloudApi") self.api.shutdown() - debugmessage(100, "self.api.shutdown()") + debugmessage(100, "BareosLibcloudApi is shut down") def start_backup_file(self, context, savepkt): - debugmessage(100, "start_backup_file() called, waiting for worker") while self.active: if self.api.check_worker_messages() != SUCCESS: self.active = False @@ -249,9 +249,7 @@ def start_backup_file(self, context, savepkt): sleep(0.01) if not self.active: - debugmessage(100, "Shutdown and join processes") self.__shutdown() - debugmessage(100, "Is Shutdown") savepkt.fname = "empty" # dummy value, savepkt is always checked return bRCs["bRC_Skip"] diff --git a/core/src/plugins/filed/BareosLibcloudApi.py b/core/src/plugins/filed/BareosLibcloudApi.py index b331e89492d..e4d7ab1db96 100644 --- a/core/src/plugins/filed/BareosLibcloudApi.py +++ b/core/src/plugins/filed/BareosLibcloudApi.py @@ -33,15 +33,15 @@ def probe_driver(options): def __init__(self, options, last_run, tmp_dir_path): self.tmp_dir_path = tmp_dir_path self.count_worker_ready = 0 - self.objects_count = 0 - queue_size = options["queue_size"] if options["queue_size"] > 0 else 1000 - - self.message_queue = Queue() - self.discovered_objects_queue = Queue(queue_size) - self.downloaded_objects_queue = Queue() + self.count_bucket_explorer_ready = 0 self.number_of_worker = options["nb_worker"] if options["nb_worker"] > 0 else 1 + queue_size = options["queue_size"] if options["queue_size"] > 0 else 1000 + self.discovered_objects_queue = Queue(queue_size) + self.downloaded_objects_queue = Queue(queue_size) + self.message_queue = Queue() + self.__create_tmp_dir() self.bucket_explorer = BucketExplorer( @@ -69,22 +69,11 @@ def __init__(self, options, last_run, tmp_dir_path): for w in self.worker: w.start() - def run(self): - while not self.worker_ready(): - if self.check_worker_messages() != SUCCESS: - break - job = self.get_next_job() - if job != None: - self.run_job(job) - - jobmessage("M_INFO", "*** Ready %d ***" % self.objects_count) - def worker_ready(self): return self.count_worker_ready == self.number_of_worker - def run_job(self, job): - debugmessage(10, "Running: %s" % job["name"]) - self.objects_count += 1 + def bucket_explorer_ready(self): + return self.count_bucket_explorer_ready == 1 def check_worker_messages(self): while not self.message_queue.empty(): @@ -92,7 +81,9 @@ def check_worker_messages(self): if message.type == MESSAGE_TYPE.InfoMessage: debugmessage(message.level, message.message_string) elif message.type == MESSAGE_TYPE.ReadyMessage: - if message.worker_id > 0: + if message.worker_id == 0: + self.count_bucket_explorer_ready += 1 + else: self.count_worker_ready += 1 elif message.type == MESSAGE_TYPE.ErrorMessage: debugmessage(10, message.message_string) @@ -112,16 +103,18 @@ def get_next_job(self): return None def shutdown(self): - debugmessage(100, "Api Shutdown worker") + debugmessage(100, "Shut down worker") self.bucket_explorer.shutdown() for w in self.worker: w.shutdown() - debugmessage(100, "Api Wait For worker") + debugmessage(100, "Wait for worker") + while not self.bucket_explorer_ready(): + self.check_worker_messages() while not self.worker_ready(): self.check_worker_messages() + debugmessage(100, "Worker finished") - debugmessage(100, "Api Worker Ready") while not self.discovered_objects_queue.empty(): self.discovered_objects_queue.get() @@ -131,7 +124,7 @@ def shutdown(self): while not self.message_queue.empty(): self.message_queue.get() - debugmessage(100, "Api Join Worker") + debugmessage(100, "Join worker processes") for w in self.worker: w.join(timeout=0.3) @@ -150,7 +143,7 @@ def shutdown(self): except: pass - jobmessage("M_INFO", "Shutdown Ready") + jobmessage("M_INFO", "Shutdown of worker processes is ready") def __create_tmp_dir(self): try: @@ -174,15 +167,3 @@ def __del__(self): except: pass - -if __name__ == "__main__": - if BareosLibcloudApi.probe_driver(options) == "success": - modification_time = ModificationTime() - - api = BareosLibcloudApi( - options, modification_time.get_last_run(), "/dev/shm/bareos_libcloud" - ) - api.run() - api.shutdown() - - debugmessage(10, "*** Exit ***") diff --git a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py index 2c928a15b55..98758b00099 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py +++ b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py @@ -31,7 +31,7 @@ def __init__( self.number_of_workers = number_of_workers self.object_count = 0 - def run(self): + def run_process(self): self.driver = get_driver(self.options) if self.driver == None: @@ -44,8 +44,6 @@ def run(self): for _ in range(self.number_of_workers): self.discovered_objects_queue.put(None) - self.wait_for_shutdown() - def __iterate_over_buckets(self): try: for bucket in self.driver.iterate_containers(): @@ -89,7 +87,7 @@ def __generate_jobs_for_bucket_objects(self, object_iterator): if self.last_run > mtime: self.info_message( - 100, + 400, "File %s not changed, skipped (%s > %s)" % (object_name, self.last_run, mtime), ) @@ -104,8 +102,8 @@ def __generate_jobs_for_bucket_objects(self, object_iterator): continue self.info_message( - 100, - "File %s was changed or is new, backing up (%s < %s)" + 400, + "File %s was changed or is new, put to queue (%s < %s)" % (object_name, self.last_run, mtime), ) diff --git a/core/src/plugins/filed/bareos_libcloud_api/process_base.py b/core/src/plugins/filed/bareos_libcloud_api/process_base.py index d5e1053ec52..3a4f273799b 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/process_base.py +++ b/core/src/plugins/filed/bareos_libcloud_api/process_base.py @@ -16,6 +16,14 @@ def __init__( self.message_queue = message_queue self.worker_id = worker_id + def run_process(self): + pass + + def run(self): + self.run_process() + self.ready_message() + self.wait_for_shutdown() + def shutdown(self): self.shutdown_event.set() @@ -40,5 +48,5 @@ def queue_try_put(self, queue, obj): queue.put(obj, block=True, timeout=0.5) return except Q.Full: - self.info_message(400, "Queue %s is full" % queue) + self.info_message(400, "Queue %s is full, trying again.." % queue) continue diff --git a/core/src/plugins/filed/bareos_libcloud_api/worker.py b/core/src/plugins/filed/bareos_libcloud_api/worker.py index 224361973e9..81321575cbb 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/worker.py +++ b/core/src/plugins/filed/bareos_libcloud_api/worker.py @@ -24,7 +24,7 @@ def __init__( self.input_queue = discovered_objects_queue self.output_queue = downloaded_objects_queue - def run(self): + def run_process(self): self.driver = get_driver(self.options) if self.driver == None: self.error_message("Could not load driver") @@ -32,8 +32,6 @@ def run(self): while not self.shutdown_event.is_set(): if self.__iterate_input_queue() == False: break - self.ready_message() - self.wait_for_shutdown() def __iterate_input_queue(self): while not self.input_queue.empty() and not self.shutdown_event.is_set(): @@ -77,5 +75,5 @@ def __iterate_input_queue(self): except Exception as e: self.worker_exception("Error using temporary file", e) - self.output_queue.put(job) + self.queue_try_put(self.output_queue, job) return True From 700ae1670e55a9348080e1e3c1b9aa8f24151e04 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Fri, 3 Apr 2020 16:08:41 +0200 Subject: [PATCH 292/341] libcloud-plugin: separate a simple function call --- .../filed/bareos_libcloud_api/worker.py | 90 ++++++++++--------- 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/core/src/plugins/filed/bareos_libcloud_api/worker.py b/core/src/plugins/filed/bareos_libcloud_api/worker.py index 81321575cbb..1e1be443ecf 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/worker.py +++ b/core/src/plugins/filed/bareos_libcloud_api/worker.py @@ -28,52 +28,62 @@ def run_process(self): self.driver = get_driver(self.options) if self.driver == None: self.error_message("Could not load driver") - else: - while not self.shutdown_event.is_set(): - if self.__iterate_input_queue() == False: - break + return + + finish = False + while not finish: + finish = self.__iterate_input_queue() def __iterate_input_queue(self): - while not self.input_queue.empty() and not self.shutdown_event.is_set(): + while not self.input_queue.empty(): + if self.shutdown_event.is_set(): + return True job = self.input_queue.get() - if job == None: - return False + if job == None: #poison pill + return True + if not self.__run_job(job): + return True + # try again + return False - try: - obj = self.driver.get_object(job["bucket"], job["name"]) - if obj is None: - # Object cannot be fetched, an error is already logged - continue - except Exception as exception: - self.worker_exception("Could not download file", exception) - return False + def __run_job(self, job): + try: + obj = self.driver.get_object(job["bucket"], job["name"]) + if obj is None: + # Object cannot be fetched, an error is already logged + return True + except Exception as exception: + self.worker_exception("Could not download file", exception) + return False - stream = obj.as_stream() - content = b"".join(list(stream)) + stream = obj.as_stream() + content = b"".join(list(stream)) - size_of_fetched_object = len(content) - if size_of_fetched_object != job["size"]: - self.error_message( - "prefetched file %s: got %s bytes, not the real size (%s bytes)" - % (job["name"], size_of_fetched_object, job["size"]), - ) - return False + size_of_fetched_object = len(content) + if size_of_fetched_object != job["size"]: + self.error_message( + "prefetched file %s: got %s bytes, not the real size (%s bytes)" + % (job["name"], size_of_fetched_object, job["size"]), + ) + return False + + buf = io.BytesIO(content) + if size_of_fetched_object < 1024 * 10: + job["data"] = buf + else: + try: + tmpfilename = self.tmp_dir_path + "/" + str(uuid.uuid4()) + obj.download(tmpfilename) + job["data"] = None + job["index"] = tmpfilename + except OSError as e: + self.worker_exception("Could not open temporary file", e) + except LibcloudError as e: + self.worker_exception("Error downloading object", e) + except Exception as e: + self.worker_exception("Error using temporary file", e) - buf = io.BytesIO(content) - if size_of_fetched_object < 1024 * 10: - job["data"] = buf - else: - try: - tmpfilename = self.tmp_dir_path + "/" + str(uuid.uuid4()) - obj.download(tmpfilename) - job["data"] = None - job["index"] = tmpfilename - except OSError as e: - self.worker_exception("Could not open temporary file", e) - except LibcloudError as e: - self.worker_exception("Error downloading object", e) - except Exception as e: - self.worker_exception("Error using temporary file", e) + self.queue_try_put(self.output_queue, job) - self.queue_try_put(self.output_queue, job) + #success return True From a04edfd48c80e25e3e9a36b45aceab3b0f1d06c8 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Fri, 3 Apr 2020 16:15:50 +0200 Subject: [PATCH 293/341] cleanup: apply black --- core/src/plugins/filed/BareosLibcloudApi.py | 1 - core/src/plugins/filed/bareos_libcloud_api/mtime.py | 4 +++- core/src/plugins/filed/bareos_libcloud_api/process_base.py | 1 + core/src/plugins/filed/bareos_libcloud_api/worker.py | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/plugins/filed/BareosLibcloudApi.py b/core/src/plugins/filed/BareosLibcloudApi.py index e4d7ab1db96..37281672afe 100644 --- a/core/src/plugins/filed/BareosLibcloudApi.py +++ b/core/src/plugins/filed/BareosLibcloudApi.py @@ -166,4 +166,3 @@ def __del__(self): self.__remove_tmp_dir() except: pass - diff --git a/core/src/plugins/filed/bareos_libcloud_api/mtime.py b/core/src/plugins/filed/bareos_libcloud_api/mtime.py index 63554f26cdb..c3a8341ae2e 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/mtime.py +++ b/core/src/plugins/filed/bareos_libcloud_api/mtime.py @@ -13,7 +13,9 @@ def __init__(self): class ModificationTime(object): def __init__(self): is_dst = time.daylight and time.localtime().tm_isdst - self.timezone_delta = datetime.timedelta(seconds=time.altzone if is_dst else time.timezone) + self.timezone_delta = datetime.timedelta( + seconds=time.altzone if is_dst else time.timezone + ) def get_mtime(self, obj): mtime = dateutil.parser.parse(obj.extra["last_modified"]) diff --git a/core/src/plugins/filed/bareos_libcloud_api/process_base.py b/core/src/plugins/filed/bareos_libcloud_api/process_base.py index 3a4f273799b..f3d6edd7339 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/process_base.py +++ b/core/src/plugins/filed/bareos_libcloud_api/process_base.py @@ -7,6 +7,7 @@ from bareos_libcloud_api.queue_message import MESSAGE_TYPE import Queue as Q + class ProcessBase(Process): def __init__( self, worker_id, message_queue, diff --git a/core/src/plugins/filed/bareos_libcloud_api/worker.py b/core/src/plugins/filed/bareos_libcloud_api/worker.py index 1e1be443ecf..6a5def51039 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/worker.py +++ b/core/src/plugins/filed/bareos_libcloud_api/worker.py @@ -39,7 +39,7 @@ def __iterate_input_queue(self): if self.shutdown_event.is_set(): return True job = self.input_queue.get() - if job == None: #poison pill + if job == None: # poison pill return True if not self.__run_job(job): return True @@ -85,5 +85,5 @@ def __run_job(self, job): self.queue_try_put(self.output_queue, job) - #success + # success return True From 10dbc31832dbf76c60760c3c7d9f8f4931d3889b Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Mon, 6 Apr 2020 09:32:34 +0200 Subject: [PATCH 294/341] packaging: add BareosLibcloudApi.py --- core/platforms/packaging/bareos.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/core/platforms/packaging/bareos.spec b/core/platforms/packaging/bareos.spec index 329e161c78b..5f5376e0fd5 100644 --- a/core/platforms/packaging/bareos.spec +++ b/core/platforms/packaging/bareos.spec @@ -1558,6 +1558,7 @@ mkdir -p %{?buildroot}/%{_libdir}/bareos/plugins/vmware_plugin %defattr(-, root, root) %{plugin_dir}/bareos-fd-libcloud.py* %{plugin_dir}/BareosFdPluginLibcloud.py* +%{plugin_dir}/BareosLibcloudApi.py* %dir %{plugin_dir}/bareos_libcloud_api %{plugin_dir}/bareos_libcloud_api/* From 9c37e95035e4806858d327e73a70b1afc86b4fd5 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Mon, 6 Apr 2020 16:33:59 +0200 Subject: [PATCH 295/341] libcloud-plugin: use debug_message for debug and info_message for job output --- core/src/plugins/filed/BareosFdPluginLibcloud.py | 11 ++++++----- core/src/plugins/filed/BareosLibcloudApi.py | 2 +- .../filed/bareos_libcloud_api/bucket_explorer.py | 4 +--- .../plugins/filed/bareos_libcloud_api/process_base.py | 9 ++++++--- .../filed/bareos_libcloud_api/queue_message.py | 6 ++++++ core/src/plugins/filed/bareos_libcloud_api/worker.py | 2 +- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index ace8af09c56..4ba47199bac 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -99,6 +99,7 @@ def parse_plugin_definition(self, context, plugindef): if config_filename: if self.__parse_config_file(context, config_filename): return bRCs["bRC_OK"] + debugmessage(100, "Could not load configfile %s" % (config_filename)) jobmessage("M_FATAL", "Could not load configfile %s" % (config_filename)) return bRCs["bRC_Error"] @@ -189,7 +190,7 @@ def __check_config(self, context, config_filename): def start_backup_job(self, context): jobmessage( "M_INFO", - "Try to connect to %s:%s" + "Start backup, try to connect to %s:%s" % (self.options["host"], self.options["port"]), ) @@ -198,7 +199,7 @@ def start_backup_job(self, context): % (self.options["host"], self.options["port"])) return bRCs["bRC_Error"] - jobmessage("M_INFO", "Last backup: %s (ts: %s)" % (self.last_run, self.since)) + jobmessage("M_INFO", "Connected, last backup: %s (ts: %s)" % (self.last_run, self.since)) self.api = None try: @@ -206,7 +207,7 @@ def start_backup_job(self, context): debugmessage(100, "BareosLibcloudApi started") except Exception as e: debugmessage(100, "Error: %s" % e) - jobmessage("M_FATAL", "Something went wrong: %s" % e) + jobmessage("M_FATAL", "Something went wrong with BareosLibcloudApi: %s" % e) return bRCs["bRC_Cancel"] return bRCs["bRC_OK"] @@ -300,9 +301,9 @@ def plugin_io(self, context, IOP): self.FILE = self.current_backup_job["data"] else: try: - self.FILE = io.open(self.current_backup_job["index"], 'rb') + self.FILE = io.open(self.current_backup_job["tmpfile"], 'rb') except Exception as e: - jobmessage("M_FATAL", "Could not open temporary file." % e) + jobmessage("M_FATAL", "Could not open temporary file for reading." % e) self.__shutdown() return bRCs["bRC_Error"] diff --git a/core/src/plugins/filed/BareosLibcloudApi.py b/core/src/plugins/filed/BareosLibcloudApi.py index 37281672afe..0fb22269232 100644 --- a/core/src/plugins/filed/BareosLibcloudApi.py +++ b/core/src/plugins/filed/BareosLibcloudApi.py @@ -79,7 +79,7 @@ def check_worker_messages(self): while not self.message_queue.empty(): message = self.message_queue.get_nowait() if message.type == MESSAGE_TYPE.InfoMessage: - debugmessage(message.level, message.message_string) + jobmessage("M_INFO", message.message_string) elif message.type == MESSAGE_TYPE.ReadyMessage: if message.worker_id == 0: self.count_bucket_explorer_ready += 1 diff --git a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py index 98758b00099..7a0e4a17cbb 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py +++ b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py @@ -58,7 +58,7 @@ def __iterate_over_buckets(self): if bucket.name in self.buckets_exclude: continue - self.info_message(100, 'Backing up bucket "%s"' % (bucket.name,)) + self.info_message('Exploring bucket "%s"' % (bucket.name,)) self.__generate_jobs_for_bucket_objects( self.driver.iterate_container_objects(bucket) @@ -87,7 +87,6 @@ def __generate_jobs_for_bucket_objects(self, object_iterator): if self.last_run > mtime: self.info_message( - 400, "File %s not changed, skipped (%s > %s)" % (object_name, self.last_run, mtime), ) @@ -102,7 +101,6 @@ def __generate_jobs_for_bucket_objects(self, object_iterator): continue self.info_message( - 400, "File %s was changed or is new, put to queue (%s < %s)" % (object_name, self.last_run, mtime), ) diff --git a/core/src/plugins/filed/bareos_libcloud_api/process_base.py b/core/src/plugins/filed/bareos_libcloud_api/process_base.py index f3d6edd7339..fda7f4e41ad 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/process_base.py +++ b/core/src/plugins/filed/bareos_libcloud_api/process_base.py @@ -31,8 +31,11 @@ def shutdown(self): def wait_for_shutdown(self): self.shutdown_event.wait() - def info_message(self, level, message): - self.message_queue.put(InfoMessage(self.worker_id, level, message)) + def info_message(self, message): + self.message_queue.put(InfoMessage(self.worker_id, message)) + + def debug_message(self, level, message): + self.message_queue.put(InfoMessage(self.worker_id, message)) def ready_message(self): self.message_queue.put(ReadyMessage(self.worker_id, "")) @@ -49,5 +52,5 @@ def queue_try_put(self, queue, obj): queue.put(obj, block=True, timeout=0.5) return except Q.Full: - self.info_message(400, "Queue %s is full, trying again.." % queue) + self.debug_message(400, "Queue %s is full, trying again.." % queue) continue diff --git a/core/src/plugins/filed/bareos_libcloud_api/queue_message.py b/core/src/plugins/filed/bareos_libcloud_api/queue_message.py index 15f31463701..cc1696253fc 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/queue_message.py +++ b/core/src/plugins/filed/bareos_libcloud_api/queue_message.py @@ -22,6 +22,12 @@ def __init__(self, worker_id, message): class InfoMessage(QueueMessageBase): + def __init__(self, worker_id, message): + QueueMessageBase.__init__(self, worker_id, message) + self.type = MESSAGE_TYPE.InfoMessage + + +class DebugMessage(QueueMessageBase): def __init__(self, worker_id, level, message): QueueMessageBase.__init__(self, worker_id, message) self.type = MESSAGE_TYPE.InfoMessage diff --git a/core/src/plugins/filed/bareos_libcloud_api/worker.py b/core/src/plugins/filed/bareos_libcloud_api/worker.py index 6a5def51039..832004aef06 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/worker.py +++ b/core/src/plugins/filed/bareos_libcloud_api/worker.py @@ -75,7 +75,7 @@ def __run_job(self, job): tmpfilename = self.tmp_dir_path + "/" + str(uuid.uuid4()) obj.download(tmpfilename) job["data"] = None - job["index"] = tmpfilename + job["tmpfile"] = tmpfilename except OSError as e: self.worker_exception("Could not open temporary file", e) except LibcloudError as e: From 7548e34bf92484bf9f73176093c28325d5115c3a Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Mon, 6 Apr 2020 20:37:49 +0200 Subject: [PATCH 296/341] libcloud-plugin: implement download as stream - use dedicated job types instead of implicit variables - send libcloud obj on the queue and create stream object just in time --- .../plugins/filed/BareosFdPluginLibcloud.py | 17 ++++++- core/src/plugins/filed/BareosLibcloudApi.py | 3 +- .../bareos_libcloud_api/bucket_explorer.py | 10 ++++ .../filed/bareos_libcloud_api/worker.py | 50 +++++++++++++------ 4 files changed, 62 insertions(+), 18 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 4ba47199bac..50695f28e4b 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -25,6 +25,7 @@ import ConfigParser as configparser import datetime import dateutil.parser +from bareos_libcloud_api.bucket_explorer import JOB_TYPE from bareos_libcloud_api.debug import debugmessage from bareos_libcloud_api.debug import jobmessage from bareos_libcloud_api.debug import set_plugin_context @@ -63,6 +64,14 @@ def str2bool(data): raise Exception("%s: not a boolean" % (data,)) +class IterStringIO(io.BufferedIOBase): + def __init__(self, iterable): + self.iter = itertools.chain.from_iterable(iterable) + + def read(self, n=None): + return bytearray(itertools.islice(self.iter, None, n)) + + class BareosFdPluginLibcloud(BareosFdPluginBaseclass.BareosFdPluginBaseclass): def __init__(self, context, plugindef): set_plugin_context(context) @@ -297,15 +306,19 @@ def plugin_io(self, context, IOP): return bRCs["bRC_OK"] # 'Backup' path - if self.current_backup_job["data"] != None: + if self.current_backup_job["type"] == JOB_TYPE.DOWNLOADED: self.FILE = self.current_backup_job["data"] - else: + elif self.current_backup_job["type"] == JOB_TYPE.TEMP_FILE: try: self.FILE = io.open(self.current_backup_job["tmpfile"], 'rb') except Exception as e: jobmessage("M_FATAL", "Could not open temporary file for reading." % e) self.__shutdown() return bRCs["bRC_Error"] + elif self.current_backup_job["type"] == JOB_TYPE.STREAM: + self.FILE = IterStringIO(self.current_backup_job["data"].as_stream()) + else: + raise Exception(value="Wrong argument") elif IOP.func == bIOPS["IO_READ"]: IOP.buf = bytearray(IOP.count) diff --git a/core/src/plugins/filed/BareosLibcloudApi.py b/core/src/plugins/filed/BareosLibcloudApi.py index 0fb22269232..db27b362ef9 100644 --- a/core/src/plugins/filed/BareosLibcloudApi.py +++ b/core/src/plugins/filed/BareosLibcloudApi.py @@ -1,4 +1,5 @@ from bareos_libcloud_api.bucket_explorer import BucketExplorer +from bareos_libcloud_api.bucket_explorer import JOB_TYPE from bareos_libcloud_api.debug import debugmessage, jobmessage from bareos_libcloud_api.get_libcloud_driver import get_driver from bareos_libcloud_api.get_libcloud_driver import options @@ -19,8 +20,6 @@ SUCCESS = 0 ERROR = 1 -MESSAGE_TYPE = MESSAGE_TYPE() - class BareosLibcloudApi(object): @staticmethod diff --git a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py index 7a0e4a17cbb..496035bcabd 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py +++ b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py @@ -2,6 +2,15 @@ from bareos_libcloud_api.get_libcloud_driver import get_driver from bareos_libcloud_api.mtime import ModificationTime +class JOB_TYPE(object): + UNDEFINED = 0 + DOWNLOADED = 1 + TEMP_FILE = 2 + STREAM = 3 + + def __setattr__(self, *_): + raise Exception("class JOB_TYPE is read only") + def parse_options_bucket(name, options): if name not in options: @@ -81,6 +90,7 @@ def __generate_jobs_for_bucket_objects(self, object_iterator): "index": None, "size": obj.size, "mtime": mtime_ts, + "type": JOB_TYPE.UNDEFINED, } object_name = "%s/%s" % (obj.container.name, obj.name) diff --git a/core/src/plugins/filed/bareos_libcloud_api/worker.py b/core/src/plugins/filed/bareos_libcloud_api/worker.py index 832004aef06..ded6e1e93e5 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/worker.py +++ b/core/src/plugins/filed/bareos_libcloud_api/worker.py @@ -1,3 +1,4 @@ +from bareos_libcloud_api.bucket_explorer import JOB_TYPE from bareos_libcloud_api.process_base import ProcessBase from bareos_libcloud_api.get_libcloud_driver import get_driver import io @@ -53,35 +54,56 @@ def __run_job(self, job): # Object cannot be fetched, an error is already logged return True except Exception as exception: - self.worker_exception("Could not download file", exception) + self.worker_exception("Could not get file object", exception) return False - stream = obj.as_stream() - content = b"".join(list(stream)) + if job["size"] < 1024 * 10: + try: + stream = obj.as_stream() + content = b"".join(list(stream)) - size_of_fetched_object = len(content) - if size_of_fetched_object != job["size"]: - self.error_message( - "prefetched file %s: got %s bytes, not the real size (%s bytes)" - % (job["name"], size_of_fetched_object, job["size"]), - ) - return False + size_of_fetched_object = len(content) + if size_of_fetched_object != job["size"]: + self.error_message( + "prefetched file %s: got %s bytes, not the real size (%s bytes)" + % (job["name"], size_of_fetched_object, job["size"]), + ) + return False - buf = io.BytesIO(content) - if size_of_fetched_object < 1024 * 10: - job["data"] = buf - else: + job["data"] = io.BytesIO(content) + job["type"] = JOB_TYPE.DOWNLOADED + except LibcloudError as e: + self.worker_exception("Libcloud error, could not download file", e) + return False + except Exception as e: + self.worker_exception("Could not download file", e) + return False + elif job["size"] < self.options["prefetch_size"]: try: tmpfilename = self.tmp_dir_path + "/" + str(uuid.uuid4()) obj.download(tmpfilename) job["data"] = None job["tmpfile"] = tmpfilename + job["type"] = JOB_TYPE.TEMP_FILE except OSError as e: self.worker_exception("Could not open temporary file", e) + return False except LibcloudError as e: self.worker_exception("Error downloading object", e) + return False except Exception as e: self.worker_exception("Error using temporary file", e) + return False + else: + try: + job["data"] = obj + job["type"] = JOB_TYPE.STREAM + except LibcloudError as e: + self.worker_exception("Libcloud error preparing stream object", e) + return False + except Exception as e: + self.worker_exception("Error preparing stream object", e) + return False self.queue_try_put(self.output_queue, job) From d2ddf6f75e3604de3c70f00384a57dd359ecf178 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 7 Apr 2020 16:28:21 +0200 Subject: [PATCH 297/341] libcloud-plugin: skip a file that does not exist --- .../plugins/filed/BareosFdPluginLibcloud.py | 85 ++++++++++++------- 1 file changed, 53 insertions(+), 32 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 50695f28e4b..943922d3df9 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -41,11 +41,12 @@ from BareosLibcloudApi import BareosLibcloudApi from bareos_fd_consts import bRCs, bCFs, bIOPS, bJobMessageType, bFileType from libcloud.storage.types import Provider +from libcloud.storage.types import ObjectDoesNotExistError from sys import version_info class FilenameConverter: - __pathprefix = 'PYLIBCLOUD:/' + __pathprefix = "PYLIBCLOUD:/" @staticmethod def BucketToBackup(filename): @@ -53,7 +54,7 @@ def BucketToBackup(filename): @staticmethod def BackupToBucket(filename): - return filename.replace(FilenameConverter.__pathprefix, '') + return filename.replace(FilenameConverter.__pathprefix, "") def str2bool(data): @@ -66,10 +67,10 @@ def str2bool(data): class IterStringIO(io.BufferedIOBase): def __init__(self, iterable): - self.iter = itertools.chain.from_iterable(iterable) + self.iter = itertools.chain.from_iterable(iterable) def read(self, n=None): - return bytearray(itertools.islice(self.iter, None, n)) + return bytearray(itertools.islice(self.iter, None, n)) class BareosFdPluginLibcloud(BareosFdPluginBaseclass.BareosFdPluginBaseclass): @@ -204,15 +205,23 @@ def start_backup_job(self, context): ) if BareosLibcloudApi.probe_driver(self.options) == "failed": - jobmessage("M_FATAL", "Could not connect to libcloud driver: %s:%s" - % (self.options["host"], self.options["port"])) + jobmessage( + "M_FATAL", + "Could not connect to libcloud driver: %s:%s" + % (self.options["host"], self.options["port"]), + ) return bRCs["bRC_Error"] - jobmessage("M_INFO", "Connected, last backup: %s (ts: %s)" % (self.last_run, self.since)) + jobmessage( + "M_INFO", + "Connected, last backup: %s (ts: %s)" % (self.last_run, self.since), + ) self.api = None try: - self.api = BareosLibcloudApi(self.options, self.last_run, "/dev/shm/bareos_libcloud") + self.api = BareosLibcloudApi( + self.options, self.last_run, "/dev/shm/bareos_libcloud" + ) debugmessage(100, "BareosLibcloudApi started") except Exception as e: debugmessage(100, "Error: %s" % e) @@ -264,10 +273,8 @@ def start_backup_file(self, context, savepkt): return bRCs["bRC_Skip"] filename = FilenameConverter.BucketToBackup( - "%s/%s" % ( - self.current_backup_job["bucket"], - self.current_backup_job["name"], - ) + "%s/%s" + % (self.current_backup_job["bucket"], self.current_backup_job["name"],) ) jobmessage("M_INFO", "Backup file: %s" % (filename,)) @@ -283,14 +290,40 @@ def start_backup_file(self, context, savepkt): self.number_of_objects_to_backup += 1 + if self.current_backup_job["type"] == JOB_TYPE.DOWNLOADED: + self.FILE = self.current_backup_job["data"] + elif self.current_backup_job["type"] == JOB_TYPE.TEMP_FILE: + try: + self.FILE = io.open(self.current_backup_job["tmpfile"], "rb") + except Exception as e: + jobmessage("M_FATAL", "Could not open temporary file for reading." % e) + self.__shutdown() + return bRCs["bRC_Error"] + elif self.current_backup_job["type"] == JOB_TYPE.STREAM: + try: + self.FILE = IterStringIO(self.current_backup_job["data"].as_stream()) + except ObjectDoesNotExistError as e: + jobmessage( + "M_WARNING", + "Skipped file %s because it does not exist" + % (self.current_backup_job["name"]), + ) + return bRCs["bRC_Skip"] + else: + raise Exception(value='Wrong argument for current_backup_job["type"]') + return bRCs["bRC_OK"] def create_file(self, context, restorepkt): - debugmessage(100, "create_file() entry point in Python called with %s\n" % (restorepkt)) + debugmessage( + 100, "create_file() entry point in Python called with %s\n" % (restorepkt) + ) FNAME = FilenameConverter.BackupToBucket(restorepkt.ofname) dirname = os.path.dirname(FNAME) if not os.path.exists(dirname): - jobmessage("M_INFO", "Directory %s does not exist, creating it now\n" % dirname) + jobmessage( + "M_INFO", "Directory %s does not exist, creating it now\n" % dirname + ) os.makedirs(dirname) if restorepkt.type == bFileType["FT_REG"]: restorepkt.create_status = bCFs["CF_EXTRACT"] @@ -303,22 +336,7 @@ def plugin_io(self, context, IOP): # Only used by the 'restore' path if IOP.flags & (os.O_CREAT | os.O_WRONLY): self.FILE = open(FilenameConverter.BackupToBucket(IOP.fname), "wb") - return bRCs["bRC_OK"] - - # 'Backup' path - if self.current_backup_job["type"] == JOB_TYPE.DOWNLOADED: - self.FILE = self.current_backup_job["data"] - elif self.current_backup_job["type"] == JOB_TYPE.TEMP_FILE: - try: - self.FILE = io.open(self.current_backup_job["tmpfile"], 'rb') - except Exception as e: - jobmessage("M_FATAL", "Could not open temporary file for reading." % e) - self.__shutdown() - return bRCs["bRC_Error"] - elif self.current_backup_job["type"] == JOB_TYPE.STREAM: - self.FILE = IterStringIO(self.current_backup_job["data"].as_stream()) - else: - raise Exception(value="Wrong argument") + return bRCs["bRC_OK"] elif IOP.func == bIOPS["IO_READ"]: IOP.buf = bytearray(IOP.count) @@ -331,8 +349,11 @@ def plugin_io(self, context, IOP): IOP.status = len(buf) return bRCs["bRC_OK"] except IOError as e: - jobmessage("M_ERROR", "Cannot read from %s : %s" - % (FilenameConverter.BackupToBucket(IOP.fname), e)) + jobmessage( + "M_ERROR", + "Cannot read from %s : %s" + % (FilenameConverter.BackupToBucket(IOP.fname), e), + ) IOP.status = 0 IOP.io_errno = e.errno return bRCs["bRC_Error"] From 792ea7fb3b73f6e33c9ffe00d37dda765e813c13 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 7 Apr 2020 17:07:13 +0200 Subject: [PATCH 298/341] libcloud-plugin: use current_job instead of iop data --- core/src/plugins/filed/BareosFdPluginLibcloud.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 943922d3df9..0f6c40aa2de 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -351,8 +351,8 @@ def plugin_io(self, context, IOP): except IOError as e: jobmessage( "M_ERROR", - "Cannot read from %s : %s" - % (FilenameConverter.BackupToBucket(IOP.fname), e), + "Cannot read from %s/%s: %s" + % (self.current_backup_job["bucket"], self.current_backup_job["name"], e), ) IOP.status = 0 IOP.io_errno = e.errno From 501534a6d6a3c0e6b53d7aa1266ae2b9566c0de4 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 7 Apr 2020 17:38:20 +0200 Subject: [PATCH 299/341] libcloud-plugin: use variables instead of magic numbers --- .../filed/bareos_libcloud_api/worker.py | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/core/src/plugins/filed/bareos_libcloud_api/worker.py b/core/src/plugins/filed/bareos_libcloud_api/worker.py index ded6e1e93e5..0c89b66fdf8 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/worker.py +++ b/core/src/plugins/filed/bareos_libcloud_api/worker.py @@ -3,9 +3,12 @@ from bareos_libcloud_api.get_libcloud_driver import get_driver import io from libcloud.common.types import LibcloudError +from libcloud.storage.types import ObjectDoesNotExistError import uuid from time import sleep +FINISH = 0 +CONTINUE = 1 class Worker(ProcessBase): def __init__( @@ -31,31 +34,31 @@ def run_process(self): self.error_message("Could not load driver") return - finish = False - while not finish: - finish = self.__iterate_input_queue() + status = CONTINUE + while status != FINISH: + status = self.__iterate_input_queue() def __iterate_input_queue(self): while not self.input_queue.empty(): if self.shutdown_event.is_set(): - return True + return FINISH job = self.input_queue.get() if job == None: # poison pill - return True - if not self.__run_job(job): - return True + return FINISH + if self.__run_job(job) == FINISH: + return FINISH # try again - return False + return CONTINUE def __run_job(self, job): try: obj = self.driver.get_object(job["bucket"], job["name"]) if obj is None: # Object cannot be fetched, an error is already logged - return True + return CONTINUE except Exception as exception: self.worker_exception("Could not get file object", exception) - return False + return FINISH if job["size"] < 1024 * 10: try: @@ -68,16 +71,16 @@ def __run_job(self, job): "prefetched file %s: got %s bytes, not the real size (%s bytes)" % (job["name"], size_of_fetched_object, job["size"]), ) - return False + return FINISH job["data"] = io.BytesIO(content) job["type"] = JOB_TYPE.DOWNLOADED except LibcloudError as e: self.worker_exception("Libcloud error, could not download file", e) - return False + return FINISH except Exception as e: self.worker_exception("Could not download file", e) - return False + return FINISH elif job["size"] < self.options["prefetch_size"]: try: tmpfilename = self.tmp_dir_path + "/" + str(uuid.uuid4()) @@ -87,25 +90,28 @@ def __run_job(self, job): job["type"] = JOB_TYPE.TEMP_FILE except OSError as e: self.worker_exception("Could not open temporary file", e) - return False + return FINISH + except ObjectDoesNotExistError as e: + self.worker_exception("Could not open object", e) + return CONTINUE except LibcloudError as e: self.worker_exception("Error downloading object", e) - return False + return FINISH except Exception as e: self.worker_exception("Error using temporary file", e) - return False + return FINISH else: try: job["data"] = obj job["type"] = JOB_TYPE.STREAM except LibcloudError as e: self.worker_exception("Libcloud error preparing stream object", e) - return False + return FINISH except Exception as e: self.worker_exception("Error preparing stream object", e) - return False + return FINISH self.queue_try_put(self.output_queue, job) # success - return True + return CONTINUE From e5652290e7858ce075c73cbac23b7c536315ab27 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 7 Apr 2020 18:35:36 +0200 Subject: [PATCH 300/341] libcloud-plugin: add configurable temporary download directory --- core/src/plugins/filed/BareosFdPluginLibcloud.py | 6 ++++-- .../python-fd-plugin-libcloud-test/etc/libcloud_config.ini | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 0f6c40aa2de..755872658e4 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -145,7 +145,7 @@ def __check_config(self, context, config_filename): mandatory_options = {} mandatory_options["credentials"] = ["username", "password"] mandatory_options["host"] = ["hostname", "port", "provider", "tls"] - mandatory_options["misc"] = ["nb_worker", "queue_size", "prefetch_size"] + mandatory_options["misc"] = ["nb_worker", "queue_size", "prefetch_size", "temporary_download_directory"] # this maps config file options to libcloud options option_map = { @@ -185,6 +185,8 @@ def __check_config(self, context, config_filename): self.options["queue_size"] = int(value) elif option == "prefetch_size": self.options["prefetch_size"] = eval(value) + elif option == "temporary_download_directory": + self.options["temporary_download_directory"] = value else: self.options[option_map[option]] = value except: @@ -220,7 +222,7 @@ def start_backup_job(self, context): self.api = None try: self.api = BareosLibcloudApi( - self.options, self.last_run, "/dev/shm/bareos_libcloud" + self.options, self.last_run, self.options["temporary_download_directory"] ) debugmessage(100, "BareosLibcloudApi started") except Exception as e: diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/libcloud_config.ini b/systemtests/tests/python-fd-plugin-libcloud-test/etc/libcloud_config.ini index aa089d5ab69..e2b9f1572c7 100644 --- a/systemtests/tests/python-fd-plugin-libcloud-test/etc/libcloud_config.ini +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/libcloud_config.ini @@ -12,3 +12,4 @@ password=minioadmin nb_worker=20 queue_size=1000 prefetch_size=10*1024*1024 +temporary_download_directory=/dev/shm/bareos_libcloud From 68f8696fcc13ae59100be469a7234c93491e4e54 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 7 Apr 2020 21:14:36 +0200 Subject: [PATCH 301/341] libcloud-plugin: add type debugmessage --- core/src/plugins/filed/BareosLibcloudApi.py | 2 ++ core/src/plugins/filed/bareos_libcloud_api/queue_message.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/plugins/filed/BareosLibcloudApi.py b/core/src/plugins/filed/BareosLibcloudApi.py index db27b362ef9..fa17e310461 100644 --- a/core/src/plugins/filed/BareosLibcloudApi.py +++ b/core/src/plugins/filed/BareosLibcloudApi.py @@ -91,6 +91,8 @@ def check_worker_messages(self): debugmessage(10, message.message_string) debugmessage(10, message.exception) return ERROR + elif message.type == MESSAGE_TYPE.DebugMessage: + debugmessage(message.level, message.message_string) else: debugmessage(10, message) return ERROR diff --git a/core/src/plugins/filed/bareos_libcloud_api/queue_message.py b/core/src/plugins/filed/bareos_libcloud_api/queue_message.py index cc1696253fc..6de968ec56c 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/queue_message.py +++ b/core/src/plugins/filed/bareos_libcloud_api/queue_message.py @@ -3,6 +3,7 @@ class MESSAGE_TYPE(object): ErrorMessage = 2 WorkerException = 3 ReadyMessage = 4 + DebugMessage = 5 def __setattr__(self, *_): raise Exception("class MESSAGE_TYPE is read only") @@ -30,7 +31,7 @@ def __init__(self, worker_id, message): class DebugMessage(QueueMessageBase): def __init__(self, worker_id, level, message): QueueMessageBase.__init__(self, worker_id, message) - self.type = MESSAGE_TYPE.InfoMessage + self.type = MESSAGE_TYPE.DebugMessage self.level = level From ea93a5a942fb92271b0b9270551bf5e720024aab Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Tue, 7 Apr 2020 21:19:18 +0200 Subject: [PATCH 302/341] libcloud-plugin: limit prefetch temporary file size to 250MB --- .../python-fd-plugin-libcloud-test/etc/libcloud_config.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/libcloud_config.ini b/systemtests/tests/python-fd-plugin-libcloud-test/etc/libcloud_config.ini index e2b9f1572c7..579e225e6f8 100644 --- a/systemtests/tests/python-fd-plugin-libcloud-test/etc/libcloud_config.ini +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/libcloud_config.ini @@ -11,5 +11,5 @@ password=minioadmin [misc] nb_worker=20 queue_size=1000 -prefetch_size=10*1024*1024 +prefetch_size=250*1024*1024 temporary_download_directory=/dev/shm/bareos_libcloud From 559763fb3d58a070bf5a2d3996b5796af80f2feb Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Wed, 8 Apr 2020 17:08:51 +0200 Subject: [PATCH 303/341] libcloud-plugin: rework the queue-message handling completely - as a consequence missing files will not cancel a job --- .../plugins/filed/BareosFdPluginLibcloud.py | 27 +++-- core/src/plugins/filed/BareosLibcloudApi.py | 37 +++--- .../bareos_libcloud_api/bucket_explorer.py | 108 +++++++++--------- .../filed/bareos_libcloud_api/process_base.py | 17 +-- .../bareos_libcloud_api/queue_message.py | 17 ++- .../filed/bareos_libcloud_api/worker.py | 70 +++++++----- 6 files changed, 146 insertions(+), 130 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 755872658e4..660c9f189ae 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -244,22 +244,22 @@ def check_file(self, context, fname): def __shutdown(self): self.active = False - if self.number_of_objects_to_backup: - jobmessage( - "M_INFO", - "Backup completed with %d objects" % self.number_of_objects_to_backup, - ) - else: - jobmessage("M_INFO", "No objects to backup") + jobmessage( + "M_INFO", + "BareosFdPluginLibcloud finished with %d files" + % (self.number_of_objects_to_backup) + ) debugmessage(100, "Shut down BareosLibcloudApi") self.api.shutdown() debugmessage(100, "BareosLibcloudApi is shut down") def start_backup_file(self, context, savepkt): + error = False while self.active: if self.api.check_worker_messages() != SUCCESS: self.active = False + error = True else: self.current_backup_job = self.api.get_next_job() if self.current_backup_job != None: @@ -271,8 +271,12 @@ def start_backup_file(self, context, savepkt): if not self.active: self.__shutdown() - savepkt.fname = "empty" # dummy value, savepkt is always checked - return bRCs["bRC_Skip"] + savepkt.fname = "empty" # dummy value + if error: + jobmessage("M_FATAL", "Shutdown after worker error") + return bRCs["bRC_Cancel"] + else: + return bRCs["bRC_Skip"] filename = FilenameConverter.BucketToBackup( "%s/%s" @@ -290,8 +294,6 @@ def start_backup_file(self, context, savepkt): savepkt.fname = filename savepkt.type = bareos_fd_consts.bFileType["FT_REG"] - self.number_of_objects_to_backup += 1 - if self.current_backup_job["type"] == JOB_TYPE.DOWNLOADED: self.FILE = self.current_backup_job["data"] elif self.current_backup_job["type"] == JOB_TYPE.TEMP_FILE: @@ -304,7 +306,7 @@ def start_backup_file(self, context, savepkt): elif self.current_backup_job["type"] == JOB_TYPE.STREAM: try: self.FILE = IterStringIO(self.current_backup_job["data"].as_stream()) - except ObjectDoesNotExistError as e: + except ObjectDoesNotExistError: jobmessage( "M_WARNING", "Skipped file %s because it does not exist" @@ -378,6 +380,7 @@ def plugin_io(self, context, IOP): def end_backup_file(self, context): if self.current_backup_job is not None: + self.number_of_objects_to_backup += 1 return bRCs["bRC_More"] else: return bRCs["bRC_OK"] diff --git a/core/src/plugins/filed/BareosLibcloudApi.py b/core/src/plugins/filed/BareosLibcloudApi.py index fa17e310461..140794f57ba 100644 --- a/core/src/plugins/filed/BareosLibcloudApi.py +++ b/core/src/plugins/filed/BareosLibcloudApi.py @@ -76,26 +76,25 @@ def bucket_explorer_ready(self): def check_worker_messages(self): while not self.message_queue.empty(): - message = self.message_queue.get_nowait() - if message.type == MESSAGE_TYPE.InfoMessage: - jobmessage("M_INFO", message.message_string) - elif message.type == MESSAGE_TYPE.ReadyMessage: - if message.worker_id == 0: - self.count_bucket_explorer_ready += 1 + try: + message = self.message_queue.get_nowait() + if message.type == MESSAGE_TYPE.InfoMessage: + jobmessage("M_INFO", message.message_string) + elif message.type == MESSAGE_TYPE.ErrorMessage: + jobmessage("M_ERROR", message.message_string) + elif message.type == MESSAGE_TYPE.ReadyMessage: + if message.worker_id == 0: + self.count_bucket_explorer_ready += 1 + else: + self.count_worker_ready += 1 + elif message.type == MESSAGE_TYPE.AbortMessage: + return ERROR + elif message.type == MESSAGE_TYPE.DebugMessage: + debugmessage(message.level, message.message_string) else: - self.count_worker_ready += 1 - elif message.type == MESSAGE_TYPE.ErrorMessage: - debugmessage(10, message.message_string) - return ERROR - elif message.type == MESSAGE_TYPE.WorkerException: - debugmessage(10, message.message_string) - debugmessage(10, message.exception) - return ERROR - elif message.type == MESSAGE_TYPE.DebugMessage: - debugmessage(message.level, message.message_string) - else: - debugmessage(10, message) - return ERROR + raise Exception(value="Unknown message type") + except Exception as e: + jobmessage("M_INFO", "check_worker_messages exception: %s" % e) return SUCCESS def get_next_job(self): diff --git a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py index 496035bcabd..c68826c3271 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py +++ b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py @@ -2,6 +2,7 @@ from bareos_libcloud_api.get_libcloud_driver import get_driver from bareos_libcloud_api.mtime import ModificationTime + class JOB_TYPE(object): UNDEFINED = 0 DOWNLOADED = 1 @@ -38,84 +39,81 @@ def __init__( self.buckets_include = parse_options_bucket("buckets_include", options) self.buckets_exclude = parse_options_bucket("buckets_exclude", options) self.number_of_workers = number_of_workers - self.object_count = 0 def run_process(self): self.driver = get_driver(self.options) if self.driver == None: self.error_message("Could not load driver") + self.abort_message() return - if not self.shutdown_event.is_set(): - self.__iterate_over_buckets() + try: + if not self.shutdown_event.is_set(): + self.__iterate_over_buckets() + except Exception: + self.error_message("Error while iterating containers") + self.abort_message() for _ in range(self.number_of_workers): self.discovered_objects_queue.put(None) def __iterate_over_buckets(self): - try: - for bucket in self.driver.iterate_containers(): - if self.shutdown_event.is_set(): - break + for bucket in self.driver.iterate_containers(): + if self.shutdown_event.is_set(): + break - if self.buckets_include is not None: - if bucket.name not in self.buckets_include: - continue + if self.buckets_include is not None: + if bucket.name not in self.buckets_include: + continue - if self.buckets_exclude is not None: - if bucket.name in self.buckets_exclude: - continue + if self.buckets_exclude is not None: + if bucket.name in self.buckets_exclude: + continue - self.info_message('Exploring bucket "%s"' % (bucket.name,)) + self.info_message('Exploring bucket "%s"' % (bucket.name,)) - self.__generate_jobs_for_bucket_objects( - self.driver.iterate_container_objects(bucket) - ) - except Exception as exception: - self.worker_exception("Error while iterating containers", exception) + self.__generate_jobs_for_bucket_objects( + self.driver.iterate_container_objects(bucket) + ) def __generate_jobs_for_bucket_objects(self, object_iterator): - try: - for obj in object_iterator: - if self.shutdown_event.is_set(): - break - - mtime, mtime_ts = ModificationTime().get_mtime(obj) - - job = { - "name": obj.name, - "bucket": obj.container.name, - "data": None, - "index": None, - "size": obj.size, - "mtime": mtime_ts, - "type": JOB_TYPE.UNDEFINED, - } - - object_name = "%s/%s" % (obj.container.name, obj.name) - - if self.last_run > mtime: - self.info_message( - "File %s not changed, skipped (%s > %s)" - % (object_name, self.last_run, mtime), - ) - - # This object was present on our last backup - # Here, we push it directly to bareos, it will not be backed again - # but remembered as "still here" (for accurate mode) - # If accurate mode is off, we can simply skip that object - if self.options["accurate"] is True: - self.queue_try_put(self.discovered_objects_queue, job) + for obj in object_iterator: + if self.shutdown_event.is_set(): + break - continue + mtime, mtime_ts = ModificationTime().get_mtime(obj) + + job = { + "name": obj.name, + "bucket": obj.container.name, + "data": None, + "index": None, + "size": obj.size, + "mtime": mtime_ts, + "type": JOB_TYPE.UNDEFINED, + } + object_name = "%s/%s" % (obj.container.name, obj.name) + + if self.last_run > mtime: self.info_message( - "File %s was changed or is new, put to queue (%s < %s)" + "File %s not changed, skipped (%s > %s)" % (object_name, self.last_run, mtime), ) - self.queue_try_put(self.discovered_objects_queue, job) + # This object was present on our last backup + # Here, we push it directly to bareos, it will not be backed again + # but remembered as "still here" (for accurate mode) + # If accurate mode is off, we can simply skip that object + if self.options["accurate"] is True: + self.queue_try_put(self.discovered_objects_queue, job) + + continue + + self.info_message( + "File %s was changed or is new, put to queue (%s < %s)" + % (object_name, self.last_run, mtime), + ) - except Exception as exception: - self.worker_exception("Error while iterating objects", exception) + self.queue_try_put(self.discovered_objects_queue, job) diff --git a/core/src/plugins/filed/bareos_libcloud_api/process_base.py b/core/src/plugins/filed/bareos_libcloud_api/process_base.py index fda7f4e41ad..85d60725c0a 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/process_base.py +++ b/core/src/plugins/filed/bareos_libcloud_api/process_base.py @@ -3,7 +3,8 @@ from bareos_libcloud_api.queue_message import InfoMessage from bareos_libcloud_api.queue_message import ReadyMessage from bareos_libcloud_api.queue_message import ErrorMessage -from bareos_libcloud_api.queue_message import WorkerException +from bareos_libcloud_api.queue_message import AbortMessage +from bareos_libcloud_api.queue_message import DebugMessage from bareos_libcloud_api.queue_message import MESSAGE_TYPE import Queue as Q @@ -34,17 +35,17 @@ def wait_for_shutdown(self): def info_message(self, message): self.message_queue.put(InfoMessage(self.worker_id, message)) + def error_message(self, message): + self.message_queue.put(ErrorMessage(self.worker_id, message)) + def debug_message(self, level, message): - self.message_queue.put(InfoMessage(self.worker_id, message)) + self.message_queue.put(DebugMessage(self.worker_id, level, message)) def ready_message(self): - self.message_queue.put(ReadyMessage(self.worker_id, "")) - - def error_message(self, message): - self.message_queue.put(ErrorMessage(self.worker_id, message)) + self.message_queue.put(ReadyMessage(self.worker_id)) - def worker_exception(self, message, exception): - self.message_queue.put(WorkerException(self.worker_id, message, exception)) + def abort_message(self): + self.message_queue.put(AbortMessage(self.worker_id)) def queue_try_put(self, queue, obj): while not self.shutdown_event.is_set(): diff --git a/core/src/plugins/filed/bareos_libcloud_api/queue_message.py b/core/src/plugins/filed/bareos_libcloud_api/queue_message.py index 6de968ec56c..dcf6e480501 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/queue_message.py +++ b/core/src/plugins/filed/bareos_libcloud_api/queue_message.py @@ -1,7 +1,7 @@ class MESSAGE_TYPE(object): InfoMessage = 1 ErrorMessage = 2 - WorkerException = 3 + AbortMessage = 3 ReadyMessage = 4 DebugMessage = 5 @@ -35,14 +35,13 @@ def __init__(self, worker_id, level, message): self.level = level -class WorkerException(QueueMessageBase): - def __init__(self, worker_id, message, exception): +class ReadyMessage(QueueMessageBase): + def __init__(self, worker_id, message=None): QueueMessageBase.__init__(self, worker_id, message) - self.type = MESSAGE_TYPE.WorkerException - self.exception = exception + self.type = MESSAGE_TYPE.ReadyMessage -class ReadyMessage(QueueMessageBase): - def __init__(self, worker_id, message): - QueueMessageBase.__init__(self, worker_id, "") - self.type = MESSAGE_TYPE.ReadyMessage +class AbortMessage(QueueMessageBase): + def __init__(self, worker_id): + QueueMessageBase.__init__(self, worker_id, None) + self.type = MESSAGE_TYPE.AbortMessage diff --git a/core/src/plugins/filed/bareos_libcloud_api/worker.py b/core/src/plugins/filed/bareos_libcloud_api/worker.py index 0c89b66fdf8..5d7dd83a018 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/worker.py +++ b/core/src/plugins/filed/bareos_libcloud_api/worker.py @@ -10,6 +10,7 @@ FINISH = 0 CONTINUE = 1 + class Worker(ProcessBase): def __init__( self, @@ -32,6 +33,7 @@ def run_process(self): self.driver = get_driver(self.options) if self.driver == None: self.error_message("Could not load driver") + self.abort_message() return status = CONTINUE @@ -53,12 +55,12 @@ def __iterate_input_queue(self): def __run_job(self, job): try: obj = self.driver.get_object(job["bucket"], job["name"]) - if obj is None: - # Object cannot be fetched, an error is already logged - return CONTINUE - except Exception as exception: - self.worker_exception("Could not get file object", exception) - return FINISH + except ObjectDoesNotExistError: + self.error_message( + "Could not get file object, skipping: %s/%s" + % (job["bucket"], job["name"]) + ) + return CONTINUE if job["size"] < 1024 * 10: try: @@ -71,16 +73,16 @@ def __run_job(self, job): "prefetched file %s: got %s bytes, not the real size (%s bytes)" % (job["name"], size_of_fetched_object, job["size"]), ) - return FINISH + return CONTINUE job["data"] = io.BytesIO(content) job["type"] = JOB_TYPE.DOWNLOADED - except LibcloudError as e: - self.worker_exception("Libcloud error, could not download file", e) - return FINISH - except Exception as e: - self.worker_exception("Could not download file", e) - return FINISH + except LibcloudError: + self.error_message("Libcloud error, could not download file") + return CONTINUE + except Exception: + self.error_message("Could not download file") + return CONTINUE elif job["size"] < self.options["prefetch_size"]: try: tmpfilename = self.tmp_dir_path + "/" + str(uuid.uuid4()) @@ -89,27 +91,41 @@ def __run_job(self, job): job["tmpfile"] = tmpfilename job["type"] = JOB_TYPE.TEMP_FILE except OSError as e: - self.worker_exception("Could not open temporary file", e) + self.error_message("Could not open temporary file %s" % e.filename) return FINISH except ObjectDoesNotExistError as e: - self.worker_exception("Could not open object", e) + self.error_message( + "Could not open object, skipping: %s" % e.object_name + ) + return CONTINUE + except LibcloudError: + self.error_message( + "Error downloading object, skipping: %s/%s" + % (job["bucket"], job["name"]) + ) + return CONTINUE + except Exception: + self.error_message( + "Error using temporary file for, skipping: %s/%s" + % (job["bucket"], job["name"]) + ) return CONTINUE - except LibcloudError as e: - self.worker_exception("Error downloading object", e) - return FINISH - except Exception as e: - self.worker_exception("Error using temporary file", e) - return FINISH else: try: job["data"] = obj job["type"] = JOB_TYPE.STREAM - except LibcloudError as e: - self.worker_exception("Libcloud error preparing stream object", e) - return FINISH - except Exception as e: - self.worker_exception("Error preparing stream object", e) - return FINISH + except LibcloudError: + self.error_message( + "Libcloud error preparing stream object, skipping: %s/%s" + % (job["bucket"], job["name"]) + ) + return CONTINUE + except Exception: + self.error_message( + "Error preparing stream object, skipping: %s/%s" + % (job["bucket"], job["name"]) + ) + return CONTINUE self.queue_try_put(self.output_queue, job) From 7f2a2b91b11f004bf972f2b4f9a3103e48c156f9 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 9 Apr 2020 12:18:25 +0200 Subject: [PATCH 304/341] docs: updated documentation for the libcloud-plugin --- .../source/TasksAndConcepts/Plugins.rst | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/docs/manuals/source/TasksAndConcepts/Plugins.rst b/docs/manuals/source/TasksAndConcepts/Plugins.rst index c771ab334a4..70e58df31c0 100644 --- a/docs/manuals/source/TasksAndConcepts/Plugins.rst +++ b/docs/manuals/source/TasksAndConcepts/Plugins.rst @@ -1194,6 +1194,8 @@ Requirements To use the Apache Libcloud backend you need to have the Libcloud module available for Python 2. +The plugin needs several options to run properly, the plugin options in the fileset resource and an additional configuration file. Both is described below. + .. _LibcloudPlugin-installation: Installation @@ -1229,6 +1231,24 @@ Configuration The Plugin options string can currently not be split over multiple lines in the configuration file. +The plugin options, separated by a colon: + +module_path + Path to the bareos modules + +module_name=bareos-fd-libcloud + This is the name of the plugin module + +config_file + The plugin needs additional parameters, this is the path to the config file (see below) + +buckets_include + Comma-separated list of buckets to include in backup + +buckets_exclude + Comma-separated list of buckets to exclude from backup + + And the job as follows: .. code-block:: bareosconfig @@ -1240,7 +1260,7 @@ And the job as follows: FileSet = "PluginTest" } -And the config file as follows: +And the plugin config file as follows: .. code-block:: bareosconfig :caption: /etc/bareos/libcloud_config.ini @@ -1258,7 +1278,8 @@ And the config file as follows: [misc] nb_worker=20 queue_size=1000 - prefetch_size=10*1024*1024 + prefetch_size=250*1024*1024 + temporary_download_directory=/dev/shm/bareos_libcloud .. note:: @@ -1295,8 +1316,12 @@ queue_size between the processes prefetch_size - The maximum size in kB for objects to be preloaded from the workers; objects above - this size are loaded by the plugin process itself + The maximum object size in bytes that should be preloaded from the workers; objects + larger than this size are loaded by the plugin process itself + +temporary_download_directory + The local path where the worker processes put their temporarily downloaded files to; + the filedaemon process needs read and write access to this path .. _PerconaXtrabackupPlugin: From e31ded1ed9c7c105412493880a911ab3a05bb152 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 9 Apr 2020 12:59:18 +0200 Subject: [PATCH 305/341] Update Plugins.rst Updated documentation --- docs/manuals/source/TasksAndConcepts/Plugins.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/manuals/source/TasksAndConcepts/Plugins.rst b/docs/manuals/source/TasksAndConcepts/Plugins.rst index 70e58df31c0..acb6d736d19 100644 --- a/docs/manuals/source/TasksAndConcepts/Plugins.rst +++ b/docs/manuals/source/TasksAndConcepts/Plugins.rst @@ -1176,16 +1176,16 @@ Apache Libcloud Plugin .. index:: pair: Plugin; libcloud -The Libcloud plugin can be used to backup objects from backends that support the Simple Storage Service (S3) protocol. The plugin code is based on the work of Alexandre Bruyelles. +The Libcloud plugin can be used to backup objects from cloud storages via the *Simple Storage Service* (**S3**) protocol. The plugin code is based on the work of Alexandre Bruyelles. .. _LibcloudPlugin-status: Status ^^^^^^ -The status of the Libcloud plugin is experimental. It can automatically recurse nested Buckets and backup all included Objects -on a S3 storage. However, restore of Objects cannot be done directly back to the storage. A restore will write these objects -as files on a filesystem. +The status of the Libcloud plugin is **experimental**. It can automatically recurse nested Buckets and backup all included Objects +on a S3 storage. However, **restore of objects cannot be done directly back to the storage**. A restore will write these objects +*as files on a filesystem*. .. _LibcloudPlugin-requirements: From 9de35bc2e91251e942cfdedb9ffab3a9d363da8e Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 9 Apr 2020 14:10:05 +0200 Subject: [PATCH 306/341] bareos-libcloud: removed unneeded files --- ...sFdPluginLocalFilesetWithRestoreObjects.py | 353 ------------------ ...os-fd-local-fileset-with-restoreobjects.py | 59 --- 2 files changed, 412 deletions(-) delete mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py delete mode 100644 systemtests/tests/python-fd-plugin-libcloud-test/python-modules/bareos-fd-local-fileset-with-restoreobjects.py diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py b/systemtests/tests/python-fd-plugin-libcloud-test/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py deleted file mode 100644 index 7a5c2e5e7a4..00000000000 --- a/systemtests/tests/python-fd-plugin-libcloud-test/python-modules/BareosFdPluginLocalFilesetWithRestoreObjects.py +++ /dev/null @@ -1,353 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# BAREOS - Backup Archiving REcovery Open Sourced -# -# Copyright (C) 2014-2019 Bareos GmbH & Co. KG -# -# This program is Free Software; you can redistribute it and/or -# modify it under the terms of version three of the GNU Affero General Public -# License as published by the Free Software Foundation, which is -# listed in the file LICENSE. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# Author: Maik Aussendorf -# -# Bareos python plugins class that adds files from a local list to -# the backup fileset - -import bareosfd -from bareos_fd_consts import bJobMessageType, bFileType, bRCs -import os -import re -import hashlib -import time -import BareosFdPluginBaseclass - - -class BareosFdPluginLocalFilesetWithRestoreObjects( - BareosFdPluginBaseclass.BareosFdPluginBaseclass -): - """ - This Bareos-FD-Plugin-Class was created for automated test purposes only. - It is based on the BareosFdPluginLocalFileset class that parses a file - and backups all files listed there. - Filename is taken from plugin argument 'filename'. - In addition to the file backup and restore, this plugin also tests - restore objects of different sizes. As restore objects are compressed - automatically, when they are greater then 1000 bytes, both uncompressed - and compressed restore objects are tested. - """ - - def __init__(self, context, plugindef): - bareosfd.DebugMessage( - context, - 100, - "Constructor called in module %s with plugindef=%s\n" - % (__name__, plugindef), - ) - # Last argument of super constructor is a list of mandatory arguments - super(BareosFdPluginLocalFilesetWithRestoreObjects, self).__init__( - context, plugindef, ["filename"] - ) - self.files_to_backup = [] - self.allow = None - self.deny = None - self.object_index_seq = int((time.time() - 1546297200) * 10) - self.sha256sums_by_filename = {} - - def filename_is_allowed(self, context, filename, allowregex, denyregex): - """ - Check, if filename is allowed. - True, if matches allowreg and not denyregex. - If allowreg is None, filename always matches - If denyreg is None, it never matches - """ - if allowregex is None or allowregex.search(filename): - allowed = True - else: - allowed = False - if denyregex is None or not denyregex.search(filename): - denied = False - else: - denied = True - if not allowed or denied: - bareosfd.DebugMessage( - context, 100, "File %s denied by configuration\n" % (filename) - ) - bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], - "File %s denied by configuration\n" % (filename), - ) - return False - else: - return True - - def start_backup_job(self, context): - """ - At this point, plugin options were passed and checked already. - We try to read from filename and setup the list of file to backup - in self.files_to_backup - """ - - bareosfd.DebugMessage( - context, - 100, - "Using %s to search for local files\n" % (self.options["filename"]), - ) - if os.path.exists(self.options["filename"]): - try: - config_file = open(self.options["filename"], "rb") - except: - bareosfd.DebugMessage( - context, - 100, - "Could not open file %s\n" % (self.options["filename"]), - ) - return bRCs["bRC_Error"] - else: - bareosfd.DebugMessage( - context, 100, "File %s does not exist\n" % (self.options["filename"]) - ) - return bRCs["bRC_Error"] - # Check, if we have allow or deny regular expressions defined - if "allow" in self.options: - self.allow = re.compile(self.options["allow"]) - if "deny" in self.options: - self.deny = re.compile(self.options["deny"]) - - for listItem in config_file.read().splitlines(): - if os.path.isfile(listItem) and self.filename_is_allowed( - context, listItem, self.allow, self.deny - ): - self.files_to_backup.append(listItem) - if os.path.isdir(listItem): - for topdir, dirNames, fileNames in os.walk(listItem): - for fileName in fileNames: - if self.filename_is_allowed( - context, - os.path.join(topdir, fileName), - self.allow, - self.deny, - ): - self.files_to_backup.append(os.path.join(topdir, fileName)) - if os.path.isfile(os.path.join(topdir, fileName)): - self.files_to_backup.append( - os.path.join(topdir, fileName) + ".sha256sum" - ) - self.files_to_backup.append( - os.path.join(topdir, fileName) + ".abspath" - ) - else: - if os.path.isfile(listItem): - self.files_to_backup.append(listItem + ".sha256sum") - self.files_to_backup.append(listItem + ".abspath") - - for longrestoreobject_length in range(998, 1004): - self.files_to_backup.append( - "%s.longrestoreobject" % longrestoreobject_length - ) - - if not self.files_to_backup: - bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], - "No (allowed) files to backup found\n", - ) - return bRCs["bRC_Error"] - else: - return bRCs["bRC_Cancel"] - - def start_backup_file(self, context, savepkt): - """ - Defines the file to backup and creates the savepkt. In this example - only files (no directories) are allowed - """ - bareosfd.DebugMessage(context, 100, "start_backup_file() called\n") - if not self.files_to_backup: - bareosfd.DebugMessage(context, 100, "No files to backup\n") - return bRCs["bRC_Skip"] - - file_to_backup = self.files_to_backup.pop() - bareosfd.DebugMessage(context, 100, "file: " + file_to_backup + "\n") - - statp = bareosfd.StatPacket() - savepkt.statp = statp - - if file_to_backup.endswith(".sha256sum"): - checksum = self.get_sha256sum(context, os.path.splitext(file_to_backup)[0]) - savepkt.type = bFileType["FT_RESTORE_FIRST"] - savepkt.fname = file_to_backup - savepkt.object_name = file_to_backup - savepkt.object = bytearray(checksum) - savepkt.object_len = len(savepkt.object) - savepkt.object_index = self.object_index_seq - self.object_index_seq += 1 - - elif file_to_backup.endswith(".abspath"): - savepkt.type = bFileType["FT_RESTORE_FIRST"] - savepkt.fname = file_to_backup - savepkt.object_name = file_to_backup - savepkt.object = bytearray(os.path.splitext(file_to_backup)[0]) - savepkt.object_len = len(savepkt.object) - savepkt.object_index = self.object_index_seq - self.object_index_seq += 1 - - elif file_to_backup.endswith(".longrestoreobject"): - teststring_length = int(os.path.splitext(file_to_backup)[0]) - savepkt.type = bFileType["FT_RESTORE_FIRST"] - savepkt.fname = file_to_backup - savepkt.object_name = file_to_backup - savepkt.object = bytearray("a" * teststring_length) - savepkt.object_len = len(savepkt.object) - savepkt.object_index = self.object_index_seq - self.object_index_seq += 1 - - else: - savepkt.fname = file_to_backup - savepkt.type = bFileType["FT_REG"] - - bareosfd.JobMessage( - context, - bJobMessageType["M_INFO"], - "Starting backup of %s\n" % (file_to_backup), - ) - return bRCs["bRC_OK"] - - def end_backup_file(self, context): - """ - Here we return 'bRC_More' as long as our list files_to_backup is not - empty and bRC_OK when we are done - """ - bareosfd.DebugMessage( - context, 100, "end_backup_file() entry point in Python called\n" - ) - if self.files_to_backup: - return bRCs["bRC_More"] - else: - return bRCs["bRC_OK"] - - def set_file_attributes(self, context, restorepkt): - bareosfd.DebugMessage( - context, - 100, - "set_file_attributes() entry point in Python called with %s\n" - % (str(restorepkt)), - ) - - orig_fname = "/" + os.path.relpath(restorepkt.ofname, restorepkt.where) - restoreobject_sha256sum = self.sha256sums_by_filename[orig_fname] - - file_sha256sum = self.get_sha256sum(context, orig_fname) - bareosfd.DebugMessage( - context, - 100, - "set_file_attributes() orig_fname: %s restoreobject_sha256sum: %s file_sha256sum: %s\n" - % (orig_fname, repr(restoreobject_sha256sum), repr(file_sha256sum)), - ) - if file_sha256sum != restoreobject_sha256sum: - bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], - "bad restoreobject orig_fname: %s restoreobject_sha256sum: %s file_sha256sum: %s\n" - % (orig_fname, repr(restoreobject_sha256sum), repr(file_sha256sum)), - ) - - return bRCs["bRC_OK"] - - def end_restore_file(self, context): - bareosfd.DebugMessage( - context, 100, "end_restore_file() self.FNAME: %s\n" % self.FNAME - ) - return bRCs["bRC_OK"] - - def restore_object_data(self, context, ROP): - """ - Note: - This is called in two cases: - - on diff/inc backup (should be called only once) - - on restore (for every job id being restored) - But at the point in time called, it is not possible - to distinguish which of them it is, because job type - is "I" until the bEventStartBackupJob event - """ - bareosfd.DebugMessage( - context, - 100, - "BareosFdPluginLocalFilesetWithRestoreObjects:restore_object_data() called with ROP:%s\n" - % (ROP), - ) - bareosfd.DebugMessage( - context, - 100, - "ROP.object_name(%s): %s\n" % (type(ROP.object_name), ROP.object_name), - ) - bareosfd.DebugMessage( - context, - 100, - "ROP.plugin_name(%s): %s\n" % (type(ROP.plugin_name), ROP.plugin_name), - ) - bareosfd.DebugMessage( - context, - 100, - "ROP.object_len(%s): %s\n" % (type(ROP.object_len), ROP.object_len), - ) - bareosfd.DebugMessage( - context, - 100, - "ROP.object_full_len(%s): %s\n" - % (type(ROP.object_full_len), ROP.object_full_len), - ) - bareosfd.DebugMessage( - context, 100, "ROP.object(%s): %s\n" % (type(ROP.object), repr(ROP.object)) - ) - orig_filename = os.path.splitext(ROP.object_name)[0] - if ROP.object_name.endswith(".sha256sum"): - self.sha256sums_by_filename[orig_filename] = str(ROP.object) - elif ROP.object_name.endswith(".abspath"): - if str(ROP.object) != orig_filename: - bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], - "bad restoreobject orig_fname: %s restoreobject_fname: %s\n" - % (orig_filename, repr(str(ROP.object))), - ) - elif ROP.object_name.endswith(".longrestoreobject"): - stored_length = int(os.path.splitext(ROP.object_name)[0]) - if str(ROP.object) != "a" * stored_length: - bareosfd.JobMessage( - context, - bJobMessageType["M_ERROR"], - "bad long restoreobject %s does not match stored object\n" - % (ROP.object_name), - ) - else: - bareosfd.DebugMessage( - context, - 100, - "not checking restoreobject: %s\n" % (type(ROP.object_name)), - ) - return bRCs["bRC_OK"] - - def get_sha256sum(self, context, filename): - f = open(filename, "rb") - m = hashlib.sha256() - while True: - d = f.read(8096) - if not d: - break - m.update(d) - f.close() - return m.hexdigest() - - -# vim: ts=4 tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/python-modules/bareos-fd-local-fileset-with-restoreobjects.py b/systemtests/tests/python-fd-plugin-libcloud-test/python-modules/bareos-fd-local-fileset-with-restoreobjects.py deleted file mode 100644 index b64ef29960f..00000000000 --- a/systemtests/tests/python-fd-plugin-libcloud-test/python-modules/bareos-fd-local-fileset-with-restoreobjects.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# BAREOS - Backup Archiving REcovery Open Sourced -# -# Copyright (C) 2014-2014 Bareos GmbH & Co. KG -# -# This program is Free Software; you can redistribute it and/or -# modify it under the terms of version three of the GNU Affero General Public -# License as published by the Free Software Foundation, which is -# listed in the file LICENSE. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# bareos-fd-local-fileset-with-restoreobjects.py is a python Bareos FD Plugin using -# BareosFdPluginLocalFilesetWithRestoreObjects which was made for automated testing -# purposes. -# -# The plugin argument 'filename' is used to read all files listed in that file and -# add it to the fileset -# -# Author: Maik Aussendorf -# - -# Provided by the Bareos FD Python plugin interface -import bareos_fd_consts - -# This module contains the wrapper functions called by the Bareos-FD, the -# functions call the corresponding methods from your plugin class -import BareosFdWrapper - -# from BareosFdWrapper import parse_plugin_definition, handle_plugin_event, start_backup_file, end_backup_file, start_restore_file, end_restore_file, restore_object_data, plugin_io, create_file, check_file, handle_backup_file # noqa -from BareosFdWrapper import * # noqa - -# This module contains the used plugin class -import BareosFdPluginLocalFilesetWithRestoreObjects - - -def load_bareos_plugin(context, plugindef): - """ - This function is called by the Bareos-FD to load the plugin - We use it to instantiate the plugin class - """ - # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that - # holds the plugin class object - BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLocalFilesetWithRestoreObjects.BareosFdPluginLocalFilesetWithRestoreObjects( - context, plugindef - ) - return bareos_fd_consts.bRCs["bRC_OK"] - - -# the rest is done in the Plugin module From 3a25131923524f428b4c22ce36a3da9b146514da Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 9 Apr 2020 14:16:21 +0200 Subject: [PATCH 307/341] libcloud-plugin: add copyright notes --- .../plugins/filed/BareosFdPluginLibcloud.py | 5 +++-- .../bareos_libcloud_api/bucket_explorer.py | 19 +++++++++++++++++++ .../filed/bareos_libcloud_api/debug.py | 19 +++++++++++++++++++ .../get_libcloud_driver.py | 19 +++++++++++++++++++ .../filed/bareos_libcloud_api/mtime.py | 19 +++++++++++++++++++ .../filed/bareos_libcloud_api/process_base.py | 19 +++++++++++++++++++ .../bareos_libcloud_api/queue_message.py | 19 +++++++++++++++++++ .../filed/bareos_libcloud_api/worker.py | 19 +++++++++++++++++++ 8 files changed, 136 insertions(+), 2 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 660c9f189ae..c463a25acee 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -1,5 +1,6 @@ -#!/usr/bin/python +#!/usr/bin/env python # -*- coding: utf-8 -*- +# Copyright (C) 2020-2020 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -16,7 +17,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. # -# Author: Alexandre Bruyelles +# Original Author: Alexandre Bruyelles # import BareosFdPluginBaseclass diff --git a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py index c68826c3271..ac241527929 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py +++ b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py @@ -1,3 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2020-2020 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation, which is +# listed in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + from bareos_libcloud_api.process_base import ProcessBase from bareos_libcloud_api.get_libcloud_driver import get_driver from bareos_libcloud_api.mtime import ModificationTime diff --git a/core/src/plugins/filed/bareos_libcloud_api/debug.py b/core/src/plugins/filed/bareos_libcloud_api/debug.py index a6237d5ee4d..313d3413b62 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/debug.py +++ b/core/src/plugins/filed/bareos_libcloud_api/debug.py @@ -1,3 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2020-2020 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation, which is +# listed in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + import os import bareosfd from bareos_fd_consts import bJobMessageType diff --git a/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py b/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py index 11434ddb3ea..be9201bbddc 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py +++ b/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py @@ -1,3 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2020-2020 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation, which is +# listed in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + import ctypes import libcloud from multiprocessing.sharedctypes import RawArray diff --git a/core/src/plugins/filed/bareos_libcloud_api/mtime.py b/core/src/plugins/filed/bareos_libcloud_api/mtime.py index c3a8341ae2e..6e390bb8aaa 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/mtime.py +++ b/core/src/plugins/filed/bareos_libcloud_api/mtime.py @@ -1,3 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2020-2020 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation, which is +# listed in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + import time import dateutil import dateutil.parser diff --git a/core/src/plugins/filed/bareos_libcloud_api/process_base.py b/core/src/plugins/filed/bareos_libcloud_api/process_base.py index 85d60725c0a..784768b98f6 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/process_base.py +++ b/core/src/plugins/filed/bareos_libcloud_api/process_base.py @@ -1,3 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2020-2020 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation, which is +# listed in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + from multiprocessing import Process, Queue, Event from time import sleep from bareos_libcloud_api.queue_message import InfoMessage diff --git a/core/src/plugins/filed/bareos_libcloud_api/queue_message.py b/core/src/plugins/filed/bareos_libcloud_api/queue_message.py index dcf6e480501..e0086caa5d4 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/queue_message.py +++ b/core/src/plugins/filed/bareos_libcloud_api/queue_message.py @@ -1,3 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2020-2020 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation, which is +# listed in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + class MESSAGE_TYPE(object): InfoMessage = 1 ErrorMessage = 2 diff --git a/core/src/plugins/filed/bareos_libcloud_api/worker.py b/core/src/plugins/filed/bareos_libcloud_api/worker.py index 5d7dd83a018..b54c475fce8 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/worker.py +++ b/core/src/plugins/filed/bareos_libcloud_api/worker.py @@ -1,3 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2020-2020 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation, which is +# listed in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + from bareos_libcloud_api.bucket_explorer import JOB_TYPE from bareos_libcloud_api.process_base import ProcessBase from bareos_libcloud_api.get_libcloud_driver import get_driver From 429e3f9cbacb34dbddb511bf903f6670a3e95d67 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 9 Apr 2020 14:22:27 +0200 Subject: [PATCH 308/341] liblcoud-plugin: reword comments and debugmessages --- core/src/plugins/filed/BareosFdPluginLibcloud.py | 12 ++++++------ .../filed/bareos_libcloud_api/bucket_explorer.py | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index c463a25acee..2e9bd3ef8b3 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -105,7 +105,7 @@ def __parse_options(self, context): self.options["accurate"] = True def parse_plugin_definition(self, context, plugindef): - debugmessage(100, "Parse Plugin Definition") + debugmessage(100, "parse_plugin_definition()") config_filename = self.options.get("config_file") if config_filename: if self.__parse_config_file(context, config_filename): @@ -130,7 +130,7 @@ def __parse_config_file(self, context, config_filename): except (IOError, OSError) as err: debugmessage( 100, - "BareosFdPluginLibcloud: Error reading config file %s: %s\n" + "Error reading config file %s: %s\n" % (self.options["config_file"], err.strerror), ) return False @@ -228,7 +228,7 @@ def start_backup_job(self, context): debugmessage(100, "BareosLibcloudApi started") except Exception as e: debugmessage(100, "Error: %s" % e) - jobmessage("M_FATAL", "Something went wrong with BareosLibcloudApi: %s" % e) + jobmessage("M_FATAL", "Starting BareosLibcloudApi failed: %s" % e) return bRCs["bRC_Cancel"] return bRCs["bRC_OK"] @@ -240,7 +240,7 @@ def end_backup_job(self, context): def check_file(self, context, fname): # All existing files/objects are passed to bareos - # If bareos have not seen one, it does not exists anymore + # If bareos has not seen one, it does not exists anymore return bRCs["bRC_Error"] def __shutdown(self): @@ -310,7 +310,7 @@ def start_backup_file(self, context, savepkt): except ObjectDoesNotExistError: jobmessage( "M_WARNING", - "Skipped file %s because it does not exist" + "Skipped file %s because it does not exist anymore" % (self.current_backup_job["name"]), ) return bRCs["bRC_Skip"] @@ -327,7 +327,7 @@ def create_file(self, context, restorepkt): dirname = os.path.dirname(FNAME) if not os.path.exists(dirname): jobmessage( - "M_INFO", "Directory %s does not exist, creating it now\n" % dirname + "M_INFO", "Directory %s does not exist, creating it\n" % dirname ) os.makedirs(dirname) if restorepkt.type == bFileType["FT_REG"]: diff --git a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py index ac241527929..57f97f394ab 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py +++ b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py @@ -71,7 +71,7 @@ def run_process(self): if not self.shutdown_event.is_set(): self.__iterate_over_buckets() except Exception: - self.error_message("Error while iterating containers") + self.error_message("Error while iterating buckets") self.abort_message() for _ in range(self.number_of_workers): @@ -122,8 +122,8 @@ def __generate_jobs_for_bucket_objects(self, object_iterator): ) # This object was present on our last backup - # Here, we push it directly to bareos, it will not be backed again - # but remembered as "still here" (for accurate mode) + # Here, we push it directly to bareos, it will not be backed up + # again but remembered as "still here" (for accurate mode) # If accurate mode is off, we can simply skip that object if self.options["accurate"] is True: self.queue_try_put(self.discovered_objects_queue, job) From 772c6d57599839813bc72f554a7f18cd24c45165 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 9 Apr 2020 14:24:56 +0200 Subject: [PATCH 309/341] libcloud-plugin: use distutils.util.strtobool instead of own method --- core/src/plugins/filed/BareosFdPluginLibcloud.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 2e9bd3ef8b3..758af017b81 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -44,6 +44,7 @@ from libcloud.storage.types import Provider from libcloud.storage.types import ObjectDoesNotExistError from sys import version_info +from distutils.util import strtobool class FilenameConverter: @@ -58,14 +59,6 @@ def BackupToBucket(filename): return filename.replace(FilenameConverter.__pathprefix, "") -def str2bool(data): - if data == "false" or data == "False": - return False - if data == "true" or data == "True": - return True - raise Exception("%s: not a boolean" % (data,)) - - class IterStringIO(io.BufferedIOBase): def __init__(self, iterable): self.iter = itertools.chain.from_iterable(iterable) @@ -179,7 +172,7 @@ def __check_config(self, context, config_filename): try: if option == "tls": - self.options["secure"] = str2bool(value) + self.options["secure"] = strtobool(value) elif option == "nb_worker": self.options["nb_worker"] = int(value) elif option == "queue_size": From 81931fbd7486ebac66c6b9ff4e713580bb0bcd40 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 9 Apr 2020 14:29:47 +0200 Subject: [PATCH 310/341] libcloud-plugin: use an empty filename when skipping at the end of a backup --- core/src/plugins/filed/BareosFdPluginLibcloud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 758af017b81..b558fb2e7ae 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -265,7 +265,7 @@ def start_backup_file(self, context, savepkt): if not self.active: self.__shutdown() - savepkt.fname = "empty" # dummy value + savepkt.fname = "" # dummy value if error: jobmessage("M_FATAL", "Shutdown after worker error") return bRCs["bRC_Cancel"] From 719f8d9c7f930a2832f7050458e5d6dcbb908aca Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 9 Apr 2020 14:33:58 +0200 Subject: [PATCH 311/341] libcloud-plugin: use a very uncommon bucket-name for testing the driver --- .../plugins/filed/bareos_libcloud_api/get_libcloud_driver.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py b/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py index be9201bbddc..704e65382c1 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py +++ b/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py @@ -54,7 +54,8 @@ def get_driver(options): driver = libcloud.storage.providers.get_driver(provider)(**driver_opt) try: - driver.get_container("123invalidname123") + driver.get_container("bareos-libcloud-invalidname-bareos-libcloud") + return driver # success if bucket accidentally matches # success except libcloud.storage.types.ContainerDoesNotExistError: From df70295a5dd1466b118f8ce3b1aeb6bb9f45e963 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 9 Apr 2020 14:56:18 +0200 Subject: [PATCH 312/341] libcloud-plugin: renamed job -> task for downloadable objects --- .../plugins/filed/BareosFdPluginLibcloud.py | 38 +++++++++---------- core/src/plugins/filed/BareosLibcloudApi.py | 14 +++---- .../bareos_libcloud_api/bucket_explorer.py | 10 ++--- .../bareos_libcloud_api/queue_message.py | 20 +++++----- .../filed/bareos_libcloud_api/worker.py | 8 ++-- 5 files changed, 45 insertions(+), 45 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index b558fb2e7ae..c31fe954867 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -26,7 +26,7 @@ import ConfigParser as configparser import datetime import dateutil.parser -from bareos_libcloud_api.bucket_explorer import JOB_TYPE +from bareos_libcloud_api.bucket_explorer import TASK_TYPE from bareos_libcloud_api.debug import debugmessage from bareos_libcloud_api.debug import jobmessage from bareos_libcloud_api.debug import set_plugin_context @@ -81,10 +81,10 @@ def __init__(self, context, plugindef): self.last_run = datetime.datetime.fromtimestamp(self.since) self.last_run = self.last_run.replace(tzinfo=None) - # The backup job in process + # The backup task in process # Set to None when the whole backup is completed # Restore's path will not touch this - self.current_backup_job = {} + self.current_backup_task = {} self.number_of_objects_to_backup = 0 self.FILE = None self.active = True @@ -255,8 +255,8 @@ def start_backup_file(self, context, savepkt): self.active = False error = True else: - self.current_backup_job = self.api.get_next_job() - if self.current_backup_job != None: + self.current_backup_task = self.api.get_next_task() + if self.current_backup_task != None: break elif self.api.worker_ready(): self.active = False @@ -274,13 +274,13 @@ def start_backup_file(self, context, savepkt): filename = FilenameConverter.BucketToBackup( "%s/%s" - % (self.current_backup_job["bucket"], self.current_backup_job["name"],) + % (self.current_backup_task["bucket"], self.current_backup_task["name"],) ) jobmessage("M_INFO", "Backup file: %s" % (filename,)) statp = bareosfd.StatPacket() - statp.size = self.current_backup_job["size"] - statp.mtime = self.current_backup_job["mtime"] + statp.size = self.current_backup_task["size"] + statp.mtime = self.current_backup_task["mtime"] statp.atime = 0 statp.ctime = 0 @@ -288,27 +288,27 @@ def start_backup_file(self, context, savepkt): savepkt.fname = filename savepkt.type = bareos_fd_consts.bFileType["FT_REG"] - if self.current_backup_job["type"] == JOB_TYPE.DOWNLOADED: - self.FILE = self.current_backup_job["data"] - elif self.current_backup_job["type"] == JOB_TYPE.TEMP_FILE: + if self.current_backup_task["type"] == TASK_TYPE.DOWNLOADED: + self.FILE = self.current_backup_task["data"] + elif self.current_backup_task["type"] == TASK_TYPE.TEMP_FILE: try: - self.FILE = io.open(self.current_backup_job["tmpfile"], "rb") + self.FILE = io.open(self.current_backup_task["tmpfile"], "rb") except Exception as e: jobmessage("M_FATAL", "Could not open temporary file for reading." % e) self.__shutdown() return bRCs["bRC_Error"] - elif self.current_backup_job["type"] == JOB_TYPE.STREAM: + elif self.current_backup_task["type"] == TASK_TYPE.STREAM: try: - self.FILE = IterStringIO(self.current_backup_job["data"].as_stream()) + self.FILE = IterStringIO(self.current_backup_task["data"].as_stream()) except ObjectDoesNotExistError: jobmessage( "M_WARNING", "Skipped file %s because it does not exist anymore" - % (self.current_backup_job["name"]), + % (self.current_backup_task["name"]), ) return bRCs["bRC_Skip"] else: - raise Exception(value='Wrong argument for current_backup_job["type"]') + raise Exception(value='Wrong argument for current_backup_task["type"]') return bRCs["bRC_OK"] @@ -328,7 +328,7 @@ def create_file(self, context, restorepkt): return bRCs["bRC_OK"] def plugin_io(self, context, IOP): - if self.current_backup_job is None: + if self.current_backup_task is None: return bRCs["bRC_Error"] if IOP.func == bIOPS["IO_OPEN"]: # Only used by the 'restore' path @@ -350,7 +350,7 @@ def plugin_io(self, context, IOP): jobmessage( "M_ERROR", "Cannot read from %s/%s: %s" - % (self.current_backup_job["bucket"], self.current_backup_job["name"], e), + % (self.current_backup_task["bucket"], self.current_backup_task["name"], e), ) IOP.status = 0 IOP.io_errno = e.errno @@ -373,7 +373,7 @@ def plugin_io(self, context, IOP): return bRCs["bRC_OK"] def end_backup_file(self, context): - if self.current_backup_job is not None: + if self.current_backup_task is not None: self.number_of_objects_to_backup += 1 return bRCs["bRC_More"] else: diff --git a/core/src/plugins/filed/BareosLibcloudApi.py b/core/src/plugins/filed/BareosLibcloudApi.py index 140794f57ba..8924f573575 100644 --- a/core/src/plugins/filed/BareosLibcloudApi.py +++ b/core/src/plugins/filed/BareosLibcloudApi.py @@ -1,5 +1,5 @@ from bareos_libcloud_api.bucket_explorer import BucketExplorer -from bareos_libcloud_api.bucket_explorer import JOB_TYPE +from bareos_libcloud_api.bucket_explorer import TASK_TYPE from bareos_libcloud_api.debug import debugmessage, jobmessage from bareos_libcloud_api.get_libcloud_driver import get_driver from bareos_libcloud_api.get_libcloud_driver import options @@ -78,18 +78,18 @@ def check_worker_messages(self): while not self.message_queue.empty(): try: message = self.message_queue.get_nowait() - if message.type == MESSAGE_TYPE.InfoMessage: + if message.type == MESSAGE_TYPE.INFO_MESSAGE: jobmessage("M_INFO", message.message_string) - elif message.type == MESSAGE_TYPE.ErrorMessage: + elif message.type == MESSAGE_TYPE.ERROR_MESSAGE: jobmessage("M_ERROR", message.message_string) - elif message.type == MESSAGE_TYPE.ReadyMessage: + elif message.type == MESSAGE_TYPE.READY_MESSAGE: if message.worker_id == 0: self.count_bucket_explorer_ready += 1 else: self.count_worker_ready += 1 - elif message.type == MESSAGE_TYPE.AbortMessage: + elif message.type == MESSAGE_TYPE.ABORT_MESSAGE: return ERROR - elif message.type == MESSAGE_TYPE.DebugMessage: + elif message.type == MESSAGE_TYPE.DEBUG_MESSAGE: debugmessage(message.level, message.message_string) else: raise Exception(value="Unknown message type") @@ -97,7 +97,7 @@ def check_worker_messages(self): jobmessage("M_INFO", "check_worker_messages exception: %s" % e) return SUCCESS - def get_next_job(self): + def get_next_task(self): if not self.downloaded_objects_queue.empty(): return self.downloaded_objects_queue.get_nowait() return None diff --git a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py index 57f97f394ab..f506cd272ea 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py +++ b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py @@ -22,7 +22,7 @@ from bareos_libcloud_api.mtime import ModificationTime -class JOB_TYPE(object): +class TASK_TYPE(object): UNDEFINED = 0 DOWNLOADED = 1 TEMP_FILE = 2 @@ -103,14 +103,14 @@ def __generate_jobs_for_bucket_objects(self, object_iterator): mtime, mtime_ts = ModificationTime().get_mtime(obj) - job = { + task = { "name": obj.name, "bucket": obj.container.name, "data": None, "index": None, "size": obj.size, "mtime": mtime_ts, - "type": JOB_TYPE.UNDEFINED, + "type": TASK_TYPE.UNDEFINED, } object_name = "%s/%s" % (obj.container.name, obj.name) @@ -126,7 +126,7 @@ def __generate_jobs_for_bucket_objects(self, object_iterator): # again but remembered as "still here" (for accurate mode) # If accurate mode is off, we can simply skip that object if self.options["accurate"] is True: - self.queue_try_put(self.discovered_objects_queue, job) + self.queue_try_put(self.discovered_objects_queue, task) continue @@ -135,4 +135,4 @@ def __generate_jobs_for_bucket_objects(self, object_iterator): % (object_name, self.last_run, mtime), ) - self.queue_try_put(self.discovered_objects_queue, job) + self.queue_try_put(self.discovered_objects_queue, task) diff --git a/core/src/plugins/filed/bareos_libcloud_api/queue_message.py b/core/src/plugins/filed/bareos_libcloud_api/queue_message.py index e0086caa5d4..e8976cf78fe 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/queue_message.py +++ b/core/src/plugins/filed/bareos_libcloud_api/queue_message.py @@ -18,11 +18,11 @@ # 02110-1301, USA. class MESSAGE_TYPE(object): - InfoMessage = 1 - ErrorMessage = 2 - AbortMessage = 3 - ReadyMessage = 4 - DebugMessage = 5 + INFO_MESSAGE = 1 + ERROR_MESSAGE = 2 + ABORT_MESSAGE = 3 + READY_MESSAGE = 4 + DEBUG_MESSAGE = 5 def __setattr__(self, *_): raise Exception("class MESSAGE_TYPE is read only") @@ -38,29 +38,29 @@ def __init__(self, worker_id, message): class ErrorMessage(QueueMessageBase): def __init__(self, worker_id, message): QueueMessageBase.__init__(self, worker_id, message) - self.type = MESSAGE_TYPE.ErrorMessage + self.type = MESSAGE_TYPE.ERROR_MESSAGE class InfoMessage(QueueMessageBase): def __init__(self, worker_id, message): QueueMessageBase.__init__(self, worker_id, message) - self.type = MESSAGE_TYPE.InfoMessage + self.type = MESSAGE_TYPE.INFO_MESSAGE class DebugMessage(QueueMessageBase): def __init__(self, worker_id, level, message): QueueMessageBase.__init__(self, worker_id, message) - self.type = MESSAGE_TYPE.DebugMessage + self.type = MESSAGE_TYPE.DEBUG_MESSAGE self.level = level class ReadyMessage(QueueMessageBase): def __init__(self, worker_id, message=None): QueueMessageBase.__init__(self, worker_id, message) - self.type = MESSAGE_TYPE.ReadyMessage + self.type = MESSAGE_TYPE.READY_MESSAGE class AbortMessage(QueueMessageBase): def __init__(self, worker_id): QueueMessageBase.__init__(self, worker_id, None) - self.type = MESSAGE_TYPE.AbortMessage + self.type = MESSAGE_TYPE.ABORT_MESSAGE diff --git a/core/src/plugins/filed/bareos_libcloud_api/worker.py b/core/src/plugins/filed/bareos_libcloud_api/worker.py index b54c475fce8..d89876eb60c 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/worker.py +++ b/core/src/plugins/filed/bareos_libcloud_api/worker.py @@ -17,7 +17,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. -from bareos_libcloud_api.bucket_explorer import JOB_TYPE +from bareos_libcloud_api.bucket_explorer import TASK_TYPE from bareos_libcloud_api.process_base import ProcessBase from bareos_libcloud_api.get_libcloud_driver import get_driver import io @@ -95,7 +95,7 @@ def __run_job(self, job): return CONTINUE job["data"] = io.BytesIO(content) - job["type"] = JOB_TYPE.DOWNLOADED + job["type"] = TASK_TYPE.DOWNLOADED except LibcloudError: self.error_message("Libcloud error, could not download file") return CONTINUE @@ -108,7 +108,7 @@ def __run_job(self, job): obj.download(tmpfilename) job["data"] = None job["tmpfile"] = tmpfilename - job["type"] = JOB_TYPE.TEMP_FILE + job["type"] = TASK_TYPE.TEMP_FILE except OSError as e: self.error_message("Could not open temporary file %s" % e.filename) return FINISH @@ -132,7 +132,7 @@ def __run_job(self, job): else: try: job["data"] = obj - job["type"] = JOB_TYPE.STREAM + job["type"] = TASK_TYPE.STREAM except LibcloudError: self.error_message( "Libcloud error preparing stream object, skipping: %s/%s" From 5d30c3496faaa6e05be7e6ae2e79c46313e8518a Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 17 Apr 2020 12:55:17 +0200 Subject: [PATCH 313/341] debian: libcloud-plugin: package also subdir @plugindir@/bareos_libcloud_api --- .../debian/bareos-filedaemon-libcloud-python-plugin.install.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/debian/bareos-filedaemon-libcloud-python-plugin.install.in b/core/debian/bareos-filedaemon-libcloud-python-plugin.install.in index e48f58a8353..03ba334f12d 100644 --- a/core/debian/bareos-filedaemon-libcloud-python-plugin.install.in +++ b/core/debian/bareos-filedaemon-libcloud-python-plugin.install.in @@ -1,2 +1,5 @@ @plugindir@/bareos-fd-libcloud.py* @plugindir@/BareosFdPluginLibcloud.py* +@plugindir@/BareosLibcloudApi.py +@plugindir@/bareos_libcloud_api +@plugindir@/bareos_libcloud_api/* From 20b223a5c07d0fc64be98f8128dea9180198503e Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 30 Apr 2020 13:11:03 +0200 Subject: [PATCH 314/341] libcloud-plugin: add more debugging output --- core/src/plugins/filed/BareosFdPluginLibcloud.py | 9 ++++++--- core/src/plugins/filed/BareosLibcloudApi.py | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index c31fe954867..b1d245c7f6e 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -244,9 +244,12 @@ def __shutdown(self): % (self.number_of_objects_to_backup) ) - debugmessage(100, "Shut down BareosLibcloudApi") - self.api.shutdown() - debugmessage(100, "BareosLibcloudApi is shut down") + if self.api == None: + debugmessage(100, "BareosLibcloudApi did not initialize properly") + else: + debugmessage(100, "Shut down BareosLibcloudApi") + self.api.shutdown() + debugmessage(100, "BareosLibcloudApi is shut down") def start_backup_file(self, context, savepkt): error = False diff --git a/core/src/plugins/filed/BareosLibcloudApi.py b/core/src/plugins/filed/BareosLibcloudApi.py index 8924f573575..933ad0638a6 100644 --- a/core/src/plugins/filed/BareosLibcloudApi.py +++ b/core/src/plugins/filed/BareosLibcloudApi.py @@ -43,6 +43,8 @@ def __init__(self, options, last_run, tmp_dir_path): self.__create_tmp_dir() + jobmessage("M_INFO", "Initialize BucketExplorer") + self.bucket_explorer = BucketExplorer( options, last_run, @@ -51,6 +53,8 @@ def __init__(self, options, last_run, tmp_dir_path): self.number_of_worker, ) + jobmessage("M_INFO", "Initialize %d Workers" % self.number_of_worker) + self.worker = [ Worker( options, @@ -63,8 +67,10 @@ def __init__(self, options, last_run, tmp_dir_path): for i in range(self.number_of_worker) ] + jobmessage("M_INFO", "Start BucketExplorer") self.bucket_explorer.start() + jobmessage("M_INFO", "Start Workers") for w in self.worker: w.start() @@ -150,9 +156,11 @@ def __create_tmp_dir(self): self.__remove_tmp_dir() except: pass + jobmessage("M_INFO", "Try to create temporary directory: %s" % (self.tmp_dir_path)) os.mkdir(self.tmp_dir_path) def __remove_tmp_dir(self): + jobmessage("M_INFO", "Try to remove old files from: %s" % (self.tmp_dir_path)) try: files = glob.glob(self.tmp_dir_path + "/*") for f in files: From 2efadbe285982e5826a1ff816124f62ea3ebbacb Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Fri, 22 May 2020 11:55:15 +0200 Subject: [PATCH 315/341] libcloud-plugin: correct some python attribute errors --- core/src/plugins/filed/BareosFdPluginLibcloud.py | 3 +-- .../plugins/filed/bareos_libcloud_api/get_libcloud_driver.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index b1d245c7f6e..b0471e539c5 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -88,6 +88,7 @@ def __init__(self, context, plugindef): self.number_of_objects_to_backup = 0 self.FILE = None self.active = True + self.api = None def __parse_options(self, context): accurate = bareos_fd_consts.bVariable["bVarAccurate"] @@ -213,7 +214,6 @@ def start_backup_job(self, context): "Connected, last backup: %s (ts: %s)" % (self.last_run, self.since), ) - self.api = None try: self.api = BareosLibcloudApi( self.options, self.last_run, self.options["temporary_download_directory"] @@ -356,7 +356,6 @@ def plugin_io(self, context, IOP): % (self.current_backup_task["bucket"], self.current_backup_task["name"], e), ) IOP.status = 0 - IOP.io_errno = e.errno return bRCs["bRC_Error"] elif IOP.func == bIOPS["IO_WRITE"]: diff --git a/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py b/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py index 704e65382c1..08b3d849967 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py +++ b/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py @@ -72,7 +72,7 @@ def get_driver(options): pass print( - "Could not connect to libcloud driver: %s:%d" + "Could not connect to libcloud driver: %s:%s" % (driver_opt["host"], driver_opt["port"]) ) From 154487e9ab45835c2abb37937edd4fe3be216a46 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Fri, 19 Jun 2020 17:14:55 +0200 Subject: [PATCH 316/341] libcloud-plugin: create a separate tmp-directory for each instance --- core/src/plugins/filed/BareosLibcloudApi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/plugins/filed/BareosLibcloudApi.py b/core/src/plugins/filed/BareosLibcloudApi.py index 933ad0638a6..fb900dbcf71 100644 --- a/core/src/plugins/filed/BareosLibcloudApi.py +++ b/core/src/plugins/filed/BareosLibcloudApi.py @@ -30,7 +30,7 @@ def probe_driver(options): return "failed" def __init__(self, options, last_run, tmp_dir_path): - self.tmp_dir_path = tmp_dir_path + self.tmp_dir_path = tmp_dir_path + "/" + str(uuid.uuid4()) self.count_worker_ready = 0 self.count_bucket_explorer_ready = 0 @@ -157,7 +157,7 @@ def __create_tmp_dir(self): except: pass jobmessage("M_INFO", "Try to create temporary directory: %s" % (self.tmp_dir_path)) - os.mkdir(self.tmp_dir_path) + os.makedirs(self.tmp_dir_path) def __remove_tmp_dir(self): jobmessage("M_INFO", "Try to remove old files from: %s" % (self.tmp_dir_path)) From 73ca91f7b643c56f4188a1a643b4a86006298499 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Fri, 19 Jun 2020 23:14:41 +0200 Subject: [PATCH 317/341] libcloud-plugin: remove temporary files immediately - put more debugging info - apply black to all py files --- .../plugins/filed/BareosFdPluginLibcloud.py | 39 +++++++++++++++---- core/src/plugins/filed/BareosLibcloudApi.py | 23 +++++++---- .../bareos_libcloud_api/bucket_explorer.py | 6 ++- .../get_libcloud_driver.py | 2 +- .../bareos_libcloud_api/queue_message.py | 1 + .../filed/bareos_libcloud_api/worker.py | 15 +++++++ 6 files changed, 68 insertions(+), 18 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index b0471e539c5..204f14632be 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -140,7 +140,12 @@ def __check_config(self, context, config_filename): mandatory_options = {} mandatory_options["credentials"] = ["username", "password"] mandatory_options["host"] = ["hostname", "port", "provider", "tls"] - mandatory_options["misc"] = ["nb_worker", "queue_size", "prefetch_size", "temporary_download_directory"] + mandatory_options["misc"] = [ + "nb_worker", + "queue_size", + "prefetch_size", + "temporary_download_directory", + ] # this maps config file options to libcloud options option_map = { @@ -216,7 +221,9 @@ def start_backup_job(self, context): try: self.api = BareosLibcloudApi( - self.options, self.last_run, self.options["temporary_download_directory"] + self.options, + self.last_run, + self.options["temporary_download_directory"], ) debugmessage(100, "BareosLibcloudApi started") except Exception as e: @@ -241,7 +248,7 @@ def __shutdown(self): jobmessage( "M_INFO", "BareosFdPluginLibcloud finished with %d files" - % (self.number_of_objects_to_backup) + % (self.number_of_objects_to_backup), ) if self.api == None: @@ -279,7 +286,7 @@ def start_backup_file(self, context, savepkt): "%s/%s" % (self.current_backup_task["bucket"], self.current_backup_task["name"],) ) - jobmessage("M_INFO", "Backup file: %s" % (filename,)) + debugmessage(100, "Backup file: %s" % (filename,)) statp = bareosfd.StatPacket() statp.size = self.current_backup_task["size"] @@ -322,9 +329,7 @@ def create_file(self, context, restorepkt): FNAME = FilenameConverter.BackupToBucket(restorepkt.ofname) dirname = os.path.dirname(FNAME) if not os.path.exists(dirname): - jobmessage( - "M_INFO", "Directory %s does not exist, creating it\n" % dirname - ) + jobmessage("M_INFO", "Directory %s does not exist, creating it\n" % dirname) os.makedirs(dirname) if restorepkt.type == bFileType["FT_REG"]: restorepkt.create_status = bCFs["CF_EXTRACT"] @@ -353,7 +358,11 @@ def plugin_io(self, context, IOP): jobmessage( "M_ERROR", "Cannot read from %s/%s: %s" - % (self.current_backup_task["bucket"], self.current_backup_task["name"], e), + % ( + self.current_backup_task["bucket"], + self.current_backup_task["name"], + e, + ), ) IOP.status = 0 return bRCs["bRC_Error"] @@ -370,6 +379,20 @@ def plugin_io(self, context, IOP): elif IOP.func == bIOPS["IO_CLOSE"]: if self.FILE: self.FILE.close() + if self.current_backup_task["type"] == TASK_TYPE.TEMP_FILE: + debugmessage( + 110, + "Removing temporary file: %s" + % (self.current_backup_task["tmpfile"]), + ) + try: + os.remove(self.current_backup_task["tmpfile"]) + except: + debugmessage( + 110, + "Could not remove temporary file: %s" + % (self.current_backup_task["tmpfile"]), + ) return bRCs["bRC_OK"] return bRCs["bRC_OK"] diff --git a/core/src/plugins/filed/BareosLibcloudApi.py b/core/src/plugins/filed/BareosLibcloudApi.py index fb900dbcf71..712f316eaf3 100644 --- a/core/src/plugins/filed/BareosLibcloudApi.py +++ b/core/src/plugins/filed/BareosLibcloudApi.py @@ -149,23 +149,32 @@ def shutdown(self): except: pass - jobmessage("M_INFO", "Shutdown of worker processes is ready") + jobmessage("M_INFO", "Finished shutdown of worker processes") def __create_tmp_dir(self): - try: - self.__remove_tmp_dir() - except: - pass - jobmessage("M_INFO", "Try to create temporary directory: %s" % (self.tmp_dir_path)) + debugmessage(100, "Try to create temporary directory: %s" % (self.tmp_dir_path)) os.makedirs(self.tmp_dir_path) + debugmessage(100, "Created temporary directory: %s" % (self.tmp_dir_path)) def __remove_tmp_dir(self): - jobmessage("M_INFO", "Try to remove old files from: %s" % (self.tmp_dir_path)) + debugmessage(100, "Try to remove leftover files from: %s" % (self.tmp_dir_path)) try: files = glob.glob(self.tmp_dir_path + "/*") + cnt = 0 for f in files: os.remove(f) + cnt += 1 + if cnt != 0: + debugmessage( + 100, + "Removed %d leftover files from: %s" % (cnt, self.tmp_dir_path), + ) + else: + debugmessage( + 100, "No leftover files to remove from: %s" % (self.tmp_dir_path), + ) os.rmdir(self.tmp_dir_path) + debugmessage(100, "Removed temporary directory: %s" % (self.tmp_dir_path)) except: pass diff --git a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py index f506cd272ea..afdcf8737be 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py +++ b/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py @@ -116,7 +116,8 @@ def __generate_jobs_for_bucket_objects(self, object_iterator): object_name = "%s/%s" % (obj.container.name, obj.name) if self.last_run > mtime: - self.info_message( + self.debug_message( + 100, "File %s not changed, skipped (%s > %s)" % (object_name, self.last_run, mtime), ) @@ -130,7 +131,8 @@ def __generate_jobs_for_bucket_objects(self, object_iterator): continue - self.info_message( + self.debug_message( + 100, "File %s was changed or is new, put to queue (%s < %s)" % (object_name, self.last_run, mtime), ) diff --git a/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py b/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py index 08b3d849967..8c381f2c258 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py +++ b/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py @@ -55,7 +55,7 @@ def get_driver(options): try: driver.get_container("bareos-libcloud-invalidname-bareos-libcloud") - return driver # success if bucket accidentally matches + return driver # success if bucket accidentally matches # success except libcloud.storage.types.ContainerDoesNotExistError: diff --git a/core/src/plugins/filed/bareos_libcloud_api/queue_message.py b/core/src/plugins/filed/bareos_libcloud_api/queue_message.py index e8976cf78fe..9190fe37325 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/queue_message.py +++ b/core/src/plugins/filed/bareos_libcloud_api/queue_message.py @@ -17,6 +17,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. + class MESSAGE_TYPE(object): INFO_MESSAGE = 1 ERROR_MESSAGE = 2 diff --git a/core/src/plugins/filed/bareos_libcloud_api/worker.py b/core/src/plugins/filed/bareos_libcloud_api/worker.py index d89876eb60c..224f04b70db 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/worker.py +++ b/core/src/plugins/filed/bareos_libcloud_api/worker.py @@ -83,6 +83,11 @@ def __run_job(self, job): if job["size"] < 1024 * 10: try: + self.debug_message( + 110, + "%3d: Put complete file %s into queue" + % (self.worker_id, job["bucket"] + job["name"]), + ) stream = obj.as_stream() content = b"".join(list(stream)) @@ -104,6 +109,11 @@ def __run_job(self, job): return CONTINUE elif job["size"] < self.options["prefetch_size"]: try: + self.debug_message( + 110, + "%3d: Prefetch file %s" + % (self.worker_id, job["bucket"] + job["name"]), + ) tmpfilename = self.tmp_dir_path + "/" + str(uuid.uuid4()) obj.download(tmpfilename) job["data"] = None @@ -131,6 +141,11 @@ def __run_job(self, job): return CONTINUE else: try: + self.debug_message( + 110, + "%3d: Prepare file as stream for download %s" + % (self.worker_id, job["bucket"] + job["name"]), + ) job["data"] = obj job["type"] = TASK_TYPE.STREAM except LibcloudError: From 20de4dc0fc47517c2305425e6b723aaaa3762b9b Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 9 Jul 2020 18:16:12 +0200 Subject: [PATCH 318/341] libcloud-plugin: check if dict is not empty before access --- .../plugins/filed/BareosFdPluginLibcloud.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 204f14632be..be089119f53 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -379,20 +379,21 @@ def plugin_io(self, context, IOP): elif IOP.func == bIOPS["IO_CLOSE"]: if self.FILE: self.FILE.close() - if self.current_backup_task["type"] == TASK_TYPE.TEMP_FILE: - debugmessage( - 110, - "Removing temporary file: %s" - % (self.current_backup_task["tmpfile"]), - ) - try: - os.remove(self.current_backup_task["tmpfile"]) - except: + if "type" in self.current_backup_task: + if self.current_backup_task["type"] == TASK_TYPE.TEMP_FILE: debugmessage( 110, - "Could not remove temporary file: %s" + "Removing temporary file: %s" % (self.current_backup_task["tmpfile"]), ) + try: + os.remove(self.current_backup_task["tmpfile"]) + except: + debugmessage( + 110, + "Could not remove temporary file: %s" + % (self.current_backup_task["tmpfile"]), + ) return bRCs["bRC_OK"] return bRCs["bRC_OK"] From 6ff9312b620b44605514632c55e75e5568ae4c33 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Fri, 10 Jul 2020 18:15:41 +0200 Subject: [PATCH 319/341] libcloud-plugin: remove needless parameter --- core/src/plugins/filed/BareosFdPluginLibcloud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index be089119f53..3df02ec069e 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -304,7 +304,7 @@ def start_backup_file(self, context, savepkt): try: self.FILE = io.open(self.current_backup_task["tmpfile"], "rb") except Exception as e: - jobmessage("M_FATAL", "Could not open temporary file for reading." % e) + jobmessage("M_FATAL", "Could not open temporary file for reading.") self.__shutdown() return bRCs["bRC_Error"] elif self.current_backup_task["type"] == TASK_TYPE.STREAM: From 3a1b93d538592854ae0aed931e2a899c166669e8 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 16 Jul 2020 15:14:08 +0200 Subject: [PATCH 320/341] systemtests: use bucket name bareos-test for libcloud tests --- .../etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in | 2 +- .../tests/python-fd-plugin-libcloud-test/testrunner | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in index 7f00193980a..3a6bf166604 100644 --- a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in +++ b/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in @@ -5,6 +5,6 @@ FileSet { Options { signature = MD5 } - Plugin = "python:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-libcloud:config_file=etc/libcloud_config.ini:buckets_include=test" + Plugin = "python:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-libcloud:config_file=etc/libcloud_config.ini:buckets_include=bareos-test" } } diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/testrunner b/systemtests/tests/python-fd-plugin-libcloud-test/testrunner index 8f586494af2..aa6a826c99e 100755 --- a/systemtests/tests/python-fd-plugin-libcloud-test/testrunner +++ b/systemtests/tests/python-fd-plugin-libcloud-test/testrunner @@ -12,6 +12,7 @@ # TestName="$(basename "$(pwd)")" export TestName +bucket_name=bareos-test JobName=backup-bareos-fd #shellcheck source=../environment.in @@ -36,13 +37,13 @@ BackupDirectory="${tmp}/data" setup_data "$@" # create s3 content for test -${S3} rb --recursive --force s3://test || echo "s3://test does not exist" -${S3} mb s3://test +${S3} rb --recursive --force s3://$bucket_name || echo "s3://$bucket_name does not exist" +${S3} mb s3://$bucket_name # this test does not work with links because of the restore objects rm -r "${tmp}"/data/weird-files >/dev/null 2>&1 -${S3} sync "$BackupDirectory" s3://test +${S3} sync "$BackupDirectory" s3://$bucket_name start_test @@ -80,7 +81,7 @@ list=( $(find "${BackupDirectory}" -type f) ) # to don'"t diff the file attributes, because they are not saved #check_restore_only_files_diff "${list[@]}" -if ! diff -r tmp/data tmp/bareos-restores/test/data; then +if ! diff -r tmp/data tmp/bareos-restores/$bucket_name/data; then export estat=1 fi From 8004383d9970a691f28ef302a7d09a803780a9bd Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Fri, 17 Jul 2020 11:09:23 +0200 Subject: [PATCH 321/341] libcloud-plugin: add optional argument treat_download_errors_as_warnings --- .../plugins/filed/BareosFdPluginLibcloud.py | 52 ++++++++++++++++--- core/src/plugins/filed/BareosLibcloudApi.py | 4 +- .../filed/bareos_libcloud_api/process_base.py | 1 + .../filed/bareos_libcloud_api/worker.py | 1 + .../source/TasksAndConcepts/Plugins.rst | 12 ++++- 5 files changed, 59 insertions(+), 11 deletions(-) diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/BareosFdPluginLibcloud.py index 3df02ec069e..d4117dc1a34 100755 --- a/core/src/plugins/filed/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/BareosFdPluginLibcloud.py @@ -39,6 +39,7 @@ from BareosLibcloudApi import SUCCESS from BareosLibcloudApi import ERROR +from BareosLibcloudApi import ABORT from BareosLibcloudApi import BareosLibcloudApi from bareos_fd_consts import bRCs, bCFs, bIOPS, bJobMessageType, bFileType from libcloud.storage.types import Provider @@ -76,6 +77,7 @@ def __init__(self, context, plugindef): super(BareosFdPluginLibcloud, self).__init__(context, plugindef) super(BareosFdPluginLibcloud, self).parse_plugin_definition(context, plugindef) + self.options["treat_download_errors_as_warnings"] = False self.__parse_options(context) self.last_run = datetime.datetime.fromtimestamp(self.since) @@ -146,6 +148,8 @@ def __check_config(self, context, config_filename): "prefetch_size", "temporary_download_directory", ] + optional_options = {} + optional_options["misc"] = ["treat_download_errors_as_warnings"] # this maps config file options to libcloud options option_map = { @@ -197,6 +201,19 @@ def __check_config(self, context, config_filename): ) return False + for option in optional_options["misc"]: + if self.config.has_option(section, option): + try: + value = self.config.get(section, option) + self.options["treat_download_errors_as_warnings"] = strtobool(value) + except: + debugmessage( + 100, + "Could not evaluate: %s in config file %s" + % (value, config_filename), + ) + return False + return True def start_backup_job(self, context): @@ -261,7 +278,14 @@ def __shutdown(self): def start_backup_file(self, context, savepkt): error = False while self.active: - if self.api.check_worker_messages() != SUCCESS: + worker_result = self.api.check_worker_messages() + if worker_result == ERROR: + if self.options["treat_download_errors_as_warnings"]: + pass + else: + self.active = False + error = True + elif worker_result == ABORT: self.active = False error = True else: @@ -311,12 +335,21 @@ def start_backup_file(self, context, savepkt): try: self.FILE = IterStringIO(self.current_backup_task["data"].as_stream()) except ObjectDoesNotExistError: - jobmessage( - "M_WARNING", - "Skipped file %s because it does not exist anymore" - % (self.current_backup_task["name"]), - ) - return bRCs["bRC_Skip"] + if self.options["treat_download_errors_as_warnings"]: + jobmessage( + "M_WARNING", + "Skipped file %s because it does not exist anymore" + % (self.current_backup_task["name"]), + ) + return bRCs["bRC_Skip"] + else: + jobmessage( + "M_ERROR", + "File %s does not exist anymore" + % (self.current_backup_task["name"]), + ) + return bRCs["bRC_Error"] + else: raise Exception(value='Wrong argument for current_backup_task["type"]') @@ -365,7 +398,10 @@ def plugin_io(self, context, IOP): ), ) IOP.status = 0 - return bRCs["bRC_Error"] + if self.options["treat_download_errors_as_warnings"]: + return bRCs["bRC_Skip"] + else: + return bRCs["bRC_Error"] elif IOP.func == bIOPS["IO_WRITE"]: try: diff --git a/core/src/plugins/filed/BareosLibcloudApi.py b/core/src/plugins/filed/BareosLibcloudApi.py index 712f316eaf3..f4c42a79caf 100644 --- a/core/src/plugins/filed/BareosLibcloudApi.py +++ b/core/src/plugins/filed/BareosLibcloudApi.py @@ -19,7 +19,7 @@ SUCCESS = 0 ERROR = 1 - +ABORT = 2 class BareosLibcloudApi(object): @staticmethod @@ -94,7 +94,7 @@ def check_worker_messages(self): else: self.count_worker_ready += 1 elif message.type == MESSAGE_TYPE.ABORT_MESSAGE: - return ERROR + return ABORT elif message.type == MESSAGE_TYPE.DEBUG_MESSAGE: debugmessage(message.level, message.message_string) else: diff --git a/core/src/plugins/filed/bareos_libcloud_api/process_base.py b/core/src/plugins/filed/bareos_libcloud_api/process_base.py index 784768b98f6..0abe4247099 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/process_base.py +++ b/core/src/plugins/filed/bareos_libcloud_api/process_base.py @@ -38,6 +38,7 @@ def __init__( self.worker_id = worker_id def run_process(self): + # implementation of derived class pass def run(self): diff --git a/core/src/plugins/filed/bareos_libcloud_api/worker.py b/core/src/plugins/filed/bareos_libcloud_api/worker.py index 224f04b70db..581015bce75 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/worker.py +++ b/core/src/plugins/filed/bareos_libcloud_api/worker.py @@ -121,6 +121,7 @@ def __run_job(self, job): job["type"] = TASK_TYPE.TEMP_FILE except OSError as e: self.error_message("Could not open temporary file %s" % e.filename) + self.abort_message() return FINISH except ObjectDoesNotExistError as e: self.error_message( diff --git a/docs/manuals/source/TasksAndConcepts/Plugins.rst b/docs/manuals/source/TasksAndConcepts/Plugins.rst index acb6d736d19..cde86103209 100644 --- a/docs/manuals/source/TasksAndConcepts/Plugins.rst +++ b/docs/manuals/source/TasksAndConcepts/Plugins.rst @@ -1287,7 +1287,7 @@ And the plugin config file as follows: Mandatory Plugin Options: -All options in the config file are mandatory: +These options in the config file are mandatory: hostname The hostname/ip address of the storage backend server @@ -1324,6 +1324,16 @@ temporary_download_directory the filedaemon process needs read and write access to this path +Optional Plugin Options: + +This option in the config file is optional: + +treat_download_errors_as_warnings + This parameter can be set to True to keep a job running if for some reason a file cannot + be downloaded from a bucket because it is either deleted or moved to another space during + download. The default for this value is False. + + .. _PerconaXtrabackupPlugin: .. _backup-mysql-XtraBackup: From 879b2bd3f9689ec1cb4d3941558e89ae0e12c0f4 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Fri, 17 Jul 2020 17:03:38 +0200 Subject: [PATCH 322/341] fixup rebase errors --- systemtests/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 534701dc832..57fb811c38d 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -630,7 +630,7 @@ endif() if(TARGET python-fd) if(S3CMD) - list(APPEND SYSTEM_TESTS "python-fd-plugin-libcloud-test") + list(APPEND SYSTEM_TESTS "python-fd-plugin-libcloud-test") else() message("s3cmd not found, disabling python-fd-plugin-libcloud-test") list(APPEND SYSTEM_TESTS_DISABLED "python-fd-plugin-libcloud-test") @@ -638,8 +638,8 @@ if(TARGET python-fd) list(APPEND SYSTEM_TESTS "pyplug-fd-local-fileset-restoreobject") else() list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-local-fileset-restoreobject") -endif() list(APPEND SYSTEM_TESTS_DISABLED "python-fd-plugin-libcloud-test") +endif() message("checking for requirements of pyplug-fd-postgres:") check_pymodule_available("psycopg2") From dd9d3d87811630ed1bb57b83108ba6a1231dde5a Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Mon, 20 Jul 2020 14:16:57 +0200 Subject: [PATCH 323/341] systemtests: rename libcloud plugin test to match the standard --- .../etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in | 0 .../etc/bareos/bareos-dir.d/client/bareos-fd.conf.in | 0 .../etc/bareos/bareos-dir.d/console/bareos-mon.conf.in | 0 .../etc/bareos/bareos-dir.d/director/bareos-dir.conf.in | 0 .../etc/bareos/bareos-dir.d/fileset/Catalog.conf.in | 0 .../etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in | 0 .../etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in | 0 .../etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in | 0 .../etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in | 0 .../etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in | 0 .../etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in | 0 .../etc/bareos/bareos-dir.d/messages/Daemon.conf.in | 0 .../etc/bareos/bareos-dir.d/messages/Standard.conf.in | 0 .../etc/bareos/bareos-dir.d/pool/Differential.conf | 0 .../etc/bareos/bareos-dir.d/pool/Full.conf | 0 .../etc/bareos/bareos-dir.d/pool/Incremental.conf | 0 .../etc/bareos/bareos-dir.d/pool/Scratch.conf | 0 .../etc/bareos/bareos-dir.d/profile/operator.conf | 0 .../etc/bareos/bareos-dir.d/storage/File.conf.in | 0 .../etc/bareos/bareos-fd.d/client/myself.conf.in | 0 .../etc/bareos/bareos-fd.d/director/bareos-dir.conf.in | 0 .../etc/bareos/bareos-fd.d/director/bareos-mon.conf.in | 0 .../etc/bareos/bareos-fd.d/messages/Standard.conf | 0 .../etc/bareos/bareos-sd.d/device/FileStorage.conf.in | 0 .../etc/bareos/bareos-sd.d/director/bareos-dir.conf.in | 0 .../etc/bareos/bareos-sd.d/director/bareos-mon.conf.in | 0 .../etc/bareos/bareos-sd.d/messages/Standard.conf | 0 .../etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in | 0 .../etc/bareos/bconsole.conf.in | 0 .../etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in | 0 .../etc/bareos/tray-monitor.d/director/Director-local.conf.in | 0 .../etc/bareos/tray-monitor.d/monitor/bareos-mon.conf.in | 0 .../etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in | 0 .../etc/libcloud_config.ini | 0 .../testrunner | 0 35 files changed, 0 insertions(+), 0 deletions(-) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-dir.d/messages/Daemon.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-dir.d/messages/Standard.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-dir.d/pool/Differential.conf (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-dir.d/pool/Full.conf (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-dir.d/pool/Incremental.conf (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-dir.d/pool/Scratch.conf (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-dir.d/profile/operator.conf (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-dir.d/storage/File.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-fd.d/client/myself.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-fd.d/messages/Standard.conf (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-sd.d/device/FileStorage.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-sd.d/messages/Standard.conf (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/bconsole.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/tray-monitor.d/director/Director-local.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/tray-monitor.d/monitor/bareos-mon.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/etc/libcloud_config.ini (100%) rename systemtests/tests/{python-fd-plugin-libcloud-test => pyplug-fd-libcloud}/testrunner (100%) diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/messages/Daemon.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/messages/Daemon.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/messages/Daemon.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/messages/Daemon.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/messages/Standard.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/messages/Standard.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/messages/Standard.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/messages/Standard.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Differential.conf b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Differential.conf similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Differential.conf rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Differential.conf diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Full.conf b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Full.conf similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Full.conf rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Full.conf diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Incremental.conf b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Incremental.conf similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Incremental.conf rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Incremental.conf diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Scratch.conf b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Scratch.conf similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/pool/Scratch.conf rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Scratch.conf diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/profile/operator.conf b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/profile/operator.conf similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/profile/operator.conf rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/profile/operator.conf diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/storage/File.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/storage/File.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-dir.d/storage/File.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/storage/File.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-fd.d/client/myself.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/client/myself.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-fd.d/client/myself.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/messages/Standard.conf b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-fd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-fd.d/messages/Standard.conf rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-fd.d/messages/Standard.conf diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/device/FileStorage.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/device/FileStorage.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/device/FileStorage.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/device/FileStorage.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/messages/Standard.conf b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/messages/Standard.conf rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/messages/Standard.conf diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bconsole.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bconsole.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/bconsole.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/bconsole.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/director/Director-local.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/tray-monitor.d/director/Director-local.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/director/Director-local.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/tray-monitor.d/director/Director-local.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/monitor/bareos-mon.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/tray-monitor.d/monitor/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/monitor/bareos-mon.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/tray-monitor.d/monitor/bareos-mon.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in b/systemtests/tests/pyplug-fd-libcloud/etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in rename to systemtests/tests/pyplug-fd-libcloud/etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/etc/libcloud_config.ini b/systemtests/tests/pyplug-fd-libcloud/etc/libcloud_config.ini similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/etc/libcloud_config.ini rename to systemtests/tests/pyplug-fd-libcloud/etc/libcloud_config.ini diff --git a/systemtests/tests/python-fd-plugin-libcloud-test/testrunner b/systemtests/tests/pyplug-fd-libcloud/testrunner similarity index 100% rename from systemtests/tests/python-fd-plugin-libcloud-test/testrunner rename to systemtests/tests/pyplug-fd-libcloud/testrunner From 45c0611436aac86c18d47077f89ff91aa32c4012 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Mon, 20 Jul 2020 21:56:39 +0200 Subject: [PATCH 324/341] packaging: add libcloud plugin to pkgtests --- docs/pkglists/CentOS_6.x86_64 | 1 + docs/pkglists/CentOS_7.x86_64 | 1 + docs/pkglists/CentOS_8.x86_64 | 1 + docs/pkglists/Debian_10.x86_64 | 1 + docs/pkglists/Debian_8.0.i586 | 1 + docs/pkglists/Debian_8.0.x86_64 | 1 + docs/pkglists/Debian_9.0.i586 | 1 + docs/pkglists/Debian_9.0.x86_64 | 1 + docs/pkglists/Fedora_29.x86_64 | 1 + docs/pkglists/Fedora_30.x86_64 | 1 + docs/pkglists/Fedora_31.x86_64 | 1 + docs/pkglists/Fedora_32.x86_64 | 1 + docs/pkglists/RHEL_6.x86_64 | 1 + docs/pkglists/RHEL_7.x86_64 | 1 + docs/pkglists/RHEL_8.x86_64 | 1 + docs/pkglists/SLE_12_SP4.x86_64 | 1 + docs/pkglists/SLE_15.x86_64 | 1 + docs/pkglists/SLE_15_SP1.x86_64 | 1 + docs/pkglists/Univention_4.3.x86_64 | 1 + docs/pkglists/openSUSE_Leap_15.0.x86_64 | 1 + docs/pkglists/openSUSE_Leap_15.1.x86_64 | 1 + docs/pkglists/openSUSE_Leap_15.2.x86_64 | 1 + docs/pkglists/xUbuntu_16.04.i586 | 1 + docs/pkglists/xUbuntu_16.04.x86_64 | 1 + docs/pkglists/xUbuntu_18.04.x86_64 | 1 + docs/pkglists/xUbuntu_20.04.x86_64 | 1 + 26 files changed, 26 insertions(+) diff --git a/docs/pkglists/CentOS_6.x86_64 b/docs/pkglists/CentOS_6.x86_64 index dd8fbb0fe5b..788edfcc8cd 100644 --- a/docs/pkglists/CentOS_6.x86_64 +++ b/docs/pkglists/CentOS_6.x86_64 @@ -16,6 +16,7 @@ x86_64/bareos-director x86_64/bareos-director-python-plugin x86_64/bareos-filedaemon x86_64/bareos-filedaemon-ldap-python-plugin +x86_64/bareos-filedaemon-libcloud-python-plugin x86_64/bareos-filedaemon-ovirt-python-plugin x86_64/bareos-filedaemon-percona-xtrabackup-python-plugin x86_64/bareos-filedaemon-postgresql-python-plugin diff --git a/docs/pkglists/CentOS_7.x86_64 b/docs/pkglists/CentOS_7.x86_64 index 364b3378041..d81301128ed 100644 --- a/docs/pkglists/CentOS_7.x86_64 +++ b/docs/pkglists/CentOS_7.x86_64 @@ -21,6 +21,7 @@ x86_64/bareos-director-python-plugin x86_64/bareos-filedaemon x86_64/bareos-filedaemon-glusterfs-plugin x86_64/bareos-filedaemon-ldap-python-plugin +x86_64/bareos-filedaemon-libcloud-python-plugin x86_64/bareos-filedaemon-ovirt-python-plugin x86_64/bareos-filedaemon-percona-xtrabackup-python-plugin x86_64/bareos-filedaemon-postgresql-python-plugin diff --git a/docs/pkglists/CentOS_8.x86_64 b/docs/pkglists/CentOS_8.x86_64 index 410a4185866..4e531e5c344 100644 --- a/docs/pkglists/CentOS_8.x86_64 +++ b/docs/pkglists/CentOS_8.x86_64 @@ -45,6 +45,7 @@ x86_64/bareos-filedaemon x86_64/bareos-filedaemon-ceph-plugin x86_64/bareos-filedaemon-glusterfs-plugin x86_64/bareos-filedaemon-ldap-python-plugin +x86_64/bareos-filedaemon-libcloud-python-plugin x86_64/bareos-filedaemon-ovirt-python-plugin x86_64/bareos-filedaemon-percona-xtrabackup-python-plugin x86_64/bareos-filedaemon-postgresql-python-plugin diff --git a/docs/pkglists/Debian_10.x86_64 b/docs/pkglists/Debian_10.x86_64 index 0738976c2fe..fe5e5001e08 100644 --- a/docs/pkglists/Debian_10.x86_64 +++ b/docs/pkglists/Debian_10.x86_64 @@ -17,6 +17,7 @@ amd64/bareos-director-python-plugin amd64/bareos-filedaemon amd64/bareos-filedaemon-ceph-plugin amd64/bareos-filedaemon-ldap-python-plugin +amd64/bareos-filedaemon-libcloud-python-plugin amd64/bareos-filedaemon-percona-xtrabackup-python-plugin amd64/bareos-filedaemon-python-plugin amd64/bareos-regress-config diff --git a/docs/pkglists/Debian_8.0.i586 b/docs/pkglists/Debian_8.0.i586 index 0b42f2153ee..c0acfa6f978 100644 --- a/docs/pkglists/Debian_8.0.i586 +++ b/docs/pkglists/Debian_8.0.i586 @@ -16,6 +16,7 @@ i386/bareos-director i386/bareos-director-python-plugin i386/bareos-filedaemon i386/bareos-filedaemon-ldap-python-plugin +i386/bareos-filedaemon-libcloud-python-plugin i386/bareos-filedaemon-percona-xtrabackup-python-plugin i386/bareos-filedaemon-python-plugin i386/bareos-regress-config diff --git a/docs/pkglists/Debian_8.0.x86_64 b/docs/pkglists/Debian_8.0.x86_64 index 9e060a2924b..f73f82a313f 100644 --- a/docs/pkglists/Debian_8.0.x86_64 +++ b/docs/pkglists/Debian_8.0.x86_64 @@ -16,6 +16,7 @@ amd64/bareos-director amd64/bareos-director-python-plugin amd64/bareos-filedaemon amd64/bareos-filedaemon-ldap-python-plugin +amd64/bareos-filedaemon-libcloud-python-plugin amd64/bareos-filedaemon-percona-xtrabackup-python-plugin amd64/bareos-filedaemon-python-plugin amd64/bareos-regress-config diff --git a/docs/pkglists/Debian_9.0.i586 b/docs/pkglists/Debian_9.0.i586 index ace0c7a6334..6fcbee273fc 100644 --- a/docs/pkglists/Debian_9.0.i586 +++ b/docs/pkglists/Debian_9.0.i586 @@ -17,6 +17,7 @@ i386/bareos-director-python-plugin i386/bareos-filedaemon i386/bareos-filedaemon-ceph-plugin i386/bareos-filedaemon-ldap-python-plugin +i386/bareos-filedaemon-libcloud-python-plugin i386/bareos-filedaemon-percona-xtrabackup-python-plugin i386/bareos-filedaemon-python-plugin i386/bareos-regress-config diff --git a/docs/pkglists/Debian_9.0.x86_64 b/docs/pkglists/Debian_9.0.x86_64 index 0738976c2fe..fe5e5001e08 100644 --- a/docs/pkglists/Debian_9.0.x86_64 +++ b/docs/pkglists/Debian_9.0.x86_64 @@ -17,6 +17,7 @@ amd64/bareos-director-python-plugin amd64/bareos-filedaemon amd64/bareos-filedaemon-ceph-plugin amd64/bareos-filedaemon-ldap-python-plugin +amd64/bareos-filedaemon-libcloud-python-plugin amd64/bareos-filedaemon-percona-xtrabackup-python-plugin amd64/bareos-filedaemon-python-plugin amd64/bareos-regress-config diff --git a/docs/pkglists/Fedora_29.x86_64 b/docs/pkglists/Fedora_29.x86_64 index 6aae0b44224..49a86805d85 100644 --- a/docs/pkglists/Fedora_29.x86_64 +++ b/docs/pkglists/Fedora_29.x86_64 @@ -43,6 +43,7 @@ x86_64/bareos-director-python-plugin x86_64/bareos-filedaemon x86_64/bareos-filedaemon-glusterfs-plugin x86_64/bareos-filedaemon-ldap-python-plugin +x86_64/bareos-filedaemon-libcloud-python-plugin x86_64/bareos-filedaemon-ovirt-python-plugin x86_64/bareos-filedaemon-percona-xtrabackup-python-plugin x86_64/bareos-filedaemon-postgresql-python-plugin diff --git a/docs/pkglists/Fedora_30.x86_64 b/docs/pkglists/Fedora_30.x86_64 index 7d7f660c078..d8ed3cc5ee2 100644 --- a/docs/pkglists/Fedora_30.x86_64 +++ b/docs/pkglists/Fedora_30.x86_64 @@ -43,6 +43,7 @@ x86_64/bareos-director-python-plugin x86_64/bareos-filedaemon x86_64/bareos-filedaemon-glusterfs-plugin x86_64/bareos-filedaemon-ldap-python-plugin +x86_64/bareos-filedaemon-libcloud-python-plugin x86_64/bareos-filedaemon-ovirt-python-plugin x86_64/bareos-filedaemon-percona-xtrabackup-python-plugin x86_64/bareos-filedaemon-postgresql-python-plugin diff --git a/docs/pkglists/Fedora_31.x86_64 b/docs/pkglists/Fedora_31.x86_64 index 7d7f660c078..d8ed3cc5ee2 100644 --- a/docs/pkglists/Fedora_31.x86_64 +++ b/docs/pkglists/Fedora_31.x86_64 @@ -43,6 +43,7 @@ x86_64/bareos-director-python-plugin x86_64/bareos-filedaemon x86_64/bareos-filedaemon-glusterfs-plugin x86_64/bareos-filedaemon-ldap-python-plugin +x86_64/bareos-filedaemon-libcloud-python-plugin x86_64/bareos-filedaemon-ovirt-python-plugin x86_64/bareos-filedaemon-percona-xtrabackup-python-plugin x86_64/bareos-filedaemon-postgresql-python-plugin diff --git a/docs/pkglists/Fedora_32.x86_64 b/docs/pkglists/Fedora_32.x86_64 index 7d7f660c078..d8ed3cc5ee2 100644 --- a/docs/pkglists/Fedora_32.x86_64 +++ b/docs/pkglists/Fedora_32.x86_64 @@ -43,6 +43,7 @@ x86_64/bareos-director-python-plugin x86_64/bareos-filedaemon x86_64/bareos-filedaemon-glusterfs-plugin x86_64/bareos-filedaemon-ldap-python-plugin +x86_64/bareos-filedaemon-libcloud-python-plugin x86_64/bareos-filedaemon-ovirt-python-plugin x86_64/bareos-filedaemon-percona-xtrabackup-python-plugin x86_64/bareos-filedaemon-postgresql-python-plugin diff --git a/docs/pkglists/RHEL_6.x86_64 b/docs/pkglists/RHEL_6.x86_64 index dd8fbb0fe5b..788edfcc8cd 100644 --- a/docs/pkglists/RHEL_6.x86_64 +++ b/docs/pkglists/RHEL_6.x86_64 @@ -16,6 +16,7 @@ x86_64/bareos-director x86_64/bareos-director-python-plugin x86_64/bareos-filedaemon x86_64/bareos-filedaemon-ldap-python-plugin +x86_64/bareos-filedaemon-libcloud-python-plugin x86_64/bareos-filedaemon-ovirt-python-plugin x86_64/bareos-filedaemon-percona-xtrabackup-python-plugin x86_64/bareos-filedaemon-postgresql-python-plugin diff --git a/docs/pkglists/RHEL_7.x86_64 b/docs/pkglists/RHEL_7.x86_64 index dc604c28147..41487e050ff 100644 --- a/docs/pkglists/RHEL_7.x86_64 +++ b/docs/pkglists/RHEL_7.x86_64 @@ -22,6 +22,7 @@ x86_64/bareos-filedaemon x86_64/bareos-filedaemon-ceph-plugin x86_64/bareos-filedaemon-glusterfs-plugin x86_64/bareos-filedaemon-ldap-python-plugin +x86_64/bareos-filedaemon-libcloud-python-plugin x86_64/bareos-filedaemon-ovirt-python-plugin x86_64/bareos-filedaemon-percona-xtrabackup-python-plugin x86_64/bareos-filedaemon-postgresql-python-plugin diff --git a/docs/pkglists/RHEL_8.x86_64 b/docs/pkglists/RHEL_8.x86_64 index 410a4185866..4e531e5c344 100644 --- a/docs/pkglists/RHEL_8.x86_64 +++ b/docs/pkglists/RHEL_8.x86_64 @@ -45,6 +45,7 @@ x86_64/bareos-filedaemon x86_64/bareos-filedaemon-ceph-plugin x86_64/bareos-filedaemon-glusterfs-plugin x86_64/bareos-filedaemon-ldap-python-plugin +x86_64/bareos-filedaemon-libcloud-python-plugin x86_64/bareos-filedaemon-ovirt-python-plugin x86_64/bareos-filedaemon-percona-xtrabackup-python-plugin x86_64/bareos-filedaemon-postgresql-python-plugin diff --git a/docs/pkglists/SLE_12_SP4.x86_64 b/docs/pkglists/SLE_12_SP4.x86_64 index b6efb3bd859..97f83452d92 100644 --- a/docs/pkglists/SLE_12_SP4.x86_64 +++ b/docs/pkglists/SLE_12_SP4.x86_64 @@ -40,6 +40,7 @@ x86_64/bareos-director-python-plugin x86_64/bareos-filedaemon x86_64/bareos-filedaemon-ceph-plugin x86_64/bareos-filedaemon-ldap-python-plugin +x86_64/bareos-filedaemon-libcloud-python-plugin x86_64/bareos-filedaemon-ovirt-python-plugin x86_64/bareos-filedaemon-percona-xtrabackup-python-plugin x86_64/bareos-filedaemon-postgresql-python-plugin diff --git a/docs/pkglists/SLE_15.x86_64 b/docs/pkglists/SLE_15.x86_64 index bc49d6b0bbc..c67b18a655a 100644 --- a/docs/pkglists/SLE_15.x86_64 +++ b/docs/pkglists/SLE_15.x86_64 @@ -40,6 +40,7 @@ x86_64/bareos-director-python-plugin x86_64/bareos-filedaemon x86_64/bareos-filedaemon-ceph-plugin x86_64/bareos-filedaemon-ldap-python-plugin +x86_64/bareos-filedaemon-libcloud-python-plugin x86_64/bareos-filedaemon-ovirt-python-plugin x86_64/bareos-filedaemon-percona-xtrabackup-python-plugin x86_64/bareos-filedaemon-postgresql-python-plugin diff --git a/docs/pkglists/SLE_15_SP1.x86_64 b/docs/pkglists/SLE_15_SP1.x86_64 index bc49d6b0bbc..c67b18a655a 100644 --- a/docs/pkglists/SLE_15_SP1.x86_64 +++ b/docs/pkglists/SLE_15_SP1.x86_64 @@ -40,6 +40,7 @@ x86_64/bareos-director-python-plugin x86_64/bareos-filedaemon x86_64/bareos-filedaemon-ceph-plugin x86_64/bareos-filedaemon-ldap-python-plugin +x86_64/bareos-filedaemon-libcloud-python-plugin x86_64/bareos-filedaemon-ovirt-python-plugin x86_64/bareos-filedaemon-percona-xtrabackup-python-plugin x86_64/bareos-filedaemon-postgresql-python-plugin diff --git a/docs/pkglists/Univention_4.3.x86_64 b/docs/pkglists/Univention_4.3.x86_64 index 75a8339f233..3fa6a257f47 100644 --- a/docs/pkglists/Univention_4.3.x86_64 +++ b/docs/pkglists/Univention_4.3.x86_64 @@ -18,6 +18,7 @@ amd64/bareos-director-python-plugin amd64/bareos-filedaemon amd64/bareos-filedaemon-ceph-plugin amd64/bareos-filedaemon-ldap-python-plugin +amd64/bareos-filedaemon-libcloud-python-plugin amd64/bareos-filedaemon-percona-xtrabackup-python-plugin amd64/bareos-filedaemon-python-plugin amd64/bareos-regress-config diff --git a/docs/pkglists/openSUSE_Leap_15.0.x86_64 b/docs/pkglists/openSUSE_Leap_15.0.x86_64 index bc49d6b0bbc..c67b18a655a 100644 --- a/docs/pkglists/openSUSE_Leap_15.0.x86_64 +++ b/docs/pkglists/openSUSE_Leap_15.0.x86_64 @@ -40,6 +40,7 @@ x86_64/bareos-director-python-plugin x86_64/bareos-filedaemon x86_64/bareos-filedaemon-ceph-plugin x86_64/bareos-filedaemon-ldap-python-plugin +x86_64/bareos-filedaemon-libcloud-python-plugin x86_64/bareos-filedaemon-ovirt-python-plugin x86_64/bareos-filedaemon-percona-xtrabackup-python-plugin x86_64/bareos-filedaemon-postgresql-python-plugin diff --git a/docs/pkglists/openSUSE_Leap_15.1.x86_64 b/docs/pkglists/openSUSE_Leap_15.1.x86_64 index bc49d6b0bbc..c67b18a655a 100644 --- a/docs/pkglists/openSUSE_Leap_15.1.x86_64 +++ b/docs/pkglists/openSUSE_Leap_15.1.x86_64 @@ -40,6 +40,7 @@ x86_64/bareos-director-python-plugin x86_64/bareos-filedaemon x86_64/bareos-filedaemon-ceph-plugin x86_64/bareos-filedaemon-ldap-python-plugin +x86_64/bareos-filedaemon-libcloud-python-plugin x86_64/bareos-filedaemon-ovirt-python-plugin x86_64/bareos-filedaemon-percona-xtrabackup-python-plugin x86_64/bareos-filedaemon-postgresql-python-plugin diff --git a/docs/pkglists/openSUSE_Leap_15.2.x86_64 b/docs/pkglists/openSUSE_Leap_15.2.x86_64 index bc49d6b0bbc..c67b18a655a 100644 --- a/docs/pkglists/openSUSE_Leap_15.2.x86_64 +++ b/docs/pkglists/openSUSE_Leap_15.2.x86_64 @@ -40,6 +40,7 @@ x86_64/bareos-director-python-plugin x86_64/bareos-filedaemon x86_64/bareos-filedaemon-ceph-plugin x86_64/bareos-filedaemon-ldap-python-plugin +x86_64/bareos-filedaemon-libcloud-python-plugin x86_64/bareos-filedaemon-ovirt-python-plugin x86_64/bareos-filedaemon-percona-xtrabackup-python-plugin x86_64/bareos-filedaemon-postgresql-python-plugin diff --git a/docs/pkglists/xUbuntu_16.04.i586 b/docs/pkglists/xUbuntu_16.04.i586 index ace0c7a6334..6fcbee273fc 100644 --- a/docs/pkglists/xUbuntu_16.04.i586 +++ b/docs/pkglists/xUbuntu_16.04.i586 @@ -17,6 +17,7 @@ i386/bareos-director-python-plugin i386/bareos-filedaemon i386/bareos-filedaemon-ceph-plugin i386/bareos-filedaemon-ldap-python-plugin +i386/bareos-filedaemon-libcloud-python-plugin i386/bareos-filedaemon-percona-xtrabackup-python-plugin i386/bareos-filedaemon-python-plugin i386/bareos-regress-config diff --git a/docs/pkglists/xUbuntu_16.04.x86_64 b/docs/pkglists/xUbuntu_16.04.x86_64 index 0738976c2fe..fe5e5001e08 100644 --- a/docs/pkglists/xUbuntu_16.04.x86_64 +++ b/docs/pkglists/xUbuntu_16.04.x86_64 @@ -17,6 +17,7 @@ amd64/bareos-director-python-plugin amd64/bareos-filedaemon amd64/bareos-filedaemon-ceph-plugin amd64/bareos-filedaemon-ldap-python-plugin +amd64/bareos-filedaemon-libcloud-python-plugin amd64/bareos-filedaemon-percona-xtrabackup-python-plugin amd64/bareos-filedaemon-python-plugin amd64/bareos-regress-config diff --git a/docs/pkglists/xUbuntu_18.04.x86_64 b/docs/pkglists/xUbuntu_18.04.x86_64 index 0738976c2fe..fe5e5001e08 100644 --- a/docs/pkglists/xUbuntu_18.04.x86_64 +++ b/docs/pkglists/xUbuntu_18.04.x86_64 @@ -17,6 +17,7 @@ amd64/bareos-director-python-plugin amd64/bareos-filedaemon amd64/bareos-filedaemon-ceph-plugin amd64/bareos-filedaemon-ldap-python-plugin +amd64/bareos-filedaemon-libcloud-python-plugin amd64/bareos-filedaemon-percona-xtrabackup-python-plugin amd64/bareos-filedaemon-python-plugin amd64/bareos-regress-config diff --git a/docs/pkglists/xUbuntu_20.04.x86_64 b/docs/pkglists/xUbuntu_20.04.x86_64 index 0738976c2fe..fe5e5001e08 100644 --- a/docs/pkglists/xUbuntu_20.04.x86_64 +++ b/docs/pkglists/xUbuntu_20.04.x86_64 @@ -17,6 +17,7 @@ amd64/bareos-director-python-plugin amd64/bareos-filedaemon amd64/bareos-filedaemon-ceph-plugin amd64/bareos-filedaemon-ldap-python-plugin +amd64/bareos-filedaemon-libcloud-python-plugin amd64/bareos-filedaemon-percona-xtrabackup-python-plugin amd64/bareos-filedaemon-python-plugin amd64/bareos-regress-config From 41692f8e674ae369a08772056ed63e2f977a3f4b Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Thu, 30 Jul 2020 19:36:51 +0200 Subject: [PATCH 325/341] libcloud-plugin: return mtime timestamp as integer not float --- core/src/plugins/filed/bareos_libcloud_api/mtime.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/plugins/filed/bareos_libcloud_api/mtime.py b/core/src/plugins/filed/bareos_libcloud_api/mtime.py index 6e390bb8aaa..bbd6017b0c5 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/mtime.py +++ b/core/src/plugins/filed/bareos_libcloud_api/mtime.py @@ -41,7 +41,7 @@ def get_mtime(self, obj): mtime = mtime - self.timezone_delta mtime = mtime.replace(tzinfo=None) - ts = time.mktime(mtime.timetuple()) + ts = int(time.mktime(mtime.timetuple())) return mtime, ts def get_last_run(self): From f300f85b5f8e1acfb041c00e1282b624a97a04d7 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Fri, 31 Jul 2020 13:56:34 +0200 Subject: [PATCH 326/341] libcloud-plugin: remove temp files on error --- .../filed/bareos_libcloud_api/utils.py | 27 +++++++++++++++++++ .../filed/bareos_libcloud_api/worker.py | 14 +++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 core/src/plugins/filed/bareos_libcloud_api/utils.py diff --git a/core/src/plugins/filed/bareos_libcloud_api/utils.py b/core/src/plugins/filed/bareos_libcloud_api/utils.py new file mode 100644 index 00000000000..3bd4a55ba08 --- /dev/null +++ b/core/src/plugins/filed/bareos_libcloud_api/utils.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2020-2020 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation, which is +# listed in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + +from os import remove + +def silentremove(filename): + try: + os.remove(filename) + except: + pass + diff --git a/core/src/plugins/filed/bareos_libcloud_api/worker.py b/core/src/plugins/filed/bareos_libcloud_api/worker.py index 581015bce75..5e886c1f7f5 100644 --- a/core/src/plugins/filed/bareos_libcloud_api/worker.py +++ b/core/src/plugins/filed/bareos_libcloud_api/worker.py @@ -23,8 +23,9 @@ import io from libcloud.common.types import LibcloudError from libcloud.storage.types import ObjectDoesNotExistError -import uuid +from utils import silentremove from time import sleep +import uuid FINISH = 0 CONTINUE = 1 @@ -72,6 +73,7 @@ def __iterate_input_queue(self): return CONTINUE def __run_job(self, job): + success = False try: obj = self.driver.get_object(job["bucket"], job["name"]) except ObjectDoesNotExistError: @@ -101,6 +103,7 @@ def __run_job(self, job): job["data"] = io.BytesIO(content) job["type"] = TASK_TYPE.DOWNLOADED + success = True except LibcloudError: self.error_message("Libcloud error, could not download file") return CONTINUE @@ -119,22 +122,26 @@ def __run_job(self, job): job["data"] = None job["tmpfile"] = tmpfilename job["type"] = TASK_TYPE.TEMP_FILE + success = True except OSError as e: self.error_message("Could not open temporary file %s" % e.filename) self.abort_message() return FINISH except ObjectDoesNotExistError as e: + silentremove(tmpfilename) self.error_message( "Could not open object, skipping: %s" % e.object_name ) return CONTINUE except LibcloudError: + silentremove(tmpfilename) self.error_message( "Error downloading object, skipping: %s/%s" % (job["bucket"], job["name"]) ) return CONTINUE except Exception: + silentremove(tmpfilename) self.error_message( "Error using temporary file for, skipping: %s/%s" % (job["bucket"], job["name"]) @@ -149,6 +156,7 @@ def __run_job(self, job): ) job["data"] = obj job["type"] = TASK_TYPE.STREAM + success = True except LibcloudError: self.error_message( "Libcloud error preparing stream object, skipping: %s/%s" @@ -162,7 +170,7 @@ def __run_job(self, job): ) return CONTINUE - self.queue_try_put(self.output_queue, job) + if success == True: + self.queue_try_put(self.output_queue, job) - # success return CONTINUE From ac5ef4c80229a4bd47b25a44363b115085a0630b Mon Sep 17 00:00:00 2001 From: Andreas Rogge Date: Fri, 7 Aug 2020 11:47:35 +0200 Subject: [PATCH 327/341] debian: configure libcloud package correctly --- .../bareos-filedaemon-libcloud-python-plugin.install.in | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {core/debian => debian}/bareos-filedaemon-libcloud-python-plugin.install.in (100%) diff --git a/core/debian/bareos-filedaemon-libcloud-python-plugin.install.in b/debian/bareos-filedaemon-libcloud-python-plugin.install.in similarity index 100% rename from core/debian/bareos-filedaemon-libcloud-python-plugin.install.in rename to debian/bareos-filedaemon-libcloud-python-plugin.install.in From 8cb670db5d784990a909e72f60364f4c87777d39 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Sat, 29 Aug 2020 13:28:07 +0200 Subject: [PATCH 328/341] fix rebase errors --- systemtests/CMakeLists.txt | 182 ++++++++++++++++++++++++++++--------- systemtests/environment.in | 5 +- 2 files changed, 144 insertions(+), 43 deletions(-) diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 57fb811c38d..0c9390568c3 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -457,13 +457,13 @@ set(python_plugin_module_src_test_dir_relative "python-modules") set(plugindirtmp ${PROJECT_BINARY_DIR}/plugindirtmp) set(rscripts ${PROJECT_BINARY_DIR}/scripts) -if(TARGET python-dir) +if(TARGET python-dir OR TARGET python3-dir) set(dir_plugin_binary_path ${DIR_PLUGINS_DIR_TO_TEST}) endif() -if(TARGET python-sd) +if(TARGET python-sd OR TARGET python3-sd) set(sd_plugin_binary_path ${SD_PLUGINS_DIR_TO_TEST}) endif() -if(TARGET python-fd) +if(TARGET python-fd OR TARGET python3-fd) set(fd_plugin_binary_path ${FD_PLUGINS_DIR_TO_TEST}) endif() @@ -541,17 +541,20 @@ endforeach() set(tests_dir ${PROJECT_BINARY_DIR}/tests) set(SYSTEM_TESTS client-initiated + config-dump encrypt-signature encrypt-signature-tls-cert notls passive spool bareos + bareos-acl bscan bconsole-status-client config-syntax-crash copy-bscan copy-remote-bscan + deprecation messages multiplied-device reload-add-client @@ -576,6 +579,25 @@ set(glusterfs_uri ) mark_as_advanced(glusterfs_uri) +include(BareosCheckXattr) +if(SETFATTR_WORKS) + list(APPEND SYSTEM_TESTS xattr) +else() + list(APPEND SYSTEM_TESTS_DISABLED xattr) +endif() + +include(BareosCheckAcl) +if(SETFACL_WORKS) + list(APPEND SYSTEM_TESTS acl) +else() + list(APPEND SYSTEM_TESTS_DISABLED acl) +endif() + +if(TARGET droplet) + list(APPEND SYSTEM_TESTS droplet-s3) +else() + list(APPEND SYSTEM_TESTS_DISABLED droplet-s3) +endif() if(SD_GFAPI_DIR_TO_TEST AND glusterfs_uri) list(APPEND SYSTEM_TESTS glusterfs-backend) else() @@ -595,6 +617,7 @@ endif() if(EXISTS /run/.containerenv) message(STATUS "detected container environment, disabling python-bareos") set(in_container TRUE) + list(APPEND SYSTEM_TESTS "dbcopy-mysql-postgresql-test") else() set(in_container FALSE) endif() @@ -623,73 +646,124 @@ else() endif() if(TARGET python-fd) - list(APPEND SYSTEM_TESTS "pyplug-fd-local-fileset") + list(APPEND SYSTEM_TESTS "py2plug-fd-local-fileset") else() - list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-local-fileset") + list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-local-fileset") +endif() + +if(TARGET python3-fd) + list(APPEND SYSTEM_TESTS "py3plug-fd-local-fileset") +else() + list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-local-fileset") endif() if(TARGET python-fd) - if(S3CMD) - list(APPEND SYSTEM_TESTS "python-fd-plugin-libcloud-test") - else() - message("s3cmd not found, disabling python-fd-plugin-libcloud-test") - list(APPEND SYSTEM_TESTS_DISABLED "python-fd-plugin-libcloud-test") - endif() - list(APPEND SYSTEM_TESTS "pyplug-fd-local-fileset-restoreobject") + list(APPEND SYSTEM_TESTS "py2plug-fd-local-fileset-restoreobject") else() - list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-local-fileset-restoreobject") - list(APPEND SYSTEM_TESTS_DISABLED "python-fd-plugin-libcloud-test") + list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-local-fileset-restoreobject") endif() -message("checking for requirements of pyplug-fd-postgres:") -check_pymodule_available("psycopg2") -check_pymodule_available("dateutil") +if(TARGET python3-fd) + list(APPEND SYSTEM_TESTS "py3plug-fd-local-fileset-restoreobject") +else() + list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-local-fileset-restoreobject") +endif() + +message("checking for requirements of py2plug-fd-postgres:") +check_pymodule_available(2 psycopg2) +check_pymodule_available(2 dateutil) +if(TARGET python-fd + AND PYMODULE_2_PSYCOPG2_FOUND + AND PYMODULE_2_DATEUTIL_FOUND +) + message("OK, enabling py2plug-fd-postgres:") + list(APPEND SYSTEM_TESTS "py2plug-fd-postgres") +else() + list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-postgres") + message("NOT OK, disabling py2plug-fd-postgres:") +endif() +message("checking for requirements of py3plug-fd-postgres:") +check_pymodule_available(3 psycopg2) +check_pymodule_available(3 dateutil) if(TARGET python-fd - AND PYMODULE_PSYCOPG2_FOUND - AND PYMODULE_DATEUTIL_FOUND + AND PYMODULE_3_PSYCOPG2_FOUND + AND PYMODULE_3_DATEUTIL_FOUND ) - message("OK, enabling pyplug-fd-postgres:") - list(APPEND SYSTEM_TESTS "pyplug-fd-postgres") + list(APPEND SYSTEM_TESTS "py3plug-fd-postgres") else() - list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-postgres") - message("NOT OK, disabling pyplug-fd-postgres:") + list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-postgres") endif() if(TARGET python-fd AND ovirt_server) - list(APPEND SYSTEM_TESTS "pyplug-fd-ovirt") + list(APPEND SYSTEM_TESTS "py2plug-fd-ovirt") else() - message(STATUS "disabling pyplug-fd-ovirt-test as ovirt_server is not set") - list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-ovirt") + message(STATUS "disabling py2plug-fd-ovirt-test as ovirt_server is not set") + list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-ovirt") +endif() + +if(TARGET python3-fd AND ovirt_server) + list(APPEND SYSTEM_TESTS "py3plug-fd-ovirt") +else() + message(STATUS "disabling py3plug-fd-ovirt as ovirt_server is not set") + list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-ovirt") endif() if(TARGET python-fd AND enable_vmware_test) - list(APPEND SYSTEM_TESTS "pyplug-fd-vmware") + list(APPEND SYSTEM_TESTS "py2plug-fd-vmware") +else() + message(STATUS "disabling py2plug-fd-vmware as vmware_server was not set") + list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-vmware") +endif() + +if(TARGET python3-fd AND enable_vmware_test) + list(APPEND SYSTEM_TESTS "py3plug-fd-vmware") else() - message(STATUS "disabling pyplug-fd-vmware as vmware_server was not set") - list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-vmware") + message(STATUS "disabling py3plug-fd-vmware as vmware_server was not set") + list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-vmware") endif() if(TARGET python-fd AND XTRABACKUP) - list(APPEND SYSTEM_TESTS "pyplug-fd-percona-xtrabackup") + list(APPEND SYSTEM_TESTS "py2plug-fd-percona-xtrabackup") else() message( STATUS - "disabling pyplug-fd-percona-xtrabackup-test as XTRABACKUP was not found" + "disabling py2plug-fd-percona-xtrabackup-test as XTRABACKUP was not found" + ) + list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-percona-xtrabackup") +endif() + +if(TARGET python3-fd AND XTRABACKUP) + list(APPEND SYSTEM_TESTS "py3plug-fd-percona-xtrabackup") +else() + message( + STATUS "disabling py3plug-fd-percona-xtrabackup as XTRABACKUP was not found" ) - list(APPEND SYSTEM_TESTS_DISABLED "pyplug-fd-percona-xtrabackup") + list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-percona-xtrabackup") endif() if(TARGET python-dir) - list(APPEND SYSTEM_TESTS "pyplug-dir") + list(APPEND SYSTEM_TESTS "py2plug-dir") else() - list(APPEND SYSTEM_TESTS_DISABLED "pyplug-dir") + list(APPEND SYSTEM_TESTS_DISABLED "py2plug-dir") +endif() + +if(TARGET python3-dir) + list(APPEND SYSTEM_TESTS "py3plug-dir") +else() + list(APPEND SYSTEM_TESTS_DISABLED "py3plug-dir") endif() if(TARGET python-sd) - list(APPEND SYSTEM_TESTS "pyplug-sd") + list(APPEND SYSTEM_TESTS "py2plug-sd") +else() + list(APPEND SYSTEM_TESTS_DISABLED "py2plug-sd") +endif() + +if(TARGET python3-sd) + list(APPEND SYSTEM_TESTS "py3plug-sd") else() - list(APPEND SYSTEM_TESTS_DISABLED "pyplug-sd") + list(APPEND SYSTEM_TESTS_DISABLED "py3plug-sd") endif() message(STATUS "Looking for pam test requirements ...") @@ -744,17 +818,18 @@ message(STATUS "Looking for webui test requirements ...") find_program(PHP php) find_program(CHROMEDRIVER chromedriver) -check_pymodule_available("selenium") # sets PYMODULE_SELENIUM_FOUND to TRUE or +check_pymodule_available(2 selenium) # sets PYMODULE_2_SELENIUM_FOUND to TRUE or +check_pymodule_available(3 selenium) # sets PYMODULE_3_SELENIUM_FOUND to TRUE or # FALSE message(" PHP: " ${PHP}) message(" PYTHON_EXECUTABLE: " ${PYTHON_EXECUTABLE}) -message(" PYMODULE_SELENIUM_FOUND:" ${PYMOD_SELENIUM_FOUND}) +message(" PYMODULE_2_SELENIUM_FOUND:" ${PYMODULE_2_SELENIUM_FOUND}) message(" CHROMEDRIVER: " ${CHROMEDRIVER}) if(PHP AND PYTHON_EXECUTABLE - AND PYMODULE_SELENIUM_FOUND + AND PYMODULE_2_SELENIUM_FOUND AND CHROMEDRIVER ) set(ENABLE_WEBUI_SELENIUM_TEST TRUE) @@ -795,10 +870,31 @@ endif() foreach(TEST_NAME ${SYSTEM_TESTS}) message(STATUS "Configuring test: ${SYSTEMTEST_PREFIX}${TEST_NAME}") + string(REGEX MATCH "py2plug" py_v2 "${TEST_NAME}") + string(REGEX MATCH "py3plug" py_v3 "${TEST_NAME}") + if(py_v2) + set(python_module_name python) + endif() + if(py_v3) + set(python_module_name python3) + endif() prepare_test() configurefilestosystemtest("systemtests" "tests/${TEST_NAME}" "*" @ONLY "") - handle_python_plugin_modules(${TEST_NAME}) + string( + CONCAT + pythonpath + "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/percona-xtrabackup:" + "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/ovirt:" + "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/postgres:" + "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/pyfiles:" + "${CMAKE_SOURCE_DIR}/core/src/plugins/stored/python/pyfiles:" + "${CMAKE_SOURCE_DIR}/core/src/plugins/dird/python/pyfiles:" + "${CMAKE_BINARY_DIR}/core/src/plugins/filed/python/${python_module_name}modules:" + "${CMAKE_BINARY_DIR}/core/src/plugins/stored/python/${python_module_name}modules:" + "${CMAKE_BINARY_DIR}/core/src/plugins/dird/python/${python_module_name}modules:" + "${CMAKE_CURRENT_SOURCE_DIR}/tests/${TEST_NAME}/python-modules" + ) configure_file("environment.in" "tests/${TEST_NAME}/environment" @ONLY) @@ -810,7 +906,7 @@ foreach(TEST_NAME ${SYSTEM_TESTS}) WORKING_DIRECTORY ${tests_dir}/${TEST_NAME} ) - set_tests_properties(${SYSTEMTEST_PREFIX}${TEST_NAME} PROPERTIES TIMEOUT 90) + set_tests_properties(${SYSTEMTEST_PREFIX}${TEST_NAME} PROPERTIES TIMEOUT 180) math(EXPR BASEPORT "${BASEPORT} + 10") endforeach() @@ -870,7 +966,9 @@ if(ENABLE_WEBUI_SELENIUM_TEST) COMMAND ${tests_dir}/${TEST_NAME}/testrunner WORKING_DIRECTORY ${tests_dir}/${TEST_NAME} ) - set_tests_properties(${WEBUI_TEST_PREFIX}${TEST_NAME} PROPERTIES TIMEOUT 90) + set_tests_properties( + ${WEBUI_TEST_PREFIX}${TEST_NAME} PROPERTIES TIMEOUT 180 + ) math(EXPR BASEPORT "${BASEPORT} + 10") endforeach() endif() diff --git a/systemtests/environment.in b/systemtests/environment.in index 9028679940d..37573323c34 100644 --- a/systemtests/environment.in +++ b/systemtests/environment.in @@ -109,12 +109,15 @@ export OVIRT_SERVER=@ovirt_server@ # real postgres binaries are hidden on debian, instead there are wrappers # which we do not want for our tests if [ -d /usr/lib/postgresql ]; then - POSTGRES_BINARY_DIR=$(dirname $(find /usr/lib/postgresql | grep psql)) + POSTGRES_BINARY_DIR=$(dirname $(find -L /usr/lib/postgresql | grep psql)) export PATH=$POSTGRES_BINARY_DIR:$PATH else export PATH=/sbin:/usr/sbin:$PATH fi export PYTHONPATH=@pythonpath@ +# enable deprecated database handling in scripts +export BAREOS_TEST_RUNNING=yes + S3CMD="@S3CMD@" S3CFG="${PROJECT_SOURCE_DIR}/s3cfg" From 85c5553208e300416e7f003faeb566db48ae4970 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Sat, 29 Aug 2020 13:36:04 +0200 Subject: [PATCH 329/341] add libcloud to new plugin file structure --- core/src/plugins/filed/python/CMakeLists.txt | 13 +++++++++++++ .../{ => python/libcloud}/BareosFdPluginLibcloud.py | 0 .../{ => python/libcloud}/BareosLibcloudApi.py | 0 .../{ => python/libcloud}/bareos-fd-libcloud.py | 0 .../libcloud}/bareos_libcloud_api/__init__.py | 0 .../bareos_libcloud_api/bucket_explorer.py | 0 .../libcloud}/bareos_libcloud_api/debug.py | 0 .../bareos_libcloud_api/get_libcloud_driver.py | 0 .../libcloud}/bareos_libcloud_api/mtime.py | 0 .../libcloud}/bareos_libcloud_api/process_base.py | 0 .../libcloud}/bareos_libcloud_api/queue_message.py | 0 .../libcloud}/bareos_libcloud_api/utils.py | 0 .../libcloud}/bareos_libcloud_api/worker.py | 0 13 files changed, 13 insertions(+) rename core/src/plugins/filed/{ => python/libcloud}/BareosFdPluginLibcloud.py (100%) rename core/src/plugins/filed/{ => python/libcloud}/BareosLibcloudApi.py (100%) rename core/src/plugins/filed/{ => python/libcloud}/bareos-fd-libcloud.py (100%) rename core/src/plugins/filed/{ => python/libcloud}/bareos_libcloud_api/__init__.py (100%) rename core/src/plugins/filed/{ => python/libcloud}/bareos_libcloud_api/bucket_explorer.py (100%) rename core/src/plugins/filed/{ => python/libcloud}/bareos_libcloud_api/debug.py (100%) rename core/src/plugins/filed/{ => python/libcloud}/bareos_libcloud_api/get_libcloud_driver.py (100%) rename core/src/plugins/filed/{ => python/libcloud}/bareos_libcloud_api/mtime.py (100%) rename core/src/plugins/filed/{ => python/libcloud}/bareos_libcloud_api/process_base.py (100%) rename core/src/plugins/filed/{ => python/libcloud}/bareos_libcloud_api/queue_message.py (100%) rename core/src/plugins/filed/{ => python/libcloud}/bareos_libcloud_api/utils.py (100%) rename core/src/plugins/filed/{ => python/libcloud}/bareos_libcloud_api/worker.py (100%) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index bccf2f5b828..37915a8cbeb 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -177,6 +177,19 @@ set(PYFILES postgres/BareosFdPluginPostgres.py vmware/bareos-fd-vmware.py vmware/BareosFdPluginVMware.py + libcloud/bareos_libcloud_api + libcloud/bareos_libcloud_api/process_base.py + libcloud/bareos_libcloud_api/queue_message.py + libcloud/bareos_libcloud_api/mtime.py + libcloud/bareos_libcloud_api/debug.py + libcloud/bareos_libcloud_api/utils.py + libcloud/bareos_libcloud_api/get_libcloud_driver.py + libcloud/bareos_libcloud_api/worker.py + libcloud/bareos_libcloud_api/__init__.py + libcloud/bareos_libcloud_api/bucket_explorer.py + libcloud/BareosLibcloudApi.py + libcloud/bareos-fd-libcloud.py + libcloud/BareosFdPluginLibcloud.py ) install( diff --git a/core/src/plugins/filed/BareosFdPluginLibcloud.py b/core/src/plugins/filed/python/libcloud/BareosFdPluginLibcloud.py similarity index 100% rename from core/src/plugins/filed/BareosFdPluginLibcloud.py rename to core/src/plugins/filed/python/libcloud/BareosFdPluginLibcloud.py diff --git a/core/src/plugins/filed/BareosLibcloudApi.py b/core/src/plugins/filed/python/libcloud/BareosLibcloudApi.py similarity index 100% rename from core/src/plugins/filed/BareosLibcloudApi.py rename to core/src/plugins/filed/python/libcloud/BareosLibcloudApi.py diff --git a/core/src/plugins/filed/bareos-fd-libcloud.py b/core/src/plugins/filed/python/libcloud/bareos-fd-libcloud.py similarity index 100% rename from core/src/plugins/filed/bareos-fd-libcloud.py rename to core/src/plugins/filed/python/libcloud/bareos-fd-libcloud.py diff --git a/core/src/plugins/filed/bareos_libcloud_api/__init__.py b/core/src/plugins/filed/python/libcloud/bareos_libcloud_api/__init__.py similarity index 100% rename from core/src/plugins/filed/bareos_libcloud_api/__init__.py rename to core/src/plugins/filed/python/libcloud/bareos_libcloud_api/__init__.py diff --git a/core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py b/core/src/plugins/filed/python/libcloud/bareos_libcloud_api/bucket_explorer.py similarity index 100% rename from core/src/plugins/filed/bareos_libcloud_api/bucket_explorer.py rename to core/src/plugins/filed/python/libcloud/bareos_libcloud_api/bucket_explorer.py diff --git a/core/src/plugins/filed/bareos_libcloud_api/debug.py b/core/src/plugins/filed/python/libcloud/bareos_libcloud_api/debug.py similarity index 100% rename from core/src/plugins/filed/bareos_libcloud_api/debug.py rename to core/src/plugins/filed/python/libcloud/bareos_libcloud_api/debug.py diff --git a/core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py b/core/src/plugins/filed/python/libcloud/bareos_libcloud_api/get_libcloud_driver.py similarity index 100% rename from core/src/plugins/filed/bareos_libcloud_api/get_libcloud_driver.py rename to core/src/plugins/filed/python/libcloud/bareos_libcloud_api/get_libcloud_driver.py diff --git a/core/src/plugins/filed/bareos_libcloud_api/mtime.py b/core/src/plugins/filed/python/libcloud/bareos_libcloud_api/mtime.py similarity index 100% rename from core/src/plugins/filed/bareos_libcloud_api/mtime.py rename to core/src/plugins/filed/python/libcloud/bareos_libcloud_api/mtime.py diff --git a/core/src/plugins/filed/bareos_libcloud_api/process_base.py b/core/src/plugins/filed/python/libcloud/bareos_libcloud_api/process_base.py similarity index 100% rename from core/src/plugins/filed/bareos_libcloud_api/process_base.py rename to core/src/plugins/filed/python/libcloud/bareos_libcloud_api/process_base.py diff --git a/core/src/plugins/filed/bareos_libcloud_api/queue_message.py b/core/src/plugins/filed/python/libcloud/bareos_libcloud_api/queue_message.py similarity index 100% rename from core/src/plugins/filed/bareos_libcloud_api/queue_message.py rename to core/src/plugins/filed/python/libcloud/bareos_libcloud_api/queue_message.py diff --git a/core/src/plugins/filed/bareos_libcloud_api/utils.py b/core/src/plugins/filed/python/libcloud/bareos_libcloud_api/utils.py similarity index 100% rename from core/src/plugins/filed/bareos_libcloud_api/utils.py rename to core/src/plugins/filed/python/libcloud/bareos_libcloud_api/utils.py diff --git a/core/src/plugins/filed/bareos_libcloud_api/worker.py b/core/src/plugins/filed/python/libcloud/bareos_libcloud_api/worker.py similarity index 100% rename from core/src/plugins/filed/bareos_libcloud_api/worker.py rename to core/src/plugins/filed/python/libcloud/bareos_libcloud_api/worker.py From 8c311b81a510c51574425957a70681e66fdfef65 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Sat, 29 Aug 2020 13:40:47 +0200 Subject: [PATCH 330/341] tests: renamed libcloud test to new name pattern --- .../etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in | 0 .../etc/bareos/bareos-dir.d/client/bareos-fd.conf.in | 0 .../etc/bareos/bareos-dir.d/console/bareos-mon.conf.in | 0 .../etc/bareos/bareos-dir.d/director/bareos-dir.conf.in | 0 .../etc/bareos/bareos-dir.d/fileset/Catalog.conf.in | 0 .../etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in | 0 .../etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in | 0 .../etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in | 0 .../etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in | 0 .../etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in | 0 .../etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in | 0 .../etc/bareos/bareos-dir.d/messages/Daemon.conf.in | 0 .../etc/bareos/bareos-dir.d/messages/Standard.conf.in | 0 .../etc/bareos/bareos-dir.d/pool/Differential.conf | 0 .../etc/bareos/bareos-dir.d/pool/Full.conf | 0 .../etc/bareos/bareos-dir.d/pool/Incremental.conf | 0 .../etc/bareos/bareos-dir.d/pool/Scratch.conf | 0 .../etc/bareos/bareos-dir.d/profile/operator.conf | 0 .../etc/bareos/bareos-dir.d/storage/File.conf.in | 0 .../etc/bareos/bareos-fd.d/client/myself.conf.in | 0 .../etc/bareos/bareos-fd.d/director/bareos-dir.conf.in | 0 .../etc/bareos/bareos-fd.d/director/bareos-mon.conf.in | 0 .../etc/bareos/bareos-fd.d/messages/Standard.conf | 0 .../etc/bareos/bareos-sd.d/device/FileStorage.conf.in | 0 .../etc/bareos/bareos-sd.d/director/bareos-dir.conf.in | 0 .../etc/bareos/bareos-sd.d/director/bareos-mon.conf.in | 0 .../etc/bareos/bareos-sd.d/messages/Standard.conf | 0 .../etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in | 0 .../etc/bareos/bconsole.conf.in | 0 .../etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in | 0 .../etc/bareos/tray-monitor.d/director/Director-local.conf.in | 0 .../etc/bareos/tray-monitor.d/monitor/bareos-mon.conf.in | 0 .../etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in | 0 .../etc/libcloud_config.ini | 0 .../tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/testrunner | 0 35 files changed, 0 insertions(+), 0 deletions(-) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-dir.d/messages/Daemon.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-dir.d/messages/Standard.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-dir.d/pool/Differential.conf (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-dir.d/pool/Full.conf (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-dir.d/pool/Incremental.conf (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-dir.d/pool/Scratch.conf (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-dir.d/profile/operator.conf (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-dir.d/storage/File.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-fd.d/client/myself.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-fd.d/messages/Standard.conf (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-sd.d/device/FileStorage.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-sd.d/messages/Standard.conf (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/bconsole.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/tray-monitor.d/director/Director-local.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/tray-monitor.d/monitor/bareos-mon.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/etc/libcloud_config.ini (100%) rename systemtests/tests/{pyplug-fd-libcloud => py2plug-fd-libcloud}/testrunner (100%) diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/catalog/MyCatalog.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/client/bareos-fd.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/console/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/Catalog.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/SelfTest.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/job/BackupCatalog.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/job/RestoreFiles.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/job/backup-bareos-fd.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/jobdefs/DefaultJob.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/messages/Daemon.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/messages/Daemon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/messages/Daemon.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/messages/Daemon.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/messages/Standard.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/messages/Standard.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/messages/Standard.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/messages/Standard.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Differential.conf b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Differential.conf similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Differential.conf rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Differential.conf diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Full.conf b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Full.conf similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Full.conf rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Full.conf diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Incremental.conf b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Incremental.conf similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Incremental.conf rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Incremental.conf diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Scratch.conf b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Scratch.conf similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Scratch.conf rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/pool/Scratch.conf diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/profile/operator.conf b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/profile/operator.conf similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/profile/operator.conf rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/profile/operator.conf diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/storage/File.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/storage/File.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-dir.d/storage/File.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/storage/File.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-fd.d/client/myself.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-fd.d/client/myself.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-fd.d/client/myself.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-fd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-fd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-fd.d/messages/Standard.conf b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-fd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-fd.d/messages/Standard.conf rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-fd.d/messages/Standard.conf diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/device/FileStorage.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-sd.d/device/FileStorage.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/device/FileStorage.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-sd.d/device/FileStorage.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-sd.d/director/bareos-dir.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-sd.d/director/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/messages/Standard.conf b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-sd.d/messages/Standard.conf similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/messages/Standard.conf rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-sd.d/messages/Standard.conf diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-sd.d/storage/bareos-sd.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/bconsole.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bconsole.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/bconsole.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/bconsole.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/tray-monitor.d/client/FileDaemon-local.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/tray-monitor.d/director/Director-local.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/tray-monitor.d/director/Director-local.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/tray-monitor.d/director/Director-local.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/tray-monitor.d/director/Director-local.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/tray-monitor.d/monitor/bareos-mon.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/tray-monitor.d/monitor/bareos-mon.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/tray-monitor.d/monitor/bareos-mon.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/tray-monitor.d/monitor/bareos-mon.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in rename to systemtests/tests/py2plug-fd-libcloud/etc/bareos/tray-monitor.d/storage/StorageDaemon-local.conf.in diff --git a/systemtests/tests/pyplug-fd-libcloud/etc/libcloud_config.ini b/systemtests/tests/py2plug-fd-libcloud/etc/libcloud_config.ini similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/etc/libcloud_config.ini rename to systemtests/tests/py2plug-fd-libcloud/etc/libcloud_config.ini diff --git a/systemtests/tests/pyplug-fd-libcloud/testrunner b/systemtests/tests/py2plug-fd-libcloud/testrunner similarity index 100% rename from systemtests/tests/pyplug-fd-libcloud/testrunner rename to systemtests/tests/py2plug-fd-libcloud/testrunner From eb70d51a47c8ef377360df69c7860d416d8655ec Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Sat, 29 Aug 2020 14:35:42 +0200 Subject: [PATCH 331/341] adapt systemtest --- systemtests/CMakeLists.txt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 0c9390568c3..b9530793d3b 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -657,6 +657,28 @@ else() list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-local-fileset") endif() +if(TARGET python-fd) + if(S3CMD) + list(APPEND SYSTEM_TESTS "py2plug-fd-libcloud") + else() + message("s3cmd not found, disabling py2plug-fd-libcloud") + list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-libcloud") + endif() +else() + list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-libcloud") +endif() + +if(TARGET python3-fd) + if(S3CMD) + list(APPEND SYSTEM_TESTS "py3plug-fd-libcloud") + else() + message("s3cmd not found, disabling py3plug-fd-libcloud") + list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-libcloud") + endif() +else() + list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-libcloud") +endif() + if(TARGET python-fd) list(APPEND SYSTEM_TESTS "py2plug-fd-local-fileset-restoreobject") else() From e47aa17e4d6d764f3d3876495463a08a0e7a26b0 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Sat, 29 Aug 2020 16:33:20 +0200 Subject: [PATCH 332/341] fixup --- core/src/plugins/filed/python/CMakeLists.txt | 1 - systemtests/CMakeLists.txt | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 37915a8cbeb..7e13c1bf881 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -177,7 +177,6 @@ set(PYFILES postgres/BareosFdPluginPostgres.py vmware/bareos-fd-vmware.py vmware/BareosFdPluginVMware.py - libcloud/bareos_libcloud_api libcloud/bareos_libcloud_api/process_base.py libcloud/bareos_libcloud_api/queue_message.py libcloud/bareos_libcloud_api/mtime.py diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index b9530793d3b..77d5c02b570 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -65,7 +65,7 @@ macro(find_installed_binary_and_set_BINARY_NAME_TO_TEST_variable_for endmacro() -function(ConfigureFilesToSystemtest srcbasedir dirname globexpression +function(configurefilestosystemtest srcbasedir dirname globexpression configure_option srcdirname ) if(srcdirname STREQUAL "") From 6aebc88d8c18dd6d44c0dfcccab59185e75b5b34 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 29 Aug 2020 20:07:33 +0200 Subject: [PATCH 333/341] systemtests: add missing symlink for py3plug-fd-libcloud --- systemtests/tests/py3plug-fd-libcloud | 1 + 1 file changed, 1 insertion(+) create mode 120000 systemtests/tests/py3plug-fd-libcloud diff --git a/systemtests/tests/py3plug-fd-libcloud b/systemtests/tests/py3plug-fd-libcloud new file mode 120000 index 00000000000..b0f980e182e --- /dev/null +++ b/systemtests/tests/py3plug-fd-libcloud @@ -0,0 +1 @@ +py2plug-fd-libcloud \ No newline at end of file From 7286a3dd8c3117f171de556af62455e7b44b30a4 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Sat, 29 Aug 2020 20:22:29 +0200 Subject: [PATCH 334/341] cmake: add libcloud directory to PYTHONPATH for systemtest --- systemtests/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 77d5c02b570..9ce9b1fe81d 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -889,7 +889,6 @@ else() set(TEST_INFO_TEXT "running system tests on the sourcetree") endif() - foreach(TEST_NAME ${SYSTEM_TESTS}) message(STATUS "Configuring test: ${SYSTEMTEST_PREFIX}${TEST_NAME}") string(REGEX MATCH "py2plug" py_v2 "${TEST_NAME}") @@ -906,6 +905,7 @@ foreach(TEST_NAME ${SYSTEM_TESTS}) string( CONCAT pythonpath + "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/libcloud:" "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/percona-xtrabackup:" "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/ovirt:" "${CMAKE_SOURCE_DIR}/core/src/plugins/filed/python/postgres:" @@ -1004,7 +1004,6 @@ foreach(TEST_NAME_DISABLED ${SYSTEM_TESTS_DISABLED}) message(STATUS "Disabled test: ${SYSTEMTEST_PREFIX}${TEST_NAME_DISABLED}") endforeach() - configure_file( "CTestCustom.cmake.in" "${CMAKE_BINARY_DIR}/CTestCustom.cmake" @ONLY ) From d244fd9b49df7f69cb2a62a3e50315af548d15f0 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Sun, 30 Aug 2020 14:31:50 +0200 Subject: [PATCH 335/341] libcloud-plugin: removed plugin context and use new constants --- .../python/libcloud/BareosFdPluginLibcloud.py | 133 +++++++++--------- .../python/libcloud/BareosLibcloudApi.py | 17 +-- .../python/libcloud/bareos-fd-libcloud.py | 11 +- .../libcloud/bareos_libcloud_api/debug.py | 19 +-- 4 files changed, 83 insertions(+), 97 deletions(-) diff --git a/core/src/plugins/filed/python/libcloud/BareosFdPluginLibcloud.py b/core/src/plugins/filed/python/libcloud/BareosFdPluginLibcloud.py index d4117dc1a34..d5eeff57070 100755 --- a/core/src/plugins/filed/python/libcloud/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/python/libcloud/BareosFdPluginLibcloud.py @@ -22,14 +22,13 @@ import BareosFdPluginBaseclass import bareosfd -import bareos_fd_consts +from bareosfd import * import ConfigParser as configparser import datetime import dateutil.parser from bareos_libcloud_api.bucket_explorer import TASK_TYPE from bareos_libcloud_api.debug import debugmessage from bareos_libcloud_api.debug import jobmessage -from bareos_libcloud_api.debug import set_plugin_context import io import itertools import libcloud @@ -41,7 +40,6 @@ from BareosLibcloudApi import ERROR from BareosLibcloudApi import ABORT from BareosLibcloudApi import BareosLibcloudApi -from bareos_fd_consts import bRCs, bCFs, bIOPS, bJobMessageType, bFileType from libcloud.storage.types import Provider from libcloud.storage.types import ObjectDoesNotExistError from sys import version_info @@ -69,16 +67,15 @@ def read(self, n=None): class BareosFdPluginLibcloud(BareosFdPluginBaseclass.BareosFdPluginBaseclass): - def __init__(self, context, plugindef): - set_plugin_context(context) + def __init__(self, plugindef): debugmessage( 100, "BareosFdPluginLibcloud called with plugindef: %s" % (plugindef,) ) - super(BareosFdPluginLibcloud, self).__init__(context, plugindef) - super(BareosFdPluginLibcloud, self).parse_plugin_definition(context, plugindef) + super(BareosFdPluginLibcloud, self).__init__(plugindef) + super(BareosFdPluginLibcloud, self).parse_plugin_definition(plugindef) self.options["treat_download_errors_as_warnings"] = False - self.__parse_options(context) + self.__parse_options() self.last_run = datetime.datetime.fromtimestamp(self.since) self.last_run = self.last_run.replace(tzinfo=None) @@ -92,25 +89,25 @@ def __init__(self, context, plugindef): self.active = True self.api = None - def __parse_options(self, context): - accurate = bareos_fd_consts.bVariable["bVarAccurate"] - accurate = bareosfd.GetValue(context, accurate) + def __parse_options(self): + accurate = bVarAccurate + accurate = bareosfd.GetValue(accurate) if accurate is None or accurate == 0: self.options["accurate"] = False else: self.options["accurate"] = True - def parse_plugin_definition(self, context, plugindef): + def parse_plugin_definition(self, plugindef): debugmessage(100, "parse_plugin_definition()") config_filename = self.options.get("config_file") if config_filename: - if self.__parse_config_file(context, config_filename): - return bRCs["bRC_OK"] + if self.__parse_config_file(config_filename): + return bRC_OK debugmessage(100, "Could not load configfile %s" % (config_filename)) - jobmessage("M_FATAL", "Could not load configfile %s" % (config_filename)) - return bRCs["bRC_Error"] + jobmessage(M_FATAL, "Could not load configfile %s" % (config_filename)) + return bRC_Error - def __parse_config_file(self, context, config_filename): + def __parse_config_file(self, config_filename): """ Parse the config file given in the config_file plugin option """ @@ -131,9 +128,9 @@ def __parse_config_file(self, context, config_filename): ) return False - return self.__check_config(context, config_filename) + return self.__check_config(config_filename) - def __check_config(self, context, config_filename): + def __check_config(self, config_filename): """ Check the configuration and set or override options if necessary, considering mandatory: username and password in the [credentials] section @@ -216,23 +213,23 @@ def __check_config(self, context, config_filename): return True - def start_backup_job(self, context): + def start_backup_job(self): jobmessage( - "M_INFO", + M_INFO, "Start backup, try to connect to %s:%s" % (self.options["host"], self.options["port"]), ) if BareosLibcloudApi.probe_driver(self.options) == "failed": jobmessage( - "M_FATAL", + M_FATAL, "Could not connect to libcloud driver: %s:%s" % (self.options["host"], self.options["port"]), ) - return bRCs["bRC_Error"] + return bRC_Error jobmessage( - "M_INFO", + M_INFO, "Connected, last backup: %s (ts: %s)" % (self.last_run, self.since), ) @@ -245,25 +242,25 @@ def start_backup_job(self, context): debugmessage(100, "BareosLibcloudApi started") except Exception as e: debugmessage(100, "Error: %s" % e) - jobmessage("M_FATAL", "Starting BareosLibcloudApi failed: %s" % e) - return bRCs["bRC_Cancel"] + jobmessage(M_FATAL, "Starting BareosLibcloudApi failed: %s" % e) + return bRC_Cancel - return bRCs["bRC_OK"] + return bRC_OK - def end_backup_job(self, context): + def end_backup_job(self): if self.active: self.__shutdown() - return bRCs["bRC_OK"] + return bRC_OK - def check_file(self, context, fname): + def check_file(self, fname): # All existing files/objects are passed to bareos # If bareos has not seen one, it does not exists anymore - return bRCs["bRC_Error"] + return bRC_Error def __shutdown(self): self.active = False jobmessage( - "M_INFO", + M_INFO, "BareosFdPluginLibcloud finished with %d files" % (self.number_of_objects_to_backup), ) @@ -275,7 +272,7 @@ def __shutdown(self): self.api.shutdown() debugmessage(100, "BareosLibcloudApi is shut down") - def start_backup_file(self, context, savepkt): + def start_backup_file(self, savepkt): error = False while self.active: worker_result = self.api.check_worker_messages() @@ -301,10 +298,10 @@ def start_backup_file(self, context, savepkt): self.__shutdown() savepkt.fname = "" # dummy value if error: - jobmessage("M_FATAL", "Shutdown after worker error") - return bRCs["bRC_Cancel"] + jobmessage(M_FATAL, "Shutdown after worker error") + return bRC_Cancel else: - return bRCs["bRC_Skip"] + return bRC_Skip filename = FilenameConverter.BucketToBackup( "%s/%s" @@ -320,7 +317,7 @@ def start_backup_file(self, context, savepkt): savepkt.statp = statp savepkt.fname = filename - savepkt.type = bareos_fd_consts.bFileType["FT_REG"] + savepkt.type = FT_REG if self.current_backup_task["type"] == TASK_TYPE.DOWNLOADED: self.FILE = self.current_backup_task["data"] @@ -328,68 +325,68 @@ def start_backup_file(self, context, savepkt): try: self.FILE = io.open(self.current_backup_task["tmpfile"], "rb") except Exception as e: - jobmessage("M_FATAL", "Could not open temporary file for reading.") + jobmessage(M_FATAL, "Could not open temporary file for reading.") self.__shutdown() - return bRCs["bRC_Error"] + return bRC_Error elif self.current_backup_task["type"] == TASK_TYPE.STREAM: try: self.FILE = IterStringIO(self.current_backup_task["data"].as_stream()) except ObjectDoesNotExistError: if self.options["treat_download_errors_as_warnings"]: jobmessage( - "M_WARNING", + M_WARNING, "Skipped file %s because it does not exist anymore" % (self.current_backup_task["name"]), ) - return bRCs["bRC_Skip"] + return bRC_Skip else: jobmessage( - "M_ERROR", + M_ERROR, "File %s does not exist anymore" % (self.current_backup_task["name"]), ) - return bRCs["bRC_Error"] + return bRC_Error else: raise Exception(value='Wrong argument for current_backup_task["type"]') - return bRCs["bRC_OK"] + return bRC_OK - def create_file(self, context, restorepkt): + def create_file(self, restorepkt): debugmessage( 100, "create_file() entry point in Python called with %s\n" % (restorepkt) ) FNAME = FilenameConverter.BackupToBucket(restorepkt.ofname) dirname = os.path.dirname(FNAME) if not os.path.exists(dirname): - jobmessage("M_INFO", "Directory %s does not exist, creating it\n" % dirname) + jobmessage(M_INFO, "Directory %s does not exist, creating it\n" % dirname) os.makedirs(dirname) - if restorepkt.type == bFileType["FT_REG"]: - restorepkt.create_status = bCFs["CF_EXTRACT"] - return bRCs["bRC_OK"] + if restorepkt.type == FT_REG: + restorepkt.create_status = CF_EXTRACT + return bRC_OK - def plugin_io(self, context, IOP): + def plugin_io(self, IOP): if self.current_backup_task is None: - return bRCs["bRC_Error"] - if IOP.func == bIOPS["IO_OPEN"]: + return bRC_Error + if IOP.func == IO_OPEN: # Only used by the 'restore' path if IOP.flags & (os.O_CREAT | os.O_WRONLY): self.FILE = open(FilenameConverter.BackupToBucket(IOP.fname), "wb") - return bRCs["bRC_OK"] + return bRC_OK - elif IOP.func == bIOPS["IO_READ"]: + elif IOP.func == IO_READ: IOP.buf = bytearray(IOP.count) IOP.io_errno = 0 if self.FILE is None: - return bRCs["bRC_Error"] + return bRC_Error try: buf = self.FILE.read(IOP.count) IOP.buf[:] = buf IOP.status = len(buf) - return bRCs["bRC_OK"] + return bRC_OK except IOError as e: jobmessage( - "M_ERROR", + M_ERROR, "Cannot read from %s/%s: %s" % ( self.current_backup_task["bucket"], @@ -399,20 +396,20 @@ def plugin_io(self, context, IOP): ) IOP.status = 0 if self.options["treat_download_errors_as_warnings"]: - return bRCs["bRC_Skip"] + return bRC_Skip else: - return bRCs["bRC_Error"] + return bRC_Error - elif IOP.func == bIOPS["IO_WRITE"]: + elif IOP.func == IO_WRITE: try: self.FILE.write(IOP.buf) IOP.status = IOP.count IOP.io_errno = 0 except IOError as msg: IOP.io_errno = -1 - jobmessage("M_ERROR", "Failed to write data: %s" % (msg,)) - return bRCs["bRC_OK"] - elif IOP.func == bIOPS["IO_CLOSE"]: + jobmessage(M_ERROR, "Failed to write data: %s" % (msg,)) + return bRC_OK + elif IOP.func == IO_CLOSE: if self.FILE: self.FILE.close() if "type" in self.current_backup_task: @@ -430,13 +427,13 @@ def plugin_io(self, context, IOP): "Could not remove temporary file: %s" % (self.current_backup_task["tmpfile"]), ) - return bRCs["bRC_OK"] + return bRC_OK - return bRCs["bRC_OK"] + return bRC_OK - def end_backup_file(self, context): + def end_backup_file(self): if self.current_backup_task is not None: self.number_of_objects_to_backup += 1 - return bRCs["bRC_More"] + return bRC_More else: - return bRCs["bRC_OK"] + return bRC_OK diff --git a/core/src/plugins/filed/python/libcloud/BareosLibcloudApi.py b/core/src/plugins/filed/python/libcloud/BareosLibcloudApi.py index f4c42a79caf..8a1001fa433 100644 --- a/core/src/plugins/filed/python/libcloud/BareosLibcloudApi.py +++ b/core/src/plugins/filed/python/libcloud/BareosLibcloudApi.py @@ -1,3 +1,4 @@ +from bareosfd import M_INFO, M_ERROR from bareos_libcloud_api.bucket_explorer import BucketExplorer from bareos_libcloud_api.bucket_explorer import TASK_TYPE from bareos_libcloud_api.debug import debugmessage, jobmessage @@ -43,7 +44,7 @@ def __init__(self, options, last_run, tmp_dir_path): self.__create_tmp_dir() - jobmessage("M_INFO", "Initialize BucketExplorer") + jobmessage(M_INFO, "Initialize BucketExplorer") self.bucket_explorer = BucketExplorer( options, @@ -53,7 +54,7 @@ def __init__(self, options, last_run, tmp_dir_path): self.number_of_worker, ) - jobmessage("M_INFO", "Initialize %d Workers" % self.number_of_worker) + jobmessage(M_INFO, "Initialize %d Workers" % self.number_of_worker) self.worker = [ Worker( @@ -67,10 +68,10 @@ def __init__(self, options, last_run, tmp_dir_path): for i in range(self.number_of_worker) ] - jobmessage("M_INFO", "Start BucketExplorer") + jobmessage(M_INFO, "Start BucketExplorer") self.bucket_explorer.start() - jobmessage("M_INFO", "Start Workers") + jobmessage(M_INFO, "Start Workers") for w in self.worker: w.start() @@ -85,9 +86,9 @@ def check_worker_messages(self): try: message = self.message_queue.get_nowait() if message.type == MESSAGE_TYPE.INFO_MESSAGE: - jobmessage("M_INFO", message.message_string) + jobmessage(M_INFO, message.message_string) elif message.type == MESSAGE_TYPE.ERROR_MESSAGE: - jobmessage("M_ERROR", message.message_string) + jobmessage(M_ERROR, message.message_string) elif message.type == MESSAGE_TYPE.READY_MESSAGE: if message.worker_id == 0: self.count_bucket_explorer_ready += 1 @@ -100,7 +101,7 @@ def check_worker_messages(self): else: raise Exception(value="Unknown message type") except Exception as e: - jobmessage("M_INFO", "check_worker_messages exception: %s" % e) + jobmessage(M_INFO, "check_worker_messages exception: %s" % e) return SUCCESS def get_next_task(self): @@ -149,7 +150,7 @@ def shutdown(self): except: pass - jobmessage("M_INFO", "Finished shutdown of worker processes") + jobmessage(M_INFO, "Finished shutdown of worker processes") def __create_tmp_dir(self): debugmessage(100, "Try to create temporary directory: %s" % (self.tmp_dir_path)) diff --git a/core/src/plugins/filed/python/libcloud/bareos-fd-libcloud.py b/core/src/plugins/filed/python/libcloud/bareos-fd-libcloud.py index 44a6a1cc61b..7462e903c6b 100644 --- a/core/src/plugins/filed/python/libcloud/bareos-fd-libcloud.py +++ b/core/src/plugins/filed/python/libcloud/bareos-fd-libcloud.py @@ -19,9 +19,6 @@ # Author: Alexandre Bruyelles # -# Provided by the Bareos FD Python plugin interface -import bareos_fd_consts - # This module contains the wrapper functions called by the Bareos-FD, the # functions call the corresponding methods from your plugin class import BareosFdWrapper @@ -32,8 +29,10 @@ # This module contains the used plugin class import BareosFdPluginLibcloud +from bareosfd import bRC_OK + -def load_bareos_plugin(context, plugindef): +def load_bareos_plugin(plugindef): """ This function is called by the Bareos-FD to load the plugin We use it to instantiate the plugin class @@ -41,9 +40,9 @@ def load_bareos_plugin(context, plugindef): # BareosFdWrapper.bareos_fd_plugin_object is the module attribute that # holds the plugin class object BareosFdWrapper.bareos_fd_plugin_object = BareosFdPluginLibcloud.BareosFdPluginLibcloud( - context, plugindef + plugindef ) - return bareos_fd_consts.bRCs["bRC_OK"] + return bRC_OK # the rest is done in the Plugin module diff --git a/core/src/plugins/filed/python/libcloud/bareos_libcloud_api/debug.py b/core/src/plugins/filed/python/libcloud/bareos_libcloud_api/debug.py index 313d3413b62..deb143bc774 100644 --- a/core/src/plugins/filed/python/libcloud/bareos_libcloud_api/debug.py +++ b/core/src/plugins/filed/python/libcloud/bareos_libcloud_api/debug.py @@ -19,26 +19,15 @@ import os import bareosfd -from bareos_fd_consts import bJobMessageType debuglevel = 100 -plugin_context = None def jobmessage(message_type, message): - global plugin_context - if plugin_context != None: - message = "BareosFdPluginLibcloud [%s]: %s\n" % (os.getpid(), message) - bareosfd.JobMessage(plugin_context, bJobMessageType[message_type], message) + message = "BareosFdPluginLibcloud [%s]: %s\n" % (os.getpid(), message) + bareosfd.JobMessage(message_type, message) def debugmessage(level, message): - global plugin_context - if plugin_context != None: - message = "BareosFdPluginLibcloud [%s]: %s\n" % (os.getpid(), message) - bareosfd.DebugMessage(plugin_context, level, message) - - -def set_plugin_context(context): - global plugin_context - plugin_context = context + message = "BareosFdPluginLibcloud [%s]: %s\n" % (os.getpid(), message) + bareosfd.DebugMessage(level, message) From dd413551d1261f3cf4a9a5502f14b5596043a1a3 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Sun, 30 Aug 2020 14:32:21 +0200 Subject: [PATCH 336/341] libcloud-plugin: do not set StatPacket variables directly --- .../filed/python/libcloud/BareosFdPluginLibcloud.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/plugins/filed/python/libcloud/BareosFdPluginLibcloud.py b/core/src/plugins/filed/python/libcloud/BareosFdPluginLibcloud.py index d5eeff57070..3974d7e109f 100755 --- a/core/src/plugins/filed/python/libcloud/BareosFdPluginLibcloud.py +++ b/core/src/plugins/filed/python/libcloud/BareosFdPluginLibcloud.py @@ -310,10 +310,10 @@ def start_backup_file(self, savepkt): debugmessage(100, "Backup file: %s" % (filename,)) statp = bareosfd.StatPacket() - statp.size = self.current_backup_task["size"] - statp.mtime = self.current_backup_task["mtime"] - statp.atime = 0 - statp.ctime = 0 +# statp.size = self.current_backup_task["size"] +# statp.mtime = self.current_backup_task["mtime"] +# statp.atime = 0 +# statp.ctime = 0 savepkt.statp = statp savepkt.fname = filename From daac8c58a31662e1ea5b491e04980aa285a0f545 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 31 Aug 2020 10:22:20 +0200 Subject: [PATCH 337/341] libcloud plugin: install subdir libcloud/bareos_libcloud_api into plugins directory --- core/src/plugins/filed/python/CMakeLists.txt | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt index 7e13c1bf881..f711d962eeb 100644 --- a/core/src/plugins/filed/python/CMakeLists.txt +++ b/core/src/plugins/filed/python/CMakeLists.txt @@ -177,15 +177,6 @@ set(PYFILES postgres/BareosFdPluginPostgres.py vmware/bareos-fd-vmware.py vmware/BareosFdPluginVMware.py - libcloud/bareos_libcloud_api/process_base.py - libcloud/bareos_libcloud_api/queue_message.py - libcloud/bareos_libcloud_api/mtime.py - libcloud/bareos_libcloud_api/debug.py - libcloud/bareos_libcloud_api/utils.py - libcloud/bareos_libcloud_api/get_libcloud_driver.py - libcloud/bareos_libcloud_api/worker.py - libcloud/bareos_libcloud_api/__init__.py - libcloud/bareos_libcloud_api/bucket_explorer.py libcloud/BareosLibcloudApi.py libcloud/bareos-fd-libcloud.py libcloud/BareosFdPluginLibcloud.py @@ -196,3 +187,9 @@ install( DESTINATION ${plugindir} COMPONENT filedaemon ) + +install( + DIRECTORY libcloud/bareos_libcloud_api + DESTINATION ${plugindir} + COMPONENT filedaemon +) From 6ea33b6f99894c8928d849db29eb706bdeac61db Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Mon, 31 Aug 2020 11:03:52 +0200 Subject: [PATCH 338/341] systemtests: discover minio and add to tests environment --- core/CMakeLists.txt | 1 + core/cmake/BareosFindPrograms.cmake | 1 + systemtests/environment.in | 1 + 3 files changed, 3 insertions(+) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 3e390898c0a..cca46106a4e 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -925,6 +925,7 @@ message(" AWK: ${AWK}") message(" GAWK: ${GAWK}") message(" RPCGEN: ${RPCGEN}") message(" MTX: ${MTX}") +message(" MINIO: ${MINIO}") message(" S3CMD: ${S3CMD}") message(" XTRABACKUP: ${XTRABACKUP}") message(" DEVELOPER: ${developer}") diff --git a/core/cmake/BareosFindPrograms.cmake b/core/cmake/BareosFindPrograms.cmake index 8cd1d24c898..4cf79bcda0b 100644 --- a/core/cmake/BareosFindPrograms.cmake +++ b/core/cmake/BareosFindPrograms.cmake @@ -40,4 +40,5 @@ find_program(DBX dbx) find_program(MDB mdb) find_program(XTRABACKUP xtrabackup) find_program(S3CMD s3cmd) +find_program(MINIO minio) diff --git a/systemtests/environment.in b/systemtests/environment.in index 37573323c34..78331b67bcb 100644 --- a/systemtests/environment.in +++ b/systemtests/environment.in @@ -119,5 +119,6 @@ export PYTHONPATH=@pythonpath@ # enable deprecated database handling in scripts export BAREOS_TEST_RUNNING=yes +MINIO=@MINIO@ S3CMD="@S3CMD@" S3CFG="${PROJECT_SOURCE_DIR}/s3cfg" From ea1b6d9b2facf15f67ba56c3f59cba1ff7ca38ac Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 31 Aug 2020 12:14:31 +0200 Subject: [PATCH 339/341] systemtests: py2plug-fd-libcloud: parametrize for python2 and 3 testing --- .../etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in | 2 +- .../etc/bareos/bareos-fd.d/client/myself.conf.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in index 3a6bf166604..23103014380 100644 --- a/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in +++ b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-dir.d/fileset/PluginTest.conf.in @@ -5,6 +5,6 @@ FileSet { Options { signature = MD5 } - Plugin = "python:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-libcloud:config_file=etc/libcloud_config.ini:buckets_include=bareos-test" + Plugin = "@python_module_name@:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-libcloud:config_file=etc/libcloud_config.ini:buckets_include=bareos-test" } } diff --git a/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-fd.d/client/myself.conf.in b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-fd.d/client/myself.conf.in index 49039c29d18..3a7cce9488e 100644 --- a/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-fd.d/client/myself.conf.in +++ b/systemtests/tests/py2plug-fd-libcloud/etc/bareos/bareos-fd.d/client/myself.conf.in @@ -7,7 +7,7 @@ Client { # otherwise all filedaemon plugins (*-fd.so) from the "Plugin Directory". # Plugin Directory = "@fd_plugin_binary_path@" - Plugin Names = "python" + Plugin Names = "@python_module_name@" # if compatible is set to yes, we are compatible with bacula # if set to no, new bareos features are enabled which is the default From 85e7dcd0ea7e995b5b65251edecd6270d5c72969 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Mon, 31 Aug 2020 13:09:12 +0200 Subject: [PATCH 340/341] systemtests: prepare start_minio script --- systemtests/scripts/start_minio.sh | 50 +++++++++++++++++++ systemtests/scripts/stop_minio.sh | 20 ++++++++ .../tests/py2plug-fd-libcloud/testrunner | 4 ++ 3 files changed, 74 insertions(+) create mode 100755 systemtests/scripts/start_minio.sh create mode 100755 systemtests/scripts/stop_minio.sh diff --git a/systemtests/scripts/start_minio.sh b/systemtests/scripts/start_minio.sh new file mode 100755 index 00000000000..e9ace16fc52 --- /dev/null +++ b/systemtests/scripts/start_minio.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +set -e +set -u + +tmp="tmp" +logdir="log" +minio_tmp_data_dir="$tmp"/minio-data-directory +minio_port_number="$1" + +. environment + +if ! "${MINIO}" -v > /dev/null 2>&1; then + echo "$0: could not find minio binary" + exit 1 +fi + +if [ -d "$minio_tmp_data_dir" ]; then + rm -rf "$minio_tmp_data_dir" +fi + +mkdir "$minio_tmp_data_dir" + +echo "$0: starting minio server" + +tries=0 +while pidof "${MINIO}" > /dev/null; do + kill -SIGTERM "$(pidof "${MINIO}")" + sleep 0.1 + (( tries++ )) && [ $tries == '100' ] \ + && { echo "$0: could not stop minio server"; exit 2; } +done + +export MINIO_DOMAIN=localhost,127.0.0.1 +"${MINIO}" server --address \':$minio_port_number\' "$minio_tmp_data_dir" > "$logdir"/minio.log + +if ! pidof ${MINIO} > /dev/null; then + echo "$0: could not start minio server" + exit 2 +fi + +tries=0 +while ! s3cmd --config=etc/s3cfg-local-minio ls S3:// > /dev/null 2>&1; do + sleep 0.1 + (( tries++ )) && [ $tries == '20' ] \ + && { echo "$0: could not start minio server"; exit 3; } +done + +exit 0 + diff --git a/systemtests/scripts/stop_minio.sh b/systemtests/scripts/stop_minio.sh new file mode 100755 index 00000000000..80aa5a902c7 --- /dev/null +++ b/systemtests/scripts/stop_minio.sh @@ -0,0 +1,20 @@ +#!/bin/bash +. environment + +echo "$0: stopping minio server" + +tries=0 +while pidof minio > /dev/null; do + kill -SIGTERM "$(pidof minio)" + sleep 0.1 + (( tries++ )) && [ $tries == '100' ] \ + && { echo "$0: could not stop minio server"; exit 1; } +done + +if ! pidof minio; then + exit 0 +fi + +echo "$0: could not stop minio server" +exit 2 + diff --git a/systemtests/tests/py2plug-fd-libcloud/testrunner b/systemtests/tests/py2plug-fd-libcloud/testrunner index aa6a826c99e..4ab3df382e8 100755 --- a/systemtests/tests/py2plug-fd-libcloud/testrunner +++ b/systemtests/tests/py2plug-fd-libcloud/testrunner @@ -36,6 +36,8 @@ BackupDirectory="${tmp}/data" # Data will be placed at "${tmp}/data/". setup_data "$@" +"${rscripts}"/start_minio.sh 9001 + # create s3 content for test ${S3} rb --recursive --force s3://$bucket_name || echo "s3://$bucket_name does not exist" ${S3} mb s3://$bucket_name @@ -85,4 +87,6 @@ if ! diff -r tmp/data tmp/bareos-restores/$bucket_name/data; then export estat=1 fi +"${rscripts}"/stop_minio.sh + end_test From c63130c6a1935c658a29b6b48e3ab9c3a5ee65bc Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Mon, 31 Aug 2020 14:03:05 +0200 Subject: [PATCH 341/341] systemtest: libcloud: check requirements before enabling --- systemtests/CMakeLists.txt | 20 +++++++++++++++---- systemtests/environment.in | 2 ++ .../tests/py2plug-fd-libcloud/testrunner | 4 +++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt index 9ce9b1fe81d..4c1b1eaa2f5 100644 --- a/systemtests/CMakeLists.txt +++ b/systemtests/CMakeLists.txt @@ -657,11 +657,18 @@ else() list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-local-fileset") endif() +check_pymodule_available(2 libcloud) +check_pymodule_available(3 libcloud) if(TARGET python-fd) - if(S3CMD) + if(S3CMD + AND MINIO + AND PYMODULE_2_LIBCLOUD_FOUND + ) list(APPEND SYSTEM_TESTS "py2plug-fd-libcloud") else() - message("s3cmd not found, disabling py2plug-fd-libcloud") + message( + "S3CMD, MINIO or LIBCLOUD MODULE not found, disabling py2plug-fd-libcloud" + ) list(APPEND SYSTEM_TESTS_DISABLED "py2plug-fd-libcloud") endif() else() @@ -669,10 +676,15 @@ else() endif() if(TARGET python3-fd) - if(S3CMD) + if(S3CMD + AND MINIO + AND PYMODULE_3_LIBCLOUD_FOUND + ) list(APPEND SYSTEM_TESTS "py3plug-fd-libcloud") else() - message("s3cmd not found, disabling py3plug-fd-libcloud") + message( + "S3CMD, MINIO or LIBCLOUD MODULE not found, disabling py3plug-fd-libcloud" + ) list(APPEND SYSTEM_TESTS_DISABLED "py3plug-fd-libcloud") endif() else() diff --git a/systemtests/environment.in b/systemtests/environment.in index 78331b67bcb..0d37d7f39de 100644 --- a/systemtests/environment.in +++ b/systemtests/environment.in @@ -122,3 +122,5 @@ export BAREOS_TEST_RUNNING=yes MINIO=@MINIO@ S3CMD="@S3CMD@" S3CFG="${PROJECT_SOURCE_DIR}/s3cfg" + +SYSTEMTESTS_DIR=@CMAKE_CURRENT_SOURCE_DIR@ diff --git a/systemtests/tests/py2plug-fd-libcloud/testrunner b/systemtests/tests/py2plug-fd-libcloud/testrunner index 4ab3df382e8..7be6d5eefec 100755 --- a/systemtests/tests/py2plug-fd-libcloud/testrunner +++ b/systemtests/tests/py2plug-fd-libcloud/testrunner @@ -1,4 +1,6 @@ #!/bin/bash +set -e +set -u # # This systemtest tests the plugin functionality # of the Bareos FD by using the supplied module @@ -36,7 +38,7 @@ BackupDirectory="${tmp}/data" # Data will be placed at "${tmp}/data/". setup_data "$@" -"${rscripts}"/start_minio.sh 9001 +"${SYSTEMTESTS_DIR}"/scripts/start_minio.sh 9000 # create s3 content for test ${S3} rb --recursive --force s3://$bucket_name || echo "s3://$bucket_name does not exist"