summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Lawrance <stl@redhat.com>2011-06-29 15:31:14 +1000
committerGerrit Code Review <gerrit@beaker-gerrit.app.eng.bne.redhat.com>2011-06-29 15:31:14 +1000
commitbdd2c715225364b2563df0d2684098da18263cc0 (patch)
treeb4d4212c1bcaa061cde7c6c4b48b15bc93fab25b
parentb64673b2fd1e093d9702347576b4c26ff8446085 (diff)
parentd577367fab8ae0b90301155fad57319bbd3f454d (diff)
Merge "Report hypervisor to inventory" into developbeaker-distribution-inventory-1_1-50
-rw-r--r--Tasks/distribution/inventory/Makefile12
-rw-r--r--Tasks/distribution/inventory/hvm_detect.c86
-rwxr-xr-xTasks/distribution/inventory/pushInventory.py11
3 files changed, 108 insertions, 1 deletions
diff --git a/Tasks/distribution/inventory/Makefile b/Tasks/distribution/inventory/Makefile
index 3c09c7d..1d2d442 100644
--- a/Tasks/distribution/inventory/Makefile
+++ b/Tasks/distribution/inventory/Makefile
@@ -60,17 +60,27 @@ acpidump: $(TARGET)
acpixtract: $(TARGET)
cp $(TARGET)/acpixtract/acpixtract .
+BINFILE=hvm_detect
+hvm_detect: hvm_detect.c
+ if which gcc; then \
+ gcc $(BINFILE).c -o ./$(BINFILE) ;\
+ chmod a+x ./$(BINFILE) ;\
+ fi;
+
# executables to be built should be added here, they will be generated on the system under test.
ifeq ("$(ACPI_SUPPORT)", "yes")
BUILT_FILES=acpidump acpixtract
else
BUILT_FILES=
endif
+ifeq ($(shell arch),x86_64)
+ BUILT_FILES+=hvm_detect
+endif
# data files, .c files, scripts anything needed to either compile the test and/or run it.
FILES=$(METADATA) runtest.sh Makefile PURPOSE push-inventory.py \
software.py i18n.py disks.py pushInventory.py procfs.py \
- utilist.py getdriver.sh
+ utilist.py getdriver.sh hvm_detect.c
run: $(FILES) build
./runtest.sh
diff --git a/Tasks/distribution/inventory/hvm_detect.c b/Tasks/distribution/inventory/hvm_detect.c
new file mode 100644
index 0000000..1d20fb8
--- /dev/null
+++ b/Tasks/distribution/inventory/hvm_detect.c
@@ -0,0 +1,86 @@
+/******************************************************************************
+ *
+ * Based on XenSource's xen_detect.c file.
+ * determines execution on xen HVM or KVM platforms.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+static int pv_context;
+
+static void cpuid(uint32_t idx,
+ uint32_t *eax,
+ uint32_t *ebx,
+ uint32_t *ecx,
+ uint32_t *edx)
+{
+ asm volatile (
+ "test %1,%1 ; jz 1f ; ud2a ; .ascii \"xen\" ; 1: cpuid"
+ : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
+ : "0" (idx), "1" (pv_context) );
+}
+
+static int check_for_hvm(void)
+{
+ uint32_t eax, ebx, ecx, edx;
+ char signature[13];
+
+ cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
+ *(uint32_t *)(signature + 0) = ebx;
+ *(uint32_t *)(signature + 4) = ecx;
+ *(uint32_t *)(signature + 8) = edx;
+ signature[12] = '\0';
+
+ /* is this a kvm guest? */
+ if ( !strcmp("KVMKVMKVM", signature) ) {
+ printf("KVM guest.\n");
+ return 1;
+ } else if ( !strcmp("XenVMMXenVMM", signature) ) {
+ printf("Xen HVM guest.\n");
+ return 1;
+ } else if ( !strcmp("Microsoft Hv", signature) ) {
+ printf("Microsoft Hv guest.\n");
+ return 1;
+ } else if ( !strcmp("VMwareVMware", signature) ) {
+ printf("VMWare guest.\n");
+ return 1;
+ } else {
+ printf("No KVM or Xen HVM\n");
+ return 0;
+ }
+ return 0;
+}
+
+int main(void)
+{
+ /* Check for execution in HVM context. */
+ if ( check_for_hvm() )
+ return 0;
+ else
+ return 1;
+
+}
diff --git a/Tasks/distribution/inventory/pushInventory.py b/Tasks/distribution/inventory/pushInventory.py
index 05ee19f..feefdc0 100755
--- a/Tasks/distribution/inventory/pushInventory.py
+++ b/Tasks/distribution/inventory/pushInventory.py
@@ -22,6 +22,7 @@ import os
import commands
import pprint
import glob
+from subprocess import Popen, PIPE
sys.path.append("/usr/share/smolt/client")
import smolt
@@ -123,6 +124,16 @@ def read_inventory():
'nodes': len(glob.glob('/sys/devices/system/node/node*')), #: number of NUMA nodes in the system, or 0 if not supported
}
+ if os.path.exists('./hvm_detect'):
+ hypervisor = Popen(['./hvm_detect'], stdout=PIPE).communicate()[0]
+ hvm_map = {"No KVM or Xen HVM\n" : None,
+ "KVM guest.\n" : u'KVM',
+ "Xen HVM guest.\n" : u'Xen',
+ "Microsoft Hv guest.\n" : u'HyperV',
+ "VMWare guest.\n" : u'VMWare',
+ }
+ data['Hypervisor'] = hvm_map[hypervisor]
+
for VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description in profile.deviceIter():
device = dict ( vendorID = "%04x" % (VendorID and VendorID or 0),
deviceID = "%04x" % (DeviceID and DeviceID or 0),