1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

storage: initial support for linking with libgfapi

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.

Note that the new pool is named 'gluster' to match a
<disk type='network'><source protocol='gluster'> image source
already supported in a <domain>; it does NOT match the
<pool type='netfs'><source><target type='glusterfs'>,
since that uses a FUSE mount to a local file name rather than
a network name.

This and subsequent patches have been tested against glusterfs
3.4.1 (available on Fedora 19); there are likely bugs in older
versions that may prevent decent use of gfapi, so this patch
enforces the minimum version tested.  A future patch may lower
the minimum.  On the other hand, I hit at least two bugs in
3.4.1 that will be fixed in 3.5/3.4.2, where it might be worth
raising the minimum: glfs_readdir is nicer to use than
glfs_readdir_r [1], and glfs_fini should only return failure on
an actual failure [2].

[1] http://lists.gnu.org/archive/html/gluster-devel/2013-10/msg00085.html
[2] http://lists.gnu.org/archive/html/gluster-devel/2013-10/msg00086.html

* configure.ac (WITH_STORAGE_GLUSTER): New conditional.
* m4/virt-gluster.m4: new file.
* libvirt.spec.in (BuildRequires): Support gluster 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.
(virStoragePoolDefFormat): Don't output target for gluster.
* src/storage/storage_backend_gluster.h: New file.
* src/storage/storage_backend_gluster.c: Likewise.
* po/POTFILES.in: Add new file.
* src/storage/storage_backend.c (backends): Register new type.
* src/Makefile.am (STORAGE_DRIVER_GLUSTER_SOURCES): Build new files.
* src/storage/storage_backend.h (_virStorageBackend): Documet
assumption.

Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Eric Blake 2013-11-19 16:26:05 -07:00
parent 1b5c8d4cbc
commit 318ea3cb77
11 changed files with 184 additions and 7 deletions

View File

