[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-block] [PATCH v4 05/11] block: Move BDS close notifiers into B
From: |
Max Reitz |
Subject: |
Re: [Qemu-block] [PATCH v4 05/11] block: Move BDS close notifiers into BB |
Date: |
Fri, 27 Feb 2015 15:08:39 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 |
On 2015-02-27 at 11:43, Max Reitz wrote:
The only remaining user of the BDS close notifiers is NBD which uses
them to determine when a BDS tree is being ejected. This patch removes
the BDS-level close notifiers and adds a notifier list to the
BlockBackend structure that is invoked whenever a BDS is removed.
Symmetrically to that, another notifier list is added that is invoked
whenever a BDS is inserted. The dataplane implementations for virtio-blk
and virtio-scsi use both notifier types for setting up and removing op
blockers. This is not only important for setting up the op blockers on
insertion, but also for removing them on ejection since bdrv_delete()
asserts that there are no op blockers set up.
Signed-off-by: Max Reitz <address@hidden>
---
block.c | 7 ----
block/block-backend.c | 19 +++++++--
blockdev-nbd.c | 36 +----------------
hw/block/dataplane/virtio-blk.c | 77 +++++++++++++++++++++++++++---------
hw/scsi/virtio-scsi.c | 87 ++++++++++++++++++++++++++++++++++++++---
include/block/block.h | 1 -
include/block/block_int.h | 2 -
include/hw/virtio/virtio-scsi.h | 10 +++++
include/sysemu/block-backend.h | 3 +-
nbd.c | 13 ++++++
10 files changed, 182 insertions(+), 73 deletions(-)
[snip]
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 5469bad..570f2fd 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -755,6 +755,37 @@ static void virtio_scsi_change(SCSIBus *bus, SCSIDevice
*dev, SCSISense sense)
}
}
+static void virtio_scsi_set_up_op_blockers(VirtIOSCSI *s, SCSIDevice *sd)
+{
+ if (!s->blocker) {
+ error_setg(&s->blocker, "block device is in use by data plane");
This will no longer be necessary with v2 of my virtio-scsi op blocker patch.
+ }
+ blk_op_block_all(sd->conf.blk, s->blocker);
+}
+
+static void virtio_scsi_remove_op_blockers(VirtIOSCSI *s, SCSIDevice *sd)
+{
+ if (s->blocker) {
+ blk_op_unblock_all(sd->conf.blk, s->blocker);
+ }
+}
+
+static void virtio_scsi_blk_insert_notifier(Notifier *n, void *data)
+{
+ VirtIOSCSIBlkChangeNotifier *cn = DO_UPCAST(VirtIOSCSIBlkChangeNotifier,
+ n, n);
+ assert(cn->sd->conf.blk == data);
+ virtio_scsi_set_up_op_blockers(cn->s, cn->sd);
+}
+
+static void virtio_scsi_blk_remove_notifier(Notifier *n, void *data)
+{
+ VirtIOSCSIBlkChangeNotifier *cn = DO_UPCAST(VirtIOSCSIBlkChangeNotifier,
+ n, n);
+ assert(cn->sd->conf.blk == data);
+ virtio_scsi_remove_op_blockers(cn->s, cn->sd);
+}
+
static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev,
Error **errp)
{
@@ -763,12 +794,26 @@ static void virtio_scsi_hotplug(HotplugHandler
*hotplug_dev, DeviceState *dev,
SCSIDevice *sd = SCSI_DEVICE(dev);
if (s->ctx && !s->dataplane_disabled) {
+ VirtIOSCSIBlkChangeNotifier *insert_notifier, *remove_notifier;
+
+ insert_notifier = g_new0(VirtIOSCSIBlkChangeNotifier, 1);
+ insert_notifier->n.notify = virtio_scsi_blk_insert_notifier;
+ insert_notifier->s = s;
+ insert_notifier->sd = sd;
+ blk_add_insert_bs_notifier(sd->conf.blk, &insert_notifier->n);
+ QTAILQ_INSERT_TAIL(&s->insert_notifiers, insert_notifier, next);
+
+ remove_notifier = g_new0(VirtIOSCSIBlkChangeNotifier, 1);
+ remove_notifier->n.notify = virtio_scsi_blk_remove_notifier;
+ remove_notifier->s = s;
+ remove_notifier->sd = sd;
+ blk_add_remove_bs_notifier(sd->conf.blk, &remove_notifier->n);
+ QTAILQ_INSERT_TAIL(&s->remove_notifiers, remove_notifier, next);
+
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");
Same for these two lines removed (they just don't exist any more).
- blk_op_block_all(sd->conf.blk, s->blocker);
+ virtio_scsi_set_up_op_blockers(s, sd);
}
if ((vdev->guest_features >> VIRTIO_SCSI_F_HOTPLUG) & 1) {
@@ -784,6 +829,7 @@ static void virtio_scsi_hotunplug(HotplugHandler
*hotplug_dev, DeviceState *dev,
VirtIODevice *vdev = VIRTIO_DEVICE(hotplug_dev);
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
SCSIDevice *sd = SCSI_DEVICE(dev);
+ VirtIOSCSIBlkChangeNotifier *insert_notifier, *remove_notifier;
if ((vdev->guest_features >> VIRTIO_SCSI_F_HOTPLUG) & 1) {
virtio_scsi_push_event(s, sd,
@@ -791,11 +837,39 @@ static void virtio_scsi_hotunplug(HotplugHandler
*hotplug_dev, DeviceState *dev,
VIRTIO_SCSI_EVT_RESET_REMOVED);
}
- if (s->ctx && s->blocker) {
- blk_op_unblock_all(sd->conf.blk, s->blocker);
+ if (s->ctx) {
+ virtio_scsi_remove_op_blockers(s, sd);
+ }
+
+ QTAILQ_FOREACH(insert_notifier, &s->insert_notifiers, next) {
+ if (insert_notifier->sd == sd) {
+ break;
+ }
+ }
+ if (insert_notifier) {
+ notifier_remove(&insert_notifier->n);
+ QTAILQ_REMOVE(&s->insert_notifiers, insert_notifier, next);
+ g_free(insert_notifier);
+ }
+
+ QTAILQ_FOREACH(remove_notifier, &s->remove_notifiers, next) {
+ if (remove_notifier->sd == sd) {
+ break;
+ }
+ }
+ if (remove_notifier) {
+ notifier_remove(&remove_notifier->n);
+ QTAILQ_REMOVE(&s->remove_notifiers, remove_notifier, next);
+ g_free(remove_notifier);
+ }
+
+ if (QTAILQ_EMPTY(&s->insert_notifiers) &&
+ QTAILQ_EMPTY(&s->remove_notifiers))
+ {
error_free(s->blocker);
s->blocker = NULL;
}
+
And for this last block.
Max
- [Qemu-block] [PATCH v4 00/11] block: Rework bdrv_close_all(), Max Reitz, 2015/02/27
- [Qemu-block] [PATCH v4 02/11] iotests: Make redirecting qemu's stderr optional, Max Reitz, 2015/02/27
- [Qemu-block] [PATCH v4 01/11] iotests: Move _filter_nbd into common.filter, Max Reitz, 2015/02/27
- [Qemu-block] [PATCH v4 05/11] block: Move BDS close notifiers into BB, Max Reitz, 2015/02/27
- [Qemu-block] [PATCH v4 03/11] iotests: Add test for eject under NBD server, Max Reitz, 2015/02/27
- [Qemu-block] [PATCH v4 07/11] blockdev: Use blk_remove_bs() in do_drive_del(), Max Reitz, 2015/02/27
- [Qemu-block] [PATCH v4 09/11] blockdev: Keep track of monitor-owned BDS, Max Reitz, 2015/02/27
- [Qemu-block] [PATCH v4 04/11] quorum: Fix close path, Max Reitz, 2015/02/27
- [Qemu-block] [PATCH v4 10/11] block: Eject BDS tree from BB at bdrv_close_all(), Max Reitz, 2015/02/27
- [Qemu-block] [PATCH v4 06/11] block: Use blk_remove_bs() in blk_delete(), Max Reitz, 2015/02/27
- [Qemu-block] [PATCH v4 08/11] block: Make bdrv_close() static, Max Reitz, 2015/02/27
- [Qemu-block] [PATCH v4 11/11] iotests: Add test for multiple BB on BDS tree, Max Reitz, 2015/02/27