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, eblake@redhat.com, armbru@redhat.com,
	stefanha@redhat.com, mreitz@redhat.com, famz@redhat.com,
	qemu-devel@nongnu.org
Subject: [Qemu-devel] [RFC PATCH 2/7] block: Add blk_by_dev()
Date: Thu, 23 Jun 2016 16:36:27 +0200	[thread overview]
Message-ID: <1466692592-9551-3-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1466692592-9551-1-git-send-email-kwolf@redhat.com>

This finds a BlockBackend given the device model that is attached to it.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/block-backend.c          | 19 +++++++++++++++++++
 include/sysemu/block-backend.h |  1 +
 2 files changed, 20 insertions(+)

diff --git a/block/block-backend.c b/block/block-backend.c
index 34500e6..307cb17 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -544,6 +544,25 @@ void *blk_get_attached_dev(BlockBackend *blk)
 }
 
 /*
+ * Return the BlockBackend which has the device model @dev attached if it
+ * exists, else null.
+ *
+ * @dev must not be null.
+ */
+BlockBackend *blk_by_dev(void *dev)
+{
+    BlockBackend *blk = NULL;
+
+    assert(dev != NULL);
+    while ((blk = blk_all_next(blk)) != NULL) {
+        if (blk->dev == dev) {
+            return blk;
+        }
+    }
+    return NULL;
+}
+
+/*
  * Set @blk's device model callbacks to @ops.
  * @opaque is the opaque argument to pass to the callbacks.
  * This is for use by device models.
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index c04af8e..aec1471 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -110,6 +110,7 @@ int blk_attach_dev(BlockBackend *blk, void *dev);
 void blk_attach_dev_nofail(BlockBackend *blk, void *dev);
 void blk_detach_dev(BlockBackend *blk, void *dev);
 void *blk_get_attached_dev(BlockBackend *blk);
+BlockBackend *blk_by_dev(void *dev);
 void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaque);
 int blk_pread_unthrottled(BlockBackend *blk, int64_t offset, uint8_t *buf,
                           int count);
-- 
1.8.3.1

  parent reply	other threads:[~2016-06-23 14:37 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-23 14:36 [Qemu-devel] [RFC PATCH 0/7] BlockBackends, nodes and guest devices Kevin Wolf
2016-06-23 14:36 ` [Qemu-devel] [RFC PATCH 1/7] block/qdev: Allow node name for drive properties Kevin Wolf
2016-06-24 17:35   ` Eric Blake
2016-06-24 17:54     ` Kevin Wolf
2016-06-23 14:36 ` Kevin Wolf [this message]
2016-06-24 17:39   ` [Qemu-devel] [RFC PATCH 2/7] block: Add blk_by_dev() Eric Blake
2016-06-23 14:36 ` [Qemu-devel] [RFC PATCH 3/7] qdev-monitor: Factor out find_device_state() Kevin Wolf
2016-06-24 17:41   ` Eric Blake
2016-06-23 14:36 ` [Qemu-devel] [RFC PATCH 4/7] qdev-monitor: Add blk_by_qdev_id() Kevin Wolf
2016-06-24 20:22   ` Eric Blake
2016-06-23 14:36 ` [Qemu-devel] [RFC PATCH 5/7] block: Accept device model name for blockdev-open/close-tray Kevin Wolf
2016-06-24 20:39   ` Eric Blake
2016-06-27  8:53     ` Kevin Wolf
2016-06-23 14:36 ` [Qemu-devel] [RFC PATCH 6/7] block: Accept node-name for block-stream Kevin Wolf
2016-06-24 20:57   ` Eric Blake
2016-06-23 14:36 ` [Qemu-devel] [RFC PATCH 7/7] block/qdev: Allow configuring WCE with qdev properties Kevin Wolf
2016-06-24 21:10   ` Eric Blake
2016-06-23 21:26 ` [Qemu-devel] [RFC PATCH 0/7] BlockBackends, nodes and guest devices Paolo Bonzini
2016-06-27 16:13 ` Max Reitz
2016-06-27 16:38   ` Kevin Wolf
2016-06-27 16:40     ` Max Reitz
2016-07-12  0:13 ` [Qemu-devel] [Qemu-block] " John Snow
2016-07-12  8:14   ` Kevin Wolf
2016-07-12 17:11     ` John Snow

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=1466692592-9551-3-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=famz@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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).