Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2658038pxa; Mon, 17 Aug 2020 15:44:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeezVu/wSUqAx0WeQrmsU0n8lxBrA2UGyJQQr2jdhJrEmh1W4jcXBgL3jphaoOPeSyTsFe X-Received: by 2002:a17:906:e24f:: with SMTP id gq15mr17136241ejb.46.1597704279478; Mon, 17 Aug 2020 15:44:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597704279; cv=none; d=google.com; s=arc-20160816; b=R0QrZ/Hn35Kehmgka7cs3asrm2WrxKmUeUdx4You6zCGDkG97AfWU+8WlSuLMANh01 h/aihOljx1CdO6Ld80LPl1U3PZ8IwxEpvwtgnxLq4DuyvAf07zjnoVhch8XTvt1XUOjL rGdnA1mvamjKc9totj1P7YclgqapPApZ48sWAcZ8vMxL3SaNljdfxJCcytJU95bQrEF/ HegcjPu+Sx1neUGhzvowwMk/aURuMsLnm2GYIFFXCP2KqXq5hPZrt3AycHQK4bSiYX4P myTIzpF70J0WY+nJt76BVaxdRybywmyd1+ree7LmjfJ33rwEbYv2aBRRq1v4KD2NW589 6dHg== 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=idDAA7LTg0v9fLVisC1YPxzO9Ds7P3a8lzOpYs/c07U=; b=wojrciIw0ys4+hbB6zk+KJ+avUM4d8B90PniHhL8/AAjUbQA+FX4RRJaZ2+71fcb51 ye740/C7Lour0IwUC4AnQj8ei7HT73Qwb3x/NfCqv61i5vCYcAHBZPTISfN9sL2/EDbR vIvbgianCUtwuBcuFWbHD+qGSwz9jzarQH/DH4KCH9rRjDdSuKFEGHbnzaiTWkSrXTx6 3JmZqAbbPl4UR8jJnxJyYjU7gQQ5WxdWFfP2GJPhnzTynM/hlga5ODSl/ceIv+p4Xyra 0Q7qCW848jvdTK/Hi+akjbVCYkqlxeAvXeWyt9PqQFQVJoEkgi6xunrX7ctcHCnN4Qfi IreQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sG8aHlV+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i6si11981833ejc.494.2020.08.17.15.44.15; Mon, 17 Aug 2020 15:44:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sG8aHlV+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390052AbgHQS6B (ORCPT + 99 others); Mon, 17 Aug 2020 14:58:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:34416 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730655AbgHQPuG (ORCPT ); Mon, 17 Aug 2020 11:50:06 -0400 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 BEAE02067C; Mon, 17 Aug 2020 15:49:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597679389; bh=SJxSG5hjeCoBv7dI/pFgKfrBpXKRvG9S8f+X7U2EkEs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sG8aHlV+bu/wm4j9/Kdv22bXCaAX8Q7s38l9diNqv7hRpc5ElQd9vpiZb26/Y/YzK R1zWmYVErNKJ15a2IudZpUIborSEfIJRwoXlSx3q1auvQBo8pa9cOE9/BQf/GIQGCA JHGadqA3wM4rTLDtMs4qO2nBwmtiUpovNerB9zts= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Darrick J. Wong" , Brian Foster , Sasha Levin Subject: [PATCH 5.7 187/393] xfs: fix reflink quota reservation accounting error Date: Mon, 17 Aug 2020 17:13:57 +0200 Message-Id: <20200817143828.691455190@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143819.579311991@linuxfoundation.org> References: <20200817143819.579311991@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: Darrick J. Wong [ Upstream commit 83895227aba1ade33e81f586aa7b6b1e143096a5 ] Quota reservations are supposed to account for the blocks that might be allocated due to a bmap btree split. Reflink doesn't do this, so fix this to make the quota accounting more accurate before we start rearranging things. Fixes: 862bb360ef56 ("xfs: reflink extents from one file to another") Signed-off-by: Darrick J. Wong Reviewed-by: Brian Foster Signed-off-by: Sasha Levin --- fs/xfs/xfs_reflink.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 107bf2a2f3448..d89201d40891f 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1003,6 +1003,7 @@ xfs_reflink_remap_extent( xfs_filblks_t rlen; xfs_filblks_t unmap_len; xfs_off_t newlen; + int64_t qres; int error; unmap_len = irec->br_startoff + irec->br_blockcount - destoff; @@ -1025,13 +1026,19 @@ xfs_reflink_remap_extent( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); - /* If we're not just clearing space, then do we have enough quota? */ - if (real_extent) { - error = xfs_trans_reserve_quota_nblks(tp, ip, - irec->br_blockcount, 0, XFS_QMOPT_RES_REGBLKS); - if (error) - goto out_cancel; - } + /* + * Reserve quota for this operation. We don't know if the first unmap + * in the dest file will cause a bmap btree split, so we always reserve + * at least enough blocks for that split. If the extent being mapped + * in is written, we need to reserve quota for that too. + */ + qres = XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK); + if (real_extent) + qres += irec->br_blockcount; + error = xfs_trans_reserve_quota_nblks(tp, ip, qres, 0, + XFS_QMOPT_RES_REGBLKS); + if (error) + goto out_cancel; trace_xfs_reflink_remap(ip, irec->br_startoff, irec->br_blockcount, irec->br_startblock); -- 2.25.1