[PATCH v4 8/9] ext4: convert to multigrain timestamps

From: Jeff Layton
Date: Thu May 18 2023 - 07:49:26 EST


Signed-off-by: Jeff Layton <jlayton@xxxxxxxxxx>
---
fs/ext4/inode.c | 17 +++++++++++++++--
fs/ext4/super.c | 2 +-
2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index e0bbcf7a07b5..37840aeb7ff9 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4235,6 +4235,19 @@ static int ext4_inode_blocks_set(struct ext4_inode *raw_inode,
return 0;
}

+static void ext4_inode_set_ctime(struct inode *inode, struct ext4_inode *raw_inode)
+{
+ struct timespec64 ctime = ctime_peek(inode);
+
+ if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), i_ctime_extra)) {
+ raw_inode->i_ctime = cpu_to_le32(ctime.tv_sec);
+ raw_inode->i_ctime_extra = ext4_encode_extra_time(&ctime);
+ } else {
+ raw_inode->i_ctime = cpu_to_le32(clamp_t(int32_t,
+ ctime.tv_sec, S32_MIN, S32_MAX));
+ }
+}
+
static int ext4_fill_raw_inode(struct inode *inode, struct ext4_inode *raw_inode)
{
struct ext4_inode_info *ei = EXT4_I(inode);
@@ -4275,7 +4288,7 @@ static int ext4_fill_raw_inode(struct inode *inode, struct ext4_inode *raw_inode
}
raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);

- EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
+ ext4_inode_set_ctime(inode, raw_inode);
EXT4_INODE_SET_XTIME(i_mtime, inode, raw_inode);
EXT4_INODE_SET_XTIME(i_atime, inode, raw_inode);
EXT4_EINODE_SET_XTIME(i_crtime, ei, raw_inode);
@@ -4983,7 +4996,7 @@ static void __ext4_update_other_inode_time(struct super_block *sb,
spin_unlock(&inode->i_lock);

spin_lock(&ei->i_raw_lock);
- EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
+ ext4_inode_set_ctime(inode, raw_inode);
EXT4_INODE_SET_XTIME(i_mtime, inode, raw_inode);
EXT4_INODE_SET_XTIME(i_atime, inode, raw_inode);
ext4_inode_csum_set(inode, raw_inode, ei);
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 9680fe753e59..4de4977dcb21 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -7258,7 +7258,7 @@ static struct file_system_type ext4_fs_type = {
.init_fs_context = ext4_init_fs_context,
.parameters = ext4_param_specs,
.kill_sb = kill_block_super,
- .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
+ .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MULTIGRAIN_TS,
};
MODULE_ALIAS_FS("ext4");

--
2.40.1