linux_dsm_epyc7002/fs/btrfs
Filipe Manana 4b5ca02bea btrfs: fix lost inode on log replay after mix of fsync, rename and inode eviction
[ Upstream commit ecc64fab7d49c678e70bd4c35fe64d2ab3e3d212 ]

When checking if we need to log the new name of a renamed inode, we are
checking if the inode and its parent inode have been logged before, and if
not we don't log the new name. The check however is buggy, as it directly
compares the logged_trans field of the inodes versus the ID of the current
transaction. The problem is that logged_trans is a transient field, only
stored in memory and never persisted in the inode item, so if an inode
was logged before, evicted and reloaded, its logged_trans field is set to
a value of 0, meaning the check will return false and the new name of the
renamed inode is not logged. If the old parent directory was previously
fsynced and we deleted the logged directory entries corresponding to the
old name, we end up with a log that when replayed will delete the renamed
inode.

The following example triggers the problem:

  $ mkfs.btrfs -f /dev/sdc
  $ mount /dev/sdc /mnt

  $ mkdir /mnt/A
  $ mkdir /mnt/B
  $ echo -n "hello world" > /mnt/A/foo

  $ sync

  # Add some new file to A and fsync directory A.
  $ touch /mnt/A/bar
  $ xfs_io -c "fsync" /mnt/A

  # Now trigger inode eviction. We are only interested in triggering
  # eviction for the inode of directory A.
  $ echo 2 > /proc/sys/vm/drop_caches

  # Move foo from directory A to directory B.
  # This deletes the directory entries for foo in A from the log, and
  # does not add the new name for foo in directory B to the log, because
  # logged_trans of A is 0, which is less than the current transaction ID.
  $ mv /mnt/A/foo /mnt/B/foo

  # Now make an fsync to anything except A, B or any file inside them,
  # like for example create a file at the root directory and fsync this
  # new file. This syncs the log that contains all the changes done by
  # previous rename operation.
  $ touch /mnt/baz
  $ xfs_io -c "fsync" /mnt/baz

  <power fail>

  # Mount the filesystem and replay the log.
  $ mount /dev/sdc /mnt

  # Check the filesystem content.
  $ ls -1R /mnt
  /mnt/:
  A
  B
  baz

  /mnt/A:
  bar

  /mnt/B:
  $

  # File foo is gone, it's neither in A/ nor in B/.

Fix this by using the inode_logged() helper at btrfs_log_new_name(), which
safely checks if an inode was logged before in the current transaction.

A test case for fstests will follow soon.

