summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-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,
int unlock_bits = EXTENT_LOCKED;
int ret = 0;
- if (create) {
- spin_lock(&BTRFS_I(inode)->lock);
- BTRFS_I(inode)->outstanding_extents++;
- spin_unlock(&BTRFS_I(inode)->lock);
+ if (create)
unlock_bits |= EXTENT_DELALLOC | EXTENT_DIRTY;
- } else
+ else
len = min_t(u64, len, root->sectorsize);
lockstart = start;
@@ -6855,6 +6852,10 @@ unlock:
if (start + len > i_size_read(inode))
i_size_write(inode, start + len);
+ spin_lock(&BTRFS_I(inode)->lock);
+ BTRFS_I(inode)->outstanding_extents++;
+ spin_unlock(&BTRFS_I(inode)->lock);
+
ret = set_extent_bit(&BTRFS_I(inode)->io_tree, lockstart,
lockstart + len - 1, EXTENT_DELALLOC, NULL,
&cached_state, GFP_NOFS);
@@ -7362,14 +7363,11 @@ static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb,
if (rw & WRITE) {
if (ret < 0 && ret != -EIOCBQUEUED)
btrfs_delalloc_release_space(inode, count);
- else if (ret > 0 && (size_t)ret < count) {
- spin_lock(&BTRFS_I(inode)->lock);
- BTRFS_I(inode)->outstanding_extents++;
- spin_unlock(&BTRFS_I(inode)->lock);
+ else if (ret >= 0 && (size_t)ret < count)
btrfs_delalloc_release_space(inode,
count - (size_t)ret);
- }
- btrfs_delalloc_release_metadata(inode, 0);
+ else
+ btrfs_delalloc_release_metadata(inode, 0);
}
out:
if (wakeup)