]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: add private ptr to option parser
authorSasha Levin <levinsasha928@gmail.com>
Wed, 5 Sep 2012 08:31:43 +0000 (10:31 +0200)
committerPekka Enberg <penberg@kernel.org>
Wed, 5 Sep 2012 13:22:36 +0000 (16:22 +0300)
Support passing a private ptr to CALLBACK options. This will make it possible
assigning options into specific struct kvms by passing them directly to parsers.

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/parse-options.h

index 2b4315baad927e370af31865f9e445c62f5916a1..52e0190948d00aa0cb93544ef26f5fb8780a9a83 100644 (file)
@@ -417,9 +417,10 @@ static int shmem_parser(const struct option *opt, const char *arg, int unset)
        OPT_CALLBACK('\0', "shmem", NULL,                               \
                     "[pci:]<addr>:<size>[:handle=<handle>][:create]",  \
                     "Share host shmem with guest via pci device",      \
-                    shmem_parser),                                     \
-       OPT_CALLBACK('d', "disk", NULL, "image or rootfs_dir", "Disk    \
-                       image or rootfs directory", img_name_parser),   \
+                    shmem_parser, NULL),                               \
+       OPT_CALLBACK('d', "disk", kvm, "image or rootfs_dir", "Disk     \
+                       image or rootfs directory", img_name_parser,    \
+                       NULL),                                          \
        OPT_BOOLEAN('\0', "balloon", &(cfg)->balloon, "Enable virtio    \
                        balloon"),                                      \
        OPT_BOOLEAN('\0', "vnc", &(cfg)->vnc, "Enable VNC framebuffer"),\
@@ -428,14 +429,14 @@ static int shmem_parser(const struct option *opt, const char *arg, int unset)
                        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),                 \
+                    guest", virtio_9p_rootdir_parser, NULL),           \
        OPT_STRING('\0', "console", &(cfg)->console, "serial, virtio or \
                        hv", "Console to use"),                         \
        OPT_STRING('\0', "dev", &(cfg)->dev, "device_file",             \
                        "KVM device file"),                             \
        OPT_CALLBACK('\0', "tty", NULL, "tty id",                       \
                     "Remap guest TTY into a pty on the host",          \
-                    tty_parser),                                       \
+                    tty_parser, NULL),                                 \
        OPT_STRING('\0', "sandbox", &(cfg)->sandbox, "script",          \
                        "Run this script when booting into custom       \
                        rootfs"),                                       \
@@ -455,7 +456,7 @@ static int shmem_parser(const struct option *opt, const char *arg, int unset)
        OPT_GROUP("Networking options:"),                               \
        OPT_CALLBACK_DEFAULT('n', "network", NULL, "network params",    \
                     "Create a new guest NIC",                          \
-                    netdev_parser, NULL),                              \
+                    netdev_parser, NULL, NULL),                        \
        OPT_BOOLEAN('\0', "no-dhcp", &(cfg)->no_dhcp, "Disable kernel DHCP\
                        in rootfs mode"),                               \
                                                                        \
index 7886ff70d3b3bbb17f4b0b491a1a9321446f9b99..a8a25d06b25bb5f7090de2eb82f7760d81d3beca 100644 (file)
@@ -89,6 +89,7 @@ const char *long_name;
 void *value;
 const char *argh;
 const char *help;
+void *ptr;
 
 int flags;
 parse_opt_cb *callback;
@@ -150,7 +151,7 @@ intptr_t defval;
        .help = (h)                         \
 }
 
-#define OPT_CALLBACK(s, l, v, a, h, f)      \
+#define OPT_CALLBACK(s, l, v, a, h, f, p)   \
 {                                          \
        .type = OPTION_CALLBACK,            \
        .short_name = (s),                  \
@@ -158,10 +159,11 @@ intptr_t defval;
        .value = (v),                       \
        (a),                                \
        .help = (h),                        \
-       .callback = (f)                     \
+       .callback = (f),                    \
+       .ptr = (p),                         \
 }
 
-#define OPT_CALLBACK_NOOPT(s, l, v, a, h, f) \
+#define OPT_CALLBACK_NOOPT(s, l, v, a, h, f, p) \
 {                                          \
        .type = OPTION_CALLBACK,            \
        .short_name = (s),                  \
@@ -170,10 +172,11 @@ intptr_t defval;
        (a),                                \
        .help = (h),                        \
        .callback = (f),                    \
-       .flags = PARSE_OPT_NOARG            \
+       .flags = PARSE_OPT_NOARG,           \
+       .ptr = (p),                         \
 }
 
-#define OPT_CALLBACK_DEFAULT(s, l, v, a, h, f, d) \
+#define OPT_CALLBACK_DEFAULT(s, l, v, a, h, f, d, p) \
 {                                          \
        .type = OPTION_CALLBACK,            \
        .short_name = (s),                  \
@@ -182,7 +185,8 @@ intptr_t defval;
        .help = (h),                        \
        .callback = (f),                    \
        .defval = (intptr_t)d,              \
-       .flags = PARSE_OPT_LASTARG_DEFAULT  \
+       .flags = PARSE_OPT_LASTARG_DEFAULT, \
+       .ptr = (p)                          \
 }
 
 #define OPT_END() { .type = OPTION_END }