Patchwork [v7,1/5] sockets: Make inet_parse() non static.

login
register
mail settings
Submitter Bharata B Rao
Date Sept. 17, 2012, 3:22 p.m.
Message ID <20120917152249.GC6879@in.ibm.com>
Download mbox | patch
Permalink /patch/184449/
State New
Headers show

Comments

Bharata B Rao - Sept. 17, 2012, 3:22 p.m.
sockets: Make inet_parse() non static.

From: Bharata B Rao <bharata@linux.vnet.ibm.com>

Make inet_parse() non-static so that other subsystems like gluster
can use it to parse inet addresses. As a pre-requisite, define and
globalize the qemu_inet_opts.

Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
---

 Makefile.objs  |    2 +-
 qemu-config.c  |   31 +++++++++++++++++++++++++++++++
 qemu-sockets.c |   42 ++++++------------------------------------
 qemu_socket.h  |    1 +
 4 files changed, 39 insertions(+), 37 deletions(-)
Kevin Wolf - Sept. 18, 2012, 12:47 p.m.
Am 17.09.2012 17:22, schrieb Bharata B Rao:
> sockets: Make inet_parse() non static.
> 
> From: Bharata B Rao <bharata@linux.vnet.ibm.com>
> 
> Make inet_parse() non-static so that other subsystems like gluster
> can use it to parse inet addresses. As a pre-requisite, define and
> globalize the qemu_inet_opts.
> 
> Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
> ---
> 
>  Makefile.objs  |    2 +-
>  qemu-config.c  |   31 +++++++++++++++++++++++++++++++
>  qemu-sockets.c |   42 ++++++------------------------------------
>  qemu_socket.h  |    1 +
>  4 files changed, 39 insertions(+), 37 deletions(-)

Making the option list global sounds fine, but I don't think it should
be moved to qemu-config.c or added to vm_config_groups, which is
generally used for command line options and config file entries. At
least I can't imagine a command line option -inet would be very useful.

Kevin
Paolo Bonzini - Sept. 18, 2012, 12:57 p.m.
Il 18/09/2012 14:47, Kevin Wolf ha scritto:
>> >  Makefile.objs  |    2 +-
>> >  qemu-config.c  |   31 +++++++++++++++++++++++++++++++
>> >  qemu-sockets.c |   42 ++++++------------------------------------
>> >  qemu_socket.h  |    1 +
>> >  4 files changed, 39 insertions(+), 37 deletions(-)
> Making the option list global sounds fine, but I don't think it should
> be moved to qemu-config.c or added to vm_config_groups, which is
> generally used for command line options and config file entries. At
> least I can't imagine a command line option -inet would be very useful.

Yes.  Also, I'll send a pull-request for
http://patchwork.ozlabs.org/patch/180237/ soon, so you might as well
take that patch.

Paolo
Bharata B Rao - Sept. 20, 2012, 5:57 a.m.
On Tue, Sep 18, 2012 at 02:57:59PM +0200, Paolo Bonzini wrote:
> Il 18/09/2012 14:47, Kevin Wolf ha scritto:
> >> >  Makefile.objs  |    2 +-
> >> >  qemu-config.c  |   31 +++++++++++++++++++++++++++++++
> >> >  qemu-sockets.c |   42 ++++++------------------------------------
> >> >  qemu_socket.h  |    1 +
> >> >  4 files changed, 39 insertions(+), 37 deletions(-)
> > Making the option list global sounds fine, but I don't think it should
> > be moved to qemu-config.c or added to vm_config_groups, which is
> > generally used for command line options and config file entries. At
> > least I can't imagine a command line option -inet would be very useful.
> 
> Yes.  Also, I'll send a pull-request for
> http://patchwork.ozlabs.org/patch/180237/ soon, so you might as well
> take that patch.

Ok, this patch is good enough for gluster usecase. I will include this in my
v8 post if its not upstream by that time.

Regards,
Bharata.

Patch

diff --git a/Makefile.objs b/Makefile.objs
index 4412757..447371f 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -230,7 +230,7 @@  universal-obj-y += $(qapi-obj-y)
 
 qga-obj-y = qga/ qemu-ga.o module.o
 qga-obj-$(CONFIG_WIN32) += oslib-win32.o
-qga-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-sockets.o qemu-option.o
+qga-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-config.o qemu-sockets.o qemu-option.o
 
 vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
diff --git a/qemu-config.c b/qemu-config.c
index eba977e..d3d36b6 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -646,6 +646,36 @@  QemuOptsList qemu_boot_opts = {
     },
 };
 
