summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorDaniel P. Berrangé2020-09-18 11:31:45 +0200
committerDaniel P. Berrangé2020-10-29 10:57:37 +0100
commitdfc00eb7dea43bfb6d4a2ba38c4f6bc9745f3729 (patch)
treee3a211dae650c740c2f46f0c163e892e08b40280 /util
parentio: Don't use '#' flag of printf format (diff)
downloadqemu-dfc00eb7dea43bfb6d4a2ba38c4f6bc9745f3729.tar.gz
qemu-dfc00eb7dea43bfb6d4a2ba38c4f6bc9745f3729.tar.xz
qemu-dfc00eb7dea43bfb6d4a2ba38c4f6bc9745f3729.zip
util: include the target address in socket connect failures
Reporting "Failed to connect socket" is essentially useless for a user attempting to diagnose failure. It needs to include the target address details. Similarly when failing to create a socket we should include the socket family info, so the user understands what particular feature was missing in their kernel build (IPv6, VSock in particular). Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/qemu-sockets.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 05e5c73f9d..38f82179b0 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -354,15 +354,15 @@ listen_ok:
((rc) == -EINPROGRESS)
#endif
-static int inet_connect_addr(struct addrinfo *addr, Error **errp);
-
-static int inet_connect_addr(struct addrinfo *addr, Error **errp)
+static int inet_connect_addr(const InetSocketAddress *saddr,
+ struct addrinfo *addr, Error **errp)
{
int sock, rc;
sock = qemu_socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
if (sock < 0) {
- error_setg_errno(errp, errno, "Failed to create socket");
+ error_setg_errno(errp, errno, "Failed to create socket family %d",
+ addr->ai_family);
return -1;
}
socket_set_fast_reuse(sock);
@@ -376,7 +376,8 @@ static int inet_connect_addr(struct addrinfo *addr, Error **errp)
} while (rc == -EINTR);
if (rc < 0) {
- error_setg_errno(errp, errno, "Failed to connect socket");
+ error_setg_errno(errp, errno, "Failed to connect to '%s:%s'",
+ saddr->host, saddr->port);
closesocket(sock);
return -1;
}
@@ -455,7 +456,7 @@ int inet_connect_saddr(InetSocketAddress *saddr, Error **errp)
for (e = res; e != NULL; e = e->ai_next) {
error_free(local_err);
local_err = NULL;
- sock = inet_connect_addr(e, &local_err);
+ sock = inet_connect_addr(saddr, e, &local_err);
if (sock >= 0) {
break;
}
@@ -549,7 +550,8 @@ static int inet_dgram_saddr(InetSocketAddress *sraddr,
/* create socket */
sock = qemu_socket(peer->ai_family, peer->ai_socktype, peer->ai_protocol);
if (sock < 0) {
- error_setg_errno(errp, errno, "Failed to create socket");
+ error_setg_errno(errp, errno, "Failed to create socket family %d",
+ peer->ai_family);
goto err;
}
socket_set_fast_reuse(sock);
@@ -562,7 +564,8 @@ static int inet_dgram_saddr(InetSocketAddress *sraddr,
/* connect to peer */
if (connect(sock,peer->ai_addr,peer->ai_addrlen) < 0) {
- error_setg_errno(errp, errno, "Failed to connect socket");
+ error_setg_errno(errp, errno, "Failed to connect to '%s:%s'",
+ addr, port);
goto err;
}
@@ -735,13 +738,15 @@ static bool vsock_parse_vaddr_to_sockaddr(const VsockSocketAddress *vaddr,
return true;
}
-static int vsock_connect_addr(const struct sockaddr_vm *svm, Error **errp)
+static int vsock_connect_addr(const VsockSocketAddress *vaddr,
+ const struct sockaddr_vm *svm, Error **errp)
{
int sock, rc;
sock = qemu_socket(AF_VSOCK, SOCK_STREAM, 0);
if (sock < 0) {
- error_setg_errno(errp, errno, "Failed to create socket");
+ error_setg_errno(errp, errno, "Failed to create socket family %d",
+ AF_VSOCK);
return -1;
}
@@ -754,7 +759,8 @@ static int vsock_connect_addr(const struct sockaddr_vm *svm, Error **errp)
} while (rc == -EINTR);
if (rc < 0) {
- error_setg_errno(errp, errno, "Failed to connect socket");
+ error_setg_errno(errp, errno, "Failed to connect to '%s:%s'",
+ vaddr->cid, vaddr->port);
closesocket(sock);
return -1;
}
@@ -770,7 +776,7 @@ static int vsock_connect_saddr(VsockSocketAddress *vaddr, Error **errp)
return -1;
}
- return vsock_connect_addr(&svm, errp);
+ return vsock_connect_addr(vaddr, &svm, errp);
}
static int vsock_listen_saddr(VsockSocketAddress *vaddr,
@@ -994,7 +1000,7 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp)
} while (rc == -EINTR);
if (rc < 0) {
- error_setg_errno(errp, -rc, "Failed to connect socket %s",
+ error_setg_errno(errp, -rc, "Failed to connect to '%s'",
saddr->path);
goto err;
}