From patchwork Tue Jul 26 20:52:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 1009532 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6QKr0as006239 for ; Tue, 26 Jul 2011 20:53:01 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751892Ab1GZUw5 (ORCPT ); Tue, 26 Jul 2011 16:52:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37934 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751443Ab1GZUw5 (ORCPT ); Tue, 26 Jul 2011 16:52:57 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6QKqvtH028506 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 26 Jul 2011 16:52:57 -0400 Received: from localhost.localdomain.com (vpn-10-41.rdu.redhat.com [10.11.10.41]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p6QKqr28018682 for ; Tue, 26 Jul 2011 16:52:56 -0400 From: Josef Bacik To: linux-btrfs@vger.kernel.org Subject: [PATCH] Btrfs: switch back to the old csum calculation Date: Tue, 26 Jul 2011 16:52:52 -0400 Message-Id: <1311713572-26962-1-git-send-email-josef@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Tue, 26 Jul 2011 20:53:01 +0000 (UTC) This just switches us back to the old way of doing csum calculations. It is broken, but less broken than what I fixed it with, so revert it and I'll come up with something more correct for later. Thanks, Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 20 +++++++------------- 1 files changed, 7 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 2e0f87b..4256ab0 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3968,6 +3968,11 @@ out: return dropped_extents; } +static u64 calc_csum_metadata_size(struct inode *inode, u64 num_bytes) +{ + return num_bytes >>= 3; +} + int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes) { struct btrfs_root *root = BTRFS_I(inode)->root; @@ -3990,21 +3995,11 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes) BTRFS_I(inode)->reserved_extents; BTRFS_I(inode)->reserved_extents += nr_extents; - /* For checksums we'll just reserve 2 leaves worth of metadata - * and hope that works out right. - * - * NOTE: - * The more correct way to do this would be to figure out how - * much space we are going to write and figure out how many - * checksums that comes out to and then adjust whenever we cross - * a leafsize barrier. But thats a huge pain in the ass, so - * wing it and hope it comes out right :). - */ - nr_extents += nr_extents * 2; to_reserve = btrfs_calc_trans_metadata_size(root, nr_extents); } spin_unlock(&BTRFS_I(inode)->lock); + to_reserve += calc_csum_metadata_size(inode, num_bytes); ret = reserve_metadata_bytes(NULL, root, block_rsv, to_reserve, 1); if (ret) { unsigned dropped; @@ -4031,8 +4026,7 @@ void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes) num_bytes = ALIGN(num_bytes, root->sectorsize); dropped = drop_outstanding_extent(inode); - /* See btrfs_delalloc_reserve_metadata for an explanation */ - dropped += dropped * 2; + to_free = calc_csum_metadata_size(inode, num_bytes); if (dropped > 0) to_free += btrfs_calc_trans_metadata_size(root, dropped);