diff options
author | Thanos Makatos <thanos.makatos@nutanix.com> | 2020-11-16 10:22:33 -0500 |
---|---|---|
committer | Thanos <tmakatos@gmail.com> | 2020-11-18 16:50:58 +0000 |
commit | d477770fb2fbefa1c1a7a067125891956c525d47 (patch) | |
tree | 9880a7cb62b5e06f100efa8b7c067420ed3563be | |
parent | 943fe77b8099d4a9c5423320dc471a4ac14c634b (diff) | |
download | libvfio-user-d477770fb2fbefa1c1a7a067125891956c525d47.zip libvfio-user-d477770fb2fbefa1c1a7a067125891956c525d47.tar.gz libvfio-user-d477770fb2fbefa1c1a7a067125891956c525d47.tar.bz2 |
don't assert on error, instead respond with the relevant bit set
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
-rw-r--r-- | lib/muser_ctx.c | 15 | ||||
-rw-r--r-- | lib/muser_priv.h | 2 | ||||
-rw-r--r-- | samples/client.c | 8 |
3 files changed, 19 insertions, 6 deletions
diff --git a/lib/muser_ctx.c b/lib/muser_ctx.c index 1a9b86d..c0f61a1 100644 --- a/lib/muser_ctx.c +++ b/lib/muser_ctx.c @@ -224,7 +224,7 @@ int _send_vfio_user_msg(int sock, uint16_t msg_id, bool is_reply, enum vfio_user_command cmd, struct iovec *iovecs, size_t nr_iovecs, - int *fds, int count) + int *fds, int count, int err) { int ret; struct vfio_user_header hdr = {.msg_id = msg_id}; @@ -240,6 +240,10 @@ _send_vfio_user_msg(int sock, uint16_t msg_id, bool is_reply, if (is_reply) { hdr.flags.type = VFIO_USER_F_TYPE_REPLY; + if (err != 0) { + hdr.flags.error = 1U; + hdr.error_no = err; + } } else { hdr.cmd = cmd; hdr.flags.type = VFIO_USER_F_TYPE_COMMAND; @@ -290,7 +294,7 @@ send_vfio_user_msg(int sock, uint16_t msg_id, bool is_reply, } }; return _send_vfio_user_msg(sock, msg_id, is_reply, cmd, iovecs, - ARRAY_SIZE(iovecs), fds, count); + ARRAY_SIZE(iovecs), fds, count, 0); } int @@ -406,7 +410,7 @@ _send_recv_vfio_user_msg(int sock, uint16_t msg_id, enum vfio_user_command cmd, void *recv_data, size_t recv_len) { int ret = _send_vfio_user_msg(sock, msg_id, false, cmd, iovecs, nr_iovecs, - send_fds, fd_count); + send_fds, fd_count, 0); if (ret < 0) { return ret; } @@ -2155,10 +2159,11 @@ reply: if (ret < 0) { lm_log(lm_ctx, LM_ERR, "failed to handle command %d: %s", hdr.cmd, strerror(-ret)); - assert(false); /* FIXME */ + } else { + ret = 0; } ret = _send_vfio_user_msg(lm_ctx->conn_fd, hdr.msg_id, true, - 0, iovecs, nr_iovecs, NULL, 0); + 0, iovecs, nr_iovecs, NULL, 0, -ret); if (unlikely(ret < 0)) { lm_log(lm_ctx, LM_ERR, "failed to complete command: %s", strerror(-ret)); diff --git a/lib/muser_priv.h b/lib/muser_priv.h index f814bc0..2ff8332 100644 --- a/lib/muser_priv.h +++ b/lib/muser_priv.h @@ -53,7 +53,7 @@ int _send_vfio_user_msg(int sock, uint16_t msg_id, bool is_reply, enum vfio_user_command cmd, struct iovec *iovecs, size_t nr_iovecs, - int *fds, int count); + int *fds, int count, int err); int send_vfio_user_msg(int sock, uint16_t msg_id, bool is_reply, diff --git a/samples/client.c b/samples/client.c index bd8d2b3..afed47a 100644 --- a/samples/client.c +++ b/samples/client.c @@ -905,6 +905,14 @@ int main(int argc, char *argv[]) ret = migrate_from(sock); } + /* + * Try to touch BAR0, we should get an error as the device is stopped. + */ + ret = access_bar0(sock); + if (ret != EINVAL) { + fprintf(stderr, "expected an error, got %d instead\n", ret); + } + return 0; } |