@@ -163,6 +163,13 @@ typedef struct VirtioDeviceClass {
int (*post_load)(VirtIODevice *vdev);
const VMStateDescription *vmsd;
bool (*primary_unplug_pending)(void *opaque);
+
+ /*
+ * Return the number of virtqueues. Called by transports that need to
+ * allocate per-virtqueue interrupt resources. This function may be called
+ * before the device is realized.
+ */
+ uint32_t (*get_num_virtqueues)(VirtIODevice *vdev);
} VirtioDeviceClass;
void virtio_instance_init_common(Object *proxy_obj, void *data,
The virtio-pci proxy objects have an "nvectors" qdev property to allocate MSI vectors. This property defaults to DEV_NVECTORS_UNSPECIFIED on multi-queue devices and the final value is based on the number of virtqueues. The number of virtqueues is typically calculated like this by the virtio-pci proxy object: num_virtqueues = NUM_FIXED_VIRTQUEUES + conf.num_queues where conf.num_queues is a qdev property to allocate virtqueues. Add VirtioDeviceClass->get_num_virtqueues() so that this calculation can be performed by the device instead of the proxy object. This removes knowledge of virtqueue layout from the proxy object and allows the device to implement other formulas for calculating the number of virtqueues. This patch has no use on its own but keeping it separate eases backports if someone wants the virtio-blk patch but not virtio-scsi, or vice versa. The next patch uses this new function to automatically set conf.num_queues to -smp N for automatic multi-queue configuration. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> --- include/hw/virtio/virtio.h | 7 +++++++ 1 file changed, 7 insertions(+)