Message ID | 1290065809-3976-2-git-send-email-lczerner@redhat.com |
---|---|
State | Accepted, archived |
Headers | show |
On Thu, Nov 18, 2010 at 08:36:49AM +0100, Lukas Czerner wrote: > @@ -541,6 +541,7 @@ struct ext4_new_group_data { > /* note ioctl 11 reserved for filesystem-independent FIEMAP ioctl */ > #define EXT4_IOC_ALLOC_DA_BLKS _IO('f', 12) > #define EXT4_IOC_MOVE_EXT _IOWR('f', 15, struct move_extent) > +#define EXT4_IOC_TRIM FITRIM If we're going to keep FITRIM defined in include/fs.h, then we should just dispatch off of FITRIM below, and not define EXT4_IOC_TRIM. > + case EXT4_IOC_TRIM: > + { Agreed? There's no point making this look like an EXT4-specific interface; if other file systems want to implement FITRIM as an ioctl, they are free to do so. - Ted -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Fri, 19 Nov 2010, Ted Ts'o wrote: > On Thu, Nov 18, 2010 at 08:36:49AM +0100, Lukas Czerner wrote: > > @@ -541,6 +541,7 @@ struct ext4_new_group_data { > > /* note ioctl 11 reserved for filesystem-independent FIEMAP ioctl */ > > #define EXT4_IOC_ALLOC_DA_BLKS _IO('f', 12) > > #define EXT4_IOC_MOVE_EXT _IOWR('f', 15, struct move_extent) > > +#define EXT4_IOC_TRIM FITRIM > > If we're going to keep FITRIM defined in include/fs.h, then we should > just dispatch off of FITRIM below, and not define EXT4_IOC_TRIM. > > > + case EXT4_IOC_TRIM: > > + { > > Agreed? I am ok either way, I was just following example of EXT4_IOC_GETFLAGS -> FS_IOC_GETFLAGS etc.. -Lukas > > There's no point making this look like an EXT4-specific interface; if > other file systems want to implement FITRIM as an ioctl, they are free > to do so. > > - Ted > -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Fri, Nov 19, 2010 at 05:26:51PM +0100, Lukas Czerner wrote: > > If we're going to keep FITRIM defined in include/fs.h, then we should > > just dispatch off of FITRIM below, and not define EXT4_IOC_TRIM. > > > > > + case EXT4_IOC_TRIM: > > > + { > > > > Agreed? > > I am ok either way, I was just following example of EXT4_IOC_GETFLAGS -> > FS_IOC_GETFLAGS etc.. The history of that was the ioctl was originally EXT4_IOC_GETFLAGS and it was later generalized to be FS_IOC_GETFLAGS. In this case though we started with it being an generalized interface, so there's no need to create an EXT4_IOC_TRIM ioctl. I'll fix that up in your patch when I add it to the ext4 patch queue. - Ted -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 6a5edea..2af5042 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -541,6 +541,7 @@ struct ext4_new_group_data { /* note ioctl 11 reserved for filesystem-independent FIEMAP ioctl */ #define EXT4_IOC_ALLOC_DA_BLKS _IO('f', 12) #define EXT4_IOC_MOVE_EXT _IOWR('f', 15, struct move_extent) +#define EXT4_IOC_TRIM FITRIM #if defined(__KERNEL__) && defined(CONFIG_COMPAT) /* diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c index bf5ae88..e07944a 100644 --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -331,6 +331,30 @@ mext_out: return err; } + case EXT4_IOC_TRIM: + { + struct super_block *sb = inode->i_sb; + struct fstrim_range range; + int ret = 0; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + if (copy_from_user(&range, (struct fstrim_range *)arg, + sizeof(range))) + return -EFAULT; + + ret = ext4_trim_fs(sb, &range); + if (ret < 0) + return ret; + + if (copy_to_user((struct fstrim_range *)arg, &range, + sizeof(range))) + return -EFAULT; + + return 0; + } + default: return -ENOTTY; }
Filesystem independent ioctl was rejected as not common enough to be in core vfs ioctl. Since we still need to access to this functionality this commit adds ext4 specific ioctl EXT4_IOC_TRIM to dispatch ext4_trim_fs(). It takes fstrim_range structure as an argument. fstrim_range is definec in the include/linux/fs.h and its definition is as follows. struct fstrim_range { __u64 start; __u64 len; __u64 minlen; } start - first Byte to trim len - number of Bytes to trim from start minlen - minimum extent length to trim, free extents shorter than this number of Bytes will be ignored. This will be rounded up to fs block size. After the FITRIM is done, the number of actually discarded Bytes is stored in fstrim_range.len to give the user better insight on how much storage space has been really released for wear-leveling. Signed-off-by: Lukas Czerner <lczerner@redhat.com> --- fs/ext4/ext4.h | 1 + fs/ext4/ioctl.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 0 deletions(-)