Commit f9f32c44 authored by Andreas Rohner's avatar Andreas Rohner Committed by Linus Torvalds

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: default avatarAndreas Rohner <andreas.rohner@gmx.net>
Signed-off-by: default avatarRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 82e11e85
...@@ -1071,6 +1071,48 @@ static int nilfs_ioctl_resize(struct inode *inode, struct file *filp, ...@@ -1071,6 +1071,48 @@ static int nilfs_ioctl_resize(struct inode *inode, struct file *filp,
return ret; return ret;
} }
/**
* nilfs_ioctl_trim_fs() - trim ioctl handle function
* @inode: inode object
* @argp: pointer on argument from userspace
*
* Decription: nilfs_ioctl_trim_fs is the FITRIM ioctl handle function. It
* checks the arguments from userspace and calls nilfs_sufile_trim_fs, which
* performs the actual trim operation.
*
* Return Value: On success, 0 is returned or negative error code, otherwise.
*/
static int nilfs_ioctl_trim_fs(struct inode *inode, void __user *argp)
{
struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
struct request_queue *q = bdev_get_queue(nilfs->ns_bdev);
struct fstrim_range range;
int ret;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
if (!blk_queue_discard(q))
return -EOPNOTSUPP;
if (copy_from_user(&range, argp, sizeof(range)))
return -EFAULT;
range.minlen = max_t(u64, range.minlen, q->limits.discard_granularity);
down_read(&nilfs->ns_segctor_sem);
ret = nilfs_sufile_trim_fs(nilfs->ns_sufile, &range);
up_read(&nilfs->ns_segctor_sem);
if (ret < 0)
return ret;
if (copy_to_user(argp, &range, sizeof(range)))
return -EFAULT;
return 0;
}
/** /**
* nilfs_ioctl_set_alloc_range - limit range of segments to be allocated * nilfs_ioctl_set_alloc_range - limit range of segments to be allocated
* @inode: inode object * @inode: inode object
...@@ -1296,6 +1338,8 @@ long nilfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -1296,6 +1338,8 @@ long nilfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
return nilfs_ioctl_resize(inode, filp, argp); return nilfs_ioctl_resize(inode, filp, argp);
case NILFS_IOCTL_SET_ALLOC_RANGE: case NILFS_IOCTL_SET_ALLOC_RANGE:
return nilfs_ioctl_set_alloc_range(inode, argp); return nilfs_ioctl_set_alloc_range(inode, argp);
case FITRIM:
return nilfs_ioctl_trim_fs(inode, argp);
default: default:
return -ENOTTY; return -ENOTTY;
} }
...@@ -1327,6 +1371,7 @@ long nilfs_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -1327,6 +1371,7 @@ long nilfs_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
case NILFS_IOCTL_SYNC: case NILFS_IOCTL_SYNC:
case NILFS_IOCTL_RESIZE: case NILFS_IOCTL_RESIZE:
case NILFS_IOCTL_SET_ALLOC_RANGE: case NILFS_IOCTL_SET_ALLOC_RANGE:
case FITRIM:
break; break;
default: default:
return -ENOIOCTLCMD; return -ENOIOCTLCMD;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment