]> git.ipfire.org Git - thirdparty/linux.git/commit
btrfs: add and use helpers for reading and writing last_trans_committed
authorFilipe Manana <fdmanana@suse.com>
Wed, 4 Oct 2023 10:38:51 +0000 (11:38 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 12 Oct 2023 14:44:17 +0000 (16:44 +0200)
commit0124855ff18b9bdfe6aec87f7b29d3fdc6f575db
tree9efcc94b959df93a18e6fecc165546b1f99f3fad
parent4a4f8fe2b0230c22aba40c9f8ea7b9c6fcfc8417
btrfs: add and use helpers for reading and writing last_trans_committed

Currently the last_trans_committed field of struct btrfs_fs_info is
modified and read without any locking or other protection. For example
early in the fsync path, skip_inode_logging() is called which reads
fs_info->last_trans_committed, but at the same time we can have a
transaction commit completing and updating that field.

In the case of an fsync this is harmless and any data race should be
rare and at most cause an unnecessary logging of an inode.

To avoid data race warnings from tools like KCSAN and other issues such
as load and store tearing (amongst others, see [1]), create helpers to
access the last_trans_committed field of struct btrfs_fs_info using
READ_ONCE() and WRITE_ONCE(), and use these helpers everywhere.

[1] https://lwn.net/Articles/793253/

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/disk-io.c
fs/btrfs/file.c
fs/btrfs/fs.h
fs/btrfs/ioctl.c
fs/btrfs/scrub.c
fs/btrfs/super.c
fs/btrfs/transaction.c
fs/btrfs/tree-checker.c