From patchwork Fri May 30 17:35:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 354284 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 AF5CD140099 for ; Sat, 31 May 2014 03:36:47 +1000 (EST) Received: from localhost ([::1]:55756 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WqQjV-0006Be-Ix for incoming@patchwork.ozlabs.org; Fri, 30 May 2014 13:36:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46204) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WqQih-0004a5-Dz for qemu-devel@nongnu.org; Fri, 30 May 2014 13:36:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WqQiZ-0002de-Uy for qemu-devel@nongnu.org; Fri, 30 May 2014 13:35:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3923) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WqQiZ-0002dX-NI for qemu-devel@nongnu.org; Fri, 30 May 2014 13:35:47 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4UHZjTx029119 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 30 May 2014 13:35:46 -0400 Received: from localhost (ovpn-112-54.phx2.redhat.com [10.3.112.54]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s4UHZhZA016452 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Fri, 30 May 2014 13:35:45 -0400 From: Jeff Cody To: qemu-devel@nongnu.org Date: Fri, 30 May 2014 13:35:22 -0400 Message-Id: <75e91af2015d8242b25f6f4e6c7ed2e99ec949b7.1401471188.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 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 v3 04/12] 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. Reviewed-by: Eric Blake Signed-off-by: Jeff Cody --- block.c | 10 ++++++++++ include/block/block.h | 1 + 2 files changed, 11 insertions(+) diff --git a/block.c b/block.c index 588046e..7eb3279 100644 --- a/block.c +++ b/block.c @@ -4388,6 +4388,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 dff5403..c82d89a 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -294,6 +294,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 {