A bunch of little socket + chardev fixes
v2 cover A bunch of little socket + chardev fixes
Hi,
Here is v2 of the series, addressing Michaels review comments.
cheers,
Gerd
Gerd Hoffmann (13):
qemu-socket: zero-initialize SocketAddress
qemu-socket: drop pointless allocation
qemu-socket: catch monitor_get_fd failures
qemu-char: check optional fields using has_*
qemu-char: use more specific error_setg_* variants
qemu-char: print notification to stderr
qemu-char: fix documentation for telnet+wait socket flags
qemu-char: don't leak opts on error
qemu-char: use ChardevBackendKind in in CharDriver
qemu-char: minor mux chardev fixes
qemu-char: add -chardev mux support
qemu-char: report udb backend errors
qemu-socket: don't leak opts on error
include/sysemu/char.h | 2 +- qapi-schema.json | 7 ++++--- qemu-char.c | 45 ++++++++++++++++++++++++++++++++------------- util/qemu-sockets.c | 9 ++++----- 4 files changed, 41 insertions(+), 22 deletions(-)
Signature · 1 line
1.7.9.7
PATCH v2 1/13 qemu-socket: zero-initialize SocketAddress
--- util/qemu-sockets.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
util/qemu-sockets.c +2 -2
@@ -848,9 +848,9 @@ int unix_nonblocking_connect(const char *path,SocketAddress *socket_parse (const char *str,Error **errp) { -SocketAddress *addr =NULL ; +SocketAddress *addr; - addr =g_new (SocketAddress,1 ); + addr =g_new0 (SocketAddress,1 );if (strstart (str,"unix:" ,NULL )) {if (str[5 ] =='\0' ) {error_setg (errp,"invalid Unix socket address" );
Signature · 1 line
1.7.9.7
PATCH v2 3/13 qemu-socket: catch monitor_get_fd failures
In reply to Gerd Hoffmann--- util/qemu-sockets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/qemu-sockets.c +1 -1
@@ -903,7 +903,7 @@ int socket_connect(SocketAddress *addr, Error **errp,case SOCKET_ADDRESS_KIND_FD : fd =monitor_get_fd (cur_mon, addr->fd->str, errp); -if (callback) { +if (fd >=0 && callback) {qemu_set_nonblock (fd);callback (fd, opaque); }
Signature · 1 line
1.7.9.7
PATCH v2 4/13 qemu-char: check optional fields using has_*
In reply to Gerd Hoffmann--- qemu-char.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
qemu-char.c +2 -2
@@ -3500,7 +3500,7 @@ static CharDriverState *qmp_chardev_open_file(ChardevFile *file, Error **errp) {HANDLE out; -if (file->in) { +if (file->has_in) {error_setg (errp,"input file not supported" );return NULL ; }
@@ -3551,7 +3551,7 @@ static CharDriverState *qmp_chardev_open_file(ChardevFile *file, Error **errp)return NULL ; } -if (file->in) { +if (file->has_in) { flags =O_RDONLY ; in =qmp_chardev_open_file_source (file->in, flags, errp);if (error_is_set (errp)) {
Signature · 1 line
1.7.9.7
PATCH v2 5/13 qemu-char: use more specific error_setg_* variants
In reply to Gerd Hoffmann--- qemu-char.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
qemu-char.c +2 -2
@@ -2604,7 +2604,7 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, bool do_nodelay,memset (&ss,0 , ss_len);if (getsockname (fd, (struct sockaddr *) &ss, &ss_len) !=0 ) { -error_setg (errp,"getsockname: %s" ,strerror (errno)); +error_setg_errno (errp, errno,"getsockname" );return NULL ; }
@@ -3536,7 +3536,7 @@ static int qmp_chardev_open_file_source(char *src, int flags,TFR (fd =qemu_open (src, flags,0666 ));if (fd ==-1 ) { -error_setg (errp,"open %s: %s" , src,strerror (errno)); +error_setg_file_open (errp, errno, src); }return fd; }
Signature · 1 line
1.7.9.7
PATCH v2 6/13 qemu-char: print notification to stderr
In reply to Gerd Hoffmann--- qemu-char.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
qemu-char.c +2 -2
@@ -2666,8 +2666,8 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, bool do_nodelay, }if (is_listen && is_waitconnect) { -printf ("QEMU waiting for connection on: %s\n" , - chr->filename); +fprintf (stderr,"QEMU waiting for connection on: %s\n" , + chr->filename);tcp_chr_accept (s->listen_chan,G_IO_IN , chr);qemu_set_nonblock (s->listen_fd); }
Signature · 1 line
1.7.9.7
PATCH v2 7/13 qemu-char: fix documentation for telnet+wait socket flags
In reply to Gerd Hoffmann--- qapi-schema.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
qapi-schema.json +4 -3
@@ -3185,10 +3185,11 @@ # @addr: socket address to listen on (server=true) # or connect to (server=false) # @server: #optional create server socket (default: true) -# @wait: #optional wait for connect (not used for server -# sockets, default: false) +# @wait: #optional wait for incoming connection on server +# sockets (default: false). # @nodelay: #optional set TCP_NODELAY socket option (default: false) -# @telnet: #optional enable telnet protocol (default: false) +# @telnet: #optional enable telnet protocol on server +# sockets (default: false) # # Since: 1.4 ##
Signature · 1 line
1.7.9.7
PATCH v2 8/13 qemu-char: don't leak opts on error
In reply to Gerd Hoffmann--- qemu-char.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-char.c +1 -1
@@ -3185,7 +3185,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,if (i ==NULL ) {error_setg (errp,"chardev: backend \"%s\" not found" ,qemu_opt_get (opts,"backend" )); -return NULL ; + goto err; }if (!cd->open) {
Signature · 1 line
1.7.9.7
PATCH v2 9/13 qemu-char: use ChardevBackendKind in in CharDriver
In reply to Gerd Hoffmann--- include/sysemu/char.h | 2 +- qemu-char.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
include/sysemu/char.h +1 -1
@@ -281,7 +281,7 @@ CharDriverState *qemu_chr_find(const char *name);QemuOpts *qemu_chr_parse_compat (const char *label,const char *filename);void register_char_driver (const char *name,CharDriverState *(*open)(QemuOpts *)); -void register_char_driver_qapi (const char *name,int kind, +void register_char_driver_qapi (const char *name,ChardevBackendKind kind,void (*parse)(QemuOpts *opts,ChardevBackend *backend,Error **errp));/* add an eventfd to the qemu devices that are polled */
qemu-char.c +2 -2
@@ -3127,7 +3127,7 @@ typedef struct CharDriver {/* old, pre qapi */ CharDriverState *(*open)(QemuOpts *opts);/* new, qapi-based */ -int kind; +ChardevBackendKind kind;void (*parse)(QemuOpts *opts,ChardevBackend *backend,Error **errp); } CharDriver;
@@ -3144,7 +3144,7 @@ void register_char_driver(const char *name, CharDriverState *(*open)(QemuOpts *) backends =g_slist_append (backends, s); } -void register_char_driver_qapi (const char *name,int kind, +void register_char_driver_qapi (const char *name,ChardevBackendKind kind,void (*parse)(QemuOpts *opts,ChardevBackend *backend,Error **errp)) {CharDriver *s;
Signature · 1 line
1.7.9.7
PATCH v2 13/13 qemu-socket: don't leak opts on error
In reply to Gerd Hoffmann--- util/qemu-sockets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/qemu-sockets.c +1 -1
@@ -963,7 +963,7 @@ int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp)default :error_setg (errp,"socket type unsupported for datagram" ); -return -1 ; + fd =-1 ; }qemu_opts_del (opts);return fd;
Signature · 1 line
1.7.9.7
PATCH v2 2/13 qemu-socket: drop pointless allocation
In reply to Gerd Hoffmann--- util/qemu-sockets.c | 1 - 1 file changed, 1 deletion(-)
util/qemu-sockets.c +0 -1
@@ -871,7 +871,6 @@ SocketAddress *socket_parse(const char *str, Error **errp) } }else { addr->kind =SOCKET_ADDRESS_KIND_INET ; - addr->inet =g_new (InetSocketAddress,1 ); addr->inet =inet_parse (str, errp);if (addr->inet ==NULL ) { goto fail;
Signature · 1 line
1.7.9.7
PATCH v2 10/13 qemu-char: minor mux chardev fixes
In reply to Gerd Hoffmannmux failure path has a memory leak. creating a mux chardev can't fail though, so just assert() that instead of fixing an error path which never ever runs anyway ...
Also fix bid being leaked while being at it.
--- qemu-char.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
qemu-char.c +3 -4
@@ -3193,7 +3193,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,ChardevBackend *backend =g_new0 (ChardevBackend,1 );ChardevReturn *ret =NULL ;const char *id =qemu_opts_id (opts); -const char *bid =NULL ; +char *bid =NULL ;if (qemu_opt_get_bool (opts,"mux" ,0 )) { bid =g_strdup_printf ("%s-base" , id);
@@ -3220,9 +3220,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, backend->kind =CHARDEV_BACKEND_KIND_MUX ; backend->mux->chardev =g_strdup (bid); ret =qmp_chardev_add (id, backend, errp); -if (error_is_set (errp)) { - goto qapi_out; - } +assert (!error_is_set (errp)); } chr =qemu_chr_find (id);
@@ -3230,6 +3228,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, qapi_out:qapi_free_ChardevBackend (backend);qapi_free_ChardevReturn (ret); +g_free (bid);return chr; }
Signature · 1 line
1.7.9.7
PATCH v2 11/13 qemu-char: add -chardev mux support
In reply to Gerd HoffmannAllow to explicitly create mux chardevs on the command line, like you can using QMP.
--- qemu-char.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
qemu-char.c +18 -0
@@ -3122,6 +3122,19 @@ static void qemu_chr_parse_memory(QemuOpts *opts, ChardevBackend *backend, } } +static void qemu_chr_parse_mux (QemuOpts *opts,ChardevBackend *backend, +Error **errp) +{ +const char *chardev =qemu_opt_get (opts,"chardev" ); + +if (chardev ==NULL ) { +error_setg (errp,"chardev: mux: no chardev given" ); +return ; + } + backend->mux =g_new0 (ChardevMux,1 ); + backend->mux->chardev =g_strdup (chardev); +} + typedef struct CharDriver { const char *name; /* old, pre qapi */
@@ -3488,6 +3501,9 @@ QemuOptsList qemu_chardev_opts = { },{ .name = "size", .type = QEMU_OPT_SIZE, + },{ + .name = "chardev", + .type = QEMU_OPT_STRING, }, {/* end of list */ } },
@@ -3778,6 +3794,8 @@ static void register_types(void)register_char_driver_qapi ("console" ,CHARDEV_BACKEND_KIND_CONSOLE ,NULL );register_char_driver_qapi ("pipe" ,CHARDEV_BACKEND_KIND_PIPE , qemu_chr_parse_pipe); +register_char_driver_qapi ("mux" ,CHARDEV_BACKEND_KIND_MUX , + qemu_chr_parse_mux); }type_init (register_types);
Signature · 1 line
1.7.9.7
PATCH v2 12/13 qemu-char: report udb backend errors
In reply to Gerd Hoffmann--- qemu-char.c | 2 ++ 1 file changed, 2 insertions(+)
qemu-char.c +2 -0
@@ -2255,6 +2255,8 @@ static CharDriverState *qemu_chr_open_udp(QemuOpts *opts) fd =inet_dgram_opts (opts, &local_err);if (fd <0 ) { +qerror_report_err (local_err); +error_free (local_err);return NULL ; }return qemu_chr_open_udp_fd (fd);
Signature · 1 line
1.7.9.7
Quoted 3 lines · Gerd Hoffmann
Hi,
Here is v2 of the series, addressing Michaels review comments.
Thank you Gerd, applied all series to the trivial-patches queue, with two edits:
Quoted 2 lines
qemu-char: use ChardevBackendKind in in CharDriver
qemu-char: report udb backend errors
fxed these :)
/mjt
Re: [Qemu-devel] [PATCH v2 07/13] qemu-char: fix documentation for telnet+wait socket flags
In reply to Gerd HoffmannQuoted 14 lines · Gerd Hoffmann
Signed-off-by Gerd Hoffmann <[email protected]>--- qapi-schema.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)qapi-schema.json +0
-1@@ -3185,10 +3185,11 @@ # @addr: socket address to listen on (server=true) # or connect to (server=false) # @server: #optional create server socket (default: true) -# @wait: #optional wait for connect (not used for server
qapi-schema.json line 3195
Quoted 10 lines
qapi-schema.json +4
-2-# sockets, default: false) +# @wait: #optional wait for incoming connection on server +# sockets (default: false). # @nodelay: #optional set TCP_NODELAY socket option (default: false) -# @telnet: #optional enable telnet protocol (default: false) +# @telnet: #optional enable telnet protocol on server +# sockets (default: false) # # Since: 1.4 ##
Yes, both options apply only with server=true (I double-checked).
Curiously, qemu_chr_open_socket_fd() puts "telnet" into chr->filename regardless of server.
qemu_chr_open_socket() has
if (!is_listen)
is_waitconnect = 0;Should this perhaps be
if (!is_listen) {
is_waitconnect = 0;
is_telnet = 0;
}?
Quoted 5 lines · Michael Tokarev
Quoted 3 lines · Gerd Hoffmann
Hi,
Here is v2 of the series, addressing Michaels review comments.
Quoted 7 lines
Thank you Gerd, applied all series to the trivial-patches queue, with two edits:
Quoted 2 lines
qemu-char: use ChardevBackendKind in in CharDriver
qemu-char: report udb backend errorsfxed these :)
My commit message nitpicks aren't worth a respin. Perhaps you want to fix them in your tree.
Quoted 1 line · Markus Armbruster
Michael Tokarev <[email protected]> writes:
[]
Quoted 10 lines
Quoted 7 lines
Thank you Gerd, applied all series to the trivial-patches queue, with two edits:
Quoted 2 lines
qemu-char: use ChardevBackendKind in in CharDriver
qemu-char: report udb backend errorsfxed these :)
My commit message nitpicks aren't worth a respin. Perhaps you want to fix them in your tree.
I'm not sure I understand what you're saying. I fixed them in my tree while applying, and that's exactly what I said -- "applied all..fixed these". What does not worth what?
Thanks,
/mjt
Re: [Qemu-devel] [PATCH v2 02/13] qemu-socket: drop pointless allocation
In reply to Gerd HoffmannQuoted 10 lines · Gerd Hoffmann
Signed-off-by Gerd Hoffmann <[email protected]>--- util/qemu-sockets.c | 1 - 1 file changed, 1 deletion(-)util/qemu-sockets.c +0
-0
util/qemu-sockets.c SocketAddress *socket_parse(const char *str, Error **errp) · line 876
Quoted 7 lines
util/qemu-sockets.c +0
-1@@ -871,7 +871,6 @@ SocketAddress *socket_parse(const char *str, Error **errp) } }else { addr->kind =SOCKET_ADDRESS_KIND_INET ; - addr->inet =g_new (InetSocketAddress,1 ); addr->inet =inet_parse (str, errp);if (addr->inet ==NULL ) { goto fail;
Plugs a memory leak, which is a bit more than "drop pointless allocation".
Quoted 22 lines · Gerd Hoffmann
Hi,
Here is v2 of the series, addressing Michaels review comments.
cheers,
GerdGerd Hoffmann (13):
qemu-socket: zero-initialize SocketAddress
qemu-socket: drop pointless allocation
qemu-socket: catchmonitor_get_fdfailures
qemu-char: check optional fields using has_*
qemu-char: use more specific error_setg_* variants
qemu-char: print notification to stderr
qemu-char: fix documentation for telnet+wait socket flags
qemu-char: don't leak opts on error
qemu-char: use ChardevBackendKind in in CharDriver
qemu-char: minor mux chardev fixes
qemu-char: add -chardev mux support
qemu-char: report udb backend errors
qemu-socket: don't leak opts on error
Quoted 6 lines
include/sysemu/char.h | 2 +- qapi-schema.json | 7 ++++--- qemu-char.c | 45 ++++++++++++++++++++++++++++++++------------- util/qemu-sockets.c | 9 ++++----- 4 files changed, 41 insertions(+), 22 deletions(-)
I think 11/13 doesn't qualify for qemu-trivial. In any case, it does seem correct, like the rest.
With the commit message fixups from Michael: series
Thanks
Laszlo
Quoted 9 lines · Michael Tokarev
Quoted 1 line · Markus Armbruster
Michael Tokarev <[email protected]> writes:
[]
Quoted 6 lines
Quoted 6 lines
Thank you Gerd, applied all series to the trivial-patches queue, with two edits:
Quoted 2 lines
qemu-char: use ChardevBackendKind in in CharDriver
qemu-char: report udb backend errors
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
fxed these :)
My commit message nitpicks aren't worth a respin. Perhaps you want to fix them in your tree.
I'm not sure I understand what you're saying. I fixed them in my tree while applying, and that's exactly what I said -- "applied all..fixed these". What does not worth what?
I replied to 02/13 and 12/13, suggesting commit message fixes. You may have covered some of them already, I don't know.
The question I asked re 07/13 is outside the scope of this series, so don't worry about that one.
Re: [Qemu-devel] [PATCH v2 12/13] qemu-char: report udb backend errors
In reply to Gerd HoffmannTypo in subject: s/udb/UDP/
Quoted 10 lines · Gerd Hoffmann
Signed-off-by Gerd Hoffmann <[email protected]>--- qemu-char.c | 2 ++ 1 file changed, 2 insertions(+)qemu-char.c +0
-0
qemu-char.c static CharDriverState *qemu_chr_open_udp(QemuOpts *opts) · line 2262
Quoted 8 lines
qemu-char.c +2
-0@@ -2255,6 +2255,8 @@ static CharDriverState *qemu_chr_open_udp(QemuOpts *opts) fd =inet_dgram_opts (opts, &local_err);if (fd <0 ) { +qerror_report_err (local_err); +error_free (local_err);return NULL ; }return qemu_chr_open_udp_fd (fd);
Also plugs memory leak on error path. Worth mentioning in commit message.