[PATCH v2 2/2] Xen: Fake versions in xencapstest

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



virInitialize() → xenRegister() → xenhypervisorInit() determins 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 <hahn@xxxxxxxxxxxxx>
---
 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 9c96fca..68abb17 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 da70c52..87a0fca 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 informations 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 d8b630a..6cacf55 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 9c1eba4..092f99a 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",
-- 
1.7.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]