aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Faria <afaria@redhat.com>2022-10-29 13:20:31 +0100
committerStefan Hajnoczi <stefanha@redhat.com>2022-10-31 14:33:15 -0400
commit4c8f4fda0504564580f5c0a37e2d4b32ff17d2a1 (patch)
tree57f53b90e5d542bd6644b7a003f1336ac255bafc
parent03d9e4c0dba9d1b5d0c532ac3518415466ebdf8f (diff)
downloadqemu-4c8f4fda0504564580f5c0a37e2d4b32ff17d2a1.zip
qemu-4c8f4fda0504564580f5c0a37e2d4b32ff17d2a1.tar.gz
qemu-4c8f4fda0504564580f5c0a37e2d4b32ff17d2a1.tar.bz2
block/blkio: Tolerate device size changes
Some libblkio drivers may be able to work with regular files (e.g., io_uring) or otherwise resizable devices. Conservatively set BlockDriver::has_variable_length to true to ensure bdrv_nb_sectors() always gives up-to-date results. Also implement BlockDriver::bdrv_co_truncate for the case where no preallocation is needed and the device already has a size compatible with what was requested. Signed-off-by: Alberto Faria <afaria@redhat.com> Message-id: 20221029122031.975273-1-afaria@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
-rw-r--r--block/blkio.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/block/blkio.c b/block/blkio.c
index f55eb77..d850506 100644
--- a/block/blkio.c
+++ b/block/blkio.c
@@ -848,6 +848,31 @@ static int64_t blkio_getlength(BlockDriverState *bs)
return capacity;
}
+static int coroutine_fn blkio_truncate(BlockDriverState *bs, int64_t offset,
+ bool exact, PreallocMode prealloc,
+ BdrvRequestFlags flags, Error **errp)
+{
+ int64_t current_length;
+
+ if (prealloc != PREALLOC_MODE_OFF) {
+ error_setg(errp, "Unsupported preallocation mode '%s'",
+ PreallocMode_str(prealloc));
+ return -ENOTSUP;
+ }
+
+ current_length = blkio_getlength(bs);
+
+ if (offset > current_length) {
+ error_setg(errp, "Cannot grow device");
+ return -EINVAL;
+ } else if (exact && offset != current_length) {
+ error_setg(errp, "Cannot resize device");
+ return -ENOTSUP;
+ }
+
+ return 0;
+}
+
static int blkio_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
{
return 0;
@@ -963,10 +988,12 @@ static void blkio_refresh_limits(BlockDriverState *bs, Error **errp)
{ \
.format_name = name, \
.protocol_name = name, \
+ .has_variable_length = true, \
.instance_size = sizeof(BDRVBlkioState), \
.bdrv_file_open = blkio_file_open, \
.bdrv_close = blkio_close, \
.bdrv_getlength = blkio_getlength, \
+ .bdrv_co_truncate = blkio_truncate, \
.bdrv_get_info = blkio_get_info, \
.bdrv_attach_aio_context = blkio_attach_aio_context, \
.bdrv_detach_aio_context = blkio_detach_aio_context, \