[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 07/17] net: handle QIOTask completion to report useful error messa
From: |
Thomas Huth |
Subject: |
[PULL 07/17] net: handle QIOTask completion to report useful error message |
Date: |
Thu, 11 Jan 2024 18:00:36 +0100 |
From: Daniel P. Berrangé <berrange@redhat.com>
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>
---
net/stream.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/net/stream.c b/net/stream.c
index 0defb21d45..97e6ec6679 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);
}
--
2.43.0
- [PULL 00/17] Misc patches (qtests, s390x, m68k, gitlab-ci), Thomas Huth, 2024/01/11
- [PULL 01/17] q800: move dp8393x_prom memory region to Q800MachineState, Thomas Huth, 2024/01/11
- [PULL 03/17] Revert "netdev: set timeout depending on loadavg", Thomas Huth, 2024/01/11
- [PULL 06/17] net: add explicit info about connecting/listening state, Thomas Huth, 2024/01/11
- [PULL 02/17] qtest: use correct boolean type for failover property, Thomas Huth, 2024/01/11
- [PULL 07/17] net: handle QIOTask completion to report useful error message,
Thomas Huth <=
- [PULL 05/17] Revert "tests/qtest/netdev-socket: Raise connection timeout to 120 seconds", Thomas Huth, 2024/01/11
- [PULL 08/17] qtest: ensure netdev-socket tests have non-overlapping names, Thomas Huth, 2024/01/11
- [PULL 04/17] Revert "osdep: add getloadavg", Thomas Huth, 2024/01/11
- [PULL 10/17] gitlab: fix s390x tag for avocado-system-centos, Thomas Huth, 2024/01/11
- [PULL 11/17] target/s390x/kvm/pv: Provide some more useful information if decryption fails, Thomas Huth, 2024/01/11
- [PULL 09/17] tests/qtest/virtio-ccw: Fix device presence checking, Thomas Huth, 2024/01/11
- [PULL 13/17] hw/s390x/ccw: Replace dirname() with g_path_get_dirname(), Thomas Huth, 2024/01/11
- [PULL 15/17] target/s390x: Fix LAE setting a wrong access register, Thomas Huth, 2024/01/11
- [PULL 14/17] scripts/checkpatch: Support codespell checking, Thomas Huth, 2024/01/11
- [PULL 12/17] hw/s390x/ccw: Replace basename() with g_path_get_basename(), Thomas Huth, 2024/01/11