[Libguestfs] [libnbd PATCH 1/6] api: Add nbd_aio_in_flight

Eric Blake eblake at redhat.com
Tue Jul 2 18:53:34 UTC 2019


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20190702/df5e3ce7/attachment.sig>


More information about the Libguestfs mailing list