summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Jones <rjones@trick.home.annexia.org>2009-07-23 09:18:57 +0100
committerRichard Jones <rjones@trick.home.annexia.org>2009-07-23 09:59:36 +0100
commitb8957a6bd16be4c6c2c2893d621ed84bf21d0f72 (patch)
tree8b5791bac62a62cbb03db9b31260a5dee4625e03
parent7880dab8d6e6d85cb086960750916b7f578e537f (diff)
downloadvirt-what-b8957a6bd16be4c6c2c2893d621ed84bf21d0f72.tar.gz
virt-what-b8957a6bd16be4c6c2c2893d621ed84bf21d0f72.tar.xz
virt-what-b8957a6bd16be4c6c2c2893d621ed84bf21d0f72.zip
Autoconfify, add CPUID helper program to detect HVM domains (Paolo Bonzini).1.1
-rw-r--r--.gitignore22
-rw-r--r--MANIFEST7
-rw-r--r--Makefile72
-rw-r--r--Makefile.am32
-rw-r--r--README12
-rw-r--r--configure.ac35
-rw-r--r--virt-what-cpuid-helper.c62
-rw-r--r--virt-what.in (renamed from virt-what.sh)21
-rw-r--r--virt-what.pod33
9 files changed, 197 insertions, 99 deletions
diff --git a/.gitignore b/.gitignore
index ac440a2..7e5d90b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,21 @@
*~
+*.o
+virt-what-*.tar.gz
+.deps
+Makefile
+Makefile.in
+aclocal.m4
+autom4te.cache
+compile
+config.h
+config.h.in
+config.log
+config.status
+configure
+depcomp
+install-sh
+missing
+stamp-h1
virt-what
-virt-what.1
-virt-what.txt
-*.tar.gz
+virt-what-cpuid-helper
+virt-what.1 \ No newline at end of file
diff --git a/MANIFEST b/MANIFEST
deleted file mode 100644
index 6b1a12c..0000000
--- a/MANIFEST
+++ /dev/null
@@ -1,7 +0,0 @@
-.cvsignore
-COPYING
-Makefile
-MANIFEST
-README
-virt-what.pod
-virt-what.sh
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 7c1ca45..0000000
--- a/Makefile
+++ /dev/null
@@ -1,72 +0,0 @@
-# Makefile for virt-what
-#
-# Copyright (C) 2008-2009 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.
-
-PACKAGE = virt-what
-VERSION = 1.0
-
-prefix = /usr/local
-bindir = $(prefix)/bin
-mandir = $(prefix)/share/man
-
-all: virt-what.1 virt-what.txt virt-what
-
-virt-what: virt-what.sh
- sed -e 's/@VERSION@/$(VERSION)/g' < $< > $@
- chmod 0755 $@
-
-virt-what.1: virt-what.pod
- pod2man -c "Virtualization Support" --release "$(PACKAGE)-$(VERSION)" \
- $< > $@
-
-virt-what.txt: virt-what.pod
- pod2text $< > $@
-
-clean:
- rm -f virt-what virt-what.1 virt-what.txt
- rm -f *~
-
-# Install.
-
-install:
- mkdir -p $(DESTDIR)$(bindir)
- mkdir -p $(DESTDIR)$(mandir)/man1
- install -m 0755 virt-what $(DESTDIR)$(bindir)/
- install -m 0644 virt-what.1 $(DESTDIR)$(mandir)/man1/
-
-# Distribution.
-
-dist:
- $(MAKE) check-manifest
- rm -rf $(PACKAGE)-$(VERSION)
- mkdir $(PACKAGE)-$(VERSION)
- tar -cf - -T MANIFEST | tar -C $(PACKAGE)-$(VERSION) -xf -
- tar zcf $(PACKAGE)-$(VERSION).tar.gz $(PACKAGE)-$(VERSION)
- rm -rf $(PACKAGE)-$(VERSION)
- ls -l $(PACKAGE)-$(VERSION).tar.gz
-
-check-manifest:
- @for d in `find -type d -name CVS | grep -v '^\./debian/'`; \
- do \
- b=`dirname $$d`/; \
- awk -F/ '$$1 != "D" {print $$2}' $$d/Entries | \
- sed -e "s|^|$$b|" -e "s|^\./||"; \
- done | sort > .check-manifest; \
- sort MANIFEST > .orig-manifest; \
- diff -u .orig-manifest .check-manifest; rv=$$?; \
- rm -f .orig-manifest .check-manifest; \
- exit $$rv
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..1c9777f
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,32 @@
+# Makefile for virt-what
+# Copyright (C) 2008-2009 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.
+
+EXTRA_DIST = virt-what.in virt-what.pod
+
+AM_CPPFLAGS = -Wall
+
+bin_SCRIPTS = virt-what
+bin_PROGRAMS = virt-what-cpuid-helper
+
+man_MANS = virt-what.1
+
+virt-what.1: virt-what.pod
+ pod2man -c "Virtualization Support" --release "$(PACKAGE)-$(VERSION)" \
+ $< > $@
+
+virt-what.txt: virt-what.pod
+ pod2text $< > $@
diff --git a/README b/README
index d50e9dc..a97fdb3 100644
--- a/README
+++ b/README
@@ -1,10 +1,20 @@
virt-what
-Copyright (C) 2008 Red Hat Inc.
+Copyright (C) 2008-2009 Red Hat Inc.
+----------------------------------------------------------------------
+
+This is a collection of scripts which you can use to work out what
+sort of virtualization you are running inside.
Build:
+ ./configure
make
+If you want to run it from the local directory, then you have to set
+the PATH:
+
+ PATH=.:$PATH ./virt-what
+
To install (usually as root):
make install
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..5b209d8
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,35 @@
+# virt-what
+# Copyright (C) 2008-2009 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.
+
+AC_INIT([virt-what],1.1)
+AM_INIT_AUTOMAKE([foreign])
+
+dnl Check for basic C environment.
+AC_PROG_CC_STDC
+AC_PROG_INSTALL
+AC_PROG_CPP
+
+AC_C_PROTOTYPES
+test "x$U" != "x" && AC_MSG_ERROR([Compiler not ANSI compliant])
+
+AM_PROG_CC_C_O
+
+dnl Produce output files.
+AC_CONFIG_HEADERS([config.h])
+AC_CONFIG_FILES([virt-what],[chmod +x virt-what])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
diff --git a/virt-what-cpuid-helper.c b/virt-what-cpuid-helper.c
new file mode 100644
index 0000000..76ce6a2
--- /dev/null
+++ b/virt-what-cpuid-helper.c
@@ -0,0 +1,62 @@
+/* virt-what-cpuid-helper: Are we running inside KVM or Xen HVM?
+ * Copyright (C) 2008 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.
+ */
+
+/* This program was suggested by Gleb Natapov and written by Paolo
+ * Bonzini, with a few modifications by Richard W.M. Jones.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#if defined(__i386__) || defined(__x86_64__)
+void
+cpu_sig (char *sig)
+{
+ unsigned int eax = 0x40000000;
+ unsigned int *sig32 = (unsigned int *)sig;
+ asm volatile (
+ "xor %%ebx, %%ebx; cpuid"
+ : "=a" (eax), "=b" (sig32[0]), "=c" (sig32[1]), "=d" (sig32[2])
+ : "0" (eax));
+ sig[12] = 0;
+}
+#else
+void
+cpu_sig (char *sig)
+{
+ /* nothing for other architectures */
+}
+#endif
+
+int
+main()
+{
+ char sig[13];
+
+ memset (sig, 0, sizeof sig);
+
+ cpu_sig (sig);
+
+ puts (sig);
+ /* Possible values:
+ * KVMKVMKVM KVM guest
+ * XenVMMXenVMM Xen HVM guest
+ */
+
+ return 0;
+}
diff --git a/virt-what.sh b/virt-what.in
index ae78f7b..cc61aae 100644
--- a/virt-what.sh
+++ b/virt-what.in
@@ -1,6 +1,6 @@
#!/bin/bash -
-#
-# Copyright (C) 2008 Red Hat Inc.
+# @configure_input@
+# Copyright (C) 2008-2009 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
@@ -87,9 +87,17 @@ if [ -d /proc/vz -a ! -d /proc/bc ]; then
echo openvz
fi
+# To tell if it is Xen and KVM HVM (fully virtualized) we can use this
+# helper C program.
+
+cpuid=`virt-what-cpuid-helper`
+
# Check for Xen.
-if [ -f /proc/xen/privcmd ]; then
+if [ "$cpuid" = "XenVMMXenVMM" ]; then
+ echo xen; echo xen-hvm
+ is_xen=1
+elif [ -f /proc/xen/privcmd ]; then
echo xen; echo xen-dom0
is_xen=1
elif [ -f /proc/xen/capabilities ]; then
@@ -109,7 +117,10 @@ if [ ! "$is_xen" ]; then
# uses QEMU for its device model.
if grep -q 'QEMU' /proc/cpuinfo; then
- # XXX How to distinguish between QEMU & KVM?
- echo qemu
+ if [ "$cpuid" = "KVMKVMKVM" ]; then
+ echo kvm
+ else
+ echo qemu
+ fi
fi
fi
diff --git a/virt-what.pod b/virt-what.pod
index 3fc4b25..0cfb753 100644
--- a/virt-what.pod
+++ b/virt-what.pod
@@ -23,47 +23,58 @@ don't know about or cannot detect.
=over 4
-=item openvz
+=item B<openvz>
The guest appears to be running inside an OpenVZ or Virtuozzo
container.
Status: contributed by Evgeniy Sokolov
-=item qemu
+=item B<kvm>
-This is QEMU or KVM.
+This is KVM.
-Status: confirmed by RWMJ. Currently we have no way to
-tell the difference between QEMU and KVM guests.
+Status: confirmed by RWMJ.
-=item virtualpc
+=item B<qemu>
+
+This is QEMU.
+
+Status: confirmed by RWMJ.
+
+=item B<virtualpc>
The guest appears to be running on Microsoft VirtualPC.
Status: not confirmed
-=item vmware
+=item B<vmware>
The guest appears to be running on VMware.
Status: not confirmed
-=item xen
+=item B<xen>
The guest appears to be running on Xen.
Status: confirmed by RWMJ
-=item xen-dom0
+=item B<xen-dom0>
This is the Xen dom0 (privileged domain).
Status: confirmed by RWMJ
-=item xen-domU
+=item B<xen-domU>
+
+This is a Xen domU (paravirtualized guest domain).
+
+Status: confirmed by RWMJ
+
+=item B<xen-hvm>
-This is a Xen domU (normal guest domain).
+This is a Xen guest fully virtualized (HVM).
Status: confirmed by RWMJ