From patchwork Tue Sep 1 15:08:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 310380 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=-13.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 4F144C433E7 for ; Tue, 1 Sep 2020 16:08:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 23410204EC for ; Tue, 1 Sep 2020 16:08:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598976487; bh=MAsR+OKTtX8ypJugoUpKQOC+iT+UUck+JGdkWEnOczA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=E8P7ioAmBuT1QTfe9/jY+KbFXQmV+GSU+QCrrr+SfQ3OhXGx8zgML3TxRIH76Sje9 w3NPIy4fX5I56E0RTWYfIp6mon790pK2fdqIPKg1DuyDyj1AwwwZxmvZYK6bPhOv0x 4qo0ciKIPZS6sSs0whUON/T+cuF4pHVfWA/hFTrQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727949AbgIAPjf (ORCPT ); Tue, 1 Sep 2020 11:39:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:49580 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727846AbgIAPjb (ORCPT ); Tue, 1 Sep 2020 11:39:31 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 9A62020866; Tue, 1 Sep 2020 15:39:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598974771; bh=MAsR+OKTtX8ypJugoUpKQOC+iT+UUck+JGdkWEnOczA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iB8VKN19OpRN5uxuM1kR2zps8Xj8M+1VezElPKLbDi4Fto7VA+gyHhm3rE3fUQ+2Z 8fvOSyOJexd0QC3UybliZ92yLkuuqBZfWWRY9I5HUt0hkPgaNZrtvA4NymEZ1cOMBY wvdE5/fjMCFqRoqx2EwV6X+rq/q6FWXpgobvSEUA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , Qu Wenruo , David Sterba , Sasha Levin Subject: [PATCH 5.8 054/255] btrfs: file: reserve qgroup space after the hole punch range is locked Date: Tue, 1 Sep 2020 17:08:30 +0200 Message-Id: <20200901151003.313221333@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901151000.800754757@linuxfoundation.org> References: <20200901151000.800754757@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: Qu Wenruo [ Upstream commit a7f8b1c2ac21bf081b41264c9cfd6260dffa6246 ] The incoming qgroup reserved space timing will move the data reservation to ordered extent completely. However in btrfs_punch_hole_lock_range() will call btrfs_invalidate_page(), which will clear QGROUP_RESERVED bit for the range. In current stage it's OK, but if we're making ordered extents handle the reserved space, then btrfs_punch_hole_lock_range() can clear the QGROUP_RESERVED bit before we submit ordered extent, leading to qgroup reserved space leakage. So here change the timing to make reserve data space after btrfs_punch_hole_lock_range(). The new timing is fine for either current code or the new code. Reviewed-by: Josef Bacik Signed-off-by: Qu Wenruo Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/file.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 1523aa4eaff07..9e8f6c66788d0 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -3176,14 +3176,14 @@ reserve_space: if (ret < 0) goto out; space_reserved = true; - ret = btrfs_qgroup_reserve_data(inode, &data_reserved, - alloc_start, bytes_to_reserve); - if (ret) - goto out; ret = btrfs_punch_hole_lock_range(inode, lockstart, lockend, &cached_state); if (ret) goto out; + ret = btrfs_qgroup_reserve_data(inode, &data_reserved, + alloc_start, bytes_to_reserve); + if (ret) + goto out; ret = btrfs_prealloc_file_range(inode, mode, alloc_start, alloc_end - alloc_start, i_blocksize(inode),