]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: virtio-9p cleanup
authorSasha Levin <levinsasha928@gmail.com>
Wed, 5 Sep 2012 08:32:03 +0000 (10:32 +0200)
committerPekka Enberg <penberg@kernel.org>
Wed, 5 Sep 2012 13:22:38 +0000 (16:22 +0300)
Sort out init/exit calls, move parser into the 9p code and make sure
rootfs config is initialized before virtio-9p (or any other init func)
is called.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/builtin-run.c
tools/kvm/include/kvm/virtio-9p.h
tools/kvm/virtio/9p.c

index 8209cf19df894448cd89ae3885016ed3560e79f7..5ddffaad57e240df1b76199d64e804544bcb43c6 100644 (file)
@@ -77,42 +77,12 @@ static int img_name_parser(const struct option *opt, const char *arg, int unset)
 {
        char path[PATH_MAX];
        struct stat st;
-       struct kvm *kvm = opt->ptr;
-
-       if (stat(arg, &st) == 0 &&
-           S_ISDIR(st.st_mode)) {
-               char tmp[PATH_MAX];
-
-               if (kvm->cfg.using_rootfs)
-                       die("Please use only one rootfs directory atmost");
-
-               if (realpath(arg, tmp) == 0 ||
-                   virtio_9p__register(kvm, tmp, "/dev/root") < 0)
-                       die("Unable to initialize virtio 9p");
-               kvm->cfg.using_rootfs = 1;
-               return 0;
-       }
 
        snprintf(path, PATH_MAX, "%s%s", kvm__get_dir(), arg);
 
-       if (stat(path, &st) == 0 &&
-           S_ISDIR(st.st_mode)) {
-               char tmp[PATH_MAX];
-
-               if (kvm->cfg.using_rootfs)
-                       die("Please use only one rootfs directory atmost");
-
-               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");
-               kvm_setup_resolv(arg);
-               kvm->cfg.using_rootfs = kvm->cfg.custom_rootfs = 1;
-               kvm->cfg.custom_rootfs_name = arg;
-               return 0;
-       }
-
+       if ((stat(arg, &st) == 0 && S_ISDIR(st.st_mode)) ||
+          (stat(path, &st) == 0 && S_ISDIR(st.st_mode)))
+               return virtio_9p_img_name_parser(opt, arg, unset);
        return disk_img_name_parser(opt, arg, unset);
 }
 
@@ -121,29 +91,6 @@ void kvm_run_set_wrapper_sandbox(void)
        kvm_run_wrapper = KVM_RUN_SANDBOX;
 }
 
