From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55291) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQ1y0-0001ce-GF for qemu-devel@nongnu.org; Mon, 23 Feb 2015 17:59:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YQ1xw-0006gB-BX for qemu-devel@nongnu.org; Mon, 23 Feb 2015 17:59:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35821) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQ1xw-0006g7-46 for qemu-devel@nongnu.org; Mon, 23 Feb 2015 17:59:04 -0500 From: Max Reitz Date: Mon, 23 Feb 2015 17:58:59 -0500 Message-Id: <1424732339-11237-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH] virtio-scsi: Allocate op blocker reason before blocking List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Max Reitz , Anthony Liguori , "Michael S. Tsirkin" s->blocker is really only used in hw/scsi/virtio-scsi.c; the only places where it is used in hw/scsi/virtio-scsi-dataplane.c is when it is allocated and when it is freed. That does not make a whole lot of sense (and is actually wrong because this leads to s->blocker potentially being NULL when blk_op_block_all() is called in virtio-scsi.c), so move the allocation and destruction of s->blocker to blk_op_block_all() and blk_op_unblock_all() in virtio-scsi.c, respectively. Signed-off-by: Max Reitz --- Try: $ echo -e 'eject drv\nquit' | \ x86_64-softmmu/qemu-system-x86_64 \ -monitor stdio -machine accel=qtest -display none \ -object iothread,id=thr -device virtio-scsi-pci,iothread=thr \ -drive if=none,file=test.qcow2,format=qcow2,id=drv \ -device scsi-cd,drive=drv What it should do: QEMU 2.2.50 monitor - type 'help' for more information (qemu) eject drv Device 'drv' is busy: block device is in use by data plane (qemu) quit What it should not do: QEMU 2.2.50 monitor - type 'help' for more information (qemu) eject drv [1] 10102 done 10103 segmentation fault (core dumped) --- hw/scsi/virtio-scsi-dataplane.c | 4 ---- hw/scsi/virtio-scsi.c | 6 +++++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplane.c index 03a1e8c..9b775d4 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -211,8 +211,6 @@ void virtio_scsi_dataplane_start(VirtIOSCSI *s) s->dataplane_starting = true; - assert(!s->blocker); - error_setg(&s->blocker, "block device is in use by data plane"); /* Set up guest notifier (irq) */ rc = k->set_guest_notifiers(qbus->parent, vs->conf.num_queues + 2, true); if (rc != 0) { @@ -279,8 +277,6 @@ void virtio_scsi_dataplane_stop(VirtIOSCSI *s) if (!s->dataplane_started || s->dataplane_stopping) { return; } - error_free(s->blocker); - s->blocker = NULL; s->dataplane_stopping = true; assert(s->ctx == iothread_get_aio_context(vs->conf.iothread)); diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 9e2c718..5469bad 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -766,6 +766,8 @@ static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev, if (blk_op_is_blocked(sd->conf.blk, BLOCK_OP_TYPE_DATAPLANE, errp)) { return; } + assert(!s->blocker); + error_setg(&s->blocker, "block device is in use by data plane"); blk_op_block_all(sd->conf.blk, s->blocker); } @@ -789,8 +791,10 @@ static void virtio_scsi_hotunplug(HotplugHandler *hotplug_dev, DeviceState *dev, VIRTIO_SCSI_EVT_RESET_REMOVED); } - if (s->ctx) { + if (s->ctx && s->blocker) { blk_op_unblock_all(sd->conf.blk, s->blocker); + error_free(s->blocker); + s->blocker = NULL; } qdev_simple_device_unplug_cb(hotplug_dev, dev, errp); } -- 2.1.0