Linux userland API discussions
 help / color / mirror / Atom feed
From: "koraynilay" <koray.fra@gmail.com>
To: "Amir Goldstein" <amir73il@gmail.com>,
	"koraynilay" <koray.fra@gmail.com>
Cc: "David Sterba" <dsterba@suse.com>,
	"Namjae Jeon" <linkinjeon@kernel.org>,
	"Sungjong Seo" <sj1557.seo@samsung.com>,
	"Alexander Viro" <viro@zeniv.linux.org.uk>,
	"Christian Brauner" <brauner@kernel.org>,
	"Trond Myklebust" <trondmy@kernel.org>,
	"Anna Schumaker" <anna@kernel.org>,
	"Chuck Lever" <cel@kernel.org>,
	"Jeff Layton" <jlayton@kernel.org>,
	"Konstantin Komarov" <almaz.alexandrovich@paragon-software.com>,
	"Paulo Alcantara" <pc@manguebit.org>,
	"Chris Mason" <mason@kernel.org>,
	"Yuezhang Mo" <yuezhang.mo@sony.com>, "Jan Kara" <jack@suse.cz>,
	NeilBrown <neil@brown.name>,
	"Olga Kornievskaia" <okorniev@redhat.com>,
	"Dai Ngo" <Dai.Ngo@oracle.com>, "Tom Talpey" <tom@talpey.com>,
	"Ronnie Sahlberg" <ronniesahlberg@gmail.com>,
	"Shyam Prasad N" <sprasad@microsoft.com>,
	"Bharath SM" <bharathsm@microsoft.com>,
	"Sergey Senozhatsky" <senozhatsky@chromium.org>,
	ChenXiaoSong <chenxiaosong@chenxiaosong.com>,
	"Darrick J . Wong" <djwong@kernel.org>,
	"Sean Smith" <defendthedisabled@gmail.com>,
	"Andrey Albershteyn" <aalbersh@kernel.org>,
	"Pedro Falcato" <pfalcato@suse.de>,
	"Pali Rohár" <pali@kernel.org>,
	linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, exfat@lists.linux.dev,
	ntfs3@lists.linux.dev, linux-cifs@vger.kernel.org,
	linux-nfs@vger.kernel.org, linux-api@vger.kernel.org
Subject: Re: [RFC PATCH v4 01/10] vfs: add provenance time (ptime)
Date: Mon, 16 Nov 2026 21:53:49 +0100	[thread overview]
Message-ID: <DMWXMP61YXEH.1W32ZFF7A7Y5H@gmail.com> (raw)
In-Reply-To: <CAOQ4uxi+50NU8qzg+Owvr8gFZ4vYF5FqWg4Hr9vB6ONUpPsFwg@mail.gmail.com>

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

On Mon Nov 16, 2026 at 9:10 PM CET, Amir Goldstein wrote:
> On Sun, Nov 15, 2026 at 7:04 PM koraynilay <koray.fra@gmail.com> wrote:
>>
>> Add provenance time (ptime), indicating the time when a file or
>> directory was created. This is user-settable via file_setattr() and
>> retrievable via statx(2) (using STATX_PTIME) or file_getattr().
>>
>> The semantics of when to preserve this new timestamp are the same as
>> mtime, the idea being that there is a correspondence like this:
>>
>> ctime <-> btime
>> mtime <-> ptime
>>
>> so every operation (copying, moving, ...) that currently preserves mtime
>> should also preserve ptime.
>>
>> Also add fa_xflags_mask to struct file_attr (and equivalent
>
> That is a very big "Also" part
> This is a significant UAPI change that needs to be delivered and
> explained with a patch on its own.

Right, that definitely makes more sense, I didn't think of that lol.

>> fsx_xflags_mask to struct file_kattr) to let the filesystems advertise
>> their support for specific xflags and users advertise what they want to
>> change, behaving like statx.stx_attributes_mask:
>> - on GET (file_getattr): each filesystem fills the mask according to
>>   their supported xflags, e.g. FS_XFLAG_PTIME or FS_XFLAG_COWEXTSIZE,
>>   and provides the values in the corresponding struct fields;
>> - on SET (file_setattr): userspace fills the mask according to which
>>   xflags it wants to change, VFS validates this and preserves xflags
>>   that were not specified in the mask;
>> - if xflags_mask == 0, use legacy full-struct replacement to keep
>>   compatibility with older programs.
>>
>> Furthermore, in order to avoid the legacy FS_IOC_FSSETXATTR accepting
>> FS_XFLAG_PTIME, add an FS_FILE_ATTR_XFLAGS_MASK mask to support new
>> xflags and use it in fileattr_to_file_attr()/file_attr_to_fileattr() to
>> validate that the xflags passed in xflags and xflags_mask fields are
>> valid.
>>
>> Finally, add the missing FS_XFLAG_PROJID flag, to allow userspace to set
>> the projid using file_[sg]etattr().
>
> This part also belongs with the xflags_mask patch

