From patchwork Fri May 30 15:35:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 354237 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 C53AB1400D6 for ; Sat, 31 May 2014 01:38:40 +1000 (EST) Received: from localhost ([::1]:54956 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WqOtC-0007ng-HX for incoming@patchwork.ozlabs.org; Fri, 30 May 2014 11:38:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43622) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WqOqD-0001PK-6Y for qemu-devel@nongnu.org; Fri, 30 May 2014 11:35:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WqOq6-0004i3-SJ for qemu-devel@nongnu.org; Fri, 30 May 2014 11:35:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62812) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WqOq5-0004hf-Jx for qemu-devel@nongnu.org; Fri, 30 May 2014 11:35:26 -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 s4UFZNM0010616 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 30 May 2014 11:35:23 -0400 Received: from localhost (ovpn-112-54.phx2.redhat.com [10.3.112.54]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s4UFZL3B018113 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Fri, 30 May 2014 11:35:23 -0400 From: Jeff Cody To: qemu-devel@nongnu.org Date: Fri, 30 May 2014 11:35:04 -0400 Message-Id: <2603e660b8e458f92ee6c6aac7a101caa8188979.1401463410.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] [v3 02/12] block: add helper function to determine if a BDS is in a chain 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 is a small helper function, to determine if 'base' is in the chain of BlockDriverState 'top'. It returns true if it is in the chain, and false otherwise. If either argument is NULL, it will also return false. Reviewed-by: Benoit Canet Reviewed-by: Eric Blake Signed-off-by: Jeff Cody --- block.c | 11 +++++++++++ include/block/block.h | 1 + 2 files changed, 12 insertions(+) diff --git a/block.c b/block.c index 415f0d2..cf4b296 100644 --- a/block.c +++ b/block.c @@ -3811,6 +3811,17 @@ BlockDriverState *bdrv_lookup_bs(const char *device, return NULL; } +/* If 'base' is in the same chain as 'top', return true. Otherwise, + * return false. If either argument is NULL, return false. */ +bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base) +{ + while (top && top != base) { + top = top->backing_hd; + } + + return top != NULL; +} + BlockDriverState *bdrv_next(BlockDriverState *bs) { if (!bs) { diff --git a/include/block/block.h b/include/block/block.h index faee3aa..4dc68be 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -404,6 +404,7 @@ BlockDeviceInfoList *bdrv_named_nodes_list(void); BlockDriverState *bdrv_lookup_bs(const char *device, const char *node_name, Error **errp); +bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base); BlockDriverState *bdrv_next(BlockDriverState *bs); void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs), void *opaque);