From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51808) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1tlA-0008Mq-N2 for qemu-devel@nongnu.org; Tue, 01 Jul 2014 04:49:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X1tl5-0006KE-JM for qemu-devel@nongnu.org; Tue, 01 Jul 2014 04:49:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13049) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1tl5-0006K9-9c for qemu-devel@nongnu.org; Tue, 01 Jul 2014 04:49:47 -0400 From: Stefan Hajnoczi Date: Tue, 1 Jul 2014 10:48:51 +0200 Message-Id: <1404204537-5082-19-git-send-email-stefanha@redhat.com> In-Reply-To: <1404204537-5082-1-git-send-email-stefanha@redhat.com> References: <1404204537-5082-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL for-2.1 18/24] block: simplify bdrv_find_base() and bdrv_find_overlay() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Jeff Cody , Stefan Hajnoczi From: Jeff Cody This simplifies the function bdrv_find_overlay(). With this change, bdrv_find_base() is just a subset of usage of bdrv_find_overlay(), so this also takes advantage of that. Reviewed-by: Eric Blake Reviewed-by: Benoit Canet Signed-off-by: Jeff Cody Signed-off-by: Stefan Hajnoczi --- block.c | 45 ++++++++++----------------------------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/block.c b/block.c index 6856c18..c111c29 100644 --- a/block.c +++ b/block.c @@ -2508,32 +2508,23 @@ int bdrv_change_backing_file(BlockDriverState *bs, * * Returns NULL if bs is not found in active's image chain, * or if active == bs. + * + * Returns the bottommost base image if bs == NULL. */ BlockDriverState *bdrv_find_overlay(BlockDriverState *active, BlockDriverState *bs) { - BlockDriverState *overlay = NULL; - BlockDriverState *intermediate; - - assert(active != NULL); - assert(bs != NULL); - - /* if bs is the same as active, then by definition it has no overlay - */ - if (active == bs) { - return NULL; + while (active && bs != active->backing_hd) { + active = active->backing_hd; } - intermediate = active; - while (intermediate->backing_hd) { - if (intermediate->backing_hd == bs) { - overlay = intermediate; - break; - } - intermediate = intermediate->backing_hd; - } + return active; +} - return overlay; +/* Given a BDS, searches for the base layer. */ +BlockDriverState *bdrv_find_base(BlockDriverState *bs) +{ + return bdrv_find_overlay(bs, NULL); } typedef struct BlkIntermediateStates { @@ -4326,22 +4317,6 @@ int bdrv_get_backing_file_depth(BlockDriverState *bs) return 1 + bdrv_get_backing_file_depth(bs->backing_hd); } -BlockDriverState *bdrv_find_base(BlockDriverState *bs) -{ - BlockDriverState *curr_bs = NULL; - - if (!bs) { - return NULL; - } - - curr_bs = bs; - - while (curr_bs->backing_hd) { - curr_bs = curr_bs->backing_hd; - } - return curr_bs; -} - /**************************************************************/ /* async I/Os */ -- 1.9.3