提交 2b84e445 编写于 作者: J Jim Fehlig

Add libxenlight driver

Add a new xen driver based on libxenlight [1], which is the primary
toolstack starting with Xen 4.1.0.  The driver is stateful and runs
privileged only.

Like the existing xen-unified driver, the libxenlight driver is
accessed with xen:// URI.  Driver selection is based on the status
of xend.  If xend is running, the libxenlight driver will not load
and xen:// connections are handled by xen-unified.  If xend is not
running *and* the libxenlight driver is available, xen://
connections are deferred to the libxenlight driver.

V6:
 - Address several code style issues noted by Daniel Veillard
 - Make drive work with xen:/// URI
 - Hold domain object reference while domain is injected in
   libvirt event loop.  Race found and fixed by Markus Groß.

V5:
 - Ensure events are unregistered when domain private data
   is destroyed.  Discovered and fixed by Markus Groß.

V4:
 - Handle restart of libvirtd, reconnecting to previously
   started domains
 - Rebased to current master
 - Tested against Xen 4.1 RC7-pre (c/s 22961:c5d121fd35c0)

V3:
  - Reserve vnc port within driver when autoport=yes

V2:
  - Update to Xen 4.1 RC6-pre (c/s 22940:5a4710640f81)
  - Rebased to current master
  - Plug memory leaks found by Stefano Stabellini and valgrind
  - Handle SHUTDOWN_crash domain death event

