diff options
author | Andreas Rohner <andreas.rohner@gmx.net> | 2014-04-03 17:50:30 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-04-03 19:21:26 -0400 |
commit | f9f32c44e7016c61f8c60afbe461fbc7d5a6c7cc (patch) | |
tree | 95170ef07f36d0a37f3ab1a26926faf1a6e5b021 | |
parent | 82e11e857be3ffd2a0a952c9db8aa2379e2b9e44 (diff) |
nilfs2: add FITRIM ioctl support for nilfs2
Add support for the FITRIM ioctl, which enables user space tools to
issue TRIM/DISCARD requests to the underlying device. Every clean
segment within the specified range will be discarded.
Signed-off-by: Andreas Rohner <andreas.rohner@gmx.net>
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | fs/nilfs2/ioctl.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c index c19a23158487..422fb54b7377 100644 --- a/fs/nilfs2/ioctl.c +++ b/fs/nilfs2/ioctl.c | |||
@@ -1072,6 +1072,48 @@ out: | |||
1072 | } | 1072 | } |
1073 | 1073 | ||
1074 | /** | 1074 | /** |
1075 | * nilfs_ioctl_trim_fs() - trim ioctl handle function | ||
1076 | * @inode: inode object | ||
1077 | * @argp: pointer on argument from userspace | ||
1078 | * | ||
1079 | * Decription: nilfs_ioctl_trim_fs is the FITRIM ioctl handle function. It | ||
1080 | * checks the arguments from userspace and calls nilfs_sufile_trim_fs, which | ||
1081 | * performs the actual trim operation. | ||
1082 | * | ||
1083 | * Return Value: On success, 0 is returned or negative error code, otherwise. | ||
1084 | */ | ||
1085 | static int nilfs_ioctl_trim_fs(struct inode *inode, void __user *argp) | ||
1086 | { | ||
1087 | struct the_nilfs *nilfs = inode->i_sb->s_fs_info; | ||
1088 | struct request_queue *q = bdev_get_queue(nilfs->ns_bdev); | ||
1089 | struct fstrim_range range; | ||
1090 | int ret; | ||
1091 | |||
1092 | if (!capable(CAP_SYS_ADMIN)) | ||
1093 | return -EPERM; | ||
1094 | |||
1095 | if (!blk_queue_discard(q)) | ||
1096 | return -EOPNOTSUPP; | ||
1097 | |||
1098 | if (copy_from_user(&range, argp, sizeof(range))) | ||
1099 | return -EFAULT; | ||
1100 | |||
1101 | range.minlen = max_t(u64, range.minlen, q->limits.discard_granularity); | ||
1102 | |||
1103 | down_read(&nilfs->ns_segctor_sem); | ||
1104 | ret = nilfs_sufile_trim_fs(nilfs->ns_sufile, &range); | ||
1105 | up_read(&nilfs->ns_segctor_sem); | ||
1106 | |||
1107 | if (ret < 0) | ||
1108 | return ret; | ||
1109 | |||
1110 | if (copy_to_user(argp, &range, sizeof(range))) | ||
1111 | return -EFAULT; | ||
1112 | |||
1113 | return 0; | ||
1114 | } | ||
1115 | |||
1116 | /** | ||
1075 | * nilfs_ioctl_set_alloc_range - limit range of segments to be allocated | 1117 | * nilfs_ioctl_set_alloc_range - limit range of segments to be allocated |
1076 | * @inode: inode object | 1118 | * @inode: inode object |
1077 | * @argp: pointer on argument from userspace | 1119 | * @argp: pointer on argument from userspace |
@@ -1296,6 +1338,8 @@ long nilfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | |||
1296 | return nilfs_ioctl_resize(inode, filp, argp); | 1338 | return nilfs_ioctl_resize(inode, filp, argp); |
1297 | case NILFS_IOCTL_SET_ALLOC_RANGE: | 1339 | case NILFS_IOCTL_SET_ALLOC_RANGE: |
1298 | return nilfs_ioctl_set_alloc_range(inode, argp); | 1340 | return nilfs_ioctl_set_alloc_range(inode, argp); |
1341 | case FITRIM: | ||
1342 | return nilfs_ioctl_trim_fs(inode, argp); | ||
1299 | default: | 1343 | default: |
1300 | return -ENOTTY; | 1344 | return -ENOTTY; |
1301 | } | 1345 | } |
@@ -1327,6 +1371,7 @@ long nilfs_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | |||
1327 | case NILFS_IOCTL_SYNC: | 1371 | case NILFS_IOCTL_SYNC: |
1328 | case NILFS_IOCTL_RESIZE: | 1372 | case NILFS_IOCTL_RESIZE: |
1329 | case NILFS_IOCTL_SET_ALLOC_RANGE: | 1373 | case NILFS_IOCTL_SET_ALLOC_RANGE: |
1374 | case FITRIM: | ||
1330 | break; | 1375 | break; |
1331 | default: | 1376 | default: |
1332 | return -ENOIOCTLCMD; | 1377 | return -ENOIOCTLCMD; |