return priority;
}
+
+#ifdef WITH_DRIVER_MODULES
+# define VIR_DAEMON_LOAD_MODULE(func, module) \
+ virDriverLoadModule(module, #func)
+#else
+# define VIR_DAEMON_LOAD_MODULE(func, module) \
+ func()
+#endif
static void daemonInitialize(void)
{
/*
* driver, since their resources must be auto-started before any
* domains can be auto-started.
*/
-#ifdef WITH_DRIVER_MODULES
/* We don't care if any of these fail, because the whole point
* is to allow users to only install modules they want to use.
* If they try to open a connection for a module that
* is not loaded they'll get a suitable error at that point
*/
-# ifdef WITH_NETWORK
- virDriverLoadModule("network");
-# endif
-# ifdef WITH_INTERFACE
- virDriverLoadModule("interface");
-# endif
-# ifdef WITH_STORAGE
- virDriverLoadModule("storage");
-# endif
-# ifdef WITH_NODE_DEVICES
- virDriverLoadModule("nodedev");
-# endif
-# ifdef WITH_SECRETS
- virDriverLoadModule("secret");
-# endif
-# ifdef WITH_NWFILTER
- virDriverLoadModule("nwfilter");
-# endif
-# ifdef WITH_XEN
- virDriverLoadModule("xen");
-# endif
-# ifdef WITH_LIBXL
- virDriverLoadModule("libxl");
-# endif
-# ifdef WITH_QEMU
- virDriverLoadModule("qemu");
-# endif
-# ifdef WITH_LXC
- virDriverLoadModule("lxc");
-# endif
-# ifdef WITH_UML
- virDriverLoadModule("uml");
-# endif
-# ifdef WITH_VBOX
- virDriverLoadModule("vbox");
-# endif
-# ifdef WITH_BHYVE
- virDriverLoadModule("bhyve");
-# endif
-# ifdef WITH_VZ
- virDriverLoadModule("vz");
-# endif
-#else
-# ifdef WITH_NETWORK
- networkRegister();
-# endif
-# ifdef WITH_INTERFACE
- interfaceRegister();
-# endif
-# ifdef WITH_STORAGE
- storageRegister();
-# endif
-# ifdef WITH_NODE_DEVICES
- nodedevRegister();
-# endif
-# ifdef WITH_SECRETS
- secretRegister();
-# endif
-# ifdef WITH_NWFILTER
- nwfilterRegister();
-# endif
-# ifdef WITH_XEN
- xenRegister();
-# endif
-# ifdef WITH_LIBXL
- libxlRegister();
-# endif
-# ifdef WITH_QEMU
- qemuRegister();
-# endif
-# ifdef WITH_LXC
- lxcRegister();
-# endif
-# ifdef WITH_UML
- umlRegister();
-# endif
-# ifdef WITH_VBOX
- vboxRegister();
-# endif
-# ifdef WITH_BHYVE
- bhyveRegister();
-# endif
-# ifdef WITH_VZ
- vzRegister();
-# endif
+#ifdef WITH_NETWORK
+ VIR_DAEMON_LOAD_MODULE(networkRegister, "network");
+#endif
+#ifdef WITH_INTERFACE
+ VIR_DAEMON_LOAD_MODULE(interfaceRegister, "interface");
+#endif
+#ifdef WITH_STORAGE
+ VIR_DAEMON_LOAD_MODULE(storageRegister, "storage");
+#endif
+#ifdef WITH_NODE_DEVICES
+ VIR_DAEMON_LOAD_MODULE(nodedevRegister, "nodedev");
+#endif
+#ifdef WITH_SECRETS
+ VIR_DAEMON_LOAD_MODULE(secretRegister, "secret");
+#endif
+#ifdef WITH_NWFILTER
+ VIR_DAEMON_LOAD_MODULE(nwfilterRegister, "nwfilter");
+#endif
+#ifdef WITH_XEN
+ VIR_DAEMON_LOAD_MODULE(xenRegister, "xen");
+#endif
+#ifdef WITH_LIBXL
+ VIR_DAEMON_LOAD_MODULE(libxlRegister, "libxl");
+#endif
+#ifdef WITH_QEMU
+ VIR_DAEMON_LOAD_MODULE(qemuRegister, "qemu");
+#endif
+#ifdef WITH_LXC
+ VIR_DAEMON_LOAD_MODULE(lxcRegister, "lxc");
+#endif
+#ifdef WITH_UML
+ VIR_DAEMON_LOAD_MODULE(umlRegister, "uml");
+#endif
+#ifdef WITH_VBOX
+ VIR_DAEMON_LOAD_MODULE(vboxRegister, "vbox");
+#endif
+#ifdef WITH_BHYVE
+ VIR_DAEMON_LOAD_MODULE(bhyveRegister, "bhyve");
+#endif
+#ifdef WITH_VZ
+ VIR_DAEMON_LOAD_MODULE(vzRegister, "vz");
#endif
}
+#undef VIR_DAEMON_LOAD_MODULE
static int ATTRIBUTE_NONNULL(3)
#include <config.h>
#include <unistd.h>
-#include <c-ctype.h>
#include "driver.h"
#include "viralloc.h"
#include "virfile.h"
#include "virlog.h"
-#include "virutil.h"
#include "configmake.h"
-#include "virstring.h"
VIR_LOG_INIT("driver");
}
-void *
-virDriverLoadModule(const char *name)
+int
+virDriverLoadModule(const char *name,
+ const char *regfunc)
{
char *modfile = NULL;
- char *fixedname = NULL;
- char *regfunc = NULL;
- char *tmp;
- void *handle = NULL;
+ int ret;
VIR_DEBUG("Module load %s", name);
abs_topbuilddir "/src/.libs",
DEFAULT_DRIVER_DIR,
"LIBVIRT_DRIVER_DIR")))
- return NULL;
-
- if (VIR_STRDUP_QUIET(fixedname, name) < 0) {
- VIR_ERROR(_("out of memory"));
- goto cleanup;
- }
-
- /* convert something_like_this into somethingLikeThis */
- while ((tmp = strchr(fixedname, '_'))) {
- memmove(tmp, tmp + 1, strlen(tmp));
- *tmp = c_toupper(*tmp);
- }
-
- if (virAsprintfQuiet(®func, "%sRegister", fixedname) < 0)
- goto cleanup;
+ return 1;
- virDriverLoadModuleFull(modfile, regfunc, &handle);
+ ret = virDriverLoadModuleFull(modfile, regfunc, NULL);
- cleanup:
VIR_FREE(modfile);
- VIR_FREE(fixedname);
- VIR_FREE(regfunc);
- return handle;
+
+ return ret;
}
VIR_LOG_INIT("tests.drivermoduletest");
+struct testDriverModuleData {
+ const char *module;
+ const char *regfunc;
+};
+
+
static int testDriverModule(const void *args)
{
- const char *name = args;
+ const struct testDriverModuleData *data = args;
/* coverity[leaked_storage] */
- if (!virDriverLoadModule(name))
+ if (virDriverLoadModule(data->module, data->regfunc) != 0)
return -1;
return 0;
mymain(void)
{
int ret = 0;
+ struct testDriverModuleData data;
-#define TEST(name) \
- do { \
- if (virTestRun("Test driver " # name, testDriverModule, name) < 0) \
- ret = -1; \
+#define TEST_FULL(name, fnc) \
+ do { \
+ data.module = name; \
+ data.regfunc = fnc; \
+ if (virTestRun("Test driver " # name, testDriverModule, &data) < 0) \
+ ret = -1; \
} while (0)
+#define TEST(name) TEST_FULL(name, name "Register")
+
#ifdef WITH_NETWORK
TEST("network");
#endif