-static int virtio_9p_rootdir_parser(const struct option *opt, const char *arg, int unset)
-{
-       char *tag_name;
-       char tmp[PATH_MAX];
-
-       /*
-        * 9p dir can be of the form dirname,tag_name or
-        * just dirname. In the later case we use the
-        * default tag name
-        */
-       tag_name = strstr(arg, ",");
-       if (tag_name) {
-               *tag_name = '\0';
-               tag_name++;
-       }
-       if (realpath(arg, tmp)) {
-               if (virtio_9p__register(kvm, tmp, tag_name) < 0)
-                       die("Unable to initialize virtio 9p");
-       } else
-               die("Failed resolving 9p path");
-       return 0;
-}
-
 #define BUILD_OPTIONS(name, cfg, kvm)                                  \
        struct option name[] = {                                        \
        OPT_GROUP("Basic options:"),                                    \
@@ -167,7 +114,7 @@ static int virtio_9p_rootdir_parser(const struct option *opt, const char *arg, i
                        Number Generator"),                             \
        OPT_CALLBACK('\0', "9p", NULL, "dir_to_share,tag_name",         \
                     "Enable virtio 9p to share files between host and  \
-                    guest", virtio_9p_rootdir_parser, NULL),           \
+                    guest", virtio_9p_rootdir_parser, kvm),            \
        OPT_STRING('\0', "console", &(cfg)->console, "serial, virtio or \
                        hv", "Console to use"),                         \
        OPT_STRING('\0', "dev", &(cfg)->dev, "device_file",             \
@@ -792,7 +739,11 @@ static int kvm_cmd_run_init(int argc, const char **argv)
                goto fail;
        }
 
-       virtio_9p__init(kvm);
+       r = virtio_9p__init(kvm);
+       if (r < 0) {
+               pr_err("virtio_9p__init() failed with error %d\n", r);
+               goto fail;
+       }
 
        r = virtio_net__init(kvm);
        if (r < 0) {
index cb590d185db3b0e5f9f9b45c6d94869f5f982e9b..19ffe505a74cbef325702e9ec23fab1cbd7016e7 100644 (file)
@@ -3,6 +3,7 @@
 #include "kvm/virtio.h"
 #include "kvm/pci.h"
 #include "kvm/threadpool.h"
+#include "kvm/parse-options.h"
 
 #include <sys/types.h>
 #include <dirent.h>
@@ -65,6 +66,8 @@ struct p9_pdu {
 
 struct kvm;
 
+int virtio_9p_rootdir_parser(const struct option *opt, const char *arg, int unset);
+int virtio_9p_img_name_parser(const struct option *opt, const char *arg, int unset);
 int virtio_9p__register(struct kvm *kvm, const char *root, const char *tag_name);
 int virtio_9p__init(struct kvm *kvm);
 int virtio_p9_pdu_readf(struct p9_pdu *pdu, const char *fmt, ...);
index c3f5280305c4af7484d0782df3258d9e542a7f0e..0705d79f32d7371a83e615cc85887cd81a9db74e 100644 (file)
@@ -5,6 +5,7 @@
 #include "kvm/irq.h"
 #include "kvm/virtio-9p.h"
 #include "kvm/guest_compat.h"
+#include "kvm/builtin-setup.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -1325,6 +1326,73 @@ struct virtio_ops p9_dev_virtio_ops = (struct virtio_ops) {
        .get_size_vq            = get_size_vq,
 };
 
+int virtio_9p_rootdir_parser(const struct option *opt, const char *arg, int unset)
+{
+       char *tag_name;
+       char tmp[PATH_MAX];
+       struct kvm *kvm = opt->ptr;
+
+       /*
+        * 9p dir can be of the form dirname,tag_name or
+        * just dirname. In the later case we use the
+        * default tag name
+        */
+       tag_name = strstr(arg, ",");
+       if (tag_name) {
+               *tag_name = '\0';
+               tag_name++;
+       }
+       if (realpath(arg, tmp)) {
+               if (virtio_9p__register(kvm, tmp, tag_name) < 0)
+                       die("Unable to initialize virtio 9p");
+       } else
+               die("Failed resolving 9p path");
+       return 0;
+}
+
+int virtio_9p_img_name_parser(const struct option *opt, const char *arg, int unset)
+{
+       char path[PATH_MAX];
+       struct stat st;
+       struct kvm *kvm = opt->ptr;
+
+       if (stat(arg, &st) == 0 &&
+           S_ISDIR(st.st_mode)) {
+               char tmp[PATH_MAX];
+
+               if (kvm->cfg.using_rootfs)
+                       die("Please use only one rootfs directory atmost");
+
+               if (realpath(arg, tmp) == 0 ||
+                   virtio_9p__register(kvm, tmp, "/dev/root") < 0)
+                       die("Unable to initialize virtio 9p");
+               kvm->cfg.using_rootfs = 1;
+               return 0;
+       }
+
+       snprintf(path, PATH_MAX, "%s%s", kvm__get_dir(), arg);
+
+       if (stat(path, &st) == 0 &&
+           S_ISDIR(st.st_mode)) {
+               char tmp[PATH_MAX];
+
+               if (kvm->cfg.using_rootfs)
+                       die("Please use only one rootfs directory atmost");
+
+               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");
+               kvm_setup_resolv(arg);
+               kvm->cfg.using_rootfs = kvm->cfg.custom_rootfs = 1;
+               kvm->cfg.custom_rootfs_name = arg;
+               return 0;
+       }
+
+       return -1;
+}
+
 int virtio_9p__init(struct kvm *kvm)
 {
        struct p9_dev *p9dev;