From patchwork Sat Dec 7 00:05:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898094 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 66CCB182 for ; Sat, 7 Dec 2024 00:05:11 +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=1733529911; cv=none; b=dxER0NTozZaRLkak7oLU3HYQIm/X5dmWgCtzKy9itk7d1IPDIPwmGnCmpcZOYiRMgqR4Dql/4n6j/CAigzLtNe7CyMokW7Gyvll1SQHZ/4px5MkSxumTbPcfGsFRFJ+kJF0BpzCSebJNNM3UffIWPJD/pQ0Xb5/uD2Wufd6lE3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733529911; c=relaxed/simple; bh=Av/VOQdsA7QOQsWUD36EIwCE2gr5dwxG1IaXdqKJeqE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BZPL2DzD6vil9rLZ3+9esKK+i+Pla34KqZysULd/1Ow9kCVtYWkWBRd7yNtGgIJ3ZGQeQAU1xK1iXJJlTNJs6s882MaNSFrRkBWq2IDLYPkWZdUIz0TZ0ZL5ZCH2cfkoCqYX5WgG2E5+yWUJ+T+rZszmZADq753IbquHAZk4m/Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=frcsHrXF; 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="frcsHrXF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 431BBC4CED1; Sat, 7 Dec 2024 00:05:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733529911; bh=Av/VOQdsA7QOQsWUD36EIwCE2gr5dwxG1IaXdqKJeqE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=frcsHrXFZ8WNc+Uh4lziPRMcq6XBDgex/BODD7mncFgju/Gt3WU3RYT309KwifsWT wcdUzpgpr6Pj7RehqeaFNJQY1HocDbCTCLMlES8LD7Gq1GUJTdnuVRVHB2WKTk3vOB VgCfwEyFFZrux0PqTSFzX7AeM51eAdijFyPeT2OWoWaNYHeKS0NF5tF68Az9XRC4Js +HgCAvQDACZ4+Fen5E38/EKSK14IBzD3y3JPrKsEY2zzZJtWAKJTVOoxlFZley5MhI q1J9waDbUiA72rTgjhp9nMTfbG3EGVXbBqxJrfCCc+LAIH7aHS+5NvjhpJ4Hx7GJPQ KGqBxy/9dPz4g== Date: Fri, 06 Dec 2024 16:05:10 -0800 Subject: [PATCH 01/50] libxfs: remove XFS_ILOCK_RT* From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352751961.126362.26672776797656879.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:05:26 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: 13898095 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 0550E182 for ; Sat, 7 Dec 2024 00:05: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=1733529927; cv=none; b=rlrM+RzOcZSCk7Bl8nQldJJGT0PQwVhxg6eziGF/L43AZqJ5DJWql84xS6mJQwxMjQC+8Ey8Ow04GIQTk6RQnLU3uWgy1Bn9WIMj3Yg97H+qdrk4uAOppD/WV9zwQbmMfJX28Nmi6jLKZ0eYBybaQYWoahebO7XyH0fPpv/PmAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733529927; c=relaxed/simple; bh=eVZiFJC+sGekSRAogRHQZ+mwk4usokq8Sjdg/wQuDOQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BNHAUCga/bv2F7wsRfvDLdCJWzib911sn7VD2iNXcFptKaDbRHrVxaO/TVu+1U3wBgVrwm6AQWkWmyiwG5TdSOjBZ+6J656V10GbpUy8L/UEG9oOAbcrMOI0rfgmS4FruQu0nRGY+mTlNg5/828hOgb6g9mbCoS+oXEGa9y+m9I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bvUooHbe; 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="bvUooHbe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D59BEC4CED1; Sat, 7 Dec 2024 00:05:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733529926; bh=eVZiFJC+sGekSRAogRHQZ+mwk4usokq8Sjdg/wQuDOQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=bvUooHbeBpcn8xBxLsTyDbdY43cBgkFDg9Pv7//UMwIBJzKQRHD2UTvD7C6kb/QUG 2iCq/soj/1WqIITcE3iIC+C6L/jY/PEDZ3afDw1cftDWS9fjZ6m/kkyC+VA/of268T jcI682QvfMMdvijJDiXlv1i860NUl78vskNKPgntkPQPEdk/4OvlXfNUEofjTlP/zF HY+0V5kwfJTQY5is44ZREs4yW57LcmWwNKM/QebkSrceI997cRE7jYUOU5WwI4CaKx WDzmNj6p1bxXyqoWahXjiMTsUAkPvK18XUhlfto+FaXOcEjHRNmwfIlWCy2vh4Wwuo O2N0jntPI46RQ== Date: Fri, 06 Dec 2024 16:05:26 -0800 Subject: [PATCH 02/50] libxfs: adjust xfs_fsb_to_db to handle segmented rtblocks From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352751977.126362.6614323652955366394.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:05: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: 13898096 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 98C31A48 for ; Sat, 7 Dec 2024 00:05:42 +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=1733529942; cv=none; b=GwMhJ5M/9zeXt4+6hgz8iGqXxFsVQ5HcYofSebwNQ5dv/EYs+OOFZ3+BFcRdixUr/XwQOJtWRQmV1Orqy6eq+QHibdLgPTIE2vdoguerrd111xN2s91uSoFyI9KwE4B0qSRrL2pu87Ckliikupco6gASSMXJZ1i1SlnW1ED0irE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733529942; c=relaxed/simple; bh=3dgb28Utw0/FWT/oDuYycHjtljQ9GH+jOuv79VhUL1A=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=vGu/rGWQ1i+ONMx+62lXWECFvFPCU2aQix0fIyz5HgWitXB3KMdNup2DjoKjoK9sQy9ujefCshAO8dJEn2O/+FA4bh1xPVuZGR5R+G8gyZjVM/jG9yad8HbCuCvol3VGNN9w7+lzOlHQlzaTfal17fIuIatGODpC5AhLtLH9TDg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P86oMNKq; 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="P86oMNKq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FFB8C4CED1; Sat, 7 Dec 2024 00:05:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733529942; bh=3dgb28Utw0/FWT/oDuYycHjtljQ9GH+jOuv79VhUL1A=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=P86oMNKq7aNpiLhn+6psFWsEWwWmkc6JsEdIJdrVDIAXCKHcAHdb+jnF8TwrWjGLL 4MfzeJlcdAkVEsryKsBucflJ0JmePhSgev0PzcAG6TiUVmaoVtxqsZh9epMWjhBD7K dZ78T3s5bGhWZiZOAiO3j6gOJhvZLRxMwHa/DVn9ZukQHJq9WtEbxJfg2RNQ3aOqL2 BULHi3QA7Qq5K7jJnA9mAFutlwWavhW0vMnxt8FLRIzThmg5fFIGGWeNyu3+yxqGQX B3cry8ewisipdMwBEWRCj8wuBbeoc2tKpVmsYVPB1amPk4FL6SHc+upldMrMya69p/ /BlEt3BPVC0nQ== Date: Fri, 06 Dec 2024 16:05:42 -0800 Subject: [PATCH 03/50] xfs_repair,mkfs: port to libxfs_rt{bitmap,summary}_create From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352751992.126362.5121798366403344201.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 d7a88133eb78e9..99019e94bab285 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -552,14 +552,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 Sat Dec 7 00:05:57 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: 13898097 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 4ACE3196 for ; Sat, 7 Dec 2024 00:05:58 +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=1733529958; cv=none; b=lsbGRyddQlfqYOp6Q4wG560e+bMqZs8V19EUtJ4f9l0togkQOTyOtGSx7MBTbEqekrQB3W98C3qf9MP5a6bUiWoN910x3Kyg4Yodul4X4Sr81TUtEdWR94HnnzbzH3MZ+uvHXP0FfkF14rqX27obtxGnt96CUJhVHyNOECFh+Jk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733529958; c=relaxed/simple; bh=nQs3/+Fk9NspfYD88XUNK26MG7XYxgTXEL57VgCmTy4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t1mWUQvhGjqtDKwNvrfQqHciQ1jmRTE7mpaTClPUU9oOp9a4Qw5/l+TRDXu9Cd12SSCkOP323VbkdMVIQdr+ZGSJFJxfP7kT8NOY+F9OW69EtYbfsGof3/akPOwYeDKNX6l6jsSF5aqHimsAJyyUV9RtyeNbTeILXFHGeYMppFs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CJHRJYTN; 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="CJHRJYTN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2001FC4CED1; Sat, 7 Dec 2024 00:05:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733529958; bh=nQs3/+Fk9NspfYD88XUNK26MG7XYxgTXEL57VgCmTy4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=CJHRJYTNAMDkQ65/EQvQGaM9nkhzjP+AWIRI+aOct5nScgIBWr7z4ynBIChJa/OCO LCGTvxKOiG02Z0otJEBSjoWW6oYVjjM/w2DlqfcFtIl/f67x/seMmQyVIlD0151iMH +razDZGJQPkiaVZFitajAfcs3aOMgrLV0fIvEzNVEc9HKZbbhWJMGEnkIIFpjvfUd5 rZDriVuf23e41Mu82HQR6F1k7XpPkZlL/eYK3/IxNprKQ3Dh8mfUaSPiR38ZxEu9g+ qzZu+N7L2fsVuyLfmemWH50q+0nbmWoLxGjQSeK+zniT9Pej6SWW8nSTR86XqFlXa7 MrOCzDRnkEVtw== Date: Fri, 06 Dec 2024 16:05:57 -0800 Subject: [PATCH 04/50] libxfs: use correct rtx count to block count conversion From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752007.126362.11650470586267839011.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:06:13 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: 13898098 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 D581C10F4 for ; Sat, 7 Dec 2024 00:06:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733529973; cv=none; b=WHAE0nXsCm0mRusTwlIjguYwFF/V2ikGalYkcflSxYUcoIt+zsRAPLaqyTFqM0mj90BtbHlG4odtYTvrCHHkBgHScF3bnAYwvg0Rgsvw9yQRrfda0c6SNXG2B4ZG1H0SbtzDgbU0lzDx3/s/5ihStFCrHmSon/cb+lzMwmPhIhc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733529973; c=relaxed/simple; bh=D7xZdjc+uX6sqsgLbSgTSSgwxE0U9WSorXPT6rZpBoU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WGOsKUUV7A5iV+FsmBxNIHbcqvA1lzmO6WLc8eEoozr+btr22CoaWuNPiD9mpXkkWrUEnVBebS1Nq0RbX/tj3LTj9mx8LmlKHu1AZb9PT2Oy574jNGtVWX34NMZdo8qsaNNNmRwSXYue8WsdbaNs7eS4BCjz32hUQDLhJnT3d8E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AkL0h3LK; 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="AkL0h3LK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B382CC4CED1; Sat, 7 Dec 2024 00:06:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733529973; bh=D7xZdjc+uX6sqsgLbSgTSSgwxE0U9WSorXPT6rZpBoU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=AkL0h3LKumJW0MMMrjaYIyM4gVnYjjhj++nmBP0CBG372k0IpYhjITln1dNQucxpD RvsdCn9TvwcohMj9QzDoChXaWyVXRlSGPv11/r9ltVtJdP5sPm/d0uxWejDWPhsDiC iqLY4mMcI5KERvF5qh1iQpIlfJxVfzG5Bxhn4vHWvwc83RIar51LpNkYu8Dvk+4/f1 rMkHmFM313Arzdk/cyDyp9kYz3zfAWFMXJ107jptk3m8Scq32JBwzICs27lELznxsI nKiwHvj/ONPNIA+O25pMALhJ9yGHmqKzRqlsSztbfDRgzZK1EAT50UJjX74HWp9UaV 1LtFMedmXumoQ== Date: Fri, 06 Dec 2024 16:06:13 -0800 Subject: [PATCH 05/50] libfrog: scrub the realtime group superblock From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752022.126362.18323811506203138310.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:06:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898099 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 B285538B for ; Sat, 7 Dec 2024 00:06:29 +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=1733529989; cv=none; b=ZYIRFe7owvp5L9JrHGi/DVuBtzjne46zxP1Xb1VnFpy0rmeiXcbBuS+WRUYgfp7i527jjAM0RtISHuTKrBq17+4joahfWIMU+ZI6Z1Ddrhx9nh+2MY6q0tvxOB2llWYSWXijPF/Qwm3ldNGEd427yMm1SJ8BU5tD069I7vuJKAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733529989; c=relaxed/simple; bh=rOVSsT4xQGezcJFxNDr9TZDUFzC54kDcvThlxQJ+EZM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=D6mLgK/3EJ7vfqBfgl7GZSsBovcCrrhtVD0JFJbMG6Qv9oPyFg4fp1DVEIiCSt4AaPXEG5fQgLTNdlJY2g0gjWQ0jB33fTaALiF7Bjye+nBMuH6URHeBXEaz94K9c2fEOuIk66+YwWGP8QTF4ETwJqvZrL6PW/wS+VuR154xW54= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BZDmU/Zc; 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="BZDmU/Zc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 480F2C4CED1; Sat, 7 Dec 2024 00:06:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733529989; bh=rOVSsT4xQGezcJFxNDr9TZDUFzC54kDcvThlxQJ+EZM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=BZDmU/Zc9cAV3Zvok2UV9cRCy91DVyycVaWh8HqLaNkpLvzE0YmJ04IK/OGeVYgpQ zo+IDucmrTe3PSlCdfbDl0zWl2yJVoiGUUBq+5m/I8DsfTFE5sJgZpGTbi2W37LMo5 v50726kDNi6DOXVFuhEbNi6G+4BmxCtqOVzWXkxO00wNdKVx21rm3zhWzLimHHBHl9 WwBUdZ+khdTtiFvkI7pXBRcHAeq1I+qO2NTJXBPJGK47UtpibMEPG07awB1gVuWlcb AKD02W3VGXf2NMtyrXiv3KZQZ0BKZKDVVVu0++dNHQYVcQj3PJk+0Ys9x1i5wuTLts ZosfXDfeP3O2w== Date: Fri, 06 Dec 2024 16:06:28 -0800 Subject: [PATCH 06/50] man: document the rt group geometry ioctl From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752037.126362.17032439118208843597.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:06:44 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: 13898100 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 459C7360 for ; Sat, 7 Dec 2024 00:06:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530005; cv=none; b=Bd8cX3YsjJBxUaHmNd6ahL5CGoow0EyaR8DxgeDyxtC2oZCzLBDb5x3v7BmfFkL3xB6vxg+BrQ+wdn8a0k3ZjJGVAblE6/N4zFq5XuWD0EE5PO6wCm7uuQNKhOh4gk0KFyGz0O6voFLfGxm4pv8JzPQ59DaBdTqMN1nUGwFSUQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530005; c=relaxed/simple; bh=dtAd+vCSkaZi6JsIJ6GyhXMlWW/1/QFfFH63EbiwpEw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bVu4ezlLTKSZXMMwOqTf2fwcro43MvHg/6/426Ko1kaSK0rzDrJz31syTYTXVv4pU18Fg0Zmj2qpMWyj+QvttyjvLAHV9GglDYTf3YO31muAc8WxvXc7bjS4i9PqDM5BGzEYdD7DTiVOXGmAfTktp5Liy0gsK0sQJ0CjWedcc2A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KfkTQrc7; 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="KfkTQrc7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1FB2C4CED1; Sat, 7 Dec 2024 00:06:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530004; bh=dtAd+vCSkaZi6JsIJ6GyhXMlWW/1/QFfFH63EbiwpEw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=KfkTQrc7UXRiUfZJE1E3xZtTArFcdNZF8iBEL3SIh6ZgqheTqjmFMPgn8keq2bsZp VnkPEyuAYlPWPF5uxSBfAkV/i7dPF1UOgqLmxeB5Nfz9+i/B5TCxFPiKP2+eUOhlBj ncLyttePKiP8XcM9FCDOoM/3c3G9ayPY4yX7Dxxz32rDtcKryOBT0Pzh+hdAQD65Bc 5XfysNwmacwiRpNhq4i3eaNKGLJSzoNL7emZU+V5CosigCgtmLMUOp3dGGA4uy4hDa U0NwuXmgaOP3O/Qjk5+hh/CIS4MwewH2IkJjKT9kRqX2Yr1npa1+cJVDgbX26fe0Ka YMfNiUxDpv7+A== Date: Fri, 06 Dec 2024 16:06:44 -0800 Subject: [PATCH 07/50] libxfs: port userspace deferred log item to handle rtgroups From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752052.126362.12924732901828504972.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:07:00 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: 13898101 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 98451139B for ; Sat, 7 Dec 2024 00:07:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530020; cv=none; b=EVwen4cu6ru0pPAduzl+q+hEB1z/AFB8+6JgOYWJMpWduA6wQf7w2d3SxsD9thTqE6Wb/k2MVvJFZHcdbBNSxGjkmSVGHX8ok7Vq4p0e1SiCCt4P+bNr8243bwt38ZztuGavuXIcqUMS54TajYII+6WVop3y2PPeaG3Jl+6B3lw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530020; c=relaxed/simple; bh=loh2sxhYhkqS8DfjBDKgW5WMuAWIWpkCKAh271kW428=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=icmD6veOknuB2ngB7B0/EIW5u2lpO/CrdzCR+yT2+cBq/35LZiZpdMapfcRMPUTM0HPDUc8rGXcEdlfnHfzfO/KNiygC4RL1tw+fYqPYonidfYQktrx2pv7tKeQJiUAtHAUC7a/au6ONpOnMIESTBuvY6W2Veu+Y4fVoextSWDI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f+EQ9gTb; 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="f+EQ9gTb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75A36C4CED1; Sat, 7 Dec 2024 00:07:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530020; bh=loh2sxhYhkqS8DfjBDKgW5WMuAWIWpkCKAh271kW428=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=f+EQ9gTb69poEark0PgTgB+59vZAjMPBPjERXMc0unIWjE36pWyp14zjpZO+fnYsg E0xxnDhQLxxhbp70ZimVh4Oxr/XJoXrshstThmb6Xn0HR4pK2c5wCOTyLzKlQstSQL PIcwCbzQNQQg0CjcIQw3pqiNUbU2aEEhgO9xUoePvjRF0SmJ9IPK37Rfe96Hue18Vm BBYWGNU26FuTQjt/VuViolSvwEjLWkXuHuK8WUPN6+SNorOJpJpH3YfGVFpy5fafPb nG3Jti/ea3YRDcqtC2YYzO7DDNrBlf62cRD9avkhKBpsC9K2Uhf6R9E+lT1TcOYrW5 +NAt8oqI4Y5AQ== Date: Fri, 06 Dec 2024 16:07:00 -0800 Subject: [PATCH 08/50] libxfs: implement some sanity checking for enormous rgcount From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752068.126362.5584212124575478710.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:07:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898102 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 79385196 for ; Sat, 7 Dec 2024 00:07:16 +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=1733530036; cv=none; b=qJAUfOh20u+H4ifcGUHF1woU8EJ7zjEgitS7dkbmrUc+ON8GpSSSKA7lG3OFrAXq23fTNXXs3iyU9baNa2Bk966cqXySxNNc9JHt1BUpuwS8Xn8CeVBcivzc3YH+ZE/z6tnoDuwwdBc2Oq3EykqKO3Yi3tSkdlWsK7/TQ+IOYzk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530036; c=relaxed/simple; bh=PWww1QqPQMO8KJnh9zqSLHVKmDGmu8K/1XOFTWKZLpM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DyPuS0+lxbqCRD0bW+yd8kuzjjCyQwH8AiTG2kAr/dphhyquNTCokLHWutUNAxAnVRemQ6WCHndh7nIGqTyV+Gx81Sj7gRSIBODn+aB1xQamSt9DQF2cSqnJzAY9NKLuRoznGCyLeD6rT4gkz4MD2hfFOtdg5pWJ/sbp8lk/imQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oe9XS3gZ; 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="oe9XS3gZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E4BDC4CED1; Sat, 7 Dec 2024 00:07:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530036; bh=PWww1QqPQMO8KJnh9zqSLHVKmDGmu8K/1XOFTWKZLpM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=oe9XS3gZrZxOghhbz0ylaTYMxiqd07s87K+4rhOqZQfU5BmaeptZNqecWPRXfptaP FkNmQm5JUJB7cM1HtmuPkV1sbwrxrCoeER7cHhhXoTqlMhMGnKktAhtGzYaOclkLfH jP+OmkagRvjynke/GXfOTKzkGfScwGHC7cJJcNTs3z4P1yyAoAPvDCLDH1owtPTjrO c95XztJQK8LXX8IiHGXnjdHf/IjRggGM73pisVisTW/CRq/mGAXRHJON+LF55gyRoM 32FP4oROjM+G1G0tR3tynIkWyH+SX9vHYsPkRdqz0tP35hDGp+V4KUf2ivZeD1E7NB 2X4AGB03pxV9Q== Date: Fri, 06 Dec 2024 16:07:15 -0800 Subject: [PATCH 09/50] libfrog: support scrubbing rtgroup metadata paths From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752083.126362.5682773152874800985.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:07:31 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: 13898103 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 C7DC110F4 for ; Sat, 7 Dec 2024 00:07:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530051; cv=none; b=NJj0SFY46aky4whE3JR2zBwWFG0/C7VaJHQFEaB8zs2iGgstBGmqc9t4JJh1mNYWoZl/Xuz18IVun5VvA2dIg/IbgatJ87reDT1cd+sdaGIDYGMryDdcC9QB2yOBkeUaCE8alHc5mZZKhF3rkBxY2+x/RWfmK2LtDic6kMqfVOA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530051; c=relaxed/simple; bh=//rDEdmrZscPpIKQa/vrBI9q4K9vJ16StolQFg8vxtE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cEbhZDFQ0PE7d/oaiPX0HuBXNwj7beMqhumSoeZpp7XuCZ+eXeDnPqdkqD2c+tv1QKOB+ypWbC9vN42qOKLKDgHbY0KCj8Ohb7bvMhvB96mFGSWZuXUjkCjGC+UdG1UKpucJBNGXGDzYclagbCV4R/BVAVe73mHbzXSnri822KM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JAaSaQFa; 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="JAaSaQFa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2257C4CED1; Sat, 7 Dec 2024 00:07:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530051; bh=//rDEdmrZscPpIKQa/vrBI9q4K9vJ16StolQFg8vxtE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=JAaSaQFa/4RmB5x/ltYL+ZPPl6kE941PuJhCUA912jEwKqfhWyC8056p/L6odh9HS MEBVvgzox85J4q1TVFMXsBbkg7KAiRlWJrGmVxRD2xUzwQrra2K2ejUyM2dZVG+BIf 1KlDppg+rJyi9eZ0gB+M7olyNzt7OtFy4QaJ2QzGWDL1rHLUol8z5//Z4Lstqi+1hK D0TRg8Fvsv9n7BgZJsmSJjKZkzXRynwUQVcb1f7dyH8XBfvTkoRByPRv9NSHQxprW7 R/1E+badJlPuK7SwG9hnVUOIl2mszsffzyqSS0V8eXGXQYn3+pHg2HiRfOBb7dqHQM onlGlbMlq7JXw== Date: Fri, 06 Dec 2024 16:07:31 -0800 Subject: [PATCH 10/50] libfrog: report rt groups in output From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752098.126362.1262402405604422083.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:07:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898104 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 6A2FD17E0 for ; Sat, 7 Dec 2024 00:07:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530067; cv=none; b=kRUMmVhcgz37NIy0tGeoBKwLxgDEz+yWNWPBkqggG5x2ndnSugdMJHefqDmiqXUHeZ85ZehBUvUlbbzMU3lFo+YM1SsDj8ZVMntS9/vJYN1iqnv9beLlOGlsckzyxIV91IhRLPUQ94bgwX8M3/apkUT+CcnX/QT96ThWl3lSH4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530067; c=relaxed/simple; bh=HDf3DlhHdAG37vvaPn5SYzT28qN+bWx7IhJ9dKaY++E=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hmIxADhKfgyj/l9p5wyvxhDc7xBuUdfGvV4vs0Ug+XbMwNErFkJk6xMdurrsYgZ2VF8P3U352KFnfvCsg8b228n6TapXEvYLEwCiP7ohZJVn2dHWrWkdnJh9N84HIjCdbuP9Mt/FBPc3uXCGOReSHhw4hTkqQNQwrJcV/3cAd5U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rfpJMqHl; 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="rfpJMqHl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FEDAC4CED1; Sat, 7 Dec 2024 00:07:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530067; bh=HDf3DlhHdAG37vvaPn5SYzT28qN+bWx7IhJ9dKaY++E=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=rfpJMqHl4mD+47uwKadncY8nHxULYK1DDxO6LMtqoINwSGcXeXf8SOPR7/ZNOdVXQ v01I3AXTnui723E1CsagLJliq8bX2u8NXAKlBETgob6qRhFynbKuTVoV3FKaRdN7F6 lT87bkhqNhetRJVpuI4x9f9Y+2VF2vcPT1R/ymK2Ck9MJarRSrcLUAS1OjbRr0nWgD vzPvqJOxMYhP1vHQA5CQVEVYefo7UMiSvg/wwTdmTnZMgmwVicxYZCXy+aaoEk7zzk 8CYhciKnZKVdyacs3scjReQibFW6Eq/GEFpYCwNio5N/RHF50BDhq4QgBjL9Ky3mO0 dKeD/cdC5cmrQ== Date: Fri, 06 Dec 2024 16:07:46 -0800 Subject: [PATCH 11/50] libfrog: add bitmap_clear From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752113.126362.10879746688196189472.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 --- 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 Sat Dec 7 00:08:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898105 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 0D59C2563 for ; Sat, 7 Dec 2024 00:08:03 +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=1733530083; cv=none; b=lnA2LtLk677I8JKNV4QOdeXyOE3CGDKQiWJMebT5wFJcXEIc2Emw3Nn8wNm/hWcWB88IrEn1sUxH5fO8RXgBX/cenaNqmGCxwQJk1ZIuomcmrGEuULoA9jaXejcSX75FT5T9XOUzbb7EPfzJmhFrS6GhRSPkZDrNdiFYQV9e3pQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530083; c=relaxed/simple; bh=0CblLwD0mlTVLE76IFfccTMkQvySm5NxZDHW1y7xH6o=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AY8Mv7zoWJC2n2RGLwQnFDTxMyE+b8WLFOLHE+pbdIipcheG+CHFZDZc2Wg4vuVnAeODjnyue5uHFGdTPVxeBsaZbJxyBe5v0twMP51M2JWcrrsTQw3Shl8h9sFvNQfD0PRovoAtn3vLWHg7hcsXukr3i1fYqerm01uAo8LRV9Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ENQtvZVq; 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="ENQtvZVq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6F45C4CED1; Sat, 7 Dec 2024 00:08:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530082; bh=0CblLwD0mlTVLE76IFfccTMkQvySm5NxZDHW1y7xH6o=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ENQtvZVqffvjqcDzlJ2joBf4V/suPDNadRGJju25ibBo5YWvDrNY0aBOBgO4eid4i YSsbl7c7etn1yb3IUuvAMwjUZMVNwzpFLtgUBLiDGLy5LfA4DEoSaPR7xmQHEiFvbC zNPu9+a6yUAsrjdBzeXHQ5VBIdyqMGDlgLw88b3bELy5A3XDqE6MZqoSJZMLYz1mOk SsyQPz7y8Lx6dqZJRK7wC37hQ4Vzr+50sk4R3OG/21PECnomcZ6bb1/CRRG9FYGzoY myMZU6P73EQIxbeIm8BnFu1rAeWgS0zQkuK9ov57viy1scn5OX1qVkkXhbdD2RZhAP EvTVRwjaKQYKw== Date: Fri, 06 Dec 2024 16:08:02 -0800 Subject: [PATCH 12/50] xfs_logprint: report realtime EFIs From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752129.126362.2344806594434228770.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:08:18 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: 13898106 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 9AB0228E8 for ; Sat, 7 Dec 2024 00:08: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=1733530098; cv=none; b=OHOmS/0WII8mQHdP/etmCS9EN2ETSlqqLed2Mzlwsbw5unHC1nBWz526UGS7u3HY2qtos0xPbbW2hoTLnW9TmH2P2Tg35z2QFROFlNQ+a27WiCn/n7LdHksIcZG325B4XcL/OlCivbx+ZiitvprBL93EInF8DJjNSZ+ZsGosDuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530098; c=relaxed/simple; bh=76nf2bUGEfcsgUoObG387U47Fq3tYQ4DUSKCwkubYYg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t8NMD0jDFSurBv3rYqa6UqYtoJWccgBNEiWymvfA8/TWRZmIw/463relsNfSWk5JlhYH5fOP6Mn9iuVEADAlOgjmFkvyvD6XkE2SbCRGo/TKXMWNJzudb+qNzhhKTN57jg5rWL96w/F23+XsewJc+2D9z6xrzXbtjetAWVpllmI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O+7o8CcH; 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="O+7o8CcH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77596C4CED1; Sat, 7 Dec 2024 00:08:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530098; bh=76nf2bUGEfcsgUoObG387U47Fq3tYQ4DUSKCwkubYYg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=O+7o8CcHxu16cPWQE92CQpWetkXlSxQm1uZD11mrDSJ/y8UW+wmCwt1J1P6EsV+fR L61wOkEMnpHzN+bjIK8+BdB8XcceKD9Bx03Cs8FLoz83U78vRkVokhAkSDXk+fyW5N J3r/0m4FLiSsf9lBW41Sv6AEznpc+Xi2VGT2ozMCfJUgUkjqdfiIdhvkynMIMPoG+9 fKokFkn5Z8BLlp7if1RqHR9Pk1v9nOo5+8WHViDYDW5hdMf7712a/7/xLRVUnwbchQ M4CFXezW9cvYOUleHSbo7v6kiyA/utZKfr75xVSfogHfAsVtc+Ovp5HJhr9mIQaMo2 sDHaOlAMQ3SKw== Date: Fri, 06 Dec 2024 16:08:18 -0800 Subject: [PATCH 13/50] xfs_repair: adjust rtbitmap/rtsummary word updates to handle big endian values From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752144.126362.17082355862911716811.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:08: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: 13898107 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 8F7832CA6 for ; Sat, 7 Dec 2024 00:08:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530114; cv=none; b=rGQVUVM+OGk7zCMvqi9VqKzMO7oVTovf8eCRDjP3M8cq8sCjUULz9261oL0vTxboz88m6yvRa2yQly1OHRrPmnvIwTC4DUyoxzRwYyOLvISZpCOuMRLl0bBJBYoIs2c6t4XmZoNwvL/m+w+un3Pd5jDaxAz7YAI6WcJBLRrzpbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530114; c=relaxed/simple; bh=bUCTMAOTkS4RCEOnyQsrsP0UZCi0E+CCkOZIJYRKrn0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Cy581YusOrklJG1xOQjUq/7Bl3qgOQQu5Hpu6AC0k0dludQEAybbnQ1o1ZSPl5dc/pY1RLUe6gfF5tSOwqhEuP2dWe5BYpbJRbjtd9EKmc8gKVtWrN5cbT+Z5iJhER8hmipkVjG4Z8HwOjg2s4OTFxITSD3Zw/gpuAHIV1w9eb4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=T5EyelGn; 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="T5EyelGn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19C52C4CED1; Sat, 7 Dec 2024 00:08:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530114; bh=bUCTMAOTkS4RCEOnyQsrsP0UZCi0E+CCkOZIJYRKrn0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=T5EyelGnW8klhAVmIVzzzuw9+WcWYnFL9k8hHQ5bFRUKqwmfFM35WA08wLLMtr6Fo anG1HWPUlTqhfI2LrFrEnvvRfC8ZENXVYRESJbx843q1nZHRqiX3nSWTreujslPVTB Ea6UUaRSDxUnoO5ovzzBMLR6P/V+7DhFBZVPFuJSTTciip0wGGFa0OYzfntqBHUqtX 1aKh42o96Vm0GIoJiRiV06qvF8DUxwRktmUg0p7d47bfE1f9umpgdiPrSAyBf28FhE LW2a5WtJaH91+A4Q/TZo0IEeI3gJOcDjb+acgD++wmvsNqtCVSxUbvfEKKUvvlo9gO pdG3R9M07qR3g== Date: Fri, 06 Dec 2024 16:08:33 -0800 Subject: [PATCH 14/50] xfs_repair: refactor phase4 From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752159.126362.17278748387791327249.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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" --- 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 Sat Dec 7 00:08:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898108 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 D6D5B322B for ; Sat, 7 Dec 2024 00:08: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=1733530129; cv=none; b=EIESrYKoBdYG6yMxZeu9poUcJLZ6g6/nvQSEyzil8eNtrYGy1uTuFjCsTOEliBXDZOFK1A43sr68hmhdsEn9RXrP50fqAekCuabKv4CXhPkFBvFgUaxiHwTEpSSCJRRaM6Ggl/QMaESCBTC9BlYHW6VYvIKgv+EeXqtOtBykXGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530129; c=relaxed/simple; bh=9Ra5H7qjZswbLEEnYtKn42y4Pg7vQEfkXkue5QLbfWo=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PCfPSrP78ZyY8QXwKLVJNxrMsY2ThpPXnDju3OzApuG9ojDBUNyOcJtwQcsQAZjU7z3d6pwc0BCHUR+82DB+VsxLAKEPyCsdutrIVKVFayG/swDWnxErMqwiB9th5S3MDUTnZYA/T/JAJnAc2aOQ9iMDayFWh+gFyu1zihKixKY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZQ+7fyvm; 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="ZQ+7fyvm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1728C4CED1; Sat, 7 Dec 2024 00:08:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530129; bh=9Ra5H7qjZswbLEEnYtKn42y4Pg7vQEfkXkue5QLbfWo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ZQ+7fyvmopWGe9PU1s6lIBZxUsuPMtbOGGdK9R6eiy2YyHAL+jQRvacCjKJPRiAcV /91y1WU4pmu9bL+OAjiIIGldsOgABm/7/6IKmpXXWBu94r3h6KnVauW1heeWg8pASi QWYQSYKS/IMMpyB4C0mHMsWDwiWW1mFe6eEnvUCWaTJbyI7/1q0jeETMnz/Y4LigkZ Ey3wAMUYvCISPgmm4SzzNIGxaG+/kYkSBPxl8cm0yMxpM9jCmsq8+Y8Vm9jB1nedgo UF96SV4a6TMRtASgOmK5HDixGPEuJRUq644ZQVQ0DgAY0VoxwSYbNBiUu9QmHi5CKn RTcQytPuZ+Gcw== Date: Fri, 06 Dec 2024 16:08:49 -0800 Subject: [PATCH 15/50] xfs_repair: refactor offsetof+sizeof to offsetofend From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752174.126362.1527723436037046190.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:09: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: 13898109 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 7CC0A3FD4 for ; Sat, 7 Dec 2024 00:09:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530145; cv=none; b=gS1O/52JFM9BkqmiR97nDRYPfqLtmKP5m3qv7a1XLGxBUzgsE8IgpeHHOSQsQl9Z9bYG2cTRffRnIO0dBZyGVkZseIP2y8KOeOLO0optOGx1m4lrRP5g3m0TpD7d1fUjrw53ABipiGnSWlj3S4d1ZtvdzAWvjTuXfWr8wEVAlas= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530145; c=relaxed/simple; bh=xFFtyiCDL3jR2vtj880L8EDoCKFIT2pjhV4fOKdM7KI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AztBDOnNZR5Gbcfqs6yk8Qit106AcLywHZwnYlP3fwY9jYmIsVdOSRSK4HKICr692Nsj2PG7Z97EMZZ29OR0evRLBUDw71JUZHsEgywdmqrXSk1TJhwOSBxPZRSmF+FcB2dm55Uw/Tagsee3nEVw6Pvi+sinSpEDXJHAVZpD+t8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jlC2QrN5; 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="jlC2QrN5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53157C4CED1; Sat, 7 Dec 2024 00:09:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530145; bh=xFFtyiCDL3jR2vtj880L8EDoCKFIT2pjhV4fOKdM7KI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=jlC2QrN5ShnKxLn+5v/o1FoYOaFDTg9gjOCk98DC8ubGGEI0RbPy+Vtf8kM/PsgLW A2BZLm9Hot067hI6oQ76BM43ptNeG1jWraOGjHi5IlHuVh/RIeZXb/a7nGuUyJp+6d NJ8gpTqaOUtqiG2SmaTLtQoFjlECKulK7N3yTG0Qmbw5H5uBru5k6JDVdODEyuc6jE +InvpCVbQJIhC1Dn65u/S8F5XGm7BMNwvMBnnSDAhE5G54UH9nIH1+1H9esL9lbZ+1 CophhlctTHGIi0Dy/n5fIDt5Oo55Q6m4PAx1WRJZ8bTaZwI9hjHKvI5z86a0OtTKdy tlp+2+lL51E/g== Date: Fri, 06 Dec 2024 16:09:04 -0800 Subject: [PATCH 16/50] xfs_repair: improve rtbitmap discrepancy reporting From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752189.126362.11084949952818788504.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:09:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898110 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 17A7E4A07 for ; Sat, 7 Dec 2024 00:09:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530161; cv=none; b=Fw7idVtMecOG3B+uN0z1M6lLwwxdYg4mEIECxqVj8C1XY35f2RviatezL65OSYbcNoBJ/Uc6KzYtN16x8G+Kuys2EeLIqmfdl9+YTlx2TcM1Nr98MmJU/TgeDW36u2VEPOgBJpYLHzsCHCysf1BKzVNoLQVHflw0YpLCYHDv3j4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530161; c=relaxed/simple; bh=7PwPanc+bm8mvr+DLKTiyz6ogTCDlNfZrqgRbaDDSNg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=upPt2cot5j2sFagaOd5a6ITl8CNxHPV8hpPSXlUyZ/6tnvLKkKx1vDgv2Ffm+nhMVJG1LuuzdKlFPKrSR1Aiv5uQvi/gNlwfkOaCEYNDFbrlsgp890cD7aXk3weLTpLSxq7vtYzguwVv4IiolCxUFYbX2ITkYQMfIOzS/azmCc0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nRayKfwx; 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="nRayKfwx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E822DC4CED2; Sat, 7 Dec 2024 00:09:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530161; bh=7PwPanc+bm8mvr+DLKTiyz6ogTCDlNfZrqgRbaDDSNg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=nRayKfwxbeiD6WMGpdkeo+C4trPCI8Lz18UIyPNjRsjEfgSk6oSEUOWoubdJqsk5k FzHGq8DXWYY2xMpzs9Mzyt1ixMB4cuIFSU5YZJWHpkuHCSgzgwbjCyS+QUWBoip/K9 G3PCkQwyjadPZaT51lnNBLlkWQRKfIAyH1m1VtRFUzAay3juETLOupRfPg99WG/Hl3 D/Be2kRv+gMXpC4ZT755gDhKkCCIadU51gwsx3AOwh+pNTKQuwnFL3o0WTWrYV/in4 cJTBT0GY5drGcKTqGxmlb1t+eHmWHdeRfO5GBRA4Cn3lRlpzX5yrvukILo3O4bWr+t 0s8FBr3jTvGOw== Date: Fri, 06 Dec 2024 16:09:20 -0800 Subject: [PATCH 17/50] xfs_repair: simplify rt_lock handling From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752205.126362.16367157719256710665.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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" --- 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 Sat Dec 7 00:09:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898111 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 B05E24C79 for ; Sat, 7 Dec 2024 00:09: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=1733530176; cv=none; b=Qgs/vHnnLGLIIfJhFIX1YrFt+wkST7MJcWtkMWR0RA+DryHsv3vNwYSpQF9Tt3e4dTHxb6pjV4yA0Je7mk/dYO9pn4E+LJQooLjBrJO7IL+IKqdv3tBDQKL9r4S1XXFIQCHn9hXx6w/uK/6gd9+8F59Zzy8J7Xfh1ZfbsJcCOy8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530176; c=relaxed/simple; bh=yefrW0F6KuPKRAJe9NJjC1qB9gg7ZO1pQrWi2a6vaDI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sH7KoFMkbbgeXKxXXbaO5fa9sxeA0Yr5//u4uzmF2gDusZ4YWT7PBBLR27TLSIYtcquvzlKZ3nGkHs+RYsqCHc10ePqSm47wDxWXmVwhy4HktRTeWrObN1geQ1SnHdTywmZNNrnvbZgeys3wjBVrU0vN9+9C+M6HZX1/s/oXl00= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lNCpN6O+; 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="lNCpN6O+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83F4FC4CED1; Sat, 7 Dec 2024 00:09:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530176; bh=yefrW0F6KuPKRAJe9NJjC1qB9gg7ZO1pQrWi2a6vaDI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=lNCpN6O+SU2mpremNISjJfl4tkqlQFPP0EdXUYLikD8jG5uHietKYNpBkDB22crq2 Vw69SlbixZDa+iasIHRjEgDkIEdJH89FdGowo94snqJ/TlEpxO1O3VSlmK0mnhjuOL lKfdDY9Go2mtvElp8JIk9t28uzuGYzQ9swBL3S7Flitm8C8/7mjYASldqgMOYVE3mq frD4oOmEAQG0bENtosn191LeBIjB2gixwquRcOi0HYL+khX/SThboK+kj1cxBzu40X cC3J4VWXTYfl8hyjje+i3qB1KeHw5mkgfdJELrpD5Zb2LNxN5MgUBErvCQURONVWtX VthPEOXTg+C+Q== Date: Fri, 06 Dec 2024 16:09:36 -0800 Subject: [PATCH 18/50] xfs_repair: add a real per-AG bitmap abstraction From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752220.126362.2136345090500961.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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" --- 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 Sat Dec 7 00:09: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: 13898112 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 5D8777482 for ; Sat, 7 Dec 2024 00:09:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530192; cv=none; b=IOKqd1vMaLBGB599qHr/1AITXpR25f/719GrHn2i2w6txU0XiyMU06Ul8PIdaEeQkPphnuV8NcyNJlOlfcffyL+OSEeGy2ZC9udkO1593/IP9aAzdtvzJZqZI+pYQ5sRdgE9bGrJAwr0hscuF5TolvAy9WLM2oI4KuiQ+mNAEzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530192; c=relaxed/simple; bh=H7h5rKCoFiw/enWZyAUbbHUdzaIZL3Li5k/KJHoDoQM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lz3zBXIutADiiSrvhWekFcla1yiAZh6+S5egkjtGCtnP40f4eEIJHj+rAkkGWWIZB1W/WLxILZP/R19EoNN/hVyGZg8amgzlqKECprBzQ9anxO2KL2xcrW2FGjAaioZkI15sHmJjdvrv4WgKfXRonwBrraxOeUu1KBliEOXWA/E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xv7IPcIX; 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="Xv7IPcIX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CE24C4CED1; Sat, 7 Dec 2024 00:09:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530192; bh=H7h5rKCoFiw/enWZyAUbbHUdzaIZL3Li5k/KJHoDoQM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Xv7IPcIX6aH0Mf7eaqYp4IOoFL27aKMdYPiL99/dqqMb+kk5oMa3P2v7YKykIsG0y r1xOV+3TT6QZEzSVvGHohjVQwdUN0ocFFvkq2dKIl5q1VdQM1qQa6/eQ1fyUb0b/ml nZtbwx6MzbXUK76yZ6w8dY5e9ZdkEC0IUgbiy63admF41Vp4EHVnQ/0dgIcL9rIzSt lUD5WFsa/JZ3BlHCD9I+h7KSpPF1lU7cj/0pD+bvVPfIZekfV6FZMXKcvR3qgszUBq X+4t1GX1KwhMmpnsMrV4z+kduRoAyWrMV8/PHubz2pDc/gULEspJFY2NTWi1xit9nd MRDRXbcxsa3yA== Date: Fri, 06 Dec 2024 16:09:51 -0800 Subject: [PATCH 19/50] xfs_repair: support realtime groups From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752235.126362.14143467181782796888.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 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. Note this is still a bit hacky at the moment by just going beyond the AG arrays and not fully supporting the unknown state for RT allocation yet. The next patch will clean this up. All this should be fixable. Large parts of the code are based on patches from Darrick J. Wong. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: "Darrick J. Wong" --- libxfs/libxfs_api_defs.h | 1 repair/agheader.c | 8 - repair/agheader.h | 10 + repair/dinode.c | 102 ++++++++---- repair/dir2.c | 13 + repair/incore.c | 22 ++- repair/incore.h | 2 repair/incore_ext.c | 6 - repair/phase2.c | 49 +++--- repair/phase4.c | 13 + repair/phase6.c | 172 +++++++++++++++++++- repair/rt.c | 404 ++++++++++++++++++++++++++++++++++++++-------- repair/rt.h | 20 ++ repair/sb.c | 41 +++++ repair/xfs_repair.c | 15 +- 15 files changed, 733 insertions(+), 145 deletions(-) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 50da547f8f21d4..980250d58164ab 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 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/dinode.c b/repair/dinode.c index 916aadc782248f..73a70ab5116c9f 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; @@ -532,12 +549,21 @@ _("Fatal error: inode %" PRIu64 " - blkmap_set_ext(): %s\n" } /* - * Profiling shows that the following loop takes the - * most time in all of xfs_repair. + * XXX: For rtgroup enabled file systems we treat the RTGs as + * basically another set of AGs tacked on at the end, but + * otherwise reuse all the existing code. That's why we'll + * see odd "agno" value here. */ - 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 = mp->m_sb.sb_agcount + + 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); @@ -545,12 +571,23 @@ _("Fatal error: inode %" PRIu64 " - blkmap_set_ext(): %s\n" lock_ag(locked_agno); } + /* + * 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); 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,8 +661,8 @@ _("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); switch (state) { @@ -1588,7 +1625,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 +1675,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 +1699,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 +2960,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 +2997,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..bab9b74bf922c8 100644 --- a/repair/incore.c +++ b/repair/incore.c @@ -254,7 +254,8 @@ free_rt_bmap(xfs_mount_t *mp) void reset_bmaps(xfs_mount_t *mp) { - xfs_agnumber_t agno; + unsigned int nr_groups = mp->m_sb.sb_agcount + mp->m_sb.sb_rgcount; + unsigned int agno; xfs_agblock_t ag_size; int ag_hdr_block; @@ -287,6 +288,25 @@ reset_bmaps(xfs_mount_t *mp) btree_insert(bmap, ag_size, &states[XR_E_BAD_STATE]); } + for ( ; agno < nr_groups; agno++) { + struct btree_root *bmap = ag_bmaps[agno].root; + uint64_t rblocks; + + btree_clear(bmap); + if (agno == mp->m_sb.sb_agcount && 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, + xfs_rtgroup_extents(mp, + (agno - mp->m_sb.sb_agcount))); + btree_insert(bmap, rblocks, &states[XR_E_BAD_STATE]); + } + 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), diff --git a/repair/incore.h b/repair/incore.h index 8385043580637f..ea55c25087dc1a 100644 --- a/repair/incore.h +++ b/repair/incore.h @@ -698,6 +698,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..a31ef066ef356c 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) { + xfs_agnumber_t agcount = mp->m_sb.sb_agcount + mp->m_sb.sb_rgcount; int i; - xfs_agnumber_t agcount = mp->m_sb.sb_agcount; pthread_mutex_init(&rt_ext_tree_lock, NULL); @@ -779,9 +778,10 @@ incore_ext_init(xfs_mount_t *mp) void incore_ext_teardown(xfs_mount_t *mp) { + xfs_agnumber_t agcount = mp->m_sb.sb_agcount + mp->m_sb.sb_rgcount; xfs_agnumber_t i; - for (i = 0; i < mp->m_sb.sb_agcount; i++) { + for (i = 0; i < agcount; i++) { btree_destroy(dup_extent_trees[i]); free(extent_bno_ptrs[i]); free(extent_bcnt_ptrs[i]); diff --git a/repair/phase2.c b/repair/phase2.c index 476a1c74db8c8d..d2f7f544d0e579 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)); @@ -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..e93178465991c2 100644 --- a/repair/phase4.c +++ b/repair/phase4.c @@ -395,7 +395,18 @@ phase4(xfs_mount_t *mp) } 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, + xfs_rtgroup_extents(mp, i)); + process_dup_extents(mp->m_sb.sb_agcount + i, 0, + rblocks); + } + } else { + process_dup_rt_extents(mp); + } /* * initialize bitmaps for all AGs diff --git a/repair/phase6.c b/repair/phase6.c index 99019e94bab285..fa4eeb08265f0c 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -570,6 +570,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( @@ -634,6 +750,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) @@ -3063,8 +3181,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; @@ -3245,6 +3365,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) { @@ -3293,7 +3456,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..f034e925965f75 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,13 @@ 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 idx = mp->m_sb.sb_agcount + rtg_rgno(rtg); unsigned int bitsperblock = mp->m_blockwsize << XFS_NBWORDLOG; xfs_rtxnum_t extno = 0; @@ -63,15 +70,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 +88,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_bmap_ext here and generate multiple bitmap + * entries per lookup. + */ + if (xfs_has_rtgroups(mp)) + state = get_bmap(idx, + extno * mp->m_sb.sb_rextsize); + else + state = get_rtbmap(extno); + if (state == XR_E_FREE) { sb_frextents++; bits |= freebit; @@ -104,11 +123,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 +142,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 +172,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 +192,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 +205,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 +236,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 +255,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 +361,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 +383,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/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 Sat Dec 7 00:10:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898113 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 019928F49 for ; Sat, 7 Dec 2024 00:10: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=1733530208; cv=none; b=de7BSQCsTb/auOpx8r00vQVJo6WR/m/OY78rfwB5lTxTcx6I1cKNalCRwjP+kQBnPdoGasHWadUf4rzxtNgBTYnBY1nYqHQ+1NlVApph5BZL9t3V79Ix45qCpHIup9ZVi8Oua+qKXUHW2BRWxavGayrlYU1SQGZiF2wnjvHBe5Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530208; c=relaxed/simple; bh=Os2VDm7T2HaClAOyw5Qu+qgRH8oZSj/aikGBRuX7uRk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=U7ufIXzAKp1ry+pDKKVVqt/EzdMwQIgAvucYyJX4vIR/sN5C3Sj184CipzzNXsIrZe+wzgviPBtKSNOM7iS8bEkEne2nWm45tfrY/f/PejJzECpIiQu/VtQYW/4v9zccIBqnpzeY9pMlzz5dCWeee3M+Bhsd9L7aHzjPW9ON2lQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FRGRawYq; 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="FRGRawYq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D07C5C4CED1; Sat, 7 Dec 2024 00:10:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530207; bh=Os2VDm7T2HaClAOyw5Qu+qgRH8oZSj/aikGBRuX7uRk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=FRGRawYqON09YurMhISUjmwMmlcLtZAx5eJdkti74BJofWWcTWNqjt+aZTxUoj9OG zfBfqNYyEuE2KHScgeecev+ZMUg8x0NCQsYkCS1TKJWJAt8WHwbVlz9CnpQ6YeCHDa eKCuZ4tSKCvs7wGwFvLNTvwiDbpBhnWBC7pynn5w3V2IYl5hHf61By2a4z/O4lUKYj VuUINRBUWAvDr5QOq1ZFcxs3CqaZIKJVeGpu/k9p/QxZVckX4zqDvigpXsteK7c4CS tK60W1PcO86xOX/T1ZGs+oaMvy6BF64OOuimdGZrO3gna5Guggcx/nuGhbw0F1+pBK EYZyLZ815VCQQ== Date: Fri, 06 Dec 2024 16:10:07 -0800 Subject: [PATCH 20/50] repair: use a separate bmaps array for real time groups From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752251.126362.2634382219651992049.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Stop pretending RTGs are high numbered AGs and just use separate structures instead. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: "Darrick J. Wong" Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: "Darrick J. Wong" --- libxfs/libxfs_api_defs.h | 1 repair/dino_chunks.c | 12 +++-- repair/dinode.c | 26 ++++------ repair/incore.c | 117 +++++++++++++++++++++++++++++----------------- repair/incore.h | 35 ++++++++++---- repair/phase2.c | 2 - repair/phase4.c | 16 ++++-- repair/phase5.c | 2 - repair/rt.c | 5 +- repair/scan.c | 28 ++++++----- 10 files changed, 148 insertions(+), 96 deletions(-) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 980250d58164ab..84965106358d61 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -289,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/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 73a70ab5116c9f..0a9059db9302a3 100644 --- a/repair/dinode.c +++ b/repair/dinode.c @@ -548,15 +548,8 @@ _("Fatal error: inode %" PRIu64 " - blkmap_set_ext(): %s\n" } } - /* - * XXX: For rtgroup enabled file systems we treat the RTGs as - * basically another set of AGs tacked on at the end, but - * otherwise reuse all the existing code. That's why we'll - * see odd "agno" value here. - */ if (isrt) { - agno = mp->m_sb.sb_agcount + - xfs_rtb_to_rgno(mp, irec.br_startblock); + 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); @@ -566,9 +559,9 @@ _("Fatal error: inode %" PRIu64 " - blkmap_set_ext(): %s\n" 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); } /* @@ -578,7 +571,7 @@ _("Fatal error: inode %" PRIu64 " - blkmap_set_ext(): %s\n" 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: /* @@ -664,7 +657,7 @@ _("illegal state %d in block map %" PRIu64 "\n"), 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: /* @@ -679,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; @@ -700,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); diff --git a/repair/incore.c b/repair/incore.c index bab9b74bf922c8..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,16 +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) { - unsigned int nr_groups = mp->m_sb.sb_agcount + mp->m_sb.sb_rgcount; - unsigned int 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; @@ -287,13 +291,20 @@ 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]); } +} - for ( ; agno < nr_groups; agno++) { - struct btree_root *bmap = ag_bmaps[agno].root; +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 (agno == mp->m_sb.sb_agcount && xfs_has_rtsb(mp)) { + 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]); @@ -302,18 +313,28 @@ reset_bmaps(xfs_mount_t *mp) } rblocks = xfs_rtbxlen_to_blen(mp, - xfs_rtgroup_extents(mp, - (agno - mp->m_sb.sb_agcount))); + 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 * @@ -354,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); } @@ -366,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 ea55c25087dc1a..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 diff --git a/repair/phase2.c b/repair/phase2.c index d2f7f544d0e579..27c873fca76747 100644 --- a/repair/phase2.c +++ b/repair/phase2.c @@ -568,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; diff --git a/repair/phase4.c b/repair/phase4.c index e93178465991c2..3a627d8aeea85a 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,8 @@ _("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); + add_dup_extent(agno + isrt ? mp->m_sb.sb_agcount : 0, + agbno, blen); break; case XR_E_BAD_STATE: default: @@ -389,7 +392,7 @@ 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); } @@ -400,9 +403,8 @@ phase4(xfs_mount_t *mp) uint64_t rblocks; rblocks = xfs_rtbxlen_to_blen(mp, - xfs_rtgroup_extents(mp, i)); - process_dup_extents(mp->m_sb.sb_agcount + i, 0, - rblocks); + libxfs_rtgroup_extents(mp, i)); + process_dup_extents(mp, i, 0, rblocks, true); } } else { process_dup_rt_extents(mp); 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/rt.c b/repair/rt.c index f034e925965f75..2de6830c931e86 100644 --- a/repair/rt.c +++ b/repair/rt.c @@ -58,7 +58,6 @@ generate_rtgroup_rtinfo( { struct rtg_computed *comp = &rt_computed[rtg_rgno(rtg)]; struct xfs_mount *mp = rtg_mount(rtg); - unsigned int idx = mp->m_sb.sb_agcount + rtg_rgno(rtg); unsigned int bitsperblock = mp->m_blockwsize << XFS_NBWORDLOG; xfs_rtxnum_t extno = 0; @@ -100,11 +99,11 @@ _("couldn't allocate memory for incore realtime summary info.\n")); /* * Note: for the RTG case it might make sense to use - * get_bmap_ext here and generate multiple bitmap + * get_rgbmap_ext here and generate multiple bitmap * entries per lookup. */ if (xfs_has_rtgroups(mp)) - state = get_bmap(idx, + state = get_rgbmap(rtg_rgno(rtg), extno * mp->m_sb.sb_rextsize); else state = get_rtbmap(extno); 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( From patchwork Sat Dec 7 00:10:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898114 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 EA3889460 for ; Sat, 7 Dec 2024 00:10:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530224; cv=none; b=uEiVerU1ClXixdUjz+petRs0t8isuMOuZFxq58tS9KjViWp4qokECnQuZa4gKpoet47hKNgNFD9JQVcF28fVXJ6Ym0uWJMMOKY2SFniI6Nt3XkEMwxtsi/wFVnif3MNU3NLG3h9cT1DzN/2c6mSSb8GiCj7sMXkKZhe/1fjBLf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530224; c=relaxed/simple; bh=usNDysAEJlfqXejl59cUXv8NE/vQni6o6k4N7CEn+pQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u1eypG0nTVBUvQMtTJskUWJSgeO1kMttxERqS8SH/WIKURCNFg1yToRwkN4M/oVE/vb2XVQJFk6AwwQrcUhNv7QB+676Ba1iqSOyLz6RS0ct7ST6R8rIqlTv5RW4QljEBnDhPDLxcHAIMwurnjSqtSYEkbq9JILkThX0BG4CLj0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Tw6Vf/Kz; 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="Tw6Vf/Kz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CA2AC4CED1; Sat, 7 Dec 2024 00:10:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530223; bh=usNDysAEJlfqXejl59cUXv8NE/vQni6o6k4N7CEn+pQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Tw6Vf/Kzu/D8ZPSCcJwUJcwbIFBdXpOibv5+nDSKP042RXqlSWgIHNWKYhCDNR+SH 9wKrHfFWK1dUcr3Xq5TLgRMIKs0iStk416DBHxuDf5K7gUL+pi1cdZT9FslK2C8wq2 /eATg3yyf6b9bPX+Gl+pgHLhN2+6UHkzjol1lDHusCymq0/gU2DtNUwU18mRleQ/A3 odIPjOCGb21/K0kQ9Vr3VENVuXG8mPIYVO1VWmN7McEpiCP2L+XreyLIbiw4GKhgJN SOa+IEykuWac2522UqGIP92M39pgU4ERRQZK/g6k1Uqz2PsByuPva6jNSwIo+gZBGB IFqA5JIQEeZwQ== Date: Fri, 06 Dec 2024 16:10:23 -0800 Subject: [PATCH 21/50] xfs_repair: find and clobber rtgroup bitmap and summary files From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752266.126362.10125424805572848219.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:10:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898115 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 C0CA8196 for ; Sat, 7 Dec 2024 00:10: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=1733530240; cv=none; b=TAg9+MDhaipuo601fmFCwjk2vV2tXHxVVF6KQqk7td9LqKlHae/rKZsu3Y3PQ3aYjlxEQoVGKzFWOwSDru95JxfLvat82zZXY7dJx7drj22W/ADKCiYIwY0cCqsVbne6OVTPGOg3uwdvPf36nshj+xYwsPP05dd8RYq2zlcvAjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530240; c=relaxed/simple; bh=zfGFa7d9hfinLkQGu/wqg2048vycKn3q09kkWATswxw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iGjdSwwPxvvAYmlt1+8l4RVWtLybXcvcu2wiD/hjMbQOWYUWUYZ93WX1HsI0lZa9i6o5ySAYjbRwve8b4TpLvye72UvClvcGtf0zWyQe39ctUzHrHJ1hyATMwNFeN2wbzsd7yIWXrrwZIZ9TgV/DH9We+tkopXBbuXJeGohyj+c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kGTpc96F; 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="kGTpc96F" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A01FC4CED1; Sat, 7 Dec 2024 00:10:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530240; bh=zfGFa7d9hfinLkQGu/wqg2048vycKn3q09kkWATswxw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=kGTpc96F63rx+zEM1UVGWyBHGJd35GXNtdVnsh6Vyr05LdseOJC8tvldMxFs8eq2g UcMQqu9D9gm9e/q1yuwOS2SgMVoyR/oezXbPDdsnDywFwGunUnI2ZVT8Nzjii+d1NL sfnLzHQROeWOACRq7iYmSlsibUn7xZPXKOORAD+UXczuvCYIw87ORr0qsW6GFZIPGr lokWrUhGB9WeFeD2eYFVN5MeT3c0IClcx0jhEB2ndxFITpLnTx6uP0zT/0W+GH38pp MuAkASoyZ8c2ZZvbiNUXby8qIEMAwIQX8hisvVzhS5ESkBEm1Ev/7Beyieu+uxYk7y n3eM4x66ATYzg== Date: Fri, 06 Dec 2024 16:10:38 -0800 Subject: [PATCH 22/50] xfs_repair: support realtime superblocks From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752281.126362.11077683700931989988.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:10: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: 13898116 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 2EC3F2CAB for ; Sat, 7 Dec 2024 00:10: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=1733530256; cv=none; b=UMiPJ+RLlAP1Oz7MR/Ef8wv+bHqxW3b6TB3+8prVfzwSwiW6B8011NuUPkc6uiuK+B8UnpfwfDTBq6VpC56klmwcrI3ykhwmjrFax1MrE3XDuh+pG4t9HJsxmGZXTHmpGdSKkzatsehptIwGcu9FULRFGQRPkdBi7eNlmMOXYeg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530256; c=relaxed/simple; bh=dhl8u/opL6FLMrT1ONqoSb5eZOtIG0eLIZw5Z1izmmg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eYi8YFzX321+St5ojqlBxslKi2ihr/OxZwQcAxRRPhqV109nAgE9jexkEfFtoxVLnQmq8MJK8ZyHaxWqZSVDoqefkeq4OQUNE+xBUTXOzy7/qqllTngxz/5Cjng79l2NfbYy2J7BGJZlRMRKQ0Algt9m6yAVZuOz3r+WNSDYSH8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OPDZ+j2F; 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="OPDZ+j2F" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3145C4CED1; Sat, 7 Dec 2024 00:10:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530256; bh=dhl8u/opL6FLMrT1ONqoSb5eZOtIG0eLIZw5Z1izmmg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=OPDZ+j2F7pEusQ0AU3SvSNCXP2iHeOMMMmoDRTQhtff58VTtYBPi7i3CTUAfnkF20 RIvFBijAy5olV1UNLwUy9mIf50t3WFoQ34aIg+o4qhpxpj/Yt4uax05Kryko8hawtA 38CXDVF1lNbZt/TMa6upA8Rw1M8UzhgwzHy54patsVGh7UdsYkMG02ZCYRfLfxvURi eVwKVEShb/B6L3fx0+kGu5/33A4q9j9ny92ZoNoaNaxQzqI5lVFdp+88Uw+auYR/W2 9Qz2ImE9i126iZzMjEbN7Iug5wzDlBjVhkX3VY4rMu0IeMm7QNZpvlCwAMRjIV0Fa1 frk4fLATX8Ljw== Date: Fri, 06 Dec 2024 16:10:55 -0800 Subject: [PATCH 23/50] xfs_repair: repair rtbitmap and rtsummary block headers From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752296.126362.12671784441675621141.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:11: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: 13898117 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 B3894256D for ; Sat, 7 Dec 2024 00:11:11 +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=1733530271; cv=none; b=Xijxat4QlHzF4SOh/7vjc6bItvUUeJRZVAtZy4oMccuJGHYuVDS1lxQhTYwFsyQDvzHoCs3KsvQxZhhu/VTknw1yA3eWb2Oxh5VWUP9PGZokXJIWGTu8/6wvxaMF9JIs0LMPV1dRrKccbugqHO3oudTC2/RoVEdOm577o80/dU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530271; c=relaxed/simple; bh=1dG0gB+ZjIOPsU6W+JVmpvGDYx7ElnpZVloDp0HtARk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZZa5au7LEku8rPYTNuDQ4SFUSq6Qodkp63Cmffi/bM9VZ5dZm4Po6PojsqL3F4odPSvefaTYNljMwG7zTx9niMmRpOsqHXa4K8SgeZJoyg3RgEPGjuWD65e6Xn13zsJqjfNxcU0ACuRTq49wMUttr9nhmadamMUSF70Pgh2vVU0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=e5axUeft; 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="e5axUeft" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F638C4CED1; Sat, 7 Dec 2024 00:11:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530271; bh=1dG0gB+ZjIOPsU6W+JVmpvGDYx7ElnpZVloDp0HtARk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=e5axUeft7U7F1B2TL2WoFhMfa8ulObjjn9BvFCkaUKCNEBk8qwQ6UEGxM3goR3NQZ O6GAtGDa1kkN9+V4enB8IiGp2d9d7PVninFMkQTcUfSpmYF4Fu7v60bvLh2q5Oz9Cw T5apJFfONveVY0BwXV5FCgtVF70xbXQi7ds7SRwhfmm43rrRzdbkJh/Nu5sil8aKn5 CT5ABXHBdugrPUn2i9QJhM0z5Qg4NiBZSCi4cMevWrG5hCQqns8uoImnr4Nyb0ucX5 aqSGJr/KlBxMm00g33ZFMA35xSJ4Me4GhdS1sk77ST3KtKY1SZxR7wC6DQEkg49CRW fC9Ek35QR9dfQ== Date: Fri, 06 Dec 2024 16:11:11 -0800 Subject: [PATCH 24/50] xfs_repair: stop tracking duplicate RT extents with rtgroups From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752311.126362.6980632236757578255.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Nothing ever looks them up, so don't bother with tracking them by overloading the AG numbers. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: "Darrick J. Wong" --- repair/incore_ext.c | 5 ++--- repair/phase4.c | 8 ++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/repair/incore_ext.c b/repair/incore_ext.c index a31ef066ef356c..892f9d25588c11 100644 --- a/repair/incore_ext.c +++ b/repair/incore_ext.c @@ -725,7 +725,7 @@ static avl64ops_t avl64_extent_tree_ops = { void incore_ext_init(xfs_mount_t *mp) { - xfs_agnumber_t agcount = mp->m_sb.sb_agcount + mp->m_sb.sb_rgcount; + xfs_agnumber_t agcount = mp->m_sb.sb_agcount; int i; pthread_mutex_init(&rt_ext_tree_lock, NULL); @@ -778,10 +778,9 @@ incore_ext_init(xfs_mount_t *mp) void incore_ext_teardown(xfs_mount_t *mp) { - xfs_agnumber_t agcount = mp->m_sb.sb_agcount + mp->m_sb.sb_rgcount; xfs_agnumber_t i; - for (i = 0; i < agcount; i++) { + for (i = 0; i < mp->m_sb.sb_agcount; i++) { btree_destroy(dup_extent_trees[i]); free(extent_bno_ptrs[i]); free(extent_bcnt_ptrs[i]); diff --git a/repair/phase4.c b/repair/phase4.c index 3a627d8aeea85a..f43f8ecd84e25b 100644 --- a/repair/phase4.c +++ b/repair/phase4.c @@ -322,8 +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 + isrt ? mp->m_sb.sb_agcount : 0, - 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: From patchwork Sat Dec 7 00:11:26 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: 13898118 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 500CA4A07 for ; Sat, 7 Dec 2024 00:11: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=1733530287; cv=none; b=sl7fEn8Pg6JekC8pvj7z/LwRE3eq9petWg8wscrBBkL+8MWOp5gWYZiLkdlUJgJKzk/aYIWF/j2wxbzMq36WmNdGnT2GBMIv38VKjMx6771rNhLCCVQxXLoQui47/uuPdEd2sDWMSibWcMTSj/++MB+aaQLHwJaaMls1lTb9kyY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530287; c=relaxed/simple; bh=sRsRFAhCHCoEukFkIdwnHD2nmS1apEizt2pThiEM3Mw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IzvimPflhAgWA8QNsnZfjDaLpXxY64hvoIZA+0XAGGIo8bhgIWSvKSeTKH32rVZLYYFByw9gGCKR+auDMLQQO+rWqo+K5ZNAydkcAVFJzQv5NlfNPGJHlHGoDyb/um7R8HhACjUS835jJwdamZZbDJ3MtOoBRJooy0mxPqeSlXg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QT0oWwx/; 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="QT0oWwx/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27BFEC4CED1; Sat, 7 Dec 2024 00:11:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530287; bh=sRsRFAhCHCoEukFkIdwnHD2nmS1apEizt2pThiEM3Mw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=QT0oWwx/6XNkQcZiFgudXSnqgAVykrKAOBijuLE8fQNfodSq6DaHmIZYym421NQWE vjlxWxewbypW1w61MELLnGHca9dU6ma0nSCjwaZmBJyN0j3SFSc99YBuRSn2SlDL7Y 7UTXtPmBp32/2YzhjM0eHHZPXxdHjvw9Jw/0Ol/u5S9KwHdaIKWnmq2N1xTmOxl4Vo YET6ucgabirAr7X6uKyG8zkRdTbIqhg9jKFICHmXqqHHQNO1+ijeSvHJoQwmQ7st0K Wkb1jFuFCmCgdXO1ZX6/14nbj05c3dfNk3KSCT2p4WH2f7z806CD4hqD0/e9XAX+PX o6WDXGPAMvx4w== Date: Fri, 06 Dec 2024 16:11:26 -0800 Subject: [PATCH 25/50] xfs_db: fix the rtblock and rtextent commands for segmented rt block numbers From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752326.126362.1070873250646267314.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:11: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: 13898119 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 EB2F24A07 for ; Sat, 7 Dec 2024 00:11:42 +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=1733530303; cv=none; b=cpDmsSCgdr4it9W9Tg1CEJ/Yd55THoT8yj216BWrfLA3Lz5T3obIcpsTz3yhCHLCgM6+sYVpyDx2q03dQNnsaotN04SLrYbBkwfyLLDOuMjV7+HU87aFEjmJ1HXBkdIaTYJ8CwS5AuHAQXsJAxyFoYUyXuw75MVBifIPgYTvLnA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530303; c=relaxed/simple; bh=wJgZk9icS/MyBkG7z51XooIslFn9A1go55AgCM0hWZk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=USt8HU2bOy6UJTTgY7nzmB+oIaS/IYmk611xh1QWUmuiszHOUYLsh9571GVq/kEtOiQF05sX4drkf2PUyshDwgwKIX4GoxjrK+WALxhvZw85RDRejgNrVBMtie18DgveES6cv9asAAYbcwyJiwd9VThdpjhfPCR2bjT/xoE7k2A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ObcRobha; 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="ObcRobha" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5753C4CED1; Sat, 7 Dec 2024 00:11:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530302; bh=wJgZk9icS/MyBkG7z51XooIslFn9A1go55AgCM0hWZk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ObcRobha2KTb1OQ6xjBkJoA+8G5YQIls4VZoSmQ58wxDa/QB9bykmM6t2vKzu9jCJ 1tT4FXaM4Z+Dt4jj4MkSYC29uyC4UESfh0XDD9PmsuS/PzwMGJI6qKSruJyU4Qe1XQ jI5s+4hQ4NQCyoanWcUOkLRIPOZbMOpERHoAZg0yGkiGeuieeRbn3qsaq7BhEbKw5t OIf/GSEEhE7wPGsU3NSX4pKtdqpF3nGAlZyEkuhHkos+WLNGCdWe7fpWCB2KckI+lc YZaeE+IunAiD/hjHbR6esR/3b62joGv9ngy0Q8U/QHHSauVFpnq9KakTijrDj/H37t P+r4I33kVW3ew== Date: Fri, 06 Dec 2024 16:11:42 -0800 Subject: [PATCH 26/50] xfs_db: fix rtconvert to handle segmented rtblocks From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752342.126362.7151084225885980106.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 066f124458b286..3cc7314cac0e66 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -1244,10 +1244,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 Sat Dec 7 00:11:57 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: 13898120 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 E00FA4A07 for ; Sat, 7 Dec 2024 00:11:58 +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=1733530319; cv=none; b=bdD4unsTXVtYPUKMuGpgZw/aorSgY08jwhDXL5/q27f0ELNuewAwONGMMx/O4iK0B29UEyZu9MHY1e2EFXySiINN+AsYCQCDef/BgrPe4xe1vqISl+Lrs9t/hGigbbdwwquAuP3I8xxTeqG/HEHGgrT+2/VjLyboriXTBx7MC78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530319; c=relaxed/simple; bh=qhGHk/bFFHSwI4Z2Z+nXhWnzaI1ZFdmBY6kRJXF3AgE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=isYtffA9wkZ+TPsrCeydv4GKlgj/YNKD2DIol4NBViIhMNnvuI4mIwKecMpyD+XuhOhNo0vmWggoCvt6dLVgw1X8rsQDrzG9Su4sxXtHtBbLEHHc3Wlxwe6nPr3T16vh3YLPTiZNpK2aeMiVVqGSc0g//iS289GI1B2rl0kZLzg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OhUIteXA; 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="OhUIteXA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72610C4CED1; Sat, 7 Dec 2024 00:11:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530318; bh=qhGHk/bFFHSwI4Z2Z+nXhWnzaI1ZFdmBY6kRJXF3AgE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=OhUIteXA2pBP4/EiCGaeK5E5pq1aZMQ+S9NgrZHRXTJHVyXyyKF7Av2U06XGkh6HT eI45Y4kYFJJMLTbBKeONkzQC/SlHEd0mntXQURkXhiyObsCPoaSaOGY6Fk4O+bVFuZ XaIzQt4DipzzeoRoGuVekB728HfbPlbvWmpGT4TdwQUHtfMBTLeP5oWAXULEUzx244 lwCzvHWxAsHpdRoJVKUbv0mTfHnpD3UTofvpUutyidSYN1Xei5p4M5QFXRk/Oj7ILK XEIzV0T+jD6ifF0nO1UK2/2GarQjuEu/Me2gKt5Vne6v0wJvRdiLtdr2q/rPG0QUoC N/Kaq6tHPN6iA== Date: Fri, 06 Dec 2024 16:11:57 -0800 Subject: [PATCH 27/50] xfs_db: listify the definition of enum typnm From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752357.126362.17852148009193165099.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:12:13 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: 13898121 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 9B82C4A07 for ; Sat, 7 Dec 2024 00:12:16 +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=1733530336; cv=none; b=HlFd5aFFBLaZoNYAbk+Ytrrp9/6h6m3EV1ft5WGkijnR+tjBzG2FpLgBCKTaWb9hDIerbjCDss46ACB2tmRsTrXToKohjejPcbspnFNNa3Jn0F32FdLCyLlXdApH47Yh4xW76LuhidLXTX1Fs9u4eLv3IqkrXKzlAFT7mGZByro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530336; c=relaxed/simple; bh=HJJpI4GCnrkAToffLSRbL1KWr0K08ZUmLDgHQvsnOl4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u8bMPmb9pmXl8vHY4rlmeptgiraQp9ZidOzD2varMETKPOS5ej8jSq4jdoeXU+ozIq6EvFvsV1WwxXJRBN7bM//3ijoFGJSwLgJFXn9Rj8Kl7mmLzm8Zu/5nXd2OyFZmyzUPdPtcR7almSMbcqrdY3YKL3cg1NZFi8VQYMTnPX4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vMMcwNk9; 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="vMMcwNk9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F149C4CED1; Sat, 7 Dec 2024 00:12:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530336; bh=HJJpI4GCnrkAToffLSRbL1KWr0K08ZUmLDgHQvsnOl4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=vMMcwNk9Y+KoKdLECgKWd4R/6Aw6iLfcKHfkAubCaNYXCkX7ayW7m41dqygPDMWN3 wlhg/Z5sSunxXX0AZRqWCcougJJNj16jc5jS2Bw7ORvgIyz3mvjKJ5ujqSI79Wux5K HMS7SWVd+CFSKOMoLGTT0+D162QHKHSEdoM271Nk1zOkfZh2yMmyW2PG5iL+x0Y0oR OywwsKhWNKMEcbSzup0PN9xJxpGqGX2xrpQiOFy2GNi9sZyVOmiQLFs8QYMaDbPV6Q 07kRDOTRMFqEsUYdsEtW8ctczd0KRSn+jnbqVA37aOLxYuHE6Y0aScy9hgvwBplRXx qd8mHAWwQgrcw== Date: Fri, 06 Dec 2024 16:12:13 -0800 Subject: [PATCH 28/50] xfs_db: support dumping realtime group data and superblocks From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752373.126362.17848531751610324154.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:12:31 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: 13898122 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 382FA4A07 for ; Sat, 7 Dec 2024 00:12: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=1733530352; cv=none; b=elwZtpcq7JI3Q/avEIOAA+rHBfMQdsNsciXkVc4BfqNUR/Y2SeGLalyEW/3VbyXgg3YRyarOVDeOqNHJw1ISoWConSY/vmEDjyD3djTxdTeOfLipQCoRgAwNVPfAianv7+HUx7NCR6Eup/5t8Qc+uVRxQnd0eMiOCc54+SkaJsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530352; c=relaxed/simple; bh=ujpZ8/GHjJVULljRJqGMS0nOJZht8C2J5CR9TQ9VH2Y=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TwkPAwhC6TlF6x5gMMjOt8aTci7y03GoFZNXkb4+aK6NlzKT6i3n4E6QqPZrGN0zIAKOxSs214D+o+FfmoUt21yq3T2y7fYOYoibWM7tUB78RrZnf/F/EioWF1gX5qoqsNG9oCSQipZRxE+A5Nk0yW/+VvMBnyi1YHzkvwwE4wI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ws6HwkD4; 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="Ws6HwkD4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10353C4CED1; Sat, 7 Dec 2024 00:12:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530352; bh=ujpZ8/GHjJVULljRJqGMS0nOJZht8C2J5CR9TQ9VH2Y=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Ws6HwkD4pWlGZ5tR9euSJbsWDCoMLDgRFqpd51/4iETJLnDXXow5PIp2Q2GWNRbQ7 ofOg0WuSccX2dJTwU5y1xfE9/keg1g8iqhTYDNX2OWZ3d8yDr7K6Uk2HXetzjcyy+s uNEK+X3d+0oz61qBA8YcFslM2YjXugHcGXwCgxt7SRtnzqwnTErxbiri1/kCcYowR3 W44Lw0amJQch1Jpftv1YMgKQtrd+u5WUqu6OX0qwOLF79clCxu6QCOua1HRSkfGpW0 0V43mjISWh0Guka8uIqUALJ/ftOKqDwwLnoDWupd9a24ev6CEmqsMtzGQpFtQ15Bjn 1Og0sF7TCblVg== Date: Fri, 06 Dec 2024 16:12:31 -0800 Subject: [PATCH 29/50] xfs_db: support changing the label and uuid of rt superblocks From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752388.126362.13051985148596315963.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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..ba5a2d5851f602 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_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 */ + 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 Sat Dec 7 00:12: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: 13898123 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 CD471139E for ; Sat, 7 Dec 2024 00:12:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530367; cv=none; b=n+uLq22TkbKhGzliJ5oKExP4hHcRwHT6Au2iF9Q0eANiUKliVUXE+z/wKDSZ2u93D9wsR5d+A9tNV+LQLVWoQ2az6P3iP7XNESdh/W2R1lztGcQvXuirg3geV8IdtKWkb4JzUdjO9TJAx09qLKHyv5zj3I1GNnujSgalLV+iNoA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530367; c=relaxed/simple; bh=dyhhviChn2JyQ4iGBurJv4PXRbT+2CqHIbHgdWd9sV4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=L0oTPzUIuTppwRrYrzRj15ulJcf4GjOnxzgNzq3cBXCKt3KdYU+ShXC0/k9gcWULtpdJofC70V96roHKrvWy2m2ZLrFdDUskTMITXC5aDsmLoQfQ8Gi54k0gwwr4fmEvEMssJsXbPPB7OcRqADz9lmp/3xqqStVVWQVvBdzUnRE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hASlw4oc; 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="hASlw4oc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6352C4CED1; Sat, 7 Dec 2024 00:12:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530367; bh=dyhhviChn2JyQ4iGBurJv4PXRbT+2CqHIbHgdWd9sV4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=hASlw4oc8Kl/YLszy1bf1qwKlOm5lw0eavse1C3YwrO6NpBZjH3H9bltVTJI7M81P N0bYFNmsAhejE8hzUrOun5XtBlo1YipKakKVPYoR6nqtwhpkoahCg048+/YRZow5eM FD/M4usHiqYR2X1DXlQs1v6uB3B3veG7aYCb/eGmT8aJ9iZxSXWDKuMoBuyQqKI8Rc BgMZSB6hb4uUODSlkqgN+/LtvtFa8q43ndl7YGdgcLfYlF9bsxraoBjw9LeltvdNbx uxvwMgFtiKuIouCod2jvBjCWVrafueOzxYFrCa3BPJg4MB48eHodU7VVr3LfPdnCZN XRG2Dm0gv8SxA== Date: Fri, 06 Dec 2024 16:12:47 -0800 Subject: [PATCH 30/50] xfs_db: enable conversion of rt space units From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752403.126362.4952280816720663470.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 3cc7314cac0e66..5d72de91dd6862 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -1167,6 +1167,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 @@ -1234,6 +1244,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 Sat Dec 7 00:13:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898124 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 CE420196 for ; Sat, 7 Dec 2024 00:13:03 +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=1733530383; cv=none; b=Xu9ms4YDht1fmG7kp5faoU5x8fgt/fXt4CDVV9qH7IwEdWXC32vuta76SY6Le3SebFe+KPMMXV4px/2f+98H/sYGIzhOgxK6BkqpcctFLdq5roAmnnkaORmF6dZ8fmjDhZ1AaEldfCmqzPzIe1/+ZB6bVWLm92diyqbzpWVupLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530383; c=relaxed/simple; bh=9+vNyjRfu6Nk6M1rPu75Kfi4fOpRTaQAMpMfodyKZqc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UF2uBR+V20hVferW0nm03YKFDJ/Wxe1UvqaqSHdYrmi/dEexgmctELyP0GHMaTJkO5rF2b5TDkh0Rcz1db5nRXpWiDEF+ctv5bV+0Y9NL5kZdwRMnx3Xyzdj8Us3SNjJdQWUaIL4CYox3E7udXCfI1k7U1WEvwc1aVvuipR8BVQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O3pVkIPU; 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="O3pVkIPU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42A50C4CED1; Sat, 7 Dec 2024 00:13:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530383; bh=9+vNyjRfu6Nk6M1rPu75Kfi4fOpRTaQAMpMfodyKZqc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=O3pVkIPUfcym4SfO5jz6niXZXVbTsSHMZrtLBgObpza7j+8sK8vPDY/ictMiNu34W 79Ol8YMcw7J5BZuxxtmzTtieoc6RWFhjPdfkX+7ibYUvNegtqfWVzGRZidAC3W31zR 417vkn59iPAp2ABETlQgFyOKHcQ5e812fzhYGXmcHCX63KNiU9wziOHVyw+QSzgHsE EO/7lOJagIaDUoZe6CDNsqyFBRdrBQosbxGQkEOY43DVUq2rwzommv2v9OqatGeNQM s7j20Wl0qTOzwpDosGcRGbeQ6pjDBo7k9HXf/Y2FKbVk0GjPfjHwuW227gt2rQ51dY ls3cgGCv1lQmA== Date: Fri, 06 Dec 2024 16:13:02 -0800 Subject: [PATCH 31/50] xfs_db: metadump metadir rt bitmap and summary files From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752419.126362.2851932707470416639.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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" --- 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 Sat Dec 7 00:13:18 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: 13898125 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 5A10410F4 for ; Sat, 7 Dec 2024 00:13:19 +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=1733530400; cv=none; b=pmfSd9lC2pRY6mgEn076z0b7V4Ke+1wBZC2l/vICLJ7DUwRiSsiJPbKhP0UpTnflRyWmO1hAkf+in6ua9iftMg1Jxmy0ieRzeznqJhtYRFhqWdyR2oqGwkpjd5j04Y7tSiSDQsNafQk0NEY4xV0Fljp3Bdv2+APgaNK86/Z2ArU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530400; c=relaxed/simple; bh=25D5yn1ZLNv6mLFjzuQLbj/+6e8RmXYT5WoTQZsdIC8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OF9lmUecjQQgmH1+3tDdN4UPj87bMsMqh2ZhDPMBYfEEtbnSnp7Gh5syx/dMPmr2fzhR3O/scg74VTFhE9DfPIQQev197lKdAowwlRmGeuIBimffJ4K5bCuTdbtOWy7ZdX3gHqgvH60awxQMg5oN9cKyoaP6MOv1BXcMcABTAZ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KuVU6zQm; 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="KuVU6zQm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E16E7C4CED1; Sat, 7 Dec 2024 00:13:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530399; bh=25D5yn1ZLNv6mLFjzuQLbj/+6e8RmXYT5WoTQZsdIC8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=KuVU6zQmt31Y1y2zSTogERC/Y8wDcz9Q93XKuBtgPFvRFPLnH4voXJ5DCQFmbymCg CxxCqhu4kG+KCfVHwEkyt1BWBFxXK5xSBnMXgdOR9q0RrtiD5O5Dj9VQFqz39hfgPJ bkM5uwe/pEp0SbefzEZnluYsRup4LwdoajhMjwlrySi67ifozFW6lf41/dHGLmIVAu duItTbjIfSTG8Q3HGC4TMA/sophVUzOPJdiG2Zp89QaKfosdFW2TsWEIzfFlXXRvLE iG/T1lfhuotVzI6mY5eYkYJ2UIrCaQeVDVzO9rYfQTqXkU/+RQVSbHnLK85hpXy7M0 awFT6EVUFT9Gw== Date: Fri, 06 Dec 2024 16:13:18 -0800 Subject: [PATCH 32/50] xfs_db: metadump realtime devices From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752434.126362.4802798668828712862.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 | 52 +++++++++++++++++++++++++++++++++++++++++++++ db/xfs_metadump.sh | 5 +++- include/xfs_metadump.h | 8 +++++++ man/man8/xfs_metadump.8 | 11 ++++++++++ mdrestore/xfs_mdrestore.c | 5 +++- 5 files changed, 78 insertions(+), 3 deletions(-) diff --git a/db/metadump.c b/db/metadump.c index 8eb4b8eb69e45c..1941f633ac1397 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,20 @@ metadump_f( return 1; } + /* The realtime device only contains metadata if rtgroups is enabled. */ + if (mp->m_rtdev_targp->bt_bdev && xfs_has_rtgroups(mp)) + metadump.realtime_data = true; + + if (metadump.realtime_data && !version_opt_set) + metadump.version = 2; + + if (metadump.version == 2 && xfs_has_realtime(mp) && + xfs_has_rtgroups(mp) && + !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 +3335,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 Sat Dec 7 00:13:34 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: 13898126 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 EF1BB17E0 for ; Sat, 7 Dec 2024 00:13:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530415; cv=none; b=gQ4fnw1M2wF6FzCIULFJR9Ws+Zr75cEIVpJcGsAkyf/1lF6Ygwc5yBpL917ht1MsnOD675B9UxsabkExknTXPyq5du1Ue8Klet9uHrV+CS8JbbfwKfPoDEnzOHjRm440Tcdc6+B40P2jE4S9dLMFvyowLl7IMmSfkPmSYSmHhM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530415; c=relaxed/simple; bh=3ey4M8dc7EhRB94eOd0SC4pJ7ZRpxn/p5QJwl/wy7iY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pA5RFF9lAKLQpZlSolUtAEeyeMTyGdTJUyewp9s+ks6pv9tjuTpn9Bnq1MSiA96/jy/sDM7A1gw45W7o7A6rl1Nn+3dCuI51g6VRX6GrCfr25wJJB0lBDGkVrhCvT8jptFr+yC4o6dC6dl2PQ75Fs7V5MFqtRc8cxEC5JLIEsVk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=exI9ue0E; 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="exI9ue0E" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8196DC4CED1; Sat, 7 Dec 2024 00:13:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530414; bh=3ey4M8dc7EhRB94eOd0SC4pJ7ZRpxn/p5QJwl/wy7iY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=exI9ue0EjDmo2yqiWGMzdd/0ePI+M9s8hK+6QMKYw8iFih/4AX+S5UIChs9NL2AMd Oxgu15IUEp/6UkmMIZx/SEKzI40Z2g/5iWf0Jppf7xcwTOy01yZkguVMzud+gEFhvv zepKg+R4tAu188w+z+Q71oJi7G/wUnaGU8Z7ePQFOeQUUseRH4/gOj6Z2r7upvZ6mc TC1oOTbieyy9MsU2bovKy/iBklw5D/QQYc9sNn6kWTafVKHm0obKvroUx2KJSqSy18 zO7UOtWbavYSGcHfgToURv6K18NZz+1KsubStYEp9rj8PCd9zJNhfaKmwcV3Jc2d5v 8tZ0+D8awD32w== Date: Fri, 06 Dec 2024 16:13:34 -0800 Subject: [PATCH 33/50] xfs_db: dump rt bitmap blocks From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752449.126362.12190261909488631960.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:13:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898127 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 55EC62563 for ; Sat, 7 Dec 2024 00:13:50 +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=1733530430; cv=none; b=bNncMFYGff/KD2zt9GaS+1QC44JBS3NaYQF6fP/yox9iYSIfwzUjBmn/NmBoxfIivqa1vEnTVStbd22vEKEnDDZWbQPxVeMurNQc1rK9VzoYrJDH7/ROhlYeZF9tADFHHaFwCqGX3j4szrrnmnGs9W0rHk5Gi0TBeHjO5E8U4gk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530430; c=relaxed/simple; bh=BUPPsOZQ79uidUdErDBvi1/CKuMVSlrt/iovDRD/sUE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bdO4LNwhPfQBd9ifWAz5D8jGOFs12KkPgJCQlLCK2iV1Hq68NIueAqhAw468WjLCfgC6tg9HBoaM/Ck8LGFODRq/xa3SPXL2Rdo2JqY2ALaBiTnr/mvgEGozLu8s8H6p7kUSg+UYa1kyFt/Y+x9AiaL3Su+USv6qHkweSDPC+4g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iaIX5FT7; 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="iaIX5FT7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30239C4CED1; Sat, 7 Dec 2024 00:13:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530430; bh=BUPPsOZQ79uidUdErDBvi1/CKuMVSlrt/iovDRD/sUE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=iaIX5FT7fANzYzyTYmaG2NjZ0MRcaKIOEhRcMuQmmDekg5tIY9D3MGVdO/sKJkC8Y xw01xLLf4xdYpZGLZs2rOFJoCsMGtU0lh9VOoy6SI9kxu+sUXU7pqEK6aH/N5eb7Lp sy+uWHjHm1gPWUwYJ2vKHJao2BSj1jLO6Dyd/SCfi0/PiZCiIMnZGe3SkCHVZIyUl8 EJ94gU7SxyllyUcoaYSbT6S+Zo7vJM6OfOAKLJ93fdHCVbCUcin49irZMot6MwQX+Z YSoUNkaSijn27TqisdHUul037pBSQGetwAZaEbQLik+UJwXlM9WjTPIeeBm9oYL7a3 i7aoD86/dDlLg== Date: Fri, 06 Dec 2024 16:13:49 -0800 Subject: [PATCH 34/50] xfs_db: dump rt summary blocks From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752464.126362.14717338357511129149.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:14:05 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: 13898128 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 ECBC728E8 for ; Sat, 7 Dec 2024 00:14:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530446; cv=none; b=EzxFGzkcNHg5vCQNztIUgm/Dc9zl3i1xqKoW6Y91XeRy0Q9pUCCbnauuDpUVC+mI1yFjzkr4KvvTS25mk6iSby0YJKKWfQUaAbhaP5Ok0VmRPDYj/fIWteXWON+CN0IDzpvPQZgbelQJT8h9PsOEZsAbj/HXu3pdtLlErRKGUMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530446; c=relaxed/simple; bh=h0Mj3+CMNgmOPhk0kg+OAmzU5sQQThPVoA5OyIJnn0o=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ReqlOABYX1fJDFCRySGHFwUsDnSB9ZQQMHU3nKJG0DZam/udksASTaXaGfF9edkr7tWplXrxFApW7RGfhUiBF2Td4wqL5GgGqdEXFIAfgqUpe1oBz2aCY4E+YRAIDQZ048gr7fE6OH6mtDAh/Ag96S0pErC8kiqTRT/4NUOK2X0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W/lM0vr3; 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="W/lM0vr3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD292C4CED1; Sat, 7 Dec 2024 00:14:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530445; bh=h0Mj3+CMNgmOPhk0kg+OAmzU5sQQThPVoA5OyIJnn0o=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=W/lM0vr3m2ZVC7aUPqzMbF49MewgxIIkHfe6SWJlXpu+Ui6hysRdFp2QYBAPJtXt8 PiwJzskNGzXahoV1uT75ChZH6vntq3QPvaBnn/joL3q3UvZOWzJtB8Wtka2o88m+64 /LPdUPrCkN/cH5o1u7LSP/12o4e/k55icPTu4/biRLNRxiZrpLCEkg/nzOS8J4aOb+ +iCietvsE/zIuPv1vwv2GDm5xpHm+eG2FAB+ekJ9nwugJhhIzwLgIJR2aMR77txk1M CqyeVH+9gsb2v+7MI/SrvrBACAX5PrOfxI6tsGIT3ECOMUCm+82BnxAsFeS+JEIQVr K7V6YPamIOYXA== Date: Fri, 06 Dec 2024 16:14:05 -0800 Subject: [PATCH 35/50] xfs_db: report rt group and block number in the bmap command From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752480.126362.14408954135415554700.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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..d63aa9ef9c015b 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_rtb_to_rgno(mp, be->startblock); + gbno = xfs_rtb_to_rgbno(mp, be->startblock); + } else { + gno = XFS_FSB_TO_AGNO(mp, be->startblock); + gbno = XFS_FSB_TO_AGBNO(mp, be->startblock); + } + + 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 Sat Dec 7 00:14:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898129 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 D85962CA6 for ; Sat, 7 Dec 2024 00:14:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530461; cv=none; b=J/R5FeKGRvD2KjlvGqzcGfP8McZUfyVY5vtPc9I4KhoHXo+DaacyAu1AlXgyU5ysa0oB5J4tiAKIdYivYBxONkVsjfziSN9K6CRqGY2q3LQf7EEMz66J5Pn73j5PcuL3QkbPvaUWRq7eeR6Ak7PBvNvrOmcxPc7O5aa0M+nJe20= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530461; c=relaxed/simple; bh=+sl1kmIZv+bgkP6TtSU+wnOmA94Yzgk/n4Ipu5Tz9zw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ChHwEsO6ClsXXleG0Bw4hyNq51lPlYOLUgO0a2ck9Hd5lcguE6+vULr1N/9x7Rb+4AN9UA1wM2n2uIRxpXaPbMxipHfbl0wACZcj0ySKKq+fGmG0UskC220h49r+guhsJdmYGIlErQpEWUZ0XLkBs0bE1CZh2bYWj4psHX+H6d8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XZqDlXW6; 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="XZqDlXW6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E370C4CED1; Sat, 7 Dec 2024 00:14:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530461; bh=+sl1kmIZv+bgkP6TtSU+wnOmA94Yzgk/n4Ipu5Tz9zw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=XZqDlXW6dOSDUXb3qsEVBP/6BZnCDXgLZ7+0J07J3TSo/BymDd0X0+pY7FcWrwkJF ycThbF2poFkEjUaM9wEgmgC4JrKUwDUyXZ8HpKxSDBJ5eAB2WSKn3gNtiuRAkjxh28 3f0qRUvr/GavovkV1SnMTZe2L/GcAIbBMgtOSZz0KyXrJiMcwvBUJT6WUhs6Y5adO7 P8/2t4oOhv2aF0R1pRlLlEtO+LQw8WRGP0ysY5EdPSOIqCvJi1RHrQ917+cb0Slae2 dx/NUTOsus1fPM/6xm0LNva6B6ph2mXy7DCKoUSd1u6Yxi8fAOOkd+rWhM6/atKQEr MMx2sh1QQEA8A== Date: Fri, 06 Dec 2024 16:14:20 -0800 Subject: [PATCH 36/50] xfs_mdrestore: restore rt group superblocks to realtime device From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752495.126362.8968721228760590908.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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" --- man/man8/xfs_mdrestore.8 | 10 ++++++++ mdrestore/xfs_mdrestore.c | 58 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 57 insertions(+), 11 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 c6c00270234442..9bc99f5cb82611 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -19,8 +19,9 @@ 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); + int ddev_fd, bool is_data_target_file, + int logdev_fd, bool is_log_target_file, + int rtdev_fd, bool is_rt_target_file); }; static struct mdrestore { @@ -29,6 +30,7 @@ static struct mdrestore { bool show_info; bool progress_since_warning; bool external_log; + bool realtime_data; } mdrestore; static void @@ -200,7 +202,9 @@ restore_v1( int ddev_fd, bool is_data_target_file, int logdev_fd, - bool is_log_target_file) + bool is_log_target_file, + int rtdev_fd, + bool is_rt_target_file) { struct xfs_metablock *metablock; /* header + index + blocks */ __be64 *block_index; @@ -325,8 +329,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 @@ -335,14 +340,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"); } @@ -381,7 +389,9 @@ restore_v2( int ddev_fd, bool is_data_target_file, int logdev_fd, - bool is_log_target_file) + bool is_log_target_file, + int rtdev_fd, + bool is_rt_target_file) { struct xfs_sb sb; struct xfs_meta_extent xme; @@ -424,6 +434,12 @@ restore_v2( sb.sb_blocksize); } + if (sb.sb_rblocks > 0) { + ASSERT(mdrestore.realtime_data == true); + verify_device_size(rtdev_fd, is_rt_target_file, sb.sb_rblocks, + sb.sb_blocksize); + } + if (pwrite(ddev_fd, block_buffer, len, 0) < 0) fatal("error writing primary superblock: %s\n", strerror(errno)); @@ -452,6 +468,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; @@ -481,7 +501,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); } @@ -494,20 +514,24 @@ main( union mdrestore_headers headers; FILE *src_f; char *logdev = NULL; + char *rtdev = NULL; int data_dev_fd = -1; int log_dev_fd = -1; + int rt_dev_fd = -1; int c; bool is_data_dev_file = false; bool is_log_dev_file = false; + bool is_rt_dev_file = false; 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; @@ -519,6 +543,10 @@ main( logdev = optarg; mdrestore.external_log = true; break; + case 'r': + rtdev = optarg; + mdrestore.realtime_data = true; + break; case 'V': printf("%s version %s\n", progname, VERSION); exit(0); @@ -587,12 +615,20 @@ main( /* check and open log device */ log_dev_fd = open_device(logdev, &is_log_dev_file); - mdrestore.mdrops->restore(&headers, src_f, data_dev_fd, - is_data_dev_file, log_dev_fd, is_log_dev_file); + if (mdrestore.realtime_data) + /* check and open realtime device */ + rt_dev_fd = open_device(rtdev, &is_rt_dev_file); + + mdrestore.mdrops->restore(&headers, src_f, + data_dev_fd, is_data_dev_file, + log_dev_fd, is_log_dev_file, + rt_dev_fd, is_rt_dev_file); close(data_dev_fd); if (mdrestore.external_log) close(log_dev_fd); + if (mdrestore.realtime_data) + close(rt_dev_fd); if (src_f != stdin) fclose(src_f); From patchwork Sat Dec 7 00:14:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898130 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 27C8633DF for ; Sat, 7 Dec 2024 00:14:37 +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=1733530477; cv=none; b=E+rMgrhfY+S+L7E3WyP5L0CW/RtqGhL8DAVY+Vin+iKQAHp4pro0dNg4ZH0n9xDaMmd8CSH8beO8qp1cH+t9mT15BtaeSJl8A72fD3Cufmi1Wy4dudNFfOeDRdxqcMWp9B6XOk3QCjginucTCGQUInUTWWPLldv5DJGfJ3XWaN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530477; c=relaxed/simple; bh=zT+E6OCWeudgHt9lgvzfPosuSo3tm0/fKcUBY+KgI3Y=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KRyPKkZha/YS09iOyf1FcMYOCMpfcEok666Dmixsh529HnqSz6Tvn2PkK7YLYrZVv6DqkCheZl4RDK3ms0/0G9VQYEGF1HZF3JB/xoyr1QBIsytifpxWh17FBmJuHgmgEsyehTsS3DP2j2p3D2pSbkh6KNs0R1bmVtMrUeo6CTk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dAPthBCx; 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="dAPthBCx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF759C4CED1; Sat, 7 Dec 2024 00:14:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530477; bh=zT+E6OCWeudgHt9lgvzfPosuSo3tm0/fKcUBY+KgI3Y=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=dAPthBCxS9KhOxMkE67HZwh/YbIzvmHUlOmE4NrtTMKH1Iv8JnRET/pubQYI3jyFH s9DKJLJZsCBWr9Ntb5hpbskndQZ1hV0iGrYfNYdgPwFCyLhG0yW+hweG3IeFgXOWg/ y5J/cHWExo1kSO0zCwUT65erxoA2YoNfFqvPgcdbmIt+YM3bJ4QmQ9wNrhYhnIGswa vXMC26gl7lDHHu5YwAw504ymStGI4WdNXWfoXQS0sdGFGi7Z6k9Kd5C/t+0equm6iM BCLP4KMgGgw/D5Iqt0GJkSfPrLqO4ZX9A/GjqjQFEsv98MPDpRXIFb6g1/Z+AMxwNg 8q2mY+N6CyF+A== Date: Fri, 06 Dec 2024 16:14:36 -0800 Subject: [PATCH 37/50] xfs_io: support scrubbing rtgroup metadata From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752510.126362.13394045053539281164.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:14:52 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: 13898131 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 0F6A2196 for ; Sat, 7 Dec 2024 00:14:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530493; cv=none; b=IqfIFDHYIi/WrC0q4WMEdmtSfOVb6CDqqi4/X3FK38znEIzpT7njymXRRltnwz/6g8hew0plLQnxNBaU1WdRzPDyj0Sj+X5RVyLpd9fiQgoSec9PgP+FJIejCr+ULaTMzPtXd17YGksTpi3i2ttCGDSjtAVfy7RMyfGBmc3m7m0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530493; c=relaxed/simple; bh=2cuu2UUfHmmcZPCgm1HX3dXqr21jX0koMhOSBu+vV30=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=f0SjRN7DSqdtUv0VmaGnjkT6Hs+3t/R5OYb2HKFPk3r1XPudtKjXbLhS/CFvoUcXXEbd+7XGEHQSV1TYH658dbB/Q4cR4fdJyYze4YbpA5rmbSttlmynnKQY+N3tLM0FLxCWhY5ke+b0EuOfiC4K+ghJbUSaV2OfJiVC2jJnxFQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sTvmqRXz; 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="sTvmqRXz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BF5CC4CED1; Sat, 7 Dec 2024 00:14:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530492; bh=2cuu2UUfHmmcZPCgm1HX3dXqr21jX0koMhOSBu+vV30=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=sTvmqRXzpi7qRLsAG+LcGjjGm/Z/vOU2jSbYQuQrdJ9GVgqSgLdfCbTTnFlyeYUIN TN9JjZgsZiBGBcpR77qBquJRSDFQ1VZC90g4aitM3EU0BCeInwzSh5ejLQrqVfkA7d QOJQPmV/Dhk9LtciLVp5NtBw4FAbPtxDxVHfK2VgrmTlPANT/YJx6XTPmcTMgq2KJf STiAnYVA9D4Q/MuM1h0DgCAu7UFdDvzJactAOZCA4eW7tNlkSpmGgcnNvSYe71G8s8 fT4nEWTKFohX65JYAoVMXLEh4W+RFtIzKcU+G0k2x5/mXmRa+8CpQc/UTfFd8c9Cbv yxPQqfDaA3b/A== Date: Fri, 06 Dec 2024 16:14:52 -0800 Subject: [PATCH 38/50] xfs_io: support scrubbing rtgroup metadata paths From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752526.126362.1330837670564192968.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:15:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898132 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 9FE0E4A32 for ; Sat, 7 Dec 2024 00:15:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530508; cv=none; b=OfvgnhdwtHJoGh529qh3zaPEvG6aTVu/3XIQWDPyFncqv4GMxzk2v4i1z4gM/qPGaM4zM/i3M0KO/P/IBAclDiaNE/v3wXH5yiOAYs5cfaxYY98y4tSAxg1hzXqH8KNpbBXAeCT3/wnTGDyyR5vtkcSk56dvnqlSZjqbopyeSw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530508; c=relaxed/simple; bh=eFVyV1m3fWRsqrjV1eHQXJnAiit1jGjeNMGyFMLM1n8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IMG9T1PbQHp3fAjyfZlHBZAyD5SJc4H3NYn6URLGWzguAvX9szC3by2pQ5j1lncwLSdnt+2r1g2FmD2ad13dzaMiha7LjTZHX7NEunbTG16VNbOkaNQgI1fO+ggFBoEQkTi4k4UO+reQVI2ObMHgIkBwQHxaJc5oMTwXnQc6xBk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kt3GpnQd; 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="kt3GpnQd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35DE8C4CED1; Sat, 7 Dec 2024 00:15:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530508; bh=eFVyV1m3fWRsqrjV1eHQXJnAiit1jGjeNMGyFMLM1n8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=kt3GpnQdmlgZkirpBas8ilcZr4Jg7gm17CWzpNIItl8Y5/98LEth+dMSoRGezFHYW sKFGhXRru63SCz81eSzq7IjF4/FkwlNCHkX4hhwEzkp5Sah/HxEyMwBtOPZY51rrbq 247wwnpkXCYnw/zoC18SI8fTfiU991OOQZwLOnZJQGUL3VEG0+0QZ2iD6j+m95RNQa 0vhgQ0/D2SBnZ8tr3qKT+upZN4swK38Vvq0S2+iXQVsAC8OKxQhx7m+L03bsgEILdi xWMf9YKGcFzWjYw30aFtmrSNiDrAnAiAq4AJ4VedvfdFdPqHAezFPtVDbRyvc64RWZ arhbbo0my3A5A== Date: Fri, 06 Dec 2024 16:15:07 -0800 Subject: [PATCH 39/50] xfs_io: add a command to display allocation group information From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752541.126362.17388723323168247273.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:15:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898133 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 5741B28E8 for ; Sat, 7 Dec 2024 00:15:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530524; cv=none; b=ZPJIC+zmHlkJg7+Q190Ms6G/GX6wfWAAtHC2+q+FX3hkUlAwc/gOkhCyTlU1GQ0yN1GDlmcEa0PfwlmJrHaKoBEAcznKjed2BXDNclrtDv3BY4JzPAwqgEIi9Bye7mWFzx3/FOCiOMjN8Hayujo0t2KoG8PB8wXESjnmyQcoOJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530524; c=relaxed/simple; bh=2QWnr4ujnATCq+XlEsclMdQs4bWZfpJQ+V5c0eLWqOc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZtyATY9caC7Les6CTjczzyUhKHXcEGM1Qjol3S7Z56we9VqWEj3Fwsbtj7bFzqQXWioD4gf5lQOmGS2hPSIH/eNZbHVplZdvRdlM62NoSwlnS+oMohFuxgmJMHWfBCIFtflj10ZFbQZyQkUSYyH635b5hp9ih2bRRsXX7PCi3Eo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W3/9kfh1; 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="W3/9kfh1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE5A6C4CED1; Sat, 7 Dec 2024 00:15:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530523; bh=2QWnr4ujnATCq+XlEsclMdQs4bWZfpJQ+V5c0eLWqOc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=W3/9kfh1oL+yvBPUWKp9mIw8jYw3rYItwpekEDGGyhwYn2eXsdy0jY5ME6UpkoF2m yhBkwlNAWYC208LRz2+G6mZbybD+I+1JLDh9sA8OHNGr3aqaDDlNuOlt6NKqgz8+H4 cxs+tPoC0mSREMGDgfO3Q2oYuSWDwGspcu4K3Nb4ckj3VsnIsrxy9KI3pYbEH8UBpb bUGCQqBZ/e4oDwgzcvJXEz3PpwgFqpQxY41yTRQvmnKes6f0GRi5MYHZRGg68KpMPK 1ScBdIoa4i9jBFkG2lDT1nPGHwFEItfgzbTsVNNxbqnqp+ZgFUBCelSK44VesIBJu4 vWQS10TQaJLHQ== Date: Fri, 06 Dec 2024 16:15:23 -0800 Subject: [PATCH 40/50] xfs_io: add a command to display realtime group information From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752556.126362.1974525931833042170.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:15:39 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: 13898134 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 DFD66139E for ; Sat, 7 Dec 2024 00:15:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530540; cv=none; b=J17xjSDpbGJNzcPibhVb4HUtjRih2CpQHvcgRFueCPhI+LWbIxj+kx1GR+Q0gvblGlMc2wvpA2Ibb7yvfWckqbvLpXxBaMA97oyXrP7WBW8y6POiV8t/g4tnfGYxF0HwwJtbf3dIeC+tO2K/GQnE1BPIXEH3QzfnC/QYs4s/QRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530540; c=relaxed/simple; bh=xLZS5RfCx57ncrOTCJQPFMeVwKvfpth46i9B1IOJE50=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=M/rMy16OXF2rUxhyhSQmC7qhRcPXNHPXKUw/T5SaBs0a5lrnXG81aXNhYgbv16MLs/5XxRE0e2coyB3juGpSs0fqia/rmyOKAxfF/jXvz6Vvg6hvHAIZ3m/HyobHbT62B7/NrVRD06LAF5MDq2xWCiPoJ27fgTvIaZp2zGpaM3k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lZZEuux/; 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="lZZEuux/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BD21C4CED1; Sat, 7 Dec 2024 00:15:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530539; bh=xLZS5RfCx57ncrOTCJQPFMeVwKvfpth46i9B1IOJE50=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=lZZEuux/Qf+TukFXDS1SAfb4Mw4WPcCkSTuaHQwwzQdXOpyIIR/6fXXuKnJEA1ZEN v/qB89poNYhvoF+GxaBhBvQI2zJnXLS//g/p1z/57Vg1u3hdteyRZayqw4rF2bSt3p OQl65V/aii5SBZVEa87hBPgZOJ6dY5tCTEWMI5ANGPNebnk7/Z2LTGYGY0QJRLGuLN 3W3hMFJy+rZLCG5OkCTUvVBRIFrtTXbt29ZnqDkZ8NP4IbZHPcv++yFZSJ4xerqpxE uc8Fqc0PmAw2fzdcbmvw7XXLHVoJPxgJPr6LDgp13fOLkfVqGcyLLt5UN2Xl1Gvypa ZHPNDqzBIT9jg== Date: Fri, 06 Dec 2024 16:15:39 -0800 Subject: [PATCH 41/50] xfs_io: display rt group in verbose bmap output From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752571.126362.12918164461473948684.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:15:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898135 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 880A9139E for ; Sat, 7 Dec 2024 00:15:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530555; cv=none; b=c2SkE3/P7kjlPLZ3SeIhF9y0KmUbRRhfwW52uZHtmCSVSn9ZpK/xEU/m2Dv3gkRqNRxQNivXzrDZvjCsU/Wkev2VIG59osEFR2NN4wWQ1HEe+3hAESjjg8EHYzYKChgRF8nCvUhb4mcL2+8rJLFdEtiMcJUShb1sFEmjm6GY6F0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530555; c=relaxed/simple; bh=4tZA5FKyFxTQOcRRrILNuEM+UdscBxJh0rXN/1xZ3/4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CVeofVagiaSARE52OXYMoxojtyzpbBDhONJoQT8vxg2f6Fw9FUeUmkIg2sQkyx5q7wt7+8Q8RoZZG5bt2lPZVgox1WaJrl0HG0luxbbRMR3wT0l1U2NvHGyMbArI556SyBL5+5LX4Zx85F20UdjE44pA3rO3692FCM5riLJ+qbo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=c506VS7A; 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="c506VS7A" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0BB91C4CED1; Sat, 7 Dec 2024 00:15:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530555; bh=4tZA5FKyFxTQOcRRrILNuEM+UdscBxJh0rXN/1xZ3/4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=c506VS7AHB59BPJhmgB2Uh6jBdwwqopz0nv98NbkGxBqb1OjfqN2UOQjiJWvXVshB 95Om84yJxHgD+yGPySp0fAFSQ8uw/x5nguTZeLmxxRyQKeDJ6Z7cno/ocLJbhSIPMM NG/FBIY85eMFVtkpQtR5jmG16yPvDOFgUkHLvy1+l/2byM9Se1EDJpnNZTIkfKn75G HZrd4vAtGt5nDB6FX7zj3vyPZckaTZkR4DT4tnAArhI234/e9836oar5lischSwKfb oXxaaur/GV2iRH8d1jp+s70wtGpEU32MUt9rS2Gkh+ejj6MpYnirva477hYF5aDDpK DiYzEjgxw1dyA== Date: Fri, 06 Dec 2024 16:15:54 -0800 Subject: [PATCH 42/50] xfs_io: display rt group in verbose fsmap output From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752587.126362.15499339908546372305.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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..545f619f5e1dc1 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 - (agno * 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 - (agno * 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 Sat Dec 7 00:16:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898136 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 1E7F7C149 for ; Sat, 7 Dec 2024 00:16:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530571; cv=none; b=cBl0iJbmE02QXjFkIGUacVrcHS7peTUfn1psjblv+hCyj0VeaHjZeqJrY7NCx0uet/T2deLotaN0C+ZpKHmWXhlxI9aKg8uOTwWIW8dIiyxZmjyX+8NNZVTaHGbe/a9d82wKvxahd8Mg/dDdK2uIXoA/L1QiePgCE2kBpJxCqDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530571; c=relaxed/simple; bh=LjjLHmLCsEG0ofh24EPkiqD8PgP4jIQr6Jrf+s7dT9k=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=D5uIIxNww7csQ9YFtdQZ8wT+mjdTWETtDyD50GQsH44mVQ1WTV8z0hVOAdAM2s4caoZmw5ylJgUYWzjYT1Zq0jVu4WUdXnIYxP0Y/8zkaJuCtCIXtj+4yU25DFXEr6zi4MSndG3nGDjEkBWQpv+dk7x3xkd3vaJm6rxVkVkpehY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jlyD3GVc; 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="jlyD3GVc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A433EC4CEE2; Sat, 7 Dec 2024 00:16:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530570; bh=LjjLHmLCsEG0ofh24EPkiqD8PgP4jIQr6Jrf+s7dT9k=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=jlyD3GVc1egqbSesC4GXEaenyRRwWPsoe+Gdfutg7yzaxyOXOoSorwNXJpGVy1EiP Nw8Drma+bbdeN4mifjEij3va5kPlXygj4DN9HyUo+6/yhpKw+ZtkdZ0VYi6FgUwXa1 xLt94Yn8QBJ9+EKZsPFwYJHyqjzD7AGISTr2Ylor18cEETiL4LfwFyZP3lWLE0xog5 28g/TRZmnqkXW8sw2XQL758IXx745pjm+khdjU7R00IYMe7Qztfn3+pKhBLbW4ussA 3w7FPNOi1Lg7c6TCARu9+Ff4Sxx+dJp0YGsoQlEr4txTY9bzyyUBDkwVSdRXcQP8zo 5mlOlteEzWUIQ== Date: Fri, 06 Dec 2024 16:16:10 -0800 Subject: [PATCH 43/50] xfs_spaceman: report on realtime group health From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752602.126362.14398852032899348325.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:16:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898137 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 C28AC4A24 for ; Sat, 7 Dec 2024 00:16:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530588; cv=none; b=HH0gYyvtBL4iePsJaSVX32yTVVYJWqC+Ugh6av0obPyg0IjGY99u87h4JSYeyLcTYoaIgWO5SRXH6ab6dRz0xjrro0Da3PQCHs5eHp4oxGWqez6Ary8nQOA6iIAz+tMdJRkvoCHJL3Kq3IxC6LnRP9itcrtgY6hYDxtzCU8MGy8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530588; c=relaxed/simple; bh=8M+fQHWxASbs+rsjPkqBKtD0cOQagWjYGXz3BgwyCcc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YBFdxp78CZYBCcMkEZN0pCNXFAPmwxtQ0MUSEIErnUgruEprUMg5l30vUk65eE2VXyH4dQz37OB2XeC1r2S/IsEii7ezw6q+tLVywwxLhMHSjnPJ7+/j/4c0z3WQyKOQCJoQHqTK8l+fnoj38IqyXzLpJbU3rKkMcUKFDZn40DQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZyJnuLjX; 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="ZyJnuLjX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E3AAC4CED1; Sat, 7 Dec 2024 00:16:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530586; bh=8M+fQHWxASbs+rsjPkqBKtD0cOQagWjYGXz3BgwyCcc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ZyJnuLjXdJGwsbFljxs8MEcQ72jfyeJgyTRMKcX+ScLx8qI7r8K9CE15FVu16hX/x Ojhm98HsYpggo31scZJPTTJg6r0pjZGVeXop7hfzWT88L9wL7zgvdzGfbWbgXASn3y nlHuXmWcF7QNitAc2uYfkE0AeGyTVBR+ZrIoK3F3li6OnXmsKw81q4EWxF/IaQR8rC CMUzMV179EHMCmQC8r5ScSgkqFjr8VPPtsW3QpxDRsrl4cIQvcDqfCXBXF8rNfliG9 an9lGmVKD/YHeroS9apNK3XhaX3fqzm5qu7jFDhXnoiPcvszxKNhfqTbJTbNeN/qvt xumhJLnVN7Nsg== Date: Fri, 06 Dec 2024 16:16:25 -0800 Subject: [PATCH 44/50] xfs_scrub: scrub realtime allocation group metadata From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752618.126362.9145973725226791141.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:16:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898138 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 F2FDD7482 for ; Sat, 7 Dec 2024 00:16: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=1733530602; cv=none; b=RjRnd2QiFwz//+k7yC23iP59V7AKJboUUND9/hJi8Pdzno6A/yCO3TcYG+QiYVXEx+rHMY26NhdhhXQcnK43cG6CQ+Y4Vj4u/WvImDH0pQgdPaIH5IRW2HoaG2BOtTAopuCiS0qNW2f05V7R9pjRbUyv8/Px0c0lFH0cOdxCUH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530602; c=relaxed/simple; bh=6oaT7ZJX8Yinv1Q35SykGGJMtAXS/4/h9hTpeNjtAeQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MFkDoM03LUEQvepRGQyfbb9O/enKP6cSawKKsvm3ezcVvng0E5L+EAuccPMG5Owe2o5twJdYV9mlgl1yQIWwFji3/pjUTw1c/3acUYHaysVJJJZ+fEG0u63I89dY2WNzx1H/XYcUOxx3G+ah1Yr1k5B+lCobIforM40R0DS7jW0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OfJntGty; 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="OfJntGty" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1BCFC4CED1; Sat, 7 Dec 2024 00:16:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530601; bh=6oaT7ZJX8Yinv1Q35SykGGJMtAXS/4/h9hTpeNjtAeQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=OfJntGtyGpeu0GS4nHdD4AZsKpLCBpbuOGT06cEgyaVAzezSj/6o2k3PQvgDkulFX adGbreuaNX+4pTdCfjsjUl2QzGExuLITkwLJgDtPDHnPReQen1iGfefYOnfL5vAzjY Dn+Bh7rSjGXA9z39Mr8YNLaVMjvtFdQreqr5/KFvwgHPYPlpLAFjxBrpNER4TzNVRO WQ2yEeS9i3FsP1yh2hnIAd9YyQYINgmbPAYmAv4HiaHXViZ5rMCYS24xYNRz8/w6cr U+k37VFX5dmYJKRhotr/qW/NW6sxeBfxMZFvqs79TLsmuyH/x4y/LNw0h6TA5Etw4n CZFM/dUQ1aeNA== Date: Fri, 06 Dec 2024 16:16:41 -0800 Subject: [PATCH 45/50] xfs_scrub: check rtgroup metadata directory connections From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752633.126362.18289089881619449643.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:16:57 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: 13898139 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 E854D2563 for ; Sat, 7 Dec 2024 00:16: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=1733530618; cv=none; b=F74U6x0XUFInnd0rIPrATifWkXIFQx3uAJV5rkdb4VW6Y49TLfLy5oiQvx6vN+frZOszUCV2qA9L0bG22muPWEAlnQXfiSkmcIzUmD1kJf0DBZdzflsaVThlWc98s9CKBZlVyE8H1gUdlpJ/tZa31jLbd7Agi4W+xk+aQICInaI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530618; c=relaxed/simple; bh=70FzFzhXysQRVXEv2NrcZvFxdZKKKCj+J7wslTu5Ap0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sINZG3YbxiGT2UyAQ28sUpN9dO2PmpCQ/+dbcb7fGIC1vW+ooGBmwwMHMdcHVL5w5EJUzrhkjTNaAv2M0aDEHPxZqUxrs1MbFMAFfPDl2XHBu3wz8kDTOMTsoFGStm0e4p5EXuRg3DggaIN8FTWIi/c/aYAul82yYUWJQLgfaOQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nk72k64Z; 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="nk72k64Z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7405FC4CED1; Sat, 7 Dec 2024 00:16:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530617; bh=70FzFzhXysQRVXEv2NrcZvFxdZKKKCj+J7wslTu5Ap0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=nk72k64ZFq8HtfYUSj77RJMv/OpbUtyHXcruMJe62CHUNq4vhHhQoMnnj6hh0M0v3 Jt0btRzrVMnroFufdD16EUq2y5KrOdsWg9PhNxz3TRmi5ANO/R3nQZqPH57v1+Zsoj ymm9vz5EGxrR7gOhU/Ga2K0ayzLsIwXeangDsmwbYIIgWeOFzmcMUBE0MEHM/s+CKY GQFvwvD+3hHCDm7Lh87LFi05b0KVCdGjaxfTk5Mqd880qKhFJWNyUW/30fUtBFv+Yg W36/M5cEQPimn/nmNZO52kxJT23Jvp0CHDviLn2FT9AQA+x/+Ml/rNY40Pcw30p4q7 KgO28Alt7jdWw== Date: Fri, 06 Dec 2024 16:16:57 -0800 Subject: [PATCH 46/50] xfs_scrub: call GETFSMAP for each rt group in parallel From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752648.126362.13619225422874515961.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 | 72 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 8 deletions(-) diff --git a/scrub/spacemap.c b/scrub/spacemap.c index e35756db2eed43..5b6bad138ce502 100644 --- a/scrub/spacemap.c +++ b/scrub/spacemap.c @@ -128,6 +128,45 @@ 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; + + + memset(keys, 0, sizeof(struct fsmap) * 2); + keys->fmr_device = ctx->fsinfo.fs_rtdev; + keys->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( @@ -208,14 +247,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) { @@ -232,6 +263,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 Sat Dec 7 00:17: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: 13898140 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 CBB28322B for ; Sat, 7 Dec 2024 00:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530633; cv=none; b=e5whbNRJMKGJlzykZ/GBMkqGx76XIPSq4Pg2Z+8L2Q4KWYaev6KKn6A0NZ9+bvH+XM3NqHVs/lb+WNrz9uZ8r25qtCksUtm/K/eIfL3ES8XaqhYpBNOWZXQ6Da3zVBLv+ea0rTjwCoaEKMGMONZ+el/wDkN0CYObnesyHgiHwIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530633; c=relaxed/simple; bh=xnBhOAryebC+Vwdwnr/jisnEmdHDTN7am1RQt/mtWIU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bpbPMp7RyGzU6jM7pbPfAbC7WydTXlVPIu7AJLo7rzToRzwEX3XOhV5F/3nCAtVouuVqPFr4rc9LhpVJPT2m5FzebAY3oP1yMuRtPTfdQKex3oJfbrX0gb5zkiJXn1SjdB626tD+AVKtLZEh8EH6n63sLJHFJq70UkEzzWr7uS8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ORjVeWrG; 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="ORjVeWrG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 469EEC4CED1; Sat, 7 Dec 2024 00:17:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530633; bh=xnBhOAryebC+Vwdwnr/jisnEmdHDTN7am1RQt/mtWIU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ORjVeWrG+rhzTLIyo1N/WwOj2/M2ZQ0vqDa0bz3uwF1WvRv+tnIs79cnRWVNHp4od WKDqXqx3yMSlrVYtzFTCyOedcu42T3M1XzCaSmFa56PQubzMyuWFqMGsn2RDh+iq4l jjPx47tpru/qV9hWQC5Khs1tNPVdRKrH1CM1rvoaDMikmpE1qOz+7nyMoYlshJQ77R 15QikJLWigVbLHTQFJKqj1HzrEL2Q3I/nGtReeMSzEN15bqyl/YlXTWMMuHrTJkeq1 SYy0PD95SXowJnl6VGJ5+nvR+baR5fQc4TfdaYdwGp3avkKvbc7AUskp8SwrE1IxIZ TAxBZQLmtr+ew== Date: Fri, 06 Dec 2024 16:17:12 -0800 Subject: [PATCH 47/50] xfs_scrub: trim realtime volumes too From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752664.126362.6074533714975702330.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:17:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898141 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 67EB93FF1 for ; Sat, 7 Dec 2024 00:17:29 +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=1733530649; cv=none; b=VAXGr3UUu4h8vlz/U9aAlSb0ol42DwIRQItd6Be1Zci8fSO39ekUQIlHkbCjCrsaH96o6S+WSp5Nmc9JAlIQX0AgjHoXuT2YDK6OxAXgSh8HZeun9zmklWTODpnuqyc1OW0D4XjkOjj3XqsFT6NlHgTUbvLbBtLhI6juEGeLdD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530649; c=relaxed/simple; bh=xopfR6/SZuIlWNWqk66CQWomvFzWkupOKBA4581JZpw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aGv/qGhAWeAjn67lIEmFqU5BmfSvZJsF+CEB+cYIxo9hBCwcXG6//6i9nXbav/qnRzxDR0ubusuW9Ibkwod734r50KHuYn/K0McHyzHplrtV+mlocrgXv3RmkCD8buicVuXQbPCdohMB//k3u08ylfM9dbQMCG0Zih/DCnk9fVQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EwN+YVmF; 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="EwN+YVmF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0683C4CED1; Sat, 7 Dec 2024 00:17:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530648; bh=xopfR6/SZuIlWNWqk66CQWomvFzWkupOKBA4581JZpw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=EwN+YVmFrJ3/eVkJODSWArrBd7qRLOcZMvcEzET5dQYyonO6CaJ5qjYG+X3xAcSDc d/TWQ+gtKgyU2HiagtyTKbOHamXBFoqrNDbGW9VYUnkvv7PdJFiv9/fMBtZJzlamlC hk+3JqC47JyLlr0SgR9oPC3Qw4IdgiTHoN5u6WJXKqfJgKEIBjBPtQIsJnPtNxViOb Buk49P97D6j3dIAxw/x/3yxqozz5MJbfWXTMsGdnTr/4lHXQXCOx1k+YnYx4sB5qmz q4U/3Ypgv6zRVVIm2zjgAcX7nNBYOQNgKiPbNa73SC42ghO7op1NQjPoyic8EWaIJH uHutmL8ya34yQ== Date: Fri, 06 Dec 2024 16:17:28 -0800 Subject: [PATCH 48/50] xfs_scrub: use histograms to speed up phase 8 on the realtime volume From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752679.126362.5625686525882316849.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:17:44 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: 13898142 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 0B9024A1C for ; Sat, 7 Dec 2024 00:17:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530665; cv=none; b=Cs04KKjndXg5cGHliSC+NvZ4xRwj9pCTCF6BbkkQMWBs2ix3D41rCVmtUiy56vlHVYzzScKzM8SCfLnjWTzV3UAx94wQ/LdbSSthk4p8AhDVyYsXG+jLJRvg0QSi7WzJPeetYJDA+9llYvkbKC4dXj1ZxF9PcA697xbcU2rVTpo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530665; c=relaxed/simple; bh=U3qyw4cZTfuqd15KXMbH8i2VmPReWmTYt2hZWJzl9MI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JMujIVHIvCnPf9PqMpbMTAUiVN83N5acz6++ppC03Br5qwFE0ZiTugRclP6iZVGw37rB/ZcbVEp02E3ZTsKJRWz4aXqzhcTv6MyhkUuFYJwQ/weIysIpYoEXXCJ0KLEmvOP9S+92j/plOEuzl0kY3ZpkX6aBDquNX4mXu4FE5n4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=t+xK9D2R; 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="t+xK9D2R" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86F10C4CED1; Sat, 7 Dec 2024 00:17:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530664; bh=U3qyw4cZTfuqd15KXMbH8i2VmPReWmTYt2hZWJzl9MI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=t+xK9D2Rc1SbPzn2GnHmkshCwXloS+zxD1p4g53VJJJ1pAVHOe8qFNfE5CC6UO75Z w/LCeHTd4PpVmYfu/FbbQdNRm7xA+9db+SCUEHKEnSOFF/6m0C+oe22OUvcnc+yqdP OwhG0QYBNL5Km+fwG+3iFf3eLvLhVNVkkLYLD4N2xUy0o3pGtu51rmG1tAWE9Dtxph m7d9R4R6T/cE23Ok0icqeTO+Il2wJbrQxTTFxpEm+e0hBzH/dVqCJ1csTrZyBGvRaF HT89K2VcTb8qfYrk1irWQ8DlNnjqY+HQXK4ygwEEdnDAFntGqjGiwZsL7nn/GpWJxG r3plQd1SPBe4Q== Date: Fri, 06 Dec 2024 16:17:44 -0800 Subject: [PATCH 49/50] mkfs: add headers to realtime bitmap blocks From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752694.126362.14739180271347119851.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 Sat Dec 7 00:17:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898143 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 5A50528E8 for ; Sat, 7 Dec 2024 00:18:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530680; cv=none; b=chT9mxxkWwTAAIocrsXF09x1p5b/zvmnQQn8B3cMZ7VCOj+szaHoXpFhrdosRakzjCftVQ2au77R1V0TVNNL1Psg5shE1twaBKv8X/Abv3P5y8r7AV2LdEzAjwDZajBznSsO0FYcoltTmu59THHBunVO3v4ypMYZHCsSxoS0HvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733530680; c=relaxed/simple; bh=u1zbKmA9mEaGKGwAy6Gl2T6IrGPA/G/qORvIUAK3FbA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RfnzxcCahMQOxaVl/L++b4iMT4RdZASHOB84TE3lJCP+1eRd6UMtIR3QCmcy2vqAt/imL/qXOjrXR8EMfq4kPF+LLsauhb1ny5f1GQbGridjX+IubFSum+Z6OoPGw8y+G3yU7l1fh7xX32hTJs1MdN6lA6BnZMNrB2pGvln5Lq4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MDTMJ0uk; 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="MDTMJ0uk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31B98C4CED1; Sat, 7 Dec 2024 00:18:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733530680; bh=u1zbKmA9mEaGKGwAy6Gl2T6IrGPA/G/qORvIUAK3FbA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=MDTMJ0ukUVFACjqR2SCFLUU8El1nVf3sMVuzfABmQls5LN1uzAj5l5oMXK5/6PdvP /hTGEkBg7KEYpmfb+sxX6pVAZyjMdN6dGa9q1tzEI+UkN3MD114fDMgt0HTd/XRXHs 2YNHDVza9FzncnTlnsqk4c2N2Chl+lZrQFhBF1Qpn5BRfe195m6I8kqthKsbvpluZg 7Sv/J6oByDurwTCp3p065ksO/ZFZZA9zSUlAorR498aS6Fe9my8juERBjyTdOZAPmk H6b5cXbIvji2V0QQy0TxL+GIwMOxSL0UyKEGkGDAgYYUARLERLiHuq462E28S2VB7q jwMImxxAL8nXg== Date: Fri, 06 Dec 2024 16:17:59 -0800 Subject: [PATCH 50/50] mkfs: format realtime groups From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352752710.126362.4060220545378050721.stgit@frogsfrogsfrogs> In-Reply-To: <173352751867.126362.1763344829761562977.stgit@frogsfrogsfrogs> References: <173352751867.126362.1763344829761562977.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 | 287 +++++++++++++++++++++++++++++++++++++++++++++- 10 files changed, 449 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..c6a15bd2cb1e5e 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= +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..cd00f3b3bd88f7 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,8 @@ 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,\n\ + rgsize=n]\n\ /* sectorsize */ [-s size=num]\n\ /* version */ [-V]\n\ devicename\n\ @@ -1989,6 +2014,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 +2562,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 +3255,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 +3298,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 +3545,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_nonpower(cfg); + cfg->rgcount = cfg->rtblocks / cfg->rgsize + + (cfg->rtblocks % cfg->rgsize != 0); + } else { + cfg->rgsize = calc_rgsize_extsize_power(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 +3881,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 +4281,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 +4342,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 +4724,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 +4973,7 @@ main( */ calculate_initial_ag_geometry(&cfg, &cli, &xi); align_ag_geometry(&cfg); + calculate_rtgroup_geometry(&cfg, &cli); calculate_imaxpct(&cfg, &cli); @@ -4804,6 +5074,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. */