From: Max Reitz <mreitz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Max Reitz <mreitz@redhat.com>,
Anthony Liguori <aliguori@amazon.com>,
"Michael S. Tsirkin" <mst@redhat.com>
Subject: [Qemu-devel] [PATCH] virtio-scsi: Allocate op blocker reason before blocking
Date: Mon, 23 Feb 2015 17:58:59 -0500 [thread overview]
Message-ID: <1424732339-11237-1-git-send-email-mreitz@redhat.com> (raw)
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 <mreitz@redhat.com>
---
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
next reply other threads:[~2015-02-23 22:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-23 22:58 Max Reitz [this message]
2015-02-24 9:43 ` [Qemu-devel] [PATCH] virtio-scsi: Allocate op blocker reason before blocking Markus Armbruster
2015-02-24 14:03 ` Max Reitz
2015-02-24 16:24 ` Eric Blake
2015-02-25 6:22 ` Fam Zheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1424732339-11237-1-git-send-email-mreitz@redhat.com \
--to=mreitz@redhat.com \
--cc=aliguori@amazon.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).