Discussion:
[libvirt] [PATCH v5 1/6] libxl: reorder libxlMakeDomBuildInfo for upcoming PVH support
Marek Marczykowski-Górecki
2018-11-26 19:34:36 UTC
Permalink
Make it easier to share HVM and PVH code where relevant. No functional
change.

Signed-off-by: Marek Marczykowski-Górecki <***@invisiblethingslab.com>
---
src/libxl/libxl_conf.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index e2bfa2f..f3da0ed 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -376,18 +376,6 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
b_info->max_memkb = virDomainDefGetMemoryInitial(def);
b_info->target_memkb = def->mem.cur_balloon;
if (hvm) {
- char bootorder[VIR_DOMAIN_BOOT_LAST + 1];
-
- libxl_defbool_set(&b_info->u.hvm.pae,
- def->features[VIR_DOMAIN_FEATURE_PAE] ==
- VIR_TRISTATE_SWITCH_ON);
- libxl_defbool_set(&b_info->u.hvm.apic,
- def->features[VIR_DOMAIN_FEATURE_APIC] ==
- VIR_TRISTATE_SWITCH_ON);
- libxl_defbool_set(&b_info->u.hvm.acpi,
- def->features[VIR_DOMAIN_FEATURE_ACPI] ==
- VIR_TRISTATE_SWITCH_ON);
-
if (caps &&
def->cpu && def->cpu->mode == (VIR_CPU_MODE_HOST_PASSTHROUGH)) {
bool hasHwVirt = false;
@@ -474,6 +462,20 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
"mode=host-passthrough to avoid risk of changed guest "
"semantics when mode=custom is supported in the future");
}
+ }
+
+ if (hvm) {
+ char bootorder[VIR_DOMAIN_BOOT_LAST + 1];
+
+ libxl_defbool_set(&b_info->u.hvm.pae,
+ def->features[VIR_DOMAIN_FEATURE_PAE] ==
+ VIR_TRISTATE_SWITCH_ON);
+ libxl_defbool_set(&b_info->u.hvm.apic,
+ def->features[VIR_DOMAIN_FEATURE_APIC] ==
+ VIR_TRISTATE_SWITCH_ON);
+ libxl_defbool_set(&b_info->u.hvm.acpi,
+ def->features[VIR_DOMAIN_FEATURE_ACPI] ==
+ VIR_TRISTATE_SWITCH_ON);

if (def->nsounds > 0) {
/*
--
git-series 0.9.1
Marek Marczykowski-Górecki
2018-11-26 19:34:40 UTC
Permalink
Handle PVH domain type in both directions (xen-xl->xml, xml->xen-xl).
And add a test for it.

Signed-off-by: Marek Marczykowski-Górecki <***@invisiblethingslab.com>
---
Changes in v3:
- update for modified "libxl: add support for PVH"
Changes in v5:
- update for xenpvh ostype
---
src/xenconfig/xen_common.c | 17 ++++++++++-------
src/xenconfig/xen_xl.c | 5 +++++
tests/testutilsxen.c | 20 +++++++++++++++++++-
tests/xlconfigdata/test-pvh-type.cfg | 13 +++++++++++++
tests/xlconfigdata/test-pvh-type.xml | 25 +++++++++++++++++++++++++
tests/xlconfigtest.c | 1 +
6 files changed, 73 insertions(+), 8 deletions(-)
create mode 100644 tests/xlconfigdata/test-pvh-type.cfg
create mode 100644 tests/xlconfigdata/test-pvh-type.xml

diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 6c27936..13646df 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -1090,7 +1090,7 @@ xenParseGeneralMeta(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps)
{
virCapsDomainDataPtr capsdata = NULL;
VIR_AUTOFREE(char *) str = NULL;
- int hvm = 0, ret = -1;
+ int ret = -1;

if (xenConfigCopyString(conf, "name", &def->name) < 0)
goto out;
@@ -1098,11 +1098,15 @@ xenParseGeneralMeta(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps)
if (xenConfigGetUUID(conf, "uuid", def->uuid) < 0)
goto out;

+ def->os.type = VIR_DOMAIN_OSTYPE_XEN;
+
if (xenConfigGetString(conf, "type", &str, NULL) == 0 && str) {
if (STREQ(str, "pv")) {
- hvm = 0;
+ def->os.type = VIR_DOMAIN_OSTYPE_XEN;
+ } else if (STREQ(str, "pvh")) {
+ def->os.type = VIR_DOMAIN_OSTYPE_XENPVH;
} else if (STREQ(str, "hvm")) {
- hvm = 1;
+ def->os.type = VIR_DOMAIN_OSTYPE_HVM;
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("type %s is not supported"), str);
@@ -1110,12 +1114,11 @@ xenParseGeneralMeta(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps)
}
} else {
if ((xenConfigGetString(conf, "builder", &str, "linux") == 0) &&
- STREQ(str, "hvm"))
- hvm = 1;
+ STREQ(str, "hvm")) {
+ def->os.type = VIR_DOMAIN_OSTYPE_HVM;
+ }
}

- def->os.type = (hvm ? VIR_DOMAIN_OSTYPE_HVM : VIR_DOMAIN_OSTYPE_XEN);
-
if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type,
VIR_ARCH_NONE, def->virtType, NULL, NULL)))
goto out;
diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c
index 7250e57..70059df 100644
--- a/src/xenconfig/xen_xl.c
+++ b/src/xenconfig/xen_xl.c
@@ -1287,6 +1287,11 @@ xenFormatXLOS(virConfPtr conf, virDomainDefPtr def)

/* XXX floppy disks */
} else {
+ if (def->os.type == VIR_DOMAIN_OSTYPE_XENPVH) {
+ if (xenConfigSetString(conf, "type", "pvh") < 0)
+ return -1;
+ }
+
if (def->os.bootloader &&
xenConfigSetString(conf, "bootloader", def->os.bootloader) < 0)
return -1;
diff --git a/tests/testutilsxen.c b/tests/testutilsxen.c
index d34be72..2c347a7 100644
--- a/tests/testutilsxen.c
+++ b/tests/testutilsxen.c
@@ -17,7 +17,10 @@ testXLInitCaps(void)
"xenfv"
};
static const char *const xen_machines[] = {
- "xenpv"
+ "xenpv",
+ };
+ static const char *const pvh_machines[] = {
+ "xenpvh",
};

if ((caps = virCapabilitiesNew(virArchFromHost(),
@@ -54,6 +57,21 @@ testXLInitCaps(void)
if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN, NULL,
NULL, 0, NULL) == NULL)
goto cleanup;
+ nmachines = ARRAY_CARDINALITY(pvh_machines);
+ if ((machines = virCapabilitiesAllocMachines(pvh_machines, nmachines)) == NULL)
+ goto cleanup;
+
+ if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_XENPVH,
+ VIR_ARCH_X86_64,
+ "/usr/lib/xen/bin/qemu-system-i386",
+ NULL,
+ nmachines, machines)) == NULL)
+ goto cleanup;
+ machines = NULL;
+
+ if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN, NULL,
+ NULL, 0, NULL) == NULL)
+ goto cleanup;
return caps;

