From patchwork Tue Jul 30 00:24:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745893 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C0CA44A11 for ; Tue, 30 Jul 2024 00:24:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299042; cv=none; b=K7zbK4Z85eoF3NhSdVPlAJhG5RlZndRwGF9olZ69raPlCwsv+9cSfWG52E2orvpbSEUM0tNHImMROg3NjCKDKZjw8SNyo56r+RrK2UmH8rO225ShgngGrnDAXoT2wnfHPFtvXPRfnCp+vQ9TaUgvxsgqOa/tam8+W7cx+zQqN0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299042; c=relaxed/simple; bh=IK5Z/8MqRdEwGypshnaSvpTTTYAu3aLEqqMpVvxc4iA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=B/GdGcqz54/VWedk7zZgmuCxWUQyl3rGDPkwlmyuADdApgwSIiv5QcKS8gDt6JNlnCZD62Lm1/IHEdn5we8LdRFVpL6R1iuoCrLEKqABRl0yJRH2lkn03rL/RUOsvba5+LdYca5nur4tkorS+nd2tOOsBO9XNgGeon+f+UPWULg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=t6DrOjj0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="t6DrOjj0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 956B1C32786; Tue, 30 Jul 2024 00:24:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299042; bh=IK5Z/8MqRdEwGypshnaSvpTTTYAu3aLEqqMpVvxc4iA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=t6DrOjj0FCZYrDlIZ3TXUbEmWBAOdWAKz+m9TMRmS62PoH1G6152HZ7mOyTZdXGEO jzEHzgkK/ATUibf1mbWGqabMqbtLpy6N0VilP8BqQskJEUFte2NoxK/2oHB8KOg70a Edg+pDbTFgSCRCCx2nyKSKiK1Y3Aipa94rZOHGMqeKeDFFj54ydbx5nZXvekWDu3tw S7RsPaPijcVP4fsvqQMHoiZy7TR5oktLnkZopA5n9Mp9k4JyeWp1j+IItqUsijCISO Tdw8E0XmMlzWFjI13S53yDN5FY+OObgy55KbEIT6JZsOPUHuTWbpE4i+8fF3eYw3zp FMjxLoVS1f3IQ== Date: Mon, 29 Jul 2024 17:24:02 -0700 Subject: [PATCH 001/115] xfs: pass xfs_buf lookup flags to xfs_*read_agi From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842455.1338752.13548570121517004752.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 549d3c9a29921f388ef3bcfd1d4f669b7dd4eed2 Allow callers to pass buffer lookup flags to xfs_read_agi and xfs_ialloc_read_agi. This will be used in the next patch to fix a deadlock in the online fsck inode scanner. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- db/iunlink.c | 4 ++-- libxfs/xfs_ag.c | 8 ++++---- libxfs/xfs_ialloc.c | 16 ++++++++++------ libxfs/xfs_ialloc.h | 5 +++-- libxfs/xfs_ialloc_btree.c | 4 ++-- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/db/iunlink.c b/db/iunlink.c index d87562e3b..256c85560 100644 --- a/db/iunlink.c +++ b/db/iunlink.c @@ -117,7 +117,7 @@ dump_unlinked( xfs_agnumber_t agno = pag->pag_agno; int error; - error = -libxfs_ialloc_read_agi(pag, NULL, &agi_bp); + error = -libxfs_ialloc_read_agi(pag, NULL, 0, &agi_bp); if (error) { dbprintf(_("AGI %u: %s\n"), agno, strerror(errno)); return; @@ -295,7 +295,7 @@ iunlink( pag = libxfs_perag_get(mp, XFS_INO_TO_AGNO(mp, ip->i_ino)); /* Get the agi buffer first. It ensures lock ordering on the list. */ - error = -libxfs_read_agi(pag, tp, &agibp); + error = -libxfs_read_agi(pag, tp, 0, &agibp); if (error) goto out; diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index a9aae0990..ad721c192 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -192,7 +192,7 @@ xfs_initialize_perag_data( pag = xfs_perag_get(mp, index); error = xfs_alloc_read_agf(pag, NULL, 0, NULL); if (!error) - error = xfs_ialloc_read_agi(pag, NULL, NULL); + error = xfs_ialloc_read_agi(pag, NULL, 0, NULL); if (error) { xfs_perag_put(pag); return error; @@ -929,7 +929,7 @@ xfs_ag_shrink_space( int error, err2; ASSERT(pag->pag_agno == mp->m_sb.sb_agcount - 1); - error = xfs_ialloc_read_agi(pag, *tpp, &agibp); + error = xfs_ialloc_read_agi(pag, *tpp, 0, &agibp); if (error) return error; @@ -1060,7 +1060,7 @@ xfs_ag_extend_space( ASSERT(pag->pag_agno == pag->pag_mount->m_sb.sb_agcount - 1); - error = xfs_ialloc_read_agi(pag, tp, &bp); + error = xfs_ialloc_read_agi(pag, tp, 0, &bp); if (error) return error; @@ -1117,7 +1117,7 @@ xfs_ag_get_geometry( int error; /* Lock the AG headers. */ - error = xfs_ialloc_read_agi(pag, NULL, &agi_bp); + error = xfs_ialloc_read_agi(pag, NULL, 0, &agi_bp); if (error) return error; error = xfs_alloc_read_agf(pag, NULL, 0, &agf_bp); diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c index c30e76830..992b8348a 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -1694,7 +1694,7 @@ xfs_dialloc_good_ag( return false; if (!xfs_perag_initialised_agi(pag)) { - error = xfs_ialloc_read_agi(pag, tp, NULL); + error = xfs_ialloc_read_agi(pag, tp, 0, NULL); if (error) return false; } @@ -1763,7 +1763,7 @@ xfs_dialloc_try_ag( * Then read in the AGI buffer and recheck with the AGI buffer * lock held. */ - error = xfs_ialloc_read_agi(pag, *tpp, &agbp); + error = xfs_ialloc_read_agi(pag, *tpp, 0, &agbp); if (error) return error; @@ -2281,7 +2281,7 @@ xfs_difree( /* * Get the allocation group header. */ - error = xfs_ialloc_read_agi(pag, tp, &agbp); + error = xfs_ialloc_read_agi(pag, tp, 0, &agbp); if (error) { xfs_warn(mp, "%s: xfs_ialloc_read_agi() returned error %d.", __func__, error); @@ -2327,7 +2327,7 @@ xfs_imap_lookup( int error; int i; - error = xfs_ialloc_read_agi(pag, tp, &agbp); + error = xfs_ialloc_read_agi(pag, tp, 0, &agbp); if (error) { xfs_alert(mp, "%s: xfs_ialloc_read_agi() returned error %d, agno %d", @@ -2670,6 +2670,7 @@ int xfs_read_agi( struct xfs_perag *pag, struct xfs_trans *tp, + xfs_buf_flags_t flags, struct xfs_buf **agibpp) { struct xfs_mount *mp = pag->pag_mount; @@ -2679,7 +2680,7 @@ xfs_read_agi( error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, XFS_AG_DADDR(mp, pag->pag_agno, XFS_AGI_DADDR(mp)), - XFS_FSS_TO_BB(mp, 1), 0, agibpp, &xfs_agi_buf_ops); + XFS_FSS_TO_BB(mp, 1), flags, agibpp, &xfs_agi_buf_ops); if (xfs_metadata_is_sick(error)) xfs_ag_mark_sick(pag, XFS_SICK_AG_AGI); if (error) @@ -2699,6 +2700,7 @@ int xfs_ialloc_read_agi( struct xfs_perag *pag, struct xfs_trans *tp, + int flags, struct xfs_buf **agibpp) { struct xfs_buf *agibp; @@ -2707,7 +2709,9 @@ xfs_ialloc_read_agi( trace_xfs_ialloc_read_agi(pag->pag_mount, pag->pag_agno); - error = xfs_read_agi(pag, tp, &agibp); + error = xfs_read_agi(pag, tp, + (flags & XFS_IALLOC_FLAG_TRYLOCK) ? XBF_TRYLOCK : 0, + &agibp); if (error) return error; diff --git a/libxfs/xfs_ialloc.h b/libxfs/xfs_ialloc.h index f1412183b..b549627e3 100644 --- a/libxfs/xfs_ialloc.h +++ b/libxfs/xfs_ialloc.h @@ -63,10 +63,11 @@ xfs_ialloc_log_agi( struct xfs_buf *bp, /* allocation group header buffer */ uint32_t fields); /* bitmask of fields to log */ -int xfs_read_agi(struct xfs_perag *pag, struct xfs_trans *tp, +int xfs_read_agi(struct xfs_perag *pag, struct xfs_trans *tp, xfs_buf_flags_t flags, struct xfs_buf **agibpp); int xfs_ialloc_read_agi(struct xfs_perag *pag, struct xfs_trans *tp, - struct xfs_buf **agibpp); + int flags, struct xfs_buf **agibpp); +#define XFS_IALLOC_FLAG_TRYLOCK (1U << 0) /* use trylock for buffer locking */ /* * Lookup a record by ino in the btree given by cur. diff --git a/libxfs/xfs_ialloc_btree.c b/libxfs/xfs_ialloc_btree.c index 58c520ecb..5db9d0b33 100644 --- a/libxfs/xfs_ialloc_btree.c +++ b/libxfs/xfs_ialloc_btree.c @@ -744,7 +744,7 @@ xfs_finobt_count_blocks( struct xfs_btree_cur *cur; int error; - error = xfs_ialloc_read_agi(pag, tp, &agbp); + error = xfs_ialloc_read_agi(pag, tp, 0, &agbp); if (error) return error; @@ -767,7 +767,7 @@ xfs_finobt_read_blocks( struct xfs_agi *agi; int error; - error = xfs_ialloc_read_agi(pag, tp, &agbp); + error = xfs_ialloc_read_agi(pag, tp, 0, &agbp); if (error) return error; From patchwork Tue Jul 30 00:24:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745894 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6B1C04A11 for ; Tue, 30 Jul 2024 00:24:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299058; cv=none; b=NIw304V2LcGDZKUNc9fuByEr/YSq+RWz35YvavnSOrujuJcSUukKeiQKkVVqqmdW+/OMyxCClEfHl1I8ylxbG62tvYNSRILdHvwxXiD8iaf8DIICZYfYjw7kmKuJc9Cg8Al/yb485cO1Se8PFM3fXsFk/pF1oAm3W6DZZpOBa1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299058; c=relaxed/simple; bh=JBm9mNyug9b6rR4eufBNYi9QlnfU14j4a9IakzZEGYc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=k8sWwvhgiafvLYtqzrarJlSWu4M3X4ZE4VI4AbyGmG6lqIpu1oaldt78d9EwzkdsP1NNOloEPc2T163m3L1WQYrHHPyfWcdlHl+jBejCCwmWCPNMVwMVb7qRryO64CCN3qX4sG5kPDuoIwDPNDrRWwgFkBv4ZqUYPfKybaFyYVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Lhn13/K9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Lhn13/K9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B7C6C32786; Tue, 30 Jul 2024 00:24:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299058; bh=JBm9mNyug9b6rR4eufBNYi9QlnfU14j4a9IakzZEGYc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Lhn13/K9LI996witdXvP3nrt8lgc6UbYvBQY1iDeu7IuCTnvznlyjVxrEst1qM38+ pOXDNHEvn4PJk2DPfB5rVss4KErAf4U2wO+J8+dBGT2qvbnG7pIoYDuuqZbD9R9NLK 83GPqNB+qGRUhitBBDpSuhiba5ame4pHqhq8H2fGEZ7T72ElFaeoNDAfUH98GPq84V XgJ4FJANc9+UksBfATV/5lkewkz8bSwNhAhoqNxs6VQ7RomhlS1KcrA2wHuRxpg4vd UFmoq6NU/nX/e0A3CmkTePN9rP8cCxt67xyVNfwbY3tE/OkoIAHDRPGWE56HkQWHl7 P1Ma2pydgiZbA== Date: Mon, 29 Jul 2024 17:24:17 -0700 Subject: [PATCH 002/115] xfs: constify xfs_bmap_is_written_extent From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842469.1338752.8458228431845610563.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 15f78aa3eb07645e7bef15a53b4ae1c757907d2c This predicate doesn't modify the structure that's being passed in, so we can mark it const. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_bmap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libxfs/xfs_bmap.h b/libxfs/xfs_bmap.h index f76625953..b8bdbf156 100644 --- a/libxfs/xfs_bmap.h +++ b/libxfs/xfs_bmap.h @@ -158,7 +158,7 @@ static inline bool xfs_bmap_is_real_extent(const struct xfs_bmbt_irec *irec) * Return true if the extent is a real, allocated extent, or false if it is a * delayed allocation, and unwritten extent or a hole. */ -static inline bool xfs_bmap_is_written_extent(struct xfs_bmbt_irec *irec) +static inline bool xfs_bmap_is_written_extent(const struct xfs_bmbt_irec *irec) { return xfs_bmap_is_real_extent(irec) && irec->br_state != XFS_EXT_UNWRITTEN; From patchwork Tue Jul 30 00:24:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745895 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1C2EB4A11 for ; Tue, 30 Jul 2024 00:24:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299074; cv=none; b=jqHf762Fc8W+t+HabX+R3Ib5gaLiRKIUhKtaVNYFjNSZyLEN085x0Gk8jwZCaa6llUxhW0HKMgmf1hVWDedN7nmIjGrGgZTQ0ue5SEgqKDYlR2me5URh1eTF9W0Ps/ZoYkmTZnBEUe7jNyPrN0MPQiF5cm1n4/7gV0b/bWR2quY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299074; c=relaxed/simple; bh=8ezvH9Rp8EvFgP31Tx9/sAUwekDRHUXYad0++gA73Dw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sojnkkR5ZHGi+IuRBNVQBYAqJ9I+EiJ77VIkliPyeH/E/sRbntvpzkJjt4Bw6sfjF4lKrX4wk8e5dDne8OZiD7ST+0f4yWiEhfXobkr0Q7qcpZ04o1ATGf/zpGd73VI4oIzChbjAnS6on6A16KI7igI1LEEGu2xaX29sRgV1IM8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qnMc9TJu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qnMc9TJu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E71DBC32786; Tue, 30 Jul 2024 00:24:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299074; bh=8ezvH9Rp8EvFgP31Tx9/sAUwekDRHUXYad0++gA73Dw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=qnMc9TJuJqOz2Kub6V8S402t3OowxEcesquULebBJ3aZ9X7l8sEhciPzmQsTvRtH/ 90nneEnUhxGu6gXUPokVDLe2GLxdIy99QJKyaZHJdyST1q8gYJEtJ03I1KGbb+6/2t 3zv6xLd+ApTwN1HvZX3UcAO1QH1tpaBLYBXhi1V2WgqaIXs8aCZoCuOqolotPcy/S2 FgnDUDMEGgIpxS2fm3JIw44eAJ2tBvPgQS09Wqqug/HazYqa5K/r4P/KecX7QwL1wN aZso6DzN5ZV2GROZFazUULPGPyAwx8w370DaZXf35nYBVSIrTu3p0MblThP5Utyxam dNRIsIvUVlThw== Date: Mon, 29 Jul 2024 17:24:33 -0700 Subject: [PATCH 003/115] xfs: introduce new file range exchange ioctl From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842484.1338752.14571927597810604078.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 9a64d9b3109d01cca0b83c1d36538b7a37c5284e Introduce a new ioctl to handle exchanging ranges of bytes between files. The goal here is to perform the exchange atomically with respect to applications -- either they see the file contents before the exchange or they see that A-B is now B-A, even if the kernel crashes. My original goal with all this code was to make it so that online repair can build a replacement directory or xattr structure in a temporary file and commit the repair by atomically exchanging all the data blocks between the two files. However, I needed a way to test this mechanism thoroughly, so I've been evolving an ioctl interface since then. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_fs.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index ca1b17d01..8a1e30cf4 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -772,6 +772,46 @@ struct xfs_scrub_metadata { # define XFS_XATTR_LIST_MAX 65536 #endif +/* + * Exchange part of file1 with part of the file that this ioctl that is being + * called against (which we'll call file2). Filesystems must be able to + * restart and complete the operation even after the system goes down. + */ +struct xfs_exchange_range { + __s32 file1_fd; + __u32 pad; /* must be zeroes */ + __u64 file1_offset; /* file1 offset, bytes */ + __u64 file2_offset; /* file2 offset, bytes */ + __u64 length; /* bytes to exchange */ + + __u64 flags; /* see XFS_EXCHANGE_RANGE_* below */ +}; + +/* + * Exchange file data all the way to the ends of both files, and then exchange + * the file sizes. This flag can be used to replace a file's contents with a + * different amount of data. length will be ignored. + */ +#define XFS_EXCHANGE_RANGE_TO_EOF (1ULL << 0) + +/* Flush all changes in file data and file metadata to disk before returning. */ +#define XFS_EXCHANGE_RANGE_DSYNC (1ULL << 1) + +/* Dry run; do all the parameter verification but do not change anything. */ +#define XFS_EXCHANGE_RANGE_DRY_RUN (1ULL << 2) + +/* + * Exchange only the parts of the two files where the file allocation units + * mapped to file1's range have been written to. This can accelerate + * scatter-gather atomic writes with a temp file if all writes are aligned to + * the file allocation unit. + */ +#define XFS_EXCHANGE_RANGE_FILE1_WRITTEN (1ULL << 3) + +#define XFS_EXCHANGE_RANGE_ALL_FLAGS (XFS_EXCHANGE_RANGE_TO_EOF | \ + XFS_EXCHANGE_RANGE_DSYNC | \ + XFS_EXCHANGE_RANGE_DRY_RUN | \ + XFS_EXCHANGE_RANGE_FILE1_WRITTEN) /* * ioctl commands that are used by Linux filesystems @@ -843,6 +883,7 @@ struct xfs_scrub_metadata { #define XFS_IOC_FSGEOMETRY _IOR ('X', 126, struct xfs_fsop_geom) #define XFS_IOC_BULKSTAT _IOR ('X', 127, struct xfs_bulkstat_req) #define XFS_IOC_INUMBERS _IOR ('X', 128, struct xfs_inumbers_req) +#define XFS_IOC_EXCHANGE_RANGE _IOWR('X', 129, struct xfs_exchange_range) /* XFS_IOC_GETFSUUID ---------- deprecated 140 */ From patchwork Tue Jul 30 00:24:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745896 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E97F74A11 for ; Tue, 30 Jul 2024 00:24:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299090; cv=none; b=jVyfd3n64zxUut0wVv/Ffj7pDf9eEiPKIHZ1LQY6EOezR+ouCimHiNC8GXqQdt/GOdP2Bpf5pDTs+op2paSi69nigRd3rpHiz1Phio1uyCDqgvSwaLL+1qmG9ZmVHczZjvrZLIfbJMmkZn7SpTLKUTHzFt6jlNTMIDSoYV8jjlk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299090; c=relaxed/simple; bh=e4hjONcryM0XHtXZ+ZWzdpvDQVEa0yi/JNxkAhiNg1o=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=R6MncHGhxx4+fK3x+B1+GV4bHVk9yDp0xQOjxhhGX48qpNDCvalTH1MMqHQ3tFHMD91gP+8CoyKK+Sv3YUfvOj5hDPGRxRqFgAMgC75Qrycl1iXu0+Tl9mvl5KI4ZDT/qb4Hqyc+daGYaUAAtpLOQ0Qv+AqR/XR/XjzAKbGTdYY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XuzFePtg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XuzFePtg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89AA1C32786; Tue, 30 Jul 2024 00:24:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299089; bh=e4hjONcryM0XHtXZ+ZWzdpvDQVEa0yi/JNxkAhiNg1o=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=XuzFePtgn9znRLT6wg6G6l8EhoyF9srlIgl+rtAgGGRvJrFJOKhnqivdhLIWt+cFe SOeyu9wg6AzQ58GdeyjaBa+tXtGuBi0nCYaSCPpRbsjxY4JDQPKeK/fWgOPEiqnagN YOHjBwde09L6uR1k9XmvuOpnoAYv7ryopXxL5EGVKWlHVKd777PpYqP7NP0o18gJ8d Jk7FHKWT7dallrdayy2RQ3jnCPKGi4E5jx7wqX3nm6o54fgeHzsYCKoN2OLqrBiK6w twn/U8DsmFgIFEmU6STh3N03jt6OaylvFi3HFgEcEFWxqyBVH0BQ8EvECqDsZH4GdE 9it80ML2N+wWA== Date: Mon, 29 Jul 2024 17:24:49 -0700 Subject: [PATCH 004/115] xfs: create a incompat flag for atomic file mapping exchanges From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842498.1338752.2972429724527989367.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 1518646eef26c220e9256906260ecaaa64503522 Create a incompat flag so that we only attempt to process file mapping exchange log items if the filesystem supports it, and a geometry flag to advertise support if it's present. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- include/xfs_mount.h | 2 ++ libxfs/xfs_format.h | 23 ++++++++++++----------- libxfs/xfs_fs.h | 1 + libxfs/xfs_sb.c | 4 ++++ 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/include/xfs_mount.h b/include/xfs_mount.h index 9c492b8f5..a9525e4e0 100644 --- a/include/xfs_mount.h +++ b/include/xfs_mount.h @@ -169,6 +169,7 @@ typedef struct xfs_mount { #define XFS_FEAT_BIGTIME (1ULL << 24) /* large timestamps */ #define XFS_FEAT_NEEDSREPAIR (1ULL << 25) /* needs xfs_repair */ #define XFS_FEAT_NREXT64 (1ULL << 26) /* large extent counters */ +#define XFS_FEAT_EXCHANGE_RANGE (1ULL << 27) /* exchange range */ #define __XFS_HAS_FEAT(name, NAME) \ static inline bool xfs_has_ ## name (struct xfs_mount *mp) \ @@ -213,6 +214,7 @@ __XFS_HAS_FEAT(inobtcounts, INOBTCNT) __XFS_HAS_FEAT(bigtime, BIGTIME) __XFS_HAS_FEAT(needsrepair, NEEDSREPAIR) __XFS_HAS_FEAT(large_extent_counts, NREXT64) +__XFS_HAS_FEAT(exchange_range, EXCHANGE_RANGE) /* Kernel mount features that we don't support */ #define __XFS_UNSUPP_FEAT(name) \ diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index 2b2f9050f..ff1e28316 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -367,18 +367,19 @@ xfs_sb_has_ro_compat_feature( return (sbp->sb_features_ro_compat & feature) != 0; } -#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0) /* filetype in dirent */ -#define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1) /* sparse inode chunks */ -#define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2) /* metadata UUID */ -#define XFS_SB_FEAT_INCOMPAT_BIGTIME (1 << 3) /* large timestamps */ -#define XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR (1 << 4) /* needs xfs_repair */ -#define XFS_SB_FEAT_INCOMPAT_NREXT64 (1 << 5) /* large extent counters */ +#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0) /* filetype in dirent */ +#define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1) /* sparse inode chunks */ +#define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2) /* metadata UUID */ +#define XFS_SB_FEAT_INCOMPAT_BIGTIME (1 << 3) /* large timestamps */ +#define XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR (1 << 4) /* needs xfs_repair */ +#define XFS_SB_FEAT_INCOMPAT_NREXT64 (1 << 5) /* large extent counters */ +#define XFS_SB_FEAT_INCOMPAT_EXCHRANGE (1 << 6) /* exchangerange supported */ #define XFS_SB_FEAT_INCOMPAT_ALL \ - (XFS_SB_FEAT_INCOMPAT_FTYPE| \ - XFS_SB_FEAT_INCOMPAT_SPINODES| \ - XFS_SB_FEAT_INCOMPAT_META_UUID| \ - XFS_SB_FEAT_INCOMPAT_BIGTIME| \ - XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR| \ + (XFS_SB_FEAT_INCOMPAT_FTYPE | \ + XFS_SB_FEAT_INCOMPAT_SPINODES | \ + XFS_SB_FEAT_INCOMPAT_META_UUID | \ + XFS_SB_FEAT_INCOMPAT_BIGTIME | \ + XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR | \ XFS_SB_FEAT_INCOMPAT_NREXT64) #define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index 8a1e30cf4..53526fca7 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -239,6 +239,7 @@ typedef struct xfs_fsop_resblks { #define XFS_FSOP_GEOM_FLAGS_BIGTIME (1 << 21) /* 64-bit nsec timestamps */ #define XFS_FSOP_GEOM_FLAGS_INOBTCNT (1 << 22) /* inobt btree counter */ #define XFS_FSOP_GEOM_FLAGS_NREXT64 (1 << 23) /* large extent counters */ +#define XFS_FSOP_GEOM_FLAGS_EXCHANGE_RANGE (1 << 24) /* exchange range */ /* * Minimum and maximum sizes need for growth checks. diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index 895d646bb..2db43b805 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -173,6 +173,8 @@ xfs_sb_version_to_features( features |= XFS_FEAT_NEEDSREPAIR; if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_NREXT64) features |= XFS_FEAT_NREXT64; + if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_EXCHRANGE) + features |= XFS_FEAT_EXCHANGE_RANGE; return features; } @@ -1257,6 +1259,8 @@ xfs_fs_geometry( } if (xfs_has_large_extent_counts(mp)) geo->flags |= XFS_FSOP_GEOM_FLAGS_NREXT64; + if (xfs_has_exchange_range(mp)) + geo->flags |= XFS_FSOP_GEOM_FLAGS_EXCHANGE_RANGE; geo->rtsectsize = sbp->sb_blocksize; geo->dirblocksize = xfs_dir2_dirblock_bytes(sbp); From patchwork Tue Jul 30 00:25:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745897 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5619B4A11 for ; Tue, 30 Jul 2024 00:25:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299105; cv=none; b=CvG7SsiLIJwbFv7PtuZb8P+D5SjmfNV8eg+P4ToaY/vZ+4pSwH3ecGD8WeRB6oGu/38MEY/Nna9dTJUMghDdha44DXy6ZP7hhxbo5e0BDC9UqNlaMrtAYIVcqkrk1PZFK1Dke6hr/TcNkM00s603anR2+qXe81ReIoytf149qG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299105; c=relaxed/simple; bh=Ve5Zk//9hTyqxr0ENgT+23KB0V+VFDH87S+dMxH0OVc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NwvLG4ZDvj94HqqVe3D7IgP6O7CCCmQm+qv1SyiIOCsG6xRsxqjj+NLo4EyOWryrPqEoiYshrYUmJzNg5KfgyqleGwC76/F2u3ME0htc4RRiBpnKs4cWplTYK+WQoZcSWnYAznR585gdlZTmtkRdahos39Vy2LCR7zWzqqFUHOk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X0S46F2a; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="X0S46F2a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BE0DC32786; Tue, 30 Jul 2024 00:25:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299105; bh=Ve5Zk//9hTyqxr0ENgT+23KB0V+VFDH87S+dMxH0OVc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=X0S46F2aF3uZg75TjLACctb3sOmYckBxlT03Lp+24bdbIz3icrchm68zAPvGDKhG/ 2atyZQoURuio3bJUxhuveU6jWmKXEC597KuhVkP/GozABgNBsviuQR0EjXP6LKal8k Pm3CXt/q1clTFaAj0Z/sOE2Zkq79ekFeb6M8qFu0obqzJAtDtNw9KvBoctG95acYny 1nlJtdk6gw/xbzow269XWkAw5UFC3+0forv7iqsjCAc5sqPvAU8RSimru2mXhP33Qt 88JUnJET3Ss/6htKWAe9DGYi/sVGDb/FRTcpnpjyD+f5x9c0B56GWYqmiQI8v1E/ry eDx6l3tfs8tzA== Date: Mon, 29 Jul 2024 17:25:04 -0700 Subject: [PATCH 005/115] xfs: introduce a file mapping exchange log intent item From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842512.1338752.945394817660315327.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 6c08f434bd33f88cf169e9e43c7a5e42fb3f2118 Introduce a new intent log item to handle exchanging mappings between the forks of two files. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_log_format.h | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/libxfs/xfs_log_format.h b/libxfs/xfs_log_format.h index 16872972e..09024431c 100644 --- a/libxfs/xfs_log_format.h +++ b/libxfs/xfs_log_format.h @@ -117,8 +117,9 @@ struct xfs_unmount_log_format { #define XLOG_REG_TYPE_ATTRD_FORMAT 28 #define XLOG_REG_TYPE_ATTR_NAME 29 #define XLOG_REG_TYPE_ATTR_VALUE 30 -#define XLOG_REG_TYPE_MAX 30 - +#define XLOG_REG_TYPE_XMI_FORMAT 31 +#define XLOG_REG_TYPE_XMD_FORMAT 32 +#define XLOG_REG_TYPE_MAX 32 /* * Flags to log operation header @@ -243,6 +244,8 @@ typedef struct xfs_trans_header { #define XFS_LI_BUD 0x1245 #define XFS_LI_ATTRI 0x1246 /* attr set/remove intent*/ #define XFS_LI_ATTRD 0x1247 /* attr set/remove done */ +#define XFS_LI_XMI 0x1248 /* mapping exchange intent */ +#define XFS_LI_XMD 0x1249 /* mapping exchange done */ #define XFS_LI_TYPE_DESC \ { XFS_LI_EFI, "XFS_LI_EFI" }, \ @@ -260,7 +263,9 @@ typedef struct xfs_trans_header { { XFS_LI_BUI, "XFS_LI_BUI" }, \ { XFS_LI_BUD, "XFS_LI_BUD" }, \ { XFS_LI_ATTRI, "XFS_LI_ATTRI" }, \ - { XFS_LI_ATTRD, "XFS_LI_ATTRD" } + { XFS_LI_ATTRD, "XFS_LI_ATTRD" }, \ + { XFS_LI_XMI, "XFS_LI_XMI" }, \ + { XFS_LI_XMD, "XFS_LI_XMD" } /* * Inode Log Item Format definitions. @@ -878,6 +883,37 @@ struct xfs_bud_log_format { uint64_t bud_bui_id; /* id of corresponding bui */ }; +/* + * XMI/XMD (file mapping exchange) log format definitions + */ + +/* This is the structure used to lay out an mapping exchange log item. */ +struct xfs_xmi_log_format { + uint16_t xmi_type; /* xmi log item type */ + uint16_t xmi_size; /* size of this item */ + uint32_t __pad; /* must be zero */ + uint64_t xmi_id; /* xmi identifier */ + + uint64_t xmi_inode1; /* inumber of first file */ + uint64_t xmi_inode2; /* inumber of second file */ + uint64_t xmi_startoff1; /* block offset into file1 */ + uint64_t xmi_startoff2; /* block offset into file2 */ + uint64_t xmi_blockcount; /* number of blocks */ + uint64_t xmi_flags; /* XFS_EXCHMAPS_* */ + uint64_t xmi_isize1; /* intended file1 size */ + uint64_t xmi_isize2; /* intended file2 size */ +}; + +#define XFS_EXCHMAPS_LOGGED_FLAGS (0) + +/* This is the structure used to lay out an mapping exchange done log item. */ +struct xfs_xmd_log_format { + uint16_t xmd_type; /* xmd log item type */ + uint16_t xmd_size; /* size of this item */ + uint32_t __pad; + uint64_t xmd_xmi_id; /* id of corresponding xmi */ +}; + /* * Dquot Log format definitions. * From patchwork Tue Jul 30 00:25:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745898 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5F9A74A11 for ; Tue, 30 Jul 2024 00:25:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299121; cv=none; b=j6yrCyzKBoS/A1kDc+ktLh5f3sVHO6pp9wWjXruP6mXvvwalJdVA6k3VZybYeiJUSBjxtBqQvrg2gBlUdYrVHvjVula9izO9OB6y7yQP+1x0OGnsUYkeIKmCmoBSw0WljffLKF8/8lm+2E2L6K9gwHo1Rx21RK7eoqrkgdC/hpo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299121; c=relaxed/simple; bh=2VHZjoBWOfhQ0urk5VYCnQ2xjkjfJSpRkxB+F2Ib/jc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MEhGyB0oT7MMKkvIj9bJom/B5KAOZ7yeAXAelYAhMBNMoBjfSGHACArkbspkBiRlN3EAz+MC+4OEJN9MF6By6qNxvXZbZ44MtjbN9xoyAnPPThsnf+UAsR2IpxL5NkTFrkTScDfIq9Zij/tB2ywlinc3gxXeCKSuX8MSakEPKrM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Oo5DnNtS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Oo5DnNtS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD3C5C32786; Tue, 30 Jul 2024 00:25:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299120; bh=2VHZjoBWOfhQ0urk5VYCnQ2xjkjfJSpRkxB+F2Ib/jc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Oo5DnNtSeXu6/ykoAW9AABXFvKTVc9DId8Ex5UgStY2FQg7PYOpCDuN/rQQvhTL9n oDC+DrVWzpTnB84JUGjWFYHfXvK70GcPXbjY53oi1A5Zqhq679F36ue0o1r9gdMUev FgKLMKPdCUFinawA2gLU4XwBGaoWxNEE+H+kAJG/h61fRvpFlKHhYp+ms4HX91ogoB /ltfe4IIe1L2f/ToJAohqp2E2sp0MHXpoD8aFqOQdYSCB2OGW1QTSZxsYYF3SFKpCr FEODuL0RXcpqz4gJzJ3QAQgXVSKmkeIMOQa6lp7h0IRg8h1NY3S3Fvi1rdiUtwqVU8 ZHFJAOFU7V1qA== Date: Mon, 29 Jul 2024 17:25:20 -0700 Subject: [PATCH 006/115] xfs: create deferred log items for file mapping exchanges From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842526.1338752.8516972356571696255.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 966ceafc7a437105ecfe1cadb3747b2965a260ca Now that we've created the skeleton of a log intent item to track and restart file mapping exchange operations, add the upper level logic to log. This builds on the existing bmap update intent items that have been around for a while now. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- include/xfs_trace.h | 14 + libxfs/Makefile | 2 libxfs/defer_item.c | 88 ++++ libxfs/defer_item.h | 5 libxfs/libxfs_priv.h | 30 + libxfs/xfs_defer.c | 6 libxfs/xfs_defer.h | 2 libxfs/xfs_exchmaps.c | 1042 ++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_exchmaps.h | 118 +++++ libxfs/xfs_log_format.h | 24 + libxfs/xfs_trans_space.h | 4 11 files changed, 1333 insertions(+), 2 deletions(-) create mode 100644 libxfs/xfs_exchmaps.c create mode 100644 libxfs/xfs_exchmaps.h diff --git a/include/xfs_trace.h b/include/xfs_trace.h index 6b9d3358a..2e5e89d65 100644 --- a/include/xfs_trace.h +++ b/include/xfs_trace.h @@ -329,6 +329,9 @@ #define trace_xfs_refcount_cow_decrease(...) ((void) 0) #define trace_xfs_refcount_recover_extent(...) ((void) 0) +#define trace_xfs_reflink_set_inode_flag(...) ((void) 0) +#define trace_xfs_reflink_unset_inode_flag(...) ((void) 0) + #define trace_xfs_rmap_find_left_neighbor_candidate(...) ((void) 0) #define trace_xfs_rmap_find_left_neighbor_query(...) ((void) 0) #define trace_xfs_rmap_find_left_neighbor_result(...) ((void) 0) @@ -342,6 +345,17 @@ #define trace_xfs_rmap_map_error(...) ((void) 0) #define trace_xfs_rmap_delete_error(...) ((void) 0) +#define trace_xfs_exchmaps_defer(...) ((void) 0) +#define trace_xfs_exchmaps_delta_nextents(...) ((void) 0) +#define trace_xfs_exchmaps_delta_nextents_step(...) ((void) 0) +#define trace_xfs_exchmaps_mapping1_skip(...) ((void) 0) +#define trace_xfs_exchmaps_mapping1(...) ((void) 0) +#define trace_xfs_exchmaps_mapping2(...) ((void) 0) +#define trace_xfs_exchmaps_final_estimate(...) ((void) 0) +#define trace_xfs_exchmaps_initial_estimate(...) ((void) 0) +#define trace_xfs_exchmaps_overhead(...) ((void) 0) +#define trace_xfs_exchmaps_update_inode_size(...) ((void) 0) + #define trace_xfs_fs_mark_healthy(a,b) ((void) 0) #define trace_xlog_intent_recovery_failed(...) ((void) 0) diff --git a/libxfs/Makefile b/libxfs/Makefile index 1c88dbc2a..e3fa18fee 100644 --- a/libxfs/Makefile +++ b/libxfs/Makefile @@ -45,6 +45,7 @@ HFILES = \ xfs_da_btree.h \ xfs_dir2.h \ xfs_errortag.h \ + xfs_exchmaps.h \ xfs_ialloc.h \ xfs_ialloc_btree.h \ xfs_inode_buf.h \ @@ -94,6 +95,7 @@ CFILES = buf_mem.c \ xfs_dir2_node.c \ xfs_dir2_sf.c \ xfs_dquot_buf.c \ + xfs_exchmaps.c \ xfs_ialloc.c \ xfs_iext_tree.c \ xfs_inode_buf.c \ diff --git a/libxfs/defer_item.c b/libxfs/defer_item.c index 21dd1d0f4..fd329e77c 100644 --- a/libxfs/defer_item.c +++ b/libxfs/defer_item.c @@ -25,6 +25,8 @@ #include "xfs_attr.h" #include "libxfs.h" #include "defer_item.h" +#include "xfs_ag.h" +#include "xfs_exchmaps.h" /* Dummy defer item ops, since we don't do logging. */ @@ -677,3 +679,89 @@ const struct xfs_defer_op_type xfs_attr_defer_type = { .finish_item = xfs_attr_finish_item, .cancel_item = xfs_attr_cancel_item, }; + +/* File Mapping Exchanges */ + +STATIC struct xfs_log_item * +xfs_exchmaps_create_intent( + struct xfs_trans *tp, + struct list_head *items, + unsigned int count, + bool sort) +{ + return NULL; +} +STATIC struct xfs_log_item * +xfs_exchmaps_create_done( + struct xfs_trans *tp, + struct xfs_log_item *intent, + unsigned int count) +{ + return NULL; +} + +/* Add this deferred XMI to the transaction. */ +void +xfs_exchmaps_defer_add( + struct xfs_trans *tp, + struct xfs_exchmaps_intent *xmi) +{ + trace_xfs_exchmaps_defer(tp->t_mountp, xmi); + + xfs_defer_add(tp, &xmi->xmi_list, &xfs_exchmaps_defer_type); +} + +static inline struct xfs_exchmaps_intent *xmi_entry(const struct list_head *e) +{ + return list_entry(e, struct xfs_exchmaps_intent, xmi_list); +} + +/* Process a deferred swapext update. */ +STATIC int +xfs_exchmaps_finish_item( + struct xfs_trans *tp, + struct xfs_log_item *done, + struct list_head *item, + struct xfs_btree_cur **state) +{ + struct xfs_exchmaps_intent *xmi = xmi_entry(item); + int error; + + /* + * Exchange one more extent between the two files. If there's still + * more work to do, we want to requeue ourselves after all other + * pending deferred operations have finished. This includes all of the + * dfops that we queued directly as well as any new ones created in the + * process of finishing the others. + */ + error = xfs_exchmaps_finish_one(tp, xmi); + if (error != -EAGAIN) + kmem_cache_free(xfs_exchmaps_intent_cache, xmi); + return error; +} + +/* Abort all pending XMIs. */ +STATIC void +xfs_exchmaps_abort_intent( + struct xfs_log_item *intent) +{ +} + +/* Cancel a deferred swapext update. */ +STATIC void +xfs_exchmaps_cancel_item( + struct list_head *item) +{ + struct xfs_exchmaps_intent *xmi = xmi_entry(item); + + kmem_cache_free(xfs_exchmaps_intent_cache, xmi); +} + +const struct xfs_defer_op_type xfs_exchmaps_defer_type = { + .name = "exchmaps", + .create_intent = xfs_exchmaps_create_intent, + .abort_intent = xfs_exchmaps_abort_intent, + .create_done = xfs_exchmaps_create_done, + .finish_item = xfs_exchmaps_finish_item, + .cancel_item = xfs_exchmaps_cancel_item, +}; diff --git a/libxfs/defer_item.h b/libxfs/defer_item.h index 6d3abf158..a5a07867c 100644 --- a/libxfs/defer_item.h +++ b/libxfs/defer_item.h @@ -10,4 +10,9 @@ struct xfs_bmap_intent; void xfs_bmap_defer_add(struct xfs_trans *tp, struct xfs_bmap_intent *bi); +struct xfs_exchmaps_intent; + +void xfs_exchmaps_defer_add(struct xfs_trans *tp, + struct xfs_exchmaps_intent *xmi); + #endif /* __LIBXFS_DEFER_ITEM_H_ */ diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 81f641f32..9ddba767b 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -219,6 +219,35 @@ static inline bool WARN_ON(bool expr) { (inode)->i_version = (version); \ } while (0) +#define __must_check __attribute__((__warn_unused_result__)) + +/* + * Allows for effectively applying __must_check to a macro so we can have + * both the type-agnostic benefits of the macros while also being able to + * enforce that the return value is, in fact, checked. + */ +static inline bool __must_check __must_check_overflow(bool overflow) +{ + return unlikely(overflow); +} + +/* + * For simplicity and code hygiene, the fallback code below insists on + * a, b and *d having the same type (similar to the min() and max() + * macros), whereas gcc's type-generic overflow checkers accept + * different types. Hence we don't just make check_add_overflow an + * alias for __builtin_add_overflow, but add type checks similar to + * below. + */ +#define check_add_overflow(a, b, d) __must_check_overflow(({ \ + typeof(a) __a = (a); \ + typeof(b) __b = (b); \ + typeof(d) __d = (d); \ + (void) (&__a == &__b); \ + (void) (&__a == __d); \ + __builtin_add_overflow(__a, __b, __d); \ +})) + #define min_t(type,x,y) \ ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; }) #define max_t(type,x,y) \ @@ -541,6 +570,7 @@ void xfs_log_item_init(struct xfs_mount *mp, struct xfs_log_item *lip, int type, #define xfs_log_in_recovery(mp) (false) /* xfs_icache.c */ +#define xfs_inode_clear_cowblocks_tag(ip) do { } while (0) #define xfs_inode_set_cowblocks_tag(ip) do { } while (0) #define xfs_inode_set_eofblocks_tag(ip) do { } while (0) diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index b80ac04ab..3a91bb3a5 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -21,6 +21,7 @@ #include "xfs_da_format.h" #include "xfs_da_btree.h" #include "xfs_attr.h" +#include "xfs_exchmaps.h" static struct kmem_cache *xfs_defer_pending_cache; @@ -1170,6 +1171,10 @@ xfs_defer_init_item_caches(void) error = xfs_attr_intent_init_cache(); if (error) goto err; + error = xfs_exchmaps_intent_init_cache(); + if (error) + goto err; + return 0; err: xfs_defer_destroy_item_caches(); @@ -1180,6 +1185,7 @@ xfs_defer_init_item_caches(void) void xfs_defer_destroy_item_caches(void) { + xfs_exchmaps_intent_destroy_cache(); xfs_attr_intent_destroy_cache(); xfs_extfree_intent_destroy_cache(); xfs_bmap_intent_destroy_cache(); diff --git a/libxfs/xfs_defer.h b/libxfs/xfs_defer.h index 18a9fb92d..81cca60d7 100644 --- a/libxfs/xfs_defer.h +++ b/libxfs/xfs_defer.h @@ -72,7 +72,7 @@ extern const struct xfs_defer_op_type xfs_rmap_update_defer_type; extern const struct xfs_defer_op_type xfs_extent_free_defer_type; extern const struct xfs_defer_op_type xfs_agfl_free_defer_type; extern const struct xfs_defer_op_type xfs_attr_defer_type; - +extern const struct xfs_defer_op_type xfs_exchmaps_defer_type; /* * Deferred operation item relogging limits. diff --git a/libxfs/xfs_exchmaps.c b/libxfs/xfs_exchmaps.c new file mode 100644 index 000000000..b2c35032d --- /dev/null +++ b/libxfs/xfs_exchmaps.c @@ -0,0 +1,1042 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020-2024 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#include "libxfs_priv.h" +#include "xfs_fs.h" +#include "xfs_shared.h" +#include "xfs_format.h" +#include "xfs_log_format.h" +#include "xfs_trans_resv.h" +#include "xfs_mount.h" +#include "xfs_defer.h" +#include "xfs_inode.h" +#include "xfs_trans.h" +#include "xfs_bmap.h" +#include "xfs_exchmaps.h" +#include "xfs_trace.h" +#include "xfs_bmap_btree.h" +#include "xfs_trans_space.h" +#include "xfs_errortag.h" +#include "xfs_health.h" +#include "defer_item.h" + +struct kmem_cache *xfs_exchmaps_intent_cache; + +/* bmbt mappings adjacent to a pair of records. */ +struct xfs_exchmaps_adjacent { + struct xfs_bmbt_irec left1; + struct xfs_bmbt_irec right1; + struct xfs_bmbt_irec left2; + struct xfs_bmbt_irec right2; +}; + +#define ADJACENT_INIT { \ + .left1 = { .br_startblock = HOLESTARTBLOCK }, \ + .right1 = { .br_startblock = HOLESTARTBLOCK }, \ + .left2 = { .br_startblock = HOLESTARTBLOCK }, \ + .right2 = { .br_startblock = HOLESTARTBLOCK }, \ +} + +/* Information to reset reflink flag / CoW fork state after an exchange. */ + +/* + * If the reflink flag is set on either inode, make sure it has an incore CoW + * fork, since all reflink inodes must have them. If there's a CoW fork and it + * has mappings in it, make sure the inodes are tagged appropriately so that + * speculative preallocations can be GC'd if we run low of space. + */ +static inline void +xfs_exchmaps_ensure_cowfork( + struct xfs_inode *ip) +{ + struct xfs_ifork *cfork; + + if (xfs_is_reflink_inode(ip)) + xfs_ifork_init_cow(ip); + + cfork = xfs_ifork_ptr(ip, XFS_COW_FORK); + if (!cfork) + return; + if (cfork->if_bytes > 0) + xfs_inode_set_cowblocks_tag(ip); + else + xfs_inode_clear_cowblocks_tag(ip); +} + +/* + * Adjust the on-disk inode size upwards if needed so that we never add + * mappings into the file past EOF. This is crucial so that log recovery won't + * get confused by the sudden appearance of post-eof mappings. + */ +STATIC void +xfs_exchmaps_update_size( + struct xfs_trans *tp, + struct xfs_inode *ip, + struct xfs_bmbt_irec *imap, + xfs_fsize_t new_isize) +{ + struct xfs_mount *mp = tp->t_mountp; + xfs_fsize_t len; + + if (new_isize < 0) + return; + + len = min(XFS_FSB_TO_B(mp, imap->br_startoff + imap->br_blockcount), + new_isize); + + if (len <= ip->i_disk_size) + return; + + trace_xfs_exchmaps_update_inode_size(ip, len); + + ip->i_disk_size = len; + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); +} + +/* Advance the incore state tracking after exchanging a mapping. */ +static inline void +xmi_advance( + struct xfs_exchmaps_intent *xmi, + const struct xfs_bmbt_irec *irec) +{ + xmi->xmi_startoff1 += irec->br_blockcount; + xmi->xmi_startoff2 += irec->br_blockcount; + xmi->xmi_blockcount -= irec->br_blockcount; +} + +/* Do we still have more mappings to exchange? */ +static inline bool +xmi_has_more_exchange_work(const struct xfs_exchmaps_intent *xmi) +{ + return xmi->xmi_blockcount > 0; +} + +/* Do we have post-operation cleanups to perform? */ +static inline bool +xmi_has_postop_work(const struct xfs_exchmaps_intent *xmi) +{ + return xmi->xmi_flags & (XFS_EXCHMAPS_CLEAR_INO1_REFLINK | + XFS_EXCHMAPS_CLEAR_INO2_REFLINK); +} + +/* Check all mappings to make sure we can actually exchange them. */ +int +xfs_exchmaps_check_forks( + struct xfs_mount *mp, + const struct xfs_exchmaps_req *req) +{ + struct xfs_ifork *ifp1, *ifp2; + int whichfork = xfs_exchmaps_reqfork(req); + + /* No fork? */ + ifp1 = xfs_ifork_ptr(req->ip1, whichfork); + ifp2 = xfs_ifork_ptr(req->ip2, whichfork); + if (!ifp1 || !ifp2) + return -EINVAL; + + /* We don't know how to exchange local format forks. */ + if (ifp1->if_format == XFS_DINODE_FMT_LOCAL || + ifp2->if_format == XFS_DINODE_FMT_LOCAL) + return -EINVAL; + + /* We don't support realtime data forks yet. */ + if (!XFS_IS_REALTIME_INODE(req->ip1)) + return 0; + if (whichfork == XFS_ATTR_FORK) + return 0; + return -EINVAL; +} + +#ifdef CONFIG_XFS_QUOTA +/* Log the actual updates to the quota accounting. */ +static inline void +xfs_exchmaps_update_quota( + struct xfs_trans *tp, + struct xfs_exchmaps_intent *xmi, + struct xfs_bmbt_irec *irec1, + struct xfs_bmbt_irec *irec2) +{ + int64_t ip1_delta = 0, ip2_delta = 0; + unsigned int qflag; + + qflag = XFS_IS_REALTIME_INODE(xmi->xmi_ip1) ? XFS_TRANS_DQ_RTBCOUNT : + XFS_TRANS_DQ_BCOUNT; + + if (xfs_bmap_is_real_extent(irec1)) { + ip1_delta -= irec1->br_blockcount; + ip2_delta += irec1->br_blockcount; + } + + if (xfs_bmap_is_real_extent(irec2)) { + ip1_delta += irec2->br_blockcount; + ip2_delta -= irec2->br_blockcount; + } + + xfs_trans_mod_dquot_byino(tp, xmi->xmi_ip1, qflag, ip1_delta); + xfs_trans_mod_dquot_byino(tp, xmi->xmi_ip2, qflag, ip2_delta); +} +#else +# define xfs_exchmaps_update_quota(tp, xmi, irec1, irec2) ((void)0) +#endif + +/* Decide if we want to skip this mapping from file1. */ +static inline bool +xfs_exchmaps_can_skip_mapping( + struct xfs_exchmaps_intent *xmi, + struct xfs_bmbt_irec *irec) +{ + /* Do not skip this mapping if the caller did not tell us to. */ + if (!(xmi->xmi_flags & XFS_EXCHMAPS_INO1_WRITTEN)) + return false; + + /* Do not skip mapped, written mappings. */ + if (xfs_bmap_is_written_extent(irec)) + return false; + + /* + * The mapping is unwritten or a hole. It cannot be a delalloc + * reservation because we already excluded those. It cannot be an + * unwritten mapping with dirty page cache because we flushed the page + * cache. We don't support realtime files yet, so we needn't (yet) + * deal with them. + */ + return true; +} + +/* + * Walk forward through the file ranges in @xmi until we find two different + * mappings to exchange. If there is work to do, return the mappings; + * otherwise we've reached the end of the range and xmi_blockcount will be + * zero. + * + * If the walk skips over a pair of mappings to the same storage, save them as + * the left records in @adj (if provided) so that the simulation phase can + * avoid an extra lookup. + */ +static int +xfs_exchmaps_find_mappings( + struct xfs_exchmaps_intent *xmi, + struct xfs_bmbt_irec *irec1, + struct xfs_bmbt_irec *irec2, + struct xfs_exchmaps_adjacent *adj) +{ + int nimaps; + int bmap_flags; + int error; + + bmap_flags = xfs_bmapi_aflag(xfs_exchmaps_whichfork(xmi)); + + for (; xmi_has_more_exchange_work(xmi); xmi_advance(xmi, irec1)) { + /* Read mapping from the first file */ + nimaps = 1; + error = xfs_bmapi_read(xmi->xmi_ip1, xmi->xmi_startoff1, + xmi->xmi_blockcount, irec1, &nimaps, + bmap_flags); + if (error) + return error; + if (nimaps != 1 || + irec1->br_startblock == DELAYSTARTBLOCK || + irec1->br_startoff != xmi->xmi_startoff1) { + /* + * We should never get no mapping or a delalloc mapping + * or something that doesn't match what we asked for, + * since the caller flushed both inodes and we hold the + * ILOCKs for both inodes. + */ + ASSERT(0); + return -EINVAL; + } + + if (xfs_exchmaps_can_skip_mapping(xmi, irec1)) { + trace_xfs_exchmaps_mapping1_skip(xmi->xmi_ip1, irec1); + continue; + } + + /* Read mapping from the second file */ + nimaps = 1; + error = xfs_bmapi_read(xmi->xmi_ip2, xmi->xmi_startoff2, + irec1->br_blockcount, irec2, &nimaps, + bmap_flags); + if (error) + return error; + if (nimaps != 1 || + irec2->br_startblock == DELAYSTARTBLOCK || + irec2->br_startoff != xmi->xmi_startoff2) { + /* + * We should never get no mapping or a delalloc mapping + * or something that doesn't match what we asked for, + * since the caller flushed both inodes and we hold the + * ILOCKs for both inodes. + */ + ASSERT(0); + return -EINVAL; + } + + /* + * We can only exchange as many blocks as the smaller of the + * two mapping maps. + */ + irec1->br_blockcount = min(irec1->br_blockcount, + irec2->br_blockcount); + + trace_xfs_exchmaps_mapping1(xmi->xmi_ip1, irec1); + trace_xfs_exchmaps_mapping2(xmi->xmi_ip2, irec2); + + /* We found something to exchange, so return it. */ + if (irec1->br_startblock != irec2->br_startblock) + return 0; + + /* + * Two mappings pointing to the same physical block must not + * have different states; that's filesystem corruption. Move + * on to the next mapping if they're both holes or both point + * to the same physical space extent. + */ + if (irec1->br_state != irec2->br_state) { + xfs_bmap_mark_sick(xmi->xmi_ip1, + xfs_exchmaps_whichfork(xmi)); + xfs_bmap_mark_sick(xmi->xmi_ip2, + xfs_exchmaps_whichfork(xmi)); + return -EFSCORRUPTED; + } + + /* + * Save the mappings if we're estimating work and skipping + * these identical mappings. + */ + if (adj) { + memcpy(&adj->left1, irec1, sizeof(*irec1)); + memcpy(&adj->left2, irec2, sizeof(*irec2)); + } + } + + return 0; +} + +/* Exchange these two mappings. */ +static void +xfs_exchmaps_one_step( + struct xfs_trans *tp, + struct xfs_exchmaps_intent *xmi, + struct xfs_bmbt_irec *irec1, + struct xfs_bmbt_irec *irec2) +{ + int whichfork = xfs_exchmaps_whichfork(xmi); + + xfs_exchmaps_update_quota(tp, xmi, irec1, irec2); + + /* Remove both mappings. */ + xfs_bmap_unmap_extent(tp, xmi->xmi_ip1, whichfork, irec1); + xfs_bmap_unmap_extent(tp, xmi->xmi_ip2, whichfork, irec2); + + /* + * Re-add both mappings. We exchange the file offsets between the two + * maps and add the opposite map, which has the effect of filling the + * logical offsets we just unmapped, but with with the physical mapping + * information exchanged. + */ + swap(irec1->br_startoff, irec2->br_startoff); + xfs_bmap_map_extent(tp, xmi->xmi_ip1, whichfork, irec2); + xfs_bmap_map_extent(tp, xmi->xmi_ip2, whichfork, irec1); + + /* Make sure we're not adding mappings past EOF. */ + if (whichfork == XFS_DATA_FORK) { + xfs_exchmaps_update_size(tp, xmi->xmi_ip1, irec2, + xmi->xmi_isize1); + xfs_exchmaps_update_size(tp, xmi->xmi_ip2, irec1, + xmi->xmi_isize2); + } + + /* + * Advance our cursor and exit. The caller (either defer ops or log + * recovery) will log the XMD item, and if *blockcount is nonzero, it + * will log a new XMI item for the remainder and call us back. + */ + xmi_advance(xmi, irec1); +} + +/* Clear the reflink flag after an exchange. */ +static inline void +xfs_exchmaps_clear_reflink( + struct xfs_trans *tp, + struct xfs_inode *ip) +{ + trace_xfs_reflink_unset_inode_flag(ip); + + ip->i_diflags2 &= ~XFS_DIFLAG2_REFLINK; + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); +} + +/* Finish whatever work might come after an exchange operation. */ +static int +xfs_exchmaps_do_postop_work( + struct xfs_trans *tp, + struct xfs_exchmaps_intent *xmi) +{ + if (xmi->xmi_flags & XFS_EXCHMAPS_CLEAR_INO1_REFLINK) { + xfs_exchmaps_clear_reflink(tp, xmi->xmi_ip1); + xmi->xmi_flags &= ~XFS_EXCHMAPS_CLEAR_INO1_REFLINK; + } + + if (xmi->xmi_flags & XFS_EXCHMAPS_CLEAR_INO2_REFLINK) { + xfs_exchmaps_clear_reflink(tp, xmi->xmi_ip2); + xmi->xmi_flags &= ~XFS_EXCHMAPS_CLEAR_INO2_REFLINK; + } + + return 0; +} + +/* Finish one step in a mapping exchange operation, possibly relogging. */ +int +xfs_exchmaps_finish_one( + struct xfs_trans *tp, + struct xfs_exchmaps_intent *xmi) +{ + struct xfs_bmbt_irec irec1, irec2; + int error; + + if (xmi_has_more_exchange_work(xmi)) { + /* + * If the operation state says that some range of the files + * have not yet been exchanged, look for mappings in that range + * to exchange. If we find some mappings, exchange them. + */ + error = xfs_exchmaps_find_mappings(xmi, &irec1, &irec2, NULL); + if (error) + return error; + + if (xmi_has_more_exchange_work(xmi)) + xfs_exchmaps_one_step(tp, xmi, &irec1, &irec2); + + /* + * If the caller asked us to exchange the file sizes after the + * exchange and either we just exchanged the last mappings in + * the range or we didn't find anything to exchange, update the + * ondisk file sizes. + */ + if ((xmi->xmi_flags & XFS_EXCHMAPS_SET_SIZES) && + !xmi_has_more_exchange_work(xmi)) { + xmi->xmi_ip1->i_disk_size = xmi->xmi_isize1; + xmi->xmi_ip2->i_disk_size = xmi->xmi_isize2; + + xfs_trans_log_inode(tp, xmi->xmi_ip1, XFS_ILOG_CORE); + xfs_trans_log_inode(tp, xmi->xmi_ip2, XFS_ILOG_CORE); + } + } else if (xmi_has_postop_work(xmi)) { + /* + * Now that we're finished with the exchange operation, + * complete the post-op cleanup work. + */ + error = xfs_exchmaps_do_postop_work(tp, xmi); + if (error) + return error; + } + + /* If we still have work to do, ask for a new transaction. */ + if (xmi_has_more_exchange_work(xmi) || xmi_has_postop_work(xmi)) { + trace_xfs_exchmaps_defer(tp->t_mountp, xmi); + return -EAGAIN; + } + + /* + * If we reach here, we've finished all the exchange work and the post + * operation work. The last thing we need to do before returning to + * the caller is to make sure that COW forks are set up correctly. + */ + if (!(xmi->xmi_flags & XFS_EXCHMAPS_ATTR_FORK)) { + xfs_exchmaps_ensure_cowfork(xmi->xmi_ip1); + xfs_exchmaps_ensure_cowfork(xmi->xmi_ip2); + } + + return 0; +} + +/* + * Compute the amount of bmbt blocks we should reserve for each file. In the + * worst case, each exchange will fill a hole with a new mapping, which could + * result in a btree split every time we add a new leaf block. + */ +static inline uint64_t +xfs_exchmaps_bmbt_blocks( + struct xfs_mount *mp, + const struct xfs_exchmaps_req *req) +{ + return howmany_64(req->nr_exchanges, + XFS_MAX_CONTIG_BMAPS_PER_BLOCK(mp)) * + XFS_EXTENTADD_SPACE_RES(mp, xfs_exchmaps_reqfork(req)); +} + +/* Compute the space we should reserve for the rmap btree expansions. */ +static inline uint64_t +xfs_exchmaps_rmapbt_blocks( + struct xfs_mount *mp, + const struct xfs_exchmaps_req *req) +{ + if (!xfs_has_rmapbt(mp)) + return 0; + if (XFS_IS_REALTIME_INODE(req->ip1)) + return 0; + + return howmany_64(req->nr_exchanges, + XFS_MAX_CONTIG_RMAPS_PER_BLOCK(mp)) * + XFS_RMAPADD_SPACE_RES(mp); +} + +/* Estimate the bmbt and rmapbt overhead required to exchange mappings. */ +static int +xfs_exchmaps_estimate_overhead( + struct xfs_exchmaps_req *req) +{ + struct xfs_mount *mp = req->ip1->i_mount; + xfs_filblks_t bmbt_blocks; + xfs_filblks_t rmapbt_blocks; + xfs_filblks_t resblks = req->resblks; + + /* + * Compute the number of bmbt and rmapbt blocks we might need to handle + * the estimated number of exchanges. + */ + bmbt_blocks = xfs_exchmaps_bmbt_blocks(mp, req); + rmapbt_blocks = xfs_exchmaps_rmapbt_blocks(mp, req); + + trace_xfs_exchmaps_overhead(mp, bmbt_blocks, rmapbt_blocks); + + /* Make sure the change in file block count doesn't overflow. */ + if (check_add_overflow(req->ip1_bcount, bmbt_blocks, &req->ip1_bcount)) + return -EFBIG; + if (check_add_overflow(req->ip2_bcount, bmbt_blocks, &req->ip2_bcount)) + return -EFBIG; + + /* + * Add together the number of blocks we need to handle btree growth, + * then add it to the number of blocks we need to reserve to this + * transaction. + */ + if (check_add_overflow(resblks, bmbt_blocks, &resblks)) + return -ENOSPC; + if (check_add_overflow(resblks, bmbt_blocks, &resblks)) + return -ENOSPC; + if (check_add_overflow(resblks, rmapbt_blocks, &resblks)) + return -ENOSPC; + if (check_add_overflow(resblks, rmapbt_blocks, &resblks)) + return -ENOSPC; + + /* Can't actually reserve more than UINT_MAX blocks. */ + if (req->resblks > UINT_MAX) + return -ENOSPC; + + req->resblks = resblks; + trace_xfs_exchmaps_final_estimate(req); + return 0; +} + +/* Decide if we can merge two real mappings. */ +static inline bool +xmi_can_merge( + const struct xfs_bmbt_irec *b1, + const struct xfs_bmbt_irec *b2) +{ + /* Don't merge holes. */ + if (b1->br_startblock == HOLESTARTBLOCK || + b2->br_startblock == HOLESTARTBLOCK) + return false; + + /* We don't merge holes. */ + if (!xfs_bmap_is_real_extent(b1) || !xfs_bmap_is_real_extent(b2)) + return false; + + if (b1->br_startoff + b1->br_blockcount == b2->br_startoff && + b1->br_startblock + b1->br_blockcount == b2->br_startblock && + b1->br_state == b2->br_state && + b1->br_blockcount + b2->br_blockcount <= XFS_MAX_BMBT_EXTLEN) + return true; + + return false; +} + +/* + * Decide if we can merge three mappings. Caller must ensure all three + * mappings must not be holes or delalloc reservations. + */ +static inline bool +xmi_can_merge_all( + const struct xfs_bmbt_irec *l, + const struct xfs_bmbt_irec *m, + const struct xfs_bmbt_irec *r) +{ + xfs_filblks_t new_len; + + new_len = l->br_blockcount + m->br_blockcount + r->br_blockcount; + return new_len <= XFS_MAX_BMBT_EXTLEN; +} + +#define CLEFT_CONTIG 0x01 +#define CRIGHT_CONTIG 0x02 +#define CHOLE 0x04 +#define CBOTH_CONTIG (CLEFT_CONTIG | CRIGHT_CONTIG) + +#define NLEFT_CONTIG 0x10 +#define NRIGHT_CONTIG 0x20 +#define NHOLE 0x40 +#define NBOTH_CONTIG (NLEFT_CONTIG | NRIGHT_CONTIG) + +/* Estimate the effect of a single exchange on mapping count. */ +static inline int +xmi_delta_nextents_step( + struct xfs_mount *mp, + const struct xfs_bmbt_irec *left, + const struct xfs_bmbt_irec *curr, + const struct xfs_bmbt_irec *new, + const struct xfs_bmbt_irec *right) +{ + bool lhole, rhole, chole, nhole; + unsigned int state = 0; + int ret = 0; + + lhole = left->br_startblock == HOLESTARTBLOCK; + rhole = right->br_startblock == HOLESTARTBLOCK; + chole = curr->br_startblock == HOLESTARTBLOCK; + nhole = new->br_startblock == HOLESTARTBLOCK; + + if (chole) + state |= CHOLE; + if (!lhole && !chole && xmi_can_merge(left, curr)) + state |= CLEFT_CONTIG; + if (!rhole && !chole && xmi_can_merge(curr, right)) + state |= CRIGHT_CONTIG; + if ((state & CBOTH_CONTIG) == CBOTH_CONTIG && + !xmi_can_merge_all(left, curr, right)) + state &= ~CRIGHT_CONTIG; + + if (nhole) + state |= NHOLE; + if (!lhole && !nhole && xmi_can_merge(left, new)) + state |= NLEFT_CONTIG; + if (!rhole && !nhole && xmi_can_merge(new, right)) + state |= NRIGHT_CONTIG; + if ((state & NBOTH_CONTIG) == NBOTH_CONTIG && + !xmi_can_merge_all(left, new, right)) + state &= ~NRIGHT_CONTIG; + + switch (state & (CLEFT_CONTIG | CRIGHT_CONTIG | CHOLE)) { + case CLEFT_CONTIG | CRIGHT_CONTIG: + /* + * left/curr/right are the same mapping, so deleting curr + * causes 2 new mappings to be created. + */ + ret += 2; + break; + case 0: + /* + * curr is not contiguous with any mapping, so we remove curr + * completely + */ + ret--; + break; + case CHOLE: + /* hole, do nothing */ + break; + case CLEFT_CONTIG: + case CRIGHT_CONTIG: + /* trim either left or right, no change */ + break; + } + + switch (state & (NLEFT_CONTIG | NRIGHT_CONTIG | NHOLE)) { + case NLEFT_CONTIG | NRIGHT_CONTIG: + /* + * left/curr/right will become the same mapping, so adding + * curr causes the deletion of right. + */ + ret--; + break; + case 0: + /* new is not contiguous with any mapping */ + ret++; + break; + case NHOLE: + /* hole, do nothing. */ + break; + case NLEFT_CONTIG: + case NRIGHT_CONTIG: + /* new is absorbed into left or right, no change */ + break; + } + + trace_xfs_exchmaps_delta_nextents_step(mp, left, curr, new, right, ret, + state); + return ret; +} + +/* Make sure we don't overflow the extent (mapping) counters. */ +static inline int +xmi_ensure_delta_nextents( + struct xfs_exchmaps_req *req, + struct xfs_inode *ip, + int64_t delta) +{ + struct xfs_mount *mp = ip->i_mount; + int whichfork = xfs_exchmaps_reqfork(req); + struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); + uint64_t new_nextents; + xfs_extnum_t max_nextents; + + if (delta < 0) + return 0; + + /* + * It's always an error if the delta causes integer overflow. delta + * needs an explicit cast here to avoid warnings about implicit casts + * coded into the overflow check. + */ + if (check_add_overflow(ifp->if_nextents, (uint64_t)delta, + &new_nextents)) + return -EFBIG; + + if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_REDUCE_MAX_IEXTENTS) && + new_nextents > 10) + return -EFBIG; + + /* + * We always promote both inodes to have large extent counts if the + * superblock feature is enabled, so we only need to check against the + * theoretical maximum. + */ + max_nextents = xfs_iext_max_nextents(xfs_has_large_extent_counts(mp), + whichfork); + if (new_nextents > max_nextents) + return -EFBIG; + + return 0; +} + +/* Find the next mapping after irec. */ +static inline int +xmi_next( + struct xfs_inode *ip, + int bmap_flags, + const struct xfs_bmbt_irec *irec, + struct xfs_bmbt_irec *nrec) +{ + xfs_fileoff_t off; + xfs_filblks_t blockcount; + int nimaps = 1; + int error; + + off = irec->br_startoff + irec->br_blockcount; + blockcount = XFS_MAX_FILEOFF - off; + error = xfs_bmapi_read(ip, off, blockcount, nrec, &nimaps, bmap_flags); + if (error) + return error; + if (nrec->br_startblock == DELAYSTARTBLOCK || + nrec->br_startoff != off) { + /* + * If we don't get the mapping we want, return a zero-length + * mapping, which our estimator function will pretend is a hole. + * We shouldn't get delalloc reservations. + */ + nrec->br_startblock = HOLESTARTBLOCK; + } + + return 0; +} + +int __init +xfs_exchmaps_intent_init_cache(void) +{ + xfs_exchmaps_intent_cache = kmem_cache_create("xfs_exchmaps_intent", + sizeof(struct xfs_exchmaps_intent), + 0, 0, NULL); + + return xfs_exchmaps_intent_cache != NULL ? 0 : -ENOMEM; +} + +void +xfs_exchmaps_intent_destroy_cache(void) +{ + kmem_cache_destroy(xfs_exchmaps_intent_cache); + xfs_exchmaps_intent_cache = NULL; +} + +/* + * Decide if we will exchange the reflink flags between the two files after the + * exchange. The only time we want to do this is if we're exchanging all + * mappings under EOF and the inode reflink flags have different states. + */ +static inline bool +xmi_can_exchange_reflink_flags( + const struct xfs_exchmaps_req *req, + unsigned int reflink_state) +{ + struct xfs_mount *mp = req->ip1->i_mount; + + if (hweight32(reflink_state) != 1) + return false; + if (req->startoff1 != 0 || req->startoff2 != 0) + return false; + if (req->blockcount != XFS_B_TO_FSB(mp, req->ip1->i_disk_size)) + return false; + if (req->blockcount != XFS_B_TO_FSB(mp, req->ip2->i_disk_size)) + return false; + return true; +} + + +/* Allocate and initialize a new incore intent item from a request. */ +struct xfs_exchmaps_intent * +xfs_exchmaps_init_intent( + const struct xfs_exchmaps_req *req) +{ + struct xfs_exchmaps_intent *xmi; + unsigned int rs = 0; + + xmi = kmem_cache_zalloc(xfs_exchmaps_intent_cache, + GFP_NOFS | __GFP_NOFAIL); + INIT_LIST_HEAD(&xmi->xmi_list); + xmi->xmi_ip1 = req->ip1; + xmi->xmi_ip2 = req->ip2; + xmi->xmi_startoff1 = req->startoff1; + xmi->xmi_startoff2 = req->startoff2; + xmi->xmi_blockcount = req->blockcount; + xmi->xmi_isize1 = xmi->xmi_isize2 = -1; + xmi->xmi_flags = req->flags & XFS_EXCHMAPS_PARAMS; + + if (xfs_exchmaps_whichfork(xmi) == XFS_ATTR_FORK) + return xmi; + + if (req->flags & XFS_EXCHMAPS_SET_SIZES) { + xmi->xmi_flags |= XFS_EXCHMAPS_SET_SIZES; + xmi->xmi_isize1 = req->ip2->i_disk_size; + xmi->xmi_isize2 = req->ip1->i_disk_size; + } + + /* Record the state of each inode's reflink flag before the op. */ + if (xfs_is_reflink_inode(req->ip1)) + rs |= 1; + if (xfs_is_reflink_inode(req->ip2)) + rs |= 2; + + /* + * Figure out if we're clearing the reflink flags (which effectively + * exchanges them) after the operation. + */ + if (xmi_can_exchange_reflink_flags(req, rs)) { + if (rs & 1) + xmi->xmi_flags |= XFS_EXCHMAPS_CLEAR_INO1_REFLINK; + if (rs & 2) + xmi->xmi_flags |= XFS_EXCHMAPS_CLEAR_INO2_REFLINK; + } + + return xmi; +} + +/* + * Estimate the number of exchange operations and the number of file blocks + * in each file that will be affected by the exchange operation. + */ +int +xfs_exchmaps_estimate( + struct xfs_exchmaps_req *req) +{ + struct xfs_exchmaps_intent *xmi; + struct xfs_bmbt_irec irec1, irec2; + struct xfs_exchmaps_adjacent adj = ADJACENT_INIT; + xfs_filblks_t ip1_blocks = 0, ip2_blocks = 0; + int64_t d_nexts1, d_nexts2; + int bmap_flags; + int error; + + ASSERT(!(req->flags & ~XFS_EXCHMAPS_PARAMS)); + + bmap_flags = xfs_bmapi_aflag(xfs_exchmaps_reqfork(req)); + xmi = xfs_exchmaps_init_intent(req); + + /* + * To guard against the possibility of overflowing the extent counters, + * we have to estimate an upper bound on the potential increase in that + * counter. We can split the mapping at each end of the range, and for + * each step of the exchange we can split the mapping that we're + * working on if the mappings do not align. + */ + d_nexts1 = d_nexts2 = 3; + + while (xmi_has_more_exchange_work(xmi)) { + /* + * Walk through the file ranges until we find something to + * exchange. Because we're simulating the exchange, pass in + * adj to capture skipped mappings for correct estimation of + * bmbt record merges. + */ + error = xfs_exchmaps_find_mappings(xmi, &irec1, &irec2, &adj); + if (error) + goto out_free; + if (!xmi_has_more_exchange_work(xmi)) + break; + + /* Update accounting. */ + if (xfs_bmap_is_real_extent(&irec1)) + ip1_blocks += irec1.br_blockcount; + if (xfs_bmap_is_real_extent(&irec2)) + ip2_blocks += irec2.br_blockcount; + req->nr_exchanges++; + + /* Read the next mappings from both files. */ + error = xmi_next(req->ip1, bmap_flags, &irec1, &adj.right1); + if (error) + goto out_free; + + error = xmi_next(req->ip2, bmap_flags, &irec2, &adj.right2); + if (error) + goto out_free; + + /* Update extent count deltas. */ + d_nexts1 += xmi_delta_nextents_step(req->ip1->i_mount, + &adj.left1, &irec1, &irec2, &adj.right1); + + d_nexts2 += xmi_delta_nextents_step(req->ip1->i_mount, + &adj.left2, &irec2, &irec1, &adj.right2); + + /* Now pretend we exchanged the mappings. */ + if (xmi_can_merge(&adj.left2, &irec1)) + adj.left2.br_blockcount += irec1.br_blockcount; + else + memcpy(&adj.left2, &irec1, sizeof(irec1)); + + if (xmi_can_merge(&adj.left1, &irec2)) + adj.left1.br_blockcount += irec2.br_blockcount; + else + memcpy(&adj.left1, &irec2, sizeof(irec2)); + + xmi_advance(xmi, &irec1); + } + + /* Account for the blocks that are being exchanged. */ + if (XFS_IS_REALTIME_INODE(req->ip1) && + xfs_exchmaps_reqfork(req) == XFS_DATA_FORK) { + req->ip1_rtbcount = ip1_blocks; + req->ip2_rtbcount = ip2_blocks; + } else { + req->ip1_bcount = ip1_blocks; + req->ip2_bcount = ip2_blocks; + } + + /* + * Make sure that both forks have enough slack left in their extent + * counters that the exchange operation will not overflow. + */ + trace_xfs_exchmaps_delta_nextents(req, d_nexts1, d_nexts2); + if (req->ip1 == req->ip2) { + error = xmi_ensure_delta_nextents(req, req->ip1, + d_nexts1 + d_nexts2); + } else { + error = xmi_ensure_delta_nextents(req, req->ip1, d_nexts1); + if (error) + goto out_free; + error = xmi_ensure_delta_nextents(req, req->ip2, d_nexts2); + } + if (error) + goto out_free; + + trace_xfs_exchmaps_initial_estimate(req); + error = xfs_exchmaps_estimate_overhead(req); +out_free: + kmem_cache_free(xfs_exchmaps_intent_cache, xmi); + return error; +} + +/* Set the reflink flag before an operation. */ +static inline void +xfs_exchmaps_set_reflink( + struct xfs_trans *tp, + struct xfs_inode *ip) +{ + trace_xfs_reflink_set_inode_flag(ip); + + ip->i_diflags2 |= XFS_DIFLAG2_REFLINK; + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); +} + +/* + * If either file has shared blocks and we're exchanging data forks, we must + * flag the other file as having shared blocks so that we get the shared-block + * rmap functions if we need to fix up the rmaps. + */ +void +xfs_exchmaps_ensure_reflink( + struct xfs_trans *tp, + const struct xfs_exchmaps_intent *xmi) +{ + unsigned int rs = 0; + + if (xfs_is_reflink_inode(xmi->xmi_ip1)) + rs |= 1; + if (xfs_is_reflink_inode(xmi->xmi_ip2)) + rs |= 2; + + if ((rs & 1) && !xfs_is_reflink_inode(xmi->xmi_ip2)) + xfs_exchmaps_set_reflink(tp, xmi->xmi_ip2); + + if ((rs & 2) && !xfs_is_reflink_inode(xmi->xmi_ip1)) + xfs_exchmaps_set_reflink(tp, xmi->xmi_ip1); +} + +/* Set the large extent count flag before an operation if needed. */ +static inline void +xfs_exchmaps_ensure_large_extent_counts( + struct xfs_trans *tp, + struct xfs_inode *ip) +{ + if (xfs_inode_has_large_extent_counts(ip)) + return; + + ip->i_diflags2 |= XFS_DIFLAG2_NREXT64; + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); +} + +/* Widen the extent counter fields of both inodes if necessary. */ +void +xfs_exchmaps_upgrade_extent_counts( + struct xfs_trans *tp, + const struct xfs_exchmaps_intent *xmi) +{ + if (!xfs_has_large_extent_counts(tp->t_mountp)) + return; + + xfs_exchmaps_ensure_large_extent_counts(tp, xmi->xmi_ip1); + xfs_exchmaps_ensure_large_extent_counts(tp, xmi->xmi_ip2); +} + +/* + * Schedule an exchange a range of mappings from one inode to another. + * + * The use of file mapping exchange log intent items ensures the operation can + * be resumed even if the system goes down. The caller must commit the + * transaction to start the work. + * + * The caller must ensure the inodes must be joined to the transaction and + * ILOCKd; they will still be joined to the transaction at exit. + */ +void +xfs_exchange_mappings( + struct xfs_trans *tp, + const struct xfs_exchmaps_req *req) +{ + struct xfs_exchmaps_intent *xmi; + + xfs_assert_ilocked(req->ip1, XFS_ILOCK_EXCL); + xfs_assert_ilocked(req->ip2, XFS_ILOCK_EXCL); + ASSERT(!(req->flags & ~XFS_EXCHMAPS_LOGGED_FLAGS)); + if (req->flags & XFS_EXCHMAPS_SET_SIZES) + ASSERT(!(req->flags & XFS_EXCHMAPS_ATTR_FORK)); + ASSERT(xfs_has_exchange_range(tp->t_mountp)); + + if (req->blockcount == 0) + return; + + xmi = xfs_exchmaps_init_intent(req); + xfs_exchmaps_defer_add(tp, xmi); + xfs_exchmaps_ensure_reflink(tp, xmi); + xfs_exchmaps_upgrade_extent_counts(tp, xmi); +} diff --git a/libxfs/xfs_exchmaps.h b/libxfs/xfs_exchmaps.h new file mode 100644 index 000000000..e8fc3f80c --- /dev/null +++ b/libxfs/xfs_exchmaps.h @@ -0,0 +1,118 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2020-2024 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#ifndef __XFS_EXCHMAPS_H__ +#define __XFS_EXCHMAPS_H__ + +/* In-core deferred operation info about a file mapping exchange request. */ +struct xfs_exchmaps_intent { + /* List of other incore deferred work. */ + struct list_head xmi_list; + + /* Inodes participating in the operation. */ + struct xfs_inode *xmi_ip1; + struct xfs_inode *xmi_ip2; + + /* File offset range information. */ + xfs_fileoff_t xmi_startoff1; + xfs_fileoff_t xmi_startoff2; + xfs_filblks_t xmi_blockcount; + + /* Set these file sizes after the operation, unless negative. */ + xfs_fsize_t xmi_isize1; + xfs_fsize_t xmi_isize2; + + uint64_t xmi_flags; /* XFS_EXCHMAPS_* flags */ +}; + +/* flags that can be passed to xfs_exchmaps_{estimate,mappings} */ +#define XFS_EXCHMAPS_PARAMS (XFS_EXCHMAPS_ATTR_FORK | \ + XFS_EXCHMAPS_SET_SIZES | \ + XFS_EXCHMAPS_INO1_WRITTEN) + +static inline int +xfs_exchmaps_whichfork(const struct xfs_exchmaps_intent *xmi) +{ + if (xmi->xmi_flags & XFS_EXCHMAPS_ATTR_FORK) + return XFS_ATTR_FORK; + return XFS_DATA_FORK; +} + +/* Parameters for a mapping exchange request. */ +struct xfs_exchmaps_req { + /* Inodes participating in the operation. */ + struct xfs_inode *ip1; + struct xfs_inode *ip2; + + /* File offset range information. */ + xfs_fileoff_t startoff1; + xfs_fileoff_t startoff2; + xfs_filblks_t blockcount; + + /* XFS_EXCHMAPS_* operation flags */ + uint64_t flags; + + /* + * Fields below this line are filled out by xfs_exchmaps_estimate; + * callers should initialize this part of the struct to zero. + */ + + /* + * Data device blocks to be moved out of ip1, and free space needed to + * handle the bmbt changes. + */ + xfs_filblks_t ip1_bcount; + + /* + * Data device blocks to be moved out of ip2, and free space needed to + * handle the bmbt changes. + */ + xfs_filblks_t ip2_bcount; + + /* rt blocks to be moved out of ip1. */ + xfs_filblks_t ip1_rtbcount; + + /* rt blocks to be moved out of ip2. */ + xfs_filblks_t ip2_rtbcount; + + /* Free space needed to handle the bmbt changes */ + unsigned long long resblks; + + /* Number of exchanges needed to complete the operation */ + unsigned long long nr_exchanges; +}; + +static inline int +xfs_exchmaps_reqfork(const struct xfs_exchmaps_req *req) +{ + if (req->flags & XFS_EXCHMAPS_ATTR_FORK) + return XFS_ATTR_FORK; + return XFS_DATA_FORK; +} + +int xfs_exchmaps_estimate(struct xfs_exchmaps_req *req); + +extern struct kmem_cache *xfs_exchmaps_intent_cache; + +int __init xfs_exchmaps_intent_init_cache(void); +void xfs_exchmaps_intent_destroy_cache(void); + +struct xfs_exchmaps_intent *xfs_exchmaps_init_intent( + const struct xfs_exchmaps_req *req); +void xfs_exchmaps_ensure_reflink(struct xfs_trans *tp, + const struct xfs_exchmaps_intent *xmi); +void xfs_exchmaps_upgrade_extent_counts(struct xfs_trans *tp, + const struct xfs_exchmaps_intent *xmi); + +int xfs_exchmaps_finish_one(struct xfs_trans *tp, + struct xfs_exchmaps_intent *xmi); + +int xfs_exchmaps_check_forks(struct xfs_mount *mp, + const struct xfs_exchmaps_req *req); + +void xfs_exchange_mappings(struct xfs_trans *tp, + const struct xfs_exchmaps_req *req); + +#endif /* __XFS_EXCHMAPS_H__ */ diff --git a/libxfs/xfs_log_format.h b/libxfs/xfs_log_format.h index 09024431c..8dbe1f997 100644 --- a/libxfs/xfs_log_format.h +++ b/libxfs/xfs_log_format.h @@ -904,7 +904,29 @@ struct xfs_xmi_log_format { uint64_t xmi_isize2; /* intended file2 size */ }; -#define XFS_EXCHMAPS_LOGGED_FLAGS (0) +/* Exchange mappings between extended attribute forks instead of data forks. */ +#define XFS_EXCHMAPS_ATTR_FORK (1ULL << 0) + +/* Set the file sizes when finished. */ +#define XFS_EXCHMAPS_SET_SIZES (1ULL << 1) + +/* + * Exchange the mappings of the two files only if the file allocation units + * mapped to file1's range have been written. + */ +#define XFS_EXCHMAPS_INO1_WRITTEN (1ULL << 2) + +/* Clear the reflink flag from inode1 after the operation. */ +#define XFS_EXCHMAPS_CLEAR_INO1_REFLINK (1ULL << 3) + +/* Clear the reflink flag from inode2 after the operation. */ +#define XFS_EXCHMAPS_CLEAR_INO2_REFLINK (1ULL << 4) + +#define XFS_EXCHMAPS_LOGGED_FLAGS (XFS_EXCHMAPS_ATTR_FORK | \ + XFS_EXCHMAPS_SET_SIZES | \ + XFS_EXCHMAPS_INO1_WRITTEN | \ + XFS_EXCHMAPS_CLEAR_INO1_REFLINK | \ + XFS_EXCHMAPS_CLEAR_INO2_REFLINK) /* This is the structure used to lay out an mapping exchange done log item. */ struct xfs_xmd_log_format { diff --git a/libxfs/xfs_trans_space.h b/libxfs/xfs_trans_space.h index 87b31c69a..9640fc232 100644 --- a/libxfs/xfs_trans_space.h +++ b/libxfs/xfs_trans_space.h @@ -10,6 +10,10 @@ * Components of space reservations. */ +/* Worst case number of bmaps that can be held in a block. */ +#define XFS_MAX_CONTIG_BMAPS_PER_BLOCK(mp) \ + (((mp)->m_bmap_dmxr[0]) - ((mp)->m_bmap_dmnr[0])) + /* Worst case number of rmaps that can be held in a block. */ #define XFS_MAX_CONTIG_RMAPS_PER_BLOCK(mp) \ (((mp)->m_rmap_mxr[0]) - ((mp)->m_rmap_mnr[0])) From patchwork Tue Jul 30 00:25:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745899 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A5371653 for ; Tue, 30 Jul 2024 00:25:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299136; cv=none; b=OAgw5EYwFwCFXVha8lr9/zsYmx9sgvHrk+WbQD5e5l8nD8Uy1cRAGQmnEfOISS4xVXK+EGKKDGAlNXsH3dExQrbEJWMr+1DcHkr9Zhd6OVYB9dtM0prOY/OeBaaMMdrDRKphMAcEDTeHZ8VW9FBQITExYBopNCk1VDGbGyon32U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299136; c=relaxed/simple; bh=8AbjniY70OoOLp4Xo7HplRxrJpZrdWI/8ZLyyw+epig=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Mwkj1UbNwR0vOU9mM3O5ifZN/9TK125zXFU9qe9PD29b4hbuAsV943EHYXbxI8kQwIiXZD/7cQRge+NYaZmH1SKPzHIeRzJxgdcQ63P1LNyXXftY63TNuHvE0aCeIkzhKAR+YJDPhD2Lt26FGpSTi3NGNu12ekUAH6/PK8WtIE8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mAZL2UM2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mAZL2UM2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7609AC32786; Tue, 30 Jul 2024 00:25:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299136; bh=8AbjniY70OoOLp4Xo7HplRxrJpZrdWI/8ZLyyw+epig=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=mAZL2UM2BlR0Cr4E+OCavjFMsMl8mPE1n3OaQd/ChpanzoqciV5noJiQ64enCMgmH BZ8EMlKTLtlTPkXcT9ZhIioAH73/7p0f5bjpNS2z/qytIcOHb3ZBa2T3XGGg4slVVy kote9vmbBBfdkbZ6d2McjLp5eD0AEH2JwVDOB12gNLI3EGNbIJ0L+cNlj+y0U8bNFQ liaKKxoKvk7qI3algb6+NGYt5ZfctwWFsgnadvFUelhQu+w5xO9NKdgMzAXSTp0r+p w1RlYwe2O8TkwPbdBSJHquHzAHZsrtRga8NFb0w9PxQEdVgxdNk0gONkyp92SmcHtY RXEqsG4a2QifA== Date: Mon, 29 Jul 2024 17:25:36 -0700 Subject: [PATCH 007/115] xfs: add error injection to test file mapping exchange recovery From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842540.1338752.4469830307040779156.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 5fd022ec7d420dfca1eaaf997923a5d4dd0dcf62 Add an errortag so that we can test recovery of exchmaps log items. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- io/inject.c | 1 + libxfs/xfs_errortag.h | 4 +++- libxfs/xfs_exchmaps.c | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/io/inject.c b/io/inject.c index 6ef1fc8d2..4aeb6da32 100644 --- a/io/inject.c +++ b/io/inject.c @@ -63,6 +63,7 @@ error_tag(char *name) { XFS_ERRTAG_ATTR_LEAF_TO_NODE, "attr_leaf_to_node" }, { XFS_ERRTAG_WB_DELAY_MS, "wb_delay_ms" }, { XFS_ERRTAG_WRITE_DELAY_MS, "write_delay_ms" }, + { XFS_ERRTAG_EXCHMAPS_FINISH_ONE, "exchmaps_finish_one" }, { XFS_ERRTAG_MAX, NULL } }; int count; diff --git a/libxfs/xfs_errortag.h b/libxfs/xfs_errortag.h index 01a9e86b3..7002d7676 100644 --- a/libxfs/xfs_errortag.h +++ b/libxfs/xfs_errortag.h @@ -63,7 +63,8 @@ #define XFS_ERRTAG_ATTR_LEAF_TO_NODE 41 #define XFS_ERRTAG_WB_DELAY_MS 42 #define XFS_ERRTAG_WRITE_DELAY_MS 43 -#define XFS_ERRTAG_MAX 44 +#define XFS_ERRTAG_EXCHMAPS_FINISH_ONE 44 +#define XFS_ERRTAG_MAX 45 /* * Random factors for above tags, 1 means always, 2 means 1/2 time, etc. @@ -111,5 +112,6 @@ #define XFS_RANDOM_ATTR_LEAF_TO_NODE 1 #define XFS_RANDOM_WB_DELAY_MS 3000 #define XFS_RANDOM_WRITE_DELAY_MS 3000 +#define XFS_RANDOM_EXCHMAPS_FINISH_ONE 1 #endif /* __XFS_ERRORTAG_H_ */ diff --git a/libxfs/xfs_exchmaps.c b/libxfs/xfs_exchmaps.c index b2c35032d..ef30d0b27 100644 --- a/libxfs/xfs_exchmaps.c +++ b/libxfs/xfs_exchmaps.c @@ -434,6 +434,9 @@ xfs_exchmaps_finish_one( return error; } + if (XFS_TEST_ERROR(false, tp->t_mountp, XFS_ERRTAG_EXCHMAPS_FINISH_ONE)) + return -EIO; + /* If we still have work to do, ask for a new transaction. */ if (xmi_has_more_exchange_work(xmi) || xmi_has_postop_work(xmi)) { trace_xfs_exchmaps_defer(tp->t_mountp, xmi); From patchwork Tue Jul 30 00:25:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745900 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5222110E3 for ; Tue, 30 Jul 2024 00:25:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299152; cv=none; b=gJRhij4l8k7Fdr7mtCMZFTQboIcRKRX8dL5hZzoGJYdLM7AY3d0A/B2CxxjMxNhjpiJRN5XpQs+Ssd4Ow5FZ2wt1ohr9O+9kCc9PH+mM2w/+urFLQUqZR2S14443/pwvhg8OUKeWCkdcLknp7Ma2qNmsvOQX01SK9xC5xBNpP5I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299152; c=relaxed/simple; bh=xHade0oEwlt7qy+CUpAwlI7jrhVVf5nfqOrNoxd39k8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oTuV4EB1eoiUY3GO6yE3Vj24U+t9+bbClr6H/wz6LiFJv8lgQuQkdalZ+2qg2SGq16bDEIYti2ibgzbw0viy2CCxPSHgrF3noY9GgNmGQfJbVcF9wDhbGrd3OL5UK2xISOqFjcsYpHyPvX5NaKDMl+8OPHjRFUBGzlW5Bao7KmE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=umk75NU7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="umk75NU7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E2CEC32786; Tue, 30 Jul 2024 00:25:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299152; bh=xHade0oEwlt7qy+CUpAwlI7jrhVVf5nfqOrNoxd39k8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=umk75NU79vqYVvlDlJJdxvM4/2YDtIv7rrZ1Qx+IXa5EmWXfG0P8X5mLIqF4Ekrxf RhYNIm/Gnub51j8U1b+5rOGY/et3ug2jENzDcqqh/7Ukdiu25L6jn21opGRWLY7EmU awJX2rScmWECnUb6uZcDBssKJwzRHDViUJFnyHf0yVs2E9yJLxMV0Sn20/pBt5iEar UygYLBTzLbiu4MOM/IiahhJkRLBeslhmC+L41MsM2xf/oVsqbOK0gIe9peaeY8eRWy VrT5+nCUjxYzwgkT1tvC6BQ/L1EMfb5Sf/cu/jJ5lc2Tf7miCPsc0vdrCvwUEWcdfY t7wivpeTgNxhA== Date: Mon, 29 Jul 2024 17:25:51 -0700 Subject: [PATCH 008/115] xfs: condense extended attributes after a mapping exchange operation From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842555.1338752.7642064315901500418.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 497d7a2608f8b7329e92bdaaf745ca127a582ad9 Add a new file mapping exchange flag that enables us to perform post-exchange processing on file2 once we're done exchanging the extent mappings. If we were swapping mappings between extended attribute forks, we want to be able to convert file2's attr fork from block to inline format. (This implies that all fork contents are exchanged.) This isn't used anywhere right now, but we need to have the basic ondisk flags in place so that a future online xattr repair feature can create salvaged attrs in a temporary file and exchange the attr fork mappings when ready. If one file is in extents format and the other is inline, we will have to promote both to extents format to perform the exchange. After the exchange, we can try to condense the fixed file's attr fork back down to inline format if possible. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_exchmaps.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++-- libxfs/xfs_exchmaps.h | 5 +++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_exchmaps.c b/libxfs/xfs_exchmaps.c index ef30d0b27..afe2c2d22 100644 --- a/libxfs/xfs_exchmaps.c +++ b/libxfs/xfs_exchmaps.c @@ -21,6 +21,10 @@ #include "xfs_errortag.h" #include "xfs_health.h" #include "defer_item.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" +#include "xfs_attr_leaf.h" +#include "xfs_attr.h" struct kmem_cache *xfs_exchmaps_intent_cache; @@ -118,7 +122,8 @@ static inline bool xmi_has_postop_work(const struct xfs_exchmaps_intent *xmi) { return xmi->xmi_flags & (XFS_EXCHMAPS_CLEAR_INO1_REFLINK | - XFS_EXCHMAPS_CLEAR_INO2_REFLINK); + XFS_EXCHMAPS_CLEAR_INO2_REFLINK | + __XFS_EXCHMAPS_INO2_SHORTFORM); } /* Check all mappings to make sure we can actually exchange them. */ @@ -357,6 +362,36 @@ xfs_exchmaps_one_step( xmi_advance(xmi, irec1); } +/* Convert inode2's leaf attr fork back to shortform, if possible.. */ +STATIC int +xfs_exchmaps_attr_to_sf( + struct xfs_trans *tp, + struct xfs_exchmaps_intent *xmi) +{ + struct xfs_da_args args = { + .dp = xmi->xmi_ip2, + .geo = tp->t_mountp->m_attr_geo, + .whichfork = XFS_ATTR_FORK, + .trans = tp, + }; + struct xfs_buf *bp; + int forkoff; + int error; + + if (!xfs_attr_is_leaf(xmi->xmi_ip2)) + return 0; + + error = xfs_attr3_leaf_read(tp, xmi->xmi_ip2, 0, &bp); + if (error) + return error; + + forkoff = xfs_attr_shortform_allfit(bp, xmi->xmi_ip2); + if (forkoff == 0) + return 0; + + return xfs_attr3_leaf_to_shortform(bp, &args, forkoff); +} + /* Clear the reflink flag after an exchange. */ static inline void xfs_exchmaps_clear_reflink( @@ -375,6 +410,16 @@ xfs_exchmaps_do_postop_work( struct xfs_trans *tp, struct xfs_exchmaps_intent *xmi) { + if (xmi->xmi_flags & __XFS_EXCHMAPS_INO2_SHORTFORM) { + int error = 0; + + if (xmi->xmi_flags & XFS_EXCHMAPS_ATTR_FORK) + error = xfs_exchmaps_attr_to_sf(tp, xmi); + xmi->xmi_flags &= ~__XFS_EXCHMAPS_INO2_SHORTFORM; + if (error) + return error; + } + if (xmi->xmi_flags & XFS_EXCHMAPS_CLEAR_INO1_REFLINK) { xfs_exchmaps_clear_reflink(tp, xmi->xmi_ip1); xmi->xmi_flags &= ~XFS_EXCHMAPS_CLEAR_INO1_REFLINK; @@ -806,8 +851,10 @@ xfs_exchmaps_init_intent( xmi->xmi_isize1 = xmi->xmi_isize2 = -1; xmi->xmi_flags = req->flags & XFS_EXCHMAPS_PARAMS; - if (xfs_exchmaps_whichfork(xmi) == XFS_ATTR_FORK) + if (xfs_exchmaps_whichfork(xmi) == XFS_ATTR_FORK) { + xmi->xmi_flags |= __XFS_EXCHMAPS_INO2_SHORTFORM; return xmi; + } if (req->flags & XFS_EXCHMAPS_SET_SIZES) { xmi->xmi_flags |= XFS_EXCHMAPS_SET_SIZES; @@ -1028,6 +1075,8 @@ xfs_exchange_mappings( { struct xfs_exchmaps_intent *xmi; + BUILD_BUG_ON(XFS_EXCHMAPS_INTERNAL_FLAGS & XFS_EXCHMAPS_LOGGED_FLAGS); + xfs_assert_ilocked(req->ip1, XFS_ILOCK_EXCL); xfs_assert_ilocked(req->ip2, XFS_ILOCK_EXCL); ASSERT(!(req->flags & ~XFS_EXCHMAPS_LOGGED_FLAGS)); diff --git a/libxfs/xfs_exchmaps.h b/libxfs/xfs_exchmaps.h index e8fc3f80c..d8718fca6 100644 --- a/libxfs/xfs_exchmaps.h +++ b/libxfs/xfs_exchmaps.h @@ -27,6 +27,11 @@ struct xfs_exchmaps_intent { uint64_t xmi_flags; /* XFS_EXCHMAPS_* flags */ }; +/* Try to convert inode2 from block to short format at the end, if possible. */ +#define __XFS_EXCHMAPS_INO2_SHORTFORM (1ULL << 63) + +#define XFS_EXCHMAPS_INTERNAL_FLAGS (__XFS_EXCHMAPS_INO2_SHORTFORM) + /* flags that can be passed to xfs_exchmaps_{estimate,mappings} */ #define XFS_EXCHMAPS_PARAMS (XFS_EXCHMAPS_ATTR_FORK | \ XFS_EXCHMAPS_SET_SIZES | \ From patchwork Tue Jul 30 00:26:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745901 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 EDE1865C for ; Tue, 30 Jul 2024 00:26:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299168; cv=none; b=eFd4esO84pC9A1dgLRsB4AJ69GDXfF7zM2Qa/Q1TjNRV2IYFeVQOwnaKicVGhDj0dPIyZU/5dnB2+6k2WqPbpwXcahxu/toTNIEjtaCthwesY+io9b7PIKizctWoTMjml/+l0kJNvtnsZRFijoxo2D8JDecO3JNSohWamlbdsPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299168; c=relaxed/simple; bh=Tlc9hpiZGlN3+Yk6s2ofVOqmZ5A/XZeTGiR3XUrtnVA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fsyoHGeDJUJ9WI4Ken7+VNEuarRwMVwPVE2ayugrZ1q1pD7aPar+8FS8MvscG8zGqb+uCCLHt/MrahdOxPoGh23q9KOSv3KfrAd6PVKVgWP/nuqp/UFDHtAFAOx0OXvBNddWvk1rYHWZoo84MvALul5+C555pvQGY3IWKhjmmLQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mBSf8GL4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mBSf8GL4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAA9BC32786; Tue, 30 Jul 2024 00:26:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299167; bh=Tlc9hpiZGlN3+Yk6s2ofVOqmZ5A/XZeTGiR3XUrtnVA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=mBSf8GL4c+cAoK/Ui2mGu+yZcK8VdIxIsPaJ2CioReaIKkmnF51Rwm+2nhd8ZxCYW FdhMjY5AWq+Ku9NIKmfBH7ewvaekT0BaQU4znWmBeTHxtkGP80I8SD7xEeum49/Ft5 sije+XllF8DFC8OO0ugdqs1DuXCpYEog2H3E/nRCT7D5zpB38kS8oWrUUHmwTMa1O+ Ka7JpUHzFFrXRpLnJOUGxdrQ1mAQiE/eA91Qz8XJV/sQ6KFd77ADczQfE6/fWwq/J2 FMaNKqJLXdnTu4XdrPRjcamx4xsaMtQWFYiRXh5aH59bhIqoWIq92gg86e131XGLi7 ahVXw5OVQXPSw== Date: Mon, 29 Jul 2024 17:26:07 -0700 Subject: [PATCH 009/115] xfs: condense directories after a mapping exchange operation From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842568.1338752.15946879769627221761.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: da165fbde23b84591b6ccdf6749277d2d767b770 The previous commit added a new file mapping exchange flag that enables us to perform post-swap processing on file2 once we're done exchanging extent mappings. Now add this ability for directories. This isn't used anywhere right now, but we need to have the basic ondisk flags in place so that a future online directory repair feature can create salvaged dirents in a temporary directory and exchange the data fork mappings when ready. If one file is in extents format and the other is inline, we will have to promote both to extents format to perform the exchange. After the exchange, we can try to condense the fixed directory down to inline format if possible. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_exchmaps.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/libxfs/xfs_exchmaps.c b/libxfs/xfs_exchmaps.c index afe2c2d22..6e758cac1 100644 --- a/libxfs/xfs_exchmaps.c +++ b/libxfs/xfs_exchmaps.c @@ -25,6 +25,8 @@ #include "xfs_da_btree.h" #include "xfs_attr_leaf.h" #include "xfs_attr.h" +#include "xfs_dir2_priv.h" +#include "xfs_dir2.h" struct kmem_cache *xfs_exchmaps_intent_cache; @@ -392,6 +394,42 @@ xfs_exchmaps_attr_to_sf( return xfs_attr3_leaf_to_shortform(bp, &args, forkoff); } +/* Convert inode2's block dir fork back to shortform, if possible.. */ +STATIC int +xfs_exchmaps_dir_to_sf( + struct xfs_trans *tp, + struct xfs_exchmaps_intent *xmi) +{ + struct xfs_da_args args = { + .dp = xmi->xmi_ip2, + .geo = tp->t_mountp->m_dir_geo, + .whichfork = XFS_DATA_FORK, + .trans = tp, + }; + struct xfs_dir2_sf_hdr sfh; + struct xfs_buf *bp; + bool isblock; + int size; + int error; + + error = xfs_dir2_isblock(&args, &isblock); + if (error) + return error; + + if (!isblock) + return 0; + + error = xfs_dir3_block_read(tp, xmi->xmi_ip2, &bp); + if (error) + return error; + + size = xfs_dir2_block_sfsize(xmi->xmi_ip2, bp->b_addr, &sfh); + if (size > xfs_inode_data_fork_size(xmi->xmi_ip2)) + return 0; + + return xfs_dir2_block_to_sf(&args, bp, size, &sfh); +} + /* Clear the reflink flag after an exchange. */ static inline void xfs_exchmaps_clear_reflink( @@ -415,6 +453,8 @@ xfs_exchmaps_do_postop_work( if (xmi->xmi_flags & XFS_EXCHMAPS_ATTR_FORK) error = xfs_exchmaps_attr_to_sf(tp, xmi); + else if (S_ISDIR(VFS_I(xmi->xmi_ip2)->i_mode)) + error = xfs_exchmaps_dir_to_sf(tp, xmi); xmi->xmi_flags &= ~__XFS_EXCHMAPS_INO2_SHORTFORM; if (error) return error; @@ -879,6 +919,9 @@ xfs_exchmaps_init_intent( xmi->xmi_flags |= XFS_EXCHMAPS_CLEAR_INO2_REFLINK; } + if (S_ISDIR(VFS_I(xmi->xmi_ip2)->i_mode)) + xmi->xmi_flags |= __XFS_EXCHMAPS_INO2_SHORTFORM; + return xmi; } From patchwork Tue Jul 30 00:26:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745912 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F181B10E3 for ; Tue, 30 Jul 2024 00:26:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299184; cv=none; b=u8Dzsp8rvZAsQRB4xkvlrQK0kWp0Y3ax0o6uCPIws0S7crUpNb9u4uOxHMUDhxgBaS8SwOaKLVsjn+tOVcYdxAnCySWqvKPGmqTsbcob94jhES437+XOz566oSDNCpt4knou5hkED1v5dqJGz4/vTgPh0C0zvMiKXoOli4B/M7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299184; c=relaxed/simple; bh=zqqE0pDSc94SCcVKaDoqqAJBp1TB/3Fo4Cvx89ltN8s=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EgWa71re65vTbmEVgTbCFaTxzbCHUkoTkO1dLv6tjvMITPRTmFs8fRF0CYgSnVjIS1SRmqhhtDrU2DriZzObnRWDenHGLfTU4NZvvbQgbQshyEc1cAniGsqGlArnfWjMoBhnYcewBoY7Y/NpuUM9e0YU9rk+j9MVOFCnvce6lFY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=j4tflIzC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="j4tflIzC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70813C32786; Tue, 30 Jul 2024 00:26:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299183; bh=zqqE0pDSc94SCcVKaDoqqAJBp1TB/3Fo4Cvx89ltN8s=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=j4tflIzCoiw1fETaE2dfKcLGgiT7Dzv40Sfu+TjJllwjFpDYqp/qXI9iJKtDziEwf TiktW7UvGTpM/oLhpxoA3L4DfYIfERkdOgeYw5IFTAZb0GgrWAZHV8O8gtYye/3bY2 VT9mir4wqBNu70uQNY1wNGjH6uFNcguNN4MhFJ+p5M8cyxX+0AhhsjWj5KwFS2sSaC f6FMSulWWj+benExzp0OLWroFkV0qaXe1EXeR9slBPZ43sFy+Xr82B/C6uSrKcnr6z zDf8BX4DMwsS/D1KH7oAktm1veYYpgq2xWcyh5QQdcA2S8sUx4FAgBw6rP6Zf0QQlw beihwhXo6W+SA== Date: Mon, 29 Jul 2024 17:26:22 -0700 Subject: [PATCH 010/115] xfs: condense symbolic links after a mapping exchange operation From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842582.1338752.12848688005174368044.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 33a9be2b7016e79f47c4c1b523a0aa59d41893c0 The previous commit added a new file mapping exchange flag that enables us to perform post-exchange processing on file2 once we're done exchanging the extent mappings. Now add this ability for symlinks. This isn't used anywhere right now, but we need to have the basic ondisk flags in place so that a future online symlink repair feature can salvage the remote target in a temporary link and exchange the data fork mappings when ready. If one file is in extents format and the other is inline, we will have to promote both to extents format to perform the exchange. After the exchange, we can try to condense the fixed symlink down to inline format if possible. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_exchmaps.c | 49 ++++++++++++++++++++++++++++++++++++++++++- libxfs/xfs_symlink_remote.c | 47 +++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_symlink_remote.h | 1 + 3 files changed, 96 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_exchmaps.c b/libxfs/xfs_exchmaps.c index 6e758cac1..34ac9d5f2 100644 --- a/libxfs/xfs_exchmaps.c +++ b/libxfs/xfs_exchmaps.c @@ -27,6 +27,7 @@ #include "xfs_attr.h" #include "xfs_dir2_priv.h" #include "xfs_dir2.h" +#include "xfs_symlink_remote.h" struct kmem_cache *xfs_exchmaps_intent_cache; @@ -430,6 +431,49 @@ xfs_exchmaps_dir_to_sf( return xfs_dir2_block_to_sf(&args, bp, size, &sfh); } +/* Convert inode2's remote symlink target back to shortform, if possible. */ +STATIC int +xfs_exchmaps_link_to_sf( + struct xfs_trans *tp, + struct xfs_exchmaps_intent *xmi) +{ + struct xfs_inode *ip = xmi->xmi_ip2; + struct xfs_ifork *ifp = xfs_ifork_ptr(ip, XFS_DATA_FORK); + char *buf; + int error; + + if (ifp->if_format == XFS_DINODE_FMT_LOCAL || + ip->i_disk_size > xfs_inode_data_fork_size(ip)) + return 0; + + /* Read the current symlink target into a buffer. */ + buf = kmalloc(ip->i_disk_size + 1, + GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL); + if (!buf) { + ASSERT(0); + return -ENOMEM; + } + + error = xfs_symlink_remote_read(ip, buf); + if (error) + goto free; + + /* Remove the blocks. */ + error = xfs_symlink_remote_truncate(tp, ip); + if (error) + goto free; + + /* Convert fork to local format and log our changes. */ + xfs_idestroy_fork(ifp); + ifp->if_bytes = 0; + ifp->if_format = XFS_DINODE_FMT_LOCAL; + xfs_init_local_fork(ip, XFS_DATA_FORK, buf, ip->i_disk_size); + xfs_trans_log_inode(tp, ip, XFS_ILOG_DDATA | XFS_ILOG_CORE); +free: + kfree(buf); + return error; +} + /* Clear the reflink flag after an exchange. */ static inline void xfs_exchmaps_clear_reflink( @@ -455,6 +499,8 @@ xfs_exchmaps_do_postop_work( error = xfs_exchmaps_attr_to_sf(tp, xmi); else if (S_ISDIR(VFS_I(xmi->xmi_ip2)->i_mode)) error = xfs_exchmaps_dir_to_sf(tp, xmi); + else if (S_ISLNK(VFS_I(xmi->xmi_ip2)->i_mode)) + error = xfs_exchmaps_link_to_sf(tp, xmi); xmi->xmi_flags &= ~__XFS_EXCHMAPS_INO2_SHORTFORM; if (error) return error; @@ -919,7 +965,8 @@ xfs_exchmaps_init_intent( xmi->xmi_flags |= XFS_EXCHMAPS_CLEAR_INO2_REFLINK; } - if (S_ISDIR(VFS_I(xmi->xmi_ip2)->i_mode)) + if (S_ISDIR(VFS_I(xmi->xmi_ip2)->i_mode) || + S_ISLNK(VFS_I(xmi->xmi_ip2)->i_mode)) xmi->xmi_flags |= __XFS_EXCHMAPS_INO2_SHORTFORM; return xmi; diff --git a/libxfs/xfs_symlink_remote.c b/libxfs/xfs_symlink_remote.c index 875e03bcb..72f175990 100644 --- a/libxfs/xfs_symlink_remote.c +++ b/libxfs/xfs_symlink_remote.c @@ -377,3 +377,50 @@ xfs_symlink_write_target( ASSERT(pathlen == 0); return 0; } + +/* Remove all the blocks from a symlink and invalidate buffers. */ +int +xfs_symlink_remote_truncate( + struct xfs_trans *tp, + struct xfs_inode *ip) +{ + struct xfs_bmbt_irec mval[XFS_SYMLINK_MAPS]; + struct xfs_mount *mp = tp->t_mountp; + struct xfs_buf *bp; + int nmaps = XFS_SYMLINK_MAPS; + int done = 0; + int i; + int error; + + /* Read mappings and invalidate buffers. */ + error = xfs_bmapi_read(ip, 0, XFS_MAX_FILEOFF, mval, &nmaps, 0); + if (error) + return error; + + for (i = 0; i < nmaps; i++) { + if (!xfs_bmap_is_real_extent(&mval[i])) + break; + + error = xfs_trans_get_buf(tp, mp->m_ddev_targp, + XFS_FSB_TO_DADDR(mp, mval[i].br_startblock), + XFS_FSB_TO_BB(mp, mval[i].br_blockcount), 0, + &bp); + if (error) + return error; + + xfs_trans_binval(tp, bp); + } + + /* Unmap the remote blocks. */ + error = xfs_bunmapi(tp, ip, 0, XFS_MAX_FILEOFF, 0, nmaps, &done); + if (error) + return error; + if (!done) { + ASSERT(done); + xfs_inode_mark_sick(ip, XFS_SICK_INO_SYMLINK); + return -EFSCORRUPTED; + } + + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); + return 0; +} diff --git a/libxfs/xfs_symlink_remote.h b/libxfs/xfs_symlink_remote.h index a63bd38ae..ac3dac8f6 100644 --- a/libxfs/xfs_symlink_remote.h +++ b/libxfs/xfs_symlink_remote.h @@ -22,5 +22,6 @@ int xfs_symlink_remote_read(struct xfs_inode *ip, char *link); int xfs_symlink_write_target(struct xfs_trans *tp, struct xfs_inode *ip, const char *target_path, int pathlen, xfs_fsblock_t fs_blocks, uint resblks); +int xfs_symlink_remote_truncate(struct xfs_trans *tp, struct xfs_inode *ip); #endif /* __XFS_SYMLINK_REMOTE_H */ From patchwork Tue Jul 30 00:26:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745913 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 44CB81361 for ; Tue, 30 Jul 2024 00:26:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299199; cv=none; b=L51ZLHb4er2mIQYpcO6GH4D6yb6MlHRreegFRqc4sV4uE9OAZBp8CGCR1TcA8etfuYQJslKTBZulg2ArQG4Luda1d5l/2zcqLBq0OGoBpmAdJG/qrtpMw6xJMTEmawc/vCLaUTD4E8PS5BJ7H5pbPhNpOkb89x+hBazZifg7DWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299199; c=relaxed/simple; bh=k0ZktlBYfMQULT3Gdav2tNpux228pBkWXHtQlzP7zVo=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tughfNW33Z35MDF7Gqk9wLJpKvGolirBgx5e9wyxldCGFux3Phfm8n1ncYrKJnm7THI/Qvj/GFLTruKfqmYq+cNTOIGSNZnL1IRD9vOsKqyRTUcPT496xi+I6GJNPfx7PiLUzISSHjP5JItO5njHVGs6+ORNkvRkRk7zkBCiS+s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GW8Ck1tO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GW8Ck1tO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 192F9C32786; Tue, 30 Jul 2024 00:26:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299199; bh=k0ZktlBYfMQULT3Gdav2tNpux228pBkWXHtQlzP7zVo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=GW8Ck1tOn6nm5Gswck6TjP5en3ITCccm9d1DyM5KvwtXSKf+ftgLDsKLmLoacLDTL UpSOAP3ld54RgqxtewSlwCFV8e6u0NiEwHtx0lhNctGGliuC5JxWnAL/XiHZktecc7 x5N16XrTQqL3AfCMZstGoCT4UV6eJeYWSYILsKgcqBg9Z7A3P7MlZmoZdnQvHjkeZb W2254TE3lJgAUC6jHT3I5WtfLJP+lTwPidVu9e2NFcCdexM8xVAtCU1JgVIxI70xsi I3vjQZhQa6BVgHcHcnGFjL+3zXa+rjCEcBDkF7ejLQWTufwIVZFj+0lN2bOQkOeHHb fYwvY4BLZiUcg== Date: Mon, 29 Jul 2024 17:26:38 -0700 Subject: [PATCH 011/115] xfs: make file range exchange support realtime files From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842596.1338752.16136594403263694499.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: e62941103faa2eedba6a155316e059a490c743a6 Now that bmap items support the realtime device, we can add the necessary pieces to the file range exchange code to support exchanging mappings. All we really need to do here is adjust the blockcount upwards to the end of the rt extent and remove the inode checks. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- include/xfs_inode.h | 10 +++++++ libxfs/xfs_exchmaps.c | 70 ++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 70 insertions(+), 10 deletions(-) diff --git a/include/xfs_inode.h b/include/xfs_inode.h index a351bb0d9..825708383 100644 --- a/include/xfs_inode.h +++ b/include/xfs_inode.h @@ -325,6 +325,16 @@ static inline bool xfs_inode_has_large_extent_counts(struct xfs_inode *ip) return ip->i_diflags2 & XFS_DIFLAG2_NREXT64; } + +/* + * Decide if this file is a realtime file whose data allocation unit is larger + * than a single filesystem block. + */ +static inline bool xfs_inode_has_bigrtalloc(struct xfs_inode *ip) +{ + return XFS_IS_REALTIME_INODE(ip) && ip->i_mount->m_sb.sb_rextsize > 1; +} + /* Always set the child's GID to this value, even if the parent is setgid. */ #define CRED_FORCE_GID (1U << 0) struct cred { diff --git a/libxfs/xfs_exchmaps.c b/libxfs/xfs_exchmaps.c index 34ac9d5f2..37e58d088 100644 --- a/libxfs/xfs_exchmaps.c +++ b/libxfs/xfs_exchmaps.c @@ -149,12 +149,7 @@ xfs_exchmaps_check_forks( ifp2->if_format == XFS_DINODE_FMT_LOCAL) return -EINVAL; - /* We don't support realtime data forks yet. */ - if (!XFS_IS_REALTIME_INODE(req->ip1)) - return 0; - if (whichfork == XFS_ATTR_FORK) - return 0; - return -EINVAL; + return 0; } #ifdef CONFIG_XFS_QUOTA @@ -195,6 +190,8 @@ xfs_exchmaps_can_skip_mapping( struct xfs_exchmaps_intent *xmi, struct xfs_bmbt_irec *irec) { + struct xfs_mount *mp = xmi->xmi_ip1->i_mount; + /* Do not skip this mapping if the caller did not tell us to. */ if (!(xmi->xmi_flags & XFS_EXCHMAPS_INO1_WRITTEN)) return false; @@ -206,11 +203,64 @@ xfs_exchmaps_can_skip_mapping( /* * The mapping is unwritten or a hole. It cannot be a delalloc * reservation because we already excluded those. It cannot be an - * unwritten mapping with dirty page cache because we flushed the page - * cache. We don't support realtime files yet, so we needn't (yet) - * deal with them. + * unwritten extent with dirty page cache because we flushed the page + * cache. For files where the allocation unit is 1FSB (files on the + * data dev, rt files if the extent size is 1FSB), we can safely + * skip this mapping. */ - return true; + if (!xfs_inode_has_bigrtalloc(xmi->xmi_ip1)) + return true; + + /* + * For a realtime file with a multi-fsb allocation unit, the decision + * is trickier because we can only swap full allocation units. + * Unwritten mappings can appear in the middle of an rtx if the rtx is + * partially written, but they can also appear for preallocations. + * + * If the mapping is a hole, skip it entirely. Holes should align with + * rtx boundaries. + */ + if (!xfs_bmap_is_real_extent(irec)) + return true; + + /* + * All mappings below this point are unwritten. + * + * - If the beginning is not aligned to an rtx, trim the end of the + * mapping so that it does not cross an rtx boundary, and swap it. + * + * - If both ends are aligned to an rtx, skip the entire mapping. + */ + if (!isaligned_64(irec->br_startoff, mp->m_sb.sb_rextsize)) { + xfs_fileoff_t new_end; + + new_end = roundup_64(irec->br_startoff, mp->m_sb.sb_rextsize); + irec->br_blockcount = min(irec->br_blockcount, + new_end - irec->br_startoff); + return false; + } + if (isaligned_64(irec->br_blockcount, mp->m_sb.sb_rextsize)) + return true; + + /* + * All mappings below this point are unwritten, start on an rtx + * boundary, and do not end on an rtx boundary. + * + * - If the mapping is longer than one rtx, trim the end of the mapping + * down to an rtx boundary and skip it. + * + * - The mapping is shorter than one rtx. Swap it. + */ + if (irec->br_blockcount > mp->m_sb.sb_rextsize) { + xfs_fileoff_t new_end; + + new_end = rounddown_64(irec->br_startoff + irec->br_blockcount, + mp->m_sb.sb_rextsize); + irec->br_blockcount = new_end - irec->br_startoff; + return true; + } + + return false; } /* From patchwork Tue Jul 30 00:26:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745914 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 367FC184E for ; Tue, 30 Jul 2024 00:26:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299215; cv=none; b=n18KNdjSnevCFZsJtRw9ChGgTjOO/wyy0zHIBS4MYc7MhnEOHM/jw0gN13BDjBkquSAzKZ8TKv7Xtfj6tfqT1Hs30IN63lmW8q1920OTbJN7iu0aLCV4N2VBFhG6PqQpU8AghUrxB1uYMWcmAXz1c/awExNQfLof4Ae/NhOuyPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299215; c=relaxed/simple; bh=iUq8o3oNa45FJ6P146tUzG7jT9mTzOy09+KkBgU+gEU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HgPzAeohEkkRYlYK3y5hYCE9hJIiqCKpZ0NsOc1j657xQLEYfMr8KzvZ1EZrSuKU7JOMxqrNm2bve79ufPZbrVomVEU3KzMrq/9ZXEPJ+40zB5cFoDNMw3jcnvuTcWjFX7pSg+oVXp8F19bjLJNHCobLtTMFu6vupbuWjtJWt5s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Aj5QLmVf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Aj5QLmVf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEF5CC32786; Tue, 30 Jul 2024 00:26:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299214; bh=iUq8o3oNa45FJ6P146tUzG7jT9mTzOy09+KkBgU+gEU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Aj5QLmVf5H6LS3yXJ3ns5DKRb3ikXszvtyb70zGceMMZJG97/C2i3FgeLsKN/eqFg BKmziUVE4BMVVE8lJrFpWcAWbHFt1vFDe/FZ6x5dHBjGbEvhPRCfkqr4Bdo2A21AQh Y8+PeElMUKLk97Nebz1vkEOCq7bQC7xaBz8K0dlo2d83I1lVHGq652jUjxLyVqbG7l JbItk1rwqX7DRF8Z3cTlqTW0uK3ItFkwLwalPONp+L9sncl8LtKGDrRNci1K1zJ9V2 BnC0P5/vyTOc1vigYV0RNE4NJ/thXhgohlzcGJaRx+T/XYawZpQknsyQ6A0z8pJmJa JEfj+Xt+XcKJg== Date: Mon, 29 Jul 2024 17:26:54 -0700 Subject: [PATCH 012/115] xfs: capture inode generation numbers in the ondisk exchmaps log item From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842611.1338752.17028313336357311290.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 14f19991020b3c712d626727c17599f134cc6efa Per some very late review comments, capture the generation numbers of both inodes involved in a file content exchange operation so that we don't accidentally target files with have been reallocated. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_log_format.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libxfs/xfs_log_format.h b/libxfs/xfs_log_format.h index 8dbe1f997..accba2acd 100644 --- a/libxfs/xfs_log_format.h +++ b/libxfs/xfs_log_format.h @@ -896,6 +896,8 @@ struct xfs_xmi_log_format { uint64_t xmi_inode1; /* inumber of first file */ uint64_t xmi_inode2; /* inumber of second file */ + uint32_t xmi_igen1; /* generation of first file */ + uint32_t xmi_igen2; /* generation of second file */ uint64_t xmi_startoff1; /* block offset into file1 */ uint64_t xmi_startoff2; /* block offset into file2 */ uint64_t xmi_blockcount; /* number of blocks */ From patchwork Tue Jul 30 00:27:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745915 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8381120E6 for ; Tue, 30 Jul 2024 00:27:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299230; cv=none; b=n/3yRBm3jUQyudjXKqhpV7gOXFWlxEkDDSeqVtHdKqQwshYityxJlFybm6HmT588oLpo/iYMWn0tQpCCPpLN3Aeiz8UzOE1PwZKsN01sPzxnRcSeGXK+L8HvMgcpyNMHb5P12VuomLDRpx/nYpiJcwW00FW31C+xfyEcHn+WWjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299230; c=relaxed/simple; bh=gkANiSMVHJHbumugeu9FuemCFpUu2wUEQkLsq3X/rfo=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bll/TJIXrTj8gByIN5QGsGJEDYYYTlGVj26cFEywFjbTzk+TuB2L87mmFbAk7lxDEMh3txmLrqYRREF7fzBoKKF0e2uSBlQYb4Bke8c4PUe0OjrREARx3+Aowb2fpQ+w6y7yzGClr0zUON4loEehzRh7zAhkT/GAOvy+om6lO4M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k1g/bJlX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="k1g/bJlX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CCD4C32786; Tue, 30 Jul 2024 00:27:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299230; bh=gkANiSMVHJHbumugeu9FuemCFpUu2wUEQkLsq3X/rfo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=k1g/bJlXdLlG47GOCXFBLywRt8ajmaRTnXgq1fFppSgi3x8gudmuBdxQDdIg0uMne 0ec20HA8FZX3AGAWYVwqAVuUzXWdQRtJdBIX8eGVjVCnh8B/Y6kTaZzjNZkQeKLSnz tCfzb5m2Jf/ofQcZZ7cHSMNbGY8GlFM7bpK78zpCR71/rd8XjUBcwlD6jrjt0s/C5C FzNqu3nvdCIMDQDjlFmOcZJ2zJb/t6opcbyXBjlszN2DGj5Rg+8kc3wzEefDoDhgfN JfqJOb44KfBHj9Y2ehkRyJ921N2DQ6fJ6m97zhcWyq0hFsxEvb0yOFhvo642vEpKi2 h3uF0tCGBRI9g== Date: Mon, 29 Jul 2024 17:27:09 -0700 Subject: [PATCH 013/115] xfs: enable logged file mapping exchange feature From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842625.1338752.3670668512753428716.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 0730e8d8ba1d1507f1d7fd719e1f835ce69961fe Add the XFS_SB_FEAT_INCOMPAT_EXCHRANGE feature to the set of features that we will permit when mounting a filesystem. This turns on support for the file range exchange feature. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_format.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index ff1e28316..10153ce11 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -380,7 +380,8 @@ xfs_sb_has_ro_compat_feature( XFS_SB_FEAT_INCOMPAT_META_UUID | \ XFS_SB_FEAT_INCOMPAT_BIGTIME | \ XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR | \ - XFS_SB_FEAT_INCOMPAT_NREXT64) + XFS_SB_FEAT_INCOMPAT_NREXT64 | \ + XFS_SB_FEAT_INCOMPAT_EXCHRANGE) #define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL static inline bool From patchwork Tue Jul 30 00:27:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745916 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2EA472563 for ; Tue, 30 Jul 2024 00:27:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299246; cv=none; b=JyIwTAzngm8yo8v0D6tJc72bir9q+8JI39FttturYUEOEqef80FpNHAblPIjB4U68TrvY8waVkXfedKKkmH5IQNn6LDDAsjLaS8a8ToNOE7DaC1vpfpO4QeqKQ19WT/NPLEEjiDIUayYm6NTdJrK54LvqMZcgXLvAn63q7+jSfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299246; c=relaxed/simple; bh=K5+SkDc9nrGKcmzS2HycCanzqR2XXo4U/7jZXt/cQ7Y=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tDkKGMK+hRCzIVVc+Bt0uJSMDzLpX8e4NYjCZ32GCXhhEmKcrqddmvBSHL9ngxgL+RopyA/cBLA0jq2UUs5xyYGI5w/0QfJ6U2T/V067QWemQ3iPEUGDQFuIUjygHieFPpd5usy25XMXsrTzYk8sbKVAMYHMZgB5wSB2DrgSzdg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jRZ3J6Yi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jRZ3J6Yi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02E90C32786; Tue, 30 Jul 2024 00:27:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299246; bh=K5+SkDc9nrGKcmzS2HycCanzqR2XXo4U/7jZXt/cQ7Y=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=jRZ3J6YiBIOsfuedhT4nd7QGw5TUBCaIpIDAXWke29eZXlomm61VpZEcTABgCxLHg 89VcOndM/m8U9HctiOLrsUCttPLIsVqwehoY3xRgRQoUQWmiL/6oCFVXR3ewFqPj9C pe5PzC6dYV8VB+0jLUctYAFNg9LIQ+/bFx7gNyKp/kkHv2V6ERe5K//+pyYey3toej nR8LCl6BFzraqnPmOl4fTMJACQGgLmVAASRJC20krpmmhDeVW24nKTlGbdKCATXrQR gO9GrOxtE71SEG65GRlZnl6ZM+FkbLaGtcX4ID3e1TRDKPhPES+Uxj7v3cTUAAXMfr Bd5xcQukzH1uQ== Date: Mon, 29 Jul 2024 17:27:25 -0700 Subject: [PATCH 014/115] xfs: add an explicit owner field to xfs_da_args From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842639.1338752.9671858425538758638.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 9eef772f3a194f6841850e45dacdf4207ec7da84 Add an explicit owner field to xfs_da_args, which will make it easier for online fsck to set the owner field of the temporary directory and xattr structures that it builds to repair damaged metadata. Note: I hopefully found all the xfs_da_args definitions by looking for automatic stack variable declarations and xfs_da_args.dp assignments: git grep -E '(args.*dp =|struct xfs_da_args[[:space:]]*[a-z0-9][a-z0-9]*)' Note that callers of xfs_attr_{get,set,change} can set the owner to zero (or leave it unset) to have the default set to args->dp. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr.c | 4 ++++ libxfs/xfs_attr_leaf.c | 2 ++ libxfs/xfs_bmap.c | 1 + libxfs/xfs_da_btree.h | 1 + libxfs/xfs_dir2.c | 5 +++++ libxfs/xfs_exchmaps.c | 2 ++ 6 files changed, 15 insertions(+) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index caf04daa7..21b5d922b 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -262,6 +262,8 @@ xfs_attr_get( if (xfs_is_shutdown(args->dp->i_mount)) return -EIO; + if (!args->owner) + args->owner = args->dp->i_ino; args->geo = args->dp->i_mount->m_attr_geo; args->whichfork = XFS_ATTR_FORK; args->hashval = xfs_da_hashname(args->name, args->namelen); @@ -935,6 +937,8 @@ xfs_attr_set( if (error) return error; + if (!args->owner) + args->owner = args->dp->i_ino; args->geo = mp->m_attr_geo; args->whichfork = XFS_ATTR_FORK; args->hashval = xfs_da_hashname(args->name, args->namelen); diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index a44312cdc..393e5e6ca 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -901,6 +901,7 @@ xfs_attr_shortform_to_leaf( nargs.whichfork = XFS_ATTR_FORK; nargs.trans = args->trans; nargs.op_flags = XFS_DA_OP_OKNOENT; + nargs.owner = args->owner; sfe = xfs_attr_sf_firstentry(sf); for (i = 0; i < sf->count; i++) { @@ -1103,6 +1104,7 @@ xfs_attr3_leaf_to_shortform( nargs.whichfork = XFS_ATTR_FORK; nargs.trans = args->trans; nargs.op_flags = XFS_DA_OP_OKNOENT; + nargs.owner = args->owner; for (i = 0; i < ichdr.count; entry++, i++) { if (entry->flags & XFS_ATTR_INCOMPLETE) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index b089f53e0..868334229 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -970,6 +970,7 @@ xfs_bmap_add_attrfork_local( dargs.total = dargs.geo->fsbcount; dargs.whichfork = XFS_DATA_FORK; dargs.trans = tp; + dargs.owner = ip->i_ino; return xfs_dir2_sf_to_block(&dargs); } diff --git a/libxfs/xfs_da_btree.h b/libxfs/xfs_da_btree.h index 706baf36e..7fb13f26e 100644 --- a/libxfs/xfs_da_btree.h +++ b/libxfs/xfs_da_btree.h @@ -79,6 +79,7 @@ typedef struct xfs_da_args { int rmtvaluelen2; /* remote attr value length in bytes */ uint32_t op_flags; /* operation flags */ enum xfs_dacmp cmpresult; /* name compare result for lookups */ + xfs_ino_t owner; /* inode that owns the dir/attr data */ } xfs_da_args_t; /* diff --git a/libxfs/xfs_dir2.c b/libxfs/xfs_dir2.c index 530c3e22a..803fb82b2 100644 --- a/libxfs/xfs_dir2.c +++ b/libxfs/xfs_dir2.c @@ -249,6 +249,7 @@ xfs_dir_init( args->geo = dp->i_mount->m_dir_geo; args->dp = dp; args->trans = tp; + args->owner = dp->i_ino; error = xfs_dir2_sf_create(args, pdp->i_ino); kfree(args); return error; @@ -294,6 +295,7 @@ xfs_dir_createname( args->whichfork = XFS_DATA_FORK; args->trans = tp; args->op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT; + args->owner = dp->i_ino; if (!inum) args->op_flags |= XFS_DA_OP_JUSTCHECK; @@ -382,6 +384,7 @@ xfs_dir_lookup( args->whichfork = XFS_DATA_FORK; args->trans = tp; args->op_flags = XFS_DA_OP_OKNOENT; + args->owner = dp->i_ino; if (ci_name) args->op_flags |= XFS_DA_OP_CILOOKUP; @@ -455,6 +458,7 @@ xfs_dir_removename( args->total = total; args->whichfork = XFS_DATA_FORK; args->trans = tp; + args->owner = dp->i_ino; if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) { rval = xfs_dir2_sf_removename(args); @@ -516,6 +520,7 @@ xfs_dir_replace( args->total = total; args->whichfork = XFS_DATA_FORK; args->trans = tp; + args->owner = dp->i_ino; if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) { rval = xfs_dir2_sf_replace(args); diff --git a/libxfs/xfs_exchmaps.c b/libxfs/xfs_exchmaps.c index 37e58d088..6160beef1 100644 --- a/libxfs/xfs_exchmaps.c +++ b/libxfs/xfs_exchmaps.c @@ -426,6 +426,7 @@ xfs_exchmaps_attr_to_sf( .geo = tp->t_mountp->m_attr_geo, .whichfork = XFS_ATTR_FORK, .trans = tp, + .owner = xmi->xmi_ip2->i_ino, }; struct xfs_buf *bp; int forkoff; @@ -456,6 +457,7 @@ xfs_exchmaps_dir_to_sf( .geo = tp->t_mountp->m_dir_geo, .whichfork = XFS_DATA_FORK, .trans = tp, + .owner = xmi->xmi_ip2->i_ino, }; struct xfs_dir2_sf_hdr sfh; struct xfs_buf *bp; From patchwork Tue Jul 30 00:27:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745917 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D3EFC1FBA for ; Tue, 30 Jul 2024 00:27:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299261; cv=none; b=PCMERi1embNteuy5aUcD58djKGlRnfNWEaHOGcjrVYfAEvuO/PTAEHe3zB2inZPtKS7jjMHCvXSbegy6JRclxzDUuFSY7DTBlsilhhObgfO2MmB/XgI87F/0Dw644v099iKr1UQb7Irin+JfEzGpoYGD8pv+cruBL07pqdEa94E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299261; c=relaxed/simple; bh=4R4eGEUR0tEM5vw1780MoWlg01l97tShRcYH7TXoaWM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MhNINfYXluxGDawnYsw3z/E398LMhSyWXtcoI6ZrD3lXR3TTmMzUhiIlnblUVdBa8Q770QzFcF4Hqk0QQ08wNtxNsPaHMVixvjBfDuCWr0XxxWwtopdhWNvMTIw3HFaou+jYgsfc0IUl3hhTkBXKl4Q5mQa0xqgCKYWVq+vDNYA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aTEE2srC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aTEE2srC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9ED0C32786; Tue, 30 Jul 2024 00:27:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299261; bh=4R4eGEUR0tEM5vw1780MoWlg01l97tShRcYH7TXoaWM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=aTEE2srCR0FrGPToGaTztXuUVM9hZ2uUiqKPlADQaxs6WH64Ek18Yxh5ZoNjhMCSA sFN5dIaQnvI8vh1i/4L5MhwP+GSpZ8wsPdVlqXrtUa9TeS0Qr6wUYvJOFZQ+fvcsqk ffnieMZ36etWWR0cu+O/WMtyeQMuH+rtvicG10xwi6XSQPYng32ol1LH0Emas1d0Ng RioqTNrBrSe7QgKxNW2s+Ga1cY3Ha+1copn73zXwBHriu1S1QvH/FEjt5DaxrqaJa9 YAbLZaKLJA2RzKyuCPWx/2cO5Hr5h8YNuNr/+0Q0QFVbax3YGsF9S60ov4ZCL57vi8 SioHqdh1tmzFQ== Date: Mon, 29 Jul 2024 17:27:41 -0700 Subject: [PATCH 015/115] xfs: use the xfs_da_args owner field to set new dir/attr block owner From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842653.1338752.12415500951052456960.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 17a85dc64ae0804d33a2293686fc987a830a462d When we're creating leaf, data, freespace, or dabtree blocks for directories and xattrs, use the explicit owner field (instead of the xfs_inode) to set the owner field. This will enable online repair to construct replacement data structures in a temporary file without having to change the owner fields prior to swapping the new and old structures. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr_leaf.c | 2 +- libxfs/xfs_attr_remote.c | 4 ++-- libxfs/xfs_da_btree.c | 2 +- libxfs/xfs_dir2_block.c | 19 ++++++++++--------- libxfs/xfs_dir2_data.c | 2 +- libxfs/xfs_dir2_leaf.c | 11 +++++------ libxfs/xfs_dir2_node.c | 2 +- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index 393e5e6ca..ed3b63f8c 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -1236,7 +1236,7 @@ xfs_attr3_leaf_create( ichdr.magic = XFS_ATTR3_LEAF_MAGIC; hdr3->blkno = cpu_to_be64(xfs_buf_daddr(bp)); - hdr3->owner = cpu_to_be64(dp->i_ino); + hdr3->owner = cpu_to_be64(args->owner); uuid_copy(&hdr3->uuid, &mp->m_sb.sb_meta_uuid); ichdr.freemap[0].base = sizeof(struct xfs_attr3_leaf_hdr); diff --git a/libxfs/xfs_attr_remote.c b/libxfs/xfs_attr_remote.c index 855d090c9..2787d3fa3 100644 --- a/libxfs/xfs_attr_remote.c +++ b/libxfs/xfs_attr_remote.c @@ -521,8 +521,8 @@ xfs_attr_rmtval_set_value( return error; bp->b_ops = &xfs_attr3_rmt_buf_ops; - xfs_attr_rmtval_copyin(mp, bp, args->dp->i_ino, &offset, - &valuelen, &src); + xfs_attr_rmtval_copyin(mp, bp, args->owner, &offset, &valuelen, + &src); error = xfs_bwrite(bp); /* GROT: NOTE: synchronous write */ xfs_buf_relse(bp); diff --git a/libxfs/xfs_da_btree.c b/libxfs/xfs_da_btree.c index 8ace7622a..3ad58ab04 100644 --- a/libxfs/xfs_da_btree.c +++ b/libxfs/xfs_da_btree.c @@ -482,7 +482,7 @@ xfs_da3_node_create( memset(hdr3, 0, sizeof(struct xfs_da3_node_hdr)); ichdr.magic = XFS_DA3_NODE_MAGIC; hdr3->info.blkno = cpu_to_be64(xfs_buf_daddr(bp)); - hdr3->info.owner = cpu_to_be64(args->dp->i_ino); + hdr3->info.owner = cpu_to_be64(args->owner); uuid_copy(&hdr3->info.uuid, &mp->m_sb.sb_meta_uuid); } else { ichdr.magic = XFS_DA_NODE_MAGIC; diff --git a/libxfs/xfs_dir2_block.c b/libxfs/xfs_dir2_block.c index 9d87735e7..c91559e59 100644 --- a/libxfs/xfs_dir2_block.c +++ b/libxfs/xfs_dir2_block.c @@ -160,12 +160,13 @@ xfs_dir3_block_read( static void xfs_dir3_block_init( - struct xfs_mount *mp, - struct xfs_trans *tp, - struct xfs_buf *bp, - struct xfs_inode *dp) + struct xfs_da_args *args, + struct xfs_buf *bp) { - struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; + struct xfs_trans *tp = args->trans; + struct xfs_inode *dp = args->dp; + struct xfs_mount *mp = dp->i_mount; + struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; bp->b_ops = &xfs_dir3_block_buf_ops; xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DIR_BLOCK_BUF); @@ -174,7 +175,7 @@ xfs_dir3_block_init( memset(hdr3, 0, sizeof(*hdr3)); hdr3->magic = cpu_to_be32(XFS_DIR3_BLOCK_MAGIC); hdr3->blkno = cpu_to_be64(xfs_buf_daddr(bp)); - hdr3->owner = cpu_to_be64(dp->i_ino); + hdr3->owner = cpu_to_be64(args->owner); uuid_copy(&hdr3->uuid, &mp->m_sb.sb_meta_uuid); return; @@ -1006,7 +1007,7 @@ xfs_dir2_leaf_to_block( /* * Start converting it to block form. */ - xfs_dir3_block_init(mp, tp, dbp, dp); + xfs_dir3_block_init(args, dbp); needlog = 1; needscan = 0; @@ -1126,7 +1127,7 @@ xfs_dir2_sf_to_block( error = xfs_dir3_data_init(args, blkno, &bp); if (error) goto out_free; - xfs_dir3_block_init(mp, tp, bp, dp); + xfs_dir3_block_init(args, bp); hdr = bp->b_addr; /* @@ -1166,7 +1167,7 @@ xfs_dir2_sf_to_block( * Create entry for . */ dep = bp->b_addr + offset; - dep->inumber = cpu_to_be64(dp->i_ino); + dep->inumber = cpu_to_be64(args->owner); dep->namelen = 1; dep->name[0] = '.'; xfs_dir2_data_put_ftype(mp, dep, XFS_DIR3_FT_DIR); diff --git a/libxfs/xfs_dir2_data.c b/libxfs/xfs_dir2_data.c index aaf3f62af..6f3ccfeb6 100644 --- a/libxfs/xfs_dir2_data.c +++ b/libxfs/xfs_dir2_data.c @@ -722,7 +722,7 @@ xfs_dir3_data_init( memset(hdr3, 0, sizeof(*hdr3)); hdr3->magic = cpu_to_be32(XFS_DIR3_DATA_MAGIC); hdr3->blkno = cpu_to_be64(xfs_buf_daddr(bp)); - hdr3->owner = cpu_to_be64(dp->i_ino); + hdr3->owner = cpu_to_be64(args->owner); uuid_copy(&hdr3->uuid, &mp->m_sb.sb_meta_uuid); } else diff --git a/libxfs/xfs_dir2_leaf.c b/libxfs/xfs_dir2_leaf.c index 80cea8a27..8fbda2250 100644 --- a/libxfs/xfs_dir2_leaf.c +++ b/libxfs/xfs_dir2_leaf.c @@ -302,12 +302,12 @@ xfs_dir3_leafn_read( */ static void xfs_dir3_leaf_init( - struct xfs_mount *mp, - struct xfs_trans *tp, + struct xfs_da_args *args, struct xfs_buf *bp, - xfs_ino_t owner, uint16_t type) { + struct xfs_mount *mp = args->dp->i_mount; + struct xfs_trans *tp = args->trans; struct xfs_dir2_leaf *leaf = bp->b_addr; ASSERT(type == XFS_DIR2_LEAF1_MAGIC || type == XFS_DIR2_LEAFN_MAGIC); @@ -321,7 +321,7 @@ xfs_dir3_leaf_init( ? cpu_to_be16(XFS_DIR3_LEAF1_MAGIC) : cpu_to_be16(XFS_DIR3_LEAFN_MAGIC); leaf3->info.blkno = cpu_to_be64(xfs_buf_daddr(bp)); - leaf3->info.owner = cpu_to_be64(owner); + leaf3->info.owner = cpu_to_be64(args->owner); uuid_copy(&leaf3->info.uuid, &mp->m_sb.sb_meta_uuid); } else { memset(leaf, 0, sizeof(*leaf)); @@ -354,7 +354,6 @@ xfs_dir3_leaf_get_buf( { struct xfs_inode *dp = args->dp; struct xfs_trans *tp = args->trans; - struct xfs_mount *mp = dp->i_mount; struct xfs_buf *bp; int error; @@ -367,7 +366,7 @@ xfs_dir3_leaf_get_buf( if (error) return error; - xfs_dir3_leaf_init(mp, tp, bp, dp->i_ino, magic); + xfs_dir3_leaf_init(args, bp, magic); xfs_dir3_leaf_log_header(args, bp); if (magic == XFS_DIR2_LEAF1_MAGIC) xfs_dir3_leaf_log_tail(args, bp); diff --git a/libxfs/xfs_dir2_node.c b/libxfs/xfs_dir2_node.c index 44c8f3f2b..b00f78387 100644 --- a/libxfs/xfs_dir2_node.c +++ b/libxfs/xfs_dir2_node.c @@ -346,7 +346,7 @@ xfs_dir3_free_get_buf( hdr.magic = XFS_DIR3_FREE_MAGIC; hdr3->hdr.blkno = cpu_to_be64(xfs_buf_daddr(bp)); - hdr3->hdr.owner = cpu_to_be64(dp->i_ino); + hdr3->hdr.owner = cpu_to_be64(args->owner); uuid_copy(&hdr3->hdr.uuid, &mp->m_sb.sb_meta_uuid); } else hdr.magic = XFS_DIR2_FREE_MAGIC; From patchwork Tue Jul 30 00:27:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745918 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8145F3C17 for ; Tue, 30 Jul 2024 00:27:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299277; cv=none; b=m+DkqncapE/QFhahB8WlYxvNAvHwzL/IXpnEgS4Zh76Rhy8ya3O+72MrF0bfxw4Hu1KPt911qyTKjUCHupO+/6vY/lInh60xo7DJZTNFw6udp5UoT8BEwHXvz0U1p7r0+iF0d1k3GYPHKRJFAJJp+tUr/+z4yZhmK8qjwnr/L2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299277; c=relaxed/simple; bh=1N0kmqk5SY21AiRUsJcpaLCd0nFoofHasJXYnZ1B4rU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V1HIBkoRix4erNrlv9zvED9O1cWZrO3J0UCs82o/HGbRffHd4rnrdjkU8BW2N+Dg5VSaozTfQdxF3RN5Iu7ITUQrGKC1fO6EaHL8v7dU9fzsBwWs6vF6rQH5+OG0MmCa+z8qRd/EGU+mMr54HbqjDtHLuif5ow77ug/+0pzCpAE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UEoXkiOY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UEoXkiOY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C492C4AF11; Tue, 30 Jul 2024 00:27:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299277; bh=1N0kmqk5SY21AiRUsJcpaLCd0nFoofHasJXYnZ1B4rU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=UEoXkiOYYe0VTT+9CfHUV9tDCb+mD7eyfU2qHT5F7awK8HfwhPGt2HnE93ofEkHDf EFyogc9wKD+S5ZnKshWx8xajyV/BuM2XKKGA9nntrNpM7MXXgzqHNZMxSNAHdO5Ip9 GUulRARe0cePad2iOAsz20Io4BPzrZumVUsCY+4E7KvUFlSyqEHL9tlvCsUqPqmsR4 oaL+ZREuN3KwDzkvYkRQZAgS98MD97i/9oFQIp/o93QWy0P4qJSTdEOyrkdyush9O8 09eBsymmawg/Y6wa2EbYjQRXqRTA+jV1gbB6qIstsWVEpfwXKd0wpjlmlh37FZMj2l yUv1r48IvDJzQ== Date: Mon, 29 Jul 2024 17:27:56 -0700 Subject: [PATCH 016/115] xfs: validate attr leaf buffer owners From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842668.1338752.5688380871544993691.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: f4887fbc41dcb1560ec5da982ac7c6ad04b71de5 Create a leaf block header checking function to validate the owner field of xattr leaf blocks. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr.c | 10 ++++----- libxfs/xfs_attr_leaf.c | 56 ++++++++++++++++++++++++++++++++++++++++-------- libxfs/xfs_attr_leaf.h | 4 +++ libxfs/xfs_da_btree.c | 42 ++++++++++++++++++++++++++++++++++++ libxfs/xfs_da_btree.h | 1 + libxfs/xfs_exchmaps.c | 3 ++- 6 files changed, 100 insertions(+), 16 deletions(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 21b5d922b..cc291cf76 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -647,8 +647,8 @@ xfs_attr_leaf_remove_attr( int forkoff; int error; - error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, - &bp); + error = xfs_attr3_leaf_read(args->trans, args->dp, args->owner, + args->blkno, &bp); if (error) return error; @@ -679,7 +679,7 @@ xfs_attr_leaf_shrink( if (!xfs_attr_is_leaf(dp)) return 0; - error = xfs_attr3_leaf_read(args->trans, args->dp, 0, &bp); + error = xfs_attr3_leaf_read(args->trans, args->dp, args->owner, 0, &bp); if (error) return error; @@ -1156,7 +1156,7 @@ xfs_attr_leaf_try_add( struct xfs_buf *bp; int error; - error = xfs_attr3_leaf_read(args->trans, args->dp, 0, &bp); + error = xfs_attr3_leaf_read(args->trans, args->dp, args->owner, 0, &bp); if (error) return error; @@ -1204,7 +1204,7 @@ xfs_attr_leaf_hasname( { int error = 0; - error = xfs_attr3_leaf_read(args->trans, args->dp, 0, bp); + error = xfs_attr3_leaf_read(args->trans, args->dp, args->owner, 0, bp); if (error) return error; diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index ed3b63f8c..47f2836fb 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -385,6 +385,27 @@ xfs_attr3_leaf_verify( return NULL; } +xfs_failaddr_t +xfs_attr3_leaf_header_check( + struct xfs_buf *bp, + xfs_ino_t owner) +{ + struct xfs_mount *mp = bp->b_mount; + + if (xfs_has_crc(mp)) { + struct xfs_attr3_leafblock *hdr3 = bp->b_addr; + + if (hdr3->hdr.info.hdr.magic != + cpu_to_be16(XFS_ATTR3_LEAF_MAGIC)) + return __this_address; + + if (be64_to_cpu(hdr3->hdr.info.owner) != owner) + return __this_address; + } + + return NULL; +} + static void xfs_attr3_leaf_write_verify( struct xfs_buf *bp) @@ -445,16 +466,30 @@ int xfs_attr3_leaf_read( struct xfs_trans *tp, struct xfs_inode *dp, + xfs_ino_t owner, xfs_dablk_t bno, struct xfs_buf **bpp) { + xfs_failaddr_t fa; int err; err = xfs_da_read_buf(tp, dp, bno, 0, bpp, XFS_ATTR_FORK, &xfs_attr3_leaf_buf_ops); - if (!err && tp && *bpp) + if (err || !(*bpp)) + return err; + + fa = xfs_attr3_leaf_header_check(*bpp, owner); + if (fa) { + __xfs_buf_mark_corrupt(*bpp, fa); + xfs_trans_brelse(tp, *bpp); + *bpp = NULL; + xfs_dirattr_mark_sick(dp, XFS_ATTR_FORK); + return -EFSCORRUPTED; + } + + if (tp) xfs_trans_buf_set_type(tp, *bpp, XFS_BLFT_ATTR_LEAF_BUF); - return err; + return 0; } /*======================================================================== @@ -1157,7 +1192,7 @@ xfs_attr3_leaf_to_node( error = xfs_da_grow_inode(args, &blkno); if (error) goto out; - error = xfs_attr3_leaf_read(args->trans, dp, 0, &bp1); + error = xfs_attr3_leaf_read(args->trans, dp, args->owner, 0, &bp1); if (error) goto out; @@ -1992,7 +2027,7 @@ xfs_attr3_leaf_toosmall( if (blkno == 0) continue; error = xfs_attr3_leaf_read(state->args->trans, state->args->dp, - blkno, &bp); + state->args->owner, blkno, &bp); if (error) return error; @@ -2714,7 +2749,8 @@ xfs_attr3_leaf_clearflag( /* * Set up the operation. */ - error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, &bp); + error = xfs_attr3_leaf_read(args->trans, args->dp, args->owner, + args->blkno, &bp); if (error) return error; @@ -2778,7 +2814,8 @@ xfs_attr3_leaf_setflag( /* * Set up the operation. */ - error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, &bp); + error = xfs_attr3_leaf_read(args->trans, args->dp, args->owner, + args->blkno, &bp); if (error) return error; @@ -2837,7 +2874,8 @@ xfs_attr3_leaf_flipflags( /* * Read the block containing the "old" attr */ - error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno, &bp1); + error = xfs_attr3_leaf_read(args->trans, args->dp, args->owner, + args->blkno, &bp1); if (error) return error; @@ -2845,8 +2883,8 @@ xfs_attr3_leaf_flipflags( * Read the block containing the "new" attr, if it is different */ if (args->blkno2 != args->blkno) { - error = xfs_attr3_leaf_read(args->trans, args->dp, args->blkno2, - &bp2); + error = xfs_attr3_leaf_read(args->trans, args->dp, args->owner, + args->blkno2, &bp2); if (error) return error; } else { diff --git a/libxfs/xfs_attr_leaf.h b/libxfs/xfs_attr_leaf.h index 9b9948639..bac219589 100644 --- a/libxfs/xfs_attr_leaf.h +++ b/libxfs/xfs_attr_leaf.h @@ -98,12 +98,14 @@ int xfs_attr_leaf_order(struct xfs_buf *leaf1_bp, struct xfs_buf *leaf2_bp); int xfs_attr_leaf_newentsize(struct xfs_da_args *args, int *local); int xfs_attr3_leaf_read(struct xfs_trans *tp, struct xfs_inode *dp, - xfs_dablk_t bno, struct xfs_buf **bpp); + xfs_ino_t owner, xfs_dablk_t bno, struct xfs_buf **bpp); void xfs_attr3_leaf_hdr_from_disk(struct xfs_da_geometry *geo, struct xfs_attr3_icleaf_hdr *to, struct xfs_attr_leafblock *from); void xfs_attr3_leaf_hdr_to_disk(struct xfs_da_geometry *geo, struct xfs_attr_leafblock *to, struct xfs_attr3_icleaf_hdr *from); +xfs_failaddr_t xfs_attr3_leaf_header_check(struct xfs_buf *bp, + xfs_ino_t owner); #endif /* __XFS_ATTR_LEAF_H__ */ diff --git a/libxfs/xfs_da_btree.c b/libxfs/xfs_da_btree.c index 3ad58ab04..28fd87c2d 100644 --- a/libxfs/xfs_da_btree.c +++ b/libxfs/xfs_da_btree.c @@ -248,6 +248,25 @@ xfs_da3_node_verify( return NULL; } +xfs_failaddr_t +xfs_da3_header_check( + struct xfs_buf *bp, + xfs_ino_t owner) +{ + struct xfs_mount *mp = bp->b_mount; + struct xfs_da_blkinfo *hdr = bp->b_addr; + + if (!xfs_has_crc(mp)) + return NULL; + + switch (hdr->magic) { + case cpu_to_be16(XFS_ATTR3_LEAF_MAGIC): + return xfs_attr3_leaf_header_check(bp, owner); + } + + return NULL; +} + static void xfs_da3_node_write_verify( struct xfs_buf *bp) @@ -1587,6 +1606,7 @@ xfs_da3_node_lookup_int( struct xfs_da_node_entry *btree; struct xfs_da3_icnode_hdr nodehdr; struct xfs_da_args *args; + xfs_failaddr_t fa; xfs_dablk_t blkno; xfs_dahash_t hashval; xfs_dahash_t btreehashval; @@ -1625,6 +1645,12 @@ xfs_da3_node_lookup_int( if (magic == XFS_ATTR_LEAF_MAGIC || magic == XFS_ATTR3_LEAF_MAGIC) { + fa = xfs_attr3_leaf_header_check(blk->bp, args->owner); + if (fa) { + __xfs_buf_mark_corrupt(blk->bp, fa); + xfs_da_mark_sick(args); + return -EFSCORRUPTED; + } blk->magic = XFS_ATTR_LEAF_MAGIC; blk->hashval = xfs_attr_leaf_lasthash(blk->bp, NULL); break; @@ -1992,6 +2018,7 @@ xfs_da3_path_shift( struct xfs_da_node_entry *btree; struct xfs_da3_icnode_hdr nodehdr; struct xfs_buf *bp; + xfs_failaddr_t fa; xfs_dablk_t blkno = 0; int level; int error; @@ -2083,6 +2110,12 @@ xfs_da3_path_shift( break; case XFS_ATTR_LEAF_MAGIC: case XFS_ATTR3_LEAF_MAGIC: + fa = xfs_attr3_leaf_header_check(blk->bp, args->owner); + if (fa) { + __xfs_buf_mark_corrupt(blk->bp, fa); + xfs_da_mark_sick(args); + return -EFSCORRUPTED; + } blk->magic = XFS_ATTR_LEAF_MAGIC; ASSERT(level == path->active-1); blk->index = 0; @@ -2286,6 +2319,7 @@ xfs_da3_swap_lastblock( struct xfs_buf *last_buf; struct xfs_buf *sib_buf; struct xfs_buf *par_buf; + xfs_failaddr_t fa; xfs_dahash_t dead_hash; xfs_fileoff_t lastoff; xfs_dablk_t dead_blkno; @@ -2322,6 +2356,14 @@ xfs_da3_swap_lastblock( error = xfs_da3_node_read(tp, dp, last_blkno, &last_buf, w); if (error) return error; + fa = xfs_da3_header_check(last_buf, args->owner); + if (fa) { + __xfs_buf_mark_corrupt(last_buf, fa); + xfs_trans_brelse(tp, last_buf); + xfs_da_mark_sick(args); + return -EFSCORRUPTED; + } + /* * Copy the last block into the dead buffer and log it. */ diff --git a/libxfs/xfs_da_btree.h b/libxfs/xfs_da_btree.h index 7fb13f26e..99618e0c8 100644 --- a/libxfs/xfs_da_btree.h +++ b/libxfs/xfs_da_btree.h @@ -236,6 +236,7 @@ void xfs_da3_node_hdr_from_disk(struct xfs_mount *mp, struct xfs_da3_icnode_hdr *to, struct xfs_da_intnode *from); void xfs_da3_node_hdr_to_disk(struct xfs_mount *mp, struct xfs_da_intnode *to, struct xfs_da3_icnode_hdr *from); +xfs_failaddr_t xfs_da3_header_check(struct xfs_buf *bp, xfs_ino_t owner); extern struct kmem_cache *xfs_da_state_cache; diff --git a/libxfs/xfs_exchmaps.c b/libxfs/xfs_exchmaps.c index 6160beef1..21c501aab 100644 --- a/libxfs/xfs_exchmaps.c +++ b/libxfs/xfs_exchmaps.c @@ -435,7 +435,8 @@ xfs_exchmaps_attr_to_sf( if (!xfs_attr_is_leaf(xmi->xmi_ip2)) return 0; - error = xfs_attr3_leaf_read(tp, xmi->xmi_ip2, 0, &bp); + error = xfs_attr3_leaf_read(tp, xmi->xmi_ip2, xmi->xmi_ip2->i_ino, 0, + &bp); if (error) return error; From patchwork Tue Jul 30 00:28:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745919 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 660D965C for ; Tue, 30 Jul 2024 00:28:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299293; cv=none; b=KFf7+8F0bL6vxHsIScxC5DolIHulWq/uUjhz63pq518OeBAtvKb0dbr+0dB6t2ZhEqBa/elbWGi5NfJc3hcdYPQXdt04yvzgKFky7Ae0U+7uNWSfC8gFUW63lonnD9w3eOgXfi0iPGRJP1kr/u4LBcoFr9uL35ZRXkxDT8On49E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299293; c=relaxed/simple; bh=k2RH1NEQ85gI27BPhc2RwtKT74727sTVwp4vMsgbCrI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iqRatnHFb8mKA5auS/87SPq98MNTovEq/TVzCPbs1fbOIItrwR/rg9W6P6S29OmM3wYAIKZQR7j22ZFroyybMoVpSfxbZwmHg+ysSFGsVySeZ43ihLtw6iqktk86kDIEMAkNksi9Q1/QRQrvrJkZvaPUwumK4tq5IhUYtZweCYY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dw5ArKjc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dw5ArKjc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4896C32786; Tue, 30 Jul 2024 00:28:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299293; bh=k2RH1NEQ85gI27BPhc2RwtKT74727sTVwp4vMsgbCrI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=dw5ArKjcZ8LyXPAA7+7r7hVhha8e/Mws/CtkpbmV+DC2DjRzRk/H2Zi57IKkZCU8p lEpNSZLnkP8nyog4c7G/Ld0T/DsT0yGMgixVq+/QvymOk4b/jwdyddlIN9UQyEaF9z vorYNPz/GHLqGXpJxz8Vdp+IJu8SEHAHCWxmgzu5lTzENVrM+UWDij9b+CbrCIYkL4 Hym+ml1t2kjP/4cL/2rur2+q+cIjrEsm0lV1CX8HNQQlUoDoJjIzgBvOoXBc9HQr39 sixmp+Y7YAU6cfWPICk3206ukoPcWF7v9UTuYECrBSdky+0wMOTS03mMJrEwMC5h5f 1jk4TRbwhYe7A== Date: Mon, 29 Jul 2024 17:28:12 -0700 Subject: [PATCH 017/115] xfs: validate attr remote value buffer owners From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842681.1338752.6597168298216066484.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 8c25dc728bd1ca9344001aa6ef4556885572baa4 Check the owner field of xattr remote value blocks. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr_remote.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libxfs/xfs_attr_remote.c b/libxfs/xfs_attr_remote.c index 2787d3fa3..eb15b272b 100644 --- a/libxfs/xfs_attr_remote.c +++ b/libxfs/xfs_attr_remote.c @@ -279,12 +279,12 @@ xfs_attr_rmtval_copyout( struct xfs_mount *mp, struct xfs_buf *bp, struct xfs_inode *dp, + xfs_ino_t owner, int *offset, int *valuelen, uint8_t **dst) { char *src = bp->b_addr; - xfs_ino_t ino = dp->i_ino; xfs_daddr_t bno = xfs_buf_daddr(bp); int len = BBTOB(bp->b_length); int blksize = mp->m_attr_geo->blksize; @@ -298,11 +298,11 @@ xfs_attr_rmtval_copyout( byte_cnt = min(*valuelen, byte_cnt); if (xfs_has_crc(mp)) { - if (xfs_attr3_rmt_hdr_ok(src, ino, *offset, + if (xfs_attr3_rmt_hdr_ok(src, owner, *offset, byte_cnt, bno)) { xfs_alert(mp, "remote attribute header mismatch bno/off/len/owner (0x%llx/0x%x/Ox%x/0x%llx)", - bno, *offset, byte_cnt, ino); + bno, *offset, byte_cnt, owner); xfs_dirattr_mark_sick(dp, XFS_ATTR_FORK); return -EFSCORRUPTED; } @@ -426,8 +426,7 @@ xfs_attr_rmtval_get( return error; error = xfs_attr_rmtval_copyout(mp, bp, args->dp, - &offset, &valuelen, - &dst); + args->owner, &offset, &valuelen, &dst); xfs_buf_relse(bp); if (error) return error; From patchwork Tue Jul 30 00:28:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745920 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 10F7D65C for ; Tue, 30 Jul 2024 00:28:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299309; cv=none; b=Au/YkDHqIuZQyiX65lx3LBiDOCWmR/PCeZziygKwYtZ6zWmIYB+kmyVlIsgZVTdH1ubPqQACgAqIWayc10PXtXyxbHnBdh0mS75eigHWy/9wf43ubZLi6mbcPmZDXkqUSNEH9sHbrkj5IpXjaAXGxjqRy6OCrFAQPZNhzKol9QY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299309; c=relaxed/simple; bh=wMEls1dpmUCqbpjk9TUwvukXV6ZnWskH/DcQYRaXHbc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ogPHC2fLSvX3kPwCVWj3SkKs6Z2+BMCXX3eq4qI2mvdlHhn2cA6UU869V+C4SrKUor/TkUgk9eLHMXq4ot3mcI//wzUXflSfbPI4qlUosczQXD8NtHb4lxyIYkPmLYMWpYOM0Zu9DM7MyeVlFqFniiFE17xdDq3cE7tHyJqOM3Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P6LcF2WE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="P6LcF2WE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B6E0C32786; Tue, 30 Jul 2024 00:28:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299308; bh=wMEls1dpmUCqbpjk9TUwvukXV6ZnWskH/DcQYRaXHbc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=P6LcF2WEmlx2gCdd6avysUDd6wC49gf1mOYND64esV2K8GF321y35KYo8H2pQ7aeM 9U2X9wcMFBXkcCt4BYHSGSfRAxgK5DgpQmf1/bqMVQzrbETlyFbuv1uo0Z8J6qa0jg BqktYjKlHGDWH1ufzkQy1IdiXrfJKp7hcBp1X/tjx2grncgD3G3H5N6zLSe47GSA7K orx6egM1NpEn+ieKSGp6IDrxyv/wL8w0bq0mgukRognfhBaHY3+SqhDX/WoErzSm5z nc57WYEoIa1oRNY/Ik71peSuAIzoJlgBYSyOO+f3/U9vEp9STe16Qf5PgLCTACvCYj 5fRugIQsbKRCA== Date: Mon, 29 Jul 2024 17:28:28 -0700 Subject: [PATCH 018/115] xfs: validate dabtree node buffer owners From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842695.1338752.11118531122403269518.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: d44bea9b41ca25f91fd9f25ed2cc3bb2f6dab4bc Check the owner field of dabtree node blocks. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_da_btree.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_da_btree.h | 1 2 files changed, 110 insertions(+) diff --git a/libxfs/xfs_da_btree.c b/libxfs/xfs_da_btree.c index 28fd87c2d..c221cbba4 100644 --- a/libxfs/xfs_da_btree.c +++ b/libxfs/xfs_da_btree.c @@ -248,6 +248,26 @@ xfs_da3_node_verify( return NULL; } +xfs_failaddr_t +xfs_da3_node_header_check( + struct xfs_buf *bp, + xfs_ino_t owner) +{ + struct xfs_mount *mp = bp->b_mount; + + if (xfs_has_crc(mp)) { + struct xfs_da3_blkinfo *hdr3 = bp->b_addr; + + if (hdr3->hdr.magic != cpu_to_be16(XFS_DA3_NODE_MAGIC)) + return __this_address; + + if (be64_to_cpu(hdr3->owner) != owner) + return __this_address; + } + + return NULL; +} + xfs_failaddr_t xfs_da3_header_check( struct xfs_buf *bp, @@ -262,6 +282,8 @@ xfs_da3_header_check( switch (hdr->magic) { case cpu_to_be16(XFS_ATTR3_LEAF_MAGIC): return xfs_attr3_leaf_header_check(bp, owner); + case cpu_to_be16(XFS_DA3_NODE_MAGIC): + return xfs_da3_node_header_check(bp, owner); } return NULL; @@ -1214,6 +1236,7 @@ xfs_da3_root_join( struct xfs_da3_icnode_hdr oldroothdr; int error; struct xfs_inode *dp = state->args->dp; + xfs_failaddr_t fa; trace_xfs_da_root_join(state->args); @@ -1240,6 +1263,13 @@ xfs_da3_root_join( error = xfs_da3_node_read(args->trans, dp, child, &bp, args->whichfork); if (error) return error; + fa = xfs_da3_header_check(bp, args->owner); + if (fa) { + __xfs_buf_mark_corrupt(bp, fa); + xfs_trans_brelse(args->trans, bp); + xfs_da_mark_sick(args); + return -EFSCORRUPTED; + } xfs_da_blkinfo_onlychild_validate(bp->b_addr, oldroothdr.level); /* @@ -1274,6 +1304,7 @@ xfs_da3_node_toosmall( struct xfs_da_blkinfo *info; xfs_dablk_t blkno; struct xfs_buf *bp; + xfs_failaddr_t fa; struct xfs_da3_icnode_hdr nodehdr; int count; int forward; @@ -1348,6 +1379,13 @@ xfs_da3_node_toosmall( state->args->whichfork); if (error) return error; + fa = xfs_da3_node_header_check(bp, state->args->owner); + if (fa) { + __xfs_buf_mark_corrupt(bp, fa); + xfs_trans_brelse(state->args->trans, bp); + xfs_da_mark_sick(state->args); + return -EFSCORRUPTED; + } node = bp->b_addr; xfs_da3_node_hdr_from_disk(dp->i_mount, &thdr, node); @@ -1670,6 +1708,13 @@ xfs_da3_node_lookup_int( return -EFSCORRUPTED; } + fa = xfs_da3_node_header_check(blk->bp, args->owner); + if (fa) { + __xfs_buf_mark_corrupt(blk->bp, fa); + xfs_da_mark_sick(args); + return -EFSCORRUPTED; + } + blk->magic = XFS_DA_NODE_MAGIC; /* @@ -1842,6 +1887,7 @@ xfs_da3_blk_link( struct xfs_da_blkinfo *tmp_info; struct xfs_da_args *args; struct xfs_buf *bp; + xfs_failaddr_t fa; int before = 0; int error; struct xfs_inode *dp = state->args->dp; @@ -1885,6 +1931,13 @@ xfs_da3_blk_link( &bp, args->whichfork); if (error) return error; + fa = xfs_da3_header_check(bp, args->owner); + if (fa) { + __xfs_buf_mark_corrupt(bp, fa); + xfs_trans_brelse(args->trans, bp); + xfs_da_mark_sick(args); + return -EFSCORRUPTED; + } ASSERT(bp != NULL); tmp_info = bp->b_addr; ASSERT(tmp_info->magic == old_info->magic); @@ -1906,6 +1959,13 @@ xfs_da3_blk_link( &bp, args->whichfork); if (error) return error; + fa = xfs_da3_header_check(bp, args->owner); + if (fa) { + __xfs_buf_mark_corrupt(bp, fa); + xfs_trans_brelse(args->trans, bp); + xfs_da_mark_sick(args); + return -EFSCORRUPTED; + } ASSERT(bp != NULL); tmp_info = bp->b_addr; ASSERT(tmp_info->magic == old_info->magic); @@ -1935,6 +1995,7 @@ xfs_da3_blk_unlink( struct xfs_da_blkinfo *tmp_info; struct xfs_da_args *args; struct xfs_buf *bp; + xfs_failaddr_t fa; int error; /* @@ -1965,6 +2026,13 @@ xfs_da3_blk_unlink( &bp, args->whichfork); if (error) return error; + fa = xfs_da3_header_check(bp, args->owner); + if (fa) { + __xfs_buf_mark_corrupt(bp, fa); + xfs_trans_brelse(args->trans, bp); + xfs_da_mark_sick(args); + return -EFSCORRUPTED; + } ASSERT(bp != NULL); tmp_info = bp->b_addr; ASSERT(tmp_info->magic == save_info->magic); @@ -1982,6 +2050,13 @@ xfs_da3_blk_unlink( &bp, args->whichfork); if (error) return error; + fa = xfs_da3_header_check(bp, args->owner); + if (fa) { + __xfs_buf_mark_corrupt(bp, fa); + xfs_trans_brelse(args->trans, bp); + xfs_da_mark_sick(args); + return -EFSCORRUPTED; + } ASSERT(bp != NULL); tmp_info = bp->b_addr; ASSERT(tmp_info->magic == save_info->magic); @@ -2097,6 +2172,12 @@ xfs_da3_path_shift( switch (be16_to_cpu(info->magic)) { case XFS_DA_NODE_MAGIC: case XFS_DA3_NODE_MAGIC: + fa = xfs_da3_node_header_check(blk->bp, args->owner); + if (fa) { + __xfs_buf_mark_corrupt(blk->bp, fa); + xfs_da_mark_sick(args); + return -EFSCORRUPTED; + } blk->magic = XFS_DA_NODE_MAGIC; xfs_da3_node_hdr_from_disk(dp->i_mount, &nodehdr, bp->b_addr); @@ -2402,6 +2483,13 @@ xfs_da3_swap_lastblock( error = xfs_da3_node_read(tp, dp, sib_blkno, &sib_buf, w); if (error) goto done; + fa = xfs_da3_header_check(sib_buf, args->owner); + if (fa) { + __xfs_buf_mark_corrupt(sib_buf, fa); + xfs_da_mark_sick(args); + error = -EFSCORRUPTED; + goto done; + } sib_info = sib_buf->b_addr; if (XFS_IS_CORRUPT(mp, be32_to_cpu(sib_info->forw) != last_blkno || @@ -2423,6 +2511,13 @@ xfs_da3_swap_lastblock( error = xfs_da3_node_read(tp, dp, sib_blkno, &sib_buf, w); if (error) goto done; + fa = xfs_da3_header_check(sib_buf, args->owner); + if (fa) { + __xfs_buf_mark_corrupt(sib_buf, fa); + xfs_da_mark_sick(args); + error = -EFSCORRUPTED; + goto done; + } sib_info = sib_buf->b_addr; if (XFS_IS_CORRUPT(mp, be32_to_cpu(sib_info->back) != last_blkno || @@ -2446,6 +2541,13 @@ xfs_da3_swap_lastblock( error = xfs_da3_node_read(tp, dp, par_blkno, &par_buf, w); if (error) goto done; + fa = xfs_da3_node_header_check(par_buf, args->owner); + if (fa) { + __xfs_buf_mark_corrupt(par_buf, fa); + xfs_da_mark_sick(args); + error = -EFSCORRUPTED; + goto done; + } par_node = par_buf->b_addr; xfs_da3_node_hdr_from_disk(dp->i_mount, &par_hdr, par_node); if (XFS_IS_CORRUPT(mp, @@ -2495,6 +2597,13 @@ xfs_da3_swap_lastblock( error = xfs_da3_node_read(tp, dp, par_blkno, &par_buf, w); if (error) goto done; + fa = xfs_da3_node_header_check(par_buf, args->owner); + if (fa) { + __xfs_buf_mark_corrupt(par_buf, fa); + xfs_da_mark_sick(args); + error = -EFSCORRUPTED; + goto done; + } par_node = par_buf->b_addr; xfs_da3_node_hdr_from_disk(dp->i_mount, &par_hdr, par_node); if (XFS_IS_CORRUPT(mp, par_hdr.level != level)) { diff --git a/libxfs/xfs_da_btree.h b/libxfs/xfs_da_btree.h index 99618e0c8..7a004786e 100644 --- a/libxfs/xfs_da_btree.h +++ b/libxfs/xfs_da_btree.h @@ -237,6 +237,7 @@ void xfs_da3_node_hdr_from_disk(struct xfs_mount *mp, void xfs_da3_node_hdr_to_disk(struct xfs_mount *mp, struct xfs_da_intnode *to, struct xfs_da3_icnode_hdr *from); xfs_failaddr_t xfs_da3_header_check(struct xfs_buf *bp, xfs_ino_t owner); +xfs_failaddr_t xfs_da3_node_header_check(struct xfs_buf *bp, xfs_ino_t owner); extern struct kmem_cache *xfs_da_state_cache; From patchwork Tue Jul 30 00:28:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745921 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 9914F10E3 for ; Tue, 30 Jul 2024 00:28:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299324; cv=none; b=Hlgn8SzmMlWTYYcexxSWadrpnXdsXfYQ9F8UV8weBeIpv+GK02xypoB/CO0TS9XwumObADydxhGPf80Rvtwgw657qlp+qlsED0PaUq0Pd32goyWdMnLmLGGIffKKJexwFXc8gJEoygCTr9ZtBEkqv4B6a73ZmnlxUYYD68qh6N4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299324; c=relaxed/simple; bh=eJ8wkroWWu0bCV2pXvpgKctis4cSMyv3r19EKvbixdg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Dssn2D/OrAt7utpE4c52q1R9NdNGlhdVCaXwLiHnfYLcuY47J2puFQSok1uPH/tKLxXle34H89X5h4ytIRkX83SCRXajaOZCs5zqF/HIeAMjsiL4U0ex++Z74C3jNEf7Suh47IoIYYRiuJ1FKa8TCG55zQJHT5b/75mimV4lZZY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FtOLNK2e; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FtOLNK2e" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CA9EC32786; Tue, 30 Jul 2024 00:28:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299324; bh=eJ8wkroWWu0bCV2pXvpgKctis4cSMyv3r19EKvbixdg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=FtOLNK2eRaAd0bOhiPmJwcfOc4QbfO9+fEVVU1vq23ZjfI5JMqTEzfX6V9VgYJqww Jlc9UQOENBdgmVWrw6yo/kkVwXtheWEv1nH64QHtxOFKWWZzjE/Gxr7BFKrGIkfLvf QMH0jAHY+DflV/HOKRp5Z8MEzX6COBqXoi2VFCCzIKix+AMFhBD7T8yLl2ldza3w7v GDTbTIrP4GumykIWEIgC1olCySF8WyWvG0PD4DUn93nW+18cOXVmTXceX28O3CosYz LZr4YOfohYQpMsuUZxsUQQvQ1CTYebrLU78Xo2NAWeL5snU7sgJX5y3OcE2ZKU7kEp uKzbVSuphkcRA== Date: Mon, 29 Jul 2024 17:28:43 -0700 Subject: [PATCH 019/115] xfs: validate directory leaf buffer owners From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842710.1338752.72489110537039762.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 402eef10a1bab0b428c418cfbaaa0a62efc9c951 Check the owner field of directory leaf blocks. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_da_btree.c | 16 ++++++++++++ libxfs/xfs_dir2.h | 2 + libxfs/xfs_dir2_leaf.c | 65 ++++++++++++++++++++++++++++++++++++++++++++---- libxfs/xfs_dir2_node.c | 3 +- libxfs/xfs_dir2_priv.h | 4 +-- 5 files changed, 81 insertions(+), 9 deletions(-) diff --git a/libxfs/xfs_da_btree.c b/libxfs/xfs_da_btree.c index c221cbba4..3c0dc26b7 100644 --- a/libxfs/xfs_da_btree.c +++ b/libxfs/xfs_da_btree.c @@ -284,8 +284,12 @@ xfs_da3_header_check( return xfs_attr3_leaf_header_check(bp, owner); case cpu_to_be16(XFS_DA3_NODE_MAGIC): return xfs_da3_node_header_check(bp, owner); + case cpu_to_be16(XFS_DIR3_LEAF1_MAGIC): + case cpu_to_be16(XFS_DIR3_LEAFN_MAGIC): + return xfs_dir3_leaf_header_check(bp, owner); } + ASSERT(0); return NULL; } @@ -1696,6 +1700,12 @@ xfs_da3_node_lookup_int( if (magic == XFS_DIR2_LEAFN_MAGIC || magic == XFS_DIR3_LEAFN_MAGIC) { + fa = xfs_dir3_leaf_header_check(blk->bp, args->owner); + if (fa) { + __xfs_buf_mark_corrupt(blk->bp, fa); + xfs_da_mark_sick(args); + return -EFSCORRUPTED; + } blk->magic = XFS_DIR2_LEAFN_MAGIC; blk->hashval = xfs_dir2_leaf_lasthash(args->dp, blk->bp, NULL); @@ -2204,6 +2214,12 @@ xfs_da3_path_shift( break; case XFS_DIR2_LEAFN_MAGIC: case XFS_DIR3_LEAFN_MAGIC: + fa = xfs_dir3_leaf_header_check(blk->bp, args->owner); + if (fa) { + __xfs_buf_mark_corrupt(blk->bp, fa); + xfs_da_mark_sick(args); + return -EFSCORRUPTED; + } blk->magic = XFS_DIR2_LEAFN_MAGIC; ASSERT(level == path->active-1); blk->index = 0; diff --git a/libxfs/xfs_dir2.h b/libxfs/xfs_dir2.h index 8497d041f..2f728c26a 100644 --- a/libxfs/xfs_dir2.h +++ b/libxfs/xfs_dir2.h @@ -101,6 +101,8 @@ extern struct xfs_dir2_data_free *xfs_dir2_data_freefind( extern int xfs_dir_ino_validate(struct xfs_mount *mp, xfs_ino_t ino); +xfs_failaddr_t xfs_dir3_leaf_header_check(struct xfs_buf *bp, xfs_ino_t owner); + extern const struct xfs_buf_ops xfs_dir3_block_buf_ops; extern const struct xfs_buf_ops xfs_dir3_leafn_buf_ops; extern const struct xfs_buf_ops xfs_dir3_leaf1_buf_ops; diff --git a/libxfs/xfs_dir2_leaf.c b/libxfs/xfs_dir2_leaf.c index 8fbda2250..6ce2d4b28 100644 --- a/libxfs/xfs_dir2_leaf.c +++ b/libxfs/xfs_dir2_leaf.c @@ -206,6 +206,29 @@ xfs_dir3_leaf_verify( return xfs_dir3_leaf_check_int(mp, &leafhdr, bp->b_addr, true); } +xfs_failaddr_t +xfs_dir3_leaf_header_check( + struct xfs_buf *bp, + xfs_ino_t owner) +{ + struct xfs_mount *mp = bp->b_mount; + + if (xfs_has_crc(mp)) { + struct xfs_dir3_leaf *hdr3 = bp->b_addr; + + if (hdr3->hdr.info.hdr.magic != + cpu_to_be16(XFS_DIR3_LEAF1_MAGIC) && + hdr3->hdr.info.hdr.magic != + cpu_to_be16(XFS_DIR3_LEAFN_MAGIC)) + return __this_address; + + if (be64_to_cpu(hdr3->hdr.info.owner) != owner) + return __this_address; + } + + return NULL; +} + static void xfs_dir3_leaf_read_verify( struct xfs_buf *bp) @@ -269,32 +292,60 @@ int xfs_dir3_leaf_read( struct xfs_trans *tp, struct xfs_inode *dp, + xfs_ino_t owner, xfs_dablk_t fbno, struct xfs_buf **bpp) { + xfs_failaddr_t fa; int err; err = xfs_da_read_buf(tp, dp, fbno, 0, bpp, XFS_DATA_FORK, &xfs_dir3_leaf1_buf_ops); - if (!err && tp && *bpp) + if (err || !(*bpp)) + return err; + + fa = xfs_dir3_leaf_header_check(*bpp, owner); + if (fa) { + __xfs_buf_mark_corrupt(*bpp, fa); + xfs_trans_brelse(tp, *bpp); + *bpp = NULL; + xfs_dirattr_mark_sick(dp, XFS_DATA_FORK); + return -EFSCORRUPTED; + } + + if (tp) xfs_trans_buf_set_type(tp, *bpp, XFS_BLFT_DIR_LEAF1_BUF); - return err; + return 0; } int xfs_dir3_leafn_read( struct xfs_trans *tp, struct xfs_inode *dp, + xfs_ino_t owner, xfs_dablk_t fbno, struct xfs_buf **bpp) { + xfs_failaddr_t fa; int err; err = xfs_da_read_buf(tp, dp, fbno, 0, bpp, XFS_DATA_FORK, &xfs_dir3_leafn_buf_ops); - if (!err && tp && *bpp) + if (err || !(*bpp)) + return err; + + fa = xfs_dir3_leaf_header_check(*bpp, owner); + if (fa) { + __xfs_buf_mark_corrupt(*bpp, fa); + xfs_trans_brelse(tp, *bpp); + *bpp = NULL; + xfs_dirattr_mark_sick(dp, XFS_DATA_FORK); + return -EFSCORRUPTED; + } + + if (tp) xfs_trans_buf_set_type(tp, *bpp, XFS_BLFT_DIR_LEAFN_BUF); - return err; + return 0; } /* @@ -644,7 +695,8 @@ xfs_dir2_leaf_addname( trace_xfs_dir2_leaf_addname(args); - error = xfs_dir3_leaf_read(tp, dp, args->geo->leafblk, &lbp); + error = xfs_dir3_leaf_read(tp, dp, args->owner, args->geo->leafblk, + &lbp); if (error) return error; @@ -1235,7 +1287,8 @@ xfs_dir2_leaf_lookup_int( tp = args->trans; mp = dp->i_mount; - error = xfs_dir3_leaf_read(tp, dp, args->geo->leafblk, &lbp); + error = xfs_dir3_leaf_read(tp, dp, args->owner, args->geo->leafblk, + &lbp); if (error) return error; diff --git a/libxfs/xfs_dir2_node.c b/libxfs/xfs_dir2_node.c index b00f78387..c0160d725 100644 --- a/libxfs/xfs_dir2_node.c +++ b/libxfs/xfs_dir2_node.c @@ -1559,7 +1559,8 @@ xfs_dir2_leafn_toosmall( /* * Read the sibling leaf block. */ - error = xfs_dir3_leafn_read(state->args->trans, dp, blkno, &bp); + error = xfs_dir3_leafn_read(state->args->trans, dp, + state->args->owner, blkno, &bp); if (error) return error; diff --git a/libxfs/xfs_dir2_priv.h b/libxfs/xfs_dir2_priv.h index 1db2e60ba..2f0e3ad47 100644 --- a/libxfs/xfs_dir2_priv.h +++ b/libxfs/xfs_dir2_priv.h @@ -95,9 +95,9 @@ void xfs_dir2_leaf_hdr_from_disk(struct xfs_mount *mp, void xfs_dir2_leaf_hdr_to_disk(struct xfs_mount *mp, struct xfs_dir2_leaf *to, struct xfs_dir3_icleaf_hdr *from); int xfs_dir3_leaf_read(struct xfs_trans *tp, struct xfs_inode *dp, - xfs_dablk_t fbno, struct xfs_buf **bpp); + xfs_ino_t owner, xfs_dablk_t fbno, struct xfs_buf **bpp); int xfs_dir3_leafn_read(struct xfs_trans *tp, struct xfs_inode *dp, - xfs_dablk_t fbno, struct xfs_buf **bpp); + xfs_ino_t owner, xfs_dablk_t fbno, struct xfs_buf **bpp); extern int xfs_dir2_block_to_leaf(struct xfs_da_args *args, struct xfs_buf *dbp); extern int xfs_dir2_leaf_addname(struct xfs_da_args *args); From patchwork Tue Jul 30 00:28:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745922 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 065CA8C13 for ; Tue, 30 Jul 2024 00:28:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299340; cv=none; b=CpSmeI/PHagxfArBdowSerzCkGXkbCGh2QgI6cjNHpmk4zntpH3zZ5waLvUB/Vy8AgwuSyY53/GwXmONpansoGpdPbpLObJnJS/Y8TjARze/GNSsO4QVGxmAggzHSxnLpFtI5ewDAGIbYT8sLKwrXBCjG2T/l3oU58O/GubyL6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299340; c=relaxed/simple; bh=zydH+z+Y+1A1IRfDLBo7KiWFF2x6ElBeQ2EvFF7HVaY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pgCz2fac8FUkh+OEZgbO3u9qQyNv837rIivaGqm4C+FTIvPaTnEXj5JsyGSmOVgc2/BpwTdLLykIgHH+xbufSGQnFZuYqBqnhdw5I4P3ff0aS4+/8TFNhS36VKbsii+R1kpCJSkBK2lc6sxk4FeVrtCFmN3mb4uuKPHqVE4ruoo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hQyFFv96; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hQyFFv96" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7C03C32786; Tue, 30 Jul 2024 00:28:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299339; bh=zydH+z+Y+1A1IRfDLBo7KiWFF2x6ElBeQ2EvFF7HVaY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=hQyFFv96d1hBx9DX4krj9r1BwXYb75UsKf+j81Yim41tlCdiUq3oE9TOCOfXSrbCx 5qoqau5jW3Xe/b+59+pHSwvx6w9C7tZxRJHaLfoSJLhPToFob13I/CbWviYanUU/od B+tSGkOQ3RGKVU2kSRyAd7M6Kmm4aUqDGWkI2OL9bqg4FMQZcguWeLZYmaaeDQ8K1u kXvCGYZiIRwH+XTR3Kpwj5XJqtXOQnPZsnqisHU9iO9Uuhz/Cer+HLSvRjyOGVCfQZ B07tmEggNiHgK6Xp/nX1HAppBCMBm/WNp+NBLifEObY2PJmb/giVt+50EFcjGwgw7C jsYSpcWfyerBQ== Date: Mon, 29 Jul 2024 17:28:59 -0700 Subject: [PATCH 020/115] xfs: validate explicit directory data buffer owners From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842724.1338752.8940938544601205900.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: cc6740ddb423db2066f7669eaaa377fdbf84ab1e Port the existing directory data header checking function to accept an owner number instead of an xfs_inode, then update the callsites to use xfs_da_args.owner when possible. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- db/namei.c | 3 ++- libxfs/xfs_dir2.h | 1 + libxfs/xfs_dir2_block.c | 3 ++- libxfs/xfs_dir2_data.c | 16 ++++++++++------ libxfs/xfs_dir2_leaf.c | 21 +++++++++++---------- libxfs/xfs_dir2_node.c | 7 +++---- libxfs/xfs_dir2_priv.h | 3 ++- 7 files changed, 31 insertions(+), 23 deletions(-) diff --git a/db/namei.c b/db/namei.c index 5a6fd2036..d2541b78a 100644 --- a/db/namei.c +++ b/db/namei.c @@ -398,7 +398,8 @@ list_leafdir( libxfs_trim_extent(&map, dabno, geo->leafblk - dabno); /* Read the directory block of that first mapping. */ - error = xfs_dir3_data_read(NULL, dp, map.br_startoff, 0, &bp); + error = xfs_dir3_data_read(NULL, dp, args->owner, + map.br_startoff, 0, &bp); if (error) break; diff --git a/libxfs/xfs_dir2.h b/libxfs/xfs_dir2.h index 2f728c26a..d623bfdcd 100644 --- a/libxfs/xfs_dir2.h +++ b/libxfs/xfs_dir2.h @@ -102,6 +102,7 @@ extern struct xfs_dir2_data_free *xfs_dir2_data_freefind( extern int xfs_dir_ino_validate(struct xfs_mount *mp, xfs_ino_t ino); xfs_failaddr_t xfs_dir3_leaf_header_check(struct xfs_buf *bp, xfs_ino_t owner); +xfs_failaddr_t xfs_dir3_data_header_check(struct xfs_buf *bp, xfs_ino_t owner); extern const struct xfs_buf_ops xfs_dir3_block_buf_ops; extern const struct xfs_buf_ops xfs_dir3_leafn_buf_ops; diff --git a/libxfs/xfs_dir2_block.c b/libxfs/xfs_dir2_block.c index c91559e59..6107e01ca 100644 --- a/libxfs/xfs_dir2_block.c +++ b/libxfs/xfs_dir2_block.c @@ -979,7 +979,8 @@ xfs_dir2_leaf_to_block( * Read the data block if we don't already have it, give up if it fails. */ if (!dbp) { - error = xfs_dir3_data_read(tp, dp, args->geo->datablk, 0, &dbp); + error = xfs_dir3_data_read(tp, dp, args->owner, + args->geo->datablk, 0, &dbp); if (error) return error; } diff --git a/libxfs/xfs_dir2_data.c b/libxfs/xfs_dir2_data.c index 6f3ccfeb6..0c77245ee 100644 --- a/libxfs/xfs_dir2_data.c +++ b/libxfs/xfs_dir2_data.c @@ -392,17 +392,20 @@ static const struct xfs_buf_ops xfs_dir3_data_reada_buf_ops = { .verify_write = xfs_dir3_data_write_verify, }; -static xfs_failaddr_t +xfs_failaddr_t xfs_dir3_data_header_check( - struct xfs_inode *dp, - struct xfs_buf *bp) + struct xfs_buf *bp, + xfs_ino_t owner) { - struct xfs_mount *mp = dp->i_mount; + struct xfs_mount *mp = bp->b_mount; if (xfs_has_crc(mp)) { struct xfs_dir3_data_hdr *hdr3 = bp->b_addr; - if (be64_to_cpu(hdr3->hdr.owner) != dp->i_ino) + if (hdr3->hdr.magic != cpu_to_be32(XFS_DIR3_DATA_MAGIC)) + return __this_address; + + if (be64_to_cpu(hdr3->hdr.owner) != owner) return __this_address; } @@ -413,6 +416,7 @@ int xfs_dir3_data_read( struct xfs_trans *tp, struct xfs_inode *dp, + xfs_ino_t owner, xfs_dablk_t bno, unsigned int flags, struct xfs_buf **bpp) @@ -426,7 +430,7 @@ xfs_dir3_data_read( return err; /* Check things that we can't do in the verifier. */ - fa = xfs_dir3_data_header_check(dp, *bpp); + fa = xfs_dir3_data_header_check(*bpp, owner); if (fa) { __xfs_buf_mark_corrupt(*bpp, fa); xfs_trans_brelse(tp, *bpp); diff --git a/libxfs/xfs_dir2_leaf.c b/libxfs/xfs_dir2_leaf.c index 6ce2d4b28..1c12b5a66 100644 --- a/libxfs/xfs_dir2_leaf.c +++ b/libxfs/xfs_dir2_leaf.c @@ -883,9 +883,9 @@ xfs_dir2_leaf_addname( * Already had space in some data block. * Just read that one in. */ - error = xfs_dir3_data_read(tp, dp, - xfs_dir2_db_to_da(args->geo, use_block), - 0, &dbp); + error = xfs_dir3_data_read(tp, dp, args->owner, + xfs_dir2_db_to_da(args->geo, use_block), 0, + &dbp); if (error) { xfs_trans_brelse(tp, lbp); return error; @@ -1326,9 +1326,9 @@ xfs_dir2_leaf_lookup_int( if (newdb != curdb) { if (dbp) xfs_trans_brelse(tp, dbp); - error = xfs_dir3_data_read(tp, dp, - xfs_dir2_db_to_da(args->geo, newdb), - 0, &dbp); + error = xfs_dir3_data_read(tp, dp, args->owner, + xfs_dir2_db_to_da(args->geo, newdb), 0, + &dbp); if (error) { xfs_trans_brelse(tp, lbp); return error; @@ -1368,9 +1368,9 @@ xfs_dir2_leaf_lookup_int( ASSERT(cidb != -1); if (cidb != curdb) { xfs_trans_brelse(tp, dbp); - error = xfs_dir3_data_read(tp, dp, - xfs_dir2_db_to_da(args->geo, cidb), - 0, &dbp); + error = xfs_dir3_data_read(tp, dp, args->owner, + xfs_dir2_db_to_da(args->geo, cidb), 0, + &dbp); if (error) { xfs_trans_brelse(tp, lbp); return error; @@ -1664,7 +1664,8 @@ xfs_dir2_leaf_trim_data( /* * Read the offending data block. We need its buffer. */ - error = xfs_dir3_data_read(tp, dp, xfs_dir2_db_to_da(geo, db), 0, &dbp); + error = xfs_dir3_data_read(tp, dp, args->owner, + xfs_dir2_db_to_da(geo, db), 0, &dbp); if (error) return error; diff --git a/libxfs/xfs_dir2_node.c b/libxfs/xfs_dir2_node.c index c0160d725..690407374 100644 --- a/libxfs/xfs_dir2_node.c +++ b/libxfs/xfs_dir2_node.c @@ -860,7 +860,7 @@ xfs_dir2_leafn_lookup_for_entry( ASSERT(state->extravalid); curbp = state->extrablk.bp; } else { - error = xfs_dir3_data_read(tp, dp, + error = xfs_dir3_data_read(tp, dp, args->owner, xfs_dir2_db_to_da(args->geo, newdb), 0, &curbp); @@ -1946,9 +1946,8 @@ xfs_dir2_node_addname_int( &freehdr, &findex); } else { /* Read the data block in. */ - error = xfs_dir3_data_read(tp, dp, - xfs_dir2_db_to_da(args->geo, dbno), - 0, &dbp); + error = xfs_dir3_data_read(tp, dp, args->owner, + xfs_dir2_db_to_da(args->geo, dbno), 0, &dbp); } if (error) return error; diff --git a/libxfs/xfs_dir2_priv.h b/libxfs/xfs_dir2_priv.h index 2f0e3ad47..879aa2e9f 100644 --- a/libxfs/xfs_dir2_priv.h +++ b/libxfs/xfs_dir2_priv.h @@ -78,7 +78,8 @@ extern void xfs_dir3_data_check(struct xfs_inode *dp, struct xfs_buf *bp); extern xfs_failaddr_t __xfs_dir3_data_check(struct xfs_inode *dp, struct xfs_buf *bp); int xfs_dir3_data_read(struct xfs_trans *tp, struct xfs_inode *dp, - xfs_dablk_t bno, unsigned int flags, struct xfs_buf **bpp); + xfs_ino_t owner, xfs_dablk_t bno, unsigned int flags, + struct xfs_buf **bpp); int xfs_dir3_data_readahead(struct xfs_inode *dp, xfs_dablk_t bno, unsigned int flags); From patchwork Tue Jul 30 00:29:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745923 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 DFF252AE9F for ; Tue, 30 Jul 2024 00:29:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299356; cv=none; b=Lfl6AcMSTKdEpTHngdoBJfJCvwwlzkn0LmmN64pl2M4bpfYPAXupVmQAjb8atVBzfr1Fm4i0BMcXVEXhZ7vl0fOZ8YVi/WMY1WLbwDRJ1vGNSEwKGowPj8gcoiEd2VH3K7RpBAUMXBBO+GSqTwbCmAdktsVYjZYjLgh0xHvbMig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299356; c=relaxed/simple; bh=wrHC1UZzxOsPgOjAqp2ApSXogvKvl6x5hLlyzBvO9lw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l09Qh8ySgxExYsE2FIjJbt/76KfMJiG9bYwAlT7mPnoAKRNBgkGe6ISvH3p7BsHtGPPMABVSQxjNqyhGILvD0VYaYbwlntFNVAQ3KbOt4yOVtIL3pclnC17pflPW9eesQTB6O0PBN+FHUekWm2n9rTI0hR/EaZhUbdLW1s6OcLw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eadcaFKa; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eadcaFKa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E3C5C4AF0E; Tue, 30 Jul 2024 00:29:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299355; bh=wrHC1UZzxOsPgOjAqp2ApSXogvKvl6x5hLlyzBvO9lw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=eadcaFKalXFds0h5OUDGnBkqRNG/veZBLDCa31+/62/j9keBb/KtVq759/28GLXs4 8rqB914sNbcxGuUxpVpMOKF4HxCtKQv24RRCWb+7Hw5ajASRWqspxDL2UMEUigNrk+ X6WxcFKNGyCt6wvj+CErBYKZDSYe1Af6sJ8aIYghategeV6qpayMw1peGXhBSA044T KRZKMF2bi9WUhUcaUELG8nJtkOM2kIL0PWhwR7IuJAl1EbQ14FYqiAsQ7K9TQ2VLc5 FqRhCejO9r9KPcSX+T/WHp4prz3TOx+oYTQsSfc2wRaITUXC5tXHAEd/ayf4OA4h83 m2mgnSZhENPzw== Date: Mon, 29 Jul 2024 17:29:14 -0700 Subject: [PATCH 021/115] xfs: validate explicit directory block buffer owners From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842739.1338752.7558412289675474495.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 29b41ce919b7f0b0c2220e088e450d9b132bec36 Port the existing directory block header checking function to accept an owner number instead of an xfs_inode, then update the callsites to use xfs_da_args.owner when possible. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- db/namei.c | 2 +- libxfs/xfs_dir2.h | 1 + libxfs/xfs_dir2_block.c | 20 ++++++++++++-------- libxfs/xfs_dir2_priv.h | 4 ++-- libxfs/xfs_exchmaps.c | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/db/namei.c b/db/namei.c index d2541b78a..303ca3448 100644 --- a/db/namei.c +++ b/db/namei.c @@ -337,7 +337,7 @@ list_blockdir( unsigned int end; int error; - error = xfs_dir3_block_read(NULL, dp, &bp); + error = xfs_dir3_block_read(NULL, dp, args->owner, &bp); if (error) return error; diff --git a/libxfs/xfs_dir2.h b/libxfs/xfs_dir2.h index d623bfdcd..eb3a5c350 100644 --- a/libxfs/xfs_dir2.h +++ b/libxfs/xfs_dir2.h @@ -103,6 +103,7 @@ extern int xfs_dir_ino_validate(struct xfs_mount *mp, xfs_ino_t ino); xfs_failaddr_t xfs_dir3_leaf_header_check(struct xfs_buf *bp, xfs_ino_t owner); xfs_failaddr_t xfs_dir3_data_header_check(struct xfs_buf *bp, xfs_ino_t owner); +xfs_failaddr_t xfs_dir3_block_header_check(struct xfs_buf *bp, xfs_ino_t owner); extern const struct xfs_buf_ops xfs_dir3_block_buf_ops; extern const struct xfs_buf_ops xfs_dir3_leafn_buf_ops; diff --git a/libxfs/xfs_dir2_block.c b/libxfs/xfs_dir2_block.c index 6107e01ca..82da0d327 100644 --- a/libxfs/xfs_dir2_block.c +++ b/libxfs/xfs_dir2_block.c @@ -112,17 +112,20 @@ const struct xfs_buf_ops xfs_dir3_block_buf_ops = { .verify_struct = xfs_dir3_block_verify, }; -static xfs_failaddr_t +xfs_failaddr_t xfs_dir3_block_header_check( - struct xfs_inode *dp, - struct xfs_buf *bp) + struct xfs_buf *bp, + xfs_ino_t owner) { - struct xfs_mount *mp = dp->i_mount; + struct xfs_mount *mp = bp->b_mount; if (xfs_has_crc(mp)) { struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; - if (be64_to_cpu(hdr3->owner) != dp->i_ino) + if (hdr3->magic != cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)) + return __this_address; + + if (be64_to_cpu(hdr3->owner) != owner) return __this_address; } @@ -133,6 +136,7 @@ int xfs_dir3_block_read( struct xfs_trans *tp, struct xfs_inode *dp, + xfs_ino_t owner, struct xfs_buf **bpp) { struct xfs_mount *mp = dp->i_mount; @@ -145,7 +149,7 @@ xfs_dir3_block_read( return err; /* Check things that we can't do in the verifier. */ - fa = xfs_dir3_block_header_check(dp, *bpp); + fa = xfs_dir3_block_header_check(*bpp, owner); if (fa) { __xfs_buf_mark_corrupt(*bpp, fa); xfs_trans_brelse(tp, *bpp); @@ -380,7 +384,7 @@ xfs_dir2_block_addname( tp = args->trans; /* Read the (one and only) directory block into bp. */ - error = xfs_dir3_block_read(tp, dp, &bp); + error = xfs_dir3_block_read(tp, dp, args->owner, &bp); if (error) return error; @@ -695,7 +699,7 @@ xfs_dir2_block_lookup_int( dp = args->dp; tp = args->trans; - error = xfs_dir3_block_read(tp, dp, &bp); + error = xfs_dir3_block_read(tp, dp, args->owner, &bp); if (error) return error; diff --git a/libxfs/xfs_dir2_priv.h b/libxfs/xfs_dir2_priv.h index 879aa2e9f..adbc544c9 100644 --- a/libxfs/xfs_dir2_priv.h +++ b/libxfs/xfs_dir2_priv.h @@ -50,8 +50,8 @@ extern int xfs_dir_cilookup_result(struct xfs_da_args *args, /* xfs_dir2_block.c */ -extern int xfs_dir3_block_read(struct xfs_trans *tp, struct xfs_inode *dp, - struct xfs_buf **bpp); +int xfs_dir3_block_read(struct xfs_trans *tp, struct xfs_inode *dp, + xfs_ino_t owner, struct xfs_buf **bpp); extern int xfs_dir2_block_addname(struct xfs_da_args *args); extern int xfs_dir2_block_lookup(struct xfs_da_args *args); extern int xfs_dir2_block_removename(struct xfs_da_args *args); diff --git a/libxfs/xfs_exchmaps.c b/libxfs/xfs_exchmaps.c index 21c501aab..71408d713 100644 --- a/libxfs/xfs_exchmaps.c +++ b/libxfs/xfs_exchmaps.c @@ -473,7 +473,7 @@ xfs_exchmaps_dir_to_sf( if (!isblock) return 0; - error = xfs_dir3_block_read(tp, xmi->xmi_ip2, &bp); + error = xfs_dir3_block_read(tp, xmi->xmi_ip2, xmi->xmi_ip2->i_ino, &bp); if (error) return error; From patchwork Tue Jul 30 00:29:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745924 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 52D4810E9 for ; Tue, 30 Jul 2024 00:29:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299371; cv=none; b=hYEBckoCYhaHGcZkbXILc7HCJZP7XJNrZUS4swqKYLufiLCj7s6LC6XLBILZ02cIe611PoEJ+Uu11p8Zq3lr0rte2b7195o1VuluuTBFnrwOGNMM990xqw9yFF3wbLG+Od4ZHoFg2A6s3NVyiWZvY538Mth1h47+EftFitDXy7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299371; c=relaxed/simple; bh=h6mQPA5l5Pk8MyzOrlXVd563D3QqsC2IiDR7JRJac0I=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oB/v0L/KqLp0zh/vOKWh8Aq1paitig1H//S5XSaAfXVsWgL1fQUwbVuJGRhWu5qPz7n+D2raDVpEY8hCtQrMts0H7tJ2QB0SpdsrZ5m5Hsjv05d9ssPcRiVy8GshHINzz4mmFNjNiLDtpZ8cfUevDS4X/F39HfcbVFuU3t6emn0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dIuj+7hu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dIuj+7hu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2991BC4AF0B; Tue, 30 Jul 2024 00:29:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299371; bh=h6mQPA5l5Pk8MyzOrlXVd563D3QqsC2IiDR7JRJac0I=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=dIuj+7hu+ytIbgvifXSUG0T9/Wje9PdmsOBdqvbDi9hOw/9eWtXrR3a6gs1ovHuTt ka+1rhKiCVhkUZhHpYiCZT6+M7BAdw87+t7KnJp9t/oG4HDi18KYtjCqqdayYQ0aBF RHZk0SPSYJltpD1O9snOYdMGMxng4EB+lz0O+5pcHLx9LLiBqM6bDnOk22x/9GI4KF ixwQh1rWFk1rciwvBnBI6/GnZHADjkG/pHzL1SQR0CcZNUG6WgDfYzFnglAnC3yF4m UoMKlBzshcAMmOXKSvCOj+BFntLgLh15lJarSUa7JQCFKHviDTBp1VqMsOmGr19xIp d5PaGaotCzDBg== Date: Mon, 29 Jul 2024 17:29:30 -0700 Subject: [PATCH 022/115] xfs: validate explicit directory free block owners From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842753.1338752.16130123938354956861.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: fe6c9f8e48e0dcbfc3dba17edd88490c8579b34b Port the existing directory freespace block header checking function to accept an owner number instead of an xfs_inode, then update the callsites to use xfs_da_args.owner when possible. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_dir2_leaf.c | 3 ++- libxfs/xfs_dir2_node.c | 32 ++++++++++++++++++-------------- libxfs/xfs_dir2_priv.h | 4 ++-- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/libxfs/xfs_dir2_leaf.c b/libxfs/xfs_dir2_leaf.c index 1c12b5a66..7c0bba512 100644 --- a/libxfs/xfs_dir2_leaf.c +++ b/libxfs/xfs_dir2_leaf.c @@ -1804,7 +1804,8 @@ xfs_dir2_node_to_leaf( /* * Read the freespace block. */ - error = xfs_dir2_free_read(tp, dp, args->geo->freeblk, &fbp); + error = xfs_dir2_free_read(tp, dp, args->owner, args->geo->freeblk, + &fbp); if (error) return error; xfs_dir2_free_hdr_from_disk(mp, &freehdr, fbp->b_addr); diff --git a/libxfs/xfs_dir2_node.c b/libxfs/xfs_dir2_node.c index 690407374..c94d00eb9 100644 --- a/libxfs/xfs_dir2_node.c +++ b/libxfs/xfs_dir2_node.c @@ -172,11 +172,11 @@ const struct xfs_buf_ops xfs_dir3_free_buf_ops = { /* Everything ok in the free block header? */ static xfs_failaddr_t xfs_dir3_free_header_check( - struct xfs_inode *dp, - xfs_dablk_t fbno, - struct xfs_buf *bp) + struct xfs_buf *bp, + xfs_ino_t owner, + xfs_dablk_t fbno) { - struct xfs_mount *mp = dp->i_mount; + struct xfs_mount *mp = bp->b_mount; int maxbests = mp->m_dir_geo->free_max_bests; unsigned int firstdb; @@ -192,7 +192,7 @@ xfs_dir3_free_header_check( return __this_address; if (be32_to_cpu(hdr3->nvalid) < be32_to_cpu(hdr3->nused)) return __this_address; - if (be64_to_cpu(hdr3->hdr.owner) != dp->i_ino) + if (be64_to_cpu(hdr3->hdr.owner) != owner) return __this_address; } else { struct xfs_dir2_free_hdr *hdr = bp->b_addr; @@ -211,6 +211,7 @@ static int __xfs_dir3_free_read( struct xfs_trans *tp, struct xfs_inode *dp, + xfs_ino_t owner, xfs_dablk_t fbno, unsigned int flags, struct xfs_buf **bpp) @@ -224,7 +225,7 @@ __xfs_dir3_free_read( return err; /* Check things that we can't do in the verifier. */ - fa = xfs_dir3_free_header_check(dp, fbno, *bpp); + fa = xfs_dir3_free_header_check(*bpp, owner, fbno); if (fa) { __xfs_buf_mark_corrupt(*bpp, fa); xfs_trans_brelse(tp, *bpp); @@ -296,20 +297,23 @@ int xfs_dir2_free_read( struct xfs_trans *tp, struct xfs_inode *dp, + xfs_ino_t owner, xfs_dablk_t fbno, struct xfs_buf **bpp) { - return __xfs_dir3_free_read(tp, dp, fbno, 0, bpp); + return __xfs_dir3_free_read(tp, dp, owner, fbno, 0, bpp); } static int xfs_dir2_free_try_read( struct xfs_trans *tp, struct xfs_inode *dp, + xfs_ino_t owner, xfs_dablk_t fbno, struct xfs_buf **bpp) { - return __xfs_dir3_free_read(tp, dp, fbno, XFS_DABUF_MAP_HOLE_OK, bpp); + return __xfs_dir3_free_read(tp, dp, owner, fbno, XFS_DABUF_MAP_HOLE_OK, + bpp); } static int @@ -714,7 +718,7 @@ xfs_dir2_leafn_lookup_for_addname( if (curbp) xfs_trans_brelse(tp, curbp); - error = xfs_dir2_free_read(tp, dp, + error = xfs_dir2_free_read(tp, dp, args->owner, xfs_dir2_db_to_da(args->geo, newfdb), &curbp); @@ -1353,8 +1357,8 @@ xfs_dir2_leafn_remove( * read in the free block. */ fdb = xfs_dir2_db_to_fdb(geo, db); - error = xfs_dir2_free_read(tp, dp, xfs_dir2_db_to_da(geo, fdb), - &fbp); + error = xfs_dir2_free_read(tp, dp, args->owner, + xfs_dir2_db_to_da(geo, fdb), &fbp); if (error) return error; free = fbp->b_addr; @@ -1713,7 +1717,7 @@ xfs_dir2_node_add_datablk( * that was just allocated. */ fbno = xfs_dir2_db_to_fdb(args->geo, *dbno); - error = xfs_dir2_free_try_read(tp, dp, + error = xfs_dir2_free_try_read(tp, dp, args->owner, xfs_dir2_db_to_da(args->geo, fbno), &fbp); if (error) return error; @@ -1860,7 +1864,7 @@ xfs_dir2_node_find_freeblk( * so this might not succeed. This should be really rare, so * there's no reason to avoid it. */ - error = xfs_dir2_free_try_read(tp, dp, + error = xfs_dir2_free_try_read(tp, dp, args->owner, xfs_dir2_db_to_da(args->geo, fbno), &fbp); if (error) @@ -2299,7 +2303,7 @@ xfs_dir2_node_trim_free( /* * Read the freespace block. */ - error = xfs_dir2_free_try_read(tp, dp, fo, &bp); + error = xfs_dir2_free_try_read(tp, dp, args->owner, fo, &bp); if (error) return error; /* diff --git a/libxfs/xfs_dir2_priv.h b/libxfs/xfs_dir2_priv.h index adbc544c9..3befb3250 100644 --- a/libxfs/xfs_dir2_priv.h +++ b/libxfs/xfs_dir2_priv.h @@ -155,8 +155,8 @@ extern int xfs_dir2_node_removename(struct xfs_da_args *args); extern int xfs_dir2_node_replace(struct xfs_da_args *args); extern int xfs_dir2_node_trim_free(struct xfs_da_args *args, xfs_fileoff_t fo, int *rvalp); -extern int xfs_dir2_free_read(struct xfs_trans *tp, struct xfs_inode *dp, - xfs_dablk_t fbno, struct xfs_buf **bpp); +int xfs_dir2_free_read(struct xfs_trans *tp, struct xfs_inode *dp, + xfs_ino_t owner, xfs_dablk_t fbno, struct xfs_buf **bpp); /* xfs_dir2_sf.c */ xfs_ino_t xfs_dir2_sf_get_ino(struct xfs_mount *mp, struct xfs_dir2_sf_hdr *hdr, From patchwork Tue Jul 30 00:29:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745925 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 57DA3BA38 for ; Tue, 30 Jul 2024 00:29:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299387; cv=none; b=EPTAVQIke25z4aYMc3lsVCYduV38pgYEMZCFk/RTNuAcj8YBqRGHg/lI/hughyzbFKWfDOl+82TS2VswjIvopVwwgCrQfyA4YaFekvT+zpmEyJLN+ss7Hv6DwysreLVd/ioV6rKhuk/NN3EaBQzimn+HchfiPVt6MUrxW7lt/TM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299387; c=relaxed/simple; bh=kd3/Bj2B7H/L0vqTGtmxmOv1voNMgS5GKGDWNUUd6Z8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pllS5D8xr+76EBE7BEEFju+3hWBumBdEEfaWSFYFAdxxz3rWOhbdfZO1j78GX2y9jGQh9DnlTc9Ulz8sve+ggzhSl5l2RZE1hJ7pRHgwap7E8qoLjCisxD/J8jnfZGUS+EifHk8QkBredvpHMYAws3V/GqhqAKyD3uzBACIEUGc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ki3vDSmW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ki3vDSmW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CAFB6C32786; Tue, 30 Jul 2024 00:29:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299386; bh=kd3/Bj2B7H/L0vqTGtmxmOv1voNMgS5GKGDWNUUd6Z8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Ki3vDSmWDiPhAnkdade6zlnDGD4Qi6hfukZgKLle2jf5Aw0Ajw8z7xEl1wWv6k9+P waHXYChCnGUSKrMJKaBRoSAdOiY15ZVaHoqAyYfN3HbD81q0If8VtRVO9rcWc7fx0q ZMAYSbEN8Z+WFaCiuv56zbncY4giD2elAlYJhZtXn7IOVxo7iYyH00LbwcCxpB5HBl ZJ5Rwv5zv+Rs/O1Qx7XflQ4aXM3PSFoaXWtFHIKJvvLPfwRU19/+v1OFghUB1Nq5p9 ZQPDCUD6AZVXHt3AiR6gq1/+5smbaQ/N2KMGrNtQqr02M+iNydWz13zWaND3mWlhYU OMfl3yP+ooFGw== Date: Mon, 29 Jul 2024 17:29:46 -0700 Subject: [PATCH 023/115] xfs: use atomic extent swapping to fix user file fork data From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842767.1338752.13236502200324811627.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 629fdaf5f5b1b7f7107ed4de04e0991a99501ced Build on the code that was recently added to the temporary repair file code so that we can atomically switch the contents of any file fork, even if the fork is in local format. The upcoming functions to repair xattrs, directories, and symlinks will need that capability. Repair can lock out access to these user files by holding IOLOCK_EXCL on these user files. Therefore, it is safe to drop the ILOCK of both the file being repaired and the tempfile being used for staging, and cancel the scrub transaction. We do this so that we can reuse the resource estimation and transaction allocation functions used by a regular file exchange operation. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_exchmaps.c | 2 +- libxfs/xfs_exchmaps.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_exchmaps.c b/libxfs/xfs_exchmaps.c index 71408d713..a8a51ce53 100644 --- a/libxfs/xfs_exchmaps.c +++ b/libxfs/xfs_exchmaps.c @@ -672,7 +672,7 @@ xfs_exchmaps_rmapbt_blocks( } /* Estimate the bmbt and rmapbt overhead required to exchange mappings. */ -static int +int xfs_exchmaps_estimate_overhead( struct xfs_exchmaps_req *req) { diff --git a/libxfs/xfs_exchmaps.h b/libxfs/xfs_exchmaps.h index d8718fca6..fa822dff2 100644 --- a/libxfs/xfs_exchmaps.h +++ b/libxfs/xfs_exchmaps.h @@ -97,6 +97,7 @@ xfs_exchmaps_reqfork(const struct xfs_exchmaps_req *req) return XFS_DATA_FORK; } +int xfs_exchmaps_estimate_overhead(struct xfs_exchmaps_req *req); int xfs_exchmaps_estimate(struct xfs_exchmaps_req *req); extern struct kmem_cache *xfs_exchmaps_intent_cache; From patchwork Tue Jul 30 00:30:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745926 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A5F2CC2C6 for ; Tue, 30 Jul 2024 00:30:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299402; cv=none; b=Q+/rbcFXWLrbqX/b7Y/zKjzJeTFPU1xHLfO8wVHlSnEPOW5Wy2X+nz3lBkU9sJKIfoZBWhVJFXcp1iWmjnS1Vu8P35i/G9XTxmp3Hu6iGlshI+sZlxkcLfP7a5+CzIeVFxfuPlb6s8WSKPOuAamm8lQsi8GkdpVRTx9L6S2P74E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299402; c=relaxed/simple; bh=tfbpyHP6Ify91BDRWZYkb9DKk3NMNTL7sy+UkveQvFY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fPGC0xB8qNruu1A7Jk1uM08rdd4fSLyP9GvRvuWIYAFXBR/9ihxaQPTqeZmbsXFpdQudZBB6xFJ7BHAYlTTG6vRaUrYdNg4WY1ZiR9Y0ocNf+0pybp6i+ASK9t8I5O2JCf39bkJ2qeJJj0niIVkVS0MZ4GwPrCYwKjhMwToVit0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dHDd3PnD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dHDd3PnD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F92FC32786; Tue, 30 Jul 2024 00:30:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299402; bh=tfbpyHP6Ify91BDRWZYkb9DKk3NMNTL7sy+UkveQvFY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=dHDd3PnD0jGBmGiWUhAmHPAYIt1bKzB27FL2ulKeL+fRvMFm3HHP5RnbEJX+o6Bry xnOfi1JZdBS5H2X8i8fYEmpLkTkIhaW28n79xcsZplFqyKaKnaSSB4dbsrnidIAIh7 +KBCLxT95w/yHDHMNIq+CkjiKs+mjBbA0gaxTPrXmrh+sH7FaCpZF4dF+y/51KpUQs iR7Ifk/YXGJOqWHrJblI0JZiZ/ADpgQ5El7O/mJ61RXZDz+jiX9YG6H/ZvwqYg4V3k d0u8WTlf6Y5DoYYPi2IvM79HlmhRT6B/FULJLLWowUnVCEIuBhgDejsiM5kEumpaDb 9+WhNiMtSlJFg== Date: Mon, 29 Jul 2024 17:30:02 -0700 Subject: [PATCH 024/115] xfs: repair extended attributes From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842782.1338752.9798387885491587085.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: e47dcf113ae348678143cc935a1183059c02c9ad If the extended attributes look bad, try to sift through the rubble to find whatever keys/values we can, stage a new attribute structure in a temporary file and use the atomic extent swapping mechanism to commit the results in bulk. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr.c | 2 +- libxfs/xfs_attr.h | 2 ++ libxfs/xfs_da_format.h | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index cc291cf76..07f873927 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -1053,7 +1053,7 @@ xfs_attr_set( * External routines when attribute list is inside the inode *========================================================================*/ -static inline int xfs_attr_sf_totsize(struct xfs_inode *dp) +int xfs_attr_sf_totsize(struct xfs_inode *dp) { struct xfs_attr_sf_hdr *sf = dp->i_af.if_data; diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h index 81be9b3e4..e4f550085 100644 --- a/libxfs/xfs_attr.h +++ b/libxfs/xfs_attr.h @@ -618,4 +618,6 @@ extern struct kmem_cache *xfs_attr_intent_cache; int __init xfs_attr_intent_init_cache(void); void xfs_attr_intent_destroy_cache(void); +int xfs_attr_sf_totsize(struct xfs_inode *dp); + #endif /* __XFS_ATTR_H__ */ diff --git a/libxfs/xfs_da_format.h b/libxfs/xfs_da_format.h index 060e5c96b..aac3fe039 100644 --- a/libxfs/xfs_da_format.h +++ b/libxfs/xfs_da_format.h @@ -721,6 +721,11 @@ struct xfs_attr3_leafblock { #define XFS_ATTR_INCOMPLETE (1u << XFS_ATTR_INCOMPLETE_BIT) #define XFS_ATTR_NSP_ONDISK_MASK (XFS_ATTR_ROOT | XFS_ATTR_SECURE) +#define XFS_ATTR_NAMESPACE_STR \ + { XFS_ATTR_LOCAL, "local" }, \ + { XFS_ATTR_ROOT, "root" }, \ + { XFS_ATTR_SECURE, "secure" } + /* * Alignment for namelist and valuelist entries (since they are mixed * there can be only one alignment value) From patchwork Tue Jul 30 00:30:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745927 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 9C5C77E6 for ; Tue, 30 Jul 2024 00:30:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299418; cv=none; b=Vt423PoQj8tp0/d8kBHp2X3PAwTrrq5OKzoxn+TK73lqDV1ot2LC0QaN2gNM8WHl6WYE1EBQhmlaj10p35hQujS3jGG/po/j45mrGZViEDqzW6IirrHZrYMzvSfir6ThYTJP8jpd65fAU67MVIaW6O5C+af5mGfOJs1CQExDDW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299418; c=relaxed/simple; bh=lERqdodjM0owbvnQKFMZ6ftQ9V/eyK2dv++2P9+I8dw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Y7ErWYQlRz9rrd2dowVdwhGr4T0q9qO1wrrtmVJrkiDAX9QDYPAuCHvF4sVMOvFgbdttkI4B/kZvSftMMQgU96jK6ddBYljc7CU/mDy3yShciRlN8Q2KotfeRdQfkRKHUty9pxVm7t2+Ockhy6P8AappxmWEkOzPxZH9btRJ0RU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qzkagoJ7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qzkagoJ7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 250E3C32786; Tue, 30 Jul 2024 00:30:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299418; bh=lERqdodjM0owbvnQKFMZ6ftQ9V/eyK2dv++2P9+I8dw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=qzkagoJ7EgSKB8iAZ9+bKFNIEUtBPHm4hvRgJvnDrfhrAbGU3sxWv/a79Qx2y3Wpq h0VAhfNPq+Ed7Pxvms5OCEQWOq16V2E5Qc6GScgUi9u+wp71K2YX8saEiu3+L+GyI1 M0mBGYGpRaxBKnDCohug11z04Dg77i5f8inVVnxeEghNLUWN44D8WehSX9NbmRk0KY lxohtpqY2demIvE7LEXzHrp7ZmnZLhG2Ij3rZDEa5JrDyU5Ev1XLqMG5Ub3i5lCjL9 xDLCETrF+MoxEDvMq3TwHXocZNjaoveghxHD3BX/9jKPh2q8sokhsh8Xz8dN+Mvnk8 4Q4SOt6AVaA2w== Date: Mon, 29 Jul 2024 17:30:17 -0700 Subject: [PATCH 025/115] xfs: expose xfs_bmap_local_to_extents for online repair From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842795.1338752.8294926697673625653.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: ef744be416b5c649d287604730400dfa728779fe Allow online repair to call xfs_bmap_local_to_extents and add a void * argument at the end so that online repair can pass its own context. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_bmap.c | 11 ++++++----- libxfs/xfs_bmap.h | 6 ++++++ libxfs/xfs_symlink_remote.c | 3 ++- libxfs/xfs_symlink_remote.h | 3 ++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 868334229..63feb20e2 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -773,7 +773,7 @@ xfs_bmap_local_to_extents_empty( } -STATIC int /* error */ +int /* error */ xfs_bmap_local_to_extents( xfs_trans_t *tp, /* transaction pointer */ xfs_inode_t *ip, /* incore inode pointer */ @@ -783,7 +783,8 @@ xfs_bmap_local_to_extents( void (*init_fn)(struct xfs_trans *tp, struct xfs_buf *bp, struct xfs_inode *ip, - struct xfs_ifork *ifp)) + struct xfs_ifork *ifp, void *priv), + void *priv) { int error = 0; int flags; /* logging flags returned */ @@ -844,7 +845,7 @@ xfs_bmap_local_to_extents( * log here. Note that init_fn must also set the buffer log item type * correctly. */ - init_fn(tp, bp, ip, ifp); + init_fn(tp, bp, ip, ifp, priv); /* account for the change in fork size */ xfs_idata_realloc(ip, -ifp->if_bytes, whichfork); @@ -976,8 +977,8 @@ xfs_bmap_add_attrfork_local( if (S_ISLNK(VFS_I(ip)->i_mode)) return xfs_bmap_local_to_extents(tp, ip, 1, flags, - XFS_DATA_FORK, - xfs_symlink_local_to_remote); + XFS_DATA_FORK, xfs_symlink_local_to_remote, + NULL); /* should only be called for types that support local format data */ ASSERT(0); diff --git a/libxfs/xfs_bmap.h b/libxfs/xfs_bmap.h index b8bdbf156..32fb2a455 100644 --- a/libxfs/xfs_bmap.h +++ b/libxfs/xfs_bmap.h @@ -179,6 +179,12 @@ unsigned int xfs_bmap_compute_attr_offset(struct xfs_mount *mp); int xfs_bmap_add_attrfork(struct xfs_inode *ip, int size, int rsvd); void xfs_bmap_local_to_extents_empty(struct xfs_trans *tp, struct xfs_inode *ip, int whichfork); +int xfs_bmap_local_to_extents(struct xfs_trans *tp, struct xfs_inode *ip, + xfs_extlen_t total, int *logflagsp, int whichfork, + void (*init_fn)(struct xfs_trans *tp, struct xfs_buf *bp, + struct xfs_inode *ip, struct xfs_ifork *ifp, + void *priv), + void *priv); void xfs_bmap_compute_maxlevels(struct xfs_mount *mp, int whichfork); int xfs_bmap_first_unused(struct xfs_trans *tp, struct xfs_inode *ip, xfs_extlen_t len, xfs_fileoff_t *unused, int whichfork); diff --git a/libxfs/xfs_symlink_remote.c b/libxfs/xfs_symlink_remote.c index 72f175990..fbcd1aebb 100644 --- a/libxfs/xfs_symlink_remote.c +++ b/libxfs/xfs_symlink_remote.c @@ -166,7 +166,8 @@ xfs_symlink_local_to_remote( struct xfs_trans *tp, struct xfs_buf *bp, struct xfs_inode *ip, - struct xfs_ifork *ifp) + struct xfs_ifork *ifp, + void *priv) { struct xfs_mount *mp = ip->i_mount; char *buf; diff --git a/libxfs/xfs_symlink_remote.h b/libxfs/xfs_symlink_remote.h index ac3dac8f6..83b89a1de 100644 --- a/libxfs/xfs_symlink_remote.h +++ b/libxfs/xfs_symlink_remote.h @@ -16,7 +16,8 @@ int xfs_symlink_hdr_set(struct xfs_mount *mp, xfs_ino_t ino, uint32_t offset, bool xfs_symlink_hdr_ok(xfs_ino_t ino, uint32_t offset, uint32_t size, struct xfs_buf *bp); void xfs_symlink_local_to_remote(struct xfs_trans *tp, struct xfs_buf *bp, - struct xfs_inode *ip, struct xfs_ifork *ifp); + struct xfs_inode *ip, struct xfs_ifork *ifp, + void *priv); xfs_failaddr_t xfs_symlink_shortform_verify(void *sfp, int64_t size); int xfs_symlink_remote_read(struct xfs_inode *ip, char *link); int xfs_symlink_write_target(struct xfs_trans *tp, struct xfs_inode *ip, From patchwork Tue Jul 30 00:30:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745928 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 47471F9D6 for ; Tue, 30 Jul 2024 00:30:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299434; cv=none; b=HL9Hw5Zed5VMGtg7qEPbzXQrFtOHjvv47LiWfJDHIsDm1QfWGMkjThLEhnQZ604bJ/of4RZbjF1mXA7jfc2E4VeWdzUWv9bAKFAyxBmnyV+Bs88ixNBPPSTnO1RYDLVK8fwGz4jWO3zvsfKvkatGQ72JCntXA7PmnsAbks6IHeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299434; c=relaxed/simple; bh=auztCkabC6+I7P34xpJHvvE+r80Z6f5LkqPGYiXeoW8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YWi0UawB+XlaTsuAoh7qGphgjRg2GB4D7LjIzz+fMdFa9v6ToKZxvagqkvdaB6vjctIQD1yMWZ+iUdaS7fzLkIwew1otJDfP4cniEp8i2Fw2ojtCCIq8mQzk+zk71PVE4J5arMh5Y6Wqtz1C9TORSkSCeM+S05m5H+0GdIxw89A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g7clOb2b; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="g7clOb2b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF2B2C32786; Tue, 30 Jul 2024 00:30:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299433; bh=auztCkabC6+I7P34xpJHvvE+r80Z6f5LkqPGYiXeoW8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=g7clOb2bdvvgyb0hISgeyN61IvS95dQ0/to6phScrN3ts4d7bOxwfZvmBQBHtMojT Q4dZlcssRj0Pii6IBYrkHu4X67MlCkZ2Yt3R7oJ+sWYlhbw5KpGiqElRKc3AZdcu64 r6iZNRJp5egE7GtoAxE3OGGwJDJRPLWw1ZcFCFG/VEuZoTHAIaLwbYr2DRMB/kpmpa GdLEwGZQli6Y7UeHXA11c0XnbTVdUNCAkY11QAs7breE8nqpD0Qfa+DBuORqUyTxiY mB7pgvkMu6quQ+ZwTUkPf9dOGQk6+HtsxmkfPSWNyGGy6rQnWBLF59DI7hIFIKInUr hhB3Xbf3TyUSQ== Date: Mon, 29 Jul 2024 17:30:33 -0700 Subject: [PATCH 026/115] xfs: pass the owner to xfs_symlink_write_target From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842810.1338752.14366833683859202866.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: ea8214c3195c2ed3a205dea42bbe7746712fc461 Require callers of xfs_symlink_write_target to pass the owner number explicitly. This sets us up for online repair to be able to write a remote symlink target to sc->tempip with sc->ip's inumber in the block heaader. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_symlink_remote.c | 4 ++-- libxfs/xfs_symlink_remote.h | 4 ++-- mkfs/proto.c | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libxfs/xfs_symlink_remote.c b/libxfs/xfs_symlink_remote.c index fbcd1aebb..2ad586f39 100644 --- a/libxfs/xfs_symlink_remote.c +++ b/libxfs/xfs_symlink_remote.c @@ -308,6 +308,7 @@ int xfs_symlink_write_target( struct xfs_trans *tp, struct xfs_inode *ip, + xfs_ino_t owner, const char *target_path, int pathlen, xfs_fsblock_t fs_blocks, @@ -362,8 +363,7 @@ xfs_symlink_write_target( byte_cnt = min(byte_cnt, pathlen); buf = bp->b_addr; - buf += xfs_symlink_hdr_set(mp, ip->i_ino, offset, byte_cnt, - bp); + buf += xfs_symlink_hdr_set(mp, owner, offset, byte_cnt, bp); memcpy(buf, cur_chunk, byte_cnt); diff --git a/libxfs/xfs_symlink_remote.h b/libxfs/xfs_symlink_remote.h index 83b89a1de..c1672fe1f 100644 --- a/libxfs/xfs_symlink_remote.h +++ b/libxfs/xfs_symlink_remote.h @@ -21,8 +21,8 @@ void xfs_symlink_local_to_remote(struct xfs_trans *tp, struct xfs_buf *bp, xfs_failaddr_t xfs_symlink_shortform_verify(void *sfp, int64_t size); int xfs_symlink_remote_read(struct xfs_inode *ip, char *link); int xfs_symlink_write_target(struct xfs_trans *tp, struct xfs_inode *ip, - const char *target_path, int pathlen, xfs_fsblock_t fs_blocks, - uint resblks); + xfs_ino_t owner, const char *target_path, int pathlen, + xfs_fsblock_t fs_blocks, uint resblks); int xfs_symlink_remote_truncate(struct xfs_trans *tp, struct xfs_inode *ip); #endif /* __XFS_SYMLINK_REMOTE_H */ diff --git a/mkfs/proto.c b/mkfs/proto.c index a923f9c10..5125ee44f 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -252,7 +252,8 @@ writesymlink( xfs_extlen_t nb = XFS_B_TO_FSB(mp, len); int error; - error = -libxfs_symlink_write_target(tp, ip, buf, len, nb, nb); + error = -libxfs_symlink_write_target(tp, ip, ip->i_ino, buf, len, nb, + nb); if (error) { fprintf(stderr, _("%s: error %d creating symlink to '%s'.\n"), progname, error, buf); From patchwork Tue Jul 30 00:30:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745929 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 92777621 for ; Tue, 30 Jul 2024 00:30:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299449; cv=none; b=QU+XsirkTAoh2SZ/OKnVURQf9WnTijYJYDwH0P+JiCXywgs30ZjYdLKe5RvV/Ag8RsIHu4YcygfRYLBtzrJfV4owb+Wa336Nydd2Crs9HmR8uDUMbJUG1PVPQKiDeZtlkIl9frGFl+NaFL5EgtSb3FdLdLDtxMh6UFPuSPM5kVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299449; c=relaxed/simple; bh=7GtJ2hLxQ5NL+C4VNNj9EnBCXdko7Mkt0R8IG/ecJx0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MsXcxQpBTHucXqVLHf76wh9dib2GfbfyLZ3KSjaE0di4VfcKOBkPaOrlbaINi7hyFivWUDqhj2IVvE9n9/8iklN7kFD4XPlsgCCKI6WpfXXsCJJcZ52eCzlJVM3XREbuTzNCBRK7jjIppXk9vlOr4Dgzuxa2H8kZ9LGKWJwL+GM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JR1gzURV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JR1gzURV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BE50C4AF07; Tue, 30 Jul 2024 00:30:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299449; bh=7GtJ2hLxQ5NL+C4VNNj9EnBCXdko7Mkt0R8IG/ecJx0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=JR1gzURV2JvEN6tEn1AZqXCBDPQCI8PidYvcf9myK3Wtty7i2GUIknPVzEcX+GgFv jQ2h34o/dbaXt7BUUmsMQcrjWmh3eq90aNy19Hojb1PU2xCNmL3kQPatMdXboz9mmr f4mPf0VnCYlKkzJ3PdoVCU5+UKO58LCpb0A3DbiRYKOfUzVxyF4BwKaDRsuomy+ZKR y7w6Vt4SmTL473LBGpRJN0pi3XGg/vtJ4ApeLV+hqL5AlwyCSBjxaXS5DcGyD0iOCG I2vV5h6kaeHDzCSh6P+nF35y8MCK81QFMbYH8HcXkEDD1qOTWSpfvFtHz/0XHPWcEL U097DAV0Lh6TA== Date: Mon, 29 Jul 2024 17:30:49 -0700 Subject: [PATCH 027/115] xfs: check unused nlink fields in the ondisk inode From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842824.1338752.8524616543740957475.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 40cb8613d6122ca80a9e42e4cecc4d308c3b80fb v2/v3 inodes use di_nlink and not di_onlink; and v1 inodes use di_onlink and not di_nlink. Whichever field is not in use, make sure its contents are zero, and teach xfs_scrub to fix that if it is. This clears a bunch of missing scrub failure errors in xfs/385 for core.onlink. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_inode_buf.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libxfs/xfs_inode_buf.c b/libxfs/xfs_inode_buf.c index 82cf64db9..aee581d53 100644 --- a/libxfs/xfs_inode_buf.c +++ b/libxfs/xfs_inode_buf.c @@ -488,6 +488,14 @@ xfs_dinode_verify( return __this_address; } + if (dip->di_version > 1) { + if (dip->di_onlink) + return __this_address; + } else { + if (dip->di_nlink) + return __this_address; + } + /* don't allow invalid i_size */ di_size = be64_to_cpu(dip->di_size); if (di_size & (1ULL << 63)) From patchwork Tue Jul 30 00:31:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745930 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7DA194A11 for ; Tue, 30 Jul 2024 00:31:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299465; cv=none; b=DBHquw4I7VesGihzxrFlt0eggkdGixjh1CC3lDwD7sxyb0/KJppyY3bvofGrOHTDok1MgfGRUY8hu9dSqDIPIJEC82lluGHKTSTmEttH0z94huzwLT1iQiwS3eBSR6d3PJScOnRtAwSYoOPvUvAKP6mtFYVpBVfsqv2x8P6ZgWk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299465; c=relaxed/simple; bh=yoV+PaP3B4jPyUMnVMu8AfI0bewOWJOcuoG55CGezys=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=srA9VFx07XKyWarIuvqov5NemXTydwjMBmwzcKMm2yHlFxCErx/gWXqhjwgBOoPrYu3teYNu/CBaYPeXrvEJLNxNkovU79ve0O8z4pHgbjd91ctBSSKngPCoIQ5ZNGHkOwuEl+U23xVf9FhS2SKuj/2KFfpAEkAxmVDdDVFr++0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lT1K4y5k; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lT1K4y5k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12B35C32786; Tue, 30 Jul 2024 00:31:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299465; bh=yoV+PaP3B4jPyUMnVMu8AfI0bewOWJOcuoG55CGezys=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=lT1K4y5kLUyGwQISE5On8rO2Z2hV3enzAOI08pmzEqxgyGIBQscXHkpKOtTzQauS4 3hjKJEVWzQWvCLNT+I3RpJfsL3kV9HCxZhHr+QNpYTM6bSy5TrDjA0Sh3XTpuAcr8u ie4w37gEfxWzNlHd6Xk8Ipc9sO+ZSF/2TZ3ILLonJZ7vFksU3SMo5jY1peEMBSoWd8 HzBM2PHCpQ3nCGxBbk/9Pygxw/PcMeXEf3jtF0y3pUTMM6X/HPM3OmVTFiaQGVuNLL zhOQDGb5wgBcsPHpNc0FYmJx16flAK/pJHUDOSsELc9753VqwGJ6C8VtkO5jNSh7v/ IcZxJsLw7Pf8g== Date: Mon, 29 Jul 2024 17:31:04 -0700 Subject: [PATCH 028/115] xfs: try to avoid allocating from sick inode clusters From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842838.1338752.15052750263469564877.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 2935213a6831a0087442d406301c2cdcc87b0f61 I noticed that xfs/413 and xfs/375 occasionally failed while fuzzing core.mode of an inode. The root cause of these problems is that the field we fuzzed (core.mode or core.magic, typically) causes the entire inode cluster buffer verification to fail, which affects several inodes at once. The repair process tries to create either a /lost+found or a temporary repair file, but regrettably it picks the same inode cluster that we just corrupted, with the result that repair triggers the demise of the filesystem. Try avoid this by making the inode allocation path detect when the perag health status indicates that someone has found bad inode cluster buffers, and try to read the inode cluster buffer. If the cluster buffer fails the verifiers, try another AG. This isn't foolproof and can result in premature ENOSPC, but that might be better than shutting down. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/util.c | 6 ++++++ libxfs/xfs_ialloc.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/libxfs/util.c b/libxfs/util.c index 841f4b963..2656c99a8 100644 --- a/libxfs/util.c +++ b/libxfs/util.c @@ -732,6 +732,12 @@ void xfs_fs_mark_sick(struct xfs_mount *mp, unsigned int mask) { } void xfs_agno_mark_sick(struct xfs_mount *mp, xfs_agnumber_t agno, unsigned int mask) { } void xfs_ag_mark_sick(struct xfs_perag *pag, unsigned int mask) { } +void xfs_ag_measure_sickness(struct xfs_perag *pag, unsigned int *sick, + unsigned int *checked) +{ + *sick = 0; + *checked = 0; +} void xfs_bmap_mark_sick(struct xfs_inode *ip, int whichfork) { } void xfs_btree_mark_sick(struct xfs_btree_cur *cur) { } void xfs_dirattr_mark_sick(struct xfs_inode *ip, int whichfork) { } diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c index 992b8348a..d8697561e 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -1052,6 +1052,33 @@ xfs_inobt_first_free_inode( return xfs_lowbit64(realfree); } +/* + * If this AG has corrupt inodes, check if allocating this inode would fail + * with corruption errors. Returns 0 if we're clear, or EAGAIN to try again + * somewhere else. + */ +static int +xfs_dialloc_check_ino( + struct xfs_perag *pag, + struct xfs_trans *tp, + xfs_ino_t ino) +{ + struct xfs_imap imap; + struct xfs_buf *bp; + int error; + + error = xfs_imap(pag, tp, ino, &imap, 0); + if (error) + return -EAGAIN; + + error = xfs_imap_to_bp(pag->pag_mount, tp, &imap, &bp); + if (error) + return -EAGAIN; + + xfs_trans_brelse(tp, bp); + return 0; +} + /* * Allocate an inode using the inobt-only algorithm. */ @@ -1304,6 +1331,13 @@ xfs_dialloc_ag_inobt( ASSERT((XFS_AGINO_TO_OFFSET(mp, rec.ir_startino) % XFS_INODES_PER_CHUNK) == 0); ino = XFS_AGINO_TO_INO(mp, pag->pag_agno, rec.ir_startino + offset); + + if (xfs_ag_has_sickness(pag, XFS_SICK_AG_INODES)) { + error = xfs_dialloc_check_ino(pag, tp, ino); + if (error) + goto error0; + } + rec.ir_free &= ~XFS_INOBT_MASK(offset); rec.ir_freecount--; error = xfs_inobt_update(cur, &rec); @@ -1579,6 +1613,12 @@ xfs_dialloc_ag( XFS_INODES_PER_CHUNK) == 0); ino = XFS_AGINO_TO_INO(mp, pag->pag_agno, rec.ir_startino + offset); + if (xfs_ag_has_sickness(pag, XFS_SICK_AG_INODES)) { + error = xfs_dialloc_check_ino(pag, tp, ino); + if (error) + goto error_cur; + } + /* * Modify or remove the finobt record. */ From patchwork Tue Jul 30 00:31:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745945 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2D90C8C1F for ; Tue, 30 Jul 2024 00:31:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299481; cv=none; b=KMv/888kgVQYeNjqMXqdzEnJJJpU6DllczXN9knHzbicUiAXBve7O0qCiu8B4A23da7bAAkjlq5VTV30WMZuYVIJoKPgvPxx0pbMdoKyiP+hq5lzXT6f6o0Wrc1BPvv5csCm92I9mQQFqqJ/OckinkUjrQY0mCsX2ksf+Bl348A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299481; c=relaxed/simple; bh=39IakTWi3zCEICDb52Uoee0r66UA2LI5mhjfhQ8T9RY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Z+Imue81GNf64FIhiEpLzMAgfNiRr4ScOwaqZOrDKCe83iGa6Zlp6XRIkIe7Mrtttybxac5YtXOLiz1kSK4ogKscyBQSKskLHIf3FLJZU7wxLnc48+v9SxU1fTzlqS16gh1KNgsRR+1Syv3yPUrAL/QNpd3wEc+8cqnHvILKrkM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ksoBP7mK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ksoBP7mK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9329C4AF07; Tue, 30 Jul 2024 00:31:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299480; bh=39IakTWi3zCEICDb52Uoee0r66UA2LI5mhjfhQ8T9RY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ksoBP7mKcI1ghOxk7hXOUt1//OKpxk6V/ap/CS84CQW/9vtj+7485nfbB+HY/V8Vc WdF0vGSl/hsrzFfSqA0lKK+lrEd19PTiV4fmK9bLncNy2rhUKyLeZrXnkZPd0aKvfb CagXRwXPn8lJ+0a+DjvAHgbx78676zmIE2uSmjIz4Iz9GLxk2+tuxl38vdyiIcANci 5xk+dUkHQraEVw0wtcmwCJgnxnEC80+0/TOZkLKn8sHtjyNxU7lSpwCTWqbI54qkHO g6eGTUXIflR0lOJHzg4gqFHlNK0w9J0/wmNOC+/Cs/I9ekqI3QRPmDrHRmDoM1nPc+ u0rKja3d2T4uA== Date: Mon, 29 Jul 2024 17:31:20 -0700 Subject: [PATCH 029/115] xfs: pin inodes that would otherwise overflow link count From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842852.1338752.10880318687395849229.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 5f204051d998ec3d7306db0d749bddcbf4c97693 The VFS inc_nlink function does not explicitly check for integer overflows in the i_nlink field. Instead, it checks the link count against s_max_links in the vfs_{link,create,rename} functions. XFS sets the maximum link count to 2.1 billion, so integer overflows should not be a problem. However. It's possible that online repair could find that a file has more than four billion links, particularly if the link count got corrupted while creating hardlinks to the file. The di_nlinkv2 field is not large enough to store a value larger than 2^32, so we ought to define a magic pin value of ~0U which means that the inode never gets deleted. This will prevent a UAF error if the repair finds this situation and users begin deleting links to the file. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_format.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index 10153ce11..f1818c54a 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -899,6 +899,12 @@ static inline uint xfs_dinode_size(int version) */ #define XFS_MAXLINK ((1U << 31) - 1U) +/* + * Any file that hits the maximum ondisk link count should be pinned to avoid + * a use-after-free situation. + */ +#define XFS_NLINK_PINNED (~0U) + /* * Values for di_format * From patchwork Tue Jul 30 00:31:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745946 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 ACD56944E for ; Tue, 30 Jul 2024 00:31:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299496; cv=none; b=FrXP4WBD3xeA595A3lctiknbd+SL6is1b7sORiKx4dgCeokhkb1n2DCugFRJDLKAIZIM5EYFn4r4Ng6XIvOGEM0+JOvY2Ua/cTsYLxhjTHHb7NFz3dFVzj5sCEXBsoW15RbNzCQ5amDgZJsx8uBn8ha7FkjyRW0QGqb3WUCdFhQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299496; c=relaxed/simple; bh=espKtufMo0z0S2t1AfNfRPOtbbkrB7Zxyiy2hbnq3nk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BRrfB07ahFxiaembT+4ual+MEx7b45fiGAQDDWxfqtpatZ4N5UZ8j3msSBeC3Wmi5MGqYfflDINFpwIw9aFZfS6op4PVgHWDAK0k9py4AioITy7Fw/FWd3KAR+VFPQHyHOzd87M91FOIKZObNeDLBEhMW8LiYDa3oxbLMqZ6WCs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b85ZYdV5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b85ZYdV5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 443FDC32786; Tue, 30 Jul 2024 00:31:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299496; bh=espKtufMo0z0S2t1AfNfRPOtbbkrB7Zxyiy2hbnq3nk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=b85ZYdV5jnxQQ/ZzhGIC2Gcu95nO1xRoQZz9WXZULFYzANwmp/BQuXFKsHy/i+vXF cd5HctEeQef64JBuKXZ9ionDY9qg7JH1wXgpxdvFhSwAszCMjhHA+oiRmR/v5W3l6R eY+37k7dda6ZwyCAHhlW7bjrGxOlXn6qOkPSd5MddkPPb0QdXYUGUN5NRyG17GAsBv J8QMArqixP2aLQqw20q7BXPoUzVPNZDegtkefUHFzad4beazd7Ra9ZSc2KQqcbtFEL 7lL6i3Q3UtxHTPFeAKpS6M3T65BHgdtIjoIJdvMtToyIIoumfLLMzX0iRprjMFuSLJ MZWc0mGoEFEqw== Date: Mon, 29 Jul 2024 17:31:35 -0700 Subject: [PATCH 030/115] xfs: Increase XFS_DEFER_OPS_NR_INODES to 5 From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Allison Henderson , Catherine Hoang , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229842866.1338752.502015054000485511.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Allison Henderson Source kernel commit: 7560c937b4b5a3c671053be86ff00156a6fdd399 Renames that generate parent pointer updates can join up to 5 inodes locked in sorted order. So we need to increase the number of defer ops inodes and relock them in the same way. Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong Reviewed-by: Catherine Hoang [djwong: have one sorting function] Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/libxfs_priv.h | 2 ++ libxfs/xfs_defer.c | 6 +++++- libxfs/xfs_defer.h | 8 +++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 9ddba767b..aa0a3adb4 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -440,6 +440,8 @@ xfs_buf_readahead( }) #define xfs_lock_two_inodes(ip0,mode0,ip1,mode1) ((void) 0) #define xfs_assert_ilocked(ip, flags) ((void) 0) +#define xfs_lock_inodes(i_tab, nr, mode) ((void) 0) +#define xfs_sort_inodes(i_tab, nr) ((void) 0) /* space allocation */ #define XFS_EXTENT_BUSY_DISCARDED 0x01 /* undergoing a discard op. */ diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 3a91bb3a5..7cf392e2f 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -1086,7 +1086,11 @@ xfs_defer_ops_continue( ASSERT(!(tp->t_flags & XFS_TRANS_DIRTY)); /* Lock the captured resources to the new transaction. */ - if (dfc->dfc_held.dr_inos == 2) + if (dfc->dfc_held.dr_inos > 2) { + xfs_sort_inodes(dfc->dfc_held.dr_ip, dfc->dfc_held.dr_inos); + xfs_lock_inodes(dfc->dfc_held.dr_ip, dfc->dfc_held.dr_inos, + XFS_ILOCK_EXCL); + } else if (dfc->dfc_held.dr_inos == 2) xfs_lock_two_inodes(dfc->dfc_held.dr_ip[0], XFS_ILOCK_EXCL, dfc->dfc_held.dr_ip[1], XFS_ILOCK_EXCL); else if (dfc->dfc_held.dr_inos == 1) diff --git a/libxfs/xfs_defer.h b/libxfs/xfs_defer.h index 81cca60d7..8b338031e 100644 --- a/libxfs/xfs_defer.h +++ b/libxfs/xfs_defer.h @@ -77,7 +77,13 @@ extern const struct xfs_defer_op_type xfs_exchmaps_defer_type; /* * Deferred operation item relogging limits. */ -#define XFS_DEFER_OPS_NR_INODES 2 /* join up to two inodes */ + +/* + * Rename w/ parent pointers can require up to 5 inodes with deferred ops to + * be joined to the transaction: src_dp, target_dp, src_ip, target_ip, and wip. + * These inodes are locked in sorted order by their inode numbers + */ +#define XFS_DEFER_OPS_NR_INODES 5 #define XFS_DEFER_OPS_NR_BUFS 2 /* join up to two buffers */ /* Resources that must be held across a transaction roll. */ From patchwork Tue Jul 30 00:31:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745947 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3D21B101DE for ; Tue, 30 Jul 2024 00:31:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299512; cv=none; b=SOrl9kiTofleS6d5xBW+UnkPsBDW3siIG9aFi1pFPRBn9eFLVFewMTp4PI2PutLdqtSqfzQWCPQFFRrG2VLaWqo8DjRW7h9lCC8hXWwBK6IBnzlnyhlMyTywe+2JA3Ykv6BNCgJdaBthQ8EIRLk79oup1qXGuJb/HTAgnWq+w6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299512; c=relaxed/simple; bh=Bmdug2vfwPORSobNz+uYgDBNJ9QYHM1FeTgERAOmTyI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=T9fyRaS+Ex8BYZqjN0mc+FmrzTUrj0J99J6L7Bqw56tIvWaBzIoY2zqa1kRonC/lnRWHcAcJseD3DhZ3lkunnBQkJU2o5TtMa1Kag+vcwSl4qBQT+Raed5CeTTORiZgP/5ugDikWfuxEvQg6tREMuv//iwjkeJo5t33zKSe0BKI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z63GfwP0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Z63GfwP0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3002C32786; Tue, 30 Jul 2024 00:31:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299511; bh=Bmdug2vfwPORSobNz+uYgDBNJ9QYHM1FeTgERAOmTyI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Z63GfwP0pc8GFP7DEtgAGaT/nwijXlNkVgjVH9gIMnYuQhr4etHLq+rH5d2rQDibJ yuLtlWkV7KOwU1ixV5kzjK0q3gmnmCKVE/ViJCWZeR/Y+Oix3tElO2wqZiKI2SesCq 3OtG0BdiSzi/JZoAAoCDgbycCzGuTNC1lKEYCI13VsWFeyzAlPoluxQIwXobwyFXnL OmeKkhsjnKvmLZfONzfM12CldBFufydwcVndvCx1WJpVFpMQ7ISh+vdcqV7oOPvZH1 dVwxr+py3OGGDuD04JSpY0WcHDNZBw1mcEXqBBW66mW6KwKl2P5mQqqxTacWKHDb5p sJZCbTuPEGMAw== Date: Mon, 29 Jul 2024 17:31:51 -0700 Subject: [PATCH 031/115] xfs: make XFS_TRANS_LOWMODE match the other XFS_TRANS_ definitions From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Dave Chinner , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229842880.1338752.10132960039094086493.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: 330c4f94b0d73e440de3f738a625e38defe1bc15 Commit bb7b1c9c5dd3 ("xfs: tag transactions that contain intent done items") switched the XFS_TRANS_ definitions to be bit based, and using comments above the definitions. As XFS_TRANS_LOWMODE was last and has a big fat comment it was missed. Switch it to the same style. Signed-off-by: Christoph Hellwig Reviewed-by: Dave Chinner Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_shared.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libxfs/xfs_shared.h b/libxfs/xfs_shared.h index dfd61fa83..f35640ad3 100644 --- a/libxfs/xfs_shared.h +++ b/libxfs/xfs_shared.h @@ -124,7 +124,6 @@ void xfs_log_get_max_trans_res(struct xfs_mount *mp, #define XFS_TRANS_RES_FDBLKS (1u << 6) /* Transaction contains an intent done log item */ #define XFS_TRANS_HAS_INTENT_DONE (1u << 7) - /* * LOWMODE is used by the allocator to activate the lowspace algorithm - when * free space is running low the extent allocator may choose to allocate an @@ -136,7 +135,7 @@ void xfs_log_get_max_trans_res(struct xfs_mount *mp, * for free space from AG 0. If the correct transaction reservations have been * made then this algorithm will eventually find all the space it needs. */ -#define XFS_TRANS_LOWMODE 0x100 /* allocate in low space mode */ +#define XFS_TRANS_LOWMODE (1u << 8) /* * Field values for xfs_trans_mod_sb. From patchwork Tue Jul 30 00:32:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745948 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0D3EC10E9 for ; Tue, 30 Jul 2024 00:32:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299528; cv=none; b=d+w+js76VMeAXsosJN4cdtQNYsw5Ip8xXq2bvhs5wYgF4Vl8MSEtsEXywn6mrYZXr3mSajCOR84GbH36pbNpTL6+90c0YU86V0Uwq3uGHDnxNytKh6jBg3mzPFfdh7FDR1ZypBIJR+jLuKjb5utI6LoUB1fiEWmButblmFtMvnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299528; c=relaxed/simple; bh=SBm8C8bObeUPQXjYiatG6+ooHe4gUdRyYKW+4XxOXM8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=URnkIdgKIb7Geeq47ac5JBy9gOBwX/JiwYu1/YptESq2edLR0vX0SirRuiEQa2qV8a1fh9CYipgsh7zD9SySlJlJI0nIzJ8MdqXpVanFxPa14bYtkXKF/opDJtd4sQCYCUlTkMlC0qNuG1FBhu2/Zf/kNBga24nusW5ab5dh2sc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Lb9a1j8e; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Lb9a1j8e" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8EF02C4AF07; Tue, 30 Jul 2024 00:32:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299527; bh=SBm8C8bObeUPQXjYiatG6+ooHe4gUdRyYKW+4XxOXM8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Lb9a1j8egA9GiCyu0o+X+Ho6beBlN+lMWCnvRlYT9llPiHSiIdWQtwfF37yzvh2iZ 4rxc1kRRg0tBHZ6WhLWns1EBmQK3avjSnEmqgzEAU9mY6XQt+G3TD8mywMc0BvbhrY CVRyRdFRIGnL2C1tRcuItaotC4VqyJTTh8WJTmZ35qv4cJxhCUNRyyV68KXOUnBAAt lvbSLeeekdLRn1UWFgN14K8QCiHpYObjFMrQKdwDaXTJdQ30pFNVYORoqVEu3W+sJ9 BImoNYuq2KPQytStxt27IyobA1SELlhv+KKDCTNyA7Lbtb/ZGjtMfiFdaGZWwY/yKa iQTpaZHxY72pA== Date: Mon, 29 Jul 2024 17:32:07 -0700 Subject: [PATCH 032/115] xfs: refactor realtime inode locking From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Dave Chinner , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229842895.1338752.7344801696812241993.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: b7e23c0e2e3b1c520a3370f058870b914071a470 Create helper functions to deal with locking realtime metadata inodes. This enables us to maintain correct locking order once we start adding the realtime rmap and refcount btree inodes. Signed-off-by: "Darrick J. Wong" Signed-off-by: Christoph Hellwig Reviewed-by: Dave Chinner Signed-off-by: Chandan Babu R --- libxfs/libxfs_priv.h | 3 +++ libxfs/xfs_bmap.c | 7 ++---- libxfs/xfs_rtbitmap.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_rtbitmap.h | 17 +++++++++++++++ 4 files changed, 79 insertions(+), 5 deletions(-) diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index aa0a3adb4..fa7cad0e0 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -170,6 +170,9 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC }; #define XFS_ERRLEVEL_LOW 1 #define XFS_ILOCK_EXCL 0 +#define XFS_ILOCK_SHARED 0 +#define XFS_ILOCK_RTBITMAP 0 +#define XFS_ILOCK_RTSUM 0 #define XFS_STATS_INC(mp, count) do { (mp) = (mp); } while (0) #define XFS_STATS_DEC(mp, count, x) do { (mp) = (mp); } while (0) #define XFS_STATS_ADD(mp, count, x) do { (mp) = (mp); } while (0) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 63feb20e2..f339e16a1 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -5412,12 +5412,9 @@ __xfs_bunmapi( if (isrt) { /* - * Synchronize by locking the bitmap inode. + * Synchronize by locking the realtime bitmap. */ - xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL|XFS_ILOCK_RTBITMAP); - xfs_trans_ijoin(tp, mp->m_rbmip, XFS_ILOCK_EXCL); - xfs_ilock(mp->m_rsumip, XFS_ILOCK_EXCL|XFS_ILOCK_RTSUM); - xfs_trans_ijoin(tp, mp->m_rsumip, XFS_ILOCK_EXCL); + xfs_rtbitmap_lock(tp, mp); } extno = 0; diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c index 543cfd2fb..58a3ba992 100644 --- a/libxfs/xfs_rtbitmap.c +++ b/libxfs/xfs_rtbitmap.c @@ -1166,3 +1166,60 @@ xfs_rtsummary_wordcount( blocks = xfs_rtsummary_blockcount(mp, rsumlevels, rbmblocks); return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG; } + +/* + * Lock both realtime free space metadata inodes for a freespace update. If a + * transaction is given, the inodes will be joined to the transaction and the + * ILOCKs will be released on transaction commit. + */ +void +xfs_rtbitmap_lock( + struct xfs_trans *tp, + struct xfs_mount *mp) +{ + xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP); + if (tp) + xfs_trans_ijoin(tp, mp->m_rbmip, XFS_ILOCK_EXCL); + + xfs_ilock(mp->m_rsumip, XFS_ILOCK_EXCL | XFS_ILOCK_RTSUM); + if (tp) + xfs_trans_ijoin(tp, mp->m_rsumip, XFS_ILOCK_EXCL); +} + +/* Unlock both realtime free space metadata inodes after a freespace update. */ +void +xfs_rtbitmap_unlock( + struct xfs_mount *mp) +{ + xfs_iunlock(mp->m_rsumip, XFS_ILOCK_EXCL | XFS_ILOCK_RTSUM); + xfs_iunlock(mp->m_rbmip, XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP); +} + +/* + * Lock the realtime free space metadata inodes for a freespace scan. Callers + * must walk metadata blocks in order of increasing file offset. + */ +void +xfs_rtbitmap_lock_shared( + struct xfs_mount *mp, + unsigned int rbmlock_flags) +{ + if (rbmlock_flags & XFS_RBMLOCK_BITMAP) + xfs_ilock(mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP); + + if (rbmlock_flags & XFS_RBMLOCK_SUMMARY) + xfs_ilock(mp->m_rsumip, XFS_ILOCK_SHARED | XFS_ILOCK_RTSUM); +} + +/* Unlock the realtime free space metadata inodes after a freespace scan. */ +void +xfs_rtbitmap_unlock_shared( + struct xfs_mount *mp, + unsigned int rbmlock_flags) +{ + if (rbmlock_flags & XFS_RBMLOCK_SUMMARY) + xfs_iunlock(mp->m_rsumip, XFS_ILOCK_SHARED | XFS_ILOCK_RTSUM); + + if (rbmlock_flags & XFS_RBMLOCK_BITMAP) + xfs_iunlock(mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP); +} diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h index 152a66750..6186585f2 100644 --- a/libxfs/xfs_rtbitmap.h +++ b/libxfs/xfs_rtbitmap.h @@ -360,6 +360,19 @@ xfs_filblks_t xfs_rtsummary_blockcount(struct xfs_mount *mp, unsigned int rsumlevels, xfs_extlen_t rbmblocks); unsigned long long xfs_rtsummary_wordcount(struct xfs_mount *mp, unsigned int rsumlevels, xfs_extlen_t rbmblocks); + +void xfs_rtbitmap_lock(struct xfs_trans *tp, struct xfs_mount *mp); +void xfs_rtbitmap_unlock(struct xfs_mount *mp); + +/* Lock the rt bitmap inode in shared mode */ +#define XFS_RBMLOCK_BITMAP (1U << 0) +/* Lock the rt summary inode in shared mode */ +#define XFS_RBMLOCK_SUMMARY (1U << 1) + +void xfs_rtbitmap_lock_shared(struct xfs_mount *mp, + unsigned int rbmlock_flags); +void xfs_rtbitmap_unlock_shared(struct xfs_mount *mp, + unsigned int rbmlock_flags); #else /* CONFIG_XFS_RT */ # define xfs_rtfree_extent(t,b,l) (-ENOSYS) # define xfs_rtfree_blocks(t,rb,rl) (-ENOSYS) @@ -378,6 +391,10 @@ xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents) # define xfs_rtbitmap_wordcount(mp, r) (0) # define xfs_rtsummary_blockcount(mp, l, b) (0) # define xfs_rtsummary_wordcount(mp, l, b) (0) +# define xfs_rtbitmap_lock(tp, mp) do { } while (0) +# define xfs_rtbitmap_unlock(mp) do { } while (0) +# define xfs_rtbitmap_lock_shared(mp, lf) do { } while (0) +# define xfs_rtbitmap_unlock_shared(mp, lf) do { } while (0) #endif /* CONFIG_XFS_RT */ #endif /* __XFS_RTBITMAP_H__ */ From patchwork Tue Jul 30 00:32:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745949 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 BFBE6440C for ; Tue, 30 Jul 2024 00:32:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299543; cv=none; b=PKCUUQZHavgMlGXrrNBErHxbFgJRGgYZ6qK2vzTYdaprpT4KRF4LayjL3iEPfktohVYD+GcM1UWfAXhgQDFF84DUrc3e/04ZdlQt2HuEWyjmR6yzGbg+rxuT5wuzEcpBwuJSgiFc9+m0rWrVfRxOlDSmodhA9071a1DopSIoP68= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299543; c=relaxed/simple; bh=hz6GOwHmDLAJZ0FkdRqc258xzmkjss5VLBz90c0+9VE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=s6DDEeYezo39RB3AuC5fD89GXl2Gbv69n8rxAKXIpMtz0QVM5W32v0b3JPmtWvWkyp3a5gOFhMIumIdAlqRO5JxLbAZVqt7tmkOrURa7TLsHdoE+6R4Llw4Ra20FLgdsfqv31RgsejAm7xb8Jg86pD4gmmoFMd3qR7sR8uiMWII= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CiQSeNnu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CiQSeNnu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B934C4AF07; Tue, 30 Jul 2024 00:32:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299543; bh=hz6GOwHmDLAJZ0FkdRqc258xzmkjss5VLBz90c0+9VE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=CiQSeNnuw6x4udjWcp3FXpHDF1xsOqFkblYLLiCO48vdAYc/k43sav7108OrL3gZH wTvfBb9QAbxQG2Ft1R/UrHexSosGC0aICFd5/vfPfaee2SRVSS5JQ/EVQJzycKre9l eeEVirzPOb88GxtEVIjXSwe/tYzFHygXCwB30F20HxerSuPg3JFW00GA7ymC+eYIFo ZtgMa26NIUxVphUcvGOCnja1jrWUrqjzJCvOVmTE2zIHBxY2uM12AbSaiI+OZPXcOA X82MbYDGZUvNgoHzS1IO7+oQGmIi/FMrN1w/FezZt7AARZ5t0jI/AUbX6HPQc+ScKl 2sCBvZtbjAMMQ== Date: Mon, 29 Jul 2024 17:32:22 -0700 Subject: [PATCH 033/115] xfs: free RT extents after updating the bmap btree From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Dave Chinner , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229842908.1338752.7701114659633869238.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: 9871d0963751293bf0587759a9b6b8f808e35c7c Currently xfs_bmap_del_extent_real frees RT extents before updating the bmap btree, while it frees regular blocks after performing the bmap btree update for convoluted historic reasons. Switch to free the RT blocks in the same place as the regular data blocks instead to simply the code and fix a very theoretical bug. A short history of this code researched by Dave Chiner below: The truncate for data device extents was originally a two-phase operation. First it removed the bmapbt record, but because this can free BMBT extents, it can use up all the free space tree reservation space. So the transaction gets rolled to commit the BMBT change and the xfs_bmap_finish() call that frees the data extent runs with a new transaction reservation that allows different free space btrees to be logged without overrun. However, on crash, this could lose the free space because there was nothing to tell recovery about the extents removed from the BMBT, hence EFIs were introduced. They tie the extent free operation to the bmapbt record removal commit for recovery of the second phase of the extent removal process. Then RT extents came along. RT extent freeing does not require a free space btree reservation because the free space metadata is static and transaction size is bound. Hence we don't need to care if the BMBT record removal modifies the per-ag free space trees and we don't need a two-phase extent remove transaction. The only thing we have to care about is not losing space on crash. Hence instead of recording the extent for freeing in the bmap list for xfs_bmap_finish() to process in a new transaction, it simply freed the rtextent directly. So the original code (from 1994) simply replaced the "free AG extent later" queueing with a direct free. This code was originally at the start of xfs_dmap_del_extent(), but the xfs_bmap_add_free() got moved to the end of the function via the "do_fx" flag (the current code logic) in 1997 (commit c4fac74eaa58 in the historic xfs-import tree) because there was a shutdown occurring because of a case where splitting the extent record failed because the BMBT split and the filesystem didn't have enough space for the split to be done. (FWIW, I'm not sure this can happen anymore.) The commit backed out the BMBT change on ENOSPC error, and in doing so I think this actually breaks RT free space tracking. However, it then returns an ENOSPC error, and we have a dirty transaction in the RT case so this will shut down the filesysetm when the transaction is cancelled. Hence the corrupted "bmbt now points at freed rt dev space" condition never make it to disk, but it's still the wrong way to handle the issue. IOWs, this proposed change fixes that "shutdown at ENOSPC on rt devices" situation that was introduced by the above commit back in 1997. Signed-off-by: Christoph Hellwig Reviewed-by: Dave Chinner Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_bmap.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index f339e16a1..dd91fb2aa 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -5103,8 +5103,7 @@ xfs_bmap_del_extent_real( { xfs_fsblock_t del_endblock=0; /* first block past del */ xfs_fileoff_t del_endoff; /* first offset past del */ - int do_fx; /* free extent at end of routine */ - int error; /* error return value */ + int error = 0; /* error return value */ struct xfs_bmbt_irec got; /* current extent entry */ xfs_fileoff_t got_endoff; /* first offset past got */ int i; /* temp state */ @@ -5147,20 +5146,10 @@ xfs_bmap_del_extent_real( return -ENOSPC; *logflagsp = XFS_ILOG_CORE; - if (xfs_ifork_is_realtime(ip, whichfork)) { - if (!(bflags & XFS_BMAPI_REMAP)) { - error = xfs_rtfree_blocks(tp, del->br_startblock, - del->br_blockcount); - if (error) - return error; - } - - do_fx = 0; + if (xfs_ifork_is_realtime(ip, whichfork)) qfield = XFS_TRANS_DQ_RTBCOUNT; - } else { - do_fx = 1; + else qfield = XFS_TRANS_DQ_BCOUNT; - } nblks = del->br_blockcount; del_endblock = del->br_startblock + del->br_blockcount; @@ -5308,18 +5297,21 @@ xfs_bmap_del_extent_real( /* * If we need to, add to list of extents to delete. */ - if (do_fx && !(bflags & XFS_BMAPI_REMAP)) { + if (!(bflags & XFS_BMAPI_REMAP)) { if (xfs_is_reflink_inode(ip) && whichfork == XFS_DATA_FORK) { xfs_refcount_decrease_extent(tp, del); + } else if (xfs_ifork_is_realtime(ip, whichfork)) { + error = xfs_rtfree_blocks(tp, del->br_startblock, + del->br_blockcount); } else { error = xfs_free_extent_later(tp, del->br_startblock, del->br_blockcount, NULL, XFS_AG_RESV_NONE, ((bflags & XFS_BMAPI_NODISCARD) || del->br_state == XFS_EXT_UNWRITTEN)); - if (error) - return error; } + if (error) + return error; } /* From patchwork Tue Jul 30 00:32:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745950 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 618324A11 for ; Tue, 30 Jul 2024 00:32:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299559; cv=none; b=RwFeCifaNDRtO9R0S1B3bSUPz8Q+mNkRHsIjnM850BJVCBBY7+/fK7R/KM+abTn9pECOu6FdGFNf0uZ+hJ0Y4zJf5wWxfTsbnpOgthUJgozgAlcOg1Fx1+v7R6YJ0alan/qccgvILx5kWdXvK9Z7v6+kvemQhwuIjcOM67BVkjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299559; c=relaxed/simple; bh=RMQW7FFEM7BTBipyRUnDR6sMuVu68TokOZjWMNRqAME=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UqjprOk5qmxPlWOE8Ci0FoWYmGGoLMlEImHXbykGzJaN8KtqvG1cKmAy/jymSyAKmbZnXR4i5UAb8vFhXJKaRRK9VxsuByaMQUWN5VPDjWzlEYuzRrhpoxJSDkSJcYtuS2Pb074R1wtEkQWIYuz8lBR7XmTAsDkUKlPYWLUrs7E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UCcfyhuZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UCcfyhuZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2EFFC32786; Tue, 30 Jul 2024 00:32:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299558; bh=RMQW7FFEM7BTBipyRUnDR6sMuVu68TokOZjWMNRqAME=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=UCcfyhuZwgcOUXDjmw8wcHn+PeIgiBeL+XTsgmhsugf9hyMJKVgk/s7Rdr1qvQvcE 1xDa7Mx3HHQR0ZDPvsqulDc/2z//tbhP3+J2akO/goytxoEtj1zXLQmntU+pDBqk+R aER2Vf6KtOGmhNxQZ2tPLkDed/O71yOXVcVB5fhAyzMbIlL4Pxt8WO6+YMZVJS7qFQ X8rQCCTSvk3AZsprG3C4zL12i45iDtPPAZWNFjuK9I9/3Rd0UKP6q+08taqLnTJccq PDTfty8tzOJNaDqcnMeCQc03Tx76//XnKLc/RyWSUL8flIwdeOACpWJCUHwCOqVtQI CQB0NhWTRd9iA== Date: Mon, 29 Jul 2024 17:32:38 -0700 Subject: [PATCH 034/115] xfs: move RT inode locking out of __xfs_bunmapi From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Dave Chinner , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229842920.1338752.15891282023588871061.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: de37dbd0ccc6933fbf4bd7b3ccbc5ac640e80b28 __xfs_bunmapi is a bit of an odd place to lock the rtbitmap and rtsummary inodes given that it is very high level code. While this only looks ugly right now, it will become a problem when supporting delayed allocations for RT inodes as __xfs_bunmapi might end up deleting only delalloc extents and thus never unlock the rt inodes. Move the locking into xfs_bmap_del_extent_real just before the call to xfs_rtfree_blocks instead and use a new flag in the transaction to ensure that the locking happens only once. Signed-off-by: Christoph Hellwig Reviewed-by: Dave Chinner Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_bmap.c | 15 ++++++++------- libxfs/xfs_shared.h | 3 +++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index dd91fb2aa..c16db82a2 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -5301,6 +5301,14 @@ xfs_bmap_del_extent_real( if (xfs_is_reflink_inode(ip) && whichfork == XFS_DATA_FORK) { xfs_refcount_decrease_extent(tp, del); } else if (xfs_ifork_is_realtime(ip, whichfork)) { + /* + * Ensure the bitmap and summary inodes are locked + * and joined to the transaction before modifying them. + */ + if (!(tp->t_flags & XFS_TRANS_RTBITMAP_LOCKED)) { + tp->t_flags |= XFS_TRANS_RTBITMAP_LOCKED; + xfs_rtbitmap_lock(tp, mp); + } error = xfs_rtfree_blocks(tp, del->br_startblock, del->br_blockcount); } else { @@ -5402,13 +5410,6 @@ __xfs_bunmapi( } else cur = NULL; - if (isrt) { - /* - * Synchronize by locking the realtime bitmap. - */ - xfs_rtbitmap_lock(tp, mp); - } - extno = 0; while (end != (xfs_fileoff_t)-1 && end >= start && (nexts == 0 || extno < nexts)) { diff --git a/libxfs/xfs_shared.h b/libxfs/xfs_shared.h index f35640ad3..34f104ed3 100644 --- a/libxfs/xfs_shared.h +++ b/libxfs/xfs_shared.h @@ -137,6 +137,9 @@ void xfs_log_get_max_trans_res(struct xfs_mount *mp, */ #define XFS_TRANS_LOWMODE (1u << 8) +/* Transaction has locked the rtbitmap and rtsum inodes */ +#define XFS_TRANS_RTBITMAP_LOCKED (1u << 9) + /* * Field values for xfs_trans_mod_sb. */ From patchwork Tue Jul 30 00:32:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745951 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A98554A11 for ; Tue, 30 Jul 2024 00:32:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299574; cv=none; b=piS13d82i87MaMMA8vkHj/Fwv1ENAcZniZf5ezCOnYVYUSCPPj/Hiwi6wXy+tSMHuGxf1pkwlCpPoa3okeCGVwbDdtsDNev+dKnYN210cLZKSmvQX+JkeJ4G+JEhKmfU1SEfIU+OmlVo7H3U4CYFeTpXTxqmaFzvSBwhBJCRm80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299574; c=relaxed/simple; bh=uV7utVH6iHCc/XGcFQF/lrIbIwh06hNRth5HCMVofnI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=j10k0sLShVOp2j32ERLxT6ku9DzZGFR7Rh0ky8cNvZgPAj7kSQQHWqSlrfeuc3K9tdkl99UhAUgsH1TTmubEUCV69YKzmBKSalD6jbvLjnX21lpYfxM0FciarqSjEYKBOgNmGZ/99Dst3Z4iBAdY0aZvV4IiM5Zo0h8LLIEpQZQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bSeB9cPh; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bSeB9cPh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80C74C32786; Tue, 30 Jul 2024 00:32:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299574; bh=uV7utVH6iHCc/XGcFQF/lrIbIwh06hNRth5HCMVofnI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=bSeB9cPhwLBOCYn7SeKSCj5JNDhtZ6HNdB/6VLi7vJ3bGXWro0nOqvw7kMhZ66jqM CWlJuuauomuFx/YrE5FANPDKHMZHp1fjoHdYWBy39qSLzKjeHOc21JaTmr0br9TEvH XvakUTVfn8WEFiYT9pAIZAJTnRy2cmpnmxKJqonkyeJNx4m5Oc2nyKXPUmkH3RtGck +n1+LUIdK4XKNTsKE/02PHSZzaMQ6CzKT5VyrbOL/UuthLMPAgTZnAoEXLx49JI1qr fLErNMwhfVk7LU4uXCyVz+mdHwmOrCoAqiMVg1U84WkgYtvNWBt9/JdC0tgXS/iij0 v3Q9CGaRv9aog== Date: Mon, 29 Jul 2024 17:32:54 -0700 Subject: [PATCH 035/115] xfs: split xfs_mod_freecounter From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Dave Chinner , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229842934.1338752.17070490377969133733.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: f30f656e25eb72c4309e76b16fa45062e183a2ee xfs_mod_freecounter has two entirely separate code paths for adding or subtracting from the free counters. Only the subtract case looks at the rsvd flag and can return an error. Split xfs_mod_freecounter into separate helpers for subtracting or adding the freecounter, and remove all the impossible to reach error handling for the addition case. Signed-off-by: Christoph Hellwig Reviewed-by: Dave Chinner Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/libxfs_priv.h | 10 +++++++--- libxfs/xfs_ag.c | 4 +--- libxfs/xfs_ag_resv.c | 24 ++++++------------------ libxfs/xfs_ag_resv.h | 2 +- libxfs/xfs_alloc.c | 4 ++-- libxfs/xfs_bmap.c | 23 ++++++++++++----------- 6 files changed, 29 insertions(+), 38 deletions(-) diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index fa7cad0e0..40c418f54 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -541,10 +541,14 @@ struct xfs_buf *xfs_trans_buf_item_match(struct xfs_trans *, struct xfs_buftarg *, struct xfs_buf_map *, int); /* local source files */ -#define xfs_mod_fdblocks(mp, delta, rsvd) \ - libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FDBLOCKS, delta, rsvd) -#define xfs_mod_frextents(mp, delta) \ +#define xfs_add_fdblocks(mp, delta) \ + libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FDBLOCKS, delta, false) +#define xfs_dec_fdblocks(mp, delta, rsvd) \ + libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FDBLOCKS, -(int64_t)(delta), rsvd) +#define xfs_add_frextents(mp, delta) \ libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FREXTENTS, delta, 0) +#define xfs_dec_frextents(mp, delta) \ + libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FREXTENTS, -(int64_t)(delta), 0) int libxfs_mod_incore_sb(struct xfs_mount *, int, int64_t, int); /* percpu counters in mp are #defined to the superblock sb_ counters */ #define xfs_reinit_percpu_counters(mp) diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index ad721c192..47522d0fc 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -961,9 +961,7 @@ xfs_ag_shrink_space( * Disable perag reservations so it doesn't cause the allocation request * to fail. We'll reestablish reservation before we return. */ - error = xfs_ag_resv_free(pag); - if (error) - return error; + xfs_ag_resv_free(pag); /* internal log shouldn't also show up in the free space btrees */ error = xfs_alloc_vextent_exact_bno(&args, diff --git a/libxfs/xfs_ag_resv.c b/libxfs/xfs_ag_resv.c index 3a80b1613..7e5cbe0cb 100644 --- a/libxfs/xfs_ag_resv.c +++ b/libxfs/xfs_ag_resv.c @@ -125,14 +125,13 @@ xfs_ag_resv_needed( } /* Clean out a reservation */ -static int +static void __xfs_ag_resv_free( struct xfs_perag *pag, enum xfs_ag_resv_type type) { struct xfs_ag_resv *resv; xfs_extlen_t oldresv; - int error; trace_xfs_ag_resv_free(pag, type, 0); @@ -148,30 +147,19 @@ __xfs_ag_resv_free( oldresv = resv->ar_orig_reserved; else oldresv = resv->ar_reserved; - error = xfs_mod_fdblocks(pag->pag_mount, oldresv, true); + xfs_add_fdblocks(pag->pag_mount, oldresv); resv->ar_reserved = 0; resv->ar_asked = 0; resv->ar_orig_reserved = 0; - - if (error) - trace_xfs_ag_resv_free_error(pag->pag_mount, pag->pag_agno, - error, _RET_IP_); - return error; } /* Free a per-AG reservation. */ -int +void xfs_ag_resv_free( struct xfs_perag *pag) { - int error; - int err2; - - error = __xfs_ag_resv_free(pag, XFS_AG_RESV_RMAPBT); - err2 = __xfs_ag_resv_free(pag, XFS_AG_RESV_METADATA); - if (err2 && !error) - error = err2; - return error; + __xfs_ag_resv_free(pag, XFS_AG_RESV_RMAPBT); + __xfs_ag_resv_free(pag, XFS_AG_RESV_METADATA); } static int @@ -215,7 +203,7 @@ __xfs_ag_resv_init( if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_AG_RESV_FAIL)) error = -ENOSPC; else - error = xfs_mod_fdblocks(mp, -(int64_t)hidden_space, true); + error = xfs_dec_fdblocks(mp, hidden_space, true); if (error) { trace_xfs_ag_resv_init_error(pag->pag_mount, pag->pag_agno, error, _RET_IP_); diff --git a/libxfs/xfs_ag_resv.h b/libxfs/xfs_ag_resv.h index b74b21000..ff20ed93d 100644 --- a/libxfs/xfs_ag_resv.h +++ b/libxfs/xfs_ag_resv.h @@ -6,7 +6,7 @@ #ifndef __XFS_AG_RESV_H__ #define __XFS_AG_RESV_H__ -int xfs_ag_resv_free(struct xfs_perag *pag); +void xfs_ag_resv_free(struct xfs_perag *pag); int xfs_ag_resv_init(struct xfs_perag *pag, struct xfs_trans *tp); bool xfs_ag_resv_critical(struct xfs_perag *pag, enum xfs_ag_resv_type type); diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index 0eefb16cc..b86f788f4 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -75,7 +75,7 @@ xfs_prealloc_blocks( } /* - * The number of blocks per AG that we withhold from xfs_mod_fdblocks to + * The number of blocks per AG that we withhold from xfs_dec_fdblocks to * guarantee that we can refill the AGFL prior to allocating space in a nearly * full AG. Although the space described by the free space btrees, the * blocks used by the freesp btrees themselves, and the blocks owned by the @@ -85,7 +85,7 @@ xfs_prealloc_blocks( * until the fs goes down, we subtract this many AG blocks from the incore * fdblocks to ensure user allocation does not overcommit the space the * filesystem needs for the AGFLs. The rmap btree uses a per-AG reservation to - * withhold space from xfs_mod_fdblocks, so we do not account for that here. + * withhold space from xfs_dec_fdblocks, so we do not account for that here. */ #define XFS_ALLOCBT_AGFL_RESERVE 4 diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index c16db82a2..3f70f24ba 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -1979,10 +1979,11 @@ xfs_bmap_add_extent_delay_real( } /* adjust for changes in reserved delayed indirect blocks */ - if (da_new != da_old) { - ASSERT(state == 0 || da_new < da_old); - error = xfs_mod_fdblocks(mp, (int64_t)(da_old - da_new), - false); + if (da_new < da_old) { + xfs_add_fdblocks(mp, da_old - da_new); + } else if (da_new > da_old) { + ASSERT(state == 0); + error = xfs_dec_fdblocks(mp, da_new - da_old, false); } xfs_bmap_check_leaf_extents(bma->cur, bma->ip, whichfork); @@ -2684,8 +2685,8 @@ xfs_bmap_add_extent_hole_delay( } if (oldlen != newlen) { ASSERT(oldlen > newlen); - xfs_mod_fdblocks(ip->i_mount, (int64_t)(oldlen - newlen), - false); + xfs_add_fdblocks(ip->i_mount, oldlen - newlen); + /* * Nothing to do for disk quota accounting here. */ @@ -4104,11 +4105,11 @@ xfs_bmapi_reserve_delalloc( indlen = (xfs_extlen_t)xfs_bmap_worst_indlen(ip, alen); ASSERT(indlen > 0); - error = xfs_mod_fdblocks(mp, -((int64_t)alen), false); + error = xfs_dec_fdblocks(mp, alen, false); if (error) goto out_unreserve_quota; - error = xfs_mod_fdblocks(mp, -((int64_t)indlen), false); + error = xfs_dec_fdblocks(mp, indlen, false); if (error) goto out_unreserve_blocks; @@ -4136,7 +4137,7 @@ xfs_bmapi_reserve_delalloc( return 0; out_unreserve_blocks: - xfs_mod_fdblocks(mp, alen, false); + xfs_add_fdblocks(mp, alen); out_unreserve_quota: if (XFS_IS_QUOTA_ON(mp)) xfs_quota_unreserve_blkres(ip, alen); @@ -4922,7 +4923,7 @@ xfs_bmap_del_extent_delay( ASSERT(got_endoff >= del_endoff); if (isrt) - xfs_mod_frextents(mp, xfs_rtb_to_rtx(mp, del->br_blockcount)); + xfs_add_frextents(mp, xfs_rtb_to_rtx(mp, del->br_blockcount)); /* * Update the inode delalloc counter now and wait to update the @@ -5009,7 +5010,7 @@ xfs_bmap_del_extent_delay( if (!isrt) da_diff += del->br_blockcount; if (da_diff) { - xfs_mod_fdblocks(mp, da_diff, false); + xfs_add_fdblocks(mp, da_diff); xfs_mod_delalloc(mp, -da_diff); } return error; From patchwork Tue Jul 30 00:33:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745952 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 471724A11 for ; Tue, 30 Jul 2024 00:33:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299590; cv=none; b=aGrFo8WyUcGp8YMWR5iFzw04ZstzWkOMZgZfPf7NDUjnJwlRUh0wyPnRlc1dCok0/N/iOeV6Retykp7Z1cAdvullVrex/ZLTfAD7ZaYVUaIOqc90QETPllv4h3zj5xeVmKdexkt7DPyISqtVvwkUkZN3IL7vI2kX/XbOX9IQQlc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299590; c=relaxed/simple; bh=cZo40OM180rGpzqsYM7vawcLN1dwEbSERuuxyqUBVsQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uEOspGTL/mmC61gehwCR8crC+aieAiNj+VWWELpzgf446PFf+L8JXaAJND+oGnqa7V/mkj7OjABLdl/nZWJByWzNbg/IS1H0HhmA5UzAGP7h/OmooDBv00m1F1mYWhnhBsS8ilYLQLIPVPYgk/HXFhdxH255wu55WIyMzeAqwCE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KptFYPdp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KptFYPdp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 241B4C32786; Tue, 30 Jul 2024 00:33:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299590; bh=cZo40OM180rGpzqsYM7vawcLN1dwEbSERuuxyqUBVsQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=KptFYPdpxgtumcVvedEUH6WUdslYgAzRjRiQFRwwz4WVJbyaWaJfrEH6fbr7lgKKh H+I4BYYO43yl4ysOYvtPFqIjJ+ev09sAdd9Pz+cY8ThvO1N6nbOzYwzij0YvLEsOb6 VE00mvQ68iQUNAcA1jFqQn0Hmtm151FieEzdCXfwWH/bfY24KaFYYEZTbdV0YvwsEw ueEljTdjHLFNFwMpGmUzvSrKVPjdoqYw9tu8zxgR9LW8irk+IZDeFxB9U2nKYfSHao /LdEV5uW0Pq0XDYokms2Hb1UYuYymorR4veRmchcDZa+Igw6Z/ymph+q1Qwr1Q1DDF m7tTMs9VQyO5A== Date: Mon, 29 Jul 2024 17:33:09 -0700 Subject: [PATCH 036/115] xfs: reinstate RT support in xfs_bmapi_reserve_delalloc From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Dave Chinner , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229842948.1338752.18246107009752852124.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: dc1b17a25c321c8f1b4f90f9d6f8afb1d132b69c Allocate data blocks for RT inodes using xfs_dec_frextents. While at it optimize the data device case by doing only a single xfs_dec_fdblocks call for the extent itself and the indirect blocks. Signed-off-by: Christoph Hellwig Reviewed-by: Dave Chinner Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_bmap.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 3f70f24ba..1319f1c90 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -4063,6 +4063,7 @@ xfs_bmapi_reserve_delalloc( struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); xfs_extlen_t alen; xfs_extlen_t indlen; + uint64_t fdblocks; int error; xfs_fileoff_t aoff = off; @@ -4105,14 +4106,18 @@ xfs_bmapi_reserve_delalloc( indlen = (xfs_extlen_t)xfs_bmap_worst_indlen(ip, alen); ASSERT(indlen > 0); - error = xfs_dec_fdblocks(mp, alen, false); - if (error) - goto out_unreserve_quota; + fdblocks = indlen; + if (XFS_IS_REALTIME_INODE(ip)) { + error = xfs_dec_frextents(mp, xfs_rtb_to_rtx(mp, alen)); + if (error) + goto out_unreserve_quota; + } else { + fdblocks += alen; + } - error = xfs_dec_fdblocks(mp, indlen, false); + error = xfs_dec_fdblocks(mp, fdblocks, false); if (error) - goto out_unreserve_blocks; - + goto out_unreserve_frextents; ip->i_delayed_blks += alen; xfs_mod_delalloc(ip->i_mount, alen + indlen); @@ -4136,8 +4141,9 @@ xfs_bmapi_reserve_delalloc( return 0; -out_unreserve_blocks: - xfs_add_fdblocks(mp, alen); +out_unreserve_frextents: + if (XFS_IS_REALTIME_INODE(ip)) + xfs_add_frextents(mp, xfs_rtb_to_rtx(mp, alen)); out_unreserve_quota: if (XFS_IS_QUOTA_ON(mp)) xfs_quota_unreserve_blkres(ip, alen); From patchwork Tue Jul 30 00:33:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745953 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 EBC2C4A11 for ; Tue, 30 Jul 2024 00:33:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299606; cv=none; b=cuG2xwclN9PnkocR1qFgbrZqjnfHrmVnLvqG1fDmxM13Arb2ocmmjimQIyW3K0rDDEqhW2VaanOp6eD2iA6teCQ71g/ca26rLkbC2nVSDeLfRyqSxGa2lC2jWois5cY+jUs51DGH6vIw45cfo9u+wif+s6KFw7enjQJYBGGgL1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299606; c=relaxed/simple; bh=jJewfFYSRD3Gmd9yR0B6v+3LkTqvUldBSiCinzqOUQc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=g4vDePQLE3nsnLpAoiTTdcRPX35CGHcDHdB7loWZ0k7kTlds0okxnO7PIPx3wtj+TFBBmctR8f4H0uFV7R8gE2ksc7Am30c5fqoNy53QZnhs2bXGQODPPJd3eBXOU3jaz2atoqADTTy6ibZM6c7KBw2yPXME/vuQRtFOGqdc9kU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qaYisE48; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qaYisE48" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C42BFC32786; Tue, 30 Jul 2024 00:33:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299605; bh=jJewfFYSRD3Gmd9yR0B6v+3LkTqvUldBSiCinzqOUQc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=qaYisE48WIpFFx7mw/ad4Ii8DCWQ/ROJjX0FcYnuClE+dJXMf7Y4vIxTRTF8XqoWO qdgtFEb9jlfUvZP0Ii8NhufIjE1s+RoZuQV2pdN0Bueg+a42QOZ6Y3TMtcHqDMfd7E 5Mg59WMLQiyn9lDE/vDhfvrLb0wKvHQb2A+7dx5tBxe09Gz7lpzhO7R82m/6jaYdVq 9BLpNSc57IdwkbmtVsoKrTLd/NyPPfy0FdtSwycOusCcT1tip+Toxg7ghTz/LQFN4U b2G5d0etWo3kctlwCHjTafWMFVtIGIwmTYm2k4ltBO/sYWXpwcmVLK8KLwtTsRWGev mw/2261i/vumA== Date: Mon, 29 Jul 2024 17:33:25 -0700 Subject: [PATCH 037/115] xfs: cleanup fdblock/frextent accounting in xfs_bmap_del_extent_delay From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Dave Chinner , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229842962.1338752.10553908934303557340.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: 7e77d57a1fea5f6bfe166210385ba9f227a606d1 The code to account fdblocks and frextents in xfs_bmap_del_extent_delay is a bit weird in that it accounts frextents before the iext tree manipulations and fdblocks after it. Given that the iext tree manipulations cannot fail currently that's not really a problem, but still odd. Move the frextent manipulation to the end, and use a fdblocks variable to account of the unconditional indirect blocks and the data blocks only freed for !RT. This prepares for following updates in the area and already makes the code more readable. Also remove the !isrt assert given that this code clearly handles rt extents correctly, and we'll soon reinstate delalloc support for RT inodes. Signed-off-by: Christoph Hellwig Reviewed-by: Dave Chinner Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_bmap.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 1319f1c90..5de8c72a8 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -4913,6 +4913,7 @@ xfs_bmap_del_extent_delay( xfs_fileoff_t del_endoff, got_endoff; xfs_filblks_t got_indlen, new_indlen, stolen; uint32_t state = xfs_bmap_fork_to_state(whichfork); + uint64_t fdblocks; int error = 0; bool isrt; @@ -4928,15 +4929,11 @@ xfs_bmap_del_extent_delay( ASSERT(got->br_startoff <= del->br_startoff); ASSERT(got_endoff >= del_endoff); - if (isrt) - xfs_add_frextents(mp, xfs_rtb_to_rtx(mp, del->br_blockcount)); - /* * Update the inode delalloc counter now and wait to update the * sb counters as we might have to borrow some blocks for the * indirect block accounting. */ - ASSERT(!isrt); error = xfs_quota_unreserve_blkres(ip, del->br_blockcount); if (error) return error; @@ -5013,12 +5010,15 @@ xfs_bmap_del_extent_delay( ASSERT(da_old >= da_new); da_diff = da_old - da_new; - if (!isrt) - da_diff += del->br_blockcount; - if (da_diff) { - xfs_add_fdblocks(mp, da_diff); - xfs_mod_delalloc(mp, -da_diff); - } + fdblocks = da_diff; + + if (isrt) + xfs_add_frextents(mp, xfs_rtb_to_rtx(mp, del->br_blockcount)); + else + fdblocks += del->br_blockcount; + + xfs_add_fdblocks(mp, fdblocks); + xfs_mod_delalloc(mp, -(int64_t)fdblocks); return error; } From patchwork Tue Jul 30 00:33:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745954 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CF8F7621 for ; Tue, 30 Jul 2024 00:33:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299621; cv=none; b=Fap44eUQVXaeD0e8cKUKkNmSSUNvjJE5QI2FG/jSQ6W+pYRg0lJaIR1i6lXNfy0eaMsWhFnD5mFqdZ5bvty9Svelrt12QV1wiiHwu6Y4Q38SpvfGyWQJTKlLRwXSXaDNwbzdUbMxpDFul5Ajy5AbrJUxS+Gw3Fi6lJrg3KLEazQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299621; c=relaxed/simple; bh=wFnGyPuJFgpJeVQzMJIyfH+uZ2Ozqim+9eqWTloG0No=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QBWCxCkdVJq6oClJxKd/Lww4msACCHLHqkHZlbtQSrIYn9XPKY/iXmXGVy8jW7qwzHUCjTUVMyD4bG5+cHdt4k63IxXJqb+rs63LKOEM+HFRg7xs1eWosV6qKdHmUxmm+ihYmoRzx4kSgOsoizMGpUBpCVc1ORGbYR1IBBGnuJo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UdlRzXu8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UdlRzXu8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78C63C32786; Tue, 30 Jul 2024 00:33:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299621; bh=wFnGyPuJFgpJeVQzMJIyfH+uZ2Ozqim+9eqWTloG0No=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=UdlRzXu8q9X5/cdLR8mJxUvc0Zcja+z/JlgnnFh5NGTyl7DTANgoMjq5ssAakK2mW lT4Rw3N9hOYyMGGYAniIdTEZfrNm1q+mXKvoCAK397mH4gOfTkBbLOyucunPsD3ff9 PTIpYe0iLFNmP6T9S/r3bei2FzbuZuFdMbsIOTg3u+pAL4p34HM1FHjWtWw1aR8+5w B60HfkSngAzdwGSWC0SijEAnAw1h+xU4PefHbta/m3XBCeGsztPcn+YFlnmdNpsfpW SvBTuKl6YM/Z/4+8AWXaNE0OWTCA0HjXyNpbSoKNT5f2xiAUQ3TZJ11WZo8GgW/K1k HsK4o5/o1Ty9g== Date: Mon, 29 Jul 2024 17:33:40 -0700 Subject: [PATCH 038/115] xfs: support RT inodes in xfs_mod_delalloc From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Dave Chinner , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229842977.1338752.18120747394730937321.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: 7099bd0f243fa7511de6e95b0b8807ba7d3e5204 To prepare for re-enabling delalloc on RT devices, track the data blocks (which use the RT device when the inode sits on it) and the indirect blocks (which don't) separately to xfs_mod_delalloc, and add a new percpu counter to also track the RT delalloc blocks. Signed-off-by: Christoph Hellwig Reviewed-by: Dave Chinner Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/libxfs_priv.h | 2 +- libxfs/xfs_bmap.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 40c418f54..cfe96b05a 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -141,7 +141,7 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC }; #define xfs_force_shutdown(d,n) ((void) 0) -#define xfs_mod_delalloc(a,b) ((void) 0) +#define xfs_mod_delalloc(a,b,c) ((void) 0) /* stop unused var warnings by assigning mp to itself */ diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 5de8c72a8..79cde87d0 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -1971,7 +1971,7 @@ xfs_bmap_add_extent_delay_real( } if (da_new != da_old) - xfs_mod_delalloc(mp, (int64_t)da_new - da_old); + xfs_mod_delalloc(bma->ip, 0, (int64_t)da_new - da_old); if (bma->cur) { da_new += bma->cur->bc_bmap.allocated; @@ -2690,7 +2690,7 @@ xfs_bmap_add_extent_hole_delay( /* * Nothing to do for disk quota accounting here. */ - xfs_mod_delalloc(ip->i_mount, (int64_t)newlen - oldlen); + xfs_mod_delalloc(ip, 0, (int64_t)newlen - oldlen); } } @@ -3367,7 +3367,7 @@ xfs_bmap_alloc_account( * yet. */ if (ap->wasdel) { - xfs_mod_delalloc(ap->ip->i_mount, -(int64_t)ap->length); + xfs_mod_delalloc(ap->ip, -(int64_t)ap->length, 0); return; } @@ -3391,7 +3391,7 @@ xfs_bmap_alloc_account( xfs_trans_log_inode(ap->tp, ap->ip, XFS_ILOG_CORE); if (ap->wasdel) { ap->ip->i_delayed_blks -= ap->length; - xfs_mod_delalloc(ap->ip->i_mount, -(int64_t)ap->length); + xfs_mod_delalloc(ap->ip, -(int64_t)ap->length, 0); fld = isrt ? XFS_TRANS_DQ_DELRTBCOUNT : XFS_TRANS_DQ_DELBCOUNT; } else { fld = isrt ? XFS_TRANS_DQ_RTBCOUNT : XFS_TRANS_DQ_BCOUNT; @@ -4120,7 +4120,7 @@ xfs_bmapi_reserve_delalloc( goto out_unreserve_frextents; ip->i_delayed_blks += alen; - xfs_mod_delalloc(ip->i_mount, alen + indlen); + xfs_mod_delalloc(ip, alen, indlen); got->br_startoff = aoff; got->br_startblock = nullstartblock(indlen); @@ -5018,7 +5018,7 @@ xfs_bmap_del_extent_delay( fdblocks += del->br_blockcount; xfs_add_fdblocks(mp, fdblocks); - xfs_mod_delalloc(mp, -(int64_t)fdblocks); + xfs_mod_delalloc(ip, -(int64_t)del->br_blockcount, -da_diff); return error; } From patchwork Tue Jul 30 00:33:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745955 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 54DF410E9 for ; Tue, 30 Jul 2024 00:33:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299637; cv=none; b=R4ga+hHIb6MWT8hPiFDVNEQLmSsbS1Hl/qfaukUoy5hcrB3H2W1ZOpQBGS+HmJLVYckaQHAKY+0ztl958d0hzIatcOcQCBc0LpVFkS4S5BqnUWsfWctgxNYjQTDcSDX7RgRM1HmLJdi1mXnXG6Vh4l+uD42GK0Xe7Z0iN2gOLyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299637; c=relaxed/simple; bh=WrHvGRxKeLIpn8O8OsOfhqco3mbu06Xa6B6/Xz1+Pjs=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MIs0cR2mlmOO4hVR6BNOfSA/JITDXeYtq/IKxxJz2tB6fly4gQiM34kKdFgYqorMYbswhRrjFCH9f9vuw7tbMfIKXRnOhEm9+7+jDrixq08kKK3ucNgQRrEn4pGGB8mnXgc3q2mVsd3UKWKsZtUmbLHq1Jn+/9Xudc3mAkWLa04= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Exz0teri; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Exz0teri" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F6AAC32786; Tue, 30 Jul 2024 00:33:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299637; bh=WrHvGRxKeLIpn8O8OsOfhqco3mbu06Xa6B6/Xz1+Pjs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Exz0teriCvNReQ8HmkeG416HWILBGENpCDW4hFY9VpA3MhvTpEfdfc9lml1HXx/Sj 7kGZ8kU9tGycopkAMmsTtex3sh+LLvjkUhYbw5ewps7BrNqLB5y0pRrlzc6jpjMvLw L/j2zVHHpT9beOugTcOEq6SlgOo18ea9CcWh2XF8wq7MjUNH/yg6zilGX3uZm5Uwth I6l92kWwRu+2rSVNTNzMCcTD1ffZfAssvPcVb3R4ZjLA1Ta18uRpSh5CphodavfIb7 RHpG7WpQyt1HzB0Y3tPur4dwDm7qGUYOLcFhBKrRRQLqVU/iw5Ujtvu9plbYwvYtbK 274bLvx5yITcg== Date: Mon, 29 Jul 2024 17:33:56 -0700 Subject: [PATCH 039/115] xfs: rework splitting of indirect block reservations From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Dave Chinner , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229842991.1338752.2749856648086015843.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: da2b9c3a8d2cbdeec3f13cebf4c6c86c13e1077e Move the check if we have enough indirect blocks and the stealing of the deleted extent blocks out of xfs_bmap_split_indlen and into the caller to prepare for handling delayed allocation of RT extents that can't easily be stolen. Signed-off-by: Christoph Hellwig Reviewed-by: Dave Chinner Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_bmap.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 79cde87d0..7b18477e0 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -4825,31 +4825,17 @@ xfs_bmapi_remap( * ores == 1). The number of stolen blocks is returned. The availability and * subsequent accounting of stolen blocks is the responsibility of the caller. */ -static xfs_filblks_t +static void xfs_bmap_split_indlen( xfs_filblks_t ores, /* original res. */ xfs_filblks_t *indlen1, /* ext1 worst indlen */ - xfs_filblks_t *indlen2, /* ext2 worst indlen */ - xfs_filblks_t avail) /* stealable blocks */ + xfs_filblks_t *indlen2) /* ext2 worst indlen */ { xfs_filblks_t len1 = *indlen1; xfs_filblks_t len2 = *indlen2; xfs_filblks_t nres = len1 + len2; /* new total res. */ - xfs_filblks_t stolen = 0; xfs_filblks_t resfactor; - /* - * Steal as many blocks as we can to try and satisfy the worst case - * indlen for both new extents. - */ - if (ores < nres && avail) - stolen = XFS_FILBLKS_MIN(nres - ores, avail); - ores += stolen; - - /* nothing else to do if we've satisfied the new reservation */ - if (ores >= nres) - return stolen; - /* * We can't meet the total required reservation for the two extents. * Calculate the percent of the overall shortage between both extents @@ -4894,8 +4880,6 @@ xfs_bmap_split_indlen( *indlen1 = len1; *indlen2 = len2; - - return stolen; } int @@ -4911,7 +4895,7 @@ xfs_bmap_del_extent_delay( struct xfs_bmbt_irec new; int64_t da_old, da_new, da_diff = 0; xfs_fileoff_t del_endoff, got_endoff; - xfs_filblks_t got_indlen, new_indlen, stolen; + xfs_filblks_t got_indlen, new_indlen, stolen = 0; uint32_t state = xfs_bmap_fork_to_state(whichfork); uint64_t fdblocks; int error = 0; @@ -4990,8 +4974,19 @@ xfs_bmap_del_extent_delay( new_indlen = xfs_bmap_worst_indlen(ip, new.br_blockcount); WARN_ON_ONCE(!got_indlen || !new_indlen); - stolen = xfs_bmap_split_indlen(da_old, &got_indlen, &new_indlen, - del->br_blockcount); + /* + * Steal as many blocks as we can to try and satisfy the worst + * case indlen for both new extents. + */ + da_new = got_indlen + new_indlen; + if (da_new > da_old) { + stolen = XFS_FILBLKS_MIN(da_new - da_old, + del->br_blockcount); + da_old += stolen; + } + if (da_new > da_old) + xfs_bmap_split_indlen(da_old, &got_indlen, &new_indlen); + da_new = got_indlen + new_indlen; got->br_startblock = nullstartblock((int)got_indlen); @@ -5003,7 +4998,6 @@ xfs_bmap_del_extent_delay( xfs_iext_next(ifp, icur); xfs_iext_insert(ip, icur, &new, state); - da_new = got_indlen + new_indlen - stolen; del->br_blockcount -= stolen; break; } From patchwork Tue Jul 30 00:34:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745956 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 43D937E1 for ; Tue, 30 Jul 2024 00:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299653; cv=none; b=bu/pVRqSvqqJXp/wSllD6Jsp1a6DBnccfnUoO+ZPv0aip/YCVFUEeTlyzgncVbhzz+9dWCXlaTChG1he5als1me68TcJa25+J4SGz5NjqsqhCjLG7cj6r0VVHgzMnRAnVQHpHv62XCoTD/Bn3I7vqxjnSZGE8nHeUZPld7mmPLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299653; c=relaxed/simple; bh=e+jyJHB91Ei9XwyBxYXS+DW/sdx5sQYGiqOg2egX7wY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ve7K7FY4Z9R7TA5QykJ891t1EtoRZQnAOfQUA808O/G1pSesVF60cnOzXICB4uNfKr7+5cll9DMRKT9QPveQTlnbV/YnsicLD/nRf3q+5t9gOIsZtcm2nP2FJWbz2JG4GAEv5Hj2vjzT2oTY5r3nwWnyMoPW52iBuNAVaPWgV1o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F70I1neD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="F70I1neD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C90A1C32786; Tue, 30 Jul 2024 00:34:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299652; bh=e+jyJHB91Ei9XwyBxYXS+DW/sdx5sQYGiqOg2egX7wY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=F70I1neDSOKEsiAKfA6g5nAw7XJ2lP+UabrIXOcLqIXeWrZQxqNsyEdJzoaMdxnC5 QTPlpaeu391XFhWZlMmWu4vEkwDS04mUu19XnU+z/DcjQnhrfEM+MwlsZTN3rvasaE K2upprCDMoPcyyM3kWvTG46vAraYD7PvepwmexR2dCGR134casOtHXJqy03cPeMSpI AzAqYHBr8vc0EpIOL2CaOPnwQmj2zNZL4TXkMKeeIPSuwx0pTsgp5F9+vKmsYQxOYP Xk8ebeBlkL9HI+YerwqIR+Q8iwNGS7EhFSusOE0UHMV7vqd996P2tPf4aO0o/2XRJ5 x0lai5BVdWwcg== Date: Mon, 29 Jul 2024 17:34:12 -0700 Subject: [PATCH 040/115] xfs: stop the steal (of data blocks for RT indirect blocks) From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Dave Chinner , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229843005.1338752.10819291299210130711.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: bd1753d8c42b6bd5d9a81c81d1ce6e3affe3a59f When xfs_bmap_del_extent_delay has to split an indirect block it tries to steal blocks from the the part that gets unmapped to increase the indirect block reservation that now needs to cover for two extents instead of one. This works perfectly fine on the data device, where the data and indirect blocks come from the same pool. It has no chance of working when the inode sits on the RT device. To support re-enabling delalloc for inodes on the RT device, make this behavior conditional on not being for rt extents. Note that split of delalloc extents should only happen on writeback failure, as for other kinds of hole punching we first write back all data and thus convert the delalloc reservations covering the hole to a real allocation. Signed-off-by: Christoph Hellwig Reviewed-by: Dave Chinner Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_bmap.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 7b18477e0..81dccf275 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -4977,9 +4977,14 @@ xfs_bmap_del_extent_delay( /* * Steal as many blocks as we can to try and satisfy the worst * case indlen for both new extents. + * + * However, we can't just steal reservations from the data + * blocks if this is an RT inodes as the data and metadata + * blocks come from different pools. We'll have to live with + * under-filled indirect reservation in this case. */ da_new = got_indlen + new_indlen; - if (da_new > da_old) { + if (da_new > da_old && !isrt) { stolen = XFS_FILBLKS_MIN(da_new - da_old, del->br_blockcount); da_old += stolen; From patchwork Tue Jul 30 00:34:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745957 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D786110E3 for ; Tue, 30 Jul 2024 00:34:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299668; cv=none; b=VdtAeAuSxBCOlBnybwixZxpUKhVSbTx5NvIDA9bumzrWNZn631TGUR5C9MoOV8oLpVqLt2AjYctArBB15xZ/o3LtkovzQX3DwPXJ5ZRGT7MPuv+2gSJq3dd5Uc6U1RqDuvcE+ClmXOR+TwUwmQ7CwjZ1CrKdD594d2rFw7S7Dlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299668; c=relaxed/simple; bh=XKX4yNFaIltEpIacbHoR3aTqxIT2InsWyFxu8dXyde4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YadjL6/wWu+gSWroMa7qWHAmy1hBoIBBpxt4+0tc7J/lWXlrQ+tJvfjotOam3T4FOHZGe6yjOiPa0N1hEfvHUm16ZWFuy4k++19ROhYp/n+6bcfRjXNMDEG9c+MRBv2kQIuYrKZ1rDbhefOyl3Lq5NrNvyDFgD2WWl77Wnnja4o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OpOVjzK/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OpOVjzK/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 741D7C32786; Tue, 30 Jul 2024 00:34:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299668; bh=XKX4yNFaIltEpIacbHoR3aTqxIT2InsWyFxu8dXyde4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=OpOVjzK/xLAZeRmpiNacRdRC1lGJ+08KnC72oqhaf4FBF/brTv8JTWi2EJzQTT1dt 30uWUwDEiQacIX8JIhHsVNx5DwuUjk2WTeDBpc3kPiUdNbAnDqYi2YwbEqyzYj0O0v 82IoAFEIsV4/LFIX3zxKHNjFPc+kScjhT0j9Z2fnOVOFwK1oTwdocByG+1hoUT2f0c BckOyXzvyzbj1DSYP8Hqjs3d7gP1C78nibZsQ6gP2HvcXn85uOevC6tyPuJyvtAJQy zlrZ4wgfeGq+pwjShcwoAUvT0PK+/+s71ND3pXkpQibcRRTWXnsfKRoxMD7GGOfbbb r93ThUM5+Og3w== Date: Mon, 29 Jul 2024 17:34:27 -0700 Subject: [PATCH 041/115] xfs: remove XFS_DA_OP_REMOVE From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843020.1338752.3697044140404729295.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: f566d5b9fb7136d39d4e9c54d84c82835b539b4e Nobody checks this flag, so get rid of it. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr.h | 1 - libxfs/xfs_da_btree.h | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h index e4f550085..670ab2a61 100644 --- a/libxfs/xfs_attr.h +++ b/libxfs/xfs_attr.h @@ -590,7 +590,6 @@ xfs_attr_init_add_state(struct xfs_da_args *args) static inline enum xfs_delattr_state xfs_attr_init_remove_state(struct xfs_da_args *args) { - args->op_flags |= XFS_DA_OP_REMOVE; if (xfs_attr_is_shortform(args->dp)) return XFS_DAS_SF_REMOVE; if (xfs_attr_is_leaf(args->dp)) diff --git a/libxfs/xfs_da_btree.h b/libxfs/xfs_da_btree.h index 7a004786e..76e764080 100644 --- a/libxfs/xfs_da_btree.h +++ b/libxfs/xfs_da_btree.h @@ -91,9 +91,8 @@ typedef struct xfs_da_args { #define XFS_DA_OP_OKNOENT (1u << 3) /* lookup op, ENOENT ok, else die */ #define XFS_DA_OP_CILOOKUP (1u << 4) /* lookup returns CI name if found */ #define XFS_DA_OP_NOTIME (1u << 5) /* don't update inode timestamps */ -#define XFS_DA_OP_REMOVE (1u << 6) /* this is a remove operation */ -#define XFS_DA_OP_RECOVERY (1u << 7) /* Log recovery operation */ -#define XFS_DA_OP_LOGGED (1u << 8) /* Use intent items to track op */ +#define XFS_DA_OP_RECOVERY (1u << 6) /* Log recovery operation */ +#define XFS_DA_OP_LOGGED (1u << 7) /* Use intent items to track op */ #define XFS_DA_OP_FLAGS \ { XFS_DA_OP_JUSTCHECK, "JUSTCHECK" }, \ @@ -102,7 +101,6 @@ typedef struct xfs_da_args { { XFS_DA_OP_OKNOENT, "OKNOENT" }, \ { XFS_DA_OP_CILOOKUP, "CILOOKUP" }, \ { XFS_DA_OP_NOTIME, "NOTIME" }, \ - { XFS_DA_OP_REMOVE, "REMOVE" }, \ { XFS_DA_OP_RECOVERY, "RECOVERY" }, \ { XFS_DA_OP_LOGGED, "LOGGED" } From patchwork Tue Jul 30 00:34:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745958 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 4AE871361 for ; Tue, 30 Jul 2024 00:34:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299684; cv=none; b=mlYhavjuQ6+wCGZzIehb7zotIPfZvNGsP0A5u067fev4RpheYfKEeBzn2mnFp8qnhCUDB6oJ9C5O/fhtLo2uc5jAQwo0Ap3OX1NVyXzwZvaXEam55Rt8Yx+H5pp2ILtjK7zJRzvb2CZC6WkRUQdfvfjn0ByiWWszx5pwfn8YG5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299684; c=relaxed/simple; bh=VPFa4LjvQ67JRlplxD68IM+O1zOKaTD0GD+JSw5i0Ok=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rpLWbOa8NJ10NMNEVFstJFfuVvIGpiwg/PKDZj14qkXrQC/lkt0olZpF/CUiVeOjJr1Vr5fNIAinhUfXkbG1SWiahtXCKN0gml9BeEhRvGPoAzRSi5R/KDDUr0Y23Jm/AerRogNBPyk3FghFys9nekSNGNe7Hd9nuVDj0s2eBIk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Q5vAktXw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Q5vAktXw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25315C32786; Tue, 30 Jul 2024 00:34:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299684; bh=VPFa4LjvQ67JRlplxD68IM+O1zOKaTD0GD+JSw5i0Ok=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Q5vAktXw6jHJpUV8hzJRWbiEV5iMIiQg+f/HT9S/Wjp0KzU5bpIK1wX8yH8OYiL3/ OS/aMDmLaMrIpdXNecBWKEjb7c2RrM5P0E1nxW9e3RFLHNJAYmLjChDrCxN3hs+Sqz mVFBiua4zwYXDfB+LlIf/pw8XfUS3xIZxZffFzT3f8iZtzcSGaCfL8ZiN7QLTFywSU TnjQIheGqCcEk2kTVxnYDggMm6VDbnm0D0qEAyZTAXHsYWj9K2zrmajUHtz+OFB/sV O5p0UUdsjb6bvz12CcNUUfVNwpgErC4qKLv34mVvwo5jJNEZyuJY3+NhJQgdwEHht3 HRI2ea89m+Fsw== Date: Mon, 29 Jul 2024 17:34:43 -0700 Subject: [PATCH 042/115] xfs: remove XFS_DA_OP_NOTIME From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843034.1338752.13204698580605910110.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 779a4b606c7678343e3603398fe07de38b817ef4 The only user of this flag sets it prior to an xfs_attr_get_ilocked call, which doesn't update anything. Get rid of the flag. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr.c | 5 ++--- libxfs/xfs_da_btree.h | 6 ++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 07f873927..958c6d720 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -363,7 +363,7 @@ xfs_attr_try_sf_addname( * Commit the shortform mods, and we're done. * NOTE: this is also the error path (EEXIST, etc). */ - if (!error && !(args->op_flags & XFS_DA_OP_NOTIME)) + if (!error) xfs_trans_ichgtime(args->trans, dp, XFS_ICHGTIME_CHG); if (xfs_has_wsync(dp->i_mount)) @@ -1031,8 +1031,7 @@ xfs_attr_set( if (xfs_has_wsync(mp)) xfs_trans_set_sync(args->trans); - if (!(args->op_flags & XFS_DA_OP_NOTIME)) - xfs_trans_ichgtime(args->trans, dp, XFS_ICHGTIME_CHG); + xfs_trans_ichgtime(args->trans, dp, XFS_ICHGTIME_CHG); /* * Commit the last in the sequence of transactions. diff --git a/libxfs/xfs_da_btree.h b/libxfs/xfs_da_btree.h index 76e764080..b04a3290f 100644 --- a/libxfs/xfs_da_btree.h +++ b/libxfs/xfs_da_btree.h @@ -90,9 +90,8 @@ typedef struct xfs_da_args { #define XFS_DA_OP_ADDNAME (1u << 2) /* this is an add operation */ #define XFS_DA_OP_OKNOENT (1u << 3) /* lookup op, ENOENT ok, else die */ #define XFS_DA_OP_CILOOKUP (1u << 4) /* lookup returns CI name if found */ -#define XFS_DA_OP_NOTIME (1u << 5) /* don't update inode timestamps */ -#define XFS_DA_OP_RECOVERY (1u << 6) /* Log recovery operation */ -#define XFS_DA_OP_LOGGED (1u << 7) /* Use intent items to track op */ +#define XFS_DA_OP_RECOVERY (1u << 5) /* Log recovery operation */ +#define XFS_DA_OP_LOGGED (1u << 6) /* Use intent items to track op */ #define XFS_DA_OP_FLAGS \ { XFS_DA_OP_JUSTCHECK, "JUSTCHECK" }, \ @@ -100,7 +99,6 @@ typedef struct xfs_da_args { { XFS_DA_OP_ADDNAME, "ADDNAME" }, \ { XFS_DA_OP_OKNOENT, "OKNOENT" }, \ { XFS_DA_OP_CILOOKUP, "CILOOKUP" }, \ - { XFS_DA_OP_NOTIME, "NOTIME" }, \ { XFS_DA_OP_RECOVERY, "RECOVERY" }, \ { XFS_DA_OP_LOGGED, "LOGGED" } From patchwork Tue Jul 30 00:34:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745959 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 EFCED1366 for ; Tue, 30 Jul 2024 00:34:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299700; cv=none; b=aRidJtrl0LRAcXVY4E3AtWgA9Xtm2RN6X7vLGdTZKGthlh554hWo68NQ0+v/MDOutm8SRihjzUsZ2eUWaDLXG1lfwr+NGQBf5eFhy2x6+Wh3S3LyeJ5SqX3Hn7lM7q/Vj9iTQT0VCrRTDs647Gl3+9fSxhL9ncnh0BJ/6bInciY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299700; c=relaxed/simple; bh=2LPiZOx4ROQuJdHKgjDCdDVCrUX5P8fIKLnGqQEZY8Y=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MrCnQis3bURAgbFS211PfED1rBkTbMUhCG8HsJ1iW0Ky/2Wb3mBjNLvtUrKtvHhBUy5S+rV6r2RCiIEfBc7oLEgqnrWriIH9KY9J6B76SUk3UY8wv45iGtPl+d3HGuOOVdXYZvS7xqkOyp2dXZQT1p/wrf9RzSLuCS+g27J1L0k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hRgp4BTN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hRgp4BTN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9D2CC32786; Tue, 30 Jul 2024 00:34:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299699; bh=2LPiZOx4ROQuJdHKgjDCdDVCrUX5P8fIKLnGqQEZY8Y=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=hRgp4BTNSbFVnbix2yJc2tLy75AtFfzb46dUY+TrvPwCu2ByyQJ9GVcTMdsAJabxS U2/XNJV1BFWwgjq5PslqvQT1KB1nrVGoCWwHFiF39MstBLCYQb8UAddFo8t2b5JZat K9lMlXnSogpFFjhCrckAH4ROHXBlPKZP4e0YZQhxoxBP0x13L+HRIdO9NAmH10t+aV Wv3pcO0xG6bCkFK0KP1Mob8vcEQMIZrga7u9Dfp0jzB4FA635uJiFFv7MZDdEOGvw5 Xjs08qDnqNEz6T3TAxWDCzm0ntL2OveowHkkKPo+arAGQQYIrJGyx+JZRqNE4x9x91 scEc6Oagt95mA== Date: Mon, 29 Jul 2024 17:34:59 -0700 Subject: [PATCH 043/115] xfs: remove xfs_da_args.attr_flags From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843049.1338752.16393745334288034377.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 54275d8496f3e4764302cebc0e9517d950ba6589 This field only ever contains XATTR_{CREATE,REPLACE}, and it only goes as deep as xfs_attr_set. Remove the field from the structure and replace it with an enum specifying exactly what kind of change we want to make to the xattr structure. Upsert is the name that we'll give to the flags==0 operation, because we're either updating an existing value or inserting it, and the caller doesn't care. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- db/attrset.c | 11 +++++------ libxfs/xfs_attr.c | 7 ++++--- libxfs/xfs_attr.h | 9 ++++++++- libxfs/xfs_da_btree.h | 1 - 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/db/attrset.c b/db/attrset.c index 0d8d70a84..736482fea 100644 --- a/db/attrset.c +++ b/db/attrset.c @@ -69,6 +69,7 @@ attr_set_f( { struct xfs_da_args args = { }; char *sp; + enum xfs_attr_update op = XFS_ATTRUPDATE_UPSERTR; int c; if (cur_typ == NULL) { @@ -98,12 +99,10 @@ attr_set_f( /* modifiers */ case 'C': - args.attr_flags |= XATTR_CREATE; - args.attr_flags &= ~XATTR_REPLACE; + op = XFS_ATTRUPDATE_CREATE; break; case 'R': - args.attr_flags |= XATTR_REPLACE; - args.attr_flags &= ~XATTR_CREATE; + op = XFS_ATTRUPDATE_REPLACE; break; case 'n': @@ -162,7 +161,7 @@ attr_set_f( goto out; } - if (libxfs_attr_set(&args)) { + if (libxfs_attr_set(&args, op)) { dbprintf(_("failed to set attr %s on inode %llu\n"), args.name, (unsigned long long)iocur_top->ino); goto out; @@ -248,7 +247,7 @@ attr_remove_f( goto out; } - if (libxfs_attr_set(&args)) { + if (libxfs_attr_set(&args, XFS_ATTRUPDATE_UPSERTR)) { dbprintf(_("failed to remove attr %s from inode %llu\n"), (unsigned char *)args.name, (unsigned long long)iocur_top->ino); diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 958c6d720..9a6787624 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -920,7 +920,8 @@ xfs_attr_defer_add( */ int xfs_attr_set( - struct xfs_da_args *args) + struct xfs_da_args *args, + enum xfs_attr_update op) { struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; @@ -1006,7 +1007,7 @@ xfs_attr_set( } /* Pure create fails if the attr already exists */ - if (args->attr_flags & XATTR_CREATE) + if (op == XFS_ATTRUPDATE_CREATE) goto out_trans_cancel; xfs_attr_defer_add(args, XFS_ATTRI_OP_FLAGS_REPLACE); break; @@ -1016,7 +1017,7 @@ xfs_attr_set( goto out_trans_cancel; /* Pure replace fails if no existing attr to replace. */ - if (args->attr_flags & XATTR_REPLACE) + if (op == XFS_ATTRUPDATE_REPLACE) goto out_trans_cancel; xfs_attr_defer_add(args, XFS_ATTRI_OP_FLAGS_SET); break; diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h index 670ab2a61..228360f7c 100644 --- a/libxfs/xfs_attr.h +++ b/libxfs/xfs_attr.h @@ -544,7 +544,14 @@ int xfs_inode_hasattr(struct xfs_inode *ip); bool xfs_attr_is_leaf(struct xfs_inode *ip); int xfs_attr_get_ilocked(struct xfs_da_args *args); int xfs_attr_get(struct xfs_da_args *args); -int xfs_attr_set(struct xfs_da_args *args); + +enum xfs_attr_update { + XFS_ATTRUPDATE_UPSERTR, /* set/remove value, replace any existing attr */ + XFS_ATTRUPDATE_CREATE, /* set value, fail if attr already exists */ + XFS_ATTRUPDATE_REPLACE, /* set value, fail if attr does not exist */ +}; + +int xfs_attr_set(struct xfs_da_args *args, enum xfs_attr_update op); int xfs_attr_set_iter(struct xfs_attr_intent *attr); int xfs_attr_remove_iter(struct xfs_attr_intent *attr); bool xfs_attr_namecheck(const void *name, size_t length); diff --git a/libxfs/xfs_da_btree.h b/libxfs/xfs_da_btree.h index b04a3290f..706b529a8 100644 --- a/libxfs/xfs_da_btree.h +++ b/libxfs/xfs_da_btree.h @@ -60,7 +60,6 @@ typedef struct xfs_da_args { void *value; /* set of bytes (maybe contain NULLs) */ int valuelen; /* length of value */ unsigned int attr_filter; /* XFS_ATTR_{ROOT,SECURE,INCOMPLETE} */ - unsigned int attr_flags; /* XATTR_{CREATE,REPLACE} */ xfs_dahash_t hashval; /* hash value of name */ xfs_ino_t inumber; /* input/output inode number */ struct xfs_inode *dp; /* directory inode to manipulate */ From patchwork Tue Jul 30 00:35:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745960 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D604F53BE for ; Tue, 30 Jul 2024 00:35:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299715; cv=none; b=pFXjyIxYht1UKqIXMaGB36ADUOOwx5VGHG6c4+UU65UyPUBgxgWUT5R0ZsYZfcM2IkPfBdLzeyo4ARggpy2IFWFBGuiYArtskQvIRc4SISHXBh+fz7A6YqHgpFP6xTV5uFaqgCrf9CUHJp/l/luyubtvy/LNuEQpYBlqqY/QHgQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299715; c=relaxed/simple; bh=2yvtfnTK5mdPnkTegL8/mStxPKxCZE3YQABcvMEQHT0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JpEdcl0O9dEQ3CBLhFx7YB5Q6rksTGCWSMBmW7n9yTPjhdVy/dPolFx99+V4s1hxLKdapCgT2nn77bqF04p8Odc/h7x4x2vknpubHJHiw4aG/TR4osIVgr7yX5nZb/ekxawZbphae7I3Dq4mDxph1f3n55nXEujGmaHMwmBsF24= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OfGnSX8M; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OfGnSX8M" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62B5EC4AF0B; Tue, 30 Jul 2024 00:35:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299715; bh=2yvtfnTK5mdPnkTegL8/mStxPKxCZE3YQABcvMEQHT0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=OfGnSX8MU3XDFgWe9ghTFb4tH6tSiCDWg93FI8zUJsgPlWdTb+HwFDajKlM9QqYH+ SVIp/28wBrGXp9e1VpqrQgn1IGHMrkKHyMGn8tfJuJFtBWr+8KpMnZMh2qJi9ulME0 Iv3i7ZBv/5ZWHspfkzpRlYZAo0Nw3uM5P77DOVn4IoozsXK6wkRB9auASOGGlZ26fW vPgTau4XwOZ76bSrgAOEh/Hf7vzkFYhkwkxY29SbC9nfxasTE0KmxNaD+CVbKngpH2 P4XERNgIBHGE0KWWRmVB6DubmZRntOdZIlYl/haJ/O5FuFWzO73K9UWnEmT4EfbhPO 350xPtPDcpSVw== Date: Mon, 29 Jul 2024 17:35:14 -0700 Subject: [PATCH 044/115] xfs: make attr removal an explicit operation From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843062.1338752.7951983944435816559.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: c27411d4c640037d70e2fa5751616e175e52ca5e Parent pointers match attrs on name+value, unlike everything else which matches on only the name. Therefore, we cannot keep using the heuristic that !value means remove. Make this an explicit operation code. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- db/attrset.c | 4 ++-- libxfs/xfs_attr.c | 19 ++++++++++--------- libxfs/xfs_attr.h | 3 ++- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/db/attrset.c b/db/attrset.c index 736482fea..a59d5473e 100644 --- a/db/attrset.c +++ b/db/attrset.c @@ -69,7 +69,7 @@ attr_set_f( { struct xfs_da_args args = { }; char *sp; - enum xfs_attr_update op = XFS_ATTRUPDATE_UPSERTR; + enum xfs_attr_update op = XFS_ATTRUPDATE_UPSERT; int c; if (cur_typ == NULL) { @@ -247,7 +247,7 @@ attr_remove_f( goto out; } - if (libxfs_attr_set(&args, XFS_ATTRUPDATE_UPSERTR)) { + if (libxfs_attr_set(&args, XFS_ATTRUPDATE_REMOVE)) { dbprintf(_("failed to remove attr %s from inode %llu\n"), (unsigned char *)args.name, (unsigned long long)iocur_top->ino); diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 9a6787624..5249f9be0 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -914,10 +914,6 @@ xfs_attr_defer_add( trace_xfs_attr_defer_add(new->xattri_dela_state, args->dp); } -/* - * Note: If args->value is NULL the attribute will be removed, just like the - * Linux ->setattr API. - */ int xfs_attr_set( struct xfs_da_args *args, @@ -953,7 +949,10 @@ xfs_attr_set( args->op_flags = XFS_DA_OP_OKNOENT | (args->op_flags & XFS_DA_OP_LOGGED); - if (args->value) { + switch (op) { + case XFS_ATTRUPDATE_UPSERT: + case XFS_ATTRUPDATE_CREATE: + case XFS_ATTRUPDATE_REPLACE: XFS_STATS_INC(mp, xs_attr_set); args->total = xfs_attr_calc_size(args, &local); @@ -973,9 +972,11 @@ xfs_attr_set( if (!local) rmt_blks = xfs_attr3_rmt_blocks(mp, args->valuelen); - } else { + break; + case XFS_ATTRUPDATE_REMOVE: XFS_STATS_INC(mp, xs_attr_remove); rmt_blks = xfs_attr3_rmt_blocks(mp, XFS_XATTR_SIZE_MAX); + break; } /* @@ -987,7 +988,7 @@ xfs_attr_set( if (error) return error; - if (args->value || xfs_inode_hasattr(dp)) { + if (op != XFS_ATTRUPDATE_REMOVE || xfs_inode_hasattr(dp)) { error = xfs_iext_count_may_overflow(dp, XFS_ATTR_FORK, XFS_IEXT_ATTR_MANIP_CNT(rmt_blks)); if (error == -EFBIG) @@ -1000,7 +1001,7 @@ xfs_attr_set( error = xfs_attr_lookup(args); switch (error) { case -EEXIST: - if (!args->value) { + if (op == XFS_ATTRUPDATE_REMOVE) { /* if no value, we are performing a remove operation */ xfs_attr_defer_add(args, XFS_ATTRI_OP_FLAGS_REMOVE); break; @@ -1013,7 +1014,7 @@ xfs_attr_set( break; case -ENOATTR: /* Can't remove what isn't there. */ - if (!args->value) + if (op == XFS_ATTRUPDATE_REMOVE) goto out_trans_cancel; /* Pure replace fails if no existing attr to replace. */ diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h index 228360f7c..c8005f521 100644 --- a/libxfs/xfs_attr.h +++ b/libxfs/xfs_attr.h @@ -546,7 +546,8 @@ int xfs_attr_get_ilocked(struct xfs_da_args *args); int xfs_attr_get(struct xfs_da_args *args); enum xfs_attr_update { - XFS_ATTRUPDATE_UPSERTR, /* set/remove value, replace any existing attr */ + XFS_ATTRUPDATE_REMOVE, /* remove attr */ + XFS_ATTRUPDATE_UPSERT, /* set value, replace any existing attr */ XFS_ATTRUPDATE_CREATE, /* set value, fail if attr already exists */ XFS_ATTRUPDATE_REPLACE, /* set value, fail if attr does not exist */ }; From patchwork Tue Jul 30 00:35:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745961 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3547E3FE4 for ; Tue, 30 Jul 2024 00:35:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299731; cv=none; b=Dl3SsZJR2U+SdgyLuwmYIptlmIcu0KajG8rZ69V74tOV15/KgD0o6TGFEOYk9p59W6/arU9J8LpTJM9oVA6q7mdigPxiMLuQwprj8Ip1kz6gm+70o2vcdl3wZZ8yFPH3cXn1cRaUzgpbTypVEqP6s9msUOh7RuUyHEG8gsrF4iQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299731; c=relaxed/simple; bh=ZpLK4fpzz73Rjb0WhopjlBg+CKpU4hdTuGXklsjF8zw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bNMSFckTR0L5MbA2tMoMHqdMKiDZNL2cO4pzwal1cbHWpSNnwFtFSDZTEMA4QCKeTcs5naE/A3RniP5OZvxWF5ZxvwgfpDThaKJqklY9Pzkjc+gbMpETTX180LrquRdm6FTUOMDe1taOS3LNjlDWKLOgH4BGSQ8F4l3Ohqj3LpM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aQ2ZW3WX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aQ2ZW3WX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 122B9C32786; Tue, 30 Jul 2024 00:35:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299731; bh=ZpLK4fpzz73Rjb0WhopjlBg+CKpU4hdTuGXklsjF8zw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=aQ2ZW3WX3BsupNBcckEYBmSYrrzeLQ4RnELSHY+QzmexFm3Oue4u3ARGrR5a+CwQa JQjwGJ+2hx64hdrXP++ukGbttSEPcrSq7EabZcnGzmB6pGwo/Lyb5e3btQ+pxITyX3 +SXxDspzWyjNDQX4+N3eF45AQfhBPW4zOBDi5bXeTRN/7HtIGWV6k2HbMxQl3s7HdN KQcovZnihdGrmw1h5vzWfxiAe6BeSZR8rqXnAnr+HWzrAbb6w0zSsr2E5GIkZWWyGi LsfUwdqp4DiAe124ol1VHaUs2tAaWqv1O0qUnxo0tivP47tMu1YfrZcIa6oendNbAM ImHCBKLgEDYqg== Date: Mon, 29 Jul 2024 17:35:30 -0700 Subject: [PATCH 045/115] xfs: rearrange xfs_da_args a bit to use less space From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843076.1338752.13895998587215955301.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: cda60317ac57add7a0a2865aa29afbc6caad3e9a A few notes about struct xfs_da_args: The XFS_ATTR_* flags only go up as far as XFS_ATTR_INCOMPLETE, which means that attr_filter could be a u8 field. I've reduced the number of XFS_DA_OP_* flags down to the point where op_flags would also fit into a u8. filetype has 7 bytes of slack after it, which is wasteful. namelen will never be greater than MAXNAMELEN, which is 256. This field could be reduced to a short. Rearrange the fields in xfs_da_args to waste less space. This reduces the structure size from 136 bytes to 128. Later when we add extra fields to support parent pointer replacement, this will only bloat the structure to 144 bytes, instead of 168. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_da_btree.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/libxfs/xfs_da_btree.h b/libxfs/xfs_da_btree.h index 706b529a8..17cef594b 100644 --- a/libxfs/xfs_da_btree.h +++ b/libxfs/xfs_da_btree.h @@ -54,16 +54,20 @@ enum xfs_dacmp { */ typedef struct xfs_da_args { struct xfs_da_geometry *geo; /* da block geometry */ - const uint8_t *name; /* string (maybe not NULL terminated) */ - int namelen; /* length of string (maybe no NULL) */ - uint8_t filetype; /* filetype of inode for directories */ + const uint8_t *name; /* string (maybe not NULL terminated) */ void *value; /* set of bytes (maybe contain NULLs) */ - int valuelen; /* length of value */ - unsigned int attr_filter; /* XFS_ATTR_{ROOT,SECURE,INCOMPLETE} */ - xfs_dahash_t hashval; /* hash value of name */ - xfs_ino_t inumber; /* input/output inode number */ struct xfs_inode *dp; /* directory inode to manipulate */ struct xfs_trans *trans; /* current trans (changes over time) */ + + xfs_ino_t inumber; /* input/output inode number */ + xfs_ino_t owner; /* inode that owns the dir/attr data */ + + int valuelen; /* length of value */ + uint8_t filetype; /* filetype of inode for directories */ + uint8_t op_flags; /* operation flags */ + uint8_t attr_filter; /* XFS_ATTR_{ROOT,SECURE,INCOMPLETE} */ + short namelen; /* length of string (maybe no NULL) */ + xfs_dahash_t hashval; /* hash value of name */ xfs_extlen_t total; /* total blocks needed, for 1st bmap */ int whichfork; /* data or attribute fork */ xfs_dablk_t blkno; /* blkno of attr leaf of interest */ @@ -76,9 +80,7 @@ typedef struct xfs_da_args { xfs_dablk_t rmtblkno2; /* remote attr value starting blkno */ int rmtblkcnt2; /* remote attr value block count */ int rmtvaluelen2; /* remote attr value length in bytes */ - uint32_t op_flags; /* operation flags */ enum xfs_dacmp cmpresult; /* name compare result for lookups */ - xfs_ino_t owner; /* inode that owns the dir/attr data */ } xfs_da_args_t; /* From patchwork Tue Jul 30 00:35:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745962 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D8F573FE4 for ; Tue, 30 Jul 2024 00:35:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299746; cv=none; b=rt2ekdBY6R32idcIDwyNoPd+stsZXUmz+sxHrsyuvHQdEaruHvTDQhce2HJAQegzKCWuAOSPgPWFE07wwqXCwtdUkFl4GJGR978uJXxko+dQvqTT0Uzp/DUPYYYR28ImnERkvPAw/cqCcDHq2N+7LPhDopmI3uzlUbKoDlZqb4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299746; c=relaxed/simple; bh=ibFX8elBA6+vt3Cyn1yJdjyD2OfAnWo4Q5+HLK3Hk7U=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iPKuwIB6oxviUI5mtT9amdanAWwfDionwXAtQ2ZOIYOxoXCYQ2qV0SOgrTw6YFbE9/fqfWTcndaQ2Mv67b1ABz8+ogoOYHSKRBOCghxowxE8UUoH+tdeb0E1YvzwtnBqpu2D+nEfVW3GScszB/YbrS7vaf0K/QcaoM1MDvCZssc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eCBJWQup; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eCBJWQup" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0CE1C32786; Tue, 30 Jul 2024 00:35:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299746; bh=ibFX8elBA6+vt3Cyn1yJdjyD2OfAnWo4Q5+HLK3Hk7U=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=eCBJWQupeTvBhRKiTS3m/ORxG6TLxnI+mAVvd6KM2u8n94TQ22CjnNiffSQuTDFTl kcRPHHbjGB7YM2NG7G+jtxeWVTJyVsZT2oQkEtc59fYOG3Wr3G/tcog9CJUvSy9qxk Id7dRm7zQFV7jhI3jMmM908FIqkDj+O65NUZ44DocIyqGYt1hTrOl22XyKECTNZcG1 aOoLRLQ1ZYRAVpNOu/dnWayZ8sK6eue7wAQS9svDnChvwpXzaVh+U6i/4Xhy4OqHF5 5/+uPtdYqQwDSO5GaSG/WzpaGNcpNZdc0hPeBGPmwU956cfvROk7zgePy89OmwZ8p0 Zhke3qo88T48Q== Date: Mon, 29 Jul 2024 17:35:46 -0700 Subject: [PATCH 046/115] xfs: attr fork iext must be loaded before calling xfs_attr_is_leaf From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843089.1338752.16878558381685097871.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: ef80de940a6344da1d4f12c948a0ad4d6ff6e841 Christoph noticed that the xfs_attr_is_leaf in xfs_attr_get_ilocked can access the incore extent tree of the attr fork, but nothing in the xfs_attr_get path guarantees that the incore tree is actually loaded. Most of the time it is, but seeing as xfs_attr_is_leaf ignores the return value of xfs_iext_get_extent I guess we've been making choices based on random stack contents and nobody's complained? Reported-by: Christoph Hellwig Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 5249f9be0..8e9e23836 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -85,6 +85,8 @@ xfs_attr_is_leaf( struct xfs_iext_cursor icur; struct xfs_bmbt_irec imap; + ASSERT(!xfs_need_iread_extents(ifp)); + if (ifp->if_nextents != 1 || ifp->if_format != XFS_DINODE_FMT_EXTENTS) return false; @@ -222,11 +224,21 @@ int xfs_attr_get_ilocked( struct xfs_da_args *args) { + int error; + xfs_assert_ilocked(args->dp, XFS_ILOCK_SHARED | XFS_ILOCK_EXCL); if (!xfs_inode_hasattr(args->dp)) return -ENOATTR; + /* + * The incore attr fork iext tree must be loaded for xfs_attr_is_leaf + * to work correctly. + */ + error = xfs_iread_extents(args->trans, args->dp, XFS_ATTR_FORK); + if (error) + return error; + if (args->dp->i_af.if_format == XFS_DINODE_FMT_LOCAL) return xfs_attr_shortform_getvalue(args); if (xfs_attr_is_leaf(args->dp)) @@ -868,6 +880,11 @@ xfs_attr_lookup( return -ENOATTR; } + /* Prerequisite for xfs_attr_is_leaf */ + error = xfs_iread_extents(args->trans, args->dp, XFS_ATTR_FORK); + if (error) + return error; + if (xfs_attr_is_leaf(dp)) { error = xfs_attr_leaf_hasname(args, &bp); From patchwork Tue Jul 30 00:36:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745968 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D30AB4A2D for ; Tue, 30 Jul 2024 00:36:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299762; cv=none; b=WeaD16g2woasyPYA4tFKDPHbI9jZG8A6P/2vpuU81DE2AUTlSxh7p5zXFH4PdbGs0MqF2sLKsouZ87TeWJwvvuBiEiFOoVIUyTIKMl8iWINFUN65GWQXASJTVXibyXkMGy8hUU8NLk+DfCngtB/P65t5LvS9U6/pYexIkQE/Q3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299762; c=relaxed/simple; bh=NI9T2Ry4vM4zGfNQ4bqw4+g3geXbtELGOzbN3rdTIFc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aso6AZMP2wpONQsStLig88AL6yLkOO8UnlPRmP7y/JZVqLHWOM0nfLUoQxks07ZONyCIY5D/SuZ60X3qODBmWE99YQTlGLs8HnoODN2SCJcjpiKa6R+zIUWsQxBZNMa8aNC0KwA52iVDi+7M7PXlIyxBcWgsv793JY509Jmw+80= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OLHQvuC1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OLHQvuC1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D4CBC32786; Tue, 30 Jul 2024 00:36:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299762; bh=NI9T2Ry4vM4zGfNQ4bqw4+g3geXbtELGOzbN3rdTIFc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=OLHQvuC1yGoN/Z0GArqYhdD86i1FC1aCkS7ImRnCzdngC9eui3YmBKlC05Cg1b1ie 9BxHchdF8EAFCzKStXNgWs1AaXbRyvc0OS3xDiUXEoZxuRX6YegCE7qRjAQ4Lp2MZ5 wFE+hyHlHNzztQMtiq2QotHpBkz4kBL+ThZVeG17dDHcxL5fRbt8entM0wRKSUOxt2 zX+ApvgPT2BJ7kb0eGc+22tbSKORy7dgXcaTiU/dcCI/QYANEmQoaKaxB9taeD8TQ9 fDQIZ0fvjGMIH/N+ioRnN9T6esFCuDYYBdvEU79y47Uk+4zeKmTp54p75n6CTCSglh r1ewd3vP4ediw== Date: Mon, 29 Jul 2024 17:36:01 -0700 Subject: [PATCH 047/115] xfs: fix missing check for invalid attr flags From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843104.1338752.14553982670184862324.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: f660ec8eaeb50d0317c29601aacabdb15e5f2203 The xattr scrubber doesn't check for undefined flags in shortform attr entries. Therefore, define a mask XFS_ATTR_ONDISK_MASK that has all possible XFS_ATTR_* flags in it, and use that to check for unknown bits in xchk_xattr_actor. Refactor the check in the dabtree scanner function to use the new mask as well. The redundant checks need to be in place because the dabtree check examines the hash mappings and therefore needs to decode the attr leaf entries to compute the namehash. This happens before the walk of the xattr entries themselves. Fixes: ae0506eba78fd ("xfs: check used space of shortform xattr structures") Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_da_format.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libxfs/xfs_da_format.h b/libxfs/xfs_da_format.h index aac3fe039..ecd0616f5 100644 --- a/libxfs/xfs_da_format.h +++ b/libxfs/xfs_da_format.h @@ -719,8 +719,13 @@ struct xfs_attr3_leafblock { #define XFS_ATTR_ROOT (1u << XFS_ATTR_ROOT_BIT) #define XFS_ATTR_SECURE (1u << XFS_ATTR_SECURE_BIT) #define XFS_ATTR_INCOMPLETE (1u << XFS_ATTR_INCOMPLETE_BIT) + #define XFS_ATTR_NSP_ONDISK_MASK (XFS_ATTR_ROOT | XFS_ATTR_SECURE) +#define XFS_ATTR_ONDISK_MASK (XFS_ATTR_NSP_ONDISK_MASK | \ + XFS_ATTR_LOCAL | \ + XFS_ATTR_INCOMPLETE) + #define XFS_ATTR_NAMESPACE_STR \ { XFS_ATTR_LOCAL, "local" }, \ { XFS_ATTR_ROOT, "root" }, \ From patchwork Tue Jul 30 00:36:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745969 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3C14D4683 for ; Tue, 30 Jul 2024 00:36:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299778; cv=none; b=qhcXyIa6V2IfDFmKE0xfst6KuDeWSNqIqt/c+KCM9thiuGZmuh2amPerjZe5nfcQZ/B7a4Wa+tyq50FC4zY1LXPTm42eZf4jES9CF1TTH8BJ4+xa8yfzUEyB0JDCIF0zYgHbuHLWDWATE+159swKm59J99SHhmJPuxeoc9GTBss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299778; c=relaxed/simple; bh=lVkshSq2H/RLKQFG0I1EnJWH6DEH67LjzmDESbXIr7E=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GEP60TRtElkBGprJv6/avIMfjWC27GP5OMGvEmriDX8nFEaWeAhgfEOtDst7XlCiMNZWIASieCfRxZ+QcmXQpGd9DcmXFBi2wTZi1J3rcjXcNlUge0dMS7XNop21sb8jWufQRXJW1iYAyU19Sj3oPODMMZS0aIiQRmHBPkD86gU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hCwhVdKM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hCwhVdKM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17973C32786; Tue, 30 Jul 2024 00:36:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299778; bh=lVkshSq2H/RLKQFG0I1EnJWH6DEH67LjzmDESbXIr7E=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=hCwhVdKM8b3C7nn86FExcYjEDYI/oDLMwmnM13IaamdWsWqzt3jQ0mh9fsgCVd+8/ A970WpL7csoZM90r/M+NNrjuYxSZGkWtWlVNfAw/+hOC542+DfXd/zvDIY2zvFRF6s nc2FrcIIWmb7I0/cVLzJjUP/AOmlrSYAUmRMhX7vbDgEF/8owWAgLbR8I97gJvyDar 61QoHxE0k4eiKtR99j86B2JxX55Yy2CJEIRXxlI0ohOcFuedmC34CI7WE8DHOzVvix HHOGhhKJ1dcPJ5+qFZbgYrfYm2LdM28i17Q5ly4YshlHqoAju6rficituaOBdCrhy+ uOnzckOvLK/Vg== Date: Mon, 29 Jul 2024 17:36:17 -0700 Subject: [PATCH 048/115] xfs: restructure xfs_attr_complete_op a bit From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843118.1338752.15209002659168190448.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 992c3b5c3fe6f42778436649ddae2b7a2984b7aa Eliminate the local variable from this function so that we can streamline things a bit later when we add the PPTR_REPLACE op code. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 8e9e23836..26674116f 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -430,14 +430,13 @@ xfs_attr_complete_op( enum xfs_delattr_state replace_state) { struct xfs_da_args *args = attr->xattri_da_args; - bool do_replace = args->op_flags & XFS_DA_OP_REPLACE; + + if (!(args->op_flags & XFS_DA_OP_REPLACE)) + replace_state = XFS_DAS_DONE; args->op_flags &= ~XFS_DA_OP_REPLACE; args->attr_filter &= ~XFS_ATTR_INCOMPLETE; - if (do_replace) - return replace_state; - - return XFS_DAS_DONE; + return replace_state; } static int From patchwork Tue Jul 30 00:36:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D809979CF for ; Tue, 30 Jul 2024 00:36:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299793; cv=none; b=m+RYJpM1geLG+mF6x6wZi48clyIzK47Ms+UpC4uUe5AO2YmKZiTgi53nV1BeTOEvLIVCKVx2f7E9z7dOYvB42jSgUCmn8Ric5/8vM7DnXREC8GdyOGULfYRichS8yDKq9ixOJ4a8lozHzvkaWYNUZX83KJjHmsJPvhcU3Rx8YLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299793; c=relaxed/simple; bh=rjWPOZJ6I48QfdS2SZX4mNKVqOLLD1qW1zOCnXBPBlI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kqaEbHoEZrXBCSB5ucL2Li/KCF5h3TancldG20wTmzmMRcbazuLEt2xbaVKCQop3RtGuBEsFjKaBlnlNshYRfAkoJhkFaxfJ8+NyagHidNFYcWZZPTdCfRWUyjPrh3N0aR3nj3BTqFsTHcycvjOEE58tV55lIC4aS86YSdE0Bo0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ru/LRkkw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ru/LRkkw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A15A4C4AF0C; Tue, 30 Jul 2024 00:36:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299793; bh=rjWPOZJ6I48QfdS2SZX4mNKVqOLLD1qW1zOCnXBPBlI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Ru/LRkkwYfytB4XVoOeAw35jVuVWZdzcjdVF1BM0llNekv7HgL2aE0OvkJzQpn0MQ 5YEwGN3AwNRAEVzmeGJzmdlm3g5BhQ/mJ1p7MfC7CdUVuhmlz4zQsOOIG5QBFj6NsA /3exsdqw9U6ZsNpnPjerwVs/T1OPx5nPh+KbaYVt1TbLxG+Hhv14fRmRTnUiFE/nd0 ac6ta+aXYoHvqyteR0FIULca346gSiTwd0EnHMqQ2Qdxo4abaFqIHo5sg4v8tpkLmG 3+yeAbkX6dWbLNgUEgi9oYo9EPUgXTYMDIGIfTSLXttStMLItgnqkgM8DzQC/dXThD RN+7Qr4FUZs/A== Date: Mon, 29 Jul 2024 17:36:33 -0700 Subject: [PATCH 049/115] xfs: use helpers to extract xattr op from opflags From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843132.1338752.3256960158984018031.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 2a2c05d013d0562076ec475a6deb0991ce1942ca Create helper functions to extract the xattr op from the ondisk xattri log item and the incore attr intent item. These will get more use in the patches that follow. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h index c8005f521..79b457adb 100644 --- a/libxfs/xfs_attr.h +++ b/libxfs/xfs_attr.h @@ -529,6 +529,11 @@ struct xfs_attr_intent { struct xfs_bmbt_irec xattri_map; }; +static inline unsigned int +xfs_attr_intent_op(const struct xfs_attr_intent *attr) +{ + return attr->xattri_op_flags & XFS_ATTRI_OP_FLAGS_TYPE_MASK; +} /*======================================================================== * Function prototypes for the kernel. From patchwork Tue Jul 30 00:36:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745971 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 74E337E6 for ; Tue, 30 Jul 2024 00:36:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299809; cv=none; b=DEO7NQrsL4riJ0gsBeQ0x3qBQwJWbVnhCee2qOSFxZzGDw12GMsXCx7NmsfbQsP/X5py4iPRUJqETfQzz/LtoPdhbeLQUrGjaFpbmZ7ve/1hnSW5k9WoMHurFXEb9sXxxRldNHtB4Uh1LYaYB969PVizXb0y9vWFC0DW1QDxFe4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299809; c=relaxed/simple; bh=kznIQn03GW4iUBzT1SRW8t8Nh3TDd5dtxqsyUsM6rMk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QACRgv3DbDBpr1c3OzmQDt/U1wQlhi2vZ42/6wlZLlRO04OQw3O76xX71ecTmVHQFMw65kSgou2Fn9PYlsnC2k7Q1BWVrZCaYJt9VogU0VH+2SMZ4mFIQMIqS5DiWmyOr4JmpK/mEl7j9bHG0e+w8QRcl2+tarNq1lvjNWXJCTk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MAiXKqKu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MAiXKqKu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B3E7C32786; Tue, 30 Jul 2024 00:36:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299809; bh=kznIQn03GW4iUBzT1SRW8t8Nh3TDd5dtxqsyUsM6rMk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=MAiXKqKuBUuaxLYrXG+KEmh8bm3e3lgdg379VBUEzsDEX+68hRnStML9YooYuDl9s pOAiGTDZFonGTX/tsssDgQvsHCbNn/qSvJraZrl48q+ZFJWf+rR+mBpLRi8yNs2X3u WGomIeykZ7a6a25FeAC6eiAf5wrU0kf5viRqmkR9cK1YwrvVdKmUVTFdF+pq+us0Gw lvZUA7d7bPlCl0NvR+UMSKP04S1SwEE+kitoXt2JvAcMC+Y76PR/WiqLOg39oL6dk0 TGIIOUEjrLPALAL7zJd5471PhNz+oN97PPLpr6dbMpg3JXPTgKzRPQ8yomsuRAM9AE jahKRxWaP6u7A== Date: Mon, 29 Jul 2024 17:36:48 -0700 Subject: [PATCH 050/115] xfs: enforce one namespace per attribute From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843146.1338752.1900296936921253423.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: ea0b3e814741fb64e7785b564ea619578058e0b0 Create a standardized helper function to enforce one namespace bit per extended attribute, and refactor all the open-coded hweight logic. This function is not a static inline to avoid porting hassles in userspace. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr.c | 11 +++++++++++ libxfs/xfs_attr.h | 4 +++- libxfs/xfs_attr_leaf.c | 7 ++++++- repair/attr_repair.c | 7 ++++--- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 26674116f..e0a3bc702 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -1530,12 +1530,23 @@ xfs_attr_node_get( return error; } +/* Enforce that there is at most one namespace bit per attr. */ +inline bool xfs_attr_check_namespace(unsigned int attr_flags) +{ + return hweight32(attr_flags & XFS_ATTR_NSP_ONDISK_MASK) < 2; +} + /* Returns true if the attribute entry name is valid. */ bool xfs_attr_namecheck( + unsigned int attr_flags, const void *name, size_t length) { + /* Only one namespace bit allowed. */ + if (!xfs_attr_check_namespace(attr_flags)) + return false; + /* * MAXNAMELEN includes the trailing null, but (name/length) leave it * out, so use >= for the length check. diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h index 79b457adb..cd106b0a4 100644 --- a/libxfs/xfs_attr.h +++ b/libxfs/xfs_attr.h @@ -560,7 +560,9 @@ enum xfs_attr_update { int xfs_attr_set(struct xfs_da_args *args, enum xfs_attr_update op); int xfs_attr_set_iter(struct xfs_attr_intent *attr); int xfs_attr_remove_iter(struct xfs_attr_intent *attr); -bool xfs_attr_namecheck(const void *name, size_t length); +bool xfs_attr_check_namespace(unsigned int attr_flags); +bool xfs_attr_namecheck(unsigned int attr_flags, const void *name, + size_t length); int xfs_attr_calc_size(struct xfs_da_args *args, int *local); void xfs_init_attr_trans(struct xfs_da_args *args, struct xfs_trans_res *tres, unsigned int *total); diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index 47f2836fb..346f0127d 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -947,6 +947,11 @@ xfs_attr_shortform_to_leaf( nargs.hashval = xfs_da_hashname(sfe->nameval, sfe->namelen); nargs.attr_filter = sfe->flags & XFS_ATTR_NSP_ONDISK_MASK; + if (!xfs_attr_check_namespace(sfe->flags)) { + xfs_da_mark_sick(args); + error = -EFSCORRUPTED; + goto out; + } error = xfs_attr3_leaf_lookup_int(bp, &nargs); /* set a->index */ ASSERT(error == -ENOATTR); error = xfs_attr3_leaf_add(bp, &nargs); @@ -1060,7 +1065,7 @@ xfs_attr_shortform_verify( * one namespace flag per xattr, so we can just count the * bits (i.e. hweight) here. */ - if (hweight8(sfep->flags & XFS_ATTR_NSP_ONDISK_MASK) > 1) + if (!xfs_attr_check_namespace(sfep->flags)) return __this_address; sfep = next_sfep; diff --git a/repair/attr_repair.c b/repair/attr_repair.c index 206a97d66..0f2f7a284 100644 --- a/repair/attr_repair.c +++ b/repair/attr_repair.c @@ -292,7 +292,8 @@ process_shortform_attr( } /* namecheck checks for null chars in attr names. */ - if (!libxfs_attr_namecheck(currententry->nameval, + if (!libxfs_attr_namecheck(currententry->flags, + currententry->nameval, currententry->namelen)) { do_warn( _("entry contains illegal character in shortform attribute name\n")); @@ -473,7 +474,7 @@ process_leaf_attr_local( local = xfs_attr3_leaf_name_local(leaf, i); if (local->namelen == 0 || - !libxfs_attr_namecheck(local->nameval, + !libxfs_attr_namecheck(entry->flags, local->nameval, local->namelen)) { do_warn( _("attribute entry %d in attr block %u, inode %" PRIu64 " has bad name (namelen = %d)\n"), @@ -529,7 +530,7 @@ process_leaf_attr_remote( remotep = xfs_attr3_leaf_name_remote(leaf, i); if (remotep->namelen == 0 || - !libxfs_attr_namecheck(remotep->name, + !libxfs_attr_namecheck(entry->flags, remotep->name, remotep->namelen) || be32_to_cpu(entry->hashval) != libxfs_da_hashname((unsigned char *)&remotep->name[0], From patchwork Tue Jul 30 00:37:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745972 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2576A7E6 for ; Tue, 30 Jul 2024 00:37:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299825; cv=none; b=RMSqrWib6mMNubArAfd7Vu1c/9dJvc8+NXR+hLy1brIfzM4j/EMZdIV1owJm5sJP88aIxhW2h585guhi8RKnh4nyiSxUwj1e8nlxTDAn6iwDt7NOo6o27ebaesJsDYTmJ+iYYFSIQXql0T899MooT1bvWkUEVXHWCY2OiA2CQc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299825; c=relaxed/simple; bh=J2MBeUrcJJzJdgMsZ992i3srKB0G+bMVO9JppJTk6AU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MTm/4aVQ7f+iypCZVNaJEMXvsfs8mwtY7D1xbN6REK7pWb8PgqYPER1i2IAr1ENC+6QDUuxZaaWYyHdCc5TZPVDP5zHzmeTS19/htzRxHwqI2+woRNvVF9LuVLtIMYRpGKQXnCZjheeYabhpsHdlyt4+rgSDBIHjY5Yc5CK8iDI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SlE2NXnG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SlE2NXnG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00AD6C32786; Tue, 30 Jul 2024 00:37:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299825; bh=J2MBeUrcJJzJdgMsZ992i3srKB0G+bMVO9JppJTk6AU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=SlE2NXnG5Lgv7pH1TVmJfLz5ryjeOTNYmoE/2zipz3hlkx1WVpZ8mN4Bbg98zW3Rj NBwejJtNbArmrTJ4A4ZxOKvnXGHdvNi9DsdPgHLMQkndbnwBRTDIKDsXvggkh7LhA3 QcWnQhNohqF/obfM73lX7/wXXukuua0IKCEOFByrsuBArbIkPgazsN26aaoL8w/AJm 4nL1bUgHc4DunwvgBmuXTVbHXu7tlec5W3CBRsNN5CMbdRhORxZnCMRBGdeSlHsRHO dBZ8VRJdLqstyB9o3F8UHF0zAs0lFWX8t+xrwb3voKWPchWkl7yjpE06Rz507P7Uap mOj8UIzAi0U5A== Date: Mon, 29 Jul 2024 17:37:04 -0700 Subject: [PATCH 051/115] xfs: rearrange xfs_attr_match parameters From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843160.1338752.10235040469343834149.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 63211876ced33fbb730f515e8d830de53533fc82 Rearrange the parameters to this function so that they match the order of attr listent: attr_flags -> name -> namelen -> value -> valuelen. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr_leaf.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index 346f0127d..a3859961f 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -507,9 +507,9 @@ xfs_attr3_leaf_read( static bool xfs_attr_match( struct xfs_da_args *args, - uint8_t namelen, - unsigned char *name, - int flags) + unsigned int attr_flags, + const unsigned char *name, + unsigned int namelen) { if (args->namelen != namelen) @@ -519,12 +519,12 @@ xfs_attr_match( /* Recovery ignores the INCOMPLETE flag. */ if ((args->op_flags & XFS_DA_OP_RECOVERY) && - args->attr_filter == (flags & XFS_ATTR_NSP_ONDISK_MASK)) + args->attr_filter == (attr_flags & XFS_ATTR_NSP_ONDISK_MASK)) return true; /* All remaining matches need to be filtered by INCOMPLETE state. */ if (args->attr_filter != - (flags & (XFS_ATTR_NSP_ONDISK_MASK | XFS_ATTR_INCOMPLETE))) + (attr_flags & (XFS_ATTR_NSP_ONDISK_MASK | XFS_ATTR_INCOMPLETE))) return false; return true; } @@ -743,8 +743,8 @@ xfs_attr_sf_findname( for (sfe = xfs_attr_sf_firstentry(sf); sfe < xfs_attr_sf_endptr(sf); sfe = xfs_attr_sf_nextentry(sfe)) { - if (xfs_attr_match(args, sfe->namelen, sfe->nameval, - sfe->flags)) + if (xfs_attr_match(args, sfe->flags, sfe->nameval, + sfe->namelen)) return sfe; } @@ -2440,15 +2440,16 @@ xfs_attr3_leaf_lookup_int( */ if (entry->flags & XFS_ATTR_LOCAL) { name_loc = xfs_attr3_leaf_name_local(leaf, probe); - if (!xfs_attr_match(args, name_loc->namelen, - name_loc->nameval, entry->flags)) + if (!xfs_attr_match(args, entry->flags, + name_loc->nameval, + name_loc->namelen)) continue; args->index = probe; return -EEXIST; } else { name_rmt = xfs_attr3_leaf_name_remote(leaf, probe); - if (!xfs_attr_match(args, name_rmt->namelen, - name_rmt->name, entry->flags)) + if (!xfs_attr_match(args, entry->flags, name_rmt->name, + name_rmt->namelen)) continue; args->index = probe; args->rmtvaluelen = be32_to_cpu(name_rmt->valuelen); From patchwork Tue Jul 30 00:37:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745973 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C8F567E6 for ; Tue, 30 Jul 2024 00:37:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299840; cv=none; b=oXMZrq2wSMBXpXzqmtphfdO3FHsw1rfhge3Gqp2IkOgzOPY8Yq9SVz1hOtFyu6mri+9jkAUuxuWyfE+3AihqiWhh4Zgq1A9ADE8f8aUocJqA2IJjPvhxZOt9a60N42nRBq3SX/mVP+0H6/wtOwfreI1jT/0YXREMx+rXXMDjjPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299840; c=relaxed/simple; bh=7glL9aW38A9R83IPn2CaVH54n9cz4mk+fNRMeq9y4QE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lLGMAPMeo/CDvkfhiHe1loHCxjr0mMoFVOG+5tfKltnpa7BWuboTRDSQW7Hw9bCIYANLiHZgouAxJ03QPsCn9BVQYsIROZBv9fWe3UpnQHIXBjV3nSIXshQpM/ZYLf/oYj9IFgFUetmXizP/OGxhlfsdbq+e2rPs1n6+CCoDvEU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hB3vQboJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hB3vQboJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5AADC32786; Tue, 30 Jul 2024 00:37:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299840; bh=7glL9aW38A9R83IPn2CaVH54n9cz4mk+fNRMeq9y4QE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=hB3vQboJpge/ltYp8Yk72qQP+Xw2wWOBuVGheoht9gBGZjtL1juO0RxHiNC7Almiu 4hKLnIos0zh/BHIDhekbw/y1rnqVOm8LOcFBlFB/u0vOXP9wyS+JRoJiS4eViQmnHA qnqRZ2elRQY8btw6qt/rFgdpBl8hj949sXqCHCvMhPsTHEFEUdvZ5sjc+sFf7ikVQl 997ayJ4aZCtSX++vTYxsJufe74mwBsid8IiVZ5/bfQnw1u/HMrdghGr08BFZ95AiB4 1XVRlVSZQc7Vxo8e74Zl2YdUAzHGPC+6djdYlzFgRW9CJcBBk14f72R9MrgjxVdWGz WP1b/j1xorU6w== Date: Mon, 29 Jul 2024 17:37:20 -0700 Subject: [PATCH 052/115] xfs: check the flags earlier in xfs_attr_match From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843173.1338752.12803574115243320131.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: f49af061f49c004fb6df7f791f39f9ed370f767b Checking the flags match is much cheaper than a memcmp, so do it early on in xfs_attr_match, and also add a little helper to calculate the match mask right under the comment explaining the logic for it. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- libxfs/xfs_attr_leaf.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index a3859961f..c6322fbd2 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -504,6 +504,13 @@ xfs_attr3_leaf_read( * INCOMPLETE flag will not be set in attr->attr_filter, but rather * XFS_DA_OP_RECOVERY will be set in args->op_flags. */ +static inline unsigned int xfs_attr_match_mask(const struct xfs_da_args *args) +{ + if (args->op_flags & XFS_DA_OP_RECOVERY) + return XFS_ATTR_NSP_ONDISK_MASK; + return XFS_ATTR_NSP_ONDISK_MASK | XFS_ATTR_INCOMPLETE; +} + static bool xfs_attr_match( struct xfs_da_args *args, @@ -511,21 +518,15 @@ xfs_attr_match( const unsigned char *name, unsigned int namelen) { + unsigned int mask = xfs_attr_match_mask(args); if (args->namelen != namelen) return false; + if ((args->attr_filter & mask) != (attr_flags & mask)) + return false; if (memcmp(args->name, name, namelen) != 0) return false; - /* Recovery ignores the INCOMPLETE flag. */ - if ((args->op_flags & XFS_DA_OP_RECOVERY) && - args->attr_filter == (attr_flags & XFS_ATTR_NSP_ONDISK_MASK)) - return true; - - /* All remaining matches need to be filtered by INCOMPLETE state. */ - if (args->attr_filter != - (attr_flags & (XFS_ATTR_NSP_ONDISK_MASK | XFS_ATTR_INCOMPLETE))) - return false; return true; } From patchwork Tue Jul 30 00:37:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745974 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6E36110E3 for ; Tue, 30 Jul 2024 00:37:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299856; cv=none; b=S5Ur6OPG/F+75lraBO+6/zt9iCqO5SIts0u4XXUAjLdJR44EgcmLPkxwIurMcHxDD8WbIsFNX1XpPLobqywsg4OWbbg3ClxQp/X+cfjU+FIY3GdbSbI/92MoGTT3Cp5iHyy+S86FS+vHpcnxQWcqyFMMS/EURaCB09p0sWDLRmQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299856; c=relaxed/simple; bh=ExmV9iTl5uDhIj3X34lOrx7MWLwDzQRusxZYxf7np00=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Tm/Oi5hYf/+uyCxXnYFrJKUCQPvxSiwXIR3Psakwl148Ytgyf9jQbh+oFa58gwT5fPuV3rSSE8rhxhl0piSoDYN4gs//ZVTOhNKzL9WGdxnXXQOe2jbhKdnKrcID6BxLnNIejHW7aK6rGAxb1i0i+T6JDLCATR/SYPJsFoGPVgc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QKKAQI88; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QKKAQI88" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DCF9C32786; Tue, 30 Jul 2024 00:37:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299856; bh=ExmV9iTl5uDhIj3X34lOrx7MWLwDzQRusxZYxf7np00=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=QKKAQI88nBr2HmYskMIMmef3s92geDS6wLhgmnKh+WgqW37DoQpqdrE5TH84K+ofy SuNXJuZ5fca5WE7TSPSx4L9n4lqfwbsUIWRe5Q6X4QWkq8/MCEDBjxv88pKDLIJK4k K4QND1DgB0Q++sKCpTMeBuPSdNOugZ9zyvREp6VqHdXndgCWmKxKbmnDJuroizDNKB C61X17trP9xafq5INYrzzM0gdRUElxCHO37DAJgr13Vs+bK3aH53YuxBTq0hmQY9m7 pYjPx1rWNdAp7z1NjkWrtlwO2VSSybmXxg42xCiIGFbOVIS+TGpDzQtWascmiP6/46 7Tkms3rKXt7mg== Date: Mon, 29 Jul 2024 17:37:35 -0700 Subject: [PATCH 053/115] xfs: move xfs_attr_defer_add to xfs_attr_item.c From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843188.1338752.4667514580772658424.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 9713dc88773d066413ae23aa474b13241507a89e Move the code that adds the incore xfs_attr_item deferred work data to a transaction live with the ATTRI log item code. This means that the upper level extended attribute code no longer has to know about the inner workings of the ATTRI log items. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/defer_item.c | 28 ++++++++++++++++++++++++++++ libxfs/defer_item.h | 8 ++++++++ libxfs/xfs_attr.c | 38 ++++---------------------------------- 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/libxfs/defer_item.c b/libxfs/defer_item.c index fd329e77c..9955e189d 100644 --- a/libxfs/defer_item.c +++ b/libxfs/defer_item.c @@ -670,6 +670,34 @@ xfs_attr_cancel_item( xfs_attr_free_item(attr); } +void +xfs_attr_defer_add( + struct xfs_da_args *args, + enum xfs_attr_defer_op op) +{ + struct xfs_attr_intent *new; + + new = kmem_cache_zalloc(xfs_attr_intent_cache, GFP_NOFS | __GFP_NOFAIL); + new->xattri_da_args = args; + + switch (op) { + case XFS_ATTR_DEFER_SET: + new->xattri_op_flags = XFS_ATTRI_OP_FLAGS_SET; + new->xattri_dela_state = xfs_attr_init_add_state(args); + break; + case XFS_ATTR_DEFER_REPLACE: + new->xattri_op_flags = XFS_ATTRI_OP_FLAGS_REPLACE; + new->xattri_dela_state = xfs_attr_init_replace_state(args); + break; + case XFS_ATTR_DEFER_REMOVE: + new->xattri_op_flags = XFS_ATTRI_OP_FLAGS_REMOVE; + new->xattri_dela_state = xfs_attr_init_remove_state(args); + break; + } + + xfs_defer_add(args->trans, &new->xattri_list, &xfs_attr_defer_type); +} + const struct xfs_defer_op_type xfs_attr_defer_type = { .name = "attr", .max_items = 1, diff --git a/libxfs/defer_item.h b/libxfs/defer_item.h index a5a07867c..df2b8d68b 100644 --- a/libxfs/defer_item.h +++ b/libxfs/defer_item.h @@ -10,6 +10,14 @@ struct xfs_bmap_intent; void xfs_bmap_defer_add(struct xfs_trans *tp, struct xfs_bmap_intent *bi); +enum xfs_attr_defer_op { + XFS_ATTR_DEFER_SET, + XFS_ATTR_DEFER_REMOVE, + XFS_ATTR_DEFER_REPLACE, +}; + +void xfs_attr_defer_add(struct xfs_da_args *args, enum xfs_attr_defer_op op); + struct xfs_exchmaps_intent; void xfs_exchmaps_defer_add(struct xfs_trans *tp, diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index e0a3bc702..7f64d8a2e 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -24,6 +24,7 @@ #include "xfs_quota_defs.h" #include "xfs_trans_space.h" #include "xfs_trace.h" +#include "defer_item.h" struct kmem_cache *xfs_attr_intent_cache; @@ -899,37 +900,6 @@ xfs_attr_lookup( return error; } -static void -xfs_attr_defer_add( - struct xfs_da_args *args, - unsigned int op_flags) -{ - - struct xfs_attr_intent *new; - - new = kmem_cache_zalloc(xfs_attr_intent_cache, - GFP_KERNEL | __GFP_NOFAIL); - new->xattri_op_flags = op_flags; - new->xattri_da_args = args; - - switch (op_flags) { - case XFS_ATTRI_OP_FLAGS_SET: - new->xattri_dela_state = xfs_attr_init_add_state(args); - break; - case XFS_ATTRI_OP_FLAGS_REPLACE: - new->xattri_dela_state = xfs_attr_init_replace_state(args); - break; - case XFS_ATTRI_OP_FLAGS_REMOVE: - new->xattri_dela_state = xfs_attr_init_remove_state(args); - break; - default: - ASSERT(0); - } - - xfs_defer_add(args->trans, &new->xattri_list, &xfs_attr_defer_type); - trace_xfs_attr_defer_add(new->xattri_dela_state, args->dp); -} - int xfs_attr_set( struct xfs_da_args *args, @@ -1019,14 +989,14 @@ xfs_attr_set( case -EEXIST: if (op == XFS_ATTRUPDATE_REMOVE) { /* if no value, we are performing a remove operation */ - xfs_attr_defer_add(args, XFS_ATTRI_OP_FLAGS_REMOVE); + xfs_attr_defer_add(args, XFS_ATTR_DEFER_REMOVE); break; } /* Pure create fails if the attr already exists */ if (op == XFS_ATTRUPDATE_CREATE) goto out_trans_cancel; - xfs_attr_defer_add(args, XFS_ATTRI_OP_FLAGS_REPLACE); + xfs_attr_defer_add(args, XFS_ATTR_DEFER_REPLACE); break; case -ENOATTR: /* Can't remove what isn't there. */ @@ -1036,7 +1006,7 @@ xfs_attr_set( /* Pure replace fails if no existing attr to replace. */ if (op == XFS_ATTRUPDATE_REPLACE) goto out_trans_cancel; - xfs_attr_defer_add(args, XFS_ATTRI_OP_FLAGS_SET); + xfs_attr_defer_add(args, XFS_ATTR_DEFER_SET); break; default: goto out_trans_cancel; From patchwork Tue Jul 30 00:37:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745975 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 258B01361 for ; Tue, 30 Jul 2024 00:37:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299872; cv=none; b=RztQCnEVdK8AWCV+G0EmMi/IQ8s9HoGY5Gfb+/yVF6RoOlKV1nVkn4Odft/q/hsxV1+H5JGLujkk9caNsANwNC02BwLzXZ9Z9gVEfhBcaWlf7E/7+wZgHm0KvMHEBRIt6JCRlHe8tcZQVmcN4WOeOMv7nWkhTSJkuniiNEjKa3U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299872; c=relaxed/simple; bh=kcN9N7hUoFackDZ7SfFUoTbWScuCFSHxDSRTCrwFWRs=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KQgncTQtB8w5ig8GzzFLX3AEuzwlvu2zWURQd2dFD+boh7PJ6iI5prqJr5ciSBP5r3Poasgjbv/1yFguQ+UMpJ3SBE69C5iToKx8yzsKjB/2Io6hCGcQxgWrrktH2z8nicoCeIxG/LzVt2hq3osQEbsSNcx6NoUM/fQN9ET3tLI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hjNDt6h9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hjNDt6h9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA4EFC32786; Tue, 30 Jul 2024 00:37:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299872; bh=kcN9N7hUoFackDZ7SfFUoTbWScuCFSHxDSRTCrwFWRs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=hjNDt6h96BlmEHuJa/+Bl/g/H+tWd42qy4m5aqctkoq0+ai5yTLoIAlMvr4Emqrpb UO3S4p+d3f2tz1t0GufqjripzBDnRsCoOw72EIVCCgOG9cSH+HQth8m3CCH6ObEpIs 0LcuFTY357nazq910vBgS2mngFxMZ4LkyYD/gvQVbSd6vvy5GwkZeQ0Ai5vjuA/r+L hlJhzsmUa4+/fmzxlNxevRcNWW2X26T8F6/UrehyZIozSC2MVA8KaZNxrLodfMQcWA 3kpGDbMamn6vAzyYZFsK0XuedCT67Z+bss+bZeoQXO/wSeDyKXiKpXW2NZe19c1x0g pOKK93evvLkiw== Date: Mon, 29 Jul 2024 17:37:51 -0700 Subject: [PATCH 054/115] xfs: create a separate hashname function for extended attributes From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843202.1338752.2387705314321279846.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: a64e0134754bf88021e937aa34f1fbb5b524e585 Create a separate function to compute name hashvalues for extended attributes. When we get to parent pointers we'll be altering the rules so that metadump obfuscation doesn't turn heinous. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr.c | 28 ++++++++++++++++++++++++++-- libxfs/xfs_attr.h | 14 ++++++++++++++ libxfs/xfs_attr_leaf.c | 3 +-- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 7f64d8a2e..91e7961c2 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -279,7 +279,7 @@ xfs_attr_get( args->owner = args->dp->i_ino; args->geo = args->dp->i_mount->m_attr_geo; args->whichfork = XFS_ATTR_FORK; - args->hashval = xfs_da_hashname(args->name, args->namelen); + xfs_attr_sethash(args); /* Entirely possible to look up a name which doesn't exist */ args->op_flags = XFS_DA_OP_OKNOENT; @@ -414,6 +414,30 @@ xfs_attr_sf_addname( return error; } +/* Compute the hash value for a user/root/secure extended attribute */ +xfs_dahash_t +xfs_attr_hashname( + const uint8_t *name, + int namelen) +{ + return xfs_da_hashname(name, namelen); +} + +/* Compute the hash value for any extended attribute from any namespace. */ +xfs_dahash_t +xfs_attr_hashval( + struct xfs_mount *mp, + unsigned int attr_flags, + const uint8_t *name, + int namelen, + const void *value, + int valuelen) +{ + ASSERT(xfs_attr_check_namespace(attr_flags)); + + return xfs_attr_hashname(name, namelen); +} + /* * Handle the state change on completion of a multi-state attr operation. * @@ -924,7 +948,7 @@ xfs_attr_set( args->owner = args->dp->i_ino; args->geo = mp->m_attr_geo; args->whichfork = XFS_ATTR_FORK; - args->hashval = xfs_da_hashname(args->name, args->namelen); + xfs_attr_sethash(args); /* * We have no control over the attribute names that userspace passes us diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h index cd106b0a4..c63b1d610 100644 --- a/libxfs/xfs_attr.h +++ b/libxfs/xfs_attr.h @@ -628,6 +628,20 @@ xfs_attr_init_replace_state(struct xfs_da_args *args) return xfs_attr_init_add_state(args); } +xfs_dahash_t xfs_attr_hashname(const uint8_t *name, int namelen); + +xfs_dahash_t xfs_attr_hashval(struct xfs_mount *mp, unsigned int attr_flags, + const uint8_t *name, int namelen, const void *value, + int valuelen); + +/* Set the hash value for any extended attribute from any namespace. */ +static inline void xfs_attr_sethash(struct xfs_da_args *args) +{ + args->hashval = xfs_attr_hashval(args->dp->i_mount, args->attr_filter, + args->name, args->namelen, + args->value, args->valuelen); +} + extern struct kmem_cache *xfs_attr_intent_cache; int __init xfs_attr_intent_init_cache(void); void xfs_attr_intent_destroy_cache(void); diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index c6322fbd2..212347bc3 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -945,14 +945,13 @@ xfs_attr_shortform_to_leaf( nargs.namelen = sfe->namelen; nargs.value = &sfe->nameval[nargs.namelen]; nargs.valuelen = sfe->valuelen; - nargs.hashval = xfs_da_hashname(sfe->nameval, - sfe->namelen); nargs.attr_filter = sfe->flags & XFS_ATTR_NSP_ONDISK_MASK; if (!xfs_attr_check_namespace(sfe->flags)) { xfs_da_mark_sick(args); error = -EFSCORRUPTED; goto out; } + xfs_attr_sethash(&nargs); error = xfs_attr3_leaf_lookup_int(bp, &nargs); /* set a->index */ ASSERT(error == -ENOATTR); error = xfs_attr3_leaf_add(bp, &nargs); From patchwork Tue Jul 30 00:38:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745976 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C8B49184E for ; Tue, 30 Jul 2024 00:38:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299887; cv=none; b=UOd+a1HoZn+E4ADwcVlssgVYJWny1IWMkyYZq1kSnOaMZsM0fphFrmDWGXdKfOk74g2/dskc0C3PGiKX3/rZ4Zenh1YUna1PN1XLnpbQDk/1V59d+Ikg2dIuRrDTljxpcsD24MasmYWFvgVt5GmLzFaLaJF8+dQ8LUGX9iHqTKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299887; c=relaxed/simple; bh=7So8USdXZMqNeGqjuaTWyEbBipxHe+YA2GVwoE1/cZk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=a5T9QYPAtJQLOQaIFw4G4ayMRlfNysjwpxQtSP0bXPU/1D3MFuNp8M6hf+ok3wRx+zHtrre113IJ+UcdFFHETieRxxzSoz3sWJs5NhYLXrqpn6jqSPbE12aYwON4o6hr8mvqT4+chb4RcNFFrM8K7VyA5I9QZ/FHLNsQv98OThA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YyhmR5Ob; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YyhmR5Ob" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E29FC32786; Tue, 30 Jul 2024 00:38:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299887; bh=7So8USdXZMqNeGqjuaTWyEbBipxHe+YA2GVwoE1/cZk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=YyhmR5ObisuXVU7lmhwa6XA/0QYDMJxFDfOokXwZ9S4EzGUdf9xm1893AFO82CTLJ QJzwcD+MSRi3YIcp8fYUr38nvhJ5GuzzoDCe60LrBzqingJWJM+OYVHBOywrQ2Ke2w IEvoD1RPY1mBOtqvBS6QPz4ziFeguGd7a0rzsmjWkbuy+lBQ2a1LR9ESyipi2opd5l Ca2VfP3t+q/fAZo/zYQqPr34XNrHhNovH1QTZxlPCvTwoz9LJYBnUarz4tncMF2Ubm pWSmSHb/S+mdl7AmLRU23Q6n5mn9oWT5sWF2B+hB2dbJkTPtbe1AW7+XzaUXKiF20B 3kOqQbyWfCMVg== Date: Mon, 29 Jul 2024 17:38:07 -0700 Subject: [PATCH 055/115] xfs: add parent pointer support to attribute code From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Mark Tinguely , Dave Chinner , Allison Henderson , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843217.1338752.13633317236906999474.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Allison Henderson Source kernel commit: 98493ff878859eb0adefbc57a49ad47a92dfd252 Add the new parent attribute type. XFS_ATTR_PARENT is used only for parent pointer entries; it uses reserved blocks like XFS_ATTR_ROOT. Signed-off-by: Mark Tinguely Signed-off-by: Dave Chinner Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_da_format.h | 9 +++++++-- libxfs/xfs_log_format.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_da_format.h b/libxfs/xfs_da_format.h index ecd0616f5..0c80f7ab9 100644 --- a/libxfs/xfs_da_format.h +++ b/libxfs/xfs_da_format.h @@ -714,13 +714,17 @@ struct xfs_attr3_leafblock { #define XFS_ATTR_LOCAL_BIT 0 /* attr is stored locally */ #define XFS_ATTR_ROOT_BIT 1 /* limit access to trusted attrs */ #define XFS_ATTR_SECURE_BIT 2 /* limit access to secure attrs */ +#define XFS_ATTR_PARENT_BIT 3 /* parent pointer attrs */ #define XFS_ATTR_INCOMPLETE_BIT 7 /* attr in middle of create/delete */ #define XFS_ATTR_LOCAL (1u << XFS_ATTR_LOCAL_BIT) #define XFS_ATTR_ROOT (1u << XFS_ATTR_ROOT_BIT) #define XFS_ATTR_SECURE (1u << XFS_ATTR_SECURE_BIT) +#define XFS_ATTR_PARENT (1u << XFS_ATTR_PARENT_BIT) #define XFS_ATTR_INCOMPLETE (1u << XFS_ATTR_INCOMPLETE_BIT) -#define XFS_ATTR_NSP_ONDISK_MASK (XFS_ATTR_ROOT | XFS_ATTR_SECURE) +#define XFS_ATTR_NSP_ONDISK_MASK (XFS_ATTR_ROOT | \ + XFS_ATTR_SECURE | \ + XFS_ATTR_PARENT) #define XFS_ATTR_ONDISK_MASK (XFS_ATTR_NSP_ONDISK_MASK | \ XFS_ATTR_LOCAL | \ @@ -729,7 +733,8 @@ struct xfs_attr3_leafblock { #define XFS_ATTR_NAMESPACE_STR \ { XFS_ATTR_LOCAL, "local" }, \ { XFS_ATTR_ROOT, "root" }, \ - { XFS_ATTR_SECURE, "secure" } + { XFS_ATTR_SECURE, "secure" }, \ + { XFS_ATTR_PARENT, "parent" } /* * Alignment for namelist and valuelist entries (since they are mixed diff --git a/libxfs/xfs_log_format.h b/libxfs/xfs_log_format.h index accba2acd..020aebd10 100644 --- a/libxfs/xfs_log_format.h +++ b/libxfs/xfs_log_format.h @@ -1034,6 +1034,7 @@ struct xfs_icreate_log { */ #define XFS_ATTRI_FILTER_MASK (XFS_ATTR_ROOT | \ XFS_ATTR_SECURE | \ + XFS_ATTR_PARENT | \ XFS_ATTR_INCOMPLETE) /* From patchwork Tue Jul 30 00:38:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745977 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C90FA6FD0 for ; Tue, 30 Jul 2024 00:38:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299903; cv=none; b=KtntO6lSJM48JdMNvk3XvUqZQ4FLngjPYP1udHUeIRQmqC7HL40nb3/+v6qqOWxjMnGazi4LBPNqIsFmgeB6P96W4ozKQzIuokwBbTKCX//ZYXyxwXkB5rqS+8HL5/zcGyStdO+QVEDN4n3t6DNZt++J3LJxyt9NP/50yVFW+XE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299903; c=relaxed/simple; bh=1aQffbD5DMoCKiXNSwwNkCZVxemNMrJY/ACPZMlKFnU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LXxYZog2lScEMeJVqE56/IdJLZHSqPIyIX8klHNNuq4W+2f6GxSIdg8BhT9NvBRyjOCtQUSYGvHwaHH9L9SfMXoGaOfZkDjh/0T7/TXuUCsJSnJ82oxUPSa3X0TsM1BlpG2hSk0o7qYMxcPjlBr4O0DgiK5agCq3CoV/ahqg+6Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VbndFcwr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VbndFcwr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 493D8C32786; Tue, 30 Jul 2024 00:38:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299903; bh=1aQffbD5DMoCKiXNSwwNkCZVxemNMrJY/ACPZMlKFnU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=VbndFcwredBWmZUodSfjCkfAVQEK4aZtAsRTqty2MPklyymP4016W8Un0kxL/8F99 J/cW65aNz9nef1+mFj28CaDr0SXdni54+lJs4QlPHrLerCe906hr2gIlGsNuart+YV bCa8yPUkThiOPgm1teWrRseBvG24foYfAahYTS7Ipt3AkWdTPwUHyg4Mx39alo2QTa KTVLQpJzRdJtO8iBmq657uApGheHI9tfUeVcHnpFaJBZ58Uulj1X0PHMt8XKKWJsyT AKrVzNgorXQc80mwmW59u4zQdg88XaOQUbJ0eE1cJ44ER0MnPw+5xdnBmVpZYb5UiM V2bp0jOVDCR/A== Date: Mon, 29 Jul 2024 17:38:22 -0700 Subject: [PATCH 056/115] xfs: define parent pointer ondisk extended attribute format From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Allison Henderson , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843231.1338752.8854547612082746685.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Allison Henderson Source kernel commit: 8337d58ab2868f231a29824cd86d2e309bd36fa9 We need to define the parent pointer attribute format before we start adding support for it into all the code that needs to use it. The EA format we will use encodes the following information: name={dirent name} value={parent inumber, parent inode generation} hash=xfs_dir2_hashname(dirent name) ^ (parent_inumber) The inode/gen gives all the information we need to reliably identify the parent without requiring child->parent lock ordering, and allows userspace to do pathname component level reconstruction without the kernel ever needing to verify the parent itself as part of ioctl calls. By using the name-value lookup mode in the extended attribute code to match parent pointers using both the xattr name and value, we can identify the exact parent pointer EA we need to modify/remove in rename/unlink operations without searching the entire EA space. By storing the dirent name, we have enough information to be able to validate and reconstruct damaged directory trees. Earlier iterations of this patchset encoded the directory offset in the parent pointer key, but this format required repair to keep that in sync across directory rebuilds, which is unnecessary complexity. Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_da_format.h | 13 +++++++++++++ libxfs/xfs_ondisk.h | 1 + 2 files changed, 14 insertions(+) diff --git a/libxfs/xfs_da_format.h b/libxfs/xfs_da_format.h index 0c80f7ab9..1395ad193 100644 --- a/libxfs/xfs_da_format.h +++ b/libxfs/xfs_da_format.h @@ -890,4 +890,17 @@ static inline unsigned int xfs_dir2_dirblock_bytes(struct xfs_sb *sbp) xfs_failaddr_t xfs_da3_blkinfo_verify(struct xfs_buf *bp, struct xfs_da3_blkinfo *hdr3); +/* + * Parent pointer attribute format definition + * + * The xattr name contains the dirent name. + * The xattr value encodes the parent inode number and generation to ease + * opening parents by handle. + * The xattr hashval is xfs_dir2_namehash() ^ p_ino + */ +struct xfs_parent_rec { + __be64 p_ino; + __be32 p_gen; +} __packed; + #endif /* __XFS_DA_FORMAT_H__ */ diff --git a/libxfs/xfs_ondisk.h b/libxfs/xfs_ondisk.h index 81885a6a0..25952ef58 100644 --- a/libxfs/xfs_ondisk.h +++ b/libxfs/xfs_ondisk.h @@ -119,6 +119,7 @@ xfs_check_ondisk_structs(void) XFS_CHECK_OFFSET(xfs_dir2_sf_entry_t, offset, 1); XFS_CHECK_OFFSET(xfs_dir2_sf_entry_t, name, 3); XFS_CHECK_STRUCT_SIZE(xfs_dir2_sf_hdr_t, 10); + XFS_CHECK_STRUCT_SIZE(struct xfs_parent_rec, 12); /* log structures */ XFS_CHECK_STRUCT_SIZE(struct xfs_buf_log_format, 88); From patchwork Tue Jul 30 00:38:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745978 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 911ED8BE8 for ; Tue, 30 Jul 2024 00:38:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299919; cv=none; b=qA29r6zRIu9zKkFR2vpQ1KqUj5V0cdk1A83N2aMeU9/2F6V75YAUjpE5etIsfFYLPdHbforOZ17MiqO6RsKeA0XYHwnyIrSjBsxIrQIM/Lrjh0QWZGptLNhdDVnlBwhEnLBTVEt5k8NfLC+mqH6zzV+N3Nt+/0/ZItbOjtOuxKg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299919; c=relaxed/simple; bh=wTovikacywMZ6yZbvy4tUoJndCl8FQI5q9+btLPw1N8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EyKUPuqt+GKAMrJeWsGa2PA5S3TO/zv3dHPjH/3HUluWeYuSQnysCyjQbJ57lWb1zIYf7Q8qmoH/2NWmuBaxOp5nVjzLBKlxw3lN1UuoU8MedRD7LsJ3GSYhC7gxZUuCQo8Gn7L8kICqQ8w9PCIP9nkY0I82hEePbS959n6Z7to= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gGDuSGtZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gGDuSGtZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF8ABC32786; Tue, 30 Jul 2024 00:38:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299919; bh=wTovikacywMZ6yZbvy4tUoJndCl8FQI5q9+btLPw1N8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=gGDuSGtZPDG4zmFXqLePtRgM6oEHulHLvoNQzz/zDZ/H1zo7W6Cpy2isliNIrqwVk VvY2q41hQ4mBWztCGORqtHLG5f3XfLgSP3dzyyFUPCRua36zKWBATJZ8RkWOtNyCUZ wtc9xLM/hXAf6uTvIku5A3HO9jDDYke+Dq9utjsCz6CBQaUtWPE6hJYoD4LQroZgYH nPCoCsAq/L32t5GXniiK8LTc6d81zrIitwjYa6lbEN8n5qoxhDH47ZMXMVI8pq24mo JOl7tplaUIheyz2p4+2tAO9lx9+oHvIfRKRoeziGAlhqjVrlnHCo6RZO4uS+SKgmco ce4wm3Xt/gbug== Date: Mon, 29 Jul 2024 17:38:38 -0700 Subject: [PATCH 057/115] xfs: allow xattr matching on name and value for parent pointers From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843245.1338752.14701764237875926851.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: f041455eb5773eda3291903ad6d1f33d4798e9a2 If a file is hardlinked with the same name but from multiple parents, the parent pointers will all have the same dirent name (== attr name) but with different parent_ino/parent_gen values. To disambiguate, we need to be able to match on both the attr name and the attr value. This is in contrast to regular xattrs, which are matchtg edit d only on name. Therefore, plumb in the ability to match shortform and local attrs on name and value in the XFS_ATTR_PARENT namespace. Parent pointer attr values are never large enough to be stored in a remote attr, so we need can reject these cases as corruption. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr_leaf.c | 52 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index 212347bc3..faa357f15 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -511,12 +511,37 @@ static inline unsigned int xfs_attr_match_mask(const struct xfs_da_args *args) return XFS_ATTR_NSP_ONDISK_MASK | XFS_ATTR_INCOMPLETE; } +static inline bool +xfs_attr_parent_match( + const struct xfs_da_args *args, + const void *value, + unsigned int valuelen) +{ + ASSERT(args->value != NULL); + + /* Parent pointers do not use remote values */ + if (!value) + return false; + + /* + * The only value we support is a parent rec. However, we'll accept + * any valuelen so that offline repair can delete ATTR_PARENT values + * that are not parent pointers. + */ + if (valuelen != args->valuelen) + return false; + + return memcmp(args->value, value, valuelen) == 0; +} + static bool xfs_attr_match( struct xfs_da_args *args, unsigned int attr_flags, const unsigned char *name, - unsigned int namelen) + unsigned int namelen, + const void *value, + unsigned int valuelen) { unsigned int mask = xfs_attr_match_mask(args); @@ -527,6 +552,9 @@ xfs_attr_match( if (memcmp(args->name, name, namelen) != 0) return false; + if (attr_flags & XFS_ATTR_PARENT) + return xfs_attr_parent_match(args, value, valuelen); + return true; } @@ -536,6 +564,13 @@ xfs_attr_copy_value( unsigned char *value, int valuelen) { + /* + * Parent pointer lookups require the caller to specify the name and + * value, so don't copy anything. + */ + if (args->attr_filter & XFS_ATTR_PARENT) + return 0; + /* * No copy if all we have to do is get the length */ @@ -745,7 +780,8 @@ xfs_attr_sf_findname( sfe < xfs_attr_sf_endptr(sf); sfe = xfs_attr_sf_nextentry(sfe)) { if (xfs_attr_match(args, sfe->flags, sfe->nameval, - sfe->namelen)) + sfe->namelen, &sfe->nameval[sfe->namelen], + sfe->valuelen)) return sfe; } @@ -2441,18 +2477,22 @@ xfs_attr3_leaf_lookup_int( if (entry->flags & XFS_ATTR_LOCAL) { name_loc = xfs_attr3_leaf_name_local(leaf, probe); if (!xfs_attr_match(args, entry->flags, - name_loc->nameval, - name_loc->namelen)) + name_loc->nameval, name_loc->namelen, + &name_loc->nameval[name_loc->namelen], + be16_to_cpu(name_loc->valuelen))) continue; args->index = probe; return -EEXIST; } else { + unsigned int valuelen; + name_rmt = xfs_attr3_leaf_name_remote(leaf, probe); + valuelen = be32_to_cpu(name_rmt->valuelen); if (!xfs_attr_match(args, entry->flags, name_rmt->name, - name_rmt->namelen)) + name_rmt->namelen, NULL, valuelen)) continue; args->index = probe; - args->rmtvaluelen = be32_to_cpu(name_rmt->valuelen); + args->rmtvaluelen = valuelen; args->rmtblkno = be32_to_cpu(name_rmt->valueblk); args->rmtblkcnt = xfs_attr3_rmt_blocks( args->dp->i_mount, From patchwork Tue Jul 30 00:38:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745979 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 14B937E6 for ; Tue, 30 Jul 2024 00:38:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299935; cv=none; b=H3JdV18aZESluMc0pkjbuvBEQ/WlkmNODcGQdYPbF7q2I7OMP196PdrPAbiEAYlgaQ6uQXVDQ44kiFODMWmXPPwEbQhRFus6P837W7YHskamk63/9UHKDG1FvnNxJN/yyXcQHSU5Eb+7GpkTB29GI7DJUEuqQR6KR/lOo3zSlT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299935; c=relaxed/simple; bh=FWUPqFOfmJEeSLsTiw/jAjjLb0bvwxa/4o6ecg65KBo=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZRrl+6GJpmfcwo2FcDo+5Y8Y3ybVQlcVOFb6NYuFin+DeXgAnJFbWvBytL6kyTseFJ5RB1hnaP3BrV+BbfhSljHsN3RiGqBcqpz69g6BRfUAR32PzHMcJch98B8p88U7GM5CuLjvBB4Tts3/Bolaz7lvGpsOllcdk533C0XbqPM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dDdhghbl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dDdhghbl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A31A5C32786; Tue, 30 Jul 2024 00:38:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299934; bh=FWUPqFOfmJEeSLsTiw/jAjjLb0bvwxa/4o6ecg65KBo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=dDdhghblav5Q0APhbJl6xJW1wn/kfjxdO0/8RMTmxr8gq+ObKdHeV9jBfGuI2ocPL 6m3DXre6k8J+OQwkEmPuZ9CgGMjCtj8GQim4LwVhYFmdwfmZSP0B/iKIbzmr36mC66 ZeBFvWmjSYQ3TgYm8e3jhGSkBEmcfq9Jv5ClMZ8OlkSngLF84pfXQTR/mbVJdvjYqn VtapNie2thbEsxrZr3yS+dh49mjQmfQ6abiudXPJQ+IP6TntD26c7wWmrsH0xqEGtC h9rvmGtwMUQwnvKyyvwHXagQLHwqKWS3T5IrMKJgqv1SEz6wXVZ11rmYeGI2Z9AAC4 6y/u2lcAEhvpA== Date: Mon, 29 Jul 2024 17:38:54 -0700 Subject: [PATCH 058/115] xfs: create attr log item opcodes and formats for parent pointers From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843259.1338752.7080239945946535934.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 5773f7f82be5aa98e4883566072d33342814cebe Make the necessary alterations to the extended attribute log intent item ondisk format so that we can log parent pointer operations. This requires the creation of new opcodes specific to parent pointers, and a new four-argument replace operation to handle renames. At this point this part of the patchset has changed so much from what Allison original wrote that I no longer think her SoB applies. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr.c | 19 +++++++++++++++++++ libxfs/xfs_attr.h | 4 ++-- libxfs/xfs_da_btree.h | 4 ++++ libxfs/xfs_log_format.h | 22 +++++++++++++++++++--- 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 91e7961c2..c67cdc77a 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -438,6 +438,23 @@ xfs_attr_hashval( return xfs_attr_hashname(name, namelen); } +/* + * PPTR_REPLACE operations require the caller to set the old and new names and + * values explicitly. Update the canonical fields to the new name and value + * here now that the removal phase has finished. + */ +static void +xfs_attr_update_pptr_replace_args( + struct xfs_da_args *args) +{ + ASSERT(args->new_namelen > 0); + args->name = args->new_name; + args->namelen = args->new_namelen; + args->value = args->new_value; + args->valuelen = args->new_valuelen; + xfs_attr_sethash(args); +} + /* * Handle the state change on completion of a multi-state attr operation. * @@ -458,6 +475,8 @@ xfs_attr_complete_op( if (!(args->op_flags & XFS_DA_OP_REPLACE)) replace_state = XFS_DAS_DONE; + else if (xfs_attr_intent_op(attr) == XFS_ATTRI_OP_FLAGS_PPTR_REPLACE) + xfs_attr_update_pptr_replace_args(args); args->op_flags &= ~XFS_DA_OP_REPLACE; args->attr_filter &= ~XFS_ATTR_INCOMPLETE; diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h index c63b1d610..d0ed7ea58 100644 --- a/libxfs/xfs_attr.h +++ b/libxfs/xfs_attr.h @@ -510,8 +510,8 @@ struct xfs_attr_intent { struct xfs_da_args *xattri_da_args; /* - * Shared buffer containing the attr name and value so that the logging - * code can share large memory buffers between log items. + * Shared buffer containing the attr name, new name, and value so that + * the logging code can share large memory buffers between log items. */ struct xfs_attri_log_nameval *xattri_nameval; diff --git a/libxfs/xfs_da_btree.h b/libxfs/xfs_da_btree.h index 17cef594b..354d5d650 100644 --- a/libxfs/xfs_da_btree.h +++ b/libxfs/xfs_da_btree.h @@ -55,7 +55,9 @@ enum xfs_dacmp { typedef struct xfs_da_args { struct xfs_da_geometry *geo; /* da block geometry */ const uint8_t *name; /* string (maybe not NULL terminated) */ + const uint8_t *new_name; /* new attr name */ void *value; /* set of bytes (maybe contain NULLs) */ + void *new_value; /* new xattr value (may contain NULLs) */ struct xfs_inode *dp; /* directory inode to manipulate */ struct xfs_trans *trans; /* current trans (changes over time) */ @@ -63,10 +65,12 @@ typedef struct xfs_da_args { xfs_ino_t owner; /* inode that owns the dir/attr data */ int valuelen; /* length of value */ + int new_valuelen; /* length of new_value */ uint8_t filetype; /* filetype of inode for directories */ uint8_t op_flags; /* operation flags */ uint8_t attr_filter; /* XFS_ATTR_{ROOT,SECURE,INCOMPLETE} */ short namelen; /* length of string (maybe no NULL) */ + short new_namelen; /* length of new attr name */ xfs_dahash_t hashval; /* hash value of name */ xfs_extlen_t total; /* total blocks needed, for 1st bmap */ int whichfork; /* data or attribute fork */ diff --git a/libxfs/xfs_log_format.h b/libxfs/xfs_log_format.h index 020aebd10..632dd9732 100644 --- a/libxfs/xfs_log_format.h +++ b/libxfs/xfs_log_format.h @@ -115,11 +115,13 @@ struct xfs_unmount_log_format { #define XLOG_REG_TYPE_BUD_FORMAT 26 #define XLOG_REG_TYPE_ATTRI_FORMAT 27 #define XLOG_REG_TYPE_ATTRD_FORMAT 28 -#define XLOG_REG_TYPE_ATTR_NAME 29 +#define XLOG_REG_TYPE_ATTR_NAME 29 #define XLOG_REG_TYPE_ATTR_VALUE 30 #define XLOG_REG_TYPE_XMI_FORMAT 31 #define XLOG_REG_TYPE_XMD_FORMAT 32 -#define XLOG_REG_TYPE_MAX 32 +#define XLOG_REG_TYPE_ATTR_NEWNAME 33 +#define XLOG_REG_TYPE_ATTR_NEWVALUE 34 +#define XLOG_REG_TYPE_MAX 34 /* * Flags to log operation header @@ -1026,6 +1028,9 @@ struct xfs_icreate_log { #define XFS_ATTRI_OP_FLAGS_SET 1 /* Set the attribute */ #define XFS_ATTRI_OP_FLAGS_REMOVE 2 /* Remove the attribute */ #define XFS_ATTRI_OP_FLAGS_REPLACE 3 /* Replace the attribute */ +#define XFS_ATTRI_OP_FLAGS_PPTR_SET 4 /* Set parent pointer */ +#define XFS_ATTRI_OP_FLAGS_PPTR_REMOVE 5 /* Remove parent pointer */ +#define XFS_ATTRI_OP_FLAGS_PPTR_REPLACE 6 /* Replace parent pointer */ #define XFS_ATTRI_OP_FLAGS_TYPE_MASK 0xFF /* Flags type mask */ /* @@ -1048,7 +1053,18 @@ struct xfs_attri_log_format { uint64_t alfi_id; /* attri identifier */ uint64_t alfi_ino; /* the inode for this attr operation */ uint32_t alfi_op_flags; /* marks the op as a set or remove */ - uint32_t alfi_name_len; /* attr name length */ + union { + uint32_t alfi_name_len; /* attr name length */ + struct { + /* + * For PPTR_REPLACE, these are the lengths of the old + * and new attr names. The new and old values must + * have the same length. + */ + uint16_t alfi_old_name_len; + uint16_t alfi_new_name_len; + }; + }; uint32_t alfi_value_len; /* attr value length */ uint32_t alfi_attr_filter;/* attr filter flags */ }; From patchwork Tue Jul 30 00:39:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745980 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 766E410E3 for ; Tue, 30 Jul 2024 00:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299950; cv=none; b=QxMYWnhN2rAsdSHRBcg8mVPVFDoj+Nh5Xi/89G4cB4Q20It7icOTc6WRFYxMUN3shO/C+cUDL686UEcFp791p7vm2QeSsH3DBzCYtOfx1sMf2yr8TgkEYfEqBaQtQ0Xq2vitEcSyi7a9V6r6YSiFFy22I1C7mhQVM6ZZwe2Iuso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299950; c=relaxed/simple; bh=3+pKoZQjLt/xLVUBXLyXVTAhNOikciOmHkfLJQ/NvCk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SmYEWmNWDgdxtzI2yWcE4wgHRpb2E7RntxxhgMZxpPpYGIFIMaMXgirqtt4lDBh7XY+JRApziB9SOjrivonAQXyEtT72eFrVw/dUUl8Zw2AEjMm+rjuqk9JYFV4dLk9kfZftD5lBU3a41giNE1sffzmGWm3W6emVyDX+4r0i3cA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MVn7SK9P; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MVn7SK9P" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F0DCC32786; Tue, 30 Jul 2024 00:39:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299950; bh=3+pKoZQjLt/xLVUBXLyXVTAhNOikciOmHkfLJQ/NvCk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=MVn7SK9Pn3v40+FZYbz1qMjVoSG7tcDWQ+Zgwv2oaRSzrUl/IQUVjdcEyB5h6zPL0 qmb1nyk2uuwI2FdbhEuZ9Y/5f4cQ6jCDRvV1siyWmIIO0sTaWQ0Bprv5oe02PZxoDA rxebE6paDS6a5skXBamPuJ1YP7ZMIUnTss5PS0bMtHoa3W8JZgAyk9ZH8qtUyPiBtm g0njVSBZp1P8/nrRlagIbHbcErgdCfgwLISAkhPrUIV/mdV4XrK2cJC8qJACWEMGN7 b4WyJxdgaTx9PS5IPY6gDii4rlpr1klUARRpL0DSmOkvHUg7+GgezDtT6UVmMH/Zc+ M/5SUqtA0FFwg== Date: Mon, 29 Jul 2024 17:39:09 -0700 Subject: [PATCH 059/115] xfs: record inode generation in xattr update log intent items From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843274.1338752.7824640779877837531.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: ae673f534a30976ce5e709c4535a59c12b786ef3 For parent pointer updates, record the i_generation of the file that is being updated so that we don't accidentally jump generations. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_log_format.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libxfs/xfs_log_format.h b/libxfs/xfs_log_format.h index 632dd9732..3e6682ed6 100644 --- a/libxfs/xfs_log_format.h +++ b/libxfs/xfs_log_format.h @@ -1049,7 +1049,7 @@ struct xfs_icreate_log { struct xfs_attri_log_format { uint16_t alfi_type; /* attri log item type */ uint16_t alfi_size; /* size of this item */ - uint32_t __pad; /* pad to 64 bit aligned */ + uint32_t alfi_igen; /* generation of alfi_ino for pptr ops */ uint64_t alfi_id; /* attri identifier */ uint64_t alfi_ino; /* the inode for this attr operation */ uint32_t alfi_op_flags; /* marks the op as a set or remove */ From patchwork Tue Jul 30 00:39:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745981 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 759021361 for ; Tue, 30 Jul 2024 00:39:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299966; cv=none; b=cnBRli1DH6Br3FoynOKAY+FuDRcJs0DT04GX41VDWohkwb8H+TTMBY+bikXT7xY/7kfLlA/+jMYzvNwO8VX3N75iKR2H7MnjJsd7XQFfOvwliTEV0hn7ynl1tsvJed5ZIc2LTpxzW3QV4o9nTw8W5o1gcsH8YJEjcVNZLpG9p0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299966; c=relaxed/simple; bh=MKa1Le1cKv9Q8IEIAFIP0M+NPQijZpleg8tdJoWfSjA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QsU3FqsSmtdfNQWh22jmRkFisjP8tm3uXJpGDppkHz/xpRjinkefN4NzCBFK/3C5Ul/jaKjWc9lvKMtyYQT8wyDZklAfgPLreiMFRNrsKFY79JMMx5oGdkp/HdrAi8IglzALF0rqwMX6VzicYD0rN8n1VObmvjxuPs4AUSEUroQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p890uh6t; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="p890uh6t" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0454C32786; Tue, 30 Jul 2024 00:39:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299966; bh=MKa1Le1cKv9Q8IEIAFIP0M+NPQijZpleg8tdJoWfSjA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=p890uh6tWm9Ou0dseCAwx1o/IVcpC/n/H+egofu6yBt3CmhIWR1XOfXXNk3aS2ZhR riAvk12XjDIf20Nhw6INlJ8cTPdgz2jTjMJav+eI8qHijWoQ+YO7qZmVOiwkhYWPN5 Ph//vq6DGiG1mn7IjuLe0h0I+c0ktBhGggal3QZf/Hd+9DjNrf+VGwZslOuX/v60m/ 9UmM3l3mbw0o91kbv+BroOpAjWYmbH+uF3o5mbIqQK2FF7DHXEkM8LbWQGN1LsugnG Eh1dhvFUD+vJPRcHYPLbCZ2uS+fVc768SrSJJeoLPKH65s4nY7FFLZhSC/1YYk/IKr O7Kr5HBtQQCtw== Date: Mon, 29 Jul 2024 17:39:25 -0700 Subject: [PATCH 060/115] xfs: add parent pointer validator functions From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Allison Henderson , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843288.1338752.5025682908444979644.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Allison Henderson Source kernel commit: a08d6729637428b6ef8c6a5a94d8c6db7b805a44 The attr name of a parent pointer is a string, and the attr value of a parent pointer is (more or less) a file handle. So we need to modify attr_namecheck to verify the parent pointer name, and add a xfs_parent_valuecheck function to sanitize the handle. At the same time, we need to validate attr values during log recovery if the xattr is really a parent pointer. Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong [djwong: move functions to xfs_parent.c, adjust for new disk format] Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/Makefile | 2 + libxfs/xfs_attr.c | 5 +++ libxfs/xfs_parent.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_parent.h | 15 +++++++++ 4 files changed, 111 insertions(+) create mode 100644 libxfs/xfs_parent.c create mode 100644 libxfs/xfs_parent.h diff --git a/libxfs/Makefile b/libxfs/Makefile index e3fa18fee..2a5cead9a 100644 --- a/libxfs/Makefile +++ b/libxfs/Makefile @@ -50,6 +50,7 @@ HFILES = \ xfs_ialloc_btree.h \ xfs_inode_buf.h \ xfs_inode_fork.h \ + xfs_parent.h \ xfs_quota_defs.h \ xfs_refcount.h \ xfs_refcount_btree.h \ @@ -102,6 +103,7 @@ CFILES = buf_mem.c \ xfs_inode_fork.c \ xfs_ialloc_btree.c \ xfs_log_rlimit.c \ + xfs_parent.c \ xfs_refcount.c \ xfs_refcount_btree.c \ xfs_rmap.c \ diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index c67cdc77a..345132921 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -25,6 +25,7 @@ #include "xfs_trans_space.h" #include "xfs_trace.h" #include "defer_item.h" +#include "xfs_parent.h" struct kmem_cache *xfs_attr_intent_cache; @@ -1567,6 +1568,10 @@ xfs_attr_namecheck( if (length >= MAXNAMELEN) return false; + /* Parent pointers have their own validation. */ + if (attr_flags & XFS_ATTR_PARENT) + return xfs_parent_namecheck(attr_flags, name, length); + /* There shouldn't be any nulls here */ return !memchr(name, 0, length); } diff --git a/libxfs/xfs_parent.c b/libxfs/xfs_parent.c new file mode 100644 index 000000000..50da527b6 --- /dev/null +++ b/libxfs/xfs_parent.c @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Oracle. + * All rights reserved. + */ +#include "libxfs_priv.h" +#include "xfs_fs.h" +#include "xfs_format.h" +#include "xfs_da_format.h" +#include "xfs_log_format.h" +#include "xfs_shared.h" +#include "xfs_trans_resv.h" +#include "xfs_mount.h" +#include "xfs_bmap_btree.h" +#include "xfs_inode.h" +#include "xfs_trace.h" +#include "xfs_trans.h" +#include "xfs_da_btree.h" +#include "xfs_attr.h" +#include "xfs_dir2.h" +#include "xfs_dir2_priv.h" +#include "xfs_attr_sf.h" +#include "xfs_bmap.h" +#include "xfs_defer.h" +#include "xfs_parent.h" +#include "xfs_trans_space.h" + +/* + * Parent pointer attribute handling. + * + * Because the attribute name is a filename component, it will never be longer + * than 255 bytes and must not contain nulls or slashes. These are roughly the + * same constraints that apply to attribute names. + * + * The attribute value must always be a struct xfs_parent_rec. This means the + * attribute will never be in remote format because 12 bytes is nowhere near + * xfs_attr_leaf_entsize_local_max() (~75% of block size). + * + * Creating a new parent attribute will always create a new attribute - there + * should never, ever be an existing attribute in the tree for a new inode. + * ENOSPC behavior is problematic - creating the inode without the parent + * pointer is effectively a corruption, so we allow parent attribute creation + * to dip into the reserve block pool to avoid unexpected ENOSPC errors from + * occurring. + */ + +/* Return true if parent pointer attr name is valid. */ +bool +xfs_parent_namecheck( + unsigned int attr_flags, + const void *name, + size_t length) +{ + /* + * Parent pointers always use logged operations, so there should never + * be incomplete xattrs. + */ + if (attr_flags & XFS_ATTR_INCOMPLETE) + return false; + + return xfs_dir2_namecheck(name, length); +} + +/* Return true if parent pointer attr value is valid. */ +bool +xfs_parent_valuecheck( + struct xfs_mount *mp, + const void *value, + size_t valuelen) +{ + const struct xfs_parent_rec *rec = value; + + if (!xfs_has_parent(mp)) + return false; + + /* The xattr value must be a parent record. */ + if (valuelen != sizeof(struct xfs_parent_rec)) + return false; + + /* The parent record must be local. */ + if (value == NULL) + return false; + + /* The parent inumber must be valid. */ + if (!xfs_verify_dir_ino(mp, be64_to_cpu(rec->p_ino))) + return false; + + return true; +} diff --git a/libxfs/xfs_parent.h b/libxfs/xfs_parent.h new file mode 100644 index 000000000..ef8aff860 --- /dev/null +++ b/libxfs/xfs_parent.h @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Oracle. + * All Rights Reserved. + */ +#ifndef __XFS_PARENT_H__ +#define __XFS_PARENT_H__ + +/* Metadata validators */ +bool xfs_parent_namecheck(unsigned int attr_flags, const void *name, + size_t length); +bool xfs_parent_valuecheck(struct xfs_mount *mp, const void *value, + size_t valuelen); + +#endif /* __XFS_PARENT_H__ */ From patchwork Tue Jul 30 00:39:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745982 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C35E217D2 for ; Tue, 30 Jul 2024 00:39:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299981; cv=none; b=WJbwuqo1C1qKV+M0AGTABtCB5wvjpvc/zluOE4E932WI/opCfeBY0PPFm/3VdbwtC48/yhEC0CsCVV9SKl4GEqHhPHSw+FKOpj4ppJXoVUhdVxGgxHI6YvJJTDxSqbp/Tf8gPY91gx5QtXtMP/fpmLJe/jbj3qrFCuFBDKA5zJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299981; c=relaxed/simple; bh=T2oQpGV2XmxLfv/1/6emXN+afA++O6V/RYvm4qIfL6U=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GFRITj3DckIEGFYtnpjCIg7q8qFt3G2xIfxRJUCoT1KCneJ0i/xnfRKUDyOiBA677P/02SjPc7vG0CMeVPh2JrkG22PggEuaSbQr9gBf1lLj1kAaZ1vCnS9WdaCPfpcj7xksk+R1y76EV8JHtDUwekDCmhD1FcpSVXLMWZK1j+c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VN3xeqG1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VN3xeqG1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99C46C32786; Tue, 30 Jul 2024 00:39:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299981; bh=T2oQpGV2XmxLfv/1/6emXN+afA++O6V/RYvm4qIfL6U=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=VN3xeqG11x/r8ERFT+nyDQITWvdpbEuh8uF1L3ktKgnzT1+97ECijT3OdwPNeZ7ls yJmd5S+HMscxgOTCmSWxZhISaraZUpgsoQqoM6EzYsIn154Zip34K6dKTV/MgcZiZa vwte7cMzcww7r8RZSG1fFXglghHWZ1bxFhN2OQPsRCqWHvRG6jouFw8X5ZMqIyUXe5 mtmRfcgNPau6Mz8/wcZVqD9Spn7CLf+r5wnlQakgBEdqb0p0OB5KCvMyfL1EfhwrGH gat2uA9HBuD1mo2jqgTQIlvTTiG+jH/4bWc+W0AxFT4FEQidfc6ZRAaADvZdSRuKX9 KmWsZDRhb77Tw== Date: Mon, 29 Jul 2024 17:39:41 -0700 Subject: [PATCH 061/115] xfs: extend transaction reservations for parent attributes From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Dave Chinner , Allison Henderson , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843302.1338752.15945632063641569278.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Allison Henderson Source kernel commit: 7dba4a5fe1c5cdf0859830380c52f29295cbf345 We need to add, remove or modify parent pointer attributes during create/link/unlink/rename operations atomically with the dirents in the parent directories being modified. This means they need to be modified in the same transaction as the parent directories, and so we need to add the required space for the attribute modifications to the transaction reservations. Signed-off-by: Dave Chinner Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong [djwong: fix indenting errors, adjust for new log format] Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/libxfs_priv.h | 1 libxfs/xfs_trans_resv.c | 324 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 273 insertions(+), 52 deletions(-) diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index cfe96b05a..4136b277f 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -492,6 +492,7 @@ static inline int retzero(void) { return 0; } #define xfs_icreate_log(tp, agno, agbno, cnt, isize, len, gen) ((void) 0) #define xfs_sb_validate_fsb_count(sbp, nblks) (0) +#define xlog_calc_iovec_len(len) roundup(len, sizeof(uint32_t)) /* * Prototypes for kernel static functions that are aren't in their diff --git a/libxfs/xfs_trans_resv.c b/libxfs/xfs_trans_resv.c index 82b3d1522..dc405a943 100644 --- a/libxfs/xfs_trans_resv.c +++ b/libxfs/xfs_trans_resv.c @@ -19,6 +19,7 @@ #include "xfs_trans_space.h" #include "xfs_quota_defs.h" #include "xfs_rtbitmap.h" +#include "xfs_da_format.h" #define _ALLOC true #define _FREE false @@ -421,29 +422,110 @@ xfs_calc_itruncate_reservation_minlogsize( return xfs_calc_itruncate_reservation(mp, true); } +static inline unsigned int xfs_calc_pptr_link_overhead(void) +{ + return sizeof(struct xfs_attri_log_format) + + xlog_calc_iovec_len(sizeof(struct xfs_parent_rec)) + + xlog_calc_iovec_len(MAXNAMELEN - 1); +} +static inline unsigned int xfs_calc_pptr_unlink_overhead(void) +{ + return sizeof(struct xfs_attri_log_format) + + xlog_calc_iovec_len(sizeof(struct xfs_parent_rec)) + + xlog_calc_iovec_len(MAXNAMELEN - 1); +} +static inline unsigned int xfs_calc_pptr_replace_overhead(void) +{ + return sizeof(struct xfs_attri_log_format) + + xlog_calc_iovec_len(sizeof(struct xfs_parent_rec)) + + xlog_calc_iovec_len(MAXNAMELEN - 1) + + xlog_calc_iovec_len(sizeof(struct xfs_parent_rec)) + + xlog_calc_iovec_len(MAXNAMELEN - 1); +} + /* * In renaming a files we can modify: * the five inodes involved: 5 * inode size * the two directory btrees: 2 * (max depth + v2) * dir block size * the two directory bmap btrees: 2 * max depth * block size * And the bmap_finish transaction can free dir and bmap blocks (two sets - * of bmap blocks) giving: + * of bmap blocks) giving (t2): * the agf for the ags in which the blocks live: 3 * sector size * the agfl for the ags in which the blocks live: 3 * sector size * the superblock for the free block count: sector size * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size + * If parent pointers are enabled (t3), then each transaction in the chain + * must be capable of setting or removing the extended attribute + * containing the parent information. It must also be able to handle + * the three xattr intent items that track the progress of the parent + * pointer update. */ STATIC uint xfs_calc_rename_reservation( struct xfs_mount *mp) { - return XFS_DQUOT_LOGRES(mp) + - max((xfs_calc_inode_res(mp, 5) + - xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp), - XFS_FSB_TO_B(mp, 1))), - (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) + - xfs_calc_buf_res(xfs_allocfree_block_count(mp, 3), - XFS_FSB_TO_B(mp, 1)))); + unsigned int overhead = XFS_DQUOT_LOGRES(mp); + struct xfs_trans_resv *resp = M_RES(mp); + unsigned int t1, t2, t3 = 0; + + t1 = xfs_calc_inode_res(mp, 5) + + xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp), + XFS_FSB_TO_B(mp, 1)); + + t2 = xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) + + xfs_calc_buf_res(xfs_allocfree_block_count(mp, 3), + XFS_FSB_TO_B(mp, 1)); + + if (xfs_has_parent(mp)) { + unsigned int rename_overhead, exchange_overhead; + + t3 = max(resp->tr_attrsetm.tr_logres, + resp->tr_attrrm.tr_logres); + + /* + * For a standard rename, the three xattr intent log items + * are (1) replacing the pptr for the source file; (2) + * removing the pptr on the dest file; and (3) adding a + * pptr for the whiteout file in the src dir. + * + * For an RENAME_EXCHANGE, there are two xattr intent + * items to replace the pptr for both src and dest + * files. Link counts don't change and there is no + * whiteout. + * + * In the worst case we can end up relogging all log + * intent items to allow the log tail to move ahead, so + * they become overhead added to each transaction in a + * processing chain. + */ + rename_overhead = xfs_calc_pptr_replace_overhead() + + xfs_calc_pptr_unlink_overhead() + + xfs_calc_pptr_link_overhead(); + exchange_overhead = 2 * xfs_calc_pptr_replace_overhead(); + + overhead += max(rename_overhead, exchange_overhead); + } + + return overhead + max3(t1, t2, t3); +} + +static inline unsigned int +xfs_rename_log_count( + struct xfs_mount *mp, + struct xfs_trans_resv *resp) +{ + /* One for the rename, one more for freeing blocks */ + unsigned int ret = XFS_RENAME_LOG_COUNT; + + /* + * Pre-reserve enough log reservation to handle the transaction + * rolling needed to remove or add one parent pointer. + */ + if (xfs_has_parent(mp)) + ret += max(resp->tr_attrsetm.tr_logcount, + resp->tr_attrrm.tr_logcount); + + return ret; } /* @@ -460,6 +542,23 @@ xfs_calc_iunlink_remove_reservation( 2 * M_IGEO(mp)->inode_cluster_size; } +static inline unsigned int +xfs_link_log_count( + struct xfs_mount *mp, + struct xfs_trans_resv *resp) +{ + unsigned int ret = XFS_LINK_LOG_COUNT; + + /* + * Pre-reserve enough log reservation to handle the transaction + * rolling needed to add one parent pointer. + */ + if (xfs_has_parent(mp)) + ret += resp->tr_attrsetm.tr_logcount; + + return ret; +} + /* * For creating a link to an inode: * the parent directory inode: inode size @@ -476,14 +575,23 @@ STATIC uint xfs_calc_link_reservation( struct xfs_mount *mp) { - return XFS_DQUOT_LOGRES(mp) + - xfs_calc_iunlink_remove_reservation(mp) + - max((xfs_calc_inode_res(mp, 2) + - xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), - XFS_FSB_TO_B(mp, 1))), - (xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) + - xfs_calc_buf_res(xfs_allocfree_block_count(mp, 1), - XFS_FSB_TO_B(mp, 1)))); + unsigned int overhead = XFS_DQUOT_LOGRES(mp); + struct xfs_trans_resv *resp = M_RES(mp); + unsigned int t1, t2, t3 = 0; + + overhead += xfs_calc_iunlink_remove_reservation(mp); + t1 = xfs_calc_inode_res(mp, 2) + + xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), XFS_FSB_TO_B(mp, 1)); + t2 = xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) + + xfs_calc_buf_res(xfs_allocfree_block_count(mp, 1), + XFS_FSB_TO_B(mp, 1)); + + if (xfs_has_parent(mp)) { + t3 = resp->tr_attrsetm.tr_logres; + overhead += xfs_calc_pptr_link_overhead(); + } + + return overhead + max3(t1, t2, t3); } /* @@ -498,6 +606,23 @@ xfs_calc_iunlink_add_reservation(xfs_mount_t *mp) M_IGEO(mp)->inode_cluster_size; } +static inline unsigned int +xfs_remove_log_count( + struct xfs_mount *mp, + struct xfs_trans_resv *resp) +{ + unsigned int ret = XFS_REMOVE_LOG_COUNT; + + /* + * Pre-reserve enough log reservation to handle the transaction + * rolling needed to add one parent pointer. + */ + if (xfs_has_parent(mp)) + ret += resp->tr_attrrm.tr_logcount; + + return ret; +} + /* * For removing a directory entry we can modify: * the parent directory inode: inode size @@ -514,14 +639,24 @@ STATIC uint xfs_calc_remove_reservation( struct xfs_mount *mp) { - return XFS_DQUOT_LOGRES(mp) + - xfs_calc_iunlink_add_reservation(mp) + - max((xfs_calc_inode_res(mp, 2) + - xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), - XFS_FSB_TO_B(mp, 1))), - (xfs_calc_buf_res(4, mp->m_sb.sb_sectsize) + - xfs_calc_buf_res(xfs_allocfree_block_count(mp, 2), - XFS_FSB_TO_B(mp, 1)))); + unsigned int overhead = XFS_DQUOT_LOGRES(mp); + struct xfs_trans_resv *resp = M_RES(mp); + unsigned int t1, t2, t3 = 0; + + overhead += xfs_calc_iunlink_add_reservation(mp); + + t1 = xfs_calc_inode_res(mp, 2) + + xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), XFS_FSB_TO_B(mp, 1)); + t2 = xfs_calc_buf_res(4, mp->m_sb.sb_sectsize) + + xfs_calc_buf_res(xfs_allocfree_block_count(mp, 2), + XFS_FSB_TO_B(mp, 1)); + + if (xfs_has_parent(mp)) { + t3 = resp->tr_attrrm.tr_logres; + overhead += xfs_calc_pptr_unlink_overhead(); + } + + return overhead + max3(t1, t2, t3); } /* @@ -570,12 +705,40 @@ xfs_calc_icreate_resv_alloc( xfs_calc_finobt_res(mp); } +static inline unsigned int +xfs_icreate_log_count( + struct xfs_mount *mp, + struct xfs_trans_resv *resp) +{ + unsigned int ret = XFS_CREATE_LOG_COUNT; + + /* + * Pre-reserve enough log reservation to handle the transaction + * rolling needed to add one parent pointer. + */ + if (xfs_has_parent(mp)) + ret += resp->tr_attrsetm.tr_logcount; + + return ret; +} + STATIC uint -xfs_calc_icreate_reservation(xfs_mount_t *mp) +xfs_calc_icreate_reservation( + struct xfs_mount *mp) { - return XFS_DQUOT_LOGRES(mp) + - max(xfs_calc_icreate_resv_alloc(mp), - xfs_calc_create_resv_modify(mp)); + struct xfs_trans_resv *resp = M_RES(mp); + unsigned int overhead = XFS_DQUOT_LOGRES(mp); + unsigned int t1, t2, t3 = 0; + + t1 = xfs_calc_icreate_resv_alloc(mp); + t2 = xfs_calc_create_resv_modify(mp); + + if (xfs_has_parent(mp)) { + t3 = resp->tr_attrsetm.tr_logres; + overhead += xfs_calc_pptr_link_overhead(); + } + + return overhead + max3(t1, t2, t3); } STATIC uint @@ -588,6 +751,23 @@ xfs_calc_create_tmpfile_reservation( return res + xfs_calc_iunlink_add_reservation(mp); } +static inline unsigned int +xfs_mkdir_log_count( + struct xfs_mount *mp, + struct xfs_trans_resv *resp) +{ + unsigned int ret = XFS_MKDIR_LOG_COUNT; + + /* + * Pre-reserve enough log reservation to handle the transaction + * rolling needed to add one parent pointer. + */ + if (xfs_has_parent(mp)) + ret += resp->tr_attrsetm.tr_logcount; + + return ret; +} + /* * Making a new directory is the same as creating a new file. */ @@ -598,6 +778,22 @@ xfs_calc_mkdir_reservation( return xfs_calc_icreate_reservation(mp); } +static inline unsigned int +xfs_symlink_log_count( + struct xfs_mount *mp, + struct xfs_trans_resv *resp) +{ + unsigned int ret = XFS_SYMLINK_LOG_COUNT; + + /* + * Pre-reserve enough log reservation to handle the transaction + * rolling needed to add one parent pointer. + */ + if (xfs_has_parent(mp)) + ret += resp->tr_attrsetm.tr_logcount; + + return ret; +} /* * Making a new symplink is the same as creating a new file, but @@ -910,6 +1106,52 @@ xfs_calc_sb_reservation( return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize); } +/* + * Namespace reservations. + * + * These get tricky when parent pointers are enabled as we have attribute + * modifications occurring from within these transactions. Rather than confuse + * each of these reservation calculations with the conditional attribute + * reservations, add them here in a clear and concise manner. This requires that + * the attribute reservations have already been calculated. + * + * Note that we only include the static attribute reservation here; the runtime + * reservation will have to be modified by the size of the attributes being + * added/removed/modified. See the comments on the attribute reservation + * calculations for more details. + */ +STATIC void +xfs_calc_namespace_reservations( + struct xfs_mount *mp, + struct xfs_trans_resv *resp) +{ + ASSERT(resp->tr_attrsetm.tr_logres > 0); + + resp->tr_rename.tr_logres = xfs_calc_rename_reservation(mp); + resp->tr_rename.tr_logcount = xfs_rename_log_count(mp, resp); + resp->tr_rename.tr_logflags |= XFS_TRANS_PERM_LOG_RES; + + resp->tr_link.tr_logres = xfs_calc_link_reservation(mp); + resp->tr_link.tr_logcount = xfs_link_log_count(mp, resp); + resp->tr_link.tr_logflags |= XFS_TRANS_PERM_LOG_RES; + + resp->tr_remove.tr_logres = xfs_calc_remove_reservation(mp); + resp->tr_remove.tr_logcount = xfs_remove_log_count(mp, resp); + resp->tr_remove.tr_logflags |= XFS_TRANS_PERM_LOG_RES; + + resp->tr_symlink.tr_logres = xfs_calc_symlink_reservation(mp); + resp->tr_symlink.tr_logcount = xfs_symlink_log_count(mp, resp); + resp->tr_symlink.tr_logflags |= XFS_TRANS_PERM_LOG_RES; + + resp->tr_create.tr_logres = xfs_calc_icreate_reservation(mp); + resp->tr_create.tr_logcount = xfs_icreate_log_count(mp, resp); + resp->tr_create.tr_logflags |= XFS_TRANS_PERM_LOG_RES; + + resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp); + resp->tr_mkdir.tr_logcount = xfs_mkdir_log_count(mp, resp); + resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES; +} + void xfs_trans_resv_calc( struct xfs_mount *mp, @@ -929,35 +1171,11 @@ xfs_trans_resv_calc( resp->tr_itruncate.tr_logcount = XFS_ITRUNCATE_LOG_COUNT; resp->tr_itruncate.tr_logflags |= XFS_TRANS_PERM_LOG_RES; - resp->tr_rename.tr_logres = xfs_calc_rename_reservation(mp); - resp->tr_rename.tr_logcount = XFS_RENAME_LOG_COUNT; - resp->tr_rename.tr_logflags |= XFS_TRANS_PERM_LOG_RES; - - resp->tr_link.tr_logres = xfs_calc_link_reservation(mp); - resp->tr_link.tr_logcount = XFS_LINK_LOG_COUNT; - resp->tr_link.tr_logflags |= XFS_TRANS_PERM_LOG_RES; - - resp->tr_remove.tr_logres = xfs_calc_remove_reservation(mp); - resp->tr_remove.tr_logcount = XFS_REMOVE_LOG_COUNT; - resp->tr_remove.tr_logflags |= XFS_TRANS_PERM_LOG_RES; - - resp->tr_symlink.tr_logres = xfs_calc_symlink_reservation(mp); - resp->tr_symlink.tr_logcount = XFS_SYMLINK_LOG_COUNT; - resp->tr_symlink.tr_logflags |= XFS_TRANS_PERM_LOG_RES; - - resp->tr_create.tr_logres = xfs_calc_icreate_reservation(mp); - resp->tr_create.tr_logcount = XFS_CREATE_LOG_COUNT; - resp->tr_create.tr_logflags |= XFS_TRANS_PERM_LOG_RES; - resp->tr_create_tmpfile.tr_logres = xfs_calc_create_tmpfile_reservation(mp); resp->tr_create_tmpfile.tr_logcount = XFS_CREATE_TMPFILE_LOG_COUNT; resp->tr_create_tmpfile.tr_logflags |= XFS_TRANS_PERM_LOG_RES; - resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp); - resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT; - resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES; - resp->tr_ifree.tr_logres = xfs_calc_ifree_reservation(mp); resp->tr_ifree.tr_logcount = XFS_INACTIVE_LOG_COUNT; resp->tr_ifree.tr_logflags |= XFS_TRANS_PERM_LOG_RES; @@ -987,6 +1205,8 @@ xfs_trans_resv_calc( resp->tr_qm_dqalloc.tr_logcount = XFS_WRITE_LOG_COUNT; resp->tr_qm_dqalloc.tr_logflags |= XFS_TRANS_PERM_LOG_RES; + xfs_calc_namespace_reservations(mp, resp); + /* * The following transactions are logged in logical format with * a default log count. From patchwork Tue Jul 30 00:39:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745983 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 628E033EC for ; Tue, 30 Jul 2024 00:39:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299997; cv=none; b=aTKdvwN1nUaGSb7/z3jM6hTJ8F/xMzoWqVUMsLdLMKfx2KZ7gAAfIvzdLYjPrES+RLNq4fhcZMuI7sRZDHdGmK6z594J6W0Vqnj91qOXx8RtD9uzL08fkPuFpPLVEVQkwtjGQ6R9w3VugS6sqQUuvWpM2FanEWy94puY9dOytOg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722299997; c=relaxed/simple; bh=LNp8BwzqxFwdFQ9SQbaKdudfu13qBmQTaNPzM/+M/f8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eaS72/W1Nq/LQPe32Zzyq9rcdJqmn0GktTGOEMzpkQlNlqjfw3tIow1JXSU+iFSURXQKtIHaMMYZnKkM3zhe12QI+nHzXCM00dG2c0u9BXvwqxgZ4Z/13mIzbUM7/9ayRFfTtHn2b4YQQ5FtgbqCLhfvBzD4WkMC99vgxgwmyEc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jpIu/XFE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jpIu/XFE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37D9CC4AF07; Tue, 30 Jul 2024 00:39:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722299997; bh=LNp8BwzqxFwdFQ9SQbaKdudfu13qBmQTaNPzM/+M/f8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=jpIu/XFEjJmKeYle8V9q9sn8TcUosYdjXVKXIetXgQ93WvPqKhfglXkP1ki3MoPSb r8btuRKekmXJBUQYgUnXIaKw/s2wK0hHCn3etKA7r31hp+dmrbUg/JmOAssOWW2+Nc 6lY/X1dc67rgApi8r3vYdKzDNKzPBqsQGOXiHQaXIo5OtpWMM3xJy48EMpC/ZJmLu3 wxQBK4lNhgeMOzAcaec8eTlecVztqnHyzkM7JNy87/9qHWjHKyP50an9aJez/I8zhD BuSzH4E8UerAjnPlFNQUmiiRBMJwpiYjoBW/iYsGuc0VEfkgNeEPm+AJ9bdNpvOZK3 XkNLD0MPY2nYQ== Date: Mon, 29 Jul 2024 17:39:56 -0700 Subject: [PATCH 062/115] xfs: create a hashname function for parent pointers From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843317.1338752.1319753630890554158.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: fb102fe7fe02e70f8a49cc7f74bc0769cdab2912 Although directory entry and parent pointer recordsets look very similar (name -> ino), there's one major difference between them: a file can be hardlinked from multiple parent directories with the same filename. This is common in shared container environments where a base directory tree might be hardlink-copied multiple times. IOWs the same 'ls' program might be hardlinked to multiple /srv/*/bin/ls paths. We don't want parent pointer operations to bog down on hash collisions between the same dirent name, so create a special hash function that mixes in the parent directory inode number. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/libxfs_priv.h | 18 ++++++++++++++++++ libxfs/xfs_attr.c | 3 +++ libxfs/xfs_parent.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_parent.h | 5 +++++ 4 files changed, 73 insertions(+) diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 4136b277f..023444082 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -618,4 +618,22 @@ int xfs_bmap_last_extent(struct xfs_trans *tp, struct xfs_inode *ip, /* xfs_inode.h */ #define xfs_iflags_set(ip, flags) do { } while (0) +/* linux/wordpart.h */ + +/** + * upper_32_bits - return bits 32-63 of a number + * @n: the number we're accessing + * + * A basic shift-right of a 64- or 32-bit quantity. Use this to suppress + * the "right shift count >= width of type" warning when that quantity is + * 32-bits. + */ +#define upper_32_bits(n) ((uint32_t)(((n) >> 16) >> 16)) + +/** + * lower_32_bits - return bits 0-31 of a number + * @n: the number we're accessing + */ +#define lower_32_bits(n) ((uint32_t)((n) & 0xffffffff)) + #endif /* __LIBXFS_INTERNAL_XFS_H__ */ diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 345132921..344b34aa4 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -436,6 +436,9 @@ xfs_attr_hashval( { ASSERT(xfs_attr_check_namespace(attr_flags)); + if (attr_flags & XFS_ATTR_PARENT) + return xfs_parent_hashattr(mp, name, namelen, value, valuelen); + return xfs_attr_hashname(name, namelen); } diff --git a/libxfs/xfs_parent.c b/libxfs/xfs_parent.c index 50da527b6..7447acc2c 100644 --- a/libxfs/xfs_parent.c +++ b/libxfs/xfs_parent.c @@ -87,3 +87,50 @@ xfs_parent_valuecheck( return true; } + +/* Compute the attribute name hash for a parent pointer. */ +xfs_dahash_t +xfs_parent_hashval( + struct xfs_mount *mp, + const uint8_t *name, + int namelen, + xfs_ino_t parent_ino) +{ + struct xfs_name xname = { + .name = name, + .len = namelen, + }; + + /* + * Use the same dirent name hash as would be used on the directory, but + * mix in the parent inode number to avoid collisions on hardlinked + * files with identical names but different parents. + */ + return xfs_dir2_hashname(mp, &xname) ^ + upper_32_bits(parent_ino) ^ lower_32_bits(parent_ino); +} + +/* Compute the attribute name hash from the xattr components. */ +xfs_dahash_t +xfs_parent_hashattr( + struct xfs_mount *mp, + const uint8_t *name, + int namelen, + const void *value, + int valuelen) +{ + const struct xfs_parent_rec *rec = value; + + /* Requires a local attr value in xfs_parent_rec format */ + if (valuelen != sizeof(struct xfs_parent_rec)) { + ASSERT(valuelen == sizeof(struct xfs_parent_rec)); + return 0; + } + + if (!value) { + ASSERT(value != NULL); + return 0; + } + + return xfs_parent_hashval(mp, name, namelen, be64_to_cpu(rec->p_ino)); +} diff --git a/libxfs/xfs_parent.h b/libxfs/xfs_parent.h index ef8aff860..6a4028871 100644 --- a/libxfs/xfs_parent.h +++ b/libxfs/xfs_parent.h @@ -12,4 +12,9 @@ bool xfs_parent_namecheck(unsigned int attr_flags, const void *name, bool xfs_parent_valuecheck(struct xfs_mount *mp, const void *value, size_t valuelen); +xfs_dahash_t xfs_parent_hashval(struct xfs_mount *mp, const uint8_t *name, + int namelen, xfs_ino_t parent_ino); +xfs_dahash_t xfs_parent_hashattr(struct xfs_mount *mp, const uint8_t *name, + int namelen, const void *value, int valuelen); + #endif /* __XFS_PARENT_H__ */ From patchwork Tue Jul 30 00:40:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745984 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 19402440C for ; Tue, 30 Jul 2024 00:40:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300013; cv=none; b=WW92PzCjEzXaj4flrnO9R2E7l6oo0F0bOjU/06KEpUr7N528drC+SVb26XE5pvc7/xp98Vx/eCpsuwGhGbwqDkexBKoJhFIw63gVIO8gapwBpMFO6n3l8MXKGdVk9fHPLLxov4y765HTG89ihRGZIpqniQci/47HQHFGAF8bJdc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300013; c=relaxed/simple; bh=rVIZ9njt6tLrVmGOQmvkHWdU84OCj/8M+qG5f3XnEdA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mjq8pLXctTpQLhXAjMjT8CjZw28QKbOwj/YqWqu0kcaQlmlMzVCImfbezqtOY7L/E5HsRaUl1IDf82WGwzXz6c94zURZG1WmQQLZX6SaPbm4V/sCOs8LAUvVQdKBuJvNaO6IlgIVeOfI0bBPBRLiZzvfcjd2e/iAqYe9BPr65M0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=J6M0Z6d0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="J6M0Z6d0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3F98C32786; Tue, 30 Jul 2024 00:40:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300013; bh=rVIZ9njt6tLrVmGOQmvkHWdU84OCj/8M+qG5f3XnEdA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=J6M0Z6d0Wls3C3y7uAiFZLeRlNUjU3YbYR5eEPVVK9hfYNtz28fL8AkT2O6/u8dZg gRNFiyg8N5QcIVgpE4TFPrhtmo+BlwfZvQ1+p0ybpowCOiF5PB5blZWFPtj+UeN5ir 55vIztFnBvoqtAaSB9KsDpQHH3ZQpGOye5SM4P/FTX+lCZquphYJFhaGpOUa7V3GVb mfgpAxZ1HRYdT8PoEQmswaZ5FHqp38EaIVEwBMQJS2a99B0V0JZl8cmzaGdzZ07OFL Ch1qjvJgM01q4IKUOAOcno7wzeTDw3cW+C27KdMoNr+CcxTmM0CMj4vrKEnMZUqQHr Kyd9uuAg6QGdA== Date: Mon, 29 Jul 2024 17:40:12 -0700 Subject: [PATCH 063/115] xfs: parent pointer attribute creation From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Dave Chinner , Allison Henderson , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843330.1338752.4977268474558843321.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Allison Henderson Source kernel commit: b7c62d90c12c6cc86f10b8a62cefe0029374b6ff Add parent pointer attribute during xfs_create, and subroutines to initialize attributes. Note that the xfs_attr_intent object contains a pointer to the caller's xfs_da_args object, so the latter must persist until transaction commit. Signed-off-by: Dave Chinner Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong [djwong: shorten names, adjust to new format, set init_xattrs for parent pointers] Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- include/libxfs.h | 1 + include/xfs_inode.h | 6 ++++ libxfs/Makefile | 1 + libxfs/init.c | 3 ++ libxfs/libxfs_api_defs.h | 2 + libxfs/xfs_parent.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_parent.h | 65 ++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_trans_space.c | 52 +++++++++++++++++++++++++++++++++++ libxfs/xfs_trans_space.h | 9 +++--- repair/phase6.c | 8 +++-- 10 files changed, 207 insertions(+), 8 deletions(-) create mode 100644 libxfs/xfs_trans_space.c diff --git a/include/libxfs.h b/include/libxfs.h index fb8efb696..e760a46d8 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -90,6 +90,7 @@ struct iomap; #include "libxfs/xfile.h" #include "libxfs/buf_mem.h" #include "xfs_btree_mem.h" +#include "xfs_parent.h" #ifndef ARRAY_SIZE #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) diff --git a/include/xfs_inode.h b/include/xfs_inode.h index 825708383..c6e4f84bd 100644 --- a/include/xfs_inode.h +++ b/include/xfs_inode.h @@ -268,6 +268,12 @@ static inline struct inode *VFS_I(struct xfs_inode *ip) return &ip->i_vnode; } +/* convert from const xfs inode to const vfs inode */ +static inline const struct inode *VFS_IC(const struct xfs_inode *ip) +{ + return &ip->i_vnode; +} + /* We only have i_size in the xfs inode in userspace */ static inline loff_t i_size_read(struct inode *inode) { diff --git a/libxfs/Makefile b/libxfs/Makefile index 2a5cead9a..9fb53d9cc 100644 --- a/libxfs/Makefile +++ b/libxfs/Makefile @@ -113,6 +113,7 @@ CFILES = buf_mem.c \ xfs_symlink_remote.c \ xfs_trans_inode.c \ xfs_trans_resv.c \ + xfs_trans_space.c \ xfs_types.c # diff --git a/libxfs/init.c b/libxfs/init.c index de91bbf3c..95de1e6d1 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -214,6 +214,8 @@ init_caches(void) "xfs_extfree_item"); xfs_trans_cache = kmem_cache_init( sizeof(struct xfs_trans), "xfs_trans"); + xfs_parent_args_cache = kmem_cache_init( + sizeof(struct xfs_parent_args), "xfs_parent_args"); } static int @@ -231,6 +233,7 @@ destroy_caches(void) xfs_btree_destroy_cur_caches(); leaked += kmem_cache_destroy(xfs_extfree_item_cache); leaked += kmem_cache_destroy(xfs_trans_cache); + leaked += kmem_cache_destroy(xfs_parent_args_cache); return leaked; } diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 16f6513f6..9b44b7709 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -98,6 +98,7 @@ #define xfs_calc_dquots_per_chunk libxfs_calc_dquots_per_chunk #define xfs_cntbt_init_cursor libxfs_cntbt_init_cursor #define xfs_compute_rextslog libxfs_compute_rextslog +#define xfs_create_space_res libxfs_create_space_res #define xfs_da3_node_hdr_from_disk libxfs_da3_node_hdr_from_disk #define xfs_da_get_buf libxfs_da_get_buf #define xfs_da_hashname libxfs_da_hashname @@ -186,6 +187,7 @@ #define xfs_log_get_max_trans_res libxfs_log_get_max_trans_res #define xfs_log_sb libxfs_log_sb #define xfs_mode_to_ftype libxfs_mode_to_ftype +#define xfs_mkdir_space_res libxfs_mkdir_space_res #define xfs_perag_get libxfs_perag_get #define xfs_perag_hold libxfs_perag_hold #define xfs_perag_put libxfs_perag_put diff --git a/libxfs/xfs_parent.c b/libxfs/xfs_parent.c index 7447acc2c..b0516c3f6 100644 --- a/libxfs/xfs_parent.c +++ b/libxfs/xfs_parent.c @@ -24,6 +24,10 @@ #include "xfs_defer.h" #include "xfs_parent.h" #include "xfs_trans_space.h" +#include "defer_item.h" +#include "xfs_health.h" + +struct kmem_cache *xfs_parent_args_cache; /* * Parent pointer attribute handling. @@ -134,3 +138,67 @@ xfs_parent_hashattr( return xfs_parent_hashval(mp, name, namelen, be64_to_cpu(rec->p_ino)); } + +/* + * Initialize the parent pointer arguments structure. Caller must have zeroed + * the contents of @args. @tp is only required for updates. + */ +static void +xfs_parent_da_args_init( + struct xfs_da_args *args, + struct xfs_trans *tp, + struct xfs_parent_rec *rec, + struct xfs_inode *child, + xfs_ino_t owner, + const struct xfs_name *parent_name) +{ + args->geo = child->i_mount->m_attr_geo; + args->whichfork = XFS_ATTR_FORK; + args->attr_filter = XFS_ATTR_PARENT; + args->op_flags = XFS_DA_OP_LOGGED | XFS_DA_OP_OKNOENT; + args->trans = tp; + args->dp = child; + args->owner = owner; + args->name = parent_name->name; + args->namelen = parent_name->len; + args->value = rec; + args->valuelen = sizeof(struct xfs_parent_rec); + xfs_attr_sethash(args); +} + +/* Make sure the incore state is ready for a parent pointer query/update. */ +static inline int +xfs_parent_iread_extents( + struct xfs_trans *tp, + struct xfs_inode *child) +{ + /* Parent pointers require that the attr fork must exist. */ + if (XFS_IS_CORRUPT(child->i_mount, !xfs_inode_has_attr_fork(child))) { + xfs_inode_mark_sick(child, XFS_SICK_INO_PARENT); + return -EFSCORRUPTED; + } + + return xfs_iread_extents(tp, child, XFS_ATTR_FORK); +} + +/* Add a parent pointer to reflect a dirent addition. */ +int +xfs_parent_addname( + struct xfs_trans *tp, + struct xfs_parent_args *ppargs, + struct xfs_inode *dp, + const struct xfs_name *parent_name, + struct xfs_inode *child) +{ + int error; + + error = xfs_parent_iread_extents(tp, child); + if (error) + return error; + + xfs_inode_to_parent_rec(&ppargs->rec, dp); + xfs_parent_da_args_init(&ppargs->args, tp, &ppargs->rec, child, + child->i_ino, parent_name); + xfs_attr_defer_add(&ppargs->args, XFS_ATTR_DEFER_SET); + return 0; +} diff --git a/libxfs/xfs_parent.h b/libxfs/xfs_parent.h index 6a4028871..6de24e3ef 100644 --- a/libxfs/xfs_parent.h +++ b/libxfs/xfs_parent.h @@ -17,4 +17,69 @@ xfs_dahash_t xfs_parent_hashval(struct xfs_mount *mp, const uint8_t *name, xfs_dahash_t xfs_parent_hashattr(struct xfs_mount *mp, const uint8_t *name, int namelen, const void *value, int valuelen); +/* Initializes a xfs_parent_rec to be stored as an attribute name. */ +static inline void +xfs_parent_rec_init( + struct xfs_parent_rec *rec, + xfs_ino_t ino, + uint32_t gen) +{ + rec->p_ino = cpu_to_be64(ino); + rec->p_gen = cpu_to_be32(gen); +} + +/* Initializes a xfs_parent_rec to be stored as an attribute name. */ +static inline void +xfs_inode_to_parent_rec( + struct xfs_parent_rec *rec, + const struct xfs_inode *dp) +{ + xfs_parent_rec_init(rec, dp->i_ino, VFS_IC(dp)->i_generation); +} + +extern struct kmem_cache *xfs_parent_args_cache; + +/* + * Parent pointer information needed to pass around the deferred xattr update + * machinery. + */ +struct xfs_parent_args { + struct xfs_parent_rec rec; + struct xfs_da_args args; +}; + +/* + * Start a parent pointer update by allocating the context object we need to + * perform a parent pointer update. + */ +static inline int +xfs_parent_start( + struct xfs_mount *mp, + struct xfs_parent_args **ppargsp) +{ + if (!xfs_has_parent(mp)) { + *ppargsp = NULL; + return 0; + } + + *ppargsp = kmem_cache_zalloc(xfs_parent_args_cache, GFP_KERNEL); + if (!*ppargsp) + return -ENOMEM; + return 0; +} + +/* Finish a parent pointer update by freeing the context object. */ +static inline void +xfs_parent_finish( + struct xfs_mount *mp, + struct xfs_parent_args *ppargs) +{ + if (ppargs) + kmem_cache_free(xfs_parent_args_cache, ppargs); +} + +int xfs_parent_addname(struct xfs_trans *tp, struct xfs_parent_args *ppargs, + struct xfs_inode *dp, const struct xfs_name *parent_name, + struct xfs_inode *child); + #endif /* __XFS_PARENT_H__ */ diff --git a/libxfs/xfs_trans_space.c b/libxfs/xfs_trans_space.c new file mode 100644 index 000000000..3408e700f --- /dev/null +++ b/libxfs/xfs_trans_space.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2000,2005 Silicon Graphics, Inc. + * All Rights Reserved. + */ +#include "libxfs_priv.h" +#include "xfs_fs.h" +#include "xfs_shared.h" +#include "xfs_format.h" +#include "xfs_da_format.h" +#include "xfs_log_format.h" +#include "xfs_trans_resv.h" +#include "xfs_mount.h" +#include "xfs_da_btree.h" +#include "xfs_bmap_btree.h" +#include "xfs_trans_space.h" + +/* Calculate the disk space required to add a parent pointer. */ +unsigned int +xfs_parent_calc_space_res( + struct xfs_mount *mp, + unsigned int namelen) +{ + /* + * Parent pointers are always the first attr in an attr tree, and never + * larger than a block + */ + return XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK) + + XFS_NEXTENTADD_SPACE_RES(mp, namelen, XFS_ATTR_FORK); +} + +unsigned int +xfs_create_space_res( + struct xfs_mount *mp, + unsigned int namelen) +{ + unsigned int ret; + + ret = XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp, namelen); + if (xfs_has_parent(mp)) + ret += xfs_parent_calc_space_res(mp, namelen); + + return ret; +} + +unsigned int +xfs_mkdir_space_res( + struct xfs_mount *mp, + unsigned int namelen) +{ + return xfs_create_space_res(mp, namelen); +} diff --git a/libxfs/xfs_trans_space.h b/libxfs/xfs_trans_space.h index 9640fc232..6cda87153 100644 --- a/libxfs/xfs_trans_space.h +++ b/libxfs/xfs_trans_space.h @@ -80,8 +80,6 @@ /* This macro is not used - see inline code in xfs_attr_set */ #define XFS_ATTRSET_SPACE_RES(mp, v) \ (XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK) + XFS_B_TO_FSB(mp, v)) -#define XFS_CREATE_SPACE_RES(mp,nl) \ - (XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl)) #define XFS_DIOSTRAT_SPACE_RES(mp, v) \ (XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK) + (v)) #define XFS_GROWFS_SPACE_RES(mp) \ @@ -90,8 +88,6 @@ ((b) + XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK)) #define XFS_LINK_SPACE_RES(mp,nl) \ XFS_DIRENTER_SPACE_RES(mp,nl) -#define XFS_MKDIR_SPACE_RES(mp,nl) \ - (XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl)) #define XFS_QM_DQALLOC_SPACE_RES(mp) \ (XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK) + \ XFS_DQUOT_CLUSTER_SIZE_FSB) @@ -106,5 +102,10 @@ #define XFS_IFREE_SPACE_RES(mp) \ (xfs_has_finobt(mp) ? M_IGEO(mp)->inobt_maxlevels : 0) +unsigned int xfs_parent_calc_space_res(struct xfs_mount *mp, + unsigned int namelen); + +unsigned int xfs_create_space_res(struct xfs_mount *mp, unsigned int namelen); +unsigned int xfs_mkdir_space_res(struct xfs_mount *mp, unsigned int namelen); #endif /* __XFS_TRANS_SPACE_H__ */ diff --git a/repair/phase6.c b/repair/phase6.c index e6103f768..c4260fb91 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -927,7 +927,7 @@ mk_orphanage(xfs_mount_t *mp) /* * could not be found, create it */ - nres = XFS_MKDIR_SPACE_RES(mp, xname.len); + nres = libxfs_mkdir_space_res(mp, xname.len); i = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_mkdir, nres, 0, 0, &tp); if (i) res_failed(i); @@ -1343,7 +1343,7 @@ longform_dir2_rebuild( p->name.name[1] == '.')))) continue; - nres = XFS_CREATE_SPACE_RES(mp, p->name.len); + nres = libxfs_create_space_res(mp, p->name.len); error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_create, nres, 0, 0, &tp); if (error) @@ -2955,7 +2955,7 @@ _("error %d fixing shortform directory %llu\n"), do_warn(_("recreating root directory .. entry\n")); - nres = XFS_MKDIR_SPACE_RES(mp, 2); + nres = libxfs_mkdir_space_res(mp, 2); error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_mkdir, nres, 0, 0, &tp); if (error) @@ -3010,7 +3010,7 @@ _("error %d fixing shortform directory %llu\n"), do_warn( _("creating missing \".\" entry in dir ino %" PRIu64 "\n"), ino); - nres = XFS_MKDIR_SPACE_RES(mp, 1); + nres = libxfs_mkdir_space_res(mp, 1); error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_mkdir, nres, 0, 0, &tp); if (error) From patchwork Tue Jul 30 00:40:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745985 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B91B94683 for ; Tue, 30 Jul 2024 00:40:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300028; cv=none; b=TIb6OAhbIVm6lXuM58RaPsXgZb60e9b/oCoYvMq/xZmSsiYGSuHjuyc2VYC+7DGJz5D5ArBPbkT42UVHq7AQAv8+fntqxjrYHkwXrNgExsbTHICbel37BypFURYTBR6J3nNEBSOTD2DNEdraET/sApbCU6711UuRTnki+fMdzk0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300028; c=relaxed/simple; bh=Tf4rB540x6TYB9Xi+exGBcdC/FoLBJEmvZhYthE+NV0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=E/HMo5AhJ8ufawQER+EEUimmjHDTOYV514c4WZbXXLItK+jtvuIdP+D4M9Spz2c7yxJqXBGuHbKdD7kd6XmOfHBBZqBAqDaf1VFMzikcGyJMtwbHASv9FzdbcdCtSGBaFjpTYl2WalX6zOxXMENRwRw9d/s/pleaqWwDjO/YW8Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=igSk6pR7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="igSk6pR7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D1A6C32786; Tue, 30 Jul 2024 00:40:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300028; bh=Tf4rB540x6TYB9Xi+exGBcdC/FoLBJEmvZhYthE+NV0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=igSk6pR7U7ScHhvdY9aATjn09IdQHmLevPwNi2HNzo/2TMX9+vFAs0dlqP7oPfPOx ncRUwosIe+hQW+qwdtHRBAnAYD5Gq+o3NdBXRjOySmLi/1a/Z+LhXcqxKOgEegWzOS sxO7UAW/JJVzDnC7O0qPP7QcKA3647WA8QK6ykPJ1krixJpwTvGymeW9fC5eVOIn6W JJcex/ONBr7GcPknugjLOilArKp1+7rr2abfd+ZaaimSQRPp0AIJQ4PLLYGHjV8a3H itQuO/+mVcbrDTNYEIdYgr9xc73KKpyEOFqtvzXKHLRiPxp2y2yAk+7p9i1D8L+9Tf HB9b1Bcklr55A== Date: Mon, 29 Jul 2024 17:40:28 -0700 Subject: [PATCH 064/115] xfs: add parent attributes to link From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Dave Chinner , Allison Henderson , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843345.1338752.534634287541735225.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Allison Henderson Source kernel commit: f1097be220fa938de5114db57a1ddb5de2bf6046 This patch modifies xfs_link to add a parent pointer to the inode. Signed-off-by: Dave Chinner Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong [djwong: minor rebase fixes] Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_trans_space.c | 14 ++++++++++++++ libxfs/xfs_trans_space.h | 3 +-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_trans_space.c b/libxfs/xfs_trans_space.c index 3408e700f..039bbd91e 100644 --- a/libxfs/xfs_trans_space.c +++ b/libxfs/xfs_trans_space.c @@ -50,3 +50,17 @@ xfs_mkdir_space_res( { return xfs_create_space_res(mp, namelen); } + +unsigned int +xfs_link_space_res( + struct xfs_mount *mp, + unsigned int namelen) +{ + unsigned int ret; + + ret = XFS_DIRENTER_SPACE_RES(mp, namelen); + if (xfs_has_parent(mp)) + ret += xfs_parent_calc_space_res(mp, namelen); + + return ret; +} diff --git a/libxfs/xfs_trans_space.h b/libxfs/xfs_trans_space.h index 6cda87153..553963400 100644 --- a/libxfs/xfs_trans_space.h +++ b/libxfs/xfs_trans_space.h @@ -86,8 +86,6 @@ (2 * (mp)->m_alloc_maxlevels) #define XFS_GROWFSRT_SPACE_RES(mp,b) \ ((b) + XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK)) -#define XFS_LINK_SPACE_RES(mp,nl) \ - XFS_DIRENTER_SPACE_RES(mp,nl) #define XFS_QM_DQALLOC_SPACE_RES(mp) \ (XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK) + \ XFS_DQUOT_CLUSTER_SIZE_FSB) @@ -107,5 +105,6 @@ unsigned int xfs_parent_calc_space_res(struct xfs_mount *mp, unsigned int xfs_create_space_res(struct xfs_mount *mp, unsigned int namelen); unsigned int xfs_mkdir_space_res(struct xfs_mount *mp, unsigned int namelen); +unsigned int xfs_link_space_res(struct xfs_mount *mp, unsigned int namelen); #endif /* __XFS_TRANS_SPACE_H__ */ From patchwork Tue Jul 30 00:40:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745986 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7A2784A21 for ; Tue, 30 Jul 2024 00:40:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300044; cv=none; b=NMNYuWZ0OKQMS0zei9L3UHaI3J7jKx0zQlQRfR8BzcEmdLW04Fs2V6dtLrlUgZsBv0UQF1jqKC7cJKB8GCdxXrtV9RUZPlTTNMKqiBjXDPGUZ8E8YLdUo+uY4uGYx43EaTOW0Jxztx+ISs1Ado5joih3WbElPBZgoTX6LlZRsis= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300044; c=relaxed/simple; bh=CAR/KcwKlrFRbbODw5+0kfheWLR3DpxZPuqd+wk/G6Q=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=flaf8FrqdPApY/MjUjM9+KbR5E1zUa9e5kEqIgkTfkSYmIdLUQFRCfFpCTdEE6+SYahGsV/Q1sE702oChMvPCFQGaKTbfVj1YP06PBIU3l8nKgMqnK2xXBDLwOVWqvUKYFBzndR6EmS7bcY0gos4scF18uyxD/OgHKeteKz05t0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Q3baNh9X; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Q3baNh9X" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 509CAC32786; Tue, 30 Jul 2024 00:40:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300044; bh=CAR/KcwKlrFRbbODw5+0kfheWLR3DpxZPuqd+wk/G6Q=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Q3baNh9X1sv8vPlyZmGZxu+GsxADME1PLUkNeRT3tZ5nn+xLQ1f1WUEP37eaJ6jR9 rGjESZ3SrQYddOJyBpgZ0Hh0iWWQfhsBkDbAtj/N0W0xLceX0NN9AfKAJhGc9HE5N/ urdVCdw9fjnxkPNgfFkptHshSnWaWv3aJ6bmx/iK3ItRbh6gprZHAEfouGEX8aQiA3 p6gdHrZJDJW2vwDuO0I27uDvMSn5KzYVTQE7sxjqzzpeA3GIlYcHfeb11GU15tg3G2 nmTH158k786SS3XmMp6Rm/gyvsC0GxHlBOhSO1CXEhCoDB9ZkFRhEYBLZG1ziRQHbI +ISUNmv10b1fg== Date: Mon, 29 Jul 2024 17:40:43 -0700 Subject: [PATCH 065/115] xfs: add parent attributes to symlink From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Allison Henderson , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843358.1338752.10591416095036311151.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Allison Henderson Source kernel commit: 5d31a85dcc1fa4c5d4a925c6da67751653a700ba This patch modifies xfs_symlink to add a parent pointer to the inode. Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong [djwong: minor rebase fixups] Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_trans_space.c | 17 +++++++++++++++++ libxfs/xfs_trans_space.h | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_trans_space.c b/libxfs/xfs_trans_space.c index 039bbd91e..bf4a41492 100644 --- a/libxfs/xfs_trans_space.c +++ b/libxfs/xfs_trans_space.c @@ -64,3 +64,20 @@ xfs_link_space_res( return ret; } + +unsigned int +xfs_symlink_space_res( + struct xfs_mount *mp, + unsigned int namelen, + unsigned int fsblocks) +{ + unsigned int ret; + + ret = XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp, namelen) + + fsblocks; + + if (xfs_has_parent(mp)) + ret += xfs_parent_calc_space_res(mp, namelen); + + return ret; +} diff --git a/libxfs/xfs_trans_space.h b/libxfs/xfs_trans_space.h index 553963400..354ad1d6e 100644 --- a/libxfs/xfs_trans_space.h +++ b/libxfs/xfs_trans_space.h @@ -95,8 +95,6 @@ XFS_DIRREMOVE_SPACE_RES(mp) #define XFS_RENAME_SPACE_RES(mp,nl) \ (XFS_DIRREMOVE_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl)) -#define XFS_SYMLINK_SPACE_RES(mp,nl,b) \ - (XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl) + (b)) #define XFS_IFREE_SPACE_RES(mp) \ (xfs_has_finobt(mp) ? M_IGEO(mp)->inobt_maxlevels : 0) @@ -106,5 +104,7 @@ unsigned int xfs_parent_calc_space_res(struct xfs_mount *mp, unsigned int xfs_create_space_res(struct xfs_mount *mp, unsigned int namelen); unsigned int xfs_mkdir_space_res(struct xfs_mount *mp, unsigned int namelen); unsigned int xfs_link_space_res(struct xfs_mount *mp, unsigned int namelen); +unsigned int xfs_symlink_space_res(struct xfs_mount *mp, unsigned int namelen, + unsigned int fsblocks); #endif /* __XFS_TRANS_SPACE_H__ */ From patchwork Tue Jul 30 00:40:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745987 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 65B4510E3 for ; Tue, 30 Jul 2024 00:41:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300060; cv=none; b=ZX3CZjY0ytWk0o8cLx2GGK2h62MDBIR/44Mnlhb6IoQ9HQsqytizHGcW1Iq/pYLQfTylToOBeoLQjhDYz+nU7sp7Ny/jBZXeM4sJu1AoJAJ6iw2uZ4vEmkbVghwC7Ir86GoOawNZESr5mUwTShLlkupovrWBLzVYKq4DNBmUuag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300060; c=relaxed/simple; bh=2NKluxWn6uqj8UQUXGHj2mOthCOJ+BogMYbjo8Kk0Og=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LcAoM9h7KpoYMS5z8Daa5FKjcaxmfxcehQGZwHkOhH8PVVT5Okt4dql6ys7WUA/J9juHXsDJggvcjrAldx6g7FlJZzOEki+4jTf1vZv0UuixfUZeQAHSyhZD8rJKs2sU3Z7x4fjq/3yoWKTHkSLuaMOzESsPKkX8yRYCmlNRFks= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZL8gCwlX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZL8gCwlX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F166EC32786; Tue, 30 Jul 2024 00:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300060; bh=2NKluxWn6uqj8UQUXGHj2mOthCOJ+BogMYbjo8Kk0Og=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ZL8gCwlXxok4Ue8WTLGpm8hDVCj0R/D+N4oPeozc9BS4dpiUpa52QrMtqo5NaPC70 jKgl33/CpiUv0x2aZeTRAFxBdDtsxuzSgDmgegvdMVcuI2oJHJeG2mbtkSEGjjIcee FwVf0TJo4BnSDzmrLtIQg7Q28y4+bTuJUpzmU9rMjdkAtx7LU5uzNGB6/JZgu14PMz K7yaW+zFyOQtEIobcWaZMcIVouz0uqgC6zlKZmDtqd2syGFRzDFqGnzWyOhoDMvWJ7 8gobwTYVpMTWXrXezXdyETxp0lbRDfoa6x8dZxRlhpbYtghOJefi7N2VtkWfjBWoIB tMch4v/1XwJ4Q== Date: Mon, 29 Jul 2024 17:40:59 -0700 Subject: [PATCH 066/115] xfs: remove parent pointers in unlink From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Dave Chinner , Allison Henderson , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843372.1338752.18248640869646401251.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Allison Henderson Source kernel commit: d2d18330f63cd70b50eddac76de7c59a36f2faa7 This patch removes the parent pointer attribute during unlink Signed-off-by: Dave Chinner Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong [djwong: adjust to new ondisk format, minor rebase fixes] Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/libxfs_api_defs.h | 1 + libxfs/xfs_parent.c | 22 ++++++++++++++++++++++ libxfs/xfs_parent.h | 3 +++ libxfs/xfs_trans_space.c | 13 +++++++++++++ libxfs/xfs_trans_space.h | 3 +-- repair/phase6.c | 6 +++--- 6 files changed, 43 insertions(+), 5 deletions(-) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 9b44b7709..896b6c953 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -204,6 +204,7 @@ #define xfs_refcountbt_stage_cursor libxfs_refcountbt_stage_cursor #define xfs_refcount_get_rec libxfs_refcount_get_rec #define xfs_refcount_lookup_le libxfs_refcount_lookup_le +#define xfs_remove_space_res libxfs_remove_space_res #define xfs_rmap_alloc libxfs_rmap_alloc #define xfs_rmapbt_calc_reserves libxfs_rmapbt_calc_reserves diff --git a/libxfs/xfs_parent.c b/libxfs/xfs_parent.c index b0516c3f6..0657728e6 100644 --- a/libxfs/xfs_parent.c +++ b/libxfs/xfs_parent.c @@ -202,3 +202,25 @@ xfs_parent_addname( xfs_attr_defer_add(&ppargs->args, XFS_ATTR_DEFER_SET); return 0; } + +/* Remove a parent pointer to reflect a dirent removal. */ +int +xfs_parent_removename( + struct xfs_trans *tp, + struct xfs_parent_args *ppargs, + struct xfs_inode *dp, + const struct xfs_name *parent_name, + struct xfs_inode *child) +{ + int error; + + error = xfs_parent_iread_extents(tp, child); + if (error) + return error; + + xfs_inode_to_parent_rec(&ppargs->rec, dp); + xfs_parent_da_args_init(&ppargs->args, tp, &ppargs->rec, child, + child->i_ino, parent_name); + xfs_attr_defer_add(&ppargs->args, XFS_ATTR_DEFER_REMOVE); + return 0; +} diff --git a/libxfs/xfs_parent.h b/libxfs/xfs_parent.h index 6de24e3ef..4a7fd48c2 100644 --- a/libxfs/xfs_parent.h +++ b/libxfs/xfs_parent.h @@ -81,5 +81,8 @@ xfs_parent_finish( int xfs_parent_addname(struct xfs_trans *tp, struct xfs_parent_args *ppargs, struct xfs_inode *dp, const struct xfs_name *parent_name, struct xfs_inode *child); +int xfs_parent_removename(struct xfs_trans *tp, struct xfs_parent_args *ppargs, + struct xfs_inode *dp, const struct xfs_name *parent_name, + struct xfs_inode *child); #endif /* __XFS_PARENT_H__ */ diff --git a/libxfs/xfs_trans_space.c b/libxfs/xfs_trans_space.c index bf4a41492..86a91a3a8 100644 --- a/libxfs/xfs_trans_space.c +++ b/libxfs/xfs_trans_space.c @@ -81,3 +81,16 @@ xfs_symlink_space_res( return ret; } + +unsigned int +xfs_remove_space_res( + struct xfs_mount *mp, + unsigned int namelen) +{ + unsigned int ret = XFS_DIRREMOVE_SPACE_RES(mp); + + if (xfs_has_parent(mp)) + ret += xfs_parent_calc_space_res(mp, namelen); + + return ret; +} diff --git a/libxfs/xfs_trans_space.h b/libxfs/xfs_trans_space.h index 354ad1d6e..a4490813c 100644 --- a/libxfs/xfs_trans_space.h +++ b/libxfs/xfs_trans_space.h @@ -91,8 +91,6 @@ XFS_DQUOT_CLUSTER_SIZE_FSB) #define XFS_QM_QINOCREATE_SPACE_RES(mp) \ XFS_IALLOC_SPACE_RES(mp) -#define XFS_REMOVE_SPACE_RES(mp) \ - XFS_DIRREMOVE_SPACE_RES(mp) #define XFS_RENAME_SPACE_RES(mp,nl) \ (XFS_DIRREMOVE_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl)) #define XFS_IFREE_SPACE_RES(mp) \ @@ -106,5 +104,6 @@ unsigned int xfs_mkdir_space_res(struct xfs_mount *mp, unsigned int namelen); unsigned int xfs_link_space_res(struct xfs_mount *mp, unsigned int namelen); unsigned int xfs_symlink_space_res(struct xfs_mount *mp, unsigned int namelen, unsigned int fsblocks); +unsigned int xfs_remove_space_res(struct xfs_mount *mp, unsigned int namelen); #endif /* __XFS_TRANS_SPACE_H__ */ diff --git a/repair/phase6.c b/repair/phase6.c index c4260fb91..2eba9772d 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -1283,7 +1283,7 @@ longform_dir2_rebuild( libxfs_dir_ino_validate(mp, pip.i_ino)) pip.i_ino = mp->m_sb.sb_rootino; - nres = XFS_REMOVE_SPACE_RES(mp); + nres = libxfs_remove_space_res(mp, 0); error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_remove, nres, 0, 0, &tp); if (error) res_failed(error); @@ -1389,7 +1389,7 @@ dir2_kill_block( int nres; xfs_trans_t *tp; - nres = XFS_REMOVE_SPACE_RES(mp); + nres = libxfs_remove_space_res(mp, 0); error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_remove, nres, 0, 0, &tp); if (error) res_failed(error); @@ -2908,7 +2908,7 @@ process_dir_inode( * inode but it's easier than wedging a * new define in ourselves. */ - nres = no_modify ? 0 : XFS_REMOVE_SPACE_RES(mp); + nres = no_modify ? 0 : libxfs_remove_space_res(mp, 0); error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_remove, nres, 0, 0, &tp); if (error) From patchwork Tue Jul 30 00:41:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745988 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 149D61361 for ; Tue, 30 Jul 2024 00:41:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300076; cv=none; b=QNwyDmA65qxoPmQeQdDLxNdrINJ5hSE+VL0HLrjkC7Fc0r+We7rpprosCjICXyGiNAn+BZi3g32yHL63PyjfyfCa8/RQG8u0d1gAkXEIv6nNkpobkCFHZFZ86yg4rkLNFOGCIMt3HFMJvpMxK8yjG2beSsW4BH/OgaBwZKYzcEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300076; c=relaxed/simple; bh=kaLRQCp17v83jsZtJNCdGInYOkS6mN7wMxYyUremahI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mA/HAILBqmG4/0MByd9IwiX59SMUP4HH52jTHWQXcvEHMCK/dzSAhG2bF57OSXZqJEGnqB+mPmgsbb60kynADdmJ+UY5Ws72gbMtFMRZ5CePT4e1qVtbAPKxoiDA/bBe6s2SSb7jP+HdObrfA4fYFTqrrua/djLRDmHB514rgVg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ibxkqveK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ibxkqveK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9970CC32786; Tue, 30 Jul 2024 00:41:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300075; bh=kaLRQCp17v83jsZtJNCdGInYOkS6mN7wMxYyUremahI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ibxkqveKO2zZwmiwQSZwqyHNzjIe/LeFFNuAV1h2JBSr3TxepLBrNi3XashZkfSQV voSfHlgXlBgCra+5FyQh96TO6dbuLtg+i5q+v243UAEFZofioytxZUlvJy+iFet5Sw oMn96eFO84WZ5oamSRJTIVl7qwZMTUeG6YWYva+sJgL/1lRGY2knZ+pKAcf4IHULgu +jMocxxJTu1Y4KQjio/M/6wr2Vkg1FIVdpw1bQ3foNBBO1gDCT1SSvTw7g8l4OLPt3 IM03A700sUgYsO8DZF0mIVdlgQ93wGrO3L0VU0ONCz7Uo4SyZtP56163YuAblhOEtH 2+IGIazKPCzTA== Date: Mon, 29 Jul 2024 17:41:15 -0700 Subject: [PATCH 067/115] xfs: Add parent pointers to rename From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Allison Henderson , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843387.1338752.4325658647941757571.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Allison Henderson Source kernel commit: 5a8338c88284df4e9e697225aa65f2709333a659 This patch removes the old parent pointer attribute during the rename operation, and re-adds the updated parent pointer. Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong [djwong: adjust to new ondisk format] Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_parent.c | 30 ++++++++++++++++++++++++++++++ libxfs/xfs_parent.h | 6 ++++++ libxfs/xfs_trans_space.c | 25 +++++++++++++++++++++++++ libxfs/xfs_trans_space.h | 6 ++++-- 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_parent.c b/libxfs/xfs_parent.c index 0657728e6..a53b7d13d 100644 --- a/libxfs/xfs_parent.c +++ b/libxfs/xfs_parent.c @@ -224,3 +224,33 @@ xfs_parent_removename( xfs_attr_defer_add(&ppargs->args, XFS_ATTR_DEFER_REMOVE); return 0; } + +/* Replace one parent pointer with another to reflect a rename. */ +int +xfs_parent_replacename( + struct xfs_trans *tp, + struct xfs_parent_args *ppargs, + struct xfs_inode *old_dp, + const struct xfs_name *old_name, + struct xfs_inode *new_dp, + const struct xfs_name *new_name, + struct xfs_inode *child) +{ + int error; + + error = xfs_parent_iread_extents(tp, child); + if (error) + return error; + + xfs_inode_to_parent_rec(&ppargs->rec, old_dp); + xfs_parent_da_args_init(&ppargs->args, tp, &ppargs->rec, child, + child->i_ino, old_name); + + xfs_inode_to_parent_rec(&ppargs->new_rec, new_dp); + ppargs->args.new_name = new_name->name; + ppargs->args.new_namelen = new_name->len; + ppargs->args.new_value = &ppargs->new_rec; + ppargs->args.new_valuelen = sizeof(struct xfs_parent_rec); + xfs_attr_defer_add(&ppargs->args, XFS_ATTR_DEFER_REPLACE); + return 0; +} diff --git a/libxfs/xfs_parent.h b/libxfs/xfs_parent.h index 4a7fd48c2..768633b31 100644 --- a/libxfs/xfs_parent.h +++ b/libxfs/xfs_parent.h @@ -45,6 +45,7 @@ extern struct kmem_cache *xfs_parent_args_cache; */ struct xfs_parent_args { struct xfs_parent_rec rec; + struct xfs_parent_rec new_rec; struct xfs_da_args args; }; @@ -84,5 +85,10 @@ int xfs_parent_addname(struct xfs_trans *tp, struct xfs_parent_args *ppargs, int xfs_parent_removename(struct xfs_trans *tp, struct xfs_parent_args *ppargs, struct xfs_inode *dp, const struct xfs_name *parent_name, struct xfs_inode *child); +int xfs_parent_replacename(struct xfs_trans *tp, + struct xfs_parent_args *ppargs, + struct xfs_inode *old_dp, const struct xfs_name *old_name, + struct xfs_inode *new_dp, const struct xfs_name *new_name, + struct xfs_inode *child); #endif /* __XFS_PARENT_H__ */ diff --git a/libxfs/xfs_trans_space.c b/libxfs/xfs_trans_space.c index 86a91a3a8..373f5cc24 100644 --- a/libxfs/xfs_trans_space.c +++ b/libxfs/xfs_trans_space.c @@ -94,3 +94,28 @@ xfs_remove_space_res( return ret; } + +unsigned int +xfs_rename_space_res( + struct xfs_mount *mp, + unsigned int src_namelen, + bool target_exists, + unsigned int target_namelen, + bool has_whiteout) +{ + unsigned int ret; + + ret = XFS_DIRREMOVE_SPACE_RES(mp) + + XFS_DIRENTER_SPACE_RES(mp, target_namelen); + + if (xfs_has_parent(mp)) { + if (has_whiteout) + ret += xfs_parent_calc_space_res(mp, src_namelen); + ret += 2 * xfs_parent_calc_space_res(mp, target_namelen); + } + + if (target_exists) + ret += xfs_parent_calc_space_res(mp, target_namelen); + + return ret; +} diff --git a/libxfs/xfs_trans_space.h b/libxfs/xfs_trans_space.h index a4490813c..1155ff2d3 100644 --- a/libxfs/xfs_trans_space.h +++ b/libxfs/xfs_trans_space.h @@ -91,8 +91,6 @@ XFS_DQUOT_CLUSTER_SIZE_FSB) #define XFS_QM_QINOCREATE_SPACE_RES(mp) \ XFS_IALLOC_SPACE_RES(mp) -#define XFS_RENAME_SPACE_RES(mp,nl) \ - (XFS_DIRREMOVE_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl)) #define XFS_IFREE_SPACE_RES(mp) \ (xfs_has_finobt(mp) ? M_IGEO(mp)->inobt_maxlevels : 0) @@ -106,4 +104,8 @@ unsigned int xfs_symlink_space_res(struct xfs_mount *mp, unsigned int namelen, unsigned int fsblocks); unsigned int xfs_remove_space_res(struct xfs_mount *mp, unsigned int namelen); +unsigned int xfs_rename_space_res(struct xfs_mount *mp, + unsigned int src_namelen, bool target_exists, + unsigned int target_namelen, bool has_whiteout); + #endif /* __XFS_TRANS_SPACE_H__ */ From patchwork Tue Jul 30 00:41:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745989 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 74D08184E for ; Tue, 30 Jul 2024 00:41:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300091; cv=none; b=JhzsMS1ic/c3WXixThvX8zUVC0kg4ApeF9rkDJLl8vA1ej5ljqAbEo1gI3B4bUM95iUINJFl9bT8UpqsBIshHBZih0YxSpxBys0F45AsPN6UKQ9cb+yYoZHbJRkI2BqeNqeFQxoG9pcFRlPWORqJNpTsT/a3WLbgar7jEbX3XiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300091; c=relaxed/simple; bh=8XlkJuSJdf7VN6ryXv0r7pIlDITttpcUJXqLIcjobVc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=g7cCM2ktmaOKUCy4pfFl9tkChxaiHHK+I9pbN3E9+Tz5NmGiR45mwugbrX/Y1y8gJO0F5Ah9dtnjInQazGYUHvdVnCM9FCoM4nz+GQK6uU7kno+MJre/jZU41Aq8qtSskrwSk66+kNJ2ODzCf81Y9DMjn+d9bWsvrNw/liOWMqI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=e/VoEgyZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="e/VoEgyZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44EC5C32786; Tue, 30 Jul 2024 00:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300091; bh=8XlkJuSJdf7VN6ryXv0r7pIlDITttpcUJXqLIcjobVc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=e/VoEgyZkuLIYOsxdID0HcdByKS2QFapLajg0dEDkAqWlFMrr2OCyRdXqqKI6sv64 Wus9vBdhKOg0hmhTectSfu0ACYC/u22NivruCTHXZ5ZW3xzvqeV8r5GKwbTtg5S0YO mjFZpS6bb+7phKWU4jIGhlXn8vw4pzOLIyucw+rMCMrxVsKDZmm+azx0okfDyjws94 ozDBiPizE+JKMshAmfhtVp7BRtNucHcGQDUuJlXMXjXAep30V0YIvwffp3Hp1Da4Uj DCuTT+j09dDjRW7aRvu4fp3xa88//t3VRZVpUIz58XF5rQMYkOYGSIAizZgogYZx8c YchdTrt4rhR7w== Date: Mon, 29 Jul 2024 17:41:30 -0700 Subject: [PATCH 068/115] xfs: don't return XFS_ATTR_PARENT attributes via listxattr From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Allison Henderson , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843401.1338752.22200803405477761.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Allison Henderson Source kernel commit: daf9f884906bcfcffe26967aee9ece893fba019b Parent pointers are internal filesystem metadata. They're not intended to be directly visible to userspace, so filter them out of xfs_xattr_put_listent so that they don't appear in listxattr. Signed-off-by: Allison Henderson Inspired-by: Andrey Albershteyn Reviewed-by: Darrick J. Wong [djwong: change this to XFS_ATTR_PRIVATE_NSP_MASK per fsverity patchset] Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_da_format.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libxfs/xfs_da_format.h b/libxfs/xfs_da_format.h index 1395ad193..ebde6eb1d 100644 --- a/libxfs/xfs_da_format.h +++ b/libxfs/xfs_da_format.h @@ -726,6 +726,9 @@ struct xfs_attr3_leafblock { XFS_ATTR_SECURE | \ XFS_ATTR_PARENT) +/* Private attr namespaces not exposed to userspace */ +#define XFS_ATTR_PRIVATE_NSP_MASK (XFS_ATTR_PARENT) + #define XFS_ATTR_ONDISK_MASK (XFS_ATTR_NSP_ONDISK_MASK | \ XFS_ATTR_LOCAL | \ XFS_ATTR_INCOMPLETE) From patchwork Tue Jul 30 00:41:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745990 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2D85D10F9 for ; Tue, 30 Jul 2024 00:41:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300107; cv=none; b=FgeApBwyVJJbbL0dNRsdB/1POC9IpoPmGrsoRIYEi3wLV2Og5kMVkJYIubaghsb7zBZpUZoKoafzXA+e2SK4j4BeYutFwUhv49Z98kQJ1yFNisnO27jmxk91PUOj9rdJ4okkti6NAE20c9UAcAqdZ6ADhUjFDwy8j7GTlIEaUeo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300107; c=relaxed/simple; bh=jZrNabBXEj0GN2xW9iFutZASU9S8rWDv7rU8ggJGIOk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=a3QSZtpr7JRQJuj8+ouiYQt69ngfpqO/FtlZDr5LOExmDwjJ0sxCb/Ge5eHZnHD05Td7mblYrzT4XMM97mt7ORZUVT1BM1jwgLXOK32Z79gsiDolYfeT5vfYathaxdT7yrQNjCY9BdcpdA0HpY/Moewu2ZloFlMm6fhRjOIpjME= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LU1C3Vfu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LU1C3Vfu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A17DC32786; Tue, 30 Jul 2024 00:41:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300107; bh=jZrNabBXEj0GN2xW9iFutZASU9S8rWDv7rU8ggJGIOk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=LU1C3Vfuvlfeuu+/6+cINBkFRaAFDpsrSPKxstEcltiR629FWN5LynZhAh6+dd4lm vbBd2XFo9NNioEPa/HtfoRo3XHFWI1XFqmGd9ZwXMrpNlaTEne/YK2VNjYT4uHhHSf oxSvVUI20MziSfV2My4P35vKpqQTiP8gEW9cdi6WkO9CVTCftPunpgi3aLqzYRICWz VAwsxPuUkFjh5U9+8HHcx+j+9+2cGj8JPd9rsHQB99n1H6HH9EIgkc7ifxXnUSG9tR BYRv5zTlzTV/daHo+v3eHofbVituTUyOnz8V7PD34+n/WV77ew9CRMzeErwklZ8hEP 9Pi5Q9ijo4mgw== Date: Mon, 29 Jul 2024 17:41:46 -0700 Subject: [PATCH 069/115] xfs: pass the attr value to put_listent when possible From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Allison Henderson , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843416.1338752.7158096912746328754.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Allison Henderson Source kernel commit: 8f4b980ee67fe53a77b70b1fdd8e15f2fe37180c Pass the attr value to put_listent when we have local xattrs or shortform xattrs. This will enable the GETPARENTS ioctl to use xfs_attr_list as its backend. Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr.h | 5 +++-- libxfs/xfs_attr_sf.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h index d0ed7ea58..d12583dd7 100644 --- a/libxfs/xfs_attr.h +++ b/libxfs/xfs_attr.h @@ -47,8 +47,9 @@ struct xfs_attrlist_cursor_kern { /* void; state communicated via *context */ -typedef void (*put_listent_func_t)(struct xfs_attr_list_context *, int, - unsigned char *, int, int); +typedef void (*put_listent_func_t)(struct xfs_attr_list_context *context, + int flags, unsigned char *name, int namelen, void *value, + int valuelen); struct xfs_attr_list_context { struct xfs_trans *tp; diff --git a/libxfs/xfs_attr_sf.h b/libxfs/xfs_attr_sf.h index bc4422223..73bdc0e55 100644 --- a/libxfs/xfs_attr_sf.h +++ b/libxfs/xfs_attr_sf.h @@ -16,6 +16,7 @@ typedef struct xfs_attr_sf_sort { uint8_t flags; /* flags bits (see xfs_attr_leaf.h) */ xfs_dahash_t hash; /* this entry's hash value */ unsigned char *name; /* name value, pointer into buffer */ + void *value; } xfs_attr_sf_sort_t; #define XFS_ATTR_SF_ENTSIZE_MAX /* max space for name&value */ \ From patchwork Tue Jul 30 00:42:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745991 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C91B44A21 for ; Tue, 30 Jul 2024 00:42:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300122; cv=none; b=Oxd+HbPWZLX+w9KnjT8s+EspLHPg8xreqbG/36HNm4AFA3VCTjzR68xfLtIjBPeQJsHBONvd4MiVzDNTqElB0do9zy2lBhUeCtWovjjEBqonOZPL42V6ISJ72FcjbIlmmIKm3gMhjyAnzq8Z5wVk9gXdFHkZ820Ies62JPnVUCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300122; c=relaxed/simple; bh=K9LoPnJYlv3h/iqABQPIIGPkhSoSFKsNkLvErpp1DJg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t7Mv0PrFO1L58hH6HosW/o7XvbwnZS0rNPa96J4vhUH2w7PCbom4neSYcwQG5DqcxRU4WrT4cGgYmKq9OnHYCNFrNfBgCNSxOzrCfAUcxX4By4xJbdkxGSyXA9SdnkdLhPJogvfWsrCRojucLCwArezqfWmn2saxJjxKKQakol4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mc0Q+Cks; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mc0Q+Cks" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A153EC32786; Tue, 30 Jul 2024 00:42:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300122; bh=K9LoPnJYlv3h/iqABQPIIGPkhSoSFKsNkLvErpp1DJg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=mc0Q+Cks3BjlQZHP2I/JAPsuawsAnxtSub4GwlgtX0foSiA//sz/LQH81FztC+VfO dkma/dQBCF0lJQ8xO/OoFm2jPx1He1lMz+KNEhK7TW3B8TcZI4PP8aMUXGFh1HF2D+ aZhxwuc90F1TbRWyf6rUXj1h+lfGqX+4fOCDXrNT5UZno+bxZ0BktxG7AjqWAK+oGO r3slRleQHIOhOdmddiIrLZpiO+bv4ZDbXKGUqQ82LYs19c77aTQbvGasPIsl0igrd4 n+AsQv0x1pi2J/B3SxODJEfEgfLgc0poe9BMLikGdbmydZResKFKtwvJ8tp/elQEyd aSrI5v5/sC0vw== Date: Mon, 29 Jul 2024 17:42:02 -0700 Subject: [PATCH 070/115] xfs: split out handle management helpers a bit From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843428.1338752.14171945500604979431.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: b8c9d4253da43c02b287831f7e576568f24fbe58 Split out the functions that generate file/fs handles and map them back into dentries in preparation for the GETPARENTS ioctl next. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_fs.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index 53526fca7..97384ab95 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -633,7 +633,9 @@ typedef struct xfs_fsop_attrmulti_handlereq { /* * per machine unique filesystem identifier types. */ -typedef struct { __u32 val[2]; } xfs_fsid_t; /* file system id type */ +typedef struct xfs_fsid { + __u32 val[2]; /* file system id type */ +} xfs_fsid_t; typedef struct xfs_fid { __u16 fid_len; /* length of remainder */ From patchwork Tue Jul 30 00:42:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745992 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7218E4A21 for ; Tue, 30 Jul 2024 00:42:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300138; cv=none; b=KeHMuquM5SC4ZXxaioidsAIRCg/CbwMHSe/jG8f+zpPqPYRy/5kweipDX97K0HsGCzC86aY6Hu6in2Oe5m5CaJs27t9j6MH86ns8Gx4t+SWM1+i35TKh2fdU09ZCjhWwdtM3sP+ggHqhlDDWhPREDksK/gjHGz6jIcY2hWfGkP0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300138; c=relaxed/simple; bh=flqiCTNhBduzDwF9dxJ68eprN5RPhjcE/NWWx+nV3e8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mxkMcATPXxxKolEsWIBh3YsxGy6Vvx3Hgl6wOeaixOpyPAh4zRSELOAHaKe/UocxYPBLXfxSq1r+f6Yo4xri3R1z5MwFLUnBLeXffBOm2PF4Yax4fKHxHCKVMeti25y0Cr2rRaUggGvZ2KAYu/H25VavgKhRa+/lT3LPyPE/HNI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hxHMpJcf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hxHMpJcf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50184C32786; Tue, 30 Jul 2024 00:42:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300138; bh=flqiCTNhBduzDwF9dxJ68eprN5RPhjcE/NWWx+nV3e8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=hxHMpJcfS2dY3Qq+Ki0RGEREVji9oTZws4xBIPjtQ8BwELI5SbMFcF1A7+FofZn3j YYEE87GYq1CMevzhReBoquX6AloTVichCAHiPtm0zxUCBgF61ry/oEOCLQCBsgkg+U tqwlaIzMQ1Kn9iyrBYa2Oa8IR6JSNkAs2mTs1b4qIRHXFsktlVQpvQ/MOo05OsoVA0 k+VI5GZrpR11cz0MTWSc8KSaE9dBvedCKb60qj0JrgEddUzMZXPBP67yKiG61UYT0L i3tPHKT5pgsn3Su3Sx9Id546bJ65Lzv6jR+uvHRUmD6c1lVsReyu+StPjpJSmMACL6 qYnn/yD6dwalA== Date: Mon, 29 Jul 2024 17:42:17 -0700 Subject: [PATCH 071/115] xfs: add parent pointer ioctls From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843441.1338752.8625477521249513852.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 233f4e12bbb2c5fb1588b857336a26e8bb6942af This patch adds a pair of new file ioctls to retrieve the parent pointer of a given inode. They both return the same results, but one operates on the file descriptor passed to ioctl() whereas the other allows the caller to specify a file handle for which the caller wants results. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_fs.h | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_ondisk.h | 5 +++ libxfs/xfs_parent.c | 34 +++++++++++++++++++++++ libxfs/xfs_parent.h | 5 +++ 4 files changed, 118 insertions(+) diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index 97384ab95..ea654df05 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -816,6 +816,78 @@ struct xfs_exchange_range { XFS_EXCHANGE_RANGE_DRY_RUN | \ XFS_EXCHANGE_RANGE_FILE1_WRITTEN) +/* Iterating parent pointers of files. */ + +/* target was the root directory */ +#define XFS_GETPARENTS_OFLAG_ROOT (1U << 0) + +/* Cursor is done iterating pptrs */ +#define XFS_GETPARENTS_OFLAG_DONE (1U << 1) + +#define XFS_GETPARENTS_OFLAGS_ALL (XFS_GETPARENTS_OFLAG_ROOT | \ + XFS_GETPARENTS_OFLAG_DONE) + +#define XFS_GETPARENTS_IFLAGS_ALL (0) + +struct xfs_getparents_rec { + struct xfs_handle gpr_parent; /* Handle to parent */ + __u32 gpr_reclen; /* Length of entire record */ + __u32 gpr_reserved; /* zero */ + char gpr_name[]; /* Null-terminated filename */ +}; + +/* Iterate through this file's directory parent pointers */ +struct xfs_getparents { + /* + * Structure to track progress in iterating the parent pointers. + * Must be initialized to zeroes before the first ioctl call, and + * not touched by callers after that. + */ + struct xfs_attrlist_cursor gp_cursor; + + /* Input flags: XFS_GETPARENTS_IFLAG* */ + __u16 gp_iflags; + + /* Output flags: XFS_GETPARENTS_OFLAG* */ + __u16 gp_oflags; + + /* Size of the gp_buffer in bytes */ + __u32 gp_bufsize; + + /* Must be set to zero */ + __u64 gp_reserved; + + /* Pointer to a buffer in which to place xfs_getparents_rec */ + __u64 gp_buffer; +}; + +static inline struct xfs_getparents_rec * +xfs_getparents_first_rec(struct xfs_getparents *gp) +{ + return (struct xfs_getparents_rec *)(uintptr_t)gp->gp_buffer; +} + +static inline struct xfs_getparents_rec * +xfs_getparents_next_rec(struct xfs_getparents *gp, + struct xfs_getparents_rec *gpr) +{ + void *next = ((void *)gpr + gpr->gpr_reclen); + void *end = (void *)(uintptr_t)(gp->gp_buffer + gp->gp_bufsize); + + if (next >= end) + return NULL; + + return next; +} + +/* Iterate through this file handle's directory parent pointers. */ +struct xfs_getparents_by_handle { + /* Handle to file whose parents we want. */ + struct xfs_handle gph_handle; + + struct xfs_getparents gph_request; +}; + /* * ioctl commands that are used by Linux filesystems */ @@ -851,6 +923,8 @@ struct xfs_exchange_range { /* XFS_IOC_GETFSMAP ------ hoisted 59 */ #define XFS_IOC_SCRUB_METADATA _IOWR('X', 60, struct xfs_scrub_metadata) #define XFS_IOC_AG_GEOMETRY _IOWR('X', 61, struct xfs_ag_geometry) +#define XFS_IOC_GETPARENTS _IOWR('X', 62, struct xfs_getparents) +#define XFS_IOC_GETPARENTS_BY_HANDLE _IOWR('X', 63, struct xfs_getparents_by_handle) /* * ioctl commands that replace IRIX syssgi()'s diff --git a/libxfs/xfs_ondisk.h b/libxfs/xfs_ondisk.h index 25952ef58..e8cdd77d0 100644 --- a/libxfs/xfs_ondisk.h +++ b/libxfs/xfs_ondisk.h @@ -156,6 +156,11 @@ xfs_check_ondisk_structs(void) XFS_CHECK_OFFSET(struct xfs_efi_log_format_32, efi_extents, 16); XFS_CHECK_OFFSET(struct xfs_efi_log_format_64, efi_extents, 16); + /* parent pointer ioctls */ + XFS_CHECK_STRUCT_SIZE(struct xfs_getparents_rec, 32); + XFS_CHECK_STRUCT_SIZE(struct xfs_getparents, 40); + XFS_CHECK_STRUCT_SIZE(struct xfs_getparents_by_handle, 64); + /* * The v5 superblock format extended several v4 header structures with * additional data. While new fields are only accessible on v5 diff --git a/libxfs/xfs_parent.c b/libxfs/xfs_parent.c index a53b7d13d..bb0465197 100644 --- a/libxfs/xfs_parent.c +++ b/libxfs/xfs_parent.c @@ -254,3 +254,37 @@ xfs_parent_replacename( xfs_attr_defer_add(&ppargs->args, XFS_ATTR_DEFER_REPLACE); return 0; } + +/* + * Extract parent pointer information from any parent pointer xattr into + * @parent_ino/gen. The last two parameters can be NULL pointers. + * + * Returns 0 if this is not a parent pointer xattr at all; or -EFSCORRUPTED for + * garbage. + */ +int +xfs_parent_from_attr( + struct xfs_mount *mp, + unsigned int attr_flags, + const unsigned char *name, + unsigned int namelen, + const void *value, + unsigned int valuelen, + xfs_ino_t *parent_ino, + uint32_t *parent_gen) +{ + const struct xfs_parent_rec *rec = value; + + ASSERT(attr_flags & XFS_ATTR_PARENT); + + if (!xfs_parent_namecheck(attr_flags, name, namelen)) + return -EFSCORRUPTED; + if (!xfs_parent_valuecheck(mp, value, valuelen)) + return -EFSCORRUPTED; + + if (parent_ino) + *parent_ino = be64_to_cpu(rec->p_ino); + if (parent_gen) + *parent_gen = be32_to_cpu(rec->p_gen); + return 0; +} diff --git a/libxfs/xfs_parent.h b/libxfs/xfs_parent.h index 768633b31..d7ab09e73 100644 --- a/libxfs/xfs_parent.h +++ b/libxfs/xfs_parent.h @@ -91,4 +91,9 @@ int xfs_parent_replacename(struct xfs_trans *tp, struct xfs_inode *new_dp, const struct xfs_name *new_name, struct xfs_inode *child); +int xfs_parent_from_attr(struct xfs_mount *mp, unsigned int attr_flags, + const unsigned char *name, unsigned int namelen, + const void *value, unsigned int valuelen, + xfs_ino_t *parent_ino, uint32_t *parent_gen); + #endif /* __XFS_PARENT_H__ */ From patchwork Tue Jul 30 00:42:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745993 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2587C4A21 for ; Tue, 30 Jul 2024 00:42:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300154; cv=none; b=dj6IWZpfPwKmg3BEzNV+//OqYjZHzVdGsPb+2f7BY8CHupyWDq/Vdc6HfZLI6aufByazGeCQO8QVf5R2nI/I0j4ki1yka9tNPNtemzbijRgcizy33K9scmq8RRcF/KnTvbQd7MAZqsd5LqYvFw4Gf91oJMqYdks7HbvtEZWWkp4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300154; c=relaxed/simple; bh=o7edboGEz5g2Uf1wb5v4DBKuljeQhgBD3sfedaTrGJA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FNSdXSOf3J0ThnG+q1IzqOD90rN3BQ27N6B3zyUXVgrts8khtyRbI9V1tNuuaE0gKso1TcJ9JT4oLWbFyRFW06rnfnaE+RsVVQF9cv2j7WtpYK2nwha/O52Bawj0z/fE8mPRluzz5VjDohObHcv6LNThMI8ezd63BprIk6qJuzI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Q54bncWp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Q54bncWp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F03A6C32786; Tue, 30 Jul 2024 00:42:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300154; bh=o7edboGEz5g2Uf1wb5v4DBKuljeQhgBD3sfedaTrGJA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Q54bncWph/JNTBDJhFNfFgVXOPiYAzWQXaztf4wkg+yjaon1WxJbBCSCZTXjMSaw+ AAtCWeZqUEo3NdbdFNrmmXV7Sr40JaJaPQKPbI2CbQUz0qLrGwUF+9rn5si1LqyP4O I9iJGmGKL/OS+K36SCWXHPWZC3fX9LiIZgaZ6eXNj7cXrc7WYqiU3d7MkPUobZEfZA 8vv0aDDz6OcfLIuOlwr86+TqItTi57bUHJ8Xdq7B+RJ7bB9+BGFhyvutIxNBoKK6Yq m2z3haGSYb7QDgsSB2Kr14Tt9Llox8+xaFnkx9pK1flPHBfRpuO1498WJjNXwveiHC Dujy6z22oRr1Q== Date: Mon, 29 Jul 2024 17:42:33 -0700 Subject: [PATCH 072/115] xfs: don't remove the attr fork when parent pointers are enabled From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Allison Henderson , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843454.1338752.7271500182319070310.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Allison Henderson Source kernel commit: 7dafb449b7922c1eec6fee3ed85b679d51f0f431 When an inode is removed, it may also cause the attribute fork to be removed if it is the last attribute. This transaction gets flushed to the log, but if the system goes down before we could inactivate the symlink, the log recovery tries to inactivate this inode (since it is on the unlinked list) but the verifier trips over the remote value and leaks it. Hence we ended up with a file in this odd state on a "clean" mount. The "obvious" fix is to prohibit erasure of the attr fork to avoid tripping over the verifiers when pptrs are enabled. Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr_leaf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index faa357f15..ce20d81a4 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -888,7 +888,8 @@ xfs_attr_sf_removename( */ if (totsize == sizeof(struct xfs_attr_sf_hdr) && xfs_has_attr2(mp) && (dp->i_df.if_format != XFS_DINODE_FMT_BTREE) && - !(args->op_flags & (XFS_DA_OP_ADDNAME | XFS_DA_OP_REPLACE))) { + !(args->op_flags & (XFS_DA_OP_ADDNAME | XFS_DA_OP_REPLACE)) && + !xfs_has_parent(mp)) { xfs_attr_fork_remove(dp, args->trans); } else { xfs_idata_realloc(dp, -size, XFS_ATTR_FORK); @@ -897,7 +898,8 @@ xfs_attr_sf_removename( ASSERT(totsize > sizeof(struct xfs_attr_sf_hdr) || (args->op_flags & XFS_DA_OP_ADDNAME) || !xfs_has_attr2(mp) || - dp->i_df.if_format == XFS_DINODE_FMT_BTREE); + dp->i_df.if_format == XFS_DINODE_FMT_BTREE || + xfs_has_parent(mp)); xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_ADATA); } From patchwork Tue Jul 30 00:42:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745994 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 24B0F4A21 for ; Tue, 30 Jul 2024 00:42:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300170; cv=none; b=rN9K6G96hUkmNqFN5VpdTNErJ8NGrPfYuv/TGn891+1ah/TSqHj/loil3bou3ZD1d6wuHLnANwEFb12gwrAoChtof15Osa8LQrgyD3hgwGm4Gee6sLBbNM6Nkl7KMHVp8QrMtjRZ8uHIanwhmbVGbzl8Tn3EEnMpdWPkiSpdRrs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300170; c=relaxed/simple; bh=w/7g7Eh4p7v7mx+bYUziTSPKX7PBwRJOGJk9Zij+qjc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QzO//eN6c33xbik/23yjKme8+c8wAD1CZza2/X7+YMG6kp18yvjErGDkeLLo73rK20sL7sGshA6Zqfk12+1cOfrLfBn8VNXflOteF4EU1YEDz/Xl+hd9aGUhFLbMrZBT8ILCocEbLT3h+msmHJG9s5j9Gs297suLAcxyML349JE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U4I3HLph; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="U4I3HLph" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A00E0C32786; Tue, 30 Jul 2024 00:42:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300169; bh=w/7g7Eh4p7v7mx+bYUziTSPKX7PBwRJOGJk9Zij+qjc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=U4I3HLph1NvJt+bMnlaipi2ehmp+wtO2j47D1S5LE0nMvc4zQlx7DOEOACmzCALQw qKBO9dt0JC/42gw9ew6VAqrrnHgagaBTCJRzRop4q1nwvwj8Js+/xzXrdXodUQxoOV qcP9HfmhYlGfheMl3ql16XhnSvpi91Yhm/Jnhp+KMTs59YODGw5s8tHAd5Ci0YB+Lq Q9FbGKTM3HeHgqEQM1vNzhzExVbhcp/KIu8o3b0LNnM9XVYuS8w6VoJBvxh6ydSmD6 Bs1kt8dcS8OjETmXKClcR+aNxxCp7/nKSNT56DYyyrHSFoBpZkzM/qyeYonCGYSmDv egcXkhr2KxWNg== Date: Mon, 29 Jul 2024 17:42:49 -0700 Subject: [PATCH 073/115] xfs: add a incompat feature bit for parent pointers From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Mark Tinguely , Dave Chinner , Allison Henderson , "Darrick J. Wong" , linux-xfs@vger.kernel.org Message-ID: <172229843469.1338752.9535654513166030813.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Allison Henderson Source kernel commit: 5f98ec1cb5c264e4815e21d632ee0b3d6e700e3d Create an incompat feature bit and a fs geometry flag so that we can enable the feature in the ondisk superblock and advertise its existence to userspace. Signed-off-by: Mark Tinguely Signed-off-by: Dave Chinner Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- libxfs/xfs_format.h | 1 + libxfs/xfs_fs.h | 1 + libxfs/xfs_sb.c | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index f1818c54a..b457e457e 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -374,6 +374,7 @@ xfs_sb_has_ro_compat_feature( #define XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR (1 << 4) /* needs xfs_repair */ #define XFS_SB_FEAT_INCOMPAT_NREXT64 (1 << 5) /* large extent counters */ #define XFS_SB_FEAT_INCOMPAT_EXCHRANGE (1 << 6) /* exchangerange supported */ +#define XFS_SB_FEAT_INCOMPAT_PARENT (1 << 7) /* parent pointers */ #define XFS_SB_FEAT_INCOMPAT_ALL \ (XFS_SB_FEAT_INCOMPAT_FTYPE | \ XFS_SB_FEAT_INCOMPAT_SPINODES | \ diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index ea654df05..dd13bfa50 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -240,6 +240,7 @@ typedef struct xfs_fsop_resblks { #define XFS_FSOP_GEOM_FLAGS_INOBTCNT (1 << 22) /* inobt btree counter */ #define XFS_FSOP_GEOM_FLAGS_NREXT64 (1 << 23) /* large extent counters */ #define XFS_FSOP_GEOM_FLAGS_EXCHANGE_RANGE (1 << 24) /* exchange range */ +#define XFS_FSOP_GEOM_FLAGS_PARENT (1 << 25) /* linux parent pointers */ /* * Minimum and maximum sizes need for growth checks. diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index 2db43b805..f45ffd994 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -175,6 +175,8 @@ xfs_sb_version_to_features( features |= XFS_FEAT_NREXT64; if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_EXCHRANGE) features |= XFS_FEAT_EXCHANGE_RANGE; + if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_PARENT) + features |= XFS_FEAT_PARENT; return features; } @@ -1251,6 +1253,8 @@ xfs_fs_geometry( geo->flags |= XFS_FSOP_GEOM_FLAGS_BIGTIME; if (xfs_has_inobtcounts(mp)) geo->flags |= XFS_FSOP_GEOM_FLAGS_INOBTCNT; + if (xfs_has_parent(mp)) + geo->flags |= XFS_FSOP_GEOM_FLAGS_PARENT; if (xfs_has_sector(mp)) { geo->flags |= XFS_FSOP_GEOM_FLAGS_SECTOR; geo->logsectsize = sbp->sb_logsectsize; From patchwork Tue Jul 30 00:43:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745995 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C8FB24A21 for ; Tue, 30 Jul 2024 00:43:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300185; cv=none; b=pzUchYMNuP2PQ5MQqE+V+XOlLcIpQrhKmjOWMlzHWHAlmAWJz8i0A7prjuTMjivX4quK4thR124BUGCxhnyCsRFIJl3Z9dsUjvR7DMnzFJuUWuX88lyav4KhDS/zG3xkEMr4jEru2ttzGXrkRL4pz/Kq1D8BC1q+xnnlG4L4O90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300185; c=relaxed/simple; bh=8oev3+MAJblHPUCLzY+Z0RvOxM/ZCztk340/QD1P0fc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JRQlDSzrZQ9G9yiPA+MGyuKOyBVlh81IjXmEq+CrlmqX0xXVQSJnrRcC+jDkf9ddsonV4z9d4vbCt4v7+8JU7QnIxNI6O6s/j5JYnPXs2vExUMPlVNJt7Mm+Ma29QU728/OdtdE8YzPqTUdVCgfEJ38CpILH0P/y6aBDNUIiNSE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OnPBytT9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OnPBytT9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55F7EC4AF07; Tue, 30 Jul 2024 00:43:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300185; bh=8oev3+MAJblHPUCLzY+Z0RvOxM/ZCztk340/QD1P0fc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=OnPBytT9Xd6N3Z7BOa48sqM9UVHEobGQoAKRbOD+mQlXDIZ2odFEuD2iyv0s5cNPT pnDbJC7fanVm7OBWNKmByn37SRirarQf2iEXCCgYTcZc6kSoWuDSbSPvZwI3KPLyGj DSmthwrywmng1zYSFDLW8w6Rr0uXaf/gM9FkTen6osi3NVjoQzaU4Q/qXDY+KXlrhP QgVzSOzhJcpJ4I7L3Yh8kQoNDcdkrshLdJ/noG4aGumuUmiYl4CRE3s5NPiij9u2vC z+wKH47i4qmI9iqQR4LPY7EmILLEoqjiaGCezMEK9L4aqzF56oUDAZ5Or7fQyIAwXI +KZP0IG9SfQNg== Date: Mon, 29 Jul 2024 17:43:04 -0700 Subject: [PATCH 074/115] xfs: fix unit conversion error in xfs_log_calc_max_attrsetm_res From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Allison Henderson , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843485.1338752.13541870224423419444.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 7ea816ca4043c2bc6052f696b6aebe2c22980a03 Dave and I were discussing some recent test regressions as a result of me turning on nrext64=1 on realtime filesystems, when we noticed that the minimum log size of a 32M filesystem jumped from 954 blocks to 4287 blocks. Digging through xfs_log_calc_max_attrsetm_res, Dave noticed that @size contains the maximum estimated amount of space needed for a local format xattr, in bytes, but we feed this quantity to XFS_NEXTENTADD_SPACE_RES, which requires units of blocks. This has resulted in an overestimation of the minimum log size over the years. We should nominally correct this, but there's a backwards compatibility problem -- if we enable it now, the minimum log size will decrease. If a corrected mkfs formats a filesystem with this new smaller log size, a user will encounter mount failures on an uncorrected kernel due to the larger minimum log size computations there. Therefore, turn this on for parent pointers because it wasn't merged at all upstream when this issue was discovered. Signed-off-by: Darrick J. Wong Reviewed-by: Allison Henderson Reviewed-by: Christoph Hellwig --- libxfs/xfs_log_rlimit.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/libxfs/xfs_log_rlimit.c b/libxfs/xfs_log_rlimit.c index cba24493f..a7bbd2933 100644 --- a/libxfs/xfs_log_rlimit.c +++ b/libxfs/xfs_log_rlimit.c @@ -16,6 +16,29 @@ #include "xfs_bmap_btree.h" #include "xfs_trace.h" +/* + * Shortly after enabling the large extents count feature in 2023, longstanding + * bugs were found in the code that computes the minimum log size. Luckily, + * the bugs resulted in over-estimates of that size, so there's no impact to + * existing users. However, we don't want to reduce the minimum log size + * because that can create the situation where a newer mkfs writes a new + * filesystem that an older kernel won't mount. + * + * Therefore, we only may correct the computation starting with filesystem + * features that didn't exist in 2023. In other words, only turn this on if + * the filesystem has parent pointers. + * + * This function can be called before the XFS_HAS_* flags have been set up, + * (e.g. mkfs) so we must check the ondisk superblock. + */ +static inline bool +xfs_want_minlogsize_fixes( + struct xfs_sb *sb) +{ + return xfs_sb_is_v5(sb) && + xfs_sb_has_incompat_feature(sb, XFS_SB_FEAT_INCOMPAT_PARENT); +} + /* * Calculate the maximum length in bytes that would be required for a local * attribute value as large attributes out of line are not logged. @@ -31,6 +54,15 @@ xfs_log_calc_max_attrsetm_res( MAXNAMELEN - 1; nblks = XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK); nblks += XFS_B_TO_FSB(mp, size); + + /* + * If the feature set is new enough, correct a unit conversion error in + * the xattr transaction reservation code that resulted in oversized + * minimum log size computations. + */ + if (xfs_want_minlogsize_fixes(&mp->m_sb)) + size = XFS_B_TO_FSB(mp, size); + nblks += XFS_NEXTENTADD_SPACE_RES(mp, size, XFS_ATTR_FORK); return M_RES(mp)->tr_attrsetm.tr_logres + From patchwork Tue Jul 30 00:43:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745996 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6DF3F4A21 for ; Tue, 30 Jul 2024 00:43:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300201; cv=none; b=AEH+hruLHCsbzXl3Yqskb9PXzSIv2W7gulUSV2Tu70LQL1qnglml2DyNffMom+QF4bgJj51pzCSetDVpVKOlwNdjxi+jMjjw4hRv0eimdHLladUBh5dRVXfJKQCAKNq9IRYnrk5gt/xwZm/OROqWalVc2P4tM3jFk+h85EpsFxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300201; c=relaxed/simple; bh=CKBq5VQH4ha9m+jecPJbYxCxv1BJ4Vmu3lMW2EtRwB4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=N2ck6cJwc+e/VMyGHkvrMXybKjDtnnEqKKUWuW/PxIZ/jiOrhHGikdvXwnfyAfkuGc0BeKnP9JJ1vZ/Cvzeuzwot8j52avvj2Z1xwLJMpupN5ePjuu2CpOzuVkqAS8dxJtkx6eKl6O57bpJZ/ZZDE6nNJ7gGxDTcJ5AaVB+bUJI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NAJGi4o/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NAJGi4o/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07474C4AF0C; Tue, 30 Jul 2024 00:43:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300201; bh=CKBq5VQH4ha9m+jecPJbYxCxv1BJ4Vmu3lMW2EtRwB4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=NAJGi4o/Jtfe69RgJTacrOqBn96XgN2tyMRNiPQMd4C7ydpylXFxl2zaxIghSR47j t7Dq6zFE7nGGIrkG9pYRYfyVGr36sq7TMrDC9+iL5gkY/f1FJbYQJyXJf6eTD93GBZ 1IE+AWb5A30XIiMcujddbATRU5W4saYLzzkK+92/QjeGr4FBfi7v4nFg6hyHkY3zxZ pxkt6zqPKKdvn84WfwJkd+m1qqmvfMACCdI1OtzVCBwygvLAd5ag/aGLpNZUecU251 At0nGgtDadqAMxRshp+02RRGS8JTrLl66nFsIXI7/WeTf9uu77yVZmYMpYVNyfFSeS 4EREMNQZkGBbg== Date: Mon, 29 Jul 2024 17:43:20 -0700 Subject: [PATCH 075/115] xfs: drop compatibility minimum log size computations for reflink From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Allison Henderson , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843500.1338752.7407883717906522881.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 6ed858c7c678218aa8df9d9e75d5e9955c105415 Let's also drop the oversized minimum log computations for reflink and rmap that were the result of bugs introduced many years ago. Signed-off-by: Darrick J. Wong Reviewed-by: Allison Henderson Reviewed-by: Christoph Hellwig --- libxfs/xfs_log_rlimit.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libxfs/xfs_log_rlimit.c b/libxfs/xfs_log_rlimit.c index a7bbd2933..246d5f486 100644 --- a/libxfs/xfs_log_rlimit.c +++ b/libxfs/xfs_log_rlimit.c @@ -24,6 +24,11 @@ * because that can create the situation where a newer mkfs writes a new * filesystem that an older kernel won't mount. * + * Several years prior, we also discovered that the transaction reservations + * for rmap and reflink operations were unnecessarily large. That was fixed, + * but the minimum log size computation was left alone to avoid the + * compatibility problems noted above. Fix that too. + * * Therefore, we only may correct the computation starting with filesystem * features that didn't exist in 2023. In other words, only turn this on if * the filesystem has parent pointers. @@ -80,6 +85,15 @@ xfs_log_calc_trans_resv_for_minlogblocks( { unsigned int rmap_maxlevels = mp->m_rmap_maxlevels; + /* + * If the feature set is new enough, drop the oversized minimum log + * size computation introduced by the original reflink code. + */ + if (xfs_want_minlogsize_fixes(&mp->m_sb)) { + xfs_trans_resv_calc(mp, resv); + return; + } + /* * In the early days of rmap+reflink, we always set the rmap maxlevels * to 9 even if the AG was small enough that it would never grow to From patchwork Tue Jul 30 00:43:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745997 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CFF4E524C for ; Tue, 30 Jul 2024 00:43:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300216; cv=none; b=j/MK1lg83XMdk+gE1ZoFnDhtNUj/Eg3+JQ4R7Aihi5CEBmzjjMNYbDamrJEyUYSnH4asudRAzlv9bstuXg7K3B0f6dLnDVJVwIjhKFT5bHFtfmmb+E6AJXjpgxzxE+usa8eY8LR07IkUFICPgfdF8ZMPpTBhaMqzPqUy+WJiA3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300216; c=relaxed/simple; bh=rSuRLugBS0uhnnP0iz31CrhGTnafo25QxAP5LRhS7SQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=B5UBZlTdOWIRAwZUQU0JSxvUeQRcCINjJuxz2Ac7fr7vhRBsN7IWr05ZokH6WDCODlULovC2Wt1sR4OET/KG2gNzJnovA90MSz86tqJvMienmS2kyn1gl3O+b3xul5UCzwoPFuGWy6SNKTytSDwILtHzqRRplEA8vwGIlUFa4v0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HsvS6JbW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HsvS6JbW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7D5BC32786; Tue, 30 Jul 2024 00:43:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300216; bh=rSuRLugBS0uhnnP0iz31CrhGTnafo25QxAP5LRhS7SQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=HsvS6JbW0XKU4Mi69Eb/LGyJGOXs/LVotSYoNvg5Foyq7TZOYMwhgFediIPv4f8y3 FizZrKR+YJkoU8RRyOwzUYQIBoqNyMCf/kIQSkSIZlyXnsOK56nvgqUQL6dMZoLQHs yJD284IIW3YTPCtxzg1lRyhzYC4QqJQzNmwrLgY5aZkEFrGGDGvuqaxHhU6fN5Wen+ U53egddga6v4EyiMalTHXjLDDLHgSupBrAmsB1+WfSn+sPygYxzTb0NnlWjtJ277xr WH4R1wYsg2kloE+oStb42eK0BEbE29H+1pfwhhf2Ydd/nnbTotA7faC0irBxvqY7An KKdSsgt5GPFOw== Date: Mon, 29 Jul 2024 17:43:36 -0700 Subject: [PATCH 076/115] xfs: enable parent pointers From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843515.1338752.3328406806785187710.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 67ac7091e35bd34b75c0ec77331b53ca052e0cb3 Add parent pointers to the list of supported features. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_format.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index b457e457e..61f51becf 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -382,7 +382,8 @@ xfs_sb_has_ro_compat_feature( XFS_SB_FEAT_INCOMPAT_BIGTIME | \ XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR | \ XFS_SB_FEAT_INCOMPAT_NREXT64 | \ - XFS_SB_FEAT_INCOMPAT_EXCHRANGE) + XFS_SB_FEAT_INCOMPAT_EXCHRANGE | \ + XFS_SB_FEAT_INCOMPAT_PARENT) #define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL static inline bool From patchwork Tue Jul 30 00:43:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745998 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 74AA05C96 for ; Tue, 30 Jul 2024 00:43:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300232; cv=none; b=lPyxIYafVBhdoGKKMnGnWuj7ZX3nzNlmUGztjnx2qVyxem49UU7RwT1u4AMvuY6hUByMWfBp3fVhR/0OANmoZH2hJvbdXKrs1lCWEu2WtFCk0HpNtafEcGKYD2WOAuZdVzC+BpSL5NpE4uhLzmLSbVirKSvB7O/hsOlpdtZ8kAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300232; c=relaxed/simple; bh=nXCYp8NGfklbGzFykjoVKDGFqGM7UWWmDnHxe5sgExc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jngEW98qOO9KAWsAmL4MeTvfoKTSWWO1tEUQNDvPJS1255i6xu8adgebZ0N9zmIOm/uhuUhPhxxf2IxuR64Vy70TqO6vS/11faGeQR3BJJTl44rU4x0INJHq1OWNhF3RJxsQqkIfHCGWErQDj1JYZRBo4azs1uFGYvSNoctE/5I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SUZJvPhl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SUZJvPhl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48711C32786; Tue, 30 Jul 2024 00:43:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300232; bh=nXCYp8NGfklbGzFykjoVKDGFqGM7UWWmDnHxe5sgExc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=SUZJvPhlUKtj0vx6TwQ3HHViSMJIvWmbeAwetAe9ieY/cktq+kxtFCVy0BtGa8mPh I4iJ5nBXjpFTtu+F+AuQm+DFq/eYE3o80eygliBNGAjYhcdcsoYpf2kr0r4CrukRH5 ZOZs452p3b3exo6BOHGSEKycn18L9d1llIoXlPwFAQg6hwWkguhNSGqgT+Zzd6DgIB l/FzTcwOKe2PUa0JQZzMIX04P7Jy4cyjf5iajWId/Rx5+BfKnS6qQLBQouwlFhQB3u FDExjpIuhq+j+8EycdFDUNUDlYcAmLBMnHCLqkHdZ8Nk+8rS9ZLx/ybtUppyKCJMri AHsubbdJdNLWQ== Date: Mon, 29 Jul 2024 17:43:51 -0700 Subject: [PATCH 077/115] xfs: check dirents have parent pointers From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843530.1338752.11619267767899663328.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 61b3f0df5c235806d372aaf696ce9aee7746d18f If the fs has parent pointers, we need to check that each child dirent points to a file that has a parent pointer pointing back at us. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_parent.c | 22 ++++++++++++++++++++++ libxfs/xfs_parent.h | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/libxfs/xfs_parent.c b/libxfs/xfs_parent.c index bb0465197..8c29ba61c 100644 --- a/libxfs/xfs_parent.c +++ b/libxfs/xfs_parent.c @@ -288,3 +288,25 @@ xfs_parent_from_attr( *parent_gen = be32_to_cpu(rec->p_gen); return 0; } + +/* + * Look up a parent pointer record (@parent_name -> @pptr) of @ip. + * + * Caller must hold at least ILOCK_SHARED. The scratchpad need not be + * initialized. + * + * Returns 0 if the pointer is found, -ENOATTR if there is no match, or a + * negative errno. + */ +int +xfs_parent_lookup( + struct xfs_trans *tp, + struct xfs_inode *ip, + const struct xfs_name *parent_name, + struct xfs_parent_rec *pptr, + struct xfs_da_args *scratch) +{ + memset(scratch, 0, sizeof(struct xfs_da_args)); + xfs_parent_da_args_init(scratch, tp, pptr, ip, ip->i_ino, parent_name); + return xfs_attr_get_ilocked(scratch); +} diff --git a/libxfs/xfs_parent.h b/libxfs/xfs_parent.h index d7ab09e73..977885823 100644 --- a/libxfs/xfs_parent.h +++ b/libxfs/xfs_parent.h @@ -96,4 +96,9 @@ int xfs_parent_from_attr(struct xfs_mount *mp, unsigned int attr_flags, const void *value, unsigned int valuelen, xfs_ino_t *parent_ino, uint32_t *parent_gen); +/* Repair functions */ +int xfs_parent_lookup(struct xfs_trans *tp, struct xfs_inode *ip, + const struct xfs_name *name, struct xfs_parent_rec *pptr, + struct xfs_da_args *scratch); + #endif /* __XFS_PARENT_H__ */ From patchwork Tue Jul 30 00:44:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13745999 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1D3CC6FB0 for ; Tue, 30 Jul 2024 00:44:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300248; cv=none; b=SmU65tniilKPCQOxvZGUKAN4QBqFosTTDauwZLiCDiMnRleDkscAXPzHDLoOQi5tUP8N3p/0JCp5lvMfxtF/oxhH7V1gZKizdWgC3HNatrPQAJqttoc/D8JPBkqf2n2EYZZ4hJ/oKFUCsDY8BUDcyJ1CgOPX6fn7l9VHecPLTyE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300248; c=relaxed/simple; bh=ubCSuFclBFM6vnnnx0GRGnRh66vzbhSDV33CYSFyBkc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kMfx9NhshZkNtmWVn1LH3PVpftGHzL1RMn+GouzGpl9SW1yK1tsjz5HJlbTNrtPNVnYOAsfr/evY2HCMLh77e3jz6Oa0X5IGGfZ8JI46mz06J/J172/gsryfEw+c/mlHJv87hlgpoRRGpJRgRIx+d6VeytYRftMxTELNe+cdYnc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GWFYk/tg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GWFYk/tg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E433FC32786; Tue, 30 Jul 2024 00:44:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300247; bh=ubCSuFclBFM6vnnnx0GRGnRh66vzbhSDV33CYSFyBkc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=GWFYk/tgEeHMliXVdn3CvL6ve95o2GCyc01sA8pDoLXCGs732dyI3PkEdLjj5biG3 AvhjGDGoG/KOBIsNBhW/dzxmoLEQR7math4TSODhS49jE4naWHV+kdoUUaHydhLCIA w0XTtkNCcSbEqYXyW1Qbc5c+XWvwvBTzxlLgbNn8WAxYnqveJDpx61wcweN1BA69nd +HcQmFheEPhIDuDaW3EWLE4BKvWYja+XUhyX6H4iz2nFbZhA/pBwRNY7KiWkQ+xDHQ EUXjCjF9JFh5E0W4tQ7ffqR9pF5fCVLrtODtdVubndvYHf0eM9xHRiitQ8K86wL7xb 0sQLcYZ2PtbgQ== Date: Mon, 29 Jul 2024 17:44:07 -0700 Subject: [PATCH 078/115] xfs: remove some boilerplate from xfs_attr_set From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843546.1338752.18021774882327744843.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: e7420e75ef04787bc51688fc9bbca7da4d164a1e In preparation for online/offline repair wanting to use xfs_attr_set, move some of the boilerplate out of this function into the callers. Repair can initialize the da_args completely, and the userspace flag handling/twisting goes away once we move it to xfs_attr_change. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 344b34aa4..1034579a1 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -947,6 +947,16 @@ xfs_attr_lookup( return error; } +/* + * Make a change to the xattr structure. + * + * The caller must have initialized @args, attached dquots, and must not hold + * any ILOCKs. + * + * Returns -EEXIST for XFS_ATTRUPDATE_CREATE if the name already exists. + * Returns -ENOATTR for XFS_ATTRUPDATE_REMOVE if the name does not exist. + * Returns 0 on success, or a negative errno if something else went wrong. + */ int xfs_attr_set( struct xfs_da_args *args, @@ -960,27 +970,7 @@ xfs_attr_set( int rmt_blks = 0; unsigned int total; - if (xfs_is_shutdown(dp->i_mount)) - return -EIO; - - error = xfs_qm_dqattach(dp); - if (error) - return error; - - if (!args->owner) - args->owner = args->dp->i_ino; - args->geo = mp->m_attr_geo; - args->whichfork = XFS_ATTR_FORK; - xfs_attr_sethash(args); - - /* - * We have no control over the attribute names that userspace passes us - * to remove, so we have to allow the name lookup prior to attribute - * removal to fail as well. Preserve the logged flag, since we need - * to pass that through to the logging code. - */ - args->op_flags = XFS_DA_OP_OKNOENT | - (args->op_flags & XFS_DA_OP_LOGGED); + ASSERT(!args->trans); switch (op) { case XFS_ATTRUPDATE_UPSERT: @@ -1075,6 +1065,7 @@ xfs_attr_set( error = xfs_trans_commit(args->trans); out_unlock: xfs_iunlock(dp, XFS_ILOCK_EXCL); + args->trans = NULL; return error; out_trans_cancel: From patchwork Tue Jul 30 00:44:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746000 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C18E77464 for ; Tue, 30 Jul 2024 00:44:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300263; cv=none; b=LqH23axrI56itssbwEgV9VRBmd9Ti0lcPGQFZf4alQit6hIVGbkskLSLK23/jYuitqs0wfOFFh8knH4NnL41nWSOoCePJeAkP4G3v+zMn7d53Cbk2tmPvISVtKy7pwj3YQefudJRxHyeTfywWfUHbguslKQtgnccnC4reEfjnrM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300263; c=relaxed/simple; bh=QehzYRNJsQct/7VL7lk7XSEQLyuRMNW73amHXmQJOFk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=R8FvgC7rRCVcvf+Ff335mfnUaXntNBB27hlt4Tsb1xGjesbK0yWUFLEXojlS0Jzx25N21m2/3wXXTtywWovbJiSimFqRTjBGXiXphUvGh2aChbbmOh9OFerAeRnKgUbjGUcQ6ASUY6tqctQRMGAqtTs//uGlka/tl2COQrQMRhI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lxHOKHrp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lxHOKHrp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 943FDC32786; Tue, 30 Jul 2024 00:44:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300263; bh=QehzYRNJsQct/7VL7lk7XSEQLyuRMNW73amHXmQJOFk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=lxHOKHrpcrbTeomaRKtsHnirOPwLi76lRuEVFNlA13eAsK6OhIjqMvv6okzIDxk6j UuKXTCwHUyW5+Cb9Vs5rJJSyw+Nj3bPpbzTnB1F7Q/WEMySJVvGAy5+3M0Y6QTxBIQ mz8iXEBH99MQBoiON8a6nBZjdAyOcsB/wAPiLrfzBL01WzKDcqgEO4+ZTx4GxBqSmX Dkxtxrz5skdPW5n3EAMvrKWE1Kzus9GYC7qP+0mLlBORwCFoSxPeviJO5tvynamAnp IpvCMJ+ol1sXRWkpxduh0MqB6qafaO4iPLtiRCEc2YJ8nJyUVgWNsrRoF9XGcstjSC gtYRBNLKSsQQA== Date: Mon, 29 Jul 2024 17:44:23 -0700 Subject: [PATCH 079/115] xfs: make the reserved block permission flag explicit in xfs_attr_set From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843560.1338752.13394120078833193917.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: bf61c36a45d4c215994699a7a06a00c58d22e8a2 Make the use of reserved blocks an explicit parameter to xfs_attr_set. Userspace setting XFS_ATTR_ROOT attrs should continue to be able to use it, but for online repairs we can back out and therefore do not care. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- db/attrset.c | 4 ++-- libxfs/xfs_attr.c | 6 +++--- libxfs/xfs_attr.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/db/attrset.c b/db/attrset.c index a59d5473e..3b5db7c2a 100644 --- a/db/attrset.c +++ b/db/attrset.c @@ -161,7 +161,7 @@ attr_set_f( goto out; } - if (libxfs_attr_set(&args, op)) { + if (libxfs_attr_set(&args, op, false)) { dbprintf(_("failed to set attr %s on inode %llu\n"), args.name, (unsigned long long)iocur_top->ino); goto out; @@ -247,7 +247,7 @@ attr_remove_f( goto out; } - if (libxfs_attr_set(&args, XFS_ATTRUPDATE_REMOVE)) { + if (libxfs_attr_set(&args, XFS_ATTRUPDATE_REMOVE, false)) { dbprintf(_("failed to remove attr %s from inode %llu\n"), (unsigned char *)args.name, (unsigned long long)iocur_top->ino); diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 1034579a1..32dd7bcf5 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -951,7 +951,7 @@ xfs_attr_lookup( * Make a change to the xattr structure. * * The caller must have initialized @args, attached dquots, and must not hold - * any ILOCKs. + * any ILOCKs. Reserved data blocks may be used if @rsvd is set. * * Returns -EEXIST for XFS_ATTRUPDATE_CREATE if the name already exists. * Returns -ENOATTR for XFS_ATTRUPDATE_REMOVE if the name does not exist. @@ -960,12 +960,12 @@ xfs_attr_lookup( int xfs_attr_set( struct xfs_da_args *args, - enum xfs_attr_update op) + enum xfs_attr_update op, + bool rsvd) { struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; struct xfs_trans_res tres; - bool rsvd = (args->attr_filter & XFS_ATTR_ROOT); int error, local; int rmt_blks = 0; unsigned int total; diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h index d12583dd7..43dee4cba 100644 --- a/libxfs/xfs_attr.h +++ b/libxfs/xfs_attr.h @@ -558,7 +558,7 @@ enum xfs_attr_update { XFS_ATTRUPDATE_REPLACE, /* set value, fail if attr does not exist */ }; -int xfs_attr_set(struct xfs_da_args *args, enum xfs_attr_update op); +int xfs_attr_set(struct xfs_da_args *args, enum xfs_attr_update op, bool rsvd); int xfs_attr_set_iter(struct xfs_attr_intent *attr); int xfs_attr_remove_iter(struct xfs_attr_intent *attr); bool xfs_attr_check_namespace(unsigned int attr_flags); From patchwork Tue Jul 30 00:44:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746001 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 67F4410E3 for ; Tue, 30 Jul 2024 00:44:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300279; cv=none; b=VAvi32w54Sp5uqkJyg7367rbDPK1BDQi8m2FkoOf0OxUFXG6A8/YsZw2Z1wse+0GafxsSJKdWFB1pQDBTZJkKMG5JrqXKKgdACClNNl9dAUVkFDokVEIAhIKWUy1SWRtv7Rio1LMVKliPIG9lPfMfZEE0UrHheEE7amHx3KBve8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300279; c=relaxed/simple; bh=uGx0bxPqynBnfMwmoMiSrDHnBDi7U3fuxD9qvxvAT8A=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZrLv2EuWqKZf++Q70lUArAnpG8BPDMZxY7W8ceQibxS2R7PWrUkZeNqpBo7RwyeiwCJVOaNFYEcojgkdYIigfnhUDf4o2Lc7qAXrKHBOzJ+kGUl46+DR35lzWxBNgP9wvCLTmbq/8BrZNO0HwWOGzNIYrz+gIjdUlvXc0Lh752U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Up3ghpqb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Up3ghpqb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 442B2C32786; Tue, 30 Jul 2024 00:44:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300279; bh=uGx0bxPqynBnfMwmoMiSrDHnBDi7U3fuxD9qvxvAT8A=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Up3ghpqb3u3jp+9CPIV8qrB+qfqTzXiIvtDh5MzVWMIpgjbCvcKHPEkANSFwJaMi6 B8cxrCUBmf3rvt8uviu/jfTXaGU+iLoK4tSyTpWGfFAHb6QFbnPY2Cu2nZf1mx8Xsf RwSNj2wZtf5dXxqCPFCIlf52PchBpsOF1cZUIhytoyG8KrBv71cfAGLNcsbxRmq766 G+4k142cL9ekgDAqMZ0aHZz/IzPKr8apfh3j3GoKkcX3W7M5YWBCLR414PduLh1KIs WYEGOrIk2XufSo4NNy0whsphfL4QZRHM5unCEu2KQ5+sOCmfL/9dZ1YM0fy9xNB43N ACkCdYqht42+g== Date: Mon, 29 Jul 2024 17:44:38 -0700 Subject: [PATCH 080/115] xfs: add raw parent pointer apis to support repair From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843576.1338752.435264629744787870.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 5769aa41ee34d4d1cc2b35376107b8e9694698f0 Add a couple of utility functions to set or remove parent pointers from a file. These functions will be used by repair code, hence they skip the xattr logging that regular parent pointer updates use. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_dir2.c | 2 +- libxfs/xfs_dir2.h | 2 +- libxfs/xfs_parent.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_parent.h | 6 +++++ 4 files changed, 72 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_dir2.c b/libxfs/xfs_dir2.c index 803fb82b2..e309e1e58 100644 --- a/libxfs/xfs_dir2.c +++ b/libxfs/xfs_dir2.c @@ -433,7 +433,7 @@ int xfs_dir_removename( struct xfs_trans *tp, struct xfs_inode *dp, - struct xfs_name *name, + const struct xfs_name *name, xfs_ino_t ino, xfs_extlen_t total) /* bmap's total block count */ { diff --git a/libxfs/xfs_dir2.h b/libxfs/xfs_dir2.h index eb3a5c350..b580a78bc 100644 --- a/libxfs/xfs_dir2.h +++ b/libxfs/xfs_dir2.h @@ -58,7 +58,7 @@ extern int xfs_dir_lookup(struct xfs_trans *tp, struct xfs_inode *dp, const struct xfs_name *name, xfs_ino_t *inum, struct xfs_name *ci_name); extern int xfs_dir_removename(struct xfs_trans *tp, struct xfs_inode *dp, - struct xfs_name *name, xfs_ino_t ino, + const struct xfs_name *name, xfs_ino_t ino, xfs_extlen_t tot); extern int xfs_dir_replace(struct xfs_trans *tp, struct xfs_inode *dp, const struct xfs_name *name, xfs_ino_t inum, diff --git a/libxfs/xfs_parent.c b/libxfs/xfs_parent.c index 8c29ba61c..84220f10a 100644 --- a/libxfs/xfs_parent.c +++ b/libxfs/xfs_parent.c @@ -310,3 +310,67 @@ xfs_parent_lookup( xfs_parent_da_args_init(scratch, tp, pptr, ip, ip->i_ino, parent_name); return xfs_attr_get_ilocked(scratch); } + +/* Sanity-check a parent pointer before we try to perform repairs. */ +static inline bool +xfs_parent_sanity_check( + struct xfs_mount *mp, + const struct xfs_name *parent_name, + const struct xfs_parent_rec *pptr) +{ + if (!xfs_parent_namecheck(XFS_ATTR_PARENT, parent_name->name, + parent_name->len)) + return false; + + if (!xfs_parent_valuecheck(mp, pptr, sizeof(*pptr))) + return false; + + return true; +} + + +/* + * Attach the parent pointer (@parent_name -> @pptr) to @ip immediately. + * Caller must not have a transaction or hold the ILOCK. This is for + * specialized repair functions only. The scratchpad need not be initialized. + */ +int +xfs_parent_set( + struct xfs_inode *ip, + xfs_ino_t owner, + const struct xfs_name *parent_name, + struct xfs_parent_rec *pptr, + struct xfs_da_args *scratch) +{ + if (!xfs_parent_sanity_check(ip->i_mount, parent_name, pptr)) { + ASSERT(0); + return -EFSCORRUPTED; + } + + memset(scratch, 0, sizeof(struct xfs_da_args)); + xfs_parent_da_args_init(scratch, NULL, pptr, ip, owner, parent_name); + return xfs_attr_set(scratch, XFS_ATTRUPDATE_CREATE, false); +} + +/* + * Remove the parent pointer (@parent_name -> @pptr) from @ip immediately. + * Caller must not have a transaction or hold the ILOCK. This is for + * specialized repair functions only. The scratchpad need not be initialized. + */ +int +xfs_parent_unset( + struct xfs_inode *ip, + xfs_ino_t owner, + const struct xfs_name *parent_name, + struct xfs_parent_rec *pptr, + struct xfs_da_args *scratch) +{ + if (!xfs_parent_sanity_check(ip->i_mount, parent_name, pptr)) { + ASSERT(0); + return -EFSCORRUPTED; + } + + memset(scratch, 0, sizeof(struct xfs_da_args)); + xfs_parent_da_args_init(scratch, NULL, pptr, ip, owner, parent_name); + return xfs_attr_set(scratch, XFS_ATTRUPDATE_REMOVE, false); +} diff --git a/libxfs/xfs_parent.h b/libxfs/xfs_parent.h index 977885823..b8036527c 100644 --- a/libxfs/xfs_parent.h +++ b/libxfs/xfs_parent.h @@ -100,5 +100,11 @@ int xfs_parent_from_attr(struct xfs_mount *mp, unsigned int attr_flags, int xfs_parent_lookup(struct xfs_trans *tp, struct xfs_inode *ip, const struct xfs_name *name, struct xfs_parent_rec *pptr, struct xfs_da_args *scratch); +int xfs_parent_set(struct xfs_inode *ip, xfs_ino_t owner, + const struct xfs_name *name, struct xfs_parent_rec *pptr, + struct xfs_da_args *scratch); +int xfs_parent_unset(struct xfs_inode *ip, xfs_ino_t owner, + const struct xfs_name *name, struct xfs_parent_rec *pptr, + struct xfs_da_args *scratch); #endif /* __XFS_PARENT_H__ */ From patchwork Tue Jul 30 00:44:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746002 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 580B71361 for ; Tue, 30 Jul 2024 00:44:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300295; cv=none; b=IBHsQKgWZkYbrR8BkkixoSxJnS+XtZzlVNhvjjjzha+e++dIfzoe9SAbbPZjXDj/IlYWRr3Oags6/57NmPHMhh+olkE989WkXDXb+gqK3TgvdKOfDZLEAZ9L/L8C7lNZuhXrzP52GpV+/Z0NktZA2TbPbR/lTxr2Yqta1MsouG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300295; c=relaxed/simple; bh=YRQ/ooQPn6Ti2xooAL13FIioxNTNDR4cn/iC+p7eXzI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Wq+zrr28KOJNBYWC6WTHPrG3IA9pTKgf7z4ks/ZB+sRH9V8dvnOwwWxye527Pt4+Fr3lSGyg6kNtu5TaM47IHH1bAiAmtHre9GYebZnFIQ7OHadZWuDJzYox9gA74I3ovQECrL7eqe7oQf9helTXZjHzBfWeapHjU1GNLvItMjE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vLumEZda; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="vLumEZda" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E41B6C32786; Tue, 30 Jul 2024 00:44:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300294; bh=YRQ/ooQPn6Ti2xooAL13FIioxNTNDR4cn/iC+p7eXzI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=vLumEZdaSDHB6lS3tEupcxcmVOr74MLIUqYyDJBoK0HmgJOVdPxPynmGe/9PFQQsH 4KLO7e1ditaLi1zn0grlbznI9jql9oJzLnG3SFn27mXjbSGXrEgs8Qw4ARA4eu+Z/L w02N0GiGDQUKyRl1EqkXWMpUbiDHiHbaUbBZdHBS202Hf5FCTPnT+mZ9/EuDnG5nnL C0Vjj013JFUfOZJcZezL6ejdHT663S0yodZoGm4JdU+8hMTIdEftylx3tYUoCnWnc3 POX7QA8SVomxyxU61FN6hTVU9fU7pZF+yF0xwRpFOcq/QHfDt8d09Di8TOsCcUAx+r rQPaHGBEJpJFA== Date: Mon, 29 Jul 2024 17:44:54 -0700 Subject: [PATCH 081/115] xfs: remove pointless unlocked assertion From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843591.1338752.17976717560948537004.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 13db7007892694c891fc37feccbd2ac8f227af78 Remove this assertion about the inode not having an attr fork from xfs_bmap_add_attrfork because the function handles that case just fine. Weirder still, the function actually /requires/ the caller not to hold the ILOCK, which means that its accesses are not stabilized. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_bmap.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 81dccf275..4cd0ffa42 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -1035,8 +1035,6 @@ xfs_bmap_add_attrfork( int logflags; /* logging flags */ int error; /* error return value */ - ASSERT(xfs_inode_has_attr_fork(ip) == 0); - mp = ip->i_mount; ASSERT(!XFS_NOT_DQATTACHED(mp, ip)); From patchwork Tue Jul 30 00:45:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746003 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 EFD8E23C9 for ; Tue, 30 Jul 2024 00:45:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300311; cv=none; b=FalMCrqJTfS12A7eKYfToI1/HDA39UauqAmiNuIswqRrs+cqwQPFMQ9ZqyNhkCXlVCaizOOoC2vuU1iqmXMsnZ7K19O8uZaSbvZARnrhvmAsVwLlxYQcGvbhPet2/BFAzaVrc189Fzw/1odemhhv1ItZ8fE26OHvUYtSAYPHmxQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300311; c=relaxed/simple; bh=1ceCEWn/zEVKgxW5gIqn+9Zry2/aNbLG8HteO8ZKluA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DdPbebaYbjt5JpfRIF5OMALy4qZ8zG51Y3pEa1+0pLVtpsP0KRXYAMJ0SbRfwuLODnXIsNsCCHmqoJjvtb7AIWNYLr61XutiM5IfbzMI7Rd0a3ZvVWV5TeXNtAlGuUnk8PwZgBte5eJOs/GNLiQVzwK5f7bNCosf2j4T5tyPeuw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WfJCI7MG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WfJCI7MG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8411DC32786; Tue, 30 Jul 2024 00:45:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300310; bh=1ceCEWn/zEVKgxW5gIqn+9Zry2/aNbLG8HteO8ZKluA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=WfJCI7MGVVbVl0hsLn97+GUa2N7kVRYOBfxnPR5Rxu7KCID081uQ1EQGmkoI0dhdS kLNH5e1BRiehn5raIQ0Fok0gvyWxNPs3LpF52AD5p/N39Yewa5qeDa3zkFn5C4HaM+ ulqnwW7LmzlTOTtHYXRjlBWJ+w0FrdkLO2qdVKzFtvOxaCfIFOGdtYQ3zxEF79Ot8i 6cYbRQUKhOfgBCSVOui+lvmf/qQrkK6sTv+wmDXhrTnhEj7CYYXNhSxAW2rDuogFz7 bf8hhzEmVTWc59fzTJjdlX7nkfOM9Ok6y9GLYY7zrgMMwci7jKTdpvJVQyF1dvGyGq PvrjmdddWlrLw== Date: Mon, 29 Jul 2024 17:45:10 -0700 Subject: [PATCH 082/115] xfs: split xfs_bmap_add_attrfork into two pieces From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843606.1338752.11606844450758887771.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 55edcd1f86474f973fccf5c5ccc8bc7908893142 Split this function into two pieces -- one to make the actual changes to the inode core to add the attr fork, and another one to deal with getting the transaction and locking the inodes. The next couple of patches will need this to be split into two. One patch implements committing new parent pointer recordsets to damaged files. If one file has an attr fork and the other does not, we have to create the missing attr fork before the atomic swap transaction, and can use the behavior encoded in the current xfs_bmap_add_attrfork. The second patch adapts /lost+found adoptions to handle parent pointers correctly. The adoption process will add a parent pointer to a child that is being moved to /lost+found, but this requires that the attr fork already exists. We don't know if we're actually going to commit the adoption until we've already reserved a transaction and taken the ILOCKs, which means that we must have a way to bypass the start of the current xfs_bmap_add_attrfork. Therefore, create xfs_attr_add_fork as the helper that creates a transaction and takes locks; and make xfs_bmap_add_attrfork the function that updates the inode core and allocates the incore attr fork. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr.c | 39 ++++++++++++++++++++++++++++++++++++++- libxfs/xfs_bmap.c | 36 ++++++++++-------------------------- libxfs/xfs_bmap.h | 3 ++- 3 files changed, 50 insertions(+), 28 deletions(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 32dd7bcf5..f94e74879 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -947,6 +947,43 @@ xfs_attr_lookup( return error; } +STATIC int +xfs_attr_add_fork( + struct xfs_inode *ip, /* incore inode pointer */ + int size, /* space new attribute needs */ + int rsvd) /* xact may use reserved blks */ +{ + struct xfs_mount *mp = ip->i_mount; + struct xfs_trans *tp; /* transaction pointer */ + unsigned int blks; /* space reservation */ + int error; /* error return value */ + + ASSERT(!XFS_NOT_DQATTACHED(mp, ip)); + + blks = XFS_ADDAFORK_SPACE_RES(mp); + + error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_addafork, blks, 0, + rsvd, &tp); + if (error) + return error; + + if (xfs_inode_has_attr_fork(ip)) + goto trans_cancel; + + error = xfs_bmap_add_attrfork(tp, ip, size, rsvd); + if (error) + goto trans_cancel; + + error = xfs_trans_commit(tp); + xfs_iunlock(ip, XFS_ILOCK_EXCL); + return error; + +trans_cancel: + xfs_trans_cancel(tp); + xfs_iunlock(ip, XFS_ILOCK_EXCL); + return error; +} + /* * Make a change to the xattr structure. * @@ -988,7 +1025,7 @@ xfs_attr_set( xfs_attr_sf_entsize_byname(args->namelen, args->valuelen); - error = xfs_bmap_add_attrfork(dp, sf_size, rsvd); + error = xfs_attr_add_fork(dp, sf_size, rsvd); if (error) return error; } diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 4cd0ffa42..def73fd50 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -1019,38 +1019,29 @@ xfs_bmap_set_attrforkoff( } /* - * Convert inode from non-attributed to attributed. - * Must not be in a transaction, ip must not be locked. + * Convert inode from non-attributed to attributed. Caller must hold the + * ILOCK_EXCL and the file cannot have an attr fork. */ int /* error code */ xfs_bmap_add_attrfork( - xfs_inode_t *ip, /* incore inode pointer */ + struct xfs_trans *tp, + struct xfs_inode *ip, /* incore inode pointer */ int size, /* space new attribute needs */ int rsvd) /* xact may use reserved blks */ { - xfs_mount_t *mp; /* mount structure */ - xfs_trans_t *tp; /* transaction pointer */ - int blks; /* space reservation */ + struct xfs_mount *mp = tp->t_mountp; int version = 1; /* superblock attr version */ int logflags; /* logging flags */ int error; /* error return value */ - mp = ip->i_mount; + xfs_assert_ilocked(ip, XFS_ILOCK_EXCL); ASSERT(!XFS_NOT_DQATTACHED(mp, ip)); - - blks = XFS_ADDAFORK_SPACE_RES(mp); - - error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_addafork, blks, 0, - rsvd, &tp); - if (error) - return error; - if (xfs_inode_has_attr_fork(ip)) - goto trans_cancel; + ASSERT(!xfs_inode_has_attr_fork(ip)); xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); error = xfs_bmap_set_attrforkoff(ip, size, &version); if (error) - goto trans_cancel; + return error; xfs_ifork_init_attr(ip, XFS_DINODE_FMT_EXTENTS, 0); logflags = 0; @@ -1071,7 +1062,7 @@ xfs_bmap_add_attrfork( if (logflags) xfs_trans_log_inode(tp, ip, logflags); if (error) - goto trans_cancel; + return error; if (!xfs_has_attr(mp) || (!xfs_has_attr2(mp) && version == 2)) { bool log_sb = false; @@ -1090,14 +1081,7 @@ xfs_bmap_add_attrfork( xfs_log_sb(tp); } - error = xfs_trans_commit(tp); - xfs_iunlock(ip, XFS_ILOCK_EXCL); - return error; - -trans_cancel: - xfs_trans_cancel(tp); - xfs_iunlock(ip, XFS_ILOCK_EXCL); - return error; + return 0; } /* diff --git a/libxfs/xfs_bmap.h b/libxfs/xfs_bmap.h index 32fb2a455..e98849eb9 100644 --- a/libxfs/xfs_bmap.h +++ b/libxfs/xfs_bmap.h @@ -176,7 +176,8 @@ int xfs_bmap_longest_free_extent(struct xfs_perag *pag, void xfs_trim_extent(struct xfs_bmbt_irec *irec, xfs_fileoff_t bno, xfs_filblks_t len); unsigned int xfs_bmap_compute_attr_offset(struct xfs_mount *mp); -int xfs_bmap_add_attrfork(struct xfs_inode *ip, int size, int rsvd); +int xfs_bmap_add_attrfork(struct xfs_trans *tp, struct xfs_inode *ip, + int size, int rsvd); void xfs_bmap_local_to_extents_empty(struct xfs_trans *tp, struct xfs_inode *ip, int whichfork); int xfs_bmap_local_to_extents(struct xfs_trans *tp, struct xfs_inode *ip, From patchwork Tue Jul 30 00:45:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746004 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B2AB3637 for ; Tue, 30 Jul 2024 00:45:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300326; cv=none; b=HomNnMhgKYPjiKawgzPqhOG4+MQBEqrnzg0ci13pmlVViE7zHF/+c58RTM/C52rS99AarhJZmBXmkULhTvoaKwGUIgQ/+DmCE+oAEl9XelM9GXrbTDXKgDeKfa86XCiQp2maxtfUY1/WKTgsR36ExMolTHOxvf7OxEEFtXfU1tQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300326; c=relaxed/simple; bh=ANNX6y9GsyIBMAVJva7ThZTkbGnteSoVwsdMaTa87Iw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Cru0zt3TiatVe0DO2sQJcnfQyWLGG5r0bu4Y2AyZt6eEWPcRqWzYnTJ3EbkUXw9rFEan+7faUlkNjpoHvpFA9LyDouVeTOU3xKolSggJS+OYcv+2ofCXx9s+Gx8DLUSfAlgqZ9EcSVdP66Lks7MjPBAGck1tDceyfUmZOF1CS5Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hkk7qCLH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hkk7qCLH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A736C32786; Tue, 30 Jul 2024 00:45:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300326; bh=ANNX6y9GsyIBMAVJva7ThZTkbGnteSoVwsdMaTa87Iw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=hkk7qCLHRinRMWI5Obvm1kxMddH78sgDhIcTERd9csZeNCSRaUh2SNX43AtqtCYoP 4vNClY0rtlYQtq/N/1lE1fKUrbNThx2zUwQM+O42IBX1NedZam0v+Rd8fmK4uW/YTK VUY7bYeguNUeyHQVG6so5rPhQATOXXwW5+vKXZfUdey6TxZCG4hWA2oESH/J48QHU6 UIA4j669+CnkshEWqd19uEP7o03JZA146VT/MrVJ2XbFaf/Ajohs2Vt9ThFmYfRPPs luNEYzYC+FstBpcIQfh3jSOpMfG5N0cxgM9EJqtJf+SU/Jn2Llz445bltzKeFi6vb6 DkolUP01qtJwg== Date: Mon, 29 Jul 2024 17:45:25 -0700 Subject: [PATCH 083/115] xfs: actually rebuild the parent pointer xattrs From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843622.1338752.17056521462803904852.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: a26dc21309af68623b82b4e366cbbeb5a85ce65b Once we've assembled all the parent pointers for a file, we need to are embedded in the xattr structure, which means that we must write a new extended attribute structure, again, atomically. Therefore, we must copy the non-parent-pointer attributes from the file being repaired into the temporary file's extended attributes and then call the atomic extent swap mechanism to exchange the blocks. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr.c | 2 +- libxfs/xfs_attr.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index f94e74879..52fcb1c4c 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -947,7 +947,7 @@ xfs_attr_lookup( return error; } -STATIC int +int xfs_attr_add_fork( struct xfs_inode *ip, /* incore inode pointer */ int size, /* space new attribute needs */ diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h index 43dee4cba..088cb7b30 100644 --- a/libxfs/xfs_attr.h +++ b/libxfs/xfs_attr.h @@ -648,5 +648,6 @@ int __init xfs_attr_intent_init_cache(void); void xfs_attr_intent_destroy_cache(void); int xfs_attr_sf_totsize(struct xfs_inode *dp); +int xfs_attr_add_fork(struct xfs_inode *ip, int size, int rsvd); #endif /* __XFS_ATTR_H__ */ From patchwork Tue Jul 30 00:45:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746005 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F04CC10E9 for ; Tue, 30 Jul 2024 00:45:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300342; cv=none; b=Qf9Vw+DbNXUePQjyawLjYHpFppCMfuCmBtFAIE8Jqwb29muJa5XHnsvKwtHy69NejRoP2cyGiaLRQgD/oKuvZIxMiQxT8tNC3UvPsTR5dK+d7QTNuimGfiQFOy8kLOAWCWdGaA6ZPIIXgQ9wFtYk4YYT+PNo/W/DiHnvU8Qjyic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300342; c=relaxed/simple; bh=dXRjIsdbYItqDORc78iq4r2C34Aa2hlCnNcb5V9PRsc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LeXYY3W4wr3UK55Bc7/pN3rlG9/4TV/ama/N0+Feh47TW6cC+wJuTg/pVvZPzNl20/XUVMBEqFGB2SY5/dX57qrlyB9u8vBNphEdN03dqb+tZrH471CDTeji3EIJ5E+LiO0HTfTiJ7BE7krVd1umyBgl/ldwGpvPZRCFDwAJGGM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fRTy9SO0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fRTy9SO0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA0DDC32786; Tue, 30 Jul 2024 00:45:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300341; bh=dXRjIsdbYItqDORc78iq4r2C34Aa2hlCnNcb5V9PRsc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=fRTy9SO0PAclornCvB0z1NnlG+7qPgk/ZQ2ZAfHHk6HACIH6xBueeyXTK8VmGUagV Daqxq3fM8T1HTSNv5/sCBstiwPuKqGiNsqv6SeCsPpZsTNCoM5D9KbnANfhIMVhEtl KRU1RxiIILStb8XdmKxLrXxkfgCccnguVwWuR5yCJi6C1BOsnc/Zz+i+gdbPn92FGL Fiinpt9yfe3v+HqhVmE+zNkO2OcNJHW/g8NKnbu7ttCS7M786o6jJxmCUzDHVGjiPS f/ytmKQDQyLcjMoriMKGTfWxJf/3UcpWIF+Pisxw98NopB4emLVkF3hu3OC9AK/KWy LpOE71lx0N1oQ== Date: Mon, 29 Jul 2024 17:45:41 -0700 Subject: [PATCH 084/115] xfs: teach online scrub to find directory tree structure problems From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843637.1338752.16678515437880585817.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 928b721a11789a9363d6d7c32a1f3166a79f3b5f Create a new scrubber that detects corruptions within the directory tree structure itself. It can detect directories with multiple parents; loops within the directory tree; and directory loops not accessible from the root. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_fs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index dd13bfa50..85f2a7e20 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -719,9 +719,10 @@ struct xfs_scrub_metadata { #define XFS_SCRUB_TYPE_QUOTACHECK 25 /* quota counters */ #define XFS_SCRUB_TYPE_NLINKS 26 /* inode link counts */ #define XFS_SCRUB_TYPE_HEALTHY 27 /* everything checked out ok */ +#define XFS_SCRUB_TYPE_DIRTREE 28 /* directory tree structure */ /* Number of scrub subcommands. */ -#define XFS_SCRUB_TYPE_NR 28 +#define XFS_SCRUB_TYPE_NR 29 /* i: Repair this metadata. */ #define XFS_SCRUB_IFLAG_REPAIR (1u << 0) From patchwork Tue Jul 30 00:45:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746006 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 DC24963D for ; Tue, 30 Jul 2024 00:45:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300357; cv=none; b=d1khnnQ09jTa7x1XG0qXq7k5fy2Ys1GZ82XFs/B34H0rgcilQyXsBrG1qx5H4aouP4NGmNLPoXMY2Dg/e71u9IQzmaSUyehJjb19tQBFJNcDsAJM7vnVLGUadpwGQm8cCzLhcWo11PD4IT77bLs4ElxbtT4t5U4ejnrpzrlCWYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300357; c=relaxed/simple; bh=CRUYQx5snKVYWwdu7tbWexDeV8aGc2ic6GE7Sx+ot2I=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qvMl8+5LdoDlmzSZehJtVeKLSB2is5kkMZ+G8nf6/h39+WGxInC1tlCgYWfyEFOXz9LlqSjVSQUyeW4LxR9FBFPs4bhSO1yEBmLIGJIKDFC4enErC92dKyT6LAfmjkbkINCYgCVGtqvZnmE4LLS5D3VMM/2jYUYoTgdx0RwXO2Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S5tnHn6p; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S5tnHn6p" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B3B8C32786; Tue, 30 Jul 2024 00:45:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300357; bh=CRUYQx5snKVYWwdu7tbWexDeV8aGc2ic6GE7Sx+ot2I=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=S5tnHn6p1CzwfDd4bbqwbSpEebQln4sItqGlvw7QjTN+/WfXn3YLc15Ex4uxfO3tY IufnL9C/V8Fy55JITpFoSJaOIMIx7XUOkwZuiiBA4sfz3f15VveXFzRoWCb1JONB7l 81wpS6hAvYyD2qwC42CuvQcZd48zpm+bpDLBpsm0nTqnQwHcsgnWNxQdf8pNsKLlf5 LpWmhxOcK89bxqL2p3kH9O24ISXM733an8GQNGLgjCQZvTPfcz5qbwExB8dsz40WNt cD3Gs7/juI8p2VH+vvRxMEjI+MTl2NhByuHE4+JCfrytp+7SDsH5nBNvzdNfDr4bhS LF+lwzpaeaNfg== Date: Mon, 29 Jul 2024 17:45:56 -0700 Subject: [PATCH 085/115] xfs: report directory tree corruption in the health information From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843652.1338752.3168191725388025794.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 37056912d5721324ac28787a4f903798f7361099 Report directories that are the source of corruption in the directory tree. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_fs.h | 1 + libxfs/xfs_health.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index 85f2a7e20..7ae1912cd 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -411,6 +411,7 @@ struct xfs_bulkstat { #define XFS_BS_SICK_XATTR (1 << 5) /* extended attributes */ #define XFS_BS_SICK_SYMLINK (1 << 6) /* symbolic link remote target */ #define XFS_BS_SICK_PARENT (1 << 7) /* parent pointers */ +#define XFS_BS_SICK_DIRTREE (1 << 8) /* directory tree structure */ /* * Project quota id helpers (previously projid was 16bit only diff --git a/libxfs/xfs_health.h b/libxfs/xfs_health.h index 3c64b5f9b..b0edb4288 100644 --- a/libxfs/xfs_health.h +++ b/libxfs/xfs_health.h @@ -95,6 +95,7 @@ struct xfs_da_args; /* Don't propagate sick status to ag health summary during inactivation */ #define XFS_SICK_INO_FORGET (1 << 12) +#define XFS_SICK_INO_DIRTREE (1 << 13) /* directory tree structure */ /* Primary evidence of health problems in a given group. */ #define XFS_SICK_FS_PRIMARY (XFS_SICK_FS_COUNTERS | \ @@ -125,7 +126,8 @@ struct xfs_da_args; XFS_SICK_INO_DIR | \ XFS_SICK_INO_XATTR | \ XFS_SICK_INO_SYMLINK | \ - XFS_SICK_INO_PARENT) + XFS_SICK_INO_PARENT | \ + XFS_SICK_INO_DIRTREE) #define XFS_SICK_INO_ZAPPED (XFS_SICK_INO_BMBTD_ZAPPED | \ XFS_SICK_INO_BMBTA_ZAPPED | \ From patchwork Tue Jul 30 00:46:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746007 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 73F48139D for ; Tue, 30 Jul 2024 00:46:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300373; cv=none; b=e2AR//vNC3zGMMMupcawSuzqABlD2Qh/kpoqKpKGK2Ca8quoixRcNU3xx4qyurpkyI8cObiTAbekvbRrW4zf7xhLfFrPV/MogR6lUhyWj7qrulyFdBDvIdT6l5L5SXTLOblslVS5y2W1bOg4H3Hl6kKQ3Yib6FVmuxgIF0kJKBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300373; c=relaxed/simple; bh=qH8EgIw8LCeh2T0eaoiEoqPsF/2Ln5OKI5T3OVDu1iU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lMFuN/JmJR7EB3tn8N6ku8zvPnMkXHgfZ/PR20Dd4L6iTjoQ0JZWQ9m2dCok0cYu3rG4Qv0TKYr+e/3YdgH9XciMXavsZyGaf8QvkmUtEtKhaImOLPQRhW2HDjJqOexi7Dpcc7lkBvX4feH7DgdFkHPp25x6sZw5fyiXvBESCQI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IfSq2LbQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IfSq2LbQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13D5CC32786; Tue, 30 Jul 2024 00:46:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300373; bh=qH8EgIw8LCeh2T0eaoiEoqPsF/2Ln5OKI5T3OVDu1iU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=IfSq2LbQbINLP7vIGiaR14Nw1DsfAJmylbRoBuF3CzFNNl//8/IoobMM4fnvmvD2l KSOY+opTpx/Q2kIaa3f3Egj8MPtRMLms/jzrpegljKNXeV7GNOnaDsbnm2lo96j4Gt ONjOZHEJbBBCUuQsK9L10tRpRMge6KHhmGtUzvSmzSeZby6YAAb8ag1Oqi8sqOE4Vo sSjgr7Zwbd6CNdUsP+ZOQXvxulx/pFF2N6t649b91aeY2YyV//KsBBzqaShYWJ6ey+ RtwPcfb+bngmZb3B66B6OH5hToFx/IxfjSW6kvyvmQ981IPqz3uQUqvgPe3tfE8mzM 175dpn4wAzkMA== Date: Mon, 29 Jul 2024 17:46:12 -0700 Subject: [PATCH 086/115] xfs: introduce vectored scrub mode From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843667.1338752.17925658320142397328.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: c77b37584c2d1054452853e47e42c7350b8fe687 Introduce a variant on XFS_SCRUB_METADATA that allows for a vectored mode. The caller specifies the principal metadata object that they want to scrub (allocation group, inode, etc.) once, followed by an array of scrub types they want called on that object. The kernel runs the scrub operations and writes the output flags and errno code to the corresponding array element. A new pseudo scrub type BARRIER is introduced to force the kernel to return to userspace if any corruptions have been found when scrubbing the previous scrub types in the array. This enables userspace to schedule, for example, the sequence: 1. data fork 2. barrier 3. directory If the data fork scrub is clean, then the kernel will perform the directory scrub. If not, the barrier in 2 will exit back to userspace. The alternative would have been an interface where userspace passes a pointer to an empty buffer, and the kernel formats that with xfs_scrub_vecs that tell userspace what it scrubbed and what the outcome was. With that the kernel would have to communicate that the buffer needed to have been at least X size, even though for our cases XFS_SCRUB_TYPE_NR + 2 would always be enough. Compared to that, this design keeps all the dependency policy and ordering logic in userspace where it already resides instead of duplicating it in the kernel. The downside of that is that it needs the barrier logic. When running fstests in "rebuild all metadata after each test" mode, I observed a 10% reduction in runtime due to fewer transitions across the system call boundary. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_fs.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index 7ae1912cd..97996cb79 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -725,6 +725,15 @@ struct xfs_scrub_metadata { /* Number of scrub subcommands. */ #define XFS_SCRUB_TYPE_NR 29 +/* + * This special type code only applies to the vectored scrub implementation. + * + * If any of the previous scrub vectors recorded runtime errors or have + * sv_flags bits set that match the OFLAG bits in the barrier vector's + * sv_flags, set the barrier's sv_ret to -ECANCELED and return to userspace. + */ +#define XFS_SCRUB_TYPE_BARRIER (0xFFFFFFFF) + /* i: Repair this metadata. */ #define XFS_SCRUB_IFLAG_REPAIR (1u << 0) @@ -769,6 +778,29 @@ struct xfs_scrub_metadata { XFS_SCRUB_OFLAG_NO_REPAIR_NEEDED) #define XFS_SCRUB_FLAGS_ALL (XFS_SCRUB_FLAGS_IN | XFS_SCRUB_FLAGS_OUT) +/* Vectored scrub calls to reduce the number of kernel transitions. */ + +struct xfs_scrub_vec { + __u32 sv_type; /* XFS_SCRUB_TYPE_* */ + __u32 sv_flags; /* XFS_SCRUB_FLAGS_* */ + __s32 sv_ret; /* 0 or a negative error code */ + __u32 sv_reserved; /* must be zero */ +}; + +/* Vectored metadata scrub control structure. */ +struct xfs_scrub_vec_head { + __u64 svh_ino; /* inode number. */ + __u32 svh_gen; /* inode generation. */ + __u32 svh_agno; /* ag number. */ + __u32 svh_flags; /* XFS_SCRUB_VEC_FLAGS_* */ + __u16 svh_rest_us; /* wait this much time between vector items */ + __u16 svh_nr; /* number of svh_vectors */ + __u64 svh_reserved; /* must be zero */ + __u64 svh_vectors; /* pointer to buffer of xfs_scrub_vec */ +}; + +#define XFS_SCRUB_VEC_FLAGS_ALL (0) + /* * ioctl limits */ @@ -928,6 +960,7 @@ struct xfs_getparents_by_handle { #define XFS_IOC_AG_GEOMETRY _IOWR('X', 61, struct xfs_ag_geometry) #define XFS_IOC_GETPARENTS _IOWR('X', 62, struct xfs_getparents) #define XFS_IOC_GETPARENTS_BY_HANDLE _IOWR('X', 63, struct xfs_getparents_by_handle) +#define XFS_IOC_SCRUBV_METADATA _IOWR('X', 64, struct xfs_scrub_vec_head) /* * ioctl commands that replace IRIX syssgi()'s From patchwork Tue Jul 30 00:46:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746008 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1C72123C9 for ; Tue, 30 Jul 2024 00:46:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300389; cv=none; b=VvKvvDdH+PZULy+/9NZ7I57PO/cf5bWy33HTkT+3j/3Umpke9z4UEznQh7Z9k6l2+rE0FEw09PSqDw9ncBI4wU3lY4R9Xcaz13HAqXjyONhAzY0VVNauQQbZsZeD/gGDirf+yWNet6idWi2ByLOezL9dJ94DKQiKFuhrRPCwNrE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300389; c=relaxed/simple; bh=0lF6D0Ln7xG1USqIc4zn/VFLBCdCCVRxLr/XMWzq2fA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ejsO7hToNpl++Cptb0N7bwe5GlUC7pKP0A3WRZuSMJfW5uVMUdhwkY/l8VzfyoYS6bb0h64MumzJFWtG/DU15SDsnjHZv95/CGiWYayu3U+uxmo++bWgEaqTWhebNnr9yR5+/mwUVRQ6+ZNOGyjNCyO4fsUi8ZvnJPKQA8NcH+c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LK3WPX9X; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LK3WPX9X" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB73DC32786; Tue, 30 Jul 2024 00:46:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300388; bh=0lF6D0Ln7xG1USqIc4zn/VFLBCdCCVRxLr/XMWzq2fA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=LK3WPX9XVIWXyuFflLjlwnbBt6hTnsgXOxsa5zzLA90uYGrdQV+4V9L30XgUvMLMy Nh0WgtT8k64M7qFexgWlsm6vc5Bx+pmF7+PTRD78UshIrkiDbD3VRBT7wq5wUUaLhG 13GUMTlvEHIsxbWQIMZyrVtauKHDFlF8bHVXib6vm4jpa1759FHhz9JnuySPs1hGqf 7cTQJg2+wYyFtuxpZilPFN3OJhuf/rL8Hli6P1I9eNr0mM/1Yc5K3k8gN++j7lPudD F6FbEJM7/najsHNCXFm3xZqlTmYmaneLIe9m6vMulel/eNiUfZPg+mJYgyioIyAwx/ 3UXmYKAQZvKjg== Date: Mon, 29 Jul 2024 17:46:28 -0700 Subject: [PATCH 087/115] xfs: factor out a xfs_dir_lookup_args helper From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229843683.1338752.11126016823215172761.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: 14ee22fef420c864c0869419e54aa4e88f64b4e6 Add a helper to switch between the different directory formats for lookup and to handle the -EEXIST return for a successful lookup. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_dir2.c | 66 ++++++++++++++++++++++++++++++++--------------------- libxfs/xfs_dir2.h | 2 ++ 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/libxfs/xfs_dir2.c b/libxfs/xfs_dir2.c index e309e1e58..0cf4120fe 100644 --- a/libxfs/xfs_dir2.c +++ b/libxfs/xfs_dir2.c @@ -351,6 +351,45 @@ xfs_dir_cilookup_result( return -EEXIST; } +int +xfs_dir_lookup_args( + struct xfs_da_args *args) +{ + bool is_block, is_leaf; + int error; + + if (args->dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) { + error = xfs_dir2_sf_lookup(args); + goto out; + } + + /* dir2 functions require that the data fork is loaded */ + error = xfs_iread_extents(args->trans, args->dp, XFS_DATA_FORK); + if (error) + goto out; + + error = xfs_dir2_isblock(args, &is_block); + if (error) + goto out; + + if (is_block) { + error = xfs_dir2_block_lookup(args); + goto out; + } + + error = xfs_dir2_isleaf(args, &is_leaf); + if (error) + goto out; + if (is_leaf) + error = xfs_dir2_leaf_lookup(args); + else + error = xfs_dir2_node_lookup(args); +out: + if (error != -EEXIST) + return error; + return 0; +} + /* * Lookup a name in a directory, give back the inode number. * If ci_name is not NULL, returns the actual name in ci_name if it differs @@ -367,7 +406,6 @@ xfs_dir_lookup( { struct xfs_da_args *args; int rval; - bool v; int lock_mode; ASSERT(S_ISDIR(VFS_I(dp)->i_mode)); @@ -389,30 +427,7 @@ xfs_dir_lookup( args->op_flags |= XFS_DA_OP_CILOOKUP; lock_mode = xfs_ilock_data_map_shared(dp); - if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) { - rval = xfs_dir2_sf_lookup(args); - goto out_check_rval; - } - - rval = xfs_dir2_isblock(args, &v); - if (rval) - goto out_free; - if (v) { - rval = xfs_dir2_block_lookup(args); - goto out_check_rval; - } - - rval = xfs_dir2_isleaf(args, &v); - if (rval) - goto out_free; - if (v) - rval = xfs_dir2_leaf_lookup(args); - else - rval = xfs_dir2_node_lookup(args); - -out_check_rval: - if (rval == -EEXIST) - rval = 0; + rval = xfs_dir_lookup_args(args); if (!rval) { *inum = args->inumber; if (ci_name) { @@ -420,7 +435,6 @@ xfs_dir_lookup( ci_name->len = args->valuelen; } } -out_free: xfs_iunlock(dp, lock_mode); kfree(args); return rval; diff --git a/libxfs/xfs_dir2.h b/libxfs/xfs_dir2.h index b580a78bc..982c2249b 100644 --- a/libxfs/xfs_dir2.h +++ b/libxfs/xfs_dir2.h @@ -66,6 +66,8 @@ extern int xfs_dir_replace(struct xfs_trans *tp, struct xfs_inode *dp, extern int xfs_dir_canenter(struct xfs_trans *tp, struct xfs_inode *dp, struct xfs_name *name); +int xfs_dir_lookup_args(struct xfs_da_args *args); + /* * Direct call from the bmap code, bypassing the generic directory layer. */ From patchwork Tue Jul 30 00:46:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746009 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B81D7323D for ; Tue, 30 Jul 2024 00:46:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300404; cv=none; b=Mi6KrkLVQJ63j846kMP4pdF7Ggh09KehYhbJcC/vU16xvaNNIIW+bq3Y0Np0zDoQiChJzJ0dILgS8j3xVTML/UnAnOfouabJtCyVKa7uCdH4V4qr+R5UfTpSVUHG5MO4eaE2fyMAWZEMMOIH45tdXLm121pDcAbbLcG6koFQ664= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300404; c=relaxed/simple; bh=S7QttBtVytd0daLtf2VkXk1Dn542MmSUwqvsn6zDxH4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QCM5zbA1phscpG+Y6GW794LwkNTB7LEq2vYerI6707Z+Nvv2DEV4UY6kZrTayDU6/90emzNAbMNg/RwbEFthtbIip2jgD5tZNwlmlyysiMBpQIZp17IYUYN8/OBTD3GkGzqBfThnWEwhr0fgdeUk4DpoxQ2zM4utOoBNIuPGvug= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Cy3SVfkS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Cy3SVfkS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50D58C32786; Tue, 30 Jul 2024 00:46:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300404; bh=S7QttBtVytd0daLtf2VkXk1Dn542MmSUwqvsn6zDxH4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Cy3SVfkSja4000074Ktp+cADNNZ5ailp4qppdauqqx1mKUBuWGEoEOXCfM8e1Afzy Y2pf82YCQErWkZa9r6yyH07un7Ee0X5D1dAswppxa0qYyT/I+1kNfGt7Ouk91Tikuy tcZgEReR2zD8Oj8JiKBiEBLqT8nlI+7FnVWj69atmorFOlofoUPhGMolB7+uvhuBLN OMdbIejWpagcYQLUuG8ArJus2HIjXKNTvklVFS7auaIh2X6gUJCrgKB7Zq1BfplR1F oD3/16Fzt29Keydj7xFRSPaTKs/F9khoNx9rJiLVQCuB733ialyIw4KuWiB8AKMmnQ i6HcgIS9zxs8w== Date: Mon, 29 Jul 2024 17:46:43 -0700 Subject: [PATCH 088/115] xfs: factor out a xfs_dir_createname_args helper From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229843698.1338752.16435627130749242510.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: 4d893a40514e9c4ee6e3be48ed1b77efb38c313b Add a helper to switch between the different directory formats for creating a directory entry and to handle the XFS_DA_OP_JUSTCHECK flag based on the passed in ino number field. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_dir2.c | 53 ++++++++++++++++++++++++++++------------------------- libxfs/xfs_dir2.h | 1 + 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/libxfs/xfs_dir2.c b/libxfs/xfs_dir2.c index 0cf4120fe..97c7ddc92 100644 --- a/libxfs/xfs_dir2.c +++ b/libxfs/xfs_dir2.c @@ -255,6 +255,33 @@ xfs_dir_init( return error; } +int +xfs_dir_createname_args( + struct xfs_da_args *args) +{ + bool is_block, is_leaf; + int error; + + if (!args->inumber) + args->op_flags |= XFS_DA_OP_JUSTCHECK; + + if (args->dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) + return xfs_dir2_sf_addname(args); + + error = xfs_dir2_isblock(args, &is_block); + if (error) + return error; + if (is_block) + return xfs_dir2_block_addname(args); + + error = xfs_dir2_isleaf(args, &is_leaf); + if (error) + return error; + if (is_leaf) + return xfs_dir2_leaf_addname(args); + return xfs_dir2_node_addname(args); +} + /* * Enter a name in a directory, or check for available space. * If inum is 0, only the available space test is performed. @@ -269,7 +296,6 @@ xfs_dir_createname( { struct xfs_da_args *args; int rval; - bool v; ASSERT(S_ISDIR(VFS_I(dp)->i_mode)); @@ -296,31 +322,8 @@ xfs_dir_createname( args->trans = tp; args->op_flags = XFS_DA_OP_ADDNAME | XFS_DA_OP_OKNOENT; args->owner = dp->i_ino; - if (!inum) - args->op_flags |= XFS_DA_OP_JUSTCHECK; - if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) { - rval = xfs_dir2_sf_addname(args); - goto out_free; - } - - rval = xfs_dir2_isblock(args, &v); - if (rval) - goto out_free; - if (v) { - rval = xfs_dir2_block_addname(args); - goto out_free; - } - - rval = xfs_dir2_isleaf(args, &v); - if (rval) - goto out_free; - if (v) - rval = xfs_dir2_leaf_addname(args); - else - rval = xfs_dir2_node_addname(args); - -out_free: + rval = xfs_dir_createname_args(args); kfree(args); return rval; } diff --git a/libxfs/xfs_dir2.h b/libxfs/xfs_dir2.h index 982c2249b..f5361dd7b 100644 --- a/libxfs/xfs_dir2.h +++ b/libxfs/xfs_dir2.h @@ -67,6 +67,7 @@ extern int xfs_dir_canenter(struct xfs_trans *tp, struct xfs_inode *dp, struct xfs_name *name); int xfs_dir_lookup_args(struct xfs_da_args *args); +int xfs_dir_createname_args(struct xfs_da_args *args); /* * Direct call from the bmap code, bypassing the generic directory layer. From patchwork Tue Jul 30 00:46:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746010 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 209E14A33 for ; Tue, 30 Jul 2024 00:47:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300420; cv=none; b=Hh7vk/5CtAc1erNuBroYq+7jKGYWyqdKlOUH5AZMMAZIs5royTRpjoVCoM133fZQuiF4AqgjBg43wOK4msBbr9LO6butb8bxl4pVMsVymGTQXDFlfYcUh70aig+mSWxJfbEQr3bQOeWIHbXj+jyjhXejiNFaUVe6geJuhvp7t1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300420; c=relaxed/simple; bh=EdK9gIM7NFQbgsqpkm9cEaptvyTxyS42nnAzQcfYplA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iiM42jb9jgXkVjYOUp3X10GzdPQTL6Jjke0bkXzZ2nVS85WOpA72SPZrAR+vH65jCS4MKAmJuY4WgUvfL1eOAlrg2T/wE3GIVLoYCzfJCgmojuLDkNhJqulZ8e5YBpRdCLPhvv794yFV8AsPlM6Ed2hAJo6b7s9A/1CpWDe9PBc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TmwPBzEJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TmwPBzEJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB33BC32786; Tue, 30 Jul 2024 00:46:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300420; bh=EdK9gIM7NFQbgsqpkm9cEaptvyTxyS42nnAzQcfYplA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=TmwPBzEJC62lFMAP2MkMFLxcUBp/xyLd8naglol0pAjnuGjUuqT2u8NhVFjFzo3P6 992NaiiTnYcLFX/bledp2SHq5uNhhJp97FfHO3stEv3wQ/2RzbirUt29ax/MSh1g4b MrqOko517rrBe60iKkUP11Ozh01qh0qW+tYfWfTOK8o1t4CUF8PygW0cJf126oGqSY h5po4TLcEx/yrBgFYEHFz5vCqrFtMSy5pO+XkuqKKw/Ykxni1Wb1vD89LBovkbSSHc vuAwcOibvLm6f2YUNnVjHhXdrrdNemj9QZJKw/ueUPbdaxg+Cg0Iufwdjd0VA6NVB9 4v4iaC79B2E0w== Date: Mon, 29 Jul 2024 17:46:59 -0700 Subject: [PATCH 089/115] xfs: factor out a xfs_dir_removename_args helper From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229843713.1338752.14572981146720826431.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: 3866e6e669e2c1b3eebf580b8779ea55838c3f5a Add a helper to switch between the different directory formats for removing a directory entry. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_dir2.c | 48 +++++++++++++++++++++++++----------------------- libxfs/xfs_dir2.h | 1 + 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/libxfs/xfs_dir2.c b/libxfs/xfs_dir2.c index 97c7ddc92..e2e0832c1 100644 --- a/libxfs/xfs_dir2.c +++ b/libxfs/xfs_dir2.c @@ -443,6 +443,30 @@ xfs_dir_lookup( return rval; } +int +xfs_dir_removename_args( + struct xfs_da_args *args) +{ + bool is_block, is_leaf; + int error; + + if (args->dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) + return xfs_dir2_sf_removename(args); + + error = xfs_dir2_isblock(args, &is_block); + if (error) + return error; + if (is_block) + return xfs_dir2_block_removename(args); + + error = xfs_dir2_isleaf(args, &is_leaf); + if (error) + return error; + if (is_leaf) + return xfs_dir2_leaf_removename(args); + return xfs_dir2_node_removename(args); +} + /* * Remove an entry from a directory. */ @@ -456,7 +480,6 @@ xfs_dir_removename( { struct xfs_da_args *args; int rval; - bool v; ASSERT(S_ISDIR(VFS_I(dp)->i_mode)); XFS_STATS_INC(dp->i_mount, xs_dir_remove); @@ -476,28 +499,7 @@ xfs_dir_removename( args->whichfork = XFS_DATA_FORK; args->trans = tp; args->owner = dp->i_ino; - - if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) { - rval = xfs_dir2_sf_removename(args); - goto out_free; - } - - rval = xfs_dir2_isblock(args, &v); - if (rval) - goto out_free; - if (v) { - rval = xfs_dir2_block_removename(args); - goto out_free; - } - - rval = xfs_dir2_isleaf(args, &v); - if (rval) - goto out_free; - if (v) - rval = xfs_dir2_leaf_removename(args); - else - rval = xfs_dir2_node_removename(args); -out_free: + rval = xfs_dir_removename_args(args); kfree(args); return rval; } diff --git a/libxfs/xfs_dir2.h b/libxfs/xfs_dir2.h index f5361dd7b..3db54801d 100644 --- a/libxfs/xfs_dir2.h +++ b/libxfs/xfs_dir2.h @@ -68,6 +68,7 @@ extern int xfs_dir_canenter(struct xfs_trans *tp, struct xfs_inode *dp, int xfs_dir_lookup_args(struct xfs_da_args *args); int xfs_dir_createname_args(struct xfs_da_args *args); +int xfs_dir_removename_args(struct xfs_da_args *args); /* * Direct call from the bmap code, bypassing the generic directory layer. From patchwork Tue Jul 30 00:47:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746011 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0301263D for ; Tue, 30 Jul 2024 00:47:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300436; cv=none; b=XFJhEVB9mqQ/Sgz9Yde5+u42fxGh6i+4y4NuVJPz0VDNErLYrRlXG/eZMj1u0SOIi8O81WJO+9fvojezn+kwxvsnf+PSpWfzoofRomZVBmr+Ya6gnI2gfM0zT1PG1ieGFdxRv3PsDioY4CWSo/dmWZuchDBhtzjQXP33QC59bt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300436; c=relaxed/simple; bh=+wlKImvTxN6GylziK+s/GFztScRavAGhRv1tCfXZC88=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ePIRpBCT4sdBZcDPffL5vhe4u5D1/P8AwZ3ztEYZHDoAbzNgIpWw1RwFeIRFOA3Iphj/XoDmnL3ho99ecurcE4v+DFQflYhEctwFaLXiw/TCPDuaq2r8i9a03RcFhi9c9S7lgFsDWM1hiEkYS64OxWVL40t52p2wRLrkT6ZogEA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZFuPZMgu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZFuPZMgu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8FDDFC32786; Tue, 30 Jul 2024 00:47:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300435; bh=+wlKImvTxN6GylziK+s/GFztScRavAGhRv1tCfXZC88=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ZFuPZMgudpW5V8JPI/WW4FxqkDj831HlSEsvNpRYCjU2dtVkrC6t2c54yBSkkRrpp 3/KQvna3Eo+q+wpqAUuB4gPBCAtaZC+SDlcMLegd3GodK0Y5WWNuNnAn8A0BqXpzVg Jxs9KCaCQAwutkaVn9ic3y/Sk7ILoanrSca82LTuE6AegktAVR7eLsVigl09yNL4Op 6u4yakUi3svVK2R2P54RhmsMsKygI4yYKJhfdCQFRzOANtORXD9Vpg+xtOqcM2byXg QFG9Ln+Oz3h70ne1ZYrSIiSJsRSp1yN2E5fTeF8x9FpoopBqwZbdLLc8XTyGw0FOY+ U5nyQQ/Xq0EZw== Date: Mon, 29 Jul 2024 17:47:15 -0700 Subject: [PATCH 090/115] xfs: factor out a xfs_dir_replace_args helper From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229843728.1338752.11874161429350723398.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: dfe5febe2b6a175d730861441bff4f726fc58a6c Add a helper to switch between the different directory formats for removing a directory entry. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_dir2.c | 49 ++++++++++++++++++++++++++----------------------- libxfs/xfs_dir2.h | 1 + 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/libxfs/xfs_dir2.c b/libxfs/xfs_dir2.c index e2e0832c1..55cf39e11 100644 --- a/libxfs/xfs_dir2.c +++ b/libxfs/xfs_dir2.c @@ -504,6 +504,31 @@ xfs_dir_removename( return rval; } +int +xfs_dir_replace_args( + struct xfs_da_args *args) +{ + bool is_block, is_leaf; + int error; + + if (args->dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) + return xfs_dir2_sf_replace(args); + + error = xfs_dir2_isblock(args, &is_block); + if (error) + return error; + if (is_block) + return xfs_dir2_block_replace(args); + + error = xfs_dir2_isleaf(args, &is_leaf); + if (error) + return error; + if (is_leaf) + return xfs_dir2_leaf_replace(args); + + return xfs_dir2_node_replace(args); +} + /* * Replace the inode number of a directory entry. */ @@ -517,7 +542,6 @@ xfs_dir_replace( { struct xfs_da_args *args; int rval; - bool v; ASSERT(S_ISDIR(VFS_I(dp)->i_mode)); @@ -540,28 +564,7 @@ xfs_dir_replace( args->whichfork = XFS_DATA_FORK; args->trans = tp; args->owner = dp->i_ino; - - if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) { - rval = xfs_dir2_sf_replace(args); - goto out_free; - } - - rval = xfs_dir2_isblock(args, &v); - if (rval) - goto out_free; - if (v) { - rval = xfs_dir2_block_replace(args); - goto out_free; - } - - rval = xfs_dir2_isleaf(args, &v); - if (rval) - goto out_free; - if (v) - rval = xfs_dir2_leaf_replace(args); - else - rval = xfs_dir2_node_replace(args); -out_free: + rval = xfs_dir_replace_args(args); kfree(args); return rval; } diff --git a/libxfs/xfs_dir2.h b/libxfs/xfs_dir2.h index 3db54801d..6c00fe24a 100644 --- a/libxfs/xfs_dir2.h +++ b/libxfs/xfs_dir2.h @@ -69,6 +69,7 @@ extern int xfs_dir_canenter(struct xfs_trans *tp, struct xfs_inode *dp, int xfs_dir_lookup_args(struct xfs_da_args *args); int xfs_dir_createname_args(struct xfs_da_args *args); int xfs_dir_removename_args(struct xfs_da_args *args); +int xfs_dir_replace_args(struct xfs_da_args *args); /* * Direct call from the bmap code, bypassing the generic directory layer. From patchwork Tue Jul 30 00:47:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746012 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 BAA9A63D for ; Tue, 30 Jul 2024 00:47:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300451; cv=none; b=Lve+VNFI5G2hFy9gFBzJQje1/eg7X0G1wuRVEh3IQCvgXcZe1dwN0XYy3QdeepR0n4QIQdOWdQHREVUuKb/ycouiy6XGUqUI4PtFEH+ij5ooTBRjV+tKfv3dg159OoqPxwkk1sQJdrc0IDlY6RDJivBs3XXkSL7WEj5h6lPc5L4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300451; c=relaxed/simple; bh=RjJFu9C8AJFZpQ+X7grIzFmlAttabbkNWLZ+REGfod8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rxxS/koG19QJl33pidxyGVWODz4CnDiob/PhrT3ztA+pKNR5TV8slo4nuEdR08J+dZjy2Be9ytBJOoREiAOemhXUl4rQd2j20/mciasdbMse17yYn/Nb4SnAovHQ/E56RcKDWyA0LCZQk0JQsT60KOwIxPhc9KCK8jq80+1djOg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZHJdSxXA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZHJdSxXA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41CE8C32786; Tue, 30 Jul 2024 00:47:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300451; bh=RjJFu9C8AJFZpQ+X7grIzFmlAttabbkNWLZ+REGfod8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ZHJdSxXAjf3mb45NWEj6VbKgbpjp8QIMTFLEFPY1lYRxPO0tNOC4XfVTIUuUIudas AXfbykvZ5Xo5mWJWRsonFV4YPJ9oN73MC6hSZPgRPg+LnRcZ4egpVi2uFy+wTFQ87i 4thNFNNRAZOAO3L8DR0htV6hwx5RL/zscQnKrYaqIR8DIzPFlZDe965DoR7Arr9usE RvT/f/gZPOnIIdllEm198QiEY3XGOjZ0hqgcG7A8YdyYqrWT0IUn7VuHg+MOFJf1r2 QeWidoPFi74TEf9jehLEp+s4Gew7NLfz6ZX2Ijijq57Lovvg0EtKqHb2vt9UaZR1U2 8MacRdALcTb0w== Date: Mon, 29 Jul 2024 17:47:30 -0700 Subject: [PATCH 091/115] xfs: refactor dir format helpers From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229843743.1338752.12553593713166400251.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: e58ac1770ded2a316447ca7608bb7809af82eca6 Add a new enum and a xfs_dir2_format helper that returns it to allow the code to switch on the format of a directory in a single operation and switch all helpers of xfs_dir2_isblock and xfs_dir2_isleaf to it. This also removes the explicit xfs_iread_extents call in a few of the call sites given that xfs_bmap_last_offset already takes care of it underneath. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- db/namei.c | 18 ++-- libxfs/libxfs_api_defs.h | 3 - libxfs/xfs_dir2.c | 188 ++++++++++++++++++---------------------------- libxfs/xfs_dir2.h | 12 ++- libxfs/xfs_exchmaps.c | 9 -- repair/phase6.c | 21 ++--- 6 files changed, 105 insertions(+), 146 deletions(-) diff --git a/db/namei.c b/db/namei.c index 303ca3448..6de062161 100644 --- a/db/namei.c +++ b/db/namei.c @@ -449,18 +449,18 @@ listdir( .geo = dp->i_mount->m_dir_geo, }; int error; - bool isblock; - if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) + switch (libxfs_dir2_format(&args, &error)) { + case XFS_DIR2_FMT_SF: return list_sfdir(&args); - - error = -libxfs_dir2_isblock(&args, &isblock); - if (error) - return error; - - if (isblock) + case XFS_DIR2_FMT_BLOCK: return list_blockdir(&args); - return list_leafdir(&args); + case XFS_DIR2_FMT_LEAF: + case XFS_DIR2_FMT_NODE: + return list_leafdir(&args); + default: + return error; + } } /* List the inode number of the currently selected inode. */ diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 896b6c953..cc670d93a 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -122,9 +122,8 @@ #define xfs_dir2_data_use_free libxfs_dir2_data_use_free #define xfs_dir2_free_hdr_from_disk libxfs_dir2_free_hdr_from_disk #define xfs_dir2_hashname libxfs_dir2_hashname -#define xfs_dir2_isblock libxfs_dir2_isblock -#define xfs_dir2_isleaf libxfs_dir2_isleaf #define xfs_dir2_leaf_hdr_from_disk libxfs_dir2_leaf_hdr_from_disk +#define xfs_dir2_format libxfs_dir2_format #define xfs_dir2_namecheck libxfs_dir2_namecheck #define xfs_dir2_sf_entsize libxfs_dir2_sf_entsize #define xfs_dir2_sf_get_ftype libxfs_dir2_sf_get_ftype diff --git a/libxfs/xfs_dir2.c b/libxfs/xfs_dir2.c index 55cf39e11..9cf05ec51 100644 --- a/libxfs/xfs_dir2.c +++ b/libxfs/xfs_dir2.c @@ -255,31 +255,60 @@ xfs_dir_init( return error; } +enum xfs_dir2_fmt +xfs_dir2_format( + struct xfs_da_args *args, + int *error) +{ + struct xfs_inode *dp = args->dp; + struct xfs_mount *mp = dp->i_mount; + struct xfs_da_geometry *geo = mp->m_dir_geo; + xfs_fileoff_t eof; + + xfs_assert_ilocked(dp, XFS_ILOCK_SHARED | XFS_ILOCK_EXCL); + + *error = 0; + if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) + return XFS_DIR2_FMT_SF; + + *error = xfs_bmap_last_offset(dp, &eof, XFS_DATA_FORK); + if (*error) + return XFS_DIR2_FMT_ERROR; + + if (eof == XFS_B_TO_FSB(mp, geo->blksize)) { + if (XFS_IS_CORRUPT(mp, dp->i_disk_size != geo->blksize)) { + xfs_da_mark_sick(args); + *error = -EFSCORRUPTED; + return XFS_DIR2_FMT_ERROR; + } + return XFS_DIR2_FMT_BLOCK; + } + if (eof == geo->leafblk + geo->fsbcount) + return XFS_DIR2_FMT_LEAF; + return XFS_DIR2_FMT_NODE; +} + int xfs_dir_createname_args( struct xfs_da_args *args) { - bool is_block, is_leaf; int error; if (!args->inumber) args->op_flags |= XFS_DA_OP_JUSTCHECK; - if (args->dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) + switch (xfs_dir2_format(args, &error)) { + case XFS_DIR2_FMT_SF: return xfs_dir2_sf_addname(args); - - error = xfs_dir2_isblock(args, &is_block); - if (error) - return error; - if (is_block) + case XFS_DIR2_FMT_BLOCK: return xfs_dir2_block_addname(args); - - error = xfs_dir2_isleaf(args, &is_leaf); - if (error) - return error; - if (is_leaf) + case XFS_DIR2_FMT_LEAF: return xfs_dir2_leaf_addname(args); - return xfs_dir2_node_addname(args); + case XFS_DIR2_FMT_NODE: + return xfs_dir2_node_addname(args); + default: + return error; + } } /* @@ -358,36 +387,25 @@ int xfs_dir_lookup_args( struct xfs_da_args *args) { - bool is_block, is_leaf; int error; - if (args->dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) { + switch (xfs_dir2_format(args, &error)) { + case XFS_DIR2_FMT_SF: error = xfs_dir2_sf_lookup(args); - goto out; - } - - /* dir2 functions require that the data fork is loaded */ - error = xfs_iread_extents(args->trans, args->dp, XFS_DATA_FORK); - if (error) - goto out; - - error = xfs_dir2_isblock(args, &is_block); - if (error) - goto out; - - if (is_block) { + break; + case XFS_DIR2_FMT_BLOCK: error = xfs_dir2_block_lookup(args); - goto out; - } - - error = xfs_dir2_isleaf(args, &is_leaf); - if (error) - goto out; - if (is_leaf) + break; + case XFS_DIR2_FMT_LEAF: error = xfs_dir2_leaf_lookup(args); - else + break; + case XFS_DIR2_FMT_NODE: error = xfs_dir2_node_lookup(args); -out: + break; + default: + break; + } + if (error != -EEXIST) return error; return 0; @@ -447,24 +465,20 @@ int xfs_dir_removename_args( struct xfs_da_args *args) { - bool is_block, is_leaf; int error; - if (args->dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) + switch (xfs_dir2_format(args, &error)) { + case XFS_DIR2_FMT_SF: return xfs_dir2_sf_removename(args); - - error = xfs_dir2_isblock(args, &is_block); - if (error) - return error; - if (is_block) + case XFS_DIR2_FMT_BLOCK: return xfs_dir2_block_removename(args); - - error = xfs_dir2_isleaf(args, &is_leaf); - if (error) - return error; - if (is_leaf) + case XFS_DIR2_FMT_LEAF: return xfs_dir2_leaf_removename(args); - return xfs_dir2_node_removename(args); + case XFS_DIR2_FMT_NODE: + return xfs_dir2_node_removename(args); + default: + return error; + } } /* @@ -508,25 +522,20 @@ int xfs_dir_replace_args( struct xfs_da_args *args) { - bool is_block, is_leaf; int error; - if (args->dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) + switch (xfs_dir2_format(args, &error)) { + case XFS_DIR2_FMT_SF: return xfs_dir2_sf_replace(args); - - error = xfs_dir2_isblock(args, &is_block); - if (error) - return error; - if (is_block) + case XFS_DIR2_FMT_BLOCK: return xfs_dir2_block_replace(args); - - error = xfs_dir2_isleaf(args, &is_leaf); - if (error) - return error; - if (is_leaf) + case XFS_DIR2_FMT_LEAF: return xfs_dir2_leaf_replace(args); - - return xfs_dir2_node_replace(args); + case XFS_DIR2_FMT_NODE: + return xfs_dir2_node_replace(args); + default: + return error; + } } /* @@ -632,57 +641,6 @@ xfs_dir2_grow_inode( return 0; } -/* - * See if the directory is a single-block form directory. - */ -int -xfs_dir2_isblock( - struct xfs_da_args *args, - bool *isblock) -{ - struct xfs_mount *mp = args->dp->i_mount; - xfs_fileoff_t eof; - int error; - - error = xfs_bmap_last_offset(args->dp, &eof, XFS_DATA_FORK); - if (error) - return error; - - *isblock = false; - if (XFS_FSB_TO_B(mp, eof) != args->geo->blksize) - return 0; - - *isblock = true; - if (XFS_IS_CORRUPT(mp, args->dp->i_disk_size != args->geo->blksize)) { - xfs_da_mark_sick(args); - return -EFSCORRUPTED; - } - return 0; -} - -/* - * See if the directory is a single-leaf form directory. - */ -int -xfs_dir2_isleaf( - struct xfs_da_args *args, - bool *isleaf) -{ - xfs_fileoff_t eof; - int error; - - error = xfs_bmap_last_offset(args->dp, &eof, XFS_DATA_FORK); - if (error) - return error; - - *isleaf = false; - if (eof != args->geo->leafblk + args->geo->fsbcount) - return 0; - - *isleaf = true; - return 0; -} - /* * Remove the given block from the directory. * This routine is used for data and free blocks, leaf/node are done diff --git a/libxfs/xfs_dir2.h b/libxfs/xfs_dir2.h index 6c00fe24a..6dbe6e9ec 100644 --- a/libxfs/xfs_dir2.h +++ b/libxfs/xfs_dir2.h @@ -36,6 +36,16 @@ xfs_dir2_samename( return !memcmp(n1->name, n2->name, n1->len); } +enum xfs_dir2_fmt { + XFS_DIR2_FMT_SF, + XFS_DIR2_FMT_BLOCK, + XFS_DIR2_FMT_LEAF, + XFS_DIR2_FMT_NODE, + XFS_DIR2_FMT_ERROR, +}; + +enum xfs_dir2_fmt xfs_dir2_format(struct xfs_da_args *args, int *error); + /* * Convert inode mode to directory entry filetype */ @@ -79,8 +89,6 @@ extern int xfs_dir2_sf_to_block(struct xfs_da_args *args); /* * Interface routines used by userspace utilities */ -extern int xfs_dir2_isblock(struct xfs_da_args *args, bool *isblock); -extern int xfs_dir2_isleaf(struct xfs_da_args *args, bool *isleaf); extern int xfs_dir2_shrink_inode(struct xfs_da_args *args, xfs_dir2_db_t db, struct xfs_buf *bp); diff --git a/libxfs/xfs_exchmaps.c b/libxfs/xfs_exchmaps.c index a8a51ce53..08bfe6f1b 100644 --- a/libxfs/xfs_exchmaps.c +++ b/libxfs/xfs_exchmaps.c @@ -462,17 +462,12 @@ xfs_exchmaps_dir_to_sf( }; struct xfs_dir2_sf_hdr sfh; struct xfs_buf *bp; - bool isblock; int size; - int error; + int error = 0; - error = xfs_dir2_isblock(&args, &isblock); - if (error) + if (xfs_dir2_format(&args, &error) != XFS_DIR2_FMT_BLOCK) return error; - if (!isblock) - return 0; - error = xfs_dir3_block_read(tp, xmi->xmi_ip2, xmi->xmi_ip2->i_ino, &bp); if (error) return error; diff --git a/repair/phase6.c b/repair/phase6.c index 2eba9772d..1e985e7db 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -2269,12 +2269,12 @@ longform_dir2_entry_check( xfs_dablk_t da_bno; freetab_t *freetab; int i; - bool isblock; - bool isleaf; + enum xfs_dir2_fmt fmt; xfs_fileoff_t next_da_bno; int seeval; int fixit = 0; struct xfs_da_args args; + int error; *need_dot = 1; freetab = malloc(FREETAB_SIZE(ip->i_disk_size / mp->m_dir_geo->blksize)); @@ -2294,8 +2294,7 @@ longform_dir2_entry_check( /* is this a block, leaf, or node directory? */ args.dp = ip; args.geo = mp->m_dir_geo; - libxfs_dir2_isblock(&args, &isblock); - libxfs_dir2_isleaf(&args, &isleaf); + fmt = libxfs_dir2_format(&args, &error); /* check directory "data" blocks (ie. name/inode pairs) */ for (da_bno = 0, next_da_bno = 0; @@ -2318,7 +2317,7 @@ longform_dir2_entry_check( break; } - if (isblock) + if (fmt == XFS_DIR2_FMT_BLOCK) ops = &xfs_dir3_block_buf_ops; else ops = &xfs_dir3_data_buf_ops; @@ -2335,7 +2334,7 @@ longform_dir2_entry_check( * block form and we fail, there isn't anything else to * read, and nothing we can do but trash it. */ - if (isblock) { + if (fmt == XFS_DIR2_FMT_BLOCK) { fixit++; goto out_fix; } @@ -2349,7 +2348,7 @@ longform_dir2_entry_check( error = check_dir3_header(mp, bp, ino); if (error) { fixit++; - if (isblock) + if (fmt == XFS_DIR2_FMT_BLOCK) goto out_fix; libxfs_buf_relse(bp); @@ -2360,8 +2359,8 @@ longform_dir2_entry_check( longform_dir2_entry_check_data(mp, ip, num_illegal, need_dot, irec, ino_offset, bp, hashtab, - &freetab, da_bno, isblock); - if (isblock) + &freetab, da_bno, fmt == XFS_DIR2_FMT_BLOCK); + if (fmt == XFS_DIR2_FMT_BLOCK) break; libxfs_buf_relse(bp); @@ -2371,7 +2370,7 @@ longform_dir2_entry_check( if (!dotdot_update) { /* check btree and freespace */ - if (isblock) { + if (fmt == XFS_DIR2_FMT_BLOCK) { struct xfs_dir2_data_hdr *block; xfs_dir2_block_tail_t *btp; xfs_dir2_leaf_entry_t *blp; @@ -2384,7 +2383,7 @@ longform_dir2_entry_check( be32_to_cpu(btp->stale)); if (dir_hash_check(hashtab, ip, seeval)) fixit |= 1; - } else if (isleaf) { + } else if (fmt == XFS_DIR2_FMT_LEAF) { fixit |= longform_dir2_check_leaf(mp, ip, hashtab, freetab); } else { From patchwork Tue Jul 30 00:47:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746013 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 048281373 for ; Tue, 30 Jul 2024 00:47:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300467; cv=none; b=fVtR4m0BpVLI4Cg9MZdFMtDKpmtLZmpaxfSaFFntR0sEl1pTefhJqIq4HT7FkIDRl1/dId55dV6strQlTJoFQl5tn+FrMOD7U/9fre5xs54Z/ViE4W5/+6rU0dDxNcV20kssYcD+/RzPswG5CuAWl5m/6I+Aq9FpaN1ILg2+DUQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300467; c=relaxed/simple; bh=BGoTx7vBBksmNCYEzPnqGAsR7e3h5jMVCkt8VOG0szY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RY0WxzpBzt7LIE/f34MvEvCZecPB76Cl/j4HEdgxdJ+yn1a1EtM3E8JPdc1m8FNuNnTM6VxvQ50rq1ExITO/onydf1Sj/hHLCqIZ7J/SSOmsczfLQDsW/tfme7V/JCafgLWH7qThQuDoLNVpFhyTAr7IKzIUqIxPCsrBM+RifYs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NGSsN7Zs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NGSsN7Zs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6979C32786; Tue, 30 Jul 2024 00:47:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300466; bh=BGoTx7vBBksmNCYEzPnqGAsR7e3h5jMVCkt8VOG0szY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=NGSsN7Zsb8hq7RNxGbYlXqLjo8exDvOobUqT4ZpTXTCoPtayTSVBvnSWORkvZ3d9m PKCxgucZgj6aHEF+p9B8B0iHYJVRn/kR1GiksUXkuIh+RLq1KiQsDu2Flcd/uNEyrB io3sCSawzdOYJKfwevyiW08CcyGdFFAkPlgCXZCcjkl17j74+XQpcaCEKbiUw7HJMz PokphTBHNQtbXRlx//ooVCdpzHyODyeWk+0c/iValdrSGGEi5/xAPHQrM8yEw3AYSd 6phz3JmIRdDlVGmW2ANTsyHeJgxCi+9hJIE/XgZdWkCA+y2VljhaEWtsf7rjKEDegc H79Ai4lUfwKtg== Date: Mon, 29 Jul 2024 17:47:46 -0700 Subject: [PATCH 092/115] xfs: make the seq argument to xfs_bmapi_convert_delalloc() optional From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Zhang Yi , Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229843758.1338752.17838555738859832583.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Zhang Yi Source kernel commit: fc8d0ba0ff5fe4700fa02008b7751ec6b84b7677 Allow callers to pass a NULLL seq argument if they don't care about the fork sequence number. Signed-off-by: Zhang Yi Reviewed-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_bmap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index def73fd50..33d0764a0 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -4642,7 +4642,8 @@ xfs_bmapi_convert_delalloc( if (!isnullstartblock(bma.got.br_startblock)) { xfs_bmbt_to_iomap(ip, iomap, &bma.got, 0, flags, xfs_iomap_inode_sequence(ip, flags)); - *seq = READ_ONCE(ifp->if_seq); + if (seq) + *seq = READ_ONCE(ifp->if_seq); goto out_trans_cancel; } @@ -4693,7 +4694,8 @@ xfs_bmapi_convert_delalloc( ASSERT(!isnullstartblock(bma.got.br_startblock)); xfs_bmbt_to_iomap(ip, iomap, &bma.got, 0, flags, xfs_iomap_inode_sequence(ip, flags)); - *seq = READ_ONCE(ifp->if_seq); + if (seq) + *seq = READ_ONCE(ifp->if_seq); if (whichfork == XFS_COW_FORK) xfs_refcount_alloc_cow_extent(tp, bma.blkno, bma.length); From patchwork Tue Jul 30 00:48:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746014 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0171E23C9 for ; Tue, 30 Jul 2024 00:48:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300483; cv=none; b=F/iY4XXktIwvVq/ElDCnalpiVFST4GlwQ+VRh5QYqvmU2gpfaScjrpAZaUK/x6Db9xFSqpkMztFxOLnGiluJ82PH1sdNE938bL128pWCamb8I8yBrReHMNwS/OGm+vkE1wobURvhM7A4FzigVWIiMvTm90o+OKaOzvjCM4vvW6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300483; c=relaxed/simple; bh=YkU+XgTRVDFU+CJS2ghZbrHN6mv1FFbqFE8L6JCxni0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YjsWEdUbA2bfKP6LTTJpl/erHsaviG6rJ4VTdeY2p6ykq/gxe/tDXc2qMwou9ayF6EQi1upIPxsVmpym2jjeIRXCYalwp983U0s236cp9ZT6HC8+fn0aSy6kzs1v/fvmFpbG8W15GNdVeXZwbHmk8SvHO4e84yt2DsnVXqcmGN8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RPD9ntq2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RPD9ntq2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7CA5DC32786; Tue, 30 Jul 2024 00:48:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300482; bh=YkU+XgTRVDFU+CJS2ghZbrHN6mv1FFbqFE8L6JCxni0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=RPD9ntq2Vth0FVKsB35QAZp4nr4YwO+b81fZTG5UdLOIbfo/VSvm6WAhEisNHsQ0a XMXc1hRBPFMaDhUyMCrMmnZt1v3DniA8H9f2kb9+mQJHGFjqz1ByLN2WR8RPTyE3hu P+U8XhlqmmncrCBDpMh3Xh2GnRhWxpVRSZRTPQWUGAz/L+5vnZk4TnhK504XLVfoeJ l0YCsck2vBJZWgYzyNjdt6rTlLdIMKUdV9p1sSWy58RjO21xNGyyuI3iuNERhxnr5X j7me+Wu2oRmjtSbun6ZX9ADC8dLmkiRh4Yc6TTfOy5a8nH0f9oUR0gzQAJ6z+6K5MD umV6iZrSfeP3A== Date: Mon, 29 Jul 2024 17:48:02 -0700 Subject: [PATCH 093/115] xfs: make xfs_bmapi_convert_delalloc() to allocate the target offset From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Zhang Yi , Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229843774.1338752.17298872330537959183.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Zhang Yi Source kernel commit: 2e08371a83f1c06fd85eea8cd37c87a224cc4cc4 Since xfs_bmapi_convert_delalloc() only attempts to allocate the entire delalloc extent and require multiple invocations to allocate the target offset. So xfs_convert_blocks() add a loop to do this job and we call it in the write back path, but xfs_convert_blocks() isn't a common helper. Let's do it in xfs_bmapi_convert_delalloc() and drop xfs_convert_blocks(), preparing for the post EOF delalloc blocks converting in the buffered write begin path. Signed-off-by: Zhang Yi Reviewed-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/libxfs_priv.h | 5 ++++- libxfs/xfs_bmap.c | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 023444082..90b2db091 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -79,7 +79,10 @@ extern struct kmem_cache *xfs_trans_cache; #define crc32c(c,p,l) crc32c_le((c),(unsigned char const *)(p),(l)) /* fake up kernel's iomap, (not) used in xfs_bmap.[ch] */ -struct iomap; +struct iomap { + unsigned long long offset; /* do not use */ + unsigned long long length; /* do not use */ +}; #define cancel_delayed_work_sync(work) do { } while(0) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 33d0764a0..9fce05e1f 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -4584,8 +4584,8 @@ xfs_bmapi_write( * invocations to allocate the target offset if a large enough physical extent * is not available. */ -int -xfs_bmapi_convert_delalloc( +static int +xfs_bmapi_convert_one_delalloc( struct xfs_inode *ip, int whichfork, xfs_off_t offset, @@ -4718,6 +4718,36 @@ xfs_bmapi_convert_delalloc( return error; } +/* + * Pass in a dellalloc extent and convert it to real extents, return the real + * extent that maps offset_fsb in iomap. + */ +int +xfs_bmapi_convert_delalloc( + struct xfs_inode *ip, + int whichfork, + loff_t offset, + struct iomap *iomap, + unsigned int *seq) +{ + int error; + + /* + * Attempt to allocate whatever delalloc extent currently backs offset + * and put the result into iomap. Allocate in a loop because it may + * take several attempts to allocate real blocks for a contiguous + * delalloc extent if free space is sufficiently fragmented. + */ + do { + error = xfs_bmapi_convert_one_delalloc(ip, whichfork, offset, + iomap, seq); + if (error) + return error; + } while (iomap->offset + iomap->length <= offset); + + return 0; +} + int xfs_bmapi_remap( struct xfs_trans *tp, From patchwork Tue Jul 30 00:48:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746015 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 4AC85323D for ; Tue, 30 Jul 2024 00:48:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300498; cv=none; b=hyTUQV9HuKZPZoGEDpvg5l8gSFfq7OhynpRMYXkcAoZS84ycloMuPiOySFSPCQZy56JudWA8jFpEQq0Dgik0rU+wlJmCZUUq4p1Tm1W5iqCEk8MLzO3W35MsVTYf3efOuw5E4XHxZliKUhfA1qiX6Uddcg+zcdIVDoHWiRNuaRI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300498; c=relaxed/simple; bh=T70NHbvucxMmim/PVM6KUfLxZ04QSGW6Nj75mJ4+VME=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=phy80mDR2t3XumJD6SWepTPCCKI4bfP5JWJU20vENvxj587DNu8v+re2ldlA+3g7OtrjCHJssYxTJCYWbgDHt96bIzuIF9NVLzeXe1Ic/2kE2BE/Vcumj9LlXkpHPYcER/HrIFpNJSotYy9kp0Jhp1hLAGCVWegCVhmZ9pdL+8k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SFc/Ba1J; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SFc/Ba1J" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E042C32786; Tue, 30 Jul 2024 00:48:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300498; bh=T70NHbvucxMmim/PVM6KUfLxZ04QSGW6Nj75mJ4+VME=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=SFc/Ba1JZfalh5IQpefmyN2SogAK8bmfGTe4BZghcGCUCyCzmlqvT1kEhuqV5i6Y1 5A+i/UieNVfUQJFahLp6h8bgJiBFCrElRElUjSt7+2lWPxR6l8b+BD3tFKir5HTNRb cl1zsSAX9lOvJOAKmWW/2akZcWYKwPfGXLsL4+vWXTXLcK3wEuPCsKQAzEiadenn5p cxpYXTspHTHjRA856yAiTd+3X0rYan4J1JurmcG/omHvlkuQOGyqBzLQKZyMP0Vx2K 5Q2NzZVjW4RI0KIymPGdcX/VhG7zNFbwP1yhrm7VK331MpCBCNpzGTk9egxx10OQpx DKXezr5OE8eTw== Date: Mon, 29 Jul 2024 17:48:17 -0700 Subject: [PATCH 094/115] xfs: fix error returns from xfs_bmapi_write From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , =?utf-8?b?5YiY6YCa?= , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229843789.1338752.2337505729207039424.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: 6773da870ab89123d1b513da63ed59e32a29cb77 xfs_bmapi_write can return 0 without actually returning a mapping in mval in two different cases: 1) when there is absolutely no space available to do an allocation 2) when converting delalloc space, and the allocation is so small that it only covers parts of the delalloc extent before the range requested by the caller Callers at best can handle one of these cases, but in many cases can't cope with either one. Switch xfs_bmapi_write to always return a mapping or return an error code instead. For case 1) above ENOSPC is the obvious choice which is very much what the callers expect anyway. For case 2) there is no really good error code, so pick a funky one from the SysV streams portfolio. This fixes the reproducer here: https://lore.kernel.org/linux-xfs/CAEJPjCvT3Uag-pMTYuigEjWZHn1sGMZ0GCjVVCv29tNHK76Cgg@mail.gmail.com0/ which uses reserved blocks to create file systems that are gravely out of space and thus cause at least xfs_file_alloc_space to hang and trigger the lack of ENOSPC handling in xfs_dquot_disk_alloc. Note that this patch does not actually make any caller but xfs_alloc_file_space deal intelligently with case 2) above. Signed-off-by: Christoph Hellwig Reported-by: 刘通 Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_attr_remote.c | 1 - libxfs/xfs_bmap.c | 46 +++++++++++++++++++++++++++++++++++++--------- libxfs/xfs_da_btree.c | 20 +++++--------------- 3 files changed, 42 insertions(+), 25 deletions(-) diff --git a/libxfs/xfs_attr_remote.c b/libxfs/xfs_attr_remote.c index eb15b272b..282cf2cb9 100644 --- a/libxfs/xfs_attr_remote.c +++ b/libxfs/xfs_attr_remote.c @@ -624,7 +624,6 @@ xfs_attr_rmtval_set_blk( if (error) return error; - ASSERT(nmap == 1); ASSERT((map->br_startblock != DELAYSTARTBLOCK) && (map->br_startblock != HOLESTARTBLOCK)); diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 9fce05e1f..84760c889 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -4211,8 +4211,10 @@ xfs_bmapi_allocate( } else { error = xfs_bmap_alloc_userdata(bma); } - if (error || bma->blkno == NULLFSBLOCK) + if (error) return error; + if (bma->blkno == NULLFSBLOCK) + return -ENOSPC; if (bma->flags & XFS_BMAPI_ZERO) { error = xfs_zero_extent(bma->ip, bma->blkno, bma->length); @@ -4391,6 +4393,15 @@ xfs_bmapi_finish( * extent state if necessary. Details behaviour is controlled by the flags * parameter. Only allocates blocks from a single allocation group, to avoid * locking problems. + * + * Returns 0 on success and places the extent mappings in mval. nmaps is used + * as an input/output parameter where the caller specifies the maximum number + * of mappings that may be returned and xfs_bmapi_write passes back the number + * of mappings (including existing mappings) it found. + * + * Returns a negative error code on failure, including -ENOSPC when it could not + * allocate any blocks and -ENOSR when it did allocate blocks to convert a + * delalloc range, but those blocks were before the passed in range. */ int xfs_bmapi_write( @@ -4519,10 +4530,16 @@ xfs_bmapi_write( ASSERT(len > 0); ASSERT(bma.length > 0); error = xfs_bmapi_allocate(&bma); - if (error) + if (error) { + /* + * If we already allocated space in a previous + * iteration return what we go so far when + * running out of space. + */ + if (error == -ENOSPC && bma.nallocs) + break; goto error0; - if (bma.blkno == NULLFSBLOCK) - break; + } /* * If this is a CoW allocation, record the data in @@ -4560,7 +4577,6 @@ xfs_bmapi_write( if (!xfs_iext_next_extent(ifp, &bma.icur, &bma.got)) eof = true; } - *nmap = n; error = xfs_bmap_btree_to_extents(tp, ip, bma.cur, &bma.logflags, whichfork); @@ -4571,7 +4587,22 @@ xfs_bmapi_write( ifp->if_nextents > XFS_IFORK_MAXEXT(ip, whichfork)); xfs_bmapi_finish(&bma, whichfork, 0); xfs_bmap_validate_ret(orig_bno, orig_len, orig_flags, orig_mval, - orig_nmap, *nmap); + orig_nmap, n); + + /* + * When converting delayed allocations, xfs_bmapi_allocate ignores + * the passed in bno and always converts from the start of the found + * delalloc extent. + * + * To avoid a successful return with *nmap set to 0, return the magic + * -ENOSR error code for this particular case so that the caller can + * handle it. + */ + if (!n) { + ASSERT(bma.nallocs >= *nmap); + return -ENOSR; + } + *nmap = n; return 0; error0: xfs_bmapi_finish(&bma, whichfork, error); @@ -4679,9 +4710,6 @@ xfs_bmapi_convert_one_delalloc( if (error) goto out_finish; - error = -ENOSPC; - if (WARN_ON_ONCE(bma.blkno == NULLFSBLOCK)) - goto out_finish; if (WARN_ON_ONCE(!xfs_valid_startblock(ip, bma.got.br_startblock))) { xfs_bmap_mark_sick(ip, whichfork); error = -EFSCORRUPTED; diff --git a/libxfs/xfs_da_btree.c b/libxfs/xfs_da_btree.c index 3c0dc26b7..820e85752 100644 --- a/libxfs/xfs_da_btree.c +++ b/libxfs/xfs_da_btree.c @@ -2293,8 +2293,8 @@ xfs_da_grow_inode_int( struct xfs_inode *dp = args->dp; int w = args->whichfork; xfs_rfsblock_t nblks = dp->i_nblocks; - struct xfs_bmbt_irec map, *mapp; - int nmap, error, got, i, mapi; + struct xfs_bmbt_irec map, *mapp = ↦ + int nmap, error, got, i, mapi = 1; /* * Find a spot in the file space to put the new block. @@ -2310,14 +2310,7 @@ xfs_da_grow_inode_int( error = xfs_bmapi_write(tp, dp, *bno, count, xfs_bmapi_aflag(w)|XFS_BMAPI_METADATA|XFS_BMAPI_CONTIG, args->total, &map, &nmap); - if (error) - return error; - - ASSERT(nmap <= 1); - if (nmap == 1) { - mapp = ↦ - mapi = 1; - } else if (nmap == 0 && count > 1) { + if (error == -ENOSPC && count > 1) { xfs_fileoff_t b; int c; @@ -2335,16 +2328,13 @@ xfs_da_grow_inode_int( args->total, &mapp[mapi], &nmap); if (error) goto out_free_map; - if (nmap < 1) - break; mapi += nmap; b = mapp[mapi - 1].br_startoff + mapp[mapi - 1].br_blockcount; } - } else { - mapi = 0; - mapp = NULL; } + if (error) + goto out_free_map; /* * Count the blocks we got, make sure it matches the total. From patchwork Tue Jul 30 00:48:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746016 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E6452443D for ; Tue, 30 Jul 2024 00:48:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300514; cv=none; b=fUWS/iRPbFZJE5h3nGhb4CMdVX6AwzHMLsJvMdgWxPajBv9gX+WQU6ASowHa8s0iYM22SzzZtWo7qeE/HboaNW4mrx4RIkgB1J7Esa7cT/QuemryMsqzgelW9wmX5ZQqC7hHf3MgOZG3w1Elw5v2h4utmRUEtFWL7lCdC+muVsk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300514; c=relaxed/simple; bh=VkAJQt8TZvYkua759XFgLO0Z7h3lmP+DXLPmwTJeJg4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t7cY+wsjtiblvQHrCOdPKIeg86hxzzlcuP2fSibSI9sTkrDhmJ8JYgqW6sraX4e4GtDfElPT6HOuv4VnIc0dAjEVY04pvF1DSJ5Ty2sTxDkHexBM3+uPH3Z37He/3uJg2k1RXwEPgK7Oe08MosI9dtCs/GrVW8z9QswOMDPmarc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TqC59XrV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TqC59XrV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2F48C32786; Tue, 30 Jul 2024 00:48:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300513; bh=VkAJQt8TZvYkua759XFgLO0Z7h3lmP+DXLPmwTJeJg4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=TqC59XrVH1rdD8nMqZz0S5HpHqz03HysN6rPUWlt9uJroabBf4S+hKNA16L21fqRY k3lFSc56f2XebKPIKCwGr66bce35Us4rnHyyUBDZ5IMQfgFPtkqplz++Sb1P0D5Sk5 qkau7t1kWUfdaKxcF6ekl6CLaZdoGqsgoY/Bm1RRTNfTmE790nIKwXYdYGFfmMKDCc dv4AX2QTuU+K56LU8rhj2mhRs3SxlXpCaPOe9yEdSHKYjgxJYJ51r4ztfjKCEL1Myi Y2gHrPj+BZuejtFRWWgjPmMBWMNBn94exVjAg4MfaoxEQsxorkLsmvZlb/M/XsJQII 52mJuxlhbpPwA== Date: Mon, 29 Jul 2024 17:48:33 -0700 Subject: [PATCH 095/115] xfs: remove the unusued tmp_logflags variable in xfs_bmapi_allocate From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229843802.1338752.18010593215932240102.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: b11ed354c9f725ece2b9440dd6343b42cd5d031c tmp_logflags is initialized to 0 and then ORed into bma->logflags, which isn't actually doing anything. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_bmap.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 84760c889..f236e40d1 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -4176,7 +4176,6 @@ xfs_bmapi_allocate( struct xfs_mount *mp = bma->ip->i_mount; int whichfork = xfs_bmapi_whichfork(bma->flags); struct xfs_ifork *ifp = xfs_ifork_ptr(bma->ip, whichfork); - int tmp_logflags = 0; int error; ASSERT(bma->length > 0); @@ -4247,8 +4246,6 @@ xfs_bmapi_allocate( error = xfs_bmap_add_extent_hole_real(bma->tp, bma->ip, whichfork, &bma->icur, &bma->cur, &bma->got, &bma->logflags, bma->flags); - - bma->logflags |= tmp_logflags; if (error) return error; From patchwork Tue Jul 30 00:48:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746017 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8D1DB4C96 for ; Tue, 30 Jul 2024 00:48:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300529; cv=none; b=gzxMcGUnDxg2+fxGC6SBI8ZUHqJEJZTP4gx7bxDpggYYuZ4JRxmhv8de4n7iMdaRZSU4LlLVbrAZnq7WF4VcOShQNdjcJlvgaMMr99+X7j2G5CWoaZ6RWhSElyayJyU3T7IkJ4VF1x0S7Kv79aiKtFnd+NOeMIkCOtkghgHXf9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300529; c=relaxed/simple; bh=e5ZtPDx+vU3HubB8yjGaccpbo8O9vMsRdvAt55Q5KQ4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jog5Vv1biCmx2qBPKWPJq9uWRBg13WtMiEhpyRWp02qH/kI6MVAHNtpTMkCQm6qOT0peVgbD01wLP0ciHQyrKg5S71xmPQNKsouUewSm2AjcwG9WG7akAc06idV6wGJtv6tIpa0fUDgFJNL700bOgP6ixwmE1shacpVqTRb3amg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rSS/3Jpu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rSS/3Jpu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66CD5C32786; Tue, 30 Jul 2024 00:48:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300529; bh=e5ZtPDx+vU3HubB8yjGaccpbo8O9vMsRdvAt55Q5KQ4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=rSS/3JpuhIdGGN1x+zGtuvwEfeR48irnrBUz3pRsU6HM26AIkXHED7NeMy5H+azuy K9qFvcm13CV5h3ea2+6zbqSJK/huA73evohozmHKXjEhYmqc6TAASP5w9dYDm0dXih IZxi9TdOBndrv+uB27TDE9bbrQQYvtYjrenvMPlf/64fkK+KvX/KE4+3ftZK0TpEyJ /SY1DZsc0M/ckHAcAd6c5r8yp4MUGu8+k8cPdnjRGQOzkc45/TKmZZz/kXBgLJnL9t oqLlv0ndgZ8QazINDZx8uASttW4nW7+MCr7pKyJ2a+3Gi5kMXUCBWB0voICpK/T91I /xGZ5YiROeGZw== Date: Mon, 29 Jul 2024 17:48:48 -0700 Subject: [PATCH 096/115] xfs: lift a xfs_valid_startblock into xfs_bmapi_allocate From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229843815.1338752.10953977831049178873.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: 04c609e6e5066294b60329420d3711e990c47abf xfs_bmapi_convert_delalloc has a xfs_valid_startblock check on the block allocated by xfs_bmapi_allocate. Lift it into xfs_bmapi_allocate as we should assert the same for xfs_bmapi_write. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_bmap.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index f236e40d1..5b1c305ec 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -4215,6 +4215,11 @@ xfs_bmapi_allocate( if (bma->blkno == NULLFSBLOCK) return -ENOSPC; + if (WARN_ON_ONCE(!xfs_valid_startblock(bma->ip, bma->blkno))) { + xfs_bmap_mark_sick(bma->ip, whichfork); + return -EFSCORRUPTED; + } + if (bma->flags & XFS_BMAPI_ZERO) { error = xfs_zero_extent(bma->ip, bma->blkno, bma->length); if (error) @@ -4707,12 +4712,6 @@ xfs_bmapi_convert_one_delalloc( if (error) goto out_finish; - if (WARN_ON_ONCE(!xfs_valid_startblock(ip, bma.got.br_startblock))) { - xfs_bmap_mark_sick(ip, whichfork); - error = -EFSCORRUPTED; - goto out_finish; - } - XFS_STATS_ADD(mp, xs_xstrat_bytes, XFS_FSB_TO_B(mp, bma.length)); XFS_STATS_INC(mp, xs_xstrat_quick); From patchwork Tue Jul 30 00:49:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746018 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2B5A2524C for ; Tue, 30 Jul 2024 00:49:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300545; cv=none; b=L+XmxFdQS3/VL0/gtT6Xq+CxRjPdV7IgrwpN8Kxs8LDQ1Z32X6Z9/W08+6oBL+GZeizoBH7ZOI4DU4N3+qlCUJl3yKQKDX2aytiOo3Ifg6kGTnfT8rWNKWn+llpomLdB3aEpr3y769EFwwcmY8VCb28LUpJJ6Hfa4zDBCQDGEBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300545; c=relaxed/simple; bh=NGyz5UT8zoUzViZ2q9ccTy/j4MymOMJOsLVL9CQ0YK8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kLDVTfC8X5c1VJP0WVYB7n0lnN1jTYxz+iHzmJv/doxMIjFh7W6+nWjFoYF0G4u0IG/d/QmQes++qjVrr2S3rUyNk6N2hRuE7tbtqhEvNLlUgHrM6Xne9JqloY8LsIxVmiX29JUJyIwU9NqAn5zSOtmuvx0vOYRY0AGDQi7wOgA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Qf7tfhg8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Qf7tfhg8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08B4EC32786; Tue, 30 Jul 2024 00:49:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300545; bh=NGyz5UT8zoUzViZ2q9ccTy/j4MymOMJOsLVL9CQ0YK8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Qf7tfhg8ABekjz2mqzITAuU/E1smY7YMz0lrA7Y6ZfFGssQNPbGbX1DoyGi7XI+zy OQiEg0IxcixU6Tl4YSKhNrfmNTARjl3/rErB/5+OyB6vlKrOwaH5ClNqO3zhN7izx+ W3VfxufNuX5xePgIXDYfTD4lm1wUUSWwjE/ij+0Zaju7AtE015X5r3VfkkzdSm/d1w /j/nn2xq+VEC+xC5agP0OLW2prQipu7c1rRe4ickv1cbtm2bIGag2TzLcgBatnR5+p RbW+zmj2geL1bweNMEOpmQBXrWkHphj6Le6f4t+e/KiSDmzAJ/8X5pe7/jVw9ZmbIG Nr5ovXoaSxs/w== Date: Mon, 29 Jul 2024 17:49:04 -0700 Subject: [PATCH 097/115] xfs: don't open code XFS_FILBLKS_MIN in xfs_bmapi_write From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229843828.1338752.6331388440954453471.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: 9d06960341ec5f45d3d65bdead3fbce753455e8a XFS_FILBLKS_MIN uses min_t and thus does the comparison using the correct xfs_filblks_t type. Use it in xfs_bmapi_write and slightly adjust the comment document th potential pitfall to take account of this Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_bmap.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 5b1c305ec..87f0a2853 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -4522,14 +4522,11 @@ xfs_bmapi_write( * allocation length request (which can be 64 bits in * length) and the bma length request, which is * xfs_extlen_t and therefore 32 bits. Hence we have to - * check for 32-bit overflows and handle them here. + * be careful and do the min() using the larger type to + * avoid overflows. */ - if (len > (xfs_filblks_t)XFS_MAX_BMBT_EXTLEN) - bma.length = XFS_MAX_BMBT_EXTLEN; - else - bma.length = len; + bma.length = XFS_FILBLKS_MIN(len, XFS_MAX_BMBT_EXTLEN); - ASSERT(len > 0); ASSERT(bma.length > 0); error = xfs_bmapi_allocate(&bma); if (error) { From patchwork Tue Jul 30 00:49:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746019 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C582663D for ; Tue, 30 Jul 2024 00:49:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300560; cv=none; b=VUTHrAhvMZioLuVMtenymxEH+O1oZ5lIWVJ9lBLxcVTkkGM1XnUwVKxFdR4hldse5VpiEqOTQM022SZpss1jFAF2Gxr4lYIPnjpkKW+k+yS6aVA/lB3QzC2Ho6AtfBMRi9syRQdPHLnckZ0s9menBVM4xNkldX3cC0vyT7iIwnw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300560; c=relaxed/simple; bh=eaz1u6koW/5F9Q4MkPfEsKhV5jakgkGHehq4vmQvHEY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=A7gmpVezbFHqu4HkZjCLWoal9XoIJfv0iDqu9VfiE+NCjBF0FB/8qA1yf4w/A+9W8LvONv9G/FJOBFHcJDex+rVZJyRnX1oTsSx+d7NwJ+415neVdXLNhHaRctb7EnvKSt/dLoe3kKFbk5vegjRRWYipKNQWZcWkjXSVTvnQjs0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YlJh2Cnf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YlJh2Cnf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3DA3C32786; Tue, 30 Jul 2024 00:49:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300560; bh=eaz1u6koW/5F9Q4MkPfEsKhV5jakgkGHehq4vmQvHEY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=YlJh2Cnf1UCkFBOdSV07T8DoEb8p/+u3mjNq17m3rNQbQ1fwT2vGUxSf+C1G+pVQ0 uRaEkhYR9uFlptiaFnWTFkuAzCSmsIY8DBUNKKOUEmukySUz7LrPlUwjSIoWqUjAiS hbQn4Zmbg4v7yUvlaMFKLgoZF5w8FMtmZV9o8Amm6CNcsmgDqmbHaFyXHaz20lr+nG 0vW/vJvzKK5ji0WESiVyLSLotiY49gmL4Yht2kO6EAAN5v6qoDVhPD92YQ7ZYmUJ3H FWz/N8780CygByZKgRrANM5CsuDsTmJnEthZIlLF5sAM3vp+ayRU2Ah7wESUYFzQu5 uLuHywQ8PhmAg== Date: Mon, 29 Jul 2024 17:49:20 -0700 Subject: [PATCH 098/115] xfs: pass the actual offset and len to allocate to xfs_bmapi_allocate From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229843840.1338752.2303408383793496548.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: 2a9b99d45be0981536f6d3faf40ae3f58febdd49 xfs_bmapi_allocate currently overwrites offset and len when converting delayed allocations, and duplicates the length cap done for non-delalloc allocations. Move all that logic into the callers to avoid duplication and to make the calling conventions more obvious. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_bmap.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 87f0a2853..a498894fc 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -4179,21 +4179,11 @@ xfs_bmapi_allocate( int error; ASSERT(bma->length > 0); + ASSERT(bma->length <= XFS_MAX_BMBT_EXTLEN); - /* - * For the wasdelay case, we could also just allocate the stuff asked - * for in this bmap call but that wouldn't be as good. - */ if (bma->wasdel) { - bma->length = (xfs_extlen_t)bma->got.br_blockcount; - bma->offset = bma->got.br_startoff; if (!xfs_iext_peek_prev_extent(ifp, &bma->icur, &bma->prev)) bma->prev.br_startoff = NULLFILEOFF; - } else { - bma->length = XFS_FILBLKS_MIN(bma->length, XFS_MAX_BMBT_EXTLEN); - if (!bma->eof) - bma->length = XFS_FILBLKS_MIN(bma->length, - bma->got.br_startoff - bma->offset); } if (bma->flags & XFS_BMAPI_CONTIG) @@ -4527,6 +4517,15 @@ xfs_bmapi_write( */ bma.length = XFS_FILBLKS_MIN(len, XFS_MAX_BMBT_EXTLEN); + if (wasdelay) { + bma.offset = bma.got.br_startoff; + bma.length = bma.got.br_blockcount; + } else { + if (!eof) + bma.length = XFS_FILBLKS_MIN(bma.length, + bma.got.br_startoff - bno); + } + ASSERT(bma.length > 0); error = xfs_bmapi_allocate(&bma); if (error) { @@ -4680,10 +4679,15 @@ xfs_bmapi_convert_one_delalloc( bma.tp = tp; bma.ip = ip; bma.wasdel = true; + bma.minleft = xfs_bmapi_minleft(tp, ip, whichfork); + + /* + * Always allocate convert from the start of the delalloc extent even if + * that is outside the passed in range to create large contiguous + * extents on disk. + */ bma.offset = bma.got.br_startoff; - bma.length = max_t(xfs_filblks_t, bma.got.br_blockcount, - XFS_MAX_BMBT_EXTLEN); - bma.minleft = xfs_bmapi_minleft(tp, ip, whichfork); + bma.length = bma.got.br_blockcount; /* * When we're converting the delalloc reservations backing dirty pages From patchwork Tue Jul 30 00:49:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746020 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 78020646 for ; Tue, 30 Jul 2024 00:49:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300576; cv=none; b=a/rFSwL0QrT7OLwgATB4i9WcSnTVtVhNa5/CfdqsTJAtjmHEGjpANxJC72DcGhy6O8iH0LIBIaBbpkmbnJacAI96vjN1/xaX1jbaGAkUHJ/5lravOhFYWFYdGuq3mCStYRLMxwbh4b9+RdILkfDoLsKMibxPTb2yapGJICKJ8Uw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300576; c=relaxed/simple; bh=3GLc+ABbuJ73pljgz0CJ27nyviXnMBDEBFuzqzArkgo=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Kxiqjr4M2ZQziL9CxF97YEMKGEQxzTgLD/Wmns+pNVT+c9q+rqM8VeSQIcwr1P09YVTJeqJwSdHLj+6AalSPUbL7tp8cgR7e2f5qx294Q6sZwk/y84r9WcclCo3jJoScHg5eC9JYwOOGKMQqY4s0HVc8R+OtiezF3dfqIIj4iJU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YH82boF5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YH82boF5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5361CC32786; Tue, 30 Jul 2024 00:49:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300576; bh=3GLc+ABbuJ73pljgz0CJ27nyviXnMBDEBFuzqzArkgo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=YH82boF5xS/zYPh6hk/s9Vluo2B19euJilvrRYax6JMeI9ACQjnJiDS4d5pIglMT9 p29Eq3Xmbpk2mLSkp27I4p8UxVsTHOuIGB9ZUMl3GWTt4i6aMZCe/jMKGsHDQyr9PG 3gevq1JetaJ9MiowVjQQP+5xIlNfYn/NkYa5aTpALPxGia4jZmHdC7wTRPjWpD3/k6 VdCHZfHNQV/VJJ+27R7+Mf2wkCEJalyubxAer5GHIORl5+ykt3yXSRgCc+tIxTAAwj ha+a321QKblksGK3Ybeq+Mq6EUXOtoLiU1JhRwLsDf65BQftZ6f+5s/AxUsYwA7UER yPC1YCKEhXyfg== Date: Mon, 29 Jul 2024 17:49:35 -0700 Subject: [PATCH 099/115] xfs: remove the xfs_iext_peek_prev_extent call in xfs_bmapi_allocate From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229843853.1338752.3161520143092544832.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: a8bb258f703f42c322638022afa16808ca4a7d25 Both callers of xfs_bmapi_allocate already initialize bma->prev, don't redo that in xfs_bmapi_allocate. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_bmap.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index a498894fc..4279ab83d 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -4181,11 +4181,6 @@ xfs_bmapi_allocate( ASSERT(bma->length > 0); ASSERT(bma->length <= XFS_MAX_BMBT_EXTLEN); - if (bma->wasdel) { - if (!xfs_iext_peek_prev_extent(ifp, &bma->icur, &bma->prev)) - bma->prev.br_startoff = NULLFILEOFF; - } - if (bma->flags & XFS_BMAPI_CONTIG) bma->minlen = bma->length; else From patchwork Tue Jul 30 00:49:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746021 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7BF6F1373 for ; Tue, 30 Jul 2024 00:49:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300592; cv=none; b=os9mELP25qg8uUMpTIITknc9UPmShzGjxOI3nWovlJPSnxsy81cyvzgzIkArlX0/imcrQ5x8P332dJn3dGQKG9SUFrfvhfJyPSZGnFlxE3Pen6apN4O128vhdN8A5Bm+JEnHDFP7ERm1KTqlkgbOndFz9BR6j51f2NXFlNxILSg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300592; c=relaxed/simple; bh=tNUKVazbnVPJ8lL6F9D9i9jfsuQrsy2GT03xye9nuyM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FphkffHaaKnp9NKwB2HBMY+kKwNjak1AD2W5vHNDAwrgTLaTfwL7ZWgBgfNWlrFJ33Rl1L5BqOFmaQ7KBnttKd7olOqR2AnQRBqeKisabVekpWkcXkEqq9BGyfD5pBB46oK3Isqw61zbquqnQSMbrU+6aBCSmNLSpl7crWhGG5s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ngEs+pmG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ngEs+pmG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A941C32786; Tue, 30 Jul 2024 00:49:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300592; bh=tNUKVazbnVPJ8lL6F9D9i9jfsuQrsy2GT03xye9nuyM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ngEs+pmGq2lQ2YEmyQ/L3J37jqzjrUOtcjgPEwOevtkAGm6qFI8st1dIK0rV5Btid T8e5cX5xzh59wcUMfs4sxs5wcgJOeSHwtX0EhYuVSm8X2DTLtRNm4i2W5wagdjDmPB p4cBod5RcfBsn9ZCsNGWqNXECMM++qYVK6qodTkGVlQZBPh4vpQJxIvCbgqZaxadCW RRfc7ciHCDQSCegxSxEnWHT5rC0OI4xNGHB/cjOOOi8toUefqg+OcmUWLXDJsnd+qF 9aRafsuOwE+LItFqekXlHFzJe+cerbNgn5nY7Y9X+XPtxpnHkQAx4KtuFptXBjk3vD ishg+6NWkXblw== Date: Mon, 29 Jul 2024 17:49:51 -0700 Subject: [PATCH 100/115] xfs: fix xfs_bmap_add_extent_delay_real for partial conversions From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229843866.1338752.16860089417780659312.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: d69bee6a35d3c5e4873b9e164dd1a9711351a97c xfs_bmap_add_extent_delay_real takes parts or all of a delalloc extent and converts them to a real extent. It is written to deal with any potential overlap of the to be converted range with the delalloc extent, but it turns out that currently only converting the entire extents, or a part starting at the beginning is actually exercised, as the only caller always tries to convert the entire delalloc extent, and either succeeds or at least progresses partially from the start. If it only converts a tiny part of a delalloc extent, the indirect block calculation for the new delalloc extent (da_new) might be equivalent to that of the existing delalloc extent (da_old). If this extent conversion now requires allocating an indirect block that gets accounted into da_new, leading to the assert that da_new must be smaller or equal to da_new unless we split the extent to trigger. Except for the assert that case is actually handled by just trying to allocate more space, as that already handled for the split case (which currently can't be reached at all), so just reusing it should be fine. Except that without dipping into the reserved block pool that would make it a bit too easy to trigger a fs shutdown due to ENOSPC. So in addition to adjusting the assert, also dip into the reserved block pool. Note that I could only reproduce the assert with a change to only convert the actually asked range instead of the full delalloc extent from xfs_bmapi_write. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_bmap.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 4279ab83d..9af65a182 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -1564,6 +1564,7 @@ xfs_bmap_add_extent_delay_real( if (error) goto done; } + ASSERT(da_new <= da_old); break; case BMAP_LEFT_FILLING | BMAP_RIGHT_FILLING | BMAP_LEFT_CONTIG: @@ -1594,6 +1595,7 @@ xfs_bmap_add_extent_delay_real( if (error) goto done; } + ASSERT(da_new <= da_old); break; case BMAP_LEFT_FILLING | BMAP_RIGHT_FILLING | BMAP_RIGHT_CONTIG: @@ -1628,6 +1630,7 @@ xfs_bmap_add_extent_delay_real( if (error) goto done; } + ASSERT(da_new <= da_old); break; case BMAP_LEFT_FILLING | BMAP_RIGHT_FILLING: @@ -1662,6 +1665,7 @@ xfs_bmap_add_extent_delay_real( goto done; } } + ASSERT(da_new <= da_old); break; case BMAP_LEFT_FILLING | BMAP_LEFT_CONTIG: @@ -1700,6 +1704,7 @@ xfs_bmap_add_extent_delay_real( if (error) goto done; } + ASSERT(da_new <= da_old); break; case BMAP_LEFT_FILLING: @@ -1790,6 +1795,7 @@ xfs_bmap_add_extent_delay_real( xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV); xfs_iext_next(ifp, &bma->icur); xfs_iext_update_extent(bma->ip, state, &bma->icur, &RIGHT); + ASSERT(da_new <= da_old); break; case BMAP_RIGHT_FILLING: @@ -1839,6 +1845,7 @@ xfs_bmap_add_extent_delay_real( PREV.br_blockcount = temp; xfs_iext_insert(bma->ip, &bma->icur, &PREV, state); xfs_iext_next(ifp, &bma->icur); + ASSERT(da_new <= da_old); break; case 0: @@ -1961,12 +1968,10 @@ xfs_bmap_add_extent_delay_real( } /* adjust for changes in reserved delayed indirect blocks */ - if (da_new < da_old) { + if (da_new < da_old) xfs_add_fdblocks(mp, da_old - da_new); - } else if (da_new > da_old) { - ASSERT(state == 0); - error = xfs_dec_fdblocks(mp, da_new - da_old, false); - } + else if (da_new > da_old) + error = xfs_dec_fdblocks(mp, da_new - da_old, true); xfs_bmap_check_leaf_extents(bma->cur, bma->ip, whichfork); done: From patchwork Tue Jul 30 00:50:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746022 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D1DE62563 for ; Tue, 30 Jul 2024 00:50:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300607; cv=none; b=kU9j7laIEkzlCV2kh73G/jEs6QK3ZyDDcFqzOC5VxrbCUXG78Rne8KhgJhhxMQn9/+zLt8TAb9cbs+NmgpEJsMHP3nSnjwOQVN1l5tQj+QQTVnvtgW5AVFUg4vuHFOC0Nfl6bdZTTUC0PwnkxMmxKrYJSm9Z8m+gIifJw/fyAeY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300607; c=relaxed/simple; bh=QY67knpmrPue324suU0s6X4F0LQvzJETQkZopPG0zE4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DpVDZ9sZ6KDHqwCVL4PHeDa8ZEYgU4y/RcsQ5KlOOvshE91bSbBixnH1LM64h5SgsEvj9QY8h4oHiAu00qc1gm5WEHeNbmxASbU4+6G/pOV6KLI1If8ac9Iq4JB2CiDqIKXHSvLEL3SdpWQSKsHLPMokJp8oqBqWS3RTs5jlRR4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EzugyMVj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EzugyMVj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9EA8C4AF07; Tue, 30 Jul 2024 00:50:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300607; bh=QY67knpmrPue324suU0s6X4F0LQvzJETQkZopPG0zE4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=EzugyMVjs6K1EAY31KB3FQ6RLez7SWXaBCn6bi4WA8b3olwiGcBNGfZ4uwZ713jwb qX5i1KEK+waUK7xXkdUKux365alMHSKj7zy7StF0HEvRr7d/MGHLZ7S04+QxqQoxuQ GiHIGymKpUUTcWbSptp5NTJ0+WSAu9D6H+9rK31dxXAze+63t5ap+oBkRXjmxjmDJc i25Io+iSfXmN1PMB2x09+vdI9DY3ESYar3VjANKCyzu22/v8pLbpAaPCZf4Z/rC1kR WAq+gk9/Oteg3QOP2DhtiA6tLvyvtzButZhDTfBJiQ4qTpUXwgW4epTEXuOji5BSCi F1F0KZoRp7UFw== Date: Mon, 29 Jul 2024 17:50:07 -0700 Subject: [PATCH 101/115] xfs: do not allocate the entire delalloc extent in xfs_bmapi_write From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229843878.1338752.8665884225036255363.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: 21255afdd7296f57dd65f815301426bcf911c82d While trying to convert the entire delalloc extent is a good decision for regular writeback as it leads to larger contigous on-disk extents, but for other callers of xfs_bmapi_write is is rather questionable as it forced them to loop creating new transactions just in case there is no large enough contiguous extent to cover the whole delalloc reservation. Change xfs_bmapi_write to only allocate the passed in range instead, whÑ–le the writeback path through xfs_bmapi_convert_delalloc and xfs_bmapi_allocate still always converts the full extents. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: Chandan Babu R --- libxfs/xfs_bmap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 9af65a182..e6d700138 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -4518,8 +4518,9 @@ xfs_bmapi_write( bma.length = XFS_FILBLKS_MIN(len, XFS_MAX_BMBT_EXTLEN); if (wasdelay) { - bma.offset = bma.got.br_startoff; - bma.length = bma.got.br_blockcount; + bma.length = XFS_FILBLKS_MIN(bma.length, + bma.got.br_blockcount - + (bno - bma.got.br_startoff)); } else { if (!eof) bma.length = XFS_FILBLKS_MIN(bma.length, From patchwork Tue Jul 30 00:50:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746023 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8432963D for ; Tue, 30 Jul 2024 00:50:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300623; cv=none; b=XJnHKCYeHxqHfLhGNLS49+6kNwUXOXAuW+df/ftrNoK0zjpT7tLeAzpkHqC8lcg4HUB0N9u5D6dzS4KraaX3ECu0V0mFRBe5lx8FCaIIG/MhJTTOenzOpsc6frSU/TUPPQ9QWjC5mDHQi5JX0FFU2Cz0HV5sXVIUSGmiDLQSovo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300623; c=relaxed/simple; bh=9c7EMmuYZ7ZJQ3i61e30K372PXHFeyvKM6jGei/0Pj8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=s60+mJ2jyWFrB2wkXXeOR1pIG96zBS7Om7QSS6KduSJSKmRAMyeFiXzmedmsuXhjAtwDm/oCesESAlKq7hg0cT7JTwajl/yIKOOiLb6yBVEC2f8xqtuL+ZXuM6eyM20aImdM6KmqhwM8bWYfUH+hMVW4Slh9VpacGLq+AnJuA3U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EaDix+04; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EaDix+04" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D707C32786; Tue, 30 Jul 2024 00:50:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300623; bh=9c7EMmuYZ7ZJQ3i61e30K372PXHFeyvKM6jGei/0Pj8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=EaDix+04XFyJZrdES/sfSIgLZDSnIevrIaZo50gudhuGEHBBuYejyuLVcZ8FnS2ug 10bQndBmZ/ERn/v9v8vTbOzBLFpUndO6izl4FqkKcQh6EyhQpnA8d9wBtM5+OPJ7ze lZrGV/WybVsFwT/rIgCO5/5mrChOUfJkPGiJwQ7eBZ1mX6l3BNDxnsMUFOf4hM2fEf hcs5okNjmkw3qbGkJNhBJvSNT9jEeTm0KZnqFfCRmw6FJ2PUVHzsMMaPl7qWpUSgmy nUFcWrSqpUyT7K6o/QU936kPbJ8oIzpbre4dANLP88amUTWULm+CNS09O2N20mlM9e RdlrBoCBNcTKg== Date: Mon, 29 Jul 2024 17:50:22 -0700 Subject: [PATCH 102/115] xfs: use unsigned ints for non-negative quantities in xfs_attr_remote.c From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Andrey Albershteyn , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843891.1338752.4693656738170403532.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: a86f8671d03e6eb31abaefdf6928b92df0a2368c In the next few patches we're going to refactor the attr remote code so that we can support headerless remote xattr values for storing merkle tree blocks. For now, let's change the code to use unsigned int to describe quantities of bytes and blocks that cannot be negative. Signed-off-by: Darrick J. Wong Reviewed-by: Andrey Albershteyn Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr_remote.c | 61 +++++++++++++++++++++++----------------------- libxfs/xfs_attr_remote.h | 2 +- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/libxfs/xfs_attr_remote.c b/libxfs/xfs_attr_remote.c index 282cf2cb9..34e74fd57 100644 --- a/libxfs/xfs_attr_remote.c +++ b/libxfs/xfs_attr_remote.c @@ -46,13 +46,13 @@ * Each contiguous block has a header, so it is not just a simple attribute * length to FSB conversion. */ -int +unsigned int xfs_attr3_rmt_blocks( - struct xfs_mount *mp, - int attrlen) + struct xfs_mount *mp, + unsigned int attrlen) { if (xfs_has_crc(mp)) { - int buflen = XFS_ATTR3_RMT_BUF_SPACE(mp, mp->m_sb.sb_blocksize); + unsigned int buflen = XFS_ATTR3_RMT_BUF_SPACE(mp, mp->m_sb.sb_blocksize); return (attrlen + buflen - 1) / buflen; } return XFS_B_TO_FSB(mp, attrlen); @@ -91,7 +91,6 @@ xfs_attr3_rmt_verify( struct xfs_mount *mp, struct xfs_buf *bp, void *ptr, - int fsbsize, xfs_daddr_t bno) { struct xfs_attr3_rmt_hdr *rmt = ptr; @@ -102,7 +101,7 @@ xfs_attr3_rmt_verify( return __this_address; if (be64_to_cpu(rmt->rm_blkno) != bno) return __this_address; - if (be32_to_cpu(rmt->rm_bytes) > fsbsize - sizeof(*rmt)) + if (be32_to_cpu(rmt->rm_bytes) > mp->m_attr_geo->blksize - sizeof(*rmt)) return __this_address; if (be32_to_cpu(rmt->rm_offset) + be32_to_cpu(rmt->rm_bytes) > XFS_XATTR_SIZE_MAX) @@ -121,9 +120,9 @@ __xfs_attr3_rmt_read_verify( { struct xfs_mount *mp = bp->b_mount; char *ptr; - int len; + unsigned int len; xfs_daddr_t bno; - int blksize = mp->m_attr_geo->blksize; + unsigned int blksize = mp->m_attr_geo->blksize; /* no verification of non-crc buffers */ if (!xfs_has_crc(mp)) @@ -140,7 +139,7 @@ __xfs_attr3_rmt_read_verify( *failaddr = __this_address; return -EFSBADCRC; } - *failaddr = xfs_attr3_rmt_verify(mp, bp, ptr, blksize, bno); + *failaddr = xfs_attr3_rmt_verify(mp, bp, ptr, bno); if (*failaddr) return -EFSCORRUPTED; len -= blksize; @@ -185,7 +184,7 @@ xfs_attr3_rmt_write_verify( { struct xfs_mount *mp = bp->b_mount; xfs_failaddr_t fa; - int blksize = mp->m_attr_geo->blksize; + unsigned int blksize = mp->m_attr_geo->blksize; char *ptr; int len; xfs_daddr_t bno; @@ -202,7 +201,7 @@ xfs_attr3_rmt_write_verify( while (len > 0) { struct xfs_attr3_rmt_hdr *rmt = (struct xfs_attr3_rmt_hdr *)ptr; - fa = xfs_attr3_rmt_verify(mp, bp, ptr, blksize, bno); + fa = xfs_attr3_rmt_verify(mp, bp, ptr, bno); if (fa) { xfs_verifier_error(bp, -EFSCORRUPTED, fa); return; @@ -280,20 +279,20 @@ xfs_attr_rmtval_copyout( struct xfs_buf *bp, struct xfs_inode *dp, xfs_ino_t owner, - int *offset, - int *valuelen, + unsigned int *offset, + unsigned int *valuelen, uint8_t **dst) { char *src = bp->b_addr; xfs_daddr_t bno = xfs_buf_daddr(bp); - int len = BBTOB(bp->b_length); - int blksize = mp->m_attr_geo->blksize; + unsigned int len = BBTOB(bp->b_length); + unsigned int blksize = mp->m_attr_geo->blksize; ASSERT(len >= blksize); while (len > 0 && *valuelen > 0) { - int hdr_size = 0; - int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize); + unsigned int hdr_size = 0; + unsigned int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize); byte_cnt = min(*valuelen, byte_cnt); @@ -329,20 +328,20 @@ xfs_attr_rmtval_copyin( struct xfs_mount *mp, struct xfs_buf *bp, xfs_ino_t ino, - int *offset, - int *valuelen, + unsigned int *offset, + unsigned int *valuelen, uint8_t **src) { char *dst = bp->b_addr; xfs_daddr_t bno = xfs_buf_daddr(bp); - int len = BBTOB(bp->b_length); - int blksize = mp->m_attr_geo->blksize; + unsigned int len = BBTOB(bp->b_length); + unsigned int blksize = mp->m_attr_geo->blksize; ASSERT(len >= blksize); while (len > 0 && *valuelen > 0) { - int hdr_size; - int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize); + unsigned int hdr_size; + unsigned int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize); byte_cnt = min(*valuelen, byte_cnt); hdr_size = xfs_attr3_rmt_hdr_set(mp, dst, ino, *offset, @@ -388,12 +387,12 @@ xfs_attr_rmtval_get( struct xfs_buf *bp; xfs_dablk_t lblkno = args->rmtblkno; uint8_t *dst = args->value; - int valuelen; + unsigned int valuelen; int nmap; int error; - int blkcnt = args->rmtblkcnt; + unsigned int blkcnt = args->rmtblkcnt; int i; - int offset = 0; + unsigned int offset = 0; trace_xfs_attr_rmtval_get(args); @@ -451,7 +450,7 @@ xfs_attr_rmt_find_hole( struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; int error; - int blkcnt; + unsigned int blkcnt; xfs_fileoff_t lfileoff = 0; /* @@ -480,11 +479,11 @@ xfs_attr_rmtval_set_value( struct xfs_bmbt_irec map; xfs_dablk_t lblkno; uint8_t *src = args->value; - int blkcnt; - int valuelen; + unsigned int blkcnt; + unsigned int valuelen; int nmap; int error; - int offset = 0; + unsigned int offset = 0; /* * Roll through the "value", copying the attribute value to the @@ -643,7 +642,7 @@ xfs_attr_rmtval_invalidate( struct xfs_da_args *args) { xfs_dablk_t lblkno; - int blkcnt; + unsigned int blkcnt; int error; /* diff --git a/libxfs/xfs_attr_remote.h b/libxfs/xfs_attr_remote.h index d097ec6c4..c64b04f91 100644 --- a/libxfs/xfs_attr_remote.h +++ b/libxfs/xfs_attr_remote.h @@ -6,7 +6,7 @@ #ifndef __XFS_ATTR_REMOTE_H__ #define __XFS_ATTR_REMOTE_H__ -int xfs_attr3_rmt_blocks(struct xfs_mount *mp, int attrlen); +unsigned int xfs_attr3_rmt_blocks(struct xfs_mount *mp, unsigned int attrlen); int xfs_attr_rmtval_get(struct xfs_da_args *args); int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map, From patchwork Tue Jul 30 00:50:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 262731373 for ; Tue, 30 Jul 2024 00:50:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300639; cv=none; b=ogg8DW2fQmdHD4kropd9icN8ZOK8i+338LfQUpYWYkv5SWrIMgKCnu28ii8bsugqLX9DXxB8K+LpH0wk0WZivuwkrFMnnMivci8Wxo8NS2elv2G0wd2iVnwpYK8TVOE0MsLOowenIQKqDx2UfbZggsneQMPUL6veS3WLBqWeQuM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300639; c=relaxed/simple; bh=yTrH3zsi6DnqeDzCE7JlQfJ2Ryqi3kvrNEyUiZH6MJk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Bb5L/TGCpFpti9/L2vpnu8FFWkrCxj9M9DbIAW+LdCaMQ6XLb5ec/LJaq6MsqTcxWnKsTAP/tMMZmiOuvUsf9US209m4ebdoXu+83s8vStaBWgbVo6nHMcNCgX9Axh7j+EN8dRFJ9jrLD/PwWiAPEzP3FCFWMo/8tcsBHbgCVTA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YJXbSgaj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YJXbSgaj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F19E6C32786; Tue, 30 Jul 2024 00:50:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300639; bh=yTrH3zsi6DnqeDzCE7JlQfJ2Ryqi3kvrNEyUiZH6MJk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=YJXbSgajuARvsHSko/xhHGWhWL8tdPdT4ckUPQlmIL62yCH2FXGS9Sil3vfQ0Xi3Q pHPhl/FWyzdVa0qguB6aBfusF5K8RBT6WDSkwnYPPcfbWEoTlup4u6q0cMKyvANUDg u/5x9tt4kOoY4f3BrP2Xauosa5pICVJuELvb8nhPgF7ZD/By1GQ0w0Ma1UwCWW1NdF lVUqPsRwikR443HcZmeB3tikOTo+BHb6L9UQQoKLoZLIGoFFIhuaWs5i1F8G3WkLak JfXozOWOHHMsMB+2Z9ywHCPymIM7P1lO5Efc8HsEpyFWF5T8eukj9TI6WW9xjLTTIK YevaG+zY8hBCQ== Date: Mon, 29 Jul 2024 17:50:38 -0700 Subject: [PATCH 103/115] xfs: turn XFS_ATTR3_RMT_BUF_SPACE into a function From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Andrey Albershteyn , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843903.1338752.16739798694181425064.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: a5714b67cad586f44777ad834e577037ce6b64fd Turn this into a properly typechecked function, and actually use the correct blocksize for extended attributes. The function cannot be static inline because xfsprogs userspace uses it. Signed-off-by: Darrick J. Wong Reviewed-by: Andrey Albershteyn Reviewed-by: Christoph Hellwig --- db/attr.c | 2 +- db/metadump.c | 8 ++++---- libxfs/xfs_attr_remote.c | 19 ++++++++++++++++--- libxfs/xfs_da_format.h | 4 +--- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/db/attr.c b/db/attr.c index ba722e146..de68d6276 100644 --- a/db/attr.c +++ b/db/attr.c @@ -214,7 +214,7 @@ attr3_remote_data_count( if (hdr->rm_magic != cpu_to_be32(XFS_ATTR3_RMT_MAGIC)) return 0; - buf_space = XFS_ATTR3_RMT_BUF_SPACE(mp, mp->m_sb.sb_blocksize); + buf_space = xfs_attr3_rmt_buf_space(mp); if (be32_to_cpu(hdr->rm_bytes) > buf_space) return buf_space; return be32_to_cpu(hdr->rm_bytes); diff --git a/db/metadump.c b/db/metadump.c index a656ef574..9457e02e8 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -1369,7 +1369,7 @@ add_remote_vals( attr_data.remote_vals[attr_data.remote_val_count] = blockidx; attr_data.remote_val_count++; blockidx++; - length -= XFS_ATTR3_RMT_BUF_SPACE(mp, mp->m_sb.sb_blocksize); + length -= xfs_attr3_rmt_buf_space(mp); } if (attr_data.remote_val_count >= MAX_REMOTE_VALS) { @@ -1405,8 +1405,8 @@ process_attr_block( attr_data.remote_vals[i] == offset) /* Macros to handle both attr and attr3 */ memset(block + - (bs - XFS_ATTR3_RMT_BUF_SPACE(mp, bs)), - 'v', XFS_ATTR3_RMT_BUF_SPACE(mp, bs)); + (bs - xfs_attr3_rmt_buf_space(mp)), + 'v', xfs_attr3_rmt_buf_space(mp)); } return; } @@ -1418,7 +1418,7 @@ process_attr_block( if (nentries == 0 || nentries * sizeof(xfs_attr_leaf_entry_t) + xfs_attr3_leaf_hdr_size(leaf) > - XFS_ATTR3_RMT_BUF_SPACE(mp, bs)) { + xfs_attr3_rmt_buf_space(mp)) { if (metadump.show_warnings) print_warning("invalid attr count in inode %llu", (long long)metadump.cur_ino); diff --git a/libxfs/xfs_attr_remote.c b/libxfs/xfs_attr_remote.c index 34e74fd57..58078465b 100644 --- a/libxfs/xfs_attr_remote.c +++ b/libxfs/xfs_attr_remote.c @@ -42,6 +42,19 @@ * the logging system and therefore never have a log item. */ +/* How many bytes can be stored in a remote value buffer? */ +inline unsigned int +xfs_attr3_rmt_buf_space( + struct xfs_mount *mp) +{ + unsigned int blocksize = mp->m_attr_geo->blksize; + + if (xfs_has_crc(mp)) + return blocksize - sizeof(struct xfs_attr3_rmt_hdr); + + return blocksize; +} + /* * Each contiguous block has a header, so it is not just a simple attribute * length to FSB conversion. @@ -52,7 +65,7 @@ xfs_attr3_rmt_blocks( unsigned int attrlen) { if (xfs_has_crc(mp)) { - unsigned int buflen = XFS_ATTR3_RMT_BUF_SPACE(mp, mp->m_sb.sb_blocksize); + unsigned int buflen = xfs_attr3_rmt_buf_space(mp); return (attrlen + buflen - 1) / buflen; } return XFS_B_TO_FSB(mp, attrlen); @@ -292,7 +305,7 @@ xfs_attr_rmtval_copyout( while (len > 0 && *valuelen > 0) { unsigned int hdr_size = 0; - unsigned int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize); + unsigned int byte_cnt = xfs_attr3_rmt_buf_space(mp); byte_cnt = min(*valuelen, byte_cnt); @@ -341,7 +354,7 @@ xfs_attr_rmtval_copyin( while (len > 0 && *valuelen > 0) { unsigned int hdr_size; - unsigned int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize); + unsigned int byte_cnt = xfs_attr3_rmt_buf_space(mp); byte_cnt = min(*valuelen, byte_cnt); hdr_size = xfs_attr3_rmt_hdr_set(mp, dst, ino, *offset, diff --git a/libxfs/xfs_da_format.h b/libxfs/xfs_da_format.h index ebde6eb1d..86de99e2f 100644 --- a/libxfs/xfs_da_format.h +++ b/libxfs/xfs_da_format.h @@ -880,9 +880,7 @@ struct xfs_attr3_rmt_hdr { #define XFS_ATTR3_RMT_CRC_OFF offsetof(struct xfs_attr3_rmt_hdr, rm_crc) -#define XFS_ATTR3_RMT_BUF_SPACE(mp, bufsize) \ - ((bufsize) - (xfs_has_crc((mp)) ? \ - sizeof(struct xfs_attr3_rmt_hdr) : 0)) +unsigned int xfs_attr3_rmt_buf_space(struct xfs_mount *mp); /* Number of bytes in a directory block. */ static inline unsigned int xfs_dir2_dirblock_bytes(struct xfs_sb *sbp) From patchwork Tue Jul 30 00:50:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D61592563 for ; Tue, 30 Jul 2024 00:50:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300654; cv=none; b=U6h7Dl9kH3ux3fg2lIKFqwaSoHK4BokhKzQFg4zyUpt+y5g5bIxQ/LWHTIgX6wskU81ZlhGtr1WCbY6E+lR9lEEQxvF+rdHCBKkAIHjAoFQFfwWZyjEYxP38VK+ioQKq8mOqw4pcU2d4Zf/RCVQKt6+DYEMKJZtWHuT363rmMIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300654; c=relaxed/simple; bh=xTIMnnubxwLmA9tcjXfYwIoxJ5BHgce+qN1cnPf9r9I=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qh6rBkAkm9/xAT9g+RoiIfuJg51niqJ6HNZP9TbAMxZJNmWRGRvUMisU7SdgdWUd1a6AoLsMia7/isM48SBkuMy4vbXbdPyLKH9P0KG+TxHjOwIvw1H8RPFGYAT9qK6ejBWyHJLeIZsmbhQl+oskz09hySCCSkQ1hiL+uqNpS4I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pbFDCTkJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pbFDCTkJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEAA9C32786; Tue, 30 Jul 2024 00:50:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300654; bh=xTIMnnubxwLmA9tcjXfYwIoxJ5BHgce+qN1cnPf9r9I=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=pbFDCTkJBLgxvdiOTLyPWFNGgZyQuusUM5VTtDnI4eG+bWkpWHAILzfchhBYzuH6O aiVXBeWOlSsBAgBVmzOXtQkAWGMVp6KgN38ImGyvybWBxX/gm38zaAqB1SSqjZB8tN kcIOQyhxl/pEtgU4cxFxobHErGKS+uwzYUFyrzO2pi7OX7yEnXrB5Uhutws6Fb9mf+ dUpeh4Gb2zNUN24blAGTxUXk3IusbuHESroIvBWWDM2957kzkJ4XEq1OIFEABIeZ2s NymgLLthw21yH293+CXEVmT87nDMUMvjDCJiezr4g9pCuNedTPDQdTsHcJyr6pqYaV WMArLb257BNJQ== Date: Mon, 29 Jul 2024 17:50:54 -0700 Subject: [PATCH 104/115] xfs: create a helper to compute the blockcount of a max sized remote value From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Andrey Albershteyn , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843916.1338752.3701572370367235328.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 204a26aa1d5a891154c9275fe4022e28793ca112 Create a helper function to compute the number of fsblocks needed to store a maximally-sized extended attribute value. Signed-off-by: Darrick J. Wong Reviewed-by: Andrey Albershteyn Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr.c | 2 +- libxfs/xfs_attr_remote.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 52fcb1c4c..99648d78c 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -1035,7 +1035,7 @@ xfs_attr_set( break; case XFS_ATTRUPDATE_REMOVE: XFS_STATS_INC(mp, xs_attr_remove); - rmt_blks = xfs_attr3_rmt_blocks(mp, XFS_XATTR_SIZE_MAX); + rmt_blks = xfs_attr3_max_rmt_blocks(mp); break; } diff --git a/libxfs/xfs_attr_remote.h b/libxfs/xfs_attr_remote.h index c64b04f91..e3c6c7d77 100644 --- a/libxfs/xfs_attr_remote.h +++ b/libxfs/xfs_attr_remote.h @@ -8,6 +8,12 @@ unsigned int xfs_attr3_rmt_blocks(struct xfs_mount *mp, unsigned int attrlen); +/* Number of rmt blocks needed to store the maximally sized attr value */ +static inline unsigned int xfs_attr3_max_rmt_blocks(struct xfs_mount *mp) +{ + return xfs_attr3_rmt_blocks(mp, XFS_XATTR_SIZE_MAX); +} + int xfs_attr_rmtval_get(struct xfs_da_args *args); int xfs_attr_rmtval_stale(struct xfs_inode *ip, struct xfs_bmbt_irec *map, xfs_buf_flags_t incore_flags); From patchwork Tue Jul 30 00:51:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C488B63D for ; Tue, 30 Jul 2024 00:51:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300670; cv=none; b=BD1hV4XJNmLdTa/kxymusgN1ZqsCSTS8ca0hsPkhJGiooGTdYV7luhaMDCKRsI8kJs4wkFO/J/ewyN1gjp6CqLZM545hufMsP95XwjDCMAByoqiEsWOKnYSn0bz8hcMwMrZefBOMRT0CxkfHgUFHd5PNFQeUnvjFT8EHPGyarlM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300670; c=relaxed/simple; bh=x372SjV2Ff6e8UCPVHDwa/1zzwMKM+GeyG7UmeBzCH8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DaEotFizkfYcxKnnWXWWi+y0KGww/ZfqLIgIzU08I+RH6z7rjhKnEdB67crBvOtnD1LBFy5J7v2iDyrTwqq7pKBaeKOyYG//gde/K+t3AixJPgGMLbFK+/TmpXDVm15dIIqYQqkfiSM16dYRIzqqoL8EOuzGBAB3KC9rBV7fzQ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hG3hk6Kc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hG3hk6Kc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F222C32786; Tue, 30 Jul 2024 00:51:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300670; bh=x372SjV2Ff6e8UCPVHDwa/1zzwMKM+GeyG7UmeBzCH8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=hG3hk6Kc6DGnQexzBxTYqpwSimWe/lQLw24yfyT6LOjF8dHGZcJ2To4vu+aKL8XM/ EuLgoYuoZmrGNH/1sNH5GqPfm27tYblVDaTX9fhL4Z4NmFoFH2FVLa7G6GCHVNAmb1 mcXXgTeeYo5tSk7TmCSWx//3APzRnQmN6QsWtQsC2B0KD+LkEVl+gXurc1S93+ljNm gE/hi70ecm40THcWCz6gYJzsmVtIhjelC+x2awiNJS63TCCSo0BJQBsyY7PYO5pVKK PeMC/TjxBZgSvrbuqT6q2aaNgVVTng9J8UuuJKz272kSf7p+pAIxrduG7WEoChyDu4 lXioDTZgCZPGw== Date: Mon, 29 Jul 2024 17:51:09 -0700 Subject: [PATCH 105/115] xfs: minor cleanups of xfs_attr3_rmt_blocks From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Andrey Albershteyn , Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843929.1338752.4061483218370317133.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 3791a053294b037a6bf62df03480f5c5ddfd4d1b Clean up the type signature of this function since we don't have negative attr lengths or block counts. Signed-off-by: Darrick J. Wong Reviewed-by: Andrey Albershteyn Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr_remote.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libxfs/xfs_attr_remote.c b/libxfs/xfs_attr_remote.c index 58078465b..a048aa5f2 100644 --- a/libxfs/xfs_attr_remote.c +++ b/libxfs/xfs_attr_remote.c @@ -55,19 +55,19 @@ xfs_attr3_rmt_buf_space( return blocksize; } -/* - * Each contiguous block has a header, so it is not just a simple attribute - * length to FSB conversion. - */ +/* Compute number of fsblocks needed to store a remote attr value */ unsigned int xfs_attr3_rmt_blocks( struct xfs_mount *mp, unsigned int attrlen) { - if (xfs_has_crc(mp)) { - unsigned int buflen = xfs_attr3_rmt_buf_space(mp); - return (attrlen + buflen - 1) / buflen; - } + /* + * Each contiguous block has a header, so it is not just a simple + * attribute length to FSB conversion. + */ + if (xfs_has_crc(mp)) + return howmany(attrlen, xfs_attr3_rmt_buf_space(mp)); + return XFS_B_TO_FSB(mp, attrlen); } From patchwork Tue Jul 30 00:51:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746029 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2C5261373 for ; Tue, 30 Jul 2024 00:51:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300686; cv=none; b=OlVB9Y5grnzrMaXEyulG7qC7g78IgGFteIB0VXpNIK7UM9vbCyt1MFYMzCiI04z0LPQ9yasn5l68aHOkzJfJmJbbxjzQkv680QghyqM2TsQu2HfRyTNaC+X9s+1nFeY/F4weCACBOlNVHt9Z9Bq5QKzxcafgew3uXSs/B6846y0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300686; c=relaxed/simple; bh=CY9MehgVyxEs1R462SS9fNdXDlf9A+7SFrTrgNmo6c0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=beb6+OWCztZWpzUZXJM+SvJpRcqeFw9F61UB3czVbcffkoA7c0xTe7AFsNe9TzyqaZNbjC6UP0l04WjgexlGtNv0vu2yxC5rU7zgWJ6eFuaTrZHPWCub2GYlEVmmgB2gs9HAlhQS6WAwmPUqCib8nrABAXO734A8RDJga643YUM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LrTLmIwb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LrTLmIwb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0205FC32786; Tue, 30 Jul 2024 00:51:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300686; bh=CY9MehgVyxEs1R462SS9fNdXDlf9A+7SFrTrgNmo6c0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=LrTLmIwb+JAWxHaMghSmgrWkgdnLg9GeIfBwEFLWt1m5ZkYJ9mIc+c9WzjzMJa0BJ ugpQN6G0OJ926IiRdWx+Ew54GSNTauWo4NJ0y1gvBHsG4JqUWeCTw7dfiXggDZ8WUi n1WxA4HQBhPLl5m3uw6ERX7A/u6hWfx/e9aDuTFOwo9ZwQWxy1p3BvtO3ok2UuoH4i clbEK+lNPe/SNka87xa0Uz2YczgXIySBgGZpM1EYlP+Pcjq7/F9Qsen8jVED0WK6G7 29Gkkt58UgfKPnd+LjqGXd3TfEwBW4gArt4/UVZJcf9ht7l6euWieJIkgtVvUFk9Ko JvTMh/J1G+Adw== Date: Mon, 29 Jul 2024 17:51:25 -0700 Subject: [PATCH 106/115] xfs: xfs_quota_unreserve_blkres can't fail From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229843941.1338752.15359927679279017373.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: cc3c92e7e79eb5f7f3ec4d5790ade384b7d294f7 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" Signed-off-by: Chandan Babu R --- libxfs/xfs_bmap.c | 16 +++++----------- libxfs/xfs_bmap.h | 2 +- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index e6d700138..4a365f1a1 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -4922,7 +4922,7 @@ xfs_bmap_split_indlen( *indlen2 = len2; } -int +void xfs_bmap_del_extent_delay( struct xfs_inode *ip, int whichfork, @@ -4938,7 +4938,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); @@ -4958,9 +4957,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) @@ -5058,7 +5055,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 @@ -5616,18 +5612,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/libxfs/xfs_bmap.h b/libxfs/xfs_bmap.h index e98849eb9..667b0c2b3 100644 --- a/libxfs/xfs_bmap.h +++ b/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, From patchwork Tue Jul 30 00:51:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746030 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D71D94A3F for ; Tue, 30 Jul 2024 00:51:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300701; cv=none; b=RRjCYbSXQ6avqBB3v5fwLzsywBlGwLoEis0DOnucwV4DfgppiE8K20o9kigWZ+8QQm10BHFYmMwKovQNgcHcVruYvtatT7giuW0rbSHnwTwTUz4jtAf26pK0ZzQndTTrS0QgqRl0LHH1Qcr0g5KuO0SvJNteMtQBXiWOa8HQJBc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300701; c=relaxed/simple; bh=eX40Xj6Z9lqAwGs+xmLAsbhzstvYaDDUyP9nzHwmA1M=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ghShVJjEknGqRXmDW/bNEy6ocMB9LLselZ6N0ZR2zVOuwOqiCssRLkJxdJARJmDE7PH0cVTDcqNtbl/EEkMU+mkrDq1/xh6w06RHgEghoaQq2cBJzg8Gr0aFyBQSpX5IqzVexF4ZmWXKCIPESEDyBlr72GwSqiR0qfIyBztqArU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lTfhxkfN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lTfhxkfN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4AD0C32786; Tue, 30 Jul 2024 00:51:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300701; bh=eX40Xj6Z9lqAwGs+xmLAsbhzstvYaDDUyP9nzHwmA1M=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=lTfhxkfNKy5SJBM8Vam6PR6Me4Z6guuthTBAHEnDvXEXdgo9jjvxs1V2gBGI53pZW tgT1PuY+SHTMD+L8kAgVmPgzdgDECsikciYqlEbyp+vlCJD7ADQa2FWbsKtHPJrnPP py4KnUT8kmPnvpg3fc9aGFRJrdfK6mLrZKKM/9kJ6MndwSsT0hhbooErc0qnF5M7++ UIgW0NU9le0n5wzRGBnN+FuESjiwtjXKhOFx2KQdzk154UOXe8s+Sm0HtAJ+JCFD7O sGhpcIsEEtuKkgAOewyTZJ433r+xoFiheGJvtfyfOxSuMg2VBWKcxQHGTdGPZKSHCB dRQlW+RQo6jCw== Date: Mon, 29 Jul 2024 17:51:41 -0700 Subject: [PATCH 107/115] xfs: simplify iext overflow checking and upgrade From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Dave Chinner , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229843954.1338752.423549545566881943.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Source kernel commit: 25576c5420e61dea4c2b52942460f2221b8e46e8 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" Reviewed-by: Dave Chinner Signed-off-by: Chandan Babu R --- libxfs/xfs_attr.c | 5 +--- libxfs/xfs_bmap.c | 5 +--- libxfs/xfs_inode_fork.c | 63 +++++++++++++++++++++-------------------------- libxfs/xfs_inode_fork.h | 6 +--- 4 files changed, 32 insertions(+), 47 deletions(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 99648d78c..9d32aa406 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -1049,11 +1049,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_extend(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/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 4a365f1a1..347b44423 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -4645,11 +4645,8 @@ xfs_bmapi_convert_one_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_extend(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/libxfs/xfs_inode_fork.c b/libxfs/xfs_inode_fork.c index d9f0a21ac..cd5e2e729 100644 --- a/libxfs/xfs_inode_fork.c +++ b/libxfs/xfs_inode_fork.c @@ -763,53 +763,46 @@ xfs_ifork_verify_local_attr( return 0; } -int -xfs_iext_count_may_overflow( - struct xfs_inode *ip, - int whichfork, - int nr_to_add) -{ - struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); - uint64_t max_exts; - uint64_t nr_exts; - - 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; - - nr_exts = ifp->if_nextents + nr_to_add; - if (nr_exts < ifp->if_nextents || nr_exts > max_exts) - 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. + * 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_upgrade( +xfs_iext_count_extend( struct xfs_trans *tp, struct xfs_inode *ip, + int whichfork, 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 nr_exts; + 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 (whichfork == XFS_COW_FORK) + return 0; + + /* no point in upgrading if if_nextents overflows */ + nr_exts = ifp->if_nextents + nr_to_add; + if (nr_exts < ifp->if_nextents) return -EFBIG; - ip->i_diflags2 |= XFS_DIFLAG2_NREXT64; - xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); + if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_REDUCE_MAX_IEXTENTS) && + nr_exts > 10) + return -EFBIG; + 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/libxfs/xfs_inode_fork.h b/libxfs/xfs_inode_fork.h index bd53eb951..2373d12fd 100644 --- a/libxfs/xfs_inode_fork.h +++ b/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_extend(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. */ From patchwork Tue Jul 30 00:51:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746031 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8A546646 for ; Tue, 30 Jul 2024 00:51:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300717; cv=none; b=ovHjpZzrZJ5Pc6hvWIoSlDgpHrtCPO6aWvBEl+VnY6YOCn4ZJPsSR+xwQdblrcjqt1m/57Eu9tq2u34Qjcu3DPo+gzJ0FSh85fr992T3lOzpDlBkvJOz1NFs7tYEPD46lvQg9m1RR9Y1WyW9pU8y13nhUZH4YXKte+86gnbiNcw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300717; c=relaxed/simple; bh=O+7b27+HrjFX1+2EeFesgf6R2DojOfupQIa3yBZC1tI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jr8YjJHjDWtKHfPRp4y5FJjHJL2BHiF0sVAgIu26DRAtHHP0/SnzDBCfLwnaAaLWZhjkZqd+/E0+srOja592UmKdyzv1Q2qJQs474aHglsIGujHHUNmFxj4+fP76Xi0OMeMzkDYuzlmT3dF1DsrfdrKYLkgbZzXx02/LTs145Fw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KL2gYcil; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KL2gYcil" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F630C32786; Tue, 30 Jul 2024 00:51:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300717; bh=O+7b27+HrjFX1+2EeFesgf6R2DojOfupQIa3yBZC1tI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=KL2gYcilO1XpFdKw0vrLBpkpAKkZX5j6aDFYKFBCOp3braejYMLpI58FhUkvS4J/t DfoemNPD2c2ze3D9Am91gChLIiEcMRUxONAudRlCXGnEZ+e9Tfjd8yJUZhtdY+gWzQ NiEQapEXxWwnCxVp1FtUBb2EW9aqTj+gslor8jhMX2obx23KTnZPCRCzA4lpRbpXv4 GG/NgGtgtWuAsH18T8PxJah0hW6QcOxMoeIjLV8WIpHxHDVlYTMWHT7HNsJyiWoqLl TFa4XPApj3epuFsW1GPdKX+3NTYa4hrY384Jv0uYvlLjaASE6EAfIBzWf3fduzrmKt 7nekj1IffFndg== Date: Mon, 29 Jul 2024 17:51:56 -0700 Subject: [PATCH 108/115] xfs: Stop using __maybe_unused in xfs_alloc.c From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Dave Chinner , John Garry , Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229843967.1338752.9487755586572190314.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: John Garry Source kernel commit: b33874fb7f28326380562f208d948bab785fbd6f In both xfs_alloc_cur_finish() and xfs_alloc_ag_vextent_exact(), local variable @afg is tagged as __maybe_unused. Otherwise an unused variable warning would be generated for when building with W=1 and CONFIG_XFS_DEBUG unset. In both cases, the variable is unused as it is only referenced in an ASSERT() call, which is compiled out (in this config). It is generally a poor programming style to use __maybe_unused for variables. The ASSERT() call is to verify that agbno of the end of the extent is within bounds for both functions. @afg is used as an intermediate variable to find the AG length. However xfs_verify_agbext() already exists to verify a valid extent range. The arguments for calling xfs_verify_agbext() are already available, so use that instead. An advantage of using xfs_verify_agbext() is that it verifies that both the start and the end of the extent are within the bounds of the AG and catches overflows. Suggested-by: Dave Chinner Signed-off-by: John Garry Reviewed-by: Christoph Hellwig Signed-off-by: Chandan Babu R --- libxfs/xfs_alloc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index b86f788f4..45feff034 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -1004,13 +1004,12 @@ xfs_alloc_cur_finish( struct xfs_alloc_arg *args, struct xfs_alloc_cur *acur) { - struct xfs_agf __maybe_unused *agf = args->agbp->b_addr; int error; ASSERT(acur->cnt && acur->bnolt); ASSERT(acur->bno >= acur->rec_bno); ASSERT(acur->bno + acur->len <= acur->rec_bno + acur->rec_len); - ASSERT(acur->rec_bno + acur->rec_len <= be32_to_cpu(agf->agf_length)); + ASSERT(xfs_verify_agbext(args->pag, acur->rec_bno, acur->rec_len)); error = xfs_alloc_fixup_trees(acur->cnt, acur->bnolt, acur->rec_bno, acur->rec_len, acur->bno, acur->len, 0); @@ -1213,7 +1212,6 @@ STATIC int /* error */ xfs_alloc_ag_vextent_exact( xfs_alloc_arg_t *args) /* allocation argument structure */ { - struct xfs_agf __maybe_unused *agf = args->agbp->b_addr; struct xfs_btree_cur *bno_cur;/* by block-number btree cursor */ struct xfs_btree_cur *cnt_cur;/* by count btree cursor */ int error; @@ -1293,7 +1291,7 @@ xfs_alloc_ag_vextent_exact( */ cnt_cur = xfs_cntbt_init_cursor(args->mp, args->tp, args->agbp, args->pag); - ASSERT(args->agbno + args->len <= be32_to_cpu(agf->agf_length)); + ASSERT(xfs_verify_agbext(args->pag, args->agbno, args->len)); error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen, args->agbno, args->len, XFSA_FIXUP_BNO_OK); if (error) { From patchwork Tue Jul 30 00:52:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746032 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7CFFA646 for ; Tue, 30 Jul 2024 00:52:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300733; cv=none; b=s29ZYncTxkHpeQN9UgyoNjkRTJ1BLZGGilLY5rWkzV5eERWJ+9O21uGS9RF5vGzB35oWt3zOXqlM0wzG8qr/wCGXjkmJ9o+Aw4tB26hKSgh3j2U7lXKoxve6KgnCDrHOm9DFJKNl6i43bq2qQMvLAIpYlIqzWBzP4+z9BPiaekg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300733; c=relaxed/simple; bh=ohlMZfvdHJey55ioF1WVvAiATIu6j7EM7niIk6eBSWk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jDxaBObb/UixKN+rI2JIW3KB+QAxXkA8wOZP7eC8sF5uTJJAJvz28QDQB2k7dYF3Aj+5lx4ftYvfE1rej77SUaDy13nB3ATlPmTd0jvNd70E65isnpRIf954nHb1DQp/mbRbpC79gB5Q2uxJvkbHzy/zMk5ggUSLsmXsmXsPL0g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DIVp5woe; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DIVp5woe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05C58C32786; Tue, 30 Jul 2024 00:52:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300733; bh=ohlMZfvdHJey55ioF1WVvAiATIu6j7EM7niIk6eBSWk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=DIVp5woe7/BY8UWAwE2+CHRyFwdFWUwx85iY0EeRdPqH+zTpT42bhTBINEPpc17RS D+ANU2ELN9J+dTay4gUCXqnaR/N7M9r96jD3kwq2aihvW4r+ya2J+lqxAkT9crugJw 1AOyA15/qYcoX1sahMsFinXm1jRoeG62yU3WU6TgG+ad4MSRNPHu57qXmUb5d/w2pF 792IAasbD2E+VFipiEH77TAjzfU593S3fhq38k3YhJcaQBmT2a1acF6F9cLVP9+tTv GEU1ih+dNILlx9tJhZocdWbq2ypnBhWsdQndQEBUz6+k1jJcms4SABVADe3TPRfAET 2rg+p8hnm3ltg== Date: Mon, 29 Jul 2024 17:52:12 -0700 Subject: [PATCH 109/115] xfs: fix xfs_init_attr_trans not handling explicit operation codes From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843979.1338752.1174570151097838124.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 06c37c719d22339ad09b93735923e9b1a9794871 When we were converting the attr code to use an explicit operation code instead of keying off of attr->value being null, we forgot to change the code that initializes the transaction reservation. Split the function into two helpers that handle the !remove and remove cases, then fix both callsites to handle this correctly. Fixes: c27411d4c640 ("xfs: make attr removal an explicit operation") Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr.c | 38 ++++++++++++++++++-------------------- libxfs/xfs_attr.h | 3 +-- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 9d32aa406..9e1cce577 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -328,26 +328,20 @@ xfs_attr_calc_size( return nblks; } -/* Initialize transaction reservation for attr operations */ -void -xfs_init_attr_trans( - struct xfs_da_args *args, - struct xfs_trans_res *tres, - unsigned int *total) +/* Initialize transaction reservation for an xattr set/replace/upsert */ +inline struct xfs_trans_res +xfs_attr_set_resv( + const struct xfs_da_args *args) { - struct xfs_mount *mp = args->dp->i_mount; + struct xfs_mount *mp = args->dp->i_mount; + struct xfs_trans_res ret = { + .tr_logres = M_RES(mp)->tr_attrsetm.tr_logres + + M_RES(mp)->tr_attrsetrt.tr_logres * args->total, + .tr_logcount = XFS_ATTRSET_LOG_COUNT, + .tr_logflags = XFS_TRANS_PERM_LOG_RES, + }; - if (args->value) { - tres->tr_logres = M_RES(mp)->tr_attrsetm.tr_logres + - M_RES(mp)->tr_attrsetrt.tr_logres * - args->total; - tres->tr_logcount = XFS_ATTRSET_LOG_COUNT; - tres->tr_logflags = XFS_TRANS_PERM_LOG_RES; - *total = args->total; - } else { - *tres = M_RES(mp)->tr_attrrm; - *total = XFS_ATTRRM_SPACE_RES(mp); - } + return ret; } /* @@ -1005,7 +999,7 @@ xfs_attr_set( struct xfs_trans_res tres; int error, local; int rmt_blks = 0; - unsigned int total; + unsigned int total = 0; ASSERT(!args->trans); @@ -1032,10 +1026,15 @@ xfs_attr_set( if (!local) rmt_blks = xfs_attr3_rmt_blocks(mp, args->valuelen); + + tres = xfs_attr_set_resv(args); + total = args->total; break; case XFS_ATTRUPDATE_REMOVE: XFS_STATS_INC(mp, xs_attr_remove); rmt_blks = xfs_attr3_max_rmt_blocks(mp); + tres = M_RES(mp)->tr_attrrm; + total = XFS_ATTRRM_SPACE_RES(mp); break; } @@ -1043,7 +1042,6 @@ xfs_attr_set( * Root fork attributes can use reserved data blocks for this * operation if necessary */ - xfs_init_attr_trans(args, &tres, &total); error = xfs_trans_alloc_inode(dp, &tres, total, 0, rsvd, &args->trans); if (error) return error; diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h index 088cb7b30..0e51d0723 100644 --- a/libxfs/xfs_attr.h +++ b/libxfs/xfs_attr.h @@ -565,8 +565,7 @@ bool xfs_attr_check_namespace(unsigned int attr_flags); bool xfs_attr_namecheck(unsigned int attr_flags, const void *name, size_t length); int xfs_attr_calc_size(struct xfs_da_args *args, int *local); -void xfs_init_attr_trans(struct xfs_da_args *args, struct xfs_trans_res *tres, - unsigned int *total); +struct xfs_trans_res xfs_attr_set_resv(const struct xfs_da_args *args); /* * Check to see if the attr should be upgraded from non-existent or shortform to From patchwork Tue Jul 30 00:52:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746033 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D14E729AF for ; Tue, 30 Jul 2024 00:52:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300748; cv=none; b=qdfRpUOBAY2sEt/dggotOYByS5zxIyt2Q2wtAXVi3VsQXvzAHuL4xGsveoFEt5Q6wvgeAHh7FXg6lFKmkEwZt+5sYgt/nTv0SDAYIsny1wQiNLkU+UBscNM9T6fWPdwclMnFO9lcG3sMpvPt/LlJ0L5EJQ3Rw95Kmh1O6phai+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300748; c=relaxed/simple; bh=y0L45dvyS1pDxkGsSHQT37y98FI3g8Ssj/4uOHX6Ypw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EAUBV4PzWlyWgzNesDDYpOSAaQwDNJO0ZpWz0RHh2NvOc8dKhJM1DcxrmqnrSH27dpF3hV8g3c5rOztjUcCwnRbFsy6eeo2+gnhFCvTwNazhkpxoHR/oM7NvvbRcyNZZ4tpZ0uCURjF0WdIKLgu6MPtrArLYlZ1/goRZ5IwIzRI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Qv7mPJtv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Qv7mPJtv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A99D6C32786; Tue, 30 Jul 2024 00:52:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300748; bh=y0L45dvyS1pDxkGsSHQT37y98FI3g8Ssj/4uOHX6Ypw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Qv7mPJtvV1W5Ol4ScA7ydCs+yzsEX6bc31meNZnfxjVmQOJJQHxomrhr6W4YCULM6 e/w6Ccn6wRaJzvLne1rS6+o0IhkLeiTTFeOAPUKYpuEybH/WbVho71jzhk0UV0HgRv R9VhzhC0+4stvRElndI3OM0RqRpT04BZPWxH0Hjfeqb/BXyOcal42H7ojOGPf/BExp oI4WjK3yrESyGBakS3t+EbciHUAvVlyfQQTXNAkyNDdyrpugn1Ac/bvCHOZzLQSELv nXLGUf0nGR/2pACwdUlbYSxrxqKzdWsUqD1pAkhVjgmco2+gWiSQQMswaeSnLB6OXH REH2v4nGCbtzg== Date: Mon, 29 Jul 2024 17:52:28 -0700 Subject: [PATCH 110/115] xfs: allow symlinks with short remote targets From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229843992.1338752.3396951522695023516.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 6d3103369360d96f52336571138980d4c831c091 An internal user complained about log recovery failing on a symlink ("Bad dinode after recovery") with the following (excerpted) format: core.magic = 0x494e core.mode = 0120777 core.version = 3 core.format = 2 (extents) core.nlinkv2 = 1 core.nextents = 1 core.size = 297 core.nblocks = 1 core.naextents = 0 core.forkoff = 0 core.aformat = 2 (extents) u3.bmx[0] = [startoff,startblock,blockcount,extentflag] 0:[0,12,1,0] This is a symbolic link with a 297-byte target stored in a disk block, which is to say this is a symlink with a remote target. The forkoff is 0, which is to say that there's 512 - 176 == 336 bytes in the inode core to store the data fork. Eventually, testing of generic/388 failed with the same inode corruption message during inode recovery. In writing a debugging patch to call xfs_dinode_verify on dirty inode log items when we're committing transactions, I observed that xfs/298 can reproduce the problem quite quickly. xfs/298 creates a symbolic link, adds some extended attributes, then deletes them all. The test failure occurs when the final removexattr also deletes the attr fork because that does not convert the remote symlink back into a shortform symlink. That is how we trip this test. The only reason why xfs/298 only triggers with the debug patch added is that it deletes the symlink, so the final iflush shows the inode as free. I wrote a quick fstest to emulate the behavior of xfs/298, except that it leaves the symlinks on the filesystem after inducing the "corrupt" state. Kernels going back at least as far as 4.18 have written out symlink inodes in this manner and prior to 1eb70f54c445f they did not object to reading them back in. Because we've been writing out inodes this way for quite some time, the only way to fix this is to relax the check for symbolic links. Directories don't have this problem because di_size is bumped to blocksize during the sf->data conversion. Fixes: 1eb70f54c445f ("xfs: validate inode fork size against fork format") Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_inode_buf.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/libxfs/xfs_inode_buf.c b/libxfs/xfs_inode_buf.c index aee581d53..5c4e66a25 100644 --- a/libxfs/xfs_inode_buf.c +++ b/libxfs/xfs_inode_buf.c @@ -371,17 +371,37 @@ xfs_dinode_verify_fork( /* * For fork types that can contain local data, check that the fork * format matches the size of local data contained within the fork. - * - * For all types, check that when the size says the should be in extent - * or btree format, the inode isn't claiming it is in local format. */ if (whichfork == XFS_DATA_FORK) { - if (S_ISDIR(mode) || S_ISLNK(mode)) { + /* + * A directory small enough to fit in the inode must be stored + * in local format. The directory sf <-> extents conversion + * code updates the directory size accordingly. + */ + if (S_ISDIR(mode)) { if (be64_to_cpu(dip->di_size) <= fork_size && fork_format != XFS_DINODE_FMT_LOCAL) return __this_address; } + /* + * A symlink with a target small enough to fit in the inode can + * be stored in extents format if xattrs were added (thus + * converting the data fork from shortform to remote format) + * and then removed. + */ + if (S_ISLNK(mode)) { + if (be64_to_cpu(dip->di_size) <= fork_size && + fork_format != XFS_DINODE_FMT_EXTENTS && + fork_format != XFS_DINODE_FMT_LOCAL) + return __this_address; + } + + /* + * For all types, check that when the size says the fork should + * be in extent or btree format, the inode isn't claiming to be + * in local format. + */ if (be64_to_cpu(dip->di_size) > fork_size && fork_format == XFS_DINODE_FMT_LOCAL) return __this_address; From patchwork Tue Jul 30 00:52:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746034 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 765A333D5 for ; Tue, 30 Jul 2024 00:52:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300764; cv=none; b=nWtRrqpZwmRDsNTzKrega9/O0csFgMa3XbKyNRg5tWsjBcrRYOtxDh9/4b/73+yeGr1ESXcLQKqvnqBccWXEFCIf0z3IHvWo6vGk69I1OxhXKmhGfGenT+U+SY1srEttAb2ZCJ3S8EID+413/t1S07mXWxhGC5PF5tZK+hXhvys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300764; c=relaxed/simple; bh=breDAnflR6HQIVbLDaUPIDL47Fl2Jo3qty8Gqo6yiuE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RYs6Jst4VHldk9r9YG/JEsRX+acMM1tACKMQBHSKqppKmsa3MkMW11yJx9k7fFjsPaYp2wICK9tS0O2ua1ZKA9qkUAvE7fjRIFQ/hBTsnXHyKtwumgsVn2w9L0pxzp6lDIpg79y+irGcOtcC+gYKW/RHYRUzdCjopGeybJ5jzkM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aMsSRiYJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aMsSRiYJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F70DC32786; Tue, 30 Jul 2024 00:52:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300764; bh=breDAnflR6HQIVbLDaUPIDL47Fl2Jo3qty8Gqo6yiuE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=aMsSRiYJUmg+O+ggdXikisMTU0aJlNYAJcfCKYKZchKrQtYzQvsQa1zfGsnl5XgCR NJ89EvkhmdY+wOTFxFV9kGWvXFGeOEAgD8W3VsSEXnuCO6B/8zQ+kei3dses6QYuEn aWdOr7FUdmo3ubrdJLWA5GmRvcPTo/z5ke/grOicAD+RmD9YwsO9pzImJjPlMzarys 8PUdqLAxJma1xnuvBNQzqgp9dK7bE1xx+RLmr1h5+rPFuXFp+ZouXvLzRspjepfChn GqjR5h0hcB/uVar0cyZPl9skifE8EiKE9cBRo7sbe1fUr23sbatgIOrLn3bKjlWzAg VhYAD9ORvEUwg== Date: Mon, 29 Jul 2024 17:52:43 -0700 Subject: [PATCH 111/115] xfs: Add cond_resched to block unmap range and reflink remap path From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Ojaswin Mujoo , "Ritesh Harjani (IBM)" , Disha Goel , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229844004.1338752.17870968518710908441.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Ritesh Harjani (IBM) Source kernel commit: b0c6bcd58d44b1b843d1b7218db5a1efe917d27e An async dio write to a sparse file can generate a lot of extents and when we unlink this file (using rm), the kernel can be busy in umapping and freeing those extents as part of transaction processing. Similarly xfs reflink remapping path can also iterate over a million extent entries in xfs_reflink_remap_blocks(). Since we can busy loop in these two functions, so let's add cond_resched() to avoid softlockup messages like these. watchdog: BUG: soft lockup - CPU#1 stuck for 22s! [kworker/1:0:82435] CPU: 1 PID: 82435 Comm: kworker/1:0 Tainted: G S L 6.9.0-rc5-0-default #1 Workqueue: xfs-inodegc/sda2 xfs_inodegc_worker NIP [c000000000beea10] xfs_extent_busy_trim+0x100/0x290 LR [c000000000bee958] xfs_extent_busy_trim+0x48/0x290 Call Trace: xfs_alloc_get_rec+0x54/0x1b0 (unreliable) xfs_alloc_compute_aligned+0x5c/0x144 xfs_alloc_ag_vextent_size+0x238/0x8d4 xfs_alloc_fix_freelist+0x540/0x694 xfs_free_extent_fix_freelist+0x84/0xe0 __xfs_free_extent+0x74/0x1ec xfs_extent_free_finish_item+0xcc/0x214 xfs_defer_finish_one+0x194/0x388 xfs_defer_finish_noroll+0x1b4/0x5c8 xfs_defer_finish+0x2c/0xc4 xfs_bunmapi_range+0xa4/0x100 xfs_itruncate_extents_flags+0x1b8/0x2f4 xfs_inactive_truncate+0xe0/0x124 xfs_inactive+0x30c/0x3e0 xfs_inodegc_worker+0x140/0x234 process_scheduled_works+0x240/0x57c worker_thread+0x198/0x468 kthread+0x138/0x140 start_kernel_thread+0x14/0x18 run fstests generic/175 at 2024-02-02 04:40:21 [ C17] watchdog: BUG: soft lockup - CPU#17 stuck for 23s! [xfs_io:7679] watchdog: BUG: soft lockup - CPU#17 stuck for 23s! [xfs_io:7679] CPU: 17 PID: 7679 Comm: xfs_io Kdump: loaded Tainted: G X 6.4.0 NIP [c008000005e3ec94] xfs_rmapbt_diff_two_keys+0x54/0xe0 [xfs] LR [c008000005e08798] xfs_btree_get_leaf_keys+0x110/0x1e0 [xfs] Call Trace: 0xc000000014107c00 (unreliable) __xfs_btree_updkeys+0x8c/0x2c0 [xfs] xfs_btree_update_keys+0x150/0x170 [xfs] xfs_btree_lshift+0x534/0x660 [xfs] xfs_btree_make_block_unfull+0x19c/0x240 [xfs] xfs_btree_insrec+0x4e4/0x630 [xfs] xfs_btree_insert+0x104/0x2d0 [xfs] xfs_rmap_insert+0xc4/0x260 [xfs] xfs_rmap_map_shared+0x228/0x630 [xfs] xfs_rmap_finish_one+0x2d4/0x350 [xfs] xfs_rmap_update_finish_item+0x44/0xc0 [xfs] xfs_defer_finish_noroll+0x2e4/0x740 [xfs] __xfs_trans_commit+0x1f4/0x400 [xfs] xfs_reflink_remap_extent+0x2d8/0x650 [xfs] xfs_reflink_remap_blocks+0x154/0x320 [xfs] xfs_file_remap_range+0x138/0x3a0 [xfs] do_clone_file_range+0x11c/0x2f0 vfs_clone_file_range+0x60/0x1c0 ioctl_file_clone+0x78/0x140 sys_ioctl+0x934/0x1270 system_call_exception+0x158/0x320 system_call_vectored_common+0x15c/0x2ec Cc: Ojaswin Mujoo Signed-off-by: Ritesh Harjani (IBM) Reviewed-by: Darrick J. Wong Tested-by: Disha Goel Signed-off-by: Chandan Babu R --- libxfs/libxfs_priv.h | 2 ++ libxfs/xfs_bmap.c | 1 + 2 files changed, 3 insertions(+) diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 90b2db091..64bc10e10 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -639,4 +639,6 @@ int xfs_bmap_last_extent(struct xfs_trans *tp, struct xfs_inode *ip, */ #define lower_32_bits(n) ((uint32_t)((n) & 0xffffffff)) +#define cond_resched() ((void)0) + #endif /* __LIBXFS_INTERNAL_XFS_H__ */ diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 347b44423..a0dda4640 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -6377,6 +6377,7 @@ xfs_bunmapi_range( error = xfs_defer_finish(tpp); if (error) goto out; + cond_resched(); } out: return error; From patchwork Tue Jul 30 00:52:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746035 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2C1CB63D for ; Tue, 30 Jul 2024 00:53:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300780; cv=none; b=i+SkD/u8GFXJeGbdRQOEDgIdk7ElhgE17evfQtuRdqIaIZDb96rAQvY4Q04QecQCl8b1TOR6Br04FsHDGgjF3o/h+KLZDJJHxqsrNNSsn4+OAvZOcDScadudpP2o2179Ehv44jee3+eCvOcEL0u4TSxMy7hncIfHd1n+J1jnvlQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300780; c=relaxed/simple; bh=YB6LGPg4laErKm6ba8BGrHDa+oP290ymgPN08DXflNw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fHFgolD1FVtZQ5W5sxtGDNfG8n8dqtCyhsJEn2sBlaIx8K+lyKDW6jz0/GklLh9+jeclJGTImkVvsmNipbXbjq4Yi8WGurVAk8pIe2EuRM93GDYzOymkIC7rjbviOYyDH1vr9iXDnqQVDixwiQKZKiw1YDIQHbPkYQWNzkwnExM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lOJUeI04; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lOJUeI04" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 030C4C32786; Tue, 30 Jul 2024 00:52:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300780; bh=YB6LGPg4laErKm6ba8BGrHDa+oP290ymgPN08DXflNw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=lOJUeI048hJBtWpoewFecTC+3yBrjABhpeBfa+8P7FUBD1fpyHfPcCLfOdxIyrEQ7 rAADQ/tHWu+oAo6LAkPVTjAEVdtVBaLQVx/0CK7eYXnjenWSu08hA2egjeL/nmZk3b ApKyQbDwO7r1Ll+MM8HXGJ9IZUekyNoMdTNSAMhNLUI8TUVAew+z9B8tQbc46VJ+ET YMwZds7Xo4xxrKSqdqPuJhY8guEq9ITe03+GzUV+wpZjcJmcfpEGfusudlRG/A5NRU Y9GzkYf0YbRz8rF1puGJlQbp3VWXtAw1pig/65hwGrqVrkPv74ps2fE1MD+npqpEDZ zSvPCTFNYi94g== Date: Mon, 29 Jul 2024 17:52:59 -0700 Subject: [PATCH 112/115] xfs: make sure sb_fdblocks is non-negative From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Wengang Wang , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229844017.1338752.2042405284909950974.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Wengang Wang Source kernel commit: 58f880711f2ba53fd5e959875aff5b3bf6d5c32e A user with a completely full filesystem experienced an unexpected shutdown when the filesystem tried to write the superblock during runtime. kernel shows the following dmesg: [ 8.176281] XFS (dm-4): Metadata corruption detected at xfs_sb_write_verify+0x60/0x120 [xfs], xfs_sb block 0x0 [ 8.177417] XFS (dm-4): Unmount and run xfs_repair [ 8.178016] XFS (dm-4): First 128 bytes of corrupted metadata buffer: [ 8.178703] 00000000: 58 46 53 42 00 00 10 00 00 00 00 00 01 90 00 00 XFSB............ [ 8.179487] 00000010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ [ 8.180312] 00000020: cf 12 dc 89 ca 26 45 29 92 e6 e3 8d 3b b8 a2 c3 .....&E)....;... [ 8.181150] 00000030: 00 00 00 00 01 00 00 06 00 00 00 00 00 00 00 80 ................ [ 8.182003] 00000040: 00 00 00 00 00 00 00 81 00 00 00 00 00 00 00 82 ................ [ 8.182004] 00000050: 00 00 00 01 00 64 00 00 00 00 00 04 00 00 00 00 .....d.......... [ 8.182004] 00000060: 00 00 64 00 b4 a5 02 00 02 00 00 08 00 00 00 00 ..d............. [ 8.182005] 00000070: 00 00 00 00 00 00 00 00 0c 09 09 03 17 00 00 19 ................ [ 8.182008] XFS (dm-4): Corruption of in-memory data detected. Shutting down filesystem [ 8.182010] XFS (dm-4): Please unmount the filesystem and rectify the problem(s) When xfs_log_sb writes super block to disk, b_fdblocks is fetched from m_fdblocks without any lock. As m_fdblocks can experience a positive -> negative -> positive changing when the FS reaches fullness (see xfs_mod_fdblocks). So there is a chance that sb_fdblocks is negative, and because sb_fdblocks is type of unsigned long long, it reads super big. And sb_fdblocks being bigger than sb_dblocks is a problem during log recovery, xfs_validate_sb_write() complains. Fix: As sb_fdblocks will be re-calculated during mount when lazysbcount is enabled, We just need to make xfs_validate_sb_write() happy -- make sure sb_fdblocks is not nenative. This patch also takes care of other percpu counters in xfs_log_sb. Signed-off-by: Wengang Wang Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R --- libxfs/libxfs_priv.h | 2 +- libxfs/xfs_sb.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 64bc10e10..5d1aa23c7 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -210,7 +210,7 @@ static inline bool WARN_ON(bool expr) { #define WARN_ON_ONCE(e) WARN_ON(e) #define percpu_counter_read(x) (*x) #define percpu_counter_read_positive(x) ((*x) > 0 ? (*x) : 0) -#define percpu_counter_sum(x) (*x) +#define percpu_counter_sum_positive(x) ((*x) > 0 ? (*x) : 0) /* * get_random_u32 is used for di_gen inode allocation, it must be zero for diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index f45ffd994..bedb36a06 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -1035,11 +1035,12 @@ xfs_log_sb( * and hence we don't need have to update it here. */ if (xfs_has_lazysbcount(mp)) { - mp->m_sb.sb_icount = percpu_counter_sum(&mp->m_icount); + mp->m_sb.sb_icount = percpu_counter_sum_positive(&mp->m_icount); mp->m_sb.sb_ifree = min_t(uint64_t, - percpu_counter_sum(&mp->m_ifree), + percpu_counter_sum_positive(&mp->m_ifree), mp->m_sb.sb_icount); - mp->m_sb.sb_fdblocks = percpu_counter_sum(&mp->m_fdblocks); + mp->m_sb.sb_fdblocks = + percpu_counter_sum_positive(&mp->m_fdblocks); } xfs_sb_to_disk(bp->b_addr, &mp->m_sb); From patchwork Tue Jul 30 00:53:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746036 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D797F646 for ; Tue, 30 Jul 2024 00:53:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300795; cv=none; b=Y+5dpFGlTO67u5zDgg1nP7kMe7u/gryQtPrTt+4OEWmCxdapdgBqcqV7xRbeDmCCrmqLfve0QpMYGb+ktB2sSVee1/xgyFLmNHQ1YhjNylmm9/Vt+VyjOSssWGxeXJaMvqUndOhThrKP97xMerx8QXR2OuhabqWxn9CUnthdlQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300795; c=relaxed/simple; bh=P8t9oW+470k2RMY1bYf/1w4HnT17gFkiTGuLONp3M4A=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uLixYSzTt4nP8/eCFv6KpEC7JPxfd9Mehy079H1suhRjf4Ken7ATBv+6wu4fpl62VeWSIetMaZP4Xwlaw5I97jwuoxfmHsvGjFXIHIfwS/A7hJdfeqDRiQPrGToDw5RTjYITTmBp2Y+nWxvu85o/ybh4LHKRf26qys1P0YW2tcw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MxL6U9lO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MxL6U9lO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE0B6C32786; Tue, 30 Jul 2024 00:53:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300795; bh=P8t9oW+470k2RMY1bYf/1w4HnT17gFkiTGuLONp3M4A=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=MxL6U9lOZGGBbKm41YpuFomQnHTZ9wXWbgOfm2orCqqAcrEl+//4iQQqJ9F5A3u9d kcFzbrR6xnpvFbYmrB4W+Z+/zvMHE5u75KXQYYfvvSDsrtWlWm/tcpe7jTKGJw0Eii faQk7avhRx/LP/+FMX7b9HaDioDoG435mID85VERg/57iclYnQuFkrNNCGLXJvoht4 RVJx+osCHzFlpC1wx+7gPZU6rxEPYCgskTZoW4QgZJ8hu09Hs9gcqqXyLnq0+kOXTq 21Hq+fmCnnbFOL7FSdSIlw9mumGThBYjp+kEl3MhCkEUxK/ELyi0vH6IN/LIDl15+V EjLCeiTRJjkng== Date: Mon, 29 Jul 2024 17:53:15 -0700 Subject: [PATCH 113/115] xfs: restrict when we try to align cow fork delalloc to cowextsz hints From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229844030.1338752.4439274179388747119.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 288e1f693f04e66be99f27e7cbe4a45936a66745 xfs/205 produces the following failure when always_cow is enabled: This is the result of overly aggressive attempts to align cow fork delalloc reservations to the CoW extent size hint. Looking at the trace data, we're trying to append a single fsblock to the "fred" file. Trying to create a speculative post-eof reservation fails because there's not enough space. We then set @prealloc_blocks to zero and try again, but the cowextsz alignment code triggers, which expands our request for a 1-fsblock reservation into a 39-block reservation. There's not enough space for that, so the whole write fails with ENOSPC even though there's sufficient space in the filesystem to allocate the single block that we need to land the write. There are two things wrong here -- first, we shouldn't be attempting speculative preallocations beyond what was requested when we're low on space. Second, if we've already computed a posteof preallocation, we shouldn't bother trying to align that to the cowextsize hint. Fix both of these problems by adding a flag that only enables the expansion of the delalloc reservation to the cowextsize if we're doing a non-extending write, and only if we're not doing an ENOSPC retry. This requires us to move the ENOSPC retry logic to xfs_bmapi_reserve_delalloc. I probably should have caught this six years ago when 6ca30729c206d was being reviewed, but oh well. Update the comments to reflect what the code does now. Fixes: 6ca30729c206d ("xfs: bmap code cleanup") Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Chandan Babu R --- include/xfs_trace.h | 1 + libxfs/xfs_bmap.c | 31 +++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/include/xfs_trace.h b/include/xfs_trace.h index 2e5e89d65..fe0854b20 100644 --- a/include/xfs_trace.h +++ b/include/xfs_trace.h @@ -68,6 +68,7 @@ #define trace_xfs_log_recover_item_add(a,b,c,d) ((void) 0) #define trace_xfs_da_btree_corrupt(a,b) ((void) 0) +#define trace_xfs_delalloc_enospc(...) ((void) 0) #define trace_xfs_btree_corrupt(a,b) ((void) 0) #define trace_xfs_btree_updkeys(a,b,c) ((void) 0) #define trace_xfs_btree_overlapped_query_range(a,b,c) ((void) 0) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index a0dda4640..e60d11470 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -4052,20 +4052,32 @@ xfs_bmapi_reserve_delalloc( xfs_extlen_t indlen; uint64_t fdblocks; int error; - xfs_fileoff_t aoff = off; + xfs_fileoff_t aoff; + bool use_cowextszhint = + whichfork == XFS_COW_FORK && !prealloc; +retry: /* * Cap the alloc length. Keep track of prealloc so we know whether to * tag the inode before we return. */ + aoff = off; alen = XFS_FILBLKS_MIN(len + prealloc, XFS_MAX_BMBT_EXTLEN); if (!eof) alen = XFS_FILBLKS_MIN(alen, got->br_startoff - aoff); if (prealloc && alen >= len) prealloc = alen - len; - /* Figure out the extent size, adjust alen */ - if (whichfork == XFS_COW_FORK) { + /* + * If we're targetting the COW fork but aren't creating a speculative + * posteof preallocation, try to expand the reservation to align with + * the COW extent size hint if there's sufficient free space. + * + * Unlike the data fork, the CoW cancellation functions will free all + * the reservations at inactivation, so we don't require that every + * delalloc reservation have a dirty pagecache. + */ + if (use_cowextszhint) { struct xfs_bmbt_irec prev; xfs_extlen_t extsz = xfs_get_cowextsz_hint(ip); @@ -4084,7 +4096,7 @@ xfs_bmapi_reserve_delalloc( */ error = xfs_quota_reserve_blkres(ip, alen); if (error) - return error; + goto out; /* * Split changing sb for alen and indlen since they could be coming @@ -4134,6 +4146,17 @@ xfs_bmapi_reserve_delalloc( out_unreserve_quota: if (XFS_IS_QUOTA_ON(mp)) xfs_quota_unreserve_blkres(ip, alen); +out: + if (error == -ENOSPC || error == -EDQUOT) { + trace_xfs_delalloc_enospc(ip, off, len); + + if (prealloc || use_cowextszhint) { + /* retry without any preallocation */ + use_cowextszhint = false; + prealloc = 0; + goto retry; + } + } return error; } From patchwork Tue Jul 30 00:53:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746037 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 837082563 for ; Tue, 30 Jul 2024 00:53:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300811; cv=none; b=JWQ05YN9nVepjoqRIeITExe5zjL5uvr9wFjfP0Yaj1FIZ9cvsImryRH+zCOMSKBwFtiL+bVeKIXOPZNZDF9cZvVm3IxZ9qwqFb3MxpJBRhbs6vo3H0KaCDgzvzXxWxxE4rEWNoK74qLHH8J0dsQo6zPS1Hc/QeU4c3NUdGBHbvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300811; c=relaxed/simple; bh=yCNbpqZYC4Y5sQix+p9Zpx6CnZT5QE80CxHom56av+k=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Cz9cPtJ36oijAWauroAaqwbH81ggzoJBN1XziG5V5vvvd6IvlC56tDAEcCe66JMscSMGSAdd9ktEVB9M92Wax7733NzdfmK4TBSBWDS0lMnsmG5JA8y2BS8wa/ac6onB3EKK50ItksQhN1Ud4e8cPwSh8/vd+e3gvBG2SxmRw5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lOw90Qyz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lOw90Qyz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54D70C32786; Tue, 30 Jul 2024 00:53:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300811; bh=yCNbpqZYC4Y5sQix+p9Zpx6CnZT5QE80CxHom56av+k=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=lOw90QyzrjkOUgjvVQsEAJDq3WveCS0reXX7bOy+GLWhPKiLdK1NiFYl081eptLPU tdadkByU/KuGD42cnO9zz75YaSs7+bcvaGdWrq5mp2RF5vg0GWoMkU/f58QZMmTPuI 8s0fIlQQorOl7UxK5bv3YziLZiuS2fmTSL+3WLAhmsqezJPNM3y0EaLKQ9e4A3T0YA VQr+nbWS4J/kwRMwma8/0oMJG3rMELw951IDf8/6sV++t/Pk4XTc/s0ffViGK6/1Bz tuKf2b6DbumYv2bOZGzVUbWdXmLO1+PwFNSjOEsfsmaTp7PgWDu4R3aiinBL/en4DK fNnXglK9+EvYg== Date: Mon, 29 Jul 2024 17:53:30 -0700 Subject: [PATCH 114/115] xfs: allow unlinked symlinks and dirs with zero size From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229844043.1338752.16084080686221125367.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: 1ec9307fc066dd8a140d5430f8a7576aa9d78cd3 For a very very long time, inode inactivation has set the inode size to zero before unmapping the extents associated with the data fork. Unfortunately, commit 3c6f46eacd876 changed the inode verifier to prohibit zero-length symlinks and directories. If an inode happens to get logged in this state and the system crashes before freeing the inode, log recovery will also fail on the broken inode. Therefore, allow zero-size symlinks and directories as long as the link count is zero; nobody will be able to open these files by handle so there isn't any risk of data exposure. Fixes: 3c6f46eacd876 ("xfs: sanity check directory inode di_size") Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Chandan Babu R --- libxfs/xfs_inode_buf.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/libxfs/xfs_inode_buf.c b/libxfs/xfs_inode_buf.c index 5c4e66a25..856659cc3 100644 --- a/libxfs/xfs_inode_buf.c +++ b/libxfs/xfs_inode_buf.c @@ -376,10 +376,13 @@ xfs_dinode_verify_fork( /* * A directory small enough to fit in the inode must be stored * in local format. The directory sf <-> extents conversion - * code updates the directory size accordingly. + * code updates the directory size accordingly. Directories + * being truncated have zero size and are not subject to this + * check. */ if (S_ISDIR(mode)) { - if (be64_to_cpu(dip->di_size) <= fork_size && + if (dip->di_size && + be64_to_cpu(dip->di_size) <= fork_size && fork_format != XFS_DINODE_FMT_LOCAL) return __this_address; } @@ -525,9 +528,19 @@ xfs_dinode_verify( if (mode && xfs_mode_to_ftype(mode) == XFS_DIR3_FT_UNKNOWN) return __this_address; - /* No zero-length symlinks/dirs. */ - if ((S_ISLNK(mode) || S_ISDIR(mode)) && di_size == 0) - return __this_address; + /* + * No zero-length symlinks/dirs unless they're unlinked and hence being + * inactivated. + */ + if ((S_ISLNK(mode) || S_ISDIR(mode)) && di_size == 0) { + if (dip->di_version > 1) { + if (dip->di_nlink) + return __this_address; + } else { + if (dip->di_onlink) + return __this_address; + } + } fa = xfs_dinode_verify_nrext64(mp, dip); if (fa) From patchwork Tue Jul 30 00:53:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746038 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 666AB33D5 for ; Tue, 30 Jul 2024 00:53:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300827; cv=none; b=KaSJG2/yd+1A2JSCYsl+K3QMnItI1uBpiCPU4yAY9ACAV2bs85idCfVCWU2lZqIJzwQIsgvAc0zCuCxCL+J7wrudiHF2KT/Ltr1lh3dk00VTqszhgMKZNT7bS6sr7Tu/ipUjXKl5/w+dfUxi1Zp8pz/8zZQqXE1NhH3/7+7rVjg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722300827; c=relaxed/simple; bh=z90GpLfbvwyU2a8WZe7YRFFxaDvkyeH0QK3HQXbEQ5w=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pOASp9hQ7We1F6mjdzG+t9bqSsEPtjeW3SptZLmH8NuWnmSa071SLt++DOInt6YkD3j2qs+bBbnYXlxP4rfCL9hJQVnFmFi+jUJezpTDMCV7ON3FFc0pZd+SUsGm8DQFliYh3zqpTLy64PA4gM75hOO9zMN6uvM6rRvIMmHPIrc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FgwZ4hQ2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FgwZ4hQ2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0E2EC32786; Tue, 30 Jul 2024 00:53:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722300827; bh=z90GpLfbvwyU2a8WZe7YRFFxaDvkyeH0QK3HQXbEQ5w=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=FgwZ4hQ2VvBdVq2a80uLXkp0JAKO0Y6/BmtoZQErG3XmX/AmhW17ndtTJNL3cEtnv BxoS6ZVJvcocnvFWzpqxjJdi3gZtKQpZJd2VuRLhfbfbLz9b3LTRFrMiqoNBlgwfY3 vSE+UJYl5ws6/LCeJ1qEBbCYrTDn0Z1749LELgFKoKbfVcUzxXPti3nNrYG145SqmL PKeeS6scx78FGhvaoQ3OV0hR/9N2ok0KK/reI4Z6DiTd765a3UgmzXcwRI4BVuUYjK 0+ElzMV3EB1AzI0D5FaG4xHYef15i2w7ObCm0T8pIzt/FV7fZreanMh8Xyj1Gw88vY V76WkDPapAwdQ== Date: Mon, 29 Jul 2024 17:53:46 -0700 Subject: [PATCH 115/115] xfs: fix direction in XFS_IOC_EXCHANGE_RANGE From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <172229844055.1338752.3125976389287760838.stgit@frogsfrogsfrogs> In-Reply-To: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> References: <172229842329.1338752.683513668861748171.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Source kernel commit: dc5e1cbae270b625dcb978f8ea762eb16a93a016 The kernel reads userspace's buffer but does not write it back. Therefore this is really an _IOW ioctl. Change this before 6.10 final releases. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Chandan Babu R --- libxfs/xfs_fs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index 97996cb79..454b63ef7 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -996,7 +996,7 @@ struct xfs_getparents_by_handle { #define XFS_IOC_FSGEOMETRY _IOR ('X', 126, struct xfs_fsop_geom) #define XFS_IOC_BULKSTAT _IOR ('X', 127, struct xfs_bulkstat_req) #define XFS_IOC_INUMBERS _IOR ('X', 128, struct xfs_inumbers_req) -#define XFS_IOC_EXCHANGE_RANGE _IOWR('X', 129, struct xfs_exchange_range) +#define XFS_IOC_EXCHANGE_RANGE _IOW ('X', 129, struct xfs_exchange_range) /* XFS_IOC_GETFSUUID ---------- deprecated 140 */