linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miklos Szeredi <mszeredi@redhat.com>
To: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Andreas Gruenbacher <agruenba@redhat.com>
Subject: [PATCH 08/18] gfs2: convert to miscattr
Date: Wed,  3 Feb 2021 13:41:02 +0100	[thread overview]
Message-ID: <20210203124112.1182614-9-mszeredi@redhat.com> (raw)
In-Reply-To: <20210203124112.1182614-1-mszeredi@redhat.com>

Use the miscattr API to let the VFS handle locking, permission checking and
conversion.

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Cc: Andreas Gruenbacher <agruenba@redhat.com>
---
 fs/gfs2/file.c  | 56 ++++++++++++-------------------------------------
 fs/gfs2/inode.c |  4 ++++
 fs/gfs2/inode.h |  2 ++
 3 files changed, 19 insertions(+), 43 deletions(-)

diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c
index b39b339feddc..d54c07965665 100644
--- a/fs/gfs2/file.c
+++ b/fs/gfs2/file.c
@@ -25,6 +25,7 @@
 #include <linux/dlm_plock.h>
 #include <linux/delay.h>
 #include <linux/backing-dev.h>
+#include <linux/miscattr.h>
 
 #include "gfs2.h"
 #include "incore.h"
@@ -153,9 +154,9 @@ static inline u32 gfs2_gfsflags_to_fsflags(struct inode *inode, u32 gfsflags)
 	return fsflags;
 }
 
