linux-yocto/fs/btrfs
Qu Wenruo 1355258be5 btrfs: populate otime when logging an inode item
[ Upstream commit 1ef94169db ]

[TEST FAILURE WITH EXPERIMENTAL FEATURES]
When running test case generic/508, the test case will fail with the new
btrfs shutdown support:

generic/508       - output mismatch (see /home/adam/xfstests/results//generic/508.out.bad)
#    --- tests/generic/508.out	2022-05-11 11:25:30.806666664 +0930
#    +++ /home/adam/xfstests/results//generic/508.out.bad	2025-07-02 14:53:22.401824212 +0930
#    @@ -1,2 +1,6 @@
#     QA output created by 508
#     Silence is golden
#    +Before:
#    +After : stat.btime = Thu Jan  1 09:30:00 1970
#    +Before:
#    +After : stat.btime = Wed Jul  2 14:53:22 2025
#    ...
#    (Run 'diff -u /home/adam/xfstests/tests/generic/508.out /home/adam/xfstests/results//generic/508.out.bad'  to see the entire diff)
Ran: generic/508
Failures: generic/508
Failed 1 of 1 tests

Please note that the test case requires shutdown support, thus the test
case will be skipped using the current upstream kernel, as it doesn't
have shutdown ioctl support.

[CAUSE]
The direct cause the 0 time stamp in the log tree:

leaf 30507008 items 2 free space 16057 generation 9 owner TREE_LOG
leaf 30507008 flags 0x1(WRITTEN) backref revision 1
checksum stored e522548d
checksum calced e522548d
fs uuid 57d45451-481e-43e4-aa93-289ad707a3a0
chunk uuid d52bd3fd-5163-4337-98a7-7986993ad398
	item 0 key (257 INODE_ITEM 0) itemoff 16123 itemsize 160
		generation 9 transid 9 size 0 nbytes 0
		block group 0 mode 100644 links 1 uid 0 gid 0 rdev 0
		sequence 1 flags 0x0(none)
		atime 1751432947.492000000 (2025-07-02 14:39:07)
		ctime 1751432947.492000000 (2025-07-02 14:39:07)
		mtime 1751432947.492000000 (2025-07-02 14:39:07)
		otime 0.0 (1970-01-01 09:30:00) <<<

But the old fs tree has all the correct time stamp:

btrfs-progs v6.12
fs tree key (FS_TREE ROOT_ITEM 0)
leaf 30425088 items 2 free space 16061 generation 5 owner FS_TREE
leaf 30425088 flags 0x1(WRITTEN) backref revision 1
checksum stored 48f6c57e
checksum calced 48f6c57e
fs uuid 57d45451-481e-43e4-aa93-289ad707a3a0
chunk uuid d52bd3fd-5163-4337-98a7-7986993ad398
	item 0 key (256 INODE_ITEM 0) itemoff 16123 itemsize 160
		generation 3 transid 0 size 0 nbytes 16384
		block group 0 mode 40755 links 1 uid 0 gid 0 rdev 0
		sequence 0 flags 0x0(none)
		atime 1751432947.0 (2025-07-02 14:39:07)
		ctime 1751432947.0 (2025-07-02 14:39:07)
		mtime 1751432947.0 (2025-07-02 14:39:07)
		otime 1751432947.0 (2025-07-02 14:39:07) <<<

The root cause is that fill_inode_item() in tree-log.c is only
populating a/c/m time, not the otime (or btime in statx output).

Part of the reason is that, the vfs inode only has a/c/m time, no native
btime support yet.

[FIX]
Thankfully btrfs has its otime stored in btrfs_inode::i_otime_sec and
btrfs_inode::i_otime_nsec.

So what we really need is just fill the otime time stamp in
fill_inode_item() of tree-log.c

There is another fill_inode_item() in inode.c, which is doing the proper
otime population.

Fixes: 94edf4ae43 ("Btrfs: don't bother committing delayed inode updates when fsyncing")
CC: stable@vger.kernel.org
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
[ Adapted token-based API calls ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-08-28 16:22:56 +02:00
..
tests btrfs: remove pointless and double ulist frees in error paths of qgroup tests 2022-11-25 17:45:40 +01:00
acl.c
async-thread.c
async-thread.h
backref.c btrfs: locking: remove all the blocking helpers 2025-01-09 13:25:04 +01:00
backref.h btrfs: sink iterator parameter to btrfs_ioctl_logical_to_ino 2022-12-08 11:23:53 +01:00
block-group.c btrfs: add handling for RAID1C23/DUP to btrfs_reduce_alloc_profile 2023-07-27 08:44:14 +02:00
block-group.h
block-rsv.c btrfs: don't free qgroup space unless specified 2023-05-17 11:48:13 +02:00
block-rsv.h
btrfs_inode.h
check-integrity.c
check-integrity.h
compression.c
compression.h
ctree.c btrfs: fix use-after-free when COWing tree bock and tracing is enabled 2025-01-09 13:25:04 +01:00
ctree.h btrfs: fix deadlock when cloning inline extents and using qgroups 2025-08-28 16:22:54 +02:00
delalloc-space.c btrfs: don't arbitrarily slow down delalloc if we're committing 2023-11-28 16:54:57 +00:00
delalloc-space.h
delayed-inode.c btrfs: locking: remove all the blocking helpers 2025-01-09 13:25:04 +01:00
delayed-inode.h
delayed-ref.c btrfs: reinitialize delayed ref list after deleting it from the list 2024-11-17 14:59:37 +01:00
delayed-ref.h
dev-replace.c btrfs: dev-replace: properly validate device names 2024-03-06 14:37:49 +00:00
dev-replace.h
dir-item.c btrfs: unify lookup return value when dir entry is missing 2024-03-01 13:16:47 +01:00
discard.c
discard.h
disk-io.c btrfs: flush delalloc workers queue before stopping cleaner kthread during unmount 2025-01-09 13:25:05 +01:00
disk-io.h btrfs: move btrfs_find_highest_objectid/btrfs_find_free_objectid to disk-io.c 2023-05-30 12:57:51 +01:00
export.c btrfs: export: handle invalid inode or root reference in btrfs_get_parent() 2024-04-13 12:59:43 +02:00
export.h btrfs: fix type of parameter generation in btrfs_get_dentry 2022-11-10 18:14:25 +01:00
extent_io.c btrfs: avoid linker error in btrfs_find_create_tree_block() 2025-06-04 14:37:00 +02:00
extent_io.h btrfs: switch extent buffer tree lock to rw_semaphore 2025-01-09 13:25:04 +01:00
extent_map.c
extent_map.h
extent-io-tree.h
extent-tree.c btrfs: don't BUG_ON() when 0 reference count at btrfs_lookup_extent_info() 2025-06-04 14:36:58 +02:00
file-item.c btrfs: handle memory allocation failure in btrfs_csum_one_bio 2023-06-21 15:45:36 +02:00
file.c btrfs: locking: remove all the blocking helpers 2025-01-09 13:25:04 +01:00
free-space-cache.c btrfs: rename bitmap_set_bits() -> btrfs_bitmap_set_bits() 2024-09-04 13:17:31 +02:00
free-space-cache.h
free-space-tree.c
free-space-tree.h
inode-item.c
inode-map.c btrfs: move btrfs_find_highest_objectid/btrfs_find_free_objectid to disk-io.c 2023-05-30 12:57:51 +01:00
inode-map.h btrfs: move btrfs_find_highest_objectid/btrfs_find_free_objectid to disk-io.c 2023-05-30 12:57:51 +01:00
inode.c btrfs: fix deadlock when cloning inline extents and using qgroups 2025-08-28 16:22:54 +02:00
ioctl.c btrfs: fix deadlock when cloning inline extents and using qgroups 2025-08-28 16:22:54 +02:00
Kconfig
locking.c btrfs: bring back the incorrectly removed extent buffer lock recursion support 2025-03-13 12:47:44 +01:00
locking.h btrfs: locking: remove all the blocking helpers 2025-01-09 13:25:04 +01:00
lzo.c
Makefile
misc.h
ordered-data.c
ordered-data.h
orphan.c
print-tree.c btrfs: switch extent buffer tree lock to rw_semaphore 2025-01-09 13:25:04 +01:00
print-tree.h
props.c
props.h
qgroup.c btrfs: fix deadlock when cloning inline extents and using qgroups 2025-08-28 16:22:54 +02:00
qgroup.h
raid56.c btrfs: raid56: don't trust any cached sector in __raid56_parity_recover() 2022-08-21 15:16:27 +02:00
raid56.h
rcu-string.h btrfs: replace strncpy() with strscpy() 2023-01-14 10:16:40 +01:00
reada.c
ref-verify.c btrfs: locking: remove all the blocking helpers 2025-01-09 13:25:04 +01:00
ref-verify.h
reflink.c btrfs: fix unexpected error path when reflinking an inline extent 2022-04-08 14:40:04 +02:00
reflink.h
relocation.c btrfs: convert BUG_ON in btrfs_reloc_cow_block() to proper error handling 2025-03-13 12:47:00 +01:00
root-tree.c btrfs: fix silent failure when deleting root reference 2022-08-31 17:15:21 +02:00
scrub.c btrfs: scrub: try harder to mark RAID56 block groups read-only 2023-06-21 15:45:36 +02:00
send.c btrfs: fix deadlock when cloning inline extents and using qgroups 2025-08-28 16:22:54 +02:00
send.h
space-info.c
space-info.h
struct-funcs.c
super.c btrfs: correctly escape subvol in btrfs_show_options() 2025-05-02 07:41:01 +02:00
sysfs.c btrfs: sysfs: normalize the error handling branch in btrfs_init_sysfs() 2022-12-02 17:40:06 +01:00
sysfs.h
transaction.c btrfs: fix deadlock when cloning inline extents and using qgroups 2025-08-28 16:22:54 +02:00
transaction.h btrfs: fix use-after-free after failure to create a snapshot 2024-09-12 11:06:44 +02:00
tree-checker.c btrfs: tree-checker: reject inline extent items with 0 ref count 2025-01-09 13:24:54 +01:00
tree-checker.h
tree-defrag.c btrfs: locking: remove all the blocking helpers 2025-01-09 13:25:04 +01:00
tree-log.c btrfs: populate otime when logging an inode item 2025-08-28 16:22:56 +02:00
tree-log.h
ulist.c
ulist.h
uuid-tree.c
volumes.c btrfs: update superblock's device bytes_used when dropping chunk 2025-07-17 18:27:42 +02:00
volumes.h btrfs: add a helper to read the superblock metadata_uuid 2023-09-23 11:01:09 +02:00
xattr.c btrfs: check if root is readonly while setting security xattr 2022-08-31 17:15:22 +02:00
xattr.h
zlib.c btrfs: zlib: zero-initialize zlib workspace 2023-02-15 17:22:22 +01:00
zstd.c