Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1160974ybf; Thu, 27 Feb 2020 06:08:15 -0800 (PST) X-Google-Smtp-Source: APXvYqygGurcga8IaS1724xrjTSt1iKYFdn4Cl343zUNt5n2YdUDV6/qpFyu4ma52JzNL5z6HWLe X-Received: by 2002:a9d:138:: with SMTP id 53mr3656221otu.334.1582812495034; Thu, 27 Feb 2020 06:08:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582812495; cv=none; d=google.com; s=arc-20160816; b=IAZIUljJWQNvKvhNbLomIuwFc7ZUGYEGcTvbLnuKRYWmRw3UqtX+70riFABa6ea2WZ Cu5dhkBWmd4zMOMt9h4rt5Q92TPzWYnm0f/3/eh3w8GQRzYGnqU7xXzc04KsVIjVcLUg In9rK4cRSW/gwWg/gRTmVcWgkGmFnQOfLAKklKr+ljn/HcxWGVEZn4nTbev512HildU6 y5P99P8buafHYEM/+/iX3gYq1IZeLWdvVkr0imRQk2kM2ZmFhEHzCTVyRHpAfWPfRaK2 Ewt+dDqKvgwnXGl3ta1CQ41MLNpUuoAWysHo92gypn6FuRmCJi0BmAj/kOD9g0KyYeXj K1kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bLI+aqvzhF5mk+ydqPbfVzBUbgyAsN2tpWkp3RARfEA=; b=L70h+UcNsMKyUtMHk7r/28BuFi3L0X5cz00Dk91PXO50diPPViUJkCQyDFEPI2RgaY bW84IdaYYbmge5VLJmS0AEaW3LAz/b+A7IMH9Oev9AWPrQRTkTS6b57hHiIdGQHtGwSW UxTMgG8IUoPluWyyi3GeCG8FunhJGd3VVpq0lYKkMjI0tMnzPCTPVcNUZLyKiAI/2K3l U9JAU40shzmpGGDDpXuHqNApaGrQfoglaHVhKXOyDEbbNVEhxQ9O7P2Bi89E2+ozyveM Qiy9sgFZFJhYPDwcnOiivFmlJu22cOfZT9P0JVX/QKWvPXLV0sfWOR5ERETtRKTpFKPv +ecA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=is+E26KG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a22si1527013otp.84.2020.02.27.06.07.39; Thu, 27 Feb 2020 06:08:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=is+E26KG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387806AbgB0OFn (ORCPT + 99 others); Thu, 27 Feb 2020 09:05:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:42436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387798AbgB0OFk (ORCPT ); Thu, 27 Feb 2020 09:05:40 -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 5B02720578; Thu, 27 Feb 2020 14:05:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582812339; bh=qpo+XMyyKLIxMT/BdGw0TqsKggEost62VlexUf7Rc0o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=is+E26KGS639ffM51QOXe238W/R7++lwi2G2r7zdsc9YLUM12LW3oANjBhF1RwEcR xWI8ammLYjGx9a9yigkpaFrWu315Qgu4sGtTYqbqfE5pdd+oxbWaeL6zHaghhIxX+x SgsSrIO2EeYifMuWH+zuXijxUTLBWeOGX0USET38= 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 4.19 78/97] Btrfs: fix btrfs_wait_ordered_range() so that it waits for all ordered extents Date: Thu, 27 Feb 2020 14:37:26 +0100 Message-Id: <20200227132227.200104132@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132214.553656188@linuxfoundation.org> References: <20200227132214.553656188@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 @@ -712,10 +712,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--; }