Skip to contentSkip to conversation

kvm tools: Add 'kvm version' command

PATCH In review Sasha Levin 2 participants 9 messages Jul 8, 2011 – Jul 9, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 kvm tools: Add 'kvm version' command

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.

---
 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
tools/kvm/Documentation/kvm-version.txt new file +21 -0
new file mode 100644
index 0000000..bf51540
@@ -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.
tools/kvm/Makefile +7 -0
index 51a3d1a..5ec222f 100644
@@ -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 $@
tools/kvm/command-list.txt +1 -0
index 36dcd67b..81ba140 100644
@@ -4,3 +4,4 @@
 #
 kvm-run				mainporcelain common
 kvm-pause			common
+kvm-version			common
tools/kvm/include/kvm/kvm-version.h new file +6 -0
new file mode 100644
index 0000000..83cac4d
@@ -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
tools/kvm/kvm-cmd.c +2 -0
index cecf0d0..404065b 100644
@@ -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 },
tools/kvm/kvm-version.c new file +15 -0
new file mode 100644
index 0000000..e30f74c
@@ -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;
+}
tools/kvm/util/KVMTOOLS-VERSION-GEN new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
1.7.6
#1 lore raw

PATCH 2/7 kvm tools: Properly add 'kvm list' to command list

Also adds some basic documentation.

---
 tools/kvm/Documentation/kvm-list.txt |   16 ++++++++++++++++
 tools/kvm/command-list.txt           |    1 +
 2 files changed, 17 insertions(+), 0 deletions(-)
 create mode 100644 tools/kvm/Documentation/kvm-list.txt
tools/kvm/Documentation/kvm-list.txt new file +16 -0
new file mode 100644
index 0000000..121e45c
@@ -0,0 +1,16 @@
+kvm-list(1)
+================
+
+NAME
+----
+kvm-list - Print a list of running instances on the host.
+
+SYNOPSIS
+--------
+[verse]
+'kvm list'
+
+DESCRIPTION
+-----------
+This command prints a list of running instances on the host which
+belong to the user who currently ran 'kvm list'.
tools/kvm/command-list.txt +1 -0
index 81ba140..32bb518 100644
@@ -5,3 +5,4 @@
 kvm-run				mainporcelain common
 kvm-pause			common
 kvm-version			common
+kvm-list			common
Signature · 1 line
1.7.6
#2 lore raw

PATCH 3/7 kvm tools: Properly add 'kvm debug' to command list

In reply to Sasha Levin

Also adds some basic documentation.

---
 tools/kvm/Documentation/kvm-debug.txt |   16 ++++++++++++++++
 tools/kvm/command-list.txt            |    1 +
 2 files changed, 17 insertions(+), 0 deletions(-)
 create mode 100644 tools/kvm/Documentation/kvm-debug.txt
tools/kvm/Documentation/kvm-debug.txt new file +16 -0
new file mode 100644
index 0000000..b1c0e3d
@@ -0,0 +1,16 @@
+kvm-debug(1)
+================
+
+NAME
+----
+kvm-debug - Print debug information from a running instance
+
+SYNOPSIS
+--------
+[verse]
+'kvm debug [instance]'
+
+DESCRIPTION
+-----------
+The command prints debug information from a running instance.
+For a list of running instances see 'kvm list'.
tools/kvm/command-list.txt +1 -0
index 32bb518..12ef4b8 100644
@@ -6,3 +6,4 @@ kvm-run				mainporcelain common
 kvm-pause			common
 kvm-version			common
 kvm-list			common
+kvm-debug			common
Signature · 1 line
1.7.6
#3 lore raw

PATCH 4/7 kvm tools: Update 'kvm pause' documentation

In reply to Sasha Levin
---
 tools/kvm/Documentation/kvm-pause.txt |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
tools/kvm/Documentation/kvm-pause.txt +2 -1
index ddf3d8f..773824f 100644
@@ -8,8 +8,9 @@ kvm-pause - Pause/resume the virtual machine
 SYNOPSIS
 --------
 [verse]
-'kvm pause'
+'kvm pause [instance]'
 
 DESCRIPTION
 -----------
 The command pauses and resumes a virtual machine.
+For a list of running instances see 'kvm list'.
Signature · 1 line
1.7.6
#4 lore raw

PATCH 5/7 kvm tools: Properly add 'kvm balloon' to command list

In reply to Sasha Levin

Also adds some documentation.

---
 tools/kvm/Documentation/kvm-balloon.txt |   24 ++++++++++++++++++++++++
 tools/kvm/command-list.txt              |    1 +
 2 files changed, 25 insertions(+), 0 deletions(-)
 create mode 100644 tools/kvm/Documentation/kvm-balloon.txt
