[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] virtio-scsi: Allocate op blocker reason before
From: |
Fam Zheng |
Subject: |
Re: [Qemu-devel] [PATCH] virtio-scsi: Allocate op blocker reason before blocking |
Date: |
Wed, 25 Feb 2015 14:22:39 +0800 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
On Mon, 02/23 17:58, Max Reitz wrote:
> 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 <address@hidden>
> ---
> 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
>
>
Reviewed-by: Fam Zheng <address@hidden>