thebeanogamer / rpms / qemu-kvm

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