On 6/29/19 8:28 AM, Eric Blake wrote:
Some clients need to know when it is safe to issue NBD_CMD_DISC, or to decide whether calling poll(POLLIN) will block indefinitely because the server isn't expected to respond. Make this easier to learn by tracking the count of commands we have queued up to send, as well as the count of commands where we are waiting on the server's response.
Update tests/aio-parallel* and examples/batched-read-write to use nbd's own in-flight counter instead of reimplementing it ourselves.
Note that h->in_flight is only ever updated while the lock is held; but we may want to consider also making it atomic and therefore readable as a lock-less function. ---
+++ b/tests/aio-parallel-load.c @@ -189,7 +189,6 @@ start_thread (void *arg) size_t i; uint64_t offset, handle; uint64_t handles[MAX_IN_FLIGHT];
This array is uninitialized. Previously, it did not matter,
@@ -291,16 +294,16 @@ start_thread (void *arg) nbd_aio_notify_write (nbd);
/* If a command is ready to retire, retire it. */ - for (i = 0; i < in_flight; ++i) { + for (i = 0; i < MAX_IN_FLIGHT; ++i) { + if (handles[i] == 0) + continue; r = nbd_aio_command_completed (nbd, handles[i]); if (r == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); goto error; } if (r) { - memmove (&handles[i], &handles[i+1], - sizeof (handles[0]) * (in_flight - i - 1));
...because we never accessed an element without first setting it up; but now valgrind is able to report a conditional branch on an uninit variable. I'm pushing an obvious fix. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org