[libvirt] [RFC PATCH] storage: initial support for linking with libglfapi

Eric Blake eblake at redhat.com
Mon Oct 14 20:12:33 UTC 2013


We support gluster volumes in domain XML, so we also ought to
support them as a storage pool.  Besides, a future patch will
want to take advantage of libgfapi to handle the case of a
gluster device holding qcow2 rather than raw storage, and for
that to work, we need a storage backend that can read gluster
storage volume contents.  This sets up the framework.

* configure.ac (WITH_STORAGE_GLUSTER): New conditional.
* libvirt.spec.in (BuildRequires): Support it in spec file.
* src/conf/storage_conf.h (VIR_STORAGE_POOL_GLUSTER): New pool
type.
* src/conf/storage_conf.c (poolTypeInfo): Treat similar to
sheepdog and rbd.
* src/storage/storage_backend_gluster.h: New file.
* src/storage/storage_backend_gluster.c: Likewise.
* src/storage/storage_backend.c (backends): Register new type.
* src/Makefile.am (STORAGE_DRIVER_GLUSTER_SOURCES): Build new files.

Signed-off-by: Eric Blake <eblake at redhat.com>
---

I'm interested in a couple of things beyond this patch:
representing a storage pool on top of gluster, and improving
the libvirt backing chain detection to allow a gluster pool
to contain qcow2 rather than raw format data (ie. where one
gluster image can call out another gluster file as its backing,
rather than forcefully treating all network files as raw).
Without at least one of those working, this patch should not
be applied in isolation.  But I figured early review is
better to make sure I'm on track.

 configure.ac                          | 32 ++++++++++++++++++++++++++++++++
 libvirt.spec.in                       | 15 +++++++++++++++
 src/Makefile.am                       |  9 +++++++++
 src/conf/storage_conf.c               | 13 ++++++++++++-
 src/conf/storage_conf.h               |  3 ++-
 src/storage/storage_backend.c         |  6 ++++++
 src/storage/storage_backend_gluster.c | 35 +++++++++++++++++++++++++++++++++++
 src/storage/storage_backend_gluster.h | 29 +++++++++++++++++++++++++++++
 8 files changed, 140 insertions(+), 2 deletions(-)
 create mode 100644 src/storage/storage_backend_gluster.c
 create mode 100644 src/storage/storage_backend_gluster.h

diff --git a/configure.ac b/configure.ac
index 1993fab..3b7fde7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -118,6 +118,7 @@ PARTED_REQUIRED="1.8.0"
 DEVMAPPER_REQUIRED=1.0.0
 LIBPCAP_REQUIRED="1.0.0"
 LIBNL_REQUIRED="1.1"
+GLFS_REQUIRED="3.0"

 dnl Checks for C compiler.
 AC_PROG_CC
@@ -1646,6 +1647,10 @@ AC_ARG_WITH([storage-sheepdog],
   [AS_HELP_STRING([--with-storage-sheepdog],
     [with Sheepdog backend for the storage driver @<:@default=check@:>@])],
   [],[with_storage_sheepdog=check])
+AC_ARG_WITH([storage-gluster],
+  [AS_HELP_STRING([--with-storage-gluster],
+    [with Gluster backend for the storage driver @<:@default=check@:>@])],
+  [],[with_storage_gluster=check])

 if test "$with_libvirtd" = "no"; then
   with_storage_dir=no
@@ -1657,6 +1662,7 @@ if test "$with_libvirtd" = "no"; then
   with_storage_disk=no
   with_storage_rbd=no
   with_storage_sheepdog=no
+  with_storage_gluster=no
 fi
 if test "$with_storage_dir" = "yes" ; then
   AC_DEFINE_UNQUOTED([WITH_STORAGE_DIR], 1, [whether directory backend for storage driver is enabled])
@@ -1858,6 +1864,26 @@ fi
 AM_CONDITIONAL([WITH_STORAGE_SHEEPDOG],
   [test "$with_storage_sheepdog" = "yes"])

+LIBGLUSTER_LIBS=
+if test "$with_storage_gluster" = "yes" || \
+   	test "$with_storage_gluster" = "check"; then
+    PKG_CHECK_MODULES([GLFS], [glusterfs-api >= $GLFS_REQUIRED],
+      [GLFS_FOUND=yes], [GLFS_FOUND=no])
+
+    AC_CHECK_HEADER([glusterfs/api/glfs.h], [GLFS_FOUND=yes; break;])
+
+    if test "$GLFS_FOUND" = "yes"; then
+        with_storage_gluster=yes
+        LIBGLUSTER_LIBS=$GLFS_LIBS
+        AC_DEFINE_UNQUOTED([WITH_STORAGE_GLUSTER], [1],
+         [whether Gluster backend for storage driver is enabled])
+    else
+        with_storage_gluster=no
+    fi
+fi
+AM_CONDITIONAL([WITH_STORAGE_GLUSTER], [test "$with_storage_gluster" = "yes"])
+AC_SUBST([LIBGLUSTER_LIBS])
+

 LIBPARTED_CFLAGS=
 LIBPARTED_LIBS=
