From patchwork Fri Jul 8 21:56:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 957482 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p68LuueE006947 for ; Fri, 8 Jul 2011 21:56:57 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751098Ab1GHV4y (ORCPT ); Fri, 8 Jul 2011 17:56:54 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:43127 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750879Ab1GHV4y (ORCPT ); Fri, 8 Jul 2011 17:56:54 -0400 Received: by wwe5 with SMTP id 5so2351812wwe.1 for ; Fri, 08 Jul 2011 14:56:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; bh=v+LB7tQ6wlQvmR0VkThPUZVRjqE8hTAvxNk9ACT/og4=; b=fDE5PiUCE1pROc+vZbWhzeggxpGXkjxVRg8BOLBmkhh+yPde+5/uXjW52ZeFWVf8AA zpfHuHVbsN3qJgdcwQ+QNLb5C+jfaEOBRTFURE+pN+N5D2AWnWfDUtKx+bFKDcUB85vS qbRfWJguPIAgtUe8QI6PxKJt5EQnL5jajUPoE= Received: by 10.216.235.134 with SMTP id u6mr1009713weq.99.1310162212728; Fri, 08 Jul 2011 14:56:52 -0700 (PDT) Received: from localhost.localdomain (bzq-79-178-209-230.red.bezeqint.net [79.178.209.230]) by mx.google.com with ESMTPS id m35sm1493611weq.36.2011.07.08.14.56.48 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 08 Jul 2011 14:56:52 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: kvm@vger.kernel.org, mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, Sasha Levin Subject: [PATCH 1/7] kvm tools: Add 'kvm version' command Date: Sat, 9 Jul 2011 00:56:08 +0300 Message-Id: <1310162174-3426-1-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.6 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 08 Jul 2011 21:56:57 +0000 (UTC) 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 Signed-off-by: Sasha Levin --- tools/kvm/Documentation/kvm-version.txt | 21 +++++++++++++++ tools/kvm/Makefile | 7 +++++ tools/kvm/command-list.txt | 1 + tools/kvm/include/kvm/kvm-version.h | 6 ++++ tools/kvm/kvm-cmd.c | 2 + tools/kvm/kvm-version.c | 15 +++++++++++ tools/kvm/util/KVMTOOLS-VERSION-GEN | 42 +++++++++++++++++++++++++++++++ 7 files changed, 94 insertions(+), 0 deletions(-) create mode 100644 tools/kvm/Documentation/kvm-version.txt create mode 100644 tools/kvm/include/kvm/kvm-version.h create mode 100644 tools/kvm/kvm-version.c create mode 100755 tools/kvm/util/KVMTOOLS-VERSION-GEN diff --git a/tools/kvm/Documentation/kvm-version.txt b/tools/kvm/Documentation/kvm-version.txt new file mode 100644 index 0000000..bf51540 --- /dev/null +++ b/tools/kvm/Documentation/kvm-version.txt @@ -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. diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index 51a3d1a..5ec222f 100644 --- a/tools/kvm/Makefile +++ b/tools/kvm/Makefile @@ -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 $@ diff --git a/tools/kvm/command-list.txt b/tools/kvm/command-list.txt index 36dcd67b..81ba140 100644 --- a/tools/kvm/command-list.txt +++ b/tools/kvm/command-list.txt @@ -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 index 0000000..83cac4d --- /dev/null +++ b/tools/kvm/include/kvm/kvm-version.h @@ -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 diff --git a/tools/kvm/kvm-cmd.c b/tools/kvm/kvm-cmd.c index cecf0d0..404065b 100644 --- a/tools/kvm/kvm-cmd.c +++ b/tools/kvm/kvm-cmd.c @@ -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 index 0000000..e30f74c --- /dev/null +++ b/tools/kvm/kvm-version.c @@ -0,0 +1,15 @@ +#include +#include +#include +#include + +#include +#include +#include + +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 index 0000000..a93c378 --- /dev/null +++ b/tools/kvm/util/KVMTOOLS-VERSION-GEN @@ -0,0 +1,42 @@ +#!/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 +} + +