aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiao Xie <miaox@cn.fujitsu.com>2013-02-21 04:48:22 -0500
committerChris Mason <chris.mason@fusionio.com>2013-02-21 08:11:43 -0500
commit172a50497ffaf84d60dff37fbeb03894268fe5c2 (patch)
tree7aae1c2d33bba4ef727d89e573a02cc90c7fcfc4
parent38c227d87c49ad5d173cb5d4374d49acec6a495d (diff)
Btrfs: fix wrong outstanding_extents when doing DIO write
When running the 083th case of xfstests on the filesystem with "compress-force=lzo", the following WARNINGs were triggered. WARNING: at fs/btrfs/inode.c:7908 WARNING: at fs/btrfs/inode.c:7909 WARNING: at fs/btrfs/inode.c:7911 WARNING: at fs/btrfs/extent-tree.c:4510 WARNING: at fs/btrfs/extent-tree.c:4511 This problem was introduced by the patch "Btrfs: fix deadlock due to unsubmitted". In this patch, there are two bugs which caused the above problem. The 1st one is a off-by-one bug, if the DIO write return 0, it is also a short write, we need release the reserved space for it. But we didn't do it in that patch. Fix it by change "ret > 0" to "ret >= 0". The 2nd one is ->outstanding_extents was increased twice when a short write happened. As we know, ->outstanding_extents is a counter to keep track of the number of extent items we may use duo to delalloc, when we reserve the free space for a delalloc write, we assume that the write will introduce just one extent item, so we increase ->outstanding_extents by 1 at that time. And then we will increase it every time we split the write, it is done at the beginning of btrfs_get_blocks_direct(). So when a short write happens, we needn't increase ->outstanding_extents again. But this patch done. In order to fix the 2nd problem, I re-write the logic for ->outstanding_extents operation. We don't increase it at the beginning of btrfs_get_blocks_direct(), instead, we just increase it when the split actually happens. Reported-by: Mitch Harder <mitch.harder@sabayonlinux.org> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
-rw-r--r--fs/btrfs/inode.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 4d0aec0cf5d8..40d49da5e846 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -6708,12 +6708,9 @@ static int btrfs_get_blocks_direct(struct inode *inode, sector_t iblock,
6708 int unlock_bits = EXTENT_LOCKED; 6708 int unlock_bits = EXTENT_LOCKED;
6709 int ret = 0; 6709 int ret = 0;
6710 6710
6711 if (create) { 6711 if (create)
6712 spin_lock(&BTRFS_I(inode)->lock);
6713 BTRFS_I(inode)->outstanding_extents++;
6714 spin_unlock(&BTRFS_I(inode)->lock);
6715 unlock_bits |= EXTENT_DELALLOC | EXTENT_DIRTY; 6712 unlock_bits |= EXTENT_DELALLOC | EXTENT_DIRTY;
6716 } else 6713 else
6717 len = min_t(u64, len, root->sectorsize); 6714 len = min_t(u64, len, root->sectorsize);
6718 6715
6719 lockstart = start; 6716 lockstart = start;
@@ -6855,6 +6852,10 @@ unlock:
6855 if (start + len > i_size_read(inode)) 6852 if (start + len > i_size_read(inode))
6856 i_size_write(inode, start + len); 6853 i_size_write(inode, start + len);
6857 6854
6855 spin_lock(&BTRFS_I(inode)->lock);
6856 BTRFS_I(inode)->outstanding_extents++;
6857 spin_unlock(&BTRFS_I(inode)->lock);
6858
6858 ret = set_extent_bit(&BTRFS_I(inode)->io_tree, lockstart, 6859 ret = set_extent_bit(&BTRFS_I(inode)->io_tree, lockstart,
6859 lockstart + len - 1, EXTENT_DELALLOC, NULL, 6860 lockstart + len - 1, EXTENT_DELALLOC, NULL,
6860 &cached_state, GFP_NOFS); 6861 &cached_state, GFP_NOFS);
@@ -7362,14 +7363,11 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb,
7362 if (rw & WRITE) { 7363 if (rw & WRITE) {
7363 if (ret < 0 && ret != -EIOCBQUEUED) 7364 if (ret < 0 && ret != -EIOCBQUEUED)
7364 btrfs_delalloc_release_space(inode, count); 7365 btrfs_delalloc_release_space(inode, count);
7365 else if (ret > 0 && (size_t)ret < count) { 7366 else if (ret >= 0 && (size_t)ret < count)
7366 spin_lock(&BTRFS_I(inode)->lock);
7367 BTRFS_I(inode)->outstanding_extents++;
7368 spin_unlock(&BTRFS_I(inode)->lock);
7369 btrfs_delalloc_release_space(inode, 7367 btrfs_delalloc_release_space(inode,
7370 count - (size_t)ret); 7368 count - (size_t)ret);
7371 } 7369 else
7372 btrfs_delalloc_release_metadata(inode, 0); 7370 btrfs_delalloc_release_metadata(inode, 0);
7373 } 7371 }
7374out: 7372out:
7375 if (wakeup) 7373 if (wakeup)