Patchwork [16/34] migration: don't rely on QERR_SOCKET_*

login
register
mail settings
Submitter Luiz Capitulino
Date Aug. 2, 2012, 1:02 a.m.
Message ID <1343869374-23417-17-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/174667/
State New
Headers show

Comments

Luiz Capitulino - Aug. 2, 2012, 1:02 a.m.
Use the error code returned by inet_connect() instead. This change
is needed because all QERR_SOCKET_* errors are going to be dropped
by a future commit.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 migration-tcp.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

Patch

diff --git a/migration-tcp.c b/migration-tcp.c
index 18944a4..7fe0ffe 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -82,27 +82,33 @@  static void tcp_wait_for_connect(void *opaque)
 int tcp_start_outgoing_migration(MigrationState *s, const char *host_port,
                                  Error **errp)
 {
+    bool in_progress;
+
     s->get_error = socket_errno;
     s->write = socket_write;
     s->close = tcp_close;
 
-    s->fd = inet_connect(host_port, false, NULL, errp);
+    s->fd = inet_connect(host_port, false, &in_progress, errp);
+    if (s->fd < 0) {
+        switch (s->fd) {
+        case -EINVAL:
+            DPRINTF("connect failed\n");
+            return -1;
+        case -ENOTCONN:
+            DPRINTF("connect failed\n");
+            migrate_fd_error(s);
+            return -1;
+        default:
+            DPRINTF("unknown error\n");
+            return -1;
+        }
+    }
 
-    if (!error_is_set(errp)) {
-        migrate_fd_connect(s);
-    } else if (error_is_type(*errp, QERR_SOCKET_CONNECT_IN_PROGRESS)) {
-        DPRINTF("connect in progress\n");
+    if (in_progress) {
         qemu_set_fd_handler2(s->fd, NULL, NULL, tcp_wait_for_connect, s);
-    } else if (error_is_type(*errp, QERR_SOCKET_CREATE_FAILED)) {
-        DPRINTF("connect failed\n");
-        return -1;
-    } else if (error_is_type(*errp, QERR_SOCKET_CONNECT_FAILED)) {
-        DPRINTF("connect failed\n");
-        migrate_fd_error(s);
-        return -1;
     } else {
-        DPRINTF("unknown error\n");
-        return -1;
+        /* connected */
+        migrate_fd_connect(s);
     }
 
     return 0;