* [PATCH] kvm tools: Use host kernel image by default
@ 2011-04-12 17:51 Pekka Enberg
[not found] ` <BANLkTik-aC+CpJnkNep1Zg9hO=TF=WL_2Q@mail.gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: Pekka Enberg @ 2011-04-12 17:51 UTC (permalink / raw)
To: kvm; +Cc: Pekka Enberg, Asias He, Cyrill Gorcunov, Ingo Molnar
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-04-12 18:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-12 17:51 [PATCH] kvm tools: Use host kernel image by default Pekka Enberg
[not found] ` <BANLkTik-aC+CpJnkNep1Zg9hO=TF=WL_2Q@mail.gmail.com>
2011-04-12 18:14 ` Pekka Enberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox