[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 11/14] block: Convert bdrv_eject() to co_wrapper
From: |
Kevin Wolf |
Subject: |
[PATCH 11/14] block: Convert bdrv_eject() to co_wrapper |
Date: |
Tue, 13 Dec 2022 09:53:17 +0100 |
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
bdrv_eject() is categorized as an I/O function, and it currently
doesn't run in a coroutine. We should let it take a graph rdlock since
it traverses the block nodes graph, which however is only possible in a
coroutine.
The only caller of this function is blk_eject(). Therefore make
blk_eject() a co_wrapper, so that it always creates a new coroutine, and
then make bdrv_eject() coroutine_fn where the lock can be taken.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
include/block/block-io.h | 3 ++-
include/block/block_int-common.h | 2 +-
include/sysemu/block-backend-io.h | 4 +++-
block.c | 2 +-
block/block-backend.c | 4 ++--
block/copy-on-read.c | 2 +-
block/filter-compress.c | 2 +-
block/raw-format.c | 2 +-
8 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/include/block/block-io.h b/include/block/block-io.h
index e27dc9787b..f3d49ea05f 100644
--- a/include/block/block-io.h
+++ b/include/block/block-io.h
@@ -144,7 +144,8 @@ bool coroutine_fn bdrv_co_is_inserted(BlockDriverState *bs);
bool co_wrapper bdrv_is_inserted(BlockDriverState *bs);
void bdrv_lock_medium(BlockDriverState *bs, bool locked);
-void bdrv_eject(BlockDriverState *bs, bool eject_flag);
+void coroutine_fn bdrv_co_eject(BlockDriverState *bs, bool eject_flag);
+
const char *bdrv_get_format_name(BlockDriverState *bs);
bool bdrv_supports_compressed_writes(BlockDriverState *bs);
diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h
index b954b3cb36..fd31b37567 100644
--- a/include/block/block_int-common.h
+++ b/include/block/block_int-common.h
@@ -711,7 +711,7 @@ struct BlockDriver {
/* removable device specific */
bool coroutine_fn (*bdrv_is_inserted)(BlockDriverState *bs);
- void (*bdrv_eject)(BlockDriverState *bs, bool eject_flag);
+ void coroutine_fn (*bdrv_eject)(BlockDriverState *bs, bool eject_flag);
void (*bdrv_lock_medium)(BlockDriverState *bs, bool locked);
/* to control generic scsi devices */
diff --git a/include/sysemu/block-backend-io.h
b/include/sysemu/block-backend-io.h
index a1eac6c00a..00209625e1 100644
--- a/include/sysemu/block-backend-io.h
+++ b/include/sysemu/block-backend-io.h
@@ -59,7 +59,9 @@ bool co_wrapper_mixed blk_is_inserted(BlockBackend *blk);
bool blk_is_available(BlockBackend *blk);
void blk_lock_medium(BlockBackend *blk, bool locked);
-void blk_eject(BlockBackend *blk, bool eject_flag);
+
+void coroutine_fn blk_co_eject(BlockBackend *blk, bool eject_flag);
+void co_wrapper blk_eject(BlockBackend *blk, bool eject_flag);
int64_t coroutine_fn blk_co_getlength(BlockBackend *blk);
int64_t co_wrapper_mixed blk_getlength(BlockBackend *blk);
diff --git a/block.c b/block.c
index a7b9da6a7e..11647e49db 100644
--- a/block.c
+++ b/block.c
@@ -6820,7 +6820,7 @@ bool coroutine_fn bdrv_co_is_inserted(BlockDriverState
*bs)
/**
* If eject_flag is TRUE, eject the media. Otherwise, close the tray
*/
-void bdrv_eject(BlockDriverState *bs, bool eject_flag)
+void coroutine_fn bdrv_co_eject(BlockDriverState *bs, bool eject_flag)
{
BlockDriver *drv = bs->drv;
IO_CODE();
diff --git a/block/block-backend.c b/block/block-backend.c
index e4b54f7b0c..233ce6d05a 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -2009,14 +2009,14 @@ void blk_lock_medium(BlockBackend *blk, bool locked)
}
}
-void blk_eject(BlockBackend *blk, bool eject_flag)
+void coroutine_fn blk_co_eject(BlockBackend *blk, bool eject_flag)
{
BlockDriverState *bs = blk_bs(blk);
char *id;
IO_CODE();
if (bs) {
- bdrv_eject(bs, eject_flag);
+ bdrv_co_eject(bs, eject_flag);
}
/* Whether or not we ejected on the backend,
diff --git a/block/copy-on-read.c b/block/copy-on-read.c
index 74f7727a02..76f884a6ae 100644
--- a/block/copy-on-read.c
+++ b/block/copy-on-read.c
@@ -218,7 +218,7 @@ static int coroutine_fn
cor_co_pwritev_compressed(BlockDriverState *bs,
static void cor_eject(BlockDriverState *bs, bool eject_flag)
{
- bdrv_eject(bs->file->bs, eject_flag);
+ bdrv_co_eject(bs->file->bs, eject_flag);
}
diff --git a/block/filter-compress.c b/block/filter-compress.c
index 305716c86c..571e4684dd 100644
--- a/block/filter-compress.c
+++ b/block/filter-compress.c
@@ -118,7 +118,7 @@ static void compress_refresh_limits(BlockDriverState *bs,
Error **errp)
static void compress_eject(BlockDriverState *bs, bool eject_flag)
{
- bdrv_eject(bs->file->bs, eject_flag);
+ bdrv_co_eject(bs->file->bs, eject_flag);
}
diff --git a/block/raw-format.c b/block/raw-format.c
index 39a2f20df1..efe1ef0265 100644
--- a/block/raw-format.c
+++ b/block/raw-format.c
@@ -405,7 +405,7 @@ static int coroutine_fn raw_co_truncate(BlockDriverState
*bs, int64_t offset,
static void raw_eject(BlockDriverState *bs, bool eject_flag)
{
- bdrv_eject(bs->file->bs, eject_flag);
+ bdrv_co_eject(bs->file->bs, eject_flag);
}
static void raw_lock_medium(BlockDriverState *bs, bool locked)
--
2.38.1
- [PATCH 04/14] block: Rename refresh_total_sectors to bdrv_refresh_total_sectors, (continued)
- [PATCH 04/14] block: Rename refresh_total_sectors to bdrv_refresh_total_sectors, Kevin Wolf, 2022/12/13
- [PATCH 08/14] block: Convert bdrv_get_allocated_file_size() to co_wrapper, Kevin Wolf, 2022/12/13
- [PATCH 10/14] block: Convert bdrv_is_inserted() to co_wrapper, Kevin Wolf, 2022/12/13
- [PATCH 05/14] block: Convert bdrv_refresh_total_sectors() to co_wrapper_mixed, Kevin Wolf, 2022/12/13
- [PATCH 13/14] block: Convert bdrv_debug_event to co_wrapper_mixed, Kevin Wolf, 2022/12/13
- [PATCH 12/14] block: convert bdrv_lock_medium in co_wrapper, Kevin Wolf, 2022/12/13
- [PATCH 14/14] block: Rename newly converted BlockDriver IO coroutine functions, Kevin Wolf, 2022/12/13
- [PATCH 11/14] block: Convert bdrv_eject() to co_wrapper,
Kevin Wolf <=
- Re: [PATCH 00/14] block: Move more functions to coroutines, Emanuele Giuseppe Esposito, 2022/12/15