linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Enrico Weigelt, metux IT consult" <info@metux.net>
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	viro@zeniv.linux.org.uk
Subject: [RFC PATCH 5/6] fs: fat: move fstrim to file_operation
Date: Tue, 22 Jun 2021 14:11:35 +0200	[thread overview]
Message-ID: <20210622121136.4394-6-info@metux.net> (raw)
In-Reply-To: <20210622121136.4394-1-info@metux.net>

Use the newly introduced file_operation callback for FITRIM ioctl.
This removes some common code, eg. permission check, buffer copying,
which is now done by generic vfs code.
---
 fs/fat/file.c | 25 ++++---------------------
 1 file changed, 4 insertions(+), 21 deletions(-)

diff --git a/fs/fat/file.c b/fs/fat/file.c
index 13855ba49cd9..5f57f06341d0 100644
--- a/fs/fat/file.c
+++ b/fs/fat/file.c
@@ -122,35 +122,20 @@ static int fat_ioctl_get_volume_id(struct inode *inode, u32 __user *user_attr)
 	return put_user(sbi->vol_id, user_attr);
 }
 
-static int fat_ioctl_fitrim(struct inode *inode, unsigned long arg)
+static int fat_ioctl_fitrim(struct file *file, struct fstrim_range *range)
 {
+	struct inode *inode = file_inode(file);
 	struct super_block *sb = inode->i_sb;
-	struct fstrim_range __user *user_range;
-	struct fstrim_range range;
 	struct request_queue *q = bdev_get_queue(sb->s_bdev);
 	int err;
 
-	if (!capable(CAP_SYS_ADMIN))
-		return -EPERM;
-
 	if (!blk_queue_discard(q))
 		return -EOPNOTSUPP;
 
-	user_range = (struct fstrim_range __user *)arg;
-	if (copy_from_user(&range, user_range, sizeof(range)))
-		return -EFAULT;
-
-	range.minlen = max_t(unsigned int, range.minlen,
+	range->minlen = max_t(unsigned int, range->minlen,
 			     q->limits.discard_granularity);
 
-	err = fat_trim_fs(inode, &range);
-	if (err < 0)
-		return err;
-
-	if (copy_to_user(user_range, &range, sizeof(range)))
-		return -EFAULT;
-
-	return 0;
+	return fat_trim_fs(inode, range);
 }
 
 long fat_generic_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
@@ -165,8 +150,6 @@ long fat_generic_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		return fat_ioctl_set_attributes(filp, user_attr);
 	case FAT_IOCTL_GET_VOLUME_ID:
 		return fat_ioctl_get_volume_id(inode, user_attr);
-	case FITRIM:
-		return fat_ioctl_fitrim(inode, arg);
 	default:
 		return -ENOTTY;	/* Inappropriate ioctl for device */
 	}
-- 
2.20.1


  parent reply	other threads:[~2021-06-22 12:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-22 12:11 RFC: generic file operation for fstrim ioctl() Enrico Weigelt, metux IT consult
2021-06-22 12:11 ` [RFC PATCH 1/6] fs: generic file operation for fstrim Enrico Weigelt, metux IT consult
2021-06-22 12:11 ` [RFC PATCH 2/6] fs: ext4: move fstrim to file_operation Enrico Weigelt, metux IT consult
2021-06-22 12:11 ` [RFC PATCH 3/6] fs: hpfs: " Enrico Weigelt, metux IT consult
2021-06-22 12:11 ` [RFC PATCH 4/6] fs: btrfs: " Enrico Weigelt, metux IT consult
2021-06-22 12:11 ` Enrico Weigelt, metux IT consult [this message]
2021-06-22 12:11 ` [RFC PATCH 6/6] fs: f2fs: " Enrico Weigelt, metux IT consult

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=20210622121136.4394-6-info@metux.net \
    --to=info@metux.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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).