Ok.

>>
>> [ This is a re-implementation of the initial patch[1] by Sean Smith
>>   <defendthedisabled@gmail.com>, following the advice[2] from Darrick J.
>>   Wong <djwong@kernel.org> of using file_setattr() instead of updating
>>   utimensat() ]
>>
>> [1]: https://lore.kernel.org/20260405195007.1306-2-DefendTheDisabled@gmail.com
>> [2]: https://lore.kernel.org/20260407014129.GC6192@frogsfrogsfrogs
>>
>> Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.4.7
>> Signed-off-by: koraynilay <koray.fra@gmail.com>
>> ---
>>  fs/file_attr.c            | 75 +++++++++++++++++++++++++++++++++++++--
>>  fs/stat.c                 |  2 ++
>>  include/linux/fileattr.h  |  6 ++++
>>  include/linux/stat.h      |  1 +
>>  include/uapi/linux/fs.h   |  9 ++++-
>>  include/uapi/linux/stat.h |  7 +++-
>>  6 files changed, 95 insertions(+), 5 deletions(-)
>>
>> diff --git a/fs/file_attr.c b/fs/file_attr.c
>> index 833e03810b24..12610fb6a751 100644
>> --- a/fs/file_attr.c
>> +++ b/fs/file_attr.c
>> @@ -102,14 +102,23 @@ EXPORT_SYMBOL(vfs_fileattr_get);
>>  static void fileattr_to_file_attr(const struct file_kattr *fa,
>>                                   struct file_attr *fattr)
>>  {
>> -       __u32 mask = FS_XFLAGS_MASK;
>> +       /*
>> +        * fsx_xflags_mask contains only flags added after the
>> +        * file_[gs]etattr() API, so we need to tell userspace the filesystem
>> +        * actually supports all legacy and new advertised flags
>> +        */
>> +       __u32 mask = (FS_XFLAGS_MASK | fa->fsx_xflags_mask) &
>> +                    FS_FILE_ATTR_XFLAGS_MASK;
>>
>>         memset(fattr, 0, sizeof(struct file_attr));
>>         fattr->fa_xflags = fa->fsx_xflags & mask;
>> +       fattr->fa_xflags_mask = mask;
>>         fattr->fa_extsize = fa->fsx_extsize;
>>         fattr->fa_nextents = fa->fsx_nextents;
>>         fattr->fa_projid = fa->fsx_projid;
>>         fattr->fa_cowextsize = fa->fsx_cowextsize;
>> +       fattr->fa_ptime_sec = fa->fsx_ptime.tv_sec;
>> +       fattr->fa_ptime_nsec = fa->fsx_ptime.tv_nsec;
>>  }
>>
>>  /**
>> @@ -141,15 +150,23 @@ EXPORT_SYMBOL(copy_fsxattr_to_user);
>>  static int file_attr_to_fileattr(const struct file_attr *fattr,
>>                                  struct file_kattr *fa)
>>  {
>> -       __u64 mask = FS_XFLAGS_MASK;
>> +       __u64 mask = fattr->fa_xflags_mask ?: FS_XFLAGS_MASK;
>> +
>> +       if (fattr->fa_xflags_mask & ~FS_FILE_ATTR_XFLAGS_MASK)
>> +               return -EINVAL;
>>
>>         if (fattr->fa_xflags & ~mask)
>>                 return -EINVAL;
>>
>>         fileattr_fill_xflags(fa, fattr->fa_xflags & ~FS_XFLAG_RDONLY_MASK);
>> +       fa->fsx_xflags_mask = fattr->fa_xflags_mask;
>>         fa->fsx_extsize = fattr->fa_extsize;
>>         fa->fsx_projid = fattr->fa_projid;
>>         fa->fsx_cowextsize = fattr->fa_cowextsize;
>> +       if (fattr->fa_xflags_mask & FS_XFLAG_PTIME) {
>> +               fa->fsx_ptime.tv_sec = fattr->fa_ptime_sec;
>> +               fa->fsx_ptime.tv_nsec = fattr->fa_ptime_nsec;
>> +       }
>>
>>         return 0;
>>  }
>> @@ -232,6 +249,23 @@ static int fileattr_set_prepare(struct inode *inode,
>>             !S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode))
>>                 return -EINVAL;
>>
>> +       if (fa->fsx_xflags_mask & FS_XFLAG_PTIME) {
>> +               if (!(old_ma->fsx_xflags_mask & FS_XFLAG_PTIME))
>> +                       return -EOPNOTSUPP;
>> +
>> +               if (!(fa->fsx_xflags & FS_XFLAG_PTIME))
>> +                       return -EINVAL;
>> +
>> +               if ((unsigned long)fa->fsx_ptime.tv_nsec >= NSEC_PER_SEC)
>> +                       return -EINVAL;
>> +
>> +               fa->fsx_ptime = timestamp_truncate(fa->fsx_ptime, inode);
>> +
>> +               if (!timespec64_equal(&old_ma->fsx_ptime, &fa->fsx_ptime) &&
>> +                   (fa->flags & old_ma->flags) & (FS_APPEND_FL | FS_IMMUTABLE_FL))
>> +                       return -EPERM;
>
> I don't know what this is but it looks strange.

That's for preserv- ok nevermind it's probably not needed anymore
since adding fsx_xflags_mask. I'll check that too for v5.

>
>> +       }
>> +
>>         /*
>>          * It is only valid to set the DAX flag on regular files and
>>          * directories on filesystems.
>> @@ -288,13 +322,41 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
>>         if (!err) {
>>                 /* initialize missing bits from old_ma */
>>                 if (fa->flags_valid) {
>> -                       fa->fsx_xflags |= old_ma.fsx_xflags & ~FS_XFLAG_COMMON;
>> +                       /* FS_IOC_SETFLAGS */
>> +                       fa->fsx_xflags |= (old_ma.fsx_xflags & FS_XFLAGS_MASK) &
>> +                                         ~FS_XFLAG_COMMON;
>>                         fa->fsx_extsize = old_ma.fsx_extsize;
>>                         fa->fsx_nextents = old_ma.fsx_nextents;
>>                         fa->fsx_projid = old_ma.fsx_projid;
>>                         fa->fsx_cowextsize = old_ma.fsx_cowextsize;
>> +                       fa->fsx_ptime = old_ma.fsx_ptime;
>>                 } else {
>> +                       /*
>> +                        * Preserve unmasked xflags when running file_setattr()
>> +                        * with a mask, which doesn't need a read-modify-write
>> +                        * so these attributes would be set to 0.
>> +                        *
>> +                        * With FS_IOC_FSSETXATTR or mask == 0 (legacy mode)
>> +                        * this is not needed as userspace does
>> +                        * read-modify-write already.
>> +                        */
>> +                       if (fa->fsx_xflags_mask) {
>> +                               fa->fsx_xflags |= old_ma.fsx_xflags &
>> +                                                 ~fa->fsx_xflags_mask;
>> +                               fileattr_fill_xflags(fa, fa->fsx_xflags &
>> +                                                    ~FS_XFLAG_RDONLY_MASK);
>> +                               if (!(fa->fsx_xflags_mask & FS_XFLAG_EXTSIZE))
>> +                                       fa->fsx_extsize = old_ma.fsx_extsize;
>> +                               if (!(fa->fsx_xflags_mask & FS_XFLAG_PROJID))
>> +                                       fa->fsx_projid = old_ma.fsx_projid;
>> +                               if (!(fa->fsx_xflags_mask & FS_XFLAG_COWEXTSIZE))
>> +                                       fa->fsx_cowextsize = old_ma.fsx_cowextsize;
>> +                       }
>>                         fa->flags |= old_ma.flags & ~FS_COMMON_FL;
>> +
>> +                       /* xflags not present in fsxattr */
>> +                       if (!(fa->fsx_xflags_mask & FS_XFLAG_PTIME))
>> +                               fa->fsx_ptime = old_ma.fsx_ptime;
>>                 }
>>
>
> This whole flags/xflags duality needs a closer look
> This looks a bit too complicated right now.

