From patchwork Mon Dec 23 22:12: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: 13919369 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 D555013FEE for ; Mon, 23 Dec 2024 22:12: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=1734991922; cv=none; b=cQ1Ehz4UbYyVH1UYLbd+zFJjWz1YPLg5d5u7thHHii8OwAw0UmhhjBdzIW/2qsFSW/9cyA/8tbw1PywYNbmDPpdO3b8GGl0UsAflkgnw1FtO53wR8RJAlsh5fwZbu1lu9yAQz/xenTBQthiwvS58aU433bEUzgb98lR+lgR1ID0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734991922; c=relaxed/simple; bh=Av/VOQdsA7QOQsWUD36EIwCE2gr5dwxG1IaXdqKJeqE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=egg+l71YwANrW0QJegSFFdaeM5myK7g74YEvIFDtY/5CsrJE4nDyrR6fA5sde38DIbVHM8X0wIn24Ei1xs+xzonkYDypP6UBHAjz7jyhuHQDj3lmzx3tT20qhiW/tXwOP66J70ITCyL3ay37y/ANlEZucrzy0t+rOUrYSIx5JNw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kisAoHpT; 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="kisAoHpT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5BFD9C4CED3; Mon, 23 Dec 2024 22:12:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734991922; bh=Av/VOQdsA7QOQsWUD36EIwCE2gr5dwxG1IaXdqKJeqE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=kisAoHpTw5XBXX4aUx7V0JKEoHUAe1/p0IpEGUqi87UbzpPUcI5ANL1oPbfub1CeC TSUyIXdrUKvrcu7TRYVKl5Mr+hNFc2VoUxc16kDoltxAgDF4LeN/NPtqTrKHuw8BQR mo/ZdT0XuvKFDwKZcTOW7EV6I4TwoBJE2GWMcfa62M9wQhzxntjFH4jx+HXvOYXHIM XOizyz4U9q9nhh6dMT8JgjziRBjphZII/YMuZER+FOJN75bYxndq6jOuw0OB8rjJwz E1pYNd7Ac5Mv9RMRi6BtjstLPyBosKffX2UAUyfxGyhT8TA2Bv66bRfGTR4fudl4xz 01N+69gekOHtg== Date: Mon, 23 Dec 2024 14:12:01 -0800 Subject: [PATCH 01/51] libxfs: remove XFS_ILOCK_RT* From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498943818.2297565.622589230063864691.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Now that we've centralized the realtime metadata locking routines, get rid of the ILOCK subclasses since we now use explicit lockdep classes. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- libxfs/libxfs_priv.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 1fc9c784b05054..dd24bdc2d169d9 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -180,8 +180,6 @@ 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_IOLOCK_EXCL 0 #define XFS_STATS_INC(mp, count) do { (mp) = (mp); } while (0) #define XFS_STATS_DEC(mp, count, x) do { (mp) = (mp); } while (0) From patchwork Mon Dec 23 22:12: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: 13919370 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 404E713FEE for ; Mon, 23 Dec 2024 22:12: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=1734991939; cv=none; b=FPlBsoHYRE9Hbh+eVz/7iiHR63MIoRbCEqPYGJ262pb/fQoXVGmp4qYwZSX96SgFnOO3PsiCQkaGmLC6J+k2JiE5McMwiHm5MB8oLmM8HMFJAHYph8QhZgziLzsKq1CFLj+PM8oUcBnrJVihkq+S2UzkU3I+DiFBAtrBQB76Sgo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734991939; c=relaxed/simple; bh=fS4tJ6fqtIkAj0b/gMkHxHOfnKkYBcTmQPFzmU7UrTY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DUVAj2KjdA1kMLpFbiJi37T6JWvcXj/OAiG85qffm5R/5/oTySXMXJQtWfv27XAwCqBEQS6d0FLqEqYm4Bykv15YKo800xSRQ3JOMkBAqjl3eFPOrmnJRouh8zErBMeE6vZtTjNJ/7dZkzlrgXfStUeQ47XEy8GXiLr7rBQFncY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aES+jmra; 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="aES+jmra" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB483C4CED3; Mon, 23 Dec 2024 22:12:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734991938; bh=fS4tJ6fqtIkAj0b/gMkHxHOfnKkYBcTmQPFzmU7UrTY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=aES+jmra0ohhT0eM7oI2+X+3ZIaqGUtwcfUenXynKvTvV/OgcKa8GZv/g4bHvdkHM b+5qm52Jokk1XvvPDmFExCuSlxE/aWbmQryI4kfJ/RVQJXFPQrUA+cn5Nfe68KL1m2 2SiB95rAkYl/TVsKR5sdFa+olYBb78l88vsDsBZoHhiKZz7riUHj2JoAcEpcL0jyZu cpnNE+APe6AH4oBm9pzl4F1n+XoUtxMo7jnWqZVWLD3VPV0OTttkGljEXTTWrStapo i55lHI+sc/ENMmJbJ6x4jIkKN2L64KeVfsMq2TMgeSv44dl722BLQTPkX3p+kiH/JZ ro8ww+fHez6FQ== Date: Mon, 23 Dec 2024 14:12:17 -0800 Subject: [PATCH 02/51] libxfs: adjust xfs_fsb_to_db to handle segmented rtblocks From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498943834.2297565.8720957741513792049.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Update this function to handle segmented xfs_rtblock_t, just like we did for the kernel. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- libxfs/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libxfs/util.c b/libxfs/util.c index ed48e2045b484b..4a9dd254083a63 100644 --- a/libxfs/util.c +++ b/libxfs/util.c @@ -433,7 +433,7 @@ static xfs_daddr_t xfs_fsb_to_db(struct xfs_inode *ip, xfs_fsblock_t fsb) { if (XFS_IS_REALTIME_INODE(ip)) - return XFS_FSB_TO_BB(ip->i_mount, fsb); + return xfs_rtb_to_daddr(ip->i_mount, fsb); return XFS_FSB_TO_DADDR(ip->i_mount, (fsb)); } From patchwork Mon Dec 23 22:12: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: 13919371 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 002361AB53A for ; Mon, 23 Dec 2024 22:12: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=1734991955; cv=none; b=LOiRkWS6tMfJDOHQ4Nji1487T1p4Y+8vfq26ZFs+S0LzY5+vY+mmbGBDswYypZv07jYskliXznwenlGj4onTpgR7MIkWw3Ib4YbbpiykEKuQa0qjbFoigOu/XXu05JLusFm5zkOnNj40+K6IpRnPqGVlBntvRza6kZIy0BHfTKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734991955; c=relaxed/simple; bh=XDMvrPt4mzp1iTblZ7hMmHcmCPtynfsKr7a3qK8NmUI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tsAOz0GcTYCF81O4nXO/EHgZ8Vj3/ZqZ46b+WQWAQzaHr99tR5b5cRa/h+mmX+d5HSzhv/odECII5GpV+SnfoKh4D8yA/B4zKWMmmI4QqMGfBtT++ckDWeknrhhYtvBP/7G+wudW65Abv9D73LNzHeM33MpMk7Jx7lhyyf8GFR8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=t6u3QNV+; 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="t6u3QNV+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87B49C4CED3; Mon, 23 Dec 2024 22:12:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734991953; bh=XDMvrPt4mzp1iTblZ7hMmHcmCPtynfsKr7a3qK8NmUI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=t6u3QNV+oUzOTYDr94rsN84tmgyqU1+DA7RaxyEvL1cHCHmgZWHAXGSeUcwxt9Dy0 EiC+/DahlHDg425vxtZh5/+dPlw6ZVvq0kHQKxcRzLQT1KKAkJojN++93wTJkmDZB1 FIX+gOVu9UPTn5JJl3mcLx2rSHbdVj1/HnnAah6dneS+39iBVNND3hL/rcJg4LO/Po D3dBbXZ+UbAsL/7Ce5BlcY8TvDw5g36KYsQupbI5D1eHFua7EIYZ5M5b6xoGQ3KHzg eXFH+/zRTw/v3jlUeajuJeDe+IsRjcx1qRS8Hr89Caqz26tFydO3pWLU5duAJRqf+R wJCyHTbp2omXg== Date: Mon, 23 Dec 2024 14:12:33 -0800 Subject: [PATCH 03/51] xfs_repair,mkfs: port to libxfs_rt{bitmap,summary}_create From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498943849.2297565.313321719499366005.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Replace the open-coded rtbitmap and summary creation routines with the ones in libxfs so that we share code. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- mkfs/proto.c | 51 ++++++++++++++++++++++----------------------------- repair/phase6.c | 8 ++------ 2 files changed, 24 insertions(+), 35 deletions(-) diff --git a/mkfs/proto.c b/mkfs/proto.c index 55182bf50fd399..846b1c9a9e8a21 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -948,7 +948,10 @@ static void create_sb_metadata_file( struct xfs_rtgroup *rtg, enum xfs_rtg_inodes type, - void (*create)(struct xfs_inode *ip)) + int (*create)(struct xfs_rtgroup *rtg, + struct xfs_inode *ip, + struct xfs_trans *tp, + bool init)) { struct xfs_mount *mp = rtg_mount(rtg); struct xfs_icreate_args args = { @@ -972,9 +975,23 @@ create_sb_metadata_file( if (error) goto fail; - create(ip); + error = create(rtg, ip, tp, true); + if (error < 0) + error = -error; + if (error) + goto fail; - libxfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); + switch (type) { + case XFS_RTGI_BITMAP: + mp->m_sb.sb_rbmino = ip->i_ino; + break; + case XFS_RTGI_SUMMARY: + mp->m_sb.sb_rsumino = ip->i_ino; + break; + default: + error = EFSCORRUPTED; + goto fail; + } libxfs_log_sb(tp); error = -libxfs_trans_commit(tp); @@ -990,30 +1007,6 @@ create_sb_metadata_file( fail(_("Realtime inode allocation failed"), error); } -static void -rtbitmap_create( - struct xfs_inode *ip) -{ - struct xfs_mount *mp = ip->i_mount; - - ip->i_disk_size = mp->m_sb.sb_rbmblocks * mp->m_sb.sb_blocksize; - ip->i_diflags |= XFS_DIFLAG_NEWRTBM; - inode_set_atime(VFS_I(ip), 0, 0); - - mp->m_sb.sb_rbmino = ip->i_ino; -} - -static void -rtsummary_create( - struct xfs_inode *ip) -{ - struct xfs_mount *mp = ip->i_mount; - - ip->i_disk_size = mp->m_rsumblocks * mp->m_sb.sb_blocksize; - - mp->m_sb.sb_rsumino = ip->i_ino; -} - /* * Free the whole realtime area using transactions. * Do one transaction per bitmap block. @@ -1078,9 +1071,9 @@ rtinit( while ((rtg = xfs_rtgroup_next(mp, rtg))) { create_sb_metadata_file(rtg, XFS_RTGI_BITMAP, - rtbitmap_create); + libxfs_rtbitmap_create); create_sb_metadata_file(rtg, XFS_RTGI_SUMMARY, - rtsummary_create); + libxfs_rtsummary_create); rtfreesp_init(rtg); } diff --git a/repair/phase6.c b/repair/phase6.c index 41342d884ce37a..e9feaa5739efa1 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -550,14 +550,10 @@ _("couldn't iget realtime %s inode -- error - %d\n"), switch (type) { case XFS_RTGI_BITMAP: - ip->i_disk_size = mp->m_sb.sb_rbmblocks * mp->m_sb.sb_blocksize; - libxfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); - error = 0; + error = -libxfs_rtbitmap_create(rtg, ip, tp, false); break; case XFS_RTGI_SUMMARY: - ip->i_disk_size = mp->m_rsumblocks * mp->m_sb.sb_blocksize; - libxfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); - error = 0; + error = -libxfs_rtsummary_create(rtg, ip, tp, false); break; default: error = EINVAL; From patchwork Mon Dec 23 22:12: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: 13919372 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 973F81AE01E for ; Mon, 23 Dec 2024 22:12: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=1734991969; cv=none; b=XgZojC4vUqmUI3DMTNUTeG1wXSAv+s9BQW/wZH9fB27CxBTvb42TwLhsJ8L/UDZ0j85aVE1x7ocmZM9uN3UgRSQqYqDzTFi/b6o7bhJVcOWcOFvLG8A+VKHBUe3cZ6psTLjwo+R01t5XkSHGwKJ9BH5E8s3LyxQdmGM2pCKL9JQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734991969; c=relaxed/simple; bh=nGZitKSXFUpcYP6YVnkdJjmB5rudbsJA2GxWbp3rlL4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OXC2MV0nR93EIE+w6lbvJuIve4OY0MTrte40yhlF+ugmn3X2dWKCdCoCHqiknULifRm9kC02y3/J6t5B+KS5fy/1CuC8tHaHOIK3Ohrk9zUaB2RGwTyJO1XBCBXCURdS0V0LrvMRnqhD2WtDQX8l6TdZ3U/o7d+jC4m/v090Ih4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MNAluxox; 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="MNAluxox" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24F58C4CED3; Mon, 23 Dec 2024 22:12:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734991969; bh=nGZitKSXFUpcYP6YVnkdJjmB5rudbsJA2GxWbp3rlL4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=MNAluxoxOj6jh7NUYr50enLNDb17NXvxVSdeCwO9ufMougVoHivTGb4Ryutte4EaU KGHnHpiXJMRvI+0F2Rhrcol4cLjFjc/fjpHl2756cLxXsA6TdqHB+Ch28uyw+MuJeU 21XKBGjwJqVToO+7HNMgiJ3xvy7e8GmB9r0Y7VyfUYRMVqE7+ycz/4am5GCodj+Y65 V6gAqC3XtlK8OjsLdAeooABCChovUMQtAbdr+E0FqjnY3LWS+3D+LY9yD5cdviSz4p 59Y9/PuzbG4B5YAWIa00P8nbUmSaXJ27G9CyWq8oCumzcuFAlDBrPzPFoKb7F2vL+N Uxx8DFwGzE/Tg== Date: Mon, 23 Dec 2024 14:12:48 -0800 Subject: [PATCH 04/51] libxfs: use correct rtx count to block count conversion From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498943864.2297565.3880168792039008642.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Fix a place where we use the wrong conversion functions to convert between a number of rt extents and a number of rt blocks. This isn't really necessary since userspace cannot allocate rt extents, but let's not leave a logic bomb. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- libxfs/trans.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libxfs/trans.c b/libxfs/trans.c index 01834eff4b77ca..5c896ba1661b10 100644 --- a/libxfs/trans.c +++ b/libxfs/trans.c @@ -1202,7 +1202,7 @@ libxfs_trans_alloc_inode( int error; error = libxfs_trans_alloc(mp, resv, dblocks, - xfs_rtb_to_rtx(mp, rblocks), + xfs_extlen_to_rtxlen(mp, rblocks), force ? XFS_TRANS_RESERVE : 0, &tp); if (error) return error; From patchwork Mon Dec 23 22:13: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: 13919373 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 394171AB53A for ; Mon, 23 Dec 2024 22:13:04 +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=1734991986; cv=none; b=rSGn5KWR/n1mKEMaM73YQtU5xG8EjOgBr8Y6whz0KHgMlbFa5rtu0carFgRmuY3r/d/FYoI6A4OB8xWQSPMAG0ycnKgiwp28nNwVWFXDerL38AM0TaRaksevexJfvcUhoRnq5Il/LWsN0GcIJi+o9oDk16y1SwFwVH2LIv7UVYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734991986; c=relaxed/simple; bh=kyjUi+7JEO1+vHOV3CwmL9k9hl+qI5tUUlFiLfGg3g4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Nd8QVQL0bwttyvm8PGcI9H3xbbo6tVtFU/mM2VLdTGSZJSpB35qkhKTxhgyJIS3xt13TEtzwwvVSHnFOoBfizAhrLZtxNVVp2h3E7oDc6gLiZYnSTcMzRL342nNQioGBunFhbhOrO5LXAOmjtRYZUZhNdBbBYPOcAsCUwOo+sBQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r6J2oN9o; 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="r6J2oN9o" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B773CC4CED3; Mon, 23 Dec 2024 22:13:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734991984; bh=kyjUi+7JEO1+vHOV3CwmL9k9hl+qI5tUUlFiLfGg3g4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=r6J2oN9o0Heeg1Xqm1aEd9RbjbvAoDGMgElOn+lughC/Ec2ksXnklI6GlCCPxQJ/A 6fUOnCS6Tw9cDgOtzhSOmOawD9FryzH+1EM/ErXdPDtqfsunzw6Kj2MWX2SLARKWlA s0/8l1+oOue3iPUcGfXaqFFjFfhjjHl+EJXlPXo+aOKC1bcivtfDa44Yi4IXJGhNEP rDqVx1IkKyvPDam8kmdYEmxMn0v3nAn4Vsc82u2JEdrtZJjqDKHWszZyRW5U9hf95b DC7Z6paYNp5DK8Hp4DcEXUlrZcTDB9uKVXjfe+MJmdpe++Mldj/czFCKR54exismXr Tgxtspomrh74g== Date: Mon, 23 Dec 2024 14:13:04 -0800 Subject: [PATCH 05/51] libfrog: scrub the realtime group superblock From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498943880.2297565.13233945030751684553.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Enable scrubbing of realtime group superblocks in xfs_scrub, and update the scrub ioctl documentation. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- libfrog/scrub.c | 5 +++++ libfrog/scrub.h | 1 + man/man2/ioctl_xfs_scrub_metadata.2 | 9 +++++++++ scrub/repair.c | 1 + scrub/scrub.c | 6 ++++++ 5 files changed, 22 insertions(+) diff --git a/libfrog/scrub.c b/libfrog/scrub.c index b2d58c7a966b0d..e7fb8b890bc133 100644 --- a/libfrog/scrub.c +++ b/libfrog/scrub.c @@ -159,6 +159,11 @@ const struct xfrog_scrub_descr xfrog_scrubbers[XFS_SCRUB_TYPE_NR] = { .descr = "metadata directory paths", .group = XFROG_SCRUB_GROUP_METAPATH, }, + [XFS_SCRUB_TYPE_RGSUPER] = { + .name = "rgsuper", + .descr = "realtime group superblock", + .group = XFROG_SCRUB_GROUP_RTGROUP, + }, }; const struct xfrog_scrub_descr xfrog_metapaths[XFS_SCRUB_METAPATH_NR] = { diff --git a/libfrog/scrub.h b/libfrog/scrub.h index a35d3e9c293fe5..83455c390e170a 100644 --- a/libfrog/scrub.h +++ b/libfrog/scrub.h @@ -16,6 +16,7 @@ enum xfrog_scrub_group { XFROG_SCRUB_GROUP_ISCAN, /* metadata requiring full inode scan */ XFROG_SCRUB_GROUP_SUMMARY, /* summary metadata */ XFROG_SCRUB_GROUP_METAPATH, /* metadata directory path */ + XFROG_SCRUB_GROUP_RTGROUP, /* per-rtgroup metadata */ }; /* Catalog of scrub types and names, indexed by XFS_SCRUB_TYPE_* */ diff --git a/man/man2/ioctl_xfs_scrub_metadata.2 b/man/man2/ioctl_xfs_scrub_metadata.2 index 1e7e327b37d226..545e3fcbac320e 100644 --- a/man/man2/ioctl_xfs_scrub_metadata.2 +++ b/man/man2/ioctl_xfs_scrub_metadata.2 @@ -88,6 +88,15 @@ .SH DESCRIPTION .BR sm_ino " and " sm_gen must be zero. +.PP +.TP +.B XFS_SCRUB_TYPE_RGSUPER +Examine a given realtime allocation group's superblock. +The realtime allocation group number must be given in +.IR sm_agno "." +.IR sm_ino " and " sm_gen +must be zero. + .TP .B XFS_SCRUB_TYPE_INODE Examine a given inode record for obviously incorrect values and diff --git a/scrub/repair.c b/scrub/repair.c index e594e704f51503..c8cdb98de5457b 100644 --- a/scrub/repair.c +++ b/scrub/repair.c @@ -546,6 +546,7 @@ repair_item_difficulty( case XFS_SCRUB_TYPE_REFCNTBT: case XFS_SCRUB_TYPE_RTBITMAP: case XFS_SCRUB_TYPE_RTSUM: + case XFS_SCRUB_TYPE_RGSUPER: ret |= REPAIR_DIFFICULTY_PRIMARY; break; } diff --git a/scrub/scrub.c b/scrub/scrub.c index bcd63eea1030a6..a2fd8d77d82be0 100644 --- a/scrub/scrub.c +++ b/scrub/scrub.c @@ -66,6 +66,9 @@ format_metapath_descr( (unsigned long long)vhead->svh_ino); sc = &xfrog_metapaths[vhead->svh_ino]; + if (sc->group == XFROG_SCRUB_GROUP_RTGROUP) + return snprintf(buf, buflen, _("rtgroup %u %s"), + vhead->svh_agno, _(sc->descr)); return snprintf(buf, buflen, "%s", _(sc->descr)); } @@ -107,6 +110,9 @@ format_scrubv_descr( return snprintf(buf, buflen, _("%s"), _(sc->descr)); case XFROG_SCRUB_GROUP_METAPATH: return format_metapath_descr(buf, buflen, vhead); + case XFROG_SCRUB_GROUP_RTGROUP: + return snprintf(buf, buflen, _("rtgroup %u %s"), + vhead->svh_agno, _(sc->descr)); } return -1; } From patchwork Mon Dec 23 22:13:19 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: 13919374 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 C266613FEE for ; Mon, 23 Dec 2024 22:13: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=1734992000; cv=none; b=XsDmmO+6dCgQ2n/HL50gkCjq6Zbg7PQFlRGXL0uMW6wSrKIvPeuiEncYiLli0POpsJohJSFfzWInsyadu3+LyvFmQFnktZEGsfNtvNlUUrpB9f31n5kfDxVW17IVaqou/lBzniGmTia1DEekiw3Vj/L8/f6YSI7VWYmroqfRbbk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992000; c=relaxed/simple; bh=5QYfq8ebbqKiVYePV1+9Nje+i146QwvQC96WY6BIXAY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t7IOhzsfNgk/WBd/nmksMQV87BhWP7FS4jTZcVU3xL2zkmUejoVxsCvNrBu9Ugo0mb/BtD9vRIILO+zy23bOlET4QW9Xo3Nc3LOAbNQI2803MOEjM1TpMnfEFUx5h7mYrd7h9VgdWnSOZjO4sVOVuFVrB9FWYVnMQXew6kUwkn0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=njm5Be1M; 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="njm5Be1M" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A0B0C4CED3; Mon, 23 Dec 2024 22:13:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992000; bh=5QYfq8ebbqKiVYePV1+9Nje+i146QwvQC96WY6BIXAY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=njm5Be1M46EQUJTPAIsSxHbuicfduP8FrgGR62mtYSH6nj4FhUhzZpiy+wspDP5Tb Ky6bf8CqVyFGTOsO7j81XZEQ6CnapjLnP0Oi18k/T2fip2fFWEWm3ICS9aIE4WEBZQ j2vypJOBe77VX7UkGnSkKgjr4X9QqZPh3RQMh3chFbPYjruD27gN/31Es2L1G5UZ2U +xuv6okzhCo4pXnDJ2QODtoGcb7EmwIDdWuS1xRovq3loY6BhNUcvbf0Z0Up/jvAS6 xr00LwOcff0rHaKw9QTqsvhqbeN4S8mdPQksOeu8w6a+3djqZuYl93vZvS2cQENq0+ NcUHy0+DWqFmQ== Date: Mon, 23 Dec 2024 14:13:19 -0800 Subject: [PATCH 06/51] man: document the rt group geometry ioctl From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498943895.2297565.14103923834622796991.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Document the new ioctl that retrieves realtime allocation group geometry information. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- man/man2/ioctl_xfs_rtgroup_geometry.2 | 99 +++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 man/man2/ioctl_xfs_rtgroup_geometry.2 diff --git a/man/man2/ioctl_xfs_rtgroup_geometry.2 b/man/man2/ioctl_xfs_rtgroup_geometry.2 new file mode 100644 index 00000000000000..c4b0de94453558 --- /dev/null +++ b/man/man2/ioctl_xfs_rtgroup_geometry.2 @@ -0,0 +1,99 @@ +.\" Copyright (c) 2022-2024 Oracle. All rights reserved. +.\" +.\" %%%LICENSE_START(GPLv2+_DOC_FULL) +.\" SPDX-License-Identifier: GPL-2.0-or-later +.\" %%%LICENSE_END +.TH IOCTL-XFS-RTGROUP-GEOMETRY 2 2022-08-18 "XFS" +.SH NAME +ioctl_xfs_rtgroup_geometry \- query XFS realtime group geometry information +.SH SYNOPSIS +.br +.B #include +.PP +.BI "int ioctl(int " fd ", XFS_IOC_RTGROUP_GEOMETRY, struct xfs_rtgroup_geometry *" arg ); +.SH DESCRIPTION +This XFS ioctl retrieves the geometry information for a given realtime group. +The geometry information is conveyed in a structure of the following form: +.PP +.in +4n +.nf +struct xfs_rtgroup_geometry { + __u32 rg_number; + __u32 rg_length; + __u32 rg_sick; + __u32 rg_checked; + __u32 rg_flags; + __u32 rg_reserved[27]; +}; +.fi +.in +.TP +.I rg_number +The caller must set this field to the index of the realtime group that the +caller wishes to learn about. +.TP +.I rg_length +The length of the realtime group is returned in this field, in units of +filesystem blocks. +.I rg_flags +The caller can set this field to change the operational behavior of the ioctl. +Currently no flags are defined, so this field must be zero. +.TP +.IR rg_reserved " and " rg_pad +All reserved fields will be set to zero on return. +.PP +The fields +.IR rg_sick " and " rg_checked +indicate the relative health of various realtime group metadata: +.IP \[bu] 2 +If a given sick flag is set in +.IR rg_sick , +then that piece of metadata has been observed to be damaged. +The same bit will be set in +.IR rg_checked . +.IP \[bu] +If a given sick flag is set in +.I rg_checked +and is not set in +.IR rg_sick , +then that piece of metadata has been checked and is not faulty. +.IP \[bu] +If a given sick flag is not set in +.IR rg_checked , +then no conclusion can be made. +.PP +The following flags apply to these fields: +.RS 0.4i +.TP +.B XFS_RTGROUP_GEOM_SICK_SUPER +Realtime group superblock. +.TP +.B XFS_RTGROUP_GEOM_SICK_BITMAP +Realtime bitmap for this group. +.TP +.B XFS_RTGROUP_GEOM_SICK_SUMMARY +Realtime summary for this group. +.RE +.SH RETURN VALUE +On error, \-1 is returned, and +.I errno +is set to indicate the error. +.PP +.SH ERRORS +Error codes can be one of, but are not limited to, the following: +.TP +.B EFSBADCRC +Metadata checksum validation failed while performing the query. +.TP +.B EFSCORRUPTED +Metadata corruption was encountered while performing the query. +.TP +.B EINVAL +The specified realtime group number is not valid for this filesystem. +.TP +.B EIO +An I/O error was encountered while performing the query. +.SH CONFORMING TO +This API is specific to XFS filesystem on the Linux kernel. +.SH SEE ALSO +.BR ioctl (2) From patchwork Mon Dec 23 22:13: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: 13919375 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 2398B13FEE for ; Mon, 23 Dec 2024 22:13: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=1734992016; cv=none; b=UBRNHSvU6BzA1vIh/kz8GVDstM5XMlELLCY5VZKf80ZMtlZQAee+yRJiGRT3R0Zjl6OORlUk3kDdftQquKpfyrTCE8y0ONhGIng8KhJTP9EnFVup2oFcuQGuR9KstLQX1XL3GrIfqDshkprZevSivyweXwJEPKvo8XPPzZ7F+/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992016; c=relaxed/simple; bh=faYR7M7Xkr7kwRHvK5D8V1oe6/skkTmgh9FKgsTRgZY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qjsTvUXuOjBvwmU1VBEAkzbsSED/3QFNglV/hxq9UrfLt3mPOAav5de7PW9a8pMS7F6AWtXc5gkkNZfzLfqBSsx1NesvAcwyavTdyQ7m6ry6+jIbUuoabBeF4uQrZu9fynDm7wGREBJHVuuLuYqSeZjl96El3ognGQaa8VXiCSw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IGPKb3VH; 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="IGPKb3VH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01E20C4CED3; Mon, 23 Dec 2024 22:13:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992016; bh=faYR7M7Xkr7kwRHvK5D8V1oe6/skkTmgh9FKgsTRgZY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=IGPKb3VHQKMEQz/S5lYsd8QpjSbNECFUeu1G7g5z08Nf9LVFcR/j6YNbda8/a9uwf sHWhnwt4qU94rwXIHz6LhdLdiBUadClkOe7QkhiaxDEeRtkkoxnmRnyvqTK4qHpdj8 KXRORkrRjhDl/OQ5lIk3N/wPPfe/I0tNXwlZJbE0hqMHXy2g1he0Bi8AlGBxnE01yV yGznbwLSSNeItz94+L8YtVRZEiy0vHSLeWMBMUNCNosErLEzrXqh1ljBSRg1CLN3YD UkSpb+AMl6ez/82W4noxhSJtECaXoY2YmNdXMxPN54zqnmlYxk34Pkqe+D0nbYY7rL 58T6HS0fL36dw== Date: Mon, 23 Dec 2024 14:13:35 -0800 Subject: [PATCH 07/51] man: document rgextents geom field From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498943910.2297565.13089929670979744869.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Document the new rgextent geom field. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: "Darrick J. Wong" --- man/man2/ioctl_xfs_fsgeometry.2 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/man/man2/ioctl_xfs_fsgeometry.2 b/man/man2/ioctl_xfs_fsgeometry.2 index c808ad5b8b9190..502054f391e9b5 100644 --- a/man/man2/ioctl_xfs_fsgeometry.2 +++ b/man/man2/ioctl_xfs_fsgeometry.2 @@ -49,7 +49,8 @@ .SH DESCRIPTION __u32 sick; __u32 checked; - __u64 reserved[17]; + __u64 rgextents; + __u64 reserved[16]; }; .fi .in @@ -139,6 +140,9 @@ .SH DESCRIPTION .B XFS METADATA HEALTH REPORTING for more details. .PP +.I rgextents +Is the number of RT extents in each rtgroup. +.PP .I reserved is set to zero. .SH FILESYSTEM FEATURE FLAGS From patchwork Mon Dec 23 22:13: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: 13919376 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 1152F1AE01E for ; Mon, 23 Dec 2024 22:13:51 +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=1734992032; cv=none; b=iUG8XsRg6ITl58A1jT62SWxr4c8OHXkDnY4KmeCc3MFHGo99AmRO5NHz9cuyjfI6XTBHy7w5IOWqM9iG+Tyay3XuD/r/110NYMUrsV5f7dGH00fKQjcoZ2SEsQCagTeE8PTybX0KlWdax+hLZGbwv8oN81eHKo17NmKVOY9scEU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992032; c=relaxed/simple; bh=oprBTl2sogd5RKvCXB0DN0OOIKVmcsI+60Xl49elaFc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nfsKJA7faw2qftXGm2LV7t0jheWJlRvkrjae8ufGJTzwnt4Lr7L66eSb3uSiGN+dSFa0TC+9aoRtUVuje+UUHFCFcg1Ssh0fMIMKwysYj61eckC4nESLvt6oM8ucB/SI7/42l2U7SbrO3ct2YzFOkOPNzNWNcgdyn5ZEDCZOCnY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fgfyAI7J; 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="fgfyAI7J" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C25BC4CED3; Mon, 23 Dec 2024 22:13:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992031; bh=oprBTl2sogd5RKvCXB0DN0OOIKVmcsI+60Xl49elaFc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=fgfyAI7Jo6aT383L7Ak5w8J3jeWU/tsEALr5D2ASqrf8+BwlweP5BPcz6RL3yT2ye MC3ddXHJ6QT2fi/GWsD4Tt63FI2s8+44vUFpaYJ9+KcDPVEZTUeUkWHn7JxlfrAER6 oIazvoVBD8L9audNKvwrguRhY9YTDfj0aasCjQr8FEJLxu0BNdZ/FbtX+TPk7pgpmB XiW/DMqV54tgrEifE1LS+DbcKKYCv/aaeZg5gHBq6ILcoRDqV3yBoyeLTlSP1akkgF xkBIJsdEIfu+FLQpCuVkeHzKk78BzbuvEpP+c7hchGGtJ57UaiGgLx+7SuZHbWPlRk UIu6iR3QgQxxw== Date: Mon, 23 Dec 2024 14:13:51 -0800 Subject: [PATCH 08/51] libxfs: port userspace deferred log item to handle rtgroups From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498943926.2297565.11437968883658093474.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Make the userspace log items to handle rt groups correctly. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- libxfs/defer_item.c | 73 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/libxfs/defer_item.c b/libxfs/defer_item.c index eee84ffbe625d5..9db0e471cba69c 100644 --- a/libxfs/defer_item.c +++ b/libxfs/defer_item.c @@ -77,6 +77,17 @@ xfs_extent_free_create_done( return NULL; } +static inline const struct xfs_defer_op_type * +xefi_ops( + struct xfs_extent_free_item *xefi) +{ + if (xfs_efi_is_realtime(xefi)) + return &xfs_rtextent_free_defer_type; + if (xefi->xefi_agresv == XFS_AG_RESV_AGFL) + return &xfs_agfl_free_defer_type; + return &xfs_extent_free_defer_type; +} + /* Add this deferred EFI to the transaction. */ void xfs_extent_free_defer_add( @@ -86,14 +97,11 @@ xfs_extent_free_defer_add( { struct xfs_mount *mp = tp->t_mountp; + trace_xfs_extent_free_defer(mp, xefi); + xefi->xefi_group = xfs_group_intent_get(mp, xefi->xefi_startblock, - XG_TYPE_AG); - if (xefi->xefi_agresv == XFS_AG_RESV_AGFL) - *dfpp = xfs_defer_add(tp, &xefi->xefi_list, - &xfs_agfl_free_defer_type); - else - *dfpp = xfs_defer_add(tp, &xefi->xefi_list, - &xfs_extent_free_defer_type); + xfs_efi_is_realtime(xefi) ? XG_TYPE_RTG : XG_TYPE_AG); + *dfpp = xfs_defer_add(tp, &xefi->xefi_list, xefi_ops(xefi)); } /* Cancel a free extent. */ @@ -159,6 +167,32 @@ const struct xfs_defer_op_type xfs_extent_free_defer_type = { .cancel_item = xfs_extent_free_cancel_item, }; +STATIC int +xfs_rtextent_free_finish_item( + struct xfs_trans *tp, + struct xfs_log_item *done, + struct list_head *item, + struct xfs_btree_cur **state) +{ + struct xfs_extent_free_item *xefi = xefi_entry(item); + int error; + + error = xfs_rtfree_blocks(tp, to_rtg(xefi->xefi_group), + xefi->xefi_startblock, xefi->xefi_blockcount); + if (error != -EAGAIN) + xfs_extent_free_cancel_item(item); + return error; +} + +const struct xfs_defer_op_type xfs_rtextent_free_defer_type = { + .name = "rtextent_free", + .create_intent = xfs_extent_free_create_intent, + .abort_intent = xfs_extent_free_abort_intent, + .create_done = xfs_extent_free_create_done, + .finish_item = xfs_rtextent_free_finish_item, + .cancel_item = xfs_extent_free_cancel_item, +}; + /* * AGFL blocks are accounted differently in the reserve pools and are not * inserted into the busy extent list. @@ -496,14 +530,16 @@ xfs_bmap_update_create_done( return NULL; } -/* Take an active ref to the AG containing the space we're mapping. */ +/* Take a passive ref to the group containing the space we're mapping. */ static inline void xfs_bmap_update_get_group( struct xfs_mount *mp, struct xfs_bmap_intent *bi) { + enum xfs_group_type type = XG_TYPE_AG; + if (xfs_ifork_is_realtime(bi->bi_owner, bi->bi_whichfork)) - return; + type = XG_TYPE_RTG; /* * Bump the intent count on behalf of the deferred rmap and refcount @@ -513,7 +549,7 @@ xfs_bmap_update_get_group( * remains nonzero across the transaction roll. */ bi->bi_group = xfs_group_intent_get(mp, bi->bi_bmap.br_startblock, - XG_TYPE_AG); + type); } /* Add this deferred BUI to the transaction. */ @@ -522,8 +558,6 @@ xfs_bmap_defer_add( struct xfs_trans *tp, struct xfs_bmap_intent *bi) { - trace_xfs_bmap_defer(bi); - xfs_bmap_update_get_group(tp->t_mountp, bi); /* @@ -536,20 +570,11 @@ xfs_bmap_defer_add( */ if (bi->bi_type == XFS_BMAP_MAP) bi->bi_owner->i_delayed_blks += bi->bi_bmap.br_blockcount; + + trace_xfs_bmap_defer(bi); xfs_defer_add(tp, &bi->bi_list, &xfs_bmap_update_defer_type); } -/* Release an active AG ref after finishing mapping work. */ -static inline void -xfs_bmap_update_put_group( - struct xfs_bmap_intent *bi) -{ - if (xfs_ifork_is_realtime(bi->bi_owner, bi->bi_whichfork)) - return; - - xfs_group_intent_put(bi->bi_group); -} - /* Cancel a deferred bmap update. */ STATIC void xfs_bmap_update_cancel_item( @@ -560,7 +585,7 @@ xfs_bmap_update_cancel_item( if (bi->bi_type == XFS_BMAP_MAP) bi->bi_owner->i_delayed_blks -= bi->bi_bmap.br_blockcount; - xfs_bmap_update_put_group(bi); + xfs_group_intent_put(bi->bi_group); kmem_cache_free(xfs_bmap_intent_cache, bi); } From patchwork Mon Dec 23 22:14:06 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: 13919379 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 9550613FEE for ; Mon, 23 Dec 2024 22:14: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=1734992047; cv=none; b=OhrSYcOHrL4NJyql4qhUgIkqYQ+zXoYSGqS/pYEkDrMWvEaNUmdZo1hl6+8T7smDLDBcEW6UOoHLGKELZ8BM4mK9C5UniK0+KVzzcvDW4pmJ76f3GccLnZaWCQYWNJRTlOdGzqujaeb++JKOoricQxSaM2F3OfwsRDHOBxzFp+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992047; c=relaxed/simple; bh=qredLaqZSVHKZIewrncChktl+Uq73WmkT/C4nzIJ12w=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=D/4I9aK8VHpvfrR2Uq/m4tsDl2zN37OR39sdLCp19NPwt9/E6jF+eTgw6WUrVk9s94ZNG7DUuJa/zl/2L5ApG5lQCf5N2Op8tfP9OSDhBU/qESUC410a4ht62Zb4qJRDNr0mZ9SqCXZrrEliRuiPItH0VxdlOJTw2laFrwGsWR8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KhhYaUJf; 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="KhhYaUJf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 235E4C4CED3; Mon, 23 Dec 2024 22:14:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992047; bh=qredLaqZSVHKZIewrncChktl+Uq73WmkT/C4nzIJ12w=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=KhhYaUJf8d1G/vNgxAFguxngZya1jdOw8oF5GidKhuYMtcqeRh+ijoqbSsvlRMJ8X Iezz6K8rjOj/1WjJbhHatiuE+PmtQANgh8cOS9dkUpddKe+uTJw0pAcANp4dxtB99z S6CbpQB9kylBt5dwSkiKFd36YJ1fMSyYvVbwBSYe79wguAULmYVurvf84cxOsGMLuw ry2Bxi3e3RScB9gCJkFwNSJrydiyWGlOxcNlS8ge6ZG4ABsXcZJDuGRXXKbNyeLIdH Rc8tVH/EQGpeEjJENcUeEt3zJXd1YSLxQf2R0tIQCRnbgumS8MBtiuHhy+A/GAN+1Y l3BQFVHejWmBg== Date: Mon, 23 Dec 2024 14:14:06 -0800 Subject: [PATCH 09/51] libxfs: implement some sanity checking for enormous rgcount From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498943941.2297565.9493389794666208223.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Similar to what we do for suspiciously large sb_agcount values, if someone tries to get libxfs to load a filesystem with a very large realtime group count, let's do some basic checks of the rt device to see if it's really that large. If the read fails, only load the first rtgroup and warn the user. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- libxfs/init.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/libxfs/init.c b/libxfs/init.c index 6642cd50c00b5f..16291466ac86d3 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -654,6 +654,49 @@ xfs_set_low_space_thresholds( mp->m_low_space[i] = dblocks * (i + 1); } +/* + * libxfs_initialize_rtgroup will allocate a rtgroup structure for each + * rtgroup. If rgcount is corrupted and insanely high, this will OOM the box. + * Try to read what would be the last rtgroup superblock. If that fails, read + * the first one and let the user know to check the geometry. + */ +static inline bool +check_many_rtgroups( + struct xfs_mount *mp, + struct xfs_sb *sbp) +{ + struct xfs_buf *bp; + xfs_daddr_t d; + int error; + + if (!mp->m_rtdev->bt_bdev) { + fprintf(stderr, _("%s: no rt device, ignoring rgcount %u\n"), + progname, sbp->sb_rgcount); + if (!xfs_is_debugger(mp)) + return false; + + sbp->sb_rgcount = 0; + return true; + } + + d = (xfs_daddr_t)XFS_FSB_TO_BB(mp, mp->m_sb.sb_rblocks); + error = libxfs_buf_read(mp->m_rtdev, d - XFS_FSB_TO_BB(mp, 1), 1, 0, + &bp, NULL); + if (!error) { + libxfs_buf_relse(bp); + return true; + } + + fprintf(stderr, _("%s: read of rtgroup %u failed\n"), progname, + sbp->sb_rgcount - 1); + if (!xfs_is_debugger(mp)) + return false; + + fprintf(stderr, _("%s: limiting reads to rtgroup 0\n"), progname); + sbp->sb_rgcount = 1; + return true; +} + /* * Mount structure initialization, provides a filled-in xfs_mount_t * such that the numerous XFS_* macros can be used. If dev is zero, @@ -810,6 +853,9 @@ libxfs_mount( libxfs_buf_relse(bp); } + if (sbp->sb_rgcount > 1000000 && !check_many_rtgroups(mp, sbp)) + goto out_da; + error = libxfs_initialize_perag(mp, 0, sbp->sb_agcount, sbp->sb_dblocks, &mp->m_maxagi); if (error) { From patchwork Mon Dec 23 22:14: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: 13919380 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 E2E0713FEE for ; Mon, 23 Dec 2024 22:14:22 +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=1734992063; cv=none; b=rTEtRV1uiOLOXdmWBFqEiyc9n3yCn1Te0pPmmE+bj8fcBMl/Ko3gB3GnJpy0vp0Yd4VGW8YayOjjEw+dGlHcBKo1bzuxOXXQsE+PK2tTumI5i04smDQL7Mm2S4Au8ExgfFoxUpNOUqIr2tfcWeejrvXIxQkdkp9d0q7Co6I6Vw4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992063; c=relaxed/simple; bh=kT+0fhm8uY54S4zxkeWoKwrm9qZPDWgro8GGENbgi2M=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ecmI4F36ZcQVceDcqr8s1u/WB8dFw7DPfCQv3Zs1EZwKPOH6D/w+38isBUvezZ2NQ8pNpXikVfiwcA6bOE0+OeCcJndTYojXhAj1CibfhDTCN2RAlQkDunAtG2AYbBbelvFzO57SLAAjw1jjrdU/zMVbHq6IQPvwBg9Od3rtKUM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fAwQwLiN; 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="fAwQwLiN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B70B9C4CED3; Mon, 23 Dec 2024 22:14:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992062; bh=kT+0fhm8uY54S4zxkeWoKwrm9qZPDWgro8GGENbgi2M=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=fAwQwLiNK3U+aqOAVBYASvLJwqHm+/Aok9npiMy3ZWCkWszfCgPudhnKlGH5/3Nx8 mUk1MaJTfHRmCbL+IVnlAGnQpAmnYlT9Hm8eKuUy9NTzJAgvEVqzgqMU/yHqp+E76U +DavzNoOTsTnABxZOpDVZA0Ft3NUCDmtlTpMUxvPR9GIHVn7MqTtJoqAuDhmdGdLQv gmQ5VzkgYCfZE4H6DkwYkXVXBdequVo/L4PhisHS7zlmdL+jvA0QaBIhYvHwRNKnG0 zwcQbVngHPxOdTDAcYVVETJbNlKnkYvtI8woT8om//WcSCoOyTsgEoRC1TQRXfhbBb xQsRkKUbQrS7Q== Date: Mon, 23 Dec 2024 14:14:22 -0800 Subject: [PATCH 10/51] libfrog: support scrubbing rtgroup metadata paths From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498943957.2297565.12360582945042560643.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Support scrubbing the metadata paths of rtgroup metadata inodes. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- libfrog/scrub.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libfrog/scrub.c b/libfrog/scrub.c index e7fb8b890bc133..66000f1ed66be4 100644 --- a/libfrog/scrub.c +++ b/libfrog/scrub.c @@ -172,6 +172,21 @@ const struct xfrog_scrub_descr xfrog_metapaths[XFS_SCRUB_METAPATH_NR] = { .descr = "metapath", .group = XFROG_SCRUB_GROUP_NONE, }, + [XFS_SCRUB_METAPATH_RTDIR] = { + .name = "rtdir", + .descr = "realtime group metadir", + .group = XFROG_SCRUB_GROUP_FS, + }, + [XFS_SCRUB_METAPATH_RTBITMAP] = { + .name = "rtbitmap", + .descr = "rtgroup bitmap", + .group = XFROG_SCRUB_GROUP_RTGROUP, + }, + [XFS_SCRUB_METAPATH_RTSUMMARY] = { + .name = "rtsummary", + .descr = "rtgroup summary", + .group = XFROG_SCRUB_GROUP_RTGROUP, + }, }; /* Invoke the scrub ioctl. Returns zero or negative error code. */ From patchwork Mon Dec 23 22:14:37 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: 13919381 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 86A1713FEE for ; Mon, 23 Dec 2024 22:14:38 +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=1734992078; cv=none; b=NYkQ+XSBn25B2ycil2qyPC/qSgEr0EaDRQYm3sPe5+HHuSpn7VSmZJ/U3lBb0c1kd5gc48yRVGivZg6YR3bjIPYOwdKMRrzwGY91ZEJV2AhQ/imET/U6PRJrh8Cq8Vgk4nGs5amvhqi4nPYuSImAudjuc8WA19gmAsam6PW98lk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992078; c=relaxed/simple; bh=xKAYeRHbOCy9Ki2+NPyQAaFllc6bRNf2NEFIALxmBKE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=axWHUosWxlS3k1qhQrgjB5XhQo7vgeY1WgkT5qlXLHmS4sqeCxwdvttAQGZYjREcIu03wKJdpZok4eKzOyXR8fNX80wWCgGzCf6MWa+Az9+u2DDA/XRdH6qKmwigewOBsPYSY+LFZdhSVfFqdwiKxmmh7ZVOSEEOqbY989SqtxQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Quh8H0Lz; 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="Quh8H0Lz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CD79C4CED3; Mon, 23 Dec 2024 22:14:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992078; bh=xKAYeRHbOCy9Ki2+NPyQAaFllc6bRNf2NEFIALxmBKE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Quh8H0LzimosWJuSUb8Pc5Pq8mpcySh306BpwkNOVEuyMZVxsY2uwkeSyCI7swRNf J1dPwKtM449/xX9KrI6gQnSDWxo0GqBrFdsPx9lHyY3Wuc8wsuoXCyVKZG/QBmxu2+ BhB2F6tyD04VAyCFqRLvCGcq7QKPkZAXbusioDcEbjmVCcWaRknmp4fSw6dMHnkwiW ciUYc7Z3ns/11KYV4zW7H/JFDgSWy7t0b1LN57bDBr4UGuS2j6fq2j2v/IDj0o+FT2 ElvLWAeANkItvnxH1ZUYsA0UUR1oQ05sqqO08XBnzIKpWCaAI43+rL1583UytJkRoM We6HuAFQhfxrA== Date: Mon, 23 Dec 2024 14:14:37 -0800 Subject: [PATCH 11/51] libfrog: report rt groups in output From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498943972.2297565.8634272081467299980.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Report realtime group geometry. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- libfrog/fsgeom.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libfrog/fsgeom.c b/libfrog/fsgeom.c index 67b4e65713be5b..9c1e9a90eb1f1b 100644 --- a/libfrog/fsgeom.c +++ b/libfrog/fsgeom.c @@ -67,7 +67,8 @@ xfs_report_geom( "naming =version %-14u bsize=%-6u ascii-ci=%d, ftype=%d, parent=%d\n" "log =%-22s bsize=%-6d blocks=%u, version=%d\n" " =%-22s sectsz=%-5u sunit=%d blks, lazy-count=%d\n" -"realtime =%-22s extsz=%-6d blocks=%lld, rtextents=%lld\n"), +"realtime =%-22s extsz=%-6d blocks=%lld, rtextents=%lld\n" +" =%-22s rgcount=%-4d rgsize=%u extents\n"), mntpoint, geo->inodesize, geo->agcount, geo->agblocks, "", geo->sectsize, attrversion, projid32bit, "", crcs_enabled, finobt_enabled, spinodes, rmapbt_enabled, @@ -82,7 +83,8 @@ xfs_report_geom( "", geo->logsectsize, geo->logsunit / geo->blocksize, lazycount, !geo->rtblocks ? _("none") : rtname ? rtname : _("external"), geo->rtextsize * geo->blocksize, (unsigned long long)geo->rtblocks, - (unsigned long long)geo->rtextents); + (unsigned long long)geo->rtextents, + "", geo->rgcount, geo->rgextents); } /* Try to obtain the xfs geometry. On error returns a negative error code. */ From patchwork Mon Dec 23 22:14:53 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: 13919382 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 762FF1BBBDC for ; Mon, 23 Dec 2024 22:14: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=1734992094; cv=none; b=GrAYOeXEz7hmrYEtZ241go54+BksxYD+BNOtG35hXowNcpi6oxlB43G5YuYPWMc4tjLXe8w2tnqeKJFVj5zeNHHhcewp/x4DOaxHFd0qwr54wIsx/rDQ21lol4pQNJO8X7ZCpHjv3/o0+txGuxjC4cLO+k0iZwMuRPynLtxzGFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992094; c=relaxed/simple; bh=7K/DGv7FEDSrk/Ic4p/gTBi/MX6vbblO5iUkjEU5aS0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gR+/3fqhOKOPpzkBTk81KjBgG3SkFj2ZYFB0ue3Jxv7r4McvxdvjRmvPMNS8d9O0hz4PjuCCLnbj9audxjJLzs1xhleIRzKoow8k0H5OXFNYedlkHzREUCjhd4KIGmh4o63RZPNkRsgc/ihqJ6/fRKrFPAU+g+jZMATP6epu0a8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GMRVT61e; 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="GMRVT61e" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1C0FC4CED3; Mon, 23 Dec 2024 22:14:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992094; bh=7K/DGv7FEDSrk/Ic4p/gTBi/MX6vbblO5iUkjEU5aS0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=GMRVT61e2QZfdStnfYjqxIYYvNGzk8taTqFI+qd5v+3qLR9sj+HUns1HzkHLnO/id N3kv/jVKDigWtSzgXbbEKECxaXoLdjfoxem2XwbcY0CQsMVaPGzj0VFL7TALBc0CpK Vm11EDvzjpHsclVXhPskoHHpqm58Im0wGFDgEt/kuELQ+vt2H+qqW9y0im8qPrcIhs 7d5bTRAsyPefZJZ88EM0rVT89T+nQ49vNhoOEKq9Um+DIvY7s92j1Dx4i2XXTFWiT/ DkifjoVTTgCvELmixLm9Jo6liQ8Bi7LBIjGkBnTGUEQFzYM1Ohqw1r9NyEO4MH+2A1 sZCS/Ef+5KL2w== Date: Mon, 23 Dec 2024 14:14:53 -0800 Subject: [PATCH 12/51] libfrog: add bitmap_clear From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498943988.2297565.16798595244468929206.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Uncomment and fix bitmap_clear so that xfs_repair can start using it. Signed-off-by: "Darrick J. Wong" [hch: split from a larger patch] Signed-off-by: Christoph Hellwig Reviewed-by: Christoph Hellwig --- libfrog/bitmap.c | 25 +++++++++++++++++++------ libfrog/bitmap.h | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/libfrog/bitmap.c b/libfrog/bitmap.c index 5af5ab8dd6b3bb..0308886d446ff2 100644 --- a/libfrog/bitmap.c +++ b/libfrog/bitmap.c @@ -233,10 +233,9 @@ bitmap_set( return res; } -#if 0 /* Unused, provided for completeness. */ /* Clear a region of bits. */ -int -bitmap_clear( +static int +__bitmap_clear( struct bitmap *bmap, uint64_t start, uint64_t len) @@ -251,8 +250,8 @@ bitmap_clear( uint64_t new_length; struct avl64node *node; int stat; + int ret = 0; - pthread_mutex_lock(&bmap->bt_lock); /* Find any existing nodes over that range. */ avl64_findranges(bmap->bt_tree, start, start + len, &firstn, &lastn); @@ -312,10 +311,24 @@ bitmap_clear( } out: - pthread_mutex_unlock(&bmap->bt_lock); return ret; } -#endif + +/* Clear a region of bits. */ +int +bitmap_clear( + struct bitmap *bmap, + uint64_t start, + uint64_t length) +{ + int res; + + pthread_mutex_lock(&bmap->bt_lock); + res = __bitmap_clear(bmap, start, length); + pthread_mutex_unlock(&bmap->bt_lock); + + return res; +} /* Iterate the set regions of this bitmap. */ int diff --git a/libfrog/bitmap.h b/libfrog/bitmap.h index 043b77eece65b3..47df0ad38467ce 100644 --- a/libfrog/bitmap.h +++ b/libfrog/bitmap.h @@ -14,6 +14,7 @@ struct bitmap { int bitmap_alloc(struct bitmap **bmap); void bitmap_free(struct bitmap **bmap); int bitmap_set(struct bitmap *bmap, uint64_t start, uint64_t length); +int bitmap_clear(struct bitmap *bmap, uint64_t start, uint64_t length); int bitmap_iterate(struct bitmap *bmap, int (*fn)(uint64_t, uint64_t, void *), void *arg); int bitmap_iterate_range(struct bitmap *bmap, uint64_t start, uint64_t length, From patchwork Mon Dec 23 22:15: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: 13919383 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 05029188596 for ; Mon, 23 Dec 2024 22:15:09 +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=1734992110; cv=none; b=Yg71Yl7+UxqggLY465uGnfNgnxFg/PdOqKP3ZS2wcZ+l1yhm7CPZK12cyKy9Yjr2HRLEqTx8jn7iWPiN/un00dnGMgfgsRdQwxMgtonew5asvuY7jPNVNtdshFKcjd32348LXM45yGyNImOGVy6pVAmajSIXRy+d815n03GdfDk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992110; c=relaxed/simple; bh=H7u7PObzHymrqJ9acOFDDAey06ZwFVtKCQHRCWpDVAU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fb7fiyhflNZ6uG0vlJRhoqb49LIvQLRAhFWGZdRPjALY9NXP1PLNpuR2BG/FWLrsGpmvCNeN2Xrt5A/13p+5zPWUi+X1Q+IM84Vv6LIlHMUoywxrscwtn+YZASi2W0cS2Vmm+dntqncbRVNAxCf1MajRWZjzvCYR9nreKGpqlpg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uTztbj8I; 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="uTztbj8I" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F216C4CED3; Mon, 23 Dec 2024 22:15:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992109; bh=H7u7PObzHymrqJ9acOFDDAey06ZwFVtKCQHRCWpDVAU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=uTztbj8IqAbhgh3hd5DzJ0b7FwOdaf9g3xgowVea8MqSkw4c655onDAjbw4Yo7fDZ ygxCNxh1MeLqi+FTGIhvR9u3325zFlIwXJap+2ZLWZRORqCcvXBMllQNQj0SPd1JiC SM2CxnjTGr6XnnlvwM+iF7B7D9lZQBoiBE56rUhCZaUqofl5S1V9ivJRBfB8oVU6r+ GkQZEEuC0OYzdQfinWGVuoyY6GJ5voEyvYzTCZXurgYqZ8Ff9NSwduTRQbEH6jwr9Z yn6xlVSe+65DhihyGTiEoz8q90hJ7GSGTf7qVPn+WtbbkK2IzTDJYc/C80SLMWy/ZY qx+Nbht7bOJ4Q== Date: Mon, 23 Dec 2024 14:15:09 -0800 Subject: [PATCH 13/51] xfs_logprint: report realtime EFIs From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944003.2297565.10725313991768318320.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Decode the EFI format just enough to report if an EFI targets the realtime device or not. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- logprint/log_misc.c | 2 ++ logprint/log_print_all.c | 8 ++++++ logprint/log_redo.c | 57 +++++++++++++++++++++++++++++++++++----------- 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/logprint/log_misc.c b/logprint/log_misc.c index 8e86ac347fa963..1df8c5d377c02d 100644 --- a/logprint/log_misc.c +++ b/logprint/log_misc.c @@ -997,12 +997,14 @@ xlog_print_record( &i, num_ops); break; } + case XFS_LI_EFI_RT: case XFS_LI_EFI: { skip = xlog_print_trans_efi(&ptr, be32_to_cpu(op_head->oh_len), continued); break; } + case XFS_LI_EFD_RT: case XFS_LI_EFD: { skip = xlog_print_trans_efd(&ptr, be32_to_cpu(op_head->oh_len)); diff --git a/logprint/log_print_all.c b/logprint/log_print_all.c index a4a5e41f17fa64..5a9ddd05ab1288 100644 --- a/logprint/log_print_all.c +++ b/logprint/log_print_all.c @@ -410,9 +410,11 @@ xlog_recover_print_logitem( case XFS_LI_INODE: xlog_recover_print_inode(item); break; + case XFS_LI_EFD_RT: case XFS_LI_EFD: xlog_recover_print_efd(item); break; + case XFS_LI_EFI_RT: case XFS_LI_EFI: xlog_recover_print_efi(item); break; @@ -474,6 +476,12 @@ xlog_recover_print_item( case XFS_LI_INODE: printf("INO"); break; + case XFS_LI_EFD_RT: + printf("EFD_RT"); + break; + case XFS_LI_EFI_RT: + printf("EFI_RT"); + break; case XFS_LI_EFD: printf("EFD"); break; diff --git a/logprint/log_redo.c b/logprint/log_redo.c index 684e5f4a3f32c2..41e7c94a52dc21 100644 --- a/logprint/log_redo.c +++ b/logprint/log_redo.c @@ -67,6 +67,7 @@ xlog_print_trans_efi( uint src_len, int continued) { + const char *item_name = "EFI?"; xfs_efi_log_format_t *src_f, *f = NULL; uint dst_len; xfs_extent_t *ex; @@ -103,8 +104,14 @@ xlog_print_trans_efi( goto error; } - printf(_("EFI: #regs: %d num_extents: %d id: 0x%llx\n"), - f->efi_size, f->efi_nextents, (unsigned long long)f->efi_id); + switch (f->efi_type) { + case XFS_LI_EFI: item_name = "EFI"; break; + case XFS_LI_EFI_RT: item_name = "EFI_RT"; break; + } + + printf(_("%s: #regs: %d num_extents: %u id: 0x%llx\n"), + item_name, f->efi_size, f->efi_nextents, + (unsigned long long)f->efi_id); if (continued) { printf(_("EFI free extent data skipped (CONTINUE set, no space)\n")); @@ -113,7 +120,7 @@ xlog_print_trans_efi( ex = f->efi_extents; for (i=0; i < f->efi_nextents; i++) { - printf("(s: 0x%llx, l: %d) ", + printf("(s: 0x%llx, l: %u) ", (unsigned long long)ex->ext_start, ex->ext_len); if (i % 4 == 3) printf("\n"); ex++; @@ -130,6 +137,7 @@ void xlog_recover_print_efi( struct xlog_recover_item *item) { + const char *item_name = "EFI?"; xfs_efi_log_format_t *f, *src_f; xfs_extent_t *ex; int i; @@ -155,12 +163,18 @@ xlog_recover_print_efi( return; } - printf(_(" EFI: #regs:%d num_extents:%d id:0x%llx\n"), - f->efi_size, f->efi_nextents, (unsigned long long)f->efi_id); + switch (f->efi_type) { + case XFS_LI_EFI: item_name = "EFI"; break; + case XFS_LI_EFI_RT: item_name = "EFI_RT"; break; + } + + printf(_(" %s: #regs:%d num_extents:%u id:0x%llx\n"), + item_name, f->efi_size, f->efi_nextents, + (unsigned long long)f->efi_id); ex = f->efi_extents; printf(" "); for (i=0; i< f->efi_nextents; i++) { - printf("(s: 0x%llx, l: %d) ", + printf("(s: 0x%llx, l: %u) ", (unsigned long long)ex->ext_start, ex->ext_len); if (i % 4 == 3) printf("\n"); @@ -174,8 +188,10 @@ xlog_recover_print_efi( int xlog_print_trans_efd(char **ptr, uint len) { - xfs_efd_log_format_t *f; - xfs_efd_log_format_t lbuf; + const char *item_name = "EFD?"; + xfs_efd_log_format_t *f; + xfs_efd_log_format_t lbuf; + /* size without extents at end */ uint core_size = sizeof(xfs_efd_log_format_t); @@ -185,11 +201,17 @@ xlog_print_trans_efd(char **ptr, uint len) */ memmove(&lbuf, *ptr, min(core_size, len)); f = &lbuf; + + switch (f->efd_type) { + case XFS_LI_EFD: item_name = "EFD"; break; + case XFS_LI_EFD_RT: item_name = "EFD_RT"; break; + } + *ptr += len; if (len >= core_size) { - printf(_("EFD: #regs: %d num_extents: %d id: 0x%llx\n"), - f->efd_size, f->efd_nextents, - (unsigned long long)f->efd_efi_id); + printf(_("%s: #regs: %d num_extents: %d id: 0x%llx\n"), + item_name, f->efd_size, f->efd_nextents, + (unsigned long long)f->efd_efi_id); /* don't print extents as they are not used */ @@ -204,18 +226,25 @@ void xlog_recover_print_efd( struct xlog_recover_item *item) { + const char *item_name = "EFD?"; xfs_efd_log_format_t *f; f = (xfs_efd_log_format_t *)item->ri_buf[0].i_addr; + + switch (f->efd_type) { + case XFS_LI_EFD: item_name = "EFD"; break; + case XFS_LI_EFD_RT: item_name = "EFD_RT"; break; + } + /* * An xfs_efd_log_format structure contains a variable length array * as the last field. * Each element is of size xfs_extent_32_t or xfs_extent_64_t. * However, the extents are never used and won't be printed. */ - printf(_(" EFD: #regs: %d num_extents: %d id: 0x%llx\n"), - f->efd_size, f->efd_nextents, - (unsigned long long)f->efd_efi_id); + printf(_(" %s: #regs: %d num_extents: %d id: 0x%llx\n"), + item_name, f->efd_size, f->efd_nextents, + (unsigned long long)f->efd_efi_id); } /* Reverse Mapping Update Items */ From patchwork Mon Dec 23 22:15:24 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: 13919384 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 552B218E35D for ; Mon, 23 Dec 2024 22:15: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=1734992125; cv=none; b=YR4Fmgj9U37rYcXeJpQCeAAPC4en0RulHD4F85ZpULsA7IN4qkvhvt3opslzpVDyKHW6ue+Lrg20CoCOS2DSmQgMsEb7+LQlyRuf/GUsYymnULgSSXA+yz35SHYVsAHsADrfRJ9zLUeX7ZufpZTogtOHl5ahtmqI728qm5swdmY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992125; c=relaxed/simple; bh=gMPeFSFPCZ17WWx6t+YrZViWdxp318pla22Wr1hqrsg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AJBt79A1mwTFdBCwKg7moe4CEJ2OkibQgwAss248GsQ4R/azGjd8baFyiygjEUjlKyDzEMKmL7RUXntZLTHfzZDe/DGK+zb2Al/Waq7MIc5Mu0piKfHFUNw5zaREpYXNB7Q45d/BDVuwUasyFY00TMfox99zmextihl8fF9gbZA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WgRXK6Rv; 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="WgRXK6Rv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29073C4CED3; Mon, 23 Dec 2024 22:15:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992125; bh=gMPeFSFPCZ17WWx6t+YrZViWdxp318pla22Wr1hqrsg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=WgRXK6RvycRcajzXpggMcwh1oKfzzin43fCsBQ1T99bANBLDDnYT57736sIdq/nMG saHPOdk/JbmD+oKSfCrbYVNX9f4+1hjLGBcxiXgc3QXf3b24LwKEuLWFPyASE5oIX2 rKGodxGXD5SV1HRVhaU++B/ngYxaUikGFmVu4snB6mHHFbb47pWIGjRyJyUyxLq2WA fqjqTFfIAQ4ET/T2RLSKki39GUq4QSCl38RQ2TSidGkyuY1tmIeJ9+xq9HQWXFcl24 JnaAdRFJbKe02vvm7U+jlFluPAyvS+v/lMCKJ0kwnhlMYzPIwFBwHWEJd7dD3rpEZs 83WLw6Ot2Rthg== Date: Mon, 23 Dec 2024 14:15:24 -0800 Subject: [PATCH 14/51] xfs_repair: adjust rtbitmap/rtsummary word updates to handle big endian values From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944018.2297565.13178926036856431152.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong With rtgroups, the rt bitmap and summary file words are defined to be be32 values. Adjust repair to handle the endianness correctly. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- repair/rt.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/repair/rt.c b/repair/rt.c index 711891a724b076..65d6a713f379d2 100644 --- a/repair/rt.c +++ b/repair/rt.c @@ -24,7 +24,10 @@ set_rtword( union xfs_rtword_raw *word, xfs_rtword_t value) { - word->old = value; + if (xfs_has_rtgroups(mp)) + word->rtg = cpu_to_be32(value); + else + word->old = value; } static inline void @@ -35,7 +38,10 @@ inc_sumcount( { union xfs_suminfo_raw *p = info + index; - p->old++; + if (xfs_has_rtgroups(mp)) + be32_add_cpu(&p->rtg, 1); + else + p->old++; } /* From patchwork Mon Dec 23 22:15: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: 13919385 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 E4549EAF6 for ; Mon, 23 Dec 2024 22:15:40 +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=1734992141; cv=none; b=IO3OikpFR8P49tv6Boux67gxixJw5xK6tyD9nmrWmmXeXiDE2qej1Vz6UleHACaHxLd7mGrsNCauUHBvftT8CEhoVPbHCOI6nRw3XJmU/bgmGNWAjt8gGt8YmA5fOeycCRSjXf6sxcLUYEi4/KPBpktKc6RXt0AaSIxzDszNgc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992141; c=relaxed/simple; bh=scHgwzeGGbF4vu1rxyVWSDLQ1D9t9xOhbvbBBm589nQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Cu2028hivurUnHwjserCWvWcs0u8Kal8CDDt9vnN4+hrMce4aZEb1ckCtGMqv4xSlk2CtPU6Oc+casC8/76hS3njrrnv5FHQhK2GuXtLXkcm5kJX4NuMWYRonK3m995bL8EmZKKh5jdXotw6yutLEYePpIYqhZUzJv1SsjIxSos= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cxiqNnzj; 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="cxiqNnzj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4DC0C4CED3; Mon, 23 Dec 2024 22:15:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992140; bh=scHgwzeGGbF4vu1rxyVWSDLQ1D9t9xOhbvbBBm589nQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=cxiqNnzj7o+0lMpYTekyLFWJAEBJJNMmMmfMhe+Efr9Bhv+SnvtvMK7nQ6eJwx08u xsSA+2YQTA0QgiLrawXVWM/SeVZTMHysqxONht6CVBDNDZQDsHQaSj2SQi8QwGU72i L8O2goT84qciyinHbi/eBlpAPPfJ22VH4tznQhVDiDCxtGxCXfT0imEwBpyv33df8x UEjb7SZHHa4kpvNbv6tH48VQR98IeM44nZjF2LlGIYdQy/j+ppU9jorTJwAEytC0mj G3NxJsD71K3tczz/5WQweTTwJfGPILqrCZ5MqFYjKiDBKVtIlNb+TbWz15AZRvbYVx 3i4hqiESwC2tA== Date: Mon, 23 Dec 2024 14:15:40 -0800 Subject: [PATCH 15/51] xfs_repair: refactor phase4 From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944034.2297565.3459255793420938338.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Split out helpers to process all duplicate extents in an AG and the RT duplicate extents. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- repair/phase4.c | 210 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 114 insertions(+), 96 deletions(-) diff --git a/repair/phase4.c b/repair/phase4.c index 40db36f1f93020..036a4ed0e54445 100644 --- a/repair/phase4.c +++ b/repair/phase4.c @@ -225,20 +225,122 @@ process_rmap_data( destroy_work_queue(&wq); } +static void +process_dup_rt_extents( + struct xfs_mount *mp) +{ + xfs_rtxnum_t rt_start = 0; + xfs_rtxlen_t rt_len = 0; + xfs_rtxnum_t rtx; + + for (rtx = 0; rtx < mp->m_sb.sb_rextents; rtx++) { + int state; + + state = get_rtbmap(rtx); + switch (state) { + case XR_E_BAD_STATE: + default: + do_warn( + _("unknown rt extent state %d, extent %" PRIu64 "\n"), + state, rtx); + fallthrough; + case XR_E_METADATA: + case XR_E_UNKNOWN: + case XR_E_FREE1: + case XR_E_FREE: + case XR_E_INUSE: + case XR_E_INUSE_FS: + case XR_E_INO: + case XR_E_FS_MAP: + if (rt_start == 0) + continue; + /* + * Add extent and reset extent state. + */ + add_rt_dup_extent(rt_start, rt_len); + rt_start = 0; + rt_len = 0; + break; + case XR_E_MULT: + switch (rt_start) { + case 0: + rt_start = rtx; + rt_len = 1; + break; + case XFS_MAX_BMBT_EXTLEN: + /* + * Large extent case. + */ + add_rt_dup_extent(rt_start, rt_len); + rt_start = rtx; + rt_len = 1; + break; + default: + rt_len++; + break; + } + break; + } + } + + /* + * Catch the tail case, extent hitting the end of the RTG. + */ + if (rt_start != 0) + add_rt_dup_extent(rt_start, rt_len); +} + +/* + * Set up duplicate extent list for an AG or RTG. + */ +static void +process_dup_extents( + xfs_agnumber_t agno, + xfs_agblock_t agbno, + xfs_agblock_t ag_end) +{ + do { + int bstate; + xfs_extlen_t blen; + + bstate = get_bmap_ext(agno, agbno, ag_end, &blen); + switch (bstate) { + case XR_E_FREE1: + if (no_modify) + do_warn( +_("free space (%u,%u-%u) only seen by one free space btree\n"), + agno, agbno, agbno + blen - 1); + break; + case XR_E_METADATA: + case XR_E_UNKNOWN: + case XR_E_FREE: + case XR_E_INUSE: + case XR_E_INUSE_FS: + case XR_E_INO: + case XR_E_FS_MAP: + break; + case XR_E_MULT: + add_dup_extent(agno, agbno, blen); + break; + case XR_E_BAD_STATE: + default: + do_warn( +_("unknown block state, ag %d, blocks %u-%u\n"), + agno, agbno, agbno + blen - 1); + break; + } + + agbno += blen; + } while (agbno < ag_end); +} + void phase4(xfs_mount_t *mp) { ino_tree_node_t *irec; - xfs_rtxnum_t rtx; - xfs_rtxnum_t rt_start; - xfs_rtxlen_t rt_len; xfs_agnumber_t i; - xfs_agblock_t j; - xfs_agblock_t ag_end; - xfs_extlen_t blen; int ag_hdr_len = 4 * mp->m_sb.sb_sectsize; int ag_hdr_block; - int bstate; if (rmap_needs_work(mp)) collect_rmaps = true; @@ -281,102 +383,19 @@ phase4(xfs_mount_t *mp) } for (i = 0; i < mp->m_sb.sb_agcount; i++) { + xfs_agblock_t ag_end; + ag_end = (i < mp->m_sb.sb_agcount - 1) ? mp->m_sb.sb_agblocks : mp->m_sb.sb_dblocks - (xfs_rfsblock_t) mp->m_sb.sb_agblocks * i; - /* - * set up duplicate extent list for this ag - */ - for (j = ag_hdr_block; j < ag_end; j += blen) { - bstate = get_bmap_ext(i, j, ag_end, &blen); - switch (bstate) { - case XR_E_FREE1: - if (no_modify) - do_warn( - _("free space (%u,%u-%u) only seen by one free space btree\n"), - i, j, j + blen - 1); - break; - case XR_E_BAD_STATE: - default: - do_warn( - _("unknown block state, ag %d, blocks %u-%u\n"), - i, j, j + blen - 1); - fallthrough; - case XR_E_METADATA: - case XR_E_UNKNOWN: - case XR_E_FREE: - case XR_E_INUSE: - case XR_E_INUSE_FS: - case XR_E_INO: - case XR_E_FS_MAP: - break; - case XR_E_MULT: - add_dup_extent(i, j, blen); - break; - } - } + process_dup_extents(i, ag_hdr_block, ag_end); PROG_RPT_INC(prog_rpt_done[i], 1); } print_final_rpt(); - /* - * initialize realtime bitmap - */ - rt_start = 0; - rt_len = 0; - - for (rtx = 0; rtx < mp->m_sb.sb_rextents; rtx++) { - bstate = get_rtbmap(rtx); - switch (bstate) { - case XR_E_BAD_STATE: - default: - do_warn( - _("unknown rt extent state, extent %" PRIu64 "\n"), - rtx); - fallthrough; - case XR_E_METADATA: - case XR_E_UNKNOWN: - case XR_E_FREE1: - case XR_E_FREE: - case XR_E_INUSE: - case XR_E_INUSE_FS: - case XR_E_INO: - case XR_E_FS_MAP: - if (rt_start == 0) - continue; - else { - /* - * add extent and reset extent state - */ - add_rt_dup_extent(rt_start, rt_len); - rt_start = 0; - rt_len = 0; - } - break; - case XR_E_MULT: - if (rt_start == 0) { - rt_start = rtx; - rt_len = 1; - } else if (rt_len == XFS_MAX_BMBT_EXTLEN) { - /* - * large extent case - */ - add_rt_dup_extent(rt_start, rt_len); - rt_start = rtx; - rt_len = 1; - } else - rt_len++; - break; - } - } - - /* - * catch tail-case, extent hitting the end of the ag - */ - if (rt_start != 0) - add_rt_dup_extent(rt_start, rt_len); + process_dup_rt_extents(mp); /* * initialize bitmaps for all AGs @@ -410,8 +429,7 @@ phase4(xfs_mount_t *mp) /* * free up memory used to track trealtime duplicate extents */ - if (rt_start != 0) - free_rt_dup_extent_tree(mp); + free_rt_dup_extent_tree(mp); /* * ensure consistency of quota inode pointers in superblock, From patchwork Mon Dec 23 22:15:55 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: 13919386 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 C21C6192B86 for ; Mon, 23 Dec 2024 22:15:56 +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=1734992156; cv=none; b=eSyCGRQ3PAUg/jr1/s05hiiPcC0d1IKIOgFm+v1UhsJu3rWBjxJyUHUk420XfzzqmAc+m0VTPKHpg8uGFcBlVX0XE459Iv5qsi9TK5Ts0u/sTNX8ndeJaTUJDQTvbzI0oU9Yl88YyalJSdTXNLyJuTWBvW/wn4diIIIFCSEv/sA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992156; c=relaxed/simple; bh=p7+GRARpRmTQ2hUNuKqArQ4WpU/fN4p+CfFIwTrdyvc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iWdc6Jxby+kyS8MTLqpwzGngoAdXJrNDBkm3vr270AgVpiaa9pVXteVmZir/pr5lTMTfvhtocIbUd3l8ug/xk/Xs4DmbuOplqb7wftlhgiTHYkxbN3piWrfW4a6vSQKk18DnOVJKlUlbZR3yRryI/Cxik9kUMv7VYyRpyUffB+I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QbjqKoS3; 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="QbjqKoS3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58633C4CED3; Mon, 23 Dec 2024 22:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992156; bh=p7+GRARpRmTQ2hUNuKqArQ4WpU/fN4p+CfFIwTrdyvc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=QbjqKoS3lXw+uhr3TUX8O9eKizwE+4zzH8ATZ5ibsEMOXykAqZ/TilbGb9vor5JlA brEcTdTtB6pBX91wovHfwfw0dv/1+o8O9Xx4ch+VxN0HN/FVpDYzZ4XDAHJjaDXVwV Xgk/kUZaLHZguRwD2GOvozKHtzFscQthB6ZvhMvvjqNWarjkYoPy3XwmICQK5uoi2d OpnUXMNzW8Cr4axBHsZTSkC55bIrFsCeFCpfCMSnPCL4NClVgBjVhflaVr1Wgt/80M 8cbN+5bcNs8zbuopO+Ydb6e6w7oDBW2hQjPUG3bM0RLf0XoVJ33EdoMI5X2x1pCIpf 0aIqD4OAyFcjw== Date: Mon, 23 Dec 2024 14:15:55 -0800 Subject: [PATCH 16/51] xfs_repair: refactor offsetof+sizeof to offsetofend From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944049.2297565.15650653706993783633.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Replace this open-coded logic with the kernel's offsetofend macro before we start adding more in the next patch. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- include/xfs.h | 15 +++++++++++++++ repair/agheader.c | 21 +++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/include/xfs.h b/include/xfs.h index e97158c8d223f5..a2f159a586ee71 100644 --- a/include/xfs.h +++ b/include/xfs.h @@ -38,8 +38,23 @@ extern int xfs_assert_largefile[sizeof(off_t)-8]; #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) #endif +/** + * sizeof_field() - Report the size of a struct field in bytes + * + * @TYPE: The structure containing the field of interest + * @MEMBER: The field to return the size of + */ #define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER)) +/** + * offsetofend() - Report the offset of a struct field within the struct + * + * @TYPE: The type of the structure + * @MEMBER: The member within the structure to get the end offset of + */ +#define offsetofend(TYPE, MEMBER) \ + (offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER)) + #include /* Include deprecated/compat pre-vfs xfs-specific symbols */ #include diff --git a/repair/agheader.c b/repair/agheader.c index fe58d833b8bafa..14aedece3d07b0 100644 --- a/repair/agheader.c +++ b/repair/agheader.c @@ -364,26 +364,19 @@ secondary_sb_whack( * size is the size of data which is valid for this sb. */ if (xfs_sb_version_hasmetadir(sb)) - size = offsetof(struct xfs_dsb, sb_metadirino) - + sizeof(sb->sb_metadirino); + size = offsetofend(struct xfs_dsb, sb_metadirino); else if (xfs_sb_version_hasmetauuid(sb)) - size = offsetof(struct xfs_dsb, sb_meta_uuid) - + sizeof(sb->sb_meta_uuid); + size = offsetofend(struct xfs_dsb, sb_meta_uuid); else if (xfs_sb_version_hascrc(sb)) - size = offsetof(struct xfs_dsb, sb_lsn) - + sizeof(sb->sb_lsn); + size = offsetofend(struct xfs_dsb, sb_lsn); else if (xfs_sb_version_hasmorebits(sb)) - size = offsetof(struct xfs_dsb, sb_bad_features2) - + sizeof(sb->sb_bad_features2); + size = offsetofend(struct xfs_dsb, sb_bad_features2); else if (xfs_sb_version_haslogv2(sb)) - size = offsetof(struct xfs_dsb, sb_logsunit) - + sizeof(sb->sb_logsunit); + size = offsetofend(struct xfs_dsb, sb_logsunit); else if (xfs_sb_version_hassector(sb)) - size = offsetof(struct xfs_dsb, sb_logsectsize) - + sizeof(sb->sb_logsectsize); + size = offsetofend(struct xfs_dsb, sb_logsectsize); else /* only support dirv2 or more recent */ - size = offsetof(struct xfs_dsb, sb_dirblklog) - + sizeof(sb->sb_dirblklog); + size = offsetofend(struct xfs_dsb, sb_dirblklog); /* Check the buffer we read from disk for garbage outside size */ for (ip = (char *)sbuf->b_addr + size; From patchwork Mon Dec 23 22:16:11 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: 13919387 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 7540AEAF6 for ; Mon, 23 Dec 2024 22:16: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=1734992172; cv=none; b=THPq56ICNivfVLXw51B7LuorQhLzaLfhDqvhBo75Cd2qzIpZJNPFrZJ6dkYDf4IHSxu2w1Jc+q6/mQiQ/kN0lfVkYzKdEle6fN+pH+0qZIgwXnb9c6OaLIaQP/VCVJDIWSgCO1FqQJx2H8VbZErq6cSczcqLBJaQAdCBxvaO4DI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992172; c=relaxed/simple; bh=IQEflgmwTkdS0n/TPlu0QU8zII4gFFZXGm64bqJhjR0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=H8XjyD2LjLqxGqETHvpaWHXbjgxlMqqS3fQ29HVx1/RIw0F9C4rpk/vyWGGGMFoUBMoZB4wIc8zWzW0wiJsIYv1Mir4a3Z2uN75unelhBM//mdwdgSntwbifJuKRiM3l7DRwY/Z7ZWyJzzRWSsyL5fyInuK/wWCz050xuUS7YQ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BIIjX/DA; 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="BIIjX/DA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFE87C4CED3; Mon, 23 Dec 2024 22:16:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992172; bh=IQEflgmwTkdS0n/TPlu0QU8zII4gFFZXGm64bqJhjR0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=BIIjX/DAfcgliWpsD5ffNOFb1hjdD9LJspFXCLHHL88U8ff8qYQ59zxgd/+W+pEW3 flsM6VvtxzlR6jtqFIMDB6VU3FGaoxPPaLMeg5bPnuZSxiIL3WO26zrKuuonENCisT K9+mmnHg6HSTdLLvp6RWXGuX8nmgdSNcgL/N+2+158RXLbYZZ5VdEuV5+edDSK90NZ RKFKA448JBM30AiQyrnJ2g1QEdBAHyXjqvGIc1Gj2MTH2FvTOwZ1p0cGn6EryyPGex bHuixb1S8cnLYo/ebxxNcRoiSrGnJl9Xz0EpFQsLM5lxtNApzYB/vcD9ntY0HyAuM+ zZDyN2LdIneqQ== Date: Mon, 23 Dec 2024 14:16:11 -0800 Subject: [PATCH 17/51] xfs_repair: improve rtbitmap discrepancy reporting From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944065.2297565.1047635748326194606.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Improve the reporting of discrepancies in the realtime bitmap and summary files by creating a separate helper function that will pinpoint the exact (word) locations of mismatches. This will help developers to diagnose problems with the rtgroups feature and users to figure out exactly what's bad in a filesystem. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- repair/rt.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/repair/rt.c b/repair/rt.c index 65d6a713f379d2..a3378ef1dd0af2 100644 --- a/repair/rt.c +++ b/repair/rt.c @@ -131,6 +131,44 @@ _("couldn't allocate memory for incore realtime summary info.\n")); } } +static void +check_rtwords( + struct xfs_mount *mp, + const char *filename, + unsigned long long bno, + void *ondisk, + void *incore) +{ + unsigned int wordcnt = mp->m_blockwsize; + union xfs_rtword_raw *o = ondisk, *i = incore; + int badstart = -1; + unsigned int j; + + if (memcmp(ondisk, incore, wordcnt << XFS_WORDLOG) == 0) + return; + + for (j = 0; j < wordcnt; j++, o++, i++) { + if (o->old == i->old) { + /* Report a range of inconsistency that just ended. */ + if (badstart >= 0) + do_warn( + _("discrepancy in %s at dblock 0x%llx words 0x%x-0x%x/0x%x\n"), + filename, bno, badstart, j - 1, wordcnt); + badstart = -1; + continue; + } + + if (badstart == -1) + badstart = j; + } + + if (badstart >= 0) + do_warn( + _("discrepancy in %s at dblock 0x%llx words 0x%x-0x%x/0x%x\n"), + filename, bno, badstart, wordcnt, + wordcnt); +} + static void check_rtfile_contents( struct xfs_mount *mp, @@ -203,9 +241,7 @@ check_rtfile_contents( break; } - if (memcmp(bp->b_addr, buf, mp->m_blockwsize << XFS_WORDLOG)) - do_warn(_("discrepancy in %s at dblock 0x%llx\n"), - filename, (unsigned long long)bno); + check_rtwords(mp, filename, bno, bp->b_addr, buf); buf += XFS_FSB_TO_B(mp, map.br_blockcount); bno += map.br_blockcount; From patchwork Mon Dec 23 22:16: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: 13919388 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 2637F188596 for ; Mon, 23 Dec 2024 22:16:27 +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=1734992189; cv=none; b=LwModrY8Wdz8xKhXfFPEHVurwoIMqEs6DLNZGE4mnwD45qlOzu7jPV226B85bCVwqjHFmtPhj/5MUfsycjGTDpJH5fB5ht1T/0poksfV2TKzOaQiTieSo8eFKML2holbbScUZKflgiYWtY5Gu0ScqjQuwAPEJXISFX3wNOW9R5E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992189; c=relaxed/simple; bh=jxQnoZdK4wjGokTLSZ64zljYKGtQmXdGS/Dluj3pl7A=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=f+SZP89zELgULLZvetKnbcJ/pny8/7cokIvX4gXGlr5g9utIbOwc1XWhp5mIpKQqqmKzYxVZqXqMrEMI5XaQ0gkqHgMGfAeUh0ttkfj1/B1MqbL6T8jd2+G+C+HYK+XdavDI80QZvbYVUJSN2hO+M5bmESoDF2sYxp0i+4oMIDw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U2rn3y7n; 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="U2rn3y7n" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95F41C4CED3; Mon, 23 Dec 2024 22:16:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992187; bh=jxQnoZdK4wjGokTLSZ64zljYKGtQmXdGS/Dluj3pl7A=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=U2rn3y7nIuloZoh0ljZGBjISzblN6J8dtXRuPnbl33WcR0ipwK3yAGfbU3tEQoxPz 6GmUdbMhDKbjsMdTi+sT1mn4h41H8xeKyg29Erv6TNsoF22O7XlGjdVVeQLFvMgUrp bcSjegETiiifH04/bdKsIeApkgPQc7mOVj595gB6vBbi7EnmwZKwZsLiPV/kD7Us4W 0BJWK1VsnRHJHLTxOOFGsjjiesXesoZoub3VX/TWq/tpjVZdGrblEc4fYH8vlTQPv+ GF/j/edaZQIa2/XJq5UFyrj4HvtElu0qa5t92U11K03e7nhNOig3hf6BBDhnMBlOPU Per3PRngN0rMA== Date: Mon, 23 Dec 2024 14:16:27 -0800 Subject: [PATCH 18/51] xfs_repair: simplify rt_lock handling From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944080.2297565.1420503238702137131.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig No need to cacheline align rt_lock if we move it next to the data it protects. Also reduce the critical section to just where those data structures are accessed. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- repair/dinode.c | 6 +++--- repair/globals.c | 1 - repair/globals.h | 2 +- repair/incore.c | 8 ++++---- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/repair/dinode.c b/repair/dinode.c index 56c7257d3766f1..8c593da545cd7f 100644 --- a/repair/dinode.c +++ b/repair/dinode.c @@ -304,7 +304,7 @@ process_rt_rec( bool zap_metadata) { xfs_fsblock_t lastb; - int bad; + int bad = 0; /* * check numeric validity of the extent @@ -338,10 +338,12 @@ _("inode %" PRIu64 " - bad rt extent overflows - start %" PRIu64 ", " return 1; } + pthread_mutex_lock(&rt_lock); if (check_dups) bad = process_rt_rec_dups(mp, ino, irec); else bad = process_rt_rec_state(mp, ino, zap_metadata, irec); + pthread_mutex_unlock(&rt_lock); if (bad) return bad; @@ -451,10 +453,8 @@ _("zero length extent (off = %" PRIu64 ", fsbno = %" PRIu64 ") in ino %" PRIu64 } if (type == XR_INO_RTDATA && whichfork == XFS_DATA_FORK) { - pthread_mutex_lock(&rt_lock.lock); error2 = process_rt_rec(mp, &irec, ino, tot, check_dups, zap_metadata); - pthread_mutex_unlock(&rt_lock.lock); if (error2) return error2; diff --git a/repair/globals.c b/repair/globals.c index bd07a9656d193b..d97e2a8d2d6d9b 100644 --- a/repair/globals.c +++ b/repair/globals.c @@ -112,7 +112,6 @@ uint32_t sb_unit; uint32_t sb_width; struct aglock *ag_locks; -struct aglock rt_lock; time_t report_interval; uint64_t *prog_rpt_done; diff --git a/repair/globals.h b/repair/globals.h index ebe8d5ee132b8d..db8afabd9f0fc9 100644 --- a/repair/globals.h +++ b/repair/globals.h @@ -156,7 +156,7 @@ struct aglock { pthread_mutex_t lock __attribute__((__aligned__(64))); }; extern struct aglock *ag_locks; -extern struct aglock rt_lock; +extern pthread_mutex_t rt_lock; extern time_t report_interval; extern uint64_t *prog_rpt_done; diff --git a/repair/incore.c b/repair/incore.c index 06edaf0d605262..21f5b05d3e93e4 100644 --- a/repair/incore.c +++ b/repair/incore.c @@ -166,6 +166,7 @@ get_bmap_ext( static uint64_t *rt_bmap; static size_t rt_bmap_size; +pthread_mutex_t rt_lock; /* block records fit into uint64_t's units */ #define XR_BB_UNIT 64 /* number of bits/unit */ @@ -209,6 +210,7 @@ init_rt_bmap( if (mp->m_sb.sb_rextents == 0) return; + pthread_mutex_init(&rt_lock, NULL); rt_bmap_size = roundup(howmany(mp->m_sb.sb_rextents, (NBBY / XR_BB)), sizeof(uint64_t)); @@ -226,8 +228,9 @@ free_rt_bmap(xfs_mount_t *mp) { free(rt_bmap); rt_bmap = NULL; -} + pthread_mutex_destroy(&rt_lock); +} void reset_bmaps(xfs_mount_t *mp) @@ -290,7 +293,6 @@ init_bmaps(xfs_mount_t *mp) btree_init(&ag_bmap[i]); pthread_mutex_init(&ag_locks[i].lock, NULL); } - pthread_mutex_init(&rt_lock.lock, NULL); init_rt_bmap(mp); reset_bmaps(mp); @@ -301,8 +303,6 @@ free_bmaps(xfs_mount_t *mp) { xfs_agnumber_t i; - pthread_mutex_destroy(&rt_lock.lock); - for (i = 0; i < mp->m_sb.sb_agcount; i++) pthread_mutex_destroy(&ag_locks[i].lock); From patchwork Mon Dec 23 22:16:42 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: 13919389 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 61D08EAF6 for ; Mon, 23 Dec 2024 22:16:43 +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=1734992203; cv=none; b=eiKGiRM3ipAvEPJBPHlTMi9cfsKrw1rLECMbhosfplZTlQ+IQ5vz+SgTJDrrhoM/YXsRPP7ADXJsbmJ6caL70AM7cNA2La1eZ4Sn8KUpifnaUoAm2EeFMxCm0VJ4LIw0HSbNZemzlQ5iUXhzyEaG+4XxSNTg0jp1YL1C72sTZ4A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992203; c=relaxed/simple; bh=8hWf2bt511VOpxcND/I7ulOgQ17rJSwgkRSg5oAMH3Q=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KvLB0O5KSYVFv+ewprEZ1spM320Ydp6Z80RsiyBUyz4NmRY/JN3DW5K97ebm10RQ8V99vNNTS3zooOynVKCOtLpYR/xr6chLIyAbjNQD+t4NsEDemHNiDUVMwwczJc+FPyUeTxQpyFk8C3ITF7sosOqpU1fP5aTkIYLs32GbjFc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nD4wvKw/; 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="nD4wvKw/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40C53C4CED3; Mon, 23 Dec 2024 22:16:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992203; bh=8hWf2bt511VOpxcND/I7ulOgQ17rJSwgkRSg5oAMH3Q=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=nD4wvKw/W0DNy0A/oOW8tZu9nF176uULMTXvm2T4ytb0oZ0E6zHkiKsMIE45h8xDS GgDJklhD/xCI8lrvUcz8frJKMi/bnbl3+a8DwfACQYBPvl7fyRTggpi/B5jXwCuQeA UNGYWxTsrMnxo9mVyg/YfDnVYsKnUuKCu0BgLs6v6wNYEyQN4z1fwc7waZSRWiNHL+ o0GysvtTSQKaxn1kbCidj3NmVYmZ/uDDTq8/DdO8w7OG2Z/ybTHtmvmurDLgPUejyr dmCOltyBnqSaquTjnxG1Pepj5pOBTWQDjhwVNt/NZ4TOwrz97XF0uYUfOOB04tAVrQ /bczmRXbm8mjA== Date: Mon, 23 Dec 2024 14:16:42 -0800 Subject: [PATCH 19/51] xfs_repair: add a real per-AG bitmap abstraction From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944095.2297565.9573944456076533840.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Add a struct bmap that contains the btree root and the lock, and provide helpers for loking instead of directly poking into the data structure. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- repair/dino_chunks.c | 23 +++++----- repair/dinode.c | 6 +-- repair/globals.c | 2 - repair/globals.h | 4 -- repair/incore.c | 114 ++++++++++++++++++++++++++++++++------------------ repair/incore.h | 3 + repair/rmap.c | 4 +- repair/scan.c | 8 ++-- 8 files changed, 97 insertions(+), 67 deletions(-) diff --git a/repair/dino_chunks.c b/repair/dino_chunks.c index 0cbc498101ec72..3c650dac8a4d8e 100644 --- a/repair/dino_chunks.c +++ b/repair/dino_chunks.c @@ -132,7 +132,7 @@ verify_inode_chunk(xfs_mount_t *mp, if (check_aginode_block(mp, agno, agino) == 0) return 0; - pthread_mutex_lock(&ag_locks[agno].lock); + lock_ag(agno); state = get_bmap(agno, agbno); switch (state) { @@ -167,8 +167,8 @@ verify_inode_chunk(xfs_mount_t *mp, _("inode block %d/%d multiply claimed, (state %d)\n"), agno, agbno, state); set_bmap(agno, agbno, XR_E_MULT); - pthread_mutex_unlock(&ag_locks[agno].lock); - return(0); + unlock_ag(agno); + return 0; default: do_warn( _("inode block %d/%d bad state, (state %d)\n"), @@ -177,7 +177,7 @@ verify_inode_chunk(xfs_mount_t *mp, break; } - pthread_mutex_unlock(&ag_locks[agno].lock); + unlock_ag(agno); start_agino = XFS_AGB_TO_AGINO(mp, agbno); *start_ino = XFS_AGINO_TO_INO(mp, agno, start_agino); @@ -424,7 +424,7 @@ verify_inode_chunk(xfs_mount_t *mp, * user data -- we're probably here as a result of a directory * entry or an iunlinked pointer */ - pthread_mutex_lock(&ag_locks[agno].lock); + lock_ag(agno); for (cur_agbno = chunk_start_agbno; cur_agbno < chunk_stop_agbno; cur_agbno += blen) { @@ -438,7 +438,7 @@ verify_inode_chunk(xfs_mount_t *mp, _("inode block %d/%d multiply claimed, (state %d)\n"), agno, cur_agbno, state); set_bmap_ext(agno, cur_agbno, blen, XR_E_MULT); - pthread_mutex_unlock(&ag_locks[agno].lock); + unlock_ag(agno); return 0; case XR_E_METADATA: case XR_E_INO: @@ -450,7 +450,7 @@ verify_inode_chunk(xfs_mount_t *mp, break; } } - pthread_mutex_unlock(&ag_locks[agno].lock); + unlock_ag(agno); /* * ok, chunk is good. put the record into the tree if required, @@ -473,8 +473,7 @@ verify_inode_chunk(xfs_mount_t *mp, set_inode_used(irec_p, agino - start_agino); - pthread_mutex_lock(&ag_locks[agno].lock); - + lock_ag(agno); for (cur_agbno = chunk_start_agbno; cur_agbno < chunk_stop_agbno; cur_agbno += blen) { @@ -516,7 +515,7 @@ verify_inode_chunk(xfs_mount_t *mp, break; } } - pthread_mutex_unlock(&ag_locks[agno].lock); + unlock_ag(agno); return(ino_cnt); } @@ -575,7 +574,7 @@ process_inode_agbno_state( { int state; - pthread_mutex_lock(&ag_locks[agno].lock); + lock_ag(agno); state = get_bmap(agno, agbno); switch (state) { case XR_E_INO: /* already marked */ @@ -605,7 +604,7 @@ process_inode_agbno_state( XFS_AGB_TO_FSB(mp, agno, agbno), state); break; } - pthread_mutex_unlock(&ag_locks[agno].lock); + unlock_ag(agno); } /* diff --git a/repair/dinode.c b/repair/dinode.c index 8c593da545cd7f..916aadc782248f 100644 --- a/repair/dinode.c +++ b/repair/dinode.c @@ -540,9 +540,9 @@ _("Fatal error: inode %" PRIu64 " - blkmap_set_ext(): %s\n" ebno = agbno + irec.br_blockcount; if (agno != locked_agno) { if (locked_agno != -1) - pthread_mutex_unlock(&ag_locks[locked_agno].lock); - pthread_mutex_lock(&ag_locks[agno].lock); + unlock_ag(locked_agno); locked_agno = agno; + lock_ag(locked_agno); } for (b = irec.br_startblock; @@ -663,7 +663,7 @@ _("illegal state %d in block map %" PRIu64 "\n"), error = 0; done: if (locked_agno != -1) - pthread_mutex_unlock(&ag_locks[locked_agno].lock); + unlock_ag(locked_agno); if (i != *numrecs) { ASSERT(i < *numrecs); diff --git a/repair/globals.c b/repair/globals.c index d97e2a8d2d6d9b..30995f5298d5a1 100644 --- a/repair/globals.c +++ b/repair/globals.c @@ -111,8 +111,6 @@ xfs_extlen_t sb_inoalignmt; uint32_t sb_unit; uint32_t sb_width; -struct aglock *ag_locks; - time_t report_interval; uint64_t *prog_rpt_done; diff --git a/repair/globals.h b/repair/globals.h index db8afabd9f0fc9..7c2d9c56c8f8a7 100644 --- a/repair/globals.h +++ b/repair/globals.h @@ -152,10 +152,6 @@ extern xfs_extlen_t sb_inoalignmt; extern uint32_t sb_unit; extern uint32_t sb_width; -struct aglock { - pthread_mutex_t lock __attribute__((__aligned__(64))); -}; -extern struct aglock *ag_locks; extern pthread_mutex_t rt_lock; extern time_t report_interval; diff --git a/repair/incore.c b/repair/incore.c index 21f5b05d3e93e4..fb9ebee1671d4f 100644 --- a/repair/incore.c +++ b/repair/incore.c @@ -24,7 +24,25 @@ static int states[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; -static struct btree_root **ag_bmap; +struct bmap { + pthread_mutex_t lock __attribute__((__aligned__(64))); + struct btree_root *root; +}; +static struct bmap *ag_bmaps; + +void +lock_ag( + xfs_agnumber_t agno) +{ + pthread_mutex_lock(&ag_bmaps[agno].lock); +} + +void +unlock_ag( + xfs_agnumber_t agno) +{ + pthread_mutex_unlock(&ag_bmaps[agno].lock); +} static void update_bmap( @@ -129,7 +147,7 @@ set_bmap_ext( xfs_extlen_t blen, int state) { - update_bmap(ag_bmap[agno], agbno, blen, &states[state]); + update_bmap(ag_bmaps[agno].root, agbno, blen, &states[state]); } int @@ -139,23 +157,24 @@ get_bmap_ext( xfs_agblock_t maxbno, xfs_extlen_t *blen) { + struct btree_root *bmap = ag_bmaps[agno].root; int *statep; unsigned long key; - statep = btree_find(ag_bmap[agno], agbno, &key); + statep = btree_find(bmap, agbno, &key); if (!statep) return -1; if (key == agbno) { if (blen) { - if (!btree_peek_next(ag_bmap[agno], &key)) + if (!btree_peek_next(bmap, &key)) return -1; *blen = min(maxbno, key) - agbno; } return *statep; } - statep = btree_peek_prev(ag_bmap[agno], NULL); + statep = btree_peek_prev(bmap, NULL); if (!statep) return -1; if (blen) @@ -243,13 +262,15 @@ reset_bmaps(xfs_mount_t *mp) ag_size = mp->m_sb.sb_agblocks; for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) { + struct btree_root *bmap = ag_bmaps[agno].root; + if (agno == mp->m_sb.sb_agcount - 1) ag_size = (xfs_extlen_t)(mp->m_sb.sb_dblocks - (xfs_rfsblock_t)mp->m_sb.sb_agblocks * agno); #ifdef BTREE_STATS - if (btree_find(ag_bmap[agno], 0, NULL)) { + if (btree_find(bmap, 0, NULL)) { printf("ag_bmap[%d] btree stats:\n", i); - btree_print_stats(ag_bmap[agno], stdout); + btree_print_stats(bmap, stdout); } #endif /* @@ -260,11 +281,10 @@ reset_bmaps(xfs_mount_t *mp) * ag_hdr_block..ag_size: XR_E_UNKNOWN * ag_size... XR_E_BAD_STATE */ - btree_clear(ag_bmap[agno]); - btree_insert(ag_bmap[agno], 0, &states[XR_E_INUSE_FS]); - btree_insert(ag_bmap[agno], - ag_hdr_block, &states[XR_E_UNKNOWN]); - btree_insert(ag_bmap[agno], ag_size, &states[XR_E_BAD_STATE]); + btree_clear(bmap); + btree_insert(bmap, 0, &states[XR_E_INUSE_FS]); + btree_insert(bmap, ag_hdr_block, &states[XR_E_UNKNOWN]); + btree_insert(bmap, ag_size, &states[XR_E_BAD_STATE]); } if (mp->m_sb.sb_logstart != 0) { @@ -276,44 +296,58 @@ reset_bmaps(xfs_mount_t *mp) reset_rt_bmap(); } +static struct bmap * +alloc_bmaps( + unsigned int nr_groups) +{ + struct bmap *bmap; + unsigned int i; + + bmap = calloc(nr_groups, sizeof(*bmap)); + if (!bmap) + return NULL; + + for (i = 0; i < nr_groups; i++) { + btree_init(&bmap[i].root); + pthread_mutex_init(&bmap[i].lock, NULL); + } + + return bmap; +} + +static void +destroy_bmaps( + struct bmap *bmap, + unsigned int nr_groups) +{ + unsigned int i; + + for (i = 0; i < nr_groups; i++) { + btree_destroy(bmap[i].root); + pthread_mutex_destroy(&bmap[i].lock); + } + + free(bmap); +} + void -init_bmaps(xfs_mount_t *mp) +init_bmaps( + struct xfs_mount *mp) { - xfs_agnumber_t i; - - ag_bmap = calloc(mp->m_sb.sb_agcount, sizeof(struct btree_root *)); - if (!ag_bmap) + ag_bmaps = alloc_bmaps(mp->m_sb.sb_agcount + mp->m_sb.sb_rgcount); + if (!ag_bmaps) do_error(_("couldn't allocate block map btree roots\n")); - ag_locks = calloc(mp->m_sb.sb_agcount, sizeof(struct aglock)); - if (!ag_locks) - do_error(_("couldn't allocate block map locks\n")); - - for (i = 0; i < mp->m_sb.sb_agcount; i++) { - btree_init(&ag_bmap[i]); - pthread_mutex_init(&ag_locks[i].lock, NULL); - } - init_rt_bmap(mp); reset_bmaps(mp); } void -free_bmaps(xfs_mount_t *mp) +free_bmaps( + struct xfs_mount *mp) { - xfs_agnumber_t i; - - for (i = 0; i < mp->m_sb.sb_agcount; i++) - pthread_mutex_destroy(&ag_locks[i].lock); - - free(ag_locks); - ag_locks = NULL; - - for (i = 0; i < mp->m_sb.sb_agcount; i++) - btree_destroy(ag_bmap[i]); - - free(ag_bmap); - ag_bmap = NULL; + destroy_bmaps(ag_bmaps, mp->m_sb.sb_agcount + mp->m_sb.sb_rgcount); + ag_bmaps = NULL; free_rt_bmap(mp); } diff --git a/repair/incore.h b/repair/incore.h index 07716fc4c01a05..8385043580637f 100644 --- a/repair/incore.h +++ b/repair/incore.h @@ -23,6 +23,9 @@ void init_bmaps(xfs_mount_t *mp); void reset_bmaps(xfs_mount_t *mp); void free_bmaps(xfs_mount_t *mp); +void lock_ag(xfs_agnumber_t agno); +void unlock_ag(xfs_agnumber_t agno); + void set_bmap_ext(xfs_agnumber_t agno, xfs_agblock_t agbno, xfs_extlen_t blen, int state); int get_bmap_ext(xfs_agnumber_t agno, xfs_agblock_t agbno, diff --git a/repair/rmap.c b/repair/rmap.c index 3b998a22cee10d..1c6a8691b8cb2c 100644 --- a/repair/rmap.c +++ b/repair/rmap.c @@ -761,12 +761,12 @@ mark_reflink_inodes( agno = XFS_INO_TO_AGNO(mp, rciter.ino); agino = XFS_INO_TO_AGINO(mp, rciter.ino); - pthread_mutex_lock(&ag_locks[agno].lock); + lock_ag(agno); irec = find_inode_rec(mp, agno, agino); off = get_inode_offset(mp, rciter.ino, irec); /* lock here because we might go outside this ag */ set_inode_is_rl(irec, off); - pthread_mutex_unlock(&ag_locks[agno].lock); + unlock_ag(agno); } rcbag_ino_iter_stop(rcstack, &rciter); } diff --git a/repair/scan.c b/repair/scan.c index ed73de4b2477bf..8b118423ce0457 100644 --- a/repair/scan.c +++ b/repair/scan.c @@ -340,7 +340,7 @@ _("bad back (left) sibling pointer (saw %llu should be NULL (0))\n" agno = XFS_FSB_TO_AGNO(mp, bno); agbno = XFS_FSB_TO_AGBNO(mp, bno); - pthread_mutex_lock(&ag_locks[agno].lock); + lock_ag(agno); state = get_bmap(agno, agbno); switch (state) { case XR_E_INUSE1: @@ -407,7 +407,7 @@ _("bad state %d, inode %" PRIu64 " bmap block 0x%" PRIx64 "\n"), state, ino, bno); break; } - pthread_mutex_unlock(&ag_locks[agno].lock); + unlock_ag(agno); } else { if (search_dup_extent(XFS_FSB_TO_AGNO(mp, bno), XFS_FSB_TO_AGBNO(mp, bno), @@ -420,9 +420,9 @@ _("bad state %d, inode %" PRIu64 " bmap block 0x%" PRIx64 "\n"), /* Record BMBT blocks in the reverse-mapping data. */ if (check_dups && collect_rmaps && !zap_metadata) { agno = XFS_FSB_TO_AGNO(mp, bno); - pthread_mutex_lock(&ag_locks[agno].lock); + lock_ag(agno); rmap_add_bmbt_rec(mp, ino, whichfork, bno); - pthread_mutex_unlock(&ag_locks[agno].lock); + unlock_ag(agno); } if (level == 0) { From patchwork Mon Dec 23 22:16:58 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: 13919390 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 0F823EAF6 for ; Mon, 23 Dec 2024 22:16: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=1734992219; cv=none; b=Gf2R3Te8CUyVDmadjOSv44AAL1N1uE6H17ERcI+FwkRs9SSbKO46nPtG5iha7OQCmWaKLJYIR+hAW7ukj0eYL+Ef9JvIldMWUX/iupAqkxxzW3K4HScDjoJLdUCLpYZUwli+c6WISbeknzeJ6bT2yIr9/c/Xfx0BSAvRaHX7Y0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992219; c=relaxed/simple; bh=1YEnhUQ0GoayUilXWvb9H4c546j1UM1vxSOKWs/0bG4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aM1lnsMjWFHlFi+Y+jIq2fR4uYxCqfrXhEUYD8/DmPvZbqkZCBsdSBFfNMFDmVtsGJ9vb6XDMfAeD53tBbyJpN5KMjJc9NHDCb6E/6bSLcUGEU+cwyNWeJyHcyaPArrnKc1fFtEesV36zSmOmc/zM+b8+8OkFuO609ex+gEACcA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CViVA85A; 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="CViVA85A" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA63AC4CED3; Mon, 23 Dec 2024 22:16:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992218; bh=1YEnhUQ0GoayUilXWvb9H4c546j1UM1vxSOKWs/0bG4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=CViVA85ASRy5tq+9pqnRxeP5AjfyGkbyEuOaDrNdZ7qaSO4F1/zHllRYWrdHV0nnU aXJf2OqMEiQsdTmsOecL/ikq+otU2M4thKFGl9O+MrOWneGDenOo4iJs+1UkIM4vZY z6UF0+CsnBH2Xu5WZkZmUigKxnjZ3wKZzMYEYIb/z+WT0+2eLDrjVUZScXPbXg5801 0F972SHO/lw48USl0TEFXbuZI1dmkafNhFVL98fYisIXn4uH/iEoGJnMkRWgu9xP1c 3bJmxGV9+g2VKPM/a8rAkGxeFdihgzyxzOhWdMXFyyLITKfpRsXJJjM2Fjh0djDLZi 083nJEOhUFplQ== Date: Mon, 23 Dec 2024 14:16:58 -0800 Subject: [PATCH 20/51] xfs_repair: support realtime groups From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944111.2297565.2501521918509370454.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Make repair aware of multiple rtgroups. This now uses the same code as the AG-based data device for block usage tracking instead of the less optimal AVL trees and bitmaps used for the traditonal RT device. This is done by introducing similar per-rtgroup space tracking structures as we have for the AGs. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: "Darrick J. Wong" --- libxfs/libxfs_api_defs.h | 2 repair/agheader.c | 8 - repair/agheader.h | 10 + repair/dino_chunks.c | 12 + repair/dinode.c | 116 +++++++++---- repair/dir2.c | 13 + repair/incore.c | 125 ++++++++++---- repair/incore.h | 37 +++- repair/incore_ext.c | 3 repair/phase2.c | 51 +++--- repair/phase4.c | 27 +++ repair/phase5.c | 2 repair/phase6.c | 172 +++++++++++++++++++- repair/rt.c | 403 ++++++++++++++++++++++++++++++++++++++-------- repair/rt.h | 20 ++ repair/sb.c | 41 +++++ repair/scan.c | 28 ++- repair/xfs_repair.c | 15 +- 18 files changed, 864 insertions(+), 221 deletions(-) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 50da547f8f21d4..84965106358d61 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -108,6 +108,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_compute_rgblklog libxfs_compute_rgblklog #define xfs_create_space_res libxfs_create_space_res #define xfs_da3_node_hdr_from_disk libxfs_da3_node_hdr_from_disk #define xfs_da3_node_read libxfs_da3_node_read @@ -288,6 +289,7 @@ #define xfs_rtsummary_create libxfs_rtsummary_create #define xfs_rtgroup_alloc libxfs_rtgroup_alloc +#define xfs_rtgroup_extents libxfs_rtgroup_extents #define xfs_rtgroup_grab libxfs_rtgroup_grab #define xfs_rtgroup_rele libxfs_rtgroup_rele diff --git a/repair/agheader.c b/repair/agheader.c index 14aedece3d07b0..fd279559aed973 100644 --- a/repair/agheader.c +++ b/repair/agheader.c @@ -319,12 +319,6 @@ check_v5_feature_mismatch( return XR_AG_SB_SEC; } -static inline bool xfs_sb_version_hasmetadir(const struct xfs_sb *sbp) -{ - return xfs_sb_is_v5(sbp) && - (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_METADIR); -} - /* * Possible fields that may have been set at mkfs time, * sb_inoalignmt, sb_unit, sb_width and sb_dirblklog. @@ -364,7 +358,7 @@ secondary_sb_whack( * size is the size of data which is valid for this sb. */ if (xfs_sb_version_hasmetadir(sb)) - size = offsetofend(struct xfs_dsb, sb_metadirino); + size = offsetofend(struct xfs_dsb, sb_pad); else if (xfs_sb_version_hasmetauuid(sb)) size = offsetofend(struct xfs_dsb, sb_meta_uuid); else if (xfs_sb_version_hascrc(sb)) diff --git a/repair/agheader.h b/repair/agheader.h index b4f81d5537906d..c81147b6607d2b 100644 --- a/repair/agheader.h +++ b/repair/agheader.h @@ -3,6 +3,8 @@ * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc. * All Rights Reserved. */ +#ifndef __XFS_REPAIR_AGHEADER_H__ +#define __XFS_REPAIR_AGHEADER_H__ typedef struct fs_geometry { /* @@ -82,3 +84,11 @@ typedef struct fs_geo_list { #define XR_AG_AGF 0x2 #define XR_AG_AGI 0x4 #define XR_AG_SB_SEC 0x8 + +static inline bool xfs_sb_version_hasmetadir(const struct xfs_sb *sbp) +{ + return xfs_sb_is_v5(sbp) && + (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_METADIR); +} + +#endif /* __XFS_REPAIR_AGHEADER_H__ */ diff --git a/repair/dino_chunks.c b/repair/dino_chunks.c index 3c650dac8a4d8e..8935cf856e70c8 100644 --- a/repair/dino_chunks.c +++ b/repair/dino_chunks.c @@ -428,7 +428,8 @@ verify_inode_chunk(xfs_mount_t *mp, for (cur_agbno = chunk_start_agbno; cur_agbno < chunk_stop_agbno; cur_agbno += blen) { - state = get_bmap_ext(agno, cur_agbno, chunk_stop_agbno, &blen); + state = get_bmap_ext(agno, cur_agbno, chunk_stop_agbno, &blen, + false); switch (state) { case XR_E_MULT: case XR_E_INUSE: @@ -437,7 +438,7 @@ verify_inode_chunk(xfs_mount_t *mp, do_warn( _("inode block %d/%d multiply claimed, (state %d)\n"), agno, cur_agbno, state); - set_bmap_ext(agno, cur_agbno, blen, XR_E_MULT); + set_bmap_ext(agno, cur_agbno, blen, XR_E_MULT, false); unlock_ag(agno); return 0; case XR_E_METADATA: @@ -477,7 +478,8 @@ verify_inode_chunk(xfs_mount_t *mp, for (cur_agbno = chunk_start_agbno; cur_agbno < chunk_stop_agbno; cur_agbno += blen) { - state = get_bmap_ext(agno, cur_agbno, chunk_stop_agbno, &blen); + state = get_bmap_ext(agno, cur_agbno, chunk_stop_agbno, &blen, + false); switch (state) { case XR_E_INO: do_error( @@ -497,7 +499,7 @@ verify_inode_chunk(xfs_mount_t *mp, case XR_E_UNKNOWN: case XR_E_FREE1: case XR_E_FREE: - set_bmap_ext(agno, cur_agbno, blen, XR_E_INO); + set_bmap_ext(agno, cur_agbno, blen, XR_E_INO, false); break; case XR_E_MULT: case XR_E_INUSE: @@ -511,7 +513,7 @@ verify_inode_chunk(xfs_mount_t *mp, do_warn( _("inode block %d/%d bad state, (state %d)\n"), agno, cur_agbno, state); - set_bmap_ext(agno, cur_agbno, blen, XR_E_INO); + set_bmap_ext(agno, cur_agbno, blen, XR_E_INO, false); break; } } diff --git a/repair/dinode.c b/repair/dinode.c index 916aadc782248f..0a9059db9302a3 100644 --- a/repair/dinode.c +++ b/repair/dinode.c @@ -21,6 +21,7 @@ #include "slab.h" #include "rmap.h" #include "bmap_repair.h" +#include "rt.h" /* * gettext lookups for translations of strings use mutexes internally to @@ -171,20 +172,33 @@ clear_dinode(xfs_mount_t *mp, struct xfs_dinode *dino, xfs_ino_t ino_num) static __inline int verify_dfsbno_range( struct xfs_mount *mp, - xfs_fsblock_t fsbno, - xfs_filblks_t count) + struct xfs_bmbt_irec *irec, + bool isrt) { + xfs_fsblock_t end = + irec->br_startblock + irec->br_blockcount - 1; + /* the start and end blocks better be in the same allocation group */ - if (XFS_FSB_TO_AGNO(mp, fsbno) != - XFS_FSB_TO_AGNO(mp, fsbno + count - 1)) { - return XR_DFSBNORANGE_OVERFLOW; + if (isrt) { + if (xfs_rtb_to_rgno(mp, irec->br_startblock) != + xfs_rtb_to_rgno(mp, end)) + return XR_DFSBNORANGE_OVERFLOW; + + if (!libxfs_verify_rtbno(mp, irec->br_startblock)) + return XR_DFSBNORANGE_BADSTART; + if (!libxfs_verify_rtbno(mp, end)) + return XR_DFSBNORANGE_BADEND; + } else { + if (XFS_FSB_TO_AGNO(mp, irec->br_startblock) != + XFS_FSB_TO_AGNO(mp, end)) + return XR_DFSBNORANGE_OVERFLOW; + + if (!libxfs_verify_fsbno(mp, irec->br_startblock)) + return XR_DFSBNORANGE_BADSTART; + if (!libxfs_verify_fsbno(mp, end)) + return XR_DFSBNORANGE_BADEND; } - if (!libxfs_verify_fsbno(mp, fsbno)) - return XR_DFSBNORANGE_BADSTART; - if (!libxfs_verify_fsbno(mp, fsbno + count - 1)) - return XR_DFSBNORANGE_BADEND; - return XR_DFSBNORANGE_VALID; } @@ -387,17 +401,21 @@ process_bmbt_reclist_int( xfs_extnum_t i; int state; xfs_agnumber_t agno; - xfs_agblock_t agbno; + xfs_agblock_t agbno, first_agbno; xfs_agblock_t ebno; xfs_extlen_t blen; xfs_agnumber_t locked_agno = -1; int error = 1; int error2; + bool isrt = false; - if (type == XR_INO_RTDATA) + if (type == XR_INO_RTDATA) { + if (whichfork == XFS_DATA_FORK) + isrt = true; ftype = ftype_real_time; - else + } else { ftype = ftype_regular; + } for (i = 0; i < *numrecs; i++) { libxfs_bmbt_disk_get_all((rp +i), &irec); @@ -452,7 +470,7 @@ _("zero length extent (off = %" PRIu64 ", fsbno = %" PRIu64 ") in ino %" PRIu64 goto done; } - if (type == XR_INO_RTDATA && whichfork == XFS_DATA_FORK) { + if (isrt && !xfs_has_rtgroups(mp)) { error2 = process_rt_rec(mp, &irec, ino, tot, check_dups, zap_metadata); if (error2) @@ -468,8 +486,7 @@ _("zero length extent (off = %" PRIu64 ", fsbno = %" PRIu64 ") in ino %" PRIu64 /* * regular file data fork or attribute fork */ - switch (verify_dfsbno_range(mp, irec.br_startblock, - irec.br_blockcount)) { + switch (verify_dfsbno_range(mp, &irec, isrt)) { case XR_DFSBNORANGE_VALID: break; @@ -531,26 +548,39 @@ _("Fatal error: inode %" PRIu64 " - blkmap_set_ext(): %s\n" } } - /* - * Profiling shows that the following loop takes the - * most time in all of xfs_repair. - */ - agno = XFS_FSB_TO_AGNO(mp, irec.br_startblock); - agbno = XFS_FSB_TO_AGBNO(mp, irec.br_startblock); - ebno = agbno + irec.br_blockcount; + if (isrt) { + agno = xfs_rtb_to_rgno(mp, irec.br_startblock); + first_agbno = xfs_rtb_to_rgbno(mp, irec.br_startblock); + } else { + agno = XFS_FSB_TO_AGNO(mp, irec.br_startblock); + first_agbno = XFS_FSB_TO_AGBNO(mp, irec.br_startblock); + } + agbno = first_agbno; + ebno = first_agbno + irec.br_blockcount; if (agno != locked_agno) { if (locked_agno != -1) - unlock_ag(locked_agno); + unlock_group(locked_agno, isrt); locked_agno = agno; - lock_ag(locked_agno); + lock_group(locked_agno, isrt); } + /* + * Profiling shows that the following loop takes the most time + * in all of xfs_repair. + */ for (b = irec.br_startblock; agbno < ebno; b += blen, agbno += blen) { - state = get_bmap_ext(agno, agbno, ebno, &blen); + state = get_bmap_ext(agno, agbno, ebno, &blen, isrt); switch (state) { case XR_E_FREE: + /* + * We never do a scan pass of the rt bitmap, so unknown + * blocks are marked as free. + */ + if (isrt) + break; + fallthrough; case XR_E_FREE1: do_warn( _("%s fork in ino %" PRIu64 " claims free block %" PRIu64 "\n"), @@ -624,10 +654,10 @@ _("illegal state %d in block map %" PRIu64 "\n"), * After a successful rebuild we'll try this scan again. * (If the rebuild fails we won't come back here.) */ - agbno = XFS_FSB_TO_AGBNO(mp, irec.br_startblock); - ebno = agbno + irec.br_blockcount; + agbno = first_agbno; + ebno = first_agbno + irec.br_blockcount; for (; agbno < ebno; agbno += blen) { - state = get_bmap_ext(agno, agbno, ebno, &blen); + state = get_bmap_ext(agno, agbno, ebno, &blen, isrt); switch (state) { case XR_E_METADATA: /* @@ -642,15 +672,16 @@ _("illegal state %d in block map %" PRIu64 "\n"), case XR_E_FREE1: case XR_E_INUSE1: case XR_E_UNKNOWN: - set_bmap_ext(agno, agbno, blen, zap_metadata ? - XR_E_METADATA : XR_E_INUSE); + set_bmap_ext(agno, agbno, blen, + zap_metadata ? + XR_E_METADATA : XR_E_INUSE, isrt); break; case XR_E_INUSE: case XR_E_MULT: if (!zap_metadata) set_bmap_ext(agno, agbno, blen, - XR_E_MULT); + XR_E_MULT, isrt); break; default: break; @@ -663,7 +694,7 @@ _("illegal state %d in block map %" PRIu64 "\n"), error = 0; done: if (locked_agno != -1) - unlock_ag(locked_agno); + unlock_group(locked_agno, isrt); if (i != *numrecs) { ASSERT(i < *numrecs); @@ -1588,7 +1619,7 @@ check_dinode_mode_format( */ static int -process_check_sb_inodes( +process_check_metadata_inodes( xfs_mount_t *mp, struct xfs_dinode *dinoc, xfs_ino_t lino, @@ -1638,8 +1669,10 @@ process_check_sb_inodes( } return 0; } + dnextents = xfs_dfork_data_extents(dinoc); - if (lino == mp->m_sb.sb_rsumino) { + if (lino == mp->m_sb.sb_rsumino || + is_rtsummary_inode(lino)) { if (*type != XR_INO_RTSUM) { do_warn( _("realtime summary inode %" PRIu64 " has bad type 0x%x, "), @@ -1660,7 +1693,8 @@ _("bad # of extents (%" PRIu64 ") for realtime summary inode %" PRIu64 "\n"), } return 0; } - if (lino == mp->m_sb.sb_rbmino) { + if (lino == mp->m_sb.sb_rbmino || + is_rtbitmap_inode(lino)) { if (*type != XR_INO_RTBITMAP) { do_warn( _("realtime bitmap inode %" PRIu64 " has bad type 0x%x, "), @@ -2920,9 +2954,11 @@ _("bad (negative) size %" PRId64 " on inode %" PRIu64 "\n"), case S_IFREG: if (be16_to_cpu(dino->di_flags) & XFS_DIFLAG_REALTIME) type = XR_INO_RTDATA; - else if (lino == mp->m_sb.sb_rbmino) + else if (lino == mp->m_sb.sb_rbmino || + is_rtbitmap_inode(lino)) type = XR_INO_RTBITMAP; - else if (lino == mp->m_sb.sb_rsumino) + else if (lino == mp->m_sb.sb_rsumino || + is_rtsummary_inode(lino)) type = XR_INO_RTSUM; else if (lino == mp->m_sb.sb_uquotino) type = XR_INO_UQUOTA; @@ -2955,9 +2991,9 @@ _("bad (negative) size %" PRId64 " on inode %" PRIu64 "\n"), } /* - * type checks for superblock inodes + * type checks for metadata inodes */ - if (process_check_sb_inodes(mp, dino, lino, &type, dirty) != 0) + if (process_check_metadata_inodes(mp, dino, lino, &type, dirty) != 0) goto clear_bad_out; validate_extsize(mp, dino, lino, dirty); diff --git a/repair/dir2.c b/repair/dir2.c index d233c724488182..ca747c90175e93 100644 --- a/repair/dir2.c +++ b/repair/dir2.c @@ -15,6 +15,7 @@ #include "da_util.h" #include "prefetch.h" #include "progress.h" +#include "rt.h" /* * Known bad inode list. These are seen when the leaf and node @@ -256,10 +257,12 @@ process_sf_dir2( * bother checking if the child inode is free or not. */ junkit = 0; - } else if (lino == mp->m_sb.sb_rbmino) { + } else if (lino == mp->m_sb.sb_rbmino || + is_rtbitmap_inode(lino)) { junkit = 1; junkreason = _("realtime bitmap"); - } else if (lino == mp->m_sb.sb_rsumino) { + } else if (lino == mp->m_sb.sb_rsumino || + is_rtsummary_inode(lino)) { junkit = 1; junkreason = _("realtime summary"); } else if (lino == mp->m_sb.sb_uquotino) { @@ -737,9 +740,11 @@ process_dir2_data( * bother checking if the child inode is free or not. */ clearino = 0; - } else if (ent_ino == mp->m_sb.sb_rbmino) { + } else if (ent_ino == mp->m_sb.sb_rbmino || + is_rtbitmap_inode(ent_ino)) { clearreason = _("realtime bitmap"); - } else if (ent_ino == mp->m_sb.sb_rsumino) { + } else if (ent_ino == mp->m_sb.sb_rsumino || + is_rtsummary_inode(ent_ino)) { clearreason = _("realtime summary"); } else if (ent_ino == mp->m_sb.sb_uquotino) { clearreason = _("user quota"); diff --git a/repair/incore.c b/repair/incore.c index fb9ebee1671d4f..2339d49a95773d 100644 --- a/repair/incore.c +++ b/repair/incore.c @@ -29,28 +29,42 @@ struct bmap { struct btree_root *root; }; static struct bmap *ag_bmaps; +static struct bmap *rtg_bmaps; + +static inline struct bmap *bmap_for_group(xfs_agnumber_t gno, bool isrt) +{ + if (isrt) + return &rtg_bmaps[gno]; + return &ag_bmaps[gno]; +} void -lock_ag( - xfs_agnumber_t agno) +lock_group( + xfs_agnumber_t gno, + bool isrt) { - pthread_mutex_lock(&ag_bmaps[agno].lock); + pthread_mutex_lock(&bmap_for_group(gno, isrt)->lock); } void -unlock_ag( - xfs_agnumber_t agno) +unlock_group( + xfs_agnumber_t gno, + bool isrt) { - pthread_mutex_unlock(&ag_bmaps[agno].lock); + pthread_mutex_unlock(&bmap_for_group(gno, isrt)->lock); } -static void -update_bmap( - struct btree_root *bmap, - unsigned long offset, + +void +set_bmap_ext( + xfs_agnumber_t gno, + xfs_agblock_t offset, xfs_extlen_t blen, - void *new_state) + int state, + bool isrt) { + struct btree_root *bmap = bmap_for_group(gno, isrt)->root; + void *new_state = &states[state]; unsigned long end = offset + blen; int *cur_state; unsigned long cur_key; @@ -140,24 +154,15 @@ update_bmap( btree_insert(bmap, end, prev_state); } -void -set_bmap_ext( - xfs_agnumber_t agno, - xfs_agblock_t agbno, - xfs_extlen_t blen, - int state) -{ - update_bmap(ag_bmaps[agno].root, agbno, blen, &states[state]); -} - int get_bmap_ext( - xfs_agnumber_t agno, + xfs_agnumber_t gno, xfs_agblock_t agbno, xfs_agblock_t maxbno, - xfs_extlen_t *blen) + xfs_extlen_t *blen, + bool isrt) { - struct btree_root *bmap = ag_bmaps[agno].root; + struct btree_root *bmap = bmap_for_group(gno, isrt)->root; int *statep; unsigned long key; @@ -248,15 +253,15 @@ free_rt_bmap(xfs_mount_t *mp) free(rt_bmap); rt_bmap = NULL; pthread_mutex_destroy(&rt_lock); - } -void -reset_bmaps(xfs_mount_t *mp) +static void +reset_ag_bmaps( + struct xfs_mount *mp) { - xfs_agnumber_t agno; - xfs_agblock_t ag_size; - int ag_hdr_block; + int ag_hdr_block; + xfs_agnumber_t agno; + xfs_agblock_t ag_size; ag_hdr_block = howmany(4 * mp->m_sb.sb_sectsize, mp->m_sb.sb_blocksize); ag_size = mp->m_sb.sb_agblocks; @@ -286,14 +291,50 @@ reset_bmaps(xfs_mount_t *mp) btree_insert(bmap, ag_hdr_block, &states[XR_E_UNKNOWN]); btree_insert(bmap, ag_size, &states[XR_E_BAD_STATE]); } +} + +static void +reset_rtg_bmaps( + struct xfs_mount *mp) +{ + xfs_rgnumber_t rgno; + + for (rgno = 0 ; rgno < mp->m_sb.sb_rgcount; rgno++) { + struct btree_root *bmap = rtg_bmaps[rgno].root; + uint64_t rblocks; + + btree_clear(bmap); + if (rgno == 0 && xfs_has_rtsb(mp)) { + btree_insert(bmap, 0, &states[XR_E_INUSE_FS]); + btree_insert(bmap, mp->m_sb.sb_rextsize, + &states[XR_E_FREE]); + } else { + btree_insert(bmap, 0, &states[XR_E_FREE]); + } + + rblocks = xfs_rtbxlen_to_blen(mp, + libxfs_rtgroup_extents(mp, rgno)); + btree_insert(bmap, rblocks, &states[XR_E_BAD_STATE]); + } +} + +void +reset_bmaps( + struct xfs_mount *mp) +{ + reset_ag_bmaps(mp); if (mp->m_sb.sb_logstart != 0) { set_bmap_ext(XFS_FSB_TO_AGNO(mp, mp->m_sb.sb_logstart), XFS_FSB_TO_AGBNO(mp, mp->m_sb.sb_logstart), - mp->m_sb.sb_logblocks, XR_E_INUSE_FS); + mp->m_sb.sb_logblocks, XR_E_INUSE_FS, false); } - reset_rt_bmap(); + if (xfs_has_rtgroups(mp)) { + reset_rtg_bmaps(mp); + } else { + reset_rt_bmap(); + } } static struct bmap * @@ -334,11 +375,18 @@ void init_bmaps( struct xfs_mount *mp) { - ag_bmaps = alloc_bmaps(mp->m_sb.sb_agcount + mp->m_sb.sb_rgcount); + ag_bmaps = alloc_bmaps(mp->m_sb.sb_agcount); if (!ag_bmaps) do_error(_("couldn't allocate block map btree roots\n")); - init_rt_bmap(mp); + if (xfs_has_rtgroups(mp)) { + rtg_bmaps = alloc_bmaps(mp->m_sb.sb_rgcount); + if (!rtg_bmaps) + do_error(_("couldn't allocate block map btree roots\n")); + } else { + init_rt_bmap(mp); + } + reset_bmaps(mp); } @@ -346,8 +394,13 @@ void free_bmaps( struct xfs_mount *mp) { - destroy_bmaps(ag_bmaps, mp->m_sb.sb_agcount + mp->m_sb.sb_rgcount); + destroy_bmaps(ag_bmaps, mp->m_sb.sb_agcount); ag_bmaps = NULL; - free_rt_bmap(mp); + if (xfs_has_rtgroups(mp)) { + destroy_bmaps(rtg_bmaps, mp->m_sb.sb_rgcount); + rtg_bmaps = NULL; + } else { + free_rt_bmap(mp); + } } diff --git a/repair/incore.h b/repair/incore.h index 8385043580637f..61730c330911f7 100644 --- a/repair/incore.h +++ b/repair/incore.h @@ -23,29 +23,46 @@ void init_bmaps(xfs_mount_t *mp); void reset_bmaps(xfs_mount_t *mp); void free_bmaps(xfs_mount_t *mp); -void lock_ag(xfs_agnumber_t agno); -void unlock_ag(xfs_agnumber_t agno); +void lock_group(xfs_agnumber_t agno, bool isrt); +void unlock_group(xfs_agnumber_t agno, bool isrt); + +static inline void lock_ag(xfs_agnumber_t agno) +{ + lock_group(agno, false); +} + +static inline void unlock_ag(xfs_agnumber_t agno) +{ + unlock_group(agno, false); +} void set_bmap_ext(xfs_agnumber_t agno, xfs_agblock_t agbno, - xfs_extlen_t blen, int state); + xfs_extlen_t blen, int state, bool isrt); int get_bmap_ext(xfs_agnumber_t agno, xfs_agblock_t agbno, - xfs_agblock_t maxbno, xfs_extlen_t *blen); - -void set_rtbmap(xfs_rtxnum_t rtx, int state); -int get_rtbmap(xfs_rtxnum_t rtx); + xfs_agblock_t maxbno, xfs_extlen_t *blen, + bool isrt); static inline void set_bmap(xfs_agnumber_t agno, xfs_agblock_t agbno, int state) { - set_bmap_ext(agno, agbno, 1, state); + set_bmap_ext(agno, agbno, 1, state, false); } static inline int get_bmap(xfs_agnumber_t agno, xfs_agblock_t agbno) { - return get_bmap_ext(agno, agbno, agbno + 1, NULL); + return get_bmap_ext(agno, agbno, agbno + 1, NULL, false); } +static inline int +get_rgbmap(xfs_rgnumber_t rgno, xfs_rgblock_t rgbno) +{ + return get_bmap_ext(rgno, rgbno, rgbno + 1, NULL, true); +} + +void set_rtbmap(xfs_rtxnum_t rtx, int state); +int get_rtbmap(xfs_rtxnum_t rtx); + /* * extent tree definitions * right now, there are 3 trees per AG, a bno tree, a bcnt tree @@ -698,6 +715,8 @@ static inline unsigned int xfs_rootrec_inodes_inuse( struct xfs_mount *mp) { + if (xfs_has_rtgroups(mp)) + return 2; /* sb_rootino, sb_metadirino */ if (xfs_has_metadir(mp)) return 4; /* sb_rootino, sb_rbmino, sb_rsumino, sb_metadirino */ return 3; /* sb_rootino, sb_rbmino, sb_rsumino */ diff --git a/repair/incore_ext.c b/repair/incore_ext.c index 59c5d6f502c308..892f9d25588c11 100644 --- a/repair/incore_ext.c +++ b/repair/incore_ext.c @@ -593,7 +593,6 @@ release_rt_extent_tree() void free_rt_dup_extent_tree(xfs_mount_t *mp) { - ASSERT(mp->m_sb.sb_rblocks != 0); free(rt_ext_tree_ptr); rt_ext_tree_ptr = NULL; } @@ -726,8 +725,8 @@ static avl64ops_t avl64_extent_tree_ops = { void incore_ext_init(xfs_mount_t *mp) { - int i; xfs_agnumber_t agcount = mp->m_sb.sb_agcount; + int i; pthread_mutex_init(&rt_ext_tree_lock, NULL); diff --git a/repair/phase2.c b/repair/phase2.c index 476a1c74db8c8d..27c873fca76747 100644 --- a/repair/phase2.c +++ b/repair/phase2.c @@ -14,6 +14,7 @@ #include "incore.h" #include "progress.h" #include "scan.h" +#include "rt.h" /* workaround craziness in the xlog routines */ int xlog_recover_do_trans(struct xlog *log, struct xlog_recover *t, int p) @@ -544,16 +545,14 @@ phase2( struct xfs_sb *sb = &mp->m_sb; if (xfs_has_metadir(mp)) - ASSERT(sb->sb_metadirino == sb->sb_rootino + 1 && - sb->sb_rbmino == sb->sb_rootino + 2 && - sb->sb_rsumino == sb->sb_rootino + 3); + ASSERT(sb->sb_metadirino == sb->sb_rootino + 1); else ASSERT(sb->sb_rbmino == sb->sb_rootino + 1 && sb->sb_rsumino == sb->sb_rootino + 2); do_warn(_("root inode chunk not found\n")); /* - * mark the first 3-4 inodes used, the rest are free + * mark the first 2-3 inodes used, the rest are free */ ino_rec = set_inode_used_alloc(mp, 0, XFS_INO_TO_AGINO(mp, sb->sb_rootino)); @@ -569,7 +568,7 @@ phase2( * also mark blocks */ set_bmap_ext(0, XFS_INO_TO_AGBNO(mp, sb->sb_rootino), - M_IGEO(mp)->ialloc_blks, XR_E_INO); + M_IGEO(mp)->ialloc_blks, XR_E_INO, false); } else { do_log(_(" - found root inode chunk\n")); j = 0; @@ -600,29 +599,33 @@ phase2( j++; } - if (is_inode_free(ino_rec, j)) { - do_warn(_("realtime bitmap inode marked free, ")); - set_inode_used(ino_rec, j); - if (!no_modify) - do_warn(_("correcting\n")); - else - do_warn(_("would correct\n")); - } - set_inode_is_meta(ino_rec, j); - j++; + if (!xfs_has_rtgroups(mp)) { + if (is_inode_free(ino_rec, j)) { + do_warn(_("realtime bitmap inode marked free, ")); + set_inode_used(ino_rec, j); + if (!no_modify) + do_warn(_("correcting\n")); + else + do_warn(_("would correct\n")); + } + set_inode_is_meta(ino_rec, j); + j++; - if (is_inode_free(ino_rec, j)) { - do_warn(_("realtime summary inode marked free, ")); - set_inode_used(ino_rec, j); - if (!no_modify) - do_warn(_("correcting\n")); - else - do_warn(_("would correct\n")); + if (is_inode_free(ino_rec, j)) { + do_warn(_("realtime summary inode marked free, ")); + set_inode_used(ino_rec, j); + if (!no_modify) + do_warn(_("correcting\n")); + else + do_warn(_("would correct\n")); + } + set_inode_is_meta(ino_rec, j); + j++; } - set_inode_is_meta(ino_rec, j); - j++; } + discover_rtgroup_inodes(mp); + /* * Upgrade the filesystem now that we've done a preliminary check of * the superblocks, the AGs, the log, and the metadata inodes. diff --git a/repair/phase4.c b/repair/phase4.c index 036a4ed0e54445..f43f8ecd84e25b 100644 --- a/repair/phase4.c +++ b/repair/phase4.c @@ -295,15 +295,17 @@ process_dup_rt_extents( */ static void process_dup_extents( + struct xfs_mount *mp, xfs_agnumber_t agno, xfs_agblock_t agbno, - xfs_agblock_t ag_end) + xfs_agblock_t ag_end, + bool isrt) { do { int bstate; xfs_extlen_t blen; - bstate = get_bmap_ext(agno, agbno, ag_end, &blen); + bstate = get_bmap_ext(agno, agbno, ag_end, &blen, isrt); switch (bstate) { case XR_E_FREE1: if (no_modify) @@ -320,7 +322,12 @@ _("free space (%u,%u-%u) only seen by one free space btree\n"), case XR_E_FS_MAP: break; case XR_E_MULT: - add_dup_extent(agno, agbno, blen); + /* + * Nothing is searching for duplicate RT extents, so + * don't bother tracking them. + */ + if (!isrt) + add_dup_extent(agno, agbno, blen); break; case XR_E_BAD_STATE: default: @@ -389,13 +396,23 @@ phase4(xfs_mount_t *mp) mp->m_sb.sb_dblocks - (xfs_rfsblock_t) mp->m_sb.sb_agblocks * i; - process_dup_extents(i, ag_hdr_block, ag_end); + process_dup_extents(mp, i, ag_hdr_block, ag_end, false); PROG_RPT_INC(prog_rpt_done[i], 1); } print_final_rpt(); - process_dup_rt_extents(mp); + if (xfs_has_rtgroups(mp)) { + for (i = 0; i < mp->m_sb.sb_rgcount; i++) { + uint64_t rblocks; + + rblocks = xfs_rtbxlen_to_blen(mp, + libxfs_rtgroup_extents(mp, i)); + process_dup_extents(mp, i, 0, rblocks, true); + } + } else { + process_dup_rt_extents(mp); + } /* * initialize bitmaps for all AGs diff --git a/repair/phase5.c b/repair/phase5.c index 91c4a8662a69f2..ac5f04697b7110 100644 --- a/repair/phase5.c +++ b/repair/phase5.c @@ -72,7 +72,7 @@ mk_incore_fstree( * largest extent. */ for (agbno = 0; agbno < ag_end; agbno += blen) { - bstate = get_bmap_ext(agno, agbno, ag_end, &blen); + bstate = get_bmap_ext(agno, agbno, ag_end, &blen, false); if (bstate < XR_E_INUSE) { free_blocks += blen; if (in_extent == 0) { diff --git a/repair/phase6.c b/repair/phase6.c index e9feaa5739efa1..59665f48684aa4 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -568,6 +568,122 @@ _("couldn't iget realtime %s inode -- error - %d\n"), do_error(_("%s: commit failed, error %d\n"), __func__, error); } +/* Mark a newly allocated inode in use in the incore bitmap. */ +static void +mark_ino_inuse( + struct xfs_mount *mp, + xfs_ino_t ino, + int mode, + xfs_ino_t parent) +{ + struct ino_tree_node *irec; + int ino_offset; + int i; + + irec = find_inode_rec(mp, XFS_INO_TO_AGNO(mp, ino), + XFS_INO_TO_AGINO(mp, ino)); + + if (irec == NULL) { + /* + * This inode is allocated from a newly created inode + * chunk and therefore did not exist when inode chunks + * were processed in phase3. Add this group of inodes to + * the entry avl tree as if they were discovered in phase3. + */ + irec = set_inode_free_alloc(mp, + XFS_INO_TO_AGNO(mp, ino), + XFS_INO_TO_AGINO(mp, ino)); + alloc_ex_data(irec); + + for (i = 0; i < XFS_INODES_PER_CHUNK; i++) + set_inode_free(irec, i); + } + + ino_offset = get_inode_offset(mp, ino, irec); + + /* + * Mark the inode allocated so it is not skipped in phase 7. We'll + * find it with the directory traverser soon, so we don't need to + * mark it reached. + */ + set_inode_used(irec, ino_offset); + set_inode_ftype(irec, ino_offset, libxfs_mode_to_ftype(mode)); + set_inode_parent(irec, ino_offset, parent); + if (S_ISDIR(mode)) + set_inode_isadir(irec, ino_offset); +} + +static bool +ensure_rtgroup_file( + struct xfs_rtgroup *rtg, + enum xfs_rtg_inodes type) +{ + struct xfs_mount *mp = rtg_mount(rtg); + struct xfs_inode *ip = rtg->rtg_inodes[type]; + const char *name = libxfs_rtginode_name(type); + int error; + + if (!xfs_rtginode_enabled(rtg, type)) + return false; + + if (no_modify) { + if (rtgroup_inodes_were_bad(type)) + do_warn(_("would reset rtgroup %u %s inode\n"), + rtg_rgno(rtg), name); + return false; + } + + if (rtgroup_inodes_were_bad(type)) { + /* + * The inode was bad or missing, state that we'll make a new + * one even though we always create a new one. + */ + do_warn(_("resetting rtgroup %u %s inode\n"), + rtg_rgno(rtg), name); + } + + error = -libxfs_rtginode_create(rtg, type, false); + if (error) + do_error( +_("Couldn't create rtgroup %u %s inode, error %d\n"), + rtg_rgno(rtg), name, error); + + ip = rtg->rtg_inodes[type]; + + /* Mark the inode in use. */ + mark_ino_inuse(mp, ip->i_ino, S_IFREG, mp->m_rtdirip->i_ino); + mark_ino_metadata(mp, ip->i_ino); + return true; +} + +static void +ensure_rtgroup_bitmap( + struct xfs_rtgroup *rtg) +{ + struct xfs_mount *mp = rtg_mount(rtg); + + if (!xfs_has_rtgroups(mp)) + return; + if (!ensure_rtgroup_file(rtg, XFS_RTGI_BITMAP)) + return; + + fill_rtbitmap(rtg); +} + +static void +ensure_rtgroup_summary( + struct xfs_rtgroup *rtg) +{ + struct xfs_mount *mp = rtg_mount(rtg); + + if (!xfs_has_rtgroups(mp)) + return; + if (!ensure_rtgroup_file(rtg, XFS_RTGI_SUMMARY)) + return; + + fill_rtsummary(rtg); +} + /* Initialize a root directory. */ static int init_fs_root_dir( @@ -632,6 +748,8 @@ mk_metadir( struct xfs_trans *tp; int error; + libxfs_rtginode_irele(&mp->m_rtdirip); + error = init_fs_root_dir(mp, mp->m_sb.sb_metadirino, 0, &mp->m_metadirip); if (error) @@ -3057,8 +3175,10 @@ mark_inode( static void mark_standalone_inodes(xfs_mount_t *mp) { - mark_inode(mp, mp->m_sb.sb_rbmino); - mark_inode(mp, mp->m_sb.sb_rsumino); + if (!xfs_has_rtgroups(mp)) { + mark_inode(mp, mp->m_sb.sb_rbmino); + mark_inode(mp, mp->m_sb.sb_rsumino); + } if (!fs_quotas) return; @@ -3239,6 +3359,49 @@ _(" - resetting contents of realtime bitmap and summary inodes\n")); libxfs_rtgroup_rele(rtg); } +static void +reset_rt_metadir_inodes( + struct xfs_mount *mp) +{ + struct xfs_rtgroup *rtg = NULL; + int error; + + /* + * Release the rtgroup inodes so that we can rebuild everything from + * observations. + */ + if (!no_modify) + unload_rtgroup_inodes(mp); + + if (mp->m_sb.sb_rgcount > 0) { + if (!no_modify) { + error = -libxfs_rtginode_mkdir_parent(mp); + if (error) + do_error(_("failed to create realtime metadir (%d)\n"), + error); + } + mark_ino_inuse(mp, mp->m_rtdirip->i_ino, S_IFDIR, + mp->m_metadirip->i_ino); + mark_ino_metadata(mp, mp->m_rtdirip->i_ino); + } + + /* + * This isn't the whole story, but it keeps the message that we've had + * for years and which is expected in xfstests and more. + */ + if (!no_modify) + do_log( +_(" - resetting contents of realtime bitmap and summary inodes\n")); + + if (mp->m_sb.sb_rgcount == 0) + return; + + while ((rtg = xfs_rtgroup_next(mp, rtg))) { + ensure_rtgroup_bitmap(rtg); + ensure_rtgroup_summary(rtg); + } +} + void phase6(xfs_mount_t *mp) { @@ -3287,7 +3450,10 @@ phase6(xfs_mount_t *mp) do_warn(_("would reinitialize metadata root directory\n")); } - reset_rt_sb_inodes(mp); + if (xfs_has_rtgroups(mp)) + reset_rt_metadir_inodes(mp); + else + reset_rt_sb_inodes(mp); mark_standalone_inodes(mp); diff --git a/repair/rt.c b/repair/rt.c index a3378ef1dd0af2..2de6830c931e86 100644 --- a/repair/rt.c +++ b/repair/rt.c @@ -12,11 +12,19 @@ #include "dinode.h" #include "protos.h" #include "err_protos.h" +#include "libfrog/bitmap.h" #include "rt.h" +/* Bitmap of rt group inodes */ +static struct bitmap *rtg_inodes[XFS_RTGI_MAX]; +static bool rtginodes_bad[XFS_RTGI_MAX]; + /* Computed rt bitmap/summary data */ -static union xfs_rtword_raw *btmcompute; -static union xfs_suminfo_raw *sumcompute; +struct rtg_computed { + union xfs_rtword_raw *bmp; + union xfs_suminfo_raw *sum; +}; +struct rtg_computed *rt_computed; static inline void set_rtword( @@ -44,14 +52,12 @@ inc_sumcount( p->old++; } -/* - * generate the real-time bitmap and summary info based on the - * incore realtime extent map. - */ -void -generate_rtinfo( - struct xfs_mount *mp) +static void +generate_rtgroup_rtinfo( + struct xfs_rtgroup *rtg) { + struct rtg_computed *comp = &rt_computed[rtg_rgno(rtg)]; + struct xfs_mount *mp = rtg_mount(rtg); unsigned int bitsperblock = mp->m_blockwsize << XFS_NBWORDLOG; xfs_rtxnum_t extno = 0; @@ -63,15 +69,15 @@ generate_rtinfo( union xfs_rtword_raw *words; wordcnt = XFS_FSB_TO_B(mp, mp->m_sb.sb_rbmblocks) >> XFS_WORDLOG; - btmcompute = calloc(wordcnt, sizeof(union xfs_rtword_raw)); - if (!btmcompute) + comp->bmp = calloc(wordcnt, sizeof(union xfs_rtword_raw)); + if (!comp->bmp) do_error( _("couldn't allocate memory for incore realtime bitmap.\n")); - words = btmcompute; + words = comp->bmp; wordcnt = XFS_FSB_TO_B(mp, mp->m_rsumblocks) >> XFS_WORDLOG; - sumcompute = calloc(wordcnt, sizeof(union xfs_suminfo_raw)); - if (!sumcompute) + comp->sum = calloc(wordcnt, sizeof(union xfs_suminfo_raw)); + if (!comp->sum) do_error( _("couldn't allocate memory for incore realtime summary info.\n")); @@ -81,15 +87,27 @@ _("couldn't allocate memory for incore realtime summary info.\n")); * end (size) of each range of free extents to set the summary info * properly. */ - while (extno < mp->m_sb.sb_rextents) { + while (extno < rtg->rtg_extents) { xfs_rtword_t freebit = 1; xfs_rtword_t bits = 0; - int i; + int state, i; set_rtword(mp, words, 0); - for (i = 0; i < sizeof(xfs_rtword_t) * NBBY && - extno < mp->m_sb.sb_rextents; i++, extno++) { - if (get_rtbmap(extno) == XR_E_FREE) { + for (i = 0; i < sizeof(xfs_rtword_t) * NBBY; i++) { + if (extno == rtg->rtg_extents) + break; + + /* + * Note: for the RTG case it might make sense to use + * get_rgbmap_ext here and generate multiple bitmap + * entries per lookup. + */ + if (xfs_has_rtgroups(mp)) + state = get_rgbmap(rtg_rgno(rtg), + extno * mp->m_sb.sb_rextsize); + else + state = get_rtbmap(extno); + if (state == XR_E_FREE) { sb_frextents++; bits |= freebit; @@ -104,11 +122,12 @@ _("couldn't allocate memory for incore realtime summary info.\n")); offs = xfs_rtsumoffs(mp, libxfs_highbit64(len), start_bmbno); - inc_sumcount(mp, sumcompute, offs); + inc_sumcount(mp, comp->sum, offs); in_extent = false; } freebit <<= 1; + extno++; } set_rtword(mp, words, bits); words++; @@ -122,8 +141,27 @@ _("couldn't allocate memory for incore realtime summary info.\n")); xfs_rtsumoff_t offs; offs = xfs_rtsumoffs(mp, libxfs_highbit64(len), start_bmbno); - inc_sumcount(mp, sumcompute, offs); + inc_sumcount(mp, comp->sum, offs); } +} + +/* + * generate the real-time bitmap and summary info based on the + * incore realtime extent map. + */ +void +generate_rtinfo( + struct xfs_mount *mp) +{ + struct xfs_rtgroup *rtg = NULL; + + rt_computed = calloc(mp->m_sb.sb_rgcount, sizeof(struct rtg_computed)); + if (!rt_computed) + do_error( + _("couldn't allocate memory for incore realtime info.\n")); + + while ((rtg = xfs_rtgroup_next(mp, rtg))) + generate_rtgroup_rtinfo(rtg); if (mp->m_sb.sb_frextents != sb_frextents) { do_warn(_("sb_frextents %" PRIu64 ", counted %" PRIu64 "\n"), @@ -133,12 +171,13 @@ _("couldn't allocate memory for incore realtime summary info.\n")); static void check_rtwords( - struct xfs_mount *mp, + struct xfs_rtgroup *rtg, const char *filename, unsigned long long bno, void *ondisk, void *incore) { + struct xfs_mount *mp = rtg_mount(rtg); unsigned int wordcnt = mp->m_blockwsize; union xfs_rtword_raw *o = ondisk, *i = incore; int badstart = -1; @@ -152,8 +191,9 @@ check_rtwords( /* Report a range of inconsistency that just ended. */ if (badstart >= 0) do_warn( - _("discrepancy in %s at dblock 0x%llx words 0x%x-0x%x/0x%x\n"), - filename, bno, badstart, j - 1, wordcnt); + _("discrepancy in %s (%u) at dblock 0x%llx words 0x%x-0x%x/0x%x\n"), + filename, rtg_rgno(rtg), bno, + badstart, j - 1, wordcnt); badstart = -1; continue; } @@ -164,44 +204,26 @@ check_rtwords( if (badstart >= 0) do_warn( - _("discrepancy in %s at dblock 0x%llx words 0x%x-0x%x/0x%x\n"), - filename, bno, badstart, wordcnt, - wordcnt); + _("discrepancy in %s (%u) at dblock 0x%llx words 0x%x-0x%x/0x%x\n"), + filename, rtg_rgno(rtg), bno, + badstart, wordcnt, wordcnt); } static void check_rtfile_contents( - struct xfs_mount *mp, - enum xfs_metafile_type metafile_type, + struct xfs_rtgroup *rtg, + enum xfs_rtg_inodes type, + void *buf, xfs_fileoff_t filelen) { - struct xfs_bmbt_irec map; - struct xfs_buf *bp; - struct xfs_inode *ip; - const char *filename; - void *buf; - xfs_ino_t ino; + struct xfs_mount *mp = rtg_mount(rtg); + const char *filename = libxfs_rtginode_name(type); + struct xfs_inode *ip = rtg->rtg_inodes[type]; xfs_fileoff_t bno = 0; int error; - switch (metafile_type) { - case XFS_METAFILE_RTBITMAP: - ino = mp->m_sb.sb_rbmino; - filename = "rtbitmap"; - buf = btmcompute; - break; - case XFS_METAFILE_RTSUMMARY: - ino = mp->m_sb.sb_rsumino; - filename = "rtsummary"; - buf = sumcompute; - break; - default: - return; - } - - error = -libxfs_metafile_iget(mp, ino, metafile_type, &ip); - if (error) { - do_warn(_("unable to open %s file, err %d\n"), filename, error); + if (!ip) { + do_warn(_("unable to open %s file\n"), filename); return; } @@ -213,12 +235,11 @@ check_rtfile_contents( } while (bno < filelen) { - xfs_filblks_t maplen; - int nmap = 1; + struct xfs_bmbt_irec map; + struct xfs_buf *bp; + int nmap = 1; - /* Read up to 1MB at a time. */ - maplen = min(filelen - bno, XFS_B_TO_FSBT(mp, 1048576)); - error = -libxfs_bmapi_read(ip, bno, maplen, &map, &nmap, 0); + error = -libxfs_bmapi_read(ip, bno, 1, &map, &nmap, 0); if (error) { do_warn(_("unable to read %s mapping, err %d\n"), filename, error); @@ -233,43 +254,104 @@ check_rtfile_contents( error = -libxfs_buf_read_uncached(mp->m_dev, XFS_FSB_TO_DADDR(mp, map.br_startblock), - XFS_FSB_TO_BB(mp, map.br_blockcount), - 0, &bp, NULL); + XFS_FSB_TO_BB(mp, 1), 0, &bp, + xfs_rtblock_ops(mp, type)); if (error) { do_warn(_("unable to read %s at dblock 0x%llx, err %d\n"), filename, (unsigned long long)bno, error); break; } - check_rtwords(mp, filename, bno, bp->b_addr, buf); + check_rtwords(rtg, filename, bno, bp->b_addr, buf); - buf += XFS_FSB_TO_B(mp, map.br_blockcount); - bno += map.br_blockcount; + buf += mp->m_blockwsize << XFS_WORDLOG; + bno++; libxfs_buf_relse(bp); } +} - libxfs_irele(ip); +/* + * Try to load a sb-rooted rt metadata file now, since earlier phases may have + * fixed verifier problems in the root inode chunk. + */ +static void +try_load_sb_rtfile( + struct xfs_mount *mp, + enum xfs_rtg_inodes type) +{ + struct xfs_rtgroup *rtg = libxfs_rtgroup_grab(mp, 0); + struct xfs_trans *tp; + int error; + + if (rtg->rtg_inodes[type]) + goto out_rtg; + + error = -libxfs_trans_alloc_empty(mp, &tp); + if (error) + goto out_rtg; + + + error = -libxfs_rtginode_load(rtg, type, tp); + if (error) + goto out_cancel; + + /* If we can't load the inode, signal to phase 6 to recreate it. */ + if (!rtg->rtg_inodes[type]) { + switch (type) { + case XFS_RTGI_BITMAP: + need_rbmino = 1; + break; + case XFS_RTGI_SUMMARY: + need_rsumino = 1; + break; + default: + ASSERT(0); + break; + } + } + +out_cancel: + libxfs_trans_cancel(tp); +out_rtg: + libxfs_rtgroup_rele(rtg); } void check_rtbitmap( struct xfs_mount *mp) { + struct xfs_rtgroup *rtg = NULL; + if (need_rbmino) return; - check_rtfile_contents(mp, XFS_METAFILE_RTBITMAP, - mp->m_sb.sb_rbmblocks); + if (!xfs_has_rtgroups(mp)) + try_load_sb_rtfile(mp, XFS_RTGI_BITMAP); + + while ((rtg = xfs_rtgroup_next(mp, rtg))) { + check_rtfile_contents(rtg, XFS_RTGI_BITMAP, + rt_computed[rtg_rgno(rtg)].bmp, + mp->m_sb.sb_rbmblocks); + } } void check_rtsummary( struct xfs_mount *mp) { + struct xfs_rtgroup *rtg = NULL; + if (need_rsumino) return; - check_rtfile_contents(mp, XFS_METAFILE_RTSUMMARY, mp->m_rsumblocks); + if (!xfs_has_rtgroups(mp)) + try_load_sb_rtfile(mp, XFS_RTGI_SUMMARY); + + while ((rtg = xfs_rtgroup_next(mp, rtg))) { + check_rtfile_contents(rtg, XFS_RTGI_SUMMARY, + rt_computed[rtg_rgno(rtg)].sum, + mp->m_rsumblocks); + } } void @@ -278,8 +360,17 @@ fill_rtbitmap( { int error; + /* + * For file systems without a RT subvolume we have the bitmap and + * summary files, but they are empty. In that case rt_computed is + * NULL. + */ + if (!rt_computed) + return; + error = -libxfs_rtfile_initialize_blocks(rtg, XFS_RTGI_BITMAP, - 0, rtg_mount(rtg)->m_sb.sb_rbmblocks, btmcompute); + 0, rtg_mount(rtg)->m_sb.sb_rbmblocks, + rt_computed[rtg_rgno(rtg)].bmp); if (error) do_error( _("couldn't re-initialize realtime bitmap inode, error %d\n"), error); @@ -291,9 +382,183 @@ fill_rtsummary( { int error; + /* + * For file systems without a RT subvolume we have the bitmap and + * summary files, but they are empty. In that case rt_computed is + * NULL. + */ + if (!rt_computed) + return; + error = -libxfs_rtfile_initialize_blocks(rtg, XFS_RTGI_SUMMARY, - 0, rtg_mount(rtg)->m_rsumblocks, sumcompute); + 0, rtg_mount(rtg)->m_rsumblocks, + rt_computed[rtg_rgno(rtg)].sum); if (error) do_error( _("couldn't re-initialize realtime summary inode, error %d\n"), error); } + +bool +is_rtgroup_inode( + xfs_ino_t ino, + enum xfs_rtg_inodes type) +{ + if (!rtg_inodes[type]) + return false; + return bitmap_test(rtg_inodes[type], ino, 1); +} + +bool +rtgroup_inodes_were_bad( + enum xfs_rtg_inodes type) +{ + return rtginodes_bad[type]; +} + +void +mark_rtgroup_inodes_bad( + struct xfs_mount *mp, + enum xfs_rtg_inodes type) +{ + struct xfs_rtgroup *rtg = NULL; + + while ((rtg = xfs_rtgroup_next(mp, rtg))) + libxfs_rtginode_irele(&rtg->rtg_inodes[type]); + + rtginodes_bad[type] = true; +} + +static inline int +mark_rtginode( + struct xfs_trans *tp, + struct xfs_rtgroup *rtg, + enum xfs_rtg_inodes type) +{ + struct xfs_inode *ip; + int error; + + if (!xfs_rtginode_enabled(rtg, type)) + return 0; + + error = -libxfs_rtginode_load(rtg, type, tp); + if (error) + goto out_corrupt; + + ip = rtg->rtg_inodes[type]; + if (!ip) + goto out_corrupt; + + if (xfs_has_rtgroups(rtg_mount(rtg))) { + if (bitmap_test(rtg_inodes[type], ip->i_ino, 1)) { + error = EFSCORRUPTED; + goto out_corrupt; + } + + error = bitmap_set(rtg_inodes[type], ip->i_ino, 1); + if (error) + goto out_corrupt; + } + + /* + * Phase 3 will clear the ondisk inodes of all rt metadata files, but + * it doesn't reset any blocks. Keep the incore inodes loaded so that + * phase 4 can check the rt metadata. These inodes must be dropped + * before rebuilding can begin during phase 6. + */ + return 0; + +out_corrupt: + rtginodes_bad[type] = true; + return error; +} + +/* Mark the reachable rt metadata inodes prior to the inode scan. */ +void +discover_rtgroup_inodes( + struct xfs_mount *mp) +{ + struct xfs_rtgroup *rtg = NULL; + struct xfs_trans *tp; + int error, err2; + int i; + + error = -libxfs_trans_alloc_empty(mp, &tp); + if (error) + goto out; + if (xfs_has_rtgroups(mp) && mp->m_sb.sb_rgcount > 0) { + error = -libxfs_rtginode_load_parent(tp); + if (error) + goto out_cancel; + } + + while ((rtg = xfs_rtgroup_next(mp, rtg))) { + for (i = 0; i < XFS_RTGI_MAX; i++) { + err2 = mark_rtginode(tp, rtg, i); + if (err2 && !error) + error = err2; + } + } + +out_cancel: + libxfs_trans_cancel(tp); +out: + if (xfs_has_rtgroups(mp) && error) { + /* + * Old xfs_repair didn't complain if rtbitmaps didn't load + * until phase 5, so only turn on extra warnings during phase 2 + * for newer filesystems. + */ + switch (error) { + case EFSCORRUPTED: + do_warn( + _("corruption in metadata directory tree while discovering rt group inodes\n")); + break; + default: + do_warn( + _("couldn't discover rt group inodes, err %d\n"), + error); + break; + } + } +} + +/* Unload incore rtgroup inodes before rebuilding rt metadata. */ +void +unload_rtgroup_inodes( + struct xfs_mount *mp) +{ + struct xfs_rtgroup *rtg = NULL; + unsigned int i; + + while ((rtg = xfs_rtgroup_next(mp, rtg))) + for (i = 0; i < XFS_RTGI_MAX; i++) + libxfs_rtginode_irele(&rtg->rtg_inodes[i]); + + libxfs_rtginode_irele(&mp->m_rtdirip); +} + +void +init_rtgroup_inodes(void) +{ + unsigned int i; + int error; + + for (i = 0; i < XFS_RTGI_MAX; i++) { + error = bitmap_alloc(&rtg_inodes[i]); + if (error) + break; + } + + if (error) + do_error(_("could not allocate rtginode bitmap, err=%d!\n"), + error); +} + +void +free_rtgroup_inodes(void) +{ + int i; + + for (i = 0; i < XFS_RTGI_MAX; i++) + bitmap_free(&rtg_inodes[i]); +} diff --git a/repair/rt.h b/repair/rt.h index 9d837de65a7dfc..4dfe4a921d4cdf 100644 --- a/repair/rt.h +++ b/repair/rt.h @@ -13,4 +13,24 @@ void check_rtsummary(struct xfs_mount *mp); void fill_rtbitmap(struct xfs_rtgroup *rtg); void fill_rtsummary(struct xfs_rtgroup *rtg); +void discover_rtgroup_inodes(struct xfs_mount *mp); +void unload_rtgroup_inodes(struct xfs_mount *mp); + +void init_rtgroup_inodes(void); +void free_rtgroup_inodes(void); + +bool is_rtgroup_inode(xfs_ino_t ino, enum xfs_rtg_inodes type); + +static inline bool is_rtbitmap_inode(xfs_ino_t ino) +{ + return is_rtgroup_inode(ino, XFS_RTGI_BITMAP); +} +static inline bool is_rtsummary_inode(xfs_ino_t ino) +{ + return is_rtgroup_inode(ino, XFS_RTGI_SUMMARY); +} + +void mark_rtgroup_inodes_bad(struct xfs_mount *mp, enum xfs_rtg_inodes type); +bool rtgroup_inodes_were_bad(enum xfs_rtg_inodes type); + #endif /* _XFS_REPAIR_RT_H_ */ diff --git a/repair/sb.c b/repair/sb.c index 7f27833d697ea9..d52ab2ffeaf28c 100644 --- a/repair/sb.c +++ b/repair/sb.c @@ -311,6 +311,38 @@ verify_sb_loginfo( return true; } +static int +verify_sb_rtgroups( + struct xfs_sb *sbp) +{ + uint64_t groups; + + if (sbp->sb_rextsize == 0) + return XR_BAD_RT_GEO_DATA; + + if (sbp->sb_rgextents > XFS_MAX_RGBLOCKS / sbp->sb_rextsize) + return XR_BAD_RT_GEO_DATA; + + if (sbp->sb_rgextents < XFS_MIN_RGEXTENTS) + return XR_BAD_RT_GEO_DATA; + + if (sbp->sb_rgcount > XFS_MAX_RGNUMBER) + return XR_BAD_RT_GEO_DATA; + + groups = howmany_64(sbp->sb_rextents, sbp->sb_rgextents); + if (groups != sbp->sb_rgcount) + return XR_BAD_RT_GEO_DATA; + + if (!(sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_EXCHRANGE)) + return XR_BAD_RT_GEO_DATA; + + if (sbp->sb_rgblklog != libxfs_compute_rgblklog(sbp->sb_rgextents, + sbp->sb_rextsize)) + return XR_BAD_RT_GEO_DATA; + + return 0; +} + /* * verify a superblock -- does not verify root inode # * can only check that geometry info is internally @@ -482,6 +514,15 @@ verify_sb(char *sb_buf, xfs_sb_t *sb, int is_primary_sb) if (sb->sb_blocklog + sb->sb_dirblklog > XFS_MAX_BLOCKSIZE_LOG) return XR_BAD_DIR_SIZE_DATA; + if (xfs_sb_version_hasmetadir(sb)) { + if (memchr_inv(sb->sb_pad, 0, sizeof(sb->sb_pad))) + return XR_SB_GEO_MISMATCH; + + ret = verify_sb_rtgroups(sb); + if (ret) + return ret; + } + return(XR_OK); } diff --git a/repair/scan.c b/repair/scan.c index 8b118423ce0457..221d660e81fdb4 100644 --- a/repair/scan.c +++ b/repair/scan.c @@ -724,10 +724,11 @@ _("%s freespace btree block claimed (state %d), agno %d, bno %d, suspect %d\n"), } for ( ; b < end; b += blen) { - state = get_bmap_ext(agno, b, end, &blen); + state = get_bmap_ext(agno, b, end, &blen, false); switch (state) { case XR_E_UNKNOWN: - set_bmap_ext(agno, b, blen, XR_E_FREE1); + set_bmap_ext(agno, b, blen, XR_E_FREE1, + false); break; case XR_E_FREE1: /* @@ -737,7 +738,7 @@ _("%s freespace btree block claimed (state %d), agno %d, bno %d, suspect %d\n"), if (magic == XFS_ABTC_MAGIC || magic == XFS_ABTC_CRC_MAGIC) { set_bmap_ext(agno, b, blen, - XR_E_FREE); + XR_E_FREE, false); break; } fallthrough; @@ -841,27 +842,27 @@ process_rmap_rec( switch (owner) { case XFS_RMAP_OWN_FS: case XFS_RMAP_OWN_LOG: - set_bmap_ext(agno, b, blen, XR_E_INUSE_FS1); + set_bmap_ext(agno, b, blen, XR_E_INUSE_FS1, false); break; case XFS_RMAP_OWN_AG: case XFS_RMAP_OWN_INOBT: - set_bmap_ext(agno, b, blen, XR_E_FS_MAP1); + set_bmap_ext(agno, b, blen, XR_E_FS_MAP1, false); break; case XFS_RMAP_OWN_INODES: - set_bmap_ext(agno, b, blen, XR_E_INO1); + set_bmap_ext(agno, b, blen, XR_E_INO1, false); break; case XFS_RMAP_OWN_REFC: - set_bmap_ext(agno, b, blen, XR_E_REFC); + set_bmap_ext(agno, b, blen, XR_E_REFC, false); break; case XFS_RMAP_OWN_COW: - set_bmap_ext(agno, b, blen, XR_E_COW); + set_bmap_ext(agno, b, blen, XR_E_COW, false); break; case XFS_RMAP_OWN_NULL: /* still unknown */ break; default: /* file data */ - set_bmap_ext(agno, b, blen, XR_E_INUSE1); + set_bmap_ext(agno, b, blen, XR_E_INUSE1, false); break; } break; @@ -1207,7 +1208,8 @@ _("%s rmap btree block claimed (state %d), agno %d, bno %d, suspect %d\n"), /* Check for block owner collisions. */ for ( ; b < end; b += blen) { - state = get_bmap_ext(agno, b, end, &blen); + state = get_bmap_ext(agno, b, end, &blen, + false); process_rmap_rec(mp, agno, b, end, blen, owner, state, name); } @@ -1483,14 +1485,16 @@ _("leftover CoW extent has invalid startblock in record %u of %s btree block %u/ xfs_extlen_t cnr; for (c = agb; c < end; c += cnr) { - state = get_bmap_ext(agno, c, end, &cnr); + state = get_bmap_ext(agno, c, end, &cnr, + false); switch (state) { case XR_E_UNKNOWN: case XR_E_COW: do_warn( _("leftover CoW extent (%u/%u) len %u\n"), agno, c, cnr); - set_bmap_ext(agno, c, cnr, XR_E_FREE); + set_bmap_ext(agno, c, cnr, + XR_E_FREE, false); break; default: do_warn( diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c index 30b014898c3203..d06bf659df89c1 100644 --- a/repair/xfs_repair.c +++ b/repair/xfs_repair.c @@ -27,6 +27,7 @@ #include "bulkload.h" #include "quotacheck.h" #include "rcbag_btree.h" +#include "rt.h" /* * option tables for getsubopt calls @@ -729,10 +730,12 @@ _("sb root inode value %" PRIu64 " valid but in unaligned location (expected %"P rootino++; } - validate_sb_ino(&mp->m_sb.sb_rbmino, rootino + 1, - _("realtime bitmap")); - validate_sb_ino(&mp->m_sb.sb_rsumino, rootino + 2, - _("realtime summary")); + if (!xfs_has_rtgroups(mp)) { + validate_sb_ino(&mp->m_sb.sb_rbmino, rootino + 1, + _("realtime bitmap")); + validate_sb_ino(&mp->m_sb.sb_rsumino, rootino + 2, + _("realtime summary")); + } } /* @@ -1345,6 +1348,7 @@ main(int argc, char **argv) incore_ino_init(mp); incore_ext_init(mp); rmaps_init(mp); + init_rtgroup_inodes(); /* initialize random globals now that we know the fs geometry */ inodes_per_block = mp->m_sb.sb_inopblock; @@ -1390,11 +1394,14 @@ main(int argc, char **argv) phase6(mp); phase_end(mp, 6); + free_rtgroup_inodes(); + phase7(mp, phase2_threads); phase_end(mp, 7); } else { do_warn( _("Inode allocation btrees are too corrupted, skipping phases 6 and 7\n")); + free_rtgroup_inodes(); } if (lost_quotas && !have_uquotino && !have_gquotino && !have_pquotino) { From patchwork Mon Dec 23 22:17: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: 13919391 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 99DCA433D5 for ; Mon, 23 Dec 2024 22:17:14 +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=1734992234; cv=none; b=qFJzx/+96ljaOtnKFMmB7q7zvgYV0IajRV7A+Qy/QxcPBk9Eex4v0pdSVzVRvXV0un1N+nDOwgv2EGok/QczaFHQlWypKVzjifN0T8zvzKVAZEs/ko4hfEHBbcbANEtfhl+yPyl2miMAtX+B6Z/2dRosELy6pquvq2e+48g+4AU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992234; c=relaxed/simple; bh=eBOABoYET+ZJQEuLSGoZyUbLSKGsvGmc+ZUhkkAvl7E=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KGxdLKbSe3XStShKis45aXz0U1QmUlFbGKSt4DBNfA4M3rP8JZOvotTsdbovd/OEyka7IfAI1bchlaQx9lkzFiUVhAqKFx7wsc+F1n6vHUAk7+cnZMYihpctD/pavUCqX/awn2SVSeQk4mPRge93FCWUWGSYTzPBIAkVKK3PhDY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E8lU5fNS; 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="E8lU5fNS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7198CC4CED6; Mon, 23 Dec 2024 22:17:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992234; bh=eBOABoYET+ZJQEuLSGoZyUbLSKGsvGmc+ZUhkkAvl7E=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=E8lU5fNSQaGxQRTfuihyGCD6ETXBqurRh9kYqy8P2Mu0g/GL9QNpxrGNtWcRBk90Y r0MPxxe1tIPGDlS/KW6Efh9qCFpwc3N0fPzN5rAZ4Jlz+Imf39ywehKJSdnxAwfPcl 4rfVy/pfcu9Xz0B6ZyTFQu61f0dEe0aX3DkDkID/VDLxOSTUgseTGPSSmiY47jiq98 A1lUXI16R5p5EN6/kK/CFnd2qGKPKPcKfupX4OqfSL54Zp7i97BEMUwh7GuT+gqkuZ cogk2krllcucI/+QTQsjYFYnqOsS22cSJ7pmxCqbE1IlKwwx3Awnmh0mZ6hg/CEEo2 Fy63rl2huXyvQ== Date: Mon, 23 Dec 2024 14:17:14 -0800 Subject: [PATCH 21/51] xfs_repair: find and clobber rtgroup bitmap and summary files From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944126.2297565.2861564368166815739.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong On a rtgroups filesystem, if the rtgroups bitmap or summary files are garbage, we need to clear the dinode and update the incore bitmap so that we don't bother to check the old rt freespace metadata. However, we regenerate the entire rt metadata directory tree during phase 6. If the bitmap and summary files are ok, we still want to clear the dinode, but we can still use the incore inode to check the old freespace contents. Split the clear_dinode function into two pieces, one that merely zeroes the inode, and the old clear_dinode now turns off checking. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- repair/dino_chunks.c | 23 +++++++++++++++++++++++ repair/dinode.c | 40 ++++++++++++++++++++++++++++++++++------ 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/repair/dino_chunks.c b/repair/dino_chunks.c index 8935cf856e70c8..fe106f0b6ab536 100644 --- a/repair/dino_chunks.c +++ b/repair/dino_chunks.c @@ -15,6 +15,7 @@ #include "versions.h" #include "prefetch.h" #include "progress.h" +#include "rt.h" /* * validates inode block or chunk, returns # of good inodes @@ -1000,6 +1001,28 @@ process_inode_chunk( _("would clear realtime summary inode %" PRIu64 "\n"), ino); } + } else if (is_rtbitmap_inode(ino)) { + mark_rtgroup_inodes_bad(mp, XFS_RTGI_BITMAP); + if (!no_modify) { + do_warn( + _("cleared rtgroup bitmap inode %" PRIu64 "\n"), + ino); + } else { + do_warn( + _("would clear rtgroup bitmap inode %" PRIu64 "\n"), + ino); + } + } else if (is_rtsummary_inode(ino)) { + mark_rtgroup_inodes_bad(mp, XFS_RTGI_SUMMARY); + if (!no_modify) { + do_warn( + _("cleared rtgroup summary inode %" PRIu64 "\n"), + ino); + } else { + do_warn( + _("would clear rtgroup summary inode %" PRIu64 "\n"), + ino); + } } else if (!no_modify) { do_warn(_("cleared inode %" PRIu64 "\n"), ino); diff --git a/repair/dinode.c b/repair/dinode.c index 0a9059db9302a3..2d341975e53993 100644 --- a/repair/dinode.c +++ b/repair/dinode.c @@ -149,16 +149,36 @@ clear_dinode_unlinked(xfs_mount_t *mp, struct xfs_dinode *dino) * until after the agi unlinked lists are walked in phase 3. */ static void -clear_dinode(xfs_mount_t *mp, struct xfs_dinode *dino, xfs_ino_t ino_num) +zero_dinode( + struct xfs_mount *mp, + struct xfs_dinode *dino, + xfs_ino_t ino_num) { clear_dinode_core(mp, dino, ino_num); clear_dinode_unlinked(mp, dino); /* and clear the forks */ memset(XFS_DFORK_DPTR(dino), 0, XFS_LITINO(mp)); - return; } +/* + * clear the inode core and, if this is a metadata inode, prevent subsequent + * phases from checking the (obviously bad) data in the file. + */ +static void +clear_dinode( + struct xfs_mount *mp, + struct xfs_dinode *dino, + xfs_ino_t ino_num) +{ + zero_dinode(mp, dino, ino_num); + + if (is_rtbitmap_inode(ino_num)) + mark_rtgroup_inodes_bad(mp, XFS_RTGI_BITMAP); + + if (is_rtsummary_inode(ino_num)) + mark_rtgroup_inodes_bad(mp, XFS_RTGI_SUMMARY); +} /* * misc. inode-related utility routines @@ -3069,13 +3089,21 @@ _("Bad CoW extent size %u on inode %" PRIu64 ", "), switch (type) { case XR_INO_RTBITMAP: case XR_INO_RTSUM: + /* + * rt bitmap and summary files are always recreated + * when rtgroups are enabled. For older filesystems, + * they exist at fixed locations and cannot be zapped. + */ + if (xfs_has_rtgroups(mp)) + zap_metadata = true; + break; case XR_INO_UQUOTA: case XR_INO_GQUOTA: case XR_INO_PQUOTA: /* - * This inode was recognized as being filesystem - * metadata, so preserve the inode and its contents for - * later checking and repair. + * Quota checking and repair doesn't happen until + * phase7, so preserve quota inodes and their contents + * for later. */ break; default: @@ -3165,7 +3193,7 @@ _("Bad CoW extent size %u on inode %" PRIu64 ", "), * file, zero the ondisk inode and the incore state. */ if (check_dups && zap_metadata && !no_modify) { - clear_dinode(mp, dino, lino); + zero_dinode(mp, dino, lino); *dirty += 1; *used = is_free; *isa_dir = 0; From patchwork Mon Dec 23 22:17:29 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: 13919392 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 B5B7A433D5 for ; Mon, 23 Dec 2024 22:17:30 +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=1734992250; cv=none; b=Z9aF/TxY4l7Qz7JXntbHJip2kSN6wA9yIoJ+wyZxzlOcSPJPVpWvJiLHCF2opyh1ZpbGOTc/IUKB6foBH4X8Os4XXuPUDLnyklpywP4kdc/F5HNMwk4x8+yo0Aqh7ZS7xnS2cZ8EKUqkjB2G7KygqoLyGx/O+kKZZQarEyEV38o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992250; c=relaxed/simple; bh=WNuIcaHvbJ2BKfZZqAj1nZaGuD5eDg4WR6ZmE1xrqNI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HBBWLRDwYYjfNf5Iacj7k83DPY6PR7QbIEzpVbd/rTKazhYdCQkyExetUledtmpAP+xmKRvA/s0/TH/s4v7GncoLOagrE2TcrbQph4F9Wj8PxKOezoN9k38lHLnf22PapSPuGdHyrgY5SZHlbnsp9/THYGe18YbwFuL7o1ULosk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=seDsKduq; 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="seDsKduq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 133CCC4CED3; Mon, 23 Dec 2024 22:17:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992250; bh=WNuIcaHvbJ2BKfZZqAj1nZaGuD5eDg4WR6ZmE1xrqNI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=seDsKduqhWKIt45y7quei4kIrBk3o5WYQkk9lFMa0MhTM0S9JH+IZl+p6mCk25Xth zeIcpjN8QWD5YvvjubJAYkGlHXLMdHztd212hfb6/MXuES6jgf2L7EH4ShykgKotip qdxicYdpQWc0wQEY4QYJPeoajJlMxWQzDG1q7r01mMndpQpvBT/yPdmciXi9inAh8i pe+tTsSx5vA9fW4jo7w2MxJBsCXZQoj6JhOayF1nmIg02eYEJUJVlZDkBKv4pSfMX+ rgkUOs4+Jk4zcZu7Ph4+7bE0BgAwJQPLSQmRjIPcc6wVeGsdSauFpWxZ3DeIdMmDeF 1tFAYxMrbhDLQ== Date: Mon, 23 Dec 2024 14:17:29 -0800 Subject: [PATCH 22/51] xfs_repair: support realtime superblocks From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944141.2297565.9135988674963134278.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Support the realtime superblock feature. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- libxfs/libxfs_api_defs.h | 1 + repair/incore.c | 12 ++++++++++ repair/phase3.c | 4 +++ repair/rt.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++ repair/rt.h | 3 +++ repair/xfs_repair.c | 4 +++ 6 files changed, 78 insertions(+) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 84965106358d61..dbdf5d100ec8e9 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -300,6 +300,7 @@ #define xfs_rtfree_extent libxfs_rtfree_extent #define xfs_rtfree_blocks libxfs_rtfree_blocks +#define xfs_update_rtsb libxfs_update_rtsb #define xfs_sb_from_disk libxfs_sb_from_disk #define xfs_sb_quota_from_disk libxfs_sb_quota_from_disk #define xfs_sb_read_secondary libxfs_sb_read_secondary diff --git a/repair/incore.c b/repair/incore.c index 2339d49a95773d..5b3d077f50e495 100644 --- a/repair/incore.c +++ b/repair/incore.c @@ -220,6 +220,15 @@ set_rtbmap( (((uint64_t) state) << ((rtx % XR_BB_NUM) * XR_BB))); } +static void +rtsb_init( + struct xfs_mount *mp) +{ + /* The first rtx of the realtime device contains the super */ + if (xfs_has_rtsb(mp) && rt_bmap) + set_rtbmap(0, XR_E_INUSE_FS); +} + static void reset_rt_bmap(void) { @@ -245,6 +254,8 @@ init_rt_bmap( mp->m_sb.sb_rextents); return; } + + rtsb_init(mp); } static void @@ -332,6 +343,7 @@ reset_bmaps( if (xfs_has_rtgroups(mp)) { reset_rtg_bmaps(mp); + rtsb_init(mp); } else { reset_rt_bmap(); } diff --git a/repair/phase3.c b/repair/phase3.c index ca4dbee47434c8..3a3ca22de14d26 100644 --- a/repair/phase3.c +++ b/repair/phase3.c @@ -17,6 +17,7 @@ #include "progress.h" #include "bmap.h" #include "threads.h" +#include "rt.h" static void process_agi_unlinked( @@ -116,6 +117,9 @@ phase3( set_progress_msg(PROG_FMT_AGI_UNLINKED, (uint64_t) glob_agcount); + if (xfs_has_rtsb(mp) && xfs_has_realtime(mp)) + check_rtsb(mp); + /* first clear the agi unlinked AGI list */ if (!no_modify) { for (i = 0; i < mp->m_sb.sb_agcount; i++) diff --git a/repair/rt.c b/repair/rt.c index 2de6830c931e86..102baa1d5d6186 100644 --- a/repair/rt.c +++ b/repair/rt.c @@ -562,3 +562,57 @@ free_rtgroup_inodes(void) for (i = 0; i < XFS_RTGI_MAX; i++) bitmap_free(&rtg_inodes[i]); } + +void +check_rtsb( + struct xfs_mount *mp) +{ + struct xfs_buf *bp; + int error; + + error = -libxfs_buf_read_uncached(mp->m_rtdev_targp, XFS_RTSB_DADDR, + XFS_FSB_TO_BB(mp, 1), 0, &bp, &xfs_rtsb_buf_ops); + if (!error) { + libxfs_buf_relse(bp); + return; + } + + if (no_modify) { + do_warn(_("would rewrite realtime superblock\n")); + return; + } + + /* + * Rewrite the rt superblock so that an update to the primary fs + * superblock will not get confused by the non-matching rtsb. + */ + do_warn(_("will rewrite realtime superblock\n")); + rewrite_rtsb(mp); +} + +void +rewrite_rtsb( + struct xfs_mount *mp) +{ + struct xfs_buf *rtsb_bp; + struct xfs_buf *sb_bp = libxfs_getsb(mp); + int error; + + if (!sb_bp) + do_error( + _("couldn't grab primary sb to update realtime sb\n")); + + error = -libxfs_buf_get_uncached(mp->m_rtdev_targp, + XFS_FSB_TO_BB(mp, 1), XFS_RTSB_DADDR, &rtsb_bp); + if (error) + do_error( + _("couldn't grab realtime superblock\n")); + + rtsb_bp->b_maps[0].bm_bn = XFS_RTSB_DADDR; + rtsb_bp->b_ops = &xfs_rtsb_buf_ops; + + libxfs_update_rtsb(rtsb_bp, sb_bp); + libxfs_buf_mark_dirty(rtsb_bp); + libxfs_buf_relse(rtsb_bp); + libxfs_buf_relse(sb_bp); +} diff --git a/repair/rt.h b/repair/rt.h index 4dfe4a921d4cdf..865d950b2bf3c4 100644 --- a/repair/rt.h +++ b/repair/rt.h @@ -33,4 +33,7 @@ static inline bool is_rtsummary_inode(xfs_ino_t ino) void mark_rtgroup_inodes_bad(struct xfs_mount *mp, enum xfs_rtg_inodes type); bool rtgroup_inodes_were_bad(enum xfs_rtg_inodes type); +void check_rtsb(struct xfs_mount *mp); +void rewrite_rtsb(struct xfs_mount *mp); + #endif /* _XFS_REPAIR_RT_H_ */ diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c index d06bf659df89c1..2a8a72e7027591 100644 --- a/repair/xfs_repair.c +++ b/repair/xfs_repair.c @@ -1518,6 +1518,10 @@ _("Note - stripe unit (%d) and width (%d) were copied from a backup superblock.\ XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR; } + /* Always rewrite the realtime superblock */ + if (xfs_has_rtsb(mp) && xfs_has_realtime(mp)) + rewrite_rtsb(mp); + /* * Done. Flush all cached buffers and inodes first to ensure all * verifiers are run (where we discover the max metadata LSN), reformat From patchwork Mon Dec 23 22:17:45 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: 13919393 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 23DEBEAF6 for ; Mon, 23 Dec 2024 22:17: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=1734992266; cv=none; b=Q3RxkPLFpIUhxVbPv4Oo5Q5+mO1NTuUY88Du1cOl2R5fjqmz3pZKFBGeP8sNXi55Ss/Z5J647pWEmw2xV83z4TDjqfxbvJzNzEH3wVsiHn7yGsUQu7ANT03Qgcl6WMWTgxAEXS8V0uizuujjzr6dveetFJqov7cHcr4v6fOOnAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992266; c=relaxed/simple; bh=C9c54xMZS4RDFq0QErlWbWEj/pgtz1IP0Z+ESBVZSKQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QAhcn49h4lrcHGj7Y3VW+251n9Z//4lnQANHA977DfedXxobgE9wXXtK8OvyMjRhjGk7ddJaiPrCYPax7Wz8CUpdfev4ATTg1HxvGoaw4Vb16G7pjxJ9AW9+IFR1I2/sKLcaIj00RKKQ76IefRNj9PDe9p6wXK/L7AFUsg7jei0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FYHhPPKB; 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="FYHhPPKB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE443C4CED3; Mon, 23 Dec 2024 22:17:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992265; bh=C9c54xMZS4RDFq0QErlWbWEj/pgtz1IP0Z+ESBVZSKQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=FYHhPPKBY4B8Bxlth1TPzEinEEKxuLy272l0VCpbThym7P80YQ4d7fnEjU4SKHjG0 xCNPKGiSnfuqIy9/Z+X1Fhrm+CBXRPBb4DFNcGL6TW5rPNwZ2PF6Rz2fFH9KAT5HeR Is/Pp1/EDXnmmbDlZo5k0vcf3XvPlrufGOmOPd2wNNcHLAhsvvMOqr0HxdeXsxhHPT NgtasTuDUab32gN3rsn9KxJ5fZ00j14Pz80JphGQqHhjYAS80OaZ7gB3Hb4Dw97Ufy eGXFdOYg6OicRBbPBhlK9sYM6szd1JOkBkNTnzb/FXN0MBZXb7ZEAfQ5m5qzrkRbdw Y29k99vXennOg== Date: Mon, 23 Dec 2024 14:17:45 -0800 Subject: [PATCH 23/51] xfs_repair: repair rtbitmap and rtsummary block headers From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944156.2297565.15780880230505091475.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Check and repair the new block headers attached to rtbitmap and rtsummary blocks. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- repair/rt.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/repair/rt.c b/repair/rt.c index 102baa1d5d6186..5ba04919bc3ccf 100644 --- a/repair/rt.c +++ b/repair/rt.c @@ -237,6 +237,7 @@ check_rtfile_contents( while (bno < filelen) { struct xfs_bmbt_irec map; struct xfs_buf *bp; + unsigned int offset = 0; int nmap = 1; error = -libxfs_bmapi_read(ip, bno, 1, &map, &nmap, 0); @@ -262,7 +263,19 @@ check_rtfile_contents( break; } - check_rtwords(rtg, filename, bno, bp->b_addr, buf); + if (xfs_has_rtgroups(mp)) { + struct xfs_rtbuf_blkinfo *hdr = bp->b_addr; + + if (hdr->rt_owner != cpu_to_be64(ip->i_ino)) { + do_warn( + _("corrupt owner in %s at dblock 0x%llx\n"), + filename, (unsigned long long)bno); + } + + offset = sizeof(*hdr); + } + + check_rtwords(rtg, filename, bno, bp->b_addr + offset, buf); buf += mp->m_blockwsize << XFS_WORDLOG; bno++; From patchwork Mon Dec 23 22:18: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: 13919394 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 AA708EAF6 for ; Mon, 23 Dec 2024 22:18:01 +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=1734992281; cv=none; b=grHcHKgoZd3fIXvkz3BRz2JoqtGWyuIQ7V+R9GeoVbaRJC4hwtrQM2qbcLZaugnuOw1bNeWlJ/g0vvH9OclOrRavpjMxccvhI3IOJYVE2yQOzdSju8MnoU44EAQ3RgmAMlLnjxUP3ORME5H/AFTQJhnbcItgrdJAeFpCUm4Apjw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992281; c=relaxed/simple; bh=940WlDlONPGF50GHxfQtaghNTzV/9wRaZ0ua5Xp91RM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bjkaZNxce5V4PC+meMowojQibKHpcGYvFkwI1QnLF14tiaMIOWlC/D2+/tWMR6f81BnlITsIvWL62x9yfkXW26yfACPD/UlfpoP/B2cDvLU89axmsAUDnZWdcuKKK6uzQdfbunrQTLNRDOmUINXgVbAnT21z8STXHab77n7MYqc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mIofPENp; 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="mIofPENp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A335C4CED3; Mon, 23 Dec 2024 22:18:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992281; bh=940WlDlONPGF50GHxfQtaghNTzV/9wRaZ0ua5Xp91RM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=mIofPENpRyjzZym9UW/kjTjkADUMZQMn2rW+qHWEgrsBVlIR5GgVjnowSDxY1SpoS TKpXP+v4auXUewkq5XsYQxA1yWlLGYxY6B0FPzXE9zN4XVjGTVvOG+iqkLjgZvY+Xd rCx4aobHR9tiRC03AabXBH43r1HZ2F8G48a7h1QIQXgnxdZzwmUSeiwNxUUonJVvkl 3L9c4dtoE/P0KTEqQmMEVWlxD7z/n2WBs1a9UiJdJNWgAGV5uNGtDdGen+tqTChGDd UzKkj788lP42Z+gmE2rWLzxaJfAqRbqHgBiU6eWzH+5xUE5iLD7K9HvYTbe59fEPRZ YMAYl4JhYiMEQ== Date: Mon, 23 Dec 2024 14:18:01 -0800 Subject: [PATCH 24/51] xfs_db: enable the rtblock and rtextent commands for segmented rt block numbers From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944171.2297565.5530629850666848064.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Now that xfs_rtblock_t can be a segmented address, fix the validation in rtblock_f to handle the inputs correctly; and fix rtextent_f to do all of its conversions in linear address space. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- db/block.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/db/block.c b/db/block.c index f197e10cd5a08d..00830a3d57e1df 100644 --- a/db/block.c +++ b/db/block.c @@ -367,10 +367,23 @@ rtblock_f( dbprintf(_("bad rtblock %s\n"), argv[1]); return 0; } - if (rtbno >= mp->m_sb.sb_rblocks) { - dbprintf(_("bad rtblock %s\n"), argv[1]); - return 0; + + if (xfs_has_rtgroups(mp)) { + xfs_rgnumber_t rgno = xfs_rtb_to_rgno(mp, rtbno); + xfs_rgblock_t rgbno = xfs_rtb_to_rgbno(mp, rtbno); + + if (rgno >= mp->m_sb.sb_rgcount || + rgbno >= mp->m_sb.sb_rgextents * mp->m_sb.sb_rextsize) { + dbprintf(_("bad rtblock %s\n"), argv[1]); + return 0; + } + } else { + if (rtbno >= mp->m_sb.sb_rblocks) { + dbprintf(_("bad rtblock %s\n"), argv[1]); + return 0; + } } + ASSERT(typtab[TYP_DATA].typnm == TYP_DATA); set_rt_cur(&typtab[TYP_DATA], xfs_rtb_to_daddr(mp, rtbno), blkbb, DB_RING_ADD, NULL); @@ -392,14 +405,17 @@ rtextent_help(void) /* * Move the cursor to a specific location on the realtime block device given * a linear address in units of realtime extents. + * + * NOTE: The user interface assumes a global RT extent number, while the + * in-kernel rtx is per-RTG now, thus the odd conversions here. */ static int rtextent_f( int argc, char **argv) { - xfs_rtblock_t rtbno; - xfs_rtxnum_t rtx; + uint64_t rfsbno; + uint64_t rtx; char *p; if (argc == 1) { @@ -408,9 +424,9 @@ rtextent_f( return 0; } - rtbno = xfs_daddr_to_rtb(mp, iocur_top->off >> BBSHIFT); + rfsbno = XFS_BB_TO_FSB(mp, iocur_top->off >> BBSHIFT); dbprintf(_("current rtextent is %lld\n"), - xfs_rtb_to_rtx(mp, rtbno)); + xfs_blen_to_rtbxlen(mp, rfsbno)); return 0; } rtx = strtoull(argv[1], &p, 0); @@ -423,9 +439,9 @@ rtextent_f( return 0; } - rtbno = xfs_rtbxlen_to_blen(mp, rtx); + rfsbno = xfs_rtbxlen_to_blen(mp, rtx); ASSERT(typtab[TYP_DATA].typnm == TYP_DATA); - set_rt_cur(&typtab[TYP_DATA], xfs_rtb_to_daddr(mp, rtbno), + set_rt_cur(&typtab[TYP_DATA], XFS_FSB_TO_BB(mp, rfsbno), mp->m_sb.sb_rextsize * blkbb, DB_RING_ADD, NULL); return 0; } From patchwork Mon Dec 23 22:18:16 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: 13919395 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 452ED433D5 for ; Mon, 23 Dec 2024 22:18:17 +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=1734992297; cv=none; b=AAakeb/zaNa1x7NgLt9NmnfSGosiG4EiGr8ZdXpRUN27034CdcGAr35e7hIKpxK2NE/IFbfvV8tNGyi2cK7Msh2xK5xPo6ralbvT4O0t0wdCXFBIcGdj3oMiOhZehrMo/209DJMbabxnguaqebksim2qETJzd2X6Rf5OfmmPYLE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992297; c=relaxed/simple; bh=KP7Op/Q3TUsPKmAFZEnFy8TvqnYfuU6iwuo9VVj1dD0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ou9vpFPtz/KNLezFJSPA/XrlKr6k9OfgC3sEZ9LWl4m5NKt9iUQnXWBfurezkyHe5jZ5ac0xf6SLg5ylWekA90gilArdl16Bue/3tiSD/e+sC9u9HQJ/iHep2l5lzEuF7N+wbxGuN5P1A5q1MFqKf/U9OGVs9oy38raORLFZecM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SnXwUstl; 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="SnXwUstl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E2B4C4CED3; Mon, 23 Dec 2024 22:18:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992297; bh=KP7Op/Q3TUsPKmAFZEnFy8TvqnYfuU6iwuo9VVj1dD0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=SnXwUstlA+lTGiZyriFkZ3bDpR/V5TNQQ3Paxxc1uu9UZQzzOs7aBCeeSUkg7wb0I 1nu3J8omxC0mImAM21ZgoJrkGkI02rX8nNAx13kLWcHjBytMlS5NQdeeg3RXRbbezO YXTH+j0t+ECNrAyTLTf+Q+TTsSrlqr/vjSPve/j7FDi5k0NASy+CJjApcVv4chLU/z WJABKePJqlgZoVYhcXS9fAiOQfFEl1SNtd/KG68hn/n7wuHPGpiHGJY/Tt0WGfJHKR 2Z7YKKFyJq987D53289epVYr1E0QS2kx4MtOj2bIvRbrsHRXQRjmU2fAtpFNxp5c4F n2+U+l6mxnM/A== Date: Mon, 23 Dec 2024 14:18:16 -0800 Subject: [PATCH 25/51] xfs_db: enable rtconvert to handle segmented rtblocks From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944186.2297565.8870209811470018728.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Now that we've turned xfs_rtblock_t into a segmented address and xfs_rtxnum_t into a per-rtgroup address, port the rtconvert debugger command to handle the unit conversions correctly. Also add an example of the bitmap/summary-related conversion commands to the manpage. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- db/convert.c | 52 ++++++++++++++++++++++++++++++++++++++-------------- man/man8/xfs_db.8 | 17 +++++++++++++++-- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/db/convert.c b/db/convert.c index 0c5c942150fe6f..2cdde7d05ac397 100644 --- a/db/convert.c +++ b/db/convert.c @@ -26,14 +26,14 @@ agino_to_bytes(XFS_INO_TO_AGINO(mp, (x)))) #define inoidx_to_bytes(x) \ ((uint64_t)(x) << mp->m_sb.sb_inodelog) -#define rtblock_to_bytes(x) \ - ((uint64_t)(x) << mp->m_sb.sb_blocklog) -#define rtx_to_rtblock(x) \ - ((uint64_t)(x) * mp->m_sb.sb_rextsize) -#define rbmblock_to_bytes(x) \ - rtblock_to_bytes(rtx_to_rtblock(xfs_rbmblock_to_rtx(mp, (uint64_t)x))) -#define rbmword_to_bytes(x) \ - rtblock_to_bytes(rtx_to_rtblock((uint64_t)(x) << XFS_NBWORDLOG)) +#define rtblock_to_bytes(x) \ + (xfs_rtb_to_daddr(mp, (x)) << BBSHIFT) +#define rtx_to_bytes(x) \ + (((uint64_t)(x) * mp->m_sb.sb_rextsize) << mp->m_sb.sb_blocklog) +#define rbmblock_to_bytes(x) \ + rtx_to_bytes(xfs_rbmblock_to_rtx(mp, (x))) +#define rbmword_to_bytes(x) \ + rtx_to_bytes((uint64_t)(x) << XFS_NBWORDLOG) typedef enum { CT_NONE = -1, @@ -316,7 +316,7 @@ bytevalue(ctype_t ctype, cval_t *val) case CT_RTBLOCK: return rtblock_to_bytes(val->rtblock); case CT_RTX: - return rtblock_to_bytes(rtx_to_rtblock(val->rtx)); + return rtx_to_bytes(val->rtx); case CT_RBMBLOCK: return rbmblock_to_bytes(val->rbmblock); case CT_RBMWORD: @@ -495,6 +495,32 @@ rt_daddr_to_rsuminfo( return xfs_rtsumoffs_to_infoword(mp, rsumoff); } +/* Translate an rt device disk address to be in units of realtime extents. */ +static inline uint64_t +rt_daddr_to_rtx( + struct xfs_mount *mp, + xfs_daddr_t daddr) +{ + return XFS_BB_TO_FSBT(mp, daddr) / mp->m_sb.sb_rextsize; +} + +/* + * Compute the offset of an rt device disk address from the start of an + * rtgroup and return the result in units of realtime extents. + */ +static inline uint64_t +rt_daddr_to_rtgrtx( + struct xfs_mount *mp, + xfs_daddr_t daddr) +{ + uint64_t rtx = rt_daddr_to_rtx(mp, daddr); + + if (xfs_has_rtgroups(mp)) + return rtx % mp->m_sb.sb_rgextents; + + return rtx; +} + static int rtconvert_f(int argc, char **argv) { @@ -565,17 +591,15 @@ rtconvert_f(int argc, char **argv) v = xfs_daddr_to_rtb(mp, v >> BBSHIFT); break; case CT_RTX: - v = xfs_daddr_to_rtb(mp, v >> BBSHIFT) / mp->m_sb.sb_rextsize; + v = rt_daddr_to_rtx(mp, v >> BBSHIFT); break; case CT_RBMBLOCK: v = xfs_rtx_to_rbmblock(mp, - xfs_rtb_to_rtx(mp, - xfs_daddr_to_rtb(mp, v >> BBSHIFT))); + rt_daddr_to_rtgrtx(mp, v >> BBSHIFT)); break; case CT_RBMWORD: v = xfs_rtx_to_rbmword(mp, - xfs_rtb_to_rtx(mp, - xfs_daddr_to_rtb(mp, v >> BBSHIFT))); + rt_daddr_to_rtgrtx(mp, v >> BBSHIFT)); break; case CT_RSUMBLOCK: v = rt_daddr_to_rsumblock(mp, v); diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8 index 2325ef169ddc1b..38916036d76c03 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -1239,10 +1239,23 @@ .SH COMMANDS conversion type, and the type must be .BR rsumlog . -To compute the rt bitmap block from summary file location, the type/number pairs -must be specified exactly in the order +For example, these commands tell us where to look in the rt summary file for +the number of free rtextents of length 2^21 starting in rt bitmap block 30: + +.B rtconvert rbmblock 30 rsumlog 21 rsumblock + +.B rtconvert rbmblock 30 rsumlog 21 rsuminfo + +To compute the rt bitmap block from summary file location, the type/number +pairs must be specified exactly in the order .BR rsumlog ", " rsuminfo ", " rsumblock . +For example, this command tells us which block in the rt bitmap file is +summarized by info word 809 in rt summary block 10 assuming that the +maximum free extent length is 2^21 rtextents: + +.B rtconvert rsumlog 21 rsuminfo 809 rsumblock 10 rbmblock + .TP .BI "sb [" agno ] Set current address to SB header in allocation group From patchwork Mon Dec 23 22:18:32 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: 13919396 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 32A3BEAF6 for ; Mon, 23 Dec 2024 22:18:32 +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=1734992313; cv=none; b=BdrZgYiwVRGxY6P6JOle1ESihjQO3bJuT5JNjH3Fv/+WGfFs3ual8844wVK3a5ngbbK1M9yfz9ph73mXz1XieXAGRgRNzYd7AqEm07wabH+HGoHSIzjzacSkbgYR5tSlw40SyjSgEH+Pdq7CRoiKJ/tB48AZJJh4VqjLFvG4WVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992313; c=relaxed/simple; bh=SjR5esQM5cTgIvofWVB9FXfnr/d1oI1WvibLAOIYsWE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BLV2kb1ebJTbbU3X/utAkOn+cgXdGdKf7A9Eea+xiQc141DU0BkpeTwuaNyNwmhOpoXrFSnzK8x0YEP7IJmR+pfftnVrvsoxBWf95+QN+fyuI2Vfk1X4QEaS0XfOZEmc/vJyb1SS+5EqB0hoiU+dUz0fiktCN5BYHsN/sKrsdo8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EPVzoWGu; 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="EPVzoWGu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B58C4C4CED3; Mon, 23 Dec 2024 22:18:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992312; bh=SjR5esQM5cTgIvofWVB9FXfnr/d1oI1WvibLAOIYsWE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=EPVzoWGuiQG8um5Gfsq6Ce/03NfJ2VeNbum+KhuU2SQpFLj+KyrHW1i2jIBezz+Fx +yYqFnPPMgFEmGgbPbmcqTcoGuN+ntKpbEbbI9cl1/FwyqOMOJUTyc3PgEKW1ubIkL xQDmg+1FCgSxWzXTWpk0EUNOFfBLIdoHoRhLbLFvAGTWEsycITb3HxFCqvEIj4551d PrjCzG/G2PH2fgjqc6M0lI7TUu4jq8TrjQxPqfQn38Nwwu5kzR7Z+dReV6Asc329Dh UCNGUa6lPG9hjWxSTVLeN+nb5oryqHVJVVjCgoNGxNlTx6YVRgaHy46RHzXZflS9ZF awgA0siHqCZNQ== Date: Mon, 23 Dec 2024 14:18:32 -0800 Subject: [PATCH 26/51] xfs_db: listify the definition of enum typnm From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944202.2297565.16068425676009397741.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Convert the enum definition into a list so that future patches adding things to enum typnm don't have to reflow the entire thing. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- db/type.h | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/db/type.h b/db/type.h index 411bfe90dbc7e6..397dcf5464c6c8 100644 --- a/db/type.h +++ b/db/type.h @@ -11,11 +11,30 @@ struct field; typedef enum typnm { - TYP_AGF, TYP_AGFL, TYP_AGI, TYP_ATTR, TYP_BMAPBTA, - TYP_BMAPBTD, TYP_BNOBT, TYP_CNTBT, TYP_RMAPBT, TYP_REFCBT, TYP_DATA, - TYP_DIR2, TYP_DQBLK, TYP_INOBT, TYP_INODATA, TYP_INODE, - TYP_LOG, TYP_RTBITMAP, TYP_RTSUMMARY, TYP_SB, TYP_SYMLINK, - TYP_TEXT, TYP_FINOBT, TYP_NONE + TYP_AGF, + TYP_AGFL, + TYP_AGI, + TYP_ATTR, + TYP_BMAPBTA, + TYP_BMAPBTD, + TYP_BNOBT, + TYP_CNTBT, + TYP_RMAPBT, + TYP_REFCBT, + TYP_DATA, + TYP_DIR2, + TYP_DQBLK, + TYP_INOBT, + TYP_INODATA, + TYP_INODE, + TYP_LOG, + TYP_RTBITMAP, + TYP_RTSUMMARY, + TYP_SB, + TYP_SYMLINK, + TYP_TEXT, + TYP_FINOBT, + TYP_NONE } typnm_t; #define DB_FUZZ 2 From patchwork Mon Dec 23 22:18:47 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: 13919397 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 E5777EAF6 for ; Mon, 23 Dec 2024 22:18:48 +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=1734992329; cv=none; b=Feg06WkoloSfXFobp+8A45gayQTGWFfMKCG6CRcrHDROu0XsJ+Fx3XZzj0gCnHv2a91vMu6vTOF1udYle6nZSASOsxlb7fapbk2Dei7vsZZsy4FRanrfmhC/4tMfMoKa69MhV4uyIq8Ju2H7Mcf6qru+OATGdpP/2MSrY0RK8dk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992329; c=relaxed/simple; bh=A77+tIIqrfKLTHT6IIPlSGAV1r14WYNlef02xL3KeCw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pvmIDaGFdphZ2Whl7qKAO6CLl0VW6M0QRky8oi1QVNPqgLeC8tM+RZFuO52QFaLBmR0tgjUIQQHB4Adnlg4/e+9d2HibeHAAUJSZtyYctibf3zOWzF2la9+8F3+qxLzG96eKG0WeC97qimXNvASYkzn26xr4O/+xDEaExvBlOcU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=c6Q4kgbQ; 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="c6Q4kgbQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82135C4CEDE; Mon, 23 Dec 2024 22:18:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992328; bh=A77+tIIqrfKLTHT6IIPlSGAV1r14WYNlef02xL3KeCw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=c6Q4kgbQjk/AOMf+ITn2JVbx8vogyRbh09ni//GkLupfwy+0JUQZFLwrXWmifTxvA 6qJk3w7SBqpScTsZAHCZK5Uchpp6gaJ1iK4zWwgSQtbq5gThXENcQ4R9SuVtjFaG49 lAsbwEfjAlLiWQJByIkgmIS2hvY9z/Kthyhv1bywPg/Z3uzJGT96/4Sr+KDelt3vJ/ Kt4SxrB4BNG71RIupQcpaloFSgaqdXJNlckoizfxxhjYPTsUjJfVUlYM3f3+OecwSs mazgC4E/GZGmkqPMzLIHKKw6da4dBq2n6sZXhxwsOCXZI/Bk7zGX4u+dKIXALBEkQ5 8MGoVafFFdKvw== Date: Mon, 23 Dec 2024 14:18:47 -0800 Subject: [PATCH 27/51] xfs_db: support dumping realtime group data and superblocks From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944217.2297565.8911188121513971898.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Allow dumping of realtime device superblocks and the new fields in the primary superblock that were added for rtgroups support. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- db/Makefile | 1 + db/command.c | 2 + db/field.c | 10 ++++++ db/field.h | 5 +++ db/rtgroup.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ db/rtgroup.h | 15 +++++++++ db/sb.c | 8 +++++ db/type.c | 6 +++ db/type.h | 1 + 9 files changed, 148 insertions(+) create mode 100644 db/rtgroup.c create mode 100644 db/rtgroup.h diff --git a/db/Makefile b/db/Makefile index 83389376c36c46..02eeead25b49d0 100644 --- a/db/Makefile +++ b/db/Makefile @@ -49,6 +49,7 @@ HFILES = \ output.h \ print.h \ quit.h \ + rtgroup.h \ sb.h \ sig.h \ strvec.h \ diff --git a/db/command.c b/db/command.c index 6cda03e9856d84..1b46c3fec08a0e 100644 --- a/db/command.c +++ b/db/command.c @@ -39,6 +39,7 @@ #include "fsmap.h" #include "crc.h" #include "fuzz.h" +#include "rtgroup.h" cmdinfo_t *cmdtab; int ncmds; @@ -135,6 +136,7 @@ init_commands(void) output_init(); print_init(); quit_init(); + rtsb_init(); sb_init(); type_init(); write_init(); diff --git a/db/field.c b/db/field.c index 946684415f65d3..f70955ef57a323 100644 --- a/db/field.c +++ b/db/field.c @@ -23,6 +23,7 @@ #include "dir2.h" #include "dir2sf.h" #include "symlink.h" +#include "rtgroup.h" #define PPOFF(f) bitize(offsetof(struct xfs_parent_rec, f)) const field_t parent_flds[] = { @@ -52,6 +53,13 @@ const ftattr_t ftattrtab[] = { { FLDT_AGNUMBER, "agnumber", fp_num, "%u", SI(bitsz(xfs_agnumber_t)), FTARG_DONULL, NULL, NULL }, + { FLDT_RGBLOCK, "rgblock", fp_num, "%u", SI(bitsz(xfs_rgblock_t)), + FTARG_DONULL, NULL, NULL }, + { FLDT_RTXLEN, "rtxlen", fp_num, "%u", SI(bitsz(xfs_rtxlen_t)), + FTARG_DONULL, NULL, NULL }, + { FLDT_RGNUMBER, "rgnumber", fp_num, "%u", SI(bitsz(xfs_rgnumber_t)), + FTARG_DONULL, NULL, NULL }, + /* attr fields */ { FLDT_ATTR, "attr", NULL, (char *)attr_flds, attr_size, FTARG_SIZE, NULL, attr_flds }, @@ -357,6 +365,8 @@ const ftattr_t ftattrtab[] = { NULL, NULL }, { FLDT_SB, "sb", NULL, (char *)sb_flds, sb_size, FTARG_SIZE, NULL, sb_flds }, + { FLDT_RTSB, "rtsb", NULL, (char *)rtsb_flds, rtsb_size, FTARG_SIZE, + NULL, rtsb_flds }, /* CRC enabled symlink */ { FLDT_SYMLINK_CRC, "symlink", NULL, (char *)symlink_crc_flds, diff --git a/db/field.h b/db/field.h index 9746676a6c7ac9..8797a75f669246 100644 --- a/db/field.h +++ b/db/field.h @@ -15,6 +15,10 @@ typedef enum fldt { FLDT_AGINONN, FLDT_AGNUMBER, + FLDT_RGBLOCK, + FLDT_RTXLEN, + FLDT_RGNUMBER, + /* attr fields */ FLDT_ATTR, FLDT_ATTR_BLKINFO, @@ -167,6 +171,7 @@ typedef enum fldt { FLDT_QCNT, FLDT_QWARNCNT, FLDT_SB, + FLDT_RTSB, /* CRC enabled symlink */ FLDT_SYMLINK_CRC, diff --git a/db/rtgroup.c b/db/rtgroup.c new file mode 100644 index 00000000000000..5cda1a4f35efb6 --- /dev/null +++ b/db/rtgroup.c @@ -0,0 +1,100 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022-2024 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#include "libxfs.h" +#include "libxlog.h" +#include "command.h" +#include "type.h" +#include "faddr.h" +#include "fprint.h" +#include "field.h" +#include "io.h" +#include "sb.h" +#include "bit.h" +#include "output.h" +#include "init.h" +#include "rtgroup.h" + +#define uuid_equal(s,d) (platform_uuid_compare((s),(d)) == 0) + +static int rtsb_f(int argc, char **argv); +static void rtsb_help(void); + +static const cmdinfo_t rtsb_cmd = + { "rtsb", NULL, rtsb_f, 0, 0, 1, "", + N_("set current address to realtime sb header"), rtsb_help }; + +void +rtsb_init(void) +{ + if (xfs_has_rtgroups(mp)) + add_command(&rtsb_cmd); +} + +#define OFF(f) bitize(offsetof(struct xfs_rtsb, rsb_ ## f)) +#define SZC(f) szcount(struct xfs_rtsb, rsb_ ## f) +const field_t rtsb_flds[] = { + { "magicnum", FLDT_UINT32X, OI(OFF(magicnum)), C1, 0, TYP_NONE }, + { "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE }, + { "pad", FLDT_UINT32X, OI(OFF(pad)), C1, 0, TYP_NONE }, + { "fname", FLDT_CHARNS, OI(OFF(fname)), CI(SZC(fname)), 0, TYP_NONE }, + { "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE }, + { "meta_uuid", FLDT_UUID, OI(OFF(meta_uuid)), C1, 0, TYP_NONE }, + { NULL } +}; + +const field_t rtsb_hfld[] = { + { "", FLDT_RTSB, OI(0), C1, 0, TYP_NONE }, + { NULL } +}; + +static void +rtsb_help(void) +{ + dbprintf(_( +"\n" +" seek to realtime superblock\n" +"\n" +" Example:\n" +"\n" +" 'rtsb - set location to realtime superblock, set type to 'rtsb'\n" +"\n" +" Located in the first block of the realtime volume, the rt superblock\n" +" contains the base information for the realtime section of a filesystem.\n" +"\n" +)); +} + +static int +rtsb_f( + int argc, + char **argv) +{ + int c; + + while ((c = getopt(argc, argv, "")) != -1) { + switch (c) { + default: + rtsb_help(); + return 0; + } + } + + cur_agno = NULLAGNUMBER; + + ASSERT(typtab[TYP_RTSB].typnm == TYP_RTSB); + set_rt_cur(&typtab[TYP_RTSB], XFS_RTSB_DADDR, XFS_FSB_TO_BB(mp, 1), + DB_RING_ADD, NULL); + return 0; +} + +int +rtsb_size( + void *obj, + int startoff, + int idx) +{ + return bitize(mp->m_sb.sb_blocksize); +} diff --git a/db/rtgroup.h b/db/rtgroup.h new file mode 100644 index 00000000000000..85960a3fb9f5c9 --- /dev/null +++ b/db/rtgroup.h @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022-2024 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#ifndef DB_RTGROUP_H_ +#define DB_RTGROUP_H_ + +extern const struct field rtsb_flds[]; +extern const struct field rtsb_hfld[]; + +extern void rtsb_init(void); +extern int rtsb_size(void *obj, int startoff, int idx); + +#endif /* DB_RTGROUP_H_ */ diff --git a/db/sb.c b/db/sb.c index fa15b429ecbefa..de248c10cb27f5 100644 --- a/db/sb.c +++ b/db/sb.c @@ -127,6 +127,14 @@ const field_t sb_flds[] = { { "meta_uuid", FLDT_UUID, OI(OFF(meta_uuid)), C1, 0, TYP_NONE }, { "metadirino", FLDT_INO, OI(OFF(metadirino)), metadirfld_count, FLD_COUNT, TYP_INODE }, + { "rgcount", FLDT_RGNUMBER, OI(OFF(rgcount)), metadirfld_count, + FLD_COUNT, TYP_NONE }, + { "rgextents", FLDT_RTXLEN, OI(OFF(rgextents)), metadirfld_count, + FLD_COUNT, TYP_NONE }, + { "rgblklog", FLDT_UINT8D, OI(OFF(rgblklog)), metadirfld_count, + FLD_COUNT, TYP_NONE }, + { "pad", FLDT_UINT8X, OI(OFF(pad)), metadirfld_count, + FLD_COUNT, TYP_NONE }, { NULL } }; diff --git a/db/type.c b/db/type.c index efe7044569d357..d875c0c636553b 100644 --- a/db/type.c +++ b/db/type.c @@ -28,6 +28,7 @@ #include "text.h" #include "symlink.h" #include "fuzz.h" +#include "rtgroup.h" static const typ_t *findtyp(char *name); static int type_f(int argc, char **argv); @@ -60,6 +61,7 @@ static const typ_t __typtab[] = { { TYP_LOG, "log", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTBITMAP, "rtbitmap", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTSUMMARY, "rtsummary", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, + { TYP_RTSB, "rtsb", handle_struct, rtsb_hfld, NULL, TYP_F_NO_CRC_OFF }, { TYP_SB, "sb", handle_struct, sb_hfld, NULL, TYP_F_NO_CRC_OFF }, { TYP_SYMLINK, "symlink", handle_string, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_TEXT, "text", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, @@ -102,6 +104,8 @@ static const typ_t __typtab_crc[] = { { TYP_LOG, "log", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTBITMAP, "rtbitmap", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTSUMMARY, "rtsummary", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, + { TYP_RTSB, "rtsb", handle_struct, rtsb_hfld, &xfs_rtsb_buf_ops, + XFS_SB_CRC_OFF }, { TYP_SB, "sb", handle_struct, sb_hfld, &xfs_sb_buf_ops, XFS_SB_CRC_OFF }, { TYP_SYMLINK, "symlink", handle_struct, symlink_crc_hfld, @@ -146,6 +150,8 @@ static const typ_t __typtab_spcrc[] = { { TYP_LOG, "log", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTBITMAP, "rtbitmap", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTSUMMARY, "rtsummary", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, + { TYP_RTSB, "rtsb", handle_struct, rtsb_hfld, &xfs_rtsb_buf_ops, + XFS_SB_CRC_OFF }, { TYP_SB, "sb", handle_struct, sb_hfld, &xfs_sb_buf_ops, XFS_SB_CRC_OFF }, { TYP_SYMLINK, "symlink", handle_struct, symlink_crc_hfld, diff --git a/db/type.h b/db/type.h index 397dcf5464c6c8..d4efa4b0fab541 100644 --- a/db/type.h +++ b/db/type.h @@ -30,6 +30,7 @@ typedef enum typnm TYP_LOG, TYP_RTBITMAP, TYP_RTSUMMARY, + TYP_RTSB, TYP_SB, TYP_SYMLINK, TYP_TEXT, From patchwork Mon Dec 23 22:19:03 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: 13919411 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 667EF433D5 for ; Mon, 23 Dec 2024 22:19:04 +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=1734992344; cv=none; b=ZzyRlMOAfkd0fe1lPCmMDu4ic01rFHSnYtncyJu2MMDGzbr5zUwJLpF/GqrL3rrMu+lrr6CU8ZyMHsb8gJTlGYYXcnMpWTEp2SuoBdC2XqV4s5x9/nt0Is2OHbIw5yu/AHUFcgmW5kgtivI2v/+bHJIGMkyvmXmZNbbhf1FlDPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992344; c=relaxed/simple; bh=szUAwoQpH33ZyfTbGjooTag/k8w/1m+f3udSAmURlVw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rLfOEKsGY8b417ufH2JosR5FbXVf2KpRNW1l5LFwci4/3GVcKOP4UBWdIUy3mx62OBH3if7Ii1f6IvwCV8YR8tXiCF/pzUdLNYQYBzwmQgptJIEZReN7ZWwNBs7uMGpQp2/eYYrrCQXq2oFEVCTTaS+748oPKf/tENvG6Se7VEc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AqMFUdoQ; 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="AqMFUdoQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3ACD6C4CED7; Mon, 23 Dec 2024 22:19:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992344; bh=szUAwoQpH33ZyfTbGjooTag/k8w/1m+f3udSAmURlVw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=AqMFUdoQvNYVXvCs4jjPu7qdr6QihO0RCHigd24E3RM2WOgaiQYD4CQzzDwfindH0 hoewNScn9ntwCPiv5dDHr/GuO2nrWXD+VQJP73chTJCFRbPazgj9Fc5Cd+J93W0UlX sb1HEZZBgmecgMSZDKbyAyfLNcgxl4yVG38QY91hGnlBlI/vWYJgnIQZk2IxFGzYjr RWO6h5md5sZ6JZkcVG9R6G/O1zfa/S0w/7s86IVFJOtdGUy9YzoKJofga/RjG0vCfP DbSsOPvMLzsDKJ0hH6K5E5uYarIDUsqixE/K/wzx9E/cHah9pyVYqTNs7D+gT94AZo QDWEANFpHD3tw== Date: Mon, 23 Dec 2024 14:19:03 -0800 Subject: [PATCH 28/51] xfs_db: support changing the label and uuid of rt superblocks From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944232.2297565.2615155124288355078.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Update the label and uuid commands to change the rt superblocks along with the filesystem superblocks. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- db/sb.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 98 insertions(+), 11 deletions(-) diff --git a/db/sb.c b/db/sb.c index de248c10cb27f5..aa8fce6712e571 100644 --- a/db/sb.c +++ b/db/sb.c @@ -27,6 +27,7 @@ static int label_f(int argc, char **argv); static void label_help(void); static int version_f(int argc, char **argv); static void version_help(void); +static size_t check_label(char *label, bool can_warn); static const cmdinfo_t sb_cmd = { "sb", NULL, sb_f, 0, 1, 1, N_("[agno]"), @@ -332,6 +333,65 @@ uuid_help(void) )); } +static bool +check_rtsb( + struct xfs_mount *mp) +{ + int error; + + if (!xfs_has_realtime(mp) || !xfs_has_rtsb(mp)) + return false; + + push_cur(); + error = set_rt_cur(&typtab[TYP_RTSB], XFS_RTSB_DADDR, + XFS_FSB_TO_BB(mp, 1), DB_RING_ADD, NULL); + if (error == ENODEV) { + /* no rt dev means we should just bail out */ + pop_cur(); + return true; + } + + pop_cur(); + return false; +} + +static int +update_rtsb( + struct xfs_mount *mp, + uuid_t *uuid, + char *label) +{ + struct xfs_rtsb *rsb; + int error; + + if (!xfs_has_rtsb(mp) || !xfs_has_realtime(mp)) + return false; + + push_cur(); + error = set_rt_cur(&typtab[TYP_RTSB], XFS_RTSB_DADDR, + XFS_FSB_TO_BB(mp, 1), DB_RING_ADD, NULL); + if (error == ENODEV) { + /* no rt dev means we should just bail out */ + exitcode = 1; + pop_cur(); + return 1; + } + + rsb = iocur_top->data; + if (label) { + size_t len = check_label(label, false); + + memset(&rsb->rsb_fname, 0, XFSLABEL_MAX); + memcpy(&rsb->rsb_fname, label, len); + } + if (uuid) + memcpy(&rsb->rsb_uuid, uuid, sizeof(rsb->rsb_uuid)); + write_cur(); + pop_cur(); + + return 0; +} + static uuid_t * do_uuid(xfs_agnumber_t agno, uuid_t *uuid) { @@ -376,6 +436,7 @@ do_uuid(xfs_agnumber_t agno, uuid_t *uuid) memcpy(&tsb.sb_uuid, uuid, sizeof(uuid_t)); libxfs_sb_to_disk(iocur_top->data, &tsb); write_cur(); + memcpy(&mp->m_sb.sb_uuid, uuid, sizeof(uuid_t)); return uuid; } @@ -438,11 +499,18 @@ uuid_f( } } + if (check_rtsb(mp)) { + exitcode = 1; + return 0; + } + /* clear the log (setting uuid) if it's not dirty */ if (!sb_logzero(&uu)) return 0; dbprintf(_("writing all SBs\n")); + if (update_rtsb(mp, &uu, NULL)) + return 1; for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) if (!do_uuid(agno, &uu)) { dbprintf(_("failed to set UUID in AG %d\n"), agno); @@ -511,6 +579,27 @@ label_help(void) )); } +static size_t +check_label( + char *label, + bool can_warn) +{ + size_t len = strlen(label); + + if (len > XFSLABEL_MAX) { + if (can_warn) + dbprintf(_("%s: truncating label length from %d to %d\n"), + progname, (int)len, XFSLABEL_MAX); + len = XFSLABEL_MAX; + } + if ( len == 2 && + (strcmp(label, "\"\"") == 0 || + strcmp(label, "''") == 0 || + strcmp(label, "--") == 0) ) + label[0] = label[1] = '\0'; + return len; +} + static char * do_label(xfs_agnumber_t agno, char *label) { @@ -529,22 +618,13 @@ do_label(xfs_agnumber_t agno, char *label) return &lbl[0]; } /* set label */ - if ((len = strlen(label)) > sizeof(tsb.sb_fname)) { - if (agno == 0) - dbprintf(_("%s: truncating label length from %d to %d\n"), - progname, (int)len, (int)sizeof(tsb.sb_fname)); - len = sizeof(tsb.sb_fname); - } - if ( len == 2 && - (strcmp(label, "\"\"") == 0 || - strcmp(label, "''") == 0 || - strcmp(label, "--") == 0) ) - label[0] = label[1] = '\0'; + len = check_label(label, agno == 0); memset(&tsb.sb_fname, 0, sizeof(tsb.sb_fname)); memcpy(&tsb.sb_fname, label, len); memcpy(&lbl[0], &tsb.sb_fname, sizeof(tsb.sb_fname)); libxfs_sb_to_disk(iocur_top->data, &tsb); write_cur(); + memcpy(&mp->m_sb.sb_fname, &tsb.sb_fname, XFSLABEL_MAX); return &lbl[0]; } @@ -576,7 +656,14 @@ label_f( return 0; } + if (check_rtsb(mp)) { + exitcode = 1; + return 0; + } + dbprintf(_("writing all SBs\n")); + if (update_rtsb(mp, NULL, argv[1])) + return 1; for (ag = 0; ag < mp->m_sb.sb_agcount; ag++) if ((p = do_label(ag, argv[1])) == NULL) { dbprintf(_("failed to set label in AG %d\n"), ag); From patchwork Mon Dec 23 22:19:19 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: 13919412 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 63E05EAF6 for ; Mon, 23 Dec 2024 22:19: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=1734992360; cv=none; b=LKomaMR5MvPMWn+newgr+u2eiXPc+PMTJ3A3GB9doQ4TuZc80ovS+QWBU2Uqz1aj3xUNqEuaLmCINu0kZ8fLfYOYP+96ED85dDHueKmoV/ExIn34Y9W/Fo+bDerL7vXpqHUSHCR5DC/pg4/Q+z8ggFjqVa+jWS3b8eaxWXyMaNE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992360; c=relaxed/simple; bh=UU+Xiph57lZ3DZiK3m+JoI05T7pHOSur3BCWv1hioN0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mqc648d9v5TB9hXMjhPXo/zOEIoaMoH56PMH9w1O/3lc71AGt+xZxux20ryLXShNJyM+bVCnKd15LwqOx1lJWItitgouWWsgu7GC49f6dtwRGY/nKFAE3vCNK/PXxWe7TTlmOR8LDgItTtpCexQgk19Eqz95tCn1q0tfvL5fej0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XzR/IXTY; 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="XzR/IXTY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB9BBC4CEDE; Mon, 23 Dec 2024 22:19:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992359; bh=UU+Xiph57lZ3DZiK3m+JoI05T7pHOSur3BCWv1hioN0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=XzR/IXTYgVYtIqyjcFKCTezkq611D/PjLndWNlkQwGQudoKlYUyDPJFZXQz/ywnjK ztwCkb7dDXoq9LMbVmbQlFtJm3lu9K2TSNE7lUIJrr748GsvfJp1t+Oa6YLRqfTx/v d8kVr3d9CsLUUERtGKp9AQRXsFJRzRPXTfW4Gzp2QF4wWQI0PRAkYYaea1zoDEKFY4 LCpPl7ow5M87n6HqTHegh01se+Wh0Ai9pP+hn1P37kBBWMcf5q2+LJk8zvhazQjku0 FZH8Nb75P83Co4D0SO0oEsTdM0F/XS1X/844zdNPaRJ8a3HyLAQFwF5UgMwDXEHSft 6bOhxIxQJ5sKw== Date: Mon, 23 Dec 2024 14:19:19 -0800 Subject: [PATCH 29/51] xfs_db: enable conversion of rt space units From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944247.2297565.6757015588226739985.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Teach the xfs_db convert function about realtime extents, blocks, and realtime group numbers. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- db/convert.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++- man/man8/xfs_db.8 | 17 +++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/db/convert.c b/db/convert.c index 2cdde7d05ac397..47d3e86fdc4ef2 100644 --- a/db/convert.c +++ b/db/convert.c @@ -34,6 +34,21 @@ rtx_to_bytes(xfs_rbmblock_to_rtx(mp, (x))) #define rbmword_to_bytes(x) \ rtx_to_bytes((uint64_t)(x) << XFS_NBWORDLOG) +#define rgblock_to_bytes(x) \ + ((uint64_t)(x) << mp->m_sb.sb_blocklog) +#define rgnumber_to_bytes(x) \ + rgblock_to_bytes((uint64_t)(x) * mp->m_groups[XG_TYPE_RTG].blocks) + +static inline xfs_rgnumber_t +xfs_daddr_to_rgno( + struct xfs_mount *mp, + xfs_daddr_t daddr) +{ + if (!xfs_has_rtgroups(mp)) + return 0; + + return XFS_BB_TO_FSBT(mp, daddr) / mp->m_groups[XG_TYPE_RTG].blocks; +} typedef enum { CT_NONE = -1, @@ -55,6 +70,8 @@ typedef enum { CT_RSUMBLOCK, /* block within rt summary */ CT_RSUMLOG, /* log level for rtsummary computations */ CT_RSUMINFO, /* info word within rt summary */ + CT_RGBLOCK, /* xfs_rgblock_t */ + CT_RGNUMBER, /* xfs_rgno_t */ NCTS } ctype_t; @@ -80,6 +97,8 @@ typedef union { xfs_fileoff_t rbmblock; unsigned int rbmword; xfs_fileoff_t rsumblock; + xfs_rgnumber_t rgnumber; + xfs_rgblock_t rgblock; } cval_t; static uint64_t bytevalue(ctype_t ctype, cval_t *val); @@ -95,7 +114,7 @@ static const char *agnumber_names[] = { "agnumber", "agno", NULL }; static const char *bboff_names[] = { "bboff", "daddroff", NULL }; static const char *blkoff_names[] = { "blkoff", "fsboff", "agboff", NULL }; -static const char *rtblkoff_names[] = { "blkoff", "rtboff", +static const char *rtblkoff_names[] = { "blkoff", "rtboff", "rgboff", NULL }; static const char *byte_names[] = { "byte", "fsbyte", NULL }; static const char *daddr_names[] = { "daddr", "bb", NULL }; @@ -111,6 +130,8 @@ static const char *rbmword_names[] = { "rbmword", "rbmw", NULL }; static const char *rsumblock_names[] = { "rsumblock", "rsmb", NULL }; static const char *rsumlog_names[] = { "rsumlog", "rsml", NULL }; static const char *rsumword_names[] = { "rsuminfo", "rsmi", NULL }; +static const char *rgblock_names[] = { "rgblock", "rgbno", NULL }; +static const char *rgnumber_names[] = { "rgnumber", "rgno", NULL }; static int rsuminfo; static int rsumlog; @@ -244,6 +265,22 @@ static const ctydesc_t ctydescs_rt[NCTS] = { .allowed = M(RSUMBLOCK), .names = rsumword_names, }, + [CT_RGBLOCK] = { + .allowed = M(RGNUMBER) | + M(BBOFF) | + M(BLKOFF) | + M(RSUMLOG), + .names = rgblock_names, + }, + [CT_RGNUMBER] = { + .allowed = M(RGBLOCK) | + M(BBOFF) | + M(BLKOFF) | + M(RSUMLOG) | + M(RBMBLOCK) | + M(RBMWORD), + .names = rgnumber_names, + }, }; static const cmdinfo_t convert_cmd = @@ -331,6 +368,10 @@ bytevalue(ctype_t ctype, cval_t *val) * value. */ return 0; + case CT_RGBLOCK: + return rgblock_to_bytes(val->rgblock); + case CT_RGNUMBER: + return rgnumber_to_bytes(val->rgnumber); case CT_NONE: case NCTS: break; @@ -437,6 +478,8 @@ convert_f(int argc, char **argv) case CT_RSUMBLOCK: case CT_RSUMLOG: case CT_RSUMINFO: + case CT_RGBLOCK: + case CT_RGNUMBER: /* shouldn't get here */ ASSERT(0); break; @@ -521,6 +564,17 @@ rt_daddr_to_rtgrtx( return rtx; } +static inline xfs_rgblock_t +rt_daddr_to_rgbno( + struct xfs_mount *mp, + xfs_daddr_t daddr) +{ + if (!xfs_has_rtgroups(mp)) + return 0; + + return XFS_BB_TO_FSBT(mp, daddr) % mp->m_groups[XG_TYPE_RTG].blocks; +} + static int rtconvert_f(int argc, char **argv) { @@ -611,6 +665,12 @@ rtconvert_f(int argc, char **argv) case CT_RSUMINFO: v = rt_daddr_to_rsuminfo(mp, v); break; + case CT_RGBLOCK: + v = rt_daddr_to_rgbno(mp, v >> BBSHIFT); + break; + case CT_RGNUMBER: + v = xfs_daddr_to_rgno(mp, v >> BBSHIFT); + break; case CT_AGBLOCK: case CT_AGINO: case CT_AGNUMBER: @@ -703,6 +763,12 @@ getvalue(char *s, ctype_t ctype, cval_t *val) case CT_RSUMINFO: rsuminfo = (unsigned int)v; break; + case CT_RGBLOCK: + val->rgblock = (xfs_rgblock_t)v; + break; + case CT_RGNUMBER: + val->rgnumber = (xfs_rgnumber_t)v; + break; case CT_NONE: case NCTS: /* NOTREACHED */ diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8 index 38916036d76c03..06f4464a928596 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -1162,6 +1162,16 @@ .SH COMMANDS .RS 1.0i .PD 0 .HP +.B rgblock +or +.B rgbno +(realtime block within a realtime group) +.HP +.B rgnumber +or +.B rgno +(realtime group number) +.HP .B bboff or .B daddroff @@ -1229,6 +1239,13 @@ .SH COMMANDS .RE .IP Only conversions that "make sense" are allowed. +The compound form (with more than three arguments) is useful for +conversions such as +.B convert rgno +.I rg +.B rgbno +.I rgb +.BR rtblock . Realtime summary file location conversions have the following rules: Each info word in the rt summary file counts the number of free extents of a From patchwork Mon Dec 23 22:19: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: 13919413 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 DFC96188596 for ; Mon, 23 Dec 2024 22:19:35 +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=1734992376; cv=none; b=uNoRvPxrDIOLd4cbCQWnMzS2HhCgIGTpgfWNrtVv10ZPhw4wYpqyC+oVZ/ztj929YhKATqKsPNeHXxp3OffXBjBRMKVLiqsThS4D6AkWTgQHpOVRYIiVBZS5UooSJ6zN/ik8vqD9AnsMqHcskdpGVhZBhLhMLrCM5cVs/pfo8VM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992376; c=relaxed/simple; bh=MAXN88n4DMTn1aHwrlxaf67GCDsL31mKQ37UoFHtCLs=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SXIAI+ZborRaz8w19gqVWEwjskZuVxgLgz7pwyIVN8TwWX48kxGbWIfqSsbisOvFkUS2q5fXjo/uzlqqwmnXZmPrr7t42DzKP2CaEMc6QhBqHAp9wIUqlX0MbA8iA79+0QPrQ3ol+UwXNfvNZjkSGNu3C5lhU7tFjxHLykHbRys= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CWIbM5Ve; 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="CWIbM5Ve" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7BBE8C4CED3; Mon, 23 Dec 2024 22:19:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992375; bh=MAXN88n4DMTn1aHwrlxaf67GCDsL31mKQ37UoFHtCLs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=CWIbM5VejgKrBJbAzROdPk9vaIa1nVsMk6Dang6jCCUmg/ofBM9cTKQrVxPgg9/47 VUVE50uSkCWOWd3JuTf1AAZAj97ry3B/QsXzKpPqb1otLrZUVB2U0AfpbMxLs5zRn6 RjqFkD69F1yMuY9yX8EdhYGrLScyzFt38fInCjVQrb/fTm/t6fjOCy8tafxENKKNwr n6arVrn45npJoeDdPJIgvnhc0bQxkdquF34unyUqASHj2VhR+jrStnjE5U1lsxZzNr eyPOsMJWixVNUZ4rYM8Qg4jSDSKko4L6s4I2TLcPl0KW6yjErX8nJtafTb2klbPD+Z GYmHuFrm55QYg== Date: Mon, 23 Dec 2024 14:19:35 -0800 Subject: [PATCH 30/51] xfs_db: metadump metadir rt bitmap and summary files From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944263.2297565.11753153507899715984.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Don't skip dumping the data fork for regular files that are marked as metadata inodes. This catches rtbitmap and summary inodes on rtgroup enabled file systems where their inode numbers aren't recorded in the superblock. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- db/metadump.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/db/metadump.c b/db/metadump.c index 144ebfbfe2a90e..8eb4b8eb69e45c 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -2072,7 +2072,11 @@ process_bmbt_reclist( xfs_agblock_t agbno; int rval = 1; - if (btype == TYP_DATA) + /* + * Ignore regular file data except for metadata inodes, where it is by + * definition metadata. + */ + if (btype == TYP_DATA && !is_metadata_ino(dip)) return 1; convert_extent(&rp[numrecs - 1], &o, &s, &c, &f); From patchwork Mon Dec 23 22:19:50 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: 13919414 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 52C16188596 for ; Mon, 23 Dec 2024 22:19:51 +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=1734992391; cv=none; b=hIi3FiEP/fBy7o1Fx8YofuCgT5Ebp7PGpx/Bhq5VDq16hyfaInHUQm5BvpwoJlN361khF/LnApplLCHyqmWaf8DIanIxMdtRm+p0I5Ltqjs+3JX6up5TxK/gcubE1/Z7pmfZe7MY8F2EFAseI8rfe9gYFd+GWTATR483y/9Y43k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992391; c=relaxed/simple; bh=g8/r9OlKFurHj39yWAEyAJbL0q8YdLIRk3inqBdBzMs=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ijVfQdBvwbgdW4hh52h2hbejyUB+cc9JaSCkJIUpvZLqgIGB+V4B7aRphI0/sPdKIKzAjSDFFEKeuJn1unx23rW6NzZR64QadInYTBcQ7K8iodfLvfe8ofOpu8FOx0cO4PfL6dIkjlp3L/zusk5G7B6JAzXEEbz7i7glnppPNY8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DQ7gpkwk; 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="DQ7gpkwk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26D70C4CED3; Mon, 23 Dec 2024 22:19:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992391; bh=g8/r9OlKFurHj39yWAEyAJbL0q8YdLIRk3inqBdBzMs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=DQ7gpkwkMYLsBMuUCkmaX7uzchQEKUdW0DWA5lG0Pwe8JM9wvWvUk8Q8nkdggTZ7G /g3UD4wTbsHNKSSz3Xdt0UnxuFF5m73tew9zZ5bZtKlTYQL8sVreNIX0lPTG/XVp6G CjqdsE3B6rDseEUurJd+zvs20aZPUXc3nWxN4qJLEaUxW/8Ih58xihSiQxCK2snzcn ZtWsS03Zl8EUOGd2UlogJpiHLxDQavZdBkTWtN7DRCZE+kLsB0LxG6ASeTmE9gM2cd Z7Cyeorc6IEpf0ZOkfpxM45PBUUYi1Y3AbB/cDzrBNRY+OpTWwBmSEwH0lyNmGROJf Q7qsjuBIXYaiw== Date: Mon, 23 Dec 2024 14:19:50 -0800 Subject: [PATCH 31/51] xfs_db: metadump realtime devices From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944278.2297565.16551495246381084206.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Teach the metadump device to dump the filesystem metadata of a realtime device to the metadump file. Currently, this is limited to the realtime superblock. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- db/metadump.c | 53 +++++++++++++++++++++++++++++++++++++++++++++ db/xfs_metadump.sh | 5 +++- include/xfs_metadump.h | 8 +++++++ man/man8/xfs_metadump.8 | 11 +++++++++ mdrestore/xfs_mdrestore.c | 5 +++- 5 files changed, 79 insertions(+), 3 deletions(-) diff --git a/db/metadump.c b/db/metadump.c index 8eb4b8eb69e45c..4f4b4f8a39a551 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -85,6 +85,7 @@ static struct metadump { bool dirty_log; bool external_log; bool stdout_metadump; + bool realtime_data; xfs_ino_t cur_ino; /* Metadump file */ FILE *outf; @@ -3027,6 +3028,7 @@ init_metadump_v2(void) { struct xfs_metadump_header xmh = {0}; uint32_t compat_flags = 0; + uint32_t incompat_flags = 0; xmh.xmh_magic = cpu_to_be32(XFS_MD_MAGIC_V2); xmh.xmh_version = cpu_to_be32(2); @@ -3039,8 +3041,11 @@ init_metadump_v2(void) compat_flags |= XFS_MD2_COMPAT_DIRTYLOG; if (metadump.external_log) compat_flags |= XFS_MD2_COMPAT_EXTERNALLOG; + if (metadump.realtime_data) + incompat_flags |= XFS_MD2_INCOMPAT_RTDEVICE; xmh.xmh_compat_flags = cpu_to_be32(compat_flags); + xmh.xmh_incompat_flags = cpu_to_be32(incompat_flags); if (fwrite(&xmh, sizeof(xmh), 1, metadump.outf) != 1) { print_warning("error writing to target file"); @@ -3050,6 +3055,30 @@ init_metadump_v2(void) return 0; } +static int +copy_rtsb(void) +{ + int error; + + if (metadump.show_progress) + print_progress("Copying realtime superblock"); + + push_cur(); + error = set_rt_cur(&typtab[TYP_RTSB], XFS_RTSB_DADDR, + XFS_FSB_TO_BB(mp, 1), DB_RING_ADD, NULL); + if (error) + return 0; + if (iocur_top->data == NULL) { + pop_cur(); + print_warning("cannot read realtime superblock"); + return !metadump.stop_on_read_error; + } + error = write_buf(iocur_top); + pop_cur(); + + return error ? 0 : 1; +} + static int write_metadump_v2( enum typnm type, @@ -3064,6 +3093,8 @@ write_metadump_v2( if (type == TYP_LOG && mp->m_logdev_targp->bt_bdev != mp->m_ddev_targp->bt_bdev) addr |= XME_ADDR_LOG_DEVICE; + else if (type == TYP_RTSB) + addr |= XME_ADDR_RT_DEVICE; else addr |= XME_ADDR_DATA_DEVICE; @@ -3112,6 +3143,7 @@ metadump_f( metadump.zero_stale_data = true; metadump.dirty_log = false; metadump.external_log = false; + metadump.realtime_data = false; if (mp->m_sb.sb_magicnum != XFS_SB_MAGIC) { print_warning("bad superblock magic number %x, giving up", @@ -3190,6 +3222,21 @@ metadump_f( return 1; } + /* + * The realtime device only contains metadata if the RT superblock is + * enabled. + */ + if (xfs_has_realtime(mp) && xfs_has_rtsb(mp)) { + if (mp->m_rtdev_targp->bt_bdev) { + metadump.realtime_data = true; + if (!version_opt_set) + metadump.version = 2; + } else if (metadump.version == 2 && !metadump.realtime_data) { + print_warning("realtime device not loaded, use -R"); + return 1; + } + } + /* * If we'll copy the log, see if the log is dirty. * @@ -3289,6 +3336,12 @@ metadump_f( if (!exitcode && !(metadump.version == 1 && metadump.external_log)) exitcode = !copy_log(); + /* copy rt superblock */ + if (!exitcode && metadump.realtime_data && xfs_has_rtsb(mp)) { + if (!copy_rtsb()) + exitcode = 1; + } + /* write the remaining index */ if (!exitcode && metadump.mdops->finish_dump) exitcode = metadump.mdops->finish_dump() < 0; diff --git a/db/xfs_metadump.sh b/db/xfs_metadump.sh index 9e8f86e53eb45d..b5c6959f2007f8 100755 --- a/db/xfs_metadump.sh +++ b/db/xfs_metadump.sh @@ -6,9 +6,9 @@ OPTS=" " DBOPTS=" " -USAGE="Usage: xfs_metadump [-aefFogwV] [-m max_extents] [-l logdev] source target" +USAGE="Usage: xfs_metadump [-aefFogwV] [-m max_extents] [-l logdev] [-r rtdev] [-v version] source target" -while getopts "aefgl:m:owFv:V" c +while getopts "aefFgl:m:or:wv:V" c do case $c in a) OPTS=$OPTS"-a ";; @@ -25,6 +25,7 @@ do status=$? exit $status ;; + r) DBOPTS=$DBOPTS"-R "$OPTARG" ";; \?) echo $USAGE 1>&2 exit 2 ;; diff --git a/include/xfs_metadump.h b/include/xfs_metadump.h index e9c3dcb8f711b9..e35f791573efc2 100644 --- a/include/xfs_metadump.h +++ b/include/xfs_metadump.h @@ -68,12 +68,18 @@ struct xfs_metadump_header { /* Dump contains external log contents. */ #define XFS_MD2_COMPAT_EXTERNALLOG (1 << 3) +/* Dump contains realtime device contents. */ +#define XFS_MD2_INCOMPAT_RTDEVICE (1U << 0) + +#define XFS_MD2_INCOMPAT_ALL (XFS_MD2_INCOMPAT_RTDEVICE) + struct xfs_meta_extent { /* * Lowest 54 bits are used to store 512 byte addresses. * Next 2 bits is used for indicating the device. * 00 - Data device * 01 - External log + * 10 - Realtime device */ __be64 xme_addr; /* In units of 512 byte blocks */ @@ -88,6 +94,8 @@ struct xfs_meta_extent { #define XME_ADDR_DATA_DEVICE (0ULL << XME_ADDR_DEVICE_SHIFT) /* Extent was copied from the log device */ #define XME_ADDR_LOG_DEVICE (1ULL << XME_ADDR_DEVICE_SHIFT) +/* Extent was copied from the rt device */ +#define XME_ADDR_RT_DEVICE (2ULL << XME_ADDR_DEVICE_SHIFT) #define XME_ADDR_DEVICE_MASK (3ULL << XME_ADDR_DEVICE_SHIFT) diff --git a/man/man8/xfs_metadump.8 b/man/man8/xfs_metadump.8 index 496b5926603f48..8618ea99b9a57e 100644 --- a/man/man8/xfs_metadump.8 +++ b/man/man8/xfs_metadump.8 @@ -12,6 +12,9 @@ .SH SYNOPSIS .B \-l .I logdev ] [ +.B \-r +.I rtdev +] [ .B \-v .I version ] @@ -146,6 +149,14 @@ .SH OPTIONS .B \-o Disables obfuscation of file names and extended attributes. .TP +.BI \-r " rtdev" +For filesystems that have a realtime section, this specifies the device where +the realtime section resides. +If the v2 metadump format is selected, the realtime group superblocks will be +copied to the metadump. +The v2 metadump format will be selected automatically if the filesystem +contains realtime groups. +.TP .B \-v The format of the metadump file to be produced. Valid values are 1 and 2. diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index 269edb8f89969d..c6c00270234442 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -314,7 +314,7 @@ read_header_v2( sizeof(h->v2) - sizeof(h->v2.xmh_magic), 1, md_fp) != 1) fatal("error reading from metadump file\n"); - if (h->v2.xmh_incompat_flags != 0) + if (h->v2.xmh_incompat_flags & cpu_to_be32(~XFS_MD2_INCOMPAT_ALL)) fatal("Metadump header has unknown incompat flags set\n"); if (h->v2.xmh_reserved != 0) @@ -324,6 +324,9 @@ read_header_v2( if (!mdrestore.external_log && (compat & XFS_MD2_COMPAT_EXTERNALLOG)) fatal("External Log device is required\n"); + + if (h->v2.xmh_incompat_flags & cpu_to_be32(XFS_MD2_INCOMPAT_RTDEVICE)) + fatal("Realtime device not yet supported\n"); } static void From patchwork Mon Dec 23 22:20:06 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: 13919415 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 591CA188596 for ; Mon, 23 Dec 2024 22:20: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=1734992407; cv=none; b=e+BzWtBJvEqiU/aRkrRuBM8q4U2Pc4t1jP28Eyqm7pymdD+e+o1QplCH60yXUs6uoUGo5F8rwpniUMggQy6VHdmqNTA7NVs9LWnAnQ5+Bd02Tru6cYlBz+3BE83oYZDhOug4HyxEPuxf58rsRuz9Lgmzn8kunsVEYJ5bwGYtx3w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992407; c=relaxed/simple; bh=PEZ2ky32n9Js0ZUsb23cHLS4beIPw4po4MONvRTJ0tI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OQrbGmgHAbG5jgd0j3zZ2VLnnewVW+DWXpVLkG0+J/Vprml7eowwPdPyWg7BYD+LWTEXxDyAMU1MgqPmnqMo3wbGghdoFGHpzsj4nv2xmQVpccHlbycHqN6sn1PrTev+wRT8nyHI+U0d3X9QnxEp3ZDhPQoO/2mNgXfbsZELVlA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aPLdEmBN; 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="aPLdEmBN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0079FC4CEE5; Mon, 23 Dec 2024 22:20:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992407; bh=PEZ2ky32n9Js0ZUsb23cHLS4beIPw4po4MONvRTJ0tI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=aPLdEmBNaBu+2/RS6wFCspA2p4XsLkFRsGKTapI8KyxS+1waKPq9IY+YGA3t4eCFI 5gAAlht6ePJLdJI7ez+Z5CkdpOApGfrStDgtDb/EbWaaCoGFN7yMyUOVPuPp9ByZBU TYo6SMEchyb1yUk83uBXnEQqSrLUPqjvGQfWRuu0Gx9qmFysTx+SCrRu4pCZHvzeGb tdgkPXliSlOoq+ICPy27u6vC60e0JrvL1JQY4DHcUI3UKSWNX1UahideCyj3CzsIru LM3V1NUi75lITax25NxlPhyT3NMawq9O3q3cpVZ/KoK6DehJCvKuxaKUAs7YRvueJf jO1FRsEF4JU7Q== Date: Mon, 23 Dec 2024 14:20:06 -0800 Subject: [PATCH 32/51] xfs_db: dump rt bitmap blocks From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944293.2297565.14382052320051831234.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Now that rtbitmap blocks have a header, make it so that xfs_db can analyze the structure. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- db/field.c | 6 ++++++ db/field.h | 3 +++ db/inode.c | 34 +++++++++++++++++++++++++--------- db/rtgroup.c | 34 ++++++++++++++++++++++++++++++++++ db/rtgroup.h | 3 +++ db/type.c | 5 +++++ db/type.h | 1 + 7 files changed, 77 insertions(+), 9 deletions(-) diff --git a/db/field.c b/db/field.c index f70955ef57a323..ad1ccb9877aca5 100644 --- a/db/field.c +++ b/db/field.c @@ -406,6 +406,12 @@ const ftattr_t ftattrtab[] = { { FLDT_UUID, "uuid", fp_uuid, NULL, SI(bitsz(uuid_t)), 0, NULL, NULL }, { FLDT_PARENT_REC, "parent", NULL, (char *)parent_flds, SI(bitsz(struct xfs_parent_rec)), 0, NULL, parent_flds }, + + { FLDT_RTWORD, "rtword", fp_num, "%#x", SI(bitsz(xfs_rtword_t)), + 0, NULL, NULL }, + { FLDT_RGBITMAP, "rgbitmap", NULL, (char *)rgbitmap_flds, btblock_size, + FTARG_SIZE, NULL, rgbitmap_flds }, + { FLDT_ZZZ, NULL } }; diff --git a/db/field.h b/db/field.h index 8797a75f669246..aace89c90d79eb 100644 --- a/db/field.h +++ b/db/field.h @@ -196,6 +196,9 @@ typedef enum fldt { FLDT_PARENT_REC, + FLDT_RTWORD, + FLDT_RGBITMAP, + FLDT_ZZZ /* mark last entry */ } fldt_t; diff --git a/db/inode.c b/db/inode.c index 07efbb4902be08..d3207510c28265 100644 --- a/db/inode.c +++ b/db/inode.c @@ -705,16 +705,32 @@ inode_next_type(void) case S_IFLNK: return TYP_SYMLINK; case S_IFREG: - if (iocur_top->ino == mp->m_sb.sb_rbmino) - return TYP_RTBITMAP; - else if (iocur_top->ino == mp->m_sb.sb_rsumino) - return TYP_RTSUMMARY; - else if (iocur_top->ino == mp->m_sb.sb_uquotino || - iocur_top->ino == mp->m_sb.sb_gquotino || - iocur_top->ino == mp->m_sb.sb_pquotino) + if (xfs_has_rtgroups(mp)) { + struct xfs_dinode *dic = iocur_top->data; + + switch (be16_to_cpu(dic->di_metatype)) { + case XFS_METAFILE_USRQUOTA: + case XFS_METAFILE_GRPQUOTA: + case XFS_METAFILE_PRJQUOTA: + return TYP_DQBLK; + case XFS_METAFILE_RTBITMAP: + return TYP_RGBITMAP; + default: + return TYP_DATA; + } + } else { + if (iocur_top->ino == mp->m_sb.sb_rbmino) + return TYP_RTBITMAP; + if (iocur_top->ino == mp->m_sb.sb_rsumino) + return TYP_RTSUMMARY; + } + + if (iocur_top->ino == mp->m_sb.sb_uquotino || + iocur_top->ino == mp->m_sb.sb_gquotino || + iocur_top->ino == mp->m_sb.sb_pquotino) return TYP_DQBLK; - else - return TYP_DATA; + + return TYP_DATA; default: return TYP_NONE; } diff --git a/db/rtgroup.c b/db/rtgroup.c index 5cda1a4f35efb6..3ef2dc8fe7f031 100644 --- a/db/rtgroup.c +++ b/db/rtgroup.c @@ -44,6 +44,7 @@ const field_t rtsb_flds[] = { { "meta_uuid", FLDT_UUID, OI(OFF(meta_uuid)), C1, 0, TYP_NONE }, { NULL } }; +#undef OFF const field_t rtsb_hfld[] = { { "", FLDT_RTSB, OI(0), C1, 0, TYP_NONE }, @@ -98,3 +99,36 @@ rtsb_size( { return bitize(mp->m_sb.sb_blocksize); } + +static int +rtwords_count( + void *obj, + int startoff) +{ + unsigned int blksz = mp->m_sb.sb_blocksize; + + if (xfs_has_rtgroups(mp)) + blksz -= sizeof(struct xfs_rtbuf_blkinfo); + + return blksz >> XFS_WORDLOG; +} + +#define OFF(f) bitize(offsetof(struct xfs_rtbuf_blkinfo, rt_ ## f)) +const field_t rgbitmap_flds[] = { + { "magicnum", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE }, + { "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE }, + { "owner", FLDT_INO, OI(OFF(owner)), C1, 0, TYP_NONE }, + { "bno", FLDT_DFSBNO, OI(OFF(blkno)), C1, 0, TYP_BMAPBTD }, + { "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE }, + { "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE }, + /* the rtword array is after the actual structure */ + { "rtwords", FLDT_RTWORD, OI(bitize(sizeof(struct xfs_rtbuf_blkinfo))), + rtwords_count, FLD_ARRAY | FLD_COUNT, TYP_DATA }, + { NULL } +}; +#undef OFF + +const field_t rgbitmap_hfld[] = { + { "", FLDT_RGBITMAP, OI(0), C1, 0, TYP_NONE }, + { NULL } +}; diff --git a/db/rtgroup.h b/db/rtgroup.h index 85960a3fb9f5c9..06f554e1862851 100644 --- a/db/rtgroup.h +++ b/db/rtgroup.h @@ -9,6 +9,9 @@ extern const struct field rtsb_flds[]; extern const struct field rtsb_hfld[]; +extern const struct field rgbitmap_flds[]; +extern const struct field rgbitmap_hfld[]; + extern void rtsb_init(void); extern int rtsb_size(void *obj, int startoff, int idx); diff --git a/db/type.c b/db/type.c index d875c0c636553b..65e7b24146f170 100644 --- a/db/type.c +++ b/db/type.c @@ -67,6 +67,7 @@ static const typ_t __typtab[] = { { TYP_TEXT, "text", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_FINOBT, "finobt", handle_struct, finobt_hfld, NULL, TYP_F_NO_CRC_OFF }, + { TYP_RGBITMAP, NULL }, { TYP_NONE, NULL } }; @@ -113,6 +114,8 @@ static const typ_t __typtab_crc[] = { { TYP_TEXT, "text", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_FINOBT, "finobt", handle_struct, finobt_crc_hfld, &xfs_finobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, + { TYP_RGBITMAP, "rgbitmap", handle_struct, rgbitmap_hfld, + &xfs_rtbitmap_buf_ops, XFS_RTBUF_CRC_OFF }, { TYP_NONE, NULL } }; @@ -159,6 +162,8 @@ static const typ_t __typtab_spcrc[] = { { TYP_TEXT, "text", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_FINOBT, "finobt", handle_struct, finobt_spcrc_hfld, &xfs_finobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, + { TYP_RGBITMAP, "rgbitmap", handle_struct, rgbitmap_hfld, + &xfs_rtbitmap_buf_ops, XFS_RTBUF_CRC_OFF }, { TYP_NONE, NULL } }; diff --git a/db/type.h b/db/type.h index d4efa4b0fab541..e2148c6351d141 100644 --- a/db/type.h +++ b/db/type.h @@ -35,6 +35,7 @@ typedef enum typnm TYP_SYMLINK, TYP_TEXT, TYP_FINOBT, + TYP_RGBITMAP, TYP_NONE } typnm_t; From patchwork Mon Dec 23 22:20: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: 13919416 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 02F3C433D5 for ; Mon, 23 Dec 2024 22:20:22 +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=1734992423; cv=none; b=WcCBMNkzi2zXoLpF6laCAE0d/p8bU3vmCiQbtgM7P9oCQtkLaFeoY9aphJx5eK3zVTvSg0qjSgB1xIsSJ95Kq2yp3Q9ffGj7rQmzdcMHarKQnKYsb4Zuo4yLm/PB606HBZFLaWKx+K8llRtMrx1kxmt5AtYF2hCrJQcMIqhadFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992423; c=relaxed/simple; bh=wU4pnZG3gFRTck1Lw2Gf8aEZZ9N3u9N+wyVlBOgVI5E=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OU3TyV8GVeZoOM4I2FPsoYmOcZPKj675zgVVMNeOuw+p+qQNV1EGiJJ1QKc/w56Jytuqj5zKfOIe+vrGhhZtoZbV8lFN/SsNPT5qon2lXCafJop0uQmU4TQ4jd5xomoZiM4qmvyId23FR6CoFJR26w3kaoOo43sMm8mok/GD5is= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IwUVF9YI; 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="IwUVF9YI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE9BAC4CED3; Mon, 23 Dec 2024 22:20:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992422; bh=wU4pnZG3gFRTck1Lw2Gf8aEZZ9N3u9N+wyVlBOgVI5E=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=IwUVF9YIyFoTnQOtqq7PEyAQDrFb0WLHdc4zxp0KsEfh0KXVj5FteLWNZs8x8uNjs x5X8dtvKgj2qY4Ys4cKYgPtYod+Pxg3c9fSuVRUqFsb10BSeO8xBt4VKGIwOKWtrkE MT/iIQUDQ5fnhKB1ZeiS3Uen8LCP6S/T3HztA2b2P7qEjSKINl48kz5HaK0LXGykKj HPk9wQ//UcOjpSIGX+XXRBarMHB/clDjl8OHVYVrtiMwBabS5CoUH4vJwx+wVAbMKW hZJI8ItoOONQcmsz5frvHX6fYV7C3D/yCa1LHxGX1gUKuOTnpcDol9wuFE1eNOy+GL 9p0SxKNQtgXzw== Date: Mon, 23 Dec 2024 14:20:22 -0800 Subject: [PATCH 33/51] xfs_db: dump rt summary blocks From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944309.2297565.10841764450456874823.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Now that rtsummary blocks have a header, make it so that xfs_db can analyze the structure. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- db/field.c | 4 ++++ db/field.h | 2 ++ db/inode.c | 2 ++ db/rtgroup.c | 20 ++++++++++++++++++++ db/rtgroup.h | 3 +++ db/type.c | 5 +++++ db/type.h | 1 + 7 files changed, 37 insertions(+) diff --git a/db/field.c b/db/field.c index ad1ccb9877aca5..ca0fe1826f9a80 100644 --- a/db/field.c +++ b/db/field.c @@ -411,6 +411,10 @@ const ftattr_t ftattrtab[] = { 0, NULL, NULL }, { FLDT_RGBITMAP, "rgbitmap", NULL, (char *)rgbitmap_flds, btblock_size, FTARG_SIZE, NULL, rgbitmap_flds }, + { FLDT_SUMINFO, "suminfo", fp_num, "%u", SI(bitsz(xfs_suminfo_t)), + 0, NULL, NULL }, + { FLDT_RGSUMMARY, "rgsummary", NULL, (char *)rgsummary_flds, + btblock_size, FTARG_SIZE, NULL, rgsummary_flds }, { FLDT_ZZZ, NULL } }; diff --git a/db/field.h b/db/field.h index aace89c90d79eb..1d7465b4d3e562 100644 --- a/db/field.h +++ b/db/field.h @@ -198,6 +198,8 @@ typedef enum fldt { FLDT_RTWORD, FLDT_RGBITMAP, + FLDT_SUMINFO, + FLDT_RGSUMMARY, FLDT_ZZZ /* mark last entry */ } fldt_t; diff --git a/db/inode.c b/db/inode.c index d3207510c28265..0a80b8d063603f 100644 --- a/db/inode.c +++ b/db/inode.c @@ -715,6 +715,8 @@ inode_next_type(void) return TYP_DQBLK; case XFS_METAFILE_RTBITMAP: return TYP_RGBITMAP; + case XFS_METAFILE_RTSUMMARY: + return TYP_RGSUMMARY; default: return TYP_DATA; } diff --git a/db/rtgroup.c b/db/rtgroup.c index 3ef2dc8fe7f031..c6b96c9dc79daa 100644 --- a/db/rtgroup.c +++ b/db/rtgroup.c @@ -132,3 +132,23 @@ const field_t rgbitmap_hfld[] = { { "", FLDT_RGBITMAP, OI(0), C1, 0, TYP_NONE }, { NULL } }; + +#define OFF(f) bitize(offsetof(struct xfs_rtbuf_blkinfo, rt_ ## f)) +const field_t rgsummary_flds[] = { + { "magicnum", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE }, + { "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE }, + { "owner", FLDT_INO, OI(OFF(owner)), C1, 0, TYP_NONE }, + { "bno", FLDT_DFSBNO, OI(OFF(blkno)), C1, 0, TYP_BMAPBTD }, + { "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE }, + { "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE }, + /* the suminfo array is after the actual structure */ + { "suminfo", FLDT_SUMINFO, OI(bitize(sizeof(struct xfs_rtbuf_blkinfo))), + rtwords_count, FLD_ARRAY | FLD_COUNT, TYP_DATA }, + { NULL } +}; +#undef OFF + +const field_t rgsummary_hfld[] = { + { "", FLDT_RGSUMMARY, OI(0), C1, 0, TYP_NONE }, + { NULL } +}; diff --git a/db/rtgroup.h b/db/rtgroup.h index 06f554e1862851..5b120f2c9a29f3 100644 --- a/db/rtgroup.h +++ b/db/rtgroup.h @@ -12,6 +12,9 @@ extern const struct field rtsb_hfld[]; extern const struct field rgbitmap_flds[]; extern const struct field rgbitmap_hfld[]; +extern const struct field rgsummary_flds[]; +extern const struct field rgsummary_hfld[]; + extern void rtsb_init(void); extern int rtsb_size(void *obj, int startoff, int idx); diff --git a/db/type.c b/db/type.c index 65e7b24146f170..2091b4ac8b139b 100644 --- a/db/type.c +++ b/db/type.c @@ -68,6 +68,7 @@ static const typ_t __typtab[] = { { TYP_FINOBT, "finobt", handle_struct, finobt_hfld, NULL, TYP_F_NO_CRC_OFF }, { TYP_RGBITMAP, NULL }, + { TYP_RGSUMMARY, NULL }, { TYP_NONE, NULL } }; @@ -116,6 +117,8 @@ static const typ_t __typtab_crc[] = { &xfs_finobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, { TYP_RGBITMAP, "rgbitmap", handle_struct, rgbitmap_hfld, &xfs_rtbitmap_buf_ops, XFS_RTBUF_CRC_OFF }, + { TYP_RGSUMMARY, "rgsummary", handle_struct, rgsummary_hfld, + &xfs_rtsummary_buf_ops, XFS_RTBUF_CRC_OFF }, { TYP_NONE, NULL } }; @@ -164,6 +167,8 @@ static const typ_t __typtab_spcrc[] = { &xfs_finobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, { TYP_RGBITMAP, "rgbitmap", handle_struct, rgbitmap_hfld, &xfs_rtbitmap_buf_ops, XFS_RTBUF_CRC_OFF }, + { TYP_RGSUMMARY, "rgsummary", handle_struct, rgsummary_hfld, + &xfs_rtsummary_buf_ops, XFS_RTBUF_CRC_OFF }, { TYP_NONE, NULL } }; diff --git a/db/type.h b/db/type.h index e2148c6351d141..e7f0ecc17680bf 100644 --- a/db/type.h +++ b/db/type.h @@ -36,6 +36,7 @@ typedef enum typnm TYP_TEXT, TYP_FINOBT, TYP_RGBITMAP, + TYP_RGSUMMARY, TYP_NONE } typnm_t; From patchwork Mon Dec 23 22:20:37 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: 13919417 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 97D1A433D5 for ; Mon, 23 Dec 2024 22:20:38 +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=1734992438; cv=none; b=gs4p5wpATB1I9hzqEaMKlpcp9lofvL1wPsGFsWgwnaJU4yLtff7KzrYnaRk/Mw31qwwoJaVWUo4Ow8lmp0opItEzWsiyjOuh/hY1mat4R6nQRX4ejZ0tp8nc53UqoFHHchdtoAlPJyQE66ULA9P2P8h/KSNPl+ieyrsTJgzL7sM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992438; c=relaxed/simple; bh=NHpDpZefwgkYlA5jt1RQ/FzL+4B3VHnORiYMfHqlOPI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ed+NSpBA0LPXAcFHfAbZ6AkTc8atNgHAC19XNC+zoin7NbdoD7/AN64aCOyuGLcRt06rtWqYN9DKeSgtDVlLJL5Cjtl3SQdScscZ56Ykis+FHB9GnuNfLkB+zmh8stGZ7BazcyMzMoJ6v2dMMkj6nM/AtuKe4qpWwS+njJ6gyNQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lF6LJ3Cd; 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="lF6LJ3Cd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62AB1C4CED7; Mon, 23 Dec 2024 22:20:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992438; bh=NHpDpZefwgkYlA5jt1RQ/FzL+4B3VHnORiYMfHqlOPI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=lF6LJ3Cd685iP53gUytV0h7t2twyxlFham4r7g8W9cFYBuLnkQBC6jEkYnRWmme3d GRA6aFjF92PicASvj+tEANwwFJsqFqlStkh88tIF2fxwLOFSRKjD+n6hzVL0agkEOa gZuXKDFRqMmgm7ZMZd02jAsp4sQs/ysjJ8tpEC8O/15E+NJDHey4XQ7iLqjyO6YiYW jJJvd2bYyVP2YL/VSbZuRH5bfZ9QnbRDb47JkORPGVcI53MsOKDIwHPhkDcjiQB5nd yqQe7dwuVj1TbjV8awWDxSNbfCEm6P4V0QEOzx89TOv+4X9ssOpAjl5r+72lWlzjjI WIf/tkDscT/lQ== Date: Mon, 23 Dec 2024 14:20:37 -0800 Subject: [PATCH 34/51] xfs_db: report rt group and block number in the bmap command From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944324.2297565.11397286166087986499.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong The bmap command does not report startblocks for realtime files correctly. If rtgroups are enabled, we need to use the appropriate functions to crack the startblock into rtgroup and block numbers; if not, then we need to report a linear address and not try to report a group number. Fix both of these issues. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- db/bmap.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/db/bmap.c b/db/bmap.c index 7915772aaee4e0..1c5694c3f7d281 100644 --- a/db/bmap.c +++ b/db/bmap.c @@ -119,6 +119,41 @@ bmap( *nexp = n; } +static void +print_group_bmbt( + bool isrt, + int whichfork, + const struct bmap_ext *be) +{ + unsigned int gno; + unsigned long long gbno; + + if (whichfork == XFS_DATA_FORK && isrt) { + gno = xfs_fsb_to_gno(mp, be->startblock, XG_TYPE_RTG); + gbno = xfs_fsb_to_gbno(mp, be->startblock, XG_TYPE_RTG); + } else { + gno = xfs_fsb_to_gno(mp, be->startblock, XG_TYPE_AG); + gbno = xfs_fsb_to_gbno(mp, be->startblock, XG_TYPE_AG); + } + + dbprintf( + _("%s offset %lld startblock %llu (%u/%llu) count %llu flag %u\n"), + whichfork == XFS_DATA_FORK ? _("data") : _("attr"), + be->startoff, be->startblock, + gno, gbno, + be->blockcount, be->flag); +} + +static void +print_linear_bmbt( + const struct bmap_ext *be) +{ + dbprintf(_("%s offset %lld startblock %llu count %llu flag %u\n"), + _("data"), + be->startoff, be->startblock, + be->blockcount, be->flag); +} + static int bmap_f( int argc, @@ -135,6 +170,7 @@ bmap_f( xfs_extnum_t nex; char *p; int whichfork; + bool isrt; if (iocur_top->ino == NULLFSINO) { dbprintf(_("no current inode\n")); @@ -154,6 +190,10 @@ bmap_f( return 0; } } + + dip = iocur_top->data; + isrt = (dip->di_flags & cpu_to_be16(XFS_DIFLAG_REALTIME)); + if (afork + dfork == 0) { push_cur(); set_cur_inode(iocur_top->ino); @@ -198,13 +238,15 @@ bmap_f( bmap(co, eo - co + 1, whichfork, &nex, &be); if (nex == 0) break; - dbprintf(_("%s offset %lld startblock %llu (%u/%u) count " - "%llu flag %u\n"), - whichfork == XFS_DATA_FORK ? _("data") : _("attr"), - be.startoff, be.startblock, - XFS_FSB_TO_AGNO(mp, be.startblock), - XFS_FSB_TO_AGBNO(mp, be.startblock), - be.blockcount, be.flag); + + if (whichfork == XFS_DATA_FORK && isrt) { + if (xfs_has_rtgroups(mp)) + print_group_bmbt(isrt, whichfork, &be); + else + print_linear_bmbt(&be); + } else { + print_group_bmbt(isrt, whichfork, &be); + } co = be.startoff + be.blockcount; } co = cosave; From patchwork Mon Dec 23 22:20:53 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: 13919418 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 2F35B188596 for ; Mon, 23 Dec 2024 22:20: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=1734992454; cv=none; b=UAb6OPanI3tsg0PG6QyH4wuF2fUCcEJhyRDaQ/NRtcd/dQ+EVdBnN+t8yEkkSibrSoUp/muY2nmWESV5im+GimNQqPRVpzXOD4RlMykBvq8o+Qk7+1YfZQaJ9tB9LKQdBMMIf8mQqDnsKovANpOY8Ir4eZcUvI8Emb7t8HGz8Dw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992454; c=relaxed/simple; bh=c2uJ1Gmt/AozRenllNmzFt/OH3vyEc/td+CaOLZqGdQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=b9X/HOnttbmLGHUYiRN3nyM50WRX23wtajBBOwvKHf5ayo6vaqIioSbmfs1oQ1RlHRh3/rJreXZHH+Ft9g/4vDCwsZ1cNTTV93IEkmcygw0OuxETvZFaSbCX48ojtA2yK9SVUPfsI5qy1r9EBfRcNZwjiUzouW7uaucB9PjZ8yU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UcprkfDU; 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="UcprkfDU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFA67C4CED3; Mon, 23 Dec 2024 22:20:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992454; bh=c2uJ1Gmt/AozRenllNmzFt/OH3vyEc/td+CaOLZqGdQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=UcprkfDUTpeFdbh5lMy+z9czMq34V3piN7CvpySujPtV9Fz1Nrzc4lGy34KJiCkAF cTcBVlM/1ZlUIG0Xdch5dtmS0NtKmppkUd/UW0zXzlOEu7fAzQCoODpKpnxSQCg6HC r1UTSjKK6pWzSMzR3bQRBl8ir+5ftWqVNJVS3QUMUI8j5Vnc/ezc1MAVSYlfKI1i4O 9PJsd78HU5fFXPq0OdqmfDoPTD4YMZWA2devOkqyDrzaV+XbF0keUVnDGBzFwv0YGD /J4MsHvbfJdMhU8z4l6Q/DGBT9XP9aVp9ekY6Eiv4N/n/TqV3StG6xQJIqT5tAnRzl LmqykJQUXX/cA== Date: Mon, 23 Dec 2024 14:20:53 -0800 Subject: [PATCH 35/51] xfs_io: support scrubbing rtgroup metadata From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944339.2297565.9149694495176919267.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Support scrubbing all rtgroup metadata with a scrubv call. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- io/scrub.c | 40 ++++++++++++++++++++++++++++++++++++++++ man/man8/xfs_io.8 | 3 ++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/io/scrub.c b/io/scrub.c index 45229a8ae81099..99c24d9550243c 100644 --- a/io/scrub.c +++ b/io/scrub.c @@ -165,6 +165,32 @@ parse_metapath( return true; } +static bool +parse_rtgroup( + int argc, + char **argv, + int optind, + __u32 *rgno) +{ + char *p; + unsigned long control; + + if (optind != argc - 1) { + fprintf(stderr, _("Must specify one rtgroup number.\n")); + return false; + } + + control = strtoul(argv[optind], &p, 0); + if (*p != '\0') { + fprintf(stderr, _("Bad rtgroup number '%s'.\n"), + argv[optind]); + return false; + } + + *rgno = control; + return true; +} + static int parse_args( int argc, @@ -230,6 +256,12 @@ parse_args( return command_usage(cmdinfo); } break; + case XFROG_SCRUB_GROUP_RTGROUP: + if (!parse_rtgroup(argc, argv, optind, &meta->sm_agno)) { + exitcode = 1; + return command_usage(cmdinfo); + } + break; case XFROG_SCRUB_GROUP_FS: case XFROG_SCRUB_GROUP_NONE: case XFROG_SCRUB_GROUP_SUMMARY: @@ -539,6 +571,8 @@ scrubv_f( group = XFROG_SCRUB_GROUP_ISCAN; else if (!strcmp(argv[optind], "summary")) group = XFROG_SCRUB_GROUP_SUMMARY; + else if (!strcmp(argv[optind], "rtgroup")) + group = XFROG_SCRUB_GROUP_RTGROUP; else { printf(_("Unknown group '%s'.\n"), argv[optind]); exitcode = 1; @@ -576,6 +610,12 @@ scrubv_f( return command_usage(&scrubv_cmd); } break; + case XFROG_SCRUB_GROUP_RTGROUP: + if (!parse_rtgroup(argc, argv, optind, &scrubv.head.svh_agno)) { + exitcode = 1; + return command_usage(&scrubv_cmd); + } + break; default: ASSERT(0); break; diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8 index c73fee7c2780c6..6775b0a273e5aa 100644 --- a/man/man8/xfs_io.8 +++ b/man/man8/xfs_io.8 @@ -1425,11 +1425,12 @@ .SH FILESYSTEM COMMANDS .RE .PD .TP -.BI "scrub " type " [ " agnumber " | " "ino" " " "gen" " | " metapath " ]" +.BI "scrub " type " [ " agnumber " | " rgnumber " | " "ino" " " "gen" " | " metapath " ]" Scrub internal XFS filesystem metadata. The .BI type parameter specifies which type of metadata to scrub. For AG metadata, one AG number must be specified. +For realtime group metadata, one rtgroup number must be specified. For file metadata, the scrub is applied to the open file unless the inode number and generation number are specified. For metapath, the name of a file or a raw number must be specified. From patchwork Mon Dec 23 22:21: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: 13919419 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 BAF05188596 for ; Mon, 23 Dec 2024 22:21:09 +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=1734992469; cv=none; b=tLzNgM6h2BvOJsUmsrvlNmbUTKwalFZew21IY4XeRTNsJTF4d3VrLnx7VVBqT6CBBPeiC/0NYnAK9ESWq5ynrbReK6WtIhyobuuZA2FrHt1DwDJiWpfLYZcEtbG6zCaV9L8Gj9pYHFQxg6DwqoQ8l41dTy/WRgzgfZZuQWvAIag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992469; c=relaxed/simple; bh=eq6tBtzkd5KsN5NuMuoNphEdw2bw5DY5PeGzwxYYwBc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sGpldq9Bo6Uh/Ba8F2/l+iKVSlMMtxtSDrkr4zmZIP0AJ7rmcvbc74i3wUVo3hbEKuaLTyR5s6aClEpqxjJPrUNwYQGgnuIQQcWec4SYJ1AhHyYe49cnCDG6XPF9ymRsTq4QR9FLniYdDkx5VFF/+J4NNgdlvObQxKaj0SO5Lu8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uTd3ceGx; 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="uTd3ceGx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8BBF5C4CED6; Mon, 23 Dec 2024 22:21:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992469; bh=eq6tBtzkd5KsN5NuMuoNphEdw2bw5DY5PeGzwxYYwBc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=uTd3ceGxu4JacoD4bshzBrNf6L6p11+6a2j3kKhI3HabA20Wu2PqPXglXN+0FwnxX Ac1oHhKa+bGZif3PYRk+8mgIt7nUZ1CGh7CkhrlGWHRWUumUXdjD7/qTVNS+E8EYuq tScmqDG0TR16Ib65FqDnIaEtpj8pt88yThdQKwsFzPnmMM+jJFNbLBugKmHa3PuRYY fBKvZ+gGA9uXd8qLnuPjORBOLf72ivMPHcuDPfLaGLYQu4j5mi9qdZ6N3RWr9TPjFU aD8ynfZKwiYs+NotzqYFb8pFnynp0ZXcVS7o+79lnJ8wYKLyfHW/HZPILM/5FhnknV Zf1EZBUit9RfQ== Date: Mon, 23 Dec 2024 14:21:09 -0800 Subject: [PATCH 36/51] xfs_io: support scrubbing rtgroup metadata paths From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944354.2297565.16014666149393356538.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Support scrubbing the metadata directory path of an rtgroup metadata file. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- io/scrub.c | 41 +++++++++++++++++++++++++++++++++++------ man/man8/xfs_io.8 | 3 ++- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/io/scrub.c b/io/scrub.c index 99c24d9550243c..a137f402b94d48 100644 --- a/io/scrub.c +++ b/io/scrub.c @@ -136,21 +136,23 @@ parse_metapath( int argc, char **argv, int optind, - __u64 *ino) + __u64 *ino, + __u32 *group) { char *p; unsigned long long control; + unsigned long control2 = 0; int i; - if (optind != argc - 1) { + if (optind != argc - 1 && optind != argc - 2) { fprintf(stderr, _("Must specify metapath number.\n")); return false; } for (i = 0; i < XFS_SCRUB_METAPATH_NR; i++) { if (!strcmp(argv[optind], xfrog_metapaths[i].name)) { - *ino = i; - return true; + control = i; + goto find_group; } } @@ -161,7 +163,32 @@ parse_metapath( return false; } +find_group: + if (xfrog_metapaths[control].group == XFROG_SCRUB_GROUP_RTGROUP) { + if (optind == argc - 1) { + fprintf(stderr, +_("%s: Metapath requires a group number.\n"), + xfrog_metapaths[*ino].name); + return false; + } + control2 = strtoul(argv[optind + 1], &p, 0); + if (*p != '\0') { + fprintf(stderr, + _("Bad group number '%s'.\n"), + argv[optind + 1]); + return false; + } + } else { + if (optind == argc - 2) { + fprintf(stderr, +_("%s: Metapath does not take a second argument.\n"), + xfrog_metapaths[*ino].name); + return false; + } + } + *ino = control; + *group = control2; return true; } @@ -237,7 +264,8 @@ parse_args( switch (d->group) { case XFROG_SCRUB_GROUP_METAPATH: - if (!parse_metapath(argc, argv, optind, &meta->sm_ino)) { + if (!parse_metapath(argc, argv, optind, &meta->sm_ino, + &meta->sm_agno)) { exitcode = 1; return command_usage(cmdinfo); } @@ -582,7 +610,8 @@ scrubv_f( switch (group) { case XFROG_SCRUB_GROUP_METAPATH: - if (!parse_metapath(argc, argv, optind, &scrubv.head.svh_ino)) { + if (!parse_metapath(argc, argv, optind, &scrubv.head.svh_ino, + &scrubv.head.svh_agno)) { exitcode = 1; return command_usage(&scrubv_cmd); } diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8 index 6775b0a273e5aa..4673b071901c28 100644 --- a/man/man8/xfs_io.8 +++ b/man/man8/xfs_io.8 @@ -1425,7 +1425,7 @@ .SH FILESYSTEM COMMANDS .RE .PD .TP -.BI "scrub " type " [ " agnumber " | " rgnumber " | " "ino" " " "gen" " | " metapath " ]" +.BI "scrub " type " [ " agnumber " | " rgnumber " | " "ino" " " "gen" " | " metapath " [ " rgnumber " ] ]" Scrub internal XFS filesystem metadata. The .BI type parameter specifies which type of metadata to scrub. @@ -1434,6 +1434,7 @@ .SH FILESYSTEM COMMANDS For file metadata, the scrub is applied to the open file unless the inode number and generation number are specified. For metapath, the name of a file or a raw number must be specified. +If the metapath file is a per-rtgroup file, the group number must be specified. .RE .PD .TP From patchwork Mon Dec 23 22:21:24 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: 13919420 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 DD4A918E35D for ; Mon, 23 Dec 2024 22:21: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=1734992485; cv=none; b=uWOc5ot9gPxMyLzowZyCp8gnAgEF9jMYE8HY2Wzguiky8Lad4nGYXhcj1RsebMsPoIYyFgjgCnVZjYyXUsil/sP4wcnMQLDelbW6EO69APbxbmxmAASUoH+A3Q6woHA+FNiZpGqsiSzAiER9mFlr6Mbw9eUaNFfW0dOyh2ogSrE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992485; c=relaxed/simple; bh=NwukFBwFaWIeCMhGHfVgsB/DoLOithbElAIlu0RzIDw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eYoAqILcw9qexHte+45RRaLOQ9WOY6nJUZIboxNzy4ThIbHWGPRjsAeLeshfXn4dWTS8ukcCciObzlbDk8IPFM5Ls4UMvsVuQIF/5A3+g7w/S1+czTDzJfsvSIrLfJw2aLEYesGKh+pvG/ke3rvK9MY7Doq6CdNpQuzicaQ1wk4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uk0Hy5az; 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="uk0Hy5az" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2A6AC4CEDF; Mon, 23 Dec 2024 22:21:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992485; bh=NwukFBwFaWIeCMhGHfVgsB/DoLOithbElAIlu0RzIDw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=uk0Hy5az4T0kgP4JWKhp3XWfBZ9qmnB5zhqZLapsfVq0F4seu/irZOmeCQozQKKJ9 Q5vkMtrO65GPkYI66yR9Bei2vAv3wRRpFyc5E7UPxMThJSN+DJORA9Rb1/w3kN8o+4 J33ODNtyr8uv2a5aTQj1x2BDJv5gQdZ+uX7Rqh1BD0un8tA5/ibzpn3Bb+OZSz+F+7 mBmb7BkIYrXYLGeoH9HyaO4Op3tg+ZHjraHzu0JG/Wr7FI8zxfJsDnEwNi5VomKQbP P6+rORiNhOhhFLWzv7N0UQABRkBqSjCdFYWs0epDqB+rzQA0WDoiDQGXtirs0JV9pv IFARwfRU3lIrQ== Date: Mon, 23 Dec 2024 14:21:24 -0800 Subject: [PATCH 37/51] xfs_io: add a command to display allocation group information From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944370.2297565.1566357439077109702.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Add a new 'aginfo' command to xfs_io so that we can display allocation group geometry. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- io/Makefile | 1 io/aginfo.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++ io/init.c | 1 io/io.h | 1 man/man8/xfs_io.8 | 12 +++++ 5 files changed, 134 insertions(+) create mode 100644 io/aginfo.c diff --git a/io/Makefile b/io/Makefile index c33d57f5e10b8f..8f835ec71fd768 100644 --- a/io/Makefile +++ b/io/Makefile @@ -9,6 +9,7 @@ LTCOMMAND = xfs_io LSRCFILES = xfs_bmap.sh xfs_freeze.sh xfs_mkfile.sh xfs_property HFILES = init.h io.h CFILES = \ + aginfo.c \ attr.c \ bmap.c \ bulkstat.c \ diff --git a/io/aginfo.c b/io/aginfo.c new file mode 100644 index 00000000000000..6cbfcb8de35523 --- /dev/null +++ b/io/aginfo.c @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2021-2024 Oracle. All rights reserved. + * Author: Darrick J. Wong + */ +#include "platform_defs.h" +#include "libxfs.h" +#include "command.h" +#include "input.h" +#include "init.h" +#include "io.h" +#include "libfrog/logging.h" +#include "libfrog/paths.h" +#include "libfrog/fsgeom.h" + +static cmdinfo_t aginfo_cmd; + +static int +report_aginfo( + struct xfs_fd *xfd, + xfs_agnumber_t agno) +{ + struct xfs_ag_geometry ageo = { 0 }; + int ret; + + ret = -xfrog_ag_geometry(xfd->fd, agno, &ageo); + if (ret) { + xfrog_perror(ret, "aginfo"); + return 1; + } + + printf(_("AG: %u\n"), ageo.ag_number); + printf(_("Blocks: %u\n"), ageo.ag_length); + printf(_("Free Blocks: %u\n"), ageo.ag_freeblks); + printf(_("Inodes: %u\n"), ageo.ag_icount); + printf(_("Free Inodes: %u\n"), ageo.ag_ifree); + printf(_("Sick: 0x%x\n"), ageo.ag_sick); + printf(_("Checked: 0x%x\n"), ageo.ag_checked); + printf(_("Flags: 0x%x\n"), ageo.ag_flags); + + return 0; +} + +/* Display AG status. */ +static int +aginfo_f( + int argc, + char **argv) +{ + struct xfs_fd xfd = XFS_FD_INIT(file->fd); + unsigned long long x; + xfs_agnumber_t agno = NULLAGNUMBER; + int c; + int ret = 0; + + ret = -xfd_prepare_geometry(&xfd); + if (ret) { + xfrog_perror(ret, "xfd_prepare_geometry"); + exitcode = 1; + return 1; + } + + while ((c = getopt(argc, argv, "a:")) != EOF) { + switch (c) { + case 'a': + errno = 0; + x = strtoll(optarg, NULL, 10); + if (!errno && x >= NULLAGNUMBER) + errno = ERANGE; + if (errno) { + perror("aginfo"); + return 1; + } + agno = x; + break; + default: + return command_usage(&aginfo_cmd); + } + } + + if (agno != NULLAGNUMBER) { + ret = report_aginfo(&xfd, agno); + } else { + for (agno = 0; !ret && agno < xfd.fsgeom.agcount; agno++) { + ret = report_aginfo(&xfd, agno); + } + } + + return ret; +} + +static void +aginfo_help(void) +{ + printf(_( +"\n" +"Report allocation group geometry.\n" +"\n" +" -a agno -- Report on the given allocation group.\n" +"\n")); + +} + +static cmdinfo_t aginfo_cmd = { + .name = "aginfo", + .cfunc = aginfo_f, + .argmin = 0, + .argmax = -1, + .args = "[-a agno]", + .flags = CMD_NOMAP_OK, + .help = aginfo_help, +}; + +void +aginfo_init(void) +{ + aginfo_cmd.oneline = _("Get XFS allocation group state."); + add_command(&aginfo_cmd); +} diff --git a/io/init.c b/io/init.c index 5727f73515a6a2..4831deae1b2683 100644 --- a/io/init.c +++ b/io/init.c @@ -44,6 +44,7 @@ init_cvtnum( static void init_commands(void) { + aginfo_init(); attr_init(); bmap_init(); bulkstat_init(); diff --git a/io/io.h b/io/io.h index 4daedac06419ae..d99065582057de 100644 --- a/io/io.h +++ b/io/io.h @@ -155,3 +155,4 @@ extern void crc32cselftest_init(void); extern void bulkstat_init(void); void exchangerange_init(void); void fsprops_init(void); +void aginfo_init(void); diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8 index 4673b071901c28..31c81efed8f99b 100644 --- a/man/man8/xfs_io.8 +++ b/man/man8/xfs_io.8 @@ -1242,6 +1242,18 @@ .SH MEMORY MAPPED I/O COMMANDS for the current memory mapping. .SH FILESYSTEM COMMANDS +.TP +.BI "aginfo [ \-a " agno " ]" +Show information about or update the state of allocation groups. +.RE +.RS 1.0i +.PD 0 +.TP +.BI \-a +Act only on a specific allocation group. +.PD +.RE + .TP .BI "bulkstat [ \-a " agno " ] [ \-d ] [ \-e " endino " ] [ \-m ] [ \-n " batchsize " ] [ \-q ] [ \-s " startino " ] [ \-v " version" ] Display raw stat information about a bunch of inodes in an XFS filesystem. From patchwork Mon Dec 23 22:21: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: 13919421 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 78EC9433D5 for ; Mon, 23 Dec 2024 22:21: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=1734992501; cv=none; b=lSmwZBRZCXgb80c7ndZiJ7mazZbL3mtTLzeNhLjbaDyJmDV+DRztaUrkgLHWgQqeHFbjQkhQOa5dG3bLcT5+ERf42lHOdY3eHX4Pryxl5LhSJ6UCWQw6zPW4LlNJ4loK6NbsDpxLJLTkqclf6VWFFopuyo3bCZSXwFcymdywKTg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992501; c=relaxed/simple; bh=jTOGc5ZY9M+WbXpMlAF4wtl+oYHGruqk026jnOULdqk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IaXLBbQmd/Yqu//WxB6ZcKvVF+XodM9h59W1NPBHJpNGUxPiR/cNuwWSNbY1AtVFIh53MzBw0YS5YgjkKvX4qGLJUkc3fZmg9qKkBmivlisVEi7D3yTf1KQZqqVmeqE1LIUBQ0wO8wRingniYNRmA6HSCyJtAGfO2oylAYrpJJs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l2HPMnzT; 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="l2HPMnzT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52875C4CED3; Mon, 23 Dec 2024 22:21:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992501; bh=jTOGc5ZY9M+WbXpMlAF4wtl+oYHGruqk026jnOULdqk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=l2HPMnzTS8it4exWT2i4y8ve4wfSdGvD4u35FA7/UwIn7X8Yo8BLwThDxwRlljEjx K6ILHCf4juSf0Pd1oG3MbCgm6fwNyPkGPthwup8GjLvYuaDcqMabZuJQMta2J6LBQ/ Zu0AwM67fQnJXo6hwY4vcGAo4qTA2gj6GQgxP6J/tDIlvYTi1DEe71M97JBWgw50S0 Hf2ZEsHHsOUDkR55jqx22BwRuVYh05qP1ZWDAGsR6AiYcsqxRNbenPUztoDSncu9kW CxiG5te1jXGKRz1xpBOtTrOjhFUTR4HzvgzwS77t+Iexn/NsbJC8khKDkcJVbOqk63 ifZhQGTHhDRiQ== Date: Mon, 23 Dec 2024 14:21:40 -0800 Subject: [PATCH 38/51] xfs_io: add a command to display realtime group information From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944385.2297565.1160370708767559300.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Add a new 'rginfo' command to xfs_io so that we can display realtime group geometry. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- io/aginfo.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++ libfrog/fsgeom.c | 18 ++++++++++ libfrog/fsgeom.h | 4 ++ man/man8/xfs_io.8 | 13 +++++++ 4 files changed, 131 insertions(+) diff --git a/io/aginfo.c b/io/aginfo.c index 6cbfcb8de35523..f81986f0df4df3 100644 --- a/io/aginfo.c +++ b/io/aginfo.c @@ -14,6 +14,7 @@ #include "libfrog/fsgeom.h" static cmdinfo_t aginfo_cmd; +static cmdinfo_t rginfo_cmd; static int report_aginfo( @@ -111,9 +112,104 @@ static cmdinfo_t aginfo_cmd = { .help = aginfo_help, }; +static int +report_rginfo( + struct xfs_fd *xfd, + xfs_rgnumber_t rgno) +{ + struct xfs_rtgroup_geometry rgeo = { 0 }; + int ret; + + ret = -xfrog_rtgroup_geometry(xfd->fd, rgno, &rgeo); + if (ret) { + xfrog_perror(ret, "rginfo"); + return 1; + } + + printf(_("RTG: %u\n"), rgeo.rg_number); + printf(_("Length: %u\n"), rgeo.rg_length); + printf(_("Sick: 0x%x\n"), rgeo.rg_sick); + printf(_("Checked: 0x%x\n"), rgeo.rg_checked); + printf(_("Flags: 0x%x\n"), rgeo.rg_flags); + + return 0; +} + +/* Display rtgroup status. */ +static int +rginfo_f( + int argc, + char **argv) +{ + struct xfs_fd xfd = XFS_FD_INIT(file->fd); + unsigned long long x; + xfs_rgnumber_t rgno = NULLRGNUMBER; + int c; + int ret = 0; + + ret = -xfd_prepare_geometry(&xfd); + if (ret) { + xfrog_perror(ret, "xfd_prepare_geometry"); + exitcode = 1; + return 1; + } + + while ((c = getopt(argc, argv, "r:")) != EOF) { + switch (c) { + case 'r': + errno = 0; + x = strtoll(optarg, NULL, 10); + if (!errno && x >= NULLRGNUMBER) + errno = ERANGE; + if (errno) { + perror("rginfo"); + return 1; + } + rgno = x; + break; + default: + return command_usage(&rginfo_cmd); + } + } + + if (rgno != NULLRGNUMBER) { + ret = report_rginfo(&xfd, rgno); + } else { + for (rgno = 0; !ret && rgno < xfd.fsgeom.rgcount; rgno++) { + ret = report_rginfo(&xfd, rgno); + } + } + + return ret; +} + +static void +rginfo_help(void) +{ + printf(_( +"\n" +"Report realtime group geometry.\n" +"\n" +" -r rgno -- Report on the given realtime group.\n" +"\n")); + +} + +static cmdinfo_t rginfo_cmd = { + .name = "rginfo", + .cfunc = rginfo_f, + .argmin = 0, + .argmax = -1, + .args = "[-r rgno]", + .flags = CMD_NOMAP_OK, + .help = rginfo_help, +}; + void aginfo_init(void) { aginfo_cmd.oneline = _("Get XFS allocation group state."); add_command(&aginfo_cmd); + rginfo_cmd.oneline = _("Get XFS realtime group state."); + add_command(&rginfo_cmd); } diff --git a/libfrog/fsgeom.c b/libfrog/fsgeom.c index 9c1e9a90eb1f1b..b5220d2d6ffd22 100644 --- a/libfrog/fsgeom.c +++ b/libfrog/fsgeom.c @@ -214,3 +214,21 @@ xfrog_ag_geometry( return -errno; return 0; } + +/* + * Try to obtain a rt group's geometry. Returns zero or a negative error code. + */ +int +xfrog_rtgroup_geometry( + int fd, + unsigned int rgno, + struct xfs_rtgroup_geometry *rgeo) +{ + int ret; + + rgeo->rg_number = rgno; + ret = ioctl(fd, XFS_IOC_RTGROUP_GEOMETRY, rgeo); + if (ret) + return -errno; + return 0; +} diff --git a/libfrog/fsgeom.h b/libfrog/fsgeom.h index df2ca2a408e78a..c571ddbcfb9b70 100644 --- a/libfrog/fsgeom.h +++ b/libfrog/fsgeom.h @@ -5,10 +5,14 @@ #ifndef __LIBFROG_FSGEOM_H__ #define __LIBFROG_FSGEOM_H__ +struct xfs_rtgroup_geometry; + void xfs_report_geom(struct xfs_fsop_geom *geo, const char *mntpoint, const char *logname, const char *rtname); int xfrog_geometry(int fd, struct xfs_fsop_geom *fsgeo); int xfrog_ag_geometry(int fd, unsigned int agno, struct xfs_ag_geometry *ageo); +int xfrog_rtgroup_geometry(int fd, unsigned int rgno, + struct xfs_rtgroup_geometry *rgeo); /* * Structure for recording whatever observations we want about the level of diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8 index 31c81efed8f99b..59d5ddc54dcc66 100644 --- a/man/man8/xfs_io.8 +++ b/man/man8/xfs_io.8 @@ -1328,6 +1328,19 @@ .SH FILESYSTEM COMMANDS .I tag argument, displays the list of error tags available. Only available in expert mode and requires privileges. + +.TP +.BI "rginfo [ \-r " rgno " ]" +Show information about or update the state of realtime allocation groups. +.RE +.RS 1.0i +.PD 0 +.TP +.BI \-r +Act only on a specific realtime group. +.PD +.RE + .TP .BI "resblks [ " blocks " ]" Get and/or set count of reserved filesystem blocks using the From patchwork Mon Dec 23 22:21: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: 13919422 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 29983433D5 for ; Mon, 23 Dec 2024 22:21: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=1734992517; cv=none; b=qV3UhMZVVWfTvRCo+rjOtPZT4aBUisMYEQoMYGTbsm4E/q80yuAeTUC/dkv0IqjXECXW/eU6rpjY9xcoJPznjR3mcmbF8r8fILahbNKV3woI9tO+dLPtsKrguN+w14mKNSceT7QgD/hOacAN3Jipww5nmL8RuNyPxIsq1Uyu/js= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992517; c=relaxed/simple; bh=fQv6lqArDLyT08eExqndvErDRhicZwQTAo6FziD93xE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lgUvNXsBbaxlYGhcHQS0jDMSBqY3Hv7L/Dy1LVHgx6tDpWwd8Mr3qWH/bWBuwDHXwnHdveE1wUdSfG3NFjB0Em0oAeNbxIYc8dtNBZDlhNv/wWG+EfMiIC87lAEh7HQMNfZo6BtlR6tuuFhzJjuWriaAgi80lB4db/mRdttthdM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qMst6EcP; 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="qMst6EcP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED774C4CED3; Mon, 23 Dec 2024 22:21:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992517; bh=fQv6lqArDLyT08eExqndvErDRhicZwQTAo6FziD93xE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=qMst6EcPlP8WWtP4/8ITflqA5RKP1PiH9vw1gTxFmVb6j7U3sYa91XiQ+vl+BXGLA odTjkSfydNkJUECKOX/pR/Vc8XrT96b8uPAngd3sFvyzNmz54NfmAhi22TKwVhzMuX U8C9qyiAnY5mdrWs7ojKzFEMTOuSjBwndLI1FQK08bnzBdjsBZKBz3MAn9IfTS3phD qb8yRgoZsp2m39Yfd/+BHwFODJpZ+Qi4zLR/MHaO8HKKge1kD0uGC65kEFph1K/xzk USRDJs85JWpZ1xdH1FLkooK/gpSVTSxmSXN5TxU3EbnQZgJ9DnhlqU9CEwmOkHk1WK IR5mt7pGGzjEg== Date: Mon, 23 Dec 2024 14:21:56 -0800 Subject: [PATCH 39/51] xfs_io: display rt group in verbose bmap output From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944400.2297565.10822398029490982082.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Display the rt group number in the bmap -v output, just like we do for regular data files. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- io/bmap.c | 27 ++++++++++++++++++--------- libfrog/fsgeom.h | 12 ++++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/io/bmap.c b/io/bmap.c index 6182e1c591da18..b2f6b490528513 100644 --- a/io/bmap.c +++ b/io/bmap.c @@ -257,16 +257,18 @@ bmap_f( #define FLG_BSW 0000010 /* Not on begin of stripe width */ #define FLG_ESW 0000001 /* Not on end of stripe width */ int agno; - off_t agoff, bbperag; + off_t agoff, bbperag; int foff_w, boff_w, aoff_w, tot_w, agno_w; char rbuf[32], bbuf[32], abuf[32]; int sunit, swidth; foff_w = boff_w = aoff_w = MINRANGE_WIDTH; tot_w = MINTOT_WIDTH; - if (is_rt) - sunit = swidth = bbperag = 0; - else { + if (is_rt) { + bbperag = bytes_per_rtgroup(&fsgeo) / BBSIZE; + sunit = 0; + swidth = 0; + } else { bbperag = (off_t)fsgeo.agblocks * (off_t)fsgeo.blocksize / BBSIZE; sunit = (fsgeo.sunit * fsgeo.blocksize) / BBSIZE; @@ -295,7 +297,7 @@ bmap_f( (long long)(map[i + 1].bmv_block + map[i + 1].bmv_length - 1LL)); boff_w = max(boff_w, strlen(bbuf)); - if (!is_rt) { + if (bbperag > 0) { agno = map[i + 1].bmv_block / bbperag; agoff = map[i + 1].bmv_block - (agno * bbperag); @@ -312,13 +314,20 @@ bmap_f( numlen(map[i+1].bmv_length, 10)); } } - agno_w = is_rt ? 0 : max(MINAG_WIDTH, numlen(fsgeo.agcount, 10)); + if (is_rt) { + if (fsgeo.rgcount > 0) + agno_w = max(MINAG_WIDTH, numlen(fsgeo.rgcount, 10)); + else + agno_w = 0; + } else { + agno_w = max(MINAG_WIDTH, numlen(fsgeo.agcount, 10)); + } printf("%4s: %-*s %-*s %*s %-*s %*s%s\n", _("EXT"), foff_w, _("FILE-OFFSET"), boff_w, is_rt ? _("RT-BLOCK-RANGE") : _("BLOCK-RANGE"), - agno_w, is_rt ? "" : _("AG"), - aoff_w, is_rt ? "" : _("AG-OFFSET"), + agno_w, is_rt ? (fsgeo.rgcount ? _("RG") : "") : _("AG"), + aoff_w, is_rt ? (fsgeo.rgcount ? _("RG-OFFSET") : "") : _("AG-OFFSET"), tot_w, _("TOTAL"), flg ? _(" FLAGS") : ""); for (i = 0; i < egcnt; i++) { @@ -377,7 +386,7 @@ bmap_f( map[i + 1].bmv_length - 1LL)); printf("%4d: %-*s %-*s", i, foff_w, rbuf, boff_w, bbuf); - if (!is_rt) { + if (bbperag > 0) { agno = map[i + 1].bmv_block / bbperag; agoff = map[i + 1].bmv_block - (agno * bbperag); diff --git a/libfrog/fsgeom.h b/libfrog/fsgeom.h index c571ddbcfb9b70..b851b9bbf36a58 100644 --- a/libfrog/fsgeom.h +++ b/libfrog/fsgeom.h @@ -205,4 +205,16 @@ cvt_b_to_agbno( return cvt_daddr_to_agbno(xfd, cvt_btobbt(byteno)); } +/* Return the number of bytes in an rtgroup. */ +static inline uint64_t +bytes_per_rtgroup( + const struct xfs_fsop_geom *fsgeo) +{ + if (!fsgeo->rgcount) + return 0; + + return (uint64_t)fsgeo->rgextents * fsgeo->rtextsize * + fsgeo->blocksize; +} + #endif /* __LIBFROG_FSGEOM_H__ */ From patchwork Mon Dec 23 22:22: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: 13919423 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 BDE7A433D5 for ; Mon, 23 Dec 2024 22:22: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=1734992532; cv=none; b=sGVaUOeb2n7e1Sq+tb/2GjAXERGce7/eyedD8vFmMhtR3qISbv1H//zQSUXheiB58WdBGNibhDuTYaE0nA/rh+hkLpTH+A9P4IjIyk8VkumZ8OPWow7u/wiyXQWaxHaGG1pgLn8oJanSPdvQtzkHQS5DG4OYODITeyJEbx2EcC0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992532; c=relaxed/simple; bh=tPh2IZbz5whf7Hat1J/yDmol/gL1I0GDaN4qz6njuGg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HzW5vqRNASMk1VIEu1nKMU2EK8IZups8KFtuhBuvi7yHd1ldJXvE0irGg/hTsiqXYaXeB9zkMVwHNl79c7Bkh6y21h66UR6HSaEcSmHXmtWymJDOW538wd1KQ7CmEVxywhyTIt/Wx4+Ji5h/GqaAW8lewQDBzYd8N7GaCCuLSPE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lKhrbhdT; 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="lKhrbhdT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 982BFC4CED3; Mon, 23 Dec 2024 22:22:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992532; bh=tPh2IZbz5whf7Hat1J/yDmol/gL1I0GDaN4qz6njuGg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=lKhrbhdT5IjkEoyvuYsF/TbQzUyE18JGnltTXTeEhcX1hPgMmlXiFTryB8O9EHtKH zuXdPCD7C6eOiPLJ/TD3qNPgWnILmueA24SdtYRS02T4feSOAfj1fg8kGAbBnm6lsY rXVYpdf4T7AAvBYCg39MRS2usKIHw/8nLH8Oy9ai7yHBl2eoRt2tRhTvKGTjNzoW04 5w4l6L0ArmEzs1xiyr9/nEpRpJQ/G2PuM/hWW7095fHTx1zO3k5LpygaZKbb89LZRE Pz2pliXRbtIskagSNO0afblB0m4Sbb0VZFRpMR7tGe9UxaYnDy8DoPYoKs3UcL2+x0 WIwMhJmYBPIDg== Date: Mon, 23 Dec 2024 14:22:12 -0800 Subject: [PATCH 40/51] xfs_io: display rt group in verbose fsmap output From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944416.2297565.1994591832292422331.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Display the rt group number in the fsmap output, just like we do for regular data files. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- io/fsmap.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/io/fsmap.c b/io/fsmap.c index bf1196390cf35d..6de720f238bb44 100644 --- a/io/fsmap.c +++ b/io/fsmap.c @@ -14,6 +14,7 @@ static cmdinfo_t fsmap_cmd; static dev_t xfs_data_dev; +static dev_t xfs_rt_dev; static void fsmap_help(void) @@ -170,7 +171,7 @@ dump_map_verbose( unsigned long long i; struct fsmap *p; int agno; - off_t agoff, bperag; + off_t agoff, bperag, bperrtg; int foff_w, boff_w, aoff_w, tot_w, agno_w, own_w; int nr_w, dev_w; char rbuf[40], bbuf[40], abuf[40], obuf[40]; @@ -185,6 +186,7 @@ dump_map_verbose( tot_w = MINTOT_WIDTH; bperag = (off_t)fsgeo->agblocks * (off_t)fsgeo->blocksize; + bperrtg = bytes_per_rtgroup(fsgeo); sunit = (fsgeo->sunit * fsgeo->blocksize); swidth = (fsgeo->swidth * fsgeo->blocksize); @@ -243,6 +245,13 @@ dump_map_verbose( "(%lld..%lld)", (long long)BTOBBT(agoff), (long long)BTOBBT(agoff + p->fmr_length - 1)); + } else if (p->fmr_device == xfs_rt_dev && fsgeo->rgcount > 0) { + agno = p->fmr_physical / bperrtg; + agoff = p->fmr_physical % bperrtg; + snprintf(abuf, sizeof(abuf), + "(%lld..%lld)", + (long long)BTOBBT(agoff), + (long long)BTOBBT(agoff + p->fmr_length - 1)); } else abuf[0] = 0; aoff_w = max(aoff_w, strlen(abuf)); @@ -315,6 +324,16 @@ dump_map_verbose( snprintf(gbuf, sizeof(gbuf), "%lld", (long long)agno); + } else if (p->fmr_device == xfs_rt_dev && fsgeo->rgcount > 0) { + agno = p->fmr_physical / bperrtg; + agoff = p->fmr_physical % bperrtg; + snprintf(abuf, sizeof(abuf), + "(%lld..%lld)", + (long long)BTOBBT(agoff), + (long long)BTOBBT(agoff + p->fmr_length - 1)); + snprintf(gbuf, sizeof(gbuf), + "%lld", + (long long)agno); } else { abuf[0] = 0; gbuf[0] = 0; @@ -501,6 +520,7 @@ fsmap_f( } fs = fs_table_lookup(file->name, FS_MOUNT_POINT); xfs_data_dev = fs ? fs->fs_datadev : 0; + xfs_rt_dev = fs ? fs->fs_rtdev : 0; head->fmh_count = map_size; do { From patchwork Mon Dec 23 22:22: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: 13919424 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 6368D433D5 for ; Mon, 23 Dec 2024 22:22: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=1734992548; cv=none; b=aIO9EoOW4ORaBtBcMx/0sZkuVapXQo5Iio4xjThrkm/wGxk+YtypWMF2KFNwLIRtSZAqvVqYk9wXDrtBITl8Uo0/7I6JVFvlrOiOf+IRyLlLpgEx84uXAhS5roRJiaYOI1b7G094xtSli9pbIvlvPRE18IMFQVcmIOiDM0u+voM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992548; c=relaxed/simple; bh=q/KaSDvUZ/o/920cGcyok1NwzFyqaVd2p/ciQPI6GB8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mdqP02xtxnJiFTJQzJzeQxuuBYmnfF1RXQ8nEjv6WaVeDZ2Sjbdi3kweeFq9cKJyqE6/sOs7SaGcPXecyoBwbT3O5/FXPaL43tiSGHckrfYLf/I+KAn3tHSNVYq2H/+hTGNxTpRE++e8MJKilxioM0XVDPyUWABpJPHh8i9ds1w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n0pRNW0z; 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="n0pRNW0z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EB6DC4CED3; Mon, 23 Dec 2024 22:22:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992548; bh=q/KaSDvUZ/o/920cGcyok1NwzFyqaVd2p/ciQPI6GB8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=n0pRNW0zgaFidgJ6Uf/SwemDE/WIoaal5id0e+OzXVxceRm1qOpmAMzdVn3gK9/fX RmsvQdMzHNd9ulmGifSipdECipR5aFC3EfMlTKqDHeP12Mr3b56MVLahvySr0g2hHY NSXBHz+xOD/47YAQz/S2fG0c2AzgmfCYFVdDnvrvp7eBzdg+pdRfbC3Gquf5iENiDT X+rzjBlQSl0XhEs4elmYZFymaGHe3jtGPstib+gBFc6Z8mRQEWl/+YHLn4eYuCdsrU mLNALKsDIy56WmsfinsIa4G3UOg3fUZdLGCfvcs/lx+ezSy7G/QilzHv+UPhmGEQIB bBn0pwl10DgMw== Date: Mon, 23 Dec 2024 14:22:27 -0800 Subject: [PATCH 41/51] xfs_mdrestore: refactor open-coded fd/is_file into a structure From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944431.2297565.16848943333894292871.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Create an explicit object to track the fd and flags associated with a device onto which we are restoring metadata, and use it to reduce the amount of open-coded arguments to ->restore. This avoids some grossness in the next patch. Signed-off-by: "Darrick J. Wong" Reviewed-by: Andrey Albershteyn Reviewed-by: Christoph Hellwig --- mdrestore/xfs_mdrestore.c | 123 +++++++++++++++++++++++---------------------- 1 file changed, 63 insertions(+), 60 deletions(-) diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index c6c00270234442..c5584fec68813e 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -15,12 +15,20 @@ union mdrestore_headers { struct xfs_metadump_header v2; }; +struct mdrestore_dev { + int fd; + bool is_file; +}; + +#define DEFINE_MDRESTORE_DEV(name) \ + struct mdrestore_dev name = { .fd = -1 } + struct mdrestore_ops { void (*read_header)(union mdrestore_headers *header, FILE *md_fp); void (*show_info)(union mdrestore_headers *header, const char *md_file); void (*restore)(union mdrestore_headers *header, FILE *md_fp, - int ddev_fd, bool is_data_target_file, int logdev_fd, - bool is_log_target_file); + const struct mdrestore_dev *ddev, + const struct mdrestore_dev *logdev); }; static struct mdrestore { @@ -108,25 +116,24 @@ fixup_superblock( fatal("error writing primary superblock: %s\n", strerror(errno)); } -static int +static void open_device( - char *path, - bool *is_file) + struct mdrestore_dev *dev, + char *path) { - struct stat statbuf; - int open_flags; - int fd; + struct stat statbuf; + int open_flags; open_flags = O_RDWR; - *is_file = false; + dev->is_file = false; if (stat(path, &statbuf) < 0) { /* ok, assume it's a file and create it */ open_flags |= O_CREAT; - *is_file = true; + dev->is_file = true; } else if (S_ISREG(statbuf.st_mode)) { open_flags |= O_TRUNC; - *is_file = true; + dev->is_file = true; } else if (platform_check_ismounted(path, NULL, &statbuf, 0)) { /* * check to make sure a filesystem isn't mounted on the device @@ -136,23 +143,30 @@ open_device( path); } - fd = open(path, open_flags, 0644); - if (fd < 0) + dev->fd = open(path, open_flags, 0644); + if (dev->fd < 0) fatal("couldn't open \"%s\"\n", path); +} - return fd; +static void +close_device( + struct mdrestore_dev *dev) +{ + if (dev->fd >= 0) + close(dev->fd); + dev->fd = -1; + dev->is_file = false; } static void verify_device_size( - int dev_fd, - bool is_file, - xfs_rfsblock_t nr_blocks, - uint32_t blocksize) + const struct mdrestore_dev *dev, + xfs_rfsblock_t nr_blocks, + uint32_t blocksize) { - if (is_file) { + if (dev->is_file) { /* ensure regular files are correctly sized */ - if (ftruncate(dev_fd, nr_blocks * blocksize)) + if (ftruncate(dev->fd, nr_blocks * blocksize)) fatal("cannot set filesystem image size: %s\n", strerror(errno)); } else { @@ -161,7 +175,7 @@ verify_device_size( off_t off; off = nr_blocks * blocksize - sizeof(lb); - if (pwrite(dev_fd, lb, sizeof(lb), off) < 0) + if (pwrite(dev->fd, lb, sizeof(lb), off) < 0) fatal("failed to write last block, is target too " "small? (error: %s)\n", strerror(errno)); } @@ -195,12 +209,10 @@ show_info_v1( static void restore_v1( - union mdrestore_headers *h, - FILE *md_fp, - int ddev_fd, - bool is_data_target_file, - int logdev_fd, - bool is_log_target_file) + union mdrestore_headers *h, + FILE *md_fp, + const struct mdrestore_dev *ddev, + const struct mdrestore_dev *logdev) { struct xfs_metablock *metablock; /* header + index + blocks */ __be64 *block_index; @@ -254,8 +266,7 @@ restore_v1( ((struct xfs_dsb*)block_buffer)->sb_inprogress = 1; - verify_device_size(ddev_fd, is_data_target_file, sb.sb_dblocks, - sb.sb_blocksize); + verify_device_size(ddev, sb.sb_dblocks, sb.sb_blocksize); bytes_read = 0; @@ -263,7 +274,7 @@ restore_v1( maybe_print_progress(&mb_read, bytes_read); for (cur_index = 0; cur_index < mb_count; cur_index++) { - if (pwrite(ddev_fd, &block_buffer[cur_index << + if (pwrite(ddev->fd, &block_buffer[cur_index << h->v1.mb_blocklog], block_size, be64_to_cpu(block_index[cur_index]) << BBSHIFT) < 0) @@ -292,7 +303,7 @@ restore_v1( final_print_progress(&mb_read, bytes_read); - fixup_superblock(ddev_fd, block_buffer, &sb); + fixup_superblock(ddev->fd, block_buffer, &sb); free(metablock); } @@ -376,12 +387,10 @@ restore_meta_extent( static void restore_v2( - union mdrestore_headers *h, - FILE *md_fp, - int ddev_fd, - bool is_data_target_file, - int logdev_fd, - bool is_log_target_file) + union mdrestore_headers *h, + FILE *md_fp, + const struct mdrestore_dev *ddev, + const struct mdrestore_dev *logdev) { struct xfs_sb sb; struct xfs_meta_extent xme; @@ -415,16 +424,14 @@ restore_v2( ((struct xfs_dsb *)block_buffer)->sb_inprogress = 1; - verify_device_size(ddev_fd, is_data_target_file, sb.sb_dblocks, - sb.sb_blocksize); + verify_device_size(ddev, sb.sb_dblocks, sb.sb_blocksize); if (sb.sb_logstart == 0) { ASSERT(mdrestore.external_log == true); - verify_device_size(logdev_fd, is_log_target_file, sb.sb_logblocks, - sb.sb_blocksize); + verify_device_size(logdev, sb.sb_logblocks, sb.sb_blocksize); } - if (pwrite(ddev_fd, block_buffer, len, 0) < 0) + if (pwrite(ddev->fd, block_buffer, len, 0) < 0) fatal("error writing primary superblock: %s\n", strerror(errno)); @@ -446,11 +453,11 @@ restore_v2( switch (be64_to_cpu(xme.xme_addr) & XME_ADDR_DEVICE_MASK) { case XME_ADDR_DATA_DEVICE: device = "data"; - fd = ddev_fd; + fd = ddev->fd; break; case XME_ADDR_LOG_DEVICE: device = "log"; - fd = logdev_fd; + fd = logdev->fd; break; default: fatal("Invalid device found in metadump\n"); @@ -467,7 +474,7 @@ restore_v2( final_print_progress(&mb_read, bytes_read); - fixup_superblock(ddev_fd, block_buffer, &sb); + fixup_superblock(ddev->fd, block_buffer, &sb); free(block_buffer); } @@ -492,13 +499,11 @@ main( char **argv) { union mdrestore_headers headers; + DEFINE_MDRESTORE_DEV(ddev); + DEFINE_MDRESTORE_DEV(logdev); FILE *src_f; - char *logdev = NULL; - int data_dev_fd = -1; - int log_dev_fd = -1; + char *logdev_path = NULL; int c; - bool is_data_dev_file = false; - bool is_log_dev_file = false; mdrestore.show_progress = false; mdrestore.show_info = false; @@ -516,7 +521,7 @@ main( mdrestore.show_info = true; break; case 'l': - logdev = optarg; + logdev_path = optarg; mdrestore.external_log = true; break; case 'V': @@ -555,7 +560,7 @@ main( switch (be32_to_cpu(headers.magic)) { case XFS_MD_MAGIC_V1: - if (logdev != NULL) + if (logdev_path != NULL) usage(); mdrestore.mdrops = &mdrestore_ops_v1; break; @@ -581,18 +586,16 @@ main( optind++; /* check and open data device */ - data_dev_fd = open_device(argv[optind], &is_data_dev_file); + open_device(&ddev, argv[optind]); + /* check and open log device */ if (mdrestore.external_log) - /* check and open log device */ - log_dev_fd = open_device(logdev, &is_log_dev_file); + open_device(&logdev, logdev_path); - mdrestore.mdrops->restore(&headers, src_f, data_dev_fd, - is_data_dev_file, log_dev_fd, is_log_dev_file); + mdrestore.mdrops->restore(&headers, src_f, &ddev, &logdev); - close(data_dev_fd); - if (mdrestore.external_log) - close(log_dev_fd); + close_device(&ddev); + close_device(&logdev); if (src_f != stdin) fclose(src_f); From patchwork Mon Dec 23 22:22: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: 13919425 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 F06BD433D5 for ; Mon, 23 Dec 2024 22:22:43 +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=1734992564; cv=none; b=Ael5X5S7Tgq+ac/3mWndfmqudCj/fwMcqLGUmXoi/XzLldykJ05x5B1qJQZmE52WTAVHTeClz7K2cv3pQKEI3mKg+esjGv/ygg3QjDFLkc+BFHOckGcl12Lzmd7Zj7oARhvJ41ivlCs0UKXeAXgPX8AVvkH0hBfxbp1Zi1GDKIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992564; c=relaxed/simple; bh=/i2oevIs7Dsjjw+bHUqt9jcSUktc+MEVT+xqbiAtVms=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VDRJT4YNx39A68wf9eirinLmwk+0xe/JdHfqQ9PwSfNOv4duMdaYV13Wbjl8Tr6ZGeHMjQEW3g3WllNSwMpzMorAHFwSAaE0Z+nHRRrRu6HmPgBr7BaYQM8JW3BaNmavtCy8JXzJZYL0/09dgnLubulGY/0o3fUYk/6TLOA0Tn8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uCiZ4RZz; 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="uCiZ4RZz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C657EC4CED3; Mon, 23 Dec 2024 22:22:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992563; bh=/i2oevIs7Dsjjw+bHUqt9jcSUktc+MEVT+xqbiAtVms=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=uCiZ4RZzQ4LyL67DpqSEgr9mkBZpwdPhTdVn/N2RwGXcOQsaOc9d+WX56U0NwWm6N fm4xabMpcXmrZ1exMm2gJo7i5fWsxWTdfcHSwVkhP3fOEO8YqFzcxdv4RDaegaCVL5 16voAMKhQgZ4zma/d7IC5UvN2TugW6re+AhoTmxXBTioz7hT4+1EPXItPvN0Qv5sns ux99Bo0nq2QtuWGGXy7+LkGgTGI5DHiUKUbqLpZXJhCOCkqLZLXYZ8kzO/AsTUS6M8 PHuXJwrcrNYEevjF2YV6lX66WqwPu11KguBmO5TG8v6SX5maXlzG7saWS03EHe92aL 4nJL1D6kT9pSA== Date: Mon, 23 Dec 2024 14:22:43 -0800 Subject: [PATCH 42/51] xfs_mdrestore: restore rt group superblocks to realtime device From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944446.2297565.16252646930364155778.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Support restoring realtime device metadata to the realtime device, if the dumped filesystem had one. Signed-off-by: "Darrick J. Wong" Reviewed-by: Andrey Albershteyn Reviewed-by: Christoph Hellwig --- man/man8/xfs_mdrestore.8 | 10 ++++++++++ mdrestore/xfs_mdrestore.c | 47 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/man/man8/xfs_mdrestore.8 b/man/man8/xfs_mdrestore.8 index f60e7b56ebf0d1..6f6e14e96c6a5c 100644 --- a/man/man8/xfs_mdrestore.8 +++ b/man/man8/xfs_mdrestore.8 @@ -8,6 +8,9 @@ .SH SYNOPSIS ] [ .B \-l .I logdev +] [ +.B \-r +.I rtdev ] .I source .I target @@ -17,6 +20,9 @@ .SH SYNOPSIS [ .B \-l .I logdev +] [ +.B \-r +.I rtdev ] .I source .br @@ -61,6 +67,10 @@ .SH OPTIONS In such a scenario, the user has to provide a device to which the log device contents from the metadump file are copied. .TP +.BI \-r " rtdev" +Restore realtime device metadata to this device. +This is only required for a metadump in v2 format. +.TP .B \-V Prints the version number and exits. .SH DIAGNOSTICS diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index c5584fec68813e..d5014981b15a68 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -28,7 +28,8 @@ struct mdrestore_ops { void (*show_info)(union mdrestore_headers *header, const char *md_file); void (*restore)(union mdrestore_headers *header, FILE *md_fp, const struct mdrestore_dev *ddev, - const struct mdrestore_dev *logdev); + const struct mdrestore_dev *logdev, + const struct mdrestore_dev *rtdev); }; static struct mdrestore { @@ -37,6 +38,7 @@ static struct mdrestore { bool show_info; bool progress_since_warning; bool external_log; + bool realtime_data; } mdrestore; static void @@ -212,7 +214,8 @@ restore_v1( union mdrestore_headers *h, FILE *md_fp, const struct mdrestore_dev *ddev, - const struct mdrestore_dev *logdev) + const struct mdrestore_dev *logdev, + const struct mdrestore_dev *rtdev) { struct xfs_metablock *metablock; /* header + index + blocks */ __be64 *block_index; @@ -336,8 +339,9 @@ read_header_v2( if (!mdrestore.external_log && (compat & XFS_MD2_COMPAT_EXTERNALLOG)) fatal("External Log device is required\n"); - if (h->v2.xmh_incompat_flags & cpu_to_be32(XFS_MD2_INCOMPAT_RTDEVICE)) - fatal("Realtime device not yet supported\n"); + if ((h->v2.xmh_incompat_flags & cpu_to_be32(XFS_MD2_INCOMPAT_RTDEVICE)) && + !mdrestore.realtime_data) + fatal("Realtime device is required\n"); } static void @@ -346,14 +350,17 @@ show_info_v2( const char *md_file) { uint32_t compat_flags; + uint32_t incompat_flags; compat_flags = be32_to_cpu(h->v2.xmh_compat_flags); + incompat_flags = be32_to_cpu(h->v2.xmh_incompat_flags); - printf("%s: %sobfuscated, %s log, external log contents are %sdumped, %s metadata blocks,\n", + printf("%s: %sobfuscated, %s log, external log contents are %sdumped, rt device contents are %sdumped, %s metadata blocks,\n", md_file, compat_flags & XFS_MD2_COMPAT_OBFUSCATED ? "":"not ", compat_flags & XFS_MD2_COMPAT_DIRTYLOG ? "dirty":"clean", compat_flags & XFS_MD2_COMPAT_EXTERNALLOG ? "":"not ", + incompat_flags & XFS_MD2_INCOMPAT_RTDEVICE ? "":"not ", compat_flags & XFS_MD2_COMPAT_FULLBLOCKS ? "full":"zeroed"); } @@ -390,7 +397,8 @@ restore_v2( union mdrestore_headers *h, FILE *md_fp, const struct mdrestore_dev *ddev, - const struct mdrestore_dev *logdev) + const struct mdrestore_dev *logdev, + const struct mdrestore_dev *rtdev) { struct xfs_sb sb; struct xfs_meta_extent xme; @@ -431,6 +439,11 @@ restore_v2( verify_device_size(logdev, sb.sb_logblocks, sb.sb_blocksize); } + if (sb.sb_rblocks > 0) { + ASSERT(mdrestore.realtime_data == true); + verify_device_size(rtdev, sb.sb_rblocks, sb.sb_blocksize); + } + if (pwrite(ddev->fd, block_buffer, len, 0) < 0) fatal("error writing primary superblock: %s\n", strerror(errno)); @@ -459,6 +472,10 @@ restore_v2( device = "log"; fd = logdev->fd; break; + case XME_ADDR_RT_DEVICE: + device = "rt"; + fd = rtdev->fd; + break; default: fatal("Invalid device found in metadump\n"); break; @@ -488,7 +505,7 @@ static struct mdrestore_ops mdrestore_ops_v2 = { static void usage(void) { - fprintf(stderr, "Usage: %s [-V] [-g] [-i] [-l logdev] source target\n", + fprintf(stderr, "Usage: %s [-V] [-g] [-i] [-l logdev] [-r rtdev] source target\n", progname); exit(1); } @@ -501,18 +518,21 @@ main( union mdrestore_headers headers; DEFINE_MDRESTORE_DEV(ddev); DEFINE_MDRESTORE_DEV(logdev); + DEFINE_MDRESTORE_DEV(rtdev); FILE *src_f; char *logdev_path = NULL; + char *rtdev_path = NULL; int c; mdrestore.show_progress = false; mdrestore.show_info = false; mdrestore.progress_since_warning = false; mdrestore.external_log = false; + mdrestore.realtime_data = false; progname = basename(argv[0]); - while ((c = getopt(argc, argv, "gil:V")) != EOF) { + while ((c = getopt(argc, argv, "gil:r:V")) != EOF) { switch (c) { case 'g': mdrestore.show_progress = true; @@ -524,6 +544,10 @@ main( logdev_path = optarg; mdrestore.external_log = true; break; + case 'r': + rtdev_path = optarg; + mdrestore.realtime_data = true; + break; case 'V': printf("%s version %s\n", progname, VERSION); exit(0); @@ -592,10 +616,15 @@ main( if (mdrestore.external_log) open_device(&logdev, logdev_path); - mdrestore.mdrops->restore(&headers, src_f, &ddev, &logdev); + /* check and open realtime device */ + if (mdrestore.realtime_data) + open_device(&rtdev, rtdev_path); + + mdrestore.mdrops->restore(&headers, src_f, &ddev, &logdev, &rtdev); close_device(&ddev); close_device(&logdev); + close_device(&rtdev); if (src_f != stdin) fclose(src_f); From patchwork Mon Dec 23 22:22:58 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: 13919426 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 945E5188596 for ; Mon, 23 Dec 2024 22:22: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=1734992579; cv=none; b=I4xoYTV7H+tDzL3SMYxi7Z1t5a4TCX1JJX2gDQSit/1rgO8he2t6cmpVyxVRanwiNpJ/6zN2Ab1py2ab1PwjSfnSY5t2j2ac/9ffEkahoiLLTruHsOcFtp8E2EjvAMN+ktMZptxTlSRxf/sWpak0xfw/XXsiIbNMISj0utZxtKU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992579; c=relaxed/simple; bh=yPslgJDIRCHIV79TljwiN69IKfj63KHF5QNZLRJbBdo=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cIZ5EPa6qRaqYma8Sv1zf8SevAXdEYMpqDmdcMOySnGQUUmw7OwwWQxV9oSobQfEwDefehx29nhB4L86ox8zMENsbpVvybA1Tn4ukcluTW5jdpwk0TSHBTgazhJQImvpoW05tK5s455xu3Vwpe4BHxLp2+Sb6/anSdAaRZQwedE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Yf4xazSU; 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="Yf4xazSU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71253C4CED3; Mon, 23 Dec 2024 22:22:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992579; bh=yPslgJDIRCHIV79TljwiN69IKfj63KHF5QNZLRJbBdo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Yf4xazSU0J5ytiaTq4w/8Kvnu7a0rZUZJslBc+5S1oV3tFHDlv2tuwqkcHo2+6kM9 pe+MV/V3VZ3TlXl4D0wkxmK7Xw7jsi+hM9d+a3/VscGrF4Rl+SeE79EVWTLQ82oi8H Uktc+LZ5YHLBRfDS+aPwyzJloR4oqlB0hjgvPFJ7duUo+aQfBBDzyQ3DD+m0vM1g2W +TA6xNwO5Tp6WtcLuGhthKA4PP2IUDr9nw/afQG8WmX0TYBqnyEzRWmoNAw7/v4BwB ww6HqokNoTk654DKNEnzqId3Sm9TctwGUp4MZMoDe8iwbm6yQDfqQeh9VKXF4FGzkR t/kwL0rVEZ3+w== Date: Mon, 23 Dec 2024 14:22:58 -0800 Subject: [PATCH 43/51] xfs_spaceman: report on realtime group health From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944462.2297565.5532810486834524461.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Add the realtime group status to the health reporting done by xfs_spaceman. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- man/man8/xfs_spaceman.8 | 5 +++- spaceman/health.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/man/man8/xfs_spaceman.8 b/man/man8/xfs_spaceman.8 index 0d299132a7881b..7d2d1ff94eeb55 100644 --- a/man/man8/xfs_spaceman.8 +++ b/man/man8/xfs_spaceman.8 @@ -91,7 +91,7 @@ .SH COMMANDS .BR "xfs_info" "(8)" prints when querying a filesystem. .TP -.BI "health [ \-a agno] [ \-c ] [ \-f ] [ \-i inum ] [ \-n ] [ \-q ] [ paths ]" +.BI "health [ \-a agno] [ \-c ] [ \-f ] [ \-i inum ] [ \-n ] [ \-q ] [ \-r rgno ] [ paths ]" Reports the health of the given group of filesystem metadata. .RS 1.0i .PD 0 @@ -119,6 +119,9 @@ .SH COMMANDS .B \-q Report only unhealthy metadata. .TP +.B \-r +Report on the health of the given realtime group. +.TP .B paths Report on the health of the files at the given path. .PD diff --git a/spaceman/health.c b/spaceman/health.c index c4d570363fbbf1..4281589324cd44 100644 --- a/spaceman/health.c +++ b/spaceman/health.c @@ -132,6 +132,22 @@ static const struct flag_map ag_flags[] = { {0}, }; +static const struct flag_map rtgroup_flags[] = { + { + .mask = XFS_RTGROUP_GEOM_SICK_SUPER, + .descr = "superblock", + }, + { + .mask = XFS_RTGROUP_GEOM_SICK_BITMAP, + .descr = "realtime bitmap", + }, + { + .mask = XFS_RTGROUP_GEOM_SICK_SUMMARY, + .descr = "realtime summary", + }, + {0}, +}; + static const struct flag_map inode_flags[] = { { .mask = XFS_BS_SICK_INODE, @@ -216,6 +232,25 @@ report_ag_sick( return 0; } +/* Report on a rt group's health. */ +static int +report_rtgroup_sick( + xfs_rgnumber_t rgno) +{ + struct xfs_rtgroup_geometry rgeo = { 0 }; + char descr[256]; + int ret; + + ret = -xfrog_rtgroup_geometry(file->xfd.fd, rgno, &rgeo); + if (ret) { + xfrog_perror(ret, "rtgroup_geometry"); + return 1; + } + snprintf(descr, sizeof(descr) - 1, _("rtgroup %u"), rgno); + report_sick(descr, rtgroup_flags, rgeo.rg_sick, rgeo.rg_checked); + return 0; +} + /* Report on an inode's health. */ static int report_inode_health( @@ -342,7 +377,7 @@ report_bulkstat_health( return error; } -#define OPT_STRING ("a:cfi:nq") +#define OPT_STRING ("a:cfi:nqr:") /* Report on health problems in XFS filesystem. */ static int @@ -352,6 +387,7 @@ health_f( { unsigned long long x; xfs_agnumber_t agno; + xfs_rgnumber_t rgno; bool default_report = true; int c; int ret; @@ -399,6 +435,17 @@ health_f( case 'q': quiet = true; break; + case 'r': + default_report = false; + errno = 0; + x = strtoll(optarg, NULL, 10); + if (!errno && x >= NULLRGNUMBER) + errno = ERANGE; + if (errno) { + perror("rtgroup health"); + return 1; + } + break; default: return command_usage(&health_cmd); } @@ -434,6 +481,12 @@ health_f( if (ret) return 1; break; + case 'r': + rgno = strtoll(optarg, NULL, 10); + ret = report_rtgroup_sick(rgno); + if (ret) + return 1; + break; default: break; } @@ -455,6 +508,11 @@ health_f( if (ret) return 1; } + for (rgno = 0; rgno < file->xfd.fsgeom.rgcount; rgno++) { + ret = report_rtgroup_sick(rgno); + if (ret) + return 1; + } if (comprehensive) { ret = report_bulkstat_health(NULLAGNUMBER); if (ret) @@ -485,6 +543,7 @@ health_help(void) " -i inum -- Report health of a given inode number.\n" " -n -- Try to report file names.\n" " -q -- Only report unhealthy metadata.\n" +" -r rgno -- Report health of the given realtime group.\n" " paths -- Report health of the given file path.\n" "\n")); @@ -495,7 +554,7 @@ static cmdinfo_t health_cmd = { .cfunc = health_f, .argmin = 0, .argmax = -1, - .args = "[-a agno] [-c] [-f] [-i inum] [-n] [-q] [paths]", + .args = "[-a agno] [-c] [-f] [-i inum] [-n] [-q] [-r rgno] [paths]", .flags = CMD_FLAG_ONESHOT, .help = health_help, }; From patchwork Mon Dec 23 22:23: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: 13919427 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 84CE518E35D for ; Mon, 23 Dec 2024 22:23: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=1734992598; cv=none; b=i3fm8DW3SFttDBPTVpLNoWREXt9BqbMGL9/GvlFmRYB2YprOLNqBggC/p4L7y7nVvCfCdAJtUDQohYZlwfmnW2PsTsXuScWYG8V4di3MdieCqGZi5/4oRjCB4qnjSq9T1HTotcyp9XvDHTStbbMzywhg7iruBes45vJTm80oDhY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992598; c=relaxed/simple; bh=0zHaFp0VEK41hRSKex8bP5zz1Lx9ediqO8dvSRWqNqM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hM89MYfMeo8+3Dyi7NKw3dHHzB1K4hvts8ThqZW7ZH4DAnKmfCoWEgFjFu+1TWM2LOuO2C/yuyget1W1MqeZu3tguiWOReF1+TKCCKjsY4tmMkgXPE2HsUZi9jwphF1PC75l3aKN+7I6J24oCHFuKR8fq6OGUFMXcHYGDO7lyTQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=u5+B9c3C; 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="u5+B9c3C" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10F74C4CED3; Mon, 23 Dec 2024 22:23:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992595; bh=0zHaFp0VEK41hRSKex8bP5zz1Lx9ediqO8dvSRWqNqM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=u5+B9c3Cxmf+z+MZTD32JThz87l1eb1DOaM5Fcboef/l0MJnBolxhtHF0N+UTG/u7 Y370T2oxQAUcPA8LOW0lg5VjVgDPkKUVW7yg+eXDgoK3k+QEtIfYzVZop0+W0S+nN3 9LFvNulCligd3PqfHMnnSshPAX6JIoPIBjy6Uo3eKhs0umneVe12G6mmQ9axfnV+Wz 0disiJETe7Rv5XBiv9yMY7VoDTh5XfyDbqw5aruhg+qz6lv6aJhZGIoY/H1Sc9Y4+q n/gu+39VNGpDkJwFftKWQKjr1fiCF9Y9acpqnnbQBt8G4guNEhVwt1xYecqminlc5F rCJkRl5/5L77g== Date: Mon, 23 Dec 2024 14:23:14 -0800 Subject: [PATCH 44/51] xfs_scrub: scrub realtime allocation group metadata From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944477.2297565.5337342089404023845.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Scan realtime group metadata as part of phase 2, just like we do for AG metadata. For pre-rtgroup filesystems, pretend that this is a "rtgroup 0" scrub request because the kernel expects that. Replace the old cond_wait code with a scrub barrier because they're equivalent for two items that cannot be scrubbed in parallel. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- libfrog/scrub.c | 4 +- scrub/phase2.c | 124 ++++++++++++++++++++++++++++++++++++++----------------- scrub/scrub.c | 1 scrub/scrub.h | 9 ++++ 4 files changed, 98 insertions(+), 40 deletions(-) diff --git a/libfrog/scrub.c b/libfrog/scrub.c index 66000f1ed66be4..d40364d35ce0b4 100644 --- a/libfrog/scrub.c +++ b/libfrog/scrub.c @@ -107,12 +107,12 @@ const struct xfrog_scrub_descr xfrog_scrubbers[XFS_SCRUB_TYPE_NR] = { [XFS_SCRUB_TYPE_RTBITMAP] = { .name = "rtbitmap", .descr = "realtime bitmap", - .group = XFROG_SCRUB_GROUP_FS, + .group = XFROG_SCRUB_GROUP_RTGROUP, }, [XFS_SCRUB_TYPE_RTSUM] = { .name = "rtsummary", .descr = "realtime summary", - .group = XFROG_SCRUB_GROUP_FS, + .group = XFROG_SCRUB_GROUP_RTGROUP, }, [XFS_SCRUB_TYPE_UQUOTA] = { .name = "usrquota", diff --git a/scrub/phase2.c b/scrub/phase2.c index c24d137358c74d..c7828c332e7c3a 100644 --- a/scrub/phase2.c +++ b/scrub/phase2.c @@ -21,12 +21,10 @@ struct scan_ctl { /* - * Control mechanism to signal that the rt bitmap file scan is done and - * wake up any waiters. + * Control mechanism to signal that each group's scan of the rt bitmap + * file scan is done and wake up any waiters. */ - pthread_cond_t rbm_wait; - pthread_mutex_t rbm_waitlock; - bool rbm_done; + unsigned int rbm_group_count; bool aborted; }; @@ -202,7 +200,7 @@ scan_fs_metadata( int ret; if (sctl->aborted) - goto out; + return; /* * Try to check all of the metadata files that we just scheduled. If @@ -215,14 +213,14 @@ scan_fs_metadata( ret = scrub_item_check(ctx, &sri); if (ret) { sctl->aborted = true; - goto out; + return; } ret = repair_and_scrub_loop(ctx, &sri, xfrog_scrubbers[type].descr, &defer_repairs); if (ret) { sctl->aborted = true; - goto out; + return; } if (defer_repairs) goto defer; @@ -235,15 +233,60 @@ scan_fs_metadata( ret = defer_fs_repair(ctx, &sri); if (ret) { sctl->aborted = true; - goto out; + return; } +} -out: - if (type == XFS_SCRUB_TYPE_RTBITMAP) { - pthread_mutex_lock(&sctl->rbm_waitlock); - sctl->rbm_done = true; - pthread_cond_broadcast(&sctl->rbm_wait); - pthread_mutex_unlock(&sctl->rbm_waitlock); +/* + * Scrub each rt group's metadata. For pre-rtgroup filesystems, we ask to + * scrub "rtgroup 0" because that's how the kernel ioctl works. + */ +static void +scan_rtgroup_metadata( + struct workqueue *wq, + xfs_agnumber_t rgno, + void *arg) +{ + struct scrub_item sri; + struct scrub_ctx *ctx = (struct scrub_ctx *)wq->wq_ctx; + struct scan_ctl *sctl = arg; + char descr[DESCR_BUFSZ]; + bool defer_repairs; + int ret; + + if (sctl->aborted) + return; + + scrub_item_init_rtgroup(&sri, rgno); + if (ctx->mnt.fsgeom.rgcount == 0) + snprintf(descr, DESCR_BUFSZ, _("realtime")); + else + snprintf(descr, DESCR_BUFSZ, _("rtgroup %u"), rgno); + + /* + * Try to check all of the rtgroup metadata items that we just + * scheduled. If we return with some types still needing a check, try + * repairing any damaged metadata that we've found so far, and try + * again. Abort if we stop making forward progress. + */ + scrub_item_schedule_group(&sri, XFROG_SCRUB_GROUP_RTGROUP); + ret = scrub_item_check(ctx, &sri); + if (ret) { + sctl->aborted = true; + return; + } + + ret = repair_and_scrub_loop(ctx, &sri, descr, &defer_repairs); + if (ret) { + sctl->aborted = true; + return; + } + + /* Everything else gets fixed during phase 4. */ + ret = defer_fs_repair(ctx, &sri); + if (ret) { + sctl->aborted = true; + return; } } @@ -255,17 +298,14 @@ phase2_func( struct workqueue wq; struct scan_ctl sctl = { .aborted = false, - .rbm_done = false, }; struct scrub_item sri; const struct xfrog_scrub_descr *sc = xfrog_scrubbers; xfs_agnumber_t agno; + xfs_rgnumber_t rgno; unsigned int type; int ret, ret2; - pthread_mutex_init(&sctl.rbm_waitlock, NULL); - pthread_cond_init(&sctl.rbm_wait, NULL); - ret = -workqueue_create(&wq, (struct xfs_mount *)ctx, scrub_nproc_workqueue(ctx)); if (ret) { @@ -311,8 +351,6 @@ phase2_func( for (type = 0; type < XFS_SCRUB_TYPE_NR; type++, sc++) { if (sc->group != XFROG_SCRUB_GROUP_FS) continue; - if (type == XFS_SCRUB_TYPE_RTSUM) - continue; ret = -workqueue_add(&wq, scan_fs_metadata, type, &sctl); if (ret) { @@ -325,24 +363,37 @@ phase2_func( if (sctl.aborted) goto out_wq; - /* - * Wait for the rt bitmap to finish scanning, then scan the rt summary - * since the summary can be regenerated completely from the bitmap. - */ - pthread_mutex_lock(&sctl.rbm_waitlock); - while (!sctl.rbm_done) - pthread_cond_wait(&sctl.rbm_wait, &sctl.rbm_waitlock); - pthread_mutex_unlock(&sctl.rbm_waitlock); + if (ctx->mnt.fsgeom.rgcount == 0) { + /* + * When rtgroups were added, the bitmap and summary files + * became per-rtgroup metadata so the scrub interface for the + * two started to accept sm_agno. For pre-rtgroups + * filesystems, we still accept sm_agno==0, so invoke scrub in + * this manner. + */ + ret = -workqueue_add(&wq, scan_rtgroup_metadata, 0, &sctl); + if (ret) { + str_liberror(ctx, ret, + _("queueing realtime scrub work")); + goto out_wq; + } + } + + /* Scan each rtgroup in parallel. */ + for (rgno = 0; + rgno < ctx->mnt.fsgeom.rgcount && !sctl.aborted; + rgno++) { + ret = -workqueue_add(&wq, scan_rtgroup_metadata, rgno, &sctl); + if (ret) { + str_liberror(ctx, ret, + _("queueing rtgroup scrub work")); + goto out_wq; + } + } if (sctl.aborted) goto out_wq; - ret = -workqueue_add(&wq, scan_fs_metadata, XFS_SCRUB_TYPE_RTSUM, &sctl); - if (ret) { - str_liberror(ctx, ret, _("queueing rtsummary scrub work")); - goto out_wq; - } - out_wq: ret2 = -workqueue_terminate(&wq); if (ret2) { @@ -352,9 +403,6 @@ phase2_func( } workqueue_destroy(&wq); out_wait: - pthread_cond_destroy(&sctl.rbm_wait); - pthread_mutex_destroy(&sctl.rbm_waitlock); - if (!ret && sctl.aborted) ret = ECANCELED; return ret; diff --git a/scrub/scrub.c b/scrub/scrub.c index a2fd8d77d82be0..de687af687d32d 100644 --- a/scrub/scrub.c +++ b/scrub/scrub.c @@ -50,6 +50,7 @@ static const unsigned int scrub_deps[XFS_SCRUB_TYPE_NR] = { [XFS_SCRUB_TYPE_QUOTACHECK] = DEP(XFS_SCRUB_TYPE_UQUOTA) | DEP(XFS_SCRUB_TYPE_GQUOTA) | DEP(XFS_SCRUB_TYPE_PQUOTA), + [XFS_SCRUB_TYPE_RTSUM] = DEP(XFS_SCRUB_TYPE_RTBITMAP), }; #undef DEP diff --git a/scrub/scrub.h b/scrub/scrub.h index 3bb3ea1d07bf40..bb94a11dcfce71 100644 --- a/scrub/scrub.h +++ b/scrub/scrub.h @@ -90,6 +90,15 @@ scrub_item_init_ag(struct scrub_item *sri, xfs_agnumber_t agno) sri->sri_gen = -1U; } +static inline void +scrub_item_init_rtgroup(struct scrub_item *sri, xfs_rgnumber_t rgno) +{ + memset(sri, 0, sizeof(*sri)); + sri->sri_agno = rgno; + sri->sri_ino = -1ULL; + sri->sri_gen = -1U; +} + static inline void scrub_item_init_fs(struct scrub_item *sri) { From patchwork Mon Dec 23 22:23: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: 13919428 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 D7E75433D5 for ; Mon, 23 Dec 2024 22:23:30 +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=1734992610; cv=none; b=Hfz8fUHHieGtwQs3H2q7toNeU71okog/MIyhiOmtldiaYvAuwW2MhFfvMR8eovFdYdWMZ4+4LatPy3U48ktWIfix3IKRxj1JlALSbv1QX7bo5z7XNi9/8VE+KdLAaz72B+wTCnPyB//pEk66jxprnSlG4L3Z3zRo88sq9zqHqB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992610; c=relaxed/simple; bh=PuAP7/rY6o5EhuWCa4z57JS1pAiPZp2R+fiPcBuUTPo=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hxxs+Ihiiv9/J+VCxjMAlKjBLcTLJilNqcwWIMcUjyBjFQJh+suGA9D/7KrM3g+0gScaaIttMQu4KyfYr56y8KQ9co6txQcht32DRBYGPJqxA+KfRfZodVVlt5P8hq2dW96ZymMlTgto6a6I9NP3p08OO1wAP67gpI7pX6lCVus= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=t4EdyTO+; 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="t4EdyTO+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4D8CC4CED3; Mon, 23 Dec 2024 22:23:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992610; bh=PuAP7/rY6o5EhuWCa4z57JS1pAiPZp2R+fiPcBuUTPo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=t4EdyTO+211CY31S3z39MXl+VHIHYATWgUXNCNCTBW59DUgfjl6/HCAYNoQPpgRkm 7aAdnPYHdOTLHr8EwxXggOGoFJfKRq5AQf02K+xqjNXYPvB7vsVCg8RJgg2fbkvdcU +VQlPDZ1WQRQoD6ksKGYnDUeVAe0lOJqnih9YiKInj4WfZRRzebb/dfBNaujCyFaau LuJe8UoC+WjaDqPkaWxTVwvAXNCSbfhi9VAmevauoPHZ3Glgapp82uqjLXAmq0uTwy iJk/mQgirnKkLtLYLEGqWFk+92U/OBMtMzLHVT+K73EarLu6dNAhAEFMlLp1i+UuJC EqVqShzi3sj9Q== Date: Mon, 23 Dec 2024 14:23:30 -0800 Subject: [PATCH 45/51] xfs_scrub: check rtgroup metadata directory connections From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944492.2297565.3738699429295344848.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Run the rtgroup metapath scrubber during phase 5 to ensure that any rtgroup metadata files are still connected to the metadir tree after we've pruned any bad links. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- scrub/phase5.c | 24 ++++++++++++++++++++++-- scrub/scrub.h | 4 +++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/scrub/phase5.c b/scrub/phase5.c index 4d0a76a529b55d..22a22915dbc68d 100644 --- a/scrub/phase5.c +++ b/scrub/phase5.c @@ -750,6 +750,7 @@ static int queue_metapath_scan( struct workqueue *wq, bool *abortedp, + xfs_rgnumber_t rgno, uint64_t type) { struct fs_scan_item *item; @@ -762,7 +763,7 @@ queue_metapath_scan( str_liberror(ctx, ret, _("setting up metapath scan")); return ret; } - scrub_item_init_metapath(&item->sri, type); + scrub_item_init_metapath(&item->sri, rgno, type); scrub_item_schedule(&item->sri, XFS_SCRUB_TYPE_METAPATH); item->abortedp = abortedp; @@ -785,6 +786,7 @@ run_kernel_metadir_path_scrubbers( const struct xfrog_scrub_descr *sc; uint64_t type; unsigned int nr_threads = scrub_nproc_workqueue(ctx); + xfs_rgnumber_t rgno; bool aborted = false; int ret, ret2; @@ -804,7 +806,7 @@ run_kernel_metadir_path_scrubbers( if (sc->group != XFROG_SCRUB_GROUP_FS) continue; - ret = queue_metapath_scan(&wq, &aborted, type); + ret = queue_metapath_scan(&wq, &aborted, 0, type); if (ret) { str_liberror(ctx, ret, _("queueing metapath scrub work")); @@ -812,6 +814,24 @@ run_kernel_metadir_path_scrubbers( } } + /* Scan all rtgroup metadata files */ + for (rgno = 0; + rgno < ctx->mnt.fsgeom.rgcount && !aborted; + rgno++) { + for (type = 0; type < XFS_SCRUB_METAPATH_NR; type++) { + sc = &xfrog_metapaths[type]; + if (sc->group != XFROG_SCRUB_GROUP_RTGROUP) + continue; + + ret = queue_metapath_scan(&wq, &aborted, rgno, type); + if (ret) { + str_liberror(ctx, ret, + _("queueing metapath scrub work")); + goto wait; + } + } + } + wait: ret2 = -workqueue_terminate(&wq); if (ret2) { diff --git a/scrub/scrub.h b/scrub/scrub.h index bb94a11dcfce71..24b5ad629c5158 100644 --- a/scrub/scrub.h +++ b/scrub/scrub.h @@ -118,9 +118,11 @@ scrub_item_init_file(struct scrub_item *sri, const struct xfs_bulkstat *bstat) } static inline void -scrub_item_init_metapath(struct scrub_item *sri, uint64_t metapath) +scrub_item_init_metapath(struct scrub_item *sri, xfs_rgnumber_t rgno, + uint64_t metapath) { memset(sri, 0, sizeof(*sri)); + sri->sri_agno = rgno; sri->sri_ino = metapath; } From patchwork Mon Dec 23 22:23:45 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: 13919429 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 8A3B9188596 for ; Mon, 23 Dec 2024 22:23: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=1734992626; cv=none; b=eemJz25AsSecSs51qgNws8vk6E/Zk/2x5Fxnqki3wNIVDY2y85Qj9iRQrkemOHn8yObA6ffB4XsykIKp1c0Ay/BqIpJzcB9BnFliAWsUJjrbQcHIfM4p1vaGwyfTFl1mFjEmo/wcgdA/oimNUr1iZ9+JyMrw7NyU300vNF1wJDk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992626; c=relaxed/simple; bh=E2w7rNJD26HBEMQXdsDCzzac2xRRSRBnqzWIsyPYYpY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AyVeuO75Zh5GVOJbyEzIiX14hbKqdn57Ad/Kmw+XYTPPxp3MnRrDETG1fN75pLDQL/5t3CsfFBMVzDIbriqgF3zN+YO8m+/zc2DfqYpMOfV/GdPIxHIWlqlPvfkyuTqHNKCKxamHOYjfVcTXMR+0et53ZIz7dgQVl3EXXrlxraA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WfX24ZMk; 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="WfX24ZMk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D53AC4CED3; Mon, 23 Dec 2024 22:23:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992626; bh=E2w7rNJD26HBEMQXdsDCzzac2xRRSRBnqzWIsyPYYpY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=WfX24ZMk/QyW5eprF4Q/OsV8QlAOC7L4+r2G/Ccs7Nh7dMZ8KhXnB8p9d7s6CKcoo vcfzhAUJlE67JGBKh5CpZKptr451GzsUUMaJVS59STYRsFhl4bSBDCC4zsMtJpN+As Uqvo6Bb1KF/R8OoQKQ1smQ10p3kFqmDCUg+hUkerrR+d9Ri+h1CwXp7QWygRG9vCJc sSDxrZQiwgwqRPA6lmiH1ZF/HsPr+2U4xVRCXaAfrKLzX5zMQh2yqlFNKgXVZiR3YD h0RuCqcEthP9Is0gVkv1/Jo8De15oksXoyUUeuW/1qfbcpcsfRsCX6KkdMQ5HvImWE 1PkTdNgJ8T6RQ== Date: Mon, 23 Dec 2024 14:23:45 -0800 Subject: [PATCH 46/51] xfs_scrub: cleanup fsmap keys initialization From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944508.2297565.5711210921054427793.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig Use the good old array notations instead of pointer arithmetics. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" [djwong: fold scan_rtg_rmaps cleanups into next patch] Signed-off-by: "Darrick J. Wong" --- scrub/phase6.c | 17 ++++++++--------- scrub/spacemap.c | 32 +++++++++++++++----------------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/scrub/phase6.c b/scrub/phase6.c index e4f26e7f1dd93e..fc63f5aad0bd7b 100644 --- a/scrub/phase6.c +++ b/scrub/phase6.c @@ -495,7 +495,7 @@ report_ioerr( uint64_t length, void *arg) { - struct fsmap keys[2]; + struct fsmap keys[2] = { }; struct ioerr_filerange fr = { .physical = start, .length = length, @@ -506,14 +506,13 @@ report_ioerr( dev = disk_to_dev(dioerr->ctx, dioerr->disk); /* Go figure out which blocks are bad from the fsmap. */ - memset(keys, 0, sizeof(struct fsmap) * 2); - keys->fmr_device = dev; - keys->fmr_physical = start; - (keys + 1)->fmr_device = dev; - (keys + 1)->fmr_physical = start + length - 1; - (keys + 1)->fmr_owner = ULLONG_MAX; - (keys + 1)->fmr_offset = ULLONG_MAX; - (keys + 1)->fmr_flags = UINT_MAX; + keys[0].fmr_device = dev; + keys[0].fmr_physical = start; + keys[1].fmr_device = dev; + keys[1].fmr_physical = start + length - 1; + keys[1].fmr_owner = ULLONG_MAX; + keys[1].fmr_offset = ULLONG_MAX; + keys[1].fmr_flags = UINT_MAX; return -scrub_iterate_fsmap(dioerr->ctx, keys, report_ioerr_fsmap, &fr); } diff --git a/scrub/spacemap.c b/scrub/spacemap.c index e35756db2eed43..4b7fae252d86ca 100644 --- a/scrub/spacemap.c +++ b/scrub/spacemap.c @@ -96,21 +96,20 @@ scan_ag_rmaps( { struct scrub_ctx *ctx = (struct scrub_ctx *)wq->wq_ctx; struct scan_blocks *sbx = arg; - struct fsmap keys[2]; + struct fsmap keys[2] = { }; off_t bperag; int ret; bperag = (off_t)ctx->mnt.fsgeom.agblocks * (off_t)ctx->mnt.fsgeom.blocksize; - memset(keys, 0, sizeof(struct fsmap) * 2); - keys->fmr_device = ctx->fsinfo.fs_datadev; - keys->fmr_physical = agno * bperag; - (keys + 1)->fmr_device = ctx->fsinfo.fs_datadev; - (keys + 1)->fmr_physical = ((agno + 1) * bperag) - 1; - (keys + 1)->fmr_owner = ULLONG_MAX; - (keys + 1)->fmr_offset = ULLONG_MAX; - (keys + 1)->fmr_flags = UINT_MAX; + keys[0].fmr_device = ctx->fsinfo.fs_datadev; + keys[0].fmr_physical = agno * bperag; + keys[1].fmr_device = ctx->fsinfo.fs_datadev; + keys[1].fmr_physical = ((agno + 1) * bperag) - 1; + keys[1].fmr_owner = ULLONG_MAX; + keys[1].fmr_offset = ULLONG_MAX; + keys[1].fmr_flags = UINT_MAX; if (sbx->aborted) return; @@ -135,16 +134,15 @@ scan_dev_rmaps( dev_t dev, struct scan_blocks *sbx) { - struct fsmap keys[2]; + struct fsmap keys[2] = { }; int ret; - memset(keys, 0, sizeof(struct fsmap) * 2); - keys->fmr_device = dev; - (keys + 1)->fmr_device = dev; - (keys + 1)->fmr_physical = ULLONG_MAX; - (keys + 1)->fmr_owner = ULLONG_MAX; - (keys + 1)->fmr_offset = ULLONG_MAX; - (keys + 1)->fmr_flags = UINT_MAX; + keys[0].fmr_device = dev; + keys[1].fmr_device = dev; + keys[1].fmr_physical = ULLONG_MAX; + keys[1].fmr_owner = ULLONG_MAX; + keys[1].fmr_offset = ULLONG_MAX; + keys[1].fmr_flags = UINT_MAX; if (sbx->aborted) return; From patchwork Mon Dec 23 22:24: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: 13919430 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 745C9433D5 for ; Mon, 23 Dec 2024 22: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=1734992642; cv=none; b=gkCM3xt8J5yW/P0QPm+YC5/eXuWJQsnlEBYy13Z07p9vXrfx+HEpeSBt6YwxFkG6GJYVtvnKexs/I4iUzWg5OL5ttbhX7Vxgqxhi50tjPwrTTvF+/mkLdFXfI2//tSwYYzHQ/ivM6M+Rn1WXyQy04Pl12SOZReJzDYki75lFPso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992642; c=relaxed/simple; bh=5arHIO5FYw3NIDGwznHiIzkWGILViZCCfyBsirXkypM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l16NOoD9pobPY9aQcx286jTeZXCNkCxRQHbJcbesmhJCNVHiT75e8FSYAWYBsTPZlsKpP4bzANtdMPwFZ5SZTGI+ix+Ky66QiNaoWQXyzaCrIixOCn2P3OQo2nXHzAg3nrz7q3EjEQHtDy+Il+MnqoIaC3x6zSA9XLwH8bIKwbc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XTy3feko; 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="XTy3feko" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7529C4CED3; Mon, 23 Dec 2024 22:24:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992642; bh=5arHIO5FYw3NIDGwznHiIzkWGILViZCCfyBsirXkypM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=XTy3fekoddPN98Sy8MDs3W1mir4fzIbR+4uO2p3X5vGIQYqfVagxE/BENSRns+xql CdAIQrVCJEveimA61/lj6ZylUqoWoEPH3Ha6+GZTKNdw2ysVbL1dNBl0UFft/Qj6F7 BJiKuH5+QfO/kTjYaOapVY6fUckbwgz2o7sIG4DtHl9Ik8aRFjd6B1S4z40Y+MGPUO Knh+xBd5X88kWMA9RUmFZNBcRArs1P0pgWEfFrBFVMiPmzF6WLvP38xLtRx+6D0k91 vFuaXnee56YzjAu0/U0lTkVwzmqTlkA4WGr892WdLvxUg4lRVw697W3dumadspgxa2 ThHVE72ZQZfLg== Date: Mon, 23 Dec 2024 14:24:01 -0800 Subject: [PATCH 47/51] xfs_scrub: call GETFSMAP for each rt group in parallel From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944523.2297565.11470905301916508239.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong If realtime groups are enabled, we should take advantage of the sharding to speed up the spacemap scans. Do so by issuing per-rtgroup GETFSMAP calls. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- scrub/spacemap.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 8 deletions(-) diff --git a/scrub/spacemap.c b/scrub/spacemap.c index 4b7fae252d86ca..c293ab44a5286c 100644 --- a/scrub/spacemap.c +++ b/scrub/spacemap.c @@ -127,6 +127,43 @@ scan_ag_rmaps( } } +/* Iterate all the reverse mappings of a realtime group. */ +static void +scan_rtg_rmaps( + struct workqueue *wq, + xfs_agnumber_t rgno, + void *arg) +{ + struct scrub_ctx *ctx = (struct scrub_ctx *)wq->wq_ctx; + struct scan_blocks *sbx = arg; + struct fsmap keys[2] = { }; + off_t bperrg = bytes_per_rtgroup(&ctx->mnt.fsgeom); + int ret; + + keys[0].fmr_device = ctx->fsinfo.fs_rtdev; + keys[0].fmr_physical = (xfs_rtblock_t)rgno * bperrg; + keys[1].fmr_device = ctx->fsinfo.fs_rtdev; + keys[1].fmr_physical = ((rgno + 1) * bperrg) - 1; + keys[1].fmr_owner = ULLONG_MAX; + keys[1].fmr_offset = ULLONG_MAX; + keys[1].fmr_flags = UINT_MAX; + + if (sbx->aborted) + return; + + ret = scrub_iterate_fsmap(ctx, keys, sbx->fn, sbx->arg); + if (ret) { + char descr[DESCR_BUFSZ]; + + snprintf(descr, DESCR_BUFSZ, _("dev %d:%d rtgroup %u fsmap"), + major(ctx->fsinfo.fs_datadev), + minor(ctx->fsinfo.fs_datadev), + rgno); + str_liberror(ctx, ret, descr); + sbx->aborted = true; + } +} + /* Iterate all the reverse mappings of a standalone device. */ static void scan_dev_rmaps( @@ -206,14 +243,6 @@ scrub_scan_all_spacemaps( str_liberror(ctx, ret, _("creating fsmap workqueue")); return ret; } - if (ctx->fsinfo.fs_rt) { - ret = -workqueue_add(&wq, scan_rt_rmaps, 0, &sbx); - if (ret) { - sbx.aborted = true; - str_liberror(ctx, ret, _("queueing rtdev fsmap work")); - goto out; - } - } if (ctx->fsinfo.fs_log) { ret = -workqueue_add(&wq, scan_log_rmaps, 0, &sbx); if (ret) { @@ -230,6 +259,31 @@ scrub_scan_all_spacemaps( break; } } + if (ctx->fsinfo.fs_rt) { + for (agno = 0; agno < ctx->mnt.fsgeom.rgcount; agno++) { + ret = -workqueue_add(&wq, scan_rtg_rmaps, agno, &sbx); + if (ret) { + sbx.aborted = true; + str_liberror(ctx, ret, + _("queueing rtgroup fsmap work")); + break; + } + } + + /* + * If the fs doesn't have any realtime groups, scan the entire + * volume all at once, since the above loop did nothing. + */ + if (ctx->mnt.fsgeom.rgcount == 0) { + ret = -workqueue_add(&wq, scan_rt_rmaps, 0, &sbx); + if (ret) { + sbx.aborted = true; + str_liberror(ctx, ret, + _("queueing rtdev fsmap work")); + goto out; + } + } + } out: ret = -workqueue_terminate(&wq); if (ret) { From patchwork Mon Dec 23 22: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: 13919431 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 B3457188596 for ; Mon, 23 Dec 2024 22:24:17 +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=1734992657; cv=none; b=MfPe8YHsi5z3fWLF5VteYOFmADL407TLRjJBV2TjWkljvdDZpam+GPFQpohho/dFYZ/eeaooF1bb9JreGkiNP2Hi63P5++UPzDQ8hs/2dik0XPqLXYAmIy0ThltV8XDsdwYg3taG6JcdPqfQkoGh9RCJWvQUei4+YMty+M7NZMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992657; c=relaxed/simple; bh=xr3Bsg1iR1m4ja8V0V9J2OxHhEpkC0+LUcvHbNO/8Uo=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HlD9sWMisPSOBPYhrfubV+roLWTP2uXm4aLd//6znhaVTj3MaQwbbfybKeD7IUTmkBPK5R3yjESDDx8KwC1prYSJKweyuoNuOsIjVUO66PelOdfkCtpBHRTT6vKMI04jKgFCeEczd3AGSLLMyY2CUJ7RCNuteYJTivnmv+sOPUw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UFeWd9q+; 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="UFeWd9q+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A266C4CED3; Mon, 23 Dec 2024 22:24:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992657; bh=xr3Bsg1iR1m4ja8V0V9J2OxHhEpkC0+LUcvHbNO/8Uo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=UFeWd9q+2PDmojusDHkEOLZbFjXh30D+K9AgioiNy7omNc3wgPwkzNAKtYiJxee6P l11avA48l/4FLlC5np0GO7uWSjxTdiYzJXR+ckIH9URz2pj45C5R9998qeDehJrsLb 4dNsRPia2Oe6FK94Lh2AayqlsfWPR8tdxggWCC5cKbF+anAbIF/wKcXGiOxy8/jWm9 esDJlQQaFcl0Xl/j3/TPk4M31mZ/upKxSUQCPNHV85+wCHnWuz77y4bd2RLN+1AjwJ rVWLUgqXZ/o9toCgb3dvukLaR5KuXKxg5bUTr0N+DraOXUkMjJqkulWbep4brVfWP4 lPLeynZrVTfnA== Date: Mon, 23 Dec 2024 14:24:17 -0800 Subject: [PATCH 48/51] xfs_scrub: trim realtime volumes too From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944538.2297565.780848807747771972.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong On the kernel side, the XFS realtime groups patchset added support for FITRIM of the realtime volume. This support doesn't actually require there to be any realtime groups, so teach scrub to run through the whole region. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- scrub/phase8.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/scrub/phase8.c b/scrub/phase8.c index 1c88460c33962b..adb177ecdafbeb 100644 --- a/scrub/phase8.c +++ b/scrub/phase8.c @@ -59,7 +59,8 @@ fstrim_fsblocks( struct scrub_ctx *ctx, uint64_t start_fsb, uint64_t fsbcount, - uint64_t minlen_fsb) + uint64_t minlen_fsb, + bool ignore_einval) { uint64_t start = cvt_off_fsb_to_b(&ctx->mnt, start_fsb); uint64_t len = cvt_off_fsb_to_b(&ctx->mnt, fsbcount); @@ -72,6 +73,8 @@ fstrim_fsblocks( run = min(len, FSTRIM_MAX_BYTES); error = fstrim(ctx, start, run, minlen); + if (error == EINVAL && ignore_einval) + error = EOPNOTSUPP; if (error == EOPNOTSUPP) { /* Pretend we finished all the work. */ progress_add(len); @@ -193,7 +196,8 @@ fstrim_datadev( */ progress_add(geo->blocksize); fsbcount = min(geo->datablocks - fsbno, geo->agblocks); - error = fstrim_fsblocks(ctx, fsbno, fsbcount, minlen_fsb); + error = fstrim_fsblocks(ctx, fsbno, fsbcount, minlen_fsb, + false); if (error) return error; } @@ -201,15 +205,35 @@ fstrim_datadev( return 0; } +/* Trim the realtime device. */ +static int +fstrim_rtdev( + struct scrub_ctx *ctx) +{ + struct xfs_fsop_geom *geo = &ctx->mnt.fsgeom; + + /* + * The fstrim ioctl pretends that the realtime volume is in the address + * space immediately after the data volume. Ignore EINVAL if someone + * tries to run us on an older kernel. + */ + return fstrim_fsblocks(ctx, geo->datablocks, geo->rtblocks, 0, true); +} + /* Trim the filesystem, if desired. */ int phase8_func( struct scrub_ctx *ctx) { + int error; + if (!fstrim_ok(ctx)) return 0; - return fstrim_datadev(ctx); + error = fstrim_datadev(ctx); + if (error) + return error; + return fstrim_rtdev(ctx); } /* Estimate how much work we're going to do. */ @@ -223,6 +247,8 @@ phase8_estimate( if (fstrim_ok(ctx)) { *items = cvt_off_fsb_to_b(&ctx->mnt, ctx->mnt.fsgeom.datablocks); + *items += cvt_off_fsb_to_b(&ctx->mnt, + ctx->mnt.fsgeom.rtblocks); } else { *items = 0; } From patchwork Mon Dec 23 22:24:32 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: 13919432 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 B358F188596 for ; Mon, 23 Dec 2024 22:24: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=1734992673; cv=none; b=SGw73jnvyTw/NI1GWQc+k97JpHgkVUXg0CYblfTFHYuRwo4r9Vd6hrERsW4ba3HzdUuSxS6+dGNshVgEqZcNdqAwKX8HbLw/8TRLJ2l1mHp6zmnjab7PQY0WDAfgHzJ7c5AAmXMlxtEinLHEVa4tAQPrjQmMO9SDZe8v+vHubzI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992673; c=relaxed/simple; bh=/Hti1zn4lnxGJa0O/Mh4a8yFYdG9sarkJ36U622PjGY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eVEEs9i3y7argHwtyMP+KBG1gPZ6J2pnzh87A0DhMjcishkltbPTs3v9J2oB4svjeGPKdJjI9yaSv4Ex+FShBMWGBd1DIcVx7lAimGk0hSl6R8jMmIkuTludGnekhUpFenQAJ2Am0h4SBGkIJUVNIbDjyCxCkmeGd0/fa3LUC0o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hnAYu5Ef; 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="hnAYu5Ef" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A6E1C4CED3; Mon, 23 Dec 2024 22:24:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992673; bh=/Hti1zn4lnxGJa0O/Mh4a8yFYdG9sarkJ36U622PjGY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=hnAYu5EfvYNXzt8jeAGjmINtZnefhkBuyHe3O6Dyn6Ai6mxPY+81bxBz+JxCqp7qu g5eqI1sEWmzbbtYGoJmnlnYSLymjMaqxb2g8LGPSimflUzZwRNMJ4tLDpFSODuzMqk PE1PNMHVonAyoIDprJn/LpTRcE2fQlkXRlI5IU/tZY6lc7OYTAkNBZdK7To1tmSDmy 1FH1Iz2CKLnaesqO+P+oUjo38DtPu8nx3uXWxLbwb11vp/hfQdMUcoYhGpV7jl60Ca 0eAlwFj4Rmem63eCWLDFr/QKdT2tRabb7yuhv4836ajV3cEfFZA6nOgZFVgYUX8zy0 KS8BA2/KYPGzA== Date: Mon, 23 Dec 2024 14:24:32 -0800 Subject: [PATCH 49/51] xfs_scrub: use histograms to speed up phase 8 on the realtime volume From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944553.2297565.13377801037666623869.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Use the same statistical methods that we use on the data volume to compute the minimum threshold size for fstrims on the realtime volume. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- scrub/phase7.c | 7 +++++++ scrub/phase8.c | 6 +++++- scrub/xfs_scrub.c | 2 ++ scrub/xfs_scrub.h | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/scrub/phase7.c b/scrub/phase7.c index 475d8f157eecca..01097b67879878 100644 --- a/scrub/phase7.c +++ b/scrub/phase7.c @@ -31,6 +31,7 @@ struct summary_counts { /* Free space histogram, in fsb */ struct histogram datadev_hist; + struct histogram rtdev_hist; }; /* @@ -56,6 +57,7 @@ summary_count_init( struct summary_counts *counts = data; init_freesp_hist(&counts->datadev_hist); + init_freesp_hist(&counts->rtdev_hist); } /* Record block usage. */ @@ -83,6 +85,8 @@ count_block_summary( blocks = cvt_b_to_off_fsbt(&ctx->mnt, fsmap->fmr_length); if (fsmap->fmr_device == ctx->fsinfo.fs_datadev) hist_add(&counts->datadev_hist, blocks); + else if (fsmap->fmr_device == ctx->fsinfo.fs_rtdev) + hist_add(&counts->rtdev_hist, blocks); return 0; } @@ -124,7 +128,9 @@ add_summaries( total->agbytes += item->agbytes; hist_import(&total->datadev_hist, &item->datadev_hist); + hist_import(&total->rtdev_hist, &item->rtdev_hist); hist_free(&item->datadev_hist); + hist_free(&item->rtdev_hist); return 0; } @@ -195,6 +201,7 @@ phase7_func( /* Preserve free space histograms for phase 8. */ hist_move(&ctx->datadev_hist, &totalcount.datadev_hist); + hist_move(&ctx->rtdev_hist, &totalcount.rtdev_hist); /* Scan the whole fs. */ error = scrub_count_all_inodes(ctx, &counted_inodes); diff --git a/scrub/phase8.c b/scrub/phase8.c index adb177ecdafbeb..e8c72d8eb851af 100644 --- a/scrub/phase8.c +++ b/scrub/phase8.c @@ -211,13 +211,17 @@ fstrim_rtdev( struct scrub_ctx *ctx) { struct xfs_fsop_geom *geo = &ctx->mnt.fsgeom; + uint64_t minlen_fsb; + + minlen_fsb = fstrim_compute_minlen(ctx, &ctx->rtdev_hist); /* * The fstrim ioctl pretends that the realtime volume is in the address * space immediately after the data volume. Ignore EINVAL if someone * tries to run us on an older kernel. */ - return fstrim_fsblocks(ctx, geo->datablocks, geo->rtblocks, 0, true); + return fstrim_fsblocks(ctx, geo->datablocks, geo->rtblocks, + minlen_fsb, true); } /* Trim the filesystem, if desired. */ diff --git a/scrub/xfs_scrub.c b/scrub/xfs_scrub.c index 3e7d9138f97ec2..90897cc26cd71d 100644 --- a/scrub/xfs_scrub.c +++ b/scrub/xfs_scrub.c @@ -728,6 +728,7 @@ main( int error; hist_init(&ctx.datadev_hist); + hist_init(&ctx.rtdev_hist); fprintf(stdout, "EXPERIMENTAL xfs_scrub program in use! Use at your own risk!\n"); fflush(stdout); @@ -960,6 +961,7 @@ main( unicrash_unload(); hist_free(&ctx.datadev_hist); + hist_free(&ctx.rtdev_hist); /* * If we're being run as a service, the return code must fit the LSB diff --git a/scrub/xfs_scrub.h b/scrub/xfs_scrub.h index 5d336cb55c7422..6ee359f4cebd47 100644 --- a/scrub/xfs_scrub.h +++ b/scrub/xfs_scrub.h @@ -101,6 +101,7 @@ struct scrub_ctx { /* Free space histograms, in fsb */ struct histogram datadev_hist; + struct histogram rtdev_hist; /* * Pick the largest value for fstrim minlen such that we trim at least From patchwork Mon Dec 23 22:24: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: 13919433 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 F2923433D5 for ; Mon, 23 Dec 2024 22:24:48 +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=1734992689; cv=none; b=dghdCsBZG1JYVe7A0JDpKSxXkQk5T37mzecVwwQpEHSwmn73pFZq6ZBPbCnIyC80ds6KUN97eiLZ/GZ8Dl/nvKYIE5rK2Xgx9cf8AIJt24qwPaeddIu/2l+X8Ma9A0YBiPn/APucOudI48QUBZ65VpPkvOPYv/neSOap3vq7FUc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992689; c=relaxed/simple; bh=/nZCbVlq4DDAzuMTWDYGQkFGG85BrqptAzs+zhHKHAM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hMSdDjgS9gnaUX/4eNm1cwso5aX+qegiUYOQNQrgrjaYUIDSccchkoMHwjj2VNf008Kbt3prYrKKh8L6DgkWZbc97obLYu0l/rXbuPgQDIkkzwQyN9XrGP/6WUcalyAyzW33a7HU0jDGh8AtL0/0zeNfdyDnMnuqcVq3/OR0gGk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xe3feRux; 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="Xe3feRux" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBAC1C4CED3; Mon, 23 Dec 2024 22:24:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992688; bh=/nZCbVlq4DDAzuMTWDYGQkFGG85BrqptAzs+zhHKHAM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Xe3feRuxGDf+BabVe+7CC9uBcFNi0YPJASTQMXNvbopLLHeKbXg2FaIwEfXVPK2WR a6UHcCNvC5AtE0JWIKS0ViZcUw0HhvJZa0TrCk/orog6Op/e+Kz8mv2cNaTYfMupAl wW7RpT6xo5zlrK55q9Be6POcB8JCNiNaZfkeEsLBAXGz9Pp41l8I6Z4NXV1BwBcqvd t4s9AJpTJSxjo+1tUnYtucslkj3VzLRAFtl5xcmj+prsqZJIUQga4sayXwGbQYMRuU sCCv3YReTzB8/7ohEuOG0jtWZieO08PWuRHAz7mkmvhvx2dlaNWTgMSzDDajWehaPJ P8yqtNsakFfmQ== Date: Mon, 23 Dec 2024 14:24:48 -0800 Subject: [PATCH 50/51] mkfs: add headers to realtime bitmap blocks From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944569.2297565.14022702152240476260.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong When the rtgroups feature is enabled, format rtbitmap blocks with the appropriate block headers. libxfs takes care of the actual writing for us, so all we have to do is ensure that the bitmap is the correct size. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- mkfs/xfs_mkfs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 2549a636568d1b..5b9fd0e92f7aba 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -3210,6 +3210,7 @@ validate_rtdev( struct cli_params *cli) { struct libxfs_init *xi = cli->xi; + unsigned int rbmblocksize = cfg->blocksize; if (!xi->rt.dev) { if (cli->rtsize) { @@ -3253,8 +3254,10 @@ reported by the device (%u).\n"), _("cannot have an rt subvolume with zero extents\n")); usage(); } + if (cfg->sb_feat.metadir) + rbmblocksize -= sizeof(struct xfs_rtbuf_blkinfo); cfg->rtbmblocks = (xfs_extlen_t)howmany(cfg->rtextents, - NBBY * cfg->blocksize); + NBBY * rbmblocksize); } static bool From patchwork Mon Dec 23 22: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: 13919434 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 D3FA0433D5 for ; Mon, 23 Dec 2024 22:25:04 +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=1734992704; cv=none; b=R4aiGIZXUvQFkP4ijeDOJV5ifqTa7BTZYeKNFRZLrjfKTiuv6WJKiMocdw1AwiCdJGjQxOmjmacE9CTeSqHnulSrHbgBj0G75nSrYAcymm8P+I5c6hi+6Jd0cm6nEX134kshoWN8QmJhByBS/mgFZjFR2ridiJd01n19vAIGmbI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734992704; c=relaxed/simple; bh=0fBIJJXlPTrIcMkNDVTg+IdO3zncwFQZ+/of1X0exhM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CtzEn2Kuz90ulTKiUQ8DBurjRgLaem22w5dqGI+Z9p2BKwqjJWlBYToN6o5qmRdIwEY2bUmPIxnbqI7zNEh8FPSU1mGaComytMUKfiw8yOv9uc3DJPEgbdwGs5tl7/VHDLCM/sAlSpptT4v0K9Bgtv2uiwaP4M9l0/oJQKHVjW0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kJMm2Uso; 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="kJMm2Uso" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70801C4CED3; Mon, 23 Dec 2024 22:25:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734992704; bh=0fBIJJXlPTrIcMkNDVTg+IdO3zncwFQZ+/of1X0exhM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=kJMm2UsoZDj3C7J7+SqcPkbk17FmDi3Z93LkDhVZXCb4j+2Ef6oOy6elM0zvr6kwc wwfJY1iir4Y35jM8pEkjYF40ZOMGjbRDOJpoqW9B5HmGw7MSv1djfBQAUTk/mwEV/P hzYyKax4nUE4s7ui9cfcdkFsR8AJ3+jG91HfFPFnGG6g0TzWLWiAx4gHPENXvxkIDr PI9EN4qTg6H0ylj6Uy+UXUJAm+AAIyqhDcG41MPcZBD9oUE5P6bY7eoggN17iaLqaK VBvvHeYindsUiJtRyAgKkXsDOJ3yOMg7D9MkYka7dIoetbtBBjA+Imd7ImGdnfEV86 ssvML7G52Kt0w== Date: Mon, 23 Dec 2024 14:25:04 -0800 Subject: [PATCH 51/51] mkfs: format realtime groups From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498944584.2297565.1780017668106157588.stgit@frogsfrogsfrogs> In-Reply-To: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> References: <173498943717.2297565.4022811207967161638.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Create filesystems with the realtime group feature enabled. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- libfrog/div64.h | 6 + libfrog/util.c | 12 ++ libfrog/util.h | 1 libxfs/libxfs_api_defs.h | 2 libxfs/libxfs_priv.h | 6 - libxfs/topology.c | 42 +++++++ libxfs/topology.h | 3 man/man8/mkfs.xfs.8.in | 31 +++++ mkfs/proto.c | 88 ++++++++++++-- mkfs/xfs_mkfs.c | 286 +++++++++++++++++++++++++++++++++++++++++++++- 10 files changed, 448 insertions(+), 29 deletions(-) diff --git a/libfrog/div64.h b/libfrog/div64.h index 673b01cbab34de..4b0d4c3b3c704d 100644 --- a/libfrog/div64.h +++ b/libfrog/div64.h @@ -93,4 +93,10 @@ howmany_64(uint64_t x, uint32_t y) return x; } +static inline __attribute__((const)) +int is_power_of_2(unsigned long n) +{ + return (n != 0 && ((n & (n - 1)) == 0)); +} + #endif /* LIBFROG_DIV64_H_ */ diff --git a/libfrog/util.c b/libfrog/util.c index 46047571a5531f..4e130c884c17a2 100644 --- a/libfrog/util.c +++ b/libfrog/util.c @@ -36,3 +36,15 @@ memchr_inv(const void *start, int c, size_t bytes) return NULL; } + +unsigned int +log2_rounddown(unsigned long long i) +{ + int rval; + + for (rval = NBBY * sizeof(i) - 1; rval >= 0; rval--) { + if ((1ULL << rval) < i) + break; + } + return rval; +} diff --git a/libfrog/util.h b/libfrog/util.h index 8b4ee7c1333b6b..d1c4dd40fc926c 100644 --- a/libfrog/util.h +++ b/libfrog/util.h @@ -9,6 +9,7 @@ #include unsigned int log2_roundup(unsigned int i); +unsigned int log2_rounddown(unsigned long long i); #define min_t(type,x,y) \ ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; }) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index dbdf5d100ec8e9..a8416dfbb27f59 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -94,6 +94,7 @@ #define xfs_btree_stage_afakeroot libxfs_btree_stage_afakeroot #define xfs_btree_stage_ifakeroot libxfs_btree_stage_ifakeroot #define xfs_btree_visit_blocks libxfs_btree_visit_blocks +#define xfs_buf_delwri_queue libxfs_buf_delwri_queue #define xfs_buf_delwri_submit libxfs_buf_delwri_submit #define xfs_buf_get libxfs_buf_get #define xfs_buf_get_uncached libxfs_buf_get_uncached @@ -302,6 +303,7 @@ #define xfs_rtfree_blocks libxfs_rtfree_blocks #define xfs_update_rtsb libxfs_update_rtsb #define xfs_sb_from_disk libxfs_sb_from_disk +#define xfs_sb_mount_rextsize libxfs_sb_mount_rextsize #define xfs_sb_quota_from_disk libxfs_sb_quota_from_disk #define xfs_sb_read_secondary libxfs_sb_read_secondary #define xfs_sb_to_disk libxfs_sb_to_disk diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index dd24bdc2d169d9..a1401b2c1e409b 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -307,12 +307,6 @@ find_next_zero_bit(const unsigned long *addr, unsigned long size, } #define find_first_zero_bit(addr, size) find_next_zero_bit((addr), (size), 0) -static inline __attribute__((const)) -int is_power_of_2(unsigned long n) -{ - return (n != 0 && ((n & (n - 1)) == 0)); -} - /* * xfs_iroundup: round up argument to next power of two */ diff --git a/libxfs/topology.c b/libxfs/topology.c index 94adb5be7bdcae..8c6affb4c4e436 100644 --- a/libxfs/topology.c +++ b/libxfs/topology.c @@ -87,6 +87,48 @@ calc_default_ag_geometry( *agcount = dblocks / blocks + (dblocks % blocks != 0); } +void +calc_default_rtgroup_geometry( + int blocklog, + uint64_t rblocks, + uint64_t *rgsize, + uint64_t *rgcount) +{ + uint64_t blocks = 0; + int shift = 0; + + /* + * For a single underlying storage device over 4TB in size use the + * maximum rtgroup size. Between 128MB and 4TB, just use 4 rtgroups + * and scale up smoothly between min/max rtgroup sizes. + */ + if (rblocks >= TERABYTES(4, blocklog)) { + blocks = XFS_MAX_RGBLOCKS; + goto done; + } + if (rblocks >= MEGABYTES(128, blocklog)) { + shift = XFS_NOMULTIDISK_AGLOG; + goto calc_blocks; + } + + /* + * If rblocks is not evenly divisible by the number of desired rt + * groups, round "blocks" up so we don't lose the last bit of the + * filesystem. The same principle applies to the rt group count, so we + * don't lose the last rt group! + */ +calc_blocks: + ASSERT(shift >= 0 && shift <= XFS_MULTIDISK_AGLOG); + blocks = rblocks >> shift; + if (rblocks & xfs_mask32lo(shift)) { + if (blocks < XFS_MAX_RGBLOCKS) + blocks++; + } +done: + *rgsize = blocks; + *rgcount = rblocks / blocks + (rblocks % blocks != 0); +} + /* * Check for existing filesystem or partition table on device. * Returns: diff --git a/libxfs/topology.h b/libxfs/topology.h index fa0a23b7738624..207a8a7f150556 100644 --- a/libxfs/topology.h +++ b/libxfs/topology.h @@ -37,6 +37,9 @@ calc_default_ag_geometry( uint64_t *agsize, uint64_t *agcount); +void calc_default_rtgroup_geometry(int blocklog, uint64_t rblocks, + uint64_t *rgsize, uint64_t *rgcount); + extern int check_overwrite( const char *device); diff --git a/man/man8/mkfs.xfs.8.in b/man/man8/mkfs.xfs.8.in index de5f6baf59df95..0c0cf1dc151e4f 100644 --- a/man/man8/mkfs.xfs.8.in +++ b/man/man8/mkfs.xfs.8.in @@ -1141,6 +1141,37 @@ .SH OPTIONS .BI noalign This option disables stripe size detection, enforcing a realtime device with no stripe geometry. +.TP +.BI rgcount= value +This is used to specify the number of allocation groups in the realtime +section. +The realtime section of the filesystem can be divided into allocation groups to +improve the performance of XFS. +More allocation groups imply that more parallelism can be achieved when +allocating blocks. +The minimum allocation group size is 2 realtime extents; the maximum size is +2^31 blocks. +The rt section of the filesystem is divided into +.I value +allocation groups (default value is scaled automatically based +on the underlying device size). +.TP +.BI rgsize= value +This is an alternative to using the +.B rgcount +suboption. The +.I value +is the desired size of the realtime allocation group expressed in bytes +(usually using the +.BR m " or " g +suffixes). +This value must be a multiple of the realtime extent size, +must be at least two realtime extents, and no more than 2^31 blocks. +The +.B rgcount +and +.B rgsize +suboptions are mutually exclusive. .RE .PP .PD 0 diff --git a/mkfs/proto.c b/mkfs/proto.c index 846b1c9a9e8a21..4e9e28d4eea1ca 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -1008,8 +1008,8 @@ create_sb_metadata_file( } /* - * Free the whole realtime area using transactions. - * Do one transaction per bitmap block. + * Free the whole realtime area using transactions. Each transaction may clear + * up to 32 rtbitmap blocks. */ static void rtfreesp_init( @@ -1017,8 +1017,8 @@ rtfreesp_init( { struct xfs_mount *mp = rtg_mount(rtg); struct xfs_trans *tp; - xfs_rtxnum_t rtx; - xfs_rtxnum_t ertx; + const xfs_rtxnum_t max_rtx = mp->m_rtx_per_rbmblock * 32; + xfs_rtxnum_t start_rtx = 0; int error; /* @@ -1034,37 +1034,56 @@ rtfreesp_init( if (error) fail(_("Initialization of rtsummary inode failed"), error); + if (!mp->m_sb.sb_rbmblocks) + return; + /* * Then free the blocks into the allocator, one bitmap block at a time. */ - for (rtx = 0; rtx < mp->m_sb.sb_rextents; rtx = ertx) { + while (start_rtx < rtg->rtg_extents) { + xfs_rtxlen_t nr = min(rtg->rtg_extents - start_rtx, max_rtx); + + /* + * The rt superblock, if present, must not be marked free. + * This may be the only rtx in the entire volume. + */ + if (xfs_has_rtsb(mp) && rtg_rgno(rtg) == 0 && start_rtx == 0) { + start_rtx++; + nr--; + + if (start_rtx == rtg->rtg_extents) + break; + } + error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp); if (error) res_failed(error); libxfs_trans_ijoin(tp, rtg->rtg_inodes[XFS_RTGI_BITMAP], 0); - ertx = min(mp->m_sb.sb_rextents, - rtx + NBBY * mp->m_sb.sb_blocksize); - - error = -libxfs_rtfree_extent(tp, rtg, rtx, - (xfs_rtxlen_t)(ertx - rtx)); + error = -libxfs_rtfree_extent(tp, rtg, start_rtx, nr); if (error) { - fail(_("Error initializing the realtime space"), - error); + fprintf(stderr, + _("Error initializing the realtime free space near rgno %u rtx %lld-%lld (max %lld): %s\n"), + rtg_rgno(rtg), + (unsigned long long)start_rtx, + (unsigned long long)start_rtx + nr - 1, + (unsigned long long)rtg->rtg_extents, + strerror(error)); + exit(1); } + error = -libxfs_trans_commit(tp); if (error) fail(_("Initialization of the realtime space failed"), error); + + start_rtx += nr; } } -/* - * Allocate the realtime bitmap and summary inodes, and fill in data if any. - */ static void -rtinit( +rtinit_nogroups( struct xfs_mount *mp) { struct xfs_rtgroup *rtg = NULL; @@ -1079,6 +1098,43 @@ rtinit( } } +static void +rtinit_groups( + struct xfs_mount *mp) +{ + struct xfs_rtgroup *rtg = NULL; + unsigned int i; + int error; + + error = -libxfs_rtginode_mkdir_parent(mp); + if (error) + fail(_("rtgroup directory allocation failed"), error); + + while ((rtg = xfs_rtgroup_next(mp, rtg))) { + for (i = 0; i < XFS_RTGI_MAX; i++) { + error = -libxfs_rtginode_create(rtg, i, true); + if (error) + fail(_("rt group inode creation failed"), + error); + } + + rtfreesp_init(rtg); + } +} + +/* + * Allocate the realtime bitmap and summary inodes, and fill in data if any. + */ +static void +rtinit( + struct xfs_mount *mp) +{ + if (xfs_has_rtgroups(mp)) + rtinit_groups(mp); + else + rtinit_nogroups(mp); +} + static off_t filesize( int fd) diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 5b9fd0e92f7aba..cd94cfd0b93706 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -132,6 +132,8 @@ enum { R_FILE, R_NAME, R_NOALIGN, + R_RGCOUNT, + R_RGSIZE, R_MAX_OPTS, }; @@ -727,6 +729,8 @@ static struct opt_params ropts = { [R_FILE] = "file", [R_NAME] = "name", [R_NOALIGN] = "noalign", + [R_RGCOUNT] = "rgcount", + [R_RGSIZE] = "rgsize", [R_MAX_OPTS] = NULL, }, .subopt_params = { @@ -766,6 +770,21 @@ static struct opt_params ropts = { .defaultval = 1, .conflicts = { { NULL, LAST_CONFLICT } }, }, + { .index = R_RGCOUNT, + .conflicts = { { &ropts, R_RGSIZE }, + { NULL, LAST_CONFLICT } }, + .minval = 1, + .maxval = XFS_MAX_RGNUMBER, + .defaultval = SUBOPT_NEEDS_VAL, + }, + { .index = R_RGSIZE, + .conflicts = { { &ropts, R_RGCOUNT }, + { NULL, LAST_CONFLICT } }, + .convert = true, + .minval = 0, + .maxval = (unsigned long long)XFS_MAX_RGBLOCKS << XFS_MAX_BLOCKSIZE_LOG, + .defaultval = SUBOPT_NEEDS_VAL, + }, }, }; @@ -940,6 +959,7 @@ struct cli_params { /* parameters that depend on sector/block size being validated. */ char *dsize; char *agsize; + char *rgsize; char *dsu; char *dirblocksize; char *logsize; @@ -961,6 +981,7 @@ struct cli_params { /* parameters where 0 is not a valid value */ int64_t agcount; + int64_t rgcount; int inodesize; int inopblock; int imaxpct; @@ -1017,6 +1038,9 @@ struct mkfs_params { uint64_t agsize; uint64_t agcount; + uint64_t rgsize; + uint64_t rgcount; + int imaxpct; bool loginternal; @@ -1075,7 +1099,7 @@ usage( void ) /* no-op info only */ [-N]\n\ /* prototype file */ [-p fname]\n\ /* quiet */ [-q]\n\ -/* realtime subvol */ [-r extsize=num,size=num,rtdev=xxx]\n\ +/* realtime subvol */ [-r extsize=num,size=num,rtdev=xxx,rgcount=n,rgsize=n]\n\ /* sectorsize */ [-s size=num]\n\ /* version */ [-V]\n\ devicename\n\ @@ -1989,6 +2013,12 @@ rtdev_opts_parser( case R_NOALIGN: cli->sb_feat.nortalign = getnum(value, opts, subopt); break; + case R_RGCOUNT: + cli->rgcount = getnum(value, opts, subopt); + break; + case R_RGSIZE: + cli->rgsize = getstr(value, opts, subopt); + break; default: return -EINVAL; } @@ -2531,6 +2561,20 @@ _("cowextsize not supported without reflink support\n")); cli->sb_feat.exchrange = true; } + /* + * Exchange-range will be needed for space reorganization on filesystems + * with realtime rmap or realtime reflink enabled, and there is no good + * reason to ever disable it on a file system with new enough features. + */ + if (cli->sb_feat.metadir && !cli->sb_feat.exchrange) { + if (cli_opt_set(&iopts, I_EXCHANGE)) { + fprintf(stderr, +_("metadir not supported without exchange-range support\n")); + usage(); + } + cli->sb_feat.exchrange = true; + } + /* * Copy features across to config structure now. */ @@ -3210,7 +3254,6 @@ validate_rtdev( struct cli_params *cli) { struct libxfs_init *xi = cli->xi; - unsigned int rbmblocksize = cfg->blocksize; if (!xi->rt.dev) { if (cli->rtsize) { @@ -3254,10 +3297,13 @@ reported by the device (%u).\n"), _("cannot have an rt subvolume with zero extents\n")); usage(); } - if (cfg->sb_feat.metadir) - rbmblocksize -= sizeof(struct xfs_rtbuf_blkinfo); + + /* + * Note for rtgroup file systems this will be overriden in + * calculate_rtgroup_geometry. + */ cfg->rtbmblocks = (xfs_extlen_t)howmany(cfg->rtextents, - NBBY * rbmblocksize); + NBBY * cfg->blocksize); } static bool @@ -3498,6 +3544,189 @@ an AG size that is one stripe unit smaller or larger, for example %llu.\n"), cfg->agsize, cfg->agcount); } +static uint64_t +calc_rgsize_extsize_nonpower( + struct mkfs_params *cfg) +{ + uint64_t try_rgsize, rgsize, rgcount; + + /* + * For non-power-of-two rt extent sizes, round the rtgroup size down to + * the nearest extent. + */ + calc_default_rtgroup_geometry(cfg->blocklog, cfg->rtblocks, &rgsize, + &rgcount); + rgsize -= rgsize % cfg->rtextblocks; + rgsize = min(XFS_MAX_RGBLOCKS, rgsize); + + /* + * If we would be left with a too-small rtgroup, increase or decrease + * the size of the group until we have a working geometry. + */ + for (try_rgsize = rgsize; + try_rgsize <= XFS_MAX_RGBLOCKS - cfg->rtextblocks; + try_rgsize += cfg->rtextblocks) { + if (cfg->rtblocks % try_rgsize >= (2 * cfg->rtextblocks)) + return try_rgsize; + } + for (try_rgsize = rgsize; + try_rgsize > (2 * cfg->rtextblocks); + try_rgsize -= cfg->rtextblocks) { + if (cfg->rtblocks % try_rgsize >= (2 * cfg->rtextblocks)) + return try_rgsize; + } + + fprintf(stderr, +_("realtime group size (%llu) not at all congruent with extent size (%llu)\n"), + (unsigned long long)rgsize, + (unsigned long long)cfg->rtextblocks); + usage(); + return 0; +} + +static uint64_t +calc_rgsize_extsize_power( + struct mkfs_params *cfg) +{ + uint64_t try_rgsize, rgsize, rgcount; + unsigned int rgsizelog; + + /* + * Find the rt group size that is both a power of two and yields at + * least as many rt groups as the default geometry specified. + */ + calc_default_rtgroup_geometry(cfg->blocklog, cfg->rtblocks, &rgsize, + &rgcount); + rgsizelog = log2_rounddown(rgsize); + rgsize = min(XFS_MAX_RGBLOCKS, 1U << rgsizelog); + + /* + * If we would be left with a too-small rtgroup, increase or decrease + * the size of the group by powers of 2 until we have a working + * geometry. If that doesn't work, try bumping by the extent size. + */ + for (try_rgsize = rgsize; + try_rgsize <= XFS_MAX_RGBLOCKS - cfg->rtextblocks; + try_rgsize <<= 2) { + if (cfg->rtblocks % try_rgsize >= (2 * cfg->rtextblocks)) + return try_rgsize; + } + for (try_rgsize = rgsize; + try_rgsize > (2 * cfg->rtextblocks); + try_rgsize >>= 2) { + if (cfg->rtblocks % try_rgsize >= (2 * cfg->rtextblocks)) + return try_rgsize; + } + for (try_rgsize = rgsize; + try_rgsize <= XFS_MAX_RGBLOCKS - cfg->rtextblocks; + try_rgsize += cfg->rtextblocks) { + if (cfg->rtblocks % try_rgsize >= (2 * cfg->rtextblocks)) + return try_rgsize; + } + for (try_rgsize = rgsize; + try_rgsize > (2 * cfg->rtextblocks); + try_rgsize -= cfg->rtextblocks) { + if (cfg->rtblocks % try_rgsize >= (2 * cfg->rtextblocks)) + return try_rgsize; + } + + fprintf(stderr, +_("realtime group size (%llu) not at all congruent with extent size (%llu)\n"), + (unsigned long long)rgsize, + (unsigned long long)cfg->rtextblocks); + usage(); + return 0; +} + +static void +calculate_rtgroup_geometry( + struct mkfs_params *cfg, + struct cli_params *cli) +{ + if (!cli->sb_feat.metadir) { + cfg->rgcount = 0; + cfg->rgsize = 0; + return; + } + + if (cli->rgsize) { /* User-specified rtgroup size */ + cfg->rgsize = getnum(cli->rgsize, &ropts, R_RGSIZE); + + /* + * Check specified agsize is a multiple of blocksize. + */ + if (cfg->rgsize % cfg->blocksize) { + fprintf(stderr, +_("rgsize (%s) not a multiple of fs blk size (%d)\n"), + cli->rgsize, cfg->blocksize); + usage(); + } + cfg->rgsize /= cfg->blocksize; + cfg->rgcount = cfg->rtblocks / cfg->rgsize + + (cfg->rtblocks % cfg->rgsize != 0); + + } else if (cli->rgcount) { /* User-specified rtgroup count */ + cfg->rgcount = cli->rgcount; + cfg->rgsize = cfg->rtblocks / cfg->rgcount + + (cfg->rtblocks % cfg->rgcount != 0); + } else if (cfg->rtblocks == 0) { + /* + * If nobody specified a realtime device or the rtgroup size, + * try 1TB, rounded down to the nearest rt extent. + */ + cfg->rgsize = TERABYTES(1, cfg->blocklog); + cfg->rgsize -= cfg->rgsize % cfg->rtextblocks; + cfg->rgcount = 0; + } else if (cfg->rtblocks < cfg->rtextblocks * 2) { + /* too small even for a single group */ + cfg->rgsize = cfg->rtblocks; + cfg->rgcount = 0; + } else if (is_power_of_2(cfg->rtextblocks)) { + cfg->rgsize = calc_rgsize_extsize_power(cfg); + cfg->rgcount = cfg->rtblocks / cfg->rgsize + + (cfg->rtblocks % cfg->rgsize != 0); + } else { + cfg->rgsize = calc_rgsize_extsize_nonpower(cfg); + cfg->rgcount = cfg->rtblocks / cfg->rgsize + + (cfg->rtblocks % cfg->rgsize != 0); + } + + if (cfg->rgsize > XFS_MAX_RGBLOCKS) { + fprintf(stderr, +_("realtime group size (%llu) must be less than the maximum (%u)\n"), + (unsigned long long)cfg->rgsize, + XFS_MAX_RGBLOCKS); + usage(); + } + + if (cfg->rgsize % cfg->rtextblocks != 0) { + fprintf(stderr, +_("realtime group size (%llu) not a multiple of rt extent size (%llu)\n"), + (unsigned long long)cfg->rgsize, + (unsigned long long)cfg->rtextblocks); + usage(); + } + + if (cfg->rgsize <= cfg->rtextblocks) { + fprintf(stderr, +_("realtime group size (%llu) must be at least two realtime extents\n"), + (unsigned long long)cfg->rgsize); + usage(); + } + + if (cfg->rgcount > XFS_MAX_RGNUMBER) { + fprintf(stderr, +_("realtime group count (%llu) must be less than the maximum (%u)\n"), + (unsigned long long)cfg->rgcount, + XFS_MAX_RGNUMBER); + usage(); + } + + if (cfg->rtextents) + cfg->rtbmblocks = howmany(cfg->rgsize / cfg->rtextblocks, + NBBY * (cfg->blocksize - sizeof(struct xfs_rtbuf_blkinfo))); +} + static void calculate_imaxpct( struct mkfs_params *cfg, @@ -3651,8 +3880,13 @@ sb_set_features( */ sbp->sb_versionnum |= XFS_SB_VERSION_ATTRBIT; } - if (fp->metadir) + if (fp->metadir) { sbp->sb_features_incompat |= XFS_SB_FEAT_INCOMPAT_METADIR; + sbp->sb_rgcount = cfg->rgcount; + sbp->sb_rgextents = cfg->rgsize / cfg->rtextblocks; + sbp->sb_rgblklog = libxfs_compute_rgblklog(sbp->sb_rgextents, + cfg->rtextblocks); + } } /* @@ -4046,6 +4280,7 @@ start_superblock_setup( sbp->sb_rblocks = cfg->rtblocks; sbp->sb_rextsize = cfg->rtextblocks; mp->m_features |= libxfs_sb_version_to_features(sbp); + libxfs_sb_mount_rextsize(mp, sbp); } static void @@ -4106,7 +4341,7 @@ finish_superblock_setup( sbp->sb_unit = cfg->dsunit; sbp->sb_width = cfg->dswidth; mp->m_features |= libxfs_sb_version_to_features(sbp); - + libxfs_sb_mount_rextsize(mp, sbp); } /* Prepare an uncached buffer, ready to write something out. */ @@ -4488,6 +4723,39 @@ set_autofsck( libxfs_irele(args.dp); } +/* Write the realtime superblock */ +static void +write_rtsb( + struct xfs_mount *mp) +{ + struct xfs_buf *rtsb_bp; + struct xfs_buf *sb_bp = libxfs_getsb(mp); + int error; + + if (!sb_bp) { + fprintf(stderr, + _("%s: couldn't grab primary superblock buffer\n"), progname); + exit(1); + } + + error = -libxfs_buf_get_uncached(mp->m_rtdev_targp, + XFS_FSB_TO_BB(mp, 1), XFS_RTSB_DADDR, + &rtsb_bp); + if (error) { + fprintf(stderr, + _("%s: couldn't grab realtime superblock buffer\n"), progname); + exit(1); + } + + rtsb_bp->b_maps[0].bm_bn = XFS_RTSB_DADDR; + rtsb_bp->b_ops = &xfs_rtsb_buf_ops; + + libxfs_update_rtsb(rtsb_bp, sb_bp); + libxfs_buf_mark_dirty(rtsb_bp); + libxfs_buf_relse(rtsb_bp); + libxfs_buf_relse(sb_bp); +} + int main( int argc, @@ -4704,6 +4972,7 @@ main( */ calculate_initial_ag_geometry(&cfg, &cli, &xi); align_ag_geometry(&cfg); + calculate_rtgroup_geometry(&cfg, &cli); calculate_imaxpct(&cfg, &cli); @@ -4804,6 +5073,9 @@ main( exit(1); } + if (xfs_has_rtsb(mp) && cfg.rtblocks > 0) + write_rtsb(mp); + /* * Initialise the freespace freelists (i.e. AGFLs) in each AG. */