* [Qemu-devel] [PATCH v1] Make inet_parse() non-static
@ 2012-09-11 8:28 Bharata B Rao
2012-09-11 12:34 ` Markus Armbruster
0 siblings, 1 reply; 3+ messages in thread
From: Bharata B Rao @ 2012-09-11 8:28 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi, Gerd Hoffmann
From: Bharata B Rao <bharata@linux.vnet.ibm.com>
Make inet_parse() non static.
- 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.
- Extend inet_parse() to parse just 'address' also in addition to
'address:port'.
Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
---
Ideally I needn't use sscanf twice once for parsing host:port (checking
return value of 2) and if that fails for parsing host w/o port (checking
return value of 1). I could just check if sscanf returned 2 or 1 and decide
if addr:port or just addr was provided, but in the latter case the
pointer to the bytes consumed (&pos) doesn't get updated.
Makefile.objs | 2 +-
qemu-config.c | 31 ++++++++++++++++++++++++++++
qemu-sockets.c | 62 +++++++++++++++++---------------------------------------
qemu_socket.h | 1 +
4 files changed, 52 insertions(+), 44 deletions(-)
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..2011691 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,11 +377,11 @@ 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];
- char port[33];
+ char port[33] = {'\0'}; /* port is optional */
int pos;
/* parse address */
@@ -426,25 +396,31 @@ static int inet_parse(QemuOpts *opts, const char *str)
} else if (str[0] == '[') {
/* IPv6 addr */
if (2 != sscanf(str,"[%64[^]]]:%32[^,]%n",addr,port,&pos)) {
- fprintf(stderr, "%s: ipv6 parse error (%s)\n",
+ if (1 != sscanf(str, "[%64[^]]]%n", addr, &pos)) {
+ fprintf(stderr, "%s: ipv6 parse error (%s)\n",
__FUNCTION__, str);
- return -1;
+ return -1;
+ }
}
qemu_opt_set(opts, "ipv6", "on");
} else if (qemu_isdigit(str[0])) {
/* IPv4 addr */
if (2 != sscanf(str,"%64[0-9.]:%32[^,]%n",addr,port,&pos)) {
- fprintf(stderr, "%s: ipv4 parse error (%s)\n",
+ if (1 != sscanf(str, "%64[0-9.]%n", addr, &pos)) {
+ fprintf(stderr, "%s: ipv4 parse error (%s)\n",
__FUNCTION__, str);
- return -1;
+ return -1;
+ }
}
qemu_opt_set(opts, "ipv4", "on");
} else {
/* hostname */
if (2 != sscanf(str,"%64[^:]:%32[^,]%n",addr,port,&pos)) {
- fprintf(stderr, "%s: hostname parse error (%s)\n",
+ if (1 != sscanf(str, "%64[^:]%n", addr, &pos)) {
+ fprintf(stderr, "%s: hostname parse error (%s)\n",
__FUNCTION__, str);
- return -1;
+ return -1;
+ }
}
}
qemu_opt_set(opts, "host", addr);
@@ -469,7 +445,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 +474,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 +573,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 +601,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);
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v1] Make inet_parse() non-static
2012-09-11 8:28 [Qemu-devel] [PATCH v1] Make inet_parse() non-static Bharata B Rao
@ 2012-09-11 12:34 ` Markus Armbruster
2012-09-12 3:35 ` Bharata B Rao
0 siblings, 1 reply; 3+ messages in thread
From: Markus Armbruster @ 2012-09-11 12:34 UTC (permalink / raw)
To: bharata; +Cc: Kevin Wolf, Stefan Hajnoczi, qemu-devel, Gerd Hoffmann
Bharata B Rao <bharata@linux.vnet.ibm.com> writes:
> From: Bharata B Rao <bharata@linux.vnet.ibm.com>
>
> Make inet_parse() non static.
>
> - 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.
Please repost this as part of a series that needs non-static
inet_parse(). I'm worried parameter "block" will cause trouble, but I
can't see that without the users.
> - Extend inet_parse() to parse just 'address' also in addition to
> 'address:port'.
Separate patch, please.
> Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
> ---
> Ideally I needn't use sscanf twice once for parsing host:port (checking
> return value of 2) and if that fails for parsing host w/o port (checking
> return value of 1). I could just check if sscanf returned 2 or 1 and decide
> if addr:port or just addr was provided, but in the latter case the
> pointer to the bytes consumed (&pos) doesn't get updated.
You can use two of them, like this:
a_end = b_end = -1;
sscanf(str, "%d%n:%d%n", &a, &a_end, &b, &b_end);
if (b_end >= 0) ...
[...]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v1] Make inet_parse() non-static
2012-09-11 12:34 ` Markus Armbruster
@ 2012-09-12 3:35 ` Bharata B Rao
0 siblings, 0 replies; 3+ messages in thread
From: Bharata B Rao @ 2012-09-12 3:35 UTC (permalink / raw)
To: Markus Armbruster; +Cc: Kevin Wolf, Stefan Hajnoczi, qemu-devel, Gerd Hoffmann
On Tue, Sep 11, 2012 at 02:34:09PM +0200, Markus Armbruster wrote:
> Bharata B Rao <bharata@linux.vnet.ibm.com> writes:
>
> > From: Bharata B Rao <bharata@linux.vnet.ibm.com>
> >
> > Make inet_parse() non static.
> >
> > - 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.
>
> Please repost this as part of a series that needs non-static
> inet_parse().
Sure, will post it as part of next version of gluster patches.
> I'm worried parameter "block" will cause trouble, but I
> can't see that without the users.
I don't see how that could affect the users. FYI I am not using "block"
parameter, pls wait for my next post to check this.
>
> > - Extend inet_parse() to parse just 'address' also in addition to
> > 'address:port'.
>
> Separate patch, please.
Hmm ok.
>
> > Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
> > ---
> > Ideally I needn't use sscanf twice once for parsing host:port (checking
> > return value of 2) and if that fails for parsing host w/o port (checking
> > return value of 1). I could just check if sscanf returned 2 or 1 and decide
> > if addr:port or just addr was provided, but in the latter case the
> > pointer to the bytes consumed (&pos) doesn't get updated.
>
> You can use two of them, like this:
>
> a_end = b_end = -1;
> sscanf(str, "%d%n:%d%n", &a, &a_end, &b, &b_end);
> if (b_end >= 0) ...
Thanks.
Bharata.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-09-12 3:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-11 8:28 [Qemu-devel] [PATCH v1] Make inet_parse() non-static Bharata B Rao
2012-09-11 12:34 ` Markus Armbruster
2012-09-12 3:35 ` Bharata B Rao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).