[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 09/10] block-backend: ignore inserted state in blk_co_nb_sectors
From: |
Kevin Wolf |
Subject: |
[PULL 09/10] block-backend: ignore inserted state in blk_co_nb_sectors |
Date: |
Tue, 11 Apr 2023 17:01:46 +0200 |
From: Paolo Bonzini <pbonzini@redhat.com>
All callers of blk_co_nb_sectors (and blk_nb_sectors) are able to
handle a non-inserted CD-ROM as a zero-length file, they do not need
to raise an error.
Not using blk_co_is_available() aligns the function with
blk_co_get_geometry(), which becomes a simple wrapper for
blk_co_nb_sectors(). It will also make it possible to skip the creation
of a coroutine in the (common) case where bs->bl.has_variable_length
is false.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20230407153303.391121-8-pbonzini@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/block-backend.c | 23 ++++++++---------------
1 file changed, 8 insertions(+), 15 deletions(-)
diff --git a/block/block-backend.c b/block/block-backend.c
index 36e3a67dff..cf58d4d1b7 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1615,9 +1615,7 @@ int64_t coroutine_fn blk_co_getlength(BlockBackend *blk)
return bdrv_co_getlength(blk_bs(blk));
}
-/* return 0 as number of sectors if no device present or error */
-void coroutine_fn blk_co_get_geometry(BlockBackend *blk,
- uint64_t *nb_sectors_ptr)
+int64_t coroutine_fn blk_co_nb_sectors(BlockBackend *blk)
{
BlockDriverState *bs = blk_bs(blk);
@@ -1625,23 +1623,18 @@ void coroutine_fn blk_co_get_geometry(BlockBackend *blk,
GRAPH_RDLOCK_GUARD();
if (!bs) {
- *nb_sectors_ptr = 0;
+ return -ENOMEDIUM;
} else {
- int64_t nb_sectors = bdrv_co_nb_sectors(bs);
- *nb_sectors_ptr = nb_sectors < 0 ? 0 : nb_sectors;
+ return bdrv_co_nb_sectors(bs);
}
}
-int64_t coroutine_fn blk_co_nb_sectors(BlockBackend *blk)
+/* return 0 as number of sectors if no device present or error */
+void coroutine_fn blk_co_get_geometry(BlockBackend *blk,
+ uint64_t *nb_sectors_ptr)
{
- IO_CODE();
- GRAPH_RDLOCK_GUARD();
-
- if (!blk_co_is_available(blk)) {
- return -ENOMEDIUM;
- }
-
- return bdrv_co_nb_sectors(blk_bs(blk));
+ int64_t ret = blk_co_nb_sectors(blk);
+ *nb_sectors_ptr = ret < 0 ? 0 : ret;
}
BlockAIOCB *blk_aio_preadv(BlockBackend *blk, int64_t offset,
--
2.39.2
- [PULL 00/10] Block layer fixes for 8.0-rc4, Kevin Wolf, 2023/04/11
- [PULL 03/10] block: move has_variable_length to BlockLimits, Kevin Wolf, 2023/04/11
- [PULL 06/10] block: remove has_variable_length from BlockDriver, Kevin Wolf, 2023/04/11
- [PULL 02/10] iotests: Regression test for vhdx log corruption, Kevin Wolf, 2023/04/11
- [PULL 09/10] block-backend: ignore inserted state in blk_co_nb_sectors,
Kevin Wolf <=
- [PULL 01/10] block/vhdx: fix dynamic VHDX BAT corruption, Kevin Wolf, 2023/04/11
- [PULL 05/10] block: refresh bs->total_sectors on reopen, Kevin Wolf, 2023/04/11
- [PULL 10/10] block, block-backend: write some hot coroutine wrappers by hand, Kevin Wolf, 2023/04/11
- [PULL 04/10] block: remove has_variable_length from filters, Kevin Wolf, 2023/04/11
- [PULL 07/10] migration/block: replace uses of blk_nb_sectors that do not check result, Kevin Wolf, 2023/04/11
- [PULL 08/10] block-backend: inline bdrv_co_get_geometry, Kevin Wolf, 2023/04/11
- Re: [PULL 00/10] Block layer fixes for 8.0-rc4, Peter Maydell, 2023/04/12