Skip to contentSkip to conversation

rdma: bugfix: make IPv6 support work

PATCH Applied [email protected] 4 participants 9 messages Jul 27, 2013 – Aug 14, 2013

v1 of 3 Applied Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rdma: bugfix: make IPv6 support work

From: "Michael R. Hines" <[email protected]>

When testing with libvirt, a simple IPv6 migration test failed because we were not using getaddrinfo() properly. This makes IPv6 migration over RDMA work.

Also, we forgot to turn the DPRINTF flag off =).

---
 migration-rdma.c |   35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)
migration-rdma.c +22 -13
index d044830..3256c9b 100644
@@ -27,7 +27,7 @@
 #include <string.h>
 #include <rdma/rdma_cma.h>
 
-#define DEBUG_RDMA
+//#define DEBUG_RDMA
 //#define DEBUG_RDMA_VERBOSE
 //#define DEBUG_RDMA_REALLY_VERBOSE
 
@@ -392,6 +392,7 @@ typedef struct RDMAContext {
     uint64_t unregistrations[RDMA_SIGNALED_SEND_MAX];
 
     GHashTable *blockmap;
+    bool ipv6;
 } RDMAContext;
 
 /*
@@ -744,6 +745,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
     char port_str[16];
     struct rdma_cm_event *cm_event;
     char ip[40] = "unknown";
+    int af = rdma->ipv6 ? PF_INET6 : PF_INET;
 
     if (rdma->host == NULL || !strcmp(rdma->host, "")) {
         ERROR(errp, "RDMA hostname has not been set\n");
@@ -773,7 +775,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
         goto err_resolve_get_addr;
     }
 
-    inet_ntop(AF_INET, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
+    inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
                                 ip, sizeof ip);
     DPRINTF("%s => %s\n", rdma->host, ip);
 
@@ -2236,9 +2238,12 @@ err_rdma_source_connect:
 static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
 {
     int ret = -EINVAL, idx;
+    int af = rdma->ipv6 ? PF_INET6 : PF_INET;
     struct sockaddr_in sin;
     struct rdma_cm_id *listen_id;
     char ip[40] = "unknown";
+    struct addrinfo *res;
+    char port_str[16];
 
     for (idx = 0; idx <= RDMA_WRID_MAX; idx++) {
         rdma->wr_data[idx].control_len = 0;
@@ -2266,27 +2271,30 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
     }
 
     memset(&sin, 0, sizeof(sin));
-    sin.sin_family = AF_INET;
+    sin.sin_family = af; 
     sin.sin_port = htons(rdma->port);
+    snprintf(port_str, 16, "%d", rdma->port);
+    port_str[15] = '\0';
 
     if (rdma->host && strcmp("", rdma->host)) {
-        struct hostent *dest_addr;
-        dest_addr = gethostbyname(rdma->host);
-        if (!dest_addr) {
-            ERROR(errp, "migration could not gethostbyname!\n");
-            ret = -EINVAL;
+        ret = getaddrinfo(rdma->host, port_str, NULL, &res);
+        if (ret < 0) {
+            ERROR(errp, "could not getaddrinfo address %s\n", rdma->host);
             goto err_dest_init_bind_addr;
         }
-        memcpy(&sin.sin_addr.s_addr, dest_addr->h_addr,
-                dest_addr->h_length);
-        inet_ntop(AF_INET, dest_addr->h_addr, ip, sizeof ip);
+
+
+        inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
+                                    ip, sizeof ip);
     } else {
-        sin.sin_addr.s_addr = INADDR_ANY;
+        ERROR(errp, "migration host and port not specified!\n");
+        ret = -EINVAL;
+        goto err_dest_init_bind_addr;
     }
 
     DPRINTF("%s => %s\n", rdma->host, ip);
 
-    ret = rdma_bind_addr(listen_id, (struct sockaddr *)&sin);
+    ret = rdma_bind_addr(listen_id, res->ai_addr);
     if (ret) {
         ERROR(errp, "Error: could not rdma_bind_addr!\n");
         goto err_dest_init_bind_addr;
@@ -2321,6 +2329,7 @@ static void *qemu_rdma_data_init(const char *host_port, Error **errp)
         if (addr != NULL) {
             rdma->port = atoi(addr->port);
             rdma->host = g_strdup(addr->host);
+            rdma->ipv6 = addr->ipv6;
         } else {
             ERROR(errp, "bad RDMA migration address '%s'", host_port);
             g_free(rdma);
Signature · 1 line
1.7.10.4
#1 lore raw

Am 27.07.2013 04:23, schrieb [email protected]:

Quoted 85 lines

From: "Michael R. Hines" <[email protected]>

When testing with libvirt, a simple IPv6 migration test failed because we were not using getaddrinfo() properly. This makes IPv6 migration over RDMA work.

Also, we forgot to turn the DPRINTF flag off =).

---
 migration-rdma.c |   35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)
migration-rdma.c +13 -8
index d044830..3256c9b 100644
@@ -27,7 +27,7 @@
 #include <string.h>
 #include <rdma/rdma_cma.h>
 
-#define DEBUG_RDMA
+//#define DEBUG_RDMA
 //#define DEBUG_RDMA_VERBOSE
 //#define DEBUG_RDMA_REALLY_VERBOSE
 
@@ -392,6 +392,7 @@ typedef struct RDMAContext {
     uint64_t unregistrations[RDMA_SIGNALED_SEND_MAX];
 
     GHashTable *blockmap;
+    bool ipv6;
 } RDMAContext;
 
 /*
@@ -744,6 +745,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
     char port_str[16];
     struct rdma_cm_event *cm_event;
     char ip[40] = "unknown";
+    int af = rdma->ipv6 ? PF_INET6 : PF_INET;
 
     if (rdma->host == NULL || !strcmp(rdma->host, "")) {
         ERROR(errp, "RDMA hostname has not been set\n");
@@ -773,7 +775,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
         goto err_resolve_get_addr;
     }
 
-    inet_ntop(AF_INET, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
+    inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
                                 ip, sizeof ip);
     DPRINTF("%s => %s\n", rdma->host, ip);
 
@@ -2236,9 +2238,12 @@ err_rdma_source_connect:
 static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
 {
     int ret = -EINVAL, idx;
+    int af = rdma->ipv6 ? PF_INET6 : PF_INET;
     struct sockaddr_in sin;
     struct rdma_cm_id *listen_id;
     char ip[40] = "unknown";
+    struct addrinfo *res;
+    char port_str[16];
 
     for (idx = 0; idx <= RDMA_WRID_MAX; idx++) {
         rdma->wr_data[idx].control_len = 0;
@@ -2266,27 +2271,30 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
     }
 
     memset(&sin, 0, sizeof(sin));
-    sin.sin_family = AF_INET;
+    sin.sin_family = af; 
     sin.sin_port = htons(rdma->port);
+    snprintf(port_str, 16, "%d", rdma->port);
+    port_str[15] = '\0';
 
     if (rdma->host && strcmp("", rdma->host)) {
-        struct hostent *dest_addr;
-        dest_addr = gethostbyname(rdma->host);
-        if (!dest_addr) {
-            ERROR(errp, "migration could not gethostbyname!\n");
-            ret = -EINVAL;
+        ret = getaddrinfo(rdma->host, port_str, NULL, &res);
+        if (ret < 0) {
+            ERROR(errp, "could not getaddrinfo address %s\n", rdma->host);
             goto err_dest_init_bind_addr;
         }

migration-rdma.c static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp) · line 2290

Quoted 10 lines
migration-rdma.c +5 -4
-        memcpy(&sin.sin_addr.s_addr, dest_addr->h_addr,
-                dest_addr->h_length);
-        inet_ntop(AF_INET, dest_addr->h_addr, ip, sizeof ip);
+
+
+        inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
+                                    ip, sizeof ip);
     } else {
-        sin.sin_addr.s_addr = INADDR_ANY;
+        ERROR(errp, "migration host and port not specified!\n");

Since ERROR() appears to be operating on errp, none of them should be adding a \n.

Andreas

Quoted 20 lines
migration-rdma.c +4 -1
+        ret = -EINVAL;
+        goto err_dest_init_bind_addr;
     }
 
     DPRINTF("%s => %s\n", rdma->host, ip);
 
-    ret = rdma_bind_addr(listen_id, (struct sockaddr *)&sin);
+    ret = rdma_bind_addr(listen_id, res->ai_addr);
     if (ret) {
         ERROR(errp, "Error: could not rdma_bind_addr!\n");
         goto err_dest_init_bind_addr;
@@ -2321,6 +2329,7 @@ static void *qemu_rdma_data_init(const char *host_port, Error **errp)
         if (addr != NULL) {
             rdma->port = atoi(addr->port);
             rdma->host = g_strdup(addr->host);
+            rdma->ipv6 = addr->ipv6;
         } else {
             ERROR(errp, "bad RDMA migration address '%s'", host_port);
             g_free(rdma);
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#2 lore raw
Quoted 99 lines · Andreas Färber

Am 27.07.2013 04:23, schrieb [email protected]:

Quoted 85 lines

From: "Michael R. Hines" <[email protected]>

When testing with libvirt, a simple IPv6 migration test failed because we were not using getaddrinfo() properly. This makes IPv6 migration over RDMA work.

Also, we forgot to turn the DPRINTF flag off =).

---
  migration-rdma.c |   35 ++++++++++++++++++++++-------------
  1 file changed, 22 insertions(+), 13 deletions(-)
migration-rdma.c +13 -8
index d044830..3256c9b 100644
@@ -27,7 +27,7 @@
  #include <string.h>
  #include <rdma/rdma_cma.h>
 
-#define DEBUG_RDMA
+//#define DEBUG_RDMA
  //#define DEBUG_RDMA_VERBOSE
  //#define DEBUG_RDMA_REALLY_VERBOSE
 
@@ -392,6 +392,7 @@ typedef struct RDMAContext {
      uint64_t unregistrations[RDMA_SIGNALED_SEND_MAX];
 
      GHashTable *blockmap;
+    bool ipv6;
  } RDMAContext;
 
  /*
@@ -744,6 +745,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
      char port_str[16];
      struct rdma_cm_event *cm_event;
      char ip[40] = "unknown";
+    int af = rdma->ipv6 ? PF_INET6 : PF_INET;
 
      if (rdma->host == NULL || !strcmp(rdma->host, "")) {
          ERROR(errp, "RDMA hostname has not been set\n");
@@ -773,7 +775,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
          goto err_resolve_get_addr;
      }
 
-    inet_ntop(AF_INET, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
+    inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
                                  ip, sizeof ip);
      DPRINTF("%s => %s\n", rdma->host, ip);
 
@@ -2236,9 +2238,12 @@ err_rdma_source_connect:
  static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
  {
      int ret = -EINVAL, idx;
+    int af = rdma->ipv6 ? PF_INET6 : PF_INET;
      struct sockaddr_in sin;
      struct rdma_cm_id *listen_id;
      char ip[40] = "unknown";
+    struct addrinfo *res;
+    char port_str[16];
 
      for (idx = 0; idx <= RDMA_WRID_MAX; idx++) {
          rdma->wr_data[idx].control_len = 0;
@@ -2266,27 +2271,30 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
      }
 
      memset(&sin, 0, sizeof(sin));
-    sin.sin_family = AF_INET;
+    sin.sin_family = af;
      sin.sin_port = htons(rdma->port);
+    snprintf(port_str, 16, "%d", rdma->port);
+    port_str[15] = '\0';
 
      if (rdma->host && strcmp("", rdma->host)) {
-        struct hostent *dest_addr;
-        dest_addr = gethostbyname(rdma->host);
-        if (!dest_addr) {
-            ERROR(errp, "migration could not gethostbyname!\n");
-            ret = -EINVAL;
+        ret = getaddrinfo(rdma->host, port_str, NULL, &res);
+        if (ret < 0) {
+            ERROR(errp, "could not getaddrinfo address %s\n", rdma->host);
              goto err_dest_init_bind_addr;
          }

migration-rdma.c static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp) · line 2290

Quoted 10 lines
migration-rdma.c +5 -4
-        memcpy(&sin.sin_addr.s_addr, dest_addr->h_addr,
-                dest_addr->h_length);
-        inet_ntop(AF_INET, dest_addr->h_addr, ip, sizeof ip);
+
+
+        inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
+                                    ip, sizeof ip);
      } else {
-        sin.sin_addr.s_addr = INADDR_ANY;
+        ERROR(errp, "migration host and port not specified!\n");

Since ERROR() appears to be operating on errp, none of them should be adding a \n.

Quoted 1 line

Andreas

Acknowledged.

Quoted 21 lines
Quoted 20 lines
migration-rdma.c +4 -1
+        ret = -EINVAL;
+        goto err_dest_init_bind_addr;
      }
 
      DPRINTF("%s => %s\n", rdma->host, ip);
 
-    ret = rdma_bind_addr(listen_id, (struct sockaddr *)&sin);
+    ret = rdma_bind_addr(listen_id, res->ai_addr);
      if (ret) {
          ERROR(errp, "Error: could not rdma_bind_addr!\n");
          goto err_dest_init_bind_addr;
@@ -2321,6 +2329,7 @@ static void *qemu_rdma_data_init(const char *host_port, Error **errp)
          if (addr != NULL) {
              rdma->port = atoi(addr->port);
              rdma->host = g_strdup(addr->host);
+            rdma->ipv6 = addr->ipv6;
          } else {
              ERROR(errp, "bad RDMA migration address '%s'", host_port);
              g_free(rdma);
#3 lore raw
In reply to [email protected]
Quoted 18 lines · On 07/27/2013 05:23 AM, [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

When testing with libvirt, a simple IPv6 migration test failed because we were not using getaddrinfo() properly. This makes IPv6 migration over RDMA work.

Also, we forgot to turn the DPRINTF flag off =).

---
 migration-rdma.c |   35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)
migration-rdma.c +0 -0
index d044830..3256c9b 100644

migration-rdma.c line 30

Quoted 5 lines
migration-rdma.c +1 -1
@@ -27,7 +27,7 @@
 #include <string.h>
 #include <rdma/rdma_cma.h>
 
-#define DEBUG_RDMA
+//#define DEBUG_RDMA

Can you put this in a separate patch?

Quoted 12 lines
migration-rdma.c +1 -0
 //#define DEBUG_RDMA_VERBOSE
 //#define DEBUG_RDMA_REALLY_VERBOSE
 
@@ -392,6 +392,7 @@ typedef struct RDMAContext {
     uint64_t unregistrations[RDMA_SIGNALED_SEND_MAX];
 
     GHashTable *blockmap;
+    bool ipv6;
 } RDMAContext;
 
 /*

migration-rdma.c static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp) · line 748

Quoted 4 lines
migration-rdma.c +1 -0
@@ -744,6 +745,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
     char port_str[16];
     struct rdma_cm_event *cm_event;
     char ip[40] = "unknown";
+    int af = rdma->ipv6 ? PF_INET6 : PF_INET;

We have code that handles ipv6 in utils/qemu-sockets.c, it also handle host and port parsing please take a look at inet_parse_connect_opts. I think it can be reused here and for the destination.

Regards,
Orit

Quoted 76 lines
migration-rdma.c +19 -12
     if (rdma->host == NULL || !strcmp(rdma->host, "")) {
         ERROR(errp, "RDMA hostname has not been set\n");
@@ -773,7 +775,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
         goto err_resolve_get_addr;
     }
 
-    inet_ntop(AF_INET, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
+    inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
                                 ip, sizeof ip);
     DPRINTF("%s => %s\n", rdma->host, ip);
 
@@ -2236,9 +2238,12 @@ err_rdma_source_connect:
 static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
 {
     int ret = -EINVAL, idx;
+    int af = rdma->ipv6 ? PF_INET6 : PF_INET;
     struct sockaddr_in sin;
     struct rdma_cm_id *listen_id;
     char ip[40] = "unknown";
+    struct addrinfo *res;
+    char port_str[16];
 
     for (idx = 0; idx <= RDMA_WRID_MAX; idx++) {
         rdma->wr_data[idx].control_len = 0;
@@ -2266,27 +2271,30 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
     }
 
     memset(&sin, 0, sizeof(sin));
-    sin.sin_family = AF_INET;
+    sin.sin_family = af; 
     sin.sin_port = htons(rdma->port);
+    snprintf(port_str, 16, "%d", rdma->port);
+    port_str[15] = '\0';
 
     if (rdma->host && strcmp("", rdma->host)) {
-        struct hostent *dest_addr;
-        dest_addr = gethostbyname(rdma->host);
-        if (!dest_addr) {
-            ERROR(errp, "migration could not gethostbyname!\n");
-            ret = -EINVAL;
+        ret = getaddrinfo(rdma->host, port_str, NULL, &res);
+        if (ret < 0) {
+            ERROR(errp, "could not getaddrinfo address %s\n", rdma->host);
             goto err_dest_init_bind_addr;
         }
-        memcpy(&sin.sin_addr.s_addr, dest_addr->h_addr,
-                dest_addr->h_length);
-        inet_ntop(AF_INET, dest_addr->h_addr, ip, sizeof ip);
+
+
+        inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
+                                    ip, sizeof ip);
     } else {
-        sin.sin_addr.s_addr = INADDR_ANY;
+        ERROR(errp, "migration host and port not specified!\n");
+        ret = -EINVAL;
+        goto err_dest_init_bind_addr;
     }
 
     DPRINTF("%s => %s\n", rdma->host, ip);
 
-    ret = rdma_bind_addr(listen_id, (struct sockaddr *)&sin);
+    ret = rdma_bind_addr(listen_id, res->ai_addr);
     if (ret) {
         ERROR(errp, "Error: could not rdma_bind_addr!\n");
         goto err_dest_init_bind_addr;
@@ -2321,6 +2329,7 @@ static void *qemu_rdma_data_init(const char *host_port, Error **errp)
         if (addr != NULL) {
             rdma->port = atoi(addr->port);
             rdma->host = g_strdup(addr->host);
+            rdma->ipv6 = addr->ipv6;
         } else {
             ERROR(errp, "bad RDMA migration address '%s'", host_port);
             g_free(rdma);
#4 lore raw
Quoted 22 lines · Orit Wasserman
Quoted 21 lines · On 07/27/2013 05:23 AM, [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

When testing with libvirt, a simple IPv6 migration test failed because we were not using getaddrinfo() properly. This makes IPv6 migration over RDMA work.

Also, we forgot to turn the DPRINTF flag off =).

---
  migration-rdma.c |   35 ++++++++++++++++++++++-------------
  1 file changed, 22 insertions(+), 13 deletions(-)
migration-rdma.c +0 -0
index d044830..3256c9b 100644
@@ -27,7 +27,7 @@
  #include <string.h>
  #include <rdma/rdma_cma.h>
 
Quoted 3 lines

migration-rdma.c line 30

Quoted 2 lines
migration-rdma.c +1 -1
-#define DEBUG_RDMA
+//#define DEBUG_RDMA

Can you put this in a separate patch?

Acknowledged.

Quoted 10 lines
Quoted 10 lines
migration-rdma.c +1 -0
  //#define DEBUG_RDMA_VERBOSE
  //#define DEBUG_RDMA_REALLY_VERBOSE
 
@@ -392,6 +392,7 @@ typedef struct RDMAContext {
      uint64_t unregistrations[RDMA_SIGNALED_SEND_MAX];
 
      GHashTable *blockmap;
+    bool ipv6;
  } RDMAContext;
 
Quoted 9 lines

migration-rdma.c static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp) · line 748

Quoted 6 lines
migration-rdma.c +1 -0
  /*
@@ -744,6 +745,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
      char port_str[16];
      struct rdma_cm_event *cm_event;
      char ip[40] = "unknown";
+    int af = rdma->ipv6 ? PF_INET6 : PF_INET;

We have code that handles ipv6 in utils/qemu-sockets.c, it also handle host and port parsing please take a look at inet_parse_connect_opts. I think it can be reused here and for the destination.

RDMA cannot use that function - it creates a socket and RDMA does not use sockets.

RDMA is *already*, however, using inet_parse() which does exactly what you said.

Quoted 78 lines

Regards,
Orit

Quoted 76 lines
migration-rdma.c +19 -12
      if (rdma->host == NULL || !strcmp(rdma->host, "")) {
          ERROR(errp, "RDMA hostname has not been set\n");
@@ -773,7 +775,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
          goto err_resolve_get_addr;
      }
 
-    inet_ntop(AF_INET, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
+    inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
                                  ip, sizeof ip);
      DPRINTF("%s => %s\n", rdma->host, ip);
 
@@ -2236,9 +2238,12 @@ err_rdma_source_connect:
  static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
  {
      int ret = -EINVAL, idx;
+    int af = rdma->ipv6 ? PF_INET6 : PF_INET;
      struct sockaddr_in sin;
      struct rdma_cm_id *listen_id;
      char ip[40] = "unknown";
+    struct addrinfo *res;
+    char port_str[16];
 
      for (idx = 0; idx <= RDMA_WRID_MAX; idx++) {
          rdma->wr_data[idx].control_len = 0;
@@ -2266,27 +2271,30 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
      }
 
      memset(&sin, 0, sizeof(sin));
-    sin.sin_family = AF_INET;
+    sin.sin_family = af;
      sin.sin_port = htons(rdma->port);
+    snprintf(port_str, 16, "%d", rdma->port);
+    port_str[15] = '\0';
 
      if (rdma->host && strcmp("", rdma->host)) {
-        struct hostent *dest_addr;
-        dest_addr = gethostbyname(rdma->host);
-        if (!dest_addr) {
-            ERROR(errp, "migration could not gethostbyname!\n");
-            ret = -EINVAL;
+        ret = getaddrinfo(rdma->host, port_str, NULL, &res);
+        if (ret < 0) {
+            ERROR(errp, "could not getaddrinfo address %s\n", rdma->host);
              goto err_dest_init_bind_addr;
          }
-        memcpy(&sin.sin_addr.s_addr, dest_addr->h_addr,
-                dest_addr->h_length);
-        inet_ntop(AF_INET, dest_addr->h_addr, ip, sizeof ip);
+
+
+        inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
+                                    ip, sizeof ip);
      } else {
-        sin.sin_addr.s_addr = INADDR_ANY;
+        ERROR(errp, "migration host and port not specified!\n");
+        ret = -EINVAL;
+        goto err_dest_init_bind_addr;
      }
 
      DPRINTF("%s => %s\n", rdma->host, ip);
 
-    ret = rdma_bind_addr(listen_id, (struct sockaddr *)&sin);
+    ret = rdma_bind_addr(listen_id, res->ai_addr);
      if (ret) {
          ERROR(errp, "Error: could not rdma_bind_addr!\n");
          goto err_dest_init_bind_addr;
@@ -2321,6 +2329,7 @@ static void *qemu_rdma_data_init(const char *host_port, Error **errp)
          if (addr != NULL) {
              rdma->port = atoi(addr->port);
              rdma->host = g_strdup(addr->host);
+            rdma->ipv6 = addr->ipv6;
          } else {
              ERROR(errp, "bad RDMA migration address '%s'", host_port);
              g_free(rdma);
#5 lore raw
Quoted 45 lines · Michael R. Hines
Quoted 14 lines · Orit Wasserman
Quoted 13 lines · On 07/27/2013 05:23 AM, [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

When testing with libvirt, a simple IPv6 migration test failed because we were not using getaddrinfo() properly. This makes IPv6 migration over RDMA work.

Also, we forgot to turn the DPRINTF flag off =).

---
  migration-rdma.c |   35 ++++++++++++++++++++++-------------
  1 file changed, 22 insertions(+), 13 deletions(-)
Quoted 10 lines

migration-rdma.c line 30

Quoted 9 lines
migration-rdma.c +1 -0
index d044830..3256c9b 100644
@@ -27,7 +27,7 @@
  #include <string.h>
  #include <rdma/rdma_cma.h>
  -#define DEBUG_RDMA
+//#define DEBUG_RDMA

Can you put this in a separate patch?

Acknowledged.

Quoted 8 lines
Quoted 8 lines
migration-rdma.c +1 -0
  //#define DEBUG_RDMA_VERBOSE
  //#define DEBUG_RDMA_REALLY_VERBOSE
  @@ -392,6 +392,7 @@ typedef struct RDMAContext {
      uint64_t unregistrations[RDMA_SIGNALED_SEND_MAX];
        GHashTable *blockmap;
+    bool ipv6;
  } RDMAContext;
    /*
Quoted 8 lines

migration-rdma.c static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp) · line 748

Quoted 5 lines
migration-rdma.c +1 -0
@@ -744,6 +745,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
      char port_str[16];
      struct rdma_cm_event *cm_event;
      char ip[40] = "unknown";
+    int af = rdma->ipv6 ? PF_INET6 : PF_INET;

We have code that handles ipv6 in utils/qemu-sockets.c, it also handle host and port parsing please take a look at inet_parse_connect_opts. I think it can be reused here and for the destination.

Quoted 4 lines

RDMA cannot use that function - it creates a socket and RDMA does not use sockets.

RDMA is *already*, however, using inet_parse() which does exactly what you said.

You can update the function so it can be used for RDMA also.

Orit

Quoted 71 lines
Quoted 70 lines

Regards,
Orit

Quoted 68 lines
migration-rdma.c +19 -10
        if (rdma->host == NULL || !strcmp(rdma->host, "")) {
          ERROR(errp, "RDMA hostname has not been set\n");
@@ -773,7 +775,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
          goto err_resolve_get_addr;
      }
  -    inet_ntop(AF_INET, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
+    inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
                                  ip, sizeof ip);
      DPRINTF("%s => %s\n", rdma->host, ip);
  @@ -2236,9 +2238,12 @@ err_rdma_source_connect:
  static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
  {
      int ret = -EINVAL, idx;
+    int af = rdma->ipv6 ? PF_INET6 : PF_INET;
      struct sockaddr_in sin;
      struct rdma_cm_id *listen_id;
      char ip[40] = "unknown";
+    struct addrinfo *res;
+    char port_str[16];
        for (idx = 0; idx <= RDMA_WRID_MAX; idx++) {
          rdma->wr_data[idx].control_len = 0;
@@ -2266,27 +2271,30 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
      }
        memset(&sin, 0, sizeof(sin));
-    sin.sin_family = AF_INET;
+    sin.sin_family = af;
      sin.sin_port = htons(rdma->port);
+    snprintf(port_str, 16, "%d", rdma->port);
+    port_str[15] = '\0';
        if (rdma->host && strcmp("", rdma->host)) {
-        struct hostent *dest_addr;
-        dest_addr = gethostbyname(rdma->host);
-        if (!dest_addr) {
-            ERROR(errp, "migration could not gethostbyname!\n");
-            ret = -EINVAL;
+        ret = getaddrinfo(rdma->host, port_str, NULL, &res);
+        if (ret < 0) {
+            ERROR(errp, "could not getaddrinfo address %s\n", rdma->host);
              goto err_dest_init_bind_addr;
          }
-        memcpy(&sin.sin_addr.s_addr, dest_addr->h_addr,
-                dest_addr->h_length);
-        inet_ntop(AF_INET, dest_addr->h_addr, ip, sizeof ip);
+
+
+        inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
+                                    ip, sizeof ip);
      } else {
-        sin.sin_addr.s_addr = INADDR_ANY;
+        ERROR(errp, "migration host and port not specified!\n");
+        ret = -EINVAL;
+        goto err_dest_init_bind_addr;
      }
        DPRINTF("%s => %s\n", rdma->host, ip);
  -    ret = rdma_bind_addr(listen_id, (struct sockaddr *)&sin);
+    ret = rdma_bind_addr(listen_id, res->ai_addr);
      if (ret) {
          ERROR(errp, "Error: could not rdma_bind_addr!\n");
          goto err_dest_init_bind_addr;
@@ -2321,6 +2329,7 @@ static void *qemu_rdma_data_init(const char *host_port, Error **errp)
          if (addr != NULL) {
              rdma->port = atoi(addr->port);
              rdma->host = g_strdup(addr->host);
+            rdma->ipv6 = addr->ipv6;
          } else {
              ERROR(errp, "bad RDMA migration address '%s'", host_port);
              g_free(rdma);
#6 lore raw
Quoted 44 lines · Orit Wasserman
Quoted 43 lines · Michael R. Hines
Quoted 14 lines · Orit Wasserman
Quoted 13 lines · On 07/27/2013 05:23 AM, [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

When testing with libvirt, a simple IPv6 migration test failed because we were not using getaddrinfo() properly. This makes IPv6 migration over RDMA work.

Also, we forgot to turn the DPRINTF flag off =).

---
   migration-rdma.c |   35 ++++++++++++++++++++++-------------
   1 file changed, 22 insertions(+), 13 deletions(-)
Quoted 10 lines

migration-rdma.c line 30

Quoted 9 lines
migration-rdma.c +1 -0
index d044830..3256c9b 100644
@@ -27,7 +27,7 @@
   #include <string.h>
   #include <rdma/rdma_cma.h>
   -#define DEBUG_RDMA
+//#define DEBUG_RDMA

Can you put this in a separate patch?

Acknowledged.

Quoted 16 lines

migration-rdma.c static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp) · line 748

Quoted 13 lines
migration-rdma.c +2 -0
   //#define DEBUG_RDMA_VERBOSE
   //#define DEBUG_RDMA_REALLY_VERBOSE
   @@ -392,6 +392,7 @@ typedef struct RDMAContext {
       uint64_t unregistrations[RDMA_SIGNALED_SEND_MAX];
         GHashTable *blockmap;
+    bool ipv6;
   } RDMAContext;
     /*
@@ -744,6 +745,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
       char port_str[16];
       struct rdma_cm_event *cm_event;
       char ip[40] = "unknown";
+    int af = rdma->ipv6 ? PF_INET6 : PF_INET;

We have code that handles ipv6 in utils/qemu-sockets.c, it also handle host and port parsing please take a look at inet_parse_connect_opts. I think it can be reused here and for the destination.

Quoted 5 lines
Quoted 4 lines

RDMA cannot use that function - it creates a socket and RDMA does not use sockets.

RDMA is *already*, however, using inet_parse() which does exactly what you said.

You can update the function so it can be used for RDMA also.

The inet_parse() function does everything that we need - it already understands IPv6 without opening an actual socket.

Any more than that would require CONFIG_RDMA to be conditionalized inside of the utils/ source code, and that seems like a lot of work for such a small reward.

- Michael

Quoted 72 lines

Orit

Quoted 70 lines
Quoted 70 lines

Regards,
Orit

Quoted 68 lines
migration-rdma.c +19 -10
         if (rdma->host == NULL || !strcmp(rdma->host, "")) {
           ERROR(errp, "RDMA hostname has not been set\n");
@@ -773,7 +775,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
           goto err_resolve_get_addr;
       }
   -    inet_ntop(AF_INET, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
+    inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
                                   ip, sizeof ip);
       DPRINTF("%s => %s\n", rdma->host, ip);
   @@ -2236,9 +2238,12 @@ err_rdma_source_connect:
   static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
   {
       int ret = -EINVAL, idx;
+    int af = rdma->ipv6 ? PF_INET6 : PF_INET;
       struct sockaddr_in sin;
       struct rdma_cm_id *listen_id;
       char ip[40] = "unknown";
+    struct addrinfo *res;
+    char port_str[16];
         for (idx = 0; idx <= RDMA_WRID_MAX; idx++) {
           rdma->wr_data[idx].control_len = 0;
@@ -2266,27 +2271,30 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
       }
         memset(&sin, 0, sizeof(sin));
-    sin.sin_family = AF_INET;
+    sin.sin_family = af;
       sin.sin_port = htons(rdma->port);
+    snprintf(port_str, 16, "%d", rdma->port);
+    port_str[15] = '\0';
         if (rdma->host && strcmp("", rdma->host)) {
-        struct hostent *dest_addr;
-        dest_addr = gethostbyname(rdma->host);
-        if (!dest_addr) {
-            ERROR(errp, "migration could not gethostbyname!\n");
-            ret = -EINVAL;
+        ret = getaddrinfo(rdma->host, port_str, NULL, &res);
+        if (ret < 0) {
+            ERROR(errp, "could not getaddrinfo address %s\n", rdma->host);
               goto err_dest_init_bind_addr;
           }
-        memcpy(&sin.sin_addr.s_addr, dest_addr->h_addr,
-                dest_addr->h_length);
-        inet_ntop(AF_INET, dest_addr->h_addr, ip, sizeof ip);
+
+
+        inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
+                                    ip, sizeof ip);
       } else {
-        sin.sin_addr.s_addr = INADDR_ANY;
+        ERROR(errp, "migration host and port not specified!\n");
+        ret = -EINVAL;
+        goto err_dest_init_bind_addr;
       }
         DPRINTF("%s => %s\n", rdma->host, ip);
   -    ret = rdma_bind_addr(listen_id, (struct sockaddr *)&sin);
+    ret = rdma_bind_addr(listen_id, res->ai_addr);
       if (ret) {
           ERROR(errp, "Error: could not rdma_bind_addr!\n");
           goto err_dest_init_bind_addr;
@@ -2321,6 +2329,7 @@ static void *qemu_rdma_data_init(const char *host_port, Error **errp)
           if (addr != NULL) {
               rdma->port = atoi(addr->port);
               rdma->host = g_strdup(addr->host);
+            rdma->ipv6 = addr->ipv6;
           } else {
               ERROR(errp, "bad RDMA migration address '%s'", host_port);
               g_free(rdma);
#7 lore raw
Quoted 49 lines · Michael R. Hines
Quoted 48 lines · Orit Wasserman
Quoted 47 lines · Michael R. Hines
Quoted 14 lines · Orit Wasserman
Quoted 13 lines · On 07/27/2013 05:23 AM, [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

When testing with libvirt, a simple IPv6 migration test failed because we were not using getaddrinfo() properly. This makes IPv6 migration over RDMA work.

Also, we forgot to turn the DPRINTF flag off =).

---
   migration-rdma.c |   35 ++++++++++++++++++++++-------------
   1 file changed, 22 insertions(+), 13 deletions(-)
Quoted 10 lines

migration-rdma.c line 30

Quoted 9 lines
migration-rdma.c +1 -0
index d044830..3256c9b 100644
@@ -27,7 +27,7 @@
   #include <string.h>
   #include <rdma/rdma_cma.h>
   -#define DEBUG_RDMA
+//#define DEBUG_RDMA

Can you put this in a separate patch?

Acknowledged.

Quoted 8 lines
Quoted 8 lines
migration-rdma.c +1 -0
   //#define DEBUG_RDMA_VERBOSE
   //#define DEBUG_RDMA_REALLY_VERBOSE
   @@ -392,6 +392,7 @@ typedef struct RDMAContext {
       uint64_t unregistrations[RDMA_SIGNALED_SEND_MAX];
         GHashTable *blockmap;
+    bool ipv6;
   } RDMAContext;
     /*
Quoted 8 lines

migration-rdma.c static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp) · line 748

Quoted 5 lines
migration-rdma.c +1 -0
@@ -744,6 +745,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
       char port_str[16];
       struct rdma_cm_event *cm_event;
       char ip[40] = "unknown";
+    int af = rdma->ipv6 ? PF_INET6 : PF_INET;

We have code that handles ipv6 in utils/qemu-sockets.c, it also handle host and port parsing please take a look at inet_parse_connect_opts. I think it can be reused here and for the destination.

RDMA cannot use that function - it creates a socket and RDMA does not use sockets.

RDMA is *already*, however, using inet_parse() which does exactly what you said.

Quoted 9 lines
Quoted 1 line

You can update the function so it can be used for RDMA also.

The inet_parse() function does everything that we need - it already understands IPv6 without opening an actual socket.

Any more than that would require CONFIG_RDMA to be conditionalized inside of the utils/ source code, and that seems like a lot of work for such a small reward.

Agreed,
Orit

Quoted 75 lines

- Michael

Quoted 72 lines

Orit

Quoted 70 lines
Quoted 70 lines

Regards,
Orit

Quoted 68 lines
migration-rdma.c +19 -10
         if (rdma->host == NULL || !strcmp(rdma->host, "")) {
           ERROR(errp, "RDMA hostname has not been set\n");
@@ -773,7 +775,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
           goto err_resolve_get_addr;
       }
   -    inet_ntop(AF_INET, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
+    inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
                                   ip, sizeof ip);
       DPRINTF("%s => %s\n", rdma->host, ip);
   @@ -2236,9 +2238,12 @@ err_rdma_source_connect:
   static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
   {
       int ret = -EINVAL, idx;
+    int af = rdma->ipv6 ? PF_INET6 : PF_INET;
       struct sockaddr_in sin;
       struct rdma_cm_id *listen_id;
       char ip[40] = "unknown";
+    struct addrinfo *res;
+    char port_str[16];
         for (idx = 0; idx <= RDMA_WRID_MAX; idx++) {
           rdma->wr_data[idx].control_len = 0;
@@ -2266,27 +2271,30 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
       }
         memset(&sin, 0, sizeof(sin));
-    sin.sin_family = AF_INET;
+    sin.sin_family = af;
       sin.sin_port = htons(rdma->port);
+    snprintf(port_str, 16, "%d", rdma->port);
+    port_str[15] = '\0';
         if (rdma->host && strcmp("", rdma->host)) {
-        struct hostent *dest_addr;
-        dest_addr = gethostbyname(rdma->host);
-        if (!dest_addr) {
-            ERROR(errp, "migration could not gethostbyname!\n");
-            ret = -EINVAL;
+        ret = getaddrinfo(rdma->host, port_str, NULL, &res);
+        if (ret < 0) {
+            ERROR(errp, "could not getaddrinfo address %s\n", rdma->host);
               goto err_dest_init_bind_addr;
           }
-        memcpy(&sin.sin_addr.s_addr, dest_addr->h_addr,
-                dest_addr->h_length);
-        inet_ntop(AF_INET, dest_addr->h_addr, ip, sizeof ip);
+
+
+        inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr,
+                                    ip, sizeof ip);
       } else {
-        sin.sin_addr.s_addr = INADDR_ANY;
+        ERROR(errp, "migration host and port not specified!\n");
+        ret = -EINVAL;
+        goto err_dest_init_bind_addr;
       }
         DPRINTF("%s => %s\n", rdma->host, ip);
   -    ret = rdma_bind_addr(listen_id, (struct sockaddr *)&sin);
+    ret = rdma_bind_addr(listen_id, res->ai_addr);
       if (ret) {
           ERROR(errp, "Error: could not rdma_bind_addr!\n");
           goto err_dest_init_bind_addr;
@@ -2321,6 +2329,7 @@ static void *qemu_rdma_data_init(const char *host_port, Error **errp)
           if (addr != NULL) {
               rdma->port = atoi(addr->port);
               rdma->host = g_strdup(addr->host);
+            rdma->ipv6 = addr->ipv6;
           } else {
               ERROR(errp, "bad RDMA migration address '%s'", host_port);
               g_free(rdma);