Return-Path: Received: from mail-by2nam03on0090.outbound.protection.outlook.com ([104.47.42.90]:61856 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032419AbeCAPfH (ORCPT ); Thu, 1 Mar 2018 10:35:07 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Nikolay Borisov , David Sterba , Sasha Levin Subject: [added to the 4.1 stable tree] btrfs: Handle btrfs_set_extent_delalloc failure in fixup worker Date: Thu, 1 Mar 2018 15:26:19 +0000 Message-ID: <20180301152116.1486-354-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: Nikolay Borisov 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 f3038ee3a3f1017a1cbe9907e31fa12d366c5dcb ] This function was introduced by 247e743cbe6e ("Btrfs: Use async helpers to deal with pages that have been improperly dirtied") and it didn't do any error handling then. This function might very well fail in ENOMEM situation, yet it's not handled, this could lead to inconsistent state. So let's handle the failure by setting the mapping error bit. Cc: stable@vger.kernel.org Signed-off-by: Nikolay Borisov Reviewed-by: Qu Wenruo Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/inode.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index d14af5bd13d6..1423231c7e49 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1999,7 +1999,15 @@ static void btrfs_writepage_fixup_worker(struct btrf= s_work *work) goto out; } =20 - btrfs_set_extent_delalloc(inode, page_start, page_end, &cached_state); + ret =3D btrfs_set_extent_delalloc(inode, page_start, page_end, + &cached_state); + if (ret) { + mapping_set_error(page->mapping, ret); + end_extent_writepage(page, ret, page_start, page_end); + ClearPageChecked(page); + goto out; + } + ClearPageChecked(page); set_page_dirty(page); out: --=20 2.14.1