[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 28/31] block.c: assert BQL lock held in bdrv_co_invalidate_cac
From: |
Emanuele Giuseppe Esposito |
Subject: |
[PATCH v5 28/31] block.c: assert BQL lock held in bdrv_co_invalidate_cache |
Date: |
Wed, 24 Nov 2021 01:44:15 -0500 |
bdrv_co_invalidate_cache is special: it is an I/O function,
but uses the block layer permission API, which is GS.
Because of this, we can assert that either the function is
being called with BQL held, and thus can use the permission API,
or make sure that the permission API is not used, by ensuring that
bs (and parents) .open_flags does not contain BDRV_O_INACTIVE.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
block.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/block.c b/block.c
index a0309f827d..805974676b 100644
--- a/block.c
+++ b/block.c
@@ -6574,6 +6574,26 @@ void bdrv_init_with_whitelist(void)
bdrv_init();
}
+static bool bdrv_is_active(BlockDriverState *bs)
+{
+ BdrvChild *parent;
+
+ if (bs->open_flags & BDRV_O_INACTIVE) {
+ return false;
+ }
+
+ QLIST_FOREACH(parent, &bs->parents, next_parent) {
+ if (parent->klass->parent_is_bds) {
+ BlockDriverState *parent_bs = parent->opaque;
+ if (!bdrv_is_active(parent_bs)) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp)
{
BdrvChild *child, *parent;
@@ -6585,6 +6605,12 @@ int coroutine_fn
bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp)
return -ENOMEDIUM;
}
+ /*
+ * No need to muck with permissions if bs is active.
+ * TODO: should activation be a separate function?
+ */
+ assert(qemu_in_main_thread() || bdrv_is_active(bs));
+
QLIST_FOREACH(child, &bs->children, next) {
bdrv_co_invalidate_cache(child->bs, &local_err);
if (local_err) {
--
2.27.0
- [PATCH v5 16/31] include/sysemu/blockdev.h: global state API, (continued)
- [PATCH v5 16/31] include/sysemu/blockdev.h: global state API, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 18/31] include/block/snapshot: global state API + assertions, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 22/31] block_int-common.h: assertion in the callers of BlockDriver function pointers, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 24/31] block_int-common.h: assertions in the callers of BdrvChildClass function pointers, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 23/31] block_int-common.h: split function pointers in BdrvChildClass, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 20/31] block/coroutines: I/O API, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 26/31] job.h: split function pointers in JobDriver, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 21/31] block_int-common.h: split function pointers in BlockDriver, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 25/31] block-backend-common.h: split function pointers in BlockDevOps, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 27/31] job.h: assertions in the callers of JobDriver funcion pointers, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 28/31] block.c: assert BQL lock held in bdrv_co_invalidate_cache,
Emanuele Giuseppe Esposito <=
- [PATCH v5 30/31] crypto: delegate permission functions to JobDriver .pre_run, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 31/31] block.c: assertions to the block layer permissions API, Emanuele Giuseppe Esposito, 2021/11/24
- [PATCH v5 29/31] jobs: introduce pre_run function in JobDriver, Emanuele Giuseppe Esposito, 2021/11/24
- Re: [PATCH v5 00/31] block layer: split block APIs in global state and I/O, Stefan Hajnoczi, 2021/11/29