@@ -2670,6 +2696,7 @@ AC_MSG_NOTICE([   mpath: $with_storage_mpath])
 AC_MSG_NOTICE([    Disk: $with_storage_disk])
 AC_MSG_NOTICE([     RBD: $with_storage_rbd])
 AC_MSG_NOTICE([Sheepdog: $with_storage_sheepdog])
+AC_MSG_NOTICE([ Gluster: $with_storage_gluster])
 AC_MSG_NOTICE([])
 AC_MSG_NOTICE([Security Drivers])
 AC_MSG_NOTICE([])
@@ -2769,6 +2796,11 @@ AC_MSG_NOTICE([     rbd: $LIBRBD_LIBS])
 else
 AC_MSG_NOTICE([     rbd: no])
 fi
+if test "$with_storage_gluster" = "yes" ; then
+AC_MSG_NOTICE([ gluster: $LIBGLUSTER_LIBS])
+else
+AC_MSG_NOTICE([ gluster: no])
+fi

 AC_MSG_NOTICE([])
 AC_MSG_NOTICE([Test suite])
diff --git a/libvirt.spec.in b/libvirt.spec.in
index 7abc315..0917d59 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -98,6 +98,11 @@
 %else
     %define with_storage_sheepdog 0
 %endif
+%if 0%{?fedora} >= 19
+    %define with_storage_gluster 0%{!?_without_storage_gluster:%{server_drivers}}
+%else
+    %define with_storage_gluster 0
+%endif
 %define with_numactl          0%{!?_without_numactl:%{server_drivers}}
 %define with_selinux          0%{!?_without_selinux:%{server_drivers}}

@@ -281,6 +286,7 @@
     %define with_storage_mpath 0
     %define with_storage_rbd 0
     %define with_storage_sheepdog 0
+    %define with_storage_gluster 0
     %define with_storage_disk 0
 %endif

@@ -555,6 +561,10 @@ BuildRequires: device-mapper-devel
 BuildRequires: ceph-devel
     %endif
 %endif
+%if %{with_storage_gluster}
+BuildRequires: glusterfs-api-devel
+BuildRequires: glusterfs-devel
+%endif
 %if %{with_numactl}
 # For QEMU/LXC numa info
 BuildRequires: numactl-devel
@@ -1265,6 +1275,10 @@ of recent versions of Linux (and other OSes).
     %define _without_storage_sheepdog --without-storage-sheepdog
 %endif

+%if ! %{with_storage_gluster}
+    %define _without_storage_gluster --without-storage-gluster
+%endif
+
 %if ! %{with_numactl}
     %define _without_numactl --without-numactl
 %endif
@@ -1387,6 +1401,7 @@ of recent versions of Linux (and other OSes).
            %{?_without_storage_mpath} \
            %{?_without_storage_rbd} \
            %{?_without_storage_sheepdog} \
+           %{?_without_storage_gluster} \
            %{?_without_numactl} \
            %{?_without_numad} \
            %{?_without_capng} \
diff --git a/src/Makefile.am b/src/Makefile.am
index e58d408..bfdb07a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -815,6 +815,9 @@ STORAGE_DRIVER_RBD_SOURCES =					\
 STORAGE_DRIVER_SHEEPDOG_SOURCES =				\
 		storage/storage_backend_sheepdog.h storage/storage_backend_sheepdog.c

+STORAGE_DRIVER_GLUSTER_SOURCES =				\
+		storage/storage_backend_gluster.h storage/storage_backend_gluster.c
+
 STORAGE_HELPER_DISK_SOURCES =					\
 		storage/parthelper.c

@@ -1429,6 +1432,11 @@ if WITH_STORAGE_SHEEPDOG
 libvirt_driver_storage_impl_la_SOURCES += $(STORAGE_DRIVER_SHEEPDOG_SOURCES)
 endif WITH_STORAGE_SHEEPDOG

+if WITH_STORAGE_GLUSTER
+libvirt_driver_storage_impl_la_SOURCES += $(STORAGE_DRIVER_GLUSTER_SOURCES)
+libvirt_driver_storage_impl_la_LIBADD += $(LIBGLUSTER_LIBS)
+endif WITH_STORAGE_GLUSTER
+
 if WITH_NODE_DEVICES
 # Needed to keep automake quiet about conditionals
 if WITH_DRIVER_MODULES
