Re: [PATCH 2/3] vfs: add xflags mask to fileattr API
From: koraynilay
Date: Thu Nov 26 2026 - 04:47:49 EST
On Thu Nov 26, 2026 at 10:23 AM CET, Amir Goldstein wrote:
> On Thu, Nov 26, 2026 at 9:59 AM koraynilay <koray.fra@xxxxxxxxx> wrote:
>>
> ...
>> >> > Attributes that have X_value like fsx_projid have few types:
>> >> > 1. 0 means disabled (all existing values incl. projid)
>> >> > 2. 0 is a valid value but cannot be unset (btime)
>> >> > 3. 0 is a valid value and NULL/unset is also a valid value
>> >> >
>> >> > Only for type 3 does can the interpretation of
>> >> > (!XFLAG_X && !fsx_X) be considered as an "unset"
>> >> > and anyway, this will require support in individual fs.
>> >>
>> >> IMO !(xflags & XFLAG) && (rw_mask & XFLAG) should clear/unset the value
>> >> in all cases, ignoring what's in fsx_X.
>> >>
>> >> And all existing values would be of type 1 for VER0, but of type 1 + 3
>> >> for VER1.
>> >>
>> >
>> > I agree that this will be more consistent.
>> >
>> > With explicit opt-in to FILEATTR_MASKS API
>> > vfs can determine that
>> > (!XFLAG_X && !!fsx_X) is alway -EINVAL
>> >
>> > When fsx_X == 0, the value of XFLAG_X does not really matter
>> > so filesystems can decide themselves if they want to act on
>> > an "unset" flag or not.
>>
>> Hmm, I think fsx_xflags should have priority over the value in this
>> _masks API.
>>
>> In my mind, to clear PROJID a userspace program would only need to do:
>>
>> struct file_attr fa = {
>> .fsx_xflags = 0,
>> .fsx_xflags_rw_mask = FS_XFLAG_PROJID
>> };
>> file_setattr(&fa, AT_FILE_ATTR_MASKS);
>
> If the program (e.g. chattr -p) internationally sets rw_mask = FS_XFLAG_PROJID
> what do we gain from not requiring the program to also set fsx_projid = 0?
> I just don't see any wins for anyone from this design choice.
>
> Maybe I am missing something.
I don't think we gain something, but I think it wouldn't make sense
semantically to require it.
At least personally, I wouldn't expect to be required to also 0 the
value if I'm already saying "I want to change PROJID and I want to unset
it" (rw mask = PROJID, xflags = 0).
Also for maybe future attributes belonging to type 3, the value should
be ignored when unsetting, since there would be no "invalid value" like
0 for projid.
>>
>> and have projid cleared (same for EXTSIZE/EXTSZINHERIT/COWEXTESIZE),
>> while to set/change it:
>>
>> struct file_attr fa = {
>> .fsx_xflags = FS_XFLAG_PROJID,
>> .fsx_xflags_rw_mask = FS_XFLAG_PROJID,
>> .fsx_projid = 67,
>> };
>> file_setattr(&fa, AT_FILE_ATTR_MASKS);
>>
>> and this:
>>
>> struct file_attr fa = {
>> .fsx_xflags = FS_XFLAG_PROJID,
>> .fsx_xflags_rw_mask = FS_XFLAG_PROJID,
>> .fsx_projid = 0,
>> };
>> file_setattr(&fa, AT_FILE_ATTR_MASKS);
>>
>> would have the same result as the first snippet, but not the same
>> meaning, since this would mean "set projid to 0" while the first snippet
>> means "clear/unset projid" (but in this case, for projid and all the
>> other already existing fsx_* it would have the same result).
>>
>
> As I wrote it could matter per attribute and per filesystem
> whether set to 0 or unset is different.
Yes, then filesystems could handle them however they want, maybe even
use the fsx_* value (if it's not 0) in the reset case above.
> The man page language should be flexible enough about this point.
>
> It only needs to document the invalid combinations.
>
> When proposing an UAPI change I often included a man-page draft
> as a proof that the UAPI can make sense to human readers.
Yes, I think I'll write the explanation in the cover letter to have the
ideas written down, then I can add man-pages and docs in v3.
Thanks,
koraynilay
> Thanks,
> Amir.
Attachment:
signature.asc
Description: PGP signature