9ae3a8
From e61f1896870d99e21879b95f538b15114d65e9d0 Mon Sep 17 00:00:00 2001
9ae3a8
Message-Id: <e61f1896870d99e21879b95f538b15114d65e9d0.1387382496.git.minovotn@redhat.com>
9ae3a8
In-Reply-To: <c5386144fbf09f628148101bc674e2421cdd16e3.1387382496.git.minovotn@redhat.com>
9ae3a8
References: <c5386144fbf09f628148101bc674e2421cdd16e3.1387382496.git.minovotn@redhat.com>
9ae3a8
From: Nigel Croxon <ncroxon@redhat.com>
9ae3a8
Date: Thu, 14 Nov 2013 22:52:56 +0100
9ae3a8
Subject: [PATCH 20/46] rdma: bugfix: make IPv6 support work
9ae3a8
9ae3a8
RH-Author: Nigel Croxon <ncroxon@redhat.com>
9ae3a8
Message-id: <1384469598-13137-21-git-send-email-ncroxon@redhat.com>
9ae3a8
Patchwork-id: 55725
9ae3a8
O-Subject: [RHEL7.0 PATCH 20/42] rdma: bugfix: make IPv6 support work
9ae3a8
Bugzilla: 1011720
9ae3a8
RH-Acked-by: Orit Wasserman <owasserm@redhat.com>
9ae3a8
RH-Acked-by: Amit Shah <amit.shah@redhat.com>
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
9ae3a8
Bugzilla: 1011720
9ae3a8
https://bugzilla.redhat.com/show_bug.cgi?id=1011720
9ae3a8
9ae3a8
>From commit ID:
9ae3a8
commit b58c8552bd466aaab67c59dedeb846838082cad6
9ae3a8
Author: Michael R. Hines <mrhines@us.ibm.com>
9ae3a8
Date:   Sat Aug 3 22:54:48 2013 -0400
9ae3a8
9ae3a8
    rdma: bugfix: make IPv6 support work
9ae3a8
9ae3a8
    RDMA does not use sockets, so we cannot use many of the socket
9ae3a8
    helper functions, but we *do* use inet_parse() which gives
9ae3a8
    RDMA all the necessary details of the connection parameters.
9ae3a8
9ae3a8
    However, when testing with libvirt, a simple IPv6 migration test failed
9ae3a8
    because we were not using getaddrinfo() properly.
9ae3a8
9ae3a8
    This makes IPv6 migration over RDMA work.
9ae3a8
9ae3a8
    Signed-off-by: Michael R. Hines <mrhines@us.ibm.com>
9ae3a8
    Message-id: 1375584894-9917-2-git-send-email-mrhines@linux.vnet.ibm.com
9ae3a8
    Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
9ae3a8
---
9ae3a8
 migration-rdma.c |   33 +++++++++++++++++++++------------
9ae3a8
 1 files changed, 21 insertions(+), 12 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Michal Novotny <minovotn@redhat.com>
9ae3a8
---
9ae3a8
 migration-rdma.c | 33 +++++++++++++++++++++------------
9ae3a8
 1 file changed, 21 insertions(+), 12 deletions(-)
9ae3a8
9ae3a8
diff --git a/migration-rdma.c b/migration-rdma.c
9ae3a8
index d044830..9cf73e3 100644
9ae3a8
--- a/migration-rdma.c
9ae3a8
+++ b/migration-rdma.c
9ae3a8
@@ -392,6 +392,7 @@ typedef struct RDMAContext {
9ae3a8
     uint64_t unregistrations[RDMA_SIGNALED_SEND_MAX];
9ae3a8
 
9ae3a8
     GHashTable *blockmap;
9ae3a8
+    bool ipv6;
9ae3a8
 } RDMAContext;
9ae3a8
 
