diff --git a/libvirt.spec.in b/libvirt.spec.in index d6058f80546b4542557f522c4259d85c73e76baa..e261e259a4bdc17d4b964cf6ff9d474a3f04fa35 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -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} diff --git a/src/storage/Makefile.inc.am b/src/storage/Makefile.inc.am index af2c97ab9317549c9882f1a5f851d45582abfa71..ea98c0ee52e06282b87a39a29d445805d674a756 100644 --- a/src/storage/Makefile.inc.am +++ b/src/storage/Makefile.inc.am @@ -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 diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index d843167112df292c9aac3d1b98787c2ce835f69e..8983738210e85cc963b046a7a5dbca6ae7d85dc2 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -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; } diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c index aca772676cff573b77fb3629b0fc309aeb9e4bd4..5d4b920a60b55e510d4b2a07c3c653949d43303f 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -24,7 +24,6 @@ #include #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; } diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 9e9b5f916892ae5a41b28c9ce7eacb4ea72d5589..185427f19c7439bbeba2290b3691b59507398199 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -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 && diff --git a/src/util/virstoragefilebackend.c b/src/util/virstoragefilebackend.c index df86ee39c2e1f657a9a6a8698119368d02bb1a70..ac087dabacd1059619525b32b0e5b25a957b4e2c 100644 --- a/src/util/virstoragefilebackend.c +++ b/src/util/virstoragefilebackend.c @@ -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; } diff --git a/src/util/virstoragefilebackend.h b/src/util/virstoragefilebackend.h index 6cd51750eea0343248ca39a2bbdf33345afd2b12..66868643670a4f1682d9c83ff41d2303470c2440 100644 --- a/src/util/virstoragefilebackend.h +++ b/src/util/virstoragefilebackend.h @@ -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;