diff options
author | Daniel P. Berrangé <berrange@redhat.com> | 2024-01-04 16:29:41 +0000 |
---|---|---|
committer | Thomas Huth <thuth@redhat.com> | 2024-01-11 11:39:26 +0100 |
commit | 9cd67f0cce1887598b09b80cdeb066531102d743 (patch) | |
tree | 9705dd05571805fa193538e585b29d8342f38440 /net | |
parent | cc91ca64d826acc0214ebf9428f5130b37deecd8 (diff) | |
download | qemu-9cd67f0cce1887598b09b80cdeb066531102d743.zip qemu-9cd67f0cce1887598b09b80cdeb066531102d743.tar.gz qemu-9cd67f0cce1887598b09b80cdeb066531102d743.tar.bz2 |
net: handle QIOTask completion to report useful error message
The network stream backend uses the async QIO socket APIs for listening
and connecting sockets. It does not check the task object completion
status, however, instead just looking at whether the socket FD is -1
or not.
By checking the task completion, we can set a useful error message for
users instead of the non-actionable "connection error" string.
eg so users will see:
(qemu) info network
net: index=0,type=stream,error: Failed to connect to '/foo.unix': No such file or directory
Signed-off-by: "Daniel P. Berrangé" <berrange@redhat.com>
Message-ID: <20240104162942.211458-6-berrange@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Diffstat (limited to 'net')
-rw-r--r-- | net/stream.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/net/stream.c b/net/stream.c index 0defb21..97e6ec6 100644 --- a/net/stream.c +++ b/net/stream.c @@ -165,6 +165,7 @@ static gboolean net_stream_send(QIOChannel *ioc, s->ioc_write_tag = 0; } if (s->listener) { + qemu_set_info_str(&s->nc, "listening"); qio_net_listener_set_client_func(s->listener, net_stream_listen, s, NULL); } @@ -173,7 +174,6 @@ static gboolean net_stream_send(QIOChannel *ioc, net_socket_rs_init(&s->rs, net_stream_rs_finalize, false); s->nc.link_down = true; - qemu_set_info_str(&s->nc, "listening"); qapi_event_send_netdev_stream_disconnected(s->nc.name); net_stream_arm_reconnect(s); @@ -272,9 +272,11 @@ static void net_stream_server_listening(QIOTask *task, gpointer opaque) QIOChannelSocket *listen_sioc = QIO_CHANNEL_SOCKET(s->listen_ioc); SocketAddress *addr; int ret; + Error *err = NULL; - if (listen_sioc->fd < 0) { - qemu_set_info_str(&s->nc, "connection error"); + if (qio_task_propagate_error(task, &err)) { + qemu_set_info_str(&s->nc, "error: %s", error_get_pretty(err)); + error_free(err); return; } @@ -327,9 +329,11 @@ static void net_stream_client_connected(QIOTask *task, gpointer opaque) SocketAddress *addr; gchar *uri; int ret; + Error *err = NULL; - if (sioc->fd < 0) { - qemu_set_info_str(&s->nc, "connection error"); + if (qio_task_propagate_error(task, &err)) { + qemu_set_info_str(&s->nc, "error: %s", error_get_pretty(err)); + error_free(err); goto error; } @@ -384,6 +388,7 @@ static gboolean net_stream_reconnect(gpointer data) static void net_stream_arm_reconnect(NetStreamState *s) { if (s->reconnect && s->timer_tag == 0) { + qemu_set_info_str(&s->nc, "connecting"); s->timer_tag = g_timeout_add_seconds(s->reconnect, net_stream_reconnect, s); } |