[Qemu-devel] [PATCH v4 3/6] migration/rdma: fix qemu_rdma_block_for_wrid error paths

Dr. David Alan Gilbert (git) posted 6 patches 8 years, 6 months ago
[Qemu-devel] [PATCH v4 3/6] migration/rdma: fix qemu_rdma_block_for_wrid error paths
Posted by Dr. David Alan Gilbert (git) 8 years, 6 months ago
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

The two places that 'goto err_block_for_wrid' weren't setting ret
and so would end up returning 0 even though we've failed.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 migration/rdma.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/migration/rdma.c b/migration/rdma.c
index 6111e10c70..59810aec2e 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -1521,14 +1521,16 @@ static int qemu_rdma_block_for_wrid(RDMAContext *rdma, int wrid_requested,
             yield_until_fd_readable(rdma->comp_channel->fd);
         }
 
-        if (ibv_get_cq_event(rdma->comp_channel, &cq, &cq_ctx)) {
+        ret = ibv_get_cq_event(rdma->comp_channel, &cq, &cq_ctx);
+        if (ret) {
             perror("ibv_get_cq_event");
             goto err_block_for_wrid;
         }
 
         num_cq_events++;
 
-        if (ibv_req_notify_cq(cq, 0)) {
+        ret = -ibv_req_notify_cq(cq, 0);
+        if (ret) {
             goto err_block_for_wrid;
         }
 
@@ -1564,6 +1566,8 @@ err_block_for_wrid:
     if (num_cq_events) {
         ibv_ack_cq_events(cq, num_cq_events);
     }
+
+    rdma->error_state = ret;
     return ret;
 }
 
-- 
2.13.0


Re: [Qemu-devel] [PATCH v4 3/6] migration/rdma: fix qemu_rdma_block_for_wrid error paths
Posted by Peter Xu 8 years, 6 months ago
On Mon, Jul 17, 2017 at 12:09:33PM +0100, Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> 
> The two places that 'goto err_block_for_wrid' weren't setting ret
> and so would end up returning 0 even though we've failed.
> 
> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
>  migration/rdma.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/migration/rdma.c b/migration/rdma.c
> index 6111e10c70..59810aec2e 100644
> --- a/migration/rdma.c
> +++ b/migration/rdma.c
> @@ -1521,14 +1521,16 @@ static int qemu_rdma_block_for_wrid(RDMAContext *rdma, int wrid_requested,
>              yield_until_fd_readable(rdma->comp_channel->fd);
>          }
>  
> -        if (ibv_get_cq_event(rdma->comp_channel, &cq, &cq_ctx)) {
> +        ret = ibv_get_cq_event(rdma->comp_channel, &cq, &cq_ctx);
> +        if (ret) {
>              perror("ibv_get_cq_event");
>              goto err_block_for_wrid;
>          }
>  
>          num_cq_events++;
>  
> -        if (ibv_req_notify_cq(cq, 0)) {
> +        ret = -ibv_req_notify_cq(cq, 0);

(I didn't really notice that it is returning a positive value for
 error...)

Reviewed-by: Peter Xu <peterx@redhat.com>

> +        if (ret) {
>              goto err_block_for_wrid;
>          }
>  
> @@ -1564,6 +1566,8 @@ err_block_for_wrid:
>      if (num_cq_events) {
>          ibv_ack_cq_events(cq, num_cq_events);
>      }
> +
> +    rdma->error_state = ret;
>      return ret;
>  }
>  
> -- 
> 2.13.0
> 

-- 
Peter Xu

Re: [Qemu-devel] [PATCH v4 3/6] migration/rdma: fix qemu_rdma_block_for_wrid error paths
Posted by Dr. David Alan Gilbert 8 years, 6 months ago
* Peter Xu (peterx@redhat.com) wrote:
> On Mon, Jul 17, 2017 at 12:09:33PM +0100, Dr. David Alan Gilbert (git) wrote:
> > From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> > 
> > The two places that 'goto err_block_for_wrid' weren't setting ret
> > and so would end up returning 0 even though we've failed.
> > 
> > Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> > ---
> >  migration/rdma.c | 8 ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> > 
> > diff --git a/migration/rdma.c b/migration/rdma.c
> > index 6111e10c70..59810aec2e 100644
> > --- a/migration/rdma.c
> > +++ b/migration/rdma.c
> > @@ -1521,14 +1521,16 @@ static int qemu_rdma_block_for_wrid(RDMAContext *rdma, int wrid_requested,
> >              yield_until_fd_readable(rdma->comp_channel->fd);
> >          }
> >  
> > -        if (ibv_get_cq_event(rdma->comp_channel, &cq, &cq_ctx)) {
> > +        ret = ibv_get_cq_event(rdma->comp_channel, &cq, &cq_ctx);
> > +        if (ret) {
> >              perror("ibv_get_cq_event");
> >              goto err_block_for_wrid;
> >          }
> >  
> >          num_cq_events++;
> >  
> > -        if (ibv_req_notify_cq(cq, 0)) {
> > +        ret = -ibv_req_notify_cq(cq, 0);
> 
> (I didn't really notice that it is returning a positive value for
>  error...)

Yes, the manpage said that and I followed it into the source to check;
none of the ibv interfaces are in any way consistent.

From the manpage:
   ibv_get_cq_event() returns 0 on success, and -1 on error.
   ibv_ack_cq_events() returns no value.
   ibv_req_notify_cq() returns 0 on success, or the value of errno on failure

   etc

(and -1 will do as a ret value if we havent got a real errno)

Dave

> Reviewed-by: Peter Xu <peterx@redhat.com>
> 
> > +        if (ret) {
> >              goto err_block_for_wrid;
> >          }
> >  
> > @@ -1564,6 +1566,8 @@ err_block_for_wrid:
> >      if (num_cq_events) {
> >          ibv_ack_cq_events(cq, num_cq_events);
> >      }
> > +
> > +    rdma->error_state = ret;
> >      return ret;
> >  }
> >  
> > -- 
> > 2.13.0
> > 
> 
> -- 
> Peter Xu
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK