From: Sasha Levin <levinsasha928@gmail.com>
To: penberg@kernel.org
Cc: kvm@vger.kernel.org, mingo@elte.hu, asias.hejun@gmail.com,
gorcunov@gmail.com, Sasha Levin <levinsasha928@gmail.com>
Subject: [PATCH 4/7] kvm tools: Improve 'kvm resume' parameters
Date: Fri, 12 Aug 2011 18:20:57 +0300 [thread overview]
Message-ID: <1313162460-14397-4-git-send-email-levinsasha928@gmail.com> (raw)
In-Reply-To: <1313162460-14397-1-git-send-email-levinsasha928@gmail.com>
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
next prev parent reply other threads:[~2011-08-12 15:22 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1313162460-14397-4-git-send-email-levinsasha928@gmail.com \
--to=levinsasha928@gmail.com \
--cc=asias.hejun@gmail.com \
--cc=gorcunov@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=penberg@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox