• Filipe Manana's avatar
    btrfs: add and use helpers for reading and writing last_log_commit · f9850787
    Filipe Manana authored
    Currently, the last_log_commit of a root can be accessed concurrently
    without any lock protection. Readers can be calling btrfs_inode_in_log()
    early in a fsync call, which reads a root's last_log_commit, while a
    writer can change the last_log_commit while a log tree if being synced,
    at btrfs_sync_log(). Any races here should be harmless, and in the worst
    case they may cause a fsync to log an inode when it's not really needed,
    so nothing bad from a functional perspective.
    
    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_log_commit field of a root using READ_ONCE() and
    WRITE_ONCE(), and use these helpers everywhere.
    
    [1] https://lwn.net/Articles/793253/Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
    Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    f9850787
ctree.h 22.6 KB