[Libguestfs] [libnbd PATCH v3 3/7] commands: Expose FIFO ordering of server completions

Richard W.M. Jones rjones at redhat.com
Wed May 22 22:17:29 UTC 2019


On Wed, May 22, 2019 at 04:29:03PM -0500, Eric Blake wrote:
> +int64_t
> +nbd_unlocked_aio_peek_command_completed (struct nbd_connection *conn)
> +{
> +  if (conn->cmds_done != NULL)
> +    return conn->cmds_done->handle;
> +
> +  if (conn->cmds_in_flight != NULL || conn->cmds_to_issue != NULL)
> +    set_error (0, "no in-flight command has completed yet");
> +  else
> +    set_error (0, "no commands are in flight");
> +  return -1;
> +}
> -- 

There are two ways I think we could improve this.  Either:

(1) I believe that all handles are >= 1 (and if this isn't true, it's
easy to achieve by starting the h->unique counter at 1).  Return
0 to mean "no completed command".  Of course "no commands in
flight" is still an error.

I think (1) is more elegant, but the alternative is:

(2) Use the errno field (currently 0) to distinguish the two cases
with a suitable errno value (EAGAIN maybe?) for the "no completed
command" case.

No need to post this patch again, ACK if you make this kind of change.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/




More information about the Libguestfs mailing list