-static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
+int gfs2_miscattr_get(struct dentry *dentry, struct miscattr *ma)
 {
-	struct inode *inode = file_inode(filp);
+	struct inode *inode = d_inode(dentry);
 	struct gfs2_inode *ip = GFS2_I(inode);
 	struct gfs2_holder gh;
 	int error;
@@ -168,8 +169,7 @@ static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
 
 	fsflags = gfs2_gfsflags_to_fsflags(inode, ip->i_diskflags);
 
-	if (put_user(fsflags, ptr))
-		error = -EFAULT;
+	miscattr_fill_flags(ma, fsflags);
 
 	gfs2_glock_dq(&gh);
 out_uninit:
@@ -213,33 +213,19 @@ void gfs2_set_inode_flags(struct inode *inode)
  * @fsflags: The FS_* inode flags passed in
  *
  */
-static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask,
+static int do_gfs2_set_flags(struct inode *inode, u32 reqflags, u32 mask,
 			     const u32 fsflags)
 {
-	struct inode *inode = file_inode(filp);
 	struct gfs2_inode *ip = GFS2_I(inode);
 	struct gfs2_sbd *sdp = GFS2_SB(inode);
 	struct buffer_head *bh;
 	struct gfs2_holder gh;
 	int error;
-	u32 new_flags, flags, oldflags;
-
-	error = mnt_want_write_file(filp);
-	if (error)
-		return error;
+	u32 new_flags, flags;
 
 	error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
 	if (error)
-		goto out_drop_write;
-
-	oldflags = gfs2_gfsflags_to_fsflags(inode, ip->i_diskflags);
-	error = vfs_ioc_setflags_prepare(inode, oldflags, fsflags);
-	if (error)
-		goto out;
-
-	error = -EACCES;
-	if (!inode_owner_or_capable(inode))
-		goto out;
+		return error;
 
 	error = 0;
 	flags = ip->i_diskflags;
@@ -252,9 +238,6 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask,
 		goto out;
 	if (IS_APPEND(inode) && (new_flags & GFS2_DIF_APPENDONLY))
 		goto out;
-	if (((new_flags ^ flags) & GFS2_DIF_IMMUTABLE) &&
-	    !capable(CAP_LINUX_IMMUTABLE))
-		goto out;
 	if (!IS_IMMUTABLE(inode)) {
 		error = gfs2_permission(inode, MAY_WRITE);
 		if (error)
@@ -291,20 +274,18 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask,
 	gfs2_trans_end(sdp);
 out:
 	gfs2_glock_dq_uninit(&gh);
-out_drop_write:
-	mnt_drop_write_file(filp);
 	return error;
 }
 
-static int gfs2_set_flags(struct file *filp, u32 __user *ptr)
+int gfs2_miscattr_set(struct dentry *dentry, struct miscattr *ma)
 {
-	struct inode *inode = file_inode(filp);
-	u32 fsflags, gfsflags = 0;
+	struct inode *inode = d_inode(dentry);
+	u32 fsflags = ma->flags, gfsflags = 0;
 	u32 mask;
 	int i;
 
-	if (get_user(fsflags, ptr))
-		return -EFAULT;
+	if (miscattr_has_xattr(ma))
+		return -EOPNOTSUPP;
 
 	for (i = 0; i < ARRAY_SIZE(fsflag_gfs2flag); i++) {
 		if (fsflags & fsflag_gfs2flag[i].fsflag) {
@@ -325,7 +306,7 @@ static int gfs2_set_flags(struct file *filp, u32 __user *ptr)
 		mask &= ~(GFS2_DIF_TOPDIR | GFS2_DIF_INHERIT_JDATA);
 	}
 
-	return do_gfs2_set_flags(filp, gfsflags, mask, fsflags);
+	return do_gfs2_set_flags(inode, gfsflags, mask, fsflags);
 }
 
 static int gfs2_getlabel(struct file *filp, char __user *label)
@@ -342,10 +323,6 @@ static int gfs2_getlabel(struct file *filp, char __user *label)
 static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
 	switch(cmd) {
-	case FS_IOC_GETFLAGS:
-		return gfs2_get_flags(filp, (u32 __user *)arg);
-	case FS_IOC_SETFLAGS:
-		return gfs2_set_flags(filp, (u32 __user *)arg);
 	case FITRIM:
 		return gfs2_fitrim(filp, (void __user *)arg);
 	case FS_IOC_GETFSLABEL:
@@ -359,13 +336,6 @@ static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 static long gfs2_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
 	switch(cmd) {
-	/* These are just misnamed, they actually get/put from/to user an int */
-	case FS_IOC32_GETFLAGS:
-		cmd = FS_IOC_GETFLAGS;
-		break;
-	case FS_IOC32_SETFLAGS:
-		cmd = FS_IOC_SETFLAGS;
-		break;
 	/* Keep this list in sync with gfs2_ioctl */
 	case FITRIM:
 	case FS_IOC_GETFSLABEL:
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index c1b77e8d6b1c..243c3862d43b 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -2145,6 +2145,8 @@ static const struct inode_operations gfs2_file_iops = {
 	.get_acl = gfs2_get_acl,
 	.set_acl = gfs2_set_acl,
 	.update_time = gfs2_update_time,
+	.miscattr_get = gfs2_miscattr_get,
+	.miscattr_set = gfs2_miscattr_set,
 };
 
 static const struct inode_operations gfs2_dir_iops = {
@@ -2166,6 +2168,8 @@ static const struct inode_operations gfs2_dir_iops = {
 	.set_acl = gfs2_set_acl,
 	.update_time = gfs2_update_time,
 	.atomic_open = gfs2_atomic_open,
+	.miscattr_get = gfs2_miscattr_get,
+	.miscattr_set = gfs2_miscattr_set,
 };
 
 static const struct inode_operations gfs2_symlink_iops = {
diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h
index 8073b8d2c7fa..446fbeb97045 100644
--- a/fs/gfs2/inode.h
+++ b/fs/gfs2/inode.h
@@ -110,6 +110,8 @@ extern loff_t gfs2_seek_hole(struct file *file, loff_t offset);
 extern const struct file_operations gfs2_file_fops_nolock;
 extern const struct file_operations gfs2_dir_fops_nolock;
 
+extern int gfs2_miscattr_get(struct dentry *dentry, struct miscattr *ma);
+extern int gfs2_miscattr_set(struct dentry *dentry, struct miscattr *ma);
 extern void gfs2_set_inode_flags(struct inode *inode);
  
 #ifdef CONFIG_GFS2_FS_LOCKING_DLM
-- 
2.26.2


  parent reply	other threads:[~2021-02-03 12:58 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-03 12:40 [PATCH 00/18] new API for FS_IOC_[GS]ETFLAGS/FS_IOC_FS[GS]ETXATTR Miklos Szeredi
2021-02-03 12:40 ` [PATCH 01/18] vfs: add miscattr ops Miklos Szeredi
2021-02-03 15:04   ` Jan Kara
2021-02-03 15:21     ` Miklos Szeredi
2021-03-23  0:23   ` Eric Biggers
2021-03-25 14:52     ` Miklos Szeredi
2021-03-25 15:17       ` Al Viro
2021-02-03 12:40 ` [PATCH 02/18] ecryptfs: stack " Miklos Szeredi
2021-02-03 12:40 ` [PATCH 03/18] ovl: stack miscattr Miklos Szeredi
2021-02-04 23:42   ` Vivek Goyal
2021-02-05 15:25     ` Miklos Szeredi
2021-02-05 15:28       ` Miklos Szeredi
2021-02-03 12:40 ` [PATCH 04/18] btrfs: convert to miscattr Miklos Szeredi
2021-02-03 12:40 ` [PATCH 05/18] ext2: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 06/18] ext4: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 07/18] f2fs: " Miklos Szeredi
2021-03-23  0:28   ` Eric Biggers
2021-02-03 12:41 ` Miklos Szeredi [this message]
2021-02-03 12:41 ` [PATCH 09/18] orangefs: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 10/18] xfs: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 11/18] efivars: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 12/18] hfsplus: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 13/18] jfs: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 14/18] nilfs2: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 15/18] ocfs2: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 16/18] reiserfs: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 17/18] ubifs: " Miklos Szeredi
2021-02-03 12:41 ` [PATCH 18/18] vfs: remove unused ioctl helpers Miklos Szeredi
2021-02-03 13:05 ` [PATCH 00/18] new API for FS_IOC_[GS]ETFLAGS/FS_IOC_FS[GS]ETXATTR Matthew Wilcox
2021-02-03 13:13   ` Miklos Szeredi
2021-02-03 13:58     ` Matthew Wilcox
2021-02-03 14:13       ` Miklos Szeredi
2021-02-03 14:28         ` Matthew Wilcox
2021-02-03 14:38           ` Miklos Szeredi
2021-02-03 14:56             ` Matthew Wilcox
2021-02-03 15:03               ` Miklos Szeredi
2021-02-08  2:00                 ` Dave Chinner
2021-02-08  8:25                   ` Miklos Szeredi
2021-02-08 14:02                     ` Matthew Wilcox
2021-02-08 14:52                       ` Miklos Szeredi

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=20210203124112.1182614-9-mszeredi@redhat.com \
    --to=mszeredi@redhat.com \
    --cc=agruenba@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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).