qcow2: Don't call bdrv_getlength() in coroutine_fns

There is a bdrv_co_getlength() now, which should be used in coroutine
context.

This requires adding GRAPH_RDLOCK to some functions so that this still
compiles with TSA because bdrv_co_getlength() is GRAPH_RDLOCK.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20230504115750.54437-2-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Kevin Wolf 2023-05-04 13:57:31 +02:00
parent 6dab4c93ec
commit 0050c163ff
3 changed files with 13 additions and 12 deletions

View File

@ -3715,7 +3715,7 @@ int coroutine_fn qcow2_detect_metadata_preallocation(BlockDriverState *bs)
qemu_co_mutex_assert_locked(&s->lock); qemu_co_mutex_assert_locked(&s->lock);
file_length = bdrv_getlength(bs->file->bs); file_length = bdrv_co_getlength(bs->file->bs);
if (file_length < 0) { if (file_length < 0) {
return file_length; return file_length;
} }

View File

@ -2089,11 +2089,10 @@ static void qcow2_join_options(QDict *options, QDict *old_options)
} }
} }
static int coroutine_fn qcow2_co_block_status(BlockDriverState *bs, static int coroutine_fn GRAPH_RDLOCK
bool want_zero, qcow2_co_block_status(BlockDriverState *bs, bool want_zero, int64_t offset,
int64_t offset, int64_t count, int64_t count, int64_t *pnum, int64_t *map,
int64_t *pnum, int64_t *map, BlockDriverState **file)
BlockDriverState **file)
{ {
BDRVQcow2State *s = bs->opaque; BDRVQcow2State *s = bs->opaque;
uint64_t host_offset; uint64_t host_offset;
@ -3235,7 +3234,7 @@ preallocate_co(BlockDriverState *bs, uint64_t offset, uint64_t new_length,
* all of the allocated clusters (otherwise we get failing reads after * all of the allocated clusters (otherwise we get failing reads after
* EOF). Extend the image to the last allocated sector. * EOF). Extend the image to the last allocated sector.
*/ */
file_length = bdrv_getlength(s->data_file->bs); file_length = bdrv_co_getlength(s->data_file->bs);
if (file_length < 0) { if (file_length < 0) {
error_setg_errno(errp, -file_length, "Could not get file size"); error_setg_errno(errp, -file_length, "Could not get file size");
ret = file_length; ret = file_length;
@ -4098,7 +4097,7 @@ qcow2_co_copy_range_from(BlockDriverState *bs,
case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN: case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN:
case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC: case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC:
if (bs->backing && bs->backing->bs) { if (bs->backing && bs->backing->bs) {
int64_t backing_length = bdrv_getlength(bs->backing->bs); int64_t backing_length = bdrv_co_getlength(bs->backing->bs);
if (src_offset >= backing_length) { if (src_offset >= backing_length) {
cur_write_flags |= BDRV_REQ_ZERO_WRITE; cur_write_flags |= BDRV_REQ_ZERO_WRITE;
} else { } else {
@ -4293,7 +4292,7 @@ qcow2_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
goto fail; goto fail;
} }
old_file_size = bdrv_getlength(bs->file->bs); old_file_size = bdrv_co_getlength(bs->file->bs);
if (old_file_size < 0) { if (old_file_size < 0) {
error_setg_errno(errp, -old_file_size, error_setg_errno(errp, -old_file_size,
"Failed to inquire current file length"); "Failed to inquire current file length");
@ -4386,7 +4385,7 @@ qcow2_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
break; break;
} }
old_file_size = bdrv_getlength(bs->file->bs); old_file_size = bdrv_co_getlength(bs->file->bs);
if (old_file_size < 0) { if (old_file_size < 0) {
error_setg_errno(errp, -old_file_size, error_setg_errno(errp, -old_file_size,
"Failed to inquire current file length"); "Failed to inquire current file length");
@ -4694,7 +4693,7 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs,
* align end of file to a sector boundary to ease reading with * align end of file to a sector boundary to ease reading with
* sector based I/Os * sector based I/Os
*/ */
int64_t len = bdrv_getlength(bs->file->bs); int64_t len = bdrv_co_getlength(bs->file->bs);
if (len < 0) { if (len < 0) {
return len; return len;
} }

View File

@ -895,7 +895,9 @@ int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order,
void *cb_opaque, Error **errp); void *cb_opaque, Error **errp);
int coroutine_fn GRAPH_RDLOCK qcow2_shrink_reftable(BlockDriverState *bs); int coroutine_fn GRAPH_RDLOCK qcow2_shrink_reftable(BlockDriverState *bs);
int64_t coroutine_fn qcow2_get_last_cluster(BlockDriverState *bs, int64_t size); int64_t coroutine_fn qcow2_get_last_cluster(BlockDriverState *bs, int64_t size);
int coroutine_fn qcow2_detect_metadata_preallocation(BlockDriverState *bs);
int coroutine_fn GRAPH_RDLOCK
qcow2_detect_metadata_preallocation(BlockDriverState *bs);
/* qcow2-cluster.c functions */ /* qcow2-cluster.c functions */
int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,