cleanup:
diff --git a/tests/xlconfigdata/test-pvh-type.cfg b/tests/xlconfigdata/test-pvh-type.cfg
new file mode 100644
index 0000000..2493535
--- /dev/null
+++ b/tests/xlconfigdata/test-pvh-type.cfg
@@ -0,0 +1,13 @@
+name = "XenGuest2"
+uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809"
+maxmem = 579
+memory = 394
+vcpus = 1
+localtime = 0
+on_poweroff = "destroy"
+on_reboot = "restart"
+on_crash = "restart"
+type = "pvh"
+kernel = "/tmp/vmlinuz"
+ramdisk = "/tmp/initrd"
+cmdline = "root=/dev/xvda1 console=hvc0"
diff --git a/tests/xlconfigdata/test-pvh-type.xml b/tests/xlconfigdata/test-pvh-type.xml
new file mode 100644
index 0000000..dc5f452
--- /dev/null
+++ b/tests/xlconfigdata/test-pvh-type.xml
@@ -0,0 +1,25 @@
+<domain type='xen'>
+ <name>XenGuest2</name>
+ <uuid>c7a5fdb2-cdaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>592896</memory>
+ <currentMemory unit='KiB'>403456</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='x86_64' machine='xenpvh'>xenpvh</type>
+ <kernel>/tmp/vmlinuz</kernel>
+ <initrd>/tmp/initrd</initrd>
+ <cmdline>root=/dev/xvda1 console=hvc0</cmdline>
+ </os>
+ <clock offset='utc' adjustment='reset'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>restart</on_crash>
+ <devices>
+ <console type='pty'>
+ <target type='xen' port='0'/>
+ </console>
+ <input type='mouse' bus='xen'/>
+ <input type='keyboard' bus='xen'/>
+ <memballoon model='xen'/>
+ </devices>
+</domain>
diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c
index 6e3267e..5159182 100644
--- a/tests/xlconfigtest.c
+++ b/tests/xlconfigtest.c
@@ -281,6 +281,7 @@ mymain(void)
DO_TEST("rbd-multihost-noauth");
DO_TEST_FORMAT("paravirt-type", false);
DO_TEST_FORMAT("fullvirt-type", false);
+ DO_TEST("pvh-type");

#ifdef LIBXL_HAVE_DEVICE_CHANNEL
DO_TEST("channel-pty");
--
git-series 0.9.1
Marek Marczykowski-Górecki
2018-11-26 19:34:37 UTC
Permalink
Since this is something between PV and HVM, it makes sense to put the
setting in place where domain type is specified.
To enable it, use <os><type machine="xenpvh">...</type></os>. It is
also included in capabilities.xml, for every supported HVM guest type - it
doesn't seems to be any other requirement (besides new enough Xen).

Signed-off-by: Marek Marczykowski-Górecki <***@invisiblethingslab.com>
---
Changes in v2 proposed by Jim:
- use new_arch_added var instead of i == nr_guest_archs for clarity
- improve comment
- adjust for now required Xen >= 4.6 (remove part for Xen < 4.5)

Changes in v3:
- limit VIR_DOMAIN_OSTYPE_XEN -> VIR_DOMAIN_OSTYPE_LINUX conversion to
Xen PV only
- do not accept VIR_DOMAIN_OSTYPE_LINUX for PVH
- fix reported capabilities for PVH - remove hostdev passthrough and
video/graphics
- use #ifdef LIBXL_DOMAIN_TYPE_PVH instead of hypervisor version to
check for PVH support
- compile fix for Xen < 4.9

Changes in v4:
- revert to "i == nr_guest_archs-1" check
- let configure check for LIBXL_DOMAIN_TYPE_PVH and use #ifdef
HAVE_XEN_PVH then
- fix comment about Xen version

Changes in v5:
- use 'xenpvh' os type
---
docs/formatcaps.html.in | 9 ++++--
docs/schemas/domaincommon.rng | 2 +-
m4/virt-driver-libxl.m4 | 3 ++-
src/conf/domain_conf.c | 10 ++++---
src/conf/domain_conf.h | 1 +-
src/libxl/libxl_capabilities.c | 38 +++++++++++++++++++++++---
src/libxl/libxl_conf.c | 52 ++++++++++++++++++++++++++++++-----
src/libxl/libxl_driver.c | 6 ++--
8 files changed, 102 insertions(+), 19 deletions(-)

diff --git a/docs/formatcaps.html.in b/docs/formatcaps.html.in
index 0d9c53d..86534b2 100644
--- a/docs/formatcaps.html.in
+++ b/docs/formatcaps.html.in
@@ -74,11 +74,14 @@
is able to run. Possible values are:
<dl>
<dt><code>xen</code></dt>
- <dd>for XEN</dd>
+ <dd>for XEN PV</dd>

<dt><code>linux</code></dt>
<dd>legacy alias for <code>xen</code></dd>

+ <dt><code>xenpvh</code></dt>
+ <dd>for XEN PVH</dd>
+
<dt><code>hvm</code></dt>
<dd>Unmodified operating system</dd>

@@ -104,8 +107,8 @@
<dt><code>machine</code></dt><dd>Machine type, for use in
<a href="formatdomain.html#attributeOSTypeMachine">machine</a>
attribute of os/type element in domain XML. For example Xen
- supports <code>xenfv</code> for HVM or <code>xenpv</code> for
- PV.</dd>
+ supports <code>xenfv</code> for HVM, <code>xenpv</code> for
+ PV, or <code>xenpvh</code> for PVH.</dd>
<dt><code>domain</code></dt><dd>The <code>type</code> attribute of
this element specifies the type of hypervisor required to run the
domain. Use in <a href="formatdomain.html#attributeDomainType">type</a>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 5ee727e..9b5ffa3 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -341,12 +341,14 @@
<choice>
<value>xenpv</value>
<value>xenfv</value>
+ <value>xenpvh</value>
</choice>
</attribute>
</optional>
<choice>
<value>xen</value>
<value>linux</value>
+ <value>xenpvh</value>
</choice>
</element>
</define>
diff --git a/m4/virt-driver-libxl.m4 b/m4/virt-driver-libxl.m4
index 479d911..2cd97cc 100644
--- a/m4/virt-driver-libxl.m4
+++ b/m4/virt-driver-libxl.m4
@@ -75,6 +75,9 @@ AC_DEFUN([LIBVIRT_DRIVER_CHECK_LIBXL], [
])
fi

+ dnl Check if Xen has support for PVH
+ AC_CHECK_DECL(LIBXL_DOMAIN_TYPE_PVH, [AC_DEFINE([HAVE_XEN_PVH], [1], [Define to 1 if Xen has PVH support.])], [], [#include <libxl.h>])
+
AC_SUBST([LIBXL_CFLAGS])
AC_SUBST([LIBXL_LIBS])
])
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1387483..10bf933 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -126,7 +126,8 @@ VIR_ENUM_IMPL(virDomainOS, VIR_DOMAIN_OSTYPE_LAST,
"xen",
"linux",
"exe",
- "uml")
+ "uml",
+ "xenpvh")

