From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Emanuele Giuseppe Esposito <eesposit@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
qemu-block@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
Hanna Reitz <hreitz@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <fam@euphon.net>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [PATCH 2/8] block-backend: enable_write_cache should be atomic
Date: Tue, 8 Nov 2022 16:19:24 -0500 [thread overview]
Message-ID: <20221108211930.876142-3-stefanha@redhat.com> (raw)
In-Reply-To: <20221108211930.876142-1-stefanha@redhat.com>
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
It is read from IO_CODE and written with BQL held,
so setting it as atomic should be enough.
Also remove the aiocontext lock that was sporadically
taken around the set.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20220609143727.1151816-3-eesposit@redhat.com>
---
block/block-backend.c | 6 +++---
hw/block/virtio-blk.c | 4 ----
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/block/block-backend.c b/block/block-backend.c
index c0c7d56c8d..949418cad4 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -60,7 +60,7 @@ struct BlockBackend {
* can be used to restore those options in the new BDS on insert) */
BlockBackendRootState root_state;
- bool enable_write_cache;
+ bool enable_write_cache; /* Atomic */
/* I/O stats (display with "info blockstats"). */
BlockAcctStats stats;
@@ -1939,13 +1939,13 @@ bool blk_is_sg(BlockBackend *blk)
bool blk_enable_write_cache(BlockBackend *blk)
{
IO_CODE();
- return blk->enable_write_cache;
+ return qatomic_read(&blk->enable_write_cache);
}
void blk_set_enable_write_cache(BlockBackend *blk, bool wce)
{
IO_CODE();
- blk->enable_write_cache = wce;
+ qatomic_set(&blk->enable_write_cache, wce);
}
void blk_activate(BlockBackend *blk, Error **errp)
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index cdc6fd5979..96d00103a4 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -961,9 +961,7 @@ static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config)
memcpy(&blkcfg, config, s->config_size);
- aio_context_acquire(blk_get_aio_context(s->blk));
blk_set_enable_write_cache(s->blk, blkcfg.wce != 0);
- aio_context_release(blk_get_aio_context(s->blk));
}
static uint64_t virtio_blk_get_features(VirtIODevice *vdev, uint64_t features,
@@ -1031,11 +1029,9 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
* s->blk would erroneously be placed in writethrough mode.
*/
if (!virtio_vdev_has_feature(vdev, VIRTIO_BLK_F_CONFIG_WCE)) {
- aio_context_acquire(blk_get_aio_context(s->blk));
blk_set_enable_write_cache(s->blk,
virtio_vdev_has_feature(vdev,
VIRTIO_BLK_F_WCE));
- aio_context_release(blk_get_aio_context(s->blk));
}
}
--
2.38.1
next prev parent reply other threads:[~2022-11-08 21:21 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-08 21:19 [PATCH 0/8] virtio-blk: remove AioContext lock Stefan Hajnoczi
2022-11-08 21:19 ` [PATCH 1/8] virtio_queue_aio_attach_host_notifier: " Stefan Hajnoczi
2022-11-11 12:17 ` Emanuele Giuseppe Esposito
2022-11-08 21:19 ` Stefan Hajnoczi [this message]
2022-11-11 12:17 ` [PATCH 2/8] block-backend: enable_write_cache should be atomic Emanuele Giuseppe Esposito
2022-11-08 21:19 ` [PATCH 3/8] virtio: categorize callbacks in GS Stefan Hajnoczi
2022-11-11 12:19 ` Emanuele Giuseppe Esposito
2022-11-08 21:19 ` [PATCH 4/8] virtio-blk: mark GLOBAL_STATE_CODE functions Stefan Hajnoczi
2022-11-11 12:19 ` Emanuele Giuseppe Esposito
2022-11-08 21:19 ` [PATCH 5/8] virtio-blk: mark IO_CODE functions Stefan Hajnoczi
2022-11-11 12:20 ` Emanuele Giuseppe Esposito
2022-11-08 21:19 ` [PATCH 6/8] virtio-blk: remove unnecessary AioContext lock from function already safe Stefan Hajnoczi
2022-11-11 12:23 ` Emanuele Giuseppe Esposito
2022-11-08 21:19 ` [PATCH 7/8] virtio-blk: don't acquire AioContext in virtio_blk_handle_vq() Stefan Hajnoczi
2022-11-11 12:41 ` Emanuele Giuseppe Esposito
2022-11-08 21:19 ` [PATCH 8/8] virtio-blk: minimize virtio_blk_reset() AioContext lock region Stefan Hajnoczi
2022-11-11 12:41 ` Emanuele Giuseppe Esposito
-- strict thread matches above, loose matches on Subject: below --
2022-06-09 14:37 [PATCH 0/8] virtio-blk: removal of AioContext lock Emanuele Giuseppe Esposito
2022-06-09 14:37 ` [PATCH 2/8] block-backend: enable_write_cache should be atomic Emanuele Giuseppe Esposito
2022-07-05 14:16 ` 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=20221108211930.876142-3-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=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 \
/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).