2022-02-07 08:23:17

by Xavier Roche

[permalink] [raw]
Subject: [PATCH RFC v1] tmpfs: support for file creation time

Various filesystems (including ext4) now support file creation time.
This patch tentatively adds such support for tmpfs-based filesystems.

The reason is that creation time has been supported on an increasing number
of filesystems (this information can be retrieved through the statx()
userland function), and its support for tmpfs would add consistency.
Example of use includes checking the creation time of an ephemeral status file
being updated (such as a "work in progress" placeholder), to get two time
points (starting point and last update).

Note that I am nothing but a new contributor, and while this patch has
been tested (and userland results checked), the logic might be broken.

Signed-off-by: Xavier Roche <[email protected]>
---
include/linux/shmem_fs.h | 1 +
mm/shmem.c | 11 +++++++++++
2 files changed, 12 insertions(+)

diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h
index e65b80ed09e7..29787767c3b9 100644
--- a/include/linux/shmem_fs.h
+++ b/include/linux/shmem_fs.h
@@ -25,6 +25,7 @@ struct shmem_inode_info {
struct simple_xattrs xattrs; /* list of xattrs */
atomic_t stop_eviction; /* hold when working on inode */
struct inode vfs_inode;
+ struct timespec64 i_crtime; /* file creation time */
};

struct shmem_sb_info {
diff --git a/mm/shmem.c b/mm/shmem.c
index a09b29ec2b45..5a3907712c4f 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1061,6 +1061,12 @@ static int shmem_getattr(struct user_namespace *mnt_userns,
if (shmem_is_huge(NULL, inode, 0))
stat->blksize = HPAGE_PMD_SIZE;

+ if ((request_mask & STATX_BTIME)) {
+ stat->result_mask |= STATX_BTIME;
+ stat->btime.tv_sec = info->i_crtime.tv_sec;
+ stat->btime.tv_nsec = info->i_crtime.tv_nsec;
+ }
+
return 0;
}

@@ -2265,6 +2271,7 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode
atomic_set(&info->stop_eviction, 0);
info->seals = F_SEAL_SEAL;
info->flags = flags & VM_NORESERVE;
+ info->i_crtime = inode->i_mtime;
INIT_LIST_HEAD(&info->shrinklist);
INIT_LIST_HEAD(&info->swaplist);
simple_xattrs_init(&info->xattrs);
@@ -3196,6 +3203,7 @@ static ssize_t shmem_listxattr(struct dentry *dentry, char *buffer, size_t size)
#endif /* CONFIG_TMPFS_XATTR */

static const struct inode_operations shmem_short_symlink_operations = {
+ .getattr = shmem_getattr,
.get_link = simple_get_link,
#ifdef CONFIG_TMPFS_XATTR
.listxattr = shmem_listxattr,
@@ -3203,6 +3211,7 @@ static const struct inode_operations shmem_short_symlink_operations = {
};

static const struct inode_operations shmem_symlink_inode_operations = {
+ .getattr = shmem_getattr,
.get_link = shmem_get_link,
#ifdef CONFIG_TMPFS_XATTR
.listxattr = shmem_listxattr,
@@ -3790,6 +3799,7 @@ static const struct inode_operations shmem_inode_operations = {

static const struct inode_operations shmem_dir_inode_operations = {
#ifdef CONFIG_TMPFS
+ .getattr = shmem_getattr,
.create = shmem_create,
.lookup = simple_lookup,
.link = shmem_link,
@@ -3811,6 +3821,7 @@ static const struct inode_operations shmem_dir_inode_operations = {
};

static const struct inode_operations shmem_special_inode_operations = {
+ .getattr = shmem_getattr,
#ifdef CONFIG_TMPFS_XATTR
.listxattr = shmem_listxattr,
#endif
--
2.25.1



2022-02-09 14:45:07

by Jean Delvare

[permalink] [raw]
Subject: Re: [PATCH RFC v1] tmpfs: support for file creation time

On Sat, 5 Feb 2022 15:12:33 +0100, Xavier Roche wrote:
> Various filesystems (including ext4) now support file creation time.
> This patch tentatively adds such support for tmpfs-based filesystems.
>
> The reason is that creation time has been supported on an increasing number
> of filesystems (this information can be retrieved through the statx()
> userland function), and its support for tmpfs would add consistency.
> Example of use includes checking the creation time of an ephemeral status file
> being updated (such as a "work in progress" placeholder), to get two time
> points (starting point and last update).
>
> Note that I am nothing but a new contributor, and while this patch has
> been tested (and userland results checked), the logic might be broken.
>
> Signed-off-by: Xavier Roche <[email protected]>
> ---
> include/linux/shmem_fs.h | 1 +
> mm/shmem.c | 11 +++++++++++
> 2 files changed, 12 insertions(+)
> (...)

Tested-by: Jean Delvare <[email protected]>

Code looks reasonable, but take my review with a grain of salt as this
isn't my area.

Reviewed-by: Jean Delvare <[email protected]>

--
Jean Delvare
SUSE L3 Support