]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
btrfs: Rename btrfs_join_transaction_nolock
authorNikolay Borisov <nborisov@suse.com>
Tue, 8 Oct 2019 17:43:06 +0000 (20:43 +0300)
committerDavid Sterba <dsterba@suse.com>
Mon, 18 Nov 2019 11:46:54 +0000 (12:46 +0100)
This function is used only during the final phase of freespace cache
writeout. This is necessary since using the plain btrfs_join_transaction
api is deadlock prone. The deadlock looks like:

T1:
btrfs_commit_transaction
  commit_cowonly_roots
    btrfs_write_dirty_block_groups
      btrfs_wait_cache_io
        __btrfs_wait_cache_io
       btrfs_wait_ordered_range <-- Triggers ordered IO for freespace
                                    inode and blocks transaction commit
    until freespace cache writeout

T2: <-- after T1 has triggered the writeout
finish_ordered_fn
  btrfs_finish_ordered_io
    btrfs_join_transaction <--- this would block waiting for current
                                transaction to commit, but since trans
commit is waiting for this writeout to
finish

The special purpose functions prevents it by simply skipping the "wait
for writeout" since it's guaranteed the transaction won't proceed until
we are done.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c
fs/btrfs/transaction.c
fs/btrfs/transaction.h

index 7ed0fe2dd5bafdc81f690edbfe3c9262c91618ec..3315a6eb09a35dc0e13aa69324f08d3f379eb518 100644 (file)
@@ -3066,7 +3066,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
        int compress_type = 0;
        int ret = 0;
        u64 logical_len = ordered_extent->len;
-       bool nolock;
+       bool freespace_inode;
        bool truncated = false;
        bool range_locked = false;
        bool clear_new_delalloc_bytes = false;
@@ -3077,7 +3077,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
            !test_bit(BTRFS_ORDERED_DIRECT, &ordered_extent->flags))
                clear_new_delalloc_bytes = true;
 
-       nolock = btrfs_is_free_space_inode(BTRFS_I(inode));
+       freespace_inode = btrfs_is_free_space_inode(BTRFS_I(inode));
 
        if (test_bit(BTRFS_ORDERED_IOERR, &ordered_extent->flags)) {
                ret = -EIO;
@@ -3108,8 +3108,8 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
                btrfs_qgroup_free_data(inode, NULL, ordered_extent->file_offset,
                                       ordered_extent->len);
                btrfs_ordered_update_i_size(inode, 0, ordered_extent);
-               if (nolock)
-                       trans = btrfs_join_transaction_nolock(root);
+               if (freespace_inode)
+                       trans = btrfs_join_transaction_spacecache(root);
                else
                        trans = btrfs_join_transaction(root);
                if (IS_ERR(trans)) {
@@ -3143,8 +3143,8 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
                        EXTENT_DEFRAG, 0, 0, &cached_state);
        }
 
-       if (nolock)
-               trans = btrfs_join_transaction_nolock(root);
+       if (freespace_inode)
+               trans = btrfs_join_transaction_spacecache(root);
        else
                trans = btrfs_join_transaction(root);
        if (IS_ERR(trans)) {
index 54b8718054ce0a503d20e8560397fdc2eab0b008..6f133906c862b43d38a5c096ac2cbc6151fcc274 100644 (file)
@@ -729,7 +729,7 @@ struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root)
                                 true);
 }
 
-struct btrfs_trans_handle *btrfs_join_transaction_nolock(struct btrfs_root *root)
+struct btrfs_trans_handle *btrfs_join_transaction_spacecache(struct btrfs_root *root)
 {
        return start_transaction(root, 0, TRANS_JOIN_NOLOCK,
                                 BTRFS_RESERVE_NO_FLUSH, true);
index 2ac89fb0d709c0f6904156cb6cf08bfca4467d50..49f7196368f5a5d3893a2a7d45c9d1ddcae38046 100644 (file)
@@ -183,7 +183,7 @@ struct btrfs_trans_handle *btrfs_start_transaction_fallback_global_rsv(
                                        unsigned int num_items,
                                        int min_factor);
 struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root);
-struct btrfs_trans_handle *btrfs_join_transaction_nolock(struct btrfs_root *root);
+struct btrfs_trans_handle *btrfs_join_transaction_spacecache(struct btrfs_root *root);
 struct btrfs_trans_handle *btrfs_join_transaction_nostart(struct btrfs_root *root);
 struct btrfs_trans_handle *btrfs_attach_transaction(struct btrfs_root *root);
 struct btrfs_trans_handle *btrfs_attach_transaction_barrier(