From patchwork Wed Aug 7 16:05:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mrhines@linux.vnet.ibm.com X-Patchwork-Id: 265563 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9AEE02C024C for ; Thu, 8 Aug 2013 02:15:32 +1000 (EST) Received: from localhost ([::1]:50790 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V76OY-0005wG-HT for incoming@patchwork.ozlabs.org; Wed, 07 Aug 2013 12:15:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V76NH-0004Jh-E0 for qemu-devel@nongnu.org; Wed, 07 Aug 2013 12:14:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V76N8-0001Pd-EJ for qemu-devel@nongnu.org; Wed, 07 Aug 2013 12:14:11 -0400 Received: from e39.co.us.ibm.com ([32.97.110.160]:46573) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V76N8-0001PJ-6y for qemu-devel@nongnu.org; Wed, 07 Aug 2013 12:14:02 -0400 Received: from /spool/local by e39.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 7 Aug 2013 10:14:01 -0600 Received: from d01dlp03.pok.ibm.com (9.56.250.168) by e39.co.us.ibm.com (192.168.1.139) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 7 Aug 2013 10:13:59 -0600 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id EFE4CC90046 for ; Wed, 7 Aug 2013 12:13:56 -0400 (EDT) Received: from d03av06.boulder.ibm.com (d03av06.boulder.ibm.com [9.17.195.245]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r77GDvwA148226 for ; Wed, 7 Aug 2013 12:13:57 -0400 Received: from d03av06.boulder.ibm.com (loopback [127.0.0.1]) by d03av06.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r77GFjBL002372 for ; Wed, 7 Aug 2013 10:16:40 -0600 Received: from mrhinesdev.klabtestbed.com (klinux.watson.ibm.com [9.2.208.21]) by d03av06.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r77G8LX0031405; Wed, 7 Aug 2013 10:08:28 -0600 From: mrhines@linux.vnet.ibm.com To: qemu-devel@nongnu.org Date: Wed, 7 Aug 2013 12:05:30 -0400 Message-Id: <1375891530-13759-5-git-send-email-mrhines@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1375891530-13759-1-git-send-email-mrhines@linux.vnet.ibm.com> References: <1375891530-13759-1-git-send-email-mrhines@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13080716-3620-0000-0000-000003D9BCEA X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 32.97.110.160 Cc: yamahata@private.email.ne.jp, aliguori@us.ibm.com, quintela@redhat.com, owasserm@redhat.com, mrhines@us.ibm.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH for-1.6 4/4] rdma: proper getaddrinfo() handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: "Michael R. Hines" getaddrinfo() already knows what it's doing, wqand can potentially return multiple addresses. Signed-off-by: Michael R. Hines Reviewed-by: Orit Wasserman --- migration-rdma.c | 56 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/migration-rdma.c b/migration-rdma.c index 30e08cd..d71cca5 100644 --- a/migration-rdma.c +++ b/migration-rdma.c @@ -392,7 +392,6 @@ typedef struct RDMAContext { uint64_t unregistrations[RDMA_SIGNALED_SEND_MAX]; GHashTable *blockmap; - bool ipv6; } RDMAContext; /* @@ -745,7 +744,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; + struct addrinfo *e; if (rdma->host == NULL || !strcmp(rdma->host, "")) { ERROR(errp, "RDMA hostname has not been set"); @@ -775,18 +774,23 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp) goto err_resolve_get_addr; } - inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr, - ip, sizeof ip); - DPRINTF("%s => %s\n", rdma->host, ip); + for (e = res; e != NULL; e = e->ai_next) { + inet_ntop(e->ai_family, + &((struct sockaddr_in *) e->ai_addr)->sin_addr, ip, sizeof ip); + DPRINTF("Trying %s => %s\n", rdma->host, ip); - /* resolve the first address */ - ret = rdma_resolve_addr(rdma->cm_id, NULL, res->ai_addr, - RDMA_RESOLVE_TIMEOUT_MS); - if (ret) { - ERROR(errp, "could not resolve address %s", rdma->host); - goto err_resolve_get_addr; + /* resolve the first address */ + ret = rdma_resolve_addr(rdma->cm_id, NULL, e->ai_addr, + RDMA_RESOLVE_TIMEOUT_MS); + if (!ret) { + goto route; + } } + ERROR(errp, "could not resolve address %s", rdma->host); + goto err_resolve_get_addr; + +route: qemu_rdma_dump_gid("source_resolve_addr", rdma->cm_id); ret = rdma_get_cm_event(rdma->channel, &cm_event); @@ -2260,8 +2264,6 @@ 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; @@ -2292,35 +2294,36 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp) goto err_dest_init_create_listen_id; } - memset(&sin, 0, sizeof(sin)); - 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 addrinfo *e; + ret = getaddrinfo(rdma->host, port_str, NULL, &res); if (ret < 0) { ERROR(errp, "could not getaddrinfo address %s", rdma->host); goto err_dest_init_bind_addr; } + for (e = res; e != NULL; e = e->ai_next) { + inet_ntop(e->ai_family, + &((struct sockaddr_in *) e->ai_addr)->sin_addr, ip, sizeof ip); + DPRINTF("Trying %s => %s\n", rdma->host, ip); + ret = rdma_bind_addr(listen_id, e->ai_addr); + if (!ret) { + goto listen; + } + } - inet_ntop(af, &((struct sockaddr_in *) res->ai_addr)->sin_addr, - ip, sizeof ip); + ERROR(errp, "Error: could not rdma_bind_addr!"); + goto err_dest_init_bind_addr; } else { ERROR(errp, "migration host and port not specified!"); ret = -EINVAL; goto err_dest_init_bind_addr; } - - DPRINTF("%s => %s\n", rdma->host, ip); - - ret = rdma_bind_addr(listen_id, res->ai_addr); - if (ret) { - ERROR(errp, "Error: could not rdma_bind_addr!"); - goto err_dest_init_bind_addr; - } +listen: rdma->listen_id = listen_id; qemu_rdma_dump_gid("dest_init", listen_id); @@ -2351,7 +2354,6 @@ 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);