@ -228,6 +228,7 @@ LIBVIRT_CHECK_CAPNG
LIBVIRT_CHECK_CURL LIBVIRT_CHECK_CURL
LIBVIRT_CHECK_DBUS LIBVIRT_CHECK_DBUS
LIBVIRT_CHECK_FUSE LIBVIRT_CHECK_FUSE
LIBVIRT_CHECK_GLUSTER
LIBVIRT_CHECK_HAL LIBVIRT_CHECK_HAL
LIBVIRT_CHECK_NETCF LIBVIRT_CHECK_NETCF
LIBVIRT_CHECK_NUMACTL LIBVIRT_CHECK_NUMACTL
@ -1643,6 +1644,10 @@ AC_ARG_WITH([storage-sheepdog],
[AS_HELP_STRING([--with-storage-sheepdog], [AS_HELP_STRING([--with-storage-sheepdog],
[with Sheepdog backend for the storage driver @<:@default=check@:>@])], [with Sheepdog backend for the storage driver @<:@default=check@:>@])],
[],[with_storage_sheepdog=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 if test "$with_libvirtd" = "no"; then
with_storage_dir=no with_storage_dir=no
@ -1654,6 +1659,7 @@ if test "$with_libvirtd" = "no"; then
with_storage_disk=no with_storage_disk=no
with_storage_rbd=no with_storage_rbd=no
with_storage_sheepdog=no with_storage_sheepdog=no
with_storage_gluster=no
fi fi
if test "$with_storage_dir" = "yes" ; then if test "$with_storage_dir" = "yes" ; then
AC_DEFINE_UNQUOTED([WITH_STORAGE_DIR], 1, [whether directory backend for storage driver is enabled]) AC_DEFINE_UNQUOTED([WITH_STORAGE_DIR], 1, [whether directory backend for storage driver is enabled])
@ -1855,6 +1861,19 @@ fi
AM_CONDITIONAL([WITH_STORAGE_SHEEPDOG], AM_CONDITIONAL([WITH_STORAGE_SHEEPDOG],
[test "$with_storage_sheepdog" = "yes"]) [test "$with_storage_sheepdog" = "yes"])
LIBGLUSTER_LIBS=
if test "$with_storage_gluster" = "check"; then
with_storage_gluster=$with_glusterfs
fi
if test "$with_storage_gluster" = "yes"; then
if test "$with_glusterfs" = no; then
AC_MSG_ERROR([Need glusterfs (libgfapi) for gluster storage driver])
fi
AC_DEFINE_UNQUOTED([WITH_STORAGE_GLUSTER], [1],
[whether Gluster backend for storage driver is enabled])
fi
AM_CONDITIONAL([WITH_STORAGE_GLUSTER], [test "$with_storage_gluster" = "yes"])
LIBPARTED_CFLAGS= LIBPARTED_CFLAGS=
LIBPARTED_LIBS= LIBPARTED_LIBS=
@ -2583,6 +2602,7 @@ AC_MSG_NOTICE([ mpath: $with_storage_mpath])
AC_MSG_NOTICE([ Disk: $with_storage_disk]) AC_MSG_NOTICE([ Disk: $with_storage_disk])
AC_MSG_NOTICE([ RBD: $with_storage_rbd]) AC_MSG_NOTICE([ RBD: $with_storage_rbd])
AC_MSG_NOTICE([Sheepdog: $with_storage_sheepdog]) AC_MSG_NOTICE([Sheepdog: $with_storage_sheepdog])
AC_MSG_NOTICE([ Gluster: $with_storage_gluster])
AC_MSG_NOTICE([]) AC_MSG_NOTICE([])
AC_MSG_NOTICE([Security Drivers]) AC_MSG_NOTICE([Security Drivers])
AC_MSG_NOTICE([]) AC_MSG_NOTICE([])
@ -2608,6 +2628,7 @@ LIBVIRT_RESULT_CAPNG
LIBVIRT_RESULT_CURL LIBVIRT_RESULT_CURL
LIBVIRT_RESULT_DBUS LIBVIRT_RESULT_DBUS
LIBVIRT_RESULT_FUSE LIBVIRT_RESULT_FUSE
LIBVIRT_RESULT_GLUSTER
LIBVIRT_RESULT_HAL LIBVIRT_RESULT_HAL
LIBVIRT_RESULT_NETCF LIBVIRT_RESULT_NETCF
LIBVIRT_RESULT_NUMACTL LIBVIRT_RESULT_NUMACTL

View File

@ -98,6 +98,11 @@
%else %else
%define with_storage_sheepdog 0 %define with_storage_sheepdog 0
%endif %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_numactl 0%{!?_without_numactl:%{server_drivers}}
%define with_selinux 0%{!?_without_selinux:%{server_drivers}} %define with_selinux 0%{!?_without_selinux:%{server_drivers}}
@ -280,6 +285,7 @@
%define with_storage_mpath 0 %define with_storage_mpath 0
%define with_storage_rbd 0 %define with_storage_rbd 0
%define with_storage_sheepdog 0 %define with_storage_sheepdog 0
%define with_storage_gluster 0
%define with_storage_disk 0 %define with_storage_disk 0
%endif %endif
@ -554,6 +560,10 @@ BuildRequires: device-mapper-devel
BuildRequires: ceph-devel BuildRequires: ceph-devel
%endif %endif
%endif %endif
%if %{with_storage_gluster}
BuildRequires: glusterfs-api-devel >= 3.4.1
BuildRequires: glusterfs-devel >= 3.4.1
%endif
%if %{with_numactl} %if %{with_numactl}
# For QEMU/LXC numa info # For QEMU/LXC numa info
BuildRequires: numactl-devel BuildRequires: numactl-devel
@ -1256,6 +1266,10 @@ driver
%define _without_storage_sheepdog --without-storage-sheepdog %define _without_storage_sheepdog --without-storage-sheepdog
%endif %endif
%if ! %{with_storage_gluster}
%define _without_storage_gluster --without-storage-gluster
%endif
%if ! %{with_numactl} %if ! %{with_numactl}
%define _without_numactl --without-numactl %define _without_numactl --without-numactl
%endif %endif
@ -1377,6 +1391,7 @@ driver
%{?_without_storage_mpath} \ %{?_without_storage_mpath} \
%{?_without_storage_rbd} \ %{?_without_storage_rbd} \
%{?_without_storage_sheepdog} \ %{?_without_storage_sheepdog} \
%{?_without_storage_gluster} \
%{?_without_numactl} \ %{?_without_numactl} \
%{?_without_numad} \ %{?_without_numad} \
%{?_without_capng} \ %{?_without_capng} \

28
m4/virt-gluster.m4 Normal file
View File

@ -0,0 +1,28 @@
dnl The gluster libgfapi.so library
dnl
dnl Copyright (C) 2013 Red Hat, Inc.
dnl
dnl This library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Lesser General Public
dnl License as published by the Free Software Foundation; either
dnl version 2.1 of the License, or (at your option) any later version.
dnl
dnl This library is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dnl Lesser General Public License for more details.
dnl
dnl You should have received a copy of the GNU Lesser General Public
dnl License along with this library. If not, see
dnl <http://www.gnu.org/licenses/>.
dnl
dnl Currently tested against Fedora 19 with glusterfs 3.4.1; earlier
dnl versions may be possible but only with further testing
AC_DEFUN([LIBVIRT_CHECK_GLUSTER],[
LIBVIRT_CHECK_PKG([GLUSTERFS], [glusterfs-api], [3.4.1])
])
AC_DEFUN([LIBVIRT_RESULT_GLUSTER],[
LIBVIRT_RESULT_LIB([GLUSTERFS])
])

View File

@ -133,6 +133,7 @@ src/storage/parthelper.c
src/storage/storage_backend.c src/storage/storage_backend.c
src/storage/storage_backend_disk.c src/storage/storage_backend_disk.c
src/storage/storage_backend_fs.c src/storage/storage_backend_fs.c
src/storage/storage_backend_gluster.c
src/storage/storage_backend_iscsi.c src/storage/storage_backend_iscsi.c
src/storage/storage_backend_logical.c src/storage/storage_backend_logical.c
src/storage/storage_backend_mpath.c src/storage/storage_backend_mpath.c

View File

@ -820,6 +820,9 @@ STORAGE_DRIVER_RBD_SOURCES = \
STORAGE_DRIVER_SHEEPDOG_SOURCES = \ STORAGE_DRIVER_SHEEPDOG_SOURCES = \
storage/storage_backend_sheepdog.h storage/storage_backend_sheepdog.c 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_HELPER_DISK_SOURCES = \
storage/parthelper.c storage/parthelper.c
@ -1435,6 +1438,12 @@ if WITH_STORAGE_SHEEPDOG
libvirt_driver_storage_impl_la_SOURCES += $(STORAGE_DRIVER_SHEEPDOG_SOURCES) libvirt_driver_storage_impl_la_SOURCES += $(STORAGE_DRIVER_SHEEPDOG_SOURCES)
endif WITH_STORAGE_SHEEPDOG endif WITH_STORAGE_SHEEPDOG
if WITH_STORAGE_GLUSTER
libvirt_driver_storage_impl_la_SOURCES += $(STORAGE_DRIVER_GLUSTER_SOURCES)
libvirt_driver_storage_impl_la_CFLAGS += $(GLUSTERFS_CFLAGS)
libvirt_driver_storage_impl_la_LIBADD += $(GLUSTERFS_LIBS)
endif WITH_STORAGE_GLUSTER
if WITH_NODE_DEVICES if WITH_NODE_DEVICES
# Needed to keep automake quiet about conditionals # Needed to keep automake quiet about conditionals
if WITH_DRIVER_MODULES if WITH_DRIVER_MODULES
@ -1635,6 +1644,7 @@ EXTRA_DIST += \
$(STORAGE_DRIVER_DISK_SOURCES) \ $(STORAGE_DRIVER_DISK_SOURCES) \
$(STORAGE_DRIVER_RBD_SOURCES) \ $(STORAGE_DRIVER_RBD_SOURCES) \
$(STORAGE_DRIVER_SHEEPDOG_SOURCES) \ $(STORAGE_DRIVER_SHEEPDOG_SOURCES) \
$(STORAGE_DRIVER_GLUSTER_SOURCES) \
$(NODE_DEVICE_DRIVER_SOURCES) \ $(NODE_DEVICE_DRIVER_SOURCES) \
$(NODE_DEVICE_DRIVER_HAL_SOURCES) \ $(NODE_DEVICE_DRIVER_HAL_SOURCES) \
$(NODE_DEVICE_DRIVER_UDEV_SOURCES) \ $(NODE_DEVICE_DRIVER_UDEV_SOURCES) \

View File

@ -59,7 +59,7 @@ VIR_ENUM_IMPL(virStoragePool,
VIR_STORAGE_POOL_LAST, VIR_STORAGE_POOL_LAST,
"dir", "fs", "netfs", "dir", "fs", "netfs",
"logical", "disk", "iscsi", "logical", "disk", "iscsi",
"scsi", "mpath", "rbd", "sheepdog") "scsi", "mpath", "rbd", "sheepdog", "gluster")
VIR_ENUM_IMPL(virStoragePoolFormatFileSystem, VIR_ENUM_IMPL(virStoragePoolFormatFileSystem,
VIR_STORAGE_POOL_FS_LAST, VIR_STORAGE_POOL_FS_LAST,
@ -248,6 +248,19 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
.formatToString = virStoragePoolFormatDiskTypeToString, .formatToString = virStoragePoolFormatDiskTypeToString,
} }
}, },
{.poolType = VIR_STORAGE_POOL_GLUSTER,
.poolOptions = {
.flags = (VIR_STORAGE_POOL_SOURCE_HOST |
VIR_STORAGE_POOL_SOURCE_NETWORK |
VIR_STORAGE_POOL_SOURCE_NAME |
VIR_STORAGE_POOL_SOURCE_DIR),
},
.volOptions = {
.defaultFormat = VIR_STORAGE_FILE_RAW,
.formatToString = virStorageFileFormatTypeToString,
.formatFromString = virStorageVolumeFormatFromString,
}
},
{.poolType = VIR_STORAGE_POOL_MPATH, {.poolType = VIR_STORAGE_POOL_MPATH,
.volOptions = { .volOptions = {
.formatToString = virStoragePoolFormatDiskTypeToString, .formatToString = virStoragePoolFormatDiskTypeToString,
@ -652,6 +665,10 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
} }
source->dir = virXPathString("string(./dir/@path)", ctxt); source->dir = virXPathString("string(./dir/@path)", ctxt);
/* In gluster, a missing dir defaults to "/" */
if (!source->dir && pool_type == VIR_STORAGE_POOL_GLUSTER &&
VIR_STRDUP(source->dir, "/") < 0)
goto cleanup;
if ((adapter_type = virXPathString("string(./adapter/@type)", ctxt))) { if ((adapter_type = virXPathString("string(./adapter/@type)", ctxt))) {
if ((source->adapter.type = if ((source->adapter.type =
@ -1196,10 +1213,11 @@ virStoragePoolDefFormat(virStoragePoolDefPtr def)
if (virStoragePoolSourceFormat(&buf, options, &def->source) < 0) if (virStoragePoolSourceFormat(&buf, options, &def->source) < 0)
goto cleanup; goto cleanup;
/* RBD and Sheepdog devices are not local block devs nor files, so it /* RBD, Sheepdog, and Gluster devices are not local block devs nor
* doesn't have a target */ * files, so they don't have a target */
if (def->type != VIR_STORAGE_POOL_RBD && if (def->type != VIR_STORAGE_POOL_RBD &&
def->type != VIR_STORAGE_POOL_SHEEPDOG) { def->type != VIR_STORAGE_POOL_SHEEPDOG &&
def->type != VIR_STORAGE_POOL_GLUSTER) {
virBufferAddLit(&buf, " <target>\n"); virBufferAddLit(&buf, " <target>\n");
virBufferEscapeString(&buf, " <path>%s</path>\n", def->target.path); virBufferEscapeString(&buf, " <path>%s</path>\n", def->target.path);

View File

@ -1,7 +1,7 @@
/* /*
* storage_conf.h: config handling for storage driver * 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 * Copyright (C) 2006-2008 Daniel P. Berrange
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
@ -129,6 +129,7 @@ enum virStoragePoolType {
VIR_STORAGE_POOL_MPATH, /* Multipath devices */ VIR_STORAGE_POOL_MPATH, /* Multipath devices */
VIR_STORAGE_POOL_RBD, /* RADOS Block Device */ VIR_STORAGE_POOL_RBD, /* RADOS Block Device */
VIR_STORAGE_POOL_SHEEPDOG, /* Sheepdog device */ VIR_STORAGE_POOL_SHEEPDOG, /* Sheepdog device */
VIR_STORAGE_POOL_GLUSTER, /* Gluster device */
VIR_STORAGE_POOL_LAST, VIR_STORAGE_POOL_LAST,
}; };

View File

@ -80,6 +80,9 @@
#if WITH_STORAGE_SHEEPDOG #if WITH_STORAGE_SHEEPDOG
# include "storage_backend_sheepdog.h" # include "storage_backend_sheepdog.h"
#endif #endif
#if WITH_STORAGE_GLUSTER
# include "storage_backend_gluster.h"
#endif
#define VIR_FROM_THIS VIR_FROM_STORAGE #define VIR_FROM_THIS VIR_FROM_STORAGE
@ -111,6 +114,9 @@ static virStorageBackendPtr backends[] = {
#endif #endif
#if WITH_STORAGE_SHEEPDOG #if WITH_STORAGE_SHEEPDOG
&virStorageBackendSheepdog, &virStorageBackendSheepdog,
#endif
#if WITH_STORAGE_GLUSTER
&virStorageBackendGluster,
#endif #endif
NULL NULL
}; };

View File

@ -1,7 +1,7 @@
/* /*
* storage_backend.h: internal storage driver backend contract * storage_backend.h: internal storage driver backend contract
* *
* Copyright (C) 2007-2010, 2012 Red Hat, Inc. * Copyright (C) 2007-2010, 2012-2013 Red Hat, Inc.
* Copyright (C) 2007-2008 Daniel P. Berrange * Copyright (C) 2007-2008 Daniel P. Berrange
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
@ -70,6 +70,8 @@ virStorageBackendFSImageToolTypeToFunc(int tool_type);
typedef struct _virStorageBackend virStorageBackend; typedef struct _virStorageBackend virStorageBackend;
typedef virStorageBackend *virStorageBackendPtr; typedef virStorageBackend *virStorageBackendPtr;
/* Callbacks are optional unless documented otherwise; but adding more
* callbacks provides better pool support. */
struct _virStorageBackend { struct _virStorageBackend {
int type; int type;
@ -77,7 +79,7 @@ struct _virStorageBackend {
virStorageBackendCheckPool checkPool; virStorageBackendCheckPool checkPool;
virStorageBackendStartPool startPool; virStorageBackendStartPool startPool;
virStorageBackendBuildPool buildPool; virStorageBackendBuildPool buildPool;
virStorageBackendRefreshPool refreshPool; virStorageBackendRefreshPool refreshPool; /* Must be non-NULL */
virStorageBackendStopPool stopPool; virStorageBackendStopPool stopPool;
virStorageBackendDeletePool deletePool; virStorageBackendDeletePool deletePool;

View File

@ -0,0 +1,46 @@
/*
* 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
static int
virStorageBackendGlusterRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool ATTRIBUTE_UNUSED)
{
virReportError(VIR_ERR_NO_SUPPORT, "%s",
_("gluster pool type not fully supported yet"));
return -1;
}
virStorageBackend virStorageBackendGluster = {
.type = VIR_STORAGE_POOL_GLUSTER,
.refreshPool = virStorageBackendGlusterRefreshPool,
};

View File

@ -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__ */