From patchwork Wed Jan 20 07:28:54 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 74011 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id o0K7TBnD031739 for ; Wed, 20 Jan 2010 07:29:11 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752723Ab0ATH3H (ORCPT ); Wed, 20 Jan 2010 02:29:07 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756118Ab0ATH3H (ORCPT ); Wed, 20 Jan 2010 02:29:07 -0500 Received: from e23smtp03.au.ibm.com ([202.81.31.145]:55970 "EHLO e23smtp03.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751682Ab0ATH3E (ORCPT ); Wed, 20 Jan 2010 02:29:04 -0500 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [202.81.31.245]) by e23smtp03.au.ibm.com (8.14.3/8.13.1) with ESMTP id o0K7Q5mU008449 for ; Wed, 20 Jan 2010 18:26:05 +1100 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o0K7T0Tq1757262 for ; Wed, 20 Jan 2010 18:29:00 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o0K7Swb5019709 for ; Wed, 20 Jan 2010 18:29:00 +1100 Received: from skywalker.linux.vnet.ibm.com (K50wks273947wss.in.ibm.com [9.124.35.109]) by d23av02.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o0K7Stiu019581; Wed, 20 Jan 2010 18:28:56 +1100 From: "Aneesh Kumar K. V" To: Paul Komkoff , Chris Mason , Roland Dreier , Paul Komkoff , linux-btrfs Subject: Re: btrfs fallocate woes In-Reply-To: <715ea5c11001190718u396f41cua51ccf74c498482a@mail.gmail.com> References: <715ea5c11001140328g6198447axce1ba884a6e6fb96@mail.gmail.com> <20100114192035.GC23810@think> <715ea5c11001141233i78410267qc4d0767f5b7b8250@mail.gmail.com> <715ea5c11001190718u396f41cua51ccf74c498482a@mail.gmail.com> Date: Wed, 20 Jan 2010 12:58:54 +0530 Message-ID: <87vdexdykp.fsf@linux.vnet.ibm.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 5440bab..db406a4 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5789,7 +5789,7 @@ out_fail: } static int prealloc_file_range(struct inode *inode, u64 start, u64 end, - u64 alloc_hint, int mode) + u64 alloc_hint, int mode, loff_t actual_len) { struct btrfs_trans_handle *trans; struct btrfs_root *root = BTRFS_I(inode)->root; @@ -5798,6 +5798,7 @@ static int prealloc_file_range(struct inode *inode, u64 start, u64 end, u64 cur_offset = start; u64 num_bytes = end - start; int ret = 0; + u64 i_size; while (num_bytes > 0) { alloc_size = min(num_bytes, root->fs_info->max_extent); @@ -5836,8 +5837,12 @@ static int prealloc_file_range(struct inode *inode, u64 start, u64 end, BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC; if (!(mode & FALLOC_FL_KEEP_SIZE) && cur_offset > inode->i_size) { - i_size_write(inode, cur_offset); - btrfs_ordered_update_i_size(inode, cur_offset, NULL); + if (cur_offset > actual_len) + i_size = actual_len; + else + i_size = cur_offset; + i_size_write(inode, i_size); + btrfs_ordered_update_i_size(inode, i_size, NULL); } ret = btrfs_update_inode(trans, root, inode); @@ -5930,7 +5935,7 @@ static long btrfs_fallocate(struct inode *inode, int mode, !test_bit(EXTENT_FLAG_PREALLOC, &em->flags))) { ret = prealloc_file_range(inode, cur_offset, last_byte, - alloc_hint, mode); + alloc_hint, mode, offset+len); if (ret < 0) { free_extent_map(em); break;