From patchwork Tue May 27 14:28:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 352992 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 17F841400A3 for ; Wed, 28 May 2014 00:33:05 +1000 (EST) Received: from localhost ([::1]:35712 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WpIR4-0006GM-OA for incoming@patchwork.ozlabs.org; Tue, 27 May 2014 10:33:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WpINI-0000RJ-CR for qemu-devel@nongnu.org; Tue, 27 May 2014 10:29:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WpINA-00052r-UQ for qemu-devel@nongnu.org; Tue, 27 May 2014 10:29:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48480) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WpINA-00052e-LW for qemu-devel@nongnu.org; Tue, 27 May 2014 10:29:00 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4RESv8b002269 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 27 May 2014 10:28:58 -0400 Received: from localhost (ovpn-112-29.phx2.redhat.com [10.3.112.29]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s4REStBB023447 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Tue, 27 May 2014 10:28:57 -0400 From: Jeff Cody To: qemu-devel@nongnu.org Date: Tue, 27 May 2014 10:28:35 -0400 Message-Id: <04056568e560af9fff466f50e54d866fe2bb2624.1401200582.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 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 05/11] block: simplify bdrv_find_base() 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 simplifies the function bdrv_find_base(), while keeping the same functionality. Signed-off-by: Jeff Cody Reviewed-by: Eric Blake --- block.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/block.c b/block.c index 577d4f1..cf29494 100644 --- a/block.c +++ b/block.c @@ -4363,20 +4363,14 @@ int bdrv_get_backing_file_depth(BlockDriverState *bs) return 1 + bdrv_get_backing_file_depth(bs->backing_hd); } +/* Given a BDS, searches for the base layer. If + * base layer cannot be found, returns NULL */ BlockDriverState *bdrv_find_base(BlockDriverState *bs) { - BlockDriverState *curr_bs = NULL; - - if (!bs) { - return NULL; + while (bs && bs->backing_hd) { + bs = bs->backing_hd; } - - curr_bs = bs; - - while (curr_bs->backing_hd) { - curr_bs = curr_bs->backing_hd; - } - return curr_bs; + return bs; } /* Given a BDS, searches for the active layer. If