Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1138320ybf; Thu, 27 Feb 2020 05:45:34 -0800 (PST) X-Google-Smtp-Source: APXvYqzTTPopvDdbSdC84YmebHyeEQnorH0Ur9317XEjOJAADuppjRXAxDQ9breIkBXD4OK4EXST X-Received: by 2002:a05:6808:3ae:: with SMTP id n14mr3383226oie.63.1582811134479; Thu, 27 Feb 2020 05:45:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582811134; cv=none; d=google.com; s=arc-20160816; b=F7mMWPSkdeyl02hadMS1BYqNv2x1XmpCcVFaUUOJlFcyDHA6GD9OrAfK8q2LuvePv4 o/SeKYf9AIb6KjiSXx1x3qt4Mt4RJdDm5Kx65lsqqQkeMI3Pir9WMPPirr6yovVJUQIx 7C4/OqC0M+GjPceJQYI8S9Z9xYZc3x/Y16NnxtSMJ1jgGzXmK6+pSiJZrukMypPI70ZX GIUKiCEa5WBo4SwFFWOlitb10qWyNOcyGdUT5WM3xNhuS4WvhI9dChbagsT7veVycLVi 4wcihaJyFwZDTamvjpfWp7hyTQWn0PNt/0GyEDa/+SC0L7z5ZDqZ/E3RsMoSWYw5x6Md Stpw== 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=eqOlu4au2tzxW/az9bhA403RDhADSNNPucGm046Rymc=; b=zb/KAK0crSILvO1e/vCSCS7YFf7cTRcqfpHgTMDGs8nAUzpRRrCG346RaWGJK/coE+ iJUT3Nnx1wzOMnz1sajlS1ff5iAZwoWeD46cqihVEFIN1PhwlsbOog5rwdbKeEsHUM+f dxzbuhplrO1At1RtiBfesooinr9p/3g4+McRjcANCbalSk+ppF2C9LBQ8l8D1i2BayXj m6uiX3/6h8swl7m4YCd9vaEK2x/P7B76ua2YEd+qSe1l+VEdtnJM3yB2YaMyOlKPoJwk EaajvL21661QVww5cvYj1FEGJDA3UadeBSUnjwcvCGZkYIhdl5i6ArkWFj4+E/6i6lI3 Skow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sUicPGYS; 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 i194si1399843oib.73.2020.02.27.05.45.22; Thu, 27 Feb 2020 05:45:34 -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=sUicPGYS; 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 S1730237AbgB0Noe (ORCPT + 99 others); Thu, 27 Feb 2020 08:44:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:40028 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729834AbgB0Nob (ORCPT ); Thu, 27 Feb 2020 08:44:31 -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 AB65620726; Thu, 27 Feb 2020 13:44:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582811071; bh=4zMSgVLvToFvLCsakiT/RfaMvUR1I5kjrs73Rp7VQy4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sUicPGYSmMkSD/7B+nGP5fsum9P2GTvhzv4lXd8iZz8FMa0/xM8nFgxkvAAw4xsV3 VHN9hxONY5lHNqOifsN5suXrcpqtaNf1JR308jT1YulVdcJlFWKc8s6ORLfZStz0vv rIRj/Qpf7rSSa0ugCNcuupd/ezSKIvd5NRIn6ebQ= 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.4 106/113] Btrfs: fix btrfs_wait_ordered_range() so that it waits for all ordered extents Date: Thu, 27 Feb 2020 14:37:02 +0100 Message-Id: <20200227132228.731447085@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132211.791484803@linuxfoundation.org> References: <20200227132211.791484803@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 @@ -820,10 +820,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--; }