From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
To: qemu-block@nongnu.org
Cc: Stefan Hajnoczi <stefanha@redhat.com>,
Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <fam@euphon.net>,
qemu-devel@nongnu.org,
Emanuele Giuseppe Esposito <eesposit@redhat.com>
Subject: [PATCH 2/2] virtio-blk: replace dataplane_start/stopping/started with enum
Date: Mon, 8 Aug 2022 05:41:47 -0400 [thread overview]
Message-ID: <20220808094147.612472-3-eesposit@redhat.com> (raw)
In-Reply-To: <20220808094147.612472-1-eesposit@redhat.com>
Virtio-blk uses VirtIOBlockDataPlane and VirtIOBlock to keep track of
the dataplane flags. This is completely unnecessary, as both structures
are always accessed together and we can simplify the sages with an enum.
Read/write the enum atomically, as it can be read also by iothread
callbacks.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
hw/block/dataplane/virtio-blk.c | 24 +++++++++---------------
hw/block/virtio-blk.c | 9 +++++----
include/hw/virtio/virtio-blk.h | 2 +-
3 files changed, 15 insertions(+), 20 deletions(-)
diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
index 49276e46f2..427f946859 100644
--- a/hw/block/dataplane/virtio-blk.c
+++ b/hw/block/dataplane/virtio-blk.c
@@ -27,9 +27,6 @@
#include "qom/object_interfaces.h"
struct VirtIOBlockDataPlane {
- bool starting;
- bool stopping;
-
VirtIOBlkConf *conf;
VirtIODevice *vdev;
QEMUBH *bh; /* bh for guest notification */
@@ -145,7 +142,7 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s)
}
vblk = VIRTIO_BLK(s->vdev);
- assert(!vblk->dataplane_started);
+ assert(qatomic_read(&vblk->dataplane_state) != DATAPLANE_STARTED);
g_free(s->batch_notify_vqs);
qemu_bh_delete(s->bh);
if (s->iothread) {
@@ -167,11 +164,11 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)
Error *local_err = NULL;
int r;
- if (vblk->dataplane_started || s->starting) {
+ if (qatomic_read(&vblk->dataplane_state) <= DATAPLANE_STARTED) {
return 0;
}
- s->starting = true;
+ qatomic_set(&vblk->dataplane_state, DATAPLANE_STARTING);
if (!virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
s->batch_notifications = true;
@@ -219,8 +216,7 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)
memory_region_transaction_commit();
- s->starting = false;
- vblk->dataplane_started = true;
+ qatomic_set(&vblk->dataplane_state, DATAPLANE_STARTED);
trace_virtio_blk_data_plane_start(s);
old_context = blk_get_aio_context(s->conf->conf.blk);
@@ -273,8 +269,7 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)
*/
virtio_blk_process_queued_requests(vblk, false);
vblk->dataplane_disabled = true;
- s->starting = false;
- vblk->dataplane_started = true;
+ qatomic_set(&vblk->dataplane_state, DATAPLANE_STARTED);
return -ENOSYS;
}
@@ -304,17 +299,17 @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev)
unsigned i;
unsigned nvqs = s->conf->num_queues;
- if (!vblk->dataplane_started || s->stopping) {
+ if (qatomic_read(&vblk->dataplane_state) != DATAPLANE_STARTED) {
return;
}
/* Better luck next time. */
if (vblk->dataplane_disabled) {
vblk->dataplane_disabled = false;
- vblk->dataplane_started = false;
+ qatomic_set(&vblk->dataplane_state, DATAPLANE_STOPPED);
return;
}
- s->stopping = true;
+ qatomic_set(&vblk->dataplane_state, DATAPLANE_STOPPING);
trace_virtio_blk_data_plane_stop(s);
aio_context_acquire(s->ctx);
@@ -352,6 +347,5 @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev)
/* Clean up guest notifier (irq) */
k->set_guest_notifiers(qbus->parent, nvqs, false);
- vblk->dataplane_started = false;
- s->stopping = false;
+ qatomic_set(&vblk->dataplane_state, DATAPLANE_STOPPED);
}
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index e9ba752f6b..a53c4a1063 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -84,7 +84,8 @@ static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status)
iov_discard_undo(&req->inhdr_undo);
iov_discard_undo(&req->outhdr_undo);
virtqueue_push(req->vq, &req->elem, req->in_len);
- if (s->dataplane_started && !s->dataplane_disabled) {
+ if (qatomic_read(&s->dataplane_state) == DATAPLANE_STARTED &&
+ !s->dataplane_disabled) {
virtio_blk_data_plane_notify(s->dataplane, req->vq);
} else {
virtio_notify(vdev, req->vq);
@@ -807,7 +808,7 @@ static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
{
VirtIOBlock *s = (VirtIOBlock *)vdev;
- if (s->dataplane && !s->dataplane_started) {
+ if (s->dataplane && qatomic_read(&s->dataplane_state) > DATAPLANE_STARTED) {
/* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start
* dataplane here instead of waiting for .set_status().
*/
@@ -907,7 +908,7 @@ static void virtio_blk_reset(VirtIODevice *vdev)
aio_context_release(ctx);
- assert(!s->dataplane_started);
+ assert(qatomic_read(&s->dataplane_state) != DATAPLANE_STARTED);
blk_set_enable_write_cache(s->blk, s->original_wce);
}
@@ -1033,7 +1034,7 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
VirtIOBlock *s = VIRTIO_BLK(vdev);
if (!(status & (VIRTIO_CONFIG_S_DRIVER | VIRTIO_CONFIG_S_DRIVER_OK))) {
- assert(!s->dataplane_started);
+ assert(qatomic_read(&s->dataplane_state) != DATAPLANE_STARTED);
}
if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h
index d311c57cca..3ac66a1f77 100644
--- a/include/hw/virtio/virtio-blk.h
+++ b/include/hw/virtio/virtio-blk.h
@@ -60,7 +60,7 @@ struct VirtIOBlock {
bool original_wce;
VMChangeStateEntry *change;
bool dataplane_disabled;
- bool dataplane_started;
+ enum VirtIODataplaneStates dataplane_state;
struct VirtIOBlockDataPlane *dataplane;
uint64_t host_features;
size_t config_size;
--
2.31.1
next prev parent reply other threads:[~2022-08-08 9:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-08 9:41 [PATCH 0/2] virtio-blk and scsi: replace dataplane_{start/stopping/started} Emanuele Giuseppe Esposito
2022-08-08 9:41 ` [PATCH 1/2] virtio-scsi: replace VirtIOBlock dataplane_{start/starting/stopped} with enum Emanuele Giuseppe Esposito
2022-08-08 15:43 ` Stefan Hajnoczi
2022-08-08 9:41 ` Emanuele Giuseppe Esposito [this message]
2022-08-08 15:43 ` [PATCH 2/2] virtio-blk: replace dataplane_start/stopping/started " Stefan Hajnoczi
2022-08-08 15:52 ` [PATCH 0/2] virtio-blk and scsi: replace dataplane_{start/stopping/started} Stefan Hajnoczi
2022-08-08 16:29 ` Stefan Hajnoczi
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=20220808094147.612472-3-eesposit@redhat.com \
--to=eesposit@redhat.com \
--cc=fam@euphon.net \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).