From patchwork Mon Apr 29 04:49:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13646275 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86124DF5C for ; Mon, 29 Apr 2024 04:49:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714366165; cv=none; b=nWFyuwQGtTzNvYlp2Gty7CFAug002cmXPCNOH/ykK5GZNieyhj3JxgpYdpDEdjYCkqFnUaOz/FC7Hqz/EMfnIZa/EhX5p2votxrMU+9wpPokJrMNlhZSnVgr4897Rp/iRlU2FD4CkKMMN/tWf0bBiXjrLovhaXjsCIxzWGPJ/T4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714366165; c=relaxed/simple; bh=hyqwHFHbv86aG7TC/mM7tiQGCYS78er9rosLv0r/UqU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nYhB+XyWVeB73vTrKhVbu33Hf6xpWgWRQy1YN50q8Tiqr34/nsRz7tGdtrMy9UpwmV3wsWIzypINxzAneeQFOOLQbYwtWoO+mrPUTOvqyvpzog4T6vRTgGCiAi8QJZEM/lVFXcNR7hNcJ6RCHUNxXn7vQu7R4K1BpAxMO9sVjDE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=1fdq7nfN; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="1fdq7nfN" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=MvWGRRV8TV81ke+USUJL1Mv4KapVSNa6T5Jei/iZjhQ=; b=1fdq7nfNYYIvz691NQ+eleQPm8 Ln+rPrm0ip+IyC2pLD8zI5if9KTIM64SGO8k3S+mGaFhddKvQXkulhzsq7UdV6OYRgsHZ0NB5OavZ qLGu2B+qwJJ3hvpeHctC8ZeS6rSA1mxI+8XiAoQ+5ZH7nBztZlF5zRYCEDwtBaX8qr7JENioYtWAb vI7ZbL74Nj8ZK7Ulg8aMlTJ7dKmSo9VGGfwuOd9twJY6XxmFjjROrgBcEe8ZBRPl4JMGvyn3vR1KD dFPzx9W+Jo7937oK+RH75woRO9fmGiVj1Q8had5luSNqA2AsJmlg7yUObSwGximcUoDzflsBywGam RK02+OOQ==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1Ix9-00000001S4j-2oeS; Mon, 29 Apr 2024 04:49:24 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 1/8] xfs: upgrade the extent counters in xfs_reflink_end_cow_extent later Date: Mon, 29 Apr 2024 06:49:10 +0200 Message-Id: <20240429044917.1504566-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240429044917.1504566-1-hch@lst.de> References: <20240429044917.1504566-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Defer the extent counter size upgrade until we know we're going to modify the extent mapping. This also defers dirtying the transaction and will allow us safely back out later in the function in later changes. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_reflink.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 7da0e8f961d351..9ce37d366534c3 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -751,14 +751,6 @@ xfs_reflink_end_cow_extent( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); - error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, - XFS_IEXT_REFLINK_END_COW_CNT); - if (error == -EFBIG) - error = xfs_iext_count_upgrade(tp, ip, - XFS_IEXT_REFLINK_END_COW_CNT); - if (error) - goto out_cancel; - /* * In case of racing, overlapping AIO writes no COW extents might be * left by the time I/O completes for the loser of the race. In that @@ -787,6 +779,14 @@ xfs_reflink_end_cow_extent( del = got; xfs_trim_extent(&del, *offset_fsb, end_fsb - *offset_fsb); + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + XFS_IEXT_REFLINK_END_COW_CNT); + if (error == -EFBIG) + error = xfs_iext_count_upgrade(tp, ip, + XFS_IEXT_REFLINK_END_COW_CNT); + if (error) + goto out_cancel; + /* Grab the corresponding mapping in the data fork. */ nmaps = 1; error = xfs_bmapi_read(ip, del.br_startoff, del.br_blockcount, &data, From patchwork Mon Apr 29 04:49:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13646276 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 019BBC129 for ; Mon, 29 Apr 2024 04:49:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714366168; cv=none; b=jxvb+vtzppvoo/ECy5av/sh+v8w/FPYsOz9DDPQtZl0B0S3vgjAZlbizFDzTjFSquJHEWqMCCSvCkmkL622ZOZ9FdF3VdJNzUDZkf+ds0/MPuqyaR1dAYW+mw+L5RzUih+HfodHtfXfwhfKw2BmyWGB1UA2u4xvRU3J+cCyZDMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714366168; c=relaxed/simple; bh=fsPgkn26zdjYdjd6qmuC6bskW4HXsUTLqEl+teK7in0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CpCC2d6qqGmATHgrShffJ9OfFotjPCAJ4KIkuChjRvTaR+St/H7O93aAQyIRUFVZXTU4PIgi3348qTbIcIuzYupVZ2d7QxsmeT3/Ntzvogrm2JU6JPu2qQwnfuGxIzpngudhdMIkHEUwB54GD2hliuHXMoyv4LhJEz5IW5J7b5A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=bROKuwXj; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="bROKuwXj" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=fXvv2gQOqGyZT04ePXFPVzIb9yv5GF39uRGki/KfwcA=; b=bROKuwXjGJ7lmka//GHSie7oxR Vf5BjrUIxg1LdRjz7qWluZu6gehzmdwvQEHUxjeLEgEDGYVYUgE7fggi9L966NPV8nakLeN2n3aRb MppF11GR9q4xpeKwIObgdtmWSAF/Ouqzv1Tf5uG3ByZtnTpYUrAXaMJkRwqMWWQbzyN3APxYPpJHs lY4ZsndqGzrCydrA325uDPZh82NOLm/YY2sPJCSPPR2MS6MLUKthn6a4F7hYXVHfMluu2u7XV87zv tzQy4cpO/tGtU0NzDdQDwCe54BMcnY0z7/KptRCqNXjD7cH7seOqCNSwlz02jJM66ondyDJvXrg07 5mW7ONgg==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1IxC-00000001S5J-136C; Mon, 29 Apr 2024 04:49:26 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 2/8] xfs: remove a racy if_bytes check in xfs_reflink_end_cow_extent Date: Mon, 29 Apr 2024 06:49:11 +0200 Message-Id: <20240429044917.1504566-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240429044917.1504566-1-hch@lst.de> References: <20240429044917.1504566-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Accessing if_bytes without the ilock is racy. Remove the initial if_bytes == 0 check in xfs_reflink_end_cow_extent and let ext_iext_lookup_extent fail for this case after we've taken the ilock. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_reflink.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 9ce37d366534c3..0ab2ef5b58f6c4 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -731,12 +731,6 @@ xfs_reflink_end_cow_extent( int nmaps; int error; - /* No COW extents? That's easy! */ - if (ifp->if_bytes == 0) { - *offset_fsb = end_fsb; - return 0; - } - resblks = XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK); error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0, XFS_TRANS_RESERVE, &tp); From patchwork Mon Apr 29 04:49:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13646277 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC9DAC129 for ; Mon, 29 Apr 2024 04:49:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714366171; cv=none; b=DMDaD5UtVzcvf5gXDz1CFIb0rj9VgQsC4eH2FDmWQ0oS1+rDE2a71IMVOPqX0Z0HVxN0lMWgC4/SAiDcMB3ZCv+IFVnCxoYqEF5JkctuLFV0vxkjNpIqsX3iOdoN3lWojbJAqBoDHdFBaQXyE9CF2kLWEnnSgtWwOVzadW+u2RI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714366171; c=relaxed/simple; bh=ve83gv0X9U2tiW9IMX9OfigUzgJIKdNTd1RdJD3Q7yE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=N2/42ExIf0WTPwphWuSt+qAP4VI+wEOl9h77zoEv4Tgdwxg7J/9QJN61jQX2lyawCLGkYqeAkrk9uxzmdXaR8Zn/VEvmbAZq9LqA7VYIlgDb8geyi8LkISStL+eoJ/V8Rubb/yYNJCHFXnlfdUwqlNZIFBh8v8T+AYFHjeLu3KI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=jWuCMDMR; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="jWuCMDMR" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=hMGWqVK2bA5X5NVVQXVyIdiFvN0d0hPuzmYdi662Byw=; b=jWuCMDMRDTeokYxRSItIP0fqbx u3u9VEb5c0azY6M57EzvxBACYt9wy7yHb5FWgIS3fCZyW3s8KbuoERnELAISJgX67h+1e4qalb0F7 IXtw5IyUZ7idEFF3Nrbs6FCbR1r6h8iz1lNWP8a8Vm5BfCRvC2lxc+AK8P1oMLRXlw3NoLgS3fgGy N95+rzzIW4CXEhmbt9tUpGA6VO8pem9xlckKxh4YmAl1HUmXawqBjXa26CGPjQ2RXsAfYdbh7IWRL HTmLglxqlJijCEvu/eY7AeVe7gcITyLyBoFfdQBGJcpulmHSvpJbBuTrvcMgeyIMrgt9LWoi+Yv0+ mimNGHzA==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1IxF-00000001S5c-0Vg0; Mon, 29 Apr 2024 04:49:29 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 3/8] xfs: consolidate the xfs_quota_reserve_blkres definitions Date: Mon, 29 Apr 2024 06:49:12 +0200 Message-Id: <20240429044917.1504566-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240429044917.1504566-1-hch@lst.de> References: <20240429044917.1504566-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html xfs_trans_reserve_quota_nblks is already stubbed out if quota support is disabled, no need for an extra xfs_quota_reserve_blkres stub. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_quota.h | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/fs/xfs/xfs_quota.h b/fs/xfs/xfs_quota.h index 85a4ae1a17f672..621ea9d7cf06d9 100644 --- a/fs/xfs/xfs_quota.h +++ b/fs/xfs/xfs_quota.h @@ -123,12 +123,6 @@ extern int xfs_qm_newmount(struct xfs_mount *, uint *, uint *); extern void xfs_qm_mount_quotas(struct xfs_mount *); extern void xfs_qm_unmount(struct xfs_mount *); extern void xfs_qm_unmount_quotas(struct xfs_mount *); - -static inline int -xfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t blocks) -{ - return xfs_trans_reserve_quota_nblks(NULL, ip, blocks, 0, false); -} bool xfs_inode_near_dquot_enforcement(struct xfs_inode *ip, xfs_dqtype_t type); # ifdef CONFIG_XFS_LIVE_HOOKS @@ -187,12 +181,6 @@ static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp, return 0; } -static inline int -xfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t blocks) -{ - return 0; -} - static inline int xfs_trans_reserve_quota_icreate(struct xfs_trans *tp, struct xfs_dquot *udqp, struct xfs_dquot *gdqp, struct xfs_dquot *pdqp, int64_t dblocks) @@ -221,6 +209,12 @@ xfs_trans_reserve_quota_icreate(struct xfs_trans *tp, struct xfs_dquot *udqp, #endif /* CONFIG_XFS_QUOTA */ +static inline int +xfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t blocks) +{ + return xfs_trans_reserve_quota_nblks(NULL, ip, blocks, 0, false); +} + static inline int xfs_quota_unreserve_blkres(struct xfs_inode *ip, int64_t blocks) { From patchwork Mon Apr 29 04:49:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13646278 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5D6DC129 for ; Mon, 29 Apr 2024 04:49:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714366174; cv=none; b=hw4WkSK0X0liqm+rEfIa8Soz/kbCBJdG61VLhTT8AbfV8q7ZPorRL0C9dVFnBixVFzHbM9M6rkIfRgj9Jqo6tKuzItW/QSrY4MTYEVpf6IanfMciMHu7XfRll5rHpVtah/PUToO8IcFvDNCNThzh1Dt7t/RjqLdnRXr1XXLJ/rI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714366174; c=relaxed/simple; bh=MYPKpRjr2tEmgjaGyfFvyFr0eJsUcAizeFf5h4kpJgA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=N71in0VC0phrfI/u5lN22xJfv45DEkWaeX1g/pkbGFmHa5jJqf/0AzJMMN05BHhQzGnOHjIMfBLnFgbuiFVHj/NBF4APun9B2xTntEWw298zpPzf29EbUHLH6CWlpPml+TvHWKBfTBt/iN2ciEYH+Rmbgtwm8yxYSd58cL5uBSU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=w5Ea+igo; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="w5Ea+igo" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=3Z5+T7kOErBqtVxWrddxmziOfA2uoA4Jlc1yiWH2CxQ=; b=w5Ea+igo9pZx318Mh1r1sqvQV+ IhcUhORARr8x3PzcKyikHyAxmmr5YVPaZ1T2teDaSLpSq9dYR2ncZ14CbM69AQtcpRBH5R8DAOW+p irBMBJViSViTixNHayHgGYMtnYFHtc/cCz//MC2on9HcEtY5sIebJhs+hWpaWGclQj0cs+UjGfhHf lQz+lxpbkAp9BVmOZzNllSB6lUBjSpxyBthjYFnPuoETQkKFzwWxe1gO63j+u/FMBDKCzHiNPocE+ WeKu878UmOHrpVLiTscmGRwp/CPJe/ZzeFADKw2M9FdFwrN/ggCfCG83EV3gd7O6dfUnSJ5LQ0rvM m3djJDAA==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1IxH-00000001S5x-3ZxE; Mon, 29 Apr 2024 04:49:32 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 4/8] xfs: xfs_quota_unreserve_blkres can't fail Date: Mon, 29 Apr 2024 06:49:13 +0200 Message-Id: <20240429044917.1504566-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240429044917.1504566-1-hch@lst.de> References: <20240429044917.1504566-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Unreserving quotas can't fail due to quota limits, and we'll notice a shut down file system a bit later in all the callers anyway. Return void and remove the error checking and propagation in the callers. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_bmap.c | 16 +++++----------- fs/xfs/libxfs/xfs_bmap.h | 2 +- fs/xfs/xfs_aops.c | 6 +----- fs/xfs/xfs_bmap_util.c | 9 +++------ fs/xfs/xfs_bmap_util.h | 2 +- fs/xfs/xfs_iomap.c | 4 ++-- fs/xfs/xfs_quota.h | 7 ++++--- fs/xfs/xfs_reflink.c | 11 +++-------- 8 files changed, 20 insertions(+), 37 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 6053f5e5c71eec..68e80e8eaaeebe 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -4870,7 +4870,7 @@ xfs_bmap_split_indlen( *indlen2 = len2; } -int +void xfs_bmap_del_extent_delay( struct xfs_inode *ip, int whichfork, @@ -4886,7 +4886,6 @@ xfs_bmap_del_extent_delay( xfs_filblks_t got_indlen, new_indlen, stolen = 0; uint32_t state = xfs_bmap_fork_to_state(whichfork); uint64_t fdblocks; - int error = 0; bool isrt; XFS_STATS_INC(mp, xs_del_exlist); @@ -4906,9 +4905,7 @@ xfs_bmap_del_extent_delay( * sb counters as we might have to borrow some blocks for the * indirect block accounting. */ - error = xfs_quota_unreserve_blkres(ip, del->br_blockcount); - if (error) - return error; + xfs_quota_unreserve_blkres(ip, del->br_blockcount); ip->i_delayed_blks -= del->br_blockcount; if (got->br_startoff == del->br_startoff) @@ -5006,7 +5003,6 @@ xfs_bmap_del_extent_delay( xfs_add_fdblocks(mp, fdblocks); xfs_mod_delalloc(ip, -(int64_t)del->br_blockcount, -da_diff); - return error; } void @@ -5564,18 +5560,16 @@ __xfs_bunmapi( delete: if (wasdel) { - error = xfs_bmap_del_extent_delay(ip, whichfork, &icur, - &got, &del); + xfs_bmap_del_extent_delay(ip, whichfork, &icur, &got, &del); } else { error = xfs_bmap_del_extent_real(ip, tp, &icur, cur, &del, &tmp_logflags, whichfork, flags); logflags |= tmp_logflags; + if (error) + goto error0; } - if (error) - goto error0; - end = del.br_startoff - 1; nodelete: /* diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h index e98849eb9bbae3..667b0c2b33d1d5 100644 --- a/fs/xfs/libxfs/xfs_bmap.h +++ b/fs/xfs/libxfs/xfs_bmap.h @@ -202,7 +202,7 @@ int xfs_bmapi_write(struct xfs_trans *tp, struct xfs_inode *ip, int xfs_bunmapi(struct xfs_trans *tp, struct xfs_inode *ip, xfs_fileoff_t bno, xfs_filblks_t len, uint32_t flags, xfs_extnum_t nexts, int *done); -int xfs_bmap_del_extent_delay(struct xfs_inode *ip, int whichfork, +void xfs_bmap_del_extent_delay(struct xfs_inode *ip, int whichfork, struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *got, struct xfs_bmbt_irec *del); void xfs_bmap_del_extent_cow(struct xfs_inode *ip, diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 3f428620ebf2a3..c51bc17f5cfa03 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -469,7 +469,6 @@ xfs_discard_folio( { struct xfs_inode *ip = XFS_I(folio->mapping->host); struct xfs_mount *mp = ip->i_mount; - int error; if (xfs_is_shutdown(mp)) return; @@ -483,11 +482,8 @@ xfs_discard_folio( * byte of the next folio. Hence the end offset is only dependent on the * folio itself and not the start offset that is passed in. */ - error = xfs_bmap_punch_delalloc_range(ip, pos, + xfs_bmap_punch_delalloc_range(ip, pos, folio_pos(folio) + folio_size(folio)); - - if (error && !xfs_is_shutdown(mp)) - xfs_alert(mp, "page discard unable to remove delalloc mapping."); } static const struct iomap_writeback_ops xfs_writeback_ops = { diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 53aa90a0ee3a85..df370d7112dc54 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -440,7 +440,7 @@ xfs_getbmap( * if the ranges only partially overlap them, so it is up to the caller to * ensure that partial blocks are not passed in. */ -int +void xfs_bmap_punch_delalloc_range( struct xfs_inode *ip, xfs_off_t start_byte, @@ -452,7 +452,6 @@ xfs_bmap_punch_delalloc_range( xfs_fileoff_t end_fsb = XFS_B_TO_FSB(mp, end_byte); struct xfs_bmbt_irec got, del; struct xfs_iext_cursor icur; - int error = 0; ASSERT(!xfs_need_iread_extents(ifp)); @@ -476,15 +475,13 @@ xfs_bmap_punch_delalloc_range( continue; } - error = xfs_bmap_del_extent_delay(ip, XFS_DATA_FORK, &icur, - &got, &del); - if (error || !xfs_iext_get_extent(ifp, &icur, &got)) + xfs_bmap_del_extent_delay(ip, XFS_DATA_FORK, &icur, &got, &del); + if (!xfs_iext_get_extent(ifp, &icur, &got)) break; } out_unlock: xfs_iunlock(ip, XFS_ILOCK_EXCL); - return error; } /* diff --git a/fs/xfs/xfs_bmap_util.h b/fs/xfs/xfs_bmap_util.h index 77ecbb753ef207..51f84d8ff372fa 100644 --- a/fs/xfs/xfs_bmap_util.h +++ b/fs/xfs/xfs_bmap_util.h @@ -30,7 +30,7 @@ xfs_bmap_rtalloc(struct xfs_bmalloca *ap) } #endif /* CONFIG_XFS_RT */ -int xfs_bmap_punch_delalloc_range(struct xfs_inode *ip, +void xfs_bmap_punch_delalloc_range(struct xfs_inode *ip, xfs_off_t start_byte, xfs_off_t end_byte); struct kgetbmap { diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 9ce0f6b9df93e6..c06fca2e751c7c 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -1211,8 +1211,8 @@ xfs_buffered_write_delalloc_punch( loff_t offset, loff_t length) { - return xfs_bmap_punch_delalloc_range(XFS_I(inode), offset, - offset + length); + xfs_bmap_punch_delalloc_range(XFS_I(inode), offset, offset + length); + return 0; } static int diff --git a/fs/xfs/xfs_quota.h b/fs/xfs/xfs_quota.h index 621ea9d7cf06d9..23d71a55bbc006 100644 --- a/fs/xfs/xfs_quota.h +++ b/fs/xfs/xfs_quota.h @@ -215,10 +215,11 @@ xfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t blocks) return xfs_trans_reserve_quota_nblks(NULL, ip, blocks, 0, false); } -static inline int -xfs_quota_unreserve_blkres(struct xfs_inode *ip, int64_t blocks) +static inline void +xfs_quota_unreserve_blkres(struct xfs_inode *ip, uint64_t blocks) { - return xfs_quota_reserve_blkres(ip, -blocks); + /* don't return an error as unreserving quotas can't fail */ + xfs_quota_reserve_blkres(ip, -(int64_t)blocks); } extern int xfs_mount_reset_sbqflags(struct xfs_mount *); diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 0ab2ef5b58f6c4..02cb6c2b257058 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -606,10 +606,8 @@ xfs_reflink_cancel_cow_blocks( trace_xfs_reflink_cancel_cow(ip, &del); if (isnullstartblock(del.br_startblock)) { - error = xfs_bmap_del_extent_delay(ip, XFS_COW_FORK, - &icur, &got, &del); - if (error) - break; + xfs_bmap_del_extent_delay(ip, XFS_COW_FORK, &icur, &got, + &del); } else if (del.br_state == XFS_EXT_UNWRITTEN || cancel_real) { ASSERT((*tpp)->t_highest_agno == NULLAGNUMBER); @@ -632,10 +630,7 @@ xfs_reflink_cancel_cow_blocks( xfs_bmap_del_extent_cow(ip, &icur, &got, &del); /* Remove the quota reservation */ - error = xfs_quota_unreserve_blkres(ip, - del.br_blockcount); - if (error) - break; + xfs_quota_unreserve_blkres(ip, del.br_blockcount); } else { /* Didn't do anything, push cursor back. */ xfs_iext_prev(ifp, &icur); From patchwork Mon Apr 29 04:49:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13646279 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1097CD28D for ; Mon, 29 Apr 2024 04:49:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714366176; cv=none; b=sTiNCVQvLJ1F9b56HNUAJrzS+wzSkZ2uHNbiQr+5ijCIcGleNRIfIL/fbh84E6C9sbrH5WALQqMm9Xx7QxV4mELB/qpBVYtGbPobRFKV5T5Z3Hsl/dB1SQ3XYELZ1ojaVr9/fLxJSQpnohcbORVEJLC4rvByDznVsO+BHb31lrU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714366176; c=relaxed/simple; bh=vYPJzDhtJrQ4GqbUFLnFxal4ZS2ZJ1kQnnZZd9Uw98o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eVUmhoj8R6U1iXYg712zD90e7VDKqCIGA+Ugzq15SJSWBD18KvUt9guMeLj4T2ywAURlzp7PEQVWvktCFN0AZEoKt6BycD/HXk9k62Iu8yPbyXEg5fU1gHfphXyi5ABNanQGB8UcKufdaYU8+8qXcfSSXaKdL2PIKYzf3JLc/zs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=UOnwUiZi; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="UOnwUiZi" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=fcOT4wJJ3e74OZATUKDXVm07h2YoLmukK07PhSiXTNY=; b=UOnwUiZivKiABrtihWdkVC5nuo G/CcRKdbLNk6EyzGKdpvhfsBUSqgL0A3KJZLWogEPzOffmiAxtMXkxfcqSdru9g237ocLhI20HTvI pOgDJA3coNDhCSk1BPMYsX77eumZyCrwnl3n2tyofIvMd9UZtdzrNn0uHCqS0pNuu8FtRxHURoyux veUhpNGywnREK+Ugur6xtu5ApMGsoRt6Qy6hgW/7MaDZ0b6zE7i4xrBNpw0YDmbuNuvexuwyyZMoF 5XUwOmoEXzuIMYIzskq86IUGUf+rh5UhyJzYf/VkdzbZ2ZOc5b18g/261OMVt74ImhbAqXGVcD31c LMj+sDhA==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1IxK-00000001S6b-13rS; Mon, 29 Apr 2024 04:49:34 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 5/8] xfs: simplify iext overflow checking and upgrade Date: Mon, 29 Apr 2024 06:49:14 +0200 Message-Id: <20240429044917.1504566-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240429044917.1504566-1-hch@lst.de> References: <20240429044917.1504566-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Currently the calls to xfs_iext_count_may_overflow and xfs_iext_count_upgrade are always paired. Merge them into a single function to simplify the callers and the actual check and upgrade logic itself. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_attr.c | 5 +-- fs/xfs/libxfs/xfs_bmap.c | 5 +-- fs/xfs/libxfs/xfs_inode_fork.c | 57 +++++++++++++++------------------- fs/xfs/libxfs/xfs_inode_fork.h | 6 ++-- fs/xfs/xfs_bmap_item.c | 4 +-- fs/xfs/xfs_bmap_util.c | 24 +++----------- fs/xfs/xfs_dquot.c | 5 +-- fs/xfs/xfs_iomap.c | 9 ++---- fs/xfs/xfs_reflink.c | 9 ++---- fs/xfs/xfs_rtalloc.c | 5 +-- 10 files changed, 41 insertions(+), 88 deletions(-) diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c index 1c2a27fce08a9d..ded92ccefe9f6d 100644 --- a/fs/xfs/libxfs/xfs_attr.c +++ b/fs/xfs/libxfs/xfs_attr.c @@ -1050,11 +1050,8 @@ xfs_attr_set( return error; if (op != XFS_ATTRUPDATE_REMOVE || xfs_inode_hasattr(dp)) { - error = xfs_iext_count_may_overflow(dp, XFS_ATTR_FORK, + error = xfs_iext_count_ensure(args->trans, dp, XFS_ATTR_FORK, XFS_IEXT_ATTR_MANIP_CNT(rmt_blks)); - if (error == -EFBIG) - error = xfs_iext_count_upgrade(args->trans, dp, - XFS_IEXT_ATTR_MANIP_CNT(rmt_blks)); if (error) goto out_trans_cancel; } diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 68e80e8eaaeebe..9a55ce4f1f0d45 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -4621,11 +4621,8 @@ xfs_bmapi_convert_delalloc( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); - error = xfs_iext_count_may_overflow(ip, whichfork, + error = xfs_iext_count_ensure(tp, ip, whichfork, XFS_IEXT_ADD_NOSPLIT_CNT); - if (error == -EFBIG) - error = xfs_iext_count_upgrade(tp, ip, - XFS_IEXT_ADD_NOSPLIT_CNT); if (error) goto out_trans_cancel; diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index 7d660a9739090a..82e670dd1212c4 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -765,53 +765,46 @@ xfs_ifork_verify_local_attr( return 0; } +/* + * Check if the inode fork supports adding nr_to_add more extents. + * + * If it doesn't but we can upgrade it to large extent counters, do the upgrade. + * If we can't upgrade or are already using big counters but still can't fit the + * additional extents, return -EFBIG. + */ int -xfs_iext_count_may_overflow( +xfs_iext_count_ensure( + struct xfs_trans *tp, struct xfs_inode *ip, int whichfork, - int nr_to_add) + uint nr_to_add) { + struct xfs_mount *mp = ip->i_mount; + bool has_large = + xfs_inode_has_large_extent_counts(ip); struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); - uint64_t max_exts; uint64_t nr_exts; + ASSERT(nr_to_add <= XFS_MAX_EXTCNT_UPGRADE_NR); + if (whichfork == XFS_COW_FORK) return 0; - max_exts = xfs_iext_max_nextents(xfs_inode_has_large_extent_counts(ip), - whichfork); - - if (XFS_TEST_ERROR(false, ip->i_mount, XFS_ERRTAG_REDUCE_MAX_IEXTENTS)) - max_exts = 10; - + /* no point in upgrading if if_nextents overflows */ nr_exts = ifp->if_nextents + nr_to_add; - if (nr_exts < ifp->if_nextents || nr_exts > max_exts) + if (nr_exts < ifp->if_nextents) return -EFBIG; - return 0; -} - -/* - * Upgrade this inode's extent counter fields to be able to handle a potential - * increase in the extent count by nr_to_add. Normally this is the same - * quantity that caused xfs_iext_count_may_overflow() to return -EFBIG. - */ -int -xfs_iext_count_upgrade( - struct xfs_trans *tp, - struct xfs_inode *ip, - uint nr_to_add) -{ - ASSERT(nr_to_add <= XFS_MAX_EXTCNT_UPGRADE_NR); - - if (!xfs_has_large_extent_counts(ip->i_mount) || - xfs_inode_has_large_extent_counts(ip) || - XFS_TEST_ERROR(false, ip->i_mount, XFS_ERRTAG_REDUCE_MAX_IEXTENTS)) + if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_REDUCE_MAX_IEXTENTS) && + nr_exts > 10) return -EFBIG; - ip->i_diflags2 |= XFS_DIFLAG2_NREXT64; - xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); - + if (nr_exts > xfs_iext_max_nextents(has_large, whichfork)) { + if (has_large || !xfs_has_large_extent_counts(mp)) + return -EFBIG; + ip->i_diflags2 |= XFS_DIFLAG2_NREXT64; + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); + } return 0; } diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index bd53eb951b6515..9e1456f5cc2c85 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -256,10 +256,8 @@ extern void xfs_ifork_init_cow(struct xfs_inode *ip); int xfs_ifork_verify_local_data(struct xfs_inode *ip); int xfs_ifork_verify_local_attr(struct xfs_inode *ip); -int xfs_iext_count_may_overflow(struct xfs_inode *ip, int whichfork, - int nr_to_add); -int xfs_iext_count_upgrade(struct xfs_trans *tp, struct xfs_inode *ip, - uint nr_to_add); +int xfs_iext_count_ensure(struct xfs_trans *tp, struct xfs_inode *ip, + int whichfork, uint nr_to_add); bool xfs_ifork_is_realtime(struct xfs_inode *ip, int whichfork); /* returns true if the fork has extents but they are not read in yet. */ diff --git a/fs/xfs/xfs_bmap_item.c b/fs/xfs/xfs_bmap_item.c index d27859a684aa69..38067d02ee3ca7 100644 --- a/fs/xfs/xfs_bmap_item.c +++ b/fs/xfs/xfs_bmap_item.c @@ -524,9 +524,7 @@ xfs_bmap_recover_work( else iext_delta = XFS_IEXT_PUNCH_HOLE_CNT; - error = xfs_iext_count_may_overflow(ip, work->bi_whichfork, iext_delta); - if (error == -EFBIG) - error = xfs_iext_count_upgrade(tp, ip, iext_delta); + error = xfs_iext_count_ensure(tp, ip, work->bi_whichfork, iext_delta); if (error) goto err_cancel; diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index df370d7112dc54..cad3b3e4f1c33e 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -710,11 +710,8 @@ xfs_alloc_file_space( if (error) break; - error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + error = xfs_iext_count_ensure(tp, ip, XFS_DATA_FORK, XFS_IEXT_ADD_NOSPLIT_CNT); - if (error == -EFBIG) - error = xfs_iext_count_upgrade(tp, ip, - XFS_IEXT_ADD_NOSPLIT_CNT); if (error) goto error; @@ -772,10 +769,8 @@ xfs_unmap_extent( if (error) return error; - error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + error = xfs_iext_count_ensure(tp, ip, XFS_DATA_FORK, XFS_IEXT_PUNCH_HOLE_CNT); - if (error == -EFBIG) - error = xfs_iext_count_upgrade(tp, ip, XFS_IEXT_PUNCH_HOLE_CNT); if (error) goto out_trans_cancel; @@ -1051,10 +1046,8 @@ xfs_insert_file_space( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); - error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + error = xfs_iext_count_ensure(tp, ip, XFS_DATA_FORK, XFS_IEXT_PUNCH_HOLE_CNT); - if (error == -EFBIG) - error = xfs_iext_count_upgrade(tp, ip, XFS_IEXT_PUNCH_HOLE_CNT); if (error) goto out_trans_cancel; @@ -1280,23 +1273,16 @@ xfs_swap_extent_rmap( trace_xfs_swap_extent_rmap_remap_piece(tip, &uirec); if (xfs_bmap_is_real_extent(&uirec)) { - error = xfs_iext_count_may_overflow(ip, - XFS_DATA_FORK, + error = xfs_iext_count_ensure(tp, ip, XFS_DATA_FORK, XFS_IEXT_SWAP_RMAP_CNT); - if (error == -EFBIG) - error = xfs_iext_count_upgrade(tp, ip, - XFS_IEXT_SWAP_RMAP_CNT); if (error) goto out; } if (xfs_bmap_is_real_extent(&irec)) { - error = xfs_iext_count_may_overflow(tip, + error = xfs_iext_count_ensure(tp, tip, XFS_DATA_FORK, XFS_IEXT_SWAP_RMAP_CNT); - if (error == -EFBIG) - error = xfs_iext_count_upgrade(tp, ip, - XFS_IEXT_SWAP_RMAP_CNT); if (error) goto out; } diff --git a/fs/xfs/xfs_dquot.c b/fs/xfs/xfs_dquot.c index 13aba84bd64afb..c2e66d392399dd 100644 --- a/fs/xfs/xfs_dquot.c +++ b/fs/xfs/xfs_dquot.c @@ -341,11 +341,8 @@ xfs_dquot_disk_alloc( goto err_cancel; } - error = xfs_iext_count_may_overflow(quotip, XFS_DATA_FORK, + error = xfs_iext_count_ensure(tp, quotip, XFS_DATA_FORK, XFS_IEXT_ADD_NOSPLIT_CNT); - if (error == -EFBIG) - error = xfs_iext_count_upgrade(tp, quotip, - XFS_IEXT_ADD_NOSPLIT_CNT); if (error) goto err_cancel; diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index c06fca2e751c7c..128ad834ca69b1 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -299,9 +299,7 @@ xfs_iomap_write_direct( if (error) return error; - error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, nr_exts); - if (error == -EFBIG) - error = xfs_iext_count_upgrade(tp, ip, nr_exts); + error = xfs_iext_count_ensure(tp, ip, XFS_DATA_FORK, nr_exts); if (error) goto out_trans_cancel; @@ -625,11 +623,8 @@ xfs_iomap_write_unwritten( if (error) return error; - error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + error = xfs_iext_count_ensure(tp, ip, XFS_DATA_FORK, XFS_IEXT_WRITE_UNWRITTEN_CNT); - if (error == -EFBIG) - error = xfs_iext_count_upgrade(tp, ip, - XFS_IEXT_WRITE_UNWRITTEN_CNT); if (error) goto error_on_bmapi_transaction; diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 02cb6c2b257058..af388f2caef304 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -768,11 +768,8 @@ xfs_reflink_end_cow_extent( del = got; xfs_trim_extent(&del, *offset_fsb, end_fsb - *offset_fsb); - error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + error = xfs_iext_count_ensure(tp, ip, XFS_DATA_FORK, XFS_IEXT_REFLINK_END_COW_CNT); - if (error == -EFBIG) - error = xfs_iext_count_upgrade(tp, ip, - XFS_IEXT_REFLINK_END_COW_CNT); if (error) goto out_cancel; @@ -1272,9 +1269,7 @@ xfs_reflink_remap_extent( if (dmap_written) ++iext_delta; - error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, iext_delta); - if (error == -EFBIG) - error = xfs_iext_count_upgrade(tp, ip, iext_delta); + error = xfs_iext_count_ensure(tp, ip, XFS_DATA_FORK, iext_delta); if (error) goto out_cancel; diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index b476a876478d93..37edf4c5ce73ad 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -695,11 +695,8 @@ xfs_growfs_rt_alloc( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); - error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, + error = xfs_iext_count_ensure(tp, ip, XFS_DATA_FORK, XFS_IEXT_ADD_NOSPLIT_CNT); - if (error == -EFBIG) - error = xfs_iext_count_upgrade(tp, ip, - XFS_IEXT_ADD_NOSPLIT_CNT); if (error) goto out_trans_cancel; From patchwork Mon Apr 29 04:49:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13646280 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AA25D28D for ; Mon, 29 Apr 2024 04:49:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714366179; cv=none; b=jLta9xlIH9IIra0gVs6ZFToiW/gfsFbDqDAPEp6ReXpsLZxO4cpqyK4mBD86Me1bdIhm0Oah3cCc1kC24oUtNvvtj3IGJ+LOAkXhaN/e/DipFwjvUvJD0EHMGUPZNo1705nja3eDqmIL8nAh1Vkucu4qcyO29l2Ff+pOQvt6NrU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714366179; c=relaxed/simple; bh=sA13kw9FhD7gMvhsQfQNyymdnJAdif4ycdypkUsM61M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jTyTVoh55XVIx6xalotdbIF1qlE6S0+F98BktrJ4SB0READhjwKA7RKkHbisM37f3FBYdCHF9y+CjEwfEedyHxA9s0XTK8JEntVIKFs6WICRvojq5fMdU41mr7waz5bV65mrBrw2gM9wVkBfE/9RRBVe9zcZnp7yRsveUD8TtmU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=xLGoR9s/; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="xLGoR9s/" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=+tWV+bp6iGWTVnLeA5oPjcqfEgPGbJauCznjmy4+A6U=; b=xLGoR9s/6EnoqMwdDpO1HYP8sJ iwl0O9hPXR/Y/jqsU2na5OHaiXXRDkLcnmQjG/BA0sPjw97XJ2zmYVE3syAmBD3b7Q++gOitsTAzN GT0jP2i/UyIeC0Lqnkaw/5JMczTpx9YAQHWv6aOk8yBPArUg0a0wZqkFA8TMAbmuLyopgBPJNuksZ ejxfmrWnG9M2Up79Ybey6JX+cRmUGSSjEyroxl36KU4FosoUxGZKia073ZeDN5SeUFqqFtBX71/Lr q3nE/BhUJOrRP44Y2LLvSIH3LKPL8iZ1TDnohkOgOLv9EkyArkkHCTl+vG0lrrBx3aPnXmAJ0zaaK rQ23z3hw==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1IxM-00000001S7g-3hVt; Mon, 29 Apr 2024 04:49:37 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 6/8] xfs: lift XREP_MAX_ITRUNCATE_EFIS out of the scrub code Date: Mon, 29 Apr 2024 06:49:15 +0200 Message-Id: <20240429044917.1504566-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240429044917.1504566-1-hch@lst.de> References: <20240429044917.1504566-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html We want to play the same trick in the COW end I/O handler, so lift this constant out of the scrub directory and change the prefix to XFS_. Signed-off-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_trans_resv.h | 7 +++++++ fs/xfs/scrub/newbt.c | 2 +- fs/xfs/scrub/reap.c | 2 +- fs/xfs/scrub/repair.h | 8 -------- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/fs/xfs/libxfs/xfs_trans_resv.h b/fs/xfs/libxfs/xfs_trans_resv.h index 0554b9d775d269..51eb56560ee189 100644 --- a/fs/xfs/libxfs/xfs_trans_resv.h +++ b/fs/xfs/libxfs/xfs_trans_resv.h @@ -95,6 +95,13 @@ struct xfs_trans_resv { #define XFS_ITRUNCATE_LOG_COUNT_REFLINK 8 #define XFS_WRITE_LOG_COUNT_REFLINK 8 +/* + * This is the maximum number of deferred extent freeing item extents (EFIs) + * that we'll attach to a transaction without rolling the transaction to avoid + * overrunning a tr_itruncate reservation. + */ +#define XFS_MAX_ITRUNCATE_EFIS 128 + void xfs_trans_resv_calc(struct xfs_mount *mp, struct xfs_trans_resv *resp); uint xfs_allocfree_block_count(struct xfs_mount *mp, uint num_ops); diff --git a/fs/xfs/scrub/newbt.c b/fs/xfs/scrub/newbt.c index 4a0271123d94ea..872f97db2a6425 100644 --- a/fs/xfs/scrub/newbt.c +++ b/fs/xfs/scrub/newbt.c @@ -452,7 +452,7 @@ xrep_newbt_free( } freed += ret; - if (freed >= XREP_MAX_ITRUNCATE_EFIS) { + if (freed >= XFS_MAX_ITRUNCATE_EFIS) { error = xrep_defer_finish(sc); if (error) goto junkit; diff --git a/fs/xfs/scrub/reap.c b/fs/xfs/scrub/reap.c index 01ceaa4efa16bf..433891b0d08c73 100644 --- a/fs/xfs/scrub/reap.c +++ b/fs/xfs/scrub/reap.c @@ -169,7 +169,7 @@ static inline bool xreap_want_roll(const struct xreap_state *rs) { if (rs->force_roll) return true; - if (rs->deferred > XREP_MAX_ITRUNCATE_EFIS) + if (rs->deferred > XFS_MAX_ITRUNCATE_EFIS) return true; if (rs->invalidated > XREAP_MAX_BINVAL) return true; diff --git a/fs/xfs/scrub/repair.h b/fs/xfs/scrub/repair.h index 0e0dc2bf985c21..ec76774afffb31 100644 --- a/fs/xfs/scrub/repair.h +++ b/fs/xfs/scrub/repair.h @@ -17,14 +17,6 @@ static inline int xrep_notsupported(struct xfs_scrub *sc) #ifdef CONFIG_XFS_ONLINE_REPAIR -/* - * This is the maximum number of deferred extent freeing item extents (EFIs) - * that we'll attach to a transaction without rolling the transaction to avoid - * overrunning a tr_itruncate reservation. - */ -#define XREP_MAX_ITRUNCATE_EFIS (128) - - /* Repair helpers */ int xrep_attempt(struct xfs_scrub *sc, struct xchk_stats_run *run); From patchwork Mon Apr 29 04:49:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13646281 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66DCCD28D for ; Mon, 29 Apr 2024 04:49:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714366182; cv=none; b=MUoY8VPWpo3s6eLKxGmwWo6i01nq1rSYyA5YyQPKvSrmSFVHFC5pCwb/eTBsn9DzKVxLk2SrtQmQcZnf6kx6LCr/chwen67B59sjTde61bCMp8DeMFNdwKTwmx0238aSqvtiPxWOqnAl1aiFy4ay5aqWuW0Y7OJPSs7X4Vhbxf4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714366182; c=relaxed/simple; bh=f/aDShJ4RfjDQeyCaMlJQHoA5dgZUg85hXaTF+/om/k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=On68FyL5MJ5DER7zkD99T1Y4U7itb8eRNvz6x91dGmno5KYNbzO6N2WafLnl5rj1erwGQ5qaNQQR+7Nq0TjH3rrWGXxTNSCaf2M5vbap7uNhG8T6D+DNcqou4VZclWweErf87cRZDEZCSuHeBd6wU2GKJovEJYq/ciX4b4cYDKQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=C/zjNTYJ; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="C/zjNTYJ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=oRJMxDwQJjMLMfL7zqflS9KyLDDWex73oKIF33Jnt0k=; b=C/zjNTYJ9nR0IbzgyLVNlqaPXA ujqgJgqnfLm/MR1SAgOXfRSf2thzM2nTXFER/WjwJblqeLi1ypows+WXJCkW7or3ANqvVeqhxGpww Q75LQDUavbQlub50LIf/FhG0Knn4LOmmCerpws2/HO7KdzAUHP+fFT1zGkVbOrC6UrCwCZfV1EK1p mr1AdmXAZv5UpocMAFo3Ghb3jLTj9Spgwe07gTzVwTvvX3rjflusY3pOQNTUCvanpfKyis+HIQ1PH SdbF3oXQ3FMNQMqWeylXr72VWIv5/0qU9g8UEvBx7w6TazD6eIK7Lm7IbcZWhG3x5dzJWt5dzRSE+ YsOmnwrw==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1IxQ-00000001S8X-2e2a; Mon, 29 Apr 2024 04:49:41 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 7/8] xfs: optimize extent remapping in xfs_reflink_end_cow_extent Date: Mon, 29 Apr 2024 06:49:16 +0200 Message-Id: <20240429044917.1504566-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240429044917.1504566-1-hch@lst.de> References: <20240429044917.1504566-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html xfs_reflink_end_cow_extent currently caps the range it works on to fit both the existing extent (or hole) in the data fork and the new COW range. For overwrites of fragmented regions that is highly inefficient, as we need to split the new region at every boundary, just for it to be merge back in the next pass. Switch to unmapping the old data using a chain of deferred bmap and extent free ops ops first, and then handle remapping the new data in one single transaction instead. Note that this also switches from a write to an itruncate transaction reservation as the xfs_reflink_end_cow_extent doesn't touch any of the allocator data structures in the AGF or the RT inodes. Instead the lead transaction just unmaps blocks, and later they get freed, COW records get freed and the new blocks get mapped into the inode. Signed-off-by: Christoph Hellwig --- fs/xfs/xfs_reflink.c | 111 ++++++++++++++++++++++++++++--------------- 1 file changed, 72 insertions(+), 39 deletions(-) diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index af388f2caef304..e20db39d1cc46f 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -701,6 +701,72 @@ xfs_reflink_cancel_cow_range( return error; } +/* + * Unmap any old data covering the COW target. + */ +static int +xfs_reflink_unmap_old_data( + struct xfs_trans **tpp, + struct xfs_inode *ip, + xfs_fileoff_t offset_fsb, + xfs_fileoff_t end_fsb) +{ + struct xfs_ifork *ifp = &ip->i_df; + struct xfs_bmbt_irec got, del; + struct xfs_iext_cursor icur; + unsigned int freed; + int error; + + ASSERT(!xfs_need_iread_extents(ifp)); + +restart: + freed = 0; + if (!xfs_iext_lookup_extent_before(ip, ifp, &end_fsb, &icur, &got)) + return 0; + + while (got.br_startoff + got.br_blockcount > offset_fsb) { + del = got; + xfs_trim_extent(&del, offset_fsb, end_fsb - offset_fsb); + + /* Extent delete may have bumped us forward */ + if (!del.br_blockcount) + goto prev_extent; + + trace_xfs_reflink_cow_remap_to(ip, &del); + if (isnullstartblock(del.br_startblock)) { + xfs_bmap_del_extent_delay(ip, XFS_DATA_FORK, &icur, + &got, &del); + goto refresh; + } + + xfs_bmap_unmap_extent(*tpp, ip, XFS_DATA_FORK, &del); + xfs_refcount_decrease_extent(*tpp, &del); + xfs_trans_mod_dquot_byino(*tpp, ip, XFS_TRANS_DQ_BCOUNT, + -del.br_blockcount); + + /* + * We can't add an unlimited number of EFIs and thus deferred + * unmapped items to a transaction. Once we've filled our + * quota roll the transaction, which requires us to restart + * the lookup as the deferred item processing will change the + * iext tree. + */ + if (++freed == XFS_MAX_ITRUNCATE_EFIS) { + error = xfs_defer_finish(tpp); + if (error) + return error; + goto restart; + } +prev_extent: + xfs_iext_prev(ifp, &icur); +refresh: + if (!xfs_iext_get_extent(ifp, &icur, &got)) + break; + } + + return 0; +} + /* * Remap part of the CoW fork into the data fork. * @@ -718,16 +784,15 @@ xfs_reflink_end_cow_extent( xfs_fileoff_t end_fsb) { struct xfs_iext_cursor icur; - struct xfs_bmbt_irec got, del, data; + struct xfs_bmbt_irec got, del; struct xfs_mount *mp = ip->i_mount; struct xfs_trans *tp; struct xfs_ifork *ifp = xfs_ifork_ptr(ip, XFS_COW_FORK); unsigned int resblks; - int nmaps; int error; resblks = XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK); - error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0, + error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, resblks, 0, XFS_TRANS_RESERVE, &tp); if (error) return error; @@ -767,51 +832,19 @@ xfs_reflink_end_cow_extent( } del = got; xfs_trim_extent(&del, *offset_fsb, end_fsb - *offset_fsb); + trace_xfs_reflink_cow_remap_from(ip, &del); error = xfs_iext_count_ensure(tp, ip, XFS_DATA_FORK, XFS_IEXT_REFLINK_END_COW_CNT); if (error) goto out_cancel; - /* Grab the corresponding mapping in the data fork. */ - nmaps = 1; - error = xfs_bmapi_read(ip, del.br_startoff, del.br_blockcount, &data, - &nmaps, 0); + /* Unmap the old data. */ + error = xfs_reflink_unmap_old_data(&tp, ip, del.br_startoff, + del.br_startoff + del.br_blockcount); if (error) goto out_cancel; - /* We can only remap the smaller of the two extent sizes. */ - data.br_blockcount = min(data.br_blockcount, del.br_blockcount); - del.br_blockcount = data.br_blockcount; - - trace_xfs_reflink_cow_remap_from(ip, &del); - trace_xfs_reflink_cow_remap_to(ip, &data); - - if (xfs_bmap_is_real_extent(&data)) { - /* - * If the extent we're remapping is backed by storage (written - * or not), unmap the extent and drop its refcount. - */ - xfs_bmap_unmap_extent(tp, ip, XFS_DATA_FORK, &data); - xfs_refcount_decrease_extent(tp, &data); - xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, - -data.br_blockcount); - } else if (data.br_startblock == DELAYSTARTBLOCK) { - int done; - - /* - * If the extent we're remapping is a delalloc reservation, - * we can use the regular bunmapi function to release the - * incore state. Dropping the delalloc reservation takes care - * of the quota reservation for us. - */ - error = xfs_bunmapi(NULL, ip, data.br_startoff, - data.br_blockcount, 0, 1, &done); - if (error) - goto out_cancel; - ASSERT(done); - } - /* Free the CoW orphan record. */ xfs_refcount_free_cow_extent(tp, del.br_startblock, del.br_blockcount); From patchwork Mon Apr 29 04:49:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13646282 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E35EED534 for ; Mon, 29 Apr 2024 04:49:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714366185; cv=none; b=kcjl9a12X/dWaW+RFE7tl7Q7ThkcRHxqTSqv9lRKBvoF4xYAIH5NI1APHVjYcRQ3din6geaW6BRA6hHnlOub/jgLva+hVufLVZDQbaKUn4nOKw13SRxvDVRRQ9WWqKxeIODEbT8p4+syHPVI2uQ3u+DaNVdqq4+RE3Krn/jAr+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714366185; c=relaxed/simple; bh=1UtKFrmTo1DCO4xEHPFaxfavne6zXLHyjmkrZK0YBbE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GLeIXr/NjoG8XIPhGaD7pEA6wPAwx3uGiiL3aBS1e7xwXSVi72iVa3APoM5F7lb70km5XSyp2+8BHdnlD5D3uptsQl20XM+t4t0WtK3QvorFd91abjOK5JKEX3d0yHqnbuomfiYRhD/QnR0nlD+BxU38vrmIk+MKTOSTSO1utZo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=c7Zs/0y2; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="c7Zs/0y2" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=2LBnwVJWyfdi8kgWchXm5CVyxntrtaHrqVXkEUlOdrA=; b=c7Zs/0y23+qAW0jAYX8Es/dThd FuHG6vzQPx71nzRClfoPktXoR7Oe75H4lUxdSzuQqURGaq0md68MYZKGv3NAvhMY3Z8sODvp8QeyD jHgQYFjUExZeJYczsFOFw8iMf3or96RBie4ZdlOI4V8GSkHFwaLVel1yf9Wq5yPoCAmW5Sy3M9wvs eAfDmpxkTWq0t7vjwCRUkQP7l/gsbkPhwzeehqVtgGLUckno+FX3HjT209eyhOEWiu9RLmrxWcJcB Ko3eqkbKtRrKJxmfJRkW2hX7KsD/QDiLMtZxCb8UHKRnSgEDuBNaoBEsjLti++QiW6rFaHzMbJgWr iQ0ruaAA==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1IxT-00000001SA8-0zQd; Mon, 29 Apr 2024 04:49:43 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 8/8] xfs: rename the del variable in xfs_reflink_end_cow_extent Date: Mon, 29 Apr 2024 06:49:17 +0200 Message-Id: <20240429044917.1504566-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240429044917.1504566-1-hch@lst.de> References: <20240429044917.1504566-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html del contains the new extent that we are remapping. Give it a somewhat less confusing name. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_reflink.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index e20db39d1cc46f..f4c4cd4ef72336 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -784,7 +784,7 @@ xfs_reflink_end_cow_extent( xfs_fileoff_t end_fsb) { struct xfs_iext_cursor icur; - struct xfs_bmbt_irec got, del; + struct xfs_bmbt_irec got, remap; struct xfs_mount *mp = ip->i_mount; struct xfs_trans *tp; struct xfs_ifork *ifp = xfs_ifork_ptr(ip, XFS_COW_FORK); @@ -820,7 +820,7 @@ xfs_reflink_end_cow_extent( * Only remap real extents that contain data. With AIO, speculative * preallocations can leak into the range we are called upon, and we * need to skip them. Preserve @got for the eventual CoW fork - * deletion; from now on @del represents the mapping that we're + * deletion; from now on @remap represents the mapping that we're * actually remapping. */ while (!xfs_bmap_is_written_extent(&got)) { @@ -830,9 +830,9 @@ xfs_reflink_end_cow_extent( goto out_cancel; } } - del = got; - xfs_trim_extent(&del, *offset_fsb, end_fsb - *offset_fsb); - trace_xfs_reflink_cow_remap_from(ip, &del); + remap = got; + xfs_trim_extent(&remap, *offset_fsb, end_fsb - *offset_fsb); + trace_xfs_reflink_cow_remap_from(ip, &remap); error = xfs_iext_count_ensure(tp, ip, XFS_DATA_FORK, XFS_IEXT_REFLINK_END_COW_CNT); @@ -840,23 +840,24 @@ xfs_reflink_end_cow_extent( goto out_cancel; /* Unmap the old data. */ - error = xfs_reflink_unmap_old_data(&tp, ip, del.br_startoff, - del.br_startoff + del.br_blockcount); + error = xfs_reflink_unmap_old_data(&tp, ip, remap.br_startoff, + remap.br_startoff + remap.br_blockcount); if (error) goto out_cancel; /* Free the CoW orphan record. */ - xfs_refcount_free_cow_extent(tp, del.br_startblock, del.br_blockcount); + xfs_refcount_free_cow_extent(tp, remap.br_startblock, + remap.br_blockcount); /* Map the new blocks into the data fork. */ - xfs_bmap_map_extent(tp, ip, XFS_DATA_FORK, &del); + xfs_bmap_map_extent(tp, ip, XFS_DATA_FORK, &remap); /* Charge this new data fork mapping to the on-disk quota. */ xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_DELBCOUNT, - (long)del.br_blockcount); + (long)remap.br_blockcount); /* Remove the mapping from the CoW fork. */ - xfs_bmap_del_extent_cow(ip, &icur, &got, &del); + xfs_bmap_del_extent_cow(ip, &icur, &got, &remap); error = xfs_trans_commit(tp); xfs_iunlock(ip, XFS_ILOCK_EXCL); @@ -864,7 +865,7 @@ xfs_reflink_end_cow_extent( return error; /* Update the caller about how much progress we made. */ - *offset_fsb = del.br_startoff + del.br_blockcount; + *offset_fsb = remap.br_startoff + remap.br_blockcount; return 0; out_cancel: