Re: [PATCH v3 2/5] vfs: add xflags masks to fileattr API
From: Amir Goldstein
Date: Sun Nov 29 2026 - 08:57:32 EST
On Sun, Nov 29, 2026 at 2:10 PM Lauri Gates <lauri.gates@xxxxxxxxx> 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.
I didn't look at the sketch, but I agree with the request, it makes a lot
of sense and for the context of FS_XFLAG_BTIME, it will also allow simpler
conversion for all the filesystems that only want to advertise read-only btime.
w.r.t describing capabilities, we need at least three different properties
instead of the single has_masks:
- filesystem can report masks in get
- filesystem can accept masks in set
- caller has specified masks (AT_FILEATTR_MASKS)
The single has_masks in v3 is probably the root cause of most of the
reported v3 overlayfs bugs.
With those properties, I think it is simpler than your sketch:
ocfs2 can advertise read-only flags in get without accepting masks
in set, so its legacy requests are passed as is.
The long term goal is for all fs methods to be converted to deal only
with the canonical masked format, so they don't need to carry legacy
code and all conversions will be done in the vfs. A fs should accept
masks in set only when all its writable flags can be expressed with xflags,
which may require adding new xflags first (e.g. DIRSYNC).
Thanks,
Amir.