Skip to content
  • Filipe Manana's avatar
    Btrfs: race free update of commit root for ro snapshots · 9c3b306e
    Filipe Manana authored
    This is a better solution for the problem addressed in the following
    commit:
    
        Btrfs: update commit root on snapshot creation after orphan cleanup
        (3821f348
    
    )
    
    The previous solution wasn't the best because of 2 reasons:
    
        1) It added another full transaction commit, which is more expensive
           than just swapping the commit root with the root;
    
        2) If a reboot happened after the first transaction commit (the one
           that creates the snapshot) and before the second transaction commit,
           then we would end up with the same problem if a send using that
           snapshot was requested before the first transaction commit after
           the reboot.
    
    This change addresses those 2 issues. The second issue is addressed by
    switching the commit root in the dentry lookup VFS callback, which is
    also called by the snapshot/subvol creation ioctl and performs orphan
    cleanup if needed. Like the vfs, the ioctl locks the parent inode too,
    preventing race issues between a dentry lookup and snapshot creation.
    
    Cc: Alex Lyakas <alex.btrfs@zadarastorage.com>
    Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
    Signed-off-by: default avatarChris Mason <clm@fb.com>
    9c3b306e