From: koraynilay <koray.fra@gmail.com>
To: David Sterba <dsterba@suse.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>
Cc: Chris Mason <mason@kernel.org>, Jan Kara <jack@suse.cz>,
"Darrick J . Wong" <djwong@kernel.org>,
Sean Smith <defendthedisabled@gmail.com>,
Andrey Albershteyn <aalbersh@kernel.org>,
linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, koraynilay <koray.fra@gmail.com>
Subject: [RFC PATCH 2/2] btrfs: add provenance time (ptime)
Date: Tue, 27 Oct 2026 23:05:32 +0100 [thread overview]
Message-ID: <20261027220532.736352-3-koray.fra@gmail.com> (raw)
In-Reply-To: <20261027220532.736352-1-koray.fra@gmail.com>
Implement provenance time (ptime) in Btrfs, as introduced in the
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.
Also add the fileattr_has_fsx_mask() helper to include/linux/fileattr.h
to let filesystems check for unsupported xflags while allowing supported
ones (like ptime). This helper can be used in the same way as
fileattr_has_fsx().
Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.4.7
Signed-off-by: koraynilay <koray.fra@gmail.com>
---
fs/btrfs/btrfs_inode.h | 4 ++++
fs/btrfs/delayed-inode.c | 6 ++++++
fs/btrfs/inode.c | 17 ++++++++++++++++-
fs/btrfs/ioctl.c | 12 +++++++++++-
fs/btrfs/print-tree.c | 1 +
fs/btrfs/tree-log.c | 3 +++
include/linux/fileattr.h | 22 +++++++++++++++++++---
include/uapi/linux/btrfs_tree.h | 3 ++-
8 files changed, 62 insertions(+), 6 deletions(-)
diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h
index 0227789e911d..5afcf99b758c 100644
--- a/fs/btrfs/btrfs_inode.h
+++ b/fs/btrfs/btrfs_inode.h
@@ -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;
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index 333ce8b52489..eef73ebb4a52 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -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;
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 1272e0d01485..7c3cd06113bc 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -4094,6 +4094,9 @@ 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);
+
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);
@@ -4286,6 +4289,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));
@@ -6025,6 +6031,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;
@@ -6751,6 +6759,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
@@ -8095,6 +8105,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);
@@ -8241,9 +8254,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)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index f3e2afe221be..48598a99bddb 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -275,6 +275,9 @@ 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;
return 0;
}
@@ -294,7 +297,10 @@ 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, FS_XFLAG_PTIME))
return -EOPNOTSUPP;
fsflags = btrfs_mask_fsflags_for_type(&inode->vfs_inode, fa->flags);
@@ -436,6 +442,10 @@ int btrfs_fileattr_set(const struct mnt_idmap *idmap,
}
update_flags:
+ if (fa->fsx_xflags & 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);
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index 53e726119ca7..ba385d0ed9ed 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c
@@ -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)
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 1d9dfb63fc5a..72a4a92b40b9 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -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
diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
index 0b93f9609284..f45377fdaf38 100644
--- a/include/linux/fileattr.h
+++ b/include/linux/fileattr.h
@@ -64,6 +64,24 @@ 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
@@ -73,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);
diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h
index 47ee52859b45..c360b3e95f45 100644
--- a/include/uapi/linux/btrfs_tree.h
+++ b/include/uapi/linux/btrfs_tree.h
@@ -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;
--
2.56.0
prev parent reply other threads:[~2026-10-27 22:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 22:05 [RFC PATCH 0/2] " koraynilay
2026-10-27 22:05 ` [RFC PATCH 1/2] vfs: " koraynilay
2026-10-27 22:05 ` koraynilay [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261027220532.736352-3-koray.fra@gmail.com \
--to=koray.fra@gmail.com \
--cc=aalbersh@kernel.org \
--cc=brauner@kernel.org \
--cc=defendthedisabled@gmail.com \
--cc=djwong@kernel.org \
--cc=dsterba@suse.com \
--cc=jack@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mason@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®