]> git.hungrycats.org Git - linux/commitdiff
Btrfs: avoid deadlocks during reservations in btrfs_truncate_block
authorJosef Bacik <jbacik@fb.com>
Wed, 20 Jul 2016 23:48:45 +0000 (16:48 -0700)
committerZygo Blaxell <zblaxell@waya.furryterror.org>
Wed, 17 Aug 2016 02:37:03 +0000 (22:37 -0400)
The new enospc code makes it possible to deadlock if we don't use
FLUSH_LIMIT during reservations inside a transaction.  This enforces
the correct flush type to avoid both deadlocks and assertions

Signed-off-by: Chris Mason <clm@fb.com>
Signed-off-by: Josef Bacik <jbacik@fb.com>
(cherry picked from commit bac357dcec2956f01df9da5365be257741b534dc)

fs/btrfs/extent-tree.c

index 6fb83597c57f66fd3555571afd66caf926219351..a492c6e8d1b4812d5445a907baf7b51c18faf7d4 100644 (file)
@@ -5668,10 +5668,15 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
         * the middle of a transaction commit.  We also don't need the delalloc
         * mutex since we won't race with anybody.  We need this mostly to make
         * lockdep shut its filthy mouth.
+        *
+        * If we have a transaction open (can happen if we call truncate_block
+        * from truncate), then we need FLUSH_LIMIT so we don't deadlock.
         */
        if (btrfs_is_free_space_inode(inode)) {
                flush = BTRFS_RESERVE_NO_FLUSH;
                delalloc_lock = false;
+       } else if (current->journal_info) {
+               flush = BTRFS_RESERVE_FLUSH_LIMIT;
        }
 
        if (flush != BTRFS_RESERVE_NO_FLUSH &&