CC: stable@vger.kernel.org # 4.14+
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-07-05 18:07:24 +02:00
..
tests init: add dsm gpl source 2024-07-05 18:00:04 +02:00
acl.c btrfs: cleanup btrfs_setxattr_trans and drop transaction parameter 2019-04-29 19:02:44 +02:00
async-thread.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
async-thread.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
backref.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
backref.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
block-group.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
block-group.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
block-rsv.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
block-rsv.h btrfs: Remove __ prefix from btrfs_block_rsv_release 2020-03-23 17:01:55 +01:00
btrfs_inode.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
check-integrity.c btrfs: check-integrity: remove unnecessary failure messages during memory allocation 2020-07-27 12:55:21 +02:00
check-integrity.h btrfs: remove btrfsic_submit_bh() 2020-03-23 17:01:39 +01:00
compression.c btrfs: mark compressed range uptodate only if all bio succeed 2024-07-05 18:02:46 +02:00
compression.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
ctree.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
ctree.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
delalloc-space.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
delalloc-space.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
delayed-inode.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
delayed-inode.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
delayed-ref.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
delayed-ref.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
dev-replace.c btrfs: fix deadlock when cloning inline extent and low on free metadata space 2021-01-17 14:16:54 +01:00
dev-replace.h btrfs: add __pure attribute to functions 2019-11-18 12:46:52 +01:00
dir-item.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
discard.c btrfs: merge critical sections of discard lock in workfn 2021-01-19 18:27:24 +01:00
discard.h btrfs: discard: Use the correct style for SPDX License Identifier 2020-04-20 17:43:42 +02:00
disk-io.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
disk-io.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
export.c btrfs: simplify iget helpers 2020-05-25 11:25:37 +02:00
export.h btrfs: export helpers for subvolume name/id resolution 2020-03-23 17:01:42 +01:00
extent_io.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
extent_io.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
extent_map.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
extent_map.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
extent-io-tree.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
extent-tree.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
file-item.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
file.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
free-space-analyze.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
free-space-cache.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
free-space-cache.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
free-space-tree.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
free-space-tree.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
inode-item.c btrfs: Make btrfs_find_name_in_ext_backref return struct btrfs_inode_extref 2019-09-09 14:59:16 +02:00
inode-map.c btrfs: make btrfs_delalloc_reserve_space take btrfs_inode 2020-07-27 12:55:36 +02:00
inode-map.h btrfs: replace GPL boilerplate by SPDX -- headers 2018-04-12 16:29:46 +02:00
inode.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
ioctl.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
Kconfig btrfs: disable build on platforms having page size 256K 2021-07-14 16:55:56 +02:00
locking.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
locking.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
lzo.c btrfs: compression: inline free_workspace 2019-11-18 12:46:59 +01:00
Makefile init: add dsm gpl source 2024-07-05 18:00:04 +02:00
misc.h btrfs: rename tree_entry to rb_simple_node and export it 2020-05-25 11:25:19 +02:00
ordered-data.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
ordered-data.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
orphan.c btrfs: replace GPL boilerplate by SPDX -- sources 2018-04-12 16:29:51 +02:00
print-tree.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
print-tree.h btrfs: print the actual offset in btrfs_root_name 2021-01-27 11:55:06 +01:00
props.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
props.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
qgroup.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
qgroup.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
raid56.c btrfs: fix raid6 qstripe kmap 2021-03-09 11:11:10 +01:00
raid56.h btrfs: constify map parameter for nr_parity_stripes and nr_data_stripes 2019-07-01 13:34:58 +02:00
rcu-string.h btrfs: rcu-string: Replace zero-length array with flexible-array member 2020-03-23 17:01:53 +01:00
reada.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
ref-verify.c btrfs: ref-verify: fix memory leak in btrfs_ref_tree_mod 2020-11-05 13:03:39 +01:00
ref-verify.h btrfs: ref-verify: Use btrfs_ref to refactor btrfs_ref_tree_mod() 2019-04-29 19:02:49 +02:00
reflink.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
reflink.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
relocation.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
root-tree.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
scrub.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
send.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
send.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
snapshot-size-query.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
space-info.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
space-info.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
struct-funcs.c btrfs: use unaligned helpers for stack and header set/get helpers 2020-10-07 12:13:23 +02:00
super.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
syno_acl.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
syno_acl.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
syno-extent-usage.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
syno-feat-tree.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
syno-feat-tree.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
syno-locker.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
syno-rbd-meta.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
syno-rbd-meta.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
sysfs.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
sysfs.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
transaction.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
transaction.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
tree-checker.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
tree-checker.h btrfs: get fs_info from eb in btrfs_check_chunk_valid 2019-04-29 19:02:39 +02:00
tree-defrag.c btrfs: remove unused btrfs_root::defrag_trans_start 2020-07-27 12:55:28 +02:00
tree-log.c btrfs: fix lost inode on log replay after mix of fsync, rename and inode eviction 2024-07-05 18:07:24 +02:00
tree-log.h btrfs: make fast fsyncs wait only for writeback 2020-10-07 12:06:56 +02:00
ulist.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
ulist.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
usrquota.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
uuid-tree.c btrfs: simplify root lookup by id 2020-05-25 11:25:36 +02:00
volumes.c btrfs: fix rw device counting in __btrfs_free_extra_devids 2024-07-05 18:02:41 +02:00
volumes.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
xattr.c init: add dsm gpl source 2024-07-05 18:00:04 +02:00
xattr.h init: add dsm gpl source 2024-07-05 18:00:04 +02:00
zlib.c btrfs: use larger zlib buffer for s390 hardware compression 2020-01-31 10:30:40 -08:00
zstd.c btrfs: compression: inline free_workspace 2019-11-18 12:46:59 +01:00