• Filipe Manana's avatar
    btrfs: add and use helpers for reading and writing log_transid · 6008859b
    Filipe Manana authored
    Currently the log_transid field of a root is always modified while holding
    the root's log_mutex locked. Most readers of a root's log_transid are also
    holding the root's log_mutex locked, however there is one exception which
    is btrfs_set_inode_last_trans() where we don't take the lock to avoid
    blocking several operations if log syncing is happening in parallel.
    
    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 log_transid field of a root using READ_ONCE() and WRITE_ONCE(),
    and use these helpers where needed.
    
    [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>
    6008859b
tree-log.c 210 KB