From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pbonzini@redhat.com, jcody@redhat.com,
famz@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH v4 1/7] block: add bdrv_common_ancestor()
Date: Mon, 30 Sep 2013 20:02:52 +0800 [thread overview]
Message-ID: <1380542578-2387-2-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1380542578-2387-1-git-send-email-famz@redhat.com>
This function finds the common ancestor in backing chain of two BDSes.
If there's no common ancestor, NULL is returned.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
block.c | 15 +++++++++++++++
include/block/block.h | 2 ++
2 files changed, 17 insertions(+)
diff --git a/block.c b/block.c
index ea4956d..db1381d 100644
--- a/block.c
+++ b/block.c
@@ -3036,6 +3036,21 @@ BlockDriverState *bdrv_find(const char *name)
return NULL;
}
+BlockDriverState *bdrv_common_ancestor(BlockDriverState *bs1,
+ BlockDriverState *bs2)
+{
+ /* TODO: higher efficiency with reverse linked backing chain */
+ BlockDriverState *base1, *base2;
+ for (base1 = bs1; base1; base1 = base1->backing_hd) {
+ for (base2 = bs2; base2; base2 = base2->backing_hd) {
+ if (base1 == base2) {
+ return base1;
+ }
+ }
+ }
+ return NULL;
+}
+
BlockDriverState *bdrv_next(BlockDriverState *bs)
{
if (!bs) {
diff --git a/include/block/block.h b/include/block/block.h
index f808550..e095f16 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -321,6 +321,8 @@ void bdrv_lock_medium(BlockDriverState *bs, bool locked);
void bdrv_eject(BlockDriverState *bs, bool eject_flag);
const char *bdrv_get_format_name(BlockDriverState *bs);
BlockDriverState *bdrv_find(const char *name);
+BlockDriverState *bdrv_common_ancestor(BlockDriverState *bs1,
+ BlockDriverState *bs2);
BlockDriverState *bdrv_next(BlockDriverState *bs);
void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs),
void *opaque);
--
1.8.3.1
next prev parent reply other threads:[~2013-09-30 12:03 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-30 12:02 [Qemu-devel] [PATCH v4 0/7] block: allow commit active as top Fam Zheng
2013-09-30 12:02 ` Fam Zheng [this message]
2013-09-30 21:40 ` [Qemu-devel] [PATCH v4 1/7] block: add bdrv_common_ancestor() Eric Blake
2013-09-30 12:02 ` [Qemu-devel] [PATCH v4 2/7] qmp: add internal sync mode "common" to mirror_start Fam Zheng
2013-09-30 14:49 ` Eric Blake
2013-10-08 8:08 ` Fam Zheng
2013-09-30 12:02 ` [Qemu-devel] [PATCH v4 3/7] mirror: don't close target Fam Zheng
2013-10-01 17:11 ` Eric Blake
2013-09-30 12:02 ` [Qemu-devel] [PATCH v4 4/7] mirror: Add commit_job_type to perform commit with mirror code Fam Zheng
2013-10-01 17:13 ` Eric Blake
2013-10-08 8:37 ` Fam Zheng
2013-09-30 12:02 ` [Qemu-devel] [PATCH v4 5/7] commit: support commit active layer Fam Zheng
2013-09-30 12:16 ` Paolo Bonzini
2013-09-30 12:02 ` [Qemu-devel] [PATCH v4 6/7] commit: remove unused check Fam Zheng
2013-09-30 12:17 ` Paolo Bonzini
2013-10-08 9:32 ` Fam Zheng
2013-09-30 12:02 ` [Qemu-devel] [PATCH v4 7/7] qemu-iotests: update test cases for commit active Fam Zheng
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=1380542578-2387-2-git-send-email-famz@redhat.com \
--to=famz@redhat.com \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@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 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).