Skip to content

Commit 40aa38a

Browse files
stefanhaRHkevmw
authored andcommitted
virtio-scsi: only expose cmd vqs via iothread-vq-mapping
Peter Krempa and Kevin Wolf observed that iothread-vq-mapping is confusing to use because the control and event virtqueues have a fixed location before the command virtqueues but need to be treated differently. Only expose the command virtqueues via iothread-vq-mapping so that the command-line parameter is intuitive: it controls where SCSI requests are processed. The control virtqueue needs to be hardcoded to the main loop thread for technical reasons anyway. Kevin also pointed out that it's better to place the event virtqueue in the main loop thread since its no poll behavior would prevent polling if assigned to an IOThread. This change is its own commit to avoid squashing the previous commit. Suggested-by: Kevin Wolf <[email protected]> Suggested-by: Peter Krempa <[email protected]> Signed-off-by: Stefan Hajnoczi <[email protected]> Message-ID: <[email protected]> Tested-by: Peter Krempa <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent bcede51 commit 40aa38a

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

hw/scsi/virtio-scsi-dataplane.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp)
2828
VirtIODevice *vdev = VIRTIO_DEVICE(s);
2929
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
3030
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
31-
uint16_t num_vqs = vs->conf.num_queues + VIRTIO_SCSI_VQ_NUM_FIXED;
3231

3332
if (vs->conf.iothread && vs->conf.iothread_vq_mapping_list) {
3433
error_setg(errp,
@@ -50,35 +49,43 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp)
5049
}
5150
}
5251

53-
s->vq_aio_context = g_new(AioContext *, num_vqs);
52+
s->vq_aio_context = g_new(AioContext *, vs->conf.num_queues +
53+
VIRTIO_SCSI_VQ_NUM_FIXED);
54+
55+
/*
56+
* Handle the ctrl virtqueue in the main loop thread where device resets
57+
* can be performed.
58+
*/
59+
s->vq_aio_context[0] = qemu_get_aio_context();
60+
61+
/*
62+
* Handle the event virtqueue in the main loop thread where its no_poll
63+
* behavior won't stop IOThread polling.
64+
*/
65+
s->vq_aio_context[1] = qemu_get_aio_context();
5466

5567
if (vs->conf.iothread_vq_mapping_list) {
5668
if (!iothread_vq_mapping_apply(vs->conf.iothread_vq_mapping_list,
57-
s->vq_aio_context, num_vqs, errp)) {
69+
&s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED],
70+
vs->conf.num_queues, errp)) {
5871
g_free(s->vq_aio_context);
5972
s->vq_aio_context = NULL;
6073
return;
6174
}
6275
} else if (vs->conf.iothread) {
6376
AioContext *ctx = iothread_get_aio_context(vs->conf.iothread);
64-
for (uint16_t i = 0; i < num_vqs; i++) {
65-
s->vq_aio_context[i] = ctx;
77+
for (uint16_t i = 0; i < vs->conf.num_queues; i++) {
78+
s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] = ctx;
6679
}
6780

6881
/* Released in virtio_scsi_dataplane_cleanup() */
6982
object_ref(OBJECT(vs->conf.iothread));
7083
} else {
7184
AioContext *ctx = qemu_get_aio_context();
72-
for (unsigned i = 0; i < num_vqs; i++) {
73-
s->vq_aio_context[i] = ctx;
85+
for (unsigned i = 0; i < vs->conf.num_queues; i++) {
86+
s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] = ctx;
7487
}
7588
}
76-
77-
/*
78-
* Always handle the ctrl virtqueue in the main loop thread where device
79-
* resets can be performed.
80-
*/
81-
s->vq_aio_context[0] = qemu_get_aio_context();
8289
}
8390

8491
/* Context: BQL held */

0 commit comments

Comments
 (0)