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 | |
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>
-rw-r--r-- | include/libvfio-user.h | 3 | ||||
-rw-r--r-- | lib/libvfio-user.c | 21 | ||||
-rw-r--r-- | lib/private.h | 2 | ||||
-rw-r--r-- | test/mocks.c | 13 |
4 files changed, 16 insertions, 23 deletions
diff --git a/include/libvfio-user.h b/include/libvfio-user.h index cd470a9..75de04e 100644 --- a/include/libvfio-user.h +++ b/include/libvfio-user.h @@ -148,7 +148,8 @@ vfu_get_poll_fd(vfu_ctx_t *vfu_ctx); * * @vfu_ctx: The libvfio-user context to poll * - * @returns 0 on success, -1 on error, with errno set as follows: + * @returns the number of requests processed (0 or more); or -1 on error, + * with errno set as follows: * * EAGAIN/EWOULDBLOCK: no more commands to process * ENOTCONN: client closed connection, vfu_attach_ctx() should be called again 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: */ diff --git a/test/mocks.c b/test/mocks.c index 6e34d4a..29fe298 100644 --- a/test/mocks.c +++ b/test/mocks.c @@ -62,7 +62,6 @@ static struct function funcs[] = { { .name = "dma_controller_add_region" }, { .name = "dma_controller_remove_region" }, { .name = "dma_controller_unmap_region" }, - { .name = "process_request" }, { .name = "should_exec_command" }, { .name = "migration_region_access_registers" }, { .name = "handle_device_state" }, @@ -169,18 +168,6 @@ device_is_stopped(struct migration *migration) return mock(); } -int -process_request(vfu_ctx_t *vfu_ctx) -{ - - if (!is_patched("process_request")) { - return __real_process_request(vfu_ctx); - } - check_expected(vfu_ctx); - - return mock(); -} - bool device_is_stopped_and_copying(struct migration *migration) { |