diff --git a/src/driver.c b/src/driver.c index 9b137c39e4..447f61d554 100644 --- a/src/driver.c +++ b/src/driver.c @@ -103,15 +103,22 @@ virDriverLoadModuleFunc(void *handle, */ int virDriverLoadModuleFull(const char *path, - const char *regfunc) + const char *regfunc, + bool required) { void *rethandle = NULL; int (*regsym)(void); int ret = -1; if (!virFileExists(path)) { - VIR_INFO("Module '%s' does not exists", path); - return 1; + if (required) { + virReportSystemError(errno, + _("Failed to find module '%s'"), path); + return -1; + } else { + VIR_INFO("Module '%s' does not exist", path); + return 1; + } } if (!(rethandle = virDriverLoadModuleFile(path))) @@ -144,21 +151,29 @@ virDriverLoadModuleFull(const char *path, #else /* ! HAVE_DLFCN_H */ int virDriverLoadModuleFull(const char *path ATTRIBUTE_UNUSED, - const char *regfunc ATTRIBUTE_UNUSED) + const char *regfunc ATTRIBUTE_UNUSED, + bool required) { VIR_DEBUG("dlopen not available on this platform"); - /* Since we have no dlopen(), but definition we have no - * loadable modules on disk, so we can resaonably - * return '1' instead of an error. - */ - return 1; + if (required) { + virReportSystemError(ENOSYS, + _("Failed to find module '%s': %s"), path); + return -1; + } else { + /* Since we have no dlopen(), but definition we have no + * loadable modules on disk, so we can resaonably + * return '1' instead of an error. + */ + return 1; + } } #endif /* ! HAVE_DLFCN_H */ int virDriverLoadModule(const char *name, - const char *regfunc) + const char *regfunc, + bool required) { char *modfile = NULL; int ret; @@ -173,7 +188,7 @@ virDriverLoadModule(const char *name, "LIBVIRT_DRIVER_DIR"))) return -1; - ret = virDriverLoadModuleFull(modfile, regfunc); + ret = virDriverLoadModuleFull(modfile, regfunc, required); VIR_FREE(modfile); diff --git a/src/driver.h b/src/driver.h index e28c63ecc2..b4e50ab987 100644 --- a/src/driver.h +++ b/src/driver.h @@ -108,9 +108,11 @@ int virSetSharedSecretDriver(virSecretDriverPtr driver) ATTRIBUTE_RETURN_CHECK; int virSetSharedStorageDriver(virStorageDriverPtr driver) ATTRIBUTE_RETURN_CHECK; int virDriverLoadModule(const char *name, - const char *regfunc); + const char *regfunc, + bool required); int virDriverLoadModuleFull(const char *path, - const char *regfunc); + const char *regfunc, + bool required); virConnectPtr virGetConnectInterface(void); virConnectPtr virGetConnectNetwork(void); diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index 3e02297eee..b4f89d4fd7 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -295,7 +295,7 @@ static int daemonErrorLogFilter(virErrorPtr err, int priority) #define VIR_DAEMON_LOAD_MODULE(func, module) \ - virDriverLoadModule(module, #func) + virDriverLoadModule(module, #func, false) static void daemonInitialize(void) { /* diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index a1bc1090bf..ee5e3b0701 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -964,7 +964,7 @@ get_files(vahControl * ctl) /* load the storage driver so that backing store can be accessed */ #ifdef WITH_STORAGE - virDriverLoadModule("storage", "storageRegister"); + virDriverLoadModule("storage", "storageRegister", false); #endif for (i = 0; i < ctl->def->ndisks; i++) { diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 8c1dcf31b1..cb1bcc0944 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -97,14 +97,7 @@ virStorageDriverLoadBackendModule(const char *name, "LIBVIRT_STORAGE_BACKEND_DIR"))) return -1; - if ((ret = virDriverLoadModuleFull(modfile, regfunc)) != 0) { - if (forceload) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to load storage backend module '%s'"), - name); - ret = -1; - } - } + ret = virDriverLoadModuleFull(modfile, regfunc, forceload); VIR_FREE(modfile); diff --git a/tests/virdrivermoduletest.c b/tests/virdrivermoduletest.c index 6c63ecd52b..125183327b 100644 --- a/tests/virdrivermoduletest.c +++ b/tests/virdrivermoduletest.c @@ -41,7 +41,7 @@ static int testDriverModule(const void *args) const struct testDriverModuleData *data = args; /* coverity[leaked_storage] */ - if (virDriverLoadModule(data->module, data->regfunc) != 0) + if (virDriverLoadModule(data->module, data->regfunc, true) != 0) return -1; return 0;