nilfs2: introduce atime support
Viacheslav Dubeyko
maintainerRFC PATCH 1/1 nilfs2: introduce atime support
Currently, NILFS2 doesn't support atime. And it is possible to see the evidence of it by running generic/003 test-case of xfstests suite:
sudo ./check generic/003
FSTYP -- nilfs2
PLATFORM -- Linux/x86_64 hfsplus-testing-0001 6.18.0-rc1+ #10 SMP PREEMPT_DYNAMIC Fri Nov 28 20:48:25 PST 2025 MKFS_OPTIONS -- /dev/loop51MOUNT_OPTIONS -- /dev/loop51 /mnt/scratch
generic/003 35s ... - output mismatch (see xfstests-dev/results//generic/003.out.bad)
This patch exchanges i_xattr on i_atime and i_pad on i_atime_nsec fields of struct nilfs_inode in the on-disk layout, removes all declarations that disabled atime support. Also, it modifies nilfs_read_inode_common(), nilfs_write_inode_common(), and nilfs_setattr() with the goal of proper atime support.
sudo ./check generic/003
FSTYP -- nilfs2 PLATFORM -- Linux/x86_64 nilfs2-testing 6.19.0-rc1+ #8 SMP PREEMPT_DYNAMIC Tue Feb 17 16:21:59 PST 2026 MKFS_OPTIONS -- /dev/loop51
MOUNT_OPTIONS -- /dev/loop51 /mnt/scratch
generic/003 30s ... 34s
Ran: generic/003
Passed all 1 tests
[1] https://github.com/nilfs-dev/nilfs2/issues/7
--- fs/nilfs2/Kconfig | 2 +- fs/nilfs2/inode.c | 18 ++++++++++++++---- fs/nilfs2/nilfs.h | 8 ++------ fs/nilfs2/segment.c | 2 -- fs/nilfs2/super.c | 5 ----- include/uapi/linux/nilfs2_ondisk.h | 8 ++++---- 6 files changed, 21 insertions(+), 22 deletions(-)
fs/nilfs2/Kconfig +1 -1
@@ -20,7 +20,7 @@ config NILFS2_FS snapshot is mountable as a read-only file system concurrently with its writable mount, and this feature is convenient for online backup. - Some features including atime, extended attributes, and POSIX ACLs, + Some features including extended attributes, and POSIX ACLs, are not supported yet. To compile this file system support as a module, choose M here: the
fs/nilfs2/inode.c +14 -4
@@ -395,8 +395,8 @@ void nilfs_set_inode_flags(struct inode *inode) new_fl |=S_NOATIME ;if (flags &FS_DIRSYNC_FL ) new_fl |=S_DIRSYNC ; -inode_set_flags (inode, new_fl,S_SYNC |S_APPEND |S_IMMUTABLE | -S_NOATIME |S_DIRSYNC ); +inode_set_flags (inode, new_fl, +S_SYNC |S_APPEND |S_IMMUTABLE |S_DIRSYNC ); } int nilfs_read_inode_common(struct inode *inode,
@@ -410,12 +410,13 @@ int nilfs_read_inode_common(struct inode *inode,i_gid_write (inode,le32_to_cpu (raw_inode->i_gid));set_nlink (inode,le16_to_cpu (raw_inode->i_links_count)); inode->i_size =le64_to_cpu (raw_inode->i_size); -inode_set_atime (inode,le64_to_cpu (raw_inode->i_mtime), -le32_to_cpu (raw_inode->i_mtime_nsec)); +inode_set_atime (inode,le64_to_cpu (raw_inode->i_atime), +le32_to_cpu (raw_inode->i_atime_nsec));inode_set_ctime (inode,le64_to_cpu (raw_inode->i_ctime),le32_to_cpu (raw_inode->i_ctime_nsec));inode_set_mtime (inode,le64_to_cpu (raw_inode->i_mtime),le32_to_cpu (raw_inode->i_mtime_nsec)); +if (nilfs_is_metadata_file_inode (inode) && !S_ISREG (inode->i_mode))return -EIO ;/* this inode is for metadata and corrupted */ if (inode->i_nlink ==0 )
@@ -723,8 +724,10 @@ void nilfs_write_inode_common(struct inode *inode, raw_inode->i_gid =cpu_to_le32 (i_gid_read (inode)); raw_inode->i_links_count =cpu_to_le16 (inode->i_nlink); raw_inode->i_size =cpu_to_le64 (inode->i_size); + raw_inode->i_atime =cpu_to_le64 (inode_get_atime_sec (inode)); raw_inode->i_ctime =cpu_to_le64 (inode_get_ctime_sec (inode)); raw_inode->i_mtime =cpu_to_le64 (inode_get_mtime_sec (inode)); + raw_inode->i_atime_nsec =cpu_to_le32 (inode_get_atime_nsec (inode)); raw_inode->i_ctime_nsec =cpu_to_le32 (inode_get_ctime_nsec (inode)); raw_inode->i_mtime_nsec =cpu_to_le32 (inode_get_mtime_nsec (inode)); raw_inode->i_blocks =cpu_to_le64 (inode->i_blocks);
@@ -929,6 +932,13 @@ int nilfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,nilfs_truncate (inode); } +if (iattr->ia_valid &ATTR_ATIME ) +inode_set_atime_to_ts (inode, iattr->ia_atime); +if (iattr->ia_valid &ATTR_MTIME ) +inode_set_mtime_to_ts (inode, iattr->ia_mtime); +if (iattr->ia_valid &ATTR_CTIME ) +inode_set_ctime_to_ts (inode, iattr->ia_ctime); +setattr_copy (&nop_mnt_idmap, inode, iattr);mark_inode_dirty (inode);
fs/nilfs2/nilfs.h +2 -6
@@ -27,7 +27,6 @@* @i_state: dynamic state flags * @i_bmap: pointer on i_bmap_data * @i_bmap_data: raw block mapping -* @i_xattr: <TODO> * @i_dir_start_lookup: page index of last successful search * @i_cno: checkpoint number for GC inode * @i_assoc_inode: associated inode (B-tree node cache holder or back pointer)
@@ -43,7 +42,6 @@ struct nilfs_inode_info {unsigned long i_state;/* Dynamic state flags */ struct nilfs_bmap *i_bmap;struct nilfs_bmap i_bmap_data; -__u64 i_xattr;/* sector_t ??? */ __u32 i_dir_start_lookup;__u64 i_cno;/* check point number for GC inode */ struct inode *i_assoc_inode;
@@ -234,12 +232,10 @@ static inline int nilfs_init_acl(struct inode *inode, struct inode *dir) }#endif -#define NILFS_ATIME_DISABLE -/* Flags that should be inherited by new inodes from their parent. */ #define NILFS_FL_INHERITED \ (FS_SECRM_FL | FS_UNRM_FL | FS_COMPR_FL | FS_SYNC_FL | \ - FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | FS_NOATIME_FL |\ + FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | \ FS_COMPRBLK_FL | FS_NOCOMP_FL | FS_NOTAIL_FL | FS_DIRSYNC_FL)/* Mask out flags that are inappropriate for the given type of inode. */
@@ -250,7 +246,7 @@ static inline __u32 nilfs_mask_flags(umode_t mode, __u32 flags)else if (S_ISREG (mode))return flags & ~(FS_DIRSYNC_FL |FS_TOPDIR_FL );else -return flags & (FS_NODUMP_FL |FS_NOATIME_FL ); +return flags &FS_NODUMP_FL ; }/* dir.c */
fs/nilfs2/segment.c +0 -2
@@ -930,8 +930,6 @@ static void nilfs_write_root_mdt_inode(struct inode *inode,nilfs_write_inode_common (inode, raw_inode);/* zero-fill unused portion of raw_inode */ - raw_inode->i_xattr =0 ; - raw_inode->i_pad =0 ;memset ((void *)raw_inode +sizeof (*raw_inode),0 , nilfs->ns_inode_size -sizeof (*raw_inode));
fs/nilfs2/super.c +0 -5
@@ -867,11 +867,6 @@ int nilfs_store_magic(struct super_block *sb, sb->s_magic =le16_to_cpu (sbp->s_magic); -/* FS independent flags */ -#ifdef NILFS_ATIME_DISABLE - sb->s_flags |=SB_NOATIME ; -#endif - nilfs->ns_resuid =le16_to_cpu (sbp->s_def_resuid); nilfs->ns_resgid =le16_to_cpu (sbp->s_def_resgid); nilfs->ns_interval =le32_to_cpu (sbp->s_c_interval);
include/uapi/linux/nilfs2_ondisk.h +4 -4
@@ -47,9 +47,9 @@* @i_links_count: links count * @i_flags: file flags * @i_bmap: block mapping -* @i_xattr: extended attributes +* @i_atime: access time (seconds) * @i_generation: file generation (for NFS) -* @i_pad: padding +* @i_atime_nsec: access time (nano seconds) */ struct nilfs_inode {__le64 i_blocks;
@@ -65,9 +65,9 @@ struct nilfs_inode {__le32 i_flags;__le64 i_bmap[NILFS_INODE_BMAP_SIZE ];#define i_device_code i_bmap[0] -__le64 i_xattr; +__le64 i_atime;__le32 i_generation; -__le32 i_pad; +__le32 i_atime_nsec; };#define NILFS_MIN_INODE_SIZE 128
Signature · 1 line
2.43.0
Ryusuke Konishi
maintainerHi Viacheslav,
Quoted 34 lines · Viacheslav Dubeyko
Currently, NILFS2 doesn't support atime. And it is possible to see the evidence of it by running generic/003 test-case of xfstests suite:
sudo ./check generic/003
FSTYP -- nilfs2
PLATFORM -- Linux/x86_64 hfsplus-testing-0001 6.18.0-rc1+ #10 SMPPREEMPT_DYNAMICFri Nov 28 20:48:25 PST 2025MKFS_OPTIONS--/dev/loop51MOUNT_OPTIONS--/dev/loop51/mnt/scratchgeneric/003 35s ... - output mismatch (see xfstests-dev/results//generic/003.out.bad)
This patch exchanges
i_xattroni_atimeandi_padoni_atime_nsecfields of structnilfs_inodein the on-disk layout, removes all declarations that disabled atime support. Also, it modifiesnilfs_read_inode_common(),nilfs_write_inode_common(), andnilfs_setattr()with the goal of proper atime support.sudo ./check generic/003
FSTYP -- nilfs2 PLATFORM -- Linux/x86_64 nilfs2-testing 6.19.0-rc1+ #8 SMP PREEMPT_DYNAMIC Tue Feb 17 16:21:59 PST 2026 MKFS_OPTIONS -- /dev/loop51
MOUNT_OPTIONS--/dev/loop51/mnt/scratchgeneric/003 30s ... 34s
Ran: generic/003
Passed all 1 tests[1] https://github.com/nilfs-dev/nilfs2/issues/7
Signed-off-by Viacheslav Dubeyko <[email protected]>
Quoted 8 lines
--- fs/nilfs2/Kconfig | 2 +- fs/nilfs2/inode.c | 18 ++++++++++++++---- fs/nilfs2/nilfs.h | 8 ++------ fs/nilfs2/segment.c | 2 -- fs/nilfs2/super.c | 5 ----- include/uapi/linux/nilfs2_ondisk.h | 8 ++++---- 6 files changed, 21 insertions(+), 22 deletions(-)
I'd like to comment on the proposed patch.
First, this patch abruptly switches the default behavior from noatime to atime. It also doesn't consider compatibility with older kernel implementations.
The lack of atime is not a bug but a specification constraint, so regardless of the performance impact of atime, this discontinuity should be avoided for filesystems.
Therefore, as a general request, I would like to ask that you create a new NILFS_FEATURE_COMPAT_RO_ATIME read-only compat flag for legacy implementations so that noatime behavior is maintained, and that atime support be enabled only when this flag is set.
(I would like to add the ro-compat flag for atime support to be set in mkfs.nilfs2 or nilfs-tune, with the goal of making it the default in the future.)
There is a place to define compat flags in nilfs2_ondisk.h, so please add it there.
It would be preferable to have a separate patch for NILFS_FEATURE_COMPAT_RO_ATIME so that the change can be applied to userland tools, but it is also fine to include it in one patch.
I'll add my comments inline below.
Quoted 19 lines
fs/nilfs2/Kconfig +1
-1@@ -20,7 +20,7 @@ config NILFS2_FS snapshot is mountable as a read-only file system concurrently with its writable mount, and this feature is convenient for online backup. - Some features including atime, extended attributes, and POSIX ACLs, + Some features including extended attributes, and POSIX ACLs, are not supported yet. To compile this file system support as a module, choose M here: thefs/nilfs2/inode.c +0
-0
fs/nilfs2/inode.c void nilfs_set_inode_flags(struct inode *inode) · line 401
Quoted 9 lines
fs/nilfs2/inode.c +2
-2@@ -395,8 +395,8 @@ void nilfs_set_inode_flags(struct inode *inode) new_fl |=S_NOATIME ;if (flags &FS_DIRSYNC_FL ) new_fl |=S_DIRSYNC ; -inode_set_flags (inode, new_fl,S_SYNC |S_APPEND |S_IMMUTABLE | -S_NOATIME |S_DIRSYNC ); +inode_set_flags (inode, new_fl, +S_SYNC |S_APPEND |S_IMMUTABLE |S_DIRSYNC ); }
This change is incorrect.
The third argument (mask) of inode_set_flags() is a bitmask to clear before conditionally setting inode flags.S_NOATIME should not be removed from this.
fs/nilfs2/inode.c int nilfs_read_inode_common(struct inode *inode, · line 414
Quoted 9 lines
fs/nilfs2/inode.c +2
-2int nilfs_read_inode_common(struct inode *inode,@@ -410,12 +410,13 @@ int nilfs_read_inode_common(struct inode *inode,i_gid_write (inode,le32_to_cpu (raw_inode->i_gid));set_nlink (inode,le16_to_cpu (raw_inode->i_links_count)); inode->i_size =le64_to_cpu (raw_inode->i_size); -inode_set_atime (inode,le64_to_cpu (raw_inode->i_mtime), -le32_to_cpu (raw_inode->i_mtime_nsec)); +inode_set_atime (inode,le64_to_cpu (raw_inode->i_atime), +le32_to_cpu (raw_inode->i_atime_nsec));
Instead of rewriting this, switch these depending on the state of the atime ro-compat flag mentioned first.
Quoted 9 lines
fs/nilfs2/inode.c +1
-0inode_set_ctime (inode,le64_to_cpu (raw_inode->i_ctime),le32_to_cpu (raw_inode->i_ctime_nsec));inode_set_mtime (inode,le64_to_cpu (raw_inode->i_mtime),le32_to_cpu (raw_inode->i_mtime_nsec)); +if (nilfs_is_metadata_file_inode (inode) && !S_ISREG (inode->i_mode))return -EIO ;/* this inode is for metadata and corrupted */ if (inode->i_nlink ==0 )
fs/nilfs2/inode.c void nilfs_write_inode_common(struct inode *inode, · line 733
Quoted 10 lines
fs/nilfs2/inode.c +2
-0@@ -723,8 +724,10 @@ void nilfs_write_inode_common(struct inode *inode, raw_inode->i_gid =cpu_to_le32 (i_gid_read (inode)); raw_inode->i_links_count =cpu_to_le16 (inode->i_nlink); raw_inode->i_size =cpu_to_le64 (inode->i_size); + raw_inode->i_atime =cpu_to_le64 (inode_get_atime_sec (inode)); raw_inode->i_ctime =cpu_to_le64 (inode_get_ctime_sec (inode)); raw_inode->i_mtime =cpu_to_le64 (inode_get_mtime_sec (inode)); + raw_inode->i_atime_nsec =cpu_to_le32 (inode_get_atime_nsec (inode)); raw_inode->i_ctime_nsec =cpu_to_le32 (inode_get_ctime_nsec (inode)); raw_inode->i_mtime_nsec =cpu_to_le32 (inode_get_mtime_nsec (inode)); raw_inode->i_blocks =cpu_to_le64 (inode->i_blocks);
This looks OK (doesn't break compatibility for older kernels) since the new fields are never used before.
fs/nilfs2/inode.c int nilfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, · line 943
Quoted 13 lines
fs/nilfs2/inode.c +7
-0@@ -929,6 +932,13 @@ int nilfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,nilfs_truncate (inode); } +if (iattr->ia_valid &ATTR_ATIME ) +inode_set_atime_to_ts (inode, iattr->ia_atime); +if (iattr->ia_valid &ATTR_MTIME ) +inode_set_mtime_to_ts (inode, iattr->ia_mtime); +if (iattr->ia_valid &ATTR_CTIME ) +inode_set_ctime_to_ts (inode, iattr->ia_ctime); +setattr_copy (&nop_mnt_idmap, inode, iattr);mark_inode_dirty (inode);
Why do you need to add this?
setattr_copy() performs a similar, conditional timestamp update process. Shouldn't we leave it to that behavior?
Quoted 23 lines
fs/nilfs2/nilfs.h +0
-2@@ -27,7 +27,6 @@* @i_state: dynamic state flags * @i_bmap: pointer on i_bmap_data * @i_bmap_data: raw block mapping -* @i_xattr: <TODO> * @i_dir_start_lookup: page index of last successful search * @i_cno: checkpoint number for GC inode * @i_assoc_inode: associated inode (B-tree node cache holder or back pointer) @@ -43,7 +42,6 @@ struct nilfs_inode_info {unsigned long i_state;/* Dynamic state flags */ struct nilfs_bmap *i_bmap;struct nilfs_bmap i_bmap_data; -__u64 i_xattr;/* sector_t ??? */ __u32 i_dir_start_lookup;__u64 i_cno;/* check point number for GC inode */ struct inode *i_assoc_inode;@@ -234,12 +232,10 @@ static inline int nilfs_init_acl(struct inode *inode, struct inode *dir) }
fs/nilfs2/nilfs.h static inline int nilfs_init_acl(struct inode *inode, struct inode *dir) · line 239
Quoted 10 lines
fs/nilfs2/nilfs.h +1
-3#endif -#define NILFS_ATIME_DISABLE -/* Flags that should be inherited by new inodes from their parent. */ #define NILFS_FL_INHERITED \ (FS_SECRM_FL | FS_UNRM_FL | FS_COMPR_FL | FS_SYNC_FL | \ - FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | FS_NOATIME_FL |\ + FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | \ FS_COMPRBLK_FL | FS_NOCOMP_FL | FS_NOTAIL_FL | FS_DIRSYNC_FL)
Do not remove this either.FS_NOATIME_FL (the flag set by chattr +A) is a flag independent of mount options and is intended to be disabled for specific files individually. In introducing atime, this flag should be kept, as inheritance is the standard behavior.
fs/nilfs2/nilfs.h static inline __u32 nilfs_mask_flags(umode_t mode, __u32 flags) · line 250
Quoted 9 lines
fs/nilfs2/nilfs.h +1
-1/* Mask out flags that are inappropriate for the given type of inode. */ @@ -250,7 +246,7 @@ static inline __u32 nilfs_mask_flags(umode_t mode, __u32 flags)else if (S_ISREG (mode))return flags & ~(FS_DIRSYNC_FL |FS_TOPDIR_FL );else -return flags & (FS_NODUMP_FL |FS_NOATIME_FL ); +return flags &FS_NODUMP_FL ; }
nilfs_mask_flags() is responsible for dropping inappropriate flags depending on the inode type.
It is standard practice to allow the FS_NOATIME_FL and FS_NODUMP_FL flags to avoid inode updates when accessing special files. Therefore, in the above case, do not remove FS_NOATIME_FL, but maintain it.
Quoted 20 lines
fs/nilfs2/nilfs.h +0
-0/* dir.c */ fs/nilfs2/segment.c +0
-2@@ -930,8 +930,6 @@ static void nilfs_write_root_mdt_inode(struct inode *inode,nilfs_write_inode_common (inode, raw_inode);/* zero-fill unused portion of raw_inode */ - raw_inode->i_xattr =0 ; - raw_inode->i_pad =0 ;memset ((void *)raw_inode +sizeof (*raw_inode),0 , nilfs->ns_inode_size -sizeof (*raw_inode));fs/nilfs2/super.c +0
-0
fs/nilfs2/super.c int nilfs_store_magic(struct super_block *sb, · line 874
Quoted 8 lines
fs/nilfs2/super.c +0
-5@@ -867,11 +867,6 @@ int nilfs_store_magic(struct super_block *sb, sb->s_magic =le16_to_cpu (sbp->s_magic); -/* FS independent flags */ -#ifdef NILFS_ATIME_DISABLE - sb->s_flags |=SB_NOATIME ; -#endif -
It is OK to remove the NILFS_ATIME_DISABLE macro. However, if the NILFS_FEATURE_COMPAT_RO_ATIME flag is not set in the superblock, please continue to set SB_NOATIME as before.
Regards,
Ryusuke Konishi
Quoted 34 lines
fs/nilfs2/super.c +0
-0nilfs->ns_resuid =le16_to_cpu (sbp->s_def_resuid); nilfs->ns_resgid =le16_to_cpu (sbp->s_def_resgid); nilfs->ns_interval =le32_to_cpu (sbp->s_c_interval);include/uapi/linux/nilfs2_ondisk.h +4
-5@@ -47,9 +47,9 @@* @i_links_count: links count * @i_flags: file flags * @i_bmap: block mapping -* @i_xattr: extended attributes +* @i_atime: access time (seconds) * @i_generation: file generation (for NFS) -* @i_pad: padding +* @i_atime_nsec: access time (nano seconds) */ struct nilfs_inode {__le64 i_blocks;@@ -65,9 +65,9 @@ struct nilfs_inode {__le32 i_flags;__le64 i_bmap[NILFS_INODE_BMAP_SIZE ];#define i_device_code i_bmap[0] -__le64 i_xattr; +__le64 i_atime;__le32 i_generation; -__le32 i_pad; +__le32 i_atime_nsec; };#define NILFS_MIN_INODE_SIZE 128 --2.43.0
Hi Ryusuke,
Quoted 63 lines · Ryusuke Konishi
Hi Viacheslav,
Quoted 34 lines · Viacheslav Dubeyko
Currently, NILFS2 doesn't support atime. And it is possible to see the evidence of it by running generic/003 test-case of xfstests suite:
sudo ./check generic/003
FSTYP -- nilfs2
PLATFORM -- Linux/x86_64 hfsplus-testing-0001 6.18.0-rc1+ #10 SMPPREEMPT_DYNAMICFri Nov 28 20:48:25 PST 2025MKFS_OPTIONS--/dev/loop51MOUNT_OPTIONS--/dev/loop51/mnt/scratchgeneric/003 35s ... - output mismatch (see xfstests-dev/results//generic/003.out.bad)
This patch exchanges
i_xattroni_atimeandi_padoni_atime_nsecfields of structnilfs_inodein the on-disk layout, removes all declarations that disabled atime support. Also, it modifiesnilfs_read_inode_common(),nilfs_write_inode_common(), andnilfs_setattr()with the goal of proper atime support.sudo ./check generic/003
FSTYP -- nilfs2 PLATFORM -- Linux/x86_64 nilfs2-testing 6.19.0-rc1+ #8 SMP PREEMPT_DYNAMIC Tue Feb 17 16:21:59 PST 2026 MKFS_OPTIONS -- /dev/loop51
MOUNT_OPTIONS--/dev/loop51/mnt/scratchgeneric/003 30s ... 34s
Ran: generic/003
Passed all 1 testsSigned-off-by Viacheslav Dubeyko <[email protected]>Quoted 8 lines
--- fs/nilfs2/Kconfig | 2 +- fs/nilfs2/inode.c | 18 ++++++++++++++---- fs/nilfs2/nilfs.h | 8 ++------ fs/nilfs2/segment.c | 2 -- fs/nilfs2/super.c | 5 ----- include/uapi/linux/nilfs2_ondisk.h | 8 ++++---- 6 files changed, 21 insertions(+), 22 deletions(-)I'd like to comment on the proposed patch.
First, this patch abruptly switches the default behavior from noatime to atime. It also doesn't consider compatibility with older kernel implementations.The lack of atime is not a bug but a specification constraint, so regardless of the performance impact of atime, this discontinuity should be avoided for filesystems.
Therefore, as a general request, I would like to ask that you create a new
NILFS_FEATURE_COMPAT_RO_ATIMEread-only compat flag for legacy implementations so that noatime behavior is maintained, and that atime support be enabled only when this flag is set.
(I would like to add the ro-compat flag for atime support to be set in mkfs.nilfs2 or nilfs-tune, with the goal of making it the default in the future.)
Quoted 6 lines
There is a place to define compat flags in
nilfs2_ondisk.h, so please add it there.
It would be preferable to have a separate patch forNILFS_FEATURE_COMPAT_RO_ATIMEso that the change can be applied to userland tools, but it is also fine to include it in one patch.
Makes sense to me.
Quoted 27 lines
I'll add my comments inline below.
Quoted 25 lines
fs/nilfs2/Kconfig +1
-1@@ -20,7 +20,7 @@ config NILFS2_FS snapshot is mountable as a read-only file system concurrently with its writable mount, and this feature is convenient for online backup. - Some features including atime, extended attributes, and POSIX ACLs, + Some features including extended attributes, and POSIX ACLs, are not supported yet. To compile this file system support as a module, choose M here: thefs/nilfs2/inode.c +1
-2@@ -395,8 +395,8 @@ void nilfs_set_inode_flags(struct inode *inode) new_fl |=S_NOATIME ;if (flags &FS_DIRSYNC_FL ) new_fl |=S_DIRSYNC ; -inode_set_flags (inode, new_fl,S_SYNC |S_APPEND |S_IMMUTABLE | -S_NOATIME |S_DIRSYNC ); + inode_set_flags(inode, new_fl,
Quoted 9 lines
fs/nilfs2/inode.c void nilfs_set_inode_flags(struct inode *inode) · line 401
Quoted 3 lines
fs/nilfs2/inode.c +1
-0+ S_SYNC | S_APPEND | S_IMMUTABLE | S_DIRSYNC); }This change is incorrect.
The third argument (mask) ofinode_set_flags()is a bitmask to clear before conditionally setting inode flags.S_NOATIMEshould not be removed from this.
OK. Sounds good.
Quoted 4 lines
Quoted 4 lines
fs/nilfs2/inode.c +0
-0int nilfs_read_inode_common(struct inode *inode,@@ -410,12 +410,13 @@ int nilfs_read_inode_common(struct inode *inode,i_gid_write (inode,le32_to_cpu (raw_inode->i_gid));set_nlink (inode,le16_to_cpu (raw_inode->i_links_count));
Quoted 8 lines
fs/nilfs2/inode.c int nilfs_read_inode_common(struct inode *inode, · line 414
Quoted 5 lines
fs/nilfs2/inode.c +2
-2inode->i_size =le64_to_cpu (raw_inode->i_size); -inode_set_atime (inode,le64_to_cpu (raw_inode->i_mtime), -le32_to_cpu (raw_inode->i_mtime_nsec)); +inode_set_atime (inode,le64_to_cpu (raw_inode->i_atime), +le32_to_cpu (raw_inode->i_atime_nsec));Instead of rewriting this, switch these depending on the state of the atime ro-compat flag mentioned first.
OK.
Quoted 40 lines
Quoted 10 lines
fs/nilfs2/inode.c +1
-0inode_set_ctime (inode,le64_to_cpu (raw_inode->i_ctime),le32_to_cpu (raw_inode->i_ctime_nsec));inode_set_mtime (inode,le64_to_cpu (raw_inode->i_mtime),le32_to_cpu (raw_inode->i_mtime_nsec)); +if (nilfs_is_metadata_file_inode (inode) && !S_ISREG (inode->i_mode))return -EIO ;/* this inode is for metadata and corrupted */ if (inode->i_nlink ==0 )fs/nilfs2/inode.c void nilfs_write_inode_common(struct inode *inode, · line 733
Quoted 10 lines
fs/nilfs2/inode.c +2
-0@@ -723,8 +724,10 @@ void nilfs_write_inode_common(struct inode *inode, raw_inode->i_gid =cpu_to_le32 (i_gid_read (inode)); raw_inode->i_links_count =cpu_to_le16 (inode->i_nlink); raw_inode->i_size =cpu_to_le64 (inode->i_size); + raw_inode->i_atime =cpu_to_le64 (inode_get_atime_sec (inode)); raw_inode->i_ctime =cpu_to_le64 (inode_get_ctime_sec (inode)); raw_inode->i_mtime =cpu_to_le64 (inode_get_mtime_sec (inode)); + raw_inode->i_atime_nsec =cpu_to_le32 (inode_get_atime_nsec (inode)); raw_inode->i_ctime_nsec =cpu_to_le32 (inode_get_ctime_nsec (inode)); raw_inode->i_mtime_nsec =cpu_to_le32 (inode_get_mtime_nsec (inode)); raw_inode->i_blocks =cpu_to_le64 (inode->i_blocks);This looks OK (doesn't break compatibility for older kernels) since the new fields are never used before.
fs/nilfs2/inode.c int nilfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, · line 943
Quoted 13 lines
fs/nilfs2/inode.c +7
-0@@ -929,6 +932,13 @@ int nilfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,nilfs_truncate (inode); } +if (iattr->ia_valid &ATTR_ATIME ) +inode_set_atime_to_ts (inode, iattr->ia_atime); +if (iattr->ia_valid &ATTR_MTIME ) +inode_set_mtime_to_ts (inode, iattr->ia_mtime); +if (iattr->ia_valid &ATTR_CTIME ) +inode_set_ctime_to_ts (inode, iattr->ia_ctime); +setattr_copy (&nop_mnt_idmap, inode, iattr);mark_inode_dirty (inode);Why do you need to add this?
Quoted 3 lines
setattr_copy()performs a similar, conditional timestamp update process. Shouldn't we leave it to that behavior?
I think you are right here. It is artifact of my debugging efforts.
Quoted 25 lines
Quoted 25 lines
fs/nilfs2/nilfs.h +0
-2@@ -27,7 +27,6 @@* @i_state: dynamic state flags * @i_bmap: pointer on i_bmap_data * @i_bmap_data: raw block mapping -* @i_xattr: <TODO> * @i_dir_start_lookup: page index of last successful search * @i_cno: checkpoint number for GC inode * @i_assoc_inode: associated inode (B-tree node cache holder or back pointer) @@ -43,7 +42,6 @@ struct nilfs_inode_info {unsigned long i_state;/* Dynamic state flags */ struct nilfs_bmap *i_bmap;struct nilfs_bmap i_bmap_data; -__u64 i_xattr;/* sector_t ??? */ __u32 i_dir_start_lookup;__u64 i_cno;/* check point number for GC inode */ struct inode *i_assoc_inode;@@ -234,12 +232,10 @@ static inline int nilfs_init_acl(struct inode *inode, struct inode *dir) }#endif
Quoted 15 lines
fs/nilfs2/nilfs.h static inline int nilfs_init_acl(struct inode *inode, struct inode *dir) · line 239
Quoted 8 lines
fs/nilfs2/nilfs.h +1
-3-#define NILFS_ATIME_DISABLE -/* Flags that should be inherited by new inodes from their parent. */ #define NILFS_FL_INHERITED \ (FS_SECRM_FL | FS_UNRM_FL | FS_COMPR_FL | FS_SYNC_FL | \ - FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | FS_NOATIME_FL |\ + FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | \ FS_COMPRBLK_FL | FS_NOCOMP_FL | FS_NOTAIL_FL | FS_DIRSYNC_FL)Do not remove this either.
FS_NOATIME_FL(the flag set by chattr +A) is a flag independent of mount options and is intended to be disabled for specific files individually. In introducing atime, this flag should be kept, as inheritance is the standard behavior.
OK.
Quoted 16 lines
fs/nilfs2/nilfs.h static inline __u32 nilfs_mask_flags(umode_t mode, __u32 flags) · line 250
Quoted 9 lines
fs/nilfs2/nilfs.h +1
-1/* Mask out flags that are inappropriate for the given type of inode. */ @@ -250,7 +246,7 @@ static inline __u32 nilfs_mask_flags(umode_t mode, __u32 flags)else if (S_ISREG (mode))return flags & ~(FS_DIRSYNC_FL |FS_TOPDIR_FL );else -return flags & (FS_NODUMP_FL |FS_NOATIME_FL ); +return flags &FS_NODUMP_FL ; }
nilfs_mask_flags()is responsible for dropping inappropriate flags depending on the inode type.
It is standard practice to allow theFS_NOATIME_FLandFS_NODUMP_FLflags to avoid inode updates when accessing special files. Therefore, in the above case, do not removeFS_NOATIME_FL, but maintain it.
Sounds good.
Quoted 23 lines
Quoted 23 lines
fs/nilfs2/nilfs.h +0
-0/* dir.c */ fs/nilfs2/segment.c +0
-2@@ -930,8 +930,6 @@ static void nilfs_write_root_mdt_inode(struct inode *inode,nilfs_write_inode_common (inode, raw_inode);/* zero-fill unused portion of raw_inode */ - raw_inode->i_xattr =0 ; - raw_inode->i_pad =0 ;memset ((void *)raw_inode +sizeof (*raw_inode),0 , nilfs->ns_inode_size -sizeof (*raw_inode));fs/nilfs2/super.c +0
-0@@ -867,11 +867,6 @@ int nilfs_store_magic(struct super_block *sb, sb->s_magic =le16_to_cpu (sbp->s_magic);
Quoted 10 lines
fs/nilfs2/super.c int nilfs_store_magic(struct super_block *sb, · line 874
Quoted 5 lines
fs/nilfs2/super.c +0
-5-/* FS independent flags */ -#ifdef NILFS_ATIME_DISABLE - sb->s_flags |=SB_NOATIME ; -#endif -It is OK to remove the
NILFS_ATIME_DISABLEmacro. However, if theNILFS_FEATURE_COMPAT_RO_ATIMEflag is not set in the superblock, please continue to setSB_NOATIMEas before.
All remarks make sense to me. Let me rework the patch and implement your suggestions.
Thanks,
Slava.
Quoted 37 lines
Regards,
Ryusuke KonishiQuoted 34 lines
fs/nilfs2/super.c +0
-0nilfs->ns_resuid =le16_to_cpu (sbp->s_def_resuid); nilfs->ns_resgid =le16_to_cpu (sbp->s_def_resgid); nilfs->ns_interval =le32_to_cpu (sbp->s_c_interval);include/uapi/linux/nilfs2_ondisk.h +4
-5@@ -47,9 +47,9 @@* @i_links_count: links count * @i_flags: file flags * @i_bmap: block mapping -* @i_xattr: extended attributes +* @i_atime: access time (seconds) * @i_generation: file generation (for NFS) -* @i_pad: padding +* @i_atime_nsec: access time (nano seconds) */ struct nilfs_inode {__le64 i_blocks;@@ -65,9 +65,9 @@ struct nilfs_inode {__le32 i_flags;__le64 i_bmap[NILFS_INODE_BMAP_SIZE ];#define i_device_code i_bmap[0] -__le64 i_xattr; +__le64 i_atime;__le32 i_generation; -__le32 i_pad; +__le32 i_atime_nsec; };#define NILFS_MIN_INODE_SIZE 128 --2.43.0