Received: by 10.223.185.116 with SMTP id b49csp1046956wrg; Fri, 23 Feb 2018 10:57:51 -0800 (PST) X-Google-Smtp-Source: AH8x227j9Xhui7Np+c1JYKbxyN3HXc4G46z0DMvVCU+PzY/VCZS2SaPN2wxShHNce6yfJs07pqni X-Received: by 2002:a17:902:12e:: with SMTP id 43-v6mr2586392plb.77.1519412270936; Fri, 23 Feb 2018 10:57:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519412270; cv=none; d=google.com; s=arc-20160816; b=e26UXm9nI+7z+JhJ8O2p6QXnd4na7aJNJXsxVkUWUjlvshCbUGnDJHOG3dDFZLHzqK pob4yu2W8YAuF/GWyiyi03mOHTAKhxTk8qmV8SR9+XROUsGiR5ED3ldKpZLLYcjmbqgh Tdy4mrpwA2gw4PjZrtz48pw22wiDs2m2RCnNFy0Dv2KHT+0DM+FOz0BJKi1IPOE6OO7y lu4fx8nLs9KK5UtCEzTa+c7CAz2LC45WHGda45hIH/Fre8o57v5P8aRzLA3u5mhYN5jd JW3/DNy4HRNF8GDJJ7mERnfq980R+Zw1eV+Rg2IvIHXfMh79Ds5vtESOD4uPGF7h5poB Rp0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=UGQhDI+lIzmSQ4BJtubQH1yjOjK5wZ86vIKXf/y7b7g=; b=JztdY6cyIe+5x2XpMxhDfJwVMPpUw5hEfHCy/QuwbvKViNqT/5/76THH+myJ6nx63j Xq8tOa0QNzybderT8HeWwCb3kHm8Ze/jDPB3SE6oFePiA+v6tP7LLQViIZAYAYiXn9gv Lt8StsvBYU6MxSKZEvVNneuNi1ctp3Ngef/Ay6zLooyGZrN74pBiebImlDe8Sbt1hLFL SdAk3KgNsOp9iAZcgha92Kpk1r9AYkom+LVamvJ1aJb7N3P3nGBpPL4MrzRW6EPYOVa5 0Zutw8a59vQOTRvZGLsxCl4qIgZY23KT29GwTI/aNdzh00Q/cvrN+DByWXPKO8+4KMLT gIeQ== ARC-Authentication-Results: i=1; mx.google.com; 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 v10si1850788pgs.164.2018.02.23.10.57.36; Fri, 23 Feb 2018 10:57:50 -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; 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 S935642AbeBWS4i (ORCPT + 99 others); Fri, 23 Feb 2018 13:56:38 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:48866 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935600AbeBWS42 (ORCPT ); Fri, 23 Feb 2018 13:56:28 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E350612A6; Fri, 23 Feb 2018 18:56:26 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Justin Maggard , Qu Wenruo , David Sterba , Sasha Levin Subject: [PATCH 4.14 118/159] btrfs: Fix quota reservation leak on preallocated files Date: Fri, 23 Feb 2018 19:27:06 +0100 Message-Id: <20180223170757.587068442@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170743.086611315@linuxfoundation.org> References: <20180223170743.086611315@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Justin Maggard [ Upstream commit b430b7751286b3acff2d324553c8cec4f1e87764 ] Commit c6887cd11149 ("Btrfs: don't do nocow check unless we have to") changed the behavior of __btrfs_buffered_write() so that it first tries to get a data space reservation, and then skips the relatively expensive nocow check if the reservation succeeded. If we have quotas enabled, the data space reservation also includes a quota reservation. But in the rewrite case, the space has already been accounted for in qgroups. So btrfs_check_data_free_space() increases the quota reservation, but it never gets decreased when the data actually gets written and overwrites the pre-existing data. So we're left with both the qgroup and qgroup reservation accounting for the same space. This commit adds the missing btrfs_qgroup_free_data() call in the case of BTRFS_ORDERED_PREALLOC extents. Fixes: c6887cd11149 ("Btrfs: don't do nocow check unless we have to") Signed-off-by: Justin Maggard Reviewed-by: Qu Wenruo Signed-off-by: David Sterba Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/inode.c | 2 ++ 1 file changed, 2 insertions(+) --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -3016,6 +3016,8 @@ static int btrfs_finish_ordered_io(struc compress_type = ordered_extent->compress_type; if (test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) { BUG_ON(compress_type); + btrfs_qgroup_free_data(inode, NULL, ordered_extent->file_offset, + ordered_extent->len); ret = btrfs_mark_extent_written(trans, BTRFS_I(inode), ordered_extent->file_offset, ordered_extent->file_offset +