From: Amos Kong <akong@redhat.com>
To: aliguori@us.ibm.com, quintela@redhat.com, jasowang@redhat.com,
mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org,
owasserm@redhat.com
Subject: [Qemu-devel] [PATCH v12 3/4] sockets: use error class to pass listen error
Date: Fri, 11 May 2012 00:28:26 +0800 [thread overview]
Message-ID: <20120510162826.15504.17930.stgit@t> (raw)
In-Reply-To: <20120510162606.15504.39510.stgit@t>
Add a new argument in inet_listen()/inet_listen_opts()
to pass back listen error.
Change nbd, qemu-char, vnc to use new interface.
Signed-off-by: Amos Kong <akong@redhat.com>
Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
nbd.c | 2 +-
qemu-char.c | 2 +-
qemu-sockets.c | 17 ++++++++++++++---
qemu_socket.h | 4 ++--
ui/vnc.c | 3 ++-
5 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/nbd.c b/nbd.c
index bebfc49..dc0adf9 100644
--- a/nbd.c
+++ b/nbd.c
@@ -176,7 +176,7 @@ 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);
+ return inet_listen(address_and_port, ostr, olen, SOCK_STREAM, 0, NULL);
}
int unix_socket_incoming(const char *path)
diff --git a/qemu-char.c b/qemu-char.c
index 060bf9d..fe1126f 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2444,7 +2444,7 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)
}
} else {
if (is_listen) {
- fd = inet_listen_opts(opts, 0);
+ fd = inet_listen_opts(opts, 0, NULL);
} else {
fd = inet_connect_opts(opts, NULL);
}
diff --git a/qemu-sockets.c b/qemu-sockets.c
index ce3f06c..46c7619 100644
--- a/qemu-sockets.c
+++ b/qemu-sockets.c
@@ -103,7 +103,7 @@ const char *inet_strfamily(int family)
return "unknown";
}
-int inet_listen_opts(QemuOpts *opts, int port_offset)
+int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)
{
struct addrinfo ai,*res,*e;
const char *addr;
@@ -120,6 +120,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset)
if ((qemu_opt_get(opts, "host") == NULL) ||
(qemu_opt_get(opts, "port") == NULL)) {
fprintf(stderr, "%s: host and/or port not specified\n", __FUNCTION__);
+ error_set(errp, QERR_SOCKET_CREATE_FAILED);
return -1;
}
pstrcpy(port, sizeof(port), qemu_opt_get(opts, "port"));
@@ -138,6 +139,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset)
if (rc != 0) {
fprintf(stderr,"getaddrinfo(%s,%s): %s\n", addr, port,
gai_strerror(rc));
+ error_set(errp, QERR_SOCKET_CREATE_FAILED);
return -1;
}
@@ -150,6 +152,9 @@ int inet_listen_opts(QemuOpts *opts, int port_offset)
if (slisten < 0) {
fprintf(stderr,"%s: socket(%s): %s\n", __FUNCTION__,
inet_strfamily(e->ai_family), strerror(errno));
+ if (!e->ai_next) {
+ error_set(errp, QERR_SOCKET_CREATE_FAILED);
+ }
continue;
}
@@ -173,6 +178,9 @@ int inet_listen_opts(QemuOpts *opts, int port_offset)
fprintf(stderr,"%s: bind(%s,%s,%d): %s\n", __FUNCTION__,
inet_strfamily(e->ai_family), uaddr, inet_getport(e),
strerror(errno));
+ if (!e->ai_next) {
+ error_set(errp, QERR_SOCKET_BIND_FAILED);
+ }
}
}
closesocket(slisten);
@@ -183,6 +191,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset)
listen:
if (listen(slisten,1) != 0) {
+ error_set(errp, QERR_SOCKET_LISTEN_FAILED);
perror("listen");
closesocket(slisten);
freeaddrinfo(res);
@@ -446,7 +455,7 @@ static int inet_parse(QemuOpts *opts, const char *str)
}
int inet_listen(const char *str, char *ostr, int olen,
- int socktype, int port_offset)
+ int socktype, int port_offset, Error **errp)
{
QemuOpts *opts;
char *optstr;
@@ -454,7 +463,7 @@ int inet_listen(const char *str, char *ostr, int olen,
opts = qemu_opts_create(&dummy_opts, NULL, 0);
if (inet_parse(opts, str) == 0) {
- sock = inet_listen_opts(opts, port_offset);
+ sock = inet_listen_opts(opts, port_offset, errp);
if (sock != -1 && ostr) {
optstr = strchr(str, ',');
if (qemu_opt_get_bool(opts, "ipv6", 0)) {
@@ -469,6 +478,8 @@ int inet_listen(const char *str, char *ostr, int olen,
optstr ? optstr : "");
}
}
+ } else {
+ error_set(errp, QERR_SOCKET_CREATE_FAILED);
}
qemu_opts_del(opts);
return sock;
diff --git a/qemu_socket.h b/qemu_socket.h
index 26998ef..4689ff3 100644
--- a/qemu_socket.h
+++ b/qemu_socket.h
@@ -39,9 +39,9 @@ void socket_set_nonblock(int fd);
int send_all(int fd, const void *buf, int len1);
/* New, ipv6-ready socket helper functions, see qemu-sockets.c */
-int inet_listen_opts(QemuOpts *opts, int port_offset);
+int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp);
int inet_listen(const char *str, char *ostr, int olen,
- int socktype, int port_offset);
+ int socktype, int port_offset, Error **errp);
int inet_connect_opts(QemuOpts *opts, Error **errp);
int inet_connect(const char *str, bool block, Error **errp);
int inet_dgram_opts(QemuOpts *opts);
diff --git a/ui/vnc.c b/ui/vnc.c
index 3ae7704..be384a5 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -3088,7 +3088,8 @@ int vnc_display_open(DisplayState *ds, const char *display)
pstrcpy(dpy, 256, "unix:");
vs->lsock = unix_listen(display+5, dpy+5, 256-5);
} else {
- vs->lsock = inet_listen(display, dpy, 256, SOCK_STREAM, 5900);
+ vs->lsock = inet_listen(display, dpy, 256,
+ SOCK_STREAM, 5900, NULL);
}
if (-1 == vs->lsock) {
g_free(dpy);
next prev parent reply other threads:[~2012-05-10 16:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-10 16:27 [Qemu-devel] [PATCH v12 0/4] support to migrate with IPv6 address Amos Kong
2012-05-10 16:28 ` [Qemu-devel] [PATCH v12 1/4] qerror: add five qerror strings Amos Kong
2012-05-10 17:21 ` Michael Roth
2012-05-10 16:28 ` [Qemu-devel] [PATCH v12 2/4] sockets: change inet_connect() to support nonblock socket Amos Kong
2012-05-10 16:28 ` Amos Kong [this message]
2012-05-10 16:28 ` [Qemu-devel] [PATCH v12 4/4] use inet_listen()/inet_connect() to support ipv6 migration Amos Kong
2012-05-10 17:29 ` [Qemu-devel] [PATCH v12 0/4] support to migrate with IPv6 address Eric Blake
2012-05-10 18:12 ` Michael Roth
2012-05-11 6:46 ` Amos Kong
2012-05-11 12:46 ` Eric Blake
2012-05-14 15:04 ` Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120510162826.15504.17930.stgit@t \
--to=akong@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=jasowang@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=owasserm@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).