[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 03/10] block: move has_variable_length to BlockLimits
From: |
Kevin Wolf |
Subject: |
[PULL 03/10] block: move has_variable_length to BlockLimits |
Date: |
Tue, 11 Apr 2023 17:01:40 +0200 |
From: Paolo Bonzini <pbonzini@redhat.com>
At the protocol level, has_variable_length only needs to be true in the
very special case of host CD-ROM drives, so that they do not need an
explicit monitor command to read the new size when a disc is loaded
in the tray.
However, at the format level has_variable_length has to be true for all
raw blockdevs and for all filters, even though in practice the length
depends on the underlying file and thus will not change except in the
case of host CD-ROM drives.
As a first step towards computing an accurate value of has_variable_length,
add the value into the BlockLimits structure and initialize the field
from the BlockDriver.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20230407153303.391121-2-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>
---
include/block/block_int-common.h | 8 ++++++++
block.c | 2 +-
block/io.c | 6 ++++++
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h
index d419017328..a6d271f25d 100644
--- a/include/block/block_int-common.h
+++ b/include/block/block_int-common.h
@@ -855,6 +855,14 @@ typedef struct BlockLimits {
/* maximum number of iovec elements */
int max_iov;
+
+ /*
+ * true if the length of the underlying file can change, and QEMU
+ * is expected to adjust automatically. Mostly for CD-ROM drives,
+ * whose length is zero when the tray is empty (they don't need
+ * an explicit monitor command to load the disk inside the guest).
+ */
+ bool has_variable_length;
} BlockLimits;
typedef struct BdrvOpBlocker BdrvOpBlocker;
diff --git a/block.c b/block.c
index e0c6c648b1..6a805ff0ea 100644
--- a/block.c
+++ b/block.c
@@ -5849,7 +5849,7 @@ int64_t coroutine_fn bdrv_co_nb_sectors(BlockDriverState
*bs)
if (!drv)
return -ENOMEDIUM;
- if (drv->has_variable_length) {
+ if (bs->bl.has_variable_length) {
int ret = bdrv_co_refresh_total_sectors(bs, bs->total_sectors);
if (ret < 0) {
return ret;
diff --git a/block/io.c b/block/io.c
index 8974d46941..932aeb5844 100644
--- a/block/io.c
+++ b/block/io.c
@@ -182,6 +182,8 @@ void bdrv_refresh_limits(BlockDriverState *bs, Transaction
*tran, Error **errp)
drv->bdrv_aio_preadv ||
drv->bdrv_co_preadv_part) ? 1 : 512;
+ bs->bl.has_variable_length = drv->has_variable_length;
+
/* Take some limits from the children as a default */
have_limits = false;
QLIST_FOREACH(c, &bs->children, next) {
@@ -190,6 +192,10 @@ void bdrv_refresh_limits(BlockDriverState *bs, Transaction
*tran, Error **errp)
bdrv_merge_limits(&bs->bl, &c->bs->bl);
have_limits = true;
}
+
+ if (c->role & BDRV_CHILD_FILTERED) {
+ bs->bl.has_variable_length |= c->bs->bl.has_variable_length;
+ }
}
if (!have_limits) {
--
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 <=
- [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, 2023/04/11
- [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