diff options
author | Daniel P. Berrangé <berrange@redhat.com> | 2020-09-18 10:31:45 +0100 |
---|---|---|
committer | Daniel P. Berrangé <berrange@redhat.com> | 2020-10-29 09:57:37 +0000 |
commit | dfc00eb7dea43bfb6d4a2ba38c4f6bc9745f3729 (patch) | |
tree | e3a211dae650c740c2f46f0c163e892e08b40280 /util | |
parent | 77b7829e755aec2f74601190a4521617b6dab49c (diff) | |
download | qemu-dfc00eb7dea43bfb6d4a2ba38c4f6bc9745f3729.zip qemu-dfc00eb7dea43bfb6d4a2ba38c4f6bc9745f3729.tar.gz qemu-dfc00eb7dea43bfb6d4a2ba38c4f6bc9745f3729.tar.bz2 |
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.c | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 05e5c73..38f8217 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; } |