Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0fff129e authored by Dmitry Shmidt's avatar Dmitry Shmidt
Browse files

Revert "ANDROID: fs: ext4: Add support for FIDTRIM, a best-effort ioctl for deep discard trim"

This reverts commit 19e04962.

FIDTRIM usage was removed from vold
parent a53dc75a
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -2453,8 +2453,7 @@ extern int ext4_mb_add_groupinfo(struct super_block *sb,
		ext4_group_t i, struct ext4_group_desc *desc);
extern int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
				ext4_fsblk_t block, unsigned long count);
extern int ext4_trim_fs(struct super_block *, struct fstrim_range *,
				unsigned long blkdev_flags);
extern int ext4_trim_fs(struct super_block *, struct fstrim_range *);
extern void ext4_process_freed_data(struct super_block *sb, tid_t commit_tid);

/* inode.c */
+1 −6
Original line number Diff line number Diff line
@@ -910,13 +910,11 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
		return err;
	}

	case FIDTRIM:
	case FITRIM:
	{
		struct request_queue *q = bdev_get_queue(sb->s_bdev);
		struct fstrim_range range;
		int ret = 0;
		int flags  = cmd == FIDTRIM ? BLKDEV_DISCARD_SECURE : 0;

		if (!capable(CAP_SYS_ADMIN))
			return -EPERM;
@@ -924,16 +922,13 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
		if (!blk_queue_discard(q))
			return -EOPNOTSUPP;

		if ((flags & BLKDEV_DISCARD_SECURE) && !blk_queue_secure_erase(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 = ext4_trim_fs(sb, &range, flags);
		ret = ext4_trim_fs(sb, &range);
		if (ret < 0)
			return ret;

+10 −16
Original line number Diff line number Diff line
@@ -2786,7 +2786,7 @@ int ext4_mb_release(struct super_block *sb)

static inline int ext4_issue_discard(struct super_block *sb,
		ext4_group_t block_group, ext4_grpblk_t cluster, int count,
		struct bio **biop, unsigned long flags)
		struct bio **biop)
{
	ext4_fsblk_t discard_block;

@@ -2801,7 +2801,7 @@ static inline int ext4_issue_discard(struct super_block *sb,
			(sector_t)count << (sb->s_blocksize_bits - 9),
			GFP_NOFS, 0, biop);
	} else
		return sb_issue_discard(sb, discard_block, count, GFP_NOFS, flags);
		return sb_issue_discard(sb, discard_block, count, GFP_NOFS, 0);
}

static void ext4_free_data_in_buddy(struct super_block *sb,
@@ -2885,7 +2885,7 @@ void ext4_process_freed_data(struct super_block *sb, tid_t commit_tid)
			err = ext4_issue_discard(sb, entry->efd_group,
						 entry->efd_start_cluster,
						 entry->efd_count,
						 &discard_bio, 0);
						 &discard_bio);
			if (err && err != -EOPNOTSUPP) {
				ext4_msg(sb, KERN_WARNING, "discard request in"
					 " group:%d block:%d count:%d failed"
@@ -4920,7 +4920,7 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode,
		 */
		if (test_opt(sb, DISCARD)) {
			err = ext4_issue_discard(sb, block_group, bit, count,
						 NULL, 0);
						 NULL);
			if (err && err != -EOPNOTSUPP)
				ext4_msg(sb, KERN_WARNING, "discard request in"
					 " group:%d block:%d count:%lu failed"
@@ -5116,15 +5116,13 @@ int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
 * @count:	number of blocks to TRIM
 * @group:	alloc. group we are working with
 * @e4b:	ext4 buddy for the group
 * @blkdev_flags: flags for the block device
 *
 * Trim "count" blocks starting at "start" in the "group". To assure that no
 * one will allocate those blocks, mark it as used in buddy bitmap. This must
 * be called with under the group lock.
 */
static int ext4_trim_extent(struct super_block *sb, int start, int count,
			    ext4_group_t group, struct ext4_buddy *e4b,
			    unsigned long blkdev_flags)
			     ext4_group_t group, struct ext4_buddy *e4b)
__releases(bitlock)
__acquires(bitlock)
{
@@ -5145,7 +5143,7 @@ __acquires(bitlock)
	 */
	mb_mark_used(e4b, &ex);
	ext4_unlock_group(sb, group);
	ret = ext4_issue_discard(sb, group, start, count, NULL, blkdev_flags);
	ret = ext4_issue_discard(sb, group, start, count, NULL);
	ext4_lock_group(sb, group);
	mb_free_blocks(NULL, e4b, start, ex.fe_len);
	return ret;
@@ -5158,7 +5156,6 @@ __acquires(bitlock)
 * @start:		first group block to examine
 * @max:		last group block to examine
 * @minblocks:		minimum extent block count
 * @blkdev_flags:	flags for the block device
 *
 * ext4_trim_all_free walks through group's buddy bitmap searching for free
 * extents. When the free block is found, ext4_trim_extent is called to TRIM
@@ -5173,7 +5170,7 @@ __acquires(bitlock)
static ext4_grpblk_t
ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
		   ext4_grpblk_t start, ext4_grpblk_t max,
		   ext4_grpblk_t minblocks, unsigned long blkdev_flags)
		   ext4_grpblk_t minblocks)
{
	void *bitmap;
	ext4_grpblk_t next, count = 0, free_count = 0;
@@ -5206,8 +5203,7 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,

		if ((next - start) >= minblocks) {
			ret = ext4_trim_extent(sb, start,
					       next - start, group, &e4b,
					       blkdev_flags);
					       next - start, group, &e4b);
			if (ret && ret != -EOPNOTSUPP)
				break;
			ret = 0;
@@ -5249,7 +5245,6 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
 * ext4_trim_fs() -- trim ioctl handle function
 * @sb:			superblock for filesystem
 * @range:		fstrim_range structure
 * @blkdev_flags:	flags for the block device
 *
 * start:	First Byte to trim
 * len:		number of Bytes to trim from start
@@ -5258,8 +5253,7 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
 * start to start+len. For each such a group ext4_trim_all_free function
 * is invoked to trim all free space.
 */
int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range,
			unsigned long blkdev_flags)
int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
{
	struct ext4_group_info *grp;
	ext4_group_t group, first_group, last_group;
@@ -5315,7 +5309,7 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range,

		if (grp->bb_free >= minlen) {
			cnt = ext4_trim_all_free(sb, group, first_cluster,
						end, minlen, blkdev_flags);
						end, minlen);
			if (cnt < 0) {
				ret = cnt;
				break;
+0 −2
Original line number Diff line number Diff line
@@ -242,8 +242,6 @@ struct fsxattr {
#define FICLONERANGE	_IOW(0x94, 13, struct file_clone_range)
#define FIDEDUPERANGE	_IOWR(0x94, 54, struct file_dedupe_range)

#define FIDTRIM	_IOWR('f', 128, struct fstrim_range)	/* Deep discard trim */

#define	FS_IOC_GETFLAGS			_IOR('f', 1, long)
#define	FS_IOC_SETFLAGS			_IOW('f', 2, long)
#define	FS_IOC_GETVERSION		_IOR('v', 1, long)