From patchwork Fri Nov 30 06:02:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Sheng-Hui X-Patchwork-Id: 1823721 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 57036DF264 for ; Fri, 30 Nov 2012 06:03:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753837Ab2K3GD2 (ORCPT ); Fri, 30 Nov 2012 01:03:28 -0500 Received: from mail-ia0-f174.google.com ([209.85.210.174]:58027 "EHLO mail-ia0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752725Ab2K3GD1 (ORCPT ); Fri, 30 Nov 2012 01:03:27 -0500 Received: by mail-ia0-f174.google.com with SMTP id y25so97671iay.19 for ; Thu, 29 Nov 2012 22:03:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=pLIztbm8X3srq5XkOTF1OxDS7VGXg11IPWMYCundDOE=; b=pZlD2yEwof7QFrkmAXImSnfmq28EPEY6p+q5DAk35KR2auBWbId4KsC9E/Qc9Cu9BM RHVn0ON9DK0PQMe8X0wxangq0popAhNJPSzktI0911zg4RmJAa05rL6d+2aubkMPMV8h SyWJdbJFBQP9jTqyC57pc7e9/yz5kMtNARXTK6PVmNYYJ57L7OMDwuUxax1a+9icnqAF hlosXAZnIbRpy+kY8siljk6G+ehWCWJfo9TMUw2a8SyStmLROfmjwjt8STx/u5ljdqHA 68EP2msY8JX6xs3voQxAXsUgwh6ZoJ/tDmmLduIaS/UJ2B41QeWOv/dXunsfD1dRMbxb iSIg== Received: by 10.50.157.162 with SMTP id wn2mr157317igb.27.1354255406087; Thu, 29 Nov 2012 22:03:26 -0800 (PST) Received: from localhost ([202.108.130.138]) by mx.google.com with ESMTPS id u4sm3826156igw.6.2012.11.29.22.03.22 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 29 Nov 2012 22:03:25 -0800 (PST) From: shhuiw@gmail.com To: chris.mason@fusionio.com, jbacik@fusionio.com Cc: linux-btrfs@vger.kernel.org Subject: [PATCH] Btrfs: check crc area early in io_ctl_init Date: Fri, 30 Nov 2012 14:02:27 +0800 Message-Id: <50b84c2d.c44d320a.520e.ffffbea6@mx.google.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1354255348-5011-1-git-send-email-y> References: <1354255348-5011-1-git-send-email-y> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Wang Sheng-Hui When use crc area, we should check if it can host the desired num of crcs. Add the check in init stage. And the check should be more strict: the first page has sizeof(u64)*2 cannot used for crc. Signed-off-by: Wang Sheng-Hui --- fs/btrfs/free-space-cache.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 4ea66d4..058fc9b 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -286,8 +286,14 @@ static int io_ctl_init(struct io_ctl *io_ctl, struct inode *inode, if (!io_ctl->pages) return -ENOMEM; io_ctl->root = root; - if (btrfs_ino(inode) != BTRFS_FREE_INO_OBJECTID) + if (btrfs_ino(inode) != BTRFS_FREE_INO_OBJECTID) { io_ctl->check_crcs = 1; + if ((io_ctl.num_pages * sizeof(u32)) > + (PAGE_CACHE_SIZE - sizeof(u64) * 2)) { + WARN_ON(1); + return -1; + } + } return 0; } @@ -917,7 +923,8 @@ int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, /* Make sure we can fit our crcs into the first page */ if (io_ctl.check_crcs && - (io_ctl.num_pages * sizeof(u32)) >= PAGE_CACHE_SIZE) { + (io_ctl.num_pages * sizeof(u32)) > + (PAGE_CACHE_SIZE - sizeof(u64) * 2)) { WARN_ON(1); goto out_nospc; }