[PATCH 08/14] driver: add option to make missing drivers a fatal problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently the driver module loading code does not report an error if the
driver module is physically missing on disk. This is useful for distro
packaging optional pieces. When the daemons are split up into one daemon
per driver, we will expect module loading to always succeed. If a driver
is not desired, the entire daemon should not be installed.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/driver.c                  | 37 ++++++++++++++++++++++++++-----------
 src/driver.h                  |  6 ++++--
 src/remote/remote_daemon.c    |  2 +-
 src/storage/storage_backend.c |  9 +--------
 tests/virdrivermoduletest.c   |  2 +-
 5 files changed, 33 insertions(+), 23 deletions(-)

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/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;
-- 
2.14.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux