Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp827781rwb; Mon, 26 Sep 2022 06:25:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4/uUnYotvrrVFgzZiUAuBa5UP8PaE6NwUbAjs/K0Yc808UWJpdv5idm/Hj4vAZ35bb8+s8 X-Received: by 2002:a17:90b:180a:b0:202:ae1f:328a with SMTP id lw10-20020a17090b180a00b00202ae1f328amr37228783pjb.78.1664198710060; Mon, 26 Sep 2022 06:25:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664198710; cv=none; d=google.com; s=arc-20160816; b=OcP5slBHYnc8MwbfdlvSNGr6rPQ9BYJ86PBqLy/1q9zC6oVBfyaBa7NWuOINGRnfzX VBUMZ+GMQL4GS+q6rF9P7cOq6/i1EMx5sTbDy6habtKptmsBJqYD1TFoHWshCS/EixrG UeOiE4qzRL9zqeZix78KCAdHiqWdnD5lkTbiJVJGKjrVFgP6Au9qqSog/PLr5M/uzFfP o5FrRzIeafsQpcKCZz5p7k4QqyxZyRF9omUlRYem1rPen/Ix5Lg6LhmwhnF62FcP5jU4 WJ4VoL8HtyS6DQ1N7kHeiEnsLtfGIJEV6eR7ZI3eUhjM5zz+yYTSbe9GHIKvxYXns+Js xIiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8875YNgm3A7CJpQ/BOVJ5jQN4M25LQP5DMzkWoorLWI=; b=g711FldMQROgSmi2lyWworLSo2PsWzzq14OpRW/2DWg2YTaVYHtYCzYOuHHquRpB1Z tjTDO7vbiaB9C3D8xSL9ANu3A50N8lIHWbK5KgOHe/2hkfA7dPMj8J9HcXKGJnHPG69t 0NqfK1+MK5pIYqRiMft3XeoRFMoJvfi3MnIqTLTqlunqedw3cry0fZbTaOOMzlPDvaZJ W8x5Y0ut9Le9ilHg8K4wXe2CpCHXsw7tK3xvgZWMP4dqTMLLWMVu8OC4jcvjstsxKvv6 SxuigIm4pfuvvWJeUqvl4tJiqljcxI/iMc/0KvlqJtypshlhCCb95AfIvjoSjSwOi61a Jmgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NyctNZsR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h71-20020a63834a000000b0043c87ece306si1361493pge.534.2022.09.26.06.24.59; Mon, 26 Sep 2022 06:25:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NyctNZsR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236691AbiIZKv3 (ORCPT + 99 others); Mon, 26 Sep 2022 06:51:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236680AbiIZKtA (ORCPT ); Mon, 26 Sep 2022 06:49:00 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B0084DB73; Mon, 26 Sep 2022 03:26:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B27EAB8055F; Mon, 26 Sep 2022 10:26:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1CA9C433D6; Mon, 26 Sep 2022 10:26:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664187982; bh=psv3uKrLsqAIWdTo1TVmFaLRqzOckcFVq3aCsW3RV7U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NyctNZsR8OL0/0xwAwdEutzxnvJkJu+n8HHkjQAo/JNVTRGI85oGNf6Zde7kTW+5T 3niggA3dJQhDqRR9AMbTzyOHucyxCqSw4razLQizpZNiHQ7cXXNlFs8NdPiHy0sabH Lf6Umvaf/Gd6Auoj3GRqVkN3xVEufSxlhw+AqIKI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Darrick J. Wong" , Christoph Hellwig , "Darrick J. Wong" , Chandan Babu R Subject: [PATCH 5.4 108/120] xfs: attach dquots and reserve quota blocks during unwritten conversion Date: Mon, 26 Sep 2022 12:12:21 +0200 Message-Id: <20220926100754.905815982@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100750.519221159@linuxfoundation.org> References: <20220926100750.519221159@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Darrick J. Wong" commit 2815a16d7ff6230a8e37928829d221bb075aa160 upstream. In xfs_iomap_write_unwritten, we need to ensure that dquots are attached to the inode and quota blocks reserved so that we capture in the quota counters any blocks allocated to handle a bmbt split. This can happen on the first unwritten extent conversion to a preallocated sparse file on a fresh mount. This was found by running generic/311 with quotas enabled. The bug seems to have been introduced in "[XFS] rework iocore infrastructure, remove some code and make it more" from ~2002? Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Acked-by: Darrick J. Wong Signed-off-by: Chandan Babu R Signed-off-by: Greg Kroah-Hartman --- fs/xfs/xfs_iomap.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -765,6 +765,11 @@ xfs_iomap_write_unwritten( */ resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1; + /* Attach dquots so that bmbt splits are accounted correctly. */ + error = xfs_qm_dqattach(ip); + if (error) + return error; + do { /* * Set up a transaction to convert the range of extents @@ -783,6 +788,11 @@ xfs_iomap_write_unwritten( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); + error = xfs_trans_reserve_quota_nblks(tp, ip, resblks, 0, + XFS_QMOPT_RES_REGBLKS); + if (error) + goto error_on_bmapi_transaction; + /* * Modify the unwritten extent state of the buffer. */