[PATCH 1/2] kvm tools: Modify 'kvm run' to use virt fs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



'kvm run' will now create a 'default' profile and boot into it.

Currently we boot into rw rootfs of the host, which is risky. Instead,
we can boot in a 'safe' enviroment with networking.

Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx>
---
 tools/kvm/builtin-run.c               |   13 ++++++++++---
 tools/kvm/builtin-setup.c             |   13 ++++++++++---
 tools/kvm/include/kvm/builtin-setup.h |    1 +
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 725c23c..13d85af 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -1,5 +1,6 @@
 #include "kvm/builtin-run.h"
 
+#include "kvm/builtin-setup.h"
 #include "kvm/virtio-balloon.h"
 #include "kvm/virtio-console.h"
 #include "kvm/parse-options.h"
@@ -747,10 +748,16 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 		strlcat(real_cmdline, kernel_cmdline, sizeof(real_cmdline));
 
 	if (!using_rootfs && !image_filename[0]) {
-		if (virtio_9p__register(kvm, "/", "/dev/root") < 0)
-			die("Unable to initialize virtio 9p");
+		char tmp[PATH_MAX];
 
-		using_rootfs = 1;
+		kvm_setup_create_new("default");
+
+		snprintf(tmp, PATH_MAX, "%s%s%s", HOME_DIR, KVM_PID_FILE_PATH, "default");
+		if (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;
 
 		if (!strstr(real_cmdline, "init="))
 			strlcat(real_cmdline, " init=/bin/sh ", sizeof(real_cmdline));
diff --git a/tools/kvm/builtin-setup.c b/tools/kvm/builtin-setup.c
index f7588dd..c93eec3 100644
--- a/tools/kvm/builtin-setup.c
+++ b/tools/kvm/builtin-setup.c
@@ -159,13 +159,13 @@ static void make_root_dir(void)
 	mkdir(name, 0777);
 }
 
-static void make_dir(const char *dir)
+static int make_dir(const char *dir)
 {
 	char name[PATH_MAX];
 
 	snprintf(name, PATH_MAX, "%s%s%s", HOME_DIR, KVM_PID_FILE_PATH, dir);
 
-	mkdir(name, 0777);
+	return mkdir(name, 0777);
 }
 
 static void make_guestfs_dir(const char *guestfs_name, const char *dir)
@@ -184,7 +184,9 @@ static int do_setup(const char *guestfs_name)
 
 	make_root_dir();
 
-	make_dir(guestfs_name);
+	ret = make_dir(guestfs_name);
+	if (ret < 0)
+		return ret;
 
 	for (i = 0; i < ARRAY_SIZE(guestfs_dirs); i++)
 		make_guestfs_dir(guestfs_name, guestfs_dirs[i]);
@@ -200,6 +202,11 @@ static int do_setup(const char *guestfs_name)
 	return copy_init(guestfs_name);
 }
 
+int kvm_setup_create_new(const char *guestfs_name)
+{
+	return do_setup(guestfs_name);
+}
+
 int kvm_cmd_setup(int argc, const char **argv, const char *prefix)
 {
 	parse_setup_options(argc, argv);
diff --git a/tools/kvm/include/kvm/builtin-setup.h b/tools/kvm/include/kvm/builtin-setup.h
index b0eb345..6e183a1 100644
--- a/tools/kvm/include/kvm/builtin-setup.h
+++ b/tools/kvm/include/kvm/builtin-setup.h
@@ -3,5 +3,6 @@
 
 int kvm_cmd_setup(int argc, const char **argv, const char *prefix);
 void kvm_setup_help(void);
+int kvm_setup_create_new(const char *guestfs_name);
 
 #endif
-- 
1.7.6.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux