Return-Path: Received: from mail-sn1nam02on0133.outbound.protection.outlook.com ([104.47.36.133]:15072 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032458AbeCAPfo (ORCPT ); Thu, 1 Mar 2018 10:35:44 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Liu Bo , David Sterba , Sasha Levin Subject: [added to the 4.1 stable tree] Btrfs: fix deadlock in run_delalloc_nocow Date: Thu, 1 Mar 2018 15:26:30 +0000 Message-ID: <20180301152116.1486-371-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Liu Bo This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit e89166990f11c3f21e1649d760dd35f9e410321c ] @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: Signed-off-by: Liu Bo Reviewed-by: Josef Bacik Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- 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 1423231c7e49..884e90e9622a 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1282,8 +1282,11 @@ static noinline int run_delalloc_nocow(struct inode = *inode, leaf =3D path->nodes[0]; if (path->slots[0] >=3D btrfs_header_nritems(leaf)) { ret =3D btrfs_next_leaf(root, path); - if (ret < 0) + if (ret < 0) { + if (cow_start !=3D (u64)-1) + cur_offset =3D cow_start; goto error; + } if (ret > 0) break; leaf =3D path->nodes[0]; --=20 2.14.1