virtio-blk: clarify that there is at least 1 virtqueue
commit5fbcbd50fca67ffe35317f2e86f6822aa22e41c6
authorStefan Hajnoczi <stefanha@redhat.com>
Tue, 6 Feb 2024 19:06:07 +0000 (6 14:06 -0500)
committerKevin Wolf <kwolf@redhat.com>
Wed, 7 Feb 2024 13:44:09 +0000 (7 14:44 +0100)
treea5188225b0e671801411fe46e81145cce640e377
parent1f995a4782d140b16d9b24e787053944fb5c4dfb
virtio-blk: clarify that there is at least 1 virtqueue

It is not possible to instantiate a virtio-blk device with 0 virtqueues.
The following check is located in ->realize():

  if (!conf->num_queues) {
      error_setg(errp, "num-queues property must be larger than 0");
      return;
  }

Later on we access s->vq_aio_context[0] under the assumption that there
is as least one virtqueue. Hanna Czenczek <hreitz@redhat.com> noted that
it would help to show that the array index is already valid.

Add an assertion to document that s->vq_aio_context[0] is always
safe...and catch future code changes that break this assumption.

Suggested-by: Hanna Czenczek <hreitz@redhat.com>
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-ID: <20240206190610.107963-3-stefanha@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
hw/block/virtio-blk.c