From 19e8ac2721148a475833d7b5f893f9b81fbb0045 Mon Sep 17 00:00:00 2001 From: Jie Liu Date: Tue, 21 Jan 2014 15:48:34 -0800 Subject: ocfs2: return EOPNOTSUPP if the device does not support discard For FITRIM ioctl(2), we should return EOPNOTSUPP to inform the user that the storage device does not support discard if it is, otherwise return success would confuse the user even though there is no free blocks were trimmed at all. Signed-off-by: Jie Liu Cc: Mark Fasheh Cc: Joel Becker Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- fs/ocfs2/ioctl.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'fs/ocfs2/ioctl.c') diff --git a/fs/ocfs2/ioctl.c b/fs/ocfs2/ioctl.c index fa32ce9b455d..4de6a2af592f 100644 --- a/fs/ocfs2/ioctl.c +++ b/fs/ocfs2/ioctl.c @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -966,12 +967,16 @@ long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) case FITRIM: { struct super_block *sb = inode->i_sb; + struct request_queue *q = bdev_get_queue(sb->s_bdev); struct fstrim_range range; int ret = 0; if (!capable(CAP_SYS_ADMIN)) return -EPERM; + if (!blk_queue_discard(q)) + return -EOPNOTSUPP; + if (copy_from_user(&range, argp, sizeof(range))) return -EFAULT; -- cgit v1.2.3 From 1ba2212bb3e9527a4b3d18692f5ffe204f29bb47 Mon Sep 17 00:00:00 2001 From: Jie Liu Date: Tue, 21 Jan 2014 15:48:36 -0800 Subject: ocfs2: adjust minlen with discard_granularity in the FITRIM ioctl Adjust minlen with discard_granularity for FITRIM ioctl(2) if the given minimum size in bytes is less than it because, discard granularity is used to tell us that the minimum size of extent that can be discarded by the storage device. This is inspired by ext4 commit 5c2ed62fd447 ("ext4: Adjust minlen with discard_granularity in the FITRIM ioctl") from Lukas Czerner. Signed-off-by: Jie Liu Cc: Mark Fasheh Cc: Joel Becker Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- fs/ocfs2/ioctl.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'fs/ocfs2/ioctl.c') diff --git a/fs/ocfs2/ioctl.c b/fs/ocfs2/ioctl.c index 4de6a2af592f..8ca3c29accbf 100644 --- a/fs/ocfs2/ioctl.c +++ b/fs/ocfs2/ioctl.c @@ -980,6 +980,8 @@ long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) if (copy_from_user(&range, argp, sizeof(range))) return -EFAULT; + range.minlen = max_t(u64, q->limits.discard_granularity, + range.minlen); ret = ocfs2_trim_fs(sb, &range); if (ret < 0) return ret; -- cgit v1.2.3