提交 0a6d3e51 编写于 作者: P Peter Krempa

storage: Turn storage backends into dynamic modules

If driver modules are enabled turn storage driver backends into
dynamically loadable objects. This will allow greater modularity for
binary distributions, where heavyweight dependencies as rbd and gluster
can be avoided by selecting only a subset of drivers if the rest is not
necessary.

The storage modules are installed into 'LIBDIR/libvirt/storage-backend/'
and users can override the location by using
'LIBVIRT_STORAGE_BACKEND_DIR' environment variable.

rpm based distros will at this point install all the backends when
libvirt-daemon-driver-storage package is installed.
上级 4fb105f6
......@@ -1239,6 +1239,8 @@ rm -f $RPM_BUILD_ROOT%{_libdir}/libvirt/lock-driver/*.la
rm -f $RPM_BUILD_ROOT%{_libdir}/libvirt/lock-driver/*.a
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
%if %{with_wireshark}
%if 0%{fedora} >= 24
rm -f $RPM_BUILD_ROOT%{_libdir}/wireshark/plugins/libvirt.la
......@@ -1694,6 +1696,21 @@ exit 0
%files daemon-driver-storage
%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-backend/libvirt_storage_backend_disk.so
%{_libdir}/%{name}/storage-backend/libvirt_storage_backend_logical.so
%{_libdir}/%{name}/storage-backend/libvirt_storage_backend_scsi.so
%{_libdir}/%{name}/storage-backend/libvirt_storage_backend_iscsi.so
%{_libdir}/%{name}/storage-backend/libvirt_storage_backend_mpath.so
%if %{with_storage_gluster}
%{_libdir}/%{name}/storage-backend/libvirt_storage_backend_gluster.so
%endif
%if %{with_storage_rbd}
%{_libdir}/%{name}/storage-backend/libvirt_storage_backend_rbd.so
%endif
%if %{with_storage_sheepdog}
%{_libdir}/%{name}/storage-backend/libvirt_storage_backend_sheepdog.so
%endif
%if %{with_qemu}
%files daemon-driver-qemu
......
......@@ -972,9 +972,12 @@ SECRET_DRIVER_SOURCES = \
secret/secret_driver.h secret/secret_driver.c
# Storage backend specific impls
STORAGE_DRIVER_BACKEND_SOURCES = \
storage/storage_backend.h storage/storage_backend.c
STORAGE_DRIVER_SOURCES = \
storage/storage_driver.h storage/storage_driver.c \
storage/storage_backend.h storage/storage_backend.c \
$(STORAGE_DRIVER_BACKEND_SOURCES) \
storage/storage_util.h storage/storage_util.c
STORAGE_DRIVER_FS_SOURCES = \
......@@ -1661,6 +1664,12 @@ if WITH_BLKID
libvirt_driver_storage_impl_la_CFLAGS += $(BLKID_CFLAGS)
libvirt_driver_storage_impl_la_LIBADD += $(BLKID_LIBS)
endif WITH_BLKID
if WITH_DRIVER_MODULES
storagebackenddir = $(libdir)/libvirt/storage-backend
storagebackend_LTLIBRARIES =
endif WITH_DRIVER_MODULES
if WITH_STORAGE
noinst_LTLIBRARIES += libvirt_driver_storage_impl.la
libvirt_driver_storage_la_SOURCES =
......@@ -1682,8 +1691,14 @@ libvirt_storage_backend_fs_la_CFLAGS = \
-I$(srcdir)/conf \
$(AM_CFLAGS)
if WITH_DRIVER_MODULES
storagebackend_LTLIBRARIES += libvirt_storage_backend_fs.la
libvirt_storage_backend_fs_la_LDFLAGS = \
-module -avoid-version $(AM_LDFLAGS)
else ! WITH_DRIVER_MODULES
noinst_LTLIBRARIES += libvirt_storage_backend_fs.la
libvirt_driver_storage_impl_la_LIBADD += libvirt_storage_backend_fs.la
endif ! WITH_DRIVER_MODULES
endif WITH_STORAGE
if WITH_STORAGE_LVM
......@@ -1693,9 +1708,15 @@ libvirt_storage_backend_logical_la_CFLAGS = \
-I$(srcdir)/conf \
$(AM_CFLAGS)
if WITH_DRIVER_MODULES
storagebackend_LTLIBRARIES += libvirt_storage_backend_logical.la
libvirt_storage_backend_logical_la_LDFLAGS = \
-module -avoid-version $(AM_LDFLAGS)
else ! WITH_DRIVER_MODULES
noinst_LTLIBRARIES += libvirt_storage_backend_logical.la
libvirt_driver_storage_impl_la_LIBADD += \
libvirt_storage_backend_logical.la
endif ! WITH_DRIVER_MODULES
endif WITH_STORAGE_LVM
if WITH_STORAGE_ISCSI
......@@ -1706,9 +1727,15 @@ libvirt_storage_backend_iscsi_la_CFLAGS = \
-I$(srcdir)/secret \
$(AM_CFLAGS)
if WITH_DRIVER_MODULES
storagebackend_LTLIBRARIES += libvirt_storage_backend_iscsi.la
libvirt_storage_backend_iscsi_la_LDFLAGS = \
-module -avoid-version $(AM_LDFLAGS)
else ! WITH_DRIVER_MODULES
noinst_LTLIBRARIES += libvirt_storage_backend_iscsi.la
libvirt_driver_storage_impl_la_LIBADD += \
libvirt_storage_backend_iscsi.la
endif ! WITH_DRIVER_MODULES
endif WITH_STORAGE_ISCSI
if WITH_STORAGE_SCSI
......@@ -1717,8 +1744,14 @@ libvirt_storage_backend_scsi_la_CFLAGS = \
-I$(srcdir)/conf \
$(AM_CFLAGS)
if WITH_DRIVER_MODULES
storagebackend_LTLIBRARIES += libvirt_storage_backend_scsi.la
libvirt_storage_backend_scsi_la_LDFLAGS = \
-module -avoid-version $(AM_LDFLAGS)
else ! WITH_DRIVER_MODULES
noinst_LTLIBRARIES += libvirt_storage_backend_scsi.la
libvirt_driver_storage_impl_la_LIBADD += libvirt_storage_backend_scsi.la
endif ! WITH_DRIVER_MODULES
endif WITH_STORAGE_SCSI
if WITH_STORAGE_MPATH
......@@ -1730,9 +1763,15 @@ libvirt_storage_backend_mpath_la_CFLAGS = \
$(DEVMAPPER_CFLAGS) \
$(AM_CFLAGS)
if WITH_DRIVER_MODULES
storagebackend_LTLIBRARIES += libvirt_storage_backend_mpath.la
libvirt_storage_backend_mpath_la_LDFLAGS = \
-module -avoid-version $(AM_LDFLAGS)
else ! WITH_DRIVER_MODULES
noinst_LTLIBRARIES += libvirt_storage_backend_mpath.la
libvirt_driver_storage_impl_la_LIBADD += \
libvirt_storage_backend_mpath.la
endif ! WITH_DRIVER_MODULES
endif WITH_STORAGE_MPATH
if WITH_STORAGE_DISK
......@@ -1741,8 +1780,14 @@ libvirt_storage_backend_disk_la_CFLAGS = \
-I$(srcdir)/conf \
$(AM_CFLAGS)
if WITH_DRIVER_MODULES
storagebackend_LTLIBRARIES += libvirt_storage_backend_disk.la
libvirt_storage_backend_disk_la_LDFLAGS = \
-module -avoid-version $(AM_LDFLAGS)
else ! WITH_DRIVER_MODULES
noinst_LTLIBRARIES += libvirt_storage_backend_disk.la
libvirt_driver_storage_impl_la_LIBADD += libvirt_storage_backend_disk.la
endif ! WITH_DRIVER_MODULES
endif WITH_STORAGE_DISK
if WITH_STORAGE_RBD
......@@ -1753,8 +1798,14 @@ libvirt_storage_backend_rbd_la_CFLAGS = \
-I$(srcdir)/secret \
$(AM_CFLAGS)
if WITH_DRIVER_MODULES
storagebackend_LTLIBRARIES += libvirt_storage_backend_rbd.la
libvirt_storage_backend_rbd_la_LDFLAGS = \
-module -avoid-version $(AM_LDFLAGS)
else ! WITH_DRIVER_MODULES
noinst_LTLIBRARIES += libvirt_storage_backend_rbd.la
libvirt_driver_storage_impl_la_LIBADD += libvirt_storage_backend_rbd.la
endif ! WITH_DRIVER_MODULES
endif WITH_STORAGE_RBD
if WITH_STORAGE_SHEEPDOG
......@@ -1764,9 +1815,23 @@ libvirt_storage_backend_sheepdog_la_CFLAGS = \
-I$(srcdir)/conf \
$(AM_CFLAGS)
libvirt_storage_backend_sheepdog_priv_la_SOURCES = \
$(STORAGE_DRIVER_SHEEPDOG_SOURCES) \
$(STORAGE_DRIVER_BACKEND_SOURCES)
libvirt_storage_backend_sheepdog_priv_la_CFLAGS = \
-I$(srcdir)/conf \
$(AM_CFLAGS)
noinst_LTLIBRARIES += libvirt_storage_backend_sheepdog_priv.la
if WITH_DRIVER_MODULES
storagebackend_LTLIBRARIES += libvirt_storage_backend_sheepdog.la
libvirt_storage_backend_sheepdog_la_LDFLAGS = \
-module -avoid-version $(AM_LDFLAGS)
else ! WITH_DRIVER_MODULES
noinst_LTLIBRARIES += libvirt_storage_backend_sheepdog.la
libvirt_driver_storage_impl_la_LIBADD += \
libvirt_storage_backend_sheepdog.la
endif ! WITH_DRIVER_MODULES
endif WITH_STORAGE_SHEEPDOG
if WITH_STORAGE_GLUSTER
......@@ -1778,9 +1843,15 @@ libvirt_storage_backend_gluster_la_CFLAGS = \
$(GLUSTERFS_CFLAGS) \
$(AM_CFLAGS)
if WITH_DRIVER_MODULES
storagebackend_LTLIBRARIES += libvirt_storage_backend_gluster.la
libvirt_storage_backend_gluster_la_LDFLAGS = \
-module -avoid-version $(AM_LDFLAGS)
else ! WITH_DRIVER_MODULES
noinst_LTLIBRARIES += libvirt_storage_backend_gluster.la
libvirt_driver_storage_impl_la_LIBADD += \
libvirt_storage_backend_gluster.la
endif ! WITH_DRIVER_MODULES
endif WITH_STORAGE_GLUSTER
if WITH_STORAGE_ZFS
......@@ -1789,8 +1860,14 @@ libvirt_storage_backend_zfs_la_CFLAGS = \
-I$(srcdir)/conf \
$(AM_CFLAGS)
if WITH_DRIVER_MODULES
storagebackend_LTLIBRARIES += libvirt_storage_backend_zfs.la
libvirt_storage_backend_zfs_la_LDFLAGS = \
-module -avoid-version $(AM_LDFLAGS)
else ! WITH_DRIVER_MODULES
noinst_LTLIBRARIES += libvirt_storage_backend_zfs.la
libvirt_driver_storage_impl_la_LIBADD += libvirt_storage_backend_zfs.la
endif ! WITH_DRIVER_MODULES
endif WITH_STORAGE_ZFS
if WITH_STORAGE_VSTORAGE
......@@ -1800,9 +1877,15 @@ libvirt_storage_backend_vstorage_la_CFLAGS = \
-I$(srcdir)/conf \
$(AM_CFLAGS)
if WITH_DRIVER_MODULES
storagebackend_LTLIBRARIES += libvirt_storage_backend_vstorage.la
libvirt_storage_backend_vstorage_la_LDFLAGS = \
-module -avoid-version $(AM_LDFLAGS)
else ! WITH_DRIVER_MODULES
noinst_LTLIBRARIES += libvirt_storage_backend_vstorage.la
libvirt_driver_storage_impl_la_LIBADD += \
libvirt_storage_backend_vstorage.la
endif ! WITH_DRIVER_MODULES
endif WITH_STORAGE_VSTORAGE
if WITH_NODE_DEVICES
......
......@@ -33,6 +33,8 @@
#include "virstoragefile.h"
#include "storage_backend.h"
#include "virlog.h"
#include "virfile.h"
#include "configmake.h"
#if WITH_STORAGE_LVM
# include "storage_backend_logical.h"
......@@ -79,45 +81,77 @@ static size_t virStorageBackendsCount;
static virStorageFileBackendPtr virStorageFileBackends[VIR_STORAGE_BACKENDS_MAX];
static size_t virStorageFileBackendsCount;
#define VIR_STORAGE_BACKEND_REGISTER(name) \
if (name() < 0) \
#if WITH_DRIVER_MODULES
# define STORAGE_BACKEND_MODULE_DIR LIBDIR "/libvirt/storage-backend"
static int
virStorageDriverLoadBackendModule(const char *name,
const char *regfunc)
{
char *modfile = NULL;
int ret;
if (!(modfile = virFileFindResourceFull(name,
"libvirt_storage_backend_",
".so",
abs_topbuilddir "/src/.libs",
STORAGE_BACKEND_MODULE_DIR,
"LIBVIRT_STORAGE_BACKEND_DIR")))
return 1;
ret = virDriverLoadModuleFull(modfile, regfunc, NULL);
VIR_FREE(modfile);
return ret;
}
# define VIR_STORAGE_BACKEND_REGISTER(func, module) \
if (virStorageDriverLoadBackendModule(module, #func) < 0) \
return -1
#else
# define VIR_STORAGE_BACKEND_REGISTER(func, module) \
if (func() < 0) \
return -1
#endif
int
virStorageBackendDriversRegister(void)
{
#if WITH_STORAGE_DIR || WITH_STORAGE_FS
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendFsRegister);
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendFsRegister, "fs");
#endif
#if WITH_STORAGE_LVM
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendLogicalRegister);
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendLogicalRegister, "logical");
#endif
#if WITH_STORAGE_ISCSI
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendISCSIRegister);
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendISCSIRegister, "iscsi");
#endif
#if WITH_STORAGE_SCSI
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendSCSIRegister);
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendSCSIRegister, "scsi");
#endif
#if WITH_STORAGE_MPATH
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendMpathRegister);
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendMpathRegister, "mpath");
#endif
#if WITH_STORAGE_DISK
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendDiskRegister);
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendDiskRegister, "disk");
#endif
#if WITH_STORAGE_RBD
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendRBDRegister);
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendRBDRegister, "rbd");
#endif
#if WITH_STORAGE_SHEEPDOG
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendSheepdogRegister);
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendSheepdogRegister, "sheepdog");
#endif
#if WITH_STORAGE_GLUSTER
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendGlusterRegister);
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendGlusterRegister, "gluster");
#endif
#if WITH_STORAGE_ZFS
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendZFSRegister);
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendZFSRegister, "zfs");
#endif
#if WITH_STORAGE_VSTORAGE
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendVstorageRegister);
VIR_STORAGE_BACKEND_REGISTER(virStorageBackendVstorageRegister, "vstorage");
#endif
return 0;
......
......@@ -805,7 +805,9 @@ storagebackendsheepdogtest_SOURCES = \
storagebackendsheepdogtest.c \
testutils.c testutils.h
storagebackendsheepdogtest_LDADD = \
../src/libvirt_driver_storage_impl.la $(LDADDS)
../src/libvirt_driver_storage_impl.la \
../src/libvirt_storage_backend_sheepdog_priv.la \
$(LDADDS)
else ! WITH_STORAGE_SHEEPDOG
EXTRA_DIST += storagebackendsheepdogtest.c
endif ! WITH_STORAGE_SHEEPDOG
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册