From: Christian Brauner <brauner@kernel.org>
To: Theodore Ts'o <tytso@mit.edu>, Jan Kara <jack@suse.cz>,
linux-ext4@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org,
"Christian Brauner (Amutable)" <brauner@kernel.org>
Subject: [PATCH 3/4] ext4: split the flag checks out of ext4_ioctl_setflags()
Date: Mon, 30 Nov 2026 14:22:15 +0100 [thread overview]
Message-ID: <20261130-work-ext4-setflags_migrate-v1-3-80f1875cfadc@kernel.org> (raw)
In-Reply-To: <20261130-work-ext4-setflags_migrate-v1-0-80f1875cfadc@kernel.org>
Move the checks that refuse a flags change into
ext4_ioctl_check_setflags() and call it from ext4_fileattr_set() before
ext4_ioctl_setflags(). The next patch needs them to run before the
project ID is changed. No functional changes.
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
fs/ext4/ioctl.c | 62 ++++++++++++++++++++++++++++-----------------------------
1 file changed, 31 insertions(+), 31 deletions(-)
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index a541f67c274e9..d341e5dbda108 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -587,61 +587,58 @@ static bool dax_compatible(struct inode *inode, unsigned int oldflags,
return true;
}
-static int ext4_ioctl_setflags(struct inode *inode,
- unsigned int flags)
+static int ext4_ioctl_check_setflags(struct inode *inode, unsigned int flags)
{
- struct ext4_inode_info *ei = EXT4_I(inode);
- handle_t *handle = NULL;
- int err = -EPERM, rc, alloc_ctx = 0;
- struct ext4_iloc iloc;
- unsigned int oldflags, mask, i;
+ unsigned int oldflags = EXT4_I(inode)->i_flags;
struct super_block *sb = inode->i_sb;
- bool others, to_ind = false;
/* Is it quota file? Do not allow user to mess with it */
if (ext4_is_quota_file(inode))
- goto flags_out;
+ return -EPERM;
- oldflags = ei->i_flags;
/*
* The JOURNAL_DATA flag can only be changed by
* the relevant capability.
*/
if ((flags ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) {
if (!capable(CAP_SYS_RESOURCE))
- goto flags_out;
+ return -EPERM;
}
- if (!dax_compatible(inode, oldflags, flags)) {
- err = -EOPNOTSUPP;
- goto flags_out;
- }
+ if (!dax_compatible(inode, oldflags, flags))
+ return -EOPNOTSUPP;
if ((flags ^ oldflags) & EXT4_CASEFOLD_FL) {
- if (!ext4_has_feature_casefold(sb)) {
- err = -EOPNOTSUPP;
- goto flags_out;
- }
+ if (!ext4_has_feature_casefold(sb))
+ return -EOPNOTSUPP;
- if (!S_ISDIR(inode->i_mode)) {
- err = -ENOTDIR;
- goto flags_out;
- }
+ if (!S_ISDIR(inode->i_mode))
+ return -ENOTDIR;
- if (!ext4_empty_dir(inode)) {
- err = -ENOTEMPTY;
- goto flags_out;
- }
+ if (!ext4_empty_dir(inode))
+ return -ENOTEMPTY;
}
/*
* Changes to the journaling mode can cause unsafe changes to
* S_DAX if the inode is DAX
*/
- if (((flags ^ oldflags) & EXT4_JOURNAL_DATA_FL) && IS_DAX(inode)) {
- err = -EBUSY;
- goto flags_out;
- }
+ if (((flags ^ oldflags) & EXT4_JOURNAL_DATA_FL) && IS_DAX(inode))
+ return -EBUSY;
+
+ return 0;
+}
+
+static int ext4_ioctl_setflags(struct inode *inode,
+ unsigned int flags)
+{
+ struct ext4_inode_info *ei = EXT4_I(inode);
+ handle_t *handle = NULL;
+ int err, rc, alloc_ctx = 0;
+ struct ext4_iloc iloc;
+ unsigned int oldflags = ei->i_flags, mask, i;
+ struct super_block *sb = inode->i_sb;
+ bool others, to_ind = false;
/*
* Callers that don't start from GETFLAGS leave the extent flag out, so
@@ -1058,6 +1055,9 @@ int ext4_fileattr_set(const struct mnt_idmap *idmap,
if (ext4_mask_flags(inode->i_mode, flags) != flags)
goto out;
err = ext4_ioctl_check_immutable(inode, fa->fsx_projid, flags);
+ if (err)
+ goto out;
+ err = ext4_ioctl_check_setflags(inode, flags);
if (err)
goto out;
err = ext4_ioctl_setflags(inode, flags);
--
2.53.0
next prev parent reply other threads:[~2026-11-30 13:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 13:22 [PATCH 0/4] ext4: don't fail FS_IOC_{SETFLAGS,FSSETXATTR} after applying them aka things that fell out of my uapi16 library work Christian Brauner
2026-11-30 13:22 ` [PATCH 1/4] ext4: don't lose the result of ext4_ext_migrate() Christian Brauner
2026-11-30 16:40 ` Jan Kara
2026-11-30 13:22 ` [PATCH 2/4] ext4: don't fail FS_IOC_SETFLAGS after applying it Christian Brauner
2026-11-30 16:48 ` Jan Kara
2026-11-30 13:22 ` Christian Brauner [this message]
2026-11-30 16:49 ` [PATCH 3/4] ext4: split the flag checks out of ext4_ioctl_setflags() Jan Kara
2026-11-30 13:22 ` [PATCH 4/4] ext4: don't fail FS_IOC_FSSETXATTR after applying it Christian Brauner
2026-11-30 16:58 ` Jan Kara
2026-11-30 13:39 ` [PATCH 0/4] ext4: don't fail FS_IOC_{SETFLAGS,FSSETXATTR} after applying them aka things that fell out of my uapi16 library work sashiko-bot
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=20261130-work-ext4-setflags_migrate-v1-3-80f1875cfadc@kernel.org \
--to=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.