Linux Overlay Filesystem development
 help / color / mirror / Atom feed
From: "koraynilay" <koray.fra@gmail.com>
To: "Lauri Gates" <lauri.gates@gmail.com>,
	"koraynilay" <koray.fra@gmail.com>
Cc: "Namjae Jeon" <linkinjeon@kernel.org>,
	"Hyunchul Lee" <hyc.lee@gmail.com>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Eric Biggers" <ebiggers@kernel.org>,
	"Theodore Y . Ts'o" <tytso@mit.edu>,
	"Jaegeuk Kim" <jaegeuk@kernel.org>,
	"Alexander Viro" <viro@zeniv.linux.org.uk>,
	"Christian Brauner" <brauner@kernel.org>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Chuck Lever" <cel@kernel.org>,
	"Jeff Layton" <jlayton@kernel.org>, "Jan Kara" <jack@suse.cz>,
	"Alexander Aring" <alex.aring@gmail.com>,
	"Darrick J . Wong" <djwong@kernel.org>,
	"Andrey Albershteyn" <aalbersh@kernel.org>,
	"Amir Goldstein" <amir73il@gmail.com>,
	"Miklos Szeredi" <miklos@szeredi.hu>,
	"Pali Rohár" <pali@kernel.org>,
	"Christoph Hellwig" <hch@infradead.org>,
	"Dave Chinner" <dgc@kernel.org>,
	linux-btrfs@vger.kernel.org, linux-xfs@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	ntfs@lists.linux.dev, linux-nfs@vger.kernel.org,
	linux-api@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-unionfs@vger.kernel.org
Subject: Re: [PATCH v3 2/5] vfs: add xflags masks to fileattr API
Date: Mon, 30 Nov 2026 19:43:54 +0100	[thread overview]
Message-ID: <DN8RMUP6F5CI.2KSDF5TMCRO1X@gmail.com> (raw)
In-Reply-To: <20261129131024.92875-1-lauri.gates@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 7631 bytes --]

