From 93a3f516ee5453f9fbea63a2e9d1495fc369d226 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 7 Feb 2017 18:58:39 +0100 Subject: [PATCH] tests: drivermodule: Make sure that all compiled storage backends can be loaded 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 | 16 ++++++++++++---- src/storage/storage_backend.h | 2 +- src/storage/storage_driver.c | 19 +++++++++++++++++-- src/storage/storage_driver.h | 1 + tests/virdrivermoduletest.c | 2 +- tests/virstoragetest.c | 2 +- 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 32f45e8413..ce278b99c5 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -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"); diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h index ca6c19c457..f433071f40 100644 --- a/src/storage/storage_backend.h +++ b/src/storage/storage_backend.h @@ -198,7 +198,7 @@ struct _virStorageFileBackend { virStorageFileBackendChown storageFileChown; }; -int virStorageBackendDriversRegister(void); +int virStorageBackendDriversRegister(bool allmodules); int virStorageBackendRegister(virStorageBackendPtr backend); int virStorageBackendFileRegister(virStorageFileBackendPtr backend); diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 7fafbcf758..0bc047f231 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -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) diff --git a/src/storage/storage_driver.h b/src/storage/storage_driver.h index 682c9ff827..f0aca36711 100644 --- a/src/storage/storage_driver.h +++ b/src/storage/storage_driver.h @@ -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__ */ diff --git a/tests/virdrivermoduletest.c b/tests/virdrivermoduletest.c index e440350c20..13d51a8e9a 100644 --- a/tests/virdrivermoduletest.c +++ b/tests/virdrivermoduletest.c @@ -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"); diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index d715fd762b..36567753ba 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -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