From patchwork Mon Dec 23 21:37: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: 13919233 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 BFCD838F82 for ; Mon, 23 Dec 2024 21:37: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=1734989843; cv=none; b=VwHPEGg7OQQ82eMQp5pZtm7J0bvI9Za19ByoOzgM0Swxyr9C1fqMIaSPcIRMCKpuqYVOiAg/xBg9QU9DwAUqj5bV5ebrQYSy9LRgHq0i3HzmJStdssu78JtJW0WW0nnB02i+f2H0mEybJ0RxqAiImd23VP+V4aABPQh7MWaUKxk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734989843; c=relaxed/simple; bh=wZ6mx4jJY7mUN1tTAgIeW+rjz9bTyNpkaT4srN8RcTg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MlsG9J765oxu5Zg7kcnmDsWu0JrbdjcaslpzwO/NZcwNfp6LnDHz62isBH1UvMe0c/Mfqz2I/iXcPqUQuA2V0RNjU23if2PFX1iSp0uEhn1ZAgO5ev34ypm1pQVZBYu4rCwPlk7SesKsBSUdJ6AGrxXEZu//3DwKIuKoL3v0t9M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZEcLxJbn; 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="ZEcLxJbn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97FBAC4CED3; Mon, 23 Dec 2024 21:37:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734989843; bh=wZ6mx4jJY7mUN1tTAgIeW+rjz9bTyNpkaT4srN8RcTg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ZEcLxJbnvbDUG8HsFe17PH9VIddu2IoA6k++4vP2UDx5fB1AlytOTR0GJXjTXmpKc NTJiM9fsFaKRcDX1ajTUlUdxfKsWIeGYc9OXthnB34UB5n/t1PPMGPZxmAGcJWpKhk YxrEWDOgIH9mbLXHJmGJ6yD3y6DTWmPgds+6xKRQN+PYBqtxDSD/xRYH8jV2xu8Zry exuLyJjtBvM8LRX4IbWmzbWa/OlNVyE6ZsSgplC48B8necnH8NCZixrpYlGpmIPtIS Mb5/DpHFMZ7hrrAu+2nYPuzX+0e1ar8oSxp5eou9QGJf5X0THFmbBOeJuI2c+JbrQ4 CXs4urjNhWorg== Date: Mon, 23 Dec 2024 13:37:23 -0800 Subject: [PATCH 01/36] xfs: remove the redundant xfs_alloc_log_agf From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: leo.lilong@huawei.com, dchinner@redhat.com, cem@kernel.org, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498939961.2293042.2074237386773207035.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Long Li Source kernel commit: 8b9b261594d8ef218ef4d0e732dad153f82aab49 There are two invocations of xfs_alloc_log_agf in xfs_alloc_put_freelist. The AGF does not change between the two calls. Although this does not pose any practical problems, it seems like a small mistake. Therefore, fix it by removing the first xfs_alloc_log_agf invocation. Signed-off-by: Long Li Reviewed-by: Dave Chinner Signed-off-by: Carlos Maiolino Reviewed-by: Christoph Hellwig --- libxfs/xfs_alloc.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index f0635b17f18548..355f8ef1a872d3 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -3152,8 +3152,6 @@ xfs_alloc_put_freelist( logflags |= XFS_AGF_BTREEBLKS; } - xfs_alloc_log_agf(tp, agbp, logflags); - ASSERT(be32_to_cpu(agf->agf_flcount) <= xfs_agfl_size(mp)); agfl_bno = xfs_buf_to_agfl_bno(agflbp); From patchwork Mon Dec 23 21:37: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: 13919234 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 B725938F82 for ; Mon, 23 Dec 2024 21:37: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=1734989859; cv=none; b=u2WdF/F1iz/VNGKFn2lmFv3ZIKm+0B4OwklzEdA657lSYfbx6JxJIfMMmd9L6OCT2qsz6ZBuCDAbtY3mvGUpYq3rkzhdb1hnbIt9JNBwjhinWd2Er8D6tD3HOgJvLSAj8LZ3cE90TSws8RTmR9m4kTVnis/958CWvEYu3hBcQbY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734989859; c=relaxed/simple; bh=O/Wz0WcC1u9YKeBp9fabWtKqEKGs0X5Ew6LDvOiWfUM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gicfV3KT3vuUEhrGOI4oVJqmPyOdDUMe5EbQw2jTqIlUKJV+kcquVDZYXT0cxIgjPqVvSDu0dKTwhzEqiZnjgfWC/xG7tTHGy3r1IXQpU0RvnO2NCvfeZsKuHz+GdDa/9vD/1NNPZEm99r4XoJhQZPBwU0fbv2VVI06kiObOM0k= 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/6GXJHY; 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/6GXJHY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C5B4C4CED3; Mon, 23 Dec 2024 21:37:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734989859; bh=O/Wz0WcC1u9YKeBp9fabWtKqEKGs0X5Ew6LDvOiWfUM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=t/6GXJHYCe/OLskVHkhCNvrq/jta5cgsqQYuYkrw3axYMa/nBwVlYoZRR+lVRQnjg EIbFh8kP/oFMwgy4K/4w8ngAb/DAwew/hh3NMHu7I0m52JsFdDxHR0DrjpGKxDzH8c EyIXqcAs0cutLsam+eNEUiQ4BX+0bnT5w70veMiX+R04nsYjqxjIKukIJnH+5HKmxL JwwMfVdxb18JPM7YTCaP0DJC7+ojBfV1/tZBMkCVZ6NGExWjV2u8rxqDgwv/3h0f9e 5PhBk8dRjtn0akhk4s7tJH+Cug5SNkAAkIr7kQTf9YtCAJ8A+tX9nDVZf1FCZhgKbX sLmx54q+dHzGg== Date: Mon, 23 Dec 2024 13:37:38 -0800 Subject: [PATCH 02/36] xfs: sb_spino_align is not verified From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: dchinner@redhat.com, cem@kernel.org, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498939977.2293042.9811398235690323418.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Dave Chinner Source kernel commit: 59e43f5479cce106d71c0b91a297c7ad1913176c It's just read in from the superblock and used without doing any validity checks at all on the value. Fixes: fb4f2b4e5a82 ("xfs: add sparse inode chunk alignment superblock field") Signed-off-by: Dave Chinner Reviewed-by: Darrick J. Wong Signed-off-by: Carlos Maiolino Reviewed-by: Christoph Hellwig --- libxfs/xfs_sb.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index 0603e5087f2e46..0d98b8a344209e 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -395,6 +395,20 @@ xfs_validate_sb_common( sbp->sb_inoalignmt, align); return -EINVAL; } + + if (!sbp->sb_spino_align || + sbp->sb_spino_align > sbp->sb_inoalignmt || + (sbp->sb_inoalignmt % sbp->sb_spino_align) != 0) { + xfs_warn(mp, + "Sparse inode alignment (%u) is invalid.", + sbp->sb_spino_align); + return -EINVAL; + } + } else if (sbp->sb_spino_align) { + xfs_warn(mp, + "Sparse inode alignment (%u) should be zero.", + sbp->sb_spino_align); + return -EINVAL; } } else if (sbp->sb_qflags & (XFS_PQUOTA_ENFD | XFS_GQUOTA_ENFD | XFS_PQUOTA_CHKD | XFS_GQUOTA_CHKD)) { From patchwork Mon Dec 23 21:37: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: 13919235 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 0740C1BEF82 for ; Mon, 23 Dec 2024 21:37: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=1734989875; cv=none; b=FDj7eejANmz4Bv+Nf+IErDcDVHJqplSFSywXtKPYRGe6+eQHK8mHUDwaudNQREgmHDooLFb/Ts/+MgrU+lzZlGuj+/3yrsTTAFk8cPuc7YZ55y4s47/qutyCL8LEIGih/N6+2LQZoWY4RBefa1fPmcmdpkC2nNN5JOlNU+l8N+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734989875; c=relaxed/simple; bh=RusH3hwlmC8YZwLJDs+aGT4z0bGD8qePX/8cbpmIIGg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mOXdKLJEYgDJQuXm20z5UO7min3ue/wrUB3a15e14QcPboln+w0dJT4JUDv3R3FNgcNt4e+xVzF5fp1ABmH+KNFfVX9B0PePfl0RseIxg+qnZyF8hrKg1QFbCKqkouxyk8CC2P/C3O6lR6azH/VeZ8c5FjCN2P3DNOCMenAU7Ag= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tDJtou5F; 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="tDJtou5F" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4092C4CED3; Mon, 23 Dec 2024 21:37:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734989874; bh=RusH3hwlmC8YZwLJDs+aGT4z0bGD8qePX/8cbpmIIGg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=tDJtou5Fo22oM520XBUyXNIFda+04Ucdo1kClUxN9xjiMBr9kRySOykmNM5/5OUHY uMFz+j7oRXUvyYy/GPYnpIAsUm9ZzaYin1Q6f5G0lGIYPkd/cyFQQt1twfA5qgQWzT k6ha/aZ6iyA1ZFpJm/rbNjyWk6eT1pADu9rXRPdAdAJUaMrZO3QT0JVHFWmeGAYEe5 kQn1VPDcGffXIkIVi5cH4CNjdpRMuoaT5mEAX9Bi9AafxepasMueN1b2FGLmSWKQ+A CwMbiY91U8zIANsAHY6ihhbq37qzf4Gci743QwJvcyA8wSGx3wR0ODrCvcUN4AyQhd JuXiJi0uTGy2A== Date: Mon, 23 Dec 2024 13:37:54 -0800 Subject: [PATCH 03/36] xfs: remove the unused pagb_count field in struct xfs_perag From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498939993.2293042.8777635963514324325.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 4e071d79e477189a6c318f598634799e50921994 Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_ag.c | 1 - libxfs/xfs_ag.h | 1 - 2 files changed, 2 deletions(-) diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index 79ee483b42695a..975b139ca497a2 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -325,7 +325,6 @@ xfs_initialize_perag( xfs_defer_drain_init(&pag->pag_intents_drain); init_waitqueue_head(&pag->pagb_wait); init_waitqueue_head(&pag->pag_active_wq); - pag->pagb_count = 0; pag->pagb_tree = RB_ROOT; xfs_hooks_init(&pag->pag_rmap_update_hooks); #endif /* __KERNEL__ */ diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index 9edfe0e9643964..79149a5ec44e9a 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -55,7 +55,6 @@ struct xfs_perag { xfs_agino_t pagl_leftrec; xfs_agino_t pagl_rightrec; - int pagb_count; /* pagb slots in use */ uint8_t pagf_refcount_level; /* recount btree height */ /* Blocks reserved for all kinds of metadata. */ From patchwork Mon Dec 23 21:38: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: 13919236 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 0AFA938F82 for ; Mon, 23 Dec 2024 21:38: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=1734989892; cv=none; b=FQmfnDmoZf4/zVD1ONM0XDpv/VHN5G4covZ7r3MW0G7je0HbcVbxv8BteP/4M6DdREqMzDByd4jcrYVEg1LKbYetbzrrUxpqNnj4vYcJnXqHbl+gB0dqcICARlyfeaaxSw07TDoilfw0z0fhAfeZe5Ykcy5dHK3B839m35S+TG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734989892; c=relaxed/simple; bh=wzEX/nLs9P9rvXfodJRgPv0hYMdp/V/3ozABeN1iW6w=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=K9Umz1tszO+Yg61a1jko+hlKLx2QX1NDVyhBO34fIIKi5QTdOyT9SmL9i+Xuj9/6oo8WOSsIm35sYfTJrHyjVFCuV/Az5nDVhZWDQJ4y+/DOqw+qU6CqS9hQjL1W5WvbT7YrFoFhdE0nrF47FNcGPmiJFVivvthT5x47DTB4LQA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mGj97ege; 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="mGj97ege" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85800C4CED3; Mon, 23 Dec 2024 21:38:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734989890; bh=wzEX/nLs9P9rvXfodJRgPv0hYMdp/V/3ozABeN1iW6w=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=mGj97egemQQ5tlxZKFaOdGXPoSTYZuGkOcXfBgBolQOP20SZiTEnE6cVLoUd0NVsb ePdGoxPstmk7abPliHAexigr0ScPIOX9fYFrO4KpOUsl4XdS8/9390f9uO+ylQmy7y zaiyTa5Nm4wrxvVnghgm3McNVg4YPDRij6p+p4Ks9/rqpBPpiAybyTJKD69V8+t/t7 eaHV3idNHiF45KYpXg/y5NEMB4SmeYsGBKHUBorOpE/E/ePLOdoMleXHmQk9XVLyxm cWwz9mnDfnHFA/kWjzf1RE/jiKwlwGFUJ/0Yh/FuxLFI8UI8vEpripCmJMcfO9ivKC +i7npmxeND3FQ== Date: Mon, 23 Dec 2024 13:38:10 -0800 Subject: [PATCH 04/36] xfs: remove the unused pag_active_wq field in struct xfs_perag From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940008.2293042.1238926203712896387.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 9943b45732905a70496fc44368ab85b230c70db4 pag_active_wq is only woken, but never waited for. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_ag.c | 4 +--- libxfs/xfs_ag.h | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index 975b139ca497a2..62fc21fe7109b9 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -105,8 +105,7 @@ xfs_perag_rele( struct xfs_perag *pag) { trace_xfs_perag_rele(pag, _RET_IP_); - if (atomic_dec_and_test(&pag->pag_active_ref)) - wake_up(&pag->pag_active_wq); + atomic_dec(&pag->pag_active_ref); } /* @@ -324,7 +323,6 @@ xfs_initialize_perag( INIT_RADIX_TREE(&pag->pag_ici_root, GFP_ATOMIC); xfs_defer_drain_init(&pag->pag_intents_drain); init_waitqueue_head(&pag->pagb_wait); - init_waitqueue_head(&pag->pag_active_wq); pag->pagb_tree = RB_ROOT; xfs_hooks_init(&pag->pag_rmap_update_hooks); #endif /* __KERNEL__ */ diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index 79149a5ec44e9a..958ca82524292f 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -34,7 +34,6 @@ struct xfs_perag { xfs_agnumber_t pag_agno; /* AG this structure belongs to */ atomic_t pag_ref; /* passive reference count */ atomic_t pag_active_ref; /* active reference count */ - wait_queue_head_t pag_active_wq;/* woken active_ref falls to zero */ unsigned long pag_opstate; uint8_t pagf_bno_level; /* # of levels in bno btree */ uint8_t pagf_cnt_level; /* # of levels in cnt btree */ From patchwork Mon Dec 23 21:38: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: 13919237 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 B16F61BEF82 for ; Mon, 23 Dec 2024 21:38: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=1734989908; cv=none; b=ovlZP6jFF4y/JZwZgMuLEHMcT2Epedb+E3Fs4CiDIklrjtOBXZv1iWaGeokvB2dkjcBRvWll/qPCrIkw08nFu/2bWMk/QtyUvVrML+7gbHCETNpLjEuzSc8YLDdLl4qdbFXXpdi5oCX+fTP81+Qsf4Td0KlM6/EBvLIaUUG03Lg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734989908; c=relaxed/simple; bh=7co+fkSe+54gIFOOWuPLxmv5igeN9Lag1EQUdVzZe2k=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bd6nfelF/H43uATldYf+iCJlsjDtbW373Ac0mVhOHdd61TRcLY2tLGvgrBWVVnTt8kvTJi6KXLitLHa2EZthxbX+grsN1YQz4v3siZexrEzG8zu20uEyRq27T3Pappit2XjW/Fte0htzFZ65P5pVzwnOkdFY/v8lSXW6K25NYbo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IDbowzKn; 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="IDbowzKn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28269C4CED6; Mon, 23 Dec 2024 21:38:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734989906; bh=7co+fkSe+54gIFOOWuPLxmv5igeN9Lag1EQUdVzZe2k=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=IDbowzKnSnX93TLs/7rek8hkEYM6bx9fU4JXHin333YxK4lLz8SFPz+Rqjm+aHt7n TIC8QHPnL8SQwowgvUiVZEP3m5EOaICqB+zqjJVka+En6gCFA5NRefozXKiO39kD+A O5EJdo6TcIB5yV/GP2aUhhnsh85Riqa+9QbzNu1LO1cRDXXUyqHqGHxmVKJ1r7Vj4b 8+V5ZE+uKPS0VSclEkqUY8uPazZVhRT1CLjltkRyqcToWKTUWUl98MI1+oVOhTBjUn UI2zSUxBN4MT1d9EC/vZqStUK2dbq8aFWCRsODemdLgdCPNsYzgPCqvll/Xq8oYGgI KcWJk54k03JeQ== Date: Mon, 23 Dec 2024 13:38:25 -0800 Subject: [PATCH 05/36] xfs: pass a pag to xfs_difree_inode_chunk From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940024.2293042.16659705325766468185.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 67ce5ba575354da1542e0579fb8c7a871cbf57b3 We'll want to use more than just the agno field in a bit. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_ialloc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c index 43af698fa90903..10d88eb0b5bc32 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -1969,10 +1969,11 @@ xfs_dialloc( static int xfs_difree_inode_chunk( struct xfs_trans *tp, - xfs_agnumber_t agno, + struct xfs_perag *pag, struct xfs_inobt_rec_incore *rec) { struct xfs_mount *mp = tp->t_mountp; + xfs_agnumber_t agno = pag->pag_agno; xfs_agblock_t sagbno = XFS_AGINO_TO_AGBNO(mp, rec->ir_startino); int startidx, endidx; @@ -2143,7 +2144,7 @@ xfs_difree_inobt( goto error0; } - error = xfs_difree_inode_chunk(tp, pag->pag_agno, &rec); + error = xfs_difree_inode_chunk(tp, pag, &rec); if (error) goto error0; } else { From patchwork Mon Dec 23 21:38: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: 13919238 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 3D6DA1BEF82 for ; Mon, 23 Dec 2024 21:38: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=1734989922; cv=none; b=D4u+Ywe+IgPo/1dcg3ErYt2KK2aChQnWiyMYkrYLvrgqaNt5bFBngjp1JhduO1pCbqJmQjn0qwl6E3VO13WaZRSar8D28GFPqU8ykHVbFwxfWcJNnbEcnpoPsAtWGeJpNAdSCqJi/LgVGb4xnpgmKm1i/BBmAjdih+4kKP4gr7c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734989922; c=relaxed/simple; bh=ITMZo6TuRBIlpJ8ab5QcwCmeMlfY1yeZh43cONYdvZM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MI6+GKXK7jz+aediV76DW/jr1vFk9wGSJUghx/vC2sVwwPUXOKYy2n3kpoGjHUq2V/SJ6fObdEzfPcaIdSMNBi8omT48vqJLDyOJkhk38GhKnONNNXfWr3lfTVwv9vgDXhrs7+c5NVx0hmUi3Y/2lnK7tUezNth+y/zP5+5RV18= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qsKLBmdH; 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="qsKLBmdH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BEFD7C4CED3; Mon, 23 Dec 2024 21:38:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734989921; bh=ITMZo6TuRBIlpJ8ab5QcwCmeMlfY1yeZh43cONYdvZM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=qsKLBmdH+bTsmeF5AfY2z5KaoGnGyRgwxGaadrrD9wL3YM6j0+8Y0bq2Jq34nA8P9 NAg5bR90cMC+uYliNH+7Wh0JStT9AaksL2q2wjYsKDayVC5kWh3l58P2OsMXgz6o2p e1xVIOnzv2vbHT9vpRRzwtxhbSeVQTzwLdyaAbIRv8WgQVQc/8zw30OeKDFbZ//ici BXi3D8jNhWNRsIEZ5V0RDTYSh65sQAmQZ6ckkgXeCEEyvjXYiIxCa49ObmXIcSBlZ+ FsKV6/+se8OiDJY3UdNtJx4nUkyGOvQ0oJdy4eLY8K90SWmdySK8Wmq8nJDGnVVoPQ 2L5B/j5bGaxBQ== Date: Mon, 23 Dec 2024 13:38:41 -0800 Subject: [PATCH 06/36] xfs: remove the agno argument to xfs_free_ag_extent From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940039.2293042.2256552049332958858.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: db129fa01113f767d5b7a6fd339114a962023464 xfs_free_ag_extent already has a pointer to the pag structure through the agf buffer. Use that instead of passing the redundant argument, and do the same for the tracepoint. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- include/xfs_trace.h | 2 +- libxfs/defer_item.c | 4 ++-- libxfs/xfs_alloc.c | 10 ++++------ libxfs/xfs_alloc.h | 5 ++--- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/include/xfs_trace.h b/include/xfs_trace.h index f6d6a6ea1af9e1..ba51419b3df3d3 100644 --- a/include/xfs_trace.h +++ b/include/xfs_trace.h @@ -79,7 +79,7 @@ #define trace_xfs_btree_free_block(...) ((void) 0) #define trace_xfs_btree_alloc_block(...) ((void) 0) -#define trace_xfs_free_extent(a,b,c,d,e,f,g) ((void) 0) +#define trace_xfs_free_extent(...) ((void) 0) #define trace_xfs_agf(a,b,c,d) ((void) 0) #define trace_xfs_read_agf(a,b) ((void) 0) #define trace_xfs_alloc_read_agf(a,b) ((void) 0) diff --git a/libxfs/defer_item.c b/libxfs/defer_item.c index 2b48ed14d67bcb..d5e075362ababe 100644 --- a/libxfs/defer_item.c +++ b/libxfs/defer_item.c @@ -181,8 +181,8 @@ xfs_agfl_free_finish_item( error = xfs_alloc_read_agf(xefi->xefi_pag, tp, 0, &agbp); if (!error) - error = xfs_free_ag_extent(tp, agbp, xefi->xefi_pag->pag_agno, - agbno, 1, &oinfo, XFS_AG_RESV_AGFL); + error = xfs_free_ag_extent(tp, agbp, agbno, 1, &oinfo, + XFS_AG_RESV_AGFL); xfs_extent_free_cancel_item(item); return error; diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index 355f8ef1a872d3..1f4740cced73a1 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -2033,7 +2033,6 @@ int xfs_free_ag_extent( struct xfs_trans *tp, struct xfs_buf *agbp, - xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len, const struct xfs_owner_info *oinfo, @@ -2354,19 +2353,19 @@ xfs_free_ag_extent( * Update the freespace totals in the ag and superblock. */ error = xfs_alloc_update_counters(tp, agbp, len); - xfs_ag_resv_free_extent(agbp->b_pag, type, tp, len); + xfs_ag_resv_free_extent(pag, type, tp, len); if (error) goto error0; XFS_STATS_INC(mp, xs_freex); XFS_STATS_ADD(mp, xs_freeb, len); - trace_xfs_free_extent(mp, agno, bno, len, type, haveleft, haveright); + trace_xfs_free_extent(pag, bno, len, type, haveleft, haveright); return 0; error0: - trace_xfs_free_extent(mp, agno, bno, len, type, -1, -1); + trace_xfs_free_extent(pag, bno, len, type, -1, -1); if (bno_cur) xfs_btree_del_cursor(bno_cur, XFS_BTREE_ERROR); if (cnt_cur) @@ -4006,8 +4005,7 @@ __xfs_free_extent( goto err_release; } - error = xfs_free_ag_extent(tp, agbp, pag->pag_agno, agbno, len, oinfo, - type); + error = xfs_free_ag_extent(tp, agbp, agbno, len, oinfo, type); if (error) goto err_release; diff --git a/libxfs/xfs_alloc.h b/libxfs/xfs_alloc.h index 0165452e7cd055..88fbce5001185f 100644 --- a/libxfs/xfs_alloc.h +++ b/libxfs/xfs_alloc.h @@ -79,9 +79,8 @@ int xfs_alloc_put_freelist(struct xfs_perag *pag, struct xfs_trans *tp, struct xfs_buf *agfbp, struct xfs_buf *agflbp, xfs_agblock_t bno, int btreeblk); int xfs_free_ag_extent(struct xfs_trans *tp, struct xfs_buf *agbp, - xfs_agnumber_t agno, xfs_agblock_t bno, - xfs_extlen_t len, const struct xfs_owner_info *oinfo, - enum xfs_ag_resv_type type); + xfs_agblock_t bno, xfs_extlen_t len, + const struct xfs_owner_info *oinfo, enum xfs_ag_resv_type type); /* * Compute and fill in value of m_alloc_maxlevels. From patchwork Mon Dec 23 21:38:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13919239 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 C9CD138F82 for ; Mon, 23 Dec 2024 21:38: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=1734989937; cv=none; b=ba/uHKp3n9IWUiMFIvjGu9ipEa0NKw2Dm3j01XRP1Za9NX3uPvQqAzEpXdBFIFjeK9ITGOlNR2LXX6m7GgWVtMPTWdG6TW0gnrM8kK3XRG9RoCpsTuAOoNTbrUFkguM+Wxzak55tewFe+cevYVr+SciCcai1vSxLdTkPsmSLYj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734989937; c=relaxed/simple; bh=xNkBbAkfwwI7O9Y10A696imuvyKJY0Vf40MFhN8OAg0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=i4w3AtZ9b59BlqCMT3aDKD4WBi5lnT3GgWLL2EfVe1/XHMKSU2WApLDSBF+FEI9LPvBAuc38umjiYC7RMcfnZRmQ/VYD3Ntqor5yEkoRLNm1S/gQ+M8/qYQfQo6GXm9e1vUvvOQtOJ8qQFq0GVKRIjYdpSrJQjsvyX+GVy9w+L4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MSbHoHV8; 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="MSbHoHV8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6257BC4CED3; Mon, 23 Dec 2024 21:38:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734989937; bh=xNkBbAkfwwI7O9Y10A696imuvyKJY0Vf40MFhN8OAg0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=MSbHoHV8oZOHi023Nb5+IvjB6lEppbxY/l0mKGf4Ek6m2aAx4zruPYQpj+1S0k8Ks 7tSjqZUtCLhufL+dTuZAoDpzdzB4e3VkOO6N6gDvV/RYHGUUx1OTs5Mgrl/fXQQYNl Ix+tJinxVhAxhvugAOC9nTihgHDanBnxKbKMWsealAy1r7z6ncMteXpLdO442qj5TC sJxGB8QAMDvQyM6EJQ+N72PjZEcNr9cclBwwOmSBlJ/AlXmyDGyswo+M/T/usa9KHS 4pfj3kUZr2Km8u9FnBwmCFJjwjVAJGUKTJPbdptFPnj9hKvs4M5NyVyJYzfrO4W1cC +pbfKfA/jELPQ== Date: Mon, 23 Dec 2024 13:38:56 -0800 Subject: [PATCH 07/36] xfs: add xfs_agbno_to_fsb and xfs_agbno_to_daddr helpers From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940054.2293042.10537369242149586587.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 856a920ac2bbb2352ef6aa9e1e052f2e80677df7 Add helpers to convert an agbno to a daddr or fsbno based on a pag structure. This provides a simpler conversion and better type safety compared to the existing code that passes the mount structure and the agno separately. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_ag.c | 2 +- libxfs/xfs_ag.h | 16 ++++++++++++++++ libxfs/xfs_alloc.c | 14 ++++++-------- libxfs/xfs_btree.c | 7 +++---- libxfs/xfs_ialloc.c | 29 +++++++++++++---------------- libxfs/xfs_ialloc_btree.c | 2 +- libxfs/xfs_refcount.c | 11 ++++------- libxfs/xfs_refcount_btree.c | 3 +-- 8 files changed, 45 insertions(+), 39 deletions(-) diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index 62fc21fe7109b9..a6b5a7d71bbf80 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -867,7 +867,7 @@ xfs_ag_shrink_space( /* internal log shouldn't also show up in the free space btrees */ error = xfs_alloc_vextent_exact_bno(&args, - XFS_AGB_TO_FSB(mp, pag->pag_agno, aglen - delta)); + xfs_agbno_to_fsb(pag, aglen - delta)); if (!error && args.agbno == NULLAGBLOCK) error = -ENOSPC; diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index 958ca82524292f..c0a30141ddc330 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -330,4 +330,20 @@ int xfs_ag_extend_space(struct xfs_perag *pag, struct xfs_trans *tp, xfs_extlen_t len); int xfs_ag_get_geometry(struct xfs_perag *pag, struct xfs_ag_geometry *ageo); +static inline xfs_fsblock_t +xfs_agbno_to_fsb( + struct xfs_perag *pag, + xfs_agblock_t agbno) +{ + return XFS_AGB_TO_FSB(pag->pag_mount, pag->pag_agno, agbno); +} + +static inline xfs_daddr_t +xfs_agbno_to_daddr( + struct xfs_perag *pag, + xfs_agblock_t agbno) +{ + return XFS_AGB_TO_DADDR(pag->pag_mount, pag->pag_agno, agbno); +} + #endif /* __LIBXFS_AG_H */ diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index 1f4740cced73a1..19b38eaf45dd07 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -1255,7 +1255,7 @@ xfs_alloc_ag_vextent_small( struct xfs_buf *bp; error = xfs_trans_get_buf(args->tp, args->mp->m_ddev_targp, - XFS_AGB_TO_DADDR(args->mp, args->agno, fbno), + xfs_agbno_to_daddr(args->pag, fbno), args->mp->m_bsize, 0, &bp); if (error) goto error; @@ -2929,9 +2929,8 @@ xfs_alloc_fix_freelist( * Deferring the free disconnects freeing up the AGFL slot from * freeing the block. */ - error = xfs_free_extent_later(tp, - XFS_AGB_TO_FSB(mp, args->agno, bno), 1, - &targs.oinfo, XFS_AG_RESV_AGFL, 0); + error = xfs_free_extent_later(tp, xfs_agbno_to_fsb(pag, bno), + 1, &targs.oinfo, XFS_AG_RESV_AGFL, 0); if (error) goto out_agbp_relse; } @@ -3590,7 +3589,7 @@ xfs_alloc_vextent_finish( goto out_drop_perag; } - args->fsbno = XFS_AGB_TO_FSB(mp, args->agno, args->agbno); + args->fsbno = xfs_agbno_to_fsb(args->pag, args->agbno); ASSERT(args->len >= args->minlen); ASSERT(args->len <= args->maxlen); @@ -3642,7 +3641,6 @@ xfs_alloc_vextent_this_ag( struct xfs_alloc_arg *args, xfs_agnumber_t agno) { - struct xfs_mount *mp = args->mp; xfs_agnumber_t minimum_agno; uint32_t alloc_flags = 0; int error; @@ -3655,8 +3653,8 @@ xfs_alloc_vextent_this_ag( trace_xfs_alloc_vextent_this_ag(args); - error = xfs_alloc_vextent_check_args(args, XFS_AGB_TO_FSB(mp, agno, 0), - &minimum_agno); + error = xfs_alloc_vextent_check_args(args, + xfs_agbno_to_fsb(args->pag, 0), &minimum_agno); if (error) { if (error == -ENOSPC) return 0; diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c index bb53b6d7af22f6..4f04a92f6513bf 100644 --- a/libxfs/xfs_btree.c +++ b/libxfs/xfs_btree.c @@ -1015,21 +1015,20 @@ xfs_btree_readahead_agblock( struct xfs_btree_block *block) { struct xfs_mount *mp = cur->bc_mp; - xfs_agnumber_t agno = cur->bc_ag.pag->pag_agno; xfs_agblock_t left = be32_to_cpu(block->bb_u.s.bb_leftsib); xfs_agblock_t right = be32_to_cpu(block->bb_u.s.bb_rightsib); int rval = 0; if ((lr & XFS_BTCUR_LEFTRA) && left != NULLAGBLOCK) { xfs_buf_readahead(mp->m_ddev_targp, - XFS_AGB_TO_DADDR(mp, agno, left), + xfs_agbno_to_daddr(cur->bc_ag.pag, left), mp->m_bsize, cur->bc_ops->buf_ops); rval++; } if ((lr & XFS_BTCUR_RIGHTRA) && right != NULLAGBLOCK) { xfs_buf_readahead(mp->m_ddev_targp, - XFS_AGB_TO_DADDR(mp, agno, right), + xfs_agbno_to_daddr(cur->bc_ag.pag, right), mp->m_bsize, cur->bc_ops->buf_ops); rval++; } @@ -1089,7 +1088,7 @@ xfs_btree_ptr_to_daddr( switch (cur->bc_ops->type) { case XFS_BTREE_TYPE_AG: - *daddr = XFS_AGB_TO_DADDR(cur->bc_mp, cur->bc_ag.pag->pag_agno, + *daddr = xfs_agbno_to_daddr(cur->bc_ag.pag, be32_to_cpu(ptr->s)); break; case XFS_BTREE_TYPE_INODE: diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c index 10d88eb0b5bc32..6694ee2370411a 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -763,8 +763,7 @@ xfs_ialloc_ag_alloc( /* Allow space for the inode btree to split. */ args.minleft = igeo->inobt_maxlevels; error = xfs_alloc_vextent_exact_bno(&args, - XFS_AGB_TO_FSB(args.mp, pag->pag_agno, - args.agbno)); + xfs_agbno_to_fsb(pag, args.agbno)); if (error) return error; @@ -806,8 +805,8 @@ xfs_ialloc_ag_alloc( */ args.minleft = igeo->inobt_maxlevels; error = xfs_alloc_vextent_near_bno(&args, - XFS_AGB_TO_FSB(args.mp, pag->pag_agno, - be32_to_cpu(agi->agi_root))); + xfs_agbno_to_fsb(pag, + be32_to_cpu(agi->agi_root))); if (error) return error; } @@ -819,8 +818,8 @@ xfs_ialloc_ag_alloc( if (isaligned && args.fsbno == NULLFSBLOCK) { args.alignment = igeo->cluster_align; error = xfs_alloc_vextent_near_bno(&args, - XFS_AGB_TO_FSB(args.mp, pag->pag_agno, - be32_to_cpu(agi->agi_root))); + xfs_agbno_to_fsb(pag, + be32_to_cpu(agi->agi_root))); if (error) return error; } @@ -855,8 +854,8 @@ xfs_ialloc_ag_alloc( igeo->ialloc_blks; error = xfs_alloc_vextent_near_bno(&args, - XFS_AGB_TO_FSB(args.mp, pag->pag_agno, - be32_to_cpu(agi->agi_root))); + xfs_agbno_to_fsb(pag, + be32_to_cpu(agi->agi_root))); if (error) return error; @@ -1973,7 +1972,6 @@ xfs_difree_inode_chunk( struct xfs_inobt_rec_incore *rec) { struct xfs_mount *mp = tp->t_mountp; - xfs_agnumber_t agno = pag->pag_agno; xfs_agblock_t sagbno = XFS_AGINO_TO_AGBNO(mp, rec->ir_startino); int startidx, endidx; @@ -1984,8 +1982,7 @@ xfs_difree_inode_chunk( if (!xfs_inobt_issparse(rec->ir_holemask)) { /* not sparse, calculate extent info directly */ - return xfs_free_extent_later(tp, - XFS_AGB_TO_FSB(mp, agno, sagbno), + return xfs_free_extent_later(tp, xfs_agbno_to_fsb(pag, sagbno), M_IGEO(mp)->ialloc_blks, &XFS_RMAP_OINFO_INODES, XFS_AG_RESV_NONE, 0); } @@ -2031,9 +2028,9 @@ xfs_difree_inode_chunk( ASSERT(agbno % mp->m_sb.sb_spino_align == 0); ASSERT(contigblk % mp->m_sb.sb_spino_align == 0); - error = xfs_free_extent_later(tp, - XFS_AGB_TO_FSB(mp, agno, agbno), contigblk, - &XFS_RMAP_OINFO_INODES, XFS_AG_RESV_NONE, 0); + error = xfs_free_extent_later(tp, xfs_agbno_to_fsb(pag, agbno), + contigblk, &XFS_RMAP_OINFO_INODES, + XFS_AG_RESV_NONE, 0); if (error) return error; @@ -2503,7 +2500,7 @@ xfs_imap( offset = XFS_INO_TO_OFFSET(mp, ino); ASSERT(offset < mp->m_sb.sb_inopblock); - imap->im_blkno = XFS_AGB_TO_DADDR(mp, pag->pag_agno, agbno); + imap->im_blkno = xfs_agbno_to_daddr(pag, agbno); imap->im_len = XFS_FSB_TO_BB(mp, 1); imap->im_boffset = (unsigned short)(offset << mp->m_sb.sb_inodelog); @@ -2533,7 +2530,7 @@ xfs_imap( offset = ((agbno - cluster_agbno) * mp->m_sb.sb_inopblock) + XFS_INO_TO_OFFSET(mp, ino); - imap->im_blkno = XFS_AGB_TO_DADDR(mp, pag->pag_agno, cluster_agbno); + imap->im_blkno = xfs_agbno_to_daddr(pag, cluster_agbno); imap->im_len = XFS_FSB_TO_BB(mp, M_IGEO(mp)->blocks_per_cluster); imap->im_boffset = (unsigned short)(offset << mp->m_sb.sb_inodelog); diff --git a/libxfs/xfs_ialloc_btree.c b/libxfs/xfs_ialloc_btree.c index ffca4a80219d6d..f80368b4d5fa5f 100644 --- a/libxfs/xfs_ialloc_btree.c +++ b/libxfs/xfs_ialloc_btree.c @@ -119,7 +119,7 @@ __xfs_inobt_alloc_block( args.resv = resv; error = xfs_alloc_vextent_near_bno(&args, - XFS_AGB_TO_FSB(args.mp, args.pag->pag_agno, sbno)); + xfs_agbno_to_fsb(args.pag, sbno)); if (error) return error; diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 22f8afb27ece1c..eeddec68a08539 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -1153,8 +1153,7 @@ xfs_refcount_adjust_extents( goto out_error; } } else { - fsbno = XFS_AGB_TO_FSB(cur->bc_mp, - cur->bc_ag.pag->pag_agno, + fsbno = xfs_agbno_to_fsb(cur->bc_ag.pag, tmp.rc_startblock); error = xfs_free_extent_later(cur->bc_tp, fsbno, tmp.rc_blockcount, NULL, @@ -1216,8 +1215,7 @@ xfs_refcount_adjust_extents( } goto advloop; } else { - fsbno = XFS_AGB_TO_FSB(cur->bc_mp, - cur->bc_ag.pag->pag_agno, + fsbno = xfs_agbno_to_fsb(cur->bc_ag.pag, ext.rc_startblock); error = xfs_free_extent_later(cur->bc_tp, fsbno, ext.rc_blockcount, NULL, @@ -1319,7 +1317,7 @@ xfs_refcount_continue_op( return -EFSCORRUPTED; } - ri->ri_startblock = XFS_AGB_TO_FSB(mp, pag->pag_agno, new_agbno); + ri->ri_startblock = xfs_agbno_to_fsb(pag, new_agbno); ASSERT(xfs_verify_fsbext(mp, ri->ri_startblock, ri->ri_blockcount)); ASSERT(pag->pag_agno == XFS_FSB_TO_AGNO(mp, ri->ri_startblock)); @@ -1955,8 +1953,7 @@ xfs_refcount_recover_cow_leftovers( goto out_free; /* Free the orphan record */ - fsb = XFS_AGB_TO_FSB(mp, pag->pag_agno, - rr->rr_rrec.rc_startblock); + fsb = xfs_agbno_to_fsb(pag, rr->rr_rrec.rc_startblock); xfs_refcount_free_cow_extent(tp, fsb, rr->rr_rrec.rc_blockcount); diff --git a/libxfs/xfs_refcount_btree.c b/libxfs/xfs_refcount_btree.c index 9028dea06b0c07..5913f4176889ea 100644 --- a/libxfs/xfs_refcount_btree.c +++ b/libxfs/xfs_refcount_btree.c @@ -73,8 +73,7 @@ xfs_refcountbt_alloc_block( args.resv = XFS_AG_RESV_METADATA; error = xfs_alloc_vextent_near_bno(&args, - XFS_AGB_TO_FSB(args.mp, args.pag->pag_agno, - xfs_refc_block(args.mp))); + xfs_agbno_to_fsb(args.pag, xfs_refc_block(args.mp))); if (error) goto out_error; if (args.fsbno == NULLFSBLOCK) { From patchwork Mon Dec 23 21:39: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: 13919240 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 3B8BF1D6199 for ; Mon, 23 Dec 2024 21:39: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=1734989953; cv=none; b=a+3jZYZfhHvvEQyqBSpEow5kxFwgoBHLiUCGAH4e/Y9M2FqEGJe6ToGtH+RpRyyHfvxpW/LWnqxZCeRyuSjVSBrZwbNZKs60I4OnXMr1DpzfFgB+IwGb06ZKiNiPg33Vr5XoZAB2K6Y5TyM2iHkv1umsNREKhY/TpvnryO64Rl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734989953; c=relaxed/simple; bh=z+xOQtHRaBKCz7eXykLXEBF2Z/cXBJ40jKoFh5/mUPE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=R6mfgRrmN5WosPC72BSfaE0qXx6Oj0dtq/s4Pd6h4GUcMTozZ3O8rkyLl2QDe699tCNkp08/k1W4BD2fEpt0ipER2TMxLifYEabyUVXDAHaU4XDqXjsufAwveufHDsOg7ApjsF8FsOIEMPE4GxcRjSHowkKVJUL6OaIs0tfSvRI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uS7/odw4; 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="uS7/odw4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1112AC4CED3; Mon, 23 Dec 2024 21:39:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734989953; bh=z+xOQtHRaBKCz7eXykLXEBF2Z/cXBJ40jKoFh5/mUPE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=uS7/odw415e0Md7jugfa4I83XS68X/A5V1HQ+kFE/gvLS/lf3w+nL87HeOSMXTqUY +6c8ivaO2G4QmwEgMS3zM2hqLS2WuMe2+jnWeB/65rJzq6erizeB1FNK3mUdhAZFf0 x/+NzrlQJSnYGEzXBlTGDsk+oLBqk+L9n1jS8YZo35odmDuIpFLtaZKe0xtbzWwjt0 rzYyqXEfCp/TK4AzunrtKDKiKKjHzzVh4QeOGmbiT7GGko4hZN/LEDsEYW7q+J3Uai 0RUj6GkFbKZq0cgc9rZOwiJzVT5XS6vLm+cJ8dKDAYTVOaU0SKDwjLAEnsXl3aNdGB 4YJ3jEYteIWMQ== Date: Mon, 23 Dec 2024 13:39:12 -0800 Subject: [PATCH 08/36] xfs: add a xfs_agino_to_ino helper From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940069.2293042.16876229849757397847.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 6abd82ab6ea48430c13caebaad436ca6b5f2c34d Add a helpers to convert an agino to an ino based on a pag structure. This provides a simpler conversion and better type safety compared to the existing code that passes the mount structure and the agno separately. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_ag.h | 8 ++++++++ libxfs/xfs_ialloc.c | 24 +++++++++++------------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index c0a30141ddc330..e0f567d90debee 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -346,4 +346,12 @@ xfs_agbno_to_daddr( return XFS_AGB_TO_DADDR(pag->pag_mount, pag->pag_agno, agbno); } +static inline xfs_ino_t +xfs_agino_to_ino( + struct xfs_perag *pag, + xfs_agino_t agino) +{ + return XFS_AGINO_TO_INO(pag->pag_mount, pag->pag_agno, agino); +} + #endif /* __LIBXFS_AG_H */ diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c index 6694ee2370411a..01b2e2d8c27c22 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -909,8 +909,7 @@ xfs_ialloc_ag_alloc( if (error == -EFSCORRUPTED) { xfs_alert(args.mp, "invalid sparse inode record: ino 0x%llx holemask 0x%x count %u", - XFS_AGINO_TO_INO(args.mp, pag->pag_agno, - rec.ir_startino), + xfs_agino_to_ino(pag, rec.ir_startino), rec.ir_holemask, rec.ir_count); xfs_force_shutdown(args.mp, SHUTDOWN_CORRUPT_INCORE); } @@ -1329,7 +1328,7 @@ xfs_dialloc_ag_inobt( ASSERT(offset < XFS_INODES_PER_CHUNK); ASSERT((XFS_AGINO_TO_OFFSET(mp, rec.ir_startino) % XFS_INODES_PER_CHUNK) == 0); - ino = XFS_AGINO_TO_INO(mp, pag->pag_agno, rec.ir_startino + offset); + ino = xfs_agino_to_ino(pag, rec.ir_startino + offset); if (xfs_ag_has_sickness(pag, XFS_SICK_AG_INODES)) { error = xfs_dialloc_check_ino(pag, tp, ino); @@ -1610,7 +1609,7 @@ xfs_dialloc_ag( ASSERT(offset < XFS_INODES_PER_CHUNK); ASSERT((XFS_AGINO_TO_OFFSET(mp, rec.ir_startino) % XFS_INODES_PER_CHUNK) == 0); - ino = XFS_AGINO_TO_INO(mp, pag->pag_agno, rec.ir_startino + offset); + ino = xfs_agino_to_ino(pag, rec.ir_startino + offset); if (xfs_ag_has_sickness(pag, XFS_SICK_AG_INODES)) { error = xfs_dialloc_check_ino(pag, tp, ino); @@ -2117,8 +2116,7 @@ xfs_difree_inobt( if (!xfs_has_ikeep(mp) && rec.ir_free == XFS_INOBT_ALL_FREE && mp->m_sb.sb_inopblock <= XFS_INODES_PER_CHUNK) { xic->deleted = true; - xic->first_ino = XFS_AGINO_TO_INO(mp, pag->pag_agno, - rec.ir_startino); + xic->first_ino = xfs_agino_to_ino(pag, rec.ir_startino); xic->alloc = xfs_inobt_irec_to_allocmask(&rec); /* @@ -2317,10 +2315,10 @@ xfs_difree( return -EINVAL; } agino = XFS_INO_TO_AGINO(mp, inode); - if (inode != XFS_AGINO_TO_INO(mp, pag->pag_agno, agino)) { - xfs_warn(mp, "%s: inode != XFS_AGINO_TO_INO() (%llu != %llu).", + if (inode != xfs_agino_to_ino(pag, agino)) { + xfs_warn(mp, "%s: inode != xfs_agino_to_ino() (%llu != %llu).", __func__, (unsigned long long)inode, - (unsigned long long)XFS_AGINO_TO_INO(mp, pag->pag_agno, agino)); + (unsigned long long)xfs_agino_to_ino(pag, agino)); ASSERT(0); return -EINVAL; } @@ -2451,7 +2449,7 @@ xfs_imap( agino = XFS_INO_TO_AGINO(mp, ino); agbno = XFS_AGINO_TO_AGBNO(mp, agino); if (agbno >= mp->m_sb.sb_agblocks || - ino != XFS_AGINO_TO_INO(mp, pag->pag_agno, agino)) { + ino != xfs_agino_to_ino(pag, agino)) { error = -EINVAL; #ifdef DEBUG /* @@ -2466,11 +2464,11 @@ xfs_imap( __func__, (unsigned long long)agbno, (unsigned long)mp->m_sb.sb_agblocks); } - if (ino != XFS_AGINO_TO_INO(mp, pag->pag_agno, agino)) { + if (ino != xfs_agino_to_ino(pag, agino)) { xfs_alert(mp, - "%s: ino (0x%llx) != XFS_AGINO_TO_INO() (0x%llx)", + "%s: ino (0x%llx) != xfs_agino_to_ino() (0x%llx)", __func__, ino, - XFS_AGINO_TO_INO(mp, pag->pag_agno, agino)); + xfs_agino_to_ino(pag, agino)); } xfs_stack_trace(); #endif /* DEBUG */ From patchwork Mon Dec 23 21:39: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: 13919241 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 1DDF21D6DA9 for ; Mon, 23 Dec 2024 21:39:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734989969; cv=none; b=R7kZl1b8jacVM2igHTedlC78W0juuGU4kDNxfZ709jLUOz4/4/4XD2nYR9TVWNk6Q+APuJ6n3cShdC69E87033MiRqAZt6gRDMKNEUbKcj6LFiHVzVckLlwZArFwNQZclUTBViUnUqpfWEidig6KdXzSvcP0IScrz7Ez23LfQNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734989969; c=relaxed/simple; bh=tudfEeFdcnB/9VePZOyb9p/TRLHZ45upIrosIfeFcuY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qytf3bpP7ocpOO/VpccQTF8lwcv+B7fN/fqGJ3ZIJNnZyytTi0axbKQOELCLEn3qgz0z19tGb7shzFwFbeEa6z1PZ2j1pgs1a7aSLOYoBpjK9L6GDPphYi4d+zyW/dt1wwIYgTtv1d+Map77q9yeaZ1PeZCnhEQBJHF5HqJqiZY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fIPxb/BH; 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="fIPxb/BH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6735C4CED3; Mon, 23 Dec 2024 21:39:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734989968; bh=tudfEeFdcnB/9VePZOyb9p/TRLHZ45upIrosIfeFcuY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=fIPxb/BHvZOeAi6Lytnk9OwE1j/vrxhPbOwq2wT0N+ApiO8aseJjBTCg/GcsvO++6 QVg2HreKBlgEb29OymVyBMuE6ORTF+fRaeefzAWUvS2THfWlLLQ7lSqrQRzZ+9IewP 094j4dpQ6sUhHYS4/+ewn3QSoY+UnEDPAqHl8+vcb5c5iYL55uQtv8tqVv1BW8tx+I CmjgGxQKbb4//vYtMo5BFKeRrOmOvddm/gakFXbnjhJ2ju0nQqXXgSGzrveRhnQCLf jHeKz3qfYhBHHWeUYh+ZAXkLogS5R8CmnsHWnYjBBDvOyRokOx0giKb3+K9lfK3Hb1 1td0wmGvDgRYg== Date: Mon, 23 Dec 2024 13:39:28 -0800 Subject: [PATCH 09/36] xfs: pass a pag to xfs_extent_busy_{search,reuse} From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940085.2293042.3744807243442293269.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: b6dc8c6dd2d3f230e1a554f869d6df4568a2dfbb Replace the [mp,agno] tuple with the perag structure, which will become more useful later. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/libxfs_priv.h | 2 +- libxfs/xfs_alloc.c | 4 ++-- libxfs/xfs_alloc_btree.c | 2 +- libxfs/xfs_rmap_btree.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 97f5003ea53862..9505806131bc42 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -465,7 +465,7 @@ xfs_buf_readahead( #define XFS_EXTENT_BUSY_DISCARDED 0x01 /* undergoing a discard op. */ #define XFS_EXTENT_BUSY_SKIP_DISCARD 0x02 /* do not discard */ -#define xfs_extent_busy_reuse(mp,ag,bno,len,user) ((void) 0) +#define xfs_extent_busy_reuse(...) ((void) 0) /* avoid unused variable warning */ #define xfs_extent_busy_insert(tp,pag,bno,len,flags)({ \ struct xfs_perag *__foo = pag; \ diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index 19b38eaf45dd07..ed04e40856740b 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -1248,7 +1248,7 @@ xfs_alloc_ag_vextent_small( if (fbno == NULLAGBLOCK) goto out; - xfs_extent_busy_reuse(args->mp, args->pag, fbno, 1, + xfs_extent_busy_reuse(args->pag, fbno, 1, (args->datatype & XFS_ALLOC_NOBUSY)); if (args->datatype & XFS_ALLOC_USERDATA) { @@ -3610,7 +3610,7 @@ xfs_alloc_vextent_finish( if (error) goto out_drop_perag; - ASSERT(!xfs_extent_busy_search(mp, args->pag, args->agbno, + ASSERT(!xfs_extent_busy_search(args->pag, args->agbno, args->len)); } diff --git a/libxfs/xfs_alloc_btree.c b/libxfs/xfs_alloc_btree.c index 4a711f2463cd30..949cd18ab16a99 100644 --- a/libxfs/xfs_alloc_btree.c +++ b/libxfs/xfs_alloc_btree.c @@ -84,7 +84,7 @@ xfs_allocbt_alloc_block( } atomic64_inc(&cur->bc_mp->m_allocbt_blks); - xfs_extent_busy_reuse(cur->bc_mp, cur->bc_ag.pag, bno, 1, false); + xfs_extent_busy_reuse(cur->bc_ag.pag, bno, 1, false); new->s = cpu_to_be32(bno); diff --git a/libxfs/xfs_rmap_btree.c b/libxfs/xfs_rmap_btree.c index ada58e92645020..c261d6eae3bc3b 100644 --- a/libxfs/xfs_rmap_btree.c +++ b/libxfs/xfs_rmap_btree.c @@ -101,7 +101,7 @@ xfs_rmapbt_alloc_block( return 0; } - xfs_extent_busy_reuse(cur->bc_mp, pag, bno, 1, false); + xfs_extent_busy_reuse(pag, bno, 1, false); new->s = cpu_to_be32(bno); be32_add_cpu(&agf->agf_rmap_blocks, 1); From patchwork Mon Dec 23 21:39:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13919242 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 A69231D63DC for ; Mon, 23 Dec 2024 21:39: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=1734989984; cv=none; b=G8Ypu9QzxopE3dLX/CayZByxDvHuXORgbhvM+5PeahF6RjBFLrYAjrJiUIrAk889VdFuiNb04lpc8B/VHY17bbSV7UJaZW49rK4OFoM+bxjGC+oWuIDHLlFvF990mqGJ2vZCb9yIe6XbxNFMWbZ8LQMCd1PcOHqNdJWR6apDYvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734989984; c=relaxed/simple; bh=xUZu1ul2GCQgwOdOsKkv11vTyaiSSy1qWRUSStF+dRo=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=M9IfEuNphRBF4ewAnLx5bI3Avze/bf4CtndXgu2DKSiERxWX4XhPmRL10+DtTu2qTkxAMzhFRj60TqLiVf/G9nZFKpWhJgBkLVrHeSumJnEIIpSCme57ESehMhBnnRtXQuO0Sa4b7r8rzFqYgD49bLODoCQvq8WvW1Y7NPFR10E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OvR1mD5m; 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="OvR1mD5m" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B2F9C4CED3; Mon, 23 Dec 2024 21:39:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734989984; bh=xUZu1ul2GCQgwOdOsKkv11vTyaiSSy1qWRUSStF+dRo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=OvR1mD5myZyYJhZw+r2Vn0qv+qvaSQSwYCC6Ar1ngh/wHEIY/eVaK7dE/T+FjuuQj spXQ4CYZWl3FXRkrC9D4gd1j4UPvI1nMM0kqwF5NK8/g23Nydmf/OAJcaUF9buD0mt WXEUsxSYoOmSCW3cmFtmcytscAb8VHH3FeLlKy3txhPvfcMG7NASTKQ3crRgPYazOL CwkaSooHcnuyyIvq0oDF1OCu/zGQ0R+bb2TmW5rEXl4w67Ch8BgJaSd0n51A0bmx86 oCSwuNbQnStdnIb5mvUlJhT3N6XzOstjWGtW87aBJA4amAe/onwr7WtbkbCtIhaT9s jDP9Y5e3L1qSw== Date: Mon, 23 Dec 2024 13:39:43 -0800 Subject: [PATCH 10/36] xfs: pass a perag structure to the xfs_ag_resv_init_error trace point From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940100.2293042.8768030502110956248.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 835ddb592fab75ed96828ee3f12ea44496882d6b And remove the single instance class indirection for it. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_ag_resv.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libxfs/xfs_ag_resv.c b/libxfs/xfs_ag_resv.c index 7e5cbe0cb6afd3..d1657d6c636546 100644 --- a/libxfs/xfs_ag_resv.c +++ b/libxfs/xfs_ag_resv.c @@ -205,8 +205,7 @@ __xfs_ag_resv_init( else error = xfs_dec_fdblocks(mp, hidden_space, true); if (error) { - trace_xfs_ag_resv_init_error(pag->pag_mount, pag->pag_agno, - error, _RET_IP_); + trace_xfs_ag_resv_init_error(pag, error, _RET_IP_); xfs_warn(mp, "Per-AG reservation for AG %u failed. Filesystem may run out of space.", pag->pag_agno); From patchwork Mon Dec 23 21:39: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: 13919243 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 0C7B11D619D for ; Mon, 23 Dec 2024 21:40: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=1734990000; cv=none; b=HvVEQgKkk36qvH6GTz6biUUPy7mYIdhkvEy8/iS/R02Y+01NmpbOJKFJrKC6kL9257sym68fEmnmVshk2qIfry2eYN9JjkorqxoylP1BVT/36au8WLItlF5y/lm/3qMZX1qUfrurh7o/MygHaljqj2NzSndma5Awn5yJ59ttENc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990000; c=relaxed/simple; bh=5PtFnDfEP460iHV4IKt8kyruSzfaZY3zPbE0rOoAA5U=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LBLZxAvRm7IiycstjKP+m8bK6v/XFGZET/khLoceeXscN50NmRYJlQemTKAgvStVKJ6naeXt5Zfv5+pY0o6DUn6w3XPLh5CFgKo+FQUTpwaBrji813QYgSvtAdfqOW/PuvswvVf3UjvoWszkF8kcU+c7WSzH8DRHe8WVkBiMLJk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L8we/qv3; 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="L8we/qv3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D96C0C4CED3; Mon, 23 Dec 2024 21:39:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734989999; bh=5PtFnDfEP460iHV4IKt8kyruSzfaZY3zPbE0rOoAA5U=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=L8we/qv3SZZjxjocrp9Ra6Y/Ep/HupeJtpJwYPQy29ku+1VmSOU+w+tyDo4Lep59z IWaO9fUhTmb27Lfjb79l5Y6U+N6pXhQhRjwQ+a9WPl/3BD8DqsMvzBt5VINCsCIcCX ei/ocv73IOfmO+1sdASODHTahyi9mkIwuIgH4ea6xg4OVl/F2GjyApKLiAWmiyc+CX hE+8xMQxDBVw7WfDwmJRhOD4tprE9c6aUHkiXDEV9eBMrAKtMTtOVQTOwI8O8kEsog Uda+ivqY+ycotYUiTYiNuBoJjTCocoYWGFdNB4BNHFLYg89zoxAIxvfniG0s4Qy4P3 CFm/iBpPMsokg== Date: Mon, 23 Dec 2024 13:39:59 -0800 Subject: [PATCH 11/36] xfs: pass objects to the xfs_irec_merge_{pre,post} trace points From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940115.2293042.6563097897581787673.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 487092ceaa72448ca3a82ea9fb89768c88f6abec Pass the perag structure and the irec to these tracepoints so that the decoding is only done when tracing is actually enabled and the call sites look a lot neater. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- include/xfs_trace.h | 4 ++-- libxfs/xfs_ialloc.c | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/include/xfs_trace.h b/include/xfs_trace.h index ba51419b3df3d3..0986e1621437d4 100644 --- a/include/xfs_trace.h +++ b/include/xfs_trace.h @@ -85,8 +85,8 @@ #define trace_xfs_alloc_read_agf(a,b) ((void) 0) #define trace_xfs_read_agi(a,b) ((void) 0) #define trace_xfs_ialloc_read_agi(a,b) ((void) 0) -#define trace_xfs_irec_merge_pre(a,b,c,d,e,f) ((void) 0) -#define trace_xfs_irec_merge_post(a,b,c,d) ((void) 0) +#define trace_xfs_irec_merge_pre(...) ((void) 0) +#define trace_xfs_irec_merge_post(...) ((void) 0) #define trace_xfs_iext_insert(a,b,c,d) ((void) 0) #define trace_xfs_iext_remove(a,b,c,d) ((void) 0) diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c index 01b2e2d8c27c22..b3d6f7f4212588 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -601,15 +601,12 @@ xfs_inobt_insert_sprec( goto error; } - trace_xfs_irec_merge_pre(mp, pag->pag_agno, rec.ir_startino, - rec.ir_holemask, nrec->ir_startino, - nrec->ir_holemask); + trace_xfs_irec_merge_pre(pag, &rec, nrec); /* merge to nrec to output the updated record */ __xfs_inobt_rec_merge(nrec, &rec); - trace_xfs_irec_merge_post(mp, pag->pag_agno, nrec->ir_startino, - nrec->ir_holemask); + trace_xfs_irec_merge_post(pag, nrec); error = xfs_inobt_rec_check_count(mp, nrec); if (error) From patchwork Mon Dec 23 21:40: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: 13919244 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 A4AB4183CCA for ; Mon, 23 Dec 2024 21:40:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990015; cv=none; b=DyhVTjfLGVMRgXzdlLPNwnDBWXmldBe9wMt5lncE78GYvqyXnwY9Nmo46JgUeFApvqApI2KzR+okIviwrkODbCV7S7fIzM7JdYset+BlSASzGFg4ZigqN34PJT0JDzpkPPdlh/8cfAW3gbzoO6f0aiQ5S2gXOomh0rWNnkkntrc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990015; c=relaxed/simple; bh=1HVniQSLlYB/rAkIVFsg2MTNNLca7FoPzzgAudq3/K4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=O0zsVyM0u+xGozWm8J3eIEoDwztvqzZPRb8tmL6SqiOzwPVuOTRvZ4AMsIpB+DxQHTTPbF8JGEpKObSOo25p7qBlvqzMBNRE0fK0KCg91+yrktcKk8aibgNfDWxmm6j0Q4UGYIOyeY5RR9TwKur0q72flHq/UNYFqFaLegTviNQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L5EKNWKX; 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="L5EKNWKX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7BA3DC4CED3; Mon, 23 Dec 2024 21:40:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990015; bh=1HVniQSLlYB/rAkIVFsg2MTNNLca7FoPzzgAudq3/K4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=L5EKNWKXGEDByOzS12+sp14gjQqbMswgw1zdYiSLdaduaaBfNf987OY1cAR4eBfSZ 4bJdjjgDTTrafLZAbMS3XyP6RX3zGO4QLFhLT6n+XcT7Z7FUUwOW+Ox2mvmxDhIQ6x rPkolTgR+2T5oWY3/Hv8nhQ35RISr75gfR3zh0PK1j3d0F4DCDEzNmtXDjSpZcJMRd 2y8VrtNeYW5dcRvXkry3136pmtecBLFMxDo/kvT1+z3I4ZR75QkqVjrOyuF5evoTIO ljJb3shPzKy7wEN2y7xVn0jouZVB6hfCVOXTsNRNBjUt39n2dx+Qvkb31vwvU4cRsR mYSz0dDF2RE4A== Date: Mon, 23 Dec 2024 13:40:15 -0800 Subject: [PATCH 12/36] xfs: convert remaining trace points to pass pag structures From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940131.2293042.10206551882717162539.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: c4ae021bcb6bf8bbb329ce8ef947a43009bc2fe4 Convert all tracepoints that take [mp,agno] tuples to take a pag argument instead so that decoding only happens when tracepoints are enabled and to clean up the callers. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- include/xfs_trace.h | 8 ++++---- libxfs/xfs_alloc.c | 4 ++-- libxfs/xfs_ialloc.c | 4 ++-- libxfs/xfs_inode_util.c | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/xfs_trace.h b/include/xfs_trace.h index 0986e1621437d4..012e0018cb8367 100644 --- a/include/xfs_trace.h +++ b/include/xfs_trace.h @@ -81,10 +81,10 @@ #define trace_xfs_free_extent(...) ((void) 0) #define trace_xfs_agf(a,b,c,d) ((void) 0) -#define trace_xfs_read_agf(a,b) ((void) 0) -#define trace_xfs_alloc_read_agf(a,b) ((void) 0) -#define trace_xfs_read_agi(a,b) ((void) 0) -#define trace_xfs_ialloc_read_agi(a,b) ((void) 0) +#define trace_xfs_read_agf(...) ((void) 0) +#define trace_xfs_alloc_read_agf(...) ((void) 0) +#define trace_xfs_read_agi(...) ((void) 0) +#define trace_xfs_ialloc_read_agi(...) ((void) 0) #define trace_xfs_irec_merge_pre(...) ((void) 0) #define trace_xfs_irec_merge_post(...) ((void) 0) diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index ed04e40856740b..bd39bcde0ea224 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -3354,7 +3354,7 @@ xfs_read_agf( struct xfs_mount *mp = pag->pag_mount; int error; - trace_xfs_read_agf(pag->pag_mount, pag->pag_agno); + trace_xfs_read_agf(pag); error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, XFS_AG_DADDR(mp, pag->pag_agno, XFS_AGF_DADDR(mp)), @@ -3385,7 +3385,7 @@ xfs_alloc_read_agf( int error; int allocbt_blks; - trace_xfs_alloc_read_agf(pag->pag_mount, pag->pag_agno); + trace_xfs_alloc_read_agf(pag); /* We don't support trylock when freeing. */ ASSERT((flags & (XFS_ALLOC_FLAG_FREEING | XFS_ALLOC_FLAG_TRYLOCK)) != diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c index b3d6f7f4212588..4f087e6b074081 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -2724,7 +2724,7 @@ xfs_read_agi( struct xfs_mount *mp = pag->pag_mount; int error; - trace_xfs_read_agi(pag->pag_mount, pag->pag_agno); + trace_xfs_read_agi(pag); error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, XFS_AG_DADDR(mp, pag->pag_agno, XFS_AGI_DADDR(mp)), @@ -2755,7 +2755,7 @@ xfs_ialloc_read_agi( struct xfs_agi *agi; int error; - trace_xfs_ialloc_read_agi(pag->pag_mount, pag->pag_agno); + trace_xfs_ialloc_read_agi(pag); error = xfs_read_agi(pag, tp, (flags & XFS_IALLOC_FLAG_TRYLOCK) ? XBF_TRYLOCK : 0, diff --git a/libxfs/xfs_inode_util.c b/libxfs/xfs_inode_util.c index 92bfdf0715f02e..f9f16c7e2d0788 100644 --- a/libxfs/xfs_inode_util.c +++ b/libxfs/xfs_inode_util.c @@ -439,8 +439,8 @@ xfs_iunlink_update_bucket( ASSERT(xfs_verify_agino_or_null(pag, new_agino)); old_value = be32_to_cpu(agi->agi_unlinked[bucket_index]); - trace_xfs_iunlink_update_bucket(tp->t_mountp, pag->pag_agno, bucket_index, - old_value, new_agino); + trace_xfs_iunlink_update_bucket(pag, bucket_index, old_value, + new_agino); /* * We should never find the head of the list already set to the value From patchwork Mon Dec 23 21:40:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13919245 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 4809E18052 for ; Mon, 23 Dec 2024 21:40: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=1734990031; cv=none; b=ZuEmAw4vFfsxlKO81V7lehFSjyaJFP+PJaK21Dho7vrbANGox4uZNEjxMoCKLEQib/RUwNk8CMzu3ecc6Puu3tKr60o8U5sWC536L++/3xysOXJA20LQxNlYuTJeHFh9JP+ALdXouExBi3vE8T9pz4PzwWwrzyjV1x4Xm0DNhww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990031; c=relaxed/simple; bh=ysOYdj7SJ0TcgzIM7t4KJH5hggQmaN4qBjOrMfGz70o=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=A+HXy5VFkxVo/0+MjxJJoYgmnhJGOyjYP+ppWznlTWx/50xPu2ZVX6znTEB7OrYEVMk9TRnI1TE8z/ZjrvrfpIJbYg5ASxeIE/riVzDLrdAC9+5O35A+41WieMuWOAvNxA4tXRWhVGDRFNbQIVelkLUT6J0/e9RGYgJzGrKFi40= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TYvhUsvb; 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="TYvhUsvb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22B93C4CED3; Mon, 23 Dec 2024 21:40:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990031; bh=ysOYdj7SJ0TcgzIM7t4KJH5hggQmaN4qBjOrMfGz70o=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=TYvhUsvbCHmqsU3bjYRdMZxFXII9zRr+Sc7APIArmtyZgbWZKvmehBqjNg+xk1f/K f9BYleNQU1V7eH9PtmGDGDWLE3V/ZejC5RDwk0pPUuq8Y7hUFut1aPi0GEKygFcjaG Ivgc6D3HGkyEavlOJ8Cwc/Orvv+Ev5rT4RUaYlr/shR/7+9zkxhpCoiSkDuBKHz3dX L9d7zTx+e7aYQ1qTKLqbGFVhbdZBrBiCAQI5d3lSDuDgc8DWnxPHgFZXIJOJvJeixn OL2Jorr5ALkClDgpJ2fO0AmhAjLAx+3FydWD/YXL9ceSXHWlKc8muZj/4pon33s1nT hrSz/VHQ7Cf0Q== Date: Mon, 23 Dec 2024 13:40:30 -0800 Subject: [PATCH 13/36] xfs: split xfs_initialize_perag From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940146.2293042.2594553624248150640.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 201c5fa342af75adaf762fd6c63380bb8001762d Factor out a xfs_perag_alloc helper that allocates a single perag structure. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_ag.c | 121 ++++++++++++++++++++++++++++++++----------------------- libxfs/xfs_ag.h | 4 +- 2 files changed, 72 insertions(+), 53 deletions(-) diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index a6b5a7d71bbf80..8809d76d496ae9 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -270,6 +270,10 @@ xfs_agino_range( return __xfs_agino_range(mp, xfs_ag_block_count(mp, agno), first, last); } +/* + * Update the perag of the previous tail AG if it has been changed during + * recovery (i.e. recovery of a growfs). + */ int xfs_update_last_ag_size( struct xfs_mount *mp, @@ -287,69 +291,57 @@ xfs_update_last_ag_size( return 0; } -int -xfs_initialize_perag( +static int +xfs_perag_alloc( struct xfs_mount *mp, - xfs_agnumber_t old_agcount, - xfs_agnumber_t new_agcount, - xfs_rfsblock_t dblocks, - xfs_agnumber_t *maxagi) + xfs_agnumber_t index, + xfs_agnumber_t agcount, + xfs_rfsblock_t dblocks) { struct xfs_perag *pag; - xfs_agnumber_t index; int error; - for (index = old_agcount; index < new_agcount; index++) { - pag = kzalloc(sizeof(*pag), GFP_KERNEL); - if (!pag) { - error = -ENOMEM; - goto out_unwind_new_pags; - } - pag->pag_agno = index; - pag->pag_mount = mp; + pag = kzalloc(sizeof(*pag), GFP_KERNEL); + if (!pag) + return -ENOMEM; - error = xa_insert(&mp->m_perags, index, pag, GFP_KERNEL); - if (error) { - WARN_ON_ONCE(error == -EBUSY); - goto out_free_pag; - } + pag->pag_agno = index; + pag->pag_mount = mp; + + error = xa_insert(&mp->m_perags, index, pag, GFP_KERNEL); + if (error) { + WARN_ON_ONCE(error == -EBUSY); + goto out_free_pag; + } #ifdef __KERNEL__ - /* Place kernel structure only init below this point. */ - spin_lock_init(&pag->pag_ici_lock); - spin_lock_init(&pag->pagb_lock); - spin_lock_init(&pag->pag_state_lock); - INIT_DELAYED_WORK(&pag->pag_blockgc_work, xfs_blockgc_worker); - INIT_RADIX_TREE(&pag->pag_ici_root, GFP_ATOMIC); - xfs_defer_drain_init(&pag->pag_intents_drain); - init_waitqueue_head(&pag->pagb_wait); - pag->pagb_tree = RB_ROOT; - xfs_hooks_init(&pag->pag_rmap_update_hooks); + /* Place kernel structure only init below this point. */ + spin_lock_init(&pag->pag_ici_lock); + spin_lock_init(&pag->pagb_lock); + spin_lock_init(&pag->pag_state_lock); + INIT_DELAYED_WORK(&pag->pag_blockgc_work, xfs_blockgc_worker); + INIT_RADIX_TREE(&pag->pag_ici_root, GFP_ATOMIC); + xfs_defer_drain_init(&pag->pag_intents_drain); + init_waitqueue_head(&pag->pagb_wait); + pag->pagb_tree = RB_ROOT; + xfs_hooks_init(&pag->pag_rmap_update_hooks); #endif /* __KERNEL__ */ - error = xfs_buf_cache_init(&pag->pag_bcache); - if (error) - goto out_remove_pag; + error = xfs_buf_cache_init(&pag->pag_bcache); + if (error) + goto out_remove_pag; - /* Active ref owned by mount indicates AG is online. */ - atomic_set(&pag->pag_active_ref, 1); + /* Active ref owned by mount indicates AG is online. */ + atomic_set(&pag->pag_active_ref, 1); - /* - * Pre-calculated geometry - */ - pag->block_count = __xfs_ag_block_count(mp, index, new_agcount, - dblocks); - pag->min_block = XFS_AGFL_BLOCK(mp); - __xfs_agino_range(mp, pag->block_count, &pag->agino_min, - &pag->agino_max); - } + /* + * Pre-calculated geometry + */ + pag->block_count = __xfs_ag_block_count(mp, index, agcount, dblocks); + pag->min_block = XFS_AGFL_BLOCK(mp); + __xfs_agino_range(mp, pag->block_count, &pag->agino_min, + &pag->agino_max); - index = xfs_set_inode_alloc(mp, new_agcount); - - if (maxagi) - *maxagi = index; - - mp->m_ag_prealloc_blocks = xfs_prealloc_blocks(mp); return 0; out_remove_pag: @@ -357,8 +349,35 @@ xfs_initialize_perag( pag = xa_erase(&mp->m_perags, index); out_free_pag: kfree(pag); + return error; +} + +int +xfs_initialize_perag( + struct xfs_mount *mp, + xfs_agnumber_t orig_agcount, + xfs_agnumber_t new_agcount, + xfs_rfsblock_t dblocks, + xfs_agnumber_t *maxagi) +{ + xfs_agnumber_t index; + int error; + + if (orig_agcount >= new_agcount) + return 0; + + for (index = orig_agcount; index < new_agcount; index++) { + error = xfs_perag_alloc(mp, index, new_agcount, dblocks); + if (error) + goto out_unwind_new_pags; + } + + *maxagi = xfs_set_inode_alloc(mp, new_agcount); + mp->m_ag_prealloc_blocks = xfs_prealloc_blocks(mp); + return 0; + out_unwind_new_pags: - xfs_free_perag_range(mp, old_agcount, index); + xfs_free_perag_range(mp, orig_agcount, index); return error; } diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index e0f567d90debee..8787823ae37f9f 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -142,8 +142,8 @@ __XFS_AG_OPSTATE(prefers_metadata, PREFERS_METADATA) __XFS_AG_OPSTATE(allows_inodes, ALLOWS_INODES) __XFS_AG_OPSTATE(agfl_needs_reset, AGFL_NEEDS_RESET) -int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t old_agcount, - xfs_agnumber_t agcount, xfs_rfsblock_t dcount, +int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t orig_agcount, + xfs_agnumber_t new_agcount, xfs_rfsblock_t dcount, xfs_agnumber_t *maxagi); void xfs_free_perag_range(struct xfs_mount *mp, xfs_agnumber_t first_agno, xfs_agnumber_t end_agno); From patchwork Mon Dec 23 21:40: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: 13919246 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 02791161328 for ; Mon, 23 Dec 2024 21:40:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990047; cv=none; b=JY89GOTubbAZSZdfR0SOCHVKabpVfDDUo5ajEhe63jJQModN+wp2uJDLYK4ynjIxjjeX/HWgFQtNDOM3/0I0/Mjxc4BQ7loJksns+NfWSXxW9pHAPUcgmydFF46UqHOpmWB9zLleoEDw5dWynmkzlDt47X5fn+S5qxthAO+Ipbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990047; c=relaxed/simple; bh=O5bXcWC6/erVcKzDBgZoagH7FcPwXxy1Rx73aDJtsxo=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=spuc1O5CxkAy5Nc06TwDg/xQ9LZ3lyDq5oS4k8esuhwPvFTYqVsoZxelXrUthFhrCQdSzSfXZkft3WD9LWzrqt2vhatbbXzkQzPImQ3q6Wq9HMt4rz/Hbvhgy12JANSNQRextosaGtYoRxaJYJ8QmFn0bqVfL9KMXhbSyjV6J8g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nnMrM1dg; 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="nnMrM1dg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6F65C4CED3; Mon, 23 Dec 2024 21:40:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990046; bh=O5bXcWC6/erVcKzDBgZoagH7FcPwXxy1Rx73aDJtsxo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=nnMrM1dgQCapcbPxmhJNnVrsSnDEMqe5VvzzJu9Lgt65KgRQX18GACc69BbQ/ZY9E A0K4vej+th4A+hZME+35dQc7cCsbHqlCRd4Pf0s9WoZaFnwElV+1IboXuRvx93ZUUL 74mhYK/h/okNFonAZ7XT7ICQyXQel2MZ+wR6uulWgjzqgGMer849CJgVU3Zy1MIUzd GNrC5iBcATI+JJNMJ9N0UVuEao8KqBML4ayg3YBHRC6F9m8uAXGW1mdb2cophsPfTA iu4wHO9ko9cHVXcMrtKpjp7ePjjhifleowYbuBjEZ66DodbRJFvjff5lxbc1eM4TAO NfP34Uis0+Llg== Date: Mon, 23 Dec 2024 13:40:46 -0800 Subject: [PATCH 14/36] xfs: insert the pag structures into the xarray later From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940160.2293042.5173621765621797998.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: d66496578b2a099ea453f56782f1cd2bf63a8029 Cleaning up is much easier if a structure can't be looked up yet, so only insert the pag once it is fully set up. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_ag.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index 8809d76d496ae9..e22ce4e83f4a62 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -305,15 +305,6 @@ xfs_perag_alloc( if (!pag) return -ENOMEM; - pag->pag_agno = index; - pag->pag_mount = mp; - - error = xa_insert(&mp->m_perags, index, pag, GFP_KERNEL); - if (error) { - WARN_ON_ONCE(error == -EBUSY); - goto out_free_pag; - } - #ifdef __KERNEL__ /* Place kernel structure only init below this point. */ spin_lock_init(&pag->pag_ici_lock); @@ -329,10 +320,7 @@ xfs_perag_alloc( error = xfs_buf_cache_init(&pag->pag_bcache); if (error) - goto out_remove_pag; - - /* Active ref owned by mount indicates AG is online. */ - atomic_set(&pag->pag_active_ref, 1); + goto out_defer_drain_free; /* * Pre-calculated geometry @@ -342,12 +330,23 @@ xfs_perag_alloc( __xfs_agino_range(mp, pag->block_count, &pag->agino_min, &pag->agino_max); + pag->pag_agno = index; + pag->pag_mount = mp; + /* Active ref owned by mount indicates AG is online. */ + atomic_set(&pag->pag_active_ref, 1); + + error = xa_insert(&mp->m_perags, index, pag, GFP_KERNEL); + if (error) { + WARN_ON_ONCE(error == -EBUSY); + goto out_buf_cache_destroy; + } + return 0; -out_remove_pag: +out_buf_cache_destroy: + xfs_buf_cache_destroy(&pag->pag_bcache); +out_defer_drain_free: xfs_defer_drain_free(&pag->pag_intents_drain); - pag = xa_erase(&mp->m_perags, index); -out_free_pag: kfree(pag); return error; } From patchwork Mon Dec 23 21:41:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13919247 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 EAFC818052 for ; Mon, 23 Dec 2024 21:41:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990063; cv=none; b=iH/HRMWpIqeDWMWuC77zGUNzFlTA7zSrSMB4OTWePOotjQxgF+7tUblupPlf/+Qd6xgDTrOHMpKkgoblPO6uHLO9hMKprFbNXKNne4b6hmFsmUOVdyWRbYe25VOt/u5bqqbrFL773+az2HIYw/oVtDkCojN74D+qhtGEkMUEHlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990063; c=relaxed/simple; bh=Lu3BKNybDVA2kT8zPDexSdMav9bOHWTrHfAWHVQUyu4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OhJlgusYQHPq2nR9rDbxLH/bqLstonPa3K2gdfsCFBx8vW0yjXFvBXNnYm7HtwfvrGhbYj8yslb8d6qOvmrSUKf+zgAY3rFXUd3129tJxvFDh/NINOkYGa6jl3Iv/5vc8tbC9SYDtOThj4Mzner+23QFDHDI+D8CDdBNA5CRFSk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pShHUNBy; 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="pShHUNBy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62F2DC4CED3; Mon, 23 Dec 2024 21:41:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990062; bh=Lu3BKNybDVA2kT8zPDexSdMav9bOHWTrHfAWHVQUyu4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=pShHUNByZYoAVhydUOsV4jpSkGBPLGcq8dPO39gipnFh95KDr/pAe9LwmjHNkyk00 QC9Hubwd5rbmeetOYf7S+iOVFsstQcZcbsz5v6qqQ2WMsKwDpt3/hkwAR9x9VWjxwv /BtKQ7IePs7rMqA9bByKyJTPTmTOSNtXjwTXvOdbNZGUQa3Iudzvm0kZuuk6exOtOW Jn1tvZu1BVifNHKQeF9ZUE1yBVeH3MjDu35g0/pSEs7x0aetPuriwslCFEuLZ+3zAL 3p1hTzwHJL0/7LLZzW4nmCucQ+Ph59SA/65qeUYUEKmAuWArZAEnlJ4SC4G0M7Kpgn BI0Pyo935O7WQ== Date: Mon, 23 Dec 2024 13:41:01 -0800 Subject: [PATCH 15/36] xfs: factor out a generic xfs_group structure From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940172.2293042.4440535755487265477.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: e9c4d8bfb26c13c41b73fdf4183d3df2d392101e Split the lookup and refcount handling of struct xfs_perag into an embedded xfs_group structure that can be reused for the upcoming realtime groups. It will be extended with more features later. Note that he xg_type field will only need a single bit even with realtime group support. For now it fills a hole, but it might be worth to fold it into another field if we can use this space better. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- db/fsmap.c | 6 +- db/info.c | 2 - db/iunlink.c | 2 - include/xfs_mount.h | 6 +- include/xfs_trace.h | 7 ++ libfrog/radix-tree.h | 9 ++ libxfs/Makefile | 2 + libxfs/defer_item.c | 6 +- libxfs/init.c | 8 +- libxfs/iunlink.c | 11 ++- libxfs/xfs_ag.c | 139 +++++++----------------------------- libxfs/xfs_ag.h | 81 +++++++++++++++++---- libxfs/xfs_ag_resv.c | 19 +++-- libxfs/xfs_alloc.c | 39 +++++----- libxfs/xfs_alloc_btree.c | 2 - libxfs/xfs_bmap.c | 2 - libxfs/xfs_btree.c | 6 +- libxfs/xfs_group.c | 168 +++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_group.h | 41 ++++++++++ libxfs/xfs_ialloc.c | 40 +++++----- libxfs/xfs_ialloc_btree.c | 16 ++-- libxfs/xfs_refcount.c | 4 + libxfs/xfs_refcount_btree.c | 8 +- libxfs/xfs_rmap.c | 4 + libxfs/xfs_rmap_btree.c | 7 +- libxfs/xfs_sb.c | 6 +- libxfs/xfs_types.h | 8 ++ repair/agbtree.c | 27 +++---- repair/bmap_repair.c | 4 - repair/bulkload.c | 9 +- repair/phase2.c | 10 +-- repair/phase5.c | 2 - repair/rmap.c | 10 +-- 33 files changed, 455 insertions(+), 256 deletions(-) create mode 100644 libxfs/xfs_group.c create mode 100644 libxfs/xfs_group.h diff --git a/db/fsmap.c b/db/fsmap.c index 7fd42df2a1c854..923d7568b9d977 100644 --- a/db/fsmap.c +++ b/db/fsmap.c @@ -64,7 +64,7 @@ fsmap( info.nr = 0; for_each_perag_range(mp, start_ag, end_ag, pag) { - if (pag->pag_agno == end_ag) + if (pag_agno(pag) == end_ag) high.rm_startblock = XFS_FSB_TO_AGBNO(mp, end_fsb); error = -libxfs_alloc_read_agf(pag, NULL, 0, &agbp); @@ -82,7 +82,7 @@ fsmap( return; } - info.agno = pag->pag_agno; + info.agno = pag_agno(pag); error = -libxfs_rmap_query_range(bt_cur, &low, &high, fsmap_fn, &info); if (error) { @@ -97,7 +97,7 @@ fsmap( libxfs_btree_del_cursor(bt_cur, XFS_BTREE_NOERROR); libxfs_buf_relse(agbp); - if (pag->pag_agno == start_ag) + if (pag_agno(pag) == start_ag) low.rm_startblock = 0; } } diff --git a/db/info.c b/db/info.c index 9c6203f029d41c..6a8765ec761a49 100644 --- a/db/info.c +++ b/db/info.c @@ -66,7 +66,7 @@ print_agresv_info( { struct xfs_buf *bp; struct xfs_agf *agf; - xfs_agnumber_t agno = pag->pag_agno; + xfs_agnumber_t agno = pag_agno(pag); xfs_extlen_t ask = 0; xfs_extlen_t used = 0; xfs_extlen_t free = 0; diff --git a/db/iunlink.c b/db/iunlink.c index 55ba5af5a3c563..c9977a859e2842 100644 --- a/db/iunlink.c +++ b/db/iunlink.c @@ -117,7 +117,7 @@ dump_unlinked( bool verbose) { struct xfs_buf *agi_bp; - xfs_agnumber_t agno = pag->pag_agno; + xfs_agnumber_t agno = pag_agno(pag); int error; error = -libxfs_ialloc_read_agi(pag, NULL, 0, &agi_bp); diff --git a/include/xfs_mount.h b/include/xfs_mount.h index e2add8a648f887..2102009aa8df73 100644 --- a/include/xfs_mount.h +++ b/include/xfs_mount.h @@ -24,6 +24,10 @@ enum { XFS_LOWSP_MAX, }; +struct xfs_groups { + struct xarray xa; +}; + /* * Define a user-level mount structure with all we need * in order to make use of the numerous XFS_* macros. @@ -91,7 +95,7 @@ typedef struct xfs_mount { xfs_extlen_t m_ag_prealloc_blocks; /* reserved ag blocks */ uint m_alloc_set_aside; /* space we can't use */ uint m_ag_max_usable; /* max space per AG */ - struct xarray m_perags; + struct xfs_groups m_groups[XG_TYPE_MAX]; uint64_t m_features; /* active filesystem features */ uint64_t m_low_space[XFS_LOWSP_MAX]; uint64_t m_rtxblkmask; /* rt extent block mask */ diff --git a/include/xfs_trace.h b/include/xfs_trace.h index 012e0018cb8367..de435a9d1a2a64 100644 --- a/include/xfs_trace.h +++ b/include/xfs_trace.h @@ -366,4 +366,11 @@ #define trace_xfs_iunlink_reload_next(...) ((void) 0) #define trace_xfs_iunlink_remove(...) ((void) 0) +#define trace_xfs_group_get(...) ((void) 0) +#define trace_xfs_group_grab_next_tag(...) ((void) 0) +#define trace_xfs_group_grab(...) ((void) 0) +#define trace_xfs_group_hold(...) ((void) 0) +#define trace_xfs_group_put(...) ((void) 0) +#define trace_xfs_group_rele(...) ((void) 0) + #endif /* __TRACE_H__ */ diff --git a/libfrog/radix-tree.h b/libfrog/radix-tree.h index fe896134eeb283..0a4e3bb4f9defc 100644 --- a/libfrog/radix-tree.h +++ b/libfrog/radix-tree.h @@ -72,6 +72,8 @@ struct xarray { struct radix_tree_root r; }; +typedef unsigned xa_mark_t; + static inline void xa_init(struct xarray *xa) { INIT_RADIX_TREE(&xa->r, GFP_KERNEL); @@ -98,4 +100,11 @@ static inline int xa_insert(struct xarray *xa, unsigned long index, void *entry, return error; } +static inline void *xa_find(struct xarray *xa, unsigned long *indexp, + unsigned long max, xa_mark_t filter) +{ + /* not implemented */ + return NULL; +} + #endif /* __LIBFROG_RADIX_TREE_H__ */ diff --git a/libxfs/Makefile b/libxfs/Makefile index aca28440adac08..470583006de69a 100644 --- a/libxfs/Makefile +++ b/libxfs/Makefile @@ -49,6 +49,7 @@ HFILES = \ xfs_dir2.h \ xfs_errortag.h \ xfs_exchmaps.h \ + xfs_group.h \ xfs_ialloc.h \ xfs_ialloc_btree.h \ xfs_inode_buf.h \ @@ -105,6 +106,7 @@ CFILES = buf_mem.c \ xfs_dir2_sf.c \ xfs_dquot_buf.c \ xfs_exchmaps.c \ + xfs_group.c \ xfs_ialloc.c \ xfs_iext_tree.c \ xfs_inode_buf.c \ diff --git a/libxfs/defer_item.c b/libxfs/defer_item.c index d5e075362ababe..f0f35361a0ff97 100644 --- a/libxfs/defer_item.c +++ b/libxfs/defer_item.c @@ -48,7 +48,7 @@ xfs_extent_free_diff_items( struct xfs_extent_free_item *ra = xefi_entry(a); struct xfs_extent_free_item *rb = xefi_entry(b); - return ra->xefi_pag->pag_agno - rb->xefi_pag->pag_agno; + return pag_agno(ra->xefi_pag) - pag_agno(rb->xefi_pag); } /* Get an EFI. */ @@ -215,7 +215,7 @@ xfs_rmap_update_diff_items( struct xfs_rmap_intent *ra = ri_entry(a); struct xfs_rmap_intent *rb = ri_entry(b); - return ra->ri_pag->pag_agno - rb->ri_pag->pag_agno; + return pag_agno(ra->ri_pag) - pag_agno(rb->ri_pag); } /* Get an RUI. */ @@ -336,7 +336,7 @@ xfs_refcount_update_diff_items( struct xfs_refcount_intent *ra = ci_entry(a); struct xfs_refcount_intent *rb = ci_entry(b); - return ra->ri_pag->pag_agno - rb->ri_pag->pag_agno; + return pag_agno(ra->ri_pag) - pag_agno(rb->ri_pag); } /* Get an CUI. */ diff --git a/libxfs/init.c b/libxfs/init.c index 483cd99546052f..beb58706629d23 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -360,7 +360,7 @@ xfs_set_inode_alloc_perag( xfs_ino_t ino, xfs_agnumber_t max_metadata) { - if (!xfs_is_inode32(pag->pag_mount)) { + if (!xfs_is_inode32(pag_mount(pag))) { set_bit(XFS_AGSTATE_ALLOWS_INODES, &pag->pag_opstate); clear_bit(XFS_AGSTATE_PREFERS_METADATA, &pag->pag_opstate); return false; @@ -373,7 +373,7 @@ xfs_set_inode_alloc_perag( } set_bit(XFS_AGSTATE_ALLOWS_INODES, &pag->pag_opstate); - if (pag->pag_agno < max_metadata) + if (pag_agno(pag) < max_metadata) set_bit(XFS_AGSTATE_PREFERS_METADATA, &pag->pag_opstate); else clear_bit(XFS_AGSTATE_PREFERS_METADATA, &pag->pag_opstate); @@ -650,6 +650,7 @@ libxfs_mount( struct xfs_buf *bp; struct xfs_sb *sbp; xfs_daddr_t d; + int i; int error; mp->m_features = xfs_sb_version_to_features(sb); @@ -667,7 +668,8 @@ libxfs_mount( mp->m_finobt_nores = true; xfs_set_inode32(mp); mp->m_sb = *sb; - xa_init(&mp->m_perags); + for (i = 0; i < XG_TYPE_MAX; i++) + xa_init(&mp->m_groups[i].xa); sbp = &mp->m_sb; spin_lock_init(&mp->m_sb_lock); spin_lock_init(&mp->m_agirotor_lock); diff --git a/libxfs/iunlink.c b/libxfs/iunlink.c index 6d0554535994c9..53e36cdc3439b2 100644 --- a/libxfs/iunlink.c +++ b/libxfs/iunlink.c @@ -65,9 +65,10 @@ xfs_iunlink_log_dinode( goto out; } - trace_xfs_iunlink_update_dinode(mp, iup->pag->pag_agno, - XFS_INO_TO_AGINO(mp, ip->i_ino), - be32_to_cpu(dip->di_next_unlinked), iup->next_agino); + trace_xfs_iunlink_update_dinode(mp, pag_agno(iup->pag), + XFS_INO_TO_AGINO(mp, ip->i_ino), + be32_to_cpu(dip->di_next_unlinked), + iup->next_agino); dip->di_next_unlinked = cpu_to_be32(iup->next_agino); offset = ip->i_imap.im_boffset + @@ -137,14 +138,14 @@ xfs_iunlink_reload_next( xfs_agino_t next_agino) { struct xfs_perag *pag = agibp->b_pag; - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); struct xfs_inode *next_ip = NULL; xfs_ino_t ino; int error; ASSERT(next_agino != NULLAGINO); - ino = XFS_AGINO_TO_INO(mp, pag->pag_agno, next_agino); + ino = XFS_AGINO_TO_INO(mp, pag_agno(pag), next_agino); error = libxfs_iget(mp, tp, ino, XFS_IGET_UNTRUSTED, &next_ip); if (error) return error; diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index e22ce4e83f4a62..15d4ac5a99f0e7 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -28,85 +28,7 @@ #include "xfs_trans.h" #include "xfs_trace.h" #include "xfs_inode.h" - - -/* - * Passive reference counting access wrappers to the perag structures. If the - * per-ag structure is to be freed, the freeing code is responsible for cleaning - * up objects with passive references before freeing the structure. This is - * things like cached buffers. - */ -struct xfs_perag * -xfs_perag_get( - struct xfs_mount *mp, - xfs_agnumber_t agno) -{ - struct xfs_perag *pag; - - rcu_read_lock(); - pag = xa_load(&mp->m_perags, agno); - if (pag) { - trace_xfs_perag_get(pag, _RET_IP_); - ASSERT(atomic_read(&pag->pag_ref) >= 0); - atomic_inc(&pag->pag_ref); - } - rcu_read_unlock(); - return pag; -} - -/* Get a passive reference to the given perag. */ -struct xfs_perag * -xfs_perag_hold( - struct xfs_perag *pag) -{ - ASSERT(atomic_read(&pag->pag_ref) > 0 || - atomic_read(&pag->pag_active_ref) > 0); - - trace_xfs_perag_hold(pag, _RET_IP_); - atomic_inc(&pag->pag_ref); - return pag; -} - -void -xfs_perag_put( - struct xfs_perag *pag) -{ - trace_xfs_perag_put(pag, _RET_IP_); - ASSERT(atomic_read(&pag->pag_ref) > 0); - atomic_dec(&pag->pag_ref); -} - -/* - * Active references for perag structures. This is for short term access to the - * per ag structures for walking trees or accessing state. If an AG is being - * shrunk or is offline, then this will fail to find that AG and return NULL - * instead. - */ -struct xfs_perag * -xfs_perag_grab( - struct xfs_mount *mp, - xfs_agnumber_t agno) -{ - struct xfs_perag *pag; - - rcu_read_lock(); - pag = xa_load(&mp->m_perags, agno); - if (pag) { - trace_xfs_perag_grab(pag, _RET_IP_); - if (!atomic_inc_not_zero(&pag->pag_active_ref)) - pag = NULL; - } - rcu_read_unlock(); - return pag; -} - -void -xfs_perag_rele( - struct xfs_perag *pag) -{ - trace_xfs_perag_rele(pag, _RET_IP_); - atomic_dec(&pag->pag_active_ref); -} +#include "xfs_group.h" /* * xfs_initialize_perag_data @@ -181,6 +103,19 @@ xfs_initialize_perag_data( return error; } +static void +xfs_perag_uninit( + struct xfs_group *xg) +{ +#ifdef __KERNEL__ + struct xfs_perag *pag = to_perag(xg); + + xfs_defer_drain_free(&pag->pag_intents_drain); + cancel_delayed_work_sync(&pag->pag_blockgc_work); + xfs_buf_cache_destroy(&pag->pag_bcache); +#endif +} + /* * Free up the per-ag resources within the specified AG range. */ @@ -193,22 +128,8 @@ xfs_free_perag_range( { xfs_agnumber_t agno; - for (agno = first_agno; agno < end_agno; agno++) { - struct xfs_perag *pag = xa_erase(&mp->m_perags, agno); - - ASSERT(pag); - XFS_IS_CORRUPT(pag->pag_mount, atomic_read(&pag->pag_ref) != 0); - xfs_defer_drain_free(&pag->pag_intents_drain); - - cancel_delayed_work_sync(&pag->pag_blockgc_work); - xfs_buf_cache_destroy(&pag->pag_bcache); - - /* drop the mount's active reference */ - xfs_perag_rele(pag); - XFS_IS_CORRUPT(pag->pag_mount, - atomic_read(&pag->pag_active_ref) != 0); - kfree_rcu_mightsleep(pag); - } + for (agno = first_agno; agno < end_agno; agno++) + xfs_group_free(mp, agno, XG_TYPE_AG, xfs_perag_uninit); } /* Find the size of the AG, in blocks. */ @@ -330,16 +251,9 @@ xfs_perag_alloc( __xfs_agino_range(mp, pag->block_count, &pag->agino_min, &pag->agino_max); - pag->pag_agno = index; - pag->pag_mount = mp; - /* Active ref owned by mount indicates AG is online. */ - atomic_set(&pag->pag_active_ref, 1); - - error = xa_insert(&mp->m_perags, index, pag, GFP_KERNEL); - if (error) { - WARN_ON_ONCE(error == -EBUSY); + error = xfs_group_insert(mp, pag_group(pag), index, XG_TYPE_AG); + if (error) goto out_buf_cache_destroy; - } return 0; @@ -831,7 +745,7 @@ xfs_ag_shrink_space( struct xfs_trans **tpp, xfs_extlen_t delta) { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); struct xfs_alloc_arg args = { .tp = *tpp, .mp = mp, @@ -848,7 +762,7 @@ xfs_ag_shrink_space( xfs_agblock_t aglen; int error, err2; - ASSERT(pag->pag_agno == mp->m_sb.sb_agcount - 1); + ASSERT(pag_agno(pag) == mp->m_sb.sb_agcount - 1); error = xfs_ialloc_read_agi(pag, *tpp, 0, &agibp); if (error) return error; @@ -945,8 +859,8 @@ xfs_ag_shrink_space( /* Update perag geometry */ pag->block_count -= delta; - __xfs_agino_range(pag->pag_mount, pag->block_count, &pag->agino_min, - &pag->agino_max); + __xfs_agino_range(mp, pag->block_count, &pag->agino_min, + &pag->agino_max); xfs_ialloc_log_agi(*tpp, agibp, XFS_AGI_LENGTH); xfs_alloc_log_agf(*tpp, agfbp, XFS_AGF_LENGTH); @@ -971,12 +885,13 @@ xfs_ag_extend_space( struct xfs_trans *tp, xfs_extlen_t len) { + struct xfs_mount *mp = pag_mount(pag); struct xfs_buf *bp; struct xfs_agi *agi; struct xfs_agf *agf; int error; - ASSERT(pag->pag_agno == pag->pag_mount->m_sb.sb_agcount - 1); + ASSERT(pag_agno(pag) == mp->m_sb.sb_agcount - 1); error = xfs_ialloc_read_agi(pag, tp, 0, &bp); if (error) @@ -1016,8 +931,8 @@ xfs_ag_extend_space( /* Update perag geometry */ pag->block_count = be32_to_cpu(agf->agf_length); - __xfs_agino_range(pag->pag_mount, pag->block_count, &pag->agino_min, - &pag->agino_max); + __xfs_agino_range(mp, pag->block_count, &pag->agino_min, + &pag->agino_max); return 0; } @@ -1044,7 +959,7 @@ xfs_ag_get_geometry( /* Fill out form. */ memset(ageo, 0, sizeof(*ageo)); - ageo->ag_number = pag->pag_agno; + ageo->ag_number = pag_agno(pag); agi = agi_bp->b_addr; ageo->ag_icount = be32_to_cpu(agi->agi_count); diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index 8787823ae37f9f..69b934ad2c4aad 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -7,6 +7,8 @@ #ifndef __LIBXFS_AG_H #define __LIBXFS_AG_H 1 +#include "xfs_group.h" + struct xfs_mount; struct xfs_trans; struct xfs_perag; @@ -30,10 +32,7 @@ struct xfs_ag_resv { * performance of allocation group selection. */ struct xfs_perag { - struct xfs_mount *pag_mount; /* owner filesystem */ - xfs_agnumber_t pag_agno; /* AG this structure belongs to */ - atomic_t pag_ref; /* passive reference count */ - atomic_t pag_active_ref; /* active reference count */ + struct xfs_group pag_group; unsigned long pag_opstate; uint8_t pagf_bno_level; /* # of levels in bno btree */ uint8_t pagf_cnt_level; /* # of levels in cnt btree */ @@ -121,6 +120,26 @@ struct xfs_perag { #endif /* __KERNEL__ */ }; +static inline struct xfs_perag *to_perag(struct xfs_group *xg) +{ + return container_of(xg, struct xfs_perag, pag_group); +} + +static inline struct xfs_group *pag_group(struct xfs_perag *pag) +{ + return &pag->pag_group; +} + +static inline struct xfs_mount *pag_mount(const struct xfs_perag *pag) +{ + return pag->pag_group.xg_mount; +} + +static inline xfs_agnumber_t pag_agno(const struct xfs_perag *pag) +{ + return pag->pag_group.xg_gno; +} + /* * Per-AG operational state. These are atomic flag bits. */ @@ -151,13 +170,43 @@ int xfs_initialize_perag_data(struct xfs_mount *mp, xfs_agnumber_t agno); int xfs_update_last_ag_size(struct xfs_mount *mp, xfs_agnumber_t prev_agcount); /* Passive AG references */ -struct xfs_perag *xfs_perag_get(struct xfs_mount *mp, xfs_agnumber_t agno); -struct xfs_perag *xfs_perag_hold(struct xfs_perag *pag); -void xfs_perag_put(struct xfs_perag *pag); +static inline struct xfs_perag * +xfs_perag_get( + struct xfs_mount *mp, + xfs_agnumber_t agno) +{ + return to_perag(xfs_group_get(mp, agno, XG_TYPE_AG)); +} + +static inline struct xfs_perag * +xfs_perag_hold( + struct xfs_perag *pag) +{ + return to_perag(xfs_group_hold(pag_group(pag))); +} + +static inline void +xfs_perag_put( + struct xfs_perag *pag) +{ + xfs_group_put(pag_group(pag)); +} /* Active AG references */ -struct xfs_perag *xfs_perag_grab(struct xfs_mount *, xfs_agnumber_t); -void xfs_perag_rele(struct xfs_perag *pag); +static inline struct xfs_perag * +xfs_perag_grab( + struct xfs_mount *mp, + xfs_agnumber_t agno) +{ + return to_perag(xfs_group_grab(mp, agno, XG_TYPE_AG)); +} + +static inline void +xfs_perag_rele( + struct xfs_perag *pag) +{ + xfs_group_rele(pag_group(pag)); +} /* * Per-ag geometry infomation and validation @@ -233,9 +282,9 @@ xfs_perag_next( xfs_agnumber_t *agno, xfs_agnumber_t end_agno) { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); - *agno = pag->pag_agno + 1; + *agno = pag_agno(pag) + 1; xfs_perag_rele(pag); while (*agno <= end_agno) { pag = xfs_perag_grab(mp, *agno); @@ -266,9 +315,9 @@ xfs_perag_next_wrap( xfs_agnumber_t restart_agno, xfs_agnumber_t wrap_agno) { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); - *agno = pag->pag_agno + 1; + *agno = pag_agno(pag) + 1; xfs_perag_rele(pag); while (*agno != stop_agno) { if (*agno >= wrap_agno) { @@ -335,7 +384,7 @@ xfs_agbno_to_fsb( struct xfs_perag *pag, xfs_agblock_t agbno) { - return XFS_AGB_TO_FSB(pag->pag_mount, pag->pag_agno, agbno); + return XFS_AGB_TO_FSB(pag_mount(pag), pag_agno(pag), agbno); } static inline xfs_daddr_t @@ -343,7 +392,7 @@ xfs_agbno_to_daddr( struct xfs_perag *pag, xfs_agblock_t agbno) { - return XFS_AGB_TO_DADDR(pag->pag_mount, pag->pag_agno, agbno); + return XFS_AGB_TO_DADDR(pag_mount(pag), pag_agno(pag), agbno); } static inline xfs_ino_t @@ -351,7 +400,7 @@ xfs_agino_to_ino( struct xfs_perag *pag, xfs_agino_t agino) { - return XFS_AGINO_TO_INO(pag->pag_mount, pag->pag_agno, agino); + return XFS_AGINO_TO_INO(pag_mount(pag), pag_agno(pag), agino); } #endif /* __LIBXFS_AG_H */ diff --git a/libxfs/xfs_ag_resv.c b/libxfs/xfs_ag_resv.c index d1657d6c636546..f5cbaa94664f22 100644 --- a/libxfs/xfs_ag_resv.c +++ b/libxfs/xfs_ag_resv.c @@ -69,6 +69,7 @@ xfs_ag_resv_critical( struct xfs_perag *pag, enum xfs_ag_resv_type type) { + struct xfs_mount *mp = pag_mount(pag); xfs_extlen_t avail; xfs_extlen_t orig; @@ -91,8 +92,8 @@ xfs_ag_resv_critical( /* Critically low if less than 10% or max btree height remains. */ return XFS_TEST_ERROR(avail < orig / 10 || - avail < pag->pag_mount->m_agbtree_maxlevels, - pag->pag_mount, XFS_ERRTAG_AG_RESV_CRITICAL); + avail < mp->m_agbtree_maxlevels, + mp, XFS_ERRTAG_AG_RESV_CRITICAL); } /* @@ -136,8 +137,8 @@ __xfs_ag_resv_free( trace_xfs_ag_resv_free(pag, type, 0); resv = xfs_perag_resv(pag, type); - if (pag->pag_agno == 0) - pag->pag_mount->m_ag_max_usable += resv->ar_asked; + if (pag_agno(pag) == 0) + pag_mount(pag)->m_ag_max_usable += resv->ar_asked; /* * RMAPBT blocks come from the AGFL and AGFL blocks are always * considered "free", so whatever was reserved at mount time must be @@ -147,7 +148,7 @@ __xfs_ag_resv_free( oldresv = resv->ar_orig_reserved; else oldresv = resv->ar_reserved; - xfs_add_fdblocks(pag->pag_mount, oldresv); + xfs_add_fdblocks(pag_mount(pag), oldresv); resv->ar_reserved = 0; resv->ar_asked = 0; resv->ar_orig_reserved = 0; @@ -169,7 +170,7 @@ __xfs_ag_resv_init( xfs_extlen_t ask, xfs_extlen_t used) { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); struct xfs_ag_resv *resv; int error; xfs_extlen_t hidden_space; @@ -208,7 +209,7 @@ __xfs_ag_resv_init( trace_xfs_ag_resv_init_error(pag, error, _RET_IP_); xfs_warn(mp, "Per-AG reservation for AG %u failed. Filesystem may run out of space.", - pag->pag_agno); + pag_agno(pag)); return error; } @@ -218,7 +219,7 @@ __xfs_ag_resv_init( * counter, we only make the adjustment for AG 0. This assumes that * there aren't any AGs hungrier for per-AG reservation than AG 0. */ - if (pag->pag_agno == 0) + if (pag_agno(pag) == 0) mp->m_ag_max_usable -= ask; resv = xfs_perag_resv(pag, type); @@ -236,7 +237,7 @@ xfs_ag_resv_init( struct xfs_perag *pag, struct xfs_trans *tp) { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); xfs_extlen_t ask; xfs_extlen_t used; int error = 0, error2; diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index bd39bcde0ea224..39e1961078ae3a 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -271,7 +271,7 @@ xfs_alloc_complain_bad_rec( xfs_warn(mp, "%sbt record corruption in AG %d detected at %pS!", - cur->bc_ops->name, cur->bc_ag.pag->pag_agno, fa); + cur->bc_ops->name, pag_agno(cur->bc_ag.pag), fa); xfs_warn(mp, "start block 0x%x block count 0x%x", irec->ar_startblock, irec->ar_blockcount); @@ -795,7 +795,7 @@ xfs_agfl_verify( * use it by using uncached buffers that don't have the perag attached * so we can detect and avoid this problem. */ - if (bp->b_pag && be32_to_cpu(agfl->agfl_seqno) != bp->b_pag->pag_agno) + if (bp->b_pag && be32_to_cpu(agfl->agfl_seqno) != pag_agno((bp->b_pag))) return __this_address; for (i = 0; i < xfs_agfl_size(mp); i++) { @@ -875,13 +875,12 @@ xfs_alloc_read_agfl( struct xfs_trans *tp, struct xfs_buf **bpp) { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); struct xfs_buf *bp; int error; - error = xfs_trans_read_buf( - mp, tp, mp->m_ddev_targp, - XFS_AG_DADDR(mp, pag->pag_agno, XFS_AGFL_DADDR(mp)), + error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, + XFS_AG_DADDR(mp, pag_agno(pag), XFS_AGFL_DADDR(mp)), XFS_FSS_TO_BB(mp, 1), 0, &bp, &xfs_agfl_buf_ops); if (xfs_metadata_is_sick(error)) xfs_ag_mark_sick(pag, XFS_SICK_AG_AGFL); @@ -2424,7 +2423,7 @@ xfs_alloc_longest_free_extent( * reservations and AGFL rules in place, we can return this extent. */ if (pag->pagf_longest > delta) - return min_t(xfs_extlen_t, pag->pag_mount->m_ag_max_usable, + return min_t(xfs_extlen_t, pag_mount(pag)->m_ag_max_usable, pag->pagf_longest - delta); /* Otherwise, let the caller try for 1 block if there's space. */ @@ -2607,7 +2606,7 @@ xfs_agfl_reset( xfs_warn(mp, "WARNING: Reset corrupted AGFL on AG %u. %d blocks leaked. " "Please unmount and run xfs_repair.", - pag->pag_agno, pag->pagf_flcount); + pag_agno(pag), pag->pagf_flcount); agf->agf_flfirst = 0; agf->agf_fllast = cpu_to_be32(xfs_agfl_size(mp) - 1); @@ -3182,7 +3181,7 @@ xfs_validate_ag_length( * use it by using uncached buffers that don't have the perag attached * so we can detect and avoid this problem. */ - if (bp->b_pag && seqno != bp->b_pag->pag_agno) + if (bp->b_pag && seqno != pag_agno(bp->b_pag)) return __this_address; /* @@ -3351,13 +3350,13 @@ xfs_read_agf( int flags, struct xfs_buf **agfbpp) { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); int error; trace_xfs_read_agf(pag); error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, - XFS_AG_DADDR(mp, pag->pag_agno, XFS_AGF_DADDR(mp)), + XFS_AG_DADDR(mp, pag_agno(pag), XFS_AGF_DADDR(mp)), XFS_FSS_TO_BB(mp, 1), flags, agfbpp, &xfs_agf_buf_ops); if (xfs_metadata_is_sick(error)) xfs_ag_mark_sick(pag, XFS_SICK_AG_AGF); @@ -3380,6 +3379,7 @@ xfs_alloc_read_agf( int flags, struct xfs_buf **agfbpp) { + struct xfs_mount *mp = pag_mount(pag); struct xfs_buf *agfbp; struct xfs_agf *agf; int error; @@ -3406,7 +3406,7 @@ xfs_alloc_read_agf( pag->pagf_cnt_level = be32_to_cpu(agf->agf_cnt_level); pag->pagf_rmap_level = be32_to_cpu(agf->agf_rmap_level); pag->pagf_refcount_level = be32_to_cpu(agf->agf_refcount_level); - if (xfs_agfl_needs_reset(pag->pag_mount, agf)) + if (xfs_agfl_needs_reset(mp, agf)) set_bit(XFS_AGSTATE_AGFL_NEEDS_RESET, &pag->pag_opstate); else clear_bit(XFS_AGSTATE_AGFL_NEEDS_RESET, &pag->pag_opstate); @@ -3419,16 +3419,15 @@ xfs_alloc_read_agf( * counter only tracks non-root blocks. */ allocbt_blks = pag->pagf_btreeblks; - if (xfs_has_rmapbt(pag->pag_mount)) + if (xfs_has_rmapbt(mp)) allocbt_blks -= be32_to_cpu(agf->agf_rmap_blocks) - 1; if (allocbt_blks > 0) - atomic64_add(allocbt_blks, - &pag->pag_mount->m_allocbt_blks); + atomic64_add(allocbt_blks, &mp->m_allocbt_blks); set_bit(XFS_AGSTATE_AGF_INIT, &pag->pag_opstate); } #ifdef DEBUG - else if (!xfs_is_shutdown(pag->pag_mount)) { + else if (!xfs_is_shutdown(mp)) { ASSERT(pag->pagf_freeblks == be32_to_cpu(agf->agf_freeblks)); ASSERT(pag->pagf_btreeblks == be32_to_cpu(agf->agf_btreeblks)); ASSERT(pag->pagf_flcount == be32_to_cpu(agf->agf_flcount)); @@ -3646,7 +3645,7 @@ xfs_alloc_vextent_this_ag( int error; ASSERT(args->pag != NULL); - ASSERT(args->pag->pag_agno == agno); + ASSERT(pag_agno(args->pag) == agno); args->agno = agno; args->agbno = 0; @@ -3859,7 +3858,7 @@ xfs_alloc_vextent_exact_bno( int error; ASSERT(args->pag != NULL); - ASSERT(args->pag->pag_agno == XFS_FSB_TO_AGNO(mp, target)); + ASSERT(pag_agno(args->pag) == XFS_FSB_TO_AGNO(mp, target)); args->agno = XFS_FSB_TO_AGNO(mp, target); args->agbno = XFS_FSB_TO_AGBNO(mp, target); @@ -3898,7 +3897,7 @@ xfs_alloc_vextent_near_bno( int error; if (!needs_perag) - ASSERT(args->pag->pag_agno == XFS_FSB_TO_AGNO(mp, target)); + ASSERT(pag_agno(args->pag) == XFS_FSB_TO_AGNO(mp, target)); args->agno = XFS_FSB_TO_AGNO(mp, target); args->agbno = XFS_FSB_TO_AGBNO(mp, target); @@ -3935,7 +3934,7 @@ xfs_free_extent_fix_freelist( memset(&args, 0, sizeof(struct xfs_alloc_arg)); args.tp = tp; args.mp = tp->t_mountp; - args.agno = pag->pag_agno; + args.agno = pag_agno(pag); args.pag = pag; /* diff --git a/libxfs/xfs_alloc_btree.c b/libxfs/xfs_alloc_btree.c index 949cd18ab16a99..667655a639fef1 100644 --- a/libxfs/xfs_alloc_btree.c +++ b/libxfs/xfs_alloc_btree.c @@ -176,7 +176,7 @@ xfs_allocbt_init_ptr_from_cur( { struct xfs_agf *agf = cur->bc_ag.agbp->b_addr; - ASSERT(cur->bc_ag.pag->pag_agno == be32_to_cpu(agf->agf_seqno)); + ASSERT(pag_agno(cur->bc_ag.pag) == be32_to_cpu(agf->agf_seqno)); if (xfs_btree_is_bno(cur->bc_ops)) ptr->s = agf->agf_bno_root; diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index aec378ff4a9193..13cd4faa492838 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -3274,7 +3274,7 @@ xfs_bmap_longest_free_extent( } longest = xfs_alloc_longest_free_extent(pag, - xfs_alloc_min_freelist(pag->pag_mount, pag), + xfs_alloc_min_freelist(pag_mount(pag), pag), xfs_ag_resv_needed(pag, XFS_AG_RESV_NONE)); if (*blen < longest) *blen = longest; diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c index 4f04a92f6513bf..2b63c18114763c 100644 --- a/libxfs/xfs_btree.c +++ b/libxfs/xfs_btree.c @@ -370,7 +370,7 @@ xfs_btree_check_ptr( case XFS_BTREE_TYPE_AG: xfs_err(cur->bc_mp, "AG %u: Corrupt %sbt pointer at level %d index %d.", - cur->bc_ag.pag->pag_agno, cur->bc_ops->name, + pag_agno(cur->bc_ag.pag), cur->bc_ops->name, level, index); break; } @@ -1310,7 +1310,7 @@ xfs_btree_owner( case XFS_BTREE_TYPE_INODE: return cur->bc_ino.ip->i_ino; case XFS_BTREE_TYPE_AG: - return cur->bc_ag.pag->pag_agno; + return pag_agno(cur->bc_ag.pag); default: ASSERT(0); return 0; @@ -4742,7 +4742,7 @@ xfs_btree_agblock_v5hdr_verify( return __this_address; if (block->bb_u.s.bb_blkno != cpu_to_be64(xfs_buf_daddr(bp))) return __this_address; - if (pag && be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno) + if (pag && be32_to_cpu(block->bb_u.s.bb_owner) != pag_agno(pag)) return __this_address; return NULL; } diff --git a/libxfs/xfs_group.c b/libxfs/xfs_group.c new file mode 100644 index 00000000000000..8a67148362b0d7 --- /dev/null +++ b/libxfs/xfs_group.c @@ -0,0 +1,168 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2018 Red Hat, Inc. + */ + +#include "libxfs_priv.h" +#include "xfs_shared.h" +#include "xfs_format.h" +#include "xfs_trans_resv.h" +#include "xfs_mount.h" +#include "xfs_trace.h" +#include "xfs_group.h" + +/* + * Groups can have passive and active references. + * + * For passive references the code freeing a group is responsible for cleaning + * up objects that hold the passive references (e.g. cached buffers). + * Routines manipulating passive references are xfs_group_get, xfs_group_hold + * and xfs_group_put. + * + * Active references are for short term access to the group for walking trees or + * accessing state. If a group is being shrunk or offlined, the lookup will fail + * to find that group and return NULL instead. + * Routines manipulating active references are xfs_group_grab and + * xfs_group_rele. + */ + +struct xfs_group * +xfs_group_get( + struct xfs_mount *mp, + uint32_t index, + enum xfs_group_type type) +{ + struct xfs_group *xg; + + rcu_read_lock(); + xg = xa_load(&mp->m_groups[type].xa, index); + if (xg) { + trace_xfs_group_get(xg, _RET_IP_); + ASSERT(atomic_read(&xg->xg_ref) >= 0); + atomic_inc(&xg->xg_ref); + } + rcu_read_unlock(); + return xg; +} + +struct xfs_group * +xfs_group_hold( + struct xfs_group *xg) +{ + ASSERT(atomic_read(&xg->xg_ref) > 0 || + atomic_read(&xg->xg_active_ref) > 0); + + trace_xfs_group_hold(xg, _RET_IP_); + atomic_inc(&xg->xg_ref); + return xg; +} + +void +xfs_group_put( + struct xfs_group *xg) +{ + trace_xfs_group_put(xg, _RET_IP_); + + ASSERT(atomic_read(&xg->xg_ref) > 0); + atomic_dec(&xg->xg_ref); +} + +struct xfs_group * +xfs_group_grab( + struct xfs_mount *mp, + uint32_t index, + enum xfs_group_type type) +{ + struct xfs_group *xg; + + rcu_read_lock(); + xg = xa_load(&mp->m_groups[type].xa, index); + if (xg) { + trace_xfs_group_grab(xg, _RET_IP_); + if (!atomic_inc_not_zero(&xg->xg_active_ref)) + xg = NULL; + } + rcu_read_unlock(); + return xg; +} + +/* + * Find the next group after @xg, or the first group if @xg is NULL. + */ +struct xfs_group * +xfs_group_grab_next_mark( + struct xfs_mount *mp, + struct xfs_group *xg, + xa_mark_t mark, + enum xfs_group_type type) +{ + unsigned long index = 0; + + if (xg) { + index = xg->xg_gno + 1; + xfs_group_rele(xg); + } + + rcu_read_lock(); + xg = xa_find(&mp->m_groups[type].xa, &index, ULONG_MAX, mark); + if (xg) { + trace_xfs_group_grab_next_tag(xg, _RET_IP_); + if (!atomic_inc_not_zero(&xg->xg_active_ref)) + xg = NULL; + } + rcu_read_unlock(); + return xg; +} + +void +xfs_group_rele( + struct xfs_group *xg) +{ + trace_xfs_group_rele(xg, _RET_IP_); + atomic_dec(&xg->xg_active_ref); +} + +void +xfs_group_free( + struct xfs_mount *mp, + uint32_t index, + enum xfs_group_type type, + void (*uninit)(struct xfs_group *xg)) +{ + struct xfs_group *xg = xa_erase(&mp->m_groups[type].xa, index); + + XFS_IS_CORRUPT(mp, atomic_read(&xg->xg_ref) != 0); + + if (uninit) + uninit(xg); + + /* drop the mount's active reference */ + xfs_group_rele(xg); + XFS_IS_CORRUPT(mp, atomic_read(&xg->xg_active_ref) != 0); + kfree_rcu_mightsleep(xg); +} + +int +xfs_group_insert( + struct xfs_mount *mp, + struct xfs_group *xg, + uint32_t index, + enum xfs_group_type type) +{ + int error; + + xg->xg_mount = mp; + xg->xg_gno = index; + xg->xg_type = type; + + /* Active ref owned by mount indicates group is online. */ + atomic_set(&xg->xg_active_ref, 1); + + error = xa_insert(&mp->m_groups[type].xa, index, xg, GFP_KERNEL); + if (error) { + WARN_ON_ONCE(error == -EBUSY); + return error; + } + + return 0; +} diff --git a/libxfs/xfs_group.h b/libxfs/xfs_group.h new file mode 100644 index 00000000000000..e3b6be7ff9e802 --- /dev/null +++ b/libxfs/xfs_group.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2018 Red Hat, Inc. + */ +#ifndef __LIBXFS_GROUP_H +#define __LIBXFS_GROUP_H 1 + +struct xfs_group { + struct xfs_mount *xg_mount; + uint32_t xg_gno; + enum xfs_group_type xg_type; + atomic_t xg_ref; /* passive reference count */ + atomic_t xg_active_ref; /* active reference count */ +}; + +struct xfs_group *xfs_group_get(struct xfs_mount *mp, uint32_t index, + enum xfs_group_type type); +struct xfs_group *xfs_group_hold(struct xfs_group *xg); +void xfs_group_put(struct xfs_group *xg); + +struct xfs_group *xfs_group_grab(struct xfs_mount *mp, uint32_t index, + enum xfs_group_type type); +struct xfs_group *xfs_group_grab_next_mark(struct xfs_mount *mp, + struct xfs_group *xg, xa_mark_t mark, enum xfs_group_type type); +void xfs_group_rele(struct xfs_group *xg); + +void xfs_group_free(struct xfs_mount *mp, uint32_t index, + enum xfs_group_type type, void (*uninit)(struct xfs_group *xg)); +int xfs_group_insert(struct xfs_mount *mp, struct xfs_group *xg, + uint32_t index, enum xfs_group_type); + +#define xfs_group_set_mark(_xg, _mark) \ + xa_set_mark(&(_xg)->xg_mount->m_groups[(_xg)->xg_type].xa, \ + (_xg)->xg_gno, (_mark)) +#define xfs_group_clear_mark(_xg, _mark) \ + xa_clear_mark(&(_xg)->xg_mount->m_groups[(_xg)->xg_type].xa, \ + (_xg)->xg_gno, (_mark)) +#define xfs_group_marked(_mp, _type, _mark) \ + xa_marked(&(_mp)->m_groups[(_type)].xa, (_mark)) + +#endif /* __LIBXFS_GROUP_H */ diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c index 4f087e6b074081..e4b9d3e2fbb5ce 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -137,7 +137,7 @@ xfs_inobt_complain_bad_rec( xfs_warn(mp, "%sbt record corruption in AG %d detected at %pS!", - cur->bc_ops->name, cur->bc_ag.pag->pag_agno, fa); + cur->bc_ops->name, pag_agno(cur->bc_ag.pag), fa); xfs_warn(mp, "start inode 0x%x, count 0x%x, free 0x%x freemask 0x%llx, holemask 0x%x", irec->ir_startino, irec->ir_count, irec->ir_freecount, @@ -546,7 +546,7 @@ xfs_inobt_insert_sprec( struct xfs_buf *agbp, struct xfs_inobt_rec_incore *nrec) /* in/out: new/merged rec. */ { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); struct xfs_btree_cur *cur; int error; int i; @@ -640,7 +640,7 @@ xfs_finobt_insert_sprec( struct xfs_buf *agbp, struct xfs_inobt_rec_incore *nrec) /* in/out: new rec. */ { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); struct xfs_btree_cur *cur; int error; int i; @@ -875,7 +875,7 @@ xfs_ialloc_ag_alloc( * rather than a linear progression to prevent the next generation * number from being easily guessable. */ - error = xfs_ialloc_inode_init(args.mp, tp, NULL, newlen, pag->pag_agno, + error = xfs_ialloc_inode_init(args.mp, tp, NULL, newlen, pag_agno(pag), args.agbno, args.len, get_random_u32()); if (error) @@ -1066,7 +1066,7 @@ xfs_dialloc_check_ino( if (error) return -EAGAIN; - error = xfs_imap_to_bp(pag->pag_mount, tp, &imap, &bp); + error = xfs_imap_to_bp(pag_mount(pag), tp, &imap, &bp); if (error) return -EAGAIN; @@ -1117,7 +1117,7 @@ xfs_dialloc_ag_inobt( /* * If in the same AG as the parent, try to get near the parent. */ - if (pagno == pag->pag_agno) { + if (pagno == pag_agno(pag)) { int doneleft; /* done, to the left */ int doneright; /* done, to the right */ @@ -1594,7 +1594,7 @@ xfs_dialloc_ag( * parent. If so, find the closest available inode to the parent. If * not, consider the agi hint or find the first free inode in the AG. */ - if (pag->pag_agno == pagno) + if (pag_agno(pag) == pagno) error = xfs_dialloc_ag_finobt_near(pagino, &cur, &rec); else error = xfs_dialloc_ag_finobt_newino(agi, cur, &rec); @@ -2048,7 +2048,7 @@ xfs_difree_inobt( struct xfs_icluster *xic, struct xfs_inobt_rec_incore *orec) { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); struct xfs_agi *agi = agbp->b_addr; struct xfs_btree_cur *cur; struct xfs_inobt_rec_incore rec; @@ -2182,7 +2182,7 @@ xfs_difree_finobt( xfs_agino_t agino, struct xfs_inobt_rec_incore *ibtrec) /* inobt record */ { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); struct xfs_btree_cur *cur; struct xfs_inobt_rec_incore rec; int offset = agino - ibtrec->ir_startino; @@ -2305,9 +2305,9 @@ xfs_difree( /* * Break up inode number into its components. */ - if (pag->pag_agno != XFS_INO_TO_AGNO(mp, inode)) { - xfs_warn(mp, "%s: agno != pag->pag_agno (%d != %d).", - __func__, XFS_INO_TO_AGNO(mp, inode), pag->pag_agno); + if (pag_agno(pag) != XFS_INO_TO_AGNO(mp, inode)) { + xfs_warn(mp, "%s: agno != pag_agno(pag) (%d != %d).", + __func__, XFS_INO_TO_AGNO(mp, inode), pag_agno(pag)); ASSERT(0); return -EINVAL; } @@ -2368,7 +2368,7 @@ xfs_imap_lookup( xfs_agblock_t *offset_agbno, int flags) { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); struct xfs_inobt_rec_incore rec; struct xfs_btree_cur *cur; struct xfs_buf *agbp; @@ -2379,7 +2379,7 @@ xfs_imap_lookup( if (error) { xfs_alert(mp, "%s: xfs_ialloc_read_agi() returned error %d, agno %d", - __func__, error, pag->pag_agno); + __func__, error, pag_agno(pag)); return error; } @@ -2429,7 +2429,7 @@ xfs_imap( struct xfs_imap *imap, /* location map structure */ uint flags) /* flags for inode btree lookup */ { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); xfs_agblock_t agbno; /* block number of inode in the alloc group */ xfs_agino_t agino; /* inode number within alloc group */ xfs_agblock_t chunk_agbno; /* first block in inode chunk */ @@ -2721,13 +2721,13 @@ xfs_read_agi( xfs_buf_flags_t flags, struct xfs_buf **agibpp) { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); int error; trace_xfs_read_agi(pag); error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, - XFS_AG_DADDR(mp, pag->pag_agno, XFS_AGI_DADDR(mp)), + XFS_AG_DADDR(mp, pag_agno(pag), XFS_AGI_DADDR(mp)), XFS_FSS_TO_BB(mp, 1), flags, agibpp, &xfs_agi_buf_ops); if (xfs_metadata_is_sick(error)) xfs_ag_mark_sick(pag, XFS_SICK_AG_AGI); @@ -2775,7 +2775,7 @@ xfs_ialloc_read_agi( * we are in the middle of a forced shutdown. */ ASSERT(pag->pagi_freecount == be32_to_cpu(agi->agi_freecount) || - xfs_is_shutdown(pag->pag_mount)); + xfs_is_shutdown(pag_mount(pag))); if (agibpp) *agibpp = agibp; else @@ -3114,13 +3114,13 @@ xfs_ialloc_check_shrink( int has; int error; - if (!xfs_has_sparseinodes(pag->pag_mount)) + if (!xfs_has_sparseinodes(pag_mount(pag))) return 0; cur = xfs_inobt_init_cursor(pag, tp, agibp); /* Look up the inobt record that would correspond to the new EOFS. */ - agino = XFS_AGB_TO_AGINO(pag->pag_mount, new_length); + agino = XFS_AGB_TO_AGINO(pag_mount(pag), new_length); error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, &has); if (error || !has) goto out; diff --git a/libxfs/xfs_ialloc_btree.c b/libxfs/xfs_ialloc_btree.c index f80368b4d5fa5f..45908cce464dff 100644 --- a/libxfs/xfs_ialloc_btree.c +++ b/libxfs/xfs_ialloc_btree.c @@ -247,7 +247,7 @@ xfs_inobt_init_ptr_from_cur( { struct xfs_agi *agi = cur->bc_ag.agbp->b_addr; - ASSERT(cur->bc_ag.pag->pag_agno == be32_to_cpu(agi->agi_seqno)); + ASSERT(pag_agno(cur->bc_ag.pag) == be32_to_cpu(agi->agi_seqno)); ptr->s = agi->agi_root; } @@ -259,7 +259,7 @@ xfs_finobt_init_ptr_from_cur( { struct xfs_agi *agi = cur->bc_ag.agbp->b_addr; - ASSERT(cur->bc_ag.pag->pag_agno == be32_to_cpu(agi->agi_seqno)); + ASSERT(pag_agno(cur->bc_ag.pag) == be32_to_cpu(agi->agi_seqno)); ptr->s = agi->agi_free_root; } @@ -477,7 +477,7 @@ xfs_inobt_init_cursor( struct xfs_trans *tp, struct xfs_buf *agbp) { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); struct xfs_btree_cur *cur; cur = xfs_btree_alloc_cursor(mp, tp, &xfs_inobt_ops, @@ -503,7 +503,7 @@ xfs_finobt_init_cursor( struct xfs_trans *tp, struct xfs_buf *agbp) { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); struct xfs_btree_cur *cur; cur = xfs_btree_alloc_cursor(mp, tp, &xfs_finobt_ops, @@ -714,7 +714,7 @@ static xfs_extlen_t xfs_inobt_max_size( struct xfs_perag *pag) { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); xfs_agblock_t agblocks = pag->block_count; /* Bail out if we're uninitialized, which can happen in mkfs. */ @@ -726,7 +726,7 @@ xfs_inobt_max_size( * never be available for the kinds of things that would require btree * expansion. We therefore can pretend the space isn't there. */ - if (xfs_ag_contains_log(mp, pag->pag_agno)) + if (xfs_ag_contains_log(mp, pag_agno(pag))) agblocks -= mp->m_sb.sb_logblocks; return xfs_btree_calc_size(M_IGEO(mp)->inobt_mnr, @@ -790,10 +790,10 @@ xfs_finobt_calc_reserves( xfs_extlen_t tree_len = 0; int error; - if (!xfs_has_finobt(pag->pag_mount)) + if (!xfs_has_finobt(pag_mount(pag))) return 0; - if (xfs_has_inobtcounts(pag->pag_mount)) + if (xfs_has_inobtcounts(pag_mount(pag))) error = xfs_finobt_read_blocks(pag, tp, &tree_len); else error = xfs_finobt_count_blocks(pag, tp, &tree_len); diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index eeddec68a08539..9507cf74578d4f 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -153,7 +153,7 @@ xfs_refcount_complain_bad_rec( xfs_warn(mp, "Refcount BTree record corruption in AG %d detected at %pS!", - cur->bc_ag.pag->pag_agno, fa); + pag_agno(cur->bc_ag.pag), fa); xfs_warn(mp, "Start block 0x%x, block count 0x%x, references 0x%x", irec->rc_startblock, irec->rc_blockcount, irec->rc_refcount); @@ -1320,7 +1320,7 @@ xfs_refcount_continue_op( ri->ri_startblock = xfs_agbno_to_fsb(pag, new_agbno); ASSERT(xfs_verify_fsbext(mp, ri->ri_startblock, ri->ri_blockcount)); - ASSERT(pag->pag_agno == XFS_FSB_TO_AGNO(mp, ri->ri_startblock)); + ASSERT(pag_agno(pag) == XFS_FSB_TO_AGNO(mp, ri->ri_startblock)); return 0; } diff --git a/libxfs/xfs_refcount_btree.c b/libxfs/xfs_refcount_btree.c index 5913f4176889ea..e9c4fc419a6114 100644 --- a/libxfs/xfs_refcount_btree.c +++ b/libxfs/xfs_refcount_btree.c @@ -80,7 +80,7 @@ xfs_refcountbt_alloc_block( *stat = 0; return 0; } - ASSERT(args.agno == cur->bc_ag.pag->pag_agno); + ASSERT(args.agno == pag_agno(cur->bc_ag.pag)); ASSERT(args.len == 1); new->s = cpu_to_be32(args.agbno); @@ -168,7 +168,7 @@ xfs_refcountbt_init_ptr_from_cur( { struct xfs_agf *agf = cur->bc_ag.agbp->b_addr; - ASSERT(cur->bc_ag.pag->pag_agno == be32_to_cpu(agf->agf_seqno)); + ASSERT(pag_agno(cur->bc_ag.pag) == be32_to_cpu(agf->agf_seqno)); ptr->s = agf->agf_refcount_root; } @@ -360,7 +360,7 @@ xfs_refcountbt_init_cursor( { struct xfs_btree_cur *cur; - ASSERT(pag->pag_agno < mp->m_sb.sb_agcount); + ASSERT(pag_agno(pag) < mp->m_sb.sb_agcount); cur = xfs_btree_alloc_cursor(mp, tp, &xfs_refcountbt_ops, mp->m_refc_maxlevels, xfs_refcountbt_cur_cache); @@ -513,7 +513,7 @@ xfs_refcountbt_calc_reserves( * never be available for the kinds of things that would require btree * expansion. We therefore can pretend the space isn't there. */ - if (xfs_ag_contains_log(mp, pag->pag_agno)) + if (xfs_ag_contains_log(mp, pag_agno(pag))) agblocks -= mp->m_sb.sb_logblocks; *ask += xfs_refcountbt_max_size(mp, agblocks); diff --git a/libxfs/xfs_rmap.c b/libxfs/xfs_rmap.c index 22947e3c9ae310..0f7dee40bda87a 100644 --- a/libxfs/xfs_rmap.c +++ b/libxfs/xfs_rmap.c @@ -212,7 +212,7 @@ xfs_rmap_check_irec( struct xfs_perag *pag, const struct xfs_rmap_irec *irec) { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); bool is_inode; bool is_unwritten; bool is_bmbt; @@ -287,7 +287,7 @@ xfs_rmap_complain_bad_rec( else xfs_warn(mp, "Reverse Mapping BTree record corruption in AG %d detected at %pS!", - cur->bc_ag.pag->pag_agno, fa); + pag_agno(cur->bc_ag.pag), fa); xfs_warn(mp, "Owner 0x%llx, flags 0x%x, start block 0x%x block count 0x%x", irec->rm_owner, irec->rm_flags, irec->rm_startblock, diff --git a/libxfs/xfs_rmap_btree.c b/libxfs/xfs_rmap_btree.c index c261d6eae3bc3b..ebb2519cf8baf3 100644 --- a/libxfs/xfs_rmap_btree.c +++ b/libxfs/xfs_rmap_btree.c @@ -226,7 +226,7 @@ xfs_rmapbt_init_ptr_from_cur( { struct xfs_agf *agf = cur->bc_ag.agbp->b_addr; - ASSERT(cur->bc_ag.pag->pag_agno == be32_to_cpu(agf->agf_seqno)); + ASSERT(pag_agno(cur->bc_ag.pag) == be32_to_cpu(agf->agf_seqno)); ptr->s = agf->agf_rmap_root; } @@ -646,9 +646,8 @@ xfs_rmapbt_mem_cursor( struct xfbtree *xfbt) { struct xfs_btree_cur *cur; - struct xfs_mount *mp = pag->pag_mount; - cur = xfs_btree_alloc_cursor(mp, tp, &xfs_rmapbt_mem_ops, + cur = xfs_btree_alloc_cursor(pag_mount(pag), tp, &xfs_rmapbt_mem_ops, xfs_rmapbt_maxlevels_ondisk(), xfs_rmapbt_cur_cache); cur->bc_mem.xfbtree = xfbt; cur->bc_nlevels = xfbt->nlevels; @@ -862,7 +861,7 @@ xfs_rmapbt_calc_reserves( * never be available for the kinds of things that would require btree * expansion. We therefore can pretend the space isn't there. */ - if (xfs_ag_contains_log(mp, pag->pag_agno)) + if (xfs_ag_contains_log(mp, pag_agno(pag))) agblocks -= mp->m_sb.sb_logblocks; /* Reserve 1% of the AG or enough for 1 block per record. */ diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index 0d98b8a344209e..f534ae5d4c4db2 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -1131,7 +1131,7 @@ xfs_update_secondary_sbs( struct xfs_buf *bp; error = xfs_buf_get(mp->m_ddev_targp, - XFS_AG_DADDR(mp, pag->pag_agno, XFS_SB_DADDR), + XFS_AG_DADDR(mp, pag_agno(pag), XFS_SB_DADDR), XFS_FSS_TO_BB(mp, 1), &bp); /* * If we get an error reading or writing alternate superblocks, @@ -1143,7 +1143,7 @@ xfs_update_secondary_sbs( if (error) { xfs_warn(mp, "error allocating secondary superblock for ag %d", - pag->pag_agno); + pag_agno(pag)); if (!saved_error) saved_error = error; continue; @@ -1164,7 +1164,7 @@ xfs_update_secondary_sbs( if (error) { xfs_warn(mp, "write error %d updating a secondary superblock near ag %d", - error, pag->pag_agno); + error, pag_agno(pag)); if (!saved_error) saved_error = error; continue; diff --git a/libxfs/xfs_types.h b/libxfs/xfs_types.h index a8cd44d03ef648..d3cb6ff3b91301 100644 --- a/libxfs/xfs_types.h +++ b/libxfs/xfs_types.h @@ -212,6 +212,14 @@ enum xbtree_recpacking { XBTREE_RECPACKING_FULL, }; +enum xfs_group_type { + XG_TYPE_AG, + XG_TYPE_MAX, +} __packed; + +#define XG_TYPE_STRINGS \ + { XG_TYPE_AG, "ag" } + /* * Type verifier functions */ diff --git a/repair/agbtree.c b/repair/agbtree.c index c8f75f49e6b363..67baa1acba9907 100644 --- a/repair/agbtree.c +++ b/repair/agbtree.c @@ -166,8 +166,7 @@ finish_rebuild( if (resv->used == resv->len) continue; - fsbno = XFS_AGB_TO_FSB(mp, resv->pag->pag_agno, - resv->agbno + resv->used); + fsbno = xfs_agbno_to_fsb(resv->pag, resv->agbno + resv->used); error = bitmap_set(lost_blocks, fsbno, resv->len - resv->used); if (error) do_error( @@ -203,7 +202,7 @@ get_bno_rec( struct xfs_btree_cur *cur, struct extent_tree_node *prev_value) { - xfs_agnumber_t agno = cur->bc_ag.pag->pag_agno; + xfs_agnumber_t agno = pag_agno(cur->bc_ag.pag); if (xfs_btree_is_bno(cur->bc_ops)) { if (!prev_value) @@ -254,7 +253,7 @@ init_freespace_cursors( struct bt_rebuild *btr_bno, struct bt_rebuild *btr_cnt) { - xfs_agnumber_t agno = pag->pag_agno; + xfs_agnumber_t agno = pag_agno(pag); unsigned int agfl_goal; int error; @@ -377,7 +376,7 @@ get_ino_rec( struct xfs_btree_cur *cur, struct ino_tree_node *prev_value) { - xfs_agnumber_t agno = cur->bc_ag.pag->pag_agno; + xfs_agnumber_t agno = pag_agno(cur->bc_ag.pag); if (xfs_btree_is_ino(cur->bc_ops)) { if (!prev_value) @@ -482,7 +481,7 @@ init_ino_cursors( struct bt_rebuild *btr_fino) { struct ino_tree_node *ino_rec; - xfs_agnumber_t agno = pag->pag_agno; + xfs_agnumber_t agno = pag_agno(pag); unsigned int ino_recs = 0; unsigned int fino_recs = 0; bool finobt; @@ -615,7 +614,7 @@ get_rmapbt_records( if (ret == 0) do_error( _("ran out of records while rebuilding AG %u rmap btree\n"), - cur->bc_ag.pag->pag_agno); + pag_agno(cur->bc_ag.pag)); block_rec = libxfs_btree_rec_addr(cur, idx, block); cur->bc_ops->init_rec_from_cur(cur, block_rec); @@ -632,7 +631,7 @@ init_rmapbt_cursor( unsigned int est_agfreeblocks, struct bt_rebuild *btr) { - xfs_agnumber_t agno = pag->pag_agno; + xfs_agnumber_t agno = pag_agno(pag); int error; if (!xfs_has_rmapbt(sc->mp)) @@ -715,7 +714,7 @@ init_refc_cursor( unsigned int est_agfreeblocks, struct bt_rebuild *btr) { - xfs_agnumber_t agno = pag->pag_agno; + xfs_agnumber_t agno = pag_agno(pag); int error; if (!xfs_has_reflink(sc->mp)) @@ -769,7 +768,7 @@ estimate_allocbt_blocks( unsigned int nr_extents) { /* Account for space consumed by both free space btrees */ - return libxfs_allocbt_calc_size(pag->pag_mount, nr_extents) * 2; + return libxfs_allocbt_calc_size(pag_mount(pag), nr_extents) * 2; } static xfs_extlen_t @@ -777,7 +776,7 @@ estimate_inobt_blocks( struct xfs_perag *pag) { struct ino_tree_node *ino_rec; - xfs_agnumber_t agno = pag->pag_agno; + xfs_agnumber_t agno = pag_agno(pag); unsigned int ino_recs = 0; unsigned int fino_recs = 0; xfs_extlen_t ret; @@ -807,9 +806,9 @@ estimate_inobt_blocks( fino_recs++; } - ret = libxfs_iallocbt_calc_size(pag->pag_mount, ino_recs); - if (xfs_has_finobt(pag->pag_mount)) - ret += libxfs_iallocbt_calc_size(pag->pag_mount, fino_recs); + ret = libxfs_iallocbt_calc_size(pag_mount(pag), ino_recs); + if (xfs_has_finobt(pag_mount(pag))) + ret += libxfs_iallocbt_calc_size(pag_mount(pag), fino_recs); return ret; } diff --git a/repair/bmap_repair.c b/repair/bmap_repair.c index b341caf627d5fd..7ccbb96fa8dc5e 100644 --- a/repair/bmap_repair.c +++ b/repair/bmap_repair.c @@ -129,7 +129,6 @@ xrep_bmap_walk_rmap( void *priv) { struct xrep_bmap *rb = priv; - struct xfs_mount *mp = cur->bc_mp; xfs_fsblock_t fsbno; int error; @@ -155,8 +154,7 @@ xrep_bmap_walk_rmap( !(rec->rm_flags & XFS_RMAP_ATTR_FORK)) return 0; - fsbno = XFS_AGB_TO_FSB(mp, cur->bc_ag.pag->pag_agno, - rec->rm_startblock); + fsbno = xfs_agbno_to_fsb(cur->bc_ag.pag, rec->rm_startblock); if (rec->rm_flags & XFS_RMAP_BMBT_BLOCK) { rb->old_bmbt_block_count += rec->rm_blockcount; diff --git a/repair/bulkload.c b/repair/bulkload.c index c96e569ef2979e..aada5bbae579f8 100644 --- a/repair/bulkload.c +++ b/repair/bulkload.c @@ -74,11 +74,10 @@ bulkload_add_extent( xfs_agblock_t agbno, xfs_extlen_t len) { - struct xfs_mount *mp = bkl->sc->mp; struct xfs_alloc_arg args = { .tp = NULL, /* no autoreap */ .oinfo = bkl->oinfo, - .fsbno = XFS_AGB_TO_FSB(mp, pag->pag_agno, agbno), + .fsbno = xfs_agbno_to_fsb(pag, agbno), .len = len, .resv = XFS_AG_RESV_NONE, }; @@ -194,7 +193,7 @@ bulkload_free_extent( * Use EFIs to free the reservations. We don't need to use EFIs here * like the kernel, but we'll do it to keep the code matched. */ - fsbno = XFS_AGB_TO_FSB(sc->mp, resv->pag->pag_agno, free_agbno); + fsbno = xfs_agbno_to_fsb(resv->pag, free_agbno); error = -libxfs_free_extent_later(sc->tp, fsbno, free_aglen, &bkl->oinfo, XFS_AG_RESV_NONE, XFS_FREE_EXTENT_SKIP_DISCARD); @@ -290,7 +289,6 @@ bulkload_claim_block( union xfs_btree_ptr *ptr) { struct bulkload_resv *resv; - struct xfs_mount *mp = cur->bc_mp; xfs_agblock_t agbno; /* @@ -316,8 +314,7 @@ bulkload_claim_block( list_move_tail(&resv->list, &bkl->resv_list); if (cur->bc_ops->ptr_len == XFS_BTREE_LONG_PTR_LEN) - ptr->l = cpu_to_be64(XFS_AGB_TO_FSB(mp, resv->pag->pag_agno, - agbno)); + ptr->l = cpu_to_be64(xfs_agbno_to_fsb(resv->pag, agbno)); else ptr->s = cpu_to_be32(agbno); return 0; diff --git a/repair/phase2.c b/repair/phase2.c index e50cd3f8c2759d..42a2861dcc3714 100644 --- a/repair/phase2.c +++ b/repair/phase2.c @@ -304,13 +304,13 @@ check_fs_free_space( if (error) do_error( _("Cannot read AGI %u for upgrade check, err=%d.\n"), - pag->pag_agno, error); + pag_agno(pag), error); error = -libxfs_alloc_read_agf(pag, tp, 0, &agf_bp); if (error) do_error( _("Cannot read AGF %u for upgrade check, err=%d.\n"), - pag->pag_agno, error); + pag_agno(pag), error); agf = agf_bp->b_addr; agblocks = be32_to_cpu(agf->agf_length); @@ -326,13 +326,13 @@ check_fs_free_space( if (error == ENOSPC) { printf( _("Not enough free space would remain in AG %u for metadata.\n"), - pag->pag_agno); + pag_agno(pag)); exit(1); } if (error) do_error( _("Error %d while checking AG %u space reservation.\n"), - error, pag->pag_agno); + error, pag_agno(pag)); /* * Would the post-upgrade filesystem have enough free space in @@ -345,7 +345,7 @@ check_fs_free_space( if (!check_free_space(mp, avail, agblocks)) { printf( _("AG %u will be low on space after upgrade.\n"), - pag->pag_agno); + pag_agno(pag)); exit(1); } libxfs_trans_cancel(tp); diff --git a/repair/phase5.c b/repair/phase5.c index 9207da7172c05b..fdbd9f56998fb4 100644 --- a/repair/phase5.c +++ b/repair/phase5.c @@ -441,7 +441,7 @@ phase5_func( struct bt_rebuild btr_fino; struct bt_rebuild btr_rmap; struct bt_rebuild btr_refc; - xfs_agnumber_t agno = pag->pag_agno; + xfs_agnumber_t agno = pag_agno(pag); int extra_blocks = 0; uint num_freeblocks; xfs_agblock_t num_extents; diff --git a/repair/rmap.c b/repair/rmap.c index 553c7a6c3658a0..29af74eee11831 100644 --- a/repair/rmap.c +++ b/repair/rmap.c @@ -1694,7 +1694,7 @@ xfs_extlen_t estimate_rmapbt_blocks( struct xfs_perag *pag) { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); struct xfs_ag_rmap *x; unsigned long long nr_recs = 0; @@ -1707,12 +1707,12 @@ estimate_rmapbt_blocks( * means we can use SEEK_DATA/HOLE on the xfile, which is faster than * walking the entire btree to count records. */ - x = &ag_rmaps[pag->pag_agno]; + x = &ag_rmaps[pag_agno(pag)]; if (!rmaps_has_observations(x)) return 0; nr_recs = xmbuf_bytes(x->ar_xmbtp) / sizeof(struct xfs_rmap_rec); - return libxfs_rmapbt_calc_size(pag->pag_mount, nr_recs); + return libxfs_rmapbt_calc_size(pag_mount(pag), nr_recs); } /* Estimate the size of the ondisk refcountbt from the incore data. */ @@ -1720,13 +1720,13 @@ xfs_extlen_t estimate_refcountbt_blocks( struct xfs_perag *pag) { - struct xfs_mount *mp = pag->pag_mount; + struct xfs_mount *mp = pag_mount(pag); struct xfs_ag_rmap *x; if (!rmap_needs_work(mp) || !xfs_has_reflink(mp)) return 0; - x = &ag_rmaps[pag->pag_agno]; + x = &ag_rmaps[pag_agno(pag)]; if (!x->ar_refcount_items) return 0; From patchwork Mon Dec 23 21:41:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13919248 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 448E218052 for ; Mon, 23 Dec 2024 21:41: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=1734990078; cv=none; b=mABqpgMleJZn61vRBueuVokY5SYZXczZeeKmn7de+uBViaJO8JqnZW3k/Evz+JBxpDMtvJdypqMs0OkPEUVnv/XefXZjDn86KKV2dhLzLBtxWE/ZzUOZWxWpRw7McYk0KV01Zw1miqTln49KgPp0CEDWj8550IKAEOPM9GQ69J8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990078; c=relaxed/simple; bh=+Zz/NXzkIN7ajYVouiv0ruG4AwetK7xTkqG/Ddykk1Y=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Hu14dvNKp95zd8t+VZZljTmGyCdtW2SjSwQJ9fnB0A90CsDCEDIXjsIyQ7pcHCn7c5HVFjQWFwFSmq3G8ZDmCj4m4UfD8DI4Eq9PxHZWBWkl54jSToBCZJV1+chvkHQFz+KRKnKLS6RZnrrVUsUg4XPWZXumpNTCNCGEFoXv69Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WB7GyTzM; 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="WB7GyTzM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18CD2C4CED3; Mon, 23 Dec 2024 21:41:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990078; bh=+Zz/NXzkIN7ajYVouiv0ruG4AwetK7xTkqG/Ddykk1Y=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=WB7GyTzMt12UBTn6MiYdqJibtlg0UinZNpUbKudI2Sn3gkPzzzji2Tlzb/HFMFe6g GoyrbRiJidVMjC5q00wZEoZtdWR/AGnsOx8LK3HwcVNlFgY+cDk9X6dyHG637e2czo a33VYuuCIpBBqKFPLmcOj6z+j6JImNDhsp91hLsh8S7SaTKLu9HcltyJ8GQCpZdwH+ pUUW/pvOcLTwofyf4PYvzofsy0L7yJRYxvsiE0lXp95QEhu9hi207a4yCB6Hg6oEPL 2X8Xmj+CVISxXdTQhZoAzx6x3xeXoOMQwm+vZYEJLfC07QSE3FBqpJ2NX9pxJBKAgm RArrOaTMqk5UQ== Date: Mon, 23 Dec 2024 13:41:17 -0800 Subject: [PATCH 16/36] xfs: add a xfs_group_next_range helper From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940189.2293042.12796489335865903644.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 819928770bd91960f88f5a4dfa21b35a1bade61b Add a helper to iterate over iterate over all groups, which can be used as a simple while loop: struct xfs_group *xg = NULL; while ((xg = xfs_group_next_range(mp, xg, 0, MAX_GROUP))) { ... } This will be wrapped by the realtime group code first, and eventually replace the for_each_rtgroup_from and for_each_rtgroup_range helpers. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_group.c | 26 ++++++++++++++++++++++++++ libxfs/xfs_group.h | 3 +++ 2 files changed, 29 insertions(+) diff --git a/libxfs/xfs_group.c b/libxfs/xfs_group.c index 8a67148362b0d7..04d65033b75eca 100644 --- a/libxfs/xfs_group.c +++ b/libxfs/xfs_group.c @@ -86,6 +86,32 @@ xfs_group_grab( return xg; } +/* + * Iterate to the next group. To start the iteration at @start_index, a %NULL + * @xg is passed, else the previous group returned from this function. The + * caller should break out of the loop when this returns %NULL. If the caller + * wants to break out of a loop that did not finish it needs to release the + * active reference to @xg using xfs_group_rele() itself. + */ +struct xfs_group * +xfs_group_next_range( + struct xfs_mount *mp, + struct xfs_group *xg, + uint32_t start_index, + uint32_t end_index, + enum xfs_group_type type) +{ + uint32_t index = start_index; + + if (xg) { + index = xg->xg_gno + 1; + xfs_group_rele(xg); + } + if (index > end_index) + return NULL; + return xfs_group_grab(mp, index, type); +} + /* * Find the next group after @xg, or the first group if @xg is NULL. */ diff --git a/libxfs/xfs_group.h b/libxfs/xfs_group.h index e3b6be7ff9e802..dd7da90443054b 100644 --- a/libxfs/xfs_group.h +++ b/libxfs/xfs_group.h @@ -20,6 +20,9 @@ void xfs_group_put(struct xfs_group *xg); struct xfs_group *xfs_group_grab(struct xfs_mount *mp, uint32_t index, enum xfs_group_type type); +struct xfs_group *xfs_group_next_range(struct xfs_mount *mp, + struct xfs_group *xg, uint32_t start_index, uint32_t end_index, + enum xfs_group_type type); struct xfs_group *xfs_group_grab_next_mark(struct xfs_mount *mp, struct xfs_group *xg, xa_mark_t mark, enum xfs_group_type type); void xfs_group_rele(struct xfs_group *xg); From patchwork Mon Dec 23 21:41: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: 13919249 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 D5D7D74BE1 for ; Mon, 23 Dec 2024 21:41:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990093; cv=none; b=vGinAMiyBsrqm3JMX4lnssbsDfSf9/WXcITEqbFH/lD/vm9PmQ6llDV0bollrONkwCKj6+pjYdJwLjEpkmFNfT1LOL0mMSvavIMbsBmbmGiXtdn5HNWpGCkCv3iFSpakvOA6imb4mMU03hogSJ2A8NHhnCXQOJBa0TVqVUmwSnc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990093; c=relaxed/simple; bh=JzsxW+FJHWMJarDaW72SB/GERXiRr/fBWOA/8j2xTqA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XkyOP4OuIknPjOZJcMH/XiFOf5cjX2R8+89o32RP7jwOkA2qRHE/MdiqoKzaTyAdQwhMD5w/2sgUzuDRRRqChhxYch7N+uJes6svVPB61xfjuGLTurRCQXmh8qUcTLLQ+oFnqw/vy1XUKMoC6Wxs7AQTu2cTeBv15yO2PkdCzNU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NkHMn6Q3; 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="NkHMn6Q3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0611C4CED3; Mon, 23 Dec 2024 21:41:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990093; bh=JzsxW+FJHWMJarDaW72SB/GERXiRr/fBWOA/8j2xTqA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=NkHMn6Q3q6NU4Urtzo1SHqH5SXhF+TIGBZBelSfXqRX9TLbNh9x2S9HiSOoTfR9Rq VpvO0MxunGkMa9LsRrVcjkiYzFZCUVtIfNjUCBtT6aHvchjzw4MNjN6YxDao3czOYC XBdnkj0/z69jnzIXlXzxhsnJjuMJIny8NIbh5k/ULk3J15/t7FqOOlsHQMUCwcXZWU 5MWCtXSD/J40lRV7YAcwLXcz95WoUnWHYpJAbTyVNOZgKqKvJEovZ47nFFdsmuQLvh t4cgnId0f2eSPMDKRSflSMbfMGe5FeyvqZnZnpKCP0xmrIPE87yCYbBfqL3/y2sUdh efZRiDX1H+Hxg== Date: Mon, 23 Dec 2024 13:41:33 -0800 Subject: [PATCH 17/36] xfs: switch perag iteration from the for_each macros to a while based iterator From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940205.2293042.5537721335028495859.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 86437e6abbd2ef040f42ef190264819db6118415 The current for_each_perag* macros are a bit annoying in that they require the caller to both provide an object and an index iterator, and also somewhat obsfucate the underlying control flow mechanism. Switch to open coded while loops using new xfs_perag_next{,_from,_range} helpers that return the next pag structure to iterate on based on the previous one or NULL for the loop start. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- db/fsmap.c | 4 ++- db/info.c | 5 ++-- db/iunlink.c | 4 ++- libxfs/xfs_ag.h | 62 +++++++++++++++++++++++--------------------------- libxfs/xfs_sb.c | 15 ++++-------- libxfs/xfs_types.c | 5 ++-- repair/bmap_repair.c | 5 ++-- repair/phase2.c | 7 ++---- repair/phase5.c | 4 ++- 9 files changed, 48 insertions(+), 63 deletions(-) diff --git a/db/fsmap.c b/db/fsmap.c index 923d7568b9d977..a9259c4632185b 100644 --- a/db/fsmap.c +++ b/db/fsmap.c @@ -46,7 +46,7 @@ fsmap( struct xfs_rmap_irec high = {0}; struct xfs_btree_cur *bt_cur; struct xfs_buf *agbp; - struct xfs_perag *pag; + struct xfs_perag *pag = NULL; int error; eofs = XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks); @@ -63,7 +63,7 @@ fsmap( end_ag = XFS_FSB_TO_AGNO(mp, end_fsb); info.nr = 0; - for_each_perag_range(mp, start_ag, end_ag, pag) { + while ((pag = xfs_perag_next_range(mp, pag, start_ag, end_ag))) { if (pag_agno(pag) == end_ag) high.rm_startblock = XFS_FSB_TO_AGBNO(mp, end_fsb); diff --git a/db/info.c b/db/info.c index 6a8765ec761a49..9a86d247839f84 100644 --- a/db/info.c +++ b/db/info.c @@ -104,8 +104,7 @@ agresv_f( int argc, char **argv) { - struct xfs_perag *pag; - xfs_agnumber_t agno; + struct xfs_perag *pag = NULL; int i; if (argc > 1) { @@ -134,7 +133,7 @@ agresv_f( return 0; } - for_each_perag(mp, agno, pag) + while ((pag = xfs_perag_next(mp, pag))) print_agresv_info(pag); return 0; diff --git a/db/iunlink.c b/db/iunlink.c index c9977a859e2842..c73f818242b983 100644 --- a/db/iunlink.c +++ b/db/iunlink.c @@ -144,7 +144,7 @@ dump_iunlinked_f( int argc, char **argv) { - struct xfs_perag *pag; + struct xfs_perag *pag = NULL; xfs_agnumber_t agno = NULLAGNUMBER; unsigned int bucket = -1U; bool quiet = false; @@ -189,7 +189,7 @@ dump_iunlinked_f( return 0; } - for_each_perag(mp, agno, pag) + while ((pag = xfs_perag_next(mp, pag))) dump_unlinked(pag, bucket, quiet, verbose); return 0; diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index 69b934ad2c4aad..80969682dc4746 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -208,6 +208,34 @@ xfs_perag_rele( xfs_group_rele(pag_group(pag)); } +static inline struct xfs_perag * +xfs_perag_next_range( + struct xfs_mount *mp, + struct xfs_perag *pag, + xfs_agnumber_t start_agno, + xfs_agnumber_t end_agno) +{ + return to_perag(xfs_group_next_range(mp, pag ? pag_group(pag) : NULL, + start_agno, end_agno, XG_TYPE_AG)); +} + +static inline struct xfs_perag * +xfs_perag_next_from( + struct xfs_mount *mp, + struct xfs_perag *pag, + xfs_agnumber_t start_agno) +{ + return xfs_perag_next_range(mp, pag, start_agno, mp->m_sb.sb_agcount - 1); +} + +static inline struct xfs_perag * +xfs_perag_next( + struct xfs_mount *mp, + struct xfs_perag *pag) +{ + return xfs_perag_next_from(mp, pag, 0); +} + /* * Per-ag geometry infomation and validation */ @@ -273,40 +301,6 @@ xfs_ag_contains_log(struct xfs_mount *mp, xfs_agnumber_t agno) agno == XFS_FSB_TO_AGNO(mp, mp->m_sb.sb_logstart); } -/* - * Perag iteration APIs - */ -static inline struct xfs_perag * -xfs_perag_next( - struct xfs_perag *pag, - xfs_agnumber_t *agno, - xfs_agnumber_t end_agno) -{ - struct xfs_mount *mp = pag_mount(pag); - - *agno = pag_agno(pag) + 1; - xfs_perag_rele(pag); - while (*agno <= end_agno) { - pag = xfs_perag_grab(mp, *agno); - if (pag) - return pag; - (*agno)++; - } - return NULL; -} - -#define for_each_perag_range(mp, agno, end_agno, pag) \ - for ((pag) = xfs_perag_grab((mp), (agno)); \ - (pag) != NULL; \ - (pag) = xfs_perag_next((pag), &(agno), (end_agno))) - -#define for_each_perag_from(mp, agno, pag) \ - for_each_perag_range((mp), (agno), (mp)->m_sb.sb_agcount - 1, (pag)) - -#define for_each_perag(mp, agno, pag) \ - (agno) = 0; \ - for_each_perag_from((mp), (agno), (pag)) - static inline struct xfs_perag * xfs_perag_next_wrap( struct xfs_perag *pag, diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index f534ae5d4c4db2..d32f789037389f 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -1120,14 +1120,13 @@ int xfs_update_secondary_sbs( struct xfs_mount *mp) { - struct xfs_perag *pag; - xfs_agnumber_t agno = 1; + struct xfs_perag *pag = NULL; int saved_error = 0; int error = 0; LIST_HEAD (buffer_list); /* update secondary superblocks. */ - for_each_perag_from(mp, agno, pag) { + while ((pag = xfs_perag_next_from(mp, pag, 1))) { struct xfs_buf *bp; error = xfs_buf_get(mp->m_ddev_targp, @@ -1157,7 +1156,7 @@ xfs_update_secondary_sbs( xfs_buf_relse(bp); /* don't hold too many buffers at once */ - if (agno % 16) + if (pag_agno(pag) % 16) continue; error = xfs_buf_delwri_submit(&buffer_list); @@ -1171,12 +1170,8 @@ xfs_update_secondary_sbs( } } error = xfs_buf_delwri_submit(&buffer_list); - if (error) { - xfs_warn(mp, - "write error %d updating a secondary superblock near ag %d", - error, agno); - } - + if (error) + xfs_warn(mp, "error %d writing secondary superblocks", error); return saved_error ? saved_error : error; } diff --git a/libxfs/xfs_types.c b/libxfs/xfs_types.c index 74ab1965a8f49c..0d1b86ae59d93e 100644 --- a/libxfs/xfs_types.c +++ b/libxfs/xfs_types.c @@ -170,13 +170,12 @@ xfs_icount_range( unsigned long long *max) { unsigned long long nr_inos = 0; - struct xfs_perag *pag; - xfs_agnumber_t agno; + struct xfs_perag *pag = NULL; /* root, rtbitmap, rtsum all live in the first chunk */ *min = XFS_INODES_PER_CHUNK; - for_each_perag(mp, agno, pag) + while ((pag = xfs_perag_next(mp, pag))) nr_inos += pag->agino_max - pag->agino_min + 1; *max = nr_inos; } diff --git a/repair/bmap_repair.c b/repair/bmap_repair.c index 7ccbb96fa8dc5e..3a214c85a1de5f 100644 --- a/repair/bmap_repair.c +++ b/repair/bmap_repair.c @@ -218,12 +218,11 @@ STATIC int xrep_bmap_find_mappings( struct xrep_bmap *rb) { - struct xfs_perag *pag; - xfs_agnumber_t agno; + struct xfs_perag *pag = NULL; int error; /* Iterate the rmaps for extents. */ - for_each_perag(rb->sc->mp, agno, pag) { + while ((pag = xfs_perag_next(rb->sc->mp, pag))) { error = xrep_bmap_scan_ag(rb, pag); if (error) { libxfs_perag_put(pag); diff --git a/repair/phase2.c b/repair/phase2.c index 42a2861dcc3714..17966bb54db09d 100644 --- a/repair/phase2.c +++ b/repair/phase2.c @@ -274,12 +274,11 @@ check_fs_free_space( const struct check_state *old, struct xfs_sb *new_sb) { - struct xfs_perag *pag; - xfs_agnumber_t agno; + struct xfs_perag *pag = NULL; int error; /* Make sure we have enough space for per-AG reservations. */ - for_each_perag(mp, agno, pag) { + while ((pag = xfs_perag_next(mp, pag))) { struct xfs_trans *tp; struct xfs_agf *agf; struct xfs_buf *agi_bp, *agf_bp; @@ -365,7 +364,7 @@ check_fs_free_space( * uninitialized so that we don't trip over stale cached counters * after the upgrade/ */ - for_each_perag(mp, agno, pag) { + while ((pag = xfs_perag_next(mp, pag))) { libxfs_ag_resv_free(pag); clear_bit(XFS_AGSTATE_AGF_INIT, &pag->pag_opstate); clear_bit(XFS_AGSTATE_AGI_INIT, &pag->pag_opstate); diff --git a/repair/phase5.c b/repair/phase5.c index fdbd9f56998fb4..86b1f681a72bb8 100644 --- a/repair/phase5.c +++ b/repair/phase5.c @@ -632,7 +632,7 @@ void phase5(xfs_mount_t *mp) { struct bitmap *lost_blocks = NULL; - struct xfs_perag *pag; + struct xfs_perag *pag = NULL; xfs_agnumber_t agno; int error; @@ -679,7 +679,7 @@ phase5(xfs_mount_t *mp) if (error) do_error(_("cannot alloc lost block bitmap\n")); - for_each_perag(mp, agno, pag) + while ((pag = xfs_perag_next(mp, pag))) phase5_func(mp, pag, lost_blocks); print_final_rpt(); From patchwork Mon Dec 23 21:41:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13919250 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 6CD7118052 for ; Mon, 23 Dec 2024 21:41: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=1734990109; cv=none; b=ThRqnVCz1c0IzBOkaNFjNRtmkNoYYPrLUDBwugLn9FlB8eWPSKwXLOA1wlg33Viz6Z2cSkHtqCUzYdoF7KKESfli4zKfJ6suT7iXsv/30tZjNVq/N77ZAHsIEzRXP7eCLfPWULFaWpYWE42L3VoiyPo/9ROop/Fpo1uH/Rauego= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990109; c=relaxed/simple; bh=tRFa7ReeozaqHVy3/hF8n5QqwOifnsJzmZaQuJfN5yI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=d6WM2ATVoMqgxJw+GO+42p3ohLqux7lyqTY1T+nj8ECk1+qNh/Fc3iUV4pyjRyJzRsv7JNWsrlqyw/+kfgoWEzYIW75+ggQWtiWcuO6St35lqEsp/xhfgmNytxvTgv/iKHzeqkkWJW6ofLXhrICZKObYw7UYZ41nkb6dSemnz+w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tVozI9jT; 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="tVozI9jT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 452C6C4CED7; Mon, 23 Dec 2024 21:41:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990109; bh=tRFa7ReeozaqHVy3/hF8n5QqwOifnsJzmZaQuJfN5yI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=tVozI9jTRZ5jOt+kgD89kevoqhcFZZZ7Ppqkv5uSX7utZfmsIqt6nQW6L8rjev6tn B6v0cWTw8O+XIblAln/7NRcSGVhAI0MIehB7u5Os8BSCDzeAIH67zs6hafrP/bndrJ LgCjKVbU/E2GoTS1RkLVSHJA5UKrjHH28YsRfkwH/sKZdWpl4wtiDxDK9+lUkzDTsZ KUPv3MPO+r6a/HN1XX0yceYAYaroCFnkANYNWBuq2ik6K//lb4y9K+1MpRyGTPBBjK to2Kj+T9Tu9tZk5izhGDY/mYKjEQPqqs9l/pbCKwqj8i8RXNSjfxGiATa7LY/EfYCo zasgtVoR77xOQ== Date: Mon, 23 Dec 2024 13:41:48 -0800 Subject: [PATCH 18/36] xfs: move metadata health tracking to the generic group structure From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940220.2293042.4076093264884435127.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 5c8483cec3fe261a5c1ede7430bab042ed156361 Prepare for also tracking the health status of the upcoming realtime groups by moving the health tracking code to the generic xfs_group structure. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/util.c | 4 ++-- libxfs/xfs_ag.c | 1 - libxfs/xfs_ag.h | 9 --------- libxfs/xfs_group.c | 4 ++++ libxfs/xfs_group.h | 12 ++++++++++++ libxfs/xfs_health.h | 45 +++++++++++++++++---------------------------- 6 files changed, 35 insertions(+), 40 deletions(-) diff --git a/libxfs/util.c b/libxfs/util.c index a3f3ad299336c7..97da94506aee01 100644 --- a/libxfs/util.c +++ b/libxfs/util.c @@ -449,8 +449,8 @@ void xfs_ag_geom_health(struct xfs_perag *pag, struct xfs_ag_geometry *ageo) { } void xfs_fs_mark_sick(struct xfs_mount *mp, unsigned int mask) { } void xfs_agno_mark_sick(struct xfs_mount *mp, xfs_agnumber_t agno, unsigned int mask) { } -void xfs_ag_mark_sick(struct xfs_perag *pag, unsigned int mask) { } -void xfs_ag_measure_sickness(struct xfs_perag *pag, unsigned int *sick, +void xfs_group_mark_sick(struct xfs_group *xg, unsigned int mask) { } +void xfs_group_measure_sickness(struct xfs_group *xg, unsigned int *sick, unsigned int *checked) { *sick = 0; diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index 15d4ac5a99f0e7..20af8b67d86e88 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -230,7 +230,6 @@ xfs_perag_alloc( /* Place kernel structure only init below this point. */ spin_lock_init(&pag->pag_ici_lock); spin_lock_init(&pag->pagb_lock); - spin_lock_init(&pag->pag_state_lock); INIT_DELAYED_WORK(&pag->pag_blockgc_work, xfs_blockgc_worker); INIT_RADIX_TREE(&pag->pag_ici_root, GFP_ATOMIC); xfs_defer_drain_init(&pag->pag_intents_drain); diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index 80969682dc4746..8271cb72c88387 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -69,13 +69,6 @@ struct xfs_perag { #ifdef __KERNEL__ /* -- kernel only structures below this line -- */ - /* - * Bitsets of per-ag metadata that have been checked and/or are sick. - * Callers should hold pag_state_lock before accessing this field. - */ - uint16_t pag_checked; - uint16_t pag_sick; - #ifdef CONFIG_XFS_ONLINE_REPAIR /* * Alternate btree heights so that online repair won't trip the write @@ -87,8 +80,6 @@ struct xfs_perag { uint8_t pagf_repair_rmap_level; #endif - spinlock_t pag_state_lock; - spinlock_t pagb_lock; /* lock for pagb_tree */ struct rb_root pagb_tree; /* ordered tree of busy extents */ unsigned int pagb_gen; /* generation count for pagb_tree */ diff --git a/libxfs/xfs_group.c b/libxfs/xfs_group.c index 04d65033b75eca..c5269cd659f327 100644 --- a/libxfs/xfs_group.c +++ b/libxfs/xfs_group.c @@ -181,6 +181,10 @@ xfs_group_insert( xg->xg_gno = index; xg->xg_type = type; +#ifdef __KERNEL__ + spin_lock_init(&xg->xg_state_lock); +#endif + /* Active ref owned by mount indicates group is online. */ atomic_set(&xg->xg_active_ref, 1); diff --git a/libxfs/xfs_group.h b/libxfs/xfs_group.h index dd7da90443054b..d2c61dd1f43e44 100644 --- a/libxfs/xfs_group.h +++ b/libxfs/xfs_group.h @@ -11,6 +11,18 @@ struct xfs_group { enum xfs_group_type xg_type; atomic_t xg_ref; /* passive reference count */ atomic_t xg_active_ref; /* active reference count */ + +#ifdef __KERNEL__ + /* -- kernel only structures below this line -- */ + + /* + * Bitsets of per-ag metadata that have been checked and/or are sick. + * Callers should hold xg_state_lock before accessing this field. + */ + uint16_t xg_checked; + uint16_t xg_sick; + spinlock_t xg_state_lock; +#endif /* __KERNEL__ */ }; struct xfs_group *xfs_group_get(struct xfs_mount *mp, uint32_t index, diff --git a/libxfs/xfs_health.h b/libxfs/xfs_health.h index b0edb4288e5929..13301420a2f670 100644 --- a/libxfs/xfs_health.h +++ b/libxfs/xfs_health.h @@ -6,6 +6,8 @@ #ifndef __XFS_HEALTH_H__ #define __XFS_HEALTH_H__ +struct xfs_group; + /* * In-Core Filesystem Health Assessments * ===================================== @@ -197,10 +199,12 @@ void xfs_rt_measure_sickness(struct xfs_mount *mp, unsigned int *sick, void xfs_agno_mark_sick(struct xfs_mount *mp, xfs_agnumber_t agno, unsigned int mask); -void xfs_ag_mark_sick(struct xfs_perag *pag, unsigned int mask); -void xfs_ag_mark_corrupt(struct xfs_perag *pag, unsigned int mask); -void xfs_ag_mark_healthy(struct xfs_perag *pag, unsigned int mask); -void xfs_ag_measure_sickness(struct xfs_perag *pag, unsigned int *sick, +void xfs_group_mark_sick(struct xfs_group *xg, unsigned int mask); +#define xfs_ag_mark_sick(pag, mask) \ + xfs_group_mark_sick(pag_group(pag), (mask)) +void xfs_group_mark_corrupt(struct xfs_group *xg, unsigned int mask); +void xfs_group_mark_healthy(struct xfs_group *xg, unsigned int mask); +void xfs_group_measure_sickness(struct xfs_group *xg, unsigned int *sick, unsigned int *checked); void xfs_inode_mark_sick(struct xfs_inode *ip, unsigned int mask); @@ -227,22 +231,19 @@ xfs_fs_has_sickness(struct xfs_mount *mp, unsigned int mask) } static inline bool -xfs_rt_has_sickness(struct xfs_mount *mp, unsigned int mask) +xfs_group_has_sickness( + struct xfs_group *xg, + unsigned int mask) { - unsigned int sick, checked; + unsigned int sick, checked; - xfs_rt_measure_sickness(mp, &sick, &checked); - return sick & mask; -} - -static inline bool -xfs_ag_has_sickness(struct xfs_perag *pag, unsigned int mask) -{ - unsigned int sick, checked; - - xfs_ag_measure_sickness(pag, &sick, &checked); + xfs_group_measure_sickness(xg, &sick, &checked); return sick & mask; } +#define xfs_ag_has_sickness(pag, mask) \ + xfs_group_has_sickness(pag_group(pag), (mask)) +#define xfs_ag_is_healthy(pag) \ + (!xfs_ag_has_sickness((pag), UINT_MAX)) static inline bool xfs_inode_has_sickness(struct xfs_inode *ip, unsigned int mask) @@ -259,18 +260,6 @@ xfs_fs_is_healthy(struct xfs_mount *mp) return !xfs_fs_has_sickness(mp, -1U); } -static inline bool -xfs_rt_is_healthy(struct xfs_mount *mp) -{ - return !xfs_rt_has_sickness(mp, -1U); -} - -static inline bool -xfs_ag_is_healthy(struct xfs_perag *pag) -{ - return !xfs_ag_has_sickness(pag, -1U); -} - static inline bool xfs_inode_is_healthy(struct xfs_inode *ip) { From patchwork Mon Dec 23 21:42: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: 13919251 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 541551D63DE for ; Mon, 23 Dec 2024 21:42: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=1734990125; cv=none; b=TCFsRF45VrqmUGDtFFZfoibDbe801tsfEFO1pADrKBBPkuojzPsNSMcOMQfNZP2u5o4FDTHCnH9sPZzSrpZZnVemYY1iPWkXBL2MSA5rWlS9y6vPC7+uX1Xw//53KlSQiqvCELj+aZJ4IZ00I0iAgFiMnhQruJEZhDlNZYyltb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990125; c=relaxed/simple; bh=9C5RfWkI2Al+F9HcbKSVcfKqeMbH37qINRT2LZy/mas=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NHCqP8QOtloHIxEMzLf3HkMg9kl474B1wzmeU1wQEfcHxihNhG6NI65EikRh2QdhKvARhHm17rsdc3jHDHbHu58DR/Rqzb7pI+doiVizVjSysx0XEohmD7NpH82pBBi/Lu7b3Ombqtnkn6HHHMR3C4JETZbPXm06+UgxG7K6EvM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=smI/Tnva; 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="smI/Tnva" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DDDE8C4CED3; Mon, 23 Dec 2024 21:42:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990124; bh=9C5RfWkI2Al+F9HcbKSVcfKqeMbH37qINRT2LZy/mas=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=smI/TnvayzKC3ZrcVHeQSNk5jgD+ftPDbHxR25/jCAmmL/AhsZ9aUKEeVd3m/ErIc QbbvH2hnhHDYdfx2wlM9e2Aa1Cgrh7olE/+RgFEPnDJHSEfMITYfCKfiQu1XRPAER4 rL4UiCE4mBPCML71SDRHxOHhPTtfhOhu4iPUNmsQC0icibRBdbtc65gy9YYN6LL90E YrduYhNUWA3naD8eJS9ndV7GtKBKtSI5Y8/fsIcIaXb8SbDuidZf7KJI5Jb31Amr5P ralUC4Pj8uHf9TvlFCxfxs+f4kia1k0q1U9GF0+UkgroVqDu+eDZai6B6VcYzJOcY4 +4lecWQm5Y+Wg== Date: Mon, 23 Dec 2024 13:42:04 -0800 Subject: [PATCH 19/36] xfs: move draining of deferred operations to the generic group structure From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940235.2293042.8328305775413138014.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 34cf3a6f3952ecabd54b4fe3d431aa44ce98fe45 Prepare supporting the upcoming realtime groups feature by moving the deferred operation draining to the generic xfs_group structure. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_ag.c | 7 ++----- libxfs/xfs_ag.h | 9 --------- libxfs/xfs_group.c | 4 ++++ libxfs/xfs_group.h | 9 +++++++++ 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index 20af8b67d86e88..d67e40f49a3fc0 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -110,7 +110,6 @@ xfs_perag_uninit( #ifdef __KERNEL__ struct xfs_perag *pag = to_perag(xg); - xfs_defer_drain_free(&pag->pag_intents_drain); cancel_delayed_work_sync(&pag->pag_blockgc_work); xfs_buf_cache_destroy(&pag->pag_bcache); #endif @@ -232,7 +231,6 @@ xfs_perag_alloc( spin_lock_init(&pag->pagb_lock); INIT_DELAYED_WORK(&pag->pag_blockgc_work, xfs_blockgc_worker); INIT_RADIX_TREE(&pag->pag_ici_root, GFP_ATOMIC); - xfs_defer_drain_init(&pag->pag_intents_drain); init_waitqueue_head(&pag->pagb_wait); pag->pagb_tree = RB_ROOT; xfs_hooks_init(&pag->pag_rmap_update_hooks); @@ -240,7 +238,7 @@ xfs_perag_alloc( error = xfs_buf_cache_init(&pag->pag_bcache); if (error) - goto out_defer_drain_free; + goto out_free_perag; /* * Pre-calculated geometry @@ -258,8 +256,7 @@ xfs_perag_alloc( out_buf_cache_destroy: xfs_buf_cache_destroy(&pag->pag_bcache); -out_defer_drain_free: - xfs_defer_drain_free(&pag->pag_intents_drain); +out_free_perag: kfree(pag); return error; } diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index 8271cb72c88387..45f8de06cdbc8a 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -97,15 +97,6 @@ struct xfs_perag { /* background prealloc block trimming */ struct delayed_work pag_blockgc_work; - /* - * We use xfs_drain to track the number of deferred log intent items - * that have been queued (but not yet processed) so that waiters (e.g. - * scrub) will not lock resources when other threads are in the middle - * of processing a chain of intent items only to find momentary - * inconsistencies. - */ - struct xfs_defer_drain pag_intents_drain; - /* Hook to feed rmapbt updates to an active online repair. */ struct xfs_hooks pag_rmap_update_hooks; #endif /* __KERNEL__ */ diff --git a/libxfs/xfs_group.c b/libxfs/xfs_group.c index c5269cd659f327..dfcebf2e9b30f8 100644 --- a/libxfs/xfs_group.c +++ b/libxfs/xfs_group.c @@ -159,6 +159,8 @@ xfs_group_free( XFS_IS_CORRUPT(mp, atomic_read(&xg->xg_ref) != 0); + xfs_defer_drain_free(&xg->xg_intents_drain); + if (uninit) uninit(xg); @@ -184,6 +186,7 @@ xfs_group_insert( #ifdef __KERNEL__ spin_lock_init(&xg->xg_state_lock); #endif + xfs_defer_drain_init(&xg->xg_intents_drain); /* Active ref owned by mount indicates group is online. */ atomic_set(&xg->xg_active_ref, 1); @@ -191,6 +194,7 @@ xfs_group_insert( error = xa_insert(&mp->m_groups[type].xa, index, xg, GFP_KERNEL); if (error) { WARN_ON_ONCE(error == -EBUSY); + xfs_defer_drain_free(&xg->xg_intents_drain); return error; } diff --git a/libxfs/xfs_group.h b/libxfs/xfs_group.h index d2c61dd1f43e44..ebefbba7d98cc2 100644 --- a/libxfs/xfs_group.h +++ b/libxfs/xfs_group.h @@ -22,6 +22,15 @@ struct xfs_group { uint16_t xg_checked; uint16_t xg_sick; spinlock_t xg_state_lock; + + /* + * We use xfs_drain to track the number of deferred log intent items + * that have been queued (but not yet processed) so that waiters (e.g. + * scrub) will not lock resources when other threads are in the middle + * of processing a chain of intent items only to find momentary + * inconsistencies. + */ + struct xfs_defer_drain xg_intents_drain; #endif /* __KERNEL__ */ }; From patchwork Mon Dec 23 21:42: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: 13919252 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 AD76E161328 for ; Mon, 23 Dec 2024 21:42:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990140; cv=none; b=oxpzlvF/YwbED95YAYSP4dZWQq45ufAUK2QGb+jffQVBviXAq5lSuKovF2RBS5IsLvKioY9shONjdGZh6UVAJ8r3EAkplgzQp55JrohSpNaLaSTYB/ZGb3vAQOQqr7i1cFYEk4fc1rzOPyud3SZzXe9kaYatzcRP5NzeA9Go+54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990140; c=relaxed/simple; bh=PYigm0wdba53/j9a3sXUv9cPwFFckP/SlIPde0GYV7M=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZTeADxUke0dPuxidwSV05q7+WNsgFy2NV3++UHq8k2RmymPweWADvGWChCKnnPdhK9cfniRerv0f3ZHhIa3AZJPk/X8OdRx4lWOWJdyQ0PpzC2dwzldAX25T9m38Qc7HxE+BJMIBYHtizzfMqp+gpGLpM3JIlByn4jgiPlifow4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JHjs1HFJ; 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="JHjs1HFJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81CF1C4CED3; Mon, 23 Dec 2024 21:42:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990140; bh=PYigm0wdba53/j9a3sXUv9cPwFFckP/SlIPde0GYV7M=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=JHjs1HFJwA8adhJiFl4Mv2jMcLVyhha0IiTl30Dfdnmgt7W0lYdfp8uFVJ3maIgxD 99VI1wepAzmVl5FFu01gZmyDqJdJRTrvO/bN4qNhDkQjpAY4K+bI0bA6IPInmd88kD KnRPfvBGfTl8Xu0BjcnC82TKUpQMpI5ohnrPemkXGIwp74u4qtsZ4UcEwJJOQ01Y1V exRDx3NEjtIIB5p0aU2D+vH+SVlxRmqPcp2k6jstm9cqzCAUEj4z5lZmaTOco9X2Fu 6csHZKpbBls+udQ+3M8zzP3dJSKXPDjWkeT+Pg+4uApvxvcoq+66fPdSPtAy1s5U3+ xCcIH9X2qc2jg== Date: Mon, 23 Dec 2024 13:42:20 -0800 Subject: [PATCH 20/36] xfs: move the online repair rmap hooks to the generic group structure From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940251.2293042.8263044745967753975.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: eb4a84a3c2bd09efe770fa940fb68e349f90c8c6 Prepare for the upcoming realtime groups feature by moving the online repair rmap hooks to based to the generic xfs_group structure. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_ag.c | 1 - libxfs/xfs_ag.h | 3 --- libxfs/xfs_group.c | 1 + libxfs/xfs_group.h | 5 +++++ libxfs/xfs_rmap.c | 24 +++++++++++++----------- libxfs/xfs_rmap.h | 4 ++-- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index d67e40f49a3fc0..1542fea06e305e 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -233,7 +233,6 @@ xfs_perag_alloc( INIT_RADIX_TREE(&pag->pag_ici_root, GFP_ATOMIC); init_waitqueue_head(&pag->pagb_wait); pag->pagb_tree = RB_ROOT; - xfs_hooks_init(&pag->pag_rmap_update_hooks); #endif /* __KERNEL__ */ error = xfs_buf_cache_init(&pag->pag_bcache); diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index 45f8de06cdbc8a..042ee0913fb9b9 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -96,9 +96,6 @@ struct xfs_perag { /* background prealloc block trimming */ struct delayed_work pag_blockgc_work; - - /* Hook to feed rmapbt updates to an active online repair. */ - struct xfs_hooks pag_rmap_update_hooks; #endif /* __KERNEL__ */ }; diff --git a/libxfs/xfs_group.c b/libxfs/xfs_group.c index dfcebf2e9b30f8..58ace330a765cf 100644 --- a/libxfs/xfs_group.c +++ b/libxfs/xfs_group.c @@ -185,6 +185,7 @@ xfs_group_insert( #ifdef __KERNEL__ spin_lock_init(&xg->xg_state_lock); + xfs_hooks_init(&xg->xg_rmap_update_hooks); #endif xfs_defer_drain_init(&xg->xg_intents_drain); diff --git a/libxfs/xfs_group.h b/libxfs/xfs_group.h index ebefbba7d98cc2..a87b9b80ef7516 100644 --- a/libxfs/xfs_group.h +++ b/libxfs/xfs_group.h @@ -31,6 +31,11 @@ struct xfs_group { * inconsistencies. */ struct xfs_defer_drain xg_intents_drain; + + /* + * Hook to feed rmapbt updates to an active online repair. + */ + struct xfs_hooks xg_rmap_update_hooks; #endif /* __KERNEL__ */ }; diff --git a/libxfs/xfs_rmap.c b/libxfs/xfs_rmap.c index 0f7dee40bda87a..e13f4aa7e99538 100644 --- a/libxfs/xfs_rmap.c +++ b/libxfs/xfs_rmap.c @@ -834,7 +834,7 @@ xfs_rmap_hook_enable(void) static inline void xfs_rmap_update_hook( struct xfs_trans *tp, - struct xfs_perag *pag, + struct xfs_group *xg, enum xfs_rmap_intent_type op, xfs_agblock_t startblock, xfs_extlen_t blockcount, @@ -849,27 +849,27 @@ xfs_rmap_update_hook( .oinfo = *oinfo, /* struct copy */ }; - if (pag) - xfs_hooks_call(&pag->pag_rmap_update_hooks, op, &p); + if (xg) + xfs_hooks_call(&xg->xg_rmap_update_hooks, op, &p); } } /* Call the specified function during a reverse mapping update. */ int xfs_rmap_hook_add( - struct xfs_perag *pag, + struct xfs_group *xg, struct xfs_rmap_hook *hook) { - return xfs_hooks_add(&pag->pag_rmap_update_hooks, &hook->rmap_hook); + return xfs_hooks_add(&xg->xg_rmap_update_hooks, &hook->rmap_hook); } /* Stop calling the specified function during a reverse mapping update. */ void xfs_rmap_hook_del( - struct xfs_perag *pag, + struct xfs_group *xg, struct xfs_rmap_hook *hook) { - xfs_hooks_del(&pag->pag_rmap_update_hooks, &hook->rmap_hook); + xfs_hooks_del(&xg->xg_rmap_update_hooks, &hook->rmap_hook); } /* Configure rmap update hook functions. */ @@ -904,7 +904,8 @@ xfs_rmap_free( return 0; cur = xfs_rmapbt_init_cursor(mp, tp, agbp, pag); - xfs_rmap_update_hook(tp, pag, XFS_RMAP_UNMAP, bno, len, false, oinfo); + xfs_rmap_update_hook(tp, pag_group(pag), XFS_RMAP_UNMAP, bno, len, + false, oinfo); error = xfs_rmap_unmap(cur, bno, len, false, oinfo); xfs_btree_del_cursor(cur, error); @@ -1148,7 +1149,8 @@ xfs_rmap_alloc( return 0; cur = xfs_rmapbt_init_cursor(mp, tp, agbp, pag); - xfs_rmap_update_hook(tp, pag, XFS_RMAP_MAP, bno, len, false, oinfo); + xfs_rmap_update_hook(tp, pag_group(pag), XFS_RMAP_MAP, bno, len, false, + oinfo); error = xfs_rmap_map(cur, bno, len, false, oinfo); xfs_btree_del_cursor(cur, error); @@ -2619,8 +2621,8 @@ xfs_rmap_finish_one( if (error) return error; - xfs_rmap_update_hook(tp, ri->ri_pag, ri->ri_type, bno, - ri->ri_bmap.br_blockcount, unwritten, &oinfo); + xfs_rmap_update_hook(tp, pag_group(ri->ri_pag), ri->ri_type, bno, + ri->ri_bmap.br_blockcount, unwritten, &oinfo); return 0; } diff --git a/libxfs/xfs_rmap.h b/libxfs/xfs_rmap.h index b783dd4dd95d1a..d409b463bc6662 100644 --- a/libxfs/xfs_rmap.h +++ b/libxfs/xfs_rmap.h @@ -264,8 +264,8 @@ struct xfs_rmap_hook { void xfs_rmap_hook_disable(void); void xfs_rmap_hook_enable(void); -int xfs_rmap_hook_add(struct xfs_perag *pag, struct xfs_rmap_hook *hook); -void xfs_rmap_hook_del(struct xfs_perag *pag, struct xfs_rmap_hook *hook); +int xfs_rmap_hook_add(struct xfs_group *xg, struct xfs_rmap_hook *hook); +void xfs_rmap_hook_del(struct xfs_group *xg, struct xfs_rmap_hook *hook); void xfs_rmap_hook_setup(struct xfs_rmap_hook *hook, notifier_fn_t mod_fn); #endif From patchwork Mon Dec 23 21:42:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13919253 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 579521D5CDD for ; Mon, 23 Dec 2024 21:42: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=1734990156; cv=none; b=NBtEPOimtJsfHjEvOEBX4cqYaO/HL0JCQL2ZNFITIwwjsp1jaJLn1cyWgZX1jg7mpbnO6eNla1s/lE0AP6VNkKc0PQA5LBoFt1ngWXxsZBFPMmI43gtYgWtyhtq4rLmN3VgejIoqPx1DigxfBrYCw2sIDVV0nn8EgY/ZWKIySgA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990156; c=relaxed/simple; bh=RgtTZi18xC6mSKlU6yOa98SScplN78aBSxufGnJg7dI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mhhqa22ZbCCO6Oae4YXbFjRdB3liDxFKEySqhfnhqUQxJ0CXqiy2FGUKwv1kFxn+CHs6r5VBciVL4eLRyxy3oAB2YP4bzBsivkaZh1PnkRWNwz6vpKoJVMY0NVkLr3p5P6xDnbDMAZVVT2zdq1bLal+7l0EcAi4+vdlLs620oFY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gm6JuoIi; 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="gm6JuoIi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D701C4CED3; Mon, 23 Dec 2024 21:42:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990156; bh=RgtTZi18xC6mSKlU6yOa98SScplN78aBSxufGnJg7dI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=gm6JuoIiESoHTl+LsgWw/RaU3OACULU3U0UkfcoGHqe8SLff7DXIxYPDIp0wFr8D8 tKcVnhGszBxOtgD/BWfPk0zTN93KvyMrvXnWDdFtsnjE7JCe0mand/Lxjv3AJmlyqr zfo0FOGKmDP2/qSfFJO5xmWImzk1G7ohakGlbV83TkWt2Jv6VwfZ+3UKrCt6kvV5U4 DIwT5wueYxf3paTEtJ1iFBLdFNGog76O7vBq1MivLTPQ62MDYf1eEb49orDkiy10Nu nZ743tsxBskN+qAKVzawOElrRm9Lguxwd/POfZBjkdTrUP/feLOqAIWzx7O68H4kcm +FXqJEMUCz28w== Date: Mon, 23 Dec 2024 13:42:35 -0800 Subject: [PATCH 21/36] xfs: convert busy extent tracking to the generic group structure From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940266.2293042.18303256379670961526.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: adbc76aa0fedcb6da2d1ceb1ce786d1f963afee8 Split busy extent tracking from struct xfs_perag into its own private structure, which can be pointed to by the generic group structure. Note that this structure is now dynamically allocated instead of embedded as the upcoming zone XFS code doesn't need it and will also have an unusually high number of groups due to hardware constraints. Dynamically allocating the structure this is a big memory saver for this case. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/libxfs_priv.h | 6 +++--- libxfs/xfs_ag.c | 3 --- libxfs/xfs_ag.h | 5 ----- libxfs/xfs_alloc.c | 29 +++++++++++++++++------------ libxfs/xfs_alloc_btree.c | 4 ++-- libxfs/xfs_group.c | 15 +++++++++++++-- libxfs/xfs_group.h | 5 +++++ libxfs/xfs_rmap_btree.c | 4 ++-- 8 files changed, 42 insertions(+), 29 deletions(-) diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 9505806131bc42..1b6bb961b7ac06 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -467,11 +467,11 @@ xfs_buf_readahead( #define xfs_extent_busy_reuse(...) ((void) 0) /* avoid unused variable warning */ -#define xfs_extent_busy_insert(tp,pag,bno,len,flags)({ \ - struct xfs_perag *__foo = pag; \ +#define xfs_extent_busy_insert(tp,xg,bno,len,flags)({ \ + struct xfs_group *__foo = xg; \ __foo = __foo; /* no set-but-unused warning */ \ }) -#define xfs_extent_busy_trim(args,bno,len,busy_gen) ({ \ +#define xfs_extent_busy_trim(group,minlen,maxlen,bno,len,busy_gen) ({ \ unsigned __foo = *(busy_gen); \ *(busy_gen) = __foo; \ false; \ diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index 1542fea06e305e..bd38ac175bbae3 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -228,11 +228,8 @@ xfs_perag_alloc( #ifdef __KERNEL__ /* Place kernel structure only init below this point. */ spin_lock_init(&pag->pag_ici_lock); - spin_lock_init(&pag->pagb_lock); INIT_DELAYED_WORK(&pag->pag_blockgc_work, xfs_blockgc_worker); INIT_RADIX_TREE(&pag->pag_ici_root, GFP_ATOMIC); - init_waitqueue_head(&pag->pagb_wait); - pag->pagb_tree = RB_ROOT; #endif /* __KERNEL__ */ error = xfs_buf_cache_init(&pag->pag_bcache); diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index 042ee0913fb9b9..7290148fa6e6aa 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -80,11 +80,6 @@ struct xfs_perag { uint8_t pagf_repair_rmap_level; #endif - spinlock_t pagb_lock; /* lock for pagb_tree */ - struct rb_root pagb_tree; /* ordered tree of busy extents */ - unsigned int pagb_gen; /* generation count for pagb_tree */ - wait_queue_head_t pagb_wait; /* woken when pagb_gen changes */ - atomic_t pagf_fstrms; /* # of filestreams active in this AG */ spinlock_t pag_ici_lock; /* incore inode cache lock */ diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index 39e1961078ae3a..1c50358a8be7ae 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -327,7 +327,8 @@ xfs_alloc_compute_aligned( bool busy; /* Trim busy sections out of found extent */ - busy = xfs_extent_busy_trim(args, &bno, &len, busy_gen); + busy = xfs_extent_busy_trim(pag_group(args->pag), args->minlen, + args->maxlen, &bno, &len, busy_gen); /* * If we have a largish extent that happens to start before min_agbno, @@ -1247,7 +1248,7 @@ xfs_alloc_ag_vextent_small( if (fbno == NULLAGBLOCK) goto out; - xfs_extent_busy_reuse(args->pag, fbno, 1, + xfs_extent_busy_reuse(pag_group(args->pag), fbno, 1, (args->datatype & XFS_ALLOC_NOBUSY)); if (args->datatype & XFS_ALLOC_USERDATA) { @@ -1360,7 +1361,8 @@ xfs_alloc_ag_vextent_exact( */ tbno = fbno; tlen = flen; - xfs_extent_busy_trim(args, &tbno, &tlen, &busy_gen); + xfs_extent_busy_trim(pag_group(args->pag), args->minlen, args->maxlen, + &tbno, &tlen, &busy_gen); /* * Give up if the start of the extent is busy, or the freespace isn't @@ -1753,8 +1755,9 @@ xfs_alloc_ag_vextent_near( * the allocation can be retried. */ trace_xfs_alloc_near_busy(args); - error = xfs_extent_busy_flush(args->tp, args->pag, - acur.busy_gen, alloc_flags); + error = xfs_extent_busy_flush(args->tp, + pag_group(args->pag), acur.busy_gen, + alloc_flags); if (error) goto out; @@ -1869,8 +1872,9 @@ xfs_alloc_ag_vextent_size( * the allocation can be retried. */ trace_xfs_alloc_size_busy(args); - error = xfs_extent_busy_flush(args->tp, args->pag, - busy_gen, alloc_flags); + error = xfs_extent_busy_flush(args->tp, + pag_group(args->pag), busy_gen, + alloc_flags); if (error) goto error0; @@ -1968,8 +1972,9 @@ xfs_alloc_ag_vextent_size( * the allocation can be retried. */ trace_xfs_alloc_size_busy(args); - error = xfs_extent_busy_flush(args->tp, args->pag, - busy_gen, alloc_flags); + error = xfs_extent_busy_flush(args->tp, + pag_group(args->pag), busy_gen, + alloc_flags); if (error) goto error0; @@ -3609,8 +3614,8 @@ xfs_alloc_vextent_finish( if (error) goto out_drop_perag; - ASSERT(!xfs_extent_busy_search(args->pag, args->agbno, - args->len)); + ASSERT(!xfs_extent_busy_search(pag_group(args->pag), + args->agbno, args->len)); } xfs_ag_resv_alloc_extent(args->pag, args->resv, args); @@ -4008,7 +4013,7 @@ __xfs_free_extent( if (skip_discard) busy_flags |= XFS_EXTENT_BUSY_SKIP_DISCARD; - xfs_extent_busy_insert(tp, pag, agbno, len, busy_flags); + xfs_extent_busy_insert(tp, pag_group(pag), agbno, len, busy_flags); return 0; err_release: diff --git a/libxfs/xfs_alloc_btree.c b/libxfs/xfs_alloc_btree.c index 667655a639fef1..bf906aeb2f8a9e 100644 --- a/libxfs/xfs_alloc_btree.c +++ b/libxfs/xfs_alloc_btree.c @@ -84,7 +84,7 @@ xfs_allocbt_alloc_block( } atomic64_inc(&cur->bc_mp->m_allocbt_blks); - xfs_extent_busy_reuse(cur->bc_ag.pag, bno, 1, false); + xfs_extent_busy_reuse(pag_group(cur->bc_ag.pag), bno, 1, false); new->s = cpu_to_be32(bno); @@ -108,7 +108,7 @@ xfs_allocbt_free_block( return error; atomic64_dec(&cur->bc_mp->m_allocbt_blks); - xfs_extent_busy_insert(cur->bc_tp, agbp->b_pag, bno, 1, + xfs_extent_busy_insert(cur->bc_tp, pag_group(agbp->b_pag), bno, 1, XFS_EXTENT_BUSY_SKIP_DISCARD); return 0; } diff --git a/libxfs/xfs_group.c b/libxfs/xfs_group.c index 58ace330a765cf..9c7fa99d00b802 100644 --- a/libxfs/xfs_group.c +++ b/libxfs/xfs_group.c @@ -160,6 +160,9 @@ xfs_group_free( XFS_IS_CORRUPT(mp, atomic_read(&xg->xg_ref) != 0); xfs_defer_drain_free(&xg->xg_intents_drain); +#ifdef __KERNEL__ + kfree(xg->xg_busy_extents); +#endif if (uninit) uninit(xg); @@ -184,6 +187,9 @@ xfs_group_insert( xg->xg_type = type; #ifdef __KERNEL__ + xg->xg_busy_extents = xfs_extent_busy_alloc(); + if (!xg->xg_busy_extents) + return -ENOMEM; spin_lock_init(&xg->xg_state_lock); xfs_hooks_init(&xg->xg_rmap_update_hooks); #endif @@ -195,9 +201,14 @@ xfs_group_insert( error = xa_insert(&mp->m_groups[type].xa, index, xg, GFP_KERNEL); if (error) { WARN_ON_ONCE(error == -EBUSY); - xfs_defer_drain_free(&xg->xg_intents_drain); - return error; + goto out_drain; } return 0; +out_drain: + xfs_defer_drain_free(&xg->xg_intents_drain); +#ifdef __KERNEL__ + kfree(xg->xg_busy_extents); +#endif + return error; } diff --git a/libxfs/xfs_group.h b/libxfs/xfs_group.h index a87b9b80ef7516..0ff6e1d5635cb1 100644 --- a/libxfs/xfs_group.h +++ b/libxfs/xfs_group.h @@ -15,6 +15,11 @@ struct xfs_group { #ifdef __KERNEL__ /* -- kernel only structures below this line -- */ + /* + * Track freed but not yet committed extents. + */ + struct xfs_extent_busy_tree *xg_busy_extents; + /* * Bitsets of per-ag metadata that have been checked and/or are sick. * Callers should hold xg_state_lock before accessing this field. diff --git a/libxfs/xfs_rmap_btree.c b/libxfs/xfs_rmap_btree.c index ebb2519cf8baf3..5829e68790314a 100644 --- a/libxfs/xfs_rmap_btree.c +++ b/libxfs/xfs_rmap_btree.c @@ -101,7 +101,7 @@ xfs_rmapbt_alloc_block( return 0; } - xfs_extent_busy_reuse(pag, bno, 1, false); + xfs_extent_busy_reuse(pag_group(pag), bno, 1, false); new->s = cpu_to_be32(bno); be32_add_cpu(&agf->agf_rmap_blocks, 1); @@ -135,7 +135,7 @@ xfs_rmapbt_free_block( if (error) return error; - xfs_extent_busy_insert(cur->bc_tp, pag, bno, 1, + xfs_extent_busy_insert(cur->bc_tp, pag_group(pag), bno, 1, XFS_EXTENT_BUSY_SKIP_DISCARD); xfs_ag_resv_free_extent(pag, XFS_AG_RESV_RMAPBT, NULL, 1); From patchwork Mon Dec 23 21:42: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: 13919254 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 493C61C4A34 for ; Mon, 23 Dec 2024 21:42:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990172; cv=none; b=sTZXe1O15k6VtoAt+DZoSeNDrZsvjjVfT3ejD2OOA+oWZBBB0l72se2mXjV+ZLoCQl6wBMBIEDZG7KSfz36VarbS9kOW47iYThhbj3bxjjftRFJyb4S+Z6BcHvBXbE7t7Q/Ae7crnXR+jgIqccKEwXB+jIBmtH3DDu4hBYypnJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990172; c=relaxed/simple; bh=2BTy5M/I6cQ7VZ+OwcY510/2V7TYMn830AIJA5qtrfw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DlCIy7r34sHOe268mPTxItdpRsNADd4VdwD1jGzAGeH9ahgqCf+4lKLkonpnh1Pw3LeGv9re7b8CrxV5rGqdGfZnIK8WDFaHwEwPrdMbpvyAn+dPEWjG88ZfvDz58UEEhOorJHwkov8A6KC+L2QX9uHkbtAo7QvwYlZfTaqhsfs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Rh68KNM7; 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="Rh68KNM7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C41C5C4CED3; Mon, 23 Dec 2024 21:42:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990171; bh=2BTy5M/I6cQ7VZ+OwcY510/2V7TYMn830AIJA5qtrfw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Rh68KNM7q6U+lGE21bDF8FXVGt7oOsKVotXVXCWQ+bkoSKBeQJxPzwo4AZK7LnyO3 Mcd3EptMBcwR7gxj7Akb88EqToavLZVEAqtG/x6VG/u8Z5shIFCpICb2hh7tfovJtf O7j7fBd9Dy4H/xDn0G7Tyg4ZqFK1ACcXvG10kp18CvZcu9bV16uwkWQQf/h3eFlsm1 xxIzZuWfaALHHGGaTQZu7N0alAfn1MXeYFsxC6clMfjs6i+9um4qZTOW+wIHURpcvA lGgP2BxcCdAbPdDlpnI+CbiPR9LTQ20c7MmAJVm9I8TouO4qr0zEKL8HL7SLcMZyQn MNOkhohecnjgw== Date: Mon, 23 Dec 2024 13:42:51 -0800 Subject: [PATCH 22/36] xfs: add a generic group pointer to the btree cursor From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940280.2293042.13275704643034566615.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 77a530e6c49d22bd4a221d2f059db24fc30094db Replace the pag pointers in the type specific union with a generic xfs_group pointer. This prepares for adding realtime group support. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_alloc.c | 8 ++++---- libxfs/xfs_alloc_btree.c | 28 ++++++++++++++-------------- libxfs/xfs_btree.c | 35 ++++++++++++----------------------- libxfs/xfs_btree.h | 3 +-- libxfs/xfs_btree_mem.c | 6 ++---- libxfs/xfs_ialloc.c | 12 +++++++----- libxfs/xfs_ialloc_btree.c | 15 ++++++++------- libxfs/xfs_refcount.c | 17 +++++++++-------- libxfs/xfs_refcount_btree.c | 10 +++++----- libxfs/xfs_rmap.c | 8 +++----- libxfs/xfs_rmap_btree.c | 19 ++++++++++--------- repair/agbtree.c | 6 +++--- repair/bmap_repair.c | 4 ++-- 13 files changed, 80 insertions(+), 91 deletions(-) diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index 1c50358a8be7ae..c449285743534d 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -271,7 +271,7 @@ xfs_alloc_complain_bad_rec( xfs_warn(mp, "%sbt record corruption in AG %d detected at %pS!", - cur->bc_ops->name, pag_agno(cur->bc_ag.pag), fa); + cur->bc_ops->name, cur->bc_group->xg_gno, fa); xfs_warn(mp, "start block 0x%x block count 0x%x", irec->ar_startblock, irec->ar_blockcount); @@ -299,7 +299,7 @@ xfs_alloc_get_rec( return error; xfs_alloc_btrec_to_irec(rec, &irec); - fa = xfs_alloc_check_irec(cur->bc_ag.pag, &irec); + fa = xfs_alloc_check_irec(to_perag(cur->bc_group), &irec); if (fa) return xfs_alloc_complain_bad_rec(cur, fa, &irec); @@ -536,7 +536,7 @@ static int xfs_alloc_fixup_longest( struct xfs_btree_cur *cnt_cur) { - struct xfs_perag *pag = cnt_cur->bc_ag.pag; + struct xfs_perag *pag = to_perag(cnt_cur->bc_group); struct xfs_buf *bp = cnt_cur->bc_ag.agbp; struct xfs_agf *agf = bp->b_addr; xfs_extlen_t longest = 0; @@ -4038,7 +4038,7 @@ xfs_alloc_query_range_helper( xfs_failaddr_t fa; xfs_alloc_btrec_to_irec(rec, &irec); - fa = xfs_alloc_check_irec(cur->bc_ag.pag, &irec); + fa = xfs_alloc_check_irec(to_perag(cur->bc_group), &irec); if (fa) return xfs_alloc_complain_bad_rec(cur, fa, &irec); diff --git a/libxfs/xfs_alloc_btree.c b/libxfs/xfs_alloc_btree.c index bf906aeb2f8a9e..63b8db4ed01350 100644 --- a/libxfs/xfs_alloc_btree.c +++ b/libxfs/xfs_alloc_btree.c @@ -26,7 +26,7 @@ xfs_bnobt_dup_cursor( struct xfs_btree_cur *cur) { return xfs_bnobt_init_cursor(cur->bc_mp, cur->bc_tp, cur->bc_ag.agbp, - cur->bc_ag.pag); + to_perag(cur->bc_group)); } STATIC struct xfs_btree_cur * @@ -34,29 +34,29 @@ xfs_cntbt_dup_cursor( struct xfs_btree_cur *cur) { return xfs_cntbt_init_cursor(cur->bc_mp, cur->bc_tp, cur->bc_ag.agbp, - cur->bc_ag.pag); + to_perag(cur->bc_group)); } - STATIC void xfs_allocbt_set_root( struct xfs_btree_cur *cur, const union xfs_btree_ptr *ptr, int inc) { - struct xfs_buf *agbp = cur->bc_ag.agbp; - struct xfs_agf *agf = agbp->b_addr; + struct xfs_perag *pag = to_perag(cur->bc_group); + struct xfs_buf *agbp = cur->bc_ag.agbp; + struct xfs_agf *agf = agbp->b_addr; ASSERT(ptr->s != 0); if (xfs_btree_is_bno(cur->bc_ops)) { agf->agf_bno_root = ptr->s; be32_add_cpu(&agf->agf_bno_level, inc); - cur->bc_ag.pag->pagf_bno_level += inc; + pag->pagf_bno_level += inc; } else { agf->agf_cnt_root = ptr->s; be32_add_cpu(&agf->agf_cnt_level, inc); - cur->bc_ag.pag->pagf_cnt_level += inc; + pag->pagf_cnt_level += inc; } xfs_alloc_log_agf(cur->bc_tp, agbp, XFS_AGF_ROOTS | XFS_AGF_LEVELS); @@ -73,7 +73,7 @@ xfs_allocbt_alloc_block( xfs_agblock_t bno; /* Allocate the new block from the freelist. If we can't, give up. */ - error = xfs_alloc_get_freelist(cur->bc_ag.pag, cur->bc_tp, + error = xfs_alloc_get_freelist(to_perag(cur->bc_group), cur->bc_tp, cur->bc_ag.agbp, &bno, 1); if (error) return error; @@ -84,7 +84,7 @@ xfs_allocbt_alloc_block( } atomic64_inc(&cur->bc_mp->m_allocbt_blks); - xfs_extent_busy_reuse(pag_group(cur->bc_ag.pag), bno, 1, false); + xfs_extent_busy_reuse(cur->bc_group, bno, 1, false); new->s = cpu_to_be32(bno); @@ -102,8 +102,8 @@ xfs_allocbt_free_block( int error; bno = xfs_daddr_to_agbno(cur->bc_mp, xfs_buf_daddr(bp)); - error = xfs_alloc_put_freelist(cur->bc_ag.pag, cur->bc_tp, agbp, NULL, - bno, 1); + error = xfs_alloc_put_freelist(to_perag(cur->bc_group), cur->bc_tp, + agbp, NULL, bno, 1); if (error) return error; @@ -176,7 +176,7 @@ xfs_allocbt_init_ptr_from_cur( { struct xfs_agf *agf = cur->bc_ag.agbp->b_addr; - ASSERT(pag_agno(cur->bc_ag.pag) == be32_to_cpu(agf->agf_seqno)); + ASSERT(cur->bc_group->xg_gno == be32_to_cpu(agf->agf_seqno)); if (xfs_btree_is_bno(cur->bc_ops)) ptr->s = agf->agf_bno_root; @@ -490,7 +490,7 @@ xfs_bnobt_init_cursor( cur = xfs_btree_alloc_cursor(mp, tp, &xfs_bnobt_ops, mp->m_alloc_maxlevels, xfs_allocbt_cur_cache); - cur->bc_ag.pag = xfs_perag_hold(pag); + cur->bc_group = xfs_group_hold(pag_group(pag)); cur->bc_ag.agbp = agbp; if (agbp) { struct xfs_agf *agf = agbp->b_addr; @@ -516,7 +516,7 @@ xfs_cntbt_init_cursor( cur = xfs_btree_alloc_cursor(mp, tp, &xfs_cntbt_ops, mp->m_alloc_maxlevels, xfs_allocbt_cur_cache); - cur->bc_ag.pag = xfs_perag_hold(pag); + cur->bc_group = xfs_group_hold(pag_group(pag)); cur->bc_ag.agbp = agbp; if (agbp) { struct xfs_agf *agf = agbp->b_addr; diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c index 2b63c18114763c..3d870f3f4a5165 100644 --- a/libxfs/xfs_btree.c +++ b/libxfs/xfs_btree.c @@ -223,7 +223,7 @@ __xfs_btree_check_agblock( struct xfs_buf *bp) { struct xfs_mount *mp = cur->bc_mp; - struct xfs_perag *pag = cur->bc_ag.pag; + struct xfs_perag *pag = to_perag(cur->bc_group); xfs_failaddr_t fa; xfs_agblock_t agbno; @@ -329,7 +329,7 @@ __xfs_btree_check_ptr( return -EFSCORRUPTED; break; case XFS_BTREE_TYPE_AG: - if (!xfs_verify_agbno(cur->bc_ag.pag, + if (!xfs_verify_agbno(to_perag(cur->bc_group), be32_to_cpu((&ptr->s)[index]))) return -EFSCORRUPTED; break; @@ -370,7 +370,7 @@ xfs_btree_check_ptr( case XFS_BTREE_TYPE_AG: xfs_err(cur->bc_mp, "AG %u: Corrupt %sbt pointer at level %d index %d.", - pag_agno(cur->bc_ag.pag), cur->bc_ops->name, + cur->bc_group->xg_gno, cur->bc_ops->name, level, index); break; } @@ -521,20 +521,8 @@ xfs_btree_del_cursor( ASSERT(!xfs_btree_is_bmap(cur->bc_ops) || cur->bc_bmap.allocated == 0 || xfs_is_shutdown(cur->bc_mp) || error != 0); - switch (cur->bc_ops->type) { - case XFS_BTREE_TYPE_AG: - if (cur->bc_ag.pag) - xfs_perag_put(cur->bc_ag.pag); - break; - case XFS_BTREE_TYPE_INODE: - /* nothing to do */ - break; - case XFS_BTREE_TYPE_MEM: - if (cur->bc_mem.pag) - xfs_perag_put(cur->bc_mem.pag); - break; - } - + if (cur->bc_group) + xfs_group_put(cur->bc_group); kmem_cache_free(cur->bc_cache, cur); } @@ -1015,21 +1003,22 @@ xfs_btree_readahead_agblock( struct xfs_btree_block *block) { struct xfs_mount *mp = cur->bc_mp; + struct xfs_perag *pag = to_perag(cur->bc_group); xfs_agblock_t left = be32_to_cpu(block->bb_u.s.bb_leftsib); xfs_agblock_t right = be32_to_cpu(block->bb_u.s.bb_rightsib); int rval = 0; if ((lr & XFS_BTCUR_LEFTRA) && left != NULLAGBLOCK) { xfs_buf_readahead(mp->m_ddev_targp, - xfs_agbno_to_daddr(cur->bc_ag.pag, left), - mp->m_bsize, cur->bc_ops->buf_ops); + xfs_agbno_to_daddr(pag, left), mp->m_bsize, + cur->bc_ops->buf_ops); rval++; } if ((lr & XFS_BTCUR_RIGHTRA) && right != NULLAGBLOCK) { xfs_buf_readahead(mp->m_ddev_targp, - xfs_agbno_to_daddr(cur->bc_ag.pag, right), - mp->m_bsize, cur->bc_ops->buf_ops); + xfs_agbno_to_daddr(pag, right), mp->m_bsize, + cur->bc_ops->buf_ops); rval++; } @@ -1088,7 +1077,7 @@ xfs_btree_ptr_to_daddr( switch (cur->bc_ops->type) { case XFS_BTREE_TYPE_AG: - *daddr = xfs_agbno_to_daddr(cur->bc_ag.pag, + *daddr = xfs_agbno_to_daddr(to_perag(cur->bc_group), be32_to_cpu(ptr->s)); break; case XFS_BTREE_TYPE_INODE: @@ -1310,7 +1299,7 @@ xfs_btree_owner( case XFS_BTREE_TYPE_INODE: return cur->bc_ino.ip->i_ino; case XFS_BTREE_TYPE_AG: - return pag_agno(cur->bc_ag.pag); + return cur->bc_group->xg_gno; default: ASSERT(0); return 0; diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h index 10b7ddc3b2b34e..3b739459ebb0f4 100644 --- a/libxfs/xfs_btree.h +++ b/libxfs/xfs_btree.h @@ -254,6 +254,7 @@ struct xfs_btree_cur union xfs_btree_irec bc_rec; /* current insert/search record value */ uint8_t bc_nlevels; /* number of levels in the tree */ uint8_t bc_maxlevels; /* maximum levels for this btree type */ + struct xfs_group *bc_group; /* per-type information */ union { @@ -264,13 +265,11 @@ struct xfs_btree_cur struct xbtree_ifakeroot *ifake; /* for staging cursor */ } bc_ino; struct { - struct xfs_perag *pag; struct xfs_buf *agbp; struct xbtree_afakeroot *afake; /* for staging cursor */ } bc_ag; struct { struct xfbtree *xfbtree; - struct xfs_perag *pag; } bc_mem; }; diff --git a/libxfs/xfs_btree_mem.c b/libxfs/xfs_btree_mem.c index ae9302b9090f58..8e3efdbccc156a 100644 --- a/libxfs/xfs_btree_mem.c +++ b/libxfs/xfs_btree_mem.c @@ -56,10 +56,8 @@ xfbtree_dup_cursor( ncur->bc_flags = cur->bc_flags; ncur->bc_nlevels = cur->bc_nlevels; ncur->bc_mem.xfbtree = cur->bc_mem.xfbtree; - - if (cur->bc_mem.pag) - ncur->bc_mem.pag = xfs_perag_hold(cur->bc_mem.pag); - + if (cur->bc_group) + ncur->bc_group = xfs_group_hold(cur->bc_group); return ncur; } diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c index e4b9d3e2fbb5ce..055eff477faceb 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -137,7 +137,7 @@ xfs_inobt_complain_bad_rec( xfs_warn(mp, "%sbt record corruption in AG %d detected at %pS!", - cur->bc_ops->name, pag_agno(cur->bc_ag.pag), fa); + cur->bc_ops->name, cur->bc_group->xg_gno, fa); xfs_warn(mp, "start inode 0x%x, count 0x%x, free 0x%x freemask 0x%llx, holemask 0x%x", irec->ir_startino, irec->ir_count, irec->ir_freecount, @@ -165,7 +165,7 @@ xfs_inobt_get_rec( return error; xfs_inobt_btrec_to_irec(mp, rec, irec); - fa = xfs_inobt_check_irec(cur->bc_ag.pag, irec); + fa = xfs_inobt_check_irec(to_perag(cur->bc_group), irec); if (fa) return xfs_inobt_complain_bad_rec(cur, fa, irec); @@ -270,8 +270,10 @@ xfs_check_agi_freecount( } } while (i == 1); - if (!xfs_is_shutdown(cur->bc_mp)) - ASSERT(freecount == cur->bc_ag.pag->pagi_freecount); + if (!xfs_is_shutdown(cur->bc_mp)) { + ASSERT(freecount == + to_perag(cur->bc_group)->pagi_freecount); + } } return 0; } @@ -2875,7 +2877,7 @@ xfs_ialloc_count_inodes_rec( xfs_failaddr_t fa; xfs_inobt_btrec_to_irec(cur->bc_mp, rec, &irec); - fa = xfs_inobt_check_irec(cur->bc_ag.pag, &irec); + fa = xfs_inobt_check_irec(to_perag(cur->bc_group), &irec); if (fa) return xfs_inobt_complain_bad_rec(cur, fa, &irec); diff --git a/libxfs/xfs_ialloc_btree.c b/libxfs/xfs_ialloc_btree.c index 45908cce464dff..4eeea240b0bd89 100644 --- a/libxfs/xfs_ialloc_btree.c +++ b/libxfs/xfs_ialloc_btree.c @@ -36,7 +36,7 @@ STATIC struct xfs_btree_cur * xfs_inobt_dup_cursor( struct xfs_btree_cur *cur) { - return xfs_inobt_init_cursor(cur->bc_ag.pag, cur->bc_tp, + return xfs_inobt_init_cursor(to_perag(cur->bc_group), cur->bc_tp, cur->bc_ag.agbp); } @@ -44,7 +44,7 @@ STATIC struct xfs_btree_cur * xfs_finobt_dup_cursor( struct xfs_btree_cur *cur) { - return xfs_finobt_init_cursor(cur->bc_ag.pag, cur->bc_tp, + return xfs_finobt_init_cursor(to_perag(cur->bc_group), cur->bc_tp, cur->bc_ag.agbp); } @@ -111,7 +111,7 @@ __xfs_inobt_alloc_block( memset(&args, 0, sizeof(args)); args.tp = cur->bc_tp; args.mp = cur->bc_mp; - args.pag = cur->bc_ag.pag; + args.pag = to_perag(cur->bc_group); args.oinfo = XFS_RMAP_OINFO_INOBT; args.minlen = 1; args.maxlen = 1; @@ -247,7 +247,7 @@ xfs_inobt_init_ptr_from_cur( { struct xfs_agi *agi = cur->bc_ag.agbp->b_addr; - ASSERT(pag_agno(cur->bc_ag.pag) == be32_to_cpu(agi->agi_seqno)); + ASSERT(cur->bc_group->xg_gno == be32_to_cpu(agi->agi_seqno)); ptr->s = agi->agi_root; } @@ -259,7 +259,8 @@ xfs_finobt_init_ptr_from_cur( { struct xfs_agi *agi = cur->bc_ag.agbp->b_addr; - ASSERT(pag_agno(cur->bc_ag.pag) == be32_to_cpu(agi->agi_seqno)); + ASSERT(cur->bc_group->xg_gno == be32_to_cpu(agi->agi_seqno)); + ptr->s = agi->agi_free_root; } @@ -482,7 +483,7 @@ xfs_inobt_init_cursor( cur = xfs_btree_alloc_cursor(mp, tp, &xfs_inobt_ops, M_IGEO(mp)->inobt_maxlevels, xfs_inobt_cur_cache); - cur->bc_ag.pag = xfs_perag_hold(pag); + cur->bc_group = xfs_group_hold(pag_group(pag)); cur->bc_ag.agbp = agbp; if (agbp) { struct xfs_agi *agi = agbp->b_addr; @@ -508,7 +509,7 @@ xfs_finobt_init_cursor( cur = xfs_btree_alloc_cursor(mp, tp, &xfs_finobt_ops, M_IGEO(mp)->inobt_maxlevels, xfs_inobt_cur_cache); - cur->bc_ag.pag = xfs_perag_hold(pag); + cur->bc_group = xfs_group_hold(pag_group(pag)); cur->bc_ag.agbp = agbp; if (agbp) { struct xfs_agi *agi = agbp->b_addr; diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 9507cf74578d4f..3eccb998545d6f 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -153,7 +153,7 @@ xfs_refcount_complain_bad_rec( xfs_warn(mp, "Refcount BTree record corruption in AG %d detected at %pS!", - pag_agno(cur->bc_ag.pag), fa); + cur->bc_group->xg_gno, fa); xfs_warn(mp, "Start block 0x%x, block count 0x%x, references 0x%x", irec->rc_startblock, irec->rc_blockcount, irec->rc_refcount); @@ -179,7 +179,7 @@ xfs_refcount_get_rec( return error; xfs_refcount_btrec_to_irec(rec, irec); - fa = xfs_refcount_check_irec(cur->bc_ag.pag, irec); + fa = xfs_refcount_check_irec(to_perag(cur->bc_group), irec); if (fa) return xfs_refcount_complain_bad_rec(cur, fa, irec); @@ -1153,7 +1153,7 @@ xfs_refcount_adjust_extents( goto out_error; } } else { - fsbno = xfs_agbno_to_fsb(cur->bc_ag.pag, + fsbno = xfs_agbno_to_fsb(to_perag(cur->bc_group), tmp.rc_startblock); error = xfs_free_extent_later(cur->bc_tp, fsbno, tmp.rc_blockcount, NULL, @@ -1215,7 +1215,7 @@ xfs_refcount_adjust_extents( } goto advloop; } else { - fsbno = xfs_agbno_to_fsb(cur->bc_ag.pag, + fsbno = xfs_agbno_to_fsb(to_perag(cur->bc_group), ext.rc_startblock); error = xfs_free_extent_later(cur->bc_tp, fsbno, ext.rc_blockcount, NULL, @@ -1309,7 +1309,7 @@ xfs_refcount_continue_op( xfs_agblock_t new_agbno) { struct xfs_mount *mp = cur->bc_mp; - struct xfs_perag *pag = cur->bc_ag.pag; + struct xfs_perag *pag = to_perag(cur->bc_group); if (XFS_IS_CORRUPT(mp, !xfs_verify_agbext(pag, new_agbno, ri->ri_blockcount))) { @@ -1357,7 +1357,7 @@ xfs_refcount_finish_one( * If we haven't gotten a cursor or the cursor AG doesn't match * the startblock, get one now. */ - if (rcur != NULL && rcur->bc_ag.pag != ri->ri_pag) { + if (rcur != NULL && to_perag(rcur->bc_group) != ri->ri_pag) { nr_ops = rcur->bc_refc.nr_ops; shape_changes = rcur->bc_refc.shape_changes; xfs_btree_del_cursor(rcur, 0); @@ -1877,7 +1877,8 @@ xfs_refcount_recover_extent( INIT_LIST_HEAD(&rr->rr_list); xfs_refcount_btrec_to_irec(rec, &rr->rr_rrec); - if (xfs_refcount_check_irec(cur->bc_ag.pag, &rr->rr_rrec) != NULL || + if (xfs_refcount_check_irec(to_perag(cur->bc_group), &rr->rr_rrec) != + NULL || XFS_IS_CORRUPT(cur->bc_mp, rr->rr_rrec.rc_domain != XFS_REFC_DOMAIN_COW)) { xfs_btree_mark_sick(cur); @@ -2025,7 +2026,7 @@ xfs_refcount_query_range_helper( xfs_failaddr_t fa; xfs_refcount_btrec_to_irec(rec, &irec); - fa = xfs_refcount_check_irec(cur->bc_ag.pag, &irec); + fa = xfs_refcount_check_irec(to_perag(cur->bc_group), &irec); if (fa) return xfs_refcount_complain_bad_rec(cur, fa, &irec); diff --git a/libxfs/xfs_refcount_btree.c b/libxfs/xfs_refcount_btree.c index e9c4fc419a6114..efb9af710f7361 100644 --- a/libxfs/xfs_refcount_btree.c +++ b/libxfs/xfs_refcount_btree.c @@ -29,7 +29,7 @@ xfs_refcountbt_dup_cursor( struct xfs_btree_cur *cur) { return xfs_refcountbt_init_cursor(cur->bc_mp, cur->bc_tp, - cur->bc_ag.agbp, cur->bc_ag.pag); + cur->bc_ag.agbp, to_perag(cur->bc_group)); } STATIC void @@ -67,7 +67,7 @@ xfs_refcountbt_alloc_block( memset(&args, 0, sizeof(args)); args.tp = cur->bc_tp; args.mp = cur->bc_mp; - args.pag = cur->bc_ag.pag; + args.pag = to_perag(cur->bc_group); args.oinfo = XFS_RMAP_OINFO_REFC; args.minlen = args.maxlen = args.prod = 1; args.resv = XFS_AG_RESV_METADATA; @@ -80,7 +80,7 @@ xfs_refcountbt_alloc_block( *stat = 0; return 0; } - ASSERT(args.agno == pag_agno(cur->bc_ag.pag)); + ASSERT(args.agno == cur->bc_group->xg_gno); ASSERT(args.len == 1); new->s = cpu_to_be32(args.agbno); @@ -168,7 +168,7 @@ xfs_refcountbt_init_ptr_from_cur( { struct xfs_agf *agf = cur->bc_ag.agbp->b_addr; - ASSERT(pag_agno(cur->bc_ag.pag) == be32_to_cpu(agf->agf_seqno)); + ASSERT(cur->bc_group->xg_gno == be32_to_cpu(agf->agf_seqno)); ptr->s = agf->agf_refcount_root; } @@ -364,7 +364,7 @@ xfs_refcountbt_init_cursor( cur = xfs_btree_alloc_cursor(mp, tp, &xfs_refcountbt_ops, mp->m_refc_maxlevels, xfs_refcountbt_cur_cache); - cur->bc_ag.pag = xfs_perag_hold(pag); + cur->bc_group = xfs_group_hold(pag_group(pag)); cur->bc_refc.nr_ops = 0; cur->bc_refc.shape_changes = 0; cur->bc_ag.agbp = agbp; diff --git a/libxfs/xfs_rmap.c b/libxfs/xfs_rmap.c index e13f4aa7e99538..07bcdf82d10081 100644 --- a/libxfs/xfs_rmap.c +++ b/libxfs/xfs_rmap.c @@ -268,9 +268,7 @@ xfs_rmap_check_btrec( struct xfs_btree_cur *cur, const struct xfs_rmap_irec *irec) { - if (xfs_btree_is_mem_rmap(cur->bc_ops)) - return xfs_rmap_check_irec(cur->bc_mem.pag, irec); - return xfs_rmap_check_irec(cur->bc_ag.pag, irec); + return xfs_rmap_check_irec(to_perag(cur->bc_group), irec); } static inline int @@ -287,7 +285,7 @@ xfs_rmap_complain_bad_rec( else xfs_warn(mp, "Reverse Mapping BTree record corruption in AG %d detected at %pS!", - pag_agno(cur->bc_ag.pag), fa); + cur->bc_group->xg_gno, fa); xfs_warn(mp, "Owner 0x%llx, flags 0x%x, start block 0x%x block count 0x%x", irec->rm_owner, irec->rm_flags, irec->rm_startblock, @@ -2587,7 +2585,7 @@ xfs_rmap_finish_one( * If we haven't gotten a cursor or the cursor AG doesn't match * the startblock, get one now. */ - if (rcur != NULL && rcur->bc_ag.pag != ri->ri_pag) { + if (rcur != NULL && to_perag(rcur->bc_group) != ri->ri_pag) { xfs_btree_del_cursor(rcur, 0); rcur = NULL; *pcur = NULL; diff --git a/libxfs/xfs_rmap_btree.c b/libxfs/xfs_rmap_btree.c index 5829e68790314a..f4da35050d2635 100644 --- a/libxfs/xfs_rmap_btree.c +++ b/libxfs/xfs_rmap_btree.c @@ -56,7 +56,7 @@ xfs_rmapbt_dup_cursor( struct xfs_btree_cur *cur) { return xfs_rmapbt_init_cursor(cur->bc_mp, cur->bc_tp, - cur->bc_ag.agbp, cur->bc_ag.pag); + cur->bc_ag.agbp, to_perag(cur->bc_group)); } STATIC void @@ -65,14 +65,15 @@ xfs_rmapbt_set_root( const union xfs_btree_ptr *ptr, int inc) { - struct xfs_buf *agbp = cur->bc_ag.agbp; - struct xfs_agf *agf = agbp->b_addr; + struct xfs_buf *agbp = cur->bc_ag.agbp; + struct xfs_agf *agf = agbp->b_addr; + struct xfs_perag *pag = to_perag(cur->bc_group); ASSERT(ptr->s != 0); agf->agf_rmap_root = ptr->s; be32_add_cpu(&agf->agf_rmap_level, inc); - cur->bc_ag.pag->pagf_rmap_level += inc; + pag->pagf_rmap_level += inc; xfs_alloc_log_agf(cur->bc_tp, agbp, XFS_AGF_ROOTS | XFS_AGF_LEVELS); } @@ -86,7 +87,7 @@ xfs_rmapbt_alloc_block( { struct xfs_buf *agbp = cur->bc_ag.agbp; struct xfs_agf *agf = agbp->b_addr; - struct xfs_perag *pag = cur->bc_ag.pag; + struct xfs_perag *pag = to_perag(cur->bc_group); struct xfs_alloc_arg args = { .len = 1 }; int error; xfs_agblock_t bno; @@ -124,7 +125,7 @@ xfs_rmapbt_free_block( { struct xfs_buf *agbp = cur->bc_ag.agbp; struct xfs_agf *agf = agbp->b_addr; - struct xfs_perag *pag = cur->bc_ag.pag; + struct xfs_perag *pag = to_perag(cur->bc_group); xfs_agblock_t bno; int error; @@ -226,7 +227,7 @@ xfs_rmapbt_init_ptr_from_cur( { struct xfs_agf *agf = cur->bc_ag.agbp->b_addr; - ASSERT(pag_agno(cur->bc_ag.pag) == be32_to_cpu(agf->agf_seqno)); + ASSERT(cur->bc_group->xg_gno == be32_to_cpu(agf->agf_seqno)); ptr->s = agf->agf_rmap_root; } @@ -537,7 +538,7 @@ xfs_rmapbt_init_cursor( cur = xfs_btree_alloc_cursor(mp, tp, &xfs_rmapbt_ops, mp->m_rmap_maxlevels, xfs_rmapbt_cur_cache); - cur->bc_ag.pag = xfs_perag_hold(pag); + cur->bc_group = xfs_group_hold(pag_group(pag)); cur->bc_ag.agbp = agbp; if (agbp) { struct xfs_agf *agf = agbp->b_addr; @@ -652,7 +653,7 @@ xfs_rmapbt_mem_cursor( cur->bc_mem.xfbtree = xfbt; cur->bc_nlevels = xfbt->nlevels; - cur->bc_mem.pag = xfs_perag_hold(pag); + cur->bc_group = xfs_group_hold(pag_group(pag)); return cur; } diff --git a/repair/agbtree.c b/repair/agbtree.c index 67baa1acba9907..42bfeee9eafbcb 100644 --- a/repair/agbtree.c +++ b/repair/agbtree.c @@ -202,7 +202,7 @@ get_bno_rec( struct xfs_btree_cur *cur, struct extent_tree_node *prev_value) { - xfs_agnumber_t agno = pag_agno(cur->bc_ag.pag); + xfs_agnumber_t agno = cur->bc_group->xg_gno; if (xfs_btree_is_bno(cur->bc_ops)) { if (!prev_value) @@ -376,7 +376,7 @@ get_ino_rec( struct xfs_btree_cur *cur, struct ino_tree_node *prev_value) { - xfs_agnumber_t agno = pag_agno(cur->bc_ag.pag); + xfs_agnumber_t agno = cur->bc_group->xg_gno; if (xfs_btree_is_ino(cur->bc_ops)) { if (!prev_value) @@ -614,7 +614,7 @@ get_rmapbt_records( if (ret == 0) do_error( _("ran out of records while rebuilding AG %u rmap btree\n"), - pag_agno(cur->bc_ag.pag)); + cur->bc_group->xg_gno); block_rec = libxfs_btree_rec_addr(cur, idx, block); cur->bc_ops->init_rec_from_cur(cur, block_rec); diff --git a/repair/bmap_repair.c b/repair/bmap_repair.c index 3a214c85a1de5f..f052b5dcddff08 100644 --- a/repair/bmap_repair.c +++ b/repair/bmap_repair.c @@ -104,7 +104,7 @@ xrep_bmap_check_fork_rmap( return EFSCORRUPTED; /* Check that this is within the AG. */ - if (!xfs_verify_agbext(cur->bc_ag.pag, rec->rm_startblock, + if (!xfs_verify_agbext(to_perag(cur->bc_group), rec->rm_startblock, rec->rm_blockcount)) return EFSCORRUPTED; @@ -154,7 +154,7 @@ xrep_bmap_walk_rmap( !(rec->rm_flags & XFS_RMAP_ATTR_FORK)) return 0; - fsbno = xfs_agbno_to_fsb(cur->bc_ag.pag, rec->rm_startblock); + fsbno = xfs_agbno_to_fsb(to_perag(cur->bc_group), rec->rm_startblock); if (rec->rm_flags & XFS_RMAP_BMBT_BLOCK) { rb->old_bmbt_block_count += rec->rm_blockcount; From patchwork Mon Dec 23 21:43:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13919255 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 AEC8718052 for ; Mon, 23 Dec 2024 21:43: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=1734990187; cv=none; b=pyalYcMek9/bgHtli+6sN2zOdHBHuSI6qqqScPwDx/DB7hFHH/plFxHsMn+GKtVp+R2kIBc444pas8Lm42ysGA5rqxLJFXj+SQPOhCCWpYDNtic2RaO0vX4MVm7HJVa8RJImJ5GZDf3GHCb+M0SwMK9tw1ajKm6lycfN+os/Ih4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990187; c=relaxed/simple; bh=zp+i/tM2/QbTnmStAgeiIqTZHWvDK3lm12XI/xR1OqY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WWKRH6euRUySxnJ6aU4iEQcY7u6UIfZz9Uzzs0GCNYi/o7XcSFQaybK7aey0+PHQ/znvLifkCk0SLGDkKY7oG3DFDNWSx3DHkTfIDPxM0UKZ80iA90rFZUpaNyKxfUiYf6qnuwkNRRVJUV8N5eRGkbgG5p1ghPhcr+zeipSEc6U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PO9tTDfL; 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="PO9tTDfL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71D84C4CED3; Mon, 23 Dec 2024 21:43:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990187; bh=zp+i/tM2/QbTnmStAgeiIqTZHWvDK3lm12XI/xR1OqY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=PO9tTDfLeAmTNtf7MBSPMb8/OdepdbS9jlLPDMIjZphG5A3wC6Hc8UuayDq32P6Uy zyVbY0ZKDazuK4+pkTR3wCP2vOA2SISngykgFaXcYGxQMIVkq0xaTl5qSdMgRKL9Gf yBoKQvt5s8BYil3/lX743jQVAAUxDdo1U/LzEPKsd2ivPKWK4MQfwfckkONR4OpbFH vfqkkLOjCy0GiWsSTmMk+mCeLPVyVdPFcgiUG8TsyBq+q8Vuly/qEIFK7/Ob3YUf5G WRO9/tbmpn3C9X0PHa8MM/wMmA1jdchapa9fK+vXNmhwK0z00NvrGpDYBKYa1tcGkm UHpsf/frXwXog== Date: Mon, 23 Dec 2024 13:43:06 -0800 Subject: [PATCH 23/36] xfs: add group based bno conversion helpers From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940294.2293042.11609429469117844134.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 759cc1989a53024066b0f2ea52c206b4ff8f522c Add/move the blocks, blklog and blkmask fields to the generic groups structure so that code can work with AGs and RTGs by just using the right index into the array. Then, add convenience helpers to convert block numbers based on the generic group. This will allow writing code that doesn't care if it is used on AGs or the upcoming realtime groups. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- include/xfs_mount.h | 26 +++++++++++++++++++++ libxfs/libxfs_api_defs.h | 1 + libxfs/xfs_group.c | 9 +++++++ libxfs/xfs_group.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_sb.c | 7 ++++++ repair/bmap_repair.c | 2 +- 6 files changed, 100 insertions(+), 1 deletion(-) diff --git a/include/xfs_mount.h b/include/xfs_mount.h index 2102009aa8df73..1d36e3986ead2f 100644 --- a/include/xfs_mount.h +++ b/include/xfs_mount.h @@ -26,6 +26,32 @@ enum { struct xfs_groups { struct xarray xa; + + /* + * Maximum capacity of the group in FSBs. + * + * Each group is laid out densely in the daddr space. For the + * degenerate case of a pre-rtgroups filesystem, the incore rtgroup + * pretends to have a zero-block and zero-blklog rtgroup. + */ + uint32_t blocks; + + /* + * Log(2) of the logical size of each group. + * + * Compared to the blocks field above this is rounded up to the next + * power of two, and thus lays out the xfs_fsblock_t/xfs_rtblock_t + * space sparsely with a hole from blocks to (1 << blklog) at the end + * of each group. + */ + uint8_t blklog; + + /* + * Mask to extract the group-relative block number from a FSB. + * For a pre-rtgroups filesystem we pretend to have one very large + * rtgroup, so this mask must be 64-bit. + */ + uint64_t blkmask; }; /* diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 8f3e9e8694675d..483a7a9a4cbf45 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -168,6 +168,7 @@ #define xfs_free_extent_later libxfs_free_extent_later #define xfs_free_perag_range libxfs_free_perag_range #define xfs_fs_geometry libxfs_fs_geometry +#define xfs_gbno_to_fsb libxfs_gbno_to_fsb #define xfs_get_initial_prid libxfs_get_initial_prid #define xfs_highbit32 libxfs_highbit32 #define xfs_highbit64 libxfs_highbit64 diff --git a/libxfs/xfs_group.c b/libxfs/xfs_group.c index 9c7fa99d00b802..80b6993cc9916e 100644 --- a/libxfs/xfs_group.c +++ b/libxfs/xfs_group.c @@ -212,3 +212,12 @@ xfs_group_insert( #endif return error; } + +struct xfs_group * +xfs_group_get_by_fsb( + struct xfs_mount *mp, + xfs_fsblock_t fsbno, + enum xfs_group_type type) +{ + return xfs_group_get(mp, xfs_fsb_to_gno(mp, fsbno, type), type); +} diff --git a/libxfs/xfs_group.h b/libxfs/xfs_group.h index 0ff6e1d5635cb1..5b7362277c3f7a 100644 --- a/libxfs/xfs_group.h +++ b/libxfs/xfs_group.h @@ -46,6 +46,8 @@ struct xfs_group { struct xfs_group *xfs_group_get(struct xfs_mount *mp, uint32_t index, enum xfs_group_type type); +struct xfs_group *xfs_group_get_by_fsb(struct xfs_mount *mp, + xfs_fsblock_t fsbno, enum xfs_group_type type); struct xfs_group *xfs_group_hold(struct xfs_group *xg); void xfs_group_put(struct xfs_group *xg); @@ -72,4 +74,58 @@ int xfs_group_insert(struct xfs_mount *mp, struct xfs_group *xg, #define xfs_group_marked(_mp, _type, _mark) \ xa_marked(&(_mp)->m_groups[(_type)].xa, (_mark)) +static inline xfs_agblock_t +xfs_group_max_blocks( + struct xfs_group *xg) +{ + return xg->xg_mount->m_groups[xg->xg_type].blocks; +} + +static inline xfs_fsblock_t +xfs_group_start_fsb( + struct xfs_group *xg) +{ + return ((xfs_fsblock_t)xg->xg_gno) << + xg->xg_mount->m_groups[xg->xg_type].blklog; +} + +static inline xfs_fsblock_t +xfs_gbno_to_fsb( + struct xfs_group *xg, + xfs_agblock_t gbno) +{ + return xfs_group_start_fsb(xg) | gbno; +} + +static inline xfs_daddr_t +xfs_gbno_to_daddr( + struct xfs_group *xg, + xfs_agblock_t gbno) +{ + struct xfs_mount *mp = xg->xg_mount; + uint32_t blocks = mp->m_groups[xg->xg_type].blocks; + + return XFS_FSB_TO_BB(mp, (xfs_fsblock_t)xg->xg_gno * blocks + gbno); +} + +static inline uint32_t +xfs_fsb_to_gno( + struct xfs_mount *mp, + xfs_fsblock_t fsbno, + enum xfs_group_type type) +{ + if (!mp->m_groups[type].blklog) + return 0; + return fsbno >> mp->m_groups[type].blklog; +} + +static inline xfs_agblock_t +xfs_fsb_to_gbno( + struct xfs_mount *mp, + xfs_fsblock_t fsbno, + enum xfs_group_type type) +{ + return fsbno & mp->m_groups[type].blkmask; +} + #endif /* __LIBXFS_GROUP_H */ diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index d32f789037389f..9120a3377735b0 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -999,6 +999,8 @@ xfs_sb_mount_common( struct xfs_mount *mp, struct xfs_sb *sbp) { + struct xfs_groups *ags = &mp->m_groups[XG_TYPE_AG]; + mp->m_agfrotor = 0; atomic_set(&mp->m_agirotor, 0); mp->m_maxagi = mp->m_sb.sb_agcount; @@ -1009,6 +1011,11 @@ xfs_sb_mount_common( mp->m_blockmask = sbp->sb_blocksize - 1; mp->m_blockwsize = sbp->sb_blocksize >> XFS_WORDLOG; mp->m_blockwmask = mp->m_blockwsize - 1; + + ags->blocks = mp->m_sb.sb_agblocks; + ags->blklog = mp->m_sb.sb_agblklog; + ags->blkmask = xfs_mask32lo(mp->m_sb.sb_agblklog); + xfs_mount_sb_set_rextsize(mp, sbp); mp->m_alloc_mxr[0] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, true); diff --git a/repair/bmap_repair.c b/repair/bmap_repair.c index f052b5dcddff08..7e7c2a39f5724b 100644 --- a/repair/bmap_repair.c +++ b/repair/bmap_repair.c @@ -154,7 +154,7 @@ xrep_bmap_walk_rmap( !(rec->rm_flags & XFS_RMAP_ATTR_FORK)) return 0; - fsbno = xfs_agbno_to_fsb(to_perag(cur->bc_group), rec->rm_startblock); + fsbno = libxfs_gbno_to_fsb(cur->bc_group, rec->rm_startblock); if (rec->rm_flags & XFS_RMAP_BMBT_BLOCK) { rb->old_bmbt_block_count += rec->rm_blockcount; From patchwork Mon Dec 23 21:43:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13919256 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 881D318052 for ; Mon, 23 Dec 2024 21:43: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=1734990203; cv=none; b=Z4vXqoChhkgJtiuyO/WHJsSVTcOMbfnyaXdyVeiyJ4F6V9++bkYGgxTjB+mrZzkrblXqjUqnwKQijMQmltNz6WkYDLgkOBeUiEKykfljFmgFcxbyCc6ho62Tym+sZVwgq9j0xvrpjqpgTNApQOVHRYFkSRwbLRrM9C5ERbNNq7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990203; c=relaxed/simple; bh=onSbLMLAArbA54vKb0rc6mZB7izQJ0wsTC9dYCwv2yU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nXQKfGA/X7dapcgDTigm8TyjNKICeSMhsZ++XpfAkOqaI2hZiwMjiCge44AtzvmizxqqtTfjA+oEYzmYuN7FEs603jVvOWgHTpBBPr5DBYy72hR3HXdbNr1XE5K2vwpVYZsh4xiYsIsKjMwHGdcjWnV7lbSFQIb/uIgA8iIegE4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IirczKFd; 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="IirczKFd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 168CCC4CED3; Mon, 23 Dec 2024 21:43:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990203; bh=onSbLMLAArbA54vKb0rc6mZB7izQJ0wsTC9dYCwv2yU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=IirczKFdYdSmSS8NTWqLJ8poi4TgvOLNaj4P/kLjhlHQ8HqpfLOqfi0dg7XJ+rOPL o81EjKQ9wasmXDCEszHCC/uZrefGsBXZc1HzOJNThJtZc+X4/1MozaWuAEFNdrRwJH +bwTd7TgdfoXc93kLoUCwE7cuQlF6l03TPRIKg1qUnfGdo2+Bm4YarIDNk41eFUs8U XzX9qp4TK5sUVKxYAB3xtPKTS8IQs0FdD9B9zetYRWWe7Du0IzpsFzWWhPEl6jN5Zy PH2nuRAwpUF02fY6Si4bxh7I6b2D8tD236yXvBEBYY7waYYL5bbfDfKeBNo3DAK605 BqWPIjJUvYM/Q== Date: Mon, 23 Dec 2024 13:43:22 -0800 Subject: [PATCH 24/36] xfs: store a generic group structure in the intents From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940310.2293042.13926732996733732522.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: e5e5cae05b71aa5b5e291c0e74b4e4d98a0b05d4 Replace the pag pointers in the extent free, bmap, rmap and refcount intent structures with a pointer to the generic group to prepare for adding intents for realtime groups. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- include/xfs_mount.h | 11 ++++++----- libxfs/defer_item.c | 31 ++++++++++++++++++------------- libxfs/xfs_alloc.h | 2 +- libxfs/xfs_bmap.h | 2 +- libxfs/xfs_refcount.c | 9 +++++---- libxfs/xfs_refcount.h | 2 +- libxfs/xfs_rmap.c | 16 +++++++++------- libxfs/xfs_rmap.h | 2 +- 8 files changed, 42 insertions(+), 33 deletions(-) diff --git a/include/xfs_mount.h b/include/xfs_mount.h index 1d36e3986ead2f..1179a80d9df94e 100644 --- a/include/xfs_mount.h +++ b/include/xfs_mount.h @@ -11,6 +11,7 @@ struct xfs_inode; struct xfs_buftarg; struct xfs_da_geometry; struct libxfs_init; +struct xfs_group; typedef void (*buf_writeback_fn)(struct xfs_buf *bp); @@ -328,12 +329,12 @@ struct xfs_defer_drain { /* empty */ }; #define xfs_defer_drain_init(dr) ((void)0) #define xfs_defer_drain_free(dr) ((void)0) -#define xfs_perag_intent_get(mp, agno) \ - xfs_perag_get((mp), XFS_FSB_TO_AGNO((mp), (agno))) -#define xfs_perag_intent_put(pag) xfs_perag_put(pag) +#define xfs_group_intent_get(mp, fsbno, type) \ + xfs_group_get_by_fsb((mp), (fsbno), (type)) +#define xfs_group_intent_put(xg) xfs_group_put(xg) -static inline void xfs_perag_intent_hold(struct xfs_perag *pag) {} -static inline void xfs_perag_intent_rele(struct xfs_perag *pag) {} +static inline void xfs_group_intent_hold(struct xfs_group *xg) {} +static inline void xfs_group_intent_rele(struct xfs_group *xg) {} static inline void libxfs_buftarg_drain(struct xfs_buftarg *btp) { diff --git a/libxfs/defer_item.c b/libxfs/defer_item.c index f0f35361a0ff97..eee84ffbe625d5 100644 --- a/libxfs/defer_item.c +++ b/libxfs/defer_item.c @@ -28,6 +28,7 @@ #include "xfs_ag.h" #include "xfs_exchmaps.h" #include "defer_item.h" +#include "xfs_group.h" /* Dummy defer item ops, since we don't do logging. */ @@ -48,7 +49,7 @@ xfs_extent_free_diff_items( struct xfs_extent_free_item *ra = xefi_entry(a); struct xfs_extent_free_item *rb = xefi_entry(b); - return pag_agno(ra->xefi_pag) - pag_agno(rb->xefi_pag); + return ra->xefi_group->xg_gno - rb->xefi_group->xg_gno; } /* Get an EFI. */ @@ -85,7 +86,8 @@ xfs_extent_free_defer_add( { struct xfs_mount *mp = tp->t_mountp; - xefi->xefi_pag = xfs_perag_intent_get(mp, xefi->xefi_startblock); + 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); @@ -101,7 +103,7 @@ xfs_extent_free_cancel_item( { struct xfs_extent_free_item *xefi = xefi_entry(item); - xfs_perag_intent_put(xefi->xefi_pag); + xfs_group_intent_put(xefi->xefi_group); kmem_cache_free(xfs_extfree_item_cache, xefi); } @@ -127,7 +129,7 @@ xfs_extent_free_finish_item( agbno = XFS_FSB_TO_AGBNO(tp->t_mountp, xefi->xefi_startblock); if (!(xefi->xefi_flags & XFS_EFI_CANCELLED)) { - error = xfs_free_extent(tp, xefi->xefi_pag, agbno, + error = xfs_free_extent(tp, to_perag(xefi->xefi_group), agbno, xefi->xefi_blockcount, &oinfo, XFS_AG_RESV_NONE); } @@ -179,7 +181,7 @@ xfs_agfl_free_finish_item( agbno = XFS_FSB_TO_AGBNO(mp, xefi->xefi_startblock); oinfo.oi_owner = xefi->xefi_owner; - error = xfs_alloc_read_agf(xefi->xefi_pag, tp, 0, &agbp); + error = xfs_alloc_read_agf(to_perag(xefi->xefi_group), tp, 0, &agbp); if (!error) error = xfs_free_ag_extent(tp, agbp, agbno, 1, &oinfo, XFS_AG_RESV_AGFL); @@ -215,7 +217,7 @@ xfs_rmap_update_diff_items( struct xfs_rmap_intent *ra = ri_entry(a); struct xfs_rmap_intent *rb = ri_entry(b); - return pag_agno(ra->ri_pag) - pag_agno(rb->ri_pag); + return ra->ri_group->xg_gno - rb->ri_group->xg_gno; } /* Get an RUI. */ @@ -253,7 +255,8 @@ xfs_rmap_defer_add( trace_xfs_rmap_defer(mp, ri); - ri->ri_pag = xfs_perag_intent_get(mp, ri->ri_bmap.br_startblock); + ri->ri_group = xfs_group_intent_get(mp, ri->ri_bmap.br_startblock, + XG_TYPE_AG); xfs_defer_add(tp, &ri->ri_list, &xfs_rmap_update_defer_type); } @@ -264,7 +267,7 @@ xfs_rmap_update_cancel_item( { struct xfs_rmap_intent *ri = ri_entry(item); - xfs_perag_intent_put(ri->ri_pag); + xfs_group_intent_put(ri->ri_group); kmem_cache_free(xfs_rmap_intent_cache, ri); } @@ -336,7 +339,7 @@ xfs_refcount_update_diff_items( struct xfs_refcount_intent *ra = ci_entry(a); struct xfs_refcount_intent *rb = ci_entry(b); - return pag_agno(ra->ri_pag) - pag_agno(rb->ri_pag); + return ra->ri_group->xg_gno - rb->ri_group->xg_gno; } /* Get an CUI. */ @@ -374,7 +377,8 @@ xfs_refcount_defer_add( trace_xfs_refcount_defer(mp, ri); - ri->ri_pag = xfs_perag_intent_get(mp, ri->ri_startblock); + ri->ri_group = xfs_group_intent_get(mp, ri->ri_startblock, + XG_TYPE_AG); xfs_defer_add(tp, &ri->ri_list, &xfs_refcount_update_defer_type); } @@ -385,7 +389,7 @@ xfs_refcount_update_cancel_item( { struct xfs_refcount_intent *ri = ci_entry(item); - xfs_perag_intent_put(ri->ri_pag); + xfs_group_intent_put(ri->ri_group); kmem_cache_free(xfs_refcount_intent_cache, ri); } @@ -508,7 +512,8 @@ xfs_bmap_update_get_group( * intent drops the intent count, ensuring that the intent count * remains nonzero across the transaction roll. */ - bi->bi_pag = xfs_perag_intent_get(mp, bi->bi_bmap.br_startblock); + bi->bi_group = xfs_group_intent_get(mp, bi->bi_bmap.br_startblock, + XG_TYPE_AG); } /* Add this deferred BUI to the transaction. */ @@ -542,7 +547,7 @@ xfs_bmap_update_put_group( if (xfs_ifork_is_realtime(bi->bi_owner, bi->bi_whichfork)) return; - xfs_perag_intent_put(bi->bi_pag); + xfs_group_intent_put(bi->bi_group); } /* Cancel a deferred bmap update. */ diff --git a/libxfs/xfs_alloc.h b/libxfs/xfs_alloc.h index 88fbce5001185f..efbde04fbbb15f 100644 --- a/libxfs/xfs_alloc.h +++ b/libxfs/xfs_alloc.h @@ -248,7 +248,7 @@ struct xfs_extent_free_item { uint64_t xefi_owner; xfs_fsblock_t xefi_startblock;/* starting fs block number */ xfs_extlen_t xefi_blockcount;/* number of blocks in extent */ - struct xfs_perag *xefi_pag; + struct xfs_group *xefi_group; unsigned int xefi_flags; enum xfs_ag_resv_type xefi_agresv; }; diff --git a/libxfs/xfs_bmap.h b/libxfs/xfs_bmap.h index 7592d46e97c661..4b721d9359943b 100644 --- a/libxfs/xfs_bmap.h +++ b/libxfs/xfs_bmap.h @@ -248,7 +248,7 @@ struct xfs_bmap_intent { enum xfs_bmap_intent_type bi_type; int bi_whichfork; struct xfs_inode *bi_owner; - struct xfs_perag *bi_pag; + struct xfs_group *bi_group; struct xfs_bmbt_irec bi_bmap; }; diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 3eccb998545d6f..709e2a94176da5 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -1357,7 +1357,7 @@ xfs_refcount_finish_one( * If we haven't gotten a cursor or the cursor AG doesn't match * the startblock, get one now. */ - if (rcur != NULL && to_perag(rcur->bc_group) != ri->ri_pag) { + if (rcur != NULL && rcur->bc_group != ri->ri_group) { nr_ops = rcur->bc_refc.nr_ops; shape_changes = rcur->bc_refc.shape_changes; xfs_btree_del_cursor(rcur, 0); @@ -1365,13 +1365,14 @@ xfs_refcount_finish_one( *pcur = NULL; } if (rcur == NULL) { - error = xfs_alloc_read_agf(ri->ri_pag, tp, + struct xfs_perag *pag = to_perag(ri->ri_group); + + error = xfs_alloc_read_agf(pag, tp, XFS_ALLOC_FLAG_FREEING, &agbp); if (error) return error; - *pcur = rcur = xfs_refcountbt_init_cursor(mp, tp, agbp, - ri->ri_pag); + *pcur = rcur = xfs_refcountbt_init_cursor(mp, tp, agbp, pag); rcur->bc_refc.nr_ops = nr_ops; rcur->bc_refc.shape_changes = shape_changes; } diff --git a/libxfs/xfs_refcount.h b/libxfs/xfs_refcount.h index 68acb0b1b4a878..62d78afcf1f3ff 100644 --- a/libxfs/xfs_refcount.h +++ b/libxfs/xfs_refcount.h @@ -56,7 +56,7 @@ enum xfs_refcount_intent_type { struct xfs_refcount_intent { struct list_head ri_list; - struct xfs_perag *ri_pag; + struct xfs_group *ri_group; enum xfs_refcount_intent_type ri_type; xfs_extlen_t ri_blockcount; xfs_fsblock_t ri_startblock; diff --git a/libxfs/xfs_rmap.c b/libxfs/xfs_rmap.c index 07bcdf82d10081..dabc7003586ce4 100644 --- a/libxfs/xfs_rmap.c +++ b/libxfs/xfs_rmap.c @@ -2585,28 +2585,30 @@ xfs_rmap_finish_one( * If we haven't gotten a cursor or the cursor AG doesn't match * the startblock, get one now. */ - if (rcur != NULL && to_perag(rcur->bc_group) != ri->ri_pag) { + if (rcur != NULL && rcur->bc_group != ri->ri_group) { xfs_btree_del_cursor(rcur, 0); rcur = NULL; *pcur = NULL; } if (rcur == NULL) { + struct xfs_perag *pag = to_perag(ri->ri_group); + /* * Refresh the freelist before we start changing the * rmapbt, because a shape change could cause us to * allocate blocks. */ - error = xfs_free_extent_fix_freelist(tp, ri->ri_pag, &agbp); + error = xfs_free_extent_fix_freelist(tp, pag, &agbp); if (error) { - xfs_ag_mark_sick(ri->ri_pag, XFS_SICK_AG_AGFL); + xfs_ag_mark_sick(pag, XFS_SICK_AG_AGFL); return error; } if (XFS_IS_CORRUPT(tp->t_mountp, !agbp)) { - xfs_ag_mark_sick(ri->ri_pag, XFS_SICK_AG_AGFL); + xfs_ag_mark_sick(pag, XFS_SICK_AG_AGFL); return -EFSCORRUPTED; } - *pcur = rcur = xfs_rmapbt_init_cursor(mp, tp, agbp, ri->ri_pag); + *pcur = rcur = xfs_rmapbt_init_cursor(mp, tp, agbp, pag); } xfs_rmap_ino_owner(&oinfo, ri->ri_owner, ri->ri_whichfork, @@ -2619,8 +2621,8 @@ xfs_rmap_finish_one( if (error) return error; - xfs_rmap_update_hook(tp, pag_group(ri->ri_pag), ri->ri_type, bno, - ri->ri_bmap.br_blockcount, unwritten, &oinfo); + xfs_rmap_update_hook(tp, ri->ri_group, ri->ri_type, bno, + ri->ri_bmap.br_blockcount, unwritten, &oinfo); return 0; } diff --git a/libxfs/xfs_rmap.h b/libxfs/xfs_rmap.h index d409b463bc6662..96b4321d831007 100644 --- a/libxfs/xfs_rmap.h +++ b/libxfs/xfs_rmap.h @@ -173,7 +173,7 @@ struct xfs_rmap_intent { int ri_whichfork; uint64_t ri_owner; struct xfs_bmbt_irec ri_bmap; - struct xfs_perag *ri_pag; + struct xfs_group *ri_group; }; /* functions for updating the rmapbt based on bmbt map/unmap operations */ From patchwork Mon Dec 23 21:43: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: 13919257 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 327DC18052 for ; Mon, 23 Dec 2024 21:43:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990219; cv=none; b=acGUX/3bR7QlYKyTK7JuXXVRB9MCGeZhxt6Ro6AcbAWT7Ns1tvvlpC2qdwqGboJ9jeeKuIkxNEIMdItuCjPd94xl6+DVmgn7ugBZH3C+SC2Zj222iD3/r6VPggsNO+1U5Epjq8PvqhzkLXtk9PP3WhBtr0mUNNUfugpov+zv+Bo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990219; c=relaxed/simple; bh=1d92ETI48XjwEGT6jL2iA0Jzg/O6AraTWo+HLjkSJn4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MPFr9nucw9UN0xYMjTP0VRFIZnOorUEnrXSqSS18S7fdiUPWOpgcx/iWC+RWJpGcl7c+eUafBG/sQXmpqCz32aGppBovPA/XMLWQrGWRA0eIH3Uj9DEAimXJB4JV1H/cFsEfQTMZwuV7cnvQ8UNi/RIVWHdiqvzIdaoTlQmWyjc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZcRWGe0/; 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="ZcRWGe0/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1C05C4CED3; Mon, 23 Dec 2024 21:43:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990218; bh=1d92ETI48XjwEGT6jL2iA0Jzg/O6AraTWo+HLjkSJn4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ZcRWGe0/u7Cj6BtOrjE5JtUMBUU5gP7bs6nBhcu7+Dj3cCa/p+OoNmFt2r6lD1FUv XXaa4Qd0/HoQ8qSJ/s7qaV6o2jLJootIgKoBn9TCI5NUYXft/d4XCXRinxJ3YKG5CF Xe2rJdjw6nQyphZ0PIfMndA0udIIkTHFahNo9ZuVxSgY/GPHSpsktKxJduOPuICF6u 6PHqrHun67g9gCBDqGCgF29cFWuREvIv6gKhbREhw6Q3r7vW8kqdLTHgE2ryLFEj2w 2pIBM5V4oGP9HLRy2jfXWwdEn10k3rxZmof9eLHNiB2Slfrlbt1UmVUtQuOC6di5p0 09YtAB4ruQEMw== Date: Mon, 23 Dec 2024 13:43:38 -0800 Subject: [PATCH 25/36] xfs: constify the xfs_sb predicates From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940325.2293042.16990305927580033879.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 8d939f4bd7b225d8b157b1329881d2719c0ecb29 Change the xfs_sb predicates to take a const struct xfs_sb pointer because they do not change the superblock. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_format.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index e1bfee0c3b1a8c..a24ab46aaebc7e 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -278,7 +278,7 @@ struct xfs_dsb { #define XFS_SB_VERSION_NUM(sbp) ((sbp)->sb_versionnum & XFS_SB_VERSION_NUMBITS) -static inline bool xfs_sb_is_v5(struct xfs_sb *sbp) +static inline bool xfs_sb_is_v5(const struct xfs_sb *sbp) { return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5; } @@ -287,12 +287,12 @@ static inline bool xfs_sb_is_v5(struct xfs_sb *sbp) * Detect a mismatched features2 field. Older kernels read/wrote * this into the wrong slot, so to be safe we keep them in sync. */ -static inline bool xfs_sb_has_mismatched_features2(struct xfs_sb *sbp) +static inline bool xfs_sb_has_mismatched_features2(const struct xfs_sb *sbp) { return sbp->sb_bad_features2 != sbp->sb_features2; } -static inline bool xfs_sb_version_hasmorebits(struct xfs_sb *sbp) +static inline bool xfs_sb_version_hasmorebits(const struct xfs_sb *sbp) { return xfs_sb_is_v5(sbp) || (sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT); @@ -342,8 +342,8 @@ static inline void xfs_sb_version_addprojid32(struct xfs_sb *sbp) #define XFS_SB_FEAT_COMPAT_UNKNOWN ~XFS_SB_FEAT_COMPAT_ALL static inline bool xfs_sb_has_compat_feature( - struct xfs_sb *sbp, - uint32_t feature) + const struct xfs_sb *sbp, + uint32_t feature) { return (sbp->sb_features_compat & feature) != 0; } @@ -360,8 +360,8 @@ xfs_sb_has_compat_feature( #define XFS_SB_FEAT_RO_COMPAT_UNKNOWN ~XFS_SB_FEAT_RO_COMPAT_ALL static inline bool xfs_sb_has_ro_compat_feature( - struct xfs_sb *sbp, - uint32_t feature) + const struct xfs_sb *sbp, + uint32_t feature) { return (sbp->sb_features_ro_compat & feature) != 0; } @@ -387,8 +387,8 @@ xfs_sb_has_ro_compat_feature( #define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL static inline bool xfs_sb_has_incompat_feature( - struct xfs_sb *sbp, - uint32_t feature) + const struct xfs_sb *sbp, + uint32_t feature) { return (sbp->sb_features_incompat & feature) != 0; } @@ -399,8 +399,8 @@ xfs_sb_has_incompat_feature( #define XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_LOG_ALL static inline bool xfs_sb_has_incompat_log_feature( - struct xfs_sb *sbp, - uint32_t feature) + const struct xfs_sb *sbp, + uint32_t feature) { return (sbp->sb_features_log_incompat & feature) != 0; } @@ -420,7 +420,7 @@ xfs_sb_add_incompat_log_features( sbp->sb_features_log_incompat |= features; } -static inline bool xfs_sb_version_haslogxattrs(struct xfs_sb *sbp) +static inline bool xfs_sb_version_haslogxattrs(const struct xfs_sb *sbp) { return xfs_sb_is_v5(sbp) && (sbp->sb_features_log_incompat & XFS_SB_FEAT_INCOMPAT_LOG_XATTRS); From patchwork Mon Dec 23 21:43:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13919258 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 D52A61D7E46 for ; Mon, 23 Dec 2024 21:43:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990234; cv=none; b=OBv6X6kE6AwLIDW3K+sK2kJ9PENwB10G5UBg2u+cOtcNbDW/y2oIYjbX1oNPLHhaU7FyEQ/KBnZ7fDMu6H3S6FllArkjARsw+e5i12Y4dDrTzHbVk2gJfX9Sl0pzExg+l/Sp+UHhr4uvXSXB3DGrwEOyScbDlGp1mosTNoWYDdQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990234; c=relaxed/simple; bh=cJbkPUaZrSX8ZRuS3Ka4nE1/x3YQO12vka1VZu/O9/o=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eSgM97YK9VQdXjoYZOT3ZBYB3VOpyKjdd0t0oOhGc6QTVgH0slwk8rx48T8Ls5k13XHu+tEgxj1kGu0+oU+Lo1ou1erosRV4dEu+KXMkUf/gU4ibBpomNKRoGMh6Noi4F7w5oJa8bXK5WIKoKGRQTuL5xI+jYVKjO5SLrcDXf9Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JiffVfWt; 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="JiffVfWt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D9F7C4CED3; Mon, 23 Dec 2024 21:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990234; bh=cJbkPUaZrSX8ZRuS3Ka4nE1/x3YQO12vka1VZu/O9/o=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=JiffVfWtq1GPuG3/c3kEVxEKSP9nv8MqXfPxeUh3IpOuV4khxbtcyTnkSlZ68INIM C4f5EEbtBrWa4l1Eo3kxCIK11rs9OU53MPIjA+xa6CZIlFv/ndtVxxA3KSCOYQLt7e omBqmW/JrzfUDGUw++5rf6rsas8RFwGZk7ARWRxoAnIyDP1JmLQZsISZwQ48Udcali Bl07dxJinHDIG26dBSfLCpXqQ1MrdxpM9SZDVV3cugfgmJW92VVAHot6arBW+xXp/4 OIh3T57o6cp7Zt69mV5nD6uAfsisQ9xPLdECHhxZDGe9TJwOvds5sP5JWN9dK80x8K x6AOKmZRdcw9g== Date: Mon, 23 Dec 2024 13:43:53 -0800 Subject: [PATCH 26/36] xfs: rename metadata inode predicates From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940340.2293042.3014490112263022011.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 4d272929a5258074328dae206c935634e0fd1a54 The predicate xfs_internal_inum tells us if an inumber refers to one of the inodes rooted in the superblock. Soon we're going to have internal inodes in a metadata directory tree, so this helper should be renamed to capture its limited scope. Ondisk inodes will soon have a flag to indicate that they're metadata inodes. Head off some confusion by renaming the xfs_is_metadata_inode predicate to xfs_is_internal_inode. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/libxfs_api_defs.h | 2 +- libxfs/xfs_types.c | 4 ++-- libxfs/xfs_types.h | 2 +- repair/rmap.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 483a7a9a4cbf45..92e26eebabfed8 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -199,7 +199,7 @@ #define xfs_inode_validate_cowextsize libxfs_inode_validate_cowextsize #define xfs_inode_validate_extsize libxfs_inode_validate_extsize -#define xfs_internal_inum libxfs_internal_inum +#define xfs_is_sb_inum libxfs_is_sb_inum #define xfs_iread_extents libxfs_iread_extents #define xfs_irele libxfs_irele diff --git a/libxfs/xfs_types.c b/libxfs/xfs_types.c index 0d1b86ae59d93e..a70c0395979cf8 100644 --- a/libxfs/xfs_types.c +++ b/libxfs/xfs_types.c @@ -111,7 +111,7 @@ xfs_verify_ino( /* Is this an internal inode number? */ inline bool -xfs_internal_inum( +xfs_is_sb_inum( struct xfs_mount *mp, xfs_ino_t ino) { @@ -129,7 +129,7 @@ xfs_verify_dir_ino( struct xfs_mount *mp, xfs_ino_t ino) { - if (xfs_internal_inum(mp, ino)) + if (xfs_is_sb_inum(mp, ino)) return false; return xfs_verify_ino(mp, ino); } diff --git a/libxfs/xfs_types.h b/libxfs/xfs_types.h index d3cb6ff3b91301..25053a66c225ed 100644 --- a/libxfs/xfs_types.h +++ b/libxfs/xfs_types.h @@ -230,7 +230,7 @@ bool xfs_verify_fsbext(struct xfs_mount *mp, xfs_fsblock_t fsbno, xfs_fsblock_t len); bool xfs_verify_ino(struct xfs_mount *mp, xfs_ino_t ino); -bool xfs_internal_inum(struct xfs_mount *mp, xfs_ino_t ino); +bool xfs_is_sb_inum(struct xfs_mount *mp, xfs_ino_t ino); bool xfs_verify_dir_ino(struct xfs_mount *mp, xfs_ino_t ino); bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno); bool xfs_verify_rtbext(struct xfs_mount *mp, xfs_rtblock_t rtbno, diff --git a/repair/rmap.c b/repair/rmap.c index 29af74eee11831..3b998a22cee10d 100644 --- a/repair/rmap.c +++ b/repair/rmap.c @@ -814,7 +814,7 @@ rmap_shareable( return false; /* Metadata in files are never shareable */ - if (libxfs_internal_inum(mp, rmap->rm_owner)) + if (libxfs_is_sb_inum(mp, rmap->rm_owner)) return false; /* Metadata and unwritten file blocks are not shareable. */ From patchwork Mon Dec 23 21:44:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13919259 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 823831D5CDD for ; Mon, 23 Dec 2024 21:44: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=1734990250; cv=none; b=QSkcx6kOD45tlyLG8Z1RB+cYTwQAa7Z/z0UMrS/2WHNBT+xxEju4+8jhD4KXnct4PxFwnAnhUJboLo+ILiG2JQTHEriLb6qUtTCO4ZPHh2Ubt4BIqZDnXy1boCJFp3qqWpsuSyu3bAUoL3cuT2SiNg05fd5KLxiMdTiQ4eIoDbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990250; c=relaxed/simple; bh=s2fbnKYlB35dyeIdOTV//6Er05E0EhaOSUx2RbTbvLs=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RjZVwQiv42j39gfs26tWNSptKtdkbPmJvV93uRbReOqgsNgvRr2YKK9JuAo/Osl+pOXE40M5V+q8euiZ89WuttvhxPN7NYwd+Jb7CqJdJvOIXh8gczm3jtIV/3xNLiCbd7H1RJooQvavBkaCsXzlqy7EPB/zL1GJMOHPWvvCI44= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YRAY5g+J; 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="YRAY5g+J" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0389CC4CED3; Mon, 23 Dec 2024 21:44:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990250; bh=s2fbnKYlB35dyeIdOTV//6Er05E0EhaOSUx2RbTbvLs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=YRAY5g+JfUhkxqjq9mdvjMI1QiNOQE4eEBKKwSzXe3jkm8XoMXdo9uZt5J4bQh3W7 vQXyky9Vz7cG9N4SEF3UigLSnzm7vXZWZcW6jEPVrUOeDbLlCTStgfMiw6Pe+y+/FR F6F6q95ih2Pc34tWF8byDBPqvatUOcJkjiSjIvTaZpiL4epIwV/ahKV8Stef8w+fwX jsB14juZscjPv4FOITeFwUvyHkLZZz1CKPJDp13BFDUesjp3Cc3jx206qDjY0Nh85x dZo7xb9TZQDmLgwa1CXUZQmZLWApnSwlJOBR/PFErjpQYEm2j/jYnCgZmV0uMIu461 8LdxNZohQIn4w== Date: Mon, 23 Dec 2024 13:44:09 -0800 Subject: [PATCH 27/36] xfs: define the on-disk format for the metadir feature From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940355.2293042.14946778770633292353.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 4f3d4dd1b04b2ba0bf236fbaa3c3c0c669aa5a47 Define the on-disk layout and feature flags for the metadata inode directory feature. Add a xfs_sb_version_hasmetadir for benefit of xfs_repair, which needs to know where the new end of the superblock lies. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- db/check.c | 2 - db/inode.c | 4 +- include/xfs_inode.h | 6 +++ include/xfs_mount.h | 2 + libxfs/xfs_format.h | 97 +++++++++++++++++++++++++++++++++++++++++------ libxfs/xfs_inode_buf.c | 20 +++++++--- libxfs/xfs_inode_util.c | 2 + libxfs/xfs_log_format.h | 2 - libxfs/xfs_ondisk.h | 2 - libxfs/xfs_sb.c | 10 +++++ repair/dino_chunks.c | 2 - repair/dinode.c | 12 +++--- 12 files changed, 132 insertions(+), 29 deletions(-) diff --git a/db/check.c b/db/check.c index 0a6e5c3280e1cf..fb7b6cb41a3fbf 100644 --- a/db/check.c +++ b/db/check.c @@ -2823,7 +2823,7 @@ process_inode( return; } if (dip->di_version == 1) { - nlink = be16_to_cpu(dip->di_onlink); + nlink = be16_to_cpu(dip->di_metatype); prid = 0; } else { nlink = be32_to_cpu(dip->di_nlink); diff --git a/db/inode.c b/db/inode.c index 7a5f5a0cb987aa..246febb5929aa1 100644 --- a/db/inode.c +++ b/db/inode.c @@ -90,9 +90,9 @@ const field_t inode_core_flds[] = { { "mode", FLDT_UINT16O, OI(COFF(mode)), C1, 0, TYP_NONE }, { "version", FLDT_INT8D, OI(COFF(version)), C1, 0, TYP_NONE }, { "format", FLDT_DINODE_FMT, OI(COFF(format)), C1, 0, TYP_NONE }, - { "nlinkv1", FLDT_UINT16D, OI(COFF(onlink)), inode_core_nlinkv1_count, + { "nlinkv1", FLDT_UINT16D, OI(COFF(metatype)), inode_core_nlinkv1_count, FLD_COUNT, TYP_NONE }, - { "onlink", FLDT_UINT16D, OI(COFF(onlink)), inode_core_onlink_count, + { "onlink", FLDT_UINT16D, OI(COFF(metatype)), inode_core_onlink_count, FLD_COUNT, TYP_NONE }, { "uid", FLDT_UINT32D, OI(COFF(uid)), C1, 0, TYP_NONE }, { "gid", FLDT_UINT32D, OI(COFF(gid)), C1, 0, TYP_NONE }, diff --git a/include/xfs_inode.h b/include/xfs_inode.h index f250102ff19d65..e03521bc9aaaa2 100644 --- a/include/xfs_inode.h +++ b/include/xfs_inode.h @@ -230,6 +230,7 @@ typedef struct xfs_inode { uint16_t i_flushiter; /* incremented on flush */ }; uint8_t i_forkoff; /* attr fork offset >> 3 */ + enum xfs_metafile_type i_metatype; /* XFS_METAFILE_* */ uint16_t i_diflags; /* XFS_DIFLAG_... */ uint64_t i_diflags2; /* XFS_DIFLAG2_... */ struct timespec64 i_crtime; /* time created */ @@ -396,6 +397,11 @@ static inline bool xfs_is_always_cow_inode(struct xfs_inode *ip) return false; } +static inline bool xfs_is_metadir_inode(const struct xfs_inode *ip) +{ + return ip->i_diflags2 & XFS_DIFLAG2_METADATA; +} + extern void libxfs_trans_inode_alloc_buf (struct xfs_trans *, struct xfs_buf *); diff --git a/include/xfs_mount.h b/include/xfs_mount.h index 1179a80d9df94e..c7fada9e2a6d70 100644 --- a/include/xfs_mount.h +++ b/include/xfs_mount.h @@ -201,6 +201,7 @@ typedef struct xfs_mount { #define XFS_FEAT_NEEDSREPAIR (1ULL << 25) /* needs xfs_repair */ #define XFS_FEAT_NREXT64 (1ULL << 26) /* large extent counters */ #define XFS_FEAT_EXCHANGE_RANGE (1ULL << 27) /* exchange range */ +#define XFS_FEAT_METADIR (1ULL << 28) /* metadata directory tree */ #define __XFS_HAS_FEAT(name, NAME) \ static inline bool xfs_has_ ## name (struct xfs_mount *mp) \ @@ -246,6 +247,7 @@ __XFS_HAS_FEAT(bigtime, BIGTIME) __XFS_HAS_FEAT(needsrepair, NEEDSREPAIR) __XFS_HAS_FEAT(large_extent_counts, NREXT64) __XFS_HAS_FEAT(exchange_range, EXCHANGE_RANGE) +__XFS_HAS_FEAT(metadir, METADIR) /* Kernel mount features that we don't support */ #define __XFS_UNSUPP_FEAT(name) \ diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index a24ab46aaebc7e..616f81045921b7 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -174,6 +174,8 @@ typedef struct xfs_sb { xfs_lsn_t sb_lsn; /* last write sequence */ uuid_t sb_meta_uuid; /* metadata file system unique id */ + xfs_ino_t sb_metadirino; /* metadata directory tree root */ + /* must be padded to 64 bit alignment */ } xfs_sb_t; @@ -259,6 +261,8 @@ struct xfs_dsb { __be64 sb_lsn; /* last write sequence */ uuid_t sb_meta_uuid; /* metadata file system unique id */ + __be64 sb_metadirino; /* metadata directory tree root */ + /* must be padded to 64 bit alignment */ }; @@ -374,6 +378,7 @@ xfs_sb_has_ro_compat_feature( #define XFS_SB_FEAT_INCOMPAT_NREXT64 (1 << 5) /* large extent counters */ #define XFS_SB_FEAT_INCOMPAT_EXCHRANGE (1 << 6) /* exchangerange supported */ #define XFS_SB_FEAT_INCOMPAT_PARENT (1 << 7) /* parent pointers */ +#define XFS_SB_FEAT_INCOMPAT_METADIR (1 << 8) /* metadata dir tree */ #define XFS_SB_FEAT_INCOMPAT_ALL \ (XFS_SB_FEAT_INCOMPAT_FTYPE | \ XFS_SB_FEAT_INCOMPAT_SPINODES | \ @@ -790,6 +795,27 @@ static inline time64_t xfs_bigtime_to_unix(uint64_t ondisk_seconds) return (time64_t)ondisk_seconds - XFS_BIGTIME_EPOCH_OFFSET; } +enum xfs_metafile_type { + XFS_METAFILE_UNKNOWN, /* unknown */ + XFS_METAFILE_DIR, /* metadir directory */ + XFS_METAFILE_USRQUOTA, /* user quota */ + XFS_METAFILE_GRPQUOTA, /* group quota */ + XFS_METAFILE_PRJQUOTA, /* project quota */ + XFS_METAFILE_RTBITMAP, /* rt bitmap */ + XFS_METAFILE_RTSUMMARY, /* rt summary */ + + XFS_METAFILE_MAX +} __packed; + +#define XFS_METAFILE_TYPE_STR \ + { XFS_METAFILE_UNKNOWN, "unknown" }, \ + { XFS_METAFILE_DIR, "dir" }, \ + { XFS_METAFILE_USRQUOTA, "usrquota" }, \ + { XFS_METAFILE_GRPQUOTA, "grpquota" }, \ + { XFS_METAFILE_PRJQUOTA, "prjquota" }, \ + { XFS_METAFILE_RTBITMAP, "rtbitmap" }, \ + { XFS_METAFILE_RTSUMMARY, "rtsummary" } + /* * On-disk inode structure. * @@ -812,7 +838,7 @@ struct xfs_dinode { __be16 di_mode; /* mode and type of file */ __u8 di_version; /* inode version */ __u8 di_format; /* format of di_c data */ - __be16 di_onlink; /* old number of links to file */ + __be16 di_metatype; /* XFS_METAFILE_*; was di_onlink */ __be32 di_uid; /* owner's user id */ __be32 di_gid; /* owner's group id */ __be32 di_nlink; /* number of links to file */ @@ -1088,21 +1114,60 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev) * Values for di_flags2 These start by being exposed to userspace in the upper * 16 bits of the XFS_XFLAG_s range. */ -#define XFS_DIFLAG2_DAX_BIT 0 /* use DAX for this inode */ -#define XFS_DIFLAG2_REFLINK_BIT 1 /* file's blocks may be shared */ -#define XFS_DIFLAG2_COWEXTSIZE_BIT 2 /* copy on write extent size hint */ -#define XFS_DIFLAG2_BIGTIME_BIT 3 /* big timestamps */ -#define XFS_DIFLAG2_NREXT64_BIT 4 /* large extent counters */ - -#define XFS_DIFLAG2_DAX (1 << XFS_DIFLAG2_DAX_BIT) -#define XFS_DIFLAG2_REFLINK (1 << XFS_DIFLAG2_REFLINK_BIT) -#define XFS_DIFLAG2_COWEXTSIZE (1 << XFS_DIFLAG2_COWEXTSIZE_BIT) -#define XFS_DIFLAG2_BIGTIME (1 << XFS_DIFLAG2_BIGTIME_BIT) -#define XFS_DIFLAG2_NREXT64 (1 << XFS_DIFLAG2_NREXT64_BIT) +/* use DAX for this inode */ +#define XFS_DIFLAG2_DAX_BIT 0 + +/* file's blocks may be shared */ +#define XFS_DIFLAG2_REFLINK_BIT 1 + +/* copy on write extent size hint */ +#define XFS_DIFLAG2_COWEXTSIZE_BIT 2 + +/* big timestamps */ +#define XFS_DIFLAG2_BIGTIME_BIT 3 + +/* large extent counters */ +#define XFS_DIFLAG2_NREXT64_BIT 4 + +/* + * The inode contains filesystem metadata and can be found through the metadata + * directory tree. Metadata inodes must satisfy the following constraints: + * + * - V5 filesystem (and ftype) are enabled; + * - The only valid modes are regular files and directories; + * - The access bits must be zero; + * - DMAPI event and state masks are zero; + * - The user and group IDs must be zero; + * - The project ID can be used as a u32 annotation; + * - The immutable, sync, noatime, nodump, nodefrag flags must be set. + * - The dax flag must not be set. + * - Directories must have nosymlinks set. + * + * These requirements are chosen defensively to minimize the ability of + * userspace to read or modify the contents, should a metadata file ever + * escape to userspace. + * + * There are further constraints on the directory tree itself: + * + * - Metadata inodes must never be resolvable through the root directory; + * - They must never be accessed by userspace; + * - Metadata directory entries must have correct ftype. + * + * Superblock-rooted metadata files must have the METADATA iflag set even + * though they do not have a parent directory. + */ +#define XFS_DIFLAG2_METADATA_BIT 5 + +#define XFS_DIFLAG2_DAX (1ULL << XFS_DIFLAG2_DAX_BIT) +#define XFS_DIFLAG2_REFLINK (1ULL << XFS_DIFLAG2_REFLINK_BIT) +#define XFS_DIFLAG2_COWEXTSIZE (1ULL << XFS_DIFLAG2_COWEXTSIZE_BIT) +#define XFS_DIFLAG2_BIGTIME (1ULL << XFS_DIFLAG2_BIGTIME_BIT) +#define XFS_DIFLAG2_NREXT64 (1ULL << XFS_DIFLAG2_NREXT64_BIT) +#define XFS_DIFLAG2_METADATA (1ULL << XFS_DIFLAG2_METADATA_BIT) #define XFS_DIFLAG2_ANY \ (XFS_DIFLAG2_DAX | XFS_DIFLAG2_REFLINK | XFS_DIFLAG2_COWEXTSIZE | \ - XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64) + XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_METADATA) static inline bool xfs_dinode_has_bigtime(const struct xfs_dinode *dip) { @@ -1117,6 +1182,12 @@ static inline bool xfs_dinode_has_large_extent_counts( (dip->di_flags2 & cpu_to_be64(XFS_DIFLAG2_NREXT64)); } +static inline bool xfs_dinode_is_metadir(const struct xfs_dinode *dip) +{ + return dip->di_version >= 3 && + (dip->di_flags2 & cpu_to_be64(XFS_DIFLAG2_METADATA)); +} + /* * Inode number format: * low inopblog bits - offset in block diff --git a/libxfs/xfs_inode_buf.c b/libxfs/xfs_inode_buf.c index 5970ee705bc5a2..981113f6acd37a 100644 --- a/libxfs/xfs_inode_buf.c +++ b/libxfs/xfs_inode_buf.c @@ -206,12 +206,15 @@ xfs_inode_from_disk( * They will also be unconditionally written back to disk as v2 inodes. */ if (unlikely(from->di_version == 1)) { - set_nlink(inode, be16_to_cpu(from->di_onlink)); + /* di_metatype used to be di_onlink */ + set_nlink(inode, be16_to_cpu(from->di_metatype)); ip->i_projid = 0; } else { set_nlink(inode, be32_to_cpu(from->di_nlink)); ip->i_projid = (prid_t)be16_to_cpu(from->di_projid_hi) << 16 | be16_to_cpu(from->di_projid_lo); + if (xfs_dinode_is_metadir(from)) + ip->i_metatype = be16_to_cpu(from->di_metatype); } i_uid_write(inode, be32_to_cpu(from->di_uid)); @@ -312,7 +315,10 @@ xfs_inode_to_disk( struct inode *inode = VFS_I(ip); to->di_magic = cpu_to_be16(XFS_DINODE_MAGIC); - to->di_onlink = 0; + if (xfs_is_metadir_inode(ip)) + to->di_metatype = cpu_to_be16(ip->i_metatype); + else + to->di_metatype = 0; to->di_format = xfs_ifork_format(&ip->i_df); to->di_uid = cpu_to_be32(i_uid_read(inode)); @@ -520,8 +526,11 @@ xfs_dinode_verify( * di_nlink==0 on a V1 inode. V2/3 inodes would get written out with * di_onlink==0, so we can check that. */ - if (dip->di_version >= 2) { - if (dip->di_onlink) + if (dip->di_version == 2) { + if (dip->di_metatype) + return __this_address; + } else if (dip->di_version >= 3) { + if (!xfs_dinode_is_metadir(dip) && dip->di_metatype) return __this_address; } @@ -543,7 +552,8 @@ xfs_dinode_verify( if (dip->di_nlink) return __this_address; } else { - if (dip->di_onlink) + /* di_metatype used to be di_onlink */ + if (dip->di_metatype) return __this_address; } } diff --git a/libxfs/xfs_inode_util.c b/libxfs/xfs_inode_util.c index f9f16c7e2d0788..edc985eb9a4e45 100644 --- a/libxfs/xfs_inode_util.c +++ b/libxfs/xfs_inode_util.c @@ -221,6 +221,8 @@ xfs_inode_inherit_flags2( } if (pip->i_diflags2 & XFS_DIFLAG2_DAX) ip->i_diflags2 |= XFS_DIFLAG2_DAX; + if (xfs_is_metadir_inode(pip)) + ip->i_diflags2 |= XFS_DIFLAG2_METADATA; /* Don't let invalid cowextsize hints propagate. */ failaddr = xfs_inode_validate_cowextsize(ip->i_mount, ip->i_cowextsize, diff --git a/libxfs/xfs_log_format.h b/libxfs/xfs_log_format.h index 3e6682ed656b30..ace7384a275bfb 100644 --- a/libxfs/xfs_log_format.h +++ b/libxfs/xfs_log_format.h @@ -404,7 +404,7 @@ struct xfs_log_dinode { uint16_t di_mode; /* mode and type of file */ int8_t di_version; /* inode version */ int8_t di_format; /* format of di_c data */ - uint8_t di_pad3[2]; /* unused in v2/3 inodes */ + uint16_t di_metatype; /* metadata type, if DIFLAG2_METADATA */ uint32_t di_uid; /* owner's user id */ uint32_t di_gid; /* owner's group id */ uint32_t di_nlink; /* number of links to file */ diff --git a/libxfs/xfs_ondisk.h b/libxfs/xfs_ondisk.h index 23c133fd36f5bb..8bca86e350fdc1 100644 --- a/libxfs/xfs_ondisk.h +++ b/libxfs/xfs_ondisk.h @@ -37,7 +37,7 @@ xfs_check_ondisk_structs(void) XFS_CHECK_STRUCT_SIZE(struct xfs_dinode, 176); XFS_CHECK_STRUCT_SIZE(struct xfs_disk_dquot, 104); XFS_CHECK_STRUCT_SIZE(struct xfs_dqblk, 136); - XFS_CHECK_STRUCT_SIZE(struct xfs_dsb, 264); + XFS_CHECK_STRUCT_SIZE(struct xfs_dsb, 272); XFS_CHECK_STRUCT_SIZE(struct xfs_dsymlink_hdr, 56); XFS_CHECK_STRUCT_SIZE(struct xfs_inobt_key, 4); XFS_CHECK_STRUCT_SIZE(struct xfs_inobt_rec, 16); diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index 9120a3377735b0..de12edd8192e1c 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -177,6 +177,8 @@ xfs_sb_version_to_features( features |= XFS_FEAT_EXCHANGE_RANGE; if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_PARENT) features |= XFS_FEAT_PARENT; + if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_METADIR) + features |= XFS_FEAT_METADIR; return features; } @@ -700,6 +702,11 @@ __xfs_sb_from_disk( /* Convert on-disk flags to in-memory flags? */ if (convert_xquota) xfs_sb_quota_from_disk(to); + + if (to->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_METADIR) + to->sb_metadirino = be64_to_cpu(from->sb_metadirino); + else + to->sb_metadirino = NULLFSINO; } void @@ -847,6 +854,9 @@ xfs_sb_to_disk( to->sb_lsn = cpu_to_be64(from->sb_lsn); if (from->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_META_UUID) uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid); + + if (from->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_METADIR) + to->sb_metadirino = cpu_to_be64(from->sb_metadirino); } /* diff --git a/repair/dino_chunks.c b/repair/dino_chunks.c index 86e29dd9ae05eb..49d57948c7eca8 100644 --- a/repair/dino_chunks.c +++ b/repair/dino_chunks.c @@ -896,7 +896,7 @@ process_inode_chunk( set_inode_disk_nlinks(ino_rec, irec_offset, dino->di_version > 1 ? be32_to_cpu(dino->di_nlink) - : be16_to_cpu(dino->di_onlink)); + : be16_to_cpu(dino->di_metatype)); } else { set_inode_free(ino_rec, irec_offset); diff --git a/repair/dinode.c b/repair/dinode.c index 2c9d9acfa10be5..e217e037f8862d 100644 --- a/repair/dinode.c +++ b/repair/dinode.c @@ -2231,20 +2231,22 @@ process_check_inode_nlink_version( int dirty = 0; /* - * if it's a version 2 inode, it should have a zero + * if it's a version 2 non-metadir inode, it should have a zero * onlink field, so clear it. */ - if (dino->di_version > 1 && dino->di_onlink != 0) { + if (dino->di_version > 1 && + !(dino->di_flags2 & cpu_to_be64(XFS_DIFLAG2_METADATA)) && + dino->di_metatype != 0) { if (!no_modify) { do_warn( _("clearing obsolete nlink field in version 2 inode %" PRIu64 ", was %d, now 0\n"), - lino, be16_to_cpu(dino->di_onlink)); - dino->di_onlink = 0; + lino, be16_to_cpu(dino->di_metatype)); + dino->di_metatype = 0; dirty = 1; } else { do_warn( _("would clear obsolete nlink field in version 2 inode %" PRIu64 ", currently %d\n"), - lino, be16_to_cpu(dino->di_onlink)); + lino, be16_to_cpu(dino->di_metatype)); } } return dirty; From patchwork Mon Dec 23 21:44: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: 13919260 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 28DBB1BEF82 for ; Mon, 23 Dec 2024 21:44:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990268; cv=none; b=mkW1OK8rPrRD22fU8uAJNnZP0tb4D/c74JISyoi7BS79omk/SgLWRnx97ksB354FDraJyaqA4l4szDblGFT2nj/MOThGzUa9iwBZvRt9WnglXLCJsgjv52wMHrKIBgGr05zNLjh2AS/k/jdUG42RNsqAnizy8oITIFMMrkb3MIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990268; c=relaxed/simple; bh=9QCrWHGsZJa3B3SlkdMJlbDw/zYloxGmtzHE+XbuiB0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=S9PItlwbaCHLz9Uri2aBE2ddFG+TPMy/2RzJlAU57+o1cr+/y226y/ZFgmaAUyhF8nzM9PAzXN63QQKbN5c8hfgPPbLwqtowoCQv/pqkbRx4pL5CzuAZQHxPK7IjeFy9yfqE4X2ppE1eevqF0zonZNcmfFyUkMXqKV0BYXii2oQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KxpjQfkE; 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="KxpjQfkE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FED4C4CED3; Mon, 23 Dec 2024 21:44:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990265; bh=9QCrWHGsZJa3B3SlkdMJlbDw/zYloxGmtzHE+XbuiB0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=KxpjQfkE/ll/eVHm0DxIIsbDE5k42fqS0UXYrGicR4UcDnx4Zkx29UU5rXAlq9KhE 5/zDrxrdxmg82DbspjVX632zCYEN66s7bc+VFEPw2OWdG2VqJ+jPF4p8oE8mORFk+7 TJEC6g+aoCC5Ose4ti68c9ueiY7vgzcRyFpirGkZK5wi5Y6jeo73CGFHr3XN2Ab6op feHC+58y3FN1eLG76I3oUccCeUHiwOFz4RMKxqfsNhsYgmOevM4Zz4Uhlk89tObXwA fXgfqA/pIzINYcGij5axzIw8uSquvSt8pnJ1cIS766d+snOfncWo09LGwcxt2/8Mfa 72/3L6T4PMGmg== Date: Mon, 23 Dec 2024 13:44:25 -0800 Subject: [PATCH 28/36] xfs: iget for metadata inodes From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940371.2293042.269440098958458524.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit df2e495bb92c84a401b6b90c835a9d1be84a3a0f Create a xfs_trans_metafile_iget function for metadata inodes to ensure that when we try to iget a metadata file, the inode is allocated and its file mode matches the metadata file type the caller expects. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- include/libxfs.h | 1 + include/xfs_inode.h | 5 ++++ libxfs/Makefile | 1 + libxfs/inode.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++ libxfs/libxfs_api_defs.h | 5 ++++ libxfs/xfs_metafile.h | 16 +++++++++++++ 6 files changed, 83 insertions(+) create mode 100644 libxfs/xfs_metafile.h diff --git a/include/libxfs.h b/include/libxfs.h index fe8e6584f1caca..0356bc57b956a9 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -95,6 +95,7 @@ struct iomap; #include "xfs_btree_mem.h" #include "xfs_parent.h" #include "xfs_ag_resv.h" +#include "xfs_metafile.h" #ifndef ARRAY_SIZE #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) diff --git a/include/xfs_inode.h b/include/xfs_inode.h index e03521bc9aaaa2..6f2d23987d5f8a 100644 --- a/include/xfs_inode.h +++ b/include/xfs_inode.h @@ -210,6 +210,11 @@ static inline struct timespec64 inode_set_ctime_current(struct inode *inode) return now; } +static inline bool inode_wrong_type(const struct inode *inode, umode_t mode) +{ + return (inode->i_mode ^ mode) & S_IFMT; +} + typedef struct xfs_inode { struct cache_node i_node; struct xfs_mount *i_mount; /* fs mount struct ptr */ diff --git a/libxfs/Makefile b/libxfs/Makefile index 470583006de69a..765c84a16408f8 100644 --- a/libxfs/Makefile +++ b/libxfs/Makefile @@ -55,6 +55,7 @@ HFILES = \ xfs_inode_buf.h \ xfs_inode_fork.h \ xfs_inode_util.h \ + xfs_metafile.h \ xfs_parent.h \ xfs_quota_defs.h \ xfs_refcount.h \ diff --git a/libxfs/inode.c b/libxfs/inode.c index 9230ad24a5cb6c..1eb0bccae48906 100644 --- a/libxfs/inode.c +++ b/libxfs/inode.c @@ -205,6 +205,61 @@ libxfs_iget( return error; } +/* + * Get a metadata inode. + * + * The metafile type must match the file mode exactly. + */ +int +libxfs_trans_metafile_iget( + struct xfs_trans *tp, + xfs_ino_t ino, + enum xfs_metafile_type metafile_type, + struct xfs_inode **ipp) +{ + struct xfs_mount *mp = tp->t_mountp; + struct xfs_inode *ip; + umode_t mode; + int error; + + error = libxfs_iget(mp, tp, ino, 0, &ip); + if (error) + return error; + + if (metafile_type == XFS_METAFILE_DIR) + mode = S_IFDIR; + else + mode = S_IFREG; + if (inode_wrong_type(VFS_I(ip), mode)) + goto bad_rele; + + *ipp = ip; + return 0; +bad_rele: + libxfs_irele(ip); + return -EFSCORRUPTED; +} + +/* Grab a metadata file if the caller doesn't already have a transaction. */ +int +libxfs_metafile_iget( + struct xfs_mount *mp, + xfs_ino_t ino, + enum xfs_metafile_type metafile_type, + struct xfs_inode **ipp) +{ + struct xfs_trans *tp; + int error; + + error = libxfs_trans_alloc_empty(mp, &tp); + if (error) + return error; + + error = libxfs_trans_metafile_iget(tp, ino, metafile_type, ipp); + libxfs_trans_cancel(tp); + return error; +} + static void libxfs_idestroy( struct xfs_inode *ip) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 92e26eebabfed8..fefae9256555a0 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -184,6 +184,7 @@ #define xfs_iext_next libxfs_iext_next #define xfs_ifork_zap_attr libxfs_ifork_zap_attr #define xfs_imap_to_bp libxfs_imap_to_bp + #define xfs_initialize_perag libxfs_initialize_perag #define xfs_initialize_perag_data libxfs_initialize_perag_data #define xfs_init_local_fork libxfs_init_local_fork @@ -208,8 +209,12 @@ #define xfs_log_calc_minimum_size libxfs_log_calc_minimum_size #define xfs_log_get_max_trans_res libxfs_log_get_max_trans_res #define xfs_log_sb libxfs_log_sb + +#define xfs_metafile_iget libxfs_metafile_iget +#define xfs_trans_metafile_iget libxfs_trans_metafile_iget #define xfs_mode_to_ftype libxfs_mode_to_ftype #define xfs_mkdir_space_res libxfs_mkdir_space_res + #define xfs_parent_addname libxfs_parent_addname #define xfs_parent_finish libxfs_parent_finish #define xfs_parent_hashval libxfs_parent_hashval diff --git a/libxfs/xfs_metafile.h b/libxfs/xfs_metafile.h new file mode 100644 index 00000000000000..60fe1890611277 --- /dev/null +++ b/libxfs/xfs_metafile.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2018-2024 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#ifndef __XFS_METAFILE_H__ +#define __XFS_METAFILE_H__ + +/* Code specific to kernel/userspace; must be provided externally. */ + +int xfs_trans_metafile_iget(struct xfs_trans *tp, xfs_ino_t ino, + enum xfs_metafile_type metafile_type, struct xfs_inode **ipp); +int xfs_metafile_iget(struct xfs_mount *mp, xfs_ino_t ino, + enum xfs_metafile_type metafile_type, struct xfs_inode **ipp); + +#endif /* __XFS_METAFILE_H__ */ From patchwork Mon Dec 23 21:44:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13919261 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 752A61BE871 for ; Mon, 23 Dec 2024 21:44: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=1734990281; cv=none; b=CFffaVmHlMcZQTG+qfq+ZUfZMrHZd6CGS8QJm6UkDY0j04btYoJMJyNH56shWj8B+rKfQ4B9V5IU6aAtAc7JXOwD6CU4LMBNqVewWVm23Lg0lwRKvFKSNxcKodaS4Fy90GeEjYIcFUWu/6x59brjFRFXNk4KyKcJLoC8F9txocI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990281; c=relaxed/simple; bh=IZVoXHys9PUnBqz+s+/BaZfkcuuasJ7akohU6Ej+BpM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iFnl9z+DqGYYgqUkkCNLQcyiA1DRSbtUqaZaO041yp5gPyGsyBVuSDiOn5/TI6PDjdcr7i1FaMTGf+SeQG88w8jvYdddd0xS9i81tdWD4w4vWnMm4S5oXvvDG7BK3zjdr3DM2fkg0I/P3Vn3Oad/wz0LJcMlkoV4xaNspK0i3aM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cAJC81pT; 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="cAJC81pT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4857DC4CED3; Mon, 23 Dec 2024 21:44:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990281; bh=IZVoXHys9PUnBqz+s+/BaZfkcuuasJ7akohU6Ej+BpM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=cAJC81pTDim8mkRxxctNqqOK3QiUFkcCB5HX5ZH7K+iEsxDHqDQMWjy/lal3wFSan XJfIkHMDLKiA22B3aWLLZy5ndkHOaqiHKj2siq+GXJy+B6phGptSxnGrt5wx0m8aok SLITHXPVBHuvuZwywhzGAchXmKTfSo/BixDjJ8P3Jde/6GpjZBkRJ+HTqleaT+GgVr ZnwuodXf0BNsNt9aG/c3DfE7Mxi/Via38DxG1DnOB/EoZc/6xu5MGfMNNNgE4p1n46 NjVB+zhWqMpxS7mMzXmaGLC0iK2nrhFl2NdtbJNDhYnCJBSkHq90BtazrhxLWc5pK2 pJa/tIduJunSQ== Date: Mon, 23 Dec 2024 13:44:40 -0800 Subject: [PATCH 29/36] xfs: enforce metadata inode flag From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940386.2293042.7331978230425131716.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 7297fd0bebbd70efd12f72632a0f3ac49a8f59fe Add checks for the metadata inode flag so that we don't ever leak metadata inodes out to userspace, and we don't ever try to read a regular inode as metadata. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_inode_buf.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_inode_buf.h | 3 ++ libxfs/xfs_metafile.h | 11 ++++++++ 3 files changed, 84 insertions(+) diff --git a/libxfs/xfs_inode_buf.c b/libxfs/xfs_inode_buf.c index 981113f6acd37a..98482cb4948284 100644 --- a/libxfs/xfs_inode_buf.c +++ b/libxfs/xfs_inode_buf.c @@ -17,6 +17,7 @@ #include "xfs_ialloc.h" #include "xfs_dir2.h" #include "xfs_health.h" +#include "xfs_metafile.h" /* @@ -486,6 +487,69 @@ xfs_dinode_verify_nrext64( return NULL; } +/* + * Validate all the picky requirements we have for a file that claims to be + * filesystem metadata. + */ +xfs_failaddr_t +xfs_dinode_verify_metadir( + struct xfs_mount *mp, + struct xfs_dinode *dip, + uint16_t mode, + uint16_t flags, + uint64_t flags2) +{ + if (!xfs_has_metadir(mp)) + return __this_address; + + /* V5 filesystem only */ + if (dip->di_version < 3) + return __this_address; + + if (be16_to_cpu(dip->di_metatype) >= XFS_METAFILE_MAX) + return __this_address; + + /* V3 inode fields that are always zero */ + if ((flags2 & XFS_DIFLAG2_NREXT64) && dip->di_nrext64_pad) + return __this_address; + if (!(flags2 & XFS_DIFLAG2_NREXT64) && dip->di_flushiter) + return __this_address; + + /* Metadata files can only be directories or regular files */ + if (!S_ISDIR(mode) && !S_ISREG(mode)) + return __this_address; + + /* They must have zero access permissions */ + if (mode & 0777) + return __this_address; + + /* DMAPI event and state masks are zero */ + if (dip->di_dmevmask || dip->di_dmstate) + return __this_address; + + /* + * User and group IDs must be zero. The project ID is used for + * grouping inodes. Metadata inodes are never accounted to quotas. + */ + if (dip->di_uid || dip->di_gid) + return __this_address; + + /* Mandatory inode flags must be set */ + if (S_ISDIR(mode)) { + if ((flags & XFS_METADIR_DIFLAGS) != XFS_METADIR_DIFLAGS) + return __this_address; + } else { + if ((flags & XFS_METAFILE_DIFLAGS) != XFS_METAFILE_DIFLAGS) + return __this_address; + } + + /* dax flags2 must not be set */ + if (flags2 & XFS_DIFLAG2_DAX) + return __this_address; + + return NULL; +} + xfs_failaddr_t xfs_dinode_verify( struct xfs_mount *mp, @@ -670,6 +734,12 @@ xfs_dinode_verify( !xfs_has_bigtime(mp)) return __this_address; + if (flags2 & XFS_DIFLAG2_METADATA) { + fa = xfs_dinode_verify_metadir(mp, dip, mode, flags, flags2); + if (fa) + return fa; + } + return NULL; } diff --git a/libxfs/xfs_inode_buf.h b/libxfs/xfs_inode_buf.h index 585ed5a110af4e..8d43d2641c7328 100644 --- a/libxfs/xfs_inode_buf.h +++ b/libxfs/xfs_inode_buf.h @@ -28,6 +28,9 @@ int xfs_inode_from_disk(struct xfs_inode *ip, struct xfs_dinode *from); xfs_failaddr_t xfs_dinode_verify(struct xfs_mount *mp, xfs_ino_t ino, struct xfs_dinode *dip); +xfs_failaddr_t xfs_dinode_verify_metadir(struct xfs_mount *mp, + struct xfs_dinode *dip, uint16_t mode, uint16_t flags, + uint64_t flags2); xfs_failaddr_t xfs_inode_validate_extsize(struct xfs_mount *mp, uint32_t extsize, uint16_t mode, uint16_t flags); xfs_failaddr_t xfs_inode_validate_cowextsize(struct xfs_mount *mp, diff --git a/libxfs/xfs_metafile.h b/libxfs/xfs_metafile.h index 60fe1890611277..c66b0c51b461a8 100644 --- a/libxfs/xfs_metafile.h +++ b/libxfs/xfs_metafile.h @@ -6,6 +6,17 @@ #ifndef __XFS_METAFILE_H__ #define __XFS_METAFILE_H__ +/* All metadata files must have these flags set. */ +#define XFS_METAFILE_DIFLAGS (XFS_DIFLAG_IMMUTABLE | \ + XFS_DIFLAG_SYNC | \ + XFS_DIFLAG_NOATIME | \ + XFS_DIFLAG_NODUMP | \ + XFS_DIFLAG_NODEFRAG) + +/* All metadata directories must have these flags set. */ +#define XFS_METADIR_DIFLAGS (XFS_METAFILE_DIFLAGS | \ + XFS_DIFLAG_NOSYMLINKS) + /* Code specific to kernel/userspace; must be provided externally. */ int xfs_trans_metafile_iget(struct xfs_trans *tp, xfs_ino_t ino, From patchwork Mon Dec 23 21:44:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13919262 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 1B1D11BEF82 for ; Mon, 23 Dec 2024 21:44: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=1734990297; cv=none; b=cgk4XSlchmySLU/r5AJCJqVUoxNmrRg5rH5ZDF3ev6fvp+jMWV4EjWcVhLZnnWc2nNy6TrgCNnuCpcZnyOHkGdO5zX3L5aicx5+zxWWH2s3EmqaJgheDbOskWe6KJELRtkFSIsxwZzOR835ivFj9AKWSadNbnAkX+Ic66oJ0Iy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990297; c=relaxed/simple; bh=/5WWOuWXk6eoQtCJEOqgNEJCfeQnOofHmSshmckkt5Q=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SW1NS2garytcHiHe1lhaUs8Ms2kQZiYnR8IYSmIA+TsK/bE/UVFLEnQ6AG7yF1zGAOkDbZ8lU/hfiNNVr1sonpn0F76kk9moTCjVf0ZeoXC4D7gweCPh5yHyCrMwPdptLMFYHtN8vyMR2uv4f+//sW1aDK+GCJkFFz28eBE4sMY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ECyEGkPM; 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="ECyEGkPM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E43D7C4CED3; Mon, 23 Dec 2024 21:44:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990297; bh=/5WWOuWXk6eoQtCJEOqgNEJCfeQnOofHmSshmckkt5Q=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ECyEGkPMOjpva4OA8KI/ZN2x33j/oRfo+8gh0Ye+obihchoKnhGUoRWGmXOONJ8g7 aiSfgooxQwayeK9EYCualc0ybGzpGZp8XlUpSws7e53H4pYSeS7SB3txozTE5j4KhL M9G9oo0TbXJEfdOtvrdI2prhu3B8f4K2fMBXe+jwSugZ+uefwpHSO1J6KKsVbElpLq qXTONk+jZc7t97Z9r0X614y2pmJOnS7TU+0Huz5ZJ/FecBjpyfBGhXPUKOnZUWhcTh ycStIZYOoP8Osa32ANpYUHn2886OFy9qAwLj1k+SL5+pia/I6VQR/jlSESy4+Vtmpp aOnw4cTCzzGCQ== Date: Mon, 23 Dec 2024 13:44:56 -0800 Subject: [PATCH 30/36] xfs: read and write metadata inode directory tree From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940402.2293042.12052500366850769405.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit e0f091c40bf1287a122dcddd8aa4e6ad06ce441f Plumb in the bits we need to load metadata inodes from a named entry in a metadir directory, create (or hardlink) inodes into a metadir directory, create metadir directories, and flag inodes as being metadata files. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- include/libxfs.h | 1 include/xfs_trace.h | 10 + include/xfs_trans.h | 3 libxfs/Makefile | 3 libxfs/libxfs_api_defs.h | 7 + libxfs/libxfs_priv.h | 2 libxfs/trans.c | 39 ++++ libxfs/xfs_metadir.c | 473 ++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_metadir.h | 47 +++++ libxfs/xfs_metafile.c | 52 +++++ libxfs/xfs_metafile.h | 4 11 files changed, 641 insertions(+) create mode 100644 libxfs/xfs_metadir.c create mode 100644 libxfs/xfs_metadir.h create mode 100644 libxfs/xfs_metafile.c diff --git a/include/libxfs.h b/include/libxfs.h index 0356bc57b956a9..348d36be192966 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -96,6 +96,7 @@ struct iomap; #include "xfs_parent.h" #include "xfs_ag_resv.h" #include "xfs_metafile.h" +#include "xfs_metadir.h" #ifndef ARRAY_SIZE #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) diff --git a/include/xfs_trace.h b/include/xfs_trace.h index de435a9d1a2a64..f3e531ef118d05 100644 --- a/include/xfs_trace.h +++ b/include/xfs_trace.h @@ -360,6 +360,16 @@ #define trace_xlog_intent_recovery_failed(...) ((void) 0) +#define trace_xfs_metadir_cancel(...) ((void) 0) +#define trace_xfs_metadir_commit(...) ((void) 0) +#define trace_xfs_metadir_create(...) ((void) 0) +#define trace_xfs_metadir_link(...) ((void) 0) +#define trace_xfs_metadir_lookup(...) ((void) 0) +#define trace_xfs_metadir_start_create(...) ((void) 0) +#define trace_xfs_metadir_start_link(...) ((void) 0) +#define trace_xfs_metadir_teardown(...) ((void) 0) +#define trace_xfs_metadir_try_create(...) ((void) 0) + #define trace_xfs_iunlink_update_bucket(...) ((void) 0) #define trace_xfs_iunlink_update_dinode(...) ((void) 0) #define trace_xfs_iunlink(...) ((void) 0) diff --git a/include/xfs_trans.h b/include/xfs_trans.h index 9bc4b1ef5e82f9..d508f8947a301c 100644 --- a/include/xfs_trans.h +++ b/include/xfs_trans.h @@ -93,6 +93,9 @@ int libxfs_trans_alloc(struct xfs_mount *mp, struct xfs_trans_res *resp, int libxfs_trans_alloc_inode(struct xfs_inode *ip, struct xfs_trans_res *resv, unsigned int dblocks, unsigned int rblocks, bool force, struct xfs_trans **tpp); +int libxfs_trans_alloc_dir(struct xfs_inode *dp, struct xfs_trans_res *resv, + struct xfs_inode *ip, unsigned int *dblocks, + struct xfs_trans **tpp, int *nospace_error); int libxfs_trans_alloc_rollable(struct xfs_mount *mp, uint blocks, struct xfs_trans **tpp); int libxfs_trans_alloc_empty(struct xfs_mount *mp, struct xfs_trans **tpp); diff --git a/libxfs/Makefile b/libxfs/Makefile index 765c84a16408f8..c8267841e77b01 100644 --- a/libxfs/Makefile +++ b/libxfs/Makefile @@ -55,6 +55,7 @@ HFILES = \ xfs_inode_buf.h \ xfs_inode_fork.h \ xfs_inode_util.h \ + xfs_metadir.h \ xfs_metafile.h \ xfs_parent.h \ xfs_quota_defs.h \ @@ -114,6 +115,8 @@ CFILES = buf_mem.c \ xfs_inode_fork.c \ xfs_inode_util.c \ xfs_ialloc_btree.c \ + xfs_metadir.c \ + xfs_metafile.c \ xfs_log_rlimit.c \ xfs_parent.c \ xfs_refcount.c \ diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index fefae9256555a0..dd163709fe07df 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -176,6 +176,7 @@ #define xfs_iallocbt_calc_size libxfs_iallocbt_calc_size #define xfs_iallocbt_maxlevels_ondisk libxfs_iallocbt_maxlevels_ondisk #define xfs_ialloc_read_agi libxfs_ialloc_read_agi +#define xfs_icreate libxfs_icreate #define xfs_idata_realloc libxfs_idata_realloc #define xfs_idestroy_fork libxfs_idestroy_fork #define xfs_iext_first libxfs_iext_first @@ -212,6 +213,11 @@ #define xfs_metafile_iget libxfs_metafile_iget #define xfs_trans_metafile_iget libxfs_trans_metafile_iget +#define xfs_metadir_link libxfs_metadir_link +#define xfs_metadir_lookup libxfs_metadir_lookup +#define xfs_metadir_start_create libxfs_metadir_start_create +#define xfs_metadir_start_link libxfs_metadir_start_link + #define xfs_mode_to_ftype libxfs_mode_to_ftype #define xfs_mkdir_space_res libxfs_mkdir_space_res @@ -285,6 +291,7 @@ #define xfs_trans_add_item libxfs_trans_add_item #define xfs_trans_alloc_empty libxfs_trans_alloc_empty #define xfs_trans_alloc libxfs_trans_alloc +#define xfs_trans_alloc_dir libxfs_trans_alloc_dir #define xfs_trans_alloc_inode libxfs_trans_alloc_inode #define xfs_trans_bdetach libxfs_trans_bdetach #define xfs_trans_bhold libxfs_trans_bhold diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 1b6bb961b7ac06..631abf266ad526 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -181,6 +181,7 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC }; #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) #define XFS_STATS_ADD(mp, count, x) do { (mp) = (mp); } while (0) @@ -632,6 +633,7 @@ int xfs_bmap_last_extent(struct xfs_trans *tp, struct xfs_inode *ip, /* xfs_inode.h */ #define xfs_iflags_set(ip, flags) do { } while (0) +#define xfs_finish_inode_setup(ip) ((void) 0) /* linux/wordpart.h */ diff --git a/libxfs/trans.c b/libxfs/trans.c index 7e36205c6a3d50..72f26591053716 100644 --- a/libxfs/trans.c +++ b/libxfs/trans.c @@ -1185,6 +1185,45 @@ libxfs_trans_alloc_inode( return 0; } +/* + * Allocate an transaction, lock and join the directory and child inodes to it, + * and reserve quota for a directory update. @resblks must point to the number + * of blocks to reserve; if not enough space is available, -ENOSPC will be + * returned. @nospace_error is always set to zero here. Userspace does not + * support reservationless creation at all, unlike the kernel. + * + * The ILOCKs will be dropped when the transaction is committed or cancelled. + * + * Caller is responsible for unlocking the inodes manually upon return + */ +int +libxfs_trans_alloc_dir( + struct xfs_inode *dp, + struct xfs_trans_res *resv, + struct xfs_inode *ip, + unsigned int *resblks, + struct xfs_trans **tpp, + int *nospace_error) +{ + struct xfs_trans *tp; + struct xfs_mount *mp = ip->i_mount; + int error; + + *nospace_error = 0; + + error = xfs_trans_alloc(mp, resv, *resblks, 0, 0, &tp); + if (error) + return error; + + xfs_lock_two_inodes(dp, XFS_ILOCK_EXCL, ip, XFS_ILOCK_EXCL); + + xfs_trans_ijoin(tp, dp, 0); + xfs_trans_ijoin(tp, ip, 0); + + *tpp = tp; + return 0; +} + /* * Try to reserve more blocks for a transaction. The single use case we * support is for offline repair -- use a transaction to gather data without diff --git a/libxfs/xfs_metadir.c b/libxfs/xfs_metadir.c new file mode 100644 index 00000000000000..b52abf12d20511 --- /dev/null +++ b/libxfs/xfs_metadir.c @@ -0,0 +1,473 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018-2024 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#include "libxfs_priv.h" +#include "xfs_fs.h" +#include "xfs_shared.h" +#include "xfs_format.h" +#include "xfs_log_format.h" +#include "xfs_trans_resv.h" +#include "xfs_bit.h" +#include "xfs_sb.h" +#include "xfs_mount.h" +#include "xfs_defer.h" +#include "xfs_trans.h" +#include "xfs_metafile.h" +#include "xfs_metadir.h" +#include "xfs_trace.h" +#include "xfs_inode.h" +#include "xfs_ialloc.h" +#include "xfs_bmap_btree.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" +#include "xfs_trans_space.h" +#include "xfs_ag.h" +#include "xfs_dir2.h" +#include "xfs_dir2_priv.h" +#include "xfs_parent.h" + +/* + * Metadata Directory Tree + * ======================= + * + * These functions provide an abstraction layer for looking up, creating, and + * deleting metadata inodes that live within a special metadata directory tree. + * + * This code does not manage the five existing metadata inodes: real time + * bitmap & summary; and the user, group, and quotas. All other metadata + * inodes must use only the xfs_meta{dir,file}_* functions. + * + * Callers wishing to create or hardlink a metadata inode must create an + * xfs_metadir_update structure, call the appropriate xfs_metadir* function, + * and then call xfs_metadir_commit or xfs_metadir_cancel to commit or cancel + * the update. Files in the metadata directory tree currently cannot be + * unlinked. + * + * When the metadir feature is enabled, all metadata inodes must have the + * "metadata" inode flag set to prevent them from being exposed to the outside + * world. + * + * Callers must take the ILOCK of any inode in the metadata directory tree to + * synchronize access to that inode. It is never necessary to take the IOLOCK + * or the MMAPLOCK since metadata inodes must not be exposed to user space. + */ + +static inline void +xfs_metadir_set_xname( + struct xfs_name *xname, + const char *path, + unsigned char ftype) +{ + xname->name = (const unsigned char *)path; + xname->len = strlen(path); + xname->type = ftype; +} + +/* + * Given a parent directory @dp and a metadata inode path component @xname, + * Look up the inode number in the directory, returning it in @ino. + * @xname.type must match the directory entry's ftype. + * + * Caller must hold ILOCK_EXCL. + */ +static inline int +xfs_metadir_lookup( + struct xfs_trans *tp, + struct xfs_inode *dp, + struct xfs_name *xname, + xfs_ino_t *ino) +{ + struct xfs_mount *mp = dp->i_mount; + struct xfs_da_args args = { + .trans = tp, + .dp = dp, + .geo = mp->m_dir_geo, + .name = xname->name, + .namelen = xname->len, + .hashval = xfs_dir2_hashname(mp, xname), + .whichfork = XFS_DATA_FORK, + .op_flags = XFS_DA_OP_OKNOENT, + .owner = dp->i_ino, + }; + int error; + + if (!S_ISDIR(VFS_I(dp)->i_mode)) + return -EFSCORRUPTED; + if (xfs_is_shutdown(mp)) + return -EIO; + + error = xfs_dir_lookup_args(&args); + if (error) + return error; + + if (!xfs_verify_ino(mp, args.inumber)) + return -EFSCORRUPTED; + if (xname->type != XFS_DIR3_FT_UNKNOWN && xname->type != args.filetype) + return -EFSCORRUPTED; + + trace_xfs_metadir_lookup(dp, xname, args.inumber); + *ino = args.inumber; + return 0; +} + +/* + * Look up and read a metadata inode from the metadata directory. If the path + * component doesn't exist, return -ENOENT. + */ +int +xfs_metadir_load( + struct xfs_trans *tp, + struct xfs_inode *dp, + const char *path, + enum xfs_metafile_type metafile_type, + struct xfs_inode **ipp) +{ + struct xfs_name xname; + xfs_ino_t ino; + int error; + + xfs_metadir_set_xname(&xname, path, XFS_DIR3_FT_UNKNOWN); + + xfs_ilock(dp, XFS_ILOCK_EXCL); + error = xfs_metadir_lookup(tp, dp, &xname, &ino); + xfs_iunlock(dp, XFS_ILOCK_EXCL); + if (error) + return error; + return xfs_trans_metafile_iget(tp, ino, metafile_type, ipp); +} + +/* + * Unlock and release resources after committing (or cancelling) a metadata + * directory tree operation. The caller retains its reference to @upd->ip + * and must release it explicitly. + */ +static inline void +xfs_metadir_teardown( + struct xfs_metadir_update *upd, + int error) +{ + trace_xfs_metadir_teardown(upd, error); + + if (upd->ppargs) { + xfs_parent_finish(upd->dp->i_mount, upd->ppargs); + upd->ppargs = NULL; + } + + if (upd->ip) { + if (upd->ip_locked) + xfs_iunlock(upd->ip, XFS_ILOCK_EXCL); + upd->ip_locked = false; + } + + if (upd->dp_locked) + xfs_iunlock(upd->dp, XFS_ILOCK_EXCL); + upd->dp_locked = false; +} + +/* + * Begin the process of creating a metadata file by allocating transactions + * and taking whatever resources we're going to need. + */ +int +xfs_metadir_start_create( + struct xfs_metadir_update *upd) +{ + struct xfs_mount *mp = upd->dp->i_mount; + int error; + + ASSERT(upd->dp != NULL); + ASSERT(upd->ip == NULL); + ASSERT(xfs_has_metadir(mp)); + ASSERT(upd->metafile_type != XFS_METAFILE_UNKNOWN); + + error = xfs_parent_start(mp, &upd->ppargs); + if (error) + return error; + + /* + * If we ever need the ability to create rt metadata files on a + * pre-metadir filesystem, we'll need to dqattach the parent here. + * Currently we assume that mkfs will create the files and quotacheck + * will account for them. + */ + + error = xfs_trans_alloc(mp, &M_RES(mp)->tr_create, + xfs_create_space_res(mp, MAXNAMELEN), 0, 0, &upd->tp); + if (error) + goto out_teardown; + + /* + * Lock the parent directory if there is one. We can't ijoin it to + * the transaction until after the child file has been created. + */ + xfs_ilock(upd->dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT); + upd->dp_locked = true; + + trace_xfs_metadir_start_create(upd); + return 0; +out_teardown: + xfs_metadir_teardown(upd, error); + return error; +} + +/* + * Create a metadata inode with the given @mode, and insert it into the + * metadata directory tree at the given @upd->path. The path up to the final + * component must already exist. The final path component must not exist. + * + * The new metadata inode will be attached to the update structure @upd->ip, + * with the ILOCK held until the caller releases it. + * + * NOTE: This function may return a new inode to the caller even if it returns + * a negative error code. If an inode is passed back, the caller must finish + * setting up the inode before releasing it. + */ +int +xfs_metadir_create( + struct xfs_metadir_update *upd, + umode_t mode) +{ + struct xfs_icreate_args args = { + .pip = upd->dp, + .mode = mode, + }; + struct xfs_name xname; + struct xfs_dir_update du = { + .dp = upd->dp, + .name = &xname, + .ppargs = upd->ppargs, + }; + struct xfs_mount *mp = upd->dp->i_mount; + xfs_ino_t ino; + unsigned int resblks; + int error; + + xfs_assert_ilocked(upd->dp, XFS_ILOCK_EXCL); + + /* Check that the name does not already exist in the directory. */ + xfs_metadir_set_xname(&xname, upd->path, XFS_DIR3_FT_UNKNOWN); + error = xfs_metadir_lookup(upd->tp, upd->dp, &xname, &ino); + switch (error) { + case -ENOENT: + break; + case 0: + error = -EEXIST; + fallthrough; + default: + return error; + } + + /* + * A newly created regular or special file just has one directory + * entry pointing to them, but a directory also the "." entry + * pointing to itself. + */ + error = xfs_dialloc(&upd->tp, &args, &ino); + if (error) + return error; + error = xfs_icreate(upd->tp, ino, &args, &upd->ip); + if (error) + return error; + du.ip = upd->ip; + xfs_metafile_set_iflag(upd->tp, upd->ip, upd->metafile_type); + upd->ip_locked = true; + + /* + * Join the directory inode to the transaction. We do not do it + * earlier because xfs_dialloc rolls the transaction. + */ + xfs_trans_ijoin(upd->tp, upd->dp, 0); + + /* Create the entry. */ + if (S_ISDIR(args.mode)) + resblks = xfs_mkdir_space_res(mp, xname.len); + else + resblks = xfs_create_space_res(mp, xname.len); + xname.type = xfs_mode_to_ftype(args.mode); + + trace_xfs_metadir_try_create(upd); + + error = xfs_dir_create_child(upd->tp, resblks, &du); + if (error) + return error; + + /* Metadir files are not accounted to quota. */ + + trace_xfs_metadir_create(upd); + + return 0; +} + +#ifndef __KERNEL__ +/* + * Begin the process of linking a metadata file by allocating transactions + * and locking whatever resources we're going to need. + */ +int +xfs_metadir_start_link( + struct xfs_metadir_update *upd) +{ + struct xfs_mount *mp = upd->dp->i_mount; + unsigned int resblks; + int nospace_error = 0; + int error; + + ASSERT(upd->dp != NULL); + ASSERT(upd->ip != NULL); + ASSERT(xfs_has_metadir(mp)); + + error = xfs_parent_start(mp, &upd->ppargs); + if (error) + return error; + + resblks = xfs_link_space_res(mp, MAXNAMELEN); + error = xfs_trans_alloc_dir(upd->dp, &M_RES(mp)->tr_link, upd->ip, + &resblks, &upd->tp, &nospace_error); + if (error) + goto out_teardown; + if (!resblks) { + /* We don't allow reservationless updates. */ + xfs_trans_cancel(upd->tp); + upd->tp = NULL; + xfs_iunlock(upd->dp, XFS_ILOCK_EXCL); + xfs_iunlock(upd->ip, XFS_ILOCK_EXCL); + error = nospace_error; + goto out_teardown; + } + + upd->dp_locked = true; + upd->ip_locked = true; + + trace_xfs_metadir_start_link(upd); + return 0; +out_teardown: + xfs_metadir_teardown(upd, error); + return error; +} + +/* + * Link the metadata directory given by @path to the inode @upd->ip. + * The path (up to the final component) must already exist, but the final + * component must not already exist. + */ +int +xfs_metadir_link( + struct xfs_metadir_update *upd) +{ + struct xfs_name xname; + struct xfs_dir_update du = { + .dp = upd->dp, + .name = &xname, + .ip = upd->ip, + .ppargs = upd->ppargs, + }; + struct xfs_mount *mp = upd->dp->i_mount; + xfs_ino_t ino; + unsigned int resblks; + int error; + + xfs_assert_ilocked(upd->dp, XFS_ILOCK_EXCL); + xfs_assert_ilocked(upd->ip, XFS_ILOCK_EXCL); + + /* Look up the name in the current directory. */ + xfs_metadir_set_xname(&xname, upd->path, + xfs_mode_to_ftype(VFS_I(upd->ip)->i_mode)); + error = xfs_metadir_lookup(upd->tp, upd->dp, &xname, &ino); + switch (error) { + case -ENOENT: + break; + case 0: + error = -EEXIST; + fallthrough; + default: + return error; + } + + resblks = xfs_link_space_res(mp, xname.len); + error = xfs_dir_add_child(upd->tp, resblks, &du); + if (error) + return error; + + trace_xfs_metadir_link(upd); + + return 0; +} +#endif /* ! __KERNEL__ */ + +/* Commit a metadir update and unlock/drop all resources. */ +int +xfs_metadir_commit( + struct xfs_metadir_update *upd) +{ + int error; + + trace_xfs_metadir_commit(upd); + + error = xfs_trans_commit(upd->tp); + upd->tp = NULL; + + xfs_metadir_teardown(upd, error); + return error; +} + +/* Cancel a metadir update and unlock/drop all resources. */ +void +xfs_metadir_cancel( + struct xfs_metadir_update *upd, + int error) +{ + trace_xfs_metadir_cancel(upd); + + xfs_trans_cancel(upd->tp); + upd->tp = NULL; + + xfs_metadir_teardown(upd, error); +} + +/* Create a metadata for the last component of the path. */ +int +xfs_metadir_mkdir( + struct xfs_inode *dp, + const char *path, + struct xfs_inode **ipp) +{ + struct xfs_metadir_update upd = { + .dp = dp, + .path = path, + .metafile_type = XFS_METAFILE_DIR, + }; + int error; + + if (xfs_is_shutdown(dp->i_mount)) + return -EIO; + + /* Allocate a transaction to create the last directory. */ + error = xfs_metadir_start_create(&upd); + if (error) + return error; + + /* Create the subdirectory and take our reference. */ + error = xfs_metadir_create(&upd, S_IFDIR); + if (error) + goto out_cancel; + + error = xfs_metadir_commit(&upd); + if (error) + goto out_irele; + + xfs_finish_inode_setup(upd.ip); + *ipp = upd.ip; + return 0; + +out_cancel: + xfs_metadir_cancel(&upd, error); +out_irele: + /* Have to finish setting up the inode to ensure it's deleted. */ + if (upd.ip) { + xfs_finish_inode_setup(upd.ip); + xfs_irele(upd.ip); + } + return error; +} diff --git a/libxfs/xfs_metadir.h b/libxfs/xfs_metadir.h new file mode 100644 index 00000000000000..bfecac7d3d1472 --- /dev/null +++ b/libxfs/xfs_metadir.h @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2018-2024 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#ifndef __XFS_METADIR_H__ +#define __XFS_METADIR_H__ + +/* Cleanup widget for metadata inode creation and deletion. */ +struct xfs_metadir_update { + /* Parent directory */ + struct xfs_inode *dp; + + /* Path to metadata file */ + const char *path; + + /* Parent pointer update context */ + struct xfs_parent_args *ppargs; + + /* Child metadata file */ + struct xfs_inode *ip; + + struct xfs_trans *tp; + + enum xfs_metafile_type metafile_type; + + unsigned int dp_locked:1; + unsigned int ip_locked:1; +}; + +int xfs_metadir_load(struct xfs_trans *tp, struct xfs_inode *dp, + const char *path, enum xfs_metafile_type metafile_type, + struct xfs_inode **ipp); + +int xfs_metadir_start_create(struct xfs_metadir_update *upd); +int xfs_metadir_create(struct xfs_metadir_update *upd, umode_t mode); + +int xfs_metadir_start_link(struct xfs_metadir_update *upd); +int xfs_metadir_link(struct xfs_metadir_update *upd); + +int xfs_metadir_commit(struct xfs_metadir_update *upd); +void xfs_metadir_cancel(struct xfs_metadir_update *upd, int error); + +int xfs_metadir_mkdir(struct xfs_inode *dp, const char *path, + struct xfs_inode **ipp); + +#endif /* __XFS_METADIR_H__ */ diff --git a/libxfs/xfs_metafile.c b/libxfs/xfs_metafile.c new file mode 100644 index 00000000000000..3bd9493373115a --- /dev/null +++ b/libxfs/xfs_metafile.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018-2024 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#include "libxfs_priv.h" +#include "xfs_fs.h" +#include "xfs_shared.h" +#include "xfs_format.h" +#include "xfs_log_format.h" +#include "xfs_trans_resv.h" +#include "xfs_bit.h" +#include "xfs_sb.h" +#include "xfs_mount.h" +#include "xfs_defer.h" +#include "xfs_trans.h" +#include "xfs_metafile.h" +#include "xfs_trace.h" +#include "xfs_inode.h" + +/* Set up an inode to be recognized as a metadata directory inode. */ +void +xfs_metafile_set_iflag( + struct xfs_trans *tp, + struct xfs_inode *ip, + enum xfs_metafile_type metafile_type) +{ + VFS_I(ip)->i_mode &= ~0777; + VFS_I(ip)->i_uid = GLOBAL_ROOT_UID; + VFS_I(ip)->i_gid = GLOBAL_ROOT_GID; + if (S_ISDIR(VFS_I(ip)->i_mode)) + ip->i_diflags |= XFS_METADIR_DIFLAGS; + else + ip->i_diflags |= XFS_METAFILE_DIFLAGS; + ip->i_diflags2 &= ~XFS_DIFLAG2_DAX; + ip->i_diflags2 |= XFS_DIFLAG2_METADATA; + ip->i_metatype = metafile_type; + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); +} + +/* Clear the metadata directory inode flag. */ +void +xfs_metafile_clear_iflag( + struct xfs_trans *tp, + struct xfs_inode *ip) +{ + ASSERT(xfs_is_metadir_inode(ip)); + ASSERT(VFS_I(ip)->i_nlink == 0); + + ip->i_diflags2 &= ~XFS_DIFLAG2_METADATA; + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); +} diff --git a/libxfs/xfs_metafile.h b/libxfs/xfs_metafile.h index c66b0c51b461a8..acec400123db05 100644 --- a/libxfs/xfs_metafile.h +++ b/libxfs/xfs_metafile.h @@ -17,6 +17,10 @@ #define XFS_METADIR_DIFLAGS (XFS_METAFILE_DIFLAGS | \ XFS_DIFLAG_NOSYMLINKS) +void xfs_metafile_set_iflag(struct xfs_trans *tp, struct xfs_inode *ip, + enum xfs_metafile_type metafile_type); +void xfs_metafile_clear_iflag(struct xfs_trans *tp, struct xfs_inode *ip); + /* Code specific to kernel/userspace; must be provided externally. */ int xfs_trans_metafile_iget(struct xfs_trans *tp, xfs_ino_t ino, From patchwork Mon Dec 23 21:45: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: 13919263 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 0A9D61C5F0B for ; Mon, 23 Dec 2024 21:45:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990313; cv=none; b=o7Id+WjZXoaKGoLJ5OYyhvFIA/uHy3jVeJYOxxdoZN6pfae1lJFrKiO8TpPI34PiJ1oqDl4Vz2Flewg9Zxyo1sgU8vEvmH3a/0fVfbbHXWV8TAJfHwgVULp+yP2RpThK0qLrmEMc75oUyAuA0cXTHQmCDlR74Oe+hhxtJS/M9YU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990313; c=relaxed/simple; bh=oxjh7kBLjtEhobK1FPbM45oYdkoYPhXqz8TCDXlHHPI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=clUp7pa8ahQxi7/hOytN87odZl5qyN36Bt+p4kF1zXFzDers04tEHlhUg4r3pzvdaGM4ZHGm5y21LgF9JetouCfvuItPh+WWStu327heDkxUQEtDapT7iqyw0Zhziwc0wPfK4Mqnb8OiaeSoMSWYGUPPrOviPR1s+2ol2FlEvg8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Rywn1/3G; 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="Rywn1/3G" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A1A9C4CED3; Mon, 23 Dec 2024 21:45:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990312; bh=oxjh7kBLjtEhobK1FPbM45oYdkoYPhXqz8TCDXlHHPI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Rywn1/3GWt5A8rB9z/9ogigdRtt5T06xPzdVcQnZ4QRdtbXzlC0MBM7LWqnTrZoB+ YUEyEs7Q73NuoGN+bFiwzb93Gxi1NMIIVhF8qkdUuRQYv+fTeBGRXO1QB29yS8zKWu +Zf927kSCaJ9ZE//R60ELGwQOqq/DPxbyG8Uhg5MTyeoYzSUiHuPVYOaQkjEMQEL+S e1AJv9TjQyK7+v8dqlKklV8Bnm9wD6XsuN0Z2TydCR7j76dvtb79+hv6nI8TZMBvEe xz2211dsg1FvWU0dhQK+lvb33gaXd4N9x7r4Y1NxmM3m9tonjrmSflB8sgAV71JctD UVv6UOjunJ6Rw== Date: Mon, 23 Dec 2024 13:45:12 -0800 Subject: [PATCH 31/36] xfs: disable the agi rotor for metadata inodes From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940417.2293042.6897059387879878254.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 8651b410ae781cc607159c51dbb0b317b23543b1 Ideally, we'd put all the metadata inodes in one place if we could, so that the metadata all stay reasonably close together instead of spreading out over the disk. Furthermore, if the log is internal we'd probably prefer to keep the metadata near the log. Therefore, disable AGI rotoring for metadata inode allocations. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_ialloc.c | 58 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c index 055eff477faceb..2575447f92dfbb 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -1836,6 +1836,40 @@ xfs_dialloc_try_ag( return error; } +/* + * Pick an AG for the new inode. + * + * Directories, symlinks, and regular files frequently allocate at least one + * block, so factor that potential expansion when we examine whether an AG has + * enough space for file creation. Try to keep metadata files all in the same + * AG. + */ +static inline xfs_agnumber_t +xfs_dialloc_pick_ag( + struct xfs_mount *mp, + struct xfs_inode *dp, + umode_t mode) +{ + xfs_agnumber_t start_agno; + + if (!dp) + return 0; + if (xfs_is_metadir_inode(dp)) { + if (mp->m_sb.sb_logstart) + return XFS_FSB_TO_AGNO(mp, mp->m_sb.sb_logstart); + return 0; + } + + if (S_ISDIR(mode)) + return (atomic_inc_return(&mp->m_agirotor) - 1) % mp->m_maxagi; + + start_agno = XFS_INO_TO_AGNO(mp, dp->i_ino); + if (start_agno >= mp->m_maxagi) + start_agno = 0; + + return start_agno; +} + /* * Allocate an on-disk inode. * @@ -1851,31 +1885,19 @@ xfs_dialloc( xfs_ino_t *new_ino) { struct xfs_mount *mp = (*tpp)->t_mountp; + struct xfs_perag *pag; + struct xfs_ino_geometry *igeo = M_IGEO(mp); + xfs_ino_t ino = NULLFSINO; xfs_ino_t parent = args->pip ? args->pip->i_ino : 0; - umode_t mode = args->mode & S_IFMT; xfs_agnumber_t agno; - int error = 0; xfs_agnumber_t start_agno; - struct xfs_perag *pag; - struct xfs_ino_geometry *igeo = M_IGEO(mp); + umode_t mode = args->mode & S_IFMT; bool ok_alloc = true; bool low_space = false; int flags; - xfs_ino_t ino = NULLFSINO; + int error = 0; - /* - * Directories, symlinks, and regular files frequently allocate at least - * one block, so factor that potential expansion when we examine whether - * an AG has enough space for file creation. - */ - if (S_ISDIR(mode)) - start_agno = (atomic_inc_return(&mp->m_agirotor) - 1) % - mp->m_maxagi; - else { - start_agno = XFS_INO_TO_AGNO(mp, parent); - if (start_agno >= mp->m_maxagi) - start_agno = 0; - } + start_agno = xfs_dialloc_pick_ag(mp, args->pip, mode); /* * If we have already hit the ceiling of inode blocks then clear From patchwork Mon Dec 23 21:45:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13919264 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 A77F219048A for ; Mon, 23 Dec 2024 21:45:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990328; cv=none; b=WkzyP7RCbFP5hrdfwd+O5VrrWh3/w+9jQVk/+ZGowLHWmtI4A6FLFNvMocJb/TAh58pRT2W/hSB6ShFws3YqQ7m7N5IiW/WOl4W37rfE6bhVMd7cXX7pVGkZT9eEDdHlWpxisFoEUTxmTNdWp17bwIMT8bTnIyM1sFeSY5tmYoY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990328; c=relaxed/simple; bh=dIwngUAllLCIFo9fuvFGhs/Z4uqBhX4bjwnojaYl6aQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UfSoohmVq/kNubhOHW9uNTtHCYkuk6Pywg3auDcqHagG4atcgcaPa1HtUN90heZgar6KsXrVm7FVJMYnX3M4bFpc7OOE6BxYdfAN/3degpFouPCCse7rA4F/MZRwaP6gIulu83HLjYAdxPyJk3cdTK80md/Qw/9czRb4UB+UNtA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LJ9KUgHS; 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="LJ9KUgHS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C3F2C4CED3; Mon, 23 Dec 2024 21:45:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990328; bh=dIwngUAllLCIFo9fuvFGhs/Z4uqBhX4bjwnojaYl6aQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=LJ9KUgHS+z3rlHy/LzRTErPzdQCTPSpfM91GPUQYzfMd9DkXD5zlFJATCM+FWcQ2i JSyuM2HWzpfeKjIQm08amaGiM7HfhkOSwSrkjqHPwcLJgA22qNnJuYUA7/oNZw5fop HwESijbzHhGJO0rAvWpQ71b/HfFDhVscpQuz9Zl3pejPuIjedbLin2EqzzeguiNXEh /Ey5ld/eUzVhllIhA2nBrQnknAr1+vGRbp6kiBraGGIB70v5AZfJswo+3quzsQY7Er E6bHQicWGOy8FIA1dVznYJ2uKIxJhHmZl9fPJIVK+oIoVi6tRdw7/S9OriOHZXfmV5 tvxtsCovrG44g== Date: Mon, 23 Dec 2024 13:45:27 -0800 Subject: [PATCH 32/36] xfs: advertise metadata directory feature From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940432.2293042.4388607088123847451.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 688828d8f8cdf8b1b917de938a1ce86a93fdbba9 Advertise the existence of the metadata directory feature; this will be used by scrub to decide if it needs to scan the metadir too. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_fs.h | 1 + libxfs/xfs_sb.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index 860284064c5aa9..a42c1a33691c0f 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -242,6 +242,7 @@ typedef struct xfs_fsop_resblks { #define XFS_FSOP_GEOM_FLAGS_NREXT64 (1 << 23) /* large extent counters */ #define XFS_FSOP_GEOM_FLAGS_EXCHANGE_RANGE (1 << 24) /* exchange range */ #define XFS_FSOP_GEOM_FLAGS_PARENT (1 << 25) /* linux parent pointers */ +#define XFS_FSOP_GEOM_FLAGS_METADIR (1 << 26) /* metadata directories */ /* * Minimum and maximum sizes need for growth checks. diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index de12edd8192e1c..4ca57d592be8fa 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -1306,6 +1306,8 @@ xfs_fs_geometry( geo->flags |= XFS_FSOP_GEOM_FLAGS_NREXT64; if (xfs_has_exchange_range(mp)) geo->flags |= XFS_FSOP_GEOM_FLAGS_EXCHANGE_RANGE; + if (xfs_has_metadir(mp)) + geo->flags |= XFS_FSOP_GEOM_FLAGS_METADIR; geo->rtsectsize = sbp->sb_blocksize; geo->dirblocksize = xfs_dir2_dirblock_bytes(sbp); From patchwork Mon Dec 23 21:45:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13919265 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 426521422AB for ; Mon, 23 Dec 2024 21:45:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990344; cv=none; b=N2VtAKZflWjGkPYNuzByD4DXnQM000AdzgZ8pLVMOzGA2YWknQbeifyORgkqLrrFSRhJmEIwTbWBYQltiG+l5daYdi3jroZ2wl4QeCATIEE13pdHllXAeeA55g0zar0bQ12ddWOg8XGWA1TV81WiR+2wQglFaqhO+3zwcyDVVnY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990344; c=relaxed/simple; bh=dE/gX7IIpQslD7Lf/wffy5xYW2sN7a4gHVTSELyN468=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WrNHZJvJ1E73EYvQJQQDAR7UF4ZrkpEZ6u0RdGMMRr3Fok4FDxUROu4+ZZGbxkh0wq6l/lgxKGVVbNSMGontDP4fTCVadqd+BO99FMf943cSoepOkgOvea8ibm14ASuwIzwABdI+uU284kpL0VKu+z+y0evlJs7swvEbbccTCuk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AYLo0wJq; 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="AYLo0wJq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3267C4CED3; Mon, 23 Dec 2024 21:45:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990343; bh=dE/gX7IIpQslD7Lf/wffy5xYW2sN7a4gHVTSELyN468=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=AYLo0wJqBVPuiyn59Ti6i4J+MIjWGR6QF/g1REQJ8dRtsLmJ/RlLZpvOrN7QUHDSf PC84EisLC8371sW9nh+jvLdmhOHz0dq/xhlMBmPzxIXpOYbHVIaageKUj0/T5AK8/g 85CgHTT3eLV0LRu6AZniUjbBtPYgyv2AmTvXmaMz1PONU1KdnENz+vWGe0ltz/FhY/ n08sX7uVIx4gMBuxRCQ7iJNarRLv0XeuvdPRNVSI8Urb7uSaoPsAPXr91hDutDq5s2 J2lZRGwGcqVzVLNJLyWTnxCYcKIyyAKNkezuGlXkIUomIA3ioE7aGNqGPQE4MDVer5 wfx6j3sBzvbLw== Date: Mon, 23 Dec 2024 13:45:43 -0800 Subject: [PATCH 33/36] xfs: allow bulkstat to return metadata directories From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940448.2293042.388425970319376264.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: df866c538ff098baa210b407b822818a415a6e7e Allow the V5 bulkstat ioctl to return information about metadata directory files so that xfs_scrub can find and scrub them, since they are otherwise ordinary directories. (Metadata files of course require per-file scrub code and hence do not need exposure.) Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_fs.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index a42c1a33691c0f..499bea4ea8067f 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -490,9 +490,17 @@ struct xfs_bulk_ireq { */ #define XFS_BULK_IREQ_NREXT64 (1U << 2) +/* + * Allow bulkstat to return information about metadata directories. This + * enables xfs_scrub to find them for scanning, as they are otherwise ordinary + * directories. + */ +#define XFS_BULK_IREQ_METADIR (1U << 3) + #define XFS_BULK_IREQ_FLAGS_ALL (XFS_BULK_IREQ_AGNO | \ XFS_BULK_IREQ_SPECIAL | \ - XFS_BULK_IREQ_NREXT64) + XFS_BULK_IREQ_NREXT64 | \ + XFS_BULK_IREQ_METADIR) /* Operate on the root directory inode. */ #define XFS_BULK_IREQ_SPECIAL_ROOT (1) From patchwork Mon Dec 23 21:45:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13919266 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 B56851422AB for ; Mon, 23 Dec 2024 21:45:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990359; cv=none; b=Rtp4WFTL+jVkLBn7Llb0qjJ1FNb3joS0uTuhDuxqZkm0ghj0DGsySZSEKkSlUzWSsm7kuJVGagT5Xbzb5qbSNh3A5Zdtcd1WW+7YJudnnRej4dKjCpK3Nvio7ANvV+rlN1Q2bapz6vJckk+0+e+LnIscLCTmhunyGeHWAY4p2eU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990359; c=relaxed/simple; bh=f1H0S3LmJiS7L2YE6t0iHQa9jIj5Qqej1nlZUUaehSQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tRWGK30RtUm56v0zfDmEWmWDbhEFw9hOE0Of/YcvwFhsJ25TDIeC4JXSMlYCnDGXOxuZ7Pn2DgGuiihy4V2QLEHdtcRe/xsbDeLuM2K5Cu4zbjwbp2YDAwfqDdqrYVCYJSxJr+vHYVqC4Fw1NSCV7AzcECRRw7j25FexCWoPDcA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NPivUrk+; 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="NPivUrk+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E6EBC4CED3; Mon, 23 Dec 2024 21:45:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990359; bh=f1H0S3LmJiS7L2YE6t0iHQa9jIj5Qqej1nlZUUaehSQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=NPivUrk+CvKMhU/DfWsU4Xmq8mm9ge9DWi+Dw8OMgT3qUq4CmpMA0p03CkenAwFbx 3rg1EzivZ3+fTnV2JzadigshtsjRDfMBU3QJnGGg0SUehhfAOSwpYwIGpocLXaVivL kqcFdhtPtQbLZ/GQQibSkhkZZvJ/Zo7dlPBmgfuVuPLjA8S8VEb6qF6ILNtntLRIBO 94d81HHtKxqzRZ8LyGb7Xo39beGcmcQWS3dFyTe4Ke1rjzvqefacmQ0xeBpZTkpuRF TpmeQExPS8I2KDnmvdVASgs7aTY2TEVfpAzMle5DsU/p+6QovjJFc3LuB1BRcdR1AW eSA+gMLgdR8Yw== Date: Mon, 23 Dec 2024 13:45:58 -0800 Subject: [PATCH 34/36] xfs: adjust xfs_bmap_add_attrfork for metadir From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940463.2293042.17206658494742067648.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: 61b6bdb30a4bee1f3417081aedfe9e346538f897 Online repair might use the xfs_bmap_add_attrfork to repair a file in the metadata directory tree if (say) the metadata file lacks the correct parent pointers. In that case, it is not correct to check that the file is dqattached -- metadata files must be not have /any/ dquot attached at all. Adjust the assertions appropriately. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_attr.c | 5 ++++- libxfs/xfs_bmap.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 150aaddf7f9fed..7567014abbe7f0 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -1003,7 +1003,10 @@ xfs_attr_add_fork( unsigned int blks; /* space reservation */ int error; /* error return value */ - ASSERT(!XFS_NOT_DQATTACHED(mp, ip)); + if (xfs_is_metadir_inode(ip)) + ASSERT(XFS_IS_DQDETACHED(ip)); + else + ASSERT(!XFS_NOT_DQATTACHED(mp, ip)); blks = XFS_ADDAFORK_SPACE_RES(mp); diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 13cd4faa492838..99d53f9383a49a 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -1036,7 +1036,10 @@ xfs_bmap_add_attrfork( int error; /* error return value */ xfs_assert_ilocked(ip, XFS_ILOCK_EXCL); - ASSERT(!XFS_NOT_DQATTACHED(mp, ip)); + if (xfs_is_metadir_inode(ip)) + ASSERT(XFS_IS_DQDETACHED(ip)); + else + ASSERT(!XFS_NOT_DQATTACHED(mp, ip)); ASSERT(!xfs_inode_has_attr_fork(ip)); xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); From patchwork Mon Dec 23 21:46:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13919267 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 68D5319048A for ; Mon, 23 Dec 2024 21:46:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990375; cv=none; b=Qv9Yl8wJSUK+4IJSM8jQj/Z1XGvmLgj3UNzqLKkro8z7wfmDF7bestkTPL+8a8YEg9BvXXe4gTuSRQyB+wf3fOPVV81Ll8cds3Aqr9vJbJ5ZYhhhpXTCSd2J9XyiEXLRp0lsxcOYyK1AQFxXzij7COE2pe/NEi3HXEapi7FQWnE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990375; c=relaxed/simple; bh=8GziOFrpJtbtbGbmS4wIvJOHzjFxAwwKRHrXlIc7FNw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OOaA8SkPIV6kWCNLneupeTVdxssHfGu+6x4adjdjBcZmmkSmRoyyqfvegPl82/faSe+BvLMESrriXaVcIN/blMpHKMP4RMW75A1mKapM+C0PF0wF8JEPh7B/9rDE6ymE9UuyszV9hbHm/dFxExksGMPOSbKO0Z+Dfp/ydvKS5Z8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E1mULql+; 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="E1mULql+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1290C4CED3; Mon, 23 Dec 2024 21:46:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990375; bh=8GziOFrpJtbtbGbmS4wIvJOHzjFxAwwKRHrXlIc7FNw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=E1mULql+nHdPuaKpv3APsGPTAr7zF1aEz/lPImhzJeQ3KHHLMIX4Qt9NEaMFYOGTg CDJ2EUvdWrWKvfhfe6z7mIpj3NoisGJCPXYD1jO9O1pRWor0uXtJAlacvXHUIBlGQ4 Y3bj8ZNJw/bOXkAJQZ1HC92IFW5s/svF8nvRLP3V5FbpBqNKY+BQO00UAYrMU04cLq utxQcAIg9xIzq3kNwOJCtX3nkIbBr8hhBP6wHqOjUYwI1Wnc1mbVWeJqFqGALoRXT5 NidjtBGCX/APq3WlVAcA/6OtJ8hhC95qMbTh5HuNd4SeyvLoGvtt9HOwoODi21N5z1 gkRWsdEZHJdxQ== Date: Mon, 23 Dec 2024 13:46:14 -0800 Subject: [PATCH 35/36] xfs: record health problems with the metadata directory From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940478.2293042.4634685472282933113.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: be42fc1393d66024eb6415c92f45fab5d1878c3e Make a report to the health monitoring subsystem any time we encounter something in the metadata directory tree that looks like corruption. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_fs.h | 1 + libxfs/xfs_health.h | 4 +++- libxfs/xfs_metadir.c | 13 ++++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index 499bea4ea8067f..b05e6fb1470351 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -198,6 +198,7 @@ struct xfs_fsop_geom { #define XFS_FSOP_GEOM_SICK_RT_SUMMARY (1 << 5) /* realtime summary */ #define XFS_FSOP_GEOM_SICK_QUOTACHECK (1 << 6) /* quota counts */ #define XFS_FSOP_GEOM_SICK_NLINKS (1 << 7) /* inode link counts */ +#define XFS_FSOP_GEOM_SICK_METADIR (1 << 8) /* metadata directory */ /* Output for XFS_FS_COUNTS */ typedef struct xfs_fsop_counts { diff --git a/libxfs/xfs_health.h b/libxfs/xfs_health.h index 13301420a2f670..f90e8dfc050000 100644 --- a/libxfs/xfs_health.h +++ b/libxfs/xfs_health.h @@ -62,6 +62,7 @@ struct xfs_da_args; #define XFS_SICK_FS_PQUOTA (1 << 3) /* project quota */ #define XFS_SICK_FS_QUOTACHECK (1 << 4) /* quota counts */ #define XFS_SICK_FS_NLINKS (1 << 5) /* inode link counts */ +#define XFS_SICK_FS_METADIR (1 << 6) /* metadata directory tree */ /* Observable health issues for realtime volume metadata. */ #define XFS_SICK_RT_BITMAP (1 << 0) /* realtime bitmap */ @@ -105,7 +106,8 @@ struct xfs_da_args; XFS_SICK_FS_GQUOTA | \ XFS_SICK_FS_PQUOTA | \ XFS_SICK_FS_QUOTACHECK | \ - XFS_SICK_FS_NLINKS) + XFS_SICK_FS_NLINKS | \ + XFS_SICK_FS_METADIR) #define XFS_SICK_RT_PRIMARY (XFS_SICK_RT_BITMAP | \ XFS_SICK_RT_SUMMARY) diff --git a/libxfs/xfs_metadir.c b/libxfs/xfs_metadir.c index b52abf12d20511..b5f05925e73a4e 100644 --- a/libxfs/xfs_metadir.c +++ b/libxfs/xfs_metadir.c @@ -27,6 +27,7 @@ #include "xfs_dir2.h" #include "xfs_dir2_priv.h" #include "xfs_parent.h" +#include "xfs_health.h" /* * Metadata Directory Tree @@ -93,8 +94,10 @@ xfs_metadir_lookup( }; int error; - if (!S_ISDIR(VFS_I(dp)->i_mode)) + if (!S_ISDIR(VFS_I(dp)->i_mode)) { + xfs_fs_mark_sick(mp, XFS_SICK_FS_METADIR); return -EFSCORRUPTED; + } if (xfs_is_shutdown(mp)) return -EIO; @@ -102,10 +105,14 @@ xfs_metadir_lookup( if (error) return error; - if (!xfs_verify_ino(mp, args.inumber)) + if (!xfs_verify_ino(mp, args.inumber)) { + xfs_fs_mark_sick(mp, XFS_SICK_FS_METADIR); return -EFSCORRUPTED; - if (xname->type != XFS_DIR3_FT_UNKNOWN && xname->type != args.filetype) + } + if (xname->type != XFS_DIR3_FT_UNKNOWN && xname->type != args.filetype) { + xfs_fs_mark_sick(mp, XFS_SICK_FS_METADIR); return -EFSCORRUPTED; + } trace_xfs_metadir_lookup(dp, xname, args.inumber); *ino = args.inumber; From patchwork Mon Dec 23 21:46:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13919268 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 ACDAB19048A for ; Mon, 23 Dec 2024 21:46:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990390; cv=none; b=na43y4pBPOAeVZG4yGquHnAYbq4Q2lApXLFRfVV0U/vPV123XkpnCpoZIpmr3SsEyMF3cEyrbIYL2lbMB2ij74zWu54YJHR3A7Grj6we6oVRHtE266l537WaQ33LveV/zq4NaWJqPnDPwfHierDanv7GM+T60OskkaIvhWdmaUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734990390; c=relaxed/simple; bh=XYEdP597n1D74NX5g9WtpTlQGZCdmx8TmnMroa+Dd9I=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Rk8DbmCQCJRihuUjEwb+K2EGlknRSHZJ0ZznDYmEKGgff2TrG9kF9eyE2w7DswEaij+cCRpAd9uIlaJETr66lWrsGFxDISd4ZSoQ9SyldbtnY1Y4gbyDoFZFSS2PbaW9tREr0fHl+wMSwz36Ks+lZfMHrLxzc3H0qFJgGaQfrSU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fns1/8iw; 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="fns1/8iw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8205FC4CED3; Mon, 23 Dec 2024 21:46:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734990390; bh=XYEdP597n1D74NX5g9WtpTlQGZCdmx8TmnMroa+Dd9I=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=fns1/8iwEhHHepbtLH8Ghm/vl956oV6ju53kwFvx6WXsHrcCILtNwDdSTnLl8Sfu4 yGjktQ6qeMKmbDTIQR+LN+dA1sXar05KiDEFEZL3hzlN9ZTGdzzl4dBNl+2/xyPo8j wPbP0FmDmHedcw33FZ7or4mtVYzj8IeGtjhJP0Z8nJ6dn8o/GbhGJSqqarQdFRskw9 snJxdoUcuMv0tMb3+/FX0tINlbdaV4IniUCUOJNIP7pZvB3XLO8YQXCtnxS6A/ww6Y M9V4vIbKpPb/ZwKMRUSZxytr653KSIjAK7iwQw1SooYVxyxeRpRMs5P7t9cpDIqqU2 KPKthLfTQQXIg== Date: Mon, 23 Dec 2024 13:46:30 -0800 Subject: [PATCH 36/36] xfs: check metadata directory file path connectivity From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173498940494.2293042.9286700350983497113.stgit@frogsfrogsfrogs> In-Reply-To: <173498939893.2293042.8029858406528247316.stgit@frogsfrogsfrogs> References: <173498939893.2293042.8029858406528247316.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 Source kernel commit: b3c03efa5972f084e40104307dbe432359279cf2 Create a new scrubber type that checks that well known metadata directory paths are connected to the metadata inode that the incore structures think is in use. For example, check that "/quota/user" in the metadata directory tree actually points to mp->m_quotainfo->qi_uquotaip->i_ino. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/xfs_fs.h | 13 ++++++++++++- libxfs/xfs_health.h | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index b05e6fb1470351..faa38a7d1eb019 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -199,6 +199,7 @@ struct xfs_fsop_geom { #define XFS_FSOP_GEOM_SICK_QUOTACHECK (1 << 6) /* quota counts */ #define XFS_FSOP_GEOM_SICK_NLINKS (1 << 7) /* inode link counts */ #define XFS_FSOP_GEOM_SICK_METADIR (1 << 8) /* metadata directory */ +#define XFS_FSOP_GEOM_SICK_METAPATH (1 << 9) /* metadir tree path */ /* Output for XFS_FS_COUNTS */ typedef struct xfs_fsop_counts { @@ -732,9 +733,10 @@ struct xfs_scrub_metadata { #define XFS_SCRUB_TYPE_NLINKS 26 /* inode link counts */ #define XFS_SCRUB_TYPE_HEALTHY 27 /* everything checked out ok */ #define XFS_SCRUB_TYPE_DIRTREE 28 /* directory tree structure */ +#define XFS_SCRUB_TYPE_METAPATH 29 /* metadata directory tree paths */ /* Number of scrub subcommands. */ -#define XFS_SCRUB_TYPE_NR 29 +#define XFS_SCRUB_TYPE_NR 30 /* * This special type code only applies to the vectored scrub implementation. @@ -812,6 +814,15 @@ struct xfs_scrub_vec_head { #define XFS_SCRUB_VEC_FLAGS_ALL (0) +/* + * i: sm_ino values for XFS_SCRUB_TYPE_METAPATH to select a metadata file for + * path checking. + */ +#define XFS_SCRUB_METAPATH_PROBE (0) /* do we have a metapath scrubber? */ + +/* Number of metapath sm_ino values */ +#define XFS_SCRUB_METAPATH_NR (1) + /* * ioctl limits */ diff --git a/libxfs/xfs_health.h b/libxfs/xfs_health.h index f90e8dfc050000..a23df94319e5fb 100644 --- a/libxfs/xfs_health.h +++ b/libxfs/xfs_health.h @@ -63,6 +63,7 @@ struct xfs_da_args; #define XFS_SICK_FS_QUOTACHECK (1 << 4) /* quota counts */ #define XFS_SICK_FS_NLINKS (1 << 5) /* inode link counts */ #define XFS_SICK_FS_METADIR (1 << 6) /* metadata directory tree */ +#define XFS_SICK_FS_METAPATH (1 << 7) /* metadata directory tree path */ /* Observable health issues for realtime volume metadata. */ #define XFS_SICK_RT_BITMAP (1 << 0) /* realtime bitmap */ @@ -107,7 +108,8 @@ struct xfs_da_args; XFS_SICK_FS_PQUOTA | \ XFS_SICK_FS_QUOTACHECK | \ XFS_SICK_FS_NLINKS | \ - XFS_SICK_FS_METADIR) + XFS_SICK_FS_METADIR | \ + XFS_SICK_FS_METAPATH) #define XFS_SICK_RT_PRIMARY (XFS_SICK_RT_BITMAP | \ XFS_SICK_RT_SUMMARY)