From: Sasha Levin <levinsasha928@gmail.com>
To: penberg@kernel.org
Cc: kvm@vger.kernel.org, mingo@elte.hu, gorcunov@gmail.com,
asias.hejun@gmail.com, Sasha Levin <levinsasha928@gmail.com>
Subject: [PATCH 4/5] kvm tools: Teach 'run' to handle guestfs
Date: Tue, 6 Sep 2011 02:23:54 +0300 [thread overview]
Message-ID: <1315265035-9496-4-git-send-email-levinsasha928@gmail.com> (raw)
In-Reply-To: <1315265035-9496-1-git-send-email-levinsasha928@gmail.com>
This patch allows to run previously created guestfs by simply specifying it
with the '-d' parameter.
This allows running guestfs which were created before using:
kvm setup -n [name]
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
tools/kvm/builtin-run.c | 24 ++++++++++++++++++++++--
tools/kvm/include/kvm/kvm.h | 3 +++
tools/kvm/kvm.c | 2 --
3 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index ef1a358..725c23c 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -85,6 +85,7 @@ static bool vnc;
static bool sdl;
static bool balloon;
static bool using_rootfs;
+static bool custom_rootfs;
extern bool ioport_debug;
extern int active_console;
extern int debug_iodelay;
@@ -103,6 +104,7 @@ static int img_name_parser(const struct option *opt, const char *arg, int unset)
{
char *sep;
struct stat st;
+ char path[PATH_MAX];
if (stat(arg, &st) == 0 &&
S_ISDIR(st.st_mode)) {
@@ -115,6 +117,21 @@ static int img_name_parser(const struct option *opt, const char *arg, int unset)
return 0;
}
+ snprintf(path, PATH_MAX, "%s%s%s", HOME_DIR, KVM_PID_FILE_PATH, arg);
+
+ if (stat(path, &st) == 0 &&
+ S_ISDIR(st.st_mode)) {
+ char tmp[PATH_MAX];
+
+ if (realpath(path, tmp) == 0 ||
+ virtio_9p__register(kvm, tmp, "/dev/root") < 0)
+ die("Unable to initialize virtio 9p");
+ if (virtio_9p__register(kvm, "/", "hostfs") < 0)
+ die("Unable to initialize virtio 9p");
+ using_rootfs = custom_rootfs = 1;
+ return 0;
+ }
+
if (image_count >= MAX_DISK_IMAGES)
die("Currently only 4 images are supported");
@@ -739,10 +756,13 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
strlcat(real_cmdline, " init=/bin/sh ", sizeof(real_cmdline));
}
- if (using_rootfs)
+ if (using_rootfs) {
strcat(real_cmdline, " root=/dev/root rw rootflags=rw,trans=virtio,version=9p2000.L rootfstype=9p");
- else if (!strstr(real_cmdline, "root="))
+ if (custom_rootfs)
+ strcat(real_cmdline, " init=/virt/init");
+ } else if (!strstr(real_cmdline, "root=")) {
strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline));
+ }
if (image_count) {
kvm->nr_disks = image_count;
diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index d471cee..bb40c4c 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -24,6 +24,9 @@
#define SIGKVMRESUME (SIGRTMIN + 5)
#define SIGKVMMEMSTAT (SIGRTMIN + 6)
+#define KVM_PID_FILE_PATH "/.kvm-tools/"
+#define HOME_DIR getenv("HOME")
+
struct kvm {
int sys_fd; /* For system ioctls(), i.e. /dev/kvm */
int vm_fd; /* For VM ioctls() */
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index bbfdea2..199c9b9 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -32,8 +32,6 @@
#include <dirent.h>
#define DEFINE_KVM_EXIT_REASON(reason) [reason] = #reason
-#define KVM_PID_FILE_PATH "/.kvm-tools/"
-#define HOME_DIR getenv("HOME")
const char *kvm_exit_reasons[] = {
DEFINE_KVM_EXIT_REASON(KVM_EXIT_UNKNOWN),
--
1.7.6.1
next prev parent reply other threads:[~2011-09-05 23:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-05 23:23 [PATCH 1/5] kvm tools: Remove unconditional warning in ivshmem Sasha Levin
2011-09-05 23:23 ` [PATCH 2/5] kvm tools: Fix 32bit warnings Sasha Levin
2011-09-05 23:23 ` [PATCH 3/5] kvm tools: Attach default 'root=' only if required Sasha Levin
2011-09-05 23:23 ` Sasha Levin [this message]
2011-09-06 13:37 ` [PATCH 4/5] kvm tools: Teach 'run' to handle guestfs Cyrill Gorcunov
2011-09-05 23:23 ` [PATCH 5/5] kvm tools: Add guestfs network autoconfiguration Sasha Levin
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=1315265035-9496-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