]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: drivermodule: Make sure that all compiled storage backends can be loaded
authorPeter Krempa <pkrempa@redhat.com>
Tue, 7 Feb 2017 17:58:39 +0000 (18:58 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 22 Feb 2017 08:31:33 +0000 (09:31 +0100)
Add a new storage driver registration function that will force the
backend code to fail if any of the storage backend modules can't be
loaded. This will make sure that they work and are present.

src/storage/storage_backend.c
src/storage/storage_backend.h
src/storage/storage_driver.c
src/storage/storage_driver.h
tests/virdrivermoduletest.c
tests/virstoragetest.c

index 32f45e8413d43477347d8482bf69b52739da5d95..ce278b99c5a31ebc8b327ac9810d2e89210b7c77 100644 (file)
@@ -87,7 +87,8 @@ static size_t virStorageFileBackendsCount;
 
 static int
 virStorageDriverLoadBackendModule(const char *name,
-                                  const char *regfunc)
+                                  const char *regfunc,
+                                  bool forceload)
 {
     char *modfile = NULL;
     int ret;
@@ -100,7 +101,14 @@ virStorageDriverLoadBackendModule(const char *name,
                                             "LIBVIRT_STORAGE_BACKEND_DIR")))
         return 1;
 
-    ret = virDriverLoadModuleFull(modfile, regfunc, NULL);
+    if ((ret = virDriverLoadModuleFull(modfile, regfunc, NULL)) != 0) {
+        if (forceload) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("failed to load storage backend module '%s'"),
+                           name);
+            ret = -1;
+        }
+    }
 
     VIR_FREE(modfile);
 
@@ -109,7 +117,7 @@ virStorageDriverLoadBackendModule(const char *name,
 
 
 # define VIR_STORAGE_BACKEND_REGISTER(func, module)                            \
-    if (virStorageDriverLoadBackendModule(module, #func) < 0)                  \
+    if (virStorageDriverLoadBackendModule(module, #func, allbackends) < 0)     \
         return -1
 #else
 # define VIR_STORAGE_BACKEND_REGISTER(func, module)                            \
@@ -118,7 +126,7 @@ virStorageDriverLoadBackendModule(const char *name,
 #endif
 
 int
-virStorageBackendDriversRegister(void)
+virStorageBackendDriversRegister(bool allbackends ATTRIBUTE_UNUSED)
 {
 #if WITH_STORAGE_DIR || WITH_STORAGE_FS
     VIR_STORAGE_BACKEND_REGISTER(virStorageBackendFsRegister, "fs");
index ca6c19c4579e72f4b2a2a117d6ac3926f3d6f84c..f433071f40f39ac8b16819ad351684333c7bfeb3 100644 (file)
@@ -198,7 +198,7 @@ struct _virStorageFileBackend {
     virStorageFileBackendChown  storageFileChown;
 };
 
-int virStorageBackendDriversRegister(void);
+int virStorageBackendDriversRegister(bool allmodules);
 
 int virStorageBackendRegister(virStorageBackendPtr backend);
 int virStorageBackendFileRegister(virStorageFileBackendPtr backend);
index 7fafbcf7585ed411c6a7eab25dd956f13043bc93..0bc047f23111d5168fcf689fe4657d89dfcd9d8c 100644 (file)
@@ -2838,9 +2838,10 @@ static virStateDriver stateDriver = {
     .stateReload = storageStateReload,
 };
 
-int storageRegister(void)
+static int
+storageRegisterFull(bool allbackends)
 {
-    if (virStorageBackendDriversRegister() < 0)
+    if (virStorageBackendDriversRegister(allbackends) < 0)
         return -1;
     if (virSetSharedStorageDriver(&storageDriver) < 0)
         return -1;
@@ -2850,6 +2851,20 @@ int storageRegister(void)
 }
 
 
+int
+storageRegister(void)
+{
+    return storageRegisterFull(false);
+}
+
+
+int
+storageRegisterAll(void)
+{
+    return storageRegisterFull(true);
+}
+
+
 /* ----------- file handlers cooperating with storage driver --------------- */
 static bool
 virStorageFileIsInitialized(const virStorageSource *src)
index 682c9ff827671a38b73ed4d5a695ba108f6e50c8..f0aca36711fd86a03e034285e987e9a8489bfa48 100644 (file)
@@ -70,5 +70,6 @@ char *virStoragePoolObjBuildTempFilePath(virStoragePoolObjPtr pool,
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
 
 int storageRegister(void);
+int storageRegisterAll(void);
 
 #endif /* __VIR_STORAGE_DRIVER_H__ */
index e440350c20eefe7ce5d1676b0273279be8d7f992..13d51a8e9a060721ca0a67aaa6cd5d2cc48f69a2 100644 (file)
@@ -71,7 +71,7 @@ mymain(void)
     TEST("interface");
 #endif
 #ifdef WITH_STORAGE
-    TEST("storage");
+    TEST_FULL("storage", "storageRegisterAll");
 #endif
 #ifdef WITH_NODE_DEVICES
     TEST("nodedev");
index d715fd762bf2c3b95961307c4ea1d83e128a8228..36567753baefefc59d0f9fa76cc047384d2fa4f0 100644 (file)
@@ -732,7 +732,7 @@ mymain(void)
     virStorageSourcePtr chain2; /* short for chain->backingStore */
     virStorageSourcePtr chain3; /* short for chain2->backingStore */
 
-    if (virStorageBackendDriversRegister() < 0)
+    if (virStorageBackendDriversRegister(false) < 0)
        return -1;
 
     /* Prep some files with qemu-img; if that is not found on PATH, or