From: Pekka Enberg <penberg@kernel.org>
To: kvm@vger.kernel.org
Cc: Pekka Enberg <penberg@kernel.org>,
Asias He <asias.hejun@gmail.com>,
Cyrill Gorcunov <gorcunov@gmail.com>, Ingo Molnar <mingo@elte.hu>
Subject: [PATCH] kvm tools: Use host kernel image by default
Date: Tue, 12 Apr 2011 20:51:29 +0300 [thread overview]
Message-ID: <1302630689-13498-1-git-send-email-penberg@kernel.org> (raw)
If user doesn't specify a kernel image for 'kvm run' command, try to look up
host kernel kernel image from /boot directory and use it as guest kernel.
Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
tools/kvm/kvm-run.c | 40 +++++++++++++++++++++++++++++++++-------
1 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
index ba02172..4986d6c 100644
--- a/tools/kvm/kvm-run.c
+++ b/tools/kvm/kvm-run.c
@@ -6,6 +6,9 @@
#include <inttypes.h>
#include <stdlib.h>
#include <termios.h>
+#include <sys/utsname.h>
+#include <sys/types.h>
+#include <sys/stat.h>
/* user defined header files */
#include <linux/types.h>
@@ -68,7 +71,7 @@ extern int active_console;
static int nrcpus = 1;
static const char * const run_usage[] = {
- "kvm run [<options>] <kernel image>",
+ "kvm run [<options>] [<kernel image>]",
NULL
};
@@ -122,6 +125,28 @@ panic_kvm:
return (void *) (intptr_t) 1;
}
+static char host_kernel[PATH_MAX];
+
+static const char *find_host_kernel(void)
+{
+ struct utsname uts;
+ struct stat st;
+
+ if (uname(&uts) < 0)
+ return NULL;
+
+ if (snprintf(host_kernel, PATH_MAX, "/boot/vmlinuz-%s", uts.release) < 0)
+ return NULL;
+
+ if (stat(host_kernel, &st) < 0)
+ return NULL;
+
+ if (!S_ISREG(st.st_mode))
+ return NULL;
+
+ return host_kernel;
+}
+
int kvm_cmd_run(int argc, const char **argv, const char *prefix)
{
static char real_cmdline[2048];
@@ -132,12 +157,6 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
signal(SIGQUIT, handle_sigquit);
signal(SIGINT, handle_sigint);
- if (!argv || !*argv) {
- /* no argument specified */
- usage_with_options(run_usage, options);
- return EINVAL;
- }
-
while (argc != 0) {
argc = parse_options(argc, argv, options, run_usage,
PARSE_OPT_STOP_AT_NON_OPTION);
@@ -158,6 +177,13 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
}
+ kernel_filename = find_host_kernel();
+
+ if (!kernel_filename) {
+ usage_with_options(run_usage, options);
+ return EINVAL;
+ }
+
if (nrcpus < 1 || nrcpus > KVM_NR_CPUS)
die("Number of CPUs %d is out of [1;%d] range", nrcpus, KVM_NR_CPUS);
--
1.7.0.4
next reply other threads:[~2011-04-12 17:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-12 17:51 Pekka Enberg [this message]
[not found] ` <BANLkTik-aC+CpJnkNep1Zg9hO=TF=WL_2Q@mail.gmail.com>
2011-04-12 18:14 ` [PATCH] kvm tools: Use host kernel image by default Pekka Enberg
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=1302630689-13498-1-git-send-email-penberg@kernel.org \
--to=penberg@kernel.org \
--cc=asias.hejun@gmail.com \
--cc=gorcunov@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=mingo@elte.hu \
/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