Fix the case when using a rootfs combined with a virtio-blk disk.

Also, simplify custon rootfs name lookup.

Signed-off-by: Sasha Levin <levinsasha...@gmail.com>
---
 tools/kvm/builtin-run.c |   18 ++++++------------
 1 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 0879ab9..e6751aa 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -87,6 +87,7 @@ static const char *script;
 static const char *guest_name;
 static const char *sandbox;
 static const char *hugetlbfs_path;
+static const char *custom_rootfs_name = "default";
 static struct virtio_net_params *net_params;
 static bool single_step;
 static bool readonly_image[MAX_DISK_IMAGES];
@@ -151,6 +152,7 @@ static int img_name_parser(const struct option *opt, const 
char *arg, int unset)
                        die("Unable to initialize virtio 9p");
                kvm_setup_resolv(arg);
                using_rootfs = custom_rootfs = 1;
+               custom_rootfs_name = arg;
                return 0;
        }
 
@@ -738,18 +740,13 @@ void kvm_run_help(void)
 static int kvm_custom_stage2(void)
 {
        char tmp[PATH_MAX], dst[PATH_MAX], *src;
-       const char *rootfs;
+       const char *rootfs = custom_rootfs_name;
        int r;
 
        src = realpath("guest/init_stage2", NULL);
        if (src == NULL)
                return -ENOMEM;
 
-       if (image_filename[0] == NULL)
-               rootfs = "default";
-       else
-               rootfs = image_filename[0];
-
        snprintf(tmp, PATH_MAX, "%s%s/virt/init_stage2", kvm__get_dir(), 
rootfs);
        remove(tmp);
 
@@ -762,12 +759,9 @@ static int kvm_custom_stage2(void)
 
 static int kvm_run_set_sandbox(void)
 {
-       const char *guestfs_name = "default";
+       const char *guestfs_name = custom_rootfs_name;
        char path[PATH_MAX], script[PATH_MAX], *tmp;
 
-       if (image_filename[0])
-               guestfs_name = image_filename[0];
-
        snprintf(path, PATH_MAX, "%s%s/virt/sandbox.sh", kvm__get_dir(), 
guestfs_name);
 
        remove(path);
@@ -976,8 +970,8 @@ int kvm_cmd_run(int argc, const char **argv, const char 
*prefix)
        if (!using_rootfs && !image_filename[0]) {
                char tmp[PATH_MAX];
 
-               kvm_setup_create_new("default");
-               kvm_setup_resolv("default");
+               kvm_setup_create_new(custom_rootfs_name);
+               kvm_setup_resolv(custom_rootfs_name);
 
                snprintf(tmp, PATH_MAX, "%s%s", kvm__get_dir(), "default");
                if (virtio_9p__register(kvm, tmp, "/dev/root") < 0)
-- 
1.7.8

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

Reply via email to