Skip to content

Commit

Permalink
migration/rdma: Fix io_writev(), io_readv() methods to obey contract
Browse files Browse the repository at this point in the history
QIOChannelClass methods qio_channel_rdma_readv() and
qio_channel_rdma_writev() violate their method contract when
rdma->error_state is non-zero:

1. They return whatever is in rdma->error_state then.  Only -1 will be
   fine.  -2 will be misinterpreted as "would block".  Anything less
   than -2 isn't defined in the contract.  A positive value would be
   misinterpreted as success, but I believe that's not actually
   possible.

2. They neglect to set an error then.  If something up the call stack
   dereferences the error when failure is returned, it will crash.  If
   it ignores the return value and checks the error instead, it will
   miss the error.

Crap like this happens when return statements hide in macros,
especially when their uses are far away from the definition.

I elected not to investigate how callers are impacted.

Expand the two bad macro uses, so we can set an error and return -1.
The next commit will then get rid of the macro altogether.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: Li Zhijian <lizhijian@fujitsu.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Message-ID: <20230928132019.2544702-19-armbru@redhat.com>
  • Loading branch information
Markus Armbruster authored and Juan Quintela committed Oct 11, 2023
1 parent 1b6e1da commit 8e262e0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions migration/rdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -2810,7 +2810,11 @@ static ssize_t qio_channel_rdma_writev(QIOChannel *ioc,
return -1;
}

CHECK_ERROR_STATE();
if (rdma->error_state) {
error_setg(errp,
"RDMA is in an error state waiting migration to abort!");
return -1;
}

/*
* Push out any writes that
Expand Down Expand Up @@ -2896,7 +2900,11 @@ static ssize_t qio_channel_rdma_readv(QIOChannel *ioc,
return -1;
}

CHECK_ERROR_STATE();
if (rdma->error_state) {
error_setg(errp,
"RDMA is in an error state waiting migration to abort!");
return -1;
}

for (i = 0; i < niov; i++) {
size_t want = iov[i].iov_len;
Expand Down

0 comments on commit 8e262e0

Please sign in to comment.