[PATCH 09/33] kvm tools: add private ptr to option parser

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

 



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@xxxxxxxxx>
---
 tools/kvm/builtin-run.c               | 13 +++++++------
 tools/kvm/include/kvm/parse-options.h | 16 ++++++++++------
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 2b4315b..52e0190 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -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"),				\
 									\
diff --git a/tools/kvm/include/kvm/parse-options.h b/tools/kvm/include/kvm/parse-options.h
index 7886ff7..a8a25d0 100644
--- a/tools/kvm/include/kvm/parse-options.h
+++ b/tools/kvm/include/kvm/parse-options.h
@@ -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 }
-- 
1.7.12

--
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