qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

scsi-disk: Use qdev_prop_drive_iothread

This makes use of qdev_prop_drive_iothread for scsi-disk so that the
disk can be attached to a node that is already in the target AioContext.
We need to check that the HBA actually supports iothreads, otherwise
scsi-disk must make sure that the node is already in the main
AioContext.

This changes the error message for conflicting iothread settings.
Previously, virtio-scsi produced the error message, now it comes from
blk_set_aio_context(). Update a test case accordingly.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>

+25 -15
+15 -7
hw/scsi/scsi-disk.c
··· 2336 2336 return; 2337 2337 } 2338 2338 2339 + if (blk_get_aio_context(s->qdev.conf.blk) != qemu_get_aio_context() && 2340 + !s->qdev.hba_supports_iothread) 2341 + { 2342 + error_setg(errp, "HBA does not support iothreads"); 2343 + return; 2344 + } 2345 + 2339 2346 if (dev->type == TYPE_DISK) { 2340 2347 if (!blkconf_geometry(&dev->conf, NULL, 65535, 255, 255, errp)) { 2341 2348 return; ··· 2929 2936 .abstract = true, 2930 2937 }; 2931 2938 2932 - #define DEFINE_SCSI_DISK_PROPERTIES() \ 2933 - DEFINE_BLOCK_PROPERTIES(SCSIDiskState, qdev.conf), \ 2934 - DEFINE_BLOCK_ERROR_PROPERTIES(SCSIDiskState, qdev.conf), \ 2935 - DEFINE_PROP_STRING("ver", SCSIDiskState, version), \ 2936 - DEFINE_PROP_STRING("serial", SCSIDiskState, serial), \ 2937 - DEFINE_PROP_STRING("vendor", SCSIDiskState, vendor), \ 2938 - DEFINE_PROP_STRING("product", SCSIDiskState, product), \ 2939 + #define DEFINE_SCSI_DISK_PROPERTIES() \ 2940 + DEFINE_PROP_DRIVE_IOTHREAD("drive", SCSIDiskState, qdev.conf.blk), \ 2941 + DEFINE_BLOCK_PROPERTIES_BASE(SCSIDiskState, qdev.conf), \ 2942 + DEFINE_BLOCK_ERROR_PROPERTIES(SCSIDiskState, qdev.conf), \ 2943 + DEFINE_PROP_STRING("ver", SCSIDiskState, version), \ 2944 + DEFINE_PROP_STRING("serial", SCSIDiskState, serial), \ 2945 + DEFINE_PROP_STRING("vendor", SCSIDiskState, vendor), \ 2946 + DEFINE_PROP_STRING("product", SCSIDiskState, product), \ 2939 2947 DEFINE_PROP_STRING("device_id", SCSIDiskState, device_id) 2940 2948 2941 2949
+8 -7
hw/scsi/virtio-scsi.c
··· 789 789 } 790 790 } 791 791 792 + static void virtio_scsi_pre_hotplug(HotplugHandler *hotplug_dev, 793 + DeviceState *dev, Error **errp) 794 + { 795 + SCSIDevice *sd = SCSI_DEVICE(dev); 796 + sd->hba_supports_iothread = true; 797 + } 798 + 792 799 static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev, 793 800 Error **errp) 794 801 { ··· 798 805 int ret; 799 806 800 807 if (s->ctx && !s->dataplane_fenced) { 801 - AioContext *ctx; 802 808 if (blk_op_is_blocked(sd->conf.blk, BLOCK_OP_TYPE_DATAPLANE, errp)) { 803 - return; 804 - } 805 - ctx = blk_get_aio_context(sd->conf.blk); 806 - if (ctx != s->ctx && ctx != qemu_get_aio_context()) { 807 - error_setg(errp, "Cannot attach a blockdev that is using " 808 - "a different iothread"); 809 809 return; 810 810 } 811 811 virtio_scsi_acquire(s); ··· 990 990 vdc->reset = virtio_scsi_reset; 991 991 vdc->start_ioeventfd = virtio_scsi_dataplane_start; 992 992 vdc->stop_ioeventfd = virtio_scsi_dataplane_stop; 993 + hc->pre_plug = virtio_scsi_pre_hotplug; 993 994 hc->plug = virtio_scsi_hotplug; 994 995 hc->unplug = virtio_scsi_hotunplug; 995 996 }
+1
include/hw/scsi/scsi.h
··· 88 88 int scsi_version; 89 89 int default_scsi_version; 90 90 bool needs_vpd_bl_emulation; 91 + bool hba_supports_iothread; 91 92 }; 92 93 93 94 extern const VMStateDescription vmstate_scsi_device;
+1 -1
tests/qemu-iotests/240.out
··· 43 43 {"return": {}} 44 44 {"return": {}} 45 45 {"return": {}} 46 - {"error": {"class": "GenericError", "desc": "Cannot attach a blockdev that is using a different iothread"}} 46 + {"error": {"class": "GenericError", "desc": "Cannot change iothread of active block backend"}} 47 47 {"return": {}} 48 48 {"return": {}} 49 49 {"return": {}}