Yes, I agree.

> I don't have time to do the full review so wanted to give you the
> main feedback first.
>
> I'll try to get to it this week.

Of course, no problem, I also still have a few kinda unrelated patches
to work on and a fairly long list of bugs to fix (found by sashiko), so
v5 will probably be ready this weekend/next week anyway.

Thank you again very much.

Best,
koraynilay

> Thanks,
> Amir.

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

  reply	other threads:[~2026-11-16 20:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-15 18:03 [RFC PATCH v4 00/10] add provenance time (ptime) koraynilay
2026-11-15 18:03 ` [RFC PATCH v4 01/10] vfs: " koraynilay
2026-11-16 20:10   ` Amir Goldstein
2026-11-16 20:53     ` koraynilay [this message]
2026-11-15 18:03 ` [RFC PATCH v4 02/10] vfs: add fileattr_has_fsx_mask() koraynilay
2026-11-15 18:03 ` [RFC PATCH v4 03/10] ntfs3: make crtime user-settable using ptime koraynilay
2026-11-15 18:03 ` [RFC PATCH v4 04/10] exfat: " koraynilay
2026-11-15 18:03 ` [RFC PATCH v4 05/10] btrfs: add provenance time (ptime) koraynilay
2026-11-15 18:03 ` [RFC PATCH v4 06/10] vfs: add __vfs_fileattr_set_locked() for inode_lock()'d callers koraynilay
2026-11-16 13:52   ` Amir Goldstein
2026-11-16 15:55     ` koraynilay
2026-11-15 18:03 ` [RFC PATCH v4 07/10] nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE koraynilay
2026-11-15 18:03 ` [RFC PATCH v4 08/10] nfs: " koraynilay
2026-11-15 18:03 ` [RFC PATCH v4 09/10] ksmbd: add provenance time (ptime) and map it to CreationTime koraynilay
2026-11-15 18:03 ` [RFC PATCH v4 10/10] cifs: add provenance time (ptime) and map it to SMB's CreationTime 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=DMWXMP61YXEH.1W32ZFF7A7Y5H@gmail.com \
    --to=koray.fra@gmail.com \
    --cc=Dai.Ngo@oracle.com \
    --cc=aalbersh@kernel.org \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=amir73il@gmail.com \
    --cc=anna@kernel.org \
    --cc=bharathsm@microsoft.com \
    --cc=brauner@kernel.org \
    --cc=cel@kernel.org \
    --cc=chenxiaosong@chenxiaosong.com \
    --cc=defendthedisabled@gmail.com \
    --cc=djwong@kernel.org \
    --cc=dsterba@suse.com \
    --cc=exfat@lists.linux.dev \
    --cc=jack@suse.cz \
    --cc=jlayton@kernel.org \
    --cc=linkinjeon@kernel.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=mason@kernel.org \
    --cc=neil@brown.name \
    --cc=ntfs3@lists.linux.dev \
    --cc=okorniev@redhat.com \
    --cc=pali@kernel.org \
    --cc=pc@manguebit.org \
    --cc=pfalcato@suse.de \
    --cc=ronniesahlberg@gmail.com \
    --cc=senozhatsky@chromium.org \
    --cc=sj1557.seo@samsung.com \
    --cc=sprasad@microsoft.com \
    --cc=tom@talpey.com \
    --cc=trondmy@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=yuezhang.mo@sony.com \
    /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