Blame SOURCES/0013-Add-lkvm-detection.patch

b6cf65
From 18d21a55c9551b76f0cdb93cd8e7b127173f083b Mon Sep 17 00:00:00 2001
b6cf65
From: Andrew Jones <drjones@redhat.com>
b6cf65
Date: Fri, 27 Mar 2015 21:18:59 +0100
b6cf65
Subject: [PATCH 13/16] Add lkvm detection
b6cf65
b6cf65
Signed-off-by: Andrew Jones <drjones@redhat.com>
b6cf65
---
b6cf65
 Makefile.am                            |  6 ++++++
b6cf65
 tests/lkvm/proc/cpuinfo                | 19 +++++++++++++++++
b6cf65
 tests/lkvm/proc/self/status            | 39 ++++++++++++++++++++++++++++++++++
b6cf65
 tests/lkvm/sbin/dmidecode              |  2 ++
b6cf65
 tests/lkvm/sbin/uname                  |  2 ++
b6cf65
 tests/lkvm/sbin/virt-what-cpuid-helper |  2 ++
b6cf65
 tests/test-lkvm.sh                     | 34 +++++++++++++++++++++++++++++
b6cf65
 virt-what.in                           |  8 +++++++
b6cf65
 virt-what.pod                          |  8 +++++++
b6cf65
 9 files changed, 120 insertions(+)
b6cf65
 create mode 100644 tests/lkvm/proc/cpuinfo
b6cf65
 create mode 100644 tests/lkvm/proc/self/status
b6cf65
 create mode 100755 tests/lkvm/sbin/dmidecode
b6cf65
 create mode 100755 tests/lkvm/sbin/uname
b6cf65
 create mode 100755 tests/lkvm/sbin/virt-what-cpuid-helper
b6cf65
 create mode 100755 tests/test-lkvm.sh
b6cf65
b6cf65
diff --git a/Makefile.am b/Makefile.am
b6cf65
index 1c14948..46ff548 100644
b6cf65
--- a/Makefile.am
b6cf65
+++ b/Makefile.am
b6cf65
@@ -46,6 +46,7 @@ TESTS = \
b6cf65
 	tests/test-kvm.sh \
b6cf65
 	tests/test-kvm-explicit-cpu.sh \
b6cf65
 	tests/test-linux-vserver.sh \
b6cf65
+	tests/test-lkvm.sh \
b6cf65
 	tests/test-lxc.sh \
b6cf65
 	tests/test-lx86.sh \
b6cf65
 	tests/test-parallels-desktop.sh \
b6cf65
@@ -95,6 +96,11 @@ EXTRA_DIST = \
b6cf65
 	tests/linux-vserver/sbin/dmidecode \
b6cf65
 	tests/linux-vserver/sbin/uname \
b6cf65
 	tests/linux-vserver/sbin/virt-what-cpuid-helper \
b6cf65
+	tests/lkvm/proc/cpuinfo \
b6cf65
+	tests/lkvm/proc/self/status \
b6cf65
+	tests/lkvm/sbin/dmidecode \
b6cf65
+	tests/lkvm/sbin/uname \
b6cf65
+	tests/lkvm/sbin/virt-what-cpuid-helper \
b6cf65
 	tests/lxc/proc/1/environ \
b6cf65
 	tests/lxc/proc/cpuinfo \
b6cf65
 	tests/lxc/proc/self/status \
