From 5710911ece194655aa4379bb76c7f3f9827f174b Mon Sep 17 00:00:00 2001 From: Liu Bo Date: Wed, 22 Aug 2012 20:10:38 -0600 Subject: [PATCH] --- yaml --- r: 322372 b: refs/heads/master c: 24c03fa5cf3d02c327cf9f2fc39f72664b1bd7e1 h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/fs/btrfs/inode.c | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/[refs] b/[refs] index c4599f5fd288..1a6377ffc726 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: bd7de2c9a449e26a5493d918618eb20ae60d56bd +refs/heads/master: 24c03fa5cf3d02c327cf9f2fc39f72664b1bd7e1 diff --git a/trunk/fs/btrfs/inode.c b/trunk/fs/btrfs/inode.c index 0808f483dafa..38cda78de5e4 100644 --- a/trunk/fs/btrfs/inode.c +++ b/trunk/fs/btrfs/inode.c @@ -5992,11 +5992,27 @@ static int btrfs_get_blocks_direct(struct inode *inode, sector_t iblock, * in the case of read we need to unlock only the end area that we * aren't using if there is any left over space. */ - if (lockstart < lockend) - clear_extent_bit(&BTRFS_I(inode)->io_tree, lockstart, lockend, - unlock_bits, 1, 0, &cached_state, GFP_NOFS); - else + if (lockstart < lockend) { + if (create && len < lockend - lockstart) { + clear_extent_bit(&BTRFS_I(inode)->io_tree, lockstart, + lockstart + len - 1, unlock_bits, 1, 0, + &cached_state, GFP_NOFS); + /* + * Beside unlock, we also need to cleanup reserved space + * for the left range by attaching EXTENT_DO_ACCOUNTING. + */ + clear_extent_bit(&BTRFS_I(inode)->io_tree, + lockstart + len, lockend, + unlock_bits | EXTENT_DO_ACCOUNTING, + 1, 0, NULL, GFP_NOFS); + } else { + clear_extent_bit(&BTRFS_I(inode)->io_tree, lockstart, + lockend, unlock_bits, 1, 0, + &cached_state, GFP_NOFS); + } + } else { free_extent_state(cached_state); + } free_extent_map(em);