aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorEmanuele Giuseppe Esposito <eesposit@redhat.com>2023-01-13 21:42:04 +0100
committerKevin Wolf <kwolf@redhat.com>2023-02-01 16:52:32 +0100
commitc86422c5549c0983b4b4525b8f56a1c69dd67aa1 (patch)
tree9791a300734a7dda8422e6a531b2d0f592a10768 /block
parentc057960c4e33becb22d4741156203a4b0d4a3088 (diff)
block: Convert bdrv_refresh_total_sectors() to co_wrapper_mixed
BlockDriver->bdrv_getlength is categorized as IO callback, and it currently doesn't run in a coroutine. We should let it take a graph rdlock since the callback traverses the block nodes graph, which however is only possible in a coroutine. Therefore turn it into a co_wrapper to move the actual function into a coroutine where the lock can be taken. Because now this function creates a new coroutine and polls, we need to take the AioContext lock where it is missing, for the only reason that internally co_wrapper calls AIO_WAIT_WHILE and it expects to release the AioContext lock. This is especially messy when a co_wrapper creates a coroutine and polls in bdrv_open_driver, because this function has so many callers in so many context that it can easily lead to deadlocks. Therefore the new rule for bdrv_open_driver is that the caller must always hold the AioContext lock of the given bs (except if it is a coroutine), because the function calls bdrv_refresh_total_sectors() which is now a co_wrapper. Once the rwlock is ultimated and placed in every place it needs to be, we will poll using AIO_WAIT_WHILE_UNLOCKED and remove the AioContext lock. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-Id: <20230113204212.359076-7-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/blkdebug.c6
-rw-r--r--block/blkio.c6
-rw-r--r--block/blklogwrites.c6
-rw-r--r--block/blkreplay.c6
-rw-r--r--block/blkverify.c6
-rw-r--r--block/block-backend.c10
-rw-r--r--block/commit.c4
-rw-r--r--block/copy-on-read.c6
-rw-r--r--block/crypto.c6
-rw-r--r--block/curl.c10
-rw-r--r--block/file-posix.c42
-rw-r--r--block/file-win32.c8
-rw-r--r--block/filter-compress.c6
-rw-r--r--block/gluster.c12
-rw-r--r--block/iscsi.c10
-rw-r--r--block/meson.build1
-rw-r--r--block/mirror.c4
-rw-r--r--block/nbd.c8
-rw-r--r--block/null.c6
-rw-r--r--block/nvme.c6
-rw-r--r--block/preallocate.c10
-rw-r--r--block/qed.c4
-rw-r--r--block/quorum.c8
-rw-r--r--block/raw-format.c6
-rw-r--r--block/rbd.c4
-rw-r--r--block/replication.c6
-rw-r--r--block/ssh.c4
-rw-r--r--block/throttle.c6
28 files changed, 110 insertions, 107 deletions
diff --git a/block/blkdebug.c b/block/blkdebug.c
index fa38c1cf7d..e6dc0ba142 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -966,9 +966,9 @@ static bool blkdebug_debug_is_suspended(BlockDriverState *bs, const char *tag)
return false;
}
-static int64_t blkdebug_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn blkdebug_co_getlength(BlockDriverState *bs)
{
- return bdrv_getlength(bs->file->bs);
+ return bdrv_co_getlength(bs->file->bs);
}
static void blkdebug_refresh_filename(BlockDriverState *bs)
@@ -1075,7 +1075,7 @@ static BlockDriver bdrv_blkdebug = {
.bdrv_reopen_prepare = blkdebug_reopen_prepare,
.bdrv_child_perm = blkdebug_child_perm,
- .bdrv_getlength = blkdebug_getlength,
+ .bdrv_co_getlength = blkdebug_co_getlength,
.bdrv_refresh_filename = blkdebug_refresh_filename,
.bdrv_refresh_limits = blkdebug_refresh_limits,
diff --git a/block/blkio.c b/block/blkio.c
index bd53d90d58..284fb292cf 100644
--- a/block/blkio.c
+++ b/block/blkio.c
@@ -839,7 +839,7 @@ static void blkio_close(BlockDriverState *bs)
}
}
-static int64_t blkio_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn blkio_co_getlength(BlockDriverState *bs)
{
BDRVBlkioState *s = bs->opaque;
uint64_t capacity;
@@ -867,7 +867,7 @@ static int coroutine_fn blkio_truncate(BlockDriverState *bs, int64_t offset,
return -ENOTSUP;
}
- current_length = blkio_getlength(bs);
+ current_length = blkio_co_getlength(bs);
if (offset > current_length) {
error_setg(errp, "Cannot grow device");
@@ -998,7 +998,7 @@ static void blkio_refresh_limits(BlockDriverState *bs, Error **errp)
.instance_size = sizeof(BDRVBlkioState), \
.bdrv_file_open = blkio_file_open, \
.bdrv_close = blkio_close, \
- .bdrv_getlength = blkio_getlength, \
+ .bdrv_co_getlength = blkio_co_getlength, \
.bdrv_co_truncate = blkio_truncate, \
.bdrv_get_info = blkio_get_info, \
.bdrv_attach_aio_context = blkio_attach_aio_context, \
diff --git a/block/blklogwrites.c b/block/blklogwrites.c
index a5bf767184..b00b8a6dd0 100644
--- a/block/blklogwrites.c
+++ b/block/blklogwrites.c
@@ -267,9 +267,9 @@ static void blk_log_writes_close(BlockDriverState *bs)
s->log_file = NULL;
}
-static int64_t blk_log_writes_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn blk_log_writes_co_getlength(BlockDriverState *bs)
{
- return bdrv_getlength(bs->file->bs);
+ return bdrv_co_getlength(bs->file->bs);
}
static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c,
@@ -498,7 +498,7 @@ static BlockDriver bdrv_blk_log_writes = {
.bdrv_open = blk_log_writes_open,
.bdrv_close = blk_log_writes_close,
- .bdrv_getlength = blk_log_writes_getlength,
+ .bdrv_co_getlength = blk_log_writes_co_getlength,
.bdrv_child_perm = blk_log_writes_child_perm,
.bdrv_refresh_limits = blk_log_writes_refresh_limits,
diff --git a/block/blkreplay.c b/block/blkreplay.c
index e3b6a3efb2..16543f585a 100644
--- a/block/blkreplay.c
+++ b/block/blkreplay.c
@@ -40,9 +40,9 @@ fail:
return ret;
}
-static int64_t blkreplay_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn blkreplay_co_getlength(BlockDriverState *bs)
{
- return bdrv_getlength(bs->file->bs);
+ return bdrv_co_getlength(bs->file->bs);
}
/* This bh is used for synchronization of return from coroutines.
@@ -136,7 +136,7 @@ static BlockDriver bdrv_blkreplay = {
.bdrv_open = blkreplay_open,
.bdrv_child_perm = bdrv_default_perms,
- .bdrv_getlength = blkreplay_getlength,
+ .bdrv_co_getlength = blkreplay_co_getlength,
.bdrv_co_preadv = blkreplay_co_preadv,
.bdrv_co_pwritev = blkreplay_co_pwritev,
diff --git a/block/blkverify.c b/block/blkverify.c
index 0e78bc9dd6..edf1a550f2 100644
--- a/block/blkverify.c
+++ b/block/blkverify.c
@@ -155,11 +155,11 @@ static void blkverify_close(BlockDriverState *bs)
s->test_file = NULL;
}
-static int64_t blkverify_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn blkverify_co_getlength(BlockDriverState *bs)
{
BDRVBlkverifyState *s = bs->opaque;
- return bdrv_getlength(s->test_file->bs);
+ return bdrv_co_getlength(s->test_file->bs);
}
static void coroutine_fn blkverify_do_test_req(void *opaque)
@@ -314,7 +314,7 @@ static BlockDriver bdrv_blkverify = {
.bdrv_file_open = blkverify_open,
.bdrv_close = blkverify_close,
.bdrv_child_perm = bdrv_default_perms,
- .bdrv_getlength = blkverify_getlength,
+ .bdrv_co_getlength = blkverify_co_getlength,
.bdrv_refresh_filename = blkverify_refresh_filename,
.bdrv_dirname = blkverify_dirname,
diff --git a/block/block-backend.c b/block/block-backend.c
index 7ba436811b..d698cc3f33 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1599,14 +1599,15 @@ BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, int64_t offset,
flags | BDRV_REQ_ZERO_WRITE, cb, opaque);
}
-int64_t blk_getlength(BlockBackend *blk)
+int64_t coroutine_fn blk_co_getlength(BlockBackend *blk)
{
IO_CODE();
+
if (!blk_is_available(blk)) {
return -ENOMEDIUM;
}
- return bdrv_getlength(blk_bs(blk));
+ return bdrv_co_getlength(blk_bs(blk));
}
void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr)
@@ -1619,14 +1620,15 @@ void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr)
}
}
-int64_t blk_nb_sectors(BlockBackend *blk)
+int64_t coroutine_fn blk_co_nb_sectors(BlockBackend *blk)
{
IO_CODE();
+
if (!blk_is_available(blk)) {
return -ENOMEDIUM;
}
- return bdrv_nb_sectors(blk_bs(blk));
+ return bdrv_co_nb_sectors(blk_bs(blk));
}
BlockAIOCB *blk_aio_preadv(BlockBackend *blk, int64_t offset,
diff --git a/block/commit.c b/block/commit.c
index b346341767..41e3599281 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -123,13 +123,13 @@ static int coroutine_fn commit_run(Job *job, Error **errp)
QEMU_AUTO_VFREE void *buf = NULL;
int64_t len, base_len;
- len = blk_getlength(s->top);
+ len = blk_co_getlength(s->top);
if (len < 0) {
return len;
}
job_progress_set_remaining(&s->common.job, len);
- base_len = blk_getlength(s->base);
+ base_len = blk_co_getlength(s->base);
if (base_len < 0) {
return base_len;
}
diff --git a/block/copy-on-read.c b/block/copy-on-read.c
index 13ed4150a6..8cad979e29 100644
--- a/block/copy-on-read.c
+++ b/block/copy-on-read.c
@@ -121,9 +121,9 @@ static void cor_child_perm(BlockDriverState *bs, BdrvChild *c,
}
-static int64_t cor_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn cor_co_getlength(BlockDriverState *bs)
{
- return bdrv_getlength(bs->file->bs);
+ return bdrv_co_getlength(bs->file->bs);
}
@@ -250,7 +250,7 @@ static BlockDriver bdrv_copy_on_read = {
.bdrv_close = cor_close,
.bdrv_child_perm = cor_child_perm,
- .bdrv_getlength = cor_getlength,
+ .bdrv_co_getlength = cor_co_getlength,
.bdrv_co_preadv_part = cor_co_preadv_part,
.bdrv_co_pwritev_part = cor_co_pwritev_part,
diff --git a/block/crypto.c b/block/crypto.c
index bbeb9f437c..6d6c006887 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -531,10 +531,10 @@ static void block_crypto_refresh_limits(BlockDriverState *bs, Error **errp)
}
-static int64_t block_crypto_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn block_crypto_co_getlength(BlockDriverState *bs)
{
BlockCrypto *crypto = bs->opaque;
- int64_t len = bdrv_getlength(bs->file->bs);
+ int64_t len = bdrv_co_getlength(bs->file->bs);
uint64_t offset = qcrypto_block_get_payload_offset(crypto->block);
assert(offset < INT64_MAX);
@@ -953,7 +953,7 @@ static BlockDriver bdrv_crypto_luks = {
.bdrv_refresh_limits = block_crypto_refresh_limits,
.bdrv_co_preadv = block_crypto_co_preadv,
.bdrv_co_pwritev = block_crypto_co_pwritev,
- .bdrv_getlength = block_crypto_getlength,
+ .bdrv_co_getlength = block_crypto_co_getlength,
.bdrv_measure = block_crypto_measure,
.bdrv_get_info = block_crypto_get_info_luks,
.bdrv_get_specific_info = block_crypto_get_specific_info_luks,
diff --git a/block/curl.c b/block/curl.c
index bf45fa3244..cbada22e9e 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -958,7 +958,7 @@ static void curl_close(BlockDriverState *bs)
g_free(s->proxypassword);
}
-static int64_t curl_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn curl_co_getlength(BlockDriverState *bs)
{
BDRVCURLState *s = bs->opaque;
return s->len;
@@ -1002,7 +1002,7 @@ static BlockDriver bdrv_http = {
.bdrv_parse_filename = curl_parse_filename,
.bdrv_file_open = curl_open,
.bdrv_close = curl_close,
- .bdrv_getlength = curl_getlength,
+ .bdrv_co_getlength = curl_co_getlength,
.bdrv_co_preadv = curl_co_preadv,
@@ -1021,7 +1021,7 @@ static BlockDriver bdrv_https = {
.bdrv_parse_filename = curl_parse_filename,
.bdrv_file_open = curl_open,
.bdrv_close = curl_close,
- .bdrv_getlength = curl_getlength,
+ .bdrv_co_getlength = curl_co_getlength,
.bdrv_co_preadv = curl_co_preadv,
@@ -1040,7 +1040,7 @@ static BlockDriver bdrv_ftp = {
.bdrv_parse_filename = curl_parse_filename,
.bdrv_file_open = curl_open,
.bdrv_close = curl_close,
- .bdrv_getlength = curl_getlength,
+ .bdrv_co_getlength = curl_co_getlength,
.bdrv_co_preadv = curl_co_preadv,
@@ -1059,7 +1059,7 @@ static BlockDriver bdrv_ftps = {
.bdrv_parse_filename = curl_parse_filename,
.bdrv_file_open = curl_open,
.bdrv_close = curl_close,
- .bdrv_getlength = curl_getlength,
+ .bdrv_co_getlength = curl_co_getlength,
.bdrv_co_preadv = curl_co_preadv,
diff --git a/block/file-posix.c b/block/file-posix.c
index 433a25fc91..b8a42601e9 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -189,7 +189,7 @@ static int fd_open(BlockDriverState *bs)
return -EIO;
}
-static int64_t raw_getlength(BlockDriverState *bs);
+static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs);
typedef struct RawPosixAIOData {
BlockDriverState *bs;
@@ -2280,7 +2280,7 @@ static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
}
if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
- int64_t cur_length = raw_getlength(bs);
+ int64_t cur_length = raw_co_getlength(bs);
if (offset != cur_length && exact) {
error_setg(errp, "Cannot resize device files");
@@ -2298,7 +2298,7 @@ static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
}
#ifdef __OpenBSD__
-static int64_t raw_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
{
BDRVRawState *s = bs->opaque;
int fd = s->fd;
@@ -2317,7 +2317,7 @@ static int64_t raw_getlength(BlockDriverState *bs)
return st.st_size;
}
#elif defined(__NetBSD__)
-static int64_t raw_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
{
BDRVRawState *s = bs->opaque;
int fd = s->fd;
@@ -2342,7 +2342,7 @@ static int64_t raw_getlength(BlockDriverState *bs)
return st.st_size;
}
#elif defined(__sun__)
-static int64_t raw_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
{
BDRVRawState *s = bs->opaque;
struct dk_minfo minfo;
@@ -2373,7 +2373,7 @@ static int64_t raw_getlength(BlockDriverState *bs)
return size;
}
#elif defined(CONFIG_BSD)
-static int64_t raw_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
{
BDRVRawState *s = bs->opaque;
int fd = s->fd;
@@ -2445,7 +2445,7 @@ again:
return size;
}
#else
-static int64_t raw_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
{
BDRVRawState *s = bs->opaque;
int ret;
@@ -2830,7 +2830,7 @@ static int coroutine_fn raw_co_block_status(BlockDriverState *bs,
* round up if necessary.
*/
if (!QEMU_IS_ALIGNED(*pnum, bs->bl.request_alignment)) {
- int64_t file_length = raw_getlength(bs);
+ int64_t file_length = raw_co_getlength(bs);
if (file_length > 0) {
/* Ignore errors, this is just a safeguard */
assert(hole == file_length);
@@ -2852,7 +2852,7 @@ static int coroutine_fn raw_co_block_status(BlockDriverState *bs,
#if defined(__linux__)
/* Verify that the file is not in the page cache */
-static void check_cache_dropped(BlockDriverState *bs, Error **errp)
+static void coroutine_fn check_cache_dropped(BlockDriverState *bs, Error **errp)
{
const size_t window_size = 128 * 1024 * 1024;
BDRVRawState *s = bs->opaque;
@@ -2867,7 +2867,7 @@ static void check_cache_dropped(BlockDriverState *bs, Error **errp)
page_size = sysconf(_SC_PAGESIZE);
vec = g_malloc(DIV_ROUND_UP(window_size, page_size));
- end = raw_getlength(bs);
+ end = raw_co_getlength(bs);
for (offset = 0; offset < end; offset += window_size) {
void *new_window;
@@ -3321,8 +3321,8 @@ BlockDriver bdrv_file = {
.bdrv_co_io_unplug = raw_co_io_unplug,
.bdrv_attach_aio_context = raw_aio_attach_aio_context,
- .bdrv_co_truncate = raw_co_truncate,
- .bdrv_getlength = raw_getlength,
+ .bdrv_co_truncate = raw_co_truncate,
+ .bdrv_co_getlength = raw_co_getlength,
.bdrv_get_info = raw_get_info,
.bdrv_get_allocated_file_size
= raw_get_allocated_file_size,
@@ -3693,8 +3693,8 @@ static BlockDriver bdrv_host_device = {
.bdrv_co_io_unplug = raw_co_io_unplug,
.bdrv_attach_aio_context = raw_aio_attach_aio_context,
- .bdrv_co_truncate = raw_co_truncate,
- .bdrv_getlength = raw_getlength,
+ .bdrv_co_truncate = raw_co_truncate,
+ .bdrv_co_getlength = raw_co_getlength,
.bdrv_get_info = raw_get_info,
.bdrv_get_allocated_file_size
= raw_get_allocated_file_size,
@@ -3817,9 +3817,9 @@ static BlockDriver bdrv_host_cdrom = {
.bdrv_co_io_unplug = raw_co_io_unplug,
.bdrv_attach_aio_context = raw_aio_attach_aio_context,
- .bdrv_co_truncate = raw_co_truncate,
- .bdrv_getlength = raw_getlength,
- .has_variable_length = true,
+ .bdrv_co_truncate = raw_co_truncate,
+ .bdrv_co_getlength = raw_co_getlength,
+ .has_variable_length = true,
.bdrv_get_allocated_file_size
= raw_get_allocated_file_size,
@@ -3885,7 +3885,7 @@ static int cdrom_reopen(BlockDriverState *bs)
static bool coroutine_fn cdrom_co_is_inserted(BlockDriverState *bs)
{
- return raw_getlength(bs) > 0;
+ return raw_co_getlength(bs) > 0;
}
static void cdrom_eject(BlockDriverState *bs, bool eject_flag)
@@ -3947,9 +3947,9 @@ static BlockDriver bdrv_host_cdrom = {
.bdrv_co_io_unplug = raw_co_io_unplug,
.bdrv_attach_aio_context = raw_aio_attach_aio_context,
- .bdrv_co_truncate = raw_co_truncate,
- .bdrv_getlength = raw_getlength,
- .has_variable_length = true,
+ .bdrv_co_truncate = raw_co_truncate,
+ .bdrv_co_getlength = raw_co_getlength,
+ .has_variable_length = true,
.bdrv_get_allocated_file_size
= raw_get_allocated_file_size,
diff --git a/block/file-win32.c b/block/file-win32.c
index 12be9c3d0f..61a3aa27a7 100644
--- a/block/file-win32.c
+++ b/block/file-win32.c
@@ -526,7 +526,7 @@ static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
return 0;
}
-static int64_t raw_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
{
BDRVRawState *s = bs->opaque;
LARGE_INTEGER l;
@@ -764,7 +764,7 @@ BlockDriver bdrv_file = {
.bdrv_aio_flush = raw_aio_flush,
.bdrv_co_truncate = raw_co_truncate,
- .bdrv_getlength = raw_getlength,
+ .bdrv_co_getlength = raw_co_getlength,
.bdrv_get_allocated_file_size
= raw_get_allocated_file_size,
@@ -933,8 +933,8 @@ static BlockDriver bdrv_host_device = {
.bdrv_detach_aio_context = raw_detach_aio_context,
.bdrv_attach_aio_context = raw_attach_aio_context,
- .bdrv_getlength = raw_getlength,
- .has_variable_length = true,
+ .bdrv_co_getlength = raw_co_getlength,
+ .has_variable_length = true,
.bdrv_get_allocated_file_size
= raw_get_allocated_file_size,
diff --git a/block/filter-compress.c b/block/filter-compress.c
index 0ff8d28661..bcf76ac910 100644
--- a/block/filter-compress.c
+++ b/block/filter-compress.c
@@ -55,9 +55,9 @@ static int compress_open(BlockDriverState *bs, QDict *options, int flags,
}
-static int64_t compress_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn compress_co_getlength(BlockDriverState *bs)
{
- return bdrv_getlength(bs->file->bs);
+ return bdrv_co_getlength(bs->file->bs);
}
@@ -135,7 +135,7 @@ static BlockDriver bdrv_compress = {
.bdrv_open = compress_open,
.bdrv_child_perm = bdrv_default_perms,
- .bdrv_getlength = compress_getlength,
+ .bdrv_co_getlength = compress_co_getlength,
.bdrv_co_preadv_part = compress_co_preadv_part,
.bdrv_co_pwritev_part = compress_co_pwritev_part,
diff --git a/block/gluster.c b/block/gluster.c
index 1ad19ae915..0b325e4292 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -1318,7 +1318,7 @@ static coroutine_fn int qemu_gluster_co_pdiscard(BlockDriverState *bs,
}
#endif
-static int64_t qemu_gluster_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn qemu_gluster_co_getlength(BlockDriverState *bs)
{
BDRVGlusterState *s = bs->opaque;
int64_t ret;
@@ -1510,7 +1510,7 @@ static int coroutine_fn qemu_gluster_co_block_status(BlockDriverState *bs,
* round up if necessary.
*/
if (!QEMU_IS_ALIGNED(*pnum, bs->bl.request_alignment)) {
- int64_t file_length = qemu_gluster_getlength(bs);
+ int64_t file_length = qemu_gluster_co_getlength(bs);
if (file_length > 0) {
/* Ignore errors, this is just a safeguard */
assert(hole == file_length);
@@ -1559,7 +1559,7 @@ static BlockDriver bdrv_gluster = {
.bdrv_close = qemu_gluster_close,
.bdrv_co_create = qemu_gluster_co_create,
.bdrv_co_create_opts = qemu_gluster_co_create_opts,
- .bdrv_getlength = qemu_gluster_getlength,
+ .bdrv_co_getlength = qemu_gluster_co_getlength,
.bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
.bdrv_co_truncate = qemu_gluster_co_truncate,
.bdrv_co_readv = qemu_gluster_co_readv,
@@ -1588,7 +1588,7 @@ static BlockDriver bdrv_gluster_tcp = {
.bdrv_close = qemu_gluster_close,
.bdrv_co_create = qemu_gluster_co_create,
.bdrv_co_create_opts = qemu_gluster_co_create_opts,
- .bdrv_getlength = qemu_gluster_getlength,
+ .bdrv_co_getlength = qemu_gluster_co_getlength,
.bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
.bdrv_co_truncate = qemu_gluster_co_truncate,
.bdrv_co_readv = qemu_gluster_co_readv,
@@ -1617,7 +1617,7 @@ static BlockDriver bdrv_gluster_unix = {
.bdrv_close = qemu_gluster_close,
.bdrv_co_create = qemu_gluster_co_create,
.bdrv_co_create_opts = qemu_gluster_co_create_opts,
- .bdrv_getlength = qemu_gluster_getlength,
+ .bdrv_co_getlength = qemu_gluster_co_getlength,
.bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
.bdrv_co_truncate = qemu_gluster_co_truncate,
.bdrv_co_readv = qemu_gluster_co_readv,
@@ -1652,7 +1652,7 @@ static BlockDriver bdrv_gluster_rdma = {
.bdrv_close = qemu_gluster_close,
.bdrv_co_create = qemu_gluster_co_create,
.bdrv_co_create_opts = qemu_gluster_co_create_opts,
- .bdrv_getlength = qemu_gluster_getlength,
+ .bdrv_co_getlength = qemu_gluster_co_getlength,
.bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
.bdrv_co_truncate = qemu_gluster_co_truncate,
.bdrv_co_readv = qemu_gluster_co_readv,
diff --git a/block/iscsi.c b/block/iscsi.c
index c16c592042..359b532a33 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1127,8 +1127,8 @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
#endif
-static int64_t
-iscsi_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn
+iscsi_co_getlength(BlockDriverState *bs)
{
IscsiLun *iscsilun = bs->opaque;
int64_t len;
@@ -2155,7 +2155,7 @@ static int coroutine_fn iscsi_co_truncate(BlockDriverState *bs, int64_t offset,
return -EIO;
}
- cur_length = iscsi_getlength(bs);
+ cur_length = iscsi_co_getlength(bs);
if (offset != cur_length && exact) {
error_setg(errp, "Cannot resize iSCSI devices");
return -ENOTSUP;
@@ -2434,7 +2434,7 @@ static BlockDriver bdrv_iscsi = {
.bdrv_reopen_commit = iscsi_reopen_commit,
.bdrv_co_invalidate_cache = iscsi_co_invalidate_cache,
- .bdrv_getlength = iscsi_getlength,
+ .bdrv_co_getlength = iscsi_co_getlength,
.bdrv_get_info = iscsi_get_info,
.bdrv_co_truncate = iscsi_co_truncate,
.bdrv_refresh_limits = iscsi_refresh_limits,
@@ -2473,7 +2473,7 @@ static BlockDriver bdrv_iser = {
.bdrv_reopen_commit = iscsi_reopen_commit,
.bdrv_co_invalidate_cache = iscsi_co_invalidate_cache,
- .bdrv_getlength = iscsi_getlength,
+ .bdrv_co_getlength = iscsi_co_getlength,
.bdrv_get_info = iscsi_get_info,
.bdrv_co_truncate = iscsi_co_truncate,
.bdrv_refresh_limits = iscsi_refresh_limits,
diff --git a/block/meson.build b/block/meson.build
index 90011a2805..3662852dc2 100644
--- a/block/meson.build
+++ b/block/meson.build
@@ -139,6 +139,7 @@ block_gen_c = custom_target('block-gen.c',
input: files(
'../include/block/block-io.h',
'../include/block/dirty-bitmap.h',
+ '../include/block/block_int-io.h',
'../include/block/block-global-state.h',
'../include/sysemu/block-backend-io.h',
'coroutines.h'
diff --git a/block/mirror.c b/block/mirror.c
index 634815d78d..7ed4dbde04 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -910,13 +910,13 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
goto immediate_exit;
}
- s->bdev_length = bdrv_getlength(bs);
+ s->bdev_length = bdrv_co_getlength(bs);
if (s->bdev_length < 0) {
ret = s->bdev_length;
goto immediate_exit;
}
- target_length = blk_getlength(s->target);
+ target_length = blk_co_getlength(s->target);
if (target_length < 0) {
ret = target_length;
goto immediate_exit;
diff --git a/block/nbd.c b/block/nbd.c
index 7d485c86d2..bf2894ad5c 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -1992,7 +1992,7 @@ static int coroutine_fn nbd_co_truncate(BlockDriverState *bs, int64_t offset,
return 0;
}
-static int64_t nbd_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn nbd_co_getlength(BlockDriverState *bs)
{
BDRVNBDState *s = bs->opaque;
@@ -2124,7 +2124,7 @@ static BlockDriver bdrv_nbd = {
.bdrv_co_pdiscard = nbd_client_co_pdiscard,
.bdrv_refresh_limits = nbd_refresh_limits,
.bdrv_co_truncate = nbd_co_truncate,
- .bdrv_getlength = nbd_getlength,
+ .bdrv_co_getlength = nbd_co_getlength,
.bdrv_refresh_filename = nbd_refresh_filename,
.bdrv_co_block_status = nbd_client_co_block_status,
.bdrv_dirname = nbd_dirname,
@@ -2152,7 +2152,7 @@ static BlockDriver bdrv_nbd_tcp = {
.bdrv_co_pdiscard = nbd_client_co_pdiscard,
.bdrv_refresh_limits = nbd_refresh_limits,
.bdrv_co_truncate = nbd_co_truncate,
- .bdrv_getlength = nbd_getlength,
+ .bdrv_co_getlength = nbd_co_getlength,
.bdrv_refresh_filename = nbd_refresh_filename,
.bdrv_co_block_status = nbd_client_co_block_status,
.bdrv_dirname = nbd_dirname,
@@ -2180,7 +2180,7 @@ static BlockDriver bdrv_nbd_unix = {
.bdrv_co_pdiscard = nbd_client_co_pdiscard,
.bdrv_refresh_limits = nbd_refresh_limits,
.bdrv_co_truncate = nbd_co_truncate,
- .bdrv_getlength = nbd_getlength,
+ .bdrv_co_getlength = nbd_co_getlength,
.bdrv_refresh_filename = nbd_refresh_filename,
.bdrv_co_block_status = nbd_client_co_block_status,
.bdrv_dirname = nbd_dirname,
diff --git a/block/null.c b/block/null.c
index 306e605fa1..bc4d0c1d9d 100644
--- a/block/null.c
+++ b/block/null.c
@@ -100,7 +100,7 @@ static int null_file_open(BlockDriverState *bs, QDict *options, int flags,
return ret;
}
-static int64_t null_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn null_co_getlength(BlockDriverState *bs)
{
BDRVNullState *s = bs->opaque;
return s->length;
@@ -284,7 +284,7 @@ static BlockDriver bdrv_null_co = {
.bdrv_file_open = null_file_open,
.bdrv_parse_filename = null_co_parse_filename,
- .bdrv_getlength = null_getlength,
+ .bdrv_co_getlength = null_co_getlength,
.bdrv_get_allocated_file_size = null_allocated_file_size,
.bdrv_co_preadv = null_co_preadv,
@@ -305,7 +305,7 @@ static BlockDriver bdrv_null_aio = {
.bdrv_file_open = null_file_open,
.bdrv_parse_filename = null_aio_parse_filename,
- .bdrv_getlength = null_getlength,
+ .bdrv_co_getlength = null_co_getlength,
.bdrv_get_allocated_file_size = null_allocated_file_size,
.bdrv_aio_preadv = null_aio_preadv,
diff --git a/block/nvme.c b/block/nvme.c
index 1fe6f98925..5b744c2bda 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -1002,7 +1002,7 @@ fail:
return ret;
}
-static int64_t nvme_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn nvme_co_getlength(BlockDriverState *bs)
{
BDRVNVMeState *s = bs->opaque;
return s->nsze << s->blkshift;
@@ -1486,7 +1486,7 @@ static int coroutine_fn nvme_co_truncate(BlockDriverState *bs, int64_t offset,
return -ENOTSUP;
}
- cur_length = nvme_getlength(bs);
+ cur_length = nvme_co_getlength(bs);
if (offset != cur_length && exact) {
error_setg(errp, "Cannot resize NVMe devices");
return -ENOTSUP;
@@ -1643,7 +1643,7 @@ static BlockDriver bdrv_nvme = {
.bdrv_parse_filename = nvme_parse_filename,
.bdrv_file_open = nvme_file_open,
.bdrv_close = nvme_close,
- .bdrv_getlength = nvme_getlength,
+ .bdrv_co_getlength = nvme_co_getlength,
.bdrv_probe_blocksizes = nvme_probe_blocksizes,
.bdrv_co_truncate = nvme_co_truncate,
diff --git a/block/preallocate.c b/block/preallocate.c
index a51fc08515..c9881942a3 100644
--- a/block/preallocate.c
+++ b/block/preallocate.c
@@ -442,7 +442,7 @@ static int coroutine_fn preallocate_co_flush(BlockDriverState *bs)
return bdrv_co_flush(bs->file->bs);
}
-static int64_t preallocate_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn preallocate_co_getlength(BlockDriverState *bs)
{
int64_t ret;
BDRVPreallocateState *s = bs->opaque;
@@ -451,7 +451,7 @@ static int64_t preallocate_getlength(BlockDriverState *bs)
return s->data_end;
}
- ret = bdrv_getlength(bs->file->bs);
+ ret = bdrv_co_getlength(bs->file->bs);
if (has_prealloc_perms(bs)) {
s->file_end = s->zero_start = s->data_end = ret;
@@ -537,9 +537,9 @@ BlockDriver bdrv_preallocate_filter = {
.format_name = "preallocate",
.instance_size = sizeof(BDRVPreallocateState),
- .bdrv_getlength = preallocate_getlength,
- .bdrv_open = preallocate_open,
- .bdrv_close = preallocate_close,
+ .bdrv_co_getlength = preallocate_co_getlength,
+ .bdrv_open = preallocate_open,
+ .bdrv_close = preallocate_close,
.bdrv_reopen_prepare = preallocate_reopen_prepare,
.bdrv_reopen_commit = preallocate_reopen_commit,
diff --git a/block/qed.c b/block/qed.c
index faa606618e..c8f9045b72 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -1480,7 +1480,7 @@ static int coroutine_fn bdrv_qed_co_truncate(BlockDriverState *bs,
return ret;
}
-static int64_t bdrv_qed_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn bdrv_qed_co_getlength(BlockDriverState *bs)
{
BDRVQEDState *s = bs->opaque;
return s->header.image_size;
@@ -1653,7 +1653,7 @@ static BlockDriver bdrv_qed = {
.bdrv_co_writev = bdrv_qed_co_writev,
.bdrv_co_pwrite_zeroes = bdrv_qed_co_pwrite_zeroes,
.bdrv_co_truncate = bdrv_qed_co_truncate,
- .bdrv_getlength = bdrv_qed_getlength,
+ .bdrv_co_getlength = bdrv_qed_co_getlength,
.bdrv_get_info = bdrv_qed_get_info,
.bdrv_refresh_limits = bdrv_qed_refresh_limits,
.bdrv_change_backing_file = bdrv_qed_change_backing_file,
diff --git a/block/quorum.c b/block/quorum.c
index 7f21c03f1f..d1dcf2eaba 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -754,19 +754,19 @@ static int coroutine_fn quorum_co_pwrite_zeroes(BlockDriverState *bs,
flags | BDRV_REQ_ZERO_WRITE);
}
-static int64_t quorum_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn quorum_co_getlength(BlockDriverState *bs)
{
BDRVQuorumState *s = bs->opaque;
int64_t result;
int i;
/* check that all file have the same length */
- result = bdrv_getlength(s->children[0]->bs);
+ result = bdrv_co_getlength(s->children[0]->bs);
if (result < 0) {
return result;
}
for (i = 1; i < s->num_children; i++) {
- int64_t value = bdrv_getlength(s->children[i]->bs);
+ int64_t value = bdrv_co_getlength(s->children[i]->bs);
if (value < 0) {
return value;
}
@@ -1283,7 +1283,7 @@ static BlockDriver bdrv_quorum = {
.bdrv_co_flush = quorum_co_flush,
- .bdrv_getlength = quorum_getlength,
+ .bdrv_co_getlength = quorum_co_getlength,
.bdrv_co_preadv = quorum_co_preadv,
.bdrv_co_pwritev = quorum_co_pwritev,
diff --git a/block/raw-format.c b/block/raw-format.c
index b6a0ce58f4..836190a306 100644
--- a/block/raw-format.c
+++ b/block/raw-format.c
@@ -317,14 +317,14 @@ static int coroutine_fn raw_co_pdiscard(BlockDriverState *bs,
return bdrv_co_pdiscard(bs->file, offset, bytes);
}
-static int64_t raw_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs)
{
int64_t len;
BDRVRawState *s = bs->opaque;
/* Update size. It should not change unless the file was externally
* modified. */
- len = bdrv_getlength(bs->file->bs);
+ len = bdrv_co_getlength(bs->file->bs);
if (len < 0) {
return len;
}
@@ -622,7 +622,7 @@ BlockDriver bdrv_raw = {
.bdrv_co_copy_range_from = &raw_co_copy_range_from,
.bdrv_co_copy_range_to = &raw_co_copy_range_to,
.bdrv_co_truncate = &raw_co_truncate,
- .bdrv_getlength = &raw_getlength,
+ .bdrv_co_getlength = &raw_co_getlength,
.is_format = true,
.has_variable_length = true,
.bdrv_measure = &raw_measure,
diff --git a/block/rbd.c b/block/rbd.c
index 6167c5e424..c127c1550d 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -1430,7 +1430,7 @@ static int coroutine_fn qemu_rbd_co_block_status(BlockDriverState *bs,
return status;
}
-static int64_t qemu_rbd_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn qemu_rbd_co_getlength(BlockDriverState *bs)
{
BDRVRBDState *s = bs->opaque;
int r;
@@ -1654,7 +1654,7 @@ static BlockDriver bdrv_rbd = {
.bdrv_get_info = qemu_rbd_getinfo,
.bdrv_get_specific_info = qemu_rbd_get_specific_info,
.create_opts = &qemu_rbd_create_opts,
- .bdrv_getlength = qemu_rbd_getlength,
+ .bdrv_co_getlength = qemu_rbd_co_getlength,
.bdrv_co_truncate = qemu_rbd_co_truncate,
.protocol_name = "rbd",
diff --git a/block/replication.c b/block/replication.c
index c62f48a874..a27417d310 100644
--- a/block/replication.c
+++ b/block/replication.c
@@ -179,9 +179,9 @@ static void replication_child_perm(BlockDriverState *bs, BdrvChild *c,
return;
}
-static int64_t replication_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn replication_co_getlength(BlockDriverState *bs)
{
- return bdrv_getlength(bs->file->bs);
+ return bdrv_co_getlength(bs->file->bs);
}
static int replication_get_io_status(BDRVReplicationState *s)
@@ -758,7 +758,7 @@ static BlockDriver bdrv_replication = {
.bdrv_close = replication_close,
.bdrv_child_perm = replication_child_perm,
- .bdrv_getlength = replication_getlength,
+ .bdrv_co_getlength = replication_co_getlength,
.bdrv_co_readv = replication_co_readv,
.bdrv_co_writev = replication_co_writev,
diff --git a/block/ssh.c b/block/ssh.c
index 8bd2a134c1..b3b3352075 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -1253,7 +1253,7 @@ static coroutine_fn int ssh_co_flush(BlockDriverState *bs)
return ret;
}
-static int64_t ssh_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn ssh_co_getlength(BlockDriverState *bs)
{
BDRVSSHState *s = bs->opaque;
int64_t length;
@@ -1364,7 +1364,7 @@ static BlockDriver bdrv_ssh = {
.bdrv_has_zero_init = ssh_has_zero_init,
.bdrv_co_readv = ssh_co_readv,
.bdrv_co_writev = ssh_co_writev,
- .bdrv_getlength = ssh_getlength,
+ .bdrv_co_getlength = ssh_co_getlength,
.bdrv_co_truncate = ssh_co_truncate,
.bdrv_co_flush_to_disk = ssh_co_flush,
.bdrv_refresh_filename = ssh_refresh_filename,
diff --git a/block/throttle.c b/block/throttle.c
index 00cb46d0e5..64fa0f5acc 100644
--- a/block/throttle.c
+++ b/block/throttle.c
@@ -106,9 +106,9 @@ static void throttle_close(BlockDriverState *bs)
}
-static int64_t throttle_getlength(BlockDriverState *bs)
+static int64_t coroutine_fn throttle_co_getlength(BlockDriverState *bs)
{
- return bdrv_getlength(bs->file->bs);
+ return bdrv_co_getlength(bs->file->bs);
}
static int coroutine_fn throttle_co_preadv(BlockDriverState *bs,
@@ -247,7 +247,7 @@ static BlockDriver bdrv_throttle = {
.bdrv_child_perm = bdrv_default_perms,
- .bdrv_getlength = throttle_getlength,
+ .bdrv_co_getlength = throttle_co_getlength,
.bdrv_co_preadv = throttle_co_preadv,
.bdrv_co_pwritev = throttle_co_pwritev,