@@ -1629,6 +1637,7 @@ EXTRA_DIST +=							\
 		$(STORAGE_DRIVER_DISK_SOURCES)			\
 		$(STORAGE_DRIVER_RBD_SOURCES)			\
 		$(STORAGE_DRIVER_SHEEPDOG_SOURCES)		\
+		$(STORAGE_DRIVER_GLUSTER_SOURCES)		\
 		$(NODE_DEVICE_DRIVER_SOURCES)			\
 		$(NODE_DEVICE_DRIVER_HAL_SOURCES)		\
 		$(NODE_DEVICE_DRIVER_UDEV_SOURCES)		\
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 975e662..bcef0b3 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -55,7 +55,7 @@ VIR_ENUM_IMPL(virStoragePool,
               VIR_STORAGE_POOL_LAST,
               "dir", "fs", "netfs",
               "logical", "disk", "iscsi",
-              "scsi", "mpath", "rbd", "sheepdog")
+              "scsi", "mpath", "rbd", "sheepdog", "gluster")

 VIR_ENUM_IMPL(virStoragePoolFormatFileSystem,
               VIR_STORAGE_POOL_FS_LAST,
@@ -244,6 +244,17 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
          .formatToString = virStoragePoolFormatDiskTypeToString,
      }
     },
+    {.poolType = VIR_STORAGE_POOL_GLUSTER,
+     .poolOptions = {
+         .flags = (VIR_STORAGE_POOL_SOURCE_HOST |
+                   VIR_STORAGE_POOL_SOURCE_NETWORK |
+                   VIR_STORAGE_POOL_SOURCE_NAME),
+     },
+     .volOptions = {
+         .defaultFormat = VIR_STORAGE_FILE_RAW,
+         .formatToString = virStoragePoolFormatDiskTypeToString,
+     }
+    },
     {.poolType = VIR_STORAGE_POOL_MPATH,
      .volOptions = {
          .formatToString = virStoragePoolFormatDiskTypeToString,
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index 62ff1fd..251e897 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -1,7 +1,7 @@
 /*
  * storage_conf.h: config handling for storage driver
  *
- * Copyright (C) 2006-2008, 2010-2012 Red Hat, Inc.
+ * Copyright (C) 2006-2008, 2010-2013 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -128,6 +128,7 @@ enum virStoragePoolType {
     VIR_STORAGE_POOL_MPATH,    /* Multipath devices */
     VIR_STORAGE_POOL_RBD,      /* RADOS Block Device */
     VIR_STORAGE_POOL_SHEEPDOG, /* Sheepdog device */
+    VIR_STORAGE_POOL_GLUSTER,  /* Gluster device */

     VIR_STORAGE_POOL_LAST,
 };
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index c21e6ea..8f30ce2 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -80,6 +80,9 @@
 #if WITH_STORAGE_SHEEPDOG
 # include "storage_backend_sheepdog.h"
 #endif
+#if WITH_STORAGE_GLUSTER
+# include "storage_backend_gluster.h"
+#endif

 #define VIR_FROM_THIS VIR_FROM_STORAGE

@@ -112,6 +115,9 @@ static virStorageBackendPtr backends[] = {
 #if WITH_STORAGE_SHEEPDOG
     &virStorageBackendSheepdog,
 #endif
+#if WITH_STORAGE_GLUSTER
+    &virStorageBackendGluster,
+#endif
     NULL
 };

diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c
new file mode 100644
index 0000000..deb44dc
--- /dev/null
+++ b/src/storage/storage_backend_gluster.c
@@ -0,0 +1,35 @@
+/*
+ * storage_backend_gluster.c: storage backend for Gluster handling
+ *
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <config.h>
+
+#include <glusterfs/api/glfs.h>
+
+#include "virerror.h"
+#include "storage_backend_gluster.h"
+#include "storage_conf.h"
+
+#define VIR_FROM_THIS VIR_FROM_STORAGE
+
+
+virStorageBackend virStorageBackendGluster = {
+    .type = VIR_STORAGE_POOL_GLUSTER,
+};
diff --git a/src/storage/storage_backend_gluster.h b/src/storage/storage_backend_gluster.h
new file mode 100644
index 0000000..b21bda7
--- /dev/null
+++ b/src/storage/storage_backend_gluster.h
@@ -0,0 +1,29 @@
+/*
+ * storage_backend_gluster.h: storage backend for Gluster handling
+ *
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __VIR_STORAGE_BACKEND_GLUSTER_H__
+# define __VIR_STORAGE_BACKEND_GLUSTER_H__
+
+# include "storage_backend.h"
+
+extern virStorageBackend virStorageBackendGluster;
+
+#endif /* __VIR_STORAGE_BACKEND_GLUSTER_H__ */
-- 
1.8.3.1




More information about the libvir-list mailing list