]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
driver: add option to make missing drivers a fatal problem
authorDaniel P. Berrangé <berrange@redhat.com>
Thu, 19 Apr 2018 15:50:56 +0000 (16:50 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Tue, 24 Apr 2018 16:01:48 +0000 (17:01 +0100)
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@redhat.com>
src/driver.c
src/driver.h
src/remote/remote_daemon.c
src/security/virt-aa-helper.c
src/storage/storage_backend.c
tests/virdrivermoduletest.c

index 9b137c39e4ff38cb114a0d719572cd07af810baf..447f61d554fcae1cf44e3e0302608f7f42b1ac72 100644 (file)
@@ -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);
 
index e28c63ecc28b055ad4c60a1441ed5ed78a30276d..b4e50ab9873a5edf6148736f1a802d1a8a2856d6 100644 (file)
@@ -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);
index 3e02297eeecd1eedbad97a3f06427c63ffc6372c..b4f89d4fd7dd3d8eb327d1cd5ef029691d7ce42e 100644 (file)
@@ -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)
 {
     /*
index a1bc1090bfca6c4a96b2e1c0652e825cd7eec0b6..ee5e3b0701d6645e7a31bb0cb388ae47a000bd98 100644 (file)
@@ -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++) {
index 8c1dcf31b1218bbe15800de52ce1f59492cbe785..cb1bcc0944f0eea56529f238cd1da78821ceaf85 100644 (file)
@@ -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);
 
index 6c63ecd52bcd05699e71851bc49e6869ede00fcf..125183327bf19df6ee0ffb0d948165813495b32a 100644 (file)
@@ -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;