diff options
author | Liu Bo <bo.li.liu@oracle.com> | 2013-04-16 05:20:28 -0400 |
---|---|---|
committer | Josef Bacik <jbacik@fusionio.com> | 2013-05-06 15:54:55 -0400 |
commit | 0abd5b17249ea5ca49a3a9ad4285cac3dfa8c30b (patch) | |
tree | 26b1399cc7b83ddabd2427d283a5a39a1dd878c5 /fs | |
parent | 3c59ccd32abb8f636b1573533d3e77972e80a9c9 (diff) |
Btrfs: return error when we specify wrong start to defrag
We need such a sanity check for wrong start when we defrag a file, otherwise,
even with a wrong start that's larger than file size, we can end up changing
not only inode's force compress flag but also FS's incompat flags.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/ioctl.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index ace88c1df540..a74edc797531 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -1154,8 +1154,11 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, | |||
1154 | u64 new_align = ~((u64)128 * 1024 - 1); | 1154 | u64 new_align = ~((u64)128 * 1024 - 1); |
1155 | struct page **pages = NULL; | 1155 | struct page **pages = NULL; |
1156 | 1156 | ||
1157 | if (extent_thresh == 0) | 1157 | if (isize == 0) |
1158 | extent_thresh = 256 * 1024; | 1158 | return 0; |
1159 | |||
1160 | if (range->start >= isize) | ||
1161 | return -EINVAL; | ||
1159 | 1162 | ||
1160 | if (range->flags & BTRFS_DEFRAG_RANGE_COMPRESS) { | 1163 | if (range->flags & BTRFS_DEFRAG_RANGE_COMPRESS) { |
1161 | if (range->compress_type > BTRFS_COMPRESS_TYPES) | 1164 | if (range->compress_type > BTRFS_COMPRESS_TYPES) |
@@ -1164,8 +1167,8 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, | |||
1164 | compress_type = range->compress_type; | 1167 | compress_type = range->compress_type; |
1165 | } | 1168 | } |
1166 | 1169 | ||
1167 | if (isize == 0) | 1170 | if (extent_thresh == 0) |
1168 | return 0; | 1171 | extent_thresh = 256 * 1024; |
1169 | 1172 | ||
1170 | /* | 1173 | /* |
1171 | * if we were not given a file, allocate a readahead | 1174 | * if we were not given a file, allocate a readahead |