Skip to contentSkip to conversation

add provenance time (ptime)

RFC PATCH In review koraynilay 6 participants 64 messages Nov 15 – Nov 20

Subsystems (9)
lore
Share & tools
lore

koraynilay

author
#0 lore raw

v4 cover add provenance time (ptime)

This is an initial implementation of a new timestamp to indicate the time when a file/directory was initially created.

This patch series takes inspiration from the one by Sean Smith <[email protected]> [1], but using file_setattr()/file_getattr() as suggested by Darrick J. Wong <[email protected]> in [2].

The semantics of this new timestamp should be at least these:
- it should be the same as btime on a newly created file
- it's user-settable, so it can be preserved for backups, filesystem conversions, archives and any similar operation
- it should be preserved every time mtime gets preserved

and the correspondence with the other timestamps is as follows:

ctime <-> btime
mtime <-> ptime

Examples:
1) a .zsh_history file created in 2019, then after a few years the user decides to switch to another filesystem, copying the .zsh_history to the new home, in that case btime would have the timestamp of the copy and ptime would have the 2019 timestamp (just like mtime would have been preserved)
2) a symlink created in 2020 from the home directory to a /path going through the same process as the .zsh_history, in this case it would also make sense to sync the ptime to the 2020 timestamp instead of keeping only the btime (so the inode creation time).

The proof-of-concept code (for testing) for stat(1) and cp(1) is available at https://github.com/koraynilay/coreutils (master branch) (Note: these coreutils code changes are a prototype and won't be submitted upstream as-is, but they work as expected in simple stat and cp -a/--preserve=ptime tests)

Lastly, the name "provenance" and "ptime" are not final, I personally don't have a strong opinion on any name, but while testing with stat(1) I noticed that "Provenance" is definitely too long for the normal output, so another option which would fit well is "Origin time", abbreviated as "ntime" (OrigiN time) and not as "otime", as that would conflict with btrfs' internal naming and create confusion.

v2 changes:
- fix permission bypass leading to ptime update on immutable and append-only files (found by sashiko[3])
- normalize ptime timestamp as done in fs/attr.c:notify_change() (found by sashiko[3])
- fix wording in vfs patch to be like the cover-letter

v3 changes:
- vfs: reject setting ptime with -EOPNOTSUPP on filesystems that do not support it instead of silently ignoring it (found by sashiko[4])
- vfs: fix not being able to clear immutable and append-only on files with ptime, and allow updating immutable/append-only atomically along with ptime (found by sashiko[4])
- btrfs: validate on-disk ptime nanoseconds and reset to otime if invalid (found by sashiko[4])
- btrfs: avoid re-assigning ptime on unrelated chattr calls (found by sashiko[4])
- add ntfs3 and exfat support as suggested by Amir Goldstein[5], but no vfat, smb, or nfs4 yet as they are a bit more complex
- move the introduction of fileattr_has_fsx_mask() from the btrfs patch to a standalone patch in the series
- btrfs: add fileattr_[gs]et to symlink and special file operations

v4 changes:
- vfs: implement fsx_xflags_mask as suggested by Amir Goldstein[6];
- add SMB (ksmbd/cifs) and nfs (nfsd/nfs) support as requested in previous threads;

Note:
to apply this patch 2 previous patches[7][8] from the ksmbd/cifs subsystem are needed.

New Question:
should I rename fileattr_has_fsx_mask() to something like fileattr_has_unsupported_fsx() and keep its code as-is, or should I add the fsx_xflags_mask & ~allowed check in it and keep the name as-is? (or both?)

Thanks.

[1]: https://lore.kernel.org/[email protected]
[2]: https://lore.kernel.org/20260407014129.GC6192@frogsfrogsfrogs
[3]: https://sashiko.dev/#/patchset/20261027220532.736352-1-koray.fra%40gmail.com
[4]: https://sashiko.dev/#/patchset/20261028134728.294127-1-koray.fra%40gmail.com
[5]: https://lore.kernel.org/CAOQ4uxiuy0VwZj+3M-zRqQ49WTpHZpiaQ+6MZ8z8WdLjyQM_zA@mail.gmail.com/
[6]: https://lore.kernel.org/CAOQ4uxjtuTDT63vJdYaq+RHQEQFLTksp66e46OMN99WhJz3SbA@mail.gmail.com/
[7]: https://lore.kernel.org/linux-cifs/[email protected]/
[8]: https://lore.kernel.org/linux-cifs/[email protected]/

koraynilay (10):
vfs: add provenance time (ptime)
vfs: add fileattr_has_fsx_mask()
ntfs3: make crtime user-settable using ptime
exfat: make crtime user-settable using ptime
btrfs: add provenance time (ptime)
vfs: add __vfs_fileattr_set_locked() for inode_lock()'d callers
nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE
nfs: add provenance time (ptime) via FATTR4_TIME_CREATE
ksmbd: add provenance time (ptime) and map it to CreationTime
cifs: add provenance time (ptime) and map it to SMB's CreationTime

 fs/btrfs/btrfs_inode.h          |   4 +
 fs/btrfs/delayed-inode.c        |   6 ++
 fs/btrfs/inode.c                |  29 +++++-
 fs/btrfs/ioctl.c                |  24 ++++-
 fs/btrfs/print-tree.c           |   1 +
 fs/btrfs/tree-log.c             |   3 +
 fs/exfat/exfat_fs.h             |   2 +
 fs/exfat/file.c                 |  42 ++++++++-
 fs/exfat/namei.c                |   1 +
 fs/file_attr.c                  | 156 ++++++++++++++++++++++++++------
 fs/nfs/inode.c                  |  27 +++++-
 fs/nfs/internal.h               |   2 +
 fs/nfs/nfs4proc.c               |  56 +++++++++++-
 fs/nfs/nfs4xdr.c                |  19 ++--
 fs/nfs/symlink.c                |   1 +
 fs/nfsd/nfs4proc.c              |   9 ++
 fs/nfsd/nfs4xdr.c               |  40 +++++---
 fs/nfsd/vfs.c                   |  17 ++++
 fs/nfsd/vfs.h                   |   4 +-
 fs/nfsd/xdr4.h                  |   3 +
 fs/ntfs3/file.c                 |  20 +++-
 fs/ntfs3/frecord.c              |   8 +-
 fs/smb/client/cifsfs.c          |   8 ++
 fs/smb/client/inode.c           |   7 +-
 fs/smb/client/ioctl.c           | 109 ++++++++++++++++------
 fs/smb/server/smb2pdu.c         |  37 +++++---
 fs/smb/server/vfs.c             |  43 ++++++++-
 fs/smb/server/vfs.h             |   1 +
 fs/stat.c                       |   2 +
 include/linux/fileattr.h        |  29 +++++-
 include/linux/nfs_xdr.h         |   3 +
 include/linux/stat.h            |   1 +
 include/uapi/linux/btrfs_tree.h |   3 +-
 include/uapi/linux/fs.h         |   9 +-
 include/uapi/linux/stat.h       |   7 +-
 35 files changed, 614 insertions(+), 119 deletions(-)

base-commit: 3bc1fb9c3b20cd478c83496ab16addecb401770d
prerequisite-patch-id: 049ae0eba275b5be35a238833107e0b251a55aa2
prerequisite-patch-id: 614f0bc9411391403d4e9702bafeb31b0ec04ec1
prerequisite-patch-id: ddf636b9d33d82ea206ce265d817371350bf8858

Signature · 1 line
2.56.0
author
#1 lore raw

RFC PATCH v4 1/10 vfs: add provenance time (ptime)

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 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 is a re-implementation of the initial patch[1] by Sean Smith
<[email protected]>, following the advice[2] from Darrick J. Wong <[email protected]> of using file_setattr() instead of updating utimensat() ]

[1]: https://lore.kernel.org/[email protected]
[2]: https://lore.kernel.org/20260407014129.GC6192@frogsfrogsfrogs

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.4.7
---
 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(-)
fs/file_attr.c +72 -3
index 833e03810b24..12610fb6a751 100644
@@ -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;
+	}
+
 	/*
 	 * 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;
 		}
 
 		err = fileattr_set_prepare(inode, &old_ma, fa);
@@ -423,6 +485,10 @@ SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename,
 		return error;
 
 	fileattr_to_file_attr(&fa, &fattr);
+
+	if (usize < FILE_ATTR_SIZE_VER1)
+		fattr.fa_xflags &= ~FS_XFLAG_PTIME;
+
 	error = copy_struct_to_user(ufattr, usize, &fattr,
 				    sizeof(struct file_attr), NULL);
 
@@ -459,6 +525,9 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename,
 	if (error)
 		return error;
 
+	if ((fattr.fa_xflags & FS_XFLAG_PTIME) && usize < FILE_ATTR_SIZE_VER1)
+		return -EINVAL;
+
 	error = file_attr_to_fileattr(&fattr, &fa);
 	if (error)
 		return error;
fs/stat.c +2 -0
index 34d786c1de3e..1e4260f55f01 100644
@@ -728,6 +728,8 @@ cp_statx(const struct kstat *stat, struct statx __user *buffer)
 	tmp.stx_ctime.tv_nsec = stat->ctime.tv_nsec;
 	tmp.stx_mtime.tv_sec = stat->mtime.tv_sec;
 	tmp.stx_mtime.tv_nsec = stat->mtime.tv_nsec;
+	tmp.stx_ptime.tv_sec = stat->ptime.tv_sec;
+	tmp.stx_ptime.tv_nsec = stat->ptime.tv_nsec;
 	tmp.stx_rdev_major = MAJOR(stat->rdev);
 	tmp.stx_rdev_minor = MINOR(stat->rdev);
 	tmp.stx_dev_major = MAJOR(stat->dev);
include/linux/fileattr.h +6 -0
index 09e32b84e02a..42b92ccdc583 100644
@@ -35,6 +35,10 @@
 	(FS_XFLAG_COMMON | FS_XFLAG_RDONLY_MASK | FS_XFLAG_VALUES_MASK | \
 	 FS_XFLAG_DIRONLY_MASK | FS_XFLAG_MISC_MASK)
 
+/* Flags only for fa_ fields */
+#define FS_FILE_ATTR_XFLAGS_MASK \
+	(FS_XFLAGS_MASK | FS_XFLAG_PTIME | FS_XFLAG_PROJID)
+
 /*
  * Merged interface for miscellaneous file attributes.  'flags' originates from
  * ext* and 'fsx_flags' from xfs.  There's some overlap between the two, which
@@ -45,10 +49,12 @@ struct file_kattr {
 	u32	flags;		/* flags (FS_IOC_GETFLAGS/FS_IOC_SETFLAGS) */
 	/* struct fsxattr: */
 	u32	fsx_xflags;	/* xflags field value (get/set) */
+	u32	fsx_xflags_mask; /* supported xflags (get) / flags to set (set) */
 	u32	fsx_extsize;	/* extsize field value (get/set)*/
 	u32	fsx_nextents;	/* nextents field value (get)	*/
 	u32	fsx_projid;	/* project identifier (get/set) */
 	u32	fsx_cowextsize;	/* CoW extsize field value (get/set)*/
+	struct timespec64 fsx_ptime; /* provenance (settable birth) time */
 	/* selectors: */
 	bool	flags_valid:1;
 	bool	fsx_valid:1;
include/linux/stat.h +1 -0
index 4f0a4af7a067..5384a77676f1 100644
@@ -48,6 +48,7 @@ struct kstat {
 	struct timespec64 mtime;
 	struct timespec64 ctime;
 	struct timespec64 btime;			/* File creation time */
+	struct timespec64 ptime;	/* File provenance (user-settable creation) time */
 	u64		blocks;
 	u64		mnt_id;
 	u64		change_cookie;
include/uapi/linux/fs.h +8 -1
index a46c33692aa2..655e448cdd23 100644
@@ -229,10 +229,14 @@ struct file_attr {
 	__u32 fa_nextents;	/* nextents field value (get)   */
 	__u32 fa_projid;	/* project identifier (get/set) */
 	__u32 fa_cowextsize;	/* CoW extsize field value (get/set) */
+	__s64 fa_ptime_sec;	/* provenance (settable birth) time (seconds) */
+	__u32 fa_ptime_nsec;	/* provenance (settable birth) time (nanoseconds) */
+	__u32 fa_xflags_mask;   /* supported xflags (get) / flags to set (set) */
 };
 
 #define FILE_ATTR_SIZE_VER0 24
-#define FILE_ATTR_SIZE_LATEST FILE_ATTR_SIZE_VER0
+#define FILE_ATTR_SIZE_VER1 40
+#define FILE_ATTR_SIZE_LATEST FILE_ATTR_SIZE_VER1
 
 /*
  * Flags for the fsx_xflags field
@@ -261,6 +265,9 @@ struct file_attr {
  */
 #define FS_XFLAG_CASEFOLD	0x00040000	/* case-insensitive lookups */
 #define FS_XFLAG_CASENONPRESERVING 0x00080000	/* case not preserved */
+
+#define FS_XFLAG_PTIME		0x00100000	/* provenance time */
+#define FS_XFLAG_PROJID		0x00200000	/* project ID */
 #define FS_XFLAG_HASATTR	0x80000000	/* no DIFLAG for this	*/
 
 /* the read-only stuff doesn't really belong here, but any other place is
include/uapi/linux/stat.h +6 -1
index 1686861aae20..f3a1013ba022 100644
@@ -187,7 +187,11 @@ struct statx {
 	__u32	__spare2[1];
 
 	/* 0xc0 */
-	__u64	__spare3[8];	/* Spare space for future expansion */
+	/* Data provenance (creation) time */
+	struct statx_timestamp	stx_ptime;
+
+	/* 0xd0 */
+	__u64	__spare3[6];	/* Spare space for future expansion */
 
 	/* 0x100 */
 };
@@ -219,6 +223,7 @@ struct statx {
 #define STATX_SUBVOL		0x00008000U	/* Want/got stx_subvol */
 #define STATX_WRITE_ATOMIC	0x00010000U	/* Want/got atomic_write_* fields */
 #define STATX_DIO_READ_ALIGN	0x00020000U	/* Want/got dio read alignment info */
+#define STATX_PTIME		0x00040000U	/* Want/got stx_ptime */
 
 #define STATX__RESERVED		0x80000000U	/* Reserved for future struct statx expansion */
 
Signature · 1 line
2.56.0
#2 lore raw

Re: [RFC PATCH v4 01/10] vfs: add provenance time (ptime)

Quoted 8 lines · koraynilay

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:

Quoted 7 lines

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.

Quoted 12 lines

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.

Quoted 8 lines

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

Quoted 83 lines

[ This is a re-implementation of the initial patch[1] by Sean Smith
<[email protected]>, following the advice[2] from Darrick J. Wong <[email protected]> of using file_setattr() instead of updating utimensat() ]

[1]: https://lore.kernel.org/[email protected]
[2]: https://lore.kernel.org/20260407014129.GC6192@frogsfrogsfrogs

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.4.7
---
 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(-)
fs/file_attr.c +24 -2
index 833e03810b24..12610fb6a751 100644
@@ -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))

fs/file_attr.c static int fileattr_set_prepare(struct inode *inode, · line 266

Quoted 10 lines
fs/file_attr.c +10 -0
+                       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.

Quoted 37 lines
fs/file_attr.c +24 -1
+       }
+
        /*
         * 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;

fs/file_attr.c int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, · line 361

Quoted 10 lines
fs/file_attr.c +7 -0
+                               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.

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.

Thanks,
Amir.

author
#3 lore raw

Re: [RFC PATCH v4 01/10] vfs: add provenance time (ptime)

Quoted 12 lines · Amir Goldstein
Quoted 11 lines · koraynilay

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

Quoted 8 lines
Quoted 4 lines

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.

Quoted 18 lines
Quoted 18 lines

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.

Quoted 4 lines
Quoted 2 lines

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.

Quoted 87 lines
Quoted 87 lines

[ This is a re-implementation of the initial patch[1] by Sean Smith
<[email protected]>, following the advice[2] from Darrick J. Wong <[email protected]> of using file_setattr() instead of updating utimensat() ]

[1]: https://lore.kernel.org/[email protected]
[2]: https://lore.kernel.org/20260407014129.GC6192@frogsfrogsfrogs

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.4.7
---
 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(-)
fs/file_attr.c +28 -2
index 833e03810b24..12610fb6a751 100644
@@ -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;
Quoted 8 lines

fs/file_attr.c static int fileattr_set_prepare(struct inode *inode, · line 266

Quoted 6 lines
fs/file_attr.c +6 -0
+
+               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.

Quoted 43 lines
Quoted 43 lines
fs/file_attr.c +28 -1
+       }
+
        /*
         * 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;
+
Quoted 8 lines

fs/file_attr.c int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, · line 361

Quoted 5 lines
fs/file_attr.c +3 -0
+                       /* 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.

Quoted 4 lines

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

Quoted 2 lines

Thanks,
Amir.

author
#4 lore raw

RFC PATCH v4 2/10 vfs: add fileattr_has_fsx_mask()

In reply to koraynilay

Add fileattr_has_fsx_mask() as a helper to let filesystems check for unsupported xflags while allowing supported ones. Can be used in the same way as fileattr_has_fsx().

Also make fileattr_has_fsx() a wrapper around fileattr_has_fsx_mask().

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.4.7
---
 include/linux/fileattr.h | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
include/linux/fileattr.h +18 -3
index 42b92ccdc583..ba7ed3b387d8 100644
@@ -65,6 +65,23 @@ int copy_fsxattr_to_user(const struct file_kattr *fa, struct fsxattr __user *ufa
 void fileattr_fill_xflags(struct file_kattr *fa, u32 xflags);
 void fileattr_fill_flags(struct file_kattr *fa, u32 flags);
 
+/**
+ * fileattr_has_fsx_mask - check for extended flags/attributes
+ * @fa:				fileattr pointer
+ * @allowed_xflags_mask:	additional xflags permitted
+ *
+ * Return: true if any attributes are present that are not represented in
+ * ->flags or @allowed_xflags_mask.
+ */
+static inline bool fileattr_has_fsx_mask(const struct file_kattr *fa,
+					 u32 allowed_xflags_mask)
+{
+	return fa->fsx_valid &&
+		((fa->fsx_xflags & ~(FS_XFLAG_COMMON | allowed_xflags_mask)) ||
+		 fa->fsx_extsize != 0 || fa->fsx_projid != 0 ||
+		 fa->fsx_cowextsize != 0);
+}
+
 /**
  * fileattr_has_fsx - check for extended flags/attributes
  * @fa:		fileattr pointer
@@ -74,9 +91,7 @@ void fileattr_fill_flags(struct file_kattr *fa, u32 flags);
  */
 static inline bool fileattr_has_fsx(const struct file_kattr *fa)
 {
-	return fa->fsx_valid &&
-		((fa->fsx_xflags & ~FS_XFLAG_COMMON) || fa->fsx_extsize != 0 ||
-		 fa->fsx_projid != 0 ||	fa->fsx_cowextsize != 0);
+	return fileattr_has_fsx_mask(fa, 0);
 }
 
 int vfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
Signature · 1 line
2.56.0
#5 lore raw

Re: [RFC PATCH v4 02/10] vfs: add fileattr_has_fsx_mask()

Quoted 28 lines · koraynilay

Add fileattr_has_fsx_mask() as a helper to let filesystems check for unsupported xflags while allowing supported ones. Can be used in the same way as fileattr_has_fsx().

Also make fileattr_has_fsx() a wrapper around fileattr_has_fsx_mask().

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.4.7
---
 include/linux/fileattr.h | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
include/linux/fileattr.h +7 -0
index 42b92ccdc583..ba7ed3b387d8 100644
@@ -65,6 +65,23 @@ int copy_fsxattr_to_user(const struct file_kattr *fa, struct fsxattr __user *ufa
 void fileattr_fill_xflags(struct file_kattr *fa, u32 xflags);
 void fileattr_fill_flags(struct file_kattr *fa, u32 flags);
 
+/**
+ * fileattr_has_fsx_mask - check for extended flags/attributes
+ * @fa:                                fileattr pointer
+ * @allowed_xflags_mask:       additional xflags permitted
+ *
+ * Return: true if any attributes are present that are not represented in
+ * ->flags or @allowed_xflags_mask.

include/linux/fileattr.h int copy_fsxattr_to_user(const struct file_kattr *fa, struct fsxattr __user *ufa · line 84

Quoted 10 lines
include/linux/fileattr.h +10 -0
+ */
+static inline bool fileattr_has_fsx_mask(const struct file_kattr *fa,
+                                        u32 allowed_xflags_mask)
+{
+       return fa->fsx_valid &&
+               ((fa->fsx_xflags & ~(FS_XFLAG_COMMON | allowed_xflags_mask)) ||
+                fa->fsx_extsize != 0 || fa->fsx_projid != 0 ||
+                fa->fsx_cowextsize != 0);
+}
+

Every patch in your series did:

       if (fileattr_has_fsx_mask(fa, EXFAT_SUPPORTED_XFLAGS))
               return -EOPNOTSUPP;

       if (fa->fsx_xflags_mask & ~EXFAT_SUPPORTED_XFLAGS)
               return -EOPNOTSUPP;

It looks like this helper is not as helpful as it could have been and you have raised this question yourself in the cover letter.

Effectively every filesystem that supports fileattr_set() already has a defined SUPPORTED mask, so I think it's better to do the negated something like:

static inline bool fileattr_supported_fsx_mask(const struct file_kattr *fa,
u32 supported)

{
        if (!fa->fsx_valid)
                return true;
        if ((fa->fsx_xflags | fa->fsx_xflags_mask) & ~supported)
                return false;
        if (fa->fsx_extsize &&
            !(supported & (FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT)))
                return false;
        if (fa->fsx_cowextsize && !(supported & FS_XFLAG_COWEXTSIZE))
                return false;
        if (fa->fsx_projid && !(supported & FS_XFLAG_PROJID))
                return false;
        return true;
}

...

if (!fileattr_supported_fsx_mask(fa, EXFAT_SUPPORTED_XFLAGS))
return -EOPNOTSUPP;

include/linux/fileattr.h void fileattr_fill_flags(struct file_kattr *fa, u32 flags); · line 94

Quoted 11 lines
include/linux/fileattr.h +1 -3
 /**
  * fileattr_has_fsx - check for extended flags/attributes
  * @fa:                fileattr pointer
@@ -74,9 +91,7 @@ void fileattr_fill_flags(struct file_kattr *fa, u32 flags);
  */
 static inline bool fileattr_has_fsx(const struct file_kattr *fa)
 {
-       return fa->fsx_valid &&
-               ((fa->fsx_xflags & ~FS_XFLAG_COMMON) || fa->fsx_extsize != 0 ||
-                fa->fsx_projid != 0 || fa->fsx_cowextsize != 0);
+       return fileattr_has_fsx_mask(fa, 0);
            return !fileattr_supported_fsx_mask(fa, FS_XFLAG_COMMON);

I hope I got this right.

Thanks,
Amir.

author
#6 lore raw

Re: [RFC PATCH v4 02/10] vfs: add fileattr_has_fsx_mask()

Quoted 93 lines · Amir Goldstein
Quoted 28 lines · koraynilay

Add fileattr_has_fsx_mask() as a helper to let filesystems check for unsupported xflags while allowing supported ones. Can be used in the same way as fileattr_has_fsx().

Also make fileattr_has_fsx() a wrapper around fileattr_has_fsx_mask().

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.4.7
---
 include/linux/fileattr.h | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
include/linux/fileattr.h +7 -0
index 42b92ccdc583..ba7ed3b387d8 100644
@@ -65,6 +65,23 @@ int copy_fsxattr_to_user(const struct file_kattr *fa, struct fsxattr __user *ufa
 void fileattr_fill_xflags(struct file_kattr *fa, u32 xflags);
 void fileattr_fill_flags(struct file_kattr *fa, u32 flags);
 
+/**
+ * fileattr_has_fsx_mask - check for extended flags/attributes
+ * @fa:                                fileattr pointer
+ * @allowed_xflags_mask:       additional xflags permitted
+ *
+ * Return: true if any attributes are present that are not represented in
+ * ->flags or @allowed_xflags_mask.

include/linux/fileattr.h int copy_fsxattr_to_user(const struct file_kattr *fa, struct fsxattr __user *ufa · line 84

Quoted 10 lines
include/linux/fileattr.h +10 -0
+ */
+static inline bool fileattr_has_fsx_mask(const struct file_kattr *fa,
+                                        u32 allowed_xflags_mask)
+{
+       return fa->fsx_valid &&
+               ((fa->fsx_xflags & ~(FS_XFLAG_COMMON | allowed_xflags_mask)) ||
+                fa->fsx_extsize != 0 || fa->fsx_projid != 0 ||
+                fa->fsx_cowextsize != 0);
+}
+

Every patch in your series did:

       if (fileattr_has_fsx_mask(fa, EXFAT_SUPPORTED_XFLAGS))
               return -EOPNOTSUPP;

       if (fa->fsx_xflags_mask & ~EXFAT_SUPPORTED_XFLAGS)
               return -EOPNOTSUPP;

It looks like this helper is not as helpful as it could have been and you have raised this question yourself in the cover letter.

Effectively every filesystem that supports fileattr_set() already has a defined SUPPORTED mask, so I think it's better to do the negated something like:

static inline bool fileattr_supported_fsx_mask(const struct file_kattr *fa,
u32 supported)

{
        if (!fa->fsx_valid)
                return true;
        if ((fa->fsx_xflags | fa->fsx_xflags_mask) & ~supported)
                return false;
        if (fa->fsx_extsize &&
            !(supported & (FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT)))
                return false;
        if (fa->fsx_cowextsize && !(supported & FS_XFLAG_COWEXTSIZE))
                return false;
        if (fa->fsx_projid && !(supported & FS_XFLAG_PROJID))
                return false;
        return true;
}

...

if (!fileattr_supported_fsx_mask(fa, EXFAT_SUPPORTED_XFLAGS))
return -EOPNOTSUPP;

include/linux/fileattr.h void fileattr_fill_flags(struct file_kattr *fa, u32 flags); · line 94

Quoted 11 lines
include/linux/fileattr.h +1 -3
 /**
  * fileattr_has_fsx - check for extended flags/attributes
  * @fa:                fileattr pointer
@@ -74,9 +91,7 @@ void fileattr_fill_flags(struct file_kattr *fa, u32 flags);
  */
 static inline bool fileattr_has_fsx(const struct file_kattr *fa)
 {
-       return fa->fsx_valid &&
-               ((fa->fsx_xflags & ~FS_XFLAG_COMMON) || fa->fsx_extsize != 0 ||
-                fa->fsx_projid != 0 || fa->fsx_cowextsize != 0);
+       return fileattr_has_fsx_mask(fa, 0);
            return !fileattr_supported_fsx_mask(fa, FS_XFLAG_COMMON);
Quoted 1 line

I hope I got this right.

I think so yeah, though for me it's easier to think about it as "unsupported" instead of "supported", but the idea should be correct.

Though yeah, this helper may not even be needed, I'll see if it's better to keep it and write it like you did here, or just remove it altogether and just do & ~SUPPORTED.

Thanks,
koraynilay

Quoted 2 lines

Thanks,
Amir.

author
#7 lore raw

RFC PATCH v4 3/10 ntfs3: make crtime user-settable using ptime

In reply to koraynilay

Since NTFS supports user-settable file creation timestamps, map provenance time (ptime) to NTFS file creation time (crtime) by using the newly introduced ptime API (in commit "vfs: add provenance time (ptime)").

To do this, update ntfs_fileattr_[gs]et(), ntfs_getattr() and make it persist to disk in ni_write_inode().

The timestamp is now retrievable by using file_getattr() or statx(), and is settable by using file_setattr() with the FS_XFLAG_PTIME flag.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.4.7
---
 fs/ntfs3/file.c    | 20 ++++++++++++++++++--
 fs/ntfs3/frecord.c |  8 +++++++-
 2 files changed, 25 insertions(+), 3 deletions(-)
fs/ntfs3/file.c +18 -2
index 6c84a3e1c7fe..1a9301006154 100644
@@ -90,6 +90,8 @@ static int ntfs_ioctl_fitrim(struct ntfs_sb_info *sbi, unsigned long arg)
 	return 0;
 }
 
+#define NTFS_SUPPORTED_XFLAGS		(FS_XFLAG_PTIME)
+
 /*
  * ntfs_fileattr_get - inode_operations::fileattr_get
  */
@@ -124,6 +126,11 @@ int ntfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
 
 	fileattr_fill_flags(fa, flags);
 
+	fa->fsx_ptime.tv_sec = ni->i_crtime.tv_sec;
+	fa->fsx_ptime.tv_nsec = ni->i_crtime.tv_nsec;
+	fa->fsx_xflags |= FS_XFLAG_PTIME;
+	fa->fsx_xflags_mask |= FS_XFLAG_PTIME;
+
 	return 0;
 }
 
@@ -142,7 +149,10 @@ int ntfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
 	if (unlikely(is_bad_ni(ni)))
 		return -EINVAL;
 
-	if (fileattr_has_fsx(fa))
+	if (fileattr_has_fsx_mask(fa, NTFS_SUPPORTED_XFLAGS))
+		return -EOPNOTSUPP;
+
+	if (fa->fsx_xflags_mask & ~NTFS_SUPPORTED_XFLAGS)
 		return -EOPNOTSUPP;
 
 	if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL))
@@ -154,6 +164,11 @@ int ntfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
 	if (flags & FS_APPEND_FL)
 		new_fl |= S_APPEND;
 
+	if (fa->fsx_xflags_mask & FS_XFLAG_PTIME) {
+		ni->i_crtime.tv_sec = fa->fsx_ptime.tv_sec;
+		ni->i_crtime.tv_nsec = fa->fsx_ptime.tv_nsec;
+	}
+
 	inode_set_flags(inode, new_fl, S_IMMUTABLE | S_APPEND);
 
 	/* Save nodump flag to return in ntfs_getattr. */
@@ -275,8 +290,9 @@ int ntfs_getattr(const struct mnt_idmap *idmap, const struct path *path,
 	if (unlikely(is_bad_ni(ni)))
 		return -EINVAL;
 
-	stat->result_mask |= STATX_BTIME;
+	stat->result_mask |= (STATX_BTIME | STATX_PTIME);
 	stat->btime = ni->i_crtime;
+	stat->ptime = ni->i_crtime;
 	stat->blksize = ni->mi.sbi->cluster_size; /* 512, 1K, ..., 2M */
 
 	if (inode->i_flags & S_IMMUTABLE)
fs/ntfs3/frecord.c +7 -1
index 16ac847de48d..5e4f743a5930 100644
@@ -3215,6 +3215,13 @@ int ni_write_inode(struct inode *inode, int sync, const char *hint)
 		}
 
 		/* Update the access times if they have changed. */
+		ts = ni->i_crtime;
+		dup.cr_time = kernel2nt(&ts);
+		if (std->cr_time != dup.cr_time) {
+			std->cr_time = dup.cr_time;
+			modified = true;
+		}
+
 		ts = inode_get_mtime(inode);
 		dup.m_time = kernel2nt(&ts);
 		if (std->m_time != dup.m_time) {
@@ -3250,7 +3257,6 @@ int ni_write_inode(struct inode *inode, int sync, const char *hint)
 		    (modified || (ni->ni_flags & NI_FLAG_UPDATE_PARENT))
 		    /* Avoid __wait_on_freeing_inode(inode). */
 		    && (sb->s_flags & SB_ACTIVE)) {
-			dup.cr_time = std->cr_time;
 			/* Not critical if this function fail. */
 			re_dirty = ni_update_parent(ni, &dup, sync);
 
Signature · 1 line
2.56.0
#8 lore raw

Re: [RFC PATCH v4 03/10] ntfs3: make crtime user-settable using ptime

Quoted 12 lines · koraynilay

Since NTFS supports user-settable file creation timestamps, map provenance time (ptime) to NTFS file creation time (crtime) by using the newly introduced ptime API (in commit "vfs: add provenance time (ptime)").

To do this, update ntfs_fileattr_[gs]et(), ntfs_getattr() and make it persist to disk in ni_write_inode().

The timestamp is now retrievable by using file_getattr() or statx(), and is settable by using file_setattr() with the FS_XFLAG_PTIME flag.

Quoted 6 lines
Assisted-by Gemini:3.8-flash-high antigravity-cli-1.4.7
---
 fs/ntfs3/file.c    | 20 ++++++++++++++++++--
 fs/ntfs3/frecord.c |  8 +++++++-
 2 files changed, 25 insertions(+), 3 deletions(-)

Please don't change the unmaintained ntfs3 driver.

If you want to include an ntfs patch work on the new fs/ntfs driver.

Thanks,
Amir.

author
#9 lore raw

Re: [RFC PATCH v4 03/10] ntfs3: make crtime user-settable using ptime

Quoted 20 lines · Amir Goldstein
Quoted 12 lines · koraynilay

Since NTFS supports user-settable file creation timestamps, map provenance time (ptime) to NTFS file creation time (crtime) by using the newly introduced ptime API (in commit "vfs: add provenance time (ptime)").

To do this, update ntfs_fileattr_[gs]et(), ntfs_getattr() and make it persist to disk in ni_write_inode().

The timestamp is now retrievable by using file_getattr() or statx(), and is settable by using file_setattr() with the FS_XFLAG_PTIME flag.

Quoted 6 lines
Assisted-by Gemini:3.8-flash-high antigravity-cli-1.4.7
---
 fs/ntfs3/file.c    | 20 ++++++++++++++++++--
 fs/ntfs3/frecord.c |  8 +++++++-
 2 files changed, 25 insertions(+), 3 deletions(-)
Quoted 3 lines

Please don't change the unmaintained ntfs3 driver.

If you want to include an ntfs patch work on the new fs/ntfs driver.

Huh, I thought ntfs3 was the modern and latest one by Paragon. But apparently I missed some news[1][2] lol.
I'll use fs/ntfs for the mutable btime patch then.

Thanks,
koraynilay

[1]: https://www.phoronix.com/news/New-NTFS-Driver-Submitted-Linux
[2]: commit 1e9ea7e04472d4e5e12e58c881eaacfb3e49b669

Quoted 2 lines

Thanks,
Amir.

author
#10 lore raw

RFC PATCH v4 4/10 exfat: make crtime user-settable using ptime

In reply to koraynilay

Since exFAT supports user-settable file creation timestamps, map provenance time (ptime) to exFAT file creation time (crtime) using the newly introduced ptime API (in commit "vfs: add provenance time (ptime)").

To do this, implement exfat_fileattr_set(), set .fileattr_set to it for both file_inode and dir_inode operations and update exfat_fileattr_get() and exfat_getattr().

The timestamp is now retrievable by using file_getattr() or statx(), and is settable by using file_setattr() with the FS_XFLAG_PTIME flag.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.4.7
---
 fs/exfat/exfat_fs.h |  2 ++
 fs/exfat/file.c     | 42 +++++++++++++++++++++++++++++++++++++++++-
 fs/exfat/namei.c    |  1 +
 3 files changed, 44 insertions(+), 1 deletion(-)
fs/exfat/exfat_fs.h +2 -0
index eee573d1697c..aff96afa258a 100644
@@ -619,6 +619,8 @@ int exfat_getattr(const struct mnt_idmap *idmap, const struct path *path,
 		  unsigned int query_flags);
 struct file_kattr;
 int exfat_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
+int exfat_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
+		       struct file_kattr *fa);
 int exfat_file_fsync(struct file *file, loff_t start, loff_t end, int datasync);
 long exfat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
 long exfat_compat_ioctl(struct file *filp, unsigned int cmd,
fs/exfat/file.c +41 -1

72 lines not on this page · raw message

fs/exfat/namei.c +1 -0
index 68ddb9c5504f..15ec7f1942c8 100644
@@ -1349,4 +1349,5 @@ const struct inode_operations exfat_dir_inode_operations = {
 	.setattr	= exfat_setattr,
 	.getattr	= exfat_getattr,
 	.fileattr_get	= exfat_fileattr_get,
+	.fileattr_set	= exfat_fileattr_set,
 };
Signature · 1 line
2.56.0
author
#11 lore raw

RFC PATCH v4 5/10 btrfs: add provenance time (ptime)

In reply to koraynilay

Implement provenance time (ptime) in Btrfs, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Update the on-disk format by claiming 12 bytes from the reserved[] space in btrfs_inode_item, putting ptime before other timestamps. When loading stale garbage data from disk for ptime, warn (rate-limited) to dmesg.

Advertise support for FS_XFLAG_PTIME using fa_xflags_mask in btrfs_fileattr_get(), and validate that only supported xflags are requested in btrfs_fileattr_set() using a newly introduced BTRFS_SUPPORTED_XFLAGS (containing only FS_XFLAG_PTIME for now).

Also, set .fileattr_[gs]et to btrfs_fileattr_[gs]et() for both symlinks and special files and reject any other flag update on them with -EOPNOTSUPP.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.4.7
---
 fs/btrfs/btrfs_inode.h          |  4 ++++
 fs/btrfs/delayed-inode.c        |  6 ++++++
 fs/btrfs/inode.c                | 29 ++++++++++++++++++++++++++++-
 fs/btrfs/ioctl.c                | 24 +++++++++++++++++++++++-
 fs/btrfs/print-tree.c           |  1 +
 fs/btrfs/tree-log.c             |  3 +++
 include/uapi/linux/btrfs_tree.h |  3 ++-
 7 files changed, 67 insertions(+), 3 deletions(-)
fs/btrfs/btrfs_inode.h +4 -0
index 0782f917fccc..c9822340567a 100644
@@ -332,6 +332,10 @@ struct btrfs_inode {
 	u64 i_otime_sec;
 	u32 i_otime_nsec;
 
+	/* File *data* creation (provenance) time. */
+	s64 i_ptime_sec;
+	u32 i_ptime_nsec;
+
 	/* Hook into fs_info->delayed_iputs */
 	struct list_head delayed_iput;
 
fs/btrfs/delayed-inode.c +6 -0
index 333ce8b52489..eef73ebb4a52 100644
@@ -1932,6 +1932,9 @@ static void fill_stack_inode_item(struct btrfs_trans_handle *trans,
 
 	btrfs_set_stack_timespec_sec(&inode_item->otime, inode->i_otime_sec);
 	btrfs_set_stack_timespec_nsec(&inode_item->otime, inode->i_otime_nsec);
+
+	btrfs_set_stack_timespec_sec(&inode_item->ptime, inode->i_ptime_sec);
+	btrfs_set_stack_timespec_nsec(&inode_item->ptime, inode->i_ptime_nsec);
 }
 
 int btrfs_fill_inode(struct btrfs_inode *inode, u32 *rdev)
@@ -1981,6 +1984,9 @@ int btrfs_fill_inode(struct btrfs_inode *inode, u32 *rdev)
 	inode->i_otime_sec = btrfs_stack_timespec_sec(&inode_item->otime);
 	inode->i_otime_nsec = btrfs_stack_timespec_nsec(&inode_item->otime);
 
+	inode->i_ptime_sec = btrfs_stack_timespec_sec(&inode_item->ptime);
+	inode->i_ptime_nsec = btrfs_stack_timespec_nsec(&inode_item->ptime);
+
 	vfs_inode->i_generation = inode->generation;
 	if (S_ISDIR(vfs_inode->i_mode))
 		inode->index_cnt = (u64)-1;
fs/btrfs/inode.c +28 -1
index abaa33471456..ff8f7a0caad3 100644
@@ -4057,6 +4057,17 @@ static int btrfs_read_locked_inode(struct btrfs_inode *inode, struct btrfs_path
 	inode->i_otime_sec = btrfs_timespec_sec(leaf, &inode_item->otime);
 	inode->i_otime_nsec = btrfs_timespec_nsec(leaf, &inode_item->otime);
 
+	inode->i_ptime_sec = btrfs_timespec_sec(leaf, &inode_item->ptime);
+	inode->i_ptime_nsec = btrfs_timespec_nsec(leaf, &inode_item->ptime);
+	/* Avoid old garbage on-disk data making btrfs load a bad value */
+	if (unlikely(inode->i_ptime_nsec >= NSEC_PER_SEC)) {
+		btrfs_warn_rl(fs_info,
+			      "invalid ptime.nsec %u on ino %llu from disk, setting ptime to otime",
+			      inode->i_ptime_nsec, btrfs_ino(inode));
+		inode->i_ptime_sec = inode->i_otime_sec;
+		inode->i_ptime_nsec = inode->i_otime_nsec;
+	}
+
 	inode_set_bytes(vfs_inode, btrfs_inode_nbytes(leaf, inode_item));
 	inode->generation = btrfs_inode_generation(leaf, inode_item);
 	inode->last_trans = btrfs_inode_transid(leaf, inode_item);
@@ -4249,6 +4260,9 @@ static void fill_inode_item(struct btrfs_trans_handle *trans,
 	btrfs_set_timespec_sec(leaf, &item->otime, BTRFS_I(inode)->i_otime_sec);
 	btrfs_set_timespec_nsec(leaf, &item->otime, BTRFS_I(inode)->i_otime_nsec);
 
+	btrfs_set_timespec_sec(leaf, &item->ptime, BTRFS_I(inode)->i_ptime_sec);
+	btrfs_set_timespec_nsec(leaf, &item->ptime, BTRFS_I(inode)->i_ptime_nsec);
+
 	btrfs_set_inode_nbytes(leaf, item, inode_get_bytes(inode));
 	btrfs_set_inode_generation(leaf, item, BTRFS_I(inode)->generation);
 	btrfs_set_inode_sequence(leaf, item, inode_peek_iversion(inode));
@@ -5988,6 +6002,8 @@ static struct btrfs_inode *new_simple_dir(struct inode *dir,
 	inode_set_atime_to_ts(vfs_inode, inode_get_atime(dir));
 	inode->i_otime_sec = ts.tv_sec;
 	inode->i_otime_nsec = ts.tv_nsec;
+	inode->i_ptime_sec = ts.tv_sec;
+	inode->i_ptime_nsec = ts.tv_nsec;
 
 	vfs_inode->i_uid = dir->i_uid;
 	vfs_inode->i_gid = dir->i_gid;
@@ -6714,6 +6730,8 @@ int btrfs_create_new_inode(struct btrfs_trans_handle *trans,
 	ts = simple_inode_init_ts(inode);
 	BTRFS_I(inode)->i_otime_sec = ts.tv_sec;
 	BTRFS_I(inode)->i_otime_nsec = ts.tv_nsec;
+	BTRFS_I(inode)->i_ptime_sec = ts.tv_sec;
+	BTRFS_I(inode)->i_ptime_nsec = ts.tv_nsec;
 
 	/*
 	 * We're going to fill the inode item now, so at this point the inode
@@ -8048,6 +8066,9 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
 	ei->i_otime_sec = 0;
 	ei->i_otime_nsec = 0;
 
+	ei->i_ptime_sec = 0;
+	ei->i_ptime_nsec = 0;
+
 	inode = &ei->vfs_inode;
 	btrfs_extent_map_tree_init(&ei->extent_tree);
 
@@ -8186,9 +8207,11 @@ static int btrfs_getattr(const struct mnt_idmap *idmap,
 	u32 blocksize = btrfs_sb(inode->i_sb)->sectorsize;
 	u32 bi_flags = BTRFS_I(inode)->flags;
 
-	stat->result_mask |= STATX_BTIME;
+	stat->result_mask |= (STATX_BTIME | STATX_PTIME);
 	stat->btime.tv_sec = BTRFS_I(inode)->i_otime_sec;
 	stat->btime.tv_nsec = BTRFS_I(inode)->i_otime_nsec;
+	stat->ptime.tv_sec = BTRFS_I(inode)->i_ptime_sec;
+	stat->ptime.tv_nsec = BTRFS_I(inode)->i_ptime_nsec;
 	if (bi_flags & BTRFS_INODE_APPEND)
 		stat->attributes |= STATX_ATTR_APPEND;
 	if (bi_flags & BTRFS_INODE_COMPRESS)
@@ -10779,6 +10802,8 @@ static const struct inode_operations btrfs_special_inode_operations = {
 	.get_inode_acl	= btrfs_get_acl,
 	.set_acl	= btrfs_set_acl,
 	.update_time	= btrfs_update_time,
+	.fileattr_get	= btrfs_fileattr_get,
+	.fileattr_set	= btrfs_fileattr_set,
 };
 static const struct inode_operations btrfs_symlink_inode_operations = {
 	.get_link	= page_get_link,
@@ -10787,6 +10812,8 @@ static const struct inode_operations btrfs_symlink_inode_operations = {
 	.permission	= btrfs_permission,
 	.listxattr	= btrfs_listxattr,
 	.update_time	= btrfs_update_time,
+	.fileattr_get	= btrfs_fileattr_get,
+	.fileattr_set	= btrfs_fileattr_set,
 };
 
 const struct dentry_operations btrfs_dentry_operations = {
fs/btrfs/ioctl.c +23 -1
index 6ba883db107b..f6c5bf9bf217 100644
@@ -270,11 +270,17 @@ static int btrfs_check_ioctl_vol_args2_subvol_name(const struct btrfs_ioctl_vol_
  * Set flags/xflags from the internal inode flags. The remaining items of
  * fsxattr are zeroed.
  */
+#define BTRFS_SUPPORTED_XFLAGS		(FS_XFLAG_PTIME)
+
 int btrfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
 {
 	const struct btrfs_inode *inode = BTRFS_I(d_inode(dentry));
 
 	fileattr_fill_flags(fa, btrfs_inode_flags_to_fsflags(inode));
+	fa->fsx_ptime.tv_sec = inode->i_ptime_sec;
+	fa->fsx_ptime.tv_nsec = inode->i_ptime_nsec;
+	fa->fsx_xflags |= FS_XFLAG_PTIME;
+	fa->fsx_xflags_mask |= FS_XFLAG_PTIME;
 	return 0;
 }
 
@@ -294,9 +300,21 @@ int btrfs_fileattr_set(const struct mnt_idmap *idmap,
 	if (btrfs_root_readonly(root))
 		return -EROFS;
 
-	if (fileattr_has_fsx(fa))
+	/*
+	 * We now support FS_XFLAG_PTIME, so exclude it from the unsupported
+	 * check
+	 */
+	if (fileattr_has_fsx_mask(fa, BTRFS_SUPPORTED_XFLAGS))
+		return -EOPNOTSUPP;
+
+	if (fa->fsx_xflags_mask & ~BTRFS_SUPPORTED_XFLAGS)
 		return -EOPNOTSUPP;
 
+	if (!S_ISREG(inode->vfs_inode.i_mode) && !S_ISDIR(inode->vfs_inode.i_mode)) {
+		if (fa->flags)
+			return -EOPNOTSUPP;
+	}
+
 	fsflags = btrfs_mask_fsflags_for_type(&inode->vfs_inode, fa->flags);
 	old_fsflags = btrfs_inode_flags_to_fsflags(inode);
 	ret = check_fsflags(old_fsflags, fsflags);
@@ -449,6 +467,10 @@ int btrfs_fileattr_set(const struct mnt_idmap *idmap,
 	}
 
 update_flags:
+	if (!fa->flags_valid && (fa->fsx_xflags_mask & FS_XFLAG_PTIME)) {
+		inode->i_ptime_sec = fa->fsx_ptime.tv_sec;
+		inode->i_ptime_nsec = fa->fsx_ptime.tv_nsec;
+	}
 	inode->flags = inode_flags;
 	btrfs_update_inode_mapping_flags(inode);
 	btrfs_sync_inode_flags_to_i_flags(inode);
fs/btrfs/print-tree.c +1 -0
index 53e726119ca7..ba385d0ed9ed 100644
@@ -263,6 +263,7 @@ static void print_inode_item(const struct extent_buffer *eb, int i)
 	print_timespec(eb, &ii->ctime, "\t\tctime ", "\n");
 	print_timespec(eb, &ii->mtime, "\t\tmtime ", "\n");
 	print_timespec(eb, &ii->otime, "\t\totime ", "\n");
+	print_timespec(eb, &ii->ptime, "\t\tptime ", "\n");
 }
 
 static void print_dir_item(const struct extent_buffer *eb, int i)
fs/btrfs/tree-log.c +3 -0
index 1d9dfb63fc5a..72a4a92b40b9 100644
@@ -4631,6 +4631,9 @@ static void fill_inode_item(struct btrfs_trans_handle *trans,
 	btrfs_set_timespec_sec(leaf, &item->otime, inode->i_otime_sec);
 	btrfs_set_timespec_nsec(leaf, &item->otime, inode->i_otime_nsec);
 
+	btrfs_set_timespec_sec(leaf, &item->ptime, inode->i_ptime_sec);
+	btrfs_set_timespec_nsec(leaf, &item->ptime, inode->i_ptime_nsec);
+
 	/*
 	 * We do not need to set the nbytes field, in fact during a fast fsync
 	 * its value may not even be correct, since a fast fsync does not wait
include/uapi/linux/btrfs_tree.h +2 -1
index 47ee52859b45..c360b3e95f45 100644
@@ -900,7 +900,8 @@ struct btrfs_inode_item {
 	 * a little future expansion, for more than this we can
 	 * just grow the inode item and version it
 	 */
-	__le64 reserved[4];
+	__le32 reserved[5];
+	struct btrfs_timespec ptime;
 	struct btrfs_timespec atime;
 	struct btrfs_timespec ctime;
 	struct btrfs_timespec mtime;
Signature · 1 line
2.56.0
author
#12 lore raw

RFC PATCH v4 6/10 vfs: add __vfs_fileattr_set_locked() for inode_lock()'d callers

In reply to koraynilay

Currently there is no way for a caller to invoke vfs_fileattr_set() while holding an inode lock without having the kernel go into deadlock.

Fix this by moving the vfs_fileattr_set() logic into __vfs_fileattr_set_locked() and making vfs_fileattr_set() a simple wrapper that only handles the inode lock.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.7
---
 fs/file_attr.c           | 139 +++++++++++++++++++++++----------------
 include/linux/fileattr.h |   2 +
 2 files changed, 86 insertions(+), 55 deletions(-)
fs/file_attr.c +84 -55
index 12610fb6a751..063c81fbfa6a 100644
@@ -288,6 +288,89 @@ static int fileattr_set_prepare(struct inode *inode,
 	return 0;
 }
 
+/**
+ * __vfs_fileattr_set_locked - change miscellaneous file attributes while
+ * holding the inode lock
+ *
+ * @idmap:	idmap of the mount
+ * @dentry:	the object to change
+ * @fa:		fileattr pointer
+ *
+ * Same as vfs_fileattr_set(), but caller must hold the inode lock.
+ *
+ * Return: 0 on success, or a negative error on failure.
+ */
+int __vfs_fileattr_set_locked(const struct mnt_idmap *idmap, struct dentry *dentry,
+			      struct file_kattr *fa)
+{
+	struct inode *inode = d_inode(dentry);
+	struct file_kattr old_ma = {};
+	int err;
+
+	if (!inode->i_op->fileattr_set)
+		return -ENOIOCTLCMD;
+
+	if (!inode_owner_or_capable(idmap, inode))
+		return -EPERM;
+
+	err = vfs_fileattr_get(dentry, &old_ma);
+	if (err)
+		return err;
+
+	/* initialize missing bits from old_ma */
+	if (fa->flags_valid) {
+		/* 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;
+	}
+
+	err = fileattr_set_prepare(inode, &old_ma, fa);
+	if (err)
+		return err;
+	err = security_inode_file_setattr(dentry, fa);
+	if (err)
+		return err;
+	err = inode->i_op->fileattr_set(idmap, dentry, fa);
+	if (err)
+		return err;
+	fsnotify_xattr(dentry);
+
+	return 0;
+}
+EXPORT_SYMBOL(__vfs_fileattr_set_locked);
+
 /**
  * vfs_fileattr_set - change miscellaneous file attributes
  * @idmap:	idmap of the mount
@@ -308,7 +391,6 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
 		     struct file_kattr *fa)
 {
 	struct inode *inode = d_inode(dentry);
-	struct file_kattr old_ma = {};
 	int err;
 
 	if (!inode->i_op->fileattr_set)
@@ -318,60 +400,7 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
 		return -EPERM;
 
 	inode_lock(inode);
-	err = vfs_fileattr_get(dentry, &old_ma);
-	if (!err) {
-		/* initialize missing bits from old_ma */
-		if (fa->flags_valid) {
-			/* 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;
-		}
-
-		err = fileattr_set_prepare(inode, &old_ma, fa);
-		if (err)
-			goto out;
-		err = security_inode_file_setattr(dentry, fa);
-		if (err)
-			goto out;
-		err = inode->i_op->fileattr_set(idmap, dentry, fa);
-		if (err)
-			goto out;
-		fsnotify_xattr(dentry);
-	}
-
-out:
+	err = __vfs_fileattr_set_locked(idmap, dentry, fa);
 	inode_unlock(inode);
 	return err;
 }
include/linux/fileattr.h +2 -0
index ba7ed3b387d8..7ff62ee27e58 100644
@@ -97,6 +97,8 @@ static inline bool fileattr_has_fsx(const struct file_kattr *fa)
 int vfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
 int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
 		     struct file_kattr *fa);
+int __vfs_fileattr_set_locked(const struct mnt_idmap *idmap, struct dentry *dentry,
+			      struct file_kattr *fa);
 int ioctl_getflags(struct file *file, unsigned int __user *argp);
 int ioctl_setflags(struct file *file, unsigned int __user *argp);
 int ioctl_fsgetxattr(struct file *file, void __user *argp);
Signature · 1 line
2.56.0
#13 lore raw

Re: [RFC PATCH v4 06/10] vfs: add __vfs_fileattr_set_locked() for inode_lock()'d callers

Quoted 184 lines · koraynilay

Currently there is no way for a caller to invoke vfs_fileattr_set() while holding an inode lock without having the kernel go into deadlock.

Fix this by moving the vfs_fileattr_set() logic into __vfs_fileattr_set_locked() and making vfs_fileattr_set() a simple wrapper that only handles the inode lock.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.7
---
 fs/file_attr.c           | 139 +++++++++++++++++++++++----------------
 include/linux/fileattr.h |   2 +
 2 files changed, 86 insertions(+), 55 deletions(-)
fs/file_attr.c +84 -55
index 12610fb6a751..063c81fbfa6a 100644
@@ -288,6 +288,89 @@ static int fileattr_set_prepare(struct inode *inode,
        return 0;
 }
 
+/**
+ * __vfs_fileattr_set_locked - change miscellaneous file attributes while
+ * holding the inode lock
+ *
+ * @idmap:     idmap of the mount
+ * @dentry:    the object to change
+ * @fa:                fileattr pointer
+ *
+ * Same as vfs_fileattr_set(), but caller must hold the inode lock.
+ *
+ * Return: 0 on success, or a negative error on failure.
+ */
+int __vfs_fileattr_set_locked(const struct mnt_idmap *idmap, struct dentry *dentry,
+                             struct file_kattr *fa)
+{
+       struct inode *inode = d_inode(dentry);
+       struct file_kattr old_ma = {};
+       int err;
+
+       if (!inode->i_op->fileattr_set)
+               return -ENOIOCTLCMD;
+
+       if (!inode_owner_or_capable(idmap, inode))
+               return -EPERM;
+
+       err = vfs_fileattr_get(dentry, &old_ma);
+       if (err)
+               return err;
+
+       /* initialize missing bits from old_ma */
+       if (fa->flags_valid) {
+               /* 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;
+       }
+
+       err = fileattr_set_prepare(inode, &old_ma, fa);
+       if (err)
+               return err;
+       err = security_inode_file_setattr(dentry, fa);
+       if (err)
+               return err;
+       err = inode->i_op->fileattr_set(idmap, dentry, fa);
+       if (err)
+               return err;
+       fsnotify_xattr(dentry);
+
+       return 0;
+}
+EXPORT_SYMBOL(__vfs_fileattr_set_locked);
+
 /**
  * vfs_fileattr_set - change miscellaneous file attributes
  * @idmap:     idmap of the mount
@@ -308,7 +391,6 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
                     struct file_kattr *fa)
 {
        struct inode *inode = d_inode(dentry);
-       struct file_kattr old_ma = {};
        int err;
 
        if (!inode->i_op->fileattr_set)
@@ -318,60 +400,7 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
                return -EPERM;
 
        inode_lock(inode);
-       err = vfs_fileattr_get(dentry, &old_ma);
-       if (!err) {
-               /* initialize missing bits from old_ma */
-               if (fa->flags_valid) {
-                       /* 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;
-               }
-
-               err = fileattr_set_prepare(inode, &old_ma, fa);
-               if (err)
-                       goto out;
-               err = security_inode_file_setattr(dentry, fa);
-               if (err)
-                       goto out;
-               err = inode->i_op->fileattr_set(idmap, dentry, fa);
-               if (err)
-                       goto out;
-               fsnotify_xattr(dentry);
-       }
-
-out:
+       err = __vfs_fileattr_set_locked(idmap, dentry, fa);
        inode_unlock(inode);
        return err;
 }
include/linux/fileattr.h +0 -0
index ba7ed3b387d8..7ff62ee27e58 100644

include/linux/fileattr.h static inline bool fileattr_has_fsx(const struct file_kattr *fa) · line 101

Quoted 5 lines
include/linux/fileattr.h +2 -0
@@ -97,6 +97,8 @@ static inline bool fileattr_has_fsx(const struct file_kattr *fa)
 int vfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
 int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
                     struct file_kattr *fa);
+int __vfs_fileattr_set_locked(const struct mnt_idmap *idmap, struct dentry *dentry,
+                             struct file_kattr *fa);

There is no reason for __ prefix here and I think it should be discouraged for global scope if possible.

Thanks,
Amir.

author
#14 lore raw

Re: [RFC PATCH v4 06/10] vfs: add __vfs_fileattr_set_locked() for inode_lock()'d callers

Quoted 185 lines · Amir Goldstein
Quoted 184 lines · koraynilay

Currently there is no way for a caller to invoke vfs_fileattr_set() while holding an inode lock without having the kernel go into deadlock.

Fix this by moving the vfs_fileattr_set() logic into __vfs_fileattr_set_locked() and making vfs_fileattr_set() a simple wrapper that only handles the inode lock.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.7
---
 fs/file_attr.c           | 139 +++++++++++++++++++++++----------------
 include/linux/fileattr.h |   2 +
 2 files changed, 86 insertions(+), 55 deletions(-)
fs/file_attr.c +84 -55
index 12610fb6a751..063c81fbfa6a 100644
@@ -288,6 +288,89 @@ static int fileattr_set_prepare(struct inode *inode,
        return 0;
 }
 
+/**
+ * __vfs_fileattr_set_locked - change miscellaneous file attributes while
+ * holding the inode lock
+ *
+ * @idmap:     idmap of the mount
+ * @dentry:    the object to change
+ * @fa:                fileattr pointer
+ *
+ * Same as vfs_fileattr_set(), but caller must hold the inode lock.
+ *
+ * Return: 0 on success, or a negative error on failure.
+ */
+int __vfs_fileattr_set_locked(const struct mnt_idmap *idmap, struct dentry *dentry,
+                             struct file_kattr *fa)
+{
+       struct inode *inode = d_inode(dentry);
+       struct file_kattr old_ma = {};
+       int err;
+
+       if (!inode->i_op->fileattr_set)
+               return -ENOIOCTLCMD;
+
+       if (!inode_owner_or_capable(idmap, inode))
+               return -EPERM;
+
+       err = vfs_fileattr_get(dentry, &old_ma);
+       if (err)
+               return err;
+
+       /* initialize missing bits from old_ma */
+       if (fa->flags_valid) {
+               /* 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;
+       }
+
+       err = fileattr_set_prepare(inode, &old_ma, fa);
+       if (err)
+               return err;
+       err = security_inode_file_setattr(dentry, fa);
+       if (err)
+               return err;
+       err = inode->i_op->fileattr_set(idmap, dentry, fa);
+       if (err)
+               return err;
+       fsnotify_xattr(dentry);
+
+       return 0;
+}
+EXPORT_SYMBOL(__vfs_fileattr_set_locked);
+
 /**
  * vfs_fileattr_set - change miscellaneous file attributes
  * @idmap:     idmap of the mount
@@ -308,7 +391,6 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
                     struct file_kattr *fa)
 {
        struct inode *inode = d_inode(dentry);
-       struct file_kattr old_ma = {};
        int err;
 
        if (!inode->i_op->fileattr_set)
@@ -318,60 +400,7 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
                return -EPERM;
 
        inode_lock(inode);
-       err = vfs_fileattr_get(dentry, &old_ma);
-       if (!err) {
-               /* initialize missing bits from old_ma */
-               if (fa->flags_valid) {
-                       /* 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;
-               }
-
-               err = fileattr_set_prepare(inode, &old_ma, fa);
-               if (err)
-                       goto out;
-               err = security_inode_file_setattr(dentry, fa);
-               if (err)
-                       goto out;
-               err = inode->i_op->fileattr_set(idmap, dentry, fa);
-               if (err)
-                       goto out;
-               fsnotify_xattr(dentry);
-       }
-
-out:
+       err = __vfs_fileattr_set_locked(idmap, dentry, fa);
        inode_unlock(inode);
        return err;
 }
include/linux/fileattr.h +0 -0
index ba7ed3b387d8..7ff62ee27e58 100644
@@ -97,6 +97,8 @@ static inline bool fileattr_has_fsx(const struct file_kattr *fa)
Quoted 8 lines

include/linux/fileattr.h static inline bool fileattr_has_fsx(const struct file_kattr *fa) · line 101

Quoted 5 lines
include/linux/fileattr.h +2 -0
 int vfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
 int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
                     struct file_kattr *fa);
+int __vfs_fileattr_set_locked(const struct mnt_idmap *idmap, struct dentry *dentry,
+                             struct file_kattr *fa);

There is no reason for __ prefix here and I think it should be discouraged for global scope if possible.

Ah ok, I copied what had been done for __vfs_setxattr_locked() / vfs_setxattr() and __vfs_removexattr_locked() / vfs_removexattr(), but I agree that __ makes it more "internal", I'll change it for v5.

Thanks,
koraynilay

Quoted 2 lines

Thanks,
Amir.

author
#15 lore raw

RFC PATCH v4 7/10 nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE

In reply to koraynilay

Implement provenance time (ptime) in NFSD, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Map ptime to FATTR4_TIME_CREATE, allowing clients to set it across CREATE, OPEN and SETATTR compounds.

If the underlying filesystem supports it, use __vfs_fileattr_set_locked() to set it, returning -EOPNOTSUPP in case it's not supported (i.e. when __vfs_fileattr_set_locked() returns -ENOIOCTLCMD).

When querying FATTR4_TIME_CREATE, request both STATX_PTIME and STATX_BTIME, preferring ptime over btime if available, and advertise FATTR4_TIME_CREATE support if either ptime or btime is available.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.7
---
 fs/nfsd/nfs4proc.c |  9 +++++++++
 fs/nfsd/nfs4xdr.c  | 40 +++++++++++++++++++++++++---------------
 fs/nfsd/vfs.c      | 17 +++++++++++++++++
 fs/nfsd/vfs.h      |  4 +++-
 fs/nfsd/xdr4.h     |  3 +++
 5 files changed, 57 insertions(+), 16 deletions(-)
fs/nfsd/nfs4proc.c +9 -0
index 3a82af381a8d..06074a7f213e 100644
@@ -322,6 +322,9 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
 	__be32 status, create_status;
 	int want_write_err;
 
+	if (open->op_bmval[1] & FATTR4_WORD1_TIME_CREATE)
+		attrs.na_time_create = &open->op_time_create;
+
 	if (name_is_dot_dotdot(open->op_fname, open->op_fnamelen))
 		return nfserr_exist;
 	if (!(iap->ia_valid & ATTR_MODE))
@@ -929,6 +932,9 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	__be32 status;
 	dev_t rdev;
 
+	if (create->cr_bmval[1] & FATTR4_WORD1_TIME_CREATE)
+		attrs.na_time_create = &create->cr_time_create;
+
 	fh_init(&resfh, NFS4_FHSIZE);
 
 	status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_NOP);
@@ -1347,6 +1353,9 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	__be32 status = nfs_ok;
 	int err;
 
+	if (setattr->sa_bmval[1] & FATTR4_WORD1_TIME_CREATE)
+		attrs.na_time_create = &setattr->sa_time_create;
+
 	deleg_attrs = setattr->sa_bmval[2] & (FATTR4_WORD2_TIME_DELEG_ACCESS |
 					      FATTR4_WORD2_TIME_DELEG_MODIFY);
 
fs/nfsd/nfs4xdr.c +25 -15
index 84161dbecd1c..faca3b9b58b8 100644
@@ -509,7 +509,8 @@ static __be32
 nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen,
 		    struct iattr *iattr, struct nfs4_acl **acl,
 		    struct xdr_netobj *label, int *umask,
-		    struct posix_acl **dpaclp, struct posix_acl **paclp)
+		    struct posix_acl **dpaclp, struct posix_acl **paclp,
+		    struct timespec64 *time_create)
 {
 	unsigned int starting_pos;
 	u32 attrlist4_count;
@@ -603,11 +604,10 @@ nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen,
 		}
 	}
 	if (bmval[1] & FATTR4_WORD1_TIME_CREATE) {
-		struct timespec64 ts;
+		if (!time_create)
+			return nfserr_bad_xdr;
 
-		/* No Linux filesystem supports setting this attribute. */
-		bmval[1] &= ~FATTR4_WORD1_TIME_CREATE;
-		status = nfsd4_decode_nfstime4(argp, &ts);
+		status = nfsd4_decode_nfstime4(argp, time_create);
 		if (status)
 			return status;
 	}
@@ -1013,7 +1013,8 @@ nfsd4_decode_create(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
 				    ARRAY_SIZE(create->cr_bmval),
 				    &create->cr_iattr, &create->cr_acl,
 				    &create->cr_label, &create->cr_umask,
-				    &create->cr_dpacl, &create->cr_pacl);
+				    &create->cr_dpacl, &create->cr_pacl,
+				    &create->cr_time_create);
 	if (status)
 		return status;
 
@@ -1165,7 +1166,8 @@ nfsd4_decode_createhow4(struct nfsd4_compoundargs *argp, struct nfsd4_open *open
 					     ARRAY_SIZE(open->op_bmval),
 					     &open->op_iattr, &open->op_acl,
 					     &open->op_label, &open->op_umask,
-					     &open->op_dpacl, &open->op_pacl);
+					     &open->op_dpacl, &open->op_pacl,
+					     &open->op_time_create);
 		if (status)
 			return status;
 		break;
@@ -1184,7 +1186,8 @@ nfsd4_decode_createhow4(struct nfsd4_compoundargs *argp, struct nfsd4_open *open
 					     ARRAY_SIZE(open->op_bmval),
 					     &open->op_iattr, &open->op_acl,
 					     &open->op_label, &open->op_umask,
-					     &open->op_dpacl, &open->op_pacl);
+					     &open->op_dpacl, &open->op_pacl,
+					     &open->op_time_create);
 		if (status)
 			return status;
 		break;
@@ -1512,7 +1515,7 @@ nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, union nfsd4_op_u *u)
 				   ARRAY_SIZE(setattr->sa_bmval),
 				   &setattr->sa_iattr, &setattr->sa_acl,
 				   &setattr->sa_label, NULL, &setattr->sa_dpacl,
-				   &setattr->sa_pacl);
+				   &setattr->sa_pacl, &setattr->sa_time_create);
 }
 
 static __be32
@@ -3646,7 +3649,14 @@ static __be32 nfsd4_encode_fattr4_time_access(struct xdr_stream *xdr,
 static __be32 nfsd4_encode_fattr4_time_create(struct xdr_stream *xdr,
 					      const struct nfsd4_fattr_args *args)
 {
-	return nfsd4_encode_nfstime4(xdr, &args->stat.btime);
+	const struct timespec64 *ts;
+
+	if (args->stat.result_mask & STATX_PTIME)
+		ts = &args->stat.ptime;
+	else
+		ts = &args->stat.btime;
+
+	return nfsd4_encode_nfstime4(xdr, ts);
 }
 
 /*
@@ -4089,8 +4099,8 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,
 	}
 
 	err = vfs_getattr(&path, &args.stat,
-			  STATX_BASIC_STATS | STATX_BTIME | STATX_CHANGE_COOKIE,
-			  AT_STATX_SYNC_AS_STAT);
+			  STATX_BASIC_STATS | STATX_BTIME | STATX_PTIME |
+			  STATX_CHANGE_COOKIE, AT_STATX_SYNC_AS_STAT);
 	if (dp) {
 		struct nfs4_cb_fattr *ncf = &dp->dl_cb_fattr;
 
@@ -4113,8 +4123,8 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,
 	if (err)
 		goto out_nfserr;
 
-	if (!(args.stat.result_mask & STATX_BTIME))
-		/* underlying FS does not offer btime so we can't share it */
+	if (!(args.stat.result_mask & (STATX_BTIME | STATX_PTIME)))
+		/* underlying FS does not offer ptime or btime so we can't share it */
 		attrmask[1] &= ~FATTR4_WORD1_TIME_CREATE;
 	if ((attrmask[0] & (FATTR4_WORD0_FILES_AVAIL | FATTR4_WORD0_FILES_FREE |
 			FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_MAXNAME)) ||
@@ -4434,7 +4444,7 @@ nfsd4_setup_notify_entry4(struct notify_entry4 *ne, struct xdr_stream *xdr,
 		if (!setup_notify_fhandle(dentry, dp, nf, &args))
 			attrmask[0] &= ~FATTR4_WORD0_FILEHANDLE;
 
-		if (!(args.stat.result_mask & STATX_BTIME))
+		if (!(args.stat.result_mask & (STATX_PTIME | STATX_BTIME)))
 			attrmask[1] &= ~FATTR4_WORD1_TIME_CREATE;
 	}
 	attrmask[2] = 0;
fs/nfsd/vfs.c +17 -0
index 56c49b5bc5bb..286ed7c98d91 100644
@@ -621,6 +621,23 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
 	if (attr->na_seclabel && attr->na_seclabel->len)
 		attr->na_labelerr = security_inode_setsecctx(dentry,
 			attr->na_seclabel->data, attr->na_seclabel->len);
+
+	if (attr->na_time_create) {
+		struct file_kattr fa = {
+			.fsx_valid = true,
+			.fsx_xflags = FS_XFLAG_PTIME,
+			.fsx_xflags_mask = FS_XFLAG_PTIME,
+			.fsx_ptime = *attr->na_time_create,
+		};
+
+		host_err = __vfs_fileattr_set_locked(&nop_mnt_idmap, dentry, &fa);
+		if (host_err) {
+			if (host_err == -ENOIOCTLCMD)
+				host_err = -EOPNOTSUPP;
+			goto out_fill_attrs;
+		}
+	}
+
 	if (IS_ENABLED(CONFIG_FS_POSIX_ACL) && attr->na_dpacl) {
 		if (!S_ISDIR(inode->i_mode))
 			attr->na_dpaclerr = -EINVAL;
fs/nfsd/vfs.h +3 -1
index 38f7d36bd4da..24c2c22b3e72 100644
@@ -100,6 +100,7 @@ struct nfsd_attrs {
 	struct xdr_netobj	*na_seclabel;	/* input */
 	struct posix_acl	*na_pacl;	/* input */
 	struct posix_acl	*na_dpacl;	/* input */
+	struct timespec64	*na_time_create; /* input */
 
 	int			na_labelerr;	/* output */
 	int			na_dpaclerr;	/* output */
@@ -118,7 +119,8 @@ static inline bool nfsd_attrs_valid(struct nfsd_attrs *attrs)
 
 	return (iap->ia_valid || (attrs->na_seclabel &&
 		attrs->na_seclabel->len) ||
-		attrs->na_pacl || attrs->na_dpacl);
+		attrs->na_pacl || attrs->na_dpacl ||
+		attrs->na_time_create);
 }
 
 struct nfsd_net;
fs/nfsd/xdr4.h +3 -0
index ec198993429e..a495a20e5889 100644
@@ -123,6 +123,7 @@ struct nfsd4_create {
 	struct posix_acl *cr_dpacl;
 	struct posix_acl *cr_pacl;
 	struct xdr_netobj cr_label;
+	struct timespec64 cr_time_create;
 };
 #define cr_datalen	u.link.datalen
 #define cr_data		u.link.data
@@ -277,6 +278,7 @@ struct nfsd4_open {
 	struct posix_acl *op_dpacl;
 	struct posix_acl *op_pacl;
 	struct xdr_netobj op_label;
+	struct timespec64 op_time_create;
 	struct svc_rqst *op_rqstp;
 };
 
@@ -378,6 +380,7 @@ struct nfsd4_setattr {
 	struct xdr_netobj sa_label;
 	struct posix_acl *sa_dpacl;
 	struct posix_acl *sa_pacl;
+	struct timespec64 sa_time_create;
 };
 
 struct nfsd4_setclientid {
Signature · 1 line
2.56.0
maintainer
#16 lore raw

Re: [RFC PATCH v4 07/10] nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE

Quoted 22 lines · koraynilay

Implement provenance time (ptime) in NFSD, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Map ptime to FATTR4_TIME_CREATE, allowing clients to set it across CREATE, OPEN and SETATTR compounds.

If the underlying filesystem supports it, use __vfs_fileattr_set_locked() to set it, returning -EOPNOTSUPP in case it's not supported (i.e. when __vfs_fileattr_set_locked() returns -ENOIOCTLCMD).

When querying FATTR4_TIME_CREATE, request both STATX_PTIME and STATX_BTIME, preferring ptime over btime if available, and advertise FATTR4_TIME_CREATE support if either ptime or btime is available.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.7
fs/nfsd/nfs4xdr.c +0 -0
@@ -3646,7 +3649,14 @@ static __be32 
 nfsd4_encode_fattr4_time_access(struct xdr_stream *xdr,
 static __be32 nfsd4_encode_fattr4_time_create(struct xdr_stream *xdr,
 					      const struct nfsd4_fattr_args *args)
 {

fs/nfsd/nfs4xdr.c static __be32 · line 3661

Quoted 10 lines
fs/nfsd/nfs4xdr.c +8 -1
-	return nfsd4_encode_nfstime4(xdr, &args->stat.btime);
+	const struct timespec64 *ts;
+
+	if (args->stat.result_mask & STATX_PTIME)
+		ts = &args->stat.ptime;
+	else
+		ts = &args->stat.btime;
+
+	return nfsd4_encode_nfstime4(xdr, ts);
 }

I have trouble with this approach.

We've already established that, for the Linux in-kernel NFS server implementation, FATTR4_TIME_CREATE reports a file's birth time and does not permit NFS clients to modify that.

After this patch is applied, the server reports the ptime instead of the btime on some filesystems but not others.

Essentially this changes the semantics of existing files that have a btime set -- technically that's a regression.

Signature · 1 line
Chuck Lever (Come to NFS bake-a-thon! https://nfsv4bat.org)
author
#17 lore raw

Re: [RFC PATCH v4 07/10] nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE

Hello and thanks for replying,

Quoted 38 lines · Chuck Lever
Quoted 22 lines · koraynilay

Implement provenance time (ptime) in NFSD, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Map ptime to FATTR4_TIME_CREATE, allowing clients to set it across CREATE, OPEN and SETATTR compounds.

If the underlying filesystem supports it, use __vfs_fileattr_set_locked() to set it, returning -EOPNOTSUPP in case it's not supported (i.e. when __vfs_fileattr_set_locked() returns -ENOIOCTLCMD).

When querying FATTR4_TIME_CREATE, request both STATX_PTIME and STATX_BTIME, preferring ptime over btime if available, and advertise FATTR4_TIME_CREATE support if either ptime or btime is available.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.7
fs/nfsd/nfs4xdr.c +0 -0
@@ -3646,7 +3649,14 @@ static __be32 
 nfsd4_encode_fattr4_time_access(struct xdr_stream *xdr,
 static __be32 nfsd4_encode_fattr4_time_create(struct xdr_stream *xdr,
 					      const struct nfsd4_fattr_args *args)
 {

fs/nfsd/nfs4xdr.c static __be32 · line 3661

Quoted 10 lines
fs/nfsd/nfs4xdr.c +8 -1
-	return nfsd4_encode_nfstime4(xdr, &args->stat.btime);
+	const struct timespec64 *ts;
+
+	if (args->stat.result_mask & STATX_PTIME)
+		ts = &args->stat.ptime;
+	else
+		ts = &args->stat.btime;
+
+	return nfsd4_encode_nfstime4(xdr, ts);
 }

I have trouble with this approach.

Quoted 6 lines

We've already established that, for the Linux in-kernel NFS server implementation, FATTR4_TIME_CREATE reports a file's birth time and does not permit NFS clients to modify that.

After this patch is applied, the server reports the ptime instead of the btime on some filesystems but not others.

I implemented it in this way to have a proof-of-concept of how ptime could be use by filesystems that already support settable btime (as was suggested to me in [1]).

There was also a discussion in v3[2] on NFS's FATTR4_TIME_CREATE as an example of such a filesystem

Quoted 2 lines

Essentially this changes the semantics of existing files that have a btime set -- technically that's a regression.

and since the NFS protocol itself states that FATTR4_TIME_CREATE should be user-settable, I think adhering more to it would be better. This would be fine even for already existing files IMO, since btime == ptime if the user doesn't manually change it (or with --preserve=ptime for the various copying tools).

Thanks,
koraynilay

[1]: https://lore.kernel.org/CAOQ4uxiuy0VwZj+3M-zRqQ49WTpHZpiaQ+6MZ8z8WdLjyQM_zA@mail.gmail.com/
[2]: https://lore.kernel.org/20261103094906.n55n5dhrpct5ykmw@pali/

#18 lore raw

Re: [RFC PATCH v4 07/10] nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE

In reply to Chuck Lever
Quoted 39 lines · Chuck Lever
Quoted 22 lines · koraynilay

Implement provenance time (ptime) in NFSD, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Map ptime to FATTR4_TIME_CREATE, allowing clients to set it across CREATE, OPEN and SETATTR compounds.

If the underlying filesystem supports it, use __vfs_fileattr_set_locked() to set it, returning -EOPNOTSUPP in case it's not supported (i.e. when __vfs_fileattr_set_locked() returns -ENOIOCTLCMD).

When querying FATTR4_TIME_CREATE, request both STATX_PTIME and STATX_BTIME, preferring ptime over btime if available, and advertise FATTR4_TIME_CREATE support if either ptime or btime is available.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.7
fs/nfsd/nfs4xdr.c +0 -0
@@ -3646,7 +3649,14 @@ static __be32
 nfsd4_encode_fattr4_time_access(struct xdr_stream *xdr,
 static __be32 nfsd4_encode_fattr4_time_create(struct xdr_stream *xdr,
                                            const struct nfsd4_fattr_args *args)
 {

fs/nfsd/nfs4xdr.c static __be32 · line 3661

Quoted 10 lines
fs/nfsd/nfs4xdr.c +8 -1
-     return nfsd4_encode_nfstime4(xdr, &args->stat.btime);
+     const struct timespec64 *ts;
+
+     if (args->stat.result_mask & STATX_PTIME)
+             ts = &args->stat.ptime;
+     else
+             ts = &args->stat.btime;
+
+     return nfsd4_encode_nfstime4(xdr, ts);
 }

I have trouble with this approach.

Quoted 6 lines

We've already established that, for the Linux in-kernel NFS server implementation, FATTR4_TIME_CREATE reports a file's birth time and does not permit NFS clients to modify that.

After this patch is applied, the server reports the ptime instead of the btime on some filesystems but not others.

In other words, for some server filesystems FATTR4_TIME_CREATE is settable and for others it is not.

Isn't the NFSv4 protocol equipt to deal with this complexity?

Quoted 3 lines

Essentially this changes the semantics of existing files that have a btime set -- technically that's a regression.

I fail to see in what situation this is a regression. Please explain.

The only oddity I can see is that a kernel downgrade could result in an NFS client's view of FATTR4_TIME_CREATE going backward in time to birth time, but I don't think this qualifies as a regression.

Thanks,
Amir.

maintainer
#19 lore raw

Re: [RFC PATCH v4 07/10] nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE

Quoted 44 lines · Amir Goldstein
Quoted 43 lines · Chuck Lever
Quoted 22 lines · koraynilay

Implement provenance time (ptime) in NFSD, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Map ptime to FATTR4_TIME_CREATE, allowing clients to set it across CREATE, OPEN and SETATTR compounds.

If the underlying filesystem supports it, use __vfs_fileattr_set_locked() to set it, returning -EOPNOTSUPP in case it's not supported (i.e. when __vfs_fileattr_set_locked() returns -ENOIOCTLCMD).

When querying FATTR4_TIME_CREATE, request both STATX_PTIME and STATX_BTIME, preferring ptime over btime if available, and advertise FATTR4_TIME_CREATE support if either ptime or btime is available.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.7
fs/nfsd/nfs4xdr.c +0 -0
@@ -3646,7 +3649,14 @@ static __be32
 nfsd4_encode_fattr4_time_access(struct xdr_stream *xdr,
 static __be32 nfsd4_encode_fattr4_time_create(struct xdr_stream *xdr,
                                            const struct nfsd4_fattr_args *args)
 {

fs/nfsd/nfs4xdr.c static __be32 · line 3661

Quoted 10 lines
fs/nfsd/nfs4xdr.c +8 -1
-     return nfsd4_encode_nfstime4(xdr, &args->stat.btime);
+     const struct timespec64 *ts;
+
+     if (args->stat.result_mask & STATX_PTIME)
+             ts = &args->stat.ptime;
+     else
+             ts = &args->stat.btime;
+
+     return nfsd4_encode_nfstime4(xdr, ts);
 }

I have trouble with this approach.

We've already established that, for the Linux in-kernel NFS server implementation, FATTR4_TIME_CREATE reports a file's birth time and does not permit NFS clients to modify that.

Quoted 7 lines
Quoted 2 lines

After this patch is applied, the server reports the ptime instead of the btime on some filesystems but not others.

In other words, for some server filesystems FATTR4_TIME_CREATE is settable and for others it is not.

Isn't the NFSv4 protocol equipt to deal with this complexity?

Not a question of whether NFSv4 _can_ do it. It's whether it _should_ and whether opaquely choosing a settable vs. an immutable timestamp on the server is the right design.

Quoted 4 lines
Quoted 2 lines

Essentially this changes the semantics of existing files that have a btime set -- technically that's a regression.

I fail to see in what situation this is a regression. Please explain.

Any consumer that depends on btime being read-only is now screwed.

Signature · 1 line
Chuck Lever (Come to NFS bake-a-thon! https://nfsv4bat.org)
#20 lore raw

Re: [RFC PATCH v4 07/10] nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE

Quoted 61 lines · Chuck Lever
Quoted 44 lines · Amir Goldstein
Quoted 43 lines · Chuck Lever
Quoted 22 lines · koraynilay

Implement provenance time (ptime) in NFSD, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Map ptime to FATTR4_TIME_CREATE, allowing clients to set it across CREATE, OPEN and SETATTR compounds.

If the underlying filesystem supports it, use __vfs_fileattr_set_locked() to set it, returning -EOPNOTSUPP in case it's not supported (i.e. when __vfs_fileattr_set_locked() returns -ENOIOCTLCMD).

When querying FATTR4_TIME_CREATE, request both STATX_PTIME and STATX_BTIME, preferring ptime over btime if available, and advertise FATTR4_TIME_CREATE support if either ptime or btime is available.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.7
fs/nfsd/nfs4xdr.c +0 -0
@@ -3646,7 +3649,14 @@ static __be32
 nfsd4_encode_fattr4_time_access(struct xdr_stream *xdr,
 static __be32 nfsd4_encode_fattr4_time_create(struct xdr_stream *xdr,
                                            const struct nfsd4_fattr_args *args)
 {

fs/nfsd/nfs4xdr.c static __be32 · line 3661

Quoted 10 lines
fs/nfsd/nfs4xdr.c +8 -1
-     return nfsd4_encode_nfstime4(xdr, &args->stat.btime);
+     const struct timespec64 *ts;
+
+     if (args->stat.result_mask & STATX_PTIME)
+             ts = &args->stat.ptime;
+     else
+             ts = &args->stat.btime;
+
+     return nfsd4_encode_nfstime4(xdr, ts);
 }

I have trouble with this approach.

We've already established that, for the Linux in-kernel NFS server implementation, FATTR4_TIME_CREATE reports a file's birth time and does not permit NFS clients to modify that.

Quoted 7 lines
Quoted 2 lines

After this patch is applied, the server reports the ptime instead of the btime on some filesystems but not others.

In other words, for some server filesystems FATTR4_TIME_CREATE is settable and for others it is not.

Isn't the NFSv4 protocol equipt to deal with this complexity?

Not a question of whether NFSv4 _can_ do it. It's whether it _should_ and whether opaquely choosing a settable vs. an immutable timestamp on the server is the right design.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Essentially this changes the semantics of existing files that have a btime set -- technically that's a regression.

I fail to see in what situation this is a regression. Please explain.

Any consumer that depends on btime being read-only is now screwed.

Who is the consumer in this context?
An NFS client?

Can't an NFS client be connected to another NFS server implementation which does allow this?

I can't wrap my head around the problem.

Thanks,
Amir.

maintainer
#21 lore raw

Re: [RFC PATCH v4 07/10] nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE

Quoted 4 lines · Amir Goldstein

Can't an NFS client be connected to another NFS server implementation which does allow this?

I can't wrap my head around the problem.

You already named the problem in a previous email: What happens when the NFS server's kernel is upgraded from an NFSD that exposes only btime to one that picks either ptime or btime?

Clients will see a file's btime before the server restart, and afterwards, they will see a changed TIME_CREATE but the file's NFSv4 change attribute will be unchanged.

Signature · 1 line
Chuck Lever (Come to NFS bake-a-thon! https://nfsv4bat.org)
author
#22 lore raw

Re: [RFC PATCH v4 07/10] nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE

Quoted 8 lines · Chuck Lever
Quoted 4 lines · Amir Goldstein

Can't an NFS client be connected to another NFS server implementation which does allow this?

I can't wrap my head around the problem.

Quoted 7 lines

You already named the problem in a previous email: What happens when the NFS server's kernel is upgraded from an NFSD that exposes only btime to one that picks either ptime or btime?

Clients will see a file's btime before the server restart, and afterwards, they will see a changed TIME_CREATE but the file's NFSv4 change attribute will be unchanged.

Not really though, newly created files will have btime == ptime, and for older files ptime won't be set until someone sets it.
If the underlying filesystem changes it, then it's the same situation as if someone on the server manually changed a/c/mtime on the underlying filesystem without informing the NFS server.

Although, I'm not sure if my current code in this patch updates iversion on ptime change, if that's the case I'll fix it for v5 since it'd be a bug.

Thanks,
koraynilay

#23 lore raw

Re: [RFC PATCH v4 07/10] nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE

In reply to Chuck Lever
Quoted 9 lines · Chuck Lever
Quoted 4 lines · Amir Goldstein

Can't an NFS client be connected to another NFS server implementation which does allow this?

I can't wrap my head around the problem.

Quoted 9 lines

You already named the problem in a previous email: What happens when the NFS server's kernel is upgraded from an NFSD that exposes only btime to one that picks either ptime or btime?

Clients will see a file's btime before the server restart, and afterwards, they will see a changed TIME_CREATE but the file's NFSv4 change attribute will be unchanged.

Indeed I have.

My newish proposal (on cover letter thread) is that we abolish the ptime/btime duality and make mutability of btime a pre-fs decision which is advertised via the get_fileattr() API. So from the user POV or nfsd POV the values will never diverge.

Thanks,
Amir.

author
#24 lore raw

RFC PATCH v4 8/10 nfs: add provenance time (ptime) via FATTR4_TIME_CREATE

In reply to koraynilay

Implement provenance time (ptime) in the NFS client, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Support reading ptime via statx(2) and file_getattr(), returning the cached creation time when the server advertises NFS_ATTR_FATTR_BTIME.

Implement sending FATTR4_TIME_CREATE, asking the server to persist the file creation time using ptime on the underlying filesystem.

Also add .fileattr_set to struct nfs_rpc_ops and set it to nfs4_fileattr_set() in nfs_v4_clientops. Provide a generic nfs_fileattr_set() dispatcher so even symlinks can update ptime under NFSv4 while cleanly returning -EOPNOTSUPP on NFSv2/v3.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.7
---
 fs/nfs/inode.c          | 27 ++++++++++++++++----
 fs/nfs/internal.h       |  2 ++
 fs/nfs/nfs4proc.c       | 56 ++++++++++++++++++++++++++++++++++++++---
 fs/nfs/nfs4xdr.c        | 19 +++++++++-----
 fs/nfs/symlink.c        |  1 +
 include/linux/nfs_xdr.h |  3 +++
 6 files changed, 93 insertions(+), 15 deletions(-)
fs/nfs/inode.c +22 -5
index e0a2e92952af..2ddcfd872616 100644
@@ -955,7 +955,7 @@ static u32 nfs_get_valid_attrmask(struct inode *inode)
 		reply_mask |= STATX_BLOCKS;
 	if (!(cache_validity & NFS_INO_INVALID_BTIME) &&
 	    (fattr_valid & NFS_ATTR_FATTR_BTIME))
-		reply_mask |= STATX_BTIME;
+		reply_mask |= STATX_BTIME | STATX_PTIME;
 	if (!(cache_validity & NFS_INO_INVALID_CHANGE))
 		reply_mask |= STATX_CHANGE_COOKIE;
 	return reply_mask;
@@ -978,10 +978,10 @@ int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path,
 	request_mask &= STATX_TYPE | STATX_MODE | STATX_NLINK | STATX_UID |
 			STATX_GID | STATX_ATIME | STATX_MTIME | STATX_CTIME |
 			STATX_INO | STATX_SIZE | STATX_BLOCKS | STATX_BTIME |
-			STATX_CHANGE_COOKIE;
+			STATX_PTIME | STATX_CHANGE_COOKIE;
 
 	if (!(fattr_valid & NFS_ATTR_FATTR_BTIME))
-		request_mask &= ~STATX_BTIME;
+		request_mask &= ~(STATX_BTIME | STATX_PTIME);
 
 	if ((query_flags & AT_STATX_DONT_SYNC) && !force_sync) {
 		if (readdirplus_enabled)
@@ -1015,7 +1015,7 @@ int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path,
 	if (!(request_mask & (STATX_MODE|STATX_NLINK|STATX_ATIME|STATX_CTIME|
 					STATX_MTIME|STATX_UID|STATX_GID|
 					STATX_SIZE|STATX_BLOCKS|STATX_BTIME|
-					STATX_CHANGE_COOKIE)))
+					STATX_PTIME|STATX_CHANGE_COOKIE)))
 		goto out_no_revalidate;
 
 	/* Check whether the cached attributes are stale */
@@ -1038,7 +1038,7 @@ int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path,
 		do_update |= cache_validity & NFS_INO_INVALID_OTHER;
 	if (request_mask & STATX_BLOCKS)
 		do_update |= cache_validity & NFS_INO_INVALID_BLOCKS;
-	if (request_mask & STATX_BTIME)
+	if (request_mask & (STATX_BTIME | STATX_PTIME))
 		do_update |= cache_validity & NFS_INO_INVALID_BTIME;
 
 	if (do_update) {
@@ -1061,6 +1061,7 @@ int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path,
 	if (S_ISDIR(inode->i_mode))
 		stat->blksize = NFS_SERVER(inode)->dtsize;
 	stat->btime = NFS_I(inode)->btime;
+	stat->ptime = NFS_I(inode)->btime;
 
 	/* Special handling for STATX_DIOALIGN and STATX_DIO_READ_ALIGN
 	 * - NFS doesn't have DIO alignment constraints, avoid getting
@@ -1092,10 +1093,26 @@ int nfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
 	}
 	if (nfs_server_capable(inode, NFS_CAP_CASE_NONPRESERVING))
 		fa->fsx_xflags |= FS_XFLAG_CASENONPRESERVING;
+	if (NFS_SERVER(inode)->fattr_valid & NFS_ATTR_FATTR_BTIME) {
+		fa->fsx_xflags |= FS_XFLAG_PTIME;
+		fa->fsx_xflags_mask |= FS_XFLAG_PTIME;
+		fa->fsx_ptime = NFS_I(inode)->btime;
+	}
 	return 0;
 }
 EXPORT_SYMBOL_GPL(nfs_fileattr_get);
 
+int nfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
+		     struct file_kattr *fa)
+{
+	const struct nfs_rpc_ops *ops = NFS_PROTO(d_inode(dentry));
+
+	if (ops->fileattr_set)
+		return ops->fileattr_set(idmap, dentry, fa);
+	return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL_GPL(nfs_fileattr_set);
+
 static void nfs_init_lock_context(struct nfs_lock_context *l_ctx)
 {
 	refcount_set(&l_ctx->count, 1);
fs/nfs/internal.h +2 -0
index 5af6a032f145..0e47fad944de 100644
@@ -458,6 +458,8 @@ extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode);
 
 struct file_kattr;
 int nfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
+int nfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
+		     struct file_kattr *fa);
 
 #if IS_ENABLED(CONFIG_NFS_LOCALIO)
 /* localio.c */
fs/nfs/nfs4proc.c +52 -4

122 lines not on this page · raw message

fs/nfs/nfs4xdr.c +13 -6
index 740f3bc4a19d..dc1dff06c5da 100644
@@ -1086,7 +1086,8 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
 				const struct nfs4_label *label,
 				const umode_t *umask,
 				const struct nfs_server *server,
-				const uint32_t attrmask[])
+				const uint32_t attrmask[],
+				const struct timespec64 *time_create)
 {
 	char owner_name[IDMAP_NAMESZ];
 	char owner_group[IDMAP_NAMESZ];
@@ -1147,6 +1148,10 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
 			len += 4;
 		}
 	}
+	if (time_create && (attrmask[1] & FATTR4_WORD1_TIME_CREATE)) {
+		bmval[1] |= FATTR4_WORD1_TIME_CREATE;
+		len += (nfstime4_maxsz << 2);
+	}
 	if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
 		if (iap->ia_valid & ATTR_MTIME_SET) {
 			bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
@@ -1180,6 +1185,8 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
 		} else
 			*p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
 	}
+	if (bmval[1] & FATTR4_WORD1_TIME_CREATE)
+		p = xdr_encode_nfstime4(p, time_create);
 	if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
 		if (iap->ia_valid & ATTR_MTIME_SET) {
 			*p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
@@ -1252,7 +1259,7 @@ static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *
 
 	encode_string(xdr, create->name->len, create->name->name);
 	encode_attrs(xdr, create->attrs, create->label, &create->umask,
-			create->server, create->server->attr_bitmask);
+			create->server, create->server->attr_bitmask, NULL);
 }
 
 static void encode_getattr(struct xdr_stream *xdr,
@@ -1440,12 +1447,12 @@ static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_op
 	case NFS4_CREATE_UNCHECKED:
 		*p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
 		encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
-				arg->server, arg->server->attr_bitmask);
+				arg->server, arg->server->attr_bitmask, NULL);
 		break;
 	case NFS4_CREATE_GUARDED:
 		*p = cpu_to_be32(NFS4_CREATE_GUARDED);
 		encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
-				arg->server, arg->server->attr_bitmask);
+				arg->server, arg->server->attr_bitmask, NULL);
 		break;
 	case NFS4_CREATE_EXCLUSIVE:
 		*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
@@ -1455,7 +1462,7 @@ static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_op
 		*p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
 		encode_nfs4_verifier(xdr, &arg->u.verifier);
 		encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
-				arg->server, arg->server->exclcreat_bitmask);
+				arg->server, arg->server->exclcreat_bitmask, NULL);
 	}
 }
 
@@ -1737,7 +1744,7 @@ static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs
 	encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
 	encode_nfs4_stateid(xdr, &arg->stateid);
 	encode_attrs(xdr, arg->iap, arg->label, NULL, server,
-			server->attr_bitmask);
+			server->attr_bitmask, arg->time_create);
 }
 
 static void encode_delegattr(struct xdr_stream *xdr,
fs/nfs/symlink.c +1 -0
index 74a072896f8d..8f50e56fbda0 100644
@@ -77,4 +77,5 @@ const struct inode_operations nfs_symlink_inode_operations = {
 	.getattr	= nfs_getattr,
 	.setattr	= nfs_setattr,
 	.fileattr_get	= nfs_fileattr_get,
+	.fileattr_set	= nfs_fileattr_set,
 };
include/linux/nfs_xdr.h +3 -0
index c0e29b4dfa62..8576c8d8e840 100644
@@ -833,6 +833,7 @@ struct nfs_setattrargs {
 	const struct nfs_server *	server; /* Needed for name mapping */
 	const u32 *			bitmask;
 	const struct nfs4_label		*label;
+	const struct timespec64		*time_create;
 };
 
 enum nfs4_acl_type {
@@ -1801,6 +1802,8 @@ struct nfs_rpc_ops {
 			    struct nfs_fattr *, struct inode *);
 	int	(*setattr) (struct dentry *, struct nfs_fattr *,
 			    struct iattr *);
+	int	(*fileattr_set)(const struct mnt_idmap *, struct dentry *,
+				struct file_kattr *);
 	int	(*lookup)  (struct inode *, struct dentry *, const struct qstr *,
 			    struct nfs_fh *, struct nfs_fattr *);
 	int	(*lookupp) (struct inode *, struct nfs_fh *,
Signature · 1 line
2.56.0
#25 lore raw

Re: [RFC PATCH v4 08/10] nfs: add provenance time (ptime) via FATTR4_TIME_CREATE

Quoted 71 lines · koraynilay

Implement provenance time (ptime) in the NFS client, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Support reading ptime via statx(2) and file_getattr(), returning the cached creation time when the server advertises NFS_ATTR_FATTR_BTIME.

Implement sending FATTR4_TIME_CREATE, asking the server to persist the file creation time using ptime on the underlying filesystem.

Also add .fileattr_set to struct nfs_rpc_ops and set it to nfs4_fileattr_set() in nfs_v4_clientops. Provide a generic nfs_fileattr_set() dispatcher so even symlinks can update ptime under NFSv4 while cleanly returning -EOPNOTSUPP on NFSv2/v3.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.7
---
 fs/nfs/inode.c          | 27 ++++++++++++++++----
 fs/nfs/internal.h       |  2 ++
 fs/nfs/nfs4proc.c       | 56 ++++++++++++++++++++++++++++++++++++++---
 fs/nfs/nfs4xdr.c        | 19 +++++++++-----
 fs/nfs/symlink.c        |  1 +
 include/linux/nfs_xdr.h |  3 +++
 6 files changed, 93 insertions(+), 15 deletions(-)
fs/nfs/inode.c +5 -5
index e0a2e92952af..2ddcfd872616 100644
@@ -955,7 +955,7 @@ static u32 nfs_get_valid_attrmask(struct inode *inode)
                reply_mask |= STATX_BLOCKS;
        if (!(cache_validity & NFS_INO_INVALID_BTIME) &&
            (fattr_valid & NFS_ATTR_FATTR_BTIME))
-               reply_mask |= STATX_BTIME;
+               reply_mask |= STATX_BTIME | STATX_PTIME;
        if (!(cache_validity & NFS_INO_INVALID_CHANGE))
                reply_mask |= STATX_CHANGE_COOKIE;
        return reply_mask;
@@ -978,10 +978,10 @@ int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path,
        request_mask &= STATX_TYPE | STATX_MODE | STATX_NLINK | STATX_UID |
                        STATX_GID | STATX_ATIME | STATX_MTIME | STATX_CTIME |
                        STATX_INO | STATX_SIZE | STATX_BLOCKS | STATX_BTIME |
-                       STATX_CHANGE_COOKIE;
+                       STATX_PTIME | STATX_CHANGE_COOKIE;
 
        if (!(fattr_valid & NFS_ATTR_FATTR_BTIME))
-               request_mask &= ~STATX_BTIME;
+               request_mask &= ~(STATX_BTIME | STATX_PTIME);
 
        if ((query_flags & AT_STATX_DONT_SYNC) && !force_sync) {
                if (readdirplus_enabled)
@@ -1015,7 +1015,7 @@ int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path,
        if (!(request_mask & (STATX_MODE|STATX_NLINK|STATX_ATIME|STATX_CTIME|
                                        STATX_MTIME|STATX_UID|STATX_GID|
                                        STATX_SIZE|STATX_BLOCKS|STATX_BTIME|
-                                       STATX_CHANGE_COOKIE)))
+                                       STATX_PTIME|STATX_CHANGE_COOKIE)))
                goto out_no_revalidate;
 
        /* Check whether the cached attributes are stale */
@@ -1038,7 +1038,7 @@ int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path,
                do_update |= cache_validity & NFS_INO_INVALID_OTHER;
        if (request_mask & STATX_BLOCKS)
                do_update |= cache_validity & NFS_INO_INVALID_BLOCKS;
-       if (request_mask & STATX_BTIME)
+       if (request_mask & (STATX_BTIME | STATX_PTIME))
                do_update |= cache_validity & NFS_INO_INVALID_BTIME;
 
        if (do_update) {

fs/nfs/inode.c int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path, · line 1065

Quoted 5 lines
fs/nfs/inode.c +1 -0
@@ -1061,6 +1061,7 @@ int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path,
        if (S_ISDIR(inode->i_mode))
                stat->blksize = NFS_SERVER(inode)->dtsize;
        stat->btime = NFS_I(inode)->btime;
+       stat->ptime = NFS_I(inode)->btime;
 

As an example of what would be needed per the mutable btime proposal, adding stat->ptime and STATX_PTIME will not be needed...

fs/nfs/inode.c int nfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa) · line 1095

Quoted 6 lines
fs/nfs/inode.c +0 -0
        /* Special handling for STATX_DIOALIGN and STATX_DIO_READ_ALIGN
         * - NFS doesn't have DIO alignment constraints, avoid getting
@@ -1092,10 +1093,26 @@ int nfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
        }
        if (nfs_server_capable(inode, NFS_CAP_CASE_NONPRESERVING))
                fa->fsx_xflags |= FS_XFLAG_CASENONPRESERVING;

This would need:

                  fa->fsx_xflags |= FS_XFLAG_CASEFOLD;
+                fa->fsx_xflags_mask |= FS_XFLAG_CASEFOLD;
+                fa->fsx_xflags_ro_mask |= FS_XFLAG_CASEFOLD;
+                /* unlink other fs FS_CASEFOLD_FL is read-only */
                  fa->flags |= FS_CASEFOLD_FL;
        }
                   fa->fsx_xflags |= FS_XFLAG_CASENONPRESERVING;

+ fa->fsx_xflags_mask |= FS_XFLAG_CASENONPRESERVING;
+ fa->fsx_xflags_ro_mask |= FS_XFLAG_CASENONPRESERVING;

fs/nfs/inode.c int nfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa) · line 1100

Quoted 5 lines
fs/nfs/inode.c +5 -0
+       if (NFS_SERVER(inode)->fattr_valid & NFS_ATTR_FATTR_BTIME) {
+               fa->fsx_xflags |= FS_XFLAG_PTIME;
+               fa->fsx_xflags_mask |= FS_XFLAG_PTIME;
+               fa->fsx_ptime = NFS_I(inode)->btime;
+       }
+               fa->fsx_xflags |= FS_XFLAG_BTIME;
+               fa->fsx_xflags_mask |= FS_XFLAG_BTIME;
+               fa->fsx_btime = NFS_I(inode)->btime;

Fs with immutable btime could either not advertise the BTIME flag in xflags/xflags_mask or advertise the flag also in xflags_ro_mask.

Quoted 116 lines
fs/nfs/inode.c +11 -0
        return 0;
 }
 EXPORT_SYMBOL_GPL(nfs_fileattr_get);
 
+int nfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
+                    struct file_kattr *fa)
+{
+       const struct nfs_rpc_ops *ops = NFS_PROTO(d_inode(dentry));
+
+       if (ops->fileattr_set)
+               return ops->fileattr_set(idmap, dentry, fa);
+       return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL_GPL(nfs_fileattr_set);
+
 static void nfs_init_lock_context(struct nfs_lock_context *l_ctx)
 {
        refcount_set(&l_ctx->count, 1);
fs/nfs/internal.h +2 -0
index 5af6a032f145..0e47fad944de 100644
@@ -458,6 +458,8 @@ extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode);
 
 struct file_kattr;
 int nfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
+int nfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
+                    struct file_kattr *fa);
 
 #if IS_ENABLED(CONFIG_NFS_LOCALIO)
 /* localio.c */
fs/nfs/nfs4proc.c +24 -4
index e1018b03c1cb..31d58ceb4dc0 100644
@@ -55,6 +55,7 @@
 #include <linux/utsname.h>
 #include <linux/freezer.h>
 #include <linux/iversion.h>
+#include <linux/fileattr.h>
 
 #include "nfs4_fs.h"
 #include "delegation.h"
@@ -98,7 +99,8 @@ static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
                              struct nfs_fattr *fattr, struct inode *inode);
 static int nfs4_do_setattr(struct inode *inode, const struct cred *cred,
                            struct nfs_fattr *fattr, struct iattr *sattr,
-                           struct nfs_open_context *ctx, struct nfs4_label *ilabel);
+                           struct nfs_open_context *ctx, struct nfs4_label *ilabel,
+                           const struct timespec64 *time_create);
 static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp,
                const struct cred *cred,
                struct nfs4_slot *slot,
@@ -3216,7 +3218,7 @@ static int _nfs4_do_open(struct inode *dir,
                        nfs_fattr_init(opendata->o_res.f_attr);
                        status = nfs4_do_setattr(state->inode, cred,
                                        opendata->o_res.f_attr, sattr,
-                                       ctx, label);
+                                       ctx, label, NULL);
                        if (status == 0) {
                                nfs_setattr_update_inode(state->inode, sattr,
                                                opendata->o_res.f_attr);
@@ -3380,7 +3382,8 @@ static int _nfs4_do_setattr(struct inode *inode,
 
 static int nfs4_do_setattr(struct inode *inode, const struct cred *cred,
                           struct nfs_fattr *fattr, struct iattr *sattr,
-                          struct nfs_open_context *ctx, struct nfs4_label *ilabel)
+                          struct nfs_open_context *ctx, struct nfs4_label *ilabel,
+                          const struct timespec64 *time_create)
 {
        struct nfs_server *server = NFS_SERVER(inode);
        __u32 bitmask[NFS4_BITMASK_SZ];
@@ -3391,6 +3394,7 @@ static int nfs4_do_setattr(struct inode *inode, const struct cred *cred,
                .server         = server,
                .bitmask = bitmask,
                .label          = ilabel,
+               .time_create    = time_create,
        };
        struct nfs_setattrres  res = {
                .fattr          = fattr,
@@ -3414,6 +3418,9 @@ static int nfs4_do_setattr(struct inode *inode, const struct cred *cred,
        if (sattr->ia_valid & ATTR_MTIME)
                adjust_flags |= NFS_INO_INVALID_MTIME;
 
+       if (time_create)
+               adjust_flags |= NFS_INO_INVALID_BTIME;
+
        do {
                nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, fattr->label),
                                        inode, adjust_flags);
@@ -4587,7 +4594,7 @@ nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
        if ((sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0)
                nfs4_inode_make_writeable(inode);
 
-       status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL);
+       status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, NULL);
        if (status == 0) {
                nfs_setattr_update_inode(inode, sattr, fattr);
                nfs_setsecurity(inode, fattr);
@@ -10845,6 +10852,44 @@ static void nfs4_disable_swap(struct inode *inode)
        wake_up_var(&clp->cl_state);
 }
 
+#define NFS4_SUPPORTED_XFLAGS  (FS_XFLAG_PTIME)
+static int nfs4_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
+                            struct file_kattr *fa)
+{
+       struct inode *inode = d_inode(dentry);
+       struct nfs_server *server = NFS_SERVER(inode);
+       struct nfs_fattr *fattr;
+       struct iattr sattr = { .ia_valid = 0 };
+       const struct timespec64 *time_create = NULL;
+       int error;
+
+       if (!(server->fattr_valid & NFS_ATTR_FATTR_BTIME))
+               return -EOPNOTSUPP;

fs/nfs/nfs4proc.c static void nfs4_disable_swap(struct inode *inode) · line 10877

Quoted 10 lines
fs/nfs/nfs4proc.c +10 -0
+
+       if (fa->flags_valid)
+               return -EOPNOTSUPP;
+
+       if (fileattr_has_fsx_mask(fa, NFS4_SUPPORTED_XFLAGS))
+               return -EOPNOTSUPP;
+
+       if (fa->fsx_xflags_mask & ~NFS4_SUPPORTED_XFLAGS)
+               return -EOPNOTSUPP;
+

These two checks look semantically identical.
I am not sure yet what you intention was with the fileattr_has_fsx_mask() helper - I know you had reservations about it but at least in this code, it doesn't look like it is needed at all.

fs/nfs/nfs4proc.c static void nfs4_disable_swap(struct inode *inode) · line 10879

Quoted 2 lines
fs/nfs/nfs4proc.c +2 -0
+       if (fa->fsx_xflags_mask & FS_XFLAG_PTIME)
+               time_create = &fa->fsx_ptime;

This would be BTIME/btime but otherwise the same.

Thanks,
Amir.

author
#26 lore raw

Re: [RFC PATCH v4 08/10] nfs: add provenance time (ptime) via FATTR4_TIME_CREATE

Quoted 90 lines · Amir Goldstein
Quoted 71 lines · koraynilay

Implement provenance time (ptime) in the NFS client, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Support reading ptime via statx(2) and file_getattr(), returning the cached creation time when the server advertises NFS_ATTR_FATTR_BTIME.

Implement sending FATTR4_TIME_CREATE, asking the server to persist the file creation time using ptime on the underlying filesystem.

Also add .fileattr_set to struct nfs_rpc_ops and set it to nfs4_fileattr_set() in nfs_v4_clientops. Provide a generic nfs_fileattr_set() dispatcher so even symlinks can update ptime under NFSv4 while cleanly returning -EOPNOTSUPP on NFSv2/v3.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.7
---
 fs/nfs/inode.c          | 27 ++++++++++++++++----
 fs/nfs/internal.h       |  2 ++
 fs/nfs/nfs4proc.c       | 56 ++++++++++++++++++++++++++++++++++++++---
 fs/nfs/nfs4xdr.c        | 19 +++++++++-----
 fs/nfs/symlink.c        |  1 +
 include/linux/nfs_xdr.h |  3 +++
 6 files changed, 93 insertions(+), 15 deletions(-)
fs/nfs/inode.c +5 -5
index e0a2e92952af..2ddcfd872616 100644
@@ -955,7 +955,7 @@ static u32 nfs_get_valid_attrmask(struct inode *inode)
                reply_mask |= STATX_BLOCKS;
        if (!(cache_validity & NFS_INO_INVALID_BTIME) &&
            (fattr_valid & NFS_ATTR_FATTR_BTIME))
-               reply_mask |= STATX_BTIME;
+               reply_mask |= STATX_BTIME | STATX_PTIME;
        if (!(cache_validity & NFS_INO_INVALID_CHANGE))
                reply_mask |= STATX_CHANGE_COOKIE;
        return reply_mask;
@@ -978,10 +978,10 @@ int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path,
        request_mask &= STATX_TYPE | STATX_MODE | STATX_NLINK | STATX_UID |
                        STATX_GID | STATX_ATIME | STATX_MTIME | STATX_CTIME |
                        STATX_INO | STATX_SIZE | STATX_BLOCKS | STATX_BTIME |
-                       STATX_CHANGE_COOKIE;
+                       STATX_PTIME | STATX_CHANGE_COOKIE;
 
        if (!(fattr_valid & NFS_ATTR_FATTR_BTIME))
-               request_mask &= ~STATX_BTIME;
+               request_mask &= ~(STATX_BTIME | STATX_PTIME);
 
        if ((query_flags & AT_STATX_DONT_SYNC) && !force_sync) {
                if (readdirplus_enabled)
@@ -1015,7 +1015,7 @@ int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path,
        if (!(request_mask & (STATX_MODE|STATX_NLINK|STATX_ATIME|STATX_CTIME|
                                        STATX_MTIME|STATX_UID|STATX_GID|
                                        STATX_SIZE|STATX_BLOCKS|STATX_BTIME|
-                                       STATX_CHANGE_COOKIE)))
+                                       STATX_PTIME|STATX_CHANGE_COOKIE)))
                goto out_no_revalidate;
 
        /* Check whether the cached attributes are stale */
@@ -1038,7 +1038,7 @@ int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path,
                do_update |= cache_validity & NFS_INO_INVALID_OTHER;
        if (request_mask & STATX_BLOCKS)
                do_update |= cache_validity & NFS_INO_INVALID_BLOCKS;
-       if (request_mask & STATX_BTIME)
+       if (request_mask & (STATX_BTIME | STATX_PTIME))
                do_update |= cache_validity & NFS_INO_INVALID_BTIME;
 
        if (do_update) {

fs/nfs/inode.c int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path, · line 1065

Quoted 5 lines
fs/nfs/inode.c +1 -0
@@ -1061,6 +1061,7 @@ int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path,
        if (S_ISDIR(inode->i_mode))
                stat->blksize = NFS_SERVER(inode)->dtsize;
        stat->btime = NFS_I(inode)->btime;
+       stat->ptime = NFS_I(inode)->btime;
 

As an example of what would be needed per the mutable btime proposal, adding stat->ptime and STATX_PTIME will not be needed...

fs/nfs/inode.c int nfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa) · line 1095

Quoted 6 lines
fs/nfs/inode.c +0 -0
        /* Special handling for STATX_DIOALIGN and STATX_DIO_READ_ALIGN
         * - NFS doesn't have DIO alignment constraints, avoid getting
@@ -1092,10 +1093,26 @@ int nfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
        }
        if (nfs_server_capable(inode, NFS_CAP_CASE_NONPRESERVING))
                fa->fsx_xflags |= FS_XFLAG_CASENONPRESERVING;

This would need:

                  fa->fsx_xflags |= FS_XFLAG_CASEFOLD;

Review

Quoted 3 lines
(quoted diff) +3 -0
+                fa->fsx_xflags_mask |= FS_XFLAG_CASEFOLD;
+                fa->fsx_xflags_ro_mask |= FS_XFLAG_CASEFOLD;
+                /* unlink other fs FS_CASEFOLD_FL is read-only */

(oh, s/unlink/unlike/?)

Quoted 1 line
                  fa->flags |= FS_CASEFOLD_FL;

With the new API and vfs helpers, this would need to get removed, as vfs would already handle this for legacy ioctls, correct?

Review

Quoted 4 lines
        }
                   fa->fsx_xflags |= FS_XFLAG_CASENONPRESERVING;
(quoted diff) +2 -0
+                 fa->fsx_xflags_mask |= FS_XFLAG_CASENONPRESERVING;
+                 fa->fsx_xflags_ro_mask |= FS_XFLAG_CASENONPRESERVING;

Uhm, why both in _mask and _ro_mask? If it's a RDONLY flag shouldn't it *only* be in _ro_mask? (same for CASEFOLD)

Quoted 11 lines
Quoted 6 lines
fs/nfs/inode.c +5 -0
+       if (NFS_SERVER(inode)->fattr_valid & NFS_ATTR_FATTR_BTIME) {
+               fa->fsx_xflags |= FS_XFLAG_PTIME;
+               fa->fsx_xflags_mask |= FS_XFLAG_PTIME;
+               fa->fsx_ptime = NFS_I(inode)->btime;
+       }
(quoted diff) +3 -0
+               fa->fsx_xflags |= FS_XFLAG_BTIME;
+               fa->fsx_xflags_mask |= FS_XFLAG_BTIME;
+               fa->fsx_btime = NFS_I(inode)->btime;
Quoted 2 lines

Fs with immutable btime could either not advertise the BTIME flag in xflags/xflags_mask or advertise the flag also in xflags_ro_mask.

That makes sense.

Quoted 123 lines
Quoted 123 lines
fs/nfs/inode.c +11 -0
        return 0;
 }
 EXPORT_SYMBOL_GPL(nfs_fileattr_get);
 
+int nfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
+                    struct file_kattr *fa)
+{
+       const struct nfs_rpc_ops *ops = NFS_PROTO(d_inode(dentry));
+
+       if (ops->fileattr_set)
+               return ops->fileattr_set(idmap, dentry, fa);
+       return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL_GPL(nfs_fileattr_set);
+
 static void nfs_init_lock_context(struct nfs_lock_context *l_ctx)
 {
        refcount_set(&l_ctx->count, 1);
fs/nfs/internal.h +2 -0
index 5af6a032f145..0e47fad944de 100644
@@ -458,6 +458,8 @@ extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode);
 
 struct file_kattr;
 int nfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
+int nfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
+                    struct file_kattr *fa);
 
 #if IS_ENABLED(CONFIG_NFS_LOCALIO)
 /* localio.c */
fs/nfs/nfs4proc.c +31 -4
index e1018b03c1cb..31d58ceb4dc0 100644
@@ -55,6 +55,7 @@
 #include <linux/utsname.h>
 #include <linux/freezer.h>
 #include <linux/iversion.h>
+#include <linux/fileattr.h>
 
 #include "nfs4_fs.h"
 #include "delegation.h"
@@ -98,7 +99,8 @@ static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
                              struct nfs_fattr *fattr, struct inode *inode);
 static int nfs4_do_setattr(struct inode *inode, const struct cred *cred,
                            struct nfs_fattr *fattr, struct iattr *sattr,
-                           struct nfs_open_context *ctx, struct nfs4_label *ilabel);
+                           struct nfs_open_context *ctx, struct nfs4_label *ilabel,
+                           const struct timespec64 *time_create);
 static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp,
                const struct cred *cred,
                struct nfs4_slot *slot,
@@ -3216,7 +3218,7 @@ static int _nfs4_do_open(struct inode *dir,
                        nfs_fattr_init(opendata->o_res.f_attr);
                        status = nfs4_do_setattr(state->inode, cred,
                                        opendata->o_res.f_attr, sattr,
-                                       ctx, label);
+                                       ctx, label, NULL);
                        if (status == 0) {
                                nfs_setattr_update_inode(state->inode, sattr,
                                                opendata->o_res.f_attr);
@@ -3380,7 +3382,8 @@ static int _nfs4_do_setattr(struct inode *inode,
 
 static int nfs4_do_setattr(struct inode *inode, const struct cred *cred,
                           struct nfs_fattr *fattr, struct iattr *sattr,
-                          struct nfs_open_context *ctx, struct nfs4_label *ilabel)
+                          struct nfs_open_context *ctx, struct nfs4_label *ilabel,
+                          const struct timespec64 *time_create)
 {
        struct nfs_server *server = NFS_SERVER(inode);
        __u32 bitmask[NFS4_BITMASK_SZ];
@@ -3391,6 +3394,7 @@ static int nfs4_do_setattr(struct inode *inode, const struct cred *cred,
                .server         = server,
                .bitmask = bitmask,
                .label          = ilabel,
+               .time_create    = time_create,
        };
        struct nfs_setattrres  res = {
                .fattr          = fattr,
@@ -3414,6 +3418,9 @@ static int nfs4_do_setattr(struct inode *inode, const struct cred *cred,
        if (sattr->ia_valid & ATTR_MTIME)
                adjust_flags |= NFS_INO_INVALID_MTIME;
 
+       if (time_create)
+               adjust_flags |= NFS_INO_INVALID_BTIME;
+
        do {
                nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, fattr->label),
                                        inode, adjust_flags);
@@ -4587,7 +4594,7 @@ nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
        if ((sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0)
                nfs4_inode_make_writeable(inode);
 
-       status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL);
+       status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, NULL);
        if (status == 0) {
                nfs_setattr_update_inode(inode, sattr, fattr);
                nfs_setsecurity(inode, fattr);
@@ -10845,6 +10852,44 @@ static void nfs4_disable_swap(struct inode *inode)
        wake_up_var(&clp->cl_state);
 }
 
+#define NFS4_SUPPORTED_XFLAGS  (FS_XFLAG_PTIME)
+static int nfs4_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
+                            struct file_kattr *fa)
+{
+       struct inode *inode = d_inode(dentry);
+       struct nfs_server *server = NFS_SERVER(inode);
+       struct nfs_fattr *fattr;
+       struct iattr sattr = { .ia_valid = 0 };
+       const struct timespec64 *time_create = NULL;
+       int error;
+
+       if (!(server->fattr_valid & NFS_ATTR_FATTR_BTIME))
+               return -EOPNOTSUPP;
+
+       if (fa->flags_valid)
+               return -EOPNOTSUPP;
+
+       if (fileattr_has_fsx_mask(fa, NFS4_SUPPORTED_XFLAGS))
+               return -EOPNOTSUPP;
+
Quoted 8 lines

fs/nfs/nfs4proc.c static void nfs4_disable_swap(struct inode *inode) · line 10877

Quoted 3 lines
fs/nfs/nfs4proc.c +3 -0
+       if (fa->fsx_xflags_mask & ~NFS4_SUPPORTED_XFLAGS)
+               return -EOPNOTSUPP;
+

These two checks look semantically identical.
I am not sure yet what you intention was with the fileattr_has_fsx_mask() helper - I know you had reservations about it but at least in this code, it doesn't look like it is needed at all.

Eh, the name is not the best, but they aren't, _mask & check the _mask field, has_fsx_mask checks the xflags field (which is why I added the question of keeping its name as it is or changing it to "fileattr_has_unsupported_fsx").
But I'm not even sure we still need this helper, so I may just drop it.

Thanks,
koraynilay

Quoted 7 lines

fs/nfs/nfs4proc.c static void nfs4_disable_swap(struct inode *inode) · line 10879

Quoted 2 lines
fs/nfs/nfs4proc.c +2 -0
+       if (fa->fsx_xflags_mask & FS_XFLAG_PTIME)
+               time_create = &fa->fsx_ptime;

This would be BTIME/btime but otherwise the same.

Thanks,
Amir.

#27 lore raw

Re: [RFC PATCH v4 08/10] nfs: add provenance time (ptime) via FATTR4_TIME_CREATE

Quoted 95 lines · koraynilay
Quoted 90 lines · Amir Goldstein
Quoted 71 lines · koraynilay

Implement provenance time (ptime) in the NFS client, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Support reading ptime via statx(2) and file_getattr(), returning the cached creation time when the server advertises NFS_ATTR_FATTR_BTIME.

Implement sending FATTR4_TIME_CREATE, asking the server to persist the file creation time using ptime on the underlying filesystem.

Also add .fileattr_set to struct nfs_rpc_ops and set it to nfs4_fileattr_set() in nfs_v4_clientops. Provide a generic nfs_fileattr_set() dispatcher so even symlinks can update ptime under NFSv4 while cleanly returning -EOPNOTSUPP on NFSv2/v3.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.7
---
 fs/nfs/inode.c          | 27 ++++++++++++++++----
 fs/nfs/internal.h       |  2 ++
 fs/nfs/nfs4proc.c       | 56 ++++++++++++++++++++++++++++++++++++++---
 fs/nfs/nfs4xdr.c        | 19 +++++++++-----
 fs/nfs/symlink.c        |  1 +
 include/linux/nfs_xdr.h |  3 +++
 6 files changed, 93 insertions(+), 15 deletions(-)
fs/nfs/inode.c +5 -5
index e0a2e92952af..2ddcfd872616 100644
@@ -955,7 +955,7 @@ static u32 nfs_get_valid_attrmask(struct inode *inode)
                reply_mask |= STATX_BLOCKS;
        if (!(cache_validity & NFS_INO_INVALID_BTIME) &&
            (fattr_valid & NFS_ATTR_FATTR_BTIME))
-               reply_mask |= STATX_BTIME;
+               reply_mask |= STATX_BTIME | STATX_PTIME;
        if (!(cache_validity & NFS_INO_INVALID_CHANGE))
                reply_mask |= STATX_CHANGE_COOKIE;
        return reply_mask;
@@ -978,10 +978,10 @@ int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path,
        request_mask &= STATX_TYPE | STATX_MODE | STATX_NLINK | STATX_UID |
                        STATX_GID | STATX_ATIME | STATX_MTIME | STATX_CTIME |
                        STATX_INO | STATX_SIZE | STATX_BLOCKS | STATX_BTIME |
-                       STATX_CHANGE_COOKIE;
+                       STATX_PTIME | STATX_CHANGE_COOKIE;
 
        if (!(fattr_valid & NFS_ATTR_FATTR_BTIME))
-               request_mask &= ~STATX_BTIME;
+               request_mask &= ~(STATX_BTIME | STATX_PTIME);
 
        if ((query_flags & AT_STATX_DONT_SYNC) && !force_sync) {
                if (readdirplus_enabled)
@@ -1015,7 +1015,7 @@ int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path,
        if (!(request_mask & (STATX_MODE|STATX_NLINK|STATX_ATIME|STATX_CTIME|
                                        STATX_MTIME|STATX_UID|STATX_GID|
                                        STATX_SIZE|STATX_BLOCKS|STATX_BTIME|
-                                       STATX_CHANGE_COOKIE)))
+                                       STATX_PTIME|STATX_CHANGE_COOKIE)))
                goto out_no_revalidate;
 
        /* Check whether the cached attributes are stale */
@@ -1038,7 +1038,7 @@ int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path,
                do_update |= cache_validity & NFS_INO_INVALID_OTHER;
        if (request_mask & STATX_BLOCKS)
                do_update |= cache_validity & NFS_INO_INVALID_BLOCKS;
-       if (request_mask & STATX_BTIME)
+       if (request_mask & (STATX_BTIME | STATX_PTIME))
                do_update |= cache_validity & NFS_INO_INVALID_BTIME;
 
        if (do_update) {

fs/nfs/inode.c int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path, · line 1065

Quoted 5 lines
fs/nfs/inode.c +1 -0
@@ -1061,6 +1061,7 @@ int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path,
        if (S_ISDIR(inode->i_mode))
                stat->blksize = NFS_SERVER(inode)->dtsize;
        stat->btime = NFS_I(inode)->btime;
+       stat->ptime = NFS_I(inode)->btime;
 

As an example of what would be needed per the mutable btime proposal, adding stat->ptime and STATX_PTIME will not be needed...

fs/nfs/inode.c int nfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa) · line 1095

Quoted 6 lines
fs/nfs/inode.c +0 -0
        /* Special handling for STATX_DIOALIGN and STATX_DIO_READ_ALIGN
         * - NFS doesn't have DIO alignment constraints, avoid getting
@@ -1092,10 +1093,26 @@ int nfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
        }
        if (nfs_server_capable(inode, NFS_CAP_CASE_NONPRESERVING))
                fa->fsx_xflags |= FS_XFLAG_CASENONPRESERVING;

This would need:

                  fa->fsx_xflags |= FS_XFLAG_CASEFOLD;

Review

Quoted 3 lines
(quoted diff) +3 -0
+                fa->fsx_xflags_mask |= FS_XFLAG_CASEFOLD;
+                fa->fsx_xflags_ro_mask |= FS_XFLAG_CASEFOLD;
+                /* unlink other fs FS_CASEFOLD_FL is read-only */
Quoted 1 line

(oh, s/unlink/unlike/?)

Yeh :)
It's a comment for you not for the code

Quoted 5 lines
Quoted 2 lines
                  fa->flags |= FS_CASEFOLD_FL;

With the new API and vfs helpers, this would need to get removed, as vfs would already handle this for legacy ioctls, correct?

Quoted 7 lines

Review

Quoted 4 lines
        }
                   fa->fsx_xflags |= FS_XFLAG_CASENONPRESERVING;
(quoted diff) +2 -0
+                 fa->fsx_xflags_mask |= FS_XFLAG_CASENONPRESERVING;
+                 fa->fsx_xflags_ro_mask |= FS_XFLAG_CASENONPRESERVING;

Uhm, why both in _mask and _ro_mask? If it's a RDONLY flag shouldn't it *only* be in _ro_mask? (same for CASEFOLD)

Good question. Maybe
I guess if you want to follow some percent FS_FL_USER_MODIFIABLE is a subset of FS_FL_USER_VISIBLE
but I think that exporting ro_mask and _mask is going to be easier and cleaner than rw_mask but not sure.

Quoted 148 lines
Quoted 11 lines
Quoted 6 lines
fs/nfs/inode.c +5 -0
+       if (NFS_SERVER(inode)->fattr_valid & NFS_ATTR_FATTR_BTIME) {
+               fa->fsx_xflags |= FS_XFLAG_PTIME;
+               fa->fsx_xflags_mask |= FS_XFLAG_PTIME;
+               fa->fsx_ptime = NFS_I(inode)->btime;
+       }
(quoted diff) +3 -0
+               fa->fsx_xflags |= FS_XFLAG_BTIME;
+               fa->fsx_xflags_mask |= FS_XFLAG_BTIME;
+               fa->fsx_btime = NFS_I(inode)->btime;
Quoted 2 lines

Fs with immutable btime could either not advertise the BTIME flag in xflags/xflags_mask or advertise the flag also in xflags_ro_mask.

That makes sense.

Quoted 123 lines
Quoted 123 lines
fs/nfs/inode.c +11 -0
        return 0;
 }
 EXPORT_SYMBOL_GPL(nfs_fileattr_get);
 
+int nfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
+                    struct file_kattr *fa)
+{
+       const struct nfs_rpc_ops *ops = NFS_PROTO(d_inode(dentry));
+
+       if (ops->fileattr_set)
+               return ops->fileattr_set(idmap, dentry, fa);
+       return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL_GPL(nfs_fileattr_set);
+
 static void nfs_init_lock_context(struct nfs_lock_context *l_ctx)
 {
        refcount_set(&l_ctx->count, 1);
fs/nfs/internal.h +2 -0
index 5af6a032f145..0e47fad944de 100644
@@ -458,6 +458,8 @@ extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode);
 
 struct file_kattr;
 int nfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
+int nfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
+                    struct file_kattr *fa);
 
 #if IS_ENABLED(CONFIG_NFS_LOCALIO)
 /* localio.c */
fs/nfs/nfs4proc.c +31 -4
index e1018b03c1cb..31d58ceb4dc0 100644
@@ -55,6 +55,7 @@
 #include <linux/utsname.h>
 #include <linux/freezer.h>
 #include <linux/iversion.h>
+#include <linux/fileattr.h>
 
 #include "nfs4_fs.h"
 #include "delegation.h"
@@ -98,7 +99,8 @@ static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
                              struct nfs_fattr *fattr, struct inode *inode);
 static int nfs4_do_setattr(struct inode *inode, const struct cred *cred,
                            struct nfs_fattr *fattr, struct iattr *sattr,
-                           struct nfs_open_context *ctx, struct nfs4_label *ilabel);
+                           struct nfs_open_context *ctx, struct nfs4_label *ilabel,
+                           const struct timespec64 *time_create);
 static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp,
                const struct cred *cred,
                struct nfs4_slot *slot,
@@ -3216,7 +3218,7 @@ static int _nfs4_do_open(struct inode *dir,
                        nfs_fattr_init(opendata->o_res.f_attr);
                        status = nfs4_do_setattr(state->inode, cred,
                                        opendata->o_res.f_attr, sattr,
-                                       ctx, label);
+                                       ctx, label, NULL);
                        if (status == 0) {
                                nfs_setattr_update_inode(state->inode, sattr,
                                                opendata->o_res.f_attr);
@@ -3380,7 +3382,8 @@ static int _nfs4_do_setattr(struct inode *inode,
 
 static int nfs4_do_setattr(struct inode *inode, const struct cred *cred,
                           struct nfs_fattr *fattr, struct iattr *sattr,
-                          struct nfs_open_context *ctx, struct nfs4_label *ilabel)
+                          struct nfs_open_context *ctx, struct nfs4_label *ilabel,
+                          const struct timespec64 *time_create)
 {
        struct nfs_server *server = NFS_SERVER(inode);
        __u32 bitmask[NFS4_BITMASK_SZ];
@@ -3391,6 +3394,7 @@ static int nfs4_do_setattr(struct inode *inode, const struct cred *cred,
                .server         = server,
                .bitmask = bitmask,
                .label          = ilabel,
+               .time_create    = time_create,
        };
        struct nfs_setattrres  res = {
                .fattr          = fattr,
@@ -3414,6 +3418,9 @@ static int nfs4_do_setattr(struct inode *inode, const struct cred *cred,
        if (sattr->ia_valid & ATTR_MTIME)
                adjust_flags |= NFS_INO_INVALID_MTIME;
 
+       if (time_create)
+               adjust_flags |= NFS_INO_INVALID_BTIME;
+
        do {
                nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, fattr->label),
                                        inode, adjust_flags);
@@ -4587,7 +4594,7 @@ nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
        if ((sattr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0)
                nfs4_inode_make_writeable(inode);
 
-       status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL);
+       status = nfs4_do_setattr(inode, cred, fattr, sattr, ctx, NULL, NULL);
        if (status == 0) {
                nfs_setattr_update_inode(inode, sattr, fattr);
                nfs_setsecurity(inode, fattr);
@@ -10845,6 +10852,44 @@ static void nfs4_disable_swap(struct inode *inode)
        wake_up_var(&clp->cl_state);
 }
 
+#define NFS4_SUPPORTED_XFLAGS  (FS_XFLAG_PTIME)
+static int nfs4_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
+                            struct file_kattr *fa)
+{
+       struct inode *inode = d_inode(dentry);
+       struct nfs_server *server = NFS_SERVER(inode);
+       struct nfs_fattr *fattr;
+       struct iattr sattr = { .ia_valid = 0 };
+       const struct timespec64 *time_create = NULL;
+       int error;
+
+       if (!(server->fattr_valid & NFS_ATTR_FATTR_BTIME))
+               return -EOPNOTSUPP;
+
+       if (fa->flags_valid)
+               return -EOPNOTSUPP;
+
+       if (fileattr_has_fsx_mask(fa, NFS4_SUPPORTED_XFLAGS))
+               return -EOPNOTSUPP;
+
Quoted 8 lines

fs/nfs/nfs4proc.c static void nfs4_disable_swap(struct inode *inode) · line 10877

Quoted 3 lines
fs/nfs/nfs4proc.c +3 -0
+       if (fa->fsx_xflags_mask & ~NFS4_SUPPORTED_XFLAGS)
+               return -EOPNOTSUPP;
+

These two checks look semantically identical.
I am not sure yet what you intention was with the fileattr_has_fsx_mask() helper - I know you had reservations about it but at least in this code, it doesn't look like it is needed at all.

Quoted 6 lines

Eh, the name is not the best, but they aren't, _mask & check the _mask field, has_fsx_mask checks the xflags field (which is why I added the question of keeping its name as it is or changing it to "fileattr_has_unsupported_fsx").
But I'm not even sure we still need this helper, so I may just drop it.

I don't care either way as long as the code reads fine.

Thanks,
Amir.

author
#28 lore raw

Re: [RFC PATCH v4 08/10] nfs: add provenance time (ptime) via FATTR4_TIME_CREATE

Quoted 49 lines · Amir Goldstein
Quoted 30 lines · koraynilay
Quoted 25 lines · Amir Goldstein

fs/nfs/inode.c int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path, · line 1065

Quoted 11 lines · koraynilay

Implement provenance time (ptime) in the NFS client, as introduced in a previous commit ("vfs: add provenance time (ptime)").
[...]

        if (do_update) {
fs/nfs/inode.c +1 -0
@@ -1061,6 +1061,7 @@ int nfs_getattr(const struct mnt_idmap *idmap, const struct path *path,
        if (S_ISDIR(inode->i_mode))
                stat->blksize = NFS_SERVER(inode)->dtsize;
        stat->btime = NFS_I(inode)->btime;
+       stat->ptime = NFS_I(inode)->btime;
 

As an example of what would be needed per the mutable btime proposal, adding stat->ptime and STATX_PTIME will not be needed...

fs/nfs/inode.c int nfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa) · line 1095

Quoted 6 lines
fs/nfs/inode.c +0 -0
        /* Special handling for STATX_DIOALIGN and STATX_DIO_READ_ALIGN
         * - NFS doesn't have DIO alignment constraints, avoid getting
@@ -1092,10 +1093,26 @@ int nfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
        }
        if (nfs_server_capable(inode, NFS_CAP_CASE_NONPRESERVING))
                fa->fsx_xflags |= FS_XFLAG_CASENONPRESERVING;

This would need:

                  fa->fsx_xflags |= FS_XFLAG_CASEFOLD;

Review

Quoted 3 lines
(quoted diff) +3 -0
+                fa->fsx_xflags_mask |= FS_XFLAG_CASEFOLD;
+                fa->fsx_xflags_ro_mask |= FS_XFLAG_CASEFOLD;
+                /* unlink other fs FS_CASEFOLD_FL is read-only */
Quoted 1 line

(oh, s/unlink/unlike/?)

Yeh :)
It's a comment for you not for the code

Quoted 5 lines
Quoted 2 lines
                  fa->flags |= FS_CASEFOLD_FL;

With the new API and vfs helpers, this would need to get removed, as vfs would already handle this for legacy ioctls, correct?

Quoted 7 lines

Review

Quoted 4 lines
        }
                   fa->fsx_xflags |= FS_XFLAG_CASENONPRESERVING;
(quoted diff) +2 -0
+                 fa->fsx_xflags_mask |= FS_XFLAG_CASENONPRESERVING;
+                 fa->fsx_xflags_ro_mask |= FS_XFLAG_CASENONPRESERVING;

Uhm, why both in _mask and _ro_mask? If it's a RDONLY flag shouldn't it *only* be in _ro_mask? (same for CASEFOLD)

Quoted 5 lines

Good question. Maybe
I guess if you want to follow some percent FS_FL_USER_MODIFIABLE is a subset of FS_FL_USER_VISIBLE
but I think that exporting ro_mask and _mask is going to be easier and cleaner than rw_mask but not sure.

Hmm I asked that also because you said in the xfs shared extent thread:

Quoted 4 lines

The advantage being that it makes the interface symmetric. User can alway setattr() with the buffer they got from getattr() and instead of randomly ignoring flags in set, the fsx_ro_mask along with fsx_mask defines the behavior exactly.

But by putting the ro flags in _mask too, a user would have to clean them out or vfs will reject the call with -EINVAL/something else, since in that case the vfs would see the user say "I want to change this [ro] flag".

Quoted 39 lines
Quoted 39 lines
Quoted 10 lines
Quoted 5 lines
fs/nfs/inode.c +5 -0
+       if (NFS_SERVER(inode)->fattr_valid & NFS_ATTR_FATTR_BTIME) {
+               fa->fsx_xflags |= FS_XFLAG_PTIME;
+               fa->fsx_xflags_mask |= FS_XFLAG_PTIME;
+               fa->fsx_ptime = NFS_I(inode)->btime;
+       }
(quoted diff) +3 -0
+               fa->fsx_xflags |= FS_XFLAG_BTIME;
+               fa->fsx_xflags_mask |= FS_XFLAG_BTIME;
+               fa->fsx_btime = NFS_I(inode)->btime;
Quoted 2 lines

Fs with immutable btime could either not advertise the BTIME flag in xflags/xflags_mask or advertise the flag also in xflags_ro_mask.

That makes sense.

Quoted 23 lines
Quoted 8 lines
fs/nfs/nfs4proc.c +3 -0
        return 0;
 }
 EXPORT_SYMBOL_GPL(nfs_fileattr_get);
 
+int nfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
[...]
+       if (!(server->fattr_valid & NFS_ATTR_FATTR_BTIME))
+               return -EOPNOTSUPP;

fs/nfs/nfs4proc.c static void nfs4_disable_swap(struct inode *inode) · line 10877

Quoted 10 lines
fs/nfs/nfs4proc.c +10 -0
+
+       if (fa->flags_valid)
+               return -EOPNOTSUPP;
+
+       if (fileattr_has_fsx_mask(fa, NFS4_SUPPORTED_XFLAGS))
+               return -EOPNOTSUPP;
+
+       if (fa->fsx_xflags_mask & ~NFS4_SUPPORTED_XFLAGS)
+               return -EOPNOTSUPP;
+

These two checks look semantically identical.
I am not sure yet what you intention was with the fileattr_has_fsx_mask() helper - I know you had reservations about it but at least in this code, it doesn't look like it is needed at all.

Quoted 8 lines
Quoted 6 lines

Eh, the name is not the best, but they aren't, _mask & check the _mask field, has_fsx_mask checks the xflags field (which is why I added the question of keeping its name as it is or changing it to "fileattr_has_unsupported_fsx").
But I'm not even sure we still need this helper, so I may just drop it.

I don't care either way as long as the code reads fine.

Fair.

Thanks,
koraynilay

Quoted 2 lines

Thanks,
Amir.

#29 lore raw

Re: [RFC PATCH v4 08/10] nfs: add provenance time (ptime) via FATTR4_TIME_CREATE

Quoted 24 lines · koraynilay
Quoted 9 lines · Amir Goldstein
Quoted 6 lines · koraynilay

Review

Quoted 3 lines
                   fa->fsx_xflags |= FS_XFLAG_CASENONPRESERVING;
(quoted diff) +2 -0
+                 fa->fsx_xflags_mask |= FS_XFLAG_CASENONPRESERVING;
+                 fa->fsx_xflags_ro_mask |= FS_XFLAG_CASENONPRESERVING;

Uhm, why both in _mask and _ro_mask? If it's a RDONLY flag shouldn't it *only* be in _ro_mask? (same for CASEFOLD)

Quoted 5 lines

Good question. Maybe
I guess if you want to follow some percent FS_FL_USER_MODIFIABLE is a subset of FS_FL_USER_VISIBLE
but I think that exporting ro_mask and _mask is going to be easier and cleaner than rw_mask but not sure.

Hmm I asked that also because you said in the xfs shared extent thread:

Quoted 4 lines

The advantage being that it makes the interface symmetric. User can alway setattr() with the buffer they got from getattr() and instead of randomly ignoring flags in set, the fsx_ro_mask along with fsx_mask defines the behavior exactly.

Quoted 5 lines

But by putting the ro flags in _mask too, a user would have to clean them out or vfs will reject the call with -EINVAL/something else, since in that case the vfs would see the user say "I want to change this [ro] flag".

That's just a matter of interpretation.

You could say that if flag FS_XFLAG_CASENONPRESERVING is in ro_mask then its value may not be modified and fs needs to fail the set if the user given value is not a match to the current kernel's value.

Could be used for an "atomic flag set" operation, but I think this is taking this too far.

I am fine with xflags_ro_mask and xflags_rw_mask I guess this is the less ambiguous option.

Thanks,
Amir.

author
#30 lore raw

Re: [RFC PATCH v4 08/10] nfs: add provenance time (ptime) via FATTR4_TIME_CREATE

Quoted 31 lines · Amir Goldstein
Quoted 24 lines · koraynilay
Quoted 9 lines · Amir Goldstein
Quoted 6 lines · koraynilay

Review

Quoted 3 lines
                   fa->fsx_xflags |= FS_XFLAG_CASENONPRESERVING;
(quoted diff) +2 -0
+                 fa->fsx_xflags_mask |= FS_XFLAG_CASENONPRESERVING;
+                 fa->fsx_xflags_ro_mask |= FS_XFLAG_CASENONPRESERVING;

Uhm, why both in _mask and _ro_mask? If it's a RDONLY flag shouldn't it *only* be in _ro_mask? (same for CASEFOLD)

Quoted 5 lines

Good question. Maybe
I guess if you want to follow some percent FS_FL_USER_MODIFIABLE is a subset of FS_FL_USER_VISIBLE
but I think that exporting ro_mask and _mask is going to be easier and cleaner than rw_mask but not sure.

Hmm I asked that also because you said in the xfs shared extent thread:

Quoted 4 lines

The advantage being that it makes the interface symmetric. User can alway setattr() with the buffer they got from getattr() and instead of randomly ignoring flags in set, the fsx_ro_mask along with fsx_mask defines the behavior exactly.

Quoted 5 lines

But by putting the ro flags in _mask too, a user would have to clean them out or vfs will reject the call with -EINVAL/something else, since in that case the vfs would see the user say "I want to change this [ro] flag".

Quoted 5 lines

That's just a matter of interpretation.

You could say that if flag FS_XFLAG_CASENONPRESERVING is in ro_mask then its value may not be modified and fs needs to fail the set

Yes, that's what I was thinking.

Quoted 2 lines

if the user given value is not a match to the current kernel's value.

Since this is a new API, I think it's fine to -EINVAL if it's in _mask anyway, even if the value is the same, no?

Quoted 5 lines

Could be used for an "atomic flag set" operation, but I think this is taking this too far.

I am fine with xflags_ro_mask and xflags_rw_mask I guess this is the less ambiguous option.

Yeah I think this is the better approach here, I'll work using that.

Thanks,
koraynilay

Quoted 2 lines

Thanks,
Amir.

#31 lore raw

Re: [RFC PATCH v4 08/10] nfs: add provenance time (ptime) via FATTR4_TIME_CREATE

Quoted 39 lines · koraynilay
Quoted 31 lines · Amir Goldstein
Quoted 24 lines · koraynilay
Quoted 9 lines · Amir Goldstein
Quoted 6 lines · koraynilay

Review

Quoted 3 lines
                   fa->fsx_xflags |= FS_XFLAG_CASENONPRESERVING;
(quoted diff) +2 -0
+                 fa->fsx_xflags_mask |= FS_XFLAG_CASENONPRESERVING;
+                 fa->fsx_xflags_ro_mask |= FS_XFLAG_CASENONPRESERVING;

Uhm, why both in _mask and _ro_mask? If it's a RDONLY flag shouldn't it *only* be in _ro_mask? (same for CASEFOLD)

Quoted 5 lines

Good question. Maybe
I guess if you want to follow some percent FS_FL_USER_MODIFIABLE is a subset of FS_FL_USER_VISIBLE
but I think that exporting ro_mask and _mask is going to be easier and cleaner than rw_mask but not sure.

Hmm I asked that also because you said in the xfs shared extent thread:

Quoted 4 lines

The advantage being that it makes the interface symmetric. User can alway setattr() with the buffer they got from getattr() and instead of randomly ignoring flags in set, the fsx_ro_mask along with fsx_mask defines the behavior exactly.

Quoted 5 lines

But by putting the ro flags in _mask too, a user would have to clean them out or vfs will reject the call with -EINVAL/something else, since in that case the vfs would see the user say "I want to change this [ro] flag".

Quoted 5 lines

That's just a matter of interpretation.

You could say that if flag FS_XFLAG_CASENONPRESERVING is in ro_mask then its value may not be modified and fs needs to fail the set

Quoted 8 lines

Yes, that's what I was thinking.

Quoted 2 lines

if the user given value is not a match to the current kernel's value.

Since this is a new API, I think it's fine to -EINVAL if it's in _mask anyway, even if the value is the same, no?

The question is only about when a flag is set in _ro_mask and say that it is not in _rw_mask
what do you do with the value of this flag in _xflags?

You can simply ignore it, mask it out as copy_fsxattr_to_user() is doing today and this is probably the right choice.

But you could also take a more conservative approach like ntfs_fileattr_set() in fs/ntfs/file.c:

        /* chattr passes the unchanged read-only flags back to us too. */
        if (NInoCompressed(ni) || NInoWofCompressed(ni))
                readonly |= FS_COMPR_FL;
        if (NInoEncrypted(ni))
                readonly |= FS_ENCRYPT_FL;
        if ((fa->flags ^ readonly) & (FS_COMPR_FL | FS_ENCRYPT_FL))
                return -EOPNOTSUPP;

This is stronger, because userspace can express:
set flag X while making sure the flag Y is not set

in this case xflags = X, xflags_rw_mask = X, xflags_ro_mask = Y

It does not have to mean that Y is a readonly attribute the filesystem itself could set it in rw_mask, but when user puts it in ro_mask its a verification_mask rather than an ignore_mask

In both interpretations (verify/ignore) the sequence:

ret = get_fileattr(&fa)
ret = set_fileattr(&fa)

should work fine most of the time, but if some rdonly flag can flip between the two calls (e.g. FS_XFLAG_PREALLOC) then the set call would fail and this is not the expectation wrt the existing FS_XFLAG_RDONLY_MASK flags.

Thanks,
Amir.

author
#32 lore raw

RFC PATCH v4 9/10 ksmbd: add provenance time (ptime) and map it to CreationTime

In reply to koraynilay

Implement provenance time (ptime) in ksmbd, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Map it to SMB's CreationTime, making it settable by SMB clients. When reporting CreationTime to clients, prioritize ptime over da.create_time memorized in the user.DOSATTRIB xattr.

Update smb2_new_xattrs() and smb2_update_xattrs() to accept a stat argument so they can check whether ptime is supported or already set and behave accordingly. When ptime is natively supported and saved to the filesystem, skip storing da.create_time in user.DOSATTRIB to avoid redundant and desynchronized metadata, while falling back to the xattr for filesystems without ptime.

Finally, add the ksmbd_vfs_set_ptime() helper to persist ptime to the underlying filesystem, if supported.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.7
---
 fs/smb/server/smb2pdu.c | 37 ++++++++++++++++++++++-------------
 fs/smb/server/vfs.c     | 43 +++++++++++++++++++++++++++++++++++++----
 fs/smb/server/vfs.h     |  1 +
 3 files changed, 64 insertions(+), 17 deletions(-)
fs/smb/server/smb2pdu.c +24 -13
index 63dfbffbb575..f389025dc518 100644
@@ -3814,7 +3814,7 @@ static int smb2_create_truncate(const struct path *path)
 }
 
 static void smb2_new_xattrs(struct ksmbd_tree_connect *tcon, const struct path *path,
-			    struct ksmbd_file *fp)
+			    struct ksmbd_file *fp, struct kstat *stat)
 {
 	struct xattr_dos_attrib da = {0};
 	int rc;
@@ -3825,9 +3825,12 @@ static void smb2_new_xattrs(struct ksmbd_tree_connect *tcon, const struct path *
 
 	da.version = 4;
 	da.attr = le32_to_cpu(fp->f_ci->m_fattr);
-	da.itime = da.create_time = fp->create_time;
-	da.flags = XATTR_DOSINFO_ATTRIB | XATTR_DOSINFO_CREATE_TIME |
-		XATTR_DOSINFO_ITIME;
+	da.itime = fp->create_time;
+	da.flags = XATTR_DOSINFO_ATTRIB | XATTR_DOSINFO_ITIME;
+	if (!(stat->result_mask & STATX_PTIME)) {
+		da.create_time = fp->create_time;
+		da.flags |= XATTR_DOSINFO_CREATE_TIME;
+	}
 
 	rc = ksmbd_vfs_set_dos_attrib_xattr(mnt_idmap(path->mnt), path, &da, true);
 	if (rc)
@@ -3859,7 +3862,8 @@ static bool smb2_parent_compressed(struct ksmbd_tree_connect *tcon,
 }
 
 static void smb2_update_xattrs(struct ksmbd_tree_connect *tcon,
-			       const struct path *path, struct ksmbd_file *fp)
+			       const struct path *path, struct ksmbd_file *fp,
+			       struct kstat *stat)
 {
 	struct xattr_dos_attrib da = {};
 	bool store_dos_attrs = test_share_config_flag(tcon->share_conf,
@@ -3879,7 +3883,8 @@ static void smb2_update_xattrs(struct ksmbd_tree_connect *tcon,
 			 * or compression updates. Fall back to using a non-zero stored time
 			 * for backwards compatibility.
 			 */
-			if ((da.flags & XATTR_DOSINFO_CREATE_TIME) || da.create_time > 0)
+			if (!(stat->result_mask & STATX_PTIME) &&
+			    ((da.flags & XATTR_DOSINFO_CREATE_TIME) || da.create_time > 0))
 				fp->create_time = da.create_time;
 			fp->itime = da.itime;
 		} else {
@@ -5505,7 +5510,9 @@ int smb2_open(struct ksmbd_work *work)
 	if (rc)
 		goto err_out1;
 
-	if (stat.result_mask & STATX_BTIME)
+	if (stat.result_mask & STATX_PTIME)
+		fp->create_time = ksmbd_UnixTimeToNT(stat.ptime);
+	else if (stat.result_mask & STATX_BTIME)
 		fp->create_time = ksmbd_UnixTimeToNT(stat.btime);
 	else
 		fp->create_time = ksmbd_UnixTimeToNT(stat.ctime);
@@ -5517,12 +5524,12 @@ int smb2_open(struct ksmbd_work *work)
 			cpu_to_le32(smb2_get_dos_mode(&stat, le32_to_cpu(req->FileAttributes)));
 
 	if (!created)
-		smb2_update_xattrs(tcon, &path, fp);
+		smb2_update_xattrs(tcon, &path, fp, &stat);
 	if (need_truncate && req->FileAttributes) {
 		dos_attr = le32_to_cpu(req->FileAttributes);
 		fp->f_ci->m_fattr =
 			cpu_to_le32(smb2_get_dos_mode(&stat, dos_attr));
-		smb2_new_xattrs(tcon, &path, fp);
+		smb2_new_xattrs(tcon, &path, fp, &stat);
 	}
 
 	ksmbd_vfs_update_compressed_fattr(path.dentry, &fp->f_ci->m_fattr);
@@ -5544,7 +5551,7 @@ int smb2_open(struct ksmbd_work *work)
 	}
 
 	if (created)
-		smb2_new_xattrs(tcon, &path, fp);
+		smb2_new_xattrs(tcon, &path, fp, &stat);
 
 	fp->create_action = cpu_to_le32(file_info);
 
@@ -8995,6 +9002,7 @@ static int set_file_basic_info(struct ksmbd_file *fp,
 	const struct mnt_idmap *idmap;
 	__le32 attrs_mask = FILE_ATTRIBUTE_DIRECTORY_LE |
 		FILE_ATTRIBUTE_COMPRESSED_LE;
+	bool ptime_saved = false;
 	s64 crtime, time;
 	int rc = 0;
 
@@ -9016,8 +9024,11 @@ static int set_file_basic_info(struct ksmbd_file *fp,
 		return rc;
 
 	crtime = (s64)le64_to_cpu(file_info->CreationTime);
-	if (crtime > 0)
+	if (crtime > 0) {
 		fp->create_time = crtime;
+		if (ksmbd_vfs_set_ptime(idmap, filp, crtime) == 0)
+			ptime_saved = true;
+	}
 
 	time = (s64)le64_to_cpu(file_info->LastAccessTime);
 	if (time > 0) {
@@ -9053,7 +9064,7 @@ static int set_file_basic_info(struct ksmbd_file *fp,
 	}
 
 	if (test_share_config_flag(share, KSMBD_SHARE_FLAG_STORE_DOS_ATTRS) &&
-	    (crtime > 0 || file_info->Attributes)) {
+	    ((!ptime_saved && crtime > 0) || file_info->Attributes)) {
 		struct xattr_dos_attrib da = {0};
 
 		rc = ksmbd_vfs_get_dos_attrib_xattr(idmap, fp->filp->f_path.dentry, &da);
@@ -9066,7 +9077,7 @@ static int set_file_basic_info(struct ksmbd_file *fp,
 		 * itime gets preserved when reading the xattr if already present
 		 * otherwise don't write it as it wasn't asked for by the client
 		 */
-		if (crtime > 0) {
+		if (!ptime_saved && crtime > 0) {
 			da.create_time = fp->create_time;
 			da.flags |= XATTR_DOSINFO_CREATE_TIME;
 		} else if (da.create_time > 0) {
fs/smb/server/vfs.c +39 -4

68 lines not on this page · raw message

fs/smb/server/vfs.h +1 -0
index 21b0d29a3db0..5925d63841f2 100644
@@ -187,4 +187,5 @@ int ksmbd_vfs_get_compression(struct ksmbd_file *fp, u16 *fmt);
 int ksmbd_vfs_set_compression(struct ksmbd_work *work, struct ksmbd_file *fp, u16 fmt);
 int ksmbd_vfs_set_compression_create(struct ksmbd_work *work,
 				     struct ksmbd_file *fp, u16 fmt);
+int ksmbd_vfs_set_ptime(const struct mnt_idmap *idmap, struct file *filp, u64 crtime);
 #endif /* __KSMBD_VFS_H__ */
Signature · 1 line
2.56.0
#33 lore raw

Re: [RFC PATCH v4 09/10] ksmbd: add provenance time (ptime) and map it to CreationTime

Quoted 7 lines · koraynilay

Implement provenance time (ptime) in ksmbd, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Map it to SMB's CreationTime, making it settable by SMB clients. When reporting CreationTime to clients, prioritize ptime over da.create_time memorized in the user.DOSATTRIB xattr.

That doesn't sound like the right thing to do.

If the server stored a CreationTime that client had set, you cannot override this.

When the client sets CreationTime, the server can decide if it can and wants (may be a policy decision) to store CreationTime in PTIME and not store it in user.DOSATTRIB.

Fun fact: the user.DOSATTRIB format also has a mask so storing the creation time inside it is also optional.

Thanks,
Amir.

author
#34 lore raw

Re: [RFC PATCH v4 09/10] ksmbd: add provenance time (ptime) and map it to CreationTime

Quoted 5 lines · Amir Goldstein
Quoted 4 lines · koraynilay

Implement provenance time (ptime) in ksmbd, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Quoted 8 lines
Quoted 3 lines

Map it to SMB's CreationTime, making it settable by SMB clients. When reporting CreationTime to clients, prioritize ptime over da.create_time memorized in the user.DOSATTRIB xattr.

That doesn't sound like the right thing to do.

If the server stored a CreationTime that client had set, you cannot override this.

Ah, yes, but how would we handle older files which get a custom CreationTime both before (in the xattr) and after (in ptime) a kernel upgrade?

Quoted 3 lines

When the client sets CreationTime, the server can decide if it can and wants (may be a policy decision) to store CreationTime in PTIME and not store it in user.DOSATTRIB.

To fix the above problem we should probably keep storing it in both ptime and the xattr though.

Quoted 2 lines

Fun fact: the user.DOSATTRIB format also has a mask so storing the creation time inside it is also optional.

With my current patch series applied, when CreationTime gets set by a client, ksmbd writes it to ptime and fixes/heals the xattr (= removing the CREATE_TIME flag created by older kernels, see the other fun fact below).

And another fun fact: until [1] ksmbd ignored the flags and just read/wrote the attribs every time :) so that can only be honored for files that have been written to/updated with newer kernels. (That's why there is the ((flags & CREATE_TIME) || da.create_time > 0) in my patch, and not just the flag check)

Thanks,
koraynilay

[1]: https://lore.kernel.org/linux-cifs/[email protected]/

Quoted 2 lines

Thanks,
Amir.

#35 lore raw

Re: [RFC PATCH v4 09/10] ksmbd: add provenance time (ptime) and map it to CreationTime

Quoted 10 lines · On Thursday 19 November 2026 22:51:26 koraynilay wrote:
Quoted 9 lines · Amir Goldstein
Quoted 7 lines · koraynilay

Implement provenance time (ptime) in ksmbd, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Map it to SMB's CreationTime, making it settable by SMB clients. When reporting CreationTime to clients, prioritize ptime over da.create_time memorized in the user.DOSATTRIB xattr.

Quoted 8 lines
Quoted 4 lines

That doesn't sound like the right thing to do.

If the server stored a CreationTime that client had set, you cannot override this.

Ah, yes, but how would we handle older files which get a custom CreationTime both before (in the xattr) and after (in ptime) a kernel upgrade?

Just to note that this problem is already there. ksmbd can export for example ntfs filesystem on removable disk. And this removable disk can be connected to Windows machine which will always only touch CreationTime and ignores xattr DOSATTRIB.

Quoted 6 lines
Quoted 3 lines

When the client sets CreationTime, the server can decide if it can and wants (may be a policy decision) to store CreationTime in PTIME and not store it in user.DOSATTRIB.

To fix the above problem we should probably keep storing it in both ptime and the xattr though.

IMHO for a long term solution it is better to not have duplicated information in xattr. Because duplicated information are going to be out-of-sync. Windows NTFS driver will not update xattr DOSATTRIB.

For me it looks like that this needs some policy / configuration decision done by user. We do not know if the user will replug that disk also to Windows NTFS driver (and then those xattr DOSATTRIB could cause out-of-sync issues) or will only use it from Linux or Samba and then xattr DOSATTRIB is probably fine.

Quoted 23 lines
Quoted 2 lines

Fun fact: the user.DOSATTRIB format also has a mask so storing the creation time inside it is also optional.

With my current patch series applied, when CreationTime gets set by a client, ksmbd writes it to ptime and fixes/heals the xattr (= removing the CREATE_TIME flag created by older kernels, see the other fun fact below).

And another fun fact: until [1] ksmbd ignored the flags and just read/wrote the attribs every time :) so that can only be honored for files that have been written to/updated with newer kernels. (That's why there is the ((flags & CREATE_TIME) || da.create_time > 0) in my patch, and not just the flag check)

Thanks,
koraynilay

[1]: https://lore.kernel.org/linux-cifs/[email protected]/

Quoted 2 lines

Thanks,
Amir.

author
#36 lore raw

Re: [RFC PATCH v4 09/10] ksmbd: add provenance time (ptime) and map it to CreationTime

Quoted 29 lines · Pali Rohár
Quoted 10 lines · On Thursday 19 November 2026 22:51:26 koraynilay wrote:
Quoted 9 lines · Amir Goldstein
Quoted 7 lines · koraynilay

Implement provenance time (ptime) in ksmbd, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Map it to SMB's CreationTime, making it settable by SMB clients. When reporting CreationTime to clients, prioritize ptime over da.create_time memorized in the user.DOSATTRIB xattr.

Quoted 8 lines
Quoted 4 lines

That doesn't sound like the right thing to do.

If the server stored a CreationTime that client had set, you cannot override this.

Ah, yes, but how would we handle older files which get a custom CreationTime both before (in the xattr) and after (in ptime) a kernel upgrade?

Just to note that this problem is already there. ksmbd can export for example ntfs filesystem on removable disk. And this removable disk can be connected to Windows machine which will always only touch CreationTime and ignores xattr DOSATTRIB.

Quoted 4 lines
Quoted 3 lines

When the client sets CreationTime, the server can decide if it can and wants (may be a policy decision) to store CreationTime in PTIME and not store it in user.DOSATTRIB.

Quoted 6 lines
Quoted 2 lines

To fix the above problem we should probably keep storing it in both ptime and the xattr though.

IMHO for a long term solution it is better to not have duplicated information in xattr. Because duplicated information are going to be out-of-sync. Windows NTFS driver will not update xattr DOSATTRIB.

Yeah, to avoid out-of-sync issues is why I made ksmbd prefer ptime over the xattr's CreationTime.

Quoted 6 lines

For me it looks like that this needs some policy / configuration decision done by user. We do not know if the user will replug that disk also to Windows NTFS driver (and then those xattr DOSATTRIB could cause out-of-sync issues) or will only use it from Linux or Samba and then xattr DOSATTRIB is probably fine.

I'm not sure if this is the best solution, it doesn't feel too right to me, but maybe there isn't a better one.

Thanks,
koraynilay

Quoted 23 lines
Quoted 23 lines
Quoted 2 lines

Fun fact: the user.DOSATTRIB format also has a mask so storing the creation time inside it is also optional.

With my current patch series applied, when CreationTime gets set by a client, ksmbd writes it to ptime and fixes/heals the xattr (= removing the CREATE_TIME flag created by older kernels, see the other fun fact below).

And another fun fact: until [1] ksmbd ignored the flags and just read/wrote the attribs every time :) so that can only be honored for files that have been written to/updated with newer kernels. (That's why there is the ((flags & CREATE_TIME) || da.create_time > 0) in my patch, and not just the flag check)

Thanks,
koraynilay

[1]: https://lore.kernel.org/linux-cifs/[email protected]/

Quoted 2 lines

Thanks,
Amir.

#37 lore raw

Re: [RFC PATCH v4 09/10] ksmbd: add provenance time (ptime) and map it to CreationTime

Quoted 42 lines · koraynilay
Quoted 29 lines · Pali Rohár
Quoted 10 lines · On Thursday 19 November 2026 22:51:26 koraynilay wrote:
Quoted 9 lines · Amir Goldstein
Quoted 7 lines · koraynilay

Implement provenance time (ptime) in ksmbd, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Map it to SMB's CreationTime, making it settable by SMB clients. When reporting CreationTime to clients, prioritize ptime over da.create_time memorized in the user.DOSATTRIB xattr.

Quoted 8 lines
Quoted 4 lines

That doesn't sound like the right thing to do.

If the server stored a CreationTime that client had set, you cannot override this.

Ah, yes, but how would we handle older files which get a custom CreationTime both before (in the xattr) and after (in ptime) a kernel upgrade?

Just to note that this problem is already there. ksmbd can export for example ntfs filesystem on removable disk. And this removable disk can be connected to Windows machine which will always only touch CreationTime and ignores xattr DOSATTRIB.

Quoted 4 lines
Quoted 3 lines

When the client sets CreationTime, the server can decide if it can and wants (may be a policy decision) to store CreationTime in PTIME and not store it in user.DOSATTRIB.

Quoted 6 lines
Quoted 2 lines

To fix the above problem we should probably keep storing it in both ptime and the xattr though.

IMHO for a long term solution it is better to not have duplicated information in xattr. Because duplicated information are going to be out-of-sync. Windows NTFS driver will not update xattr DOSATTRIB.

Yeah, to avoid out-of-sync issues is why I made ksmbd prefer ptime over the xattr's CreationTime.

Quoted 1 line
Quoted 9 lines
Quoted 5 lines

For me it looks like that this needs some policy / configuration decision done by user. We do not know if the user will replug that disk also to Windows NTFS driver (and then those xattr DOSATTRIB could cause out-of-sync issues) or will only use it from Linux or Samba and then xattr DOSATTRIB is probably fine.

I'm not sure if this is the best solution, it doesn't feel too right to me, but maybe there isn't a better one.

If you ask me, this is not your problem and I agree with Pali that this is a policy decision.

I would not include this patch at all in the series if I were you. Maybe as a demo user, but you could just as well include a demo user application.

The nfsd user is a simpler demo, so as long as the nfsd maintainers are on the same page wrt the mutable btime plan, you could include it in your series.

The problem you raise with DOSATTRIB xattr is similar to the problems that Chuck raised for ptime vs. btime as the source of FATTR4_TIME_CREATE

Thanks,
Amir.

author
#38 lore raw

Re: [RFC PATCH v4 09/10] ksmbd: add provenance time (ptime) and map it to CreationTime

Quoted 53 lines · Amir Goldstein
Quoted 42 lines · koraynilay
Quoted 29 lines · Pali Rohár
Quoted 10 lines · On Thursday 19 November 2026 22:51:26 koraynilay wrote:
Quoted 9 lines · Amir Goldstein
Quoted 7 lines · koraynilay

Implement provenance time (ptime) in ksmbd, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Map it to SMB's CreationTime, making it settable by SMB clients. When reporting CreationTime to clients, prioritize ptime over da.create_time memorized in the user.DOSATTRIB xattr.

Quoted 8 lines
Quoted 4 lines

That doesn't sound like the right thing to do.

If the server stored a CreationTime that client had set, you cannot override this.

Ah, yes, but how would we handle older files which get a custom CreationTime both before (in the xattr) and after (in ptime) a kernel upgrade?

Just to note that this problem is already there. ksmbd can export for example ntfs filesystem on removable disk. And this removable disk can be connected to Windows machine which will always only touch CreationTime and ignores xattr DOSATTRIB.

Quoted 4 lines
Quoted 3 lines

When the client sets CreationTime, the server can decide if it can and wants (may be a policy decision) to store CreationTime in PTIME and not store it in user.DOSATTRIB.

Quoted 6 lines
Quoted 2 lines

To fix the above problem we should probably keep storing it in both ptime and the xattr though.

IMHO for a long term solution it is better to not have duplicated information in xattr. Because duplicated information are going to be out-of-sync. Windows NTFS driver will not update xattr DOSATTRIB.

Yeah, to avoid out-of-sync issues is why I made ksmbd prefer ptime over the xattr's CreationTime.

Quoted 1 line
Quoted 9 lines
Quoted 5 lines

For me it looks like that this needs some policy / configuration decision done by user. We do not know if the user will replug that disk also to Windows NTFS driver (and then those xattr DOSATTRIB could cause out-of-sync issues) or will only use it from Linux or Samba and then xattr DOSATTRIB is probably fine.

I'm not sure if this is the best solution, it doesn't feel too right to me, but maybe there isn't a better one.

Quoted 6 lines

If you ask me, this is not your problem and I agree with Pali that this is a policy decision.

I would not include this patch at all in the series if I were you. Maybe as a demo user, but you could just as well include a demo user application.

Ah, ok, fair.

Quoted 6 lines

The nfsd user is a simpler demo, so as long as the nfsd maintainers are on the same page wrt the mutable btime plan, you could include it in your series.

The problem you raise with DOSATTRIB xattr is similar to the problems that Chuck raised for ptime vs. btime as the source of FATTR4_TIME_CREATE

Ah right, I can see the parallel, tho before the ptime change you couldn't modify the creation time at all from linux with nfsd, so in that case unless a user manually changed it after a kernel upgrade, it wouldn't have this desync problem (apart from a kernel downgrade).

Thanks,
koraynilay

Quoted 2 lines

Thanks,
Amir.

author
#39 lore raw

RFC PATCH v4 10/10 cifs: add provenance time (ptime) and map it to SMB's CreationTime

In reply to koraynilay

Implement provenance time (ptime) in cifs, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Map it to SMB's CreationTime, making it settable from userspace and propagating it to the SMB server via FILE_BASIC_INFO.

Support reading ptime via statx(2) and fileattr_get() from the cached CreationTime.

Update cifs_fileattr_set() to check xflags instead of only legacy flags and add the cifs_set_file_crtime() helper to wrap the RPC call to the SMB server.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.7
---
 fs/smb/client/cifsfs.c |   8 +++
 fs/smb/client/inode.c  |   7 ++-
 fs/smb/client/ioctl.c  | 109 ++++++++++++++++++++++++++++++-----------
 3 files changed, 94 insertions(+), 30 deletions(-)
fs/smb/client/cifsfs.c +8 -0
index 8cff7857b450..c2f557e406d3 100644
@@ -1307,6 +1307,14 @@ int cifs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
 	if (READ_ONCE(CIFS_I(inode)->cifsAttrs) & ATTR_COMPRESSED)
 		fa->flags |= FS_COMPR_FL;
 
+	/* Report provenance time (ptime) to userspace */
+	if (CIFS_I(inode)->createtime) {
+		fa->fsx_xflags |= FS_XFLAG_PTIME;
+		fa->fsx_xflags_mask |= FS_XFLAG_PTIME;
+		fa->fsx_ptime =
+		      cifs_NTtimeToUnix(cpu_to_le64(CIFS_I(inode)->createtime));
+	}
+
 	/*
 	 * FS_CASEFOLD_FL is defined by UAPI as a folder attribute,
 	 * and userspace tools (e.g., lsattr) display it only on
fs/smb/client/inode.c +6 -1
index 2647785ec1e4..f0b20a72b9c2 100644
@@ -222,6 +222,7 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr,
 
 	cifs_i->cifsAttrs = fattr->cf_cifsattrs;
 	cifs_i->reparse_tag = fattr->cf_cifstag;
+	cifs_i->createtime = fattr->cf_createtime;
 
 	if (fattr->cf_flags & CIFS_FATTR_NEED_REVAL)
 		cifs_i->time = 0;
@@ -2958,7 +2959,8 @@ int cifs_getattr(const struct mnt_idmap *idmap, const struct path *path,
 	 * We need to be sure that all dirty pages are written and the server
 	 * has actual ctime, mtime and file length.
 	 */
-	if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_SIZE | STATX_BLOCKS)) &&
+	if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_PTIME
+			     | STATX_SIZE | STATX_BLOCKS)) &&
 	    !CIFS_CACHE_READ(CIFS_I(inode)) &&
 	    inode->i_mapping && inode->i_mapping->nrpages != 0) {
 		rc = filemap_fdatawait(inode->i_mapping);
@@ -2992,6 +2994,9 @@ int cifs_getattr(const struct mnt_idmap *idmap, const struct path *path,
 		stat->result_mask |= STATX_BTIME;
 		stat->btime =
 		      cifs_NTtimeToUnix(cpu_to_le64(CIFS_I(inode)->createtime));
+		stat->result_mask |= STATX_PTIME;
+		stat->ptime =
+		      cifs_NTtimeToUnix(cpu_to_le64(CIFS_I(inode)->createtime));
 	}
 
 	stat->attributes_mask |= (STATX_ATTR_COMPRESSED | STATX_ATTR_ENCRYPTED);
fs/smb/client/ioctl.c +80 -29

135 lines not on this page · raw message

Signature · 1 line
2.56.0
#40 lore raw

Re: [RFC PATCH v4 10/10] cifs: add provenance time (ptime) and map it to SMB's CreationTime

Quoted 120 lines · koraynilay

Implement provenance time (ptime) in cifs, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Map it to SMB's CreationTime, making it settable from userspace and propagating it to the SMB server via FILE_BASIC_INFO.

Support reading ptime via statx(2) and fileattr_get() from the cached CreationTime.

Update cifs_fileattr_set() to check xflags instead of only legacy flags and add the cifs_set_file_crtime() helper to wrap the RPC call to the SMB server.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.7
---
 fs/smb/client/cifsfs.c |   8 +++
 fs/smb/client/inode.c  |   7 ++-
 fs/smb/client/ioctl.c  | 109 ++++++++++++++++++++++++++++++-----------
 3 files changed, 94 insertions(+), 30 deletions(-)
fs/smb/client/cifsfs.c +8 -0
index 8cff7857b450..c2f557e406d3 100644
@@ -1307,6 +1307,14 @@ int cifs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
        if (READ_ONCE(CIFS_I(inode)->cifsAttrs) & ATTR_COMPRESSED)
                fa->flags |= FS_COMPR_FL;
 
+       /* Report provenance time (ptime) to userspace */
+       if (CIFS_I(inode)->createtime) {
+               fa->fsx_xflags |= FS_XFLAG_PTIME;
+               fa->fsx_xflags_mask |= FS_XFLAG_PTIME;
+               fa->fsx_ptime =
+                     cifs_NTtimeToUnix(cpu_to_le64(CIFS_I(inode)->createtime));
+       }
+
        /*
         * FS_CASEFOLD_FL is defined by UAPI as a folder attribute,
         * and userspace tools (e.g., lsattr) display it only on
fs/smb/client/inode.c +6 -1
index 2647785ec1e4..f0b20a72b9c2 100644
@@ -222,6 +222,7 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr,
 
        cifs_i->cifsAttrs = fattr->cf_cifsattrs;
        cifs_i->reparse_tag = fattr->cf_cifstag;
+       cifs_i->createtime = fattr->cf_createtime;
 
        if (fattr->cf_flags & CIFS_FATTR_NEED_REVAL)
                cifs_i->time = 0;
@@ -2958,7 +2959,8 @@ int cifs_getattr(const struct mnt_idmap *idmap, const struct path *path,
         * We need to be sure that all dirty pages are written and the server
         * has actual ctime, mtime and file length.
         */
-       if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_SIZE | STATX_BLOCKS)) &&
+       if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_PTIME
+                            | STATX_SIZE | STATX_BLOCKS)) &&
            !CIFS_CACHE_READ(CIFS_I(inode)) &&
            inode->i_mapping && inode->i_mapping->nrpages != 0) {
                rc = filemap_fdatawait(inode->i_mapping);
@@ -2992,6 +2994,9 @@ int cifs_getattr(const struct mnt_idmap *idmap, const struct path *path,
                stat->result_mask |= STATX_BTIME;
                stat->btime =
                      cifs_NTtimeToUnix(cpu_to_le64(CIFS_I(inode)->createtime));
+               stat->result_mask |= STATX_PTIME;
+               stat->ptime =
+                     cifs_NTtimeToUnix(cpu_to_le64(CIFS_I(inode)->createtime));
        }
 
        stat->attributes_mask |= (STATX_ATTR_COMPRESSED | STATX_ATTR_ENCRYPTED);
fs/smb/client/ioctl.c +35 -0
index bb8808289a46..19a9556d39b4 100644
@@ -181,6 +181,41 @@ static int cifs_set_compression(unsigned int xid, struct dentry *dentry,
                                            compression_state);
 }
 
+static int cifs_set_file_crtime(unsigned int xid, struct dentry *dentry,
+                               struct cifs_tcon *tcon, u64 crtime)
+{
+       struct inode *inode = d_inode(dentry);
+       struct TCP_Server_Info *server = tcon->ses->server;
+       FILE_BASIC_INFO info_buf = {};
+       const char *full_path;
+       void *page;
+       int rc;
+
+       if (!server->ops->set_file_info)
+               return -EOPNOTSUPP;
+
+       info_buf.CreationTime = cpu_to_le64(crtime);
+
+       page = alloc_dentry_path();
+       full_path = build_path_from_dentry(dentry, page);
+       if (IS_ERR(full_path)) {
+               rc = PTR_ERR(full_path);
+               goto out;
+       }
+
+       rc = server->ops->set_file_info(inode, full_path, &info_buf, xid);
+       if (rc == 0) {
+               CIFS_I(inode)->createtime = crtime;
+               CIFS_I(inode)->time = 0;
+               inode_set_ctime_current(inode);
+       }
+
+out:
+       free_dentry_path(page);
+       return rc;
+}
+
+#define CIFS_SUPPORTED_XFLAGS (FS_XFLAG_PTIME)
 int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
                      struct file_kattr *fa)
 {

fs/smb/client/ioctl.c int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, · line 234

Quoted 9 lines
fs/smb/client/ioctl.c +2 -2
@@ -193,49 +228,65 @@ int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
        bool enable_compression;
        struct cifs_tcon *tcon;
        unsigned int xid;
-       int rc;
+       int rc = 0;
 
-       if (!fa->flags_valid)
+       if (fileattr_has_fsx_mask(fa, CIFS_SUPPORTED_XFLAGS))
                return -EOPNOTSUPP;

What is this supposed to check that is not already checked explicitly with fsx_xflags_mask below?

Quoted 23 lines
fs/smb/client/ioctl.c +5 -15
-       /*
-        * chattr writes back all flags returned by fileattr_get(). Accept
-        * FS_CASEFOLD_FL only when it reflects the share's casefold state.
-        */
-       if (fa->flags & FS_CASEFOLD_FL) {
-               rc = cifs_fileattr_get(dentry, &current_fa);
-               if (rc)
-                       return rc;
-               if (current_fa.flags & FS_CASEFOLD_FL)
-                       allowed |= FS_CASEFOLD_FL;
-       }
-       if (fa->flags & ~allowed)
+       if (fa->fsx_xflags_mask & ~CIFS_SUPPORTED_XFLAGS)
                return -EOPNOTSUPP;
 
-       enable_compression = fa->flags & FS_COMPR_FL;
-       compression_state = enable_compression ? COMPRESSION_FORMAT_DEFAULT :
-                                                COMPRESSION_FORMAT_NONE;
+       if (fa->flags_valid) {
+               /*
+                * chattr writes back all flags returned by fileattr_get(). Accept
+                * FS_CASEFOLD_FL only when it reflects the share's casefold state.

fs/smb/client/ioctl.c int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, · line 252

Quoted 10 lines
fs/smb/client/ioctl.c +10 -0
+                */
+               if (fa->flags & FS_CASEFOLD_FL) {
+                       rc = cifs_fileattr_get(dentry, &current_fa);
+                       if (rc)
+                               return rc;
+                       if (current_fa.flags & FS_CASEFOLD_FL)
+                               allowed |= FS_CASEFOLD_FL;
+               }
+               if (fa->flags & ~allowed)
+                       return -EOPNOTSUPP;

This whole mess could be sorted out by switching the cifs implementation to the new API and implementing a generic vfs helper which does something like the above code to handle the old ioctls.

FS_XFLAG_CASEFOLD would then be removed from FS_XFLAG_RDONLY_MASK and set explicitly in xflags_ro_mask by fs which don't allow to set if (e.g. nfs) and added to FS_COMMON_FL/FS_XFLAG_COMMON

cifs would advertise FS_XFLAG_CASEFOLD in its ro_mask and then the generic helper would mask it and the new syscall will not allow it.

Quoted 33 lines
fs/smb/client/ioctl.c +15 -11
+       }
 
        tlink = cifs_sb_tlink(cifs_sb);
        if (IS_ERR(tlink))
                return PTR_ERR(tlink);
        tcon = tlink_tcon(tlink);
-
        xid = get_xid();
-       rc = cifs_set_compression(xid, dentry, tcon, NULL, compression_state);
-       free_xid(xid);
-       cifs_put_tlink(tlink);
 
-       if (!rc) {
-               spin_lock(&inode->i_lock);
-               if (enable_compression)
-                       CIFS_I(inode)->cifsAttrs |= FILE_ATTRIBUTE_COMPRESSED;
-               else
-                       CIFS_I(inode)->cifsAttrs &= ~FILE_ATTRIBUTE_COMPRESSED;
-               spin_unlock(&inode->i_lock);
+       /* modern xflags */
+       if (fa->fsx_valid) {
+               if (fa->fsx_xflags_mask & FS_XFLAG_PTIME) {
+                       rc = cifs_set_file_crtime(xid, dentry, tcon,
+                                                 cifs_UnixTimeToNT(fa->fsx_ptime));
+                       if (rc)
+                               goto out;
+               }
+       } else if (fa->flags_valid) { /* legacy flags */
+               enable_compression = fa->flags & FS_COMPR_FL;
+               compression_state = enable_compression ? COMPRESSION_FORMAT_DEFAULT :
+                                                        COMPRESSION_FORMAT_NONE;
+
+               rc = cifs_set_compression(xid, dentry, tcon, NULL, compression_state);

fs/smb/client/ioctl.c int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, · line 284

Quoted 10 lines
fs/smb/client/ioctl.c +10 -0
+
+               if (!rc) {
+                       spin_lock(&inode->i_lock);
+                       if (enable_compression)
+                               CIFS_I(inode)->cifsAttrs |= FILE_ATTRIBUTE_COMPRESSED;
+                       else
+                               CIFS_I(inode)->cifsAttrs &= ~FILE_ATTRIBUTE_COMPRESSED;
+                       spin_unlock(&inode->i_lock);
+               }
+               cifs_dbg(FYI, "set compress flag rc %d\n", rc);

I think that the roadmap should be to slowly define all the old FS_*_FL flags as FS_XFLAGS_* and let the generic helpers deal with the conversion.

No need to do that now, as part of this patch set which is complicated enough, just need to see the road ahead of us that we have a way forward out of this messy flags_valid/fsx_valid inside filesystem implementations.

My understanding is that Miklos introduced those hints to reduce the work needed per filesystem for the initial implementation of the vfs methods.

But it is not so hard to convert one filesystem at a time in a way that fa->fsx_valid will have to be true, because, for example, here all the relevant flags would be supported by the new xflags API.

Thanks,
Amir.

author
#41 lore raw

Re: [RFC PATCH v4 10/10] cifs: add provenance time (ptime) and map it to SMB's CreationTime

Quoted 127 lines · Amir Goldstein
Quoted 126 lines · koraynilay

Implement provenance time (ptime) in cifs, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Map it to SMB's CreationTime, making it settable from userspace and propagating it to the SMB server via FILE_BASIC_INFO.

Support reading ptime via statx(2) and fileattr_get() from the cached CreationTime.

Update cifs_fileattr_set() to check xflags instead of only legacy flags and add the cifs_set_file_crtime() helper to wrap the RPC call to the SMB server.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.7
---
 fs/smb/client/cifsfs.c |   8 +++
 fs/smb/client/inode.c  |   7 ++-
 fs/smb/client/ioctl.c  | 109 ++++++++++++++++++++++++++++++-----------
 3 files changed, 94 insertions(+), 30 deletions(-)
fs/smb/client/cifsfs.c +8 -0
index 8cff7857b450..c2f557e406d3 100644
@@ -1307,6 +1307,14 @@ int cifs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
        if (READ_ONCE(CIFS_I(inode)->cifsAttrs) & ATTR_COMPRESSED)
                fa->flags |= FS_COMPR_FL;
 
+       /* Report provenance time (ptime) to userspace */
+       if (CIFS_I(inode)->createtime) {
+               fa->fsx_xflags |= FS_XFLAG_PTIME;
+               fa->fsx_xflags_mask |= FS_XFLAG_PTIME;
+               fa->fsx_ptime =
+                     cifs_NTtimeToUnix(cpu_to_le64(CIFS_I(inode)->createtime));
+       }
+
        /*
         * FS_CASEFOLD_FL is defined by UAPI as a folder attribute,
         * and userspace tools (e.g., lsattr) display it only on
fs/smb/client/inode.c +6 -1
index 2647785ec1e4..f0b20a72b9c2 100644
@@ -222,6 +222,7 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr,
 
        cifs_i->cifsAttrs = fattr->cf_cifsattrs;
        cifs_i->reparse_tag = fattr->cf_cifstag;
+       cifs_i->createtime = fattr->cf_createtime;
 
        if (fattr->cf_flags & CIFS_FATTR_NEED_REVAL)
                cifs_i->time = 0;
@@ -2958,7 +2959,8 @@ int cifs_getattr(const struct mnt_idmap *idmap, const struct path *path,
         * We need to be sure that all dirty pages are written and the server
         * has actual ctime, mtime and file length.
         */
-       if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_SIZE | STATX_BLOCKS)) &&
+       if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_PTIME
+                            | STATX_SIZE | STATX_BLOCKS)) &&
            !CIFS_CACHE_READ(CIFS_I(inode)) &&
            inode->i_mapping && inode->i_mapping->nrpages != 0) {
                rc = filemap_fdatawait(inode->i_mapping);
@@ -2992,6 +2994,9 @@ int cifs_getattr(const struct mnt_idmap *idmap, const struct path *path,
                stat->result_mask |= STATX_BTIME;
                stat->btime =
                      cifs_NTtimeToUnix(cpu_to_le64(CIFS_I(inode)->createtime));
+               stat->result_mask |= STATX_PTIME;
+               stat->ptime =
+                     cifs_NTtimeToUnix(cpu_to_le64(CIFS_I(inode)->createtime));
        }
 
        stat->attributes_mask |= (STATX_ATTR_COMPRESSED | STATX_ATTR_ENCRYPTED);
fs/smb/client/ioctl.c +36 -1
index bb8808289a46..19a9556d39b4 100644
@@ -181,6 +181,41 @@ static int cifs_set_compression(unsigned int xid, struct dentry *dentry,
                                            compression_state);
 }
 
+static int cifs_set_file_crtime(unsigned int xid, struct dentry *dentry,
+                               struct cifs_tcon *tcon, u64 crtime)
+{
+       struct inode *inode = d_inode(dentry);
+       struct TCP_Server_Info *server = tcon->ses->server;
+       FILE_BASIC_INFO info_buf = {};
+       const char *full_path;
+       void *page;
+       int rc;
+
+       if (!server->ops->set_file_info)
+               return -EOPNOTSUPP;
+
+       info_buf.CreationTime = cpu_to_le64(crtime);
+
+       page = alloc_dentry_path();
+       full_path = build_path_from_dentry(dentry, page);
+       if (IS_ERR(full_path)) {
+               rc = PTR_ERR(full_path);
+               goto out;
+       }
+
+       rc = server->ops->set_file_info(inode, full_path, &info_buf, xid);
+       if (rc == 0) {
+               CIFS_I(inode)->createtime = crtime;
+               CIFS_I(inode)->time = 0;
+               inode_set_ctime_current(inode);
+       }
+
+out:
+       free_dentry_path(page);
+       return rc;
+}
+
+#define CIFS_SUPPORTED_XFLAGS (FS_XFLAG_PTIME)
 int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
                      struct file_kattr *fa)
 {
@@ -193,49 +228,65 @@ int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
        bool enable_compression;
        struct cifs_tcon *tcon;
        unsigned int xid;
-       int rc;
+       int rc = 0;
 
Quoted 6 lines

fs/smb/client/ioctl.c int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, · line 234

Quoted 3 lines
fs/smb/client/ioctl.c +1 -1
-       if (!fa->flags_valid)
+       if (fileattr_has_fsx_mask(fa, CIFS_SUPPORTED_XFLAGS))
                return -EOPNOTSUPP;

What is this supposed to check that is not already checked explicitly with fsx_xflags_mask below?

It should work for FS_IOC_FSSETXATTR, where mask is 0... but it's also there because when I started writing the various filesystems code I hadn't added _mask yet, so I'll need to take a little step back and revisit.

Quoted 34 lines
Quoted 23 lines
fs/smb/client/ioctl.c +5 -15
-       /*
-        * chattr writes back all flags returned by fileattr_get(). Accept
-        * FS_CASEFOLD_FL only when it reflects the share's casefold state.
-        */
-       if (fa->flags & FS_CASEFOLD_FL) {
-               rc = cifs_fileattr_get(dentry, &current_fa);
-               if (rc)
-                       return rc;
-               if (current_fa.flags & FS_CASEFOLD_FL)
-                       allowed |= FS_CASEFOLD_FL;
-       }
-       if (fa->flags & ~allowed)
+       if (fa->fsx_xflags_mask & ~CIFS_SUPPORTED_XFLAGS)
                return -EOPNOTSUPP;
 
-       enable_compression = fa->flags & FS_COMPR_FL;
-       compression_state = enable_compression ? COMPRESSION_FORMAT_DEFAULT :
-                                                COMPRESSION_FORMAT_NONE;
+       if (fa->flags_valid) {
+               /*
+                * chattr writes back all flags returned by fileattr_get(). Accept
+                * FS_CASEFOLD_FL only when it reflects the share's casefold state.

fs/smb/client/ioctl.c int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, · line 252

Quoted 10 lines
fs/smb/client/ioctl.c +10 -0
+                */
+               if (fa->flags & FS_CASEFOLD_FL) {
+                       rc = cifs_fileattr_get(dentry, &current_fa);
+                       if (rc)
+                               return rc;
+                       if (current_fa.flags & FS_CASEFOLD_FL)
+                               allowed |= FS_CASEFOLD_FL;
+               }
+               if (fa->flags & ~allowed)
+                       return -EOPNOTSUPP;
Quoted 2 lines

This whole mess could be sorted out by switching the cifs implementation to the new API

("new API" you mean _mask right?)

Quoted 16 lines

and implementing a generic vfs
helper which does something like the above code to handle the old ioctls.
FS_XFLAG_CASEFOLD would then be removed from FS_XFLAG_RDONLY_MASK and set explicitly in xflags_ro_mask by fs which don't allow to set if (e.g. nfs) and added to FS_COMMON_FL/FS_XFLAG_COMMON

cifs would advertise FS_XFLAG_CASEFOLD in its ro_mask and then the generic helper would mask it and the new syscall will not allow it.

fs/smb/client/ioctl.c int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,

Quoted 3 lines
fs/smb/client/ioctl.c +2 -0
+       }
[...]
+               cifs_dbg(FYI, "set compress flag rc %d\n", rc);
Quoted 6 lines

I think that the roadmap should be to slowly define all the old FS_*_FL flags as FS_XFLAGS_* and let the generic helpers deal with the conversion.

But it is not so hard to convert one filesystem at a time in a way that fa->fsx_valid will have to be true, because, for example, here all the relevant flags would be supported by the new xflags API.

So, something like what fileattr_fill_{x,}flags() do now, but for file_attr_to_fileattr()?

Quoted 4 lines

No need to do that now, as part of this patch set which is complicated enough, just need to see the road ahead of us that we have a way forward out of this messy flags_valid/fsx_valid inside filesystem implementations.

I think it's probably better to clean up the API now, before introducing new flags (like FS_XFLAG_BTIME/PTIME or the shared extent one in the other thread) and as I'll say in that reply (I'll write it in a bit) I think it's even better to first split the _mask changes into their own RFC PATCH series, then have a separate one for ptime/btime.

Quoted 3 lines

My understanding is that Miklos introduced those hints to reduce the work needed per filesystem for the initial implementation of the vfs methods.

Ah yeah that would make sense.

Thanks,
koraynilay

Quoted 2 lines

Thanks,
Amir.

#42 lore raw

Re: [RFC PATCH v4 10/10] cifs: add provenance time (ptime) and map it to SMB's CreationTime

Quoted 136 lines · koraynilay
Quoted 127 lines · Amir Goldstein
Quoted 126 lines · koraynilay

Implement provenance time (ptime) in cifs, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Map it to SMB's CreationTime, making it settable from userspace and propagating it to the SMB server via FILE_BASIC_INFO.

Support reading ptime via statx(2) and fileattr_get() from the cached CreationTime.

Update cifs_fileattr_set() to check xflags instead of only legacy flags and add the cifs_set_file_crtime() helper to wrap the RPC call to the SMB server.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.7
---
 fs/smb/client/cifsfs.c |   8 +++
 fs/smb/client/inode.c  |   7 ++-
 fs/smb/client/ioctl.c  | 109 ++++++++++++++++++++++++++++++-----------
 3 files changed, 94 insertions(+), 30 deletions(-)
fs/smb/client/cifsfs.c +8 -0
index 8cff7857b450..c2f557e406d3 100644
@@ -1307,6 +1307,14 @@ int cifs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
        if (READ_ONCE(CIFS_I(inode)->cifsAttrs) & ATTR_COMPRESSED)
                fa->flags |= FS_COMPR_FL;
 
+       /* Report provenance time (ptime) to userspace */
+       if (CIFS_I(inode)->createtime) {
+               fa->fsx_xflags |= FS_XFLAG_PTIME;
+               fa->fsx_xflags_mask |= FS_XFLAG_PTIME;
+               fa->fsx_ptime =
+                     cifs_NTtimeToUnix(cpu_to_le64(CIFS_I(inode)->createtime));
+       }
+
        /*
         * FS_CASEFOLD_FL is defined by UAPI as a folder attribute,
         * and userspace tools (e.g., lsattr) display it only on
fs/smb/client/inode.c +6 -1
index 2647785ec1e4..f0b20a72b9c2 100644
@@ -222,6 +222,7 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr,
 
        cifs_i->cifsAttrs = fattr->cf_cifsattrs;
        cifs_i->reparse_tag = fattr->cf_cifstag;
+       cifs_i->createtime = fattr->cf_createtime;
 
        if (fattr->cf_flags & CIFS_FATTR_NEED_REVAL)
                cifs_i->time = 0;
@@ -2958,7 +2959,8 @@ int cifs_getattr(const struct mnt_idmap *idmap, const struct path *path,
         * We need to be sure that all dirty pages are written and the server
         * has actual ctime, mtime and file length.
         */
-       if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_SIZE | STATX_BLOCKS)) &&
+       if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_PTIME
+                            | STATX_SIZE | STATX_BLOCKS)) &&
            !CIFS_CACHE_READ(CIFS_I(inode)) &&
            inode->i_mapping && inode->i_mapping->nrpages != 0) {
                rc = filemap_fdatawait(inode->i_mapping);
@@ -2992,6 +2994,9 @@ int cifs_getattr(const struct mnt_idmap *idmap, const struct path *path,
                stat->result_mask |= STATX_BTIME;
                stat->btime =
                      cifs_NTtimeToUnix(cpu_to_le64(CIFS_I(inode)->createtime));
+               stat->result_mask |= STATX_PTIME;
+               stat->ptime =
+                     cifs_NTtimeToUnix(cpu_to_le64(CIFS_I(inode)->createtime));
        }
 
        stat->attributes_mask |= (STATX_ATTR_COMPRESSED | STATX_ATTR_ENCRYPTED);
fs/smb/client/ioctl.c +36 -1
index bb8808289a46..19a9556d39b4 100644
@@ -181,6 +181,41 @@ static int cifs_set_compression(unsigned int xid, struct dentry *dentry,
                                            compression_state);
 }
 
+static int cifs_set_file_crtime(unsigned int xid, struct dentry *dentry,
+                               struct cifs_tcon *tcon, u64 crtime)
+{
+       struct inode *inode = d_inode(dentry);
+       struct TCP_Server_Info *server = tcon->ses->server;
+       FILE_BASIC_INFO info_buf = {};
+       const char *full_path;
+       void *page;
+       int rc;
+
+       if (!server->ops->set_file_info)
+               return -EOPNOTSUPP;
+
+       info_buf.CreationTime = cpu_to_le64(crtime);
+
+       page = alloc_dentry_path();
+       full_path = build_path_from_dentry(dentry, page);
+       if (IS_ERR(full_path)) {
+               rc = PTR_ERR(full_path);
+               goto out;
+       }
+
+       rc = server->ops->set_file_info(inode, full_path, &info_buf, xid);
+       if (rc == 0) {
+               CIFS_I(inode)->createtime = crtime;
+               CIFS_I(inode)->time = 0;
+               inode_set_ctime_current(inode);
+       }
+
+out:
+       free_dentry_path(page);
+       return rc;
+}
+
+#define CIFS_SUPPORTED_XFLAGS (FS_XFLAG_PTIME)
 int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
                      struct file_kattr *fa)
 {
@@ -193,49 +228,65 @@ int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
        bool enable_compression;
        struct cifs_tcon *tcon;
        unsigned int xid;
-       int rc;
+       int rc = 0;
 
Quoted 6 lines

fs/smb/client/ioctl.c int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, · line 234

Quoted 3 lines
fs/smb/client/ioctl.c +1 -1
-       if (!fa->flags_valid)
+       if (fileattr_has_fsx_mask(fa, CIFS_SUPPORTED_XFLAGS))
                return -EOPNOTSUPP;

What is this supposed to check that is not already checked explicitly with fsx_xflags_mask below?

Quoted 5 lines

It should work for FS_IOC_FSSETXATTR, where mask is 0... but it's also there because when I started writing the various filesystems code I hadn't added _mask yet, so I'll need to take a little step back and revisit.

Yes, I see.
I think the helper may still have value for fs that still parse the two types of flags.

To reduce the scope of your patch set this may be better.

Quoted 34 lines
Quoted 34 lines
Quoted 33 lines
fs/smb/client/ioctl.c +15 -15
-       /*
-        * chattr writes back all flags returned by fileattr_get(). Accept
-        * FS_CASEFOLD_FL only when it reflects the share's casefold state.
-        */
-       if (fa->flags & FS_CASEFOLD_FL) {
-               rc = cifs_fileattr_get(dentry, &current_fa);
-               if (rc)
-                       return rc;
-               if (current_fa.flags & FS_CASEFOLD_FL)
-                       allowed |= FS_CASEFOLD_FL;
-       }
-       if (fa->flags & ~allowed)
+       if (fa->fsx_xflags_mask & ~CIFS_SUPPORTED_XFLAGS)
                return -EOPNOTSUPP;
 
-       enable_compression = fa->flags & FS_COMPR_FL;
-       compression_state = enable_compression ? COMPRESSION_FORMAT_DEFAULT :
-                                                COMPRESSION_FORMAT_NONE;
+       if (fa->flags_valid) {
+               /*
+                * chattr writes back all flags returned by fileattr_get(). Accept
+                * FS_CASEFOLD_FL only when it reflects the share's casefold state.
+                */
+               if (fa->flags & FS_CASEFOLD_FL) {
+                       rc = cifs_fileattr_get(dentry, &current_fa);
+                       if (rc)
+                               return rc;
+                       if (current_fa.flags & FS_CASEFOLD_FL)
+                               allowed |= FS_CASEFOLD_FL;
+               }
+               if (fa->flags & ~allowed)
+                       return -EOPNOTSUPP;
Quoted 5 lines
Quoted 2 lines

This whole mess could be sorted out by switching the cifs implementation to the new API

("new API" you mean _mask right?)

Yes and ro_mask, but it probably also means converting all the read-only CASEFOLD fs to new api, so that FS_XFLAG_CASEFOLD could be taken out of FS_XFLAG_RDONLY_MASK

Quoted 19 lines
Quoted 18 lines

and implementing a generic vfs
helper which does something like the above code to handle the old ioctls.
FS_XFLAG_CASEFOLD would then be removed from FS_XFLAG_RDONLY_MASK and set explicitly in xflags_ro_mask by fs which don't allow to set if (e.g. nfs) and added to FS_COMMON_FL/FS_XFLAG_COMMON

cifs would advertise FS_XFLAG_CASEFOLD in its ro_mask and then the generic helper would mask it and the new syscall will not allow it.

fs/smb/client/ioctl.c int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,

Quoted 3 lines
fs/smb/client/ioctl.c +2 -0
+       }
[...]
+               cifs_dbg(FYI, "set compress flag rc %d\n", rc);

I think that the roadmap should be to slowly define all the old FS_*_FL flags as FS_XFLAGS_* and let the generic helpers deal with the conversion.

Quoted 7 lines
Quoted 3 lines

But it is not so hard to convert one filesystem at a time in a way that fa->fsx_valid will have to be true, because, for example, here all the relevant flags would be supported by the new xflags API.

So, something like what fileattr_fill_{x,}flags() do now, but for file_attr_to_fileattr()?

Yes, something like this (maybe)

void fileattr_fill_flags(struct file_kattr *fa, u32 flags)

 {
        fa->flags_valid = true;
+       fa->fsx_valid = !(flags & ~FS_COMMON_FL);
+       fa->fsx_xflags_mask = FS_XFLAG_COMMON;
        fa->flags = flags;

But in this model FS_XFLAG_COMMON are only the ones that are mutable from the old ioctl.

We would need to define FS_READONLY_FL to deal with the group of read-only legacy flags, if some fs needs them and wants to use the new API.

Quoted 11 lines
Quoted 4 lines

No need to do that now, as part of this patch set which is complicated enough, just need to see the road ahead of us that we have a way forward out of this messy flags_valid/fsx_valid inside filesystem implementations.

I think it's probably better to clean up the API now, before introducing new flags (like FS_XFLAG_BTIME/PTIME or the shared extent one in the other thread) and as I'll say in that reply (I'll write it in a bit) I think it's even better to first split the _mask changes into their own RFC PATCH series, then have a separate one for ptime/btime.

Agree.

It's even two different changes -
The vfs internal _mask change and the UAPI _mask change. chattr -p implementation with new API would be the perfect champion to drive this UAPI change IMO.

Quoted 6 lines
Quoted 3 lines

My understanding is that Miklos introduced those hints to reduce the work needed per filesystem for the initial implementation of the vfs methods.

Ah yeah that would make sense.

BTW the trigger for the vfs interface was ovl_copy_fileattr() so this is a user of the new vfs _mask API that we need to pay attention to.

Thanks,
Amir.

author
#43 lore raw

Re: [RFC PATCH v4 10/10] cifs: add provenance time (ptime) and map it to SMB's CreationTime

Quoted 143 lines · Amir Goldstein
Quoted 136 lines · koraynilay
Quoted 127 lines · Amir Goldstein
Quoted 126 lines · koraynilay

Implement provenance time (ptime) in cifs, as introduced in a previous commit ("vfs: add provenance time (ptime)").

Map it to SMB's CreationTime, making it settable from userspace and propagating it to the SMB server via FILE_BASIC_INFO.

Support reading ptime via statx(2) and fileattr_get() from the cached CreationTime.

Update cifs_fileattr_set() to check xflags instead of only legacy flags and add the cifs_set_file_crtime() helper to wrap the RPC call to the SMB server.

Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.7
---
 fs/smb/client/cifsfs.c |   8 +++
 fs/smb/client/inode.c  |   7 ++-
 fs/smb/client/ioctl.c  | 109 ++++++++++++++++++++++++++++++-----------
 3 files changed, 94 insertions(+), 30 deletions(-)
fs/smb/client/cifsfs.c +8 -0
index 8cff7857b450..c2f557e406d3 100644
@@ -1307,6 +1307,14 @@ int cifs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
        if (READ_ONCE(CIFS_I(inode)->cifsAttrs) & ATTR_COMPRESSED)
                fa->flags |= FS_COMPR_FL;
 
+       /* Report provenance time (ptime) to userspace */
+       if (CIFS_I(inode)->createtime) {
+               fa->fsx_xflags |= FS_XFLAG_PTIME;
+               fa->fsx_xflags_mask |= FS_XFLAG_PTIME;
+               fa->fsx_ptime =
+                     cifs_NTtimeToUnix(cpu_to_le64(CIFS_I(inode)->createtime));
+       }
+
        /*
         * FS_CASEFOLD_FL is defined by UAPI as a folder attribute,
         * and userspace tools (e.g., lsattr) display it only on
fs/smb/client/inode.c +6 -1
index 2647785ec1e4..f0b20a72b9c2 100644
@@ -222,6 +222,7 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr,
 
        cifs_i->cifsAttrs = fattr->cf_cifsattrs;
        cifs_i->reparse_tag = fattr->cf_cifstag;
+       cifs_i->createtime = fattr->cf_createtime;
 
        if (fattr->cf_flags & CIFS_FATTR_NEED_REVAL)
                cifs_i->time = 0;
@@ -2958,7 +2959,8 @@ int cifs_getattr(const struct mnt_idmap *idmap, const struct path *path,
         * We need to be sure that all dirty pages are written and the server
         * has actual ctime, mtime and file length.
         */
-       if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_SIZE | STATX_BLOCKS)) &&
+       if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_PTIME
+                            | STATX_SIZE | STATX_BLOCKS)) &&
            !CIFS_CACHE_READ(CIFS_I(inode)) &&
            inode->i_mapping && inode->i_mapping->nrpages != 0) {
                rc = filemap_fdatawait(inode->i_mapping);
@@ -2992,6 +2994,9 @@ int cifs_getattr(const struct mnt_idmap *idmap, const struct path *path,
                stat->result_mask |= STATX_BTIME;
                stat->btime =
                      cifs_NTtimeToUnix(cpu_to_le64(CIFS_I(inode)->createtime));
+               stat->result_mask |= STATX_PTIME;
+               stat->ptime =
+                     cifs_NTtimeToUnix(cpu_to_le64(CIFS_I(inode)->createtime));
        }
 
        stat->attributes_mask |= (STATX_ATTR_COMPRESSED | STATX_ATTR_ENCRYPTED);
fs/smb/client/ioctl.c +36 -1
index bb8808289a46..19a9556d39b4 100644
@@ -181,6 +181,41 @@ static int cifs_set_compression(unsigned int xid, struct dentry *dentry,
                                            compression_state);
 }
 
+static int cifs_set_file_crtime(unsigned int xid, struct dentry *dentry,
+                               struct cifs_tcon *tcon, u64 crtime)
+{
+       struct inode *inode = d_inode(dentry);
+       struct TCP_Server_Info *server = tcon->ses->server;
+       FILE_BASIC_INFO info_buf = {};
+       const char *full_path;
+       void *page;
+       int rc;
+
+       if (!server->ops->set_file_info)
+               return -EOPNOTSUPP;
+
+       info_buf.CreationTime = cpu_to_le64(crtime);
+
+       page = alloc_dentry_path();
+       full_path = build_path_from_dentry(dentry, page);
+       if (IS_ERR(full_path)) {
+               rc = PTR_ERR(full_path);
+               goto out;
+       }
+
+       rc = server->ops->set_file_info(inode, full_path, &info_buf, xid);
+       if (rc == 0) {
+               CIFS_I(inode)->createtime = crtime;
+               CIFS_I(inode)->time = 0;
+               inode_set_ctime_current(inode);
+       }
+
+out:
+       free_dentry_path(page);
+       return rc;
+}
+
+#define CIFS_SUPPORTED_XFLAGS (FS_XFLAG_PTIME)
 int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
                      struct file_kattr *fa)
 {
@@ -193,49 +228,65 @@ int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
        bool enable_compression;
        struct cifs_tcon *tcon;
        unsigned int xid;
-       int rc;
+       int rc = 0;
 
Quoted 6 lines

fs/smb/client/ioctl.c int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, · line 234

Quoted 3 lines
fs/smb/client/ioctl.c +1 -1
-       if (!fa->flags_valid)
+       if (fileattr_has_fsx_mask(fa, CIFS_SUPPORTED_XFLAGS))
                return -EOPNOTSUPP;

What is this supposed to check that is not already checked explicitly with fsx_xflags_mask below?

Quoted 5 lines

It should work for FS_IOC_FSSETXATTR, where mask is 0... but it's also there because when I started writing the various filesystems code I hadn't added _mask yet, so I'll need to take a little step back and revisit.

Quoted 3 lines

Yes, I see.
I think the helper may still have value for fs that still parse the two types of flags.

Yeah maybe, I'll see after I the first vfs-only patch I think.

Quoted 39 lines

To reduce the scope of your patch set this may be better.

Quoted 37 lines
Quoted 36 lines
Quoted 23 lines
fs/smb/client/ioctl.c +5 -15
-       /*
-        * chattr writes back all flags returned by fileattr_get(). Accept
-        * FS_CASEFOLD_FL only when it reflects the share's casefold state.
-        */
-       if (fa->flags & FS_CASEFOLD_FL) {
-               rc = cifs_fileattr_get(dentry, &current_fa);
-               if (rc)
-                       return rc;
-               if (current_fa.flags & FS_CASEFOLD_FL)
-                       allowed |= FS_CASEFOLD_FL;
-       }
-       if (fa->flags & ~allowed)
+       if (fa->fsx_xflags_mask & ~CIFS_SUPPORTED_XFLAGS)
                return -EOPNOTSUPP;
 
-       enable_compression = fa->flags & FS_COMPR_FL;
-       compression_state = enable_compression ? COMPRESSION_FORMAT_DEFAULT :
-                                                COMPRESSION_FORMAT_NONE;
+       if (fa->flags_valid) {
+               /*
+                * chattr writes back all flags returned by fileattr_get(). Accept
+                * FS_CASEFOLD_FL only when it reflects the share's casefold state.

fs/smb/client/ioctl.c int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, · line 252

Quoted 10 lines
fs/smb/client/ioctl.c +10 -0
+                */
+               if (fa->flags & FS_CASEFOLD_FL) {
+                       rc = cifs_fileattr_get(dentry, &current_fa);
+                       if (rc)
+                               return rc;
+                       if (current_fa.flags & FS_CASEFOLD_FL)
+                               allowed |= FS_CASEFOLD_FL;
+               }
+               if (fa->flags & ~allowed)
+                       return -EOPNOTSUPP;

This whole mess could be sorted out by switching the cifs implementation to the new API

Quoted 6 lines
Quoted 2 lines

("new API" you mean _mask right?)

Yes and ro_mask, but it probably also means converting all the read-only CASEFOLD fs to new api, so that FS_XFLAG_CASEFOLD could be taken out of FS_XFLAG_RDONLY_MASK

Can all flags currently in FS_XFLAG_RDONLY_MASK be rw for some filesystems or only some?
Should they all be removed from FS_XFLAG_RDONLY_MASK and left to each filesystem to define them as ro (to put in _ro_mask)?

Quoted 32 lines
Quoted 19 lines
Quoted 18 lines

and implementing a generic vfs
helper which does something like the above code to handle the old ioctls.
FS_XFLAG_CASEFOLD would then be removed from FS_XFLAG_RDONLY_MASK and set explicitly in xflags_ro_mask by fs which don't allow to set if (e.g. nfs) and added to FS_COMMON_FL/FS_XFLAG_COMMON

cifs would advertise FS_XFLAG_CASEFOLD in its ro_mask and then the generic helper would mask it and the new syscall will not allow it.

fs/smb/client/ioctl.c int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,

Quoted 3 lines
fs/smb/client/ioctl.c +2 -0
+       }
[...]
+               cifs_dbg(FYI, "set compress flag rc %d\n", rc);

I think that the roadmap should be to slowly define all the old FS_*_FL flags as FS_XFLAGS_* and let the generic helpers deal with the conversion.

Quoted 7 lines
Quoted 3 lines

But it is not so hard to convert one filesystem at a time in a way that fa->fsx_valid will have to be true, because, for example, here all the relevant flags would be supported by the new xflags API.

So, something like what fileattr_fill_{x,}flags() do now, but for file_attr_to_fileattr()?

Yes, something like this (maybe)

void fileattr_fill_flags(struct file_kattr *fa, u32 flags)

 {
        fa->flags_valid = true;

Review

Quoted 3 lines
(quoted diff) +2 -0
+       fa->fsx_valid = !(flags & ~FS_COMMON_FL);
+       fa->fsx_xflags_mask = FS_XFLAG_COMMON;
        fa->flags = flags;

So, for the filesystems that switch to the new API, these new/changed helpers should handle giving userspace the legacy FS_*_FL flags (if userspace uses FS_IOC_GETFLAGS) by converting them from the FS_XFLAG_* reported by the filesystem?

But did you write this

Review

Quoted 2 lines
(quoted diff) +2 -0
+       fa->fsx_valid = !(flags & ~FS_COMMON_FL);
+       fa->fsx_xflags_mask = FS_XFLAG_COMMON;

while thinking about FS_IOC_SETFLAGS, so from userspace to filesystem, and this would be needed because that filesystem wouldn't know what FS_*_FL are, so it will use the _mask and the converted xflags?

But why the opposite of (flags & ~FS_COMMON_FL) as fsx_valid?

Why fsx_valid = 0 if the passed flags also contain non-FS_COMMON_FL flags and fsx_valid = 1 if the passed flags contain only FS_COMMON_FL flags?
(if I understood correctly)

Quoted 6 lines

But in this model FS_XFLAG_COMMON are only the ones that are mutable from the old ioctl.

We would need to define FS_READONLY_FL to deal with the group of read-only legacy flags, if some fs needs them and wants to use the new API.

So the those filesystems can put it in _ro_mask on GET you mean?

Quoted 12 lines
Quoted 11 lines
Quoted 4 lines

No need to do that now, as part of this patch set which is complicated enough, just need to see the road ahead of us that we have a way forward out of this messy flags_valid/fsx_valid inside filesystem implementations.

I think it's probably better to clean up the API now, before introducing new flags (like FS_XFLAG_BTIME/PTIME or the shared extent one in the other thread) and as I'll say in that reply (I'll write it in a bit) I think it's even better to first split the _mask changes into their own RFC PATCH series, then have a separate one for ptime/btime.

Quoted 6 lines

Agree.

It's even two different changes -
The vfs internal _mask change and the UAPI _mask change. chattr -p implementation with new API would be the perfect champion to drive this UAPI change IMO.

Ah, right, they could even be made in 2 separate patches but it's probably better to keep both in only one, since otherwise there would need to be temporary vfs functions to convert xflags to xflags_mask and back.

Quoted 10 lines
Quoted 6 lines
Quoted 3 lines

My understanding is that Miklos introduced those hints to reduce the work needed per filesystem for the initial implementation of the vfs methods.

Ah yeah that would make sense.

BTW the trigger for the vfs interface was ovl_copy_fileattr() so this is a user of the new vfs _mask API that we need to pay attention to.

Ah ok, I'll look into that too then.

Quoted 2 lines

Thanks,
Amir.

#44 lore raw

Re: [RFC PATCH v4 10/10] cifs: add provenance time (ptime) and map it to SMB's CreationTime

Quoted 43 lines · koraynilay
Quoted 43 lines

To reduce the scope of your patch set this may be better.

Quoted 39 lines
Quoted 34 lines
Quoted 23 lines
fs/smb/client/ioctl.c +5 -15
-       /*
-        * chattr writes back all flags returned by fileattr_get(). Accept
-        * FS_CASEFOLD_FL only when it reflects the share's casefold state.
-        */
-       if (fa->flags & FS_CASEFOLD_FL) {
-               rc = cifs_fileattr_get(dentry, &current_fa);
-               if (rc)
-                       return rc;
-               if (current_fa.flags & FS_CASEFOLD_FL)
-                       allowed |= FS_CASEFOLD_FL;
-       }
-       if (fa->flags & ~allowed)
+       if (fa->fsx_xflags_mask & ~CIFS_SUPPORTED_XFLAGS)
                return -EOPNOTSUPP;
 
-       enable_compression = fa->flags & FS_COMPR_FL;
-       compression_state = enable_compression ? COMPRESSION_FORMAT_DEFAULT :
-                                                COMPRESSION_FORMAT_NONE;
+       if (fa->flags_valid) {
+               /*
+                * chattr writes back all flags returned by fileattr_get(). Accept
+                * FS_CASEFOLD_FL only when it reflects the share's casefold state.

fs/smb/client/ioctl.c int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, · line 252

Quoted 10 lines
fs/smb/client/ioctl.c +10 -0
+                */
+               if (fa->flags & FS_CASEFOLD_FL) {
+                       rc = cifs_fileattr_get(dentry, &current_fa);
+                       if (rc)
+                               return rc;
+                       if (current_fa.flags & FS_CASEFOLD_FL)
+                               allowed |= FS_CASEFOLD_FL;
+               }
+               if (fa->flags & ~allowed)
+                       return -EOPNOTSUPP;
Quoted 2 lines

This whole mess could be sorted out by switching the cifs implementation to the new API

("new API" you mean _mask right?)

Quoted 6 lines
Quoted 3 lines

Yes and ro_mask, but it probably also means converting all the read-only CASEFOLD fs to new api, so that FS_XFLAG_CASEFOLD could be taken out of FS_XFLAG_RDONLY_MASK

Can all flags currently in FS_XFLAG_RDONLY_MASK be rw for some filesystems or only some?

No. CASEFOLD is the only one which is MODIFIABLE/SETTABLE in the old setflags ioctl.

Its twin xflag FS_XFLAG_CASEFOLD was recently added along with FS_XFLAG_CASENONPRESERVING for a bunch of fs (e.g. nfs) which advertise it as rdonly attribute.

Quoted 3 lines

Should they all be removed from FS_XFLAG_RDONLY_MASK and left to each filesystem to define them as ro (to put in _ro_mask)?

No need to do this.

One flag at a time per demand.

You *need* to get FS_XFLAG_CASEFOLD out when some
fs will want to set it via xflags API.

You *may* get a flag out of FS_XFLAG_RDONLY_MASK
only after *all* of the fs which support it have been converted to the new xflags_*_mask api.

Quoted 36 lines
Quoted 32 lines
Quoted 19 lines
Quoted 18 lines

and implementing a generic vfs
helper which does something like the above code to handle the old ioctls.
FS_XFLAG_CASEFOLD would then be removed from FS_XFLAG_RDONLY_MASK and set explicitly in xflags_ro_mask by fs which don't allow to set if (e.g. nfs) and added to FS_COMMON_FL/FS_XFLAG_COMMON

cifs would advertise FS_XFLAG_CASEFOLD in its ro_mask and then the generic helper would mask it and the new syscall will not allow it.

Review

Quoted 3 lines
(quoted diff) +2 -0
+       }
[...]
+               cifs_dbg(FYI, "set compress flag rc %d\n", rc);

I think that the roadmap should be to slowly define all the old FS_*_FL flags as FS_XFLAGS_* and let the generic helpers deal with the conversion.

Quoted 7 lines
Quoted 3 lines

But it is not so hard to convert one filesystem at a time in a way that fa->fsx_valid will have to be true, because, for example, here all the relevant flags would be supported by the new xflags API.

So, something like what fileattr_fill_{x,}flags() do now, but for file_attr_to_fileattr()?

Yes, something like this (maybe)

void fileattr_fill_flags(struct file_kattr *fa, u32 flags)

 {
        fa->flags_valid = true;

Review

Quoted 3 lines
(quoted diff) +2 -0
+       fa->fsx_valid = !(flags & ~FS_COMMON_FL);
+       fa->fsx_xflags_mask = FS_XFLAG_COMMON;
        fa->flags = flags;
Quoted 5 lines

So, for the filesystems that switch to the new API, these new/changed helpers should handle giving userspace the legacy FS_*_FL flags (if userspace uses FS_IOC_GETFLAGS) by converting them from the FS_XFLAG_* reported by the filesystem?

I did not look at the implementation details but when you make the vfs API rich enough with the masks, the should be no problem to describe in the API what the old ioctls do
"get a subset of attributes"
"set a subset of attributes"

Where "subset" differs depending on the ioctl.

Quoted 7 lines

But did you write this

Review

Quoted 2 lines
(quoted diff) +2 -0
+       fa->fsx_valid = !(flags & ~FS_COMMON_FL);
+       fa->fsx_xflags_mask = FS_XFLAG_COMMON;

while thinking about FS_IOC_SETFLAGS, so from userspace to filesystem, and this would be needed because that filesystem wouldn't know what FS_*_FL are, so it will use the _mask and the converted xflags?

Quoted 7 lines

But why the opposite of (flags & ~FS_COMMON_FL) as fsx_valid?

Why fsx_valid = 0 if the passed flags also contain non-FS_COMMON_FL flags and fsx_valid = 1 if the passed flags contain only FS_COMMON_FL flags?
(if I understood correctly)

My interpretation of fsx_valid (for the set side) is:
fs may completely ignore ->flags and get all the information from fsx_* similarly for flags_valid fs does not need to look at fsx_*

In the case that all requested flags are common, both fsx_valid and flags_valid can be true.

But what I wrote is nonsense, because the old ioctls have no request_mask so unset flag does not mean it is not being set.

I think what is needed is something like this helper to be called from filesystems:

bool fileattr_prepare_xflags(struct file_kattr *fa, u32 xflags, u32 supported)

{
        if (fa->flags_valid) {
                fa->fsx_valid = !(fa->flags & supported & ~FS_COMMON_FL);
                fa->fsx_xflags_mask = supported & FS_XFLAG_COMMON;
        }
        return fa->fsx_valid;
}

Then cifs_fileattr_set() starts with:

if (!fileattr_prepare_xflags(fa, CIFS_SUPPORTED_XFLAGS))
return -EOPNOTSUPP;

And from here on, talk only xflags and xflags_*mask

For cifs that means to add vfs support for FS_XFLAG_COMPR <-> FS_COMR_FL conversion in helpers.

FS_COMR_FL is also rdonly flag in some fs and rw in others.

Quoted 9 lines
Quoted 6 lines

But in this model FS_XFLAG_COMMON are only the ones that are mutable from the old ioctl.

We would need to define FS_READONLY_FL to deal with the group of read-only legacy flags, if some fs needs them and wants to use the new API.

So the those filesystems can put it in _ro_mask on GET you mean?

Actually, I meant that the old setflags ioctls could be translates to the new xflags_mask dialect, for example:

bool fileattr_prepare_xflags(struct file_kattr *fa, u32 xflags, u32 supported)

{
        if (fa->flags_valid) {
                fa->fsx_valid = !(fa->flags & supported & ~FS_COMMON_FL);
                fa->fsx_xflags_rw_mask = supported & FS_XFLAG_COMMON &
                                                          ~FS_XFLAG_RDONLY_MASK;
                fa->fsx_xflags_ro_mask = supported & FS_XFLAG_COMMON &
                                                          FS_XFLAG_RDONLY_MASK;
        }
        return fa->fsx_valid;
}

so it will work correctly for example with fs/ntfs which supports readonly ENCRYPT|COMPR

Thanks,
Amir.

maintainer
#45 lore raw
In reply to koraynilay
Quoted 14 lines · koraynilay

This is an initial implementation of a new timestamp to indicate the time when a file/directory was initially created.

This patch series takes inspiration from the one by Sean Smith <[email protected]> [1], but using file_setattr()/file_getattr() as suggested by Darrick J. Wong <[email protected]> in [2].

The semantics of this new timestamp should be at least these:
- it should be the same as btime on a newly created file
- it's user-settable, so it can be preserved for backups, filesystem conversions, archives and any similar operation
- it should be preserved every time mtime gets preserved

Quoted 5 lines

and the correspondence with the other timestamps is as follows:

ctime <-> btime
mtime <-> ptime

I'm not sure how to interpret the correspondence above.

Quoted 124 lines

Examples:
1) a .zsh_history file created in 2019, then after a few years the user decides to switch to another filesystem, copying the .zsh_history to the new home, in that case btime would have the timestamp of the copy and ptime would have the 2019 timestamp (just like mtime would have been preserved)
2) a symlink created in 2020 from the home directory to a /path going through the same process as the .zsh_history, in this case it would also make sense to sync the ptime to the 2020 timestamp instead of keeping only the btime (so the inode creation time).

The proof-of-concept code (for testing) for stat(1) and cp(1) is available at https://github.com/koraynilay/coreutils (master branch) (Note: these coreutils code changes are a prototype and won't be submitted upstream as-is, but they work as expected in simple stat and cp -a/--preserve=ptime tests)

Lastly, the name "provenance" and "ptime" are not final, I personally don't have a strong opinion on any name, but while testing with stat(1) I noticed that "Provenance" is definitely too long for the normal output, so another option which would fit well is "Origin time", abbreviated as "ntime" (OrigiN time) and not as "otime", as that would conflict with btrfs' internal naming and create confusion.

v2 changes:
- fix permission bypass leading to ptime update on immutable and append-only files (found by sashiko[3])
- normalize ptime timestamp as done in fs/attr.c:notify_change() (found by sashiko[3])
- fix wording in vfs patch to be like the cover-letter

v3 changes:
- vfs: reject setting ptime with -EOPNOTSUPP on filesystems that do not support it instead of silently ignoring it (found by sashiko[4])
- vfs: fix not being able to clear immutable and append-only on files with ptime, and allow updating immutable/append-only atomically along with ptime (found by sashiko[4])
- btrfs: validate on-disk ptime nanoseconds and reset to otime if invalid (found by sashiko[4])
- btrfs: avoid re-assigning ptime on unrelated chattr calls (found by sashiko[4])
- add ntfs3 and exfat support as suggested by Amir Goldstein[5], but no vfat, smb, or nfs4 yet as they are a bit more complex
- move the introduction of fileattr_has_fsx_mask() from the btrfs patch to a standalone patch in the series
- btrfs: add fileattr_[gs]et to symlink and special file operations

v4 changes:
- vfs: implement fsx_xflags_mask as suggested by Amir Goldstein[6];
- add SMB (ksmbd/cifs) and nfs (nfsd/nfs) support as requested in previous threads;

Note:
to apply this patch 2 previous patches[7][8] from the ksmbd/cifs subsystem are needed.

New Question:
should I rename fileattr_has_fsx_mask() to something like fileattr_has_unsupported_fsx() and keep its code as-is, or should I add the fsx_xflags_mask & ~allowed check in it and keep the name as-is? (or both?)

Thanks.

[1]: https://lore.kernel.org/[email protected]
[2]: https://lore.kernel.org/20260407014129.GC6192@frogsfrogsfrogs
[3]: https://sashiko.dev/#/patchset/20261027220532.736352-1-koray.fra%40gmail.com
[4]: https://sashiko.dev/#/patchset/20261028134728.294127-1-koray.fra%40gmail.com
[5]: https://lore.kernel.org/CAOQ4uxiuy0VwZj+3M-zRqQ49WTpHZpiaQ+6MZ8z8WdLjyQM_zA@mail.gmail.com/
[6]: https://lore.kernel.org/CAOQ4uxjtuTDT63vJdYaq+RHQEQFLTksp66e46OMN99WhJz3SbA@mail.gmail.com/
[7]: https://lore.kernel.org/linux-cifs/[email protected]/
[8]: https://lore.kernel.org/linux-cifs/[email protected]/

koraynilay (10):
vfs: add provenance time (ptime)
vfs: add fileattr_has_fsx_mask()
ntfs3: make crtime user-settable using ptime
exfat: make crtime user-settable using ptime
btrfs: add provenance time (ptime)
vfs: add __vfs_fileattr_set_locked() for inode_lock()'d callers
nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE
nfs: add provenance time (ptime) via FATTR4_TIME_CREATE
ksmbd: add provenance time (ptime) and map it to CreationTime
cifs: add provenance time (ptime) and map it to SMB's CreationTime

 fs/btrfs/btrfs_inode.h          |   4 +
 fs/btrfs/delayed-inode.c        |   6 ++
 fs/btrfs/inode.c                |  29 +++++-
 fs/btrfs/ioctl.c                |  24 ++++-
 fs/btrfs/print-tree.c           |   1 +
 fs/btrfs/tree-log.c             |   3 +
 fs/exfat/exfat_fs.h             |   2 +
 fs/exfat/file.c                 |  42 ++++++++-
 fs/exfat/namei.c                |   1 +
 fs/file_attr.c                  | 156 ++++++++++++++++++++++++++------
 fs/nfs/inode.c                  |  27 +++++-
 fs/nfs/internal.h               |   2 +
 fs/nfs/nfs4proc.c               |  56 +++++++++++-
 fs/nfs/nfs4xdr.c                |  19 ++--
 fs/nfs/symlink.c                |   1 +
 fs/nfsd/nfs4proc.c              |   9 ++
 fs/nfsd/nfs4xdr.c               |  40 +++++---
 fs/nfsd/vfs.c                   |  17 ++++
 fs/nfsd/vfs.h                   |   4 +-
 fs/nfsd/xdr4.h                  |   3 +
 fs/ntfs3/file.c                 |  20 +++-
 fs/ntfs3/frecord.c              |   8 +-
 fs/smb/client/cifsfs.c          |   8 ++
 fs/smb/client/inode.c           |   7 +-
 fs/smb/client/ioctl.c           | 109 ++++++++++++++++------
 fs/smb/server/smb2pdu.c         |  37 +++++---
 fs/smb/server/vfs.c             |  43 ++++++++-
 fs/smb/server/vfs.h             |   1 +
 fs/stat.c                       |   2 +
 include/linux/fileattr.h        |  29 +++++-
 include/linux/nfs_xdr.h         |   3 +
 include/linux/stat.h            |   1 +
 include/uapi/linux/btrfs_tree.h |   3 +-
 include/uapi/linux/fs.h         |   9 +-
 include/uapi/linux/stat.h       |   7 +-
 35 files changed, 614 insertions(+), 119 deletions(-)
Quoted 4 lines

base-commit: 3bc1fb9c3b20cd478c83496ab16addecb401770d
prerequisite-patch-id: 049ae0eba275b5be35a238833107e0b251a55aa2
prerequisite-patch-id: 614f0bc9411391403d4e9702bafeb31b0ec04ec1
prerequisite-patch-id: ddf636b9d33d82ea206ce265d817371350bf8858

I think this is going to be very hard to do properly, because the kernel can't really manage this on its own. Something in userland is going to have to set this value if you want to update it to something other than the original inode instantiation time (aka btime).

It really sounds like what you want is the ability to make the btime settable. Personally I think the decision to forbid that was wrong- headed and that it should have been settable from userland from the beginning. Maybe we should just revisit that decision.

Failing that, why not just track this in an xattr of some sort, since this is really just an opaque blob once you allow it to be settable. If the xattr isn't present, then you can just use the value of the btime as-is. FWIW, I think samba does this today, so you could try to sync with its behavior here.

That seems a lot simpler than adding an entirely new inode timestamp that is always going to be a copy of the btime, except in rare cases. Having to patch all of the on-disk filesystems with a new per-inode field is a lot more work.

Signature · 1 line
Jeff Layton <[email protected]>
author
#46 lore raw

Hello and thanks for replying,

Quoted 15 lines · Jeff Layton
Quoted 14 lines · koraynilay

This is an initial implementation of a new timestamp to indicate the time when a file/directory was initially created.

This patch series takes inspiration from the one by Sean Smith <[email protected]> [1], but using file_setattr()/file_getattr() as suggested by Darrick J. Wong <[email protected]> in [2].

The semantics of this new timestamp should be at least these:
- it should be the same as btime on a newly created file
- it's user-settable, so it can be preserved for backups, filesystem conversions, archives and any similar operation
- it should be preserved every time mtime gets preserved

Quoted 7 lines
Quoted 5 lines

and the correspondence with the other timestamps is as follows:

ctime <-> btime
mtime <-> ptime

I'm not sure how to interpret the correspondence above.

  |-----\_-----------------|-----------|
  |       \_      change/  |   birth/  |
  |         \_ modification|  creation |
  |           \------------|-----------|
  | inode time |   ctime   |   btime   |
  |------------|-----------|-----------|
  | file time  |   mtime   |   ptime   |
  |------------|-----------|-----------|

("file" as in "the concept of this file", I'd say "file content" but that would be incorrect for symlinks)

so ctime is "inode change time", btime is "inode birth/creation time", while mtime is "file content change/modification time" and ptime would be "file content creation time" (same as Window's or MacOS's creation time).

Does this make more sense?

Quoted 135 lines
Quoted 125 lines

Examples:
1) a .zsh_history file created in 2019, then after a few years the user decides to switch to another filesystem, copying the .zsh_history to the new home, in that case btime would have the timestamp of the copy and ptime would have the 2019 timestamp (just like mtime would have been preserved)
2) a symlink created in 2020 from the home directory to a /path going through the same process as the .zsh_history, in this case it would also make sense to sync the ptime to the 2020 timestamp instead of keeping only the btime (so the inode creation time).

The proof-of-concept code (for testing) for stat(1) and cp(1) is available at https://github.com/koraynilay/coreutils (master branch) (Note: these coreutils code changes are a prototype and won't be submitted upstream as-is, but they work as expected in simple stat and cp -a/--preserve=ptime tests)

Lastly, the name "provenance" and "ptime" are not final, I personally don't have a strong opinion on any name, but while testing with stat(1) I noticed that "Provenance" is definitely too long for the normal output, so another option which would fit well is "Origin time", abbreviated as "ntime" (OrigiN time) and not as "otime", as that would conflict with btrfs' internal naming and create confusion.

v2 changes:
- fix permission bypass leading to ptime update on immutable and append-only files (found by sashiko[3])
- normalize ptime timestamp as done in fs/attr.c:notify_change() (found by sashiko[3])
- fix wording in vfs patch to be like the cover-letter

v3 changes:
- vfs: reject setting ptime with -EOPNOTSUPP on filesystems that do not support it instead of silently ignoring it (found by sashiko[4])
- vfs: fix not being able to clear immutable and append-only on files with ptime, and allow updating immutable/append-only atomically along with ptime (found by sashiko[4])
- btrfs: validate on-disk ptime nanoseconds and reset to otime if invalid (found by sashiko[4])
- btrfs: avoid re-assigning ptime on unrelated chattr calls (found by sashiko[4])
- add ntfs3 and exfat support as suggested by Amir Goldstein[5], but no vfat, smb, or nfs4 yet as they are a bit more complex
- move the introduction of fileattr_has_fsx_mask() from the btrfs patch to a standalone patch in the series
- btrfs: add fileattr_[gs]et to symlink and special file operations

v4 changes:
- vfs: implement fsx_xflags_mask as suggested by Amir Goldstein[6];
- add SMB (ksmbd/cifs) and nfs (nfsd/nfs) support as requested in previous threads;

Note:
to apply this patch 2 previous patches[7][8] from the ksmbd/cifs subsystem are needed.

New Question:
should I rename fileattr_has_fsx_mask() to something like fileattr_has_unsupported_fsx() and keep its code as-is, or should I add the fsx_xflags_mask & ~allowed check in it and keep the name as-is? (or both?)

Thanks.

[1]: https://lore.kernel.org/[email protected]
[2]: https://lore.kernel.org/20260407014129.GC6192@frogsfrogsfrogs
[3]: https://sashiko.dev/#/patchset/20261027220532.736352-1-koray.fra%40gmail.com
[4]: https://sashiko.dev/#/patchset/20261028134728.294127-1-koray.fra%40gmail.com
[5]: https://lore.kernel.org/CAOQ4uxiuy0VwZj+3M-zRqQ49WTpHZpiaQ+6MZ8z8WdLjyQM_zA@mail.gmail.com/
[6]: https://lore.kernel.org/CAOQ4uxjtuTDT63vJdYaq+RHQEQFLTksp66e46OMN99WhJz3SbA@mail.gmail.com/
[7]: https://lore.kernel.org/linux-cifs/[email protected]/
[8]: https://lore.kernel.org/linux-cifs/[email protected]/

koraynilay (10):
vfs: add provenance time (ptime)
vfs: add fileattr_has_fsx_mask()
ntfs3: make crtime user-settable using ptime
exfat: make crtime user-settable using ptime
btrfs: add provenance time (ptime)
vfs: add __vfs_fileattr_set_locked() for inode_lock()'d callers
nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE
nfs: add provenance time (ptime) via FATTR4_TIME_CREATE
ksmbd: add provenance time (ptime) and map it to CreationTime
cifs: add provenance time (ptime) and map it to SMB's CreationTime

 fs/btrfs/btrfs_inode.h          |   4 +
 fs/btrfs/delayed-inode.c        |   6 ++
 fs/btrfs/inode.c                |  29 +++++-
 fs/btrfs/ioctl.c                |  24 ++++-
 fs/btrfs/print-tree.c           |   1 +
 fs/btrfs/tree-log.c             |   3 +
 fs/exfat/exfat_fs.h             |   2 +
 fs/exfat/file.c                 |  42 ++++++++-
 fs/exfat/namei.c                |   1 +
 fs/file_attr.c                  | 156 ++++++++++++++++++++++++++------
 fs/nfs/inode.c                  |  27 +++++-
 fs/nfs/internal.h               |   2 +
 fs/nfs/nfs4proc.c               |  56 +++++++++++-
 fs/nfs/nfs4xdr.c                |  19 ++--
 fs/nfs/symlink.c                |   1 +
 fs/nfsd/nfs4proc.c              |   9 ++
 fs/nfsd/nfs4xdr.c               |  40 +++++---
 fs/nfsd/vfs.c                   |  17 ++++
 fs/nfsd/vfs.h                   |   4 +-
 fs/nfsd/xdr4.h                  |   3 +
 fs/ntfs3/file.c                 |  20 +++-
 fs/ntfs3/frecord.c              |   8 +-
 fs/smb/client/cifsfs.c          |   8 ++
 fs/smb/client/inode.c           |   7 +-
 fs/smb/client/ioctl.c           | 109 ++++++++++++++++------
 fs/smb/server/smb2pdu.c         |  37 +++++---
 fs/smb/server/vfs.c             |  43 ++++++++-
 fs/smb/server/vfs.h             |   1 +
 fs/stat.c                       |   2 +
 include/linux/fileattr.h        |  29 +++++-
 include/linux/nfs_xdr.h         |   3 +
 include/linux/stat.h            |   1 +
 include/uapi/linux/btrfs_tree.h |   3 +-
 include/uapi/linux/fs.h         |   9 +-
 include/uapi/linux/stat.h       |   7 +-
 35 files changed, 614 insertions(+), 119 deletions(-)
Quoted 4 lines

base-commit: 3bc1fb9c3b20cd478c83496ab16addecb401770d
prerequisite-patch-id: 049ae0eba275b5be35a238833107e0b251a55aa2
prerequisite-patch-id: 614f0bc9411391403d4e9702bafeb31b0ec04ec1
prerequisite-patch-id: ddf636b9d33d82ea206ce265d817371350bf8858

I think this is going to be very hard to do properly, because the kernel can't really manage this on its own. Something in userland is going to have to set this value if you want to update it to something other than the original inode instantiation time (aka btime).

Quoted 4 lines

It really sounds like what you want is the ability to make the btime settable. Personally I think the decision to forbid that was wrong- headed and that it should have been settable from userland from the beginning. Maybe we should just revisit that decision.

Originally I just wanted to have btime settable, yes, and if btime was settable I wouldn't have made this RFC PATCH either, but after reading the already existing discussions about it, I can understand having an "immutable inode creation time", like ctime exists, so even after making btime settable, a new timestamp would be necessary anyway (e.g. for the people who want btime to exist as a forensics timestamp).

Quoted 5 lines

Failing that, why not just track this in an xattr of some sort, since this is really just an opaque blob once you allow it to be settable. If the xattr isn't present, then you can just use the value of the btime as-is. FWIW, I think samba does this today, so you could try to sync with its behavior here.

(This is copied and adapted from [2])

I actually have been using fully userspace xattrs[1] for a few months, mostly for backups, and it "works"; but last month I wanted to merge 2 FSs (and have another merge I have to do), so I ran [1] on all files and then compared all metadata/data between source and destination and noticed there were quite a lot of files that didn't have the xattr set. So I looked online and learned that xattrs only work on regular files/directories, not on symlinks or anything else (and the missing ones were of symlinks).
This is what prompted me to search more if anyone had already proposed a new timestamp (instead of making btime settable) and found the email thread from april linked in the cover letter, which gave me the excuse to finally work on a proper patch.

Quoted 8 lines

That seems a lot simpler than adding an entirely new inode timestamp that is always going to be a copy of the btime, except in rare cases. Having to patch all of the on-disk filesystems with a new per-inode field is a lot more work.

This patch is quite simple, but changing btrfs, then ext4, xfs, etc is a mess, and inevitably you can't get these timestamps until you upgrade your filesystems.

So yeah while I do agree it touches a lot of code that could create problems, IMO this is the best solution and it would complete files' timestamps like other OSs have (and this, I think, is necessary for both backup/archival and migrations).

Thanks,
koraynilay

[1]: https://github.com/koraynilay/btime-to-xattr
[2]: https://lore.kernel.org/[email protected]/

#47 lore raw
Quoted 39 lines · koraynilay

Hello and thanks for replying,

Quoted 15 lines · Jeff Layton
Quoted 14 lines · koraynilay

This is an initial implementation of a new timestamp to indicate the time when a file/directory was initially created.

This patch series takes inspiration from the one by Sean Smith <[email protected]> [1], but using file_setattr()/file_getattr() as suggested by Darrick J. Wong <[email protected]> in [2].

The semantics of this new timestamp should be at least these:
- it should be the same as btime on a newly created file
- it's user-settable, so it can be preserved for backups, filesystem conversions, archives and any similar operation
- it should be preserved every time mtime gets preserved

Quoted 7 lines
Quoted 5 lines

and the correspondence with the other timestamps is as follows:

ctime <-> btime
mtime <-> ptime

I'm not sure how to interpret the correspondence above.

  |-----\_-----------------|-----------|
  |       \_      change/  |   birth/  |
  |         \_ modification|  creation |
  |           \------------|-----------|
  | inode time |   ctime   |   btime   |
  |------------|-----------|-----------|
  | file time  |   mtime   |   ptime   |
  |------------|-----------|-----------|

("file" as in "the concept of this file", I'd say "file content" but that would be incorrect for symlinks)

Quoted 147 lines

so ctime is "inode change time", btime is "inode birth/creation time", while mtime is "file content change/modification time" and ptime would be "file content creation time" (same as Window's or MacOS's creation time).

Does this make more sense?

Quoted 139 lines
Quoted 125 lines

Examples:
1) a .zsh_history file created in 2019, then after a few years the user decides to switch to another filesystem, copying the .zsh_history to the new home, in that case btime would have the timestamp of the copy and ptime would have the 2019 timestamp (just like mtime would have been preserved)
2) a symlink created in 2020 from the home directory to a /path going through the same process as the .zsh_history, in this case it would also make sense to sync the ptime to the 2020 timestamp instead of keeping only the btime (so the inode creation time).

The proof-of-concept code (for testing) for stat(1) and cp(1) is available at https://github.com/koraynilay/coreutils (master branch) (Note: these coreutils code changes are a prototype and won't be submitted upstream as-is, but they work as expected in simple stat and cp -a/--preserve=ptime tests)

Lastly, the name "provenance" and "ptime" are not final, I personally don't have a strong opinion on any name, but while testing with stat(1) I noticed that "Provenance" is definitely too long for the normal output, so another option which would fit well is "Origin time", abbreviated as "ntime" (OrigiN time) and not as "otime", as that would conflict with btrfs' internal naming and create confusion.

v2 changes:
- fix permission bypass leading to ptime update on immutable and append-only files (found by sashiko[3])
- normalize ptime timestamp as done in fs/attr.c:notify_change() (found by sashiko[3])
- fix wording in vfs patch to be like the cover-letter

v3 changes:
- vfs: reject setting ptime with -EOPNOTSUPP on filesystems that do not support it instead of silently ignoring it (found by sashiko[4])
- vfs: fix not being able to clear immutable and append-only on files with ptime, and allow updating immutable/append-only atomically along with ptime (found by sashiko[4])
- btrfs: validate on-disk ptime nanoseconds and reset to otime if invalid (found by sashiko[4])
- btrfs: avoid re-assigning ptime on unrelated chattr calls (found by sashiko[4])
- add ntfs3 and exfat support as suggested by Amir Goldstein[5], but no vfat, smb, or nfs4 yet as they are a bit more complex
- move the introduction of fileattr_has_fsx_mask() from the btrfs patch to a standalone patch in the series
- btrfs: add fileattr_[gs]et to symlink and special file operations

v4 changes:
- vfs: implement fsx_xflags_mask as suggested by Amir Goldstein[6];
- add SMB (ksmbd/cifs) and nfs (nfsd/nfs) support as requested in previous threads;

Note:
to apply this patch 2 previous patches[7][8] from the ksmbd/cifs subsystem are needed.

New Question:
should I rename fileattr_has_fsx_mask() to something like fileattr_has_unsupported_fsx() and keep its code as-is, or should I add the fsx_xflags_mask & ~allowed check in it and keep the name as-is? (or both?)

Thanks.

[1]: https://lore.kernel.org/[email protected]
[2]: https://lore.kernel.org/20260407014129.GC6192@frogsfrogsfrogs
[3]: https://sashiko.dev/#/patchset/20261027220532.736352-1-koray.fra%40gmail.com
[4]: https://sashiko.dev/#/patchset/20261028134728.294127-1-koray.fra%40gmail.com
[5]: https://lore.kernel.org/CAOQ4uxiuy0VwZj+3M-zRqQ49WTpHZpiaQ+6MZ8z8WdLjyQM_zA@mail.gmail.com/
[6]: https://lore.kernel.org/CAOQ4uxjtuTDT63vJdYaq+RHQEQFLTksp66e46OMN99WhJz3SbA@mail.gmail.com/
[7]: https://lore.kernel.org/linux-cifs/[email protected]/
[8]: https://lore.kernel.org/linux-cifs/[email protected]/

koraynilay (10):
vfs: add provenance time (ptime)
vfs: add fileattr_has_fsx_mask()
ntfs3: make crtime user-settable using ptime
exfat: make crtime user-settable using ptime
btrfs: add provenance time (ptime)
vfs: add __vfs_fileattr_set_locked() for inode_lock()'d callers
nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE
nfs: add provenance time (ptime) via FATTR4_TIME_CREATE
ksmbd: add provenance time (ptime) and map it to CreationTime
cifs: add provenance time (ptime) and map it to SMB's CreationTime

 fs/btrfs/btrfs_inode.h          |   4 +
 fs/btrfs/delayed-inode.c        |   6 ++
 fs/btrfs/inode.c                |  29 +++++-
 fs/btrfs/ioctl.c                |  24 ++++-
 fs/btrfs/print-tree.c           |   1 +
 fs/btrfs/tree-log.c             |   3 +
 fs/exfat/exfat_fs.h             |   2 +
 fs/exfat/file.c                 |  42 ++++++++-
 fs/exfat/namei.c                |   1 +
 fs/file_attr.c                  | 156 ++++++++++++++++++++++++++------
 fs/nfs/inode.c                  |  27 +++++-
 fs/nfs/internal.h               |   2 +
 fs/nfs/nfs4proc.c               |  56 +++++++++++-
 fs/nfs/nfs4xdr.c                |  19 ++--
 fs/nfs/symlink.c                |   1 +
 fs/nfsd/nfs4proc.c              |   9 ++
 fs/nfsd/nfs4xdr.c               |  40 +++++---
 fs/nfsd/vfs.c                   |  17 ++++
 fs/nfsd/vfs.h                   |   4 +-
 fs/nfsd/xdr4.h                  |   3 +
 fs/ntfs3/file.c                 |  20 +++-
 fs/ntfs3/frecord.c              |   8 +-
 fs/smb/client/cifsfs.c          |   8 ++
 fs/smb/client/inode.c           |   7 +-
 fs/smb/client/ioctl.c           | 109 ++++++++++++++++------
 fs/smb/server/smb2pdu.c         |  37 +++++---
 fs/smb/server/vfs.c             |  43 ++++++++-
 fs/smb/server/vfs.h             |   1 +
 fs/stat.c                       |   2 +
 include/linux/fileattr.h        |  29 +++++-
 include/linux/nfs_xdr.h         |   3 +
 include/linux/stat.h            |   1 +
 include/uapi/linux/btrfs_tree.h |   3 +-
 include/uapi/linux/fs.h         |   9 +-
 include/uapi/linux/stat.h       |   7 +-
 35 files changed, 614 insertions(+), 119 deletions(-)
Quoted 4 lines

base-commit: 3bc1fb9c3b20cd478c83496ab16addecb401770d
prerequisite-patch-id: 049ae0eba275b5be35a238833107e0b251a55aa2
prerequisite-patch-id: 614f0bc9411391403d4e9702bafeb31b0ec04ec1
prerequisite-patch-id: ddf636b9d33d82ea206ce265d817371350bf8858

I think this is going to be very hard to do properly, because the kernel can't really manage this on its own. Something in userland is going to have to set this value if you want to update it to something other than the original inode instantiation time (aka btime).

It really sounds like what you want is the ability to make the btime settable. Personally I think the decision to forbid that was wrong- headed and that it should have been settable from userland from the beginning. Maybe we should just revisit that decision.

Frankly, I don't think this decision was made at all.

There are only 2 types of filesystems in Linux today:
1. btime is constant (xfs, etx4, btrfs,...)
2. crtime is settable in principle but not via a standardized Linux API (ntfs, cifs, ...)

AFAIK, btrfs in this series is the only filesystem which is going to have two deviated copies of btime and ptime.
For all the rest, the deviation is artificial in statx.

So the questions to ask are:
1. Do btrfs developers prefer to store a new settable ptime or making otime/btime settable with this new API?
2. Will any other fs in the future want to store settable ptime along side the legacy immutable btime?

My take on these question is:
- Personally I would love to see ptime support in xfs in the future and would willing to contribute to this work, because I have hard evidence from the performance benefits that it brings to smb server workloads
- Judging by past experience with i_version bump interpretation on xfs, I find it hard to believe that xfs developer would agree to making the legacy btime settable

Hence the distinction in statx API is needed, but for most filesystems it is a pure semantic way of saying "I do/don't have settable birth time".

Quoted 7 lines

Originally I just wanted to have btime settable, yes, and if btime was settable I wouldn't have made this RFC PATCH either, but after reading the already existing discussions about it, I can understand having an "immutable inode creation time", like ctime exists, so even after making btime settable, a new timestamp would be necessary anyway (e.g. for the people who want btime to exist as a forensics timestamp).

Right, but every filesystem (e.g. btrfs) can still make an independent choice whether storing one or two copies is desired.
The API does not limit those choices.

Quoted 8 lines
Quoted 5 lines

Failing that, why not just track this in an xattr of some sort, since this is really just an opaque blob once you allow it to be settable. If the xattr isn't present, then you can just use the value of the btime as-is. FWIW, I think samba does this today, so you could try to sync with its behavior here.

(This is copied and adapted from [2])

Quoted 13 lines

I actually have been using fully userspace xattrs[1] for a few months, mostly for backups, and it "works"; but last month I wanted to merge 2 FSs (and have another merge I have to do), so I ran [1] on all files and then compared all metadata/data between source and destination and noticed there were quite a lot of files that didn't have the xattr set. So I looked online and learned that xattrs only work on regular files/directories, not on symlinks or anything else (and the missing ones were of symlinks).
This is what prompted me to search more if anyone had already proposed a new timestamp (instead of making btime settable) and found the email thread from april linked in the cover letter, which gave me the excuse to finally work on a proper patch.

I am tired of repeating my arguments (and finding my own quotes) about why using xattrs is a poor replacement for in-inode ptime. AI agents can easily find those quotes for those who are interested so I won't bother, I just say that smbd already uses xattr to store the creation time - it's just bad for performance and disk usage in metadata intensive workloads.

Quoted 9 lines
Quoted 8 lines

That seems a lot simpler than adding an entirely new inode timestamp that is always going to be a copy of the btime, except in rare cases. Having to patch all of the on-disk filesystems with a new per-inode field is a lot more work.

This patch is quite simple, but changing btrfs, then ext4, xfs, etc is a mess, and inevitably you can't get these timestamps until you upgrade your filesystems.

Jeff, this is standard "how to make progress".
I completely don't agree with this argument.
We cannot use this argument to block progress.
Is it already a long standing practice for userspace file servers (samba) to probe the host filesystem for specific features and fall back to alternative implementation if they are not supported.

There will be nothing new in this case, that's the only way to make forward progress - define the API, make support queryable, implement the feature in some filesystems, implement consumers, repeat.

Also for nfsd, that's the only way to ever implement settable FATTR4_TIME_CREATE which is the protocol allows.
This is never going to be possible with custom xattrs.
So I must say that I don't understand the objection from you and Chuck

Thanks,
Amir.

author
#48 lore raw
Quoted 190 lines · Amir Goldstein
Quoted 39 lines · koraynilay

Hello and thanks for replying,

Quoted 15 lines · Jeff Layton
Quoted 14 lines · koraynilay

This is an initial implementation of a new timestamp to indicate the time when a file/directory was initially created.

This patch series takes inspiration from the one by Sean Smith <[email protected]> [1], but using file_setattr()/file_getattr() as suggested by Darrick J. Wong <[email protected]> in [2].

The semantics of this new timestamp should be at least these:
- it should be the same as btime on a newly created file
- it's user-settable, so it can be preserved for backups, filesystem conversions, archives and any similar operation
- it should be preserved every time mtime gets preserved

Quoted 7 lines
Quoted 5 lines

and the correspondence with the other timestamps is as follows:

ctime <-> btime
mtime <-> ptime

I'm not sure how to interpret the correspondence above.

  |-----\_-----------------|-----------|
  |       \_      change/  |   birth/  |
  |         \_ modification|  creation |
  |           \------------|-----------|
  | inode time |   ctime   |   btime   |
  |------------|-----------|-----------|
  | file time  |   mtime   |   ptime   |
  |------------|-----------|-----------|

("file" as in "the concept of this file", I'd say "file content" but that would be incorrect for symlinks)

Quoted 147 lines

so ctime is "inode change time", btime is "inode birth/creation time", while mtime is "file content change/modification time" and ptime would be "file content creation time" (same as Window's or MacOS's creation time).

Does this make more sense?

Quoted 139 lines
Quoted 125 lines

Examples:
1) a .zsh_history file created in 2019, then after a few years the user decides to switch to another filesystem, copying the .zsh_history to the new home, in that case btime would have the timestamp of the copy and ptime would have the 2019 timestamp (just like mtime would have been preserved)
2) a symlink created in 2020 from the home directory to a /path going through the same process as the .zsh_history, in this case it would also make sense to sync the ptime to the 2020 timestamp instead of keeping only the btime (so the inode creation time).

The proof-of-concept code (for testing) for stat(1) and cp(1) is available at https://github.com/koraynilay/coreutils (master branch) (Note: these coreutils code changes are a prototype and won't be submitted upstream as-is, but they work as expected in simple stat and cp -a/--preserve=ptime tests)

Lastly, the name "provenance" and "ptime" are not final, I personally don't have a strong opinion on any name, but while testing with stat(1) I noticed that "Provenance" is definitely too long for the normal output, so another option which would fit well is "Origin time", abbreviated as "ntime" (OrigiN time) and not as "otime", as that would conflict with btrfs' internal naming and create confusion.

v2 changes:
- fix permission bypass leading to ptime update on immutable and append-only files (found by sashiko[3])
- normalize ptime timestamp as done in fs/attr.c:notify_change() (found by sashiko[3])
- fix wording in vfs patch to be like the cover-letter

v3 changes:
- vfs: reject setting ptime with -EOPNOTSUPP on filesystems that do not support it instead of silently ignoring it (found by sashiko[4])
- vfs: fix not being able to clear immutable and append-only on files with ptime, and allow updating immutable/append-only atomically along with ptime (found by sashiko[4])
- btrfs: validate on-disk ptime nanoseconds and reset to otime if invalid (found by sashiko[4])
- btrfs: avoid re-assigning ptime on unrelated chattr calls (found by sashiko[4])
- add ntfs3 and exfat support as suggested by Amir Goldstein[5], but no vfat, smb, or nfs4 yet as they are a bit more complex
- move the introduction of fileattr_has_fsx_mask() from the btrfs patch to a standalone patch in the series
- btrfs: add fileattr_[gs]et to symlink and special file operations

v4 changes:
- vfs: implement fsx_xflags_mask as suggested by Amir Goldstein[6];
- add SMB (ksmbd/cifs) and nfs (nfsd/nfs) support as requested in previous threads;

Note:
to apply this patch 2 previous patches[7][8] from the ksmbd/cifs subsystem are needed.

New Question:
should I rename fileattr_has_fsx_mask() to something like fileattr_has_unsupported_fsx() and keep its code as-is, or should I add the fsx_xflags_mask & ~allowed check in it and keep the name as-is? (or both?)

Thanks.

[1]: https://lore.kernel.org/[email protected]
[2]: https://lore.kernel.org/20260407014129.GC6192@frogsfrogsfrogs
[3]: https://sashiko.dev/#/patchset/20261027220532.736352-1-koray.fra%40gmail.com
[4]: https://sashiko.dev/#/patchset/20261028134728.294127-1-koray.fra%40gmail.com
[5]: https://lore.kernel.org/CAOQ4uxiuy0VwZj+3M-zRqQ49WTpHZpiaQ+6MZ8z8WdLjyQM_zA@mail.gmail.com/
[6]: https://lore.kernel.org/CAOQ4uxjtuTDT63vJdYaq+RHQEQFLTksp66e46OMN99WhJz3SbA@mail.gmail.com/
[7]: https://lore.kernel.org/linux-cifs/[email protected]/
[8]: https://lore.kernel.org/linux-cifs/[email protected]/

koraynilay (10):
vfs: add provenance time (ptime)
vfs: add fileattr_has_fsx_mask()
ntfs3: make crtime user-settable using ptime
exfat: make crtime user-settable using ptime
btrfs: add provenance time (ptime)
vfs: add __vfs_fileattr_set_locked() for inode_lock()'d callers
nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE
nfs: add provenance time (ptime) via FATTR4_TIME_CREATE
ksmbd: add provenance time (ptime) and map it to CreationTime
cifs: add provenance time (ptime) and map it to SMB's CreationTime

 fs/btrfs/btrfs_inode.h          |   4 +
 fs/btrfs/delayed-inode.c        |   6 ++
 fs/btrfs/inode.c                |  29 +++++-
 fs/btrfs/ioctl.c                |  24 ++++-
 fs/btrfs/print-tree.c           |   1 +
 fs/btrfs/tree-log.c             |   3 +
 fs/exfat/exfat_fs.h             |   2 +
 fs/exfat/file.c                 |  42 ++++++++-
 fs/exfat/namei.c                |   1 +
 fs/file_attr.c                  | 156 ++++++++++++++++++++++++++------
 fs/nfs/inode.c                  |  27 +++++-
 fs/nfs/internal.h               |   2 +
 fs/nfs/nfs4proc.c               |  56 +++++++++++-
 fs/nfs/nfs4xdr.c                |  19 ++--
 fs/nfs/symlink.c                |   1 +
 fs/nfsd/nfs4proc.c              |   9 ++
 fs/nfsd/nfs4xdr.c               |  40 +++++---
 fs/nfsd/vfs.c                   |  17 ++++
 fs/nfsd/vfs.h                   |   4 +-
 fs/nfsd/xdr4.h                  |   3 +
 fs/ntfs3/file.c                 |  20 +++-
 fs/ntfs3/frecord.c              |   8 +-
 fs/smb/client/cifsfs.c          |   8 ++
 fs/smb/client/inode.c           |   7 +-
 fs/smb/client/ioctl.c           | 109 ++++++++++++++++------
 fs/smb/server/smb2pdu.c         |  37 +++++---
 fs/smb/server/vfs.c             |  43 ++++++++-
 fs/smb/server/vfs.h             |   1 +
 fs/stat.c                       |   2 +
 include/linux/fileattr.h        |  29 +++++-
 include/linux/nfs_xdr.h         |   3 +
 include/linux/stat.h            |   1 +
 include/uapi/linux/btrfs_tree.h |   3 +-
 include/uapi/linux/fs.h         |   9 +-
 include/uapi/linux/stat.h       |   7 +-
 35 files changed, 614 insertions(+), 119 deletions(-)
Quoted 4 lines

base-commit: 3bc1fb9c3b20cd478c83496ab16addecb401770d
prerequisite-patch-id: 049ae0eba275b5be35a238833107e0b251a55aa2
prerequisite-patch-id: 614f0bc9411391403d4e9702bafeb31b0ec04ec1
prerequisite-patch-id: ddf636b9d33d82ea206ce265d817371350bf8858

I think this is going to be very hard to do properly, because the kernel can't really manage this on its own. Something in userland is going to have to set this value if you want to update it to something other than the original inode instantiation time (aka btime).

It really sounds like what you want is the ability to make the btime settable. Personally I think the decision to forbid that was wrong- headed and that it should have been settable from userland from the beginning. Maybe we should just revisit that decision.

Frankly, I don't think this decision was made at all.

Quoted 8 lines

There are only 2 types of filesystems in Linux today:
1. btime is constant (xfs, etx4, btrfs,...)
2. crtime is settable in principle but not via a standardized Linux API (ntfs, cifs, ...)

AFAIK, btrfs in this series is the only filesystem which is going to have two deviated copies of btime and ptime.
For all the rest, the deviation is artificial in statx.

Well, my objective with this series would be having ptime just as supported as a/c/m/btime, especially from userspace in the 90% of setups,

Quoted 6 lines

So the questions to ask are:
1. Do btrfs developers prefer to store a new settable ptime or making otime/btime settable with this new API?
2. Will any other fs in the future want to store settable ptime along side the legacy immutable btime?

Quoted 7 lines

My take on these question is:
- Personally I would love to see ptime support in xfs in the future and would willing to contribute to this work, because I have hard evidence from the performance benefits that it brings to smb server workloads
- Judging by past experience with i_version bump interpretation on xfs, I find it hard to believe that xfs developer would agree to making the legacy btime settable

so I guess for v5 or v6 I'll also draft a patch for at least ext4 and xfs.

Quoted 37 lines

Hence the distinction in statx API is needed, but for most filesystems it is a pure semantic way of saying "I do/don't have settable birth time".

Quoted 7 lines

Originally I just wanted to have btime settable, yes, and if btime was settable I wouldn't have made this RFC PATCH either, but after reading the already existing discussions about it, I can understand having an "immutable inode creation time", like ctime exists, so even after making btime settable, a new timestamp would be necessary anyway (e.g. for the people who want btime to exist as a forensics timestamp).

Right, but every filesystem (e.g. btrfs) can still make an independent choice whether storing one or two copies is desired.
The API does not limit those choices.

Quoted 8 lines
Quoted 5 lines

Failing that, why not just track this in an xattr of some sort, since this is really just an opaque blob once you allow it to be settable. If the xattr isn't present, then you can just use the value of the btime as-is. FWIW, I think samba does this today, so you could try to sync with its behavior here.

(This is copied and adapted from [2])

Quoted 13 lines

I actually have been using fully userspace xattrs[1] for a few months, mostly for backups, and it "works"; but last month I wanted to merge 2 FSs (and have another merge I have to do), so I ran [1] on all files and then compared all metadata/data between source and destination and noticed there were quite a lot of files that didn't have the xattr set. So I looked online and learned that xattrs only work on regular files/directories, not on symlinks or anything else (and the missing ones were of symlinks).
This is what prompted me to search more if anyone had already proposed a new timestamp (instead of making btime settable) and found the email thread from april linked in the cover letter, which gave me the excuse to finally work on a proper patch.

Quoted 6 lines

I am tired of repeating my arguments (and finding my own quotes) about why using xattrs is a poor replacement for in-inode ptime. AI agents can easily find those quotes for those who are interested so I won't bother, I just say that smbd already uses xattr to store the creation time - it's just bad for performance and disk usage in metadata intensive workloads.

(I really need to remember to add the xattr explanation in the cover letter, it's been 3 version since I wanted to but forgot lol)

Quoted 17 lines
Quoted 9 lines
Quoted 8 lines

That seems a lot simpler than adding an entirely new inode timestamp that is always going to be a copy of the btime, except in rare cases. Having to patch all of the on-disk filesystems with a new per-inode field is a lot more work.

This patch is quite simple, but changing btrfs, then ext4, xfs, etc is a mess, and inevitably you can't get these timestamps until you upgrade your filesystems.

Jeff, this is standard "how to make progress".
I completely don't agree with this argument.
We cannot use this argument to block progress.
Is it already a long standing practice for userspace file servers (samba) to probe the host filesystem for specific features and fall back to alternative implementation if they are not supported.

Quoted 8 lines

There will be nothing new in this case, that's the only way to make forward progress - define the API, make support queryable, implement the feature in some filesystems, implement consumers, repeat.

Also for nfsd, that's the only way to ever implement settable FATTR4_TIME_CREATE which is the protocol allows.
This is never going to be possible with custom xattrs.
So I must say that I don't understand the objection from you and Chuck

Thanks,
koraynilay

Quoted 2 lines

Thanks,
Amir.

#49 lore raw
Quoted 197 lines · koraynilay
Quoted 195 lines · Amir Goldstein
Quoted 39 lines · koraynilay

Hello and thanks for replying,

Quoted 15 lines · Jeff Layton
Quoted 14 lines · koraynilay

This is an initial implementation of a new timestamp to indicate the time when a file/directory was initially created.

This patch series takes inspiration from the one by Sean Smith <[email protected]> [1], but using file_setattr()/file_getattr() as suggested by Darrick J. Wong <[email protected]> in [2].

The semantics of this new timestamp should be at least these:
- it should be the same as btime on a newly created file
- it's user-settable, so it can be preserved for backups, filesystem conversions, archives and any similar operation
- it should be preserved every time mtime gets preserved

Quoted 7 lines
Quoted 5 lines

and the correspondence with the other timestamps is as follows:

ctime <-> btime
mtime <-> ptime

I'm not sure how to interpret the correspondence above.

  |-----\_-----------------|-----------|
  |       \_      change/  |   birth/  |
  |         \_ modification|  creation |
  |           \------------|-----------|
  | inode time |   ctime   |   btime   |
  |------------|-----------|-----------|
  | file time  |   mtime   |   ptime   |
  |------------|-----------|-----------|

("file" as in "the concept of this file", I'd say "file content" but that would be incorrect for symlinks)

Quoted 147 lines

so ctime is "inode change time", btime is "inode birth/creation time", while mtime is "file content change/modification time" and ptime would be "file content creation time" (same as Window's or MacOS's creation time).

Does this make more sense?

Quoted 139 lines
Quoted 125 lines

Examples:
1) a .zsh_history file created in 2019, then after a few years the user decides to switch to another filesystem, copying the .zsh_history to the new home, in that case btime would have the timestamp of the copy and ptime would have the 2019 timestamp (just like mtime would have been preserved)
2) a symlink created in 2020 from the home directory to a /path going through the same process as the .zsh_history, in this case it would also make sense to sync the ptime to the 2020 timestamp instead of keeping only the btime (so the inode creation time).

The proof-of-concept code (for testing) for stat(1) and cp(1) is available at https://github.com/koraynilay/coreutils (master branch) (Note: these coreutils code changes are a prototype and won't be submitted upstream as-is, but they work as expected in simple stat and cp -a/--preserve=ptime tests)

Lastly, the name "provenance" and "ptime" are not final, I personally don't have a strong opinion on any name, but while testing with stat(1) I noticed that "Provenance" is definitely too long for the normal output, so another option which would fit well is "Origin time", abbreviated as "ntime" (OrigiN time) and not as "otime", as that would conflict with btrfs' internal naming and create confusion.

v2 changes:
- fix permission bypass leading to ptime update on immutable and append-only files (found by sashiko[3])
- normalize ptime timestamp as done in fs/attr.c:notify_change() (found by sashiko[3])
- fix wording in vfs patch to be like the cover-letter

v3 changes:
- vfs: reject setting ptime with -EOPNOTSUPP on filesystems that do not support it instead of silently ignoring it (found by sashiko[4])
- vfs: fix not being able to clear immutable and append-only on files with ptime, and allow updating immutable/append-only atomically along with ptime (found by sashiko[4])
- btrfs: validate on-disk ptime nanoseconds and reset to otime if invalid (found by sashiko[4])
- btrfs: avoid re-assigning ptime on unrelated chattr calls (found by sashiko[4])
- add ntfs3 and exfat support as suggested by Amir Goldstein[5], but no vfat, smb, or nfs4 yet as they are a bit more complex
- move the introduction of fileattr_has_fsx_mask() from the btrfs patch to a standalone patch in the series
- btrfs: add fileattr_[gs]et to symlink and special file operations

v4 changes:
- vfs: implement fsx_xflags_mask as suggested by Amir Goldstein[6];
- add SMB (ksmbd/cifs) and nfs (nfsd/nfs) support as requested in previous threads;

Note:
to apply this patch 2 previous patches[7][8] from the ksmbd/cifs subsystem are needed.

New Question:
should I rename fileattr_has_fsx_mask() to something like fileattr_has_unsupported_fsx() and keep its code as-is, or should I add the fsx_xflags_mask & ~allowed check in it and keep the name as-is? (or both?)

Thanks.

[1]: https://lore.kernel.org/[email protected]
[2]: https://lore.kernel.org/20260407014129.GC6192@frogsfrogsfrogs
[3]: https://sashiko.dev/#/patchset/20261027220532.736352-1-koray.fra%40gmail.com
[4]: https://sashiko.dev/#/patchset/20261028134728.294127-1-koray.fra%40gmail.com
[5]: https://lore.kernel.org/CAOQ4uxiuy0VwZj+3M-zRqQ49WTpHZpiaQ+6MZ8z8WdLjyQM_zA@mail.gmail.com/
[6]: https://lore.kernel.org/CAOQ4uxjtuTDT63vJdYaq+RHQEQFLTksp66e46OMN99WhJz3SbA@mail.gmail.com/
[7]: https://lore.kernel.org/linux-cifs/[email protected]/
[8]: https://lore.kernel.org/linux-cifs/[email protected]/

koraynilay (10):
vfs: add provenance time (ptime)
vfs: add fileattr_has_fsx_mask()
ntfs3: make crtime user-settable using ptime
exfat: make crtime user-settable using ptime
btrfs: add provenance time (ptime)
vfs: add __vfs_fileattr_set_locked() for inode_lock()'d callers
nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE
nfs: add provenance time (ptime) via FATTR4_TIME_CREATE
ksmbd: add provenance time (ptime) and map it to CreationTime
cifs: add provenance time (ptime) and map it to SMB's CreationTime

 fs/btrfs/btrfs_inode.h          |   4 +
 fs/btrfs/delayed-inode.c        |   6 ++
 fs/btrfs/inode.c                |  29 +++++-
 fs/btrfs/ioctl.c                |  24 ++++-
 fs/btrfs/print-tree.c           |   1 +
 fs/btrfs/tree-log.c             |   3 +
 fs/exfat/exfat_fs.h             |   2 +
 fs/exfat/file.c                 |  42 ++++++++-
 fs/exfat/namei.c                |   1 +
 fs/file_attr.c                  | 156 ++++++++++++++++++++++++++------
 fs/nfs/inode.c                  |  27 +++++-
 fs/nfs/internal.h               |   2 +
 fs/nfs/nfs4proc.c               |  56 +++++++++++-
 fs/nfs/nfs4xdr.c                |  19 ++--
 fs/nfs/symlink.c                |   1 +
 fs/nfsd/nfs4proc.c              |   9 ++
 fs/nfsd/nfs4xdr.c               |  40 +++++---
 fs/nfsd/vfs.c                   |  17 ++++
 fs/nfsd/vfs.h                   |   4 +-
 fs/nfsd/xdr4.h                  |   3 +
 fs/ntfs3/file.c                 |  20 +++-
 fs/ntfs3/frecord.c              |   8 +-
 fs/smb/client/cifsfs.c          |   8 ++
 fs/smb/client/inode.c           |   7 +-
 fs/smb/client/ioctl.c           | 109 ++++++++++++++++------
 fs/smb/server/smb2pdu.c         |  37 +++++---
 fs/smb/server/vfs.c             |  43 ++++++++-
 fs/smb/server/vfs.h             |   1 +
 fs/stat.c                       |   2 +
 include/linux/fileattr.h        |  29 +++++-
 include/linux/nfs_xdr.h         |   3 +
 include/linux/stat.h            |   1 +
 include/uapi/linux/btrfs_tree.h |   3 +-
 include/uapi/linux/fs.h         |   9 +-
 include/uapi/linux/stat.h       |   7 +-
 35 files changed, 614 insertions(+), 119 deletions(-)
Quoted 4 lines

base-commit: 3bc1fb9c3b20cd478c83496ab16addecb401770d
prerequisite-patch-id: 049ae0eba275b5be35a238833107e0b251a55aa2
prerequisite-patch-id: 614f0bc9411391403d4e9702bafeb31b0ec04ec1
prerequisite-patch-id: ddf636b9d33d82ea206ce265d817371350bf8858

I think this is going to be very hard to do properly, because the kernel can't really manage this on its own. Something in userland is going to have to set this value if you want to update it to something other than the original inode instantiation time (aka btime).

It really sounds like what you want is the ability to make the btime settable. Personally I think the decision to forbid that was wrong- headed and that it should have been settable from userland from the beginning. Maybe we should just revisit that decision.

Frankly, I don't think this decision was made at all.

There are only 2 types of filesystems in Linux today:
1. btime is constant (xfs, etx4, btrfs,...)
2. crtime is settable in principle but not via a standardized Linux API (ntfs, cifs, ...)

Quoted 8 lines
Quoted 3 lines

AFAIK, btrfs in this series is the only filesystem which is going to have two deviated copies of btime and ptime.
For all the rest, the deviation is artificial in statx.

Well, my objective with this series would be having ptime just as supported as a/c/m/btime, especially from userspace in the 90% of setups,

This is not a realistic objective for the mid term IMO. Even if you did go through all the cruciating steps on adding on-disk ptime support for ext4/xfs/... old formatted filesystems may or may not be allowed to set the new inode field (per maintainer's decision) and the stable kernels will take a long time to get those changes, so userspace tools will not be able to assume support for ptime exists for a long while.

Maybe 90% support is a realistic objective, depending on the time windows you set for this objective to manifest...

IMO the more realistic goal is to allow rsync/etc between the fs that already support ptime, for example between two smb mounts or within the same smb mount.

Quoted 14 lines
Quoted 6 lines

So the questions to ask are:
1. Do btrfs developers prefer to store a new settable ptime or making otime/btime settable with this new API?
2. Will any other fs in the future want to store settable ptime along side the legacy immutable btime?

Quoted 7 lines

My take on these question is:
- Personally I would love to see ptime support in xfs in the future and would willing to contribute to this work, because I have hard evidence from the performance benefits that it brings to smb server workloads
- Judging by past experience with i_version bump interpretation on xfs, I find it hard to believe that xfs developer would agree to making the legacy btime settable

Quoted 2 lines

so I guess for v5 or v6 I'll also draft a patch for at least ext4 and xfs.

I strongly advise you against this.

That's a great way to block your own patch set indefinitely.

Implementing ptime for ext4/xfs requires working with each of the maintainers not only on kernel but also on the userspace progs and has backward compat implications, which makes testing ever so much harder.

You start with defining an API and implement it for the filesystems that already have storage for ptime.

You could include a new fs that didn't have storage for ptime (btrfs) if you are on the same page with the btrfs maintainers and have the userspace tools patches lined up for review as well.

Otherwise, you will just be blocking your own patch set creating dependencies with other user space tools.

Thanks,
Amir.

author
#50 lore raw
Quoted 202 lines · Amir Goldstein
Quoted 201 lines · koraynilay
Quoted 198 lines · Amir Goldstein
Quoted 39 lines · koraynilay

Hello and thanks for replying,

Quoted 15 lines · Jeff Layton
Quoted 14 lines · koraynilay

This is an initial implementation of a new timestamp to indicate the time when a file/directory was initially created.

This patch series takes inspiration from the one by Sean Smith <[email protected]> [1], but using file_setattr()/file_getattr() as suggested by Darrick J. Wong <[email protected]> in [2].

The semantics of this new timestamp should be at least these:
- it should be the same as btime on a newly created file
- it's user-settable, so it can be preserved for backups, filesystem conversions, archives and any similar operation
- it should be preserved every time mtime gets preserved

Quoted 7 lines
Quoted 5 lines

and the correspondence with the other timestamps is as follows:

ctime <-> btime
mtime <-> ptime

I'm not sure how to interpret the correspondence above.

  |-----\_-----------------|-----------|
  |       \_      change/  |   birth/  |
  |         \_ modification|  creation |
  |           \------------|-----------|
  | inode time |   ctime   |   btime   |
  |------------|-----------|-----------|
  | file time  |   mtime   |   ptime   |
  |------------|-----------|-----------|

("file" as in "the concept of this file", I'd say "file content" but that would be incorrect for symlinks)

Quoted 147 lines

so ctime is "inode change time", btime is "inode birth/creation time", while mtime is "file content change/modification time" and ptime would be "file content creation time" (same as Window's or MacOS's creation time).

Does this make more sense?

Quoted 139 lines
Quoted 125 lines

Examples:
1) a .zsh_history file created in 2019, then after a few years the user decides to switch to another filesystem, copying the .zsh_history to the new home, in that case btime would have the timestamp of the copy and ptime would have the 2019 timestamp (just like mtime would have been preserved)
2) a symlink created in 2020 from the home directory to a /path going through the same process as the .zsh_history, in this case it would also make sense to sync the ptime to the 2020 timestamp instead of keeping only the btime (so the inode creation time).

The proof-of-concept code (for testing) for stat(1) and cp(1) is available at https://github.com/koraynilay/coreutils (master branch) (Note: these coreutils code changes are a prototype and won't be submitted upstream as-is, but they work as expected in simple stat and cp -a/--preserve=ptime tests)

Lastly, the name "provenance" and "ptime" are not final, I personally don't have a strong opinion on any name, but while testing with stat(1) I noticed that "Provenance" is definitely too long for the normal output, so another option which would fit well is "Origin time", abbreviated as "ntime" (OrigiN time) and not as "otime", as that would conflict with btrfs' internal naming and create confusion.

v2 changes:
- fix permission bypass leading to ptime update on immutable and append-only files (found by sashiko[3])
- normalize ptime timestamp as done in fs/attr.c:notify_change() (found by sashiko[3])
- fix wording in vfs patch to be like the cover-letter

v3 changes:
- vfs: reject setting ptime with -EOPNOTSUPP on filesystems that do not support it instead of silently ignoring it (found by sashiko[4])
- vfs: fix not being able to clear immutable and append-only on files with ptime, and allow updating immutable/append-only atomically along with ptime (found by sashiko[4])
- btrfs: validate on-disk ptime nanoseconds and reset to otime if invalid (found by sashiko[4])
- btrfs: avoid re-assigning ptime on unrelated chattr calls (found by sashiko[4])
- add ntfs3 and exfat support as suggested by Amir Goldstein[5], but no vfat, smb, or nfs4 yet as they are a bit more complex
- move the introduction of fileattr_has_fsx_mask() from the btrfs patch to a standalone patch in the series
- btrfs: add fileattr_[gs]et to symlink and special file operations

v4 changes:
- vfs: implement fsx_xflags_mask as suggested by Amir Goldstein[6];
- add SMB (ksmbd/cifs) and nfs (nfsd/nfs) support as requested in previous threads;

Note:
to apply this patch 2 previous patches[7][8] from the ksmbd/cifs subsystem are needed.

New Question:
should I rename fileattr_has_fsx_mask() to something like fileattr_has_unsupported_fsx() and keep its code as-is, or should I add the fsx_xflags_mask & ~allowed check in it and keep the name as-is? (or both?)

Thanks.

[1]: https://lore.kernel.org/[email protected]
[2]: https://lore.kernel.org/20260407014129.GC6192@frogsfrogsfrogs
[3]: https://sashiko.dev/#/patchset/20261027220532.736352-1-koray.fra%40gmail.com
[4]: https://sashiko.dev/#/patchset/20261028134728.294127-1-koray.fra%40gmail.com
[5]: https://lore.kernel.org/CAOQ4uxiuy0VwZj+3M-zRqQ49WTpHZpiaQ+6MZ8z8WdLjyQM_zA@mail.gmail.com/
[6]: https://lore.kernel.org/CAOQ4uxjtuTDT63vJdYaq+RHQEQFLTksp66e46OMN99WhJz3SbA@mail.gmail.com/
[7]: https://lore.kernel.org/linux-cifs/[email protected]/
[8]: https://lore.kernel.org/linux-cifs/[email protected]/

koraynilay (10):
vfs: add provenance time (ptime)
vfs: add fileattr_has_fsx_mask()
ntfs3: make crtime user-settable using ptime
exfat: make crtime user-settable using ptime
btrfs: add provenance time (ptime)
vfs: add __vfs_fileattr_set_locked() for inode_lock()'d callers
nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE
nfs: add provenance time (ptime) via FATTR4_TIME_CREATE
ksmbd: add provenance time (ptime) and map it to CreationTime
cifs: add provenance time (ptime) and map it to SMB's CreationTime

 fs/btrfs/btrfs_inode.h          |   4 +
 fs/btrfs/delayed-inode.c        |   6 ++
 fs/btrfs/inode.c                |  29 +++++-
 fs/btrfs/ioctl.c                |  24 ++++-
 fs/btrfs/print-tree.c           |   1 +
 fs/btrfs/tree-log.c             |   3 +
 fs/exfat/exfat_fs.h             |   2 +
 fs/exfat/file.c                 |  42 ++++++++-
 fs/exfat/namei.c                |   1 +
 fs/file_attr.c                  | 156 ++++++++++++++++++++++++++------
 fs/nfs/inode.c                  |  27 +++++-
 fs/nfs/internal.h               |   2 +
 fs/nfs/nfs4proc.c               |  56 +++++++++++-
 fs/nfs/nfs4xdr.c                |  19 ++--
 fs/nfs/symlink.c                |   1 +
 fs/nfsd/nfs4proc.c              |   9 ++
 fs/nfsd/nfs4xdr.c               |  40 +++++---
 fs/nfsd/vfs.c                   |  17 ++++
 fs/nfsd/vfs.h                   |   4 +-
 fs/nfsd/xdr4.h                  |   3 +
 fs/ntfs3/file.c                 |  20 +++-
 fs/ntfs3/frecord.c              |   8 +-
 fs/smb/client/cifsfs.c          |   8 ++
 fs/smb/client/inode.c           |   7 +-
 fs/smb/client/ioctl.c           | 109 ++++++++++++++++------
 fs/smb/server/smb2pdu.c         |  37 +++++---
 fs/smb/server/vfs.c             |  43 ++++++++-
 fs/smb/server/vfs.h             |   1 +
 fs/stat.c                       |   2 +
 include/linux/fileattr.h        |  29 +++++-
 include/linux/nfs_xdr.h         |   3 +
 include/linux/stat.h            |   1 +
 include/uapi/linux/btrfs_tree.h |   3 +-
 include/uapi/linux/fs.h         |   9 +-
 include/uapi/linux/stat.h       |   7 +-
 35 files changed, 614 insertions(+), 119 deletions(-)
Quoted 4 lines

base-commit: 3bc1fb9c3b20cd478c83496ab16addecb401770d
prerequisite-patch-id: 049ae0eba275b5be35a238833107e0b251a55aa2
prerequisite-patch-id: 614f0bc9411391403d4e9702bafeb31b0ec04ec1
prerequisite-patch-id: ddf636b9d33d82ea206ce265d817371350bf8858

I think this is going to be very hard to do properly, because the kernel can't really manage this on its own. Something in userland is going to have to set this value if you want to update it to something other than the original inode instantiation time (aka btime).

It really sounds like what you want is the ability to make the btime settable. Personally I think the decision to forbid that was wrong- headed and that it should have been settable from userland from the beginning. Maybe we should just revisit that decision.

Frankly, I don't think this decision was made at all.

There are only 2 types of filesystems in Linux today:
1. btime is constant (xfs, etx4, btrfs,...)
2. crtime is settable in principle but not via a standardized Linux API (ntfs, cifs, ...)

AFAIK, btrfs in this series is the only filesystem which is going to have two deviated copies of btime and ptime.
For all the rest, the deviation is artificial in statx.

Quoted 6 lines
Quoted 4 lines

Well, my objective with this series would be having ptime just as supported as a/c/m/btime, especially from userspace in the 90% of setups,

This is not a realistic objective for the mid term IMO.

Yes, that would indeed be a long-term objective.
But thinking about it, it does make more sense to have a patch series for an intial implementation and then future patches for the single filesystems.

Quoted 9 lines

Even if you did go through all the cruciating steps on adding on-disk ptime support for ext4/xfs/... old formatted filesystems may or may not be allowed to set the new inode field (per maintainer's decision) and the stable kernels will take a long time to get those changes, so userspace tools will not be able to assume support for ptime exists for a long while.

Maybe 90% support is a realistic objective, depending on the time windows you set for this objective to manifest...

For 90+% support (like btime has) I have like 1/2 years in mind, but I haven't thought about it too much.

Quoted 3 lines

IMO the more realistic goal is to allow rsync/etc between the fs that already support ptime, for example between two smb mounts or within the same smb mount.

Fair.

Quoted 21 lines
Quoted 14 lines
Quoted 6 lines

So the questions to ask are:
1. Do btrfs developers prefer to store a new settable ptime or making otime/btime settable with this new API?
2. Will any other fs in the future want to store settable ptime along side the legacy immutable btime?

Quoted 7 lines

My take on these question is:
- Personally I would love to see ptime support in xfs in the future and would willing to contribute to this work, because I have hard evidence from the performance benefits that it brings to smb server workloads
- Judging by past experience with i_version bump interpretation on xfs, I find it hard to believe that xfs developer would agree to making the legacy btime settable

Quoted 2 lines

so I guess for v5 or v6 I'll also draft a patch for at least ext4 and xfs.

I strongly advise you against this.

That's a great way to block your own patch set indefinitely.

Quoted 7 lines

Implementing ptime for ext4/xfs requires working with each of the maintainers not only on kernel but also on the userspace progs and has backward compat implications, which makes testing ever so much harder.

You start with defining an API and implement it for the filesystems that already have storage for ptime.

Fair, that makes sense.

Quoted 3 lines

You could include a new fs that didn't have storage for ptime (btrfs) if you are on the same page with the btrfs maintainers and have the userspace tools patches lined up for review as well.

Btrfs is where I would like it the most as that's the one I need it on, so hopefully I can get it merged there.

Quoted 2 lines

Otherwise, you will just be blocking your own patch set creating dependencies with other user space tools.

I do plan on personally adding support for ptime on at least the most used userspace tools (+ the ones I use), and I was thinking 1/2 years also considering this.

Thanks,
koraynilay

Quoted 2 lines

Thanks,
Amir.

maintainer
#51 lore raw
In reply to Amir Goldstein
Quoted 188 lines · Amir Goldstein
Quoted 39 lines · koraynilay

Hello and thanks for replying,

Quoted 15 lines · Jeff Layton
Quoted 14 lines · koraynilay

This is an initial implementation of a new timestamp to indicate the time when a file/directory was initially created.

This patch series takes inspiration from the one by Sean Smith <[email protected]> [1], but using file_setattr()/file_getattr() as suggested by Darrick J. Wong <[email protected]> in [2].

The semantics of this new timestamp should be at least these:
- it should be the same as btime on a newly created file
- it's user-settable, so it can be preserved for backups, filesystem conversions, archives and any similar operation
- it should be preserved every time mtime gets preserved

Quoted 7 lines
Quoted 5 lines

and the correspondence with the other timestamps is as follows:

ctime <-> btime
mtime <-> ptime

I'm not sure how to interpret the correspondence above.

  |-----\_-----------------|-----------|
  |       \_      change/  |   birth/  |
  |         \_ modification|  creation |
  |           \------------|-----------|
  | inode time |   ctime   |   btime   |
  |------------|-----------|-----------|
  | file time  |   mtime   |   ptime   |
  |------------|-----------|-----------|

("file" as in "the concept of this file", I'd say "file content" but that would be incorrect for symlinks)

Quoted 147 lines

so ctime is "inode change time", btime is "inode birth/creation time", while mtime is "file content change/modification time" and ptime would be "file content creation time" (same as Window's or MacOS's creation time).

Does this make more sense?

Quoted 139 lines
Quoted 125 lines

Examples:
1) a .zsh_history file created in 2019, then after a few years the user decides to switch to another filesystem, copying the .zsh_history to the new home, in that case btime would have the timestamp of the copy and ptime would have the 2019 timestamp (just like mtime would have been preserved)
2) a symlink created in 2020 from the home directory to a /path going through the same process as the .zsh_history, in this case it would also make sense to sync the ptime to the 2020 timestamp instead of keeping only the btime (so the inode creation time).

The proof-of-concept code (for testing) for stat(1) and cp(1) is available at https://github.com/koraynilay/coreutils (master branch) (Note: these coreutils code changes are a prototype and won't be submitted upstream as-is, but they work as expected in simple stat and cp -a/--preserve=ptime tests)

Lastly, the name "provenance" and "ptime" are not final, I personally don't have a strong opinion on any name, but while testing with stat(1) I noticed that "Provenance" is definitely too long for the normal output, so another option which would fit well is "Origin time", abbreviated as "ntime" (OrigiN time) and not as "otime", as that would conflict with btrfs' internal naming and create confusion.

v2 changes:
- fix permission bypass leading to ptime update on immutable and append-only files (found by sashiko[3])
- normalize ptime timestamp as done in fs/attr.c:notify_change() (found by sashiko[3])
- fix wording in vfs patch to be like the cover-letter

v3 changes:
- vfs: reject setting ptime with -EOPNOTSUPP on filesystems that do not support it instead of silently ignoring it (found by sashiko[4])
- vfs: fix not being able to clear immutable and append-only on files with ptime, and allow updating immutable/append-only atomically along with ptime (found by sashiko[4])
- btrfs: validate on-disk ptime nanoseconds and reset to otime if invalid (found by sashiko[4])
- btrfs: avoid re-assigning ptime on unrelated chattr calls (found by sashiko[4])
- add ntfs3 and exfat support as suggested by Amir Goldstein[5], but no vfat, smb, or nfs4 yet as they are a bit more complex
- move the introduction of fileattr_has_fsx_mask() from the btrfs patch to a standalone patch in the series
- btrfs: add fileattr_[gs]et to symlink and special file operations

v4 changes:
- vfs: implement fsx_xflags_mask as suggested by Amir Goldstein[6];
- add SMB (ksmbd/cifs) and nfs (nfsd/nfs) support as requested in previous threads;

Note:
to apply this patch 2 previous patches[7][8] from the ksmbd/cifs subsystem are needed.

New Question:
should I rename fileattr_has_fsx_mask() to something like fileattr_has_unsupported_fsx() and keep its code as-is, or should I add the fsx_xflags_mask & ~allowed check in it and keep the name as-is? (or both?)

Thanks.

[1]: https://lore.kernel.org/[email protected]
[2]: https://lore.kernel.org/20260407014129.GC6192@frogsfrogsfrogs
[3]: https://sashiko.dev/#/patchset/20261027220532.736352-1-koray.fra%40gmail.com
[4]: https://sashiko.dev/#/patchset/20261028134728.294127-1-koray.fra%40gmail.com
[5]: https://lore.kernel.org/CAOQ4uxiuy0VwZj+3M-zRqQ49WTpHZpiaQ+6MZ8z8WdLjyQM_zA@mail.gmail.com/
[6]: https://lore.kernel.org/CAOQ4uxjtuTDT63vJdYaq+RHQEQFLTksp66e46OMN99WhJz3SbA@mail.gmail.com/
[7]: https://lore.kernel.org/linux-cifs/[email protected]/
[8]: https://lore.kernel.org/linux-cifs/[email protected]/

koraynilay (10):
vfs: add provenance time (ptime)
vfs: add fileattr_has_fsx_mask()
ntfs3: make crtime user-settable using ptime
exfat: make crtime user-settable using ptime
btrfs: add provenance time (ptime)
vfs: add __vfs_fileattr_set_locked() for inode_lock()'d callers
nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE
nfs: add provenance time (ptime) via FATTR4_TIME_CREATE
ksmbd: add provenance time (ptime) and map it to CreationTime
cifs: add provenance time (ptime) and map it to SMB's CreationTime

 fs/btrfs/btrfs_inode.h          |   4 +
 fs/btrfs/delayed-inode.c        |   6 ++
 fs/btrfs/inode.c                |  29 +++++-
 fs/btrfs/ioctl.c                |  24 ++++-
 fs/btrfs/print-tree.c           |   1 +
 fs/btrfs/tree-log.c             |   3 +
 fs/exfat/exfat_fs.h             |   2 +
 fs/exfat/file.c                 |  42 ++++++++-
 fs/exfat/namei.c                |   1 +
 fs/file_attr.c                  | 156 ++++++++++++++++++++++++++------
 fs/nfs/inode.c                  |  27 +++++-
 fs/nfs/internal.h               |   2 +
 fs/nfs/nfs4proc.c               |  56 +++++++++++-
 fs/nfs/nfs4xdr.c                |  19 ++--
 fs/nfs/symlink.c                |   1 +
 fs/nfsd/nfs4proc.c              |   9 ++
 fs/nfsd/nfs4xdr.c               |  40 +++++---
 fs/nfsd/vfs.c                   |  17 ++++
 fs/nfsd/vfs.h                   |   4 +-
 fs/nfsd/xdr4.h                  |   3 +
 fs/ntfs3/file.c                 |  20 +++-
 fs/ntfs3/frecord.c              |   8 +-
 fs/smb/client/cifsfs.c          |   8 ++
 fs/smb/client/inode.c           |   7 +-
 fs/smb/client/ioctl.c           | 109 ++++++++++++++++------
 fs/smb/server/smb2pdu.c         |  37 +++++---
 fs/smb/server/vfs.c             |  43 ++++++++-
 fs/smb/server/vfs.h             |   1 +
 fs/stat.c                       |   2 +
 include/linux/fileattr.h        |  29 +++++-
 include/linux/nfs_xdr.h         |   3 +
 include/linux/stat.h            |   1 +
 include/uapi/linux/btrfs_tree.h |   3 +-
 include/uapi/linux/fs.h         |   9 +-
 include/uapi/linux/stat.h       |   7 +-
 35 files changed, 614 insertions(+), 119 deletions(-)
Quoted 4 lines

base-commit: 3bc1fb9c3b20cd478c83496ab16addecb401770d
prerequisite-patch-id: 049ae0eba275b5be35a238833107e0b251a55aa2
prerequisite-patch-id: 614f0bc9411391403d4e9702bafeb31b0ec04ec1
prerequisite-patch-id: ddf636b9d33d82ea206ce265d817371350bf8858

I think this is going to be very hard to do properly, because the kernel can't really manage this on its own. Something in userland is going to have to set this value if you want to update it to something other than the original inode instantiation time (aka btime).

It really sounds like what you want is the ability to make the btime settable. Personally I think the decision to forbid that was wrong- headed and that it should have been settable from userland from the beginning. Maybe we should just revisit that decision.

Quoted 7 lines

Frankly, I don't think this decision was made at all.

There are only 2 types of filesystems in Linux today:
1. btime is constant (xfs, etx4, btrfs,...)
2. crtime is settable in principle but not via a standardized Linux API (ntfs, cifs, ...)

CephFS is in this category too. I explicitly made it settable so we could set it when restoring backups.

Quoted 10 lines

AFAIK, btrfs in this series is the only filesystem which is going to have two deviated copies of btime and ptime.
For all the rest, the deviation is artificial in statx.

So the questions to ask are:
1. Do btrfs developers prefer to store a new settable ptime or making otime/btime settable with this new API?
2. Will any other fs in the future want to store settable ptime along side the legacy immutable btime?

Quoted 8 lines

My take on these question is:
- Personally I would love to see ptime support in xfs in the future and would willing to contribute to this work, because I have hard evidence from the performance benefits that it brings to smb server workloads
- Judging by past experience with i_version bump interpretation on xfs, I find it hard to believe that xfs developer would agree to making the legacy btime settable

Maybe? The main reason for that was that XFS uses i_version as internally as a change counter for any inode change. I doubt that it uses btime internally like that.

The only reason I can see to _not_ make btime settable is for
forensics: maybe having the inode btime be immutable would make it harder to disguise when an inode was instantiated, but I imagine that would be defeatable with offline tools anyway.

If people are using the btime in this way, then it would be nice for them to speak up and give us some details about this usage. How does keeping it immutable help you?

Quoted 37 lines

Hence the distinction in statx API is needed, but for most filesystems it is a pure semantic way of saying "I do/don't have settable birth time".

Quoted 7 lines

Originally I just wanted to have btime settable, yes, and if btime was settable I wouldn't have made this RFC PATCH either, but after reading the already existing discussions about it, I can understand having an "immutable inode creation time", like ctime exists, so even after making btime settable, a new timestamp would be necessary anyway (e.g. for the people who want btime to exist as a forensics timestamp).

Right, but every filesystem (e.g. btrfs) can still make an independent choice whether storing one or two copies is desired.
The API does not limit those choices.

Quoted 8 lines
Quoted 5 lines

Failing that, why not just track this in an xattr of some sort, since this is really just an opaque blob once you allow it to be settable. If the xattr isn't present, then you can just use the value of the btime as-is. FWIW, I think samba does this today, so you could try to sync with its behavior here.

(This is copied and adapted from [2])

Quoted 13 lines

I actually have been using fully userspace xattrs[1] for a few months, mostly for backups, and it "works"; but last month I wanted to merge 2 FSs (and have another merge I have to do), so I ran [1] on all files and then compared all metadata/data between source and destination and noticed there were quite a lot of files that didn't have the xattr set. So I looked online and learned that xattrs only work on regular files/directories, not on symlinks or anything else (and the missing ones were of symlinks).
This is what prompted me to search more if anyone had already proposed a new timestamp (instead of making btime settable) and found the email thread from april linked in the cover letter, which gave me the excuse to finally work on a proper patch.

Quoted 16 lines

I am tired of repeating my arguments (and finding my own quotes) about why using xattrs is a poor replacement for in-inode ptime. AI agents can easily find those quotes for those who are interested so I won't bother, I just say that smbd already uses xattr to store the creation time - it's just bad for performance and disk usage in metadata intensive workloads.

Quoted 9 lines
Quoted 8 lines

That seems a lot simpler than adding an entirely new inode timestamp that is always going to be a copy of the btime, except in rare cases. Having to patch all of the on-disk filesystems with a new per-inode field is a lot more work.

This patch is quite simple, but changing btrfs, then ext4, xfs, etc is a mess, and inevitably you can't get these timestamps until you upgrade your filesystems.

Weird. I didn't write the above sentence.

Quoted 8 lines

Jeff, this is standard "how to make progress".
I completely don't agree with this argument.
We cannot use this argument to block progress.
Is it already a long standing practice for userspace file servers (samba) to probe the host filesystem for specific features and fall back to alternative implementation if they are not supported.

Quoted 9 lines

There will be nothing new in this case, that's the only way to make forward progress - define the API, make support queryable, implement the feature in some filesystems, implement consumers, repeat.

Also for nfsd, that's the only way to ever implement settable FATTR4_TIME_CREATE which is the protocol allows.
This is never going to be possible with custom xattrs.
So I must say that I don't understand the objection from you and Chuck

I'm not saying that to try and block progress. I'm just pointing out that it is a rather heavy lift to add a new inode field. This will require revving the on-disk format for most local filesystems, and it will take years to roll out. If we can get away with just making the btime settable, that seems like a much simpler way to do this.

FWIW, Omar Sandoval apparently tried to add AT_UTIME_BTIME to utimensat() back in 2019, but it never made it in. It might be good to look over the objections to it then to see if they can be overcome.

Signature · 1 line
Jeff Layton <[email protected]>
author
#52 lore raw
Quoted 191 lines · Jeff Layton
Quoted 190 lines · Amir Goldstein
Quoted 39 lines · koraynilay

Hello and thanks for replying,

Quoted 15 lines · Jeff Layton
Quoted 14 lines · koraynilay

This is an initial implementation of a new timestamp to indicate the time when a file/directory was initially created.

This patch series takes inspiration from the one by Sean Smith <[email protected]> [1], but using file_setattr()/file_getattr() as suggested by Darrick J. Wong <[email protected]> in [2].

The semantics of this new timestamp should be at least these:
- it should be the same as btime on a newly created file
- it's user-settable, so it can be preserved for backups, filesystem conversions, archives and any similar operation
- it should be preserved every time mtime gets preserved

Quoted 7 lines
Quoted 5 lines

and the correspondence with the other timestamps is as follows:

ctime <-> btime
mtime <-> ptime

I'm not sure how to interpret the correspondence above.

  |-----\_-----------------|-----------|
  |       \_      change/  |   birth/  |
  |         \_ modification|  creation |
  |           \------------|-----------|
  | inode time |   ctime   |   btime   |
  |------------|-----------|-----------|
  | file time  |   mtime   |   ptime   |
  |------------|-----------|-----------|

("file" as in "the concept of this file", I'd say "file content" but that would be incorrect for symlinks)

Quoted 147 lines

so ctime is "inode change time", btime is "inode birth/creation time", while mtime is "file content change/modification time" and ptime would be "file content creation time" (same as Window's or MacOS's creation time).

Does this make more sense?

Quoted 139 lines
Quoted 125 lines

Examples:
1) a .zsh_history file created in 2019, then after a few years the user decides to switch to another filesystem, copying the .zsh_history to the new home, in that case btime would have the timestamp of the copy and ptime would have the 2019 timestamp (just like mtime would have been preserved)
2) a symlink created in 2020 from the home directory to a /path going through the same process as the .zsh_history, in this case it would also make sense to sync the ptime to the 2020 timestamp instead of keeping only the btime (so the inode creation time).

The proof-of-concept code (for testing) for stat(1) and cp(1) is available at https://github.com/koraynilay/coreutils (master branch) (Note: these coreutils code changes are a prototype and won't be submitted upstream as-is, but they work as expected in simple stat and cp -a/--preserve=ptime tests)

Lastly, the name "provenance" and "ptime" are not final, I personally don't have a strong opinion on any name, but while testing with stat(1) I noticed that "Provenance" is definitely too long for the normal output, so another option which would fit well is "Origin time", abbreviated as "ntime" (OrigiN time) and not as "otime", as that would conflict with btrfs' internal naming and create confusion.

v2 changes:
- fix permission bypass leading to ptime update on immutable and append-only files (found by sashiko[3])
- normalize ptime timestamp as done in fs/attr.c:notify_change() (found by sashiko[3])
- fix wording in vfs patch to be like the cover-letter

v3 changes:
- vfs: reject setting ptime with -EOPNOTSUPP on filesystems that do not support it instead of silently ignoring it (found by sashiko[4])
- vfs: fix not being able to clear immutable and append-only on files with ptime, and allow updating immutable/append-only atomically along with ptime (found by sashiko[4])
- btrfs: validate on-disk ptime nanoseconds and reset to otime if invalid (found by sashiko[4])
- btrfs: avoid re-assigning ptime on unrelated chattr calls (found by sashiko[4])
- add ntfs3 and exfat support as suggested by Amir Goldstein[5], but no vfat, smb, or nfs4 yet as they are a bit more complex
- move the introduction of fileattr_has_fsx_mask() from the btrfs patch to a standalone patch in the series
- btrfs: add fileattr_[gs]et to symlink and special file operations

v4 changes:
- vfs: implement fsx_xflags_mask as suggested by Amir Goldstein[6];
- add SMB (ksmbd/cifs) and nfs (nfsd/nfs) support as requested in previous threads;

Note:
to apply this patch 2 previous patches[7][8] from the ksmbd/cifs subsystem are needed.

New Question:
should I rename fileattr_has_fsx_mask() to something like fileattr_has_unsupported_fsx() and keep its code as-is, or should I add the fsx_xflags_mask & ~allowed check in it and keep the name as-is? (or both?)

Thanks.

[1]: https://lore.kernel.org/[email protected]
[2]: https://lore.kernel.org/20260407014129.GC6192@frogsfrogsfrogs
[3]: https://sashiko.dev/#/patchset/20261027220532.736352-1-koray.fra%40gmail.com
[4]: https://sashiko.dev/#/patchset/20261028134728.294127-1-koray.fra%40gmail.com
[5]: https://lore.kernel.org/CAOQ4uxiuy0VwZj+3M-zRqQ49WTpHZpiaQ+6MZ8z8WdLjyQM_zA@mail.gmail.com/
[6]: https://lore.kernel.org/CAOQ4uxjtuTDT63vJdYaq+RHQEQFLTksp66e46OMN99WhJz3SbA@mail.gmail.com/
[7]: https://lore.kernel.org/linux-cifs/[email protected]/
[8]: https://lore.kernel.org/linux-cifs/[email protected]/

koraynilay (10):
vfs: add provenance time (ptime)
vfs: add fileattr_has_fsx_mask()
ntfs3: make crtime user-settable using ptime
exfat: make crtime user-settable using ptime
btrfs: add provenance time (ptime)
vfs: add __vfs_fileattr_set_locked() for inode_lock()'d callers
nfsd: add provenance time (ptime) via FATTR4_TIME_CREATE
nfs: add provenance time (ptime) via FATTR4_TIME_CREATE
ksmbd: add provenance time (ptime) and map it to CreationTime
cifs: add provenance time (ptime) and map it to SMB's CreationTime

 fs/btrfs/btrfs_inode.h          |   4 +
 fs/btrfs/delayed-inode.c        |   6 ++
 fs/btrfs/inode.c                |  29 +++++-
 fs/btrfs/ioctl.c                |  24 ++++-
 fs/btrfs/print-tree.c           |   1 +
 fs/btrfs/tree-log.c             |   3 +
 fs/exfat/exfat_fs.h             |   2 +
 fs/exfat/file.c                 |  42 ++++++++-
 fs/exfat/namei.c                |   1 +
 fs/file_attr.c                  | 156 ++++++++++++++++++++++++++------
 fs/nfs/inode.c                  |  27 +++++-
 fs/nfs/internal.h               |   2 +
 fs/nfs/nfs4proc.c               |  56 +++++++++++-
 fs/nfs/nfs4xdr.c                |  19 ++--
 fs/nfs/symlink.c                |   1 +
 fs/nfsd/nfs4proc.c              |   9 ++
 fs/nfsd/nfs4xdr.c               |  40 +++++---
 fs/nfsd/vfs.c                   |  17 ++++
 fs/nfsd/vfs.h                   |   4 +-
 fs/nfsd/xdr4.h                  |   3 +
 fs/ntfs3/file.c                 |  20 +++-
 fs/ntfs3/frecord.c              |   8 +-
 fs/smb/client/cifsfs.c          |   8 ++
 fs/smb/client/inode.c           |   7 +-
 fs/smb/client/ioctl.c           | 109 ++++++++++++++++------
 fs/smb/server/smb2pdu.c         |  37 +++++---
 fs/smb/server/vfs.c             |  43 ++++++++-
 fs/smb/server/vfs.h             |   1 +
 fs/stat.c                       |   2 +
 include/linux/fileattr.h        |  29 +++++-
 include/linux/nfs_xdr.h         |   3 +
 include/linux/stat.h            |   1 +
 include/uapi/linux/btrfs_tree.h |   3 +-
 include/uapi/linux/fs.h         |   9 +-
 include/uapi/linux/stat.h       |   7 +-
 35 files changed, 614 insertions(+), 119 deletions(-)
Quoted 4 lines

base-commit: 3bc1fb9c3b20cd478c83496ab16addecb401770d
prerequisite-patch-id: 049ae0eba275b5be35a238833107e0b251a55aa2
prerequisite-patch-id: 614f0bc9411391403d4e9702bafeb31b0ec04ec1
prerequisite-patch-id: ddf636b9d33d82ea206ce265d817371350bf8858

I think this is going to be very hard to do properly, because the kernel can't really manage this on its own. Something in userland is going to have to set this value if you want to update it to something other than the original inode instantiation time (aka btime).

It really sounds like what you want is the ability to make the btime settable. Personally I think the decision to forbid that was wrong- headed and that it should have been settable from userland from the beginning. Maybe we should just revisit that decision.

Frankly, I don't think this decision was made at all.

Quoted 8 lines
Quoted 5 lines

There are only 2 types of filesystems in Linux today:
1. btime is constant (xfs, etx4, btrfs,...)
2. crtime is settable in principle but not via a standardized Linux API (ntfs, cifs, ...)

CephFS is in this category too. I explicitly made it settable so we could set it when restoring backups.

Ah ok, should I try adding support for it using this API in the next version? (either by making btime settable like with SMB/NFS or adding ptime as new?)

Quoted 24 lines
Quoted 11 lines

AFAIK, btrfs in this series is the only filesystem which is going to have two deviated copies of btime and ptime.
For all the rest, the deviation is artificial in statx.

So the questions to ask are:
1. Do btrfs developers prefer to store a new settable ptime or making otime/btime settable with this new API?
2. Will any other fs in the future want to store settable ptime along side the legacy immutable btime?

Quoted 8 lines

My take on these question is:
- Personally I would love to see ptime support in xfs in the future and would willing to contribute to this work, because I have hard evidence from the performance benefits that it brings to smb server workloads
- Judging by past experience with i_version bump interpretation on xfs, I find it hard to believe that xfs developer would agree to making the legacy btime settable

Maybe? The main reason for that was that XFS uses i_version as internally as a change counter for any inode change. I doubt that it uses btime internally like that.

Quoted 8 lines

The only reason I can see to _not_ make btime settable is for
forensics: maybe having the inode btime be immutable would make it harder to disguise when an inode was instantiated, but I imagine that would be defeatable with offline tools anyway.

If people are using the btime in this way, then it would be nice for them to speak up and give us some details about this usage. How does keeping it immutable help you?

I agree, I do understand the possible reasons for keeping it, but personally I don't have any use for immutable btime (tho, it is nice to have also that information available).

Quoted 49 lines
Quoted 49 lines

Hence the distinction in statx API is needed, but for most filesystems it is a pure semantic way of saying "I do/don't have settable birth time".

Quoted 7 lines

Originally I just wanted to have btime settable, yes, and if btime was settable I wouldn't have made this RFC PATCH either, but after reading the already existing discussions about it, I can understand having an "immutable inode creation time", like ctime exists, so even after making btime settable, a new timestamp would be necessary anyway (e.g. for the people who want btime to exist as a forensics timestamp).

Right, but every filesystem (e.g. btrfs) can still make an independent choice whether storing one or two copies is desired.
The API does not limit those choices.

Quoted 8 lines
Quoted 5 lines

Failing that, why not just track this in an xattr of some sort, since this is really just an opaque blob once you allow it to be settable. If the xattr isn't present, then you can just use the value of the btime as-is. FWIW, I think samba does this today, so you could try to sync with its behavior here.

(This is copied and adapted from [2])

Quoted 13 lines

I actually have been using fully userspace xattrs[1] for a few months, mostly for backups, and it "works"; but last month I wanted to merge 2 FSs (and have another merge I have to do), so I ran [1] on all files and then compared all metadata/data between source and destination and noticed there were quite a lot of files that didn't have the xattr set. So I looked online and learned that xattrs only work on regular files/directories, not on symlinks or anything else (and the missing ones were of symlinks).
This is what prompted me to search more if anyone had already proposed a new timestamp (instead of making btime settable) and found the email thread from april linked in the cover letter, which gave me the excuse to finally work on a proper patch.

I am tired of repeating my arguments (and finding my own quotes) about why using xattrs is a poor replacement for in-inode ptime. AI agents can easily find those quotes for those who are interested so I won't bother, I just say that smbd already uses xattr to store the creation time - it's just bad for performance and disk usage in metadata intensive workloads.

Quoted 5 lines
Quoted 4 lines

That seems a lot simpler than adding an entirely new inode timestamp that is always going to be a copy of the btime, except in rare cases. Having to patch all of the on-disk filesystems with a new per-inode field is a lot more work.

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

This patch is quite simple, but changing btrfs, then ext4, xfs, etc is a mess, and inevitably you can't get these timestamps until you upgrade your filesystems.

Weird. I didn't write the above sentence.

Yes, I copy-pasted from the linked email and since it was raising the same issue I kept it along yours (I should've probably used >>).

Quoted 24 lines
Quoted 8 lines

Jeff, this is standard "how to make progress".
I completely don't agree with this argument.
We cannot use this argument to block progress.
Is it already a long standing practice for userspace file servers (samba) to probe the host filesystem for specific features and fall back to alternative implementation if they are not supported.

Quoted 9 lines

There will be nothing new in this case, that's the only way to make forward progress - define the API, make support queryable, implement the feature in some filesystems, implement consumers, repeat.

Also for nfsd, that's the only way to ever implement settable FATTR4_TIME_CREATE which is the protocol allows.
This is never going to be possible with custom xattrs.
So I must say that I don't understand the objection from you and Chuck

I'm not saying that to try and block progress. I'm just pointing out that it is a rather heavy lift to add a new inode field. This will require revving the on-disk format for most local filesystems, and it will take years to roll out. If we can get away with just making the btime settable, that seems like a much simpler way to do this.

Quoted 3 lines

FWIW, Omar Sandoval apparently tried to add AT_UTIME_BTIME to utimensat() back in 2019, but it never made it in. It might be good to look over the objections to it then to see if they can be overcome.

That would also be fine for me, tho adding ptime as a new timestamp does increase completeness, which would be better IMO.

Thanks,
koraynilay

#53 lore raw
In reply to koraynilay

Hello,

I have just one issue with the userspace API. It does not allow me to figure out what is the source of statx btime field. If it is fs ptime or fs btime because this RFC implementation is mixing both fs ptime and fs btime into the statx btime field.

I have feeling that this is quite a mess in API and I would like to see a clear distinguish between btime and ptime in the API, like there is a difference in the fs storage.

If the btime is used for forensic analysis then somehow I would expect that the statx would not report / not fill changeable ptime value into the statx btime.

It would be really helpful if the statx API on inode can differ between:

1. btime is present and its value is ..., ptime is not supported
2. btime is not supported, ptime is set to value ...
3. btime is present and its value is ..., ptime is set to value ...
4. both btime and ptime are not supported

This should cover all cases of different filesystems and also allows userspace to do proper backup of both ptime and btime fields (if it want to do forensic analysis or anything else).

Pali

author
#54 lore raw
Quoted 7 lines · Pali Rohár

Hello,

I have just one issue with the userspace API. It does not allow me to figure out what is the source of statx btime field. If it is fs ptime or fs btime because this RFC implementation is mixing both fs ptime and fs btime into the statx btime field.

Quoted 7 lines

I have feeling that this is quite a mess in API and I would like to see a clear distinguish between btime and ptime in the API, like there is a difference in the fs storage.

If the btime is used for forensic analysis then somehow I would expect that the statx would not report / not fill changeable ptime value into the statx btime.

Hi, for native linux filesystems it will report ptime as PTIME and btime as BTIME (also semnatically), for the windows-like ones that only have ptime (semantically) I think it's reasonable to not expect btime to be immutable, since they are meant to be used with other OSs who lack btime semantics.

Quoted 10 lines

It would be really helpful if the statx API on inode can differ between:

1. btime is present and its value is ..., ptime is not supported
2. btime is not supported, ptime is set to value ...
3. btime is present and its value is ..., ptime is set to value ...
4. both btime and ptime are not supported

This should cover all cases of different filesystems and also allows userspace to do proper backup of both ptime and btime fields (if it want to do forensic analysis or anything else).

These should already all be covered by STATX_BTIME/PTIME and their fields in struct statx, the only problems are windows-like filesystems, which IMO shuold be handled as mentioned above.

Of course, as in the other discussion, I'm open to changing ptime NTFS/exFAT/... support to remove btime altogether and only use ptime for their own crtime if that's what wanted (I'm fairly impartial on this specific issue).

Thanks,
koraynilay

Quoted 2 lines

Pali

#55 lore raw
Quoted 12 lines · On Wednesday 18 November 2026 15:58:02 koraynilay wrote:
Quoted 11 lines · Pali Rohár

Hello,

I have just one issue with the userspace API. It does not allow me to figure out what is the source of statx btime field. If it is fs ptime or fs btime because this RFC implementation is mixing both fs ptime and fs btime into the statx btime field.

I have feeling that this is quite a mess in API and I would like to see a clear distinguish between btime and ptime in the API, like there is a difference in the fs storage.

Quoted 6 lines
Quoted 3 lines

If the btime is used for forensic analysis then somehow I would expect that the statx would not report / not fill changeable ptime value into the statx btime.

Hi, for native linux filesystems it will report ptime as PTIME and btime as BTIME (also semnatically).

That is fine.

Quoted 4 lines

for the windows-like ones that only have
ptime (semantically) I think it's reasonable to not expect btime to be immutable, since they are meant to be used with other OSs who lack btime semantics.

The problem is here that the RFC statx API does not provide this information that the fs lacks btime semantics and instead it fills non-immutable ptime value there.

I'm pointing only about this inconsistency.

Quoted 7 lines
Quoted 7 lines

It would be really helpful if the statx API on inode can differ between:

1. btime is present and its value is ..., ptime is not supported
2. btime is not supported, ptime is set to value ...
3. btime is present and its value is ..., ptime is set to value ...
4. both btime and ptime are not supported

Quoted 7 lines
Quoted 3 lines

This should cover all cases of different filesystems and also allows userspace to do proper backup of both ptime and btime fields (if it want to do forensic analysis or anything else).

These should already all be covered by STATX_BTIME/PTIME and their fields in struct statx, the only problems are windows-like filesystems, which IMO shuold be handled as mentioned above.

Exactly, I pointed out about these problems. I somehow expect that the new API would be generic and uniform across filesystem. IMHO it does not matter if the filesystem is windows-like or not (there are also FreeBSD fs and also others which allows to modify that time). So better description is fs belongs to category 2. from my above description.

Quoted 4 lines

Of course, as in the other discussion, I'm open to changing ptime NTFS/exFAT/... support to remove btime altogether and only use ptime for their own crtime if that's what wanted (I'm fairly impartial on this specific issue).

I'm giving some ideas how to possible handle this situation:

1. do not fill btime it at all when it is not available (remove btime altogether - the case like you wrote above)

2. when userspace ask both ptime and btime, then do not fill btime (remove btime altogether - but only for that new case)

3. fill btime with ptime value, but add a new output flag indicating that the btime is not present at all and instead kernel filled ptime value into the statx btime field

4. let statx btime as currently is, and add two new statx fields:
immutable_btime and ptime. immutable_btime would be filled only if the fs supports real btime (so not for ntfs/extfat crtime) and ptime would be what is currently in RFC

Ideas 2. 3. and 4. should be fully backward compatible as it would affect statx output only when called with new flags.

Quoted 5 lines

Thanks,
koraynilay

Quoted 2 lines

Pali

author
#56 lore raw
Quoted 48 lines · Pali Rohár
Quoted 12 lines · On Wednesday 18 November 2026 15:58:02 koraynilay wrote:
Quoted 11 lines · Pali Rohár

Hello,

I have just one issue with the userspace API. It does not allow me to figure out what is the source of statx btime field. If it is fs ptime or fs btime because this RFC implementation is mixing both fs ptime and fs btime into the statx btime field.

I have feeling that this is quite a mess in API and I would like to see a clear distinguish between btime and ptime in the API, like there is a difference in the fs storage.

Quoted 6 lines
Quoted 3 lines

If the btime is used for forensic analysis then somehow I would expect that the statx would not report / not fill changeable ptime value into the statx btime.

Hi, for native linux filesystems it will report ptime as PTIME and btime as BTIME (also semnatically).

That is fine.

Quoted 4 lines

for the windows-like ones that only have
ptime (semantically) I think it's reasonable to not expect btime to be immutable, since they are meant to be used with other OSs who lack btime semantics.

The problem is here that the RFC statx API does not provide this information that the fs lacks btime semantics and instead it fills non-immutable ptime value there.

I'm pointing only about this inconsistency.

Quoted 7 lines
Quoted 7 lines

It would be really helpful if the statx API on inode can differ between:

1. btime is present and its value is ..., ptime is not supported
2. btime is not supported, ptime is set to value ...
3. btime is present and its value is ..., ptime is set to value ...
4. both btime and ptime are not supported

Quoted 7 lines
Quoted 3 lines

This should cover all cases of different filesystems and also allows userspace to do proper backup of both ptime and btime fields (if it want to do forensic analysis or anything else).

These should already all be covered by STATX_BTIME/PTIME and their fields in struct statx, the only problems are windows-like filesystems, which IMO shuold be handled as mentioned above.

Quoted 5 lines

Exactly, I pointed out about these problems. I somehow expect that the new API would be generic and uniform across filesystem. IMHO it does not matter if the filesystem is windows-like or not (there are also FreeBSD fs and also others which allows to modify that time). So better description is fs belongs to category 2. from my above description.

Ah yes, I used windows-like to mean "only have ptime semantics", so same as your category 2.

Quoted 9 lines
Quoted 4 lines

Of course, as in the other discussion, I'm open to changing ptime NTFS/exFAT/... support to remove btime altogether and only use ptime for their own crtime if that's what wanted (I'm fairly impartial on this specific issue).

I'm giving some ideas how to possible handle this situation:

1. do not fill btime it at all when it is not available (remove btime altogether - the case like you wrote above)

This would be the most semantically correct option, but would break at least 1 script/program/use case.

Quoted 2 lines

2. when userspace ask both ptime and btime, then do not fill btime (remove btime altogether - but only for that new case)

This probably is the best compromise.

Quoted 3 lines

3. fill btime with ptime value, but add a new output flag indicating that the btime is not present at all and instead kernel filled ptime value into the statx btime field

I don't really like this, it adds complexity and uses memory/1 flag big for a single specific field, IMO it's not worth it.

Quoted 4 lines

4. let statx btime as currently is, and add two new statx fields:
immutable_btime and ptime. immutable_btime would be filled only if the fs supports real btime (so not for ntfs/extfat crtime) and ptime would be what is currently in RFC

I think this is also too complex.

Quoted 2 lines

Ideas 2. 3. and 4. should be fully backward compatible as it would affect statx output only when called with new flags.

Then 2. is probably the best way to go forward (maybe I'll include it in some way in v5), but I think we should let each filesystem maintainer decide if they think their users want to have statx report their own crtime as btime, ptime or both (native linux ones would of course report btime as btime and ptime as ptime).

Thanks,
koraynilay

Quoted 5 lines
Quoted 5 lines

Thanks,
koraynilay

Quoted 2 lines

Pali

#57 lore raw
Quoted 88 lines · On Wednesday 18 November 2026 17:50:39 koraynilay wrote:
Quoted 48 lines · Pali Rohár
Quoted 12 lines · On Wednesday 18 November 2026 15:58:02 koraynilay wrote:
Quoted 11 lines · Pali Rohár

Hello,

I have just one issue with the userspace API. It does not allow me to figure out what is the source of statx btime field. If it is fs ptime or fs btime because this RFC implementation is mixing both fs ptime and fs btime into the statx btime field.

I have feeling that this is quite a mess in API and I would like to see a clear distinguish between btime and ptime in the API, like there is a difference in the fs storage.

Quoted 6 lines
Quoted 3 lines

If the btime is used for forensic analysis then somehow I would expect that the statx would not report / not fill changeable ptime value into the statx btime.

Hi, for native linux filesystems it will report ptime as PTIME and btime as BTIME (also semnatically).

That is fine.

Quoted 4 lines

for the windows-like ones that only have
ptime (semantically) I think it's reasonable to not expect btime to be immutable, since they are meant to be used with other OSs who lack btime semantics.

The problem is here that the RFC statx API does not provide this information that the fs lacks btime semantics and instead it fills non-immutable ptime value there.

I'm pointing only about this inconsistency.

Quoted 7 lines
Quoted 7 lines

It would be really helpful if the statx API on inode can differ between:

1. btime is present and its value is ..., ptime is not supported
2. btime is not supported, ptime is set to value ...
3. btime is present and its value is ..., ptime is set to value ...
4. both btime and ptime are not supported

Quoted 7 lines
Quoted 3 lines

This should cover all cases of different filesystems and also allows userspace to do proper backup of both ptime and btime fields (if it want to do forensic analysis or anything else).

These should already all be covered by STATX_BTIME/PTIME and their fields in struct statx, the only problems are windows-like filesystems, which IMO shuold be handled as mentioned above.

Quoted 5 lines

Exactly, I pointed out about these problems. I somehow expect that the new API would be generic and uniform across filesystem. IMHO it does not matter if the filesystem is windows-like or not (there are also FreeBSD fs and also others which allows to modify that time). So better description is fs belongs to category 2. from my above description.

Ah yes, I used windows-like to mean "only have ptime semantics", so same as your category 2.

Quoted 9 lines
Quoted 4 lines

Of course, as in the other discussion, I'm open to changing ptime NTFS/exFAT/... support to remove btime altogether and only use ptime for their own crtime if that's what wanted (I'm fairly impartial on this specific issue).

I'm giving some ideas how to possible handle this situation:

1. do not fill btime it at all when it is not available (remove btime altogether - the case like you wrote above)

This would be the most semantically correct option, but would break at least 1 script/program/use case.

Quoted 2 lines

2. when userspace ask both ptime and btime, then do not fill btime (remove btime altogether - but only for that new case)

This probably is the best compromise.

Quoted 3 lines

3. fill btime with ptime value, but add a new output flag indicating that the btime is not present at all and instead kernel filled ptime value into the statx btime field

I don't really like this, it adds complexity and uses memory/1 flag big for a single specific field, IMO it's not worth it.

Quoted 4 lines

4. let statx btime as currently is, and add two new statx fields:
immutable_btime and ptime. immutable_btime would be filled only if the fs supports real btime (so not for ntfs/extfat crtime) and ptime would be what is currently in RFC

Quoted 7 lines

I think this is also too complex.

Quoted 2 lines

Ideas 2. 3. and 4. should be fully backward compatible as it would affect statx output only when called with new flags.

Then 2. is probably the best way to go forward (maybe I'll include it in some way in v5),

My preference is 1. or 2. Just wanted to give more alternative solutions.

Quoted 4 lines

but I think we should let each filesystem maintainer decide if they think their users want to have statx report their own crtime as btime, ptime or both (native linux ones would of course report btime as btime and ptime as ptime).

statx syscall API is or rather should not be filesystem specific. If every filesystem decides to fill members differently then how could somebody write reasonable userspasce application? It would contain lot of spaghetti code like this:

  statx(...buf...);
  if (fs == fs_type1) {
    process_buf_for_type1(buf);
  } else if (fs == fs_type2) {
    process_buf_for_type2(buf);
  } else if ...

And such thing is not API anymore.

If every filesystem decides on its own how it fills, then it would not be able to write "rsync"-like backup or forensic tool to copy data to some other storage (does not have to be fs) or even to different filesystem on linux.

Things for which filesystems could decide how to handle are private fs ioctl calls which are specific for individual filesystems.

Quoted 10 lines

Thanks,
koraynilay

Quoted 5 lines
Quoted 5 lines

Thanks,
koraynilay

Quoted 2 lines

Pali

#58 lore raw
In reply to koraynilay
Quoted 91 lines · koraynilay
Quoted 48 lines · Pali Rohár
Quoted 12 lines · On Wednesday 18 November 2026 15:58:02 koraynilay wrote:
Quoted 11 lines · Pali Rohár

Hello,

I have just one issue with the userspace API. It does not allow me to figure out what is the source of statx btime field. If it is fs ptime or fs btime because this RFC implementation is mixing both fs ptime and fs btime into the statx btime field.

I have feeling that this is quite a mess in API and I would like to see a clear distinguish between btime and ptime in the API, like there is a difference in the fs storage.

Quoted 6 lines
Quoted 3 lines

If the btime is used for forensic analysis then somehow I would expect that the statx would not report / not fill changeable ptime value into the statx btime.

Hi, for native linux filesystems it will report ptime as PTIME and btime as BTIME (also semnatically).

That is fine.

Quoted 4 lines

for the windows-like ones that only have
ptime (semantically) I think it's reasonable to not expect btime to be immutable, since they are meant to be used with other OSs who lack btime semantics.

The problem is here that the RFC statx API does not provide this information that the fs lacks btime semantics and instead it fills non-immutable ptime value there.

I'm pointing only about this inconsistency.

Quoted 7 lines
Quoted 7 lines

It would be really helpful if the statx API on inode can differ between:

1. btime is present and its value is ..., ptime is not supported
2. btime is not supported, ptime is set to value ...
3. btime is present and its value is ..., ptime is set to value ...
4. both btime and ptime are not supported

Quoted 7 lines
Quoted 3 lines

This should cover all cases of different filesystems and also allows userspace to do proper backup of both ptime and btime fields (if it want to do forensic analysis or anything else).

These should already all be covered by STATX_BTIME/PTIME and their fields in struct statx, the only problems are windows-like filesystems, which IMO shuold be handled as mentioned above.

Quoted 5 lines

Exactly, I pointed out about these problems. I somehow expect that the new API would be generic and uniform across filesystem. IMHO it does not matter if the filesystem is windows-like or not (there are also FreeBSD fs and also others which allows to modify that time). So better description is fs belongs to category 2. from my above description.

Ah yes, I used windows-like to mean "only have ptime semantics", so same as your category 2.

Quoted 9 lines
Quoted 4 lines

Of course, as in the other discussion, I'm open to changing ptime NTFS/exFAT/... support to remove btime altogether and only use ptime for their own crtime if that's what wanted (I'm fairly impartial on this specific issue).

I'm giving some ideas how to possible handle this situation:

1. do not fill btime it at all when it is not available (remove btime altogether - the case like you wrote above)

This would be the most semantically correct option, but would break at least 1 script/program/use case.

Quoted 2 lines

2. when userspace ask both ptime and btime, then do not fill btime (remove btime altogether - but only for that new case)

This probably is the best compromise.

Quoted 3 lines

3. fill btime with ptime value, but add a new output flag indicating that the btime is not present at all and instead kernel filled ptime value into the statx btime field

I don't really like this, it adds complexity and uses memory/1 flag big for a single specific field, IMO it's not worth it.

Quoted 4 lines

4. let statx btime as currently is, and add two new statx fields:
immutable_btime and ptime. immutable_btime would be filled only if the fs supports real btime (so not for ntfs/extfat crtime) and ptime would be what is currently in RFC

I think this is also too complex.

Quoted 9 lines
Quoted 2 lines

Ideas 2. 3. and 4. should be fully backward compatible as it would affect statx output only when called with new flags.

Then 2. is probably the best way to go forward (maybe I'll include it in some way in v5), but I think we should let each filesystem maintainer decide if they think their users want to have statx report their own crtime as btime, ptime or both (native linux ones would of course report btime as btime and ptime as ptime).

Guys,

Let's take a step back.

If this discussion is proving anything is that the btime/ptime duality is a big headache and it's going to be a source of confusion to users even if we come up with some smart pants consistent semantics.

As Jeff writes, I think we should consider making btime mutable be a per-fs choice and not an API limitation.

A filesystem can even decide to store both the forensics btime alongside the user settable crtime.

There are some precedents in xfs with settable UUID which is a different field then the origin UUID from mkfs.

Fs that have immutable btime have a few choices:
1. Keep it immutable
2. Start making it muttbale (like the Win fs)
3. Start making the user visible btime (STATX_BTIME) mutable but keep the forensics btime on-disk for, well, forensics

If btime becomes settable via options 2 or 3, this could require admin opt-in (e.g. tune2fs -O crtime).

With option 3 the crtime feature would be ROCOMPAT With option 2, it could probably be COMPAT. Maybe.

If we accept this story and the major fs maintainers are in agreement with this plan, then I think the missing piece is making the "settable mask" visible to users via the new API.

IOW, we need to somehow export FS_XFLAG_RDONLY_MASK to userspace instead of only exporting the supported mask. And then with the addition of xflags_mask, we could also -EINVAL on users trying to set readonly flags/values.

Perhaps a single xflags_settable_mask is enough.

For file_setattr(), xflags_mask is anyway a set-those mask. For file_getattr(), does it matter if we get an answer Filesystem does not support casefold on this file OR
Filesystem does not have casefold on this file and you cannot set casefold on this file

It's kind of the same, isn't it?

What do you say?

Shall we drop PTIME in favor of "is BTIME settable?" API? Leaving STATX_BTIME exactly as is.

Thanks,
Amir.

maintainer
#59 lore raw
Quoted 149 lines · Amir Goldstein
Quoted 91 lines · koraynilay
Quoted 48 lines · Pali Rohár
Quoted 12 lines · On Wednesday 18 November 2026 15:58:02 koraynilay wrote:
Quoted 11 lines · Pali Rohár

Hello,

I have just one issue with the userspace API. It does not allow me to figure out what is the source of statx btime field. If it is fs ptime or fs btime because this RFC implementation is mixing both fs ptime and fs btime into the statx btime field.

I have feeling that this is quite a mess in API and I would like to see a clear distinguish between btime and ptime in the API, like there is a difference in the fs storage.

Quoted 6 lines
Quoted 3 lines

If the btime is used for forensic analysis then somehow I would expect that the statx would not report / not fill changeable ptime value into the statx btime.

Hi, for native linux filesystems it will report ptime as PTIME and btime as BTIME (also semnatically).

That is fine.

Quoted 4 lines

for the windows-like ones that only have
ptime (semantically) I think it's reasonable to not expect btime to be immutable, since they are meant to be used with other OSs who lack btime semantics.

The problem is here that the RFC statx API does not provide this information that the fs lacks btime semantics and instead it fills non-immutable ptime value there.

I'm pointing only about this inconsistency.

Quoted 7 lines
Quoted 7 lines

It would be really helpful if the statx API on inode can differ between:

1. btime is present and its value is ..., ptime is not supported
2. btime is not supported, ptime is set to value ...
3. btime is present and its value is ..., ptime is set to value ...
4. both btime and ptime are not supported

Quoted 7 lines
Quoted 3 lines

This should cover all cases of different filesystems and also allows userspace to do proper backup of both ptime and btime fields (if it want to do forensic analysis or anything else).

These should already all be covered by STATX_BTIME/PTIME and their fields in struct statx, the only problems are windows-like filesystems, which IMO shuold be handled as mentioned above.

Quoted 5 lines

Exactly, I pointed out about these problems. I somehow expect that the new API would be generic and uniform across filesystem. IMHO it does not matter if the filesystem is windows-like or not (there are also FreeBSD fs and also others which allows to modify that time). So better description is fs belongs to category 2. from my above description.

Ah yes, I used windows-like to mean "only have ptime semantics", so same as your category 2.

Quoted 9 lines
Quoted 4 lines

Of course, as in the other discussion, I'm open to changing ptime NTFS/exFAT/... support to remove btime altogether and only use ptime for their own crtime if that's what wanted (I'm fairly impartial on this specific issue).

I'm giving some ideas how to possible handle this situation:

1. do not fill btime it at all when it is not available (remove btime altogether - the case like you wrote above)

This would be the most semantically correct option, but would break at least 1 script/program/use case.

Quoted 2 lines

2. when userspace ask both ptime and btime, then do not fill btime (remove btime altogether - but only for that new case)

This probably is the best compromise.

Quoted 3 lines

3. fill btime with ptime value, but add a new output flag indicating that the btime is not present at all and instead kernel filled ptime value into the statx btime field

I don't really like this, it adds complexity and uses memory/1 flag big for a single specific field, IMO it's not worth it.

Quoted 4 lines

4. let statx btime as currently is, and add two new statx fields:
immutable_btime and ptime. immutable_btime would be filled only if the fs supports real btime (so not for ntfs/extfat crtime) and ptime would be what is currently in RFC

I think this is also too complex.

Quoted 9 lines
Quoted 2 lines

Ideas 2. 3. and 4. should be fully backward compatible as it would affect statx output only when called with new flags.

Then 2. is probably the best way to go forward (maybe I'll include it in some way in v5), but I think we should let each filesystem maintainer decide if they think their users want to have statx report their own crtime as btime, ptime or both (native linux ones would of course report btime as btime and ptime as ptime).

Guys,

Let's take a step back.

If this discussion is proving anything is that the btime/ptime duality is a big headache and it's going to be a source of confusion to users even if we come up with some smart pants consistent semantics.

As Jeff writes, I think we should consider making btime mutable be a per-fs choice and not an API limitation.

A filesystem can even decide to store both the forensics btime alongside the user settable crtime.

There are some precedents in xfs with settable UUID which is a different field then the origin UUID from mkfs.

Fs that have immutable btime have a few choices:
1. Keep it immutable
2. Start making it muttbale (like the Win fs)
3. Start making the user visible btime (STATX_BTIME) mutable but keep the forensics btime on-disk for, well, forensics

If btime becomes settable via options 2 or 3, this could require admin opt-in (e.g. tune2fs -O crtime).

With option 3 the crtime feature would be ROCOMPAT With option 2, it could probably be COMPAT. Maybe.

If we accept this story and the major fs maintainers are in agreement with this plan, then I think the missing piece is making the "settable mask" visible to users via the new API.

IOW, we need to somehow export FS_XFLAG_RDONLY_MASK to userspace instead of only exporting the supported mask. And then with the addition of xflags_mask, we could also -EINVAL on users trying to set readonly flags/values.

Perhaps a single xflags_settable_mask is enough.

For file_setattr(), xflags_mask is anyway a set-those mask. For file_getattr(), does it matter if we get an answer Filesystem does not support casefold on this file OR
Filesystem does not have casefold on this file and you cannot set casefold on this file

Quoted 8 lines

It's kind of the same, isn't it?

What do you say?

Shall we drop PTIME in favor of "is BTIME settable?" API? Leaving STATX_BTIME exactly as is.

+1

I think this is the better approach.

Looking over some of the earlier discussions around this since 2010 (!?!): I think some of the XFS devs objected to making it settable for forensic reasons. So, on XFS you might need to rev the on-disk format if you want to do it there to preserve the "historical" btime, and maybe some xfs userland work to make it accessible for forensics.

For the record, the statx manpage documents the btime field very sparsely:

stx_btime
The file's creation timestamp.

There is no documented guarantee that this will be immutable, AFAICT.

Signature · 1 line
Jeff Layton <[email protected]>
#60 lore raw
Quoted 2 lines · Jeff Layton

On Wed, 2026-11-18 at 18:28 +0100, Amir Goldstein wrote:

...

Quoted 58 lines
Quoted 47 lines

Guys,

Let's take a step back.

If this discussion is proving anything is that the btime/ptime duality is a big headache and it's going to be a source of confusion to users even if we come up with some smart pants consistent semantics.

As Jeff writes, I think we should consider making btime mutable be a per-fs choice and not an API limitation.

A filesystem can even decide to store both the forensics btime alongside the user settable crtime.

There are some precedents in xfs with settable UUID which is a different field then the origin UUID from mkfs.

Fs that have immutable btime have a few choices:
1. Keep it immutable
2. Start making it muttbale (like the Win fs)
3. Start making the user visible btime (STATX_BTIME) mutable but keep the forensics btime on-disk for, well, forensics

If btime becomes settable via options 2 or 3, this could require admin opt-in (e.g. tune2fs -O crtime).

With option 3 the crtime feature would be ROCOMPAT With option 2, it could probably be COMPAT. Maybe.

If we accept this story and the major fs maintainers are in agreement with this plan, then I think the missing piece is making the "settable mask" visible to users via the new API.

IOW, we need to somehow export FS_XFLAG_RDONLY_MASK to userspace instead of only exporting the supported mask. And then with the addition of xflags_mask, we could also -EINVAL on users trying to set readonly flags/values.

Perhaps a single xflags_settable_mask is enough.

For file_setattr(), xflags_mask is anyway a set-those mask. For file_getattr(), does it matter if we get an answer Filesystem does not support casefold on this file OR
Filesystem does not have casefold on this file and you cannot set casefold on this file

Quoted 8 lines

It's kind of the same, isn't it?

What do you say?

Shall we drop PTIME in favor of "is BTIME settable?" API? Leaving STATX_BTIME exactly as is.

+1

Quoted 7 lines

I think this is the better approach.

Looking over some of the earlier discussions around this since 2010 (!?!): I think some of the XFS devs objected to making it settable for forensic reasons. So, on XFS you might need to rev the on-disk format if you want to do it there to preserve the "historical" btime, and maybe some xfs userland work to make it accessible for forensics.

XFS_IOC_FSBULKSTAT will likely continue to publish the original bs_btime. if a mutable field is added it could be published as bs_crtime.

For forensics this should be enough.

Quoted 8 lines

For the record, the statx manpage documents the btime field very sparsely:

stx_btime
The file's creation timestamp.

There is no documented guarantee that this will be immutable, AFAICT.

Yes, and it really isn't immutable for cifs already. It's just that we don't have a standard API to change it.

Thanks,
Amir.

#61 lore raw
In reply to Amir Goldstein
Quoted 151 lines · On Wednesday 18 November 2026 18:28:04 Amir Goldstein wrote:
Quoted 91 lines · koraynilay
Quoted 48 lines · Pali Rohár
Quoted 12 lines · On Wednesday 18 November 2026 15:58:02 koraynilay wrote:
Quoted 11 lines · Pali Rohár

Hello,

I have just one issue with the userspace API. It does not allow me to figure out what is the source of statx btime field. If it is fs ptime or fs btime because this RFC implementation is mixing both fs ptime and fs btime into the statx btime field.

I have feeling that this is quite a mess in API and I would like to see a clear distinguish between btime and ptime in the API, like there is a difference in the fs storage.

Quoted 6 lines
Quoted 3 lines

If the btime is used for forensic analysis then somehow I would expect that the statx would not report / not fill changeable ptime value into the statx btime.

Hi, for native linux filesystems it will report ptime as PTIME and btime as BTIME (also semnatically).

That is fine.

Quoted 4 lines

for the windows-like ones that only have
ptime (semantically) I think it's reasonable to not expect btime to be immutable, since they are meant to be used with other OSs who lack btime semantics.

The problem is here that the RFC statx API does not provide this information that the fs lacks btime semantics and instead it fills non-immutable ptime value there.

I'm pointing only about this inconsistency.

Quoted 7 lines
Quoted 7 lines

It would be really helpful if the statx API on inode can differ between:

1. btime is present and its value is ..., ptime is not supported
2. btime is not supported, ptime is set to value ...
3. btime is present and its value is ..., ptime is set to value ...
4. both btime and ptime are not supported

Quoted 7 lines
Quoted 3 lines

This should cover all cases of different filesystems and also allows userspace to do proper backup of both ptime and btime fields (if it want to do forensic analysis or anything else).

These should already all be covered by STATX_BTIME/PTIME and their fields in struct statx, the only problems are windows-like filesystems, which IMO shuold be handled as mentioned above.

Quoted 5 lines

Exactly, I pointed out about these problems. I somehow expect that the new API would be generic and uniform across filesystem. IMHO it does not matter if the filesystem is windows-like or not (there are also FreeBSD fs and also others which allows to modify that time). So better description is fs belongs to category 2. from my above description.

Ah yes, I used windows-like to mean "only have ptime semantics", so same as your category 2.

Quoted 9 lines
Quoted 4 lines

Of course, as in the other discussion, I'm open to changing ptime NTFS/exFAT/... support to remove btime altogether and only use ptime for their own crtime if that's what wanted (I'm fairly impartial on this specific issue).

I'm giving some ideas how to possible handle this situation:

1. do not fill btime it at all when it is not available (remove btime altogether - the case like you wrote above)

This would be the most semantically correct option, but would break at least 1 script/program/use case.

Quoted 2 lines

2. when userspace ask both ptime and btime, then do not fill btime (remove btime altogether - but only for that new case)

This probably is the best compromise.

Quoted 3 lines

3. fill btime with ptime value, but add a new output flag indicating that the btime is not present at all and instead kernel filled ptime value into the statx btime field

I don't really like this, it adds complexity and uses memory/1 flag big for a single specific field, IMO it's not worth it.

Quoted 4 lines

4. let statx btime as currently is, and add two new statx fields:
immutable_btime and ptime. immutable_btime would be filled only if the fs supports real btime (so not for ntfs/extfat crtime) and ptime would be what is currently in RFC

I think this is also too complex.

Quoted 9 lines
Quoted 2 lines

Ideas 2. 3. and 4. should be fully backward compatible as it would affect statx output only when called with new flags.

Then 2. is probably the best way to go forward (maybe I'll include it in some way in v5), but I think we should let each filesystem maintainer decide if they think their users want to have statx report their own crtime as btime, ptime or both (native linux ones would of course report btime as btime and ptime as ptime).

Guys,

Let's take a step back.

If this discussion is proving anything is that the btime/ptime duality is a big headache and it's going to be a source of confusion to users even if we come up with some smart pants consistent semantics.

As Jeff writes, I think we should consider making btime mutable be a per-fs choice and not an API limitation.

A filesystem can even decide to store both the forensics btime alongside the user settable crtime.

There are some precedents in xfs with settable UUID which is a different field then the origin UUID from mkfs.

Fs that have immutable btime have a few choices:
1. Keep it immutable
2. Start making it muttbale (like the Win fs)
3. Start making the user visible btime (STATX_BTIME) mutable but keep the forensics btime on-disk for, well, forensics

If btime becomes settable via options 2 or 3, this could require admin opt-in (e.g. tune2fs -O crtime).

With option 3 the crtime feature would be ROCOMPAT With option 2, it could probably be COMPAT. Maybe.

If we accept this story and the major fs maintainers are in agreement with this plan, then I think the missing piece is making the "settable mask" visible to users via the new API.

IOW, we need to somehow export FS_XFLAG_RDONLY_MASK to userspace instead of only exporting the supported mask. And then with the addition of xflags_mask, we could also -EINVAL on users trying to set readonly flags/values.

Perhaps a single xflags_settable_mask is enough.

For file_setattr(), xflags_mask is anyway a set-those mask. For file_getattr(), does it matter if we get an answer Filesystem does not support casefold on this file OR
Filesystem does not have casefold on this file and you cannot set casefold on this file

It's kind of the same, isn't it?

Quoted 7 lines

What do you say?

Shall we drop PTIME in favor of "is BTIME settable?" API? Leaving STATX_BTIME exactly as is.

Thanks,
Amir.

From the beginning I had a feeling that this is not an option at all and that is why all that ptime-way was chosen.

So thanks for brining this up. I like this your idea. It address the original problem with backup/restore of "create time".

But I would like to point out about another thing in this your idea. It would be nice to have an API to retrieve that "forensics on-diks btime" in case there would be filesystems which choose option 3.

#62 lore raw
Quoted 164 lines · Pali Rohár
Quoted 151 lines · On Wednesday 18 November 2026 18:28:04 Amir Goldstein wrote:
Quoted 91 lines · koraynilay
Quoted 48 lines · Pali Rohár
Quoted 12 lines · On Wednesday 18 November 2026 15:58:02 koraynilay wrote:
Quoted 11 lines · Pali Rohár

Hello,

I have just one issue with the userspace API. It does not allow me to figure out what is the source of statx btime field. If it is fs ptime or fs btime because this RFC implementation is mixing both fs ptime and fs btime into the statx btime field.

I have feeling that this is quite a mess in API and I would like to see a clear distinguish between btime and ptime in the API, like there is a difference in the fs storage.

Quoted 6 lines
Quoted 3 lines

If the btime is used for forensic analysis then somehow I would expect that the statx would not report / not fill changeable ptime value into the statx btime.

Hi, for native linux filesystems it will report ptime as PTIME and btime as BTIME (also semnatically).

That is fine.

Quoted 4 lines

for the windows-like ones that only have
ptime (semantically) I think it's reasonable to not expect btime to be immutable, since they are meant to be used with other OSs who lack btime semantics.

The problem is here that the RFC statx API does not provide this information that the fs lacks btime semantics and instead it fills non-immutable ptime value there.

I'm pointing only about this inconsistency.

Quoted 7 lines
Quoted 7 lines

It would be really helpful if the statx API on inode can differ between:

1. btime is present and its value is ..., ptime is not supported
2. btime is not supported, ptime is set to value ...
3. btime is present and its value is ..., ptime is set to value ...
4. both btime and ptime are not supported

Quoted 7 lines
Quoted 3 lines

This should cover all cases of different filesystems and also allows userspace to do proper backup of both ptime and btime fields (if it want to do forensic analysis or anything else).

These should already all be covered by STATX_BTIME/PTIME and their fields in struct statx, the only problems are windows-like filesystems, which IMO shuold be handled as mentioned above.

Quoted 5 lines

Exactly, I pointed out about these problems. I somehow expect that the new API would be generic and uniform across filesystem. IMHO it does not matter if the filesystem is windows-like or not (there are also FreeBSD fs and also others which allows to modify that time). So better description is fs belongs to category 2. from my above description.

Ah yes, I used windows-like to mean "only have ptime semantics", so same as your category 2.

Quoted 9 lines
Quoted 4 lines

Of course, as in the other discussion, I'm open to changing ptime NTFS/exFAT/... support to remove btime altogether and only use ptime for their own crtime if that's what wanted (I'm fairly impartial on this specific issue).

I'm giving some ideas how to possible handle this situation:

1. do not fill btime it at all when it is not available (remove btime altogether - the case like you wrote above)

This would be the most semantically correct option, but would break at least 1 script/program/use case.

Quoted 2 lines

2. when userspace ask both ptime and btime, then do not fill btime (remove btime altogether - but only for that new case)

This probably is the best compromise.

Quoted 3 lines

3. fill btime with ptime value, but add a new output flag indicating that the btime is not present at all and instead kernel filled ptime value into the statx btime field

I don't really like this, it adds complexity and uses memory/1 flag big for a single specific field, IMO it's not worth it.

Quoted 4 lines

4. let statx btime as currently is, and add two new statx fields:
immutable_btime and ptime. immutable_btime would be filled only if the fs supports real btime (so not for ntfs/extfat crtime) and ptime would be what is currently in RFC

I think this is also too complex.

Quoted 9 lines
Quoted 2 lines

Ideas 2. 3. and 4. should be fully backward compatible as it would affect statx output only when called with new flags.

Then 2. is probably the best way to go forward (maybe I'll include it in some way in v5), but I think we should let each filesystem maintainer decide if they think their users want to have statx report their own crtime as btime, ptime or both (native linux ones would of course report btime as btime and ptime as ptime).

Guys,

Let's take a step back.

If this discussion is proving anything is that the btime/ptime duality is a big headache and it's going to be a source of confusion to users even if we come up with some smart pants consistent semantics.

As Jeff writes, I think we should consider making btime mutable be a per-fs choice and not an API limitation.

A filesystem can even decide to store both the forensics btime alongside the user settable crtime.

There are some precedents in xfs with settable UUID which is a different field then the origin UUID from mkfs.

Fs that have immutable btime have a few choices:
1. Keep it immutable
2. Start making it muttbale (like the Win fs)
3. Start making the user visible btime (STATX_BTIME) mutable but keep the forensics btime on-disk for, well, forensics

If btime becomes settable via options 2 or 3, this could require admin opt-in (e.g. tune2fs -O crtime).

With option 3 the crtime feature would be ROCOMPAT With option 2, it could probably be COMPAT. Maybe.

If we accept this story and the major fs maintainers are in agreement with this plan, then I think the missing piece is making the "settable mask" visible to users via the new API.

IOW, we need to somehow export FS_XFLAG_RDONLY_MASK to userspace instead of only exporting the supported mask. And then with the addition of xflags_mask, we could also -EINVAL on users trying to set readonly flags/values.

Perhaps a single xflags_settable_mask is enough.

For file_setattr(), xflags_mask is anyway a set-those mask. For file_getattr(), does it matter if we get an answer Filesystem does not support casefold on this file OR
Filesystem does not have casefold on this file and you cannot set casefold on this file

It's kind of the same, isn't it?

Quoted 7 lines

What do you say?

Shall we drop PTIME in favor of "is BTIME settable?" API? Leaving STATX_BTIME exactly as is.

Thanks,
Amir.

From the beginning I had a feeling that this is not an option at all and that is why all that ptime-way was chosen.

Quoted 6 lines

So thanks for brining this up. I like this your idea. It address the original problem with backup/restore of "create time".

But I would like to point out about another thing in this your idea. It would be nice to have an API to retrieve that "forensics on-diks btime" in case there would be filesystems which choose option 3.

Anticipated this question ;)

As I said there is already a precedent with xfs settable uuid (I think other fs have it as well?). All the metadata is available to admin via xfs specific ioctls, but not via the generic vfs APIs not even to vfs via vfs APIs.

I don't know if this is good enough, that's why I urged to get an ACK on the API design from major fs maintainers.

Thanks,
Amir.