VIR_ENUM_IMPL(virDomainBoot, VIR_DOMAIN_BOOT_LAST,
"fd",
@@ -12932,7 +12933,8 @@ virDomainInputDefParseXML(virDomainXMLOptionPtr xmlopt,
bus);
goto error;
}
- } else if (dom->os.type == VIR_DOMAIN_OSTYPE_XEN) {
+ } else if (dom->os.type == VIR_DOMAIN_OSTYPE_XEN ||
+ dom->os.type == VIR_DOMAIN_OSTYPE_XENPVH) {
if (def->bus != VIR_DOMAIN_INPUT_BUS_XEN) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unsupported input bus %s"),
@@ -12981,7 +12983,8 @@ virDomainInputDefParseXML(virDomainXMLOptionPtr xmlopt,
} else {
def->bus = VIR_DOMAIN_INPUT_BUS_USB;
}
- } else if (dom->os.type == VIR_DOMAIN_OSTYPE_XEN) {
+ } else if (dom->os.type == VIR_DOMAIN_OSTYPE_XEN ||
+ dom->os.type == VIR_DOMAIN_OSTYPE_XENPVH) {
def->bus = VIR_DOMAIN_INPUT_BUS_XEN;
} else {
if ((dom->virtType == VIR_DOMAIN_VIRT_VZ ||
@@ -18770,6 +18773,7 @@ virDomainDefParseBootOptions(virDomainDefPtr def,
}

if (def->os.type == VIR_DOMAIN_OSTYPE_XEN ||
+ def->os.type == VIR_DOMAIN_OSTYPE_XENPVH ||
def->os.type == VIR_DOMAIN_OSTYPE_HVM ||
def->os.type == VIR_DOMAIN_OSTYPE_UML) {
xmlNodePtr loader_node;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 467785c..cb56b6f 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -255,6 +255,7 @@ typedef enum {
VIR_DOMAIN_OSTYPE_LINUX,
VIR_DOMAIN_OSTYPE_EXE,
VIR_DOMAIN_OSTYPE_UML,
+ VIR_DOMAIN_OSTYPE_XENPVH,

VIR_DOMAIN_OSTYPE_LAST
} virDomainOSType;
diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c
index 18596c7..58ec13f 100644
--- a/src/libxl/libxl_capabilities.c
+++ b/src/libxl/libxl_capabilities.c
@@ -57,6 +57,7 @@ struct guest_arch {
virArch arch;
int bits;
int hvm;
+ int pvh;
int pae;
int nonpae;
int ia64_be;
@@ -491,20 +492,44 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps)
guest_archs[i].nonpae = nonpae;
if (ia64_be)
guest_archs[i].ia64_be = ia64_be;
+
+ /*
+ * Xen 4.10 introduced support for the PVH guest type, which
+ * requires hardware virtualization support similar to the
+ * HVM guest type. Add a PVH guest type for each new HVM
+ * guest type.
+ */
+#ifdef HAVE_XEN_PVH
+ if (hvm && i == nr_guest_archs-1) {
+ /* Ensure we have not exhausted the guest_archs array */
+ if (nr_guest_archs >= ARRAY_CARDINALITY(guest_archs))
+ continue;
+ i = nr_guest_archs;
+ nr_guest_archs++;
+
+ guest_archs[i].arch = arch;
+ guest_archs[i].hvm = 0;
+ guest_archs[i].pvh = 1;
+ }
+#endif
}
}
regfree(&regex);

for (i = 0; i < nr_guest_archs; ++i) {
virCapsGuestPtr guest;
- char const *const xen_machines[] = {guest_archs[i].hvm ? "xenfv" : "xenpv"};
+ char const *const xen_machines[] = {
+ guest_archs[i].hvm ? "xenfv" :
+ (guest_archs[i].pvh ? "xenpvh" : "xenpv")};
virCapsGuestMachinePtr *machines;

if ((machines = virCapabilitiesAllocMachines(xen_machines, 1)) == NULL)
return -1;

if ((guest = virCapabilitiesAddGuest(caps,
- guest_archs[i].hvm ? VIR_DOMAIN_OSTYPE_HVM : VIR_DOMAIN_OSTYPE_XEN,
+ guest_archs[i].hvm ? VIR_DOMAIN_OSTYPE_HVM :
+ (guest_archs[i].pvh ? VIR_DOMAIN_OSTYPE_XENPVH :
+ VIR_DOMAIN_OSTYPE_XEN),
guest_archs[i].arch,
LIBXL_EXECBIN_DIR "/qemu-system-i386",
(guest_archs[i].hvm ?
@@ -557,7 +582,9 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps)
1,
0) == NULL)
return -1;
+ }

+ if (guest_archs[i].hvm || guest_archs[i].pvh) {
if (virCapabilitiesAddGuestFeature(guest,
"hap",
1,
@@ -580,7 +607,7 @@ libxlMakeDomainOSCaps(const char *machine,

os->supported = true;

- if (STREQ(machine, "xenpv"))
+ if (STREQ(machine, "xenpv") || STREQ(machine, "xenpvh"))
return 0;

capsLoader->supported = true;
@@ -734,9 +761,12 @@ libxlMakeDomainCapabilities(virDomainCapsPtr domCaps,
if (libxlMakeDomainOSCaps(domCaps->machine, os, firmwares, nfirmwares) < 0 ||
libxlMakeDomainDeviceDiskCaps(disk) < 0 ||
libxlMakeDomainDeviceGraphicsCaps(graphics) < 0 ||
- libxlMakeDomainDeviceVideoCaps(video) < 0 ||
+ libxlMakeDomainDeviceVideoCaps(video) < 0)
+ return -1;
+ if (STRNEQ(domCaps->machine, "xenpvh") &&
libxlMakeDomainDeviceHostdevCaps(hostdev) < 0)
return -1;
+
return 0;
}

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index f3da0ed..ea88032 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -133,8 +133,19 @@ libxlMakeDomCreateInfo(libxl_ctx *ctx,

libxl_domain_create_info_init(c_info);

- if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
+ if (def->os.type == VIR_DOMAIN_OSTYPE_HVM ||
+ def->os.type == VIR_DOMAIN_OSTYPE_XENPVH) {
+#ifdef HAVE_XEN_PVH
+ c_info->type = def->os.type == VIR_DOMAIN_OSTYPE_HVM ?
+ LIBXL_DOMAIN_TYPE_HVM : LIBXL_DOMAIN_TYPE_PVH;
+#else
+ if (def->os.type == VIR_DOMAIN_OSTYPE_XENPVH) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("PVH guest os type not supported"));
+ return -1;
+ }
c_info->type = LIBXL_DOMAIN_TYPE_HVM;
+#endif
switch ((virTristateSwitch) def->features[VIR_DOMAIN_FEATURE_HAP]) {
case VIR_TRISTATE_SWITCH_OFF:
libxl_defbool_set(&c_info->hap, false);
@@ -276,16 +287,26 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
virDomainClockDef clock = def->clock;
libxl_ctx *ctx = cfg->ctx;
libxl_domain_build_info *b_info = &d_config->b_info;
- int hvm = def->os.type == VIR_DOMAIN_OSTYPE_HVM;
+ bool hvm = def->os.type == VIR_DOMAIN_OSTYPE_HVM;
+ bool pvh = def->os.type == VIR_DOMAIN_OSTYPE_XENPVH;
size_t i;
size_t nusbdevice = 0;

libxl_domain_build_info_init(b_info);

- if (hvm)
+ if (hvm) {
libxl_domain_build_info_init_type(b_info, LIBXL_DOMAIN_TYPE_HVM);
- else
+ } else if (pvh) {
+#ifdef HAVE_XEN_PVH
+ libxl_domain_build_info_init_type(b_info, LIBXL_DOMAIN_TYPE_PVH);
+#else
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("PVH guest os type not supported"));
+ return -1;
+#endif
+ } else {
libxl_domain_build_info_init_type(b_info, LIBXL_DOMAIN_TYPE_PV);
+ }

b_info->max_vcpus = virDomainDefGetVcpusMax(def);
if (libxl_cpu_bitmap_alloc(ctx, &b_info->avail_vcpus, b_info->max_vcpus))
@@ -375,7 +396,7 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
def->mem.cur_balloon = VIR_ROUND_UP(def->mem.cur_balloon, 1024);
b_info->max_memkb = virDomainDefGetMemoryInitial(def);
b_info->target_memkb = def->mem.cur_balloon;
- if (hvm) {
+ if (hvm || pvh) {
if (caps &&
def->cpu && def->cpu->mode == (VIR_CPU_MODE_HOST_PASSTHROUGH)) {
bool hasHwVirt = false;
@@ -647,6 +668,22 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
return -1;
}
#endif
+ } else if (pvh) {
+ if (VIR_STRDUP(b_info->cmdline, def->os.cmdline) < 0)
+ return -1;
+ if (VIR_STRDUP(b_info->kernel, def->os.kernel) < 0)
+ return -1;
+ if (VIR_STRDUP(b_info->ramdisk, def->os.initrd) < 0)
+ return -1;
+#ifdef LIBXL_HAVE_BUILDINFO_BOOTLOADER
+ if (VIR_STRDUP(b_info->bootloader, def->os.bootloader) < 0)
+ return -1;
+ if (def->os.bootloaderArgs) {
+ if (!(b_info->bootloader_args =
+ virStringSplit(def->os.bootloaderArgs, " \t\n", 0)))
+ return -1;
+ }
+#endif
} else {
/*
* For compatibility with the legacy xen toolstack, default to pygrub
@@ -1226,11 +1263,12 @@ libxlMakeNic(virDomainDefPtr def,
* hvm guest").
*/
if (l_nic->model) {
- if (def->os.type == VIR_DOMAIN_OSTYPE_XEN &&
+ if ((def->os.type == VIR_DOMAIN_OSTYPE_XEN ||
+ def->os.type == VIR_DOMAIN_OSTYPE_XENPVH) &&
STRNEQ(l_nic->model, "netfront")) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("only model 'netfront' is supported for "
- "Xen PV domains"));
+ "Xen PV(H) domains"));
return -1;
}
if (VIR_STRDUP(x_nic->model, l_nic->model) < 0)
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index efd47a3..5aa68a7 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -6398,9 +6398,11 @@ libxlConnectGetDomainCapabilities(virConnectPtr conn,
emulatorbin = "/usr/bin/qemu-system-x86_64";

if (machine) {
- if (STRNEQ(machine, "xenpv") && STRNEQ(machine, "xenfv")) {
+ if (STRNEQ(machine, "xenpv") &&
+ STRNEQ(machine, "xenpvh") &&
+ STRNEQ(machine, "xenfv")) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
- _("Xen only supports 'xenpv' and 'xenfv' machines"));
+ _("Xen only supports 'xenpv', 'xenpvh' and 'xenfv' machines"));
goto cleanup;
}
} else {
--
git-series 0.9.1
Jim Fehlig
2018-11-27 00:19:03 UTC
Permalink
Post by Marek Marczykowski-Górecki
Since this is something between PV and HVM, it makes sense to put the
setting in place where domain type is specified.
To enable it, use <os><type machine="xenpvh">...</type></os>. It is
I replaced '...' with 'xenpvh' in my local branch before pushing.

Regards,
Jim
Post by Marek Marczykowski-Górecki
also included in capabilities.xml, for every supported HVM guest type - it
doesn't seems to be any other requirement (besides new enough Xen).
---
- use new_arch_added var instead of i == nr_guest_archs for clarity
- improve comment
- adjust for now required Xen >= 4.6 (remove part for Xen < 4.5)
- limit VIR_DOMAIN_OSTYPE_XEN -> VIR_DOMAIN_OSTYPE_LINUX conversion to
Xen PV only
- do not accept VIR_DOMAIN_OSTYPE_LINUX for PVH
- fix reported capabilities for PVH - remove hostdev passthrough and
video/graphics
- use #ifdef LIBXL_DOMAIN_TYPE_PVH instead of hypervisor version to
check for PVH support
- compile fix for Xen < 4.9
- revert to "i == nr_guest_archs-1" check
- let configure check for LIBXL_DOMAIN_TYPE_PVH and use #ifdef
HAVE_XEN_PVH then
- fix comment about Xen version
- use 'xenpvh' os type
---
docs/formatcaps.html.in | 9 ++++--
docs/schemas/domaincommon.rng | 2 +-
m4/virt-driver-libxl.m4 | 3 ++-
src/conf/domain_conf.c | 10 ++++---
src/conf/domain_conf.h | 1 +-
src/libxl/libxl_capabilities.c | 38 +++++++++++++++++++++++---
src/libxl/libxl_conf.c | 52 ++++++++++++++++++++++++++++++-----
src/libxl/libxl_driver.c | 6 ++--
8 files changed, 102 insertions(+), 19 deletions(-)
diff --git a/docs/formatcaps.html.in b/docs/formatcaps.html.in
index 0d9c53d..86534b2 100644
--- a/docs/formatcaps.html.in
+++ b/docs/formatcaps.html.in
@@ -74,11 +74,14 @@
<dl>
<dt><code>xen</code></dt>
- <dd>for XEN</dd>
+ <dd>for XEN PV</dd>
<dt><code>linux</code></dt>
<dd>legacy alias for <code>xen</code></dd>
+ <dt><code>xenpvh</code></dt>
+ <dd>for XEN PVH</dd>
+
<dt><code>hvm</code></dt>
<dd>Unmodified operating system</dd>
@@ -104,8 +107,8 @@
<dt><code>machine</code></dt><dd>Machine type, for use in
<a href="formatdomain.html#attributeOSTypeMachine">machine</a>
attribute of os/type element in domain XML. For example Xen
- supports <code>xenfv</code> for HVM or <code>xenpv</code> for
- PV.</dd>
+ supports <code>xenfv</code> for HVM, <code>xenpv</code> for
+ PV, or <code>xenpvh</code> for PVH.</dd>
<dt><code>domain</code></dt><dd>The <code>type</code> attribute of
this element specifies the type of hypervisor required to run the
domain. Use in <a href="formatdomain.html#attributeDomainType">type</a>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 5ee727e..9b5ffa3 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -341,12 +341,14 @@
<choice>
<value>xenpv</value>
<value>xenfv</value>
+ <value>xenpvh</value>
</choice>
</attribute>
</optional>
<choice>
<value>xen</value>
<value>linux</value>
+ <value>xenpvh</value>
</choice>
</element>
</define>
diff --git a/m4/virt-driver-libxl.m4 b/m4/virt-driver-libxl.m4
index 479d911..2cd97cc 100644
--- a/m4/virt-driver-libxl.m4
+++ b/m4/virt-driver-libxl.m4
@@ -75,6 +75,9 @@ AC_DEFUN([LIBVIRT_DRIVER_CHECK_LIBXL], [
])
fi
+ dnl Check if Xen has support for PVH
+ AC_CHECK_DECL(LIBXL_DOMAIN_TYPE_PVH, [AC_DEFINE([HAVE_XEN_PVH], [1], [Define to 1 if Xen has PVH support.])], [], [#include <libxl.h>])
+
AC_SUBST([LIBXL_CFLAGS])
AC_SUBST([LIBXL_LIBS])
])
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1387483..10bf933 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -126,7 +126,8 @@ VIR_ENUM_IMPL(virDomainOS, VIR_DOMAIN_OSTYPE_LAST,
"xen",
"linux",
"exe",
- "uml")
+ "uml",
+ "xenpvh")
VIR_ENUM_IMPL(virDomainBoot, VIR_DOMAIN_BOOT_LAST,
"fd",
@@ -12932,7 +12933,8 @@ virDomainInputDefParseXML(virDomainXMLOptionPtr xmlopt,
bus);
goto error;
}
- } else if (dom->os.type == VIR_DOMAIN_OSTYPE_XEN) {
+ } else if (dom->os.type == VIR_DOMAIN_OSTYPE_XEN ||
+ dom->os.type == VIR_DOMAIN_OSTYPE_XENPVH) {
if (def->bus != VIR_DOMAIN_INPUT_BUS_XEN) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unsupported input bus %s"),
@@ -12981,7 +12983,8 @@ virDomainInputDefParseXML(virDomainXMLOptionPtr xmlopt,
} else {
def->bus = VIR_DOMAIN_INPUT_BUS_USB;
}
- } else if (dom->os.type == VIR_DOMAIN_OSTYPE_XEN) {
+ } else if (dom->os.type == VIR_DOMAIN_OSTYPE_XEN ||
+ dom->os.type == VIR_DOMAIN_OSTYPE_XENPVH) {
def->bus = VIR_DOMAIN_INPUT_BUS_XEN;
} else {
if ((dom->virtType == VIR_DOMAIN_VIRT_VZ ||
@@ -18770,6 +18773,7 @@ virDomainDefParseBootOptions(virDomainDefPtr def,
}
if (def->os.type == VIR_DOMAIN_OSTYPE_XEN ||
+ def->os.type == VIR_DOMAIN_OSTYPE_XENPVH ||
def->os.type == VIR_DOMAIN_OSTYPE_HVM ||
def->os.type == VIR_DOMAIN_OSTYPE_UML) {
xmlNodePtr loader_node;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 467785c..cb56b6f 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -255,6 +255,7 @@ typedef enum {
VIR_DOMAIN_OSTYPE_LINUX,
VIR_DOMAIN_OSTYPE_EXE,
VIR_DOMAIN_OSTYPE_UML,
+ VIR_DOMAIN_OSTYPE_XENPVH,
VIR_DOMAIN_OSTYPE_LAST
} virDomainOSType;
diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c
index 18596c7..58ec13f 100644
--- a/src/libxl/libxl_capabilities.c
+++ b/src/libxl/libxl_capabilities.c
@@ -57,6 +57,7 @@ struct guest_arch {
virArch arch;
int bits;
int hvm;
+ int pvh;
int pae;
int nonpae;
int ia64_be;
@@ -491,20 +492,44 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps)
guest_archs[i].nonpae = nonpae;
if (ia64_be)
guest_archs[i].ia64_be = ia64_be;
+
+ /*
+ * Xen 4.10 introduced support for the PVH guest type, which
+ * requires hardware virtualization support similar to the
+ * HVM guest type. Add a PVH guest type for each new HVM
+ * guest type.
+ */
+#ifdef HAVE_XEN_PVH
+ if (hvm && i == nr_guest_archs-1) {
+ /* Ensure we have not exhausted the guest_archs array */
+ if (nr_guest_archs >= ARRAY_CARDINALITY(guest_archs))
+ continue;
+ i = nr_guest_archs;
+ nr_guest_archs++;
+
+ guest_archs[i].arch = arch;
+ guest_archs[i].hvm = 0;
+ guest_archs[i].pvh = 1;
+ }
+#endif
}
}
regfree(&regex);
for (i = 0; i < nr_guest_archs; ++i) {
virCapsGuestPtr guest;
- char const *const xen_machines[] = {guest_archs[i].hvm ? "xenfv" : "xenpv"};
+ char const *const xen_machines[] = {
+ (guest_archs[i].pvh ? "xenpvh" : "xenpv")};
virCapsGuestMachinePtr *machines;
if ((machines = virCapabilitiesAllocMachines(xen_machines, 1)) == NULL)
return -1;
if ((guest = virCapabilitiesAddGuest(caps,
- guest_archs[i].hvm ? VIR_DOMAIN_OSTYPE_HVM : VIR_DOMAIN_OSTYPE_XEN,
+ VIR_DOMAIN_OSTYPE_XEN),
guest_archs[i].arch,
LIBXL_EXECBIN_DIR "/qemu-system-i386",
(guest_archs[i].hvm ?
@@ -557,7 +582,9 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCapsPtr caps)
1,
0) == NULL)
return -1;
+ }
+ if (guest_archs[i].hvm || guest_archs[i].pvh) {
if (virCapabilitiesAddGuestFeature(guest,
"hap",
1,
@@ -580,7 +607,7 @@ libxlMakeDomainOSCaps(const char *machine,
os->supported = true;
- if (STREQ(machine, "xenpv"))
+ if (STREQ(machine, "xenpv") || STREQ(machine, "xenpvh"))
return 0;
capsLoader->supported = true;
@@ -734,9 +761,12 @@ libxlMakeDomainCapabilities(virDomainCapsPtr domCaps,
if (libxlMakeDomainOSCaps(domCaps->machine, os, firmwares, nfirmwares) < 0 ||
libxlMakeDomainDeviceDiskCaps(disk) < 0 ||
libxlMakeDomainDeviceGraphicsCaps(graphics) < 0 ||
- libxlMakeDomainDeviceVideoCaps(video) < 0 ||
+ libxlMakeDomainDeviceVideoCaps(video) < 0)
+ return -1;
+ if (STRNEQ(domCaps->machine, "xenpvh") &&
libxlMakeDomainDeviceHostdevCaps(hostdev) < 0)
return -1;
+
return 0;
}
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index f3da0ed..ea88032 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -133,8 +133,19 @@ libxlMakeDomCreateInfo(libxl_ctx *ctx,
libxl_domain_create_info_init(c_info);
- if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
+ if (def->os.type == VIR_DOMAIN_OSTYPE_HVM ||
+ def->os.type == VIR_DOMAIN_OSTYPE_XENPVH) {
+#ifdef HAVE_XEN_PVH
+ c_info->type = def->os.type == VIR_DOMAIN_OSTYPE_HVM ?
+ LIBXL_DOMAIN_TYPE_HVM : LIBXL_DOMAIN_TYPE_PVH;
+#else
+ if (def->os.type == VIR_DOMAIN_OSTYPE_XENPVH) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("PVH guest os type not supported"));
+ return -1;
+ }
c_info->type = LIBXL_DOMAIN_TYPE_HVM;
+#endif
switch ((virTristateSwitch) def->features[VIR_DOMAIN_FEATURE_HAP]) {
libxl_defbool_set(&c_info->hap, false);
@@ -276,16 +287,26 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
virDomainClockDef clock = def->clock;
libxl_ctx *ctx = cfg->ctx;
libxl_domain_build_info *b_info = &d_config->b_info;
- int hvm = def->os.type == VIR_DOMAIN_OSTYPE_HVM;
+ bool hvm = def->os.type == VIR_DOMAIN_OSTYPE_HVM;
+ bool pvh = def->os.type == VIR_DOMAIN_OSTYPE_XENPVH;
size_t i;
size_t nusbdevice = 0;
libxl_domain_build_info_init(b_info);
- if (hvm)
+ if (hvm) {
libxl_domain_build_info_init_type(b_info, LIBXL_DOMAIN_TYPE_HVM);
- else
+ } else if (pvh) {
+#ifdef HAVE_XEN_PVH
+ libxl_domain_build_info_init_type(b_info, LIBXL_DOMAIN_TYPE_PVH);
+#else
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("PVH guest os type not supported"));
+ return -1;
+#endif
+ } else {
libxl_domain_build_info_init_type(b_info, LIBXL_DOMAIN_TYPE_PV);
+ }
b_info->max_vcpus = virDomainDefGetVcpusMax(def);
if (libxl_cpu_bitmap_alloc(ctx, &b_info->avail_vcpus, b_info->max_vcpus))
@@ -375,7 +396,7 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
def->mem.cur_balloon = VIR_ROUND_UP(def->mem.cur_balloon, 1024);
b_info->max_memkb = virDomainDefGetMemoryInitial(def);
b_info->target_memkb = def->mem.cur_balloon;
- if (hvm) {
+ if (hvm || pvh) {
if (caps &&
def->cpu && def->cpu->mode == (VIR_CPU_MODE_HOST_PASSTHROUGH)) {
bool hasHwVirt = false;
@@ -647,6 +668,22 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
return -1;
}
#endif
+ } else if (pvh) {
+ if (VIR_STRDUP(b_info->cmdline, def->os.cmdline) < 0)
+ return -1;
+ if (VIR_STRDUP(b_info->kernel, def->os.kernel) < 0)
+ return -1;
+ if (VIR_STRDUP(b_info->ramdisk, def->os.initrd) < 0)
+ return -1;
+#ifdef LIBXL_HAVE_BUILDINFO_BOOTLOADER
+ if (VIR_STRDUP(b_info->bootloader, def->os.bootloader) < 0)
+ return -1;
+ if (def->os.bootloaderArgs) {
+ if (!(b_info->bootloader_args =
+ virStringSplit(def->os.bootloaderArgs, " \t\n", 0)))
+ return -1;
+ }
+#endif
} else {
/*
* For compatibility with the legacy xen toolstack, default to pygrub
@@ -1226,11 +1263,12 @@ libxlMakeNic(virDomainDefPtr def,
* hvm guest").
*/
if (l_nic->model) {
- if (def->os.type == VIR_DOMAIN_OSTYPE_XEN &&
+ if ((def->os.type == VIR_DOMAIN_OSTYPE_XEN ||
+ def->os.type == VIR_DOMAIN_OSTYPE_XENPVH) &&
STRNEQ(l_nic->model, "netfront")) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("only model 'netfront' is supported for "
- "Xen PV domains"));
+ "Xen PV(H) domains"));
return -1;
}
if (VIR_STRDUP(x_nic->model, l_nic->model) < 0)
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index efd47a3..5aa68a7 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -6398,9 +6398,11 @@ libxlConnectGetDomainCapabilities(virConnectPtr conn,
emulatorbin = "/usr/bin/qemu-system-x86_64";
if (machine) {
- if (STRNEQ(machine, "xenpv") && STRNEQ(machine, "xenfv")) {
+ if (STRNEQ(machine, "xenpv") &&
+ STRNEQ(machine, "xenpvh") &&
+ STRNEQ(machine, "xenfv")) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
- _("Xen only supports 'xenpv' and 'xenfv' machines"));
+ _("Xen only supports 'xenpv', 'xenpvh' and 'xenfv' machines"));
goto cleanup;
}
} else {
Marek Marczykowski-Górecki
2018-11-26 19:34:38 UTC
Permalink
Signed-off-by: Marek Marczykowski-Górecki <***@invisiblethingslab.com>
---
Changes in v3:
- update for modified "libxl: add support for PVH"
- skip PVH test on too old Xen

Changes in v5:
- adjust for xenpvh os type
---
tests/libxlxml2domconfigdata/basic-pvh.json | 49 ++++++++++++++++++++++-
tests/libxlxml2domconfigdata/basic-pvh.xml | 28 +++++++++++++-
tests/libxlxml2domconfigtest.c | 3 +-
3 files changed, 80 insertions(+)
create mode 100644 tests/libxlxml2domconfigdata/basic-pvh.json
create mode 100644 tests/libxlxml2domconfigdata/basic-pvh.xml

diff --git a/tests/libxlxml2domconfigdata/basic-pvh.json b/tests/libxlxml2domconfigdata/basic-pvh.json
new file mode 100644
index 0000000..48365c9
--- /dev/null
+++ b/tests/libxlxml2domconfigdata/basic-pvh.json
@@ -0,0 +1,49 @@
+{
+ "c_info": {
+ "type": "pvh",
+ "name": "test-pvh",
+ "uuid": "039e9ee6-4a84-3055-4c81-8ba426ae2656"
+ },
+ "b_info": {
+ "max_vcpus": 4,
+ "avail_vcpus": [
+ 0,
+ 1,
+ 2,
+ 3
+ ],
+ "max_memkb": 524288,
+ "target_memkb": 524288,
+ "shadow_memkb": 8192,
+ "sched_params": {
+
+ },
+ "kernel": "/boot/vmlinuz",
+ "ramdisk": "/boot/initrd.img",
+ "type.pvh": {
+ },
+ "arch_arm": {
+
+ }
+ },
+ "disks": [
+ {
+ "pdev_path": "/var/lib/xen/images/test-pv.img",
+ "vdev": "xvda",
+ "backend": "qdisk",
+ "format": "raw",
+ "removable": 1,
+ "readwrite": 1
+ }
+ ],
+ "nics": [
+ {
+ "devid": 0,
+ "mac": "00:16:3e:3e:86:60",
+ "bridge": "br0",
+ "script": "/etc/xen/scripts/vif-bridge",
+ "nictype": "vif"
+ }
+ ],
+ "on_reboot": "restart"
+}
diff --git a/tests/libxlxml2domconfigdata/basic-pvh.xml b/tests/libxlxml2domconfigdata/basic-pvh.xml
new file mode 100644
index 0000000..fa9ff7c
--- /dev/null
+++ b/tests/libxlxml2domconfigdata/basic-pvh.xml
@@ -0,0 +1,28 @@
+<domain type='xen'>
+ <name>test-pvh</name>
+ <uuid>039e9ee6-4a84-3055-4c81-8ba426ae2656</uuid>
+ <memory>524288</memory>
+ <currentMemory>524288</currentMemory>
+ <vcpu>4</vcpu>
+ <os>
+ <type arch='x86_64' machine='xenpvh'>xenpvh</type>
+ <kernel>/boot/vmlinuz</kernel>
+ <initrd>/boot/initrd.img</initrd>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <disk type='file' device='disk'>
+ <driver name='qemu'/>
+ <source file='/var/lib/xen/images/test-pv.img'/>
+ <target dev='xvda'/>
+ </disk>
+ <interface type='bridge'>
+ <source bridge='br0'/>
+ <mac address='00:16:3e:3e:86:60'/>
+ <script path='/etc/xen/scripts/vif-bridge'/>
+ </interface>
+ </devices>
+</domain>
diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c
index f380941..969d84e 100644
--- a/tests/libxlxml2domconfigtest.c
+++ b/tests/libxlxml2domconfigtest.c
@@ -203,6 +203,9 @@ mymain(void)

DO_TEST("basic-pv");
DO_TEST("basic-hvm");
+# ifdef HAVE_XEN_PVH
+ DO_TEST("basic-pvh");
+# endif
DO_TEST("cpu-shares-hvm");
DO_TEST("variable-clock-hvm");
DO_TEST("moredevs-hvm");
--
git-series 0.9.1
Marek Marczykowski-Górecki
2018-11-26 19:34:39 UTC
Permalink
builder="hvm" is deprecated since Xen 4.10, new syntax is type="hvm" (or
type="pv", which is default). Since the old one is still supported,
still use it when writing native config, so the config will work on
older Xen too (and will also not complicate tests).

Signed-off-by: Marek Marczykowski-Górecki <***@invisiblethingslab.com>
---
"type" option is the only syntax for specifying PVH guest, coming in
next patch.

Changes in v2:
- fix code style
---
src/xenconfig/xen_common.c | 18 +++++++++++++---
tests/xlconfigdata/test-fullvirt-type.cfg | 21 +++++++++++++++++++-
tests/xlconfigdata/test-fullvirt-type.xml | 27 ++++++++++++++++++++++++-
tests/xlconfigdata/test-paravirt-type.cfg | 13 ++++++++++++-
tests/xlconfigdata/test-paravirt-type.xml | 25 ++++++++++++++++++++++-
tests/xlconfigtest.c | 2 ++-
6 files changed, 103 insertions(+), 3 deletions(-)
create mode 100644 tests/xlconfigdata/test-fullvirt-type.cfg
create mode 100644 tests/xlconfigdata/test-fullvirt-type.xml
create mode 100644 tests/xlconfigdata/test-paravirt-type.cfg
create mode 100644 tests/xlconfigdata/test-paravirt-type.xml

diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 0a99587..6c27936 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -1098,9 +1098,21 @@ xenParseGeneralMeta(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps)
if (xenConfigGetUUID(conf, "uuid", def->uuid) < 0)
goto out;

- if ((xenConfigGetString(conf, "builder", &str, "linux") == 0) &&
- STREQ(str, "hvm"))
- hvm = 1;
+ if (xenConfigGetString(conf, "type", &str, NULL) == 0 && str) {
+ if (STREQ(str, "pv")) {
+ hvm = 0;
+ } else if (STREQ(str, "hvm")) {
+ hvm = 1;
+ } else {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("type %s is not supported"), str);
+ return -1;
+ }
+ } else {
+ if ((xenConfigGetString(conf, "builder", &str, "linux") == 0) &&
+ STREQ(str, "hvm"))
+ hvm = 1;
+ }

def->os.type = (hvm ? VIR_DOMAIN_OSTYPE_HVM : VIR_DOMAIN_OSTYPE_XEN);

diff --git a/tests/xlconfigdata/test-fullvirt-type.cfg b/tests/xlconfigdata/test-fullvirt-type.cfg
new file mode 100644
index 0000000..f8ecc2e
--- /dev/null
+++ b/tests/xlconfigdata/test-fullvirt-type.cfg
@@ -0,0 +1,21 @@
+name = "XenGuest2"
+uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809"
+maxmem = 579
+memory = 394
+vcpus = 1
+pae = 1
+acpi = 1
+apic = 1
+viridian = 0
+rtc_timeoffset = 0
+localtime = 0
+on_poweroff = "destroy"
+on_reboot = "restart"
+on_crash = "restart"
+device_model = "/usr/lib/xen/bin/qemu-system-i386"
+sdl = 0
+vnc = 0
+parallel = "none"
+serial = "none"
+type = "hvm"
+boot = "d"
diff --git a/tests/xlconfigdata/test-fullvirt-type.xml b/tests/xlconfigdata/test-fullvirt-type.xml
new file mode 100644
index 0000000..da8e360
--- /dev/null
+++ b/tests/xlconfigdata/test-fullvirt-type.xml
@@ -0,0 +1,27 @@
+<domain type='xen'>
+ <name>XenGuest2</name>
+ <uuid>c7a5fdb2-cdaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>592896</memory>
+ <currentMemory unit='KiB'>403456</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='x86_64' machine='xenfv'>hvm</type>
+ <loader type='rom'>/usr/lib/xen/boot/hvmloader</loader>
+ <boot dev='cdrom'/>
+ </os>
+ <features>
+ <acpi/>
+ <apic/>
+ <pae/>
+ </features>
+ <clock offset='variable' adjustment='0' basis='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>restart</on_crash>
+ <devices>
+ <emulator>/usr/lib/xen/bin/qemu-system-i386</emulator>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <memballoon model='xen'/>
+ </devices>
+</domain>
diff --git a/tests/xlconfigdata/test-paravirt-type.cfg b/tests/xlconfigdata/test-paravirt-type.cfg
new file mode 100644
index 0000000..078db99
--- /dev/null
+++ b/tests/xlconfigdata/test-paravirt-type.cfg
@@ -0,0 +1,13 @@
+name = "XenGuest2"
+uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809"
+type = "pv"
+maxmem = 579
+memory = 394
+vcpus = 1
+localtime = 0
+on_poweroff = "destroy"
+on_reboot = "restart"
+on_crash = "restart"
+kernel = "/tmp/vmlinuz"
+ramdisk = "/tmp/initrd"
+cmdline = "root=/dev/xvda1 console=hvc0"
diff --git a/tests/xlconfigdata/test-paravirt-type.xml b/tests/xlconfigdata/test-paravirt-type.xml
new file mode 100644
index 0000000..4357640
--- /dev/null
+++ b/tests/xlconfigdata/test-paravirt-type.xml
@@ -0,0 +1,25 @@
+<domain type='xen'>
+ <name>XenGuest2</name>
+ <uuid>c7a5fdb2-cdaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>592896</memory>
+ <currentMemory unit='KiB'>403456</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='x86_64' machine='xenpv'>linux</type>
+ <kernel>/tmp/vmlinuz</kernel>
+ <initrd>/tmp/initrd</initrd>
+ <cmdline>root=/dev/xvda1 console=hvc0</cmdline>
+ </os>
+ <clock offset='utc' adjustment='reset'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>restart</on_crash>
+ <devices>
+ <console type='pty'>
+ <target type='xen' port='0'/>
+ </console>
+ <input type='mouse' bus='xen'/>
+ <input type='keyboard' bus='xen'/>
+ <memballoon model='xen'/>
+ </devices>
+</domain>
diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c
index b2e4591..6e3267e 100644
--- a/tests/xlconfigtest.c
+++ b/tests/xlconfigtest.c
@@ -279,6 +279,8 @@ mymain(void)
DO_TEST_FORMAT("paravirt-cmdline-extra-root", false);
DO_TEST_FORMAT("paravirt-cmdline-bogus-extra-root", false);
DO_TEST("rbd-multihost-noauth");
+ DO_TEST_FORMAT("paravirt-type", false);
+ DO_TEST_FORMAT("fullvirt-type", false);

#ifdef LIBXL_HAVE_DEVICE_CHANNEL
DO_TEST("channel-pty");
--
git-series 0.9.1
Marek Marczykowski-Górecki
2018-11-26 19:34:41 UTC
Permalink
Signed-off-by: Marek Marczykowski-Górecki <***@invisiblethingslab.com>
---
New patch in v5
---
docs/news.xml | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/docs/news.xml b/docs/news.xml
index 4406aeb..d345271 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -68,6 +68,14 @@
be viewed via the domain statistics.
</description>
</change>
+ <change>
+ <summary>
+ libxl: Add XEN PVH support
+ </summary>
+ <description>
+ The libxl driver now has support for PVH os type.
+ </description>
+ </change>
</section>
<section title="Improvements">
</section>
--
git-series 0.9.1
Jim Fehlig
2018-11-27 00:22:11 UTC
Permalink
Post by Marek Marczykowski-Górecki
---
New patch in v5
---
docs/news.xml | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/docs/news.xml b/docs/news.xml
index 4406aeb..d345271 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -68,6 +68,14 @@
be viewed via the domain statistics.
</description>
</change>
+ <change>
+ <summary>
+ libxl: Add XEN PVH support
+ </summary>
+ <description>
+ The libxl driver now has support for PVH os type.
+ </description>
+ </change>
</section>
<section title="Improvements">
</section>
I tweaked the commit summary and this text a bit before pushing.

Regards,
Jim

diff --git a/docs/news.xml b/docs/news.xml
index d34527191b..26f3bdf16c 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -70,10 +70,12 @@
</change>
<change>
<summary>
- libxl: Add XEN PVH support
+ Xen: Add support for PVH
</summary>
<description>
- The libxl driver now has support for PVH os type.
+ The libxl driver now supports Xen's PVH virtual machine type.
+ PVH machines are enabled with the new "xenpvh" OS type, e.g.
+ <code>&lt;os&gt;&lt;type&gt;xenpvh&lt;/type&gt;&lt;/os&gt;</code>
</description>
</change>
</section>
Jim Fehlig
2018-11-27 00:28:16 UTC
Permalink
Hi Marek,

Thanks for all of the work! I've pushed this series, just in time for the 4.10.0
freeze :-). Please keep an eye out for any Coverity fallout (or anything else we
may have missed) that needs fixed before the release.

Regards,
Jim
This is a respin of my old PVHv1 patch[1], converted to PVHv2. The actual code
use "PVH" name.
It introduce new guest ostype VIR_DOMAIN_OSTYPE_XENPVH, and also PVH machine,
machine="xenpvh" attribute is used.
Since PVHv2 relies on features in newer Xen versions, I needed to convert also
some older code. For example b_info->u.hvm.nested_hvm was deprecated in favor
of b_info->nested_hvm. While the code do handle both old and new versions
(obviously refusing PVHv2 if Xen is too old), this isn't the case for tests.
How it should be handled, if at all?
To test this with all supported Xen versions (4.6, 4.7, 4.8, 4.9, 4.10, 4.11,
unstable), I've extended travis configuration for that[2]. It isn't exactly
trivial to build Xen 4.6-4.8 on recent system, mostly thanks to -Werror and new
warnings, but also other toolchain changes. Because of this, the configuration
is rather hacky. But it may be a good idea to include multiple pre-built Xen
versions in the base docker image and choose one using ./configure options (maybe
together with some symlink or environment variable like PKG_CONFIG_PATH).
[1] https://www.redhat.com/archives/libvir-list/2016-August/msg00376.html
[2] https://github.com/marmarek/libvirt/tree/travis-xen-pvh
- drop "docs: don't refer to deprecated 'linux' ostype in example" patch -
migrating further away from "linux" os type is offtopic to this series and
apparently is a controversial thing
- drop "docs: update domain schema for machine attribute" patch -
already applied
- apply review comments from Jim
- rebase on master
- rebase on master, drop already applied patches
- use #ifdef LIBXL_DOMAIN_TYPE_PVH to detect PVH support, fix compilation
failure on older Xen
- exclude PVH from VIR_DOMAIN_OSTYPE_XEN <-> VIR_DOMAIN_OSTYPE_LINUX conversion
- fix reported capabilities for PVH
- change PVH support detection method
- use VIR_DOMAIN_OSTYPE_XENPVH
- add news entry
libxl: reorder libxlMakeDomBuildInfo for upcoming PVH support
libxl: add support for PVH
tests: add basic Xen PVH test
xenconfig: add support for parsing type= xl config entry
xenconfig: add support for type="pvh"
news: add libxl PVH
docs/formatcaps.html.in | 9 ++-
docs/news.xml | 8 ++-
docs/schemas/domaincommon.rng | 2 +-
m4/virt-driver-libxl.m4 | 3 +-
src/conf/domain_conf.c | 10 ++-
src/conf/domain_conf.h | 1 +-
src/libxl/libxl_capabilities.c | 38 +++++++++--
src/libxl/libxl_conf.c | 78 ++++++++++++++++------
src/libxl/libxl_driver.c | 6 +-
src/xenconfig/xen_common.c | 25 +++++--
src/xenconfig/xen_xl.c | 5 +-
tests/libxlxml2domconfigdata/basic-pvh.json | 49 ++++++++++++++-
tests/libxlxml2domconfigdata/basic-pvh.xml | 28 ++++++++-
tests/libxlxml2domconfigtest.c | 3 +-
tests/testutilsxen.c | 20 +++++-
tests/xlconfigdata/test-fullvirt-type.cfg | 21 ++++++-
tests/xlconfigdata/test-fullvirt-type.xml | 27 ++++++++-
tests/xlconfigdata/test-paravirt-type.cfg | 13 ++++-
tests/xlconfigdata/test-paravirt-type.xml | 25 +++++++-
tests/xlconfigdata/test-pvh-type.cfg | 13 ++++-
tests/xlconfigdata/test-pvh-type.xml | 25 +++++++-
tests/xlconfigtest.c | 3 +-
22 files changed, 375 insertions(+), 37 deletions(-)
create mode 100644 tests/libxlxml2domconfigdata/basic-pvh.json
create mode 100644 tests/libxlxml2domconfigdata/basic-pvh.xml
create mode 100644 tests/xlconfigdata/test-fullvirt-type.cfg
create mode 100644 tests/xlconfigdata/test-fullvirt-type.xml
create mode 100644 tests/xlconfigdata/test-paravirt-type.cfg
create mode 100644 tests/xlconfigdata/test-paravirt-type.xml
create mode 100644 tests/xlconfigdata/test-pvh-type.cfg
create mode 100644 tests/xlconfigdata/test-pvh-type.xml
base-commit: 794af564f4c96044b935ab898acc8e61a58b6bb5
Loading...