All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Cody <jcody@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, benoit.canet@irqsave.net, pkrempa@redhat.com,
	famz@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH v7 for 2.1 1/4] block: add helper function to determine if a BDS is in a chain
Date: Wed, 25 Jun 2014 15:40:09 -0400	[thread overview]
Message-ID: <0c52400d7448e0c27bdb07ed493c39c7f77b3516.1403723847.git.jcody@redhat.com> (raw)
In-Reply-To: <cover.1403723847.git.jcody@redhat.com>
In-Reply-To: <cover.1403723847.git.jcody@redhat.com>

This is a small helper function, to determine if 'base' is in the
chain of BlockDriverState 'top'.  It returns true if it is in the chain,
and false otherwise.

If either argument is NULL, it will also return false.

Reviewed-by: Benoit Canet <benoit@irqsave.net>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Jeff Cody <jcody@redhat.com>
---
 block.c               | 11 +++++++++++
 include/block/block.h |  1 +
 2 files changed, 12 insertions(+)

diff --git a/block.c b/block.c
index a91809c..84ddb46 100644
--- a/block.c
+++ b/block.c
@@ -3781,6 +3781,17 @@ BlockDriverState *bdrv_lookup_bs(const char *device,
     return NULL;
 }
 
+/* If 'base' is in the same chain as 'top', return true. Otherwise,
+ * return false.  If either argument is NULL, return false. */
+bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base)
+{
+    while (top && top != base) {
+        top = top->backing_hd;
+    }
+
+    return top != NULL;
+}
+
 BlockDriverState *bdrv_next(BlockDriverState *bs)
 {
     if (!bs) {
diff --git a/include/block/block.h b/include/block/block.h
index d0baf4f..1055990 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -399,6 +399,7 @@ BlockDeviceInfoList *bdrv_named_nodes_list(void);
 BlockDriverState *bdrv_lookup_bs(const char *device,
                                  const char *node_name,
                                  Error **errp);
+bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base);
 BlockDriverState *bdrv_next(BlockDriverState *bs);
 void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs),
                   void *opaque);
-- 
1.9.3

  reply	other threads:[~2014-06-25 19:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-25 19:40 [Qemu-devel] [PATCH v7 for 2.1 0/4] Allow custom backing-file string in commit/stream Jeff Cody
2014-06-25 19:40 ` Jeff Cody [this message]
2014-06-30 14:55   ` [Qemu-devel] [PATCH v7 for 2.1 1/4] block: add helper function to determine if a BDS is in a chain Kevin Wolf
2014-06-25 19:40 ` [Qemu-devel] [PATCH v7 for 2.1 2/4] block: extend block-commit to accept a string for the backing file Jeff Cody
2014-06-30 14:55   ` Kevin Wolf
2014-06-25 19:40 ` [Qemu-devel] [PATCH v7 for 2.1 3/4] block: add backing-file option to block-stream Jeff Cody
2014-06-25 19:40 ` [Qemu-devel] [PATCH v7 for 2.1 4/4] block: add QAPI command to allow live backing file change Jeff Cody
2014-06-25 19:52   ` Eric Blake
2014-06-25 19:56     ` Jeff Cody
2014-06-30 14:59   ` Kevin Wolf
2014-06-30 15:55     ` Eric Blake
2014-07-01  7:52   ` [Qemu-devel] [PATCH v8 " Stefan Hajnoczi
2014-07-01  8:20     ` Kevin Wolf
2014-07-01 14:43     ` Eric Blake

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=0c52400d7448e0c27bdb07ed493c39c7f77b3516.1403723847.git.jcody@redhat.com \
    --to=jcody@redhat.com \
    --cc=benoit.canet@irqsave.net \
    --cc=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pkrempa@redhat.com \
    --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 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.