b6cf65
diff --git a/tests/lkvm/proc/cpuinfo b/tests/lkvm/proc/cpuinfo
b6cf65
new file mode 100644
b6cf65
index 0000000..a53a4b9
b6cf65
--- /dev/null
b6cf65
+++ b/tests/lkvm/proc/cpuinfo
b6cf65
@@ -0,0 +1,19 @@
b6cf65
+processor	: 0
b6cf65
+vendor_id	: GenuineIntel
b6cf65
+cpu family	: 6
b6cf65
+model		: 15
b6cf65
+model name	: Intel(R) Core(TM)2 Duo CPU     T7700  @ 2.40GHz
b6cf65
+stepping	: 11
b6cf65
+cpu MHz		: 2659.998
b6cf65
+cache size	: 4096 KB
b6cf65
+fpu		: yes
b6cf65
+fpu_exception	: yes
b6cf65
+cpuid level	: 10
b6cf65
+wp		: yes
b6cf65
+flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx lm constant_tsc up rep_good pni ssse3 cx16 hypervisor lahf_lm
b6cf65
+bogomips	: 5319.99
b6cf65
+clflush size	: 64
b6cf65
+cache_alignment	: 64
b6cf65
+address sizes	: 40 bits physical, 48 bits virtual
b6cf65
+power management:
b6cf65
+
b6cf65
diff --git a/tests/lkvm/proc/self/status b/tests/lkvm/proc/self/status
b6cf65
new file mode 100644
b6cf65
index 0000000..264981d
b6cf65
--- /dev/null
b6cf65
+++ b/tests/lkvm/proc/self/status
b6cf65
@@ -0,0 +1,39 @@
b6cf65
+Name:	cat
b6cf65
+State:	R (running)
b6cf65
+Tgid:	1618
b6cf65
+Pid:	1618
b6cf65
+PPid:	1609
b6cf65
+TracerPid:	0
b6cf65
+Uid:	0	0	0	0
b6cf65
+Gid:	0	0	0	0
b6cf65
+Utrace:	0
b6cf65
+FDSize:	256
b6cf65
+Groups:	0 1 2 3 4 6 10 
b6cf65
+VmPeak:	  101012 kB
b6cf65
+VmSize:	  101012 kB
b6cf65
+VmLck:	       0 kB
b6cf65
+VmHWM:	     472 kB
b6cf65
+VmRSS:	     472 kB
b6cf65
+VmData:	     184 kB
b6cf65
+VmStk:	     136 kB
b6cf65
+VmExe:	      44 kB
b6cf65
+VmLib:	    1728 kB
b6cf65
+VmPTE:	      44 kB
b6cf65
+VmSwap:	       0 kB
b6cf65
+Threads:	1
b6cf65
+SigQ:	0/7858
b6cf65
+SigPnd:	0000000000000000
b6cf65
+ShdPnd:	0000000000000000
b6cf65
+SigBlk:	0000000000000000
b6cf65
+SigIgn:	0000000000000000
b6cf65
+SigCgt:	0000000000000000
b6cf65
+CapInh:	0000000000000000
b6cf65
+CapPrm:	ffffffffffffffff
b6cf65
+CapEff:	ffffffffffffffff
b6cf65
+CapBnd:	ffffffffffffffff
b6cf65
+Cpus_allowed:	1
b6cf65
+Cpus_allowed_list:	0
b6cf65
+Mems_allowed:	00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001
b6cf65
+Mems_allowed_list:	0
b6cf65
+voluntary_ctxt_switches:	0
b6cf65
+nonvoluntary_ctxt_switches:	1
b6cf65
diff --git a/tests/lkvm/sbin/dmidecode b/tests/lkvm/sbin/dmidecode
b6cf65
new file mode 100755
b6cf65
index 0000000..e53c12f
b6cf65
--- /dev/null
b6cf65
+++ b/tests/lkvm/sbin/dmidecode
b6cf65
@@ -0,0 +1,2 @@
b6cf65
+#!/bin/sh -
b6cf65
+exit 1
b6cf65
diff --git a/tests/lkvm/sbin/uname b/tests/lkvm/sbin/uname
b6cf65
new file mode 100755
b6cf65
index 0000000..ab0ec89
b6cf65
--- /dev/null
b6cf65
+++ b/tests/lkvm/sbin/uname
b6cf65
@@ -0,0 +1,2 @@
b6cf65
+#!/bin/sh -
b6cf65
+echo x86_64
b6cf65
diff --git a/tests/lkvm/sbin/virt-what-cpuid-helper b/tests/lkvm/sbin/virt-what-cpuid-helper
b6cf65
new file mode 100755
b6cf65
index 0000000..2b068cd
b6cf65
--- /dev/null
b6cf65
+++ b/tests/lkvm/sbin/virt-what-cpuid-helper
b6cf65
@@ -0,0 +1,2 @@
b6cf65
+#!/bin/sh -
b6cf65
+echo LKVMLKVMLKVM
b6cf65
diff --git a/tests/test-lkvm.sh b/tests/test-lkvm.sh
b6cf65
new file mode 100755
b6cf65
index 0000000..6eb326c
b6cf65
--- /dev/null
b6cf65
+++ b/tests/test-lkvm.sh
b6cf65
@@ -0,0 +1,34 @@
b6cf65
+# Test for LKVM
b6cf65
+# Copyright (C) 2015 Red Hat Inc.
b6cf65
+#
b6cf65
+# This program is free software; you can redistribute it and/or modify
b6cf65
+# it under the terms of the GNU General Public License as published by
b6cf65
+# the Free Software Foundation; either version 2 of the License, or
b6cf65
+# (at your option) any later version.
b6cf65
+#
b6cf65
+# This program is distributed in the hope that it will be useful,
b6cf65
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
b6cf65
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b6cf65
+# GNU General Public License for more details.
b6cf65
+#
b6cf65
+# You should have received a copy of the GNU General Public License
b6cf65
+# along with this program; if not, write to the Free Software
b6cf65
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
b6cf65
+
b6cf65
+root=tests/lkvm
b6cf65
+
b6cf65
+output="$(./virt-what --test-root=$root 2>&1)"
b6cf65
+expected="lkvm"
b6cf65
+
b6cf65
+if [ "$output" != "$expected" ]; then
b6cf65
+    echo "$0: test failed because output did not match expected"
b6cf65
+    echo "Expected output was:"
b6cf65
+    echo "----------------------------------------"
b6cf65
+    echo "$expected"
b6cf65
+    echo "----------------------------------------"
b6cf65
+    echo "But the actual output of the program was:"
b6cf65
+    echo "----------------------------------------"
b6cf65
+    echo "$output"
b6cf65
+    echo "----------------------------------------"
b6cf65
+    exit 1
b6cf65
+fi
b6cf65
diff --git a/virt-what.in b/virt-what.in
b6cf65
index 0770070..ed08dae 100644
b6cf65
--- a/virt-what.in
b6cf65
+++ b/virt-what.in
b6cf65
@@ -30,6 +30,7 @@
b6cf65
 set -u
