Btrfs: fix deadlock in run_delalloc_nocow

"Linux Kernel Mailing List" <[email protected]> Fri, 16 Feb 2018 17:44:22 +0000 (UTC)
Newsgroups gmane.linux.kernel.commits.head
Message-ID <[email protected]>
Web:        https://git.kernel.org/torvalds/c/e89166990f11c3f21e1649d760dd35f9e410321c
Commit:     e89166990f11c3f21e1649d760dd35f9e410321c
Parent:     3acbcbfc8f06d4ade2aab2ebba0a2542a05ce90c
Refname:    refs/heads/master
Author:     Liu Bo <[email protected]>
AuthorDate: Thu Jan 25 11:02:50 2018 -0700
Committer:  David Sterba <[email protected]>
CommitDate: Fri Feb 2 16:24:19 2018 +0100

    Btrfs: fix deadlock in run_delalloc_nocow
    
    @cur_offset is not set back to what it should be (@cow_start) if
    btrfs_next_leaf() returns something wrong, and the range [cow_start,
    cur_offset) remains locked forever.
    
    cc: <[email protected]>
    Signed-off-by: Liu Bo <[email protected]>
    Reviewed-by: Josef Bacik <[email protected]>
    Signed-off-by: David Sterba <[email protected]>
---
 fs/btrfs/inode.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index c5f31817778b..a68a4acd16e5 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1334,8 +1334,11 @@ next_slot:
 		leaf = path->nodes[0];
 		if (path->slots[0] >= btrfs_header_nritems(leaf)) {
 			ret = btrfs_next_leaf(root, path);
-			if (ret < 0)
+			if (ret < 0) {
+				if (cow_start != (u64)-1)
+					cur_offset = cow_start;
 				goto error;
+			}
 			if (ret > 0)
 				break;
 			leaf = path->nodes[0];
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html