storage: create separate loadable modules for storage file drivers

The storage file drivers are currently loaded as a side effect of
loading the storage driver. This is a bogus dependancy because the
storage file code has no interaction with the storage drivers, and
even ultimately be running in a completely separate daemon.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2018-04-25 14:37:07 +01:00
parent 1421e7168c
commit 01888af0e2
7 changed files with 111 additions and 32 deletions

View File

@ -1390,6 +1390,8 @@ rm -f $RPM_BUILD_ROOT%{_libdir}/libvirt/connection-driver/*.la
rm -f $RPM_BUILD_ROOT%{_libdir}/libvirt/connection-driver/*.a
rm -f $RPM_BUILD_ROOT%{_libdir}/libvirt/storage-backend/*.la
rm -f $RPM_BUILD_ROOT%{_libdir}/libvirt/storage-backend/*.a
rm -f $RPM_BUILD_ROOT%{_libdir}/libvirt/storage-file/*.la
rm -f $RPM_BUILD_ROOT%{_libdir}/libvirt/storage-file/*.a
%if %{with_wireshark}
rm -f $RPM_BUILD_ROOT%{wireshark_plugindir}/libvirt.la
%endif
@ -1892,6 +1894,7 @@ exit 0
%attr(0755, root, root) %{_libexecdir}/libvirt_parthelper
%{_libdir}/%{name}/connection-driver/libvirt_driver_storage.so
%{_libdir}/%{name}/storage-backend/libvirt_storage_backend_fs.so
%{_libdir}/%{name}/storage-file/libvirt_storage_file_fs.so
%files daemon-driver-storage-disk
%{_libdir}/%{name}/storage-backend/libvirt_storage_backend_disk.so
@ -1911,6 +1914,7 @@ exit 0
%if %{with_storage_gluster}
%files daemon-driver-storage-gluster
%{_libdir}/%{name}/storage-backend/libvirt_storage_backend_gluster.so
%{_libdir}/%{name}/storage-file/libvirt_storage_file_gluster.so
%endif
%if %{with_storage_rbd}

View File

@ -14,6 +14,9 @@ STORAGE_DRIVER_SOURCES = \
STORAGE_DRIVER_FS_SOURCES = \
storage/storage_backend_fs.h \
storage/storage_backend_fs.c \
$(NULL)
STORAGE_FILE_FS_SOURCES = \
storage/storage_file_fs.h \
storage/storage_file_fs.c \
$(NULL)
@ -57,6 +60,9 @@ STORAGE_DRIVER_SHEEPDOG_SOURCES = \
STORAGE_DRIVER_GLUSTER_SOURCES = \
storage/storage_backend_gluster.h \
storage/storage_backend_gluster.c \
$(NULL)
STORAGE_FILE_GLUSTER_SOURCES = \
storage/storage_file_gluster.h \
storage/storage_file_gluster.c \
$(NULL)
@ -80,6 +86,7 @@ STATEFUL_DRIVER_SOURCE_FILES += $(STORAGE_DRIVER_SOURCES)
EXTRA_DIST += \
$(STORAGE_DRIVER_SOURCES) \
$(STORAGE_DRIVER_FS_SOURCES) \
$(STORAGE_FILE_FS_SOURCES) \
$(STORAGE_DRIVER_LVM_SOURCES) \
$(STORAGE_DRIVER_ISCSI_SOURCES) \
$(STORAGE_DRIVER_SCSI_SOURCES) \
@ -88,6 +95,7 @@ EXTRA_DIST += \
$(STORAGE_DRIVER_RBD_SOURCES) \
$(STORAGE_DRIVER_SHEEPDOG_SOURCES) \
$(STORAGE_DRIVER_GLUSTER_SOURCES) \
$(STORAGE_FILE_GLUSTER_SOURCES) \
$(STORAGE_DRIVER_ZFS_SOURCES) \
$(STORAGE_DRIVER_VSTORAGE_SOURCES) \
$(STORAGE_HELPER_DISK_SOURCES) \
@ -96,6 +104,9 @@ EXTRA_DIST += \
storagebackenddir = $(libdir)/libvirt/storage-backend
storagebackend_LTLIBRARIES =
storagefiledir = $(libdir)/libvirt/storage-file
storagefile_LTLIBRARIES =
# Needed to keep automake quiet about conditionals
libvirt_driver_storage_impl_la_SOURCES =
libvirt_driver_storage_impl_la_CFLAGS = \
@ -136,6 +147,19 @@ libvirt_storage_backend_fs_la_LIBADD = \
libvirt.la \
../gnulib/lib/libgnu.la \
$(NULL)
libvirt_storage_file_fs_la_SOURCES = $(STORAGE_FILE_FS_SOURCES)
libvirt_storage_file_fs_la_CFLAGS = \
-I$(srcdir)/conf \
$(AM_CFLAGS) \
$(NULL)
storagefile_LTLIBRARIES += libvirt_storage_file_fs.la
libvirt_storage_file_fs_la_LDFLAGS = $(AM_LDFLAGS_MOD)
libvirt_storage_file_fs_la_LIBADD = \
libvirt.la \
../gnulib/lib/libgnu.la \
$(NULL)
endif WITH_STORAGE
if WITH_STORAGE_LVM
@ -270,6 +294,22 @@ libvirt_storage_backend_gluster_la_CFLAGS = \
storagebackend_LTLIBRARIES += libvirt_storage_backend_gluster.la
libvirt_storage_backend_gluster_la_LDFLAGS = $(AM_LDFLAGS_MOD)
libvirt_storage_file_gluster_la_SOURCES = $(STORAGE_FILE_GLUSTER_SOURCES)
libvirt_storage_file_gluster_la_LIBADD = \
libvirt.la \
$(GLUSTERFS_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
libvirt_storage_file_gluster_la_CFLAGS = \
-I$(srcdir)/conf \
$(GLUSTERFS_CFLAGS) \
$(AM_CFLAGS) \
$(NULL)
storagefile_LTLIBRARIES += libvirt_storage_file_gluster.la
libvirt_storage_file_gluster_la_LDFLAGS = $(AM_LDFLAGS_MOD)
endif WITH_STORAGE_GLUSTER
if WITH_STORAGE_ZFS

View File

@ -32,7 +32,6 @@
#include "virerror.h"
#include "storage_backend_fs.h"
#include "storage_file_fs.h"
#include "storage_util.h"
#include "storage_conf.h"
#include "vircommand.h"
@ -713,8 +712,5 @@ virStorageBackendFsRegister(void)
return -1;
#endif /* WITH_STORAGE_FS */
if (virStorageFileFsRegister() < 0)
return -1;
return 0;
}

