From patchwork Tue May 27 14:28:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 352986 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E3C6314007F for ; Wed, 28 May 2014 00:29:52 +1000 (EST) Received: from localhost ([::1]:35682 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WpINy-0001pe-I6 for incoming@patchwork.ozlabs.org; Tue, 27 May 2014 10:29:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59039) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WpINF-0000Mw-I1 for qemu-devel@nongnu.org; Tue, 27 May 2014 10:29:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WpIN8-000527-0I for qemu-devel@nongnu.org; Tue, 27 May 2014 10:29:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46165) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WpIN7-00051q-OK for qemu-devel@nongnu.org; Tue, 27 May 2014 10:28:57 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4REStrZ002245 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 May 2014 10:28:55 -0400 Received: from localhost (ovpn-112-29.phx2.redhat.com [10.3.112.29]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s4RESrYc012864 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Tue, 27 May 2014 10:28:54 -0400 From: Jeff Cody To: qemu-devel@nongnu.org Date: Tue, 27 May 2014 10:28:34 -0400 Message-Id: <532d4f010624ccf8f70f5447519acdc795c375d9.1401200582.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, benoit.canet@irqsave.net, pkrempa@redhat.com, famz@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v2 04/11] block: add helper function to find the active layer of any BDS X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This helper function will find the active (top-most) layer of a specified BDS. This returns either the active layer, or NULL if the passed BDS is NULL. Signed-off-by: Jeff Cody Reviewed-by: Eric Blake --- block.c | 10 ++++++++++ include/block/block.h | 1 + 2 files changed, 11 insertions(+) diff --git a/block.c b/block.c index b72fe4e..577d4f1 100644 --- a/block.c +++ b/block.c @@ -4379,6 +4379,16 @@ BlockDriverState *bdrv_find_base(BlockDriverState *bs) return curr_bs; } +/* Given a BDS, searches for the active layer. If + * active layer cannot be found, returns NULL */ +BlockDriverState *bdrv_find_active(BlockDriverState *bs) +{ + while (bs && bs->overlay) { + bs = bs->overlay; + } + return bs; +} + /**************************************************************/ /* async I/Os */ diff --git a/include/block/block.h b/include/block/block.h index 4dc68be..a978e0d 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -293,6 +293,7 @@ int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top, BlockDriverState *bdrv_find_overlay(BlockDriverState *active, BlockDriverState *bs); BlockDriverState *bdrv_find_base(BlockDriverState *bs); +BlockDriverState *bdrv_find_active(BlockDriverState *bs); typedef struct BdrvCheckResult {