]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Add 'kvm version' command
authorSasha Levin <levinsasha928@gmail.com>
Fri, 8 Jul 2011 21:56:08 +0000 (00:56 +0300)
committerPekka Enberg <penberg@kernel.org>
Fri, 8 Jul 2011 22:23:03 +0000 (01:23 +0300)
Add a 'kvm version' command which prints the version of the kernel
used to build kvm tools.

Part of the code is based on and was loaned from perf.

Suggested-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/Documentation/kvm-version.txt [new file with mode: 0644]
tools/kvm/Makefile
tools/kvm/command-list.txt
tools/kvm/include/kvm/kvm-version.h [new file with mode: 0644]
tools/kvm/kvm-cmd.c
tools/kvm/kvm-version.c [new file with mode: 0644]
tools/kvm/util/KVMTOOLS-VERSION-GEN [new file with mode: 0755]

diff --git a/tools/kvm/Documentation/kvm-version.txt b/tools/kvm/Documentation/kvm-version.txt
new file mode 100644 (file)
index 0000000..bf51540
--- /dev/null
@@ -0,0 +1,21 @@
+kvm-version(1)
+================
+
+NAME
+----
+kvm-version - Print the version of the kernel tree kvm tools
+was built on.
+
+SYNOPSIS
+--------
+[verse]
+'kvm version'
+
+DESCRIPTION
+-----------
+The command prints the version of the kernel that was used to build
+kvm tools.
+
+Note that the version is not the version of the kernel which is currently
+running on the host, but is the version of the kernel tree from which kvm
+tools was built.
index 51a3d1abe489a158c5b03c2fe6a5c475e0dc187a..5ec222fbad288894063c59749ce7b66c09a3fcf6 100644 (file)
@@ -61,6 +61,7 @@ OBJS  += kvm-pause.o
 OBJS   += kvm-balloon.o
 OBJS   += kvm-list.o
 OBJS   += kvm-run.o
+OBJS   += kvm-version.o
 OBJS   += mptable.o
 OBJS   += rbtree.o
 OBJS   += threadpool.o
@@ -124,6 +125,7 @@ endif
 
 DEFINES        += -D_FILE_OFFSET_BITS=64
 DEFINES        += -D_GNU_SOURCE
+DEFINES        += -DKVMTOOLS_VERSION='"$(KVMTOOLS_VERSION)"'
 
 KVM_INCLUDE := include
 CFLAGS += $(CPPFLAGS) $(DEFINES) -I$(KVM_INCLUDE) -I../../include -I../../arch/$(ARCH)/include/ -Os -g
@@ -152,6 +154,10 @@ CFLAGS     += $(WARNINGS)
 
 all: $(PROGRAM)
 
+KVMTOOLS-VERSION-FILE:
+       @$(SHELL_PATH) util/KVMTOOLS-VERSION-GEN $(OUTPUT)
+-include $(OUTPUT)KVMTOOLS-VERSION-FILE
+
 $(PROGRAM): $(DEPS) $(OBJS)
        $(E) "  LINK    " $@
        $(Q) $(CC) $(OBJS) $(LIBS) -o $@
@@ -168,6 +174,7 @@ $(OBJS):
 
 rbtree.o: ../../lib/rbtree.c
        $(Q) $(CC) -c $(CFLAGS) $< -o $@
+
 %.o: %.c
        $(E) "  CC      " $@
        $(Q) $(CC) -c $(CFLAGS) $< -o $@
index 36dcd67bdb7b391bef3e591282d52ae0c3ecd155..81ba1402ba95f276a5cbd396c50d4f2e5b5d8652 100644 (file)
@@ -4,3 +4,4 @@
 #
 kvm-run                                mainporcelain common
 kvm-pause                      common
+kvm-version                    common
diff --git a/tools/kvm/include/kvm/kvm-version.h b/tools/kvm/include/kvm/kvm-version.h
new file mode 100644 (file)
index 0000000..83cac4d
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef KVM__VERSION_H
+#define KVM__VERSION_H
+
+int kvm_cmd_version(int argc, const char **argv, const char *prefix);
+
+#endif
index cecf0d051d4cd81ea9f61961cc0ddf6b0cde5775..404065b0a93011d536194a7f9a3dbeac880136ef 100644 (file)
@@ -9,6 +9,7 @@
 #include "kvm/kvm-pause.h"
 #include "kvm/kvm-balloon.h"
 #include "kvm/kvm-list.h"
+#include "kvm/kvm-version.h"
 #include "kvm/kvm-help.h"
 #include "kvm/kvm-cmd.h"
 #include "kvm/kvm-run.h"
@@ -18,6 +19,7 @@ struct cmd_struct kvm_commands[] = {
        { "debug",      kvm_cmd_debug,          NULL,         0 },
        { "balloon",    kvm_cmd_balloon,        NULL,         0 },
        { "list",       kvm_cmd_list,           NULL,         0 },
+       { "version",    kvm_cmd_version,        NULL,         0 },
        { "help",       kvm_cmd_help,           NULL,         0 },
        { "run",        kvm_cmd_run,            kvm_run_help, 0 },
        { NULL,         NULL,                   NULL,         0 },
diff --git a/tools/kvm/kvm-version.c b/tools/kvm/kvm-version.c
new file mode 100644 (file)
index 0000000..e30f74c
--- /dev/null
@@ -0,0 +1,15 @@
+#include <kvm/util.h>
+#include <kvm/kvm-cmd.h>
+#include <kvm/kvm-version.h>
+#include <kvm/kvm.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+
+int kvm_cmd_version(int argc, const char **argv, const char *prefix)
+{
+       printf("%s\n", KVMTOOLS_VERSION);
+
+       return 0;
+}
diff --git a/tools/kvm/util/KVMTOOLS-VERSION-GEN b/tools/kvm/util/KVMTOOLS-VERSION-GEN
new file mode 100755 (executable)
index 0000000..1af9d6c
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+if [ $# -eq 1 ]  ; then
+       OUTPUT=$1
+fi
+
+GVF=${OUTPUT}KVMTOOLS-VERSION-FILE
+
+LF='
+'
+
+# First check if there is a .git to get the version from git describe
+# otherwise try to get the version from the kernel makefile
+if test -d ../../.git -o -f ../../.git &&
+       VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
+       case "$VN" in
+       *$LF*) (exit 1) ;;
+       v[0-9]*)
+               git update-index -q --refresh
+               test -z "$(git diff-index --name-only HEAD --)" ||
+               VN="$VN-dirty" ;;
+       esac
+then
+       VN=$(echo "$VN" | sed -e 's/-/./g');
+else
+       VN=$(MAKEFLAGS= make -sC ../.. kernelversion)
+fi
+
+VN=$(expr "$VN" : v*'\(.*\)')
+
+if test -r $GVF
+then
+       VC=$(sed -e 's/^KVMTOOLS_VERSION = //' <$GVF)
+else
+       VC=unset
+fi
+test "$VN" = "$VC" || {
+       echo >&2 "KVMTOOLS_VERSION = $VN"
+       echo "KVMTOOLS_VERSION = $VN" >$GVF
+}