From patchwork Fri Oct 7 09:30:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: robbieko X-Patchwork-Id: 9365811 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1E193600C8 for ; Fri, 7 Oct 2016 09:31:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DD4D29443 for ; Fri, 7 Oct 2016 09:31:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0230729446; Fri, 7 Oct 2016 09:31:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA77729443 for ; Fri, 7 Oct 2016 09:31:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751515AbcJGJbD (ORCPT ); Fri, 7 Oct 2016 05:31:03 -0400 Received: from synology.com ([59.124.61.242]:47662 "EHLO synology.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750866AbcJGJbB (ORCPT ); Fri, 7 Oct 2016 05:31:01 -0400 Received: from localhost.localdomain (unknown [10.12.12.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: robbieko@synology.com) by synology.com (Postfix) with ESMTPSA id 05B5A1298066E; Fri, 7 Oct 2016 17:30:53 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1475832653; bh=OxDBdQHs5paF5OyJK2/zeERA1D2Q6DtNa1pHcRqcuoA=; h=From:To:Cc:Subject:Date; b=tpuR1VoIp+e4xSY2YAQgTjUpT1vPAcQxabNvIg0xQqIASRpj2ybaelJuJBa8+Vlzm c/DaPdTT8KF62jGZvbCG5SRpYgJ2hcV1JnR0AvU9LgrVRdLbz0P8a/kzCwrk2I00Ly skAY74eg2uKMvV89rS6Fkcda8gwox3MNKtCFEyHY= From: robbieko To: linux-btrfs@vger.kernel.org Cc: Robbie Ko Subject: [PATCH] Btrfs: fix infinite loop when tree log recovery Date: Fri, 7 Oct 2016 17:30:47 +0800 Message-Id: <1475832647-14012-1-git-send-email-robbieko@synology.com> X-Mailer: git-send-email 1.9.1 X-MailScanner-ID: 05B5A1298066E.A752B X-MailScanner: Found to be clean X-MailScanner-MCPCheck: MCP-Clean, MCP-Checker (score=0, required 80) X-MailScanner-SpamCheck: not spam (whitelisted), SpamAssassin (not cached, score=-0.891, required 4.5, ALL_TRUSTED -1.00, BAYES_40 -0.00, DKIM_SIGNED 0.10, T_DKIM_INVALID 0.01) X-MailScanner-From: robbieko@synology.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Robbie Ko if log tree like below: leaf N: ... item 240 key (282 DIR_LOG_ITEM 0) itemoff 8189 itemsize 8 dir log end 1275809046 leaf N+1: item 0 key (282 DIR_LOG_ITEM 3936149215) itemoff 16275 itemsize 8 dir log end 18446744073709551615 ... when start_ret > 1275809046, but slot[0] never >= nritems, so never go to next leaf. Signed-off-by: Robbie Ko --- fs/btrfs/tree-log.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index ef9c55b..e63dd99 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -1940,12 +1940,11 @@ static noinline int find_dir_range(struct btrfs_root *root, next: /* check the next slot in the tree to see if it is a valid item */ nritems = btrfs_header_nritems(path->nodes[0]); + path->slots[0]++; if (path->slots[0] >= nritems) { ret = btrfs_next_leaf(root, path); if (ret) goto out; - } else { - path->slots[0]++; } btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);