From patchwork Mon Apr 22 13:13:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 2471821 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 8030EDFE86 for ; Mon, 22 Apr 2013 13:13:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752869Ab3DVNNx (ORCPT ); Mon, 22 Apr 2013 09:13:53 -0400 Received: from dkim1.fusionio.com ([66.114.96.53]:60135 "EHLO dkim1.fusionio.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751435Ab3DVNNw (ORCPT ); Mon, 22 Apr 2013 09:13:52 -0400 Received: from mx2.fusionio.com (unknown [10.101.1.160]) by dkim1.fusionio.com (Postfix) with ESMTP id 226FF7C067C for ; Mon, 22 Apr 2013 07:13:52 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fusionio.com; s=default; t=1366636432; bh=74cA9c9IBPSstw8cRCqvfi0dolL/Ezhn2IUYangY1Tk=; h=From:To:Subject:Date; b=oewX8UXtpuX/vVtMil242KSOsbzqHWdRzTtB4AMCr88oOGD7zoQMxLplNxzwLW/n5 p0ozFuvIrbdyzw3ge+OCrZnwPM4ibsXyoOE53DA9YerXMaPK9bP4yZM8xrMnespLDp 771cAkcC7fjPhltne9aoWMWdDS9oZSzU+5FqHOt0= X-ASG-Debug-ID: 1366636404-0421b537ab93a50001-6jHSXT Received: from mail1.int.fusionio.com (mail1.int.fusionio.com [10.101.1.21]) by mx2.fusionio.com with ESMTP id jZfo05p7UQSgxOQP (version=TLSv1 cipher=AES128-SHA bits=128 verify=NO) for ; Mon, 22 Apr 2013 07:13:24 -0600 (MDT) X-Barracuda-Envelope-From: JBacik@fusionio.com Received: from localhost (76.182.72.146) by mail.fusionio.com (10.101.1.19) with Microsoft SMTP Server (TLS) id 8.3.83.0; Mon, 22 Apr 2013 07:13:23 -0600 From: Josef Bacik To: Subject: [PATCH] Btrfs: fix possible infinite loop in slow caching Date: Mon, 22 Apr 2013 09:13:21 -0400 X-ASG-Orig-Subj: [PATCH] Btrfs: fix possible infinite loop in slow caching Message-ID: <1366636401-2066-1-git-send-email-jbacik@fusionio.com> X-Mailer: git-send-email 1.7.7.6 MIME-Version: 1.0 X-Barracuda-Connect: mail1.int.fusionio.com[10.101.1.21] X-Barracuda-Start-Time: 1366636404 X-Barracuda-Encrypted: AES128-SHA X-Barracuda-URL: http://10.101.1.181:8000/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at fusionio.com X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.2.128839 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org So I noticed there is an infinite loop in the slow caching code. If we return 1 when we hit the end of the tree, so we could end up caching the last block group the slow way and suddenly we're looping forever because we just keep re-searching and trying again. Fix this by only doing btrfs_next_leaf() if we don't need_resched(). Thanks, Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 12c32f9..b441be3 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -419,8 +419,7 @@ again: if (ret) break; - if (need_resched() || - btrfs_next_leaf(extent_root, path)) { + if (need_resched()) { caching_ctl->progress = last; btrfs_release_path(path); up_read(&fs_info->extent_commit_sem); @@ -428,6 +427,12 @@ again: cond_resched(); goto again; } + + ret = btrfs_next_leaf(extent_root, path); + if (ret < 0) + goto err; + if (ret) + break; leaf = path->nodes[0]; nritems = btrfs_header_nritems(leaf); continue;