From e39438e869c7a1e692736fad35bcec0156d36c59 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Wed, 20 Feb 2008 15:42:30 +0000 Subject: [PATCH] Added directory/filesystem/netfs based storage pool backend --- ChangeLog | 11 +++++++++ configure.in | 52 +++++++++++++++++++++++++++++++++++++++++++ libvirt.spec.in | 24 ++++++++++++++++++++ po/POTFILES.in | 1 + src/Makefile.am | 1 + src/storage_backend.c | 34 ++++++++++++++++++++++++++++ 6 files changed, 123 insertions(+) diff --git a/ChangeLog b/ChangeLog index b675cadedb..8bf04fbcfe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Wed Feb 20 10:32:27 EST 2008 Daniel P. Berrange + + * configure.in: Add checks for mount/unmount/qemu-img/qcow-create + * docs/storage/*.xml: Add some example XML configs for storage + * libvirt.spec.in: Added deps on qemu-img and/or qcow-create, + and util-linux + * src/Makefile.am, src/storage_backend.c, src/storage_backend_fs.c, + src/storage_backend_fs.h: Add impl of directory, filesystem & + network filesystem pools. + * po/POTFILES.in: Added storage_backend_fs.c + Wed Feb 20 10:32:27 EST 2008 Daniel P. Berrange * configure.in: Add check for selinux library diff --git a/configure.in b/configure.in index 15c91aba31..5c75e7f2e3 100644 --- a/configure.in +++ b/configure.in @@ -552,6 +552,52 @@ AC_SUBST(VIRSH_LIBS) AC_SUBST(WITH_XEN) AC_SUBST(LIBVIRT_FEATURES) + +dnl +dnl Storage driver checks +dnl + +AC_ARG_WITH(storage-fs, +[ --with-storage-fs with FileSystem backend for the storage driver (on)],[],[with_storage_fs=check]) + +if test "$with_storage_fs" = "yes" -o "$with_storage_fs" = "check"; then + AC_PATH_PROG(MOUNT, [mount], [], [$PATH:/sbin:/usr/sbin]) + AC_PATH_PROG(UMOUNT, [umount], [], [$PATH:/sbin:/usr/sbin]) + if test "$with_storage_fs" = "yes" ; then + if test -z "$MOUNT" ; then AC_MSG_ERROR(We need mount for FS storage driver) ; fi + if test -z "$UMOUNT" ; then AC_MSG_ERROR(We need mount for FS storage driver) ; fi + else + if test -z "$MOUNT" ; then with_storage_fs=no ; fi + if test -z "$UMOUNT" ; then with_storage_fs=no ; fi + + if test "$with_storage_fs" = "check" ; then with_storage_fs=yes ; fi + fi + + if test "$with_storage_fs" = "yes" ; then + AC_DEFINE_UNQUOTED(WITH_STORAGE_FS, 1, [whether FS backend for storage driver is enabled]) + AC_DEFINE_UNQUOTED([MOUNT],["$MOUNT"], + [Location or name of the mount program]) + AC_DEFINE_UNQUOTED([UMOUNT],["$UMOUNT"], + [Location or name of the mount program]) + fi +fi +AM_CONDITIONAL(WITH_STORAGE_FS, [test "$with_storage_fs" = "yes"]) + +AC_PATH_PROG(QEMU_IMG, [qemu-img], [], [$PATH:/sbin:/usr/sbin:/bin:/usr/bin]) +if test -n "$QEMU_IMG" ; then + AC_DEFINE_UNQUOTED(HAVE_QEMU_IMG, 1, [whether qemu-img is available for non-raw files]) + AC_DEFINE_UNQUOTED([QEMU_IMG],["$QEMU_IMG"], + [Location or name of the qemu-img program]) +fi + +AC_PATH_PROG(QCOW_CREATE, [qcow-create], [], [$PATH:/sbin:/usr/sbin:/bin:/usr/bin]) +if test -n "$QCOW_CREATE" ; then + AC_DEFINE_UNQUOTED(HAVE_QCOW_CREATE, 1, [whether qcow-create is available for non-raw files]) + AC_DEFINE_UNQUOTED([QCOW_CREATE],["$QCOW_CREATE"], + [Location or name of the qcow-create program]) +fi + + dnl dnl check for python dnl @@ -760,6 +806,12 @@ AC_MSG_NOTICE([ Test: $with_test]) AC_MSG_NOTICE([ Remote: $with_remote]) AC_MSG_NOTICE([Libvirtd: $with_libvirtd]) AC_MSG_NOTICE([]) +AC_MSG_NOTICE([Storage Drivers]) +AC_MSG_NOTICE([]) +AC_MSG_NOTICE([ Dir: yes]) +AC_MSG_NOTICE([ FS: $with_storage_fs]) +AC_MSG_NOTICE([ NetFS: $with_storage_fs]) +AC_MSG_NOTICE([]) AC_MSG_NOTICE([Libraries]) AC_MSG_NOTICE([]) AC_MSG_NOTICE([ libxml: $LIBXML_CFLAGS $LIBXML_LIBS]) diff --git a/libvirt.spec.in b/libvirt.spec.in index 15f38c2c32..677b40698a 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -8,6 +8,12 @@ %define with_proxy yes %endif +%if "%{fedora}" +%define with_qemu 1 +%else +%define with_qemu 0 +%endif + Summary: Library providing a simple API virtualization Name: libvirt Version: @VERSION@ @@ -34,6 +40,15 @@ Requires: cyrus-sasl-md5 %if %{with_polkit} Requires: PolicyKit >= 0.6 %endif +# For mount/umount in FS driver +BuildRequires: util-linux +%if %{with_qemu} +# From QEMU RPMs +Requires: /usr/bin/qemu-img +%else +# From Xen RPMs +Requires: /usr/sbin/qcow-create +%endif BuildRequires: xen-devel BuildRequires: libxml2-devel BuildRequires: readline-devel @@ -49,6 +64,15 @@ BuildRequires: cyrus-sasl-devel %if %{with_polkit} BuildRequires: PolicyKit-devel >= 0.6 %endif +# For mount/umount in FS driver +BuildRequires: util-linux +%if %{with_qemu} +# From QEMU RPMs +BuildRequires: /usr/bin/qemu-img +%else +# From Xen RPMs +BuildRequires: /usr/sbin/qcow-create +%endif Obsoletes: libvir ExclusiveArch: i386 x86_64 ia64 diff --git a/po/POTFILES.in b/po/POTFILES.in index f6c4dd8fa1..e0a917f3bc 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -11,6 +11,7 @@ src/qemu_conf.c src/qemu_driver.c src/remote_internal.c src/storage_backend.c +src/storage_backend_fs.c src/storage_conf.c src/storage_driver.c src/sexpr.c diff --git a/src/Makefile.am b/src/Makefile.am index f9750e9e11..38efa66734 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -62,6 +62,7 @@ CLIENT_SOURCES = \ storage_conf.h storage_conf.c \ storage_driver.h storage_driver.c \ storage_backend.h storage_backend.c \ + storage_backend_fs.h storage_backend_fs.c \ util.c util.h SERVER_SOURCES = \ diff --git a/src/storage_backend.c b/src/storage_backend.c index b350b753c0..4d3a8cb53d 100644 --- a/src/storage_backend.c +++ b/src/storage_backend.c @@ -40,10 +40,24 @@ #include "util.h" #include "storage_backend.h" +#include "storage_backend_fs.h" + +static virStorageBackendPtr backends[] = { + &virStorageBackendDirectory, +#if WITH_STORAGE_FS + &virStorageBackendFileSystem, + &virStorageBackendNetFileSystem, +#endif +}; virStorageBackendPtr virStorageBackendForType(int type) { + unsigned int i; + for (i = 0 ; i < (sizeof(backends)/sizeof(backends[0])) ; i++) + if (backends[i]->type == type) + return backends[i]; + virStorageReportError(NULL, VIR_ERR_INTERNAL_ERROR, _("missing backend for pool type %d"), type); return NULL; @@ -68,6 +82,15 @@ virStorageBackendVolOptionsForType(int type) { int virStorageBackendFromString(const char *type) { + if (STREQ(type, "dir")) + return VIR_STORAGE_POOL_DIR; +#if WITH_STORAGE_FS + if (STREQ(type, "fs")) + return VIR_STORAGE_POOL_FS; + if (STREQ(type, "netfs")) + return VIR_STORAGE_POOL_NETFS; +#endif + virStorageReportError(NULL, VIR_ERR_INTERNAL_ERROR, _("unknown storage backend type %s"), type); return -1; @@ -75,6 +98,17 @@ virStorageBackendFromString(const char *type) { const char * virStorageBackendToString(int type) { + switch (type) { + case VIR_STORAGE_POOL_DIR: + return "dir"; +#if WITH_STORAGE_FS + case VIR_STORAGE_POOL_FS: + return "fs"; + case VIR_STORAGE_POOL_NETFS: + return "netfs"; +#endif + } + virStorageReportError(NULL, VIR_ERR_INTERNAL_ERROR, _("unknown storage backend type %d"), type); return NULL; -- GitLab