+QemuOptsList qemu_inet_opts = {
+    .name = "inet",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_inet_opts.head),
+    .desc = {
+        {
+            .name = "path",
+            .type = QEMU_OPT_STRING,
+        },{
+            .name = "host",
+            .type = QEMU_OPT_STRING,
+        },{
+            .name = "port",
+            .type = QEMU_OPT_STRING,
+        },{
+            .name = "to",
+            .type = QEMU_OPT_NUMBER,
+        },{
+            .name = "ipv4",
+            .type = QEMU_OPT_BOOL,
+        },{
+            .name = "ipv6",
+            .type = QEMU_OPT_BOOL,
+        },{
+            .name = "block",
+            .type = QEMU_OPT_BOOL,
+        },
+        { /* end if list */ }
+    },
+};
+
 static QemuOptsList *vm_config_groups[32] = {
     &qemu_drive_opts,
     &qemu_chardev_opts,
@@ -662,6 +692,7 @@  static QemuOptsList *vm_config_groups[32] = {
     &qemu_boot_opts,
     &qemu_iscsi_opts,
     &qemu_sandbox_opts,
+    &qemu_inet_opts,
     NULL,
 };
 
diff --git a/qemu-sockets.c b/qemu-sockets.c
index 361d890..c330fc5 100644
--- a/qemu-sockets.c
+++ b/qemu-sockets.c
@@ -24,6 +24,7 @@ 
 
 #include "qemu_socket.h"
 #include "qemu-common.h" /* for qemu_isdigit */
+#include "qemu-config.h"
 
 #ifndef AI_ADDRCONFIG
 # define AI_ADDRCONFIG 0
@@ -31,37 +32,6 @@ 
 
 static const int on=1, off=0;
 
-/* used temporarely until all users are converted to QemuOpts */
-static QemuOptsList dummy_opts = {
-    .name = "dummy",
-    .head = QTAILQ_HEAD_INITIALIZER(dummy_opts.head),
-    .desc = {
-        {
-            .name = "path",
-            .type = QEMU_OPT_STRING,
-        },{
-            .name = "host",
-            .type = QEMU_OPT_STRING,
-        },{
-            .name = "port",
-            .type = QEMU_OPT_STRING,
-        },{
-            .name = "to",
-            .type = QEMU_OPT_NUMBER,
-        },{
-            .name = "ipv4",
-            .type = QEMU_OPT_BOOL,
-        },{
-            .name = "ipv6",
-            .type = QEMU_OPT_BOOL,
-        },{
-            .name = "block",
-            .type = QEMU_OPT_BOOL,
-        },
-        { /* end if list */ }
-    },
-};
-
 static int inet_getport(struct addrinfo *e)
 {
     struct sockaddr_in *i4;
@@ -407,7 +377,7 @@  err:
 }
 
 /* compatibility wrapper */
-static int inet_parse(QemuOpts *opts, const char *str)
+int inet_parse(QemuOpts *opts, const char *str)
 {
     const char *optstr, *h;
     char addr[64];
@@ -469,7 +439,7 @@  int inet_listen(const char *str, char *ostr, int olen,
     char *optstr;
     int sock = -1;
 
-    opts = qemu_opts_create(&dummy_opts, NULL, 0, NULL);
+    opts = qemu_opts_create(qemu_find_opts("inet"), NULL, 0, NULL);
     if (inet_parse(opts, str) == 0) {
         sock = inet_listen_opts(opts, port_offset, errp);
         if (sock != -1 && ostr) {
@@ -498,7 +468,7 @@  int inet_connect(const char *str, bool block, bool *in_progress, Error **errp)
     QemuOpts *opts;
     int sock = -1;
 
-    opts = qemu_opts_create(&dummy_opts, NULL, 0, NULL);
+    opts = qemu_opts_create(qemu_find_opts("inet"), NULL, 0, NULL);
     if (inet_parse(opts, str) == 0) {
         if (block) {
             qemu_opt_set(opts, "block", "on");
@@ -597,7 +567,7 @@  int unix_listen(const char *str, char *ostr, int olen)
     char *path, *optstr;
     int sock, len;
 
-    opts = qemu_opts_create(&dummy_opts, NULL, 0, NULL);
+    opts = qemu_opts_create(qemu_find_opts("inet"), NULL, 0, NULL);
 
     optstr = strchr(str, ',');
     if (optstr) {
@@ -625,7 +595,7 @@  int unix_connect(const char *path)
     QemuOpts *opts;
     int sock;
 
-    opts = qemu_opts_create(&dummy_opts, NULL, 0, NULL);
+    opts = qemu_opts_create(qemu_find_opts("inet"), NULL, 0, NULL);
     qemu_opt_set(opts, "path", path);
     sock = unix_connect_opts(opts);
     qemu_opts_del(opts);
diff --git a/qemu_socket.h b/qemu_socket.h
index 30ae6af..bd4d281 100644
--- a/qemu_socket.h
+++ b/qemu_socket.h
@@ -46,6 +46,7 @@  int inet_connect_opts(QemuOpts *opts, bool *in_progress, Error **errp);
 int inet_connect(const char *str, bool block, bool *in_progress, Error **errp);
 int inet_dgram_opts(QemuOpts *opts);
 const char *inet_strfamily(int family);
+int inet_parse(QemuOpts *opts, const char *str);
 
 int unix_listen_opts(QemuOpts *opts);
 int unix_listen(const char *path, char *ostr, int olen);