Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Lauri Gates <lauri.gates@gmail.com>
To: 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: Sun, 29 Nov 2026 15:10:24 +0200	[thread overview]
Message-ID: <20261129131024.92875-1-lauri.gates@gmail.com> (raw)
In-Reply-To: <20261129024233.2361718-3-koray.fra@gmail.com>

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.

[1] https://lore.kernel.org/linux-xfs/20261102193533.93690-1-lauri.gates@gmail.com/

Lauri

  reply	other threads:[~2026-11-29 13:10 UTC|newest]

Thread overview: 14+ 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 [this message]
2026-11-29 13:57     ` 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  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  2:42 ` [PATCH v3 5/5] docs: add fileattr API documentation koraynilay
2026-11-29 11:32   ` 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=20261129131024.92875-1-lauri.gates@gmail.com \
    --to=lauri.gates@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=koray.fra@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