tools/kvm/Documentation/kvm-balloon.txt new file +24 -0
new file mode 100644
index 0000000..5ba68d6
@@ -0,0 +1,24 @@
+kvm-balloon(1)
+================
+
+NAME
+----
+kvm-balloon - Inflate or deflate the virtio balloon
+
+SYNOPSIS
+--------
+[verse]
+'kvm balloon [instance] [command] [size]'
+
+DESCRIPTION
+-----------
+The command inflates or deflates the virtio balloon located in the
+specified instance.
+For a list of running instances see 'kvm list'.
+
+Command can be either 'inflate' or 'deflate'. Inflate increases the
+size of the balloon, thus decreasing the amount of virtual RAM available
+for the guest. Deflation returns previously inflated memory back to the
+guest.
+
+size is specified in Mb.
tools/kvm/command-list.txt +1 -0
index 12ef4b8..037a8ea 100644
@@ -7,3 +7,4 @@ kvm-pause			common
 kvm-version			common
 kvm-list			common
 kvm-debug			common
+kvm-balloon			common
Signature · 1 line
1.7.6
#5 lore raw

PATCH 6/7 kvm tools: Rename command source files

In reply to Sasha Levin

Rename kvm-[command] into builtin-[command] to prevent clashes with non-command files such as kvm-cpu.h

---
 tools/kvm/Makefile                                 |   14 +++++++-------
 tools/kvm/{kvm-balloon.c => builtin-balloon.c}     |    2 +-
 tools/kvm/{kvm-debug.c => builtin-debug.c}         |    2 +-
 tools/kvm/{kvm-help.c => builtin-help.c}           |    2 +-
 tools/kvm/{kvm-list.c => builtin-list.c}           |    2 +-
 tools/kvm/{kvm-pause.c => builtin-pause.c}         |    2 +-
 tools/kvm/{kvm-run.c => builtin-run.c}             |    0
 tools/kvm/{kvm-version.c => builtin-version.c}     |    2 +-
 .../kvm/{kvm-balloon.h => builtin-balloon.h}       |    0
 .../include/kvm/{kvm-debug.h => builtin-debug.h}   |    0
 .../kvm/include/kvm/{kvm-help.h => builtin-help.h} |    0
 .../kvm/include/kvm/{kvm-list.h => builtin-list.h} |    0
 .../include/kvm/{kvm-pause.h => builtin-pause.h}   |    0
 tools/kvm/include/kvm/{kvm-run.h => builtin-run.h} |    0
 .../kvm/{kvm-version.h => builtin-version.h}       |    0
 tools/kvm/kvm-cmd.c                                |   14 +++++++-------
 16 files changed, 20 insertions(+), 20 deletions(-)
 rename tools/kvm/{kvm-balloon.c => builtin-balloon.c} (95%)
 rename tools/kvm/{kvm-debug.c => builtin-debug.c} (94%)
 rename tools/kvm/{kvm-help.c => builtin-help.c} (97%)
 rename tools/kvm/{kvm-list.c => builtin-list.c} (96%)
 rename tools/kvm/{kvm-pause.c => builtin-pause.c} (94%)
 rename tools/kvm/{kvm-run.c => builtin-run.c} (100%)
 rename tools/kvm/{kvm-version.c => builtin-version.c} (88%)
 rename tools/kvm/include/kvm/{kvm-balloon.h => builtin-balloon.h} (100%)
 rename tools/kvm/include/kvm/{kvm-debug.h => builtin-debug.h} (100%)
 rename tools/kvm/include/kvm/{kvm-help.h => builtin-help.h} (100%)
 rename tools/kvm/include/kvm/{kvm-list.h => builtin-list.h} (100%)
 rename tools/kvm/include/kvm/{kvm-pause.h => builtin-pause.h} (100%)
 rename tools/kvm/include/kvm/{kvm-run.h => builtin-run.h} (100%)
 rename tools/kvm/include/kvm/{kvm-version.h => builtin-version.h} (100%)
tools/kvm/Makefile +7 -7
index 5ec222f..4b71620 100644
@@ -20,6 +20,13 @@ TAGS	:= ctags
 
 PROGRAM	:= kvm
 
+OBJS	+= builtin-balloon.o
+OBJS	+= builtin-debug.o
+OBJS	+= builtin-help.o
+OBJS	+= builtin-list.o
+OBJS	+= builtin-pause.o
+OBJS	+= builtin-run.o
+OBJS	+= builtin-version.o
 OBJS	+= cpuid.o
 OBJS	+= disk/core.o
 OBJS	+= framebuffer.o
