diff options
author | Chris Mason <chris.mason@oracle.com> | 2008-01-30 14:33:02 -0500 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2008-09-25 11:04:00 -0400 |
commit | 1b0f7c29e2f4f41e1367e7581d3a9c8c70f0394a (patch) | |
tree | cc9b9b7282496d521b8ed43cc45848b31ed9d717 /fs/btrfs | |
parent | f392a938f3cc36a2abe68db9286bd864c3b2f7dd (diff) |
Fix hole start calculation in btrfs_settar
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/inode.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 515f8b01ab04..bcf3b35fb65e 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -1000,20 +1000,14 @@ static int btrfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
1000 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; | 1000 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; |
1001 | 1001 | ||
1002 | u64 mask = root->sectorsize - 1; | 1002 | u64 mask = root->sectorsize - 1; |
1003 | u64 pos = (inode->i_size + mask) & ~mask; | 1003 | u64 hole_start = (inode->i_size + mask) & ~mask; |
1004 | u64 block_end = (attr->ia_size + mask) & ~mask; | 1004 | u64 block_end = (attr->ia_size + mask) & ~mask; |
1005 | u64 hole_start; | ||
1006 | u64 hole_size; | 1005 | u64 hole_size; |
1007 | u64 alloc_hint = 0; | 1006 | u64 alloc_hint = 0; |
1008 | 1007 | ||
1009 | if (attr->ia_size <= pos) | 1008 | if (attr->ia_size <= hole_start) |
1010 | goto out; | 1009 | goto out; |
1011 | 1010 | ||
1012 | if (pos != inode->i_size) | ||
1013 | hole_start = pos + root->sectorsize; | ||
1014 | else | ||
1015 | hole_start = pos; | ||
1016 | |||
1017 | mutex_lock(&root->fs_info->fs_mutex); | 1011 | mutex_lock(&root->fs_info->fs_mutex); |
1018 | err = btrfs_check_free_space(root, 1, 0); | 1012 | err = btrfs_check_free_space(root, 1, 0); |
1019 | mutex_unlock(&root->fs_info->fs_mutex); | 1013 | mutex_unlock(&root->fs_info->fs_mutex); |
@@ -1022,14 +1016,14 @@ static int btrfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
1022 | 1016 | ||
1023 | btrfs_truncate_page(inode->i_mapping, inode->i_size); | 1017 | btrfs_truncate_page(inode->i_mapping, inode->i_size); |
1024 | 1018 | ||
1025 | lock_extent(io_tree, pos, block_end - 1, GFP_NOFS); | 1019 | lock_extent(io_tree, hole_start, block_end - 1, GFP_NOFS); |
1026 | hole_size = block_end - hole_start; | 1020 | hole_size = block_end - hole_start; |
1027 | 1021 | ||
1028 | mutex_lock(&root->fs_info->fs_mutex); | 1022 | mutex_lock(&root->fs_info->fs_mutex); |
1029 | trans = btrfs_start_transaction(root, 1); | 1023 | trans = btrfs_start_transaction(root, 1); |
1030 | btrfs_set_trans_block_group(trans, inode); | 1024 | btrfs_set_trans_block_group(trans, inode); |
1031 | err = btrfs_drop_extents(trans, root, inode, | 1025 | err = btrfs_drop_extents(trans, root, inode, |
1032 | pos, block_end, pos, | 1026 | hole_start, block_end, hole_start, |
1033 | &alloc_hint); | 1027 | &alloc_hint); |
1034 | 1028 | ||
1035 | if (alloc_hint != EXTENT_MAP_INLINE) { | 1029 | if (alloc_hint != EXTENT_MAP_INLINE) { |
@@ -1043,7 +1037,7 @@ static int btrfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
1043 | } | 1037 | } |
1044 | btrfs_end_transaction(trans, root); | 1038 | btrfs_end_transaction(trans, root); |
1045 | mutex_unlock(&root->fs_info->fs_mutex); | 1039 | mutex_unlock(&root->fs_info->fs_mutex); |
1046 | unlock_extent(io_tree, pos, block_end - 1, GFP_NOFS); | 1040 | unlock_extent(io_tree, hole_start, block_end - 1, GFP_NOFS); |
1047 | if (err) | 1041 | if (err) |
1048 | return err; | 1042 | return err; |
1049 | } | 1043 | } |