Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2653828pxa; Mon, 17 Aug 2020 15:36:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFs9twzrwFsH7b922NhPW4+HTBxK6dS3AFypVxDNWiPCd/VqEFkeDtcvBp/xVGm/rABCQB X-Received: by 2002:a17:906:4dc8:: with SMTP id f8mr17658471ejw.257.1597703801716; Mon, 17 Aug 2020 15:36:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597703801; cv=none; d=google.com; s=arc-20160816; b=PdIP2/8xJx9gTZy2mOY0/+dNpWELgBIPBtGCP0n10l8r8roHLn0O60ZnrWZpXUvdY8 uhe/9DwCidqfoZitDAk2AtIKoalqza8pqocLnAGO1kjwNLJjdQGAdPGft6V2MveRXd/K vochF9kfaslq8vU/kPqW4/MuQvqZxelNeqFm5K3iXjl27N//GLKKg8qIE4g7yL66dhpO 0Qel5TygqdK3DX2mBeET8m2A1ARAWGwNAK0dY9xc0cBzktSIwpmWmxHl1jOwMgFDKmlz fgCGkg6U3P+cGKTkRmMnjnpOF8vOUcwe95i4uCs7aaS7uaNsa7OscPkV9MEUlBxptmwo +C7g== 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=KdztEiQS7IGnurUE8wogdwD0Q0SckXjMvjIfaTYJ6lo=; b=CwSW5kPeWARft2LlmZafcP8BI6vw88RqRFyTrNrnBZk9HOK0+iDFg4viAdLAZrcYe+ 1hvbRF2ALpvsCzW07eLOzZDxACbSaWbPn4FsGINXiOShfoZkIlIpQQDj+HSAfKq9nX2r pzzjTaDqVxJB5XDXFfpskPxk/H5DEoCdG3uresgo4UzHOYZL0n6a5ibkfuDKRT3FA8Ts XpQbOVZqgL/aeod4mgJonvmjfGF3cfymNMGWWk+TrIN4yEL0T0dgRMpipnwAbRcwM2c9 28Lpz1D7o9sdMRbiQFAI2xwmYe7jsZxVYNDZV1mLofrGPsWqGSQ3y/Gt66WivteyWWv1 4ELQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1rhqZVUg; 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 y102si7928822ede.258.2020.08.17.15.36.18; Mon, 17 Aug 2020 15:36:41 -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=1rhqZVUg; 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 S2389598AbgHQRQ1 (ORCPT + 99 others); Mon, 17 Aug 2020 13:16:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:48230 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388769AbgHQQNz (ORCPT ); Mon, 17 Aug 2020 12:13:55 -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 50D6920658; Mon, 17 Aug 2020 16:13:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597680832; bh=NI13nfLqQv9gzozmG+JagpQfnNQnWYTygAizOUqmkFY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1rhqZVUgAv66PParCQGb2cH89v/pgaTioITi8yGi8e7CNae1+Jo31tsUZwcUHVEHt 3T5LbYhx840879QVhCn/D6VW69kZcb46/i5H3gKXfGj/b/L//kemMsiHxJsubUb2eS TxjAaYNjvjmy4jhqigqukHF1DjCsMurSc4AFOl4s= 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 4.19 076/168] xfs: fix reflink quota reservation accounting error Date: Mon, 17 Aug 2020 17:16:47 +0200 Message-Id: <20200817143737.511119337@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143733.692105228@linuxfoundation.org> References: <20200817143733.692105228@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 6622652a85a80..0b159a79a17c6 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1010,6 +1010,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; @@ -1032,13 +1033,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