From patchwork Thu Feb 27 13:37:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 230414 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B903CC54FC5 for ; Thu, 27 Feb 2020 14:10:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8F94D20801 for ; Thu, 27 Feb 2020 14:10:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582812647; bh=G9EA7YhuBsmASAXGxVxqTr+Br1dwP2PxxDW6Vo/Q3W0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=cOgV7WObql4YYE5rLkdh+14tqkX9Xf0GKLSg1gvN90azxdJv/AmR/agXIvQIRE5Qf dv4Tmqgf0qbuwuoMMZMJzF42UlqW4Osa5KqXjTvpfaM5x6/xVOx3v/jXipikaFfu9C YCIlCoSyVu15RuxHUI53Fj5vzAsvQLVutrVaxI8Y= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388583AbgB0OKq (ORCPT ); Thu, 27 Feb 2020 09:10:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:49000 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388578AbgB0OKq (ORCPT ); Thu, 27 Feb 2020 09:10:46 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1D7DD246B7; Thu, 27 Feb 2020 14:10:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582812645; bh=G9EA7YhuBsmASAXGxVxqTr+Br1dwP2PxxDW6Vo/Q3W0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b4W4aITwEF15l02Yi4lP6a7MaTmeJ6mVkYrOpHVTdiPHNoX2WC+hBokiXkIqJiv+5 P6wJ2KNNkcqFp43/XEiCYKzgW56MQK75CQt24hPUZEwqhjEvvwto/HaUKaIRC8THwr 1mz5E9HfXvej4uEGa6BDZvrbBvj0vZcwTgRg/DJ0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , Josef Bacik , Filipe Manana , David Sterba Subject: [PATCH 5.4 096/135] Btrfs: fix btrfs_wait_ordered_range() so that it waits for all ordered extents Date: Thu, 27 Feb 2020 14:37:16 +0100 Message-Id: <20200227132243.658339077@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132228.710492098@linuxfoundation.org> References: <20200227132228.710492098@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Filipe Manana commit e75fd33b3f744f644061a4f9662bd63f5434f806 upstream. In btrfs_wait_ordered_range() once we find an ordered extent that has finished with an error we exit the loop and don't wait for any other ordered extents that might be still in progress. All the users of btrfs_wait_ordered_range() expect that there are no more ordered extents in progress after that function returns. So past fixes such like the ones from the two following commits: ff612ba7849964 ("btrfs: fix panic during relocation after ENOSPC before writeback happens") 28aeeac1dd3080 ("Btrfs: fix panic when starting bg cache writeout after IO error") don't work when there are multiple ordered extents in the range. Fix that by making btrfs_wait_ordered_range() wait for all ordered extents even after it finds one that had an error. Link: https://github.com/kdave/btrfs-progs/issues/228#issuecomment-569777554 CC: stable@vger.kernel.org # 4.4+ Reviewed-by: Qu Wenruo Reviewed-by: Josef Bacik Signed-off-by: Filipe Manana Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/ordered-data.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -690,10 +690,15 @@ int btrfs_wait_ordered_range(struct inod } btrfs_start_ordered_extent(inode, ordered, 1); end = ordered->file_offset; + /* + * If the ordered extent had an error save the error but don't + * exit without waiting first for all other ordered extents in + * the range to complete. + */ if (test_bit(BTRFS_ORDERED_IOERR, &ordered->flags)) ret = -EIO; btrfs_put_ordered_extent(ordered); - if (ret || end == 0 || end == start) + if (end == 0 || end == start) break; end--; }