Skip to content

Commit

Permalink
nbd: ask and print error information from qemu-sockets
Browse files Browse the repository at this point in the history
Before:

    $ qemu-system-x86_64 nbd:localhost:12345
    inet_connect_opts: connect(ipv4,yakj.usersys.redhat.com,127.0.0.1,12345): Connection refused
    qemu-system-x86_64: could not open disk image nbd:localhost:12345: Connection refused

After:

    $ x86_64-softmmu/qemu-system-x86_64 nbd:localhost:12345
    qemu-system-x86_64: Failed to connect to socket: Connection refused
    qemu-system-x86_64: could not open disk image nbd:localhost:12345: Connection refused

Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
bonzini committed Oct 23, 2012
1 parent 87d5f24 commit f8430e7
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,14 @@ int tcp_socket_outgoing(const char *address, uint16_t port)

int tcp_socket_outgoing_spec(const char *address_and_port)
{
return inet_connect(address_and_port, NULL);
Error *local_err = NULL;
int fd = inet_connect(address_and_port, &local_err);

if (local_err != NULL) {
qerror_report_err(local_err);
error_free(local_err);
}
return fd;
}

int tcp_socket_incoming(const char *address, uint16_t port)
Expand All @@ -220,22 +227,38 @@ int tcp_socket_incoming(const char *address, uint16_t port)

int tcp_socket_incoming_spec(const char *address_and_port)
{
char *ostr = NULL;
int olen = 0;
return inet_listen(address_and_port, ostr, olen, SOCK_STREAM, 0, NULL);
Error *local_err = NULL;
int fd = inet_listen(address_and_port, NULL, 0, SOCK_STREAM, 0, &local_err);

if (local_err != NULL) {
qerror_report_err(local_err);
error_free(local_err);
}
return fd;
}

int unix_socket_incoming(const char *path)
{
char *ostr = NULL;
int olen = 0;
Error *local_err = NULL;
int fd = unix_listen(path, NULL, 0, &local_err);

return unix_listen(path, ostr, olen, NULL);
if (local_err != NULL) {
qerror_report_err(local_err);
error_free(local_err);
}
return fd;
}

int unix_socket_outgoing(const char *path)
{
return unix_connect(path, NULL);
Error *local_err = NULL;
int fd = unix_connect(path, &local_err);

if (local_err != NULL) {
qerror_report_err(local_err);
error_free(local_err);
}
return fd;
}

/* Basic flow for negotiation
Expand Down

0 comments on commit f8430e7

Please sign in to comment.