qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org
Subject: [PULL 07/28] qcow2: Don't call bdrv_getlength() in coroutine_fns
Date: Wed, 10 May 2023 14:20:50 +0200	[thread overview]
Message-ID: <20230510122111.46566-8-kwolf@redhat.com> (raw)
In-Reply-To: <20230510122111.46566-1-kwolf@redhat.com>

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>
---
 block/qcow2.h          |  4 +++-
 block/qcow2-refcount.c |  2 +-
 block/qcow2.c          | 19 +++++++++----------
 3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/block/qcow2.h b/block/qcow2.h
index c75decc38a..4f67eb912a 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -895,7 +895,9 @@ int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order,
                                 void *cb_opaque, Error **errp);
 int coroutine_fn GRAPH_RDLOCK qcow2_shrink_reftable(BlockDriverState *bs);
 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 */
 int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index b2a81ff707..4cf91bd955 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -3715,7 +3715,7 @@ int coroutine_fn qcow2_detect_metadata_preallocation(BlockDriverState *bs)
 
     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) {
         return file_length;
     }
diff --git a/block/qcow2.c b/block/qcow2.c
index fe5def438e..94cf59af8b 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2089,11 +2089,10 @@ static void qcow2_join_options(QDict *options, QDict *old_options)
     }
 }
 
-static int coroutine_fn qcow2_co_block_status(BlockDriverState *bs,
-                                              bool want_zero,
-                                              int64_t offset, int64_t count,
-                                              int64_t *pnum, int64_t *map,
-                                              BlockDriverState **file)
+static int coroutine_fn GRAPH_RDLOCK
+qcow2_co_block_status(BlockDriverState *bs, bool want_zero, int64_t offset,
+                      int64_t count, int64_t *pnum, int64_t *map,
+                      BlockDriverState **file)
 {
     BDRVQcow2State *s = bs->opaque;
     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
      * 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) {
         error_setg_errno(errp, -file_length, "Could not get file size");
         ret = file_length;
@@ -4098,7 +4097,7 @@ qcow2_co_copy_range_from(BlockDriverState *bs,
         case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN:
         case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC:
             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) {
                     cur_write_flags |= BDRV_REQ_ZERO_WRITE;
                 } else {
@@ -4293,7 +4292,7 @@ qcow2_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
             goto fail;
         }
 
-        old_file_size = bdrv_getlength(bs->file->bs);
+        old_file_size = bdrv_co_getlength(bs->file->bs);
         if (old_file_size < 0) {
             error_setg_errno(errp, -old_file_size,
                              "Failed to inquire current file length");
@@ -4386,7 +4385,7 @@ qcow2_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
             break;
         }
 
-        old_file_size = bdrv_getlength(bs->file->bs);
+        old_file_size = bdrv_co_getlength(bs->file->bs);
         if (old_file_size < 0) {
             error_setg_errno(errp, -old_file_size,
                              "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
          * sector based I/Os
          */
-        int64_t len = bdrv_getlength(bs->file->bs);
+        int64_t len = bdrv_co_getlength(bs->file->bs);
         if (len < 0) {
             return len;
         }
-- 
2.40.1



  parent reply	other threads:[~2023-05-10 12:25 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-10 12:20 [PULL 00/28] Block layer patches Kevin Wolf
2023-05-10 12:20 ` [PULL 01/28] block: add configure options for excluding vmdk, vhdx and vpc Kevin Wolf
2023-05-10 12:20 ` [PULL 02/28] block: add missing coroutine_fn annotations Kevin Wolf
2023-05-10 12:20 ` [PULL 03/28] aio-wait: avoid AioContext lock in aio_wait_bh_oneshot() Kevin Wolf
2023-05-10 12:20 ` [PULL 04/28] block: Fix use after free in blockdev_mark_auto_del() Kevin Wolf
2023-05-10 12:20 ` [PULL 05/28] iotests/nbd-reconnect-on-open: Fix NBD socket path Kevin Wolf
2023-05-10 12:20 ` [PULL 06/28] migration: Attempt disk reactivation in more failure scenarios Kevin Wolf
2023-05-10 12:20 ` Kevin Wolf [this message]
2023-05-10 12:20 ` [PULL 08/28] block: Consistently call bdrv_activate() outside coroutine Kevin Wolf
2023-05-10 12:20 ` [PULL 09/28] block: bdrv/blk_co_unref() for calls in coroutine context Kevin Wolf
2023-05-11 15:32   ` Michael Tokarev
2023-05-15 13:07     ` Kevin Wolf
2023-05-15 14:25       ` Michael Tokarev
2023-05-10 12:20 ` [PULL 10/28] block: Don't call no_coroutine_fns in qmp_block_resize() Kevin Wolf
2023-05-10 12:20 ` [PULL 11/28] iotests: Test resizing image attached to an iothread Kevin Wolf
2023-05-10 12:20 ` [PULL 12/28] test-bdrv-drain: Don't modify the graph in coroutines Kevin Wolf
2023-05-10 12:20 ` [PULL 13/28] graph-lock: Add GRAPH_UNLOCKED(_PTR) Kevin Wolf
2023-05-10 12:20 ` [PULL 14/28] graph-lock: Fix GRAPH_RDLOCK_GUARD*() to be reader lock Kevin Wolf
2023-05-10 12:20 ` [PULL 15/28] block: .bdrv_open is non-coroutine and unlocked Kevin Wolf
2023-05-10 12:20 ` [PULL 16/28] nbd: Remove nbd_co_flush() wrapper function Kevin Wolf
2023-05-10 12:21 ` [PULL 17/28] nbd: Mark nbd_co_do_establish_connection() and callers GRAPH_RDLOCK Kevin Wolf
2023-05-10 12:21 ` [PULL 18/28] vhdx: Require GRAPH_RDLOCK for accessing a node's parent list Kevin Wolf
2023-05-10 12:21 ` [PULL 19/28] mirror: " Kevin Wolf
2023-05-10 12:21 ` [PULL 20/28] block: Mark bdrv_co_get_allocated_file_size() and callers GRAPH_RDLOCK Kevin Wolf
2023-05-10 12:21 ` [PULL 21/28] block: Mark bdrv_co_get_info() " Kevin Wolf
2023-05-10 12:21 ` [PULL 22/28] block: Mark bdrv_co_debug_event() GRAPH_RDLOCK Kevin Wolf
2023-05-10 12:21 ` [PULL 23/28] block: Mark BlockDriver callbacks for amend job GRAPH_RDLOCK Kevin Wolf
2023-05-10 12:21 ` [PULL 24/28] block: Mark bdrv_query_bds_stats() and callers GRAPH_RDLOCK Kevin Wolf
2023-05-10 12:21 ` [PULL 25/28] block: Mark bdrv_query_block_graph_info() " Kevin Wolf
2023-05-10 12:21 ` [PULL 26/28] block: Mark bdrv_recurse_can_replace() " Kevin Wolf
2023-05-10 12:21 ` [PULL 27/28] block: Mark bdrv_refresh_limits() " Kevin Wolf
2023-05-10 12:21 ` [PULL 28/28] block: compile out assert_bdrv_graph_readable() by default Kevin Wolf
2023-05-10 15:42 ` [PULL 00/28] Block layer patches Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230510122111.46566-8-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).