b6cf65
 root=''
b6cf65
 skip_qemu_kvm=false
b6cf65
+skip_lkvm=false
b6cf65
 
b6cf65
 VERSION="@VERSION@"
b6cf65
 
b6cf65
@@ -215,6 +216,7 @@ elif [ -d "${root}/proc/xen" ]; then
b6cf65
         echo xen-domU
b6cf65
     fi
b6cf65
     skip_qemu_kvm=true
b6cf65
+    skip_lkvm=true
b6cf65
 elif [ -f "${root}/sys/hypervisor/type" ] &&
b6cf65
     grep -q "xen" "${root}/sys/hypervisor/type"; then
b6cf65
     # Ordinary kernel with pv_ops.  There does not seem to be
b6cf65
@@ -259,6 +261,12 @@ if ! "$skip_qemu_kvm"; then
b6cf65
     fi
b6cf65
 fi
b6cf65
 
b6cf65
+if ! "$skip_lkvm"; then
b6cf65
+    if [ "$cpuid" = "LKVMLKVMLKVM" ]; then
b6cf65
+        echo lkvm
b6cf65
+    fi
b6cf65
+fi
b6cf65
+
b6cf65
 # Check for Docker.
b6cf65
 if [ -f "${root}/.dockerinit" ]; then
b6cf65
 	echo docker
b6cf65
diff --git a/virt-what.pod b/virt-what.pod
b6cf65
index 8fd9bc4..0e2e8a5 100644
b6cf65
--- a/virt-what.pod
b6cf65
+++ b/virt-what.pod
b6cf65
@@ -101,6 +101,14 @@ instead.
b6cf65
 
b6cf65
 Status: confirmed by RWMJ.
b6cf65
 
b6cf65
+=item B<lkvm>
b6cf65
+
b6cf65
+This guest is running on the KVM hypervisor using hardware
b6cf65
+acceleration, and the userspace component of the hypervisor
b6cf65
+is lkvm (a.k.a kvmtool).
b6cf65
+
b6cf65
+Status: contributed by Andrew Jones
b6cf65
+
b6cf65
 =item B<openvz>
b6cf65
 
b6cf65
 The guest appears to be running inside an OpenVZ or Virtuozzo
b6cf65
-- 
b6cf65
2.3.1
b6cf65