cryptospore / rpms / qemu-kvm

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