diff options
author | John Levon <john.levon@nutanix.com> | 2021-06-30 15:24:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-30 15:24:48 +0100 |
commit | 677a541ca1f42d1f32a0371bbdf32005bdbd871d (patch) | |
tree | 3381320b7f4148c1ad6474c3021fc6834b8028bd /lib | |
parent | 8b4089ad1164ef0d98d6d777de63de2aa25a1d8a (diff) | |
download | libvfio-user-677a541ca1f42d1f32a0371bbdf32005bdbd871d.zip libvfio-user-677a541ca1f42d1f32a0371bbdf32005bdbd871d.tar.gz libvfio-user-677a541ca1f42d1f32a0371bbdf32005bdbd871d.tar.bz2 |
return process request count in vfu_run_ctx() (#574)
Consumers such as SPDK would like to know if any actual work was done. Modify
the API to support this. Also, clean up some stale mocking we no longer use.
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libvfio-user.c | 21 | ||||
-rw-r--r-- | lib/private.h | 2 |
2 files changed, 14 insertions, 9 deletions
diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c index 0762c24..a90d9c2 100644 --- a/lib/libvfio-user.c +++ b/lib/libvfio-user.c @@ -1011,8 +1011,8 @@ exec_command(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg) * the socket. Otherwise, we synchronously process the request in place, and * possibly reply. */ -int -MOCK_DEFINE(process_request)(vfu_ctx_t *vfu_ctx) +static int +process_request(vfu_ctx_t *vfu_ctx) { vfu_msg_t *msg = NULL; int ret; @@ -1022,9 +1022,6 @@ MOCK_DEFINE(process_request)(vfu_ctx_t *vfu_ctx) ret = get_request_header(vfu_ctx, &msg); if (ret < 0) { - if (errno == EAGAIN || errno == EWOULDBLOCK) { - return 0; - } return ret; } @@ -1162,8 +1159,9 @@ vfu_realize_ctx(vfu_ctx_t *vfu_ctx) EXPORT int vfu_run_ctx(vfu_ctx_t *vfu_ctx) { - int err; + int reqs_processed = 0; bool blocking; + int err; assert(vfu_ctx != NULL); @@ -1172,11 +1170,20 @@ vfu_run_ctx(vfu_ctx_t *vfu_ctx) } blocking = !(vfu_ctx->flags & LIBVFIO_USER_FLAG_ATTACH_NB); + do { err = process_request(vfu_ctx); + + if (err == 0) { + reqs_processed++; + } else { + if (errno == EAGAIN || errno == EWOULDBLOCK) { + err = 0; + } + } } while (err == 0 && blocking); - return err; + return err == 0 ? reqs_processed : err; } static void diff --git a/lib/private.h b/lib/private.h index f474e1f..fb26b6a 100644 --- a/lib/private.h +++ b/lib/private.h @@ -214,8 +214,6 @@ MOCK_DECLARE(bool, cmd_allowed_when_stopped_and_copying, uint16_t cmd); MOCK_DECLARE(bool, should_exec_command, vfu_ctx_t *vfu_ctx, uint16_t cmd); -MOCK_DECLARE(int, process_request, vfu_ctx_t *vfu_ctx); - #endif /* LIB_VFIO_USER_PRIVATE_H */ /* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */ |