yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
958e1b
From e49f2991513ff786625bff7e729ebe9b292e633a Mon Sep 17 00:00:00 2001
91048c
From: Jeffrey Cody <jcody@redhat.com>
91048c
Date: Fri, 19 Sep 2014 03:18:56 +0200
958e1b
Subject: [PATCH 17/20] block: add helper function to determine if a BDS is in a chain
91048c
91048c
Message-id: <aa9b5aa581c435e579e97bec44bb821e047b59f6.1411096194.git.jcody@redhat.com>
91048c
Patchwork-id: 61310
91048c
O-Subject: [PATCH qemu-kvm-rhev RHEL7.0.z 1/4] block: add helper function to determine if a BDS is in a chain
91048c
Bugzilla: 1122925
91048c
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
91048c
RH-Acked-by: Eric Blake <eblake@redhat.com>
91048c
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
91048c
91048c
This is a small helper function, to determine if 'base' is in the
91048c
chain of BlockDriverState 'top'.  It returns true if it is in the chain,
91048c
and false otherwise.
91048c
91048c
If either argument is NULL, it will also return false.
91048c
91048c
Reviewed-by: Benoit Canet <benoit@irqsave.net>
91048c
Reviewed-by: Eric Blake <eblake@redhat.com>
91048c
Signed-off-by: Jeff Cody <jcody@redhat.com>
91048c
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
91048c
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
91048c
(cherry picked from commit 5a6684d2b957f9ec75d7ed7b14332293abec1d6c)
91048c
91048c
Conflicts:
91048c
	block.c
91048c
	include/block/block.h
91048c
91048c
Signed-off-by: Jeff Cody <jcody@redhat.com>
91048c
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
91048c
---
91048c
 block.c               |   11 +++++++++++
91048c
 include/block/block.h |    1 +
91048c
 2 files changed, 12 insertions(+), 0 deletions(-)
91048c
91048c
diff --git a/block.c b/block.c
958e1b
index af162fe..7bdbbc6 100644
91048c
--- a/block.c
91048c
+++ b/block.c
958e1b
@@ -3439,6 +3439,17 @@ BlockDriverState *bdrv_find(const char *name)
91048c
     return NULL;
91048c
 }
91048c
 
91048c
+/* If 'base' is in the same chain as 'top', return true. Otherwise,
91048c
+ * return false.  If either argument is NULL, return false. */
91048c
+bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base)
91048c
+{
91048c
+    while (top && top != base) {
91048c
+        top = top->backing_hd;
91048c
+    }
91048c
+
91048c
+    return top != NULL;
91048c
+}
91048c
+
91048c
 BlockDriverState *bdrv_next(BlockDriverState *bs)
91048c
 {
91048c
     if (!bs) {
91048c
diff --git a/include/block/block.h b/include/block/block.h
91048c
index 13ef173..972c0e7 100644
91048c
--- a/include/block/block.h
91048c
+++ b/include/block/block.h
91048c
@@ -361,6 +361,7 @@ void bdrv_lock_medium(BlockDriverState *bs, bool locked);
91048c
 void bdrv_eject(BlockDriverState *bs, bool eject_flag);
91048c
 const char *bdrv_get_format_name(BlockDriverState *bs);
91048c
 BlockDriverState *bdrv_find(const char *name);
91048c
+bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base);
91048c
 BlockDriverState *bdrv_next(BlockDriverState *bs);
91048c
 void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs),
91048c
                   void *opaque);
91048c
-- 
91048c
1.7.1
91048c