@@ -55,13 +62,6 @@ OBJS	+= uip/udp.o
 OBJS	+= uip/buf.o
 OBJS	+= uip/csum.o
 OBJS	+= kvm-cmd.o
-OBJS	+= kvm-debug.o
-OBJS	+= kvm-help.o
-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
tools/kvm/builtin-balloon.c renamed from tools/kvm/kvm-balloon.c +1 -1
similarity index 95%
rename from tools/kvm/kvm-balloon.c
rename to tools/kvm/builtin-balloon.c
index 277cada..319941d 100644
@@ -4,7 +4,7 @@
 
 #include <kvm/util.h>
 #include <kvm/kvm-cmd.h>
-#include <kvm/kvm-balloon.h>
+#include <kvm/builtin-balloon.h>
 #include <kvm/kvm.h>
 
 int kvm_cmd_balloon(int argc, const char **argv, const char *prefix)
tools/kvm/builtin-debug.c renamed from tools/kvm/kvm-debug.c +1 -1
similarity index 94%
rename from tools/kvm/kvm-debug.c
rename to tools/kvm/builtin-debug.c
index 676f311..153badd 100644
@@ -1,6 +1,6 @@
 #include <kvm/util.h>
 #include <kvm/kvm-cmd.h>
-#include <kvm/kvm-debug.h>
+#include <kvm/builtin-debug.h>
 #include <kvm/kvm.h>
 
 #include <stdio.h>
tools/kvm/builtin-help.c renamed from tools/kvm/kvm-help.c +1 -1
similarity index 97%
rename from tools/kvm/kvm-help.c
rename to tools/kvm/builtin-help.c
index 817e4f8..e89cd5c 100644
@@ -6,7 +6,7 @@
 
 #include <kvm/util.h>
 #include <kvm/kvm-cmd.h>
-#include <kvm/kvm-help.h>
+#include <kvm/builtin-help.h>
 
 
 const char kvm_usage_string[] =
tools/kvm/builtin-list.c renamed from tools/kvm/kvm-list.c +1 -1
similarity index 96%
rename from tools/kvm/kvm-list.c
rename to tools/kvm/builtin-list.c
index 40c0e48..dde3fb3 100644
@@ -1,6 +1,6 @@
 #include <kvm/util.h>
 #include <kvm/kvm-cmd.h>
-#include <kvm/kvm-list.h>
+#include <kvm/builtin-list.h>
 #include <kvm/kvm.h>
 
 #include <stdio.h>
tools/kvm/builtin-pause.c renamed from tools/kvm/kvm-pause.c +1 -1
similarity index 94%
rename from tools/kvm/kvm-pause.c
rename to tools/kvm/builtin-pause.c
index ea4f95d..0c0010d 100644
@@ -4,7 +4,7 @@
 
 #include <kvm/util.h>
 #include <kvm/kvm-cmd.h>
-#include <kvm/kvm-pause.h>
+#include <kvm/builtin-pause.h>
 #include <kvm/kvm.h>
 
 static void do_pause(const char *name, int pid)
tools/kvm/builtin-run.c renamed from tools/kvm/kvm-run.c +0 -0
similarity index 100%
rename from tools/kvm/kvm-run.c
rename to tools/kvm/builtin-run.c
tools/kvm/builtin-version.c renamed from tools/kvm/kvm-version.c +1 -1
similarity index 88%
rename from tools/kvm/kvm-version.c
rename to tools/kvm/builtin-version.c
index e30f74c..5b3b598 100644
@@ -1,6 +1,6 @@
 #include <kvm/util.h>
 #include <kvm/kvm-cmd.h>
-#include <kvm/kvm-version.h>
+#include <kvm/builtin-version.h>
 #include <kvm/kvm.h>
 
 #include <stdio.h>
