Make inet_parse() non-static
PATCH 1/1 Make inet_parse() non-static
From: Bharata B Rao <[email protected]>
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'.
---
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(-)
Makefile.objs +1 -1
@@ -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)
qemu-config.c +31 -0
@@ -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, };
qemu-sockets.c +19 -43
126 lines not on this page · raw message
qemu_socket.h +1 -0
@@ -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);
Quoted 7 lines · Bharata B Rao
From: Bharata B Rao <[email protected]>
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 theqemu_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.
Quoted 2 lines
- Extend
inet_parse()to parse just 'address' also in addition to 'address:port'.
Separate patch, please.
Quoted 7 lines
Signed-off-by Bharata B Rao <[email protected]>---
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) ...[...]
Quoted 4 lines · Markus Armbruster
Quoted 2 lines · Bharata B Rao
From: Bharata B Rao <[email protected]>
Quoted 8 lines
Quoted 5 lines
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 theqemu_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.
Quoted 2 lines
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.
Quoted 5 lines
Quoted 3 lines
- Extend
inet_parse()to parse just 'address' also in addition to 'address:port'.Separate patch, please.
Hmm ok.
Quoted 9 lines
Quoted 8 lines
Signed-off-by Bharata B Rao <[email protected]>---
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.
Quoted 5 lines
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.