Implements domainXMLTo/FromNative in libxl driver

* src/Makefile.am src/libvirt_private.syms configure.ac: share and
  reuse the sexpr routines from sexpr.h of the old xen driver
* src/libxl/libxl_driver.c: implements libxlDomainXMLFromNative and
  libxlDomainXMLToNative
This commit is contained in:
Markus Groß 2011-03-29 20:39:18 +08:00 committed by Daniel Veillard
parent 3d6fe99c5c
commit 0244977180
4 changed files with 116 additions and 6 deletions

View File

@ -600,6 +600,8 @@ AM_CONDITIONAL([WITH_XEN], [test "$with_xen" = "yes"])
AC_SUBST([XEN_CFLAGS])
AC_SUBST([XEN_LIBS])
AM_CONDITIONAL([WITH_XENXS], [test "$with_libxl" = "yes" || test "$with_xen" = "yes"])
dnl
dnl check for kernel headers required by xen_inotify
dnl

View File

@ -473,7 +473,7 @@ libvirt_vmx_la_CFLAGS = \
libvirt_vmx_la_SOURCES = $(VMX_SOURCES)
endif
if WITH_XEN
if WITH_XENXS
noinst_LTLIBRARIES += libvirt_xenxs.la
libvirt_la_BUILT_LIBADD += libvirt_xenxs.la
libvirt_xenxs_la_CFLAGS = \
@ -704,9 +704,11 @@ noinst_LTLIBRARIES += libvirt_driver_libxl.la
#libvirt_la_BUILT_LIBADD += libvirt_driver_libxl.la
endif
libvirt_driver_libxl_la_CFLAGS = $(LIBXL_CFLAGS) \
-I@top_srcdir@/src/conf $(AM_CFLAGS)
-I@top_srcdir@/src/conf \
-I@top_srcdir@/src/xenxs \
$(AM_CFLAGS)
libvirt_driver_libxl_la_LDFLAGS = $(AM_LDFLAGS)
libvirt_driver_libxl_la_LIBADD = $(LIBXL_LIBS)
libvirt_driver_libxl_la_LIBADD = $(LIBXL_LIBS) libvirt_xenxs.la
if WITH_DRIVER_MODULES
libvirt_driver_libxl_la_LIBADD += ../gnulib/lib/libgnu.la
libvirt_driver_libxl_la_LDFLAGS += -module -avoid-version

View File

@ -757,6 +757,22 @@ virSecurityManagerSetSavedStateLabel;
virSecurityManagerSetSocketLabel;
virSecurityManagerVerify;
# sexpr.h
sexpr_append;
sexpr_cons;
sexpr_float;
sexpr_fmt_node;
sexpr_free;
sexpr_has;
sexpr_int;
sexpr_lookup;
sexpr_nil;
sexpr_node;
sexpr_node_copy;
sexpr_string;
sexpr_u64;
sexpr2string;
string2sexpr;
# storage_conf.h
virStoragePartedFsTypeTypeToString;

View File

@ -33,6 +33,7 @@
#include "internal.h"
#include "logging.h"
#include "virterror_internal.h"
#include "conf.h"
#include "datatypes.h"
#include "files.h"
#include "memory.h"
@ -41,6 +42,7 @@
#include "command.h"
#include "libxl_driver.h"
#include "libxl_conf.h"
#include "xen_xm.h"
#define VIR_FROM_THIS VIR_FROM_LIBXL
@ -51,6 +53,8 @@
#define LIBXL_DOM_REQ_CRASH 3
#define LIBXL_DOM_REQ_HALT 4
#define LIBXL_CONFIG_FORMAT_XM "xen-xm"
static libxlDriverPrivatePtr libxl_driver = NULL;
@ -1636,6 +1640,92 @@ libxlDomainDumpXML(virDomainPtr dom, int flags)
return ret;
}
static char *
libxlDomainXMLFromNative(virConnectPtr conn, const char * nativeFormat,
const char * nativeConfig,
unsigned int flags ATTRIBUTE_UNUSED)
{
libxlDriverPrivatePtr driver = conn->privateData;
const libxl_version_info *ver_info;
virDomainDefPtr def = NULL;
virConfPtr conf = NULL;
char *xml = NULL;
if (STRNEQ(nativeFormat, LIBXL_CONFIG_FORMAT_XM)) {
libxlError(VIR_ERR_INVALID_ARG,
_("unsupported config type %s"), nativeFormat);
goto cleanup;
}
if ((ver_info = libxl_get_version_info(&driver->ctx)) == NULL) {
VIR_ERROR0(_("cannot get version information from libxenlight"));
goto cleanup;
}
if (!(conf = virConfReadMem(nativeConfig, strlen(nativeConfig), 0)))
goto cleanup;
if (!(def = xenParseXM(conf, ver_info->xen_version_major, driver->caps))) {
libxlError(VIR_ERR_INTERNAL_ERROR, "%s", _("parsing xm config failed"));
goto cleanup;
}
xml = virDomainDefFormat(def, VIR_DOMAIN_XML_INACTIVE);
cleanup:
virDomainDefFree(def);
if (conf)
virConfFree(conf);
return xml;
}
#define MAX_CONFIG_SIZE (1024 * 65)
static char *
libxlDomainXMLToNative(virConnectPtr conn, const char * nativeFormat,
const char * domainXml,
unsigned int flags ATTRIBUTE_UNUSED)
{
libxlDriverPrivatePtr driver = conn->privateData;
const libxl_version_info *ver_info;
virDomainDefPtr def = NULL;
virConfPtr conf = NULL;
int len = MAX_CONFIG_SIZE;
char *ret = NULL;
if (STRNEQ(nativeFormat, LIBXL_CONFIG_FORMAT_XM)) {
libxlError(VIR_ERR_INVALID_ARG,
_("unsupported config type %s"), nativeFormat);
goto cleanup;
}
if ((ver_info = libxl_get_version_info(&driver->ctx)) == NULL) {
VIR_ERROR0(_("cannot get version information from libxenlight"));
goto cleanup;
}
if (!(def = virDomainDefParseString(driver->caps, domainXml, 0)))
goto cleanup;
if (!(conf = xenFormatXM(conn, def, ver_info->xen_version_major)))
goto cleanup;
if (VIR_ALLOC_N(ret, len) < 0) {
virReportOOMError();
goto cleanup;
}
if (virConfWriteMem(ret, &len, conf) < 0) {
VIR_FREE(ret);
goto cleanup;
}
cleanup:
virDomainDefFree(def);
if (conf)
virConfFree(conf);
return ret;
}
static int
libxlListDefinedDomains(virConnectPtr conn,
char **const names, int nnames)
@ -1994,8 +2084,8 @@ static virDriver libxlDriver = {
NULL, /* domainGetSecurityLabel */
NULL, /* nodeGetSecurityModel */
libxlDomainDumpXML, /* domainDumpXML */
NULL, /* domainXmlFromNative */
NULL, /* domainXmlToNative */
libxlDomainXMLFromNative, /* domainXmlFromNative */
libxlDomainXMLToNative, /* domainXmlToNative */
libxlListDefinedDomains, /* listDefinedDomains */
libxlNumDefinedDomains, /* numOfDefinedDomains */
libxlDomainCreate, /* domainCreate */