From: Lukas Czerner <lczerner@redhat.com>
To: tytso@mit.edu
Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, hch@infradead.org,
sandeen@redhat.com, lczerner@redhat.com
Subject: [PATCH 2/2] ext4: Add EXT4_IOC_TRIM ioctl to handle batched discard
Date: Thu, 18 Nov 2010 08:36:49 +0100 [thread overview]
Message-ID: <1290065809-3976-2-git-send-email-lczerner@redhat.com> (raw)
In-Reply-To: <1290065809-3976-1-git-send-email-lczerner@redhat.com>
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(-)
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;
}
--
1.7.2.3
next prev parent reply other threads:[~2010-11-18 7:37 UTC|newest]
Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-18 7:36 [PATCH 1/2] fs: Do not dispatch FITRIM through separate super_operation Lukas Czerner
2010-11-18 7:36 ` Lukas Czerner [this message]
2010-11-19 16:19 ` [PATCH 2/2] ext4: Add EXT4_IOC_TRIM ioctl to handle batched discard Ted Ts'o
2010-11-19 16:26 ` Lukas Czerner
2010-11-20 1:37 ` Ted Ts'o
2010-11-18 13:06 ` [PATCH 1/2] fs: Do not dispatch FITRIM through separate super_operation Matthew Wilcox
2010-11-18 13:48 ` Josef Bacik
2010-11-18 14:19 ` Matthew Wilcox
2010-11-18 14:29 ` Christoph Hellwig
2010-11-18 17:19 ` James Bottomley
2010-11-18 17:22 ` Jeff Moyer
2010-11-18 17:41 ` James Bottomley
2010-11-18 20:04 ` Greg Freemyer
2010-11-18 21:42 ` Mark Lord
2010-11-18 21:44 ` Mark Lord
2010-11-18 21:50 ` James Bottomley
2010-11-18 22:07 ` Mark Lord
2010-11-19 1:33 ` Ted Ts'o
2010-11-19 3:44 ` Mark Lord
2010-11-19 13:58 ` Jeff Moyer
2010-11-18 23:52 ` Martin K. Petersen
2010-11-19 0:34 ` Mark Lord
2010-11-19 1:16 ` Greg Freemyer
2010-11-19 11:55 ` Christoph Hellwig
2010-11-19 14:01 ` Mark Lord
2010-11-19 14:06 ` Christoph Hellwig
2010-11-19 14:48 ` Mark Lord
2010-11-19 14:54 ` Christoph Hellwig
2010-11-19 15:24 ` Mark Lord
2010-11-19 15:34 ` Christoph Hellwig
2010-11-19 16:20 ` Greg Freemyer
2010-11-19 16:38 ` Christoph Hellwig
2010-11-19 18:06 ` Lukas Czerner
2010-11-19 18:10 ` Lukas Czerner
2010-11-19 18:14 ` Lukas Czerner
2010-11-19 19:29 ` Chris Mason
2010-11-19 1:49 ` Martin K. Petersen
2010-11-19 3:42 ` Mark Lord
2010-11-18 18:05 ` Jamie Lokier
2010-11-18 19:32 ` Markus Trippelsdorf
2010-11-18 21:45 ` Mark Lord
2010-11-18 21:50 ` Markus Trippelsdorf
2010-11-18 22:09 ` Mark Lord
2010-11-18 17:35 ` Lukas Czerner
2010-11-19 12:16 ` Steven Whitehouse
2010-11-19 13:53 ` Mark Lord
2010-11-19 14:02 ` Ted Ts'o
2010-11-19 14:10 ` Christoph Hellwig
2010-11-19 14:50 ` Mark Lord
2010-11-19 15:35 ` Mark Lord
2010-11-19 15:44 ` Lukas Czerner
2010-11-19 16:30 ` Ted Ts'o
2010-11-19 22:49 ` Mark Lord
2010-11-25 2:48 ` Mark Lord
2010-11-25 4:23 ` Martin K. Petersen
2010-11-25 14:44 ` Mark Lord
2010-11-25 4:41 ` Greg Freemyer
2010-11-25 14:53 ` Mark Lord
2010-11-25 16:24 ` Greg Freemyer
2010-11-26 13:49 ` Mark Lord
2010-11-26 14:00 ` Lukas Czerner
[not found] ` <20101119141007.GB25488@infradead.org>
2010-11-19 15:37 ` Ted Ts'o
2010-11-19 15:50 ` Christoph Hellwig
2010-11-19 16:16 ` Ted Ts'o
2010-11-18 17:55 ` Chris Mason
2010-12-03 18:24 ` Ric Wheeler
2010-11-18 21:37 ` Mark Lord
2010-11-19 11:09 ` Christoph Hellwig
2010-11-19 13:54 ` Mark Lord
2010-11-19 14:40 ` Chris Mason
2010-11-19 14:53 ` Mark Lord
2010-11-19 14:57 ` Christoph Hellwig
2010-11-19 15:21 ` Mark Lord
2010-12-07 9:27 ` Christoph Hellwig
2010-12-07 16:52 ` Chris Mason
2011-06-02 4:52 ` Kyungmin Park
2011-06-02 8:14 ` Lukas Czerner
2011-06-03 2:06 ` Dave Chinner
2011-06-03 4:25 ` Kyungmin Park
2010-11-19 15:30 ` Mark Lord
2010-11-21 19:07 ` Valdis.Kletnieks
2010-11-21 20:20 ` James Bottomley
2010-11-18 14:31 ` Josef Bacik
2010-11-18 14:36 ` Tao Ma
2010-11-19 15:41 ` Ted Ts'o
2010-11-19 15:50 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1290065809-3976-2-git-send-email-lczerner@redhat.com \
--to=lczerner@redhat.com \
--cc=hch@infradead.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sandeen@redhat.com \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).