public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/7] kvm tools: Print version when running 'kvm --version'
@ 2011-08-12 15:20 Sasha Levin
  2011-08-12 15:20 ` [PATCH 2/7] kvm tools: Connect existing command helpers to 'kvm help' Sasha Levin
                   ` (6 more replies)
  0 siblings, 7 replies; 12+ messages in thread
From: Sasha Levin @ 2011-08-12 15:20 UTC (permalink / raw)
  To: penberg; +Cc: kvm, mingo, asias.hejun, gorcunov, Sasha Levin

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/kvm-cmd.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/kvm-cmd.c b/tools/kvm/kvm-cmd.c
index e85f22f..3a90d6d 100644
--- a/tools/kvm/kvm-cmd.c
+++ b/tools/kvm/kvm-cmd.c
@@ -24,6 +24,7 @@ struct cmd_struct kvm_commands[] = {
 	{ "balloon",	kvm_cmd_balloon,	NULL,         0 },
 	{ "list",	kvm_cmd_list,		NULL,         0 },
 	{ "version",	kvm_cmd_version,	NULL,         0 },
+	{ "--version",	kvm_cmd_version,	NULL,         0 },
 	{ "stop",	kvm_cmd_stop,		NULL,         0 },
 	{ "help",	kvm_cmd_help,		NULL,         0 },
 	{ "run",	kvm_cmd_run,		kvm_run_help, 0 },
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/7] kvm tools: Connect existing command helpers to 'kvm help'
  2011-08-12 15:20 [PATCH 1/7] kvm tools: Print version when running 'kvm --version' Sasha Levin
@ 2011-08-12 15:20 ` Sasha Levin
  2011-08-12 15:20 ` [PATCH 3/7] kvm tools: Improve 'kvm stop' parameters Sasha Levin
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Sasha Levin @ 2011-08-12 15:20 UTC (permalink / raw)
  To: penberg; +Cc: kvm, mingo, asias.hejun, gorcunov, Sasha Levin

This patch connects usage helpers to 'kvm help' callbacks, allowing
to see help about a command by doing 'kvm help [command]'.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/builtin-balloon.c             |    7 ++++++-
 tools/kvm/builtin-debug.c               |    7 ++++++-
 tools/kvm/builtin-list.c                |   15 +++++++++++++++
 tools/kvm/builtin-pause.c               |    7 ++++++-
 tools/kvm/builtin-resume.c              |    7 ++++++-
 tools/kvm/builtin-stop.c                |    7 ++++++-
 tools/kvm/include/kvm/builtin-balloon.h |    1 +
 tools/kvm/include/kvm/builtin-debug.h   |    1 +
 tools/kvm/include/kvm/builtin-list.h    |    1 +
 tools/kvm/include/kvm/builtin-pause.h   |    1 +
 tools/kvm/include/kvm/builtin-resume.h  |    1 +
 tools/kvm/include/kvm/builtin-stop.h    |    1 +
 tools/kvm/kvm-cmd.c                     |   22 +++++++++++-----------
 13 files changed, 62 insertions(+), 16 deletions(-)

diff --git a/tools/kvm/builtin-balloon.c b/tools/kvm/builtin-balloon.c
index 907a56a..08795cd 100644
--- a/tools/kvm/builtin-balloon.c
+++ b/tools/kvm/builtin-balloon.c
@@ -17,6 +17,11 @@ static const struct option balloon_options[] = {
 	OPT_END()
 };
 
