Skip to contentSkip to conversation

Btrfs: Fix disk_i_size update corner case

PATCH In review Yan, Zheng 2 participants 2 messages Nov 12, 2009 – Dec 16, 2009 Btrfs file system

lore
Share & tools
lore

Yan, Zheng

author
#0 lore raw

PATCH 4/12 Btrfs: Fix disk_i_size update corner case

There are some cases file extents are inserted without involving ordered struct. In these cases, we update disk_i_size directly, without checking pending ordered extent and DELALLOC bit. This patch extends btrfs_ordered_update_i_size() to handle these cases.

---
 fs/btrfs/btrfs_inode.h  |    5 +--
 fs/btrfs/inode.c        |   70 +++++++++++++++++++++++++++-------------------
 fs/btrfs/ordered-data.c |   71 +++++++++++++++++++++++++++++++++-------------
 fs/btrfs/ordered-data.h |    2 +-
 4 files changed, 94 insertions(+), 54 deletions(-)
fs/btrfs/btrfs_inode.h +1 -4
index f6783a4..3f1f50d 100644
@@ -44,9 +44,6 @@ struct btrfs_inode {
 	 */
 	struct extent_io_tree io_failure_tree;
 
-	/* held while inesrting or deleting extents from files */
-	struct mutex extent_mutex;
-
 	/* held while logging the inode in tree-log.c */
 	struct mutex log_mutex;
 
@@ -166,7 +163,7 @@ static inline struct btrfs_inode *BTRFS_I(struct inode *inode)
 
 static inline void btrfs_i_size_write(struct inode *inode, u64 size)
 {
-	inode->i_size = size;
+	i_size_write(inode, size);
 	BTRFS_I(inode)->disk_i_size = size;
 }
 
fs/btrfs/inode.c +41 -29

172 lines not on this page · raw message

fs/btrfs/ordered-data.c +51 -20

136 lines not on this page · raw message

fs/btrfs/ordered-data.h +1 -1
index 993a7ea..a080180 100644
@@ -150,7 +150,7 @@ void btrfs_start_ordered_extent(struct inode *inode,
 int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len);
 struct btrfs_ordered_extent *
 btrfs_lookup_first_ordered_extent(struct inode * inode, u64 file_offset);
-int btrfs_ordered_update_i_size(struct inode *inode,
+int btrfs_ordered_update_i_size(struct inode *inode, u64 offset,
 				struct btrfs_ordered_extent *ordered);
 int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr, u32 *sum);
 int btrfs_wait_on_page_writeback_range(struct address_space *mapping,
Signature · 1 line
1.6.2.5
#1 lore raw
Quoted 4 lines · Zheng

There are some cases file extents are inserted without involving ordered struct. In these cases, we update disk_i_size directly, without checking pending ordered extent and DELALLOC bit. This patch extends btrfs_ordered_update_i_size() to handle these cases.

I'm hitting problems with this one in testing. I think the issue is that the extent_mutex was protecting us from something like this:

proc1:
process end io for extent [0, 32768] btrfs_ordered_update_i_size() -- update i_disk_size to 32768

proc2:
process end io for extent [32768, 55536] btrfs_ordered_update_i_size() find the rbtree entry [0, 32768], exit

proc1:
remove extent [0, 32768] from rbtree

Because the first extent was still in the rbtree, we didn't update i_size to the full 55536, even though the first extent was fully processed. I think I've got this fixed by removing the extents from the rbtree when we're in btrfs_ordered_update_i_size(). The current patch does this only when an ordered extent was passed in.

-chris