[1] http://lists.xensource.com/archives/html/xen-devel/2009-11/msg00436.html
上级 fba550f6
......@@ -403,6 +403,7 @@ msg_gen_function += virXenStoreError
msg_gen_function += virXendError
msg_gen_function += vmwareError
msg_gen_function += xenapiSessionErrorHandler
msg_gen_function += libxlError
msg_gen_function += xenUnifiedError
msg_gen_function += xenXMError
msg_gen_function += VIR_ERROR
......
......@@ -263,6 +263,8 @@ AC_ARG_WITH([phyp],
AC_HELP_STRING([--with-phyp], [add PHYP support @<:@default=check@:>@]),[],[with_phyp=check])
AC_ARG_WITH([xenapi],
AC_HELP_STRING([--with-xenapi], [add XenAPI support @<:@default=check@:>@]),[],[with_xenapi=check])
AC_ARG_WITH([libxl],
AC_HELP_STRING([--with-libxl], [add libxenlight support @<:@default=check@:>@]),[],[with_libxl=check])
AC_ARG_WITH([vbox],
AC_HELP_STRING([--with-vbox=@<:@PFX@:>@],
[VirtualBox XPCOMC location @<:@default=yes@:>@]),[],
......@@ -497,6 +499,46 @@ fi
AC_SUBST([LIBXENSERVER_CFLAGS])
AC_SUBST([LIBXENSERVER_LIBS])
old_LIBS="$LIBS"
old_CFLAGS="$CFLAGS"
LIBXL_LIBS=""
LIBXL_CFLAGS=""
dnl search for libxl, aka libxenlight
fail=0
if test "$with_libxl" != "no" ; then
if test "$with_libxl" != "yes" && test "$with_libxl" != "check" ; then
LIBXL_CFLAGS="-I$with_libxl/include"
LIBXL_LIBS="-L$with_libxl"
fi
CFLAGS="$CFLAGS $LIBXL_CFLAGS"
LIBS="$LIBS $LIBXL_LIBS"
AC_CHECK_LIB([xenlight], [libxl_ctx_init], [
with_libxl=yes
LIBXL_LIBS="$LIBXL_LIBS -lxenlight -lxenstore -lxenctrl -lxenguest -luuid -lutil -lblktapctl"
],[
if test "$with_libxl" = "yes"; then
fail=1
fi
with_libxl=no
],[
-lxenstore -lxenctrl -lxenguest -luuid -lutil -lblktapctl
])
fi
LIBS="$old_LIBS"
CFLAGS="$old_CFLAGS"
if test $fail = 1; then
AC_MSG_ERROR([You must install the libxl Library to compile libxenlight driver with -lxl])
fi
if test "$with_libxl" = "yes"; then
AC_DEFINE_UNQUOTED([WITH_LIBXL], 1, [whether libxenlight driver is enabled])
fi
AM_CONDITIONAL([WITH_LIBXL], [test "$with_libxl" = "yes"])
AC_SUBST([LIBXL_CFLAGS])
AC_SUBST([LIBXL_LIBS])
old_LIBS="$LIBS"
old_CFLAGS="$CFLAGS"
......@@ -2370,6 +2412,7 @@ AC_MSG_NOTICE([ OpenVZ: $with_openvz])
AC_MSG_NOTICE([ VMware: $with_vmware])
AC_MSG_NOTICE([ VBox: $with_vbox])
AC_MSG_NOTICE([ XenAPI: $with_xenapi])
AC_MSG_NOTICE([xenlight: $with_libxl])
AC_MSG_NOTICE([ LXC: $with_lxc])
AC_MSG_NOTICE([ PHYP: $with_phyp])
AC_MSG_NOTICE([ ONE: $with_one])
......@@ -2479,6 +2522,11 @@ AC_MSG_NOTICE([ xenapi: $LIBXENSERVER_CFLAGS $LIBXENSERVER_LIBS])
else
AC_MSG_NOTICE([ xenapi: no])
fi
if test "$with_libxl" = "yes" ; then
AC_MSG_NOTICE([ libxenlight: $LIBXL_CFLAGS $LIBXL_LIBS])
else
AC_MSG_NOTICE([ libxenlight: no])
fi
if test "$with_hal" = "yes" ; then
AC_MSG_NOTICE([ hal: $HAL_CFLAGS $HAL_LIBS])
else
......
......@@ -106,6 +106,10 @@ if WITH_LXC
libvirtd_LDADD += ../src/libvirt_driver_lxc.la
endif
if WITH_LIBXL
libvirtd_LDADD += ../src/libvirt_driver_libxl.la
endif
if WITH_UML
libvirtd_LDADD += ../src/libvirt_driver_uml.la
endif
......
......@@ -81,6 +81,9 @@
# ifdef WITH_LXC
# include "lxc/lxc_driver.h"
# endif
# ifdef WITH_LIBXL
# include "libxl/libxl_driver.h"
# endif
# ifdef WITH_UML
# include "uml/uml_driver.h"
# endif
......@@ -943,6 +946,9 @@ static struct qemud_server *qemudInitialize(void) {
# ifdef WITH_NWFILTER
nwfilterRegister();
# endif
# ifdef WITH_LIBXL
libxlRegister();
# endif
# ifdef WITH_QEMU
qemuRegister();
# endif
......
......@@ -80,6 +80,7 @@ typedef enum {
VIR_FROM_STREAMS = 38, /* Error from I/O streams */
VIR_FROM_VMWARE = 39, /* Error from VMware driver */
VIR_FROM_EVENT = 40, /* Error from event loop impl */
VIR_FROM_LIBXL = 41, /* Error from libxenlight driver */
} virErrorDomain;
......
......@@ -45,6 +45,7 @@
%define with_vbox 0%{!?_without_vbox:%{server_drivers}}
%define with_uml 0%{!?_without_uml:%{server_drivers}}
%define with_xenapi 0%{!?_without_xenapi:%{server_drivers}}
%define with_libxl 0%{!?_without_libxl:%{server_drivers}}
# XXX this shouldn't be here, but it mistakenly links into libvirtd
%define with_one 0%{!?_without_one:%{server_drivers}}
......@@ -96,7 +97,7 @@
%endif
# RHEL doesn't ship OpenVZ, VBox, UML, OpenNebula, PowerHypervisor,
# VMWare, or libxenserver (xenapi)
# VMWare, libxenserver (xenapi), or libxenlight (Xen 4.1 and newer)
%if 0%{?rhel}
%define with_openvz 0
%define with_vbox 0
......@@ -105,6 +106,7 @@
%define with_phyp 0
%define with_vmware 0
%define with_xenapi 0
%define with_libxl 0
%endif
# RHEL-5 has restricted QEMU to x86_64 only and is too old for LXC
......@@ -493,6 +495,10 @@ of recent versions of Linux (and other OSes).
%define _without_xenapi --without-xenapi
%endif
%if ! %{with_libxl}
%define _without_libxl --without-libxl
%endif
%if ! %{with_sasl}
%define _without_sasl --without-sasl
%endif
......@@ -872,6 +878,9 @@ fi
%dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/qemu/
%dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/lxc/
%dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/uml/
%if %{with_libxl}
%dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/libxl/
%endif
%config(noreplace) %{_sysconfdir}/logrotate.d/libvirtd
%if %{with_qemu}
......@@ -912,6 +921,10 @@ fi
%dir %{_localstatedir}/run/libvirt/uml/
%dir %attr(0700, root, root) %{_localstatedir}/lib/libvirt/uml/
%endif
%if %{with_libxl}
%dir %{_localstatedir}/run/libvirt/libxl/
%dir %attr(0700, root, root) %{_localstatedir}/lib/libvirt/libxl/
%endif
%if %{with_network}
%dir %{_localstatedir}/run/libvirt/network/
%dir %attr(0700, root, root) %{_localstatedir}/lib/libvirt/network/
......
......@@ -34,6 +34,8 @@ src/lxc/lxc_conf.c
src/lxc/lxc_controller.c
src/lxc/lxc_driver.c
src/lxc/veth.c
src/libxl/libxl_driver.c
src/libxl/libxl_conf.c
src/network/bridge_driver.c
src/node_device/node_device_driver.c
src/node_device/node_device_hal.c
......
......@@ -298,6 +298,10 @@ XENAPI_DRIVER_SOURCES = \
xenapi/xenapi_driver_private.h \
xenapi/xenapi_utils.c xenapi/xenapi_utils.h
LIBXL_DRIVER_SOURCES = \
libxl/libxl_conf.c libxl/libxl_conf.h \
libxl/libxl_driver.c libxl/libxl_driver.h
UML_DRIVER_SOURCES = \
uml/uml_conf.c uml/uml_conf.h \
uml/uml_driver.c uml/uml_driver.h
......@@ -692,6 +696,25 @@ endif
libvirt_driver_xenapi_la_SOURCES = $(XENAPI_DRIVER_SOURCES)
endif
if WITH_LIBXL
if WITH_DRIVER_MODULES
mod_LTLIBRARIES += libvirt_driver_libxl.la
else
noinst_LTLIBRARIES += libvirt_driver_libxl.la
# Stateful, so linked to daemon instead
#libvirt_la_BUILT_LIBADD += libvirt_driver_libxl.la
endif
libvirt_driver_libxl_la_CFLAGS = $(LIBXL_CFLAGS) \
-I@top_srcdir@/src/conf $(AM_CFLAGS)
libvirt_driver_libxl_la_LDFLAGS = $(AM_LDFLAGS)
libvirt_driver_libxl_la_LIBADD = $(LIBXL_LIBS)
if WITH_DRIVER_MODULES
libvirt_driver_libxl_la_LIBADD += ../gnulib/lib/libgnu.la
libvirt_driver_libxl_la_LDFLAGS += -module -avoid-version
endif
libvirt_driver_libxl_la_SOURCES = $(LIBXL_DRIVER_SOURCES)
endif
if WITH_QEMU
if WITH_DRIVER_MODULES
mod_LTLIBRARIES += libvirt_driver_qemu.la
......@@ -1005,6 +1028,7 @@ EXTRA_DIST += \
$(PHYP_DRIVER_SOURCES) \
$(VBOX_DRIVER_SOURCES) \
$(XENAPI_DRIVER_SOURCES) \
$(LIBXL_DRIVER_SOURCES) \
$(ESX_DRIVER_SOURCES) \
$(ESX_DRIVER_EXTRA_DIST) \
$(NETWORK_DRIVER_SOURCES) \
......@@ -1259,6 +1283,10 @@ if WITH_LXC
$(MKDIR_P) "$(DESTDIR)$(localstatedir)/lib/libvirt/lxc"
$(MKDIR_P) "$(DESTDIR)$(localstatedir)/run/libvirt/lxc"
endif
if WITH_LIBXL
$(MKDIR_P) "$(DESTDIR)$(localstatedir)/lib/libvirt/libxl"
$(MKDIR_P) "$(DESTDIR)$(localstatedir)/run/libvirt/libxl"
endif
if WITH_UML
$(MKDIR_P) "$(DESTDIR)$(localstatedir)/lib/libvirt/uml"
$(MKDIR_P) "$(DESTDIR)$(localstatedir)/run/libvirt/uml"
......@@ -1296,6 +1324,10 @@ if WITH_LXC
rmdir "$(DESTDIR)$(localstatedir)/lib/libvirt/lxc" ||:
rmdir "$(DESTDIR)$(localstatedir)/run/libvirt/lxc" ||:
endif
if WITH_LIBXL
rmdir "$(DESTDIR)$(localstatedir)/lib/libvirt/libxl" ||:
rmdir "$(DESTDIR)$(localstatedir)/run/libvirt/libxl" ||:
endif
if WITH_UML
rmdir "$(DESTDIR)$(localstatedir)/lib/libvirt/uml" ||:
rmdir "$(DESTDIR)$(localstatedir)/run/libvirt/uml" ||:
......
......@@ -27,7 +27,8 @@ typedef enum {
VIR_DRV_ESX = 10,
VIR_DRV_PHYP = 11,
VIR_DRV_XENAPI = 12,
VIR_DRV_VMWARE = 13
VIR_DRV_VMWARE = 13,
VIR_DRV_LIBXL = 14,
} virDrvNo;
......
......@@ -912,6 +912,10 @@ virGetVersion(unsigned long *libVer, const char *type,
if (STRCASEEQ(type, "LXC"))
*typeVer = LIBVIR_VERSION_NUMBER;
# endif
# if WITH_LIBXL
if (STRCASEEQ(type, "xenlight"))
*typeVer = LIBVIR_VERSION_NUMBER;
# endif
# if WITH_PHYP
if (STRCASEEQ(type, "phyp"))
*typeVer = LIBVIR_VERSION_NUMBER;
......
此差异已折叠。
/*---------------------------------------------------------------------------*/
/* Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*---------------------------------------------------------------------------*/
#ifndef LIBXL_CONF_H
# define LIBXL_CONF_H
# include <config.h>
# include <libxl.h>
# include "internal.h"
# include "domain_conf.h"
# include "capabilities.h"
# include "configmake.h"
# include "bitmap.h"
# define LIBXL_VNC_PORT_MIN 5900
# define LIBXL_VNC_PORT_MAX 65535
# define LIBXL_CONFIG_DIR SYSCONFDIR "/libvirt/libxl"
# define LIBXL_AUTOSTART_DIR LIBXL_CONFIG_DIR "/autostart"
# define LIBXL_STATE_DIR LOCALSTATEDIR "/run/libvirt/libxl"
# define LIBXL_LOG_DIR LOCALSTATEDIR "/log/libvirt/libxl"
# define LIBXL_LIB_DIR LOCALSTATEDIR "/lib/libvirt/libxl"
# define LIBXL_SAVE_DIR LIBXL_LIB_DIR "/save"
typedef struct _libxlDriverPrivate libxlDriverPrivate;
typedef libxlDriverPrivate *libxlDriverPrivatePtr;
struct _libxlDriverPrivate {
virMutex lock;
virCapsPtr caps;
unsigned int version;
FILE *logger_file;
xentoollog_logger *logger;
/* libxl ctx for driver wide ops; getVersion, getNodeInfo, ... */
libxl_ctx ctx;
virBitmapPtr reservedVNCPorts;
virDomainObjList domains;
char *configDir;
char *autostartDir;
char *logDir;
char *stateDir;
char *libDir;
char *saveDir;
};
typedef struct _libxlDomainObjPrivate libxlDomainObjPrivate;
typedef libxlDomainObjPrivate *libxlDomainObjPrivatePtr;
struct _libxlDomainObjPrivate {
/* per domain libxl ctx */
libxl_ctx ctx;
libxl_waiter *dWaiter;
int waiterFD;
int eventHdl;
};
# define libxlError(code, ...) \
virReportErrorHelper(NULL, VIR_FROM_LIBXL, code, __FILE__, \
__FUNCTION__, __LINE__, __VA_ARGS__)
virCapsPtr
libxlMakeCapabilities(libxl_ctx *ctx);
int
libxlBuildDomainConfig(libxlDriverPrivatePtr driver,
virDomainDefPtr def, libxl_domain_config *d_config);
#endif /* LIBXL_CONF_H */
此差异已折叠。
/*---------------------------------------------------------------------------*/
/* Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*---------------------------------------------------------------------------*/
#ifndef LIBXL_DRIVER_H
# define LIBXL_DRIVER_H
# include <config.h>
int libxlRegister(void);
#endif /* LIBXL_DRIVER_H */
......@@ -89,6 +89,9 @@ static const char *virErrorDomainName(virErrorDomain domain) {
case VIR_FROM_XENAPI:
dom = "XenAPI ";
break;
case VIR_FROM_LIBXL:
dom = "xenlight ";
break;
case VIR_FROM_XML:
dom = "XML ";
break;
......
......@@ -50,6 +50,7 @@
#include "uuid.h"
#include "fdstream.h"
#include "files.h"
#include "command.h"
#define VIR_FROM_THIS VIR_FROM_XEN
......@@ -229,6 +230,23 @@ xenUnifiedProbe (void)
return 0;
}
#ifdef WITH_LIBXL
static int
xenUnifiedXendProbe (void)
{
virCommandPtr cmd;
int status;
int ret = 0;
cmd = virCommandNewArgList("/usr/sbin/xend", "status", NULL);
if (virCommandRun(cmd, &status) == 0 && status == 0)
ret = 1;
virCommandFree(cmd);
return ret;
}
#endif
static virDrvOpenStatus
xenUnifiedOpen (virConnectPtr conn, virConnectAuthPtr auth, int flags)
{
......@@ -292,6 +310,13 @@ xenUnifiedOpen (virConnectPtr conn, virConnectAuthPtr auth, int flags)
}
}
#ifdef WITH_LIBXL
/* Decline xen:// URI if xend is not running and libxenlight
* driver is potentially available. */
if (!xenUnifiedXendProbe())
return VIR_DRV_OPEN_DECLINED;
#endif
/* We now know the URI is definitely for this driver, so beyond
* here, don't return DECLINED, always use ERROR */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册