+void kvm_balloon_help(void)
+{
+	usage_with_options(balloon_usage, balloon_options);
+}
+
 int kvm_cmd_balloon(int argc, const char **argv, const char *prefix)
 {
 	int pid;
@@ -24,7 +29,7 @@ int kvm_cmd_balloon(int argc, const char **argv, const char *prefix)
 	int inflate = 0;
 
 	if (argc != 3)
-		usage_with_options(balloon_usage, balloon_options);
+		kvm_balloon_help();
 
 	pid = kvm__get_pid_by_instance(argv[2]);
 	if (pid < 0)
diff --git a/tools/kvm/builtin-debug.c b/tools/kvm/builtin-debug.c
index adb0b54..444ec51 100644
--- a/tools/kvm/builtin-debug.c
+++ b/tools/kvm/builtin-debug.c
@@ -17,6 +17,11 @@ static const struct option debug_options[] = {
 	OPT_END()
 };
 
+void kvm_debug_help(void)
+{
+	usage_with_options(debug_usage, debug_options);
+}
+
 static int do_debug(const char *name, int pid)
 {
 	return kill(pid, SIGQUIT);
@@ -27,7 +32,7 @@ int kvm_cmd_debug(int argc, const char **argv, const char *prefix)
 	int pid;
 
 	if (argc != 1)
-		usage_with_options(debug_usage, debug_options);
+		kvm_debug_help();
 
 	if (strcmp(argv[0], "all") == 0) {
 		return kvm__enumerate_instances(do_debug);
diff --git a/tools/kvm/builtin-list.c b/tools/kvm/builtin-list.c
index 34cc03b..fcf9bb0 100644
--- a/tools/kvm/builtin-list.c
+++ b/tools/kvm/builtin-list.c
@@ -2,6 +2,7 @@
 #include <kvm/kvm-cmd.h>
 #include <kvm/builtin-list.h>
 #include <kvm/kvm.h>
+#include <kvm/parse-options.h>
 
 #include <stdio.h>
 #include <string.h>
@@ -10,6 +11,20 @@
 
 #define PROCESS_NAME "kvm"
 
+static const char * const list_usage[] = {
+	"kvm list",
+	NULL
+};
+
+static const struct option list_options[] = {
+	OPT_END()
+};
+
+void kvm_list_help(void)
+{
+	usage_with_options(list_usage, list_options);
+}
+
 static int print_guest(const char *name, int pid)
 {
 	char proc_name[PATH_MAX];
diff --git a/tools/kvm/builtin-pause.c b/tools/kvm/builtin-pause.c
index 7ac793c..7a6a6c7 100644
--- a/tools/kvm/builtin-pause.c
+++ b/tools/kvm/builtin-pause.c
@@ -17,6 +17,11 @@ static const struct option pause_options[] = {
 	OPT_END()
 };
 
+void kvm_pause_help(void)
+{
+	usage_with_options(pause_usage, pause_options);
+}
+
 static int do_pause(const char *name, int pid)
 {
 	return kill(pid, SIGUSR2);
@@ -27,7 +32,7 @@ int kvm_cmd_pause(int argc, const char **argv, const char *prefix)
 	int pid;
 
 	if (argc != 1)
-		usage_with_options(pause_usage, pause_options);
+		kvm_pause_help();
 
 	if (strcmp(argv[0], "all") == 0) {
 		return kvm__enumerate_instances(do_pause);
diff --git a/tools/kvm/builtin-resume.c b/tools/kvm/builtin-resume.c
index 3b08d3f..b004f2d 100644
--- a/tools/kvm/builtin-resume.c
+++ b/tools/kvm/builtin-resume.c
@@ -17,6 +17,11 @@ static const struct option resume_options[] = {
 	OPT_END()
 };
 
+void kvm_resume_help(void)
+{
+	usage_with_options(resume_usage, resume_options);
+}
+
 static int do_resume(const char *name, int pid)
 {
 	return kill(pid, SIGKVMRESUME);
@@ -27,7 +32,7 @@ int kvm_cmd_resume(int argc, const char **argv, const char *prefix)
 	int pid;
 
 	if (argc != 1)
-		usage_with_options(resume_usage, resume_options);
+		kvm_resume_help();
 
 	if (strcmp(argv[0], "all") == 0) {
 		return kvm__enumerate_instances(do_resume);
diff --git a/tools/kvm/builtin-stop.c b/tools/kvm/builtin-stop.c
index efbf979..de31132 100644
--- a/tools/kvm/builtin-stop.c
+++ b/tools/kvm/builtin-stop.c
@@ -17,6 +17,11 @@ static const struct option stop_options[] = {
 	OPT_END()
 };
 
+void kvm_stop_help(void)
+{
+	usage_with_options(stop_usage, stop_options);
+}
+
 static int do_stop(const char *name, int pid)
 {
 	return kill(pid, SIGKVMSTOP);
@@ -27,7 +32,7 @@ int kvm_cmd_stop(int argc, const char **argv, const char *prefix)
 	int pid;
 
 	if (argc != 1)
-		usage_with_options(stop_usage, stop_options);
+		kvm_stop_help();
 
 	if (strcmp(argv[0], "all") == 0) {
 		return kvm__enumerate_instances(do_stop);
diff --git a/tools/kvm/include/kvm/builtin-balloon.h b/tools/kvm/include/kvm/builtin-balloon.h
index f5f92b9..85055eb 100644
--- a/tools/kvm/include/kvm/builtin-balloon.h
+++ b/tools/kvm/include/kvm/builtin-balloon.h
@@ -2,5 +2,6 @@
 #define KVM__BALLOON_H
 
 int kvm_cmd_balloon(int argc, const char **argv, const char *prefix);
+void kvm_balloon_help(void);
 
 #endif
diff --git a/tools/kvm/include/kvm/builtin-debug.h b/tools/kvm/include/kvm/builtin-debug.h
index 190cf31..3fc2469 100644
--- a/tools/kvm/include/kvm/builtin-debug.h
+++ b/tools/kvm/include/kvm/builtin-debug.h
@@ -2,5 +2,6 @@
 #define KVM__DEBUG_H
 
 int kvm_cmd_debug(int argc, const char **argv, const char *prefix);
+void kvm_debug_help(void);
 
 #endif
diff --git a/tools/kvm/include/kvm/builtin-list.h b/tools/kvm/include/kvm/builtin-list.h
index eba9cfd..04fca22 100644
--- a/tools/kvm/include/kvm/builtin-list.h
+++ b/tools/kvm/include/kvm/builtin-list.h
@@ -2,5 +2,6 @@
 #define KVM__LIST_H
 
 int kvm_cmd_list(int argc, const char **argv, const char *prefix);
+void kvm_list_help(void);
 
 #endif
diff --git a/tools/kvm/include/kvm/builtin-pause.h b/tools/kvm/include/kvm/builtin-pause.h
index 0f8e96b..540cc8e 100644
--- a/tools/kvm/include/kvm/builtin-pause.h
+++ b/tools/kvm/include/kvm/builtin-pause.h
@@ -2,5 +2,6 @@
 #define KVM__PAUSE_H
 
 int kvm_cmd_pause(int argc, const char **argv, const char *prefix);
+void kvm_pause_help(void);
 
 #endif
diff --git a/tools/kvm/include/kvm/builtin-resume.h b/tools/kvm/include/kvm/builtin-resume.h
index 4a64747..9e6e8d7 100644
--- a/tools/kvm/include/kvm/builtin-resume.h
+++ b/tools/kvm/include/kvm/builtin-resume.h
@@ -2,5 +2,6 @@
 #define KVM__RESUME_H
 
 int kvm_cmd_resume(int argc, const char **argv, const char *prefix);
+void kvm_resume_help(void);
 
 #endif
diff --git a/tools/kvm/include/kvm/builtin-stop.h b/tools/kvm/include/kvm/builtin-stop.h
index 317d34d..7570695 100644
--- a/tools/kvm/include/kvm/builtin-stop.h
+++ b/tools/kvm/include/kvm/builtin-stop.h
@@ -2,5 +2,6 @@
 #define KVM__STOP_H
 
 int kvm_cmd_stop(int argc, const char **argv, const char *prefix);
+void kvm_stop_help(void);
 
 #endif
diff --git a/tools/kvm/kvm-cmd.c b/tools/kvm/kvm-cmd.c
index 3a90d6d..4e3ea22 100644
--- a/tools/kvm/kvm-cmd.c
+++ b/tools/kvm/kvm-cmd.c
@@ -18,17 +18,17 @@
 #include "kvm/util.h"
 
 struct cmd_struct kvm_commands[] = {
-	{ "pause",	kvm_cmd_pause,		NULL,         0 },
-	{ "resume",	kvm_cmd_resume,		NULL,         0 },
-	{ "debug",	kvm_cmd_debug,		NULL,         0 },
-	{ "balloon",	kvm_cmd_balloon,	NULL,         0 },
-	{ "list",	kvm_cmd_list,		NULL,         0 },
-	{ "version",	kvm_cmd_version,	NULL,         0 },
-	{ "--version",	kvm_cmd_version,	NULL,         0 },
-	{ "stop",	kvm_cmd_stop,		NULL,         0 },
-	{ "help",	kvm_cmd_help,		NULL,         0 },
-	{ "run",	kvm_cmd_run,		kvm_run_help, 0 },
-	{ NULL,		NULL,			NULL,         0 },
+	{ "pause",	kvm_cmd_pause,		kvm_pause_help,		0 },
+	{ "resume",	kvm_cmd_resume,		kvm_resume_help,	0 },
+	{ "debug",	kvm_cmd_debug,		kvm_debug_help,		0 },
+	{ "balloon",	kvm_cmd_balloon,	kvm_balloon_help,	0 },
+	{ "list",	kvm_cmd_list,		kvm_list_help,		0 },
+	{ "version",	kvm_cmd_version,	NULL,			0 },
+	{ "--version",	kvm_cmd_version,	NULL,			0 },
+	{ "stop",	kvm_cmd_stop,		kvm_stop_help,		0 },
+	{ "help",	kvm_cmd_help,		NULL,			0 },
+	{ "run",	kvm_cmd_run,		kvm_run_help,		0 },
+	{ NULL,		NULL,			NULL,			0 },
 };
 
 /*
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/7] kvm tools: Improve 'kvm stop' parameters
  2011-08-12 15:20 [PATCH 1/7] kvm tools: Print version when running 'kvm --version' Sasha Levin
  2011-08-12 15:20 ` [PATCH 2/7] kvm tools: Connect existing command helpers to 'kvm help' Sasha Levin
@ 2011-08-12 15:20 ` Sasha Levin
  2011-08-12 15:20 ` [PATCH 4/7] kvm tools: Improve 'kvm resume' parameters Sasha Levin
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Sasha Levin @ 2011-08-12 15:20 UTC (permalink / raw)
  To: penberg; +Cc: kvm, mingo, asias.hejun, gorcunov, Sasha Levin

kvm stop now uses the git option parser to parse parameters.

Added option to stop instance by PID and stop all instances.

Improved usage message.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/builtin-stop.c |   40 ++++++++++++++++++++++++++++++----------
 1 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/tools/kvm/builtin-stop.c b/tools/kvm/builtin-stop.c
index de31132..bfc9510 100644
--- a/tools/kvm/builtin-stop.c
+++ b/tools/kvm/builtin-stop.c
@@ -8,15 +8,33 @@
 #include <string.h>
 #include <signal.h>
 
+static bool all;
+static u64 instance_pid;
+static const char *instance_name;
+
 static const char * const stop_usage[] = {
-	"kvm stop <instance name>",
+	"kvm stop [--all] [-n name] [-p pid]",
 	NULL
 };
 
 static const struct option stop_options[] = {
+	OPT_GROUP("General options:"),
+	OPT_BOOLEAN('a', "all", &all, "Stop all instances"),
+	OPT_STRING('n', "name", &instance_name, "name", "Instance name"),
+	OPT_U64('p', "pid", &instance_pid, "Instance pid"),
 	OPT_END()
 };
 
+static void parse_stop_options(int argc, const char **argv)
+{
+	while (argc != 0) {
+		argc = parse_options(argc, argv, stop_options, stop_usage,
+				PARSE_OPT_STOP_AT_NON_OPTION);
+		if (argc != 0)
+			kvm_stop_help();
+	}
+}
+
 void kvm_stop_help(void)
 {
 	usage_with_options(stop_usage, stop_options);
@@ -29,18 +47,20 @@ static int do_stop(const char *name, int pid)
 
 int kvm_cmd_stop(int argc, const char **argv, const char *prefix)
 {
-	int pid;
+	parse_stop_options(argc, argv);
 
-	if (argc != 1)
+	if (all)
+		return kvm__enumerate_instances(do_stop);
+
+	if (instance_name == NULL &&
+	    instance_pid == 0)
 		kvm_stop_help();
 
-	if (strcmp(argv[0], "all") == 0) {
-		return kvm__enumerate_instances(do_stop);
-	}
+	if (instance_name)
+		instance_pid = kvm__get_pid_by_instance(argv[0]);
 
-	pid = kvm__get_pid_by_instance(argv[0]);
-	if (pid < 0)
-		die("Failed locating instance name");
+	if (instance_pid <= 0)
+		die("Failed locating instance");
 
-	return kill(pid, SIGKVMSTOP);
+	return kill(instance_pid, SIGKVMSTOP);
 }
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/7] kvm tools: Improve 'kvm resume' parameters
  2011-08-12 15:20 [PATCH 1/7] kvm tools: Print version when running 'kvm --version' Sasha Levin
  2011-08-12 15:20 ` [PATCH 2/7] kvm tools: Connect existing command helpers to 'kvm help' Sasha Levin
  2011-08-12 15:20 ` [PATCH 3/7] kvm tools: Improve 'kvm stop' parameters Sasha Levin
@ 2011-08-12 15:20 ` Sasha Levin
  2011-08-12 15:20 ` [PATCH 5/7] kvm tools: Improve 'kvm pause' parameters Sasha Levin
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Sasha Levin @ 2011-08-12 15:20 UTC (permalink / raw)
  To: penberg; +Cc: kvm, mingo, asias.hejun, gorcunov, Sasha Levin

kvm resume now uses the git option parser to parse parameters.

Added option to resume instance by PID and resume all instances.

Improved usage message.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/builtin-resume.c |   48 +++++++++++++++++++++++++++++++------------
 1 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/tools/kvm/builtin-resume.c b/tools/kvm/builtin-resume.c
index b004f2d..e2c88f4 100644
--- a/tools/kvm/builtin-resume.c
+++ b/tools/kvm/builtin-resume.c
@@ -1,22 +1,40 @@
-#include <stdio.h>
-#include <string.h>
-#include <signal.h>
-
 #include <kvm/util.h>
 #include <kvm/kvm-cmd.h>
 #include <kvm/builtin-resume.h>
 #include <kvm/kvm.h>
 #include <kvm/parse-options.h>
 
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+
+static bool all;
+static u64 instance_pid;
+static const char *instance_name;
+
 static const char * const resume_usage[] = {
-	"kvm resume <instance name>",
+	"kvm resume [--all] [-n name] [-p pid]",
 	NULL
 };
 
 static const struct option resume_options[] = {
+	OPT_GROUP("General options:"),
+	OPT_BOOLEAN('a', "all", &all, "Resume all instances"),
+	OPT_STRING('n', "name", &instance_name, "name", "Instance name"),
+	OPT_U64('p', "pid", &instance_pid, "Instance pid"),
 	OPT_END()
 };
 
+static void parse_resume_options(int argc, const char **argv)
+{
+	while (argc != 0) {
+		argc = parse_options(argc, argv, resume_options, resume_usage,
+				PARSE_OPT_STOP_AT_NON_OPTION);
+		if (argc != 0)
+			kvm_resume_help();
+	}
+}
+
 void kvm_resume_help(void)
 {
 	usage_with_options(resume_usage, resume_options);
@@ -29,18 +47,20 @@ static int do_resume(const char *name, int pid)
 
 int kvm_cmd_resume(int argc, const char **argv, const char *prefix)
 {
-	int pid;
+	parse_resume_options(argc, argv);
 
-	if (argc != 1)
+	if (all)
+		return kvm__enumerate_instances(do_resume);
+
+	if (instance_name == NULL &&
+	    instance_pid == 0)
 		kvm_resume_help();
 
-	if (strcmp(argv[0], "all") == 0) {
-		return kvm__enumerate_instances(do_resume);
-	}
+	if (instance_name)
+		instance_pid = kvm__get_pid_by_instance(argv[0]);
 
-	pid = kvm__get_pid_by_instance(argv[0]);
-	if (pid < 0)
-		die("Failed locating instance name");
+	if (instance_pid <= 0)
+		die("Failed locating instance");
 
-	return kill(pid, SIGKVMRESUME);
+	return kill(instance_pid, SIGKVMRESUME);
 }
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 5/7] kvm tools: Improve 'kvm pause' parameters
  2011-08-12 15:20 [PATCH 1/7] kvm tools: Print version when running 'kvm --version' Sasha Levin
                   ` (2 preceding siblings ...)
  2011-08-12 15:20 ` [PATCH 4/7] kvm tools: Improve 'kvm resume' parameters Sasha Levin
@ 2011-08-12 15:20 ` Sasha Levin
  2011-08-12 15:20 ` [PATCH 6/7] kvm tools: Improve 'kvm debug' parameters Sasha Levin
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Sasha Levin @ 2011-08-12 15:20 UTC (permalink / raw)
  To: penberg; +Cc: kvm, mingo, asias.hejun, gorcunov, Sasha Levin

kvm pause now uses the git option parser to parse parameters.

Added option to pause instance by PID and pause all instances.

Improved usage message.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/builtin-pause.c |   48 +++++++++++++++++++++++++++++++-------------
 1 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/tools/kvm/builtin-pause.c b/tools/kvm/builtin-pause.c
index 7a6a6c7..1c3ec44 100644
--- a/tools/kvm/builtin-pause.c
+++ b/tools/kvm/builtin-pause.c
@@ -1,22 +1,40 @@
-#include <stdio.h>
-#include <string.h>
-#include <signal.h>
-
 #include <kvm/util.h>
 #include <kvm/kvm-cmd.h>
 #include <kvm/builtin-pause.h>
 #include <kvm/kvm.h>
 #include <kvm/parse-options.h>
 
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+
+static bool all;
+static u64 instance_pid;
+static const char *instance_name;
+
 static const char * const pause_usage[] = {
-	"kvm pause <instance name>",
+	"kvm pause [--all] [-n name] [-p pid]",
 	NULL
 };
 
 static const struct option pause_options[] = {
+	OPT_GROUP("General options:"),
+	OPT_BOOLEAN('a', "all", &all, "Pause all instances"),
+	OPT_STRING('n', "name", &instance_name, "name", "Instance name"),
+	OPT_U64('p', "pid", &instance_pid, "Instance pid"),
 	OPT_END()
 };
 
+static void parse_pause_options(int argc, const char **argv)
+{
+	while (argc != 0) {
+		argc = parse_options(argc, argv, pause_options, pause_usage,
+				PARSE_OPT_STOP_AT_NON_OPTION);
+		if (argc != 0)
+			kvm_pause_help();
+	}
+}
+
 void kvm_pause_help(void)
 {
 	usage_with_options(pause_usage, pause_options);
@@ -29,18 +47,20 @@ static int do_pause(const char *name, int pid)
 
 int kvm_cmd_pause(int argc, const char **argv, const char *prefix)
 {
-	int pid;
+	parse_pause_options(argc, argv);
 
-	if (argc != 1)
+	if (all)
+		return kvm__enumerate_instances(do_pause);
+
+	if (instance_name == NULL &&
+	    instance_pid == 0)
 		kvm_pause_help();
 
-	if (strcmp(argv[0], "all") == 0) {
-		return kvm__enumerate_instances(do_pause);
-	}
+	if (instance_name)
+		instance_pid = kvm__get_pid_by_instance(argv[0]);
 
-	pid = kvm__get_pid_by_instance(argv[0]);
-	if (pid < 0)
-		die("Failed locating instance name");
+	if (instance_pid <= 0)
+		die("Failed locating instance");
 
-	return kill(pid, SIGUSR2);
+	return kill(instance_pid, SIGUSR2);
 }
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 6/7] kvm tools: Improve 'kvm debug' parameters
  2011-08-12 15:20 [PATCH 1/7] kvm tools: Print version when running 'kvm --version' Sasha Levin
                   ` (3 preceding siblings ...)
  2011-08-12 15:20 ` [PATCH 5/7] kvm tools: Improve 'kvm pause' parameters Sasha Levin
@ 2011-08-12 15:20 ` Sasha Levin
  2011-08-12 15:21 ` [PATCH 7/7] kvm tools: Improve 'kvm balloon' parameters Sasha Levin
  2011-08-12 15:22 ` [PATCH 1/7] kvm tools: Print version when running 'kvm --version' walimis
  6 siblings, 0 replies; 12+ messages in thread
From: Sasha Levin @ 2011-08-12 15:20 UTC (permalink / raw)
  To: penberg; +Cc: kvm, mingo, asias.hejun, gorcunov, Sasha Levin

kvm debug now uses the git option parser to parse parameters.

Added option to debug instance by PID and debug all instances.

Improved usage message.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/builtin-debug.c |   40 ++++++++++++++++++++++++++++++----------
 1 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/tools/kvm/builtin-debug.c b/tools/kvm/builtin-debug.c
index 444ec51..4a59962 100644
--- a/tools/kvm/builtin-debug.c
+++ b/tools/kvm/builtin-debug.c
@@ -8,15 +8,33 @@
 #include <string.h>
 #include <signal.h>
 
+static bool all;
+static u64 instance_pid;
+static const char *instance_name;
+
 static const char * const debug_usage[] = {
-	"kvm debug <instance name>",
+	"kvm debug [--all] [-n name] [-p pid]",
 	NULL
 };
 
 static const struct option debug_options[] = {
+	OPT_GROUP("General options:"),
+	OPT_BOOLEAN('a', "all", &all, "Debug all instances"),
+	OPT_STRING('n', "name", &instance_name, "name", "Instance name"),
+	OPT_U64('p', "pid", &instance_pid, "Instance pid"),
 	OPT_END()
 };
 
+static void parse_debug_options(int argc, const char **argv)
+{
+	while (argc != 0) {
+		argc = parse_options(argc, argv, debug_options, debug_usage,
+				PARSE_OPT_STOP_AT_NON_OPTION);
+		if (argc != 0)
+			kvm_debug_help();
+	}
+}
+
 void kvm_debug_help(void)
 {
 	usage_with_options(debug_usage, debug_options);
@@ -29,18 +47,20 @@ static int do_debug(const char *name, int pid)
 
 int kvm_cmd_debug(int argc, const char **argv, const char *prefix)
 {
-	int pid;
+	parse_debug_options(argc, argv);
 
-	if (argc != 1)
+	if (all)
+		return kvm__enumerate_instances(do_debug);
+
+	if (instance_name == NULL &&
+	    instance_pid == 0)
 		kvm_debug_help();
 
-	if (strcmp(argv[0], "all") == 0) {
-		return kvm__enumerate_instances(do_debug);
-	}
+	if (instance_name)
+		instance_pid = kvm__get_pid_by_instance(argv[0]);
 
-	pid = kvm__get_pid_by_instance(argv[0]);
-	if (pid < 0)
-		die("Failed locating instance name");
+	if (instance_pid <= 0)
+		die("Failed locating instance");
 
-	return kill(pid, SIGQUIT);
+	return kill(instance_pid, SIGQUIT);
 }
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 7/7] kvm tools: Improve 'kvm balloon' parameters
  2011-08-12 15:20 [PATCH 1/7] kvm tools: Print version when running 'kvm --version' Sasha Levin
                   ` (4 preceding siblings ...)
  2011-08-12 15:20 ` [PATCH 6/7] kvm tools: Improve 'kvm debug' parameters Sasha Levin
@ 2011-08-12 15:21 ` Sasha Levin
  2011-08-12 15:22 ` [PATCH 1/7] kvm tools: Print version when running 'kvm --version' walimis
  6 siblings, 0 replies; 12+ messages in thread
From: Sasha Levin @ 2011-08-12 15:21 UTC (permalink / raw)
  To: penberg; +Cc: kvm, mingo, asias.hejun, gorcunov, Sasha Levin

kvm balloon now uses the git option parser to parse parameters.

Added option to balloon instance by PID.

Improved usage message.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/builtin-balloon.c |   61 ++++++++++++++++++++++++++++++++----------
 1 files changed, 46 insertions(+), 15 deletions(-)

diff --git a/tools/kvm/builtin-balloon.c b/tools/kvm/builtin-balloon.c
index 08795cd..5dfd2e4 100644
--- a/tools/kvm/builtin-balloon.c
+++ b/tools/kvm/builtin-balloon.c
@@ -8,13 +8,29 @@
 #include <kvm/parse-options.h>
 #include <kvm/kvm.h>
 
+static u64 instance_pid;
+static const char *instance_name;
+static u64 inflate;
+static u64 deflate;
+
 static const char * const balloon_usage[] = {
 	"kvm balloon {inflate|deflate} <size in MiB> <instance name>",
 	NULL
 };
 
+static const char * const debug_usage[] = {
+	"kvm balloon [-n name] [-p pid] [-i amount] [-d amount]",
+	NULL
+};
+
 static const struct option balloon_options[] = {
-	OPT_END()
+	OPT_GROUP("Instance options:"),
+	OPT_STRING('n', "name", &instance_name, "name", "Instance name"),
+	OPT_U64('p', "pid", &instance_pid, "Instance pid"),
+	OPT_GROUP("Balloon options:"),
+	OPT_U64('i', "inflate", &inflate, "Amount to inflate"),
+	OPT_U64('d', "deflate", &deflate, "Amount to deflate"),
+	OPT_END(),
 };
 
 void kvm_balloon_help(void)
@@ -22,28 +38,43 @@ void kvm_balloon_help(void)
 	usage_with_options(balloon_usage, balloon_options);
 }
 
+static void parse_balloon_options(int argc, const char **argv)
+{
+	while (argc != 0) {
+		argc = parse_options(argc, argv, balloon_options, balloon_usage,
+				PARSE_OPT_STOP_AT_NON_OPTION);
+		if (argc != 0)
+			kvm_balloon_help();
+	}
+}
+
 int kvm_cmd_balloon(int argc, const char **argv, const char *prefix)
 {
-	int pid;
-	int amount, i;
-	int inflate = 0;
+	u64 i;
+
+	parse_balloon_options(argc, argv);
 
-	if (argc != 3)
+	if (inflate == 0 && deflate == 0)
 		kvm_balloon_help();
 
-	pid = kvm__get_pid_by_instance(argv[2]);
-	if (pid < 0)
-		die("Failed locating instance name");
+	if (instance_name == NULL &&
+	    instance_pid == 0)
+		kvm_balloon_help();
 
-	if (strcmp(argv[0], "inflate") == 0)
-		inflate = 1;
-	else if (strcmp(argv[0], "deflate"))
-		die("command can be either 'inflate' or 'deflate'");
+	if (instance_name)
+		instance_pid = kvm__get_pid_by_instance(argv[0]);
 
-	amount = atoi(argv[1]);
+	if (instance_pid <= 0)
+		die("Failed locating instance");
 
-	for (i = 0; i < amount; i++)
-		kill(pid, inflate ? SIGKVMADDMEM : SIGKVMDELMEM);
+	if (inflate)
+		for (i = 0; i < inflate; i++)
+			kill(instance_pid, SIGKVMADDMEM);
+	else if (deflate)
+		for (i = 0; i < deflate; i++)
+			kill(instance_pid, SIGKVMDELMEM);
+	else
+		kvm_balloon_help();
 
 	return 0;
 }
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/7] kvm tools: Print version when running 'kvm --version'
  2011-08-12 15:20 [PATCH 1/7] kvm tools: Print version when running 'kvm --version' Sasha Levin
                   ` (5 preceding siblings ...)
  2011-08-12 15:21 ` [PATCH 7/7] kvm tools: Improve 'kvm balloon' parameters Sasha Levin
@ 2011-08-12 15:22 ` walimis
  2011-08-12 15:39   ` Pekka Enberg
  2011-08-12 15:47   ` Sasha Levin
  6 siblings, 2 replies; 12+ messages in thread
From: walimis @ 2011-08-12 15:22 UTC (permalink / raw)
  To: Sasha Levin; +Cc: penberg, kvm, mingo, asias.hejun, gorcunov

On Fri, Aug 12, 2011 at 06:20:54PM +0300, Sasha Levin wrote:
>Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
>---
> tools/kvm/kvm-cmd.c |    1 +
> 1 files changed, 1 insertions(+), 0 deletions(-)
>
>diff --git a/tools/kvm/kvm-cmd.c b/tools/kvm/kvm-cmd.c
>index e85f22f..3a90d6d 100644
>--- a/tools/kvm/kvm-cmd.c
>+++ b/tools/kvm/kvm-cmd.c
>@@ -24,6 +24,7 @@ struct cmd_struct kvm_commands[] = {
> 	{ "balloon",	kvm_cmd_balloon,	NULL,         0 },
> 	{ "list",	kvm_cmd_list,		NULL,         0 },
> 	{ "version",	kvm_cmd_version,	NULL,         0 },
>+	{ "--version",	kvm_cmd_version,	NULL,         0 },
Although it works, I think it's not good way to implement a option
as a command.

walimis
> 	{ "stop",	kvm_cmd_stop,		NULL,         0 },
> 	{ "help",	kvm_cmd_help,		NULL,         0 },
> 	{ "run",	kvm_cmd_run,		kvm_run_help, 0 },
>-- 
>1.7.6
>
>--
>To unsubscribe from this list: send the line "unsubscribe kvm" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/7] kvm tools: Print version when running 'kvm --version'
  2011-08-12 15:22 ` [PATCH 1/7] kvm tools: Print version when running 'kvm --version' walimis
@ 2011-08-12 15:39   ` Pekka Enberg
  2011-08-12 15:43     ` walimis
  2011-08-12 15:47   ` Sasha Levin
  1 sibling, 1 reply; 12+ messages in thread
From: Pekka Enberg @ 2011-08-12 15:39 UTC (permalink / raw)
  To: walimis; +Cc: Sasha Levin, kvm, mingo, asias.hejun, gorcunov

On Fri, 12 Aug 2011, walimis wrote:
>> @@ -24,6 +24,7 @@ struct cmd_struct kvm_commands[] = {
>> 	{ "balloon",	kvm_cmd_balloon,	NULL,         0 },
>> 	{ "list",	kvm_cmd_list,		NULL,         0 },
>> 	{ "version",	kvm_cmd_version,	NULL,         0 },
>> +	{ "--version",	kvm_cmd_version,	NULL,         0 },
> Although it works, I think it's not good way to implement a option
> as a command.

Well, I already merged the patch because the whole series was so 
super-cool. What downsides are there to implementing the alias like this?

 			Pekka

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/7] kvm tools: Print version when running 'kvm --version'
  2011-08-12 15:39   ` Pekka Enberg
@ 2011-08-12 15:43     ` walimis
  0 siblings, 0 replies; 12+ messages in thread
From: walimis @ 2011-08-12 15:43 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Sasha Levin, kvm, mingo, asias.hejun, gorcunov

On Fri, Aug 12, 2011 at 06:39:46PM +0300, Pekka Enberg wrote:
>On Fri, 12 Aug 2011, walimis wrote:
>>>@@ -24,6 +24,7 @@ struct cmd_struct kvm_commands[] = {
>>>	{ "balloon",	kvm_cmd_balloon,	NULL,         0 },
>>>	{ "list",	kvm_cmd_list,		NULL,         0 },
>>>	{ "version",	kvm_cmd_version,	NULL,         0 },
>>>+	{ "--version",	kvm_cmd_version,	NULL,         0 },
>>Although it works, I think it's not good way to implement a option
>>as a command.
>
>Well, I already merged the patch because the whole series was so
>super-cool. What downsides are there to implementing the alias like
>this?
no downsides, I just consider that a option is preceded 
with "--", but the struct cmd_struct is to describe a command.

walimis
>
>			Pekka

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/7] kvm tools: Print version when running 'kvm --version'
  2011-08-12 15:47   ` Sasha Levin
@ 2011-08-12 15:45     ` walimis
  0 siblings, 0 replies; 12+ messages in thread
From: walimis @ 2011-08-12 15:45 UTC (permalink / raw)
  To: Sasha Levin; +Cc: penberg, kvm, mingo, asias.hejun, gorcunov

On Fri, Aug 12, 2011 at 06:47:19PM +0300, Sasha Levin wrote:
>On Fri, 2011-08-12 at 23:22 +0800, walimis wrote:
>> On Fri, Aug 12, 2011 at 06:20:54PM +0300, Sasha Levin wrote:
>> >Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
>> >---
>> > tools/kvm/kvm-cmd.c |    1 +
>> > 1 files changed, 1 insertions(+), 0 deletions(-)
>> >
>> >diff --git a/tools/kvm/kvm-cmd.c b/tools/kvm/kvm-cmd.c
>> >index e85f22f..3a90d6d 100644
>> >--- a/tools/kvm/kvm-cmd.c
>> >+++ b/tools/kvm/kvm-cmd.c
>> >@@ -24,6 +24,7 @@ struct cmd_struct kvm_commands[] = {
>> > 	{ "balloon",	kvm_cmd_balloon,	NULL,         0 },
>> > 	{ "list",	kvm_cmd_list,		NULL,         0 },
>> > 	{ "version",	kvm_cmd_version,	NULL,         0 },
>> >+	{ "--version",	kvm_cmd_version,	NULL,         0 },
>> Although it works, I think it's not good way to implement a option
>> as a command.
>
>Since kvm tools isn't going to support options to 'kvm' itself, I
>believe that even though it looks somewhat hacky, it's the simplest and
>most correct solution.
>
>If we were going to add more parameters besides '--version' then yes,
>let's write a better interface.
>
>Perf for example allow '--version' by doing a strcmp() before command
>parsing, which is equally not that nice :)
OK, I get it.
Thanks.

walimis

>
>-- 
>
>Sasha.
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/7] kvm tools: Print version when running 'kvm --version'
  2011-08-12 15:22 ` [PATCH 1/7] kvm tools: Print version when running 'kvm --version' walimis
  2011-08-12 15:39   ` Pekka Enberg
@ 2011-08-12 15:47   ` Sasha Levin
  2011-08-12 15:45     ` walimis
  1 sibling, 1 reply; 12+ messages in thread
From: Sasha Levin @ 2011-08-12 15:47 UTC (permalink / raw)
  To: walimis; +Cc: penberg, kvm, mingo, asias.hejun, gorcunov

On Fri, 2011-08-12 at 23:22 +0800, walimis wrote:
> On Fri, Aug 12, 2011 at 06:20:54PM +0300, Sasha Levin wrote:
> >Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> >---
> > tools/kvm/kvm-cmd.c |    1 +
> > 1 files changed, 1 insertions(+), 0 deletions(-)
> >
> >diff --git a/tools/kvm/kvm-cmd.c b/tools/kvm/kvm-cmd.c
> >index e85f22f..3a90d6d 100644
> >--- a/tools/kvm/kvm-cmd.c
> >+++ b/tools/kvm/kvm-cmd.c
> >@@ -24,6 +24,7 @@ struct cmd_struct kvm_commands[] = {
> > 	{ "balloon",	kvm_cmd_balloon,	NULL,         0 },
> > 	{ "list",	kvm_cmd_list,		NULL,         0 },
> > 	{ "version",	kvm_cmd_version,	NULL,         0 },
> >+	{ "--version",	kvm_cmd_version,	NULL,         0 },
> Although it works, I think it's not good way to implement a option
> as a command.

Since kvm tools isn't going to support options to 'kvm' itself, I
believe that even though it looks somewhat hacky, it's the simplest and
most correct solution.

If we were going to add more parameters besides '--version' then yes,
let's write a better interface.

Perf for example allow '--version' by doing a strcmp() before command
parsing, which is equally not that nice :)

-- 

Sasha.


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2011-08-12 16:01 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-12 15:20 [PATCH 1/7] kvm tools: Print version when running 'kvm --version' Sasha Levin
2011-08-12 15:20 ` [PATCH 2/7] kvm tools: Connect existing command helpers to 'kvm help' Sasha Levin
2011-08-12 15:20 ` [PATCH 3/7] kvm tools: Improve 'kvm stop' parameters Sasha Levin
2011-08-12 15:20 ` [PATCH 4/7] kvm tools: Improve 'kvm resume' parameters Sasha Levin
2011-08-12 15:20 ` [PATCH 5/7] kvm tools: Improve 'kvm pause' parameters Sasha Levin
2011-08-12 15:20 ` [PATCH 6/7] kvm tools: Improve 'kvm debug' parameters Sasha Levin
2011-08-12 15:21 ` [PATCH 7/7] kvm tools: Improve 'kvm balloon' parameters Sasha Levin
2011-08-12 15:22 ` [PATCH 1/7] kvm tools: Print version when running 'kvm --version' walimis
2011-08-12 15:39   ` Pekka Enberg
2011-08-12 15:43     ` walimis
2011-08-12 15:47   ` Sasha Levin
2011-08-12 15:45     ` walimis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox