All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, mreitz@redhat.com, jcody@redhat.com,
	armbru@redhat.com, eblake@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH v2 1/9] block: Use BdrvChild callbacks for change_media/resize
Date: Wed, 27 Apr 2016 15:20:23 +0200	[thread overview]
Message-ID: <1461763231-17598-2-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1461763231-17598-1-git-send-email-kwolf@redhat.com>

We want to get rid of BlockDriverState.blk in order to allow multiple
BlockBackends per BDS. Converting the device callbacks in block.c (which
assume a single BlockBackend) to per-child callbacks gets us rid of the
first few instances.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
 block.c                   | 39 ++++++++++++++++++++++++++-------------
 block/block-backend.c     | 15 ++++++++++++++-
 include/block/block_int.h |  4 +++-
 3 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/block.c b/block.c
index d8c6e98..69ee791 100644
--- a/block.c
+++ b/block.c
@@ -1216,6 +1216,27 @@ void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child)
     bdrv_root_unref_child(child);
 }
 
+
+static void bdrv_parent_cb_change_media(BlockDriverState *bs, bool load)
+{
+    BdrvChild *c;
+    QLIST_FOREACH(c, &bs->parents, next_parent) {
+        if (c->role->change_media) {
+            c->role->change_media(c, load);
+        }
+    }
+}
+
+static void bdrv_parent_cb_resize(BlockDriverState *bs)
+{
+    BdrvChild *c;
+    QLIST_FOREACH(c, &bs->parents, next_parent) {
+        if (c->role->resize) {
+            c->role->resize(c);
+        }
+    }
+}
+
 /*
  * Sets the backing file link of a BDS. A new reference is created; callers
  * which don't need their own reference any more must call bdrv_unref().
@@ -1675,9 +1696,7 @@ static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
     }
 
     if (!bdrv_key_required(bs)) {
-        if (bs->blk) {
-            blk_dev_change_media_cb(bs->blk, true);
-        }
+        bdrv_parent_cb_change_media(bs, true);
     } else if (!runstate_check(RUN_STATE_PRELAUNCH)
                && !runstate_check(RUN_STATE_INMIGRATE)
                && !runstate_check(RUN_STATE_PAUSED)) { /* HACK */
@@ -2123,9 +2142,7 @@ static void bdrv_close(BlockDriverState *bs)
     bdrv_release_named_dirty_bitmaps(bs);
     assert(QLIST_EMPTY(&bs->dirty_bitmaps));
 
-    if (bs->blk) {
-        blk_dev_change_media_cb(bs->blk, false);
-    }
+    bdrv_parent_cb_change_media(bs, false);
 
     if (bs->drv) {
         BdrvChild *child, *next;
@@ -2576,9 +2593,7 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset)
     if (ret == 0) {
         ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS);
         bdrv_dirty_bitmap_truncate(bs);
-        if (bs->blk) {
-            blk_dev_resize_cb(bs->blk);
-        }
+        bdrv_parent_cb_resize(bs);
     }
     return ret;
 }
@@ -2688,11 +2703,9 @@ int bdrv_set_key(BlockDriverState *bs, const char *key)
     if (ret < 0) {
         bs->valid_key = 0;
     } else if (!bs->valid_key) {
+        /* call the change callback now, we skipped it on open */
         bs->valid_key = 1;
-        if (bs->blk) {
-            /* call the change callback now, we skipped it on open */
-            blk_dev_change_media_cb(bs->blk, true);
-        }
+        bdrv_parent_cb_change_media(bs, true);
     }
     return ret;
 }
diff --git a/block/block-backend.c b/block/block-backend.c
index 063024d..7f507ba 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -94,9 +94,15 @@ static void blk_root_inherit_options(int *child_flags, QDict *child_options,
 static void blk_root_drained_begin(BdrvChild *child);
 static void blk_root_drained_end(BdrvChild *child);
 
+static void blk_root_change_media(BdrvChild *child, bool load);
+static void blk_root_resize(BdrvChild *child);
+
 static const BdrvChildRole child_root = {
     .inherit_options    = blk_root_inherit_options,
 
+    .change_media       = blk_root_change_media,
+    .resize             = blk_root_resize,
+
     .drained_begin      = blk_root_drained_begin,
     .drained_end        = blk_root_drained_end,
 };
@@ -556,6 +562,11 @@ void blk_dev_change_media_cb(BlockBackend *blk, bool load)
     }
 }
 
