Btrfs: account for space we may use in fallocate

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <git-commits-head@...>
Date: Friday, July 3, 2009 - 5:59 pm

Gitweb:     http://git.kernel.org/linus/a970b0a16cc416a509d5ae8b1d70978664e6f4fe
Commit:     a970b0a16cc416a509d5ae8b1d70978664e6f4fe
Parent:     c8a894d77de4a1e0a544577fd4eabc9aacd453a8
Author:     Josef Bacik <jbacik@redhat.com>
AuthorDate: Sat Jun 27 21:07:34 2009 -0400
Committer:  Chris Mason <chris.mason@oracle.com>
CommitDate: Thu Jul 2 13:41:16 2009 -0400

    Btrfs: account for space we may use in fallocate
    
    Using Eric Sandeen's xfstest for fallocate, you can easily trigger a ENOSPC
    panic on btrfs.  This is because we do not account for data we may use when
    doing the fallocate.  This patch fixes the problem by properly reserving space,
    and then just freeing it when we are done.  The reservation stuff was made with
    delalloc in mind, so its a little crude for this case, but it keeps the box
    from panicing.
    
    Signed-off-by: Josef Bacik <jbacik@redhat.com>
    Signed-off-by: Chris Mason <chris.mason@oracle.com>
---
 fs/btrfs/inode.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 5b68330..1eacc78 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -5103,6 +5103,7 @@ static long btrfs_fallocate(struct inode *inode, int mode,
 	u64 mask = BTRFS_I(inode)->root->sectorsize - 1;
 	struct extent_map *em;
 	struct btrfs_trans_handle *trans;
+	struct btrfs_root *root;
 	int ret;
 
 	alloc_start = offset & ~mask;
@@ -5121,6 +5122,13 @@ static long btrfs_fallocate(struct inode *inode, int mode,
 			goto out;
 	}
 
+	root = BTRFS_I(inode)->root;
+
+	ret = btrfs_check_data_free_space(root, inode,
+					  alloc_end - alloc_start);
+	if (ret)
+		goto out;
+
 	locked_end = alloc_end - 1;
 	while (1) {
 		struct btrfs_ordered_extent *ordered;
@@ -5128,7 +5136,7 @@ static long btrfs_fallocate(struct inode *inode, int mode,
 		trans = btrfs_start_transaction(BTRFS_I(inode)->root, 1);
 		if (!trans) {
 			ret = -EIO;
-			goto out;
+			goto out_free;
 		}
 
 		/* the extent lock is ordered inside the running
@@ -5189,6 +5197,8 @@ static long btrfs_fallocate(struct inode *inode, int mode,
 		      GFP_NOFS);
 
 	btrfs_end_transaction(trans, BTRFS_I(inode)->root);
+out_free:
+	btrfs_free_reserved_data_space(root, inode, alloc_end - alloc_start);
 out:
 	mutex_unlock(&inode->i_mutex);
 	return ret;
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Btrfs: account for space we may use in fallocate, Linux Kernel Mailing List..., (Fri Jul 3, 5:59 pm)