From 435b9d99cce9b729de72fffbcae15ea0c1101aef Mon Sep 17 00:00:00 2001 From: Philipp Hahn Date: Fri, 14 Oct 2011 14:10:26 +0200 Subject: [PATCH] Xen: Fake versions in xencapstest MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit virInitialize() → xenRegister() → xenhypervisorInit() determines the version of the Hypervisor. This breaks xencapstest when building as root on a dom0 system, since xenHypervisorBuildCapabilities() adds the "hap" and "viridian" features based on the detected version. Add an optional parameter to xenhypervisorInit() to disable automatic detection of the Hypervisor version. The passed in arguments are used instead. Signed-off-by: Philipp Hahn --- src/xen/xen_driver.c | 2 +- src/xen/xen_hypervisor.c | 14 ++++++++++++-- src/xen/xen_hypervisor.h | 2 +- tests/xencapstest.c | 10 ++++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 9c96fcab46..68abb1759a 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -2272,7 +2272,7 @@ int xenRegister (void) { /* Ignore failures here. */ - (void) xenHypervisorInit (); + (void) xenHypervisorInit (NULL); #ifdef WITH_LIBVIRTD if (virRegisterStateDriver (&state_driver) == -1) return -1; diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c index b552e4745d..58ae6a3edb 100644 --- a/src/xen/xen_hypervisor.c +++ b/src/xen/xen_hypervisor.c @@ -1951,12 +1951,16 @@ virXen_getvcpusinfo(int handle, int id, unsigned int vcpu, virVcpuInfoPtr ipt, /** * xenHypervisorInit: + * @override_versions: pointer to optional struct xenHypervisorVersions with + * version information used instead of automatic version detection. * * Initialize the hypervisor layer. Try to detect the kind of interface * used i.e. pre or post changeset 10277 + * + * Returns 0 or -1 in case of failure */ int -xenHypervisorInit(void) +xenHypervisorInit(struct xenHypervisorVersions *override_versions) { int fd, ret, cmd, errcode; hypercall_t hc; @@ -2007,6 +2011,12 @@ xenHypervisorInit(void) return -1; } + if (override_versions) { + hv_versions = *override_versions; + in_init = 0; + return 0; + } + /* Xen hypervisor version detection begins. */ ret = open(XEN_HYPERVISOR_SOCKET, O_RDWR); if (ret < 0) { @@ -2188,7 +2198,7 @@ xenHypervisorOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); if (initialized == 0) - if (xenHypervisorInit() == -1) + if (xenHypervisorInit(NULL) == -1) return -1; priv->handle = -1; diff --git a/src/xen/xen_hypervisor.h b/src/xen/xen_hypervisor.h index cf8153ef06..77c6f74725 100644 --- a/src/xen/xen_hypervisor.h +++ b/src/xen/xen_hypervisor.h @@ -26,7 +26,7 @@ struct xenHypervisorVersions { }; extern struct xenUnifiedDriver xenHypervisorDriver; -int xenHypervisorInit (void); +int xenHypervisorInit(struct xenHypervisorVersions *override_versions); virCapsPtr xenHypervisorMakeCapabilities (virConnectPtr conn); diff --git a/tests/xencapstest.c b/tests/xencapstest.c index 9c1eba4d39..ca93857516 100644 --- a/tests/xencapstest.c +++ b/tests/xencapstest.c @@ -145,11 +145,21 @@ static int testXenppc64(const void *data ATTRIBUTE_UNUSED) { } +/* Fake initialization data for xenHypervisorInit(). Must be initialized + * explicitly before the implicit call via virInitialize(). */ +static struct xenHypervisorVersions hv_versions = { + .hv = 0, + .hypervisor = 2, + .sys_interface = -1, + .dom_interface = -1, +}; + static int mymain(void) { int ret = 0; + xenHypervisorInit(&hv_versions); virInitialize(); if (virtTestRun("Capabilities for i686, no PAE, no HVM", -- 2.47.2