Skip to content

Commit

Permalink
ext4: check if device support discard in FITRIM ioctl
Browse files Browse the repository at this point in the history
For a device that does not support discard, the FITRIM ioctl returns
-EOPNOTSUPP when blkdev_issue_discard() returns this error code, which
is how the user is informed that the device does not support discard.

If there are no suitable free extents to be trimmed, then FITRIM will
return success even though the device does not support discard, which
could confuse the user.  So check explicitly if the device supports
discard and return an error code at the beginning of the FITRIM ioctl
processing.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
  • Loading branch information
Lukas Czerner authored and Theodore Ts'o committed Feb 23, 2011
1 parent 0b75a84 commit 4143179
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fs/ext4/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,16 @@ long ext4_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, (struct fstrim_range *)arg,
sizeof(range)))
return -EFAULT;
Expand Down

0 comments on commit 4143179

Please sign in to comment.