From patchwork Mon Feb 22 06:59:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 8372241 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3E8B29FC55 for ; Mon, 22 Feb 2016 07:03:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 61D732038A for ; Mon, 22 Feb 2016 07:03:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7A55F20396 for ; Mon, 22 Feb 2016 07:03:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753359AbcBVHCN (ORCPT ); Mon, 22 Feb 2016 02:02:13 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:63508 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752015AbcBVHCM (ORCPT ); Mon, 22 Feb 2016 02:02:12 -0500 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="333108" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 22 Feb 2016 15:02:02 +0800 Received: from localhost.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id 682654056403; Mon, 22 Feb 2016 15:01:58 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH 1/5] btrfs: volume: Fix a bug causing btrfs-find-root to skip first chunk Date: Mon, 22 Feb 2016 14:59:53 +0800 Message-Id: <1456124397-21403-2-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.7.1 In-Reply-To: <1456124397-21403-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1456124397-21403-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: 682654056403.A764E X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is a small bug from 2011, where btrfs_next_bg (formally btrfs_next_metadata) function will always skip the first chunk. That's OK for that time, as there is always 3 empty temporary chunks. But now, we may ended up with only one metadata or system chunk, with empty chunk auto-remove from kernel or new mkfs.btrfs. So fix it by checking the initial value so btrfs_next_bg() will return the first chunk if its *logical parameter is 0. Signed-off-by: Qu Wenruo --- volumes.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/volumes.c b/volumes.c index a94be0e..059c4f4 100644 --- a/volumes.c +++ b/volumes.c @@ -1170,14 +1170,23 @@ int btrfs_next_bg(struct btrfs_mapping_tree *map_tree, u64 *logical, { struct cache_extent *ce; struct map_lookup *map; + u64 cur = *logical; - ce = search_cache_extent(&map_tree->cache_tree, *logical); + ce = search_cache_extent(&map_tree->cache_tree, cur); while (ce) { - ce = next_cache_extent(ce); - if (!ce) - return -ENOENT; + /* + * only jump to next bg if our cur is not 0 + * As the initial logical for btrfs_next_bg() is 0, and + * if we jump to next bg, we skipped a valid bg. + */ + if (cur) { + ce = next_cache_extent(ce); + if (!ce) + return -ENOENT; + } + cur = ce->start; map = container_of(ce, struct map_lookup, ce); if (map->type & type) { *logical = ce->start;