View File

@ -24,7 +24,6 @@
#include <glusterfs/api/glfs.h>
#include "storage_backend_gluster.h"
#include "storage_file_gluster.h"
#include "storage_conf.h"
#include "viralloc.h"
#include "virerror.h"
@ -567,8 +566,5 @@ virStorageBackendGlusterRegister(void)
if (virStorageBackendRegister(&virStorageBackendGluster) < 0)
return -1;
if (virStorageFileGlusterRegister() < 0)
return -1;
return 0;
}

View File

@ -4117,7 +4117,9 @@ virStorageFileGetBackendForSupportCheck(const virStorageSource *src,
actualType = virStorageSourceGetActualType(src);
*backend = virStorageFileBackendForTypeInternal(actualType, src->protocol, false);
if (virStorageFileBackendForType(actualType, src->protocol, false, backend) < 0)
return -1;
return 0;
}
@ -4234,8 +4236,10 @@ virStorageFileInitAs(virStorageSourcePtr src,
else
src->drv->gid = gid;
if (!(src->drv->backend = virStorageFileBackendForType(actualType,
src->protocol)))
if (virStorageFileBackendForType(actualType,
src->protocol,
true,
&src->drv->backend) < 0)
goto error;
if (src->drv->backend->backendInit &&

View File

@ -32,6 +32,7 @@
#include "internal.h"
#include "virstoragefilebackend.h"
#include "virlog.h"
#include "virmodule.h"
#include "virfile.h"
#include "configmake.h"
@ -44,6 +45,46 @@ VIR_LOG_INIT("storage.storage_source_backend");
static virStorageFileBackendPtr virStorageFileBackends[VIR_STORAGE_BACKENDS_MAX];
static size_t virStorageFileBackendsCount;
#define STORAGE_FILE_MODULE_DIR LIBDIR "/libvirt/storage-file"
static int
virStorageFileLoadBackendModule(const char *name,
const char *regfunc,
bool forceload)
{
char *modfile = NULL;
int ret;
if (!(modfile = virFileFindResourceFull(name,
"libvirt_storage_file_",
".so",
abs_topbuilddir "/src/.libs",
STORAGE_FILE_MODULE_DIR,
"LIBVIRT_STORAGE_FILE_DIR")))
return -1;
ret = virModuleLoad(modfile, regfunc, forceload);
VIR_FREE(modfile);
return ret;
}
static int virStorageFileBackendOnceInit(void)
{
#if WITH_STORAGE_DIR || WITH_STORAGE_FS
if (virStorageFileLoadBackendModule("fs", "virStorageFileFsRegister", false) < 0)
return -1;
#endif /* WITH_STORAGE_DIR || WITH_STORAGE_FS */
#if WITH_STORAGE_GLUSTER
if (virStorageFileLoadBackendModule("gluster", "virStorageFileGlusterRegister", false) < 0)
return -1;
#endif /* WITH_STORAGE_GLUSTER */
return 0;
}
VIR_ONCE_GLOBAL_INIT(virStorageFileBackend)
int
virStorageFileBackendRegister(virStorageFileBackendPtr backend)
@ -65,25 +106,32 @@ virStorageFileBackendRegister(virStorageFileBackendPtr backend)
return 0;
}
virStorageFileBackendPtr
virStorageFileBackendForTypeInternal(int type,
int protocol,
bool report)
int
virStorageFileBackendForType(int type,
int protocol,
bool required,
virStorageFileBackendPtr *backend)
{
size_t i;
*backend = NULL;
if (virStorageFileBackendInitialize() < 0)
return -1;
for (i = 0; i < virStorageFileBackendsCount; i++) {
if (virStorageFileBackends[i]->type == type) {
if (type == VIR_STORAGE_TYPE_NETWORK &&
virStorageFileBackends[i]->protocol != protocol)
continue;
return virStorageFileBackends[i];
*backend = virStorageFileBackends[i];
return 0;
}
}
if (!report)
return NULL;
if (!required)
return 0;
if (type == VIR_STORAGE_TYPE_NETWORK) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@ -96,13 +144,5 @@ virStorageFileBackendForTypeInternal(int type,
virStorageTypeToString(type));
}
return NULL;
}
virStorageFileBackendPtr
virStorageFileBackendForType(int type,
int protocol)
{
return virStorageFileBackendForTypeInternal(type, protocol, true);
return -1;
}

View File

@ -71,11 +71,10 @@ typedef int
uid_t uid,
gid_t gid);
virStorageFileBackendPtr virStorageFileBackendForType(int type, int protocol);
virStorageFileBackendPtr virStorageFileBackendForTypeInternal(int type,
int protocol,
bool report);
int virStorageFileBackendForType(int type,
int protocol,
bool required,
virStorageFileBackendPtr *backend);
struct _virStorageFileBackend {
int type;