diff options
author | Jaegeuk Kim <jaegeuk@kernel.org> | 2014-09-21 07:06:39 +0200 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2014-10-01 00:06:09 +0200 |
commit | 4b2fecc84655055a6a1fe9151786992ac04b56ce (patch) | |
tree | 05f5f041260756216c0b3f1a0da2360be31580b6 /fs/f2fs/file.c | |
parent | f2fs: introduce cp_control structure (diff) | |
download | linux-4b2fecc84655055a6a1fe9151786992ac04b56ce.tar.xz linux-4b2fecc84655055a6a1fe9151786992ac04b56ce.zip |
f2fs: introduce FITRIM in f2fs_ioctl
This patch introduces FITRIM in f2fs_ioctl.
In this case, f2fs will issue small discards and prefree discards as many as
possible for the given area.
Reviewed-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/f2fs/file.c')
-rw-r--r-- | fs/f2fs/file.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index ac8c6804097f..11842076d960 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -860,6 +860,35 @@ out: mnt_drop_write_file(filp); return ret; } + 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 __user *)arg, + sizeof(range))) + return -EFAULT; + + range.minlen = max((unsigned int)range.minlen, + q->limits.discard_granularity); + ret = f2fs_trim_fs(F2FS_SB(sb), &range); + if (ret < 0) + return ret; + + if (copy_to_user((struct fstrim_range __user *)arg, &range, + sizeof(range))) + return -EFAULT; + + return 0; + } default: return -ENOTTY; } |