9ae3a8
 /*
9ae3a8
@@ -744,6 +745,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
9ae3a8
     char port_str[16];
9ae3a8
     struct rdma_cm_event *cm_event;
9ae3a8
     char ip[40] = "unknown";
9ae3a8
+    int af = rdma->ipv6 ? PF_INET6 : PF_INET;
9ae3a8
 
9ae3a8
     if (rdma->host == NULL || !strcmp(rdma->host, "")) {
9ae3a8
         ERROR(errp, "RDMA hostname has not been set\n");
9ae3a8
@@ -773,7 +775,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
9ae3a8
         goto err_resolve_get_addr;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    inet_ntop(AF_INET, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
9ae3a8
+    inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
9ae3a8
                                 ip, sizeof ip);
9ae3a8
     DPRINTF("%s => %s\n", rdma->host, ip);
9ae3a8
 
9ae3a8
@@ -2236,9 +2238,12 @@ err_rdma_source_connect:
9ae3a8
 static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
9ae3a8
 {
9ae3a8
     int ret = -EINVAL, idx;
9ae3a8
+    int af = rdma->ipv6 ? PF_INET6 : PF_INET;
9ae3a8
     struct sockaddr_in sin;
9ae3a8
     struct rdma_cm_id *listen_id;
9ae3a8
     char ip[40] = "unknown";
9ae3a8
+    struct addrinfo *res;
9ae3a8
+    char port_str[16];
9ae3a8
 
9ae3a8
     for (idx = 0; idx <= RDMA_WRID_MAX; idx++) {
9ae3a8
         rdma->wr_data[idx].control_len = 0;
9ae3a8
@@ -2266,27 +2271,30 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
9ae3a8
     }
9ae3a8
 
9ae3a8
     memset(&sin, 0, sizeof(sin));
9ae3a8
-    sin.sin_family = AF_INET;
9ae3a8
+    sin.sin_family = af;
9ae3a8
     sin.sin_port = htons(rdma->port);
9ae3a8
+    snprintf(port_str, 16, "%d", rdma->port);
9ae3a8
+    port_str[15] = '\0';
9ae3a8
 
9ae3a8
     if (rdma->host && strcmp("", rdma->host)) {
9ae3a8
-        struct hostent *dest_addr;
9ae3a8
-        dest_addr = gethostbyname(rdma->host);
9ae3a8
-        if (!dest_addr) {
9ae3a8
-            ERROR(errp, "migration could not gethostbyname!\n");
9ae3a8
-            ret = -EINVAL;
9ae3a8
+        ret = getaddrinfo(rdma->host, port_str, NULL, &res;;
9ae3a8
+        if (ret < 0) {
9ae3a8
+            ERROR(errp, "could not getaddrinfo address %s\n", rdma->host);
9ae3a8
             goto err_dest_init_bind_addr;
9ae3a8
         }
9ae3a8
-        memcpy(&sin.sin_addr.s_addr, dest_addr->h_addr,
9ae3a8
-                dest_addr->h_length);
9ae3a8
-        inet_ntop(AF_INET, dest_addr->h_addr, ip, sizeof ip);
9ae3a8
+
9ae3a8
+
9ae3a8
+        inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
9ae3a8
+                                    ip, sizeof ip);
9ae3a8
     } else {
9ae3a8
-        sin.sin_addr.s_addr = INADDR_ANY;
9ae3a8
+        ERROR(errp, "migration host and port not specified!\n");
9ae3a8
+        ret = -EINVAL;
9ae3a8
+        goto err_dest_init_bind_addr;
9ae3a8
     }
9ae3a8
 
9ae3a8
     DPRINTF("%s => %s\n", rdma->host, ip);
9ae3a8
 
9ae3a8
-    ret = rdma_bind_addr(listen_id, (struct sockaddr *)&sin;;
9ae3a8
+    ret = rdma_bind_addr(listen_id, res->ai_addr);
9ae3a8
     if (ret) {
9ae3a8
         ERROR(errp, "Error: could not rdma_bind_addr!\n");
9ae3a8
         goto err_dest_init_bind_addr;
9ae3a8
@@ -2321,6 +2329,7 @@ static void *qemu_rdma_data_init(const char *host_port, Error **errp)
9ae3a8
         if (addr != NULL) {
9ae3a8
             rdma->port = atoi(addr->port);
9ae3a8
             rdma->host = g_strdup(addr->host);
9ae3a8
+            rdma->ipv6 = addr->ipv6;
9ae3a8
         } else {
9ae3a8
             ERROR(errp, "bad RDMA migration address '%s'", host_port);
9ae3a8
             g_free(rdma);
9ae3a8
-- 
9ae3a8
1.7.11.7
9ae3a8