On Sun Nov 29, 2026 at 2:10 PM CET, Lauri Gates wrote:
> On Sun, Nov 29, 2026 at 03:42:30AM +0100, koraynilay wrote:
>> +	if (fa->flags_valid) {
>> +		/*
>> +		 * Assume that if the filesystem supports masks it supports its
>> +		 * writable FS_*_FL flags via FS_XFLAG_* and fsx_xflags_rw_mask.
>> +		 */
>> +		changed = fa->flags ^ old_ma->flags;
>> +		if (changed & ~xflags_to_flags(old_ma->fsx_xflags_rw_mask))
>> +			return -EOPNOTSUPP;
>
> I would like to ask for a change here before v4: let FS_IOC_SETFLAGS
> keep working for flags that the rw mask cannot express, instead of
> failing with EOPNOTSUPP. A sketch and the reason follow; would you take
> something like it?
>
> I ran into this assumption while putting the may-share flag from the
> FIEMAP thread [1] on top of v3, in a series I have not posted yet. The
> flag is read-only, so it is reported through fa_xflags_ro_mask, which
> the VFS fills only when the filesystem sets has_masks. My series
> therefore sets has_masks for ocfs2 as well as xfs. On ocfs2 that broke
> FS_IOC_SETFLAGS for six flags it accepts today. Five have no FS_XFLAG_*
> counterpart: SECRM, UNRM and NOTAIL on files, DIRSYNC and TOPDIR on
> directories. The sixth is COMPR, whose xflag from 3/5 is read-only, so
> it can never be in fsx_xflags_rw_mask. Each set failed with EOPNOTSUPP
> (QEMU, v7.4-rc1 plus v3 1-3 and my series); without my series all six
> work.
>
> ocfs2 is only the first case. Of the filesystems in v3 only ntfs sets
> has_masks, but ext4 (DIRSYNC, TOPDIR, JOURNAL_DATA, EXTENTS) and btrfs
> (DIRSYNC, NOCOW) have the same kind of flags, so neither could set it
> without losing chattr for them. COMPR on btrfs is the case Amir asked to
> footnote in 5/5 as "RW only via SETFLAGS": with masks, chattr +c would
> fail the same way, and the footnote would no longer be true. With the
> fallback below it stays true. FS_IOC_FSSETXATTR is not affected, since
> it has never been able to set these flags.
>
> The sketch, against v3 2/5: when an FS_IOC_SETFLAGS call changes a flag
> that the rw mask cannot express, give the filesystem the full
> read-modify-write request it got before masks. The check quoted above
> can then never fire, so the sketch removes it:
>
> --- a/fs/file_attr.c
> +++ b/fs/file_attr.c
> @@ static int fileattr_set_rmw_to_mask(struct file_kattr *fa,
>  	if (fa->flags_valid) {
> -		/*
> -		 * Assume that if the filesystem supports masks it supports its
> -		 * writable FS_*_FL flags via FS_XFLAG_* and fsx_xflags_rw_mask.
> -		 */
> -		changed = fa->flags ^ old_ma->flags;
> -		if (changed & ~xflags_to_flags(old_ma->fsx_xflags_rw_mask))
> -			return -EOPNOTSUPP;
> -
> -		changed = flags_to_xflags(changed);
> +		changed = flags_to_xflags(fa->flags ^ old_ma->flags);
>  	} else { /* if (fa->fsx_valid) */
> @@ static int fileattr_set_convert(struct file_kattr *fa,
> -	if (old_ma->has_masks)
> +	/*
> +	 * A masked request names only flags with an FS_XFLAG_* counterpart.
> +	 * FS_IOC_SETFLAGS changing any other flag (e.g. FS_DIRSYNC_FL) gets
> +	 * the full request below, which the filesystem handled before masks.
> +	 */
> +	if (old_ma->has_masks &&
> +	    !(fa->flags_valid && ((fa->flags ^ old_ma->flags) &
> +				  ~xflags_to_flags(old_ma->fsx_xflags_rw_mask))))
>  		return fileattr_set_rmw_to_mask(fa, old_ma);
>
> With it, all six ocfs2 flags set and clear again, and nothing else in my
> xfs, ocfs2 and overlayfs checks changes. The cost is in the contract: a
> filesystem that sets has_masks must still accept a full, unmasked
> request from FS_IOC_SETFLAGS. Every ->fileattr_set() does today, because
> has_masks on set is new in this series, but the documentation in 5/5
> would need to say so. The other way I can see is to keep the masked
> request and pass the unmapped FS_*_FL changes beside it, which needs a
> second mask. That seems like more API than the case needs, so I would go
> with the fallback.

Hi, can you try with this diff and setting both get_only_masks and
has_masks to true in ocfs2's code?

(to set only get_only_masks and leave has_masks as false, we'd need to
also add || fa->get_only_masks in the clamping of vfs_fileattr_get and
mask population in fileattr_to_file_attr, which I think wouldn't be as
clean)

Thanks,
koraynilay

(WIP, it will be cleaned up for v4)

diff --git a/fs/file_attr.c b/fs/file_attr.c
index 2b3fe36bbab9..a6f6d59eb649 100644
--- a/fs/file_attr.c
+++ b/fs/file_attr.c
@@ -185,7 +185,7 @@ static int file_attr_to_fileattr(const struct file_attr *fattr,
 	if (fattr->fa_xflags & ~mask)
 		return -EINVAL;
 
-	if (fa->has_masks) {
+	if (fa->use_masks && fa->has_masks) {
 		u64 rw_user_mask = fattr->fa_xflags_rw_mask;
 
 		if (rw_user_mask & ~FS_FILE_ATTR_XFLAGS_MASK)
@@ -301,6 +301,7 @@ static int fileattr_set_rmw_to_mask(struct file_kattr *fa,
 	fa->fsx_xflags = new_xflags;
 	fa->fsx_xflags_rw_mask = new_rw_mask;
 	fa->has_masks = true;
+	fa->use_masks = true;
 
 	fa->fsx_valid = true;
 	fa->flags_valid = false;
@@ -374,6 +375,7 @@ static int fileattr_set_mask_to_rmw(struct file_kattr *fa,
 	fa->fsx_xflags = new_xflags;
 	fa->fsx_xflags_rw_mask = 0;
 	fa->has_masks = false;
+	fa->use_masks = false;
 
 	fa->fsx_valid = true;
 	fa->flags_valid = false;
@@ -389,15 +391,17 @@ static int fileattr_set_mask_to_rmw(struct file_kattr *fa,
 static int fileattr_set_convert(struct file_kattr *fa,
 				const struct file_kattr *old_ma)
 {
+	bool fs_has_masks = old_ma->has_masks && !old_ma->get_only_masks;
+
 	if (fa->has_masks) {
-		if (!old_ma->has_masks)
+		if (!fs_has_masks)
 			return fileattr_set_mask_to_rmw(fa, old_ma);
 
 		/* Both have masks, pass the request through. */
 		return 0;
 	}
 
-	if (old_ma->has_masks)
+	if (fs_has_masks)
 		return fileattr_set_rmw_to_mask(fa, old_ma);
 
 	fa->fsx_xflags_rw_mask = 0;
@@ -543,6 +547,16 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
 	if (!inode_owner_or_capable(idmap, inode))
 		return -EPERM;
 
+	if (fa->use_masks && !fa->has_masks)
+		return -EINVAL;
+
+	/* This comes from an older call or caller wanted VER0 RMW semantics */
+	if (!fa->use_masks)
+		fa->has_masks = false;
+
+	// also try this, it should be the same as above but less readable
+	//fa->has_masks = fa->use_masks;
+
 	if (fa->has_masks && !fa->fsx_xflags_rw_mask)
 		return -EINVAL;
 
@@ -754,8 +768,10 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename,
 			return error;
 	}
 
-	if (at_flags & AT_FILEATTR_MASKS)
+	if (at_flags & AT_FILEATTR_MASKS) {
 		fa.has_masks = true;
+		fa.use_masks = true;
+	}
 
 	error = file_attr_to_fileattr(&fattr, &fa);
 	if (error)
diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
index ad77febe8c76..59353a5240f6 100644
--- a/include/linux/fileattr.h
+++ b/include/linux/fileattr.h
@@ -64,7 +64,15 @@ struct file_kattr {
 	/* selectors: */
 	bool	flags_valid:1;
 	bool	fsx_valid:1;
-	bool	has_masks:1;
+	bool	has_masks:1;	/* struct has valid masks */
+	bool	use_masks:1;	/* equivalent to AT_FILEATTR_MASKS but for
+				   in-kernel calls (set, only in) */
+	bool	get_only_masks:1;/* Transitional. Filesystem doesn't actually
+				    support masks yet, but wants to support
+				    read-only / get-only xflags like
+				    MAYSHAREEXTENT or BTIME */
+				/* Transitional: filesystem doesn't support rw_mask for set,
+				   but supports ro_mask on get */
 };
 
 int copy_fsxattr_to_user(const struct file_kattr *fa, struct fsxattr __user *ufa);

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  parent reply	other threads:[~2026-11-30 18:44 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  2:42 [PATCH v3 0/5] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay
2026-11-29  2:42 ` [PATCH v3 1/5] vfs: use goto out on error in vfs_fileattr_set() koraynilay
2026-11-29  9:32   ` Amir Goldstein
2026-11-29 13:23     ` koraynilay
2026-11-29  2:42 ` [PATCH v3 2/5] vfs: add xflags masks to fileattr API koraynilay
2026-11-29 13:10   ` Lauri Gates
2026-11-29 13:57     ` Amir Goldstein
2026-11-30 18:43     ` koraynilay [this message]
2026-11-30 19:44       ` Lauri Gates
2026-11-29 14:23   ` Amir Goldstein
2026-11-29 21:44     ` koraynilay
2026-11-29 22:22       ` koraynilay
2026-11-30  0:00       ` Amir Goldstein
2026-11-30 11:23         ` koraynilay
2026-11-30 11:28           ` koraynilay
2026-11-30 15:53             ` Amir Goldstein
2026-11-30 17:22               ` koraynilay
2026-11-30 21:04                 ` Amir Goldstein
2026-11-29  2:42 ` [PATCH v3 3/5] vfs: add COMPR/ENCRYPT xflags from FS_COMPR_FL/FS_ENCRYPT_FL koraynilay
2026-11-29 10:11   ` Amir Goldstein
2026-11-29 18:20     ` koraynilay
2026-11-29 21:30       ` Amir Goldstein
2026-11-29 21:55         ` koraynilay
2026-11-29  2:42 ` [PATCH v3 4/5] ntfs: switch to the new xflags fileattr API koraynilay
2026-11-29  9:12   ` Amir Goldstein
2026-11-29 17:51     ` koraynilay
2026-11-29 21:18       ` Amir Goldstein
2026-11-29 22:05         ` koraynilay
2026-11-29 22:20           ` Amir Goldstein
2026-11-29  2:42 ` [PATCH v3 5/5] docs: add fileattr API documentation koraynilay
2026-11-29 11:32   ` Amir Goldstein
2026-11-29 14:19     ` koraynilay
2026-11-29 22:11       ` Amir Goldstein
2026-11-30 13:33   ` Andrey Albershteyn
2026-11-30 14:10     ` koraynilay
2026-11-30 15:24       ` Amir Goldstein
2026-11-29  2:47 ` [PATCH v3 0/5] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay

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=DN8RMUP6F5CI.2KSDF5TMCRO1X@gmail.com \
    --to=koray.fra@gmail.com \
    --cc=aalbersh@kernel.org \
    --cc=alex.aring@gmail.com \
    --cc=amir73il@gmail.com \
    --cc=brauner@kernel.org \
    --cc=cel@kernel.org \
    --cc=corbet@lwn.net \
    --cc=dgc@kernel.org \
    --cc=djwong@kernel.org \
    --cc=ebiggers@kernel.org \
    --cc=hch@infradead.org \
    --cc=hyc.lee@gmail.com \
    --cc=jack@suse.cz \
    --cc=jaegeuk@kernel.org \
    --cc=jlayton@kernel.org \
    --cc=lauri.gates@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=ntfs@lists.linux.dev \
    --cc=pali@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=skhan@linuxfoundation.org \
    --cc=tytso@mit.edu \
    --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