tools/kvm/include/kvm/builtin-balloon.h renamed from tools/kvm/include/kvm/kvm-balloon.h +0 -0
similarity index 100%
rename from tools/kvm/include/kvm/kvm-balloon.h
rename to tools/kvm/include/kvm/builtin-balloon.h
tools/kvm/include/kvm/builtin-debug.h renamed from tools/kvm/include/kvm/kvm-debug.h +0 -0
similarity index 100%
rename from tools/kvm/include/kvm/kvm-debug.h
rename to tools/kvm/include/kvm/builtin-debug.h
tools/kvm/include/kvm/builtin-help.h renamed from tools/kvm/include/kvm/kvm-help.h +0 -0
similarity index 100%
rename from tools/kvm/include/kvm/kvm-help.h
rename to tools/kvm/include/kvm/builtin-help.h
tools/kvm/include/kvm/builtin-list.h renamed from tools/kvm/include/kvm/kvm-list.h +0 -0
similarity index 100%
rename from tools/kvm/include/kvm/kvm-list.h
rename to tools/kvm/include/kvm/builtin-list.h
tools/kvm/include/kvm/builtin-pause.h renamed from tools/kvm/include/kvm/kvm-pause.h +0 -0
similarity index 100%
rename from tools/kvm/include/kvm/kvm-pause.h
rename to tools/kvm/include/kvm/builtin-pause.h
tools/kvm/include/kvm/builtin-run.h renamed from tools/kvm/include/kvm/kvm-run.h +0 -0
similarity index 100%
rename from tools/kvm/include/kvm/kvm-run.h
rename to tools/kvm/include/kvm/builtin-run.h
tools/kvm/include/kvm/builtin-version.h renamed from tools/kvm/include/kvm/kvm-version.h +0 -0
similarity index 100%
rename from tools/kvm/include/kvm/kvm-version.h
rename to tools/kvm/include/kvm/builtin-version.h
tools/kvm/kvm-cmd.c +7 -7
index 404065b..a954a61 100644
@@ -5,14 +5,14 @@
 #include <assert.h>
 
 /* user defined header files */
-#include "kvm/kvm-debug.h"
-#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/builtin-debug.h"
+#include "kvm/builtin-pause.h"
+#include "kvm/builtin-balloon.h"
+#include "kvm/builtin-list.h"
+#include "kvm/builtin-version.h"
+#include "kvm/builtin-help.h"
 #include "kvm/kvm-cmd.h"
-#include "kvm/kvm-run.h"
+#include "kvm/builtin-run.h"
 
 struct cmd_struct kvm_commands[] = {
 	{ "pause",	kvm_cmd_pause,		NULL,         0 },
Signature · 1 line
1.7.6
#6 lore raw

Re: [PATCH 6/7] kvm tools: Rename command source files

Quoted 5 lines · Sasha Levin

Rename kvm-[command] into builtin-[command] to prevent clashes with non-command files such as kvm-cpu.h

I see this when I apply your patch:

penberg@tiger:~/linux/tools/kvm$ make
builtin-help.c:5:25: error: common-cmds.h: No such file or directory
KVMTOOLS_VERSION = 3.0.rc5.683.g44315f
builtin-help.c:5:25: error: common-cmds.h: No such file or directory
make: *** No rule to make target `builtin-help.d', needed by `kvm'.  Stop.
#7 lore raw

Re: [PATCH 6/7] kvm tools: Rename command source files

Quoted 7 lines · Pekka Enberg
Quoted 5 lines · Sasha Levin

Rename kvm-[command] into builtin-[command] to prevent clashes with non-command files such as kvm-cpu.h

Quoted 8 lines

I see this when I apply your patch:

penberg@tiger:~/linux/tools/kvm$ make
builtin-help.c:5:25: error: common-cmds.h: No such file or directory
KVMTOOLS_VERSION = 3.0.rc5.683.g44315f
builtin-help.c:5:25: error: common-cmds.h: No such file or directory
make: *** No rule to make target `builtin-help.d', needed by `kvm'.  Stop.

Looks like I had old .o files which made the build work. I'll resend this patch.

Signature · 1 line
Sasha.
#8 lore raw

PATCH 7/7 kvm tools: Rename debug options under 'kvm run'

In reply to Sasha Levin

Rename debug options to make them consistent with eachother.

---
 tools/kvm/builtin-run.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
tools/kvm/builtin-run.c +3 -3
index 048b6a2..8b7d08b 100644
@@ -37,7 +37,7 @@
 #include <kvm/framebuffer.h>
 
 /* header files for gitish interface  */
-#include <kvm/kvm-run.h>
+#include <kvm/builtin-run.h>
 #include <kvm/parse-options.h>
 #include <kvm/mutex.h>
 
@@ -178,9 +178,9 @@ static const struct option options[] = {
 			"Enable debug messages"),
 	OPT_BOOLEAN('\0', "debug-single-step", &single_step,
 			"Enable single stepping"),
-	OPT_BOOLEAN('\0', "debug-ioport-debug", &ioport_debug,
+	OPT_BOOLEAN('\0', "debug-ioport", &ioport_debug,
 			"Enable ioport debugging"),
-	OPT_INTEGER('\0', "debug_iodelay", &debug_iodelay,
+	OPT_INTEGER('\0', "debug-iodelay", &debug_iodelay,
 			"Delay IO by millisecond"),
 	OPT_END()
 };
Signature · 1 line
1.7.6