+static void blk_root_change_media(BdrvChild *child, bool load)
+{
+    blk_dev_change_media_cb(child->opaque, load);
+}
+
 /*
  * Does @blk's attached device model have removable media?
  * %true if no device model is attached.
@@ -610,8 +621,10 @@ bool blk_dev_is_medium_locked(BlockBackend *blk)
 /*
  * Notify @blk's attached device model of a backend size change.
  */
-void blk_dev_resize_cb(BlockBackend *blk)
+static void blk_root_resize(BdrvChild *child)
 {
+    BlockBackend *blk = child->opaque;
+
     if (blk->dev_ops && blk->dev_ops->resize_cb) {
         blk->dev_ops->resize_cb(blk->dev_opaque);
     }
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 8481e80..9938a3d 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -362,6 +362,9 @@ struct BdrvChildRole {
     void (*inherit_options)(int *child_flags, QDict *child_options,
                             int parent_flags, QDict *parent_options);
 
+    void (*change_media)(BdrvChild *child, bool load);
+    void (*resize)(BdrvChild *child);
+
     void (*drained_begin)(BdrvChild *child);
     void (*drained_end)(BdrvChild *child);
 };
@@ -706,7 +709,6 @@ bool blk_dev_has_tray(BlockBackend *blk);
 void blk_dev_eject_request(BlockBackend *blk, bool force);
 bool blk_dev_is_tray_open(BlockBackend *blk);
 bool blk_dev_is_medium_locked(BlockBackend *blk);
-void blk_dev_resize_cb(BlockBackend *blk);
 
 void bdrv_set_dirty(BlockDriverState *bs, int64_t cur_sector, int nr_sectors);
 bool bdrv_requests_pending(BlockDriverState *bs);
-- 
1.8.3.1

  reply	other threads:[~2016-04-27 13:20 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-27 13:20 [Qemu-devel] [PATCH v2 0/9] block: Remove BlockDriverState.blk Kevin Wolf
2016-04-27 13:20 ` Kevin Wolf [this message]
2016-04-27 13:20 ` [Qemu-devel] [PATCH v2 2/9] block: User BdrvChild callback for device name Kevin Wolf
2016-04-27 13:20 ` [Qemu-devel] [PATCH v2 3/9] blockjob: Don't set iostatus of target Kevin Wolf
2016-05-06 12:01   ` Max Reitz
2016-05-06 12:32     ` Max Reitz
2016-05-06 13:31       ` Kevin Wolf
2016-05-06 13:40         ` Max Reitz
2016-05-06 14:12           ` Kevin Wolf
2016-05-11 15:02             ` Max Reitz
2016-05-06 14:34         ` Eric Blake
2016-04-27 13:20 ` [Qemu-devel] [PATCH v2 4/9] blockjob: Don't touch BDS iostatus Kevin Wolf
2016-05-06 13:37   ` Max Reitz
2016-04-27 13:20 ` [Qemu-devel] [PATCH v2 5/9] block: Remove bdrv_aio_multiwrite() Kevin Wolf
2016-05-06 12:29   ` Eric Blake
2016-05-12 20:18   ` Eric Blake
2016-04-27 13:20 ` [Qemu-devel] [PATCH v2 6/9] block: Add bdrv_has_blk() Kevin Wolf
2016-04-27 13:20 ` [Qemu-devel] [PATCH v2 7/9] block: Avoid bs->blk in bdrv_next() Kevin Wolf
2016-05-06 12:54   ` Max Reitz
2016-04-27 13:20 ` [Qemu-devel] [PATCH v2 8/9] block: Don't return throttling info in query-named-block-nodes Kevin Wolf
2016-04-27 13:20 ` [Qemu-devel] [PATCH v2 9/9] block: Remove BlockDriverState.blk Kevin Wolf
2016-05-17 14:28 ` [Qemu-devel] [PATCH v2 0/9] " Kevin Wolf

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=1461763231-17598-2-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=jcody@redhat.com \
    --cc=mreitz@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.