aboutsummaryrefslogtreecommitdiff
path: root/hw/block
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2023-05-16 15:02:29 -0400
committerKevin Wolf <kwolf@redhat.com>2023-05-30 17:32:02 +0200
commitf6eac904f6825d47adc6102c8d7b59b8ba5b778e (patch)
tree5b1faf62077883c92fd8619063bd3738680c20e0 /hw/block
parentab61335025b1274bd7042219203524045b23e0d3 (diff)
downloadqemu-f6eac904f6825d47adc6102c8d7b59b8ba5b778e.zip
qemu-f6eac904f6825d47adc6102c8d7b59b8ba5b778e.tar.gz
qemu-f6eac904f6825d47adc6102c8d7b59b8ba5b778e.tar.bz2
xen-block: implement BlockDevOps->drained_begin()
Detach event channels during drained sections to stop I/O submission from the ring. xen-block is no longer reliant on aio_disable_external() after this patch. This will allow us to remove the aio_disable_external() API once all other code that relies on it is converted. Extend xen_device_set_event_channel_context() to allow ctx=NULL. The event channel still exists but the event loop does not monitor the file descriptor. Event channel processing can resume by calling xen_device_set_event_channel_context() with a non-NULL ctx. Factor out xen_device_set_event_channel_context() calls in hw/block/dataplane/xen-block.c into attach/detach helper functions. Incidentally, these don't require the AioContext lock because aio_set_fd_handler() is thread-safe. It's safer to register BlockDevOps after the dataplane instance has been created. The BlockDevOps .drained_begin/end() callbacks depend on the dataplane instance, so move the blk_set_dev_ops() call after xen_block_dataplane_create(). Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Message-Id: <20230516190238.8401-12-stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'hw/block')
-rw-r--r--hw/block/dataplane/xen-block.c42
-rw-r--r--hw/block/dataplane/xen-block.h2
-rw-r--r--hw/block/xen-block.c24
3 files changed, 54 insertions, 14 deletions
diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c
index d8bc39d..2597f38 100644
--- a/hw/block/dataplane/xen-block.c
+++ b/hw/block/dataplane/xen-block.c
@@ -664,6 +664,30 @@ void xen_block_dataplane_destroy(XenBlockDataPlane *dataplane)
g_free(dataplane);
}
+void xen_block_dataplane_detach(XenBlockDataPlane *dataplane)
+{
+ if (!dataplane || !dataplane->event_channel) {
+ return;
+ }
+
+ /* Only reason for failure is a NULL channel */
+ xen_device_set_event_channel_context(dataplane->xendev,
+ dataplane->event_channel,
+ NULL, &error_abort);
+}
+
+void xen_block_dataplane_attach(XenBlockDataPlane *dataplane)
+{
+ if (!dataplane || !dataplane->event_channel) {
+ return;
+ }
+
+ /* Only reason for failure is a NULL channel */
+ xen_device_set_event_channel_context(dataplane->xendev,
+ dataplane->event_channel,
+ dataplane->ctx, &error_abort);
+}
+
void xen_block_dataplane_stop(XenBlockDataPlane *dataplane)
{
XenDevice *xendev;
@@ -674,13 +698,11 @@ void xen_block_dataplane_stop(XenBlockDataPlane *dataplane)
xendev = dataplane->xendev;
- aio_context_acquire(dataplane->ctx);
- if (dataplane->event_channel) {
- /* Only reason for failure is a NULL channel */
- xen_device_set_event_channel_context(xendev, dataplane->event_channel,
- qemu_get_aio_context(),
- &error_abort);
+ if (!blk_in_drain(dataplane->blk)) {
+ xen_block_dataplane_detach(dataplane);
}
+
+ aio_context_acquire(dataplane->ctx);
/* Xen doesn't have multiple users for nodes, so this can't fail */
blk_set_aio_context(dataplane->blk, qemu_get_aio_context(), &error_abort);
aio_context_release(dataplane->ctx);
@@ -819,11 +841,9 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane,
blk_set_aio_context(dataplane->blk, dataplane->ctx, NULL);
aio_context_release(old_context);
- /* Only reason for failure is a NULL channel */
- aio_context_acquire(dataplane->ctx);
- xen_device_set_event_channel_context(xendev, dataplane->event_channel,
- dataplane->ctx, &error_abort);
- aio_context_release(dataplane->ctx);
+ if (!blk_in_drain(dataplane->blk)) {
+ xen_block_dataplane_attach(dataplane);
+ }
return;
diff --git a/hw/block/dataplane/xen-block.h b/hw/block/dataplane/xen-block.h
index 76dcd51..7b8e9df 100644
--- a/hw/block/dataplane/xen-block.h
+++ b/hw/block/dataplane/xen-block.h
@@ -26,5 +26,7 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane,
unsigned int protocol,
Error **errp);
void xen_block_dataplane_stop(XenBlockDataPlane *dataplane);
+void xen_block_dataplane_attach(XenBlockDataPlane *dataplane);
+void xen_block_dataplane_detach(XenBlockDataPlane *dataplane);
#endif /* HW_BLOCK_DATAPLANE_XEN_BLOCK_H */
diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c
index f5a7445..f099914 100644
--- a/hw/block/xen-block.c
+++ b/hw/block/xen-block.c
@@ -189,8 +189,26 @@ static void xen_block_resize_cb(void *opaque)
xen_device_backend_printf(xendev, "state", "%u", state);
}
+/* Suspend request handling */
+static void xen_block_drained_begin(void *opaque)
+{
+ XenBlockDevice *blockdev = opaque;
+
+ xen_block_dataplane_detach(blockdev->dataplane);
+}
+
+/* Resume request handling */
+static void xen_block_drained_end(void *opaque)
+{
+ XenBlockDevice *blockdev = opaque;
+
+ xen_block_dataplane_attach(blockdev->dataplane);
+}
+
static const BlockDevOps xen_block_dev_ops = {
- .resize_cb = xen_block_resize_cb,
+ .resize_cb = xen_block_resize_cb,
+ .drained_begin = xen_block_drained_begin,
+ .drained_end = xen_block_drained_end,
};
static void xen_block_realize(XenDevice *xendev, Error **errp)
@@ -242,8 +260,6 @@ static void xen_block_realize(XenDevice *xendev, Error **errp)
return;
}
- blk_set_dev_ops(blk, &xen_block_dev_ops, blockdev);
-
if (conf->discard_granularity == -1) {
conf->discard_granularity = conf->physical_block_size;
}
@@ -277,6 +293,8 @@ static void xen_block_realize(XenDevice *xendev, Error **errp)
blockdev->dataplane =
xen_block_dataplane_create(xendev, blk, conf->logical_block_size,
blockdev->props.iothread);
+
+ blk_set_dev_ops(blk, &xen_block_dev_ops, blockdev);
}
static void xen_block_frontend_changed(XenDevice *xendev,