Blob Blame History Raw
From 18d21a55c9551b76f0cdb93cd8e7b127173f083b Mon Sep 17 00:00:00 2001
From: Andrew Jones <drjones@redhat.com>
Date: Fri, 27 Mar 2015 21:18:59 +0100
Subject: [PATCH 13/16] Add lkvm detection

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 Makefile.am                            |  6 ++++++
 tests/lkvm/proc/cpuinfo                | 19 +++++++++++++++++
 tests/lkvm/proc/self/status            | 39 ++++++++++++++++++++++++++++++++++
 tests/lkvm/sbin/dmidecode              |  2 ++
 tests/lkvm/sbin/uname                  |  2 ++
 tests/lkvm/sbin/virt-what-cpuid-helper |  2 ++
 tests/test-lkvm.sh                     | 34 +++++++++++++++++++++++++++++
 virt-what.in                           |  8 +++++++
 virt-what.pod                          |  8 +++++++
 9 files changed, 120 insertions(+)
 create mode 100644 tests/lkvm/proc/cpuinfo
 create mode 100644 tests/lkvm/proc/self/status
 create mode 100755 tests/lkvm/sbin/dmidecode
 create mode 100755 tests/lkvm/sbin/uname
 create mode 100755 tests/lkvm/sbin/virt-what-cpuid-helper
 create mode 100755 tests/test-lkvm.sh

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