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, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 04/14] blockdev: blockdev_mark_auto_del: drop usage of bs->job
Date: Tue, 18 Jun 2019 17:23:08 +0200	[thread overview]
Message-ID: <20190618152318.24953-5-kwolf@redhat.com> (raw)
In-Reply-To: <20190618152318.24953-1-kwolf@redhat.com>

From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

We are going to remove bs->job pointer. Drop it's usage in
blockdev_mark_auto_del: instead of looking at bs->job let's check all
jobs for references to bs.

Suggested-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 include/block/blockjob.h |  9 +++++++++
 blockdev.c               | 17 ++++++++---------
 blockjob.c               | 14 ++++++++++++++
 3 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/include/block/blockjob.h b/include/block/blockjob.h
index ede0bd8dcb..35faa3aa26 100644
--- a/include/block/blockjob.h
+++ b/include/block/blockjob.h
@@ -121,6 +121,15 @@ int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs,
  */
 void block_job_remove_all_bdrv(BlockJob *job);
 
+/**
+ * block_job_has_bdrv:
+ * @job: The block job
+ *
+ * Searches for @bs in the list of nodes that are involved in the
+ * job.
+ */
+bool block_job_has_bdrv(BlockJob *job, BlockDriverState *bs);
+
 /**
  * block_job_set_speed:
  * @job: The job to set the speed for.
diff --git a/blockdev.c b/blockdev.c
index b5c0fd3c49..a9dd73eafc 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -140,22 +140,21 @@ void override_max_devs(BlockInterfaceType type, int max_devs)
 void blockdev_mark_auto_del(BlockBackend *blk)
 {
     DriveInfo *dinfo = blk_legacy_dinfo(blk);
-    BlockDriverState *bs = blk_bs(blk);
-    AioContext *aio_context;
+    BlockJob *job;
 
     if (!dinfo) {
         return;
     }
 
-    if (bs) {
-        aio_context = bdrv_get_aio_context(bs);
-        aio_context_acquire(aio_context);
+    for (job = block_job_next(NULL); job; job = block_job_next(job)) {
+        if (block_job_has_bdrv(job, blk_bs(blk))) {
+            AioContext *aio_context = job->job.aio_context;
+            aio_context_acquire(aio_context);
 
-        if (bs->job) {
-            job_cancel(&bs->job->job, false);
-        }
+            job_cancel(&job->job, false);
 
-        aio_context_release(aio_context);
+            aio_context_release(aio_context);
+        }
     }
 
     dinfo->auto_del = 1;
diff --git a/blockjob.c b/blockjob.c
index 1fac6bb8a7..c3620ec544 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -198,6 +198,20 @@ void block_job_remove_all_bdrv(BlockJob *job)
     job->nodes = NULL;
 }
 
+bool block_job_has_bdrv(BlockJob *job, BlockDriverState *bs)
+{
+    GSList *el;
+
+    for (el = job->nodes; el; el = el->next) {
+        BdrvChild *c = el->data;
+        if (c->bs == bs) {
+            return true;
+        }
+    }
+
+    return false;
+}
+
 int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs,
                        uint64_t perm, uint64_t shared_perm, Error **errp)
 {
-- 
2.20.1



  parent reply	other threads:[~2019-06-18 16:25 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-18 15:23 [Qemu-devel] [PULL 00/14] Block layer patches Kevin Wolf
2019-06-18 15:23 ` [Qemu-devel] [PULL 01/14] iotests: Hide timestamps for skipped tests Kevin Wolf
2019-06-18 15:23 ` [Qemu-devel] [PULL 02/14] block/replication: drop usage of bs->job Kevin Wolf
2019-06-18 15:23 ` [Qemu-devel] [PULL 03/14] block/block-backend: blk_iostatus_reset: " Kevin Wolf
2019-06-18 15:23 ` Kevin Wolf [this message]
2019-06-18 15:23 ` [Qemu-devel] [PULL 05/14] block: drop bs->job Kevin Wolf
2019-06-18 15:23 ` [Qemu-devel] [PULL 06/14] file-posix: Update open_flags in raw_set_perm() Kevin Wolf
2019-06-18 15:23 ` [Qemu-devel] [PULL 07/14] block: Add bdrv_child_refresh_perms() Kevin Wolf
2019-06-18 15:23 ` [Qemu-devel] [PULL 08/14] block/mirror: Fix child permissions Kevin Wolf
2019-06-18 15:23 ` [Qemu-devel] [PULL 09/14] block/commit: Drop bdrv_child_try_set_perm() Kevin Wolf
2019-06-18 15:23 ` [Qemu-devel] [PULL 10/14] block: Fix order in bdrv_replace_child() Kevin Wolf
2019-06-18 15:23 ` [Qemu-devel] [PULL 11/14] block: Add *tighten_restrictions to *check*_perm() Kevin Wolf
2019-06-18 15:23 ` [Qemu-devel] [PULL 12/14] block: Ignore loosening perm restrictions failures Kevin Wolf
2019-06-18 15:23 ` [Qemu-devel] [PULL 13/14] iotests: Test failure to loosen restrictions Kevin Wolf
2019-06-18 15:23 ` [Qemu-devel] [PULL 14/14] block/null: Expose read-zeroes option in QAPI schema Kevin Wolf
2019-06-18 16:32 ` [Qemu-devel] [PULL 00/14] Block layer patches Peter Maydell

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=20190618152318.24953-5-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.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).