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);