From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1YOOIH-0002sW-4x for mharc-qemu-trivial@gnu.org; Thu, 19 Feb 2015 05:25:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOOIE-0002pU-It for qemu-trivial@nongnu.org; Thu, 19 Feb 2015 05:25:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YOOID-0007lY-CT for qemu-trivial@nongnu.org; Thu, 19 Feb 2015 05:25:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45210) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOOI7-0007cy-0j; Thu, 19 Feb 2015 05:25:07 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1JAP4Sx010877 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 19 Feb 2015 05:25:05 -0500 Received: from work-vm (ovpn-116-86.ams2.redhat.com [10.36.116.86]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t1JAP0vE016816 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Thu, 19 Feb 2015 05:25:03 -0500 Date: Thu, 19 Feb 2015 10:25:00 +0000 From: "Dr. David Alan Gilbert" To: Michael Tokarev Message-ID: <20150219102500.GA2305@work-vm> References: <1424073025-13262-1-git-send-email-mjt@msgid.tls.msk.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1424073025-13262-1-git-send-email-mjt@msgid.tls.msk.ru> User-Agent: Mutt/1.5.23 (2014-03-12) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-trivial@nongnu.org, Amit Shah , qemu-devel@nongnu.org, Juan Quintela Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH] migration/rdma: clean up qemu_rdma_dest_init a bit X-BeenThere: qemu-trivial@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Feb 2015 10:25:15 -0000 * Michael Tokarev (mjt@tls.msk.ru) wrote: > Do not check for rdma->host being empty twice. This removes a large > "if" block, so code indentation is changed. While at it, remove an > ugly goto from the loop, replacing it with a cleaner if logic. And > finally, there's no need to initialize `ret' variable since is always > has a value. This looks OK; have you got RDMA hardware to test with, if not I can give it a go. Dave > > Signed-off-by: Michael Tokarev > --- > migration/rdma.c | 51 ++++++++++++++++++++++----------------------------- > 1 file changed, 22 insertions(+), 29 deletions(-) > > diff --git a/migration/rdma.c b/migration/rdma.c > index 6bee30c..76af724 100644 > --- a/migration/rdma.c > +++ b/migration/rdma.c > @@ -2366,10 +2366,10 @@ err_rdma_source_connect: > > static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp) > { > - int ret = -EINVAL, idx; > + int ret, idx; > struct rdma_cm_id *listen_id; > char ip[40] = "unknown"; > - struct rdma_addrinfo *res; > + struct rdma_addrinfo *res, *e; > char port_str[16]; > > for (idx = 0; idx < RDMA_WRID_MAX; idx++) { > @@ -2377,7 +2377,7 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp) > rdma->wr_data[idx].control_curr = NULL; > } > > - if (rdma->host == NULL) { > + if (!rdma->host || !rdma->host[0]) { > ERROR(errp, "RDMA host is not set!"); > rdma->error_state = -EINVAL; > return -1; > @@ -2400,40 +2400,33 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp) > snprintf(port_str, 16, "%d", rdma->port); > port_str[15] = '\0'; > > - if (rdma->host && strcmp("", rdma->host)) { > - struct rdma_addrinfo *e; > + ret = rdma_getaddrinfo(rdma->host, port_str, NULL, &res); > + if (ret < 0) { > + ERROR(errp, "could not rdma_getaddrinfo address %s", rdma->host); > + goto err_dest_init_bind_addr; > + } > > - ret = rdma_getaddrinfo(rdma->host, port_str, NULL, &res); > - if (ret < 0) { > - ERROR(errp, "could not rdma_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_dst_addr)->sin_addr, ip, sizeof ip); > + trace_qemu_rdma_dest_init_trying(rdma->host, ip); > + ret = rdma_bind_addr(listen_id, e->ai_dst_addr); > + if (ret) { > + continue; > } > - > - for (e = res; e != NULL; e = e->ai_next) { > - inet_ntop(e->ai_family, > - &((struct sockaddr_in *) e->ai_dst_addr)->sin_addr, ip, sizeof ip); > - trace_qemu_rdma_dest_init_trying(rdma->host, ip); > - ret = rdma_bind_addr(listen_id, e->ai_dst_addr); > - if (!ret) { > - if (e->ai_family == AF_INET6) { > - ret = qemu_rdma_broken_ipv6_kernel(errp, listen_id->verbs); > - if (ret) { > - continue; > - } > - } > - > - goto listen; > + if (e->ai_family == AF_INET6) { > + ret = qemu_rdma_broken_ipv6_kernel(errp, listen_id->verbs); > + if (ret) { > + continue; > } > } > + break; > + } > > + if (!e) { > 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; > } > -listen: > > rdma->listen_id = listen_id; > qemu_rdma_dump_gid("dest_init", listen_id); > -- > 2.1.4 > > -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38280) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOOIC-0002mr-5T for qemu-devel@nongnu.org; Thu, 19 Feb 2015 05:25:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YOOI7-0007hN-7D for qemu-devel@nongnu.org; Thu, 19 Feb 2015 05:25:12 -0500 Date: Thu, 19 Feb 2015 10:25:00 +0000 From: "Dr. David Alan Gilbert" Message-ID: <20150219102500.GA2305@work-vm> References: <1424073025-13262-1-git-send-email-mjt@msgid.tls.msk.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1424073025-13262-1-git-send-email-mjt@msgid.tls.msk.ru> Subject: Re: [Qemu-devel] [PATCH] migration/rdma: clean up qemu_rdma_dest_init a bit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Tokarev Cc: qemu-trivial@nongnu.org, Amit Shah , qemu-devel@nongnu.org, Juan Quintela * Michael Tokarev (mjt@tls.msk.ru) wrote: > Do not check for rdma->host being empty twice. This removes a large > "if" block, so code indentation is changed. While at it, remove an > ugly goto from the loop, replacing it with a cleaner if logic. And > finally, there's no need to initialize `ret' variable since is always > has a value. This looks OK; have you got RDMA hardware to test with, if not I can give it a go. Dave > > Signed-off-by: Michael Tokarev > --- > migration/rdma.c | 51 ++++++++++++++++++++++----------------------------- > 1 file changed, 22 insertions(+), 29 deletions(-) > > diff --git a/migration/rdma.c b/migration/rdma.c > index 6bee30c..76af724 100644 > --- a/migration/rdma.c > +++ b/migration/rdma.c > @@ -2366,10 +2366,10 @@ err_rdma_source_connect: > > static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp) > { > - int ret = -EINVAL, idx; > + int ret, idx; > struct rdma_cm_id *listen_id; > char ip[40] = "unknown"; > - struct rdma_addrinfo *res; > + struct rdma_addrinfo *res, *e; > char port_str[16]; > > for (idx = 0; idx < RDMA_WRID_MAX; idx++) { > @@ -2377,7 +2377,7 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp) > rdma->wr_data[idx].control_curr = NULL; > } > > - if (rdma->host == NULL) { > + if (!rdma->host || !rdma->host[0]) { > ERROR(errp, "RDMA host is not set!"); > rdma->error_state = -EINVAL; > return -1; > @@ -2400,40 +2400,33 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp) > snprintf(port_str, 16, "%d", rdma->port); > port_str[15] = '\0'; > > - if (rdma->host && strcmp("", rdma->host)) { > - struct rdma_addrinfo *e; > + ret = rdma_getaddrinfo(rdma->host, port_str, NULL, &res); > + if (ret < 0) { > + ERROR(errp, "could not rdma_getaddrinfo address %s", rdma->host); > + goto err_dest_init_bind_addr; > + } > > - ret = rdma_getaddrinfo(rdma->host, port_str, NULL, &res); > - if (ret < 0) { > - ERROR(errp, "could not rdma_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_dst_addr)->sin_addr, ip, sizeof ip); > + trace_qemu_rdma_dest_init_trying(rdma->host, ip); > + ret = rdma_bind_addr(listen_id, e->ai_dst_addr); > + if (ret) { > + continue; > } > - > - for (e = res; e != NULL; e = e->ai_next) { > - inet_ntop(e->ai_family, > - &((struct sockaddr_in *) e->ai_dst_addr)->sin_addr, ip, sizeof ip); > - trace_qemu_rdma_dest_init_trying(rdma->host, ip); > - ret = rdma_bind_addr(listen_id, e->ai_dst_addr); > - if (!ret) { > - if (e->ai_family == AF_INET6) { > - ret = qemu_rdma_broken_ipv6_kernel(errp, listen_id->verbs); > - if (ret) { > - continue; > - } > - } > - > - goto listen; > + if (e->ai_family == AF_INET6) { > + ret = qemu_rdma_broken_ipv6_kernel(errp, listen_id->verbs); > + if (ret) { > + continue; > } > } > + break; > + } > > + if (!e) { > 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; > } > -listen: > > rdma->listen_id = listen_id; > qemu_rdma_dump_gid("dest_init", listen_id); > -- > 2.1.4 > > -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK