aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorJie Liu <jeff.liu@oracle.com>2014-01-21 18:48:35 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-01-21 19:19:42 -0500
commitaa89762c54800208d5afdcd8e6bf124818f17fe0 (patch)
tree36beda22a4b7bc8697fbd05a02af4a2d0dab1b04 /fs
parent19e8ac2721148a475833d7b5f893f9b81fbb0045 (diff)
ocfs2: return EINVAL if the given range to discard is less than block size
For FITRIM ioctl(2), we should not keep silence if the given range length ls less than a block size as there is no data blocks would be discareded. Hence it should return EINVAL instead. This issue can be verified via xfstests/generic/288 which is used for FITRIM argument handling tests. Signed-off-by: Jie Liu <jeff.liu@oracle.com> Cc: Mark Fasheh <mfasheh@suse.com> Cc: Joel Becker <jlbec@evilplan.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/ocfs2/alloc.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index dc7411fe185d..8750ae1b8636 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -7260,14 +7260,8 @@ int ocfs2_trim_fs(struct super_block *sb, struct fstrim_range *range)
7260 start = range->start >> osb->s_clustersize_bits; 7260 start = range->start >> osb->s_clustersize_bits;
7261 len = range->len >> osb->s_clustersize_bits; 7261 len = range->len >> osb->s_clustersize_bits;
7262 minlen = range->minlen >> osb->s_clustersize_bits; 7262 minlen = range->minlen >> osb->s_clustersize_bits;
7263 trimmed = 0;
7264
7265 if (!len) {
7266 range->len = 0;
7267 return 0;
7268 }
7269 7263
7270 if (minlen >= osb->bitmap_cpg) 7264 if (minlen >= osb->bitmap_cpg || range->len < sb->s_blocksize)
7271 return -EINVAL; 7265 return -EINVAL;
7272 7266
7273 main_bm_inode = ocfs2_get_system_file_inode(osb, 7267 main_bm_inode = ocfs2_get_system_file_inode(osb,
@@ -7293,6 +7287,7 @@ int ocfs2_trim_fs(struct super_block *sb, struct fstrim_range *range)
7293 goto out_unlock; 7287 goto out_unlock;
7294 } 7288 }
7295 7289
7290 len = range->len >> osb->s_clustersize_bits;
7296 if (start + len > le32_to_cpu(main_bm->i_clusters)) 7291 if (start + len > le32_to_cpu(main_bm->i_clusters))
7297 len = le32_to_cpu(main_bm->i_clusters) - start; 7292 len = le32_to_cpu(main_bm->i_clusters) - start;
7298 7293
@@ -7307,6 +7302,7 @@ int ocfs2_trim_fs(struct super_block *sb, struct fstrim_range *range)
7307 last_group = ocfs2_which_cluster_group(main_bm_inode, start + len - 1); 7302 last_group = ocfs2_which_cluster_group(main_bm_inode, start + len - 1);
7308 last_bit = osb->bitmap_cpg; 7303 last_bit = osb->bitmap_cpg;
7309 7304
7305 trimmed = 0;
7310 for (group = first_group; group <= last_group;) { 7306 for (group = first_group; group <= last_group;) {
7311 if (first_bit + len >= osb->bitmap_cpg) 7307 if (first_bit + len >= osb->bitmap_cpg)
7312 last_bit = osb->bitmap_cpg; 7308 last_bit = osb->bitmap_cpg;